aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
authorDave Jones <davej@redhat.com>2006-12-12 18:13:32 -0500
committerDave Jones <davej@redhat.com>2006-12-12 18:13:32 -0500
commitf0eef25339f92f7cd4aeea23d9ae97987a5a1e82 (patch)
tree2472e94d39f43a9580a6d2d5d92de0b749023263 /drivers/char
parent0cfea5dd98205f2fa318836da664a7d7df1afbc1 (diff)
parente1036502e5263851259d147771226161e5ccc85a (diff)
Merge ../linus
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/.gitignore1
-rw-r--r--drivers/char/Kconfig93
-rw-r--r--drivers/char/Makefile10
-rw-r--r--drivers/char/agp/Kconfig10
-rw-r--r--drivers/char/agp/Makefile1
-rw-r--r--drivers/char/agp/generic.c2
-rw-r--r--drivers/char/agp/intel-agp.c33
-rw-r--r--drivers/char/agp/parisc-agp.c416
-rw-r--r--drivers/char/amiserial.c44
-rw-r--r--drivers/char/applicom.c4
-rw-r--r--drivers/char/briq_panel.c1
-rw-r--r--drivers/char/cs5535_gpio.c4
-rw-r--r--drivers/char/cyclades.c7804
-rw-r--r--drivers/char/decserial.c38
-rw-r--r--drivers/char/drm/Kconfig9
-rw-r--r--drivers/char/drm/Makefile6
-rw-r--r--drivers/char/drm/drm.h33
-rw-r--r--drivers/char/drm/drmP.h91
-rw-r--r--drivers/char/drm/drm_auth.c64
-rw-r--r--drivers/char/drm/drm_bufs.c88
-rw-r--r--drivers/char/drm/drm_core.h8
-rw-r--r--drivers/char/drm/drm_drawable.c294
-rw-r--r--drivers/char/drm/drm_drv.c26
-rw-r--r--drivers/char/drm/drm_fops.c10
-rw-r--r--drivers/char/drm/drm_hashtab.c190
-rw-r--r--drivers/char/drm/drm_hashtab.h67
-rw-r--r--drivers/char/drm/drm_ioc32.c58
-rw-r--r--drivers/char/drm/drm_ioctl.c34
-rw-r--r--drivers/char/drm/drm_irq.c165
-rw-r--r--drivers/char/drm/drm_lock.c11
-rw-r--r--drivers/char/drm/drm_mm.c201
-rw-r--r--drivers/char/drm/drm_os_linux.h2
-rw-r--r--drivers/char/drm/drm_pciids.h187
-rw-r--r--drivers/char/drm/drm_proc.c2
-rw-r--r--drivers/char/drm/drm_sman.c353
-rw-r--r--drivers/char/drm/drm_sman.h176
-rw-r--r--drivers/char/drm/drm_stub.c14
-rw-r--r--drivers/char/drm/drm_sysfs.c43
-rw-r--r--drivers/char/drm/drm_vm.c69
-rw-r--r--drivers/char/drm/i810_dma.c10
-rw-r--r--drivers/char/drm/i830_dma.c4
-rw-r--r--drivers/char/drm/i915_dma.c47
-rw-r--r--drivers/char/drm/i915_drm.h25
-rw-r--r--drivers/char/drm/i915_drv.c4
-rw-r--r--drivers/char/drm/i915_drv.h32
-rw-r--r--drivers/char/drm/i915_ioc32.c12
-rw-r--r--drivers/char/drm/i915_irq.c281
-rw-r--r--drivers/char/drm/mga_drv.c1
-rw-r--r--drivers/char/drm/mga_ioc32.c8
-rw-r--r--drivers/char/drm/r128_ioc32.c10
-rw-r--r--drivers/char/drm/r300_cmdbuf.c33
-rw-r--r--drivers/char/drm/radeon_cp.c72
-rw-r--r--drivers/char/drm/radeon_drv.c2
-rw-r--r--drivers/char/drm/radeon_drv.h36
-rw-r--r--drivers/char/drm/radeon_ioc32.c20
-rw-r--r--drivers/char/drm/radeon_state.c157
-rw-r--r--drivers/char/drm/savage_bci.c1
-rw-r--r--drivers/char/drm/savage_state.c2
-rw-r--r--drivers/char/drm/sis_drv.c39
-rw-r--r--drivers/char/drm/sis_drv.h34
-rw-r--r--drivers/char/drm/sis_ds.c299
-rw-r--r--drivers/char/drm/sis_ds.h146
-rw-r--r--drivers/char/drm/sis_mm.c504
-rw-r--r--drivers/char/drm/via_dmablit.c74
-rw-r--r--drivers/char/drm/via_drm.h8
-rw-r--r--drivers/char/drm/via_drv.c3
-rw-r--r--drivers/char/drm/via_drv.h16
-rw-r--r--drivers/char/drm/via_ds.c273
-rw-r--r--drivers/char/drm/via_ds.h104
-rw-r--r--drivers/char/drm/via_map.c9
-rw-r--r--drivers/char/drm/via_mm.c375
-rw-r--r--drivers/char/ds1286.c15
-rw-r--r--drivers/char/dsp56k.c6
-rw-r--r--drivers/char/dtlk.c4
-rw-r--r--drivers/char/ec3104_keyb.c2
-rw-r--r--drivers/char/epca.c75
-rw-r--r--drivers/char/epca.h1
-rw-r--r--drivers/char/esp.c21
-rw-r--r--drivers/char/ftape/Kconfig330
-rw-r--r--drivers/char/ftape/Makefile28
-rw-r--r--drivers/char/ftape/README.PCI81
-rw-r--r--drivers/char/ftape/RELEASE-NOTES966
-rw-r--r--drivers/char/ftape/compressor/Makefile31
-rw-r--r--drivers/char/ftape/compressor/lzrw3.c743
-rw-r--r--drivers/char/ftape/compressor/lzrw3.h253
-rw-r--r--drivers/char/ftape/compressor/zftape-compress.c1203
-rw-r--r--drivers/char/ftape/compressor/zftape-compress.h83
-rw-r--r--drivers/char/ftape/lowlevel/Makefile43
-rw-r--r--drivers/char/ftape/lowlevel/fc-10.c175
-rw-r--r--drivers/char/ftape/lowlevel/fc-10.h39
-rw-r--r--drivers/char/ftape/lowlevel/fdc-io.c1350
-rw-r--r--drivers/char/ftape/lowlevel/fdc-io.h252
-rw-r--r--drivers/char/ftape/lowlevel/fdc-isr.c1170
-rw-r--r--drivers/char/ftape/lowlevel/fdc-isr.h55
-rw-r--r--drivers/char/ftape/lowlevel/ftape-bsm.c491
-rw-r--r--drivers/char/ftape/lowlevel/ftape-bsm.h66
-rw-r--r--drivers/char/ftape/lowlevel/ftape-buffer.c130
-rw-r--r--drivers/char/ftape/lowlevel/ftape-buffer.h32
-rw-r--r--drivers/char/ftape/lowlevel/ftape-calibr.c275
-rw-r--r--drivers/char/ftape/lowlevel/ftape-calibr.h37
-rw-r--r--drivers/char/ftape/lowlevel/ftape-ctl.c896
-rw-r--r--drivers/char/ftape/lowlevel/ftape-ctl.h162
-rw-r--r--drivers/char/ftape/lowlevel/ftape-ecc.c853
-rw-r--r--drivers/char/ftape/lowlevel/ftape-ecc.h84
-rw-r--r--drivers/char/ftape/lowlevel/ftape-format.c344
-rw-r--r--drivers/char/ftape/lowlevel/ftape-format.h37
-rw-r--r--drivers/char/ftape/lowlevel/ftape-init.c160
-rw-r--r--drivers/char/ftape/lowlevel/ftape-init.h43
-rw-r--r--drivers/char/ftape/lowlevel/ftape-io.c992
-rw-r--r--drivers/char/ftape/lowlevel/ftape-io.h90
-rw-r--r--drivers/char/ftape/lowlevel/ftape-proc.c214
-rw-r--r--drivers/char/ftape/lowlevel/ftape-proc.h35
-rw-r--r--drivers/char/ftape/lowlevel/ftape-read.c621
-rw-r--r--drivers/char/ftape/lowlevel/ftape-read.h51
-rw-r--r--drivers/char/ftape/lowlevel/ftape-rw.c1092
-rw-r--r--drivers/char/ftape/lowlevel/ftape-rw.h111
-rw-r--r--drivers/char/ftape/lowlevel/ftape-setup.c104
-rw-r--r--drivers/char/ftape/lowlevel/ftape-tracing.c118
-rw-r--r--drivers/char/ftape/lowlevel/ftape-tracing.h179
-rw-r--r--drivers/char/ftape/lowlevel/ftape-write.c336
-rw-r--r--drivers/char/ftape/lowlevel/ftape-write.h53
-rw-r--r--drivers/char/ftape/lowlevel/ftape_syms.c87
-rw-r--r--drivers/char/ftape/zftape/Makefile36
-rw-r--r--drivers/char/ftape/zftape/zftape-buffers.c149
-rw-r--r--drivers/char/ftape/zftape/zftape-buffers.h55
-rw-r--r--drivers/char/ftape/zftape/zftape-ctl.c1417
-rw-r--r--drivers/char/ftape/zftape/zftape-ctl.h58
-rw-r--r--drivers/char/ftape/zftape/zftape-eof.c199
-rw-r--r--drivers/char/ftape/zftape/zftape-eof.h52
-rw-r--r--drivers/char/ftape/zftape/zftape-init.c377
-rw-r--r--drivers/char/ftape/zftape/zftape-init.h77
-rw-r--r--drivers/char/ftape/zftape/zftape-read.c377
-rw-r--r--drivers/char/ftape/zftape/zftape-read.h53
-rw-r--r--drivers/char/ftape/zftape/zftape-rw.c376
-rw-r--r--drivers/char/ftape/zftape/zftape-rw.h102
-rw-r--r--drivers/char/ftape/zftape/zftape-vtbl.c757
-rw-r--r--drivers/char/ftape/zftape/zftape-vtbl.h227
-rw-r--r--drivers/char/ftape/zftape/zftape-write.c483
-rw-r--r--drivers/char/ftape/zftape/zftape-write.h38
-rw-r--r--drivers/char/ftape/zftape/zftape_syms.c43
-rw-r--r--drivers/char/generic_serial.c34
-rw-r--r--drivers/char/genrtc.c4
-rw-r--r--drivers/char/hangcheck-timer.c2
-rw-r--r--drivers/char/hpet.c3
-rw-r--r--drivers/char/hvc_console.c7
-rw-r--r--drivers/char/hvc_iseries.c15
-rw-r--r--drivers/char/hvc_vio.c4
-rw-r--r--drivers/char/hvcs.c440
-rw-r--r--drivers/char/hvsi.c26
-rw-r--r--drivers/char/hw_random/Kconfig19
-rw-r--r--drivers/char/hw_random/Makefile3
-rw-r--r--drivers/char/hw_random/core.c39
-rw-r--r--drivers/char/hw_random/intel-rng.c186
-rw-r--r--drivers/char/hw_random/ixp4xx-rng.c3
-rw-r--r--drivers/char/hw_random/omap-rng.c2
-rw-r--r--drivers/char/ip2/i2cmd.h5
-rw-r--r--drivers/char/ip2/i2lib.c24
-rw-r--r--drivers/char/ip2/i2lib.h2
-rw-r--r--drivers/char/ip2/ip2main.c62
-rw-r--r--drivers/char/ipmi/ipmi_bt_sm.c643
-rw-r--r--drivers/char/ipmi/ipmi_devintf.c65
-rw-r--r--drivers/char/ipmi/ipmi_kcs_sm.c18
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c943
-rw-r--r--drivers/char/ipmi/ipmi_poweroff.c114
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c450
-rw-r--r--drivers/char/ipmi/ipmi_smic_sm.c14
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c141
-rw-r--r--drivers/char/isicom.c350
-rw-r--r--drivers/char/istallion.c1214
-rw-r--r--drivers/char/ite_gpio.c419
-rw-r--r--drivers/char/keyboard.c162
-rw-r--r--drivers/char/lp.c8
-rw-r--r--drivers/char/mbcs.c10
-rw-r--r--drivers/char/mem.c76
-rw-r--r--drivers/char/misc.c15
-rw-r--r--drivers/char/mmtimer.c26
-rw-r--r--drivers/char/moxa.c114
-rw-r--r--drivers/char/mspec.c426
-rw-r--r--drivers/char/mwave/README5
-rw-r--r--drivers/char/mwave/mwavedd.c4
-rw-r--r--drivers/char/mwave/tp3780i.c4
-rw-r--r--drivers/char/mxser.c113
-rw-r--r--drivers/char/mxser_new.c2804
-rw-r--r--drivers/char/mxser_new.h450
-rw-r--r--drivers/char/n_r3964.c4
-rw-r--r--drivers/char/n_tty.c2
-rw-r--r--drivers/char/nsc_gpio.c5
-rw-r--r--drivers/char/nwbutton.c7
-rw-r--r--drivers/char/nwbutton.h2
-rw-r--r--drivers/char/pc8736x_gpio.c10
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c26
-rw-r--r--drivers/char/pcmcia/cm4040_cs.c26
-rw-r--r--drivers/char/pcmcia/synclink_cs.c52
-rw-r--r--drivers/char/ppdev.c12
-rw-r--r--drivers/char/pty.c12
-rw-r--r--drivers/char/qtronix.c605
-rw-r--r--drivers/char/qtronixmap.c_shipped265
-rw-r--r--drivers/char/qtronixmap.map287
-rw-r--r--drivers/char/random.c67
-rw-r--r--drivers/char/raw.c64
-rw-r--r--drivers/char/rio/func.h2
-rw-r--r--drivers/char/rio/host.h1
-rw-r--r--drivers/char/rio/rio_linux.c27
-rw-r--r--drivers/char/rio/riocmd.c2
-rw-r--r--drivers/char/rio/rioctrl.c4
-rw-r--r--drivers/char/rio/rioinit.c2
-rw-r--r--drivers/char/rio/riointr.c2
-rw-r--r--drivers/char/rio/rioparam.c6
-rw-r--r--drivers/char/riscom8.c64
-rw-r--r--drivers/char/rocket.c12
-rw-r--r--drivers/char/rtc.c16
-rw-r--r--drivers/char/s3c2410-rtc.c591
-rw-r--r--drivers/char/scx200_gpio.c4
-rw-r--r--drivers/char/selection.c2
-rw-r--r--drivers/char/ser_a2232.c8
-rw-r--r--drivers/char/serial167.c110
-rw-r--r--drivers/char/snsc.c2
-rw-r--r--drivers/char/snsc_event.c4
-rw-r--r--drivers/char/sonypi.c8
-rw-r--r--drivers/char/specialix.c73
-rw-r--r--drivers/char/stallion.c2159
-rw-r--r--drivers/char/sx.c2236
-rw-r--r--drivers/char/sx.h1
-rw-r--r--drivers/char/synclink.c50
-rw-r--r--drivers/char/synclink_gt.c144
-rw-r--r--drivers/char/synclinkmp.c45
-rw-r--r--drivers/char/sysrq.c84
-rw-r--r--drivers/char/tb0219.c4
-rw-r--r--drivers/char/tipar.c10
-rw-r--r--drivers/char/tlclk.c9
-rw-r--r--drivers/char/toshiba.c1
-rw-r--r--drivers/char/tpm/tpm.c18
-rw-r--r--drivers/char/tpm/tpm.h1
-rw-r--r--drivers/char/tpm/tpm_atmel.c10
-rw-r--r--drivers/char/tpm/tpm_nsc.c6
-rw-r--r--drivers/char/tpm/tpm_tis.c4
-rw-r--r--drivers/char/tty_io.c541
-rw-r--r--drivers/char/tty_ioctl.c299
-rw-r--r--drivers/char/vc_screen.c27
-rw-r--r--drivers/char/viocons.c4
-rw-r--r--drivers/char/viotape.c10
-rw-r--r--drivers/char/vme_scc.c24
-rw-r--r--drivers/char/vr41xx_giu.c6
-rw-r--r--drivers/char/vt.c235
-rw-r--r--drivers/char/vt_ioctl.c34
-rw-r--r--drivers/char/watchdog/Kconfig136
-rw-r--r--drivers/char/watchdog/Makefile9
-rw-r--r--drivers/char/watchdog/acquirewdt.c2
-rw-r--r--drivers/char/watchdog/advantechwdt.c2
-rw-r--r--drivers/char/watchdog/alim1535_wdt.c12
-rw-r--r--drivers/char/watchdog/alim7101_wdt.c30
-rw-r--r--drivers/char/watchdog/at91rm9200_wdt.c (renamed from drivers/char/watchdog/at91_wdt.c)3
-rw-r--r--drivers/char/watchdog/booke_wdt.c2
-rw-r--r--drivers/char/watchdog/cpu5wdt.c2
-rw-r--r--drivers/char/watchdog/ep93xx_wdt.c2
-rw-r--r--drivers/char/watchdog/eurotechwdt.c4
-rw-r--r--drivers/char/watchdog/i6300esb.c2
-rw-r--r--drivers/char/watchdog/i8xx_tco.c35
-rw-r--r--drivers/char/watchdog/iTCO_vendor_support.c307
-rw-r--r--drivers/char/watchdog/iTCO_wdt.c772
-rw-r--r--drivers/char/watchdog/ib700wdt.c2
-rw-r--r--drivers/char/watchdog/ibmasr.c2
-rw-r--r--drivers/char/watchdog/indydog.c2
-rw-r--r--drivers/char/watchdog/ixp2000_wdt.c4
-rw-r--r--drivers/char/watchdog/ixp4xx_wdt.c4
-rw-r--r--drivers/char/watchdog/machzwd.c5
-rw-r--r--drivers/char/watchdog/mixcomwd.c2
-rw-r--r--drivers/char/watchdog/mpc83xx_wdt.c2
-rw-r--r--drivers/char/watchdog/mpc8xx_wdt.c2
-rw-r--r--drivers/char/watchdog/mpcore_wdt.c6
-rw-r--r--drivers/char/watchdog/mv64x60_wdt.c2
-rw-r--r--drivers/char/watchdog/omap_wdt.c390
-rw-r--r--drivers/char/watchdog/omap_wdt.h64
-rw-r--r--drivers/char/watchdog/pc87413_wdt.c635
-rw-r--r--drivers/char/watchdog/pcwd.c3
-rw-r--r--drivers/char/watchdog/pcwd_pci.c3
-rw-r--r--drivers/char/watchdog/pcwd_usb.c9
-rw-r--r--drivers/char/watchdog/pnx4008_wdt.c361
-rw-r--r--drivers/char/watchdog/rm9k_wdt.c420
-rw-r--r--drivers/char/watchdog/s3c2410_wdt.c20
-rw-r--r--drivers/char/watchdog/sa1100_wdt.c2
-rw-r--r--drivers/char/watchdog/sbc60xxwdt.c2
-rw-r--r--drivers/char/watchdog/sbc_epx_c3.c2
-rw-r--r--drivers/char/watchdog/sc1200wdt.c11
-rw-r--r--drivers/char/watchdog/sc520_wdt.c2
-rw-r--r--drivers/char/watchdog/scx200_wdt.c2
-rw-r--r--drivers/char/watchdog/shwdt.c112
-rw-r--r--drivers/char/watchdog/smsc37b787_wdt.c627
-rw-r--r--drivers/char/watchdog/softdog.c2
-rw-r--r--drivers/char/watchdog/w83627hf_wdt.c10
-rw-r--r--drivers/char/watchdog/w83697hf_wdt.c450
-rw-r--r--drivers/char/watchdog/w83877f_wdt.c2
-rw-r--r--drivers/char/watchdog/w83977f_wdt.c2
-rw-r--r--drivers/char/watchdog/wafer5823wdt.c2
-rw-r--r--drivers/char/watchdog/wdrtas.c2
-rw-r--r--drivers/char/watchdog/wdt.c5
-rw-r--r--drivers/char/watchdog/wdt285.c4
-rw-r--r--drivers/char/watchdog/wdt977.c2
-rw-r--r--drivers/char/watchdog/wdt_pci.c5
299 files changed, 22054 insertions, 33064 deletions
diff --git a/drivers/char/.gitignore b/drivers/char/.gitignore
index 73dfdcebfbba..83683a2d8e6a 100644
--- a/drivers/char/.gitignore
+++ b/drivers/char/.gitignore
@@ -1,3 +1,2 @@
1consolemap_deftbl.c 1consolemap_deftbl.c
2defkeymap.c 2defkeymap.c
3qtronixmap.c
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 52ea94b891f5..b10f4d8fdc7f 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -201,6 +201,21 @@ config MOXA_SMARTIO
201 The module will be called mxser. If you want to do that, say M 201 The module will be called mxser. If you want to do that, say M
202 here. 202 here.
203 203
204config MOXA_SMARTIO_NEW
205 tristate "Moxa SmartIO support v. 2.0 (EXPERIMENTAL)"
206 depends on SERIAL_NONSTANDARD
207 help
208 Say Y here if you have a Moxa SmartIO multiport serial card and/or
209 want to help develop a new version of this driver.
210
211 This is upgraded (1.9.1) driver from original Moxa drivers with
212 changes finally resulting in PCI probing.
213
214 Use at your own risk.
215
216 This driver can also be built as a module. The module will be called
217 mxser_new. If you want to do that, say M here.
218
204config ISI 219config ISI
205 tristate "Multi-Tech multiport card support (EXPERIMENTAL)" 220 tristate "Multi-Tech multiport card support (EXPERIMENTAL)"
206 depends on SERIAL_NONSTANDARD 221 depends on SERIAL_NONSTANDARD
@@ -371,36 +386,6 @@ config AU1000_SERIAL_CONSOLE
371 If you have an Alchemy AU1000 processor (MIPS based) and you want 386 If you have an Alchemy AU1000 processor (MIPS based) and you want
372 to use a console on a serial port, say Y. Otherwise, say N. 387 to use a console on a serial port, say Y. Otherwise, say N.
373 388
374config QTRONIX_KEYBOARD
375 bool "Enable Qtronix 990P Keyboard Support"
376 depends on IT8712
377 help
378 Images of Qtronix keyboards are at
379 <http://www.qtronix.com/keyboard.html>.
380
381config IT8172_CIR
382 bool
383 depends on QTRONIX_KEYBOARD
384 default y
385
386config IT8172_SCR0
387 bool "Enable Smart Card Reader 0 Support "
388 depends on IT8712
389 help
390 Say Y here to support smart-card reader 0 (SCR0) on the Integrated
391 Technology Express, Inc. ITE8172 SBC. Vendor page at
392 <http://www.ite.com.tw/ia/brief_it8172bsp.htm>; picture of the
393 board at <http://www.mvista.com/partners/semiconductor/ite.html>.
394
395config IT8172_SCR1
396 bool "Enable Smart Card Reader 1 Support "
397 depends on IT8712
398 help
399 Say Y here to support smart-card reader 1 (SCR1) on the Integrated
400 Technology Express, Inc. ITE8172 SBC. Vendor page at
401 <http://www.ite.com.tw/ia/brief_it8172bsp.htm>; picture of the
402 board at <http://www.mvista.com/partners/semiconductor/ite.html>.
403
404config A2232 389config A2232
405 tristate "Commodore A2232 serial support (EXPERIMENTAL)" 390 tristate "Commodore A2232 serial support (EXPERIMENTAL)"
406 depends on EXPERIMENTAL && ZORRO && BROKEN_ON_SMP 391 depends on EXPERIMENTAL && ZORRO && BROKEN_ON_SMP
@@ -739,7 +724,7 @@ config NVRAM
739 724
740config RTC 725config RTC
741 tristate "Enhanced Real Time Clock Support" 726 tristate "Enhanced Real Time Clock Support"
742 depends on !PPC && !PARISC && !IA64 && !M68K && (!SPARC || PCI) && !FRV && !ARM 727 depends on !PPC && !PARISC && !IA64 && !M68K && (!SPARC || PCI) && !FRV && !ARM && !SUPERH
743 ---help--- 728 ---help---
744 If you say Y here and create a character special file /dev/rtc with 729 If you say Y here and create a character special file /dev/rtc with
745 major number 10 and minor number 135 using mknod ("man mknod"), you 730 major number 10 and minor number 135 using mknod ("man mknod"), you
@@ -823,14 +808,6 @@ config DS1302
823 will get access to the real time clock (or hardware clock) built 808 will get access to the real time clock (or hardware clock) built
824 into your computer. 809 into your computer.
825 810
826config S3C2410_RTC
827 bool "S3C2410 RTC Driver"
828 depends on ARCH_S3C2410
829 help
830 RTC (Realtime Clock) driver for the clock inbuilt into the
831 Samsung S3C2410. This can provide periodic interrupt rates
832 from 1Hz to 64Hz for user programs, and wakeup from Alarm.
833
834config COBALT_LCD 811config COBALT_LCD
835 bool "Support for Cobalt LCD" 812 bool "Support for Cobalt LCD"
836 depends on MIPS_COBALT 813 depends on MIPS_COBALT
@@ -893,39 +870,6 @@ config TANBAC_TB0219
893 depends TANBAC_TB022X 870 depends TANBAC_TB022X
894 select GPIO_VR41XX 871 select GPIO_VR41XX
895 872
896menu "Ftape, the floppy tape device driver"
897
898config FTAPE
899 tristate "Ftape (QIC-80/Travan) support"
900 depends on BROKEN_ON_SMP && (ALPHA || X86)
901 ---help---
902 If you have a tape drive that is connected to your floppy
903 controller, say Y here.
904
905 Some tape drives (like the Seagate "Tape Store 3200" or the Iomega
906 "Ditto 3200" or the Exabyte "Eagle TR-3") come with a "high speed"
907 controller of their own. These drives (and their companion
908 controllers) are also supported if you say Y here.
909
910 If you have a special controller (such as the CMS FC-10, FC-20,
911 Mountain Mach-II, or any controller that is based on the Intel 82078
912 FDC like the high speed controllers by Seagate and Exabyte and
913 Iomega's "Ditto Dash") you must configure it by selecting the
914 appropriate entries from the "Floppy tape controllers" sub-menu
915 below and possibly modify the default values for the IRQ and DMA
916 channel and the IO base in ftape's configuration menu.
917
918 If you want to use your floppy tape drive on a PCI-bus based system,
919 please read the file <file:drivers/char/ftape/README.PCI>.
920
921 The ftape kernel driver is also available as a runtime loadable
922 module. To compile this driver as a module, choose M here: the
923 module will be called ftape.
924
925source "drivers/char/ftape/Kconfig"
926
927endmenu
928
929source "drivers/char/agp/Kconfig" 873source "drivers/char/agp/Kconfig"
930 874
931source "drivers/char/drm/Kconfig" 875source "drivers/char/drm/Kconfig"
@@ -1006,6 +950,7 @@ config GPIO_VR41XX
1006 950
1007config RAW_DRIVER 951config RAW_DRIVER
1008 tristate "RAW driver (/dev/raw/rawN) (OBSOLETE)" 952 tristate "RAW driver (/dev/raw/rawN) (OBSOLETE)"
953 depends on BLOCK
1009 help 954 help
1010 The raw driver permits block devices to be bound to /dev/raw/rawN. 955 The raw driver permits block devices to be bound to /dev/raw/rawN.
1011 Once bound, I/O against /dev/raw/rawN uses efficient zero-copy I/O. 956 Once bound, I/O against /dev/raw/rawN uses efficient zero-copy I/O.
@@ -1031,7 +976,7 @@ config HPET
1031 help 976 help
1032 If you say Y here, you will have a miscdevice named "/dev/hpet/". Each 977 If you say Y here, you will have a miscdevice named "/dev/hpet/". Each
1033 open selects one of the timers supported by the HPET. The timers are 978 open selects one of the timers supported by the HPET. The timers are
1034 non-periodioc and/or periodic. 979 non-periodic and/or periodic.
1035 980
1036config HPET_RTC_IRQ 981config HPET_RTC_IRQ
1037 bool "HPET Control RTC IRQ" if !HPET_EMULATE_RTC 982 bool "HPET Control RTC IRQ" if !HPET_EMULATE_RTC
@@ -1075,7 +1020,7 @@ source "drivers/char/tpm/Kconfig"
1075 1020
1076config TELCLOCK 1021config TELCLOCK
1077 tristate "Telecom clock driver for MPBL0010 ATCA SBC" 1022 tristate "Telecom clock driver for MPBL0010 ATCA SBC"
1078 depends on EXPERIMENTAL 1023 depends on EXPERIMENTAL && X86
1079 default n 1024 default n
1080 help 1025 help
1081 The telecom clock device is specific to the MPBL0010 ATCA computer and 1026 The telecom clock device is specific to the MPBL0010 ATCA computer and
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 8c6dfc621520..fc110637ced6 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_MOXA_INTELLIO) += moxa.o
31obj-$(CONFIG_A2232) += ser_a2232.o generic_serial.o 31obj-$(CONFIG_A2232) += ser_a2232.o generic_serial.o
32obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o 32obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o
33obj-$(CONFIG_MOXA_SMARTIO) += mxser.o 33obj-$(CONFIG_MOXA_SMARTIO) += mxser.o
34obj-$(CONFIG_MOXA_SMARTIO_NEW) += mxser_new.o
34obj-$(CONFIG_COMPUTONE) += ip2/ 35obj-$(CONFIG_COMPUTONE) += ip2/
35obj-$(CONFIG_RISCOM8) += riscom8.o 36obj-$(CONFIG_RISCOM8) += riscom8.o
36obj-$(CONFIG_ISI) += isicom.o 37obj-$(CONFIG_ISI) += isicom.o
@@ -47,6 +48,7 @@ obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o
47obj-$(CONFIG_HVC_DRIVER) += hvc_console.o 48obj-$(CONFIG_HVC_DRIVER) += hvc_console.o
48obj-$(CONFIG_RAW_DRIVER) += raw.o 49obj-$(CONFIG_RAW_DRIVER) += raw.o
49obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o 50obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o
51obj-$(CONFIG_MSPEC) += mspec.o
50obj-$(CONFIG_MMTIMER) += mmtimer.o 52obj-$(CONFIG_MMTIMER) += mmtimer.o
51obj-$(CONFIG_VIOCONS) += viocons.o 53obj-$(CONFIG_VIOCONS) += viocons.o
52obj-$(CONFIG_VIOTAPE) += viotape.o 54obj-$(CONFIG_VIOTAPE) += viotape.o
@@ -68,7 +70,6 @@ obj-$(CONFIG_EFI_RTC) += efirtc.o
68obj-$(CONFIG_SGI_DS1286) += ds1286.o 70obj-$(CONFIG_SGI_DS1286) += ds1286.o
69obj-$(CONFIG_SGI_IP27_RTC) += ip27-rtc.o 71obj-$(CONFIG_SGI_IP27_RTC) += ip27-rtc.o
70obj-$(CONFIG_DS1302) += ds1302.o 72obj-$(CONFIG_DS1302) += ds1302.o
71obj-$(CONFIG_S3C2410_RTC) += s3c2410-rtc.o
72ifeq ($(CONFIG_GENERIC_NVRAM),y) 73ifeq ($(CONFIG_GENERIC_NVRAM),y)
73 obj-$(CONFIG_NVRAM) += generic_nvram.o 74 obj-$(CONFIG_NVRAM) += generic_nvram.o
74else 75else
@@ -78,7 +79,6 @@ obj-$(CONFIG_TOSHIBA) += toshiba.o
78obj-$(CONFIG_I8K) += i8k.o 79obj-$(CONFIG_I8K) += i8k.o
79obj-$(CONFIG_DS1620) += ds1620.o 80obj-$(CONFIG_DS1620) += ds1620.o
80obj-$(CONFIG_HW_RANDOM) += hw_random/ 81obj-$(CONFIG_HW_RANDOM) += hw_random/
81obj-$(CONFIG_FTAPE) += ftape/
82obj-$(CONFIG_COBALT_LCD) += lcd.o 82obj-$(CONFIG_COBALT_LCD) += lcd.o
83obj-$(CONFIG_PPDEV) += ppdev.o 83obj-$(CONFIG_PPDEV) += ppdev.o
84obj-$(CONFIG_NWBUTTON) += nwbutton.o 84obj-$(CONFIG_NWBUTTON) += nwbutton.o
@@ -102,7 +102,7 @@ obj-$(CONFIG_HANGCHECK_TIMER) += hangcheck-timer.o
102obj-$(CONFIG_TCG_TPM) += tpm/ 102obj-$(CONFIG_TCG_TPM) += tpm/
103 103
104# Files generated that shall be removed upon make clean 104# Files generated that shall be removed upon make clean
105clean-files := consolemap_deftbl.c defkeymap.c qtronixmap.c 105clean-files := consolemap_deftbl.c defkeymap.c
106 106
107quiet_cmd_conmk = CONMK $@ 107quiet_cmd_conmk = CONMK $@
108 cmd_conmk = scripts/conmakehash $< > $@ 108 cmd_conmk = scripts/conmakehash $< > $@
@@ -112,8 +112,6 @@ $(obj)/consolemap_deftbl.c: $(src)/$(FONTMAPFILE)
112 112
113$(obj)/defkeymap.o: $(obj)/defkeymap.c 113$(obj)/defkeymap.o: $(obj)/defkeymap.c
114 114
115$(obj)/qtronixmap.o: $(obj)/qtronixmap.c
116
117# Uncomment if you're changing the keymap and have an appropriate 115# Uncomment if you're changing the keymap and have an appropriate
118# loadkeys version for the map. By default, we'll use the shipped 116# loadkeys version for the map. By default, we'll use the shipped
119# versions. 117# versions.
@@ -121,7 +119,7 @@ $(obj)/qtronixmap.o: $(obj)/qtronixmap.c
121 119
122ifdef GENERATE_KEYMAP 120ifdef GENERATE_KEYMAP
123 121
124$(obj)/defkeymap.c $(obj)/qtronixmap.c: $(obj)/%.c: $(src)/%.map 122$(obj)/defkeymap.c $(obj)/%.c: $(src)/%.map
125 loadkeys --mktable $< > $@.tmp 123 loadkeys --mktable $< > $@.tmp
126 sed -e 's/^static *//' $@.tmp > $@ 124 sed -e 's/^static *//' $@.tmp > $@
127 rm $@.tmp 125 rm $@.tmp
diff --git a/drivers/char/agp/Kconfig b/drivers/char/agp/Kconfig
index 3d7cad7841de..a9f9c48c2424 100644
--- a/drivers/char/agp/Kconfig
+++ b/drivers/char/agp/Kconfig
@@ -1,6 +1,6 @@
1config AGP 1config AGP
2 tristate "/dev/agpgart (AGP Support)" 2 tristate "/dev/agpgart (AGP Support)"
3 depends on ALPHA || IA64 || PPC || X86 3 depends on ALPHA || IA64 || PARISC || PPC || X86
4 depends on PCI 4 depends on PCI
5 ---help--- 5 ---help---
6 AGP (Accelerated Graphics Port) is a bus system mainly used to 6 AGP (Accelerated Graphics Port) is a bus system mainly used to
@@ -122,6 +122,14 @@ config AGP_HP_ZX1
122 This option gives you AGP GART support for the HP ZX1 chipset 122 This option gives you AGP GART support for the HP ZX1 chipset
123 for IA64 processors. 123 for IA64 processors.
124 124
125config AGP_PARISC
126 tristate "HP Quicksilver AGP support"
127 depends on AGP && PARISC && 64BIT
128 help
129 This option gives you AGP GART support for the HP Quicksilver
130 AGP bus adapter on HP PA-RISC machines (Ok, just on the C8000
131 workstation...)
132
125config AGP_ALPHA_CORE 133config AGP_ALPHA_CORE
126 tristate "Alpha AGP support" 134 tristate "Alpha AGP support"
127 depends on AGP && (ALPHA_GENERIC || ALPHA_TITAN || ALPHA_MARVEL) 135 depends on AGP && (ALPHA_GENERIC || ALPHA_TITAN || ALPHA_MARVEL)
diff --git a/drivers/char/agp/Makefile b/drivers/char/agp/Makefile
index d33a22f2fa0b..3e581603d0a8 100644
--- a/drivers/char/agp/Makefile
+++ b/drivers/char/agp/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_AGP_AMD64) += amd64-agp.o
8obj-$(CONFIG_AGP_ALPHA_CORE) += alpha-agp.o 8obj-$(CONFIG_AGP_ALPHA_CORE) += alpha-agp.o
9obj-$(CONFIG_AGP_EFFICEON) += efficeon-agp.o 9obj-$(CONFIG_AGP_EFFICEON) += efficeon-agp.o
10obj-$(CONFIG_AGP_HP_ZX1) += hp-agp.o 10obj-$(CONFIG_AGP_HP_ZX1) += hp-agp.o
11obj-$(CONFIG_AGP_PARISC) += parisc-agp.o
11obj-$(CONFIG_AGP_I460) += i460-agp.o 12obj-$(CONFIG_AGP_I460) += i460-agp.o
12obj-$(CONFIG_AGP_INTEL) += intel-agp.o 13obj-$(CONFIG_AGP_INTEL) += intel-agp.o
13obj-$(CONFIG_AGP_NVIDIA) += nvidia-agp.o 14obj-$(CONFIG_AGP_NVIDIA) += nvidia-agp.o
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
index ca4629f66d17..883a36a27833 100644
--- a/drivers/char/agp/generic.c
+++ b/drivers/char/agp/generic.c
@@ -1079,7 +1079,7 @@ void *agp_generic_alloc_page(struct agp_bridge_data *bridge)
1079{ 1079{
1080 struct page * page; 1080 struct page * page;
1081 1081
1082 page = alloc_page(GFP_KERNEL); 1082 page = alloc_page(GFP_KERNEL | GFP_DMA32);
1083 if (page == NULL) 1083 if (page == NULL)
1084 return NULL; 1084 return NULL;
1085 1085
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index d1ede7db5a12..555b3a8ab49c 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -169,7 +169,7 @@ static void *i8xx_alloc_pages(void)
169{ 169{
170 struct page * page; 170 struct page * page;
171 171
172 page = alloc_pages(GFP_KERNEL, 2); 172 page = alloc_pages(GFP_KERNEL | GFP_DMA32, 2);
173 if (page == NULL) 173 if (page == NULL)
174 return NULL; 174 return NULL;
175 175
@@ -387,11 +387,7 @@ static void intel_i830_init_gtt_entries(void)
387 /* We obtain the size of the GTT, which is also stored (for some 387 /* We obtain the size of the GTT, which is also stored (for some
388 * reason) at the top of stolen memory. Then we add 4KB to that 388 * reason) at the top of stolen memory. Then we add 4KB to that
389 * for the video BIOS popup, which is also stored in there. */ 389 * for the video BIOS popup, which is also stored in there. */
390 390 size = agp_bridge->driver->fetch_size() + 4;
391 if (IS_I965)
392 size = 512 + 4;
393 else
394 size = agp_bridge->driver->fetch_size() + 4;
395 391
396 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82830_HB || 392 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82830_HB ||
397 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) { 393 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) {
@@ -805,6 +801,26 @@ static int intel_i915_create_gatt_table(struct agp_bridge_data *bridge)
805 801
806 return 0; 802 return 0;
807} 803}
804
805/*
806 * The i965 supports 36-bit physical addresses, but to keep
807 * the format of the GTT the same, the bits that don't fit
808 * in a 32-bit word are shifted down to bits 4..7.
809 *
810 * Gcc is smart enough to notice that "(addr >> 28) & 0xf0"
811 * is always zero on 32-bit architectures, so no need to make
812 * this conditional.
813 */
814static unsigned long intel_i965_mask_memory(struct agp_bridge_data *bridge,
815 unsigned long addr, int type)
816{
817 /* Shift high bits down */
818 addr |= (addr >> 28) & 0xf0;
819
820 /* Type checking must be done elsewhere */
821 return addr | bridge->driver->masks[type].mask;
822}
823
808static int intel_i965_fetch_size(void) 824static int intel_i965_fetch_size(void)
809{ 825{
810 struct aper_size_info_fixed *values; 826 struct aper_size_info_fixed *values;
@@ -832,7 +848,8 @@ static int intel_i965_fetch_size(void)
832 848
833 agp_bridge->previous_size = agp_bridge->current_size = (void *)(values + offset); 849 agp_bridge->previous_size = agp_bridge->current_size = (void *)(values + offset);
834 850
835 return values[offset].size; 851 /* The i965 GTT is always sized as if it had a 512kB aperture size */
852 return 512;
836} 853}
837 854
838/* The intel i965 automatically initializes the agp aperture during POST. 855/* The intel i965 automatically initializes the agp aperture during POST.
@@ -1584,7 +1601,7 @@ static struct agp_bridge_driver intel_i965_driver = {
1584 .fetch_size = intel_i965_fetch_size, 1601 .fetch_size = intel_i965_fetch_size,
1585 .cleanup = intel_i915_cleanup, 1602 .cleanup = intel_i915_cleanup,
1586 .tlb_flush = intel_i810_tlbflush, 1603 .tlb_flush = intel_i810_tlbflush,
1587 .mask_memory = intel_i810_mask_memory, 1604 .mask_memory = intel_i965_mask_memory,
1588 .masks = intel_i810_masks, 1605 .masks = intel_i810_masks,
1589 .agp_enable = intel_i810_agp_enable, 1606 .agp_enable = intel_i810_agp_enable,
1590 .cache_flush = global_cache_flush, 1607 .cache_flush = global_cache_flush,
diff --git a/drivers/char/agp/parisc-agp.c b/drivers/char/agp/parisc-agp.c
new file mode 100644
index 000000000000..17c50b0f83f0
--- /dev/null
+++ b/drivers/char/agp/parisc-agp.c
@@ -0,0 +1,416 @@
1/*
2 * HP Quicksilver AGP GART routines
3 *
4 * Copyright (c) 2006, Kyle McMartin <kyle@parisc-linux.org>
5 *
6 * Based on drivers/char/agpgart/hp-agp.c which is
7 * (c) Copyright 2002, 2003 Hewlett-Packard Development Company, L.P.
8 * Bjorn Helgaas <bjorn.helgaas@hp.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 */
15
16#include <linux/module.h>
17#include <linux/pci.h>
18#include <linux/init.h>
19#include <linux/klist.h>
20#include <linux/agp_backend.h>
21
22#include <asm-parisc/parisc-device.h>
23#include <asm-parisc/ropes.h>
24
25#include "agp.h"
26
27#define DRVNAME "quicksilver"
28#define DRVPFX DRVNAME ": "
29
30#ifndef log2
31#define log2(x) ffz(~(x))
32#endif
33
34#define AGP8X_MODE_BIT 3
35#define AGP8X_MODE (1 << AGP8X_MODE_BIT)
36
37static struct _parisc_agp_info {
38 void __iomem *ioc_regs;
39 void __iomem *lba_regs;
40
41 int lba_cap_offset;
42
43 u64 *gatt;
44 u64 gatt_entries;
45
46 u64 gart_base;
47 u64 gart_size;
48
49 int io_page_size;
50 int io_pages_per_kpage;
51} parisc_agp_info;
52
53static struct gatt_mask parisc_agp_masks[] =
54{
55 {
56 .mask = SBA_PDIR_VALID_BIT,
57 .type = 0
58 }
59};
60
61static struct aper_size_info_fixed parisc_agp_sizes[] =
62{
63 {0, 0, 0}, /* filled in by parisc_agp_fetch_size() */
64};
65
66static int
67parisc_agp_fetch_size(void)
68{
69 int size;
70
71 size = parisc_agp_info.gart_size / MB(1);
72 parisc_agp_sizes[0].size = size;
73 agp_bridge->current_size = (void *) &parisc_agp_sizes[0];
74
75 return size;
76}
77
78static int
79parisc_agp_configure(void)
80{
81 struct _parisc_agp_info *info = &parisc_agp_info;
82
83 agp_bridge->gart_bus_addr = info->gart_base;
84 agp_bridge->capndx = info->lba_cap_offset;
85 agp_bridge->mode = readl(info->lba_regs+info->lba_cap_offset+PCI_AGP_STATUS);
86
87 return 0;
88}
89
90static void
91parisc_agp_tlbflush(struct agp_memory *mem)
92{
93 struct _parisc_agp_info *info = &parisc_agp_info;
94
95 writeq(info->gart_base | log2(info->gart_size), info->ioc_regs+IOC_PCOM);
96 readq(info->ioc_regs+IOC_PCOM); /* flush */
97}
98
99static int
100parisc_agp_create_gatt_table(struct agp_bridge_data *bridge)
101{
102 struct _parisc_agp_info *info = &parisc_agp_info;
103 int i;
104
105 for (i = 0; i < info->gatt_entries; i++) {
106 info->gatt[i] = (unsigned long)agp_bridge->scratch_page;
107 }
108
109 return 0;
110}
111
112static int
113parisc_agp_free_gatt_table(struct agp_bridge_data *bridge)
114{
115 struct _parisc_agp_info *info = &parisc_agp_info;
116
117 info->gatt[0] = SBA_AGPGART_COOKIE;
118
119 return 0;
120}
121
122static int
123parisc_agp_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
124{
125 struct _parisc_agp_info *info = &parisc_agp_info;
126 int i, k;
127 off_t j, io_pg_start;
128 int io_pg_count;
129
130 if (type != 0 || mem->type != 0) {
131 return -EINVAL;
132 }
133
134 io_pg_start = info->io_pages_per_kpage * pg_start;
135 io_pg_count = info->io_pages_per_kpage * mem->page_count;
136 if ((io_pg_start + io_pg_count) > info->gatt_entries) {
137 return -EINVAL;
138 }
139
140 j = io_pg_start;
141 while (j < (io_pg_start + io_pg_count)) {
142 if (info->gatt[j])
143 return -EBUSY;
144 j++;
145 }
146
147 if (mem->is_flushed == FALSE) {
148 global_cache_flush();
149 mem->is_flushed = TRUE;
150 }
151
152 for (i = 0, j = io_pg_start; i < mem->page_count; i++) {
153 unsigned long paddr;
154
155 paddr = mem->memory[i];
156 for (k = 0;
157 k < info->io_pages_per_kpage;
158 k++, j++, paddr += info->io_page_size) {
159 info->gatt[j] =
160 agp_bridge->driver->mask_memory(agp_bridge,
161 paddr, type);
162 }
163 }
164
165 agp_bridge->driver->tlb_flush(mem);
166
167 return 0;
168}
169
170static int
171parisc_agp_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
172{
173 struct _parisc_agp_info *info = &parisc_agp_info;
174 int i, io_pg_start, io_pg_count;
175
176 if (type != 0 || mem->type != 0) {
177 return -EINVAL;
178 }
179
180 io_pg_start = info->io_pages_per_kpage * pg_start;
181 io_pg_count = info->io_pages_per_kpage * mem->page_count;
182 for (i = io_pg_start; i < io_pg_count + io_pg_start; i++) {
183 info->gatt[i] = agp_bridge->scratch_page;
184 }
185
186 agp_bridge->driver->tlb_flush(mem);
187 return 0;
188}
189
190static unsigned long
191parisc_agp_mask_memory(struct agp_bridge_data *bridge,
192 unsigned long addr, int type)
193{
194 return SBA_PDIR_VALID_BIT | addr;
195}
196
197static void
198parisc_agp_enable(struct agp_bridge_data *bridge, u32 mode)
199{
200 struct _parisc_agp_info *info = &parisc_agp_info;
201 u32 command;
202
203 command = readl(info->lba_regs + info->lba_cap_offset + PCI_AGP_STATUS);
204
205 command = agp_collect_device_status(bridge, mode, command);
206 command |= 0x00000100;
207
208 writel(command, info->lba_regs + info->lba_cap_offset + PCI_AGP_COMMAND);
209
210 agp_device_command(command, (mode & AGP8X_MODE) != 0);
211}
212
213struct agp_bridge_driver parisc_agp_driver = {
214 .owner = THIS_MODULE,
215 .size_type = FIXED_APER_SIZE,
216 .configure = parisc_agp_configure,
217 .fetch_size = parisc_agp_fetch_size,
218 .tlb_flush = parisc_agp_tlbflush,
219 .mask_memory = parisc_agp_mask_memory,
220 .masks = parisc_agp_masks,
221 .agp_enable = parisc_agp_enable,
222 .cache_flush = global_cache_flush,
223 .create_gatt_table = parisc_agp_create_gatt_table,
224 .free_gatt_table = parisc_agp_free_gatt_table,
225 .insert_memory = parisc_agp_insert_memory,
226 .remove_memory = parisc_agp_remove_memory,
227 .alloc_by_type = agp_generic_alloc_by_type,
228 .free_by_type = agp_generic_free_by_type,
229 .agp_alloc_page = agp_generic_alloc_page,
230 .agp_destroy_page = agp_generic_destroy_page,
231 .cant_use_aperture = 1,
232};
233
234static int __init
235agp_ioc_init(void __iomem *ioc_regs)
236{
237 struct _parisc_agp_info *info = &parisc_agp_info;
238 u64 *iova_base, *io_pdir, io_tlb_ps;
239 int io_tlb_shift;
240
241 printk(KERN_INFO DRVPFX "IO PDIR shared with sba_iommu\n");
242
243 info->ioc_regs = ioc_regs;
244
245 io_tlb_ps = readq(info->ioc_regs+IOC_TCNFG);
246 switch (io_tlb_ps) {
247 case 0: io_tlb_shift = 12; break;
248 case 1: io_tlb_shift = 13; break;
249 case 2: io_tlb_shift = 14; break;
250 case 3: io_tlb_shift = 16; break;
251 default:
252 printk(KERN_ERR DRVPFX "Invalid IOTLB page size "
253 "configuration 0x%llx\n", io_tlb_ps);
254 info->gatt = NULL;
255 info->gatt_entries = 0;
256 return -ENODEV;
257 }
258 info->io_page_size = 1 << io_tlb_shift;
259 info->io_pages_per_kpage = PAGE_SIZE / info->io_page_size;
260
261 iova_base = readq(info->ioc_regs+IOC_IBASE) & ~0x1;
262 info->gart_base = iova_base + PLUTO_IOVA_SIZE - PLUTO_GART_SIZE;
263
264 info->gart_size = PLUTO_GART_SIZE;
265 info->gatt_entries = info->gart_size / info->io_page_size;
266
267 io_pdir = phys_to_virt(readq(info->ioc_regs+IOC_PDIR_BASE));
268 info->gatt = &io_pdir[(PLUTO_IOVA_SIZE/2) >> PAGE_SHIFT];
269
270 if (info->gatt[0] != SBA_AGPGART_COOKIE) {
271 info->gatt = NULL;
272 info->gatt_entries = 0;
273 printk(KERN_ERR DRVPFX "No reserved IO PDIR entry found; "
274 "GART disabled\n");
275 return -ENODEV;
276 }
277
278 return 0;
279}
280
281static int
282lba_find_capability(int cap)
283{
284 struct _parisc_agp_info *info = &parisc_agp_info;
285 u16 status;
286 u8 pos, id;
287 int ttl = 48;
288
289 status = readw(info->lba_regs + PCI_STATUS);
290 if (!(status & PCI_STATUS_CAP_LIST))
291 return 0;
292 pos = readb(info->lba_regs + PCI_CAPABILITY_LIST);
293 while (ttl-- && pos >= 0x40) {
294 pos &= ~3;
295 id = readb(info->lba_regs + pos + PCI_CAP_LIST_ID);
296 if (id == 0xff)
297 break;
298 if (id == cap)
299 return pos;
300 pos = readb(info->lba_regs + pos + PCI_CAP_LIST_NEXT);
301 }
302 return 0;
303}
304
305static int __init
306agp_lba_init(void __iomem *lba_hpa)
307{
308 struct _parisc_agp_info *info = &parisc_agp_info;
309 int cap;
310
311 info->lba_regs = lba_hpa;
312 info->lba_cap_offset = lba_find_capability(PCI_CAP_ID_AGP);
313
314 cap = readl(lba_hpa + info->lba_cap_offset) & 0xff;
315 if (cap != PCI_CAP_ID_AGP) {
316 printk(KERN_ERR DRVPFX "Invalid capability ID 0x%02x at 0x%x\n",
317 cap, info->lba_cap_offset);
318 return -ENODEV;
319 }
320
321 return 0;
322}
323
324static int __init
325parisc_agp_setup(void __iomem *ioc_hpa, void __iomem *lba_hpa)
326{
327 struct pci_dev *fake_bridge_dev = NULL;
328 struct agp_bridge_data *bridge;
329 int error = 0;
330
331 fake_bridge_dev = kmalloc(sizeof (struct pci_dev), GFP_KERNEL);
332 if (!fake_bridge_dev) {
333 error = -ENOMEM;
334 goto fail;
335 }
336
337 error = agp_ioc_init(ioc_hpa);
338 if (error)
339 goto fail;
340
341 error = agp_lba_init(lba_hpa);
342 if (error)
343 goto fail;
344
345 bridge = agp_alloc_bridge();
346 if (!bridge) {
347 error = -ENOMEM;
348 goto fail;
349 }
350 bridge->driver = &parisc_agp_driver;
351
352 fake_bridge_dev->vendor = PCI_VENDOR_ID_HP;
353 fake_bridge_dev->device = PCI_DEVICE_ID_HP_PCIX_LBA;
354 bridge->dev = fake_bridge_dev;
355
356 error = agp_add_bridge(bridge);
357
358fail:
359 return error;
360}
361
362static struct device *next_device(struct klist_iter *i) {
363 struct klist_node * n = klist_next(i);
364 return n ? container_of(n, struct device, knode_parent) : NULL;
365}
366
367static int
368parisc_agp_init(void)
369{
370 extern struct sba_device *sba_list;
371
372 int err = -1;
373 struct parisc_device *sba = NULL, *lba = NULL;
374 struct lba_device *lbadev = NULL;
375 struct device *dev = NULL;
376 struct klist_iter i;
377
378 if (!sba_list)
379 goto out;
380
381 /* Find our parent Pluto */
382 sba = sba_list->dev;
383 if (!IS_PLUTO(sba)) {
384 printk(KERN_INFO DRVPFX "No Pluto found, so no AGPGART for you.\n");
385 goto out;
386 }
387
388 /* Now search our Pluto for our precious AGP device... */
389 klist_iter_init(&sba->dev.klist_children, &i);
390 while ((dev = next_device(&i))) {
391 struct parisc_device *padev = to_parisc_device(dev);
392 if (IS_QUICKSILVER(padev))
393 lba = padev;
394 }
395 klist_iter_exit(&i);
396
397 if (!lba) {
398 printk(KERN_INFO DRVPFX "No AGP devices found.\n");
399 goto out;
400 }
401
402 lbadev = parisc_get_drvdata(lba);
403
404 /* w00t, let's go find our cookies... */
405 parisc_agp_setup(sba_list->ioc[0].ioc_hpa, lbadev->hba.base_addr);
406
407 return 0;
408
409out:
410 return err;
411}
412
413module_init(parisc_agp_init);
414
415MODULE_AUTHOR("Kyle McMartin <kyle@parisc-linux.org>");
416MODULE_LICENSE("GPL");
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index 9d6713a93ed7..feb4ac802a0d 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -104,7 +104,7 @@ static struct async_struct *IRQ_ports;
104 104
105static unsigned char current_ctl_bits; 105static unsigned char current_ctl_bits;
106 106
107static void change_speed(struct async_struct *info, struct termios *old); 107static void change_speed(struct async_struct *info, struct ktermios *old);
108static void rs_wait_until_sent(struct tty_struct *tty, int timeout); 108static void rs_wait_until_sent(struct tty_struct *tty, int timeout);
109 109
110 110
@@ -112,17 +112,6 @@ static struct serial_state rs_table[1];
112 112
113#define NR_PORTS ARRAY_SIZE(rs_table) 113#define NR_PORTS ARRAY_SIZE(rs_table)
114 114
115/*
116 * tmp_buf is used as a temporary buffer by serial_write. We need to
117 * lock it in case the copy_from_user blocks while swapping in a page,
118 * and some other program tries to do a serial write at the same time.
119 * Since the lock will only come under contention when the system is
120 * swapping and available memory is low, it makes sense to share one
121 * buffer across all the serial ports, since it significantly saves
122 * memory if large numbers of serial ports are open.
123 */
124static unsigned char *tmp_buf;
125
126#include <asm/uaccess.h> 115#include <asm/uaccess.h>
127 116
128#define serial_isroot() (capable(CAP_SYS_ADMIN)) 117#define serial_isroot() (capable(CAP_SYS_ADMIN))
@@ -458,7 +447,7 @@ static void check_modem_status(struct async_struct *info)
458 } 447 }
459} 448}
460 449
461static irqreturn_t ser_vbl_int( int irq, void *data, struct pt_regs *regs) 450static irqreturn_t ser_vbl_int( int irq, void *data)
462{ 451{
463 /* vbl is just a periodic interrupt we tie into to update modem status */ 452 /* vbl is just a periodic interrupt we tie into to update modem status */
464 struct async_struct * info = IRQ_ports; 453 struct async_struct * info = IRQ_ports;
@@ -471,7 +460,7 @@ static irqreturn_t ser_vbl_int( int irq, void *data, struct pt_regs *regs)
471 return IRQ_HANDLED; 460 return IRQ_HANDLED;
472} 461}
473 462
474static irqreturn_t ser_rx_int(int irq, void *dev_id, struct pt_regs * regs) 463static irqreturn_t ser_rx_int(int irq, void *dev_id)
475{ 464{
476 struct async_struct * info; 465 struct async_struct * info;
477 466
@@ -491,7 +480,7 @@ static irqreturn_t ser_rx_int(int irq, void *dev_id, struct pt_regs * regs)
491 return IRQ_HANDLED; 480 return IRQ_HANDLED;
492} 481}
493 482
494static irqreturn_t ser_tx_int(int irq, void *dev_id, struct pt_regs * regs) 483static irqreturn_t ser_tx_int(int irq, void *dev_id)
495{ 484{
496 struct async_struct * info; 485 struct async_struct * info;
497 486
@@ -705,7 +694,7 @@ static void shutdown(struct async_struct * info)
705 * the specified baud rate for a serial port. 694 * the specified baud rate for a serial port.
706 */ 695 */
707static void change_speed(struct async_struct *info, 696static void change_speed(struct async_struct *info,
708 struct termios *old_termios) 697 struct ktermios *old_termios)
709{ 698{
710 int quot = 0, baud_base, baud; 699 int quot = 0, baud_base, baud;
711 unsigned cflag, cval = 0; 700 unsigned cflag, cval = 0;
@@ -912,7 +901,7 @@ static int rs_write(struct tty_struct * tty, const unsigned char *buf, int count
912 if (serial_paranoia_check(info, tty->name, "rs_write")) 901 if (serial_paranoia_check(info, tty->name, "rs_write"))
913 return 0; 902 return 0;
914 903
915 if (!info->xmit.buf || !tmp_buf) 904 if (!info->xmit.buf)
916 return 0; 905 return 0;
917 906
918 local_save_flags(flags); 907 local_save_flags(flags);
@@ -1376,7 +1365,7 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file,
1376 return 0; 1365 return 0;
1377} 1366}
1378 1367
1379static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios) 1368static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1380{ 1369{
1381 struct async_struct *info = (struct async_struct *)tty->driver_data; 1370 struct async_struct *info = (struct async_struct *)tty->driver_data;
1382 unsigned long flags; 1371 unsigned long flags;
@@ -1778,7 +1767,6 @@ static int rs_open(struct tty_struct *tty, struct file * filp)
1778{ 1767{
1779 struct async_struct *info; 1768 struct async_struct *info;
1780 int retval, line; 1769 int retval, line;
1781 unsigned long page;
1782 1770
1783 line = tty->index; 1771 line = tty->index;
1784 if ((line < 0) || (line >= NR_PORTS)) { 1772 if ((line < 0) || (line >= NR_PORTS)) {
@@ -1798,17 +1786,6 @@ static int rs_open(struct tty_struct *tty, struct file * filp)
1798#endif 1786#endif
1799 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1787 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1800 1788
1801 if (!tmp_buf) {
1802 page = get_zeroed_page(GFP_KERNEL);
1803 if (!page) {
1804 return -ENOMEM;
1805 }
1806 if (tmp_buf)
1807 free_page(page);
1808 else
1809 tmp_buf = (unsigned char *) page;
1810 }
1811
1812 /* 1789 /*
1813 * If the port is the middle of closing, bail out now 1790 * If the port is the middle of closing, bail out now
1814 */ 1791 */
@@ -1958,7 +1935,7 @@ static void show_serial_version(void)
1958} 1935}
1959 1936
1960 1937
1961static struct tty_operations serial_ops = { 1938static const struct tty_operations serial_ops = {
1962 .open = rs_open, 1939 .open = rs_open,
1963 .close = rs_close, 1940 .close = rs_close,
1964 .write = rs_write, 1941 .write = rs_write,
@@ -2090,11 +2067,6 @@ static __exit void rs_exit(void)
2090 kfree(info); 2067 kfree(info);
2091 } 2068 }
2092 2069
2093 if (tmp_buf) {
2094 free_page((unsigned long) tmp_buf);
2095 tmp_buf = NULL;
2096 }
2097
2098 release_mem_region(CUSTOM_PHYSADDR+0x30, 4); 2070 release_mem_region(CUSTOM_PHYSADDR+0x30, 4);
2099} 2071}
2100 2072
diff --git a/drivers/char/applicom.c b/drivers/char/applicom.c
index 10a389dafd60..1f0b752e5de1 100644
--- a/drivers/char/applicom.c
+++ b/drivers/char/applicom.c
@@ -110,7 +110,7 @@ static ssize_t ac_read (struct file *, char __user *, size_t, loff_t *);
110static ssize_t ac_write (struct file *, const char __user *, size_t, loff_t *); 110static ssize_t ac_write (struct file *, const char __user *, size_t, loff_t *);
111static int ac_ioctl(struct inode *, struct file *, unsigned int, 111static int ac_ioctl(struct inode *, struct file *, unsigned int,
112 unsigned long); 112 unsigned long);
113static irqreturn_t ac_interrupt(int, void *, struct pt_regs *); 113static irqreturn_t ac_interrupt(int, void *);
114 114
115static const struct file_operations ac_fops = { 115static const struct file_operations ac_fops = {
116 .owner = THIS_MODULE, 116 .owner = THIS_MODULE,
@@ -617,7 +617,7 @@ static ssize_t ac_read (struct file *filp, char __user *buf, size_t count, loff_
617 } 617 }
618} 618}
619 619
620static irqreturn_t ac_interrupt(int vec, void *dev_instance, struct pt_regs *regs) 620static irqreturn_t ac_interrupt(int vec, void *dev_instance)
621{ 621{
622 unsigned int i; 622 unsigned int i;
623 unsigned int FlagInt; 623 unsigned int FlagInt;
diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
index b8c22255f6ad..9f8082f8dd29 100644
--- a/drivers/char/briq_panel.c
+++ b/drivers/char/briq_panel.c
@@ -11,7 +11,6 @@
11#include <linux/sched.h> 11#include <linux/sched.h>
12#include <linux/tty.h> 12#include <linux/tty.h>
13#include <linux/timer.h> 13#include <linux/timer.h>
14#include <linux/config.h>
15#include <linux/kernel.h> 14#include <linux/kernel.h>
16#include <linux/wait.h> 15#include <linux/wait.h>
17#include <linux/string.h> 16#include <linux/string.h>
diff --git a/drivers/char/cs5535_gpio.c b/drivers/char/cs5535_gpio.c
index 8ce3f34cfc22..c02d9e99e050 100644
--- a/drivers/char/cs5535_gpio.c
+++ b/drivers/char/cs5535_gpio.c
@@ -82,7 +82,7 @@ static inline u32 cs5535_lowhigh_base(int reg)
82static ssize_t cs5535_gpio_write(struct file *file, const char __user *data, 82static ssize_t cs5535_gpio_write(struct file *file, const char __user *data,
83 size_t len, loff_t *ppos) 83 size_t len, loff_t *ppos)
84{ 84{
85 u32 m = iminor(file->f_dentry->d_inode); 85 u32 m = iminor(file->f_path.dentry->d_inode);
86 int i, j; 86 int i, j;
87 u32 base = gpio_base + cs5535_lowhigh_base(m); 87 u32 base = gpio_base + cs5535_lowhigh_base(m);
88 u32 m0, m1; 88 u32 m0, m1;
@@ -117,7 +117,7 @@ static ssize_t cs5535_gpio_write(struct file *file, const char __user *data,
117static ssize_t cs5535_gpio_read(struct file *file, char __user *buf, 117static ssize_t cs5535_gpio_read(struct file *file, char __user *buf,
118 size_t len, loff_t *ppos) 118 size_t len, loff_t *ppos)
119{ 119{
120 u32 m = iminor(file->f_dentry->d_inode); 120 u32 m = iminor(file->f_path.dentry->d_inode);
121 u32 base = gpio_base + cs5535_lowhigh_base(m); 121 u32 base = gpio_base + cs5535_lowhigh_base(m);
122 int rd_bit = 1 << (m & 0x0f); 122 int rd_bit = 1 << (m & 0x0f);
123 int i; 123 int i;
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index c1c67281750d..3ffa0807754c 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -1,8 +1,6 @@
1#undef BLOCKMOVE 1#undef BLOCKMOVE
2#define Z_WAKE 2#define Z_WAKE
3#undef Z_EXT_CHARS_IN_BUFFER 3#undef Z_EXT_CHARS_IN_BUFFER
4static char rcsid[] =
5"$Revision: 2.3.2.20 $$Date: 2004/02/25 18:14:16 $";
6 4
7/* 5/*
8 * linux/drivers/char/cyclades.c 6 * linux/drivers/char/cyclades.c
@@ -593,18 +591,20 @@ static char rcsid[] =
593 * 591 *
594 */ 592 */
595 593
594#define CY_VERSION "2.4"
595
596/* If you need to install more boards than NR_CARDS, change the constant 596/* If you need to install more boards than NR_CARDS, change the constant
597 in the definition below. No other change is necessary to support up to 597 in the definition below. No other change is necessary to support up to
598 eight boards. Beyond that you'll have to extend cy_isa_addresses. */ 598 eight boards. Beyond that you'll have to extend cy_isa_addresses. */
599 599
600#define NR_CARDS 4 600#define NR_CARDS 4
601 601
602/* 602/*
603 If the total number of ports is larger than NR_PORTS, change this 603 If the total number of ports is larger than NR_PORTS, change this
604 constant in the definition below. No other change is necessary to 604 constant in the definition below. No other change is necessary to
605 support more boards/ports. */ 605 support more boards/ports. */
606 606
607#define NR_PORTS 256 607#define NR_PORTS 256
608 608
609#define ZE_V1_NPORTS 64 609#define ZE_V1_NPORTS 64
610#define ZO_V1 0 610#define ZO_V1 0
@@ -625,9 +625,9 @@ static char rcsid[] =
625#undef CY_PCI_DEBUG 625#undef CY_PCI_DEBUG
626 626
627#if 0 627#if 0
628#define PAUSE __asm__("nop"); 628#define PAUSE __asm__("nop")
629#else 629#else
630#define PAUSE ; 630#define PAUSE do {} while (0)
631#endif 631#endif
632 632
633/* 633/*
@@ -663,7 +663,7 @@ static char rcsid[] =
663 do { \ 663 do { \
664 spin_lock_irqsave(&cy_card[info->card].card_lock, flags); \ 664 spin_lock_irqsave(&cy_card[info->card].card_lock, flags); \
665 } while (0) 665 } while (0)
666 666
667#define CY_UNLOCK(info,flags) \ 667#define CY_UNLOCK(info,flags) \
668 do { \ 668 do { \
669 spin_unlock_irqrestore(&cy_card[info->card].card_lock, flags); \ 669 spin_unlock_irqrestore(&cy_card[info->card].card_lock, flags); \
@@ -676,14 +676,14 @@ static char rcsid[] =
676#include <linux/stat.h> 676#include <linux/stat.h>
677#include <linux/proc_fs.h> 677#include <linux/proc_fs.h>
678 678
679static void cy_throttle (struct tty_struct *tty); 679static void cy_throttle(struct tty_struct *tty);
680static void cy_send_xchar (struct tty_struct *tty, char ch); 680static void cy_send_xchar(struct tty_struct *tty, char ch);
681 681
682#define IS_CYC_Z(card) ((card).num_chips == -1) 682#define IS_CYC_Z(card) ((card).num_chips == -1)
683 683
684#define Z_FPGA_CHECK(card) \ 684#define Z_FPGA_CHECK(card) \
685 ((cy_readl(&((struct RUNTIME_9060 __iomem *) \ 685 ((cy_readl(&((struct RUNTIME_9060 __iomem *) \
686 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0) 686 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0)
687 687
688#define ISZLOADED(card) (((ZO_V1==cy_readl(&((struct RUNTIME_9060 __iomem *) \ 688#define ISZLOADED(card) (((ZO_V1==cy_readl(&((struct RUNTIME_9060 __iomem *) \
689 ((card).ctl_addr))->mail_box_0)) || \ 689 ((card).ctl_addr))->mail_box_0)) || \
@@ -698,8 +698,6 @@ static void cy_send_xchar (struct tty_struct *tty, char ch);
698 698
699#define STD_COM_FLAGS (0) 699#define STD_COM_FLAGS (0)
700 700
701#define JIFFIES_DIFF(n, j) ((j) - (n))
702
703static struct tty_driver *cy_serial_driver; 701static struct tty_driver *cy_serial_driver;
704 702
705#ifdef CONFIG_ISA 703#ifdef CONFIG_ISA
@@ -713,27 +711,28 @@ static struct tty_driver *cy_serial_driver;
713*/ 711*/
714 712
715static unsigned int cy_isa_addresses[] = { 713static unsigned int cy_isa_addresses[] = {
716 0xD0000, 714 0xD0000,
717 0xD2000, 715 0xD2000,
718 0xD4000, 716 0xD4000,
719 0xD6000, 717 0xD6000,
720 0xD8000, 718 0xD8000,
721 0xDA000, 719 0xDA000,
722 0xDC000, 720 0xDC000,
723 0xDE000, 721 0xDE000,
724 0,0,0,0,0,0,0,0 722 0, 0, 0, 0, 0, 0, 0, 0
725}; 723};
724
726#define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses) 725#define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses)
727 726
728#ifdef MODULE 727#ifdef MODULE
729static long maddr[NR_CARDS] = { 0, }; 728static long maddr[NR_CARDS] = { 0, };
730static int irq[NR_CARDS] = { 0, }; 729static int irq[NR_CARDS] = { 0, };
731 730
732module_param_array(maddr, long, NULL, 0); 731module_param_array(maddr, long, NULL, 0);
733module_param_array(irq, int, NULL, 0); 732module_param_array(irq, int, NULL, 0);
734#endif 733#endif
735 734
736#endif /* CONFIG_ISA */ 735#endif /* CONFIG_ISA */
737 736
738/* This is the per-card data structure containing address, irq, number of 737/* This is the per-card data structure containing address, irq, number of
739 channels, etc. This driver supports a maximum of NR_CARDS cards. 738 channels, etc. This driver supports a maximum of NR_CARDS cards.
@@ -745,19 +744,7 @@ static struct cyclades_card cy_card[NR_CARDS];
745*/ 744*/
746static struct cyclades_port cy_port[NR_PORTS]; 745static struct cyclades_port cy_port[NR_PORTS];
747 746
748static int cy_next_channel; /* next minor available */ 747static int cy_next_channel; /* next minor available */
749
750/*
751 * tmp_buf is used as a temporary buffer by serial_write. We need to
752 * lock it in case the copy_from_user blocks while swapping in a page,
753 * and some other program tries to do a serial write at the same time.
754 * Since the lock will only come under contention when the system is
755 * swapping and available memory is low, it makes sense to share one
756 * buffer across all the serial ports, since it significantly saves
757 * memory if large numbers of serial ports are open. This buffer is
758 * allocated when the first cy_open occurs.
759 */
760static unsigned char *tmp_buf;
761 748
762/* 749/*
763 * This is used to look up the divisor speeds and the timeouts 750 * This is used to look up the divisor speeds and the timeouts
@@ -769,36 +756,42 @@ static unsigned char *tmp_buf;
769 * 20 756 * 20
770 */ 757 */
771static int baud_table[] = { 758static int baud_table[] = {
772 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 759 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
773 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000, 760 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200, 150000,
774 230400, 0}; 761 230400, 0
775 762};
776static char baud_co_25[] = { /* 25 MHz clock option table */ 763
777 /* value => 00 01 02 03 04 */ 764static char baud_co_25[] = { /* 25 MHz clock option table */
778 /* divide by 8 32 128 512 2048 */ 765 /* value => 00 01 02 03 04 */
779 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02, 766 /* divide by 8 32 128 512 2048 */
780 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 767 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
781 768 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
782static char baud_bpr_25[] = { /* 25 MHz baud rate period table */ 769};
783 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3, 770
784 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15}; 771static char baud_bpr_25[] = { /* 25 MHz baud rate period table */
785 772 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
786static char baud_co_60[] = { /* 60 MHz clock option table (CD1400 J) */ 773 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15
787 /* value => 00 01 02 03 04 */ 774};
788 /* divide by 8 32 128 512 2048 */ 775
789 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 776static char baud_co_60[] = { /* 60 MHz clock option table (CD1400 J) */
790 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 777 /* value => 00 01 02 03 04 */
791 0x00}; 778 /* divide by 8 32 128 512 2048 */
792 779 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03,
793static char baud_bpr_60[] = { /* 60 MHz baud rate period table (CD1400 J) */ 780 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
794 0x00, 0x82, 0x21, 0xff, 0xdb, 0xc3, 0x92, 0x62, 0xc3, 0x62, 781 0x00
795 0x41, 0xc3, 0x62, 0xc3, 0x62, 0xc3, 0x82, 0x62, 0x41, 0x32, 782};
796 0x21}; 783
797 784static char baud_bpr_60[] = { /* 60 MHz baud rate period table (CD1400 J) */
798static char baud_cor3[] = { /* receive threshold */ 785 0x00, 0x82, 0x21, 0xff, 0xdb, 0xc3, 0x92, 0x62, 0xc3, 0x62,
799 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 786 0x41, 0xc3, 0x62, 0xc3, 0x62, 0xc3, 0x82, 0x62, 0x41, 0x32,
800 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07, 787 0x21
801 0x07}; 788};
789
790static char baud_cor3[] = { /* receive threshold */
791 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
792 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07,
793 0x07
794};
802 795
803/* 796/*
804 * The Cyclades driver implements HW flow control as any serial driver. 797 * The Cyclades driver implements HW flow control as any serial driver.
@@ -811,42 +804,42 @@ static char baud_cor3[] = { /* receive threshold */
811 * cables. 804 * cables.
812 */ 805 */
813 806
814static char rflow_thr[] = { /* rflow threshold */ 807static char rflow_thr[] = { /* rflow threshold */
815 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 808 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
816 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 809 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
817 0x0a}; 810 0x0a
811};
818 812
819/* The Cyclom-Ye has placed the sequential chips in non-sequential 813/* The Cyclom-Ye has placed the sequential chips in non-sequential
820 * address order. This look-up table overcomes that problem. 814 * address order. This look-up table overcomes that problem.
821 */ 815 */
822static int cy_chip_offset [] = 816static int cy_chip_offset[] = { 0x0000,
823 { 0x0000, 817 0x0400,
824 0x0400, 818 0x0800,
825 0x0800, 819 0x0C00,
826 0x0C00, 820 0x0200,
827 0x0200, 821 0x0600,
828 0x0600, 822 0x0A00,
829 0x0A00, 823 0x0E00
830 0x0E00 824};
831 };
832 825
833/* PCI related definitions */ 826/* PCI related definitions */
834 827
835static unsigned short cy_pci_nboard; 828static unsigned short cy_pci_nboard;
836static unsigned short cy_isa_nboard; 829static unsigned short cy_isa_nboard;
837static unsigned short cy_nboard; 830static unsigned short cy_nboard;
838#ifdef CONFIG_PCI 831#ifdef CONFIG_PCI
839static unsigned short cy_pci_dev_id[] = { 832static unsigned short cy_pci_dev_id[] = {
840 PCI_DEVICE_ID_CYCLOM_Y_Lo, /* PCI < 1Mb */ 833 PCI_DEVICE_ID_CYCLOM_Y_Lo, /* PCI < 1Mb */
841 PCI_DEVICE_ID_CYCLOM_Y_Hi, /* PCI > 1Mb */ 834 PCI_DEVICE_ID_CYCLOM_Y_Hi, /* PCI > 1Mb */
842 PCI_DEVICE_ID_CYCLOM_4Y_Lo, /* 4Y PCI < 1Mb */ 835 PCI_DEVICE_ID_CYCLOM_4Y_Lo, /* 4Y PCI < 1Mb */
843 PCI_DEVICE_ID_CYCLOM_4Y_Hi, /* 4Y PCI > 1Mb */ 836 PCI_DEVICE_ID_CYCLOM_4Y_Hi, /* 4Y PCI > 1Mb */
844 PCI_DEVICE_ID_CYCLOM_8Y_Lo, /* 8Y PCI < 1Mb */ 837 PCI_DEVICE_ID_CYCLOM_8Y_Lo, /* 8Y PCI < 1Mb */
845 PCI_DEVICE_ID_CYCLOM_8Y_Hi, /* 8Y PCI > 1Mb */ 838 PCI_DEVICE_ID_CYCLOM_8Y_Hi, /* 8Y PCI > 1Mb */
846 PCI_DEVICE_ID_CYCLOM_Z_Lo, /* Z PCI < 1Mb */ 839 PCI_DEVICE_ID_CYCLOM_Z_Lo, /* Z PCI < 1Mb */
847 PCI_DEVICE_ID_CYCLOM_Z_Hi, /* Z PCI > 1Mb */ 840 PCI_DEVICE_ID_CYCLOM_Z_Hi, /* Z PCI > 1Mb */
848 0 /* end of table */ 841 0 /* end of table */
849 }; 842};
850#endif 843#endif
851 844
852static void cy_start(struct tty_struct *); 845static void cy_start(struct tty_struct *);
@@ -854,9 +847,9 @@ static void set_line_char(struct cyclades_port *);
854static int cyz_issue_cmd(struct cyclades_card *, uclong, ucchar, uclong); 847static int cyz_issue_cmd(struct cyclades_card *, uclong, ucchar, uclong);
855#ifdef CONFIG_ISA 848#ifdef CONFIG_ISA
856static unsigned detect_isa_irq(void __iomem *); 849static unsigned detect_isa_irq(void __iomem *);
857#endif /* CONFIG_ISA */ 850#endif /* CONFIG_ISA */
858 851
859static int cyclades_get_proc_info(char *, char **, off_t , int , int *, void *); 852static int cyclades_get_proc_info(char *, char **, off_t, int, int *, void *);
860 853
861#ifndef CONFIG_CYZ_INTR 854#ifndef CONFIG_CYZ_INTR
862static void cyz_poll(unsigned long); 855static void cyz_poll(unsigned long);
@@ -867,41 +860,36 @@ static long cyz_polling_cycle = CZ_DEF_POLL;
867static int cyz_timeron = 0; 860static int cyz_timeron = 0;
868static DEFINE_TIMER(cyz_timerlist, cyz_poll, 0, 0); 861static DEFINE_TIMER(cyz_timerlist, cyz_poll, 0, 0);
869 862
870#else /* CONFIG_CYZ_INTR */ 863#else /* CONFIG_CYZ_INTR */
871static void cyz_rx_restart(unsigned long); 864static void cyz_rx_restart(unsigned long);
872static struct timer_list cyz_rx_full_timer[NR_PORTS]; 865static struct timer_list cyz_rx_full_timer[NR_PORTS];
873#endif /* CONFIG_CYZ_INTR */ 866#endif /* CONFIG_CYZ_INTR */
874 867
875static inline int 868static inline int serial_paranoia_check(struct cyclades_port *info,
876serial_paranoia_check(struct cyclades_port *info, 869 char *name, const char *routine)
877 char *name, const char *routine)
878{ 870{
879#ifdef SERIAL_PARANOIA_CHECK 871#ifdef SERIAL_PARANOIA_CHECK
880 static const char *badmagic = 872 if (!info) {
881 "cyc Warning: bad magic number for serial struct (%s) in %s\n"; 873 printk("cyc Warning: null cyclades_port for (%s) in %s\n",
882 static const char *badinfo = 874 name, routine);
883 "cyc Warning: null cyclades_port for (%s) in %s\n"; 875 return 1;
884 static const char *badrange = 876 }
885 "cyc Warning: cyclades_port out of range for (%s) in %s\n"; 877
886 878 if ((long)info < (long)(&cy_port[0]) ||
887 if (!info) { 879 (long)(&cy_port[NR_PORTS]) < (long)info) {
888 printk(badinfo, name, routine); 880 printk("cyc Warning: cyclades_port out of range for (%s) in "
889 return 1; 881 "%s\n", name, routine);
890 } 882 return 1;
891 883 }
892 if( (long)info < (long)(&cy_port[0]) 884
893 || (long)(&cy_port[NR_PORTS]) < (long)info ){ 885 if (info->magic != CYCLADES_MAGIC) {
894 printk(badrange, name, routine); 886 printk("cyc Warning: bad magic number for serial struct (%s) "
895 return 1; 887 "in %s\n", name, routine);
896 } 888 return 1;
897 889 }
898 if (info->magic != CYCLADES_MAGIC) {
899 printk(badmagic, name, routine);
900 return 1;
901 }
902#endif 890#endif
903 return 0; 891 return 0;
904} /* serial_paranoia_check */ 892} /* serial_paranoia_check */
905 893
906/* 894/*
907 * This routine is used by the interrupt handler to schedule 895 * This routine is used by the interrupt handler to schedule
@@ -909,13 +897,11 @@ serial_paranoia_check(struct cyclades_port *info,
909 * (also known as the "bottom half"). This can be called any 897 * (also known as the "bottom half"). This can be called any
910 * number of times for any channel without harm. 898 * number of times for any channel without harm.
911 */ 899 */
912static inline void 900static inline void cy_sched_event(struct cyclades_port *info, int event)
913cy_sched_event(struct cyclades_port *info, int event)
914{ 901{
915 info->event |= 1 << event; /* remember what kind of event and who */ 902 info->event |= 1 << event; /* remember what kind of event and who */
916 schedule_work(&info->tqueue); 903 schedule_work(&info->tqueue);
917} /* cy_sched_event */ 904} /* cy_sched_event */
918
919 905
920/* 906/*
921 * This routine is used to handle the "bottom half" processing for the 907 * This routine is used to handle the "bottom half" processing for the
@@ -938,44 +924,40 @@ cy_sched_event(struct cyclades_port *info, int event)
938 * had to poll every port to see if that port needed servicing. 924 * had to poll every port to see if that port needed servicing.
939 */ 925 */
940static void 926static void
941do_softint(void *private_) 927do_softint(struct work_struct *work)
942{ 928{
943 struct cyclades_port *info = (struct cyclades_port *) private_; 929 struct cyclades_port *info =
944 struct tty_struct *tty; 930 container_of(work, struct cyclades_port, tqueue);
945 931 struct tty_struct *tty;
946 tty = info->tty; 932
947 if (!tty) 933 tty = info->tty;
948 return; 934 if (!tty)
949 935 return;
950 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) { 936
951 tty_hangup(info->tty); 937 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
952 wake_up_interruptible(&info->open_wait); 938 tty_hangup(info->tty);
953 info->flags &= ~ASYNC_NORMAL_ACTIVE; 939 wake_up_interruptible(&info->open_wait);
954 } 940 info->flags &= ~ASYNC_NORMAL_ACTIVE;
955 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) { 941 }
956 wake_up_interruptible(&info->open_wait); 942 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event))
957 } 943 wake_up_interruptible(&info->open_wait);
958#ifdef CONFIG_CYZ_INTR 944#ifdef CONFIG_CYZ_INTR
959 if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL, &info->event)) { 945 if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL, &info->event)) {
960 if (cyz_rx_full_timer[info->line].function == NULL) { 946 if (cyz_rx_full_timer[info->line].function == NULL) {
961 cyz_rx_full_timer[info->line].expires = jiffies + 1; 947 cyz_rx_full_timer[info->line].expires = jiffies + 1;
962 cyz_rx_full_timer[info->line].function = cyz_rx_restart; 948 cyz_rx_full_timer[info->line].function = cyz_rx_restart;
963 cyz_rx_full_timer[info->line].data = (unsigned long)info; 949 cyz_rx_full_timer[info->line].data =
964 add_timer(&cyz_rx_full_timer[info->line]); 950 (unsigned long)info;
951 add_timer(&cyz_rx_full_timer[info->line]);
952 }
965 } 953 }
966 }
967#endif 954#endif
968 if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP, &info->event)) { 955 if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP, &info->event))
969 wake_up_interruptible(&info->delta_msr_wait); 956 wake_up_interruptible(&info->delta_msr_wait);
970 } 957 tty_wakeup(tty);
971 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
972 tty_wakeup(tty);
973 wake_up_interruptible(&tty->write_wait);
974 }
975#ifdef Z_WAKE 958#ifdef Z_WAKE
976 if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP, &info->event)) { 959 if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP, &info->event))
977 wake_up_interruptible(&info->shutdown_wait); 960 wake_up_interruptible(&info->shutdown_wait);
978 }
979#endif 961#endif
980} /* do_softint */ 962} /* do_softint */
981 963
@@ -990,341 +972,339 @@ do_softint(void *private_)
990 972
991 This function is only called from inside spinlock-protected code. 973 This function is only called from inside spinlock-protected code.
992 */ 974 */
993static int 975static int cyy_issue_cmd(void __iomem * base_addr, u_char cmd, int index)
994cyy_issue_cmd(void __iomem *base_addr, u_char cmd, int index)
995{ 976{
996 volatile int i; 977 volatile int i;
997 978
998 /* Check to see that the previous command has completed */ 979 /* Check to see that the previous command has completed */
999 for(i = 0 ; i < 100 ; i++){ 980 for (i = 0; i < 100; i++) {
1000 if (cy_readb(base_addr+(CyCCR<<index)) == 0){ 981 if (cy_readb(base_addr + (CyCCR << index)) == 0) {
1001 break; 982 break;
983 }
984 udelay(10L);
1002 } 985 }
1003 udelay(10L); 986 /* if the CCR never cleared, the previous command
1004 } 987 didn't finish within the "reasonable time" */
1005 /* if the CCR never cleared, the previous command 988 if (i == 100)
1006 didn't finish within the "reasonable time" */ 989 return -1;
1007 if (i == 100) return (-1);
1008 990
1009 /* Issue the new command */ 991 /* Issue the new command */
1010 cy_writeb(base_addr+(CyCCR<<index), cmd); 992 cy_writeb(base_addr + (CyCCR << index), cmd);
1011 993
1012 return(0); 994 return 0;
1013} /* cyy_issue_cmd */ 995} /* cyy_issue_cmd */
1014 996
1015#ifdef CONFIG_ISA 997#ifdef CONFIG_ISA
1016/* ISA interrupt detection code */ 998/* ISA interrupt detection code */
1017static unsigned 999static unsigned detect_isa_irq(void __iomem * address)
1018detect_isa_irq(void __iomem *address)
1019{ 1000{
1020 int irq; 1001 int irq;
1021 unsigned long irqs, flags; 1002 unsigned long irqs, flags;
1022 int save_xir, save_car; 1003 int save_xir, save_car;
1023 int index = 0; /* IRQ probing is only for ISA */ 1004 int index = 0; /* IRQ probing is only for ISA */
1024 1005
1025 /* forget possible initially masked and pending IRQ */ 1006 /* forget possible initially masked and pending IRQ */
1026 irq = probe_irq_off(probe_irq_on()); 1007 irq = probe_irq_off(probe_irq_on());
1027 1008
1028 /* Clear interrupts on the board first */ 1009 /* Clear interrupts on the board first */
1029 cy_writeb(address + (Cy_ClrIntr<<index), 0); 1010 cy_writeb(address + (Cy_ClrIntr << index), 0);
1030 /* Cy_ClrIntr is 0x1800 */ 1011 /* Cy_ClrIntr is 0x1800 */
1031 1012
1032 irqs = probe_irq_on(); 1013 irqs = probe_irq_on();
1033 /* Wait ... */ 1014 /* Wait ... */
1034 udelay(5000L); 1015 udelay(5000L);
1035 1016
1036 /* Enable the Tx interrupts on the CD1400 */ 1017 /* Enable the Tx interrupts on the CD1400 */
1037 local_irq_save(flags); 1018 local_irq_save(flags);
1038 cy_writeb(address + (CyCAR<<index), 0); 1019 cy_writeb(address + (CyCAR << index), 0);
1039 cyy_issue_cmd(address, CyCHAN_CTL|CyENB_XMTR, index); 1020 cyy_issue_cmd(address, CyCHAN_CTL | CyENB_XMTR, index);
1040 1021
1041 cy_writeb(address + (CyCAR<<index), 0); 1022 cy_writeb(address + (CyCAR << index), 0);
1042 cy_writeb(address + (CySRER<<index), 1023 cy_writeb(address + (CySRER << index),
1043 cy_readb(address + (CySRER<<index)) | CyTxRdy); 1024 cy_readb(address + (CySRER << index)) | CyTxRdy);
1044 local_irq_restore(flags); 1025 local_irq_restore(flags);
1045 1026
1046 /* Wait ... */ 1027 /* Wait ... */
1047 udelay(5000L); 1028 udelay(5000L);
1048 1029
1049 /* Check which interrupt is in use */ 1030 /* Check which interrupt is in use */
1050 irq = probe_irq_off(irqs); 1031 irq = probe_irq_off(irqs);
1051 1032
1052 /* Clean up */ 1033 /* Clean up */
1053 save_xir = (u_char) cy_readb(address + (CyTIR<<index)); 1034 save_xir = (u_char) cy_readb(address + (CyTIR << index));
1054 save_car = cy_readb(address + (CyCAR<<index)); 1035 save_car = cy_readb(address + (CyCAR << index));
1055 cy_writeb(address + (CyCAR<<index), (save_xir & 0x3)); 1036 cy_writeb(address + (CyCAR << index), (save_xir & 0x3));
1056 cy_writeb(address + (CySRER<<index), 1037 cy_writeb(address + (CySRER << index),
1057 cy_readb(address + (CySRER<<index)) & ~CyTxRdy); 1038 cy_readb(address + (CySRER << index)) & ~CyTxRdy);
1058 cy_writeb(address + (CyTIR<<index), (save_xir & 0x3f)); 1039 cy_writeb(address + (CyTIR << index), (save_xir & 0x3f));
1059 cy_writeb(address + (CyCAR<<index), (save_car)); 1040 cy_writeb(address + (CyCAR << index), (save_car));
1060 cy_writeb(address + (Cy_ClrIntr<<index), 0); 1041 cy_writeb(address + (Cy_ClrIntr << index), 0);
1061 /* Cy_ClrIntr is 0x1800 */ 1042 /* Cy_ClrIntr is 0x1800 */
1062 1043
1063 return (irq > 0)? irq : 0; 1044 return (irq > 0) ? irq : 0;
1064} 1045}
1065#endif /* CONFIG_ISA */ 1046#endif /* CONFIG_ISA */
1066 1047
1067/* The real interrupt service routine is called 1048static void cyy_intr_chip(struct cyclades_card *cinfo, int chip,
1068 whenever the card wants its hand held--chars 1049 void __iomem * base_addr, int status, int index)
1069 received, out buffer empty, modem change, etc.
1070 */
1071static irqreturn_t
1072cyy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1073{ 1050{
1074 struct tty_struct *tty; 1051 struct cyclades_port *info;
1075 int status; 1052 struct tty_struct *tty;
1076 struct cyclades_card *cinfo; 1053 volatile int char_count;
1077 struct cyclades_port *info; 1054 int i, j, len, mdm_change, mdm_status, outch;
1078 void __iomem *base_addr, *card_base_addr; 1055 int save_xir, channel, save_car;
1079 int chip; 1056 char data;
1080 int save_xir, channel, save_car; 1057
1081 char data; 1058 if (status & CySRReceive) { /* reception interrupt */
1082 volatile int char_count;
1083 int outch;
1084 int i,j,index;
1085 int too_many;
1086 int had_work;
1087 int mdm_change;
1088 int mdm_status;
1089 int len;
1090 if((cinfo = (struct cyclades_card *)dev_id) == 0){
1091#ifdef CY_DEBUG_INTERRUPTS 1059#ifdef CY_DEBUG_INTERRUPTS
1092 printk("cyy_interrupt: spurious interrupt %d\n\r", irq); 1060 printk("cyy_interrupt: rcvd intr, chip %d\n\r", chip);
1093#endif 1061#endif
1094 return IRQ_NONE; /* spurious interrupt */ 1062 /* determine the channel & change to that context */
1095 } 1063 spin_lock(&cinfo->card_lock);
1096 1064 save_xir = (u_char) cy_readb(base_addr + (CyRIR << index));
1097 card_base_addr = cinfo->base_addr; 1065 channel = (u_short) (save_xir & CyIRChannel);
1098 index = cinfo->bus_index; 1066 i = channel + chip * 4 + cinfo->first_line;
1099 1067 info = &cy_port[i];
1100 1068 info->last_active = jiffies;
1101 /* This loop checks all chips in the card. Make a note whenever 1069 save_car = cy_readb(base_addr + (CyCAR << index));
1102 _any_ chip had some work to do, as this is considered an 1070 cy_writeb(base_addr + (CyCAR << index), save_xir);
1103 indication that there will be more to do. Only when no chip 1071
1104 has any work does this outermost loop exit. 1072 /* if there is nowhere to put the data, discard it */
1105 */ 1073 if (info->tty == 0) {
1106 do{ 1074 j = (cy_readb(base_addr + (CyRIVR << index)) &
1107 had_work = 0; 1075 CyIVRMask);
1108 for ( chip = 0 ; chip < cinfo->num_chips ; chip ++) { 1076 if (j == CyIVRRxEx) { /* exception */
1109 base_addr = cinfo->base_addr + (cy_chip_offset[chip]<<index); 1077 data = cy_readb(base_addr + (CyRDSR << index));
1110 too_many = 0; 1078 } else { /* normal character reception */
1111 while ( (status = cy_readb(base_addr+(CySVRR<<index))) != 0x00) { 1079 char_count = cy_readb(base_addr +
1112 had_work++; 1080 (CyRDCR << index));
1113 /* The purpose of the following test is to ensure that 1081 while (char_count--) {
1114 no chip can monopolize the driver. This forces the 1082 data = cy_readb(base_addr +
1115 chips to be checked in a round-robin fashion (after 1083 (CyRDSR << index));
1116 draining each of a bunch (1000) of characters). 1084 }
1117 */ 1085 }
1118 if(1000<too_many++){ 1086 } else { /* there is an open port for this data */
1119 break; 1087 tty = info->tty;
1120 } 1088 j = (cy_readb(base_addr + (CyRIVR << index)) &
1121 if (status & CySRReceive) { /* reception interrupt */ 1089 CyIVRMask);
1122#ifdef CY_DEBUG_INTERRUPTS 1090 if (j == CyIVRRxEx) { /* exception */
1123 printk("cyy_interrupt: rcvd intr, chip %d\n\r", chip); 1091 data = cy_readb(base_addr + (CyRDSR << index));
1124#endif 1092
1125 /* determine the channel & change to that context */ 1093 /* For statistics only */
1126 spin_lock(&cinfo->card_lock); 1094 if (data & CyBREAK)
1127 save_xir = (u_char) cy_readb(base_addr+(CyRIR<<index)); 1095 info->icount.brk++;
1128 channel = (u_short ) (save_xir & CyIRChannel); 1096 else if (data & CyFRAME)
1129 i = channel + chip * 4 + cinfo->first_line; 1097 info->icount.frame++;
1130 info = &cy_port[i]; 1098 else if (data & CyPARITY)
1131 info->last_active = jiffies; 1099 info->icount.parity++;
1132 save_car = cy_readb(base_addr+(CyCAR<<index)); 1100 else if (data & CyOVERRUN)
1133 cy_writeb(base_addr+(CyCAR<<index), save_xir); 1101 info->icount.overrun++;
1134 1102
1135 /* if there is nowhere to put the data, discard it */ 1103 if (data & info->ignore_status_mask) {
1136 if(info->tty == 0){
1137 j = (cy_readb(base_addr+(CyRIVR<<index)) & CyIVRMask);
1138 if ( j == CyIVRRxEx ) { /* exception */
1139 data = cy_readb(base_addr+(CyRDSR<<index));
1140 } else { /* normal character reception */
1141 char_count = cy_readb(base_addr+(CyRDCR<<index));
1142 while(char_count--){
1143 data = cy_readb(base_addr+(CyRDSR<<index));
1144 }
1145 }
1146 }else{ /* there is an open port for this data */
1147 tty = info->tty;
1148 j = (cy_readb(base_addr+(CyRIVR<<index)) & CyIVRMask);
1149 if ( j == CyIVRRxEx ) { /* exception */
1150 data = cy_readb(base_addr+(CyRDSR<<index));
1151
1152 /* For statistics only */
1153 if (data & CyBREAK)
1154 info->icount.brk++;
1155 else if(data & CyFRAME)
1156 info->icount.frame++;
1157 else if(data & CyPARITY)
1158 info->icount.parity++;
1159 else if(data & CyOVERRUN)
1160 info->icount.overrun++;
1161
1162 if(data & info->ignore_status_mask){
1163 info->icount.rx++;
1164 continue;
1165 }
1166 if (tty_buffer_request_room(tty, 1)) {
1167 if (data & info->read_status_mask){
1168 if(data & CyBREAK){
1169 tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_BREAK);
1170 info->icount.rx++;
1171 if (info->flags & ASYNC_SAK){
1172 do_SAK(tty);
1173 }
1174 }else if(data & CyFRAME){
1175 tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_FRAME);
1176 info->icount.rx++;
1177 info->idle_stats.frame_errs++;
1178 }else if(data & CyPARITY){
1179 /* Pieces of seven... */
1180 tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_PARITY);
1181 info->icount.rx++;
1182 info->idle_stats.parity_errs++;
1183 }else if(data & CyOVERRUN){
1184 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
1185 info->icount.rx++; 1104 info->icount.rx++;
1186 /* If the flip buffer itself is 1105 return;
1187 overflowing, we still lose 1106 }
1188 the next incoming character. 1107 if (tty_buffer_request_room(tty, 1)) {
1189 */ 1108 if (data & info->read_status_mask) {
1190 tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_FRAME); 1109 if (data & CyBREAK) {
1191 info->icount.rx++; 1110 tty_insert_flip_char(
1111 tty,
1112 cy_readb(
1113 base_addr +
1114 (CyRDSR <<
1115 index)),
1116 TTY_BREAK);
1117 info->icount.rx++;
1118 if (info->flags &
1119 ASYNC_SAK) {
1120 do_SAK(tty);
1121 }
1122 } else if (data & CyFRAME) {
1123 tty_insert_flip_char(
1124 tty,
1125 cy_readb(
1126 base_addr +
1127 (CyRDSR <<
1128 index)),
1129 TTY_FRAME);
1130 info->icount.rx++;
1131 info->idle_stats.
1132 frame_errs++;
1133 } else if (data & CyPARITY) {
1134 /* Pieces of seven... */
1135 tty_insert_flip_char(
1136 tty,
1137 cy_readb(
1138 base_addr +
1139 (CyRDSR <<
1140 index)),
1141 TTY_PARITY);
1142 info->icount.rx++;
1143 info->idle_stats.
1144 parity_errs++;
1145 } else if (data & CyOVERRUN) {
1146 tty_insert_flip_char(
1147 tty, 0,
1148 TTY_OVERRUN);
1149 info->icount.rx++;
1150 /* If the flip buffer itself is
1151 overflowing, we still lose
1152 the next incoming character.
1153 */
1154 tty_insert_flip_char(
1155 tty,
1156 cy_readb(
1157 base_addr +
1158 (CyRDSR <<
1159 index)),
1160 TTY_FRAME);
1161 info->icount.rx++;
1162 info->idle_stats.
1163 overruns++;
1164 /* These two conditions may imply */
1165 /* a normal read should be done. */
1166 /* }else if(data & CyTIMEOUT){ */
1167 /* }else if(data & CySPECHAR){ */
1168 } else {
1169 tty_insert_flip_char(
1170 tty, 0,
1171 TTY_NORMAL);
1172 info->icount.rx++;
1173 }
1174 } else {
1175 tty_insert_flip_char(tty, 0,
1176 TTY_NORMAL);
1177 info->icount.rx++;
1178 }
1179 } else {
1180 /* there was a software buffer
1181 overrun and nothing could be
1182 done about it!!! */
1183 info->icount.buf_overrun++;
1192 info->idle_stats.overruns++; 1184 info->idle_stats.overruns++;
1193 /* These two conditions may imply */ 1185 }
1194 /* a normal read should be done. */ 1186 } else { /* normal character reception */
1195 /* }else if(data & CyTIMEOUT){ */ 1187 /* load # chars available from the chip */
1196 /* }else if(data & CySPECHAR){ */ 1188 char_count = cy_readb(base_addr +
1197 }else { 1189 (CyRDCR << index));
1198 tty_insert_flip_char(tty, 0, TTY_NORMAL);
1199 info->icount.rx++;
1200 }
1201 }else{
1202 tty_insert_flip_char(tty, 0, TTY_NORMAL);
1203 info->icount.rx++;
1204 }
1205 }else{
1206 /* there was a software buffer
1207 overrun and nothing could be
1208 done about it!!! */
1209 info->icount.buf_overrun++;
1210 info->idle_stats.overruns++;
1211 }
1212 } else { /* normal character reception */
1213 /* load # chars available from the chip */
1214 char_count = cy_readb(base_addr+(CyRDCR<<index));
1215 1190
1216#ifdef CY_ENABLE_MONITORING 1191#ifdef CY_ENABLE_MONITORING
1217 ++info->mon.int_count; 1192 ++info->mon.int_count;
1218 info->mon.char_count += char_count; 1193 info->mon.char_count += char_count;
1219 if (char_count > info->mon.char_max) 1194 if (char_count > info->mon.char_max)
1220 info->mon.char_max = char_count; 1195 info->mon.char_max = char_count;
1221 info->mon.char_last = char_count; 1196 info->mon.char_last = char_count;
1222#endif 1197#endif
1223 len = tty_buffer_request_room(tty, char_count); 1198 len = tty_buffer_request_room(tty, char_count);
1224 while(len--){ 1199 while (len--) {
1225 data = cy_readb(base_addr+(CyRDSR<<index)); 1200 data = cy_readb(base_addr +
1226 tty_insert_flip_char(tty, data, TTY_NORMAL); 1201 (CyRDSR << index));
1227 info->idle_stats.recv_bytes++; 1202 tty_insert_flip_char(tty, data,
1228 info->icount.rx++; 1203 TTY_NORMAL);
1204 info->idle_stats.recv_bytes++;
1205 info->icount.rx++;
1229#ifdef CY_16Y_HACK 1206#ifdef CY_16Y_HACK
1230 udelay(10L); 1207 udelay(10L);
1231#endif 1208#endif
1232 } 1209 }
1233 info->idle_stats.recv_idle = jiffies; 1210 info->idle_stats.recv_idle = jiffies;
1234 } 1211 }
1235 tty_schedule_flip(tty); 1212 tty_schedule_flip(tty);
1236 } 1213 }
1237 /* end of service */ 1214 /* end of service */
1238 cy_writeb(base_addr+(CyRIR<<index), (save_xir & 0x3f)); 1215 cy_writeb(base_addr + (CyRIR << index), (save_xir & 0x3f));
1239 cy_writeb(base_addr+(CyCAR<<index), (save_car)); 1216 cy_writeb(base_addr + (CyCAR << index), (save_car));
1240 spin_unlock(&cinfo->card_lock); 1217 spin_unlock(&cinfo->card_lock);
1241 } 1218 }
1242 1219
1243 1220 if (status & CySRTransmit) { /* transmission interrupt */
1244 if (status & CySRTransmit) { /* transmission interrupt */ 1221 /* Since we only get here when the transmit buffer
1245 /* Since we only get here when the transmit buffer 1222 is empty, we know we can always stuff a dozen
1246 is empty, we know we can always stuff a dozen 1223 characters. */
1247 characters. */
1248#ifdef CY_DEBUG_INTERRUPTS 1224#ifdef CY_DEBUG_INTERRUPTS
1249 printk("cyy_interrupt: xmit intr, chip %d\n\r", chip); 1225 printk("cyy_interrupt: xmit intr, chip %d\n\r", chip);
1250#endif 1226#endif
1251 1227
1252 /* determine the channel & change to that context */ 1228 /* determine the channel & change to that context */
1253 spin_lock(&cinfo->card_lock); 1229 spin_lock(&cinfo->card_lock);
1254 save_xir = (u_char) cy_readb(base_addr+(CyTIR<<index)); 1230 save_xir = (u_char) cy_readb(base_addr + (CyTIR << index));
1255 channel = (u_short ) (save_xir & CyIRChannel); 1231 channel = (u_short) (save_xir & CyIRChannel);
1256 i = channel + chip * 4 + cinfo->first_line; 1232 i = channel + chip * 4 + cinfo->first_line;
1257 save_car = cy_readb(base_addr+(CyCAR<<index)); 1233 save_car = cy_readb(base_addr + (CyCAR << index));
1258 cy_writeb(base_addr+(CyCAR<<index), save_xir); 1234 cy_writeb(base_addr + (CyCAR << index), save_xir);
1259 1235
1260 /* validate the port# (as configured and open) */ 1236 /* validate the port# (as configured and open) */
1261 if( (i < 0) || (NR_PORTS <= i) ){ 1237 if ((i < 0) || (NR_PORTS <= i)) {
1262 cy_writeb(base_addr+(CySRER<<index), 1238 cy_writeb(base_addr + (CySRER << index),
1263 cy_readb(base_addr+(CySRER<<index)) & ~CyTxRdy); 1239 cy_readb(base_addr + (CySRER << index)) &
1264 goto txend; 1240 ~CyTxRdy);
1265 } 1241 goto txend;
1266 info = &cy_port[i]; 1242 }
1267 info->last_active = jiffies; 1243 info = &cy_port[i];
1268 if(info->tty == 0){ 1244 info->last_active = jiffies;
1269 cy_writeb(base_addr+(CySRER<<index), 1245 if (info->tty == 0) {
1270 cy_readb(base_addr+(CySRER<<index)) & ~CyTxRdy); 1246 cy_writeb(base_addr + (CySRER << index),
1271 goto txdone; 1247 cy_readb(base_addr + (CySRER << index)) &
1272 } 1248 ~CyTxRdy);
1273 1249 goto txdone;
1274 /* load the on-chip space for outbound data */ 1250 }
1275 char_count = info->xmit_fifo_size; 1251
1276 1252 /* load the on-chip space for outbound data */
1277 if(info->x_char) { /* send special char */ 1253 char_count = info->xmit_fifo_size;
1278 outch = info->x_char; 1254
1279 cy_writeb(base_addr+(CyTDR<<index), outch); 1255 if (info->x_char) { /* send special char */
1280 char_count--; 1256 outch = info->x_char;
1257 cy_writeb(base_addr + (CyTDR << index), outch);
1258 char_count--;
1281 info->icount.tx++; 1259 info->icount.tx++;
1282 info->x_char = 0; 1260 info->x_char = 0;
1283 } 1261 }
1284 1262
1285 if (info->breakon || info->breakoff) { 1263 if (info->breakon || info->breakoff) {
1286 if (info->breakon) { 1264 if (info->breakon) {
1287 cy_writeb(base_addr + (CyTDR<<index), 0); 1265 cy_writeb(base_addr + (CyTDR << index), 0);
1288 cy_writeb(base_addr + (CyTDR<<index), 0x81); 1266 cy_writeb(base_addr + (CyTDR << index), 0x81);
1289 info->breakon = 0; 1267 info->breakon = 0;
1290 char_count -= 2; 1268 char_count -= 2;
1291 } 1269 }
1292 if (info->breakoff) { 1270 if (info->breakoff) {
1293 cy_writeb(base_addr + (CyTDR<<index), 0); 1271 cy_writeb(base_addr + (CyTDR << index), 0);
1294 cy_writeb(base_addr + (CyTDR<<index), 0x83); 1272 cy_writeb(base_addr + (CyTDR << index), 0x83);
1295 info->breakoff = 0; 1273 info->breakoff = 0;
1296 char_count -= 2; 1274 char_count -= 2;
1297 } 1275 }
1298 } 1276 }
1299 1277
1300 while (char_count-- > 0){ 1278 while (char_count-- > 0) {
1301 if (!info->xmit_cnt){ 1279 if (!info->xmit_cnt) {
1302 if (cy_readb(base_addr+(CySRER<<index))&CyTxMpty) { 1280 if (cy_readb(base_addr + (CySRER << index)) &
1303 cy_writeb(base_addr+(CySRER<<index), 1281 CyTxMpty) {
1304 cy_readb(base_addr+(CySRER<<index)) & 1282 cy_writeb(base_addr + (CySRER << index),
1305 ~CyTxMpty); 1283 cy_readb(base_addr +
1306 } else { 1284 (CySRER << index)) &
1307 cy_writeb(base_addr+(CySRER<<index), 1285 ~CyTxMpty);
1308 ((cy_readb(base_addr+(CySRER<<index)) 1286 } else {
1309 & ~CyTxRdy) 1287 cy_writeb(base_addr + (CySRER << index),
1310 | CyTxMpty)); 1288 (cy_readb(base_addr +
1311 } 1289 (CySRER << index)) &
1312 goto txdone; 1290 ~CyTxRdy) | CyTxMpty);
1291 }
1292 goto txdone;
1313 } 1293 }
1314 if (info->xmit_buf == 0){ 1294 if (info->xmit_buf == 0) {
1315 cy_writeb(base_addr+(CySRER<<index), 1295 cy_writeb(base_addr + (CySRER << index),
1316 cy_readb(base_addr+(CySRER<<index)) & 1296 cy_readb(base_addr + (CySRER << index))&
1317 ~CyTxRdy); 1297 ~CyTxRdy);
1318 goto txdone; 1298 goto txdone;
1319 } 1299 }
1320 if (info->tty->stopped || info->tty->hw_stopped){ 1300 if (info->tty->stopped || info->tty->hw_stopped) {
1321 cy_writeb(base_addr+(CySRER<<index), 1301 cy_writeb(base_addr + (CySRER << index),
1322 cy_readb(base_addr+(CySRER<<index)) & 1302 cy_readb(base_addr + (CySRER << index))&
1323 ~CyTxRdy); 1303 ~CyTxRdy);
1324 goto txdone; 1304 goto txdone;
1325 } 1305 }
1326 /* Because the Embedded Transmit Commands have 1306 /* Because the Embedded Transmit Commands have
1327 been enabled, we must check to see if the 1307 been enabled, we must check to see if the
1328 escape character, NULL, is being sent. If it 1308 escape character, NULL, is being sent. If it
1329 is, we must ensure that there is room for it 1309 is, we must ensure that there is room for it
1330 to be doubled in the output stream. Therefore 1310 to be doubled in the output stream. Therefore
@@ -1333,125 +1313,182 @@ cyy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1333 after the check for a NULL output character. 1313 after the check for a NULL output character.
1334 This is necessary because there may not be 1314 This is necessary because there may not be
1335 room for the two chars needed to send a NULL.) 1315 room for the two chars needed to send a NULL.)
1336 */ 1316 */
1337 outch = info->xmit_buf[info->xmit_tail]; 1317 outch = info->xmit_buf[info->xmit_tail];
1338 if( outch ){ 1318 if (outch) {
1339 info->xmit_cnt--; 1319 info->xmit_cnt--;
1340 info->xmit_tail = (info->xmit_tail + 1) 1320 info->xmit_tail = (info->xmit_tail + 1) &
1341 & (SERIAL_XMIT_SIZE - 1); 1321 (SERIAL_XMIT_SIZE - 1);
1342 cy_writeb(base_addr+(CyTDR<<index), outch); 1322 cy_writeb(base_addr + (CyTDR << index), outch);
1343 info->icount.tx++;
1344 }else{
1345 if(char_count > 1){
1346 info->xmit_cnt--;
1347 info->xmit_tail = (info->xmit_tail + 1)
1348 & (SERIAL_XMIT_SIZE - 1);
1349 cy_writeb(base_addr+(CyTDR<<index),
1350 outch);
1351 cy_writeb(base_addr+(CyTDR<<index), 0);
1352 info->icount.tx++; 1323 info->icount.tx++;
1353 char_count--; 1324 } else {
1354 }else{ 1325 if (char_count > 1) {
1355 } 1326 info->xmit_cnt--;
1356 } 1327 info->xmit_tail = (info->xmit_tail + 1)&
1357 } 1328 (SERIAL_XMIT_SIZE - 1);
1358 1329 cy_writeb(base_addr + (CyTDR << index),
1359 txdone: 1330 outch);
1360 if (info->xmit_cnt < WAKEUP_CHARS) { 1331 cy_writeb(base_addr + (CyTDR << index),
1361 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP); 1332 0);
1362 } 1333 info->icount.tx++;
1363 txend: 1334 char_count--;
1364 /* end of service */ 1335 } else {
1365 cy_writeb(base_addr+(CyTIR<<index), 1336 }
1366 (save_xir & 0x3f)); 1337 }
1367 cy_writeb(base_addr+(CyCAR<<index), (save_car)); 1338 }
1368 spin_unlock(&cinfo->card_lock); 1339
1369 } 1340txdone:
1370 1341 if (info->xmit_cnt < WAKEUP_CHARS) {
1371 if (status & CySRModem) { /* modem interrupt */ 1342 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
1372 1343 }
1373 /* determine the channel & change to that context */ 1344txend:
1374 spin_lock(&cinfo->card_lock); 1345 /* end of service */
1375 save_xir = (u_char) cy_readb(base_addr+(CyMIR<<index)); 1346 cy_writeb(base_addr + (CyTIR << index), (save_xir & 0x3f));
1376 channel = (u_short ) (save_xir & CyIRChannel); 1347 cy_writeb(base_addr + (CyCAR << index), (save_car));
1377 info = &cy_port[channel + chip * 4 1348 spin_unlock(&cinfo->card_lock);
1378 + cinfo->first_line]; 1349 }
1379 info->last_active = jiffies; 1350
1380 save_car = cy_readb(base_addr+(CyCAR<<index)); 1351 if (status & CySRModem) { /* modem interrupt */
1381 cy_writeb(base_addr+(CyCAR<<index), save_xir); 1352
1382 1353 /* determine the channel & change to that context */
1383 mdm_change = cy_readb(base_addr+(CyMISR<<index)); 1354 spin_lock(&cinfo->card_lock);
1384 mdm_status = cy_readb(base_addr+(CyMSVR1<<index)); 1355 save_xir = (u_char) cy_readb(base_addr + (CyMIR << index));
1385 1356 channel = (u_short) (save_xir & CyIRChannel);
1386 if(info->tty == 0){/* no place for data, ignore it*/ 1357 info = &cy_port[channel + chip * 4 + cinfo->first_line];
1387 ; 1358 info->last_active = jiffies;
1388 }else{ 1359 save_car = cy_readb(base_addr + (CyCAR << index));
1360 cy_writeb(base_addr + (CyCAR << index), save_xir);
1361
1362 mdm_change = cy_readb(base_addr + (CyMISR << index));
1363 mdm_status = cy_readb(base_addr + (CyMSVR1 << index));
1364
1365 if (info->tty == 0) { /* no place for data, ignore it */
1366 ;
1367 } else {
1389 if (mdm_change & CyANY_DELTA) { 1368 if (mdm_change & CyANY_DELTA) {
1390 /* For statistics only */ 1369 /* For statistics only */
1391 if (mdm_change & CyDCD) info->icount.dcd++; 1370 if (mdm_change & CyDCD)
1392 if (mdm_change & CyCTS) info->icount.cts++; 1371 info->icount.dcd++;
1393 if (mdm_change & CyDSR) info->icount.dsr++; 1372 if (mdm_change & CyCTS)
1394 if (mdm_change & CyRI) info->icount.rng++; 1373 info->icount.cts++;
1374 if (mdm_change & CyDSR)
1375 info->icount.dsr++;
1376 if (mdm_change & CyRI)
1377 info->icount.rng++;
1378
1379 cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
1380 }
1381
1382 if ((mdm_change & CyDCD) &&
1383 (info->flags & ASYNC_CHECK_CD)) {
1384 if (mdm_status & CyDCD) {
1385 cy_sched_event(info,
1386 Cy_EVENT_OPEN_WAKEUP);
1387 } else {
1388 cy_sched_event(info, Cy_EVENT_HANGUP);
1389 }
1390 }
1391 if ((mdm_change & CyCTS) &&
1392 (info->flags & ASYNC_CTS_FLOW)) {
1393 if (info->tty->hw_stopped) {
1394 if (mdm_status & CyCTS) {
1395 /* cy_start isn't used
1396 because... !!! */
1397 info->tty->hw_stopped = 0;
1398 cy_writeb(base_addr +
1399 (CySRER << index),
1400 cy_readb(base_addr +
1401 (CySRER <<
1402 index))|
1403 CyTxRdy);
1404 cy_sched_event(info,
1405 Cy_EVENT_WRITE_WAKEUP);
1406 }
1407 } else {
1408 if (!(mdm_status & CyCTS)) {
1409 /* cy_stop isn't used
1410 because ... !!! */
1411 info->tty->hw_stopped = 1;
1412 cy_writeb(base_addr +
1413 (CySRER << index),
1414 cy_readb(base_addr +
1415 (CySRER <<
1416 index)) &
1417 ~CyTxRdy);
1418 }
1419 }
1420 }
1421 if (mdm_change & CyDSR) {
1422 }
1423 if (mdm_change & CyRI) {
1424 }
1425 }
1426 /* end of service */
1427 cy_writeb(base_addr + (CyMIR << index), (save_xir & 0x3f));
1428 cy_writeb(base_addr + (CyCAR << index), save_car);
1429 spin_unlock(&cinfo->card_lock);
1430 }
1431}
1432
1433/* The real interrupt service routine is called
1434 whenever the card wants its hand held--chars
1435 received, out buffer empty, modem change, etc.
1436 */
1437static irqreturn_t cyy_interrupt(int irq, void *dev_id)
1438{
1439 int status;
1440 struct cyclades_card *cinfo;
1441 void __iomem *base_addr, *card_base_addr;
1442 int chip;
1443 int index;
1444 int too_many;
1445 int had_work;
1446
1447 if ((cinfo = (struct cyclades_card *)dev_id) == 0) {
1448#ifdef CY_DEBUG_INTERRUPTS
1449 printk("cyy_interrupt: spurious interrupt %d\n\r", irq);
1450#endif
1451 return IRQ_NONE; /* spurious interrupt */
1452 }
1453
1454 card_base_addr = cinfo->base_addr;
1455 index = cinfo->bus_index;
1395 1456
1396 cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP); 1457 /* This loop checks all chips in the card. Make a note whenever
1458 _any_ chip had some work to do, as this is considered an
1459 indication that there will be more to do. Only when no chip
1460 has any work does this outermost loop exit.
1461 */
1462 do {
1463 had_work = 0;
1464 for (chip = 0; chip < cinfo->num_chips; chip++) {
1465 base_addr = cinfo->base_addr +
1466 (cy_chip_offset[chip] << index);
1467 too_many = 0;
1468 while ((status = cy_readb(base_addr +
1469 (CySVRR << index))) != 0x00) {
1470 had_work++;
1471 /* The purpose of the following test is to ensure that
1472 no chip can monopolize the driver. This forces the
1473 chips to be checked in a round-robin fashion (after
1474 draining each of a bunch (1000) of characters).
1475 */
1476 if (1000 < too_many++) {
1477 break;
1478 }
1479 cyy_intr_chip(cinfo, chip, base_addr, status,
1480 index);
1397 } 1481 }
1482 }
1483 } while (had_work);
1398 1484
1399 if((mdm_change & CyDCD) 1485 /* clear interrupts */
1400 && (info->flags & ASYNC_CHECK_CD)){ 1486 spin_lock(&cinfo->card_lock);
1401 if(mdm_status & CyDCD){ 1487 cy_writeb(card_base_addr + (Cy_ClrIntr << index), 0);
1402 cy_sched_event(info, 1488 /* Cy_ClrIntr is 0x1800 */
1403 Cy_EVENT_OPEN_WAKEUP); 1489 spin_unlock(&cinfo->card_lock);
1404 }else{ 1490 return IRQ_HANDLED;
1405 cy_sched_event(info, 1491} /* cyy_interrupt */
1406 Cy_EVENT_HANGUP);
1407 }
1408 }
1409 if((mdm_change & CyCTS)
1410 && (info->flags & ASYNC_CTS_FLOW)){
1411 if(info->tty->hw_stopped){
1412 if(mdm_status & CyCTS){
1413 /* cy_start isn't used
1414 because... !!! */
1415 info->tty->hw_stopped = 0;
1416 cy_writeb(base_addr+(CySRER<<index),
1417 cy_readb(base_addr+(CySRER<<index)) |
1418 CyTxRdy);
1419 cy_sched_event(info,
1420 Cy_EVENT_WRITE_WAKEUP);
1421 }
1422 }else{
1423 if(!(mdm_status & CyCTS)){
1424 /* cy_stop isn't used
1425 because ... !!! */
1426 info->tty->hw_stopped = 1;
1427 cy_writeb(base_addr+(CySRER<<index),
1428 cy_readb(base_addr+(CySRER<<index)) &
1429 ~CyTxRdy);
1430 }
1431 }
1432 }
1433 if(mdm_change & CyDSR){
1434 }
1435 if(mdm_change & CyRI){
1436 }
1437 }
1438 /* end of service */
1439 cy_writeb(base_addr+(CyMIR<<index),
1440 (save_xir & 0x3f));
1441 cy_writeb(base_addr+(CyCAR<<index), save_car);
1442 spin_unlock(&cinfo->card_lock);
1443 }
1444 } /* end while status != 0 */
1445 } /* end loop for chips... */
1446 } while(had_work);
1447
1448 /* clear interrupts */
1449 spin_lock(&cinfo->card_lock);
1450 cy_writeb(card_base_addr + (Cy_ClrIntr<<index), 0);
1451 /* Cy_ClrIntr is 0x1800 */
1452 spin_unlock(&cinfo->card_lock);
1453 return IRQ_HANDLED;
1454} /* cyy_interrupt */
1455 1492
1456/***********************************************************/ 1493/***********************************************************/
1457/********* End of block of Cyclom-Y specific code **********/ 1494/********* End of block of Cyclom-Y specific code **********/
@@ -1459,643 +1496,655 @@ cyy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1459/***********************************************************/ 1496/***********************************************************/
1460 1497
1461static int 1498static int
1462cyz_fetch_msg( struct cyclades_card *cinfo, 1499cyz_fetch_msg(struct cyclades_card *cinfo,
1463 uclong *channel, ucchar *cmd, uclong *param) 1500 uclong * channel, ucchar * cmd, uclong * param)
1464{ 1501{
1465 struct FIRM_ID __iomem *firm_id; 1502 struct FIRM_ID __iomem *firm_id;
1466 struct ZFW_CTRL __iomem *zfw_ctrl; 1503 struct ZFW_CTRL __iomem *zfw_ctrl;
1467 struct BOARD_CTRL __iomem *board_ctrl; 1504 struct BOARD_CTRL __iomem *board_ctrl;
1468 unsigned long loc_doorbell; 1505 unsigned long loc_doorbell;
1469 1506
1470 firm_id = cinfo->base_addr + ID_ADDRESS; 1507 firm_id = cinfo->base_addr + ID_ADDRESS;
1471 if (!ISZLOADED(*cinfo)){ 1508 if (!ISZLOADED(*cinfo)) {
1472 return (-1); 1509 return -1;
1473 } 1510 }
1474 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 1511 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) &
1475 board_ctrl = &zfw_ctrl->board_ctrl; 1512 0xfffff);
1476 1513 board_ctrl = &zfw_ctrl->board_ctrl;
1477 loc_doorbell = cy_readl(&((struct RUNTIME_9060 __iomem *) 1514
1478 (cinfo->ctl_addr))->loc_doorbell); 1515 loc_doorbell = cy_readl(&((struct RUNTIME_9060 __iomem *)
1479 if (loc_doorbell){ 1516 (cinfo->ctl_addr))->loc_doorbell);
1480 *cmd = (char)(0xff & loc_doorbell); 1517 if (loc_doorbell) {
1481 *channel = cy_readl(&board_ctrl->fwcmd_channel); 1518 *cmd = (char)(0xff & loc_doorbell);
1482 *param = (uclong)cy_readl(&board_ctrl->fwcmd_param); 1519 *channel = cy_readl(&board_ctrl->fwcmd_channel);
1483 cy_writel(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->loc_doorbell, 1520 *param = (uclong) cy_readl(&board_ctrl->fwcmd_param);
1484 0xffffffff); 1521 cy_writel(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->
1485 return 1; 1522 loc_doorbell, 0xffffffff);
1486 } 1523 return 1;
1487 return 0; 1524 }
1488} /* cyz_fetch_msg */ 1525 return 0;
1526} /* cyz_fetch_msg */
1489 1527
1490static int 1528static int
1491cyz_issue_cmd( struct cyclades_card *cinfo, 1529cyz_issue_cmd(struct cyclades_card *cinfo,
1492 uclong channel, ucchar cmd, uclong param) 1530 uclong channel, ucchar cmd, uclong param)
1493{ 1531{
1494 struct FIRM_ID __iomem *firm_id; 1532 struct FIRM_ID __iomem *firm_id;
1495 struct ZFW_CTRL __iomem *zfw_ctrl; 1533 struct ZFW_CTRL __iomem *zfw_ctrl;
1496 struct BOARD_CTRL __iomem *board_ctrl; 1534 struct BOARD_CTRL __iomem *board_ctrl;
1497 unsigned long __iomem *pci_doorbell; 1535 unsigned long __iomem *pci_doorbell;
1498 int index; 1536 int index;
1499 1537
1500 firm_id = cinfo->base_addr + ID_ADDRESS; 1538 firm_id = cinfo->base_addr + ID_ADDRESS;
1501 if (!ISZLOADED(*cinfo)){ 1539 if (!ISZLOADED(*cinfo)) {
1502 return (-1); 1540 return -1;
1503 } 1541 }
1504 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 1542 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) &
1505 board_ctrl = &zfw_ctrl->board_ctrl; 1543 0xfffff);
1506 1544 board_ctrl = &zfw_ctrl->board_ctrl;
1507 index = 0; 1545
1508 pci_doorbell = &((struct RUNTIME_9060 __iomem *) (cinfo->ctl_addr))->pci_doorbell; 1546 index = 0;
1509 while( (cy_readl(pci_doorbell) & 0xff) != 0){ 1547 pci_doorbell =
1510 if (index++ == 1000){ 1548 &((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->pci_doorbell;
1511 return((int)(cy_readl(pci_doorbell) & 0xff)); 1549 while ((cy_readl(pci_doorbell) & 0xff) != 0) {
1512 } 1550 if (index++ == 1000) {
1513 udelay(50L); 1551 return (int)(cy_readl(pci_doorbell) & 0xff);
1514 } 1552 }
1515 cy_writel(&board_ctrl->hcmd_channel, channel); 1553 udelay(50L);
1516 cy_writel(&board_ctrl->hcmd_param , param); 1554 }
1517 cy_writel(pci_doorbell, (long)cmd); 1555 cy_writel(&board_ctrl->hcmd_channel, channel);
1518 1556 cy_writel(&board_ctrl->hcmd_param, param);
1519 return(0); 1557 cy_writel(pci_doorbell, (long)cmd);
1520} /* cyz_issue_cmd */ 1558
1559 return 0;
1560} /* cyz_issue_cmd */
1521 1561
1522static void 1562static void
1523cyz_handle_rx(struct cyclades_port *info, 1563cyz_handle_rx(struct cyclades_port *info,
1524 volatile struct CH_CTRL __iomem *ch_ctrl, 1564 volatile struct CH_CTRL __iomem * ch_ctrl,
1525 volatile struct BUF_CTRL __iomem *buf_ctrl) 1565 volatile struct BUF_CTRL __iomem * buf_ctrl)
1526{ 1566{
1527 struct cyclades_card *cinfo = &cy_card[info->card]; 1567 struct cyclades_card *cinfo = &cy_card[info->card];
1528 struct tty_struct *tty = info->tty; 1568 struct tty_struct *tty = info->tty;
1529 volatile int char_count; 1569 volatile int char_count;
1530 int len; 1570 int len;
1531#ifdef BLOCKMOVE 1571#ifdef BLOCKMOVE
1532 int small_count; 1572 int small_count;
1533#else 1573#else
1534 char data; 1574 char data;
1535#endif 1575#endif
1536 volatile uclong rx_put, rx_get, new_rx_get, rx_bufsize, rx_bufaddr; 1576 volatile uclong rx_put, rx_get, new_rx_get, rx_bufsize, rx_bufaddr;
1537 1577
1538 rx_get = new_rx_get = cy_readl(&buf_ctrl->rx_get); 1578 rx_get = new_rx_get = cy_readl(&buf_ctrl->rx_get);
1539 rx_put = cy_readl(&buf_ctrl->rx_put); 1579 rx_put = cy_readl(&buf_ctrl->rx_put);
1540 rx_bufsize = cy_readl(&buf_ctrl->rx_bufsize); 1580 rx_bufsize = cy_readl(&buf_ctrl->rx_bufsize);
1541 rx_bufaddr = cy_readl(&buf_ctrl->rx_bufaddr); 1581 rx_bufaddr = cy_readl(&buf_ctrl->rx_bufaddr);
1542 if (rx_put >= rx_get) 1582 if (rx_put >= rx_get)
1543 char_count = rx_put - rx_get; 1583 char_count = rx_put - rx_get;
1544 else 1584 else
1545 char_count = rx_put - rx_get + rx_bufsize; 1585 char_count = rx_put - rx_get + rx_bufsize;
1546 1586
1547 if ( char_count ) { 1587 if (char_count) {
1548 info->last_active = jiffies; 1588 info->last_active = jiffies;
1549 info->jiffies[1] = jiffies; 1589 info->jiffies[1] = jiffies;
1550 1590
1551#ifdef CY_ENABLE_MONITORING 1591#ifdef CY_ENABLE_MONITORING
1552 info->mon.int_count++; 1592 info->mon.int_count++;
1553 info->mon.char_count += char_count; 1593 info->mon.char_count += char_count;
1554 if (char_count > info->mon.char_max) 1594 if (char_count > info->mon.char_max)
1555 info->mon.char_max = char_count; 1595 info->mon.char_max = char_count;
1556 info->mon.char_last = char_count; 1596 info->mon.char_last = char_count;
1557#endif 1597#endif
1558 if(tty == 0){ 1598 if (tty == 0) {
1559 /* flush received characters */ 1599 /* flush received characters */
1560 new_rx_get = (new_rx_get + char_count) & (rx_bufsize - 1); 1600 new_rx_get = (new_rx_get + char_count) &
1561 info->rflush_count++; 1601 (rx_bufsize - 1);
1562 }else{ 1602 info->rflush_count++;
1603 } else {
1563#ifdef BLOCKMOVE 1604#ifdef BLOCKMOVE
1564 /* we'd like to use memcpy(t, f, n) and memset(s, c, count) 1605 /* we'd like to use memcpy(t, f, n) and memset(s, c, count)
1565 for performance, but because of buffer boundaries, there 1606 for performance, but because of buffer boundaries, there
1566 may be several steps to the operation */ 1607 may be several steps to the operation */
1567 while(0 < (small_count = 1608 while (0 < (small_count = min_t(unsigned int,
1568 min_t(unsigned int, (rx_bufsize - new_rx_get), 1609 rx_bufsize - new_rx_get,
1569 min_t(unsigned int, (TTY_FLIPBUF_SIZE - tty->flip.count), char_count)) 1610 min_t(unsigned int, TTY_FLIPBUF_SIZE -
1570 )) { 1611 tty->flip.count, char_count)))){
1571 memcpy_fromio(tty->flip.char_buf_ptr, 1612 memcpy_fromio(tty->flip.char_buf_ptr,
1572 (char *)(cinfo->base_addr 1613 (char *)(cinfo->base_addr + rx_bufaddr +
1573 + rx_bufaddr + new_rx_get), 1614 new_rx_get),
1574 small_count); 1615 small_count);
1575 1616
1576 tty->flip.char_buf_ptr += small_count; 1617 tty->flip.char_buf_ptr += small_count;
1577 memset(tty->flip.flag_buf_ptr, TTY_NORMAL, small_count); 1618 memset(tty->flip.flag_buf_ptr, TTY_NORMAL,
1578 tty->flip.flag_buf_ptr += small_count; 1619 small_count);
1579 new_rx_get = (new_rx_get + small_count) & (rx_bufsize - 1); 1620 tty->flip.flag_buf_ptr += small_count;
1580 char_count -= small_count; 1621 new_rx_get = (new_rx_get + small_count) &
1581 info->icount.rx += small_count; 1622 (rx_bufsize - 1);
1582 info->idle_stats.recv_bytes += small_count; 1623 char_count -= small_count;
1583 tty->flip.count += small_count; 1624 info->icount.rx += small_count;
1584 } 1625 info->idle_stats.recv_bytes += small_count;
1626 tty->flip.count += small_count;
1627 }
1585#else 1628#else
1586 len = tty_buffer_request_room(tty, char_count); 1629 len = tty_buffer_request_room(tty, char_count);
1587 while(len--){ 1630 while (len--) {
1588 data = cy_readb(cinfo->base_addr + rx_bufaddr + new_rx_get); 1631 data = cy_readb(cinfo->base_addr + rx_bufaddr +
1589 new_rx_get = (new_rx_get + 1) & (rx_bufsize - 1); 1632 new_rx_get);
1590 tty_insert_flip_char(tty, data, TTY_NORMAL); 1633 new_rx_get = (new_rx_get + 1)& (rx_bufsize - 1);
1591 info->idle_stats.recv_bytes++; 1634 tty_insert_flip_char(tty, data, TTY_NORMAL);
1592 info->icount.rx++; 1635 info->idle_stats.recv_bytes++;
1593 } 1636 info->icount.rx++;
1637 }
1594#endif 1638#endif
1595#ifdef CONFIG_CYZ_INTR 1639#ifdef CONFIG_CYZ_INTR
1596 /* Recalculate the number of chars in the RX buffer and issue 1640 /* Recalculate the number of chars in the RX buffer and issue
1597 a cmd in case it's higher than the RX high water mark */ 1641 a cmd in case it's higher than the RX high water mark */
1598 rx_put = cy_readl(&buf_ctrl->rx_put); 1642 rx_put = cy_readl(&buf_ctrl->rx_put);
1599 if (rx_put >= rx_get) 1643 if (rx_put >= rx_get)
1600 char_count = rx_put - rx_get; 1644 char_count = rx_put - rx_get;
1601 else 1645 else
1602 char_count = rx_put - rx_get + rx_bufsize; 1646 char_count = rx_put - rx_get + rx_bufsize;
1603 if(char_count >= cy_readl(&buf_ctrl->rx_threshold)) { 1647 if (char_count >= (int)cy_readl(&buf_ctrl->
1604 cy_sched_event(info, Cy_EVENT_Z_RX_FULL); 1648 rx_threshold)) {
1605 } 1649 cy_sched_event(info, Cy_EVENT_Z_RX_FULL);
1650 }
1606#endif 1651#endif
1607 info->idle_stats.recv_idle = jiffies; 1652 info->idle_stats.recv_idle = jiffies;
1608 tty_schedule_flip(tty); 1653 tty_schedule_flip(tty);
1654 }
1655 /* Update rx_get */
1656 cy_writel(&buf_ctrl->rx_get, new_rx_get);
1609 } 1657 }
1610 /* Update rx_get */
1611 cy_writel(&buf_ctrl->rx_get, new_rx_get);
1612 }
1613} 1658}
1614 1659
1615static void 1660static void
1616cyz_handle_tx(struct cyclades_port *info, 1661cyz_handle_tx(struct cyclades_port *info,
1617 volatile struct CH_CTRL __iomem *ch_ctrl, 1662 volatile struct CH_CTRL __iomem * ch_ctrl,
1618 volatile struct BUF_CTRL __iomem *buf_ctrl) 1663 volatile struct BUF_CTRL __iomem * buf_ctrl)
1619{ 1664{
1620 struct cyclades_card *cinfo = &cy_card[info->card]; 1665 struct cyclades_card *cinfo = &cy_card[info->card];
1621 struct tty_struct *tty = info->tty; 1666 struct tty_struct *tty = info->tty;
1622 char data; 1667 char data;
1623 volatile int char_count; 1668 volatile int char_count;
1624#ifdef BLOCKMOVE 1669#ifdef BLOCKMOVE
1625 int small_count; 1670 int small_count;
1626#endif 1671#endif
1627 volatile uclong tx_put, tx_get, tx_bufsize, tx_bufaddr; 1672 volatile uclong tx_put, tx_get, tx_bufsize, tx_bufaddr;
1628 1673
1629 if (info->xmit_cnt <= 0) /* Nothing to transmit */ 1674 if (info->xmit_cnt <= 0) /* Nothing to transmit */
1630 return; 1675 return;
1631 1676
1632 tx_get = cy_readl(&buf_ctrl->tx_get); 1677 tx_get = cy_readl(&buf_ctrl->tx_get);
1633 tx_put = cy_readl(&buf_ctrl->tx_put); 1678 tx_put = cy_readl(&buf_ctrl->tx_put);
1634 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize); 1679 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize);
1635 tx_bufaddr = cy_readl(&buf_ctrl->tx_bufaddr); 1680 tx_bufaddr = cy_readl(&buf_ctrl->tx_bufaddr);
1636 if (tx_put >= tx_get) 1681 if (tx_put >= tx_get)
1637 char_count = tx_get - tx_put - 1 + tx_bufsize; 1682 char_count = tx_get - tx_put - 1 + tx_bufsize;
1638 else 1683 else
1639 char_count = tx_get - tx_put - 1; 1684 char_count = tx_get - tx_put - 1;
1640 1685
1641 if ( char_count ) { 1686 if (char_count) {
1642 1687
1643 if( tty == 0 ){ 1688 if (tty == 0) {
1644 goto ztxdone; 1689 goto ztxdone;
1645 } 1690 }
1646 1691
1647 if(info->x_char) { /* send special char */ 1692 if (info->x_char) { /* send special char */
1648 data = info->x_char; 1693 data = info->x_char;
1649 1694
1650 cy_writeb((cinfo->base_addr + tx_bufaddr + tx_put), data); 1695 cy_writeb(cinfo->base_addr + tx_bufaddr + tx_put, data);
1651 tx_put = (tx_put + 1) & (tx_bufsize - 1); 1696 tx_put = (tx_put + 1) & (tx_bufsize - 1);
1652 info->x_char = 0; 1697 info->x_char = 0;
1653 char_count--; 1698 char_count--;
1654 info->icount.tx++; 1699 info->icount.tx++;
1655 info->last_active = jiffies; 1700 info->last_active = jiffies;
1656 info->jiffies[2] = jiffies; 1701 info->jiffies[2] = jiffies;
1657 } 1702 }
1658#ifdef BLOCKMOVE 1703#ifdef BLOCKMOVE
1659 while(0 < (small_count = 1704 while (0 < (small_count = min_t(unsigned int,
1660 min_t(unsigned int, (tx_bufsize - tx_put), 1705 tx_bufsize - tx_put, min_t(unsigned int,
1661 min_t(unsigned int, (SERIAL_XMIT_SIZE - info->xmit_tail), 1706 (SERIAL_XMIT_SIZE - info->xmit_tail),
1662 min_t(unsigned int, info->xmit_cnt, char_count))))) { 1707 min_t(unsigned int, info->xmit_cnt,
1663 1708 char_count))))) {
1664 memcpy_toio((char *)(cinfo->base_addr + tx_bufaddr + tx_put), 1709
1665 &info->xmit_buf[info->xmit_tail], 1710 memcpy_toio((char *)(cinfo->base_addr + tx_bufaddr +
1666 small_count); 1711 tx_put),
1667 1712 &info->xmit_buf[info->xmit_tail],
1668 tx_put = (tx_put + small_count) & (tx_bufsize - 1); 1713 small_count);
1669 char_count -= small_count; 1714
1670 info->icount.tx += small_count; 1715 tx_put = (tx_put + small_count) & (tx_bufsize - 1);
1671 info->xmit_cnt -= small_count; 1716 char_count -= small_count;
1672 info->xmit_tail = 1717 info->icount.tx += small_count;
1673 (info->xmit_tail + small_count) & (SERIAL_XMIT_SIZE - 1); 1718 info->xmit_cnt -= small_count;
1674 info->last_active = jiffies; 1719 info->xmit_tail = (info->xmit_tail + small_count) &
1675 info->jiffies[2] = jiffies; 1720 (SERIAL_XMIT_SIZE - 1);
1676 } 1721 info->last_active = jiffies;
1722 info->jiffies[2] = jiffies;
1723 }
1677#else 1724#else
1678 while (info->xmit_cnt && char_count){ 1725 while (info->xmit_cnt && char_count) {
1679 data = info->xmit_buf[info->xmit_tail]; 1726 data = info->xmit_buf[info->xmit_tail];
1680 info->xmit_cnt--; 1727 info->xmit_cnt--;
1681 info->xmit_tail = (info->xmit_tail + 1) & (SERIAL_XMIT_SIZE - 1); 1728 info->xmit_tail = (info->xmit_tail + 1) &
1682 1729 (SERIAL_XMIT_SIZE - 1);
1683 cy_writeb(cinfo->base_addr + tx_bufaddr + tx_put, data); 1730
1684 tx_put = (tx_put + 1) & (tx_bufsize - 1); 1731 cy_writeb(cinfo->base_addr + tx_bufaddr + tx_put, data);
1685 char_count--; 1732 tx_put = (tx_put + 1) & (tx_bufsize - 1);
1686 info->icount.tx++; 1733 char_count--;
1687 info->last_active = jiffies; 1734 info->icount.tx++;
1688 info->jiffies[2] = jiffies; 1735 info->last_active = jiffies;
1689 } 1736 info->jiffies[2] = jiffies;
1737 }
1690#endif 1738#endif
1691 ztxdone: 1739ztxdone:
1692 if (info->xmit_cnt < WAKEUP_CHARS) { 1740 if (info->xmit_cnt < WAKEUP_CHARS) {
1693 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP); 1741 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
1742 }
1743 /* Update tx_put */
1744 cy_writel(&buf_ctrl->tx_put, tx_put);
1694 } 1745 }
1695 /* Update tx_put */
1696 cy_writel(&buf_ctrl->tx_put, tx_put);
1697 }
1698} 1746}
1699 1747
1700static void 1748static void cyz_handle_cmd(struct cyclades_card *cinfo)
1701cyz_handle_cmd(struct cyclades_card *cinfo)
1702{ 1749{
1703 struct tty_struct *tty; 1750 struct tty_struct *tty;
1704 struct cyclades_port *info; 1751 struct cyclades_port *info;
1705 static volatile struct FIRM_ID __iomem *firm_id; 1752 static volatile struct FIRM_ID __iomem *firm_id;
1706 static volatile struct ZFW_CTRL __iomem *zfw_ctrl; 1753 static volatile struct ZFW_CTRL __iomem *zfw_ctrl;
1707 static volatile struct BOARD_CTRL __iomem *board_ctrl; 1754 static volatile struct BOARD_CTRL __iomem *board_ctrl;
1708 static volatile struct CH_CTRL __iomem *ch_ctrl; 1755 static volatile struct CH_CTRL __iomem *ch_ctrl;
1709 static volatile struct BUF_CTRL __iomem *buf_ctrl; 1756 static volatile struct BUF_CTRL __iomem *buf_ctrl;
1710 uclong channel; 1757 uclong channel;
1711 ucchar cmd; 1758 ucchar cmd;
1712 uclong param; 1759 uclong param;
1713 uclong hw_ver, fw_ver; 1760 uclong hw_ver, fw_ver;
1714 int special_count; 1761 int special_count;
1715 int delta_count; 1762 int delta_count;
1716 1763
1717 firm_id = cinfo->base_addr + ID_ADDRESS; 1764 firm_id = cinfo->base_addr + ID_ADDRESS;
1718 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 1765 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) &
1719 board_ctrl = &zfw_ctrl->board_ctrl; 1766 0xfffff);
1720 fw_ver = cy_readl(&board_ctrl->fw_version); 1767 board_ctrl = &zfw_ctrl->board_ctrl;
1721 hw_ver = cy_readl(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->mail_box_0); 1768 fw_ver = cy_readl(&board_ctrl->fw_version);
1722 1769 hw_ver = cy_readl(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->
1723 1770 mail_box_0);
1724 while(cyz_fetch_msg(cinfo, &channel, &cmd, &param) == 1) { 1771
1725 special_count = 0; 1772 while (cyz_fetch_msg(cinfo, &channel, &cmd, &param) == 1) {
1726 delta_count = 0; 1773 special_count = 0;
1727 info = &cy_port[channel + cinfo->first_line]; 1774 delta_count = 0;
1728 if((tty = info->tty) == 0) { 1775 info = &cy_port[channel + cinfo->first_line];
1729 continue; 1776 if ((tty = info->tty) == 0) {
1730 } 1777 continue;
1731 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
1732 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
1733
1734 switch(cmd) {
1735 case C_CM_PR_ERROR:
1736 tty_insert_flip_char(tty, 0, TTY_PARITY);
1737 info->icount.rx++;
1738 special_count++;
1739 break;
1740 case C_CM_FR_ERROR:
1741 tty_insert_flip_char(tty, 0, TTY_FRAME);
1742 info->icount.rx++;
1743 special_count++;
1744 break;
1745 case C_CM_RXBRK:
1746 tty_insert_flip_char(tty, 0, TTY_BREAK);
1747 info->icount.rx++;
1748 special_count++;
1749 break;
1750 case C_CM_MDCD:
1751 info->icount.dcd++;
1752 delta_count++;
1753 if (info->flags & ASYNC_CHECK_CD){
1754 if ((fw_ver > 241 ?
1755 ((u_long)param) :
1756 cy_readl(&ch_ctrl->rs_status)) & C_RS_DCD) {
1757 cy_sched_event(info, Cy_EVENT_OPEN_WAKEUP);
1758 }else{
1759 cy_sched_event(info, Cy_EVENT_HANGUP);
1760 }
1761 } 1778 }
1762 break; 1779 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
1763 case C_CM_MCTS: 1780 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
1764 info->icount.cts++; 1781
1765 delta_count++; 1782 switch (cmd) {
1766 break; 1783 case C_CM_PR_ERROR:
1767 case C_CM_MRI: 1784 tty_insert_flip_char(tty, 0, TTY_PARITY);
1768 info->icount.rng++; 1785 info->icount.rx++;
1769 delta_count++; 1786 special_count++;
1770 break; 1787 break;
1771 case C_CM_MDSR: 1788 case C_CM_FR_ERROR:
1772 info->icount.dsr++; 1789 tty_insert_flip_char(tty, 0, TTY_FRAME);
1773 delta_count++; 1790 info->icount.rx++;
1774 break; 1791 special_count++;
1792 break;
1793 case C_CM_RXBRK:
1794 tty_insert_flip_char(tty, 0, TTY_BREAK);
1795 info->icount.rx++;
1796 special_count++;
1797 break;
1798 case C_CM_MDCD:
1799 info->icount.dcd++;
1800 delta_count++;
1801 if (info->flags & ASYNC_CHECK_CD) {
1802 if ((fw_ver > 241 ? ((u_long) param) :
1803 cy_readl(&ch_ctrl->rs_status)) &
1804 C_RS_DCD) {
1805 cy_sched_event(info,
1806 Cy_EVENT_OPEN_WAKEUP);
1807 } else {
1808 cy_sched_event(info, Cy_EVENT_HANGUP);
1809 }
1810 }
1811 break;
1812 case C_CM_MCTS:
1813 info->icount.cts++;
1814 delta_count++;
1815 break;
1816 case C_CM_MRI:
1817 info->icount.rng++;
1818 delta_count++;
1819 break;
1820 case C_CM_MDSR:
1821 info->icount.dsr++;
1822 delta_count++;
1823 break;
1775#ifdef Z_WAKE 1824#ifdef Z_WAKE
1776 case C_CM_IOCTLW: 1825 case C_CM_IOCTLW:
1777 cy_sched_event(info, Cy_EVENT_SHUTDOWN_WAKEUP); 1826 cy_sched_event(info, Cy_EVENT_SHUTDOWN_WAKEUP);
1778 break; 1827 break;
1779#endif 1828#endif
1780#ifdef CONFIG_CYZ_INTR 1829#ifdef CONFIG_CYZ_INTR
1781 case C_CM_RXHIWM: 1830 case C_CM_RXHIWM:
1782 case C_CM_RXNNDT: 1831 case C_CM_RXNNDT:
1783 case C_CM_INTBACK2: 1832 case C_CM_INTBACK2:
1784 /* Reception Interrupt */ 1833 /* Reception Interrupt */
1785#ifdef CY_DEBUG_INTERRUPTS 1834#ifdef CY_DEBUG_INTERRUPTS
1786 printk("cyz_interrupt: rcvd intr, card %d, port %ld\n\r", 1835 printk("cyz_interrupt: rcvd intr, card %d, "
1787 info->card, channel); 1836 "port %ld\n\r", info->card, channel);
1788#endif 1837#endif
1789 cyz_handle_rx(info, ch_ctrl, buf_ctrl); 1838 cyz_handle_rx(info, ch_ctrl, buf_ctrl);
1790 break; 1839 break;
1791 case C_CM_TXBEMPTY: 1840 case C_CM_TXBEMPTY:
1792 case C_CM_TXLOWWM: 1841 case C_CM_TXLOWWM:
1793 case C_CM_INTBACK: 1842 case C_CM_INTBACK:
1794 /* Transmission Interrupt */ 1843 /* Transmission Interrupt */
1795#ifdef CY_DEBUG_INTERRUPTS 1844#ifdef CY_DEBUG_INTERRUPTS
1796 printk("cyz_interrupt: xmit intr, card %d, port %ld\n\r", 1845 printk("cyz_interrupt: xmit intr, card %d, "
1797 info->card, channel); 1846 "port %ld\n\r", info->card, channel);
1798#endif 1847#endif
1799 cyz_handle_tx(info, ch_ctrl, buf_ctrl); 1848 cyz_handle_tx(info, ch_ctrl, buf_ctrl);
1800 break; 1849 break;
1801#endif /* CONFIG_CYZ_INTR */ 1850#endif /* CONFIG_CYZ_INTR */
1802 case C_CM_FATAL: 1851 case C_CM_FATAL:
1803 /* should do something with this !!! */ 1852 /* should do something with this !!! */
1804 break; 1853 break;
1805 default: 1854 default:
1806 break; 1855 break;
1856 }
1857 if (delta_count)
1858 cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
1859 if (special_count)
1860 tty_schedule_flip(tty);
1807 } 1861 }
1808 if(delta_count)
1809 cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
1810 if(special_count)
1811 tty_schedule_flip(tty);
1812 }
1813} 1862}
1814 1863
1815#ifdef CONFIG_CYZ_INTR 1864#ifdef CONFIG_CYZ_INTR
1816static irqreturn_t 1865static irqreturn_t cyz_interrupt(int irq, void *dev_id)
1817cyz_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1818{ 1866{
1819 struct cyclades_card *cinfo; 1867 struct cyclades_card *cinfo;
1820 1868
1821 if((cinfo = (struct cyclades_card *)dev_id) == 0){ 1869 if ((cinfo = (struct cyclades_card *)dev_id) == 0) {
1822#ifdef CY_DEBUG_INTERRUPTS 1870#ifdef CY_DEBUG_INTERRUPTS
1823 printk("cyz_interrupt: spurious interrupt %d\n\r", irq); 1871 printk("cyz_interrupt: spurious interrupt %d\n\r", irq);
1824#endif 1872#endif
1825 return IRQ_NONE; /* spurious interrupt */ 1873 return IRQ_NONE; /* spurious interrupt */
1826 } 1874 }
1827 1875
1828 if (!ISZLOADED(*cinfo)) { 1876 if (!ISZLOADED(*cinfo)) {
1829#ifdef CY_DEBUG_INTERRUPTS 1877#ifdef CY_DEBUG_INTERRUPTS
1830 printk("cyz_interrupt: board not yet loaded (IRQ%d).\n\r", irq); 1878 printk("cyz_interrupt: board not yet loaded (IRQ%d).\n\r", irq);
1831#endif 1879#endif
1832 return IRQ_NONE; 1880 return IRQ_NONE;
1833 } 1881 }
1834 1882
1835 /* Handle the interrupts */ 1883 /* Handle the interrupts */
1836 cyz_handle_cmd(cinfo); 1884 cyz_handle_cmd(cinfo);
1837 1885
1838 return IRQ_HANDLED; 1886 return IRQ_HANDLED;
1839} /* cyz_interrupt */ 1887} /* cyz_interrupt */
1840 1888
1841static void 1889static void cyz_rx_restart(unsigned long arg)
1842cyz_rx_restart(unsigned long arg)
1843{ 1890{
1844 struct cyclades_port *info = (struct cyclades_port *)arg; 1891 struct cyclades_port *info = (struct cyclades_port *)arg;
1845 int retval; 1892 int retval;
1846 int card = info->card; 1893 int card = info->card;
1847 uclong channel = (info->line) - (cy_card[card].first_line); 1894 uclong channel = (info->line) - (cy_card[card].first_line);
1848 unsigned long flags; 1895 unsigned long flags;
1849 1896
1850 CY_LOCK(info, flags); 1897 CY_LOCK(info, flags);
1851 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK2, 0L); 1898 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK2, 0L);
1852 if (retval != 0){ 1899 if (retval != 0) {
1853 printk("cyc:cyz_rx_restart retval on ttyC%d was %x\n", 1900 printk("cyc:cyz_rx_restart retval on ttyC%d was %x\n",
1854 info->line, retval); 1901 info->line, retval);
1855 } 1902 }
1856 cyz_rx_full_timer[info->line].function = NULL; 1903 cyz_rx_full_timer[info->line].function = NULL;
1857 CY_UNLOCK(info, flags); 1904 CY_UNLOCK(info, flags);
1858} 1905}
1859 1906
1860#else /* CONFIG_CYZ_INTR */ 1907#else /* CONFIG_CYZ_INTR */
1861 1908
1862static void 1909static void cyz_poll(unsigned long arg)
1863cyz_poll(unsigned long arg)
1864{ 1910{
1865 struct cyclades_card *cinfo; 1911 struct cyclades_card *cinfo;
1866 struct cyclades_port *info; 1912 struct cyclades_port *info;
1867 struct tty_struct *tty; 1913 struct tty_struct *tty;
1868 static volatile struct FIRM_ID *firm_id; 1914 static volatile struct FIRM_ID *firm_id;
1869 static volatile struct ZFW_CTRL *zfw_ctrl; 1915 static volatile struct ZFW_CTRL *zfw_ctrl;
1870 static volatile struct BOARD_CTRL *board_ctrl; 1916 static volatile struct BOARD_CTRL *board_ctrl;
1871 static volatile struct CH_CTRL *ch_ctrl; 1917 static volatile struct CH_CTRL *ch_ctrl;
1872 static volatile struct BUF_CTRL *buf_ctrl; 1918 static volatile struct BUF_CTRL *buf_ctrl;
1873 int card, port; 1919 int card, port;
1874
1875 cyz_timerlist.expires = jiffies + (HZ);
1876 for (card = 0 ; card < NR_CARDS ; card++){
1877 cinfo = &cy_card[card];
1878
1879 if (!IS_CYC_Z(*cinfo)) continue;
1880 if (!ISZLOADED(*cinfo)) continue;
1881 1920
1882 firm_id = cinfo->base_addr + ID_ADDRESS; 1921 cyz_timerlist.expires = jiffies + (HZ);
1883 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 1922 for (card = 0; card < NR_CARDS; card++) {
1884 board_ctrl = &(zfw_ctrl->board_ctrl); 1923 cinfo = &cy_card[card];
1924
1925 if (!IS_CYC_Z(*cinfo))
1926 continue;
1927 if (!ISZLOADED(*cinfo))
1928 continue;
1929
1930 firm_id = cinfo->base_addr + ID_ADDRESS;
1931 zfw_ctrl = cinfo->base_addr +
1932 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
1933 board_ctrl = &(zfw_ctrl->board_ctrl);
1885 1934
1886 /* Skip first polling cycle to avoid racing conditions with the FW */ 1935 /* Skip first polling cycle to avoid racing conditions with the FW */
1887 if (!cinfo->intr_enabled) { 1936 if (!cinfo->intr_enabled) {
1888 cinfo->nports = (int) cy_readl(&board_ctrl->n_channel); 1937 cinfo->nports = (int)cy_readl(&board_ctrl->n_channel);
1889 cinfo->intr_enabled = 1; 1938 cinfo->intr_enabled = 1;
1890 continue; 1939 continue;
1891 } 1940 }
1892 1941
1893 cyz_handle_cmd(cinfo); 1942 cyz_handle_cmd(cinfo);
1894 1943
1895 for (port = 0 ; port < cinfo->nports ; port++) { 1944 for (port = 0; port < cinfo->nports; port++) {
1896 info = &cy_port[ port + cinfo->first_line ]; 1945 info = &cy_port[port + cinfo->first_line];
1897 tty = info->tty; 1946 tty = info->tty;
1898 ch_ctrl = &(zfw_ctrl->ch_ctrl[port]); 1947 ch_ctrl = &(zfw_ctrl->ch_ctrl[port]);
1899 buf_ctrl = &(zfw_ctrl->buf_ctrl[port]); 1948 buf_ctrl = &(zfw_ctrl->buf_ctrl[port]);
1900 1949
1901 if (!info->throttle) 1950 if (!info->throttle)
1902 cyz_handle_rx(info, ch_ctrl, buf_ctrl); 1951 cyz_handle_rx(info, ch_ctrl, buf_ctrl);
1903 cyz_handle_tx(info, ch_ctrl, buf_ctrl); 1952 cyz_handle_tx(info, ch_ctrl, buf_ctrl);
1953 }
1954 /* poll every 'cyz_polling_cycle' period */
1955 cyz_timerlist.expires = jiffies + cyz_polling_cycle;
1904 } 1956 }
1905 /* poll every 'cyz_polling_cycle' period */ 1957 add_timer(&cyz_timerlist);
1906 cyz_timerlist.expires = jiffies + cyz_polling_cycle; 1958} /* cyz_poll */
1907 }
1908 add_timer(&cyz_timerlist);
1909
1910 return;
1911} /* cyz_poll */
1912 1959
1913#endif /* CONFIG_CYZ_INTR */ 1960#endif /* CONFIG_CYZ_INTR */
1914 1961
1915/********** End of block of Cyclades-Z specific code *********/ 1962/********** End of block of Cyclades-Z specific code *********/
1916/***********************************************************/ 1963/***********************************************************/
1917 1964
1918
1919/* This is called whenever a port becomes active; 1965/* This is called whenever a port becomes active;
1920 interrupts are enabled and DTR & RTS are turned on. 1966 interrupts are enabled and DTR & RTS are turned on.
1921 */ 1967 */
1922static int 1968static int startup(struct cyclades_port *info)
1923startup(struct cyclades_port * info)
1924{ 1969{
1925 unsigned long flags; 1970 unsigned long flags;
1926 int retval = 0; 1971 int retval = 0;
1927 void __iomem *base_addr; 1972 void __iomem *base_addr;
1928 int card,chip,channel,index; 1973 int card, chip, channel, index;
1929 unsigned long page; 1974 unsigned long page;
1930 1975
1931 card = info->card; 1976 card = info->card;
1932 channel = (info->line) - (cy_card[card].first_line); 1977 channel = (info->line) - (cy_card[card].first_line);
1933 1978
1934 page = get_zeroed_page(GFP_KERNEL); 1979 page = get_zeroed_page(GFP_KERNEL);
1935 if (!page) 1980 if (!page)
1936 return -ENOMEM; 1981 return -ENOMEM;
1937 1982
1938 CY_LOCK(info, flags); 1983 CY_LOCK(info, flags);
1939 1984
1940 if (info->flags & ASYNC_INITIALIZED){ 1985 if (info->flags & ASYNC_INITIALIZED) {
1941 free_page(page); 1986 free_page(page);
1942 goto errout; 1987 goto errout;
1943 } 1988 }
1944 1989
1945 if (!info->type){ 1990 if (!info->type) {
1946 if (info->tty){ 1991 if (info->tty) {
1947 set_bit(TTY_IO_ERROR, &info->tty->flags); 1992 set_bit(TTY_IO_ERROR, &info->tty->flags);
1948 } 1993 }
1949 free_page(page); 1994 free_page(page);
1950 goto errout; 1995 goto errout;
1951 } 1996 }
1952 1997
1953 if (info->xmit_buf) 1998 if (info->xmit_buf)
1954 free_page(page); 1999 free_page(page);
1955 else 2000 else
1956 info->xmit_buf = (unsigned char *) page; 2001 info->xmit_buf = (unsigned char *)page;
1957 2002
1958 CY_UNLOCK(info, flags); 2003 CY_UNLOCK(info, flags);
1959 2004
1960 set_line_char(info); 2005 set_line_char(info);
1961 2006
1962 if (!IS_CYC_Z(cy_card[card])) { 2007 if (!IS_CYC_Z(cy_card[card])) {
1963 chip = channel>>2; 2008 chip = channel >> 2;
1964 channel &= 0x03; 2009 channel &= 0x03;
1965 index = cy_card[card].bus_index; 2010 index = cy_card[card].bus_index;
1966 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index); 2011 base_addr = cy_card[card].base_addr +
2012 (cy_chip_offset[chip] << index);
1967 2013
1968#ifdef CY_DEBUG_OPEN 2014#ifdef CY_DEBUG_OPEN
1969 printk("cyc startup card %d, chip %d, channel %d, base_addr %lx\n", 2015 printk("cyc startup card %d, chip %d, channel %d, "
1970 card, chip, channel, (long)base_addr);/**/ 2016 "base_addr %lx\n",
2017 card, chip, channel, (long)base_addr);
2018 /**/
1971#endif 2019#endif
2020 CY_LOCK(info, flags);
1972 2021
1973 CY_LOCK(info, flags); 2022 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
1974
1975 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
1976 2023
1977 cy_writeb(base_addr+(CyRTPR<<index), (info->default_timeout 2024 cy_writeb(base_addr + (CyRTPR << index),
1978 ? info->default_timeout : 0x02)); /* 10ms rx timeout */ 2025 (info->default_timeout ? info->default_timeout : 0x02));
2026 /* 10ms rx timeout */
1979 2027
1980 cyy_issue_cmd(base_addr,CyCHAN_CTL|CyENB_RCVR|CyENB_XMTR,index); 2028 cyy_issue_cmd(base_addr, CyCHAN_CTL | CyENB_RCVR | CyENB_XMTR,
2029 index);
1981 2030
1982 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 2031 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
1983 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS); 2032 cy_writeb(base_addr + (CyMSVR1 << index), CyRTS);
1984 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR); 2033 cy_writeb(base_addr + (CyMSVR2 << index), CyDTR);
1985 2034
1986#ifdef CY_DEBUG_DTR 2035#ifdef CY_DEBUG_DTR
1987 printk("cyc:startup raising DTR\n"); 2036 printk("cyc:startup raising DTR\n");
1988 printk(" status: 0x%x, 0x%x\n", 2037 printk(" status: 0x%x, 0x%x\n",
1989 cy_readb(base_addr+(CyMSVR1<<index)), 2038 cy_readb(base_addr + (CyMSVR1 << index)),
1990 cy_readb(base_addr+(CyMSVR2<<index))); 2039 cy_readb(base_addr + (CyMSVR2 << index)));
1991#endif 2040#endif
1992 2041
1993 cy_writeb(base_addr+(CySRER<<index), 2042 cy_writeb(base_addr + (CySRER << index),
1994 cy_readb(base_addr+(CySRER<<index)) | CyRxData); 2043 cy_readb(base_addr + (CySRER << index)) | CyRxData);
1995 info->flags |= ASYNC_INITIALIZED; 2044 info->flags |= ASYNC_INITIALIZED;
1996 2045
1997 if (info->tty){ 2046 if (info->tty) {
1998 clear_bit(TTY_IO_ERROR, &info->tty->flags); 2047 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1999 } 2048 }
2000 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 2049 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2001 info->breakon = info->breakoff = 0; 2050 info->breakon = info->breakoff = 0;
2002 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats)); 2051 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats));
2003 info->idle_stats.in_use = 2052 info->idle_stats.in_use =
2004 info->idle_stats.recv_idle = 2053 info->idle_stats.recv_idle =
2005 info->idle_stats.xmit_idle = jiffies; 2054 info->idle_stats.xmit_idle = jiffies;
2006 2055
2007 CY_UNLOCK(info, flags); 2056 CY_UNLOCK(info, flags);
2008 2057
2009 } else { 2058 } else {
2010 struct FIRM_ID __iomem *firm_id; 2059 struct FIRM_ID __iomem *firm_id;
2011 struct ZFW_CTRL __iomem *zfw_ctrl; 2060 struct ZFW_CTRL __iomem *zfw_ctrl;
2012 struct BOARD_CTRL __iomem *board_ctrl; 2061 struct BOARD_CTRL __iomem *board_ctrl;
2013 struct CH_CTRL __iomem *ch_ctrl; 2062 struct CH_CTRL __iomem *ch_ctrl;
2014 int retval; 2063 int retval;
2015 2064
2016 base_addr = cy_card[card].base_addr; 2065 base_addr = cy_card[card].base_addr;
2017 2066
2018 firm_id = base_addr + ID_ADDRESS; 2067 firm_id = base_addr + ID_ADDRESS;
2019 if (!ISZLOADED(cy_card[card])){ 2068 if (!ISZLOADED(cy_card[card])) {
2020 return -ENODEV; 2069 return -ENODEV;
2021 } 2070 }
2022 2071
2023 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 2072 zfw_ctrl = cy_card[card].base_addr +
2024 board_ctrl = &zfw_ctrl->board_ctrl; 2073 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2025 ch_ctrl = zfw_ctrl->ch_ctrl; 2074 board_ctrl = &zfw_ctrl->board_ctrl;
2075 ch_ctrl = zfw_ctrl->ch_ctrl;
2026 2076
2027#ifdef CY_DEBUG_OPEN 2077#ifdef CY_DEBUG_OPEN
2028 printk("cyc startup Z card %d, channel %d, base_addr %lx\n", 2078 printk("cyc startup Z card %d, channel %d, base_addr %lx\n",
2029 card, channel, (long)base_addr);/**/ 2079 card, channel, (long)base_addr);
2080 /**/
2030#endif 2081#endif
2082 CY_LOCK(info, flags);
2031 2083
2032 CY_LOCK(info, flags); 2084 cy_writel(&ch_ctrl[channel].op_mode, C_CH_ENABLE);
2033
2034 cy_writel(&ch_ctrl[channel].op_mode, C_CH_ENABLE);
2035#ifdef Z_WAKE 2085#ifdef Z_WAKE
2036#ifdef CONFIG_CYZ_INTR 2086#ifdef CONFIG_CYZ_INTR
2037 cy_writel(&ch_ctrl[channel].intr_enable, 2087 cy_writel(&ch_ctrl[channel].intr_enable,
2038 C_IN_TXBEMPTY|C_IN_TXLOWWM|C_IN_RXHIWM|C_IN_RXNNDT| 2088 C_IN_TXBEMPTY | C_IN_TXLOWWM | C_IN_RXHIWM |
2039 C_IN_IOCTLW| 2089 C_IN_RXNNDT | C_IN_IOCTLW | C_IN_MDCD);
2040 C_IN_MDCD);
2041#else 2090#else
2042 cy_writel(&ch_ctrl[channel].intr_enable, 2091 cy_writel(&ch_ctrl[channel].intr_enable,
2043 C_IN_IOCTLW| 2092 C_IN_IOCTLW | C_IN_MDCD);
2044 C_IN_MDCD); 2093#endif /* CONFIG_CYZ_INTR */
2045#endif /* CONFIG_CYZ_INTR */
2046#else 2094#else
2047#ifdef CONFIG_CYZ_INTR 2095#ifdef CONFIG_CYZ_INTR
2048 cy_writel(&ch_ctrl[channel].intr_enable, 2096 cy_writel(&ch_ctrl[channel].intr_enable,
2049 C_IN_TXBEMPTY|C_IN_TXLOWWM|C_IN_RXHIWM|C_IN_RXNNDT| 2097 C_IN_TXBEMPTY | C_IN_TXLOWWM | C_IN_RXHIWM |
2050 C_IN_MDCD); 2098 C_IN_RXNNDT | C_IN_MDCD);
2051#else 2099#else
2052 cy_writel(&ch_ctrl[channel].intr_enable, 2100 cy_writel(&ch_ctrl[channel].intr_enable, C_IN_MDCD);
2053 C_IN_MDCD); 2101#endif /* CONFIG_CYZ_INTR */
2054#endif /* CONFIG_CYZ_INTR */ 2102#endif /* Z_WAKE */
2055#endif /* Z_WAKE */ 2103
2056 2104 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L);
2057 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L); 2105 if (retval != 0) {
2058 if (retval != 0){ 2106 printk("cyc:startup(1) retval on ttyC%d was %x\n",
2059 printk("cyc:startup(1) retval on ttyC%d was %x\n", 2107 info->line, retval);
2060 info->line, retval); 2108 }
2061 }
2062 2109
2063 /* Flush RX buffers before raising DTR and RTS */ 2110 /* Flush RX buffers before raising DTR and RTS */
2064 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_RX, 0L); 2111 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_RX,
2065 if (retval != 0){ 2112 0L);
2066 printk("cyc:startup(2) retval on ttyC%d was %x\n", 2113 if (retval != 0) {
2067 info->line, retval); 2114 printk("cyc:startup(2) retval on ttyC%d was %x\n",
2068 } 2115 info->line, retval);
2116 }
2069 2117
2070 /* set timeout !!! */ 2118 /* set timeout !!! */
2071 /* set RTS and DTR !!! */ 2119 /* set RTS and DTR !!! */
2072 cy_writel(&ch_ctrl[channel].rs_control, 2120 cy_writel(&ch_ctrl[channel].rs_control,
2073 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS | C_RS_DTR) ; 2121 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS |
2074 retval = cyz_issue_cmd(&cy_card[info->card], 2122 C_RS_DTR);
2075 channel, C_CM_IOCTLM, 0L); 2123 retval = cyz_issue_cmd(&cy_card[info->card], channel,
2076 if (retval != 0){ 2124 C_CM_IOCTLM, 0L);
2077 printk("cyc:startup(3) retval on ttyC%d was %x\n", 2125 if (retval != 0) {
2078 info->line, retval); 2126 printk("cyc:startup(3) retval on ttyC%d was %x\n",
2079 } 2127 info->line, retval);
2128 }
2080#ifdef CY_DEBUG_DTR 2129#ifdef CY_DEBUG_DTR
2081 printk("cyc:startup raising Z DTR\n"); 2130 printk("cyc:startup raising Z DTR\n");
2082#endif 2131#endif
2083 2132
2084 /* enable send, recv, modem !!! */ 2133 /* enable send, recv, modem !!! */
2085 2134
2086 info->flags |= ASYNC_INITIALIZED; 2135 info->flags |= ASYNC_INITIALIZED;
2087 if (info->tty){ 2136 if (info->tty) {
2088 clear_bit(TTY_IO_ERROR, &info->tty->flags); 2137 clear_bit(TTY_IO_ERROR, &info->tty->flags);
2089 } 2138 }
2090 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 2139 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2091 info->breakon = info->breakoff = 0; 2140 info->breakon = info->breakoff = 0;
2092 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats)); 2141 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats));
2093 info->idle_stats.in_use = 2142 info->idle_stats.in_use =
2094 info->idle_stats.recv_idle = 2143 info->idle_stats.recv_idle =
2095 info->idle_stats.xmit_idle = jiffies; 2144 info->idle_stats.xmit_idle = jiffies;
2096 2145
2097 CY_UNLOCK(info, flags); 2146 CY_UNLOCK(info, flags);
2098 } 2147 }
2099 2148
2100#ifdef CY_DEBUG_OPEN 2149#ifdef CY_DEBUG_OPEN
2101 printk(" cyc startup done\n"); 2150 printk(" cyc startup done\n");
@@ -2105,165 +2154,165 @@ startup(struct cyclades_port * info)
2105errout: 2154errout:
2106 CY_UNLOCK(info, flags); 2155 CY_UNLOCK(info, flags);
2107 return retval; 2156 return retval;
2108} /* startup */ 2157} /* startup */
2109 2158
2110 2159static void start_xmit(struct cyclades_port *info)
2111static void
2112start_xmit( struct cyclades_port *info )
2113{ 2160{
2114 unsigned long flags; 2161 unsigned long flags;
2115 void __iomem *base_addr; 2162 void __iomem *base_addr;
2116 int card,chip,channel,index; 2163 int card, chip, channel, index;
2117
2118 card = info->card;
2119 channel = (info->line) - (cy_card[card].first_line);
2120 if (!IS_CYC_Z(cy_card[card])) {
2121 chip = channel>>2;
2122 channel &= 0x03;
2123 index = cy_card[card].bus_index;
2124 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
2125 2164
2126 CY_LOCK(info, flags); 2165 card = info->card;
2127 cy_writeb(base_addr+(CyCAR<<index), channel); 2166 channel = (info->line) - (cy_card[card].first_line);
2128 cy_writeb(base_addr+(CySRER<<index), 2167 if (!IS_CYC_Z(cy_card[card])) {
2129 cy_readb(base_addr+(CySRER<<index)) | CyTxRdy); 2168 chip = channel >> 2;
2130 CY_UNLOCK(info, flags); 2169 channel &= 0x03;
2131 } else { 2170 index = cy_card[card].bus_index;
2171 base_addr = cy_card[card].base_addr +
2172 (cy_chip_offset[chip] << index);
2173
2174 CY_LOCK(info, flags);
2175 cy_writeb(base_addr + (CyCAR << index), channel);
2176 cy_writeb(base_addr + (CySRER << index),
2177 cy_readb(base_addr + (CySRER << index)) | CyTxRdy);
2178 CY_UNLOCK(info, flags);
2179 } else {
2132#ifdef CONFIG_CYZ_INTR 2180#ifdef CONFIG_CYZ_INTR
2133 int retval; 2181 int retval;
2134 2182
2135 CY_LOCK(info, flags); 2183 CY_LOCK(info, flags);
2136 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK, 0L); 2184 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK,
2137 if (retval != 0){ 2185 0L);
2138 printk("cyc:start_xmit retval on ttyC%d was %x\n", 2186 if (retval != 0) {
2139 info->line, retval); 2187 printk("cyc:start_xmit retval on ttyC%d was %x\n",
2140 } 2188 info->line, retval);
2141 CY_UNLOCK(info, flags); 2189 }
2142#else /* CONFIG_CYZ_INTR */ 2190 CY_UNLOCK(info, flags);
2143 /* Don't have to do anything at this time */ 2191#else /* CONFIG_CYZ_INTR */
2144#endif /* CONFIG_CYZ_INTR */ 2192 /* Don't have to do anything at this time */
2145 } 2193#endif /* CONFIG_CYZ_INTR */
2146} /* start_xmit */ 2194 }
2195} /* start_xmit */
2147 2196
2148/* 2197/*
2149 * This routine shuts down a serial port; interrupts are disabled, 2198 * This routine shuts down a serial port; interrupts are disabled,
2150 * and DTR is dropped if the hangup on close termio flag is on. 2199 * and DTR is dropped if the hangup on close termio flag is on.
2151 */ 2200 */
2152static void 2201static void shutdown(struct cyclades_port *info)
2153shutdown(struct cyclades_port * info)
2154{ 2202{
2155 unsigned long flags; 2203 unsigned long flags;
2156 void __iomem *base_addr; 2204 void __iomem *base_addr;
2157 int card,chip,channel,index; 2205 int card, chip, channel, index;
2158 2206
2159 if (!(info->flags & ASYNC_INITIALIZED)){ 2207 if (!(info->flags & ASYNC_INITIALIZED)) {
2160 return; 2208 return;
2161 } 2209 }
2162 2210
2163 card = info->card; 2211 card = info->card;
2164 channel = info->line - cy_card[card].first_line; 2212 channel = info->line - cy_card[card].first_line;
2165 if (!IS_CYC_Z(cy_card[card])) { 2213 if (!IS_CYC_Z(cy_card[card])) {
2166 chip = channel>>2; 2214 chip = channel >> 2;
2167 channel &= 0x03; 2215 channel &= 0x03;
2168 index = cy_card[card].bus_index; 2216 index = cy_card[card].bus_index;
2169 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index); 2217 base_addr = cy_card[card].base_addr +
2218 (cy_chip_offset[chip] << index);
2170 2219
2171#ifdef CY_DEBUG_OPEN 2220#ifdef CY_DEBUG_OPEN
2172 printk("cyc shutdown Y card %d, chip %d, channel %d, base_addr %lx\n", 2221 printk("cyc shutdown Y card %d, chip %d, channel %d, "
2173 card, chip, channel, (long)base_addr); 2222 "base_addr %lx\n",
2223 card, chip, channel, (long)base_addr);
2174#endif 2224#endif
2175 2225
2176 CY_LOCK(info, flags); 2226 CY_LOCK(info, flags);
2177 2227
2178 /* Clear delta_msr_wait queue to avoid mem leaks. */ 2228 /* Clear delta_msr_wait queue to avoid mem leaks. */
2179 wake_up_interruptible(&info->delta_msr_wait); 2229 wake_up_interruptible(&info->delta_msr_wait);
2180 2230
2181 if (info->xmit_buf){ 2231 if (info->xmit_buf) {
2182 unsigned char * temp; 2232 unsigned char *temp;
2183 temp = info->xmit_buf; 2233 temp = info->xmit_buf;
2184 info->xmit_buf = NULL; 2234 info->xmit_buf = NULL;
2185 free_page((unsigned long) temp); 2235 free_page((unsigned long)temp);
2186 } 2236 }
2187 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 2237 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
2188 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) { 2238 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
2189 cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS); 2239 cy_writeb(base_addr + (CyMSVR1 << index), ~CyRTS);
2190 cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR); 2240 cy_writeb(base_addr + (CyMSVR2 << index), ~CyDTR);
2191#ifdef CY_DEBUG_DTR 2241#ifdef CY_DEBUG_DTR
2192 printk("cyc shutdown dropping DTR\n"); 2242 printk("cyc shutdown dropping DTR\n");
2193 printk(" status: 0x%x, 0x%x\n", 2243 printk(" status: 0x%x, 0x%x\n",
2194 cy_readb(base_addr+(CyMSVR1<<index)), 2244 cy_readb(base_addr + (CyMSVR1 << index)),
2195 cy_readb(base_addr+(CyMSVR2<<index))); 2245 cy_readb(base_addr + (CyMSVR2 << index)));
2196#endif 2246#endif
2197 } 2247 }
2198 cyy_issue_cmd(base_addr,CyCHAN_CTL|CyDIS_RCVR,index); 2248 cyy_issue_cmd(base_addr, CyCHAN_CTL | CyDIS_RCVR, index);
2199 /* it may be appropriate to clear _XMIT at 2249 /* it may be appropriate to clear _XMIT at
2200 some later date (after testing)!!! */ 2250 some later date (after testing)!!! */
2201 2251
2202 if (info->tty){ 2252 if (info->tty) {
2203 set_bit(TTY_IO_ERROR, &info->tty->flags); 2253 set_bit(TTY_IO_ERROR, &info->tty->flags);
2204 } 2254 }
2205 info->flags &= ~ASYNC_INITIALIZED; 2255 info->flags &= ~ASYNC_INITIALIZED;
2206 CY_UNLOCK(info, flags); 2256 CY_UNLOCK(info, flags);
2207 } else { 2257 } else {
2208 struct FIRM_ID __iomem *firm_id; 2258 struct FIRM_ID __iomem *firm_id;
2209 struct ZFW_CTRL __iomem *zfw_ctrl; 2259 struct ZFW_CTRL __iomem *zfw_ctrl;
2210 struct BOARD_CTRL __iomem *board_ctrl; 2260 struct BOARD_CTRL __iomem *board_ctrl;
2211 struct CH_CTRL __iomem *ch_ctrl; 2261 struct CH_CTRL __iomem *ch_ctrl;
2212 int retval; 2262 int retval;
2213 2263
2214 base_addr = cy_card[card].base_addr; 2264 base_addr = cy_card[card].base_addr;
2215#ifdef CY_DEBUG_OPEN 2265#ifdef CY_DEBUG_OPEN
2216 printk("cyc shutdown Z card %d, channel %d, base_addr %lx\n", 2266 printk("cyc shutdown Z card %d, channel %d, base_addr %lx\n",
2217 card, channel, (long)base_addr); 2267 card, channel, (long)base_addr);
2218#endif 2268#endif
2219 2269
2220 firm_id = base_addr + ID_ADDRESS; 2270 firm_id = base_addr + ID_ADDRESS;
2221 if (!ISZLOADED(cy_card[card])) { 2271 if (!ISZLOADED(cy_card[card])) {
2222 return; 2272 return;
2223 } 2273 }
2224 2274
2225 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 2275 zfw_ctrl = cy_card[card].base_addr +
2226 board_ctrl = &zfw_ctrl->board_ctrl; 2276 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2227 ch_ctrl = zfw_ctrl->ch_ctrl; 2277 board_ctrl = &zfw_ctrl->board_ctrl;
2278 ch_ctrl = zfw_ctrl->ch_ctrl;
2228 2279
2229 CY_LOCK(info, flags); 2280 CY_LOCK(info, flags);
2230 2281
2231 if (info->xmit_buf){ 2282 if (info->xmit_buf) {
2232 unsigned char * temp; 2283 unsigned char *temp;
2233 temp = info->xmit_buf; 2284 temp = info->xmit_buf;
2234 info->xmit_buf = NULL; 2285 info->xmit_buf = NULL;
2235 free_page((unsigned long) temp); 2286 free_page((unsigned long)temp);
2236 }
2237
2238 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
2239 cy_writel(&ch_ctrl[channel].rs_control,
2240 (uclong)(cy_readl(&ch_ctrl[channel].rs_control) &
2241 ~(C_RS_RTS | C_RS_DTR)));
2242 retval = cyz_issue_cmd(&cy_card[info->card],
2243 channel, C_CM_IOCTLM, 0L);
2244 if (retval != 0){
2245 printk("cyc:shutdown retval on ttyC%d was %x\n",
2246 info->line, retval);
2247 } 2287 }
2288
2289 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
2290 cy_writel(&ch_ctrl[channel].rs_control,
2291 (uclong)(cy_readl(&ch_ctrl[channel].rs_control)&
2292 ~(C_RS_RTS | C_RS_DTR)));
2293 retval = cyz_issue_cmd(&cy_card[info->card], channel,
2294 C_CM_IOCTLM, 0L);
2295 if (retval != 0) {
2296 printk("cyc:shutdown retval on ttyC%d was %x\n",
2297 info->line, retval);
2298 }
2248#ifdef CY_DEBUG_DTR 2299#ifdef CY_DEBUG_DTR
2249 printk("cyc:shutdown dropping Z DTR\n"); 2300 printk("cyc:shutdown dropping Z DTR\n");
2250#endif 2301#endif
2251 } 2302 }
2252
2253 if (info->tty){
2254 set_bit(TTY_IO_ERROR, &info->tty->flags);
2255 }
2256 info->flags &= ~ASYNC_INITIALIZED;
2257 2303
2258 CY_UNLOCK(info, flags); 2304 if (info->tty) {
2259 } 2305 set_bit(TTY_IO_ERROR, &info->tty->flags);
2306 }
2307 info->flags &= ~ASYNC_INITIALIZED;
2308
2309 CY_UNLOCK(info, flags);
2310 }
2260 2311
2261#ifdef CY_DEBUG_OPEN 2312#ifdef CY_DEBUG_OPEN
2262 printk(" cyc shutdown done\n"); 2313 printk(" cyc shutdown done\n");
2263#endif 2314#endif
2264 return; 2315} /* shutdown */
2265} /* shutdown */
2266
2267 2316
2268/* 2317/*
2269 * ------------------------------------------------------------ 2318 * ------------------------------------------------------------
@@ -2272,537 +2321,546 @@ shutdown(struct cyclades_port * info)
2272 */ 2321 */
2273 2322
2274static int 2323static int
2275block_til_ready(struct tty_struct *tty, struct file * filp, 2324block_til_ready(struct tty_struct *tty, struct file *filp,
2276 struct cyclades_port *info) 2325 struct cyclades_port *info)
2277{ 2326{
2278 DECLARE_WAITQUEUE(wait, current); 2327 DECLARE_WAITQUEUE(wait, current);
2279 struct cyclades_card *cinfo; 2328 struct cyclades_card *cinfo;
2280 unsigned long flags; 2329 unsigned long flags;
2281 int chip, channel,index; 2330 int chip, channel, index;
2282 int retval; 2331 int retval;
2283 void __iomem *base_addr; 2332 void __iomem *base_addr;
2284 2333
2285 cinfo = &cy_card[info->card]; 2334 cinfo = &cy_card[info->card];
2286 channel = info->line - cinfo->first_line; 2335 channel = info->line - cinfo->first_line;
2287 2336
2288 /* 2337 /*
2289 * If the device is in the middle of being closed, then block 2338 * If the device is in the middle of being closed, then block
2290 * until it's done, and then try again. 2339 * until it's done, and then try again.
2291 */ 2340 */
2292 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) { 2341 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
2293 if (info->flags & ASYNC_CLOSING) { 2342 if (info->flags & ASYNC_CLOSING) {
2294 interruptible_sleep_on(&info->close_wait); 2343 interruptible_sleep_on(&info->close_wait);
2344 }
2345 return (info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
2346 }
2347
2348 /*
2349 * If non-blocking mode is set, then make the check up front
2350 * and then exit.
2351 */
2352 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
2353 info->flags |= ASYNC_NORMAL_ACTIVE;
2354 return 0;
2295 } 2355 }
2296 return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); 2356
2297 } 2357 /*
2298 2358 * Block waiting for the carrier detect and the line to become
2299 /* 2359 * free (i.e., not in use by the callout). While we are in
2300 * If non-blocking mode is set, then make the check up front 2360 * this loop, info->count is dropped by one, so that
2301 * and then exit. 2361 * cy_close() knows when to free things. We restore it upon
2302 */ 2362 * exit, either normal or abnormal.
2303 if ((filp->f_flags & O_NONBLOCK) || 2363 */
2304 (tty->flags & (1 << TTY_IO_ERROR))) { 2364 retval = 0;
2305 info->flags |= ASYNC_NORMAL_ACTIVE; 2365 add_wait_queue(&info->open_wait, &wait);
2306 return 0;
2307 }
2308
2309 /*
2310 * Block waiting for the carrier detect and the line to become
2311 * free (i.e., not in use by the callout). While we are in
2312 * this loop, info->count is dropped by one, so that
2313 * cy_close() knows when to free things. We restore it upon
2314 * exit, either normal or abnormal.
2315 */
2316 retval = 0;
2317 add_wait_queue(&info->open_wait, &wait);
2318#ifdef CY_DEBUG_OPEN 2366#ifdef CY_DEBUG_OPEN
2319 printk("cyc block_til_ready before block: ttyC%d, count = %d\n", 2367 printk("cyc block_til_ready before block: ttyC%d, count = %d\n",
2320 info->line, info->count);/**/ 2368 info->line, info->count);
2369 /**/
2321#endif 2370#endif
2322 CY_LOCK(info, flags); 2371 CY_LOCK(info, flags);
2323 if (!tty_hung_up_p(filp)) 2372 if (!tty_hung_up_p(filp))
2324 info->count--; 2373 info->count--;
2325 CY_UNLOCK(info, flags); 2374 CY_UNLOCK(info, flags);
2326#ifdef CY_DEBUG_COUNT 2375#ifdef CY_DEBUG_COUNT
2327 printk("cyc block_til_ready: (%d): decrementing count to %d\n", 2376 printk("cyc block_til_ready: (%d): decrementing count to %d\n",
2328 current->pid, info->count); 2377 current->pid, info->count);
2329#endif 2378#endif
2330 info->blocked_open++; 2379 info->blocked_open++;
2331 2380
2332 if (!IS_CYC_Z(*cinfo)) { 2381 if (!IS_CYC_Z(*cinfo)) {
2333 chip = channel>>2; 2382 chip = channel >> 2;
2334 channel &= 0x03; 2383 channel &= 0x03;
2335 index = cinfo->bus_index; 2384 index = cinfo->bus_index;
2336 base_addr = cinfo->base_addr + (cy_chip_offset[chip]<<index); 2385 base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index);
2337 2386
2338 while (1) { 2387 while (1) {
2339 CY_LOCK(info, flags); 2388 CY_LOCK(info, flags);
2340 if ((tty->termios->c_cflag & CBAUD)){ 2389 if ((tty->termios->c_cflag & CBAUD)) {
2341 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 2390 cy_writeb(base_addr + (CyCAR << index),
2342 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS); 2391 (u_char) channel);
2343 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR); 2392 cy_writeb(base_addr + (CyMSVR1 << index),
2393 CyRTS);
2394 cy_writeb(base_addr + (CyMSVR2 << index),
2395 CyDTR);
2344#ifdef CY_DEBUG_DTR 2396#ifdef CY_DEBUG_DTR
2345 printk("cyc:block_til_ready raising DTR\n"); 2397 printk("cyc:block_til_ready raising DTR\n");
2346 printk(" status: 0x%x, 0x%x\n", 2398 printk(" status: 0x%x, 0x%x\n",
2347 cy_readb(base_addr+(CyMSVR1<<index)), 2399 cy_readb(base_addr +
2348 cy_readb(base_addr+(CyMSVR2<<index))); 2400 (CyMSVR1 << index)),
2401 cy_readb(base_addr +
2402 (CyMSVR2 << index)));
2349#endif 2403#endif
2350 } 2404 }
2351 CY_UNLOCK(info, flags); 2405 CY_UNLOCK(info, flags);
2352 2406
2353 set_current_state(TASK_INTERRUPTIBLE); 2407 set_current_state(TASK_INTERRUPTIBLE);
2354 if (tty_hung_up_p(filp) 2408 if (tty_hung_up_p(filp) ||
2355 || !(info->flags & ASYNC_INITIALIZED) ){ 2409 !(info->flags & ASYNC_INITIALIZED)) {
2356 retval = ((info->flags & ASYNC_HUP_NOTIFY) ? 2410 retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
2357 -EAGAIN : -ERESTARTSYS); 2411 -EAGAIN : -ERESTARTSYS);
2358 break; 2412 break;
2359 } 2413 }
2360 2414
2361 CY_LOCK(info, flags); 2415 CY_LOCK(info, flags);
2362 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 2416 cy_writeb(base_addr + (CyCAR << index),
2363 if (!(info->flags & ASYNC_CLOSING) 2417 (u_char) channel);
2364 && (C_CLOCAL(tty) 2418 if (!(info->flags & ASYNC_CLOSING) && (C_CLOCAL(tty) ||
2365 || (cy_readb(base_addr+(CyMSVR1<<index)) & CyDCD))) { 2419 (cy_readb(base_addr +
2420 (CyMSVR1 << index)) & CyDCD))) {
2421 CY_UNLOCK(info, flags);
2422 break;
2423 }
2366 CY_UNLOCK(info, flags); 2424 CY_UNLOCK(info, flags);
2367 break;
2368 }
2369 CY_UNLOCK(info, flags);
2370 2425
2371 if (signal_pending(current)) { 2426 if (signal_pending(current)) {
2372 retval = -ERESTARTSYS; 2427 retval = -ERESTARTSYS;
2373 break; 2428 break;
2374 } 2429 }
2375#ifdef CY_DEBUG_OPEN 2430#ifdef CY_DEBUG_OPEN
2376 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n", 2431 printk("cyc block_til_ready blocking: ttyC%d, "
2377 info->line, info->count);/**/ 2432 "count = %d\n",
2433 info->line, info->count);
2434 /**/
2378#endif 2435#endif
2379 schedule(); 2436 schedule();
2380 } 2437 }
2381 } else { 2438 } else {
2382 struct FIRM_ID __iomem *firm_id; 2439 struct FIRM_ID __iomem *firm_id;
2383 struct ZFW_CTRL __iomem *zfw_ctrl; 2440 struct ZFW_CTRL __iomem *zfw_ctrl;
2384 struct BOARD_CTRL __iomem *board_ctrl; 2441 struct BOARD_CTRL __iomem *board_ctrl;
2385 struct CH_CTRL __iomem *ch_ctrl; 2442 struct CH_CTRL __iomem *ch_ctrl;
2386 int retval; 2443 int retval;
2387 2444
2388 base_addr = cinfo->base_addr; 2445 base_addr = cinfo->base_addr;
2389 firm_id = base_addr + ID_ADDRESS; 2446 firm_id = base_addr + ID_ADDRESS;
2390 if (!ISZLOADED(*cinfo)){ 2447 if (!ISZLOADED(*cinfo)) {
2391 current->state = TASK_RUNNING; 2448 current->state = TASK_RUNNING;
2392 remove_wait_queue(&info->open_wait, &wait); 2449 remove_wait_queue(&info->open_wait, &wait);
2393 return -EINVAL; 2450 return -EINVAL;
2394 }
2395
2396 zfw_ctrl = base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2397 board_ctrl = &zfw_ctrl->board_ctrl;
2398 ch_ctrl = zfw_ctrl->ch_ctrl;
2399
2400 while (1) {
2401 if ((tty->termios->c_cflag & CBAUD)){
2402 cy_writel(&ch_ctrl[channel].rs_control,
2403 cy_readl(&ch_ctrl[channel].rs_control) |
2404 (C_RS_RTS | C_RS_DTR));
2405 retval = cyz_issue_cmd(&cy_card[info->card],
2406 channel, C_CM_IOCTLM, 0L);
2407 if (retval != 0){
2408 printk("cyc:block_til_ready retval on ttyC%d was %x\n",
2409 info->line, retval);
2410 } 2451 }
2452
2453 zfw_ctrl = base_addr + (cy_readl(&firm_id->zfwctrl_addr) &
2454 0xfffff);
2455 board_ctrl = &zfw_ctrl->board_ctrl;
2456 ch_ctrl = zfw_ctrl->ch_ctrl;
2457
2458 while (1) {
2459 if ((tty->termios->c_cflag & CBAUD)) {
2460 cy_writel(&ch_ctrl[channel].rs_control,
2461 cy_readl(&ch_ctrl[channel].
2462 rs_control) | (C_RS_RTS |
2463 C_RS_DTR));
2464 retval = cyz_issue_cmd(&cy_card[info->card],
2465 channel, C_CM_IOCTLM, 0L);
2466 if (retval != 0) {
2467 printk("cyc:block_til_ready retval on "
2468 "ttyC%d was %x\n",
2469 info->line, retval);
2470 }
2411#ifdef CY_DEBUG_DTR 2471#ifdef CY_DEBUG_DTR
2412 printk("cyc:block_til_ready raising Z DTR\n"); 2472 printk("cyc:block_til_ready raising Z DTR\n");
2413#endif 2473#endif
2414 } 2474 }
2415 2475
2416 set_current_state(TASK_INTERRUPTIBLE); 2476 set_current_state(TASK_INTERRUPTIBLE);
2417 if (tty_hung_up_p(filp) 2477 if (tty_hung_up_p(filp) ||
2418 || !(info->flags & ASYNC_INITIALIZED) ){ 2478 !(info->flags & ASYNC_INITIALIZED)) {
2419 retval = ((info->flags & ASYNC_HUP_NOTIFY) ? 2479 retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
2420 -EAGAIN : -ERESTARTSYS); 2480 -EAGAIN : -ERESTARTSYS);
2421 break; 2481 break;
2422 } 2482 }
2423 if (!(info->flags & ASYNC_CLOSING) 2483 if (!(info->flags & ASYNC_CLOSING) && (C_CLOCAL(tty) ||
2424 && (C_CLOCAL(tty) 2484 (cy_readl(&ch_ctrl[channel].rs_status) &
2425 || (cy_readl(&ch_ctrl[channel].rs_status) & C_RS_DCD))) { 2485 C_RS_DCD))) {
2426 break; 2486 break;
2427 } 2487 }
2428 if (signal_pending(current)) { 2488 if (signal_pending(current)) {
2429 retval = -ERESTARTSYS; 2489 retval = -ERESTARTSYS;
2430 break; 2490 break;
2431 } 2491 }
2432#ifdef CY_DEBUG_OPEN 2492#ifdef CY_DEBUG_OPEN
2433 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n", 2493 printk("cyc block_til_ready blocking: ttyC%d, "
2434 info->line, info->count);/**/ 2494 "count = %d\n",
2495 info->line, info->count);
2496 /**/
2435#endif 2497#endif
2436 schedule(); 2498 schedule();
2499 }
2437 } 2500 }
2438 } 2501 current->state = TASK_RUNNING;
2439 current->state = TASK_RUNNING; 2502 remove_wait_queue(&info->open_wait, &wait);
2440 remove_wait_queue(&info->open_wait, &wait); 2503 if (!tty_hung_up_p(filp)) {
2441 if (!tty_hung_up_p(filp)){ 2504 info->count++;
2442 info->count++;
2443#ifdef CY_DEBUG_COUNT 2505#ifdef CY_DEBUG_COUNT
2444 printk("cyc:block_til_ready (%d): incrementing count to %d\n", 2506 printk("cyc:block_til_ready (%d): incrementing count to %d\n",
2445 current->pid, info->count); 2507 current->pid, info->count);
2446#endif 2508#endif
2447 } 2509 }
2448 info->blocked_open--; 2510 info->blocked_open--;
2449#ifdef CY_DEBUG_OPEN 2511#ifdef CY_DEBUG_OPEN
2450 printk("cyc:block_til_ready after blocking: ttyC%d, count = %d\n", 2512 printk("cyc:block_til_ready after blocking: ttyC%d, count = %d\n",
2451 info->line, info->count);/**/ 2513 info->line, info->count);
2514 /**/
2452#endif 2515#endif
2453 if (retval) 2516 if (retval)
2454 return retval; 2517 return retval;
2455 info->flags |= ASYNC_NORMAL_ACTIVE; 2518 info->flags |= ASYNC_NORMAL_ACTIVE;
2456 return 0; 2519 return 0;
2457} /* block_til_ready */ 2520} /* block_til_ready */
2458
2459 2521
2460/* 2522/*
2461 * This routine is called whenever a serial port is opened. It 2523 * This routine is called whenever a serial port is opened. It
2462 * performs the serial-specific initialization for the tty structure. 2524 * performs the serial-specific initialization for the tty structure.
2463 */ 2525 */
2464static int 2526static int cy_open(struct tty_struct *tty, struct file *filp)
2465cy_open(struct tty_struct *tty, struct file * filp)
2466{ 2527{
2467 struct cyclades_port *info; 2528 struct cyclades_port *info;
2468 int retval, line; 2529 int retval, line;
2469 unsigned long page;
2470
2471 line = tty->index;
2472 if ((line < 0) || (NR_PORTS <= line)){
2473 return -ENODEV;
2474 }
2475 info = &cy_port[line];
2476 if (info->line < 0){
2477 return -ENODEV;
2478 }
2479
2480 /* If the card's firmware hasn't been loaded,
2481 treat it as absent from the system. This
2482 will make the user pay attention.
2483 */
2484 if (IS_CYC_Z(cy_card[info->card])) {
2485 struct cyclades_card *cinfo = &cy_card[info->card];
2486 struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS;
2487
2488 if (!ISZLOADED(*cinfo)) {
2489 if (((ZE_V1 ==cy_readl(&((struct RUNTIME_9060 __iomem *)
2490 (cinfo->ctl_addr))->mail_box_0)) &&
2491 Z_FPGA_CHECK (*cinfo)) &&
2492 (ZFIRM_HLT == cy_readl (&firm_id->signature)))
2493 {
2494 printk ("cyc:Cyclades-Z Error: you need an external power supply for this number of ports.\n\rFirmware halted.\r\n");
2495 } else {
2496 printk("cyc:Cyclades-Z firmware not yet loaded\n");
2497 }
2498 return -ENODEV;
2499 }
2500#ifdef CONFIG_CYZ_INTR
2501 else {
2502 /* In case this Z board is operating in interrupt mode, its
2503 interrupts should be enabled as soon as the first open happens
2504 to one of its ports. */
2505 if (!cinfo->intr_enabled) {
2506 struct ZFW_CTRL __iomem *zfw_ctrl;
2507 struct BOARD_CTRL __iomem *board_ctrl;
2508
2509 zfw_ctrl = cinfo->base_addr + (cy_readl (&firm_id->zfwctrl_addr) & 0xfffff);
2510 2530
2511 board_ctrl = &zfw_ctrl->board_ctrl; 2531 line = tty->index;
2532 if ((line < 0) || (NR_PORTS <= line)) {
2533 return -ENODEV;
2534 }
2535 info = &cy_port[line];
2536 if (info->line < 0) {
2537 return -ENODEV;
2538 }
2512 2539
2513 /* Enable interrupts on the PLX chip */ 2540 /* If the card's firmware hasn't been loaded,
2514 cy_writew(cinfo->ctl_addr+0x68, 2541 treat it as absent from the system. This
2515 cy_readw(cinfo->ctl_addr+0x68)|0x0900); 2542 will make the user pay attention.
2516 /* Enable interrupts on the FW */ 2543 */
2517 retval = cyz_issue_cmd(cinfo, 2544 if (IS_CYC_Z(cy_card[info->card])) {
2518 0, C_CM_IRQ_ENBL, 0L); 2545 struct cyclades_card *cinfo = &cy_card[info->card];
2519 if (retval != 0){ 2546 struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS;
2520 printk("cyc:IRQ enable retval was %x\n", retval); 2547
2548 if (!ISZLOADED(*cinfo)) {
2549 if (((ZE_V1 == cy_readl(
2550 &((struct RUNTIME_9060 __iomem *)
2551 (cinfo->ctl_addr))->mail_box_0)) &&
2552 Z_FPGA_CHECK(*cinfo)) &&
2553 (ZFIRM_HLT == cy_readl(
2554 &firm_id->signature))) {
2555 printk("cyc:Cyclades-Z Error: you need an "
2556 "external power supply for this number "
2557 "of ports.\n\rFirmware halted.\r\n");
2558 } else {
2559 printk("cyc:Cyclades-Z firmware not yet "
2560 "loaded\n");
2561 }
2562 return -ENODEV;
2563 }
2564#ifdef CONFIG_CYZ_INTR
2565 else {
2566 /* In case this Z board is operating in interrupt mode, its
2567 interrupts should be enabled as soon as the first open
2568 happens to one of its ports. */
2569 if (!cinfo->intr_enabled) {
2570 struct ZFW_CTRL __iomem *zfw_ctrl;
2571 struct BOARD_CTRL __iomem *board_ctrl;
2572
2573 zfw_ctrl = cinfo->base_addr +
2574 (cy_readl(&firm_id->zfwctrl_addr) &
2575 0xfffff);
2576
2577 board_ctrl = &zfw_ctrl->board_ctrl;
2578
2579 /* Enable interrupts on the PLX chip */
2580 cy_writew(cinfo->ctl_addr + 0x68,
2581 cy_readw(cinfo->ctl_addr +
2582 0x68) | 0x0900);
2583 /* Enable interrupts on the FW */
2584 retval = cyz_issue_cmd(cinfo, 0,
2585 C_CM_IRQ_ENBL, 0L);
2586 if (retval != 0) {
2587 printk("cyc:IRQ enable retval was %x\n",
2588 retval);
2589 }
2590 cinfo->nports =
2591 (int)cy_readl(&board_ctrl->n_channel);
2592 cinfo->intr_enabled = 1;
2593 }
2521 } 2594 }
2522 cinfo->nports = (int) cy_readl (&board_ctrl->n_channel); 2595#endif /* CONFIG_CYZ_INTR */
2523 cinfo->intr_enabled = 1; 2596 /* Make sure this Z port really exists in hardware */
2524 } 2597 if (info->line > (cinfo->first_line + cinfo->nports - 1))
2598 return -ENODEV;
2525 } 2599 }
2526#endif /* CONFIG_CYZ_INTR */
2527 /* Make sure this Z port really exists in hardware */
2528 if (info->line > (cinfo->first_line + cinfo->nports - 1))
2529 return -ENODEV;
2530 }
2531#ifdef CY_DEBUG_OTHER 2600#ifdef CY_DEBUG_OTHER
2532 printk("cyc:cy_open ttyC%d\n", info->line); /* */ 2601 printk("cyc:cy_open ttyC%d\n", info->line); /* */
2533#endif 2602#endif
2534 tty->driver_data = info; 2603 tty->driver_data = info;
2535 info->tty = tty; 2604 info->tty = tty;
2536 if (serial_paranoia_check(info, tty->name, "cy_open")){ 2605 if (serial_paranoia_check(info, tty->name, "cy_open")) {
2537 return -ENODEV; 2606 return -ENODEV;
2538 } 2607 }
2539#ifdef CY_DEBUG_OPEN 2608#ifdef CY_DEBUG_OPEN
2540 printk("cyc:cy_open ttyC%d, count = %d\n", 2609 printk("cyc:cy_open ttyC%d, count = %d\n", info->line, info->count);
2541 info->line, info->count);/**/ 2610 /**/
2542#endif 2611#endif
2543 info->count++; 2612 info->count++;
2544#ifdef CY_DEBUG_COUNT 2613#ifdef CY_DEBUG_COUNT
2545 printk("cyc:cy_open (%d): incrementing count to %d\n", 2614 printk("cyc:cy_open (%d): incrementing count to %d\n",
2546 current->pid, info->count); 2615 current->pid, info->count);
2547#endif 2616#endif
2548 if (!tmp_buf) {
2549 page = get_zeroed_page(GFP_KERNEL);
2550 if (!page)
2551 return -ENOMEM;
2552 if (tmp_buf)
2553 free_page(page);
2554 else
2555 tmp_buf = (unsigned char *) page;
2556 }
2557
2558 /*
2559 * If the port is the middle of closing, bail out now
2560 */
2561 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
2562 if (info->flags & ASYNC_CLOSING)
2563 interruptible_sleep_on(&info->close_wait);
2564 return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
2565 }
2566
2567 /*
2568 * Start up serial port
2569 */
2570 retval = startup(info);
2571 if (retval){
2572 return retval;
2573 }
2574
2575 retval = block_til_ready(tty, filp, info);
2576 if (retval) {
2577#ifdef CY_DEBUG_OPEN
2578 printk("cyc:cy_open returning after block_til_ready with %d\n",
2579 retval);
2580#endif
2581 return retval;
2582 }
2583 2617
2584 info->throttle = 0; 2618 /*
2619 * If the port is the middle of closing, bail out now
2620 */
2621 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
2622 if (info->flags & ASYNC_CLOSING)
2623 interruptible_sleep_on(&info->close_wait);
2624 return (info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
2625 }
2626
2627 /*
2628 * Start up serial port
2629 */
2630 retval = startup(info);
2631 if (retval) {
2632 return retval;
2633 }
2585 2634
2635 retval = block_til_ready(tty, filp, info);
2636 if (retval) {
2586#ifdef CY_DEBUG_OPEN 2637#ifdef CY_DEBUG_OPEN
2587 printk(" cyc:cy_open done\n");/**/ 2638 printk("cyc:cy_open returning after block_til_ready with %d\n",
2639 retval);
2588#endif 2640#endif
2641 return retval;
2642 }
2589 2643
2590 return 0; 2644 info->throttle = 0;
2591} /* cy_open */
2592 2645
2646#ifdef CY_DEBUG_OPEN
2647 printk(" cyc:cy_open done\n");
2648 /**/
2649#endif
2650 return 0;
2651} /* cy_open */
2593 2652
2594/* 2653/*
2595 * cy_wait_until_sent() --- wait until the transmitter is empty 2654 * cy_wait_until_sent() --- wait until the transmitter is empty
2596 */ 2655 */
2597static void 2656static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
2598cy_wait_until_sent(struct tty_struct *tty, int timeout)
2599{ 2657{
2600 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 2658 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2601 void __iomem *base_addr; 2659 void __iomem *base_addr;
2602 int card,chip,channel,index; 2660 int card, chip, channel, index;
2603 unsigned long orig_jiffies; 2661 unsigned long orig_jiffies;
2604 int char_time; 2662 int char_time;
2605 2663
2606 if (serial_paranoia_check(info, tty->name, "cy_wait_until_sent")) 2664 if (serial_paranoia_check(info, tty->name, "cy_wait_until_sent"))
2607 return; 2665 return;
2608 2666
2609 if (info->xmit_fifo_size == 0) 2667 if (info->xmit_fifo_size == 0)
2610 return; /* Just in case.... */ 2668 return; /* Just in case.... */
2611 2669
2612 2670 orig_jiffies = jiffies;
2613 orig_jiffies = jiffies; 2671 /*
2614 /* 2672 * Set the check interval to be 1/5 of the estimated time to
2615 * Set the check interval to be 1/5 of the estimated time to 2673 * send a single character, and make it at least 1. The check
2616 * send a single character, and make it at least 1. The check 2674 * interval should also be less than the timeout.
2617 * interval should also be less than the timeout. 2675 *
2618 * 2676 * Note: we have to use pretty tight timings here to satisfy
2619 * Note: we have to use pretty tight timings here to satisfy 2677 * the NIST-PCTS.
2620 * the NIST-PCTS. 2678 */
2621 */ 2679 char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
2622 char_time = (info->timeout - HZ/50) / info->xmit_fifo_size; 2680 char_time = char_time / 5;
2623 char_time = char_time / 5; 2681 if (char_time <= 0)
2624 if (char_time <= 0) 2682 char_time = 1;
2625 char_time = 1; 2683 if (timeout < 0)
2626 if (timeout < 0) 2684 timeout = 0;
2627 timeout = 0; 2685 if (timeout)
2628 if (timeout) 2686 char_time = min(char_time, timeout);
2629 char_time = min(char_time, timeout); 2687 /*
2630 /* 2688 * If the transmitter hasn't cleared in twice the approximate
2631 * If the transmitter hasn't cleared in twice the approximate 2689 * amount of time to send the entire FIFO, it probably won't
2632 * amount of time to send the entire FIFO, it probably won't 2690 * ever clear. This assumes the UART isn't doing flow
2633 * ever clear. This assumes the UART isn't doing flow 2691 * control, which is currently the case. Hence, if it ever
2634 * control, which is currently the case. Hence, if it ever 2692 * takes longer than info->timeout, this is probably due to a
2635 * takes longer than info->timeout, this is probably due to a 2693 * UART bug of some kind. So, we clamp the timeout parameter at
2636 * UART bug of some kind. So, we clamp the timeout parameter at 2694 * 2*info->timeout.
2637 * 2*info->timeout. 2695 */
2638 */ 2696 if (!timeout || timeout > 2 * info->timeout)
2639 if (!timeout || timeout > 2*info->timeout) 2697 timeout = 2 * info->timeout;
2640 timeout = 2*info->timeout;
2641#ifdef CY_DEBUG_WAIT_UNTIL_SENT 2698#ifdef CY_DEBUG_WAIT_UNTIL_SENT
2642 printk("In cy_wait_until_sent(%d) check=%lu...", timeout, char_time); 2699 printk("In cy_wait_until_sent(%d) check=%lu...", timeout, char_time);
2643 printk("jiff=%lu...", jiffies); 2700 printk("jiff=%lu...", jiffies);
2644#endif 2701#endif
2645 card = info->card; 2702 card = info->card;
2646 channel = (info->line) - (cy_card[card].first_line); 2703 channel = (info->line) - (cy_card[card].first_line);
2647 if (!IS_CYC_Z(cy_card[card])) { 2704 if (!IS_CYC_Z(cy_card[card])) {
2648 chip = channel>>2; 2705 chip = channel >> 2;
2649 channel &= 0x03; 2706 channel &= 0x03;
2650 index = cy_card[card].bus_index; 2707 index = cy_card[card].bus_index;
2651 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index); 2708 base_addr =
2652 while (cy_readb(base_addr+(CySRER<<index)) & CyTxRdy) { 2709 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
2710 while (cy_readb(base_addr + (CySRER << index)) & CyTxRdy) {
2653#ifdef CY_DEBUG_WAIT_UNTIL_SENT 2711#ifdef CY_DEBUG_WAIT_UNTIL_SENT
2654 printk("Not clean (jiff=%lu)...", jiffies); 2712 printk("Not clean (jiff=%lu)...", jiffies);
2655#endif 2713#endif
2656 if (msleep_interruptible(jiffies_to_msecs(char_time))) 2714 if (msleep_interruptible(jiffies_to_msecs(char_time)))
2657 break; 2715 break;
2658 if (timeout && time_after(jiffies, orig_jiffies + timeout)) 2716 if (timeout && time_after(jiffies, orig_jiffies +
2659 break; 2717 timeout))
2718 break;
2719 }
2720 } else {
2721 /* Nothing to do! */
2660 } 2722 }
2661 } else { 2723 /* Run one more char cycle */
2662 // Nothing to do! 2724 msleep_interruptible(jiffies_to_msecs(char_time * 5));
2663 }
2664 /* Run one more char cycle */
2665 msleep_interruptible(jiffies_to_msecs(char_time * 5));
2666#ifdef CY_DEBUG_WAIT_UNTIL_SENT 2725#ifdef CY_DEBUG_WAIT_UNTIL_SENT
2667 printk("Clean (jiff=%lu)...done\n", jiffies); 2726 printk("Clean (jiff=%lu)...done\n", jiffies);
2668#endif 2727#endif
2669} 2728}
2670 2729
2671/* 2730/*
2672 * This routine is called when a particular tty device is closed. 2731 * This routine is called when a particular tty device is closed.
2673 */ 2732 */
2674static void 2733static void cy_close(struct tty_struct *tty, struct file *filp)
2675cy_close(struct tty_struct *tty, struct file *filp)
2676{ 2734{
2677 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2735 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2678 unsigned long flags; 2736 unsigned long flags;
2679 2737
2680#ifdef CY_DEBUG_OTHER 2738#ifdef CY_DEBUG_OTHER
2681 printk("cyc:cy_close ttyC%d\n", info->line); 2739 printk("cyc:cy_close ttyC%d\n", info->line);
2682#endif 2740#endif
2683 2741
2684 if (!info || serial_paranoia_check(info, tty->name, "cy_close")){ 2742 if (!info || serial_paranoia_check(info, tty->name, "cy_close")) {
2685 return; 2743 return;
2686 } 2744 }
2687 2745
2688 CY_LOCK(info, flags); 2746 CY_LOCK(info, flags);
2689 /* If the TTY is being hung up, nothing to do */ 2747 /* If the TTY is being hung up, nothing to do */
2690 if (tty_hung_up_p(filp)) { 2748 if (tty_hung_up_p(filp)) {
2691 CY_UNLOCK(info, flags); 2749 CY_UNLOCK(info, flags);
2692 return; 2750 return;
2693 } 2751 }
2694
2695#ifdef CY_DEBUG_OPEN 2752#ifdef CY_DEBUG_OPEN
2696 printk("cyc:cy_close ttyC%d, count = %d\n", info->line, info->count); 2753 printk("cyc:cy_close ttyC%d, count = %d\n", info->line, info->count);
2697#endif 2754#endif
2698 if ((tty->count == 1) && (info->count != 1)) { 2755 if ((tty->count == 1) && (info->count != 1)) {
2699 /* 2756 /*
2700 * Uh, oh. tty->count is 1, which means that the tty 2757 * Uh, oh. tty->count is 1, which means that the tty
2701 * structure will be freed. Info->count should always 2758 * structure will be freed. Info->count should always
2702 * be one in these conditions. If it's greater than 2759 * be one in these conditions. If it's greater than
2703 * one, we've got real problems, since it means the 2760 * one, we've got real problems, since it means the
2704 * serial port won't be shutdown. 2761 * serial port won't be shutdown.
2705 */ 2762 */
2706 printk("cyc:cy_close: bad serial port count; tty->count is 1, " 2763 printk("cyc:cy_close: bad serial port count; tty->count is 1, "
2707 "info->count is %d\n", info->count); 2764 "info->count is %d\n", info->count);
2708 info->count = 1; 2765 info->count = 1;
2709 } 2766 }
2710#ifdef CY_DEBUG_COUNT 2767#ifdef CY_DEBUG_COUNT
2711 printk("cyc:cy_close at (%d): decrementing count to %d\n", 2768 printk("cyc:cy_close at (%d): decrementing count to %d\n",
2712 current->pid, info->count - 1); 2769 current->pid, info->count - 1);
2713#endif 2770#endif
2714 if (--info->count < 0) { 2771 if (--info->count < 0) {
2715#ifdef CY_DEBUG_COUNT 2772#ifdef CY_DEBUG_COUNT
2716 printk("cyc:cyc_close setting count to 0\n"); 2773 printk("cyc:cyc_close setting count to 0\n");
2717#endif 2774#endif
2718 info->count = 0; 2775 info->count = 0;
2719 }
2720 if (info->count) {
2721 CY_UNLOCK(info, flags);
2722 return;
2723 }
2724 info->flags |= ASYNC_CLOSING;
2725
2726 /*
2727 * Now we wait for the transmit buffer to clear; and we notify
2728 * the line discipline to only process XON/XOFF characters.
2729 */
2730 tty->closing = 1;
2731 CY_UNLOCK(info, flags);
2732 if (info->closing_wait != CY_CLOSING_WAIT_NONE) {
2733 tty_wait_until_sent(tty, info->closing_wait);
2734 }
2735 CY_LOCK(info, flags);
2736
2737 if (!IS_CYC_Z(cy_card[info->card])) {
2738 int channel = info->line - cy_card[info->card].first_line;
2739 int index = cy_card[info->card].bus_index;
2740 void __iomem *base_addr = cy_card[info->card].base_addr + (cy_chip_offset[channel>>2] << index);
2741 /* Stop accepting input */
2742 channel &= 0x03;
2743 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
2744 cy_writeb(base_addr+(CySRER<<index),
2745 cy_readb(base_addr+(CySRER<<index)) & ~CyRxData);
2746 if (info->flags & ASYNC_INITIALIZED) {
2747 /* Waiting for on-board buffers to be empty before closing
2748 the port */
2749 CY_UNLOCK(info, flags);
2750 cy_wait_until_sent(tty, info->timeout);
2751 CY_LOCK(info, flags);
2752 } 2776 }
2753 } else { 2777 if (info->count) {
2754#ifdef Z_WAKE 2778 CY_UNLOCK(info, flags);
2755 /* Waiting for on-board buffers to be empty before closing the port */ 2779 return;
2756 void __iomem *base_addr = cy_card[info->card].base_addr; 2780 }
2757 struct FIRM_ID __iomem *firm_id = base_addr + ID_ADDRESS; 2781 info->flags |= ASYNC_CLOSING;
2758 struct ZFW_CTRL __iomem *zfw_ctrl = base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2759 struct CH_CTRL __iomem *ch_ctrl = zfw_ctrl->ch_ctrl;
2760 int channel = info->line - cy_card[info->card].first_line;
2761 int retval;
2762 2782
2763 if (cy_readl(&ch_ctrl[channel].flow_status) != C_FS_TXIDLE) { 2783 /*
2764 retval = cyz_issue_cmd(&cy_card[info->card], channel, 2784 * Now we wait for the transmit buffer to clear; and we notify
2765 C_CM_IOCTLW, 0L); 2785 * the line discipline to only process XON/XOFF characters.
2766 if (retval != 0){ 2786 */
2767 printk("cyc:cy_close retval on ttyC%d was %x\n", 2787 tty->closing = 1;
2768 info->line, retval); 2788 CY_UNLOCK(info, flags);
2769 } 2789 if (info->closing_wait != CY_CLOSING_WAIT_NONE) {
2770 CY_UNLOCK(info, flags); 2790 tty_wait_until_sent(tty, info->closing_wait);
2771 interruptible_sleep_on(&info->shutdown_wait);
2772 CY_LOCK(info, flags);
2773 } 2791 }
2792 CY_LOCK(info, flags);
2793
2794 if (!IS_CYC_Z(cy_card[info->card])) {
2795 int channel = info->line - cy_card[info->card].first_line;
2796 int index = cy_card[info->card].bus_index;
2797 void __iomem *base_addr = cy_card[info->card].base_addr +
2798 (cy_chip_offset[channel >> 2] << index);
2799 /* Stop accepting input */
2800 channel &= 0x03;
2801 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
2802 cy_writeb(base_addr + (CySRER << index),
2803 cy_readb(base_addr + (CySRER << index)) & ~CyRxData);
2804 if (info->flags & ASYNC_INITIALIZED) {
2805 /* Waiting for on-board buffers to be empty before closing
2806 the port */
2807 CY_UNLOCK(info, flags);
2808 cy_wait_until_sent(tty, info->timeout);
2809 CY_LOCK(info, flags);
2810 }
2811 } else {
2812#ifdef Z_WAKE
2813 /* Waiting for on-board buffers to be empty before closing the port */
2814 void __iomem *base_addr = cy_card[info->card].base_addr;
2815 struct FIRM_ID __iomem *firm_id = base_addr + ID_ADDRESS;
2816 struct ZFW_CTRL __iomem *zfw_ctrl =
2817 base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2818 struct CH_CTRL __iomem *ch_ctrl = zfw_ctrl->ch_ctrl;
2819 int channel = info->line - cy_card[info->card].first_line;
2820 int retval;
2821
2822 if (cy_readl(&ch_ctrl[channel].flow_status) != C_FS_TXIDLE) {
2823 retval = cyz_issue_cmd(&cy_card[info->card], channel,
2824 C_CM_IOCTLW, 0L);
2825 if (retval != 0) {
2826 printk("cyc:cy_close retval on ttyC%d was %x\n",
2827 info->line, retval);
2828 }
2829 CY_UNLOCK(info, flags);
2830 interruptible_sleep_on(&info->shutdown_wait);
2831 CY_LOCK(info, flags);
2832 }
2774#endif 2833#endif
2775 } 2834 }
2776 2835
2777 CY_UNLOCK(info, flags);
2778 shutdown(info);
2779 if (tty->driver->flush_buffer)
2780 tty->driver->flush_buffer(tty);
2781 tty_ldisc_flush(tty);
2782 CY_LOCK(info, flags);
2783
2784 tty->closing = 0;
2785 info->event = 0;
2786 info->tty = NULL;
2787 if (info->blocked_open) {
2788 CY_UNLOCK(info, flags); 2836 CY_UNLOCK(info, flags);
2789 if (info->close_delay) { 2837 shutdown(info);
2790 msleep_interruptible(jiffies_to_msecs(info->close_delay)); 2838 if (tty->driver->flush_buffer)
2791 } 2839 tty->driver->flush_buffer(tty);
2792 wake_up_interruptible(&info->open_wait); 2840 tty_ldisc_flush(tty);
2793 CY_LOCK(info, flags); 2841 CY_LOCK(info, flags);
2794 } 2842
2795 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 2843 tty->closing = 0;
2796 wake_up_interruptible(&info->close_wait); 2844 info->event = 0;
2845 info->tty = NULL;
2846 if (info->blocked_open) {
2847 CY_UNLOCK(info, flags);
2848 if (info->close_delay) {
2849 msleep_interruptible(jiffies_to_msecs
2850 (info->close_delay));
2851 }
2852 wake_up_interruptible(&info->open_wait);
2853 CY_LOCK(info, flags);
2854 }
2855 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
2856 wake_up_interruptible(&info->close_wait);
2797 2857
2798#ifdef CY_DEBUG_OTHER 2858#ifdef CY_DEBUG_OTHER
2799 printk(" cyc:cy_close done\n"); 2859 printk(" cyc:cy_close done\n");
2800#endif 2860#endif
2801 2861
2802 CY_UNLOCK(info, flags); 2862 CY_UNLOCK(info, flags);
2803 return; 2863} /* cy_close */
2804} /* cy_close */
2805
2806 2864
2807/* This routine gets called when tty_write has put something into 2865/* This routine gets called when tty_write has put something into
2808 * the write_queue. The characters may come from user space or 2866 * the write_queue. The characters may come from user space or
@@ -2817,50 +2875,49 @@ cy_close(struct tty_struct *tty, struct file *filp)
2817 * If the port is already active, there is no need to kick it. 2875 * If the port is already active, there is no need to kick it.
2818 * 2876 *
2819 */ 2877 */
2820static int 2878static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
2821cy_write(struct tty_struct * tty, const unsigned char *buf, int count)
2822{ 2879{
2823 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2880 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2824 unsigned long flags; 2881 unsigned long flags;
2825 int c, ret = 0; 2882 int c, ret = 0;
2826 2883
2827#ifdef CY_DEBUG_IO 2884#ifdef CY_DEBUG_IO
2828 printk("cyc:cy_write ttyC%d\n", info->line); /* */ 2885 printk("cyc:cy_write ttyC%d\n", info->line); /* */
2829#endif 2886#endif
2830 2887
2831 if (serial_paranoia_check(info, tty->name, "cy_write")){ 2888 if (serial_paranoia_check(info, tty->name, "cy_write")) {
2832 return 0; 2889 return 0;
2833 } 2890 }
2834 2891
2835 if (!info->xmit_buf || !tmp_buf) 2892 if (!info->xmit_buf)
2836 return 0; 2893 return 0;
2837 2894
2838 CY_LOCK(info, flags); 2895 CY_LOCK(info, flags);
2839 while (1) { 2896 while (1) {
2840 c = min(count, min((int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1), 2897 c = min(count, min((int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1),
2841 (int)(SERIAL_XMIT_SIZE - info->xmit_head))); 2898 (int)(SERIAL_XMIT_SIZE - info->xmit_head)));
2842
2843 if (c <= 0)
2844 break;
2845
2846 memcpy(info->xmit_buf + info->xmit_head, buf, c);
2847 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
2848 info->xmit_cnt += c;
2849 buf += c;
2850 count -= c;
2851 ret += c;
2852 }
2853 CY_UNLOCK(info, flags);
2854
2855 info->idle_stats.xmit_bytes += ret;
2856 info->idle_stats.xmit_idle = jiffies;
2857
2858 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
2859 start_xmit(info);
2860 }
2861 return ret;
2862} /* cy_write */
2863 2899
2900 if (c <= 0)
2901 break;
2902
2903 memcpy(info->xmit_buf + info->xmit_head, buf, c);
2904 info->xmit_head = (info->xmit_head + c) &
2905 (SERIAL_XMIT_SIZE - 1);
2906 info->xmit_cnt += c;
2907 buf += c;
2908 count -= c;
2909 ret += c;
2910 }
2911 CY_UNLOCK(info, flags);
2912
2913 info->idle_stats.xmit_bytes += ret;
2914 info->idle_stats.xmit_idle = jiffies;
2915
2916 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
2917 start_xmit(info);
2918 }
2919 return ret;
2920} /* cy_write */
2864 2921
2865/* 2922/*
2866 * This routine is called by the kernel to write a single 2923 * This routine is called by the kernel to write a single
@@ -2869,60 +2926,56 @@ cy_write(struct tty_struct * tty, const unsigned char *buf, int count)
2869 * done stuffing characters into the driver. If there is no room 2926 * done stuffing characters into the driver. If there is no room
2870 * in the queue, the character is ignored. 2927 * in the queue, the character is ignored.
2871 */ 2928 */
2872static void 2929static void cy_put_char(struct tty_struct *tty, unsigned char ch)
2873cy_put_char(struct tty_struct *tty, unsigned char ch)
2874{ 2930{
2875 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2931 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2876 unsigned long flags; 2932 unsigned long flags;
2877 2933
2878#ifdef CY_DEBUG_IO 2934#ifdef CY_DEBUG_IO
2879 printk("cyc:cy_put_char ttyC%d\n", info->line); 2935 printk("cyc:cy_put_char ttyC%d\n", info->line);
2880#endif 2936#endif
2881 2937
2882 if (serial_paranoia_check(info, tty->name, "cy_put_char")) 2938 if (serial_paranoia_check(info, tty->name, "cy_put_char"))
2883 return; 2939 return;
2884 2940
2885 if (!info->xmit_buf) 2941 if (!info->xmit_buf)
2886 return; 2942 return;
2887 2943
2888 CY_LOCK(info, flags); 2944 CY_LOCK(info, flags);
2889 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1) { 2945 if (info->xmit_cnt >= (int)(SERIAL_XMIT_SIZE - 1)) {
2890 CY_UNLOCK(info, flags); 2946 CY_UNLOCK(info, flags);
2891 return; 2947 return;
2892 } 2948 }
2893 2949
2894 info->xmit_buf[info->xmit_head++] = ch; 2950 info->xmit_buf[info->xmit_head++] = ch;
2895 info->xmit_head &= SERIAL_XMIT_SIZE - 1; 2951 info->xmit_head &= SERIAL_XMIT_SIZE - 1;
2896 info->xmit_cnt++; 2952 info->xmit_cnt++;
2897 info->idle_stats.xmit_bytes++; 2953 info->idle_stats.xmit_bytes++;
2898 info->idle_stats.xmit_idle = jiffies; 2954 info->idle_stats.xmit_idle = jiffies;
2899 CY_UNLOCK(info, flags); 2955 CY_UNLOCK(info, flags);
2900} /* cy_put_char */ 2956} /* cy_put_char */
2901
2902 2957
2903/* 2958/*
2904 * This routine is called by the kernel after it has written a 2959 * This routine is called by the kernel after it has written a
2905 * series of characters to the tty device using put_char(). 2960 * series of characters to the tty device using put_char().
2906 */ 2961 */
2907static void 2962static void cy_flush_chars(struct tty_struct *tty)
2908cy_flush_chars(struct tty_struct *tty)
2909{ 2963{
2910 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2964 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2911 2965
2912#ifdef CY_DEBUG_IO 2966#ifdef CY_DEBUG_IO
2913 printk("cyc:cy_flush_chars ttyC%d\n", info->line); /* */ 2967 printk("cyc:cy_flush_chars ttyC%d\n", info->line); /* */
2914#endif 2968#endif
2915 2969
2916 if (serial_paranoia_check(info, tty->name, "cy_flush_chars")) 2970 if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
2917 return; 2971 return;
2918
2919 if (info->xmit_cnt <= 0 || tty->stopped
2920 || tty->hw_stopped || !info->xmit_buf)
2921 return;
2922 2972
2923 start_xmit(info); 2973 if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
2924} /* cy_flush_chars */ 2974 !info->xmit_buf)
2975 return;
2925 2976
2977 start_xmit(info);
2978} /* cy_flush_chars */
2926 2979
2927/* 2980/*
2928 * This routine returns the numbers of characters the tty driver 2981 * This routine returns the numbers of characters the tty driver
@@ -2930,75 +2983,70 @@ cy_flush_chars(struct tty_struct *tty)
2930 * to change as output buffers get emptied, or if the output flow 2983 * to change as output buffers get emptied, or if the output flow
2931 * control is activated. 2984 * control is activated.
2932 */ 2985 */
2933static int 2986static int cy_write_room(struct tty_struct *tty)
2934cy_write_room(struct tty_struct *tty)
2935{ 2987{
2936 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2988 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2937 int ret; 2989 int ret;
2938 2990
2939#ifdef CY_DEBUG_IO 2991#ifdef CY_DEBUG_IO
2940 printk("cyc:cy_write_room ttyC%d\n", info->line); /* */ 2992 printk("cyc:cy_write_room ttyC%d\n", info->line); /* */
2941#endif 2993#endif
2942 2994
2943 if (serial_paranoia_check(info, tty->name, "cy_write_room")) 2995 if (serial_paranoia_check(info, tty->name, "cy_write_room"))
2944 return 0; 2996 return 0;
2945 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1; 2997 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
2946 if (ret < 0) 2998 if (ret < 0)
2947 ret = 0; 2999 ret = 0;
2948 return ret; 3000 return ret;
2949} /* cy_write_room */ 3001} /* cy_write_room */
2950 3002
2951 3003static int cy_chars_in_buffer(struct tty_struct *tty)
2952static int
2953cy_chars_in_buffer(struct tty_struct *tty)
2954{ 3004{
2955 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 3005 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2956 int card, channel; 3006 int card, channel;
2957 3007
2958 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer")) 3008 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
2959 return 0; 3009 return 0;
2960 3010
2961 card = info->card; 3011 card = info->card;
2962 channel = (info->line) - (cy_card[card].first_line); 3012 channel = (info->line) - (cy_card[card].first_line);
2963 3013
2964#ifdef Z_EXT_CHARS_IN_BUFFER 3014#ifdef Z_EXT_CHARS_IN_BUFFER
2965 if (!IS_CYC_Z(cy_card[card])) { 3015 if (!IS_CYC_Z(cy_card[card])) {
2966#endif /* Z_EXT_CHARS_IN_BUFFER */ 3016#endif /* Z_EXT_CHARS_IN_BUFFER */
2967#ifdef CY_DEBUG_IO 3017#ifdef CY_DEBUG_IO
2968 printk("cyc:cy_chars_in_buffer ttyC%d %d\n", 3018 printk("cyc:cy_chars_in_buffer ttyC%d %d\n", info->line, info->xmit_cnt); /* */
2969 info->line, info->xmit_cnt); /* */
2970#endif 3019#endif
2971 return info->xmit_cnt; 3020 return info->xmit_cnt;
2972#ifdef Z_EXT_CHARS_IN_BUFFER 3021#ifdef Z_EXT_CHARS_IN_BUFFER
2973 } else { 3022 } else {
2974 static volatile struct FIRM_ID *firm_id; 3023 static volatile struct FIRM_ID *firm_id;
2975 static volatile struct ZFW_CTRL *zfw_ctrl; 3024 static volatile struct ZFW_CTRL *zfw_ctrl;
2976 static volatile struct CH_CTRL *ch_ctrl; 3025 static volatile struct CH_CTRL *ch_ctrl;
2977 static volatile struct BUF_CTRL *buf_ctrl; 3026 static volatile struct BUF_CTRL *buf_ctrl;
2978 int char_count; 3027 int char_count;
2979 volatile uclong tx_put, tx_get, tx_bufsize; 3028 volatile uclong tx_put, tx_get, tx_bufsize;
2980 3029
2981 firm_id = cy_card[card].base_addr + ID_ADDRESS; 3030 firm_id = cy_card[card].base_addr + ID_ADDRESS;
2982 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 3031 zfw_ctrl = cy_card[card].base_addr +
2983 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]); 3032 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2984 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]); 3033 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
2985 3034 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
2986 tx_get = cy_readl(&buf_ctrl->tx_get); 3035
2987 tx_put = cy_readl(&buf_ctrl->tx_put); 3036 tx_get = cy_readl(&buf_ctrl->tx_get);
2988 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize); 3037 tx_put = cy_readl(&buf_ctrl->tx_put);
2989 if (tx_put >= tx_get) 3038 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize);
2990 char_count = tx_put - tx_get; 3039 if (tx_put >= tx_get)
2991 else 3040 char_count = tx_put - tx_get;
2992 char_count = tx_put - tx_get + tx_bufsize; 3041 else
3042 char_count = tx_put - tx_get + tx_bufsize;
2993#ifdef CY_DEBUG_IO 3043#ifdef CY_DEBUG_IO
2994 printk("cyc:cy_chars_in_buffer ttyC%d %d\n", 3044 printk("cyc:cy_chars_in_buffer ttyC%d %d\n", info->line, info->xmit_cnt + char_count); /* */
2995 info->line, info->xmit_cnt + char_count); /* */
2996#endif 3045#endif
2997 return (info->xmit_cnt + char_count); 3046 return info->xmit_cnt + char_count;
2998 } 3047 }
2999#endif /* Z_EXT_CHARS_IN_BUFFER */ 3048#endif /* Z_EXT_CHARS_IN_BUFFER */
3000} /* cy_chars_in_buffer */ 3049} /* cy_chars_in_buffer */
3001
3002 3050
3003/* 3051/*
3004 * ------------------------------------------------------------ 3052 * ------------------------------------------------------------
@@ -3006,178 +3054,179 @@ cy_chars_in_buffer(struct tty_struct *tty)
3006 * ------------------------------------------------------------ 3054 * ------------------------------------------------------------
3007 */ 3055 */
3008 3056
3009static void 3057static void cyy_baud_calc(struct cyclades_port *info, uclong baud)
3010cyy_baud_calc(struct cyclades_port *info, uclong baud)
3011{ 3058{
3012 int co, co_val, bpr; 3059 int co, co_val, bpr;
3013 uclong cy_clock = ((info->chip_rev >= CD1400_REV_J) ? 60000000 : 25000000); 3060 uclong cy_clock = ((info->chip_rev >= CD1400_REV_J) ? 60000000 :
3014 3061 25000000);
3015 if (baud == 0) { 3062
3016 info->tbpr = info->tco = info->rbpr = info->rco = 0; 3063 if (baud == 0) {
3017 return; 3064 info->tbpr = info->tco = info->rbpr = info->rco = 0;
3018 } 3065 return;
3019 3066 }
3020 /* determine which prescaler to use */ 3067
3021 for (co = 4, co_val = 2048; co; co--, co_val >>= 2) { 3068 /* determine which prescaler to use */
3022 if (cy_clock / co_val / baud > 63) 3069 for (co = 4, co_val = 2048; co; co--, co_val >>= 2) {
3023 break; 3070 if (cy_clock / co_val / baud > 63)
3024 } 3071 break;
3025 3072 }
3026 bpr = (cy_clock / co_val * 2 / baud + 1) / 2; 3073
3027 if (bpr > 255) 3074 bpr = (cy_clock / co_val * 2 / baud + 1) / 2;
3028 bpr = 255; 3075 if (bpr > 255)
3029 3076 bpr = 255;
3030 info->tbpr = info->rbpr = bpr; 3077
3031 info->tco = info->rco = co; 3078 info->tbpr = info->rbpr = bpr;
3079 info->tco = info->rco = co;
3032} 3080}
3033 3081
3034/* 3082/*
3035 * This routine finds or computes the various line characteristics. 3083 * This routine finds or computes the various line characteristics.
3036 * It used to be called config_setup 3084 * It used to be called config_setup
3037 */ 3085 */
3038static void 3086static void set_line_char(struct cyclades_port *info)
3039set_line_char(struct cyclades_port * info)
3040{ 3087{
3041 unsigned long flags; 3088 unsigned long flags;
3042 void __iomem *base_addr; 3089 void __iomem *base_addr;
3043 int card,chip,channel,index; 3090 int card, chip, channel, index;
3044 unsigned cflag, iflag; 3091 unsigned cflag, iflag;
3045 unsigned short chip_number; 3092 unsigned short chip_number;
3046 int baud, baud_rate = 0; 3093 int baud, baud_rate = 0;
3047 int i; 3094 int i;
3048 3095
3049 3096 if (!info->tty || !info->tty->termios) {
3050 if (!info->tty || !info->tty->termios){ 3097 return;
3051 return;
3052 }
3053 if (info->line == -1){
3054 return;
3055 }
3056 cflag = info->tty->termios->c_cflag;
3057 iflag = info->tty->termios->c_iflag;
3058
3059 /*
3060 * Set up the tty->alt_speed kludge
3061 */
3062 if (info->tty) {
3063 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3064 info->tty->alt_speed = 57600;
3065 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3066 info->tty->alt_speed = 115200;
3067 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3068 info->tty->alt_speed = 230400;
3069 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3070 info->tty->alt_speed = 460800;
3071 }
3072
3073 card = info->card;
3074 channel = (info->line) - (cy_card[card].first_line);
3075 chip_number = channel / 4;
3076
3077 if (!IS_CYC_Z(cy_card[card])) {
3078
3079 index = cy_card[card].bus_index;
3080
3081 /* baud rate */
3082 baud = tty_get_baud_rate(info->tty);
3083 if ((baud == 38400) &&
3084 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
3085 if (info->custom_divisor)
3086 baud_rate = info->baud / info->custom_divisor;
3087 else
3088 baud_rate = info->baud;
3089 } else if (baud > CD1400_MAX_SPEED) {
3090 baud = CD1400_MAX_SPEED;
3091 } 3098 }
3092 /* find the baud index */ 3099 if (info->line == -1) {
3093 for (i = 0; i < 20; i++) { 3100 return;
3094 if (baud == baud_table[i]) {
3095 break;
3096 }
3097 } 3101 }
3098 if (i == 20) { 3102 cflag = info->tty->termios->c_cflag;
3099 i = 19; /* CD1400_MAX_SPEED */ 3103 iflag = info->tty->termios->c_iflag;
3100 }
3101 3104
3102 if ((baud == 38400) && 3105 /*
3103 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) { 3106 * Set up the tty->alt_speed kludge
3104 cyy_baud_calc(info, baud_rate); 3107 */
3105 } else { 3108 if (info->tty) {
3106 if(info->chip_rev >= CD1400_REV_J) { 3109 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3107 /* It is a CD1400 rev. J or later */ 3110 info->tty->alt_speed = 57600;
3108 info->tbpr = baud_bpr_60[i]; /* Tx BPR */ 3111 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3109 info->tco = baud_co_60[i]; /* Tx CO */ 3112 info->tty->alt_speed = 115200;
3110 info->rbpr = baud_bpr_60[i]; /* Rx BPR */ 3113 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3111 info->rco = baud_co_60[i]; /* Rx CO */ 3114 info->tty->alt_speed = 230400;
3112 } else { 3115 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3113 info->tbpr = baud_bpr_25[i]; /* Tx BPR */ 3116 info->tty->alt_speed = 460800;
3114 info->tco = baud_co_25[i]; /* Tx CO */
3115 info->rbpr = baud_bpr_25[i]; /* Rx BPR */
3116 info->rco = baud_co_25[i]; /* Rx CO */
3117 }
3118 }
3119 if (baud_table[i] == 134) {
3120 /* get it right for 134.5 baud */
3121 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
3122 } else if ((baud == 38400) &&
3123 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
3124 info->timeout = (info->xmit_fifo_size*HZ*15/baud_rate) + 2;
3125 } else if (baud_table[i]) {
3126 info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2;
3127 /* this needs to be propagated into the card info */
3128 } else {
3129 info->timeout = 0;
3130 }
3131 /* By tradition (is it a standard?) a baud rate of zero
3132 implies the line should be/has been closed. A bit
3133 later in this routine such a test is performed. */
3134
3135 /* byte size and parity */
3136 info->cor5 = 0;
3137 info->cor4 = 0;
3138 info->cor3 = (info->default_threshold
3139 ? info->default_threshold
3140 : baud_cor3[i]); /* receive threshold */
3141 info->cor2 = CyETC;
3142 switch(cflag & CSIZE){
3143 case CS5:
3144 info->cor1 = Cy_5_BITS;
3145 break;
3146 case CS6:
3147 info->cor1 = Cy_6_BITS;
3148 break;
3149 case CS7:
3150 info->cor1 = Cy_7_BITS;
3151 break;
3152 case CS8:
3153 info->cor1 = Cy_8_BITS;
3154 break;
3155 }
3156 if(cflag & CSTOPB){
3157 info->cor1 |= Cy_2_STOP;
3158 }
3159 if (cflag & PARENB){
3160 if (cflag & PARODD){
3161 info->cor1 |= CyPARITY_O;
3162 }else{
3163 info->cor1 |= CyPARITY_E;
3164 }
3165 }else{
3166 info->cor1 |= CyPARITY_NONE;
3167 }
3168
3169 /* CTS flow control flag */
3170 if (cflag & CRTSCTS){
3171 info->flags |= ASYNC_CTS_FLOW;
3172 info->cor2 |= CyCtsAE;
3173 }else{
3174 info->flags &= ~ASYNC_CTS_FLOW;
3175 info->cor2 &= ~CyCtsAE;
3176 } 3117 }
3177 if (cflag & CLOCAL) 3118
3178 info->flags &= ~ASYNC_CHECK_CD; 3119 card = info->card;
3179 else 3120 channel = (info->line) - (cy_card[card].first_line);
3180 info->flags |= ASYNC_CHECK_CD; 3121 chip_number = channel / 4;
3122
3123 if (!IS_CYC_Z(cy_card[card])) {
3124
3125 index = cy_card[card].bus_index;
3126
3127 /* baud rate */
3128 baud = tty_get_baud_rate(info->tty);
3129 if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3130 ASYNC_SPD_CUST) {
3131 if (info->custom_divisor)
3132 baud_rate = info->baud / info->custom_divisor;
3133 else
3134 baud_rate = info->baud;
3135 } else if (baud > CD1400_MAX_SPEED) {
3136 baud = CD1400_MAX_SPEED;
3137 }
3138 /* find the baud index */
3139 for (i = 0; i < 20; i++) {
3140 if (baud == baud_table[i]) {
3141 break;
3142 }
3143 }
3144 if (i == 20) {
3145 i = 19; /* CD1400_MAX_SPEED */
3146 }
3147
3148 if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3149 ASYNC_SPD_CUST) {
3150 cyy_baud_calc(info, baud_rate);
3151 } else {
3152 if (info->chip_rev >= CD1400_REV_J) {
3153 /* It is a CD1400 rev. J or later */
3154 info->tbpr = baud_bpr_60[i]; /* Tx BPR */
3155 info->tco = baud_co_60[i]; /* Tx CO */
3156 info->rbpr = baud_bpr_60[i]; /* Rx BPR */
3157 info->rco = baud_co_60[i]; /* Rx CO */
3158 } else {
3159 info->tbpr = baud_bpr_25[i]; /* Tx BPR */
3160 info->tco = baud_co_25[i]; /* Tx CO */
3161 info->rbpr = baud_bpr_25[i]; /* Rx BPR */
3162 info->rco = baud_co_25[i]; /* Rx CO */
3163 }
3164 }
3165 if (baud_table[i] == 134) {
3166 /* get it right for 134.5 baud */
3167 info->timeout = (info->xmit_fifo_size * HZ * 30 / 269) +
3168 2;
3169 } else if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3170 ASYNC_SPD_CUST) {
3171 info->timeout = (info->xmit_fifo_size * HZ * 15 /
3172 baud_rate) + 2;
3173 } else if (baud_table[i]) {
3174 info->timeout = (info->xmit_fifo_size * HZ * 15 /
3175 baud_table[i]) + 2;
3176 /* this needs to be propagated into the card info */
3177 } else {
3178 info->timeout = 0;
3179 }
3180 /* By tradition (is it a standard?) a baud rate of zero
3181 implies the line should be/has been closed. A bit
3182 later in this routine such a test is performed. */
3183
3184 /* byte size and parity */
3185 info->cor5 = 0;
3186 info->cor4 = 0;
3187 /* receive threshold */
3188 info->cor3 = (info->default_threshold ?
3189 info->default_threshold : baud_cor3[i]);
3190 info->cor2 = CyETC;
3191 switch (cflag & CSIZE) {
3192 case CS5:
3193 info->cor1 = Cy_5_BITS;
3194 break;
3195 case CS6:
3196 info->cor1 = Cy_6_BITS;
3197 break;
3198 case CS7:
3199 info->cor1 = Cy_7_BITS;
3200 break;
3201 case CS8:
3202 info->cor1 = Cy_8_BITS;
3203 break;
3204 }
3205 if (cflag & CSTOPB) {
3206 info->cor1 |= Cy_2_STOP;
3207 }
3208 if (cflag & PARENB) {
3209 if (cflag & PARODD) {
3210 info->cor1 |= CyPARITY_O;
3211 } else {
3212 info->cor1 |= CyPARITY_E;
3213 }
3214 } else {
3215 info->cor1 |= CyPARITY_NONE;
3216 }
3217
3218 /* CTS flow control flag */
3219 if (cflag & CRTSCTS) {
3220 info->flags |= ASYNC_CTS_FLOW;
3221 info->cor2 |= CyCtsAE;
3222 } else {
3223 info->flags &= ~ASYNC_CTS_FLOW;
3224 info->cor2 &= ~CyCtsAE;
3225 }
3226 if (cflag & CLOCAL)
3227 info->flags &= ~ASYNC_CHECK_CD;
3228 else
3229 info->flags |= ASYNC_CHECK_CD;
3181 3230
3182 /*********************************************** 3231 /***********************************************
3183 The hardware option, CyRtsAO, presents RTS when 3232 The hardware option, CyRtsAO, presents RTS when
@@ -3189,300 +3238,319 @@ set_line_char(struct cyclades_port * info)
3189 cable. Contact Marcio Saito for details. 3238 cable. Contact Marcio Saito for details.
3190 ***********************************************/ 3239 ***********************************************/
3191 3240
3192 chip = channel>>2; 3241 chip = channel >> 2;
3193 channel &= 0x03; 3242 channel &= 0x03;
3194 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index); 3243 base_addr = cy_card[card].base_addr +
3244 (cy_chip_offset[chip] << index);
3195 3245
3196 CY_LOCK(info, flags); 3246 CY_LOCK(info, flags);
3197 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3247 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
3198 3248
3199 /* tx and rx baud rate */ 3249 /* tx and rx baud rate */
3200 3250
3201 cy_writeb(base_addr+(CyTCOR<<index), info->tco); 3251 cy_writeb(base_addr + (CyTCOR << index), info->tco);
3202 cy_writeb(base_addr+(CyTBPR<<index), info->tbpr); 3252 cy_writeb(base_addr + (CyTBPR << index), info->tbpr);
3203 cy_writeb(base_addr+(CyRCOR<<index), info->rco); 3253 cy_writeb(base_addr + (CyRCOR << index), info->rco);
3204 cy_writeb(base_addr+(CyRBPR<<index), info->rbpr); 3254 cy_writeb(base_addr + (CyRBPR << index), info->rbpr);
3205 3255
3206 /* set line characteristics according configuration */ 3256 /* set line characteristics according configuration */
3207 3257
3208 cy_writeb(base_addr+(CySCHR1<<index), 3258 cy_writeb(base_addr + (CySCHR1 << index),
3209 START_CHAR(info->tty)); 3259 START_CHAR(info->tty));
3210 cy_writeb(base_addr+(CySCHR2<<index), 3260 cy_writeb(base_addr + (CySCHR2 << index), STOP_CHAR(info->tty));
3211 STOP_CHAR(info->tty)); 3261 cy_writeb(base_addr + (CyCOR1 << index), info->cor1);
3212 cy_writeb(base_addr+(CyCOR1<<index), info->cor1); 3262 cy_writeb(base_addr + (CyCOR2 << index), info->cor2);
3213 cy_writeb(base_addr+(CyCOR2<<index), info->cor2); 3263 cy_writeb(base_addr + (CyCOR3 << index), info->cor3);
3214 cy_writeb(base_addr+(CyCOR3<<index), info->cor3); 3264 cy_writeb(base_addr + (CyCOR4 << index), info->cor4);
3215 cy_writeb(base_addr+(CyCOR4<<index), info->cor4); 3265 cy_writeb(base_addr + (CyCOR5 << index), info->cor5);
3216 cy_writeb(base_addr+(CyCOR5<<index), info->cor5); 3266
3217 3267 cyy_issue_cmd(base_addr, CyCOR_CHANGE | CyCOR1ch | CyCOR2ch |
3218 cyy_issue_cmd(base_addr, 3268 CyCOR3ch, index);
3219 CyCOR_CHANGE|CyCOR1ch|CyCOR2ch|CyCOR3ch,index); 3269
3220 3270 cy_writeb(base_addr + (CyCAR << index), (u_char) channel); /* !!! Is this needed? */
3221 cy_writeb(base_addr+(CyCAR<<index), 3271 cy_writeb(base_addr + (CyRTPR << index),
3222 (u_char)channel); /* !!! Is this needed? */ 3272 (info->default_timeout ? info->default_timeout : 0x02));
3223 cy_writeb(base_addr+(CyRTPR<<index), (info->default_timeout 3273 /* 10ms rx timeout */
3224 ? info->default_timeout 3274
3225 : 0x02)); /* 10ms rx timeout */ 3275 if (C_CLOCAL(info->tty)) {
3226 3276 /* without modem intr */
3227 if (C_CLOCAL(info->tty)) { 3277 cy_writeb(base_addr + (CySRER << index),
3228 /* without modem intr */ 3278 cy_readb(base_addr +
3229 cy_writeb(base_addr+(CySRER<<index), 3279 (CySRER << index)) | CyMdmCh);
3230 cy_readb(base_addr+(CySRER<<index)) | CyMdmCh); 3280 /* act on 1->0 modem transitions */
3231 /* act on 1->0 modem transitions */ 3281 if ((cflag & CRTSCTS) && info->rflow) {
3232 if ((cflag & CRTSCTS) && info->rflow) { 3282 cy_writeb(base_addr + (CyMCOR1 << index),
3233 cy_writeb(base_addr+(CyMCOR1<<index), 3283 (CyCTS | rflow_thr[i]));
3234 (CyCTS|rflow_thr[i])); 3284 } else {
3235 } else { 3285 cy_writeb(base_addr + (CyMCOR1 << index),
3236 cy_writeb(base_addr+(CyMCOR1<<index), CyCTS); 3286 CyCTS);
3237 } 3287 }
3238 /* act on 0->1 modem transitions */ 3288 /* act on 0->1 modem transitions */
3239 cy_writeb(base_addr+(CyMCOR2<<index), CyCTS); 3289 cy_writeb(base_addr + (CyMCOR2 << index), CyCTS);
3240 } else {
3241 /* without modem intr */
3242 cy_writeb(base_addr+(CySRER<<index),
3243 cy_readb(base_addr+(CySRER<<index)) | CyMdmCh);
3244 /* act on 1->0 modem transitions */
3245 if ((cflag & CRTSCTS) && info->rflow) {
3246 cy_writeb(base_addr+(CyMCOR1<<index),
3247 (CyDSR|CyCTS|CyRI|CyDCD|rflow_thr[i]));
3248 } else {
3249 cy_writeb(base_addr+(CyMCOR1<<index),
3250 CyDSR|CyCTS|CyRI|CyDCD);
3251 }
3252 /* act on 0->1 modem transitions */
3253 cy_writeb(base_addr+(CyMCOR2<<index),
3254 CyDSR|CyCTS|CyRI|CyDCD);
3255 }
3256
3257 if(i == 0){ /* baud rate is zero, turn off line */
3258 if (info->rtsdtr_inv) {
3259 cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS);
3260 } else { 3290 } else {
3261 cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR); 3291 /* without modem intr */
3292 cy_writeb(base_addr + (CySRER << index),
3293 cy_readb(base_addr +
3294 (CySRER << index)) | CyMdmCh);
3295 /* act on 1->0 modem transitions */
3296 if ((cflag & CRTSCTS) && info->rflow) {
3297 cy_writeb(base_addr + (CyMCOR1 << index),
3298 (CyDSR | CyCTS | CyRI | CyDCD |
3299 rflow_thr[i]));
3300 } else {
3301 cy_writeb(base_addr + (CyMCOR1 << index),
3302 CyDSR | CyCTS | CyRI | CyDCD);
3303 }
3304 /* act on 0->1 modem transitions */
3305 cy_writeb(base_addr + (CyMCOR2 << index),
3306 CyDSR | CyCTS | CyRI | CyDCD);
3262 } 3307 }
3308
3309 if (i == 0) { /* baud rate is zero, turn off line */
3310 if (info->rtsdtr_inv) {
3311 cy_writeb(base_addr + (CyMSVR1 << index),
3312 ~CyRTS);
3313 } else {
3314 cy_writeb(base_addr + (CyMSVR2 << index),
3315 ~CyDTR);
3316 }
3263#ifdef CY_DEBUG_DTR 3317#ifdef CY_DEBUG_DTR
3264 printk("cyc:set_line_char dropping DTR\n"); 3318 printk("cyc:set_line_char dropping DTR\n");
3265 printk(" status: 0x%x, 0x%x\n", 3319 printk(" status: 0x%x, 0x%x\n",
3266 cy_readb(base_addr+(CyMSVR1<<index)), 3320 cy_readb(base_addr + (CyMSVR1 << index)),
3267 cy_readb(base_addr+(CyMSVR2<<index))); 3321 cy_readb(base_addr + (CyMSVR2 << index)));
3268#endif 3322#endif
3269 }else{ 3323 } else {
3270 if (info->rtsdtr_inv) { 3324 if (info->rtsdtr_inv) {
3271 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS); 3325 cy_writeb(base_addr + (CyMSVR1 << index),
3272 } else { 3326 CyRTS);
3273 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR); 3327 } else {
3274 } 3328 cy_writeb(base_addr + (CyMSVR2 << index),
3329 CyDTR);
3330 }
3275#ifdef CY_DEBUG_DTR 3331#ifdef CY_DEBUG_DTR
3276 printk("cyc:set_line_char raising DTR\n"); 3332 printk("cyc:set_line_char raising DTR\n");
3277 printk(" status: 0x%x, 0x%x\n", 3333 printk(" status: 0x%x, 0x%x\n",
3278 cy_readb(base_addr+(CyMSVR1<<index)), 3334 cy_readb(base_addr + (CyMSVR1 << index)),
3279 cy_readb(base_addr+(CyMSVR2<<index))); 3335 cy_readb(base_addr + (CyMSVR2 << index)));
3280#endif 3336#endif
3281 } 3337 }
3282
3283 if (info->tty){
3284 clear_bit(TTY_IO_ERROR, &info->tty->flags);
3285 }
3286 CY_UNLOCK(info, flags);
3287 3338
3288 } else { 3339 if (info->tty) {
3289 struct FIRM_ID __iomem *firm_id; 3340 clear_bit(TTY_IO_ERROR, &info->tty->flags);
3290 struct ZFW_CTRL __iomem *zfw_ctrl; 3341 }
3291 struct BOARD_CTRL __iomem *board_ctrl; 3342 CY_UNLOCK(info, flags);
3292 struct CH_CTRL __iomem *ch_ctrl;
3293 struct BUF_CTRL __iomem *buf_ctrl;
3294 uclong sw_flow;
3295 int retval;
3296
3297 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3298 if (!ISZLOADED(cy_card[card])) {
3299 return;
3300 }
3301 3343
3302 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3303 board_ctrl = &zfw_ctrl->board_ctrl;
3304 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
3305 buf_ctrl = &zfw_ctrl->buf_ctrl[channel];
3306
3307 /* baud rate */
3308 baud = tty_get_baud_rate(info->tty);
3309 if ((baud == 38400) &&
3310 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
3311 if (info->custom_divisor)
3312 baud_rate = info->baud / info->custom_divisor;
3313 else
3314 baud_rate = info->baud;
3315 } else if (baud > CYZ_MAX_SPEED) {
3316 baud = CYZ_MAX_SPEED;
3317 }
3318 cy_writel(&ch_ctrl->comm_baud , baud);
3319
3320 if (baud == 134) {
3321 /* get it right for 134.5 baud */
3322 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
3323 } else if ((baud == 38400) &&
3324 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
3325 info->timeout = (info->xmit_fifo_size*HZ*15/baud_rate) + 2;
3326 } else if (baud) {
3327 info->timeout = (info->xmit_fifo_size*HZ*15/baud) + 2;
3328 /* this needs to be propagated into the card info */
3329 } else { 3344 } else {
3330 info->timeout = 0; 3345 struct FIRM_ID __iomem *firm_id;
3331 } 3346 struct ZFW_CTRL __iomem *zfw_ctrl;
3347 struct BOARD_CTRL __iomem *board_ctrl;
3348 struct CH_CTRL __iomem *ch_ctrl;
3349 struct BUF_CTRL __iomem *buf_ctrl;
3350 uclong sw_flow;
3351 int retval;
3352
3353 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3354 if (!ISZLOADED(cy_card[card])) {
3355 return;
3356 }
3332 3357
3333 /* byte size and parity */ 3358 zfw_ctrl = cy_card[card].base_addr +
3334 switch(cflag & CSIZE){ 3359 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3335 case CS5: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS5); break; 3360 board_ctrl = &zfw_ctrl->board_ctrl;
3336 case CS6: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS6); break; 3361 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
3337 case CS7: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS7); break; 3362 buf_ctrl = &zfw_ctrl->buf_ctrl[channel];
3338 case CS8: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS8); break; 3363
3339 } 3364 /* baud rate */
3340 if(cflag & CSTOPB){ 3365 baud = tty_get_baud_rate(info->tty);
3341 cy_writel(&ch_ctrl->comm_data_l, 3366 if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3342 cy_readl(&ch_ctrl->comm_data_l) | C_DL_2STOP); 3367 ASYNC_SPD_CUST) {
3343 }else{ 3368 if (info->custom_divisor)
3344 cy_writel(&ch_ctrl->comm_data_l, 3369 baud_rate = info->baud / info->custom_divisor;
3345 cy_readl(&ch_ctrl->comm_data_l) | C_DL_1STOP); 3370 else
3346 } 3371 baud_rate = info->baud;
3347 if (cflag & PARENB){ 3372 } else if (baud > CYZ_MAX_SPEED) {
3348 if (cflag & PARODD){ 3373 baud = CYZ_MAX_SPEED;
3349 cy_writel(&ch_ctrl->comm_parity , C_PR_ODD); 3374 }
3350 }else{ 3375 cy_writel(&ch_ctrl->comm_baud, baud);
3351 cy_writel(&ch_ctrl->comm_parity , C_PR_EVEN); 3376
3352 } 3377 if (baud == 134) {
3353 }else{ 3378 /* get it right for 134.5 baud */
3354 cy_writel(&ch_ctrl->comm_parity , C_PR_NONE); 3379 info->timeout = (info->xmit_fifo_size * HZ * 30 / 269) +
3355 } 3380 2;
3381 } else if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3382 ASYNC_SPD_CUST) {
3383 info->timeout = (info->xmit_fifo_size * HZ * 15 /
3384 baud_rate) + 2;
3385 } else if (baud) {
3386 info->timeout = (info->xmit_fifo_size * HZ * 15 /
3387 baud) + 2;
3388 /* this needs to be propagated into the card info */
3389 } else {
3390 info->timeout = 0;
3391 }
3356 3392
3357 /* CTS flow control flag */ 3393 /* byte size and parity */
3358 if (cflag & CRTSCTS){ 3394 switch (cflag & CSIZE) {
3359 cy_writel(&ch_ctrl->hw_flow, 3395 case CS5:
3360 cy_readl(&ch_ctrl->hw_flow) | C_RS_CTS | C_RS_RTS); 3396 cy_writel(&ch_ctrl->comm_data_l, C_DL_CS5);
3361 }else{ 3397 break;
3362 cy_writel(&ch_ctrl->hw_flow, 3398 case CS6:
3363 cy_readl(&ch_ctrl->hw_flow) & ~(C_RS_CTS | C_RS_RTS)); 3399 cy_writel(&ch_ctrl->comm_data_l, C_DL_CS6);
3364 } 3400 break;
3365 /* As the HW flow control is done in firmware, the driver doesn't 3401 case CS7:
3366 need to care about it */ 3402 cy_writel(&ch_ctrl->comm_data_l, C_DL_CS7);
3367 info->flags &= ~ASYNC_CTS_FLOW; 3403 break;
3368 3404 case CS8:
3369 /* XON/XOFF/XANY flow control flags */ 3405 cy_writel(&ch_ctrl->comm_data_l, C_DL_CS8);
3370 sw_flow = 0; 3406 break;
3371 if (iflag & IXON){ 3407 }
3372 sw_flow |= C_FL_OXX; 3408 if (cflag & CSTOPB) {
3373 if (iflag & IXANY) 3409 cy_writel(&ch_ctrl->comm_data_l,
3374 sw_flow |= C_FL_OIXANY; 3410 cy_readl(&ch_ctrl->comm_data_l) | C_DL_2STOP);
3375 } 3411 } else {
3376 cy_writel(&ch_ctrl->sw_flow, sw_flow); 3412 cy_writel(&ch_ctrl->comm_data_l,
3413 cy_readl(&ch_ctrl->comm_data_l) | C_DL_1STOP);
3414 }
3415 if (cflag & PARENB) {
3416 if (cflag & PARODD) {
3417 cy_writel(&ch_ctrl->comm_parity, C_PR_ODD);
3418 } else {
3419 cy_writel(&ch_ctrl->comm_parity, C_PR_EVEN);
3420 }
3421 } else {
3422 cy_writel(&ch_ctrl->comm_parity, C_PR_NONE);
3423 }
3377 3424
3378 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L); 3425 /* CTS flow control flag */
3379 if (retval != 0){ 3426 if (cflag & CRTSCTS) {
3380 printk("cyc:set_line_char retval on ttyC%d was %x\n", 3427 cy_writel(&ch_ctrl->hw_flow,
3381 info->line, retval); 3428 cy_readl(&ch_ctrl->
3382 } 3429 hw_flow) | C_RS_CTS | C_RS_RTS);
3430 } else {
3431 cy_writel(&ch_ctrl->hw_flow,
3432 cy_readl(&ch_ctrl->
3433 hw_flow) & ~(C_RS_CTS | C_RS_RTS));
3434 }
3435 /* As the HW flow control is done in firmware, the driver
3436 doesn't need to care about it */
3437 info->flags &= ~ASYNC_CTS_FLOW;
3438
3439 /* XON/XOFF/XANY flow control flags */
3440 sw_flow = 0;
3441 if (iflag & IXON) {
3442 sw_flow |= C_FL_OXX;
3443 if (iflag & IXANY)
3444 sw_flow |= C_FL_OIXANY;
3445 }
3446 cy_writel(&ch_ctrl->sw_flow, sw_flow);
3383 3447
3384 /* CD sensitivity */ 3448 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L);
3385 if (cflag & CLOCAL){ 3449 if (retval != 0) {
3386 info->flags &= ~ASYNC_CHECK_CD; 3450 printk("cyc:set_line_char retval on ttyC%d was %x\n",
3387 }else{ 3451 info->line, retval);
3388 info->flags |= ASYNC_CHECK_CD; 3452 }
3389 }
3390 3453
3391 if(baud == 0){ /* baud rate is zero, turn off line */ 3454 /* CD sensitivity */
3392 cy_writel(&ch_ctrl->rs_control, 3455 if (cflag & CLOCAL) {
3393 cy_readl(&ch_ctrl->rs_control) & ~C_RS_DTR); 3456 info->flags &= ~ASYNC_CHECK_CD;
3457 } else {
3458 info->flags |= ASYNC_CHECK_CD;
3459 }
3460
3461 if (baud == 0) { /* baud rate is zero, turn off line */
3462 cy_writel(&ch_ctrl->rs_control,
3463 cy_readl(&ch_ctrl->rs_control) & ~C_RS_DTR);
3394#ifdef CY_DEBUG_DTR 3464#ifdef CY_DEBUG_DTR
3395 printk("cyc:set_line_char dropping Z DTR\n"); 3465 printk("cyc:set_line_char dropping Z DTR\n");
3396#endif 3466#endif
3397 }else{ 3467 } else {
3398 cy_writel(&ch_ctrl->rs_control, 3468 cy_writel(&ch_ctrl->rs_control,
3399 cy_readl(&ch_ctrl->rs_control) | C_RS_DTR); 3469 cy_readl(&ch_ctrl->rs_control) | C_RS_DTR);
3400#ifdef CY_DEBUG_DTR 3470#ifdef CY_DEBUG_DTR
3401 printk("cyc:set_line_char raising Z DTR\n"); 3471 printk("cyc:set_line_char raising Z DTR\n");
3402#endif 3472#endif
3403 } 3473 }
3404 3474
3405 retval = cyz_issue_cmd( &cy_card[card], channel, C_CM_IOCTLM, 0L); 3475 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTLM,0L);
3406 if (retval != 0){ 3476 if (retval != 0) {
3407 printk("cyc:set_line_char(2) retval on ttyC%d was %x\n", 3477 printk("cyc:set_line_char(2) retval on ttyC%d was %x\n",
3408 info->line, retval); 3478 info->line, retval);
3409 } 3479 }
3410 3480
3411 if (info->tty){ 3481 if (info->tty) {
3412 clear_bit(TTY_IO_ERROR, &info->tty->flags); 3482 clear_bit(TTY_IO_ERROR, &info->tty->flags);
3483 }
3413 } 3484 }
3414 } 3485} /* set_line_char */
3415} /* set_line_char */
3416
3417 3486
3418static int 3487static int
3419get_serial_info(struct cyclades_port * info, 3488get_serial_info(struct cyclades_port *info,
3420 struct serial_struct __user * retinfo) 3489 struct serial_struct __user * retinfo)
3421{ 3490{
3422 struct serial_struct tmp; 3491 struct serial_struct tmp;
3423 struct cyclades_card *cinfo = &cy_card[info->card]; 3492 struct cyclades_card *cinfo = &cy_card[info->card];
3424
3425 if (!retinfo)
3426 return -EFAULT;
3427 memset(&tmp, 0, sizeof(tmp));
3428 tmp.type = info->type;
3429 tmp.line = info->line;
3430 tmp.port = info->card * 0x100 + info->line - cinfo->first_line;
3431 tmp.irq = cinfo->irq;
3432 tmp.flags = info->flags;
3433 tmp.close_delay = info->close_delay;
3434 tmp.baud_base = info->baud;
3435 tmp.custom_divisor = info->custom_divisor;
3436 tmp.hub6 = 0; /*!!!*/
3437 return copy_to_user(retinfo,&tmp,sizeof(*retinfo))?-EFAULT:0;
3438} /* get_serial_info */
3439 3493
3494 if (!retinfo)
3495 return -EFAULT;
3496 memset(&tmp, 0, sizeof(tmp));
3497 tmp.type = info->type;
3498 tmp.line = info->line;
3499 tmp.port = info->card * 0x100 + info->line - cinfo->first_line;
3500 tmp.irq = cinfo->irq;
3501 tmp.flags = info->flags;
3502 tmp.close_delay = info->close_delay;
3503 tmp.baud_base = info->baud;
3504 tmp.custom_divisor = info->custom_divisor;
3505 tmp.hub6 = 0; /*!!! */
3506 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
3507} /* get_serial_info */
3440 3508
3441static int 3509static int
3442set_serial_info(struct cyclades_port * info, 3510set_serial_info(struct cyclades_port *info,
3443 struct serial_struct __user * new_info) 3511 struct serial_struct __user * new_info)
3444{ 3512{
3445 struct serial_struct new_serial; 3513 struct serial_struct new_serial;
3446 struct cyclades_port old_info; 3514 struct cyclades_port old_info;
3447 3515
3448 if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) 3516 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
3449 return -EFAULT; 3517 return -EFAULT;
3450 old_info = *info; 3518 old_info = *info;
3451 3519
3452 if (!capable(CAP_SYS_ADMIN)) { 3520 if (!capable(CAP_SYS_ADMIN)) {
3453 if ((new_serial.close_delay != info->close_delay) || 3521 if (new_serial.close_delay != info->close_delay ||
3454 (new_serial.baud_base != info->baud) || 3522 new_serial.baud_base != info->baud ||
3455 ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) != 3523 (new_serial.flags & ASYNC_FLAGS &
3456 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK))) 3524 ~ASYNC_USR_MASK) !=
3457 return -EPERM; 3525 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK))
3458 info->flags = ((info->flags & ~ASYNC_USR_MASK) | 3526 return -EPERM;
3459 (new_serial.flags & ASYNC_USR_MASK)); 3527 info->flags = (info->flags & ~ASYNC_USR_MASK) |
3460 info->baud = new_serial.baud_base; 3528 (new_serial.flags & ASYNC_USR_MASK);
3461 info->custom_divisor = new_serial.custom_divisor; 3529 info->baud = new_serial.baud_base;
3462 goto check_and_exit; 3530 info->custom_divisor = new_serial.custom_divisor;
3463 } 3531 goto check_and_exit;
3464 3532 }
3465 3533
3466 /* 3534 /*
3467 * OK, past this point, all the error checking has been done. 3535 * OK, past this point, all the error checking has been done.
3468 * At this point, we start making changes..... 3536 * At this point, we start making changes.....
3469 */ 3537 */
3470 3538
3471 info->baud = new_serial.baud_base; 3539 info->baud = new_serial.baud_base;
3472 info->custom_divisor = new_serial.custom_divisor; 3540 info->custom_divisor = new_serial.custom_divisor;
3473 info->flags = ((info->flags & ~ASYNC_FLAGS) | 3541 info->flags = (info->flags & ~ASYNC_FLAGS) |
3474 (new_serial.flags & ASYNC_FLAGS)); 3542 (new_serial.flags & ASYNC_FLAGS);
3475 info->close_delay = new_serial.close_delay * HZ/100; 3543 info->close_delay = new_serial.close_delay * HZ / 100;
3476 info->closing_wait = new_serial.closing_wait * HZ/100; 3544 info->closing_wait = new_serial.closing_wait * HZ / 100;
3477 3545
3478check_and_exit: 3546check_and_exit:
3479 if (info->flags & ASYNC_INITIALIZED){ 3547 if (info->flags & ASYNC_INITIALIZED) {
3480 set_line_char(info); 3548 set_line_char(info);
3481 return 0; 3549 return 0;
3482 }else{ 3550 } else {
3483 return startup(info); 3551 return startup(info);
3484 } 3552 }
3485} /* set_serial_info */ 3553} /* set_serial_info */
3486 3554
3487/* 3555/*
3488 * get_lsr_info - get line status register info 3556 * get_lsr_info - get line status register info
@@ -3494,441 +3562,452 @@ check_and_exit:
3494 * transmit holding register is empty. This functionality 3562 * transmit holding register is empty. This functionality
3495 * allows an RS485 driver to be written in user space. 3563 * allows an RS485 driver to be written in user space.
3496 */ 3564 */
3497static int get_lsr_info(struct cyclades_port *info, unsigned int __user *value) 3565static int get_lsr_info(struct cyclades_port *info, unsigned int __user * value)
3498{ 3566{
3499 int card, chip, channel, index; 3567 int card, chip, channel, index;
3500 unsigned char status; 3568 unsigned char status;
3501 unsigned int result; 3569 unsigned int result;
3502 unsigned long flags; 3570 unsigned long flags;
3503 void __iomem *base_addr; 3571 void __iomem *base_addr;
3504
3505 card = info->card;
3506 channel = (info->line) - (cy_card[card].first_line);
3507 if (!IS_CYC_Z(cy_card[card])) {
3508 chip = channel>>2;
3509 channel &= 0x03;
3510 index = cy_card[card].bus_index;
3511 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3512 3572
3513 CY_LOCK(info, flags); 3573 card = info->card;
3514 status = cy_readb(base_addr+(CySRER<<index)) & (CyTxRdy|CyTxMpty); 3574 channel = (info->line) - (cy_card[card].first_line);
3515 CY_UNLOCK(info, flags); 3575 if (!IS_CYC_Z(cy_card[card])) {
3516 result = (status ? 0 : TIOCSER_TEMT); 3576 chip = channel >> 2;
3517 } else { 3577 channel &= 0x03;
3518 /* Not supported yet */ 3578 index = cy_card[card].bus_index;
3519 return -EINVAL; 3579 base_addr =
3520 } 3580 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3521 return put_user(result, (unsigned long __user *) value); 3581
3582 CY_LOCK(info, flags);
3583 status = cy_readb(base_addr + (CySRER << index)) &
3584 (CyTxRdy | CyTxMpty);
3585 CY_UNLOCK(info, flags);
3586 result = (status ? 0 : TIOCSER_TEMT);
3587 } else {
3588 /* Not supported yet */
3589 return -EINVAL;
3590 }
3591 return put_user(result, (unsigned long __user *)value);
3522} 3592}
3523 3593
3524static int 3594static int cy_tiocmget(struct tty_struct *tty, struct file *file)
3525cy_tiocmget(struct tty_struct *tty, struct file *file)
3526{ 3595{
3527 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 3596 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3528 int card,chip,channel,index; 3597 int card, chip, channel, index;
3529 void __iomem *base_addr; 3598 void __iomem *base_addr;
3530 unsigned long flags; 3599 unsigned long flags;
3531 unsigned char status; 3600 unsigned char status;
3532 unsigned long lstatus; 3601 unsigned long lstatus;
3533 unsigned int result; 3602 unsigned int result;
3534 struct FIRM_ID __iomem *firm_id; 3603 struct FIRM_ID __iomem *firm_id;
3535 struct ZFW_CTRL __iomem *zfw_ctrl; 3604 struct ZFW_CTRL __iomem *zfw_ctrl;
3536 struct BOARD_CTRL __iomem *board_ctrl; 3605 struct BOARD_CTRL __iomem *board_ctrl;
3537 struct CH_CTRL __iomem *ch_ctrl; 3606 struct CH_CTRL __iomem *ch_ctrl;
3538 3607
3539 if (serial_paranoia_check(info, tty->name, __FUNCTION__)) 3608 if (serial_paranoia_check(info, tty->name, __FUNCTION__))
3540 return -ENODEV; 3609 return -ENODEV;
3541
3542 card = info->card;
3543 channel = (info->line) - (cy_card[card].first_line);
3544 if (!IS_CYC_Z(cy_card[card])) {
3545 chip = channel>>2;
3546 channel &= 0x03;
3547 index = cy_card[card].bus_index;
3548 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3549 3610
3550 CY_LOCK(info, flags); 3611 card = info->card;
3551 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3612 channel = (info->line) - (cy_card[card].first_line);
3552 status = cy_readb(base_addr+(CyMSVR1<<index)); 3613 if (!IS_CYC_Z(cy_card[card])) {
3553 status |= cy_readb(base_addr+(CyMSVR2<<index)); 3614 chip = channel >> 2;
3554 CY_UNLOCK(info, flags); 3615 channel &= 0x03;
3616 index = cy_card[card].bus_index;
3617 base_addr =
3618 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3619
3620 CY_LOCK(info, flags);
3621 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
3622 status = cy_readb(base_addr + (CyMSVR1 << index));
3623 status |= cy_readb(base_addr + (CyMSVR2 << index));
3624 CY_UNLOCK(info, flags);
3555 3625
3556 if (info->rtsdtr_inv) { 3626 if (info->rtsdtr_inv) {
3557 result = ((status & CyRTS) ? TIOCM_DTR : 0) 3627 result = ((status & CyRTS) ? TIOCM_DTR : 0) |
3558 | ((status & CyDTR) ? TIOCM_RTS : 0); 3628 ((status & CyDTR) ? TIOCM_RTS : 0);
3629 } else {
3630 result = ((status & CyRTS) ? TIOCM_RTS : 0) |
3631 ((status & CyDTR) ? TIOCM_DTR : 0);
3632 }
3633 result |= ((status & CyDCD) ? TIOCM_CAR : 0) |
3634 ((status & CyRI) ? TIOCM_RNG : 0) |
3635 ((status & CyDSR) ? TIOCM_DSR : 0) |
3636 ((status & CyCTS) ? TIOCM_CTS : 0);
3559 } else { 3637 } else {
3560 result = ((status & CyRTS) ? TIOCM_RTS : 0) 3638 base_addr = cy_card[card].base_addr;
3561 | ((status & CyDTR) ? TIOCM_DTR : 0);
3562 }
3563 result |= ((status & CyDCD) ? TIOCM_CAR : 0)
3564 | ((status & CyRI) ? TIOCM_RNG : 0)
3565 | ((status & CyDSR) ? TIOCM_DSR : 0)
3566 | ((status & CyCTS) ? TIOCM_CTS : 0);
3567 } else {
3568 base_addr = cy_card[card].base_addr;
3569
3570 if (cy_card[card].num_chips != -1){
3571 return -EINVAL;
3572 }
3573 3639
3574 firm_id = cy_card[card].base_addr + ID_ADDRESS; 3640 if (cy_card[card].num_chips != -1) {
3575 if (ISZLOADED(cy_card[card])) { 3641 return -EINVAL;
3576 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 3642 }
3577 board_ctrl = &zfw_ctrl->board_ctrl;
3578 ch_ctrl = zfw_ctrl->ch_ctrl;
3579 lstatus = cy_readl(&ch_ctrl[channel].rs_status);
3580 result = ((lstatus & C_RS_RTS) ? TIOCM_RTS : 0)
3581 | ((lstatus & C_RS_DTR) ? TIOCM_DTR : 0)
3582 | ((lstatus & C_RS_DCD) ? TIOCM_CAR : 0)
3583 | ((lstatus & C_RS_RI) ? TIOCM_RNG : 0)
3584 | ((lstatus & C_RS_DSR) ? TIOCM_DSR : 0)
3585 | ((lstatus & C_RS_CTS) ? TIOCM_CTS : 0);
3586 }else{
3587 result = 0;
3588 return -ENODEV;
3589 }
3590 3643
3591 } 3644 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3592 return result; 3645 if (ISZLOADED(cy_card[card])) {
3593} /* cy_tiomget */ 3646 zfw_ctrl = cy_card[card].base_addr +
3647 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3648 board_ctrl = &zfw_ctrl->board_ctrl;
3649 ch_ctrl = zfw_ctrl->ch_ctrl;
3650 lstatus = cy_readl(&ch_ctrl[channel].rs_status);
3651 result = ((lstatus & C_RS_RTS) ? TIOCM_RTS : 0) |
3652 ((lstatus & C_RS_DTR) ? TIOCM_DTR : 0) |
3653 ((lstatus & C_RS_DCD) ? TIOCM_CAR : 0) |
3654 ((lstatus & C_RS_RI) ? TIOCM_RNG : 0) |
3655 ((lstatus & C_RS_DSR) ? TIOCM_DSR : 0) |
3656 ((lstatus & C_RS_CTS) ? TIOCM_CTS : 0);
3657 } else {
3658 result = 0;
3659 return -ENODEV;
3660 }
3594 3661
3662 }
3663 return result;
3664} /* cy_tiomget */
3595 3665
3596static int 3666static int
3597cy_tiocmset(struct tty_struct *tty, struct file *file, 3667cy_tiocmset(struct tty_struct *tty, struct file *file,
3598 unsigned int set, unsigned int clear) 3668 unsigned int set, unsigned int clear)
3599{ 3669{
3600 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 3670 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3601 int card,chip,channel,index; 3671 int card, chip, channel, index;
3602 void __iomem *base_addr; 3672 void __iomem *base_addr;
3603 unsigned long flags; 3673 unsigned long flags;
3604 struct FIRM_ID __iomem *firm_id; 3674 struct FIRM_ID __iomem *firm_id;
3605 struct ZFW_CTRL __iomem *zfw_ctrl; 3675 struct ZFW_CTRL __iomem *zfw_ctrl;
3606 struct BOARD_CTRL __iomem *board_ctrl; 3676 struct BOARD_CTRL __iomem *board_ctrl;
3607 struct CH_CTRL __iomem *ch_ctrl; 3677 struct CH_CTRL __iomem *ch_ctrl;
3608 int retval; 3678 int retval;
3609 3679
3610 if (serial_paranoia_check(info, tty->name, __FUNCTION__)) 3680 if (serial_paranoia_check(info, tty->name, __FUNCTION__))
3611 return -ENODEV; 3681 return -ENODEV;
3612 3682
3613 card = info->card; 3683 card = info->card;
3614 channel = (info->line) - (cy_card[card].first_line); 3684 channel = (info->line) - (cy_card[card].first_line);
3615 if (!IS_CYC_Z(cy_card[card])) { 3685 if (!IS_CYC_Z(cy_card[card])) {
3616 chip = channel>>2; 3686 chip = channel >> 2;
3617 channel &= 0x03; 3687 channel &= 0x03;
3618 index = cy_card[card].bus_index; 3688 index = cy_card[card].bus_index;
3619 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index); 3689 base_addr =
3620 3690 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3621 if (set & TIOCM_RTS){ 3691
3622 CY_LOCK(info, flags); 3692 if (set & TIOCM_RTS) {
3623 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3693 CY_LOCK(info, flags);
3624 if (info->rtsdtr_inv) { 3694 cy_writeb(base_addr + (CyCAR << index),
3625 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR); 3695 (u_char) channel);
3626 } else { 3696 if (info->rtsdtr_inv) {
3627 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS); 3697 cy_writeb(base_addr + (CyMSVR2 << index),
3628 } 3698 CyDTR);
3629 CY_UNLOCK(info, flags); 3699 } else {
3630 } 3700 cy_writeb(base_addr + (CyMSVR1 << index),
3631 if (clear & TIOCM_RTS) { 3701 CyRTS);
3632 CY_LOCK(info, flags); 3702 }
3633 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3703 CY_UNLOCK(info, flags);
3634 if (info->rtsdtr_inv) { 3704 }
3635 cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR); 3705 if (clear & TIOCM_RTS) {
3636 } else { 3706 CY_LOCK(info, flags);
3637 cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS); 3707 cy_writeb(base_addr + (CyCAR << index),
3638 } 3708 (u_char) channel);
3639 CY_UNLOCK(info, flags); 3709 if (info->rtsdtr_inv) {
3640 } 3710 cy_writeb(base_addr + (CyMSVR2 << index),
3641 if (set & TIOCM_DTR){ 3711 ~CyDTR);
3642 CY_LOCK(info, flags); 3712 } else {
3643 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3713 cy_writeb(base_addr + (CyMSVR1 << index),
3644 if (info->rtsdtr_inv) { 3714 ~CyRTS);
3645 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS); 3715 }
3646 } else { 3716 CY_UNLOCK(info, flags);
3647 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR); 3717 }
3648 } 3718 if (set & TIOCM_DTR) {
3719 CY_LOCK(info, flags);
3720 cy_writeb(base_addr + (CyCAR << index),
3721 (u_char) channel);
3722 if (info->rtsdtr_inv) {
3723 cy_writeb(base_addr + (CyMSVR1 << index),
3724 CyRTS);
3725 } else {
3726 cy_writeb(base_addr + (CyMSVR2 << index),
3727 CyDTR);
3728 }
3649#ifdef CY_DEBUG_DTR 3729#ifdef CY_DEBUG_DTR
3650 printk("cyc:set_modem_info raising DTR\n"); 3730 printk("cyc:set_modem_info raising DTR\n");
3651 printk(" status: 0x%x, 0x%x\n", 3731 printk(" status: 0x%x, 0x%x\n",
3652 cy_readb(base_addr+(CyMSVR1<<index)), 3732 cy_readb(base_addr + (CyMSVR1 << index)),
3653 cy_readb(base_addr+(CyMSVR2<<index))); 3733 cy_readb(base_addr + (CyMSVR2 << index)));
3654#endif 3734#endif
3655 CY_UNLOCK(info, flags); 3735 CY_UNLOCK(info, flags);
3656 } 3736 }
3657 if (clear & TIOCM_DTR) { 3737 if (clear & TIOCM_DTR) {
3658 CY_LOCK(info, flags); 3738 CY_LOCK(info, flags);
3659 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3739 cy_writeb(base_addr + (CyCAR << index),
3660 if (info->rtsdtr_inv) { 3740 (u_char) channel);
3661 cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS); 3741 if (info->rtsdtr_inv) {
3662 } else { 3742 cy_writeb(base_addr + (CyMSVR1 << index),
3663 cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR); 3743 ~CyRTS);
3664 } 3744 } else {
3745 cy_writeb(base_addr + (CyMSVR2 << index),
3746 ~CyDTR);
3747 }
3665 3748
3666#ifdef CY_DEBUG_DTR 3749#ifdef CY_DEBUG_DTR
3667 printk("cyc:set_modem_info dropping DTR\n"); 3750 printk("cyc:set_modem_info dropping DTR\n");
3668 printk(" status: 0x%x, 0x%x\n", 3751 printk(" status: 0x%x, 0x%x\n",
3669 cy_readb(base_addr+(CyMSVR1<<index)), 3752 cy_readb(base_addr + (CyMSVR1 << index)),
3670 cy_readb(base_addr+(CyMSVR2<<index))); 3753 cy_readb(base_addr + (CyMSVR2 << index)));
3671#endif 3754#endif
3672 CY_UNLOCK(info, flags); 3755 CY_UNLOCK(info, flags);
3673 } 3756 }
3674 } else { 3757 } else {
3675 base_addr = cy_card[card].base_addr; 3758 base_addr = cy_card[card].base_addr;
3676 3759
3677 firm_id = cy_card[card].base_addr + ID_ADDRESS; 3760 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3678 if (ISZLOADED(cy_card[card])) { 3761 if (ISZLOADED(cy_card[card])) {
3679 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 3762 zfw_ctrl = cy_card[card].base_addr +
3680 board_ctrl = &zfw_ctrl->board_ctrl; 3763 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3681 ch_ctrl = zfw_ctrl->ch_ctrl; 3764 board_ctrl = &zfw_ctrl->board_ctrl;
3682 3765 ch_ctrl = zfw_ctrl->ch_ctrl;
3683 if (set & TIOCM_RTS){ 3766
3684 CY_LOCK(info, flags); 3767 if (set & TIOCM_RTS) {
3685 cy_writel(&ch_ctrl[channel].rs_control, 3768 CY_LOCK(info, flags);
3686 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS); 3769 cy_writel(&ch_ctrl[channel].rs_control,
3687 CY_UNLOCK(info, flags); 3770 cy_readl(&ch_ctrl[channel].
3688 } 3771 rs_control) | C_RS_RTS);
3689 if (clear & TIOCM_RTS) { 3772 CY_UNLOCK(info, flags);
3690 CY_LOCK(info, flags); 3773 }
3691 cy_writel(&ch_ctrl[channel].rs_control, 3774 if (clear & TIOCM_RTS) {
3692 cy_readl(&ch_ctrl[channel].rs_control) & ~C_RS_RTS); 3775 CY_LOCK(info, flags);
3693 CY_UNLOCK(info, flags); 3776 cy_writel(&ch_ctrl[channel].rs_control,
3694 } 3777 cy_readl(&ch_ctrl[channel].
3695 if (set & TIOCM_DTR){ 3778 rs_control) & ~C_RS_RTS);
3696 CY_LOCK(info, flags); 3779 CY_UNLOCK(info, flags);
3697 cy_writel(&ch_ctrl[channel].rs_control, 3780 }
3698 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_DTR); 3781 if (set & TIOCM_DTR) {
3782 CY_LOCK(info, flags);
3783 cy_writel(&ch_ctrl[channel].rs_control,
3784 cy_readl(&ch_ctrl[channel].
3785 rs_control) | C_RS_DTR);
3699#ifdef CY_DEBUG_DTR 3786#ifdef CY_DEBUG_DTR
3700 printk("cyc:set_modem_info raising Z DTR\n"); 3787 printk("cyc:set_modem_info raising Z DTR\n");
3701#endif 3788#endif
3702 CY_UNLOCK(info, flags); 3789 CY_UNLOCK(info, flags);
3703 } 3790 }
3704 if (clear & TIOCM_DTR) { 3791 if (clear & TIOCM_DTR) {
3705 CY_LOCK(info, flags); 3792 CY_LOCK(info, flags);
3706 cy_writel(&ch_ctrl[channel].rs_control, 3793 cy_writel(&ch_ctrl[channel].rs_control,
3707 cy_readl(&ch_ctrl[channel].rs_control) & ~C_RS_DTR); 3794 cy_readl(&ch_ctrl[channel].
3795 rs_control) & ~C_RS_DTR);
3708#ifdef CY_DEBUG_DTR 3796#ifdef CY_DEBUG_DTR
3709 printk("cyc:set_modem_info clearing Z DTR\n"); 3797 printk("cyc:set_modem_info clearing Z DTR\n");
3710#endif 3798#endif
3711 CY_UNLOCK(info, flags); 3799 CY_UNLOCK(info, flags);
3712 } 3800 }
3713 }else{ 3801 } else {
3714 return -ENODEV; 3802 return -ENODEV;
3715 } 3803 }
3716 CY_LOCK(info, flags); 3804 CY_LOCK(info, flags);
3717 retval = cyz_issue_cmd(&cy_card[info->card], 3805 retval = cyz_issue_cmd(&cy_card[info->card],
3718 channel, C_CM_IOCTLM,0L); 3806 channel, C_CM_IOCTLM, 0L);
3719 if (retval != 0){ 3807 if (retval != 0) {
3720 printk("cyc:set_modem_info retval on ttyC%d was %x\n", 3808 printk("cyc:set_modem_info retval on ttyC%d was %x\n",
3721 info->line, retval); 3809 info->line, retval);
3810 }
3811 CY_UNLOCK(info, flags);
3722 } 3812 }
3723 CY_UNLOCK(info, flags); 3813 return 0;
3724 } 3814} /* cy_tiocmset */
3725 return 0;
3726} /* cy_tiocmset */
3727 3815
3728/* 3816/*
3729 * cy_break() --- routine which turns the break handling on or off 3817 * cy_break() --- routine which turns the break handling on or off
3730 */ 3818 */
3731static void 3819static void cy_break(struct tty_struct *tty, int break_state)
3732cy_break(struct tty_struct *tty, int break_state)
3733{ 3820{
3734 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 3821 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3735 unsigned long flags; 3822 unsigned long flags;
3736 3823
3737 if (serial_paranoia_check(info, tty->name, "cy_break")) 3824 if (serial_paranoia_check(info, tty->name, "cy_break"))
3738 return; 3825 return;
3739 3826
3740 CY_LOCK(info, flags); 3827 CY_LOCK(info, flags);
3741 if (!IS_CYC_Z(cy_card[info->card])) { 3828 if (!IS_CYC_Z(cy_card[info->card])) {
3742 /* Let the transmit ISR take care of this (since it 3829 /* Let the transmit ISR take care of this (since it
3743 requires stuffing characters into the output stream). 3830 requires stuffing characters into the output stream).
3744 */ 3831 */
3745 if (break_state == -1) { 3832 if (break_state == -1) {
3746 if (!info->breakon) { 3833 if (!info->breakon) {
3747 info->breakon = 1; 3834 info->breakon = 1;
3748 if (!info->xmit_cnt) { 3835 if (!info->xmit_cnt) {
3749 CY_UNLOCK(info, flags); 3836 CY_UNLOCK(info, flags);
3750 start_xmit(info); 3837 start_xmit(info);
3751 CY_LOCK(info, flags); 3838 CY_LOCK(info, flags);
3839 }
3840 }
3841 } else {
3842 if (!info->breakoff) {
3843 info->breakoff = 1;
3844 if (!info->xmit_cnt) {
3845 CY_UNLOCK(info, flags);
3846 start_xmit(info);
3847 CY_LOCK(info, flags);
3848 }
3849 }
3752 } 3850 }
3753 }
3754 } else { 3851 } else {
3755 if (!info->breakoff) { 3852 int retval;
3756 info->breakoff = 1; 3853
3757 if (!info->xmit_cnt) { 3854 if (break_state == -1) {
3758 CY_UNLOCK(info, flags); 3855 retval = cyz_issue_cmd(&cy_card[info->card],
3759 start_xmit(info); 3856 info->line - cy_card[info->card].first_line,
3760 CY_LOCK(info, flags); 3857 C_CM_SET_BREAK, 0L);
3858 if (retval != 0) {
3859 printk("cyc:cy_break (set) retval on ttyC%d "
3860 "was %x\n", info->line, retval);
3861 }
3862 } else {
3863 retval = cyz_issue_cmd(&cy_card[info->card],
3864 info->line - cy_card[info->card].first_line,
3865 C_CM_CLR_BREAK, 0L);
3866 if (retval != 0) {
3867 printk("cyc:cy_break (clr) retval on ttyC%d "
3868 "was %x\n", info->line, retval);
3869 }
3761 } 3870 }
3762 }
3763 }
3764 } else {
3765 int retval;
3766
3767 if (break_state == -1) {
3768 retval = cyz_issue_cmd(&cy_card[info->card],
3769 (info->line) - (cy_card[info->card].first_line),
3770 C_CM_SET_BREAK, 0L);
3771 if (retval != 0) {
3772 printk("cyc:cy_break (set) retval on ttyC%d was %x\n",
3773 info->line, retval);
3774 }
3775 } else {
3776 retval = cyz_issue_cmd(&cy_card[info->card],
3777 (info->line) - (cy_card[info->card].first_line),
3778 C_CM_CLR_BREAK, 0L);
3779 if (retval != 0) {
3780 printk("cyc:cy_break (clr) retval on ttyC%d was %x\n",
3781 info->line, retval);
3782 }
3783 } 3871 }
3784 } 3872 CY_UNLOCK(info, flags);
3785 CY_UNLOCK(info, flags); 3873} /* cy_break */
3786} /* cy_break */
3787 3874
3788static int 3875static int
3789get_mon_info(struct cyclades_port * info, struct cyclades_monitor __user * mon) 3876get_mon_info(struct cyclades_port *info, struct cyclades_monitor __user * mon)
3790{ 3877{
3791 3878
3792 if(copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor))) 3879 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
3793 return -EFAULT; 3880 return -EFAULT;
3794 info->mon.int_count = 0; 3881 info->mon.int_count = 0;
3795 info->mon.char_count = 0; 3882 info->mon.char_count = 0;
3796 info->mon.char_max = 0; 3883 info->mon.char_max = 0;
3797 info->mon.char_last = 0; 3884 info->mon.char_last = 0;
3798 return 0; 3885 return 0;
3799}/* get_mon_info */ 3886} /* get_mon_info */
3800
3801 3887
3802static int 3888static int set_threshold(struct cyclades_port *info, unsigned long value)
3803set_threshold(struct cyclades_port * info, unsigned long value)
3804{ 3889{
3805 void __iomem *base_addr; 3890 void __iomem *base_addr;
3806 int card,channel,chip,index; 3891 int card, channel, chip, index;
3807 unsigned long flags; 3892 unsigned long flags;
3808
3809 card = info->card;
3810 channel = info->line - cy_card[card].first_line;
3811 if (!IS_CYC_Z(cy_card[card])) {
3812 chip = channel>>2;
3813 channel &= 0x03;
3814 index = cy_card[card].bus_index;
3815 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3816
3817 info->cor3 &= ~CyREC_FIFO;
3818 info->cor3 |= value & CyREC_FIFO;
3819 3893
3820 CY_LOCK(info, flags); 3894 card = info->card;
3821 cy_writeb(base_addr+(CyCOR3<<index), info->cor3); 3895 channel = info->line - cy_card[card].first_line;
3822 cyy_issue_cmd(base_addr,CyCOR_CHANGE|CyCOR3ch,index); 3896 if (!IS_CYC_Z(cy_card[card])) {
3823 CY_UNLOCK(info, flags); 3897 chip = channel >> 2;
3824 } else { 3898 channel &= 0x03;
3825 // Nothing to do! 3899 index = cy_card[card].bus_index;
3826 } 3900 base_addr =
3827 return 0; 3901 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3828}/* set_threshold */
3829 3902
3903 info->cor3 &= ~CyREC_FIFO;
3904 info->cor3 |= value & CyREC_FIFO;
3830 3905
3831static int 3906 CY_LOCK(info, flags);
3832get_threshold(struct cyclades_port * info, unsigned long __user *value) 3907 cy_writeb(base_addr + (CyCOR3 << index), info->cor3);
3833{ 3908 cyy_issue_cmd(base_addr, CyCOR_CHANGE | CyCOR3ch, index);
3834 void __iomem *base_addr; 3909 CY_UNLOCK(info, flags);
3835 int card,channel,chip,index; 3910 } else {
3836 unsigned long tmp; 3911 /* Nothing to do! */
3837 3912 }
3838 card = info->card;
3839 channel = info->line - cy_card[card].first_line;
3840 if (!IS_CYC_Z(cy_card[card])) {
3841 chip = channel>>2;
3842 channel &= 0x03;
3843 index = cy_card[card].bus_index;
3844 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3845
3846 tmp = cy_readb(base_addr+(CyCOR3<<index)) & CyREC_FIFO;
3847 return put_user(tmp,value);
3848 } else {
3849 // Nothing to do!
3850 return 0; 3913 return 0;
3851 } 3914} /* set_threshold */
3852}/* get_threshold */
3853
3854 3915
3855static int 3916static int
3856set_default_threshold(struct cyclades_port * info, unsigned long value) 3917get_threshold(struct cyclades_port *info, unsigned long __user * value)
3857{ 3918{
3858 info->default_threshold = value & 0x0f; 3919 void __iomem *base_addr;
3859 return 0; 3920 int card, channel, chip, index;
3860}/* set_default_threshold */ 3921 unsigned long tmp;
3861 3922
3923 card = info->card;
3924 channel = info->line - cy_card[card].first_line;
3925 if (!IS_CYC_Z(cy_card[card])) {
3926 chip = channel >> 2;
3927 channel &= 0x03;
3928 index = cy_card[card].bus_index;
3929 base_addr =
3930 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3931
3932 tmp = cy_readb(base_addr + (CyCOR3 << index)) & CyREC_FIFO;
3933 return put_user(tmp, value);
3934 } else {
3935 /* Nothing to do! */
3936 return 0;
3937 }
3938} /* get_threshold */
3862 3939
3863static int 3940static int
3864get_default_threshold(struct cyclades_port * info, unsigned long __user *value) 3941set_default_threshold(struct cyclades_port *info, unsigned long value)
3865{ 3942{
3866 return put_user(info->default_threshold,value); 3943 info->default_threshold = value & 0x0f;
3867}/* get_default_threshold */ 3944 return 0;
3868 3945} /* set_default_threshold */
3869 3946
3870static int 3947static int
3871set_timeout(struct cyclades_port * info, unsigned long value) 3948get_default_threshold(struct cyclades_port *info, unsigned long __user * value)
3872{ 3949{
3873 void __iomem *base_addr; 3950 return put_user(info->default_threshold, value);
3874 int card,channel,chip,index; 3951} /* get_default_threshold */
3875 unsigned long flags;
3876
3877 card = info->card;
3878 channel = info->line - cy_card[card].first_line;
3879 if (!IS_CYC_Z(cy_card[card])) {
3880 chip = channel>>2;
3881 channel &= 0x03;
3882 index = cy_card[card].bus_index;
3883 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3884 3952
3885 CY_LOCK(info, flags); 3953static int set_timeout(struct cyclades_port *info, unsigned long value)
3886 cy_writeb(base_addr+(CyRTPR<<index), value & 0xff); 3954{
3887 CY_UNLOCK(info, flags); 3955 void __iomem *base_addr;
3888 } else { 3956 int card, channel, chip, index;
3889 // Nothing to do! 3957 unsigned long flags;
3890 }
3891 return 0;
3892}/* set_timeout */
3893 3958
3959 card = info->card;
3960 channel = info->line - cy_card[card].first_line;
3961 if (!IS_CYC_Z(cy_card[card])) {
3962 chip = channel >> 2;
3963 channel &= 0x03;
3964 index = cy_card[card].bus_index;
3965 base_addr =
3966 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3894 3967
3895static int 3968 CY_LOCK(info, flags);
3896get_timeout(struct cyclades_port * info, unsigned long __user *value) 3969 cy_writeb(base_addr + (CyRTPR << index), value & 0xff);
3897{ 3970 CY_UNLOCK(info, flags);
3898 void __iomem *base_addr; 3971 } else {
3899 int card,channel,chip,index; 3972 /* Nothing to do! */
3900 unsigned long tmp; 3973 }
3901
3902 card = info->card;
3903 channel = info->line - cy_card[card].first_line;
3904 if (!IS_CYC_Z(cy_card[card])) {
3905 chip = channel>>2;
3906 channel &= 0x03;
3907 index = cy_card[card].bus_index;
3908 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3909
3910 tmp = cy_readb(base_addr+(CyRTPR<<index));
3911 return put_user(tmp,value);
3912 } else {
3913 // Nothing to do!
3914 return 0; 3974 return 0;
3915 } 3975} /* set_timeout */
3916}/* get_timeout */
3917
3918 3976
3919static int 3977static int get_timeout(struct cyclades_port *info, unsigned long __user * value)
3920set_default_timeout(struct cyclades_port * info, unsigned long value)
3921{ 3978{
3922 info->default_timeout = value & 0xff; 3979 void __iomem *base_addr;
3923 return 0; 3980 int card, channel, chip, index;
3924}/* set_default_timeout */ 3981 unsigned long tmp;
3925 3982
3983 card = info->card;
3984 channel = info->line - cy_card[card].first_line;
3985 if (!IS_CYC_Z(cy_card[card])) {
3986 chip = channel >> 2;
3987 channel &= 0x03;
3988 index = cy_card[card].bus_index;
3989 base_addr =
3990 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3991
3992 tmp = cy_readb(base_addr + (CyRTPR << index));
3993 return put_user(tmp, value);
3994 } else {
3995 /* Nothing to do! */
3996 return 0;
3997 }
3998} /* get_timeout */
3999
4000static int set_default_timeout(struct cyclades_port *info, unsigned long value)
4001{
4002 info->default_timeout = value & 0xff;
4003 return 0;
4004} /* set_default_timeout */
3926 4005
3927static int 4006static int
3928get_default_timeout(struct cyclades_port * info, unsigned long __user *value) 4007get_default_timeout(struct cyclades_port *info, unsigned long __user * value)
3929{ 4008{
3930 return put_user(info->default_timeout,value); 4009 return put_user(info->default_timeout, value);
3931}/* get_default_timeout */ 4010} /* get_default_timeout */
3932 4011
3933/* 4012/*
3934 * This routine allows the tty driver to implement device- 4013 * This routine allows the tty driver to implement device-
@@ -3936,184 +4015,193 @@ get_default_timeout(struct cyclades_port * info, unsigned long __user *value)
3936 * not recognized by the driver, it should return ENOIOCTLCMD. 4015 * not recognized by the driver, it should return ENOIOCTLCMD.
3937 */ 4016 */
3938static int 4017static int
3939cy_ioctl(struct tty_struct *tty, struct file * file, 4018cy_ioctl(struct tty_struct *tty, struct file *file,
3940 unsigned int cmd, unsigned long arg) 4019 unsigned int cmd, unsigned long arg)
3941{ 4020{
3942 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 4021 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3943 struct cyclades_icount cprev, cnow; /* kernel counter temps */ 4022 struct cyclades_icount cprev, cnow; /* kernel counter temps */
3944 struct serial_icounter_struct __user *p_cuser; /* user space */ 4023 struct serial_icounter_struct __user *p_cuser; /* user space */
3945 int ret_val = 0; 4024 int ret_val = 0;
3946 unsigned long flags; 4025 unsigned long flags;
3947 void __user *argp = (void __user *)arg; 4026 void __user *argp = (void __user *)arg;
3948 4027
3949 if (serial_paranoia_check(info, tty->name, "cy_ioctl")) 4028 if (serial_paranoia_check(info, tty->name, "cy_ioctl"))
3950 return -ENODEV; 4029 return -ENODEV;
3951 4030
3952#ifdef CY_DEBUG_OTHER 4031#ifdef CY_DEBUG_OTHER
3953 printk("cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n", 4032 printk("cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n", info->line, cmd, arg); /* */
3954 info->line, cmd, arg); /* */
3955#endif 4033#endif
3956 4034
3957 switch (cmd) { 4035 switch (cmd) {
3958 case CYGETMON: 4036 case CYGETMON:
3959 ret_val = get_mon_info(info, argp); 4037 ret_val = get_mon_info(info, argp);
3960 break; 4038 break;
3961 case CYGETTHRESH: 4039 case CYGETTHRESH:
3962 ret_val = get_threshold(info, argp); 4040 ret_val = get_threshold(info, argp);
3963 break; 4041 break;
3964 case CYSETTHRESH: 4042 case CYSETTHRESH:
3965 ret_val = set_threshold(info, arg); 4043 ret_val = set_threshold(info, arg);
3966 break; 4044 break;
3967 case CYGETDEFTHRESH: 4045 case CYGETDEFTHRESH:
3968 ret_val = get_default_threshold(info, argp); 4046 ret_val = get_default_threshold(info, argp);
3969 break; 4047 break;
3970 case CYSETDEFTHRESH: 4048 case CYSETDEFTHRESH:
3971 ret_val = set_default_threshold(info, arg); 4049 ret_val = set_default_threshold(info, arg);
3972 break; 4050 break;
3973 case CYGETTIMEOUT: 4051 case CYGETTIMEOUT:
3974 ret_val = get_timeout(info, argp); 4052 ret_val = get_timeout(info, argp);
3975 break; 4053 break;
3976 case CYSETTIMEOUT: 4054 case CYSETTIMEOUT:
3977 ret_val = set_timeout(info, arg); 4055 ret_val = set_timeout(info, arg);
3978 break; 4056 break;
3979 case CYGETDEFTIMEOUT: 4057 case CYGETDEFTIMEOUT:
3980 ret_val = get_default_timeout(info, argp); 4058 ret_val = get_default_timeout(info, argp);
3981 break; 4059 break;
3982 case CYSETDEFTIMEOUT: 4060 case CYSETDEFTIMEOUT:
3983 ret_val = set_default_timeout(info, arg); 4061 ret_val = set_default_timeout(info, arg);
3984 break; 4062 break;
3985 case CYSETRFLOW: 4063 case CYSETRFLOW:
3986 info->rflow = (int)arg; 4064 info->rflow = (int)arg;
3987 ret_val = 0; 4065 ret_val = 0;
3988 break; 4066 break;
3989 case CYGETRFLOW: 4067 case CYGETRFLOW:
3990 ret_val = info->rflow; 4068 ret_val = info->rflow;
3991 break; 4069 break;
3992 case CYSETRTSDTR_INV: 4070 case CYSETRTSDTR_INV:
3993 info->rtsdtr_inv = (int)arg; 4071 info->rtsdtr_inv = (int)arg;
3994 ret_val = 0; 4072 ret_val = 0;
3995 break; 4073 break;
3996 case CYGETRTSDTR_INV: 4074 case CYGETRTSDTR_INV:
3997 ret_val = info->rtsdtr_inv; 4075 ret_val = info->rtsdtr_inv;
3998 break; 4076 break;
3999 case CYGETCARDINFO: 4077 case CYGETCARDINFO:
4000 if (copy_to_user(argp, &cy_card[info->card], 4078 if (copy_to_user(argp, &cy_card[info->card],
4001 sizeof (struct cyclades_card))) { 4079 sizeof(struct cyclades_card))) {
4002 ret_val = -EFAULT; 4080 ret_val = -EFAULT;
4081 break;
4082 }
4083 ret_val = 0;
4003 break; 4084 break;
4004 }
4005 ret_val = 0;
4006 break;
4007 case CYGETCD1400VER: 4085 case CYGETCD1400VER:
4008 ret_val = info->chip_rev; 4086 ret_val = info->chip_rev;
4009 break; 4087 break;
4010#ifndef CONFIG_CYZ_INTR 4088#ifndef CONFIG_CYZ_INTR
4011 case CYZSETPOLLCYCLE: 4089 case CYZSETPOLLCYCLE:
4012 cyz_polling_cycle = (arg * HZ) / 1000; 4090 cyz_polling_cycle = (arg * HZ) / 1000;
4013 ret_val = 0; 4091 ret_val = 0;
4014 break; 4092 break;
4015 case CYZGETPOLLCYCLE: 4093 case CYZGETPOLLCYCLE:
4016 ret_val = (cyz_polling_cycle * 1000) / HZ; 4094 ret_val = (cyz_polling_cycle * 1000) / HZ;
4017 break; 4095 break;
4018#endif /* CONFIG_CYZ_INTR */ 4096#endif /* CONFIG_CYZ_INTR */
4019 case CYSETWAIT: 4097 case CYSETWAIT:
4020 info->closing_wait = (unsigned short)arg * HZ/100; 4098 info->closing_wait = (unsigned short)arg *HZ / 100;
4021 ret_val = 0; 4099 ret_val = 0;
4022 break; 4100 break;
4023 case CYGETWAIT: 4101 case CYGETWAIT:
4024 ret_val = info->closing_wait / (HZ/100); 4102 ret_val = info->closing_wait / (HZ / 100);
4025 break; 4103 break;
4026 case TIOCGSERIAL: 4104 case TIOCGSERIAL:
4027 ret_val = get_serial_info(info, argp); 4105 ret_val = get_serial_info(info, argp);
4028 break; 4106 break;
4029 case TIOCSSERIAL: 4107 case TIOCSSERIAL:
4030 ret_val = set_serial_info(info, argp); 4108 ret_val = set_serial_info(info, argp);
4031 break; 4109 break;
4032 case TIOCSERGETLSR: /* Get line status register */ 4110 case TIOCSERGETLSR: /* Get line status register */
4033 ret_val = get_lsr_info(info, argp); 4111 ret_val = get_lsr_info(info, argp);
4034 break; 4112 break;
4035 /* 4113 /*
4036 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change 4114 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
4037 * - mask passed in arg for lines of interest 4115 * - mask passed in arg for lines of interest
4038 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking) 4116 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
4039 * Caller should use TIOCGICOUNT to see which one it was 4117 * Caller should use TIOCGICOUNT to see which one it was
4040 */ 4118 */
4041 case TIOCMIWAIT: 4119 case TIOCMIWAIT:
4042 CY_LOCK(info, flags);
4043 /* note the counters on entry */
4044 cprev = info->icount;
4045 CY_UNLOCK(info, flags);
4046 while (1) {
4047 interruptible_sleep_on(&info->delta_msr_wait);
4048 /* see if a signal did it */
4049 if (signal_pending(current)) {
4050 return -ERESTARTSYS;
4051 }
4052
4053 CY_LOCK(info, flags); 4120 CY_LOCK(info, flags);
4054 cnow = info->icount; /* atomic copy */ 4121 /* note the counters on entry */
4122 cprev = info->icount;
4055 CY_UNLOCK(info, flags); 4123 CY_UNLOCK(info, flags);
4124 while (1) {
4125 interruptible_sleep_on(&info->delta_msr_wait);
4126 /* see if a signal did it */
4127 if (signal_pending(current)) {
4128 return -ERESTARTSYS;
4129 }
4056 4130
4057 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && 4131 CY_LOCK(info, flags);
4058 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) { 4132 cnow = info->icount; /* atomic copy */
4059 return -EIO; /* no change => error */ 4133 CY_UNLOCK(info, flags);
4060 }
4061 if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
4062 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
4063 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
4064 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
4065 return 0;
4066 }
4067 cprev = cnow;
4068 }
4069 /* NOTREACHED */
4070 4134
4071 /* 4135 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
4072 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) 4136 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
4073 * Return: write counters to the user passed counter struct 4137 return -EIO; /* no change => error */
4074 * NB: both 1->0 and 0->1 transitions are counted except for 4138 }
4075 * RI where only 0->1 is counted. 4139 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
4076 */ 4140 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
4141 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
4142 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
4143 return 0;
4144 }
4145 cprev = cnow;
4146 }
4147 /* NOTREACHED */
4148
4149 /*
4150 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
4151 * Return: write counters to the user passed counter struct
4152 * NB: both 1->0 and 0->1 transitions are counted except for
4153 * RI where only 0->1 is counted.
4154 */
4077 case TIOCGICOUNT: 4155 case TIOCGICOUNT:
4078 CY_LOCK(info, flags); 4156 CY_LOCK(info, flags);
4079 cnow = info->icount; 4157 cnow = info->icount;
4080 CY_UNLOCK(info, flags); 4158 CY_UNLOCK(info, flags);
4081 p_cuser = argp; 4159 p_cuser = argp;
4082 ret_val = put_user(cnow.cts, &p_cuser->cts); 4160 ret_val = put_user(cnow.cts, &p_cuser->cts);
4083 if (ret_val) return ret_val; 4161 if (ret_val)
4084 ret_val = put_user(cnow.dsr, &p_cuser->dsr); 4162 return ret_val;
4085 if (ret_val) return ret_val; 4163 ret_val = put_user(cnow.dsr, &p_cuser->dsr);
4086 ret_val = put_user(cnow.rng, &p_cuser->rng); 4164 if (ret_val)
4087 if (ret_val) return ret_val; 4165 return ret_val;
4088 ret_val = put_user(cnow.dcd, &p_cuser->dcd); 4166 ret_val = put_user(cnow.rng, &p_cuser->rng);
4089 if (ret_val) return ret_val; 4167 if (ret_val)
4090 ret_val = put_user(cnow.rx, &p_cuser->rx); 4168 return ret_val;
4091 if (ret_val) return ret_val; 4169 ret_val = put_user(cnow.dcd, &p_cuser->dcd);
4092 ret_val = put_user(cnow.tx, &p_cuser->tx); 4170 if (ret_val)
4093 if (ret_val) return ret_val; 4171 return ret_val;
4094 ret_val = put_user(cnow.frame, &p_cuser->frame); 4172 ret_val = put_user(cnow.rx, &p_cuser->rx);
4095 if (ret_val) return ret_val; 4173 if (ret_val)
4096 ret_val = put_user(cnow.overrun, &p_cuser->overrun); 4174 return ret_val;
4097 if (ret_val) return ret_val; 4175 ret_val = put_user(cnow.tx, &p_cuser->tx);
4098 ret_val = put_user(cnow.parity, &p_cuser->parity); 4176 if (ret_val)
4099 if (ret_val) return ret_val; 4177 return ret_val;
4100 ret_val = put_user(cnow.brk, &p_cuser->brk); 4178 ret_val = put_user(cnow.frame, &p_cuser->frame);
4101 if (ret_val) return ret_val; 4179 if (ret_val)
4102 ret_val = put_user(cnow.buf_overrun, &p_cuser->buf_overrun); 4180 return ret_val;
4103 if (ret_val) return ret_val; 4181 ret_val = put_user(cnow.overrun, &p_cuser->overrun);
4104 ret_val = 0; 4182 if (ret_val)
4105 break; 4183 return ret_val;
4106 default: 4184 ret_val = put_user(cnow.parity, &p_cuser->parity);
4107 ret_val = -ENOIOCTLCMD; 4185 if (ret_val)
4108 } 4186 return ret_val;
4187 ret_val = put_user(cnow.brk, &p_cuser->brk);
4188 if (ret_val)
4189 return ret_val;
4190 ret_val = put_user(cnow.buf_overrun, &p_cuser->buf_overrun);
4191 if (ret_val)
4192 return ret_val;
4193 ret_val = 0;
4194 break;
4195 default:
4196 ret_val = -ENOIOCTLCMD;
4197 }
4109 4198
4110#ifdef CY_DEBUG_OTHER 4199#ifdef CY_DEBUG_OTHER
4111 printk(" cyc:cy_ioctl done\n"); 4200 printk(" cyc:cy_ioctl done\n");
4112#endif 4201#endif
4113 4202
4114 return ret_val; 4203 return ret_val;
4115} /* cy_ioctl */ 4204} /* cy_ioctl */
4116
4117 4205
4118/* 4206/*
4119 * This routine allows the tty driver to be notified when 4207 * This routine allows the tty driver to be notified when
@@ -4121,66 +4209,64 @@ cy_ioctl(struct tty_struct *tty, struct file * file,
4121 * well-designed tty driver should be prepared to accept the case 4209 * well-designed tty driver should be prepared to accept the case
4122 * where old == NULL, and try to do something rational. 4210 * where old == NULL, and try to do something rational.
4123 */ 4211 */
4124static void 4212static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
4125cy_set_termios(struct tty_struct *tty, struct termios * old_termios)
4126{ 4213{
4127 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4214 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4128 4215
4129#ifdef CY_DEBUG_OTHER 4216#ifdef CY_DEBUG_OTHER
4130 printk("cyc:cy_set_termios ttyC%d\n", info->line); 4217 printk("cyc:cy_set_termios ttyC%d\n", info->line);
4131#endif 4218#endif
4132 4219
4133 if ((tty->termios->c_cflag == old_termios->c_cflag) && 4220 if (tty->termios->c_cflag == old_termios->c_cflag &&
4134 ((tty->termios->c_iflag & (IXON|IXANY)) == 4221 (tty->termios->c_iflag & (IXON | IXANY)) ==
4135 (old_termios->c_iflag & (IXON|IXANY)))) 4222 (old_termios->c_iflag & (IXON | IXANY)))
4136 return; 4223 return;
4137 set_line_char(info); 4224 set_line_char(info);
4138 4225
4139 if ((old_termios->c_cflag & CRTSCTS) && 4226 if ((old_termios->c_cflag & CRTSCTS) &&
4140 !(tty->termios->c_cflag & CRTSCTS)) { 4227 !(tty->termios->c_cflag & CRTSCTS)) {
4141 tty->hw_stopped = 0; 4228 tty->hw_stopped = 0;
4142 cy_start(tty); 4229 cy_start(tty);
4143 } 4230 }
4144#if 0 4231#if 0
4145 /* 4232 /*
4146 * No need to wake up processes in open wait, since they 4233 * No need to wake up processes in open wait, since they
4147 * sample the CLOCAL flag once, and don't recheck it. 4234 * sample the CLOCAL flag once, and don't recheck it.
4148 * XXX It's not clear whether the current behavior is correct 4235 * XXX It's not clear whether the current behavior is correct
4149 * or not. Hence, this may change..... 4236 * or not. Hence, this may change.....
4150 */ 4237 */
4151 if (!(old_termios->c_cflag & CLOCAL) && 4238 if (!(old_termios->c_cflag & CLOCAL) &&
4152 (tty->termios->c_cflag & CLOCAL)) 4239 (tty->termios->c_cflag & CLOCAL))
4153 wake_up_interruptible(&info->open_wait); 4240 wake_up_interruptible(&info->open_wait);
4154#endif 4241#endif
4155 4242} /* cy_set_termios */
4156 return;
4157} /* cy_set_termios */
4158 4243
4159/* This function is used to send a high-priority XON/XOFF character to 4244/* This function is used to send a high-priority XON/XOFF character to
4160 the device. 4245 the device.
4161*/ 4246*/
4162static void 4247static void cy_send_xchar(struct tty_struct *tty, char ch)
4163cy_send_xchar (struct tty_struct *tty, char ch)
4164{ 4248{
4165 struct cyclades_port *info = (struct cyclades_port *) tty->driver_data; 4249 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4166 int card, channel; 4250 int card, channel;
4167 4251
4168 if (serial_paranoia_check (info, tty->name, "cy_send_xchar")) 4252 if (serial_paranoia_check(info, tty->name, "cy_send_xchar"))
4169 return; 4253 return;
4170 4254
4171 info->x_char = ch; 4255 info->x_char = ch;
4172 4256
4173 if (ch) 4257 if (ch)
4174 cy_start (tty); 4258 cy_start(tty);
4175 4259
4176 card = info->card; 4260 card = info->card;
4177 channel = info->line - cy_card[card].first_line; 4261 channel = info->line - cy_card[card].first_line;
4178 4262
4179 if (IS_CYC_Z (cy_card[card])) { 4263 if (IS_CYC_Z(cy_card[card])) {
4180 if (ch == STOP_CHAR (tty)) 4264 if (ch == STOP_CHAR(tty))
4181 cyz_issue_cmd (&cy_card[card], channel, C_CM_SENDXOFF, 0L); 4265 cyz_issue_cmd(&cy_card[card], channel, C_CM_SENDXOFF,
4182 else if (ch == START_CHAR (tty)) 4266 0L);
4183 cyz_issue_cmd (&cy_card[card], channel, C_CM_SENDXON, 0L); 4267 else if (ch == START_CHAR(tty))
4268 cyz_issue_cmd(&cy_card[card], channel, C_CM_SENDXON,
4269 0L);
4184 } 4270 }
4185} 4271}
4186 4272
@@ -4188,260 +4274,248 @@ cy_send_xchar (struct tty_struct *tty, char ch)
4188 that incoming characters should be throttled because the input 4274 that incoming characters should be throttled because the input
4189 buffers are close to full. 4275 buffers are close to full.
4190 */ 4276 */
4191static void 4277static void cy_throttle(struct tty_struct *tty)
4192cy_throttle(struct tty_struct * tty)
4193{ 4278{
4194 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4279 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4195 unsigned long flags; 4280 unsigned long flags;
4196 void __iomem *base_addr; 4281 void __iomem *base_addr;
4197 int card,chip,channel,index; 4282 int card, chip, channel, index;
4198 4283
4199#ifdef CY_DEBUG_THROTTLE 4284#ifdef CY_DEBUG_THROTTLE
4200 char buf[64]; 4285 char buf[64];
4201 4286
4202 printk("cyc:throttle %s: %d....ttyC%d\n", 4287 printk("cyc:throttle %s: %d....ttyC%d\n", tty_name(tty, buf),
4203 tty_name(tty, buf), 4288 tty->ldisc.chars_in_buffer(tty), info->line);
4204 tty->ldisc.chars_in_buffer(tty), info->line);
4205#endif 4289#endif
4206 4290
4207 if (serial_paranoia_check(info, tty->name, "cy_throttle")){ 4291 if (serial_paranoia_check(info, tty->name, "cy_throttle")) {
4208 return; 4292 return;
4209 } 4293 }
4210 4294
4211 card = info->card; 4295 card = info->card;
4212
4213 if (I_IXOFF(tty)) {
4214 if (!IS_CYC_Z (cy_card[card]))
4215 cy_send_xchar (tty, STOP_CHAR (tty));
4216 else
4217 info->throttle = 1;
4218 }
4219
4220 if (tty->termios->c_cflag & CRTSCTS) {
4221 channel = info->line - cy_card[card].first_line;
4222 if (!IS_CYC_Z(cy_card[card])) {
4223 chip = channel>>2;
4224 channel &= 0x03;
4225 index = cy_card[card].bus_index;
4226 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
4227
4228 CY_LOCK(info, flags);
4229 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
4230 if (info->rtsdtr_inv) {
4231 cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR);
4232 } else {
4233 cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS);
4234 }
4235 CY_UNLOCK(info, flags);
4236 } else {
4237 info->throttle = 1;
4238 }
4239 }
4240 4296
4241 return; 4297 if (I_IXOFF(tty)) {
4242} /* cy_throttle */ 4298 if (!IS_CYC_Z(cy_card[card]))
4299 cy_send_xchar(tty, STOP_CHAR(tty));
4300 else
4301 info->throttle = 1;
4302 }
4243 4303
4304 if (tty->termios->c_cflag & CRTSCTS) {
4305 channel = info->line - cy_card[card].first_line;
4306 if (!IS_CYC_Z(cy_card[card])) {
4307 chip = channel >> 2;
4308 channel &= 0x03;
4309 index = cy_card[card].bus_index;
4310 base_addr = cy_card[card].base_addr +
4311 (cy_chip_offset[chip] << index);
4312
4313 CY_LOCK(info, flags);
4314 cy_writeb(base_addr + (CyCAR << index),
4315 (u_char) channel);
4316 if (info->rtsdtr_inv) {
4317 cy_writeb(base_addr + (CyMSVR2 << index),
4318 ~CyDTR);
4319 } else {
4320 cy_writeb(base_addr + (CyMSVR1 << index),
4321 ~CyRTS);
4322 }
4323 CY_UNLOCK(info, flags);
4324 } else {
4325 info->throttle = 1;
4326 }
4327 }
4328} /* cy_throttle */
4244 4329
4245/* 4330/*
4246 * This routine notifies the tty driver that it should signal 4331 * This routine notifies the tty driver that it should signal
4247 * that characters can now be sent to the tty without fear of 4332 * that characters can now be sent to the tty without fear of
4248 * overrunning the input buffers of the line disciplines. 4333 * overrunning the input buffers of the line disciplines.
4249 */ 4334 */
4250static void 4335static void cy_unthrottle(struct tty_struct *tty)
4251cy_unthrottle(struct tty_struct * tty)
4252{ 4336{
4253 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4337 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4254 unsigned long flags; 4338 unsigned long flags;
4255 void __iomem *base_addr; 4339 void __iomem *base_addr;
4256 int card,chip,channel,index; 4340 int card, chip, channel, index;
4257 4341
4258#ifdef CY_DEBUG_THROTTLE 4342#ifdef CY_DEBUG_THROTTLE
4259 char buf[64]; 4343 char buf[64];
4260
4261 printk("cyc:unthrottle %s: %d....ttyC%d\n",
4262 tty_name(tty, buf),
4263 tty->ldisc.chars_in_buffer(tty), info->line);
4264#endif
4265 4344
4266 if (serial_paranoia_check(info, tty->name, "cy_unthrottle")){ 4345 printk("cyc:unthrottle %s: %d....ttyC%d\n", tty_name(tty, buf),
4267 return; 4346 tty->ldisc.chars_in_buffer(tty), info->line);
4268 } 4347#endif
4269 4348
4270 if (I_IXOFF(tty)) { 4349 if (serial_paranoia_check(info, tty->name, "cy_unthrottle")) {
4271 if (info->x_char) 4350 return;
4272 info->x_char = 0;
4273 else
4274 cy_send_xchar (tty, START_CHAR (tty));
4275 }
4276
4277 if (tty->termios->c_cflag & CRTSCTS) {
4278 card = info->card;
4279 channel = info->line - cy_card[card].first_line;
4280 if (!IS_CYC_Z(cy_card[card])) {
4281 chip = channel>>2;
4282 channel &= 0x03;
4283 index = cy_card[card].bus_index;
4284 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
4285
4286 CY_LOCK(info, flags);
4287 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
4288 if (info->rtsdtr_inv) {
4289 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR);
4290 } else {
4291 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS);
4292 }
4293 CY_UNLOCK(info, flags);
4294 } else {
4295 info->throttle = 0;
4296 } 4351 }
4297 }
4298 4352
4299 return; 4353 if (I_IXOFF(tty)) {
4300} /* cy_unthrottle */ 4354 if (info->x_char)
4355 info->x_char = 0;
4356 else
4357 cy_send_xchar(tty, START_CHAR(tty));
4358 }
4301 4359
4360 if (tty->termios->c_cflag & CRTSCTS) {
4361 card = info->card;
4362 channel = info->line - cy_card[card].first_line;
4363 if (!IS_CYC_Z(cy_card[card])) {
4364 chip = channel >> 2;
4365 channel &= 0x03;
4366 index = cy_card[card].bus_index;
4367 base_addr = cy_card[card].base_addr +
4368 (cy_chip_offset[chip] << index);
4369
4370 CY_LOCK(info, flags);
4371 cy_writeb(base_addr + (CyCAR << index),
4372 (u_char) channel);
4373 if (info->rtsdtr_inv) {
4374 cy_writeb(base_addr + (CyMSVR2 << index),
4375 CyDTR);
4376 } else {
4377 cy_writeb(base_addr + (CyMSVR1 << index),
4378 CyRTS);
4379 }
4380 CY_UNLOCK(info, flags);
4381 } else {
4382 info->throttle = 0;
4383 }
4384 }
4385} /* cy_unthrottle */
4302 4386
4303/* cy_start and cy_stop provide software output flow control as a 4387/* cy_start and cy_stop provide software output flow control as a
4304 function of XON/XOFF, software CTS, and other such stuff. 4388 function of XON/XOFF, software CTS, and other such stuff.
4305*/ 4389*/
4306static void 4390static void cy_stop(struct tty_struct *tty)
4307cy_stop(struct tty_struct *tty)
4308{ 4391{
4309 struct cyclades_card *cinfo; 4392 struct cyclades_card *cinfo;
4310 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4393 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4311 void __iomem *base_addr; 4394 void __iomem *base_addr;
4312 int chip,channel,index; 4395 int chip, channel, index;
4313 unsigned long flags; 4396 unsigned long flags;
4314 4397
4315#ifdef CY_DEBUG_OTHER 4398#ifdef CY_DEBUG_OTHER
4316 printk("cyc:cy_stop ttyC%d\n", info->line); /* */ 4399 printk("cyc:cy_stop ttyC%d\n", info->line); /* */
4317#endif 4400#endif
4318 4401
4319 if (serial_paranoia_check(info, tty->name, "cy_stop")) 4402 if (serial_paranoia_check(info, tty->name, "cy_stop"))
4320 return; 4403 return;
4321
4322 cinfo = &cy_card[info->card];
4323 channel = info->line - cinfo->first_line;
4324 if (!IS_CYC_Z(*cinfo)) {
4325 index = cinfo->bus_index;
4326 chip = channel>>2;
4327 channel &= 0x03;
4328 base_addr = cy_card[info->card].base_addr + (cy_chip_offset[chip]<<index);
4329
4330 CY_LOCK(info, flags);
4331 cy_writeb(base_addr+(CyCAR<<index),
4332 (u_char)(channel & 0x0003)); /* index channel */
4333 cy_writeb(base_addr+(CySRER<<index),
4334 cy_readb(base_addr+(CySRER<<index)) & ~CyTxRdy);
4335 CY_UNLOCK(info, flags);
4336 } else {
4337 // Nothing to do!
4338 }
4339 4404
4340 return; 4405 cinfo = &cy_card[info->card];
4341} /* cy_stop */ 4406 channel = info->line - cinfo->first_line;
4407 if (!IS_CYC_Z(*cinfo)) {
4408 index = cinfo->bus_index;
4409 chip = channel >> 2;
4410 channel &= 0x03;
4411 base_addr = cy_card[info->card].base_addr +
4412 (cy_chip_offset[chip] << index);
4342 4413
4414 CY_LOCK(info, flags);
4415 cy_writeb(base_addr + (CyCAR << index),
4416 (u_char)(channel & 0x0003)); /* index channel */
4417 cy_writeb(base_addr + (CySRER << index),
4418 cy_readb(base_addr + (CySRER << index)) & ~CyTxRdy);
4419 CY_UNLOCK(info, flags);
4420 } else {
4421 /* Nothing to do! */
4422 }
4423} /* cy_stop */
4343 4424
4344static void 4425static void cy_start(struct tty_struct *tty)
4345cy_start(struct tty_struct *tty)
4346{ 4426{
4347 struct cyclades_card *cinfo; 4427 struct cyclades_card *cinfo;
4348 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4428 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4349 void __iomem *base_addr; 4429 void __iomem *base_addr;
4350 int chip,channel,index; 4430 int chip, channel, index;
4351 unsigned long flags; 4431 unsigned long flags;
4352 4432
4353#ifdef CY_DEBUG_OTHER 4433#ifdef CY_DEBUG_OTHER
4354 printk("cyc:cy_start ttyC%d\n", info->line); /* */ 4434 printk("cyc:cy_start ttyC%d\n", info->line); /* */
4355#endif 4435#endif
4356 4436
4357 if (serial_paranoia_check(info, tty->name, "cy_start")) 4437 if (serial_paranoia_check(info, tty->name, "cy_start"))
4358 return; 4438 return;
4359
4360 cinfo = &cy_card[info->card];
4361 channel = info->line - cinfo->first_line;
4362 index = cinfo->bus_index;
4363 if (!IS_CYC_Z(*cinfo)) {
4364 chip = channel>>2;
4365 channel &= 0x03;
4366 base_addr = cy_card[info->card].base_addr + (cy_chip_offset[chip]<<index);
4367
4368 CY_LOCK(info, flags);
4369 cy_writeb(base_addr+(CyCAR<<index),
4370 (u_char)(channel & 0x0003)); /* index channel */
4371 cy_writeb(base_addr+(CySRER<<index),
4372 cy_readb(base_addr+(CySRER<<index)) | CyTxRdy);
4373 CY_UNLOCK(info, flags);
4374 } else {
4375 // Nothing to do!
4376 }
4377 4439
4378 return; 4440 cinfo = &cy_card[info->card];
4379} /* cy_start */ 4441 channel = info->line - cinfo->first_line;
4442 index = cinfo->bus_index;
4443 if (!IS_CYC_Z(*cinfo)) {
4444 chip = channel >> 2;
4445 channel &= 0x03;
4446 base_addr = cy_card[info->card].base_addr +
4447 (cy_chip_offset[chip] << index);
4380 4448
4449 CY_LOCK(info, flags);
4450 cy_writeb(base_addr + (CyCAR << index), (u_char) (channel & 0x0003)); /* index channel */
4451 cy_writeb(base_addr + (CySRER << index),
4452 cy_readb(base_addr + (CySRER << index)) | CyTxRdy);
4453 CY_UNLOCK(info, flags);
4454 } else {
4455 /* Nothing to do! */
4456 }
4457} /* cy_start */
4381 4458
4382static void 4459static void cy_flush_buffer(struct tty_struct *tty)
4383cy_flush_buffer(struct tty_struct *tty)
4384{ 4460{
4385 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4461 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4386 int card, channel, retval; 4462 int card, channel, retval;
4387 unsigned long flags; 4463 unsigned long flags;
4388 4464
4389#ifdef CY_DEBUG_IO 4465#ifdef CY_DEBUG_IO
4390 printk("cyc:cy_flush_buffer ttyC%d\n", info->line); /* */ 4466 printk("cyc:cy_flush_buffer ttyC%d\n", info->line); /* */
4391#endif 4467#endif
4392 4468
4393 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer")) 4469 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
4394 return; 4470 return;
4395
4396 card = info->card;
4397 channel = (info->line) - (cy_card[card].first_line);
4398 4471
4399 CY_LOCK(info, flags); 4472 card = info->card;
4400 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 4473 channel = (info->line) - (cy_card[card].first_line);
4401 CY_UNLOCK(info, flags);
4402 4474
4403 if (IS_CYC_Z(cy_card[card])) { /* If it is a Z card, flush the on-board
4404 buffers as well */
4405 CY_LOCK(info, flags); 4475 CY_LOCK(info, flags);
4406 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_TX, 0L); 4476 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
4407 if (retval != 0) {
4408 printk("cyc: flush_buffer retval on ttyC%d was %x\n",
4409 info->line, retval);
4410 }
4411 CY_UNLOCK(info, flags); 4477 CY_UNLOCK(info, flags);
4412 }
4413 tty_wakeup(tty);
4414 wake_up_interruptible(&tty->write_wait);
4415} /* cy_flush_buffer */
4416 4478
4479 if (IS_CYC_Z(cy_card[card])) { /* If it is a Z card, flush the on-board
4480 buffers as well */
4481 CY_LOCK(info, flags);
4482 retval =
4483 cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_TX, 0L);
4484 if (retval != 0) {
4485 printk("cyc: flush_buffer retval on ttyC%d was %x\n",
4486 info->line, retval);
4487 }
4488 CY_UNLOCK(info, flags);
4489 }
4490 tty_wakeup(tty);
4491 wake_up_interruptible(&tty->write_wait);
4492} /* cy_flush_buffer */
4417 4493
4418/* 4494/*
4419 * cy_hangup() --- called by tty_hangup() when a hangup is signaled. 4495 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
4420 */ 4496 */
4421static void 4497static void cy_hangup(struct tty_struct *tty)
4422cy_hangup(struct tty_struct *tty)
4423{ 4498{
4424 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 4499 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4425 4500
4426#ifdef CY_DEBUG_OTHER 4501#ifdef CY_DEBUG_OTHER
4427 printk("cyc:cy_hangup ttyC%d\n", info->line); /* */ 4502 printk("cyc:cy_hangup ttyC%d\n", info->line); /* */
4428#endif 4503#endif
4429 4504
4430 if (serial_paranoia_check(info, tty->name, "cy_hangup")) 4505 if (serial_paranoia_check(info, tty->name, "cy_hangup"))
4431 return; 4506 return;
4432 4507
4433 cy_flush_buffer(tty); 4508 cy_flush_buffer(tty);
4434 shutdown(info); 4509 shutdown(info);
4435 info->event = 0; 4510 info->event = 0;
4436 info->count = 0; 4511 info->count = 0;
4437#ifdef CY_DEBUG_COUNT 4512#ifdef CY_DEBUG_COUNT
4438 printk("cyc:cy_hangup (%d): setting count to 0\n", current->pid); 4513 printk("cyc:cy_hangup (%d): setting count to 0\n", current->pid);
4439#endif 4514#endif
4440 info->tty = NULL; 4515 info->tty = NULL;
4441 info->flags &= ~ASYNC_NORMAL_ACTIVE; 4516 info->flags &= ~ASYNC_NORMAL_ACTIVE;
4442 wake_up_interruptible(&info->open_wait); 4517 wake_up_interruptible(&info->open_wait);
4443} /* cy_hangup */ 4518} /* cy_hangup */
4444
4445 4519
4446/* 4520/*
4447 * --------------------------------------------------------------------- 4521 * ---------------------------------------------------------------------
@@ -4454,82 +4528,84 @@ cy_hangup(struct tty_struct *tty)
4454/* initialize chips on Cyclom-Y card -- return number of valid 4528/* initialize chips on Cyclom-Y card -- return number of valid
4455 chips (which is number of ports/4) */ 4529 chips (which is number of ports/4) */
4456static unsigned short __init 4530static unsigned short __init
4457cyy_init_card(void __iomem *true_base_addr,int index) 4531cyy_init_card(void __iomem * true_base_addr, int index)
4458{ 4532{
4459 unsigned int chip_number; 4533 unsigned int chip_number;
4460 void __iomem *base_addr; 4534 void __iomem *base_addr;
4461 4535
4462 cy_writeb(true_base_addr+(Cy_HwReset<<index), 0); 4536 cy_writeb(true_base_addr + (Cy_HwReset << index), 0);
4463 /* Cy_HwReset is 0x1400 */ 4537 /* Cy_HwReset is 0x1400 */
4464 cy_writeb(true_base_addr+(Cy_ClrIntr<<index), 0); 4538 cy_writeb(true_base_addr + (Cy_ClrIntr << index), 0);
4465 /* Cy_ClrIntr is 0x1800 */ 4539 /* Cy_ClrIntr is 0x1800 */
4466 udelay(500L); 4540 udelay(500L);
4467 4541
4468 for(chip_number=0; chip_number<CyMAX_CHIPS_PER_CARD; chip_number++){ 4542 for (chip_number = 0; chip_number < CyMAX_CHIPS_PER_CARD; chip_number++) {
4469 base_addr = true_base_addr + (cy_chip_offset[chip_number]<<index); 4543 base_addr =
4470 mdelay(1); 4544 true_base_addr + (cy_chip_offset[chip_number] << index);
4471 if(cy_readb(base_addr+(CyCCR<<index)) != 0x00){ 4545 mdelay(1);
4472 /************* 4546 if (cy_readb(base_addr + (CyCCR << index)) != 0x00) {
4473 printk(" chip #%d at %#6lx is never idle (CCR != 0)\n", 4547 /*************
4474 chip_number, (unsigned long)base_addr); 4548 printk(" chip #%d at %#6lx is never idle (CCR != 0)\n",
4475 *************/ 4549 chip_number, (unsigned long)base_addr);
4476 return chip_number; 4550 *************/
4477 } 4551 return chip_number;
4478 4552 }
4479 cy_writeb(base_addr+(CyGFRCR<<index), 0); 4553
4480 udelay(10L); 4554 cy_writeb(base_addr + (CyGFRCR << index), 0);
4481 4555 udelay(10L);
4482 /* The Cyclom-16Y does not decode address bit 9 and therefore 4556
4483 cannot distinguish between references to chip 0 and a non- 4557 /* The Cyclom-16Y does not decode address bit 9 and therefore
4484 existent chip 4. If the preceding clearing of the supposed 4558 cannot distinguish between references to chip 0 and a non-
4485 chip 4 GFRCR register appears at chip 0, there is no chip 4 4559 existent chip 4. If the preceding clearing of the supposed
4486 and this must be a Cyclom-16Y, not a Cyclom-32Ye. 4560 chip 4 GFRCR register appears at chip 0, there is no chip 4
4487 */ 4561 and this must be a Cyclom-16Y, not a Cyclom-32Ye.
4488 if (chip_number == 4 4562 */
4489 && cy_readb(true_base_addr 4563 if (chip_number == 4 && cy_readb(true_base_addr +
4490 + (cy_chip_offset[0]<<index) 4564 (cy_chip_offset[0] << index) +
4491 + (CyGFRCR<<index)) == 0){ 4565 (CyGFRCR << index)) == 0) {
4492 return chip_number; 4566 return chip_number;
4493 } 4567 }
4494 4568
4495 cy_writeb(base_addr+(CyCCR<<index), CyCHIP_RESET); 4569 cy_writeb(base_addr + (CyCCR << index), CyCHIP_RESET);
4496 mdelay(1); 4570 mdelay(1);
4497
4498 if(cy_readb(base_addr+(CyGFRCR<<index)) == 0x00){
4499 /*
4500 printk(" chip #%d at %#6lx is not responding ",
4501 chip_number, (unsigned long)base_addr);
4502 printk("(GFRCR stayed 0)\n",
4503 */
4504 return chip_number;
4505 }
4506 if((0xf0 & (cy_readb(base_addr+(CyGFRCR<<index)))) != 0x40){
4507 /*
4508 printk(" chip #%d at %#6lx is not valid (GFRCR == %#2x)\n",
4509 chip_number, (unsigned long)base_addr,
4510 base_addr[CyGFRCR<<index]);
4511 */
4512 return chip_number;
4513 }
4514 cy_writeb(base_addr+(CyGCR<<index), CyCH0_SERIAL);
4515 if (cy_readb(base_addr+(CyGFRCR<<index)) >= CD1400_REV_J){
4516 /* It is a CD1400 rev. J or later */
4517 /* Impossible to reach 5ms with this chip.
4518 Changed to 2ms instead (f = 500 Hz). */
4519 cy_writeb(base_addr+(CyPPR<<index), CyCLOCK_60_2MS);
4520 } else {
4521 /* f = 200 Hz */
4522 cy_writeb(base_addr+(CyPPR<<index), CyCLOCK_25_5MS);
4523 }
4524 4571
4525 /* 4572 if (cy_readb(base_addr + (CyGFRCR << index)) == 0x00) {
4526 printk(" chip #%d at %#6lx is rev 0x%2x\n", 4573 /*
4527 chip_number, (unsigned long)base_addr, 4574 printk(" chip #%d at %#6lx is not responding ",
4528 cy_readb(base_addr+(CyGFRCR<<index))); 4575 chip_number, (unsigned long)base_addr);
4529 */ 4576 printk("(GFRCR stayed 0)\n",
4530 } 4577 */
4531 return chip_number; 4578 return chip_number;
4532} /* cyy_init_card */ 4579 }
4580 if ((0xf0 & (cy_readb(base_addr + (CyGFRCR << index)))) !=
4581 0x40) {
4582 /*
4583 printk(" chip #%d at %#6lx is not valid (GFRCR == "
4584 "%#2x)\n",
4585 chip_number, (unsigned long)base_addr,
4586 base_addr[CyGFRCR<<index]);
4587 */
4588 return chip_number;
4589 }
4590 cy_writeb(base_addr + (CyGCR << index), CyCH0_SERIAL);
4591 if (cy_readb(base_addr + (CyGFRCR << index)) >= CD1400_REV_J) {
4592 /* It is a CD1400 rev. J or later */
4593 /* Impossible to reach 5ms with this chip.
4594 Changed to 2ms instead (f = 500 Hz). */
4595 cy_writeb(base_addr + (CyPPR << index), CyCLOCK_60_2MS);
4596 } else {
4597 /* f = 200 Hz */
4598 cy_writeb(base_addr + (CyPPR << index), CyCLOCK_25_5MS);
4599 }
4600
4601 /*
4602 printk(" chip #%d at %#6lx is rev 0x%2x\n",
4603 chip_number, (unsigned long)base_addr,
4604 cy_readb(base_addr+(CyGFRCR<<index)));
4605 */
4606 }
4607 return chip_number;
4608} /* cyy_init_card */
4533 4609
4534/* 4610/*
4535 * --------------------------------------------------------------------- 4611 * ---------------------------------------------------------------------
@@ -4537,126 +4613,124 @@ cyy_init_card(void __iomem *true_base_addr,int index)
4537 * sets global variables and return the number of ISA boards found. 4613 * sets global variables and return the number of ISA boards found.
4538 * --------------------------------------------------------------------- 4614 * ---------------------------------------------------------------------
4539 */ 4615 */
4540static int __init 4616static int __init cy_detect_isa(void)
4541cy_detect_isa(void)
4542{ 4617{
4543#ifdef CONFIG_ISA 4618#ifdef CONFIG_ISA
4544 unsigned short cy_isa_irq,nboard; 4619 unsigned short cy_isa_irq, nboard;
4545 void __iomem *cy_isa_address; 4620 void __iomem *cy_isa_address;
4546 unsigned short i,j,cy_isa_nchan; 4621 unsigned short i, j, cy_isa_nchan;
4547#ifdef MODULE 4622#ifdef MODULE
4548 int isparam = 0; 4623 int isparam = 0;
4549#endif 4624#endif
4550 4625
4551 nboard = 0; 4626 nboard = 0;
4552 4627
4553#ifdef MODULE 4628#ifdef MODULE
4554 /* Check for module parameters */ 4629 /* Check for module parameters */
4555 for(i = 0 ; i < NR_CARDS; i++) { 4630 for (i = 0; i < NR_CARDS; i++) {
4556 if (maddr[i] || i) { 4631 if (maddr[i] || i) {
4557 isparam = 1; 4632 isparam = 1;
4558 cy_isa_addresses[i] = maddr[i]; 4633 cy_isa_addresses[i] = maddr[i];
4559 } 4634 }
4560 if (!maddr[i]) 4635 if (!maddr[i])
4561 break; 4636 break;
4562 } 4637 }
4563#endif 4638#endif
4564 4639
4565 /* scan the address table probing for Cyclom-Y/ISA boards */ 4640 /* scan the address table probing for Cyclom-Y/ISA boards */
4566 for (i = 0 ; i < NR_ISA_ADDRS ; i++) { 4641 for (i = 0; i < NR_ISA_ADDRS; i++) {
4567 unsigned int isa_address = cy_isa_addresses[i]; 4642 unsigned int isa_address = cy_isa_addresses[i];
4568 if (isa_address == 0x0000) { 4643 if (isa_address == 0x0000) {
4569 return(nboard); 4644 return nboard;
4570 } 4645 }
4571 4646
4572 /* probe for CD1400... */ 4647 /* probe for CD1400... */
4573 cy_isa_address = ioremap(isa_address, CyISA_Ywin); 4648 cy_isa_address = ioremap(isa_address, CyISA_Ywin);
4574 cy_isa_nchan = CyPORTS_PER_CHIP * 4649 cy_isa_nchan = CyPORTS_PER_CHIP *
4575 cyy_init_card(cy_isa_address,0); 4650 cyy_init_card(cy_isa_address, 0);
4576 if (cy_isa_nchan == 0) { 4651 if (cy_isa_nchan == 0) {
4577 continue; 4652 continue;
4578 } 4653 }
4579
4580#ifdef MODULE 4654#ifdef MODULE
4581 if (isparam && irq[i]) 4655 if (isparam && irq[i])
4582 cy_isa_irq = irq[i]; 4656 cy_isa_irq = irq[i];
4583 else 4657 else
4584#endif 4658#endif
4585 /* find out the board's irq by probing */ 4659 /* find out the board's irq by probing */
4586 cy_isa_irq = detect_isa_irq(cy_isa_address); 4660 cy_isa_irq = detect_isa_irq(cy_isa_address);
4587 if (cy_isa_irq == 0) { 4661 if (cy_isa_irq == 0) {
4588 printk("Cyclom-Y/ISA found at 0x%lx ", 4662 printk("Cyclom-Y/ISA found at 0x%lx ",
4589 (unsigned long) cy_isa_address); 4663 (unsigned long)cy_isa_address);
4590 printk("but the IRQ could not be detected.\n"); 4664 printk("but the IRQ could not be detected.\n");
4591 continue; 4665 continue;
4592 } 4666 }
4593 4667
4594 if((cy_next_channel+cy_isa_nchan) > NR_PORTS) { 4668 if ((cy_next_channel + cy_isa_nchan) > NR_PORTS) {
4595 printk("Cyclom-Y/ISA found at 0x%lx ", 4669 printk("Cyclom-Y/ISA found at 0x%lx ",
4596 (unsigned long) cy_isa_address); 4670 (unsigned long)cy_isa_address);
4597 printk("but no more channels are available.\n"); 4671 printk("but no more channels are available.\n");
4598 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n"); 4672 printk("Change NR_PORTS in cyclades.c and recompile "
4599 return(nboard); 4673 "kernel.\n");
4600 } 4674 return nboard;
4601 /* fill the next cy_card structure available */ 4675 }
4602 for (j = 0 ; j < NR_CARDS ; j++) { 4676 /* fill the next cy_card structure available */
4603 if (cy_card[j].base_addr == 0) break; 4677 for (j = 0; j < NR_CARDS; j++) {
4604 } 4678 if (cy_card[j].base_addr == 0)
4605 if (j == NR_CARDS) { /* no more cy_cards available */ 4679 break;
4606 printk("Cyclom-Y/ISA found at 0x%lx ", 4680 }
4607 (unsigned long) cy_isa_address); 4681 if (j == NR_CARDS) { /* no more cy_cards available */
4608 printk("but no more cards can be used .\n"); 4682 printk("Cyclom-Y/ISA found at 0x%lx ",
4609 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n"); 4683 (unsigned long)cy_isa_address);
4610 return(nboard); 4684 printk("but no more cards can be used .\n");
4611 } 4685 printk("Change NR_CARDS in cyclades.c and recompile "
4612 4686 "kernel.\n");
4613 /* allocate IRQ */ 4687 return nboard;
4614 if(request_irq(cy_isa_irq, cyy_interrupt, 4688 }
4615 IRQF_DISABLED, "Cyclom-Y", &cy_card[j])) 4689
4616 { 4690 /* allocate IRQ */
4617 printk("Cyclom-Y/ISA found at 0x%lx ", 4691 if (request_irq(cy_isa_irq, cyy_interrupt,
4618 (unsigned long) cy_isa_address); 4692 IRQF_DISABLED, "Cyclom-Y", &cy_card[j])) {
4619 printk("but could not allocate IRQ#%d.\n", 4693 printk("Cyclom-Y/ISA found at 0x%lx ",
4620 cy_isa_irq); 4694 (unsigned long)cy_isa_address);
4621 return(nboard); 4695 printk("but could not allocate IRQ#%d.\n", cy_isa_irq);
4622 } 4696 return nboard;
4623 4697 }
4624 /* set cy_card */ 4698
4625 cy_card[j].base_addr = cy_isa_address; 4699 /* set cy_card */
4626 cy_card[j].ctl_addr = NULL; 4700 cy_card[j].base_addr = cy_isa_address;
4627 cy_card[j].irq = (int) cy_isa_irq; 4701 cy_card[j].ctl_addr = NULL;
4628 cy_card[j].bus_index = 0; 4702 cy_card[j].irq = (int)cy_isa_irq;
4629 cy_card[j].first_line = cy_next_channel; 4703 cy_card[j].bus_index = 0;
4630 cy_card[j].num_chips = cy_isa_nchan/4; 4704 cy_card[j].first_line = cy_next_channel;
4631 nboard++; 4705 cy_card[j].num_chips = cy_isa_nchan / 4;
4632 4706 nboard++;
4633 /* print message */ 4707
4634 printk("Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d, ", 4708 /* print message */
4635 j+1, (unsigned long) cy_isa_address, 4709 printk("Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d, ",
4636 (unsigned long)(cy_isa_address + (CyISA_Ywin - 1)), 4710 j + 1, (unsigned long)cy_isa_address,
4637 cy_isa_irq); 4711 (unsigned long)(cy_isa_address + (CyISA_Ywin - 1)),
4638 printk("%d channels starting from port %d.\n", 4712 cy_isa_irq);
4639 cy_isa_nchan, cy_next_channel); 4713 printk("%d channels starting from port %d.\n",
4640 cy_next_channel += cy_isa_nchan; 4714 cy_isa_nchan, cy_next_channel);
4641 } 4715 cy_next_channel += cy_isa_nchan;
4642 return(nboard); 4716 }
4717 return nboard;
4643#else 4718#else
4644 return(0); 4719 return 0;
4645#endif /* CONFIG_ISA */ 4720#endif /* CONFIG_ISA */
4646} /* cy_detect_isa */ 4721} /* cy_detect_isa */
4647 4722
4648static void 4723static void plx_init(void __iomem * addr, uclong initctl)
4649plx_init(void __iomem *addr, uclong initctl)
4650{ 4724{
4651 /* Reset PLX */ 4725 /* Reset PLX */
4652 cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x40000000); 4726 cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x40000000);
4653 udelay(100L); 4727 udelay(100L);
4654 cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x40000000); 4728 cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x40000000);
4655 4729
4656 /* Reload Config. Registers from EEPROM */ 4730 /* Reload Config. Registers from EEPROM */
4657 cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x20000000); 4731 cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x20000000);
4658 udelay(100L); 4732 udelay(100L);
4659 cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x20000000); 4733 cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x20000000);
4660} 4734}
4661 4735
4662/* 4736/*
@@ -4665,43 +4739,42 @@ plx_init(void __iomem *addr, uclong initctl)
4665 * sets global variables and return the number of PCI boards found. 4739 * sets global variables and return the number of PCI boards found.
4666 * --------------------------------------------------------------------- 4740 * ---------------------------------------------------------------------
4667 */ 4741 */
4668static int __init 4742static int __init cy_detect_pci(void)
4669cy_detect_pci(void)
4670{ 4743{
4671#ifdef CONFIG_PCI 4744#ifdef CONFIG_PCI
4672 4745
4673 struct pci_dev *pdev = NULL; 4746 struct pci_dev *pdev = NULL;
4674 unsigned char cyy_rev_id; 4747 unsigned char cyy_rev_id;
4675 unsigned char cy_pci_irq = 0; 4748 unsigned char cy_pci_irq = 0;
4676 uclong cy_pci_phys0, cy_pci_phys2; 4749 uclong cy_pci_phys0, cy_pci_phys2;
4677 void __iomem *cy_pci_addr0, *cy_pci_addr2; 4750 void __iomem *cy_pci_addr0, *cy_pci_addr2;
4678 unsigned short i,j,cy_pci_nchan, plx_ver; 4751 unsigned short i, j, cy_pci_nchan, plx_ver;
4679 unsigned short device_id,dev_index = 0; 4752 unsigned short device_id, dev_index = 0;
4680 uclong mailbox; 4753 uclong mailbox;
4681 uclong ZeIndex = 0; 4754 uclong ZeIndex = 0;
4682 void __iomem *Ze_addr0[NR_CARDS], *Ze_addr2[NR_CARDS]; 4755 void __iomem *Ze_addr0[NR_CARDS], *Ze_addr2[NR_CARDS];
4683 uclong Ze_phys0[NR_CARDS], Ze_phys2[NR_CARDS]; 4756 uclong Ze_phys0[NR_CARDS], Ze_phys2[NR_CARDS];
4684 unsigned char Ze_irq[NR_CARDS]; 4757 unsigned char Ze_irq[NR_CARDS];
4685 struct pci_dev *Ze_pdev[NR_CARDS]; 4758 struct pci_dev *Ze_pdev[NR_CARDS];
4686 4759
4687 for (i = 0; i < NR_CARDS; i++) { 4760 for (i = 0; i < NR_CARDS; i++) {
4688 /* look for a Cyclades card by vendor and device id */ 4761 /* look for a Cyclades card by vendor and device id */
4689 while((device_id = cy_pci_dev_id[dev_index]) != 0) { 4762 while ((device_id = cy_pci_dev_id[dev_index]) != 0) {
4690 if((pdev = pci_get_device(PCI_VENDOR_ID_CYCLADES, 4763 if ((pdev = pci_get_device(PCI_VENDOR_ID_CYCLADES,
4691 device_id, pdev)) == NULL) { 4764 device_id, pdev)) == NULL) {
4692 dev_index++; /* try next device id */ 4765 dev_index++; /* try next device id */
4693 } else { 4766 } else {
4694 break; /* found a board */ 4767 break; /* found a board */
4695 } 4768 }
4696 } 4769 }
4697 4770
4698 if (device_id == 0) 4771 if (device_id == 0)
4699 break; 4772 break;
4700 4773
4701 if (pci_enable_device(pdev)) 4774 if (pci_enable_device(pdev))
4702 continue; 4775 continue;
4703 4776
4704 /* read PCI configuration area */ 4777 /* read PCI configuration area */
4705 cy_pci_irq = pdev->irq; 4778 cy_pci_irq = pdev->irq;
4706 cy_pci_phys0 = pci_resource_start(pdev, 0); 4779 cy_pci_phys0 = pci_resource_start(pdev, 0);
4707 cy_pci_phys2 = pci_resource_start(pdev, 2); 4780 cy_pci_phys2 = pci_resource_start(pdev, 2);
@@ -4709,482 +4782,497 @@ cy_detect_pci(void)
4709 4782
4710 device_id &= ~PCI_DEVICE_ID_MASK; 4783 device_id &= ~PCI_DEVICE_ID_MASK;
4711 4784
4712 if ((device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo) 4785 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo ||
4713 || (device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi)){ 4786 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) {
4714#ifdef CY_PCI_DEBUG 4787#ifdef CY_PCI_DEBUG
4715 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ", 4788 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4716 pdev->bus->number, pdev->devfn); 4789 pdev->bus->number, pdev->devfn);
4717 printk("rev_id=%d) IRQ%d\n", 4790 printk("rev_id=%d) IRQ%d\n",
4718 cyy_rev_id, (int)cy_pci_irq); 4791 cyy_rev_id, (int)cy_pci_irq);
4719 printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n", 4792 printk("Cyclom-Y/PCI:found winaddr=0x%lx "
4720 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0); 4793 "ctladdr=0x%lx\n",
4794 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0);
4721#endif 4795#endif
4722 4796
4723 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) { 4797 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) {
4724 printk(" Warning: PCI I/O bit incorrectly set. " 4798 printk(" Warning: PCI I/O bit incorrectly "
4725 "Ignoring it...\n"); 4799 "set. Ignoring it...\n");
4726 pdev->resource[2].flags &= ~IORESOURCE_IO; 4800 pdev->resource[2].flags &= ~IORESOURCE_IO;
4727 } 4801 }
4728
4729 /* Although we don't use this I/O region, we should
4730 request it from the kernel anyway, to avoid problems
4731 with other drivers accessing it. */
4732 if (pci_request_regions(pdev, "Cyclom-Y") != 0) {
4733 printk(KERN_ERR "cyclades: failed to reserve PCI resources\n");
4734 continue;
4735 }
4736 4802
4803 /* Although we don't use this I/O region, we should
4804 request it from the kernel anyway, to avoid problems
4805 with other drivers accessing it. */
4806 if (pci_request_regions(pdev, "Cyclom-Y") != 0) {
4807 printk(KERN_ERR "cyclades: failed to reserve "
4808 "PCI resources\n");
4809 continue;
4810 }
4737#if defined(__alpha__) 4811#if defined(__alpha__)
4738 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo) { /* below 1M? */ 4812 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo) { /* below 1M? */
4739 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ", 4813 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4740 pdev->bus->number, pdev->devfn); 4814 pdev->bus->number, pdev->devfn);
4741 printk("rev_id=%d) IRQ%d\n", 4815 printk("rev_id=%d) IRQ%d\n",
4742 cyy_rev_id, (int)cy_pci_irq); 4816 cyy_rev_id, (int)cy_pci_irq);
4743 printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n", 4817 printk("Cyclom-Y/PCI:found winaddr=0x%lx "
4744 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0); 4818 "ctladdr=0x%lx\n",
4745 printk("Cyclom-Y/PCI not supported for low addresses in " 4819 (ulong)cy_pci_phys2,
4746 "Alpha systems.\n"); 4820 (ulong)cy_pci_phys0);
4747 i--; 4821 printk("Cyclom-Y/PCI not supported for low "
4748 continue; 4822 "addresses in Alpha systems.\n");
4749 } 4823 i--;
4824 continue;
4825 }
4750#endif 4826#endif
4751 cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Yctl); 4827 cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Yctl);
4752 cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Ywin); 4828 cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Ywin);
4753 4829
4754#ifdef CY_PCI_DEBUG 4830#ifdef CY_PCI_DEBUG
4755 printk("Cyclom-Y/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n", 4831 printk("Cyclom-Y/PCI: relocate winaddr=0x%lx "
4756 (u_long)cy_pci_addr2, (u_long)cy_pci_addr0); 4832 "ctladdr=0x%lx\n",
4833 (u_long)cy_pci_addr2, (u_long)cy_pci_addr0);
4757#endif 4834#endif
4758 cy_pci_nchan = (unsigned short)(CyPORTS_PER_CHIP * 4835 cy_pci_nchan = (unsigned short)(CyPORTS_PER_CHIP *
4759 cyy_init_card(cy_pci_addr2, 1)); 4836 cyy_init_card(cy_pci_addr2, 1));
4760 if(cy_pci_nchan == 0) { 4837 if (cy_pci_nchan == 0) {
4761 printk("Cyclom-Y PCI host card with "); 4838 printk("Cyclom-Y PCI host card with ");
4762 printk("no Serial-Modules at 0x%lx.\n", 4839 printk("no Serial-Modules at 0x%lx.\n",
4763 (ulong) cy_pci_phys2); 4840 (ulong) cy_pci_phys2);
4764 i--; 4841 i--;
4765 continue; 4842 continue;
4766 } 4843 }
4767 if((cy_next_channel+cy_pci_nchan) > NR_PORTS) { 4844 if ((cy_next_channel + cy_pci_nchan) > NR_PORTS) {
4768 printk("Cyclom-Y/PCI found at 0x%lx ", 4845 printk("Cyclom-Y/PCI found at 0x%lx ",
4769 (ulong) cy_pci_phys2); 4846 (ulong) cy_pci_phys2);
4770 printk("but no channels are available.\n"); 4847 printk("but no channels are available.\n");
4771 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n"); 4848 printk("Change NR_PORTS in cyclades.c and "
4772 return(i); 4849 "recompile kernel.\n");
4773 } 4850 return i;
4774 /* fill the next cy_card structure available */ 4851 }
4775 for (j = 0 ; j < NR_CARDS ; j++) { 4852 /* fill the next cy_card structure available */
4776 if (cy_card[j].base_addr == 0) break; 4853 for (j = 0; j < NR_CARDS; j++) {
4777 } 4854 if (cy_card[j].base_addr == 0)
4778 if (j == NR_CARDS) { /* no more cy_cards available */ 4855 break;
4779 printk("Cyclom-Y/PCI found at 0x%lx ", 4856 }
4780 (ulong) cy_pci_phys2); 4857 if (j == NR_CARDS) { /* no more cy_cards available */
4781 printk("but no more cards can be used.\n"); 4858 printk("Cyclom-Y/PCI found at 0x%lx ",
4782 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n"); 4859 (ulong) cy_pci_phys2);
4783 return(i); 4860 printk("but no more cards can be used.\n");
4784 } 4861 printk("Change NR_CARDS in cyclades.c and "
4785 4862 "recompile kernel.\n");
4786 /* allocate IRQ */ 4863 return i;
4787 if(request_irq(cy_pci_irq, cyy_interrupt, 4864 }
4788 IRQF_SHARED, "Cyclom-Y", &cy_card[j])) 4865
4789 { 4866 /* allocate IRQ */
4790 printk("Cyclom-Y/PCI found at 0x%lx ", 4867 if (request_irq(cy_pci_irq, cyy_interrupt,
4791 (ulong) cy_pci_phys2); 4868 IRQF_SHARED, "Cyclom-Y", &cy_card[j])) {
4792 printk("but could not allocate IRQ%d.\n", 4869 printk("Cyclom-Y/PCI found at 0x%lx ",
4793 cy_pci_irq); 4870 (ulong) cy_pci_phys2);
4794 return(i); 4871 printk("but could not allocate IRQ%d.\n",
4795 } 4872 cy_pci_irq);
4796 4873 return i;
4797 /* set cy_card */ 4874 }
4798 cy_card[j].base_phys = (ulong)cy_pci_phys2; 4875
4799 cy_card[j].ctl_phys = (ulong)cy_pci_phys0; 4876 /* set cy_card */
4800 cy_card[j].base_addr = cy_pci_addr2; 4877 cy_card[j].base_phys = (ulong) cy_pci_phys2;
4801 cy_card[j].ctl_addr = cy_pci_addr0; 4878 cy_card[j].ctl_phys = (ulong) cy_pci_phys0;
4802 cy_card[j].irq = (int) cy_pci_irq; 4879 cy_card[j].base_addr = cy_pci_addr2;
4803 cy_card[j].bus_index = 1; 4880 cy_card[j].ctl_addr = cy_pci_addr0;
4804 cy_card[j].first_line = cy_next_channel; 4881 cy_card[j].irq = (int)cy_pci_irq;
4805 cy_card[j].num_chips = cy_pci_nchan/4; 4882 cy_card[j].bus_index = 1;
4806 cy_card[j].pdev = pdev; 4883 cy_card[j].first_line = cy_next_channel;
4807 4884 cy_card[j].num_chips = cy_pci_nchan / 4;
4808 /* enable interrupts in the PCI interface */ 4885 cy_card[j].pdev = pdev;
4809 plx_ver = cy_readb(cy_pci_addr2 + CyPLX_VER) & 0x0f; 4886
4810 switch (plx_ver) { 4887 /* enable interrupts in the PCI interface */
4811 case PLX_9050: 4888 plx_ver = cy_readb(cy_pci_addr2 + CyPLX_VER) & 0x0f;
4812 4889 switch (plx_ver) {
4813 cy_writeb(cy_pci_addr0+0x4c, 0x43); 4890 case PLX_9050:
4814 break; 4891
4815 4892 cy_writeb(cy_pci_addr0 + 0x4c, 0x43);
4816 case PLX_9060: 4893 break;
4817 case PLX_9080: 4894
4818 default: /* Old boards, use PLX_9060 */ 4895 case PLX_9060:
4819 4896 case PLX_9080:
4820 plx_init(cy_pci_addr0, 0x6c); 4897 default: /* Old boards, use PLX_9060 */
4821 /* For some yet unknown reason, once the PLX9060 reloads 4898
4822 the EEPROM, the IRQ is lost and, thus, we have to 4899 plx_init(cy_pci_addr0, 0x6c);
4823 re-write it to the PCI config. registers. 4900 /* For some yet unknown reason, once the PLX9060 reloads
4824 This will remain here until we find a permanent fix. */ 4901 the EEPROM, the IRQ is lost and, thus, we have to
4825 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, cy_pci_irq); 4902 re-write it to the PCI config. registers.
4826 4903 This will remain here until we find a permanent
4827 cy_writew(cy_pci_addr0+0x68, 4904 fix. */
4828 cy_readw(cy_pci_addr0+0x68)|0x0900); 4905 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE,
4829 break; 4906 cy_pci_irq);
4830 } 4907
4908 cy_writew(cy_pci_addr0 + 0x68,
4909 cy_readw(cy_pci_addr0 +
4910 0x68) | 0x0900);
4911 break;
4912 }
4831 4913
4832 /* print message */ 4914 /* print message */
4833 printk("Cyclom-Y/PCI #%d: 0x%lx-0x%lx, IRQ%d, ", 4915 printk("Cyclom-Y/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
4834 j+1, 4916 j + 1, (ulong)cy_pci_phys2,
4835 (ulong)cy_pci_phys2, 4917 (ulong) (cy_pci_phys2 + CyPCI_Ywin - 1),
4836 (ulong)(cy_pci_phys2 + CyPCI_Ywin - 1), 4918 (int)cy_pci_irq);
4837 (int)cy_pci_irq); 4919 printk("%d channels starting from port %d.\n",
4838 printk("%d channels starting from port %d.\n", 4920 cy_pci_nchan, cy_next_channel);
4839 cy_pci_nchan, cy_next_channel); 4921
4840 4922 cy_next_channel += cy_pci_nchan;
4841 cy_next_channel += cy_pci_nchan; 4923 } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Lo) {
4842 }else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Lo){ 4924 /* print message */
4843 /* print message */ 4925 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
4844 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ", 4926 pdev->bus->number, pdev->devfn);
4845 pdev->bus->number, pdev->devfn); 4927 printk("rev_id=%d) IRQ%d\n",
4846 printk("rev_id=%d) IRQ%d\n", 4928 cyy_rev_id, (int)cy_pci_irq);
4847 cyy_rev_id, (int)cy_pci_irq); 4929 printk("Cyclades-Z/PCI: found winaddr=0x%lx "
4848 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n", 4930 "ctladdr=0x%lx\n",
4849 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0); 4931 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0);
4850 printk("Cyclades-Z/PCI not supported for low addresses\n"); 4932 printk("Cyclades-Z/PCI not supported for low "
4851 break; 4933 "addresses\n");
4852 }else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi){ 4934 break;
4935 } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi) {
4853#ifdef CY_PCI_DEBUG 4936#ifdef CY_PCI_DEBUG
4854 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ", 4937 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
4855 pdev->bus->number, pdev->devfn); 4938 pdev->bus->number, pdev->devfn);
4856 printk("rev_id=%d) IRQ%d\n", 4939 printk("rev_id=%d) IRQ%d\n",
4857 cyy_rev_id, (int)cy_pci_irq); 4940 cyy_rev_id, (int)cy_pci_irq);
4858 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n", 4941 printk("Cyclades-Z/PCI: found winaddr=0x%lx "
4859 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0); 4942 "ctladdr=0x%lx\n",
4943 (ulong) cy_pci_phys2, (ulong) cy_pci_phys0);
4860#endif 4944#endif
4861 cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Zctl); 4945 cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Zctl);
4862 4946
4863 /* Disable interrupts on the PLX before resetting it */ 4947 /* Disable interrupts on the PLX before resetting it */
4864 cy_writew(cy_pci_addr0+0x68, 4948 cy_writew(cy_pci_addr0 + 0x68,
4865 cy_readw(cy_pci_addr0+0x68) & ~0x0900); 4949 cy_readw(cy_pci_addr0 + 0x68) & ~0x0900);
4866 4950
4867 plx_init(cy_pci_addr0, 0x6c); 4951 plx_init(cy_pci_addr0, 0x6c);
4868 /* For some yet unknown reason, once the PLX9060 reloads 4952 /* For some yet unknown reason, once the PLX9060 reloads
4869 the EEPROM, the IRQ is lost and, thus, we have to 4953 the EEPROM, the IRQ is lost and, thus, we have to
4870 re-write it to the PCI config. registers. 4954 re-write it to the PCI config. registers.
4871 This will remain here until we find a permanent fix. */ 4955 This will remain here until we find a permanent
4872 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, cy_pci_irq); 4956 fix. */
4873 4957 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE,
4874 mailbox = (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *) 4958 cy_pci_irq);
4875 cy_pci_addr0)->mail_box_0); 4959
4876 4960 mailbox =
4877 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) { 4961 (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *)
4878 printk(" Warning: PCI I/O bit incorrectly set. " 4962 cy_pci_addr0)->mail_box_0);
4879 "Ignoring it...\n"); 4963
4880 pdev->resource[2].flags &= ~IORESOURCE_IO; 4964 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) {
4881 } 4965 printk(" Warning: PCI I/O bit incorrectly "
4966 "set. Ignoring it...\n");
4967 pdev->resource[2].flags &= ~IORESOURCE_IO;
4968 }
4882 4969
4883 /* Although we don't use this I/O region, we should 4970 /* Although we don't use this I/O region, we should
4884 request it from the kernel anyway, to avoid problems 4971 request it from the kernel anyway, to avoid problems
4885 with other drivers accessing it. */ 4972 with other drivers accessing it. */
4886 if (pci_request_regions(pdev, "Cyclades-Z") != 0) { 4973 if (pci_request_regions(pdev, "Cyclades-Z") != 0) {
4887 printk(KERN_ERR "cyclades: failed to reserve PCI resources\n"); 4974 printk(KERN_ERR "cyclades: failed to reserve "
4888 continue; 4975 "PCI resources\n");
4889 } 4976 continue;
4890 4977 }
4891 if (mailbox == ZE_V1) { 4978
4892 cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Ze_win); 4979 if (mailbox == ZE_V1) {
4893 if (ZeIndex == NR_CARDS) { 4980 cy_pci_addr2 = ioremap(cy_pci_phys2,
4894 printk("Cyclades-Ze/PCI found at 0x%lx ", 4981 CyPCI_Ze_win);
4895 (ulong)cy_pci_phys2); 4982 if (ZeIndex == NR_CARDS) {
4896 printk("but no more cards can be used.\n"); 4983 printk("Cyclades-Ze/PCI found at "
4897 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n"); 4984 "0x%lx but no more cards can "
4898 } else { 4985 "be used.\nChange NR_CARDS in "
4899 Ze_phys0[ZeIndex] = cy_pci_phys0; 4986 "cyclades.c and recompile "
4900 Ze_phys2[ZeIndex] = cy_pci_phys2; 4987 "kernel.\n",
4901 Ze_addr0[ZeIndex] = cy_pci_addr0; 4988 (ulong)cy_pci_phys2);
4902 Ze_addr2[ZeIndex] = cy_pci_addr2; 4989 } else {
4903 Ze_irq[ZeIndex] = cy_pci_irq; 4990 Ze_phys0[ZeIndex] = cy_pci_phys0;
4904 Ze_pdev[ZeIndex] = pdev; 4991 Ze_phys2[ZeIndex] = cy_pci_phys2;
4905 ZeIndex++; 4992 Ze_addr0[ZeIndex] = cy_pci_addr0;
4906 } 4993 Ze_addr2[ZeIndex] = cy_pci_addr2;
4907 i--; 4994 Ze_irq[ZeIndex] = cy_pci_irq;
4908 continue; 4995 Ze_pdev[ZeIndex] = pdev;
4909 } else { 4996 ZeIndex++;
4910 cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Zwin); 4997 }
4911 } 4998 i--;
4999 continue;
5000 } else {
5001 cy_pci_addr2 = ioremap(cy_pci_phys2,CyPCI_Zwin);
5002 }
4912 5003
4913#ifdef CY_PCI_DEBUG 5004#ifdef CY_PCI_DEBUG
4914 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n", 5005 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx "
4915 (ulong)cy_pci_addr2, (ulong)cy_pci_addr0); 5006 "ctladdr=0x%lx\n",
4916 if (mailbox == ZO_V1) { 5007 (ulong) cy_pci_addr2, (ulong) cy_pci_addr0);
4917 cy_writel(&((struct RUNTIME_9060 *) 5008 if (mailbox == ZO_V1) {
4918 (cy_pci_addr0))->loc_addr_base, WIN_CREG); 5009 cy_writel(&((struct RUNTIME_9060 *)
4919 PAUSE 5010 (cy_pci_addr0))->loc_addr_base,
4920 printk("Cyclades-8Zo/PCI: FPGA id %lx, ver %lx\n", 5011 WIN_CREG);
4921 (ulong)(0xff & cy_readl(&((struct CUSTOM_REG *) 5012 PAUSE;
4922 (cy_pci_addr2))->fpga_id)), 5013 printk("Cyclades-8Zo/PCI: FPGA id %lx, ver "
4923 (ulong)(0xff & cy_readl(&((struct CUSTOM_REG *) 5014 "%lx\n", (ulong) (0xff &
4924 (cy_pci_addr2))->fpga_version))); 5015 cy_readl(&((struct CUSTOM_REG *)
4925 cy_writel(&((struct RUNTIME_9060 *) 5016 (cy_pci_addr2))->fpga_id)),
4926 (cy_pci_addr0))->loc_addr_base, WIN_RAM); 5017 (ulong)(0xff &
4927 } else { 5018 cy_readl(&((struct CUSTOM_REG *)
4928 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n"); 5019 (cy_pci_addr2))->
4929 } 5020 fpga_version)));
5021 cy_writel(&((struct RUNTIME_9060 *)
5022 (cy_pci_addr0))->loc_addr_base,
5023 WIN_RAM);
5024 } else {
5025 printk("Cyclades-Z/PCI: New Cyclades-Z board. "
5026 "FPGA not loaded\n");
5027 }
4930#endif 5028#endif
4931 /* The following clears the firmware id word. This ensures 5029 /* The following clears the firmware id word. This
4932 that the driver will not attempt to talk to the board 5030 ensures that the driver will not attempt to talk to
4933 until it has been properly initialized. 5031 the board until it has been properly initialized.
4934 */ 5032 */
4935 PAUSE 5033 PAUSE;
4936 if ((mailbox == ZO_V1) || (mailbox == ZO_V2)) 5034 if ((mailbox == ZO_V1) || (mailbox == ZO_V2))
4937 cy_writel(cy_pci_addr2 + ID_ADDRESS, 0L); 5035 cy_writel(cy_pci_addr2 + ID_ADDRESS, 0L);
4938 5036
4939 /* This must be a Cyclades-8Zo/PCI. The extendable 5037 /* This must be a Cyclades-8Zo/PCI. The extendable
4940 version will have a different device_id and will 5038 version will have a different device_id and will
4941 be allocated its maximum number of ports. */ 5039 be allocated its maximum number of ports. */
4942 cy_pci_nchan = 8; 5040 cy_pci_nchan = 8;
4943 5041
4944 if((cy_next_channel+cy_pci_nchan) > NR_PORTS) { 5042 if ((cy_next_channel + cy_pci_nchan) > NR_PORTS) {
4945 printk("Cyclades-8Zo/PCI found at 0x%lx ", 5043 printk("Cyclades-8Zo/PCI found at 0x%lx but"
4946 (ulong)cy_pci_phys2); 5044 "no channels are available.\nChange "
4947 printk("but no channels are available.\n"); 5045 "NR_PORTS in cyclades.c and recompile "
4948 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n"); 5046 "kernel.\n", (ulong)cy_pci_phys2);
4949 return(i); 5047 return i;
4950 } 5048 }
4951
4952 /* fill the next cy_card structure available */
4953 for (j = 0 ; j < NR_CARDS ; j++) {
4954 if (cy_card[j].base_addr == 0) break;
4955 }
4956 if (j == NR_CARDS) { /* no more cy_cards available */
4957 printk("Cyclades-8Zo/PCI found at 0x%lx ",
4958 (ulong)cy_pci_phys2);
4959 printk("but no more cards can be used.\n");
4960 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4961 return(i);
4962 }
4963 5049
5050 /* fill the next cy_card structure available */
5051 for (j = 0; j < NR_CARDS; j++) {
5052 if (cy_card[j].base_addr == 0)
5053 break;
5054 }
5055 if (j == NR_CARDS) { /* no more cy_cards available */
5056 printk("Cyclades-8Zo/PCI found at 0x%lx but"
5057 "no more cards can be used.\nChange "
5058 "NR_CARDS in cyclades.c and recompile "
5059 "kernel.\n", (ulong)cy_pci_phys2);
5060 return i;
5061 }
5062#ifdef CONFIG_CYZ_INTR
5063 /* allocate IRQ only if board has an IRQ */
5064 if ((cy_pci_irq != 0) && (cy_pci_irq != 255)) {
5065 if (request_irq(cy_pci_irq, cyz_interrupt,
5066 IRQF_SHARED, "Cyclades-Z",
5067 &cy_card[j])) {
5068 printk("Cyclom-8Zo/PCI found at 0x%lx "
5069 "but could not allocate "
5070 "IRQ%d.\n", (ulong)cy_pci_phys2,
5071 cy_pci_irq);
5072 return i;
5073 }
5074 }
5075#endif /* CONFIG_CYZ_INTR */
5076
5077 /* set cy_card */
5078 cy_card[j].base_phys = cy_pci_phys2;
5079 cy_card[j].ctl_phys = cy_pci_phys0;
5080 cy_card[j].base_addr = cy_pci_addr2;
5081 cy_card[j].ctl_addr = cy_pci_addr0;
5082 cy_card[j].irq = (int)cy_pci_irq;
5083 cy_card[j].bus_index = 1;
5084 cy_card[j].first_line = cy_next_channel;
5085 cy_card[j].num_chips = -1;
5086 cy_card[j].pdev = pdev;
5087
5088 /* print message */
4964#ifdef CONFIG_CYZ_INTR 5089#ifdef CONFIG_CYZ_INTR
4965 /* allocate IRQ only if board has an IRQ */ 5090 /* don't report IRQ if board is no IRQ */
4966 if( (cy_pci_irq != 0) && (cy_pci_irq != 255) ) { 5091 if ((cy_pci_irq != 0) && (cy_pci_irq != 255))
4967 if(request_irq(cy_pci_irq, cyz_interrupt, 5092 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, "
4968 IRQF_SHARED, "Cyclades-Z", &cy_card[j])) 5093 "IRQ%d, ", j + 1, (ulong)cy_pci_phys2,
4969 { 5094 (ulong) (cy_pci_phys2 + CyPCI_Zwin - 1),
4970 printk("Cyclom-8Zo/PCI found at 0x%lx ", 5095 (int)cy_pci_irq);
4971 (ulong) cy_pci_phys2); 5096 else
4972 printk("but could not allocate IRQ%d.\n", 5097#endif /* CONFIG_CYZ_INTR */
4973 cy_pci_irq); 5098 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, ",
4974 return(i); 5099 j + 1, (ulong)cy_pci_phys2,
4975 } 5100 (ulong)(cy_pci_phys2 + CyPCI_Zwin - 1));
5101
5102 printk("%d channels starting from port %d.\n",
5103 cy_pci_nchan, cy_next_channel);
5104 cy_next_channel += cy_pci_nchan;
4976 } 5105 }
4977#endif /* CONFIG_CYZ_INTR */ 5106 }
4978
4979
4980 /* set cy_card */
4981 cy_card[j].base_phys = cy_pci_phys2;
4982 cy_card[j].ctl_phys = cy_pci_phys0;
4983 cy_card[j].base_addr = cy_pci_addr2;
4984 cy_card[j].ctl_addr = cy_pci_addr0;
4985 cy_card[j].irq = (int) cy_pci_irq;
4986 cy_card[j].bus_index = 1;
4987 cy_card[j].first_line = cy_next_channel;
4988 cy_card[j].num_chips = -1;
4989 cy_card[j].pdev = pdev;
4990 5107
4991 /* print message */ 5108 for (; ZeIndex != 0 && i < NR_CARDS; i++) {
4992#ifdef CONFIG_CYZ_INTR 5109 cy_pci_phys0 = Ze_phys0[0];
4993 /* don't report IRQ if board is no IRQ */ 5110 cy_pci_phys2 = Ze_phys2[0];
4994 if( (cy_pci_irq != 0) && (cy_pci_irq != 255) ) 5111 cy_pci_addr0 = Ze_addr0[0];
4995 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, IRQ%d, ", 5112 cy_pci_addr2 = Ze_addr2[0];
4996 j+1,(ulong)cy_pci_phys2, 5113 cy_pci_irq = Ze_irq[0];
4997 (ulong)(cy_pci_phys2 + CyPCI_Zwin - 1), 5114 pdev = Ze_pdev[0];
4998 (int)cy_pci_irq); 5115 for (j = 0; j < ZeIndex - 1; j++) {
4999 else 5116 Ze_phys0[j] = Ze_phys0[j + 1];
5000#endif /* CONFIG_CYZ_INTR */ 5117 Ze_phys2[j] = Ze_phys2[j + 1];
5001 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, ", 5118 Ze_addr0[j] = Ze_addr0[j + 1];
5002 j+1,(ulong)cy_pci_phys2, 5119 Ze_addr2[j] = Ze_addr2[j + 1];
5003 (ulong)(cy_pci_phys2 + CyPCI_Zwin - 1)); 5120 Ze_irq[j] = Ze_irq[j + 1];
5004 5121 Ze_pdev[j] = Ze_pdev[j + 1];
5005 printk("%d channels starting from port %d.\n", 5122 }
5006 cy_pci_nchan,cy_next_channel); 5123 ZeIndex--;
5007 cy_next_channel += cy_pci_nchan; 5124 mailbox = (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *)
5008 } 5125 cy_pci_addr0)->mail_box_0);
5009 }
5010
5011 for (; ZeIndex != 0 && i < NR_CARDS; i++) {
5012 cy_pci_phys0 = Ze_phys0[0];
5013 cy_pci_phys2 = Ze_phys2[0];
5014 cy_pci_addr0 = Ze_addr0[0];
5015 cy_pci_addr2 = Ze_addr2[0];
5016 cy_pci_irq = Ze_irq[0];
5017 pdev = Ze_pdev[0];
5018 for (j = 0 ; j < ZeIndex-1 ; j++) {
5019 Ze_phys0[j] = Ze_phys0[j+1];
5020 Ze_phys2[j] = Ze_phys2[j+1];
5021 Ze_addr0[j] = Ze_addr0[j+1];
5022 Ze_addr2[j] = Ze_addr2[j+1];
5023 Ze_irq[j] = Ze_irq[j+1];
5024 Ze_pdev[j] = Ze_pdev[j+1];
5025 }
5026 ZeIndex--;
5027 mailbox = (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *)
5028 cy_pci_addr0)->mail_box_0);
5029#ifdef CY_PCI_DEBUG 5126#ifdef CY_PCI_DEBUG
5030 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n", 5127 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
5031 (ulong)cy_pci_addr2, (ulong)cy_pci_addr0); 5128 (ulong)cy_pci_addr2, (ulong)cy_pci_addr0);
5032 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n"); 5129 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not "
5130 "loaded\n");
5033#endif 5131#endif
5034 PAUSE 5132 PAUSE;
5035 /* This must be the new Cyclades-Ze/PCI. */ 5133 /* This must be the new Cyclades-Ze/PCI. */
5036 cy_pci_nchan = ZE_V1_NPORTS; 5134 cy_pci_nchan = ZE_V1_NPORTS;
5037 5135
5038 if((cy_next_channel+cy_pci_nchan) > NR_PORTS) { 5136 if ((cy_next_channel + cy_pci_nchan) > NR_PORTS) {
5039 printk("Cyclades-Ze/PCI found at 0x%lx ", 5137 printk("Cyclades-Ze/PCI found at 0x%lx but no channels "
5040 (ulong)cy_pci_phys2); 5138 "are available.\nChange NR_PORTS in cyclades.c "
5041 printk("but no channels are available.\n"); 5139 "and recompile kernel.\n",
5042 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n"); 5140 (ulong) cy_pci_phys2);
5043 return(i); 5141 return i;
5044 } 5142 }
5045
5046 /* fill the next cy_card structure available */
5047 for (j = 0 ; j < NR_CARDS ; j++) {
5048 if (cy_card[j].base_addr == 0) break;
5049 }
5050 if (j == NR_CARDS) { /* no more cy_cards available */
5051 printk("Cyclades-Ze/PCI found at 0x%lx ",
5052 (ulong)cy_pci_phys2);
5053 printk("but no more cards can be used.\n");
5054 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5055 return(i);
5056 }
5057 5143
5144 /* fill the next cy_card structure available */
5145 for (j = 0; j < NR_CARDS; j++) {
5146 if (cy_card[j].base_addr == 0)
5147 break;
5148 }
5149 if (j == NR_CARDS) { /* no more cy_cards available */
5150 printk("Cyclades-Ze/PCI found at 0x%lx but no more "
5151 "cards can be used.\nChange NR_CARDS in "
5152 "cyclades.c and recompile kernel.\n",
5153 (ulong) cy_pci_phys2);
5154 return i;
5155 }
5058#ifdef CONFIG_CYZ_INTR 5156#ifdef CONFIG_CYZ_INTR
5059 /* allocate IRQ only if board has an IRQ */ 5157 /* allocate IRQ only if board has an IRQ */
5060 if( (cy_pci_irq != 0) && (cy_pci_irq != 255) ) { 5158 if ((cy_pci_irq != 0) && (cy_pci_irq != 255)) {
5061 if(request_irq(cy_pci_irq, cyz_interrupt, 5159 if (request_irq(cy_pci_irq, cyz_interrupt,
5062 IRQF_SHARED, "Cyclades-Z", &cy_card[j])) 5160 IRQF_SHARED, "Cyclades-Z",
5063 { 5161 &cy_card[j])) {
5064 printk("Cyclom-Ze/PCI found at 0x%lx ", 5162 printk("Cyclom-Ze/PCI found at 0x%lx ",
5065 (ulong) cy_pci_phys2); 5163 (ulong) cy_pci_phys2);
5066 printk("but could not allocate IRQ%d.\n", 5164 printk("but could not allocate IRQ%d.\n",
5067 cy_pci_irq); 5165 cy_pci_irq);
5068 return(i); 5166 return i;
5069 } 5167 }
5070 } 5168 }
5071#endif /* CONFIG_CYZ_INTR */ 5169#endif /* CONFIG_CYZ_INTR */
5072 5170
5073 /* set cy_card */ 5171 /* set cy_card */
5074 cy_card[j].base_phys = cy_pci_phys2; 5172 cy_card[j].base_phys = cy_pci_phys2;
5075 cy_card[j].ctl_phys = cy_pci_phys0; 5173 cy_card[j].ctl_phys = cy_pci_phys0;
5076 cy_card[j].base_addr = cy_pci_addr2; 5174 cy_card[j].base_addr = cy_pci_addr2;
5077 cy_card[j].ctl_addr = cy_pci_addr0; 5175 cy_card[j].ctl_addr = cy_pci_addr0;
5078 cy_card[j].irq = (int) cy_pci_irq; 5176 cy_card[j].irq = (int)cy_pci_irq;
5079 cy_card[j].bus_index = 1; 5177 cy_card[j].bus_index = 1;
5080 cy_card[j].first_line = cy_next_channel; 5178 cy_card[j].first_line = cy_next_channel;
5081 cy_card[j].num_chips = -1; 5179 cy_card[j].num_chips = -1;
5082 cy_card[j].pdev = pdev; 5180 cy_card[j].pdev = pdev;
5083 5181
5084 /* print message */ 5182 /* print message */
5085#ifdef CONFIG_CYZ_INTR 5183#ifdef CONFIG_CYZ_INTR
5086 /* don't report IRQ if board is no IRQ */ 5184 /* don't report IRQ if board is no IRQ */
5087 if( (cy_pci_irq != 0) && (cy_pci_irq != 255) ) 5185 if ((cy_pci_irq != 0) && (cy_pci_irq != 255))
5088 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, IRQ%d, ", 5186 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
5089 j+1,(ulong)cy_pci_phys2, 5187 j + 1, (ulong) cy_pci_phys2,
5090 (ulong)(cy_pci_phys2 + CyPCI_Ze_win - 1), 5188 (ulong) (cy_pci_phys2 + CyPCI_Ze_win - 1),
5091 (int)cy_pci_irq); 5189 (int)cy_pci_irq);
5092 else 5190 else
5093#endif /* CONFIG_CYZ_INTR */ 5191#endif /* CONFIG_CYZ_INTR */
5094 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, ", 5192 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, ",
5095 j+1,(ulong)cy_pci_phys2, 5193 j + 1, (ulong) cy_pci_phys2,
5096 (ulong)(cy_pci_phys2 + CyPCI_Ze_win - 1)); 5194 (ulong) (cy_pci_phys2 + CyPCI_Ze_win - 1));
5097 5195
5098 printk("%d channels starting from port %d.\n", 5196 printk("%d channels starting from port %d.\n",
5099 cy_pci_nchan,cy_next_channel); 5197 cy_pci_nchan, cy_next_channel);
5100 cy_next_channel += cy_pci_nchan; 5198 cy_next_channel += cy_pci_nchan;
5101 } 5199 }
5102 if (ZeIndex != 0) { 5200 if (ZeIndex != 0) {
5103 printk("Cyclades-Ze/PCI found at 0x%x ", 5201 printk("Cyclades-Ze/PCI found at 0x%x but no more cards can be "
5104 (unsigned int) Ze_phys2[0]); 5202 "used.\nChange NR_CARDS in cyclades.c and recompile "
5105 printk("but no more cards can be used.\n"); 5203 "kernel.\n", (unsigned int)Ze_phys2[0]);
5106 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5107 } 5204 }
5108 return(i); 5205 return i;
5109#else 5206#else
5110 return(0); 5207 return 0;
5111#endif /* ifdef CONFIG_PCI */ 5208#endif /* ifdef CONFIG_PCI */
5112} /* cy_detect_pci */ 5209} /* cy_detect_pci */
5113
5114 5210
5115/* 5211/*
5116 * This routine prints out the appropriate serial driver version number 5212 * This routine prints out the appropriate serial driver version number
5117 * and identifies which options were configured into this driver. 5213 * and identifies which options were configured into this driver.
5118 */ 5214 */
5119static inline void 5215static inline void show_version(void)
5120show_version(void)
5121{ 5216{
5122 char *rcsvers, *rcsdate, *tmp; 5217 printk("Cyclades driver " CY_VERSION "\n");
5123 rcsvers = strchr(rcsid, ' '); rcsvers++; 5218 printk(" built %s %s\n", __DATE__, __TIME__);
5124 tmp = strchr(rcsvers, ' '); *tmp++ = '\0'; 5219} /* show_version */
5125 rcsdate = strchr(tmp, ' '); rcsdate++; 5220
5126 tmp = strrchr(rcsdate, ' '); *tmp = '\0'; 5221static int
5127 printk("Cyclades driver %s %s\n",
5128 rcsvers, rcsdate);
5129 printk(" built %s %s\n",
5130 __DATE__, __TIME__);
5131} /* show_version */
5132
5133static int
5134cyclades_get_proc_info(char *buf, char **start, off_t offset, int length, 5222cyclades_get_proc_info(char *buf, char **start, off_t offset, int length,
5135 int *eof, void *data) 5223 int *eof, void *data)
5136{ 5224{
5137 struct cyclades_port *info; 5225 struct cyclades_port *info;
5138 int i; 5226 int i;
5139 int len=0; 5227 int len = 0;
5140 off_t begin=0; 5228 off_t begin = 0;
5141 off_t pos=0; 5229 off_t pos = 0;
5142 int size; 5230 int size;
5143 __u32 cur_jifs = jiffies; 5231 __u32 cur_jifs = jiffies;
5144 5232
5145 size = sprintf(buf, "Dev TimeOpen BytesOut IdleOut BytesIn IdleIn Overruns Ldisc\n"); 5233 size = sprintf(buf, "Dev TimeOpen BytesOut IdleOut BytesIn "
5146 5234 "IdleIn Overruns Ldisc\n");
5147 pos += size; 5235
5148 len += size; 5236 pos += size;
5149
5150 /* Output one line for each known port */
5151 for (i = 0; i < NR_PORTS && cy_port[i].line >= 0; i++) {
5152 info = &cy_port[i];
5153
5154 if (info->count)
5155 size = sprintf(buf+len,
5156 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
5157 info->line,
5158 JIFFIES_DIFF(info->idle_stats.in_use, cur_jifs) / HZ,
5159 info->idle_stats.xmit_bytes,
5160 JIFFIES_DIFF(info->idle_stats.xmit_idle, cur_jifs) / HZ,
5161 info->idle_stats.recv_bytes,
5162 JIFFIES_DIFF(info->idle_stats.recv_idle, cur_jifs) / HZ,
5163 info->idle_stats.overruns,
5164 (long) info->tty->ldisc.num);
5165 else
5166 size = sprintf(buf+len,
5167 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
5168 info->line, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
5169 len += size; 5237 len += size;
5170 pos = begin + len;
5171 5238
5172 if (pos < offset) { 5239 /* Output one line for each known port */
5173 len = 0; 5240 for (i = 0; i < NR_PORTS && cy_port[i].line >= 0; i++) {
5174 begin = pos; 5241 info = &cy_port[i];
5242
5243 if (info->count)
5244 size = sprintf(buf + len, "%3d %8lu %10lu %8lu %10lu "
5245 "%8lu %9lu %6ld\n", info->line,
5246 (cur_jifs - info->idle_stats.in_use) / HZ,
5247 info->idle_stats.xmit_bytes,
5248 (cur_jifs - info->idle_stats.xmit_idle) / HZ,
5249 info->idle_stats.recv_bytes,
5250 (cur_jifs - info->idle_stats.recv_idle) / HZ,
5251 info->idle_stats.overruns,
5252 (long)info->tty->ldisc.num);
5253 else
5254 size = sprintf(buf + len, "%3d %8lu %10lu %8lu %10lu "
5255 "%8lu %9lu %6ld\n",
5256 info->line, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
5257 len += size;
5258 pos = begin + len;
5259
5260 if (pos < offset) {
5261 len = 0;
5262 begin = pos;
5263 }
5264 if (pos > offset + length)
5265 goto done;
5175 } 5266 }
5176 if (pos > offset + length) 5267 *eof = 1;
5177 goto done;
5178 }
5179 *eof = 1;
5180done: 5268done:
5181 *start = buf + (offset - begin); /* Start of wanted data */ 5269 *start = buf + (offset - begin); /* Start of wanted data */
5182 len -= (offset - begin); /* Start slop */ 5270 len -= (offset - begin); /* Start slop */
5183 if (len > length) 5271 if (len > length)
5184 len = length; /* Ending slop */ 5272 len = length; /* Ending slop */
5185 if (len < 0) 5273 if (len < 0)
5186 len = 0; 5274 len = 0;
5187 return len; 5275 return len;
5188} 5276}
5189 5277
5190/* The serial driver boot-time initialization code! 5278/* The serial driver boot-time initialization code!
@@ -5205,295 +5293,289 @@ done:
5205 extra ports are ignored. 5293 extra ports are ignored.
5206 */ 5294 */
5207 5295
5208static struct tty_operations cy_ops = { 5296static const struct tty_operations cy_ops = {
5209 .open = cy_open, 5297 .open = cy_open,
5210 .close = cy_close, 5298 .close = cy_close,
5211 .write = cy_write, 5299 .write = cy_write,
5212 .put_char = cy_put_char, 5300 .put_char = cy_put_char,
5213 .flush_chars = cy_flush_chars, 5301 .flush_chars = cy_flush_chars,
5214 .write_room = cy_write_room, 5302 .write_room = cy_write_room,
5215 .chars_in_buffer = cy_chars_in_buffer, 5303 .chars_in_buffer = cy_chars_in_buffer,
5216 .flush_buffer = cy_flush_buffer, 5304 .flush_buffer = cy_flush_buffer,
5217 .ioctl = cy_ioctl, 5305 .ioctl = cy_ioctl,
5218 .throttle = cy_throttle, 5306 .throttle = cy_throttle,
5219 .unthrottle = cy_unthrottle, 5307 .unthrottle = cy_unthrottle,
5220 .set_termios = cy_set_termios, 5308 .set_termios = cy_set_termios,
5221 .stop = cy_stop, 5309 .stop = cy_stop,
5222 .start = cy_start, 5310 .start = cy_start,
5223 .hangup = cy_hangup, 5311 .hangup = cy_hangup,
5224 .break_ctl = cy_break, 5312 .break_ctl = cy_break,
5225 .wait_until_sent = cy_wait_until_sent, 5313 .wait_until_sent = cy_wait_until_sent,
5226 .read_proc = cyclades_get_proc_info, 5314 .read_proc = cyclades_get_proc_info,
5227 .tiocmget = cy_tiocmget, 5315 .tiocmget = cy_tiocmget,
5228 .tiocmset = cy_tiocmset, 5316 .tiocmset = cy_tiocmset,
5229}; 5317};
5230 5318
5231static int __init 5319static int __init cy_init(void)
5232cy_init(void)
5233{ 5320{
5234 struct cyclades_port *info; 5321 struct cyclades_port *info;
5235 struct cyclades_card *cinfo; 5322 struct cyclades_card *cinfo;
5236 int number_z_boards = 0; 5323 int number_z_boards = 0;
5237 int board,port,i,index; 5324 int board, port, i, index;
5238 unsigned long mailbox; 5325 unsigned long mailbox;
5239 unsigned short chip_number; 5326 unsigned short chip_number;
5240 int nports; 5327 int nports;
5241 5328
5242 cy_serial_driver = alloc_tty_driver(NR_PORTS); 5329 cy_serial_driver = alloc_tty_driver(NR_PORTS);
5243 if (!cy_serial_driver) 5330 if (!cy_serial_driver)
5244 return -ENOMEM; 5331 return -ENOMEM;
5245 show_version(); 5332 show_version();
5246 5333
5247 /* Initialize the tty_driver structure */ 5334 /* Initialize the tty_driver structure */
5248 5335
5249 cy_serial_driver->owner = THIS_MODULE; 5336 cy_serial_driver->owner = THIS_MODULE;
5250 cy_serial_driver->driver_name = "cyclades"; 5337 cy_serial_driver->driver_name = "cyclades";
5251 cy_serial_driver->name = "ttyC"; 5338 cy_serial_driver->name = "ttyC";
5252 cy_serial_driver->major = CYCLADES_MAJOR; 5339 cy_serial_driver->major = CYCLADES_MAJOR;
5253 cy_serial_driver->minor_start = 0; 5340 cy_serial_driver->minor_start = 0;
5254 cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL; 5341 cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
5255 cy_serial_driver->subtype = SERIAL_TYPE_NORMAL; 5342 cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
5256 cy_serial_driver->init_termios = tty_std_termios; 5343 cy_serial_driver->init_termios = tty_std_termios;
5257 cy_serial_driver->init_termios.c_cflag = 5344 cy_serial_driver->init_termios.c_cflag =
5258 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 5345 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
5259 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW; 5346 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
5260 tty_set_operations(cy_serial_driver, &cy_ops); 5347 tty_set_operations(cy_serial_driver, &cy_ops);
5261 5348
5262 if (tty_register_driver(cy_serial_driver)) 5349 if (tty_register_driver(cy_serial_driver))
5263 panic("Couldn't register Cyclades serial driver\n"); 5350 panic("Couldn't register Cyclades serial driver\n");
5264 5351
5265 for (i = 0; i < NR_CARDS; i++) { 5352 for (i = 0; i < NR_CARDS; i++) {
5266 /* base_addr=0 indicates board not found */ 5353 /* base_addr=0 indicates board not found */
5267 cy_card[i].base_addr = NULL; 5354 cy_card[i].base_addr = NULL;
5268 } 5355 }
5269 5356
5270 /* the code below is responsible to find the boards. Each different 5357 /* the code below is responsible to find the boards. Each different
5271 type of board has its own detection routine. If a board is found, 5358 type of board has its own detection routine. If a board is found,
5272 the next cy_card structure available is set by the detection 5359 the next cy_card structure available is set by the detection
5273 routine. These functions are responsible for checking the 5360 routine. These functions are responsible for checking the
5274 availability of cy_card and cy_port data structures and updating 5361 availability of cy_card and cy_port data structures and updating
5275 the cy_next_channel. */ 5362 the cy_next_channel. */
5276 5363
5277 /* look for isa boards */ 5364 /* look for isa boards */
5278 cy_isa_nboard = cy_detect_isa(); 5365 cy_isa_nboard = cy_detect_isa();
5279 5366
5280 /* look for pci boards */ 5367 /* look for pci boards */
5281 cy_pci_nboard = cy_detect_pci(); 5368 cy_pci_nboard = cy_detect_pci();
5282 5369
5283 cy_nboard = cy_isa_nboard + cy_pci_nboard; 5370 cy_nboard = cy_isa_nboard + cy_pci_nboard;
5284 5371
5285 /* invalidate remaining cy_card structures */ 5372 /* invalidate remaining cy_card structures */
5286 for (i = 0 ; i < NR_CARDS ; i++) { 5373 for (i = 0; i < NR_CARDS; i++) {
5287 if (cy_card[i].base_addr == 0) { 5374 if (cy_card[i].base_addr == 0) {
5288 cy_card[i].first_line = -1; 5375 cy_card[i].first_line = -1;
5289 cy_card[i].ctl_addr = NULL; 5376 cy_card[i].ctl_addr = NULL;
5290 cy_card[i].irq = 0; 5377 cy_card[i].irq = 0;
5291 cy_card[i].bus_index = 0; 5378 cy_card[i].bus_index = 0;
5292 cy_card[i].first_line = 0; 5379 cy_card[i].first_line = 0;
5293 cy_card[i].num_chips = 0; 5380 cy_card[i].num_chips = 0;
5294 } 5381 }
5295 } 5382 }
5296 /* invalidate remaining cy_port structures */ 5383 /* invalidate remaining cy_port structures */
5297 for (i = cy_next_channel ; i < NR_PORTS ; i++) { 5384 for (i = cy_next_channel; i < NR_PORTS; i++) {
5298 cy_port[i].line = -1; 5385 cy_port[i].line = -1;
5299 cy_port[i].magic = -1; 5386 cy_port[i].magic = -1;
5300 } 5387 }
5301 5388
5302 /* initialize per-port data structures for each valid board found */ 5389 /* initialize per-port data structures for each valid board found */
5303 for (board = 0 ; board < cy_nboard ; board++) { 5390 for (board = 0; board < cy_nboard; board++) {
5304 cinfo = &cy_card[board]; 5391 cinfo = &cy_card[board];
5305 if (cinfo->num_chips == -1) { /* Cyclades-Z */ 5392 if (cinfo->num_chips == -1) { /* Cyclades-Z */
5306 number_z_boards++; 5393 number_z_boards++;
5307 mailbox = cy_readl(&((struct RUNTIME_9060 __iomem *) 5394 mailbox = cy_readl(&((struct RUNTIME_9060 __iomem *)
5308 cy_card[board].ctl_addr)->mail_box_0); 5395 cy_card[board].ctl_addr)->
5309 nports = (mailbox == ZE_V1) ? ZE_V1_NPORTS : 8; 5396 mail_box_0);
5310 cinfo->intr_enabled = 0; 5397 nports = (mailbox == ZE_V1) ? ZE_V1_NPORTS : 8;
5311 cinfo->nports = 0; /* Will be correctly set later, after 5398 cinfo->intr_enabled = 0;
5312 Z FW is loaded */ 5399 cinfo->nports = 0; /* Will be correctly set later, after
5313 spin_lock_init(&cinfo->card_lock); 5400 Z FW is loaded */
5314 for (port = cinfo->first_line ; 5401 spin_lock_init(&cinfo->card_lock);
5315 port < cinfo->first_line + nports; 5402 for (port = cinfo->first_line;
5316 port++) 5403 port < cinfo->first_line + nports; port++) {
5317 { 5404 info = &cy_port[port];
5318 info = &cy_port[port]; 5405 info->magic = CYCLADES_MAGIC;
5319 info->magic = CYCLADES_MAGIC; 5406 info->type = PORT_STARTECH;
5320 info->type = PORT_STARTECH; 5407 info->card = board;
5321 info->card = board; 5408 info->line = port;
5322 info->line = port; 5409 info->chip_rev = 0;
5323 info->chip_rev = 0; 5410 info->flags = STD_COM_FLAGS;
5324 info->flags = STD_COM_FLAGS; 5411 info->tty = NULL;
5325 info->tty = NULL; 5412 if (mailbox == ZO_V1)
5326 if (mailbox == ZO_V1) 5413 info->xmit_fifo_size = CYZ_FIFO_SIZE;
5327 info->xmit_fifo_size = CYZ_FIFO_SIZE; 5414 else
5328 else 5415 info->xmit_fifo_size =
5329 info->xmit_fifo_size = 4 * CYZ_FIFO_SIZE; 5416 4 * CYZ_FIFO_SIZE;
5330 info->cor1 = 0; 5417 info->cor1 = 0;
5331 info->cor2 = 0; 5418 info->cor2 = 0;
5332 info->cor3 = 0; 5419 info->cor3 = 0;
5333 info->cor4 = 0; 5420 info->cor4 = 0;
5334 info->cor5 = 0; 5421 info->cor5 = 0;
5335 info->tbpr = 0; 5422 info->tbpr = 0;
5336 info->tco = 0; 5423 info->tco = 0;
5337 info->rbpr = 0; 5424 info->rbpr = 0;
5338 info->rco = 0; 5425 info->rco = 0;
5339 info->custom_divisor = 0; 5426 info->custom_divisor = 0;
5340 info->close_delay = 5*HZ/10; 5427 info->close_delay = 5 * HZ / 10;
5341 info->closing_wait = CLOSING_WAIT_DELAY; 5428 info->closing_wait = CLOSING_WAIT_DELAY;
5342 info->icount.cts = info->icount.dsr = 5429 info->icount.cts = info->icount.dsr =
5343 info->icount.rng = info->icount.dcd = 0; 5430 info->icount.rng = info->icount.dcd = 0;
5344 info->icount.rx = info->icount.tx = 0; 5431 info->icount.rx = info->icount.tx = 0;
5345 info->icount.frame = info->icount.parity = 0; 5432 info->icount.frame = info->icount.parity = 0;
5346 info->icount.overrun = info->icount.brk = 0; 5433 info->icount.overrun = info->icount.brk = 0;
5347 info->x_char = 0; 5434 info->x_char = 0;
5348 info->event = 0; 5435 info->event = 0;
5349 info->count = 0; 5436 info->count = 0;
5350 info->blocked_open = 0; 5437 info->blocked_open = 0;
5351 info->default_threshold = 0; 5438 info->default_threshold = 0;
5352 info->default_timeout = 0; 5439 info->default_timeout = 0;
5353 INIT_WORK(&info->tqueue, do_softint, info); 5440 INIT_WORK(&info->tqueue, do_softint);
5354 init_waitqueue_head(&info->open_wait); 5441 init_waitqueue_head(&info->open_wait);
5355 init_waitqueue_head(&info->close_wait); 5442 init_waitqueue_head(&info->close_wait);
5356 init_waitqueue_head(&info->shutdown_wait); 5443 init_waitqueue_head(&info->shutdown_wait);
5357 init_waitqueue_head(&info->delta_msr_wait); 5444 init_waitqueue_head(&info->delta_msr_wait);
5358 /* info->session */ 5445 /* info->session */
5359 /* info->pgrp */ 5446 /* info->pgrp */
5360 info->read_status_mask = 0; 5447 info->read_status_mask = 0;
5361 /* info->timeout */ 5448 /* info->timeout */
5362 /* Bentson's vars */ 5449 /* Bentson's vars */
5363 info->jiffies[0] = 0; 5450 info->jiffies[0] = 0;
5364 info->jiffies[1] = 0; 5451 info->jiffies[1] = 0;
5365 info->jiffies[2] = 0; 5452 info->jiffies[2] = 0;
5366 info->rflush_count = 0; 5453 info->rflush_count = 0;
5367#ifdef CONFIG_CYZ_INTR 5454#ifdef CONFIG_CYZ_INTR
5368 init_timer(&cyz_rx_full_timer[port]); 5455 init_timer(&cyz_rx_full_timer[port]);
5369 cyz_rx_full_timer[port].function = NULL; 5456 cyz_rx_full_timer[port].function = NULL;
5370#endif 5457#endif
5371 } 5458 }
5372 continue; 5459 continue;
5373 }else{ /* Cyclom-Y of some kind*/ 5460 } else { /* Cyclom-Y of some kind */
5374 index = cinfo->bus_index; 5461 index = cinfo->bus_index;
5375 spin_lock_init(&cinfo->card_lock); 5462 spin_lock_init(&cinfo->card_lock);
5376 cinfo->nports = CyPORTS_PER_CHIP * cinfo->num_chips; 5463 cinfo->nports = CyPORTS_PER_CHIP * cinfo->num_chips;
5377 for (port = cinfo->first_line ; 5464 for (port = cinfo->first_line;
5378 port < cinfo->first_line + cinfo->nports ; 5465 port < cinfo->first_line + cinfo->nports; port++) {
5379 port++) 5466 info = &cy_port[port];
5380 { 5467 info->magic = CYCLADES_MAGIC;
5381 info = &cy_port[port]; 5468 info->type = PORT_CIRRUS;
5382 info->magic = CYCLADES_MAGIC; 5469 info->card = board;
5383 info->type = PORT_CIRRUS; 5470 info->line = port;
5384 info->card = board; 5471 info->flags = STD_COM_FLAGS;
5385 info->line = port; 5472 info->tty = NULL;
5386 info->flags = STD_COM_FLAGS; 5473 info->xmit_fifo_size = CyMAX_CHAR_FIFO;
5387 info->tty = NULL; 5474 info->cor1 =
5388 info->xmit_fifo_size = CyMAX_CHAR_FIFO; 5475 CyPARITY_NONE | Cy_1_STOP | Cy_8_BITS;
5389 info->cor1 = CyPARITY_NONE|Cy_1_STOP|Cy_8_BITS; 5476 info->cor2 = CyETC;
5390 info->cor2 = CyETC; 5477 info->cor3 = 0x08; /* _very_ small rcv threshold */
5391 info->cor3 = 0x08; /* _very_ small rcv threshold */ 5478 info->cor4 = 0;
5392 info->cor4 = 0; 5479 info->cor5 = 0;
5393 info->cor5 = 0; 5480 info->custom_divisor = 0;
5394 info->custom_divisor = 0; 5481 info->close_delay = 5 * HZ / 10;
5395 info->close_delay = 5*HZ/10; 5482 info->closing_wait = CLOSING_WAIT_DELAY;
5396 info->closing_wait = CLOSING_WAIT_DELAY; 5483 info->icount.cts = info->icount.dsr =
5397 info->icount.cts = info->icount.dsr = 5484 info->icount.rng = info->icount.dcd = 0;
5398 info->icount.rng = info->icount.dcd = 0; 5485 info->icount.rx = info->icount.tx = 0;
5399 info->icount.rx = info->icount.tx = 0; 5486 info->icount.frame = info->icount.parity = 0;
5400 info->icount.frame = info->icount.parity = 0; 5487 info->icount.overrun = info->icount.brk = 0;
5401 info->icount.overrun = info->icount.brk = 0; 5488 chip_number = (port - cinfo->first_line) / 4;
5402 chip_number = (port - cinfo->first_line) / 4; 5489 if ((info->chip_rev =
5403 if ((info->chip_rev = 5490 cy_readb(cinfo->base_addr +
5404 cy_readb(cinfo->base_addr + 5491 (cy_chip_offset[chip_number] <<
5405 (cy_chip_offset[chip_number]<<index) + 5492 index) + (CyGFRCR << index))) >=
5406 (CyGFRCR<<index))) >= CD1400_REV_J) { 5493 CD1400_REV_J) {
5407 /* It is a CD1400 rev. J or later */ 5494 /* It is a CD1400 rev. J or later */
5408 info->tbpr = baud_bpr_60[13]; /* Tx BPR */ 5495 info->tbpr = baud_bpr_60[13]; /* Tx BPR */
5409 info->tco = baud_co_60[13]; /* Tx CO */ 5496 info->tco = baud_co_60[13]; /* Tx CO */
5410 info->rbpr = baud_bpr_60[13]; /* Rx BPR */ 5497 info->rbpr = baud_bpr_60[13]; /* Rx BPR */
5411 info->rco = baud_co_60[13]; /* Rx CO */ 5498 info->rco = baud_co_60[13]; /* Rx CO */
5412 info->rflow = 0; 5499 info->rflow = 0;
5413 info->rtsdtr_inv = 1; 5500 info->rtsdtr_inv = 1;
5414 } else { 5501 } else {
5415 info->tbpr = baud_bpr_25[13]; /* Tx BPR */ 5502 info->tbpr = baud_bpr_25[13]; /* Tx BPR */
5416 info->tco = baud_co_25[13]; /* Tx CO */ 5503 info->tco = baud_co_25[13]; /* Tx CO */
5417 info->rbpr = baud_bpr_25[13]; /* Rx BPR */ 5504 info->rbpr = baud_bpr_25[13]; /* Rx BPR */
5418 info->rco = baud_co_25[13]; /* Rx CO */ 5505 info->rco = baud_co_25[13]; /* Rx CO */
5419 info->rflow = 0; 5506 info->rflow = 0;
5420 info->rtsdtr_inv = 0; 5507 info->rtsdtr_inv = 0;
5421 } 5508 }
5422 info->x_char = 0; 5509 info->x_char = 0;
5423 info->event = 0; 5510 info->event = 0;
5424 info->count = 0; 5511 info->count = 0;
5425 info->blocked_open = 0; 5512 info->blocked_open = 0;
5426 info->default_threshold = 0; 5513 info->default_threshold = 0;
5427 info->default_timeout = 0; 5514 info->default_timeout = 0;
5428 INIT_WORK(&info->tqueue, do_softint, info); 5515 INIT_WORK(&info->tqueue, do_softint);
5429 init_waitqueue_head(&info->open_wait); 5516 init_waitqueue_head(&info->open_wait);
5430 init_waitqueue_head(&info->close_wait); 5517 init_waitqueue_head(&info->close_wait);
5431 init_waitqueue_head(&info->shutdown_wait); 5518 init_waitqueue_head(&info->shutdown_wait);
5432 init_waitqueue_head(&info->delta_msr_wait); 5519 init_waitqueue_head(&info->delta_msr_wait);
5433 /* info->session */ 5520 /* info->session */
5434 /* info->pgrp */ 5521 /* info->pgrp */
5435 info->read_status_mask = 5522 info->read_status_mask =
5436 CyTIMEOUT| CySPECHAR| CyBREAK 5523 CyTIMEOUT | CySPECHAR | CyBREAK
5437 | CyPARITY| CyFRAME| CyOVERRUN; 5524 | CyPARITY | CyFRAME | CyOVERRUN;
5438 /* info->timeout */ 5525 /* info->timeout */
5439 } 5526 }
5440 } 5527 }
5441 } 5528 }
5442 5529
5443#ifndef CONFIG_CYZ_INTR 5530#ifndef CONFIG_CYZ_INTR
5444 if (number_z_boards && !cyz_timeron){ 5531 if (number_z_boards && !cyz_timeron) {
5445 cyz_timeron++; 5532 cyz_timeron++;
5446 cyz_timerlist.expires = jiffies + 1; 5533 cyz_timerlist.expires = jiffies + 1;
5447 add_timer(&cyz_timerlist); 5534 add_timer(&cyz_timerlist);
5448#ifdef CY_PCI_DEBUG 5535#ifdef CY_PCI_DEBUG
5449 printk("Cyclades-Z polling initialized\n"); 5536 printk("Cyclades-Z polling initialized\n");
5450#endif 5537#endif
5451 } 5538 }
5452#endif /* CONFIG_CYZ_INTR */ 5539#endif /* CONFIG_CYZ_INTR */
5540
5541 return 0;
5453 5542
5454 return 0; 5543} /* cy_init */
5455
5456} /* cy_init */
5457 5544
5458static void __exit 5545static void __exit cy_cleanup_module(void)
5459cy_cleanup_module(void)
5460{ 5546{
5461 int i, e1; 5547 int i, e1;
5462 5548
5463#ifndef CONFIG_CYZ_INTR 5549#ifndef CONFIG_CYZ_INTR
5464 if (cyz_timeron){ 5550 if (cyz_timeron){
5465 cyz_timeron = 0; 5551 cyz_timeron = 0;
5466 del_timer(&cyz_timerlist); 5552 del_timer(&cyz_timerlist);
5467 } 5553 }
5468#endif /* CONFIG_CYZ_INTR */ 5554#endif /* CONFIG_CYZ_INTR */
5469 5555
5470 if ((e1 = tty_unregister_driver(cy_serial_driver))) 5556 if ((e1 = tty_unregister_driver(cy_serial_driver)))
5471 printk("cyc: failed to unregister Cyclades serial driver(%d)\n", 5557 printk("cyc: failed to unregister Cyclades serial driver(%d)\n",
5472 e1); 5558 e1);
5473 5559
5474 put_tty_driver(cy_serial_driver); 5560 put_tty_driver(cy_serial_driver);
5475 5561
5476 for (i = 0; i < NR_CARDS; i++) { 5562 for (i = 0; i < NR_CARDS; i++) {
5477 if (cy_card[i].base_addr) { 5563 if (cy_card[i].base_addr) {
5478 iounmap(cy_card[i].base_addr); 5564 iounmap(cy_card[i].base_addr);
5479 if (cy_card[i].ctl_addr) 5565 if (cy_card[i].ctl_addr)
5480 iounmap(cy_card[i].ctl_addr); 5566 iounmap(cy_card[i].ctl_addr);
5481 if (cy_card[i].irq 5567 if (cy_card[i].irq
5482#ifndef CONFIG_CYZ_INTR 5568#ifndef CONFIG_CYZ_INTR
5483 && cy_card[i].num_chips != -1 /* not a Z card */ 5569 && cy_card[i].num_chips != -1 /* not a Z card */
5484#endif /* CONFIG_CYZ_INTR */ 5570#endif /* CONFIG_CYZ_INTR */
5485 ) 5571 )
5486 free_irq(cy_card[i].irq, &cy_card[i]); 5572 free_irq(cy_card[i].irq, &cy_card[i]);
5487#ifdef CONFIG_PCI 5573#ifdef CONFIG_PCI
5488 if (cy_card[i].pdev) 5574 if (cy_card[i].pdev)
5489 pci_release_regions(cy_card[i].pdev); 5575 pci_release_regions(cy_card[i].pdev);
5490#endif 5576#endif
5491 } 5577 }
5492 } 5578 }
5493 if (tmp_buf) {
5494 free_page((unsigned long) tmp_buf);
5495 tmp_buf = NULL;
5496 }
5497} /* cy_cleanup_module */ 5579} /* cy_cleanup_module */
5498 5580
5499module_init(cy_init); 5581module_init(cy_init);
diff --git a/drivers/char/decserial.c b/drivers/char/decserial.c
index 85f404e25c73..8ea2bea2b183 100644
--- a/drivers/char/decserial.c
+++ b/drivers/char/decserial.c
@@ -23,20 +23,12 @@
23extern int zs_init(void); 23extern int zs_init(void);
24#endif 24#endif
25 25
26#ifdef CONFIG_DZ
27extern int dz_init(void);
28#endif
29
30#ifdef CONFIG_SERIAL_CONSOLE 26#ifdef CONFIG_SERIAL_CONSOLE
31 27
32#ifdef CONFIG_ZS 28#ifdef CONFIG_ZS
33extern void zs_serial_console_init(void); 29extern void zs_serial_console_init(void);
34#endif 30#endif
35 31
36#ifdef CONFIG_DZ
37extern void dz_serial_console_init(void);
38#endif
39
40#endif 32#endif
41 33
42/* rs_init - starts up the serial interface - 34/* rs_init - starts up the serial interface -
@@ -46,23 +38,11 @@ extern void dz_serial_console_init(void);
46 38
47int __init rs_init(void) 39int __init rs_init(void)
48{ 40{
49 41#ifdef CONFIG_ZS
50#if defined(CONFIG_ZS) && defined(CONFIG_DZ)
51 if (IOASIC) 42 if (IOASIC)
52 return zs_init(); 43 return zs_init();
53 else
54 return dz_init();
55#else
56
57#ifdef CONFIG_ZS
58 return zs_init();
59#endif
60
61#ifdef CONFIG_DZ
62 return dz_init();
63#endif
64
65#endif 44#endif
45 return -ENXIO;
66} 46}
67 47
68__initcall(rs_init); 48__initcall(rs_init);
@@ -76,21 +56,9 @@ __initcall(rs_init);
76 */ 56 */
77static int __init decserial_console_init(void) 57static int __init decserial_console_init(void)
78{ 58{
79#if defined(CONFIG_ZS) && defined(CONFIG_DZ) 59#ifdef CONFIG_ZS
80 if (IOASIC) 60 if (IOASIC)
81 zs_serial_console_init(); 61 zs_serial_console_init();
82 else
83 dz_serial_console_init();
84#else
85
86#ifdef CONFIG_ZS
87 zs_serial_console_init();
88#endif
89
90#ifdef CONFIG_DZ
91 dz_serial_console_init();
92#endif
93
94#endif 62#endif
95 return 0; 63 return 0;
96} 64}
diff --git a/drivers/char/drm/Kconfig b/drivers/char/drm/Kconfig
index 5278c388d3e7..ef833a1c27eb 100644
--- a/drivers/char/drm/Kconfig
+++ b/drivers/char/drm/Kconfig
@@ -60,7 +60,9 @@ config DRM_I830
60 Choose this option if you have a system that has Intel 830M, 845G, 60 Choose this option if you have a system that has Intel 830M, 845G,
61 852GM, 855GM or 865G integrated graphics. If M is selected, the 61 852GM, 855GM or 865G integrated graphics. If M is selected, the
62 module will be called i830. AGP support is required for this driver 62 module will be called i830. AGP support is required for this driver
63 to work. This driver will eventually be replaced by the i915 one. 63 to work. This driver is used by the older X releases X.org 6.7 and
64 XFree86 4.3. If unsure, build this and i915 as modules and the X server
65 will load the correct one.
64 66
65config DRM_I915 67config DRM_I915
66 tristate "i915 driver" 68 tristate "i915 driver"
@@ -68,8 +70,9 @@ config DRM_I915
68 Choose this option if you have a system that has Intel 830M, 845G, 70 Choose this option if you have a system that has Intel 830M, 845G,
69 852GM, 855GM 865G or 915G integrated graphics. If M is selected, the 71 852GM, 855GM 865G or 915G integrated graphics. If M is selected, the
70 module will be called i915. AGP support is required for this driver 72 module will be called i915. AGP support is required for this driver
71 to work. This driver will eventually replace the I830 driver, when 73 to work. This driver is used by the Intel driver in X.org 6.8 and
72 later release of X start to use the new DDX and DRI. 74 XFree86 4.4 and above. If unsure, build this and i830 as modules and
75 the X server will load the correct one.
73 76
74endchoice 77endchoice
75 78
diff --git a/drivers/char/drm/Makefile b/drivers/char/drm/Makefile
index 9d180c42816c..3ad0f648c6b2 100644
--- a/drivers/char/drm/Makefile
+++ b/drivers/char/drm/Makefile
@@ -6,7 +6,7 @@ drm-objs := drm_auth.o drm_bufs.o drm_context.o drm_dma.o drm_drawable.o \
6 drm_drv.o drm_fops.o drm_ioctl.o drm_irq.o \ 6 drm_drv.o drm_fops.o drm_ioctl.o drm_irq.o \
7 drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \ 7 drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \
8 drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \ 8 drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \
9 drm_sysfs.o 9 drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o
10 10
11tdfx-objs := tdfx_drv.o 11tdfx-objs := tdfx_drv.o
12r128-objs := r128_drv.o r128_cce.o r128_state.o r128_irq.o 12r128-objs := r128_drv.o r128_cce.o r128_state.o r128_irq.o
@@ -16,9 +16,9 @@ i830-objs := i830_drv.o i830_dma.o i830_irq.o
16i915-objs := i915_drv.o i915_dma.o i915_irq.o i915_mem.o 16i915-objs := i915_drv.o i915_dma.o i915_irq.o i915_mem.o
17radeon-objs := radeon_drv.o radeon_cp.o radeon_state.o radeon_mem.o radeon_irq.o r300_cmdbuf.o 17radeon-objs := radeon_drv.o radeon_cp.o radeon_state.o radeon_mem.o radeon_irq.o r300_cmdbuf.o
18ffb-objs := ffb_drv.o ffb_context.o 18ffb-objs := ffb_drv.o ffb_context.o
19sis-objs := sis_drv.o sis_ds.o sis_mm.o 19sis-objs := sis_drv.o sis_mm.o
20savage-objs := savage_drv.o savage_bci.o savage_state.o 20savage-objs := savage_drv.o savage_bci.o savage_state.o
21via-objs := via_irq.o via_drv.o via_ds.o via_map.o via_mm.o via_dma.o via_verifier.o via_video.o via_dmablit.o 21via-objs := via_irq.o via_drv.o via_map.o via_mm.o via_dma.o via_verifier.o via_video.o via_dmablit.o
22 22
23ifeq ($(CONFIG_COMPAT),y) 23ifeq ($(CONFIG_COMPAT),y)
24drm-objs += drm_ioc32.o 24drm-objs += drm_ioc32.o
diff --git a/drivers/char/drm/drm.h b/drivers/char/drm/drm.h
index 5642ac43e0f5..8db9041e306c 100644
--- a/drivers/char/drm/drm.h
+++ b/drivers/char/drm/drm.h
@@ -117,6 +117,14 @@ typedef struct drm_clip_rect {
117} drm_clip_rect_t; 117} drm_clip_rect_t;
118 118
119/** 119/**
120 * Drawable information.
121 */
122typedef struct drm_drawable_info {
123 unsigned int num_rects;
124 drm_clip_rect_t *rects;
125} drm_drawable_info_t;
126
127/**
120 * Texture region, 128 * Texture region,
121 */ 129 */
122typedef struct drm_tex_region { 130typedef struct drm_tex_region {
@@ -348,7 +356,8 @@ typedef struct drm_buf_desc {
348 _DRM_PAGE_ALIGN = 0x01, /**< Align on page boundaries for DMA */ 356 _DRM_PAGE_ALIGN = 0x01, /**< Align on page boundaries for DMA */
349 _DRM_AGP_BUFFER = 0x02, /**< Buffer is in AGP space */ 357 _DRM_AGP_BUFFER = 0x02, /**< Buffer is in AGP space */
350 _DRM_SG_BUFFER = 0x04, /**< Scatter/gather memory buffer */ 358 _DRM_SG_BUFFER = 0x04, /**< Scatter/gather memory buffer */
351 _DRM_FB_BUFFER = 0x08 /**< Buffer is in frame buffer */ 359 _DRM_FB_BUFFER = 0x08, /**< Buffer is in frame buffer */
360 _DRM_PCI_BUFFER_RO = 0x10 /**< Map PCI DMA buffer read-only */
352 } flags; 361 } flags;
353 unsigned long agp_start; /**< 362 unsigned long agp_start; /**<
354 * Start address of where the AGP buffers are 363 * Start address of where the AGP buffers are
@@ -444,6 +453,20 @@ typedef struct drm_draw {
444} drm_draw_t; 453} drm_draw_t;
445 454
446/** 455/**
456 * DRM_IOCTL_UPDATE_DRAW ioctl argument type.
457 */
458typedef enum {
459 DRM_DRAWABLE_CLIPRECTS,
460} drm_drawable_info_type_t;
461
462typedef struct drm_update_draw {
463 drm_drawable_t handle;
464 unsigned int type;
465 unsigned int num;
466 unsigned long long data;
467} drm_update_draw_t;
468
469/**
447 * DRM_IOCTL_GET_MAGIC and DRM_IOCTL_AUTH_MAGIC ioctl argument type. 470 * DRM_IOCTL_GET_MAGIC and DRM_IOCTL_AUTH_MAGIC ioctl argument type.
448 */ 471 */
449typedef struct drm_auth { 472typedef struct drm_auth {
@@ -465,10 +488,14 @@ typedef struct drm_irq_busid {
465typedef enum { 488typedef enum {
466 _DRM_VBLANK_ABSOLUTE = 0x0, /**< Wait for specific vblank sequence number */ 489 _DRM_VBLANK_ABSOLUTE = 0x0, /**< Wait for specific vblank sequence number */
467 _DRM_VBLANK_RELATIVE = 0x1, /**< Wait for given number of vblanks */ 490 _DRM_VBLANK_RELATIVE = 0x1, /**< Wait for given number of vblanks */
491 _DRM_VBLANK_NEXTONMISS = 0x10000000, /**< If missed, wait for next vblank */
492 _DRM_VBLANK_SECONDARY = 0x20000000, /**< Secondary display controller */
468 _DRM_VBLANK_SIGNAL = 0x40000000 /**< Send signal instead of blocking */ 493 _DRM_VBLANK_SIGNAL = 0x40000000 /**< Send signal instead of blocking */
469} drm_vblank_seq_type_t; 494} drm_vblank_seq_type_t;
470 495
471#define _DRM_VBLANK_FLAGS_MASK _DRM_VBLANK_SIGNAL 496#define _DRM_VBLANK_TYPES_MASK (_DRM_VBLANK_ABSOLUTE | _DRM_VBLANK_RELATIVE)
497#define _DRM_VBLANK_FLAGS_MASK (_DRM_VBLANK_SIGNAL | _DRM_VBLANK_SECONDARY | \
498 _DRM_VBLANK_NEXTONMISS)
472 499
473struct drm_wait_vblank_request { 500struct drm_wait_vblank_request {
474 drm_vblank_seq_type_t type; 501 drm_vblank_seq_type_t type;
@@ -623,6 +650,8 @@ typedef struct drm_set_version {
623 650
624#define DRM_IOCTL_WAIT_VBLANK DRM_IOWR(0x3a, drm_wait_vblank_t) 651#define DRM_IOCTL_WAIT_VBLANK DRM_IOWR(0x3a, drm_wait_vblank_t)
625 652
653#define DRM_IOCTL_UPDATE_DRAW DRM_IOW(0x3f, drm_update_draw_t)
654
626/** 655/**
627 * Device specific ioctls should only be in their respective headers 656 * Device specific ioctls should only be in their respective headers
628 * The device specific ioctl range is from 0x40 to 0x79. 657 * The device specific ioctl range is from 0x40 to 0x79.
diff --git a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h
index d2a56182bc35..0bbb04f2390f 100644
--- a/drivers/char/drm/drmP.h
+++ b/drivers/char/drm/drmP.h
@@ -79,6 +79,7 @@
79#define __OS_HAS_MTRR (defined(CONFIG_MTRR)) 79#define __OS_HAS_MTRR (defined(CONFIG_MTRR))
80 80
81#include "drm_os_linux.h" 81#include "drm_os_linux.h"
82#include "drm_hashtab.h"
82 83
83/***********************************************************************/ 84/***********************************************************************/
84/** \name DRM template customization defaults */ 85/** \name DRM template customization defaults */
@@ -96,6 +97,7 @@
96#define DRIVER_IRQ_VBL 0x100 97#define DRIVER_IRQ_VBL 0x100
97#define DRIVER_DMA_QUEUE 0x200 98#define DRIVER_DMA_QUEUE 0x200
98#define DRIVER_FB_DMA 0x400 99#define DRIVER_FB_DMA 0x400
100#define DRIVER_IRQ_VBL2 0x800
99 101
100/***********************************************************************/ 102/***********************************************************************/
101/** \name Begin the DRM... */ 103/** \name Begin the DRM... */
@@ -104,7 +106,7 @@
104#define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then 106#define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
105 also include looping detection. */ 107 also include looping detection. */
106 108
107#define DRM_HASH_SIZE 16 /**< Size of key hash table. Must be power of 2. */ 109#define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
108#define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */ 110#define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
109#define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */ 111#define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
110#define DRM_LOOPING_LIMIT 5000000 112#define DRM_LOOPING_LIMIT 5000000
@@ -134,19 +136,12 @@
134#define DRM_MEM_CTXBITMAP 18 136#define DRM_MEM_CTXBITMAP 18
135#define DRM_MEM_STUB 19 137#define DRM_MEM_STUB 19
136#define DRM_MEM_SGLISTS 20 138#define DRM_MEM_SGLISTS 20
137#define DRM_MEM_CTXLIST 21 139#define DRM_MEM_CTXLIST 21
140#define DRM_MEM_MM 22
141#define DRM_MEM_HASHTAB 23
138 142
139#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8) 143#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
140 144#define DRM_MAP_HASH_OFFSET 0x10000000
141/*@}*/
142
143/***********************************************************************/
144/** \name Backward compatibility section */
145/*@{*/
146
147#define DRM_RPR_ARG(vma) vma,
148
149#define VM_OFFSET(vma) ((vma)->vm_pgoff << PAGE_SHIFT)
150 145
151/*@}*/ 146/*@}*/
152 147
@@ -211,8 +206,6 @@
211/*@{*/ 206/*@{*/
212 207
213#define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x) 208#define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
214#define DRM_MIN(a,b) min(a,b)
215#define DRM_MAX(a,b) max(a,b)
216 209
217#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1)) 210#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
218#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x)) 211#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
@@ -286,7 +279,8 @@ typedef struct drm_devstate {
286} drm_devstate_t; 279} drm_devstate_t;
287 280
288typedef struct drm_magic_entry { 281typedef struct drm_magic_entry {
289 drm_magic_t magic; 282 drm_hash_item_t hash_item;
283 struct list_head head;
290 struct drm_file *priv; 284 struct drm_file *priv;
291 struct drm_magic_entry *next; 285 struct drm_magic_entry *next;
292} drm_magic_entry_t; 286} drm_magic_entry_t;
@@ -437,7 +431,8 @@ typedef struct drm_device_dma {
437 enum { 431 enum {
438 _DRM_DMA_USE_AGP = 0x01, 432 _DRM_DMA_USE_AGP = 0x01,
439 _DRM_DMA_USE_SG = 0x02, 433 _DRM_DMA_USE_SG = 0x02,
440 _DRM_DMA_USE_FB = 0x04 434 _DRM_DMA_USE_FB = 0x04,
435 _DRM_DMA_USE_PCI_RO = 0x08
441 } flags; 436 } flags;
442 437
443} drm_device_dma_t; 438} drm_device_dma_t;
@@ -493,6 +488,7 @@ typedef struct drm_sigdata {
493 */ 488 */
494typedef struct drm_map_list { 489typedef struct drm_map_list {
495 struct list_head head; /**< list head */ 490 struct list_head head; /**< list head */
491 drm_hash_item_t hash;
496 drm_map_t *map; /**< mapping */ 492 drm_map_t *map; /**< mapping */
497 unsigned int user_token; 493 unsigned int user_token;
498} drm_map_list_t; 494} drm_map_list_t;
@@ -527,6 +523,22 @@ typedef struct ati_pcigart_info {
527 drm_local_map_t mapping; 523 drm_local_map_t mapping;
528} drm_ati_pcigart_info; 524} drm_ati_pcigart_info;
529 525
526/*
527 * Generic memory manager structs
528 */
529typedef struct drm_mm_node {
530 struct list_head fl_entry;
531 struct list_head ml_entry;
532 int free;
533 unsigned long start;
534 unsigned long size;
535 void *private;
536} drm_mm_node_t;
537
538typedef struct drm_mm {
539 drm_mm_node_t root_node;
540} drm_mm_t;
541
530/** 542/**
531 * DRM driver structure. This structure represent the common code for 543 * DRM driver structure. This structure represent the common code for
532 * a family of cards. There will one drm_device for each card present 544 * a family of cards. There will one drm_device for each card present
@@ -552,6 +564,7 @@ struct drm_driver {
552 void (*kernel_context_switch_unlock) (struct drm_device * dev, 564 void (*kernel_context_switch_unlock) (struct drm_device * dev,
553 drm_lock_t *lock); 565 drm_lock_t *lock);
554 int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence); 566 int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence);
567 int (*vblank_wait2) (struct drm_device * dev, unsigned int *sequence);
555 int (*dri_library_name) (struct drm_device *dev, char *buf); 568 int (*dri_library_name) (struct drm_device *dev, char *buf);
556 569
557 /** 570 /**
@@ -646,13 +659,15 @@ typedef struct drm_device {
646 /*@{ */ 659 /*@{ */
647 drm_file_t *file_first; /**< file list head */ 660 drm_file_t *file_first; /**< file list head */
648 drm_file_t *file_last; /**< file list tail */ 661 drm_file_t *file_last; /**< file list tail */
649 drm_magic_head_t magiclist[DRM_HASH_SIZE]; /**< magic hash table */ 662 drm_open_hash_t magiclist; /**< magic hash table */
663 struct list_head magicfree;
650 /*@} */ 664 /*@} */
651 665
652 /** \name Memory management */ 666 /** \name Memory management */
653 /*@{ */ 667 /*@{ */
654 drm_map_list_t *maplist; /**< Linked list of regions */ 668 drm_map_list_t *maplist; /**< Linked list of regions */
655 int map_count; /**< Number of mappable regions */ 669 int map_count; /**< Number of mappable regions */
670 drm_open_hash_t map_hash; /**< User token hash table for maps */
656 671
657 /** \name Context handle management */ 672 /** \name Context handle management */
658 /*@{ */ 673 /*@{ */
@@ -696,9 +711,13 @@ typedef struct drm_device {
696 711
697 wait_queue_head_t vbl_queue; /**< VBLANK wait queue */ 712 wait_queue_head_t vbl_queue; /**< VBLANK wait queue */
698 atomic_t vbl_received; 713 atomic_t vbl_received;
714 atomic_t vbl_received2; /**< number of secondary VBLANK interrupts */
699 spinlock_t vbl_lock; 715 spinlock_t vbl_lock;
700 drm_vbl_sig_t vbl_sigs; /**< signal list to send on VBLANK */ 716 drm_vbl_sig_t vbl_sigs; /**< signal list to send on VBLANK */
717 drm_vbl_sig_t vbl_sigs2; /**< signals to send on secondary VBLANK */
701 unsigned int vbl_pending; 718 unsigned int vbl_pending;
719 spinlock_t tasklet_lock; /**< For drm_locked_tasklet */
720 void (*locked_tasklet_func)(struct drm_device *dev);
702 721
703 /*@} */ 722 /*@} */
704 cycles_t ctx_start; 723 cycles_t ctx_start;
@@ -711,10 +730,8 @@ typedef struct drm_device {
711 drm_agp_head_t *agp; /**< AGP data */ 730 drm_agp_head_t *agp; /**< AGP data */
712 731
713 struct pci_dev *pdev; /**< PCI device structure */ 732 struct pci_dev *pdev; /**< PCI device structure */
714 int pci_domain; /**< PCI bus domain number */ 733 int pci_vendor; /**< PCI vendor id */
715 int pci_bus; /**< PCI bus number */ 734 int pci_device; /**< PCI device id */
716 int pci_slot; /**< PCI slot number */
717 int pci_func; /**< PCI function number */
718#ifdef __alpha__ 735#ifdef __alpha__
719 struct pci_controller *hose; 736 struct pci_controller *hose;
720#endif 737#endif
@@ -728,6 +745,15 @@ typedef struct drm_device {
728 drm_local_map_t *agp_buffer_map; 745 drm_local_map_t *agp_buffer_map;
729 unsigned int agp_buffer_token; 746 unsigned int agp_buffer_token;
730 drm_head_t primary; /**< primary screen head */ 747 drm_head_t primary; /**< primary screen head */
748
749 /** \name Drawable information */
750 /*@{ */
751 spinlock_t drw_lock;
752 unsigned int drw_bitfield_length;
753 u32 *drw_bitfield;
754 unsigned int drw_info_length;
755 drm_drawable_info_t **drw_info;
756 /*@} */
731} drm_device_t; 757} drm_device_t;
732 758
733static __inline__ int drm_core_check_feature(struct drm_device *dev, 759static __inline__ int drm_core_check_feature(struct drm_device *dev,
@@ -736,6 +762,12 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev,
736 return ((dev->driver->driver_features & feature) ? 1 : 0); 762 return ((dev->driver->driver_features & feature) ? 1 : 0);
737} 763}
738 764
765#ifdef __alpha__
766#define drm_get_pci_domain(dev) dev->hose->bus->number
767#else
768#define drm_get_pci_domain(dev) 0
769#endif
770
739#if __OS_HAS_AGP 771#if __OS_HAS_AGP
740static inline int drm_core_has_AGP(struct drm_device *dev) 772static inline int drm_core_has_AGP(struct drm_device *dev)
741{ 773{
@@ -869,6 +901,10 @@ extern int drm_adddraw(struct inode *inode, struct file *filp,
869 unsigned int cmd, unsigned long arg); 901 unsigned int cmd, unsigned long arg);
870extern int drm_rmdraw(struct inode *inode, struct file *filp, 902extern int drm_rmdraw(struct inode *inode, struct file *filp,
871 unsigned int cmd, unsigned long arg); 903 unsigned int cmd, unsigned long arg);
904extern int drm_update_drawable_info(struct inode *inode, struct file *filp,
905 unsigned int cmd, unsigned long arg);
906extern drm_drawable_info_t *drm_get_drawable_info(drm_device_t *dev,
907 drm_drawable_t id);
872 908
873 /* Authentication IOCTL support (drm_auth.h) */ 909 /* Authentication IOCTL support (drm_auth.h) */
874extern int drm_getmagic(struct inode *inode, struct file *filp, 910extern int drm_getmagic(struct inode *inode, struct file *filp,
@@ -933,6 +969,7 @@ extern int drm_wait_vblank(struct inode *inode, struct file *filp,
933 unsigned int cmd, unsigned long arg); 969 unsigned int cmd, unsigned long arg);
934extern int drm_vblank_wait(drm_device_t * dev, unsigned int *vbl_seq); 970extern int drm_vblank_wait(drm_device_t * dev, unsigned int *vbl_seq);
935extern void drm_vbl_send_signals(drm_device_t * dev); 971extern void drm_vbl_send_signals(drm_device_t * dev);
972extern void drm_locked_tasklet(drm_device_t *dev, void(*func)(drm_device_t*));
936 973
937 /* AGP/GART support (drm_agpsupport.h) */ 974 /* AGP/GART support (drm_agpsupport.h) */
938extern drm_agp_head_t *drm_agp_init(drm_device_t * dev); 975extern drm_agp_head_t *drm_agp_init(drm_device_t * dev);
@@ -1011,6 +1048,18 @@ extern struct class_device *drm_sysfs_device_add(struct class *cs,
1011 drm_head_t *head); 1048 drm_head_t *head);
1012extern void drm_sysfs_device_remove(struct class_device *class_dev); 1049extern void drm_sysfs_device_remove(struct class_device *class_dev);
1013 1050
1051/*
1052 * Basic memory manager support (drm_mm.c)
1053 */
1054extern drm_mm_node_t *drm_mm_get_block(drm_mm_node_t * parent,
1055 unsigned long size,
1056 unsigned alignment);
1057extern void drm_mm_put_block(drm_mm_t *mm, drm_mm_node_t *cur);
1058extern drm_mm_node_t *drm_mm_search_free(const drm_mm_t *mm, unsigned long size,
1059 unsigned alignment, int best_match);
1060extern int drm_mm_init(drm_mm_t *mm, unsigned long start, unsigned long size);
1061extern void drm_mm_takedown(drm_mm_t *mm);
1062
1014/* Inline replacements for DRM_IOREMAP macros */ 1063/* Inline replacements for DRM_IOREMAP macros */
1015static __inline__ void drm_core_ioremap(struct drm_map *map, 1064static __inline__ void drm_core_ioremap(struct drm_map *map,
1016 struct drm_device *dev) 1065 struct drm_device *dev)
diff --git a/drivers/char/drm/drm_auth.c b/drivers/char/drm/drm_auth.c
index 2a37586a7ee8..c7b19d35bcd6 100644
--- a/drivers/char/drm/drm_auth.c
+++ b/drivers/char/drm/drm_auth.c
@@ -36,20 +36,6 @@
36#include "drmP.h" 36#include "drmP.h"
37 37
38/** 38/**
39 * Generate a hash key from a magic.
40 *
41 * \param magic magic.
42 * \return hash key.
43 *
44 * The key is the modulus of the hash table size, #DRM_HASH_SIZE, which must be
45 * a power of 2.
46 */
47static int drm_hash_magic(drm_magic_t magic)
48{
49 return magic & (DRM_HASH_SIZE - 1);
50}
51
52/**
53 * Find the file with the given magic number. 39 * Find the file with the given magic number.
54 * 40 *
55 * \param dev DRM device. 41 * \param dev DRM device.
@@ -63,14 +49,12 @@ static drm_file_t *drm_find_file(drm_device_t * dev, drm_magic_t magic)
63{ 49{
64 drm_file_t *retval = NULL; 50 drm_file_t *retval = NULL;
65 drm_magic_entry_t *pt; 51 drm_magic_entry_t *pt;
66 int hash = drm_hash_magic(magic); 52 drm_hash_item_t *hash;
67 53
68 mutex_lock(&dev->struct_mutex); 54 mutex_lock(&dev->struct_mutex);
69 for (pt = dev->magiclist[hash].head; pt; pt = pt->next) { 55 if (!drm_ht_find_item(&dev->magiclist, (unsigned long)magic, &hash)) {
70 if (pt->magic == magic) { 56 pt = drm_hash_entry(hash, drm_magic_entry_t, hash_item);
71 retval = pt->priv; 57 retval = pt->priv;
72 break;
73 }
74 } 58 }
75 mutex_unlock(&dev->struct_mutex); 59 mutex_unlock(&dev->struct_mutex);
76 return retval; 60 return retval;
@@ -90,28 +74,20 @@ static drm_file_t *drm_find_file(drm_device_t * dev, drm_magic_t magic)
90static int drm_add_magic(drm_device_t * dev, drm_file_t * priv, 74static int drm_add_magic(drm_device_t * dev, drm_file_t * priv,
91 drm_magic_t magic) 75 drm_magic_t magic)
92{ 76{
93 int hash;
94 drm_magic_entry_t *entry; 77 drm_magic_entry_t *entry;
95 78
96 DRM_DEBUG("%d\n", magic); 79 DRM_DEBUG("%d\n", magic);
97 80
98 hash = drm_hash_magic(magic);
99 entry = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC); 81 entry = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC);
100 if (!entry) 82 if (!entry)
101 return -ENOMEM; 83 return -ENOMEM;
102 memset(entry, 0, sizeof(*entry)); 84 memset(entry, 0, sizeof(*entry));
103 entry->magic = magic;
104 entry->priv = priv; 85 entry->priv = priv;
105 entry->next = NULL;
106 86
87 entry->hash_item.key = (unsigned long)magic;
107 mutex_lock(&dev->struct_mutex); 88 mutex_lock(&dev->struct_mutex);
108 if (dev->magiclist[hash].tail) { 89 drm_ht_insert_item(&dev->magiclist, &entry->hash_item);
109 dev->magiclist[hash].tail->next = entry; 90 list_add_tail(&entry->head, &dev->magicfree);
110 dev->magiclist[hash].tail = entry;
111 } else {
112 dev->magiclist[hash].head = entry;
113 dev->magiclist[hash].tail = entry;
114 }
115 mutex_unlock(&dev->struct_mutex); 91 mutex_unlock(&dev->struct_mutex);
116 92
117 return 0; 93 return 0;
@@ -128,34 +104,24 @@ static int drm_add_magic(drm_device_t * dev, drm_file_t * priv,
128 */ 104 */
129static int drm_remove_magic(drm_device_t * dev, drm_magic_t magic) 105static int drm_remove_magic(drm_device_t * dev, drm_magic_t magic)
130{ 106{
131 drm_magic_entry_t *prev = NULL;
132 drm_magic_entry_t *pt; 107 drm_magic_entry_t *pt;
133 int hash; 108 drm_hash_item_t *hash;
134 109
135 DRM_DEBUG("%d\n", magic); 110 DRM_DEBUG("%d\n", magic);
136 hash = drm_hash_magic(magic);
137 111
138 mutex_lock(&dev->struct_mutex); 112 mutex_lock(&dev->struct_mutex);
139 for (pt = dev->magiclist[hash].head; pt; prev = pt, pt = pt->next) { 113 if (drm_ht_find_item(&dev->magiclist, (unsigned long)magic, &hash)) {
140 if (pt->magic == magic) { 114 mutex_unlock(&dev->struct_mutex);
141 if (dev->magiclist[hash].head == pt) { 115 return -EINVAL;
142 dev->magiclist[hash].head = pt->next;
143 }
144 if (dev->magiclist[hash].tail == pt) {
145 dev->magiclist[hash].tail = prev;
146 }
147 if (prev) {
148 prev->next = pt->next;
149 }
150 mutex_unlock(&dev->struct_mutex);
151 return 0;
152 }
153 } 116 }
117 pt = drm_hash_entry(hash, drm_magic_entry_t, hash_item);
118 drm_ht_remove_item(&dev->magiclist, hash);
119 list_del(&pt->head);
154 mutex_unlock(&dev->struct_mutex); 120 mutex_unlock(&dev->struct_mutex);
155 121
156 drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC); 122 drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
157 123
158 return -EINVAL; 124 return 0;
159} 125}
160 126
161/** 127/**
diff --git a/drivers/char/drm/drm_bufs.c b/drivers/char/drm/drm_bufs.c
index 006b06d29727..9f65f5697ba8 100644
--- a/drivers/char/drm/drm_bufs.c
+++ b/drivers/char/drm/drm_bufs.c
@@ -65,43 +65,29 @@ static drm_map_list_t *drm_find_matching_map(drm_device_t *dev,
65 return NULL; 65 return NULL;
66} 66}
67 67
68/* 68static int drm_map_handle(drm_device_t *dev, drm_hash_item_t *hash,
69 * Used to allocate 32-bit handles for mappings. 69 unsigned long user_token, int hashed_handle)
70 */
71#define START_RANGE 0x10000000
72#define END_RANGE 0x40000000
73
74#ifdef _LP64
75static __inline__ unsigned int HandleID(unsigned long lhandle,
76 drm_device_t *dev)
77{ 70{
78 static unsigned int map32_handle = START_RANGE; 71 int use_hashed_handle;
79 unsigned int hash; 72#if (BITS_PER_LONG == 64)
80 73 use_hashed_handle = ((user_token & 0xFFFFFFFF00000000UL) || hashed_handle);
81 if (lhandle & 0xffffffff00000000) { 74#elif (BITS_PER_LONG == 32)
82 hash = map32_handle; 75 use_hashed_handle = hashed_handle;
83 map32_handle += PAGE_SIZE; 76#else
84 if (map32_handle > END_RANGE) 77#error Unsupported long size. Neither 64 nor 32 bits.
85 map32_handle = START_RANGE; 78#endif
86 } else
87 hash = lhandle;
88
89 while (1) {
90 drm_map_list_t *_entry;
91 list_for_each_entry(_entry, &dev->maplist->head, head) {
92 if (_entry->user_token == hash)
93 break;
94 }
95 if (&_entry->head == &dev->maplist->head)
96 return hash;
97 79
98 hash += PAGE_SIZE; 80 if (!use_hashed_handle) {
99 map32_handle += PAGE_SIZE; 81 int ret;
82 hash->key = user_token;
83 ret = drm_ht_insert_item(&dev->map_hash, hash);
84 if (ret != -EINVAL)
85 return ret;
100 } 86 }
87 return drm_ht_just_insert_please(&dev->map_hash, hash,
88 user_token, 32 - PAGE_SHIFT - 3,
89 PAGE_SHIFT, DRM_MAP_HASH_OFFSET);
101} 90}
102#else
103# define HandleID(x,dev) (unsigned int)(x)
104#endif
105 91
106/** 92/**
107 * Ioctl to specify a range of memory that is available for mapping by a non-root process. 93 * Ioctl to specify a range of memory that is available for mapping by a non-root process.
@@ -123,6 +109,8 @@ static int drm_addmap_core(drm_device_t * dev, unsigned int offset,
123 drm_map_t *map; 109 drm_map_t *map;
124 drm_map_list_t *list; 110 drm_map_list_t *list;
125 drm_dma_handle_t *dmah; 111 drm_dma_handle_t *dmah;
112 unsigned long user_token;
113 int ret;
126 114
127 map = drm_alloc(sizeof(*map), DRM_MEM_MAPS); 115 map = drm_alloc(sizeof(*map), DRM_MEM_MAPS);
128 if (!map) 116 if (!map)
@@ -249,6 +237,8 @@ static int drm_addmap_core(drm_device_t * dev, unsigned int offset,
249 237
250 list = drm_alloc(sizeof(*list), DRM_MEM_MAPS); 238 list = drm_alloc(sizeof(*list), DRM_MEM_MAPS);
251 if (!list) { 239 if (!list) {
240 if (map->type == _DRM_REGISTERS)
241 drm_ioremapfree(map->handle, map->size, dev);
252 drm_free(map, sizeof(*map), DRM_MEM_MAPS); 242 drm_free(map, sizeof(*map), DRM_MEM_MAPS);
253 return -EINVAL; 243 return -EINVAL;
254 } 244 }
@@ -257,11 +247,22 @@ static int drm_addmap_core(drm_device_t * dev, unsigned int offset,
257 247
258 mutex_lock(&dev->struct_mutex); 248 mutex_lock(&dev->struct_mutex);
259 list_add(&list->head, &dev->maplist->head); 249 list_add(&list->head, &dev->maplist->head);
250
260 /* Assign a 32-bit handle */ 251 /* Assign a 32-bit handle */
261 /* We do it here so that dev->struct_mutex protects the increment */ 252 /* We do it here so that dev->struct_mutex protects the increment */
262 list->user_token = HandleID(map->type == _DRM_SHM 253 user_token = (map->type == _DRM_SHM) ? (unsigned long)map->handle :
263 ? (unsigned long)map->handle 254 map->offset;
264 : map->offset, dev); 255 ret = drm_map_handle(dev, &list->hash, user_token, 0);
256 if (ret) {
257 if (map->type == _DRM_REGISTERS)
258 drm_ioremapfree(map->handle, map->size, dev);
259 drm_free(map, sizeof(*map), DRM_MEM_MAPS);
260 drm_free(list, sizeof(*list), DRM_MEM_MAPS);
261 mutex_unlock(&dev->struct_mutex);
262 return ret;
263 }
264
265 list->user_token = list->hash.key;
265 mutex_unlock(&dev->struct_mutex); 266 mutex_unlock(&dev->struct_mutex);
266 267
267 *maplist = list; 268 *maplist = list;
@@ -346,6 +347,7 @@ int drm_rmmap_locked(drm_device_t *dev, drm_local_map_t *map)
346 347
347 if (r_list->map == map) { 348 if (r_list->map == map) {
348 list_del(list); 349 list_del(list);
350 drm_ht_remove_key(&dev->map_hash, r_list->user_token);
349 drm_free(list, sizeof(*list), DRM_MEM_MAPS); 351 drm_free(list, sizeof(*list), DRM_MEM_MAPS);
350 break; 352 break;
351 } 353 }
@@ -441,8 +443,10 @@ int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
441 return -EINVAL; 443 return -EINVAL;
442 } 444 }
443 445
444 if (!map) 446 if (!map) {
447 mutex_unlock(&dev->struct_mutex);
445 return -EINVAL; 448 return -EINVAL;
449 }
446 450
447 /* Register and framebuffer maps are permanent */ 451 /* Register and framebuffer maps are permanent */
448 if ((map->type == _DRM_REGISTERS) || (map->type == _DRM_FRAME_BUFFER)) { 452 if ((map->type == _DRM_REGISTERS) || (map->type == _DRM_FRAME_BUFFER)) {
@@ -883,6 +887,9 @@ int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request)
883 request->count = entry->buf_count; 887 request->count = entry->buf_count;
884 request->size = size; 888 request->size = size;
885 889
890 if (request->flags & _DRM_PCI_BUFFER_RO)
891 dma->flags = _DRM_DMA_USE_PCI_RO;
892
886 atomic_dec(&dev->buf_alloc); 893 atomic_dec(&dev->buf_alloc);
887 return 0; 894 return 0;
888 895
@@ -1467,9 +1474,10 @@ int drm_freebufs(struct inode *inode, struct file *filp,
1467 * \param arg pointer to a drm_buf_map structure. 1474 * \param arg pointer to a drm_buf_map structure.
1468 * \return zero on success or a negative number on failure. 1475 * \return zero on success or a negative number on failure.
1469 * 1476 *
1470 * Maps the AGP or SG buffer region with do_mmap(), and copies information 1477 * Maps the AGP, SG or PCI buffer region with do_mmap(), and copies information
1471 * about each buffer into user space. The PCI buffers are already mapped on the 1478 * about each buffer into user space. For PCI buffers, it calls do_mmap() with
1472 * addbufs_pci() call. 1479 * offset equal to 0, which drm_mmap() interpretes as PCI buffers and calls
1480 * drm_mmap_dma().
1473 */ 1481 */
1474int drm_mapbufs(struct inode *inode, struct file *filp, 1482int drm_mapbufs(struct inode *inode, struct file *filp,
1475 unsigned int cmd, unsigned long arg) 1483 unsigned int cmd, unsigned long arg)
diff --git a/drivers/char/drm/drm_core.h b/drivers/char/drm/drm_core.h
index f4f9db6c7ed4..316739036079 100644
--- a/drivers/char/drm/drm_core.h
+++ b/drivers/char/drm/drm_core.h
@@ -24,11 +24,11 @@
24 24
25#define CORE_NAME "drm" 25#define CORE_NAME "drm"
26#define CORE_DESC "DRM shared core routines" 26#define CORE_DESC "DRM shared core routines"
27#define CORE_DATE "20051102" 27#define CORE_DATE "20060810"
28 28
29#define DRM_IF_MAJOR 1 29#define DRM_IF_MAJOR 1
30#define DRM_IF_MINOR 2 30#define DRM_IF_MINOR 3
31 31
32#define CORE_MAJOR 1 32#define CORE_MAJOR 1
33#define CORE_MINOR 0 33#define CORE_MINOR 1
34#define CORE_PATCHLEVEL 1 34#define CORE_PATCHLEVEL 0
diff --git a/drivers/char/drm/drm_drawable.c b/drivers/char/drm/drm_drawable.c
index 7857453c4f48..de37d5f74563 100644
--- a/drivers/char/drm/drm_drawable.c
+++ b/drivers/char/drm/drm_drawable.c
@@ -4,6 +4,7 @@
4 * 4 *
5 * \author Rickard E. (Rik) Faith <faith@valinux.com> 5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com> 6 * \author Gareth Hughes <gareth@valinux.com>
7 * \author Michel Dänzer <michel@tungstengraphics.com>
7 */ 8 */
8 9
9/* 10/*
@@ -11,6 +12,7 @@
11 * 12 *
12 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 13 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
13 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 14 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
15 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, North Dakota.
14 * All Rights Reserved. 16 * All Rights Reserved.
15 * 17 *
16 * Permission is hereby granted, free of charge, to any person obtaining a 18 * Permission is hereby granted, free of charge, to any person obtaining a
@@ -35,22 +37,294 @@
35 37
36#include "drmP.h" 38#include "drmP.h"
37 39
38/** No-op. */ 40/**
39int drm_adddraw(struct inode *inode, struct file *filp, 41 * Allocate drawable ID and memory to store information about it.
40 unsigned int cmd, unsigned long arg) 42 */
43int drm_adddraw(DRM_IOCTL_ARGS)
41{ 44{
45 DRM_DEVICE;
46 unsigned long irqflags;
47 int i, j;
48 u32 *bitfield = dev->drw_bitfield;
49 unsigned int bitfield_length = dev->drw_bitfield_length;
50 drm_drawable_info_t **info = dev->drw_info;
51 unsigned int info_length = dev->drw_info_length;
42 drm_draw_t draw; 52 drm_draw_t draw;
43 53
44 draw.handle = 0; /* NOOP */ 54 for (i = 0, j = 0; i < bitfield_length; i++) {
55 if (bitfield[i] == ~0)
56 continue;
57
58 for (; j < 8 * sizeof(*bitfield); j++)
59 if (!(bitfield[i] & (1 << j)))
60 goto done;
61 }
62done:
63
64 if (i == bitfield_length) {
65 bitfield_length++;
66
67 bitfield = drm_alloc(bitfield_length * sizeof(*bitfield),
68 DRM_MEM_BUFS);
69
70 if (!bitfield) {
71 DRM_ERROR("Failed to allocate new drawable bitfield\n");
72 return DRM_ERR(ENOMEM);
73 }
74
75 if (8 * sizeof(*bitfield) * bitfield_length > info_length) {
76 info_length += 8 * sizeof(*bitfield);
77
78 info = drm_alloc(info_length * sizeof(*info),
79 DRM_MEM_BUFS);
80
81 if (!info) {
82 DRM_ERROR("Failed to allocate new drawable info"
83 " array\n");
84
85 drm_free(bitfield,
86 bitfield_length * sizeof(*bitfield),
87 DRM_MEM_BUFS);
88 return DRM_ERR(ENOMEM);
89 }
90 }
91
92 bitfield[i] = 0;
93 }
94
95 draw.handle = i * 8 * sizeof(*bitfield) + j + 1;
45 DRM_DEBUG("%d\n", draw.handle); 96 DRM_DEBUG("%d\n", draw.handle);
46 if (copy_to_user((drm_draw_t __user *) arg, &draw, sizeof(draw))) 97
47 return -EFAULT; 98 spin_lock_irqsave(&dev->drw_lock, irqflags);
99
100 bitfield[i] |= 1 << j;
101 info[draw.handle - 1] = NULL;
102
103 if (bitfield != dev->drw_bitfield) {
104 memcpy(bitfield, dev->drw_bitfield, dev->drw_bitfield_length *
105 sizeof(*bitfield));
106 drm_free(dev->drw_bitfield, sizeof(*bitfield) *
107 dev->drw_bitfield_length, DRM_MEM_BUFS);
108 dev->drw_bitfield = bitfield;
109 dev->drw_bitfield_length = bitfield_length;
110 }
111
112 if (info != dev->drw_info) {
113 memcpy(info, dev->drw_info, dev->drw_info_length *
114 sizeof(*info));
115 drm_free(dev->drw_info, sizeof(*info) * dev->drw_info_length,
116 DRM_MEM_BUFS);
117 dev->drw_info = info;
118 dev->drw_info_length = info_length;
119 }
120
121 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
122
123 DRM_COPY_TO_USER_IOCTL((drm_draw_t __user *)data, draw, sizeof(draw));
124
48 return 0; 125 return 0;
49} 126}
50 127
51/** No-op. */ 128/**
52int drm_rmdraw(struct inode *inode, struct file *filp, 129 * Free drawable ID and memory to store information about it.
53 unsigned int cmd, unsigned long arg) 130 */
131int drm_rmdraw(DRM_IOCTL_ARGS)
54{ 132{
55 return 0; /* NOOP */ 133 DRM_DEVICE;
134 drm_draw_t draw;
135 int id, idx;
136 unsigned int shift;
137 unsigned long irqflags;
138 u32 *bitfield = dev->drw_bitfield;
139 unsigned int bitfield_length = dev->drw_bitfield_length;
140 drm_drawable_info_t **info = dev->drw_info;
141 unsigned int info_length = dev->drw_info_length;
142
143 DRM_COPY_FROM_USER_IOCTL(draw, (drm_draw_t __user *) data,
144 sizeof(draw));
145
146 id = draw.handle - 1;
147 idx = id / (8 * sizeof(*bitfield));
148 shift = id % (8 * sizeof(*bitfield));
149
150 if (idx < 0 || idx >= bitfield_length ||
151 !(bitfield[idx] & (1 << shift))) {
152 DRM_DEBUG("No such drawable %d\n", draw.handle);
153 return 0;
154 }
155
156 spin_lock_irqsave(&dev->drw_lock, irqflags);
157
158 bitfield[idx] &= ~(1 << shift);
159
160 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
161
162 if (info[id]) {
163 drm_free(info[id]->rects, info[id]->num_rects *
164 sizeof(drm_clip_rect_t), DRM_MEM_BUFS);
165 drm_free(info[id], sizeof(**info), DRM_MEM_BUFS);
166 }
167
168 /* Can we shrink the arrays? */
169 if (idx == bitfield_length - 1) {
170 while (idx >= 0 && !bitfield[idx])
171 --idx;
172
173 bitfield_length = idx + 1;
174
175 if (idx != id / (8 * sizeof(*bitfield)))
176 bitfield = drm_alloc(bitfield_length *
177 sizeof(*bitfield), DRM_MEM_BUFS);
178
179 if (!bitfield && bitfield_length) {
180 bitfield = dev->drw_bitfield;
181 bitfield_length = dev->drw_bitfield_length;
182 }
183 }
184
185 if (bitfield != dev->drw_bitfield) {
186 info_length = 8 * sizeof(*bitfield) * bitfield_length;
187
188 info = drm_alloc(info_length * sizeof(*info), DRM_MEM_BUFS);
189
190 if (!info && info_length) {
191 info = dev->drw_info;
192 info_length = dev->drw_info_length;
193 }
194
195 spin_lock_irqsave(&dev->drw_lock, irqflags);
196
197 memcpy(bitfield, dev->drw_bitfield, bitfield_length *
198 sizeof(*bitfield));
199 drm_free(dev->drw_bitfield, sizeof(*bitfield) *
200 dev->drw_bitfield_length, DRM_MEM_BUFS);
201 dev->drw_bitfield = bitfield;
202 dev->drw_bitfield_length = bitfield_length;
203
204 if (info != dev->drw_info) {
205 memcpy(info, dev->drw_info, info_length *
206 sizeof(*info));
207 drm_free(dev->drw_info, sizeof(*info) *
208 dev->drw_info_length, DRM_MEM_BUFS);
209 dev->drw_info = info;
210 dev->drw_info_length = info_length;
211 }
212
213 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
214 }
215
216 DRM_DEBUG("%d\n", draw.handle);
217 return 0;
218}
219
220int drm_update_drawable_info(DRM_IOCTL_ARGS) {
221 DRM_DEVICE;
222 drm_update_draw_t update;
223 unsigned int id, idx, shift;
224 u32 *bitfield = dev->drw_bitfield;
225 unsigned long irqflags, bitfield_length = dev->drw_bitfield_length;
226 drm_drawable_info_t *info;
227 drm_clip_rect_t *rects;
228 int err;
229
230 DRM_COPY_FROM_USER_IOCTL(update, (drm_update_draw_t __user *) data,
231 sizeof(update));
232
233 id = update.handle - 1;
234 idx = id / (8 * sizeof(*bitfield));
235 shift = id % (8 * sizeof(*bitfield));
236
237 if (idx < 0 || idx >= bitfield_length ||
238 !(bitfield[idx] & (1 << shift))) {
239 DRM_ERROR("No such drawable %d\n", update.handle);
240 return DRM_ERR(EINVAL);
241 }
242
243 info = dev->drw_info[id];
244
245 if (!info) {
246 info = drm_calloc(1, sizeof(drm_drawable_info_t), DRM_MEM_BUFS);
247
248 if (!info) {
249 DRM_ERROR("Failed to allocate drawable info memory\n");
250 return DRM_ERR(ENOMEM);
251 }
252 }
253
254 switch (update.type) {
255 case DRM_DRAWABLE_CLIPRECTS:
256 if (update.num != info->num_rects) {
257 rects = drm_alloc(update.num * sizeof(drm_clip_rect_t),
258 DRM_MEM_BUFS);
259 } else
260 rects = info->rects;
261
262 if (update.num && !rects) {
263 DRM_ERROR("Failed to allocate cliprect memory\n");
264 err = DRM_ERR(ENOMEM);
265 goto error;
266 }
267
268 if (update.num && DRM_COPY_FROM_USER(rects,
269 (drm_clip_rect_t __user *)
270 (unsigned long)update.data,
271 update.num *
272 sizeof(*rects))) {
273 DRM_ERROR("Failed to copy cliprects from userspace\n");
274 err = DRM_ERR(EFAULT);
275 goto error;
276 }
277
278 spin_lock_irqsave(&dev->drw_lock, irqflags);
279
280 if (rects != info->rects) {
281 drm_free(info->rects, info->num_rects *
282 sizeof(drm_clip_rect_t), DRM_MEM_BUFS);
283 }
284
285 info->rects = rects;
286 info->num_rects = update.num;
287 dev->drw_info[id] = info;
288
289 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
290
291 DRM_DEBUG("Updated %d cliprects for drawable %d\n",
292 info->num_rects, id);
293 break;
294 default:
295 DRM_ERROR("Invalid update type %d\n", update.type);
296 return DRM_ERR(EINVAL);
297 }
298
299 return 0;
300
301error:
302 if (!dev->drw_info[id])
303 drm_free(info, sizeof(*info), DRM_MEM_BUFS);
304 else if (rects != dev->drw_info[id]->rects)
305 drm_free(rects, update.num *
306 sizeof(drm_clip_rect_t), DRM_MEM_BUFS);
307
308 return err;
309}
310
311/**
312 * Caller must hold the drawable spinlock!
313 */
314drm_drawable_info_t *drm_get_drawable_info(drm_device_t *dev, drm_drawable_t id) {
315 u32 *bitfield = dev->drw_bitfield;
316 unsigned int idx, shift;
317
318 id--;
319 idx = id / (8 * sizeof(*bitfield));
320 shift = id % (8 * sizeof(*bitfield));
321
322 if (idx < 0 || idx >= dev->drw_bitfield_length ||
323 !(bitfield[idx] & (1 << shift))) {
324 DRM_DEBUG("No such drawable %d\n", id);
325 return NULL;
326 }
327
328 return dev->drw_info[id];
56} 329}
330EXPORT_SYMBOL(drm_get_drawable_info);
diff --git a/drivers/char/drm/drm_drv.c b/drivers/char/drm/drm_drv.c
index 3c0b882a8e72..a70af0de4453 100644
--- a/drivers/char/drm/drm_drv.c
+++ b/drivers/char/drm/drm_drv.c
@@ -116,9 +116,11 @@ static drm_ioctl_desc_t drm_ioctls[] = {
116 [DRM_IOCTL_NR(DRM_IOCTL_SG_FREE)] = {drm_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY}, 116 [DRM_IOCTL_NR(DRM_IOCTL_SG_FREE)] = {drm_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
117 117
118 [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)] = {drm_wait_vblank, 0}, 118 [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)] = {drm_wait_vblank, 0},
119
120 [DRM_IOCTL_NR(DRM_IOCTL_UPDATE_DRAW)] = {drm_update_drawable_info, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
119}; 121};
120 122
121#define DRIVER_IOCTL_COUNT DRM_ARRAY_SIZE( drm_ioctls ) 123#define DRIVER_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
122 124
123/** 125/**
124 * Take down the DRM device. 126 * Take down the DRM device.
@@ -151,16 +153,29 @@ int drm_lastclose(drm_device_t * dev)
151 if (dev->irq_enabled) 153 if (dev->irq_enabled)
152 drm_irq_uninstall(dev); 154 drm_irq_uninstall(dev);
153 155
156 /* Free drawable information memory */
157 for (i = 0; i < dev->drw_bitfield_length / sizeof(*dev->drw_bitfield);
158 i++) {
159 drm_drawable_info_t *info = drm_get_drawable_info(dev, i);
160
161 if (info) {
162 drm_free(info->rects, info->num_rects *
163 sizeof(drm_clip_rect_t), DRM_MEM_BUFS);
164 drm_free(info, sizeof(*info), DRM_MEM_BUFS);
165 }
166 }
167
154 mutex_lock(&dev->struct_mutex); 168 mutex_lock(&dev->struct_mutex);
155 del_timer(&dev->timer); 169 del_timer(&dev->timer);
156 170
157 /* Clear pid list */ 171 /* Clear pid list */
158 for (i = 0; i < DRM_HASH_SIZE; i++) { 172 if (dev->magicfree.next) {
159 for (pt = dev->magiclist[i].head; pt; pt = next) { 173 list_for_each_entry_safe(pt, next, &dev->magicfree, head) {
160 next = pt->next; 174 list_del(&pt->head);
175 drm_ht_remove_item(&dev->magiclist, &pt->hash_item);
161 drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC); 176 drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
162 } 177 }
163 dev->magiclist[i].head = dev->magiclist[i].tail = NULL; 178 drm_ht_remove(&dev->magiclist);
164 } 179 }
165 180
166 /* Clear AGP information */ 181 /* Clear AGP information */
@@ -299,6 +314,7 @@ static void drm_cleanup(drm_device_t * dev)
299 if (dev->maplist) { 314 if (dev->maplist) {
300 drm_free(dev->maplist, sizeof(*dev->maplist), DRM_MEM_MAPS); 315 drm_free(dev->maplist, sizeof(*dev->maplist), DRM_MEM_MAPS);
301 dev->maplist = NULL; 316 dev->maplist = NULL;
317 drm_ht_remove(&dev->map_hash);
302 } 318 }
303 319
304 drm_ctxbitmap_cleanup(dev); 320 drm_ctxbitmap_cleanup(dev);
diff --git a/drivers/char/drm/drm_fops.c b/drivers/char/drm/drm_fops.c
index b7f7951c4587..898f47dafec0 100644
--- a/drivers/char/drm/drm_fops.c
+++ b/drivers/char/drm/drm_fops.c
@@ -53,6 +53,8 @@ static int drm_setup(drm_device_t * dev)
53 return ret; 53 return ret;
54 } 54 }
55 55
56 dev->magicfree.next = NULL;
57
56 /* prebuild the SAREA */ 58 /* prebuild the SAREA */
57 i = drm_addmap(dev, 0, SAREA_MAX, _DRM_SHM, _DRM_CONTAINS_LOCK, &map); 59 i = drm_addmap(dev, 0, SAREA_MAX, _DRM_SHM, _DRM_CONTAINS_LOCK, &map);
58 if (i != 0) 60 if (i != 0)
@@ -69,13 +71,11 @@ static int drm_setup(drm_device_t * dev)
69 return i; 71 return i;
70 } 72 }
71 73
72 for (i = 0; i < DRM_ARRAY_SIZE(dev->counts); i++) 74 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
73 atomic_set(&dev->counts[i], 0); 75 atomic_set(&dev->counts[i], 0);
74 76
75 for (i = 0; i < DRM_HASH_SIZE; i++) { 77 drm_ht_create(&dev->magiclist, DRM_MAGIC_HASH_ORDER);
76 dev->magiclist[i].head = NULL; 78 INIT_LIST_HEAD(&dev->magicfree);
77 dev->magiclist[i].tail = NULL;
78 }
79 79
80 dev->ctxlist = drm_alloc(sizeof(*dev->ctxlist), DRM_MEM_CTXLIST); 80 dev->ctxlist = drm_alloc(sizeof(*dev->ctxlist), DRM_MEM_CTXLIST);
81 if (dev->ctxlist == NULL) 81 if (dev->ctxlist == NULL)
diff --git a/drivers/char/drm/drm_hashtab.c b/drivers/char/drm/drm_hashtab.c
new file mode 100644
index 000000000000..a0b2d6802ae4
--- /dev/null
+++ b/drivers/char/drm/drm_hashtab.c
@@ -0,0 +1,190 @@
1/**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND. USA.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 *
27 **************************************************************************/
28/*
29 * Simple open hash tab implementation.
30 *
31 * Authors:
32 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
33 */
34
35#include "drmP.h"
36#include "drm_hashtab.h"
37#include <linux/hash.h>
38
39int drm_ht_create(drm_open_hash_t *ht, unsigned int order)
40{
41 unsigned int i;
42
43 ht->size = 1 << order;
44 ht->order = order;
45 ht->fill = 0;
46 ht->table = vmalloc(ht->size*sizeof(*ht->table));
47 if (!ht->table) {
48 DRM_ERROR("Out of memory for hash table\n");
49 return -ENOMEM;
50 }
51 for (i=0; i< ht->size; ++i) {
52 INIT_HLIST_HEAD(&ht->table[i]);
53 }
54 return 0;
55}
56
57void drm_ht_verbose_list(drm_open_hash_t *ht, unsigned long key)
58{
59 drm_hash_item_t *entry;
60 struct hlist_head *h_list;
61 struct hlist_node *list;
62 unsigned int hashed_key;
63 int count = 0;
64
65 hashed_key = hash_long(key, ht->order);
66 DRM_DEBUG("Key is 0x%08lx, Hashed key is 0x%08x\n", key, hashed_key);
67 h_list = &ht->table[hashed_key];
68 hlist_for_each(list, h_list) {
69 entry = hlist_entry(list, drm_hash_item_t, head);
70 DRM_DEBUG("count %d, key: 0x%08lx\n", count++, entry->key);
71 }
72}
73
74static struct hlist_node *drm_ht_find_key(drm_open_hash_t *ht,
75 unsigned long key)
76{
77 drm_hash_item_t *entry;
78 struct hlist_head *h_list;
79 struct hlist_node *list;
80 unsigned int hashed_key;
81
82 hashed_key = hash_long(key, ht->order);
83 h_list = &ht->table[hashed_key];
84 hlist_for_each(list, h_list) {
85 entry = hlist_entry(list, drm_hash_item_t, head);
86 if (entry->key == key)
87 return list;
88 if (entry->key > key)
89 break;
90 }
91 return NULL;
92}
93
94
95int drm_ht_insert_item(drm_open_hash_t *ht, drm_hash_item_t *item)
96{
97 drm_hash_item_t *entry;
98 struct hlist_head *h_list;
99 struct hlist_node *list, *parent;
100 unsigned int hashed_key;
101 unsigned long key = item->key;
102
103 hashed_key = hash_long(key, ht->order);
104 h_list = &ht->table[hashed_key];
105 parent = NULL;
106 hlist_for_each(list, h_list) {
107 entry = hlist_entry(list, drm_hash_item_t, head);
108 if (entry->key == key)
109 return -EINVAL;
110 if (entry->key > key)
111 break;
112 parent = list;
113 }
114 if (parent) {
115 hlist_add_after(parent, &item->head);
116 } else {
117 hlist_add_head(&item->head, h_list);
118 }
119 return 0;
120}
121
122/*
123 * Just insert an item and return any "bits" bit key that hasn't been
124 * used before.
125 */
126int drm_ht_just_insert_please(drm_open_hash_t *ht, drm_hash_item_t *item,
127 unsigned long seed, int bits, int shift,
128 unsigned long add)
129{
130 int ret;
131 unsigned long mask = (1 << bits) - 1;
132 unsigned long first, unshifted_key;
133
134 unshifted_key = hash_long(seed, bits);
135 first = unshifted_key;
136 do {
137 item->key = (unshifted_key << shift) + add;
138 ret = drm_ht_insert_item(ht, item);
139 if (ret)
140 unshifted_key = (unshifted_key + 1) & mask;
141 } while(ret && (unshifted_key != first));
142
143 if (ret) {
144 DRM_ERROR("Available key bit space exhausted\n");
145 return -EINVAL;
146 }
147 return 0;
148}
149
150int drm_ht_find_item(drm_open_hash_t *ht, unsigned long key,
151 drm_hash_item_t **item)
152{
153 struct hlist_node *list;
154
155 list = drm_ht_find_key(ht, key);
156 if (!list)
157 return -EINVAL;
158
159 *item = hlist_entry(list, drm_hash_item_t, head);
160 return 0;
161}
162
163int drm_ht_remove_key(drm_open_hash_t *ht, unsigned long key)
164{
165 struct hlist_node *list;
166
167 list = drm_ht_find_key(ht, key);
168 if (list) {
169 hlist_del_init(list);
170 ht->fill--;
171 return 0;
172 }
173 return -EINVAL;
174}
175
176int drm_ht_remove_item(drm_open_hash_t *ht, drm_hash_item_t *item)
177{
178 hlist_del_init(&item->head);
179 ht->fill--;
180 return 0;
181}
182
183void drm_ht_remove(drm_open_hash_t *ht)
184{
185 if (ht->table) {
186 vfree(ht->table);
187 ht->table = NULL;
188 }
189}
190
diff --git a/drivers/char/drm/drm_hashtab.h b/drivers/char/drm/drm_hashtab.h
new file mode 100644
index 000000000000..40afec05bff8
--- /dev/null
+++ b/drivers/char/drm/drm_hashtab.h
@@ -0,0 +1,67 @@
1/**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Bismack, ND. USA.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 *
27 **************************************************************************/
28/*
29 * Simple open hash tab implementation.
30 *
31 * Authors:
32 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
33 */
34
35#ifndef DRM_HASHTAB_H
36#define DRM_HASHTAB_H
37
38#define drm_hash_entry(_ptr, _type, _member) container_of(_ptr, _type, _member)
39
40typedef struct drm_hash_item{
41 struct hlist_node head;
42 unsigned long key;
43} drm_hash_item_t;
44
45typedef struct drm_open_hash{
46 unsigned int size;
47 unsigned int order;
48 unsigned int fill;
49 struct hlist_head *table;
50} drm_open_hash_t;
51
52
53extern int drm_ht_create(drm_open_hash_t *ht, unsigned int order);
54extern int drm_ht_insert_item(drm_open_hash_t *ht, drm_hash_item_t *item);
55extern int drm_ht_just_insert_please(drm_open_hash_t *ht, drm_hash_item_t *item,
56 unsigned long seed, int bits, int shift,
57 unsigned long add);
58extern int drm_ht_find_item(drm_open_hash_t *ht, unsigned long key, drm_hash_item_t **item);
59
60extern void drm_ht_verbose_list(drm_open_hash_t *ht, unsigned long key);
61extern int drm_ht_remove_key(drm_open_hash_t *ht, unsigned long key);
62extern int drm_ht_remove_item(drm_open_hash_t *ht, drm_hash_item_t *item);
63extern void drm_ht_remove(drm_open_hash_t *ht);
64
65
66#endif
67
diff --git a/drivers/char/drm/drm_ioc32.c b/drivers/char/drm/drm_ioc32.c
index e9e2db18952d..fafeb34f89d5 100644
--- a/drivers/char/drm/drm_ioc32.c
+++ b/drivers/char/drm/drm_ioc32.c
@@ -102,7 +102,7 @@ static int compat_drm_version(struct file *file, unsigned int cmd,
102 &version->desc)) 102 &version->desc))
103 return -EFAULT; 103 return -EFAULT;
104 104
105 err = drm_ioctl(file->f_dentry->d_inode, file, 105 err = drm_ioctl(file->f_path.dentry->d_inode, file,
106 DRM_IOCTL_VERSION, (unsigned long)version); 106 DRM_IOCTL_VERSION, (unsigned long)version);
107 if (err) 107 if (err)
108 return err; 108 return err;
@@ -143,7 +143,7 @@ static int compat_drm_getunique(struct file *file, unsigned int cmd,
143 &u->unique)) 143 &u->unique))
144 return -EFAULT; 144 return -EFAULT;
145 145
146 err = drm_ioctl(file->f_dentry->d_inode, file, 146 err = drm_ioctl(file->f_path.dentry->d_inode, file,
147 DRM_IOCTL_GET_UNIQUE, (unsigned long)u); 147 DRM_IOCTL_GET_UNIQUE, (unsigned long)u);
148 if (err) 148 if (err)
149 return err; 149 return err;
@@ -172,7 +172,7 @@ static int compat_drm_setunique(struct file *file, unsigned int cmd,
172 &u->unique)) 172 &u->unique))
173 return -EFAULT; 173 return -EFAULT;
174 174
175 return drm_ioctl(file->f_dentry->d_inode, file, 175 return drm_ioctl(file->f_path.dentry->d_inode, file,
176 DRM_IOCTL_SET_UNIQUE, (unsigned long)u); 176 DRM_IOCTL_SET_UNIQUE, (unsigned long)u);
177} 177}
178 178
@@ -203,7 +203,7 @@ static int compat_drm_getmap(struct file *file, unsigned int cmd,
203 if (__put_user(idx, &map->offset)) 203 if (__put_user(idx, &map->offset))
204 return -EFAULT; 204 return -EFAULT;
205 205
206 err = drm_ioctl(file->f_dentry->d_inode, file, 206 err = drm_ioctl(file->f_path.dentry->d_inode, file,
207 DRM_IOCTL_GET_MAP, (unsigned long)map); 207 DRM_IOCTL_GET_MAP, (unsigned long)map);
208 if (err) 208 if (err)
209 return err; 209 return err;
@@ -244,7 +244,7 @@ static int compat_drm_addmap(struct file *file, unsigned int cmd,
244 || __put_user(m32.flags, &map->flags)) 244 || __put_user(m32.flags, &map->flags))
245 return -EFAULT; 245 return -EFAULT;
246 246
247 err = drm_ioctl(file->f_dentry->d_inode, file, 247 err = drm_ioctl(file->f_path.dentry->d_inode, file,
248 DRM_IOCTL_ADD_MAP, (unsigned long)map); 248 DRM_IOCTL_ADD_MAP, (unsigned long)map);
249 if (err) 249 if (err)
250 return err; 250 return err;
@@ -282,7 +282,7 @@ static int compat_drm_rmmap(struct file *file, unsigned int cmd,
282 if (__put_user((void *)(unsigned long)handle, &map->handle)) 282 if (__put_user((void *)(unsigned long)handle, &map->handle))
283 return -EFAULT; 283 return -EFAULT;
284 284
285 return drm_ioctl(file->f_dentry->d_inode, file, 285 return drm_ioctl(file->f_path.dentry->d_inode, file,
286 DRM_IOCTL_RM_MAP, (unsigned long)map); 286 DRM_IOCTL_RM_MAP, (unsigned long)map);
287} 287}
288 288
@@ -312,7 +312,7 @@ static int compat_drm_getclient(struct file *file, unsigned int cmd,
312 if (__put_user(idx, &client->idx)) 312 if (__put_user(idx, &client->idx))
313 return -EFAULT; 313 return -EFAULT;
314 314
315 err = drm_ioctl(file->f_dentry->d_inode, file, 315 err = drm_ioctl(file->f_path.dentry->d_inode, file,
316 DRM_IOCTL_GET_CLIENT, (unsigned long)client); 316 DRM_IOCTL_GET_CLIENT, (unsigned long)client);
317 if (err) 317 if (err)
318 return err; 318 return err;
@@ -349,7 +349,7 @@ static int compat_drm_getstats(struct file *file, unsigned int cmd,
349 if (!access_ok(VERIFY_WRITE, stats, sizeof(*stats))) 349 if (!access_ok(VERIFY_WRITE, stats, sizeof(*stats)))
350 return -EFAULT; 350 return -EFAULT;
351 351
352 err = drm_ioctl(file->f_dentry->d_inode, file, 352 err = drm_ioctl(file->f_path.dentry->d_inode, file,
353 DRM_IOCTL_GET_STATS, (unsigned long)stats); 353 DRM_IOCTL_GET_STATS, (unsigned long)stats);
354 if (err) 354 if (err)
355 return err; 355 return err;
@@ -393,7 +393,7 @@ static int compat_drm_addbufs(struct file *file, unsigned int cmd,
393 || __put_user(agp_start, &buf->agp_start)) 393 || __put_user(agp_start, &buf->agp_start))
394 return -EFAULT; 394 return -EFAULT;
395 395
396 err = drm_ioctl(file->f_dentry->d_inode, file, 396 err = drm_ioctl(file->f_path.dentry->d_inode, file,
397 DRM_IOCTL_ADD_BUFS, (unsigned long)buf); 397 DRM_IOCTL_ADD_BUFS, (unsigned long)buf);
398 if (err) 398 if (err)
399 return err; 399 return err;
@@ -425,7 +425,7 @@ static int compat_drm_markbufs(struct file *file, unsigned int cmd,
425 || __put_user(b32.high_mark, &buf->high_mark)) 425 || __put_user(b32.high_mark, &buf->high_mark))
426 return -EFAULT; 426 return -EFAULT;
427 427
428 return drm_ioctl(file->f_dentry->d_inode, file, 428 return drm_ioctl(file->f_path.dentry->d_inode, file,
429 DRM_IOCTL_MARK_BUFS, (unsigned long)buf); 429 DRM_IOCTL_MARK_BUFS, (unsigned long)buf);
430} 430}
431 431
@@ -467,7 +467,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
467 || __put_user(list, &request->list)) 467 || __put_user(list, &request->list))
468 return -EFAULT; 468 return -EFAULT;
469 469
470 err = drm_ioctl(file->f_dentry->d_inode, file, 470 err = drm_ioctl(file->f_path.dentry->d_inode, file,
471 DRM_IOCTL_INFO_BUFS, (unsigned long)request); 471 DRM_IOCTL_INFO_BUFS, (unsigned long)request);
472 if (err) 472 if (err)
473 return err; 473 return err;
@@ -529,7 +529,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
529 || __put_user(list, &request->list)) 529 || __put_user(list, &request->list))
530 return -EFAULT; 530 return -EFAULT;
531 531
532 err = drm_ioctl(file->f_dentry->d_inode, file, 532 err = drm_ioctl(file->f_path.dentry->d_inode, file,
533 DRM_IOCTL_MAP_BUFS, (unsigned long)request); 533 DRM_IOCTL_MAP_BUFS, (unsigned long)request);
534 if (err) 534 if (err)
535 return err; 535 return err;
@@ -576,7 +576,7 @@ static int compat_drm_freebufs(struct file *file, unsigned int cmd,
576 &request->list)) 576 &request->list))
577 return -EFAULT; 577 return -EFAULT;
578 578
579 return drm_ioctl(file->f_dentry->d_inode, file, 579 return drm_ioctl(file->f_path.dentry->d_inode, file,
580 DRM_IOCTL_FREE_BUFS, (unsigned long)request); 580 DRM_IOCTL_FREE_BUFS, (unsigned long)request);
581} 581}
582 582
@@ -603,7 +603,7 @@ static int compat_drm_setsareactx(struct file *file, unsigned int cmd,
603 &request->handle)) 603 &request->handle))
604 return -EFAULT; 604 return -EFAULT;
605 605
606 return drm_ioctl(file->f_dentry->d_inode, file, 606 return drm_ioctl(file->f_path.dentry->d_inode, file,
607 DRM_IOCTL_SET_SAREA_CTX, (unsigned long)request); 607 DRM_IOCTL_SET_SAREA_CTX, (unsigned long)request);
608} 608}
609 609
@@ -626,7 +626,7 @@ static int compat_drm_getsareactx(struct file *file, unsigned int cmd,
626 if (__put_user(ctx_id, &request->ctx_id)) 626 if (__put_user(ctx_id, &request->ctx_id))
627 return -EFAULT; 627 return -EFAULT;
628 628
629 err = drm_ioctl(file->f_dentry->d_inode, file, 629 err = drm_ioctl(file->f_path.dentry->d_inode, file,
630 DRM_IOCTL_GET_SAREA_CTX, (unsigned long)request); 630 DRM_IOCTL_GET_SAREA_CTX, (unsigned long)request);
631 if (err) 631 if (err)
632 return err; 632 return err;
@@ -662,7 +662,7 @@ static int compat_drm_resctx(struct file *file, unsigned int cmd,
662 &res->contexts)) 662 &res->contexts))
663 return -EFAULT; 663 return -EFAULT;
664 664
665 err = drm_ioctl(file->f_dentry->d_inode, file, 665 err = drm_ioctl(file->f_path.dentry->d_inode, file,
666 DRM_IOCTL_RES_CTX, (unsigned long)res); 666 DRM_IOCTL_RES_CTX, (unsigned long)res);
667 if (err) 667 if (err)
668 return err; 668 return err;
@@ -716,7 +716,7 @@ static int compat_drm_dma(struct file *file, unsigned int cmd,
716 &d->request_sizes)) 716 &d->request_sizes))
717 return -EFAULT; 717 return -EFAULT;
718 718
719 err = drm_ioctl(file->f_dentry->d_inode, file, 719 err = drm_ioctl(file->f_path.dentry->d_inode, file,
720 DRM_IOCTL_DMA, (unsigned long)d); 720 DRM_IOCTL_DMA, (unsigned long)d);
721 if (err) 721 if (err)
722 return err; 722 return err;
@@ -749,7 +749,7 @@ static int compat_drm_agp_enable(struct file *file, unsigned int cmd,
749 if (put_user(m32.mode, &mode->mode)) 749 if (put_user(m32.mode, &mode->mode))
750 return -EFAULT; 750 return -EFAULT;
751 751
752 return drm_ioctl(file->f_dentry->d_inode, file, 752 return drm_ioctl(file->f_path.dentry->d_inode, file,
753 DRM_IOCTL_AGP_ENABLE, (unsigned long)mode); 753 DRM_IOCTL_AGP_ENABLE, (unsigned long)mode);
754} 754}
755 755
@@ -779,7 +779,7 @@ static int compat_drm_agp_info(struct file *file, unsigned int cmd,
779 if (!access_ok(VERIFY_WRITE, info, sizeof(*info))) 779 if (!access_ok(VERIFY_WRITE, info, sizeof(*info)))
780 return -EFAULT; 780 return -EFAULT;
781 781
782 err = drm_ioctl(file->f_dentry->d_inode, file, 782 err = drm_ioctl(file->f_path.dentry->d_inode, file,
783 DRM_IOCTL_AGP_INFO, (unsigned long)info); 783 DRM_IOCTL_AGP_INFO, (unsigned long)info);
784 if (err) 784 if (err)
785 return err; 785 return err;
@@ -825,7 +825,7 @@ static int compat_drm_agp_alloc(struct file *file, unsigned int cmd,
825 || __put_user(req32.type, &request->type)) 825 || __put_user(req32.type, &request->type))
826 return -EFAULT; 826 return -EFAULT;
827 827
828 err = drm_ioctl(file->f_dentry->d_inode, file, 828 err = drm_ioctl(file->f_path.dentry->d_inode, file,
829 DRM_IOCTL_AGP_ALLOC, (unsigned long)request); 829 DRM_IOCTL_AGP_ALLOC, (unsigned long)request);
830 if (err) 830 if (err)
831 return err; 831 return err;
@@ -833,7 +833,7 @@ static int compat_drm_agp_alloc(struct file *file, unsigned int cmd,
833 if (__get_user(req32.handle, &request->handle) 833 if (__get_user(req32.handle, &request->handle)
834 || __get_user(req32.physical, &request->physical) 834 || __get_user(req32.physical, &request->physical)
835 || copy_to_user(argp, &req32, sizeof(req32))) { 835 || copy_to_user(argp, &req32, sizeof(req32))) {
836 drm_ioctl(file->f_dentry->d_inode, file, 836 drm_ioctl(file->f_path.dentry->d_inode, file,
837 DRM_IOCTL_AGP_FREE, (unsigned long)request); 837 DRM_IOCTL_AGP_FREE, (unsigned long)request);
838 return -EFAULT; 838 return -EFAULT;
839 } 839 }
@@ -854,7 +854,7 @@ static int compat_drm_agp_free(struct file *file, unsigned int cmd,
854 || __put_user(handle, &request->handle)) 854 || __put_user(handle, &request->handle))
855 return -EFAULT; 855 return -EFAULT;
856 856
857 return drm_ioctl(file->f_dentry->d_inode, file, 857 return drm_ioctl(file->f_path.dentry->d_inode, file,
858 DRM_IOCTL_AGP_FREE, (unsigned long)request); 858 DRM_IOCTL_AGP_FREE, (unsigned long)request);
859} 859}
860 860
@@ -879,7 +879,7 @@ static int compat_drm_agp_bind(struct file *file, unsigned int cmd,
879 || __put_user(req32.offset, &request->offset)) 879 || __put_user(req32.offset, &request->offset))
880 return -EFAULT; 880 return -EFAULT;
881 881
882 return drm_ioctl(file->f_dentry->d_inode, file, 882 return drm_ioctl(file->f_path.dentry->d_inode, file,
883 DRM_IOCTL_AGP_BIND, (unsigned long)request); 883 DRM_IOCTL_AGP_BIND, (unsigned long)request);
884} 884}
885 885
@@ -896,7 +896,7 @@ static int compat_drm_agp_unbind(struct file *file, unsigned int cmd,
896 || __put_user(handle, &request->handle)) 896 || __put_user(handle, &request->handle))
897 return -EFAULT; 897 return -EFAULT;
898 898
899 return drm_ioctl(file->f_dentry->d_inode, file, 899 return drm_ioctl(file->f_path.dentry->d_inode, file,
900 DRM_IOCTL_AGP_UNBIND, (unsigned long)request); 900 DRM_IOCTL_AGP_UNBIND, (unsigned long)request);
901} 901}
902#endif /* __OS_HAS_AGP */ 902#endif /* __OS_HAS_AGP */
@@ -921,7 +921,7 @@ static int compat_drm_sg_alloc(struct file *file, unsigned int cmd,
921 || __put_user(x, &request->size)) 921 || __put_user(x, &request->size))
922 return -EFAULT; 922 return -EFAULT;
923 923
924 err = drm_ioctl(file->f_dentry->d_inode, file, 924 err = drm_ioctl(file->f_path.dentry->d_inode, file,
925 DRM_IOCTL_SG_ALLOC, (unsigned long)request); 925 DRM_IOCTL_SG_ALLOC, (unsigned long)request);
926 if (err) 926 if (err)
927 return err; 927 return err;
@@ -948,7 +948,7 @@ static int compat_drm_sg_free(struct file *file, unsigned int cmd,
948 || __put_user(x << PAGE_SHIFT, &request->handle)) 948 || __put_user(x << PAGE_SHIFT, &request->handle))
949 return -EFAULT; 949 return -EFAULT;
950 950
951 return drm_ioctl(file->f_dentry->d_inode, file, 951 return drm_ioctl(file->f_path.dentry->d_inode, file,
952 DRM_IOCTL_SG_FREE, (unsigned long)request); 952 DRM_IOCTL_SG_FREE, (unsigned long)request);
953} 953}
954 954
@@ -988,7 +988,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
988 || __put_user(req32.request.signal, &request->request.signal)) 988 || __put_user(req32.request.signal, &request->request.signal))
989 return -EFAULT; 989 return -EFAULT;
990 990
991 err = drm_ioctl(file->f_dentry->d_inode, file, 991 err = drm_ioctl(file->f_path.dentry->d_inode, file,
992 DRM_IOCTL_WAIT_VBLANK, (unsigned long)request); 992 DRM_IOCTL_WAIT_VBLANK, (unsigned long)request);
993 if (err) 993 if (err)
994 return err; 994 return err;
@@ -1051,7 +1051,7 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1051 drm_ioctl_compat_t *fn; 1051 drm_ioctl_compat_t *fn;
1052 int ret; 1052 int ret;
1053 1053
1054 if (nr >= DRM_ARRAY_SIZE(drm_compat_ioctls)) 1054 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
1055 return -ENOTTY; 1055 return -ENOTTY;
1056 1056
1057 fn = drm_compat_ioctls[nr]; 1057 fn = drm_compat_ioctls[nr];
@@ -1060,7 +1060,7 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1060 if (fn != NULL) 1060 if (fn != NULL)
1061 ret = (*fn) (filp, cmd, arg); 1061 ret = (*fn) (filp, cmd, arg);
1062 else 1062 else
1063 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg); 1063 ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
1064 unlock_kernel(); 1064 unlock_kernel();
1065 1065
1066 return ret; 1066 return ret;
diff --git a/drivers/char/drm/drm_ioctl.c b/drivers/char/drm/drm_ioctl.c
index 555f323b8a32..565895547d75 100644
--- a/drivers/char/drm/drm_ioctl.c
+++ b/drivers/char/drm/drm_ioctl.c
@@ -127,9 +127,10 @@ int drm_setunique(struct inode *inode, struct file *filp,
127 domain = bus >> 8; 127 domain = bus >> 8;
128 bus &= 0xff; 128 bus &= 0xff;
129 129
130 if ((domain != dev->pci_domain) || 130 if ((domain != drm_get_pci_domain(dev)) ||
131 (bus != dev->pci_bus) || 131 (bus != dev->pdev->bus->number) ||
132 (slot != dev->pci_slot) || (func != dev->pci_func)) 132 (slot != PCI_SLOT(dev->pdev->devfn)) ||
133 (func != PCI_FUNC(dev->pdev->devfn)))
133 return -EINVAL; 134 return -EINVAL;
134 135
135 return 0; 136 return 0;
@@ -140,15 +141,17 @@ static int drm_set_busid(drm_device_t * dev)
140 int len; 141 int len;
141 142
142 if (dev->unique != NULL) 143 if (dev->unique != NULL)
143 return EBUSY; 144 return 0;
144 145
145 dev->unique_len = 40; 146 dev->unique_len = 40;
146 dev->unique = drm_alloc(dev->unique_len + 1, DRM_MEM_DRIVER); 147 dev->unique = drm_alloc(dev->unique_len + 1, DRM_MEM_DRIVER);
147 if (dev->unique == NULL) 148 if (dev->unique == NULL)
148 return ENOMEM; 149 return -ENOMEM;
149 150
150 len = snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d", 151 len = snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d",
151 dev->pci_domain, dev->pci_bus, dev->pci_slot, dev->pci_func); 152 drm_get_pci_domain(dev), dev->pdev->bus->number,
153 PCI_SLOT(dev->pdev->devfn),
154 PCI_FUNC(dev->pdev->devfn));
152 155
153 if (len > dev->unique_len) 156 if (len > dev->unique_len)
154 DRM_ERROR("Unique buffer overflowed\n"); 157 DRM_ERROR("Unique buffer overflowed\n");
@@ -157,7 +160,7 @@ static int drm_set_busid(drm_device_t * dev)
157 drm_alloc(strlen(dev->driver->pci_driver.name) + dev->unique_len + 160 drm_alloc(strlen(dev->driver->pci_driver.name) + dev->unique_len +
158 2, DRM_MEM_DRIVER); 161 2, DRM_MEM_DRIVER);
159 if (dev->devname == NULL) 162 if (dev->devname == NULL)
160 return ENOMEM; 163 return -ENOMEM;
161 164
162 sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name, 165 sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
163 dev->unique); 166 dev->unique);
@@ -330,27 +333,32 @@ int drm_setversion(DRM_IOCTL_ARGS)
330 drm_set_version_t retv; 333 drm_set_version_t retv;
331 int if_version; 334 int if_version;
332 drm_set_version_t __user *argp = (void __user *)data; 335 drm_set_version_t __user *argp = (void __user *)data;
336 int ret;
333 337
334 DRM_COPY_FROM_USER_IOCTL(sv, argp, sizeof(sv)); 338 if (copy_from_user(&sv, argp, sizeof(sv)))
339 return -EFAULT;
335 340
336 retv.drm_di_major = DRM_IF_MAJOR; 341 retv.drm_di_major = DRM_IF_MAJOR;
337 retv.drm_di_minor = DRM_IF_MINOR; 342 retv.drm_di_minor = DRM_IF_MINOR;
338 retv.drm_dd_major = dev->driver->major; 343 retv.drm_dd_major = dev->driver->major;
339 retv.drm_dd_minor = dev->driver->minor; 344 retv.drm_dd_minor = dev->driver->minor;
340 345
341 DRM_COPY_TO_USER_IOCTL(argp, retv, sizeof(sv)); 346 if (copy_to_user(argp, &retv, sizeof(retv)))
347 return -EFAULT;
342 348
343 if (sv.drm_di_major != -1) { 349 if (sv.drm_di_major != -1) {
344 if (sv.drm_di_major != DRM_IF_MAJOR || 350 if (sv.drm_di_major != DRM_IF_MAJOR ||
345 sv.drm_di_minor < 0 || sv.drm_di_minor > DRM_IF_MINOR) 351 sv.drm_di_minor < 0 || sv.drm_di_minor > DRM_IF_MINOR)
346 return EINVAL; 352 return -EINVAL;
347 if_version = DRM_IF_VERSION(sv.drm_di_major, sv.drm_di_minor); 353 if_version = DRM_IF_VERSION(sv.drm_di_major, sv.drm_di_minor);
348 dev->if_version = DRM_MAX(if_version, dev->if_version); 354 dev->if_version = max(if_version, dev->if_version);
349 if (sv.drm_di_minor >= 1) { 355 if (sv.drm_di_minor >= 1) {
350 /* 356 /*
351 * Version 1.1 includes tying of DRM to specific device 357 * Version 1.1 includes tying of DRM to specific device
352 */ 358 */
353 drm_set_busid(dev); 359 ret = drm_set_busid(dev);
360 if (ret)
361 return ret;
354 } 362 }
355 } 363 }
356 364
@@ -358,7 +366,7 @@ int drm_setversion(DRM_IOCTL_ARGS)
358 if (sv.drm_dd_major != dev->driver->major || 366 if (sv.drm_dd_major != dev->driver->major ||
359 sv.drm_dd_minor < 0 367 sv.drm_dd_minor < 0
360 || sv.drm_dd_minor > dev->driver->minor) 368 || sv.drm_dd_minor > dev->driver->minor)
361 return EINVAL; 369 return -EINVAL;
362 370
363 if (dev->driver->set_version) 371 if (dev->driver->set_version)
364 dev->driver->set_version(dev, &sv); 372 dev->driver->set_version(dev, &sv);
diff --git a/drivers/char/drm/drm_irq.c b/drivers/char/drm/drm_irq.c
index ebdb7182c4fd..9d00c51fe2c4 100644
--- a/drivers/char/drm/drm_irq.c
+++ b/drivers/char/drm/drm_irq.c
@@ -64,9 +64,9 @@ int drm_irq_by_busid(struct inode *inode, struct file *filp,
64 if (copy_from_user(&p, argp, sizeof(p))) 64 if (copy_from_user(&p, argp, sizeof(p)))
65 return -EFAULT; 65 return -EFAULT;
66 66
67 if ((p.busnum >> 8) != dev->pci_domain || 67 if ((p.busnum >> 8) != drm_get_pci_domain(dev) ||
68 (p.busnum & 0xff) != dev->pci_bus || 68 (p.busnum & 0xff) != dev->pdev->bus->number ||
69 p.devnum != dev->pci_slot || p.funcnum != dev->pci_func) 69 p.devnum != PCI_SLOT(dev->pdev->devfn) || p.funcnum != PCI_FUNC(dev->pdev->devfn))
70 return -EINVAL; 70 return -EINVAL;
71 71
72 p.irq = dev->irq; 72 p.irq = dev->irq;
@@ -121,6 +121,7 @@ static int drm_irq_install(drm_device_t * dev)
121 spin_lock_init(&dev->vbl_lock); 121 spin_lock_init(&dev->vbl_lock);
122 122
123 INIT_LIST_HEAD(&dev->vbl_sigs.head); 123 INIT_LIST_HEAD(&dev->vbl_sigs.head);
124 INIT_LIST_HEAD(&dev->vbl_sigs2.head);
124 125
125 dev->vbl_pending = 0; 126 dev->vbl_pending = 0;
126 } 127 }
@@ -175,6 +176,8 @@ int drm_irq_uninstall(drm_device_t * dev)
175 176
176 free_irq(dev->irq, dev); 177 free_irq(dev->irq, dev);
177 178
179 dev->locked_tasklet_func = NULL;
180
178 return 0; 181 return 0;
179} 182}
180 183
@@ -247,19 +250,34 @@ int drm_wait_vblank(DRM_IOCTL_ARGS)
247 drm_wait_vblank_t vblwait; 250 drm_wait_vblank_t vblwait;
248 struct timeval now; 251 struct timeval now;
249 int ret = 0; 252 int ret = 0;
250 unsigned int flags; 253 unsigned int flags, seq;
251 254
252 if (!drm_core_check_feature(dev, DRIVER_IRQ_VBL)) 255 if (!dev->irq)
253 return -EINVAL; 256 return -EINVAL;
254 257
255 if (!dev->irq) 258 if (copy_from_user(&vblwait, argp, sizeof(vblwait)))
259 return -EFAULT;
260
261 if (vblwait.request.type &
262 ~(_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK)) {
263 DRM_ERROR("Unsupported type value 0x%x, supported mask 0x%x\n",
264 vblwait.request.type,
265 (_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK));
256 return -EINVAL; 266 return -EINVAL;
267 }
257 268
258 DRM_COPY_FROM_USER_IOCTL(vblwait, argp, sizeof(vblwait)); 269 flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK;
259 270
260 switch (vblwait.request.type & ~_DRM_VBLANK_FLAGS_MASK) { 271 if (!drm_core_check_feature(dev, (flags & _DRM_VBLANK_SECONDARY) ?
272 DRIVER_IRQ_VBL2 : DRIVER_IRQ_VBL))
273 return -EINVAL;
274
275 seq = atomic_read((flags & _DRM_VBLANK_SECONDARY) ? &dev->vbl_received2
276 : &dev->vbl_received);
277
278 switch (vblwait.request.type & _DRM_VBLANK_TYPES_MASK) {
261 case _DRM_VBLANK_RELATIVE: 279 case _DRM_VBLANK_RELATIVE:
262 vblwait.request.sequence += atomic_read(&dev->vbl_received); 280 vblwait.request.sequence += seq;
263 vblwait.request.type &= ~_DRM_VBLANK_RELATIVE; 281 vblwait.request.type &= ~_DRM_VBLANK_RELATIVE;
264 case _DRM_VBLANK_ABSOLUTE: 282 case _DRM_VBLANK_ABSOLUTE:
265 break; 283 break;
@@ -267,26 +285,30 @@ int drm_wait_vblank(DRM_IOCTL_ARGS)
267 return -EINVAL; 285 return -EINVAL;
268 } 286 }
269 287
270 flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK; 288 if ((flags & _DRM_VBLANK_NEXTONMISS) &&
289 (seq - vblwait.request.sequence) <= (1<<23)) {
290 vblwait.request.sequence = seq + 1;
291 }
271 292
272 if (flags & _DRM_VBLANK_SIGNAL) { 293 if (flags & _DRM_VBLANK_SIGNAL) {
273 unsigned long irqflags; 294 unsigned long irqflags;
295 drm_vbl_sig_t *vbl_sigs = (flags & _DRM_VBLANK_SECONDARY)
296 ? &dev->vbl_sigs2 : &dev->vbl_sigs;
274 drm_vbl_sig_t *vbl_sig; 297 drm_vbl_sig_t *vbl_sig;
275 298
276 vblwait.reply.sequence = atomic_read(&dev->vbl_received);
277
278 spin_lock_irqsave(&dev->vbl_lock, irqflags); 299 spin_lock_irqsave(&dev->vbl_lock, irqflags);
279 300
280 /* Check if this task has already scheduled the same signal 301 /* Check if this task has already scheduled the same signal
281 * for the same vblank sequence number; nothing to be done in 302 * for the same vblank sequence number; nothing to be done in
282 * that case 303 * that case
283 */ 304 */
284 list_for_each_entry(vbl_sig, &dev->vbl_sigs.head, head) { 305 list_for_each_entry(vbl_sig, &vbl_sigs->head, head) {
285 if (vbl_sig->sequence == vblwait.request.sequence 306 if (vbl_sig->sequence == vblwait.request.sequence
286 && vbl_sig->info.si_signo == vblwait.request.signal 307 && vbl_sig->info.si_signo == vblwait.request.signal
287 && vbl_sig->task == current) { 308 && vbl_sig->task == current) {
288 spin_unlock_irqrestore(&dev->vbl_lock, 309 spin_unlock_irqrestore(&dev->vbl_lock,
289 irqflags); 310 irqflags);
311 vblwait.reply.sequence = seq;
290 goto done; 312 goto done;
291 } 313 }
292 } 314 }
@@ -314,11 +336,16 @@ int drm_wait_vblank(DRM_IOCTL_ARGS)
314 336
315 spin_lock_irqsave(&dev->vbl_lock, irqflags); 337 spin_lock_irqsave(&dev->vbl_lock, irqflags);
316 338
317 list_add_tail((struct list_head *)vbl_sig, &dev->vbl_sigs.head); 339 list_add_tail((struct list_head *)vbl_sig, &vbl_sigs->head);
318 340
319 spin_unlock_irqrestore(&dev->vbl_lock, irqflags); 341 spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
342
343 vblwait.reply.sequence = seq;
320 } else { 344 } else {
321 if (dev->driver->vblank_wait) 345 if (flags & _DRM_VBLANK_SECONDARY) {
346 if (dev->driver->vblank_wait2)
347 ret = dev->driver->vblank_wait2(dev, &vblwait.request.sequence);
348 } else if (dev->driver->vblank_wait)
322 ret = 349 ret =
323 dev->driver->vblank_wait(dev, 350 dev->driver->vblank_wait(dev,
324 &vblwait.request.sequence); 351 &vblwait.request.sequence);
@@ -329,7 +356,8 @@ int drm_wait_vblank(DRM_IOCTL_ARGS)
329 } 356 }
330 357
331 done: 358 done:
332 DRM_COPY_TO_USER_IOCTL(argp, vblwait, sizeof(vblwait)); 359 if (copy_to_user(argp, &vblwait, sizeof(vblwait)))
360 return -EFAULT;
333 361
334 return ret; 362 return ret;
335} 363}
@@ -345,25 +373,32 @@ int drm_wait_vblank(DRM_IOCTL_ARGS)
345 */ 373 */
346void drm_vbl_send_signals(drm_device_t * dev) 374void drm_vbl_send_signals(drm_device_t * dev)
347{ 375{
348 struct list_head *list, *tmp;
349 drm_vbl_sig_t *vbl_sig;
350 unsigned int vbl_seq = atomic_read(&dev->vbl_received);
351 unsigned long flags; 376 unsigned long flags;
377 int i;
352 378
353 spin_lock_irqsave(&dev->vbl_lock, flags); 379 spin_lock_irqsave(&dev->vbl_lock, flags);
354 380
355 list_for_each_safe(list, tmp, &dev->vbl_sigs.head) { 381 for (i = 0; i < 2; i++) {
356 vbl_sig = list_entry(list, drm_vbl_sig_t, head); 382 struct list_head *list, *tmp;
357 if ((vbl_seq - vbl_sig->sequence) <= (1 << 23)) { 383 drm_vbl_sig_t *vbl_sig;
358 vbl_sig->info.si_code = vbl_seq; 384 drm_vbl_sig_t *vbl_sigs = i ? &dev->vbl_sigs2 : &dev->vbl_sigs;
359 send_sig_info(vbl_sig->info.si_signo, &vbl_sig->info, 385 unsigned int vbl_seq = atomic_read(i ? &dev->vbl_received2 :
360 vbl_sig->task); 386 &dev->vbl_received);
387
388 list_for_each_safe(list, tmp, &vbl_sigs->head) {
389 vbl_sig = list_entry(list, drm_vbl_sig_t, head);
390 if ((vbl_seq - vbl_sig->sequence) <= (1 << 23)) {
391 vbl_sig->info.si_code = vbl_seq;
392 send_sig_info(vbl_sig->info.si_signo,
393 &vbl_sig->info, vbl_sig->task);
361 394
362 list_del(list); 395 list_del(list);
363 396
364 drm_free(vbl_sig, sizeof(*vbl_sig), DRM_MEM_DRIVER); 397 drm_free(vbl_sig, sizeof(*vbl_sig),
398 DRM_MEM_DRIVER);
365 399
366 dev->vbl_pending--; 400 dev->vbl_pending--;
401 }
367 } 402 }
368 } 403 }
369 404
@@ -371,3 +406,77 @@ void drm_vbl_send_signals(drm_device_t * dev)
371} 406}
372 407
373EXPORT_SYMBOL(drm_vbl_send_signals); 408EXPORT_SYMBOL(drm_vbl_send_signals);
409
410/**
411 * Tasklet wrapper function.
412 *
413 * \param data DRM device in disguise.
414 *
415 * Attempts to grab the HW lock and calls the driver callback on success. On
416 * failure, leave the lock marked as contended so the callback can be called
417 * from drm_unlock().
418 */
419static void drm_locked_tasklet_func(unsigned long data)
420{
421 drm_device_t *dev = (drm_device_t*)data;
422 unsigned long irqflags;
423
424 spin_lock_irqsave(&dev->tasklet_lock, irqflags);
425
426 if (!dev->locked_tasklet_func ||
427 !drm_lock_take(&dev->lock.hw_lock->lock,
428 DRM_KERNEL_CONTEXT)) {
429 spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
430 return;
431 }
432
433 dev->lock.lock_time = jiffies;
434 atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
435
436 dev->locked_tasklet_func(dev);
437
438 drm_lock_free(dev, &dev->lock.hw_lock->lock,
439 DRM_KERNEL_CONTEXT);
440
441 dev->locked_tasklet_func = NULL;
442
443 spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
444}
445
446/**
447 * Schedule a tasklet to call back a driver hook with the HW lock held.
448 *
449 * \param dev DRM device.
450 * \param func Driver callback.
451 *
452 * This is intended for triggering actions that require the HW lock from an
453 * interrupt handler. The lock will be grabbed ASAP after the interrupt handler
454 * completes. Note that the callback may be called from interrupt or process
455 * context, it must not make any assumptions about this. Also, the HW lock will
456 * be held with the kernel context or any client context.
457 */
458void drm_locked_tasklet(drm_device_t *dev, void (*func)(drm_device_t*))
459{
460 unsigned long irqflags;
461 static DECLARE_TASKLET(drm_tasklet, drm_locked_tasklet_func, 0);
462
463 if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ) ||
464 test_bit(TASKLET_STATE_SCHED, &drm_tasklet.state))
465 return;
466
467 spin_lock_irqsave(&dev->tasklet_lock, irqflags);
468
469 if (dev->locked_tasklet_func) {
470 spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
471 return;
472 }
473
474 dev->locked_tasklet_func = func;
475
476 spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
477
478 drm_tasklet.data = (unsigned long)dev;
479
480 tasklet_hi_schedule(&drm_tasklet);
481}
482EXPORT_SYMBOL(drm_locked_tasklet);
diff --git a/drivers/char/drm/drm_lock.c b/drivers/char/drm/drm_lock.c
index f9e45303498d..116ed0f2ac09 100644
--- a/drivers/char/drm/drm_lock.c
+++ b/drivers/char/drm/drm_lock.c
@@ -155,6 +155,7 @@ int drm_unlock(struct inode *inode, struct file *filp,
155 drm_file_t *priv = filp->private_data; 155 drm_file_t *priv = filp->private_data;
156 drm_device_t *dev = priv->head->dev; 156 drm_device_t *dev = priv->head->dev;
157 drm_lock_t lock; 157 drm_lock_t lock;
158 unsigned long irqflags;
158 159
159 if (copy_from_user(&lock, (drm_lock_t __user *) arg, sizeof(lock))) 160 if (copy_from_user(&lock, (drm_lock_t __user *) arg, sizeof(lock)))
160 return -EFAULT; 161 return -EFAULT;
@@ -165,6 +166,16 @@ int drm_unlock(struct inode *inode, struct file *filp,
165 return -EINVAL; 166 return -EINVAL;
166 } 167 }
167 168
169 spin_lock_irqsave(&dev->tasklet_lock, irqflags);
170
171 if (dev->locked_tasklet_func) {
172 dev->locked_tasklet_func(dev);
173
174 dev->locked_tasklet_func = NULL;
175 }
176
177 spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
178
168 atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]); 179 atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
169 180
170 /* kernel_context_switch isn't used by any of the x86 drm 181 /* kernel_context_switch isn't used by any of the x86 drm
diff --git a/drivers/char/drm/drm_mm.c b/drivers/char/drm/drm_mm.c
new file mode 100644
index 000000000000..617526bd5b0c
--- /dev/null
+++ b/drivers/char/drm/drm_mm.c
@@ -0,0 +1,201 @@
1/**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 *
27 **************************************************************************/
28
29/*
30 * Generic simple memory manager implementation. Intended to be used as a base
31 * class implementation for more advanced memory managers.
32 *
33 * Note that the algorithm used is quite simple and there might be substantial
34 * performance gains if a smarter free list is implemented. Currently it is just an
35 * unordered stack of free regions. This could easily be improved if an RB-tree
36 * is used instead. At least if we expect heavy fragmentation.
37 *
38 * Aligned allocations can also see improvement.
39 *
40 * Authors:
41 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
42 */
43
44#include "drmP.h"
45
46drm_mm_node_t *drm_mm_get_block(drm_mm_node_t * parent,
47 unsigned long size, unsigned alignment)
48{
49
50 drm_mm_node_t *child;
51
52 if (alignment)
53 size += alignment - 1;
54
55 if (parent->size == size) {
56 list_del_init(&parent->fl_entry);
57 parent->free = 0;
58 return parent;
59 } else {
60 child = (drm_mm_node_t *) drm_alloc(sizeof(*child), DRM_MEM_MM);
61 if (!child)
62 return NULL;
63
64 INIT_LIST_HEAD(&child->ml_entry);
65 INIT_LIST_HEAD(&child->fl_entry);
66
67 child->free = 0;
68 child->size = size;
69 child->start = parent->start;
70
71 list_add_tail(&child->ml_entry, &parent->ml_entry);
72 parent->size -= size;
73 parent->start += size;
74 }
75 return child;
76}
77
78/*
79 * Put a block. Merge with the previous and / or next block if they are free.
80 * Otherwise add to the free stack.
81 */
82
83void drm_mm_put_block(drm_mm_t * mm, drm_mm_node_t * cur)
84{
85
86 drm_mm_node_t *list_root = &mm->root_node;
87 struct list_head *cur_head = &cur->ml_entry;
88 struct list_head *root_head = &list_root->ml_entry;
89 drm_mm_node_t *prev_node = NULL;
90 drm_mm_node_t *next_node;
91
92 int merged = 0;
93
94 if (cur_head->prev != root_head) {
95 prev_node = list_entry(cur_head->prev, drm_mm_node_t, ml_entry);
96 if (prev_node->free) {
97 prev_node->size += cur->size;
98 merged = 1;
99 }
100 }
101 if (cur_head->next != root_head) {
102 next_node = list_entry(cur_head->next, drm_mm_node_t, ml_entry);
103 if (next_node->free) {
104 if (merged) {
105 prev_node->size += next_node->size;
106 list_del(&next_node->ml_entry);
107 list_del(&next_node->fl_entry);
108 drm_free(next_node, sizeof(*next_node),
109 DRM_MEM_MM);
110 } else {
111 next_node->size += cur->size;
112 next_node->start = cur->start;
113 merged = 1;
114 }
115 }
116 }
117 if (!merged) {
118 cur->free = 1;
119 list_add(&cur->fl_entry, &list_root->fl_entry);
120 } else {
121 list_del(&cur->ml_entry);
122 drm_free(cur, sizeof(*cur), DRM_MEM_MM);
123 }
124}
125
126drm_mm_node_t *drm_mm_search_free(const drm_mm_t * mm,
127 unsigned long size,
128 unsigned alignment, int best_match)
129{
130 struct list_head *list;
131 const struct list_head *free_stack = &mm->root_node.fl_entry;
132 drm_mm_node_t *entry;
133 drm_mm_node_t *best;
134 unsigned long best_size;
135
136 best = NULL;
137 best_size = ~0UL;
138
139 if (alignment)
140 size += alignment - 1;
141
142 list_for_each(list, free_stack) {
143 entry = list_entry(list, drm_mm_node_t, fl_entry);
144 if (entry->size >= size) {
145 if (!best_match)
146 return entry;
147 if (size < best_size) {
148 best = entry;
149 best_size = entry->size;
150 }
151 }
152 }
153
154 return best;
155}
156
157int drm_mm_init(drm_mm_t * mm, unsigned long start, unsigned long size)
158{
159 drm_mm_node_t *child;
160
161 INIT_LIST_HEAD(&mm->root_node.ml_entry);
162 INIT_LIST_HEAD(&mm->root_node.fl_entry);
163 child = (drm_mm_node_t *) drm_alloc(sizeof(*child), DRM_MEM_MM);
164 if (!child)
165 return -ENOMEM;
166
167 INIT_LIST_HEAD(&child->ml_entry);
168 INIT_LIST_HEAD(&child->fl_entry);
169
170 child->start = start;
171 child->size = size;
172 child->free = 1;
173
174 list_add(&child->fl_entry, &mm->root_node.fl_entry);
175 list_add(&child->ml_entry, &mm->root_node.ml_entry);
176
177 return 0;
178}
179
180EXPORT_SYMBOL(drm_mm_init);
181
182void drm_mm_takedown(drm_mm_t * mm)
183{
184 struct list_head *bnode = mm->root_node.fl_entry.next;
185 drm_mm_node_t *entry;
186
187 entry = list_entry(bnode, drm_mm_node_t, fl_entry);
188
189 if (entry->ml_entry.next != &mm->root_node.ml_entry ||
190 entry->fl_entry.next != &mm->root_node.fl_entry) {
191 DRM_ERROR("Memory manager not clean. Delaying takedown\n");
192 return;
193 }
194
195 list_del(&entry->fl_entry);
196 list_del(&entry->ml_entry);
197
198 drm_free(entry, sizeof(*entry), DRM_MEM_MM);
199}
200
201EXPORT_SYMBOL(drm_mm_takedown);
diff --git a/drivers/char/drm/drm_os_linux.h b/drivers/char/drm/drm_os_linux.h
index 695115d70382..2908b72daa6e 100644
--- a/drivers/char/drm/drm_os_linux.h
+++ b/drivers/char/drm/drm_os_linux.h
@@ -38,7 +38,7 @@
38 drm_device_t *dev = priv->head->dev 38 drm_device_t *dev = priv->head->dev
39 39
40/** IRQ handler arguments and return type and values */ 40/** IRQ handler arguments and return type and values */
41#define DRM_IRQ_ARGS int irq, void *arg, struct pt_regs *regs 41#define DRM_IRQ_ARGS int irq, void *arg
42 42
43/** AGP types */ 43/** AGP types */
44#if __OS_HAS_AGP 44#if __OS_HAS_AGP
diff --git a/drivers/char/drm/drm_pciids.h b/drivers/char/drm/drm_pciids.h
index b1bb3c7b568d..09398d5fbd3f 100644
--- a/drivers/char/drm/drm_pciids.h
+++ b/drivers/char/drm/drm_pciids.h
@@ -3,13 +3,13 @@
3 Please contact dri-devel@lists.sf.net to add new cards to this list 3 Please contact dri-devel@lists.sf.net to add new cards to this list
4*/ 4*/
5#define radeon_PCI_IDS \ 5#define radeon_PCI_IDS \
6 {0x1002, 0x3150, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY}, \ 6 {0x1002, 0x3150, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \
7 {0x1002, 0x3152, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 7 {0x1002, 0x3152, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
8 {0x1002, 0x3154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 8 {0x1002, 0x3154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
9 {0x1002, 0x3E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \ 9 {0x1002, 0x3E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
10 {0x1002, 0x3E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \ 10 {0x1002, 0x3E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
11 {0x1002, 0x4136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|CHIP_IS_IGP}, \ 11 {0x1002, 0x4136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|RADEON_IS_IGP}, \
12 {0x1002, 0x4137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|CHIP_IS_IGP}, \ 12 {0x1002, 0x4137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|RADEON_IS_IGP}, \
13 {0x1002, 0x4144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 13 {0x1002, 0x4144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
14 {0x1002, 0x4145, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 14 {0x1002, 0x4145, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
15 {0x1002, 0x4146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 15 {0x1002, 0x4146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
@@ -25,35 +25,35 @@
25 {0x1002, 0x4154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \ 25 {0x1002, 0x4154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
26 {0x1002, 0x4155, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \ 26 {0x1002, 0x4155, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
27 {0x1002, 0x4156, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \ 27 {0x1002, 0x4156, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
28 {0x1002, 0x4237, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|CHIP_IS_IGP}, \ 28 {0x1002, 0x4237, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|RADEON_IS_IGP}, \
29 {0x1002, 0x4242, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 29 {0x1002, 0x4242, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
30 {0x1002, 0x4243, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 30 {0x1002, 0x4243, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
31 {0x1002, 0x4336, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|CHIP_IS_IGP|CHIP_IS_MOBILITY}, \ 31 {0x1002, 0x4336, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
32 {0x1002, 0x4337, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|CHIP_IS_IGP|CHIP_IS_MOBILITY}, \ 32 {0x1002, 0x4337, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
33 {0x1002, 0x4437, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|CHIP_IS_IGP|CHIP_IS_MOBILITY}, \ 33 {0x1002, 0x4437, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
34 {0x1002, 0x4966, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250}, \ 34 {0x1002, 0x4966, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250}, \
35 {0x1002, 0x4967, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250}, \ 35 {0x1002, 0x4967, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250}, \
36 {0x1002, 0x4A48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 36 {0x1002, 0x4A48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
37 {0x1002, 0x4A49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 37 {0x1002, 0x4A49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
38 {0x1002, 0x4A4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 38 {0x1002, 0x4A4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
39 {0x1002, 0x4A4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 39 {0x1002, 0x4A4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
40 {0x1002, 0x4A4C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 40 {0x1002, 0x4A4C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
41 {0x1002, 0x4A4D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 41 {0x1002, 0x4A4D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
42 {0x1002, 0x4A4E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 42 {0x1002, 0x4A4E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
43 {0x1002, 0x4A4F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 43 {0x1002, 0x4A4F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
44 {0x1002, 0x4A50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 44 {0x1002, 0x4A50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
45 {0x1002, 0x4A54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 45 {0x1002, 0x4A54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
46 {0x1002, 0x4B49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 46 {0x1002, 0x4B49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
47 {0x1002, 0x4B4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 47 {0x1002, 0x4B4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
48 {0x1002, 0x4B4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 48 {0x1002, 0x4B4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
49 {0x1002, 0x4B4C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 49 {0x1002, 0x4B4C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
50 {0x1002, 0x4C57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200|CHIP_IS_MOBILITY}, \ 50 {0x1002, 0x4C57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200|RADEON_IS_MOBILITY}, \
51 {0x1002, 0x4C58, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200|CHIP_IS_MOBILITY}, \ 51 {0x1002, 0x4C58, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200|RADEON_IS_MOBILITY}, \
52 {0x1002, 0x4C59, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100|CHIP_IS_MOBILITY}, \ 52 {0x1002, 0x4C59, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100|RADEON_IS_MOBILITY}, \
53 {0x1002, 0x4C5A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100|CHIP_IS_MOBILITY}, \ 53 {0x1002, 0x4C5A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100|RADEON_IS_MOBILITY}, \
54 {0x1002, 0x4C64, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|CHIP_IS_MOBILITY}, \ 54 {0x1002, 0x4C64, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|RADEON_IS_MOBILITY}, \
55 {0x1002, 0x4C66, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|CHIP_IS_MOBILITY}, \ 55 {0x1002, 0x4C66, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|RADEON_IS_MOBILITY}, \
56 {0x1002, 0x4C67, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|CHIP_IS_MOBILITY}, \ 56 {0x1002, 0x4C67, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|RADEON_IS_MOBILITY}, \
57 {0x1002, 0x4E44, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 57 {0x1002, 0x4E44, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
58 {0x1002, 0x4E45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 58 {0x1002, 0x4E45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
59 {0x1002, 0x4E46, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 59 {0x1002, 0x4E46, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
@@ -62,16 +62,16 @@
62 {0x1002, 0x4E49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \ 62 {0x1002, 0x4E49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
63 {0x1002, 0x4E4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \ 63 {0x1002, 0x4E4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
64 {0x1002, 0x4E4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \ 64 {0x1002, 0x4E4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
65 {0x1002, 0x4E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \ 65 {0x1002, 0x4E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
66 {0x1002, 0x4E51, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \ 66 {0x1002, 0x4E51, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
67 {0x1002, 0x4E52, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \ 67 {0x1002, 0x4E52, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
68 {0x1002, 0x4E53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \ 68 {0x1002, 0x4E53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
69 {0x1002, 0x4E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \ 69 {0x1002, 0x4E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
70 {0x1002, 0x4E56, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \ 70 {0x1002, 0x4E56, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
71 {0x1002, 0x5144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|CHIP_SINGLE_CRTC}, \ 71 {0x1002, 0x5144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|RADEON_SINGLE_CRTC}, \
72 {0x1002, 0x5145, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|CHIP_SINGLE_CRTC}, \ 72 {0x1002, 0x5145, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|RADEON_SINGLE_CRTC}, \
73 {0x1002, 0x5146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|CHIP_SINGLE_CRTC}, \ 73 {0x1002, 0x5146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|RADEON_SINGLE_CRTC}, \
74 {0x1002, 0x5147, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|CHIP_SINGLE_CRTC}, \ 74 {0x1002, 0x5147, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|RADEON_SINGLE_CRTC}, \
75 {0x1002, 0x5148, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 75 {0x1002, 0x5148, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
76 {0x1002, 0x514C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 76 {0x1002, 0x514C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
77 {0x1002, 0x514D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 77 {0x1002, 0x514D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
@@ -80,59 +80,59 @@
80 {0x1002, 0x5159, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \ 80 {0x1002, 0x5159, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
81 {0x1002, 0x515A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \ 81 {0x1002, 0x515A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
82 {0x1002, 0x515E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \ 82 {0x1002, 0x515E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
83 {0x1002, 0x5460, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY}, \ 83 {0x1002, 0x5460, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \
84 {0x1002, 0x5462, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY}, \ 84 {0x1002, 0x5462, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \
85 {0x1002, 0x5464, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY}, \ 85 {0x1002, 0x5464, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \
86 {0x1002, 0x5548, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 86 {0x1002, 0x5548, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
87 {0x1002, 0x5549, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 87 {0x1002, 0x5549, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
88 {0x1002, 0x554A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 88 {0x1002, 0x554A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
89 {0x1002, 0x554B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 89 {0x1002, 0x554B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
90 {0x1002, 0x554C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 90 {0x1002, 0x554C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
91 {0x1002, 0x554D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 91 {0x1002, 0x554D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
92 {0x1002, 0x554E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 92 {0x1002, 0x554E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
93 {0x1002, 0x554F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 93 {0x1002, 0x554F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
94 {0x1002, 0x5550, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 94 {0x1002, 0x5550, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
95 {0x1002, 0x5551, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 95 {0x1002, 0x5551, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
96 {0x1002, 0x5552, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 96 {0x1002, 0x5552, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
97 {0x1002, 0x5554, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 97 {0x1002, 0x5554, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
98 {0x1002, 0x564A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 98 {0x1002, 0x564A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
99 {0x1002, 0x564B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 99 {0x1002, 0x564B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
100 {0x1002, 0x564F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 100 {0x1002, 0x564F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
101 {0x1002, 0x5652, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 101 {0x1002, 0x5652, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
102 {0x1002, 0x5653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 102 {0x1002, 0x5653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
103 {0x1002, 0x5834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|CHIP_IS_IGP}, \ 103 {0x1002, 0x5834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP}, \
104 {0x1002, 0x5835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|CHIP_IS_IGP|CHIP_IS_MOBILITY}, \ 104 {0x1002, 0x5835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
105 {0x1002, 0x5960, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 105 {0x1002, 0x5960, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
106 {0x1002, 0x5961, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 106 {0x1002, 0x5961, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
107 {0x1002, 0x5962, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 107 {0x1002, 0x5962, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
108 {0x1002, 0x5964, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 108 {0x1002, 0x5964, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
109 {0x1002, 0x5965, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 109 {0x1002, 0x5965, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
110 {0x1002, 0x5969, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \ 110 {0x1002, 0x5969, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
111 {0x1002, 0x5b60, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \ 111 {0x1002, 0x5b60, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
112 {0x1002, 0x5b62, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \ 112 {0x1002, 0x5b62, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
113 {0x1002, 0x5b63, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \ 113 {0x1002, 0x5b63, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
114 {0x1002, 0x5b64, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \ 114 {0x1002, 0x5b64, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
115 {0x1002, 0x5b65, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \ 115 {0x1002, 0x5b65, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
116 {0x1002, 0x5c61, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280|CHIP_IS_MOBILITY}, \ 116 {0x1002, 0x5c61, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280|RADEON_IS_MOBILITY}, \
117 {0x1002, 0x5c63, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280|CHIP_IS_MOBILITY}, \ 117 {0x1002, 0x5c63, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280|RADEON_IS_MOBILITY}, \
118 {0x1002, 0x5d48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 118 {0x1002, 0x5d48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
119 {0x1002, 0x5d49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 119 {0x1002, 0x5d49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
120 {0x1002, 0x5d4a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 120 {0x1002, 0x5d4a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
121 {0x1002, 0x5d4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 121 {0x1002, 0x5d4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
122 {0x1002, 0x5d4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 122 {0x1002, 0x5d4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
123 {0x1002, 0x5d4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 123 {0x1002, 0x5d4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
124 {0x1002, 0x5d4f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 124 {0x1002, 0x5d4f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
125 {0x1002, 0x5d50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 125 {0x1002, 0x5d50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
126 {0x1002, 0x5d52, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 126 {0x1002, 0x5d52, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
127 {0x1002, 0x5d57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \ 127 {0x1002, 0x5d57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
128 {0x1002, 0x5e48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \ 128 {0x1002, 0x5e48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
129 {0x1002, 0x5e4a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \ 129 {0x1002, 0x5e4a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
130 {0x1002, 0x5e4b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \ 130 {0x1002, 0x5e4b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
131 {0x1002, 0x5e4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \ 131 {0x1002, 0x5e4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
132 {0x1002, 0x5e4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \ 132 {0x1002, 0x5e4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
133 {0x1002, 0x5e4f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \ 133 {0x1002, 0x5e4f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
134 {0x1002, 0x7834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|CHIP_IS_IGP|CHIP_NEW_MEMMAP}, \ 134 {0x1002, 0x7834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_NEW_MEMMAP}, \
135 {0x1002, 0x7835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|CHIP_IS_IGP|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \ 135 {0x1002, 0x7835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
136 {0, 0, 0} 136 {0, 0, 0}
137 137
138#define r128_PCI_IDS \ 138#define r128_PCI_IDS \
@@ -209,6 +209,7 @@
209 {0x1039, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 209 {0x1039, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
210 {0x1039, 0x5300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 210 {0x1039, 0x5300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
211 {0x1039, 0x6300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 211 {0x1039, 0x6300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
212 {0x1039, 0x6330, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
212 {0x1039, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 213 {0x1039, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
213 {0, 0, 0} 214 {0, 0, 0}
214 215
@@ -227,6 +228,10 @@
227 {0x1106, 0x3122, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 228 {0x1106, 0x3122, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
228 {0x1106, 0x7205, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 229 {0x1106, 0x7205, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
229 {0x1106, 0x3108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 230 {0x1106, 0x3108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
231 {0x1106, 0x3304, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
232 {0x1106, 0x3157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
233 {0x1106, 0x3344, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
234 {0x1106, 0x7204, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
230 {0, 0, 0} 235 {0, 0, 0}
231 236
232#define i810_PCI_IDS \ 237#define i810_PCI_IDS \
@@ -285,5 +290,9 @@
285 {0x8086, 0x2592, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 290 {0x8086, 0x2592, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
286 {0x8086, 0x2772, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 291 {0x8086, 0x2772, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
287 {0x8086, 0x27a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 292 {0x8086, 0x27a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
293 {0x8086, 0x2972, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
294 {0x8086, 0x2982, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
295 {0x8086, 0x2992, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
296 {0x8086, 0x29a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
288 {0, 0, 0} 297 {0, 0, 0}
289 298
diff --git a/drivers/char/drm/drm_proc.c b/drivers/char/drm/drm_proc.c
index 362a270af0f1..62d5fe15f046 100644
--- a/drivers/char/drm/drm_proc.c
+++ b/drivers/char/drm/drm_proc.c
@@ -510,7 +510,7 @@ static int drm__vma_info(char *buf, char **start, off_t offset, int request,
510 vma->vm_flags & VM_MAYSHARE ? 's' : 'p', 510 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
511 vma->vm_flags & VM_LOCKED ? 'l' : '-', 511 vma->vm_flags & VM_LOCKED ? 'l' : '-',
512 vma->vm_flags & VM_IO ? 'i' : '-', 512 vma->vm_flags & VM_IO ? 'i' : '-',
513 VM_OFFSET(vma)); 513 vma->vm_pgoff << PAGE_SHIFT);
514 514
515#if defined(__i386__) 515#if defined(__i386__)
516 pgprot = pgprot_val(vma->vm_page_prot); 516 pgprot = pgprot_val(vma->vm_page_prot);
diff --git a/drivers/char/drm/drm_sman.c b/drivers/char/drm/drm_sman.c
new file mode 100644
index 000000000000..19c81d2e13d0
--- /dev/null
+++ b/drivers/char/drm/drm_sman.c
@@ -0,0 +1,353 @@
1/**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck., ND., USA.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 *
26 *
27 **************************************************************************/
28/*
29 * Simple memory manager interface that keeps track on allocate regions on a
30 * per "owner" basis. All regions associated with an "owner" can be released
31 * with a simple call. Typically if the "owner" exists. The owner is any
32 * "unsigned long" identifier. Can typically be a pointer to a file private
33 * struct or a context identifier.
34 *
35 * Authors:
36 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
37 */
38
39#include "drm_sman.h"
40
41typedef struct drm_owner_item {
42 drm_hash_item_t owner_hash;
43 struct list_head sman_list;
44 struct list_head mem_blocks;
45} drm_owner_item_t;
46
47void drm_sman_takedown(drm_sman_t * sman)
48{
49 drm_ht_remove(&sman->user_hash_tab);
50 drm_ht_remove(&sman->owner_hash_tab);
51 if (sman->mm)
52 drm_free(sman->mm, sman->num_managers * sizeof(*sman->mm),
53 DRM_MEM_MM);
54}
55
56EXPORT_SYMBOL(drm_sman_takedown);
57
58int
59drm_sman_init(drm_sman_t * sman, unsigned int num_managers,
60 unsigned int user_order, unsigned int owner_order)
61{
62 int ret = 0;
63
64 sman->mm = (drm_sman_mm_t *) drm_calloc(num_managers, sizeof(*sman->mm),
65 DRM_MEM_MM);
66 if (!sman->mm) {
67 ret = -ENOMEM;
68 goto out;
69 }
70 sman->num_managers = num_managers;
71 INIT_LIST_HEAD(&sman->owner_items);
72 ret = drm_ht_create(&sman->owner_hash_tab, owner_order);
73 if (ret)
74 goto out1;
75 ret = drm_ht_create(&sman->user_hash_tab, user_order);
76 if (!ret)
77 goto out;
78
79 drm_ht_remove(&sman->owner_hash_tab);
80out1:
81 drm_free(sman->mm, num_managers * sizeof(*sman->mm), DRM_MEM_MM);
82out:
83 return ret;
84}
85
86EXPORT_SYMBOL(drm_sman_init);
87
88static void *drm_sman_mm_allocate(void *private, unsigned long size,
89 unsigned alignment)
90{
91 drm_mm_t *mm = (drm_mm_t *) private;
92 drm_mm_node_t *tmp;
93
94 tmp = drm_mm_search_free(mm, size, alignment, 1);
95 if (!tmp) {
96 return NULL;
97 }
98 tmp = drm_mm_get_block(tmp, size, alignment);
99 return tmp;
100}
101
102static void drm_sman_mm_free(void *private, void *ref)
103{
104 drm_mm_t *mm = (drm_mm_t *) private;
105 drm_mm_node_t *node = (drm_mm_node_t *) ref;
106
107 drm_mm_put_block(mm, node);
108}
109
110static void drm_sman_mm_destroy(void *private)
111{
112 drm_mm_t *mm = (drm_mm_t *) private;
113 drm_mm_takedown(mm);
114 drm_free(mm, sizeof(*mm), DRM_MEM_MM);
115}
116
117static unsigned long drm_sman_mm_offset(void *private, void *ref)
118{
119 drm_mm_node_t *node = (drm_mm_node_t *) ref;
120 return node->start;
121}
122
123int
124drm_sman_set_range(drm_sman_t * sman, unsigned int manager,
125 unsigned long start, unsigned long size)
126{
127 drm_sman_mm_t *sman_mm;
128 drm_mm_t *mm;
129 int ret;
130
131 BUG_ON(manager >= sman->num_managers);
132
133 sman_mm = &sman->mm[manager];
134 mm = drm_calloc(1, sizeof(*mm), DRM_MEM_MM);
135 if (!mm) {
136 return -ENOMEM;
137 }
138 sman_mm->private = mm;
139 ret = drm_mm_init(mm, start, size);
140
141 if (ret) {
142 drm_free(mm, sizeof(*mm), DRM_MEM_MM);
143 return ret;
144 }
145
146 sman_mm->allocate = drm_sman_mm_allocate;
147 sman_mm->free = drm_sman_mm_free;
148 sman_mm->destroy = drm_sman_mm_destroy;
149 sman_mm->offset = drm_sman_mm_offset;
150
151 return 0;
152}
153
154EXPORT_SYMBOL(drm_sman_set_range);
155
156int
157drm_sman_set_manager(drm_sman_t * sman, unsigned int manager,
158 drm_sman_mm_t * allocator)
159{
160 BUG_ON(manager >= sman->num_managers);
161 sman->mm[manager] = *allocator;
162
163 return 0;
164}
165EXPORT_SYMBOL(drm_sman_set_manager);
166
167static drm_owner_item_t *drm_sman_get_owner_item(drm_sman_t * sman,
168 unsigned long owner)
169{
170 int ret;
171 drm_hash_item_t *owner_hash_item;
172 drm_owner_item_t *owner_item;
173
174 ret = drm_ht_find_item(&sman->owner_hash_tab, owner, &owner_hash_item);
175 if (!ret) {
176 return drm_hash_entry(owner_hash_item, drm_owner_item_t,
177 owner_hash);
178 }
179
180 owner_item = drm_calloc(1, sizeof(*owner_item), DRM_MEM_MM);
181 if (!owner_item)
182 goto out;
183
184 INIT_LIST_HEAD(&owner_item->mem_blocks);
185 owner_item->owner_hash.key = owner;
186 if (drm_ht_insert_item(&sman->owner_hash_tab, &owner_item->owner_hash))
187 goto out1;
188
189 list_add_tail(&owner_item->sman_list, &sman->owner_items);
190 return owner_item;
191
192out1:
193 drm_free(owner_item, sizeof(*owner_item), DRM_MEM_MM);
194out:
195 return NULL;
196}
197
198drm_memblock_item_t *drm_sman_alloc(drm_sman_t *sman, unsigned int manager,
199 unsigned long size, unsigned alignment,
200 unsigned long owner)
201{
202 void *tmp;
203 drm_sman_mm_t *sman_mm;
204 drm_owner_item_t *owner_item;
205 drm_memblock_item_t *memblock;
206
207 BUG_ON(manager >= sman->num_managers);
208
209 sman_mm = &sman->mm[manager];
210 tmp = sman_mm->allocate(sman_mm->private, size, alignment);
211
212 if (!tmp) {
213 return NULL;
214 }
215
216 memblock = drm_calloc(1, sizeof(*memblock), DRM_MEM_MM);
217
218 if (!memblock)
219 goto out;
220
221 memblock->mm_info = tmp;
222 memblock->mm = sman_mm;
223 memblock->sman = sman;
224
225 if (drm_ht_just_insert_please
226 (&sman->user_hash_tab, &memblock->user_hash,
227 (unsigned long)memblock, 32, 0, 0))
228 goto out1;
229
230 owner_item = drm_sman_get_owner_item(sman, owner);
231 if (!owner_item)
232 goto out2;
233
234 list_add_tail(&memblock->owner_list, &owner_item->mem_blocks);
235
236 return memblock;
237
238out2:
239 drm_ht_remove_item(&sman->user_hash_tab, &memblock->user_hash);
240out1:
241 drm_free(memblock, sizeof(*memblock), DRM_MEM_MM);
242out:
243 sman_mm->free(sman_mm->private, tmp);
244
245 return NULL;
246}
247
248EXPORT_SYMBOL(drm_sman_alloc);
249
250static void drm_sman_free(drm_memblock_item_t *item)
251{
252 drm_sman_t *sman = item->sman;
253
254 list_del(&item->owner_list);
255 drm_ht_remove_item(&sman->user_hash_tab, &item->user_hash);
256 item->mm->free(item->mm->private, item->mm_info);
257 drm_free(item, sizeof(*item), DRM_MEM_MM);
258}
259
260int drm_sman_free_key(drm_sman_t *sman, unsigned int key)
261{
262 drm_hash_item_t *hash_item;
263 drm_memblock_item_t *memblock_item;
264
265 if (drm_ht_find_item(&sman->user_hash_tab, key, &hash_item))
266 return -EINVAL;
267
268 memblock_item = drm_hash_entry(hash_item, drm_memblock_item_t, user_hash);
269 drm_sman_free(memblock_item);
270 return 0;
271}
272
273EXPORT_SYMBOL(drm_sman_free_key);
274
275static void drm_sman_remove_owner(drm_sman_t *sman,
276 drm_owner_item_t *owner_item)
277{
278 list_del(&owner_item->sman_list);
279 drm_ht_remove_item(&sman->owner_hash_tab, &owner_item->owner_hash);
280 drm_free(owner_item, sizeof(*owner_item), DRM_MEM_MM);
281}
282
283int drm_sman_owner_clean(drm_sman_t *sman, unsigned long owner)
284{
285
286 drm_hash_item_t *hash_item;
287 drm_owner_item_t *owner_item;
288
289 if (drm_ht_find_item(&sman->owner_hash_tab, owner, &hash_item)) {
290 return -1;
291 }
292
293 owner_item = drm_hash_entry(hash_item, drm_owner_item_t, owner_hash);
294 if (owner_item->mem_blocks.next == &owner_item->mem_blocks) {
295 drm_sman_remove_owner(sman, owner_item);
296 return -1;
297 }
298
299 return 0;
300}
301
302EXPORT_SYMBOL(drm_sman_owner_clean);
303
304static void drm_sman_do_owner_cleanup(drm_sman_t *sman,
305 drm_owner_item_t *owner_item)
306{
307 drm_memblock_item_t *entry, *next;
308
309 list_for_each_entry_safe(entry, next, &owner_item->mem_blocks,
310 owner_list) {
311 drm_sman_free(entry);
312 }
313 drm_sman_remove_owner(sman, owner_item);
314}
315
316void drm_sman_owner_cleanup(drm_sman_t *sman, unsigned long owner)
317{
318
319 drm_hash_item_t *hash_item;
320 drm_owner_item_t *owner_item;
321
322 if (drm_ht_find_item(&sman->owner_hash_tab, owner, &hash_item)) {
323
324 return;
325 }
326
327 owner_item = drm_hash_entry(hash_item, drm_owner_item_t, owner_hash);
328 drm_sman_do_owner_cleanup(sman, owner_item);
329}
330
331EXPORT_SYMBOL(drm_sman_owner_cleanup);
332
333void drm_sman_cleanup(drm_sman_t *sman)
334{
335 drm_owner_item_t *entry, *next;
336 unsigned int i;
337 drm_sman_mm_t *sman_mm;
338
339 list_for_each_entry_safe(entry, next, &sman->owner_items, sman_list) {
340 drm_sman_do_owner_cleanup(sman, entry);
341 }
342 if (sman->mm) {
343 for (i = 0; i < sman->num_managers; ++i) {
344 sman_mm = &sman->mm[i];
345 if (sman_mm->private) {
346 sman_mm->destroy(sman_mm->private);
347 sman_mm->private = NULL;
348 }
349 }
350 }
351}
352
353EXPORT_SYMBOL(drm_sman_cleanup);
diff --git a/drivers/char/drm/drm_sman.h b/drivers/char/drm/drm_sman.h
new file mode 100644
index 000000000000..ddc732a1bf27
--- /dev/null
+++ b/drivers/char/drm/drm_sman.h
@@ -0,0 +1,176 @@
1/**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 *
27 **************************************************************************/
28/*
29 * Simple memory MANager interface that keeps track on allocate regions on a
30 * per "owner" basis. All regions associated with an "owner" can be released
31 * with a simple call. Typically if the "owner" exists. The owner is any
32 * "unsigned long" identifier. Can typically be a pointer to a file private
33 * struct or a context identifier.
34 *
35 * Authors:
36 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
37 */
38
39#ifndef DRM_SMAN_H
40#define DRM_SMAN_H
41
42#include "drmP.h"
43#include "drm_hashtab.h"
44
45/*
46 * A class that is an abstration of a simple memory allocator.
47 * The sman implementation provides a default such allocator
48 * using the drm_mm.c implementation. But the user can replace it.
49 * See the SiS implementation, which may use the SiS FB kernel module
50 * for memory management.
51 */
52
53typedef struct drm_sman_mm {
54 /* private info. If allocated, needs to be destroyed by the destroy
55 function */
56 void *private;
57
58 /* Allocate a memory block with given size and alignment.
59 Return an opaque reference to the memory block */
60
61 void *(*allocate) (void *private, unsigned long size,
62 unsigned alignment);
63
64 /* Free a memory block. "ref" is the opaque reference that we got from
65 the "alloc" function */
66
67 void (*free) (void *private, void *ref);
68
69 /* Free all resources associated with this allocator */
70
71 void (*destroy) (void *private);
72
73 /* Return a memory offset from the opaque reference returned from the
74 "alloc" function */
75
76 unsigned long (*offset) (void *private, void *ref);
77} drm_sman_mm_t;
78
79typedef struct drm_memblock_item {
80 struct list_head owner_list;
81 drm_hash_item_t user_hash;
82 void *mm_info;
83 drm_sman_mm_t *mm;
84 struct drm_sman *sman;
85} drm_memblock_item_t;
86
87typedef struct drm_sman {
88 drm_sman_mm_t *mm;
89 int num_managers;
90 drm_open_hash_t owner_hash_tab;
91 drm_open_hash_t user_hash_tab;
92 struct list_head owner_items;
93} drm_sman_t;
94
95/*
96 * Take down a memory manager. This function should only be called after a
97 * successful init and after a call to drm_sman_cleanup.
98 */
99
100extern void drm_sman_takedown(drm_sman_t * sman);
101
102/*
103 * Allocate structures for a manager.
104 * num_managers are the number of memory pools to manage. (VRAM, AGP, ....)
105 * user_order is the log2 of the number of buckets in the user hash table.
106 * set this to approximately log2 of the max number of memory regions
107 * that will be allocated for _all_ pools together.
108 * owner_order is the log2 of the number of buckets in the owner hash table.
109 * set this to approximately log2 of
110 * the number of client file connections that will
111 * be using the manager.
112 *
113 */
114
115extern int drm_sman_init(drm_sman_t * sman, unsigned int num_managers,
116 unsigned int user_order, unsigned int owner_order);
117
118/*
119 * Initialize a drm_mm.c allocator. Should be called only once for each
120 * manager unless a customized allogator is used.
121 */
122
123extern int drm_sman_set_range(drm_sman_t * sman, unsigned int manager,
124 unsigned long start, unsigned long size);
125
126/*
127 * Initialize a customized allocator for one of the managers.
128 * (See the SiS module). The object pointed to by "allocator" is copied,
129 * so it can be destroyed after this call.
130 */
131
132extern int drm_sman_set_manager(drm_sman_t * sman, unsigned int mananger,
133 drm_sman_mm_t * allocator);
134
135/*
136 * Allocate a memory block. Aligment is not implemented yet.
137 */
138
139extern drm_memblock_item_t *drm_sman_alloc(drm_sman_t * sman,
140 unsigned int manager,
141 unsigned long size,
142 unsigned alignment,
143 unsigned long owner);
144/*
145 * Free a memory block identified by its user hash key.
146 */
147
148extern int drm_sman_free_key(drm_sman_t * sman, unsigned int key);
149
150/*
151 * returns 1 iff there are no stale memory blocks associated with this owner.
152 * Typically called to determine if we need to idle the hardware and call
153 * drm_sman_owner_cleanup. If there are no stale memory blocks, it removes all
154 * resources associated with owner.
155 */
156
157extern int drm_sman_owner_clean(drm_sman_t * sman, unsigned long owner);
158
159/*
160 * Frees all stale memory blocks associated with this owner. Note that this
161 * requires that the hardware is finished with all blocks, so the graphics engine
162 * should be idled before this call is made. This function also frees
163 * any resources associated with "owner" and should be called when owner
164 * is not going to be referenced anymore.
165 */
166
167extern void drm_sman_owner_cleanup(drm_sman_t * sman, unsigned long owner);
168
169/*
170 * Frees all stale memory blocks associated with the memory manager.
171 * See idling above.
172 */
173
174extern void drm_sman_cleanup(drm_sman_t * sman);
175
176#endif
diff --git a/drivers/char/drm/drm_stub.c b/drivers/char/drm/drm_stub.c
index 9a842a36bb27..5fd6dc0870cf 100644
--- a/drivers/char/drm/drm_stub.c
+++ b/drivers/char/drm/drm_stub.c
@@ -60,27 +60,29 @@ static int drm_fill_in_dev(drm_device_t * dev, struct pci_dev *pdev,
60 int retcode; 60 int retcode;
61 61
62 spin_lock_init(&dev->count_lock); 62 spin_lock_init(&dev->count_lock);
63 spin_lock_init(&dev->drw_lock);
64 spin_lock_init(&dev->tasklet_lock);
63 init_timer(&dev->timer); 65 init_timer(&dev->timer);
64 mutex_init(&dev->struct_mutex); 66 mutex_init(&dev->struct_mutex);
65 mutex_init(&dev->ctxlist_mutex); 67 mutex_init(&dev->ctxlist_mutex);
66 68
67 dev->pdev = pdev; 69 dev->pdev = pdev;
70 dev->pci_device = pdev->device;
71 dev->pci_vendor = pdev->vendor;
68 72
69#ifdef __alpha__ 73#ifdef __alpha__
70 dev->hose = pdev->sysdata; 74 dev->hose = pdev->sysdata;
71 dev->pci_domain = dev->hose->bus->number;
72#else
73 dev->pci_domain = 0;
74#endif 75#endif
75 dev->pci_bus = pdev->bus->number;
76 dev->pci_slot = PCI_SLOT(pdev->devfn);
77 dev->pci_func = PCI_FUNC(pdev->devfn);
78 dev->irq = pdev->irq; 76 dev->irq = pdev->irq;
79 77
80 dev->maplist = drm_calloc(1, sizeof(*dev->maplist), DRM_MEM_MAPS); 78 dev->maplist = drm_calloc(1, sizeof(*dev->maplist), DRM_MEM_MAPS);
81 if (dev->maplist == NULL) 79 if (dev->maplist == NULL)
82 return -ENOMEM; 80 return -ENOMEM;
83 INIT_LIST_HEAD(&dev->maplist->head); 81 INIT_LIST_HEAD(&dev->maplist->head);
82 if (drm_ht_create(&dev->map_hash, 12)) {
83 drm_free(dev->maplist, sizeof(*dev->maplist), DRM_MEM_MAPS);
84 return -ENOMEM;
85 }
84 86
85 /* the DRM has 6 basic counters */ 87 /* the DRM has 6 basic counters */
86 dev->counters = 6; 88 dev->counters = 6;
diff --git a/drivers/char/drm/drm_sysfs.c b/drivers/char/drm/drm_sysfs.c
index 51ad98c685c3..ba4b8de83cf0 100644
--- a/drivers/char/drm/drm_sysfs.c
+++ b/drivers/char/drm/drm_sysfs.c
@@ -42,13 +42,24 @@ static CLASS_ATTR(version, S_IRUGO, version_show, NULL);
42struct class *drm_sysfs_create(struct module *owner, char *name) 42struct class *drm_sysfs_create(struct module *owner, char *name)
43{ 43{
44 struct class *class; 44 struct class *class;
45 int err;
45 46
46 class = class_create(owner, name); 47 class = class_create(owner, name);
47 if (!class) 48 if (!class) {
48 return class; 49 err = -ENOMEM;
50 goto err_out;
51 }
52
53 err = class_create_file(class, &class_attr_version);
54 if (err)
55 goto err_out_class;
49 56
50 class_create_file(class, &class_attr_version);
51 return class; 57 return class;
58
59err_out_class:
60 class_destroy(class);
61err_out:
62 return ERR_PTR(err);
52} 63}
53 64
54/** 65/**
@@ -96,20 +107,36 @@ static struct class_device_attribute class_device_attrs[] = {
96struct class_device *drm_sysfs_device_add(struct class *cs, drm_head_t *head) 107struct class_device *drm_sysfs_device_add(struct class *cs, drm_head_t *head)
97{ 108{
98 struct class_device *class_dev; 109 struct class_device *class_dev;
99 int i; 110 int i, j, err;
100 111
101 class_dev = class_device_create(cs, NULL, 112 class_dev = class_device_create(cs, NULL,
102 MKDEV(DRM_MAJOR, head->minor), 113 MKDEV(DRM_MAJOR, head->minor),
103 &(head->dev->pdev)->dev, 114 &(head->dev->pdev)->dev,
104 "card%d", head->minor); 115 "card%d", head->minor);
105 if (!class_dev) 116 if (!class_dev) {
106 return NULL; 117 err = -ENOMEM;
118 goto err_out;
119 }
107 120
108 class_set_devdata(class_dev, head); 121 class_set_devdata(class_dev, head);
109 122
110 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) 123 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) {
111 class_device_create_file(class_dev, &class_device_attrs[i]); 124 err = class_device_create_file(class_dev,
125 &class_device_attrs[i]);
126 if (err)
127 goto err_out_files;
128 }
129
112 return class_dev; 130 return class_dev;
131
132err_out_files:
133 if (i > 0)
134 for (j = 0; j < i; j++)
135 class_device_remove_file(class_dev,
136 &class_device_attrs[i]);
137 class_device_unregister(class_dev);
138err_out:
139 return ERR_PTR(err);
113} 140}
114 141
115/** 142/**
diff --git a/drivers/char/drm/drm_vm.c b/drivers/char/drm/drm_vm.c
index ffd0800ed601..b9cfc077f6bc 100644
--- a/drivers/char/drm/drm_vm.c
+++ b/drivers/char/drm/drm_vm.c
@@ -59,7 +59,7 @@ static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
59 drm_device_t *dev = priv->head->dev; 59 drm_device_t *dev = priv->head->dev;
60 drm_map_t *map = NULL; 60 drm_map_t *map = NULL;
61 drm_map_list_t *r_list; 61 drm_map_list_t *r_list;
62 struct list_head *list; 62 drm_hash_item_t *hash;
63 63
64 /* 64 /*
65 * Find the right map 65 * Find the right map
@@ -70,14 +70,11 @@ static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
70 if (!dev->agp || !dev->agp->cant_use_aperture) 70 if (!dev->agp || !dev->agp->cant_use_aperture)
71 goto vm_nopage_error; 71 goto vm_nopage_error;
72 72
73 list_for_each(list, &dev->maplist->head) { 73 if (drm_ht_find_item(&dev->map_hash, vma->vm_pgoff << PAGE_SHIFT, &hash))
74 r_list = list_entry(list, drm_map_list_t, head); 74 goto vm_nopage_error;
75 map = r_list->map; 75
76 if (!map) 76 r_list = drm_hash_entry(hash, drm_map_list_t, hash);
77 continue; 77 map = r_list->map;
78 if (r_list->user_token == VM_OFFSET(vma))
79 break;
80 }
81 78
82 if (map && map->type == _DRM_AGP) { 79 if (map && map->type == _DRM_AGP) {
83 unsigned long offset = address - vma->vm_start; 80 unsigned long offset = address - vma->vm_start;
@@ -150,14 +147,14 @@ static __inline__ struct page *drm_do_vm_shm_nopage(struct vm_area_struct *vma,
150 if (address > vma->vm_end) 147 if (address > vma->vm_end)
151 return NOPAGE_SIGBUS; /* Disallow mremap */ 148 return NOPAGE_SIGBUS; /* Disallow mremap */
152 if (!map) 149 if (!map)
153 return NOPAGE_OOM; /* Nothing allocated */ 150 return NOPAGE_SIGBUS; /* Nothing allocated */
154 151
155 offset = address - vma->vm_start; 152 offset = address - vma->vm_start;
156 i = (unsigned long)map->handle + offset; 153 i = (unsigned long)map->handle + offset;
157 page = (map->type == _DRM_CONSISTENT) ? 154 page = (map->type == _DRM_CONSISTENT) ?
158 virt_to_page((void *)i) : vmalloc_to_page((void *)i); 155 virt_to_page((void *)i) : vmalloc_to_page((void *)i);
159 if (!page) 156 if (!page)
160 return NOPAGE_OOM; 157 return NOPAGE_SIGBUS;
161 get_page(page); 158 get_page(page);
162 159
163 DRM_DEBUG("shm_nopage 0x%lx\n", address); 160 DRM_DEBUG("shm_nopage 0x%lx\n", address);
@@ -275,7 +272,7 @@ static __inline__ struct page *drm_do_vm_dma_nopage(struct vm_area_struct *vma,
275 if (address > vma->vm_end) 272 if (address > vma->vm_end)
276 return NOPAGE_SIGBUS; /* Disallow mremap */ 273 return NOPAGE_SIGBUS; /* Disallow mremap */
277 if (!dma->pagelist) 274 if (!dma->pagelist)
278 return NOPAGE_OOM; /* Nothing allocated */ 275 return NOPAGE_SIGBUS; /* Nothing allocated */
279 276
280 offset = address - vma->vm_start; /* vm_[pg]off[set] should be 0 */ 277 offset = address - vma->vm_start; /* vm_[pg]off[set] should be 0 */
281 page_nr = offset >> PAGE_SHIFT; 278 page_nr = offset >> PAGE_SHIFT;
@@ -313,7 +310,7 @@ static __inline__ struct page *drm_do_vm_sg_nopage(struct vm_area_struct *vma,
313 if (address > vma->vm_end) 310 if (address > vma->vm_end)
314 return NOPAGE_SIGBUS; /* Disallow mremap */ 311 return NOPAGE_SIGBUS; /* Disallow mremap */
315 if (!entry->pagelist) 312 if (!entry->pagelist)
316 return NOPAGE_OOM; /* Nothing allocated */ 313 return NOPAGE_SIGBUS; /* Nothing allocated */
317 314
318 offset = address - vma->vm_start; 315 offset = address - vma->vm_start;
319 map_offset = map->offset - (unsigned long)dev->sg->virtual; 316 map_offset = map->offset - (unsigned long)dev->sg->virtual;
@@ -467,7 +464,7 @@ static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma)
467 dev = priv->head->dev; 464 dev = priv->head->dev;
468 dma = dev->dma; 465 dma = dev->dma;
469 DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n", 466 DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n",
470 vma->vm_start, vma->vm_end, VM_OFFSET(vma)); 467 vma->vm_start, vma->vm_end, vma->vm_pgoff << PAGE_SHIFT);
471 468
472 /* Length must match exact page count */ 469 /* Length must match exact page count */
473 if (!dma || (length >> PAGE_SHIFT) != dma->page_count) { 470 if (!dma || (length >> PAGE_SHIFT) != dma->page_count) {
@@ -476,6 +473,22 @@ static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma)
476 } 473 }
477 unlock_kernel(); 474 unlock_kernel();
478 475
476 if (!capable(CAP_SYS_ADMIN) &&
477 (dma->flags & _DRM_DMA_USE_PCI_RO)) {
478 vma->vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
479#if defined(__i386__) || defined(__x86_64__)
480 pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW;
481#else
482 /* Ye gads this is ugly. With more thought
483 we could move this up higher and use
484 `protection_map' instead. */
485 vma->vm_page_prot =
486 __pgprot(pte_val
487 (pte_wrprotect
488 (__pte(pgprot_val(vma->vm_page_prot)))));
489#endif
490 }
491
479 vma->vm_ops = &drm_vm_dma_ops; 492 vma->vm_ops = &drm_vm_dma_ops;
480 493
481 vma->vm_flags |= VM_RESERVED; /* Don't swap */ 494 vma->vm_flags |= VM_RESERVED; /* Don't swap */
@@ -521,12 +534,11 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma)
521 drm_file_t *priv = filp->private_data; 534 drm_file_t *priv = filp->private_data;
522 drm_device_t *dev = priv->head->dev; 535 drm_device_t *dev = priv->head->dev;
523 drm_map_t *map = NULL; 536 drm_map_t *map = NULL;
524 drm_map_list_t *r_list;
525 unsigned long offset = 0; 537 unsigned long offset = 0;
526 struct list_head *list; 538 drm_hash_item_t *hash;
527 539
528 DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n", 540 DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n",
529 vma->vm_start, vma->vm_end, VM_OFFSET(vma)); 541 vma->vm_start, vma->vm_end, vma->vm_pgoff << PAGE_SHIFT);
530 542
531 if (!priv->authenticated) 543 if (!priv->authenticated)
532 return -EACCES; 544 return -EACCES;
@@ -535,7 +547,7 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma)
535 * the AGP mapped at physical address 0 547 * the AGP mapped at physical address 0
536 * --BenH. 548 * --BenH.
537 */ 549 */
538 if (!VM_OFFSET(vma) 550 if (!(vma->vm_pgoff << PAGE_SHIFT)
539#if __OS_HAS_AGP 551#if __OS_HAS_AGP
540 && (!dev->agp 552 && (!dev->agp
541 || dev->agp->agp_info.device->vendor != PCI_VENDOR_ID_APPLE) 553 || dev->agp->agp_info.device->vendor != PCI_VENDOR_ID_APPLE)
@@ -543,23 +555,12 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma)
543 ) 555 )
544 return drm_mmap_dma(filp, vma); 556 return drm_mmap_dma(filp, vma);
545 557
546 /* A sequential search of a linked list is 558 if (drm_ht_find_item(&dev->map_hash, vma->vm_pgoff << PAGE_SHIFT, &hash)) {
547 fine here because: 1) there will only be 559 DRM_ERROR("Could not find map\n");
548 about 5-10 entries in the list and, 2) a 560 return -EINVAL;
549 DRI client only has to do this mapping
550 once, so it doesn't have to be optimized
551 for performance, even if the list was a
552 bit longer. */
553 list_for_each(list, &dev->maplist->head) {
554
555 r_list = list_entry(list, drm_map_list_t, head);
556 map = r_list->map;
557 if (!map)
558 continue;
559 if (r_list->user_token == VM_OFFSET(vma))
560 break;
561 } 561 }
562 562
563 map = drm_hash_entry(hash, drm_map_list_t, hash)->map;
563 if (!map || ((map->flags & _DRM_RESTRICTED) && !capable(CAP_SYS_ADMIN))) 564 if (!map || ((map->flags & _DRM_RESTRICTED) && !capable(CAP_SYS_ADMIN)))
564 return -EPERM; 565 return -EPERM;
565 566
@@ -620,7 +621,7 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma)
620 offset = dev->driver->get_reg_ofs(dev); 621 offset = dev->driver->get_reg_ofs(dev);
621#ifdef __sparc__ 622#ifdef __sparc__
622 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 623 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
623 if (io_remap_pfn_range(DRM_RPR_ARG(vma) vma->vm_start, 624 if (io_remap_pfn_range(vma, vma->vm_start,
624 (map->offset + offset) >> PAGE_SHIFT, 625 (map->offset + offset) >> PAGE_SHIFT,
625 vma->vm_end - vma->vm_start, 626 vma->vm_end - vma->vm_start,
626 vma->vm_page_prot)) 627 vma->vm_page_prot))
diff --git a/drivers/char/drm/i810_dma.c b/drivers/char/drm/i810_dma.c
index c658dde3633b..fa2de70f7401 100644
--- a/drivers/char/drm/i810_dma.c
+++ b/drivers/char/drm/i810_dma.c
@@ -106,7 +106,7 @@ static int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
106 unlock_kernel(); 106 unlock_kernel();
107 107
108 if (io_remap_pfn_range(vma, vma->vm_start, 108 if (io_remap_pfn_range(vma, vma->vm_start,
109 VM_OFFSET(vma) >> PAGE_SHIFT, 109 vma->vm_pgoff,
110 vma->vm_end - vma->vm_start, vma->vm_page_prot)) 110 vma->vm_end - vma->vm_start, vma->vm_page_prot))
111 return -EAGAIN; 111 return -EAGAIN;
112 return 0; 112 return 0;
@@ -141,10 +141,10 @@ static int i810_map_buffer(drm_buf_t * buf, struct file *filp)
141 MAP_SHARED, buf->bus_address); 141 MAP_SHARED, buf->bus_address);
142 dev_priv->mmap_buffer = NULL; 142 dev_priv->mmap_buffer = NULL;
143 filp->f_op = old_fops; 143 filp->f_op = old_fops;
144 if ((unsigned long)buf_priv->virtual > -1024UL) { 144 if (IS_ERR(buf_priv->virtual)) {
145 /* Real error */ 145 /* Real error */
146 DRM_ERROR("mmap error\n"); 146 DRM_ERROR("mmap error\n");
147 retcode = (signed int)buf_priv->virtual; 147 retcode = PTR_ERR(buf_priv->virtual);
148 buf_priv->virtual = NULL; 148 buf_priv->virtual = NULL;
149 } 149 }
150 up_write(&current->mm->mmap_sem); 150 up_write(&current->mm->mmap_sem);
@@ -808,7 +808,7 @@ static void i810_dma_dispatch_vertex(drm_device_t * dev,
808 ((GFX_OP_PRIMITIVE | prim | ((used / 4) - 2))); 808 ((GFX_OP_PRIMITIVE | prim | ((used / 4) - 2)));
809 809
810 if (used & 4) { 810 if (used & 4) {
811 *(u32 *) ((u32) buf_priv->kernel_virtual + used) = 0; 811 *(u32 *) ((char *) buf_priv->kernel_virtual + used) = 0;
812 used += 4; 812 used += 4;
813 } 813 }
814 814
@@ -1166,7 +1166,7 @@ static void i810_dma_dispatch_mc(drm_device_t * dev, drm_buf_t * buf, int used,
1166 1166
1167 if (buf_priv->currently_mapped == I810_BUF_MAPPED) { 1167 if (buf_priv->currently_mapped == I810_BUF_MAPPED) {
1168 if (used & 4) { 1168 if (used & 4) {
1169 *(u32 *) ((u32) buf_priv->virtual + used) = 0; 1169 *(u32 *) ((char *) buf_priv->virtual + used) = 0;
1170 used += 4; 1170 used += 4;
1171 } 1171 }
1172 1172
diff --git a/drivers/char/drm/i830_dma.c b/drivers/char/drm/i830_dma.c
index b0f815d8cea8..4f0e5746ab33 100644
--- a/drivers/char/drm/i830_dma.c
+++ b/drivers/char/drm/i830_dma.c
@@ -108,7 +108,7 @@ static int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
108 unlock_kernel(); 108 unlock_kernel();
109 109
110 if (io_remap_pfn_range(vma, vma->vm_start, 110 if (io_remap_pfn_range(vma, vma->vm_start,
111 VM_OFFSET(vma) >> PAGE_SHIFT, 111 vma->vm_pgoff,
112 vma->vm_end - vma->vm_start, vma->vm_page_prot)) 112 vma->vm_end - vma->vm_start, vma->vm_page_prot))
113 return -EAGAIN; 113 return -EAGAIN;
114 return 0; 114 return 0;
@@ -146,7 +146,7 @@ static int i830_map_buffer(drm_buf_t * buf, struct file *filp)
146 if (IS_ERR((void *)virtual)) { /* ugh */ 146 if (IS_ERR((void *)virtual)) { /* ugh */
147 /* Real error */ 147 /* Real error */
148 DRM_ERROR("mmap error\n"); 148 DRM_ERROR("mmap error\n");
149 retcode = virtual; 149 retcode = PTR_ERR((void *)virtual);
150 buf_priv->virtual = NULL; 150 buf_priv->virtual = NULL;
151 } else { 151 } else {
152 buf_priv->virtual = (void __user *)virtual; 152 buf_priv->virtual = (void __user *)virtual;
diff --git a/drivers/char/drm/i915_dma.c b/drivers/char/drm/i915_dma.c
index a94233bdbc0e..9354ce3b0093 100644
--- a/drivers/char/drm/i915_dma.c
+++ b/drivers/char/drm/i915_dma.c
@@ -31,6 +31,11 @@
31#include "i915_drm.h" 31#include "i915_drm.h"
32#include "i915_drv.h" 32#include "i915_drv.h"
33 33
34#define IS_I965G(dev) (dev->pci_device == 0x2972 || \
35 dev->pci_device == 0x2982 || \
36 dev->pci_device == 0x2992 || \
37 dev->pci_device == 0x29A2)
38
34/* Really want an OS-independent resettable timer. Would like to have 39/* Really want an OS-independent resettable timer. Would like to have
35 * this loop run for (eg) 3 sec, but have the timer reset every time 40 * this loop run for (eg) 3 sec, but have the timer reset every time
36 * the head pointer changes, so that EBUSY only happens if the ring 41 * the head pointer changes, so that EBUSY only happens if the ring
@@ -157,6 +162,7 @@ static int i915_initialize(drm_device_t * dev,
157 162
158 dev_priv->ring.virtual_start = dev_priv->ring.map.handle; 163 dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
159 164
165 dev_priv->cpp = init->cpp;
160 dev_priv->back_offset = init->back_offset; 166 dev_priv->back_offset = init->back_offset;
161 dev_priv->front_offset = init->front_offset; 167 dev_priv->front_offset = init->front_offset;
162 dev_priv->current_page = 0; 168 dev_priv->current_page = 0;
@@ -255,7 +261,7 @@ static int i915_dma_init(DRM_IOCTL_ARGS)
255 retcode = i915_dma_resume(dev); 261 retcode = i915_dma_resume(dev);
256 break; 262 break;
257 default: 263 default:
258 retcode = -EINVAL; 264 retcode = DRM_ERR(EINVAL);
259 break; 265 break;
260 } 266 }
261 267
@@ -347,7 +353,7 @@ static int i915_emit_cmds(drm_device_t * dev, int __user * buffer, int dwords)
347 if ((dwords+1) * sizeof(int) >= dev_priv->ring.Size - 8) 353 if ((dwords+1) * sizeof(int) >= dev_priv->ring.Size - 8)
348 return DRM_ERR(EINVAL); 354 return DRM_ERR(EINVAL);
349 355
350 BEGIN_LP_RING(((dwords+1)&~1)); 356 BEGIN_LP_RING((dwords+1)&~1);
351 357
352 for (i = 0; i < dwords;) { 358 for (i = 0; i < dwords;) {
353 int cmd, sz; 359 int cmd, sz;
@@ -386,7 +392,7 @@ static int i915_emit_box(drm_device_t * dev,
386 RING_LOCALS; 392 RING_LOCALS;
387 393
388 if (DRM_COPY_FROM_USER_UNCHECKED(&box, &boxes[i], sizeof(box))) { 394 if (DRM_COPY_FROM_USER_UNCHECKED(&box, &boxes[i], sizeof(box))) {
389 return EFAULT; 395 return DRM_ERR(EFAULT);
390 } 396 }
391 397
392 if (box.y2 <= box.y1 || box.x2 <= box.x1 || box.y2 <= 0 || box.x2 <= 0) { 398 if (box.y2 <= box.y1 || box.x2 <= box.x1 || box.y2 <= 0 || box.x2 <= 0) {
@@ -395,24 +401,40 @@ static int i915_emit_box(drm_device_t * dev,
395 return DRM_ERR(EINVAL); 401 return DRM_ERR(EINVAL);
396 } 402 }
397 403
398 BEGIN_LP_RING(6); 404 if (IS_I965G(dev)) {
399 OUT_RING(GFX_OP_DRAWRECT_INFO); 405 BEGIN_LP_RING(4);
400 OUT_RING(DR1); 406 OUT_RING(GFX_OP_DRAWRECT_INFO_I965);
401 OUT_RING((box.x1 & 0xffff) | (box.y1 << 16)); 407 OUT_RING((box.x1 & 0xffff) | (box.y1 << 16));
402 OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16)); 408 OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16));
403 OUT_RING(DR4); 409 OUT_RING(DR4);
404 OUT_RING(0); 410 ADVANCE_LP_RING();
405 ADVANCE_LP_RING(); 411 } else {
412 BEGIN_LP_RING(6);
413 OUT_RING(GFX_OP_DRAWRECT_INFO);
414 OUT_RING(DR1);
415 OUT_RING((box.x1 & 0xffff) | (box.y1 << 16));
416 OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16));
417 OUT_RING(DR4);
418 OUT_RING(0);
419 ADVANCE_LP_RING();
420 }
406 421
407 return 0; 422 return 0;
408} 423}
409 424
425/* XXX: Emitting the counter should really be moved to part of the IRQ
426 * emit. For now, do it in both places:
427 */
428
410static void i915_emit_breadcrumb(drm_device_t *dev) 429static void i915_emit_breadcrumb(drm_device_t *dev)
411{ 430{
412 drm_i915_private_t *dev_priv = dev->dev_private; 431 drm_i915_private_t *dev_priv = dev->dev_private;
413 RING_LOCALS; 432 RING_LOCALS;
414 433
415 dev_priv->sarea_priv->last_enqueue = dev_priv->counter++; 434 dev_priv->sarea_priv->last_enqueue = ++dev_priv->counter;
435
436 if (dev_priv->counter > 0x7FFFFFFFUL)
437 dev_priv->sarea_priv->last_enqueue = dev_priv->counter = 1;
416 438
417 BEGIN_LP_RING(4); 439 BEGIN_LP_RING(4);
418 OUT_RING(CMD_STORE_DWORD_IDX); 440 OUT_RING(CMD_STORE_DWORD_IDX);
@@ -761,6 +783,7 @@ drm_ioctl_desc_t i915_ioctls[] = {
761 [DRM_IOCTL_NR(DRM_I915_DESTROY_HEAP)] = { i915_mem_destroy_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY }, 783 [DRM_IOCTL_NR(DRM_I915_DESTROY_HEAP)] = { i915_mem_destroy_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY },
762 [DRM_IOCTL_NR(DRM_I915_SET_VBLANK_PIPE)] = { i915_vblank_pipe_set, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY }, 784 [DRM_IOCTL_NR(DRM_I915_SET_VBLANK_PIPE)] = { i915_vblank_pipe_set, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY },
763 [DRM_IOCTL_NR(DRM_I915_GET_VBLANK_PIPE)] = { i915_vblank_pipe_get, DRM_AUTH }, 785 [DRM_IOCTL_NR(DRM_I915_GET_VBLANK_PIPE)] = { i915_vblank_pipe_get, DRM_AUTH },
786 [DRM_IOCTL_NR(DRM_I915_VBLANK_SWAP)] = {i915_vblank_swap, DRM_AUTH},
764}; 787};
765 788
766int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls); 789int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
diff --git a/drivers/char/drm/i915_drm.h b/drivers/char/drm/i915_drm.h
index 5aa3e0e3bb45..96a468886a7a 100644
--- a/drivers/char/drm/i915_drm.h
+++ b/drivers/char/drm/i915_drm.h
@@ -98,6 +98,21 @@ typedef struct _drm_i915_sarea {
98 int rotated_size; 98 int rotated_size;
99 int rotated_pitch; 99 int rotated_pitch;
100 int virtualX, virtualY; 100 int virtualX, virtualY;
101
102 unsigned int front_tiled;
103 unsigned int back_tiled;
104 unsigned int depth_tiled;
105 unsigned int rotated_tiled;
106 unsigned int rotated2_tiled;
107
108 int pipeA_x;
109 int pipeA_y;
110 int pipeA_w;
111 int pipeA_h;
112 int pipeB_x;
113 int pipeB_y;
114 int pipeB_w;
115 int pipeB_h;
101} drm_i915_sarea_t; 116} drm_i915_sarea_t;
102 117
103/* Flags for perf_boxes 118/* Flags for perf_boxes
@@ -126,6 +141,7 @@ typedef struct _drm_i915_sarea {
126#define DRM_I915_DESTROY_HEAP 0x0c 141#define DRM_I915_DESTROY_HEAP 0x0c
127#define DRM_I915_SET_VBLANK_PIPE 0x0d 142#define DRM_I915_SET_VBLANK_PIPE 0x0d
128#define DRM_I915_GET_VBLANK_PIPE 0x0e 143#define DRM_I915_GET_VBLANK_PIPE 0x0e
144#define DRM_I915_VBLANK_SWAP 0x0f
129 145
130#define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t) 146#define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
131#define DRM_IOCTL_I915_FLUSH DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH) 147#define DRM_IOCTL_I915_FLUSH DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -142,6 +158,7 @@ typedef struct _drm_i915_sarea {
142#define DRM_IOCTL_I915_DESTROY_HEAP DRM_IOW( DRM_COMMAND_BASE + DRM_I915_DESTROY_HEAP, drm_i915_mem_destroy_heap_t) 158#define DRM_IOCTL_I915_DESTROY_HEAP DRM_IOW( DRM_COMMAND_BASE + DRM_I915_DESTROY_HEAP, drm_i915_mem_destroy_heap_t)
143#define DRM_IOCTL_I915_SET_VBLANK_PIPE DRM_IOW( DRM_COMMAND_BASE + DRM_I915_SET_VBLANK_PIPE, drm_i915_vblank_pipe_t) 159#define DRM_IOCTL_I915_SET_VBLANK_PIPE DRM_IOW( DRM_COMMAND_BASE + DRM_I915_SET_VBLANK_PIPE, drm_i915_vblank_pipe_t)
144#define DRM_IOCTL_I915_GET_VBLANK_PIPE DRM_IOR( DRM_COMMAND_BASE + DRM_I915_GET_VBLANK_PIPE, drm_i915_vblank_pipe_t) 160#define DRM_IOCTL_I915_GET_VBLANK_PIPE DRM_IOR( DRM_COMMAND_BASE + DRM_I915_GET_VBLANK_PIPE, drm_i915_vblank_pipe_t)
161#define DRM_IOCTL_I915_VBLANK_SWAP DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_VBLANK_SWAP, drm_i915_vblank_swap_t)
145 162
146/* Allow drivers to submit batchbuffers directly to hardware, relying 163/* Allow drivers to submit batchbuffers directly to hardware, relying
147 * on the security mechanisms provided by hardware. 164 * on the security mechanisms provided by hardware.
@@ -237,4 +254,12 @@ typedef struct drm_i915_vblank_pipe {
237 int pipe; 254 int pipe;
238} drm_i915_vblank_pipe_t; 255} drm_i915_vblank_pipe_t;
239 256
257/* Schedule buffer swap at given vertical blank:
258 */
259typedef struct drm_i915_vblank_swap {
260 drm_drawable_t drawable;
261 drm_vblank_seq_type_t seqtype;
262 unsigned int sequence;
263} drm_i915_vblank_swap_t;
264
240#endif /* _I915_DRM_H_ */ 265#endif /* _I915_DRM_H_ */
diff --git a/drivers/char/drm/i915_drv.c b/drivers/char/drm/i915_drv.c
index 8e2e6095c4b3..85bcc276f804 100644
--- a/drivers/char/drm/i915_drv.c
+++ b/drivers/char/drm/i915_drv.c
@@ -44,12 +44,14 @@ static struct drm_driver driver = {
44 */ 44 */
45 .driver_features = 45 .driver_features =
46 DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/ 46 DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/
47 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_IRQ_VBL, 47 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_IRQ_VBL |
48 DRIVER_IRQ_VBL2,
48 .load = i915_driver_load, 49 .load = i915_driver_load,
49 .lastclose = i915_driver_lastclose, 50 .lastclose = i915_driver_lastclose,
50 .preclose = i915_driver_preclose, 51 .preclose = i915_driver_preclose,
51 .device_is_agp = i915_driver_device_is_agp, 52 .device_is_agp = i915_driver_device_is_agp,
52 .vblank_wait = i915_driver_vblank_wait, 53 .vblank_wait = i915_driver_vblank_wait,
54 .vblank_wait2 = i915_driver_vblank_wait2,
53 .irq_preinstall = i915_driver_irq_preinstall, 55 .irq_preinstall = i915_driver_irq_preinstall,
54 .irq_postinstall = i915_driver_irq_postinstall, 56 .irq_postinstall = i915_driver_irq_postinstall,
55 .irq_uninstall = i915_driver_irq_uninstall, 57 .irq_uninstall = i915_driver_irq_uninstall,
diff --git a/drivers/char/drm/i915_drv.h b/drivers/char/drm/i915_drv.h
index 2d565031c002..93cdcfe6aa84 100644
--- a/drivers/char/drm/i915_drv.h
+++ b/drivers/char/drm/i915_drv.h
@@ -46,9 +46,11 @@
46 * 1.3: Add vblank support 46 * 1.3: Add vblank support
47 * 1.4: Fix cmdbuffer path, add heap destroy 47 * 1.4: Fix cmdbuffer path, add heap destroy
48 * 1.5: Add vblank pipe configuration 48 * 1.5: Add vblank pipe configuration
49 * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
50 * - Support vertical blank on secondary display pipe
49 */ 51 */
50#define DRIVER_MAJOR 1 52#define DRIVER_MAJOR 1
51#define DRIVER_MINOR 5 53#define DRIVER_MINOR 6
52#define DRIVER_PATCHLEVEL 0 54#define DRIVER_PATCHLEVEL 0
53 55
54typedef struct _drm_i915_ring_buffer { 56typedef struct _drm_i915_ring_buffer {
@@ -71,6 +73,13 @@ struct mem_block {
71 DRMFILE filp; /* 0: free, -1: heap, other: real files */ 73 DRMFILE filp; /* 0: free, -1: heap, other: real files */
72}; 74};
73 75
76typedef struct _drm_i915_vbl_swap {
77 struct list_head head;
78 drm_drawable_t drw_id;
79 unsigned int pipe;
80 unsigned int sequence;
81} drm_i915_vbl_swap_t;
82
74typedef struct drm_i915_private { 83typedef struct drm_i915_private {
75 drm_local_map_t *sarea; 84 drm_local_map_t *sarea;
76 drm_local_map_t *mmio_map; 85 drm_local_map_t *mmio_map;
@@ -83,6 +92,7 @@ typedef struct drm_i915_private {
83 dma_addr_t dma_status_page; 92 dma_addr_t dma_status_page;
84 unsigned long counter; 93 unsigned long counter;
85 94
95 unsigned int cpp;
86 int back_offset; 96 int back_offset;
87 int front_offset; 97 int front_offset;
88 int current_page; 98 int current_page;
@@ -98,6 +108,10 @@ typedef struct drm_i915_private {
98 struct mem_block *agp_heap; 108 struct mem_block *agp_heap;
99 unsigned int sr01, adpa, ppcr, dvob, dvoc, lvds; 109 unsigned int sr01, adpa, ppcr, dvob, dvoc, lvds;
100 int vblank_pipe; 110 int vblank_pipe;
111
112 spinlock_t swaps_lock;
113 drm_i915_vbl_swap_t vbl_swaps;
114 unsigned int swaps_pending;
101} drm_i915_private_t; 115} drm_i915_private_t;
102 116
103extern drm_ioctl_desc_t i915_ioctls[]; 117extern drm_ioctl_desc_t i915_ioctls[];
@@ -117,12 +131,14 @@ extern int i915_irq_emit(DRM_IOCTL_ARGS);
117extern int i915_irq_wait(DRM_IOCTL_ARGS); 131extern int i915_irq_wait(DRM_IOCTL_ARGS);
118 132
119extern int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence); 133extern int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence);
134extern int i915_driver_vblank_wait2(drm_device_t *dev, unsigned int *sequence);
120extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS); 135extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS);
121extern void i915_driver_irq_preinstall(drm_device_t * dev); 136extern void i915_driver_irq_preinstall(drm_device_t * dev);
122extern void i915_driver_irq_postinstall(drm_device_t * dev); 137extern void i915_driver_irq_postinstall(drm_device_t * dev);
123extern void i915_driver_irq_uninstall(drm_device_t * dev); 138extern void i915_driver_irq_uninstall(drm_device_t * dev);
124extern int i915_vblank_pipe_set(DRM_IOCTL_ARGS); 139extern int i915_vblank_pipe_set(DRM_IOCTL_ARGS);
125extern int i915_vblank_pipe_get(DRM_IOCTL_ARGS); 140extern int i915_vblank_pipe_get(DRM_IOCTL_ARGS);
141extern int i915_vblank_swap(DRM_IOCTL_ARGS);
126 142
127/* i915_mem.c */ 143/* i915_mem.c */
128extern int i915_mem_alloc(DRM_IOCTL_ARGS); 144extern int i915_mem_alloc(DRM_IOCTL_ARGS);
@@ -146,9 +162,9 @@ extern void i915_mem_release(drm_device_t * dev,
146#define BEGIN_LP_RING(n) do { \ 162#define BEGIN_LP_RING(n) do { \
147 if (I915_VERBOSE) \ 163 if (I915_VERBOSE) \
148 DRM_DEBUG("BEGIN_LP_RING(%d) in %s\n", \ 164 DRM_DEBUG("BEGIN_LP_RING(%d) in %s\n", \
149 n, __FUNCTION__); \ 165 (n), __FUNCTION__); \
150 if (dev_priv->ring.space < n*4) \ 166 if (dev_priv->ring.space < (n)*4) \
151 i915_wait_ring(dev, n*4, __FUNCTION__); \ 167 i915_wait_ring(dev, (n)*4, __FUNCTION__); \
152 outcount = 0; \ 168 outcount = 0; \
153 outring = dev_priv->ring.tail; \ 169 outring = dev_priv->ring.tail; \
154 ringmask = dev_priv->ring.tail_mask; \ 170 ringmask = dev_priv->ring.tail_mask; \
@@ -157,7 +173,7 @@ extern void i915_mem_release(drm_device_t * dev,
157 173
158#define OUT_RING(n) do { \ 174#define OUT_RING(n) do { \
159 if (I915_VERBOSE) DRM_DEBUG(" OUT_RING %x\n", (int)(n)); \ 175 if (I915_VERBOSE) DRM_DEBUG(" OUT_RING %x\n", (int)(n)); \
160 *(volatile unsigned int *)(virt + outring) = n; \ 176 *(volatile unsigned int *)(virt + outring) = (n); \
161 outcount++; \ 177 outcount++; \
162 outring += 4; \ 178 outring += 4; \
163 outring &= ringmask; \ 179 outring &= ringmask; \
@@ -254,6 +270,12 @@ extern int i915_wait_ring(drm_device_t * dev, int n, const char *caller);
254#define GFX_OP_DESTBUFFER_VARS ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0) 270#define GFX_OP_DESTBUFFER_VARS ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
255#define GFX_OP_DRAWRECT_INFO ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3)) 271#define GFX_OP_DRAWRECT_INFO ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
256 272
273#define GFX_OP_DRAWRECT_INFO_I965 ((0x7900<<16)|0x2)
274
275#define XY_SRC_COPY_BLT_CMD ((2<<29)|(0x53<<22)|6)
276#define XY_SRC_COPY_BLT_WRITE_ALPHA (1<<21)
277#define XY_SRC_COPY_BLT_WRITE_RGB (1<<20)
278
257#define MI_BATCH_BUFFER ((0x30<<23)|1) 279#define MI_BATCH_BUFFER ((0x30<<23)|1)
258#define MI_BATCH_BUFFER_START (0x31<<23) 280#define MI_BATCH_BUFFER_START (0x31<<23)
259#define MI_BATCH_BUFFER_END (0xA<<23) 281#define MI_BATCH_BUFFER_END (0xA<<23)
diff --git a/drivers/char/drm/i915_ioc32.c b/drivers/char/drm/i915_ioc32.c
index 296248cdc767..1fe68a251b75 100644
--- a/drivers/char/drm/i915_ioc32.c
+++ b/drivers/char/drm/i915_ioc32.c
@@ -66,7 +66,7 @@ static int compat_i915_batchbuffer(struct file *file, unsigned int cmd,
66 &batchbuffer->cliprects)) 66 &batchbuffer->cliprects))
67 return -EFAULT; 67 return -EFAULT;
68 68
69 return drm_ioctl(file->f_dentry->d_inode, file, 69 return drm_ioctl(file->f_path.dentry->d_inode, file,
70 DRM_IOCTL_I915_BATCHBUFFER, 70 DRM_IOCTL_I915_BATCHBUFFER,
71 (unsigned long)batchbuffer); 71 (unsigned long)batchbuffer);
72} 72}
@@ -102,7 +102,7 @@ static int compat_i915_cmdbuffer(struct file *file, unsigned int cmd,
102 &cmdbuffer->cliprects)) 102 &cmdbuffer->cliprects))
103 return -EFAULT; 103 return -EFAULT;
104 104
105 return drm_ioctl(file->f_dentry->d_inode, file, 105 return drm_ioctl(file->f_path.dentry->d_inode, file,
106 DRM_IOCTL_I915_CMDBUFFER, (unsigned long)cmdbuffer); 106 DRM_IOCTL_I915_CMDBUFFER, (unsigned long)cmdbuffer);
107} 107}
108 108
@@ -125,7 +125,7 @@ static int compat_i915_irq_emit(struct file *file, unsigned int cmd,
125 &request->irq_seq)) 125 &request->irq_seq))
126 return -EFAULT; 126 return -EFAULT;
127 127
128 return drm_ioctl(file->f_dentry->d_inode, file, 128 return drm_ioctl(file->f_path.dentry->d_inode, file,
129 DRM_IOCTL_I915_IRQ_EMIT, (unsigned long)request); 129 DRM_IOCTL_I915_IRQ_EMIT, (unsigned long)request);
130} 130}
131typedef struct drm_i915_getparam32 { 131typedef struct drm_i915_getparam32 {
@@ -149,7 +149,7 @@ static int compat_i915_getparam(struct file *file, unsigned int cmd,
149 &request->value)) 149 &request->value))
150 return -EFAULT; 150 return -EFAULT;
151 151
152 return drm_ioctl(file->f_dentry->d_inode, file, 152 return drm_ioctl(file->f_path.dentry->d_inode, file,
153 DRM_IOCTL_I915_GETPARAM, (unsigned long)request); 153 DRM_IOCTL_I915_GETPARAM, (unsigned long)request);
154} 154}
155 155
@@ -178,7 +178,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
178 &request->region_offset)) 178 &request->region_offset))
179 return -EFAULT; 179 return -EFAULT;
180 180
181 return drm_ioctl(file->f_dentry->d_inode, file, 181 return drm_ioctl(file->f_path.dentry->d_inode, file,
182 DRM_IOCTL_I915_ALLOC, (unsigned long)request); 182 DRM_IOCTL_I915_ALLOC, (unsigned long)request);
183} 183}
184 184
@@ -215,7 +215,7 @@ long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
215 if (fn != NULL) 215 if (fn != NULL)
216 ret = (*fn) (filp, cmd, arg); 216 ret = (*fn) (filp, cmd, arg);
217 else 217 else
218 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg); 218 ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
219 unlock_kernel(); 219 unlock_kernel();
220 220
221 return ret; 221 return ret;
diff --git a/drivers/char/drm/i915_irq.c b/drivers/char/drm/i915_irq.c
index cd96cfa430db..e5463b111fc0 100644
--- a/drivers/char/drm/i915_irq.c
+++ b/drivers/char/drm/i915_irq.c
@@ -37,6 +37,99 @@
37 37
38#define MAX_NOPID ((u32)~0) 38#define MAX_NOPID ((u32)~0)
39 39
40/**
41 * Emit blits for scheduled buffer swaps.
42 *
43 * This function will be called with the HW lock held.
44 */
45static void i915_vblank_tasklet(drm_device_t *dev)
46{
47 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
48 unsigned long irqflags;
49 struct list_head *list, *tmp;
50
51 DRM_DEBUG("\n");
52
53 spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
54
55 list_for_each_safe(list, tmp, &dev_priv->vbl_swaps.head) {
56 drm_i915_vbl_swap_t *vbl_swap =
57 list_entry(list, drm_i915_vbl_swap_t, head);
58 atomic_t *counter = vbl_swap->pipe ? &dev->vbl_received2 :
59 &dev->vbl_received;
60
61 if ((atomic_read(counter) - vbl_swap->sequence) <= (1<<23)) {
62 drm_drawable_info_t *drw;
63
64 spin_unlock(&dev_priv->swaps_lock);
65
66 spin_lock(&dev->drw_lock);
67
68 drw = drm_get_drawable_info(dev, vbl_swap->drw_id);
69
70 if (drw) {
71 int i, num_rects = drw->num_rects;
72 drm_clip_rect_t *rect = drw->rects;
73 drm_i915_sarea_t *sarea_priv =
74 dev_priv->sarea_priv;
75 u32 cpp = dev_priv->cpp;
76 u32 cmd = (cpp == 4) ? (XY_SRC_COPY_BLT_CMD |
77 XY_SRC_COPY_BLT_WRITE_ALPHA |
78 XY_SRC_COPY_BLT_WRITE_RGB)
79 : XY_SRC_COPY_BLT_CMD;
80 u32 pitchropcpp = (sarea_priv->pitch * cpp) |
81 (0xcc << 16) | (cpp << 23) |
82 (1 << 24);
83 RING_LOCALS;
84
85 i915_kernel_lost_context(dev);
86
87 BEGIN_LP_RING(6);
88
89 OUT_RING(GFX_OP_DRAWRECT_INFO);
90 OUT_RING(0);
91 OUT_RING(0);
92 OUT_RING(sarea_priv->width |
93 sarea_priv->height << 16);
94 OUT_RING(sarea_priv->width |
95 sarea_priv->height << 16);
96 OUT_RING(0);
97
98 ADVANCE_LP_RING();
99
100 sarea_priv->ctxOwner = DRM_KERNEL_CONTEXT;
101
102 for (i = 0; i < num_rects; i++, rect++) {
103 BEGIN_LP_RING(8);
104
105 OUT_RING(cmd);
106 OUT_RING(pitchropcpp);
107 OUT_RING((rect->y1 << 16) | rect->x1);
108 OUT_RING((rect->y2 << 16) | rect->x2);
109 OUT_RING(sarea_priv->front_offset);
110 OUT_RING((rect->y1 << 16) | rect->x1);
111 OUT_RING(pitchropcpp & 0xffff);
112 OUT_RING(sarea_priv->back_offset);
113
114 ADVANCE_LP_RING();
115 }
116 }
117
118 spin_unlock(&dev->drw_lock);
119
120 spin_lock(&dev_priv->swaps_lock);
121
122 list_del(list);
123
124 drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER);
125
126 dev_priv->swaps_pending--;
127 }
128 }
129
130 spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
131}
132
40irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS) 133irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
41{ 134{
42 drm_device_t *dev = (drm_device_t *) arg; 135 drm_device_t *dev = (drm_device_t *) arg;
@@ -60,9 +153,26 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
60 DRM_WAKEUP(&dev_priv->irq_queue); 153 DRM_WAKEUP(&dev_priv->irq_queue);
61 154
62 if (temp & (VSYNC_PIPEA_FLAG | VSYNC_PIPEB_FLAG)) { 155 if (temp & (VSYNC_PIPEA_FLAG | VSYNC_PIPEB_FLAG)) {
63 atomic_inc(&dev->vbl_received); 156 int vblank_pipe = dev_priv->vblank_pipe;
157
158 if ((vblank_pipe &
159 (DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B))
160 == (DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B)) {
161 if (temp & VSYNC_PIPEA_FLAG)
162 atomic_inc(&dev->vbl_received);
163 if (temp & VSYNC_PIPEB_FLAG)
164 atomic_inc(&dev->vbl_received2);
165 } else if (((temp & VSYNC_PIPEA_FLAG) &&
166 (vblank_pipe & DRM_I915_VBLANK_PIPE_A)) ||
167 ((temp & VSYNC_PIPEB_FLAG) &&
168 (vblank_pipe & DRM_I915_VBLANK_PIPE_B)))
169 atomic_inc(&dev->vbl_received);
170
64 DRM_WAKEUP(&dev->vbl_queue); 171 DRM_WAKEUP(&dev->vbl_queue);
65 drm_vbl_send_signals(dev); 172 drm_vbl_send_signals(dev);
173
174 if (dev_priv->swaps_pending > 0)
175 drm_locked_tasklet(dev, i915_vblank_tasklet);
66 } 176 }
67 177
68 return IRQ_HANDLED; 178 return IRQ_HANDLED;
@@ -71,21 +181,27 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
71static int i915_emit_irq(drm_device_t * dev) 181static int i915_emit_irq(drm_device_t * dev)
72{ 182{
73 drm_i915_private_t *dev_priv = dev->dev_private; 183 drm_i915_private_t *dev_priv = dev->dev_private;
74 u32 ret;
75 RING_LOCALS; 184 RING_LOCALS;
76 185
77 i915_kernel_lost_context(dev); 186 i915_kernel_lost_context(dev);
78 187
79 DRM_DEBUG("%s\n", __FUNCTION__); 188 DRM_DEBUG("%s\n", __FUNCTION__);
80 189
81 ret = dev_priv->counter; 190 dev_priv->sarea_priv->last_enqueue = ++dev_priv->counter;
82 191
83 BEGIN_LP_RING(2); 192 if (dev_priv->counter > 0x7FFFFFFFUL)
193 dev_priv->sarea_priv->last_enqueue = dev_priv->counter = 1;
194
195 BEGIN_LP_RING(6);
196 OUT_RING(CMD_STORE_DWORD_IDX);
197 OUT_RING(20);
198 OUT_RING(dev_priv->counter);
199 OUT_RING(0);
84 OUT_RING(0); 200 OUT_RING(0);
85 OUT_RING(GFX_OP_USER_INTERRUPT); 201 OUT_RING(GFX_OP_USER_INTERRUPT);
86 ADVANCE_LP_RING(); 202 ADVANCE_LP_RING();
87 203
88 return ret; 204 return dev_priv->counter;
89} 205}
90 206
91static int i915_wait_irq(drm_device_t * dev, int irq_nr) 207static int i915_wait_irq(drm_device_t * dev, int irq_nr)
@@ -114,7 +230,8 @@ static int i915_wait_irq(drm_device_t * dev, int irq_nr)
114 return ret; 230 return ret;
115} 231}
116 232
117int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence) 233static int i915_driver_vblank_do_wait(drm_device_t *dev, unsigned int *sequence,
234 atomic_t *counter)
118{ 235{
119 drm_i915_private_t *dev_priv = dev->dev_private; 236 drm_i915_private_t *dev_priv = dev->dev_private;
120 unsigned int cur_vblank; 237 unsigned int cur_vblank;
@@ -126,7 +243,7 @@ int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence)
126 } 243 }
127 244
128 DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ, 245 DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
129 (((cur_vblank = atomic_read(&dev->vbl_received)) 246 (((cur_vblank = atomic_read(counter))
130 - *sequence) <= (1<<23))); 247 - *sequence) <= (1<<23)));
131 248
132 *sequence = cur_vblank; 249 *sequence = cur_vblank;
@@ -135,6 +252,16 @@ int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence)
135} 252}
136 253
137 254
255int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence)
256{
257 return i915_driver_vblank_do_wait(dev, sequence, &dev->vbl_received);
258}
259
260int i915_driver_vblank_wait2(drm_device_t *dev, unsigned int *sequence)
261{
262 return i915_driver_vblank_do_wait(dev, sequence, &dev->vbl_received2);
263}
264
138/* Needs the lock as it touches the ring. 265/* Needs the lock as it touches the ring.
139 */ 266 */
140int i915_irq_emit(DRM_IOCTL_ARGS) 267int i915_irq_emit(DRM_IOCTL_ARGS)
@@ -183,7 +310,7 @@ int i915_irq_wait(DRM_IOCTL_ARGS)
183 return i915_wait_irq(dev, irqwait.irq_seq); 310 return i915_wait_irq(dev, irqwait.irq_seq);
184} 311}
185 312
186static int i915_enable_interrupt (drm_device_t *dev) 313static void i915_enable_interrupt (drm_device_t *dev)
187{ 314{
188 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 315 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
189 u16 flag; 316 u16 flag;
@@ -193,13 +320,8 @@ static int i915_enable_interrupt (drm_device_t *dev)
193 flag |= VSYNC_PIPEA_FLAG; 320 flag |= VSYNC_PIPEA_FLAG;
194 if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_B) 321 if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_B)
195 flag |= VSYNC_PIPEB_FLAG; 322 flag |= VSYNC_PIPEB_FLAG;
196 if (dev_priv->vblank_pipe & ~(DRM_I915_VBLANK_PIPE_A|DRM_I915_VBLANK_PIPE_B)) { 323
197 DRM_ERROR("%s called with invalid pipe 0x%x\n",
198 __FUNCTION__, dev_priv->vblank_pipe);
199 return DRM_ERR(EINVAL);
200 }
201 I915_WRITE16(I915REG_INT_ENABLE_R, USER_INT_FLAG | flag); 324 I915_WRITE16(I915REG_INT_ENABLE_R, USER_INT_FLAG | flag);
202 return 0;
203} 325}
204 326
205/* Set the vblank monitor pipe 327/* Set the vblank monitor pipe
@@ -218,8 +340,17 @@ int i915_vblank_pipe_set(DRM_IOCTL_ARGS)
218 DRM_COPY_FROM_USER_IOCTL(pipe, (drm_i915_vblank_pipe_t __user *) data, 340 DRM_COPY_FROM_USER_IOCTL(pipe, (drm_i915_vblank_pipe_t __user *) data,
219 sizeof(pipe)); 341 sizeof(pipe));
220 342
343 if (pipe.pipe & ~(DRM_I915_VBLANK_PIPE_A|DRM_I915_VBLANK_PIPE_B)) {
344 DRM_ERROR("%s called with invalid pipe 0x%x\n",
345 __FUNCTION__, pipe.pipe);
346 return DRM_ERR(EINVAL);
347 }
348
221 dev_priv->vblank_pipe = pipe.pipe; 349 dev_priv->vblank_pipe = pipe.pipe;
222 return i915_enable_interrupt (dev); 350
351 i915_enable_interrupt (dev);
352
353 return 0;
223} 354}
224 355
225int i915_vblank_pipe_get(DRM_IOCTL_ARGS) 356int i915_vblank_pipe_get(DRM_IOCTL_ARGS)
@@ -245,6 +376,118 @@ int i915_vblank_pipe_get(DRM_IOCTL_ARGS)
245 return 0; 376 return 0;
246} 377}
247 378
379/**
380 * Schedule buffer swap at given vertical blank.
381 */
382int i915_vblank_swap(DRM_IOCTL_ARGS)
383{
384 DRM_DEVICE;
385 drm_i915_private_t *dev_priv = dev->dev_private;
386 drm_i915_vblank_swap_t swap;
387 drm_i915_vbl_swap_t *vbl_swap;
388 unsigned int pipe, seqtype, curseq;
389 unsigned long irqflags;
390 struct list_head *list;
391
392 if (!dev_priv) {
393 DRM_ERROR("%s called with no initialization\n", __func__);
394 return DRM_ERR(EINVAL);
395 }
396
397 if (dev_priv->sarea_priv->rotation) {
398 DRM_DEBUG("Rotation not supported\n");
399 return DRM_ERR(EINVAL);
400 }
401
402 DRM_COPY_FROM_USER_IOCTL(swap, (drm_i915_vblank_swap_t __user *) data,
403 sizeof(swap));
404
405 if (swap.seqtype & ~(_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE |
406 _DRM_VBLANK_SECONDARY | _DRM_VBLANK_NEXTONMISS)) {
407 DRM_ERROR("Invalid sequence type 0x%x\n", swap.seqtype);
408 return DRM_ERR(EINVAL);
409 }
410
411 pipe = (swap.seqtype & _DRM_VBLANK_SECONDARY) ? 1 : 0;
412
413 seqtype = swap.seqtype & (_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE);
414
415 if (!(dev_priv->vblank_pipe & (1 << pipe))) {
416 DRM_ERROR("Invalid pipe %d\n", pipe);
417 return DRM_ERR(EINVAL);
418 }
419
420 spin_lock_irqsave(&dev->drw_lock, irqflags);
421
422 if (!drm_get_drawable_info(dev, swap.drawable)) {
423 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
424 DRM_ERROR("Invalid drawable ID %d\n", swap.drawable);
425 return DRM_ERR(EINVAL);
426 }
427
428 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
429
430 curseq = atomic_read(pipe ? &dev->vbl_received2 : &dev->vbl_received);
431
432 if (seqtype == _DRM_VBLANK_RELATIVE)
433 swap.sequence += curseq;
434
435 if ((curseq - swap.sequence) <= (1<<23)) {
436 if (swap.seqtype & _DRM_VBLANK_NEXTONMISS) {
437 swap.sequence = curseq + 1;
438 } else {
439 DRM_DEBUG("Missed target sequence\n");
440 return DRM_ERR(EINVAL);
441 }
442 }
443
444 spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
445
446 list_for_each(list, &dev_priv->vbl_swaps.head) {
447 vbl_swap = list_entry(list, drm_i915_vbl_swap_t, head);
448
449 if (vbl_swap->drw_id == swap.drawable &&
450 vbl_swap->pipe == pipe &&
451 vbl_swap->sequence == swap.sequence) {
452 spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
453 DRM_DEBUG("Already scheduled\n");
454 return 0;
455 }
456 }
457
458 spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
459
460 if (dev_priv->swaps_pending >= 100) {
461 DRM_DEBUG("Too many swaps queued\n");
462 return DRM_ERR(EBUSY);
463 }
464
465 vbl_swap = drm_calloc(1, sizeof(vbl_swap), DRM_MEM_DRIVER);
466
467 if (!vbl_swap) {
468 DRM_ERROR("Failed to allocate memory to queue swap\n");
469 return DRM_ERR(ENOMEM);
470 }
471
472 DRM_DEBUG("\n");
473
474 vbl_swap->drw_id = swap.drawable;
475 vbl_swap->pipe = pipe;
476 vbl_swap->sequence = swap.sequence;
477
478 spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
479
480 list_add_tail((struct list_head *)vbl_swap, &dev_priv->vbl_swaps.head);
481 dev_priv->swaps_pending++;
482
483 spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
484
485 DRM_COPY_TO_USER_IOCTL((drm_i915_vblank_swap_t __user *) data, swap,
486 sizeof(swap));
487
488 return 0;
489}
490
248/* drm_dma.h hooks 491/* drm_dma.h hooks
249*/ 492*/
250void i915_driver_irq_preinstall(drm_device_t * dev) 493void i915_driver_irq_preinstall(drm_device_t * dev)
@@ -260,6 +503,12 @@ void i915_driver_irq_postinstall(drm_device_t * dev)
260{ 503{
261 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 504 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
262 505
506 dev_priv->swaps_lock = SPIN_LOCK_UNLOCKED;
507 INIT_LIST_HEAD(&dev_priv->vbl_swaps.head);
508 dev_priv->swaps_pending = 0;
509
510 if (!dev_priv->vblank_pipe)
511 dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A;
263 i915_enable_interrupt(dev); 512 i915_enable_interrupt(dev);
264 DRM_INIT_WAITQUEUE(&dev_priv->irq_queue); 513 DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
265} 514}
diff --git a/drivers/char/drm/mga_drv.c b/drivers/char/drm/mga_drv.c
index e30f556b79f1..be49dbb9ec3f 100644
--- a/drivers/char/drm/mga_drv.c
+++ b/drivers/char/drm/mga_drv.c
@@ -47,6 +47,7 @@ static struct drm_driver driver = {
47 DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | 47 DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
48 DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | 48 DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED |
49 DRIVER_IRQ_VBL, 49 DRIVER_IRQ_VBL,
50 .dev_priv_size = sizeof(drm_mga_buf_priv_t),
50 .load = mga_driver_load, 51 .load = mga_driver_load,
51 .unload = mga_driver_unload, 52 .unload = mga_driver_unload,
52 .lastclose = mga_driver_lastclose, 53 .lastclose = mga_driver_lastclose,
diff --git a/drivers/char/drm/mga_ioc32.c b/drivers/char/drm/mga_ioc32.c
index 54a18eb2fc04..30d00478ddee 100644
--- a/drivers/char/drm/mga_ioc32.c
+++ b/drivers/char/drm/mga_ioc32.c
@@ -100,7 +100,7 @@ static int compat_mga_init(struct file *file, unsigned int cmd,
100 if (err) 100 if (err)
101 return -EFAULT; 101 return -EFAULT;
102 102
103 return drm_ioctl(file->f_dentry->d_inode, file, 103 return drm_ioctl(file->f_path.dentry->d_inode, file,
104 DRM_IOCTL_MGA_INIT, (unsigned long)init); 104 DRM_IOCTL_MGA_INIT, (unsigned long)init);
105} 105}
106 106
@@ -125,7 +125,7 @@ static int compat_mga_getparam(struct file *file, unsigned int cmd,
125 &getparam->value)) 125 &getparam->value))
126 return -EFAULT; 126 return -EFAULT;
127 127
128 return drm_ioctl(file->f_dentry->d_inode, file, 128 return drm_ioctl(file->f_path.dentry->d_inode, file,
129 DRM_IOCTL_MGA_GETPARAM, (unsigned long)getparam); 129 DRM_IOCTL_MGA_GETPARAM, (unsigned long)getparam);
130} 130}
131 131
@@ -166,7 +166,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
166 || __put_user(dma_bootstrap32.agp_size, &dma_bootstrap->agp_size)) 166 || __put_user(dma_bootstrap32.agp_size, &dma_bootstrap->agp_size))
167 return -EFAULT; 167 return -EFAULT;
168 168
169 err = drm_ioctl(file->f_dentry->d_inode, file, 169 err = drm_ioctl(file->f_path.dentry->d_inode, file,
170 DRM_IOCTL_MGA_DMA_BOOTSTRAP, 170 DRM_IOCTL_MGA_DMA_BOOTSTRAP,
171 (unsigned long)dma_bootstrap); 171 (unsigned long)dma_bootstrap);
172 if (err) 172 if (err)
@@ -224,7 +224,7 @@ long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
224 if (fn != NULL) 224 if (fn != NULL)
225 ret = (*fn) (filp, cmd, arg); 225 ret = (*fn) (filp, cmd, arg);
226 else 226 else
227 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg); 227 ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
228 unlock_kernel(); 228 unlock_kernel();
229 229
230 return ret; 230 return ret;
diff --git a/drivers/char/drm/r128_ioc32.c b/drivers/char/drm/r128_ioc32.c
index 9dd6d4116e47..d3cb676eee84 100644
--- a/drivers/char/drm/r128_ioc32.c
+++ b/drivers/char/drm/r128_ioc32.c
@@ -95,7 +95,7 @@ static int compat_r128_init(struct file *file, unsigned int cmd,
95 &init->agp_textures_offset)) 95 &init->agp_textures_offset))
96 return -EFAULT; 96 return -EFAULT;
97 97
98 return drm_ioctl(file->f_dentry->d_inode, file, 98 return drm_ioctl(file->f_path.dentry->d_inode, file,
99 DRM_IOCTL_R128_INIT, (unsigned long)init); 99 DRM_IOCTL_R128_INIT, (unsigned long)init);
100} 100}
101 101
@@ -129,7 +129,7 @@ static int compat_r128_depth(struct file *file, unsigned int cmd,
129 &depth->mask)) 129 &depth->mask))
130 return -EFAULT; 130 return -EFAULT;
131 131
132 return drm_ioctl(file->f_dentry->d_inode, file, 132 return drm_ioctl(file->f_path.dentry->d_inode, file,
133 DRM_IOCTL_R128_DEPTH, (unsigned long)depth); 133 DRM_IOCTL_R128_DEPTH, (unsigned long)depth);
134 134
135} 135}
@@ -153,7 +153,7 @@ static int compat_r128_stipple(struct file *file, unsigned int cmd,
153 &stipple->mask)) 153 &stipple->mask))
154 return -EFAULT; 154 return -EFAULT;
155 155
156 return drm_ioctl(file->f_dentry->d_inode, file, 156 return drm_ioctl(file->f_path.dentry->d_inode, file,
157 DRM_IOCTL_R128_STIPPLE, (unsigned long)stipple); 157 DRM_IOCTL_R128_STIPPLE, (unsigned long)stipple);
158} 158}
159 159
@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
178 &getparam->value)) 178 &getparam->value))
179 return -EFAULT; 179 return -EFAULT;
180 180
181 return drm_ioctl(file->f_dentry->d_inode, file, 181 return drm_ioctl(file->f_path.dentry->d_inode, file,
182 DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam); 182 DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
183} 183}
184 184
@@ -214,7 +214,7 @@ long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
214 if (fn != NULL) 214 if (fn != NULL)
215 ret = (*fn) (filp, cmd, arg); 215 ret = (*fn) (filp, cmd, arg);
216 else 216 else
217 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg); 217 ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
218 unlock_kernel(); 218 unlock_kernel();
219 219
220 return ret; 220 return ret;
diff --git a/drivers/char/drm/r300_cmdbuf.c b/drivers/char/drm/r300_cmdbuf.c
index 26bdf2ca59d7..d14477ba3679 100644
--- a/drivers/char/drm/r300_cmdbuf.c
+++ b/drivers/char/drm/r300_cmdbuf.c
@@ -538,6 +538,36 @@ static __inline__ int r300_emit_bitblt_multi(drm_radeon_private_t *dev_priv,
538 return 0; 538 return 0;
539} 539}
540 540
541static __inline__ int r300_emit_indx_buffer(drm_radeon_private_t *dev_priv,
542 drm_radeon_kcmd_buffer_t *cmdbuf)
543{
544 u32 *cmd = (u32 *) cmdbuf->buf;
545 int count, ret;
546 RING_LOCALS;
547
548 count=(cmd[0]>>16) & 0x3fff;
549
550 if ((cmd[1] & 0x8000ffff) != 0x80000810) {
551 DRM_ERROR("Invalid indx_buffer reg address %08X\n", cmd[1]);
552 return DRM_ERR(EINVAL);
553 }
554 ret = r300_check_offset(dev_priv, cmd[2]);
555 if (ret) {
556 DRM_ERROR("Invalid indx_buffer offset is %08X\n", cmd[2]);
557 return DRM_ERR(EINVAL);
558 }
559
560 BEGIN_RING(count+2);
561 OUT_RING(cmd[0]);
562 OUT_RING_TABLE((int *)(cmdbuf->buf + 4), count + 1);
563 ADVANCE_RING();
564
565 cmdbuf->buf += (count+2)*4;
566 cmdbuf->bufsz -= (count+2)*4;
567
568 return 0;
569}
570
541static __inline__ int r300_emit_raw_packet3(drm_radeon_private_t *dev_priv, 571static __inline__ int r300_emit_raw_packet3(drm_radeon_private_t *dev_priv,
542 drm_radeon_kcmd_buffer_t *cmdbuf) 572 drm_radeon_kcmd_buffer_t *cmdbuf)
543{ 573{
@@ -578,10 +608,11 @@ static __inline__ int r300_emit_raw_packet3(drm_radeon_private_t *dev_priv,
578 case RADEON_CNTL_BITBLT_MULTI: 608 case RADEON_CNTL_BITBLT_MULTI:
579 return r300_emit_bitblt_multi(dev_priv, cmdbuf); 609 return r300_emit_bitblt_multi(dev_priv, cmdbuf);
580 610
611 case RADEON_CP_INDX_BUFFER: /* DRAW_INDX_2 without INDX_BUFFER seems to lock up the gpu */
612 return r300_emit_indx_buffer(dev_priv, cmdbuf);
581 case RADEON_CP_3D_DRAW_IMMD_2: /* triggers drawing using in-packet vertex data */ 613 case RADEON_CP_3D_DRAW_IMMD_2: /* triggers drawing using in-packet vertex data */
582 case RADEON_CP_3D_DRAW_VBUF_2: /* triggers drawing of vertex buffers setup elsewhere */ 614 case RADEON_CP_3D_DRAW_VBUF_2: /* triggers drawing of vertex buffers setup elsewhere */
583 case RADEON_CP_3D_DRAW_INDX_2: /* triggers drawing using indices to vertex buffer */ 615 case RADEON_CP_3D_DRAW_INDX_2: /* triggers drawing using indices to vertex buffer */
584 case RADEON_CP_INDX_BUFFER: /* DRAW_INDX_2 without INDX_BUFFER seems to lock up the gpu */
585 case RADEON_WAIT_FOR_IDLE: 616 case RADEON_WAIT_FOR_IDLE:
586 case RADEON_CP_NOP: 617 case RADEON_CP_NOP:
587 /* these packets are safe */ 618 /* these packets are safe */
diff --git a/drivers/char/drm/radeon_cp.c b/drivers/char/drm/radeon_cp.c
index 5ad43ba7b5aa..5ed965688293 100644
--- a/drivers/char/drm/radeon_cp.c
+++ b/drivers/char/drm/radeon_cp.c
@@ -864,13 +864,13 @@ static int radeon_do_pixcache_flush(drm_radeon_private_t * dev_priv)
864 864
865 dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE; 865 dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
866 866
867 tmp = RADEON_READ(RADEON_RB2D_DSTCACHE_CTLSTAT); 867 tmp = RADEON_READ(RADEON_RB3D_DSTCACHE_CTLSTAT);
868 tmp |= RADEON_RB2D_DC_FLUSH_ALL; 868 tmp |= RADEON_RB3D_DC_FLUSH_ALL;
869 RADEON_WRITE(RADEON_RB2D_DSTCACHE_CTLSTAT, tmp); 869 RADEON_WRITE(RADEON_RB3D_DSTCACHE_CTLSTAT, tmp);
870 870
871 for (i = 0; i < dev_priv->usec_timeout; i++) { 871 for (i = 0; i < dev_priv->usec_timeout; i++) {
872 if (!(RADEON_READ(RADEON_RB2D_DSTCACHE_CTLSTAT) 872 if (!(RADEON_READ(RADEON_RB3D_DSTCACHE_CTLSTAT)
873 & RADEON_RB2D_DC_BUSY)) { 873 & RADEON_RB3D_DC_BUSY)) {
874 return 0; 874 return 0;
875 } 875 }
876 DRM_UDELAY(1); 876 DRM_UDELAY(1);
@@ -1130,7 +1130,7 @@ static void radeon_cp_init_ring_buffer(drm_device_t * dev,
1130 | (dev_priv->fb_location >> 16)); 1130 | (dev_priv->fb_location >> 16));
1131 1131
1132#if __OS_HAS_AGP 1132#if __OS_HAS_AGP
1133 if (dev_priv->flags & CHIP_IS_AGP) { 1133 if (dev_priv->flags & RADEON_IS_AGP) {
1134 RADEON_WRITE(RADEON_AGP_BASE, (unsigned int)dev->agp->base); 1134 RADEON_WRITE(RADEON_AGP_BASE, (unsigned int)dev->agp->base);
1135 RADEON_WRITE(RADEON_MC_AGP_LOCATION, 1135 RADEON_WRITE(RADEON_MC_AGP_LOCATION,
1136 (((dev_priv->gart_vm_start - 1 + 1136 (((dev_priv->gart_vm_start - 1 +
@@ -1158,7 +1158,7 @@ static void radeon_cp_init_ring_buffer(drm_device_t * dev,
1158 dev_priv->ring.tail = cur_read_ptr; 1158 dev_priv->ring.tail = cur_read_ptr;
1159 1159
1160#if __OS_HAS_AGP 1160#if __OS_HAS_AGP
1161 if (dev_priv->flags & CHIP_IS_AGP) { 1161 if (dev_priv->flags & RADEON_IS_AGP) {
1162 RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR, 1162 RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR,
1163 dev_priv->ring_rptr->offset 1163 dev_priv->ring_rptr->offset
1164 - dev->agp->base + dev_priv->gart_vm_start); 1164 - dev->agp->base + dev_priv->gart_vm_start);
@@ -1258,6 +1258,13 @@ static void radeon_test_writeback(drm_radeon_private_t * dev_priv)
1258 dev_priv->writeback_works = 0; 1258 dev_priv->writeback_works = 0;
1259 DRM_INFO("writeback forced off\n"); 1259 DRM_INFO("writeback forced off\n");
1260 } 1260 }
1261
1262 if (!dev_priv->writeback_works) {
1263 /* Disable writeback to avoid unnecessary bus master transfer */
1264 RADEON_WRITE(RADEON_CP_RB_CNTL, RADEON_READ(RADEON_CP_RB_CNTL) |
1265 RADEON_RB_NO_UPDATE);
1266 RADEON_WRITE(RADEON_SCRATCH_UMSK, 0);
1267 }
1261} 1268}
1262 1269
1263/* Enable or disable PCI-E GART on the chip */ 1270/* Enable or disable PCI-E GART on the chip */
@@ -1295,7 +1302,7 @@ static void radeon_set_pcigart(drm_radeon_private_t * dev_priv, int on)
1295{ 1302{
1296 u32 tmp; 1303 u32 tmp;
1297 1304
1298 if (dev_priv->flags & CHIP_IS_PCIE) { 1305 if (dev_priv->flags & RADEON_IS_PCIE) {
1299 radeon_set_pciegart(dev_priv, on); 1306 radeon_set_pciegart(dev_priv, on);
1300 return; 1307 return;
1301 } 1308 }
@@ -1333,20 +1340,22 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1333 DRM_DEBUG("\n"); 1340 DRM_DEBUG("\n");
1334 1341
1335 /* if we require new memory map but we don't have it fail */ 1342 /* if we require new memory map but we don't have it fail */
1336 if ((dev_priv->flags & CHIP_NEW_MEMMAP) && !dev_priv->new_memmap) 1343 if ((dev_priv->flags & RADEON_NEW_MEMMAP) && !dev_priv->new_memmap) {
1337 { 1344 DRM_ERROR("Cannot initialise DRM on this card\nThis card requires a new X.org DDX for 3D\n");
1338 DRM_ERROR("Cannot initialise DRM on this card\nThis card requires a new X.org DDX\n");
1339 radeon_do_cleanup_cp(dev); 1345 radeon_do_cleanup_cp(dev);
1340 return DRM_ERR(EINVAL); 1346 return DRM_ERR(EINVAL);
1341 } 1347 }
1342 1348
1343 if (init->is_pci && (dev_priv->flags & CHIP_IS_AGP)) 1349 if (init->is_pci && (dev_priv->flags & RADEON_IS_AGP)) {
1344 {
1345 DRM_DEBUG("Forcing AGP card to PCI mode\n"); 1350 DRM_DEBUG("Forcing AGP card to PCI mode\n");
1346 dev_priv->flags &= ~CHIP_IS_AGP; 1351 dev_priv->flags &= ~RADEON_IS_AGP;
1352 } else if (!(dev_priv->flags & (RADEON_IS_AGP | RADEON_IS_PCI | RADEON_IS_PCIE))
1353 && !init->is_pci) {
1354 DRM_DEBUG("Restoring AGP flag\n");
1355 dev_priv->flags |= RADEON_IS_AGP;
1347 } 1356 }
1348 1357
1349 if ((!(dev_priv->flags & CHIP_IS_AGP)) && !dev->sg) { 1358 if ((!(dev_priv->flags & RADEON_IS_AGP)) && !dev->sg) {
1350 DRM_ERROR("PCI GART memory not allocated!\n"); 1359 DRM_ERROR("PCI GART memory not allocated!\n");
1351 radeon_do_cleanup_cp(dev); 1360 radeon_do_cleanup_cp(dev);
1352 return DRM_ERR(EINVAL); 1361 return DRM_ERR(EINVAL);
@@ -1489,7 +1498,7 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1489 init->sarea_priv_offset); 1498 init->sarea_priv_offset);
1490 1499
1491#if __OS_HAS_AGP 1500#if __OS_HAS_AGP
1492 if (dev_priv->flags & CHIP_IS_AGP) { 1501 if (dev_priv->flags & RADEON_IS_AGP) {
1493 drm_core_ioremap(dev_priv->cp_ring, dev); 1502 drm_core_ioremap(dev_priv->cp_ring, dev);
1494 drm_core_ioremap(dev_priv->ring_rptr, dev); 1503 drm_core_ioremap(dev_priv->ring_rptr, dev);
1495 drm_core_ioremap(dev->agp_buffer_map, dev); 1504 drm_core_ioremap(dev->agp_buffer_map, dev);
@@ -1548,7 +1557,7 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1548 * align it down. 1557 * align it down.
1549 */ 1558 */
1550#if __OS_HAS_AGP 1559#if __OS_HAS_AGP
1551 if (dev_priv->flags & CHIP_IS_AGP) { 1560 if (dev_priv->flags & RADEON_IS_AGP) {
1552 base = dev->agp->base; 1561 base = dev->agp->base;
1553 /* Check if valid */ 1562 /* Check if valid */
1554 if ((base + dev_priv->gart_size) > dev_priv->fb_location && 1563 if ((base + dev_priv->gart_size) > dev_priv->fb_location &&
@@ -1578,7 +1587,7 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1578 } 1587 }
1579 1588
1580#if __OS_HAS_AGP 1589#if __OS_HAS_AGP
1581 if (dev_priv->flags & CHIP_IS_AGP) 1590 if (dev_priv->flags & RADEON_IS_AGP)
1582 dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset 1591 dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset
1583 - dev->agp->base 1592 - dev->agp->base
1584 + dev_priv->gart_vm_start); 1593 + dev_priv->gart_vm_start);
@@ -1604,7 +1613,7 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1604 dev_priv->ring.high_mark = RADEON_RING_HIGH_MARK; 1613 dev_priv->ring.high_mark = RADEON_RING_HIGH_MARK;
1605 1614
1606#if __OS_HAS_AGP 1615#if __OS_HAS_AGP
1607 if (dev_priv->flags & CHIP_IS_AGP) { 1616 if (dev_priv->flags & RADEON_IS_AGP) {
1608 /* Turn off PCI GART */ 1617 /* Turn off PCI GART */
1609 radeon_set_pcigart(dev_priv, 0); 1618 radeon_set_pcigart(dev_priv, 0);
1610 } else 1619 } else
@@ -1624,7 +1633,7 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1624 dev_priv->gart_info.mapping.handle; 1633 dev_priv->gart_info.mapping.handle;
1625 1634
1626 dev_priv->gart_info.is_pcie = 1635 dev_priv->gart_info.is_pcie =
1627 !!(dev_priv->flags & CHIP_IS_PCIE); 1636 !!(dev_priv->flags & RADEON_IS_PCIE);
1628 dev_priv->gart_info.gart_table_location = 1637 dev_priv->gart_info.gart_table_location =
1629 DRM_ATI_GART_FB; 1638 DRM_ATI_GART_FB;
1630 1639
@@ -1636,7 +1645,7 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1636 DRM_ATI_GART_MAIN; 1645 DRM_ATI_GART_MAIN;
1637 dev_priv->gart_info.addr = NULL; 1646 dev_priv->gart_info.addr = NULL;
1638 dev_priv->gart_info.bus_addr = 0; 1647 dev_priv->gart_info.bus_addr = 0;
1639 if (dev_priv->flags & CHIP_IS_PCIE) { 1648 if (dev_priv->flags & RADEON_IS_PCIE) {
1640 DRM_ERROR 1649 DRM_ERROR
1641 ("Cannot use PCI Express without GART in FB memory\n"); 1650 ("Cannot use PCI Express without GART in FB memory\n");
1642 radeon_do_cleanup_cp(dev); 1651 radeon_do_cleanup_cp(dev);
@@ -1678,7 +1687,7 @@ static int radeon_do_cleanup_cp(drm_device_t * dev)
1678 drm_irq_uninstall(dev); 1687 drm_irq_uninstall(dev);
1679 1688
1680#if __OS_HAS_AGP 1689#if __OS_HAS_AGP
1681 if (dev_priv->flags & CHIP_IS_AGP) { 1690 if (dev_priv->flags & RADEON_IS_AGP) {
1682 if (dev_priv->cp_ring != NULL) { 1691 if (dev_priv->cp_ring != NULL) {
1683 drm_core_ioremapfree(dev_priv->cp_ring, dev); 1692 drm_core_ioremapfree(dev_priv->cp_ring, dev);
1684 dev_priv->cp_ring = NULL; 1693 dev_priv->cp_ring = NULL;
@@ -1733,7 +1742,7 @@ static int radeon_do_resume_cp(drm_device_t * dev)
1733 DRM_DEBUG("Starting radeon_do_resume_cp()\n"); 1742 DRM_DEBUG("Starting radeon_do_resume_cp()\n");
1734 1743
1735#if __OS_HAS_AGP 1744#if __OS_HAS_AGP
1736 if (dev_priv->flags & CHIP_IS_AGP) { 1745 if (dev_priv->flags & RADEON_IS_AGP) {
1737 /* Turn off PCI GART */ 1746 /* Turn off PCI GART */
1738 radeon_set_pcigart(dev_priv, 0); 1747 radeon_set_pcigart(dev_priv, 0);
1739 } else 1748 } else
@@ -2177,13 +2186,15 @@ int radeon_driver_load(struct drm_device *dev, unsigned long flags)
2177 dev->dev_private = (void *)dev_priv; 2186 dev->dev_private = (void *)dev_priv;
2178 dev_priv->flags = flags; 2187 dev_priv->flags = flags;
2179 2188
2180 switch (flags & CHIP_FAMILY_MASK) { 2189 switch (flags & RADEON_FAMILY_MASK) {
2181 case CHIP_R100: 2190 case CHIP_R100:
2182 case CHIP_RV200: 2191 case CHIP_RV200:
2183 case CHIP_R200: 2192 case CHIP_R200:
2184 case CHIP_R300: 2193 case CHIP_R300:
2194 case CHIP_R350:
2185 case CHIP_R420: 2195 case CHIP_R420:
2186 dev_priv->flags |= CHIP_HAS_HIERZ; 2196 case CHIP_RV410:
2197 dev_priv->flags |= RADEON_HAS_HIERZ;
2187 break; 2198 break;
2188 default: 2199 default:
2189 /* all other chips have no hierarchical z buffer */ 2200 /* all other chips have no hierarchical z buffer */
@@ -2191,13 +2202,14 @@ int radeon_driver_load(struct drm_device *dev, unsigned long flags)
2191 } 2202 }
2192 2203
2193 if (drm_device_is_agp(dev)) 2204 if (drm_device_is_agp(dev))
2194 dev_priv->flags |= CHIP_IS_AGP; 2205 dev_priv->flags |= RADEON_IS_AGP;
2195 2206 else if (drm_device_is_pcie(dev))
2196 if (drm_device_is_pcie(dev)) 2207 dev_priv->flags |= RADEON_IS_PCIE;
2197 dev_priv->flags |= CHIP_IS_PCIE; 2208 else
2209 dev_priv->flags |= RADEON_IS_PCI;
2198 2210
2199 DRM_DEBUG("%s card detected\n", 2211 DRM_DEBUG("%s card detected\n",
2200 ((dev_priv->flags & CHIP_IS_AGP) ? "AGP" : (((dev_priv->flags & CHIP_IS_PCIE) ? "PCIE" : "PCI")))); 2212 ((dev_priv->flags & RADEON_IS_AGP) ? "AGP" : (((dev_priv->flags & RADEON_IS_PCIE) ? "PCIE" : "PCI"))));
2201 return ret; 2213 return ret;
2202} 2214}
2203 2215
diff --git a/drivers/char/drm/radeon_drv.c b/drivers/char/drm/radeon_drv.c
index eb985c2a31e9..2eb652ec6745 100644
--- a/drivers/char/drm/radeon_drv.c
+++ b/drivers/char/drm/radeon_drv.c
@@ -44,7 +44,7 @@ module_param_named(no_wb, radeon_no_wb, int, 0444);
44static int dri_library_name(struct drm_device *dev, char *buf) 44static int dri_library_name(struct drm_device *dev, char *buf)
45{ 45{
46 drm_radeon_private_t *dev_priv = dev->dev_private; 46 drm_radeon_private_t *dev_priv = dev->dev_private;
47 int family = dev_priv->flags & CHIP_FAMILY_MASK; 47 int family = dev_priv->flags & RADEON_FAMILY_MASK;
48 48
49 return snprintf(buf, PAGE_SIZE, "%s\n", 49 return snprintf(buf, PAGE_SIZE, "%s\n",
50 (family < CHIP_R200) ? "radeon" : 50 (family < CHIP_R200) ? "radeon" :
diff --git a/drivers/char/drm/radeon_drv.h b/drivers/char/drm/radeon_drv.h
index e5a256f5429c..f45cd7f147a5 100644
--- a/drivers/char/drm/radeon_drv.h
+++ b/drivers/char/drm/radeon_drv.h
@@ -133,15 +133,16 @@ enum radeon_cp_microcode_version {
133 * Chip flags 133 * Chip flags
134 */ 134 */
135enum radeon_chip_flags { 135enum radeon_chip_flags {
136 CHIP_FAMILY_MASK = 0x0000ffffUL, 136 RADEON_FAMILY_MASK = 0x0000ffffUL,
137 CHIP_FLAGS_MASK = 0xffff0000UL, 137 RADEON_FLAGS_MASK = 0xffff0000UL,
138 CHIP_IS_MOBILITY = 0x00010000UL, 138 RADEON_IS_MOBILITY = 0x00010000UL,
139 CHIP_IS_IGP = 0x00020000UL, 139 RADEON_IS_IGP = 0x00020000UL,
140 CHIP_SINGLE_CRTC = 0x00040000UL, 140 RADEON_SINGLE_CRTC = 0x00040000UL,
141 CHIP_IS_AGP = 0x00080000UL, 141 RADEON_IS_AGP = 0x00080000UL,
142 CHIP_HAS_HIERZ = 0x00100000UL, 142 RADEON_HAS_HIERZ = 0x00100000UL,
143 CHIP_IS_PCIE = 0x00200000UL, 143 RADEON_IS_PCIE = 0x00200000UL,
144 CHIP_NEW_MEMMAP = 0x00400000UL, 144 RADEON_NEW_MEMMAP = 0x00400000UL,
145 RADEON_IS_PCI = 0x00800000UL,
145}; 146};
146 147
147#define GET_RING_HEAD(dev_priv) (dev_priv->writeback_works ? \ 148#define GET_RING_HEAD(dev_priv) (dev_priv->writeback_works ? \
@@ -424,6 +425,8 @@ extern int r300_do_cp_cmdbuf(drm_device_t * dev, DRMFILE filp,
424#define RADEON_RB3D_COLOROFFSET 0x1c40 425#define RADEON_RB3D_COLOROFFSET 0x1c40
425#define RADEON_RB3D_COLORPITCH 0x1c48 426#define RADEON_RB3D_COLORPITCH 0x1c48
426 427
428#define RADEON_SRC_X_Y 0x1590
429
427#define RADEON_DP_GUI_MASTER_CNTL 0x146c 430#define RADEON_DP_GUI_MASTER_CNTL 0x146c
428# define RADEON_GMC_SRC_PITCH_OFFSET_CNTL (1 << 0) 431# define RADEON_GMC_SRC_PITCH_OFFSET_CNTL (1 << 0)
429# define RADEON_GMC_DST_PITCH_OFFSET_CNTL (1 << 1) 432# define RADEON_GMC_DST_PITCH_OFFSET_CNTL (1 << 1)
@@ -441,6 +444,7 @@ extern int r300_do_cp_cmdbuf(drm_device_t * dev, DRMFILE filp,
441# define RADEON_ROP3_S 0x00cc0000 444# define RADEON_ROP3_S 0x00cc0000
442# define RADEON_ROP3_P 0x00f00000 445# define RADEON_ROP3_P 0x00f00000
443#define RADEON_DP_WRITE_MASK 0x16cc 446#define RADEON_DP_WRITE_MASK 0x16cc
447#define RADEON_SRC_PITCH_OFFSET 0x1428
444#define RADEON_DST_PITCH_OFFSET 0x142c 448#define RADEON_DST_PITCH_OFFSET 0x142c
445#define RADEON_DST_PITCH_OFFSET_C 0x1c80 449#define RADEON_DST_PITCH_OFFSET_C 0x1c80
446# define RADEON_DST_TILE_LINEAR (0 << 30) 450# define RADEON_DST_TILE_LINEAR (0 << 30)
@@ -545,6 +549,11 @@ extern int r300_do_cp_cmdbuf(drm_device_t * dev, DRMFILE filp,
545# define RADEON_RB3D_ZC_FREE (1 << 2) 549# define RADEON_RB3D_ZC_FREE (1 << 2)
546# define RADEON_RB3D_ZC_FLUSH_ALL 0x5 550# define RADEON_RB3D_ZC_FLUSH_ALL 0x5
547# define RADEON_RB3D_ZC_BUSY (1 << 31) 551# define RADEON_RB3D_ZC_BUSY (1 << 31)
552#define RADEON_RB3D_DSTCACHE_CTLSTAT 0x325c
553# define RADEON_RB3D_DC_FLUSH (3 << 0)
554# define RADEON_RB3D_DC_FREE (3 << 2)
555# define RADEON_RB3D_DC_FLUSH_ALL 0xf
556# define RADEON_RB3D_DC_BUSY (1 << 31)
548#define RADEON_RB3D_ZSTENCILCNTL 0x1c2c 557#define RADEON_RB3D_ZSTENCILCNTL 0x1c2c
549# define RADEON_Z_TEST_MASK (7 << 4) 558# define RADEON_Z_TEST_MASK (7 << 4)
550# define RADEON_Z_TEST_ALWAYS (7 << 4) 559# define RADEON_Z_TEST_ALWAYS (7 << 4)
@@ -681,6 +690,7 @@ extern int r300_do_cp_cmdbuf(drm_device_t * dev, DRMFILE filp,
681#define RADEON_CP_RB_BASE 0x0700 690#define RADEON_CP_RB_BASE 0x0700
682#define RADEON_CP_RB_CNTL 0x0704 691#define RADEON_CP_RB_CNTL 0x0704
683# define RADEON_BUF_SWAP_32BIT (2 << 16) 692# define RADEON_BUF_SWAP_32BIT (2 << 16)
693# define RADEON_RB_NO_UPDATE (1 << 27)
684#define RADEON_CP_RB_RPTR_ADDR 0x070c 694#define RADEON_CP_RB_RPTR_ADDR 0x070c
685#define RADEON_CP_RB_RPTR 0x0710 695#define RADEON_CP_RB_RPTR 0x0710
686#define RADEON_CP_RB_WPTR 0x0714 696#define RADEON_CP_RB_WPTR 0x0714
@@ -986,13 +996,13 @@ do { \
986} while (0) 996} while (0)
987 997
988#define RADEON_FLUSH_CACHE() do { \ 998#define RADEON_FLUSH_CACHE() do { \
989 OUT_RING( CP_PACKET0( RADEON_RB2D_DSTCACHE_CTLSTAT, 0 ) ); \ 999 OUT_RING( CP_PACKET0( RADEON_RB3D_DSTCACHE_CTLSTAT, 0 ) ); \
990 OUT_RING( RADEON_RB2D_DC_FLUSH ); \ 1000 OUT_RING( RADEON_RB3D_DC_FLUSH ); \
991} while (0) 1001} while (0)
992 1002
993#define RADEON_PURGE_CACHE() do { \ 1003#define RADEON_PURGE_CACHE() do { \
994 OUT_RING( CP_PACKET0( RADEON_RB2D_DSTCACHE_CTLSTAT, 0 ) ); \ 1004 OUT_RING( CP_PACKET0( RADEON_RB3D_DSTCACHE_CTLSTAT, 0 ) ); \
995 OUT_RING( RADEON_RB2D_DC_FLUSH_ALL ); \ 1005 OUT_RING( RADEON_RB3D_DC_FLUSH_ALL ); \
996} while (0) 1006} while (0)
997 1007
998#define RADEON_FLUSH_ZCACHE() do { \ 1008#define RADEON_FLUSH_ZCACHE() do { \
diff --git a/drivers/char/drm/radeon_ioc32.c b/drivers/char/drm/radeon_ioc32.c
index 0ccfd3618ff1..1f1f9cc055a4 100644
--- a/drivers/char/drm/radeon_ioc32.c
+++ b/drivers/char/drm/radeon_ioc32.c
@@ -92,7 +92,7 @@ static int compat_radeon_cp_init(struct file *file, unsigned int cmd,
92 &init->gart_textures_offset)) 92 &init->gart_textures_offset))
93 return -EFAULT; 93 return -EFAULT;
94 94
95 return drm_ioctl(file->f_dentry->d_inode, file, 95 return drm_ioctl(file->f_path.dentry->d_inode, file,
96 DRM_IOCTL_RADEON_CP_INIT, (unsigned long)init); 96 DRM_IOCTL_RADEON_CP_INIT, (unsigned long)init);
97} 97}
98 98
@@ -125,7 +125,7 @@ static int compat_radeon_cp_clear(struct file *file, unsigned int cmd,
125 &clr->depth_boxes)) 125 &clr->depth_boxes))
126 return -EFAULT; 126 return -EFAULT;
127 127
128 return drm_ioctl(file->f_dentry->d_inode, file, 128 return drm_ioctl(file->f_path.dentry->d_inode, file,
129 DRM_IOCTL_RADEON_CLEAR, (unsigned long)clr); 129 DRM_IOCTL_RADEON_CLEAR, (unsigned long)clr);
130} 130}
131 131
@@ -149,7 +149,7 @@ static int compat_radeon_cp_stipple(struct file *file, unsigned int cmd,
149 &request->mask)) 149 &request->mask))
150 return -EFAULT; 150 return -EFAULT;
151 151
152 return drm_ioctl(file->f_dentry->d_inode, file, 152 return drm_ioctl(file->f_path.dentry->d_inode, file,
153 DRM_IOCTL_RADEON_STIPPLE, (unsigned long)request); 153 DRM_IOCTL_RADEON_STIPPLE, (unsigned long)request);
154} 154}
155 155
@@ -204,7 +204,7 @@ static int compat_radeon_cp_texture(struct file *file, unsigned int cmd,
204 &image->data)) 204 &image->data))
205 return -EFAULT; 205 return -EFAULT;
206 206
207 return drm_ioctl(file->f_dentry->d_inode, file, 207 return drm_ioctl(file->f_path.dentry->d_inode, file,
208 DRM_IOCTL_RADEON_TEXTURE, (unsigned long)request); 208 DRM_IOCTL_RADEON_TEXTURE, (unsigned long)request);
209} 209}
210 210
@@ -238,7 +238,7 @@ static int compat_radeon_cp_vertex2(struct file *file, unsigned int cmd,
238 &request->prim)) 238 &request->prim))
239 return -EFAULT; 239 return -EFAULT;
240 240
241 return drm_ioctl(file->f_dentry->d_inode, file, 241 return drm_ioctl(file->f_path.dentry->d_inode, file,
242 DRM_IOCTL_RADEON_VERTEX2, (unsigned long)request); 242 DRM_IOCTL_RADEON_VERTEX2, (unsigned long)request);
243} 243}
244 244
@@ -268,7 +268,7 @@ static int compat_radeon_cp_cmdbuf(struct file *file, unsigned int cmd,
268 &request->boxes)) 268 &request->boxes))
269 return -EFAULT; 269 return -EFAULT;
270 270
271 return drm_ioctl(file->f_dentry->d_inode, file, 271 return drm_ioctl(file->f_path.dentry->d_inode, file,
272 DRM_IOCTL_RADEON_CMDBUF, (unsigned long)request); 272 DRM_IOCTL_RADEON_CMDBUF, (unsigned long)request);
273} 273}
274 274
@@ -293,7 +293,7 @@ static int compat_radeon_cp_getparam(struct file *file, unsigned int cmd,
293 &request->value)) 293 &request->value))
294 return -EFAULT; 294 return -EFAULT;
295 295
296 return drm_ioctl(file->f_dentry->d_inode, file, 296 return drm_ioctl(file->f_path.dentry->d_inode, file,
297 DRM_IOCTL_RADEON_GETPARAM, (unsigned long)request); 297 DRM_IOCTL_RADEON_GETPARAM, (unsigned long)request);
298} 298}
299 299
@@ -322,7 +322,7 @@ static int compat_radeon_mem_alloc(struct file *file, unsigned int cmd,
322 &request->region_offset)) 322 &request->region_offset))
323 return -EFAULT; 323 return -EFAULT;
324 324
325 return drm_ioctl(file->f_dentry->d_inode, file, 325 return drm_ioctl(file->f_path.dentry->d_inode, file,
326 DRM_IOCTL_RADEON_ALLOC, (unsigned long)request); 326 DRM_IOCTL_RADEON_ALLOC, (unsigned long)request);
327} 327}
328 328
@@ -345,7 +345,7 @@ static int compat_radeon_irq_emit(struct file *file, unsigned int cmd,
345 &request->irq_seq)) 345 &request->irq_seq))
346 return -EFAULT; 346 return -EFAULT;
347 347
348 return drm_ioctl(file->f_dentry->d_inode, file, 348 return drm_ioctl(file->f_path.dentry->d_inode, file,
349 DRM_IOCTL_RADEON_IRQ_EMIT, (unsigned long)request); 349 DRM_IOCTL_RADEON_IRQ_EMIT, (unsigned long)request);
350} 350}
351 351
@@ -386,7 +386,7 @@ long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
386 if (fn != NULL) 386 if (fn != NULL)
387 ret = (*fn) (filp, cmd, arg); 387 ret = (*fn) (filp, cmd, arg);
388 else 388 else
389 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg); 389 ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
390 unlock_kernel(); 390 unlock_kernel();
391 391
392 return ret; 392 return ret;
diff --git a/drivers/char/drm/radeon_state.c b/drivers/char/drm/radeon_state.c
index 39a7f685e3fd..6e04fdd732ac 100644
--- a/drivers/char/drm/radeon_state.c
+++ b/drivers/char/drm/radeon_state.c
@@ -42,7 +42,11 @@ static __inline__ int radeon_check_and_fixup_offset(drm_radeon_private_t *
42 drm_file_t * filp_priv, 42 drm_file_t * filp_priv,
43 u32 *offset) 43 u32 *offset)
44{ 44{
45 u32 off = *offset; 45 u64 off = *offset;
46 u32 fb_start = dev_priv->fb_location;
47 u32 fb_end = fb_start + dev_priv->fb_size - 1;
48 u32 gart_start = dev_priv->gart_vm_start;
49 u32 gart_end = gart_start + dev_priv->gart_size - 1;
46 struct drm_radeon_driver_file_fields *radeon_priv; 50 struct drm_radeon_driver_file_fields *radeon_priv;
47 51
48 /* Hrm ... the story of the offset ... So this function converts 52 /* Hrm ... the story of the offset ... So this function converts
@@ -62,10 +66,8 @@ static __inline__ int radeon_check_and_fixup_offset(drm_radeon_private_t *
62 /* First, the best case, the offset already lands in either the 66 /* First, the best case, the offset already lands in either the
63 * framebuffer or the GART mapped space 67 * framebuffer or the GART mapped space
64 */ 68 */
65 if ((off >= dev_priv->fb_location && 69 if ((off >= fb_start && off <= fb_end) ||
66 off < (dev_priv->fb_location + dev_priv->fb_size)) || 70 (off >= gart_start && off <= gart_end))
67 (off >= dev_priv->gart_vm_start &&
68 off < (dev_priv->gart_vm_start + dev_priv->gart_size)))
69 return 0; 71 return 0;
70 72
71 /* Ok, that didn't happen... now check if we have a zero based 73 /* Ok, that didn't happen... now check if we have a zero based
@@ -78,16 +80,13 @@ static __inline__ int radeon_check_and_fixup_offset(drm_radeon_private_t *
78 } 80 }
79 81
80 /* Finally, assume we aimed at a GART offset if beyond the fb */ 82 /* Finally, assume we aimed at a GART offset if beyond the fb */
81 if (off > (dev_priv->fb_location + dev_priv->fb_size)) 83 if (off > fb_end)
82 off = off - (dev_priv->fb_location + dev_priv->fb_size) + 84 off = off - fb_end - 1 + gart_start;
83 dev_priv->gart_vm_start;
84 85
85 /* Now recheck and fail if out of bounds */ 86 /* Now recheck and fail if out of bounds */
86 if ((off >= dev_priv->fb_location && 87 if ((off >= fb_start && off <= fb_end) ||
87 off < (dev_priv->fb_location + dev_priv->fb_size)) || 88 (off >= gart_start && off <= gart_end)) {
88 (off >= dev_priv->gart_vm_start && 89 DRM_DEBUG("offset fixed up to 0x%x\n", (unsigned int)off);
89 off < (dev_priv->gart_vm_start + dev_priv->gart_size))) {
90 DRM_DEBUG("offset fixed up to 0x%x\n", off);
91 *offset = off; 90 *offset = off;
92 return 0; 91 return 0;
93 } 92 }
@@ -276,6 +275,8 @@ static __inline__ int radeon_check_and_fixup_packet3(drm_radeon_private_t *
276 unsigned int *cmdsz) 275 unsigned int *cmdsz)
277{ 276{
278 u32 *cmd = (u32 *) cmdbuf->buf; 277 u32 *cmd = (u32 *) cmdbuf->buf;
278 u32 offset, narrays;
279 int count, i, k;
279 280
280 *cmdsz = 2 + ((cmd[0] & RADEON_CP_PACKET_COUNT_MASK) >> 16); 281 *cmdsz = 2 + ((cmd[0] & RADEON_CP_PACKET_COUNT_MASK) >> 16);
281 282
@@ -289,10 +290,106 @@ static __inline__ int radeon_check_and_fixup_packet3(drm_radeon_private_t *
289 return DRM_ERR(EINVAL); 290 return DRM_ERR(EINVAL);
290 } 291 }
291 292
292 /* Check client state and fix it up if necessary */ 293 switch(cmd[0] & 0xff00) {
293 if (cmd[0] & 0x8000) { /* MSB of opcode: next DWORD GUI_CNTL */ 294 /* XXX Are there old drivers needing other packets? */
294 u32 offset;
295 295
296 case RADEON_3D_DRAW_IMMD:
297 case RADEON_3D_DRAW_VBUF:
298 case RADEON_3D_DRAW_INDX:
299 case RADEON_WAIT_FOR_IDLE:
300 case RADEON_CP_NOP:
301 case RADEON_3D_CLEAR_ZMASK:
302/* case RADEON_CP_NEXT_CHAR:
303 case RADEON_CP_PLY_NEXTSCAN:
304 case RADEON_CP_SET_SCISSORS: */ /* probably safe but will never need them? */
305 /* these packets are safe */
306 break;
307
308 case RADEON_CP_3D_DRAW_IMMD_2:
309 case RADEON_CP_3D_DRAW_VBUF_2:
310 case RADEON_CP_3D_DRAW_INDX_2:
311 case RADEON_3D_CLEAR_HIZ:
312 /* safe but r200 only */
313 if (dev_priv->microcode_version != UCODE_R200) {
314 DRM_ERROR("Invalid 3d packet for r100-class chip\n");
315 return DRM_ERR(EINVAL);
316 }
317 break;
318
319 case RADEON_3D_LOAD_VBPNTR:
320 count = (cmd[0] >> 16) & 0x3fff;
321
322 if (count > 18) { /* 12 arrays max */
323 DRM_ERROR("Too large payload in 3D_LOAD_VBPNTR (count=%d)\n",
324 count);
325 return DRM_ERR(EINVAL);
326 }
327
328 /* carefully check packet contents */
329 narrays = cmd[1] & ~0xc000;
330 k = 0;
331 i = 2;
332 while ((k < narrays) && (i < (count + 2))) {
333 i++; /* skip attribute field */
334 if (radeon_check_and_fixup_offset(dev_priv, filp_priv, &cmd[i])) {
335 DRM_ERROR
336 ("Invalid offset (k=%d i=%d) in 3D_LOAD_VBPNTR packet.\n",
337 k, i);
338 return DRM_ERR(EINVAL);
339 }
340 k++;
341 i++;
342 if (k == narrays)
343 break;
344 /* have one more to process, they come in pairs */
345 if (radeon_check_and_fixup_offset(dev_priv, filp_priv, &cmd[i])) {
346 DRM_ERROR
347 ("Invalid offset (k=%d i=%d) in 3D_LOAD_VBPNTR packet.\n",
348 k, i);
349 return DRM_ERR(EINVAL);
350 }
351 k++;
352 i++;
353 }
354 /* do the counts match what we expect ? */
355 if ((k != narrays) || (i != (count + 2))) {
356 DRM_ERROR
357 ("Malformed 3D_LOAD_VBPNTR packet (k=%d i=%d narrays=%d count+1=%d).\n",
358 k, i, narrays, count + 1);
359 return DRM_ERR(EINVAL);
360 }
361 break;
362
363 case RADEON_3D_RNDR_GEN_INDX_PRIM:
364 if (dev_priv->microcode_version != UCODE_R100) {
365 DRM_ERROR("Invalid 3d packet for r200-class chip\n");
366 return DRM_ERR(EINVAL);
367 }
368 if (radeon_check_and_fixup_offset(dev_priv, filp_priv, &cmd[1])) {
369 DRM_ERROR("Invalid rndr_gen_indx offset\n");
370 return DRM_ERR(EINVAL);
371 }
372 break;
373
374 case RADEON_CP_INDX_BUFFER:
375 if (dev_priv->microcode_version != UCODE_R200) {
376 DRM_ERROR("Invalid 3d packet for r100-class chip\n");
377 return DRM_ERR(EINVAL);
378 }
379 if ((cmd[1] & 0x8000ffff) != 0x80000810) {
380 DRM_ERROR("Invalid indx_buffer reg address %08X\n", cmd[1]);
381 return DRM_ERR(EINVAL);
382 }
383 if (radeon_check_and_fixup_offset(dev_priv, filp_priv, &cmd[2])) {
384 DRM_ERROR("Invalid indx_buffer offset is %08X\n", cmd[2]);
385 return DRM_ERR(EINVAL);
386 }
387 break;
388
389 case RADEON_CNTL_HOSTDATA_BLT:
390 case RADEON_CNTL_PAINT_MULTI:
391 case RADEON_CNTL_BITBLT_MULTI:
392 /* MSB of opcode: next DWORD GUI_CNTL */
296 if (cmd[1] & (RADEON_GMC_SRC_PITCH_OFFSET_CNTL 393 if (cmd[1] & (RADEON_GMC_SRC_PITCH_OFFSET_CNTL
297 | RADEON_GMC_DST_PITCH_OFFSET_CNTL)) { 394 | RADEON_GMC_DST_PITCH_OFFSET_CNTL)) {
298 offset = cmd[2] << 10; 395 offset = cmd[2] << 10;
@@ -314,6 +411,11 @@ static __inline__ int radeon_check_and_fixup_packet3(drm_radeon_private_t *
314 } 411 }
315 cmd[3] = (cmd[3] & 0xffc00000) | offset >> 10; 412 cmd[3] = (cmd[3] & 0xffc00000) | offset >> 10;
316 } 413 }
414 break;
415
416 default:
417 DRM_ERROR("Invalid packet type %x\n", cmd[0] & 0xff00);
418 return DRM_ERR(EINVAL);
317 } 419 }
318 420
319 return 0; 421 return 0;
@@ -869,7 +971,7 @@ static void radeon_cp_dispatch_clear(drm_device_t * dev,
869 */ 971 */
870 dev_priv->sarea_priv->ctx_owner = 0; 972 dev_priv->sarea_priv->ctx_owner = 0;
871 973
872 if ((dev_priv->flags & CHIP_HAS_HIERZ) 974 if ((dev_priv->flags & RADEON_HAS_HIERZ)
873 && (flags & RADEON_USE_HIERZ)) { 975 && (flags & RADEON_USE_HIERZ)) {
874 /* FIXME : reverse engineer that for Rx00 cards */ 976 /* FIXME : reverse engineer that for Rx00 cards */
875 /* FIXME : the mask supposedly contains low-res z values. So can't set 977 /* FIXME : the mask supposedly contains low-res z values. So can't set
@@ -914,7 +1016,7 @@ static void radeon_cp_dispatch_clear(drm_device_t * dev,
914 for (i = 0; i < nbox; i++) { 1016 for (i = 0; i < nbox; i++) {
915 int tileoffset, nrtilesx, nrtilesy, j; 1017 int tileoffset, nrtilesx, nrtilesy, j;
916 /* it looks like r200 needs rv-style clears, at least if hierz is not enabled? */ 1018 /* it looks like r200 needs rv-style clears, at least if hierz is not enabled? */
917 if ((dev_priv->flags & CHIP_HAS_HIERZ) 1019 if ((dev_priv->flags & RADEON_HAS_HIERZ)
918 && !(dev_priv->microcode_version == UCODE_R200)) { 1020 && !(dev_priv->microcode_version == UCODE_R200)) {
919 /* FIXME : figure this out for r200 (when hierz is enabled). Or 1021 /* FIXME : figure this out for r200 (when hierz is enabled). Or
920 maybe r200 actually doesn't need to put the low-res z value into 1022 maybe r200 actually doesn't need to put the low-res z value into
@@ -998,7 +1100,7 @@ static void radeon_cp_dispatch_clear(drm_device_t * dev,
998 } 1100 }
999 1101
1000 /* TODO don't always clear all hi-level z tiles */ 1102 /* TODO don't always clear all hi-level z tiles */
1001 if ((dev_priv->flags & CHIP_HAS_HIERZ) 1103 if ((dev_priv->flags & RADEON_HAS_HIERZ)
1002 && (dev_priv->microcode_version == UCODE_R200) 1104 && (dev_priv->microcode_version == UCODE_R200)
1003 && (flags & RADEON_USE_HIERZ)) 1105 && (flags & RADEON_USE_HIERZ))
1004 /* r100 and cards without hierarchical z-buffer have no high-level z-buffer */ 1106 /* r100 and cards without hierarchical z-buffer have no high-level z-buffer */
@@ -1270,9 +1372,9 @@ static void radeon_cp_dispatch_swap(drm_device_t * dev)
1270 1372
1271 DRM_DEBUG("dispatch swap %d,%d-%d,%d\n", x, y, w, h); 1373 DRM_DEBUG("dispatch swap %d,%d-%d,%d\n", x, y, w, h);
1272 1374
1273 BEGIN_RING(7); 1375 BEGIN_RING(9);
1274 1376
1275 OUT_RING(CP_PACKET3(RADEON_CNTL_BITBLT_MULTI, 5)); 1377 OUT_RING(CP_PACKET0(RADEON_DP_GUI_MASTER_CNTL, 0));
1276 OUT_RING(RADEON_GMC_SRC_PITCH_OFFSET_CNTL | 1378 OUT_RING(RADEON_GMC_SRC_PITCH_OFFSET_CNTL |
1277 RADEON_GMC_DST_PITCH_OFFSET_CNTL | 1379 RADEON_GMC_DST_PITCH_OFFSET_CNTL |
1278 RADEON_GMC_BRUSH_NONE | 1380 RADEON_GMC_BRUSH_NONE |
@@ -1284,6 +1386,7 @@ static void radeon_cp_dispatch_swap(drm_device_t * dev)
1284 1386
1285 /* Make this work even if front & back are flipped: 1387 /* Make this work even if front & back are flipped:
1286 */ 1388 */
1389 OUT_RING(CP_PACKET0(RADEON_SRC_PITCH_OFFSET, 1));
1287 if (dev_priv->current_page == 0) { 1390 if (dev_priv->current_page == 0) {
1288 OUT_RING(dev_priv->back_pitch_offset); 1391 OUT_RING(dev_priv->back_pitch_offset);
1289 OUT_RING(dev_priv->front_pitch_offset); 1392 OUT_RING(dev_priv->front_pitch_offset);
@@ -1292,6 +1395,7 @@ static void radeon_cp_dispatch_swap(drm_device_t * dev)
1292 OUT_RING(dev_priv->back_pitch_offset); 1395 OUT_RING(dev_priv->back_pitch_offset);
1293 } 1396 }
1294 1397
1398 OUT_RING(CP_PACKET0(RADEON_SRC_X_Y, 2));
1295 OUT_RING((x << 16) | y); 1399 OUT_RING((x << 16) | y);
1296 OUT_RING((x << 16) | y); 1400 OUT_RING((x << 16) | y);
1297 OUT_RING((w << 16) | h); 1401 OUT_RING((w << 16) | h);
@@ -2987,16 +3091,21 @@ static int radeon_cp_getparam(DRM_IOCTL_ARGS)
2987 case RADEON_PARAM_GART_TEX_HANDLE: 3091 case RADEON_PARAM_GART_TEX_HANDLE:
2988 value = dev_priv->gart_textures_offset; 3092 value = dev_priv->gart_textures_offset;
2989 break; 3093 break;
2990 3094 case RADEON_PARAM_SCRATCH_OFFSET:
3095 if (!dev_priv->writeback_works)
3096 return DRM_ERR(EINVAL);
3097 value = RADEON_SCRATCH_REG_OFFSET;
3098 break;
2991 case RADEON_PARAM_CARD_TYPE: 3099 case RADEON_PARAM_CARD_TYPE:
2992 if (dev_priv->flags & CHIP_IS_PCIE) 3100 if (dev_priv->flags & RADEON_IS_PCIE)
2993 value = RADEON_CARD_PCIE; 3101 value = RADEON_CARD_PCIE;
2994 else if (dev_priv->flags & CHIP_IS_AGP) 3102 else if (dev_priv->flags & RADEON_IS_AGP)
2995 value = RADEON_CARD_AGP; 3103 value = RADEON_CARD_AGP;
2996 else 3104 else
2997 value = RADEON_CARD_PCI; 3105 value = RADEON_CARD_PCI;
2998 break; 3106 break;
2999 default: 3107 default:
3108 DRM_DEBUG("Invalid parameter %d\n", param.param);
3000 return DRM_ERR(EINVAL); 3109 return DRM_ERR(EINVAL);
3001 } 3110 }
3002 3111
diff --git a/drivers/char/drm/savage_bci.c b/drivers/char/drm/savage_bci.c
index 59c7520bf9a2..a9a84f88df5e 100644
--- a/drivers/char/drm/savage_bci.c
+++ b/drivers/char/drm/savage_bci.c
@@ -728,6 +728,7 @@ static int savage_do_init_bci(drm_device_t * dev, drm_savage_init_t * init)
728 dev_priv->status = NULL; 728 dev_priv->status = NULL;
729 } 729 }
730 if (dev_priv->dma_type == SAVAGE_DMA_AGP && init->buffers_offset) { 730 if (dev_priv->dma_type == SAVAGE_DMA_AGP && init->buffers_offset) {
731 dev->agp_buffer_token = init->buffers_offset;
731 dev->agp_buffer_map = drm_core_findmap(dev, 732 dev->agp_buffer_map = drm_core_findmap(dev,
732 init->buffers_offset); 733 init->buffers_offset);
733 if (!dev->agp_buffer_map) { 734 if (!dev->agp_buffer_map) {
diff --git a/drivers/char/drm/savage_state.c b/drivers/char/drm/savage_state.c
index ef2581d16146..1ca1e9cb5a33 100644
--- a/drivers/char/drm/savage_state.c
+++ b/drivers/char/drm/savage_state.c
@@ -994,7 +994,7 @@ int savage_bci_cmdbuf(DRM_IOCTL_ARGS)
994 if (cmdbuf.size) { 994 if (cmdbuf.size) {
995 kcmd_addr = drm_alloc(cmdbuf.size * 8, DRM_MEM_DRIVER); 995 kcmd_addr = drm_alloc(cmdbuf.size * 8, DRM_MEM_DRIVER);
996 if (kcmd_addr == NULL) 996 if (kcmd_addr == NULL)
997 return ENOMEM; 997 return DRM_ERR(ENOMEM);
998 998
999 if (DRM_COPY_FROM_USER(kcmd_addr, cmdbuf.cmd_addr, 999 if (DRM_COPY_FROM_USER(kcmd_addr, cmdbuf.cmd_addr,
1000 cmdbuf.size * 8)) 1000 cmdbuf.size * 8))
diff --git a/drivers/char/drm/sis_drv.c b/drivers/char/drm/sis_drv.c
index 5e9dc86f2956..3d5b3218b6ff 100644
--- a/drivers/char/drm/sis_drv.c
+++ b/drivers/char/drm/sis_drv.c
@@ -35,11 +35,44 @@ static struct pci_device_id pciidlist[] = {
35 sisdrv_PCI_IDS 35 sisdrv_PCI_IDS
36}; 36};
37 37
38static int sis_driver_load(drm_device_t *dev, unsigned long chipset)
39{
40 drm_sis_private_t *dev_priv;
41 int ret;
42
43 dev_priv = drm_calloc(1, sizeof(drm_sis_private_t), DRM_MEM_DRIVER);
44 if (dev_priv == NULL)
45 return DRM_ERR(ENOMEM);
46
47 dev->dev_private = (void *)dev_priv;
48 dev_priv->chipset = chipset;
49 ret = drm_sman_init(&dev_priv->sman, 2, 12, 8);
50 if (ret) {
51 drm_free(dev_priv, sizeof(dev_priv), DRM_MEM_DRIVER);
52 }
53
54 return ret;
55}
56
57static int sis_driver_unload(drm_device_t *dev)
58{
59 drm_sis_private_t *dev_priv = dev->dev_private;
60
61 drm_sman_takedown(&dev_priv->sman);
62 drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER);
63
64 return 0;
65}
66
38static struct drm_driver driver = { 67static struct drm_driver driver = {
39 .driver_features = DRIVER_USE_AGP | DRIVER_USE_MTRR, 68 .driver_features = DRIVER_USE_AGP | DRIVER_USE_MTRR,
40 .context_ctor = sis_init_context, 69 .load = sis_driver_load,
41 .context_dtor = sis_final_context, 70 .unload = sis_driver_unload,
42 .reclaim_buffers = drm_core_reclaim_buffers, 71 .context_dtor = NULL,
72 .dma_quiescent = sis_idle,
73 .reclaim_buffers = NULL,
74 .reclaim_buffers_locked = sis_reclaim_buffers_locked,
75 .lastclose = sis_lastclose,
43 .get_map_ofs = drm_core_get_map_ofs, 76 .get_map_ofs = drm_core_get_map_ofs,
44 .get_reg_ofs = drm_core_get_reg_ofs, 77 .get_reg_ofs = drm_core_get_reg_ofs,
45 .ioctls = sis_ioctls, 78 .ioctls = sis_ioctls,
diff --git a/drivers/char/drm/sis_drv.h b/drivers/char/drm/sis_drv.h
index e218e5269503..2b8d6f6ed7c0 100644
--- a/drivers/char/drm/sis_drv.h
+++ b/drivers/char/drm/sis_drv.h
@@ -31,23 +31,39 @@
31/* General customization: 31/* General customization:
32 */ 32 */
33 33
34#define DRIVER_AUTHOR "SIS" 34#define DRIVER_AUTHOR "SIS, Tungsten Graphics"
35#define DRIVER_NAME "sis" 35#define DRIVER_NAME "sis"
36#define DRIVER_DESC "SIS 300/630/540" 36#define DRIVER_DESC "SIS 300/630/540"
37#define DRIVER_DATE "20030826" 37#define DRIVER_DATE "20060704"
38#define DRIVER_MAJOR 1 38#define DRIVER_MAJOR 1
39#define DRIVER_MINOR 1 39#define DRIVER_MINOR 2
40#define DRIVER_PATCHLEVEL 0 40#define DRIVER_PATCHLEVEL 1
41 41
42#include "sis_ds.h" 42enum sis_family {
43 SIS_OTHER = 0,
44 SIS_CHIP_315 = 1,
45};
46
47#include "drm_sman.h"
48
49#define SIS_BASE (dev_priv->mmio)
50#define SIS_READ(reg) DRM_READ32(SIS_BASE, reg);
51#define SIS_WRITE(reg, val) DRM_WRITE32(SIS_BASE, reg, val);
43 52
44typedef struct drm_sis_private { 53typedef struct drm_sis_private {
45 memHeap_t *AGPHeap; 54 drm_local_map_t *mmio;
46 memHeap_t *FBHeap; 55 unsigned int idle_fault;
56 drm_sman_t sman;
57 unsigned int chipset;
58 int vram_initialized;
59 int agp_initialized;
60 unsigned long vram_offset;
61 unsigned long agp_offset;
47} drm_sis_private_t; 62} drm_sis_private_t;
48 63
49extern int sis_init_context(drm_device_t * dev, int context); 64extern int sis_idle(drm_device_t *dev);
50extern int sis_final_context(drm_device_t * dev, int context); 65extern void sis_reclaim_buffers_locked(drm_device_t *dev, struct file *filp);
66extern void sis_lastclose(drm_device_t *dev);
51 67
52extern drm_ioctl_desc_t sis_ioctls[]; 68extern drm_ioctl_desc_t sis_ioctls[];
53extern int sis_max_ioctl; 69extern int sis_max_ioctl;
diff --git a/drivers/char/drm/sis_ds.c b/drivers/char/drm/sis_ds.c
deleted file mode 100644
index 2e485d482943..000000000000
--- a/drivers/char/drm/sis_ds.c
+++ /dev/null
@@ -1,299 +0,0 @@
1/* sis_ds.c -- Private header for Direct Rendering Manager -*- linux-c -*-
2 * Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw
3 *
4 * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
5 * All rights reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 *
26 * Authors:
27 * Sung-Ching Lin <sclin@sis.com.tw>
28 *
29 */
30
31#include "drmP.h"
32#include "drm.h"
33#include "sis_ds.h"
34
35/* Set Data Structure, not check repeated value
36 * temporarily used
37 */
38
39set_t *setInit(void)
40{
41 int i;
42 set_t *set;
43
44 set = (set_t *) drm_alloc(sizeof(set_t), DRM_MEM_DRIVER);
45 if (set != NULL) {
46 for (i = 0; i < SET_SIZE; i++) {
47 set->list[i].free_next = i + 1;
48 set->list[i].alloc_next = -1;
49 }
50 set->list[SET_SIZE - 1].free_next = -1;
51 set->free = 0;
52 set->alloc = -1;
53 set->trace = -1;
54 }
55 return set;
56}
57
58int setAdd(set_t * set, ITEM_TYPE item)
59{
60 int free = set->free;
61
62 if (free != -1) {
63 set->list[free].val = item;
64 set->free = set->list[free].free_next;
65 } else {
66 return 0;
67 }
68
69 set->list[free].alloc_next = set->alloc;
70 set->alloc = free;
71 set->list[free].free_next = -1;
72
73 return 1;
74}
75
76int setDel(set_t * set, ITEM_TYPE item)
77{
78 int alloc = set->alloc;
79 int prev = -1;
80
81 while (alloc != -1) {
82 if (set->list[alloc].val == item) {
83 if (prev != -1)
84 set->list[prev].alloc_next =
85 set->list[alloc].alloc_next;
86 else
87 set->alloc = set->list[alloc].alloc_next;
88 break;
89 }
90 prev = alloc;
91 alloc = set->list[alloc].alloc_next;
92 }
93
94 if (alloc == -1)
95 return 0;
96
97 set->list[alloc].free_next = set->free;
98 set->free = alloc;
99 set->list[alloc].alloc_next = -1;
100
101 return 1;
102}
103
104/* setFirst -> setAdd -> setNext is wrong */
105
106int setFirst(set_t * set, ITEM_TYPE * item)
107{
108 if (set->alloc == -1)
109 return 0;
110
111 *item = set->list[set->alloc].val;
112 set->trace = set->list[set->alloc].alloc_next;
113
114 return 1;
115}
116
117int setNext(set_t * set, ITEM_TYPE * item)
118{
119 if (set->trace == -1)
120 return 0;
121
122 *item = set->list[set->trace].val;
123 set->trace = set->list[set->trace].alloc_next;
124
125 return 1;
126}
127
128int setDestroy(set_t * set)
129{
130 drm_free(set, sizeof(set_t), DRM_MEM_DRIVER);
131
132 return 1;
133}
134
135/*
136 * GLX Hardware Device Driver common code
137 * Copyright (C) 1999 Wittawat Yamwong
138 *
139 * Permission is hereby granted, free of charge, to any person obtaining a
140 * copy of this software and associated documentation files (the "Software"),
141 * to deal in the Software without restriction, including without limitation
142 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
143 * and/or sell copies of the Software, and to permit persons to whom the
144 * Software is furnished to do so, subject to the following conditions:
145 *
146 * The above copyright notice and this permission notice shall be included
147 * in all copies or substantial portions of the Software.
148 *
149 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
150 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
151 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
152 * WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
153 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
154 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
155 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
156 *
157 */
158
159#define ISFREE(bptr) ((bptr)->free)
160
161memHeap_t *mmInit(int ofs, int size)
162{
163 PMemBlock blocks;
164
165 if (size <= 0)
166 return NULL;
167
168 blocks = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock), DRM_MEM_DRIVER);
169 if (blocks != NULL) {
170 blocks->ofs = ofs;
171 blocks->size = size;
172 blocks->free = 1;
173 return (memHeap_t *) blocks;
174 } else
175 return NULL;
176}
177
178/* Checks if a pointer 'b' is part of the heap 'heap' */
179int mmBlockInHeap(memHeap_t * heap, PMemBlock b)
180{
181 TMemBlock *p;
182
183 if (heap == NULL || b == NULL)
184 return 0;
185
186 p = heap;
187 while (p != NULL && p != b) {
188 p = p->next;
189 }
190 if (p == b)
191 return 1;
192 else
193 return 0;
194}
195
196static TMemBlock *SliceBlock(TMemBlock * p,
197 int startofs, int size,
198 int reserved, int alignment)
199{
200 TMemBlock *newblock;
201
202 /* break left */
203 if (startofs > p->ofs) {
204 newblock = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock),
205 DRM_MEM_DRIVER);
206 newblock->ofs = startofs;
207 newblock->size = p->size - (startofs - p->ofs);
208 newblock->free = 1;
209 newblock->next = p->next;
210 p->size -= newblock->size;
211 p->next = newblock;
212 p = newblock;
213 }
214
215 /* break right */
216 if (size < p->size) {
217 newblock = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock),
218 DRM_MEM_DRIVER);
219 newblock->ofs = startofs + size;
220 newblock->size = p->size - size;
221 newblock->free = 1;
222 newblock->next = p->next;
223 p->size = size;
224 p->next = newblock;
225 }
226
227 /* p = middle block */
228 p->align = alignment;
229 p->free = 0;
230 p->reserved = reserved;
231 return p;
232}
233
234PMemBlock mmAllocMem(memHeap_t * heap, int size, int align2, int startSearch)
235{
236 int mask, startofs, endofs;
237 TMemBlock *p;
238
239 if (heap == NULL || align2 < 0 || size <= 0)
240 return NULL;
241
242 mask = (1 << align2) - 1;
243 startofs = 0;
244 p = (TMemBlock *) heap;
245 while (p != NULL) {
246 if (ISFREE(p)) {
247 startofs = (p->ofs + mask) & ~mask;
248 if (startofs < startSearch) {
249 startofs = startSearch;
250 }
251 endofs = startofs + size;
252 if (endofs <= (p->ofs + p->size))
253 break;
254 }
255 p = p->next;
256 }
257 if (p == NULL)
258 return NULL;
259 p = SliceBlock(p, startofs, size, 0, mask + 1);
260 p->heap = heap;
261 return p;
262}
263
264static __inline__ int Join2Blocks(TMemBlock * p)
265{
266 if (p->free && p->next && p->next->free) {
267 TMemBlock *q = p->next;
268 p->size += q->size;
269 p->next = q->next;
270 drm_free(q, sizeof(TMemBlock), DRM_MEM_DRIVER);
271 return 1;
272 }
273 return 0;
274}
275
276int mmFreeMem(PMemBlock b)
277{
278 TMemBlock *p, *prev;
279
280 if (b == NULL)
281 return 0;
282 if (b->heap == NULL)
283 return -1;
284
285 p = b->heap;
286 prev = NULL;
287 while (p != NULL && p != b) {
288 prev = p;
289 p = p->next;
290 }
291 if (p == NULL || p->free || p->reserved)
292 return -1;
293
294 p->free = 1;
295 Join2Blocks(p);
296 if (prev)
297 Join2Blocks(prev);
298 return 0;
299}
diff --git a/drivers/char/drm/sis_ds.h b/drivers/char/drm/sis_ds.h
deleted file mode 100644
index 94f2b4728b63..000000000000
--- a/drivers/char/drm/sis_ds.h
+++ /dev/null
@@ -1,146 +0,0 @@
1/* sis_ds.h -- Private header for Direct Rendering Manager -*- linux-c -*-
2 * Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw
3 */
4/*
5 * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
6 * All rights reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 * Authors:
28 * Sung-Ching Lin <sclin@sis.com.tw>
29 *
30 */
31
32#ifndef __SIS_DS_H__
33#define __SIS_DS_H__
34
35/* Set Data Structure */
36
37#define SET_SIZE 5000
38
39typedef unsigned long ITEM_TYPE;
40
41typedef struct {
42 ITEM_TYPE val;
43 int alloc_next, free_next;
44} list_item_t;
45
46typedef struct {
47 int alloc;
48 int free;
49 int trace;
50 list_item_t list[SET_SIZE];
51} set_t;
52
53set_t *setInit(void);
54int setAdd(set_t * set, ITEM_TYPE item);
55int setDel(set_t * set, ITEM_TYPE item);
56int setFirst(set_t * set, ITEM_TYPE * item);
57int setNext(set_t * set, ITEM_TYPE * item);
58int setDestroy(set_t * set);
59
60/*
61 * GLX Hardware Device Driver common code
62 * Copyright (C) 1999 Wittawat Yamwong
63 *
64 * Permission is hereby granted, free of charge, to any person obtaining a
65 * copy of this software and associated documentation files (the "Software"),
66 * to deal in the Software without restriction, including without limitation
67 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
68 * and/or sell copies of the Software, and to permit persons to whom the
69 * Software is furnished to do so, subject to the following conditions:
70 *
71 * The above copyright notice and this permission notice shall be included
72 * in all copies or substantial portions of the Software.
73 *
74 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
75 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
76 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
77 * WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
78 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
79 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
80 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
81 *
82 */
83
84struct mem_block_t {
85 struct mem_block_t *next;
86 struct mem_block_t *heap;
87 int ofs, size;
88 int align;
89 unsigned int free:1;
90 unsigned int reserved:1;
91};
92typedef struct mem_block_t TMemBlock;
93typedef struct mem_block_t *PMemBlock;
94
95/* a heap is just the first block in a chain */
96typedef struct mem_block_t memHeap_t;
97
98static __inline__ int mmBlockSize(PMemBlock b)
99{
100 return b->size;
101}
102
103static __inline__ int mmOffset(PMemBlock b)
104{
105 return b->ofs;
106}
107
108static __inline__ void mmMarkReserved(PMemBlock b)
109{
110 b->reserved = 1;
111}
112
113/*
114 * input: total size in bytes
115 * return: a heap pointer if OK, NULL if error
116 */
117memHeap_t *mmInit(int ofs, int size);
118
119/*
120 * Allocate 'size' bytes with 2^align2 bytes alignment,
121 * restrict the search to free memory after 'startSearch'
122 * depth and back buffers should be in different 4mb banks
123 * to get better page hits if possible
124 * input: size = size of block
125 * align2 = 2^align2 bytes alignment
126 * startSearch = linear offset from start of heap to begin search
127 * return: pointer to the allocated block, 0 if error
128 */
129PMemBlock mmAllocMem(memHeap_t * heap, int size, int align2, int startSearch);
130
131/*
132 * Returns 1 if the block 'b' is part of the heap 'heap'
133 */
134int mmBlockInHeap(PMemBlock heap, PMemBlock b);
135
136/*
137 * Free block starts at offset
138 * input: pointer to a block
139 * return: 0 if OK, -1 if error
140 */
141int mmFreeMem(PMemBlock b);
142
143/* For debuging purpose. */
144void mmDumpMemInfo(memHeap_t * mmInit);
145
146#endif /* __SIS_DS_H__ */
diff --git a/drivers/char/drm/sis_mm.c b/drivers/char/drm/sis_mm.c
index 5e9936bc307f..d26f5dbb7853 100644
--- a/drivers/char/drm/sis_mm.c
+++ b/drivers/char/drm/sis_mm.c
@@ -1,414 +1,348 @@
1/* sis_mm.c -- Private header for Direct Rendering Manager -*- linux-c -*- 1/**************************************************************************
2 * Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw
3 * 2 *
4 * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan. 3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA.
5 * All rights reserved. 4 * All Rights Reserved.
6 * 5 *
7 * Permission is hereby granted, free of charge, to any person obtaining a 6 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"), 7 * copy of this software and associated documentation files (the
9 * to deal in the Software without restriction, including without limitation 8 * "Software"), to deal in the Software without restriction, including
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * without limitation the rights to use, copy, modify, merge, publish,
11 * and/or sell copies of the Software, and to permit persons to whom the 10 * distribute, sub license, and/or sell copies of the Software, and to
12 * Software is furnished to do so, subject to the following conditions: 11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 * 13 *
14 * The above copyright notice and this permission notice (including the next 14 * The above copyright notice and this permission notice (including the
15 * paragraph) shall be included in all copies or substantial portions of the 15 * next paragraph) shall be included in all copies or substantial portions
16 * Software. 16 * of the Software.
17 * 17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * DEALINGS IN THE SOFTWARE. 24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * 25 *
26 * Authors:
27 * Sung-Ching Lin <sclin@sis.com.tw>
28 * 26 *
27 **************************************************************************/
28
29/*
30 * Authors:
31 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
29 */ 32 */
30 33
31#include "drmP.h" 34#include "drmP.h"
32#include "sis_drm.h" 35#include "sis_drm.h"
33#include "sis_drv.h" 36#include "sis_drv.h"
34#include "sis_ds.h" 37
35#if defined(__linux__) && defined(CONFIG_FB_SIS)
36#include <video/sisfb.h> 38#include <video/sisfb.h>
37#endif
38 39
39#define MAX_CONTEXT 100
40#define VIDEO_TYPE 0 40#define VIDEO_TYPE 0
41#define AGP_TYPE 1 41#define AGP_TYPE 1
42 42
43typedef struct {
44 int used;
45 int context;
46 set_t *sets[2]; /* 0 for video, 1 for AGP */
47} sis_context_t;
48 43
49static sis_context_t global_ppriv[MAX_CONTEXT]; 44#if defined(CONFIG_FB_SIS)
45/* fb management via fb device */
50 46
51static int add_alloc_set(int context, int type, unsigned int val) 47#define SIS_MM_ALIGN_SHIFT 0
52{ 48#define SIS_MM_ALIGN_MASK 0
53 int i, retval = 0;
54 49
55 for (i = 0; i < MAX_CONTEXT; i++) { 50static void *sis_sman_mm_allocate(void *private, unsigned long size,
56 if (global_ppriv[i].used && global_ppriv[i].context == context) { 51 unsigned alignment)
57 retval = setAdd(global_ppriv[i].sets[type], val);
58 break;
59 }
60 }
61 return retval;
62}
63
64static int del_alloc_set(int context, int type, unsigned int val)
65{ 52{
66 int i, retval = 0; 53 struct sis_memreq req;
67 54
68 for (i = 0; i < MAX_CONTEXT; i++) { 55 req.size = size;
69 if (global_ppriv[i].used && global_ppriv[i].context == context) { 56 sis_malloc(&req);
70 retval = setDel(global_ppriv[i].sets[type], val); 57 if (req.size == 0)
71 break; 58 return NULL;
72 } 59 else
73 } 60 return (void *)~req.offset;
74 return retval;
75} 61}
76 62
77/* fb management via fb device */ 63static void sis_sman_mm_free(void *private, void *ref)
78#if defined(__linux__) && defined(CONFIG_FB_SIS)
79
80static int sis_fb_init(DRM_IOCTL_ARGS)
81{ 64{
82 return 0; 65 sis_free(~((unsigned long)ref));
83} 66}
84 67
85static int sis_fb_alloc(DRM_IOCTL_ARGS) 68static void sis_sman_mm_destroy(void *private)
86{ 69{
87 drm_sis_mem_t fb; 70 ;
88 struct sis_memreq req;
89 drm_sis_mem_t __user *argp = (drm_sis_mem_t __user *)data;
90 int retval = 0;
91
92 DRM_COPY_FROM_USER_IOCTL(fb, argp, sizeof(fb));
93
94 req.size = fb.size;
95 sis_malloc(&req);
96 if (req.offset) {
97 /* TODO */
98 fb.offset = req.offset;
99 fb.free = req.offset;
100 if (!add_alloc_set(fb.context, VIDEO_TYPE, fb.free)) {
101 DRM_DEBUG("adding to allocation set fails\n");
102 sis_free(req.offset);
103 retval = DRM_ERR(EINVAL);
104 }
105 } else {
106 fb.offset = 0;
107 fb.size = 0;
108 fb.free = 0;
109 }
110
111 DRM_COPY_TO_USER_IOCTL(argp, fb, sizeof(fb));
112
113 DRM_DEBUG("alloc fb, size = %d, offset = %d\n", fb.size, req.offset);
114
115 return retval;
116} 71}
117 72
118static int sis_fb_free(DRM_IOCTL_ARGS) 73static unsigned long sis_sman_mm_offset(void *private, void *ref)
119{ 74{
120 drm_sis_mem_t fb; 75 return ~((unsigned long)ref);
121 int retval = 0; 76}
122
123 DRM_COPY_FROM_USER_IOCTL(fb, (drm_sis_mem_t __user *) data, sizeof(fb));
124
125 if (!fb.free)
126 return DRM_ERR(EINVAL);
127 77
128 if (!del_alloc_set(fb.context, VIDEO_TYPE, fb.free)) 78#else /* CONFIG_FB_SIS */
129 retval = DRM_ERR(EINVAL);
130 sis_free(fb.free);
131 79
132 DRM_DEBUG("free fb, offset = 0x%lx\n", fb.free); 80#define SIS_MM_ALIGN_SHIFT 4
81#define SIS_MM_ALIGN_MASK ( (1 << SIS_MM_ALIGN_SHIFT) - 1)
133 82
134 return retval; 83#endif /* CONFIG_FB_SIS */
135}
136 84
137#else
138
139/* Called by the X Server to initialize the FB heap. Allocations will fail
140 * unless this is called. Offset is the beginning of the heap from the
141 * framebuffer offset (MaxXFBMem in XFree86).
142 *
143 * Memory layout according to Thomas Winischofer:
144 * |------------------|DDDDDDDDDDDDDDDDDDDDDDDDDDDDD|HHHH|CCCCCCCCCCC|
145 *
146 * X driver/sisfb HW- Command-
147 * framebuffer memory DRI heap Cursor queue
148 */
149static int sis_fb_init(DRM_IOCTL_ARGS) 85static int sis_fb_init(DRM_IOCTL_ARGS)
150{ 86{
151 DRM_DEVICE; 87 DRM_DEVICE;
152 drm_sis_private_t *dev_priv = dev->dev_private; 88 drm_sis_private_t *dev_priv = dev->dev_private;
153 drm_sis_fb_t fb; 89 drm_sis_fb_t fb;
90 int ret;
154 91
155 DRM_COPY_FROM_USER_IOCTL(fb, (drm_sis_fb_t __user *) data, sizeof(fb)); 92 DRM_COPY_FROM_USER_IOCTL(fb, (drm_sis_fb_t __user *) data, sizeof(fb));
156 93
157 if (dev_priv == NULL) { 94 mutex_lock(&dev->struct_mutex);
158 dev->dev_private = drm_calloc(1, sizeof(drm_sis_private_t), 95#if defined(CONFIG_FB_SIS)
159 DRM_MEM_DRIVER); 96 {
160 dev_priv = dev->dev_private; 97 drm_sman_mm_t sman_mm;
161 if (dev_priv == NULL) 98 sman_mm.private = (void *)0xFFFFFFFF;
162 return ENOMEM; 99 sman_mm.allocate = sis_sman_mm_allocate;
100 sman_mm.free = sis_sman_mm_free;
101 sman_mm.destroy = sis_sman_mm_destroy;
102 sman_mm.offset = sis_sman_mm_offset;
103 ret =
104 drm_sman_set_manager(&dev_priv->sman, VIDEO_TYPE, &sman_mm);
163 } 105 }
106#else
107 ret = drm_sman_set_range(&dev_priv->sman, VIDEO_TYPE, 0,
108 fb.size >> SIS_MM_ALIGN_SHIFT);
109#endif
164 110
165 if (dev_priv->FBHeap != NULL) 111 if (ret) {
166 return DRM_ERR(EINVAL); 112 DRM_ERROR("VRAM memory manager initialisation error\n");
113 mutex_unlock(&dev->struct_mutex);
114 return ret;
115 }
167 116
168 dev_priv->FBHeap = mmInit(fb.offset, fb.size); 117 dev_priv->vram_initialized = 1;
118 dev_priv->vram_offset = fb.offset;
169 119
120 mutex_unlock(&dev->struct_mutex);
170 DRM_DEBUG("offset = %u, size = %u", fb.offset, fb.size); 121 DRM_DEBUG("offset = %u, size = %u", fb.offset, fb.size);
171 122
172 return 0; 123 return 0;
173} 124}
174 125
175static int sis_fb_alloc(DRM_IOCTL_ARGS) 126static int sis_drm_alloc(drm_device_t * dev, drm_file_t * priv,
127 unsigned long data, int pool)
176{ 128{
177 DRM_DEVICE;
178 drm_sis_private_t *dev_priv = dev->dev_private; 129 drm_sis_private_t *dev_priv = dev->dev_private;
179 drm_sis_mem_t __user *argp = (drm_sis_mem_t __user *)data; 130 drm_sis_mem_t __user *argp = (drm_sis_mem_t __user *) data;
180 drm_sis_mem_t fb; 131 drm_sis_mem_t mem;
181 PMemBlock block;
182 int retval = 0; 132 int retval = 0;
133 drm_memblock_item_t *item;
134
135 DRM_COPY_FROM_USER_IOCTL(mem, argp, sizeof(mem));
183 136
184 if (dev_priv == NULL || dev_priv->FBHeap == NULL) 137 mutex_lock(&dev->struct_mutex);
138
139 if (0 == ((pool == 0) ? dev_priv->vram_initialized :
140 dev_priv->agp_initialized)) {
141 DRM_ERROR
142 ("Attempt to allocate from uninitialized memory manager.\n");
185 return DRM_ERR(EINVAL); 143 return DRM_ERR(EINVAL);
144 }
186 145
187 DRM_COPY_FROM_USER_IOCTL(fb, argp, sizeof(fb)); 146 mem.size = (mem.size + SIS_MM_ALIGN_MASK) >> SIS_MM_ALIGN_SHIFT;
188 147 item = drm_sman_alloc(&dev_priv->sman, pool, mem.size, 0,
189 block = mmAllocMem(dev_priv->FBHeap, fb.size, 0, 0); 148 (unsigned long)priv);
190 if (block) { 149
191 /* TODO */ 150 mutex_unlock(&dev->struct_mutex);
192 fb.offset = block->ofs; 151 if (item) {
193 fb.free = (unsigned long)block; 152 mem.offset = ((pool == 0) ?
194 if (!add_alloc_set(fb.context, VIDEO_TYPE, fb.free)) { 153 dev_priv->vram_offset : dev_priv->agp_offset) +
195 DRM_DEBUG("adding to allocation set fails\n"); 154 (item->mm->
196 mmFreeMem((PMemBlock) fb.free); 155 offset(item->mm, item->mm_info) << SIS_MM_ALIGN_SHIFT);
197 retval = DRM_ERR(EINVAL); 156 mem.free = item->user_hash.key;
198 } 157 mem.size = mem.size << SIS_MM_ALIGN_SHIFT;
199 } else { 158 } else {
200 fb.offset = 0; 159 mem.offset = 0;
201 fb.size = 0; 160 mem.size = 0;
202 fb.free = 0; 161 mem.free = 0;
162 retval = DRM_ERR(ENOMEM);
203 } 163 }
204 164
205 DRM_COPY_TO_USER_IOCTL(argp, fb, sizeof(fb)); 165 DRM_COPY_TO_USER_IOCTL(argp, mem, sizeof(mem));
206 166
207 DRM_DEBUG("alloc fb, size = %d, offset = %d\n", fb.size, fb.offset); 167 DRM_DEBUG("alloc %d, size = %d, offset = %d\n", pool, mem.size,
168 mem.offset);
208 169
209 return retval; 170 return retval;
210} 171}
211 172
212static int sis_fb_free(DRM_IOCTL_ARGS) 173static int sis_drm_free(DRM_IOCTL_ARGS)
213{ 174{
214 DRM_DEVICE; 175 DRM_DEVICE;
215 drm_sis_private_t *dev_priv = dev->dev_private; 176 drm_sis_private_t *dev_priv = dev->dev_private;
216 drm_sis_mem_t fb; 177 drm_sis_mem_t mem;
178 int ret;
217 179
218 if (dev_priv == NULL || dev_priv->FBHeap == NULL) 180 DRM_COPY_FROM_USER_IOCTL(mem, (drm_sis_mem_t __user *) data,
219 return DRM_ERR(EINVAL); 181 sizeof(mem));
220 182
221 DRM_COPY_FROM_USER_IOCTL(fb, (drm_sis_mem_t __user *) data, sizeof(fb)); 183 mutex_lock(&dev->struct_mutex);
184 ret = drm_sman_free_key(&dev_priv->sman, mem.free);
185 mutex_unlock(&dev->struct_mutex);
186 DRM_DEBUG("free = 0x%lx\n", mem.free);
222 187
223 if (!mmBlockInHeap(dev_priv->FBHeap, (PMemBlock) fb.free)) 188 return ret;
224 return DRM_ERR(EINVAL);
225
226 if (!del_alloc_set(fb.context, VIDEO_TYPE, fb.free))
227 return DRM_ERR(EINVAL);
228 mmFreeMem((PMemBlock) fb.free);
229
230 DRM_DEBUG("free fb, free = 0x%lx\n", fb.free);
231
232 return 0;
233} 189}
234 190
235#endif 191static int sis_fb_alloc(DRM_IOCTL_ARGS)
236 192{
237/* agp memory management */ 193 DRM_DEVICE;
194 return sis_drm_alloc(dev, priv, data, VIDEO_TYPE);
195}
238 196
239static int sis_ioctl_agp_init(DRM_IOCTL_ARGS) 197static int sis_ioctl_agp_init(DRM_IOCTL_ARGS)
240{ 198{
241 DRM_DEVICE; 199 DRM_DEVICE;
242 drm_sis_private_t *dev_priv = dev->dev_private; 200 drm_sis_private_t *dev_priv = dev->dev_private;
243 drm_sis_agp_t agp; 201 drm_sis_agp_t agp;
244 202 int ret;
245 if (dev_priv == NULL) { 203 dev_priv = dev->dev_private;
246 dev->dev_private = drm_calloc(1, sizeof(drm_sis_private_t),
247 DRM_MEM_DRIVER);
248 dev_priv = dev->dev_private;
249 if (dev_priv == NULL)
250 return ENOMEM;
251 }
252
253 if (dev_priv->AGPHeap != NULL)
254 return DRM_ERR(EINVAL);
255 204
256 DRM_COPY_FROM_USER_IOCTL(agp, (drm_sis_agp_t __user *) data, 205 DRM_COPY_FROM_USER_IOCTL(agp, (drm_sis_agp_t __user *) data,
257 sizeof(agp)); 206 sizeof(agp));
207 mutex_lock(&dev->struct_mutex);
208 ret = drm_sman_set_range(&dev_priv->sman, AGP_TYPE, 0,
209 agp.size >> SIS_MM_ALIGN_SHIFT);
210
211 if (ret) {
212 DRM_ERROR("AGP memory manager initialisation error\n");
213 mutex_unlock(&dev->struct_mutex);
214 return ret;
215 }
258 216
259 dev_priv->AGPHeap = mmInit(agp.offset, agp.size); 217 dev_priv->agp_initialized = 1;
218 dev_priv->agp_offset = agp.offset;
219 mutex_unlock(&dev->struct_mutex);
260 220
261 DRM_DEBUG("offset = %u, size = %u", agp.offset, agp.size); 221 DRM_DEBUG("offset = %u, size = %u", agp.offset, agp.size);
262
263 return 0; 222 return 0;
264} 223}
265 224
266static int sis_ioctl_agp_alloc(DRM_IOCTL_ARGS) 225static int sis_ioctl_agp_alloc(DRM_IOCTL_ARGS)
267{ 226{
268 DRM_DEVICE; 227 DRM_DEVICE;
269 drm_sis_private_t *dev_priv = dev->dev_private;
270 drm_sis_mem_t __user *argp = (drm_sis_mem_t __user *)data;
271 drm_sis_mem_t agp;
272 PMemBlock block;
273 int retval = 0;
274 228
275 if (dev_priv == NULL || dev_priv->AGPHeap == NULL) 229 return sis_drm_alloc(dev, priv, data, AGP_TYPE);
276 return DRM_ERR(EINVAL); 230}
277 231
278 DRM_COPY_FROM_USER_IOCTL(agp, argp, sizeof(agp)); 232static drm_local_map_t *sis_reg_init(drm_device_t *dev)
279 233{
280 block = mmAllocMem(dev_priv->AGPHeap, agp.size, 0, 0); 234 drm_map_list_t *entry;
281 if (block) { 235 drm_local_map_t *map;
282 /* TODO */ 236
283 agp.offset = block->ofs; 237 list_for_each_entry(entry, &dev->maplist->head, head) {
284 agp.free = (unsigned long)block; 238 map = entry->map;
285 if (!add_alloc_set(agp.context, AGP_TYPE, agp.free)) { 239 if (!map)
286 DRM_DEBUG("adding to allocation set fails\n"); 240 continue;
287 mmFreeMem((PMemBlock) agp.free); 241 if (map->type == _DRM_REGISTERS) {
288 retval = -1; 242 return map;
289 } 243 }
290 } else {
291 agp.offset = 0;
292 agp.size = 0;
293 agp.free = 0;
294 } 244 }
295 245 return NULL;
296 DRM_COPY_TO_USER_IOCTL(argp, agp, sizeof(agp));
297
298 DRM_DEBUG("alloc agp, size = %d, offset = %d\n", agp.size, agp.offset);
299
300 return retval;
301} 246}
302 247
303static int sis_ioctl_agp_free(DRM_IOCTL_ARGS) 248int sis_idle(drm_device_t *dev)
304{ 249{
305 DRM_DEVICE;
306 drm_sis_private_t *dev_priv = dev->dev_private; 250 drm_sis_private_t *dev_priv = dev->dev_private;
307 drm_sis_mem_t agp; 251 uint32_t idle_reg;
308 252 unsigned long end;
309 if (dev_priv == NULL || dev_priv->AGPHeap == NULL) 253 int i;
310 return DRM_ERR(EINVAL);
311 254
312 DRM_COPY_FROM_USER_IOCTL(agp, (drm_sis_mem_t __user *) data, 255 if (dev_priv->idle_fault)
313 sizeof(agp)); 256 return 0;
314 257
315 if (!mmBlockInHeap(dev_priv->AGPHeap, (PMemBlock) agp.free)) 258 if (dev_priv->mmio == NULL) {
316 return DRM_ERR(EINVAL); 259 dev_priv->mmio = sis_reg_init(dev);
260 if (dev_priv->mmio == NULL) {
261 DRM_ERROR("Could not find register map.\n");
262 return 0;
263 }
264 }
265
266 /*
267 * Implement a device switch here if needed
268 */
269
270 if (dev_priv->chipset != SIS_CHIP_315)
271 return 0;
272
273 /*
274 * Timeout after 3 seconds. We cannot use DRM_WAIT_ON here
275 * because its polling frequency is too low.
276 */
277
278 end = jiffies + (DRM_HZ * 3);
279
280 for (i=0; i<4; ++i) {
281 do {
282 idle_reg = SIS_READ(0x85cc);
283 } while ( !time_after_eq(jiffies, end) &&
284 ((idle_reg & 0x80000000) != 0x80000000));
285 }
317 286
318 mmFreeMem((PMemBlock) agp.free); 287 if (time_after_eq(jiffies, end)) {
319 if (!del_alloc_set(agp.context, AGP_TYPE, agp.free)) 288 DRM_ERROR("Graphics engine idle timeout. "
320 return DRM_ERR(EINVAL); 289 "Disabling idle check\n");
290 dev_priv->idle_fault = 1;
291 }
321 292
322 DRM_DEBUG("free agp, free = 0x%lx\n", agp.free); 293 /*
294 * The caller never sees an error code. It gets trapped
295 * in libdrm.
296 */
323 297
324 return 0; 298 return 0;
325} 299}
326 300
327int sis_init_context(struct drm_device *dev, int context)
328{
329 int i;
330 301
331 for (i = 0; i < MAX_CONTEXT; i++) { 302void sis_lastclose(struct drm_device *dev)
332 if (global_ppriv[i].used && 303{
333 (global_ppriv[i].context == context)) 304 drm_sis_private_t *dev_priv = dev->dev_private;
334 break;
335 }
336 305
337 if (i >= MAX_CONTEXT) { 306 if (!dev_priv)
338 for (i = 0; i < MAX_CONTEXT; i++) { 307 return;
339 if (!global_ppriv[i].used) {
340 global_ppriv[i].context = context;
341 global_ppriv[i].used = 1;
342 global_ppriv[i].sets[0] = setInit();
343 global_ppriv[i].sets[1] = setInit();
344 DRM_DEBUG("init allocation set, socket=%d, "
345 "context = %d\n", i, context);
346 break;
347 }
348 }
349 if ((i >= MAX_CONTEXT) || (global_ppriv[i].sets[0] == NULL) ||
350 (global_ppriv[i].sets[1] == NULL)) {
351 return 0;
352 }
353 }
354 308
355 return 1; 309 mutex_lock(&dev->struct_mutex);
310 drm_sman_cleanup(&dev_priv->sman);
311 dev_priv->vram_initialized = 0;
312 dev_priv->agp_initialized = 0;
313 dev_priv->mmio = NULL;
314 mutex_unlock(&dev->struct_mutex);
356} 315}
357 316
358int sis_final_context(struct drm_device *dev, int context) 317void sis_reclaim_buffers_locked(drm_device_t * dev, struct file *filp)
359{ 318{
360 int i; 319 drm_sis_private_t *dev_priv = dev->dev_private;
320 drm_file_t *priv = filp->private_data;
361 321
362 for (i = 0; i < MAX_CONTEXT; i++) { 322 mutex_lock(&dev->struct_mutex);
363 if (global_ppriv[i].used && 323 if (drm_sman_owner_clean(&dev_priv->sman, (unsigned long)priv)) {
364 (global_ppriv[i].context == context)) 324 mutex_unlock(&dev->struct_mutex);
365 break; 325 return;
366 } 326 }
367 327
368 if (i < MAX_CONTEXT) { 328 if (dev->driver->dma_quiescent) {
369 set_t *set; 329 dev->driver->dma_quiescent(dev);
370 ITEM_TYPE item;
371 int retval;
372
373 DRM_DEBUG("find socket %d, context = %d\n", i, context);
374
375 /* Video Memory */
376 set = global_ppriv[i].sets[0];
377 retval = setFirst(set, &item);
378 while (retval) {
379 DRM_DEBUG("free video memory 0x%lx\n", item);
380#if defined(__linux__) && defined(CONFIG_FB_SIS)
381 sis_free(item);
382#else
383 mmFreeMem((PMemBlock) item);
384#endif
385 retval = setNext(set, &item);
386 }
387 setDestroy(set);
388
389 /* AGP Memory */
390 set = global_ppriv[i].sets[1];
391 retval = setFirst(set, &item);
392 while (retval) {
393 DRM_DEBUG("free agp memory 0x%lx\n", item);
394 mmFreeMem((PMemBlock) item);
395 retval = setNext(set, &item);
396 }
397 setDestroy(set);
398
399 global_ppriv[i].used = 0;
400 } 330 }
401 331
402 return 1; 332 drm_sman_owner_cleanup(&dev_priv->sman, (unsigned long)priv);
333 mutex_unlock(&dev->struct_mutex);
334 return;
403} 335}
404 336
405drm_ioctl_desc_t sis_ioctls[] = { 337drm_ioctl_desc_t sis_ioctls[] = {
406 [DRM_IOCTL_NR(DRM_SIS_FB_ALLOC)] = {sis_fb_alloc, DRM_AUTH}, 338 [DRM_IOCTL_NR(DRM_SIS_FB_ALLOC)] = {sis_fb_alloc, DRM_AUTH},
407 [DRM_IOCTL_NR(DRM_SIS_FB_FREE)] = {sis_fb_free, DRM_AUTH}, 339 [DRM_IOCTL_NR(DRM_SIS_FB_FREE)] = {sis_drm_free, DRM_AUTH},
408 [DRM_IOCTL_NR(DRM_SIS_AGP_INIT)] = {sis_ioctl_agp_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY}, 340 [DRM_IOCTL_NR(DRM_SIS_AGP_INIT)] =
341 {sis_ioctl_agp_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY},
409 [DRM_IOCTL_NR(DRM_SIS_AGP_ALLOC)] = {sis_ioctl_agp_alloc, DRM_AUTH}, 342 [DRM_IOCTL_NR(DRM_SIS_AGP_ALLOC)] = {sis_ioctl_agp_alloc, DRM_AUTH},
410 [DRM_IOCTL_NR(DRM_SIS_AGP_FREE)] = {sis_ioctl_agp_free, DRM_AUTH}, 343 [DRM_IOCTL_NR(DRM_SIS_AGP_FREE)] = {sis_drm_free, DRM_AUTH},
411 [DRM_IOCTL_NR(DRM_SIS_FB_INIT)] = {sis_fb_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY} 344 [DRM_IOCTL_NR(DRM_SIS_FB_INIT)] =
345 {sis_fb_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY}
412}; 346};
413 347
414int sis_max_ioctl = DRM_ARRAY_SIZE(sis_ioctls); 348int sis_max_ioctl = DRM_ARRAY_SIZE(sis_ioctls);
diff --git a/drivers/char/drm/via_dmablit.c b/drivers/char/drm/via_dmablit.c
index 78a81a4a99c5..806f9ce5f47b 100644
--- a/drivers/char/drm/via_dmablit.c
+++ b/drivers/char/drm/via_dmablit.c
@@ -41,9 +41,9 @@
41 41
42#include <linux/pagemap.h> 42#include <linux/pagemap.h>
43 43
44#define VIA_PGDN(x) (((unsigned long)(x)) & PAGE_MASK) 44#define VIA_PGDN(x) (((unsigned long)(x)) & PAGE_MASK)
45#define VIA_PGOFF(x) (((unsigned long)(x)) & ~PAGE_MASK) 45#define VIA_PGOFF(x) (((unsigned long)(x)) & ~PAGE_MASK)
46#define VIA_PFN(x) ((unsigned long)(x) >> PAGE_SHIFT) 46#define VIA_PFN(x) ((unsigned long)(x) >> PAGE_SHIFT)
47 47
48typedef struct _drm_via_descriptor { 48typedef struct _drm_via_descriptor {
49 uint32_t mem_addr; 49 uint32_t mem_addr;
@@ -121,19 +121,19 @@ via_map_blit_for_device(struct pci_dev *pdev,
121 121
122 while (line_len > 0) { 122 while (line_len > 0) {
123 123
124 remaining_len = min(PAGE_SIZE-VIA_PGOFF(cur_mem), line_len); 124 remaining_len = min(PAGE_SIZE-VIA_PGOFF(cur_mem), line_len);
125 line_len -= remaining_len; 125 line_len -= remaining_len;
126 126
127 if (mode == 1) { 127 if (mode == 1) {
128 desc_ptr->mem_addr = 128 desc_ptr->mem_addr =
129 dma_map_page(&pdev->dev, 129 dma_map_page(&pdev->dev,
130 vsg->pages[VIA_PFN(cur_mem) - 130 vsg->pages[VIA_PFN(cur_mem) -
131 VIA_PFN(first_addr)], 131 VIA_PFN(first_addr)],
132 VIA_PGOFF(cur_mem), remaining_len, 132 VIA_PGOFF(cur_mem), remaining_len,
133 vsg->direction); 133 vsg->direction);
134 desc_ptr->dev_addr = cur_fb; 134 desc_ptr->dev_addr = cur_fb;
135 135
136 desc_ptr->size = remaining_len; 136 desc_ptr->size = remaining_len;
137 desc_ptr->next = (uint32_t) next; 137 desc_ptr->next = (uint32_t) next;
138 next = dma_map_single(&pdev->dev, desc_ptr, sizeof(*desc_ptr), 138 next = dma_map_single(&pdev->dev, desc_ptr, sizeof(*desc_ptr),
139 DMA_TO_DEVICE); 139 DMA_TO_DEVICE);
@@ -162,7 +162,7 @@ via_map_blit_for_device(struct pci_dev *pdev,
162 162
163/* 163/*
164 * Function that frees up all resources for a blit. It is usable even if the 164 * Function that frees up all resources for a blit. It is usable even if the
165 * blit info has only be partially built as long as the status enum is consistent 165 * blit info has only been partially built as long as the status enum is consistent
166 * with the actual status of the used resources. 166 * with the actual status of the used resources.
167 */ 167 */
168 168
@@ -238,8 +238,11 @@ via_lock_all_dma_pages(drm_via_sg_info_t *vsg, drm_via_dmablit_t *xfer)
238 return DRM_ERR(ENOMEM); 238 return DRM_ERR(ENOMEM);
239 memset(vsg->pages, 0, sizeof(struct page *) * vsg->num_pages); 239 memset(vsg->pages, 0, sizeof(struct page *) * vsg->num_pages);
240 down_read(&current->mm->mmap_sem); 240 down_read(&current->mm->mmap_sem);
241 ret = get_user_pages(current, current->mm, (unsigned long) xfer->mem_addr, 241 ret = get_user_pages(current, current->mm,
242 vsg->num_pages, vsg->direction, 0, vsg->pages, NULL); 242 (unsigned long)xfer->mem_addr,
243 vsg->num_pages,
244 (vsg->direction == DMA_FROM_DEVICE),
245 0, vsg->pages, NULL);
243 246
244 up_read(&current->mm->mmap_sem); 247 up_read(&current->mm->mmap_sem);
245 if (ret != vsg->num_pages) { 248 if (ret != vsg->num_pages) {
@@ -475,9 +478,15 @@ via_dmablit_timer(unsigned long data)
475 if (!timer_pending(&blitq->poll_timer)) { 478 if (!timer_pending(&blitq->poll_timer)) {
476 blitq->poll_timer.expires = jiffies+1; 479 blitq->poll_timer.expires = jiffies+1;
477 add_timer(&blitq->poll_timer); 480 add_timer(&blitq->poll_timer);
478 }
479 via_dmablit_handler(dev, engine, 0);
480 481
482 /*
483 * Rerun handler to delete timer if engines are off, and
484 * to shorten abort latency. This is a little nasty.
485 */
486
487 via_dmablit_handler(dev, engine, 0);
488
489 }
481} 490}
482 491
483 492
@@ -491,9 +500,9 @@ via_dmablit_timer(unsigned long data)
491 500
492 501
493static void 502static void
494via_dmablit_workqueue(void *data) 503via_dmablit_workqueue(struct work_struct *work)
495{ 504{
496 drm_via_blitq_t *blitq = (drm_via_blitq_t *) data; 505 drm_via_blitq_t *blitq = container_of(work, drm_via_blitq_t, wq);
497 drm_device_t *dev = blitq->dev; 506 drm_device_t *dev = blitq->dev;
498 unsigned long irqsave; 507 unsigned long irqsave;
499 drm_via_sg_info_t *cur_sg; 508 drm_via_sg_info_t *cur_sg;
@@ -562,7 +571,7 @@ via_init_dmablit(drm_device_t *dev)
562 DRM_INIT_WAITQUEUE(blitq->blit_queue + j); 571 DRM_INIT_WAITQUEUE(blitq->blit_queue + j);
563 } 572 }
564 DRM_INIT_WAITQUEUE(&blitq->busy_queue); 573 DRM_INIT_WAITQUEUE(&blitq->busy_queue);
565 INIT_WORK(&blitq->wq, via_dmablit_workqueue, blitq); 574 INIT_WORK(&blitq->wq, via_dmablit_workqueue);
566 init_timer(&blitq->poll_timer); 575 init_timer(&blitq->poll_timer);
567 blitq->poll_timer.function = &via_dmablit_timer; 576 blitq->poll_timer.function = &via_dmablit_timer;
568 blitq->poll_timer.data = (unsigned long) blitq; 577 blitq->poll_timer.data = (unsigned long) blitq;
@@ -597,15 +606,27 @@ via_build_sg_info(drm_device_t *dev, drm_via_sg_info_t *vsg, drm_via_dmablit_t *
597 * (Not a big limitation anyway.) 606 * (Not a big limitation anyway.)
598 */ 607 */
599 608
600 if (((xfer->mem_stride - xfer->line_length) >= PAGE_SIZE) || 609 if ((xfer->mem_stride - xfer->line_length) >= PAGE_SIZE) {
601 (xfer->mem_stride > 2048*4)) {
602 DRM_ERROR("Too large system memory stride. Stride: %d, " 610 DRM_ERROR("Too large system memory stride. Stride: %d, "
603 "Length: %d\n", xfer->mem_stride, xfer->line_length); 611 "Length: %d\n", xfer->mem_stride, xfer->line_length);
604 return DRM_ERR(EINVAL); 612 return DRM_ERR(EINVAL);
605 } 613 }
606 614
607 if (xfer->num_lines > 2048) { 615 if ((xfer->mem_stride == xfer->line_length) &&
608 DRM_ERROR("Too many PCI DMA bitblt lines.\n"); 616 (xfer->fb_stride == xfer->line_length)) {
617 xfer->mem_stride *= xfer->num_lines;
618 xfer->line_length = xfer->mem_stride;
619 xfer->fb_stride = xfer->mem_stride;
620 xfer->num_lines = 1;
621 }
622
623 /*
624 * Don't lock an arbitrary large number of pages, since that causes a
625 * DOS security hole.
626 */
627
628 if (xfer->num_lines > 2048 || (xfer->num_lines*xfer->mem_stride > (2048*2048*4))) {
629 DRM_ERROR("Too large PCI DMA bitblt.\n");
609 return DRM_ERR(EINVAL); 630 return DRM_ERR(EINVAL);
610 } 631 }
611 632
@@ -628,16 +649,17 @@ via_build_sg_info(drm_device_t *dev, drm_via_sg_info_t *vsg, drm_via_dmablit_t *
628 649
629#ifdef VIA_BUGFREE 650#ifdef VIA_BUGFREE
630 if ((((unsigned long)xfer->mem_addr & 3) != ((unsigned long)xfer->fb_addr & 3)) || 651 if ((((unsigned long)xfer->mem_addr & 3) != ((unsigned long)xfer->fb_addr & 3)) ||
631 ((xfer->mem_stride & 3) != (xfer->fb_stride & 3))) { 652 ((xfer->num_lines > 1) && ((xfer->mem_stride & 3) != (xfer->fb_stride & 3)))) {
632 DRM_ERROR("Invalid DRM bitblt alignment.\n"); 653 DRM_ERROR("Invalid DRM bitblt alignment.\n");
633 return DRM_ERR(EINVAL); 654 return DRM_ERR(EINVAL);
634 } 655 }
635#else 656#else
636 if ((((unsigned long)xfer->mem_addr & 15) || 657 if ((((unsigned long)xfer->mem_addr & 15) ||
637 ((unsigned long)xfer->fb_addr & 3)) || (xfer->mem_stride & 15) || 658 ((unsigned long)xfer->fb_addr & 3)) ||
638 (xfer->fb_stride & 3)) { 659 ((xfer->num_lines > 1) &&
660 ((xfer->mem_stride & 15) || (xfer->fb_stride & 3)))) {
639 DRM_ERROR("Invalid DRM bitblt alignment.\n"); 661 DRM_ERROR("Invalid DRM bitblt alignment.\n");
640 return DRM_ERR(EINVAL); 662 return DRM_ERR(EINVAL);
641 } 663 }
642#endif 664#endif
643 665
@@ -715,7 +737,7 @@ via_dmablit(drm_device_t *dev, drm_via_dmablit_t *xfer)
715 drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private; 737 drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private;
716 drm_via_sg_info_t *vsg; 738 drm_via_sg_info_t *vsg;
717 drm_via_blitq_t *blitq; 739 drm_via_blitq_t *blitq;
718 int ret; 740 int ret;
719 int engine; 741 int engine;
720 unsigned long irqsave; 742 unsigned long irqsave;
721 743
@@ -756,7 +778,7 @@ via_dmablit(drm_device_t *dev, drm_via_dmablit_t *xfer)
756 778
757/* 779/*
758 * Sync on a previously submitted blit. Note that the X server use signals extensively, and 780 * Sync on a previously submitted blit. Note that the X server use signals extensively, and
759 * that there is a very big proability that this IOCTL will be interrupted by a signal. In that 781 * that there is a very big probability that this IOCTL will be interrupted by a signal. In that
760 * case it returns with -EAGAIN for the signal to be delivered. 782 * case it returns with -EAGAIN for the signal to be delivered.
761 * The caller should then reissue the IOCTL. This is similar to what is being done for drmGetLock(). 783 * The caller should then reissue the IOCTL. This is similar to what is being done for drmGetLock().
762 */ 784 */
diff --git a/drivers/char/drm/via_drm.h b/drivers/char/drm/via_drm.h
index 47f0b5b26379..e4ee97d7156f 100644
--- a/drivers/char/drm/via_drm.h
+++ b/drivers/char/drm/via_drm.h
@@ -250,6 +250,12 @@ typedef struct drm_via_blitsync {
250 unsigned engine; 250 unsigned engine;
251} drm_via_blitsync_t; 251} drm_via_blitsync_t;
252 252
253/* - * Below,"flags" is currently unused but will be used for possible future
254 * extensions like kernel space bounce buffers for bad alignments and
255 * blit engine busy-wait polling for better latency in the absence of
256 * interrupts.
257 */
258
253typedef struct drm_via_dmablit { 259typedef struct drm_via_dmablit {
254 uint32_t num_lines; 260 uint32_t num_lines;
255 uint32_t line_length; 261 uint32_t line_length;
@@ -260,7 +266,7 @@ typedef struct drm_via_dmablit {
260 unsigned char *mem_addr; 266 unsigned char *mem_addr;
261 uint32_t mem_stride; 267 uint32_t mem_stride;
262 268
263 int bounce_buffer; 269 uint32_t flags;
264 int to_fb; 270 int to_fb;
265 271
266 drm_via_blitsync_t sync; 272 drm_via_blitsync_t sync;
diff --git a/drivers/char/drm/via_drv.c b/drivers/char/drm/via_drv.c
index b3d364d793d7..bb9dde8b1911 100644
--- a/drivers/char/drm/via_drv.c
+++ b/drivers/char/drm/via_drv.c
@@ -43,7 +43,6 @@ static struct drm_driver driver = {
43 DRIVER_IRQ_SHARED | DRIVER_IRQ_VBL, 43 DRIVER_IRQ_SHARED | DRIVER_IRQ_VBL,
44 .load = via_driver_load, 44 .load = via_driver_load,
45 .unload = via_driver_unload, 45 .unload = via_driver_unload,
46 .context_ctor = via_init_context,
47 .context_dtor = via_final_context, 46 .context_dtor = via_final_context,
48 .vblank_wait = via_driver_vblank_wait, 47 .vblank_wait = via_driver_vblank_wait,
49 .irq_preinstall = via_driver_irq_preinstall, 48 .irq_preinstall = via_driver_irq_preinstall,
@@ -53,6 +52,8 @@ static struct drm_driver driver = {
53 .dma_quiescent = via_driver_dma_quiescent, 52 .dma_quiescent = via_driver_dma_quiescent,
54 .dri_library_name = dri_library_name, 53 .dri_library_name = dri_library_name,
55 .reclaim_buffers = drm_core_reclaim_buffers, 54 .reclaim_buffers = drm_core_reclaim_buffers,
55 .reclaim_buffers_locked = via_reclaim_buffers_locked,
56 .lastclose = via_lastclose,
56 .get_map_ofs = drm_core_get_map_ofs, 57 .get_map_ofs = drm_core_get_map_ofs,
57 .get_reg_ofs = drm_core_get_reg_ofs, 58 .get_reg_ofs = drm_core_get_reg_ofs,
58 .ioctls = via_ioctls, 59 .ioctls = via_ioctls,
diff --git a/drivers/char/drm/via_drv.h b/drivers/char/drm/via_drv.h
index 52bcc7b1ba45..d21b5b75da0f 100644
--- a/drivers/char/drm/via_drv.h
+++ b/drivers/char/drm/via_drv.h
@@ -24,15 +24,16 @@
24#ifndef _VIA_DRV_H_ 24#ifndef _VIA_DRV_H_
25#define _VIA_DRV_H_ 25#define _VIA_DRV_H_
26 26
27#include "drm_sman.h"
27#define DRIVER_AUTHOR "Various" 28#define DRIVER_AUTHOR "Various"
28 29
29#define DRIVER_NAME "via" 30#define DRIVER_NAME "via"
30#define DRIVER_DESC "VIA Unichrome / Pro" 31#define DRIVER_DESC "VIA Unichrome / Pro"
31#define DRIVER_DATE "20051116" 32#define DRIVER_DATE "20060529"
32 33
33#define DRIVER_MAJOR 2 34#define DRIVER_MAJOR 2
34#define DRIVER_MINOR 7 35#define DRIVER_MINOR 10
35#define DRIVER_PATCHLEVEL 4 36#define DRIVER_PATCHLEVEL 0
36 37
37#include "via_verifier.h" 38#include "via_verifier.h"
38 39
@@ -85,6 +86,12 @@ typedef struct drm_via_private {
85 uint32_t irq_enable_mask; 86 uint32_t irq_enable_mask;
86 uint32_t irq_pending_mask; 87 uint32_t irq_pending_mask;
87 int *irq_map; 88 int *irq_map;
89 unsigned int idle_fault;
90 drm_sman_t sman;
91 int vram_initialized;
92 int agp_initialized;
93 unsigned long vram_offset;
94 unsigned long agp_offset;
88 drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES]; 95 drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES];
89} drm_via_private_t; 96} drm_via_private_t;
90 97
@@ -135,6 +142,9 @@ extern void via_init_futex(drm_via_private_t * dev_priv);
135extern void via_cleanup_futex(drm_via_private_t * dev_priv); 142extern void via_cleanup_futex(drm_via_private_t * dev_priv);
136extern void via_release_futex(drm_via_private_t * dev_priv, int context); 143extern void via_release_futex(drm_via_private_t * dev_priv, int context);
137 144
145extern void via_reclaim_buffers_locked(drm_device_t *dev, struct file *filp);
146extern void via_lastclose(drm_device_t *dev);
147
138extern void via_dmablit_handler(drm_device_t *dev, int engine, int from_irq); 148extern void via_dmablit_handler(drm_device_t *dev, int engine, int from_irq);
139extern void via_init_dmablit(drm_device_t *dev); 149extern void via_init_dmablit(drm_device_t *dev);
140 150
diff --git a/drivers/char/drm/via_ds.c b/drivers/char/drm/via_ds.c
deleted file mode 100644
index 9429736b3b96..000000000000
--- a/drivers/char/drm/via_ds.c
+++ /dev/null
@@ -1,273 +0,0 @@
1/*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sub license,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25#include "drmP.h"
26
27#include "via_ds.h"
28extern unsigned int VIA_DEBUG;
29
30set_t *via_setInit(void)
31{
32 int i;
33 set_t *set;
34 set = (set_t *) drm_alloc(sizeof(set_t), DRM_MEM_DRIVER);
35 for (i = 0; i < SET_SIZE; i++) {
36 set->list[i].free_next = i + 1;
37 set->list[i].alloc_next = -1;
38 }
39 set->list[SET_SIZE - 1].free_next = -1;
40 set->free = 0;
41 set->alloc = -1;
42 set->trace = -1;
43 return set;
44}
45
46int via_setAdd(set_t * set, ITEM_TYPE item)
47{
48 int free = set->free;
49 if (free != -1) {
50 set->list[free].val = item;
51 set->free = set->list[free].free_next;
52 } else {
53 return 0;
54 }
55 set->list[free].alloc_next = set->alloc;
56 set->alloc = free;
57 set->list[free].free_next = -1;
58 return 1;
59}
60
61int via_setDel(set_t * set, ITEM_TYPE item)
62{
63 int alloc = set->alloc;
64 int prev = -1;
65
66 while (alloc != -1) {
67 if (set->list[alloc].val == item) {
68 if (prev != -1)
69 set->list[prev].alloc_next =
70 set->list[alloc].alloc_next;
71 else
72 set->alloc = set->list[alloc].alloc_next;
73 break;
74 }
75 prev = alloc;
76 alloc = set->list[alloc].alloc_next;
77 }
78
79 if (alloc == -1)
80 return 0;
81
82 set->list[alloc].free_next = set->free;
83 set->free = alloc;
84 set->list[alloc].alloc_next = -1;
85
86 return 1;
87}
88
89/* setFirst -> setAdd -> setNext is wrong */
90
91int via_setFirst(set_t * set, ITEM_TYPE * item)
92{
93 if (set->alloc == -1)
94 return 0;
95
96 *item = set->list[set->alloc].val;
97 set->trace = set->list[set->alloc].alloc_next;
98
99 return 1;
100}
101
102int via_setNext(set_t * set, ITEM_TYPE * item)
103{
104 if (set->trace == -1)
105 return 0;
106
107 *item = set->list[set->trace].val;
108 set->trace = set->list[set->trace].alloc_next;
109
110 return 1;
111}
112
113int via_setDestroy(set_t * set)
114{
115 drm_free(set, sizeof(set_t), DRM_MEM_DRIVER);
116
117 return 1;
118}
119
120#define ISFREE(bptr) ((bptr)->free)
121
122#define fprintf(fmt, arg...) do{}while(0)
123
124memHeap_t *via_mmInit(int ofs, int size)
125{
126 PMemBlock blocks;
127
128 if (size <= 0)
129 return NULL;
130
131 blocks = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock), DRM_MEM_DRIVER);
132
133 if (blocks) {
134 blocks->ofs = ofs;
135 blocks->size = size;
136 blocks->free = 1;
137 return (memHeap_t *) blocks;
138 } else
139 return NULL;
140}
141
142static TMemBlock *SliceBlock(TMemBlock * p,
143 int startofs, int size,
144 int reserved, int alignment)
145{
146 TMemBlock *newblock;
147
148 /* break left */
149 if (startofs > p->ofs) {
150 newblock =
151 (TMemBlock *) drm_calloc(1, sizeof(TMemBlock),
152 DRM_MEM_DRIVER);
153 newblock->ofs = startofs;
154 newblock->size = p->size - (startofs - p->ofs);
155 newblock->free = 1;
156 newblock->next = p->next;
157 p->size -= newblock->size;
158 p->next = newblock;
159 p = newblock;
160 }
161
162 /* break right */
163 if (size < p->size) {
164 newblock =
165 (TMemBlock *) drm_calloc(1, sizeof(TMemBlock),
166 DRM_MEM_DRIVER);
167 newblock->ofs = startofs + size;
168 newblock->size = p->size - size;
169 newblock->free = 1;
170 newblock->next = p->next;
171 p->size = size;
172 p->next = newblock;
173 }
174
175 /* p = middle block */
176 p->align = alignment;
177 p->free = 0;
178 p->reserved = reserved;
179 return p;
180}
181
182PMemBlock via_mmAllocMem(memHeap_t * heap, int size, int align2,
183 int startSearch)
184{
185 int mask, startofs, endofs;
186 TMemBlock *p;
187
188 if (!heap || align2 < 0 || size <= 0)
189 return NULL;
190
191 mask = (1 << align2) - 1;
192 startofs = 0;
193 p = (TMemBlock *) heap;
194
195 while (p) {
196 if (ISFREE(p)) {
197 startofs = (p->ofs + mask) & ~mask;
198
199 if (startofs < startSearch)
200 startofs = startSearch;
201
202 endofs = startofs + size;
203
204 if (endofs <= (p->ofs + p->size))
205 break;
206 }
207
208 p = p->next;
209 }
210
211 if (!p)
212 return NULL;
213
214 p = SliceBlock(p, startofs, size, 0, mask + 1);
215 p->heap = heap;
216
217 return p;
218}
219
220static __inline__ int Join2Blocks(TMemBlock * p)
221{
222 if (p->free && p->next && p->next->free) {
223 TMemBlock *q = p->next;
224 p->size += q->size;
225 p->next = q->next;
226 drm_free(q, sizeof(TMemBlock), DRM_MEM_DRIVER);
227
228 return 1;
229 }
230
231 return 0;
232}
233
234int via_mmFreeMem(PMemBlock b)
235{
236 TMemBlock *p, *prev;
237
238 if (!b)
239 return 0;
240
241 if (!b->heap) {
242 fprintf(stderr, "no heap\n");
243
244 return -1;
245 }
246
247 p = b->heap;
248 prev = NULL;
249
250 while (p && p != b) {
251 prev = p;
252 p = p->next;
253 }
254
255 if (!p || p->free || p->reserved) {
256 if (!p)
257 fprintf(stderr, "block not found in heap\n");
258 else if (p->free)
259 fprintf(stderr, "block already free\n");
260 else
261 fprintf(stderr, "block is reserved\n");
262
263 return -1;
264 }
265
266 p->free = 1;
267 Join2Blocks(p);
268
269 if (prev)
270 Join2Blocks(prev);
271
272 return 0;
273}
diff --git a/drivers/char/drm/via_ds.h b/drivers/char/drm/via_ds.h
deleted file mode 100644
index d2bb9f37ca38..000000000000
--- a/drivers/char/drm/via_ds.h
+++ /dev/null
@@ -1,104 +0,0 @@
1/*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
5 * All rights reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sub license,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 */
26#ifndef _via_ds_h_
27#define _via_ds_h_
28
29#include "drmP.h"
30
31/* Set Data Structure */
32#define SET_SIZE 5000
33typedef unsigned long ITEM_TYPE;
34
35typedef struct {
36 ITEM_TYPE val;
37 int alloc_next, free_next;
38} list_item_t;
39
40typedef struct {
41 int alloc;
42 int free;
43 int trace;
44 list_item_t list[SET_SIZE];
45} set_t;
46
47set_t *via_setInit(void);
48int via_setAdd(set_t * set, ITEM_TYPE item);
49int via_setDel(set_t * set, ITEM_TYPE item);
50int via_setFirst(set_t * set, ITEM_TYPE * item);
51int via_setNext(set_t * set, ITEM_TYPE * item);
52int via_setDestroy(set_t * set);
53
54#endif
55
56#ifndef MM_INC
57#define MM_INC
58
59struct mem_block_t {
60 struct mem_block_t *next;
61 struct mem_block_t *heap;
62 int ofs, size;
63 int align;
64 unsigned int free:1;
65 unsigned int reserved:1;
66};
67typedef struct mem_block_t TMemBlock;
68typedef struct mem_block_t *PMemBlock;
69
70/* a heap is just the first block in a chain */
71typedef struct mem_block_t memHeap_t;
72
73static __inline__ int mmBlockSize(PMemBlock b)
74{
75 return b->size;
76}
77
78static __inline__ int mmOffset(PMemBlock b)
79{
80 return b->ofs;
81}
82
83static __inline__ void mmMarkReserved(PMemBlock b)
84{
85 b->reserved = 1;
86}
87
88/*
89 * input: total size in bytes
90 * return: a heap pointer if OK, NULL if error
91 */
92memHeap_t *via_mmInit(int ofs, int size);
93
94PMemBlock via_mmAllocMem(memHeap_t * heap, int size, int align2,
95 int startSearch);
96
97/*
98 * Free block starts at offset
99 * input: pointer to a block
100 * return: 0 if OK, -1 if error
101 */
102int via_mmFreeMem(PMemBlock b);
103
104#endif
diff --git a/drivers/char/drm/via_map.c b/drivers/char/drm/via_map.c
index c6a08e96285b..782011e0a58d 100644
--- a/drivers/char/drm/via_map.c
+++ b/drivers/char/drm/via_map.c
@@ -98,6 +98,7 @@ int via_map_init(DRM_IOCTL_ARGS)
98int via_driver_load(drm_device_t *dev, unsigned long chipset) 98int via_driver_load(drm_device_t *dev, unsigned long chipset)
99{ 99{
100 drm_via_private_t *dev_priv; 100 drm_via_private_t *dev_priv;
101 int ret = 0;
101 102
102 dev_priv = drm_calloc(1, sizeof(drm_via_private_t), DRM_MEM_DRIVER); 103 dev_priv = drm_calloc(1, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
103 if (dev_priv == NULL) 104 if (dev_priv == NULL)
@@ -108,13 +109,19 @@ int via_driver_load(drm_device_t *dev, unsigned long chipset)
108 if (chipset == VIA_PRO_GROUP_A) 109 if (chipset == VIA_PRO_GROUP_A)
109 dev_priv->pro_group_a = 1; 110 dev_priv->pro_group_a = 1;
110 111
111 return 0; 112 ret = drm_sman_init(&dev_priv->sman, 2, 12, 8);
113 if (ret) {
114 drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER);
115 }
116 return ret;
112} 117}
113 118
114int via_driver_unload(drm_device_t *dev) 119int via_driver_unload(drm_device_t *dev)
115{ 120{
116 drm_via_private_t *dev_priv = dev->dev_private; 121 drm_via_private_t *dev_priv = dev->dev_private;
117 122
123 drm_sman_takedown(&dev_priv->sman);
124
118 drm_free(dev_priv, sizeof(drm_via_private_t), DRM_MEM_DRIVER); 125 drm_free(dev_priv, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
119 126
120 return 0; 127 return 0;
diff --git a/drivers/char/drm/via_mm.c b/drivers/char/drm/via_mm.c
index 33e0cb12e4c3..2fcf0577a7aa 100644
--- a/drivers/char/drm/via_mm.c
+++ b/drivers/char/drm/via_mm.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved. 2 * Copyright 2006 Tungsten Graphics Inc., Bismarck, ND., USA.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved. 3 * All rights reserved.
4 * 4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a 5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"), 6 * copy of this software and associated documentation files (the "Software"),
@@ -16,347 +16,194 @@
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 19 * THE AUTHORS OR COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE. 22 * DEALINGS IN THE SOFTWARE.
23 */ 23 */
24/*
25 * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
26 */
27
24#include "drmP.h" 28#include "drmP.h"
25#include "via_drm.h" 29#include "via_drm.h"
26#include "via_drv.h" 30#include "via_drv.h"
27#include "via_ds.h" 31#include "drm_sman.h"
28#include "via_mm.h"
29
30#define MAX_CONTEXT 100
31
32typedef struct {
33 int used;
34 int context;
35 set_t *sets[2]; /* 0 for frame buffer, 1 for AGP , 2 for System */
36} via_context_t;
37
38static via_context_t global_ppriv[MAX_CONTEXT];
39 32
40static int via_agp_alloc(drm_via_mem_t * mem); 33#define VIA_MM_ALIGN_SHIFT 4
41static int via_agp_free(drm_via_mem_t * mem); 34#define VIA_MM_ALIGN_MASK ( (1 << VIA_MM_ALIGN_SHIFT) - 1)
42static int via_fb_alloc(drm_via_mem_t * mem);
43static int via_fb_free(drm_via_mem_t * mem);
44
45static int add_alloc_set(int context, int type, unsigned long val)
46{
47 int i, retval = 0;
48
49 for (i = 0; i < MAX_CONTEXT; i++) {
50 if (global_ppriv[i].used && global_ppriv[i].context == context) {
51 retval = via_setAdd(global_ppriv[i].sets[type], val);
52 break;
53 }
54 }
55
56 return retval;
57}
58
59static int del_alloc_set(int context, int type, unsigned long val)
60{
61 int i, retval = 0;
62
63 for (i = 0; i < MAX_CONTEXT; i++)
64 if (global_ppriv[i].used && global_ppriv[i].context == context) {
65 retval = via_setDel(global_ppriv[i].sets[type], val);
66 break;
67 }
68
69 return retval;
70}
71
72/* agp memory management */
73static memHeap_t *AgpHeap = NULL;
74 35
75int via_agp_init(DRM_IOCTL_ARGS) 36int via_agp_init(DRM_IOCTL_ARGS)
76{ 37{
38 DRM_DEVICE;
77 drm_via_agp_t agp; 39 drm_via_agp_t agp;
40 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
41 int ret;
78 42
79 DRM_COPY_FROM_USER_IOCTL(agp, (drm_via_agp_t __user *) data, 43 DRM_COPY_FROM_USER_IOCTL(agp, (drm_via_agp_t __user *) data,
80 sizeof(agp)); 44 sizeof(agp));
45 mutex_lock(&dev->struct_mutex);
46 ret = drm_sman_set_range(&dev_priv->sman, VIA_MEM_AGP, 0,
47 agp.size >> VIA_MM_ALIGN_SHIFT);
48
49 if (ret) {
50 DRM_ERROR("AGP memory manager initialisation error\n");
51 mutex_unlock(&dev->struct_mutex);
52 return ret;
53 }
81 54
82 AgpHeap = via_mmInit(agp.offset, agp.size); 55 dev_priv->agp_initialized = 1;
83 56 dev_priv->agp_offset = agp.offset;
84 DRM_DEBUG("offset = %lu, size = %lu", (unsigned long)agp.offset, 57 mutex_unlock(&dev->struct_mutex);
85 (unsigned long)agp.size);
86 58
59 DRM_DEBUG("offset = %u, size = %u", agp.offset, agp.size);
87 return 0; 60 return 0;
88} 61}
89 62
90/* fb memory management */
91static memHeap_t *FBHeap = NULL;
92
93int via_fb_init(DRM_IOCTL_ARGS) 63int via_fb_init(DRM_IOCTL_ARGS)
94{ 64{
65 DRM_DEVICE;
95 drm_via_fb_t fb; 66 drm_via_fb_t fb;
67 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
68 int ret;
96 69
97 DRM_COPY_FROM_USER_IOCTL(fb, (drm_via_fb_t __user *) data, sizeof(fb)); 70 DRM_COPY_FROM_USER_IOCTL(fb, (drm_via_fb_t __user *) data, sizeof(fb));
98 71
99 FBHeap = via_mmInit(fb.offset, fb.size); 72 mutex_lock(&dev->struct_mutex);
73 ret = drm_sman_set_range(&dev_priv->sman, VIA_MEM_VIDEO, 0,
74 fb.size >> VIA_MM_ALIGN_SHIFT);
100 75
101 DRM_DEBUG("offset = %lu, size = %lu", (unsigned long)fb.offset, 76 if (ret) {
102 (unsigned long)fb.size); 77 DRM_ERROR("VRAM memory manager initialisation error\n");
78 mutex_unlock(&dev->struct_mutex);
79 return ret;
80 }
103 81
104 return 0; 82 dev_priv->vram_initialized = 1;
105} 83 dev_priv->vram_offset = fb.offset;
106 84
107int via_init_context(struct drm_device *dev, int context) 85 mutex_unlock(&dev->struct_mutex);
108{ 86 DRM_DEBUG("offset = %u, size = %u", fb.offset, fb.size);
109 int i; 87
110 88 return 0;
111 for (i = 0; i < MAX_CONTEXT; i++)
112 if (global_ppriv[i].used &&
113 (global_ppriv[i].context == context))
114 break;
115
116 if (i >= MAX_CONTEXT) {
117 for (i = 0; i < MAX_CONTEXT; i++) {
118 if (!global_ppriv[i].used) {
119 global_ppriv[i].context = context;
120 global_ppriv[i].used = 1;
121 global_ppriv[i].sets[0] = via_setInit();
122 global_ppriv[i].sets[1] = via_setInit();
123 DRM_DEBUG("init allocation set, socket=%d,"
124 " context = %d\n", i, context);
125 break;
126 }
127 }
128
129 if ((i >= MAX_CONTEXT) || (global_ppriv[i].sets[0] == NULL) ||
130 (global_ppriv[i].sets[1] == NULL)) {
131 return 0;
132 }
133 }
134 89
135 return 1;
136} 90}
137 91
138int via_final_context(struct drm_device *dev, int context) 92int via_final_context(struct drm_device *dev, int context)
139{ 93{
140 int i;
141 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; 94 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
142 95
143 for (i = 0; i < MAX_CONTEXT; i++)
144 if (global_ppriv[i].used &&
145 (global_ppriv[i].context == context))
146 break;
147
148 if (i < MAX_CONTEXT) {
149 set_t *set;
150 ITEM_TYPE item;
151 int retval;
152
153 DRM_DEBUG("find socket %d, context = %d\n", i, context);
154
155 /* Video Memory */
156 set = global_ppriv[i].sets[0];
157 retval = via_setFirst(set, &item);
158 while (retval) {
159 DRM_DEBUG("free video memory 0x%lx\n", item);
160 via_mmFreeMem((PMemBlock) item);
161 retval = via_setNext(set, &item);
162 }
163 via_setDestroy(set);
164
165 /* AGP Memory */
166 set = global_ppriv[i].sets[1];
167 retval = via_setFirst(set, &item);
168 while (retval) {
169 DRM_DEBUG("free agp memory 0x%lx\n", item);
170 via_mmFreeMem((PMemBlock) item);
171 retval = via_setNext(set, &item);
172 }
173 via_setDestroy(set);
174 global_ppriv[i].used = 0;
175 }
176 via_release_futex(dev_priv, context); 96 via_release_futex(dev_priv, context);
177 97
178#if defined(__linux__)
179 /* Linux specific until context tracking code gets ported to BSD */ 98 /* Linux specific until context tracking code gets ported to BSD */
180 /* Last context, perform cleanup */ 99 /* Last context, perform cleanup */
181 if (dev->ctx_count == 1 && dev->dev_private) { 100 if (dev->ctx_count == 1 && dev->dev_private) {
182 DRM_DEBUG("Last Context\n"); 101 DRM_DEBUG("Last Context\n");
183 if (dev->irq) 102 if (dev->irq)
184 drm_irq_uninstall(dev); 103 drm_irq_uninstall(dev);
185
186 via_cleanup_futex(dev_priv); 104 via_cleanup_futex(dev_priv);
187 via_do_cleanup_map(dev); 105 via_do_cleanup_map(dev);
188 } 106 }
189#endif
190
191 return 1; 107 return 1;
192} 108}
193 109
110void via_lastclose(struct drm_device *dev)
111{
112 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
113
114 if (!dev_priv)
115 return;
116
117 mutex_lock(&dev->struct_mutex);
118 drm_sman_cleanup(&dev_priv->sman);
119 dev_priv->vram_initialized = 0;
120 dev_priv->agp_initialized = 0;
121 mutex_unlock(&dev->struct_mutex);
122}
123
194int via_mem_alloc(DRM_IOCTL_ARGS) 124int via_mem_alloc(DRM_IOCTL_ARGS)
195{ 125{
126 DRM_DEVICE;
127
196 drm_via_mem_t mem; 128 drm_via_mem_t mem;
129 int retval = 0;
130 drm_memblock_item_t *item;
131 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
132 unsigned long tmpSize;
197 133
198 DRM_COPY_FROM_USER_IOCTL(mem, (drm_via_mem_t __user *) data, 134 DRM_COPY_FROM_USER_IOCTL(mem, (drm_via_mem_t __user *) data,
199 sizeof(mem)); 135 sizeof(mem));
200 136
201 switch (mem.type) { 137 if (mem.type > VIA_MEM_AGP) {
202 case VIA_MEM_VIDEO: 138 DRM_ERROR("Unknown memory type allocation\n");
203 if (via_fb_alloc(&mem) < 0) 139 return DRM_ERR(EINVAL);
204 return -EFAULT;
205 DRM_COPY_TO_USER_IOCTL((drm_via_mem_t __user *) data, mem,
206 sizeof(mem));
207 return 0;
208 case VIA_MEM_AGP:
209 if (via_agp_alloc(&mem) < 0)
210 return -EFAULT;
211 DRM_COPY_TO_USER_IOCTL((drm_via_mem_t __user *) data, mem,
212 sizeof(mem));
213 return 0;
214 } 140 }
215 141 mutex_lock(&dev->struct_mutex);
216 return -EFAULT; 142 if (0 == ((mem.type == VIA_MEM_VIDEO) ? dev_priv->vram_initialized :
217} 143 dev_priv->agp_initialized)) {
218 144 DRM_ERROR
219static int via_fb_alloc(drm_via_mem_t * mem) 145 ("Attempt to allocate from uninitialized memory manager.\n");
220{ 146 mutex_unlock(&dev->struct_mutex);
221 drm_via_mm_t fb; 147 return DRM_ERR(EINVAL);
222 PMemBlock block;
223 int retval = 0;
224
225 if (!FBHeap)
226 return -1;
227
228 fb.size = mem->size;
229 fb.context = mem->context;
230
231 block = via_mmAllocMem(FBHeap, fb.size, 5, 0);
232 if (block) {
233 fb.offset = block->ofs;
234 fb.free = (unsigned long)block;
235 if (!add_alloc_set(fb.context, VIA_MEM_VIDEO, fb.free)) {
236 DRM_DEBUG("adding to allocation set fails\n");
237 via_mmFreeMem((PMemBlock) fb.free);
238 retval = -1;
239 }
240 } else {
241 fb.offset = 0;
242 fb.size = 0;
243 fb.free = 0;
244 retval = -1;
245 } 148 }
246 149
247 mem->offset = fb.offset; 150 tmpSize = (mem.size + VIA_MM_ALIGN_MASK) >> VIA_MM_ALIGN_SHIFT;
248 mem->index = fb.free; 151 item = drm_sman_alloc(&dev_priv->sman, mem.type, tmpSize, 0,
249 152 (unsigned long)priv);
250 DRM_DEBUG("alloc fb, size = %d, offset = %d\n", fb.size, 153 mutex_unlock(&dev->struct_mutex);
251 (int)fb.offset); 154 if (item) {
252 155 mem.offset = ((mem.type == VIA_MEM_VIDEO) ?
253 return retval; 156 dev_priv->vram_offset : dev_priv->agp_offset) +
254} 157 (item->mm->
255 158 offset(item->mm, item->mm_info) << VIA_MM_ALIGN_SHIFT);
256static int via_agp_alloc(drm_via_mem_t * mem) 159 mem.index = item->user_hash.key;
257{
258 drm_via_mm_t agp;
259 PMemBlock block;
260 int retval = 0;
261
262 if (!AgpHeap)
263 return -1;
264
265 agp.size = mem->size;
266 agp.context = mem->context;
267
268 block = via_mmAllocMem(AgpHeap, agp.size, 5, 0);
269 if (block) {
270 agp.offset = block->ofs;
271 agp.free = (unsigned long)block;
272 if (!add_alloc_set(agp.context, VIA_MEM_AGP, agp.free)) {
273 DRM_DEBUG("adding to allocation set fails\n");
274 via_mmFreeMem((PMemBlock) agp.free);
275 retval = -1;
276 }
277 } else { 160 } else {
278 agp.offset = 0; 161 mem.offset = 0;
279 agp.size = 0; 162 mem.size = 0;
280 agp.free = 0; 163 mem.index = 0;
164 DRM_DEBUG("Video memory allocation failed\n");
165 retval = DRM_ERR(ENOMEM);
281 } 166 }
167 DRM_COPY_TO_USER_IOCTL((drm_via_mem_t __user *) data, mem, sizeof(mem));
282 168
283 mem->offset = agp.offset;
284 mem->index = agp.free;
285
286 DRM_DEBUG("alloc agp, size = %d, offset = %d\n", agp.size,
287 (unsigned int)agp.offset);
288 return retval; 169 return retval;
289} 170}
290 171
291int via_mem_free(DRM_IOCTL_ARGS) 172int via_mem_free(DRM_IOCTL_ARGS)
292{ 173{
174 DRM_DEVICE;
175 drm_via_private_t *dev_priv = dev->dev_private;
293 drm_via_mem_t mem; 176 drm_via_mem_t mem;
177 int ret;
294 178
295 DRM_COPY_FROM_USER_IOCTL(mem, (drm_via_mem_t __user *) data, 179 DRM_COPY_FROM_USER_IOCTL(mem, (drm_via_mem_t __user *) data,
296 sizeof(mem)); 180 sizeof(mem));
297 181
298 switch (mem.type) { 182 mutex_lock(&dev->struct_mutex);
183 ret = drm_sman_free_key(&dev_priv->sman, mem.index);
184 mutex_unlock(&dev->struct_mutex);
185 DRM_DEBUG("free = 0x%lx\n", mem.index);
299 186
300 case VIA_MEM_VIDEO: 187 return ret;
301 if (via_fb_free(&mem) == 0)
302 return 0;
303 break;
304 case VIA_MEM_AGP:
305 if (via_agp_free(&mem) == 0)
306 return 0;
307 break;
308 }
309
310 return -EFAULT;
311} 188}
312 189
313static int via_fb_free(drm_via_mem_t * mem)
314{
315 drm_via_mm_t fb;
316 int retval = 0;
317
318 if (!FBHeap) {
319 return -1;
320 }
321
322 fb.free = mem->index;
323 fb.context = mem->context;
324
325 if (!fb.free) {
326 return -1;
327
328 }
329
330 via_mmFreeMem((PMemBlock) fb.free);
331
332 if (!del_alloc_set(fb.context, VIA_MEM_VIDEO, fb.free)) {
333 retval = -1;
334 }
335
336 DRM_DEBUG("free fb, free = %ld\n", fb.free);
337 190
338 return retval; 191void via_reclaim_buffers_locked(drm_device_t * dev, struct file *filp)
339}
340
341static int via_agp_free(drm_via_mem_t * mem)
342{ 192{
343 drm_via_mm_t agp; 193 drm_via_private_t *dev_priv = dev->dev_private;
344 194 drm_file_t *priv = filp->private_data;
345 int retval = 0;
346 195
347 agp.free = mem->index; 196 mutex_lock(&dev->struct_mutex);
348 agp.context = mem->context; 197 if (drm_sman_owner_clean(&dev_priv->sman, (unsigned long)priv)) {
349 198 mutex_unlock(&dev->struct_mutex);
350 if (!agp.free) 199 return;
351 return -1;
352
353 via_mmFreeMem((PMemBlock) agp.free);
354
355 if (!del_alloc_set(agp.context, VIA_MEM_AGP, agp.free)) {
356 retval = -1;
357 } 200 }
358 201
359 DRM_DEBUG("free agp, free = %ld\n", agp.free); 202 if (dev->driver->dma_quiescent) {
203 dev->driver->dma_quiescent(dev);
204 }
360 205
361 return retval; 206 drm_sman_owner_cleanup(&dev_priv->sman, (unsigned long)priv);
207 mutex_unlock(&dev->struct_mutex);
208 return;
362} 209}
diff --git a/drivers/char/ds1286.c b/drivers/char/ds1286.c
index 21c8229f5443..6d58b0370802 100644
--- a/drivers/char/ds1286.c
+++ b/drivers/char/ds1286.c
@@ -104,7 +104,7 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
104 switch (cmd) { 104 switch (cmd) {
105 case RTC_AIE_OFF: /* Mask alarm int. enab. bit */ 105 case RTC_AIE_OFF: /* Mask alarm int. enab. bit */
106 { 106 {
107 unsigned int flags; 107 unsigned long flags;
108 unsigned char val; 108 unsigned char val;
109 109
110 if (!capable(CAP_SYS_TIME)) 110 if (!capable(CAP_SYS_TIME))
@@ -120,7 +120,7 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
120 } 120 }
121 case RTC_AIE_ON: /* Allow alarm interrupts. */ 121 case RTC_AIE_ON: /* Allow alarm interrupts. */
122 { 122 {
123 unsigned int flags; 123 unsigned long flags;
124 unsigned char val; 124 unsigned char val;
125 125
126 if (!capable(CAP_SYS_TIME)) 126 if (!capable(CAP_SYS_TIME))
@@ -136,7 +136,7 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
136 } 136 }
137 case RTC_WIE_OFF: /* Mask watchdog int. enab. bit */ 137 case RTC_WIE_OFF: /* Mask watchdog int. enab. bit */
138 { 138 {
139 unsigned int flags; 139 unsigned long flags;
140 unsigned char val; 140 unsigned char val;
141 141
142 if (!capable(CAP_SYS_TIME)) 142 if (!capable(CAP_SYS_TIME))
@@ -152,7 +152,7 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
152 } 152 }
153 case RTC_WIE_ON: /* Allow watchdog interrupts. */ 153 case RTC_WIE_ON: /* Allow watchdog interrupts. */
154 { 154 {
155 unsigned int flags; 155 unsigned long flags;
156 unsigned char val; 156 unsigned char val;
157 157
158 if (!capable(CAP_SYS_TIME)) 158 if (!capable(CAP_SYS_TIME))
@@ -434,7 +434,7 @@ static inline unsigned char ds1286_is_updating(void)
434static void ds1286_get_time(struct rtc_time *rtc_tm) 434static void ds1286_get_time(struct rtc_time *rtc_tm)
435{ 435{
436 unsigned char save_control; 436 unsigned char save_control;
437 unsigned int flags; 437 unsigned long flags;
438 unsigned long uip_watchdog = jiffies; 438 unsigned long uip_watchdog = jiffies;
439 439
440 /* 440 /*
@@ -494,7 +494,8 @@ static int ds1286_set_time(struct rtc_time *rtc_tm)
494{ 494{
495 unsigned char mon, day, hrs, min, sec, leap_yr; 495 unsigned char mon, day, hrs, min, sec, leap_yr;
496 unsigned char save_control; 496 unsigned char save_control;
497 unsigned int yrs, flags; 497 unsigned int yrs;
498 unsigned long flags;
498 499
499 500
500 yrs = rtc_tm->tm_year + 1900; 501 yrs = rtc_tm->tm_year + 1900;
@@ -552,7 +553,7 @@ static int ds1286_set_time(struct rtc_time *rtc_tm)
552static void ds1286_get_alm_time(struct rtc_time *alm_tm) 553static void ds1286_get_alm_time(struct rtc_time *alm_tm)
553{ 554{
554 unsigned char cmd; 555 unsigned char cmd;
555 unsigned int flags; 556 unsigned long flags;
556 557
557 /* 558 /*
558 * Only the values that we read from the RTC are set. That 559 * Only the values that we read from the RTC are set. That
diff --git a/drivers/char/dsp56k.c b/drivers/char/dsp56k.c
index 9b1bf60ffbe7..06f2dbf17710 100644
--- a/drivers/char/dsp56k.c
+++ b/drivers/char/dsp56k.c
@@ -201,7 +201,7 @@ static int dsp56k_upload(u_char __user *bin, int len)
201static ssize_t dsp56k_read(struct file *file, char __user *buf, size_t count, 201static ssize_t dsp56k_read(struct file *file, char __user *buf, size_t count,
202 loff_t *ppos) 202 loff_t *ppos)
203{ 203{
204 struct inode *inode = file->f_dentry->d_inode; 204 struct inode *inode = file->f_path.dentry->d_inode;
205 int dev = iminor(inode) & 0x0f; 205 int dev = iminor(inode) & 0x0f;
206 206
207 switch(dev) 207 switch(dev)
@@ -264,7 +264,7 @@ static ssize_t dsp56k_read(struct file *file, char __user *buf, size_t count,
264static ssize_t dsp56k_write(struct file *file, const char __user *buf, size_t count, 264static ssize_t dsp56k_write(struct file *file, const char __user *buf, size_t count,
265 loff_t *ppos) 265 loff_t *ppos)
266{ 266{
267 struct inode *inode = file->f_dentry->d_inode; 267 struct inode *inode = file->f_path.dentry->d_inode;
268 int dev = iminor(inode) & 0x0f; 268 int dev = iminor(inode) & 0x0f;
269 269
270 switch(dev) 270 switch(dev)
@@ -420,7 +420,7 @@ static int dsp56k_ioctl(struct inode *inode, struct file *file,
420#if 0 420#if 0
421static unsigned int dsp56k_poll(struct file *file, poll_table *wait) 421static unsigned int dsp56k_poll(struct file *file, poll_table *wait)
422{ 422{
423 int dev = iminor(file->f_dentry->d_inode) & 0x0f; 423 int dev = iminor(file->f_path.dentry->d_inode) & 0x0f;
424 424
425 switch(dev) 425 switch(dev)
426 { 426 {
diff --git a/drivers/char/dtlk.c b/drivers/char/dtlk.c
index 5e82c3bad2e3..d4005e94fe5f 100644
--- a/drivers/char/dtlk.c
+++ b/drivers/char/dtlk.c
@@ -122,7 +122,7 @@ static void dtlk_timer_tick(unsigned long data);
122static ssize_t dtlk_read(struct file *file, char __user *buf, 122static ssize_t dtlk_read(struct file *file, char __user *buf,
123 size_t count, loff_t * ppos) 123 size_t count, loff_t * ppos)
124{ 124{
125 unsigned int minor = iminor(file->f_dentry->d_inode); 125 unsigned int minor = iminor(file->f_path.dentry->d_inode);
126 char ch; 126 char ch;
127 int i = 0, retries; 127 int i = 0, retries;
128 128
@@ -174,7 +174,7 @@ static ssize_t dtlk_write(struct file *file, const char __user *buf,
174 } 174 }
175#endif 175#endif
176 176
177 if (iminor(file->f_dentry->d_inode) != DTLK_MINOR) 177 if (iminor(file->f_path.dentry->d_inode) != DTLK_MINOR)
178 return -EINVAL; 178 return -EINVAL;
179 179
180 while (1) { 180 while (1) {
diff --git a/drivers/char/ec3104_keyb.c b/drivers/char/ec3104_keyb.c
index abac18b1871c..77f58ed6d59a 100644
--- a/drivers/char/ec3104_keyb.c
+++ b/drivers/char/ec3104_keyb.c
@@ -370,7 +370,7 @@ static void e5_receive(struct e5_struct *k)
370 } 370 }
371} 371}
372 372
373static void ec3104_keyb_interrupt(int irq, void *data, struct pt_regs *regs) 373static void ec3104_keyb_interrupt(int irq, void *data)
374{ 374{
375 struct e5_struct *k = &ec3104_keyb; 375 struct e5_struct *k = &ec3104_keyb;
376 u8 msr, lsr; 376 u8 msr, lsr;
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index 86d290e9f307..a0f822c9d74d 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -199,8 +199,8 @@ static int pc_ioctl(struct tty_struct *, struct file *,
199 unsigned int, unsigned long); 199 unsigned int, unsigned long);
200static int info_ioctl(struct tty_struct *, struct file *, 200static int info_ioctl(struct tty_struct *, struct file *,
201 unsigned int, unsigned long); 201 unsigned int, unsigned long);
202static void pc_set_termios(struct tty_struct *, struct termios *); 202static void pc_set_termios(struct tty_struct *, struct ktermios *);
203static void do_softint(void *); 203static void do_softint(struct work_struct *work);
204static void pc_stop(struct tty_struct *); 204static void pc_stop(struct tty_struct *);
205static void pc_start(struct tty_struct *); 205static void pc_start(struct tty_struct *);
206static void pc_throttle(struct tty_struct * tty); 206static void pc_throttle(struct tty_struct * tty);
@@ -1113,11 +1113,8 @@ static void __exit epca_module_exit(void)
1113 ch = card_ptr[crd]; 1113 ch = card_ptr[crd];
1114 for (count = 0; count < bd->numports; count++, ch++) 1114 for (count = 0; count < bd->numports; count++, ch++)
1115 { /* Begin for each port */ 1115 { /* Begin for each port */
1116 if (ch) { 1116 if (ch && ch->tty)
1117 if (ch->tty) 1117 tty_hangup(ch->tty);
1118 tty_hangup(ch->tty);
1119 kfree(ch->tmp_buf);
1120 }
1121 } /* End for each port */ 1118 } /* End for each port */
1122 } /* End for each card */ 1119 } /* End for each card */
1123 pci_unregister_driver (&epca_driver); 1120 pci_unregister_driver (&epca_driver);
@@ -1125,7 +1122,7 @@ static void __exit epca_module_exit(void)
1125 1122
1126module_exit(epca_module_exit); 1123module_exit(epca_module_exit);
1127 1124
1128static struct tty_operations pc_ops = { 1125static const struct tty_operations pc_ops = {
1129 .open = pc_open, 1126 .open = pc_open,
1130 .close = pc_close, 1127 .close = pc_close,
1131 .write = pc_write, 1128 .write = pc_write,
@@ -1160,6 +1157,7 @@ static int __init pc_init(void)
1160 int crd; 1157 int crd;
1161 struct board_info *bd; 1158 struct board_info *bd;
1162 unsigned char board_id = 0; 1159 unsigned char board_id = 0;
1160 int err = -ENOMEM;
1163 1161
1164 int pci_boards_found, pci_count; 1162 int pci_boards_found, pci_count;
1165 1163
@@ -1167,13 +1165,11 @@ static int __init pc_init(void)
1167 1165
1168 pc_driver = alloc_tty_driver(MAX_ALLOC); 1166 pc_driver = alloc_tty_driver(MAX_ALLOC);
1169 if (!pc_driver) 1167 if (!pc_driver)
1170 return -ENOMEM; 1168 goto out1;
1171 1169
1172 pc_info = alloc_tty_driver(MAX_ALLOC); 1170 pc_info = alloc_tty_driver(MAX_ALLOC);
1173 if (!pc_info) { 1171 if (!pc_info)
1174 put_tty_driver(pc_driver); 1172 goto out2;
1175 return -ENOMEM;
1176 }
1177 1173
1178 /* ----------------------------------------------------------------------- 1174 /* -----------------------------------------------------------------------
1179 If epca_setup has not been ran by LILO set num_cards to defaults; copy 1175 If epca_setup has not been ran by LILO set num_cards to defaults; copy
@@ -1240,6 +1236,8 @@ static int __init pc_init(void)
1240 pc_driver->init_termios.c_oflag = 0; 1236 pc_driver->init_termios.c_oflag = 0;
1241 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; 1237 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1242 pc_driver->init_termios.c_lflag = 0; 1238 pc_driver->init_termios.c_lflag = 0;
1239 pc_driver->init_termios.c_ispeed = 9600;
1240 pc_driver->init_termios.c_ospeed = 9600;
1243 pc_driver->flags = TTY_DRIVER_REAL_RAW; 1241 pc_driver->flags = TTY_DRIVER_REAL_RAW;
1244 tty_set_operations(pc_driver, &pc_ops); 1242 tty_set_operations(pc_driver, &pc_ops);
1245 1243
@@ -1254,6 +1252,8 @@ static int __init pc_init(void)
1254 pc_info->init_termios.c_oflag = 0; 1252 pc_info->init_termios.c_oflag = 0;
1255 pc_info->init_termios.c_lflag = 0; 1253 pc_info->init_termios.c_lflag = 0;
1256 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL; 1254 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1255 pc_info->init_termios.c_ispeed = 9600;
1256 pc_info->init_termios.c_ospeed = 9600;
1257 pc_info->flags = TTY_DRIVER_REAL_RAW; 1257 pc_info->flags = TTY_DRIVER_REAL_RAW;
1258 tty_set_operations(pc_info, &info_ops); 1258 tty_set_operations(pc_info, &info_ops);
1259 1259
@@ -1373,11 +1373,17 @@ static int __init pc_init(void)
1373 1373
1374 } /* End for each card */ 1374 } /* End for each card */
1375 1375
1376 if (tty_register_driver(pc_driver)) 1376 err = tty_register_driver(pc_driver);
1377 panic("Couldn't register Digi PC/ driver"); 1377 if (err) {
1378 printk(KERN_ERR "Couldn't register Digi PC/ driver");
1379 goto out3;
1380 }
1378 1381
1379 if (tty_register_driver(pc_info)) 1382 err = tty_register_driver(pc_info);
1380 panic("Couldn't register Digi PC/ info "); 1383 if (err) {
1384 printk(KERN_ERR "Couldn't register Digi PC/ info ");
1385 goto out4;
1386 }
1381 1387
1382 /* ------------------------------------------------------------------- 1388 /* -------------------------------------------------------------------
1383 Start up the poller to check for events on all enabled boards 1389 Start up the poller to check for events on all enabled boards
@@ -1388,6 +1394,15 @@ static int __init pc_init(void)
1388 mod_timer(&epca_timer, jiffies + HZ/25); 1394 mod_timer(&epca_timer, jiffies + HZ/25);
1389 return 0; 1395 return 0;
1390 1396
1397out4:
1398 tty_unregister_driver(pc_driver);
1399out3:
1400 put_tty_driver(pc_info);
1401out2:
1402 put_tty_driver(pc_driver);
1403out1:
1404 return err;
1405
1391} /* End pc_init */ 1406} /* End pc_init */
1392 1407
1393/* ------------------ Begin post_fep_init ---------------------- */ 1408/* ------------------ Begin post_fep_init ---------------------- */
@@ -1494,7 +1509,7 @@ static void post_fep_init(unsigned int crd)
1494 1509
1495 ch->brdchan = bc; 1510 ch->brdchan = bc;
1496 ch->mailbox = gd; 1511 ch->mailbox = gd;
1497 INIT_WORK(&ch->tqueue, do_softint, ch); 1512 INIT_WORK(&ch->tqueue, do_softint);
1498 ch->board = &boards[crd]; 1513 ch->board = &boards[crd];
1499 1514
1500 spin_lock_irqsave(&epca_lock, flags); 1515 spin_lock_irqsave(&epca_lock, flags);
@@ -1635,16 +1650,6 @@ static void post_fep_init(unsigned int crd)
1635 init_waitqueue_head(&ch->close_wait); 1650 init_waitqueue_head(&ch->close_wait);
1636 1651
1637 spin_unlock_irqrestore(&epca_lock, flags); 1652 spin_unlock_irqrestore(&epca_lock, flags);
1638
1639 ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL);
1640 if (!ch->tmp_buf) {
1641 printk(KERN_ERR "POST FEP INIT : kmalloc failed for port 0x%x\n",i);
1642 release_region((int)bd->port, 4);
1643 while(i-- > 0)
1644 kfree((ch--)->tmp_buf);
1645 return;
1646 } else
1647 memset((void *)ch->tmp_buf,0,ch->txbufsize);
1648 } /* End for each port */ 1653 } /* End for each port */
1649 1654
1650 printk(KERN_INFO 1655 printk(KERN_INFO
@@ -1998,7 +2003,7 @@ static void epcaparam(struct tty_struct *tty, struct channel *ch)
1998{ /* Begin epcaparam */ 2003{ /* Begin epcaparam */
1999 2004
2000 unsigned int cmdHead; 2005 unsigned int cmdHead;
2001 struct termios *ts; 2006 struct ktermios *ts;
2002 struct board_chan __iomem *bc; 2007 struct board_chan __iomem *bc;
2003 unsigned mval, hflow, cflag, iflag; 2008 unsigned mval, hflow, cflag, iflag;
2004 2009
@@ -2113,7 +2118,7 @@ static void receive_data(struct channel *ch)
2113{ /* Begin receive_data */ 2118{ /* Begin receive_data */
2114 2119
2115 unchar *rptr; 2120 unchar *rptr;
2116 struct termios *ts = NULL; 2121 struct ktermios *ts = NULL;
2117 struct tty_struct *tty; 2122 struct tty_struct *tty;
2118 struct board_chan __iomem *bc; 2123 struct board_chan __iomem *bc;
2119 int dataToRead, wrapgap, bytesAvailable; 2124 int dataToRead, wrapgap, bytesAvailable;
@@ -2361,12 +2366,14 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2361 switch (cmd) 2366 switch (cmd)
2362 { /* Begin switch cmd */ 2367 { /* Begin switch cmd */
2363 2368
2369#if 0 /* Handled by calling layer properly */
2364 case TCGETS: 2370 case TCGETS:
2365 if (copy_to_user(argp, tty->termios, sizeof(struct termios))) 2371 if (copy_to_user(argp, tty->termios, sizeof(struct ktermios)))
2366 return -EFAULT; 2372 return -EFAULT;
2367 return 0; 2373 return 0;
2368 case TCGETA: 2374 case TCGETA:
2369 return get_termio(tty, argp); 2375 return get_termio(tty, argp);
2376#endif
2370 case TCSBRK: /* SVID version: non-zero arg --> no break */ 2377 case TCSBRK: /* SVID version: non-zero arg --> no break */
2371 retval = tty_check_change(tty); 2378 retval = tty_check_change(tty);
2372 if (retval) 2379 if (retval)
@@ -2535,7 +2542,7 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2535 2542
2536/* --------------------- Begin pc_set_termios ----------------------- */ 2543/* --------------------- Begin pc_set_termios ----------------------- */
2537 2544
2538static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios) 2545static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2539{ /* Begin pc_set_termios */ 2546{ /* Begin pc_set_termios */
2540 2547
2541 struct channel *ch; 2548 struct channel *ch;
@@ -2565,9 +2572,9 @@ static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
2565 2572
2566/* --------------------- Begin do_softint ----------------------- */ 2573/* --------------------- Begin do_softint ----------------------- */
2567 2574
2568static void do_softint(void *private_) 2575static void do_softint(struct work_struct *work)
2569{ /* Begin do_softint */ 2576{ /* Begin do_softint */
2570 struct channel *ch = (struct channel *) private_; 2577 struct channel *ch = container_of(work, struct channel, tqueue);
2571 /* Called in response to a modem change event */ 2578 /* Called in response to a modem change event */
2572 if (ch && ch->magic == EPCA_MAGIC) { /* Begin EPCA_MAGIC */ 2579 if (ch && ch->magic == EPCA_MAGIC) { /* Begin EPCA_MAGIC */
2573 struct tty_struct *tty = ch->tty; 2580 struct tty_struct *tty = ch->tty;
diff --git a/drivers/char/epca.h b/drivers/char/epca.h
index 456d6c8f94a8..a297238cd3ba 100644
--- a/drivers/char/epca.h
+++ b/drivers/char/epca.h
@@ -130,7 +130,6 @@ struct channel
130 unsigned long c_oflag; 130 unsigned long c_oflag;
131 unsigned char __iomem *txptr; 131 unsigned char __iomem *txptr;
132 unsigned char __iomem *rxptr; 132 unsigned char __iomem *rxptr;
133 unsigned char *tmp_buf;
134 struct board_info *board; 133 struct board_info *board;
135 struct board_chan __iomem *brdchan; 134 struct board_chan __iomem *brdchan;
136 struct digi_struct digiext; 135 struct digi_struct digiext;
diff --git a/drivers/char/esp.c b/drivers/char/esp.c
index afcd83d9984b..d1bfbaa2aa02 100644
--- a/drivers/char/esp.c
+++ b/drivers/char/esp.c
@@ -615,8 +615,7 @@ static inline void check_modem_status(struct esp_struct *info)
615/* 615/*
616 * This is the serial driver's interrupt routine 616 * This is the serial driver's interrupt routine
617 */ 617 */
618static irqreturn_t rs_interrupt_single(int irq, void *dev_id, 618static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
619 struct pt_regs *regs)
620{ 619{
621 struct esp_struct * info; 620 struct esp_struct * info;
622 unsigned err_status; 621 unsigned err_status;
@@ -724,9 +723,10 @@ static irqreturn_t rs_interrupt_single(int irq, void *dev_id,
724 * ------------------------------------------------------------------- 723 * -------------------------------------------------------------------
725 */ 724 */
726 725
727static void do_softint(void *private_) 726static void do_softint(struct work_struct *work)
728{ 727{
729 struct esp_struct *info = (struct esp_struct *) private_; 728 struct esp_struct *info =
729 container_of(work, struct esp_struct, tqueue);
730 struct tty_struct *tty; 730 struct tty_struct *tty;
731 731
732 tty = info->tty; 732 tty = info->tty;
@@ -747,9 +747,10 @@ static void do_softint(void *private_)
747 * do_serial_hangup() -> tty->hangup() -> esp_hangup() 747 * do_serial_hangup() -> tty->hangup() -> esp_hangup()
748 * 748 *
749 */ 749 */
750static void do_serial_hangup(void *private_) 750static void do_serial_hangup(struct work_struct *work)
751{ 751{
752 struct esp_struct *info = (struct esp_struct *) private_; 752 struct esp_struct *info =
753 container_of(work, struct esp_struct, tqueue_hangup);
753 struct tty_struct *tty; 754 struct tty_struct *tty;
754 755
755 tty = info->tty; 756 tty = info->tty;
@@ -1914,7 +1915,7 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file,
1914 return 0; 1915 return 0;
1915} 1916}
1916 1917
1917static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios) 1918static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1918{ 1919{
1919 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1920 struct esp_struct *info = (struct esp_struct *)tty->driver_data;
1920 unsigned long flags; 1921 unsigned long flags;
@@ -2376,7 +2377,7 @@ static inline int autoconfig(struct esp_struct * info)
2376 return (port_detected); 2377 return (port_detected);
2377} 2378}
2378 2379
2379static struct tty_operations esp_ops = { 2380static const struct tty_operations esp_ops = {
2380 .open = esp_open, 2381 .open = esp_open,
2381 .close = rs_close, 2382 .close = rs_close,
2382 .write = rs_write, 2383 .write = rs_write,
@@ -2502,8 +2503,8 @@ static int __init espserial_init(void)
2502 info->magic = ESP_MAGIC; 2503 info->magic = ESP_MAGIC;
2503 info->close_delay = 5*HZ/10; 2504 info->close_delay = 5*HZ/10;
2504 info->closing_wait = 30*HZ; 2505 info->closing_wait = 30*HZ;
2505 INIT_WORK(&info->tqueue, do_softint, info); 2506 INIT_WORK(&info->tqueue, do_softint);
2506 INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info); 2507 INIT_WORK(&info->tqueue_hangup, do_serial_hangup);
2507 info->config.rx_timeout = rx_timeout; 2508 info->config.rx_timeout = rx_timeout;
2508 info->config.flow_on = flow_on; 2509 info->config.flow_on = flow_on;
2509 info->config.flow_off = flow_off; 2510 info->config.flow_off = flow_off;
diff --git a/drivers/char/ftape/Kconfig b/drivers/char/ftape/Kconfig
deleted file mode 100644
index 0d65189a7ae8..000000000000
--- a/drivers/char/ftape/Kconfig
+++ /dev/null
@@ -1,330 +0,0 @@
1#
2# Ftape configuration
3#
4config ZFTAPE
5 tristate "Zftape, the VFS interface"
6 depends on FTAPE
7 ---help---
8 Normally, you want to say Y or M. DON'T say N here or you
9 WON'T BE ABLE TO USE YOUR FLOPPY TAPE DRIVE.
10
11 The ftape module itself no longer contains the routines necessary
12 to interface with the kernel VFS layer (i.e. to actually write data
13 to and read data from the tape drive). Instead the file system
14 interface (i.e. the hardware independent part of the driver) has
15 been moved to a separate module.
16
17 To compile this driver as a module, choose M here: the
18 module will be called zftape.
19
20 Regardless of whether you say Y or M here, an additional runtime
21 loadable module called `zft-compressor' which contains code to
22 support user transparent on-the-fly compression based on Ross
23 William's lzrw3 algorithm will be produced. If you have enabled the
24 kernel module loader (i.e. have said Y to "Kernel module loader
25 support", above) then `zft-compressor' will be loaded
26 automatically by zftape when needed.
27
28 Despite its name, zftape does NOT use compression by default.
29
30config ZFT_DFLT_BLK_SZ
31 int "Default block size"
32 depends on ZFTAPE
33 default "10240"
34 ---help---
35 If unsure leave this at its default value, i.e. 10240. Note that
36 you specify only the default block size here. The block size can be
37 changed at run time using the MTSETBLK tape operation with the
38 MTIOCTOP ioctl (i.e. with "mt -f /dev/qft0 setblk #BLKSZ" from the
39 shell command line).
40
41 The probably most striking difference between zftape and previous
42 versions of ftape is the fact that all data must be written or read
43 in multiples of a fixed block size. The block size defaults to
44 10240 which is what GNU tar uses. The values for the block size
45 should be either 1 or multiples of 1024 up to a maximum value of
46 63488 (i.e. 62 K). If you specify `1' then zftape's builtin
47 compression will be disabled.
48
49 Reasonable values are `10240' (GNU tar's default block size),
50 `5120' (afio's default block size), `32768' (default block size some
51 backup programs assume for SCSI tape drives) or `1' (no restriction
52 on block size, but disables builtin compression).
53
54comment "The compressor will be built as a module only!"
55 depends on FTAPE && ZFTAPE
56
57config ZFT_COMPRESSOR
58 tristate
59 depends on FTAPE!=n && ZFTAPE!=n
60 default m
61
62config FT_NR_BUFFERS
63 int "Number of ftape buffers (EXPERIMENTAL)"
64 depends on FTAPE && EXPERIMENTAL
65 default "3"
66 help
67 Please leave this at `3' unless you REALLY know what you are doing.
68 It is not necessary to change this value. Values below 3 make the
69 proper use of ftape impossible, values greater than 3 are a waste of
70 memory. You can change the amount of DMA memory used by ftape at
71 runtime with "mt -f /dev/qft0 setdrvbuffer #NUMBUFFERS". Each buffer
72 wastes 32 KB of memory. Please note that this memory cannot be
73 swapped out.
74
75config FT_PROC_FS
76 bool "Enable procfs status report (+2kb)"
77 depends on FTAPE && PROC_FS
78 ---help---
79 Optional. Saying Y will result in creation of a directory
80 `/proc/ftape' under the /proc file system. The files can be viewed
81 with your favorite pager (i.e. use "more /proc/ftape/history" or
82 "less /proc/ftape/history" or simply "cat /proc/ftape/history"). The
83 file will contain some status information about the inserted
84 cartridge, the kernel driver, your tape drive, the floppy disk
85 controller and the error history for the most recent use of the
86 kernel driver. Saying Y will enlarge the size of the ftape driver
87 by approximately 2 KB.
88
89 WARNING: When compiling ftape as a module (i.e. saying M to "Floppy
90 tape drive") it is dangerous to use ftape's /proc file system
91 interface. Accessing `/proc/ftape' while the module is unloaded will
92 result in a kernel Oops. This cannot be fixed from inside ftape.
93
94choice
95 prompt "Debugging output"
96 depends on FTAPE
97 default FT_NORMAL_DEBUG
98
99config FT_NORMAL_DEBUG
100 bool "Normal"
101 ---help---
102 This option controls the amount of debugging output the ftape driver
103 is ABLE to produce; it does not increase or diminish the debugging
104 level itself. If unsure, leave this at its default setting,
105 i.e. choose "Normal".
106
107 Ftape can print lots of debugging messages to the system console
108 resp. kernel log files. Reducing the amount of possible debugging
109 output reduces the size of the kernel module by some KB, so it might
110 be a good idea to use "None" for emergency boot floppies.
111
112 If you want to save memory then the following strategy is
113 recommended: leave this option at its default setting "Normal" until
114 you know that the driver works as expected, afterwards reconfigure
115 the kernel, this time specifying "Reduced" or "None" and recompile
116 and install the kernel as usual. Note that choosing "Excessive"
117 debugging output does not increase the amount of debugging output
118 printed to the console but only makes it possible to produce
119 "Excessive" debugging output.
120
121 Please read <file:Documentation/ftape.txt> for a short description
122 how to control the amount of debugging output.
123
124config FT_FULL_DEBUG
125 bool "Excessive"
126 help
127 Extremely verbose output for driver debugging purposes.
128
129config FT_NO_TRACE
130 bool "Reduced"
131 help
132 Reduced tape driver debugging output.
133
134config FT_NO_TRACE_AT_ALL
135 bool "None"
136 help
137 Suppress all debugging output from the tape drive.
138
139endchoice
140
141comment "Hardware configuration"
142 depends on FTAPE
143
144choice
145 prompt "Floppy tape controllers"
146 depends on FTAPE
147 default FT_STD_FDC
148
149config FT_STD_FDC
150 bool "Standard"
151 ---help---
152 Only change this setting if you have a special controller. If you
153 didn't plug any add-on card into your computer system but just
154 plugged the floppy tape cable into the already existing floppy drive
155 controller then you don't want to change the default setting,
156 i.e. choose "Standard".
157
158 Choose "MACH-2" if you have a Mountain Mach-2 controller.
159 Choose "FC-10/FC-20" if you have a Colorado FC-10 or FC-20
160 controller.
161 Choose "Alt/82078" if you have another controller that is located at
162 an IO base address different from the standard floppy drive
163 controller's base address of `0x3f0', or uses an IRQ (interrupt)
164 channel different from `6', or a DMA channel different from
165 `2'. This is necessary for any controller card that is based on
166 Intel's 82078 FDC such as Seagate's, Exabyte's and Iomega's "high
167 speed" controllers.
168
169 If you choose something other than "Standard" then please make
170 sure that the settings for the IO base address and the IRQ and DMA
171 channel in the configuration menus below are correct. Use the manual
172 of your tape drive to determine the correct settings!
173
174 If you are already successfully using your tape drive with another
175 operating system then you definitely should use the same settings
176 for the IO base, the IRQ and DMA channel that have proven to work
177 with that other OS.
178
179 Note that this menu lets you specify only the default setting for
180 the hardware setup. The hardware configuration can be changed at
181 boot time (when ftape is compiled into the kernel, i.e. if you
182 have said Y to "Floppy tape drive") or module load time (i.e. if you
183 have said M to "Floppy tape drive").
184
185 Please read also the file <file:Documentation/ftape.txt> which
186 contains a short description of the parameters that can be set at
187 boot or load time. If you want to use your floppy tape drive on a
188 PCI-bus based system, please read the file
189 <file:drivers/char/ftape/README.PCI>.
190
191config FT_MACH2
192 bool "MACH-2"
193
194config FT_PROBE_FC10
195 bool "FC-10/FC-20"
196
197config FT_ALT_FDC
198 bool "Alt/82078"
199
200endchoice
201
202comment "Consult the manuals of your tape drive for the correct settings!"
203 depends on FTAPE && !FT_STD_FDC
204
205config FT_FDC_BASE
206 hex "IO base of the floppy disk controller"
207 depends on FTAPE && !FT_STD_FDC
208 default "0"
209 ---help---
210 You don't need to specify a value if the following default
211 settings for the base IO address are correct:
212 <<< MACH-2 : 0x1E0 >>>
213 <<< FC-10/FC-20: 0x180 >>>
214 <<< Secondary : 0x370 >>>
215 Secondary refers to a secondary FDC controller like the "high speed"
216 controllers delivered by Seagate or Exabyte or Iomega's Ditto Dash.
217 Please make sure that the setting for the IO base address
218 specified here is correct. USE THE MANUAL OF YOUR TAPE DRIVE OR
219 CONTROLLER CARD TO DETERMINE THE CORRECT SETTING. If you are already
220 successfully using the tape drive with another operating system then
221 you definitely should use the same settings for the IO base that has
222 proven to work with that other OS.
223
224 Note that this menu lets you specify only the default setting for
225 the IO base. The hardware configuration can be changed at boot time
226 (when ftape is compiled into the kernel, i.e. if you specified Y to
227 "Floppy tape drive") or module load time (i.e. if you have said M to
228 "Floppy tape drive").
229
230 Please read also the file <file:Documentation/ftape.txt> which
231 contains a short description of the parameters that can be set at
232 boot or load time.
233
234config FT_FDC_IRQ
235 int "IRQ channel of the floppy disk controller"
236 depends on FTAPE && !FT_STD_FDC
237 default "0"
238 ---help---
239 You don't need to specify a value if the following default
240 settings for the interrupt channel are correct:
241 <<< MACH-2 : 6 >>>
242 <<< FC-10/FC-20: 9 >>>
243 <<< Secondary : 6 >>>
244 Secondary refers to secondary a FDC controller like the "high speed"
245 controllers delivered by Seagate or Exabyte or Iomega's Ditto Dash.
246 Please make sure that the setting for the IO base address
247 specified here is correct. USE THE MANUAL OF YOUR TAPE DRIVE OR
248 CONTROLLER CARD TO DETERMINE THE CORRECT SETTING. If you are already
249 successfully using the tape drive with another operating system then
250 you definitely should use the same settings for the IO base that has
251 proven to work with that other OS.
252
253 Note that this menu lets you specify only the default setting for
254 the IRQ channel. The hardware configuration can be changed at boot
255 time (when ftape is compiled into the kernel, i.e. if you said Y to
256 "Floppy tape drive") or module load time (i.e. if you said M to
257 "Floppy tape drive").
258
259 Please read also the file <file:Documentation/ftape.txt> which
260 contains a short description of the parameters that can be set at
261 boot or load time.
262
263config FT_FDC_DMA
264 int "DMA channel of the floppy disk controller"
265 depends on FTAPE && !FT_STD_FDC
266 default "0"
267 ---help---
268 You don't need to specify a value if the following default
269 settings for the DMA channel are correct:
270 <<< MACH-2 : 2 >>>
271 <<< FC-10/FC-20: 3 >>>
272 <<< Secondary : 2 >>>
273 Secondary refers to a secondary FDC controller like the "high speed"
274 controllers delivered by Seagate or Exabyte or Iomega's Ditto Dash.
275 Please make sure that the setting for the IO base address
276 specified here is correct. USE THE MANUAL OF YOUR TAPE DRIVE OR
277 CONTROLLER CARD TO DETERMINE THE CORRECT SETTING. If you are already
278 successfully using the tape drive with another operating system then
279 you definitely should use the same settings for the IO base that has
280 proven to work with that other OS.
281
282 Note that this menu lets you specify only the default setting for
283 the DMA channel. The hardware configuration can be changed at boot
284 time (when ftape is compiled into the kernel, i.e. if you said Y to
285 "Floppy tape drive") or module load time (i.e. if you said M to
286 "Floppy tape drive").
287
288 Please read also the file <file:Documentation/ftape.txt> which
289 contains a short description of the parameters that can be set at
290 boot or load time.
291
292config FT_FDC_THR
293 int "Default FIFO threshold (EXPERIMENTAL)"
294 depends on FTAPE && EXPERIMENTAL
295 default "8"
296 help
297 Set the FIFO threshold of the FDC. If this is higher the DMA
298 controller may serve the FDC after a higher latency time. If this is
299 lower, fewer DMA transfers occur leading to less bus contention.
300 You may try to tune this if ftape annoys you with "reduced data
301 rate because of excessive overrun errors" messages. However, this
302 doesn't seem to have too much effect.
303
304 If unsure, don't touch the initial value, i.e. leave it at "8".
305
306config FT_FDC_MAX_RATE
307 int "Maximal data rate to use (EXPERIMENTAL)"
308 depends on FTAPE && EXPERIMENTAL
309 default "2000"
310 ---help---
311 With some motherboard/FDC combinations ftape will not be able to
312 run your FDC/tape drive combination at the highest available
313 speed. If this is the case you'll encounter "reduced data rate
314 because of excessive overrun errors" messages and lots of retries
315 before ftape finally decides to reduce the data rate.
316
317 In this case it might be desirable to tell ftape beforehand that
318 it need not try to run the tape drive at the highest available
319 speed. If unsure, leave this disabled, i.e. leave it at 2000
320 bits/sec.
321
322config FT_ALPHA_CLOCK
323 int "CPU clock frequency of your DEC Alpha" if ALPHA
324 depends on FTAPE
325 default "0"
326 help
327 On some DEC Alpha machines the CPU clock frequency cannot be
328 determined automatically, so you need to specify it here ONLY if
329 running a DEC Alpha, otherwise this setting has no effect.
330
diff --git a/drivers/char/ftape/Makefile b/drivers/char/ftape/Makefile
deleted file mode 100644
index 0e67d2f8b7ec..000000000000
--- a/drivers/char/ftape/Makefile
+++ /dev/null
@@ -1,28 +0,0 @@
1#
2# Copyright (C) 1997 Claus Heine.
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2, or (at your option)
7# any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; see the file COPYING. If not, write to
16# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17#
18# $Source: /homes/cvs/ftape-stacked/ftape/Makefile,v $
19# $Revision: 1.4 $
20# $Date: 1997/10/05 19:17:56 $
21#
22# Makefile for the QIC-40/80/3010/3020 floppy-tape driver for
23# Linux.
24#
25
26obj-$(CONFIG_FTAPE) += lowlevel/
27obj-$(CONFIG_ZFTAPE) += zftape/
28obj-$(CONFIG_ZFT_COMPRESSOR) += compressor/
diff --git a/drivers/char/ftape/README.PCI b/drivers/char/ftape/README.PCI
deleted file mode 100644
index 18de159d36e0..000000000000
--- a/drivers/char/ftape/README.PCI
+++ /dev/null
@@ -1,81 +0,0 @@
1Some notes for ftape users with PCI motherboards:
2=================================================
3
4The problem:
5------------
6
7There have been some problem reports from people using PCI-bus based
8systems getting overrun errors.
9I wasn't able to reproduce these until I ran ftape on a Intel Plato
10(Premiere PCI II) motherboard with bios version 1.00.08AX1.
11It turned out that if GAT (Guaranteed Access Timing) is enabled (?)
12ftape gets a lot of overrun errors.
13The problem disappears when disabling GAT in the bios.
14Note that Intel removed this setting (permanently disabled) from the
151.00.10AX1 bios !
16
17It looks like that if GAT is enabled there are often large periods
18(greater than 120 us !??) on the ISA bus that the DMA controller cannot
19service the floppy disk controller.
20I cannot imagine this being acceptable in a decent PCI implementation.
21Maybe this is a `feature' of the chipset. I can only speculate why
22Intel choose to remove the option from the latest Bios...
23
24The lesson of this all is that there may be other motherboard
25implementations having the same of similar problems.
26If you experience a lot of overrun errors during a backup to tape,
27see if there is some setting in the Bios that may influence the
28bus timing.
29
30I judge this a hardware problem and not a limitation of ftape ;-)
31My DOS backup software seems to be suffering from the same problems
32and even refuses to run at 1 Mbps !
33Ftape will reduce the data-rate from 1 Mbps to 500 Kbps if the number
34of overrun errors on a track exceeds a threshold.
35
36
37Possible solutions:
38-------------------
39
40Some of the problems were solved by upgrading the (flash) bios.
41Other suggest that it has to do with the FDC being on the PCI
42bus, but that is not the case with the Intel Premiere II boards.
43[If upgrading the bios doesn't solve the problem you could try
44a floppy disk controller on the isa-bus].
45
46Here is a list of systems and recommended BIOS settings:
47
48
49 Intel Premiere PCI (Revenge):
50
51Bios version 1.00.09.AF2 is reported to work.
52
53
54
55 Intel Premiere PCI II (Plato):
56
57Bios version 1.00.10.AX1 and version 11 beta are ok.
58If using version 1.00.08.AX1, GAT must be disabled !
59
60
61
62 ASUS PCI/I-SP3G:
63
64Preferred settings: ISA-GAT-mode : disabled
65 DMA-linebuffer-mode : standard
66 ISA-masterbuffer-mode : standard
67
68
69 DELL Dimension XPS P90
70
71Bios version A2 is reported to be broken, while bios version A5 works.
72You can get a flash bios upgrade from http://www.dell.com
73
74
75To see if you're having the GAT problem, try making a backup
76under DOS. If it's very slow and often repositions you're
77probably having this problem.
78
79 --//--
80 LocalWords: ftape PCI bios GAT ISA DMA chipset Mbps Kbps FDC isa AF ok ASUS
81 LocalWords: SP linebuffer masterbuffer XPS http www com
diff --git a/drivers/char/ftape/RELEASE-NOTES b/drivers/char/ftape/RELEASE-NOTES
deleted file mode 100644
index 03799dbc05a4..000000000000
--- a/drivers/char/ftape/RELEASE-NOTES
+++ /dev/null
@@ -1,966 +0,0 @@
1Hey, Emacs, we're -*-Text-*- mode!
2
3===== Release notes for ftape-3.04d 25/11/97 =====
4- The correct pre-processor statement for "else if" is "#elif" not
5 "elsif".
6- Need to call zft_reset_position() when overwriting cartridges
7 previously written with ftape-2.x, sftape, or ancient
8 (pre-ftape-3.x) versions of zftape.
9
10===== Release notes for ftape-3.04c 16/11/97 =====
11- fdc_probe() was calling DUMPREGS with a result length of "1" which
12 was just fine. Undo previous change.
13
14===== Release notes for ftape-3.04b 14/11/97 =====
15
16- patches/2.x.x/floppy.c.diff was somewhat broken, releasing i/o
17 regions it never had allocated.
18- fdc_probe() was calling DUMPREGS with a result length of "1" instead
19 of "10"
20- Writing deleted data marks if the first segents on track zero are
21 should work now.
22- ftformat should now be able to handle those cases where the tape
23 drive sets the read only status bit (QIC-40/80 cartridges with
24 QIC-3010/3020 tape drives) because the header segment is damaged.
25- the MTIOCFTCMD ioctl may now be issued by the superuser ONLY.
26
27===== Release notes for ftape-3.04a 12/11/97 =====
28- Fix an "infinite loop can't be killed by signal" bug in
29 ftape_get_drive_status(). Only relevant when trying to access
30 buggy/misconfigured hardware
31- Try to compensate a bug in the HP Colorado T3000's firmware: it
32 doesn't set the write protect bit for QIC80/QIC40 cartridges.
33
34===== Release notes for ftape-3.04 06/11/97 =====
35- If positioning with fast seeking fails fall back to a slow seek
36 before giving up.
37- (nearly) no retries on "no data errors" when verifying after
38 formatting. Improved tuning of the bad sector map after formatting.
39- the directory layout has changed again to allow for easier kernel
40 integration
41- Module parameter "ftape_tracing" now is called "ft_tracing" because
42 the "ftape_tracing" variable has the version checksum attached to it.
43- `/proc/ftape' interface for 2.0.* kernels. `/proc/ftape' no longer
44 is a directory but a file that contains all the information formerly
45 provided in separate files under the `/proc/ftape/' directory.
46- Most of the configuration options have been prefixed by "CONFIG_FT_"
47 in preparation of the kernel inclusion. The Makefiles under
48 "./ftape/" should be directly usable by the kernel.
49- The MODVERSIONS stuff is now auto-detected.
50- Broke backslashed multi line options in MCONFIG into separate lines
51 using GNU-make's "+=" feature.
52- The html and dvi version of the manual is now installed under
53 '/usr/doc/ftape` with 'make install`
54- New SMP define in MCONFIG. ftape works with SMP if this is defined.
55- attempt to cope with "excessive overrun errors" by gradually
56 increasing FDC FIFO threshold. But this doesn't seem to have too
57 much an effect.
58- New load time configuration parameter "ft_fdc_rate_limit". If you
59 encounter too many overrun errors with a 2Mb controller then you
60 might want to set this to 1000.
61- overrun errors on the last sector in a segment sometimes result in
62 a zero DMA residue. Dunno why, but compensate for it.
63- there were still fdc_read() timeout errors. I think I have fixed it
64 now, please FIXME.
65- Sometimes ftape_write() failed to re-start the tape drive when a
66 segment without a good sector was reached ("wait for empty segment
67 failed"). This is fixed. Especially important for > QIC-3010.
68- sftape (aka ftape-2.x) has vanished. I didn't work on it for
69 ages. It is probably still possible to use the old code with
70 ftape-3.04, if one really needs it (BUT RECOMPILE IT)
71- zftape no longer alters the contents of already existing volume
72 table entries, which makes it possible to fill in missing fields,
73 like time stamps using some user space program.
74- ./contrib/vtblc/ contains such a program.
75- new perl script ./contrib/scripts/listtape that list the contents of a
76 floppy tape cartridge parsing the output of "mt volinfo" + "mt fsf"
77- the MTWEOF implementation has changed a little bit (after I had a
78 look at amanda). Calling MTWEOF while the tape is still held open
79 after writing something to the tape now will terminate the current
80 volume, and start a new one at the current position.
81- the volume table maintained by zftape now is a doubly linked list
82 that grows dynamically as needed.
83
84 formatting floppy tape cartridges
85 ---------------------------------
86 * there is a new user space formatting program that does most of the
87 dirty work in user space (auto-detect, computing the sector
88 coordinates, adjusting time stamps and statistics). It has a
89 simple command line interface.
90 * ftape-format.o has vanished, it has been folded into the low level
91 ftape.o module, and the ioctl interface into zftape.o. Most of the
92 complicated stuff has been moved to user space, so there was no
93 need for a separate module anymore.
94 * there is a new ioctl MTIOCFTCMD that sends a bare QIC-117 command
95 to the tape drive.
96 * there is a new mmap() feature to map the dma buffers into user
97 space to be used by the user level formatting program.
98 * Formatting of yet unformatted or totally degaussed cartridges
99 should be possible now. FIXME.
100
101===== Release notes for ftape-3.03b, <forgot the exact date> ====
102
103ftape-3.03b was released as a beta release only. Its main new feature
104was support of the DITTO-2GB drive. This was made possible by reverse
105engineering done by <fill in his name> after Iomega failed to support
106ftape. Although they had promised to do so (this makes me feel a bit
107sad and uncomfortable about Iomega).
108
109===== Release notes for ftape-3.03a, 22/05/97 ====
110
111- Finally fixed auto-un-loading of modules for kernels > 2.1.18
112- Add an "uninstall" target to the Makefile
113- removed the kdtime hack
114- texi2www didn't properly set the back-reference from a footnote back
115 to the regular text.
116
117 zftape specific
118 ---------------
119 * hide the old compression map volume. Taper doesn't accept the
120 presence of non-Taper volumes and Taper-written volume on the same
121 tape.
122 * EOD (End Of Data) handling was still broken: the expected behavior
123 is to return a zero byte count at the first attempt to read past
124 EOD, return a zero byte count at the second attempt to read past
125 EOD and THEN return -EIO.
126
127 ftape-format specific
128 ---------------------
129 * Detection of QIC-40 cartridges in select_tape_format() was broken
130 and made it impossible to format QIC-3010/3020 cartridges.
131 * There are strange "TR-1 Extra" cartridges out there which weren't
132 detected properly because the don't strictly conform to the
133 QIC-80, Rev. N, spec.
134
135===== Release notes for ftape-3.03, 30/04/97 =====
136
137- Removed kernel integration code from the package. I plan to provide
138 a package that can be integrated into the stock kernel separately
139 (hopefully soon).
140 As a result, a simple `make' command now will build everything.
141- ALL compile time configuration options have been moved to the file
142 `MCONFIG'.
143- Quite a few `low level' changes to allow formatting of cartridges.
144- formatting is implemented as a separate module `ftape-format.o'. The
145 modified `mt' program contains sample code that shows how to use it.
146- The VFS interface has been moved from the `ftape.o' module to the
147 high level modules `zftape.o' resp. `sftape.o'. `ftape.o' contains
148 the hardware support only.
149- A bit of /proc support for kernels > 2.1.28
150- Moved documentation to Doc subdir. INSTALL now contains some real
151 installation notes.
152- `install' target in Makefile.
153
154zftape specific:
155----------------
156
157- zftape works for large cartridges now ( > 2^31 bytes)
158- MTIOCVOLINFO and MTIOCGETSIZE now return the size in KILOBYTES,
159 NO LONGER in bytes.
160
161- permissions for write access to a cartridge have changed:
162 * zftape now also takes the file access mode into account
163 * zftape no longer allows writing in the middle of the recorded
164 media. The tape has to be positioned at BOT or EOD for write
165 access.
166
167- MTBSF has changed. It used to position at the beginning of the
168 previous file when called with count 1. This was different from the
169 expected behavior for other Un*x tape drivers (i.e. SCSI). MTBSF
170 with count 1 should merely position at the beginning of the current
171 volume. Fixed. As a result, `tar --verify' now produces the desired
172 result: it verifies the last written volume, not the pre-last
173 written volume.
174
175- The compression map has vanished --> no need for `mt erase' any
176 more. Fast seeking in a compressed volume is still be possible, but
177 takes slightly longer. As a side effect, you may experience an
178 additional volume showing up in front of all others for old
179 cartridges. This is the tape volume that holds the compression map.
180
181- The compression support for zftape has been moved to a separate
182 module `zft-compressor'. DON'T forget to load it before trying to
183 read back compressed volumes. The stock `zftape.o' module probes for
184 the module `zft-compressor' using the kerneld message channel; you
185 have to install `zft-compressor.o' in a place where modprobe can
186 find it if you want to use this.
187
188- New experimental feature that tries to get the broken down GMT time
189 from user space via a kernel daemon message channel. You need to
190 compile and start the `kdtime' daemon contained in the contrib
191 directory to use it. Needed (?) for time stamps in the header
192 segments and the volume table.
193
194- variable block size mode via MTSETBLK 0
195
196- keep modules locked in memory after the block size has been changed
197
198sftape specific:
199----------------
200
201- end of tape handling should be fixed, i.e. multi volume archives
202 written with `afio' can be read back now.
203
204
205===== Release notes for ftape-3.02a, 09/01/97 =====
206
207No big news:
208- call zft_init() resp. sft_init() when compiling the entire stuff
209 into the kernel image.
210- fix bug in ftape-setup.c when NO_TRACE_AT_ALL was defined.
211- fix bug in sftape-eof.c/zftape-eof.c for old kernels (1.2.*)
212- add support for new module interface for recent kernels
213
214===== Release notes for ftape-3.02, 16/12/96 =====
215- Fixed the `FDC unlock command failed' bug in fdc-io.c. When the FIFO
216 was already locked when ftape was loaded, ftape failed to unlock it.
217- Fixed compilation of `contrib/gnumt'. It now finds `mtio.h' even if
218 ftape is NOT included into the kernel source tree.
219- fc-10.c: include <asm/io.h> for inb() and outb().
220- ftape/sftape/zftape: all global variable now have either a `ftape_',
221 a `ft_', `sft_', `zft_' or `qic_' prefix to prevent name clashes
222 with other parts of the kernel when including ftape into the kernel
223 source tree.
224- Kerneld support has changed. `ftape' now searches for a module
225 `ftape-frontend' when none of the frontend (`sftape' or `zftape') is
226 loaded. Please refer to the `Installation/Loading ftape' section of
227 the TeXinfo manual.
228- Add load resp. boot-time configuration of ftape. There are now
229 variables ft_fdc_base, ft_fdc_dma and ft_fdc_irq corresponding to
230 the former FDC_BASE etc. compile time definitions. One can also use
231 the kernel command line parameters to configure the driver if it is
232 compiled into the kernel. Also, the FC-10/FC-20 support is load-time
233 configurable now as well as the MACH-II hack (ft_probe_fc10,
234 resp. ft_mach2). Please refer to the section `Installation/Configure
235 ftape' of the TeXinfo manual.
236- I removed the MODVERSIONS option from `Makefile.module'. Let me alone
237 with ftape and MODVERSIONS unless you include the ftape sources into
238 the kernel source tree.
239- new vendors in `vendors.h':
240 * HP Colorado T3000
241 * ComByte DoublePlay (including a bug fix for their broken
242 formatting software, thanks to whraven@njackn.com)
243 * Iomega DITTO 2GIG. NOTE: this drive cannot work with ftape because
244 the logical data layout of the cartridges used by this drive does
245 NOT conform to the QIC standards, it is a special Iomega specific
246 format. I've sent mail to Iomega but didn't receive an answer
247 yet. If you want this drive to be supported by ftape, ask Iomega
248 to give me information about it.
249- zftape:
250 * re-introduced the MTIOC_ZFTAPE_GETBLKSZ ioctl for compatibility
251 with zftape 1.06a and earlier. Please don't use it when writing
252 new software, use the MTIOCVOLINFO ioctl instead.
253 * Major overhaul of the code that updates the header segments. Never
254 change the tape label unless erasing the tape. Thus we almost
255 never need to write the header segments, unless we would modify
256 the bad sector map which isn't done yet. Updating of volume table
257 and compression map more secure now although it takes a bit
258 longer.
259 * Fixed bug when aborting a write operation with a signal: zftape
260 now finishes the current volume (i.e. writes an eof marker) at the
261 current position. It didn't before which led to somehow *strange*
262 behavior in this cases.
263 * Keep module locked in memory when using it with the non-rewinding
264 devices and the tape is not logical at BOT. Needed for kerneld
265 support.
266- sftape:
267 * Keep module locked in memory when using it with the non-rewinding
268 devices and the tape is not logical at BOT. Needed for kerneld
269 support.
270
271===== Release notes for ftape-3.01, 14/11/96 =====
272
273- Fixed silly bugs in ftape-3.00:
274 * MAKEDEV.ftape: major device number must be 27, not 23
275 * sftape/sftape-read.c: sftape_read_header_segments() called
276 itself recursively instead of calling ftape_read_header_segment()
277 * zftape/qic-vtbl.h: conversion of ftape's file marks to zftape's
278 internal volume table was broken.
279 * patches/2.x.x/linux-2.0.21.dif: my RCS (resp. CVS) system replaced
280 the `$Revison:' etc. macros in the `ftape.h' concerning part of the
281 patch :-( Fixed.
282 * info/ftape.info: Fixed misspellings (`cp' <-> `cp -r' etc.)
283 * when ftape/sftape or ftape/zftape was compiled into the kernel the
284 variable ftape_status was declared twice. Fixed.
285 * removed reference to undeclared variable kernel_version when not
286 compiling as module
287 * fixed a bug introduced by the use of bit-fields for some flags
288 (i.e. write_protected, no_cartridge, formatted)
289 * flag `header_read' is now reset correctly to zero when tape is
290 removed.
291- fixed a bug in sftape/sftape-eof.c that was already in the original
292 ftape code. MTFSF/BSF was not handled correctly when positioned
293 right before the file mark (think of tar)
294- Changed TRACE macros (following a suggestion of Marcin Dalecki) to use
295 the predefined __FUNCTION__ macro of GCC. Spares about 4k of code.
296- added new vendor id for Iomega DITTO 2GIG
297- fixed a bug already present in zftape-1.06 when aborting a write
298 with a signal: we now finish the current volume at that
299 position. Header segments remain NOT up to date until an explicit call
300 to MTREW or MTOFFL is done.
301
302===== Release notes for ftape-3.00, 14/10/96 =====
303
304- Merged ftape with zftape. There are three modules now:
305 ftape for the hardware support, sftape for the implementation of the
306 original ftape eof mark stuff and zftape that implements zftape's way
307 of handling things (compression, volume table, tape blocks of
308 constant length)
309- Documentation in TeXinfo format in the `info' subdirectory.
310- New ioctls for zftape. See zftape/zftape.h
311- Dummy formatting ioctl for ftape. See ftape.h
312- Kernel patch files for the 2.*.* series to include ftape-3.00 in the
313 kernel source tree. These includes a kernel compatible Config.in
314 script and fairly large online information for the kernel configure
315 script.
316- Support for compiling with Linux-1.2.13.
317- Modified GNU mt from their cpio package that can handle the new
318 ioctls.
319- ftape/sftape/zftape is kerneld save now!
320
321Notes on sftape:
322- sftape implements the eof handling code of the original ftape. If
323 you like to stick with the original ftape stuff, you have to use
324 this module, not zftape.
325- sftape is kerneld save, unlike the original ftape.
326- we keep the entire header segment now in memory, so no need to read
327 it before updating the header segments. Additional memory
328 consumption: 256 bytes.
329
330Notes for zftape:
331- zftape has support for tapes with format code 6 now, which use a
332 slightly different volume table format compared with other floppy
333 tapes.
334- new ioctls for zftape. Have a look at zftape/zftape.h
335- The internal volume table representation has changed for zftape. Old
336 cartridges are converted automatically.
337- zftape no longer uses compression map segments, which have vanished
338 from the QIC specs, but creates volume table entry that reserves
339 enough space for the compression map.
340- zftape is kerneld save now.
341- we keep the entire header segment now in memory, so no need to read
342 it before updating the header segments. Additional memory
343 consumption: 256 bytes.
344
345Notes for contrib/gnumt:
346- modified mt from the GNU cpio package that supports all the new
347 ioctls of zftape.
348Notes for contrib/swapout:
349- This contains the swapout.c program that was written by Kai
350 Harrekilde-Pederson. I simply added a Makefile.
351
352===== Release notes for ftape-2.10, 14/10/96 =====
353
354The ftape maintainer has changed.
355Kai Harrekilde-Petersen <khp@dolphinics.no>
356has resigned from maintaining ftape, and I,
357Claus-Justus Heine <claus@momo.math.rwth-aachen.de>,
358have taken over.
359
360- Added support for tapes with `format code 6', i.e. QIC-3020 tapes
361 with more than 2^16 segments.
362- merged changes made by Bas Laarhoven with ftape-2.09. Refer
363 to his release notes below. I've included them into this
364 file unchanged for your reference.
365- disabled call stack back trace for now. This new feature
366 introduced by the interim release 2.0.x still seems to
367 be buggy.
368- Tried to minimize differences between the ftape version
369 to be included into the kernel source tree and the standalone
370 module version.
371- Reintroduced support for Linux-1.2.13. Please refer to the
372 Install-guide.
373
374===== Release notes for ftape-2.09, 16/06/96 =====
375
376There aren't any really big news in this release, mostly just that I
377(the maintainer) have changed my email address (due to a new job). My
378new address is <khp@dolphinics.no>
379
380- The CLK_48MHZ and FDC_82078SL options has gone (all 2Mbps cards seem
381 to use a 48MHz oscillator anyway and I haven't heard of an 'SL
382 chip out there).
383- The S82078B has been `downgraded' to i82077AA compability.
384- TESTING option revived. Right now, it'll enable the (seriously broken)
385 2Mbps code. If you enable it, you'll experience a tape drive that's
386 *really* out to lunch!
387- Some (bold) changes in the init code. Please notify me if they
388 break things for you.
389
390===== Release notes for ftape-2.08, 14/03/96 =====
391
392If you correct a problem with ftape, please send your patch to
393khp@dolphinics.no too.
394
395- Updated to reflect that NR_MEM_LISTS is gone in 1.3.74
396- Teac 700 added to list of known drives.
397- The registered device name is now "ft" rather than "ftape".
398
399===== Release notes for ftape-2.07a, 14/03/96 =====
400
401Bugfixes by Marcin Dalecki <dalecki@namu03.gwdg.de>:
402- In the last release it just compiled against 1.3.70;
403 now the params to request_irq() and free_irq are() are fixed, so it also
404 works in 1.3.73 :-)
405- Support for modules is now correct for newer kernels.
406
407===== Release notes for ftape-2.07, 04/03/96 =====
408
409
410- ftape updated to compile against 1.3.70.
411- Iomega 700 and Wangtek 3200 recognised.
412
413
414===== Release notes for ftape-2.06b, 13/02/96 =====
415
416Another simple bugfix version.
417
418- Jumbo 700 recognised.
419- Typo in vendors.h fixed.
420
421
422===== Release notes for ftape-2.06a, 10/02/96 =====
423
424This release is a simple bugfix version.
425
426- Linux/SMP: ftape *should* work.
427- FC-10/20: Only accepts IRQs 3-7, or 9. If IRQ 9, properly tell the card
428 to use IRQ 2. Thanks to Greg Crider (gcrider@iclnet.org) for finding and
429 locating this bug and testing the patch.
430- Insight drive recognised correctly again.
431- Motor-on wakeup version of the Iomega 250 drive added
432
433
434===== Release notes for ftape-2.06, 28/01/96 =====
435
436Special thanks go to Neal Friedman and Steven Sorbom for their
437help in producing and testing this release.
438
439I have continued to clean up the code, with an eye towards inclusion
440of ftape in Linus' official kernel (In fact, as I type this, I am
441running on a kernel with ftape support statically linked). I have
442test-compiled ftape against my 1.2.13 tree without problems.
443Hopefully, everything should be OK for the v1.2.x people.
444
445WARNING! Alan Cox has mailed me that ftape does *NOT* work with
446Linux/SMP. If you try to run ftape under Linux/SMP, it will cause a
447kernel deadlock (which is worse than a panic).
448
449- QIC-3020/TR-3: 1Mbps support works. Neal is capable of reading and
450 writing data to a tape. ftape will automatically detect the type of
451 tape (e.g. TR-3 vs QIC-80) and move the fdc in and out of
452 "perpendicular mode" as necessary.
453- 2Mbps support is disabled by default, since it is not fully
454 debugged. If you are adventurous, remove -DFDC_82078SL in the
455 Makefile and see what happens :-)
456- fdc detection: silly bugs removed (Only 2Mbps fdcs were affected)
457 and added detection of the National Semiconductors PC8744 fdc chip
458 (used in the PC873xx "super-IO" chips).
459- Removed warning about incompatible types when compiling with Linux
460 1.2.x.
461- README.PCI updated with info about the DELL Dimension XPS P90.
462- Connor TST3200R added to detected drives.
463- `swapout' utility added to distribution. It will dirty 5Meg of
464 memory, trying to swap out other programs. Just say `make swapout'
465 to build it. ftape will do this automatically Real Soon Now (ie:
466 when I have found out which kernel memory alloc function to call).
467
468
469===== Release notes for ftape-2.05, 08/01/96 =====
470
471- For v1.2.x Kernels, you must apply the patch linux-1.2/ksyms.patch to
472 the kernel and rebuild it (it adds the __get_dma_pages symbol to
473 ksyms.c).
474- Included new asm-i386/io.h file from v1.3.x kernel series, to enable
475 gcc v.2.7.[12] to compile v1.2.x kernels (linux-1.2/io.h).
476- Module versions: If you wish to compile ftape as a versioned module,
477 you must first compile your kernel with CONFIG_MODVERSIONS=y.
478 Otherwise, you will get complaints that <linux/modversions.h> does not
479 exist (if that happens, a `touch modversions.h' will help you out).
480- CLK_48MHZ: new define in the Makefile (default: non-zero). If you have
481 a tape controller card that uses the i82078(-1) chip, but cannot get
482 it to work with ftape, try set it to 0 (and please report this).
483- QIC-3010/3020: Complete support is still missing, but will hopefully
484 come soon. Steven Sorbom has kindly provided me with hints about
485 this. Writing of QIC-3020 tapes definitely does NOT work (do not try
486 it! - the drive will not be in "perpendicular mode" and this will ruin
487 the formatting info on the tape).
488- ftape_num_buffers is out of fashion: use NR_BUFFERS instead (and
489 recompile if you want to change it :-).
490
491
492===== Release notes for ftape-2.04, 01/01/96 =====
493
494This version by Kai Harrekilde-Petersen <khp@dolphinics.no>
495
496- ALERT! Support for Kernels earlier then v1.1.85 is about to go away.
497 I intend to clean up some of the code (getting rid of an annoyingly
498 large numbers of #ifdef mostly), which means that support for
499 pre-1.1.85 kernels must go as well.
500- NR_FTAPE_BUFFERS is gone; You can instead select the number of dma
501 buffers by saying `insmod ftape.o ftape_num_buffer=<n>' instead.
502- Configure script gone. ftape will now automagically determine your
503 kernel version by /usr/include/linux/version.h instead.
504- CONFIG_MODVERSIONS now work. All combinations of versioned /
505 unversioned kernel and ftape module works (at least with my 1.3.52
506 kernel).
507- If you have problems with inserting ftape into an old (1.2.x)
508 kernel (e.g. insmod says "1.2.8 does not match 1.2.8), recompile
509 your modules utilities with your new compiler.
510- Reveal TB1400 drive added to vendors.h
511- Support for the i82078-1 (2Mbps) chip is coming along. The
512 biggest problem is that I don't have such a card, which makes
513 testing / debugging somewhat problematic. The second biggest
514 problem is that I do not have the QIC-3010/3020 standards either.
515 Status right now is that the chip is detected, and it should be
516 possible to put it into 2Mbps mode. However, I do not know what
517 "extras" are needed to complete the support. Although putting the
518 i82078 into 1Mbps mode ought to work out of the box, it doesn't
519 (right now, ftape complains about id am errors).
520
521
522===== Release notes for ftape-2.04beta5, 29/12/95 =====
523
524Bas offline linux-tape
525----------------------
526For reasons only known to the majordomo mail list processor, Bas was
527kicked off the linux-tape list sometime during the summer. Being
528overworked at his for-pay job, he didn't notice it much. Instead I
529(Kai, khp@dolphinics.no) has worked on ftape to produce the 2.04(beta)
530version.
531
532zftape
533------
534Note that there exists a much improved version of ftape, written by
535Claus-Justus Heine <claus@willi.math.rwth-aachen.de> which is named
536zftape, which conforms to the QIC-80 specs on how to mark backups, and
537is capable of doing automatic compression. However, zftape makes
538substantial changes to ftape, and I (Kai) have therefore declined to
539integrate zftape into ftape. Hopefully, this will happen soon.
540
541CONFIG_QIC117 removed from the kernel
542-------------------------------------
543The biggest change of all is that ftape now will allocate its dma
544buffers when it is inserted. The means that the CONFIG_QIC117 option
545has disappeared from the Linux kernel as of v1.3.34. If you have an
546earlier kernel, simply answer 'no' to the question will do the trick
547(if you get complains about __get_free_pages() missing, contact the
548linux-tape mailing list).
549
550Note that ftape-2.04beta will work equally well on kernels with and
551without `ftape support'. The only catch is, that you will waste
552around 96-128Kb of precious DMA'able memory on a box that has ftape
553support compiled in.
554
555Now for the real changes:
556
557- FC-20 can now use DMA channels 1, 2, and 3. Thanks to Daniel
558 Cohen, catman@wpi.edu.
559- ftape no longer requires a (gigantic) 96Kb buffer to be statically
560 allocated by the kernel.
561- Added new Iomega drive (8882) to vendors.h
562- -fno-strength-reduce added to Makefile, since GCC is broken.
563- i82078-1 (2Mbps) FDC support started.
564
565
566===== Release notes for ftape-2.03b, 27/05/95 =====
567
568- Prevented verify_area to return error if called with zero length.
569- Fixed a bug in flush_buffers that caused too much padding to be
570 written when a final segment had bad sectors.
571- Increased maximum fast-seek overshoot value from 5 to 10 segments.
572- Breaking loop after 5 retries when positioning fails.
573- Fixed wrong calculation of tape length for QIC-3010 and QIC-3020
574 tapes (densities were swapped).
575- Fixed wrong calculation of overshoot on seek_forward: Wrong sign
576 of error.
577- Suppress (false) error message due to new tape loaded.
578- Added two new CMS drives (11c3 and 11c5) to vendors.h.
579
580
581===== Release notes for ftape-2.03a, 09/05/95 =====
582
583- Fixed display of old error (even if already cleared) in ftape_open.
584- Improved tape length detection, ioctls would fail for 425 ft tapes.
585 Until the tape length is calculated with data from the header
586 segment, we'll use worst-case values.
587- Clear eof_mark after rewinding ioctls.
588- Fixed wrong version message (2.03 had 2.02g id).
589- Fixed bug that caused the fdc to be reset very frequently.
590 This shouldn't affect normal operation but the timing of the
591 report routines has changed again and that may cause problems.
592 We'll just have to find out....
593- Implemented correct write precompensation setting for QIC-3010/3020.
594- Cleaned up fdc_interrupt_wait routine. Hope it still works :-)
595- Finally removed (already disabled) special eof mark handling for
596 gnu tar.
597- Changed order of get_dma_residue and disable_dma in fdc-isr.c
598 because the current order would fail on at least one system.
599 We're back to the original order again, hope (and expect) this
600 doesn't break any other system.
601
602
603===== Release notes for ftape-2.03, 07/05/95 =====
604
605(Changes refer to the first ftape-2.02 release)
606
607Support for wide and extended length tapes
608------------------------------------------
609The Conner TSM 420 and 850 drives are reported to be working.
610I haven't received any reports about other brands; the TSM 420
611and 850 seem to be the most widely used wide drives.
612Extended length tapes (425 ft) with normal QIC-80 drives
613are operating too (At least I've had no reports stating otherwise).
614_Not_ yet completely supported (although they may work) are
615QIC-3020 drives and 2 Mbps floppy disk controllers won't work at
616the highest speed.
617If someone is kind enough to send me one of these, I'll include
618support for it too ;-)
619
620Easier configuration
621--------------------
622Problems due to wrong settings in the Makefile are prevented
623by using a configuration script that sets the necessary (kernel
624version dependent) compile time options.
625This kernel version is now determined from the sources found
626at /usr/src/linux, or if not found, the old way using
627/proc/version.
628Versioned modules will be used automatically when supported
629by- and configured in- the kernel.
630Note that the current modules code (1.1.87) is still broken
631and _needs_ the fix included in the insmod directory.
632Please don't send me any more Oops reports caused by insmod :-(
633
634Reduced module size
635-------------------
636The standard module size is much reduced and some compile time
637options can even reduce it further. (I don't recommend this
638for normal use but it can be handy for rescue diskettes)
639
640Option: Approx. module size:
641
642<standard> 150 Kb
643NO_TRACE 125 Kb
644NO_TRACE_AT_ALL 67 Kb
645
646
647Much improved driver interruption
648---------------------------------
649Most possible loops have been broken and signal detection
650has been improved.
651In most cases the driver can be aborted by ^C (SIGINT) and
652SIGKILL (kill -9) will generate be a sure kill.
653(Note that aborting a tape operation may damage the last
654data written to tape)
655
656Improved error recovery
657-----------------------
658Ftape now returns an error (ENODATA) to the application if
659a segment proves to be unrecoverable and then skips the
660bad segment.
661This causes most applications to continue to work (tar
662and afio) loosing only a small amount (up to 29 Kb) of data.
663Retried read operations will now be done slightly off-track
664to improve the chance of success. Serious head off-track
665errors will be detected.
666
667FC-10 and FC-20 controllers
668---------------------------
669Ftape now supports both the old CMS FC-10 and the newer FC-20
670controllers.
671Because the operation of these cards is still undocumented,
672thus far they will only work with the default settings (See
673Makefile). Any feed-back on how to use them with other settings
674will be welcome !
675Compilation will fail if one changes the settings to illegal
676values.
677
678Kernels and compilers
679---------------------
680Ftape is currently being developed using the 2.5.8 compiler.
681The older 2.4.5 probably works too (Set option in Makefile!).
682I have no experience with any later compilers nor Elf support.
683Any information on this is welcome.
684The latest kernel I have tested ftape with is 1.2.6.
685
686Compression
687-----------
688An impressive collection of changes for ftape including
689on-the-fly compression is still lying on my desk.
690If 2.03 proves to be reliable I might start integrating these
691but as usual, I'm short in time :-(
692
693Formatting
694----------
695There is still no way to format tapes under Linux. As far as
696I know all attempts to write such a program have died now.
697Since formatted tapes are rather common now, I think all we
698need is a utility that writes a worst case pattern and verifies
699that with the drive put in verify mode, reducing margins.
700Any takers ?
701
702Furthermore
703-----------
704Cleaned up messages.
705Prepared to support multiple tape drives on one fdc.
706Thanks to all the people who sent bug reports and helped me
707improve the driver. Without trying to be complete I'll mention
708Gary Anderson (without his accurate reports and unreliable
709hardware there wouldn't be a 2.03), Stefan Kneifel (FC-20),
710Robert Broughton (FC-20, you were almost there ;-), Bjorn
711Ekwall (for the versioned modules and buggy insmod ;-), Peter
712Fox, Christopher Oliver, Ralph Whittaker and not the least
713Linus Torvalds (for Linux and keeping me busy because of
714changes to the kernel ;-)
715Thanks to anyone I forgot, for the bug reports, the ftape
716bashing and the mental support...
717
718
719That's it for now. Have Fun,
720
721Bas.
722
723
724===== Release notes for ftape-2.02g, 06/05/95 =====
725
726- Added extra test to break read-id loop with signal.
727- Changed rewind code to handle negative overshoot for drives
728 that take very long to start or stop.
729- Let use of get/set i/o-regions depend on kernel version.
730- Changed code to use a more general test for conditional
731 compilations depending on kernel version.
732- Improved micro-step functionality to go off-track only
733 while reading (id & data).
734- Added failure on tape-not-referenced bit in ftape_command.
735- Added FOREVER option to read-wait routine.
736- Changed read-id to use shorter timeout causing smaller
737 rewinds on timeout.
738- Made kernel-interface functions static.
739
740
741===== Release notes for ftape-2.02f, 03/05/95 =====
742
743- Added support for dual tape drives on my system, extended Configure
744 script to detect host 'dodo'.
745- Log media defect in history if ecc failed and no data was returned.
746- Fixed Configure script that was failing for kernel versions with
747 double digit version or revision numbers.
748
749
750===== Release notes for ftape-2.02e, 01/05/95 =====
751
752- Fixed reposition loop at logical eot (failing read_id).
753- Fixed 34 segment offset when rewinding.
754- Added fast seek capability for more than 255 segments.
755- Fixed wrong busy result from ftape_command causing reverse
756 seek to fail.
757- Added breakout from infinite rewind loop (if something fails).
758
759
760===== Release notes for ftape-2.02d, 30/04/95 =====
761
762- Improved abortion on signals: Interrupt will make a graceful
763 exit, Kill will be less nice and should be used if everything
764 else fails.
765- Included check for tape-head off track.
766- Implemented exit from tape-start loop.
767- Added kernel io-port registration.
768- Implemented skip of failing segment (ENODATA) on ecc failure.
769 This allows afio and tar to continue when the tape is damaged.
770- Made distinction between drive names with different codes.
771
772
773===== Release notes for ftape-2.02c, 22/04/95 =====
774
775- Fixed too tight command queueing after tape stop/pause command
776 issued from within interrupt service routine (Showed as timeout
777 on Acknowledge errors during retries on some systems)
778- Tried to fix timeouts when using 425 ft tape because the extended
779 length doesn't seem to be detected by the hardware.
780 We now use the format code from the header segment so adjust the
781 timing after reading the header segment.
782- Fixed some messages stating 'unexpected something...' being not
783 unexpected anymore.
784- Started preparations for merge of dynamic buffer allocation and
785 compression code.
786- Changed some debug messages to include relevant segment information
787 at level 4.
788- Included early bail-out when drive offline, preventing a lot of
789 false messages.
790- Moved ftape_parameter_xxx() offsets into function instead of in calls.
791- Removed 'weird, drive busy but no data' error when caused by
792 an error during a read-id.
793- Improved 'timeout on acknowledge' diagnostics.
794- Moved MODULE option into Configure.
795- Reduced code size when no tracing at all was set (Claus Heine).
796- No longer log error code 0 (no error) as an error.
797
798
799===== Release notes for ftape-2.02b, 09/04/95 =====
800
801- Relaxed timing for status operation and displaying
802 abnormal results. Hopefully this shows what's going
803 wrong with the Conner TSM850R drives.
804- Created script for configuration, using version number
805 of kernel source if available, otherwise /proc/version.
806- Fixed conditionals in kernel-interface.c.
807- Removed unavoidable TRACE output.
808
809
810===== Release notes for ftape-2.02a, 01/04/95 =====
811
812- Implemented `new-style' (versioned) modules support for new
813 kernels.
814- Reduced size of module by moving static data to bss.
815- Now using version number of kernel source instead of running
816 kernel for kernel versions >= 1.1.82
817- Added feedback on drive speeds to vendor information.
818- Included fixed insmod sources to distribution (Let's hope
819 the modules distribution get fixed soon :-/).
820
821Note that I haven't yet implemented any of the code extension I
822received. I hope to find some time to do this soon.
823
824
825===== Release notes for ftape-2.02, 15/01/95 =====
826
827
828- Fixed failing repositioning when overshoot was incremented.
829- Fixed rate selection: Because of a deficiency in the QIC-117
830 specification one cannot distinguish between a not implemented
831 and a failing command. Therefor we now try to find out if the
832 drive does support this command before usage.
833- Fixed error retry using wrong offset in fdc-isr.
834- Improved retry code to retry only once on a single no-data
835 error in a segment.
836- Validate sector number extracted from eof mark because an
837 invalid file mark (due to ???) could cause kernel panic.
838- Split ftape-io.c into ftape-io.c and ftape-ctl.c files.
839- Corrected too high media error count after writing to
840 a bad tape.
841- Added #include <asm/segment.h> again because old kernel versions
842 need it.
843- Fixed fdc not being disabled when open failed because no tape
844 drive was found.
845- Fixed problem with soft error in sector 32 (shift operator with
846 shiftcount 32 is not defined).
847
848
849===== Release notes for ftape-2.01, 08/01/95 =====
850
851
852- Removed TESTING setting from distributed Makefile.
853- Fixed `mt asf' failure: Rewind was deferred to close which
854 overruled the fsf ioctl.
855- Prevented non-interruptible commands being interrupted.
856- Added missing timeout.pause setting.
857- Maximum tape speed read from drive type information table.
858 If the information is not in the table (0) the drive will
859 determine the speed itself and put a message in the logfile.
860 This information should then be added to the table in the
861 vendors.h file (and reported to me).
862- Added call to ftape_init_drive after soft reset for those
863 (antique) drives that don't do an implicit seek_load_point
864 after a reset or power up.
865- Don't try to set data rate if reset failed.
866- Prevent update of seek variables when starting from the
867 beginning or the end of the tape.
868- Fixed wrong adjustment of overshoot in seek_forward().
869- Added sync to Makefile (again).
870- Added code to diagnose timer problems (calibr.c).
871- Replaced time differences by timediff calls.
872- Removed reference to do_floppy from object for recent kernels.
873- Fixed wrong display of 'failing dma controller' message.
874- Removed various no longer used #include statements.
875- Added max. tape speed value to vendor-struct.
876- Changed ftape-command to check pre-conditions and wait
877 if needed.
878- Further updated qic117.h to rev G.
879- Combined command name table and restrictions table to one.
880 Extended this table with some new fields.
881- Increased timeout on Ack timer value and included code to
882 report out of spec behaviour.
883- Increased rewind timeout margin to calculated + 20%.
884- Improved data rate selection so it won't fail on some
885 older (pre standard) drives.
886- Changed initialisation code so drive will be rewound if the
887 driver is reloaded and the tape is not at bot.
888- Moved some of the flush operations from close to the ioctls.
889- Added exit code value to failing verify area message.
890- Loop until tape halted in smart-stop.
891- Fast seek handled specially if located at bot or eot.
892- Being more conservative on overshoot value.
893
894
895===== Release notes for ftape-2.00, 31/12/94 =====
896
897 The Install-guide is completely rewritten and now also includes
898some information on how to use the driver. If you're either new
899to ftape or new to Unix tape devices make sure to read it !
900
901 If you own a pci system and experience problems with the
902ftape driver make sure to read the README.PCI file. It contains
903some hints on how to fix your hardware.
904
905 For anybody who hasn't noticed: The version number of the
906driver has been incremented (The latest released version has
907been version 1.14d).
908 This has been done for two major reasons:
909
910 o A new (better) error recovery scheme is implemented.
911 o Support for new drive types has been added.
912
913 All these improvements/changes will probably include a couple
914of new (and old?) bugs. If you encounter any problems that you think
915I'm not yet aware of, feel free to send a report to <bas@vimec.nl>.
916 I recommend keeping a version of ftape-1.14d available, just
917in case ;-)
918
919 This version should work with all kernel versions from 1.0.9 up
920to 1.1.72 (and probably earlier and later versions too).
921
922
923Major new features:
924
925- Better handling of tapes with defects: When a sector repeatedly
926 (SOFT_RETRIES in ftape.h) cannot be written to or read from it is
927 marked as an hard error and gets skipped.
928 The error correction code can handle up to three of these hard
929 errors provided there are no other errors in that segment (32 Kb).
930
931- Allows writing to tapes with defects (although the risk of loosing
932 data increases !)
933 Look for the media-defects entry printed with the statistics when
934 the tape is closed. A non-zero value here shows a bad tape.
935 [the actual count is wrong (too high), this is a known bug].
936
937- Use of backup header segment if first one is failing.
938
939- Support for extended length tapes with QIC-80: both 425 and 1100 ft.
940 0.25 inch tapes are now recognized and handled.
941
942- Support for new QIC-80 drives with 8 mm `wide' tapes (e.g. Conner
943 TSM 420).
944
945- Support for new QIC-3010 and QIC-3020 drives (experimental) with
946 both 0.25 inch and 8 mm tapes.
947
948Some minor features were added, a couple of small bugs were fixed and
949probably some new ones introduced ;-).
950
951[lseek() didn't make it into this version]
952
953Have fun,
954
955Bas.
956----
957 LocalWords: ftape MCONFIG mt VFS zftape resp sftape proc subdir MTIOCVOLINFO
958 LocalWords: MTIOCGETSIZE BOT EOD MTBSF zft kerneld modprobe kdtime contrib TR
959 LocalWords: MTSETBLK afio uninstall texi www EIO QIC init sft eof aka dma GB
960 LocalWords: SIGKILL MTIOCFTCMD mmap Iomega FDC fdc io gnumt mtio fc asm inb
961 LocalWords: outb ft qic frontend TeXinfo irq mach MODVERSIONS CONFIG html dvi
962 LocalWords: usr doc SMP Mb Dunno FIXME vtblc perl listtape volinfo fsf MTWEOF
963 LocalWords: amanda degaussed ComByte DoublePlay whraven njackn com MTIOC vtbl
964 LocalWords: GETBLKSZ MAKEDEV zftape's linux dif CVS Revison cp MTREW MTOFFL
965 LocalWords: MTFSF BSF Marcin Dalecki GCC Config cpio swapout Kai Harrekilde
966 LocalWords: Pederson khp dolphinics Justus claus momo rwth aachen Laarhoven
diff --git a/drivers/char/ftape/compressor/Makefile b/drivers/char/ftape/compressor/Makefile
deleted file mode 100644
index 1fbd6c4019db..000000000000
--- a/drivers/char/ftape/compressor/Makefile
+++ /dev/null
@@ -1,31 +0,0 @@
1#
2# Copyright (C) 1997 Claus-Justus Heine.
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2, or (at your option)
7# any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; see the file COPYING. If not, write to
16# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17#
18# $Source: /homes/cvs/ftape-stacked/ftape/compressor/Makefile,v $
19# $Revision: 1.1 $
20# $Date: 1997/10/05 19:12:28 $
21#
22# Makefile for the optional compressor for th zftape VFS
23# interface to the QIC-40/80/3010/3020 floppy-tape driver for
24# Linux.
25#
26
27obj-$(CONFIG_ZFT_COMPRESSOR) += zft-compressor.o
28
29zft-compressor-objs := zftape-compress.o lzrw3.o
30
31CFLAGS_lzrw3.o := -O6 -funroll-all-loops
diff --git a/drivers/char/ftape/compressor/lzrw3.c b/drivers/char/ftape/compressor/lzrw3.c
deleted file mode 100644
index a032a0ee2a99..000000000000
--- a/drivers/char/ftape/compressor/lzrw3.c
+++ /dev/null
@@ -1,743 +0,0 @@
1/*
2 * $Source: /homes/cvs/ftape-stacked/ftape/compressor/lzrw3.c,v $
3 * $Revision: 1.1 $
4 * $Date: 1997/10/05 19:12:29 $
5 *
6 * Implementation of Ross Williams lzrw3 algorithm. Adaption for zftape.
7 *
8 */
9
10#include "../compressor/lzrw3.h" /* Defines single exported function "compress". */
11
12/******************************************************************************/
13/* */
14/* LZRW3.C */
15/* */
16/******************************************************************************/
17/* */
18/* Author : Ross Williams. */
19/* Date : 30-Jun-1991. */
20/* Release : 1. */
21/* */
22/******************************************************************************/
23/* */
24/* This file contains an implementation of the LZRW3 data compression */
25/* algorithm in C. */
26/* */
27/* The algorithm is a general purpose compression algorithm that runs fast */
28/* and gives reasonable compression. The algorithm is a member of the Lempel */
29/* Ziv family of algorithms and bases its compression on the presence in the */
30/* data of repeated substrings. */
31/* */
32/* This algorithm is unpatented and the code is public domain. As the */
33/* algorithm is based on the LZ77 class of algorithms, it is unlikely to be */
34/* the subject of a patent challenge. */
35/* */
36/* Unlike the LZRW1 and LZRW1-A algorithms, the LZRW3 algorithm is */
37/* deterministic and is guaranteed to yield the same compressed */
38/* representation for a given file each time it is run. */
39/* */
40/* The LZRW3 algorithm was originally designed and implemented */
41/* by Ross Williams on 31-Dec-1990. */
42/* */
43/* Here are the results of applying this code, compiled under THINK C 4.0 */
44/* and running on a Mac-SE (8MHz 68000), to the standard calgary corpus. */
45/* */
46/* +----------------------------------------------------------------+ */
47/* | DATA COMPRESSION TEST | */
48/* | ===================== | */
49/* | Time of run : Sun 30-Jun-1991 09:31PM | */
50/* | Timing accuracy : One part in 100 | */
51/* | Context length : 262144 bytes (= 256.0000K) | */
52/* | Test suite : Calgary Corpus Suite | */
53/* | Files in suite : 14 | */
54/* | Algorithm : LZRW3 | */
55/* | Note: All averages are calculated from the un-rounded values. | */
56/* +----------------------------------------------------------------+ */
57/* | File Name Length CxB ComLen %Remn Bits Com K/s Dec K/s | */
58/* | ---------- ------ --- ------ ----- ---- ------- ------- | */
59/* | rpus:Bib.D 111261 1 55033 49.5 3.96 19.46 32.27 | */
60/* | us:Book1.D 768771 3 467962 60.9 4.87 17.03 31.07 | */
61/* | us:Book2.D 610856 3 317102 51.9 4.15 19.39 34.15 | */
62/* | rpus:Geo.D 102400 1 82424 80.5 6.44 11.65 18.18 | */
63/* | pus:News.D 377109 2 205670 54.5 4.36 17.14 27.47 | */
64/* | pus:Obj1.D 21504 1 13027 60.6 4.85 13.40 18.95 | */
65/* | pus:Obj2.D 246814 1 116286 47.1 3.77 19.31 30.10 | */
66/* | s:Paper1.D 53161 1 27522 51.8 4.14 18.60 31.15 | */
67/* | s:Paper2.D 82199 1 45160 54.9 4.40 18.45 32.84 | */
68/* | rpus:Pic.D 513216 2 122388 23.8 1.91 35.29 51.05 | */
69/* | us:Progc.D 39611 1 19669 49.7 3.97 18.87 30.64 | */
70/* | us:Progl.D 71646 1 28247 39.4 3.15 24.34 40.66 | */
71/* | us:Progp.D 49379 1 19377 39.2 3.14 23.91 39.23 | */
72/* | us:Trans.D 93695 1 33481 35.7 2.86 25.48 40.37 | */
73/* +----------------------------------------------------------------+ */
74/* | Average 224401 1 110953 50.0 4.00 20.17 32.72 | */
75/* +----------------------------------------------------------------+ */
76/* */
77/******************************************************************************/
78
79/******************************************************************************/
80
81/* The following structure is returned by the "compress" function below when */
82/* the user asks the function to return identifying information. */
83/* The most important field in the record is the working memory field which */
84/* tells the calling program how much working memory should be passed to */
85/* "compress" when it is called to perform a compression or decompression. */
86/* LZRW3 uses the same amount of memory during compression and decompression. */
87/* For more information on this structure see "compress.h". */
88
89#define U(X) ((ULONG) X)
90#define SIZE_P_BYTE (U(sizeof(UBYTE *)))
91#define SIZE_WORD (U(sizeof(UWORD )))
92#define ALIGNMENT_FUDGE (U(16))
93#define MEM_REQ ( U(4096)*(SIZE_P_BYTE) + ALIGNMENT_FUDGE )
94
95static struct compress_identity identity =
96{
97 U(0x032DDEA8), /* Algorithm identification number. */
98 MEM_REQ, /* Working memory (bytes) required. */
99 "LZRW3", /* Name of algorithm. */
100 "1.0", /* Version number of algorithm. */
101 "31-Dec-1990", /* Date of algorithm. */
102 "Public Domain", /* Copyright notice. */
103 "Ross N. Williams", /* Author of algorithm. */
104 "Renaissance Software", /* Affiliation of author. */
105 "Public Domain" /* Vendor of algorithm. */
106};
107
108LOCAL void compress_compress (UBYTE *,UBYTE *,ULONG,UBYTE *, LONG *);
109LOCAL void compress_decompress(UBYTE *,UBYTE *,LONG, UBYTE *, ULONG *);
110
111/******************************************************************************/
112
113/* This function is the only function exported by this module. */
114/* Depending on its first parameter, the function can be requested to */
115/* compress a block of memory, decompress a block of memory, or to identify */
116/* itself. For more information, see the specification file "compress.h". */
117
118EXPORT void lzrw3_compress(
119 UWORD action, /* Action to be performed. */
120 UBYTE *wrk_mem, /* Address of working memory we can use.*/
121 UBYTE *src_adr, /* Address of input data. */
122 LONG src_len, /* Length of input data. */
123 UBYTE *dst_adr, /* Address to put output data. */
124 void *p_dst_len /* Address of longword for length of output data.*/
125)
126{
127 switch (action)
128 {
129 case COMPRESS_ACTION_IDENTITY:
130 *((struct compress_identity **)p_dst_len)= &identity;
131 break;
132 case COMPRESS_ACTION_COMPRESS:
133 compress_compress(wrk_mem,src_adr,src_len,dst_adr,(LONG *)p_dst_len);
134 break;
135 case COMPRESS_ACTION_DECOMPRESS:
136 compress_decompress(wrk_mem,src_adr,src_len,dst_adr,(LONG *)p_dst_len);
137 break;
138 }
139}
140
141/******************************************************************************/
142/* */
143/* BRIEF DESCRIPTION OF THE LZRW3 ALGORITHM */
144/* ======================================== */
145/* The LZRW3 algorithm is identical to the LZRW1-A algorithm except that */
146/* instead of transmitting history offsets, it transmits hash table indexes. */
147/* In order to decode the indexes, the decompressor must maintain an */
148/* identical hash table. Copy items are straightforward:when the decompressor */
149/* receives a copy item, it simply looks up the hash table to translate the */
150/* index into a pointer into the data already decompressed. To update the */
151/* hash table, it replaces the same table entry with a pointer to the start */
152/* of the newly decoded phrase. The tricky part is with literal items, for at */
153/* the time that the decompressor receives a literal item the decompressor */
154/* does not have the three bytes in the Ziv (that the compressor has) to */
155/* perform the three-byte hash. To solve this problem, in LZRW3, both the */
156/* compressor and decompressor are wired up so that they "buffer" these */
157/* literals and update their hash tables only when three bytes are available. */
158/* This makes the maximum buffering 2 bytes. */
159/* */
160/* Replacement of offsets by hash table indexes yields a few percent extra */
161/* compression at the cost of some speed. LZRW3 is slower than LZRW1, LZRW1-A */
162/* and LZRW2, but yields better compression. */
163/* */
164/* Extra compression could be obtained by using a hash table of depth two. */
165/* However, increasing the depth above one incurs a significant decrease in */
166/* compression speed which was not considered worthwhile. Another reason for */
167/* keeping the depth down to one was to allow easy comparison with the */
168/* LZRW1-A and LZRW2 algorithms so as to demonstrate the exact effect of the */
169/* use of direct hash indexes. */
170/* */
171/* +---+ */
172/* |___|4095 */
173/* |___| */
174/* +---------------------*_|<---+ /----+---\ */
175/* | |___| +---|Hash | */
176/* | |___| |Function| */
177/* | |___| \--------/ */
178/* | |___|0 ^ */
179/* | +---+ | */
180/* | Hash +-----+ */
181/* | Table | */
182/* | --- */
183/* v ^^^ */
184/* +-------------------------------------|----------------+ */
185/* |||||||||||||||||||||||||||||||||||||||||||||||||||||||| */
186/* +-------------------------------------|----------------+ */
187/* | |1......18| | */
188/* |<------- Lempel=History ------------>|<--Ziv-->| | */
189/* | (=bytes already processed) |<-Still to go-->| */
190/* |<-------------------- INPUT BLOCK ------------------->| */
191/* */
192/* The diagram above for LZRW3 looks almost identical to the diagram for */
193/* LZRW1. The difference is that in LZRW3, the compressor transmits hash */
194/* table indices instead of Lempel offsets. For this to work, the */
195/* decompressor must maintain a hash table as well as the compressor and both */
196/* compressor and decompressor must "buffer" literals, as the decompressor */
197/* cannot hash phrases commencing with a literal until another two bytes have */
198/* arrived. */
199/* */
200/* LZRW3 Algorithm Execution Summary */
201/* --------------------------------- */
202/* 1. Hash the first three bytes of the Ziv to yield a hash table index h. */
203/* 2. Look up the hash table yielding history pointer p. */
204/* 3. Match where p points with the Ziv. If there is a match of three or */
205/* more bytes, code those bytes (in the Ziv) as a copy item, otherwise */
206/* code the next byte in the Ziv as a literal item. */
207/* 4. Update the hash table as possible subject to the constraint that only */
208/* phrases commencing three bytes back from the Ziv can be hashed and */
209/* entered into the hash table. (This enables the decompressor to keep */
210/* pace). See the description and code for more details. */
211/* */
212/******************************************************************************/
213/* */
214/* DEFINITION OF COMPRESSED FILE FORMAT */
215/* ==================================== */
216/* * A compressed file consists of a COPY FLAG followed by a REMAINDER. */
217/* * The copy flag CF uses up four bytes with the first byte being the */
218/* least significant. */
219/* * If CF=1, then the compressed file represents the remainder of the file */
220/* exactly. Otherwise CF=0 and the remainder of the file consists of zero */
221/* or more GROUPS, each of which represents one or more bytes. */
222/* * Each group consists of two bytes of CONTROL information followed by */
223/* sixteen ITEMs except for the last group which can contain from one */
224/* to sixteen items. */
225/* * An item can be either a LITERAL item or a COPY item. */
226/* * Each item corresponds to a bit in the control bytes. */
227/* * The first control byte corresponds to the first 8 items in the group */
228/* with bit 0 corresponding to the first item in the group and bit 7 to */
229/* the eighth item in the group. */
230/* * The second control byte corresponds to the second 8 items in the group */
231/* with bit 0 corresponding to the ninth item in the group and bit 7 to */
232/* the sixteenth item in the group. */
233/* * A zero bit in a control word means that the corresponding item is a */
234/* literal item. A one bit corresponds to a copy item. */
235/* * A literal item consists of a single byte which represents itself. */
236/* * A copy item consists of two bytes that represent from 3 to 18 bytes. */
237/* * The first byte in a copy item will be denoted C1. */
238/* * The second byte in a copy item will be denoted C2. */
239/* * Bits will be selected using square brackets. */
240/* For example: C1[0..3] is the low nibble of the first control byte. */
241/* of copy item C1. */
242/* * The LENGTH of a copy item is defined to be C1[0..3]+3 which is a number */
243/* in the range [3,18]. */
244/* * The INDEX of a copy item is defined to be C1[4..7]*256+C2[0..8] which */
245/* is a number in the range [0,4095]. */
246/* * A copy item represents the sequence of bytes */
247/* text[POS-OFFSET..POS-OFFSET+LENGTH-1] where */
248/* text is the entire text of the uncompressed string. */
249/* POS is the index in the text of the character following the */
250/* string represented by all the items preceeding the item */
251/* being defined. */
252/* OFFSET is obtained from INDEX by looking up the hash table. */
253/* */
254/******************************************************************************/
255
256/* The following #define defines the length of the copy flag that appears at */
257/* the start of the compressed file. The value of four bytes was chosen */
258/* because the fast_copy routine on my Macintosh runs faster if the source */
259/* and destination blocks are relatively longword aligned. */
260/* The actual flag data appears in the first byte. The rest are zeroed so as */
261/* to normalize the compressed representation (i.e. not non-deterministic). */
262#define FLAG_BYTES 4
263
264/* The following #defines define the meaning of the values of the copy */
265/* flag at the start of the compressed file. */
266#define FLAG_COMPRESS 0 /* Signals that output was result of compression. */
267#define FLAG_COPY 1 /* Signals that output was simply copied over. */
268
269/* The 68000 microprocessor (on which this algorithm was originally developed */
270/* is fussy about non-aligned arrays of words. To avoid these problems the */
271/* following macro can be used to "waste" from 0 to 3 bytes so as to align */
272/* the argument pointer. */
273#define ULONG_ALIGN_UP(X) ((((ULONG)X)+sizeof(ULONG)-1)&~(sizeof(ULONG)-1))
274
275
276/* The following constant defines the maximum length of an uncompressed item. */
277/* This definition must not be changed; its value is hardwired into the code. */
278/* The longest number of bytes that can be spanned by a single item is 18 */
279/* for the longest copy item. */
280#define MAX_RAW_ITEM (18)
281
282/* The following constant defines the maximum length of an uncompressed group.*/
283/* This definition must not be changed; its value is hardwired into the code. */
284/* A group contains at most 16 items which explains this definition. */
285#define MAX_RAW_GROUP (16*MAX_RAW_ITEM)
286
287/* The following constant defines the maximum length of a compressed group. */
288/* This definition must not be changed; its value is hardwired into the code. */
289/* A compressed group consists of two control bytes followed by up to 16 */
290/* compressed items each of which can have a maximum length of two bytes. */
291#define MAX_CMP_GROUP (2+16*2)
292
293/* The following constant defines the number of entries in the hash table. */
294/* This definition must not be changed; its value is hardwired into the code. */
295#define HASH_TABLE_LENGTH (4096)
296
297/* LZRW3, unlike LZRW1(-A), must initialize its hash table so as to enable */
298/* the compressor and decompressor to stay in step maintaining identical hash */
299/* tables. In an early version of the algorithm, the tables were simply */
300/* initialized to zero and a check for zero was included just before the */
301/* matching code. However, this test costs time. A better solution is to */
302/* initialize all the entries in the hash table to point to a constant */
303/* string. The decompressor does the same. This solution requires no extra */
304/* test. The contents of the string do not matter so long as the string is */
305/* the same for the compressor and decompressor and contains at least */
306/* MAX_RAW_ITEM bytes. I chose consecutive decimal digits because they do not */
307/* have white space problems (e.g. there is no chance that the compiler will */
308/* replace more than one space by a TAB) and because they make the length of */
309/* the string obvious by inspection. */
310#define START_STRING_18 ((UBYTE *) "123456789012345678")
311
312/* In this algorithm, hash values have to be calculated at more than one */
313/* point. The following macro neatens the code up for this. */
314#define HASH(PTR) \
315 (((40543*(((*(PTR))<<8)^((*((PTR)+1))<<4)^(*((PTR)+2))))>>4) & 0xFFF)
316
317/******************************************************************************/
318
319/* Input : Hand over the required amount of working memory in p_wrk_mem. */
320/* Input : Specify input block using p_src_first and src_len. */
321/* Input : Point p_dst_first to the start of the output zone (OZ). */
322/* Input : Point p_dst_len to a ULONG to receive the output length. */
323/* Input : Input block and output zone must not overlap. */
324/* Output : Length of output block written to *p_dst_len. */
325/* Output : Output block in Mem[p_dst_first..p_dst_first+*p_dst_len-1]. May */
326/* Output : write in OZ=Mem[p_dst_first..p_dst_first+src_len+MAX_CMP_GROUP-1].*/
327/* Output : Upon completion guaranteed *p_dst_len<=src_len+FLAG_BYTES. */
328LOCAL void compress_compress(UBYTE *p_wrk_mem,
329 UBYTE *p_src_first, ULONG src_len,
330 UBYTE *p_dst_first, LONG *p_dst_len)
331{
332 /* p_src and p_dst step through the source and destination blocks. */
333 register UBYTE *p_src = p_src_first;
334 register UBYTE *p_dst = p_dst_first;
335
336 /* The following variables are never modified and are used in the */
337 /* calculations that determine when the main loop terminates. */
338 UBYTE *p_src_post = p_src_first+src_len;
339 UBYTE *p_dst_post = p_dst_first+src_len;
340 UBYTE *p_src_max1 = p_src_first+src_len-MAX_RAW_ITEM;
341 UBYTE *p_src_max16 = p_src_first+src_len-MAX_RAW_ITEM*16;
342
343 /* The variables 'p_control' and 'control' are used to buffer control bits. */
344 /* Before each group is processed, the next two bytes of the output block */
345 /* are set aside for the control word for the group about to be processed. */
346 /* 'p_control' is set to point to the first byte of that word. Meanwhile, */
347 /* 'control' buffers the control bits being generated during the processing */
348 /* of the group. Instead of having a counter to keep track of how many items */
349 /* have been processed (=the number of bits in the control word), at the */
350 /* start of each group, the top word of 'control' is filled with 1 bits. */
351 /* As 'control' is shifted for each item, the 1 bits in the top word are */
352 /* absorbed or destroyed. When they all run out (i.e. when the top word is */
353 /* all zero bits, we know that we are at the end of a group. */
354# define TOPWORD 0xFFFF0000
355 UBYTE *p_control;
356 register ULONG control=TOPWORD;
357
358 /* THe variable 'hash' always points to the first element of the hash table. */
359 UBYTE **hash= (UBYTE **) ULONG_ALIGN_UP(p_wrk_mem);
360
361 /* The following two variables represent the literal buffer. p_h1 points to */
362 /* the hash table entry corresponding to the youngest literal. p_h2 points */
363 /* to the hash table entry corresponding to the second youngest literal. */
364 /* Note: p_h1=0=>p_h2=0 because zero values denote absence of a pending */
365 /* literal. The variables are initialized to zero meaning an empty "buffer". */
366 UBYTE **p_h1=NULL;
367 UBYTE **p_h2=NULL;
368
369 /* To start, we write the flag bytes. Being optimistic, we set the flag to */
370 /* FLAG_COMPRESS. The remaining flag bytes are zeroed so as to keep the */
371 /* algorithm deterministic. */
372 *p_dst++=FLAG_COMPRESS;
373 {UWORD i; for (i=2;i<=FLAG_BYTES;i++) *p_dst++=0;}
374
375 /* Reserve the first word of output as the control word for the first group. */
376 /* Note: This is undone at the end if the input block is empty. */
377 p_control=p_dst; p_dst+=2;
378
379 /* Initialize all elements of the hash table to point to a constant string. */
380 /* Use of an unrolled loop speeds this up considerably. */
381 {UWORD i; UBYTE **p_h=hash;
382# define ZH *p_h++=START_STRING_18
383 for (i=0;i<256;i++) /* 256=HASH_TABLE_LENGTH/16. */
384 {ZH;ZH;ZH;ZH;
385 ZH;ZH;ZH;ZH;
386 ZH;ZH;ZH;ZH;
387 ZH;ZH;ZH;ZH;}
388 }
389
390 /* The main loop processes either 1 or 16 items per iteration. As its */
391 /* termination logic is complicated, I have opted for an infinite loop */
392 /* structure containing 'break' and 'goto' statements. */
393 while (TRUE)
394 {/* Begin main processing loop. */
395
396 /* Note: All the variables here except unroll should be defined within */
397 /* the inner loop. Unfortunately the loop hasn't got a block. */
398 register UBYTE *p; /* Scans through targ phrase during matching. */
399 register UBYTE *p_ziv= NULL ; /* Points to first byte of current Ziv. */
400 register UWORD unroll; /* Loop counter for unrolled inner loop. */
401 register UWORD index; /* Index of current hash table entry. */
402 register UBYTE **p_h0 = NULL ; /* Pointer to current hash table entry. */
403
404 /* Test for overrun and jump to overrun code if necessary. */
405 if (p_dst>p_dst_post)
406 goto overrun;
407
408 /* The following cascade of if statements efficiently catches and deals */
409 /* with varying degrees of closeness to the end of the input block. */
410 /* When we get very close to the end, we stop updating the table and */
411 /* code the remaining bytes as literals. This makes the code simpler. */
412 unroll=16;
413 if (p_src>p_src_max16)
414 {
415 unroll=1;
416 if (p_src>p_src_max1)
417 {
418 if (p_src==p_src_post)
419 break;
420 else
421 goto literal;
422 }
423 }
424
425 /* This inner unrolled loop processes 'unroll' (whose value is either 1 */
426 /* or 16) items. I have chosen to implement this loop with labels and */
427 /* gotos to heighten the ease with which the loop may be implemented with */
428 /* a single decrement and branch instruction in assembly language and */
429 /* also because the labels act as highly readable place markers. */
430 /* (Also because we jump into the loop for endgame literals (see above)). */
431
432 begin_unrolled_loop:
433
434 /* To process the next phrase, we hash the next three bytes and use */
435 /* the resultant hash table index to look up the hash table. A pointer */
436 /* to the entry is stored in p_h0 so as to avoid an array lookup. The */
437 /* hash table entry *p_h0 is looked up yielding a pointer p to a */
438 /* potential match of the Ziv in the history. */
439 index=HASH(p_src);
440 p_h0=&hash[index];
441 p=*p_h0;
442
443 /* Having looked up the candidate position, we are in a position to */
444 /* attempt a match. The match loop has been unrolled using the PS */
445 /* macro so that failure within the first three bytes automatically */
446 /* results in the literal branch being taken. The coding is simple. */
447 /* p_ziv saves p_src so we can let p_src wander. */
448# define PS *p++!=*p_src++
449 p_ziv=p_src;
450 if (PS || PS || PS)
451 {
452 /* Literal. */
453
454 /* Code the literal byte as itself and a zero control bit. */
455 p_src=p_ziv; literal: *p_dst++=*p_src++; control&=0xFFFEFFFF;
456
457 /* We have just coded a literal. If we had two pending ones, that */
458 /* makes three and we can update the hash table. */
459 if (p_h2!=0)
460 {*p_h2=p_ziv-2;}
461
462 /* In any case, rotate the hash table pointers for next time. */
463 p_h2=p_h1; p_h1=p_h0;
464
465 }
466 else
467 {
468 /* Copy */
469
470 /* Match up to 15 remaining bytes using an unrolled loop and code. */
471#if 0
472 PS || PS || PS || PS || PS || PS || PS || PS ||
473 PS || PS || PS || PS || PS || PS || PS || p_src++;
474#else
475 if (
476 !( PS || PS || PS || PS || PS || PS || PS || PS ||
477 PS || PS || PS || PS || PS || PS || PS )
478 ) p_src++;
479#endif
480 *p_dst++=((index&0xF00)>>4)|(--p_src-p_ziv-3);
481 *p_dst++=index&0xFF;
482
483 /* As we have just coded three bytes, we are now in a position to */
484 /* update the hash table with the literal bytes that were pending */
485 /* upon the arrival of extra context bytes. */
486 if (p_h1!=0)
487 {
488 if (p_h2)
489 {*p_h2=p_ziv-2; p_h2=NULL;}
490 *p_h1=p_ziv-1; p_h1=NULL;
491 }
492
493 /* In any case, we can update the hash table based on the current */
494 /* position as we just coded at least three bytes in a copy items. */
495 *p_h0=p_ziv;
496
497 }
498 control>>=1;
499
500 /* This loop is all set up for a decrement and jump instruction! */
501#ifndef linux
502` end_unrolled_loop: if (--unroll) goto begin_unrolled_loop;
503#else
504 /* end_unrolled_loop: */ if (--unroll) goto begin_unrolled_loop;
505#endif
506
507 /* At this point it will nearly always be the end of a group in which */
508 /* case, we have to do some control-word processing. However, near the */
509 /* end of the input block, the inner unrolled loop is only executed once. */
510 /* This necessitates the 'if' test. */
511 if ((control&TOPWORD)==0)
512 {
513 /* Write the control word to the place we saved for it in the output. */
514 *p_control++= control &0xFF;
515 *p_control = (control>>8) &0xFF;
516
517 /* Reserve the next word in the output block for the control word */
518 /* for the group about to be processed. */
519 p_control=p_dst; p_dst+=2;
520
521 /* Reset the control bits buffer. */
522 control=TOPWORD;
523 }
524
525 } /* End main processing loop. */
526
527 /* After the main processing loop has executed, all the input bytes have */
528 /* been processed. However, the control word has still to be written to the */
529 /* word reserved for it in the output at the start of the most recent group. */
530 /* Before writing, the control word has to be shifted so that all the bits */
531 /* are in the right place. The "empty" bit positions are filled with 1s */
532 /* which partially fill the top word. */
533 while(control&TOPWORD) control>>=1;
534 *p_control++= control &0xFF;
535 *p_control++=(control>>8) &0xFF;
536
537 /* If the last group contained no items, delete the control word too. */
538 if (p_control==p_dst) p_dst-=2;
539
540 /* Write the length of the output block to the dst_len parameter and return. */
541 *p_dst_len=p_dst-p_dst_first;
542 return;
543
544 /* Jump here as soon as an overrun is detected. An overrun is defined to */
545 /* have occurred if p_dst>p_dst_first+src_len. That is, the moment the */
546 /* length of the output written so far exceeds the length of the input block.*/
547 /* The algorithm checks for overruns at least at the end of each group */
548 /* which means that the maximum overrun is MAX_CMP_GROUP bytes. */
549 /* Once an overrun occurs, the only thing to do is to set the copy flag and */
550 /* copy the input over. */
551 overrun:
552#if 0
553 *p_dst_first=FLAG_COPY;
554 fast_copy(p_src_first,p_dst_first+FLAG_BYTES,src_len);
555 *p_dst_len=src_len+FLAG_BYTES;
556#else
557 fast_copy(p_src_first,p_dst_first,src_len);
558 *p_dst_len= -src_len; /* return a negative number to indicate uncompressed data */
559#endif
560}
561
562/******************************************************************************/
563
564/* Input : Hand over the required amount of working memory in p_wrk_mem. */
565/* Input : Specify input block using p_src_first and src_len. */
566/* Input : Point p_dst_first to the start of the output zone. */
567/* Input : Point p_dst_len to a ULONG to receive the output length. */
568/* Input : Input block and output zone must not overlap. User knows */
569/* Input : upperbound on output block length from earlier compression. */
570/* Input : In any case, maximum expansion possible is nine times. */
571/* Output : Length of output block written to *p_dst_len. */
572/* Output : Output block in Mem[p_dst_first..p_dst_first+*p_dst_len-1]. */
573/* Output : Writes only in Mem[p_dst_first..p_dst_first+*p_dst_len-1]. */
574LOCAL void compress_decompress( UBYTE *p_wrk_mem,
575 UBYTE *p_src_first, LONG src_len,
576 UBYTE *p_dst_first, ULONG *p_dst_len)
577{
578 /* Byte pointers p_src and p_dst scan through the input and output blocks. */
579 register UBYTE *p_src = p_src_first+FLAG_BYTES;
580 register UBYTE *p_dst = p_dst_first;
581 /* we need to avoid a SEGV when trying to uncompress corrupt data */
582 register UBYTE *p_dst_post = p_dst_first + *p_dst_len;
583
584 /* The following two variables are never modified and are used to control */
585 /* the main loop. */
586 UBYTE *p_src_post = p_src_first+src_len;
587 UBYTE *p_src_max16 = p_src_first+src_len-(MAX_CMP_GROUP-2);
588
589 /* The hash table is the only resident of the working memory. The hash table */
590 /* contains HASH_TABLE_LENGTH=4096 pointers to positions in the history. To */
591 /* keep Macintoshes happy, it is longword aligned. */
592 UBYTE **hash = (UBYTE **) ULONG_ALIGN_UP(p_wrk_mem);
593
594 /* The variable 'control' is used to buffer the control bits which appear in */
595 /* groups of 16 bits (control words) at the start of each compressed group. */
596 /* When each group is read, bit 16 of the register is set to one. Whenever */
597 /* a new bit is needed, the register is shifted right. When the value of the */
598 /* register becomes 1, we know that we have reached the end of a group. */
599 /* Initializing the register to 1 thus instructs the code to follow that it */
600 /* should read a new control word immediately. */
601 register ULONG control=1;
602
603 /* The value of 'literals' is always in the range 0..3. It is the number of */
604 /* consecutive literal items just seen. We have to record this number so as */
605 /* to know when to update the hash table. When literals gets to 3, there */
606 /* have been three consecutive literals and we can update at the position of */
607 /* the oldest of the three. */
608 register UWORD literals=0;
609
610 /* Check the leading copy flag to see if the compressor chose to use a copy */
611 /* operation instead of a compression operation. If a copy operation was */
612 /* used, then all we need to do is copy the data over, set the output length */
613 /* and return. */
614#if 0
615 if (*p_src_first==FLAG_COPY)
616 {
617 fast_copy(p_src_first+FLAG_BYTES,p_dst_first,src_len-FLAG_BYTES);
618 *p_dst_len=src_len-FLAG_BYTES;
619 return;
620 }
621#else
622 if ( src_len < 0 )
623 {
624 fast_copy(p_src_first,p_dst_first,-src_len );
625 *p_dst_len = (ULONG)-src_len;
626 return;
627 }
628#endif
629
630 /* Initialize all elements of the hash table to point to a constant string. */
631 /* Use of an unrolled loop speeds this up considerably. */
632 {UWORD i; UBYTE **p_h=hash;
633# define ZJ *p_h++=START_STRING_18
634 for (i=0;i<256;i++) /* 256=HASH_TABLE_LENGTH/16. */
635 {ZJ;ZJ;ZJ;ZJ;
636 ZJ;ZJ;ZJ;ZJ;
637 ZJ;ZJ;ZJ;ZJ;
638 ZJ;ZJ;ZJ;ZJ;}
639 }
640
641 /* The outer loop processes either 1 or 16 items per iteration depending on */
642 /* how close p_src is to the end of the input block. */
643 while (p_src!=p_src_post)
644 {/* Start of outer loop */
645
646 register UWORD unroll; /* Counts unrolled loop executions. */
647
648 /* When 'control' has the value 1, it means that the 16 buffered control */
649 /* bits that were read in at the start of the current group have all been */
650 /* shifted out and that all that is left is the 1 bit that was injected */
651 /* into bit 16 at the start of the current group. When we reach the end */
652 /* of a group, we have to load a new control word and inject a new 1 bit. */
653 if (control==1)
654 {
655 control=0x10000|*p_src++;
656 control|=(*p_src++)<<8;
657 }
658
659 /* If it is possible that we are within 16 groups from the end of the */
660 /* input, execute the unrolled loop only once, else process a whole group */
661 /* of 16 items by looping 16 times. */
662 unroll= p_src<=p_src_max16 ? 16 : 1;
663
664 /* This inner loop processes one phrase (item) per iteration. */
665 while (unroll--)
666 { /* Begin unrolled inner loop. */
667
668 /* Process a literal or copy item depending on the next control bit. */
669 if (control&1)
670 {
671 /* Copy item. */
672
673 register UBYTE *p; /* Points to place from which to copy. */
674 register UWORD lenmt; /* Length of copy item minus three. */
675 register UBYTE **p_hte; /* Pointer to current hash table entry.*/
676 register UBYTE *p_ziv=p_dst; /* Pointer to start of current Ziv. */
677
678 /* Read and dismantle the copy word. Work out from where to copy. */
679 lenmt=*p_src++;
680 p_hte=&hash[((lenmt&0xF0)<<4)|*p_src++];
681 p=*p_hte;
682 lenmt&=0xF;
683
684 /* Now perform the copy using a half unrolled loop. */
685 *p_dst++=*p++;
686 *p_dst++=*p++;
687 *p_dst++=*p++;
688 while (lenmt--)
689 *p_dst++=*p++;
690
691 /* Because we have just received 3 or more bytes in a copy item */
692 /* (whose bytes we have just installed in the output), we are now */
693 /* in a position to flush all the pending literal hashings that had */
694 /* been postponed for lack of bytes. */
695 if (literals>0)
696 {
697 register UBYTE *r=p_ziv-literals;
698 hash[HASH(r)]=r;
699 if (literals==2)
700 {r++; hash[HASH(r)]=r;}
701 literals=0;
702 }
703
704 /* In any case, we can immediately update the hash table with the */
705 /* current position. We don't need to do a HASH(...) to work out */
706 /* where to put the pointer, as the compressor just told us!!! */
707 *p_hte=p_ziv;
708
709 }
710 else
711 {
712 /* Literal item. */
713
714 /* Copy over the literal byte. */
715 *p_dst++=*p_src++;
716
717 /* If we now have three literals waiting to be hashed into the hash */
718 /* table, we can do one of them now (because there are three). */
719 if (++literals == 3)
720 {register UBYTE *p=p_dst-3; hash[HASH(p)]=p; literals=2;}
721 }
722
723 /* Shift the control buffer so the next control bit is in bit 0. */
724 control>>=1;
725#if 1
726 if (p_dst > p_dst_post)
727 {
728 /* Shit: we tried to decompress corrupt data */
729 *p_dst_len = 0;
730 return;
731 }
732#endif
733 } /* End unrolled inner loop. */
734
735 } /* End of outer loop */
736
737 /* Write the length of the decompressed data before returning. */
738 *p_dst_len=p_dst-p_dst_first;
739}
740
741/******************************************************************************/
742/* End of LZRW3.C */
743/******************************************************************************/
diff --git a/drivers/char/ftape/compressor/lzrw3.h b/drivers/char/ftape/compressor/lzrw3.h
deleted file mode 100644
index 533feba47526..000000000000
--- a/drivers/char/ftape/compressor/lzrw3.h
+++ /dev/null
@@ -1,253 +0,0 @@
1#ifndef _LZRW3_H
2#define _LZRW3_H
3/*
4 * $Source: /homes/cvs/ftape-stacked/ftape/compressor/lzrw3.h,v $
5 * $Revision: 1.1 $
6 * $Date: 1997/10/05 19:12:30 $
7 *
8 * include files for lzrw3. Only slighty modified from the original
9 * version. Assembles the three include files compress.h, port.h and
10 * fastcopy.h from the original lzrw3 package.
11 *
12 */
13
14#include <linux/types.h>
15#include <linux/string.h>
16
17/******************************************************************************/
18/* */
19/* COMPRESS.H */
20/* */
21/******************************************************************************/
22/* */
23/* Author : Ross Williams. */
24/* Date : December 1989. */
25/* */
26/* This header file defines the interface to a set of functions called */
27/* 'compress', each member of which implements a particular data compression */
28/* algorithm. */
29/* */
30/* Normally in C programming, for each .H file, there is a corresponding .C */
31/* file that implements the functions promised in the .H file. */
32/* Here, there are many .C files corresponding to this header file. */
33/* Each comforming implementation file contains a single function */
34/* called 'compress' that implements a single data compression */
35/* algorithm that conforms with the interface specified in this header file. */
36/* Only one algorithm can be linked in at a time in this organization. */
37/* */
38/******************************************************************************/
39/* */
40/* DEFINITION OF FUNCTION COMPRESS */
41/* =============================== */
42/* */
43/* Summary of Function Compress */
44/* ---------------------------- */
45/* The action that 'compress' takes depends on its first argument called */
46/* 'action'. The function provides three actions: */
47/* */
48/* - Return information about the algorithm. */
49/* - Compress a block of memory. */
50/* - Decompress a block of memory. */
51/* */
52/* Parameters */
53/* ---------- */
54/* See the formal C definition later for a description of the parameters. */
55/* */
56/* Constants */
57/* --------- */
58/* COMPRESS_OVERRUN: The constant COMPRESS_OVERRUN defines by how many bytes */
59/* an algorithm is allowed to expand a block during a compression operation. */
60/* */
61/* Although compression algorithms usually compress data, there will always */
62/* be data that a given compressor will expand (this can be proven). */
63/* Fortunately, the degree of expansion can be limited to a single bit, by */
64/* copying over the input data if the data gets bigger during compression. */
65/* To allow for this possibility, the first bit of a compressed */
66/* representation can be used as a flag indicating whether the */
67/* input data was copied over, or truly compressed. In practice, the first */
68/* byte would be used to store this bit so as to maintain byte alignment. */
69/* */
70/* Unfortunately, in general, the only way to tell if an algorithm will */
71/* expand a particular block of data is to run the algorithm on the data. */
72/* If the algorithm does not continuously monitor how many output bytes it */
73/* has written, it might write an output block far larger than the input */
74/* block before realizing that it has done so. */
75/* On the other hand, continuous checks on output length are inefficient. */
76/* */
77/* To cater for all these problems, this interface definition: */
78/* > Allows a compression algorithm to return an output block that is up to */
79/* COMPRESS_OVERRUN bytes longer than the input block. */
80/* > Allows a compression algorithm to write up to COMPRESS_OVERRUN bytes */
81/* more than the length of the input block to the memory of the output */
82/* block regardless of the length of the output block eventually returned. */
83/* This allows an algorithm to overrun the length of the input block in the */
84/* output block by up to COMPRESS_OVERRUN bytes between expansion checks. */
85/* */
86/* The problem does not arise for decompression. */
87/* */
88/* Identity Action */
89/* --------------- */
90/* > action must be COMPRESS_ACTION_IDENTITY. */
91/* > p_dst_len must point to a longword to receive a longword address. */
92/* > The value of the other parameters does not matter. */
93/* > After execution, the longword that p_dst_len points to will be a pointer */
94/* to a structure of type compress_identity. */
95/* Thus, for example, after the call, (*p_dst_len)->memory will return the */
96/* number of bytes of working memory that the algorithm requires to run. */
97/* > The values of the identity structure returned are fixed constant */
98/* attributes of the algorithm and must not vary from call to call. */
99/* */
100/* Common Requirements for Compression and Decompression Actions */
101/* ------------------------------------------------------------- */
102/* > wrk_mem must point to an unused block of memory of a length specified in */
103/* the algorithm's identity block. The identity block can be obtained by */
104/* making a separate call to compress, specifying the identity action. */
105/* > The INPUT BLOCK is defined to be Memory[src_addr,src_addr+src_len-1]. */
106/* > dst_len will be used to denote *p_dst_len. */
107/* > dst_len is not read by compress, only written. */
108/* > The value of dst_len is defined only upon termination. */
109/* > The OUTPUT BLOCK is defined to be Memory[dst_addr,dst_addr+dst_len-1]. */
110/* */
111/* Compression Action */
112/* ------------------ */
113/* > action must be COMPRESS_ACTION_COMPRESS. */
114/* > src_len must be in the range [0,COMPRESS_MAX_ORG]. */
115/* > The OUTPUT ZONE is defined to be */
116/* Memory[dst_addr,dst_addr+src_len-1+COMPRESS_OVERRUN]. */
117/* > The function can modify any part of the output zone regardless of the */
118/* final length of the output block. */
119/* > The input block and the output zone must not overlap. */
120/* > dst_len will be in the range [0,src_len+COMPRESS_OVERRUN]. */
121/* > dst_len will be in the range [0,COMPRESS_MAX_COM] (from prev fact). */
122/* > The output block will consist of a representation of the input block. */
123/* */
124/* Decompression Action */
125/* -------------------- */
126/* > action must be COMPRESS_ACTION_DECOMPRESS. */
127/* > The input block must be the result of an earlier compression operation. */
128/* > If the previous fact is true, the following facts must also be true: */
129/* > src_len will be in the range [0,COMPRESS_MAX_COM]. */
130/* > dst_len will be in the range [0,COMPRESS_MAX_ORG]. */
131/* > The input and output blocks must not overlap. */
132/* > Only the output block is modified. */
133/* > Upon termination, the output block will consist of the bytes contained */
134/* in the input block passed to the earlier compression operation. */
135/* */
136/******************************************************************************/
137
138/******************************************************************************/
139/* */
140/* PORT.H */
141/* */
142/******************************************************************************/
143/* */
144/* This module contains macro definitions and types that are likely to */
145/* change between computers. */
146/* */
147/******************************************************************************/
148
149#ifndef DONE_PORT /* Only do this if not previously done. */
150
151 #ifdef THINK_C
152 #define UBYTE unsigned char /* Unsigned byte */
153 #define UWORD unsigned int /* Unsigned word (2 bytes) */
154 #define ULONG unsigned long /* Unsigned word (4 bytes) */
155 #define BOOL unsigned char /* Boolean */
156 #define FOPEN_BINARY_READ "rb" /* Mode string for binary reading. */
157 #define FOPEN_BINARY_WRITE "wb" /* Mode string for binary writing. */
158 #define FOPEN_TEXT_APPEND "a" /* Mode string for text appending. */
159 #define REAL double /* USed for floating point stuff. */
160 #endif
161 #if defined(LINUX) || defined(linux)
162 #define UBYTE __u8 /* Unsigned byte */
163 #define UWORD __u16 /* Unsigned word (2 bytes) */
164 #define ULONG __u32 /* Unsigned word (4 bytes) */
165 #define LONG __s32 /* Signed word (4 bytes) */
166 #define BOOL is not used here /* Boolean */
167 #define FOPEN_BINARY_READ not used /* Mode string for binary reading. */
168 #define FOPEN_BINARY_WRITE not used /* Mode string for binary writing. */
169 #define FOPEN_TEXT_APPEND not used /* Mode string for text appending. */
170 #define REAL not used /* USed for floating point stuff. */
171 #ifndef TRUE
172 #define TRUE 1
173 #endif
174 #endif
175
176 #define DONE_PORT /* Don't do all this again. */
177 #define MALLOC_FAIL NULL /* Failure status from malloc() */
178 #define LOCAL static /* For non-exported routines. */
179 #define EXPORT /* Signals exported function. */
180 #define then /* Useful for aligning ifs. */
181
182#endif
183
184/******************************************************************************/
185/* End of PORT.H */
186/******************************************************************************/
187
188#define COMPRESS_ACTION_IDENTITY 0
189#define COMPRESS_ACTION_COMPRESS 1
190#define COMPRESS_ACTION_DECOMPRESS 2
191
192#define COMPRESS_OVERRUN 1024
193#define COMPRESS_MAX_COM 0x70000000
194#define COMPRESS_MAX_ORG (COMPRESS_MAX_COM-COMPRESS_OVERRUN)
195
196#define COMPRESS_MAX_STRLEN 255
197
198/* The following structure provides information about the algorithm. */
199/* > The top bit of id must be zero. The remaining bits must be chosen by */
200/* the author of the algorithm by tossing a coin 31 times. */
201/* > The amount of memory requested by the algorithm is specified in bytes */
202/* and must be in the range [0,0x70000000]. */
203/* > All strings s must be such that strlen(s)<=COMPRESS_MAX_STRLEN. */
204struct compress_identity
205 {
206 ULONG id; /* Identifying number of algorithm. */
207 ULONG memory; /* Number of bytes of working memory required. */
208
209 char *name; /* Name of algorithm. */
210 char *version; /* Version number. */
211 char *date; /* Date of release of this version. */
212 char *copyright; /* Copyright message. */
213
214 char *author; /* Author of algorithm. */
215 char *affiliation; /* Affiliation of author. */
216 char *vendor; /* Where the algorithm can be obtained. */
217 };
218
219void lzrw3_compress( /* Single function interface to compression algorithm. */
220UWORD action, /* Action to be performed. */
221UBYTE *wrk_mem, /* Working memory temporarily given to routine to use. */
222UBYTE *src_adr, /* Address of input data. */
223LONG src_len, /* Length of input data. */
224UBYTE *dst_adr, /* Address of output data. */
225void *p_dst_len /* Pointer to a longword where routine will write: */
226 /* If action=..IDENTITY => Adr of id structure. */
227 /* If action=..COMPRESS => Length of output data. */
228 /* If action=..DECOMPRESS => Length of output data. */
229);
230
231/******************************************************************************/
232/* End of COMPRESS.H */
233/******************************************************************************/
234
235
236/******************************************************************************/
237/* fast_copy.h */
238/******************************************************************************/
239
240/* This function copies a block of memory very quickly. */
241/* The exact speed depends on the relative alignment of the blocks of memory. */
242/* PRE : 0<=src_len<=(2^32)-1 . */
243/* PRE : Source and destination blocks must not overlap. */
244/* POST : MEM[dst_adr,dst_adr+src_len-1]=MEM[src_adr,src_adr+src_len-1]. */
245/* POST : MEM[dst_adr,dst_adr+src_len-1] is the only memory changed. */
246
247#define fast_copy(src,dst,len) memcpy(dst,src,len)
248
249/******************************************************************************/
250/* End of fast_copy.h */
251/******************************************************************************/
252
253#endif
diff --git a/drivers/char/ftape/compressor/zftape-compress.c b/drivers/char/ftape/compressor/zftape-compress.c
deleted file mode 100644
index 65ffc0be3df9..000000000000
--- a/drivers/char/ftape/compressor/zftape-compress.c
+++ /dev/null
@@ -1,1203 +0,0 @@
1/*
2 * Copyright (C) 1994-1997 Claus-Justus Heine
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2, or (at
7 your option) any later version.
8
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
17 USA.
18
19 *
20 * This file implements a "generic" interface between the *
21 * zftape-driver and a compression-algorithm. The *
22 * compression-algorithm currently used is a LZ77. I use the *
23 * implementation lzrw3 by Ross N. Williams (Renaissance *
24 * Software). The compression program itself is in the file
25 * lzrw3.c * and lzrw3.h. To adopt another compression algorithm
26 * the functions * zft_compress() and zft_uncompress() must be
27 * changed * appropriately. See below.
28 */
29
30#include <linux/errno.h>
31#include <linux/mm.h>
32#include <linux/module.h>
33
34#include <linux/zftape.h>
35
36#include <asm/uaccess.h>
37
38#include "../zftape/zftape-init.h"
39#include "../zftape/zftape-eof.h"
40#include "../zftape/zftape-ctl.h"
41#include "../zftape/zftape-write.h"
42#include "../zftape/zftape-read.h"
43#include "../zftape/zftape-rw.h"
44#include "../compressor/zftape-compress.h"
45#include "../zftape/zftape-vtbl.h"
46#include "../compressor/lzrw3.h"
47
48/*
49 * global variables
50 */
51
52/* I handle the allocation of this buffer as a special case, because
53 * it's size varies depending on the tape length inserted.
54 */
55
56/* local variables
57 */
58static void *zftc_wrk_mem = NULL;
59static __u8 *zftc_buf = NULL;
60static void *zftc_scratch_buf = NULL;
61
62/* compression statistics
63 */
64static unsigned int zftc_wr_uncompressed = 0;
65static unsigned int zftc_wr_compressed = 0;
66static unsigned int zftc_rd_uncompressed = 0;
67static unsigned int zftc_rd_compressed = 0;
68
69/* forward */
70static int zftc_write(int *write_cnt,
71 __u8 *dst_buf, const int seg_sz,
72 const __u8 __user *src_buf, const int req_len,
73 const zft_position *pos, const zft_volinfo *volume);
74static int zftc_read(int *read_cnt,
75 __u8 __user *dst_buf, const int to_do,
76 const __u8 *src_buf, const int seg_sz,
77 const zft_position *pos, const zft_volinfo *volume);
78static int zftc_seek(unsigned int new_block_pos,
79 zft_position *pos, const zft_volinfo *volume,
80 __u8 *buffer);
81static void zftc_lock (void);
82static void zftc_reset (void);
83static void zftc_cleanup(void);
84static void zftc_stats (void);
85
86/* compressed segment. This conforms to QIC-80-MC, Revision K.
87 *
88 * Rev. K applies to tapes with `fixed length format' which is
89 * indicated by format code 2,3 and 5. See below for format code 4 and 6
90 *
91 * 2 bytes: offset of compression segment structure
92 * 29k > offset >= 29k-18: data from previous segment ens in this
93 * segment and no compressed block starts
94 * in this segment
95 * offset == 0: data from previous segment occupies entire
96 * segment and continues in next segment
97 * n bytes: remainder from previous segment
98 *
99 * Rev. K:
100 * 4 bytes: 4 bytes: files set byte offset
101 * Post Rev. K and QIC-3020/3020:
102 * 8 bytes: 8 bytes: files set byte offset
103 * 2 bytes: byte count N (amount of data following)
104 * bit 15 is set if data is compressed, bit 15 is not
105 * set if data is uncompressed
106 * N bytes: data (as much as specified in the byte count)
107 * 2 bytes: byte count N_1 of next cluster
108 * N_1 bytes: data of next cluset
109 * 2 bytes: byte count N_2 of next cluster
110 * N_2 bytes: ...
111 *
112 * Note that the `N' byte count accounts only for the bytes that in the
113 * current segment if the cluster spans to the next segment.
114 */
115
116typedef struct
117{
118 int cmpr_pos; /* actual position in compression buffer */
119 int cmpr_sz; /* what is left in the compression buffer
120 * when copying the compressed data to the
121 * deblock buffer
122 */
123 unsigned int first_block; /* location of header information in
124 * this segment
125 */
126 unsigned int count; /* amount of data of current block
127 * contained in current segment
128 */
129 unsigned int offset; /* offset in current segment */
130 unsigned int spans:1; /* might continue in next segment */
131 unsigned int uncmpr; /* 0x8000 if this block contains
132 * uncompressed data
133 */
134 __s64 foffs; /* file set byte offset, same as in
135 * compression map segment
136 */
137} cmpr_info;
138
139static cmpr_info cseg; /* static data. Must be kept uptodate and shared by
140 * read, write and seek functions
141 */
142
143#define DUMP_CMPR_INFO(level, msg, info) \
144 TRACE(level, msg "\n" \
145 KERN_INFO "cmpr_pos : %d\n" \
146 KERN_INFO "cmpr_sz : %d\n" \
147 KERN_INFO "first_block: %d\n" \
148 KERN_INFO "count : %d\n" \
149 KERN_INFO "offset : %d\n" \
150 KERN_INFO "spans : %d\n" \
151 KERN_INFO "uncmpr : 0x%04x\n" \
152 KERN_INFO "foffs : " LL_X, \
153 (info)->cmpr_pos, (info)->cmpr_sz, (info)->first_block, \
154 (info)->count, (info)->offset, (info)->spans == 1, \
155 (info)->uncmpr, LL((info)->foffs))
156
157/* dispatch compression segment info, return error code
158 *
159 * afterwards, cseg->offset points to start of data of the NEXT
160 * compressed block, and cseg->count contains the amount of data
161 * left in the actual compressed block. cseg->spans is set to 1 if
162 * the block is continued in the following segment. Otherwise it is
163 * set to 0.
164 */
165static int get_cseg (cmpr_info *cinfo, const __u8 *buff,
166 const unsigned int seg_sz,
167 const zft_volinfo *volume)
168{
169 TRACE_FUN(ft_t_flow);
170
171 cinfo->first_block = GET2(buff, 0);
172 if (cinfo->first_block == 0) { /* data spans to next segment */
173 cinfo->count = seg_sz - sizeof(__u16);
174 cinfo->offset = seg_sz;
175 cinfo->spans = 1;
176 } else { /* cluster definetely ends in this segment */
177 if (cinfo->first_block > seg_sz) {
178 /* data corrupted */
179 TRACE_ABORT(-EIO, ft_t_err, "corrupted data:\n"
180 KERN_INFO "segment size: %d\n"
181 KERN_INFO "first block : %d",
182 seg_sz, cinfo->first_block);
183 }
184 cinfo->count = cinfo->first_block - sizeof(__u16);
185 cinfo->offset = cinfo->first_block;
186 cinfo->spans = 0;
187 }
188 /* now get the offset the first block should have in the
189 * uncompressed data stream.
190 *
191 * For this magic `18' refer to CRF-3 standard or QIC-80MC,
192 * Rev. K.
193 */
194 if ((seg_sz - cinfo->offset) > 18) {
195 if (volume->qic113) { /* > revision K */
196 TRACE(ft_t_data_flow, "New QIC-113 compliance");
197 cinfo->foffs = GET8(buff, cinfo->offset);
198 cinfo->offset += sizeof(__s64);
199 } else {
200 TRACE(/* ft_t_data_flow */ ft_t_noise, "pre QIC-113 version");
201 cinfo->foffs = (__s64)GET4(buff, cinfo->offset);
202 cinfo->offset += sizeof(__u32);
203 }
204 }
205 if (cinfo->foffs > volume->size) {
206 TRACE_ABORT(-EIO, ft_t_err, "Inconsistency:\n"
207 KERN_INFO "offset in current volume: %d\n"
208 KERN_INFO "size of current volume : %d",
209 (int)(cinfo->foffs>>10), (int)(volume->size>>10));
210 }
211 if (cinfo->cmpr_pos + cinfo->count > volume->blk_sz) {
212 TRACE_ABORT(-EIO, ft_t_err, "Inconsistency:\n"
213 KERN_INFO "block size : %d\n"
214 KERN_INFO "data record: %d",
215 volume->blk_sz, cinfo->cmpr_pos + cinfo->count);
216 }
217 DUMP_CMPR_INFO(ft_t_noise /* ft_t_any */, "", cinfo);
218 TRACE_EXIT 0;
219}
220
221/* This one is called, when a new cluster starts in same segment.
222 *
223 * Note: if this is the first cluster in the current segment, we must
224 * not check whether there are more than 18 bytes available because
225 * this have already been done in get_cseg() and there may be less
226 * than 18 bytes available due to header information.
227 *
228 */
229static void get_next_cluster(cmpr_info *cluster, const __u8 *buff,
230 const int seg_sz, const int finish)
231{
232 TRACE_FUN(ft_t_flow);
233
234 if (seg_sz - cluster->offset > 18 || cluster->foffs != 0) {
235 cluster->count = GET2(buff, cluster->offset);
236 cluster->uncmpr = cluster->count & 0x8000;
237 cluster->count -= cluster->uncmpr;
238 cluster->offset += sizeof(__u16);
239 cluster->foffs = 0;
240 if ((cluster->offset + cluster->count) < seg_sz) {
241 cluster->spans = 0;
242 } else if (cluster->offset + cluster->count == seg_sz) {
243 cluster->spans = !finish;
244 } else {
245 /* either an error or a volume written by an
246 * old version. If this is a data error, then we'll
247 * catch it later.
248 */
249 TRACE(ft_t_data_flow, "Either error or old volume");
250 cluster->spans = 1;
251 cluster->count = seg_sz - cluster->offset;
252 }
253 } else {
254 cluster->count = 0;
255 cluster->spans = 0;
256 cluster->foffs = 0;
257 }
258 DUMP_CMPR_INFO(ft_t_noise /* ft_t_any */ , "", cluster);
259 TRACE_EXIT;
260}
261
262static void zftc_lock(void)
263{
264}
265
266/* this function is needed for zftape_reset_position in zftape-io.c
267 */
268static void zftc_reset(void)
269{
270 TRACE_FUN(ft_t_flow);
271
272 memset((void *)&cseg, '\0', sizeof(cseg));
273 zftc_stats();
274 TRACE_EXIT;
275}
276
277static int cmpr_mem_initialized = 0;
278static unsigned int alloc_blksz = 0;
279
280static int zft_allocate_cmpr_mem(unsigned int blksz)
281{
282 TRACE_FUN(ft_t_flow);
283
284 if (cmpr_mem_initialized && blksz == alloc_blksz) {
285 TRACE_EXIT 0;
286 }
287 TRACE_CATCH(zft_vmalloc_once(&zftc_wrk_mem, CMPR_WRK_MEM_SIZE),
288 zftc_cleanup());
289 TRACE_CATCH(zft_vmalloc_always(&zftc_buf, blksz + CMPR_OVERRUN),
290 zftc_cleanup());
291 alloc_blksz = blksz;
292 TRACE_CATCH(zft_vmalloc_always(&zftc_scratch_buf, blksz+CMPR_OVERRUN),
293 zftc_cleanup());
294 cmpr_mem_initialized = 1;
295 TRACE_EXIT 0;
296}
297
298static void zftc_cleanup(void)
299{
300 TRACE_FUN(ft_t_flow);
301
302 zft_vfree(&zftc_wrk_mem, CMPR_WRK_MEM_SIZE);
303 zft_vfree(&zftc_buf, alloc_blksz + CMPR_OVERRUN);
304 zft_vfree(&zftc_scratch_buf, alloc_blksz + CMPR_OVERRUN);
305 cmpr_mem_initialized = alloc_blksz = 0;
306 TRACE_EXIT;
307}
308
309/*****************************************************************************
310 * *
311 * The following two functions "ftape_compress()" and *
312 * "ftape_uncompress()" are the interface to the actual compression *
313 * algorithm (i.e. they are calling the "compress()" function from *
314 * the lzrw3 package for now). These routines could quite easily be *
315 * changed to adopt another compression algorithm instead of lzrw3, *
316 * which currently is used. *
317 * *
318 *****************************************************************************/
319
320/* called by zft_compress_write() to perform the compression. Must
321 * return the size of the compressed data.
322 *
323 * NOTE: The size of the compressed data should not exceed the size of
324 * the uncompressed data. Most compression algorithms have means
325 * to store data unchanged if the "compressed" data amount would
326 * exceed the original one. Mostly this is done by storing some
327 * flag-bytes in front of the compressed data to indicate if it
328 * is compressed or not. Thus the worst compression result
329 * length is the original length plus those flag-bytes.
330 *
331 * We don't want that, as the QIC-80 standard provides a means
332 * of marking uncompressed blocks by simply setting bit 15 of
333 * the compressed block's length. Thus a compessed block can
334 * have at most a length of 2^15-1 bytes. The QIC-80 standard
335 * restricts the block-length even further, allowing only 29k -
336 * 6 bytes.
337 *
338 * Currently, the maximum blocksize used by zftape is 28k.
339 *
340 * In short: don't exceed the length of the input-package, set
341 * bit 15 of the compressed size to 1 if you have copied data
342 * instead of compressing it.
343 */
344static int zft_compress(__u8 *in_buffer, unsigned int in_sz, __u8 *out_buffer)
345{
346 __s32 compressed_sz;
347 TRACE_FUN(ft_t_flow);
348
349
350 lzrw3_compress(COMPRESS_ACTION_COMPRESS, zftc_wrk_mem,
351 in_buffer, in_sz, out_buffer, &compressed_sz);
352 if (TRACE_LEVEL >= ft_t_info) {
353 /* the compiler will optimize this away when
354 * compiled with NO_TRACE_AT_ALL option
355 */
356 TRACE(ft_t_data_flow, "\n"
357 KERN_INFO "before compression: %d bytes\n"
358 KERN_INFO "after compresison : %d bytes",
359 in_sz,
360 (int)(compressed_sz < 0
361 ? -compressed_sz : compressed_sz));
362 /* for statistical purposes
363 */
364 zftc_wr_compressed += (compressed_sz < 0
365 ? -compressed_sz : compressed_sz);
366 zftc_wr_uncompressed += in_sz;
367 }
368 TRACE_EXIT (int)compressed_sz;
369}
370
371/* called by zft_compress_read() to decompress the data. Must
372 * return the size of the decompressed data for sanity checks
373 * (compared with zft_blk_sz)
374 *
375 * NOTE: Read the note for zft_compress() above! If bit 15 of the
376 * parameter in_sz is set, then the data in in_buffer isn't
377 * compressed, which must be handled by the un-compression
378 * algorithm. (I changed lzrw3 to handle this.)
379 *
380 * The parameter max_out_sz is needed to prevent buffer overruns when
381 * uncompressing corrupt data.
382 */
383static unsigned int zft_uncompress(__u8 *in_buffer,
384 int in_sz,
385 __u8 *out_buffer,
386 unsigned int max_out_sz)
387{
388 TRACE_FUN(ft_t_flow);
389
390 lzrw3_compress(COMPRESS_ACTION_DECOMPRESS, zftc_wrk_mem,
391 in_buffer, (__s32)in_sz,
392 out_buffer, (__u32 *)&max_out_sz);
393
394 if (TRACE_LEVEL >= ft_t_info) {
395 TRACE(ft_t_data_flow, "\n"
396 KERN_INFO "before decompression: %d bytes\n"
397 KERN_INFO "after decompression : %d bytes",
398 in_sz < 0 ? -in_sz : in_sz,(int)max_out_sz);
399 /* for statistical purposes
400 */
401 zftc_rd_compressed += in_sz < 0 ? -in_sz : in_sz;
402 zftc_rd_uncompressed += max_out_sz;
403 }
404 TRACE_EXIT (unsigned int)max_out_sz;
405}
406
407/* print some statistics about the efficiency of the compression to
408 * the kernel log
409 */
410static void zftc_stats(void)
411{
412 TRACE_FUN(ft_t_flow);
413
414 if (TRACE_LEVEL < ft_t_info) {
415 TRACE_EXIT;
416 }
417 if (zftc_wr_uncompressed != 0) {
418 if (zftc_wr_compressed > (1<<14)) {
419 TRACE(ft_t_info, "compression statistics (writing):\n"
420 KERN_INFO " compr./uncmpr. : %3d %%",
421 (((zftc_wr_compressed>>10) * 100)
422 / (zftc_wr_uncompressed>>10)));
423 } else {
424 TRACE(ft_t_info, "compression statistics (writing):\n"
425 KERN_INFO " compr./uncmpr. : %3d %%",
426 ((zftc_wr_compressed * 100)
427 / zftc_wr_uncompressed));
428 }
429 }
430 if (zftc_rd_uncompressed != 0) {
431 if (zftc_rd_compressed > (1<<14)) {
432 TRACE(ft_t_info, "compression statistics (reading):\n"
433 KERN_INFO " compr./uncmpr. : %3d %%",
434 (((zftc_rd_compressed>>10) * 100)
435 / (zftc_rd_uncompressed>>10)));
436 } else {
437 TRACE(ft_t_info, "compression statistics (reading):\n"
438 KERN_INFO " compr./uncmpr. : %3d %%",
439 ((zftc_rd_compressed * 100)
440 / zftc_rd_uncompressed));
441 }
442 }
443 /* only print it once: */
444 zftc_wr_uncompressed =
445 zftc_wr_compressed =
446 zftc_rd_uncompressed =
447 zftc_rd_compressed = 0;
448 TRACE_EXIT;
449}
450
451/* start new compressed block
452 */
453static int start_new_cseg(cmpr_info *cluster,
454 char *dst_buf,
455 const zft_position *pos,
456 const unsigned int blk_sz,
457 const char *src_buf,
458 const int this_segs_sz,
459 const int qic113)
460{
461 int size_left;
462 int cp_cnt;
463 int buf_pos;
464 TRACE_FUN(ft_t_flow);
465
466 size_left = this_segs_sz - sizeof(__u16) - cluster->cmpr_sz;
467 TRACE(ft_t_data_flow,"\n"
468 KERN_INFO "segment size : %d\n"
469 KERN_INFO "compressed_sz: %d\n"
470 KERN_INFO "size_left : %d",
471 this_segs_sz, cluster->cmpr_sz, size_left);
472 if (size_left > 18) { /* start a new cluseter */
473 cp_cnt = cluster->cmpr_sz;
474 cluster->cmpr_sz = 0;
475 buf_pos = cp_cnt + sizeof(__u16);
476 PUT2(dst_buf, 0, buf_pos);
477
478 if (qic113) {
479 __s64 foffs = pos->volume_pos;
480 if (cp_cnt) foffs += (__s64)blk_sz;
481
482 TRACE(ft_t_data_flow, "new style QIC-113 header");
483 PUT8(dst_buf, buf_pos, foffs);
484 buf_pos += sizeof(__s64);
485 } else {
486 __u32 foffs = (__u32)pos->volume_pos;
487 if (cp_cnt) foffs += (__u32)blk_sz;
488
489 TRACE(ft_t_data_flow, "old style QIC-80MC header");
490 PUT4(dst_buf, buf_pos, foffs);
491 buf_pos += sizeof(__u32);
492 }
493 } else if (size_left >= 0) {
494 cp_cnt = cluster->cmpr_sz;
495 cluster->cmpr_sz = 0;
496 buf_pos = cp_cnt + sizeof(__u16);
497 PUT2(dst_buf, 0, buf_pos);
498 /* zero unused part of segment. */
499 memset(dst_buf + buf_pos, '\0', size_left);
500 buf_pos = this_segs_sz;
501 } else { /* need entire segment and more space */
502 PUT2(dst_buf, 0, 0);
503 cp_cnt = this_segs_sz - sizeof(__u16);
504 cluster->cmpr_sz -= cp_cnt;
505 buf_pos = this_segs_sz;
506 }
507 memcpy(dst_buf + sizeof(__u16), src_buf + cluster->cmpr_pos, cp_cnt);
508 cluster->cmpr_pos += cp_cnt;
509 TRACE_EXIT buf_pos;
510}
511
512/* return-value: the number of bytes removed from the user-buffer
513 * `src_buf' or error code
514 *
515 * int *write_cnt : how much actually has been moved to the
516 * dst_buf. Need not be initialized when
517 * function returns with an error code
518 * (negativ return value)
519 * __u8 *dst_buf : kernel space buffer where the has to be
520 * copied to. The contents of this buffers
521 * goes to a specific segment.
522 * const int seg_sz : the size of the segment dst_buf will be
523 * copied to.
524 * const zft_position *pos : struct containing the coordinates in
525 * the current volume (byte position,
526 * segment id of current segment etc)
527 * const zft_volinfo *volume: information about the current volume,
528 * size etc.
529 * const __u8 *src_buf : user space buffer that contains the
530 * data the user wants to be written to
531 * tape.
532 * const int req_len : the amount of data the user wants to be
533 * written to tape.
534 */
535static int zftc_write(int *write_cnt,
536 __u8 *dst_buf, const int seg_sz,
537 const __u8 __user *src_buf, const int req_len,
538 const zft_position *pos, const zft_volinfo *volume)
539{
540 int req_len_left = req_len;
541 int result;
542 int len_left;
543 int buf_pos_write = pos->seg_byte_pos;
544 TRACE_FUN(ft_t_flow);
545
546 /* Note: we do not unlock the module because
547 * there are some values cached in that `cseg' variable. We
548 * don't don't want to use this information when being
549 * unloaded by kerneld even when the tape is full or when we
550 * cannot allocate enough memory.
551 */
552 if (pos->tape_pos > (volume->size-volume->blk_sz-ZFT_CMPR_OVERHEAD)) {
553 TRACE_EXIT -ENOSPC;
554 }
555 if (zft_allocate_cmpr_mem(volume->blk_sz) < 0) {
556 /* should we unlock the module? But it shouldn't
557 * be locked anyway ...
558 */
559 TRACE_EXIT -ENOMEM;
560 }
561 if (buf_pos_write == 0) { /* fill a new segment */
562 *write_cnt = buf_pos_write = start_new_cseg(&cseg,
563 dst_buf,
564 pos,
565 volume->blk_sz,
566 zftc_buf,
567 seg_sz,
568 volume->qic113);
569 if (cseg.cmpr_sz == 0 && cseg.cmpr_pos != 0) {
570 req_len_left -= result = volume->blk_sz;
571 cseg.cmpr_pos = 0;
572 } else {
573 result = 0;
574 }
575 } else {
576 *write_cnt = result = 0;
577 }
578
579 len_left = seg_sz - buf_pos_write;
580 while ((req_len_left > 0) && (len_left > 18)) {
581 /* now we have some size left for a new compressed
582 * block. We know, that the compression buffer is
583 * empty (else there wouldn't be any space left).
584 */
585 if (copy_from_user(zftc_scratch_buf, src_buf + result,
586 volume->blk_sz) != 0) {
587 TRACE_EXIT -EFAULT;
588 }
589 req_len_left -= volume->blk_sz;
590 cseg.cmpr_sz = zft_compress(zftc_scratch_buf, volume->blk_sz,
591 zftc_buf);
592 if (cseg.cmpr_sz < 0) {
593 cseg.uncmpr = 0x8000;
594 cseg.cmpr_sz = -cseg.cmpr_sz;
595 } else {
596 cseg.uncmpr = 0;
597 }
598 /* increment "result" iff we copied the entire
599 * compressed block to the zft_deblock_buf
600 */
601 len_left -= sizeof(__u16);
602 if (len_left >= cseg.cmpr_sz) {
603 len_left -= cseg.count = cseg.cmpr_sz;
604 cseg.cmpr_pos = cseg.cmpr_sz = 0;
605 result += volume->blk_sz;
606 } else {
607 cseg.cmpr_sz -=
608 cseg.cmpr_pos =
609 cseg.count = len_left;
610 len_left = 0;
611 }
612 PUT2(dst_buf, buf_pos_write, cseg.uncmpr | cseg.count);
613 buf_pos_write += sizeof(__u16);
614 memcpy(dst_buf + buf_pos_write, zftc_buf, cseg.count);
615 buf_pos_write += cseg.count;
616 *write_cnt += cseg.count + sizeof(__u16);
617 FT_SIGNAL_EXIT(_DONT_BLOCK);
618 }
619 /* erase the remainder of the segment if less than 18 bytes
620 * left (18 bytes is due to the QIC-80 standard)
621 */
622 if (len_left <= 18) {
623 memset(dst_buf + buf_pos_write, '\0', len_left);
624 (*write_cnt) += len_left;
625 }
626 TRACE(ft_t_data_flow, "returning %d", result);
627 TRACE_EXIT result;
628}
629
630/* out:
631 *
632 * int *read_cnt: the number of bytes we removed from the zft_deblock_buf
633 * (result)
634 * int *to_do : the remaining size of the read-request.
635 *
636 * in:
637 *
638 * char *buff : buff is the address of the upper part of the user
639 * buffer, that hasn't been filled with data yet.
640
641 * int buf_pos_read : copy of from _ftape_read()
642 * int buf_len_read : copy of buf_len_rd from _ftape_read()
643 * char *zft_deblock_buf: zft_deblock_buf
644 * unsigned short blk_sz: the block size valid for this volume, may differ
645 * from zft_blk_sz.
646 * int finish: if != 0 means that this is the last segment belonging
647 * to this volume
648 * returns the amount of data actually copied to the user-buffer
649 *
650 * to_do MUST NOT SHRINK except to indicate an EOF. In this case *to_do has to
651 * be set to 0
652 */
653static int zftc_read (int *read_cnt,
654 __u8 __user *dst_buf, const int to_do,
655 const __u8 *src_buf, const int seg_sz,
656 const zft_position *pos, const zft_volinfo *volume)
657{
658 int uncompressed_sz;
659 int result = 0;
660 int remaining = to_do;
661 TRACE_FUN(ft_t_flow);
662
663 TRACE_CATCH(zft_allocate_cmpr_mem(volume->blk_sz),);
664 if (pos->seg_byte_pos == 0) {
665 /* new segment just read
666 */
667 TRACE_CATCH(get_cseg(&cseg, src_buf, seg_sz, volume),
668 *read_cnt = 0);
669 memcpy(zftc_buf + cseg.cmpr_pos, src_buf + sizeof(__u16),
670 cseg.count);
671 cseg.cmpr_pos += cseg.count;
672 *read_cnt = cseg.offset;
673 DUMP_CMPR_INFO(ft_t_noise /* ft_t_any */, "", &cseg);
674 } else {
675 *read_cnt = 0;
676 }
677 /* loop and uncompress until user buffer full or
678 * deblock-buffer empty
679 */
680 TRACE(ft_t_data_flow, "compressed_sz: %d, compos : %d, *read_cnt: %d",
681 cseg.cmpr_sz, cseg.cmpr_pos, *read_cnt);
682 while ((cseg.spans == 0) && (remaining > 0)) {
683 if (cseg.cmpr_pos != 0) { /* cmpr buf is not empty */
684 uncompressed_sz =
685 zft_uncompress(zftc_buf,
686 cseg.uncmpr == 0x8000 ?
687 -cseg.cmpr_pos : cseg.cmpr_pos,
688 zftc_scratch_buf,
689 volume->blk_sz);
690 if (uncompressed_sz != volume->blk_sz) {
691 *read_cnt = 0;
692 TRACE_ABORT(-EIO, ft_t_warn,
693 "Uncompressed blk (%d) != blk size (%d)",
694 uncompressed_sz, volume->blk_sz);
695 }
696 if (copy_to_user(dst_buf + result,
697 zftc_scratch_buf,
698 uncompressed_sz) != 0 ) {
699 TRACE_EXIT -EFAULT;
700 }
701 remaining -= uncompressed_sz;
702 result += uncompressed_sz;
703 cseg.cmpr_pos = 0;
704 }
705 if (remaining > 0) {
706 get_next_cluster(&cseg, src_buf, seg_sz,
707 volume->end_seg == pos->seg_pos);
708 if (cseg.count != 0) {
709 memcpy(zftc_buf, src_buf + cseg.offset,
710 cseg.count);
711 cseg.cmpr_pos = cseg.count;
712 cseg.offset += cseg.count;
713 *read_cnt += cseg.count + sizeof(__u16);
714 } else {
715 remaining = 0;
716 }
717 }
718 TRACE(ft_t_data_flow, "\n"
719 KERN_INFO "compressed_sz: %d\n"
720 KERN_INFO "compos : %d\n"
721 KERN_INFO "*read_cnt : %d",
722 cseg.cmpr_sz, cseg.cmpr_pos, *read_cnt);
723 }
724 if (seg_sz - cseg.offset <= 18) {
725 *read_cnt += seg_sz - cseg.offset;
726 TRACE(ft_t_data_flow, "expanding read cnt to: %d", *read_cnt);
727 }
728 TRACE(ft_t_data_flow, "\n"
729 KERN_INFO "segment size : %d\n"
730 KERN_INFO "read count : %d\n"
731 KERN_INFO "buf_pos_read : %d\n"
732 KERN_INFO "remaining : %d",
733 seg_sz, *read_cnt, pos->seg_byte_pos,
734 seg_sz - *read_cnt - pos->seg_byte_pos);
735 TRACE(ft_t_data_flow, "returning: %d", result);
736 TRACE_EXIT result;
737}
738
739/* seeks to the new data-position. Reads sometimes a segment.
740 *
741 * start_seg and end_seg give the boundaries of the current volume
742 * blk_sz is the blk_sz of the current volume as stored in the
743 * volume label
744 *
745 * We don't allow blocksizes less than 1024 bytes, therefore we don't need
746 * a 64 bit argument for new_block_pos.
747 */
748
749static int seek_in_segment(const unsigned int to_do, cmpr_info *c_info,
750 const char *src_buf, const int seg_sz,
751 const int seg_pos, const zft_volinfo *volume);
752static int slow_seek_forward_until_error(const unsigned int distance,
753 cmpr_info *c_info, zft_position *pos,
754 const zft_volinfo *volume, __u8 *buf);
755static int search_valid_segment(unsigned int segment,
756 const unsigned int end_seg,
757 const unsigned int max_foffs,
758 zft_position *pos, cmpr_info *c_info,
759 const zft_volinfo *volume, __u8 *buf);
760static int slow_seek_forward(unsigned int dest, cmpr_info *c_info,
761 zft_position *pos, const zft_volinfo *volume,
762 __u8 *buf);
763static int compute_seg_pos(unsigned int dest, zft_position *pos,
764 const zft_volinfo *volume);
765
766#define ZFT_SLOW_SEEK_THRESHOLD 10 /* segments */
767#define ZFT_FAST_SEEK_MAX_TRIALS 10 /* times */
768#define ZFT_FAST_SEEK_BACKUP 10 /* segments */
769
770static int zftc_seek(unsigned int new_block_pos,
771 zft_position *pos, const zft_volinfo *volume, __u8 *buf)
772{
773 unsigned int dest;
774 int limit;
775 int distance;
776 int result = 0;
777 int seg_dist;
778 int new_seg;
779 int old_seg = 0;
780 int fast_seek_trials = 0;
781 TRACE_FUN(ft_t_flow);
782
783 if (new_block_pos == 0) {
784 pos->seg_pos = volume->start_seg;
785 pos->seg_byte_pos = 0;
786 pos->volume_pos = 0;
787 zftc_reset();
788 TRACE_EXIT 0;
789 }
790 dest = new_block_pos * (volume->blk_sz >> 10);
791 distance = dest - (pos->volume_pos >> 10);
792 while (distance != 0) {
793 seg_dist = compute_seg_pos(dest, pos, volume);
794 TRACE(ft_t_noise, "\n"
795 KERN_INFO "seg_dist: %d\n"
796 KERN_INFO "distance: %d\n"
797 KERN_INFO "dest : %d\n"
798 KERN_INFO "vpos : %d\n"
799 KERN_INFO "seg_pos : %d\n"
800 KERN_INFO "trials : %d",
801 seg_dist, distance, dest,
802 (unsigned int)(pos->volume_pos>>10), pos->seg_pos,
803 fast_seek_trials);
804 if (distance > 0) {
805 if (seg_dist < 0) {
806 TRACE(ft_t_bug, "BUG: distance %d > 0, "
807 "segment difference %d < 0",
808 distance, seg_dist);
809 result = -EIO;
810 break;
811 }
812 new_seg = pos->seg_pos + seg_dist;
813 if (new_seg > volume->end_seg) {
814 new_seg = volume->end_seg;
815 }
816 if (old_seg == new_seg || /* loop */
817 seg_dist <= ZFT_SLOW_SEEK_THRESHOLD ||
818 fast_seek_trials >= ZFT_FAST_SEEK_MAX_TRIALS) {
819 TRACE(ft_t_noise, "starting slow seek:\n"
820 KERN_INFO "fast seek failed too often: %s\n"
821 KERN_INFO "near target position : %s\n"
822 KERN_INFO "looping between two segs : %s",
823 (fast_seek_trials >=
824 ZFT_FAST_SEEK_MAX_TRIALS)
825 ? "yes" : "no",
826 (seg_dist <= ZFT_SLOW_SEEK_THRESHOLD)
827 ? "yes" : "no",
828 (old_seg == new_seg)
829 ? "yes" : "no");
830 result = slow_seek_forward(dest, &cseg,
831 pos, volume, buf);
832 break;
833 }
834 old_seg = new_seg;
835 limit = volume->end_seg;
836 fast_seek_trials ++;
837 for (;;) {
838 result = search_valid_segment(new_seg, limit,
839 volume->size,
840 pos, &cseg,
841 volume, buf);
842 if (result == 0 || result == -EINTR) {
843 break;
844 }
845 if (new_seg == volume->start_seg) {
846 result = -EIO; /* set errror
847 * condition
848 */
849 break;
850 }
851 limit = new_seg;
852 new_seg -= ZFT_FAST_SEEK_BACKUP;
853 if (new_seg < volume->start_seg) {
854 new_seg = volume->start_seg;
855 }
856 }
857 if (result < 0) {
858 TRACE(ft_t_warn,
859 "Couldn't find a readable segment");
860 break;
861 }
862 } else /* if (distance < 0) */ {
863 if (seg_dist > 0) {
864 TRACE(ft_t_bug, "BUG: distance %d < 0, "
865 "segment difference %d >0",
866 distance, seg_dist);
867 result = -EIO;
868 break;
869 }
870 new_seg = pos->seg_pos + seg_dist;
871 if (fast_seek_trials > 0 && seg_dist == 0) {
872 /* this avoids sticking to the same
873 * segment all the time. On the other hand:
874 * if we got here for the first time, and the
875 * deblock_buffer still contains a valid
876 * segment, then there is no need to skip to
877 * the previous segment if the desired position
878 * is inside this segment.
879 */
880 new_seg --;
881 }
882 if (new_seg < volume->start_seg) {
883 new_seg = volume->start_seg;
884 }
885 limit = pos->seg_pos;
886 fast_seek_trials ++;
887 for (;;) {
888 result = search_valid_segment(new_seg, limit,
889 pos->volume_pos,
890 pos, &cseg,
891 volume, buf);
892 if (result == 0 || result == -EINTR) {
893 break;
894 }
895 if (new_seg == volume->start_seg) {
896 result = -EIO; /* set errror
897 * condition
898 */
899 break;
900 }
901 limit = new_seg;
902 new_seg -= ZFT_FAST_SEEK_BACKUP;
903 if (new_seg < volume->start_seg) {
904 new_seg = volume->start_seg;
905 }
906 }
907 if (result < 0) {
908 TRACE(ft_t_warn,
909 "Couldn't find a readable segment");
910 break;
911 }
912 }
913 distance = dest - (pos->volume_pos >> 10);
914 }
915 TRACE_EXIT result;
916}
917
918
919/* advance inside the given segment at most to_do bytes.
920 * of kilobytes moved
921 */
922
923static int seek_in_segment(const unsigned int to_do,
924 cmpr_info *c_info,
925 const char *src_buf,
926 const int seg_sz,
927 const int seg_pos,
928 const zft_volinfo *volume)
929{
930 int result = 0;
931 int blk_sz = volume->blk_sz >> 10;
932 int remaining = to_do;
933 TRACE_FUN(ft_t_flow);
934
935 if (c_info->offset == 0) {
936 /* new segment just read
937 */
938 TRACE_CATCH(get_cseg(c_info, src_buf, seg_sz, volume),);
939 c_info->cmpr_pos += c_info->count;
940 DUMP_CMPR_INFO(ft_t_noise, "", c_info);
941 }
942 /* loop and uncompress until user buffer full or
943 * deblock-buffer empty
944 */
945 TRACE(ft_t_noise, "compressed_sz: %d, compos : %d",
946 c_info->cmpr_sz, c_info->cmpr_pos);
947 while (c_info->spans == 0 && remaining > 0) {
948 if (c_info->cmpr_pos != 0) { /* cmpr buf is not empty */
949 result += blk_sz;
950 remaining -= blk_sz;
951 c_info->cmpr_pos = 0;
952 }
953 if (remaining > 0) {
954 get_next_cluster(c_info, src_buf, seg_sz,
955 volume->end_seg == seg_pos);
956 if (c_info->count != 0) {
957 c_info->cmpr_pos = c_info->count;
958 c_info->offset += c_info->count;
959 } else {
960 break;
961 }
962 }
963 /* Allow escape from this loop on signal!
964 */
965 FT_SIGNAL_EXIT(_DONT_BLOCK);
966 DUMP_CMPR_INFO(ft_t_noise, "", c_info);
967 TRACE(ft_t_noise, "to_do: %d", remaining);
968 }
969 if (seg_sz - c_info->offset <= 18) {
970 c_info->offset = seg_sz;
971 }
972 TRACE(ft_t_noise, "\n"
973 KERN_INFO "segment size : %d\n"
974 KERN_INFO "buf_pos_read : %d\n"
975 KERN_INFO "remaining : %d",
976 seg_sz, c_info->offset,
977 seg_sz - c_info->offset);
978 TRACE_EXIT result;
979}
980
981static int slow_seek_forward_until_error(const unsigned int distance,
982 cmpr_info *c_info,
983 zft_position *pos,
984 const zft_volinfo *volume,
985 __u8 *buf)
986{
987 unsigned int remaining = distance;
988 int seg_sz;
989 int seg_pos;
990 int result;
991 TRACE_FUN(ft_t_flow);
992
993 seg_pos = pos->seg_pos;
994 do {
995 TRACE_CATCH(seg_sz = zft_fetch_segment(seg_pos, buf,
996 FT_RD_AHEAD),);
997 /* now we have the contents of the actual segment in
998 * the deblock buffer
999 */
1000 TRACE_CATCH(result = seek_in_segment(remaining, c_info, buf,
1001 seg_sz, seg_pos,volume),);
1002 remaining -= result;
1003 pos->volume_pos += result<<10;
1004 pos->seg_pos = seg_pos;
1005 pos->seg_byte_pos = c_info->offset;
1006 seg_pos ++;
1007 if (seg_pos <= volume->end_seg && c_info->offset == seg_sz) {
1008 pos->seg_pos ++;
1009 pos->seg_byte_pos = 0;
1010 c_info->offset = 0;
1011 }
1012 /* Allow escape from this loop on signal!
1013 */
1014 FT_SIGNAL_EXIT(_DONT_BLOCK);
1015 TRACE(ft_t_noise, "\n"
1016 KERN_INFO "remaining: %d\n"
1017 KERN_INFO "seg_pos: %d\n"
1018 KERN_INFO "end_seg: %d\n"
1019 KERN_INFO "result: %d",
1020 remaining, seg_pos, volume->end_seg, result);
1021 } while (remaining > 0 && seg_pos <= volume->end_seg);
1022 TRACE_EXIT 0;
1023}
1024
1025/* return segment id of next segment containing valid data, -EIO otherwise
1026 */
1027static int search_valid_segment(unsigned int segment,
1028 const unsigned int end_seg,
1029 const unsigned int max_foffs,
1030 zft_position *pos,
1031 cmpr_info *c_info,
1032 const zft_volinfo *volume,
1033 __u8 *buf)
1034{
1035 cmpr_info tmp_info;
1036 int seg_sz;
1037 TRACE_FUN(ft_t_flow);
1038
1039 memset(&tmp_info, 0, sizeof(cmpr_info));
1040 while (segment <= end_seg) {
1041 FT_SIGNAL_EXIT(_DONT_BLOCK);
1042 TRACE(ft_t_noise,
1043 "Searching readable segment between %d and %d",
1044 segment, end_seg);
1045 seg_sz = zft_fetch_segment(segment, buf, FT_RD_AHEAD);
1046 if ((seg_sz > 0) &&
1047 (get_cseg (&tmp_info, buf, seg_sz, volume) >= 0) &&
1048 (tmp_info.foffs != 0 || segment == volume->start_seg)) {
1049 if ((tmp_info.foffs>>10) > max_foffs) {
1050 TRACE_ABORT(-EIO, ft_t_noise, "\n"
1051 KERN_INFO "cseg.foff: %d\n"
1052 KERN_INFO "dest : %d",
1053 (int)(tmp_info.foffs >> 10),
1054 max_foffs);
1055 }
1056 DUMP_CMPR_INFO(ft_t_noise, "", &tmp_info);
1057 *c_info = tmp_info;
1058 pos->seg_pos = segment;
1059 pos->volume_pos = c_info->foffs;
1060 pos->seg_byte_pos = c_info->offset;
1061 TRACE(ft_t_noise, "found segment at %d", segment);
1062 TRACE_EXIT 0;
1063 }
1064 segment++;
1065 }
1066 TRACE_EXIT -EIO;
1067}
1068
1069static int slow_seek_forward(unsigned int dest,
1070 cmpr_info *c_info,
1071 zft_position *pos,
1072 const zft_volinfo *volume,
1073 __u8 *buf)
1074{
1075 unsigned int distance;
1076 int result = 0;
1077 TRACE_FUN(ft_t_flow);
1078
1079 distance = dest - (pos->volume_pos >> 10);
1080 while ((distance > 0) &&
1081 (result = slow_seek_forward_until_error(distance,
1082 c_info,
1083 pos,
1084 volume,
1085 buf)) < 0) {
1086 if (result == -EINTR) {
1087 break;
1088 }
1089 TRACE(ft_t_noise, "seg_pos: %d", pos->seg_pos);
1090 /* the failing segment is either pos->seg_pos or
1091 * pos->seg_pos + 1. There is no need to further try
1092 * that segment, because ftape_read_segment() already
1093 * has tried very much to read it. So we start with
1094 * following segment, which is pos->seg_pos + 1
1095 */
1096 if(search_valid_segment(pos->seg_pos+1, volume->end_seg, dest,
1097 pos, c_info,
1098 volume, buf) < 0) {
1099 TRACE(ft_t_noise, "search_valid_segment() failed");
1100 result = -EIO;
1101 break;
1102 }
1103 distance = dest - (pos->volume_pos >> 10);
1104 result = 0;
1105 TRACE(ft_t_noise, "segment: %d", pos->seg_pos);
1106 /* found valid segment, retry the seek */
1107 }
1108 TRACE_EXIT result;
1109}
1110
1111static int compute_seg_pos(const unsigned int dest,
1112 zft_position *pos,
1113 const zft_volinfo *volume)
1114{
1115 int segment;
1116 int distance = dest - (pos->volume_pos >> 10);
1117 unsigned int raw_size;
1118 unsigned int virt_size;
1119 unsigned int factor;
1120 TRACE_FUN(ft_t_flow);
1121
1122 if (distance >= 0) {
1123 raw_size = volume->end_seg - pos->seg_pos + 1;
1124 virt_size = ((unsigned int)(volume->size>>10)
1125 - (unsigned int)(pos->volume_pos>>10)
1126 + FT_SECTORS_PER_SEGMENT - FT_ECC_SECTORS - 1);
1127 virt_size /= FT_SECTORS_PER_SEGMENT - FT_ECC_SECTORS;
1128 if (virt_size == 0 || raw_size == 0) {
1129 TRACE_EXIT 0;
1130 }
1131 if (raw_size >= (1<<25)) {
1132 factor = raw_size/(virt_size>>7);
1133 } else {
1134 factor = (raw_size<<7)/virt_size;
1135 }
1136 segment = distance/(FT_SECTORS_PER_SEGMENT-FT_ECC_SECTORS);
1137 segment = (segment * factor)>>7;
1138 } else {
1139 raw_size = pos->seg_pos - volume->start_seg + 1;
1140 virt_size = ((unsigned int)(pos->volume_pos>>10)
1141 + FT_SECTORS_PER_SEGMENT - FT_ECC_SECTORS - 1);
1142 virt_size /= FT_SECTORS_PER_SEGMENT - FT_ECC_SECTORS;
1143 if (virt_size == 0 || raw_size == 0) {
1144 TRACE_EXIT 0;
1145 }
1146 if (raw_size >= (1<<25)) {
1147 factor = raw_size/(virt_size>>7);
1148 } else {
1149 factor = (raw_size<<7)/virt_size;
1150 }
1151 segment = distance/(FT_SECTORS_PER_SEGMENT-FT_ECC_SECTORS);
1152 }
1153 TRACE(ft_t_noise, "factor: %d/%d", factor, 1<<7);
1154 TRACE_EXIT segment;
1155}
1156
1157static struct zft_cmpr_ops cmpr_ops = {
1158 zftc_write,
1159 zftc_read,
1160 zftc_seek,
1161 zftc_lock,
1162 zftc_reset,
1163 zftc_cleanup
1164};
1165
1166int zft_compressor_init(void)
1167{
1168 TRACE_FUN(ft_t_flow);
1169
1170#ifdef MODULE
1171 printk(KERN_INFO "zftape compressor v1.00a 970514 for " FTAPE_VERSION "\n");
1172 if (TRACE_LEVEL >= ft_t_info) {
1173 printk(
1174KERN_INFO "(c) 1997 Claus-Justus Heine (claus@momo.math.rwth-aachen.de)\n"
1175KERN_INFO "Compressor for zftape (lzrw3 algorithm)\n");
1176 }
1177#else /* !MODULE */
1178 /* print a short no-nonsense boot message */
1179 printk(KERN_INFO "zftape compressor v1.00a 970514\n");
1180 printk(KERN_INFO "For use with " FTAPE_VERSION "\n");
1181#endif /* MODULE */
1182 TRACE(ft_t_info, "zft_compressor_init @ 0x%p", zft_compressor_init);
1183 TRACE(ft_t_info, "installing compressor for zftape ...");
1184 TRACE_CATCH(zft_cmpr_register(&cmpr_ops),);
1185 TRACE_EXIT 0;
1186}
1187
1188#ifdef MODULE
1189
1190MODULE_AUTHOR(
1191 "(c) 1996, 1997 Claus-Justus Heine (claus@momo.math.rwth-aachen.de");
1192MODULE_DESCRIPTION(
1193"Compression routines for zftape. Uses the lzrw3 algorithm by Ross Williams");
1194MODULE_LICENSE("GPL");
1195
1196/* Called by modules package when installing the driver
1197 */
1198int init_module(void)
1199{
1200 return zft_compressor_init();
1201}
1202
1203#endif /* MODULE */
diff --git a/drivers/char/ftape/compressor/zftape-compress.h b/drivers/char/ftape/compressor/zftape-compress.h
deleted file mode 100644
index f200741e33bf..000000000000
--- a/drivers/char/ftape/compressor/zftape-compress.h
+++ /dev/null
@@ -1,83 +0,0 @@
1#ifndef _ZFTAPE_COMPRESS_H
2#define _ZFTAPE_COMPRESS_H
3/*
4 * Copyright (c) 1994-1997 Claus-Justus Heine
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2, or (at
9 your option) any later version.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
19 USA.
20
21 *
22 * $Source: /homes/cvs/ftape-stacked/ftape/compressor/zftape-compress.h,v $
23 * $Revision: 1.1 $
24 * $Date: 1997/10/05 19:12:32 $
25 *
26 * This file contains macros and definitions for zftape's
27 * builtin compression code.
28 *
29 */
30
31#include "../zftape/zftape-buffers.h"
32#include "../zftape/zftape-vtbl.h"
33#include "../compressor/lzrw3.h"
34
35/* CMPR_WRK_MEM_SIZE gives the size of the compression wrk_mem */
36/* I got these out of lzrw3.c */
37#define U(X) ((__u32) X)
38#define SIZE_P_BYTE (U(sizeof(__u8 *)))
39#define ALIGNMENT_FUDGE (U(16))
40
41#define CMPR_WRK_MEM_SIZE (U(4096)*(SIZE_P_BYTE) + ALIGNMENT_FUDGE)
42
43/* the maximum number of bytes the size of the "compressed" data can
44 * exceed the uncompressed data. As it is quite useless to compress
45 * data twice it is sometimes the case that it is more efficient to
46 * copy a block of data but to feed it to the "compression"
47 * algorithm. In this case there are some flag bytes or the like
48 * proceding the "compressed" data. THAT MUST NOT BE THE CASE for the
49 * algorithm we use for this driver. Instead, the high bit 15 of
50 * compressed_size:
51 *
52 * compressed_size = ftape_compress()
53 *
54 * must be set in such a case.
55 *
56 * Nevertheless, it might also be as for lzrw3 that there is an
57 * "intermediate" overrun that exceeds the amount of the compressed
58 * data that is actually produced. During the algorithm we need in the
59 * worst case MAX_CMP_GROUP bytes more than the input-size.
60 */
61#define MAX_CMP_GROUP (2+16*2) /* from lzrw3.c */
62
63#define CMPR_OVERRUN MAX_CMP_GROUP /* during compression */
64
65/****************************************************/
66
67#define CMPR_BUFFER_SIZE (MAX_BLOCK_SIZE + CMPR_OVERRUN)
68
69/* the compression map stores the byte offset compressed blocks within
70 * the current volume for catridges with format code 2,3 and 5
71 * (and old versions of zftape) and the offset measured in kilobytes for
72 * format code 4 and 6. This gives us a possible max. size of a
73 * compressed volume of 1024*4GIG which should be enough.
74 */
75typedef __u32 CmprMap;
76
77/* globals
78 */
79
80/* exported functions
81 */
82
83#endif /* _ZFTAPE_COMPRESS_H */
diff --git a/drivers/char/ftape/lowlevel/Makefile b/drivers/char/ftape/lowlevel/Makefile
deleted file mode 100644
index febab07ba427..000000000000
--- a/drivers/char/ftape/lowlevel/Makefile
+++ /dev/null
@@ -1,43 +0,0 @@
1#
2# Copyright (C) 1996, 1997 Clau-Justus Heine.
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2, or (at your option)
7# any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; see the file COPYING. If not, write to
16# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17#
18# $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/Makefile,v $
19# $Revision: 1.4 $
20# $Date: 1997/10/07 09:26:02 $
21#
22# Makefile for the lowlevel part QIC-40/80/3010/3020 floppy-tape
23# driver for Linux.
24#
25
26obj-$(CONFIG_FTAPE) += ftape.o
27
28ftape-objs := ftape-init.o fdc-io.o fdc-isr.o \
29 ftape-bsm.o ftape-ctl.o ftape-read.o ftape-rw.o \
30 ftape-write.o ftape-io.o ftape-calibr.o ftape-ecc.o fc-10.o \
31 ftape-buffer.o ftape-format.o ftape_syms.o
32
33ifeq ($(CONFIG_FTAPE),y)
34ftape-objs += ftape-setup.o
35endif
36
37ifndef CONFIG_FT_NO_TRACE_AT_ALL
38ftape-objs += ftape-tracing.o
39endif
40
41ifeq ($(CONFIG_FT_PROC_FS),y)
42ftape-objs += ftape-proc.o
43endif
diff --git a/drivers/char/ftape/lowlevel/fc-10.c b/drivers/char/ftape/lowlevel/fc-10.c
deleted file mode 100644
index 9bc1cddade76..000000000000
--- a/drivers/char/ftape/lowlevel/fc-10.c
+++ /dev/null
@@ -1,175 +0,0 @@
1/*
2 *
3
4 Copyright (C) 1993,1994 Jon Tombs.
5
6 This program is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 GNU General Public License for more details.
10
11 The entire guts of this program was written by dosemu, modified to
12 record reads and writes to the ports in the 0x180-0x188 address space,
13 while running the CMS program TAPE.EXE V2.0.5 supplied with the drive.
14
15 Modified to use an array of addresses and generally cleaned up (made
16 much shorter) 4 June 94, dosemu isn't that good at writing short code it
17 would seem :-). Made independent of 0x180, but I doubt it will work
18 at any other address.
19
20 Modified for distribution with ftape source. 21 June 94, SJL.
21
22 Modifications on 20 October 95, by Daniel Cohen (catman@wpi.edu):
23 Modified to support different DMA, IRQ, and IO Ports. Borland's
24 Turbo Debugger in virtual 8086 mode (TD386.EXE with hardware breakpoints
25 provided by the TDH386.SYS Device Driver) was used on the CMS program
26 TAPE V4.0.5. I set breakpoints on I/O to ports 0x180-0x187. Note that
27 CMS's program will not successfully configure the tape drive if you set
28 breakpoints on IO Reads, but you can set them on IO Writes without problems.
29 Known problems:
30 - You can not use DMA Channels 5 or 7.
31
32 Modification on 29 January 96, by Daniel Cohen (catman@wpi.edu):
33 Modified to only accept IRQs 3 - 7, or 9. Since we can only send a 3 bit
34 number representing the IRQ to the card, special handling is required when
35 IRQ 9 is selected. IRQ 2 and 9 are the same, and we should request IRQ 9
36 from the kernel while telling the card to use IRQ 2. Thanks to Greg
37 Crider (gcrider@iclnet.org) for finding and locating this bug, as well as
38 testing the patch.
39
40 Modification on 11 December 96, by Claus Heine (claus@momo.math.rwth-aachen.de):
41 Modified a little to use variahle ft_fdc_base, ft_fdc_irq, ft_fdc_dma
42 instead of preprocessor symbols. Thus we can compile this into the module
43 or kernel and let the user specify the options as command line arguments.
44
45 *
46 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/fc-10.c,v $
47 * $Revision: 1.2 $
48 * $Date: 1997/10/05 19:18:04 $
49 *
50 * This file contains code for the CMS FC-10/FC-20 card.
51 */
52
53#include <asm/io.h>
54#include <linux/ftape.h>
55#include "../lowlevel/ftape-tracing.h"
56#include "../lowlevel/fdc-io.h"
57#include "../lowlevel/fc-10.h"
58
59static __u16 inbs_magic[] = {
60 0x3, 0x3, 0x0, 0x4, 0x7, 0x2, 0x5, 0x3, 0x1, 0x4,
61 0x3, 0x5, 0x2, 0x0, 0x3, 0x7, 0x4, 0x2,
62 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7
63};
64
65static __u16 fc10_ports[] = {
66 0x180, 0x210, 0x2A0, 0x300, 0x330, 0x340, 0x370
67};
68
69int fc10_enable(void)
70{
71 int i;
72 __u8 cardConfig = 0x00;
73 __u8 x;
74 TRACE_FUN(ft_t_flow);
75
76/* This code will only work if the FC-10 (or FC-20) is set to
77 * use DMA channels 1, 2, or 3. DMA channels 5 and 7 seem to be
78 * initialized by the same command as channels 1 and 3, respectively.
79 */
80 if (ft_fdc_dma > 3) {
81 TRACE_ABORT(0, ft_t_err,
82"Error: The FC-10/20 must be set to use DMA channels 1, 2, or 3!");
83 }
84/* Only allow the FC-10/20 to use IRQ 3-7, or 9. Note that CMS's program
85 * only accepts IRQ's 2-7, but in linux, IRQ 2 is the same as IRQ 9.
86 */
87 if (ft_fdc_irq < 3 || ft_fdc_irq == 8 || ft_fdc_irq > 9) {
88 TRACE_ABORT(0, ft_t_err,
89"Error: The FC-10/20 must be set to use IRQ levels 3 - 7, or 9!\n"
90KERN_INFO "Note: IRQ 9 is the same as IRQ 2");
91 }
92 /* Clear state machine ???
93 */
94 for (i = 0; i < NR_ITEMS(inbs_magic); i++) {
95 inb(ft_fdc_base + inbs_magic[i]);
96 }
97 outb(0x0, ft_fdc_base);
98
99 x = inb(ft_fdc_base);
100 if (x == 0x13 || x == 0x93) {
101 for (i = 1; i < 8; i++) {
102 if (inb(ft_fdc_base + i) != x) {
103 TRACE_EXIT 0;
104 }
105 }
106 } else {
107 TRACE_EXIT 0;
108 }
109
110 outb(0x8, ft_fdc_base);
111
112 for (i = 0; i < 8; i++) {
113 if (inb(ft_fdc_base + i) != 0x0) {
114 TRACE_EXIT 0;
115 }
116 }
117 outb(0x10, ft_fdc_base);
118
119 for (i = 0; i < 8; i++) {
120 if (inb(ft_fdc_base + i) != 0xff) {
121 TRACE_EXIT 0;
122 }
123 }
124
125 /* Okay, we found a FC-10 card ! ???
126 */
127 outb(0x0, fdc.ccr);
128
129 /* Clear state machine again ???
130 */
131 for (i = 0; i < NR_ITEMS(inbs_magic); i++) {
132 inb(ft_fdc_base + inbs_magic[i]);
133 }
134 /* Send io port */
135 for (i = 0; i < NR_ITEMS(fc10_ports); i++)
136 if (ft_fdc_base == fc10_ports[i])
137 cardConfig = i + 1;
138 if (cardConfig == 0) {
139 TRACE_EXIT 0; /* Invalid I/O Port */
140 }
141 /* and IRQ - If using IRQ 9, tell the FC card it is actually IRQ 2 */
142 if (ft_fdc_irq != 9)
143 cardConfig |= ft_fdc_irq << 3;
144 else
145 cardConfig |= 2 << 3;
146
147 /* and finally DMA Channel */
148 cardConfig |= ft_fdc_dma << 6;
149 outb(cardConfig, ft_fdc_base); /* DMA [2 bits]/IRQ [3 bits]/BASE [3 bits] */
150
151 /* Enable FC-10 ???
152 */
153 outb(0, fdc.ccr);
154 outb(0, fdc.dor2);
155 outb(FDC_DMA_MODE /* 8 */, fdc.dor);
156 outb(FDC_DMA_MODE /* 8 */, fdc.dor);
157 outb(1, fdc.dor2);
158
159 /*************************************
160 *
161 * cH: why the hell should this be necessary? This is done
162 * by fdc_reset()!!!
163 *
164 *************************************/
165 /* Initialize fdc, select drive B:
166 */
167 outb(FDC_DMA_MODE, fdc.dor); /* assert reset, dma & irq enabled */
168 /* 0x08 */
169 outb(FDC_DMA_MODE|FDC_RESET_NOT, fdc.dor); /* release reset */
170 /* 0x08 | 0x04 = 0x0c */
171 outb(FDC_DMA_MODE|FDC_RESET_NOT|FDC_MOTOR_1|FTAPE_SEL_B, fdc.dor);
172 /* 0x08 | 0x04 | 0x20 | 0x01 = 0x2d */
173 /* select drive 1 */ /* why not drive 0 ???? */
174 TRACE_EXIT (x == 0x93) ? 2 : 1;
175}
diff --git a/drivers/char/ftape/lowlevel/fc-10.h b/drivers/char/ftape/lowlevel/fc-10.h
deleted file mode 100644
index da7b88bca889..000000000000
--- a/drivers/char/ftape/lowlevel/fc-10.h
+++ /dev/null
@@ -1,39 +0,0 @@
1#ifndef _FC_10_H
2#define _FC_10_H
3
4/*
5 * Copyright (C) 1994-1996 Bas Laarhoven.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 *
22 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/fc-10.h,v $
23 * $Revision: 1.1 $
24 * $Date: 1997/09/19 09:05:22 $
25 *
26 * This file contains definitions for the FC-10 code
27 * of the QIC-40/80 floppy-tape driver for Linux.
28 */
29
30/*
31 * fc-10.c defined global vars.
32 */
33
34/*
35 * fc-10.c defined global functions.
36 */
37extern int fc10_enable(void);
38
39#endif
diff --git a/drivers/char/ftape/lowlevel/fdc-io.c b/drivers/char/ftape/lowlevel/fdc-io.c
deleted file mode 100644
index 65c9d2ec60bd..000000000000
--- a/drivers/char/ftape/lowlevel/fdc-io.c
+++ /dev/null
@@ -1,1350 +0,0 @@
1/*
2 * Copyright (C) 1993-1996 Bas Laarhoven,
3 * (C) 1996-1997 Claus-Justus Heine.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 *
20 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/fdc-io.c,v $
21 * $Revision: 1.7.4.2 $
22 * $Date: 1997/11/16 14:48:17 $
23 *
24 * This file contains the low-level floppy disk interface code
25 * for the QIC-40/80/3010/3020 floppy-tape driver "ftape" for
26 * Linux.
27 */
28
29#include <linux/config.h> /* for CONFIG_FT_* */
30#include <linux/errno.h>
31#include <linux/sched.h>
32#include <linux/ioport.h>
33#include <linux/interrupt.h>
34#include <linux/kernel.h>
35#include <asm/system.h>
36#include <asm/io.h>
37#include <asm/dma.h>
38#include <asm/irq.h>
39
40#include <linux/ftape.h>
41#include <linux/qic117.h>
42#include "../lowlevel/ftape-tracing.h"
43#include "../lowlevel/fdc-io.h"
44#include "../lowlevel/fdc-isr.h"
45#include "../lowlevel/ftape-io.h"
46#include "../lowlevel/ftape-rw.h"
47#include "../lowlevel/ftape-ctl.h"
48#include "../lowlevel/ftape-calibr.h"
49#include "../lowlevel/fc-10.h"
50
51/* Global vars.
52 */
53static int ftape_motor;
54volatile int ftape_current_cylinder = -1;
55volatile fdc_mode_enum fdc_mode = fdc_idle;
56fdc_config_info fdc;
57DECLARE_WAIT_QUEUE_HEAD(ftape_wait_intr);
58
59unsigned int ft_fdc_base = CONFIG_FT_FDC_BASE;
60unsigned int ft_fdc_irq = CONFIG_FT_FDC_IRQ;
61unsigned int ft_fdc_dma = CONFIG_FT_FDC_DMA;
62unsigned int ft_fdc_threshold = CONFIG_FT_FDC_THR; /* bytes */
63unsigned int ft_fdc_rate_limit = CONFIG_FT_FDC_MAX_RATE; /* bits/sec */
64int ft_probe_fc10 = CONFIG_FT_PROBE_FC10;
65int ft_mach2 = CONFIG_FT_MACH2;
66
67/* Local vars.
68 */
69static spinlock_t fdc_io_lock;
70static unsigned int fdc_calibr_count;
71static unsigned int fdc_calibr_time;
72static int fdc_status;
73volatile __u8 fdc_head; /* FDC head from sector id */
74volatile __u8 fdc_cyl; /* FDC track from sector id */
75volatile __u8 fdc_sect; /* FDC sector from sector id */
76static int fdc_data_rate = 500; /* data rate (Kbps) */
77static int fdc_rate_code; /* data rate code (0 == 500 Kbps) */
78static int fdc_seek_rate = 2; /* step rate (msec) */
79static void (*do_ftape) (void);
80static int fdc_fifo_state; /* original fifo setting - fifo enabled */
81static int fdc_fifo_thr; /* original fifo setting - threshold */
82static int fdc_lock_state; /* original lock setting - locked */
83static int fdc_fifo_locked; /* has fifo && lock set ? */
84static __u8 fdc_precomp; /* default precomp. value (nsec) */
85static __u8 fdc_prec_code; /* fdc precomp. select code */
86
87static char ftape_id[] = "ftape"; /* used by request irq and free irq */
88
89static int fdc_set_seek_rate(int seek_rate);
90
91void fdc_catch_stray_interrupts(int count)
92{
93 unsigned long flags;
94
95 spin_lock_irqsave(&fdc_io_lock, flags);
96 if (count == 0) {
97 ft_expected_stray_interrupts = 0;
98 } else {
99 ft_expected_stray_interrupts += count;
100 }
101 spin_unlock_irqrestore(&fdc_io_lock, flags);
102}
103
104/* Wait during a timeout period for a given FDC status.
105 * If usecs == 0 then just test status, else wait at least for usecs.
106 * Returns -ETIME on timeout. Function must be calibrated first !
107 */
108static int fdc_wait(unsigned int usecs, __u8 mask, __u8 state)
109{
110 int count_1 = (fdc_calibr_count * usecs +
111 fdc_calibr_count - 1) / fdc_calibr_time;
112
113 do {
114 fdc_status = inb_p(fdc.msr);
115 if ((fdc_status & mask) == state) {
116 return 0;
117 }
118 } while (count_1-- >= 0);
119 return -ETIME;
120}
121
122int fdc_ready_wait(unsigned int usecs)
123{
124 return fdc_wait(usecs, FDC_DATA_READY | FDC_BUSY, FDC_DATA_READY);
125}
126
127/* Why can't we just use udelay()?
128 */
129static void fdc_usec_wait(unsigned int usecs)
130{
131 fdc_wait(usecs, 0, 1); /* will always timeout ! */
132}
133
134static int fdc_ready_out_wait(unsigned int usecs)
135{
136 fdc_usec_wait(FT_RQM_DELAY); /* wait for valid RQM status */
137 return fdc_wait(usecs, FDC_DATA_OUT_READY, FDC_DATA_OUT_READY);
138}
139
140void fdc_wait_calibrate(void)
141{
142 ftape_calibrate("fdc_wait",
143 fdc_usec_wait, &fdc_calibr_count, &fdc_calibr_time);
144}
145
146/* Wait for a (short) while for the FDC to become ready
147 * and transfer the next command byte.
148 * Return -ETIME on timeout on getting ready (depends on hardware!).
149 */
150static int fdc_write(const __u8 data)
151{
152 fdc_usec_wait(FT_RQM_DELAY); /* wait for valid RQM status */
153 if (fdc_wait(150, FDC_DATA_READY_MASK, FDC_DATA_IN_READY) < 0) {
154 return -ETIME;
155 } else {
156 outb(data, fdc.fifo);
157 return 0;
158 }
159}
160
161/* Wait for a (short) while for the FDC to become ready
162 * and transfer the next result byte.
163 * Return -ETIME if timeout on getting ready (depends on hardware!).
164 */
165static int fdc_read(__u8 * data)
166{
167 fdc_usec_wait(FT_RQM_DELAY); /* wait for valid RQM status */
168 if (fdc_wait(150, FDC_DATA_READY_MASK, FDC_DATA_OUT_READY) < 0) {
169 return -ETIME;
170 } else {
171 *data = inb(fdc.fifo);
172 return 0;
173 }
174}
175
176/* Output a cmd_len long command string to the FDC.
177 * The FDC should be ready to receive a new command or
178 * an error (EBUSY or ETIME) will occur.
179 */
180int fdc_command(const __u8 * cmd_data, int cmd_len)
181{
182 int result = 0;
183 unsigned long flags;
184 int count = cmd_len;
185 int retry = 0;
186#ifdef TESTING
187 static unsigned int last_time;
188 unsigned int time;
189#endif
190 TRACE_FUN(ft_t_any);
191
192 fdc_usec_wait(FT_RQM_DELAY); /* wait for valid RQM status */
193 spin_lock_irqsave(&fdc_io_lock, flags);
194 if (!in_interrupt())
195 /* Yes, I know, too much comments inside this function
196 * ...
197 *
198 * Yet another bug in the original driver. All that
199 * havoc is caused by the fact that the isr() sends
200 * itself a command to the floppy tape driver (pause,
201 * micro step pause). Now, the problem is that
202 * commands are transmitted via the fdc_seek
203 * command. But: the fdc performs seeks in the
204 * background i.e. it doesn't signal busy while
205 * sending the step pulses to the drive. Therefore the
206 * non-interrupt level driver has no chance to tell
207 * whether the isr() just has issued a seek. Therefore
208 * we HAVE TO have a look at the ft_hide_interrupt
209 * flag: it signals the non-interrupt level part of
210 * the driver that it has to wait for the fdc until it
211 * has completet seeking.
212 *
213 * THIS WAS PRESUMABLY THE REASON FOR ALL THAT
214 * "fdc_read timeout" errors, I HOPE :-)
215 */
216 if (ft_hide_interrupt) {
217 restore_flags(flags);
218 TRACE(ft_t_info,
219 "Waiting for the isr() completing fdc_seek()");
220 if (fdc_interrupt_wait(2 * FT_SECOND) < 0) {
221 TRACE(ft_t_warn,
222 "Warning: timeout waiting for isr() seek to complete");
223 }
224 if (ft_hide_interrupt || !ft_seek_completed) {
225 /* There cannot be another
226 * interrupt. The isr() only stops
227 * the tape and the next interrupt
228 * won't come until we have send our
229 * command to the drive.
230 */
231 TRACE_ABORT(-EIO, ft_t_bug,
232 "BUG? isr() is still seeking?\n"
233 KERN_INFO "hide: %d\n"
234 KERN_INFO "seek: %d",
235 ft_hide_interrupt,
236 ft_seek_completed);
237
238 }
239 fdc_usec_wait(FT_RQM_DELAY); /* wait for valid RQM status */
240 spin_lock_irqsave(&fdc_io_lock, flags);
241 }
242 fdc_status = inb(fdc.msr);
243 if ((fdc_status & FDC_DATA_READY_MASK) != FDC_DATA_IN_READY) {
244 spin_unlock_irqrestore(&fdc_io_lock, flags);
245 TRACE_ABORT(-EBUSY, ft_t_err, "fdc not ready");
246 }
247 fdc_mode = *cmd_data; /* used by isr */
248#ifdef TESTING
249 if (fdc_mode == FDC_SEEK) {
250 time = ftape_timediff(last_time, ftape_timestamp());
251 if (time < 6000) {
252 TRACE(ft_t_bug,"Warning: short timeout between seek commands: %d",
253 time);
254 }
255 }
256#endif
257 if (!in_interrupt()) {
258 /* shouldn't be cleared if called from isr
259 */
260 ft_interrupt_seen = 0;
261 }
262 while (count) {
263 result = fdc_write(*cmd_data);
264 if (result < 0) {
265 TRACE(ft_t_fdc_dma,
266 "fdc_mode = %02x, status = %02x at index %d",
267 (int) fdc_mode, (int) fdc_status,
268 cmd_len - count);
269 if (++retry <= 3) {
270 TRACE(ft_t_warn, "fdc_write timeout, retry");
271 } else {
272 TRACE(ft_t_err, "fdc_write timeout, fatal");
273 /* recover ??? */
274 break;
275 }
276 } else {
277 --count;
278 ++cmd_data;
279 }
280 }
281#ifdef TESTING
282 if (fdc_mode == FDC_SEEK) {
283 last_time = ftape_timestamp();
284 }
285#endif
286 spin_unlock_irqrestore(&fdc_io_lock, flags);
287 TRACE_EXIT result;
288}
289
290/* Input a res_len long result string from the FDC.
291 * The FDC should be ready to send the result or an error
292 * (EBUSY or ETIME) will occur.
293 */
294int fdc_result(__u8 * res_data, int res_len)
295{
296 int result = 0;
297 unsigned long flags;
298 int count = res_len;
299 int retry = 0;
300 TRACE_FUN(ft_t_any);
301
302 spin_lock_irqsave(&fdc_io_lock, flags);
303 fdc_status = inb(fdc.msr);
304 if ((fdc_status & FDC_DATA_READY_MASK) != FDC_DATA_OUT_READY) {
305 TRACE(ft_t_err, "fdc not ready");
306 result = -EBUSY;
307 } else while (count) {
308 if (!(fdc_status & FDC_BUSY)) {
309 spin_unlock_irqrestore(&fdc_io_lock, flags);
310 TRACE_ABORT(-EIO, ft_t_err, "premature end of result phase");
311 }
312 result = fdc_read(res_data);
313 if (result < 0) {
314 TRACE(ft_t_fdc_dma,
315 "fdc_mode = %02x, status = %02x at index %d",
316 (int) fdc_mode,
317 (int) fdc_status,
318 res_len - count);
319 if (++retry <= 3) {
320 TRACE(ft_t_warn, "fdc_read timeout, retry");
321 } else {
322 TRACE(ft_t_err, "fdc_read timeout, fatal");
323 /* recover ??? */
324 break;
325 ++retry;
326 }
327 } else {
328 --count;
329 ++res_data;
330 }
331 }
332 spin_unlock_irqrestore(&fdc_io_lock, flags);
333 fdc_usec_wait(FT_RQM_DELAY); /* allow FDC to negate BSY */
334 TRACE_EXIT result;
335}
336
337/* Handle command and result phases for
338 * commands without data phase.
339 */
340static int fdc_issue_command(const __u8 * out_data, int out_count,
341 __u8 * in_data, int in_count)
342{
343 TRACE_FUN(ft_t_any);
344
345 if (out_count > 0) {
346 TRACE_CATCH(fdc_command(out_data, out_count),);
347 }
348 /* will take 24 - 30 usec for fdc_sense_drive_status and
349 * fdc_sense_interrupt_status commands.
350 * 35 fails sometimes (5/9/93 SJL)
351 * On a loaded system it incidentally takes longer than
352 * this for the fdc to get ready ! ?????? WHY ??????
353 * So until we know what's going on use a very long timeout.
354 */
355 TRACE_CATCH(fdc_ready_out_wait(500 /* usec */),);
356 if (in_count > 0) {
357 TRACE_CATCH(fdc_result(in_data, in_count),
358 TRACE(ft_t_err, "result phase aborted"));
359 }
360 TRACE_EXIT 0;
361}
362
363/* Wait for FDC interrupt with timeout (in milliseconds).
364 * Signals are blocked so the wait will not be aborted.
365 * Note: interrupts must be enabled ! (23/05/93 SJL)
366 */
367int fdc_interrupt_wait(unsigned int time)
368{
369 DECLARE_WAITQUEUE(wait,current);
370 sigset_t old_sigmask;
371 static int resetting;
372 long timeout;
373
374 TRACE_FUN(ft_t_fdc_dma);
375
376 if (waitqueue_active(&ftape_wait_intr)) {
377 TRACE_ABORT(-EIO, ft_t_err, "error: nested call");
378 }
379 /* timeout time will be up to USPT microseconds too long ! */
380 timeout = (1000 * time + FT_USPT - 1) / FT_USPT;
381
382 spin_lock_irq(&current->sighand->siglock);
383 old_sigmask = current->blocked;
384 sigfillset(&current->blocked);
385 recalc_sigpending();
386 spin_unlock_irq(&current->sighand->siglock);
387
388 set_current_state(TASK_INTERRUPTIBLE);
389 add_wait_queue(&ftape_wait_intr, &wait);
390 while (!ft_interrupt_seen && timeout)
391 timeout = schedule_timeout_interruptible(timeout);
392
393 spin_lock_irq(&current->sighand->siglock);
394 current->blocked = old_sigmask;
395 recalc_sigpending();
396 spin_unlock_irq(&current->sighand->siglock);
397
398 remove_wait_queue(&ftape_wait_intr, &wait);
399 /* the following IS necessary. True: as well
400 * wake_up_interruptible() as the schedule() set TASK_RUNNING
401 * when they wakeup a task, BUT: it may very well be that
402 * ft_interrupt_seen is already set to 1 when we enter here
403 * in which case schedule() gets never called, and
404 * TASK_RUNNING never set. This has the funny effect that we
405 * execute all the code until we leave kernel space, but then
406 * the task is stopped (a task CANNOT be preempted while in
407 * kernel mode. Sending a pair of SIGSTOP/SIGCONT to the
408 * tasks wakes it up again. Funny! :-)
409 */
410 current->state = TASK_RUNNING;
411 if (ft_interrupt_seen) { /* woken up by interrupt */
412 ft_interrupt_seen = 0;
413 TRACE_EXIT 0;
414 }
415 /* Original comment:
416 * In first instance, next statement seems unnecessary since
417 * it will be cleared in fdc_command. However, a small part of
418 * the software seems to rely on this being cleared here
419 * (ftape_close might fail) so stick to it until things get fixed !
420 */
421 /* My deeply sought of knowledge:
422 * Behold NO! It is obvious. fdc_reset() doesn't call fdc_command()
423 * but nevertheless uses fdc_interrupt_wait(). OF COURSE this needs to
424 * be reset here.
425 */
426 ft_interrupt_seen = 0; /* clear for next call */
427 if (!resetting) {
428 resetting = 1; /* break infinite recursion if reset fails */
429 TRACE(ft_t_any, "cleanup reset");
430 fdc_reset();
431 resetting = 0;
432 }
433 TRACE_EXIT (signal_pending(current)) ? -EINTR : -ETIME;
434}
435
436/* Start/stop drive motor. Enable DMA mode.
437 */
438void fdc_motor(int motor)
439{
440 int unit = ft_drive_sel;
441 int data = unit | FDC_RESET_NOT | FDC_DMA_MODE;
442 TRACE_FUN(ft_t_any);
443
444 ftape_motor = motor;
445 if (ftape_motor) {
446 data |= FDC_MOTOR_0 << unit;
447 TRACE(ft_t_noise, "turning motor %d on", unit);
448 } else {
449 TRACE(ft_t_noise, "turning motor %d off", unit);
450 }
451 if (ft_mach2) {
452 outb_p(data, fdc.dor2);
453 } else {
454 outb_p(data, fdc.dor);
455 }
456 ftape_sleep(10 * FT_MILLISECOND);
457 TRACE_EXIT;
458}
459
460static void fdc_update_dsr(void)
461{
462 TRACE_FUN(ft_t_any);
463
464 TRACE(ft_t_flow, "rate = %d Kbps, precomp = %d ns",
465 fdc_data_rate, fdc_precomp);
466 if (fdc.type >= i82077) {
467 outb_p((fdc_rate_code & 0x03) | fdc_prec_code, fdc.dsr);
468 } else {
469 outb_p(fdc_rate_code & 0x03, fdc.ccr);
470 }
471 TRACE_EXIT;
472}
473
474void fdc_set_write_precomp(int precomp)
475{
476 TRACE_FUN(ft_t_any);
477
478 TRACE(ft_t_noise, "New precomp: %d nsec", precomp);
479 fdc_precomp = precomp;
480 /* write precompensation can be set in multiples of 41.67 nsec.
481 * round the parameter to the nearest multiple and convert it
482 * into a fdc setting. Note that 0 means default to the fdc,
483 * 7 is used instead of that.
484 */
485 fdc_prec_code = ((fdc_precomp + 21) / 42) << 2;
486 if (fdc_prec_code == 0 || fdc_prec_code > (6 << 2)) {
487 fdc_prec_code = 7 << 2;
488 }
489 fdc_update_dsr();
490 TRACE_EXIT;
491}
492
493/* Reprogram the 82078 registers to use Data Rate Table 1 on all drives.
494 */
495static void fdc_set_drive_specs(void)
496{
497 __u8 cmd[] = { FDC_DRIVE_SPEC, 0x00, 0x00, 0x00, 0x00, 0xc0};
498 int result;
499 TRACE_FUN(ft_t_any);
500
501 TRACE(ft_t_flow, "Setting of drive specs called");
502 if (fdc.type >= i82078_1) {
503 cmd[1] = (0 << 5) | (2 << 2);
504 cmd[2] = (1 << 5) | (2 << 2);
505 cmd[3] = (2 << 5) | (2 << 2);
506 cmd[4] = (3 << 5) | (2 << 2);
507 result = fdc_command(cmd, NR_ITEMS(cmd));
508 if (result < 0) {
509 TRACE(ft_t_err, "Setting of drive specs failed");
510 }
511 }
512 TRACE_EXIT;
513}
514
515/* Select clock for fdc, must correspond with tape drive setting !
516 * This also influences the fdc timing so we must adjust some values.
517 */
518int fdc_set_data_rate(int rate)
519{
520 int bad_rate = 0;
521 TRACE_FUN(ft_t_any);
522
523 /* Select clock for fdc, must correspond with tape drive setting !
524 * This also influences the fdc timing so we must adjust some values.
525 */
526 TRACE(ft_t_fdc_dma, "new rate = %d", rate);
527 switch (rate) {
528 case 250:
529 fdc_rate_code = fdc_data_rate_250;
530 break;
531 case 500:
532 fdc_rate_code = fdc_data_rate_500;
533 break;
534 case 1000:
535 if (fdc.type < i82077) {
536 bad_rate = 1;
537 } else {
538 fdc_rate_code = fdc_data_rate_1000;
539 }
540 break;
541 case 2000:
542 if (fdc.type < i82078_1) {
543 bad_rate = 1;
544 } else {
545 fdc_rate_code = fdc_data_rate_2000;
546 }
547 break;
548 default:
549 bad_rate = 1;
550 }
551 if (bad_rate) {
552 TRACE_ABORT(-EIO,
553 ft_t_fdc_dma, "%d is not a valid data rate", rate);
554 }
555 fdc_data_rate = rate;
556 fdc_update_dsr();
557 fdc_set_seek_rate(fdc_seek_rate); /* clock changed! */
558 ftape_udelay(1000);
559 TRACE_EXIT 0;
560}
561
562/* keep the unit select if keep_select is != 0,
563 */
564static void fdc_dor_reset(int keep_select)
565{
566 __u8 fdc_ctl = ft_drive_sel;
567
568 if (keep_select != 0) {
569 fdc_ctl |= FDC_DMA_MODE;
570 if (ftape_motor) {
571 fdc_ctl |= FDC_MOTOR_0 << ft_drive_sel;
572 }
573 }
574 ftape_udelay(10); /* ??? but seems to be necessary */
575 if (ft_mach2) {
576 outb_p(fdc_ctl & 0x0f, fdc.dor);
577 outb_p(fdc_ctl, fdc.dor2);
578 } else {
579 outb_p(fdc_ctl, fdc.dor);
580 }
581 fdc_usec_wait(10); /* delay >= 14 fdc clocks */
582 if (keep_select == 0) {
583 fdc_ctl = 0;
584 }
585 fdc_ctl |= FDC_RESET_NOT;
586 if (ft_mach2) {
587 outb_p(fdc_ctl & 0x0f, fdc.dor);
588 outb_p(fdc_ctl, fdc.dor2);
589 } else {
590 outb_p(fdc_ctl, fdc.dor);
591 }
592}
593
594/* Reset the floppy disk controller. Leave the ftape_unit selected.
595 */
596void fdc_reset(void)
597{
598 int st0;
599 int i;
600 int dummy;
601 unsigned long flags;
602 TRACE_FUN(ft_t_any);
603
604 spin_lock_irqsave(&fdc_io_lock, flags);
605
606 fdc_dor_reset(1); /* keep unit selected */
607
608 fdc_mode = fdc_idle;
609
610 /* maybe the spin_lock_irq* pair is not necessary, BUT:
611 * the following line MUST be here. Otherwise fdc_interrupt_wait()
612 * won't wait. Note that fdc_reset() is called from
613 * ftape_dumb_stop() when the fdc is busy transferring data. In this
614 * case fdc_isr() MOST PROBABLY sets ft_interrupt_seen, and tries
615 * to get the result bytes from the fdc etc. CLASH.
616 */
617 ft_interrupt_seen = 0;
618
619 /* Program data rate
620 */
621 fdc_update_dsr(); /* restore data rate and precomp */
622
623 spin_unlock_irqrestore(&fdc_io_lock, flags);
624
625 /*
626 * Wait for first polling cycle to complete
627 */
628 if (fdc_interrupt_wait(1 * FT_SECOND) < 0) {
629 TRACE(ft_t_err, "no drive polling interrupt!");
630 } else { /* clear all disk-changed statuses */
631 for (i = 0; i < 4; ++i) {
632 if(fdc_sense_interrupt_status(&st0, &dummy) != 0) {
633 TRACE(ft_t_err, "sense failed for %d", i);
634 }
635 if (i == ft_drive_sel) {
636 ftape_current_cylinder = dummy;
637 }
638 }
639 TRACE(ft_t_noise, "drive polling completed");
640 }
641 /*
642 * SPECIFY COMMAND
643 */
644 fdc_set_seek_rate(fdc_seek_rate);
645 /*
646 * DRIVE SPECIFICATION COMMAND (if fdc type known)
647 */
648 if (fdc.type >= i82078_1) {
649 fdc_set_drive_specs();
650 }
651 TRACE_EXIT;
652}
653
654#if !defined(CLK_48MHZ)
655# define CLK_48MHZ 1
656#endif
657
658/* When we're done, put the fdc into reset mode so that the regular
659 * floppy disk driver will figure out that something is wrong and
660 * initialize the controller the way it wants.
661 */
662void fdc_disable(void)
663{
664 __u8 cmd1[] = {FDC_CONFIGURE, 0x00, 0x00, 0x00};
665 __u8 cmd2[] = {FDC_LOCK};
666 __u8 cmd3[] = {FDC_UNLOCK};
667 __u8 stat[1];
668 TRACE_FUN(ft_t_flow);
669
670 if (!fdc_fifo_locked) {
671 fdc_reset();
672 TRACE_EXIT;
673 }
674 if (fdc_issue_command(cmd3, 1, stat, 1) < 0 || stat[0] != 0x00) {
675 fdc_dor_reset(0);
676 TRACE_ABORT(/**/, ft_t_bug,
677 "couldn't unlock fifo, configuration remains changed");
678 }
679 fdc_fifo_locked = 0;
680 if (CLK_48MHZ && fdc.type >= i82078) {
681 cmd1[0] |= FDC_CLK48_BIT;
682 }
683 cmd1[2] = ((fdc_fifo_state) ? 0 : 0x20) + (fdc_fifo_thr - 1);
684 if (fdc_command(cmd1, NR_ITEMS(cmd1)) < 0) {
685 fdc_dor_reset(0);
686 TRACE_ABORT(/**/, ft_t_bug,
687 "couldn't reconfigure fifo to old state");
688 }
689 if (fdc_lock_state &&
690 fdc_issue_command(cmd2, 1, stat, 1) < 0) {
691 fdc_dor_reset(0);
692 TRACE_ABORT(/**/, ft_t_bug, "couldn't lock old state again");
693 }
694 TRACE(ft_t_noise, "fifo restored: %sabled, thr. %d, %slocked",
695 fdc_fifo_state ? "en" : "dis",
696 fdc_fifo_thr, (fdc_lock_state) ? "" : "not ");
697 fdc_dor_reset(0);
698 TRACE_EXIT;
699}
700
701/* Specify FDC seek-rate (milliseconds)
702 */
703static int fdc_set_seek_rate(int seek_rate)
704{
705 /* set step rate, dma mode, and minimal head load and unload times
706 */
707 __u8 in[3] = { FDC_SPECIFY, 1, (1 << 1)};
708
709 fdc_seek_rate = seek_rate;
710 in[1] |= (16 - (fdc_data_rate * fdc_seek_rate) / 500) << 4;
711
712 return fdc_command(in, 3);
713}
714
715/* Sense drive status: get unit's drive status (ST3)
716 */
717int fdc_sense_drive_status(int *st3)
718{
719 __u8 out[2];
720 __u8 in[1];
721 TRACE_FUN(ft_t_any);
722
723 out[0] = FDC_SENSED;
724 out[1] = ft_drive_sel;
725 TRACE_CATCH(fdc_issue_command(out, 2, in, 1),);
726 *st3 = in[0];
727 TRACE_EXIT 0;
728}
729
730/* Sense Interrupt Status command:
731 * should be issued at the end of each seek.
732 * get ST0 and current cylinder.
733 */
734int fdc_sense_interrupt_status(int *st0, int *current_cylinder)
735{
736 __u8 out[1];
737 __u8 in[2];
738 TRACE_FUN(ft_t_any);
739
740 out[0] = FDC_SENSEI;
741 TRACE_CATCH(fdc_issue_command(out, 1, in, 2),);
742 *st0 = in[0];
743 *current_cylinder = in[1];
744 TRACE_EXIT 0;
745}
746
747/* step to track
748 */
749int fdc_seek(int track)
750{
751 __u8 out[3];
752 int st0, pcn;
753#ifdef TESTING
754 unsigned int time;
755#endif
756 TRACE_FUN(ft_t_any);
757
758 out[0] = FDC_SEEK;
759 out[1] = ft_drive_sel;
760 out[2] = track;
761#ifdef TESTING
762 time = ftape_timestamp();
763#endif
764 /* We really need this command to work !
765 */
766 ft_seek_completed = 0;
767 TRACE_CATCH(fdc_command(out, 3),
768 fdc_reset();
769 TRACE(ft_t_noise, "destination was: %d, resetting FDC...",
770 track));
771 /* Handle interrupts until ft_seek_completed or timeout.
772 */
773 for (;;) {
774 TRACE_CATCH(fdc_interrupt_wait(2 * FT_SECOND),);
775 if (ft_seek_completed) {
776 TRACE_CATCH(fdc_sense_interrupt_status(&st0, &pcn),);
777 if ((st0 & ST0_SEEK_END) == 0) {
778 TRACE_ABORT(-EIO, ft_t_err,
779 "no seek-end after seek completion !??");
780 }
781 break;
782 }
783 }
784#ifdef TESTING
785 time = ftape_timediff(time, ftape_timestamp()) / abs(track - ftape_current_cylinder);
786 if ((time < 900 || time > 3100) && abs(track - ftape_current_cylinder) > 5) {
787 TRACE(ft_t_warn, "Wrong FDC STEP interval: %d usecs (%d)",
788 time, track - ftape_current_cylinder);
789 }
790#endif
791 /* Verify whether we issued the right tape command.
792 */
793 /* Verify that we seek to the proper track. */
794 if (pcn != track) {
795 TRACE_ABORT(-EIO, ft_t_err, "bad seek..");
796 }
797 ftape_current_cylinder = track;
798 TRACE_EXIT 0;
799}
800
801static int perpend_mode; /* set if fdc is in perpendicular mode */
802
803static int perpend_off(void)
804{
805 __u8 perpend[] = {FDC_PERPEND, 0x00};
806 TRACE_FUN(ft_t_any);
807
808 if (perpend_mode) {
809 /* Turn off perpendicular mode */
810 perpend[1] = 0x80;
811 TRACE_CATCH(fdc_command(perpend, 2),
812 TRACE(ft_t_err,"Perpendicular mode exit failed!"));
813 perpend_mode = 0;
814 }
815 TRACE_EXIT 0;
816}
817
818static int handle_perpend(int segment_id)
819{
820 __u8 perpend[] = {FDC_PERPEND, 0x00};
821 TRACE_FUN(ft_t_any);
822
823 /* When writing QIC-3020 tapes, turn on perpendicular mode
824 * if tape is moving in forward direction (even tracks).
825 */
826 if (ft_qic_std == QIC_TAPE_QIC3020 &&
827 ((segment_id / ft_segments_per_track) & 1) == 0) {
828/* FIXME: some i82077 seem to support perpendicular mode as
829 * well.
830 */
831#if 0
832 if (fdc.type < i82077AA) {}
833#else
834 if (fdc.type < i82077 && ft_data_rate < 1000) {
835#endif
836 /* fdc does not support perpendicular mode: complain
837 */
838 TRACE_ABORT(-EIO, ft_t_err,
839 "Your FDC does not support QIC-3020.");
840 }
841 perpend[1] = 0x03 /* 0x83 + (0x4 << ft_drive_sel) */ ;
842 TRACE_CATCH(fdc_command(perpend, 2),
843 TRACE(ft_t_err,"Perpendicular mode entry failed!"));
844 TRACE(ft_t_flow, "Perpendicular mode set");
845 perpend_mode = 1;
846 TRACE_EXIT 0;
847 }
848 TRACE_EXIT perpend_off();
849}
850
851static inline void fdc_setup_dma(char mode,
852 volatile void *addr, unsigned int count)
853{
854 /* Program the DMA controller.
855 */
856 disable_dma(fdc.dma);
857 clear_dma_ff(fdc.dma);
858 set_dma_mode(fdc.dma, mode);
859 set_dma_addr(fdc.dma, virt_to_bus((void*)addr));
860 set_dma_count(fdc.dma, count);
861 enable_dma(fdc.dma);
862}
863
864/* Setup fdc and dma for formatting the next segment
865 */
866int fdc_setup_formatting(buffer_struct * buff)
867{
868 unsigned long flags;
869 __u8 out[6] = {
870 FDC_FORMAT, 0x00, 3, 4 * FT_SECTORS_PER_SEGMENT, 0x00, 0x6b
871 };
872 TRACE_FUN(ft_t_any);
873
874 TRACE_CATCH(handle_perpend(buff->segment_id),);
875 /* Program the DMA controller.
876 */
877 TRACE(ft_t_fdc_dma,
878 "phys. addr. = %lx", virt_to_bus((void*) buff->ptr));
879 spin_lock_irqsave(&fdc_io_lock, flags);
880 fdc_setup_dma(DMA_MODE_WRITE, buff->ptr, FT_SECTORS_PER_SEGMENT * 4);
881 /* Issue FDC command to start reading/writing.
882 */
883 out[1] = ft_drive_sel;
884 out[4] = buff->gap3;
885 TRACE_CATCH(fdc_setup_error = fdc_command(out, sizeof(out)),
886 restore_flags(flags); fdc_mode = fdc_idle);
887 spin_unlock_irqrestore(&fdc_io_lock, flags);
888 TRACE_EXIT 0;
889}
890
891
892/* Setup Floppy Disk Controller and DMA to read or write the next cluster
893 * of good sectors from or to the current segment.
894 */
895int fdc_setup_read_write(buffer_struct * buff, __u8 operation)
896{
897 unsigned long flags;
898 __u8 out[9];
899 int dma_mode;
900 TRACE_FUN(ft_t_any);
901
902 switch(operation) {
903 case FDC_VERIFY:
904 if (fdc.type < i82077) {
905 operation = FDC_READ;
906 }
907 case FDC_READ:
908 case FDC_READ_DELETED:
909 dma_mode = DMA_MODE_READ;
910 TRACE(ft_t_fdc_dma, "xfer %d sectors to 0x%p",
911 buff->sector_count, buff->ptr);
912 TRACE_CATCH(perpend_off(),);
913 break;
914 case FDC_WRITE_DELETED:
915 TRACE(ft_t_noise, "deleting segment %d", buff->segment_id);
916 case FDC_WRITE:
917 dma_mode = DMA_MODE_WRITE;
918 /* When writing QIC-3020 tapes, turn on perpendicular mode
919 * if tape is moving in forward direction (even tracks).
920 */
921 TRACE_CATCH(handle_perpend(buff->segment_id),);
922 TRACE(ft_t_fdc_dma, "xfer %d sectors from 0x%p",
923 buff->sector_count, buff->ptr);
924 break;
925 default:
926 TRACE_ABORT(-EIO,
927 ft_t_bug, "bug: invalid operation parameter");
928 }
929 TRACE(ft_t_fdc_dma, "phys. addr. = %lx",virt_to_bus((void*)buff->ptr));
930 spin_lock_irqsave(&fdc_io_lock, flags);
931 if (operation != FDC_VERIFY) {
932 fdc_setup_dma(dma_mode, buff->ptr,
933 FT_SECTOR_SIZE * buff->sector_count);
934 }
935 /* Issue FDC command to start reading/writing.
936 */
937 out[0] = operation;
938 out[1] = ft_drive_sel;
939 out[2] = buff->cyl;
940 out[3] = buff->head;
941 out[4] = buff->sect + buff->sector_offset;
942 out[5] = 3; /* Sector size of 1K. */
943 out[6] = out[4] + buff->sector_count - 1; /* last sector */
944 out[7] = 109; /* Gap length. */
945 out[8] = 0xff; /* No limit to transfer size. */
946 TRACE(ft_t_fdc_dma, "C: 0x%02x, H: 0x%02x, R: 0x%02x, cnt: 0x%02x",
947 out[2], out[3], out[4], out[6] - out[4] + 1);
948 spin_unlock_irqrestore(&fdc_io_lock, flags);
949 TRACE_CATCH(fdc_setup_error = fdc_command(out, 9),fdc_mode = fdc_idle);
950 TRACE_EXIT 0;
951}
952
953int fdc_fifo_threshold(__u8 threshold,
954 int *fifo_state, int *lock_state, int *fifo_thr)
955{
956 const __u8 cmd0[] = {FDC_DUMPREGS};
957 __u8 cmd1[] = {FDC_CONFIGURE, 0, (0x0f & (threshold - 1)), 0};
958 const __u8 cmd2[] = {FDC_LOCK};
959 const __u8 cmd3[] = {FDC_UNLOCK};
960 __u8 reg[10];
961 __u8 stat;
962 int i;
963 int result;
964 TRACE_FUN(ft_t_any);
965
966 if (CLK_48MHZ && fdc.type >= i82078) {
967 cmd1[0] |= FDC_CLK48_BIT;
968 }
969 /* Dump fdc internal registers for examination
970 */
971 TRACE_CATCH(fdc_command(cmd0, NR_ITEMS(cmd0)),
972 TRACE(ft_t_warn, "dumpreg cmd failed, fifo unchanged"));
973 /* Now read fdc internal registers from fifo
974 */
975 for (i = 0; i < (int)NR_ITEMS(reg); ++i) {
976 fdc_read(&reg[i]);
977 TRACE(ft_t_fdc_dma, "Register %d = 0x%02x", i, reg[i]);
978 }
979 if (fifo_state && lock_state && fifo_thr) {
980 *fifo_state = (reg[8] & 0x20) == 0;
981 *lock_state = reg[7] & 0x80;
982 *fifo_thr = 1 + (reg[8] & 0x0f);
983 }
984 TRACE(ft_t_noise,
985 "original fifo state: %sabled, threshold %d, %slocked",
986 ((reg[8] & 0x20) == 0) ? "en" : "dis",
987 1 + (reg[8] & 0x0f), (reg[7] & 0x80) ? "" : "not ");
988 /* If fdc is already locked, unlock it first ! */
989 if (reg[7] & 0x80) {
990 fdc_ready_wait(100);
991 TRACE_CATCH(fdc_issue_command(cmd3, NR_ITEMS(cmd3), &stat, 1),
992 TRACE(ft_t_bug, "FDC unlock command failed, "
993 "configuration unchanged"));
994 }
995 fdc_fifo_locked = 0;
996 /* Enable fifo and set threshold at xx bytes to allow a
997 * reasonably large latency and reduce number of dma bursts.
998 */
999 fdc_ready_wait(100);
1000 if ((result = fdc_command(cmd1, NR_ITEMS(cmd1))) < 0) {
1001 TRACE(ft_t_bug, "configure cmd failed, fifo unchanged");
1002 }
1003 /* Now lock configuration so reset will not change it
1004 */
1005 if(fdc_issue_command(cmd2, NR_ITEMS(cmd2), &stat, 1) < 0 ||
1006 stat != 0x10) {
1007 TRACE_ABORT(-EIO, ft_t_bug,
1008 "FDC lock command failed, stat = 0x%02x", stat);
1009 }
1010 fdc_fifo_locked = 1;
1011 TRACE_EXIT result;
1012}
1013
1014static int fdc_fifo_enable(void)
1015{
1016 TRACE_FUN(ft_t_any);
1017
1018 if (fdc_fifo_locked) {
1019 TRACE_ABORT(0, ft_t_warn, "Fifo not enabled because locked");
1020 }
1021 TRACE_CATCH(fdc_fifo_threshold(ft_fdc_threshold /* bytes */,
1022 &fdc_fifo_state,
1023 &fdc_lock_state,
1024 &fdc_fifo_thr),);
1025 TRACE_CATCH(fdc_fifo_threshold(ft_fdc_threshold /* bytes */,
1026 NULL, NULL, NULL),);
1027 TRACE_EXIT 0;
1028}
1029
1030/* Determine fd controller type
1031 */
1032static __u8 fdc_save_state[2];
1033
1034static int fdc_probe(void)
1035{
1036 __u8 cmd[1];
1037 __u8 stat[16]; /* must be able to hold dumpregs & save results */
1038 int i;
1039 TRACE_FUN(ft_t_any);
1040
1041 /* Try to find out what kind of fd controller we have to deal with
1042 * Scheme borrowed from floppy driver:
1043 * first try if FDC_DUMPREGS command works
1044 * (this indicates that we have a 82072 or better)
1045 * then try the FDC_VERSION command (82072 doesn't support this)
1046 * then try the FDC_UNLOCK command (some older 82077's don't support this)
1047 * then try the FDC_PARTID command (82078's support this)
1048 */
1049 cmd[0] = FDC_DUMPREGS;
1050 if (fdc_issue_command(cmd, 1, stat, 1) != 0) {
1051 TRACE_ABORT(no_fdc, ft_t_bug, "No FDC found");
1052 }
1053 if (stat[0] == 0x80) {
1054 /* invalid command: must be pre 82072 */
1055 TRACE_ABORT(i8272,
1056 ft_t_warn, "Type 8272A/765A compatible FDC found");
1057 }
1058 fdc_result(&stat[1], 9);
1059 fdc_save_state[0] = stat[7];
1060 fdc_save_state[1] = stat[8];
1061 cmd[0] = FDC_VERSION;
1062 if (fdc_issue_command(cmd, 1, stat, 1) < 0 || stat[0] == 0x80) {
1063 TRACE_ABORT(i8272, ft_t_warn, "Type 82072 FDC found");
1064 }
1065 if (*stat != 0x90) {
1066 TRACE_ABORT(i8272, ft_t_warn, "Unknown FDC found");
1067 }
1068 cmd[0] = FDC_UNLOCK;
1069 if(fdc_issue_command(cmd, 1, stat, 1) < 0 || stat[0] != 0x00) {
1070 TRACE_ABORT(i8272, ft_t_warn,
1071 "Type pre-1991 82077 FDC found, "
1072 "treating it like a 82072");
1073 }
1074 if (fdc_save_state[0] & 0x80) { /* was locked */
1075 cmd[0] = FDC_LOCK; /* restore lock */
1076 (void)fdc_issue_command(cmd, 1, stat, 1);
1077 TRACE(ft_t_warn, "FDC is already locked");
1078 }
1079 /* Test for a i82078 FDC */
1080 cmd[0] = FDC_PARTID;
1081 if (fdc_issue_command(cmd, 1, stat, 1) < 0 || stat[0] == 0x80) {
1082 /* invalid command: not a i82078xx type FDC */
1083 for (i = 0; i < 4; ++i) {
1084 outb_p(i, fdc.tdr);
1085 if ((inb_p(fdc.tdr) & 0x03) != i) {
1086 TRACE_ABORT(i82077,
1087 ft_t_warn, "Type 82077 FDC found");
1088 }
1089 }
1090 TRACE_ABORT(i82077AA, ft_t_warn, "Type 82077AA FDC found");
1091 }
1092 /* FDC_PARTID cmd succeeded */
1093 switch (stat[0] >> 5) {
1094 case 0x0:
1095 /* i82078SL or i82078-1. The SL part cannot run at
1096 * 2Mbps (the SL and -1 dies are identical; they are
1097 * speed graded after production, according to Intel).
1098 * Some SL's can be detected by doing a SAVE cmd and
1099 * look at bit 7 of the first byte (the SEL3V# bit).
1100 * If it is 0, the part runs off 3Volts, and hence it
1101 * is a SL.
1102 */
1103 cmd[0] = FDC_SAVE;
1104 if(fdc_issue_command(cmd, 1, stat, 16) < 0) {
1105 TRACE(ft_t_err, "FDC_SAVE failed. Dunno why");
1106 /* guess we better claim the fdc to be a i82078 */
1107 TRACE_ABORT(i82078,
1108 ft_t_warn,
1109 "Type i82078 FDC (i suppose) found");
1110 }
1111 if ((stat[0] & FDC_SEL3V_BIT)) {
1112 /* fdc running off 5Volts; Pray that it's a i82078-1
1113 */
1114 TRACE_ABORT(i82078_1, ft_t_warn,
1115 "Type i82078-1 or 5Volt i82078SL FDC found");
1116 }
1117 TRACE_ABORT(i82078, ft_t_warn,
1118 "Type 3Volt i82078SL FDC (1Mbps) found");
1119 case 0x1:
1120 case 0x2: /* S82078B */
1121 /* The '78B isn't '78 compatible. Detect it as a '77AA */
1122 TRACE_ABORT(i82077AA, ft_t_warn, "Type i82077AA FDC found");
1123 case 0x3: /* NSC PC8744 core; used in several super-IO chips */
1124 TRACE_ABORT(i82077AA,
1125 ft_t_warn, "Type 82077AA compatible FDC found");
1126 default:
1127 TRACE(ft_t_warn, "A previously undetected FDC found");
1128 TRACE_ABORT(i82077AA, ft_t_warn,
1129 "Treating it as a 82077AA. Please report partid= %d",
1130 stat[0]);
1131 } /* switch(stat[ 0] >> 5) */
1132 TRACE_EXIT no_fdc;
1133}
1134
1135static int fdc_request_regions(void)
1136{
1137 TRACE_FUN(ft_t_flow);
1138
1139 if (ft_mach2 || ft_probe_fc10) {
1140 if (!request_region(fdc.sra, 8, "fdc (ft)")) {
1141#ifndef BROKEN_FLOPPY_DRIVER
1142 TRACE_EXIT -EBUSY;
1143#else
1144 TRACE(ft_t_warn,
1145"address 0x%03x occupied (by floppy driver?), using it anyway", fdc.sra);
1146#endif
1147 }
1148 } else {
1149 if (!request_region(fdc.sra, 6, "fdc (ft)")) {
1150#ifndef BROKEN_FLOPPY_DRIVER
1151 TRACE_EXIT -EBUSY;
1152#else
1153 TRACE(ft_t_warn,
1154"address 0x%03x occupied (by floppy driver?), using it anyway", fdc.sra);
1155#endif
1156 }
1157 if (!request_region(fdc.sra + 7, 1, "fdc (ft)")) {
1158#ifndef BROKEN_FLOPPY_DRIVER
1159 release_region(fdc.sra, 6);
1160 TRACE_EXIT -EBUSY;
1161#else
1162 TRACE(ft_t_warn,
1163"address 0x%03x occupied (by floppy driver?), using it anyway", fdc.sra + 7);
1164#endif
1165 }
1166 }
1167 TRACE_EXIT 0;
1168}
1169
1170void fdc_release_regions(void)
1171{
1172 TRACE_FUN(ft_t_flow);
1173
1174 if (fdc.sra != 0) {
1175 if (fdc.dor2 != 0) {
1176 release_region(fdc.sra, 8);
1177 } else {
1178 release_region(fdc.sra, 6);
1179 release_region(fdc.dir, 1);
1180 }
1181 }
1182 TRACE_EXIT;
1183}
1184
1185static int fdc_config_regs(unsigned int fdc_base,
1186 unsigned int fdc_irq,
1187 unsigned int fdc_dma)
1188{
1189 TRACE_FUN(ft_t_flow);
1190
1191 fdc.irq = fdc_irq;
1192 fdc.dma = fdc_dma;
1193 fdc.sra = fdc_base;
1194 fdc.srb = fdc_base + 1;
1195 fdc.dor = fdc_base + 2;
1196 fdc.tdr = fdc_base + 3;
1197 fdc.msr = fdc.dsr = fdc_base + 4;
1198 fdc.fifo = fdc_base + 5;
1199 fdc.dir = fdc.ccr = fdc_base + 7;
1200 fdc.dor2 = (ft_mach2 || ft_probe_fc10) ? fdc_base + 6 : 0;
1201 TRACE_CATCH(fdc_request_regions(), fdc.sra = 0);
1202 TRACE_EXIT 0;
1203}
1204
1205static int fdc_config(void)
1206{
1207 static int already_done;
1208 TRACE_FUN(ft_t_any);
1209
1210 if (already_done) {
1211 TRACE_CATCH(fdc_request_regions(),);
1212 *(fdc.hook) = fdc_isr; /* hook our handler in */
1213 TRACE_EXIT 0;
1214 }
1215 if (ft_probe_fc10) {
1216 int fc_type;
1217
1218 TRACE_CATCH(fdc_config_regs(ft_fdc_base,
1219 ft_fdc_irq, ft_fdc_dma),);
1220 fc_type = fc10_enable();
1221 if (fc_type != 0) {
1222 TRACE(ft_t_warn, "FC-%c0 controller found", '0' + fc_type);
1223 fdc.type = fc10;
1224 fdc.hook = &do_ftape;
1225 *(fdc.hook) = fdc_isr; /* hook our handler in */
1226 already_done = 1;
1227 TRACE_EXIT 0;
1228 } else {
1229 TRACE(ft_t_warn, "FC-10/20 controller not found");
1230 fdc_release_regions();
1231 fdc.type = no_fdc;
1232 ft_probe_fc10 = 0;
1233 ft_fdc_base = 0x3f0;
1234 ft_fdc_irq = 6;
1235 ft_fdc_dma = 2;
1236 }
1237 }
1238 TRACE(ft_t_warn, "fdc base: 0x%x, irq: %d, dma: %d",
1239 ft_fdc_base, ft_fdc_irq, ft_fdc_dma);
1240 TRACE_CATCH(fdc_config_regs(ft_fdc_base, ft_fdc_irq, ft_fdc_dma),);
1241 fdc.hook = &do_ftape;
1242 *(fdc.hook) = fdc_isr; /* hook our handler in */
1243 already_done = 1;
1244 TRACE_EXIT 0;
1245}
1246
1247static irqreturn_t ftape_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1248{
1249 void (*handler) (void) = *fdc.hook;
1250 int handled = 0;
1251 TRACE_FUN(ft_t_any);
1252
1253 *fdc.hook = NULL;
1254 if (handler) {
1255 handled = 1;
1256 handler();
1257 } else {
1258 TRACE(ft_t_bug, "Unexpected ftape interrupt");
1259 }
1260 TRACE_EXIT IRQ_RETVAL(handled);
1261}
1262
1263static int fdc_grab_irq_and_dma(void)
1264{
1265 TRACE_FUN(ft_t_any);
1266
1267 if (fdc.hook == &do_ftape) {
1268 /* Get fast interrupt handler.
1269 */
1270 if (request_irq(fdc.irq, ftape_interrupt,
1271 IRQF_DISABLED, "ft", ftape_id)) {
1272 TRACE_ABORT(-EIO, ft_t_bug,
1273 "Unable to grab IRQ%d for ftape driver",
1274 fdc.irq);
1275 }
1276 if (request_dma(fdc.dma, ftape_id)) {
1277 free_irq(fdc.irq, ftape_id);
1278 TRACE_ABORT(-EIO, ft_t_bug,
1279 "Unable to grab DMA%d for ftape driver",
1280 fdc.dma);
1281 }
1282 }
1283 if (ft_fdc_base != 0x3f0 && (ft_fdc_dma == 2 || ft_fdc_irq == 6)) {
1284 /* Using same dma channel or irq as standard fdc, need
1285 * to disable the dma-gate on the std fdc. This
1286 * couldn't be done in the floppy driver as some
1287 * laptops are using the dma-gate to enter a low power
1288 * or even suspended state :-(
1289 */
1290 outb_p(FDC_RESET_NOT, 0x3f2);
1291 TRACE(ft_t_noise, "DMA-gate on standard fdc disabled");
1292 }
1293 TRACE_EXIT 0;
1294}
1295
1296int fdc_release_irq_and_dma(void)
1297{
1298 TRACE_FUN(ft_t_any);
1299
1300 if (fdc.hook == &do_ftape) {
1301 disable_dma(fdc.dma); /* just in case... */
1302 free_dma(fdc.dma);
1303 free_irq(fdc.irq, ftape_id);
1304 }
1305 if (ft_fdc_base != 0x3f0 && (ft_fdc_dma == 2 || ft_fdc_irq == 6)) {
1306 /* Using same dma channel as standard fdc, need to
1307 * disable the dma-gate on the std fdc. This couldn't
1308 * be done in the floppy driver as some laptops are
1309 * using the dma-gate to enter a low power or even
1310 * suspended state :-(
1311 */
1312 outb_p(FDC_RESET_NOT | FDC_DMA_MODE, 0x3f2);
1313 TRACE(ft_t_noise, "DMA-gate on standard fdc enabled again");
1314 }
1315 TRACE_EXIT 0;
1316}
1317
1318int fdc_init(void)
1319{
1320 TRACE_FUN(ft_t_any);
1321
1322 /* find a FDC to use */
1323 TRACE_CATCH(fdc_config(),);
1324 TRACE_CATCH(fdc_grab_irq_and_dma(), fdc_release_regions());
1325 ftape_motor = 0;
1326 fdc_catch_stray_interrupts(0); /* clear number of awainted
1327 * stray interrupte
1328 */
1329 fdc_catch_stray_interrupts(1); /* one always comes (?) */
1330 TRACE(ft_t_flow, "resetting fdc");
1331 fdc_set_seek_rate(2); /* use nominal QIC step rate */
1332 fdc_reset(); /* init fdc & clear track counters */
1333 if (fdc.type == no_fdc) { /* no FC-10 or FC-20 found */
1334 fdc.type = fdc_probe();
1335 fdc_reset(); /* update with new knowledge */
1336 }
1337 if (fdc.type == no_fdc) {
1338 fdc_release_irq_and_dma();
1339 fdc_release_regions();
1340 TRACE_EXIT -ENXIO;
1341 }
1342 if (fdc.type >= i82077) {
1343 if (fdc_fifo_enable() < 0) {
1344 TRACE(ft_t_warn, "couldn't enable fdc fifo !");
1345 } else {
1346 TRACE(ft_t_flow, "fdc fifo enabled and locked");
1347 }
1348 }
1349 TRACE_EXIT 0;
1350}
diff --git a/drivers/char/ftape/lowlevel/fdc-io.h b/drivers/char/ftape/lowlevel/fdc-io.h
deleted file mode 100644
index 7ec3c72178bb..000000000000
--- a/drivers/char/ftape/lowlevel/fdc-io.h
+++ /dev/null
@@ -1,252 +0,0 @@
1#ifndef _FDC_IO_H
2#define _FDC_IO_H
3
4/*
5 * Copyright (C) 1993-1996 Bas Laarhoven,
6 * (C) 1996-1997 Claus-Justus Heine.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 *
23 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/fdc-io.h,v $
24 * $Revision: 1.3 $
25 * $Date: 1997/10/05 19:18:06 $
26 *
27 * This file contains the declarations for the low level
28 * functions that communicate with the floppy disk controller,
29 * for the QIC-40/80/3010/3020 floppy-tape driver "ftape" for
30 * Linux.
31 */
32
33#include <linux/fdreg.h>
34
35#include "../lowlevel/ftape-bsm.h"
36
37#define FDC_SK_BIT (0x20)
38#define FDC_MT_BIT (0x80)
39
40#define FDC_READ (FD_READ & ~(FDC_SK_BIT | FDC_MT_BIT))
41#define FDC_WRITE (FD_WRITE & ~FDC_MT_BIT)
42#define FDC_READ_DELETED (0x4c)
43#define FDC_WRITE_DELETED (0x49)
44#define FDC_VERIFY (0x56)
45#define FDC_READID (0x4a)
46#define FDC_SENSED (0x04)
47#define FDC_SENSEI (FD_SENSEI)
48#define FDC_FORMAT (FD_FORMAT)
49#define FDC_RECAL (FD_RECALIBRATE)
50#define FDC_SEEK (FD_SEEK)
51#define FDC_SPECIFY (FD_SPECIFY)
52#define FDC_RECALIBR (FD_RECALIBRATE)
53#define FDC_VERSION (FD_VERSION)
54#define FDC_PERPEND (FD_PERPENDICULAR)
55#define FDC_DUMPREGS (FD_DUMPREGS)
56#define FDC_LOCK (FD_LOCK)
57#define FDC_UNLOCK (FD_UNLOCK)
58#define FDC_CONFIGURE (FD_CONFIGURE)
59#define FDC_DRIVE_SPEC (0x8e) /* i82078 has this (any others?) */
60#define FDC_PARTID (0x18) /* i82078 has this */
61#define FDC_SAVE (0x2e) /* i82078 has this (any others?) */
62#define FDC_RESTORE (0x4e) /* i82078 has this (any others?) */
63
64#define FDC_STATUS_MASK (STATUS_BUSY | STATUS_DMA | STATUS_DIR | STATUS_READY)
65#define FDC_DATA_READY (STATUS_READY)
66#define FDC_DATA_OUTPUT (STATUS_DIR)
67#define FDC_DATA_READY_MASK (STATUS_READY | STATUS_DIR)
68#define FDC_DATA_OUT_READY (STATUS_READY | STATUS_DIR)
69#define FDC_DATA_IN_READY (STATUS_READY)
70#define FDC_BUSY (STATUS_BUSY)
71#define FDC_CLK48_BIT (0x80)
72#define FDC_SEL3V_BIT (0x40)
73
74#define ST0_INT_MASK (ST0_INTR)
75#define FDC_INT_NORMAL (ST0_INTR & 0x00)
76#define FDC_INT_ABNORMAL (ST0_INTR & 0x40)
77#define FDC_INT_INVALID (ST0_INTR & 0x80)
78#define FDC_INT_READYCH (ST0_INTR & 0xC0)
79#define ST0_SEEK_END (ST0_SE)
80#define ST3_TRACK_0 (ST3_TZ)
81
82#define FDC_RESET_NOT (0x04)
83#define FDC_DMA_MODE (0x08)
84#define FDC_MOTOR_0 (0x10)
85#define FDC_MOTOR_1 (0x20)
86
87typedef struct {
88 void (**hook) (void); /* our wedge into the isr */
89 enum {
90 no_fdc, i8272, i82077, i82077AA, fc10,
91 i82078, i82078_1
92 } type; /* FDC type */
93 unsigned int irq; /* FDC irq nr */
94 unsigned int dma; /* FDC dma channel nr */
95 __u16 sra; /* Status register A (PS/2 only) */
96 __u16 srb; /* Status register B (PS/2 only) */
97 __u16 dor; /* Digital output register */
98 __u16 tdr; /* Tape Drive Register (82077SL-1 &
99 82078 only) */
100 __u16 msr; /* Main Status Register */
101 __u16 dsr; /* Datarate Select Register (8207x only) */
102 __u16 fifo; /* Data register / Fifo on 8207x */
103 __u16 dir; /* Digital Input Register */
104 __u16 ccr; /* Configuration Control Register */
105 __u16 dor2; /* Alternate dor on MACH-2 controller,
106 also used with FC-10, meaning unknown */
107} fdc_config_info;
108
109typedef enum {
110 fdc_data_rate_250 = 2,
111 fdc_data_rate_300 = 1, /* any fdc in default configuration */
112 fdc_data_rate_500 = 0,
113 fdc_data_rate_1000 = 3,
114 fdc_data_rate_2000 = 1, /* i82078-1: when using Data Rate Table #2 */
115} fdc_data_rate_type;
116
117typedef enum {
118 fdc_idle = 0,
119 fdc_reading_data = FDC_READ,
120 fdc_seeking = FDC_SEEK,
121 fdc_writing_data = FDC_WRITE,
122 fdc_deleting = FDC_WRITE_DELETED,
123 fdc_reading_id = FDC_READID,
124 fdc_recalibrating = FDC_RECAL,
125 fdc_formatting = FDC_FORMAT,
126 fdc_verifying = FDC_VERIFY
127} fdc_mode_enum;
128
129typedef enum {
130 waiting = 0,
131 reading,
132 writing,
133 formatting,
134 verifying,
135 deleting,
136 done,
137 error,
138 mmapped,
139} buffer_state_enum;
140
141typedef struct {
142 __u8 *address;
143 volatile buffer_state_enum status;
144 volatile __u8 *ptr;
145 volatile unsigned int bytes;
146 volatile unsigned int segment_id;
147
148 /* bitmap for remainder of segment not yet handled.
149 * one bit set for each bad sector that must be skipped.
150 */
151 volatile SectorMap bad_sector_map;
152
153 /* bitmap with bad data blocks in data buffer.
154 * the errors in this map may be retried.
155 */
156 volatile SectorMap soft_error_map;
157
158 /* bitmap with bad data blocks in data buffer
159 * the errors in this map may not be retried.
160 */
161 volatile SectorMap hard_error_map;
162
163 /* retry counter for soft errors.
164 */
165 volatile int retry;
166
167 /* sectors to skip on retry ???
168 */
169 volatile unsigned int skip;
170
171 /* nr of data blocks in data buffer
172 */
173 volatile unsigned int data_offset;
174
175 /* offset in segment for first sector to be handled.
176 */
177 volatile unsigned int sector_offset;
178
179 /* size of cluster of good sectors to be handled.
180 */
181 volatile unsigned int sector_count;
182
183 /* size of remaining part of segment to be handled.
184 */
185 volatile unsigned int remaining;
186
187 /* points to next segment (contiguous) to be handled,
188 * or is zero if no read-ahead is allowed.
189 */
190 volatile unsigned int next_segment;
191
192 /* flag being set if deleted data was read.
193 */
194 volatile int deleted;
195
196 /* floppy coordinates of first sector in segment */
197 volatile __u8 head;
198 volatile __u8 cyl;
199 volatile __u8 sect;
200
201 /* gap to use when formatting */
202 __u8 gap3;
203 /* flag set when buffer is mmaped */
204 int mmapped;
205} buffer_struct;
206
207/*
208 * fdc-io.c defined public variables
209 */
210extern volatile fdc_mode_enum fdc_mode;
211extern int fdc_setup_error; /* outdated ??? */
212extern wait_queue_head_t ftape_wait_intr;
213extern volatile int ftape_current_cylinder; /* track nr FDC thinks we're on */
214extern volatile __u8 fdc_head; /* FDC head */
215extern volatile __u8 fdc_cyl; /* FDC track */
216extern volatile __u8 fdc_sect; /* FDC sector */
217extern fdc_config_info fdc; /* FDC hardware configuration */
218
219extern unsigned int ft_fdc_base;
220extern unsigned int ft_fdc_irq;
221extern unsigned int ft_fdc_dma;
222extern unsigned int ft_fdc_threshold;
223extern unsigned int ft_fdc_rate_limit;
224extern int ft_probe_fc10;
225extern int ft_mach2;
226/*
227 * fdc-io.c defined public functions
228 */
229extern void fdc_catch_stray_interrupts(int count);
230extern int fdc_ready_wait(unsigned int timeout);
231extern int fdc_command(const __u8 * cmd_data, int cmd_len);
232extern int fdc_result(__u8 * res_data, int res_len);
233extern int fdc_interrupt_wait(unsigned int time);
234extern int fdc_seek(int track);
235extern int fdc_sense_drive_status(int *st3);
236extern void fdc_motor(int motor);
237extern void fdc_reset(void);
238extern void fdc_disable(void);
239extern int fdc_fifo_threshold(__u8 threshold,
240 int *fifo_state, int *lock_state, int *fifo_thr);
241extern void fdc_wait_calibrate(void);
242extern int fdc_sense_interrupt_status(int *st0, int *current_cylinder);
243extern void fdc_save_drive_specs(void);
244extern void fdc_restore_drive_specs(void);
245extern int fdc_set_data_rate(int rate);
246extern void fdc_set_write_precomp(int precomp);
247extern int fdc_release_irq_and_dma(void);
248extern void fdc_release_regions(void);
249extern int fdc_init(void);
250extern int fdc_setup_read_write(buffer_struct * buff, __u8 operation);
251extern int fdc_setup_formatting(buffer_struct * buff);
252#endif
diff --git a/drivers/char/ftape/lowlevel/fdc-isr.c b/drivers/char/ftape/lowlevel/fdc-isr.c
deleted file mode 100644
index ad2bc733ae1b..000000000000
--- a/drivers/char/ftape/lowlevel/fdc-isr.c
+++ /dev/null
@@ -1,1170 +0,0 @@
1/*
2 * Copyright (C) 1994-1996 Bas Laarhoven,
3 * (C) 1996-1997 Claus-Justus Heine.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 *
20 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/fdc-isr.c,v $
21 * $Revision: 1.9 $
22 * $Date: 1997/10/17 23:01:53 $
23 *
24 * This file contains the interrupt service routine and
25 * associated code for the QIC-40/80/3010/3020 floppy-tape driver
26 * "ftape" for Linux.
27 */
28
29#include <asm/io.h>
30#include <asm/dma.h>
31
32#define volatile /* */
33
34#include <linux/ftape.h>
35#include <linux/qic117.h>
36#include "../lowlevel/ftape-tracing.h"
37#include "../lowlevel/fdc-isr.h"
38#include "../lowlevel/fdc-io.h"
39#include "../lowlevel/ftape-ctl.h"
40#include "../lowlevel/ftape-rw.h"
41#include "../lowlevel/ftape-io.h"
42#include "../lowlevel/ftape-calibr.h"
43#include "../lowlevel/ftape-bsm.h"
44
45/* Global vars.
46 */
47volatile int ft_expected_stray_interrupts;
48volatile int ft_interrupt_seen;
49volatile int ft_seek_completed;
50volatile int ft_hide_interrupt;
51/* Local vars.
52 */
53typedef enum {
54 no_error = 0, id_am_error = 0x01, id_crc_error = 0x02,
55 data_am_error = 0x04, data_crc_error = 0x08,
56 no_data_error = 0x10, overrun_error = 0x20,
57} error_cause;
58static int stop_read_ahead;
59
60
61static void print_error_cause(int cause)
62{
63 TRACE_FUN(ft_t_any);
64
65 switch (cause) {
66 case no_data_error:
67 TRACE(ft_t_noise, "no data error");
68 break;
69 case id_am_error:
70 TRACE(ft_t_noise, "id am error");
71 break;
72 case id_crc_error:
73 TRACE(ft_t_noise, "id crc error");
74 break;
75 case data_am_error:
76 TRACE(ft_t_noise, "data am error");
77 break;
78 case data_crc_error:
79 TRACE(ft_t_noise, "data crc error");
80 break;
81 case overrun_error:
82 TRACE(ft_t_noise, "overrun error");
83 break;
84 default:;
85 }
86 TRACE_EXIT;
87}
88
89static char *fdc_mode_txt(fdc_mode_enum mode)
90{
91 switch (mode) {
92 case fdc_idle:
93 return "fdc_idle";
94 case fdc_reading_data:
95 return "fdc_reading_data";
96 case fdc_seeking:
97 return "fdc_seeking";
98 case fdc_writing_data:
99 return "fdc_writing_data";
100 case fdc_reading_id:
101 return "fdc_reading_id";
102 case fdc_recalibrating:
103 return "fdc_recalibrating";
104 case fdc_formatting:
105 return "fdc_formatting";
106 case fdc_verifying:
107 return "fdc_verifying";
108 default:
109 return "unknown";
110 }
111}
112
113static inline error_cause decode_irq_cause(fdc_mode_enum mode, __u8 st[])
114{
115 error_cause cause = no_error;
116 TRACE_FUN(ft_t_any);
117
118 /* Valid st[], decode cause of interrupt.
119 */
120 switch (st[0] & ST0_INT_MASK) {
121 case FDC_INT_NORMAL:
122 TRACE(ft_t_fdc_dma,"normal completion: %s",fdc_mode_txt(mode));
123 break;
124 case FDC_INT_ABNORMAL:
125 TRACE(ft_t_flow, "abnormal completion %s", fdc_mode_txt(mode));
126 TRACE(ft_t_fdc_dma, "ST0: 0x%02x, ST1: 0x%02x, ST2: 0x%02x",
127 st[0], st[1], st[2]);
128 TRACE(ft_t_fdc_dma,
129 "C: 0x%02x, H: 0x%02x, R: 0x%02x, N: 0x%02x",
130 st[3], st[4], st[5], st[6]);
131 if (st[1] & 0x01) {
132 if (st[2] & 0x01) {
133 cause = data_am_error;
134 } else {
135 cause = id_am_error;
136 }
137 } else if (st[1] & 0x20) {
138 if (st[2] & 0x20) {
139 cause = data_crc_error;
140 } else {
141 cause = id_crc_error;
142 }
143 } else if (st[1] & 0x04) {
144 cause = no_data_error;
145 } else if (st[1] & 0x10) {
146 cause = overrun_error;
147 }
148 print_error_cause(cause);
149 break;
150 case FDC_INT_INVALID:
151 TRACE(ft_t_flow, "invalid completion %s", fdc_mode_txt(mode));
152 break;
153 case FDC_INT_READYCH:
154 if (st[0] & ST0_SEEK_END) {
155 TRACE(ft_t_flow, "drive poll completed");
156 } else {
157 TRACE(ft_t_flow, "ready change %s",fdc_mode_txt(mode));
158 }
159 break;
160 default:
161 break;
162 }
163 TRACE_EXIT cause;
164}
165
166static void update_history(error_cause cause)
167{
168 switch (cause) {
169 case id_am_error:
170 ft_history.id_am_errors++;
171 break;
172 case id_crc_error:
173 ft_history.id_crc_errors++;
174 break;
175 case data_am_error:
176 ft_history.data_am_errors++;
177 break;
178 case data_crc_error:
179 ft_history.data_crc_errors++;
180 break;
181 case overrun_error:
182 ft_history.overrun_errors++;
183 break;
184 case no_data_error:
185 ft_history.no_data_errors++;
186 break;
187 default:;
188 }
189}
190
191static void skip_bad_sector(buffer_struct * buff)
192{
193 TRACE_FUN(ft_t_any);
194
195 /* Mark sector as soft error and skip it
196 */
197 if (buff->remaining > 0) {
198 ++buff->sector_offset;
199 ++buff->data_offset;
200 --buff->remaining;
201 buff->ptr += FT_SECTOR_SIZE;
202 buff->bad_sector_map >>= 1;
203 } else {
204 /* Hey, what is this????????????? C code: if we shift
205 * more than 31 bits, we get no shift. That's bad!!!!!!
206 */
207 ++buff->sector_offset; /* hack for error maps */
208 TRACE(ft_t_warn, "skipping last sector in segment");
209 }
210 TRACE_EXIT;
211}
212
213static void update_error_maps(buffer_struct * buff, unsigned int error_offset)
214{
215 int hard = 0;
216 TRACE_FUN(ft_t_any);
217
218 if (buff->retry < FT_SOFT_RETRIES) {
219 buff->soft_error_map |= (1 << error_offset);
220 } else {
221 buff->hard_error_map |= (1 << error_offset);
222 buff->soft_error_map &= ~buff->hard_error_map;
223 buff->retry = -1; /* will be set to 0 in setup_segment */
224 hard = 1;
225 }
226 TRACE(ft_t_noise, "sector %d : %s error\n"
227 KERN_INFO "hard map: 0x%08lx\n"
228 KERN_INFO "soft map: 0x%08lx",
229 FT_SECTOR(error_offset), hard ? "hard" : "soft",
230 (long) buff->hard_error_map, (long) buff->soft_error_map);
231 TRACE_EXIT;
232}
233
234static void print_progress(buffer_struct *buff, error_cause cause)
235{
236 TRACE_FUN(ft_t_any);
237
238 switch (cause) {
239 case no_error:
240 TRACE(ft_t_flow,"%d Sector(s) transferred", buff->sector_count);
241 break;
242 case no_data_error:
243 TRACE(ft_t_flow, "Sector %d not found",
244 FT_SECTOR(buff->sector_offset));
245 break;
246 case overrun_error:
247 /* got an overrun error on the first byte, must be a
248 * hardware problem
249 */
250 TRACE(ft_t_bug,
251 "Unexpected error: failing DMA or FDC controller ?");
252 break;
253 case data_crc_error:
254 TRACE(ft_t_flow, "Error in sector %d",
255 FT_SECTOR(buff->sector_offset - 1));
256 break;
257 case id_crc_error:
258 case id_am_error:
259 case data_am_error:
260 TRACE(ft_t_flow, "Error in sector %d",
261 FT_SECTOR(buff->sector_offset));
262 break;
263 default:
264 TRACE(ft_t_flow, "Unexpected error at sector %d",
265 FT_SECTOR(buff->sector_offset));
266 break;
267 }
268 TRACE_EXIT;
269}
270
271/*
272 * Error cause: Amount xferred: Action:
273 *
274 * id_am_error 0 mark bad and skip
275 * id_crc_error 0 mark bad and skip
276 * data_am_error 0 mark bad and skip
277 * data_crc_error % 1024 mark bad and skip
278 * no_data_error 0 retry on write
279 * mark bad and skip on read
280 * overrun_error [ 0..all-1 ] mark bad and skip
281 * no_error all continue
282 */
283
284/* the arg `sector' is returned by the fdc and tells us at which sector we
285 * are positioned at (relative to starting sector of segment)
286 */
287static void determine_verify_progress(buffer_struct *buff,
288 error_cause cause,
289 __u8 sector)
290{
291 TRACE_FUN(ft_t_any);
292
293 if (cause == no_error && sector == 1) {
294 buff->sector_offset = FT_SECTORS_PER_SEGMENT;
295 buff->remaining = 0;
296 if (TRACE_LEVEL >= ft_t_flow) {
297 print_progress(buff, cause);
298 }
299 } else {
300 buff->sector_offset = sector - buff->sect;
301 buff->remaining = FT_SECTORS_PER_SEGMENT - buff->sector_offset;
302 TRACE(ft_t_noise, "%ssector offset: 0x%04x",
303 (cause == no_error) ? "unexpected " : "",
304 buff->sector_offset);
305 switch (cause) {
306 case overrun_error:
307 break;
308#if 0
309 case no_data_error:
310 buff->retry = FT_SOFT_RETRIES;
311 if (buff->hard_error_map &&
312 buff->sector_offset > 1 &&
313 (buff->hard_error_map &
314 (1 << (buff->sector_offset-2)))) {
315 buff->retry --;
316 }
317 break;
318#endif
319 default:
320 buff->retry = FT_SOFT_RETRIES;
321 break;
322 }
323 if (TRACE_LEVEL >= ft_t_flow) {
324 print_progress(buff, cause);
325 }
326 /* Sector_offset points to the problem area Now adjust
327 * sector_offset so it always points one past he failing
328 * sector. I.e. skip the bad sector.
329 */
330 ++buff->sector_offset;
331 --buff->remaining;
332 update_error_maps(buff, buff->sector_offset - 1);
333 }
334 TRACE_EXIT;
335}
336
337static void determine_progress(buffer_struct *buff,
338 error_cause cause,
339 __u8 sector)
340{
341 unsigned int dma_residue;
342 TRACE_FUN(ft_t_any);
343
344 /* Using less preferred order of disable_dma and
345 * get_dma_residue because this seems to fail on at least one
346 * system if reversed!
347 */
348 dma_residue = get_dma_residue(fdc.dma);
349 disable_dma(fdc.dma);
350 if (cause != no_error || dma_residue != 0) {
351 TRACE(ft_t_noise, "%sDMA residue: 0x%04x",
352 (cause == no_error) ? "unexpected " : "",
353 dma_residue);
354 /* adjust to actual value: */
355 if (dma_residue == 0) {
356 /* this happens sometimes with overrun errors.
357 * I don't know whether we could ignore the
358 * overrun error. Play save.
359 */
360 buff->sector_count --;
361 } else {
362 buff->sector_count -= ((dma_residue +
363 (FT_SECTOR_SIZE - 1)) /
364 FT_SECTOR_SIZE);
365 }
366 }
367 /* Update var's influenced by the DMA operation.
368 */
369 if (buff->sector_count > 0) {
370 buff->sector_offset += buff->sector_count;
371 buff->data_offset += buff->sector_count;
372 buff->ptr += (buff->sector_count *
373 FT_SECTOR_SIZE);
374 buff->remaining -= buff->sector_count;
375 buff->bad_sector_map >>= buff->sector_count;
376 }
377 if (TRACE_LEVEL >= ft_t_flow) {
378 print_progress(buff, cause);
379 }
380 if (cause != no_error) {
381 if (buff->remaining == 0) {
382 TRACE(ft_t_warn, "foo?\n"
383 KERN_INFO "count : %d\n"
384 KERN_INFO "offset: %d\n"
385 KERN_INFO "soft : %08x\n"
386 KERN_INFO "hard : %08x",
387 buff->sector_count,
388 buff->sector_offset,
389 buff->soft_error_map,
390 buff->hard_error_map);
391 }
392 /* Sector_offset points to the problem area, except if we got
393 * a data_crc_error. In that case it points one past the
394 * failing sector.
395 *
396 * Now adjust sector_offset so it always points one past he
397 * failing sector. I.e. skip the bad sector.
398 */
399 if (cause != data_crc_error) {
400 skip_bad_sector(buff);
401 }
402 update_error_maps(buff, buff->sector_offset - 1);
403 }
404 TRACE_EXIT;
405}
406
407static int calc_steps(int cmd)
408{
409 if (ftape_current_cylinder > cmd) {
410 return ftape_current_cylinder - cmd;
411 } else {
412 return ftape_current_cylinder + cmd;
413 }
414}
415
416static void pause_tape(int retry, int mode)
417{
418 int result;
419 __u8 out[3] = {FDC_SEEK, ft_drive_sel, 0};
420 TRACE_FUN(ft_t_any);
421
422 /* We'll use a raw seek command to get the tape to rewind and
423 * stop for a retry.
424 */
425 ++ft_history.rewinds;
426 if (qic117_cmds[ftape_current_command].non_intr) {
427 TRACE(ft_t_warn, "motion command may be issued too soon");
428 }
429 if (retry && (mode == fdc_reading_data ||
430 mode == fdc_reading_id ||
431 mode == fdc_verifying)) {
432 ftape_current_command = QIC_MICRO_STEP_PAUSE;
433 ftape_might_be_off_track = 1;
434 } else {
435 ftape_current_command = QIC_PAUSE;
436 }
437 out[2] = calc_steps(ftape_current_command);
438 result = fdc_command(out, 3); /* issue QIC_117 command */
439 ftape_current_cylinder = out[ 2];
440 if (result < 0) {
441 TRACE(ft_t_noise, "qic-pause failed, status = %d", result);
442 } else {
443 ft_location.known = 0;
444 ft_runner_status = idle;
445 ft_hide_interrupt = 1;
446 ftape_tape_running = 0;
447 }
448 TRACE_EXIT;
449}
450
451static void continue_xfer(buffer_struct *buff,
452 fdc_mode_enum mode,
453 unsigned int skip)
454{
455 int write = 0;
456 TRACE_FUN(ft_t_any);
457
458 if (mode == fdc_writing_data || mode == fdc_deleting) {
459 write = 1;
460 }
461 /* This part can be removed if it never happens
462 */
463 if (skip > 0 &&
464 (ft_runner_status != running ||
465 (write && (buff->status != writing)) ||
466 (!write && (buff->status != reading &&
467 buff->status != verifying)))) {
468 TRACE(ft_t_err, "unexpected runner/buffer state %d/%d",
469 ft_runner_status, buff->status);
470 buff->status = error;
471 /* finish this buffer: */
472 (void)ftape_next_buffer(ft_queue_head);
473 ft_runner_status = aborting;
474 fdc_mode = fdc_idle;
475 } else if (buff->remaining > 0 && ftape_calc_next_cluster(buff) > 0) {
476 /* still sectors left in current segment, continue
477 * with this segment
478 */
479 if (fdc_setup_read_write(buff, mode) < 0) {
480 /* failed, abort operation
481 */
482 buff->bytes = buff->ptr - buff->address;
483 buff->status = error;
484 /* finish this buffer: */
485 (void)ftape_next_buffer(ft_queue_head);
486 ft_runner_status = aborting;
487 fdc_mode = fdc_idle;
488 }
489 } else {
490 /* current segment completed
491 */
492 unsigned int last_segment = buff->segment_id;
493 int eot = ((last_segment + 1) % ft_segments_per_track) == 0;
494 unsigned int next = buff->next_segment; /* 0 means stop ! */
495
496 buff->bytes = buff->ptr - buff->address;
497 buff->status = done;
498 buff = ftape_next_buffer(ft_queue_head);
499 if (eot) {
500 /* finished last segment on current track,
501 * can't continue
502 */
503 ft_runner_status = logical_eot;
504 fdc_mode = fdc_idle;
505 TRACE_EXIT;
506 }
507 if (next <= 0) {
508 /* don't continue with next segment
509 */
510 TRACE(ft_t_noise, "no %s allowed, stopping tape",
511 (write) ? "write next" : "read ahead");
512 pause_tape(0, mode);
513 ft_runner_status = idle; /* not quite true until
514 * next irq
515 */
516 TRACE_EXIT;
517 }
518 /* continue with next segment
519 */
520 if (buff->status != waiting) {
521 TRACE(ft_t_noise, "all input buffers %s, pausing tape",
522 (write) ? "empty" : "full");
523 pause_tape(0, mode);
524 ft_runner_status = idle; /* not quite true until
525 * next irq
526 */
527 TRACE_EXIT;
528 }
529 if (write && next != buff->segment_id) {
530 TRACE(ft_t_noise,
531 "segments out of order, aborting write");
532 ft_runner_status = do_abort;
533 fdc_mode = fdc_idle;
534 TRACE_EXIT;
535 }
536 ftape_setup_new_segment(buff, next, 0);
537 if (stop_read_ahead) {
538 buff->next_segment = 0;
539 stop_read_ahead = 0;
540 }
541 if (ftape_calc_next_cluster(buff) == 0 ||
542 fdc_setup_read_write(buff, mode) != 0) {
543 TRACE(ft_t_err, "couldn't start %s-ahead",
544 write ? "write" : "read");
545 ft_runner_status = do_abort;
546 fdc_mode = fdc_idle;
547 } else {
548 /* keep on going */
549 switch (ft_driver_state) {
550 case reading: buff->status = reading; break;
551 case verifying: buff->status = verifying; break;
552 case writing: buff->status = writing; break;
553 case deleting: buff->status = deleting; break;
554 default:
555 TRACE(ft_t_err,
556 "BUG: ft_driver_state %d should be one out of "
557 "{reading, writing, verifying, deleting}",
558 ft_driver_state);
559 buff->status = write ? writing : reading;
560 break;
561 }
562 }
563 }
564 TRACE_EXIT;
565}
566
567static void retry_sector(buffer_struct *buff,
568 int mode,
569 unsigned int skip)
570{
571 TRACE_FUN(ft_t_any);
572
573 TRACE(ft_t_noise, "%s error, will retry",
574 (mode == fdc_writing_data || mode == fdc_deleting) ? "write" : "read");
575 pause_tape(1, mode);
576 ft_runner_status = aborting;
577 buff->status = error;
578 buff->skip = skip;
579 TRACE_EXIT;
580}
581
582static unsigned int find_resume_point(buffer_struct *buff)
583{
584 int i = 0;
585 SectorMap mask;
586 SectorMap map;
587 TRACE_FUN(ft_t_any);
588
589 /* This function is to be called after all variables have been
590 * updated to point past the failing sector.
591 * If there are any soft errors before the failing sector,
592 * find the first soft error and return the sector offset.
593 * Otherwise find the last hard error.
594 * Note: there should always be at least one hard or soft error !
595 */
596 if (buff->sector_offset < 1 || buff->sector_offset > 32) {
597 TRACE(ft_t_bug, "BUG: sector_offset = %d",
598 buff->sector_offset);
599 TRACE_EXIT 0;
600 }
601 if (buff->sector_offset >= 32) { /* C-limitation on shift ! */
602 mask = 0xffffffff;
603 } else {
604 mask = (1 << buff->sector_offset) - 1;
605 }
606 map = buff->soft_error_map & mask;
607 if (map) {
608 while ((map & (1 << i)) == 0) {
609 ++i;
610 }
611 TRACE(ft_t_noise, "at sector %d", FT_SECTOR(i));
612 } else {
613 map = buff->hard_error_map & mask;
614 i = buff->sector_offset - 1;
615 if (map) {
616 while ((map & (1 << i)) == 0) {
617 --i;
618 }
619 TRACE(ft_t_noise, "after sector %d", FT_SECTOR(i));
620 ++i; /* first sector after last hard error */
621 } else {
622 TRACE(ft_t_bug, "BUG: no soft or hard errors");
623 }
624 }
625 TRACE_EXIT i;
626}
627
628/* check possible dma residue when formatting, update position record in
629 * buffer struct. This is, of course, modelled after determine_progress(), but
630 * we don't need to set up for retries because the format process cannot be
631 * interrupted (except at the end of the tape track).
632 */
633static int determine_fmt_progress(buffer_struct *buff, error_cause cause)
634{
635 unsigned int dma_residue;
636 TRACE_FUN(ft_t_any);
637
638 /* Using less preferred order of disable_dma and
639 * get_dma_residue because this seems to fail on at least one
640 * system if reversed!
641 */
642 dma_residue = get_dma_residue(fdc.dma);
643 disable_dma(fdc.dma);
644 if (cause != no_error || dma_residue != 0) {
645 TRACE(ft_t_info, "DMA residue = 0x%04x", dma_residue);
646 fdc_mode = fdc_idle;
647 switch(cause) {
648 case no_error:
649 ft_runner_status = aborting;
650 buff->status = idle;
651 break;
652 case overrun_error:
653 /* got an overrun error on the first byte, must be a
654 * hardware problem
655 */
656 TRACE(ft_t_bug,
657 "Unexpected error: failing DMA controller ?");
658 ft_runner_status = do_abort;
659 buff->status = error;
660 break;
661 default:
662 TRACE(ft_t_noise, "Unexpected error at segment %d",
663 buff->segment_id);
664 ft_runner_status = do_abort;
665 buff->status = error;
666 break;
667 }
668 TRACE_EXIT -EIO; /* can only retry entire track in format mode
669 */
670 }
671 /* Update var's influenced by the DMA operation.
672 */
673 buff->ptr += FT_SECTORS_PER_SEGMENT * 4;
674 buff->bytes -= FT_SECTORS_PER_SEGMENT * 4;
675 buff->remaining -= FT_SECTORS_PER_SEGMENT;
676 buff->segment_id ++; /* done with segment */
677 TRACE_EXIT 0;
678}
679
680/*
681 * Continue formatting, switch buffers if there is no data left in
682 * current buffer. This is, of course, modelled after
683 * continue_xfer(), but we don't need to set up for retries because
684 * the format process cannot be interrupted (except at the end of the
685 * tape track).
686 */
687static void continue_formatting(buffer_struct *buff)
688{
689 TRACE_FUN(ft_t_any);
690
691 if (buff->remaining <= 0) { /* no space left in dma buffer */
692 unsigned int next = buff->next_segment;
693
694 if (next == 0) { /* end of tape track */
695 buff->status = done;
696 ft_runner_status = logical_eot;
697 fdc_mode = fdc_idle;
698 TRACE(ft_t_noise, "Done formatting track %d",
699 ft_location.track);
700 TRACE_EXIT;
701 }
702 /*
703 * switch to next buffer!
704 */
705 buff->status = done;
706 buff = ftape_next_buffer(ft_queue_head);
707
708 if (buff->status != waiting || next != buff->segment_id) {
709 goto format_setup_error;
710 }
711 }
712 if (fdc_setup_formatting(buff) < 0) {
713 goto format_setup_error;
714 }
715 buff->status = formatting;
716 TRACE(ft_t_fdc_dma, "Formatting segment %d on track %d",
717 buff->segment_id, ft_location.track);
718 TRACE_EXIT;
719 format_setup_error:
720 ft_runner_status = do_abort;
721 fdc_mode = fdc_idle;
722 buff->status = error;
723 TRACE(ft_t_err, "Error setting up for segment %d on track %d",
724 buff->segment_id, ft_location.track);
725 TRACE_EXIT;
726
727}
728
729/* this handles writing, read id, reading and formatting
730 */
731static void handle_fdc_busy(buffer_struct *buff)
732{
733 static int no_data_error_count;
734 int retry = 0;
735 error_cause cause;
736 __u8 in[7];
737 int skip;
738 fdc_mode_enum fmode = fdc_mode;
739 TRACE_FUN(ft_t_any);
740
741 if (fdc_result(in, 7) < 0) { /* better get it fast ! */
742 TRACE(ft_t_err,
743 "Probably fatal error during FDC Result Phase\n"
744 KERN_INFO
745 "drive may hang until (power on) reset :-(");
746 /* what to do next ????
747 */
748 TRACE_EXIT;
749 }
750 cause = decode_irq_cause(fdc_mode, in);
751#ifdef TESTING
752 { int i;
753 for (i = 0; i < (int)ft_nr_buffers; ++i)
754 TRACE(ft_t_any, "buffer[%d] status: %d, segment_id: %d",
755 i, ft_buffer[i]->status, ft_buffer[i]->segment_id);
756 }
757#endif
758 if (fmode == fdc_reading_data && ft_driver_state == verifying) {
759 fmode = fdc_verifying;
760 }
761 switch (fmode) {
762 case fdc_verifying:
763 if (ft_runner_status == aborting ||
764 ft_runner_status == do_abort) {
765 TRACE(ft_t_noise,"aborting %s",fdc_mode_txt(fdc_mode));
766 break;
767 }
768 if (buff->retry > 0) {
769 TRACE(ft_t_flow, "this is retry nr %d", buff->retry);
770 }
771 switch (cause) {
772 case no_error:
773 no_data_error_count = 0;
774 determine_verify_progress(buff, cause, in[5]);
775 if (in[2] & 0x40) {
776 /* This should not happen when verifying
777 */
778 TRACE(ft_t_warn,
779 "deleted data in segment %d/%d",
780 buff->segment_id,
781 FT_SECTOR(buff->sector_offset - 1));
782 buff->remaining = 0; /* abort transfer */
783 buff->hard_error_map = EMPTY_SEGMENT;
784 skip = 1;
785 } else {
786 skip = 0;
787 }
788 continue_xfer(buff, fdc_mode, skip);
789 break;
790 case no_data_error:
791 no_data_error_count ++;
792 case overrun_error:
793 retry ++;
794 case id_am_error:
795 case id_crc_error:
796 case data_am_error:
797 case data_crc_error:
798 determine_verify_progress(buff, cause, in[5]);
799 if (cause == no_data_error) {
800 if (no_data_error_count >= 2) {
801 TRACE(ft_t_warn,
802 "retrying because of successive "
803 "no data errors");
804 no_data_error_count = 0;
805 } else {
806 retry --;
807 }
808 } else {
809 no_data_error_count = 0;
810 }
811 if (retry) {
812 skip = find_resume_point(buff);
813 } else {
814 skip = buff->sector_offset;
815 }
816 if (retry && skip < 32) {
817 retry_sector(buff, fdc_mode, skip);
818 } else {
819 continue_xfer(buff, fdc_mode, skip);
820 }
821 update_history(cause);
822 break;
823 default:
824 /* Don't know why this could happen
825 * but find out.
826 */
827 determine_verify_progress(buff, cause, in[5]);
828 retry_sector(buff, fdc_mode, 0);
829 TRACE(ft_t_err, "Error: unexpected error");
830 break;
831 }
832 break;
833 case fdc_reading_data:
834#ifdef TESTING
835 /* I'm sorry, but: NOBODY ever used this trace
836 * messages for ages. I guess that Bas was the last person
837 * that ever really used this (thank you, between the lines)
838 */
839 if (cause == no_error) {
840 TRACE(ft_t_flow,"reading segment %d",buff->segment_id);
841 } else {
842 TRACE(ft_t_noise, "error reading segment %d",
843 buff->segment_id);
844 TRACE(ft_t_noise, "\n"
845 KERN_INFO
846 "IRQ:C: 0x%02x, H: 0x%02x, R: 0x%02x, N: 0x%02x\n"
847 KERN_INFO
848 "BUF:C: 0x%02x, H: 0x%02x, R: 0x%02x",
849 in[3], in[4], in[5], in[6],
850 buff->cyl, buff->head, buff->sect);
851 }
852#endif
853 if (ft_runner_status == aborting ||
854 ft_runner_status == do_abort) {
855 TRACE(ft_t_noise,"aborting %s",fdc_mode_txt(fdc_mode));
856 break;
857 }
858 if (buff->bad_sector_map == FAKE_SEGMENT) {
859 /* This condition occurs when reading a `fake'
860 * sector that's not accessible. Doesn't
861 * really matter as we would have ignored it
862 * anyway !
863 *
864 * Chance is that we're past the next segment
865 * now, so the next operation may fail and
866 * result in a retry.
867 */
868 buff->remaining = 0; /* skip failing sector */
869 /* buff->ptr = buff->address; */
870 /* fake success: */
871 continue_xfer(buff, fdc_mode, 1);
872 /* trace calls are expensive: place them AFTER
873 * the real stuff has been done.
874 *
875 */
876 TRACE(ft_t_noise, "skipping empty segment %d (read), size? %d",
877 buff->segment_id, buff->ptr - buff->address);
878 TRACE_EXIT;
879 }
880 if (buff->retry > 0) {
881 TRACE(ft_t_flow, "this is retry nr %d", buff->retry);
882 }
883 switch (cause) {
884 case no_error:
885 determine_progress(buff, cause, in[5]);
886 if (in[2] & 0x40) {
887 /* Handle deleted data in header segments.
888 * Skip segment and force read-ahead.
889 */
890 TRACE(ft_t_warn,
891 "deleted data in segment %d/%d",
892 buff->segment_id,
893 FT_SECTOR(buff->sector_offset - 1));
894 buff->deleted = 1;
895 buff->remaining = 0;/*abort transfer */
896 buff->soft_error_map |=
897 (-1L << buff->sector_offset);
898 if (buff->segment_id == 0) {
899 /* stop on next segment */
900 stop_read_ahead = 1;
901 }
902 /* force read-ahead: */
903 buff->next_segment =
904 buff->segment_id + 1;
905 skip = (FT_SECTORS_PER_SEGMENT -
906 buff->sector_offset);
907 } else {
908 skip = 0;
909 }
910 continue_xfer(buff, fdc_mode, skip);
911 break;
912 case no_data_error:
913 /* Tape started too far ahead of or behind the
914 * right sector. This may also happen in the
915 * middle of a segment !
916 *
917 * Handle no-data as soft error. If next
918 * sector fails too, a retry (with needed
919 * reposition) will follow.
920 */
921 retry ++;
922 case id_am_error:
923 case id_crc_error:
924 case data_am_error:
925 case data_crc_error:
926 case overrun_error:
927 retry += (buff->soft_error_map != 0 ||
928 buff->hard_error_map != 0);
929 determine_progress(buff, cause, in[5]);
930#if 1 || defined(TESTING)
931 if (cause == overrun_error) retry ++;
932#endif
933 if (retry) {
934 skip = find_resume_point(buff);
935 } else {
936 skip = buff->sector_offset;
937 }
938 /* Try to resume with next sector on single
939 * errors (let ecc correct it), but retry on
940 * no_data (we'll be past the target when we
941 * get here so we cannot retry) or on
942 * multiple errors (reduce chance on ecc
943 * failure).
944 */
945 /* cH: 23/02/97: if the last sector in the
946 * segment was a hard error, then there is
947 * no sense in a retry. This occasion seldom
948 * occurs but ... @:³²¸`@%&§$
949 */
950 if (retry && skip < 32) {
951 retry_sector(buff, fdc_mode, skip);
952 } else {
953 continue_xfer(buff, fdc_mode, skip);
954 }
955 update_history(cause);
956 break;
957 default:
958 /* Don't know why this could happen
959 * but find out.
960 */
961 determine_progress(buff, cause, in[5]);
962 retry_sector(buff, fdc_mode, 0);
963 TRACE(ft_t_err, "Error: unexpected error");
964 break;
965 }
966 break;
967 case fdc_reading_id:
968 if (cause == no_error) {
969 fdc_cyl = in[3];
970 fdc_head = in[4];
971 fdc_sect = in[5];
972 TRACE(ft_t_fdc_dma,
973 "id read: C: 0x%02x, H: 0x%02x, R: 0x%02x",
974 fdc_cyl, fdc_head, fdc_sect);
975 } else { /* no valid information, use invalid sector */
976 fdc_cyl = fdc_head = fdc_sect = 0;
977 TRACE(ft_t_flow, "Didn't find valid sector Id");
978 }
979 fdc_mode = fdc_idle;
980 break;
981 case fdc_deleting:
982 case fdc_writing_data:
983#ifdef TESTING
984 if (cause == no_error) {
985 TRACE(ft_t_flow, "writing segment %d", buff->segment_id);
986 } else {
987 TRACE(ft_t_noise, "error writing segment %d",
988 buff->segment_id);
989 }
990#endif
991 if (ft_runner_status == aborting ||
992 ft_runner_status == do_abort) {
993 TRACE(ft_t_flow, "aborting %s",fdc_mode_txt(fdc_mode));
994 break;
995 }
996 if (buff->retry > 0) {
997 TRACE(ft_t_flow, "this is retry nr %d", buff->retry);
998 }
999 if (buff->bad_sector_map == FAKE_SEGMENT) {
1000 /* This condition occurs when trying to write to a
1001 * `fake' sector that's not accessible. Doesn't really
1002 * matter as it isn't used anyway ! Might be located
1003 * at wrong segment, then we'll fail on the next
1004 * segment.
1005 */
1006 TRACE(ft_t_noise, "skipping empty segment (write)");
1007 buff->remaining = 0; /* skip failing sector */
1008 /* fake success: */
1009 continue_xfer(buff, fdc_mode, 1);
1010 break;
1011 }
1012 switch (cause) {
1013 case no_error:
1014 determine_progress(buff, cause, in[5]);
1015 continue_xfer(buff, fdc_mode, 0);
1016 break;
1017 case no_data_error:
1018 case id_am_error:
1019 case id_crc_error:
1020 case data_am_error:
1021 case overrun_error:
1022 update_history(cause);
1023 determine_progress(buff, cause, in[5]);
1024 skip = find_resume_point(buff);
1025 retry_sector(buff, fdc_mode, skip);
1026 break;
1027 default:
1028 if (in[1] & 0x02) {
1029 TRACE(ft_t_err, "media not writable");
1030 } else {
1031 TRACE(ft_t_bug, "unforeseen write error");
1032 }
1033 fdc_mode = fdc_idle;
1034 break;
1035 }
1036 break; /* fdc_deleting || fdc_writing_data */
1037 case fdc_formatting:
1038 /* The interrupt comes after formatting a segment. We then
1039 * have to set up QUICKLY for the next segment. But
1040 * afterwards, there is plenty of time.
1041 */
1042 switch (cause) {
1043 case no_error:
1044 /* would like to keep most of the formatting stuff
1045 * outside the isr code, but timing is too critical
1046 */
1047 if (determine_fmt_progress(buff, cause) >= 0) {
1048 continue_formatting(buff);
1049 }
1050 break;
1051 case no_data_error:
1052 case id_am_error:
1053 case id_crc_error:
1054 case data_am_error:
1055 case overrun_error:
1056 default:
1057 determine_fmt_progress(buff, cause);
1058 update_history(cause);
1059 if (in[1] & 0x02) {
1060 TRACE(ft_t_err, "media not writable");
1061 } else {
1062 TRACE(ft_t_bug, "unforeseen write error");
1063 }
1064 break;
1065 } /* cause */
1066 break;
1067 default:
1068 TRACE(ft_t_warn, "Warning: unexpected irq during: %s",
1069 fdc_mode_txt(fdc_mode));
1070 fdc_mode = fdc_idle;
1071 break;
1072 }
1073 TRACE_EXIT;
1074}
1075
1076/* FDC interrupt service routine.
1077 */
1078void fdc_isr(void)
1079{
1080 static int isr_active;
1081#ifdef TESTING
1082 unsigned int t0 = ftape_timestamp();
1083#endif
1084 TRACE_FUN(ft_t_any);
1085
1086 if (isr_active++) {
1087 --isr_active;
1088 TRACE(ft_t_bug, "BUG: nested interrupt, not good !");
1089 *fdc.hook = fdc_isr; /* hook our handler into the fdc
1090 * code again
1091 */
1092 TRACE_EXIT;
1093 }
1094 sti();
1095 if (inb_p(fdc.msr) & FDC_BUSY) { /* Entering Result Phase */
1096 ft_hide_interrupt = 0;
1097 handle_fdc_busy(ftape_get_buffer(ft_queue_head));
1098 if (ft_runner_status == do_abort) {
1099 /* cease operation, remember tape position
1100 */
1101 TRACE(ft_t_flow, "runner aborting");
1102 ft_runner_status = aborting;
1103 ++ft_expected_stray_interrupts;
1104 }
1105 } else { /* !FDC_BUSY */
1106 /* clear interrupt, cause should be gotten by issuing
1107 * a Sense Interrupt Status command.
1108 */
1109 if (fdc_mode == fdc_recalibrating || fdc_mode == fdc_seeking) {
1110 if (ft_hide_interrupt) {
1111 int st0;
1112 int pcn;
1113
1114 if (fdc_sense_interrupt_status(&st0, &pcn) < 0)
1115 TRACE(ft_t_err,
1116 "sense interrupt status failed");
1117 ftape_current_cylinder = pcn;
1118 TRACE(ft_t_flow, "handled hidden interrupt");
1119 }
1120 ft_seek_completed = 1;
1121 fdc_mode = fdc_idle;
1122 } else if (!waitqueue_active(&ftape_wait_intr)) {
1123 if (ft_expected_stray_interrupts == 0) {
1124 TRACE(ft_t_warn, "unexpected stray interrupt");
1125 } else {
1126 TRACE(ft_t_flow, "expected stray interrupt");
1127 --ft_expected_stray_interrupts;
1128 }
1129 } else {
1130 if (fdc_mode == fdc_reading_data ||
1131 fdc_mode == fdc_verifying ||
1132 fdc_mode == fdc_writing_data ||
1133 fdc_mode == fdc_deleting ||
1134 fdc_mode == fdc_formatting ||
1135 fdc_mode == fdc_reading_id) {
1136 if (inb_p(fdc.msr) & FDC_BUSY) {
1137 TRACE(ft_t_bug,
1138 "***** FDC failure, busy too late");
1139 } else {
1140 TRACE(ft_t_bug,
1141 "***** FDC failure, no busy");
1142 }
1143 } else {
1144 TRACE(ft_t_fdc_dma, "awaited stray interrupt");
1145 }
1146 }
1147 ft_hide_interrupt = 0;
1148 }
1149 /* Handle sleep code.
1150 */
1151 if (!ft_hide_interrupt) {
1152 ft_interrupt_seen ++;
1153 if (waitqueue_active(&ftape_wait_intr)) {
1154 wake_up_interruptible(&ftape_wait_intr);
1155 }
1156 } else {
1157 TRACE(ft_t_flow, "hiding interrupt while %s",
1158 waitqueue_active(&ftape_wait_intr) ? "waiting":"active");
1159 }
1160#ifdef TESTING
1161 t0 = ftape_timediff(t0, ftape_timestamp());
1162 if (t0 >= 1000) {
1163 /* only tell us about long calls */
1164 TRACE(ft_t_noise, "isr() duration: %5d usec", t0);
1165 }
1166#endif
1167 *fdc.hook = fdc_isr; /* hook our handler into the fdc code again */
1168 --isr_active;
1169 TRACE_EXIT;
1170}
diff --git a/drivers/char/ftape/lowlevel/fdc-isr.h b/drivers/char/ftape/lowlevel/fdc-isr.h
deleted file mode 100644
index 065aa978942d..000000000000
--- a/drivers/char/ftape/lowlevel/fdc-isr.h
+++ /dev/null
@@ -1,55 +0,0 @@
1#ifndef _FDC_ISR_H
2#define _FDC_ISR_H
3
4/*
5 * Copyright (C) 1993-1996 Bas Laarhoven,
6 * (C) 1996-1997 Claus-Justus Heine.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 *
23 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/fdc-isr.h,v $
24 * $Revision: 1.2 $
25 * $Date: 1997/10/05 19:18:07 $
26 *
27 * This file declares the global variables necessary to
28 * synchronize the interrupt service routine (isr) with the
29 * remainder of the QIC-40/80/3010/3020 floppy-tape driver
30 * "ftape" for Linux.
31 */
32
33/*
34 * fdc-isr.c defined public variables
35 */
36extern volatile int ft_expected_stray_interrupts; /* masks stray interrupts */
37extern volatile int ft_seek_completed; /* flag set by isr */
38extern volatile int ft_interrupt_seen; /* flag set by isr */
39extern volatile int ft_hide_interrupt; /* flag set by isr */
40
41/*
42 * fdc-io.c defined public functions
43 */
44extern void fdc_isr(void);
45
46/*
47 * A kernel hook that steals one interrupt from the floppy
48 * driver (Should be fixed when the new fdc driver gets ready)
49 * See the linux kernel source files:
50 * drivers/block/floppy.c & drivers/block/blk.h
51 * for the details.
52 */
53extern void (*do_floppy) (void);
54
55#endif
diff --git a/drivers/char/ftape/lowlevel/ftape-bsm.c b/drivers/char/ftape/lowlevel/ftape-bsm.c
deleted file mode 100644
index d1a301cc344f..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-bsm.c
+++ /dev/null
@@ -1,491 +0,0 @@
1/*
2 * Copyright (C) 1994-1996 Bas Laarhoven,
3 * (C) 1996-1997 Claus Heine.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 *
20 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-bsm.c,v $
21 * $Revision: 1.3 $
22 * $Date: 1997/10/05 19:15:15 $
23 *
24 * This file contains the bad-sector map handling code for
25 * the QIC-117 floppy tape driver for Linux.
26 * QIC-40, QIC-80, QIC-3010 and QIC-3020 maps are implemented.
27 */
28
29#include <linux/string.h>
30
31#include <linux/ftape.h>
32#include "../lowlevel/ftape-tracing.h"
33#include "../lowlevel/ftape-bsm.h"
34#include "../lowlevel/ftape-ctl.h"
35#include "../lowlevel/ftape-rw.h"
36
37/* Global vars.
38 */
39
40/* Local vars.
41 */
42static __u8 *bad_sector_map;
43static SectorCount *bsm_hash_ptr;
44
45typedef enum {
46 forward, backward
47} mode_type;
48
49#if 0
50static void ftape_put_bad_sector_entry(int segment_id, SectorMap new_map);
51#endif
52
53#if 0
54/* fix_tape converts a normal QIC-80 tape into a 'wide' tape.
55 * For testing purposes only !
56 */
57void fix_tape(__u8 * buffer, ft_format_type new_code)
58{
59 static __u8 list[BAD_SECTOR_MAP_SIZE];
60 SectorMap *src_ptr = (SectorMap *) list;
61 __u8 *dst_ptr = bad_sector_map;
62 SectorMap map;
63 unsigned int sector = 1;
64 int i;
65
66 if (format_code != fmt_var && format_code != fmt_big) {
67 memcpy(list, bad_sector_map, sizeof(list));
68 memset(bad_sector_map, 0, sizeof(bad_sector_map));
69 while ((__u8 *) src_ptr - list < sizeof(list)) {
70 map = *src_ptr++;
71 if (map == EMPTY_SEGMENT) {
72 *(SectorMap *) dst_ptr = 0x800000 + sector;
73 dst_ptr += 3;
74 sector += SECTORS_PER_SEGMENT;
75 } else {
76 for (i = 0; i < SECTORS_PER_SEGMENT; ++i) {
77 if (map & 1) {
78 *(SewctorMap *) dst_ptr = sector;
79 dst_ptr += 3;
80 }
81 map >>= 1;
82 ++sector;
83 }
84 }
85 }
86 }
87 bad_sector_map_changed = 1;
88 *(buffer + 4) = new_code; /* put new format code */
89 if (format_code != fmt_var && new_code == fmt_big) {
90 PUT4(buffer, FT_6_HSEG_1, (__u32)GET2(buffer, 6));
91 PUT4(buffer, FT_6_HSEG_2, (__u32)GET2(buffer, 8));
92 PUT4(buffer, FT_6_FRST_SEG, (__u32)GET2(buffer, 10));
93 PUT4(buffer, FT_6_LAST_SEG, (__u32)GET2(buffer, 12));
94 memset(buffer+6, '\0', 8);
95 }
96 format_code = new_code;
97}
98
99#endif
100
101/* given buffer that contains a header segment, find the end of
102 * of the bsm list
103 */
104__u8 * ftape_find_end_of_bsm_list(__u8 * address)
105{
106 __u8 *ptr = address + FT_HEADER_END; /* start of bsm list */
107 __u8 *limit = address + FT_SEGMENT_SIZE;
108 while (ptr + 2 < limit) {
109 if (ptr[0] || ptr[1] || ptr[2]) {
110 ptr += 3;
111 } else {
112 return ptr;
113 }
114 }
115 return NULL;
116}
117
118static inline void put_sector(SectorCount *ptr, unsigned int sector)
119{
120 ptr->bytes[0] = sector & 0xff;
121 sector >>= 8;
122 ptr->bytes[1] = sector & 0xff;
123 sector >>= 8;
124 ptr->bytes[2] = sector & 0xff;
125}
126
127static inline unsigned int get_sector(SectorCount *ptr)
128{
129#if 1
130 unsigned int sector;
131
132 sector = ptr->bytes[0];
133 sector += ptr->bytes[1] << 8;
134 sector += ptr->bytes[2] << 16;
135
136 return sector;
137#else
138 /* GET4 gets the next four bytes in Intel little endian order
139 * and converts them to host byte order and handles unaligned
140 * access.
141 */
142 return (GET4(ptr, 0) & 0x00ffffff); /* back to host byte order */
143#endif
144}
145
146static void bsm_debug_fake(void)
147{
148 /* for testing of bad sector handling at end of tape
149 */
150#if 0
151 ftape_put_bad_sector_entry(segments_per_track * tracks_per_tape - 3,
152 0x000003e0;
153 ftape_put_bad_sector_entry(segments_per_track * tracks_per_tape - 2,
154 0xff3fffff;
155 ftape_put_bad_sector_entry(segments_per_track * tracks_per_tape - 1,
156 0xffffe000;
157#endif
158 /* Enable to test bad sector handling
159 */
160#if 0
161 ftape_put_bad_sector_entry(30, 0xfffffffe)
162 ftape_put_bad_sector_entry(32, 0x7fffffff);
163 ftape_put_bad_sector_entry(34, 0xfffeffff);
164 ftape_put_bad_sector_entry(36, 0x55555555);
165 ftape_put_bad_sector_entry(38, 0xffffffff);
166 ftape_put_bad_sector_entry(50, 0xffff0000);
167 ftape_put_bad_sector_entry(51, 0xffffffff);
168 ftape_put_bad_sector_entry(52, 0xffffffff);
169 ftape_put_bad_sector_entry(53, 0x0000ffff);
170#endif
171 /* Enable when testing multiple volume tar dumps.
172 */
173#if 0
174 {
175 int i;
176
177 for (i = ft_first_data_segment;
178 i <= ft_last_data_segment - 7; ++i) {
179 ftape_put_bad_sector_entry(i, EMPTY_SEGMENT);
180 }
181 }
182#endif
183 /* Enable when testing bit positions in *_error_map
184 */
185#if 0
186 {
187 int i;
188
189 for (i = first_data_segment; i <= last_data_segment; ++i) {
190 ftape_put_bad_sector_entry(i,
191 ftape_get_bad_sector_entry(i)
192 | 0x00ff00ff);
193 }
194 }
195#endif
196}
197
198static void print_bad_sector_map(void)
199{
200 unsigned int good_sectors;
201 unsigned int total_bad = 0;
202 int i;
203 TRACE_FUN(ft_t_flow);
204
205 if (ft_format_code == fmt_big ||
206 ft_format_code == fmt_var ||
207 ft_format_code == fmt_1100ft) {
208 SectorCount *ptr = (SectorCount *)bad_sector_map;
209 unsigned int sector;
210 __u16 *ptr16;
211
212 while((sector = get_sector(ptr++)) != 0) {
213 if ((ft_format_code == fmt_big ||
214 ft_format_code == fmt_var) &&
215 sector & 0x800000) {
216 total_bad += FT_SECTORS_PER_SEGMENT - 3;
217 TRACE(ft_t_noise, "bad segment at sector: %6d",
218 sector & 0x7fffff);
219 } else {
220 ++total_bad;
221 TRACE(ft_t_noise, "bad sector: %6d", sector);
222 }
223 }
224 /* Display old ftape's end-of-file marks
225 */
226 ptr16 = (__u16*)ptr;
227 while ((sector = get_unaligned(ptr16++)) != 0) {
228 TRACE(ft_t_noise, "Old ftape eof mark: %4d/%2d",
229 sector, get_unaligned(ptr16++));
230 }
231 } else { /* fixed size format */
232 for (i = ft_first_data_segment;
233 i < (int)(ft_segments_per_track * ft_tracks_per_tape); ++i) {
234 SectorMap map = ((SectorMap *) bad_sector_map)[i];
235
236 if (map) {
237 TRACE(ft_t_noise,
238 "bsm for segment %4d: 0x%08x", i, (unsigned int)map);
239 total_bad += ((map == EMPTY_SEGMENT)
240 ? FT_SECTORS_PER_SEGMENT - 3
241 : count_ones(map));
242 }
243 }
244 }
245 good_sectors =
246 ((ft_segments_per_track * ft_tracks_per_tape - ft_first_data_segment)
247 * (FT_SECTORS_PER_SEGMENT - 3)) - total_bad;
248 TRACE(ft_t_info, "%d Kb usable on this tape", good_sectors);
249 if (total_bad == 0) {
250 TRACE(ft_t_info,
251 "WARNING: this tape has no bad blocks registered !");
252 } else {
253 TRACE(ft_t_info, "%d bad sectors", total_bad);
254 }
255 TRACE_EXIT;
256}
257
258
259void ftape_extract_bad_sector_map(__u8 * buffer)
260{
261 TRACE_FUN(ft_t_any);
262
263 /* Fill the bad sector map with the contents of buffer.
264 */
265 if (ft_format_code == fmt_var || ft_format_code == fmt_big) {
266 /* QIC-3010/3020 and wide QIC-80 tapes no longer have a failed
267 * sector log but use this area to extend the bad sector map.
268 */
269 bad_sector_map = &buffer[FT_HEADER_END];
270 } else {
271 /* non-wide QIC-80 tapes have a failed sector log area that
272 * mustn't be included in the bad sector map.
273 */
274 bad_sector_map = &buffer[FT_FSL + FT_FSL_SIZE];
275 }
276 if (ft_format_code == fmt_1100ft ||
277 ft_format_code == fmt_var ||
278 ft_format_code == fmt_big) {
279 bsm_hash_ptr = (SectorCount *)bad_sector_map;
280 } else {
281 bsm_hash_ptr = NULL;
282 }
283 bsm_debug_fake();
284 if (TRACE_LEVEL >= ft_t_info) {
285 print_bad_sector_map();
286 }
287 TRACE_EXIT;
288}
289
290static inline SectorMap cvt2map(unsigned int sector)
291{
292 return 1 << (((sector & 0x7fffff) - 1) % FT_SECTORS_PER_SEGMENT);
293}
294
295static inline int cvt2segment(unsigned int sector)
296{
297 return ((sector & 0x7fffff) - 1) / FT_SECTORS_PER_SEGMENT;
298}
299
300static int forward_seek_entry(int segment_id,
301 SectorCount **ptr,
302 SectorMap *map)
303{
304 unsigned int sector;
305 int segment;
306
307 do {
308 sector = get_sector((*ptr)++);
309 segment = cvt2segment(sector);
310 } while (sector != 0 && segment < segment_id);
311 (*ptr) --; /* point to first sector >= segment_id */
312 /* Get all sectors in segment_id
313 */
314 if (sector == 0 || segment != segment_id) {
315 *map = 0;
316 return 0;
317 } else if ((sector & 0x800000) &&
318 (ft_format_code == fmt_var || ft_format_code == fmt_big)) {
319 *map = EMPTY_SEGMENT;
320 return FT_SECTORS_PER_SEGMENT;
321 } else {
322 int count = 1;
323 SectorCount *tmp_ptr = (*ptr) + 1;
324
325 *map = cvt2map(sector);
326 while ((sector = get_sector(tmp_ptr++)) != 0 &&
327 (segment = cvt2segment(sector)) == segment_id) {
328 *map |= cvt2map(sector);
329 ++count;
330 }
331 return count;
332 }
333}
334
335static int backwards_seek_entry(int segment_id,
336 SectorCount **ptr,
337 SectorMap *map)
338{
339 unsigned int sector;
340 int segment; /* max unsigned int */
341
342 if (*ptr <= (SectorCount *)bad_sector_map) {
343 *map = 0;
344 return 0;
345 }
346 do {
347 sector = get_sector(--(*ptr));
348 segment = cvt2segment(sector);
349 } while (*ptr > (SectorCount *)bad_sector_map && segment > segment_id);
350 if (segment > segment_id) { /* at start of list, no entry found */
351 *map = 0;
352 return 0;
353 } else if (segment < segment_id) {
354 /* before smaller entry, adjust for overshoot */
355 (*ptr) ++;
356 *map = 0;
357 return 0;
358 } else if ((sector & 0x800000) &&
359 (ft_format_code == fmt_big || ft_format_code == fmt_var)) {
360 *map = EMPTY_SEGMENT;
361 return FT_SECTORS_PER_SEGMENT;
362 } else { /* get all sectors in segment_id */
363 int count = 1;
364
365 *map = cvt2map(sector);
366 while(*ptr > (SectorCount *)bad_sector_map) {
367 sector = get_sector(--(*ptr));
368 segment = cvt2segment(sector);
369 if (segment != segment_id) {
370 break;
371 }
372 *map |= cvt2map(sector);
373 ++count;
374 }
375 if (segment < segment_id) {
376 (*ptr) ++;
377 }
378 return count;
379 }
380}
381
382#if 0
383static void ftape_put_bad_sector_entry(int segment_id, SectorMap new_map)
384{
385 SectorCount *ptr = (SectorCount *)bad_sector_map;
386 int count;
387 int new_count;
388 SectorMap map;
389 TRACE_FUN(ft_t_any);
390
391 if (ft_format_code == fmt_1100ft ||
392 ft_format_code == fmt_var ||
393 ft_format_code == fmt_big) {
394 count = forward_seek_entry(segment_id, &ptr, &map);
395 new_count = count_ones(new_map);
396 /* If format code == 4 put empty segment instead of 32
397 * bad sectors.
398 */
399 if (ft_format_code == fmt_var || ft_format_code == fmt_big) {
400 if (new_count == FT_SECTORS_PER_SEGMENT) {
401 new_count = 1;
402 }
403 if (count == FT_SECTORS_PER_SEGMENT) {
404 count = 1;
405 }
406 }
407 if (count != new_count) {
408 /* insert (or delete if < 0) new_count - count
409 * entries. Move trailing part of list
410 * including terminating 0.
411 */
412 SectorCount *hi_ptr = ptr;
413
414 do {
415 } while (get_sector(hi_ptr++) != 0);
416 /* Note: ptr is of type byte *, and each bad sector
417 * consumes 3 bytes.
418 */
419 memmove(ptr + new_count, ptr + count,
420 (size_t)(hi_ptr - (ptr + count))*sizeof(SectorCount));
421 }
422 TRACE(ft_t_noise, "putting map 0x%08x at %p, segment %d",
423 (unsigned int)new_map, ptr, segment_id);
424 if (new_count == 1 && new_map == EMPTY_SEGMENT) {
425 put_sector(ptr++, (0x800001 +
426 segment_id *
427 FT_SECTORS_PER_SEGMENT));
428 } else {
429 int i = 0;
430
431 while (new_map) {
432 if (new_map & 1) {
433 put_sector(ptr++,
434 1 + segment_id *
435 FT_SECTORS_PER_SEGMENT + i);
436 }
437 ++i;
438 new_map >>= 1;
439 }
440 }
441 } else {
442 ((SectorMap *) bad_sector_map)[segment_id] = new_map;
443 }
444 TRACE_EXIT;
445}
446#endif /* 0 */
447
448SectorMap ftape_get_bad_sector_entry(int segment_id)
449{
450 if (ft_used_header_segment == -1) {
451 /* When reading header segment we'll need a blank map.
452 */
453 return 0;
454 } else if (bsm_hash_ptr != NULL) {
455 /* Invariants:
456 * map - mask value returned on last call.
457 * bsm_hash_ptr - points to first sector greater or equal to
458 * first sector in last_referenced segment.
459 * last_referenced - segment id used in the last call,
460 * sector and map belong to this id.
461 * This code is designed for sequential access and retries.
462 * For true random access it may have to be redesigned.
463 */
464 static int last_reference = -1;
465 static SectorMap map;
466
467 if (segment_id > last_reference) {
468 /* Skip all sectors before segment_id
469 */
470 forward_seek_entry(segment_id, &bsm_hash_ptr, &map);
471 } else if (segment_id < last_reference) {
472 /* Skip backwards until begin of buffer or
473 * first sector in segment_id
474 */
475 backwards_seek_entry(segment_id, &bsm_hash_ptr, &map);
476 } /* segment_id == last_reference : keep map */
477 last_reference = segment_id;
478 return map;
479 } else {
480 return ((SectorMap *) bad_sector_map)[segment_id];
481 }
482}
483
484/* This is simply here to prevent us from overwriting other kernel
485 * data. Writes will result in NULL Pointer dereference.
486 */
487void ftape_init_bsm(void)
488{
489 bad_sector_map = NULL;
490 bsm_hash_ptr = NULL;
491}
diff --git a/drivers/char/ftape/lowlevel/ftape-bsm.h b/drivers/char/ftape/lowlevel/ftape-bsm.h
deleted file mode 100644
index ed45465af4d4..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-bsm.h
+++ /dev/null
@@ -1,66 +0,0 @@
1#ifndef _FTAPE_BSM_H
2#define _FTAPE_BSM_H
3
4/*
5 * Copyright (C) 1994-1996 Bas Laarhoven,
6 * (C) 1996-1997 Claus-Justus Heine.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 *
23 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-bsm.h,v $
24 * $Revision: 1.2 $
25 * $Date: 1997/10/05 19:18:07 $
26 *
27 * This file contains definitions for the bad sector map handling
28 * routines for the QIC-117 floppy-tape driver for Linux.
29 */
30
31#include <linux/ftape.h>
32#include <linux/ftape-header-segment.h>
33
34#define EMPTY_SEGMENT (0xffffffff)
35#define FAKE_SEGMENT (0xfffffffe)
36
37/* maximum (format code 4) bad sector map size (bytes).
38 */
39#define BAD_SECTOR_MAP_SIZE (29 * SECTOR_SIZE - 256)
40
41/* format code 4 bad sector entry, ftape uses this
42 * internally for all format codes
43 */
44typedef __u32 SectorMap;
45/* variable and 1100 ft bad sector map entry. These three bytes represent
46 * a single sector address measured from BOT.
47 */
48typedef struct NewSectorMap {
49 __u8 bytes[3];
50} SectorCount;
51
52
53/*
54 * ftape-bsm.c defined global vars.
55 */
56
57/*
58 * ftape-bsm.c defined global functions.
59 */
60extern void update_bad_sector_map(__u8 * buffer);
61extern void ftape_extract_bad_sector_map(__u8 * buffer);
62extern SectorMap ftape_get_bad_sector_entry(int segment_id);
63extern __u8 *ftape_find_end_of_bsm_list(__u8 * address);
64extern void ftape_init_bsm(void);
65
66#endif
diff --git a/drivers/char/ftape/lowlevel/ftape-buffer.c b/drivers/char/ftape/lowlevel/ftape-buffer.c
deleted file mode 100644
index c706ff162771..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-buffer.c
+++ /dev/null
@@ -1,130 +0,0 @@
1/*
2 * Copyright (C) 1997 Claus-Justus Heine
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 *
19 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-buffer.c,v $
20 * $Revision: 1.3 $
21 * $Date: 1997/10/16 23:33:11 $
22 *
23 * This file contains the allocator/dealloctor for ftape's dynamic dma
24 * buffer.
25 */
26
27#include <linux/slab.h>
28#include <linux/mm.h>
29#include <linux/mman.h>
30#include <asm/dma.h>
31
32#include <linux/ftape.h>
33#include "../lowlevel/ftape-rw.h"
34#include "../lowlevel/ftape-read.h"
35#include "../lowlevel/ftape-tracing.h"
36#include "../lowlevel/ftape-buffer.h"
37
38/* DMA'able memory allocation stuff.
39 */
40
41static inline void *dmaalloc(size_t size)
42{
43 unsigned long addr;
44
45 if (size == 0) {
46 return NULL;
47 }
48 addr = __get_dma_pages(GFP_KERNEL, get_order(size));
49 if (addr) {
50 struct page *page;
51
52 for (page = virt_to_page(addr); page < virt_to_page(addr+size); page++)
53 SetPageReserved(page);
54 }
55 return (void *)addr;
56}
57
58static inline void dmafree(void *addr, size_t size)
59{
60 if (size > 0) {
61 struct page *page;
62
63 for (page = virt_to_page((unsigned long)addr);
64 page < virt_to_page((unsigned long)addr+size); page++)
65 ClearPageReserved(page);
66 free_pages((unsigned long) addr, get_order(size));
67 }
68}
69
70static int add_one_buffer(void)
71{
72 TRACE_FUN(ft_t_flow);
73
74 if (ft_nr_buffers >= FT_MAX_NR_BUFFERS) {
75 TRACE_EXIT -ENOMEM;
76 }
77 ft_buffer[ft_nr_buffers] = kmalloc(sizeof(buffer_struct), GFP_KERNEL);
78 if (ft_buffer[ft_nr_buffers] == NULL) {
79 TRACE_EXIT -ENOMEM;
80 }
81 memset(ft_buffer[ft_nr_buffers], 0, sizeof(buffer_struct));
82 ft_buffer[ft_nr_buffers]->address = dmaalloc(FT_BUFF_SIZE);
83 if (ft_buffer[ft_nr_buffers]->address == NULL) {
84 kfree(ft_buffer[ft_nr_buffers]);
85 ft_buffer[ft_nr_buffers] = NULL;
86 TRACE_EXIT -ENOMEM;
87 }
88 ft_nr_buffers ++;
89 TRACE(ft_t_info, "buffer nr #%d @ %p, dma area @ %p",
90 ft_nr_buffers,
91 ft_buffer[ft_nr_buffers-1],
92 ft_buffer[ft_nr_buffers-1]->address);
93 TRACE_EXIT 0;
94}
95
96static void del_one_buffer(void)
97{
98 TRACE_FUN(ft_t_flow);
99 if (ft_nr_buffers > 0) {
100 TRACE(ft_t_info, "releasing buffer nr #%d @ %p, dma area @ %p",
101 ft_nr_buffers,
102 ft_buffer[ft_nr_buffers-1],
103 ft_buffer[ft_nr_buffers-1]->address);
104 ft_nr_buffers --;
105 dmafree(ft_buffer[ft_nr_buffers]->address, FT_BUFF_SIZE);
106 kfree(ft_buffer[ft_nr_buffers]);
107 ft_buffer[ft_nr_buffers] = NULL;
108 }
109 TRACE_EXIT;
110}
111
112int ftape_set_nr_buffers(int cnt)
113{
114 int delta = cnt - ft_nr_buffers;
115 TRACE_FUN(ft_t_flow);
116
117 if (delta > 0) {
118 while (delta--) {
119 if (add_one_buffer() < 0) {
120 TRACE_EXIT -ENOMEM;
121 }
122 }
123 } else if (delta < 0) {
124 while (delta++) {
125 del_one_buffer();
126 }
127 }
128 ftape_zap_read_buffers();
129 TRACE_EXIT 0;
130}
diff --git a/drivers/char/ftape/lowlevel/ftape-buffer.h b/drivers/char/ftape/lowlevel/ftape-buffer.h
deleted file mode 100644
index eec99cee8f82..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-buffer.h
+++ /dev/null
@@ -1,32 +0,0 @@
1#ifndef _FTAPE_BUFFER_H
2#define _FTAPE_BUFFER_H
3
4/*
5 * Copyright (C) 1997 Claus-Justus Heine.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 *
22 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-buffer.h,v $
23 * $Revision: 1.2 $
24 * $Date: 1997/10/05 19:18:08 $
25 *
26 * This file contains the allocator/dealloctor for ftape's dynamic dma
27 * buffer.
28 */
29
30extern int ftape_set_nr_buffers(int cnt);
31
32#endif
diff --git a/drivers/char/ftape/lowlevel/ftape-calibr.c b/drivers/char/ftape/lowlevel/ftape-calibr.c
deleted file mode 100644
index 8e50bfd35a52..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-calibr.c
+++ /dev/null
@@ -1,275 +0,0 @@
1/*
2 * Copyright (C) 1993-1996 Bas Laarhoven.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 *
19 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-calibr.c,v $
20 * $Revision: 1.2 $
21 * $Date: 1997/10/05 19:18:08 $
22 *
23 * GP calibration routine for processor speed dependent
24 * functions.
25 */
26
27#include <linux/errno.h>
28#include <linux/jiffies.h>
29#include <asm/system.h>
30#include <asm/io.h>
31#if defined(__alpha__)
32# include <asm/hwrpb.h>
33#elif defined(__x86_64__)
34# include <asm/msr.h>
35# include <asm/timex.h>
36#elif defined(__i386__)
37# include <linux/timex.h>
38#endif
39#include <linux/ftape.h>
40#include "../lowlevel/ftape-tracing.h"
41#include "../lowlevel/ftape-calibr.h"
42#include "../lowlevel/fdc-io.h"
43
44#undef DEBUG
45
46#if !defined(__alpha__) && !defined(__i386__) && !defined(__x86_64__)
47# error Ftape is not implemented for this architecture!
48#endif
49
50#if defined(__alpha__) || defined(__x86_64__)
51static unsigned long ps_per_cycle = 0;
52#endif
53
54static spinlock_t calibr_lock;
55
56/*
57 * Note: On Intel PCs, the clock ticks at 100 Hz (HZ==100) which is
58 * too slow for certain timeouts (and that clock doesn't even tick
59 * when interrupts are disabled). For that reason, the 8254 timer is
60 * used directly to implement fine-grained timeouts. However, on
61 * Alpha PCs, the 8254 is *not* used to implement the clock tick
62 * (which is 1024 Hz, normally) and the 8254 timer runs at some
63 * "random" frequency (it seems to run at 18Hz, but it's not safe to
64 * rely on this value). Instead, we use the Alpha's "rpcc"
65 * instruction to read cycle counts. As this is a 32 bit counter,
66 * it will overflow only once per 30 seconds (on a 200MHz machine),
67 * which is plenty.
68 */
69
70unsigned int ftape_timestamp(void)
71{
72#if defined(__alpha__)
73 unsigned long r;
74
75 asm volatile ("rpcc %0" : "=r" (r));
76 return r;
77#elif defined(__x86_64__)
78 unsigned long r;
79 rdtscl(r);
80 return r;
81#elif defined(__i386__)
82
83/*
84 * Note that there is some time between counter underflowing and jiffies
85 * increasing, so the code below won't always give correct output.
86 * -Vojtech
87 */
88
89 unsigned long flags;
90 __u16 lo;
91 __u16 hi;
92
93 spin_lock_irqsave(&calibr_lock, flags);
94 outb_p(0x00, 0x43); /* latch the count ASAP */
95 lo = inb_p(0x40); /* read the latched count */
96 lo |= inb(0x40) << 8;
97 hi = jiffies;
98 spin_unlock_irqrestore(&calibr_lock, flags);
99 return ((hi + 1) * (unsigned int) LATCH) - lo; /* downcounter ! */
100#endif
101}
102
103static unsigned int short_ftape_timestamp(void)
104{
105#if defined(__alpha__) || defined(__x86_64__)
106 return ftape_timestamp();
107#elif defined(__i386__)
108 unsigned int count;
109 unsigned long flags;
110
111 spin_lock_irqsave(&calibr_lock, flags);
112 outb_p(0x00, 0x43); /* latch the count ASAP */
113 count = inb_p(0x40); /* read the latched count */
114 count |= inb(0x40) << 8;
115 spin_unlock_irqrestore(&calibr_lock, flags);
116 return (LATCH - count); /* normal: downcounter */
117#endif
118}
119
120static unsigned int diff(unsigned int t0, unsigned int t1)
121{
122#if defined(__alpha__) || defined(__x86_64__)
123 return (t1 - t0);
124#elif defined(__i386__)
125 /*
126 * This is tricky: to work for both short and full ftape_timestamps
127 * we'll have to discriminate between these.
128 * If it _looks_ like short stamps with wrapping around we'll
129 * asume it are. This will generate a small error if it really
130 * was a (very large) delta from full ftape_timestamps.
131 */
132 return (t1 <= t0 && t0 <= LATCH) ? t1 + LATCH - t0 : t1 - t0;
133#endif
134}
135
136static unsigned int usecs(unsigned int count)
137{
138#if defined(__alpha__) || defined(__x86_64__)
139 return (ps_per_cycle * count) / 1000000UL;
140#elif defined(__i386__)
141 return (10000 * count) / ((CLOCK_TICK_RATE + 50) / 100);
142#endif
143}
144
145unsigned int ftape_timediff(unsigned int t0, unsigned int t1)
146{
147 /*
148 * Calculate difference in usec for ftape_timestamp results t0 & t1.
149 * Note that on the i386 platform with short time-stamps, the
150 * maximum allowed timespan is 1/HZ or we'll lose ticks!
151 */
152 return usecs(diff(t0, t1));
153}
154
155/* To get an indication of the I/O performance,
156 * measure the duration of the inb() function.
157 */
158static void time_inb(void)
159{
160 int i;
161 int t0, t1;
162 unsigned long flags;
163 int status;
164 TRACE_FUN(ft_t_any);
165
166 spin_lock_irqsave(&calibr_lock, flags);
167 t0 = short_ftape_timestamp();
168 for (i = 0; i < 1000; ++i) {
169 status = inb(fdc.msr);
170 }
171 t1 = short_ftape_timestamp();
172 spin_unlock_irqrestore(&calibr_lock, flags);
173 TRACE(ft_t_info, "inb() duration: %d nsec", ftape_timediff(t0, t1));
174 TRACE_EXIT;
175}
176
177static void init_clock(void)
178{
179 TRACE_FUN(ft_t_any);
180
181#if defined(__x86_64__)
182 ps_per_cycle = 1000000000UL / cpu_khz;
183#elif defined(__alpha__)
184 extern struct hwrpb_struct *hwrpb;
185 ps_per_cycle = (1000*1000*1000*1000UL) / hwrpb->cycle_freq;
186#endif
187 TRACE_EXIT;
188}
189
190/*
191 * Input: function taking int count as parameter.
192 * pointers to calculated calibration variables.
193 */
194void ftape_calibrate(char *name,
195 void (*fun) (unsigned int),
196 unsigned int *calibr_count,
197 unsigned int *calibr_time)
198{
199 static int first_time = 1;
200 int i;
201 unsigned int tc = 0;
202 unsigned int count;
203 unsigned int time;
204#if defined(__i386__)
205 unsigned int old_tc = 0;
206 unsigned int old_count = 1;
207 unsigned int old_time = 1;
208#endif
209 TRACE_FUN(ft_t_flow);
210
211 if (first_time) { /* get idea of I/O performance */
212 init_clock();
213 time_inb();
214 first_time = 0;
215 }
216 /* value of timeout must be set so that on very slow systems
217 * it will give a time less than one jiffy, and on
218 * very fast systems it'll give reasonable precision.
219 */
220
221 count = 40;
222 for (i = 0; i < 15; ++i) {
223 unsigned int t0;
224 unsigned int t1;
225 unsigned int once;
226 unsigned int multiple;
227 unsigned long flags;
228
229 *calibr_count =
230 *calibr_time = count; /* set TC to 1 */
231 spin_lock_irqsave(&calibr_lock, flags);
232 fun(0); /* dummy, get code into cache */
233 t0 = short_ftape_timestamp();
234 fun(0); /* overhead + one test */
235 t1 = short_ftape_timestamp();
236 once = diff(t0, t1);
237 t0 = short_ftape_timestamp();
238 fun(count); /* overhead + count tests */
239 t1 = short_ftape_timestamp();
240 multiple = diff(t0, t1);
241 spin_unlock_irqrestore(&calibr_lock, flags);
242 time = ftape_timediff(0, multiple - once);
243 tc = (1000 * time) / (count - 1);
244 TRACE(ft_t_any, "once:%3d us,%6d times:%6d us, TC:%5d ns",
245 usecs(once), count - 1, usecs(multiple), tc);
246#if defined(__alpha__) || defined(__x86_64__)
247 /*
248 * Increase the calibration count exponentially until the
249 * calibration time exceeds 100 ms.
250 */
251 if (time >= 100*1000) {
252 break;
253 }
254#elif defined(__i386__)
255 /*
256 * increase the count until the resulting time nears 2/HZ,
257 * then the tc will drop sharply because we lose LATCH counts.
258 */
259 if (tc <= old_tc / 2) {
260 time = old_time;
261 count = old_count;
262 break;
263 }
264 old_tc = tc;
265 old_count = count;
266 old_time = time;
267#endif
268 count *= 2;
269 }
270 *calibr_count = count - 1;
271 *calibr_time = time;
272 TRACE(ft_t_info, "TC for `%s()' = %d nsec (at %d counts)",
273 name, (1000 * *calibr_time) / *calibr_count, *calibr_count);
274 TRACE_EXIT;
275}
diff --git a/drivers/char/ftape/lowlevel/ftape-calibr.h b/drivers/char/ftape/lowlevel/ftape-calibr.h
deleted file mode 100644
index 0c7e75246c7d..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-calibr.h
+++ /dev/null
@@ -1,37 +0,0 @@
1#ifndef _FTAPE_CALIBR_H
2#define _FTAPE_CALIBR_H
3
4/*
5 * Copyright (C) 1993-1996 Bas Laarhoven.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 *
22 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-calibr.h,v $
23 * $Revision: 1.1 $
24 * $Date: 1997/09/19 09:05:26 $
25 *
26 * This file contains a gp calibration routine for
27 * hardware dependent timeout functions.
28 */
29
30extern void ftape_calibrate(char *name,
31 void (*fun) (unsigned int),
32 unsigned int *calibr_count,
33 unsigned int *calibr_time);
34extern unsigned int ftape_timestamp(void);
35extern unsigned int ftape_timediff(unsigned int t0, unsigned int t1);
36
37#endif /* _FTAPE_CALIBR_H */
diff --git a/drivers/char/ftape/lowlevel/ftape-ctl.c b/drivers/char/ftape/lowlevel/ftape-ctl.c
deleted file mode 100644
index 5d7c1ce92d59..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-ctl.c
+++ /dev/null
@@ -1,896 +0,0 @@
1/*
2 * Copyright (C) 1993-1996 Bas Laarhoven,
3 * 1996-1997 Claus-Justus Heine.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 *
20 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-ctl.c,v $
21 * $Revision: 1.4 $
22 * $Date: 1997/11/11 14:37:44 $
23 *
24 * This file contains the non-read/write ftape functions for the
25 * QIC-40/80/3010/3020 floppy-tape driver "ftape" for Linux.
26 */
27
28#include <linux/errno.h>
29#include <linux/mm.h>
30#include <linux/mman.h>
31
32#include <linux/ftape.h>
33#include <linux/qic117.h>
34#include <asm/uaccess.h>
35#include <asm/io.h>
36
37/* ease porting between pre-2.4.x and later kernels */
38#define vma_get_pgoff(v) ((v)->vm_pgoff)
39
40#include "../lowlevel/ftape-tracing.h"
41#include "../lowlevel/ftape-io.h"
42#include "../lowlevel/ftape-ctl.h"
43#include "../lowlevel/ftape-write.h"
44#include "../lowlevel/ftape-read.h"
45#include "../lowlevel/ftape-rw.h"
46#include "../lowlevel/ftape-bsm.h"
47
48/* Global vars.
49 */
50ftape_info ftape_status = {
51/* vendor information */
52 { 0, }, /* drive type */
53/* data rates */
54 500, /* used data rate */
55 500, /* drive max rate */
56 500, /* fdc max rate */
57/* drive selection, either FTAPE_SEL_A/B/C/D */
58 -1, /* drive selection */
59/* flags set after decode the drive and tape status */
60 0, /* formatted */
61 1, /* no tape */
62 1, /* write protected */
63 1, /* new tape */
64/* values of last queried drive/tape status and error */
65 {{0,}}, /* last error code */
66 {{0,}}, /* drive status, configuration, tape status */
67/* cartridge geometry */
68 20, /* tracks_per_tape */
69 102, /* segments_per_track */
70/* location of header segments, etc. */
71 -1, /* used_header_segment */
72 -1, /* header_segment_1 */
73 -1, /* header_segment_2 */
74 -1, /* first_data_segment */
75 -1, /* last_data_segment */
76/* the format code as stored in the header segment */
77 fmt_normal, /* format code */
78/* the default for the qic std: unknown */
79 -1,
80/* is tape running? */
81 idle, /* runner_state */
82/* is tape reading/writing/verifying/formatting/deleting */
83 idle, /* driver state */
84/* flags fatal hardware error */
85 1, /* failure */
86/* history record */
87 { 0, } /* history record */
88};
89
90int ftape_segments_per_head = 1020;
91int ftape_segments_per_cylinder = 4;
92int ftape_init_drive_needed = 1; /* need to be global for ftape_reset_drive()
93 * in ftape-io.c
94 */
95
96/* Local vars.
97 */
98static const vendor_struct vendors[] = QIC117_VENDORS;
99static const wakeup_method methods[] = WAKEUP_METHODS;
100
101const ftape_info *ftape_get_status(void)
102{
103#if defined(STATUS_PARANOYA)
104 static ftape_info get_status;
105
106 get_status = ftape_status;
107 return &get_status;
108#else
109 return &ftape_status; /* maybe return only a copy of it to assure
110 * read only access
111 */
112#endif
113}
114
115static int ftape_not_operational(int status)
116{
117 /* return true if status indicates tape can not be used.
118 */
119 return ((status ^ QIC_STATUS_CARTRIDGE_PRESENT) &
120 (QIC_STATUS_ERROR |
121 QIC_STATUS_CARTRIDGE_PRESENT |
122 QIC_STATUS_NEW_CARTRIDGE));
123}
124
125int ftape_seek_to_eot(void)
126{
127 int status;
128 TRACE_FUN(ft_t_any);
129
130 TRACE_CATCH(ftape_ready_wait(ftape_timeout.pause, &status),);
131 while ((status & QIC_STATUS_AT_EOT) == 0) {
132 if (ftape_not_operational(status)) {
133 TRACE_EXIT -EIO;
134 }
135 TRACE_CATCH(ftape_command_wait(QIC_PHYSICAL_FORWARD,
136 ftape_timeout.rewind,&status),);
137 }
138 TRACE_EXIT 0;
139}
140
141int ftape_seek_to_bot(void)
142{
143 int status;
144 TRACE_FUN(ft_t_any);
145
146 TRACE_CATCH(ftape_ready_wait(ftape_timeout.pause, &status),);
147 while ((status & QIC_STATUS_AT_BOT) == 0) {
148 if (ftape_not_operational(status)) {
149 TRACE_EXIT -EIO;
150 }
151 TRACE_CATCH(ftape_command_wait(QIC_PHYSICAL_REVERSE,
152 ftape_timeout.rewind,&status),);
153 }
154 TRACE_EXIT 0;
155}
156
157static int ftape_new_cartridge(void)
158{
159 ft_location.track = -1; /* force seek on first access */
160 ftape_zap_read_buffers();
161 ftape_zap_write_buffers();
162 return 0;
163}
164
165int ftape_abort_operation(void)
166{
167 int result = 0;
168 int status;
169 TRACE_FUN(ft_t_flow);
170
171 if (ft_runner_status == running) {
172 TRACE(ft_t_noise, "aborting runner, waiting");
173
174 ft_runner_status = do_abort;
175 /* set timeout so that the tape will run to logical EOT
176 * if we missed the last sector and there are no queue pulses.
177 */
178 result = ftape_dumb_stop();
179 }
180 if (ft_runner_status != idle) {
181 if (ft_runner_status == do_abort) {
182 TRACE(ft_t_noise, "forcing runner abort");
183 }
184 TRACE(ft_t_noise, "stopping tape");
185 result = ftape_stop_tape(&status);
186 ft_location.known = 0;
187 ft_runner_status = idle;
188 }
189 ftape_reset_buffer();
190 ftape_zap_read_buffers();
191 ftape_set_state(idle);
192 TRACE_EXIT result;
193}
194
195static int lookup_vendor_id(unsigned int vendor_id)
196{
197 int i = 0;
198
199 while (vendors[i].vendor_id != vendor_id) {
200 if (++i >= NR_ITEMS(vendors)) {
201 return -1;
202 }
203 }
204 return i;
205}
206
207static void ftape_detach_drive(void)
208{
209 TRACE_FUN(ft_t_any);
210
211 TRACE(ft_t_flow, "disabling tape drive and fdc");
212 ftape_put_drive_to_sleep(ft_drive_type.wake_up);
213 fdc_catch_stray_interrupts(1); /* one always comes */
214 fdc_disable();
215 fdc_release_irq_and_dma();
216 fdc_release_regions();
217 TRACE_EXIT;
218}
219
220static void clear_history(void)
221{
222 ft_history.used = 0;
223 ft_history.id_am_errors =
224 ft_history.id_crc_errors =
225 ft_history.data_am_errors =
226 ft_history.data_crc_errors =
227 ft_history.overrun_errors =
228 ft_history.no_data_errors =
229 ft_history.retries =
230 ft_history.crc_errors =
231 ft_history.crc_failures =
232 ft_history.ecc_failures =
233 ft_history.corrected =
234 ft_history.defects =
235 ft_history.rewinds = 0;
236}
237
238static int ftape_activate_drive(vendor_struct * drive_type)
239{
240 int result = 0;
241 TRACE_FUN(ft_t_flow);
242
243 /* If we already know the drive type, wake it up.
244 * Else try to find out what kind of drive is attached.
245 */
246 if (drive_type->wake_up != unknown_wake_up) {
247 TRACE(ft_t_flow, "enabling tape drive and fdc");
248 result = ftape_wakeup_drive(drive_type->wake_up);
249 if (result < 0) {
250 TRACE(ft_t_err, "known wakeup method failed");
251 }
252 } else {
253 wake_up_types method;
254 const ft_trace_t old_tracing = TRACE_LEVEL;
255 if (TRACE_LEVEL < ft_t_flow) {
256 SET_TRACE_LEVEL(ft_t_bug);
257 }
258
259 /* Try to awaken the drive using all known methods.
260 * Lower tracing for a while.
261 */
262 for (method=no_wake_up; method < NR_ITEMS(methods); ++method) {
263 drive_type->wake_up = method;
264#ifdef CONFIG_FT_TWO_DRIVES
265 /* Test setup for dual drive configuration.
266 * /dev/rft2 uses mountain wakeup
267 * /dev/rft3 uses colorado wakeup
268 * Other systems will use the normal scheme.
269 */
270 if ((ft_drive_sel < 2) ||
271 (ft_drive_sel == 2 && method == FT_WAKE_UP_1) ||
272 (ft_drive_sel == 3 && method == FT_WAKE_UP_2)) {
273 result=ftape_wakeup_drive(drive_type->wake_up);
274 } else {
275 result = -EIO;
276 }
277#else
278 result = ftape_wakeup_drive(drive_type->wake_up);
279#endif
280 if (result >= 0) {
281 TRACE(ft_t_warn, "drive wakeup method: %s",
282 methods[drive_type->wake_up].name);
283 break;
284 }
285 }
286 SET_TRACE_LEVEL(old_tracing);
287
288 if (method >= NR_ITEMS(methods)) {
289 /* no response at all, cannot open this drive */
290 drive_type->wake_up = unknown_wake_up;
291 TRACE(ft_t_err, "no tape drive found !");
292 result = -ENODEV;
293 }
294 }
295 TRACE_EXIT result;
296}
297
298static int ftape_get_drive_status(void)
299{
300 int result;
301 int status;
302 TRACE_FUN(ft_t_flow);
303
304 ft_no_tape = ft_write_protected = 0;
305 /* Tape drive is activated now.
306 * First clear error status if present.
307 */
308 do {
309 result = ftape_ready_wait(ftape_timeout.reset, &status);
310 if (result < 0) {
311 if (result == -ETIME) {
312 TRACE(ft_t_err, "ftape_ready_wait timeout");
313 } else if (result == -EINTR) {
314 TRACE(ft_t_err, "ftape_ready_wait aborted");
315 } else {
316 TRACE(ft_t_err, "ftape_ready_wait failed");
317 }
318 TRACE_EXIT -EIO;
319 }
320 /* Clear error condition (drive is ready !)
321 */
322 if (status & QIC_STATUS_ERROR) {
323 unsigned int error;
324 qic117_cmd_t command;
325
326 TRACE(ft_t_err, "error status set");
327 result = ftape_report_error(&error, &command, 1);
328 if (result < 0) {
329 TRACE(ft_t_err,
330 "report_error_code failed: %d", result);
331 /* hope it's working next time */
332 ftape_reset_drive();
333 TRACE_EXIT -EIO;
334 } else if (error != 0) {
335 TRACE(ft_t_noise, "error code : %d", error);
336 TRACE(ft_t_noise, "error command: %d", command);
337 }
338 }
339 if (status & QIC_STATUS_NEW_CARTRIDGE) {
340 unsigned int error;
341 qic117_cmd_t command;
342 const ft_trace_t old_tracing = TRACE_LEVEL;
343 SET_TRACE_LEVEL(ft_t_bug);
344
345 /* Undocumented feature: Must clear (not present!)
346 * error here or we'll fail later.
347 */
348 ftape_report_error(&error, &command, 1);
349
350 SET_TRACE_LEVEL(old_tracing);
351 TRACE(ft_t_info, "status: new cartridge");
352 ft_new_tape = 1;
353 } else {
354 ft_new_tape = 0;
355 }
356 FT_SIGNAL_EXIT(_DONT_BLOCK);
357 } while (status & QIC_STATUS_ERROR);
358
359 ft_no_tape = !(status & QIC_STATUS_CARTRIDGE_PRESENT);
360 ft_write_protected = (status & QIC_STATUS_WRITE_PROTECT) != 0;
361 if (ft_no_tape) {
362 TRACE(ft_t_warn, "no cartridge present");
363 } else {
364 if (ft_write_protected) {
365 TRACE(ft_t_noise, "Write protected cartridge");
366 }
367 }
368 TRACE_EXIT 0;
369}
370
371static void ftape_log_vendor_id(void)
372{
373 int vendor_index;
374 TRACE_FUN(ft_t_flow);
375
376 ftape_report_vendor_id(&ft_drive_type.vendor_id);
377 vendor_index = lookup_vendor_id(ft_drive_type.vendor_id);
378 if (ft_drive_type.vendor_id == UNKNOWN_VENDOR &&
379 ft_drive_type.wake_up == wake_up_colorado) {
380 vendor_index = 0;
381 /* hack to get rid of all this mail */
382 ft_drive_type.vendor_id = 0;
383 }
384 if (vendor_index < 0) {
385 /* Unknown vendor id, first time opening device. The
386 * drive_type remains set to type found at wakeup
387 * time, this will probably keep the driver operating
388 * for this new vendor.
389 */
390 TRACE(ft_t_warn, "\n"
391 KERN_INFO "============ unknown vendor id ===========\n"
392 KERN_INFO "A new, yet unsupported tape drive is found\n"
393 KERN_INFO "Please report the following values:\n"
394 KERN_INFO " Vendor id : 0x%04x\n"
395 KERN_INFO " Wakeup method : %s\n"
396 KERN_INFO "And a description of your tape drive\n"
397 KERN_INFO "to "THE_FTAPE_MAINTAINER"\n"
398 KERN_INFO "==========================================",
399 ft_drive_type.vendor_id,
400 methods[ft_drive_type.wake_up].name);
401 ft_drive_type.speed = 0; /* unknown */
402 } else {
403 ft_drive_type.name = vendors[vendor_index].name;
404 ft_drive_type.speed = vendors[vendor_index].speed;
405 TRACE(ft_t_info, "tape drive type: %s", ft_drive_type.name);
406 /* scan all methods for this vendor_id in table */
407 while(ft_drive_type.wake_up != vendors[vendor_index].wake_up) {
408 if (vendor_index < NR_ITEMS(vendors) - 1 &&
409 vendors[vendor_index + 1].vendor_id
410 ==
411 ft_drive_type.vendor_id) {
412 ++vendor_index;
413 } else {
414 break;
415 }
416 }
417 if (ft_drive_type.wake_up != vendors[vendor_index].wake_up) {
418 TRACE(ft_t_warn, "\n"
419 KERN_INFO "==========================================\n"
420 KERN_INFO "wakeup type mismatch:\n"
421 KERN_INFO "found: %s, expected: %s\n"
422 KERN_INFO "please report this to "THE_FTAPE_MAINTAINER"\n"
423 KERN_INFO "==========================================",
424 methods[ft_drive_type.wake_up].name,
425 methods[vendors[vendor_index].wake_up].name);
426 }
427 }
428 TRACE_EXIT;
429}
430
431void ftape_calc_timeouts(unsigned int qic_std,
432 unsigned int data_rate,
433 unsigned int tape_len)
434{
435 int speed; /* deci-ips ! */
436 int ff_speed;
437 int length;
438 TRACE_FUN(ft_t_any);
439
440 /* tape transport speed
441 * data rate: QIC-40 QIC-80 QIC-3010 QIC-3020
442 *
443 * 250 Kbps 25 ips n/a n/a n/a
444 * 500 Kbps 50 ips 34 ips 22.6 ips n/a
445 * 1 Mbps n/a 68 ips 45.2 ips 22.6 ips
446 * 2 Mbps n/a n/a n/a 45.2 ips
447 *
448 * fast tape transport speed is at least 68 ips.
449 */
450 switch (qic_std) {
451 case QIC_TAPE_QIC40:
452 speed = (data_rate == 250) ? 250 : 500;
453 break;
454 case QIC_TAPE_QIC80:
455 speed = (data_rate == 500) ? 340 : 680;
456 break;
457 case QIC_TAPE_QIC3010:
458 speed = (data_rate == 500) ? 226 : 452;
459 break;
460 case QIC_TAPE_QIC3020:
461 speed = (data_rate == 1000) ? 226 : 452;
462 break;
463 default:
464 TRACE(ft_t_bug, "Unknown qic_std (bug) ?");
465 speed = 500;
466 break;
467 }
468 if (ft_drive_type.speed == 0) {
469 unsigned long t0;
470 static int dt = 0; /* keep gcc from complaining */
471 static int first_time = 1;
472
473 /* Measure the time it takes to wind to EOT and back to BOT.
474 * If the tape length is known, calculate the rewind speed.
475 * Else keep the time value for calculation of the rewind
476 * speed later on, when the length _is_ known.
477 * Ask for a report only when length and speed are both known.
478 */
479 if (first_time) {
480 ftape_seek_to_bot();
481 t0 = jiffies;
482 ftape_seek_to_eot();
483 ftape_seek_to_bot();
484 dt = (int) (((jiffies - t0) * FT_USPT) / 1000);
485 if (dt < 1) {
486 dt = 1; /* prevent div by zero on failures */
487 }
488 first_time = 0;
489 TRACE(ft_t_info,
490 "trying to determine seek timeout, got %d msec",
491 dt);
492 }
493 if (tape_len != 0) {
494 ft_drive_type.speed =
495 (2 * 12 * tape_len * 1000) / dt;
496 TRACE(ft_t_warn, "\n"
497 KERN_INFO "==========================================\n"
498 KERN_INFO "drive type: %s\n"
499 KERN_INFO "delta time = %d ms, length = %d ft\n"
500 KERN_INFO "has a maximum tape speed of %d ips\n"
501 KERN_INFO "please report this to "THE_FTAPE_MAINTAINER"\n"
502 KERN_INFO "==========================================",
503 ft_drive_type.name, dt, tape_len,
504 ft_drive_type.speed);
505 }
506 }
507 /* Handle unknown length tapes as very long ones. We'll
508 * determine the actual length from a header segment later.
509 * This is normal for all modern (Wide,TR1/2/3) formats.
510 */
511 if (tape_len <= 0) {
512 TRACE(ft_t_noise,
513 "Unknown tape length, using maximal timeouts");
514 length = QIC_TOP_TAPE_LEN; /* use worst case values */
515 } else {
516 length = tape_len; /* use actual values */
517 }
518 if (ft_drive_type.speed == 0) {
519 ff_speed = speed;
520 } else {
521 ff_speed = ft_drive_type.speed;
522 }
523 /* time to go from bot to eot at normal speed (data rate):
524 * time = (1+delta) * length (ft) * 12 (inch/ft) / speed (ips)
525 * delta = 10 % for seek speed, 20 % for rewind speed.
526 */
527 ftape_timeout.seek = (length * 132 * FT_SECOND) / speed;
528 ftape_timeout.rewind = (length * 144 * FT_SECOND) / (10 * ff_speed);
529 ftape_timeout.reset = 20 * FT_SECOND + ftape_timeout.rewind;
530 TRACE(ft_t_noise, "timeouts for speed = %d, length = %d\n"
531 KERN_INFO "seek timeout : %d sec\n"
532 KERN_INFO "rewind timeout: %d sec\n"
533 KERN_INFO "reset timeout : %d sec",
534 speed, length,
535 (ftape_timeout.seek + 500) / 1000,
536 (ftape_timeout.rewind + 500) / 1000,
537 (ftape_timeout.reset + 500) / 1000);
538 TRACE_EXIT;
539}
540
541/* This function calibrates the datarate (i.e. determines the maximal
542 * usable data rate) and sets the global variable ft_qic_std to qic_std
543 *
544 */
545int ftape_calibrate_data_rate(unsigned int qic_std)
546{
547 int rate = ft_fdc_rate_limit;
548 int result;
549 TRACE_FUN(ft_t_flow);
550
551 ft_qic_std = qic_std;
552
553 if (ft_qic_std == -1) {
554 TRACE_ABORT(-EIO, ft_t_err,
555 "Unable to determine data rate if QIC standard is unknown");
556 }
557
558 /* Select highest rate supported by both fdc and drive.
559 * Start with highest rate supported by the fdc.
560 */
561 while (fdc_set_data_rate(rate) < 0 && rate > 250) {
562 rate /= 2;
563 }
564 TRACE(ft_t_info,
565 "Highest FDC supported data rate: %d Kbps", rate);
566 ft_fdc_max_rate = rate;
567 do {
568 result = ftape_set_data_rate(rate, ft_qic_std);
569 } while (result == -EINVAL && (rate /= 2) > 250);
570 if (result < 0) {
571 TRACE_ABORT(-EIO, ft_t_err, "set datarate failed");
572 }
573 ft_data_rate = rate;
574 TRACE_EXIT 0;
575}
576
577static int ftape_init_drive(void)
578{
579 int status;
580 qic_model model;
581 unsigned int qic_std;
582 unsigned int data_rate;
583 TRACE_FUN(ft_t_flow);
584
585 ftape_init_drive_needed = 0; /* don't retry if this fails ? */
586 TRACE_CATCH(ftape_report_raw_drive_status(&status),);
587 if (status & QIC_STATUS_CARTRIDGE_PRESENT) {
588 if (!(status & QIC_STATUS_AT_BOT)) {
589 /* Antique drives will get here after a soft reset,
590 * modern ones only if the driver is loaded when the
591 * tape wasn't rewound properly.
592 */
593 /* Tape should be at bot if new cartridge ! */
594 ftape_seek_to_bot();
595 }
596 if (!(status & QIC_STATUS_REFERENCED)) {
597 TRACE(ft_t_flow, "starting seek_load_point");
598 TRACE_CATCH(ftape_command_wait(QIC_SEEK_LOAD_POINT,
599 ftape_timeout.reset,
600 &status),);
601 }
602 }
603 ft_formatted = (status & QIC_STATUS_REFERENCED) != 0;
604 if (!ft_formatted) {
605 TRACE(ft_t_warn, "Warning: tape is not formatted !");
606 }
607
608 /* report configuration aborts when ftape_tape_len == -1
609 * unknown qic_std is okay if not formatted.
610 */
611 TRACE_CATCH(ftape_report_configuration(&model,
612 &data_rate,
613 &qic_std,
614 &ftape_tape_len),);
615
616 /* Maybe add the following to the /proc entry
617 */
618 TRACE(ft_t_info, "%s drive @ %d Kbps",
619 (model == prehistoric) ? "prehistoric" :
620 ((model == pre_qic117c) ? "pre QIC-117C" :
621 ((model == post_qic117b) ? "post QIC-117B" :
622 "post QIC-117D")), data_rate);
623
624 if (ft_formatted) {
625 /* initialize ft_used_data_rate to maximum value
626 * and set ft_qic_std
627 */
628 TRACE_CATCH(ftape_calibrate_data_rate(qic_std),);
629 if (ftape_tape_len == 0) {
630 TRACE(ft_t_info, "unknown length QIC-%s tape",
631 (ft_qic_std == QIC_TAPE_QIC40) ? "40" :
632 ((ft_qic_std == QIC_TAPE_QIC80) ? "80" :
633 ((ft_qic_std == QIC_TAPE_QIC3010)
634 ? "3010" : "3020")));
635 } else {
636 TRACE(ft_t_info, "%d ft. QIC-%s tape", ftape_tape_len,
637 (ft_qic_std == QIC_TAPE_QIC40) ? "40" :
638 ((ft_qic_std == QIC_TAPE_QIC80) ? "80" :
639 ((ft_qic_std == QIC_TAPE_QIC3010)
640 ? "3010" : "3020")));
641 }
642 ftape_calc_timeouts(ft_qic_std, ft_data_rate, ftape_tape_len);
643 /* soft write-protect QIC-40/QIC-80 cartridges used with a
644 * Colorado T3000 drive. Buggy hardware!
645 */
646 if ((ft_drive_type.vendor_id == 0x011c6) &&
647 ((ft_qic_std == QIC_TAPE_QIC40 ||
648 ft_qic_std == QIC_TAPE_QIC80) &&
649 !ft_write_protected)) {
650 TRACE(ft_t_warn, "\n"
651 KERN_INFO "The famous Colorado T3000 bug:\n"
652 KERN_INFO "%s drives can't write QIC40 and QIC80\n"
653 KERN_INFO "cartridges but don't set the write-protect flag!",
654 ft_drive_type.name);
655 ft_write_protected = 1;
656 }
657 } else {
658 /* Doesn't make too much sense to set the data rate
659 * because we don't know what to use for the write
660 * precompensation.
661 * Need to do this again when formatting the cartridge.
662 */
663 ft_data_rate = data_rate;
664 ftape_calc_timeouts(QIC_TAPE_QIC40,
665 data_rate,
666 ftape_tape_len);
667 }
668 ftape_new_cartridge();
669 TRACE_EXIT 0;
670}
671
672static void ftape_munmap(void)
673{
674 int i;
675 TRACE_FUN(ft_t_flow);
676
677 for (i = 0; i < ft_nr_buffers; i++) {
678 ft_buffer[i]->mmapped = 0;
679 }
680 TRACE_EXIT;
681}
682
683/* Map the dma buffers into the virtual address range given by vma.
684 * We only check the caller doesn't map non-existent buffers. We
685 * don't check for multiple mappings.
686 */
687int ftape_mmap(struct vm_area_struct *vma)
688{
689 int num_buffers;
690 int i;
691 TRACE_FUN(ft_t_flow);
692
693 if (ft_failure) {
694 TRACE_EXIT -ENODEV;
695 }
696 if (!(vma->vm_flags & (VM_READ|VM_WRITE))) {
697 TRACE_ABORT(-EINVAL, ft_t_err, "Undefined mmap() access");
698 }
699 if (vma_get_pgoff(vma) != 0) {
700 TRACE_ABORT(-EINVAL, ft_t_err, "page offset must be 0");
701 }
702 if ((vma->vm_end - vma->vm_start) % FT_BUFF_SIZE != 0) {
703 TRACE_ABORT(-EINVAL, ft_t_err,
704 "size = %ld, should be a multiple of %d",
705 vma->vm_end - vma->vm_start,
706 FT_BUFF_SIZE);
707 }
708 num_buffers = (vma->vm_end - vma->vm_start) / FT_BUFF_SIZE;
709 if (num_buffers > ft_nr_buffers) {
710 TRACE_ABORT(-EINVAL,
711 ft_t_err, "size = %ld, should be less than %d",
712 vma->vm_end - vma->vm_start,
713 ft_nr_buffers * FT_BUFF_SIZE);
714 }
715 if (ft_driver_state != idle) {
716 /* this also clears the buffer states
717 */
718 ftape_abort_operation();
719 } else {
720 ftape_reset_buffer();
721 }
722 for (i = 0; i < num_buffers; i++) {
723 unsigned long pfn;
724
725 pfn = virt_to_phys(ft_buffer[i]->address) >> PAGE_SHIFT;
726 TRACE_CATCH(remap_pfn_range(vma, vma->vm_start +
727 i * FT_BUFF_SIZE,
728 pfn,
729 FT_BUFF_SIZE,
730 vma->vm_page_prot),
731 _res = -EAGAIN);
732 TRACE(ft_t_noise, "remapped dma buffer @ %p to location @ %p",
733 ft_buffer[i]->address,
734 (void *)(vma->vm_start + i * FT_BUFF_SIZE));
735 }
736 for (i = 0; i < num_buffers; i++) {
737 memset(ft_buffer[i]->address, 0xAA, FT_BUFF_SIZE);
738 ft_buffer[i]->mmapped++;
739 }
740 TRACE_EXIT 0;
741}
742
743static void ftape_init_driver(void); /* forward declaration */
744
745/* OPEN routine called by kernel-interface code
746 */
747int ftape_enable(int drive_selection)
748{
749 TRACE_FUN(ft_t_any);
750
751 if (ft_drive_sel == -1 || ft_drive_sel != drive_selection) {
752 /* Other selection than last time
753 */
754 ftape_init_driver();
755 }
756 ft_drive_sel = FTAPE_SEL(drive_selection);
757 ft_failure = 0;
758 TRACE_CATCH(fdc_init(),); /* init & detect fdc */
759 TRACE_CATCH(ftape_activate_drive(&ft_drive_type),
760 fdc_disable();
761 fdc_release_irq_and_dma();
762 fdc_release_regions());
763 TRACE_CATCH(ftape_get_drive_status(), ftape_detach_drive());
764 if (ft_drive_type.vendor_id == UNKNOWN_VENDOR) {
765 ftape_log_vendor_id();
766 }
767 if (ft_new_tape) {
768 ftape_init_drive_needed = 1;
769 }
770 if (!ft_no_tape && ftape_init_drive_needed) {
771 TRACE_CATCH(ftape_init_drive(), ftape_detach_drive());
772 }
773 ftape_munmap(); /* clear the mmap flag */
774 clear_history();
775 TRACE_EXIT 0;
776}
777
778/* release routine called by the high level interface modules
779 * zftape or sftape.
780 */
781void ftape_disable(void)
782{
783 int i;
784 TRACE_FUN(ft_t_any);
785
786 for (i = 0; i < ft_nr_buffers; i++) {
787 if (ft_buffer[i]->mmapped) {
788 TRACE(ft_t_noise, "first byte of buffer %d: 0x%02x",
789 i, *ft_buffer[i]->address);
790 }
791 }
792 if (sigtestsetmask(&current->pending.signal, _DONT_BLOCK) &&
793 !(sigtestsetmask(&current->pending.signal, _NEVER_BLOCK)) &&
794 ftape_tape_running) {
795 TRACE(ft_t_warn,
796 "Interrupted by fatal signal and tape still running");
797 ftape_dumb_stop();
798 ftape_abort_operation(); /* it's annoying */
799 } else {
800 ftape_set_state(idle);
801 }
802 ftape_detach_drive();
803 if (ft_history.used) {
804 TRACE(ft_t_info, "== Non-fatal errors this run: ==");
805 TRACE(ft_t_info, "fdc isr statistics:\n"
806 KERN_INFO " id_am_errors : %3d\n"
807 KERN_INFO " id_crc_errors : %3d\n"
808 KERN_INFO " data_am_errors : %3d\n"
809 KERN_INFO " data_crc_errors : %3d\n"
810 KERN_INFO " overrun_errors : %3d\n"
811 KERN_INFO " no_data_errors : %3d\n"
812 KERN_INFO " retries : %3d",
813 ft_history.id_am_errors, ft_history.id_crc_errors,
814 ft_history.data_am_errors, ft_history.data_crc_errors,
815 ft_history.overrun_errors, ft_history.no_data_errors,
816 ft_history.retries);
817 if (ft_history.used & 1) {
818 TRACE(ft_t_info, "ecc statistics:\n"
819 KERN_INFO " crc_errors : %3d\n"
820 KERN_INFO " crc_failures : %3d\n"
821 KERN_INFO " ecc_failures : %3d\n"
822 KERN_INFO " sectors corrected: %3d",
823 ft_history.crc_errors, ft_history.crc_failures,
824 ft_history.ecc_failures, ft_history.corrected);
825 }
826 if (ft_history.defects > 0) {
827 TRACE(ft_t_warn, "Warning: %d media defects!",
828 ft_history.defects);
829 }
830 if (ft_history.rewinds > 0) {
831 TRACE(ft_t_info, "tape motion statistics:\n"
832 KERN_INFO "repositions : %3d",
833 ft_history.rewinds);
834 }
835 }
836 ft_failure = 1;
837 TRACE_EXIT;
838}
839
840static void ftape_init_driver(void)
841{
842 TRACE_FUN(ft_t_flow);
843
844 ft_drive_type.vendor_id = UNKNOWN_VENDOR;
845 ft_drive_type.speed = 0;
846 ft_drive_type.wake_up = unknown_wake_up;
847 ft_drive_type.name = "Unknown";
848
849 ftape_timeout.seek = 650 * FT_SECOND;
850 ftape_timeout.reset = 670 * FT_SECOND;
851 ftape_timeout.rewind = 650 * FT_SECOND;
852 ftape_timeout.head_seek = 15 * FT_SECOND;
853 ftape_timeout.stop = 5 * FT_SECOND;
854 ftape_timeout.pause = 16 * FT_SECOND;
855
856 ft_qic_std = -1;
857 ftape_tape_len = 0; /* unknown */
858 ftape_current_command = 0;
859 ftape_current_cylinder = -1;
860
861 ft_segments_per_track = 102;
862 ftape_segments_per_head = 1020;
863 ftape_segments_per_cylinder = 4;
864 ft_tracks_per_tape = 20;
865
866 ft_failure = 1;
867
868 ft_formatted = 0;
869 ft_no_tape = 1;
870 ft_write_protected = 1;
871 ft_new_tape = 1;
872
873 ft_driver_state = idle;
874
875 ft_data_rate =
876 ft_fdc_max_rate = 500;
877 ft_drive_max_rate = 0; /* triggers set_rate_test() */
878
879 ftape_init_drive_needed = 1;
880
881 ft_header_segment_1 = -1;
882 ft_header_segment_2 = -1;
883 ft_used_header_segment = -1;
884 ft_first_data_segment = -1;
885 ft_last_data_segment = -1;
886
887 ft_location.track = -1;
888 ft_location.known = 0;
889
890 ftape_tape_running = 0;
891 ftape_might_be_off_track = 1;
892
893 ftape_new_cartridge(); /* init some tape related variables */
894 ftape_init_bsm();
895 TRACE_EXIT;
896}
diff --git a/drivers/char/ftape/lowlevel/ftape-ctl.h b/drivers/char/ftape/lowlevel/ftape-ctl.h
deleted file mode 100644
index 5f5e30bc3615..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-ctl.h
+++ /dev/null
@@ -1,162 +0,0 @@
1#ifndef _FTAPE_CTL_H
2#define _FTAPE_CTL_H
3
4/*
5 * Copyright (C) 1993-1996 Bas Laarhoven,
6 * (C) 1996-1997 Claus-Justus Heine.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 *
23 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-ctl.h,v $
24 * $Revision: 1.2 $
25 * $Date: 1997/10/05 19:18:09 $
26 *
27 * This file contains the non-standard IOCTL related definitions
28 * for the QIC-40/80/3010/3020 floppy-tape driver "ftape" for
29 * Linux.
30 */
31
32#include <linux/ioctl.h>
33#include <linux/mtio.h>
34#include <linux/ftape-vendors.h>
35
36#include "../lowlevel/ftape-rw.h"
37#include <linux/ftape-header-segment.h>
38
39typedef struct {
40 int used; /* any reading or writing done */
41 /* isr statistics */
42 unsigned int id_am_errors; /* id address mark not found */
43 unsigned int id_crc_errors; /* crc error in id address mark */
44 unsigned int data_am_errors; /* data address mark not found */
45 unsigned int data_crc_errors; /* crc error in data field */
46 unsigned int overrun_errors; /* fdc access timing problem */
47 unsigned int no_data_errors; /* sector not found */
48 unsigned int retries; /* number of tape retries */
49 /* ecc statistics */
50 unsigned int crc_errors; /* crc error in data */
51 unsigned int crc_failures; /* bad data without crc error */
52 unsigned int ecc_failures; /* failed to correct */
53 unsigned int corrected; /* total sectors corrected */
54 /* general statistics */
55 unsigned int rewinds; /* number of tape rewinds */
56 unsigned int defects; /* bad sectors due to media defects */
57} history_record;
58
59/* this structure contains * ALL * information that we want
60 * our child modules to know about, but don't want them to
61 * modify.
62 */
63typedef struct {
64 /* vendor information */
65 vendor_struct fti_drive_type;
66 /* data rates */
67 unsigned int fti_used_data_rate;
68 unsigned int fti_drive_max_rate;
69 unsigned int fti_fdc_max_rate;
70 /* drive selection, either FTAPE_SEL_A/B/C/D */
71 int fti_drive_sel;
72 /* flags set after decode the drive and tape status */
73 unsigned int fti_formatted :1;
74 unsigned int fti_no_tape :1;
75 unsigned int fti_write_protected:1;
76 unsigned int fti_new_tape :1;
77 /* values of last queried drive/tape status and error */
78 ft_drive_error fti_last_error;
79 ft_drive_status fti_last_status;
80 /* cartridge geometry */
81 unsigned int fti_tracks_per_tape;
82 unsigned int fti_segments_per_track;
83 /* location of header segments, etc. */
84 int fti_used_header_segment;
85 int fti_header_segment_1;
86 int fti_header_segment_2;
87 int fti_first_data_segment;
88 int fti_last_data_segment;
89 /* the format code as stored in the header segment */
90 ft_format_type fti_format_code;
91 /* the following is the sole reason for the ftape_set_status() call */
92 unsigned int fti_qic_std;
93 /* is tape running? */
94 volatile enum runner_status_enum fti_runner_status;
95 /* is tape reading/writing/verifying/formatting/deleting */
96 buffer_state_enum fti_state;
97 /* flags fatal hardware error */
98 unsigned int fti_failure:1;
99 /* history record */
100 history_record fti_history;
101} ftape_info;
102
103/* vendor information */
104#define ft_drive_type ftape_status.fti_drive_type
105/* data rates */
106#define ft_data_rate ftape_status.fti_used_data_rate
107#define ft_drive_max_rate ftape_status.fti_drive_max_rate
108#define ft_fdc_max_rate ftape_status.fti_fdc_max_rate
109/* drive selection, either FTAPE_SEL_A/B/C/D */
110#define ft_drive_sel ftape_status.fti_drive_sel
111/* flags set after decode the drive and tape status */
112#define ft_formatted ftape_status.fti_formatted
113#define ft_no_tape ftape_status.fti_no_tape
114#define ft_write_protected ftape_status.fti_write_protected
115#define ft_new_tape ftape_status.fti_new_tape
116/* values of last queried drive/tape status and error */
117#define ft_last_error ftape_status.fti_last_error
118#define ft_last_status ftape_status.fti_last_status
119/* cartridge geometry */
120#define ft_tracks_per_tape ftape_status.fti_tracks_per_tape
121#define ft_segments_per_track ftape_status.fti_segments_per_track
122/* the format code as stored in the header segment */
123#define ft_format_code ftape_status.fti_format_code
124/* the qic status as returned by report drive configuration */
125#define ft_qic_std ftape_status.fti_qic_std
126#define ft_used_header_segment ftape_status.fti_used_header_segment
127#define ft_header_segment_1 ftape_status.fti_header_segment_1
128#define ft_header_segment_2 ftape_status.fti_header_segment_2
129#define ft_first_data_segment ftape_status.fti_first_data_segment
130#define ft_last_data_segment ftape_status.fti_last_data_segment
131/* is tape running? */
132#define ft_runner_status ftape_status.fti_runner_status
133/* is tape reading/writing/verifying/formatting/deleting */
134#define ft_driver_state ftape_status.fti_state
135/* flags fatal hardware error */
136#define ft_failure ftape_status.fti_failure
137/* history record */
138#define ft_history ftape_status.fti_history
139
140/*
141 * ftape-ctl.c defined global vars.
142 */
143extern ftape_info ftape_status;
144extern int ftape_segments_per_head;
145extern int ftape_segments_per_cylinder;
146extern int ftape_init_drive_needed;
147
148/*
149 * ftape-ctl.c defined global functions.
150 */
151extern int ftape_mmap(struct vm_area_struct *vma);
152extern int ftape_enable(int drive_selection);
153extern void ftape_disable(void);
154extern int ftape_seek_to_bot(void);
155extern int ftape_seek_to_eot(void);
156extern int ftape_abort_operation(void);
157extern void ftape_calc_timeouts(unsigned int qic_std,
158 unsigned int data_rate,
159 unsigned int tape_len);
160extern int ftape_calibrate_data_rate(unsigned int qic_std);
161extern const ftape_info *ftape_get_status(void);
162#endif
diff --git a/drivers/char/ftape/lowlevel/ftape-ecc.c b/drivers/char/ftape/lowlevel/ftape-ecc.c
deleted file mode 100644
index e5632f674bc8..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-ecc.c
+++ /dev/null
@@ -1,853 +0,0 @@
1/*
2 *
3 * Copyright (c) 1993 Ning and David Mosberger.
4
5 This is based on code originally written by Bas Laarhoven (bas@vimec.nl)
6 and David L. Brown, Jr., and incorporates improvements suggested by
7 Kai Harrekilde-Petersen.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2, or (at
12 your option) any later version.
13
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 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; see the file COPYING. If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
22 USA.
23
24 *
25 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-ecc.c,v $
26 * $Revision: 1.3 $
27 * $Date: 1997/10/05 19:18:10 $
28 *
29 * This file contains the Reed-Solomon error correction code
30 * for the QIC-40/80 floppy-tape driver for Linux.
31 */
32
33#include <linux/ftape.h>
34
35#include "../lowlevel/ftape-tracing.h"
36#include "../lowlevel/ftape-ecc.h"
37
38/* Machines that are big-endian should define macro BIG_ENDIAN.
39 * Unfortunately, there doesn't appear to be a standard include file
40 * that works for all OSs.
41 */
42
43#if defined(__sparc__) || defined(__hppa)
44#define BIG_ENDIAN
45#endif /* __sparc__ || __hppa */
46
47#if defined(__mips__)
48#error Find a smart way to determine the Endianness of the MIPS CPU
49#endif
50
51/* Notice: to minimize the potential for confusion, we use r to
52 * denote the independent variable of the polynomials in the
53 * Galois Field GF(2^8). We reserve x for polynomials that
54 * that have coefficients in GF(2^8).
55 *
56 * The Galois Field in which coefficient arithmetic is performed are
57 * the polynomials over Z_2 (i.e., 0 and 1) modulo the irreducible
58 * polynomial f(r), where f(r)=r^8 + r^7 + r^2 + r + 1. A polynomial
59 * is represented as a byte with the MSB as the coefficient of r^7 and
60 * the LSB as the coefficient of r^0. For example, the binary
61 * representation of f(x) is 0x187 (of course, this doesn't fit into 8
62 * bits). In this field, the polynomial r is a primitive element.
63 * That is, r^i with i in 0,...,255 enumerates all elements in the
64 * field.
65 *
66 * The generator polynomial for the QIC-80 ECC is
67 *
68 * g(x) = x^3 + r^105*x^2 + r^105*x + 1
69 *
70 * which can be factored into:
71 *
72 * g(x) = (x-r^-1)(x-r^0)(x-r^1)
73 *
74 * the byte representation of the coefficients are:
75 *
76 * r^105 = 0xc0
77 * r^-1 = 0xc3
78 * r^0 = 0x01
79 * r^1 = 0x02
80 *
81 * Notice that r^-1 = r^254 as exponent arithmetic is performed
82 * modulo 2^8-1 = 255.
83 *
84 * For more information on Galois Fields and Reed-Solomon codes, refer
85 * to any good book. I found _An Introduction to Error Correcting
86 * Codes with Applications_ by S. A. Vanstone and P. C. van Oorschot
87 * to be a good introduction into the former. _CODING THEORY: The
88 * Essentials_ I found very useful for its concise description of
89 * Reed-Solomon encoding/decoding.
90 *
91 */
92
93typedef __u8 Matrix[3][3];
94
95/*
96 * gfpow[] is defined such that gfpow[i] returns r^i if
97 * i is in the range [0..255].
98 */
99static const __u8 gfpow[] =
100{
101 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
102 0x87, 0x89, 0x95, 0xad, 0xdd, 0x3d, 0x7a, 0xf4,
103 0x6f, 0xde, 0x3b, 0x76, 0xec, 0x5f, 0xbe, 0xfb,
104 0x71, 0xe2, 0x43, 0x86, 0x8b, 0x91, 0xa5, 0xcd,
105 0x1d, 0x3a, 0x74, 0xe8, 0x57, 0xae, 0xdb, 0x31,
106 0x62, 0xc4, 0x0f, 0x1e, 0x3c, 0x78, 0xf0, 0x67,
107 0xce, 0x1b, 0x36, 0x6c, 0xd8, 0x37, 0x6e, 0xdc,
108 0x3f, 0x7e, 0xfc, 0x7f, 0xfe, 0x7b, 0xf6, 0x6b,
109 0xd6, 0x2b, 0x56, 0xac, 0xdf, 0x39, 0x72, 0xe4,
110 0x4f, 0x9e, 0xbb, 0xf1, 0x65, 0xca, 0x13, 0x26,
111 0x4c, 0x98, 0xb7, 0xe9, 0x55, 0xaa, 0xd3, 0x21,
112 0x42, 0x84, 0x8f, 0x99, 0xb5, 0xed, 0x5d, 0xba,
113 0xf3, 0x61, 0xc2, 0x03, 0x06, 0x0c, 0x18, 0x30,
114 0x60, 0xc0, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0,
115 0x47, 0x8e, 0x9b, 0xb1, 0xe5, 0x4d, 0x9a, 0xb3,
116 0xe1, 0x45, 0x8a, 0x93, 0xa1, 0xc5, 0x0d, 0x1a,
117 0x34, 0x68, 0xd0, 0x27, 0x4e, 0x9c, 0xbf, 0xf9,
118 0x75, 0xea, 0x53, 0xa6, 0xcb, 0x11, 0x22, 0x44,
119 0x88, 0x97, 0xa9, 0xd5, 0x2d, 0x5a, 0xb4, 0xef,
120 0x59, 0xb2, 0xe3, 0x41, 0x82, 0x83, 0x81, 0x85,
121 0x8d, 0x9d, 0xbd, 0xfd, 0x7d, 0xfa, 0x73, 0xe6,
122 0x4b, 0x96, 0xab, 0xd1, 0x25, 0x4a, 0x94, 0xaf,
123 0xd9, 0x35, 0x6a, 0xd4, 0x2f, 0x5e, 0xbc, 0xff,
124 0x79, 0xf2, 0x63, 0xc6, 0x0b, 0x16, 0x2c, 0x58,
125 0xb0, 0xe7, 0x49, 0x92, 0xa3, 0xc1, 0x05, 0x0a,
126 0x14, 0x28, 0x50, 0xa0, 0xc7, 0x09, 0x12, 0x24,
127 0x48, 0x90, 0xa7, 0xc9, 0x15, 0x2a, 0x54, 0xa8,
128 0xd7, 0x29, 0x52, 0xa4, 0xcf, 0x19, 0x32, 0x64,
129 0xc8, 0x17, 0x2e, 0x5c, 0xb8, 0xf7, 0x69, 0xd2,
130 0x23, 0x46, 0x8c, 0x9f, 0xb9, 0xf5, 0x6d, 0xda,
131 0x33, 0x66, 0xcc, 0x1f, 0x3e, 0x7c, 0xf8, 0x77,
132 0xee, 0x5b, 0xb6, 0xeb, 0x51, 0xa2, 0xc3, 0x01
133};
134
135/*
136 * This is a log table. That is, gflog[r^i] returns i (modulo f(r)).
137 * gflog[0] is undefined and the first element is therefore not valid.
138 */
139static const __u8 gflog[256] =
140{
141 0xff, 0x00, 0x01, 0x63, 0x02, 0xc6, 0x64, 0x6a,
142 0x03, 0xcd, 0xc7, 0xbc, 0x65, 0x7e, 0x6b, 0x2a,
143 0x04, 0x8d, 0xce, 0x4e, 0xc8, 0xd4, 0xbd, 0xe1,
144 0x66, 0xdd, 0x7f, 0x31, 0x6c, 0x20, 0x2b, 0xf3,
145 0x05, 0x57, 0x8e, 0xe8, 0xcf, 0xac, 0x4f, 0x83,
146 0xc9, 0xd9, 0xd5, 0x41, 0xbe, 0x94, 0xe2, 0xb4,
147 0x67, 0x27, 0xde, 0xf0, 0x80, 0xb1, 0x32, 0x35,
148 0x6d, 0x45, 0x21, 0x12, 0x2c, 0x0d, 0xf4, 0x38,
149 0x06, 0x9b, 0x58, 0x1a, 0x8f, 0x79, 0xe9, 0x70,
150 0xd0, 0xc2, 0xad, 0xa8, 0x50, 0x75, 0x84, 0x48,
151 0xca, 0xfc, 0xda, 0x8a, 0xd6, 0x54, 0x42, 0x24,
152 0xbf, 0x98, 0x95, 0xf9, 0xe3, 0x5e, 0xb5, 0x15,
153 0x68, 0x61, 0x28, 0xba, 0xdf, 0x4c, 0xf1, 0x2f,
154 0x81, 0xe6, 0xb2, 0x3f, 0x33, 0xee, 0x36, 0x10,
155 0x6e, 0x18, 0x46, 0xa6, 0x22, 0x88, 0x13, 0xf7,
156 0x2d, 0xb8, 0x0e, 0x3d, 0xf5, 0xa4, 0x39, 0x3b,
157 0x07, 0x9e, 0x9c, 0x9d, 0x59, 0x9f, 0x1b, 0x08,
158 0x90, 0x09, 0x7a, 0x1c, 0xea, 0xa0, 0x71, 0x5a,
159 0xd1, 0x1d, 0xc3, 0x7b, 0xae, 0x0a, 0xa9, 0x91,
160 0x51, 0x5b, 0x76, 0x72, 0x85, 0xa1, 0x49, 0xeb,
161 0xcb, 0x7c, 0xfd, 0xc4, 0xdb, 0x1e, 0x8b, 0xd2,
162 0xd7, 0x92, 0x55, 0xaa, 0x43, 0x0b, 0x25, 0xaf,
163 0xc0, 0x73, 0x99, 0x77, 0x96, 0x5c, 0xfa, 0x52,
164 0xe4, 0xec, 0x5f, 0x4a, 0xb6, 0xa2, 0x16, 0x86,
165 0x69, 0xc5, 0x62, 0xfe, 0x29, 0x7d, 0xbb, 0xcc,
166 0xe0, 0xd3, 0x4d, 0x8c, 0xf2, 0x1f, 0x30, 0xdc,
167 0x82, 0xab, 0xe7, 0x56, 0xb3, 0x93, 0x40, 0xd8,
168 0x34, 0xb0, 0xef, 0x26, 0x37, 0x0c, 0x11, 0x44,
169 0x6f, 0x78, 0x19, 0x9a, 0x47, 0x74, 0xa7, 0xc1,
170 0x23, 0x53, 0x89, 0xfb, 0x14, 0x5d, 0xf8, 0x97,
171 0x2e, 0x4b, 0xb9, 0x60, 0x0f, 0xed, 0x3e, 0xe5,
172 0xf6, 0x87, 0xa5, 0x17, 0x3a, 0xa3, 0x3c, 0xb7
173};
174
175/* This is a multiplication table for the factor 0xc0 (i.e., r^105 (mod f(r)).
176 * gfmul_c0[f] returns r^105 * f(r) (modulo f(r)).
177 */
178static const __u8 gfmul_c0[256] =
179{
180 0x00, 0xc0, 0x07, 0xc7, 0x0e, 0xce, 0x09, 0xc9,
181 0x1c, 0xdc, 0x1b, 0xdb, 0x12, 0xd2, 0x15, 0xd5,
182 0x38, 0xf8, 0x3f, 0xff, 0x36, 0xf6, 0x31, 0xf1,
183 0x24, 0xe4, 0x23, 0xe3, 0x2a, 0xea, 0x2d, 0xed,
184 0x70, 0xb0, 0x77, 0xb7, 0x7e, 0xbe, 0x79, 0xb9,
185 0x6c, 0xac, 0x6b, 0xab, 0x62, 0xa2, 0x65, 0xa5,
186 0x48, 0x88, 0x4f, 0x8f, 0x46, 0x86, 0x41, 0x81,
187 0x54, 0x94, 0x53, 0x93, 0x5a, 0x9a, 0x5d, 0x9d,
188 0xe0, 0x20, 0xe7, 0x27, 0xee, 0x2e, 0xe9, 0x29,
189 0xfc, 0x3c, 0xfb, 0x3b, 0xf2, 0x32, 0xf5, 0x35,
190 0xd8, 0x18, 0xdf, 0x1f, 0xd6, 0x16, 0xd1, 0x11,
191 0xc4, 0x04, 0xc3, 0x03, 0xca, 0x0a, 0xcd, 0x0d,
192 0x90, 0x50, 0x97, 0x57, 0x9e, 0x5e, 0x99, 0x59,
193 0x8c, 0x4c, 0x8b, 0x4b, 0x82, 0x42, 0x85, 0x45,
194 0xa8, 0x68, 0xaf, 0x6f, 0xa6, 0x66, 0xa1, 0x61,
195 0xb4, 0x74, 0xb3, 0x73, 0xba, 0x7a, 0xbd, 0x7d,
196 0x47, 0x87, 0x40, 0x80, 0x49, 0x89, 0x4e, 0x8e,
197 0x5b, 0x9b, 0x5c, 0x9c, 0x55, 0x95, 0x52, 0x92,
198 0x7f, 0xbf, 0x78, 0xb8, 0x71, 0xb1, 0x76, 0xb6,
199 0x63, 0xa3, 0x64, 0xa4, 0x6d, 0xad, 0x6a, 0xaa,
200 0x37, 0xf7, 0x30, 0xf0, 0x39, 0xf9, 0x3e, 0xfe,
201 0x2b, 0xeb, 0x2c, 0xec, 0x25, 0xe5, 0x22, 0xe2,
202 0x0f, 0xcf, 0x08, 0xc8, 0x01, 0xc1, 0x06, 0xc6,
203 0x13, 0xd3, 0x14, 0xd4, 0x1d, 0xdd, 0x1a, 0xda,
204 0xa7, 0x67, 0xa0, 0x60, 0xa9, 0x69, 0xae, 0x6e,
205 0xbb, 0x7b, 0xbc, 0x7c, 0xb5, 0x75, 0xb2, 0x72,
206 0x9f, 0x5f, 0x98, 0x58, 0x91, 0x51, 0x96, 0x56,
207 0x83, 0x43, 0x84, 0x44, 0x8d, 0x4d, 0x8a, 0x4a,
208 0xd7, 0x17, 0xd0, 0x10, 0xd9, 0x19, 0xde, 0x1e,
209 0xcb, 0x0b, 0xcc, 0x0c, 0xc5, 0x05, 0xc2, 0x02,
210 0xef, 0x2f, 0xe8, 0x28, 0xe1, 0x21, 0xe6, 0x26,
211 0xf3, 0x33, 0xf4, 0x34, 0xfd, 0x3d, 0xfa, 0x3a
212};
213
214
215/* Returns V modulo 255 provided V is in the range -255,-254,...,509.
216 */
217static inline __u8 mod255(int v)
218{
219 if (v > 0) {
220 if (v < 255) {
221 return v;
222 } else {
223 return v - 255;
224 }
225 } else {
226 return v + 255;
227 }
228}
229
230
231/* Add two numbers in the field. Addition in this field is equivalent
232 * to a bit-wise exclusive OR operation---subtraction is therefore
233 * identical to addition.
234 */
235static inline __u8 gfadd(__u8 a, __u8 b)
236{
237 return a ^ b;
238}
239
240
241/* Add two vectors of numbers in the field. Each byte in A and B gets
242 * added individually.
243 */
244static inline unsigned long gfadd_long(unsigned long a, unsigned long b)
245{
246 return a ^ b;
247}
248
249
250/* Multiply two numbers in the field:
251 */
252static inline __u8 gfmul(__u8 a, __u8 b)
253{
254 if (a && b) {
255 return gfpow[mod255(gflog[a] + gflog[b])];
256 } else {
257 return 0;
258 }
259}
260
261
262/* Just like gfmul, except we have already looked up the log of the
263 * second number.
264 */
265static inline __u8 gfmul_exp(__u8 a, int b)
266{
267 if (a) {
268 return gfpow[mod255(gflog[a] + b)];
269 } else {
270 return 0;
271 }
272}
273
274
275/* Just like gfmul_exp, except that A is a vector of numbers. That
276 * is, each byte in A gets multiplied by gfpow[mod255(B)].
277 */
278static inline unsigned long gfmul_exp_long(unsigned long a, int b)
279{
280 __u8 t;
281
282 if (sizeof(long) == 4) {
283 return (
284 ((t = (__u32)a >> 24 & 0xff) ?
285 (((__u32) gfpow[mod255(gflog[t] + b)]) << 24) : 0) |
286 ((t = (__u32)a >> 16 & 0xff) ?
287 (((__u32) gfpow[mod255(gflog[t] + b)]) << 16) : 0) |
288 ((t = (__u32)a >> 8 & 0xff) ?
289 (((__u32) gfpow[mod255(gflog[t] + b)]) << 8) : 0) |
290 ((t = (__u32)a >> 0 & 0xff) ?
291 (((__u32) gfpow[mod255(gflog[t] + b)]) << 0) : 0));
292 } else if (sizeof(long) == 8) {
293 return (
294 ((t = (__u64)a >> 56 & 0xff) ?
295 (((__u64) gfpow[mod255(gflog[t] + b)]) << 56) : 0) |
296 ((t = (__u64)a >> 48 & 0xff) ?
297 (((__u64) gfpow[mod255(gflog[t] + b)]) << 48) : 0) |
298 ((t = (__u64)a >> 40 & 0xff) ?
299 (((__u64) gfpow[mod255(gflog[t] + b)]) << 40) : 0) |
300 ((t = (__u64)a >> 32 & 0xff) ?
301 (((__u64) gfpow[mod255(gflog[t] + b)]) << 32) : 0) |
302 ((t = (__u64)a >> 24 & 0xff) ?
303 (((__u64) gfpow[mod255(gflog[t] + b)]) << 24) : 0) |
304 ((t = (__u64)a >> 16 & 0xff) ?
305 (((__u64) gfpow[mod255(gflog[t] + b)]) << 16) : 0) |
306 ((t = (__u64)a >> 8 & 0xff) ?
307 (((__u64) gfpow[mod255(gflog[t] + b)]) << 8) : 0) |
308 ((t = (__u64)a >> 0 & 0xff) ?
309 (((__u64) gfpow[mod255(gflog[t] + b)]) << 0) : 0));
310 } else {
311 TRACE_FUN(ft_t_any);
312 TRACE_ABORT(-1, ft_t_err, "Error: size of long is %d bytes",
313 (int)sizeof(long));
314 }
315}
316
317
318/* Divide two numbers in the field. Returns a/b (modulo f(x)).
319 */
320static inline __u8 gfdiv(__u8 a, __u8 b)
321{
322 if (!b) {
323 TRACE_FUN(ft_t_any);
324 TRACE_ABORT(0xff, ft_t_bug, "Error: division by zero");
325 } else if (a == 0) {
326 return 0;
327 } else {
328 return gfpow[mod255(gflog[a] - gflog[b])];
329 }
330}
331
332
333/* The following functions return the inverse of the matrix of the
334 * linear system that needs to be solved to determine the error
335 * magnitudes. The first deals with matrices of rank 3, while the
336 * second deals with matrices of rank 2. The error indices are passed
337 * in arguments L0,..,L2 (0=first sector, 31=last sector). The error
338 * indices must be sorted in ascending order, i.e., L0<L1<L2.
339 *
340 * The linear system that needs to be solved for the error magnitudes
341 * is A * b = s, where s is the known vector of syndromes, b is the
342 * vector of error magnitudes and A in the ORDER=3 case:
343 *
344 * A_3 = {{1/r^L[0], 1/r^L[1], 1/r^L[2]},
345 * { 1, 1, 1},
346 * { r^L[0], r^L[1], r^L[2]}}
347 */
348static inline int gfinv3(__u8 l0,
349 __u8 l1,
350 __u8 l2,
351 Matrix Ainv)
352{
353 __u8 det;
354 __u8 t20, t10, t21, t12, t01, t02;
355 int log_det;
356
357 /* compute some intermediate results: */
358 t20 = gfpow[l2 - l0]; /* t20 = r^l2/r^l0 */
359 t10 = gfpow[l1 - l0]; /* t10 = r^l1/r^l0 */
360 t21 = gfpow[l2 - l1]; /* t21 = r^l2/r^l1 */
361 t12 = gfpow[l1 - l2 + 255]; /* t12 = r^l1/r^l2 */
362 t01 = gfpow[l0 - l1 + 255]; /* t01 = r^l0/r^l1 */
363 t02 = gfpow[l0 - l2 + 255]; /* t02 = r^l0/r^l2 */
364 /* Calculate the determinant of matrix A_3^-1 (sometimes
365 * called the Vandermonde determinant):
366 */
367 det = gfadd(t20, gfadd(t10, gfadd(t21, gfadd(t12, gfadd(t01, t02)))));
368 if (!det) {
369 TRACE_FUN(ft_t_any);
370 TRACE_ABORT(0, ft_t_err,
371 "Inversion failed (3 CRC errors, >0 CRC failures)");
372 }
373 log_det = 255 - gflog[det];
374
375 /* Now, calculate all of the coefficients:
376 */
377 Ainv[0][0]= gfmul_exp(gfadd(gfpow[l1], gfpow[l2]), log_det);
378 Ainv[0][1]= gfmul_exp(gfadd(t21, t12), log_det);
379 Ainv[0][2]= gfmul_exp(gfadd(gfpow[255 - l1], gfpow[255 - l2]),log_det);
380
381 Ainv[1][0]= gfmul_exp(gfadd(gfpow[l0], gfpow[l2]), log_det);
382 Ainv[1][1]= gfmul_exp(gfadd(t20, t02), log_det);
383 Ainv[1][2]= gfmul_exp(gfadd(gfpow[255 - l0], gfpow[255 - l2]),log_det);
384
385 Ainv[2][0]= gfmul_exp(gfadd(gfpow[l0], gfpow[l1]), log_det);
386 Ainv[2][1]= gfmul_exp(gfadd(t10, t01), log_det);
387 Ainv[2][2]= gfmul_exp(gfadd(gfpow[255 - l0], gfpow[255 - l1]),log_det);
388
389 return 1;
390}
391
392
393static inline int gfinv2(__u8 l0, __u8 l1, Matrix Ainv)
394{
395 __u8 det;
396 __u8 t1, t2;
397 int log_det;
398
399 t1 = gfpow[255 - l0];
400 t2 = gfpow[255 - l1];
401 det = gfadd(t1, t2);
402 if (!det) {
403 TRACE_FUN(ft_t_any);
404 TRACE_ABORT(0, ft_t_err,
405 "Inversion failed (2 CRC errors, >0 CRC failures)");
406 }
407 log_det = 255 - gflog[det];
408
409 /* Now, calculate all of the coefficients:
410 */
411 Ainv[0][0] = Ainv[1][0] = gfpow[log_det];
412
413 Ainv[0][1] = gfmul_exp(t2, log_det);
414 Ainv[1][1] = gfmul_exp(t1, log_det);
415
416 return 1;
417}
418
419
420/* Multiply matrix A by vector S and return result in vector B. M is
421 * assumed to be of order NxN, S and B of order Nx1.
422 */
423static inline void gfmat_mul(int n, Matrix A,
424 __u8 *s, __u8 *b)
425{
426 int i, j;
427 __u8 dot_prod;
428
429 for (i = 0; i < n; ++i) {
430 dot_prod = 0;
431 for (j = 0; j < n; ++j) {
432 dot_prod = gfadd(dot_prod, gfmul(A[i][j], s[j]));
433 }
434 b[i] = dot_prod;
435 }
436}
437
438
439
440/* The Reed Solomon ECC codes are computed over the N-th byte of each
441 * block, where N=SECTOR_SIZE. There are up to 29 blocks of data, and
442 * 3 blocks of ECC. The blocks are stored contiguously in memory. A
443 * segment, consequently, is assumed to have at least 4 blocks: one or
444 * more data blocks plus three ECC blocks.
445 *
446 * Notice: In QIC-80 speak, a CRC error is a sector with an incorrect
447 * CRC. A CRC failure is a sector with incorrect data, but
448 * a valid CRC. In the error control literature, the former
449 * is usually called "erasure", the latter "error."
450 */
451/* Compute the parity bytes for C columns of data, where C is the
452 * number of bytes that fit into a long integer. We use a linear
453 * feed-back register to do this. The parity bytes P[0], P[STRIDE],
454 * P[2*STRIDE] are computed such that:
455 *
456 * x^k * p(x) + m(x) = 0 (modulo g(x))
457 *
458 * where k = NBLOCKS,
459 * p(x) = P[0] + P[STRIDE]*x + P[2*STRIDE]*x^2, and
460 * m(x) = sum_{i=0}^k m_i*x^i.
461 * m_i = DATA[i*SECTOR_SIZE]
462 */
463static inline void set_parity(unsigned long *data,
464 int nblocks,
465 unsigned long *p,
466 int stride)
467{
468 unsigned long p0, p1, p2, t1, t2, *end;
469
470 end = data + nblocks * (FT_SECTOR_SIZE / sizeof(long));
471 p0 = p1 = p2 = 0;
472 while (data < end) {
473 /* The new parity bytes p0_i, p1_i, p2_i are computed
474 * from the old values p0_{i-1}, p1_{i-1}, p2_{i-1}
475 * recursively as:
476 *
477 * p0_i = p1_{i-1} + r^105 * (m_{i-1} - p0_{i-1})
478 * p1_i = p2_{i-1} + r^105 * (m_{i-1} - p0_{i-1})
479 * p2_i = (m_{i-1} - p0_{i-1})
480 *
481 * With the initial condition: p0_0 = p1_0 = p2_0 = 0.
482 */
483 t1 = gfadd_long(*data, p0);
484 /*
485 * Multiply each byte in t1 by 0xc0:
486 */
487 if (sizeof(long) == 4) {
488 t2= (((__u32) gfmul_c0[(__u32)t1 >> 24 & 0xff]) << 24 |
489 ((__u32) gfmul_c0[(__u32)t1 >> 16 & 0xff]) << 16 |
490 ((__u32) gfmul_c0[(__u32)t1 >> 8 & 0xff]) << 8 |
491 ((__u32) gfmul_c0[(__u32)t1 >> 0 & 0xff]) << 0);
492 } else if (sizeof(long) == 8) {
493 t2= (((__u64) gfmul_c0[(__u64)t1 >> 56 & 0xff]) << 56 |
494 ((__u64) gfmul_c0[(__u64)t1 >> 48 & 0xff]) << 48 |
495 ((__u64) gfmul_c0[(__u64)t1 >> 40 & 0xff]) << 40 |
496 ((__u64) gfmul_c0[(__u64)t1 >> 32 & 0xff]) << 32 |
497 ((__u64) gfmul_c0[(__u64)t1 >> 24 & 0xff]) << 24 |
498 ((__u64) gfmul_c0[(__u64)t1 >> 16 & 0xff]) << 16 |
499 ((__u64) gfmul_c0[(__u64)t1 >> 8 & 0xff]) << 8 |
500 ((__u64) gfmul_c0[(__u64)t1 >> 0 & 0xff]) << 0);
501 } else {
502 TRACE_FUN(ft_t_any);
503 TRACE(ft_t_err, "Error: long is of size %d",
504 (int) sizeof(long));
505 TRACE_EXIT;
506 }
507 p0 = gfadd_long(t2, p1);
508 p1 = gfadd_long(t2, p2);
509 p2 = t1;
510 data += FT_SECTOR_SIZE / sizeof(long);
511 }
512 *p = p0;
513 p += stride;
514 *p = p1;
515 p += stride;
516 *p = p2;
517 return;
518}
519
520
521/* Compute the 3 syndrome values. DATA should point to the first byte
522 * of the column for which the syndromes are desired. The syndromes
523 * are computed over the first NBLOCKS of rows. The three bytes will
524 * be placed in S[0], S[1], and S[2].
525 *
526 * S[i] is the value of the "message" polynomial m(x) evaluated at the
527 * i-th root of the generator polynomial g(x).
528 *
529 * As g(x)=(x-r^-1)(x-1)(x-r^1) we evaluate the message polynomial at
530 * x=r^-1 to get S[0], at x=r^0=1 to get S[1], and at x=r to get S[2].
531 * This could be done directly and efficiently via the Horner scheme.
532 * However, it would require multiplication tables for the factors
533 * r^-1 (0xc3) and r (0x02). The following scheme does not require
534 * any multiplication tables beyond what's needed for set_parity()
535 * anyway and is slightly faster if there are no errors and slightly
536 * slower if there are errors. The latter is hopefully the infrequent
537 * case.
538 *
539 * To understand the alternative algorithm, notice that set_parity(m,
540 * k, p) computes parity bytes such that:
541 *
542 * x^k * p(x) = m(x) (modulo g(x)).
543 *
544 * That is, to evaluate m(r^m), where r^m is a root of g(x), we can
545 * simply evaluate (r^m)^k*p(r^m). Also, notice that p is 0 if and
546 * only if s is zero. That is, if all parity bytes are 0, we know
547 * there is no error in the data and consequently there is no need to
548 * compute s(x) at all! In all other cases, we compute s(x) from p(x)
549 * by evaluating (r^m)^k*p(r^m) for m=-1, m=0, and m=1. The p(x)
550 * polynomial is evaluated via the Horner scheme.
551 */
552static int compute_syndromes(unsigned long *data, int nblocks, unsigned long *s)
553{
554 unsigned long p[3];
555
556 set_parity(data, nblocks, p, 1);
557 if (p[0] | p[1] | p[2]) {
558 /* Some of the checked columns do not have a zero
559 * syndrome. For simplicity, we compute the syndromes
560 * for all columns that we have computed the
561 * remainders for.
562 */
563 s[0] = gfmul_exp_long(
564 gfadd_long(p[0],
565 gfmul_exp_long(
566 gfadd_long(p[1],
567 gfmul_exp_long(p[2], -1)),
568 -1)),
569 -nblocks);
570 s[1] = gfadd_long(gfadd_long(p[2], p[1]), p[0]);
571 s[2] = gfmul_exp_long(
572 gfadd_long(p[0],
573 gfmul_exp_long(
574 gfadd_long(p[1],
575 gfmul_exp_long(p[2], 1)),
576 1)),
577 nblocks);
578 return 0;
579 } else {
580 return 1;
581 }
582}
583
584
585/* Correct the block in the column pointed to by DATA. There are NBAD
586 * CRC errors and their indices are in BAD_LOC[0], up to
587 * BAD_LOC[NBAD-1]. If NBAD>1, Ainv holds the inverse of the matrix
588 * of the linear system that needs to be solved to determine the error
589 * magnitudes. S[0], S[1], and S[2] are the syndrome values. If row
590 * j gets corrected, then bit j will be set in CORRECTION_MAP.
591 */
592static inline int correct_block(__u8 *data, int nblocks,
593 int nbad, int *bad_loc, Matrix Ainv,
594 __u8 *s,
595 SectorMap * correction_map)
596{
597 int ncorrected = 0;
598 int i;
599 __u8 t1, t2;
600 __u8 c0, c1, c2; /* check bytes */
601 __u8 error_mag[3], log_error_mag;
602 __u8 *dp, l, e;
603 TRACE_FUN(ft_t_any);
604
605 switch (nbad) {
606 case 0:
607 /* might have a CRC failure: */
608 if (s[0] == 0) {
609 /* more than one error */
610 TRACE_ABORT(-1, ft_t_err,
611 "ECC failed (0 CRC errors, >1 CRC failures)");
612 }
613 t1 = gfdiv(s[1], s[0]);
614 if ((bad_loc[nbad++] = gflog[t1]) >= nblocks) {
615 TRACE(ft_t_err,
616 "ECC failed (0 CRC errors, >1 CRC failures)");
617 TRACE_ABORT(-1, ft_t_err,
618 "attempt to correct data at %d", bad_loc[0]);
619 }
620 error_mag[0] = s[1];
621 break;
622 case 1:
623 t1 = gfadd(gfmul_exp(s[1], bad_loc[0]), s[2]);
624 t2 = gfadd(gfmul_exp(s[0], bad_loc[0]), s[1]);
625 if (t1 == 0 && t2 == 0) {
626 /* one erasure, no error: */
627 Ainv[0][0] = gfpow[bad_loc[0]];
628 } else if (t1 == 0 || t2 == 0) {
629 /* one erasure and more than one error: */
630 TRACE_ABORT(-1, ft_t_err,
631 "ECC failed (1 erasure, >1 error)");
632 } else {
633 /* one erasure, one error: */
634 if ((bad_loc[nbad++] = gflog[gfdiv(t1, t2)])
635 >= nblocks) {
636 TRACE(ft_t_err, "ECC failed "
637 "(1 CRC errors, >1 CRC failures)");
638 TRACE_ABORT(-1, ft_t_err,
639 "attempt to correct data at %d",
640 bad_loc[1]);
641 }
642 if (!gfinv2(bad_loc[0], bad_loc[1], Ainv)) {
643 /* inversion failed---must have more
644 * than one error
645 */
646 TRACE_EXIT -1;
647 }
648 }
649 /* FALL THROUGH TO ERROR MAGNITUDE COMPUTATION:
650 */
651 case 2:
652 case 3:
653 /* compute error magnitudes: */
654 gfmat_mul(nbad, Ainv, s, error_mag);
655 break;
656
657 default:
658 TRACE_ABORT(-1, ft_t_err,
659 "Internal Error: number of CRC errors > 3");
660 }
661
662 /* Perform correction by adding ERROR_MAG[i] to the byte at
663 * offset BAD_LOC[i]. Also add the value of the computed
664 * error polynomial to the syndrome values. If the correction
665 * was successful, the resulting check bytes should be zero
666 * (i.e., the corrected data is a valid code word).
667 */
668 c0 = s[0];
669 c1 = s[1];
670 c2 = s[2];
671 for (i = 0; i < nbad; ++i) {
672 e = error_mag[i];
673 if (e) {
674 /* correct the byte at offset L by magnitude E: */
675 l = bad_loc[i];
676 dp = &data[l * FT_SECTOR_SIZE];
677 *dp = gfadd(*dp, e);
678 *correction_map |= 1 << l;
679 ++ncorrected;
680
681 log_error_mag = gflog[e];
682 c0 = gfadd(c0, gfpow[mod255(log_error_mag - l)]);
683 c1 = gfadd(c1, e);
684 c2 = gfadd(c2, gfpow[mod255(log_error_mag + l)]);
685 }
686 }
687 if (c0 || c1 || c2) {
688 TRACE_ABORT(-1, ft_t_err,
689 "ECC self-check failed, too many errors");
690 }
691 TRACE_EXIT ncorrected;
692}
693
694
695#if defined(ECC_SANITY_CHECK) || defined(ECC_PARANOID)
696
697/* Perform a sanity check on the computed parity bytes:
698 */
699static int sanity_check(unsigned long *data, int nblocks)
700{
701 TRACE_FUN(ft_t_any);
702 unsigned long s[3];
703
704 if (!compute_syndromes(data, nblocks, s)) {
705 TRACE_ABORT(0, ft_bug,
706 "Internal Error: syndrome self-check failed");
707 }
708 TRACE_EXIT 1;
709}
710
711#endif /* defined(ECC_SANITY_CHECK) || defined(ECC_PARANOID) */
712
713/* Compute the parity for an entire segment of data.
714 */
715int ftape_ecc_set_segment_parity(struct memory_segment *mseg)
716{
717 int i;
718 __u8 *parity_bytes;
719
720 parity_bytes = &mseg->data[(mseg->blocks - 3) * FT_SECTOR_SIZE];
721 for (i = 0; i < FT_SECTOR_SIZE; i += sizeof(long)) {
722 set_parity((unsigned long *) &mseg->data[i], mseg->blocks - 3,
723 (unsigned long *) &parity_bytes[i],
724 FT_SECTOR_SIZE / sizeof(long));
725#ifdef ECC_PARANOID
726 if (!sanity_check((unsigned long *) &mseg->data[i],
727 mseg->blocks)) {
728 return -1;
729 }
730#endif /* ECC_PARANOID */
731 }
732 return 0;
733}
734
735
736/* Checks and corrects (if possible) the segment MSEG. Returns one of
737 * ECC_OK, ECC_CORRECTED, and ECC_FAILED.
738 */
739int ftape_ecc_correct_data(struct memory_segment *mseg)
740{
741 int col, i, result;
742 int ncorrected = 0;
743 int nerasures = 0; /* # of erasures (CRC errors) */
744 int erasure_loc[3]; /* erasure locations */
745 unsigned long ss[3];
746 __u8 s[3];
747 Matrix Ainv;
748 TRACE_FUN(ft_t_flow);
749
750 mseg->corrected = 0;
751
752 /* find first column that has non-zero syndromes: */
753 for (col = 0; col < FT_SECTOR_SIZE; col += sizeof(long)) {
754 if (!compute_syndromes((unsigned long *) &mseg->data[col],
755 mseg->blocks, ss)) {
756 /* something is wrong---have to fix things */
757 break;
758 }
759 }
760 if (col >= FT_SECTOR_SIZE) {
761 /* all syndromes are ok, therefore nothing to correct */
762 TRACE_EXIT ECC_OK;
763 }
764 /* count the number of CRC errors if there were any: */
765 if (mseg->read_bad) {
766 for (i = 0; i < mseg->blocks; i++) {
767 if (BAD_CHECK(mseg->read_bad, i)) {
768 if (nerasures >= 3) {
769 /* this is too much for ECC */
770 TRACE_ABORT(ECC_FAILED, ft_t_err,
771 "ECC failed (>3 CRC errors)");
772 } /* if */
773 erasure_loc[nerasures++] = i;
774 }
775 }
776 }
777 /*
778 * If there are at least 2 CRC errors, determine inverse of matrix
779 * of linear system to be solved:
780 */
781 switch (nerasures) {
782 case 2:
783 if (!gfinv2(erasure_loc[0], erasure_loc[1], Ainv)) {
784 TRACE_EXIT ECC_FAILED;
785 }
786 break;
787 case 3:
788 if (!gfinv3(erasure_loc[0], erasure_loc[1],
789 erasure_loc[2], Ainv)) {
790 TRACE_EXIT ECC_FAILED;
791 }
792 break;
793 default:
794 /* this is not an error condition... */
795 break;
796 }
797
798 do {
799 for (i = 0; i < sizeof(long); ++i) {
800 s[0] = ss[0];
801 s[1] = ss[1];
802 s[2] = ss[2];
803 if (s[0] | s[1] | s[2]) {
804#ifdef BIG_ENDIAN
805 result = correct_block(
806 &mseg->data[col + sizeof(long) - 1 - i],
807 mseg->blocks,
808 nerasures,
809 erasure_loc,
810 Ainv,
811 s,
812 &mseg->corrected);
813#else
814 result = correct_block(&mseg->data[col + i],
815 mseg->blocks,
816 nerasures,
817 erasure_loc,
818 Ainv,
819 s,
820 &mseg->corrected);
821#endif
822 if (result < 0) {
823 TRACE_EXIT ECC_FAILED;
824 }
825 ncorrected += result;
826 }
827 ss[0] >>= 8;
828 ss[1] >>= 8;
829 ss[2] >>= 8;
830 }
831
832#ifdef ECC_SANITY_CHECK
833 if (!sanity_check((unsigned long *) &mseg->data[col],
834 mseg->blocks)) {
835 TRACE_EXIT ECC_FAILED;
836 }
837#endif /* ECC_SANITY_CHECK */
838
839 /* find next column with non-zero syndromes: */
840 while ((col += sizeof(long)) < FT_SECTOR_SIZE) {
841 if (!compute_syndromes((unsigned long *)
842 &mseg->data[col], mseg->blocks, ss)) {
843 /* something is wrong---have to fix things */
844 break;
845 }
846 }
847 } while (col < FT_SECTOR_SIZE);
848 if (ncorrected && nerasures == 0) {
849 TRACE(ft_t_warn, "block contained error not caught by CRC");
850 }
851 TRACE((ncorrected > 0) ? ft_t_noise : ft_t_any, "number of corrections: %d", ncorrected);
852 TRACE_EXIT ncorrected ? ECC_CORRECTED : ECC_OK;
853}
diff --git a/drivers/char/ftape/lowlevel/ftape-ecc.h b/drivers/char/ftape/lowlevel/ftape-ecc.h
deleted file mode 100644
index 4829146fe9a0..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-ecc.h
+++ /dev/null
@@ -1,84 +0,0 @@
1#ifndef _FTAPE_ECC_H_
2#define _FTAPE_ECC_H_
3
4/*
5 * Copyright (C) 1993 Ning and David Mosberger.
6 * Original:
7 * Copyright (C) 1993 Bas Laarhoven.
8 * Copyright (C) 1992 David L. Brown, Jr.
9
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
14
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; see the file COPYING. If not, write to
22 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
23 USA.
24
25 *
26 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-ecc.h,v $
27 * $Revision: 1.2 $
28 * $Date: 1997/10/05 19:18:11 $
29 *
30 * This file contains the definitions for the
31 * Reed-Solomon error correction code
32 * for the QIC-40/80 tape streamer device driver.
33 */
34
35#include "../lowlevel/ftape-bsm.h"
36
37#define BAD_CLEAR(entry) ((entry)=0)
38#define BAD_SET(entry,sector) ((entry)|=(1<<(sector)))
39#define BAD_CHECK(entry,sector) ((entry)&(1<<(sector)))
40
41/*
42 * Return values for ecc_correct_data:
43 */
44enum {
45 ECC_OK, /* Data was correct. */
46 ECC_CORRECTED, /* Correctable error in data. */
47 ECC_FAILED, /* Could not correct data. */
48};
49
50/*
51 * Representation of an in memory segment. MARKED_BAD lists the
52 * sectors that were marked bad during formatting. If the N-th sector
53 * in a segment is marked bad, bit 1<<N will be set in MARKED_BAD.
54 * The sectors should be read in from the disk and packed, as if the
55 * bad sectors were not there, and the segment just contained fewer
56 * sectors. READ_SECTORS is a bitmap of errors encountered while
57 * reading the data. These offsets are relative to the packed data.
58 * BLOCKS is a count of the sectors not marked bad. This is just to
59 * prevent having to count the zero bits in MARKED_BAD each time this
60 * is needed. DATA is the actual sector packed data from (or to) the
61 * tape.
62 */
63 struct memory_segment {
64 SectorMap marked_bad;
65 SectorMap read_bad;
66 int blocks;
67 __u8 *data;
68 SectorMap corrected;
69 };
70
71/*
72 * ecc.c defined global variables:
73 */
74#ifdef TEST
75extern int ftape_ecc_tracing;
76#endif
77
78/*
79 * ecc.c defined global functions:
80 */
81extern int ftape_ecc_correct_data(struct memory_segment *data);
82extern int ftape_ecc_set_segment_parity(struct memory_segment *data);
83
84#endif /* _FTAPE_ECC_H_ */
diff --git a/drivers/char/ftape/lowlevel/ftape-format.c b/drivers/char/ftape/lowlevel/ftape-format.c
deleted file mode 100644
index 5dd4c59a3f34..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-format.c
+++ /dev/null
@@ -1,344 +0,0 @@
1/*
2 * Copyright (C) 1997 Claus-Justus Heine.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 *
19 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-format.c,v $
20 * $Revision: 1.2.4.1 $
21 * $Date: 1997/11/14 16:05:39 $
22 *
23 * This file contains the code to support formatting of floppy
24 * tape cartridges with the QIC-40/80/3010/3020 floppy-tape
25 * driver "ftape" for Linux.
26 */
27
28#include <linux/string.h>
29#include <linux/errno.h>
30
31#include <linux/ftape.h>
32#include <linux/qic117.h>
33#include "../lowlevel/ftape-tracing.h"
34#include "../lowlevel/ftape-io.h"
35#include "../lowlevel/ftape-ctl.h"
36#include "../lowlevel/ftape-rw.h"
37#include "../lowlevel/ftape-ecc.h"
38#include "../lowlevel/ftape-bsm.h"
39#include "../lowlevel/ftape-format.h"
40
41#if defined(TESTING)
42#define FT_FMT_SEGS_PER_BUF 50
43#else
44#define FT_FMT_SEGS_PER_BUF (FT_BUFF_SIZE/(4*FT_SECTORS_PER_SEGMENT))
45#endif
46
47static spinlock_t ftape_format_lock;
48
49/*
50 * first segment of the new buffer
51 */
52static int switch_segment;
53
54/*
55 * at most 256 segments fit into one 32 kb buffer. Even TR-1 cartridges have
56 * more than this many segments per track, so better be careful.
57 *
58 * buffer_struct *buff: buffer to store the formatting coordinates in
59 * int start: starting segment for this buffer.
60 * int spt: segments per track
61 *
62 * Note: segment ids are relative to the start of the track here.
63 */
64static void setup_format_buffer(buffer_struct *buff, int start, int spt,
65 __u8 gap3)
66{
67 int to_do = spt - start;
68 TRACE_FUN(ft_t_flow);
69
70 if (to_do > FT_FMT_SEGS_PER_BUF) {
71 to_do = FT_FMT_SEGS_PER_BUF;
72 }
73 buff->ptr = buff->address;
74 buff->remaining = to_do * FT_SECTORS_PER_SEGMENT; /* # sectors */
75 buff->bytes = buff->remaining * 4; /* need 4 bytes per sector */
76 buff->gap3 = gap3;
77 buff->segment_id = start;
78 buff->next_segment = start + to_do;
79 if (buff->next_segment >= spt) {
80 buff->next_segment = 0; /* 0 means: stop runner */
81 }
82 buff->status = waiting; /* tells the isr that it can use
83 * this buffer
84 */
85 TRACE_EXIT;
86}
87
88
89/*
90 * start formatting a new track.
91 */
92int ftape_format_track(const unsigned int track, const __u8 gap3)
93{
94 unsigned long flags;
95 buffer_struct *tail, *head;
96 int status;
97 TRACE_FUN(ft_t_flow);
98
99 TRACE_CATCH(ftape_ready_wait(ftape_timeout.pause, &status),);
100 if (track & 1) {
101 if (!(status & QIC_STATUS_AT_EOT)) {
102 TRACE_CATCH(ftape_seek_to_eot(),);
103 }
104 } else {
105 if (!(status & QIC_STATUS_AT_BOT)) {
106 TRACE_CATCH(ftape_seek_to_bot(),);
107 }
108 }
109 ftape_abort_operation(); /* this sets ft_head = ft_tail = 0 */
110 ftape_set_state(formatting);
111
112 TRACE(ft_t_noise,
113 "Formatting track %d, logical: from segment %d to %d",
114 track, track * ft_segments_per_track,
115 (track + 1) * ft_segments_per_track - 1);
116
117 /*
118 * initialize the buffer switching protocol for this track
119 */
120 head = ftape_get_buffer(ft_queue_head); /* tape isn't running yet */
121 tail = ftape_get_buffer(ft_queue_tail); /* tape isn't running yet */
122 switch_segment = 0;
123 do {
124 FT_SIGNAL_EXIT(_DONT_BLOCK);
125 setup_format_buffer(tail, switch_segment,
126 ft_segments_per_track, gap3);
127 switch_segment = tail->next_segment;
128 } while ((switch_segment != 0) &&
129 ((tail = ftape_next_buffer(ft_queue_tail)) != head));
130 /* go */
131 head->status = formatting;
132 TRACE_CATCH(ftape_seek_head_to_track(track),);
133 TRACE_CATCH(ftape_command(QIC_LOGICAL_FORWARD),);
134 spin_lock_irqsave(&ftape_format_lock, flags);
135 TRACE_CATCH(fdc_setup_formatting(head), restore_flags(flags));
136 spin_unlock_irqrestore(&ftape_format_lock, flags);
137 TRACE_EXIT 0;
138}
139
140/* return segment id of segment currently being formatted and do the
141 * buffer switching stuff.
142 */
143int ftape_format_status(unsigned int *segment_id)
144{
145 buffer_struct *tail = ftape_get_buffer(ft_queue_tail);
146 int result;
147 TRACE_FUN(ft_t_flow);
148
149 while (switch_segment != 0 &&
150 ftape_get_buffer(ft_queue_head) != tail) {
151 FT_SIGNAL_EXIT(_DONT_BLOCK);
152 /* need more buffers, first wait for empty buffer
153 */
154 TRACE_CATCH(ftape_wait_segment(formatting),);
155 /* don't worry for gap3. If we ever hit this piece of code,
156 * then all buffer already have the correct gap3 set!
157 */
158 setup_format_buffer(tail, switch_segment,
159 ft_segments_per_track, tail->gap3);
160 switch_segment = tail->next_segment;
161 if (switch_segment != 0) {
162 tail = ftape_next_buffer(ft_queue_tail);
163 }
164 }
165 /* should runner stop ?
166 */
167 if (ft_runner_status == aborting || ft_runner_status == do_abort) {
168 buffer_struct *head = ftape_get_buffer(ft_queue_head);
169 TRACE(ft_t_warn, "Error formatting segment %d",
170 ftape_get_buffer(ft_queue_head)->segment_id);
171 (void)ftape_abort_operation();
172 TRACE_EXIT (head->status != error) ? -EAGAIN : -EIO;
173 }
174 /*
175 * don't care if the timer expires, this is just kind of a
176 * "select" operation that lets the calling process sleep
177 * until something has happened
178 */
179 if (fdc_interrupt_wait(5 * FT_SECOND) < 0) {
180 TRACE(ft_t_noise, "End of track %d at segment %d",
181 ft_location.track,
182 ftape_get_buffer(ft_queue_head)->segment_id);
183 result = 1; /* end of track, unlock module */
184 } else {
185 result = 0;
186 }
187 /*
188 * the calling process should use the seg id to determine
189 * which parts of the dma buffers can be safely overwritten
190 * with new data.
191 */
192 *segment_id = ftape_get_buffer(ft_queue_head)->segment_id;
193 /*
194 * Internally we start counting segment ids from the start of
195 * each track when formatting, but externally we keep them
196 * relative to the start of the tape:
197 */
198 *segment_id += ft_location.track * ft_segments_per_track;
199 TRACE_EXIT result;
200}
201
202/*
203 * The segment id is relative to the start of the tape
204 */
205int ftape_verify_segment(const unsigned int segment_id, SectorMap *bsm)
206{
207 int result;
208 int verify_done = 0;
209 TRACE_FUN(ft_t_flow);
210
211 TRACE(ft_t_noise, "Verifying segment %d", segment_id);
212
213 if (ft_driver_state != verifying) {
214 TRACE(ft_t_noise, "calling ftape_abort_operation");
215 if (ftape_abort_operation() < 0) {
216 TRACE(ft_t_err, "ftape_abort_operation failed");
217 TRACE_EXIT -EIO;
218 }
219 }
220 *bsm = 0x00000000;
221 ftape_set_state(verifying);
222 for (;;) {
223 buffer_struct *tail;
224 /*
225 * Allow escape from this loop on signal
226 */
227 FT_SIGNAL_EXIT(_DONT_BLOCK);
228 /*
229 * Search all full buffers for the first matching the
230 * wanted segment. Clear other buffers on the fly.
231 */
232 tail = ftape_get_buffer(ft_queue_tail);
233 while (!verify_done && tail->status == done) {
234 /*
235 * Allow escape from this loop on signal !
236 */
237 FT_SIGNAL_EXIT(_DONT_BLOCK);
238 if (tail->segment_id == segment_id) {
239 /* If out buffer is already full,
240 * return its contents.
241 */
242 TRACE(ft_t_flow, "found segment in cache: %d",
243 segment_id);
244 if ((tail->soft_error_map |
245 tail->hard_error_map) != 0) {
246 TRACE(ft_t_info,"bsm[%d] = 0x%08lx",
247 segment_id,
248 (unsigned long)
249 (tail->soft_error_map |
250 tail->hard_error_map));
251 *bsm = (tail->soft_error_map |
252 tail->hard_error_map);
253 }
254 verify_done = 1;
255 } else {
256 TRACE(ft_t_flow,"zapping segment in cache: %d",
257 tail->segment_id);
258 }
259 tail->status = waiting;
260 tail = ftape_next_buffer(ft_queue_tail);
261 }
262 if (!verify_done && tail->status == verifying) {
263 if (tail->segment_id == segment_id) {
264 switch(ftape_wait_segment(verifying)) {
265 case 0:
266 break;
267 case -EINTR:
268 TRACE_ABORT(-EINTR, ft_t_warn,
269 "interrupted by "
270 "non-blockable signal");
271 break;
272 default:
273 ftape_abort_operation();
274 ftape_set_state(verifying);
275 /* be picky */
276 TRACE_ABORT(-EIO, ft_t_warn,
277 "wait_segment failed");
278 }
279 } else {
280 /* We're reading the wrong segment,
281 * stop runner.
282 */
283 TRACE(ft_t_noise, "verifying wrong segment");
284 ftape_abort_operation();
285 ftape_set_state(verifying);
286 }
287 }
288 /* should runner stop ?
289 */
290 if (ft_runner_status == aborting) {
291 buffer_struct *head = ftape_get_buffer(ft_queue_head);
292 if (head->status == error ||
293 head->status == verifying) {
294 /* no data or overrun error */
295 head->status = waiting;
296 }
297 TRACE_CATCH(ftape_dumb_stop(),);
298 } else {
299 /* If just passed last segment on tape: wait
300 * for BOT or EOT mark. Sets ft_runner_status to
301 * idle if at lEOT and successful
302 */
303 TRACE_CATCH(ftape_handle_logical_eot(),);
304 }
305 if (verify_done) {
306 TRACE_EXIT 0;
307 }
308 /* Now at least one buffer is idle!
309 * Restart runner & tape if needed.
310 */
311 /* We could optimize the following a little bit. We know that
312 * the bad sector map is empty.
313 */
314 tail = ftape_get_buffer(ft_queue_tail);
315 if (tail->status == waiting) {
316 buffer_struct *head = ftape_get_buffer(ft_queue_head);
317
318 ftape_setup_new_segment(head, segment_id, -1);
319 ftape_calc_next_cluster(head);
320 if (ft_runner_status == idle) {
321 result = ftape_start_tape(segment_id,
322 head->sector_offset);
323 switch(result) {
324 case 0:
325 break;
326 case -ETIME:
327 case -EINTR:
328 TRACE_ABORT(result, ft_t_err, "Error: "
329 "segment %d unreachable",
330 segment_id);
331 break;
332 default:
333 *bsm = EMPTY_SEGMENT;
334 TRACE_EXIT 0;
335 break;
336 }
337 }
338 head->status = verifying;
339 fdc_setup_read_write(head, FDC_VERIFY);
340 }
341 }
342 /* not reached */
343 TRACE_EXIT -EIO;
344}
diff --git a/drivers/char/ftape/lowlevel/ftape-format.h b/drivers/char/ftape/lowlevel/ftape-format.h
deleted file mode 100644
index f15161566643..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-format.h
+++ /dev/null
@@ -1,37 +0,0 @@
1#ifndef _FTAPE_FORMAT_H
2#define _FTAPE_FORMAT_H
3
4/*
5 * Copyright (C) 1996-1997 Claus-Justus Heine.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 *
22 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-format.h,v $
23 * $Revision: 1.2 $
24 * $Date: 1997/10/05 19:18:13 $
25 *
26 * This file contains the low level definitions for the
27 * formatting support for the QIC-40/80/3010/3020 floppy-tape
28 * driver "ftape" for Linux.
29 */
30
31#ifdef __KERNEL__
32extern int ftape_format_track(const unsigned int track, const __u8 gap3);
33extern int ftape_format_status(unsigned int *segment_id);
34extern int ftape_verify_segment(const unsigned int segment_id, SectorMap *bsm);
35#endif /* __KERNEL__ */
36
37#endif
diff --git a/drivers/char/ftape/lowlevel/ftape-init.c b/drivers/char/ftape/lowlevel/ftape-init.c
deleted file mode 100644
index 4998132a81d1..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-init.c
+++ /dev/null
@@ -1,160 +0,0 @@
1/*
2 * Copyright (C) 1993-1996 Bas Laarhoven,
3 * (C) 1996-1997 Claus-Justus Heine.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 *
20 * This file contains the code that interfaces the kernel
21 * for the QIC-40/80/3010/3020 floppy-tape driver for Linux.
22 */
23
24#include <linux/module.h>
25#include <linux/errno.h>
26#include <linux/fs.h>
27#include <linux/kernel.h>
28#include <linux/signal.h>
29#include <linux/major.h>
30
31#include <linux/ftape.h>
32#include <linux/init.h>
33#include <linux/qic117.h>
34#ifdef CONFIG_ZFTAPE
35#include <linux/zftape.h>
36#endif
37
38#include "../lowlevel/ftape-init.h"
39#include "../lowlevel/ftape-io.h"
40#include "../lowlevel/ftape-read.h"
41#include "../lowlevel/ftape-write.h"
42#include "../lowlevel/ftape-ctl.h"
43#include "../lowlevel/ftape-rw.h"
44#include "../lowlevel/fdc-io.h"
45#include "../lowlevel/ftape-buffer.h"
46#include "../lowlevel/ftape-proc.h"
47#include "../lowlevel/ftape-tracing.h"
48
49
50#if defined(MODULE) && !defined(CONFIG_FT_NO_TRACE_AT_ALL)
51static int ft_tracing = -1;
52#endif
53
54
55/* Called by modules package when installing the driver
56 * or by kernel during the initialization phase
57 */
58static int __init ftape_init(void)
59{
60 TRACE_FUN(ft_t_flow);
61
62#ifdef MODULE
63#ifndef CONFIG_FT_NO_TRACE_AT_ALL
64 if (ft_tracing != -1) {
65 ftape_tracing = ft_tracing;
66 }
67#endif
68 printk(KERN_INFO FTAPE_VERSION "\n");
69 if (TRACE_LEVEL >= ft_t_info) {
70 printk(
71KERN_INFO "(c) 1993-1996 Bas Laarhoven (bas@vimec.nl)\n"
72KERN_INFO "(c) 1995-1996 Kai Harrekilde-Petersen (khp@dolphinics.no)\n"
73KERN_INFO "(c) 1996-1997 Claus-Justus Heine (claus@momo.math.rwth-aachen.de)\n"
74KERN_INFO "QIC-117 driver for QIC-40/80/3010/3020 floppy tape drives\n");
75 }
76#else /* !MODULE */
77 /* print a short no-nonsense boot message */
78 printk(KERN_INFO FTAPE_VERSION "\n");
79#endif /* MODULE */
80 TRACE(ft_t_info, "installing QIC-117 floppy tape hardware drive ... ");
81 TRACE(ft_t_info, "ftape_init @ 0x%p", ftape_init);
82 /* Allocate the DMA buffers. They are deallocated at cleanup() time.
83 */
84#ifdef TESTING
85#ifdef MODULE
86 while (ftape_set_nr_buffers(CONFIG_FT_NR_BUFFERS) < 0) {
87 ftape_sleep(FT_SECOND/20);
88 if (signal_pending(current)) {
89 (void)ftape_set_nr_buffers(0);
90 TRACE(ft_t_bug,
91 "Killed by signal while allocating buffers.");
92 TRACE_ABORT(-EINTR,
93 ft_t_bug, "Free up memory and retry");
94 }
95 }
96#else
97 TRACE_CATCH(ftape_set_nr_buffers(CONFIG_FT_NR_BUFFERS),
98 (void)ftape_set_nr_buffers(0));
99#endif
100#else
101 TRACE_CATCH(ftape_set_nr_buffers(CONFIG_FT_NR_BUFFERS),
102 (void)ftape_set_nr_buffers(0));
103#endif
104 ft_drive_sel = -1;
105 ft_failure = 1; /* inhibit any operation but open */
106 ftape_udelay_calibrate(); /* must be before fdc_wait_calibrate ! */
107 fdc_wait_calibrate();
108#if defined(CONFIG_PROC_FS) && defined(CONFIG_FT_PROC_FS)
109 (void)ftape_proc_init();
110#endif
111#ifdef CONFIG_ZFTAPE
112 (void)zft_init();
113#endif
114 TRACE_EXIT 0;
115}
116
117module_param(ft_fdc_base, uint, 0);
118MODULE_PARM_DESC(ft_fdc_base, "Base address of FDC controller.");
119module_param(ft_fdc_irq, uint, 0);
120MODULE_PARM_DESC(ft_fdc_irq, "IRQ (interrupt channel) to use.");
121module_param(ft_fdc_dma, uint, 0);
122MODULE_PARM_DESC(ft_fdc_dma, "DMA channel to use.");
123module_param(ft_fdc_threshold, uint, 0);
124MODULE_PARM_DESC(ft_fdc_threshold, "Threshold of the FDC Fifo.");
125module_param(ft_fdc_rate_limit, uint, 0);
126MODULE_PARM_DESC(ft_fdc_rate_limit, "Maximal data rate for FDC.");
127module_param(ft_probe_fc10, bool, 0);
128MODULE_PARM_DESC(ft_probe_fc10,
129 "If non-zero, probe for a Colorado FC-10/FC-20 controller.");
130module_param(ft_mach2, bool, 0);
131MODULE_PARM_DESC(ft_mach2,
132 "If non-zero, probe for a Mountain MACH-2 controller.");
133#if defined(MODULE) && !defined(CONFIG_FT_NO_TRACE_AT_ALL)
134module_param(ft_tracing, int, 0644);
135MODULE_PARM_DESC(ft_tracing,
136 "Amount of debugging output, 0 <= tracing <= 8, default 3.");
137#endif
138
139MODULE_AUTHOR(
140 "(c) 1993-1996 Bas Laarhoven (bas@vimec.nl), "
141 "(c) 1995-1996 Kai Harrekilde-Petersen (khp@dolphinics.no), "
142 "(c) 1996, 1997 Claus-Justus Heine (claus@momo.math.rwth-aachen.de)");
143MODULE_DESCRIPTION(
144 "QIC-117 driver for QIC-40/80/3010/3020 floppy tape drives.");
145MODULE_LICENSE("GPL");
146
147static void __exit ftape_exit(void)
148{
149 TRACE_FUN(ft_t_flow);
150
151#if defined(CONFIG_PROC_FS) && defined(CONFIG_FT_PROC_FS)
152 ftape_proc_destroy();
153#endif
154 (void)ftape_set_nr_buffers(0);
155 printk(KERN_INFO "ftape: unloaded.\n");
156 TRACE_EXIT;
157}
158
159module_init(ftape_init);
160module_exit(ftape_exit);
diff --git a/drivers/char/ftape/lowlevel/ftape-init.h b/drivers/char/ftape/lowlevel/ftape-init.h
deleted file mode 100644
index 99a7b8ab086f..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-init.h
+++ /dev/null
@@ -1,43 +0,0 @@
1#ifndef _FTAPE_INIT_H
2#define _FTAPE_INIT_H
3
4/*
5 * Copyright (C) 1993-1996 Bas Laarhoven,
6 * (C) 1996-1997 Claus-Justus Heine.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 *
23 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-init.h,v $
24 * $Revision: 1.2 $
25 * $Date: 1997/10/05 19:18:16 $
26 *
27 * This file contains the definitions for the interface to
28 * the Linux kernel for floppy tape driver ftape.
29 *
30 */
31
32#include <linux/linkage.h>
33#include <linux/signal.h>
34
35#define _NEVER_BLOCK (sigmask(SIGKILL) | sigmask(SIGSTOP))
36#define _DONT_BLOCK (_NEVER_BLOCK | sigmask(SIGINT))
37#define _DO_BLOCK (sigmask(SIGPIPE))
38
39#ifndef QIC117_TAPE_MAJOR
40#define QIC117_TAPE_MAJOR 27
41#endif
42
43#endif
diff --git a/drivers/char/ftape/lowlevel/ftape-io.c b/drivers/char/ftape/lowlevel/ftape-io.c
deleted file mode 100644
index 259015aeff55..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-io.c
+++ /dev/null
@@ -1,992 +0,0 @@
1/*
2 * Copyright (C) 1993-1996 Bas Laarhoven,
3 * (C) 1996 Kai Harrekilde-Petersen,
4 * (C) 1997 Claus-Justus Heine.
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, or (at your option)
9 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; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 *
21 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-io.c,v $
22 * $Revision: 1.4 $
23 * $Date: 1997/11/11 14:02:36 $
24 *
25 * This file contains the general control functions for the
26 * QIC-40/80/3010/3020 floppy-tape driver "ftape" for Linux.
27 */
28
29#include <linux/errno.h>
30#include <linux/sched.h>
31#include <linux/mm.h>
32#include <asm/system.h>
33#include <linux/ioctl.h>
34#include <linux/mtio.h>
35#include <linux/delay.h>
36
37#include <linux/ftape.h>
38#include <linux/qic117.h>
39#include "../lowlevel/ftape-tracing.h"
40#include "../lowlevel/fdc-io.h"
41#include "../lowlevel/ftape-io.h"
42#include "../lowlevel/ftape-ctl.h"
43#include "../lowlevel/ftape-rw.h"
44#include "../lowlevel/ftape-write.h"
45#include "../lowlevel/ftape-read.h"
46#include "../lowlevel/ftape-init.h"
47#include "../lowlevel/ftape-calibr.h"
48
49/* Global vars.
50 */
51/* NOTE: sectors start numbering at 1, all others at 0 ! */
52ft_timeout_table ftape_timeout;
53unsigned int ftape_tape_len;
54volatile qic117_cmd_t ftape_current_command;
55const struct qic117_command_table qic117_cmds[] = QIC117_COMMANDS;
56int ftape_might_be_off_track;
57
58/* Local vars.
59 */
60static int diagnostic_mode;
61static unsigned int ftape_udelay_count;
62static unsigned int ftape_udelay_time;
63
64void ftape_udelay(unsigned int usecs)
65{
66 volatile int count = (ftape_udelay_count * usecs +
67 ftape_udelay_count - 1) / ftape_udelay_time;
68 volatile int i;
69
70 while (count-- > 0) {
71 for (i = 0; i < 20; ++i);
72 }
73}
74
75void ftape_udelay_calibrate(void)
76{
77 ftape_calibrate("ftape_udelay",
78 ftape_udelay, &ftape_udelay_count, &ftape_udelay_time);
79}
80
81/* Delay (msec) routine.
82 */
83void ftape_sleep(unsigned int time)
84{
85 TRACE_FUN(ft_t_any);
86
87 time *= 1000; /* msecs -> usecs */
88 if (time < FT_USPT) {
89 /* Time too small for scheduler, do a busy wait ! */
90 ftape_udelay(time);
91 } else {
92 long timeout;
93 unsigned long flags;
94 unsigned int ticks = (time + FT_USPT - 1) / FT_USPT;
95
96 TRACE(ft_t_any, "%d msec, %d ticks", time/1000, ticks);
97 timeout = ticks;
98 save_flags(flags);
99 sti();
100 msleep_interruptible(jiffies_to_msecs(timeout));
101 /* Mmm. Isn't current->blocked == 0xffffffff ?
102 */
103 if (signal_pending(current)) {
104 TRACE(ft_t_err, "awoken by non-blocked signal :-(");
105 }
106 restore_flags(flags);
107 }
108 TRACE_EXIT;
109}
110
111/* send a command or parameter to the drive
112 * Generates # of step pulses.
113 */
114static inline int ft_send_to_drive(int arg)
115{
116 /* Always wait for a command_timeout period to separate
117 * individuals commands and/or parameters.
118 */
119 ftape_sleep(3 * FT_MILLISECOND);
120 /* Keep cylinder nr within range, step towards home if possible.
121 */
122 if (ftape_current_cylinder >= arg) {
123 return fdc_seek(ftape_current_cylinder - arg);
124 } else {
125 return fdc_seek(ftape_current_cylinder + arg);
126 }
127}
128
129/* forward */ int ftape_report_raw_drive_status(int *status);
130
131static int ft_check_cmd_restrictions(qic117_cmd_t command)
132{
133 int status = -1;
134 TRACE_FUN(ft_t_any);
135
136 TRACE(ft_t_flow, "%s", qic117_cmds[command].name);
137 /* A new motion command during an uninterruptible (motion)
138 * command requires a ready status before the new command can
139 * be issued. Otherwise a new motion command needs to be
140 * checked against required status.
141 */
142 if (qic117_cmds[command].cmd_type == motion &&
143 qic117_cmds[ftape_current_command].non_intr) {
144 ftape_report_raw_drive_status(&status);
145 if ((status & QIC_STATUS_READY) == 0) {
146 TRACE(ft_t_noise,
147 "motion cmd (%d) during non-intr cmd (%d)",
148 command, ftape_current_command);
149 TRACE(ft_t_noise, "waiting until drive gets ready");
150 ftape_ready_wait(ftape_timeout.seek,
151 &status);
152 }
153 }
154 if (qic117_cmds[command].mask != 0) {
155 __u8 difference;
156 /* Some commands do require a certain status:
157 */
158 if (status == -1) { /* not yet set */
159 ftape_report_raw_drive_status(&status);
160 }
161 difference = ((status ^ qic117_cmds[command].state) &
162 qic117_cmds[command].mask);
163 /* Wait until the drive gets
164 * ready. This may last forever if
165 * the drive never gets ready...
166 */
167 while ((difference & QIC_STATUS_READY) != 0) {
168 TRACE(ft_t_noise, "command %d issued while not ready",
169 command);
170 TRACE(ft_t_noise, "waiting until drive gets ready");
171 if (ftape_ready_wait(ftape_timeout.seek,
172 &status) == -EINTR) {
173 /* Bail out on signal !
174 */
175 TRACE_ABORT(-EINTR, ft_t_warn,
176 "interrupted by non-blockable signal");
177 }
178 difference = ((status ^ qic117_cmds[command].state) &
179 qic117_cmds[command].mask);
180 }
181 while ((difference & QIC_STATUS_ERROR) != 0) {
182 int err;
183 qic117_cmd_t cmd;
184
185 TRACE(ft_t_noise,
186 "command %d issued while error pending",
187 command);
188 TRACE(ft_t_noise, "clearing error status");
189 ftape_report_error(&err, &cmd, 1);
190 ftape_report_raw_drive_status(&status);
191 difference = ((status ^ qic117_cmds[command].state) &
192 qic117_cmds[command].mask);
193 if ((difference & QIC_STATUS_ERROR) != 0) {
194 /* Bail out on fatal signal !
195 */
196 FT_SIGNAL_EXIT(_NEVER_BLOCK);
197 }
198 }
199 if (difference) {
200 /* Any remaining difference can't be solved
201 * here.
202 */
203 if (difference & (QIC_STATUS_CARTRIDGE_PRESENT |
204 QIC_STATUS_NEW_CARTRIDGE |
205 QIC_STATUS_REFERENCED)) {
206 TRACE(ft_t_warn,
207 "Fatal: tape removed or reinserted !");
208 ft_failure = 1;
209 } else {
210 TRACE(ft_t_err, "wrong state: 0x%02x should be: 0x%02x",
211 status & qic117_cmds[command].mask,
212 qic117_cmds[command].state);
213 }
214 TRACE_EXIT -EIO;
215 }
216 if (~status & QIC_STATUS_READY & qic117_cmds[command].mask) {
217 TRACE_ABORT(-EBUSY, ft_t_err, "Bad: still busy!");
218 }
219 }
220 TRACE_EXIT 0;
221}
222
223/* Issue a tape command:
224 */
225int ftape_command(qic117_cmd_t command)
226{
227 int result = 0;
228 static int level;
229 TRACE_FUN(ft_t_any);
230
231 if ((unsigned int)command > NR_ITEMS(qic117_cmds)) {
232 /* This is a bug we'll want to know about too.
233 */
234 TRACE_ABORT(-EIO, ft_t_bug, "bug - bad command: %d", command);
235 }
236 if (++level > 5) { /* This is a bug we'll want to know about. */
237 --level;
238 TRACE_ABORT(-EIO, ft_t_bug, "bug - recursion for command: %d",
239 command);
240 }
241 /* disable logging and restriction check for some commands,
242 * check all other commands that have a prescribed starting
243 * status.
244 */
245 if (diagnostic_mode) {
246 TRACE(ft_t_flow, "diagnostic command %d", command);
247 } else if (command == QIC_REPORT_DRIVE_STATUS ||
248 command == QIC_REPORT_NEXT_BIT) {
249 TRACE(ft_t_any, "%s", qic117_cmds[command].name);
250 } else {
251 TRACE_CATCH(ft_check_cmd_restrictions(command), --level);
252 }
253 /* Now all conditions are met or result was < 0.
254 */
255 result = ft_send_to_drive((unsigned int)command);
256 if (qic117_cmds[command].cmd_type == motion &&
257 command != QIC_LOGICAL_FORWARD && command != QIC_STOP_TAPE) {
258 ft_location.known = 0;
259 }
260 ftape_current_command = command;
261 --level;
262 TRACE_EXIT result;
263}
264
265/* Send a tape command parameter:
266 * Generates command # of step pulses.
267 * Skips tape-status call !
268 */
269int ftape_parameter(unsigned int parameter)
270{
271 TRACE_FUN(ft_t_any);
272
273 TRACE(ft_t_flow, "called with parameter = %d", parameter);
274 TRACE_EXIT ft_send_to_drive(parameter + 2);
275}
276
277/* Wait for the drive to get ready.
278 * timeout time in milli-seconds
279 * Returned status is valid if result != -EIO
280 *
281 * Should we allow to be killed by SIGINT? (^C)
282 * Would be nice at least for large timeouts.
283 */
284int ftape_ready_wait(unsigned int timeout, int *status)
285{
286 unsigned long t0;
287 unsigned int poll_delay;
288 int signal_retries;
289 TRACE_FUN(ft_t_any);
290
291 /* the following ** REALLY ** reduces the system load when
292 * e.g. one simply rewinds or retensions. The tape is slow
293 * anyway. It is really not necessary to detect error
294 * conditions with 1/10 seconds granularity
295 *
296 * On my AMD 133MHZ 486: 100 ms: 23% system load
297 * 1 sec: 5%
298 * 5 sec: 0.6%, yeah
299 */
300 if (timeout <= FT_SECOND) {
301 poll_delay = 100 * FT_MILLISECOND;
302 signal_retries = 20; /* two seconds */
303 } else if (timeout < 20 * FT_SECOND) {
304 TRACE(ft_t_flow, "setting poll delay to 1 second");
305 poll_delay = FT_SECOND;
306 signal_retries = 2; /* two seconds */
307 } else {
308 TRACE(ft_t_flow, "setting poll delay to 5 seconds");
309 poll_delay = 5 * FT_SECOND;
310 signal_retries = 1; /* five seconds */
311 }
312 for (;;) {
313 t0 = jiffies;
314 TRACE_CATCH(ftape_report_raw_drive_status(status),);
315 if (*status & QIC_STATUS_READY) {
316 TRACE_EXIT 0;
317 }
318 if (!signal_retries--) {
319 FT_SIGNAL_EXIT(_NEVER_BLOCK);
320 }
321 if ((int)timeout >= 0) {
322 /* this will fail when jiffies wraps around about
323 * once every year :-)
324 */
325 timeout -= ((jiffies - t0) * FT_SECOND) / HZ;
326 if (timeout <= 0) {
327 TRACE_ABORT(-ETIME, ft_t_err, "timeout");
328 }
329 ftape_sleep(poll_delay);
330 timeout -= poll_delay;
331 } else {
332 ftape_sleep(poll_delay);
333 }
334 }
335 TRACE_EXIT -ETIME;
336}
337
338/* Issue command and wait up to timeout milli seconds for drive ready
339 */
340int ftape_command_wait(qic117_cmd_t command, unsigned int timeout, int *status)
341{
342 int result;
343
344 /* Drive should be ready, issue command
345 */
346 result = ftape_command(command);
347 if (result >= 0) {
348 result = ftape_ready_wait(timeout, status);
349 }
350 return result;
351}
352
353static int ftape_parameter_wait(unsigned int parm, unsigned int timeout, int *status)
354{
355 int result;
356
357 /* Drive should be ready, issue command
358 */
359 result = ftape_parameter(parm);
360 if (result >= 0) {
361 result = ftape_ready_wait(timeout, status);
362 }
363 return result;
364}
365
366/*--------------------------------------------------------------------------
367 * Report operations
368 */
369
370/* Query the drive about its status. The command is sent and
371 result_length bits of status are returned (2 extra bits are read
372 for start and stop). */
373
374int ftape_report_operation(int *status,
375 qic117_cmd_t command,
376 int result_length)
377{
378 int i, st3;
379 unsigned int t0;
380 unsigned int dt;
381 TRACE_FUN(ft_t_any);
382
383 TRACE_CATCH(ftape_command(command),);
384 t0 = ftape_timestamp();
385 i = 0;
386 do {
387 ++i;
388 ftape_sleep(3 * FT_MILLISECOND); /* see remark below */
389 TRACE_CATCH(fdc_sense_drive_status(&st3),);
390 dt = ftape_timediff(t0, ftape_timestamp());
391 /* Ack should be asserted within Ttimout + Tack = 6 msec.
392 * Looks like some drives fail to do this so extend this
393 * period to 300 msec.
394 */
395 } while (!(st3 & ST3_TRACK_0) && dt < 300000);
396 if (!(st3 & ST3_TRACK_0)) {
397 TRACE(ft_t_err,
398 "No acknowledge after %u msec. (%i iter)", dt / 1000, i);
399 TRACE_ABORT(-EIO, ft_t_err, "timeout on Acknowledge");
400 }
401 /* dt may be larger than expected because of other tasks
402 * scheduled while we were sleeping.
403 */
404 if (i > 1 && dt > 6000) {
405 TRACE(ft_t_err, "Acknowledge after %u msec. (%i iter)",
406 dt / 1000, i);
407 }
408 *status = 0;
409 for (i = 0; i < result_length + 1; i++) {
410 TRACE_CATCH(ftape_command(QIC_REPORT_NEXT_BIT),);
411 TRACE_CATCH(fdc_sense_drive_status(&st3),);
412 if (i < result_length) {
413 *status |= ((st3 & ST3_TRACK_0) ? 1 : 0) << i;
414 } else if ((st3 & ST3_TRACK_0) == 0) {
415 TRACE_ABORT(-EIO, ft_t_err, "missing status stop bit");
416 }
417 }
418 /* this command will put track zero and index back into normal state */
419 (void)ftape_command(QIC_REPORT_NEXT_BIT);
420 TRACE_EXIT 0;
421}
422
423/* Report the current drive status. */
424
425int ftape_report_raw_drive_status(int *status)
426{
427 int result;
428 int count = 0;
429 TRACE_FUN(ft_t_any);
430
431 do {
432 result = ftape_report_operation(status,
433 QIC_REPORT_DRIVE_STATUS, 8);
434 } while (result < 0 && ++count <= 3);
435 if (result < 0) {
436 TRACE_ABORT(-EIO, ft_t_err,
437 "report_operation failed after %d trials", count);
438 }
439 if ((*status & 0xff) == 0xff) {
440 TRACE_ABORT(-EIO, ft_t_err,
441 "impossible drive status 0xff");
442 }
443 if (*status & QIC_STATUS_READY) {
444 ftape_current_command = QIC_NO_COMMAND; /* completed */
445 }
446 ft_last_status.status.drive_status = (__u8)(*status & 0xff);
447 TRACE_EXIT 0;
448}
449
450int ftape_report_drive_status(int *status)
451{
452 TRACE_FUN(ft_t_any);
453
454 TRACE_CATCH(ftape_report_raw_drive_status(status),);
455 if (*status & QIC_STATUS_NEW_CARTRIDGE ||
456 !(*status & QIC_STATUS_CARTRIDGE_PRESENT)) {
457 ft_failure = 1; /* will inhibit further operations */
458 TRACE_EXIT -EIO;
459 }
460 if (*status & QIC_STATUS_READY && *status & QIC_STATUS_ERROR) {
461 /* Let caller handle all errors */
462 TRACE_ABORT(1, ft_t_warn, "warning: error status set!");
463 }
464 TRACE_EXIT 0;
465}
466
467int ftape_report_error(unsigned int *error,
468 qic117_cmd_t *command, int report)
469{
470 static const ftape_error ftape_errors[] = QIC117_ERRORS;
471 int code;
472 TRACE_FUN(ft_t_any);
473
474 TRACE_CATCH(ftape_report_operation(&code, QIC_REPORT_ERROR_CODE, 16),);
475 *error = (unsigned int)(code & 0xff);
476 *command = (qic117_cmd_t)((code>>8)&0xff);
477 /* remember hardware status, maybe useful for status ioctls
478 */
479 ft_last_error.error.command = (__u8)*command;
480 ft_last_error.error.error = (__u8)*error;
481 if (!report) {
482 TRACE_EXIT 0;
483 }
484 if (*error == 0) {
485 TRACE_ABORT(0, ft_t_info, "No error");
486 }
487 TRACE(ft_t_info, "errorcode: %d", *error);
488 if (*error < NR_ITEMS(ftape_errors)) {
489 TRACE(ft_t_noise, "%sFatal ERROR:",
490 (ftape_errors[*error].fatal ? "" : "Non-"));
491 TRACE(ft_t_noise, "%s ...", ftape_errors[*error].message);
492 } else {
493 TRACE(ft_t_noise, "Unknown ERROR !");
494 }
495 if ((unsigned int)*command < NR_ITEMS(qic117_cmds) &&
496 qic117_cmds[*command].name != NULL) {
497 TRACE(ft_t_noise, "... caused by command \'%s\'",
498 qic117_cmds[*command].name);
499 } else {
500 TRACE(ft_t_noise, "... caused by unknown command %d",
501 *command);
502 }
503 TRACE_EXIT 0;
504}
505
506int ftape_report_configuration(qic_model *model,
507 unsigned int *rate,
508 int *qic_std,
509 int *tape_len)
510{
511 int result;
512 int config;
513 int status;
514 static const unsigned int qic_rates[ 4] = { 250, 2000, 500, 1000 };
515 TRACE_FUN(ft_t_any);
516
517 result = ftape_report_operation(&config,
518 QIC_REPORT_DRIVE_CONFIGURATION, 8);
519 if (result < 0) {
520 ft_last_status.status.drive_config = (__u8)0x00;
521 *model = prehistoric;
522 *rate = 500;
523 *qic_std = QIC_TAPE_QIC40;
524 *tape_len = 205;
525 TRACE_EXIT 0;
526 } else {
527 ft_last_status.status.drive_config = (__u8)(config & 0xff);
528 }
529 *rate = qic_rates[(config & QIC_CONFIG_RATE_MASK) >> QIC_CONFIG_RATE_SHIFT];
530 result = ftape_report_operation(&status, QIC_REPORT_TAPE_STATUS, 8);
531 if (result < 0) {
532 ft_last_status.status.tape_status = (__u8)0x00;
533 /* pre- QIC117 rev C spec. drive, QIC_CONFIG_80 bit is valid.
534 */
535 *qic_std = (config & QIC_CONFIG_80) ?
536 QIC_TAPE_QIC80 : QIC_TAPE_QIC40;
537 /* ?? how's about 425ft tapes? */
538 *tape_len = (config & QIC_CONFIG_LONG) ? 307 : 0;
539 *model = pre_qic117c;
540 result = 0;
541 } else {
542 ft_last_status.status.tape_status = (__u8)(status & 0xff);
543 *model = post_qic117b;
544 TRACE(ft_t_any, "report tape status result = %02x", status);
545 /* post- QIC117 rev C spec. drive, QIC_CONFIG_80 bit is
546 * invalid.
547 */
548 switch (status & QIC_TAPE_STD_MASK) {
549 case QIC_TAPE_QIC40:
550 case QIC_TAPE_QIC80:
551 case QIC_TAPE_QIC3020:
552 case QIC_TAPE_QIC3010:
553 *qic_std = status & QIC_TAPE_STD_MASK;
554 break;
555 default:
556 *qic_std = -1;
557 break;
558 }
559 switch (status & QIC_TAPE_LEN_MASK) {
560 case QIC_TAPE_205FT:
561 /* 205 or 425+ ft 550 Oe tape */
562 *tape_len = 0;
563 break;
564 case QIC_TAPE_307FT:
565 /* 307.5 ft 550 Oe Extended Length (XL) tape */
566 *tape_len = 307;
567 break;
568 case QIC_TAPE_VARIABLE:
569 /* Variable length 550 Oe tape */
570 *tape_len = 0;
571 break;
572 case QIC_TAPE_1100FT:
573 /* 1100 ft 550 Oe tape */
574 *tape_len = 1100;
575 break;
576 case QIC_TAPE_FLEX:
577 /* Variable length 900 Oe tape */
578 *tape_len = 0;
579 break;
580 default:
581 *tape_len = -1;
582 break;
583 }
584 if (*qic_std == -1 || *tape_len == -1) {
585 TRACE(ft_t_any,
586 "post qic-117b spec drive with unknown tape");
587 }
588 result = *tape_len == -1 ? -EIO : 0;
589 if (status & QIC_TAPE_WIDE) {
590 switch (*qic_std) {
591 case QIC_TAPE_QIC80:
592 TRACE(ft_t_info, "TR-1 tape detected");
593 break;
594 case QIC_TAPE_QIC3010:
595 TRACE(ft_t_info, "TR-2 tape detected");
596 break;
597 case QIC_TAPE_QIC3020:
598 TRACE(ft_t_info, "TR-3 tape detected");
599 break;
600 default:
601 TRACE(ft_t_warn,
602 "Unknown Travan tape type detected");
603 break;
604 }
605 }
606 }
607 TRACE_EXIT (result < 0) ? -EIO : 0;
608}
609
610static int ftape_report_rom_version(int *version)
611{
612
613 if (ftape_report_operation(version, QIC_REPORT_ROM_VERSION, 8) < 0) {
614 return -EIO;
615 } else {
616 return 0;
617 }
618}
619
620void ftape_report_vendor_id(unsigned int *id)
621{
622 int result;
623 TRACE_FUN(ft_t_any);
624
625 /* We'll try to get a vendor id from the drive. First
626 * according to the QIC-117 spec, a 16-bit id is requested.
627 * If that fails we'll try an 8-bit version, otherwise we'll
628 * try an undocumented query.
629 */
630 result = ftape_report_operation((int *) id, QIC_REPORT_VENDOR_ID, 16);
631 if (result < 0) {
632 result = ftape_report_operation((int *) id,
633 QIC_REPORT_VENDOR_ID, 8);
634 if (result < 0) {
635 /* The following is an undocumented call found
636 * in the CMS code.
637 */
638 result = ftape_report_operation((int *) id, 24, 8);
639 if (result < 0) {
640 *id = UNKNOWN_VENDOR;
641 } else {
642 TRACE(ft_t_noise, "got old 8 bit id: %04x",
643 *id);
644 *id |= 0x20000;
645 }
646 } else {
647 TRACE(ft_t_noise, "got 8 bit id: %04x", *id);
648 *id |= 0x10000;
649 }
650 } else {
651 TRACE(ft_t_noise, "got 16 bit id: %04x", *id);
652 }
653 if (*id == 0x0047) {
654 int version;
655 int sign;
656
657 if (ftape_report_rom_version(&version) < 0) {
658 TRACE(ft_t_bug, "report rom version failed");
659 TRACE_EXIT;
660 }
661 TRACE(ft_t_noise, "CMS rom version: %d", version);
662 ftape_command(QIC_ENTER_DIAGNOSTIC_1);
663 ftape_command(QIC_ENTER_DIAGNOSTIC_1);
664 diagnostic_mode = 1;
665 if (ftape_report_operation(&sign, 9, 8) < 0) {
666 unsigned int error;
667 qic117_cmd_t command;
668
669 ftape_report_error(&error, &command, 1);
670 ftape_command(QIC_ENTER_PRIMARY_MODE);
671 diagnostic_mode = 0;
672 TRACE_EXIT; /* failure ! */
673 } else {
674 TRACE(ft_t_noise, "CMS signature: %02x", sign);
675 }
676 if (sign == 0xa5) {
677 result = ftape_report_operation(&sign, 37, 8);
678 if (result < 0) {
679 if (version >= 63) {
680 *id = 0x8880;
681 TRACE(ft_t_noise,
682 "This is an Iomega drive !");
683 } else {
684 *id = 0x0047;
685 TRACE(ft_t_noise,
686 "This is a real CMS drive !");
687 }
688 } else {
689 *id = 0x0047;
690 TRACE(ft_t_noise, "CMS status: %d", sign);
691 }
692 } else {
693 *id = UNKNOWN_VENDOR;
694 }
695 ftape_command(QIC_ENTER_PRIMARY_MODE);
696 diagnostic_mode = 0;
697 }
698 TRACE_EXIT;
699}
700
701static int qic_rate_code(unsigned int rate)
702{
703 switch (rate) {
704 case 250:
705 return QIC_CONFIG_RATE_250;
706 case 500:
707 return QIC_CONFIG_RATE_500;
708 case 1000:
709 return QIC_CONFIG_RATE_1000;
710 case 2000:
711 return QIC_CONFIG_RATE_2000;
712 default:
713 return QIC_CONFIG_RATE_500;
714 }
715}
716
717static int ftape_set_rate_test(unsigned int *max_rate)
718{
719 unsigned int error;
720 qic117_cmd_t command;
721 int status;
722 int supported = 0;
723 TRACE_FUN(ft_t_any);
724
725 /* Check if the drive does support the select rate command
726 * by testing all different settings. If any one is accepted
727 * we assume the command is supported, else not.
728 */
729 for (*max_rate = 2000; *max_rate >= 250; *max_rate /= 2) {
730 if (ftape_command(QIC_SELECT_RATE) < 0) {
731 continue;
732 }
733 if (ftape_parameter_wait(qic_rate_code(*max_rate),
734 1 * FT_SECOND, &status) < 0) {
735 continue;
736 }
737 if (status & QIC_STATUS_ERROR) {
738 ftape_report_error(&error, &command, 0);
739 continue;
740 }
741 supported = 1; /* did accept a request */
742 break;
743 }
744 TRACE(ft_t_noise, "Select Rate command is%s supported",
745 supported ? "" : " not");
746 TRACE_EXIT supported;
747}
748
749int ftape_set_data_rate(unsigned int new_rate /* Kbps */, unsigned int qic_std)
750{
751 int status;
752 int result = 0;
753 unsigned int data_rate = new_rate;
754 static int supported;
755 int rate_changed = 0;
756 qic_model dummy_model;
757 unsigned int dummy_qic_std, dummy_tape_len;
758 TRACE_FUN(ft_t_any);
759
760 if (ft_drive_max_rate == 0) { /* first time */
761 supported = ftape_set_rate_test(&ft_drive_max_rate);
762 }
763 if (supported) {
764 ftape_command(QIC_SELECT_RATE);
765 result = ftape_parameter_wait(qic_rate_code(new_rate),
766 1 * FT_SECOND, &status);
767 if (result >= 0 && !(status & QIC_STATUS_ERROR)) {
768 rate_changed = 1;
769 }
770 }
771 TRACE_CATCH(result = ftape_report_configuration(&dummy_model,
772 &data_rate,
773 &dummy_qic_std,
774 &dummy_tape_len),);
775 if (data_rate != new_rate) {
776 if (!supported) {
777 TRACE(ft_t_warn, "Rate change not supported!");
778 } else if (rate_changed) {
779 TRACE(ft_t_warn, "Requested: %d, got %d",
780 new_rate, data_rate);
781 } else {
782 TRACE(ft_t_warn, "Rate change failed!");
783 }
784 result = -EINVAL;
785 }
786 /*
787 * Set data rate and write precompensation as specified:
788 *
789 * | QIC-40/80 | QIC-3010/3020
790 * rate | precomp | precomp
791 * ----------+-------------+--------------
792 * 250 Kbps. | 250 ns. | 0 ns.
793 * 500 Kbps. | 125 ns. | 0 ns.
794 * 1 Mbps. | 42 ns. | 0 ns.
795 * 2 Mbps | N/A | 0 ns.
796 */
797 if ((qic_std == QIC_TAPE_QIC40 && data_rate > 500) ||
798 (qic_std == QIC_TAPE_QIC80 && data_rate > 1000)) {
799 TRACE_ABORT(-EINVAL,
800 ft_t_warn, "Datarate too high for QIC-mode");
801 }
802 TRACE_CATCH(fdc_set_data_rate(data_rate),_res = -EINVAL);
803 ft_data_rate = data_rate;
804 if (qic_std == QIC_TAPE_QIC40 || qic_std == QIC_TAPE_QIC80) {
805 switch (data_rate) {
806 case 250:
807 fdc_set_write_precomp(250);
808 break;
809 default:
810 case 500:
811 fdc_set_write_precomp(125);
812 break;
813 case 1000:
814 fdc_set_write_precomp(42);
815 break;
816 }
817 } else {
818 fdc_set_write_precomp(0);
819 }
820 TRACE_EXIT result;
821}
822
823/* The next two functions are used to cope with excessive overrun errors
824 */
825int ftape_increase_threshold(void)
826{
827 TRACE_FUN(ft_t_flow);
828
829 if (fdc.type < i82077 || ft_fdc_threshold >= 12) {
830 TRACE_ABORT(-EIO, ft_t_err, "cannot increase fifo threshold");
831 }
832 if (fdc_fifo_threshold(++ft_fdc_threshold, NULL, NULL, NULL) < 0) {
833 TRACE(ft_t_err, "cannot increase fifo threshold");
834 ft_fdc_threshold --;
835 fdc_reset();
836 }
837 TRACE(ft_t_info, "New FIFO threshold: %d", ft_fdc_threshold);
838 TRACE_EXIT 0;
839}
840
841int ftape_half_data_rate(void)
842{
843 if (ft_data_rate < 500) {
844 return -1;
845 }
846 if (ftape_set_data_rate(ft_data_rate / 2, ft_qic_std) < 0) {
847 return -EIO;
848 }
849 ftape_calc_timeouts(ft_qic_std, ft_data_rate, ftape_tape_len);
850 return 0;
851}
852
853/* Seek the head to the specified track.
854 */
855int ftape_seek_head_to_track(unsigned int track)
856{
857 int status;
858 TRACE_FUN(ft_t_any);
859
860 ft_location.track = -1; /* remains set in case of error */
861 if (track >= ft_tracks_per_tape) {
862 TRACE_ABORT(-EINVAL, ft_t_bug, "track out of bounds");
863 }
864 TRACE(ft_t_flow, "seeking track %d", track);
865 TRACE_CATCH(ftape_command(QIC_SEEK_HEAD_TO_TRACK),);
866 TRACE_CATCH(ftape_parameter_wait(track, ftape_timeout.head_seek,
867 &status),);
868 ft_location.track = track;
869 ftape_might_be_off_track = 0;
870 TRACE_EXIT 0;
871}
872
873int ftape_wakeup_drive(wake_up_types method)
874{
875 int status;
876 int motor_on = 0;
877 TRACE_FUN(ft_t_any);
878
879 switch (method) {
880 case wake_up_colorado:
881 TRACE_CATCH(ftape_command(QIC_PHANTOM_SELECT),);
882 TRACE_CATCH(ftape_parameter(0 /* ft_drive_sel ?? */),);
883 break;
884 case wake_up_mountain:
885 TRACE_CATCH(ftape_command(QIC_SOFT_SELECT),);
886 ftape_sleep(FT_MILLISECOND); /* NEEDED */
887 TRACE_CATCH(ftape_parameter(18),);
888 break;
889 case wake_up_insight:
890 ftape_sleep(100 * FT_MILLISECOND);
891 motor_on = 1;
892 fdc_motor(motor_on); /* enable is done by motor-on */
893 case no_wake_up:
894 break;
895 default:
896 TRACE_EXIT -ENODEV; /* unknown wakeup method */
897 break;
898 }
899 /* If wakeup succeeded we shouldn't get an error here..
900 */
901 TRACE_CATCH(ftape_report_raw_drive_status(&status),
902 if (motor_on) {
903 fdc_motor(0);
904 });
905 TRACE_EXIT 0;
906}
907
908int ftape_put_drive_to_sleep(wake_up_types method)
909{
910 TRACE_FUN(ft_t_any);
911
912 switch (method) {
913 case wake_up_colorado:
914 TRACE_CATCH(ftape_command(QIC_PHANTOM_DESELECT),);
915 break;
916 case wake_up_mountain:
917 TRACE_CATCH(ftape_command(QIC_SOFT_DESELECT),);
918 break;
919 case wake_up_insight:
920 fdc_motor(0); /* enable is done by motor-on */
921 case no_wake_up: /* no wakeup / no sleep ! */
922 break;
923 default:
924 TRACE_EXIT -ENODEV; /* unknown wakeup method */
925 }
926 TRACE_EXIT 0;
927}
928
929int ftape_reset_drive(void)
930{
931 int result = 0;
932 int status;
933 unsigned int err_code;
934 qic117_cmd_t err_command;
935 int i;
936 TRACE_FUN(ft_t_any);
937
938 /* We want to re-establish contact with our drive. Fire a
939 * number of reset commands (single step pulses) and pray for
940 * success.
941 */
942 for (i = 0; i < 2; ++i) {
943 TRACE(ft_t_flow, "Resetting fdc");
944 fdc_reset();
945 ftape_sleep(10 * FT_MILLISECOND);
946 TRACE(ft_t_flow, "Reset command to drive");
947 result = ftape_command(QIC_RESET);
948 if (result == 0) {
949 ftape_sleep(1 * FT_SECOND); /* drive not
950 * accessible
951 * during 1 second
952 */
953 TRACE(ft_t_flow, "Re-selecting drive");
954
955 /* Strange, the QIC-117 specs don't mention
956 * this but the drive gets deselected after a
957 * soft reset ! So we need to enable it
958 * again.
959 */
960 if (ftape_wakeup_drive(ft_drive_type.wake_up) < 0) {
961 TRACE(ft_t_err, "Wakeup failed !");
962 }
963 TRACE(ft_t_flow, "Waiting until drive gets ready");
964 result= ftape_ready_wait(ftape_timeout.reset, &status);
965 if (result == 0 && (status & QIC_STATUS_ERROR)) {
966 result = ftape_report_error(&err_code,
967 &err_command, 1);
968 if (result == 0 && err_code == 27) {
969 /* Okay, drive saw reset
970 * command and responded as it
971 * should
972 */
973 break;
974 } else {
975 result = -EIO;
976 }
977 } else {
978 result = -EIO;
979 }
980 }
981 FT_SIGNAL_EXIT(_DONT_BLOCK);
982 }
983 if (result != 0) {
984 TRACE(ft_t_err, "General failure to reset tape drive");
985 } else {
986 /* Restore correct settings: keep original rate
987 */
988 ftape_set_data_rate(ft_data_rate, ft_qic_std);
989 }
990 ftape_init_drive_needed = 1;
991 TRACE_EXIT result;
992}
diff --git a/drivers/char/ftape/lowlevel/ftape-io.h b/drivers/char/ftape/lowlevel/ftape-io.h
deleted file mode 100644
index 26a7baad8717..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-io.h
+++ /dev/null
@@ -1,90 +0,0 @@
1#ifndef _FTAPE_IO_H
2#define _FTAPE_IO_H
3
4/*
5 * Copyright (C) 1993-1996 Bas Laarhoven,
6 * (C) 1997 Claus-Justus Heine.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 *
23 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-io.h,v $
24 * $Revision: 1.2 $
25 * $Date: 1997/10/05 19:18:18 $
26 *
27 * This file contains definitions for the glue part of the
28 * QIC-40/80/3010/3020 floppy-tape driver "ftape" for Linux.
29 */
30
31#include <linux/qic117.h>
32#include <linux/ftape-vendors.h>
33
34typedef struct {
35 unsigned int seek;
36 unsigned int reset;
37 unsigned int rewind;
38 unsigned int head_seek;
39 unsigned int stop;
40 unsigned int pause;
41} ft_timeout_table;
42
43typedef enum {
44 prehistoric, pre_qic117c, post_qic117b, post_qic117d
45} qic_model;
46
47/*
48 * ftape-io.c defined global vars.
49 */
50extern ft_timeout_table ftape_timeout;
51extern unsigned int ftape_tape_len;
52extern volatile qic117_cmd_t ftape_current_command;
53extern const struct qic117_command_table qic117_cmds[];
54extern int ftape_might_be_off_track;
55
56/*
57 * ftape-io.c defined global functions.
58 */
59extern void ftape_udelay(unsigned int usecs);
60extern void ftape_udelay_calibrate(void);
61extern void ftape_sleep(unsigned int time);
62extern void ftape_report_vendor_id(unsigned int *id);
63extern int ftape_command(qic117_cmd_t command);
64extern int ftape_command_wait(qic117_cmd_t command,
65 unsigned int timeout,
66 int *status);
67extern int ftape_parameter(unsigned int parameter);
68extern int ftape_report_operation(int *status,
69 qic117_cmd_t command,
70 int result_length);
71extern int ftape_report_configuration(qic_model *model,
72 unsigned int *rate,
73 int *qic_std,
74 int *tape_len);
75extern int ftape_report_drive_status(int *status);
76extern int ftape_report_raw_drive_status(int *status);
77extern int ftape_report_status(int *status);
78extern int ftape_ready_wait(unsigned int timeout, int *status);
79extern int ftape_seek_head_to_track(unsigned int track);
80extern int ftape_set_data_rate(unsigned int new_rate, unsigned int qic_std);
81extern int ftape_report_error(unsigned int *error,
82 qic117_cmd_t *command,
83 int report);
84extern int ftape_reset_drive(void);
85extern int ftape_put_drive_to_sleep(wake_up_types method);
86extern int ftape_wakeup_drive(wake_up_types method);
87extern int ftape_increase_threshold(void);
88extern int ftape_half_data_rate(void);
89
90#endif
diff --git a/drivers/char/ftape/lowlevel/ftape-proc.c b/drivers/char/ftape/lowlevel/ftape-proc.c
deleted file mode 100644
index e805b15e0a12..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-proc.c
+++ /dev/null
@@ -1,214 +0,0 @@
1/*
2 * Copyright (C) 1997 Claus-Justus Heine
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 *
19 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-proc.c,v $
20 * $Revision: 1.11 $
21 * $Date: 1997/10/24 14:47:37 $
22 *
23 * This file contains the procfs interface for the
24 * QIC-40/80/3010/3020 floppy-tape driver "ftape" for Linux.
25
26 * Old code removed, switched to dynamic proc entry.
27 */
28
29
30#if defined(CONFIG_PROC_FS) && defined(CONFIG_FT_PROC_FS)
31
32#include <linux/proc_fs.h>
33
34#include <linux/ftape.h>
35#include <linux/init.h>
36#include <linux/qic117.h>
37
38#include "../lowlevel/ftape-io.h"
39#include "../lowlevel/ftape-ctl.h"
40#include "../lowlevel/ftape-proc.h"
41#include "../lowlevel/ftape-tracing.h"
42
43static size_t get_driver_info(char *buf)
44{
45 const char *debug_level[] = { "bugs" ,
46 "errors",
47 "warnings",
48 "informational",
49 "noisy",
50 "program flow",
51 "fdc and dma",
52 "data flow",
53 "anything" };
54
55 return sprintf(buf,
56 "version : %s\n"
57 "used data rate: %d kbit/sec\n"
58 "dma memory : %d kb\n"
59 "debug messages: %s\n",
60 FTAPE_VERSION,
61 ft_data_rate,
62 FT_BUFF_SIZE * ft_nr_buffers >> 10,
63 debug_level[TRACE_LEVEL]);
64}
65
66static size_t get_tapedrive_info(char *buf)
67{
68 return sprintf(buf,
69 "vendor id : 0x%04x\n"
70 "drive name: %s\n"
71 "wind speed: %d ips\n"
72 "wakeup : %s\n"
73 "max. rate : %d kbit/sec\n",
74 ft_drive_type.vendor_id,
75 ft_drive_type.name,
76 ft_drive_type.speed,
77 ((ft_drive_type.wake_up == no_wake_up)
78 ? "No wakeup needed" :
79 ((ft_drive_type.wake_up == wake_up_colorado)
80 ? "Colorado" :
81 ((ft_drive_type.wake_up == wake_up_mountain)
82 ? "Mountain" :
83 ((ft_drive_type.wake_up == wake_up_insight)
84 ? "Motor on" :
85 "Unknown")))),
86 ft_drive_max_rate);
87}
88
89static size_t get_cartridge_info(char *buf)
90{
91 if (ftape_init_drive_needed) {
92 return sprintf(buf, "uninitialized\n");
93 }
94 if (ft_no_tape) {
95 return sprintf(buf, "no cartridge inserted\n");
96 }
97 return sprintf(buf,
98 "segments : %5d\n"
99 "tracks : %5d\n"
100 "length : %5dft\n"
101 "formatted : %3s\n"
102 "writable : %3s\n"
103 "QIC spec. : QIC-%s\n"
104 "fmt-code : %1d\n",
105 ft_segments_per_track,
106 ft_tracks_per_tape,
107 ftape_tape_len,
108 (ft_formatted == 1) ? "yes" : "no",
109 (ft_write_protected == 1) ? "no" : "yes",
110 ((ft_qic_std == QIC_TAPE_QIC40) ? "40" :
111 ((ft_qic_std == QIC_TAPE_QIC80) ? "80" :
112 ((ft_qic_std == QIC_TAPE_QIC3010) ? "3010" :
113 ((ft_qic_std == QIC_TAPE_QIC3020) ? "3020" :
114 "???")))),
115 ft_format_code);
116}
117
118static size_t get_controller_info(char *buf)
119{
120 const char *fdc_name[] = { "no fdc",
121 "i8272",
122 "i82077",
123 "i82077AA",
124 "Colorado FC-10 or FC-20",
125 "i82078",
126 "i82078_1" };
127
128 return sprintf(buf,
129 "FDC type : %s\n"
130 "FDC base : 0x%03x\n"
131 "FDC irq : %d\n"
132 "FDC dma : %d\n"
133 "FDC thr. : %d\n"
134 "max. rate : %d kbit/sec\n",
135 ft_mach2 ? "Mountain MACH-2" : fdc_name[fdc.type],
136 fdc.sra, fdc.irq, fdc.dma,
137 ft_fdc_threshold, ft_fdc_max_rate);
138}
139
140static size_t get_history_info(char *buf)
141{
142 size_t len;
143
144 len = sprintf(buf,
145 "\nFDC isr statistics\n"
146 " id_am_errors : %3d\n"
147 " id_crc_errors : %3d\n"
148 " data_am_errors : %3d\n"
149 " data_crc_errors : %3d\n"
150 " overrun_errors : %3d\n"
151 " no_data_errors : %3d\n"
152 " retries : %3d\n",
153 ft_history.id_am_errors, ft_history.id_crc_errors,
154 ft_history.data_am_errors, ft_history.data_crc_errors,
155 ft_history.overrun_errors, ft_history.no_data_errors,
156 ft_history.retries);
157 len += sprintf(buf + len,
158 "\nECC statistics\n"
159 " crc_errors : %3d\n"
160 " crc_failures : %3d\n"
161 " ecc_failures : %3d\n"
162 " sectors corrected: %3d\n",
163 ft_history.crc_errors, ft_history.crc_failures,
164 ft_history.ecc_failures, ft_history.corrected);
165 len += sprintf(buf + len,
166 "\ntape quality statistics\n"
167 " media defects : %3d\n",
168 ft_history.defects);
169 len += sprintf(buf + len,
170 "\ntape motion statistics\n"
171 " repositions : %3d\n",
172 ft_history.rewinds);
173 return len;
174}
175
176static int ftape_read_proc(char *page, char **start, off_t off,
177 int count, int *eof, void *data)
178{
179 char *ptr = page;
180 size_t len;
181
182 ptr += sprintf(ptr, "Kernel Driver\n\n");
183 ptr += get_driver_info(ptr);
184 ptr += sprintf(ptr, "\nTape Drive\n\n");
185 ptr += get_tapedrive_info(ptr);
186 ptr += sprintf(ptr, "\nFDC Controller\n\n");
187 ptr += get_controller_info(ptr);
188 ptr += sprintf(ptr, "\nTape Cartridge\n\n");
189 ptr += get_cartridge_info(ptr);
190 ptr += sprintf(ptr, "\nHistory Record\n\n");
191 ptr += get_history_info(ptr);
192
193 len = strlen(page);
194 *start = NULL;
195 if (off+count >= len) {
196 *eof = 1;
197 } else {
198 *eof = 0;
199 }
200 return len;
201}
202
203int __init ftape_proc_init(void)
204{
205 return create_proc_read_entry("ftape", 0, &proc_root,
206 ftape_read_proc, NULL) != NULL;
207}
208
209void ftape_proc_destroy(void)
210{
211 remove_proc_entry("ftape", &proc_root);
212}
213
214#endif /* defined(CONFIG_PROC_FS) && defined(CONFIG_FT_PROC_FS) */
diff --git a/drivers/char/ftape/lowlevel/ftape-proc.h b/drivers/char/ftape/lowlevel/ftape-proc.h
deleted file mode 100644
index 264dfcc1d22d..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-proc.h
+++ /dev/null
@@ -1,35 +0,0 @@
1#ifndef _FTAPE_PROC_H
2#define _FTAPE_PROC_H
3
4/*
5 * Copyright (C) 1997 Claus-Justus Heine
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 *
22 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-proc.h,v $
23 * $Revision: 1.2 $
24 * $Date: 1997/10/05 19:18:20 $
25 *
26 * This file contains definitions for the procfs interface of the
27 * QIC-40/80/3010/3020 floppy-tape driver "ftape" for Linux.
28 */
29
30#include <linux/proc_fs.h>
31
32extern int ftape_proc_init(void);
33extern void ftape_proc_destroy(void);
34
35#endif
diff --git a/drivers/char/ftape/lowlevel/ftape-read.c b/drivers/char/ftape/lowlevel/ftape-read.c
deleted file mode 100644
index d967d8cd86dc..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-read.c
+++ /dev/null
@@ -1,621 +0,0 @@
1/*
2 * Copyright (C) 1993-1996 Bas Laarhoven,
3 * (C) 1996-1997 Claus-Justus Heine.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 *
20 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-read.c,v $
21 * $Revision: 1.6 $
22 * $Date: 1997/10/21 14:39:22 $
23 *
24 * This file contains the reading code
25 * for the QIC-117 floppy-tape driver for Linux.
26 *
27 */
28
29#include <linux/string.h>
30#include <linux/errno.h>
31#include <linux/mm.h>
32
33#include <linux/ftape.h>
34#include <linux/qic117.h>
35#include "../lowlevel/ftape-tracing.h"
36#include "../lowlevel/ftape-read.h"
37#include "../lowlevel/ftape-io.h"
38#include "../lowlevel/ftape-ctl.h"
39#include "../lowlevel/ftape-rw.h"
40#include "../lowlevel/ftape-write.h"
41#include "../lowlevel/ftape-ecc.h"
42#include "../lowlevel/ftape-bsm.h"
43
44/* Global vars.
45 */
46
47/* Local vars.
48 */
49
50void ftape_zap_read_buffers(void)
51{
52 int i;
53
54 for (i = 0; i < ft_nr_buffers; ++i) {
55/* changed to "fit" with dynamic allocation of tape_buffer. --khp */
56 ft_buffer[i]->status = waiting;
57 ft_buffer[i]->bytes = 0;
58 ft_buffer[i]->skip = 0;
59 ft_buffer[i]->retry = 0;
60 }
61/* ftape_reset_buffer(); */
62}
63
64static SectorMap convert_sector_map(buffer_struct * buff)
65{
66 int i = 0;
67 SectorMap bad_map = ftape_get_bad_sector_entry(buff->segment_id);
68 SectorMap src_map = buff->soft_error_map | buff->hard_error_map;
69 SectorMap dst_map = 0;
70 TRACE_FUN(ft_t_any);
71
72 if (bad_map || src_map) {
73 TRACE(ft_t_flow, "bad_map = 0x%08lx", (long) bad_map);
74 TRACE(ft_t_flow, "src_map = 0x%08lx", (long) src_map);
75 }
76 while (bad_map) {
77 while ((bad_map & 1) == 0) {
78 if (src_map & 1) {
79 dst_map |= (1 << i);
80 }
81 src_map >>= 1;
82 bad_map >>= 1;
83 ++i;
84 }
85 /* (bad_map & 1) == 1 */
86 src_map >>= 1;
87 bad_map >>= 1;
88 }
89 if (src_map) {
90 dst_map |= (src_map << i);
91 }
92 if (dst_map) {
93 TRACE(ft_t_flow, "dst_map = 0x%08lx", (long) dst_map);
94 }
95 TRACE_EXIT dst_map;
96}
97
98static int correct_and_copy_fraction(buffer_struct *buff, __u8 * destination,
99 int start, int size)
100{
101 struct memory_segment mseg;
102 int result;
103 SectorMap read_bad;
104 TRACE_FUN(ft_t_any);
105
106 mseg.read_bad = convert_sector_map(buff);
107 mseg.marked_bad = 0; /* not used... */
108 mseg.blocks = buff->bytes / FT_SECTOR_SIZE;
109 mseg.data = buff->address;
110 /* If there are no data sectors we can skip this segment.
111 */
112 if (mseg.blocks <= 3) {
113 TRACE_ABORT(0, ft_t_noise, "empty segment");
114 }
115 read_bad = mseg.read_bad;
116 ft_history.crc_errors += count_ones(read_bad);
117 result = ftape_ecc_correct_data(&mseg);
118 if (read_bad != 0 || mseg.corrected != 0) {
119 TRACE(ft_t_noise, "crc error map: 0x%08lx", (unsigned long)read_bad);
120 TRACE(ft_t_noise, "corrected map: 0x%08lx", (unsigned long)mseg.corrected);
121 ft_history.corrected += count_ones(mseg.corrected);
122 }
123 if (result == ECC_CORRECTED || result == ECC_OK) {
124 if (result == ECC_CORRECTED) {
125 TRACE(ft_t_info, "ecc corrected segment: %d", buff->segment_id);
126 }
127 if(start < 0) {
128 start= 0;
129 }
130 if((start+size) > ((mseg.blocks - 3) * FT_SECTOR_SIZE)) {
131 size = (mseg.blocks - 3) * FT_SECTOR_SIZE - start;
132 }
133 if (size < 0) {
134 size= 0;
135 }
136 if(size > 0) {
137 memcpy(destination + start, mseg.data + start, size);
138 }
139 if ((read_bad ^ mseg.corrected) & mseg.corrected) {
140 /* sectors corrected without crc errors set */
141 ft_history.crc_failures++;
142 }
143 TRACE_EXIT size; /* (mseg.blocks - 3) * FT_SECTOR_SIZE; */
144 } else {
145 ft_history.ecc_failures++;
146 TRACE_ABORT(-EAGAIN,
147 ft_t_err, "ecc failure on segment %d",
148 buff->segment_id);
149 }
150 TRACE_EXIT 0;
151}
152
153/* Read given segment into buffer at address.
154 */
155int ftape_read_segment_fraction(const int segment_id,
156 void *address,
157 const ft_read_mode_t read_mode,
158 const int start,
159 const int size)
160{
161 int result = 0;
162 int retry = 0;
163 int bytes_read = 0;
164 int read_done = 0;
165 TRACE_FUN(ft_t_flow);
166
167 ft_history.used |= 1;
168 TRACE(ft_t_data_flow, "segment_id = %d", segment_id);
169 if (ft_driver_state != reading) {
170 TRACE(ft_t_noise, "calling ftape_abort_operation");
171 TRACE_CATCH(ftape_abort_operation(),);
172 ftape_set_state(reading);
173 }
174 for(;;) {
175 buffer_struct *tail;
176 /* Allow escape from this loop on signal !
177 */
178 FT_SIGNAL_EXIT(_DONT_BLOCK);
179 /* Search all full buffers for the first matching the
180 * wanted segment. Clear other buffers on the fly.
181 */
182 tail = ftape_get_buffer(ft_queue_tail);
183 while (!read_done && tail->status == done) {
184 /* Allow escape from this loop on signal !
185 */
186 FT_SIGNAL_EXIT(_DONT_BLOCK);
187 if (tail->segment_id == segment_id) {
188 /* If out buffer is already full,
189 * return its contents.
190 */
191 TRACE(ft_t_flow, "found segment in cache: %d",
192 segment_id);
193 if (tail->deleted) {
194 /* Return a value that
195 * read_header_segment
196 * understands. As this
197 * should only occur when
198 * searching for the header
199 * segments it shouldn't be
200 * misinterpreted elsewhere.
201 */
202 TRACE_EXIT 0;
203 }
204 result = correct_and_copy_fraction(
205 tail,
206 address,
207 start,
208 size);
209 TRACE(ft_t_flow, "segment contains (bytes): %d",
210 result);
211 if (result < 0) {
212 if (result != -EAGAIN) {
213 TRACE_EXIT result;
214 }
215 /* keep read_done == 0, will
216 * trigger
217 * ftape_abort_operation
218 * because reading wrong
219 * segment.
220 */
221 TRACE(ft_t_err, "ecc failed, retry");
222 ++retry;
223 } else {
224 read_done = 1;
225 bytes_read = result;
226 }
227 } else {
228 TRACE(ft_t_flow,"zapping segment in cache: %d",
229 tail->segment_id);
230 }
231 tail->status = waiting;
232 tail = ftape_next_buffer(ft_queue_tail);
233 }
234 if (!read_done && tail->status == reading) {
235 if (tail->segment_id == segment_id) {
236 switch(ftape_wait_segment(reading)) {
237 case 0:
238 break;
239 case -EINTR:
240 TRACE_ABORT(-EINTR, ft_t_warn,
241 "interrupted by "
242 "non-blockable signal");
243 break;
244 default:
245 TRACE(ft_t_noise,
246 "wait_segment failed");
247 ftape_abort_operation();
248 ftape_set_state(reading);
249 break;
250 }
251 } else {
252 /* We're reading the wrong segment,
253 * stop runner.
254 */
255 TRACE(ft_t_noise, "reading wrong segment");
256 ftape_abort_operation();
257 ftape_set_state(reading);
258 }
259 }
260 /* should runner stop ?
261 */
262 if (ft_runner_status == aborting) {
263 buffer_struct *head = ftape_get_buffer(ft_queue_head);
264 switch(head->status) {
265 case error:
266 ft_history.defects +=
267 count_ones(head->hard_error_map);
268 case reading:
269 head->status = waiting;
270 break;
271 default:
272 break;
273 }
274 TRACE_CATCH(ftape_dumb_stop(),);
275 } else {
276 /* If just passed last segment on tape: wait
277 * for BOT or EOT mark. Sets ft_runner_status to
278 * idle if at lEOT and successful
279 */
280 TRACE_CATCH(ftape_handle_logical_eot(),);
281 }
282 /* If we got a segment: quit, or else retry up to limit.
283 *
284 * If segment to read is empty, do not start runner for it,
285 * but wait for next read call.
286 */
287 if (read_done ||
288 ftape_get_bad_sector_entry(segment_id) == EMPTY_SEGMENT ) {
289 /* bytes_read = 0; should still be zero */
290 TRACE_EXIT bytes_read;
291
292 }
293 if (retry > FT_RETRIES_ON_ECC_ERROR) {
294 ft_history.defects++;
295 TRACE_ABORT(-ENODATA, ft_t_err,
296 "too many retries on ecc failure");
297 }
298 /* Now at least one buffer is empty !
299 * Restart runner & tape if needed.
300 */
301 TRACE(ft_t_any, "head: %d, tail: %d, ft_runner_status: %d",
302 ftape_buffer_id(ft_queue_head),
303 ftape_buffer_id(ft_queue_tail),
304 ft_runner_status);
305 TRACE(ft_t_any, "buffer[].status, [head]: %d, [tail]: %d",
306 ftape_get_buffer(ft_queue_head)->status,
307 ftape_get_buffer(ft_queue_tail)->status);
308 tail = ftape_get_buffer(ft_queue_tail);
309 if (tail->status == waiting) {
310 buffer_struct *head = ftape_get_buffer(ft_queue_head);
311
312 ftape_setup_new_segment(head, segment_id, -1);
313 if (read_mode == FT_RD_SINGLE) {
314 /* disable read-ahead */
315 head->next_segment = 0;
316 }
317 ftape_calc_next_cluster(head);
318 if (ft_runner_status == idle) {
319 result = ftape_start_tape(segment_id,
320 head->sector_offset);
321 if (result < 0) {
322 TRACE_ABORT(result, ft_t_err, "Error: "
323 "segment %d unreachable",
324 segment_id);
325 }
326 }
327 head->status = reading;
328 fdc_setup_read_write(head, FDC_READ);
329 }
330 }
331 /* not reached */
332 TRACE_EXIT -EIO;
333}
334
335int ftape_read_header_segment(__u8 *address)
336{
337 int result;
338 int header_segment;
339 int first_failed = 0;
340 int status;
341 TRACE_FUN(ft_t_flow);
342
343 ft_used_header_segment = -1;
344 TRACE_CATCH(ftape_report_drive_status(&status),);
345 TRACE(ft_t_flow, "reading...");
346 /* We're looking for the first header segment.
347 * A header segment cannot contain bad sectors, therefor at the
348 * tape start, segments with bad sectors are (according to QIC-40/80)
349 * written with deleted data marks and must be skipped.
350 */
351 memset(address, '\0', (FT_SECTORS_PER_SEGMENT - 3) * FT_SECTOR_SIZE);
352 result = 0;
353#define HEADER_SEGMENT_BOUNDARY 68 /* why not 42? */
354 for (header_segment = 0;
355 header_segment < HEADER_SEGMENT_BOUNDARY && result == 0;
356 ++header_segment) {
357 /* Set no read-ahead, the isr will force read-ahead whenever
358 * it encounters deleted data !
359 */
360 result = ftape_read_segment(header_segment,
361 address,
362 FT_RD_SINGLE);
363 if (result < 0 && !first_failed) {
364 TRACE(ft_t_err, "header segment damaged, trying backup");
365 first_failed = 1;
366 result = 0; /* force read of next (backup) segment */
367 }
368 }
369 if (result < 0 || header_segment >= HEADER_SEGMENT_BOUNDARY) {
370 TRACE_ABORT(-EIO, ft_t_err,
371 "no readable header segment found");
372 }
373 TRACE_CATCH(ftape_abort_operation(),);
374 ft_used_header_segment = header_segment;
375 result = ftape_decode_header_segment(address);
376 TRACE_EXIT result;
377}
378
379int ftape_decode_header_segment(__u8 *address)
380{
381 unsigned int max_floppy_side;
382 unsigned int max_floppy_track;
383 unsigned int max_floppy_sector;
384 unsigned int new_tape_len;
385 TRACE_FUN(ft_t_flow);
386
387 if (GET4(address, FT_SIGNATURE) == FT_D2G_MAGIC) {
388 /* Ditto 2GB header segment. They encrypt the bad sector map.
389 * We decrypt it and store them in normal format.
390 * I hope this is correct.
391 */
392 int i;
393 TRACE(ft_t_warn,
394 "Found Ditto 2GB tape, "
395 "trying to decrypt bad sector map");
396 for (i=256; i < 29 * FT_SECTOR_SIZE; i++) {
397 address[i] = ~(address[i] - (i&0xff));
398 }
399 PUT4(address, 0,FT_HSEG_MAGIC);
400 } else if (GET4(address, FT_SIGNATURE) != FT_HSEG_MAGIC) {
401 TRACE_ABORT(-EIO, ft_t_err,
402 "wrong signature in header segment");
403 }
404 ft_format_code = (ft_format_type) address[FT_FMT_CODE];
405 if (ft_format_code != fmt_big) {
406 ft_header_segment_1 = GET2(address, FT_HSEG_1);
407 ft_header_segment_2 = GET2(address, FT_HSEG_2);
408 ft_first_data_segment = GET2(address, FT_FRST_SEG);
409 ft_last_data_segment = GET2(address, FT_LAST_SEG);
410 } else {
411 ft_header_segment_1 = GET4(address, FT_6_HSEG_1);
412 ft_header_segment_2 = GET4(address, FT_6_HSEG_2);
413 ft_first_data_segment = GET4(address, FT_6_FRST_SEG);
414 ft_last_data_segment = GET4(address, FT_6_LAST_SEG);
415 }
416 TRACE(ft_t_noise, "first data segment: %d", ft_first_data_segment);
417 TRACE(ft_t_noise, "last data segment: %d", ft_last_data_segment);
418 TRACE(ft_t_noise, "header segments are %d and %d",
419 ft_header_segment_1, ft_header_segment_2);
420
421 /* Verify tape parameters...
422 * QIC-40/80 spec: tape_parameters:
423 *
424 * segments-per-track segments_per_track
425 * tracks-per-cartridge tracks_per_tape
426 * max-floppy-side (segments_per_track *
427 * tracks_per_tape - 1) /
428 * ftape_segments_per_head
429 * max-floppy-track ftape_segments_per_head /
430 * ftape_segments_per_cylinder - 1
431 * max-floppy-sector ftape_segments_per_cylinder *
432 * FT_SECTORS_PER_SEGMENT
433 */
434 ft_segments_per_track = GET2(address, FT_SPT);
435 ft_tracks_per_tape = address[FT_TPC];
436 max_floppy_side = address[FT_FHM];
437 max_floppy_track = address[FT_FTM];
438 max_floppy_sector = address[FT_FSM];
439 TRACE(ft_t_noise, "(fmt/spt/tpc/fhm/ftm/fsm) = %d/%d/%d/%d/%d/%d",
440 ft_format_code, ft_segments_per_track, ft_tracks_per_tape,
441 max_floppy_side, max_floppy_track, max_floppy_sector);
442 new_tape_len = ftape_tape_len;
443 switch (ft_format_code) {
444 case fmt_425ft:
445 new_tape_len = 425;
446 break;
447 case fmt_normal:
448 if (ftape_tape_len == 0) { /* otherwise 307 ft */
449 new_tape_len = 205;
450 }
451 break;
452 case fmt_1100ft:
453 new_tape_len = 1100;
454 break;
455 case fmt_var:{
456 int segments_per_1000_inch = 1; /* non-zero default for switch */
457 switch (ft_qic_std) {
458 case QIC_TAPE_QIC40:
459 segments_per_1000_inch = 332;
460 break;
461 case QIC_TAPE_QIC80:
462 segments_per_1000_inch = 488;
463 break;
464 case QIC_TAPE_QIC3010:
465 segments_per_1000_inch = 730;
466 break;
467 case QIC_TAPE_QIC3020:
468 segments_per_1000_inch = 1430;
469 break;
470 }
471 new_tape_len = (1000 * ft_segments_per_track +
472 (segments_per_1000_inch - 1)) / segments_per_1000_inch;
473 break;
474 }
475 case fmt_big:{
476 int segments_per_1000_inch = 1; /* non-zero default for switch */
477 switch (ft_qic_std) {
478 case QIC_TAPE_QIC40:
479 segments_per_1000_inch = 332;
480 break;
481 case QIC_TAPE_QIC80:
482 segments_per_1000_inch = 488;
483 break;
484 case QIC_TAPE_QIC3010:
485 segments_per_1000_inch = 730;
486 break;
487 case QIC_TAPE_QIC3020:
488 segments_per_1000_inch = 1430;
489 break;
490 default:
491 TRACE_ABORT(-EIO, ft_t_bug,
492 "%x QIC-standard with fmt-code %d, please report",
493 ft_qic_std, ft_format_code);
494 }
495 new_tape_len = ((1000 * ft_segments_per_track +
496 (segments_per_1000_inch - 1)) /
497 segments_per_1000_inch);
498 break;
499 }
500 default:
501 TRACE_ABORT(-EIO, ft_t_err,
502 "unknown tape format, please report !");
503 }
504 if (new_tape_len != ftape_tape_len) {
505 ftape_tape_len = new_tape_len;
506 TRACE(ft_t_info, "calculated tape length is %d ft",
507 ftape_tape_len);
508 ftape_calc_timeouts(ft_qic_std, ft_data_rate, ftape_tape_len);
509 }
510 if (ft_segments_per_track == 0 && ft_tracks_per_tape == 0 &&
511 max_floppy_side == 0 && max_floppy_track == 0 &&
512 max_floppy_sector == 0) {
513 /* QIC-40 Rev E and earlier has no values in the header.
514 */
515 ft_segments_per_track = 68;
516 ft_tracks_per_tape = 20;
517 max_floppy_side = 1;
518 max_floppy_track = 169;
519 max_floppy_sector = 128;
520 }
521 /* This test will compensate for the wrong parameter on tapes
522 * formatted by Conner software.
523 */
524 if (ft_segments_per_track == 150 &&
525 ft_tracks_per_tape == 28 &&
526 max_floppy_side == 7 &&
527 max_floppy_track == 149 &&
528 max_floppy_sector == 128) {
529TRACE(ft_t_info, "the famous CONNER bug: max_floppy_side off by one !");
530 max_floppy_side = 6;
531 }
532 /* These tests will compensate for the wrong parameter on tapes
533 * formatted by ComByte Windows software.
534 *
535 * First, for 205 foot tapes
536 */
537 if (ft_segments_per_track == 100 &&
538 ft_tracks_per_tape == 28 &&
539 max_floppy_side == 9 &&
540 max_floppy_track == 149 &&
541 max_floppy_sector == 128) {
542TRACE(ft_t_info, "the ComByte bug: max_floppy_side incorrect!");
543 max_floppy_side = 4;
544 }
545 /* Next, for 307 foot tapes. */
546 if (ft_segments_per_track == 150 &&
547 ft_tracks_per_tape == 28 &&
548 max_floppy_side == 9 &&
549 max_floppy_track == 149 &&
550 max_floppy_sector == 128) {
551TRACE(ft_t_info, "the ComByte bug: max_floppy_side incorrect!");
552 max_floppy_side = 6;
553 }
554 /* This test will compensate for the wrong parameter on tapes
555 * formatted by Colorado Windows software.
556 */
557 if (ft_segments_per_track == 150 &&
558 ft_tracks_per_tape == 28 &&
559 max_floppy_side == 6 &&
560 max_floppy_track == 150 &&
561 max_floppy_sector == 128) {
562TRACE(ft_t_info, "the famous Colorado bug: max_floppy_track off by one !");
563 max_floppy_track = 149;
564 }
565 ftape_segments_per_head = ((max_floppy_sector/FT_SECTORS_PER_SEGMENT) *
566 (max_floppy_track + 1));
567 /* This test will compensate for some bug reported by Dima
568 * Brodsky. Seems to be a Colorado bug, either. (freebee
569 * Imation tape shipped together with Colorado T3000
570 */
571 if ((ft_format_code == fmt_var || ft_format_code == fmt_big) &&
572 ft_tracks_per_tape == 50 &&
573 max_floppy_side == 54 &&
574 max_floppy_track == 255 &&
575 max_floppy_sector == 128) {
576TRACE(ft_t_info, "the famous ??? bug: max_floppy_track off by one !");
577 max_floppy_track = 254;
578 }
579 /*
580 * Verify drive_configuration with tape parameters
581 */
582 if (ftape_segments_per_head == 0 || ftape_segments_per_cylinder == 0 ||
583 ((ft_segments_per_track * ft_tracks_per_tape - 1) / ftape_segments_per_head
584 != max_floppy_side) ||
585 (ftape_segments_per_head / ftape_segments_per_cylinder - 1 != max_floppy_track) ||
586 (ftape_segments_per_cylinder * FT_SECTORS_PER_SEGMENT != max_floppy_sector)
587#ifdef TESTING
588 || ((ft_format_code == fmt_var || ft_format_code == fmt_big) &&
589 (max_floppy_track != 254 || max_floppy_sector != 128))
590#endif
591 ) {
592 char segperheadz = ftape_segments_per_head ? ' ' : '?';
593 char segpercylz = ftape_segments_per_cylinder ? ' ' : '?';
594 TRACE(ft_t_err,"Tape parameters inconsistency, please report");
595 TRACE(ft_t_err, "reported = %d/%d/%d/%d/%d/%d",
596 ft_format_code,
597 ft_segments_per_track,
598 ft_tracks_per_tape,
599 max_floppy_side,
600 max_floppy_track,
601 max_floppy_sector);
602 TRACE(ft_t_err, "required = %d/%d/%d/%d%c/%d%c/%d",
603 ft_format_code,
604 ft_segments_per_track,
605 ft_tracks_per_tape,
606 ftape_segments_per_head ?
607 ((ft_segments_per_track * ft_tracks_per_tape -1) /
608 ftape_segments_per_head ) :
609 (ft_segments_per_track * ft_tracks_per_tape -1),
610 segperheadz,
611 ftape_segments_per_cylinder ?
612 (ftape_segments_per_head /
613 ftape_segments_per_cylinder - 1 ) :
614 ftape_segments_per_head - 1,
615 segpercylz,
616 (ftape_segments_per_cylinder * FT_SECTORS_PER_SEGMENT));
617 TRACE_EXIT -EIO;
618 }
619 ftape_extract_bad_sector_map(address);
620 TRACE_EXIT 0;
621}
diff --git a/drivers/char/ftape/lowlevel/ftape-read.h b/drivers/char/ftape/lowlevel/ftape-read.h
deleted file mode 100644
index 069f99f2a984..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-read.h
+++ /dev/null
@@ -1,51 +0,0 @@
1#ifndef _FTAPE_READ_H
2#define _FTAPE_READ_H
3
4/*
5 * Copyright (C) 1994-1996 Bas Laarhoven,
6 * (C) 1996-1997 Claus-Justus Heine.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 *
23 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-read.h,v $
24 * $Revision: 1.2 $
25 * $Date: 1997/10/05 19:18:22 $
26 *
27 * This file contains the definitions for the read functions
28 * for the QIC-117 floppy-tape driver for Linux.
29 *
30 */
31
32/* ftape-read.c defined global functions.
33 */
34typedef enum {
35 FT_RD_SINGLE = 0,
36 FT_RD_AHEAD = 1,
37} ft_read_mode_t;
38
39extern int ftape_read_header_segment(__u8 *address);
40extern int ftape_decode_header_segment(__u8 *address);
41extern int ftape_read_segment_fraction(const int segment,
42 void *address,
43 const ft_read_mode_t read_mode,
44 const int start,
45 const int size);
46#define ftape_read_segment(segment, address, read_mode) \
47 ftape_read_segment_fraction(segment, address, read_mode, \
48 0, FT_SEGMENT_SIZE)
49extern void ftape_zap_read_buffers(void);
50
51#endif /* _FTAPE_READ_H */
diff --git a/drivers/char/ftape/lowlevel/ftape-rw.c b/drivers/char/ftape/lowlevel/ftape-rw.c
deleted file mode 100644
index c0d6dc2cbfd3..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-rw.c
+++ /dev/null
@@ -1,1092 +0,0 @@
1/*
2 * Copyright (C) 1993-1996 Bas Laarhoven,
3 * (C) 1996-1997 Claus-Justus Heine.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 *
20 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-rw.c,v $
21 * $Revision: 1.7 $
22 * $Date: 1997/10/28 14:26:49 $
23 *
24 * This file contains some common code for the segment read and
25 * segment write routines for the QIC-117 floppy-tape driver for
26 * Linux.
27 */
28
29#include <linux/string.h>
30#include <linux/errno.h>
31
32#include <linux/ftape.h>
33#include <linux/qic117.h>
34#include "../lowlevel/ftape-tracing.h"
35#include "../lowlevel/ftape-rw.h"
36#include "../lowlevel/fdc-io.h"
37#include "../lowlevel/ftape-init.h"
38#include "../lowlevel/ftape-io.h"
39#include "../lowlevel/ftape-ctl.h"
40#include "../lowlevel/ftape-read.h"
41#include "../lowlevel/ftape-ecc.h"
42#include "../lowlevel/ftape-bsm.h"
43
44/* Global vars.
45 */
46int ft_nr_buffers;
47buffer_struct *ft_buffer[FT_MAX_NR_BUFFERS];
48static volatile int ft_head;
49static volatile int ft_tail; /* not volatile but need same type as head */
50int fdc_setup_error;
51location_record ft_location = {-1, 0};
52volatile int ftape_tape_running;
53
54/* Local vars.
55 */
56static int overrun_count_offset;
57static int inhibit_correction;
58
59/* maxmimal allowed overshoot when fast seeking
60 */
61#define OVERSHOOT_LIMIT 10
62
63/* Increment cyclic buffer nr.
64 */
65buffer_struct *ftape_next_buffer(ft_buffer_queue_t pos)
66{
67 switch (pos) {
68 case ft_queue_head:
69 if (++ft_head >= ft_nr_buffers) {
70 ft_head = 0;
71 }
72 return ft_buffer[ft_head];
73 case ft_queue_tail:
74 if (++ft_tail >= ft_nr_buffers) {
75 ft_tail = 0;
76 }
77 return ft_buffer[ft_tail];
78 default:
79 return NULL;
80 }
81}
82int ftape_buffer_id(ft_buffer_queue_t pos)
83{
84 switch(pos) {
85 case ft_queue_head: return ft_head;
86 case ft_queue_tail: return ft_tail;
87 default: return -1;
88 }
89}
90buffer_struct *ftape_get_buffer(ft_buffer_queue_t pos)
91{
92 switch(pos) {
93 case ft_queue_head: return ft_buffer[ft_head];
94 case ft_queue_tail: return ft_buffer[ft_tail];
95 default: return NULL;
96 }
97}
98void ftape_reset_buffer(void)
99{
100 ft_head = ft_tail = 0;
101}
102
103buffer_state_enum ftape_set_state(buffer_state_enum new_state)
104{
105 buffer_state_enum old_state = ft_driver_state;
106
107 ft_driver_state = new_state;
108 return old_state;
109}
110/* Calculate Floppy Disk Controller and DMA parameters for a segment.
111 * head: selects buffer struct in array.
112 * offset: number of physical sectors to skip (including bad ones).
113 * count: number of physical sectors to handle (including bad ones).
114 */
115static int setup_segment(buffer_struct * buff,
116 int segment_id,
117 unsigned int sector_offset,
118 unsigned int sector_count,
119 int retry)
120{
121 SectorMap offset_mask;
122 SectorMap mask;
123 TRACE_FUN(ft_t_any);
124
125 buff->segment_id = segment_id;
126 buff->sector_offset = sector_offset;
127 buff->remaining = sector_count;
128 buff->head = segment_id / ftape_segments_per_head;
129 buff->cyl = (segment_id % ftape_segments_per_head) / ftape_segments_per_cylinder;
130 buff->sect = (segment_id % ftape_segments_per_cylinder) * FT_SECTORS_PER_SEGMENT + 1;
131 buff->deleted = 0;
132 offset_mask = (1 << buff->sector_offset) - 1;
133 mask = ftape_get_bad_sector_entry(segment_id) & offset_mask;
134 while (mask) {
135 if (mask & 1) {
136 offset_mask >>= 1; /* don't count bad sector */
137 }
138 mask >>= 1;
139 }
140 buff->data_offset = count_ones(offset_mask); /* good sectors to skip */
141 buff->ptr = buff->address + buff->data_offset * FT_SECTOR_SIZE;
142 TRACE(ft_t_flow, "data offset = %d sectors", buff->data_offset);
143 if (retry) {
144 buff->soft_error_map &= offset_mask; /* keep skipped part */
145 } else {
146 buff->hard_error_map = buff->soft_error_map = 0;
147 }
148 buff->bad_sector_map = ftape_get_bad_sector_entry(buff->segment_id);
149 if (buff->bad_sector_map != 0) {
150 TRACE(ft_t_noise, "segment: %d, bad sector map: %08lx",
151 buff->segment_id, (long)buff->bad_sector_map);
152 } else {
153 TRACE(ft_t_flow, "segment: %d", buff->segment_id);
154 }
155 if (buff->sector_offset > 0) {
156 buff->bad_sector_map >>= buff->sector_offset;
157 }
158 if (buff->sector_offset != 0 || buff->remaining != FT_SECTORS_PER_SEGMENT) {
159 TRACE(ft_t_flow, "sector offset = %d, count = %d",
160 buff->sector_offset, buff->remaining);
161 }
162 /* Segments with 3 or less sectors are not written with valid
163 * data because there is no space left for the ecc. The
164 * data written is whatever happens to be in the buffer.
165 * Reading such a segment will return a zero byte-count.
166 * To allow us to read/write segments with all bad sectors
167 * we fake one readable sector in the segment. This
168 * prevents having to handle these segments in a very
169 * special way. It is not important if the reading of this
170 * bad sector fails or not (the data is ignored). It is
171 * only read to keep the driver running.
172 *
173 * The QIC-40/80 spec. has no information on how to handle
174 * this case, so this is my interpretation.
175 */
176 if (buff->bad_sector_map == EMPTY_SEGMENT) {
177 TRACE(ft_t_flow, "empty segment %d, fake first sector good",
178 buff->segment_id);
179 if (buff->ptr != buff->address) {
180 TRACE(ft_t_bug, "This is a bug: %p/%p",
181 buff->ptr, buff->address);
182 }
183 buff->bad_sector_map = FAKE_SEGMENT;
184 }
185 fdc_setup_error = 0;
186 buff->next_segment = segment_id + 1;
187 TRACE_EXIT 0;
188}
189
190/* Calculate Floppy Disk Controller and DMA parameters for a new segment.
191 */
192int ftape_setup_new_segment(buffer_struct * buff, int segment_id, int skip)
193{
194 int result = 0;
195 static int old_segment_id = -1;
196 static buffer_state_enum old_ft_driver_state = idle;
197 int retry = 0;
198 unsigned offset = 0;
199 int count = FT_SECTORS_PER_SEGMENT;
200 TRACE_FUN(ft_t_flow);
201
202 TRACE(ft_t_flow, "%s segment %d (old = %d)",
203 (ft_driver_state == reading || ft_driver_state == verifying)
204 ? "reading" : "writing",
205 segment_id, old_segment_id);
206 if (ft_driver_state != old_ft_driver_state) { /* when verifying */
207 old_segment_id = -1;
208 old_ft_driver_state = ft_driver_state;
209 }
210 if (segment_id == old_segment_id) {
211 ++buff->retry;
212 ++ft_history.retries;
213 TRACE(ft_t_flow, "setting up for retry nr %d", buff->retry);
214 retry = 1;
215 if (skip && buff->skip > 0) { /* allow skip on retry */
216 offset = buff->skip;
217 count -= offset;
218 TRACE(ft_t_flow, "skipping %d sectors", offset);
219 }
220 } else {
221 buff->retry = 0;
222 buff->skip = 0;
223 old_segment_id = segment_id;
224 }
225 result = setup_segment(buff, segment_id, offset, count, retry);
226 TRACE_EXIT result;
227}
228
229/* Determine size of next cluster of good sectors.
230 */
231int ftape_calc_next_cluster(buffer_struct * buff)
232{
233 /* Skip bad sectors.
234 */
235 while (buff->remaining > 0 && (buff->bad_sector_map & 1) != 0) {
236 buff->bad_sector_map >>= 1;
237 ++buff->sector_offset;
238 --buff->remaining;
239 }
240 /* Find next cluster of good sectors
241 */
242 if (buff->bad_sector_map == 0) { /* speed up */
243 buff->sector_count = buff->remaining;
244 } else {
245 SectorMap map = buff->bad_sector_map;
246
247 buff->sector_count = 0;
248 while (buff->sector_count < buff->remaining && (map & 1) == 0) {
249 ++buff->sector_count;
250 map >>= 1;
251 }
252 }
253 return buff->sector_count;
254}
255
256/* if just passed the last segment on a track, wait for BOT
257 * or EOT mark.
258 */
259int ftape_handle_logical_eot(void)
260{
261 TRACE_FUN(ft_t_flow);
262
263 if (ft_runner_status == logical_eot) {
264 int status;
265
266 TRACE(ft_t_noise, "tape at logical EOT");
267 TRACE_CATCH(ftape_ready_wait(ftape_timeout.seek, &status),);
268 if ((status & (QIC_STATUS_AT_BOT | QIC_STATUS_AT_EOT)) == 0) {
269 TRACE_ABORT(-EIO, ft_t_err, "eot/bot not reached");
270 }
271 ft_runner_status = end_of_tape;
272 }
273 if (ft_runner_status == end_of_tape) {
274 TRACE(ft_t_noise, "runner stopped because of logical EOT");
275 ft_runner_status = idle;
276 }
277 TRACE_EXIT 0;
278}
279
280static int check_bot_eot(int status)
281{
282 TRACE_FUN(ft_t_flow);
283
284 if (status & (QIC_STATUS_AT_BOT | QIC_STATUS_AT_EOT)) {
285 ft_location.bot = ((ft_location.track & 1) == 0 ?
286 (status & QIC_STATUS_AT_BOT) != 0:
287 (status & QIC_STATUS_AT_EOT) != 0);
288 ft_location.eot = !ft_location.bot;
289 ft_location.segment = (ft_location.track +
290 (ft_location.bot ? 0 : 1)) * ft_segments_per_track - 1;
291 ft_location.sector = -1;
292 ft_location.known = 1;
293 TRACE(ft_t_flow, "tape at logical %s",
294 ft_location.bot ? "bot" : "eot");
295 TRACE(ft_t_flow, "segment = %d", ft_location.segment);
296 } else {
297 ft_location.known = 0;
298 }
299 TRACE_EXIT ft_location.known;
300}
301
302/* Read Id of first sector passing tape head.
303 */
304static int ftape_read_id(void)
305{
306 int status;
307 __u8 out[2];
308 TRACE_FUN(ft_t_any);
309
310 /* Assume tape is running on entry, be able to handle
311 * situation where it stopped or is stopping.
312 */
313 ft_location.known = 0; /* default is location not known */
314 out[0] = FDC_READID;
315 out[1] = ft_drive_sel;
316 TRACE_CATCH(fdc_command(out, 2),);
317 switch (fdc_interrupt_wait(20 * FT_SECOND)) {
318 case 0:
319 if (fdc_sect == 0) {
320 if (ftape_report_drive_status(&status) >= 0 &&
321 (status & QIC_STATUS_READY)) {
322 ftape_tape_running = 0;
323 TRACE(ft_t_flow, "tape has stopped");
324 check_bot_eot(status);
325 }
326 } else {
327 ft_location.known = 1;
328 ft_location.segment = (ftape_segments_per_head
329 * fdc_head
330 + ftape_segments_per_cylinder
331 * fdc_cyl
332 + (fdc_sect - 1)
333 / FT_SECTORS_PER_SEGMENT);
334 ft_location.sector = ((fdc_sect - 1)
335 % FT_SECTORS_PER_SEGMENT);
336 ft_location.eot = ft_location.bot = 0;
337 }
338 break;
339 case -ETIME:
340 /* Didn't find id on tape, must be near end: Wait
341 * until stopped.
342 */
343 if (ftape_ready_wait(FT_FOREVER, &status) >= 0) {
344 ftape_tape_running = 0;
345 TRACE(ft_t_flow, "tape has stopped");
346 check_bot_eot(status);
347 }
348 break;
349 default:
350 /* Interrupted or otherwise failing
351 * fdc_interrupt_wait()
352 */
353 TRACE(ft_t_err, "fdc_interrupt_wait failed");
354 break;
355 }
356 if (!ft_location.known) {
357 TRACE_ABORT(-EIO, ft_t_flow, "no id found");
358 }
359 if (ft_location.sector == 0) {
360 TRACE(ft_t_flow, "passing segment %d/%d",
361 ft_location.segment, ft_location.sector);
362 } else {
363 TRACE(ft_t_fdc_dma, "passing segment %d/%d",
364 ft_location.segment, ft_location.sector);
365 }
366 TRACE_EXIT 0;
367}
368
369static int logical_forward(void)
370{
371 ftape_tape_running = 1;
372 return ftape_command(QIC_LOGICAL_FORWARD);
373}
374
375int ftape_stop_tape(int *pstatus)
376{
377 int retry = 0;
378 int result;
379 TRACE_FUN(ft_t_flow);
380
381 do {
382 result = ftape_command_wait(QIC_STOP_TAPE,
383 ftape_timeout.stop, pstatus);
384 if (result == 0) {
385 if ((*pstatus & QIC_STATUS_READY) == 0) {
386 result = -EIO;
387 } else {
388 ftape_tape_running = 0;
389 }
390 }
391 } while (result < 0 && ++retry <= 3);
392 if (result < 0) {
393 TRACE(ft_t_err, "failed ! (fatal)");
394 }
395 TRACE_EXIT result;
396}
397
398int ftape_dumb_stop(void)
399{
400 int result;
401 int status;
402 TRACE_FUN(ft_t_flow);
403
404 /* Abort current fdc operation if it's busy (probably read
405 * or write operation pending) with a reset.
406 */
407 if (fdc_ready_wait(100 /* usec */) < 0) {
408 TRACE(ft_t_noise, "aborting fdc operation");
409 fdc_reset();
410 }
411 /* Reading id's after the last segment on a track may fail
412 * but eventually the drive will become ready (logical eot).
413 */
414 result = ftape_report_drive_status(&status);
415 ft_location.known = 0;
416 do {
417 if (result == 0 && status & QIC_STATUS_READY) {
418 /* Tape is not running any more.
419 */
420 TRACE(ft_t_noise, "tape already halted");
421 check_bot_eot(status);
422 ftape_tape_running = 0;
423 } else if (ftape_tape_running) {
424 /* Tape is (was) still moving.
425 */
426#ifdef TESTING
427 ftape_read_id();
428#endif
429 result = ftape_stop_tape(&status);
430 } else {
431 /* Tape not yet ready but stopped.
432 */
433 result = ftape_ready_wait(ftape_timeout.pause,&status);
434 }
435 } while (ftape_tape_running
436 && !(sigtestsetmask(&current->pending.signal, _NEVER_BLOCK)));
437#ifndef TESTING
438 ft_location.known = 0;
439#endif
440 if (ft_runner_status == aborting || ft_runner_status == do_abort) {
441 ft_runner_status = idle;
442 }
443 TRACE_EXIT result;
444}
445
446/* Wait until runner has finished tail buffer.
447 *
448 */
449int ftape_wait_segment(buffer_state_enum state)
450{
451 int status;
452 int result = 0;
453 TRACE_FUN(ft_t_flow);
454
455 while (ft_buffer[ft_tail]->status == state) {
456 TRACE(ft_t_flow, "state: %d", ft_buffer[ft_tail]->status);
457 /* First buffer still being worked on, wait up to timeout.
458 *
459 * Note: we check two times for being killed. 50
460 * seconds are quite long. Note that
461 * fdc_interrupt_wait() is not killable by any
462 * means. ftape_read_segment() wants us to return
463 * -EINTR in case of a signal.
464 */
465 FT_SIGNAL_EXIT(_DONT_BLOCK);
466 result = fdc_interrupt_wait(50 * FT_SECOND);
467 FT_SIGNAL_EXIT(_DONT_BLOCK);
468 if (result < 0) {
469 TRACE_ABORT(result,
470 ft_t_err, "fdc_interrupt_wait failed");
471 }
472 if (fdc_setup_error) {
473 /* recover... FIXME */
474 TRACE_ABORT(-EIO, ft_t_err, "setup error");
475 }
476 }
477 if (ft_buffer[ft_tail]->status != error) {
478 TRACE_EXIT 0;
479 }
480 TRACE_CATCH(ftape_report_drive_status(&status),);
481 TRACE(ft_t_noise, "ftape_report_drive_status: 0x%02x", status);
482 if ((status & QIC_STATUS_READY) &&
483 (status & QIC_STATUS_ERROR)) {
484 unsigned int error;
485 qic117_cmd_t command;
486
487 /* Report and clear error state.
488 * In case the drive can't operate at the selected
489 * rate, select the next lower data rate.
490 */
491 ftape_report_error(&error, &command, 1);
492 if (error == 31 && command == QIC_LOGICAL_FORWARD) {
493 /* drive does not accept this data rate */
494 if (ft_data_rate > 250) {
495 TRACE(ft_t_info,
496 "Probable data rate conflict");
497 TRACE(ft_t_info,
498 "Lowering data rate to %d Kbps",
499 ft_data_rate / 2);
500 ftape_half_data_rate();
501 if (ft_buffer[ft_tail]->retry > 0) {
502 /* give it a chance */
503 --ft_buffer[ft_tail]->retry;
504 }
505 } else {
506 /* no rate is accepted... */
507 TRACE(ft_t_err, "We're dead :(");
508 }
509 } else {
510 TRACE(ft_t_err, "Unknown error");
511 }
512 TRACE_EXIT -EIO; /* g.p. error */
513 }
514 TRACE_EXIT 0;
515}
516
517/* forward */ static int seek_forward(int segment_id, int fast);
518
519static int fast_seek(int count, int reverse)
520{
521 int result = 0;
522 int status;
523 TRACE_FUN(ft_t_flow);
524
525 if (count > 0) {
526 /* If positioned at begin or end of tape, fast seeking needs
527 * special treatment.
528 * Starting from logical bot needs a (slow) seek to the first
529 * segment before the high speed seek. Most drives do this
530 * automatically but some older don't, so we treat them
531 * all the same.
532 * Starting from logical eot is even more difficult because
533 * we cannot (slow) reverse seek to the last segment.
534 * TO BE IMPLEMENTED.
535 */
536 inhibit_correction = 0;
537 if (ft_location.known &&
538 ((ft_location.bot && !reverse) ||
539 (ft_location.eot && reverse))) {
540 if (!reverse) {
541 /* (slow) skip to first segment on a track
542 */
543 seek_forward(ft_location.track * ft_segments_per_track, 0);
544 --count;
545 } else {
546 /* When seeking backwards from
547 * end-of-tape the number of erased
548 * gaps found seems to be higher than
549 * expected. Therefor the drive must
550 * skip some more segments than
551 * calculated, but we don't know how
552 * many. Thus we will prevent the
553 * re-calculation of offset and
554 * overshoot when seeking backwards.
555 */
556 inhibit_correction = 1;
557 count += 3; /* best guess */
558 }
559 }
560 } else {
561 TRACE(ft_t_flow, "warning: zero or negative count: %d", count);
562 }
563 if (count > 0) {
564 int i;
565 int nibbles = count > 255 ? 3 : 2;
566
567 if (count > 4095) {
568 TRACE(ft_t_noise, "skipping clipped at 4095 segment");
569 count = 4095;
570 }
571 /* Issue this tape command first. */
572 if (!reverse) {
573 TRACE(ft_t_noise, "skipping %d segment(s)", count);
574 result = ftape_command(nibbles == 3 ?
575 QIC_SKIP_EXTENDED_FORWARD : QIC_SKIP_FORWARD);
576 } else {
577 TRACE(ft_t_noise, "backing up %d segment(s)", count);
578 result = ftape_command(nibbles == 3 ?
579 QIC_SKIP_EXTENDED_REVERSE : QIC_SKIP_REVERSE);
580 }
581 if (result < 0) {
582 TRACE(ft_t_noise, "Skip command failed");
583 } else {
584 --count; /* 0 means one gap etc. */
585 for (i = 0; i < nibbles; ++i) {
586 if (result >= 0) {
587 result = ftape_parameter(count & 15);
588 count /= 16;
589 }
590 }
591 result = ftape_ready_wait(ftape_timeout.rewind, &status);
592 if (result >= 0) {
593 ftape_tape_running = 0;
594 }
595 }
596 }
597 TRACE_EXIT result;
598}
599
600static int validate(int id)
601{
602 /* Check to see if position found is off-track as reported
603 * once. Because all tracks in one direction lie next to
604 * each other, if off-track the error will be approximately
605 * 2 * ft_segments_per_track.
606 */
607 if (ft_location.track == -1) {
608 return 1; /* unforseen situation, don't generate error */
609 } else {
610 /* Use margin of ft_segments_per_track on both sides
611 * because ftape needs some margin and the error we're
612 * looking for is much larger !
613 */
614 int lo = (ft_location.track - 1) * ft_segments_per_track;
615 int hi = (ft_location.track + 2) * ft_segments_per_track;
616
617 return (id >= lo && id < hi);
618 }
619}
620
621static int seek_forward(int segment_id, int fast)
622{
623 int failures = 0;
624 int count;
625 static int margin = 1; /* fixed: stop this before target */
626 static int overshoot = 1;
627 static int min_count = 8;
628 int expected = -1;
629 int target = segment_id - margin;
630 int fast_seeking;
631 int prev_segment = ft_location.segment;
632 TRACE_FUN(ft_t_flow);
633
634 if (!ft_location.known) {
635 TRACE_ABORT(-EIO, ft_t_err,
636 "fatal: cannot seek from unknown location");
637 }
638 if (!validate(segment_id)) {
639 ftape_sleep(1 * FT_SECOND);
640 ft_failure = 1;
641 TRACE_ABORT(-EIO, ft_t_err,
642 "fatal: head off track (bad hardware?)");
643 }
644 TRACE(ft_t_noise, "from %d/%d to %d/0 - %d",
645 ft_location.segment, ft_location.sector,segment_id,margin);
646 count = target - ft_location.segment - overshoot;
647 fast_seeking = (fast &&
648 count > (min_count + (ft_location.bot ? 1 : 0)));
649 if (fast_seeking) {
650 TRACE(ft_t_noise, "fast skipping %d segments", count);
651 expected = segment_id - margin;
652 fast_seek(count, 0);
653 }
654 if (!ftape_tape_running) {
655 logical_forward();
656 }
657 while (ft_location.segment < segment_id) {
658 /* This requires at least one sector in a (bad) segment to
659 * have a valid and readable sector id !
660 * It looks like this is not guaranteed, so we must try
661 * to find a way to skip an EMPTY_SEGMENT. !!! FIXME !!!
662 */
663 if (ftape_read_id() < 0 || !ft_location.known ||
664 sigtestsetmask(&current->pending.signal, _DONT_BLOCK)) {
665 ft_location.known = 0;
666 if (!ftape_tape_running ||
667 ++failures > FT_SECTORS_PER_SEGMENT) {
668 TRACE_ABORT(-EIO, ft_t_err,
669 "read_id failed completely");
670 }
671 FT_SIGNAL_EXIT(_DONT_BLOCK);
672 TRACE(ft_t_flow, "read_id failed, retry (%d)",
673 failures);
674 continue;
675 }
676 if (fast_seeking) {
677 TRACE(ft_t_noise, "ended at %d/%d (%d,%d)",
678 ft_location.segment, ft_location.sector,
679 overshoot, inhibit_correction);
680 if (!inhibit_correction &&
681 (ft_location.segment < expected ||
682 ft_location.segment > expected + margin)) {
683 int error = ft_location.segment - expected;
684 TRACE(ft_t_noise,
685 "adjusting overshoot from %d to %d",
686 overshoot, overshoot + error);
687 overshoot += error;
688 /* All overshoots have the same
689 * direction, so it should never
690 * become negative, but who knows.
691 */
692 if (overshoot < -5 ||
693 overshoot > OVERSHOOT_LIMIT) {
694 if (overshoot < 0) {
695 /* keep sane value */
696 overshoot = -5;
697 } else {
698 /* keep sane value */
699 overshoot = OVERSHOOT_LIMIT;
700 }
701 TRACE(ft_t_noise,
702 "clipped overshoot to %d",
703 overshoot);
704 }
705 }
706 fast_seeking = 0;
707 }
708 if (ft_location.known) {
709 if (ft_location.segment > prev_segment + 1) {
710 TRACE(ft_t_noise,
711 "missed segment %d while skipping",
712 prev_segment + 1);
713 }
714 prev_segment = ft_location.segment;
715 }
716 }
717 if (ft_location.segment > segment_id) {
718 TRACE_ABORT(-EIO,
719 ft_t_noise, "failed: skip ended at segment %d/%d",
720 ft_location.segment, ft_location.sector);
721 }
722 TRACE_EXIT 0;
723}
724
725static int skip_reverse(int segment_id, int *pstatus)
726{
727 int failures = 0;
728 static int overshoot = 1;
729 static int min_rewind = 2; /* 1 + overshoot */
730 static const int margin = 1; /* stop this before target */
731 int expected = 0;
732 int count = 1;
733 int short_seek;
734 int target = segment_id - margin;
735 TRACE_FUN(ft_t_flow);
736
737 if (ft_location.known && !validate(segment_id)) {
738 ftape_sleep(1 * FT_SECOND);
739 ft_failure = 1;
740 TRACE_ABORT(-EIO, ft_t_err,
741 "fatal: head off track (bad hardware?)");
742 }
743 do {
744 if (!ft_location.known) {
745 TRACE(ft_t_warn, "warning: location not known");
746 }
747 TRACE(ft_t_noise, "from %d/%d to %d/0 - %d",
748 ft_location.segment, ft_location.sector,
749 segment_id, margin);
750 /* min_rewind == 1 + overshoot_when_doing_minimum_rewind
751 * overshoot == overshoot_when_doing_larger_rewind
752 * Initially min_rewind == 1 + overshoot, optimization
753 * of both values will be done separately.
754 * overshoot and min_rewind can be negative as both are
755 * sums of three components:
756 * any_overshoot == rewind_overshoot -
757 * stop_overshoot -
758 * start_overshoot
759 */
760 if (ft_location.segment - target - (min_rewind - 1) < 1) {
761 short_seek = 1;
762 } else {
763 count = ft_location.segment - target - overshoot;
764 short_seek = (count < 1);
765 }
766 if (short_seek) {
767 count = 1; /* do shortest rewind */
768 expected = ft_location.segment - min_rewind;
769 if (expected/ft_segments_per_track != ft_location.track) {
770 expected = (ft_location.track *
771 ft_segments_per_track);
772 }
773 } else {
774 expected = target;
775 }
776 fast_seek(count, 1);
777 logical_forward();
778 if (ftape_read_id() < 0 || !ft_location.known ||
779 (sigtestsetmask(&current->pending.signal, _DONT_BLOCK))) {
780 if ((!ftape_tape_running && !ft_location.known) ||
781 ++failures > FT_SECTORS_PER_SEGMENT) {
782 TRACE_ABORT(-EIO, ft_t_err,
783 "read_id failed completely");
784 }
785 FT_SIGNAL_EXIT(_DONT_BLOCK);
786 TRACE_CATCH(ftape_report_drive_status(pstatus),);
787 TRACE(ft_t_noise, "ftape_read_id failed, retry (%d)",
788 failures);
789 continue;
790 }
791 TRACE(ft_t_noise, "ended at %d/%d (%d,%d,%d)",
792 ft_location.segment, ft_location.sector,
793 min_rewind, overshoot, inhibit_correction);
794 if (!inhibit_correction &&
795 (ft_location.segment < expected ||
796 ft_location.segment > expected + margin)) {
797 int error = expected - ft_location.segment;
798 if (short_seek) {
799 TRACE(ft_t_noise,
800 "adjusting min_rewind from %d to %d",
801 min_rewind, min_rewind + error);
802 min_rewind += error;
803 if (min_rewind < -5) {
804 /* is this right ? FIXME ! */
805 /* keep sane value */
806 min_rewind = -5;
807 TRACE(ft_t_noise,
808 "clipped min_rewind to %d",
809 min_rewind);
810 }
811 } else {
812 TRACE(ft_t_noise,
813 "adjusting overshoot from %d to %d",
814 overshoot, overshoot + error);
815 overshoot += error;
816 if (overshoot < -5 ||
817 overshoot > OVERSHOOT_LIMIT) {
818 if (overshoot < 0) {
819 /* keep sane value */
820 overshoot = -5;
821 } else {
822 /* keep sane value */
823 overshoot = OVERSHOOT_LIMIT;
824 }
825 TRACE(ft_t_noise,
826 "clipped overshoot to %d",
827 overshoot);
828 }
829 }
830 }
831 } while (ft_location.segment > segment_id);
832 if (ft_location.known) {
833 TRACE(ft_t_noise, "current location: %d/%d",
834 ft_location.segment, ft_location.sector);
835 }
836 TRACE_EXIT 0;
837}
838
839static int determine_position(void)
840{
841 int retry = 0;
842 int status;
843 int result;
844 TRACE_FUN(ft_t_flow);
845
846 if (!ftape_tape_running) {
847 /* This should only happen if tape is stopped by isr.
848 */
849 TRACE(ft_t_flow, "waiting for tape stop");
850 if (ftape_ready_wait(ftape_timeout.pause, &status) < 0) {
851 TRACE(ft_t_flow, "drive still running (fatal)");
852 ftape_tape_running = 1; /* ? */
853 }
854 } else {
855 ftape_report_drive_status(&status);
856 }
857 if (status & QIC_STATUS_READY) {
858 /* Drive must be ready to check error state !
859 */
860 TRACE(ft_t_flow, "drive is ready");
861 if (status & QIC_STATUS_ERROR) {
862 unsigned int error;
863 qic117_cmd_t command;
864
865 /* Report and clear error state, try to continue.
866 */
867 TRACE(ft_t_flow, "error status set");
868 ftape_report_error(&error, &command, 1);
869 ftape_ready_wait(ftape_timeout.reset, &status);
870 ftape_tape_running = 0; /* ? */
871 }
872 if (check_bot_eot(status)) {
873 if (ft_location.bot) {
874 if ((status & QIC_STATUS_READY) == 0) {
875 /* tape moving away from
876 * bot/eot, let's see if we
877 * can catch up with the first
878 * segment on this track.
879 */
880 } else {
881 TRACE(ft_t_flow,
882 "start tape from logical bot");
883 logical_forward(); /* start moving */
884 }
885 } else {
886 if ((status & QIC_STATUS_READY) == 0) {
887 TRACE(ft_t_noise, "waiting for logical end of track");
888 result = ftape_ready_wait(ftape_timeout.reset, &status);
889 /* error handling needed ? */
890 } else {
891 TRACE(ft_t_noise,
892 "tape at logical end of track");
893 }
894 }
895 } else {
896 TRACE(ft_t_flow, "start tape");
897 logical_forward(); /* start moving */
898 ft_location.known = 0; /* not cleared by logical forward ! */
899 }
900 }
901 /* tape should be moving now, start reading id's
902 */
903 while (!ft_location.known &&
904 retry++ < FT_SECTORS_PER_SEGMENT &&
905 (result = ftape_read_id()) < 0) {
906
907 TRACE(ft_t_flow, "location unknown");
908
909 /* exit on signal
910 */
911 FT_SIGNAL_EXIT(_DONT_BLOCK);
912
913 /* read-id somehow failed, tape may
914 * have reached end or some other
915 * error happened.
916 */
917 TRACE(ft_t_flow, "read-id failed");
918 TRACE_CATCH(ftape_report_drive_status(&status),);
919 TRACE(ft_t_err, "ftape_report_drive_status: 0x%02x", status);
920 if (status & QIC_STATUS_READY) {
921 ftape_tape_running = 0;
922 TRACE(ft_t_noise, "tape stopped for unknown reason! "
923 "status = 0x%02x", status);
924 if (status & QIC_STATUS_ERROR ||
925 !check_bot_eot(status)) {
926 /* oops, tape stopped but not at end!
927 */
928 TRACE_EXIT -EIO;
929 }
930 }
931 }
932 TRACE(ft_t_flow,
933 "tape is positioned at segment %d", ft_location.segment);
934 TRACE_EXIT ft_location.known ? 0 : -EIO;
935}
936
937/* Get the tape running and position it just before the
938 * requested segment.
939 * Seek tape-track and reposition as needed.
940 */
941int ftape_start_tape(int segment_id, int sector_offset)
942{
943 int track = segment_id / ft_segments_per_track;
944 int result = -EIO;
945 int status;
946 static int last_segment = -1;
947 static int bad_bus_timing = 0;
948 /* number of segments passing the head between starting the tape
949 * and being able to access the first sector.
950 */
951 static int start_offset = 1;
952 int retry;
953 TRACE_FUN(ft_t_flow);
954
955 /* If sector_offset > 0, seek into wanted segment instead of
956 * into previous.
957 * This allows error recovery if a part of the segment is bad
958 * (erased) causing the tape drive to generate an index pulse
959 * thus causing a no-data error before the requested sector
960 * is reached.
961 */
962 ftape_tape_running = 0;
963 TRACE(ft_t_noise, "target segment: %d/%d%s", segment_id, sector_offset,
964 ft_buffer[ft_head]->retry > 0 ? " retry" : "");
965 if (ft_buffer[ft_head]->retry > 0) { /* this is a retry */
966 int dist = segment_id - last_segment;
967
968 if ((int)ft_history.overrun_errors < overrun_count_offset) {
969 overrun_count_offset = ft_history.overrun_errors;
970 } else if (dist < 0 || dist > 50) {
971 overrun_count_offset = ft_history.overrun_errors;
972 } else if ((ft_history.overrun_errors -
973 overrun_count_offset) >= 8) {
974 if (ftape_increase_threshold() >= 0) {
975 --ft_buffer[ft_head]->retry;
976 overrun_count_offset =
977 ft_history.overrun_errors;
978 TRACE(ft_t_warn, "increased threshold because "
979 "of excessive overrun errors");
980 } else if (!bad_bus_timing && ft_data_rate >= 1000) {
981 ftape_half_data_rate();
982 --ft_buffer[ft_head]->retry;
983 bad_bus_timing = 1;
984 overrun_count_offset =
985 ft_history.overrun_errors;
986 TRACE(ft_t_warn, "reduced datarate because "
987 "of excessive overrun errors");
988 }
989 }
990 }
991 last_segment = segment_id;
992 if (ft_location.track != track ||
993 (ftape_might_be_off_track && ft_buffer[ft_head]->retry== 0)) {
994 /* current track unknown or not equal to destination
995 */
996 ftape_ready_wait(ftape_timeout.seek, &status);
997 ftape_seek_head_to_track(track);
998 /* overrun_count_offset = ft_history.overrun_errors; */
999 }
1000 result = -EIO;
1001 retry = 0;
1002 while (result < 0 &&
1003 retry++ <= 5 &&
1004 !ft_failure &&
1005 !(sigtestsetmask(&current->pending.signal, _DONT_BLOCK))) {
1006
1007 if (retry && start_offset < 5) {
1008 start_offset ++;
1009 }
1010 /* Check if we are able to catch the requested
1011 * segment in time.
1012 */
1013 if ((ft_location.known || (determine_position() == 0)) &&
1014 ft_location.segment >=
1015 (segment_id -
1016 ((ftape_tape_running || ft_location.bot)
1017 ? 0 : start_offset))) {
1018 /* Too far ahead (in or past target segment).
1019 */
1020 if (ftape_tape_running) {
1021 if ((result = ftape_stop_tape(&status)) < 0) {
1022 TRACE(ft_t_err,
1023 "stop tape failed with code %d",
1024 result);
1025 break;
1026 }
1027 TRACE(ft_t_noise, "tape stopped");
1028 ftape_tape_running = 0;
1029 }
1030 TRACE(ft_t_noise, "repositioning");
1031 ++ft_history.rewinds;
1032 if (segment_id % ft_segments_per_track < start_offset){
1033 TRACE(ft_t_noise, "end of track condition\n"
1034 KERN_INFO "segment_id : %d\n"
1035 KERN_INFO "ft_segments_per_track: %d\n"
1036 KERN_INFO "start_offset : %d",
1037 segment_id, ft_segments_per_track,
1038 start_offset);
1039
1040 /* If seeking to first segments on
1041 * track better do a complete rewind
1042 * to logical begin of track to get a
1043 * more steady tape motion.
1044 */
1045 result = ftape_command_wait(
1046 (ft_location.track & 1)
1047 ? QIC_PHYSICAL_FORWARD
1048 : QIC_PHYSICAL_REVERSE,
1049 ftape_timeout.rewind, &status);
1050 check_bot_eot(status); /* update location */
1051 } else {
1052 result= skip_reverse(segment_id - start_offset,
1053 &status);
1054 }
1055 }
1056 if (!ft_location.known) {
1057 TRACE(ft_t_bug, "panic: location not known");
1058 result = -EIO;
1059 continue; /* while() will check for failure */
1060 }
1061 TRACE(ft_t_noise, "current segment: %d/%d",
1062 ft_location.segment, ft_location.sector);
1063 /* We're on the right track somewhere before the
1064 * wanted segment. Start tape movement if needed and
1065 * skip to just before or inside the requested
1066 * segment. Keep tape running.
1067 */
1068 result = 0;
1069 if (ft_location.segment <
1070 (segment_id - ((ftape_tape_running || ft_location.bot)
1071 ? 0 : start_offset))) {
1072 if (sector_offset > 0) {
1073 result = seek_forward(segment_id,
1074 retry <= 3);
1075 } else {
1076 result = seek_forward(segment_id - 1,
1077 retry <= 3);
1078 }
1079 }
1080 if (result == 0 &&
1081 ft_location.segment !=
1082 (segment_id - (sector_offset > 0 ? 0 : 1))) {
1083 result = -EIO;
1084 }
1085 }
1086 if (result < 0) {
1087 TRACE(ft_t_err, "failed to reposition");
1088 } else {
1089 ft_runner_status = running;
1090 }
1091 TRACE_EXIT result;
1092}
diff --git a/drivers/char/ftape/lowlevel/ftape-rw.h b/drivers/char/ftape/lowlevel/ftape-rw.h
deleted file mode 100644
index 32f4feeb887c..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-rw.h
+++ /dev/null
@@ -1,111 +0,0 @@
1#ifndef _FTAPE_RW_H
2#define _FTAPE_RW_H
3
4/*
5 * Copyright (C) 1993-1996 Bas Laarhoven,
6 * (C) 1996-1997 Claus-Justus Heine.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 *
23 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-rw.h,v $
24 * $Revision: 1.2 $
25 * $Date: 1997/10/05 19:18:25 $
26 *
27 * This file contains the definitions for the read and write
28 * functions for the QIC-117 floppy-tape driver for Linux.
29 *
30 * Claus-Justus Heine (1996/09/20): Add definition of format code 6
31 * Claus-Justus Heine (1996/10/04): Changed GET/PUT macros to cast to (__u8 *)
32 *
33 */
34
35#include "../lowlevel/fdc-io.h"
36#include "../lowlevel/ftape-init.h"
37#include "../lowlevel/ftape-bsm.h"
38
39#include <asm/unaligned.h>
40
41#define GET2(address, offset) get_unaligned((__u16*)((__u8 *)address + offset))
42#define GET4(address, offset) get_unaligned((__u32*)((__u8 *)address + offset))
43#define GET8(address, offset) get_unaligned((__u64*)((__u8 *)address + offset))
44#define PUT2(address, offset , value) put_unaligned((value), (__u16*)((__u8 *)address + offset))
45#define PUT4(address, offset , value) put_unaligned((value), (__u32*)((__u8 *)address + offset))
46#define PUT8(address, offset , value) put_unaligned((value), (__u64*)((__u8 *)address + offset))
47
48enum runner_status_enum {
49 idle = 0,
50 running,
51 do_abort,
52 aborting,
53 logical_eot,
54 end_of_tape,
55};
56
57typedef enum ft_buffer_queue {
58 ft_queue_head = 0,
59 ft_queue_tail = 1
60} ft_buffer_queue_t;
61
62
63typedef struct {
64 int track; /* tape head position */
65 volatile int segment; /* current segment */
66 volatile int sector; /* sector offset within current segment */
67 volatile unsigned int bot; /* logical begin of track */
68 volatile unsigned int eot; /* logical end of track */
69 volatile unsigned int known; /* validates bot, segment, sector */
70} location_record;
71
72/* Count nr of 1's in pattern.
73 */
74static inline int count_ones(unsigned long mask)
75{
76 int bits;
77
78 for (bits = 0; mask != 0; mask >>= 1) {
79 if (mask & 1) {
80 ++bits;
81 }
82 }
83 return bits;
84}
85
86#define FT_MAX_NR_BUFFERS 16 /* arbitrary value */
87/* ftape-rw.c defined global vars.
88 */
89extern buffer_struct *ft_buffer[FT_MAX_NR_BUFFERS];
90extern int ft_nr_buffers;
91extern location_record ft_location;
92extern volatile int ftape_tape_running;
93
94/* ftape-rw.c defined global functions.
95 */
96extern int ftape_setup_new_segment(buffer_struct * buff,
97 int segment_id,
98 int offset);
99extern int ftape_calc_next_cluster(buffer_struct * buff);
100extern buffer_struct *ftape_next_buffer (ft_buffer_queue_t pos);
101extern buffer_struct *ftape_get_buffer (ft_buffer_queue_t pos);
102extern int ftape_buffer_id (ft_buffer_queue_t pos);
103extern void ftape_reset_buffer(void);
104extern void ftape_tape_parameters(__u8 drive_configuration);
105extern int ftape_wait_segment(buffer_state_enum state);
106extern int ftape_dumb_stop(void);
107extern int ftape_start_tape(int segment_id, int offset);
108extern int ftape_stop_tape(int *pstatus);
109extern int ftape_handle_logical_eot(void);
110extern buffer_state_enum ftape_set_state(buffer_state_enum new_state);
111#endif /* _FTAPE_RW_H */
diff --git a/drivers/char/ftape/lowlevel/ftape-setup.c b/drivers/char/ftape/lowlevel/ftape-setup.c
deleted file mode 100644
index 678340acd0b7..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-setup.c
+++ /dev/null
@@ -1,104 +0,0 @@
1/*
2 * Copyright (C) 1996, 1997 Claus-Justus Heine.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 *
19 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-setup.c,v $
20 * $Revision: 1.7 $
21 * $Date: 1997/10/10 09:57:06 $
22 *
23 * This file contains the code for processing the kernel command
24 * line options for the QIC-40/80/3010/3020 floppy-tape driver
25 * "ftape" for Linux.
26 */
27
28#include <linux/string.h>
29#include <linux/errno.h>
30#include <linux/mm.h>
31
32#include <linux/ftape.h>
33#include <linux/init.h>
34#include "../lowlevel/ftape-tracing.h"
35#include "../lowlevel/fdc-io.h"
36
37static struct param_table {
38 const char *name;
39 int *var;
40 int def_param;
41 int min;
42 int max;
43} config_params[] __initdata = {
44#ifndef CONFIG_FT_NO_TRACE_AT_ALL
45 { "tracing", &ftape_tracing, 3, ft_t_bug, ft_t_any},
46#endif
47 { "ioport", &ft_fdc_base, CONFIG_FT_FDC_BASE, 0x0, 0xfff},
48 { "irq", &ft_fdc_irq, CONFIG_FT_FDC_IRQ, 2, 15},
49 { "dma", &ft_fdc_dma, CONFIG_FT_FDC_DMA, 0, 3},
50 { "threshold", &ft_fdc_threshold, CONFIG_FT_FDC_THR, 1, 16},
51 { "datarate", &ft_fdc_rate_limit, CONFIG_FT_FDC_MAX_RATE, 500, 2000},
52 { "fc10", &ft_probe_fc10, CONFIG_FT_PROBE_FC10, 0, 1},
53 { "mach2", &ft_mach2, CONFIG_FT_MACH2, 0, 1}
54};
55
56static int __init ftape_setup(char *str)
57{
58 int i;
59 int param;
60 int ints[2];
61
62 TRACE_FUN(ft_t_flow);
63
64 str = get_options(str, ARRAY_SIZE(ints), ints);
65 if (str) {
66 for (i=0; i < NR_ITEMS(config_params); i++) {
67 if (strcmp(str,config_params[i].name) == 0){
68 if (ints[0]) {
69 param = ints[1];
70 } else {
71 param = config_params[i].def_param;
72 }
73 if (param < config_params[i].min ||
74 param > config_params[i].max) {
75 TRACE(ft_t_err,
76 "parameter %s out of range %d ... %d",
77 config_params[i].name,
78 config_params[i].min,
79 config_params[i].max);
80 goto out;
81 }
82 if(config_params[i].var) {
83 TRACE(ft_t_info, "%s=%d", str, param);
84 *config_params[i].var = param;
85 }
86 goto out;
87 }
88 }
89 }
90 if (str) {
91 TRACE(ft_t_err, "unknown ftape option [%s]", str);
92
93 TRACE(ft_t_err, "allowed options are:");
94 for (i=0; i < NR_ITEMS(config_params); i++) {
95 TRACE(ft_t_err, " %s",config_params[i].name);
96 }
97 } else {
98 TRACE(ft_t_err, "botched ftape option");
99 }
100 out:
101 TRACE_EXIT 1;
102}
103
104__setup("ftape=", ftape_setup);
diff --git a/drivers/char/ftape/lowlevel/ftape-tracing.c b/drivers/char/ftape/lowlevel/ftape-tracing.c
deleted file mode 100644
index 7fdc6567440b..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-tracing.c
+++ /dev/null
@@ -1,118 +0,0 @@
1/*
2 * Copyright (C) 1993-1996 Bas Laarhoven,
3 * (C) 1996-1997 Claus-Justus Heine.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 *
20 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-tracing.c,v $
21 * $Revision: 1.2 $
22 * $Date: 1997/10/05 19:18:27 $
23 *
24 * This file contains the reading code
25 * for the QIC-117 floppy-tape driver for Linux.
26 */
27
28#include <linux/ftape.h>
29#include "../lowlevel/ftape-tracing.h"
30
31/* Global vars.
32 */
33/* tracing
34 * set it to: to log :
35 * 0 bugs
36 * 1 + errors
37 * 2 + warnings
38 * 3 + information
39 * 4 + more information
40 * 5 + program flow
41 * 6 + fdc/dma info
42 * 7 + data flow
43 * 8 + everything else
44 */
45ft_trace_t ftape_tracing = ft_t_info; /* Default level: information and up */
46int ftape_function_nest_level;
47
48/* Local vars.
49 */
50static __u8 trace_id;
51static char spacing[] = "* ";
52
53void ftape_trace_call(const char *file, const char *name)
54{
55 char *indent;
56
57 /* Since printk seems not to work with "%*s" format
58 * we'll use this work-around.
59 */
60 if (ftape_function_nest_level < 0) {
61 printk(KERN_INFO "function nest level (%d) < 0\n",
62 ftape_function_nest_level);
63 ftape_function_nest_level = 0;
64 }
65 if (ftape_function_nest_level < sizeof(spacing)) {
66 indent = (spacing +
67 sizeof(spacing) - 1 -
68 ftape_function_nest_level);
69 } else {
70 indent = spacing;
71 }
72 printk(KERN_INFO "[%03d]%s+%s (%s)\n",
73 (int) trace_id++, indent, file, name);
74}
75
76void ftape_trace_exit(const char *file, const char *name)
77{
78 char *indent;
79
80 /* Since printk seems not to work with "%*s" format
81 * we'll use this work-around.
82 */
83 if (ftape_function_nest_level < 0) {
84 printk(KERN_INFO "function nest level (%d) < 0\n", ftape_function_nest_level);
85 ftape_function_nest_level = 0;
86 }
87 if (ftape_function_nest_level < sizeof(spacing)) {
88 indent = (spacing +
89 sizeof(spacing) - 1 -
90 ftape_function_nest_level);
91 } else {
92 indent = spacing;
93 }
94 printk(KERN_INFO "[%03d]%s-%s (%s)\n",
95 (int) trace_id++, indent, file, name);
96}
97
98void ftape_trace_log(const char *file, const char *function)
99{
100 char *indent;
101
102 /* Since printk seems not to work with "%*s" format
103 * we'll use this work-around.
104 */
105 if (ftape_function_nest_level < 0) {
106 printk(KERN_INFO "function nest level (%d) < 0\n", ftape_function_nest_level);
107 ftape_function_nest_level = 0;
108 }
109 if (ftape_function_nest_level < sizeof(spacing)) {
110 indent = (spacing +
111 sizeof(spacing) - 1 -
112 ftape_function_nest_level);
113 } else {
114 indent = spacing;
115 }
116 printk(KERN_INFO "[%03d]%s%s (%s) - ",
117 (int) trace_id++, indent, file, function);
118}
diff --git a/drivers/char/ftape/lowlevel/ftape-tracing.h b/drivers/char/ftape/lowlevel/ftape-tracing.h
deleted file mode 100644
index 2950810c7085..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-tracing.h
+++ /dev/null
@@ -1,179 +0,0 @@
1#ifndef _FTAPE_TRACING_H
2#define _FTAPE_TRACING_H
3
4/*
5 * Copyright (C) 1994-1996 Bas Laarhoven,
6 * (C) 1996-1997 Claus-Justus Heine.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 *
23 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-tracing.h,v $
24 * $Revision: 1.2 $
25 * $Date: 1997/10/05 19:18:28 $
26 *
27 * This file contains definitions that eases the debugging of the
28 * QIC-40/80/3010/3020 floppy-tape driver "ftape" for Linux.
29 */
30
31#include <linux/kernel.h>
32
33/*
34 * Be very careful with TRACE_EXIT and TRACE_ABORT.
35 *
36 * if (something) TRACE_EXIT error;
37 *
38 * will NOT work. Use
39 *
40 * if (something) {
41 * TRACE_EXIT error;
42 * }
43 *
44 * instead. Maybe a bit dangerous, but save lots of lines of code.
45 */
46
47#define LL_X "%d/%d KB"
48#define LL(x) (unsigned int)((__u64)(x)>>10), (unsigned int)((x)&1023)
49
50typedef enum {
51 ft_t_nil = -1,
52 ft_t_bug,
53 ft_t_err,
54 ft_t_warn,
55 ft_t_info,
56 ft_t_noise,
57 ft_t_flow,
58 ft_t_fdc_dma,
59 ft_t_data_flow,
60 ft_t_any
61} ft_trace_t;
62
63#ifdef CONFIG_FT_NO_TRACE_AT_ALL
64/* the compiler will optimize away most TRACE() macros
65 */
66#define FT_TRACE_TOP_LEVEL ft_t_bug
67#define TRACE_FUN(level) do {} while(0)
68#define TRACE_EXIT return
69#define TRACE(l, m, i...) \
70{ \
71 if ((ft_trace_t)(l) == FT_TRACE_TOP_LEVEL) { \
72 printk(KERN_INFO"ftape%s(%s):\n" \
73 KERN_INFO m".\n" ,__FILE__, __FUNCTION__ , ##i); \
74 } \
75}
76#define SET_TRACE_LEVEL(l) if ((l) == (l)) do {} while(0)
77#define TRACE_LEVEL FT_TRACE_TOP_LEVEL
78
79#else
80
81#ifdef CONFIG_FT_NO_TRACE
82/* the compiler will optimize away many TRACE() macros
83 * the ftape_simple_trace_call() function simply increments
84 * the function nest level.
85 */
86#define FT_TRACE_TOP_LEVEL ft_t_warn
87#define TRACE_FUN(level) ftape_function_nest_level++
88#define TRACE_EXIT ftape_function_nest_level--; return
89
90#else
91#ifdef CONFIG_FT_FULL_DEBUG
92#define FT_TRACE_TOP_LEVEL ft_t_any
93#else
94#define FT_TRACE_TOP_LEVEL ft_t_flow
95#endif
96#define TRACE_FUN(level) \
97 const ft_trace_t _tracing = level; \
98 if (ftape_tracing >= (ft_trace_t)(level) && \
99 (ft_trace_t)(level) <= FT_TRACE_TOP_LEVEL) \
100 ftape_trace_call(__FILE__, __FUNCTION__); \
101 ftape_function_nest_level ++;
102
103#define TRACE_EXIT \
104 --ftape_function_nest_level; \
105 if (ftape_tracing >= (ft_trace_t)(_tracing) && \
106 (ft_trace_t)(_tracing) <= FT_TRACE_TOP_LEVEL) \
107 ftape_trace_exit(__FILE__, __FUNCTION__); \
108 return
109
110#endif
111
112#define TRACE(l, m, i...) \
113{ \
114 if (ftape_tracing >= (ft_trace_t)(l) && \
115 (ft_trace_t)(l) <= FT_TRACE_TOP_LEVEL) { \
116 ftape_trace_log(__FILE__, __FUNCTION__); \
117 printk(m".\n" ,##i); \
118 } \
119}
120
121#define SET_TRACE_LEVEL(l) \
122{ \
123 if ((ft_trace_t)(l) <= FT_TRACE_TOP_LEVEL) { \
124 ftape_tracing = (ft_trace_t)(l); \
125 } else { \
126 ftape_tracing = FT_TRACE_TOP_LEVEL; \
127 } \
128}
129#define TRACE_LEVEL \
130((ftape_tracing <= FT_TRACE_TOP_LEVEL) ? ftape_tracing : FT_TRACE_TOP_LEVEL)
131
132
133/* Global variables declared in tracing.c
134 */
135extern ft_trace_t ftape_tracing; /* sets default level */
136extern int ftape_function_nest_level;
137
138/* Global functions declared in tracing.c
139 */
140extern void ftape_trace_call(const char *file, const char *name);
141extern void ftape_trace_exit(const char *file, const char *name);
142extern void ftape_trace_log (const char *file, const char *name);
143
144#endif /* !defined(CONFIG_FT_NO_TRACE_AT_ALL) */
145
146/*
147 * Abort with a message.
148 */
149#define TRACE_ABORT(res, i...) \
150{ \
151 TRACE(i); \
152 TRACE_EXIT res; \
153}
154
155/* The following transforms the common "if(result < 0) ... " into a
156 * one-liner.
157 */
158#define _TRACE_CATCH(level, fun, action) \
159{ \
160 int _res = (fun); \
161 if (_res < 0) { \
162 do { action /* */ ; } while(0); \
163 TRACE_ABORT(_res, level, "%s failed: %d", #fun, _res); \
164 } \
165}
166
167#define TRACE_CATCH(fun, fail) _TRACE_CATCH(ft_t_err, fun, fail)
168
169/* Abort the current function when signalled. This doesn't belong here,
170 * but rather into ftape-rw.h (maybe)
171 */
172#define FT_SIGNAL_EXIT(sig_mask) \
173 if (sigtestsetmask(&current->pending.signal, sig_mask)) { \
174 TRACE_ABORT(-EINTR, \
175 ft_t_warn, \
176 "interrupted by non-blockable signal"); \
177 }
178
179#endif /* _FTAPE_TRACING_H */
diff --git a/drivers/char/ftape/lowlevel/ftape-write.c b/drivers/char/ftape/lowlevel/ftape-write.c
deleted file mode 100644
index 45601ec801ee..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-write.c
+++ /dev/null
@@ -1,336 +0,0 @@
1/*
2 * Copyright (C) 1993-1995 Bas Laarhoven,
3 * (C) 1996-1997 Claus-Justus Heine.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 *
20 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-write.c,v $
21 * $Revision: 1.3.4.1 $
22 * $Date: 1997/11/14 18:07:04 $
23 *
24 * This file contains the writing code
25 * for the QIC-117 floppy-tape driver for Linux.
26 */
27
28#include <linux/string.h>
29#include <linux/errno.h>
30#include <linux/mm.h>
31
32#include <linux/ftape.h>
33#include <linux/qic117.h>
34#include "../lowlevel/ftape-tracing.h"
35#include "../lowlevel/ftape-write.h"
36#include "../lowlevel/ftape-read.h"
37#include "../lowlevel/ftape-io.h"
38#include "../lowlevel/ftape-ctl.h"
39#include "../lowlevel/ftape-rw.h"
40#include "../lowlevel/ftape-ecc.h"
41#include "../lowlevel/ftape-bsm.h"
42#include "../lowlevel/fdc-isr.h"
43
44/* Global vars.
45 */
46
47/* Local vars.
48 */
49static int last_write_failed;
50
51void ftape_zap_write_buffers(void)
52{
53 int i;
54
55 for (i = 0; i < ft_nr_buffers; ++i) {
56 ft_buffer[i]->status = done;
57 }
58 ftape_reset_buffer();
59}
60
61static int copy_and_gen_ecc(void *destination,
62 const void *source,
63 const SectorMap bad_sector_map)
64{
65 int result;
66 struct memory_segment mseg;
67 int bads = count_ones(bad_sector_map);
68 TRACE_FUN(ft_t_any);
69
70 if (bads > 0) {
71 TRACE(ft_t_noise, "bad sectors in map: %d", bads);
72 }
73 if (bads + 3 >= FT_SECTORS_PER_SEGMENT) {
74 TRACE(ft_t_noise, "empty segment");
75 mseg.blocks = 0; /* skip entire segment */
76 result = 0; /* nothing written */
77 } else {
78 mseg.blocks = FT_SECTORS_PER_SEGMENT - bads;
79 mseg.data = destination;
80 memcpy(mseg.data, source, (mseg.blocks - 3) * FT_SECTOR_SIZE);
81 result = ftape_ecc_set_segment_parity(&mseg);
82 if (result < 0) {
83 TRACE(ft_t_err, "ecc_set_segment_parity failed");
84 } else {
85 result = (mseg.blocks - 3) * FT_SECTOR_SIZE;
86 }
87 }
88 TRACE_EXIT result;
89}
90
91
92int ftape_start_writing(const ft_write_mode_t mode)
93{
94 buffer_struct *head = ftape_get_buffer(ft_queue_head);
95 int segment_id = head->segment_id;
96 int result;
97 buffer_state_enum wanted_state = (mode == FT_WR_DELETE
98 ? deleting
99 : writing);
100 TRACE_FUN(ft_t_flow);
101
102 if ((ft_driver_state != wanted_state) || head->status != waiting) {
103 TRACE_EXIT 0;
104 }
105 ftape_setup_new_segment(head, segment_id, 1);
106 if (mode == FT_WR_SINGLE) {
107 /* stop tape instead of pause */
108 head->next_segment = 0;
109 }
110 ftape_calc_next_cluster(head); /* prepare */
111 head->status = ft_driver_state; /* either writing or deleting */
112 if (ft_runner_status == idle) {
113 TRACE(ft_t_noise,
114 "starting runner for segment %d", segment_id);
115 TRACE_CATCH(ftape_start_tape(segment_id,head->sector_offset),);
116 } else {
117 TRACE(ft_t_noise, "runner not idle, not starting tape");
118 }
119 /* go */
120 result = fdc_setup_read_write(head, (mode == FT_WR_DELETE
121 ? FDC_WRITE_DELETED : FDC_WRITE));
122 ftape_set_state(wanted_state); /* should not be necessary */
123 TRACE_EXIT result;
124}
125
126/* Wait until all data is actually written to tape.
127 *
128 * There is a problem: when the tape runs into logical EOT, then this
129 * failes. We need to restart the runner in this case.
130 */
131int ftape_loop_until_writes_done(void)
132{
133 buffer_struct *head;
134 TRACE_FUN(ft_t_flow);
135
136 while ((ft_driver_state == writing || ft_driver_state == deleting) &&
137 ftape_get_buffer(ft_queue_head)->status != done) {
138 /* set the runner status to idle if at lEOT */
139 TRACE_CATCH(ftape_handle_logical_eot(), last_write_failed = 1);
140 /* restart the tape if necessary */
141 if (ft_runner_status == idle) {
142 TRACE(ft_t_noise, "runner is idle, restarting");
143 if (ft_driver_state == deleting) {
144 TRACE_CATCH(ftape_start_writing(FT_WR_DELETE),
145 last_write_failed = 1);
146 } else {
147 TRACE_CATCH(ftape_start_writing(FT_WR_MULTI),
148 last_write_failed = 1);
149 }
150 }
151 TRACE(ft_t_noise, "tail: %d, head: %d",
152 ftape_buffer_id(ft_queue_tail),
153 ftape_buffer_id(ft_queue_head));
154 TRACE_CATCH(fdc_interrupt_wait(5 * FT_SECOND),
155 last_write_failed = 1);
156 head = ftape_get_buffer(ft_queue_head);
157 if (head->status == error) {
158 /* Allow escape from loop when signaled !
159 */
160 FT_SIGNAL_EXIT(_DONT_BLOCK);
161 if (head->hard_error_map != 0) {
162 /* Implement hard write error recovery here
163 */
164 }
165 /* retry this one */
166 head->status = waiting;
167 if (ft_runner_status == aborting) {
168 ftape_dumb_stop();
169 }
170 if (ft_runner_status != idle) {
171 TRACE_ABORT(-EIO, ft_t_err,
172 "unexpected state: "
173 "ft_runner_status != idle");
174 }
175 ftape_start_writing(ft_driver_state == deleting
176 ? FT_WR_MULTI : FT_WR_DELETE);
177 }
178 TRACE(ft_t_noise, "looping until writes done");
179 }
180 ftape_set_state(idle);
181 TRACE_EXIT 0;
182}
183
184/* Write given segment from buffer at address to tape.
185 */
186static int write_segment(const int segment_id,
187 const void *address,
188 const ft_write_mode_t write_mode)
189{
190 int bytes_written = 0;
191 buffer_struct *tail;
192 buffer_state_enum wanted_state = (write_mode == FT_WR_DELETE
193 ? deleting : writing);
194 TRACE_FUN(ft_t_flow);
195
196 TRACE(ft_t_noise, "segment_id = %d", segment_id);
197 if (ft_driver_state != wanted_state) {
198 if (ft_driver_state == deleting ||
199 wanted_state == deleting) {
200 TRACE_CATCH(ftape_loop_until_writes_done(),);
201 }
202 TRACE(ft_t_noise, "calling ftape_abort_operation");
203 TRACE_CATCH(ftape_abort_operation(),);
204 ftape_zap_write_buffers();
205 ftape_set_state(wanted_state);
206 }
207 /* if all buffers full we'll have to wait...
208 */
209 ftape_wait_segment(wanted_state);
210 tail = ftape_get_buffer(ft_queue_tail);
211 switch(tail->status) {
212 case done:
213 ft_history.defects += count_ones(tail->hard_error_map);
214 break;
215 case waiting:
216 /* this could happen with multiple EMPTY_SEGMENTs, but
217 * shouldn't happen any more as we re-start the runner even
218 * with an empty segment.
219 */
220 bytes_written = -EAGAIN;
221 break;
222 case error:
223 /* setup for a retry
224 */
225 tail->status = waiting;
226 bytes_written = -EAGAIN; /* force retry */
227 if (tail->hard_error_map != 0) {
228 TRACE(ft_t_warn,
229 "warning: %d hard error(s) in written segment",
230 count_ones(tail->hard_error_map));
231 TRACE(ft_t_noise, "hard_error_map = 0x%08lx",
232 (long)tail->hard_error_map);
233 /* Implement hard write error recovery here
234 */
235 }
236 break;
237 default:
238 TRACE_ABORT(-EIO, ft_t_err,
239 "wait for empty segment failed, tail status: %d",
240 tail->status);
241 }
242 /* should runner stop ?
243 */
244 if (ft_runner_status == aborting) {
245 buffer_struct *head = ftape_get_buffer(ft_queue_head);
246 if (head->status == wanted_state) {
247 head->status = done; /* ???? */
248 }
249 /* don't call abort_operation(), we don't want to zap
250 * the dma buffers
251 */
252 TRACE_CATCH(ftape_dumb_stop(),);
253 } else {
254 /* If just passed last segment on tape: wait for BOT
255 * or EOT mark. Sets ft_runner_status to idle if at lEOT
256 * and successful
257 */
258 TRACE_CATCH(ftape_handle_logical_eot(),);
259 }
260 if (tail->status == done) {
261 /* now at least one buffer is empty, fill it with our
262 * data. skip bad sectors and generate ecc.
263 * copy_and_gen_ecc return nr of bytes written, range
264 * 0..29 Kb inclusive!
265 *
266 * Empty segments are handled inside coyp_and_gen_ecc()
267 */
268 if (write_mode != FT_WR_DELETE) {
269 TRACE_CATCH(bytes_written = copy_and_gen_ecc(
270 tail->address, address,
271 ftape_get_bad_sector_entry(segment_id)),);
272 }
273 tail->segment_id = segment_id;
274 tail->status = waiting;
275 tail = ftape_next_buffer(ft_queue_tail);
276 }
277 /* Start tape only if all buffers full or flush mode.
278 * This will give higher probability of streaming.
279 */
280 if (ft_runner_status != running &&
281 ((tail->status == waiting &&
282 ftape_get_buffer(ft_queue_head) == tail) ||
283 write_mode != FT_WR_ASYNC)) {
284 TRACE_CATCH(ftape_start_writing(write_mode),);
285 }
286 TRACE_EXIT bytes_written;
287}
288
289/* Write as much as fits from buffer to the given segment on tape
290 * and handle retries.
291 * Return the number of bytes written (>= 0), or:
292 * -EIO write failed
293 * -EINTR interrupted by signal
294 * -ENOSPC device full
295 */
296int ftape_write_segment(const int segment_id,
297 const void *buffer,
298 const ft_write_mode_t flush)
299{
300 int retry = 0;
301 int result;
302 TRACE_FUN(ft_t_flow);
303
304 ft_history.used |= 2;
305 if (segment_id >= ft_tracks_per_tape*ft_segments_per_track) {
306 /* tape full */
307 TRACE_ABORT(-ENOSPC, ft_t_err,
308 "invalid segment id: %d (max %d)",
309 segment_id,
310 ft_tracks_per_tape * ft_segments_per_track -1);
311 }
312 for (;;) {
313 if ((result = write_segment(segment_id, buffer, flush)) >= 0) {
314 if (result == 0) { /* empty segment */
315 TRACE(ft_t_noise,
316 "empty segment, nothing written");
317 }
318 TRACE_EXIT result;
319 }
320 if (result == -EAGAIN) {
321 if (++retry > 100) { /* give up */
322 TRACE_ABORT(-EIO, ft_t_err,
323 "write failed, >100 retries in segment");
324 }
325 TRACE(ft_t_warn, "write error, retry %d (%d)",
326 retry,
327 ftape_get_buffer(ft_queue_tail)->segment_id);
328 } else {
329 TRACE_ABORT(result, ft_t_err,
330 "write_segment failed, error: %d", result);
331 }
332 /* Allow escape from loop when signaled !
333 */
334 FT_SIGNAL_EXIT(_DONT_BLOCK);
335 }
336}
diff --git a/drivers/char/ftape/lowlevel/ftape-write.h b/drivers/char/ftape/lowlevel/ftape-write.h
deleted file mode 100644
index 0e7f898b7af9..000000000000
--- a/drivers/char/ftape/lowlevel/ftape-write.h
+++ /dev/null
@@ -1,53 +0,0 @@
1#ifndef _FTAPE_WRITE_H
2#define _FTAPE_WRITE_H
3
4/*
5 * Copyright (C) 1994-1995 Bas Laarhoven,
6 * (C) 1996-1997 Claus-Justus Heine.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 *
23 $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-write.h,v $
24 $Author: claus $
25 *
26 $Revision: 1.2 $
27 $Date: 1997/10/05 19:18:30 $
28 $State: Exp $
29 *
30 * This file contains the definitions for the write functions
31 * for the QIC-117 floppy-tape driver for Linux.
32 *
33 */
34
35
36/* ftape-write.c defined global functions.
37 */
38typedef enum {
39 FT_WR_ASYNC = 0, /* start tape only when all buffers are full */
40 FT_WR_MULTI = 1, /* start tape, but don't necessarily stop */
41 FT_WR_SINGLE = 2, /* write a single segment and stop afterwards */
42 FT_WR_DELETE = 3 /* write deleted data marks */
43} ft_write_mode_t;
44
45extern int ftape_start_writing(const ft_write_mode_t mode);
46extern int ftape_write_segment(const int segment,
47 const void *address,
48 const ft_write_mode_t flushing);
49extern void ftape_zap_write_buffers(void);
50extern int ftape_loop_until_writes_done(void);
51
52#endif /* _FTAPE_WRITE_H */
53
diff --git a/drivers/char/ftape/lowlevel/ftape_syms.c b/drivers/char/ftape/lowlevel/ftape_syms.c
deleted file mode 100644
index 8e0dc4a07ca6..000000000000
--- a/drivers/char/ftape/lowlevel/ftape_syms.c
+++ /dev/null
@@ -1,87 +0,0 @@
1/*
2 * Copyright (C) 1996-1997 Claus-Justus Heine
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 *
19 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape_syms.c,v $
20 * $Revision: 1.4 $
21 * $Date: 1997/10/17 00:03:51 $
22 *
23 * This file contains the symbols that the ftape low level
24 * part of the QIC-40/80/3010/3020 floppy-tape driver "ftape"
25 * exports to its high level clients
26 */
27
28#include <linux/module.h>
29
30#include <linux/ftape.h>
31#include "../lowlevel/ftape-tracing.h"
32#include "../lowlevel/ftape-init.h"
33#include "../lowlevel/fdc-io.h"
34#include "../lowlevel/ftape-read.h"
35#include "../lowlevel/ftape-write.h"
36#include "../lowlevel/ftape-io.h"
37#include "../lowlevel/ftape-ctl.h"
38#include "../lowlevel/ftape-rw.h"
39#include "../lowlevel/ftape-bsm.h"
40#include "../lowlevel/ftape-buffer.h"
41#include "../lowlevel/ftape-format.h"
42
43/* bad sector handling from ftape-bsm.c */
44EXPORT_SYMBOL(ftape_get_bad_sector_entry);
45EXPORT_SYMBOL(ftape_find_end_of_bsm_list);
46/* from ftape-rw.c */
47EXPORT_SYMBOL(ftape_set_state);
48/* from ftape-ctl.c */
49EXPORT_SYMBOL(ftape_seek_to_bot);
50EXPORT_SYMBOL(ftape_seek_to_eot);
51EXPORT_SYMBOL(ftape_abort_operation);
52EXPORT_SYMBOL(ftape_get_status);
53EXPORT_SYMBOL(ftape_enable);
54EXPORT_SYMBOL(ftape_disable);
55EXPORT_SYMBOL(ftape_mmap);
56EXPORT_SYMBOL(ftape_calibrate_data_rate);
57/* from ftape-io.c */
58EXPORT_SYMBOL(ftape_reset_drive);
59EXPORT_SYMBOL(ftape_command);
60EXPORT_SYMBOL(ftape_parameter);
61EXPORT_SYMBOL(ftape_ready_wait);
62EXPORT_SYMBOL(ftape_report_operation);
63EXPORT_SYMBOL(ftape_report_error);
64/* from ftape-read.c */
65EXPORT_SYMBOL(ftape_read_segment_fraction);
66EXPORT_SYMBOL(ftape_zap_read_buffers);
67EXPORT_SYMBOL(ftape_read_header_segment);
68EXPORT_SYMBOL(ftape_decode_header_segment);
69/* from ftape-write.c */
70EXPORT_SYMBOL(ftape_write_segment);
71EXPORT_SYMBOL(ftape_start_writing);
72EXPORT_SYMBOL(ftape_loop_until_writes_done);
73/* from ftape-buffer.h */
74EXPORT_SYMBOL(ftape_set_nr_buffers);
75/* from ftape-format.h */
76EXPORT_SYMBOL(ftape_format_track);
77EXPORT_SYMBOL(ftape_format_status);
78EXPORT_SYMBOL(ftape_verify_segment);
79/* from tracing.c */
80#ifndef CONFIG_FT_NO_TRACE_AT_ALL
81EXPORT_SYMBOL(ftape_tracing);
82EXPORT_SYMBOL(ftape_function_nest_level);
83EXPORT_SYMBOL(ftape_trace_call);
84EXPORT_SYMBOL(ftape_trace_exit);
85EXPORT_SYMBOL(ftape_trace_log);
86#endif
87
diff --git a/drivers/char/ftape/zftape/Makefile b/drivers/char/ftape/zftape/Makefile
deleted file mode 100644
index 6d91c1f77c05..000000000000
--- a/drivers/char/ftape/zftape/Makefile
+++ /dev/null
@@ -1,36 +0,0 @@
1#
2# Copyright (C) 1996, 1997 Claus-Justus Heine.
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2, or (at your option)
7# any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; see the file COPYING. If not, write to
16# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17#
18# $Source: /homes/cvs/ftape-stacked/ftape/zftape/Makefile,v $
19# $Revision: 1.4 $
20# $Date: 1997/10/05 19:18:58 $
21#
22# Makefile for the QIC-40/80/3010/3020 zftape interface VFS to
23# ftape
24#
25
26
27# ZFT_OBSOLETE - enable the MTIOC_ZFTAPE_GETBLKSZ ioctl. You should
28# leave this enabled for compatibility with taper.
29
30obj-$(CONFIG_ZFTAPE) += zftape.o
31
32zftape-objs := zftape-rw.o zftape-ctl.o zftape-read.o \
33 zftape-write.o zftape-vtbl.o zftape-eof.o \
34 zftape-init.o zftape-buffers.o zftape_syms.o
35
36EXTRA_CFLAGS := -DZFT_OBSOLETE
diff --git a/drivers/char/ftape/zftape/zftape-buffers.c b/drivers/char/ftape/zftape/zftape-buffers.c
deleted file mode 100644
index da06f138334e..000000000000
--- a/drivers/char/ftape/zftape/zftape-buffers.c
+++ /dev/null
@@ -1,149 +0,0 @@
1/*
2 * Copyright (C) 1995-1997 Claus-Justus Heine.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 *
19 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-buffers.c,v $
20 * $Revision: 1.2 $
21 * $Date: 1997/10/05 19:18:59 $
22 *
23 * This file contains the dynamic buffer allocation routines
24 * of zftape
25 */
26
27#include <linux/errno.h>
28#include <linux/mm.h>
29#include <linux/slab.h>
30#include <linux/delay.h>
31
32#include <linux/zftape.h>
33
34#include <linux/vmalloc.h>
35
36#include "../zftape/zftape-init.h"
37#include "../zftape/zftape-eof.h"
38#include "../zftape/zftape-ctl.h"
39#include "../zftape/zftape-write.h"
40#include "../zftape/zftape-read.h"
41#include "../zftape/zftape-rw.h"
42#include "../zftape/zftape-vtbl.h"
43
44/* global variables
45 */
46
47/* local varibales
48 */
49static unsigned int used_memory;
50static unsigned int peak_memory;
51
52void zft_memory_stats(void)
53{
54 TRACE_FUN(ft_t_flow);
55
56 TRACE(ft_t_noise, "Memory usage (vmalloc allocations):\n"
57 KERN_INFO "total allocated: %d\n"
58 KERN_INFO "peak allocation: %d",
59 used_memory, peak_memory);
60 peak_memory = used_memory;
61 TRACE_EXIT;
62}
63
64int zft_vcalloc_once(void *new, size_t size)
65{
66 TRACE_FUN(ft_t_flow);
67 if (zft_vmalloc_once(new, size) < 0) {
68 TRACE_EXIT -ENOMEM;
69 }
70 memset(*(void **)new, '\0', size);
71 TRACE_EXIT 0;
72}
73int zft_vmalloc_once(void *new, size_t size)
74{
75 TRACE_FUN(ft_t_flow);
76
77 if (*(void **)new != NULL || size == 0) {
78 TRACE_EXIT 0;
79 }
80 if ((*(void **)new = vmalloc(size)) == NULL) {
81 TRACE_EXIT -ENOMEM;
82 }
83 used_memory += size;
84 if (peak_memory < used_memory) {
85 peak_memory = used_memory;
86 }
87 TRACE_ABORT(0, ft_t_noise,
88 "allocated buffer @ %p, %d bytes", *(void **)new, size);
89}
90int zft_vmalloc_always(void *new, size_t size)
91{
92 TRACE_FUN(ft_t_flow);
93
94 zft_vfree(new, size);
95 TRACE_EXIT zft_vmalloc_once(new, size);
96}
97void zft_vfree(void *old, size_t size)
98{
99 TRACE_FUN(ft_t_flow);
100
101 if (*(void **)old) {
102 vfree(*(void **)old);
103 used_memory -= size;
104 TRACE(ft_t_noise, "released buffer @ %p, %d bytes",
105 *(void **)old, size);
106 *(void **)old = NULL;
107 }
108 TRACE_EXIT;
109}
110
111void *zft_kmalloc(size_t size)
112{
113 void *new;
114
115 while ((new = kmalloc(size, GFP_KERNEL)) == NULL) {
116 msleep_interruptible(100);
117 }
118 memset(new, 0, size);
119 used_memory += size;
120 if (peak_memory < used_memory) {
121 peak_memory = used_memory;
122 }
123 return new;
124}
125
126void zft_kfree(void *old, size_t size)
127{
128 kfree(old);
129 used_memory -= size;
130}
131
132/* there are some more buffers that are allocated on demand.
133 * cleanup_module() calles this function to be sure to have released
134 * them
135 */
136void zft_uninit_mem(void)
137{
138 TRACE_FUN(ft_t_flow);
139
140 zft_vfree(&zft_hseg_buf, FT_SEGMENT_SIZE);
141 zft_vfree(&zft_deblock_buf, FT_SEGMENT_SIZE); zft_deblock_segment = -1;
142 zft_free_vtbl();
143 if (zft_cmpr_lock(0 /* don't load */) == 0) {
144 (*zft_cmpr_ops->cleanup)();
145 (*zft_cmpr_ops->reset)(); /* unlock it again */
146 }
147 zft_memory_stats();
148 TRACE_EXIT;
149}
diff --git a/drivers/char/ftape/zftape/zftape-buffers.h b/drivers/char/ftape/zftape/zftape-buffers.h
deleted file mode 100644
index 798e3128c682..000000000000
--- a/drivers/char/ftape/zftape/zftape-buffers.h
+++ /dev/null
@@ -1,55 +0,0 @@
1#ifndef _FTAPE_DYNMEM_H
2#define _FTAPE_DYNMEM_H
3
4/*
5 * Copyright (C) 1995-1997 Claus-Justus Heine.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 *
22 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-buffers.h,v $
23 * $Revision: 1.2 $
24 * $Date: 1997/10/05 19:18:59 $
25 *
26 * memory allocation routines.
27 *
28 */
29
30/* we do not allocate all of the really large buffer memory before
31 * someone tries to open the drive. ftape_open() may fail with
32 * -ENOMEM, but that's better having 200k of vmalloced memory which
33 * cannot be swapped out.
34 */
35
36extern void zft_memory_stats(void);
37extern int zft_vmalloc_once(void *new, size_t size);
38extern int zft_vcalloc_once(void *new, size_t size);
39extern int zft_vmalloc_always(void *new, size_t size);
40extern void zft_vfree(void *old, size_t size);
41extern void *zft_kmalloc(size_t size);
42extern void zft_kfree(void *old, size_t size);
43
44/* called by cleanup_module()
45 */
46extern void zft_uninit_mem(void);
47
48#endif
49
50
51
52
53
54
55
diff --git a/drivers/char/ftape/zftape/zftape-ctl.c b/drivers/char/ftape/zftape/zftape-ctl.c
deleted file mode 100644
index 22ba0f5d00cf..000000000000
--- a/drivers/char/ftape/zftape/zftape-ctl.c
+++ /dev/null
@@ -1,1417 +0,0 @@
1/*
2 * Copyright (C) 1996, 1997 Claus-Justus Heine
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 *
19 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-ctl.c,v $
20 * $Revision: 1.2.6.2 $
21 * $Date: 1997/11/14 18:07:33 $
22 *
23 * This file contains the non-read/write zftape functions
24 * for the QIC-40/80/3010/3020 floppy-tape driver for Linux.
25 */
26
27#include <linux/errno.h>
28#include <linux/mm.h>
29#include <linux/module.h>
30#include <linux/fcntl.h>
31
32#include <linux/zftape.h>
33
34#include <asm/uaccess.h>
35
36#include "../zftape/zftape-init.h"
37#include "../zftape/zftape-eof.h"
38#include "../zftape/zftape-ctl.h"
39#include "../zftape/zftape-write.h"
40#include "../zftape/zftape-read.h"
41#include "../zftape/zftape-rw.h"
42#include "../zftape/zftape-vtbl.h"
43
44/* Global vars.
45 */
46int zft_write_protected; /* this is when cartridge rdonly or O_RDONLY */
47int zft_header_read;
48int zft_offline;
49unsigned int zft_unit;
50int zft_resid;
51int zft_mt_compression;
52
53/* Local vars.
54 */
55static int going_offline;
56
57typedef int (mt_fun)(int *argptr);
58typedef int (*mt_funp)(int *argptr);
59typedef struct
60{
61 mt_funp function;
62 unsigned offline : 1; /* op permitted if offline or no_tape */
63 unsigned write_protected : 1; /* op permitted if write-protected */
64 unsigned not_formatted : 1; /* op permitted if tape not formatted */
65 unsigned raw_mode : 1; /* op permitted if zft_mode == 0 */
66 unsigned need_idle_state : 1; /* need to call def_idle_state */
67 char *name;
68} fun_entry;
69
70static mt_fun mt_dummy, mt_reset, mt_fsr, mt_bsr, mt_rew, mt_offl, mt_nop,
71 mt_weof, mt_erase, mt_ras2, mt_setblk, mt_setdensity,
72 mt_seek, mt_tell, mt_reten, mt_eom, mt_fsf, mt_bsf,
73 mt_fsfm, mt_bsfm, mt_setdrvbuffer, mt_compression;
74
75static fun_entry mt_funs[]=
76{
77 {mt_reset , 1, 1, 1, 1, 0, "MT_RESET" }, /* 0 */
78 {mt_fsf , 0, 1, 0, 0, 1, "MT_FSF" },
79 {mt_bsf , 0, 1, 0, 0, 1, "MT_BSF" },
80 {mt_fsr , 0, 1, 0, 1, 1, "MT_FSR" },
81 {mt_bsr , 0, 1, 0, 1, 1, "MT_BSR" },
82 {mt_weof , 0, 0, 0, 0, 0, "MT_WEOF" }, /* 5 */
83 {mt_rew , 0, 1, 1, 1, 0, "MT_REW" },
84 {mt_offl , 0, 1, 1, 1, 0, "MT_OFFL" },
85 {mt_nop , 1, 1, 1, 1, 0, "MT_NOP" },
86 {mt_reten , 0, 1, 1, 1, 0, "MT_RETEN" },
87 {mt_bsfm , 0, 1, 0, 0, 1, "MT_BSFM" }, /* 10 */
88 {mt_fsfm , 0, 1, 0, 0, 1, "MT_FSFM" },
89 {mt_eom , 0, 1, 0, 0, 1, "MT_EOM" },
90 {mt_erase , 0, 0, 0, 1, 0, "MT_ERASE" },
91 {mt_dummy , 1, 1, 1, 1, 0, "MT_RAS1" },
92 {mt_ras2 , 0, 0, 0, 1, 0, "MT_RAS2" },
93 {mt_dummy , 1, 1, 1, 1, 0, "MT_RAS3" },
94 {mt_dummy , 1, 1, 1, 1, 0, "UNKNOWN" },
95 {mt_dummy , 1, 1, 1, 1, 0, "UNKNOWN" },
96 {mt_dummy , 1, 1, 1, 1, 0, "UNKNOWN" },
97 {mt_setblk , 1, 1, 1, 1, 1, "MT_SETBLK"}, /* 20 */
98 {mt_setdensity , 1, 1, 1, 1, 0, "MT_SETDENSITY"},
99 {mt_seek , 0, 1, 0, 1, 1, "MT_SEEK" },
100 {mt_dummy , 0, 1, 0, 1, 1, "MT_TELL" }, /* wr-only ?! */
101 {mt_setdrvbuffer, 1, 1, 1, 1, 0, "MT_SETDRVBUFFER" },
102 {mt_dummy , 1, 1, 1, 1, 0, "MT_FSS" }, /* 25 */
103 {mt_dummy , 1, 1, 1, 1, 0, "MT_BSS" },
104 {mt_dummy , 1, 1, 1, 1, 0, "MT_WSM" },
105 {mt_dummy , 1, 1, 1, 1, 0, "MT_LOCK" },
106 {mt_dummy , 1, 1, 1, 1, 0, "MT_UNLOCK"},
107 {mt_dummy , 1, 1, 1, 1, 0, "MT_LOAD" }, /* 30 */
108 {mt_dummy , 1, 1, 1, 1, 0, "MT_UNLOAD"},
109 {mt_compression , 1, 1, 1, 0, 1, "MT_COMPRESSION"},
110 {mt_dummy , 1, 1, 1, 1, 0, "MT_SETPART"},
111 {mt_dummy , 1, 1, 1, 1, 0, "MT_MKPART"}
112};
113
114#define NR_MT_CMDS NR_ITEMS(mt_funs)
115
116void zft_reset_position(zft_position *pos)
117{
118 TRACE_FUN(ft_t_flow);
119
120 pos->seg_byte_pos =
121 pos->volume_pos = 0;
122 if (zft_header_read) {
123 /* need to keep track of the volume table and
124 * compression map. We therefor simply
125 * position at the beginning of the first
126 * volume. This covers old ftape archives as
127 * well has various flavours of the
128 * compression map segments. The worst case is
129 * that the compression map shows up as a
130 * additional volume in front of all others.
131 */
132 pos->seg_pos = zft_find_volume(0)->start_seg;
133 pos->tape_pos = zft_calc_tape_pos(pos->seg_pos);
134 } else {
135 pos->tape_pos = 0;
136 pos->seg_pos = -1;
137 }
138 zft_just_before_eof = 0;
139 zft_deblock_segment = -1;
140 zft_io_state = zft_idle;
141 zft_zap_read_buffers();
142 zft_prevent_flush();
143 /* unlock the compresison module if it is loaded.
144 * The zero arg means not to try to load the module.
145 */
146 if (zft_cmpr_lock(0) == 0) {
147 (*zft_cmpr_ops->reset)(); /* unlock */
148 }
149 TRACE_EXIT;
150}
151
152static void zft_init_driver(void)
153{
154 TRACE_FUN(ft_t_flow);
155
156 zft_resid =
157 zft_header_read =
158 zft_old_ftape =
159 zft_offline =
160 zft_write_protected =
161 going_offline =
162 zft_mt_compression =
163 zft_header_changed =
164 zft_volume_table_changed =
165 zft_written_segments = 0;
166 zft_blk_sz = CONFIG_ZFT_DFLT_BLK_SZ;
167 zft_reset_position(&zft_pos); /* does most of the stuff */
168 ftape_zap_read_buffers();
169 ftape_set_state(idle);
170 TRACE_EXIT;
171}
172
173int zft_def_idle_state(void)
174{
175 int result = 0;
176 TRACE_FUN(ft_t_flow);
177
178 if (!zft_header_read) {
179 result = zft_read_header_segments();
180 } else if ((result = zft_flush_buffers()) >= 0 && zft_qic_mode) {
181 /* don't move past eof
182 */
183 (void)zft_close_volume(&zft_pos);
184 }
185 if (ftape_abort_operation() < 0) {
186 TRACE(ft_t_warn, "ftape_abort_operation() failed");
187 result = -EIO;
188 }
189 /* clear remaining read buffers */
190 zft_zap_read_buffers();
191 zft_io_state = zft_idle;
192 TRACE_EXIT result;
193}
194
195/*****************************************************************************
196 * *
197 * functions for the MTIOCTOP commands *
198 * *
199 *****************************************************************************/
200
201static int mt_dummy(int *dummy)
202{
203 TRACE_FUN(ft_t_flow);
204
205 TRACE_EXIT -ENOSYS;
206}
207
208static int mt_reset(int *dummy)
209{
210 TRACE_FUN(ft_t_flow);
211
212 (void)ftape_seek_to_bot();
213 TRACE_CATCH(ftape_reset_drive(),
214 zft_init_driver(); zft_uninit_mem(); zft_offline = 1);
215 /* fake a re-open of the device. This will set all flage and
216 * allocate buffers as appropriate. The new tape condition will
217 * force the open routine to do anything we need.
218 */
219 TRACE_CATCH(_zft_open(-1 /* fake reopen */, 0 /* dummy */),);
220 TRACE_EXIT 0;
221}
222
223static int mt_fsf(int *arg)
224{
225 int result;
226 TRACE_FUN(ft_t_flow);
227
228 result = zft_skip_volumes(*arg, &zft_pos);
229 zft_just_before_eof = 0;
230 TRACE_EXIT result;
231}
232
233static int mt_bsf(int *arg)
234{
235 int result = 0;
236 TRACE_FUN(ft_t_flow);
237
238 if (*arg != 0) {
239 result = zft_skip_volumes(-*arg + 1, &zft_pos);
240 }
241 TRACE_EXIT result;
242}
243
244static int seek_block(__s64 data_offset,
245 __s64 block_increment,
246 zft_position *pos)
247{
248 int result = 0;
249 __s64 new_block_pos;
250 __s64 vol_block_count;
251 const zft_volinfo *volume;
252 int exceed;
253 TRACE_FUN(ft_t_flow);
254
255 volume = zft_find_volume(pos->seg_pos);
256 if (volume->start_seg == 0 || volume->end_seg == 0) {
257 TRACE_EXIT -EIO;
258 }
259 new_block_pos = (zft_div_blksz(data_offset, volume->blk_sz)
260 + block_increment);
261 vol_block_count = zft_div_blksz(volume->size, volume->blk_sz);
262 if (new_block_pos < 0) {
263 TRACE(ft_t_noise,
264 "new_block_pos " LL_X " < 0", LL(new_block_pos));
265 zft_resid = (int)new_block_pos;
266 new_block_pos = 0;
267 exceed = 1;
268 } else if (new_block_pos > vol_block_count) {
269 TRACE(ft_t_noise,
270 "new_block_pos " LL_X " exceeds size of volume " LL_X,
271 LL(new_block_pos), LL(vol_block_count));
272 zft_resid = (int)(vol_block_count - new_block_pos);
273 new_block_pos = vol_block_count;
274 exceed = 1;
275 } else {
276 exceed = 0;
277 }
278 if (zft_use_compression && volume->use_compression) {
279 TRACE_CATCH(zft_cmpr_lock(1 /* try to load */),);
280 result = (*zft_cmpr_ops->seek)(new_block_pos, pos, volume,
281 zft_deblock_buf);
282 pos->tape_pos = zft_calc_tape_pos(pos->seg_pos);
283 pos->tape_pos += pos->seg_byte_pos;
284 } else {
285 pos->volume_pos = zft_mul_blksz(new_block_pos, volume->blk_sz);
286 pos->tape_pos = zft_calc_tape_pos(volume->start_seg);
287 pos->tape_pos += pos->volume_pos;
288 pos->seg_pos = zft_calc_seg_byte_coord(&pos->seg_byte_pos,
289 pos->tape_pos);
290 }
291 zft_just_before_eof = volume->size == pos->volume_pos;
292 if (zft_just_before_eof) {
293 /* why this? because zft_file_no checks agains start
294 * and end segment of a volume. We do not want to
295 * advance to the next volume with this function.
296 */
297 TRACE(ft_t_noise, "set zft_just_before_eof");
298 zft_position_before_eof(pos, volume);
299 }
300 TRACE(ft_t_noise, "\n"
301 KERN_INFO "new_seg_pos : %d\n"
302 KERN_INFO "new_tape_pos: " LL_X "\n"
303 KERN_INFO "vol_size : " LL_X "\n"
304 KERN_INFO "seg_byte_pos: %d\n"
305 KERN_INFO "blk_sz : %d",
306 pos->seg_pos, LL(pos->tape_pos),
307 LL(volume->size), pos->seg_byte_pos,
308 volume->blk_sz);
309 if (!exceed) {
310 zft_resid = new_block_pos - zft_div_blksz(pos->volume_pos,
311 volume->blk_sz);
312 }
313 if (zft_resid < 0) {
314 zft_resid = -zft_resid;
315 }
316 TRACE_EXIT ((exceed || zft_resid != 0) && result >= 0) ? -EINVAL : result;
317}
318
319static int mt_fsr(int *arg)
320{
321 int result;
322 TRACE_FUN(ft_t_flow);
323
324 result = seek_block(zft_pos.volume_pos, *arg, &zft_pos);
325 TRACE_EXIT result;
326}
327
328static int mt_bsr(int *arg)
329{
330 int result;
331 TRACE_FUN(ft_t_flow);
332
333 result = seek_block(zft_pos.volume_pos, -*arg, &zft_pos);
334 TRACE_EXIT result;
335}
336
337static int mt_weof(int *arg)
338{
339 int result;
340 TRACE_FUN(ft_t_flow);
341
342 TRACE_CATCH(zft_flush_buffers(),);
343 result = zft_weof(*arg, &zft_pos);
344 TRACE_EXIT result;
345}
346
347static int mt_rew(int *dummy)
348{
349 int result;
350 TRACE_FUN(ft_t_flow);
351
352 if(zft_header_read) {
353 (void)zft_def_idle_state();
354 }
355 result = ftape_seek_to_bot();
356 zft_reset_position(&zft_pos);
357 TRACE_EXIT result;
358}
359
360static int mt_offl(int *dummy)
361{
362 int result;
363 TRACE_FUN(ft_t_flow);
364
365 going_offline= 1;
366 result = mt_rew(NULL);
367 TRACE_EXIT result;
368}
369
370static int mt_nop(int *dummy)
371{
372 TRACE_FUN(ft_t_flow);
373 /* should we set tape status?
374 */
375 if (!zft_offline) { /* offline includes no_tape */
376 (void)zft_def_idle_state();
377 }
378 TRACE_EXIT 0;
379}
380
381static int mt_reten(int *dummy)
382{
383 int result;
384 TRACE_FUN(ft_t_flow);
385
386 if(zft_header_read) {
387 (void)zft_def_idle_state();
388 }
389 result = ftape_seek_to_eot();
390 if (result >= 0) {
391 result = ftape_seek_to_bot();
392 }
393 TRACE_EXIT(result);
394}
395
396static int fsfbsfm(int arg, zft_position *pos)
397{
398 const zft_volinfo *vtbl;
399 __s64 block_pos;
400 TRACE_FUN(ft_t_flow);
401
402 /* What to do? This should seek to the next file-mark and
403 * position BEFORE. That is, a next write would just extend
404 * the current file. Well. Let's just seek to the end of the
405 * current file, if count == 1. If count > 1, then do a
406 * "mt_fsf(count - 1)", and then seek to the end of that file.
407 * If count == 0, do nothing
408 */
409 if (arg == 0) {
410 TRACE_EXIT 0;
411 }
412 zft_just_before_eof = 0;
413 TRACE_CATCH(zft_skip_volumes(arg < 0 ? arg : arg-1, pos),
414 if (arg > 0) {
415 zft_resid ++;
416 });
417 vtbl = zft_find_volume(pos->seg_pos);
418 block_pos = zft_div_blksz(vtbl->size, vtbl->blk_sz);
419 (void)seek_block(0, block_pos, pos);
420 if (pos->volume_pos != vtbl->size) {
421 zft_just_before_eof = 0;
422 zft_resid = 1;
423 /* we didn't managed to go there */
424 TRACE_ABORT(-EIO, ft_t_err,
425 "wanted file position " LL_X ", arrived at " LL_X,
426 LL(vtbl->size), LL(pos->volume_pos));
427 }
428 zft_just_before_eof = 1;
429 TRACE_EXIT 0;
430}
431
432static int mt_bsfm(int *arg)
433{
434 int result;
435 TRACE_FUN(ft_t_flow);
436
437 result = fsfbsfm(-*arg, &zft_pos);
438 TRACE_EXIT result;
439}
440
441static int mt_fsfm(int *arg)
442{
443 int result;
444 TRACE_FUN(ft_t_flow);
445
446 result = fsfbsfm(*arg, &zft_pos);
447 TRACE_EXIT result;
448}
449
450static int mt_eom(int *dummy)
451{
452 TRACE_FUN(ft_t_flow);
453
454 zft_skip_to_eom(&zft_pos);
455 TRACE_EXIT 0;
456}
457
458static int mt_erase(int *dummy)
459{
460 int result;
461 TRACE_FUN(ft_t_flow);
462
463 result = zft_erase();
464 TRACE_EXIT result;
465}
466
467static int mt_ras2(int *dummy)
468{
469 int result;
470 TRACE_FUN(ft_t_flow);
471
472 result = -ENOSYS;
473 TRACE_EXIT result;
474}
475
476/* Sets the new blocksize in BYTES
477 *
478 */
479static int mt_setblk(int *new_size)
480{
481 TRACE_FUN(ft_t_flow);
482
483 if((unsigned int)(*new_size) > ZFT_MAX_BLK_SZ) {
484 TRACE_ABORT(-EINVAL, ft_t_info,
485 "desired blk_sz (%d) should be <= %d bytes",
486 *new_size, ZFT_MAX_BLK_SZ);
487 }
488 if ((*new_size & (FT_SECTOR_SIZE-1)) != 0) {
489 TRACE_ABORT(-EINVAL, ft_t_info,
490 "desired blk_sz (%d) must be a multiple of %d bytes",
491 *new_size, FT_SECTOR_SIZE);
492 }
493 if (*new_size == 0) {
494 if (zft_use_compression) {
495 TRACE_ABORT(-EINVAL, ft_t_info,
496 "Variable block size not yet "
497 "supported with compression");
498 }
499 *new_size = 1;
500 }
501 zft_blk_sz = *new_size;
502 TRACE_EXIT 0;
503}
504
505static int mt_setdensity(int *arg)
506{
507 TRACE_FUN(ft_t_flow);
508
509 SET_TRACE_LEVEL(*arg);
510 TRACE(TRACE_LEVEL, "tracing set to %d", TRACE_LEVEL);
511 if ((int)TRACE_LEVEL != *arg) {
512 TRACE_EXIT -EINVAL;
513 }
514 TRACE_EXIT 0;
515}
516
517static int mt_seek(int *new_block_pos)
518{
519 int result= 0;
520 TRACE_FUN(ft_t_any);
521
522 result = seek_block(0, (__s64)*new_block_pos, &zft_pos);
523 TRACE_EXIT result;
524}
525
526/* OK, this is totally different from SCSI, but the worst thing that can
527 * happen is that there is not enough defragmentated memory that can be
528 * allocated. Also, there is a hardwired limit of 16 dma buffers in the
529 * stock ftape module. This shouldn't bring the system down.
530 *
531 * NOTE: the argument specifies the total number of dma buffers to use.
532 * The driver needs at least 3 buffers to function at all.
533 *
534 */
535static int mt_setdrvbuffer(int *cnt)
536{
537 TRACE_FUN(ft_t_flow);
538
539 if (*cnt < 3) {
540 TRACE_EXIT -EINVAL;
541 }
542 TRACE_CATCH(ftape_set_nr_buffers(*cnt),);
543 TRACE_EXIT 0;
544}
545/* return the block position from start of volume
546 */
547static int mt_tell(int *arg)
548{
549 TRACE_FUN(ft_t_flow);
550
551 *arg = zft_div_blksz(zft_pos.volume_pos,
552 zft_find_volume(zft_pos.seg_pos)->blk_sz);
553 TRACE_EXIT 0;
554}
555
556static int mt_compression(int *arg)
557{
558 TRACE_FUN(ft_t_flow);
559
560 /* Ok. We could also check whether compression is available at
561 * all by trying to load the compression module. We could
562 * also check for a block size of 1 byte which is illegal
563 * with compression. Instead of doing it here we rely on
564 * zftape_write() to do the proper checks.
565 */
566 if ((unsigned int)*arg > 1) {
567 TRACE_EXIT -EINVAL;
568 }
569 if (*arg != 0 && zft_blk_sz == 1) { /* variable block size */
570 TRACE_ABORT(-EINVAL, ft_t_info,
571 "Compression not yet supported "
572 "with variable block size");
573 }
574 zft_mt_compression = *arg;
575 if ((zft_unit & ZFT_ZIP_MODE) == 0) {
576 zft_use_compression = zft_mt_compression;
577 }
578 TRACE_EXIT 0;
579}
580
581/* check whether write access is allowed. Write access is denied when
582 * + zft_write_protected == 1 -- this accounts for either hard write
583 * protection of the cartridge or for
584 * O_RDONLY access mode of the tape device
585 * + zft_offline == 1 -- this meany that there is either no tape
586 * or that the MTOFFLINE ioctl has been
587 * previously issued (`soft eject')
588 * + ft_formatted == 0 -- this means that the cartridge is not
589 * formatted
590 * Then we distinuguish two cases. When zft_qic_mode is TRUE, then we try
591 * to emulate a `traditional' (aka SCSI like) UN*X tape device. Therefore we
592 * deny writes when
593 * + zft_qic_mode ==1 &&
594 * (!zft_tape_at_lbot() && -- tape no at logical BOT
595 * !(zft_tape_at_eom() || -- tape not at logical EOM (or EOD)
596 * (zft_tape_at_eom() &&
597 * zft_old_ftape()))) -- we can't add new volume to tapes
598 * written by old ftape because ftape
599 * don't use the volume table
600 *
601 * when the drive is in true raw mode (aka /dev/rawft0) then we don't
602 * care about LBOT and EOM conditions. This device is intended for a
603 * user level program that wants to truly implement the QIC-80 compliance
604 * at the logical data layout level of the cartridge, i.e. implement all
605 * that volume table and volume directory stuff etc.<
606 */
607int zft_check_write_access(zft_position *pos)
608{
609 TRACE_FUN(ft_t_flow);
610
611 if (zft_offline) { /* offline includes no_tape */
612 TRACE_ABORT(-ENXIO,
613 ft_t_info, "tape is offline or no cartridge");
614 }
615 if (!ft_formatted) {
616 TRACE_ABORT(-EACCES, ft_t_info, "tape is not formatted");
617 }
618 if (zft_write_protected) {
619 TRACE_ABORT(-EACCES, ft_t_info, "cartridge write protected");
620 }
621 if (zft_qic_mode) {
622 /* check BOT condition */
623 if (!zft_tape_at_lbot(pos)) {
624 /* protect cartridges written by old ftape if
625 * not at BOT because they use the vtbl
626 * segment for storing data
627 */
628 if (zft_old_ftape) {
629 TRACE_ABORT(-EACCES, ft_t_warn,
630 "Cannot write to cartridges written by old ftape when not at BOT");
631 }
632 /* not at BOT, but allow writes at EOD, of course
633 */
634 if (!zft_tape_at_eod(pos)) {
635 TRACE_ABORT(-EACCES, ft_t_info,
636 "tape not at BOT and not at EOD");
637 }
638 }
639 /* fine. Now the tape is either at BOT or at EOD. */
640 }
641 /* or in raw mode in which case we don't care about BOT and EOD */
642 TRACE_EXIT 0;
643}
644
645/* OPEN routine called by kernel-interface code
646 *
647 * NOTE: this is also called by mt_reset() with dev_minor == -1
648 * to fake a reopen after a reset.
649 */
650int _zft_open(unsigned int dev_minor, unsigned int access_mode)
651{
652 static unsigned int tape_unit;
653 static unsigned int file_access_mode;
654 int result;
655 TRACE_FUN(ft_t_flow);
656
657 if ((int)dev_minor == -1) {
658 /* fake reopen */
659 zft_unit = tape_unit;
660 access_mode = file_access_mode;
661 zft_init_driver(); /* reset all static data to defaults */
662 } else {
663 tape_unit = dev_minor;
664 file_access_mode = access_mode;
665 if ((result = ftape_enable(FTAPE_SEL(dev_minor))) < 0) {
666 TRACE_ABORT(-ENXIO, ft_t_err,
667 "ftape_enable failed: %d", result);
668 }
669 if (ft_new_tape || ft_no_tape || !ft_formatted ||
670 (FTAPE_SEL(zft_unit) != FTAPE_SEL(dev_minor)) ||
671 (zft_unit & ZFT_RAW_MODE) != (dev_minor & ZFT_RAW_MODE)) {
672 /* reset all static data to defaults,
673 */
674 zft_init_driver();
675 }
676 zft_unit = dev_minor;
677 }
678 zft_set_flags(zft_unit); /* decode the minor bits */
679 if (zft_blk_sz == 1 && zft_use_compression) {
680 ftape_disable(); /* resets ft_no_tape */
681 TRACE_ABORT(-ENODEV, ft_t_warn, "Variable block size not yet "
682 "supported with compression");
683 }
684 /* no need for most of the buffers when no tape or not
685 * formatted. for the read/write operations, it is the
686 * regardless whether there is no tape, a not-formatted tape
687 * or the whether the driver is soft offline.
688 * Nevertheless we allow some ioctls with non-formatted tapes,
689 * like rewind and reset.
690 */
691 if (ft_no_tape || !ft_formatted) {
692 zft_uninit_mem();
693 }
694 if (ft_no_tape) {
695 zft_offline = 1; /* so we need not test two variables */
696 }
697 if ((access_mode == O_WRONLY || access_mode == O_RDWR) &&
698 (ft_write_protected || ft_no_tape)) {
699 ftape_disable(); /* resets ft_no_tape */
700 TRACE_ABORT(ft_no_tape ? -ENXIO : -EROFS,
701 ft_t_warn, "wrong access mode %s cartridge",
702 ft_no_tape ? "without a" : "with write protected");
703 }
704 zft_write_protected = (access_mode == O_RDONLY ||
705 ft_write_protected != 0);
706 if (zft_write_protected) {
707 TRACE(ft_t_noise,
708 "read only access mode: %d, "
709 "drive write protected: %d",
710 access_mode == O_RDONLY,
711 ft_write_protected != 0);
712 }
713 if (!zft_offline) {
714 TRACE_CATCH(zft_vmalloc_once(&zft_deblock_buf,FT_SEGMENT_SIZE),
715 ftape_disable());
716 }
717 /* zft_seg_pos should be greater than the vtbl segpos but not
718 * if in compatibility mode and only after we read in the
719 * header segments
720 *
721 * might also be a problem if the user makes a backup with a
722 * *qft* device and rewinds it with a raw device.
723 */
724 if (zft_qic_mode &&
725 !zft_old_ftape &&
726 zft_pos.seg_pos >= 0 &&
727 zft_header_read &&
728 zft_pos.seg_pos <= ft_first_data_segment) {
729 TRACE(ft_t_noise, "you probably mixed up the zftape devices!");
730 zft_reset_position(&zft_pos);
731 }
732 TRACE_EXIT 0;
733}
734
735/* RELEASE routine called by kernel-interface code
736 */
737int _zft_close(void)
738{
739 int result = 0;
740 TRACE_FUN(ft_t_flow);
741
742 if (zft_offline) {
743 /* call the hardware release routine. Puts the drive offline */
744 ftape_disable();
745 TRACE_EXIT 0;
746 }
747 if (!(ft_write_protected || zft_old_ftape)) {
748 result = zft_flush_buffers();
749 TRACE(ft_t_noise, "writing file mark at current position");
750 if (zft_qic_mode && zft_close_volume(&zft_pos) == 0) {
751 zft_move_past_eof(&zft_pos);
752 }
753 if ((zft_tape_at_lbot(&zft_pos) ||
754 !(zft_unit & FTAPE_NO_REWIND))) {
755 if (result >= 0) {
756 result = zft_update_header_segments();
757 } else {
758 TRACE(ft_t_err,
759 "Error: unable to update header segments");
760 }
761 }
762 }
763 ftape_abort_operation();
764 if (!(zft_unit & FTAPE_NO_REWIND)) {
765 TRACE(ft_t_noise, "rewinding tape");
766 if (ftape_seek_to_bot() < 0 && result >= 0) {
767 result = -EIO; /* keep old value */
768 }
769 zft_reset_position(&zft_pos);
770 }
771 zft_zap_read_buffers();
772 /* now free up memory as much as possible. We don't destroy
773 * the deblock buffer if it containes a valid segment.
774 */
775 if (zft_deblock_segment == -1) {
776 zft_vfree(&zft_deblock_buf, FT_SEGMENT_SIZE);
777 }
778 /* high level driver status, forces creation of a new volume
779 * when calling ftape_write again and not zft_just_before_eof
780 */
781 zft_io_state = zft_idle;
782 if (going_offline) {
783 zft_init_driver();
784 zft_uninit_mem();
785 going_offline = 0;
786 zft_offline = 1;
787 } else if (zft_cmpr_lock(0 /* don't load */) == 0) {
788 (*zft_cmpr_ops->reset)(); /* unlock it again */
789 }
790 zft_memory_stats();
791 /* call the hardware release routine. Puts the drive offline */
792 ftape_disable();
793 TRACE_EXIT result;
794}
795
796/*
797 * the wrapper function around the wrapper MTIOCTOP ioctl
798 */
799static int mtioctop(struct mtop *mtop, int arg_size)
800{
801 int result = 0;
802 fun_entry *mt_fun_entry;
803 TRACE_FUN(ft_t_flow);
804
805 if (arg_size != sizeof(struct mtop) || mtop->mt_op >= NR_MT_CMDS) {
806 TRACE_EXIT -EINVAL;
807 }
808 TRACE(ft_t_noise, "calling MTIOCTOP command: %s",
809 mt_funs[mtop->mt_op].name);
810 mt_fun_entry= &mt_funs[mtop->mt_op];
811 zft_resid = mtop->mt_count;
812 if (!mt_fun_entry->offline && zft_offline) {
813 if (ft_no_tape) {
814 TRACE_ABORT(-ENXIO, ft_t_info, "no tape present");
815 } else {
816 TRACE_ABORT(-ENXIO, ft_t_info, "drive is offline");
817 }
818 }
819 if (!mt_fun_entry->not_formatted && !ft_formatted) {
820 TRACE_ABORT(-EACCES, ft_t_info, "tape is not formatted");
821 }
822 if (!mt_fun_entry->write_protected) {
823 TRACE_CATCH(zft_check_write_access(&zft_pos),);
824 }
825 if (mt_fun_entry->need_idle_state && !(zft_offline || !ft_formatted)) {
826 TRACE_CATCH(zft_def_idle_state(),);
827 }
828 if (!zft_qic_mode && !mt_fun_entry->raw_mode) {
829 TRACE_ABORT(-EACCES, ft_t_info,
830"Drive needs to be in QIC-80 compatibility mode for this command");
831 }
832 result = (mt_fun_entry->function)(&mtop->mt_count);
833 if (zft_tape_at_lbot(&zft_pos)) {
834 TRACE_CATCH(zft_update_header_segments(),);
835 }
836 if (result >= 0) {
837 zft_resid = 0;
838 }
839 TRACE_EXIT result;
840}
841
842/*
843 * standard MTIOCGET ioctl
844 */
845static int mtiocget(struct mtget *mtget, int arg_size)
846{
847 const zft_volinfo *volume;
848 __s64 max_tape_pos;
849 TRACE_FUN(ft_t_flow);
850
851 if (arg_size != sizeof(struct mtget)) {
852 TRACE_ABORT(-EINVAL, ft_t_info, "bad argument size: %d",
853 arg_size);
854 }
855 mtget->mt_type = ft_drive_type.vendor_id + 0x800000;
856 mtget->mt_dsreg = ft_last_status.space;
857 mtget->mt_erreg = ft_last_error.space; /* error register */
858 mtget->mt_resid = zft_resid; /* residuum of writes, reads and
859 * MTIOCTOP commands
860 */
861 if (!zft_offline) { /* neither no_tape nor soft offline */
862 mtget->mt_gstat = GMT_ONLINE(~0UL);
863 /* should rather return the status of the cartridge
864 * than the access mode of the file, therefor use
865 * ft_write_protected, not zft_write_protected
866 */
867 if (ft_write_protected) {
868 mtget->mt_gstat |= GMT_WR_PROT(~0UL);
869 }
870 if(zft_header_read) { /* this catches non-formatted */
871 volume = zft_find_volume(zft_pos.seg_pos);
872 mtget->mt_fileno = volume->count;
873 max_tape_pos = zft_capacity - zft_blk_sz;
874 if (zft_use_compression) {
875 max_tape_pos -= ZFT_CMPR_OVERHEAD;
876 }
877 if (zft_tape_at_eod(&zft_pos)) {
878 mtget->mt_gstat |= GMT_EOD(~0UL);
879 }
880 if (zft_pos.tape_pos > max_tape_pos) {
881 mtget->mt_gstat |= GMT_EOT(~0UL);
882 }
883 mtget->mt_blkno = zft_div_blksz(zft_pos.volume_pos,
884 volume->blk_sz);
885 if (zft_just_before_eof) {
886 mtget->mt_gstat |= GMT_EOF(~0UL);
887 }
888 if (zft_tape_at_lbot(&zft_pos)) {
889 mtget->mt_gstat |= GMT_BOT(~0UL);
890 }
891 } else {
892 mtget->mt_fileno = mtget->mt_blkno = -1;
893 if (mtget->mt_dsreg & QIC_STATUS_AT_BOT) {
894 mtget->mt_gstat |= GMT_BOT(~0UL);
895 }
896 }
897 } else {
898 if (ft_no_tape) {
899 mtget->mt_gstat = GMT_DR_OPEN(~0UL);
900 } else {
901 mtget->mt_gstat = 0UL;
902 }
903 mtget->mt_fileno = mtget->mt_blkno = -1;
904 }
905 TRACE_EXIT 0;
906}
907
908#ifdef MTIOCRDFTSEG
909/*
910 * Read a floppy tape segment. This is useful for manipulating the
911 * volume table, and read the old header segment before re-formatting
912 * the cartridge.
913 */
914static int mtiocrdftseg(struct mtftseg * mtftseg, int arg_size)
915{
916 TRACE_FUN(ft_t_flow);
917
918 TRACE(ft_t_noise, "Mag tape ioctl command: MTIOCRDFTSEG");
919 if (zft_qic_mode) {
920 TRACE_ABORT(-EACCES, ft_t_info,
921 "driver needs to be in raw mode for this ioctl");
922 }
923 if (arg_size != sizeof(struct mtftseg)) {
924 TRACE_ABORT(-EINVAL, ft_t_info, "bad argument size: %d",
925 arg_size);
926 }
927 if (zft_offline) {
928 TRACE_EXIT -ENXIO;
929 }
930 if (mtftseg->mt_mode != FT_RD_SINGLE &&
931 mtftseg->mt_mode != FT_RD_AHEAD) {
932 TRACE_ABORT(-EINVAL, ft_t_info, "invalid read mode");
933 }
934 if (!ft_formatted) {
935 TRACE_EXIT -EACCES; /* -ENXIO ? */
936
937 }
938 if (!zft_header_read) {
939 TRACE_CATCH(zft_def_idle_state(),);
940 }
941 if (mtftseg->mt_segno > ft_last_data_segment) {
942 TRACE_ABORT(-EINVAL, ft_t_info, "segment number is too large");
943 }
944 mtftseg->mt_result = ftape_read_segment(mtftseg->mt_segno,
945 zft_deblock_buf,
946 mtftseg->mt_mode);
947 if (mtftseg->mt_result < 0) {
948 /* a negativ result is not an ioctl error. if
949 * the user wants to read damaged tapes,
950 * it's up to her/him
951 */
952 TRACE_EXIT 0;
953 }
954 if (copy_to_user(mtftseg->mt_data,
955 zft_deblock_buf,
956 mtftseg->mt_result) != 0) {
957 TRACE_EXIT -EFAULT;
958 }
959 TRACE_EXIT 0;
960}
961#endif
962
963#ifdef MTIOCWRFTSEG
964/*
965 * write a floppy tape segment. This version features writing of
966 * deleted address marks, and gracefully ignores the (software)
967 * ft_formatted flag to support writing of header segments after
968 * formatting.
969 */
970static int mtiocwrftseg(struct mtftseg * mtftseg, int arg_size)
971{
972 int result;
973 TRACE_FUN(ft_t_flow);
974
975 TRACE(ft_t_noise, "Mag tape ioctl command: MTIOCWRFTSEG");
976 if (zft_write_protected || zft_qic_mode) {
977 TRACE_EXIT -EACCES;
978 }
979 if (arg_size != sizeof(struct mtftseg)) {
980 TRACE_ABORT(-EINVAL, ft_t_info, "bad argument size: %d",
981 arg_size);
982 }
983 if (zft_offline) {
984 TRACE_EXIT -ENXIO;
985 }
986 if (mtftseg->mt_mode != FT_WR_ASYNC &&
987 mtftseg->mt_mode != FT_WR_MULTI &&
988 mtftseg->mt_mode != FT_WR_SINGLE &&
989 mtftseg->mt_mode != FT_WR_DELETE) {
990 TRACE_ABORT(-EINVAL, ft_t_info, "invalid write mode");
991 }
992 /*
993 * We don't check for ft_formatted, because this gives
994 * only the software status of the driver.
995 *
996 * We assume that the user knows what it is
997 * doing. And rely on the low level stuff to fail
998 * when the tape isn't formatted. We only make sure
999 * that The header segment buffer is allocated,
1000 * because it holds the bad sector map.
1001 */
1002 if (zft_hseg_buf == NULL) {
1003 TRACE_EXIT -ENXIO;
1004 }
1005 if (mtftseg->mt_mode != FT_WR_DELETE) {
1006 if (copy_from_user(zft_deblock_buf,
1007 mtftseg->mt_data,
1008 FT_SEGMENT_SIZE) != 0) {
1009 TRACE_EXIT -EFAULT;
1010 }
1011 }
1012 mtftseg->mt_result = ftape_write_segment(mtftseg->mt_segno,
1013 zft_deblock_buf,
1014 mtftseg->mt_mode);
1015 if (mtftseg->mt_result >= 0 && mtftseg->mt_mode == FT_WR_SINGLE) {
1016 /*
1017 * a negativ result is not an ioctl error. if
1018 * the user wants to write damaged tapes,
1019 * it's up to her/him
1020 */
1021 if ((result = ftape_loop_until_writes_done()) < 0) {
1022 mtftseg->mt_result = result;
1023 }
1024 }
1025 TRACE_EXIT 0;
1026}
1027#endif
1028
1029#ifdef MTIOCVOLINFO
1030/*
1031 * get information about volume positioned at.
1032 */
1033static int mtiocvolinfo(struct mtvolinfo *volinfo, int arg_size)
1034{
1035 const zft_volinfo *volume;
1036 TRACE_FUN(ft_t_flow);
1037
1038 TRACE(ft_t_noise, "Mag tape ioctl command: MTIOCVOLINFO");
1039 if (arg_size != sizeof(struct mtvolinfo)) {
1040 TRACE_ABORT(-EINVAL,
1041 ft_t_info, "bad argument size: %d", arg_size);
1042 }
1043 if (zft_offline) {
1044 TRACE_EXIT -ENXIO;
1045 }
1046 if (!ft_formatted) {
1047 TRACE_EXIT -EACCES;
1048 }
1049 TRACE_CATCH(zft_def_idle_state(),);
1050 volume = zft_find_volume(zft_pos.seg_pos);
1051 volinfo->mt_volno = volume->count;
1052 volinfo->mt_blksz = volume->blk_sz == 1 ? 0 : volume->blk_sz;
1053 volinfo->mt_size = volume->size >> 10;
1054 volinfo->mt_rawsize = ((zft_calc_tape_pos(volume->end_seg + 1) >> 10) -
1055 (zft_calc_tape_pos(volume->start_seg) >> 10));
1056 volinfo->mt_cmpr = volume->use_compression;
1057 TRACE_EXIT 0;
1058}
1059#endif
1060
1061#ifdef ZFT_OBSOLETE
1062static int mtioc_zftape_getblksz(struct mtblksz *blksz, int arg_size)
1063{
1064 TRACE_FUN(ft_t_flow);
1065
1066 TRACE(ft_t_noise, "\n"
1067 KERN_INFO "Mag tape ioctl command: MTIOC_ZTAPE_GETBLKSZ\n"
1068 KERN_INFO "This ioctl is here merely for compatibility.\n"
1069 KERN_INFO "Please use MTIOCVOLINFO instead");
1070 if (arg_size != sizeof(struct mtblksz)) {
1071 TRACE_ABORT(-EINVAL,
1072 ft_t_info, "bad argument size: %d", arg_size);
1073 }
1074 if (zft_offline) {
1075 TRACE_EXIT -ENXIO;
1076 }
1077 if (!ft_formatted) {
1078 TRACE_EXIT -EACCES;
1079 }
1080 TRACE_CATCH(zft_def_idle_state(),);
1081 blksz->mt_blksz = zft_find_volume(zft_pos.seg_pos)->blk_sz;
1082 TRACE_EXIT 0;
1083}
1084#endif
1085
1086#ifdef MTIOCGETSIZE
1087/*
1088 * get the capacity of the tape cartridge.
1089 */
1090static int mtiocgetsize(struct mttapesize *size, int arg_size)
1091{
1092 TRACE_FUN(ft_t_flow);
1093
1094 TRACE(ft_t_noise, "Mag tape ioctl command: MTIOC_ZFTAPE_GETSIZE");
1095 if (arg_size != sizeof(struct mttapesize)) {
1096 TRACE_ABORT(-EINVAL,
1097 ft_t_info, "bad argument size: %d", arg_size);
1098 }
1099 if (zft_offline) {
1100 TRACE_EXIT -ENXIO;
1101 }
1102 if (!ft_formatted) {
1103 TRACE_EXIT -EACCES;
1104 }
1105 TRACE_CATCH(zft_def_idle_state(),);
1106 size->mt_capacity = (unsigned int)(zft_capacity>>10);
1107 size->mt_used = (unsigned int)(zft_get_eom_pos()>>10);
1108 TRACE_EXIT 0;
1109}
1110#endif
1111
1112static int mtiocpos(struct mtpos *mtpos, int arg_size)
1113{
1114 int result;
1115 TRACE_FUN(ft_t_flow);
1116
1117 TRACE(ft_t_noise, "Mag tape ioctl command: MTIOCPOS");
1118 if (arg_size != sizeof(struct mtpos)) {
1119 TRACE_ABORT(-EINVAL,
1120 ft_t_info, "bad argument size: %d", arg_size);
1121 }
1122 result = mt_tell((int *)&mtpos->mt_blkno);
1123 TRACE_EXIT result;
1124}
1125
1126#ifdef MTIOCFTFORMAT
1127/*
1128 * formatting of floppy tape cartridges. This is intended to be used
1129 * together with the MTIOCFTCMD ioctl and the new mmap feature
1130 */
1131
1132/*
1133 * This function uses ftape_decode_header_segment() to inform the low
1134 * level ftape module about the new parameters.
1135 *
1136 * It erases the hseg_buf. The calling process must specify all
1137 * parameters to assure proper operation.
1138 *
1139 * return values: -EINVAL - wrong argument size
1140 * -EINVAL - if ftape_decode_header_segment() failed.
1141 */
1142static int set_format_parms(struct ftfmtparms *p, __u8 *hseg_buf)
1143{
1144 ft_trace_t old_level = TRACE_LEVEL;
1145 TRACE_FUN(ft_t_flow);
1146
1147 TRACE(ft_t_noise, "MTIOCFTFORMAT operation FTFMT_SETPARMS");
1148 memset(hseg_buf, 0, FT_SEGMENT_SIZE);
1149 PUT4(hseg_buf, FT_SIGNATURE, FT_HSEG_MAGIC);
1150
1151 /* fill in user specified parameters
1152 */
1153 hseg_buf[FT_FMT_CODE] = (__u8)p->ft_fmtcode;
1154 PUT2(hseg_buf, FT_SPT, p->ft_spt);
1155 hseg_buf[FT_TPC] = (__u8)p->ft_tpc;
1156 hseg_buf[FT_FHM] = (__u8)p->ft_fhm;
1157 hseg_buf[FT_FTM] = (__u8)p->ft_ftm;
1158
1159 /* fill in sane defaults to make ftape happy.
1160 */
1161 hseg_buf[FT_FSM] = (__u8)128; /* 128 is hard wired all over ftape */
1162 if (p->ft_fmtcode == fmt_big) {
1163 PUT4(hseg_buf, FT_6_HSEG_1, 0);
1164 PUT4(hseg_buf, FT_6_HSEG_2, 1);
1165 PUT4(hseg_buf, FT_6_FRST_SEG, 2);
1166 PUT4(hseg_buf, FT_6_LAST_SEG, p->ft_spt * p->ft_tpc - 1);
1167 } else {
1168 PUT2(hseg_buf, FT_HSEG_1, 0);
1169 PUT2(hseg_buf, FT_HSEG_2, 1);
1170 PUT2(hseg_buf, FT_FRST_SEG, 2);
1171 PUT2(hseg_buf, FT_LAST_SEG, p->ft_spt * p->ft_tpc - 1);
1172 }
1173
1174 /* Synchronize with the low level module. This is particularly
1175 * needed for unformatted cartridges as the QIC std was previously
1176 * unknown BUT is needed to set data rate and to calculate timeouts.
1177 */
1178 TRACE_CATCH(ftape_calibrate_data_rate(p->ft_qicstd&QIC_TAPE_STD_MASK),
1179 _res = -EINVAL);
1180
1181 /* The following will also recalcualte the timeouts for the tape
1182 * length and QIC std we want to format to.
1183 * abort with -EINVAL rather than -EIO
1184 */
1185 SET_TRACE_LEVEL(ft_t_warn);
1186 TRACE_CATCH(ftape_decode_header_segment(hseg_buf),
1187 SET_TRACE_LEVEL(old_level); _res = -EINVAL);
1188 SET_TRACE_LEVEL(old_level);
1189 TRACE_EXIT 0;
1190}
1191
1192/*
1193 * Return the internal SOFTWARE status of the kernel driver. This does
1194 * NOT query the tape drive about its status.
1195 */
1196static int get_format_parms(struct ftfmtparms *p, __u8 *hseg_buffer)
1197{
1198 TRACE_FUN(ft_t_flow);
1199
1200 TRACE(ft_t_noise, "MTIOCFTFORMAT operation FTFMT_GETPARMS");
1201 p->ft_qicstd = ft_qic_std;
1202 p->ft_fmtcode = ft_format_code;
1203 p->ft_fhm = hseg_buffer[FT_FHM];
1204 p->ft_ftm = hseg_buffer[FT_FTM];
1205 p->ft_spt = ft_segments_per_track;
1206 p->ft_tpc = ft_tracks_per_tape;
1207 TRACE_EXIT 0;
1208}
1209
1210static int mtiocftformat(struct mtftformat *mtftformat, int arg_size)
1211{
1212 int result;
1213 union fmt_arg *arg = &mtftformat->fmt_arg;
1214 TRACE_FUN(ft_t_flow);
1215
1216 TRACE(ft_t_noise, "Mag tape ioctl command: MTIOCFTFORMAT");
1217 if (zft_offline) {
1218 if (ft_no_tape) {
1219 TRACE_ABORT(-ENXIO, ft_t_info, "no tape present");
1220 } else {
1221 TRACE_ABORT(-ENXIO, ft_t_info, "drive is offline");
1222 }
1223 }
1224 if (zft_qic_mode) {
1225 TRACE_ABORT(-EACCES, ft_t_info,
1226 "driver needs to be in raw mode for this ioctl");
1227 }
1228 if (zft_hseg_buf == NULL) {
1229 TRACE_CATCH(zft_vcalloc_once(&zft_hseg_buf, FT_SEGMENT_SIZE),);
1230 }
1231 zft_header_read = 0;
1232 switch(mtftformat->fmt_op) {
1233 case FTFMT_SET_PARMS:
1234 TRACE_CATCH(set_format_parms(&arg->fmt_parms, zft_hseg_buf),);
1235 TRACE_EXIT 0;
1236 case FTFMT_GET_PARMS:
1237 TRACE_CATCH(get_format_parms(&arg->fmt_parms, zft_hseg_buf),);
1238 TRACE_EXIT 0;
1239 case FTFMT_FORMAT_TRACK:
1240 if ((ft_formatted && zft_check_write_access(&zft_pos) < 0) ||
1241 (!ft_formatted && zft_write_protected)) {
1242 TRACE_ABORT(-EACCES, ft_t_info, "Write access denied");
1243 }
1244 TRACE_CATCH(ftape_format_track(arg->fmt_track.ft_track,
1245 arg->fmt_track.ft_gap3),);
1246 TRACE_EXIT 0;
1247 case FTFMT_STATUS:
1248 TRACE_CATCH(ftape_format_status(&arg->fmt_status.ft_segment),);
1249 TRACE_EXIT 0;
1250 case FTFMT_VERIFY:
1251 TRACE_CATCH(ftape_verify_segment(arg->fmt_verify.ft_segment,
1252 (SectorMap *)&arg->fmt_verify.ft_bsm),);
1253 TRACE_EXIT 0;
1254 default:
1255 TRACE_ABORT(-EINVAL, ft_t_err, "Invalid format operation");
1256 }
1257 TRACE_EXIT result;
1258}
1259#endif
1260
1261#ifdef MTIOCFTCMD
1262/*
1263 * send a QIC-117 command to the drive, with optional timeouts,
1264 * parameter and result bits. This is intended to be used together
1265 * with the formatting ioctl.
1266 */
1267static int mtiocftcmd(struct mtftcmd *ftcmd, int arg_size)
1268{
1269 int i;
1270 TRACE_FUN(ft_t_flow);
1271
1272 TRACE(ft_t_noise, "Mag tape ioctl command: MTIOCFTCMD");
1273 if (!capable(CAP_SYS_ADMIN)) {
1274 TRACE_ABORT(-EPERM, ft_t_info,
1275 "need CAP_SYS_ADMIN capability to send raw qic-117 commands");
1276 }
1277 if (zft_qic_mode) {
1278 TRACE_ABORT(-EACCES, ft_t_info,
1279 "driver needs to be in raw mode for this ioctl");
1280 }
1281 if (arg_size != sizeof(struct mtftcmd)) {
1282 TRACE_ABORT(-EINVAL,
1283 ft_t_info, "bad argument size: %d", arg_size);
1284 }
1285 if (ftcmd->ft_wait_before) {
1286 TRACE_CATCH(ftape_ready_wait(ftcmd->ft_wait_before,
1287 &ftcmd->ft_status),);
1288 }
1289 if (ftcmd->ft_status & QIC_STATUS_ERROR)
1290 goto ftmtcmd_error;
1291 if (ftcmd->ft_result_bits != 0) {
1292 TRACE_CATCH(ftape_report_operation(&ftcmd->ft_result,
1293 ftcmd->ft_cmd,
1294 ftcmd->ft_result_bits),);
1295 } else {
1296 TRACE_CATCH(ftape_command(ftcmd->ft_cmd),);
1297 if (ftcmd->ft_status & QIC_STATUS_ERROR)
1298 goto ftmtcmd_error;
1299 for (i = 0; i < ftcmd->ft_parm_cnt; i++) {
1300 TRACE_CATCH(ftape_parameter(ftcmd->ft_parms[i]&0x0f),);
1301 if (ftcmd->ft_status & QIC_STATUS_ERROR)
1302 goto ftmtcmd_error;
1303 }
1304 }
1305 if (ftcmd->ft_wait_after != 0) {
1306 TRACE_CATCH(ftape_ready_wait(ftcmd->ft_wait_after,
1307 &ftcmd->ft_status),);
1308 }
1309ftmtcmd_error:
1310 if (ftcmd->ft_status & QIC_STATUS_ERROR) {
1311 TRACE(ft_t_noise, "error status set");
1312 TRACE_CATCH(ftape_report_error(&ftcmd->ft_error,
1313 &ftcmd->ft_cmd, 1),);
1314 }
1315 TRACE_EXIT 0; /* this is not an i/o error */
1316}
1317#endif
1318
1319/* IOCTL routine called by kernel-interface code
1320 */
1321int _zft_ioctl(unsigned int command, void __user * arg)
1322{
1323 int result;
1324 union { struct mtop mtop;
1325 struct mtget mtget;
1326 struct mtpos mtpos;
1327#ifdef MTIOCRDFTSEG
1328 struct mtftseg mtftseg;
1329#endif
1330#ifdef MTIOCVOLINFO
1331 struct mtvolinfo mtvolinfo;
1332#endif
1333#ifdef MTIOCGETSIZE
1334 struct mttapesize mttapesize;
1335#endif
1336#ifdef MTIOCFTFORMAT
1337 struct mtftformat mtftformat;
1338#endif
1339#ifdef ZFT_OBSOLETE
1340 struct mtblksz mtblksz;
1341#endif
1342#ifdef MTIOCFTCMD
1343 struct mtftcmd mtftcmd;
1344#endif
1345 } krnl_arg;
1346 int arg_size = _IOC_SIZE(command);
1347 int dir = _IOC_DIR(command);
1348 TRACE_FUN(ft_t_flow);
1349
1350 /* This check will only catch arguments that are too large !
1351 */
1352 if (dir & (_IOC_READ | _IOC_WRITE) && arg_size > sizeof(krnl_arg)) {
1353 TRACE_ABORT(-EINVAL,
1354 ft_t_info, "bad argument size: %d", arg_size);
1355 }
1356 if (dir & _IOC_WRITE) {
1357 if (copy_from_user(&krnl_arg, arg, arg_size) != 0) {
1358 TRACE_EXIT -EFAULT;
1359 }
1360 }
1361 TRACE(ft_t_flow, "called with ioctl command: 0x%08x", command);
1362 switch (command) {
1363 case MTIOCTOP:
1364 result = mtioctop(&krnl_arg.mtop, arg_size);
1365 break;
1366 case MTIOCGET:
1367 result = mtiocget(&krnl_arg.mtget, arg_size);
1368 break;
1369 case MTIOCPOS:
1370 result = mtiocpos(&krnl_arg.mtpos, arg_size);
1371 break;
1372#ifdef MTIOCVOLINFO
1373 case MTIOCVOLINFO:
1374 result = mtiocvolinfo(&krnl_arg.mtvolinfo, arg_size);
1375 break;
1376#endif
1377#ifdef ZFT_OBSOLETE
1378 case MTIOC_ZFTAPE_GETBLKSZ:
1379 result = mtioc_zftape_getblksz(&krnl_arg.mtblksz, arg_size);
1380 break;
1381#endif
1382#ifdef MTIOCRDFTSEG
1383 case MTIOCRDFTSEG: /* read a segment via ioctl */
1384 result = mtiocrdftseg(&krnl_arg.mtftseg, arg_size);
1385 break;
1386#endif
1387#ifdef MTIOCWRFTSEG
1388 case MTIOCWRFTSEG: /* write a segment via ioctl */
1389 result = mtiocwrftseg(&krnl_arg.mtftseg, arg_size);
1390 break;
1391#endif
1392#ifdef MTIOCGETSIZE
1393 case MTIOCGETSIZE:
1394 result = mtiocgetsize(&krnl_arg.mttapesize, arg_size);
1395 break;
1396#endif
1397#ifdef MTIOCFTFORMAT
1398 case MTIOCFTFORMAT:
1399 result = mtiocftformat(&krnl_arg.mtftformat, arg_size);
1400 break;
1401#endif
1402#ifdef MTIOCFTCMD
1403 case MTIOCFTCMD:
1404 result = mtiocftcmd(&krnl_arg.mtftcmd, arg_size);
1405 break;
1406#endif
1407 default:
1408 result = -EINVAL;
1409 break;
1410 }
1411 if ((result >= 0) && (dir & _IOC_READ)) {
1412 if (copy_to_user(arg, &krnl_arg, arg_size) != 0) {
1413 TRACE_EXIT -EFAULT;
1414 }
1415 }
1416 TRACE_EXIT result;
1417}
diff --git a/drivers/char/ftape/zftape/zftape-ctl.h b/drivers/char/ftape/zftape/zftape-ctl.h
deleted file mode 100644
index 8e6f2d7ac74e..000000000000
--- a/drivers/char/ftape/zftape/zftape-ctl.h
+++ /dev/null
@@ -1,58 +0,0 @@
1#ifndef _ZFTAPE_CTL_H
2#define _ZFTAPE_CTL_H
3
4/*
5 * Copyright (C) 1996, 1997 Claus-Justus Heine.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 *
22 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-ctl.h,v $
23 * $Revision: 1.2 $
24 * $Date: 1997/10/05 19:19:02 $
25 *
26 * This file contains the non-standard IOCTL related definitions
27 * for the QIC-40/80 floppy-tape driver for Linux.
28 */
29
30#include <linux/ioctl.h>
31#include <linux/mtio.h>
32
33#include "../zftape/zftape-rw.h"
34
35#ifdef CONFIG_ZFTAPE_MODULE
36#define ftape_status (*zft_status)
37#endif
38
39extern int zft_offline;
40extern int zft_mt_compression;
41extern int zft_write_protected;
42extern int zft_header_read;
43extern unsigned int zft_unit;
44extern int zft_resid;
45
46extern void zft_reset_position(zft_position *pos);
47extern int zft_check_write_access(zft_position *pos);
48extern int zft_def_idle_state(void);
49
50/* hooks for the VFS interface
51 */
52extern int _zft_open(unsigned int dev_minor, unsigned int access_mode);
53extern int _zft_close(void);
54extern int _zft_ioctl(unsigned int command, void __user *arg);
55#endif
56
57
58
diff --git a/drivers/char/ftape/zftape/zftape-eof.c b/drivers/char/ftape/zftape/zftape-eof.c
deleted file mode 100644
index dcadcaee9ac1..000000000000
--- a/drivers/char/ftape/zftape/zftape-eof.c
+++ /dev/null
@@ -1,199 +0,0 @@
1/*
2 * I use these routines just to decide when I have to fake a
3 * volume-table to preserve compatibility to original ftape.
4 */
5/*
6 * Copyright (C) 1994-1995 Bas Laarhoven.
7 *
8 * Modified for zftape 1996, 1997 Claus Heine.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; see the file COPYING. If not, write to
22 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-eof.c,v $
25 * $Revision: 1.2 $
26 * $Date: 1997/10/05 19:19:02 $
27 *
28 * This file contains the eof mark handling code
29 * for the QIC-40/80 floppy-tape driver for Linux.
30 */
31
32#include <linux/string.h>
33#include <linux/errno.h>
34
35#include <linux/zftape.h>
36
37#include "../zftape/zftape-init.h"
38#include "../zftape/zftape-rw.h"
39#include "../zftape/zftape-eof.h"
40
41/* Global vars.
42 */
43
44/* a copy of the failed sector log from the header segment.
45 */
46eof_mark_union *zft_eof_map;
47
48/* number of eof marks (entries in bad sector log) on tape.
49 */
50int zft_nr_eof_marks = -1;
51
52
53/* Local vars.
54 */
55
56static char linux_tape_label[] = "Linux raw format V";
57enum {
58 min_fmt_version = 1, max_fmt_version = 2
59};
60static unsigned ftape_fmt_version = 0;
61
62
63/* Ftape (mis)uses the bad sector log to record end-of-file marks.
64 * Initially (when the tape is erased) all entries in the bad sector
65 * log are added to the tape's bad sector map. The bad sector log then
66 * is cleared.
67 *
68 * The bad sector log normally contains entries of the form:
69 * even 16-bit word: segment number of bad sector
70 * odd 16-bit word: encoded date
71 * There can be a total of 448 entries (1792 bytes).
72 *
73 * My guess is that no program is using this bad sector log (the *
74 * format seems useless as there is no indication of the bad sector
75 * itself, only the segment) However, if any program does use the bad
76 * sector log, the format used by ftape will let the program think
77 * there are some bad sectors and no harm is done.
78 *
79 * The eof mark entries that ftape stores in the bad sector log: even
80 * 16-bit word: segment number of eof mark odd 16-bit word: sector
81 * number of eof mark [1..32]
82 *
83 * The zft_eof_map as maintained is a sorted list of eof mark entries.
84 *
85 *
86 * The tape name field in the header segments is used to store a linux
87 * tape identification string and a version number. This way the tape
88 * can be recognized as a Linux raw format tape when using tools under
89 * other OS's.
90 *
91 * 'Wide' QIC tapes (format code 4) don't have a failed sector list
92 * anymore. That space is used for the (longer) bad sector map that
93 * now is a variable length list too. We now store our end-of-file
94 * marker list after the bad-sector-map on tape. The list is delimited
95 * by a (__u32) 0 entry.
96 */
97
98int zft_ftape_validate_label(char *label)
99{
100 static char tmp_label[45];
101 int result = 0;
102 TRACE_FUN(ft_t_any);
103
104 memcpy(tmp_label, label, FT_LABEL_SZ);
105 tmp_label[FT_LABEL_SZ] = '\0';
106 TRACE(ft_t_noise, "tape label = `%s'", tmp_label);
107 ftape_fmt_version = 0;
108 if (memcmp(label, linux_tape_label, strlen(linux_tape_label)) == 0) {
109 int pos = strlen(linux_tape_label);
110 while (label[pos] >= '0' && label[pos] <= '9') {
111 ftape_fmt_version *= 10;
112 ftape_fmt_version = label[ pos++] - '0';
113 }
114 result = (ftape_fmt_version >= min_fmt_version &&
115 ftape_fmt_version <= max_fmt_version);
116 }
117 TRACE(ft_t_noise, "format version = %d", ftape_fmt_version);
118 TRACE_EXIT result;
119}
120
121static __u8 * find_end_of_eof_list(__u8 * ptr, __u8 * limit)
122{
123 while (ptr + 3 < limit) {
124
125 if (get_unaligned((__u32*)ptr)) {
126 ptr += sizeof(__u32);
127 } else {
128 return ptr;
129 }
130 }
131 return NULL;
132}
133
134void zft_ftape_extract_file_marks(__u8* address)
135{
136 int i;
137 TRACE_FUN(ft_t_any);
138
139 zft_eof_map = NULL;
140 if (ft_format_code == fmt_var || ft_format_code == fmt_big) {
141 __u8* end;
142 __u8* start = ftape_find_end_of_bsm_list(address);
143
144 zft_nr_eof_marks = 0;
145 if (start) {
146 start += 3; /* skip end of list mark */
147 end = find_end_of_eof_list(start,
148 address + FT_SEGMENT_SIZE);
149 if (end && end - start <= FT_FSL_SIZE) {
150 zft_nr_eof_marks = ((end - start) /
151 sizeof(eof_mark_union));
152 zft_eof_map = (eof_mark_union *)start;
153 } else {
154 TRACE(ft_t_err,
155 "EOF Mark List is too long or damaged!");
156 }
157 } else {
158 TRACE(ft_t_err,
159 "Bad Sector List is too long or damaged !");
160 }
161 } else {
162 zft_eof_map = (eof_mark_union *)&address[FT_FSL];
163 zft_nr_eof_marks = GET2(address, FT_FSL_CNT);
164 }
165 TRACE(ft_t_noise, "number of file marks: %d", zft_nr_eof_marks);
166 if (ftape_fmt_version == 1) {
167 TRACE(ft_t_info, "swapping version 1 fields");
168 /* version 1 format uses swapped sector and segment
169 * fields, correct that !
170 */
171 for (i = 0; i < zft_nr_eof_marks; ++i) {
172 __u16 tmp = GET2(&zft_eof_map[i].mark.segment,0);
173 PUT2(&zft_eof_map[i].mark.segment, 0,
174 GET2(&zft_eof_map[i].mark.date,0));
175 PUT2(&zft_eof_map[i].mark.date, 0, tmp);
176 }
177 }
178 for (i = 0; i < zft_nr_eof_marks; ++i) {
179 TRACE(ft_t_noise, "eof mark: %5d/%2d",
180 GET2(&zft_eof_map[i].mark.segment, 0),
181 GET2(&zft_eof_map[i].mark.date,0));
182 }
183 TRACE_EXIT;
184}
185
186void zft_clear_ftape_file_marks(void)
187{
188 TRACE_FUN(ft_t_flow);
189 /* Clear failed sector log: remove all tape marks. We
190 * don't use old ftape-style EOF-marks.
191 */
192 TRACE(ft_t_info, "Clearing old ftape's eof map");
193 memset(zft_eof_map, 0, zft_nr_eof_marks * sizeof(__u32));
194 zft_nr_eof_marks = 0;
195 PUT2(zft_hseg_buf, FT_FSL_CNT, 0); /* nr of eof-marks */
196 zft_header_changed = 1;
197 zft_update_label(zft_hseg_buf);
198 TRACE_EXIT;
199}
diff --git a/drivers/char/ftape/zftape/zftape-eof.h b/drivers/char/ftape/zftape/zftape-eof.h
deleted file mode 100644
index 26568c26c518..000000000000
--- a/drivers/char/ftape/zftape/zftape-eof.h
+++ /dev/null
@@ -1,52 +0,0 @@
1#ifndef _ZFTAPE_EOF_H
2#define _ZFTAPE_EOF_H
3
4/*
5 * Copyright (C) 1994-1995 Bas Laarhoven.
6 * adaptaed for zftape 1996, 1997 by Claus Heine
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 *
23 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-eof.h,v $
24 * $Revision: 1.2 $
25 * $Date: 1997/10/05 19:19:03 $
26 *
27 * Definitions and declarations for the end of file markers
28 * for the QIC-40/80 floppy-tape driver for Linux.
29 */
30
31#include <linux/ftape-header-segment.h>
32#include "../zftape/zftape-buffers.h"
33/* failed sector log size (only used if format code != 4).
34 */
35
36typedef union {
37 ft_fsl_entry mark;
38 __u32 entry;
39} eof_mark_union;
40
41/* ftape-eof.c defined global vars.
42 */
43extern int zft_nr_eof_marks;
44extern eof_mark_union *zft_eof_map;
45
46/* ftape-eof.c defined global functions.
47 */
48extern void zft_ftape_extract_file_marks(__u8* address);
49extern int zft_ftape_validate_label(char* label);
50extern void zft_clear_ftape_file_marks(void);
51
52#endif
diff --git a/drivers/char/ftape/zftape/zftape-init.c b/drivers/char/ftape/zftape/zftape-init.c
deleted file mode 100644
index 164a1aa77a2f..000000000000
--- a/drivers/char/ftape/zftape/zftape-init.c
+++ /dev/null
@@ -1,377 +0,0 @@
1/*
2 * Copyright (C) 1996, 1997 Claus-Justus Heine.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 *
19 * This file contains the code that registers the zftape frontend
20 * to the ftape floppy tape driver for Linux
21 */
22
23#include <linux/module.h>
24#include <linux/errno.h>
25#include <linux/fs.h>
26#include <linux/kernel.h>
27#include <linux/signal.h>
28#include <linux/major.h>
29#include <linux/slab.h>
30#ifdef CONFIG_KMOD
31#include <linux/kmod.h>
32#endif
33#include <linux/fcntl.h>
34#include <linux/smp_lock.h>
35
36#include <linux/zftape.h>
37#include <linux/init.h>
38#include <linux/device.h>
39
40#include "../zftape/zftape-init.h"
41#include "../zftape/zftape-read.h"
42#include "../zftape/zftape-write.h"
43#include "../zftape/zftape-ctl.h"
44#include "../zftape/zftape-buffers.h"
45
46MODULE_AUTHOR("(c) 1996, 1997 Claus-Justus Heine "
47 "(claus@momo.math.rwth-aachen.de)");
48MODULE_DESCRIPTION(ZFTAPE_VERSION " - "
49 "VFS interface for the Linux floppy tape driver. "
50 "Support for QIC-113 compatible volume table "
51 "and builtin compression (lzrw3 algorithm)");
52MODULE_SUPPORTED_DEVICE("char-major-27");
53MODULE_LICENSE("GPL");
54
55/* Global vars.
56 */
57struct zft_cmpr_ops *zft_cmpr_ops = NULL;
58const ftape_info *zft_status;
59
60/* Local vars.
61 */
62static unsigned long busy_flag;
63
64static sigset_t orig_sigmask;
65
66/* the interface to the kernel vfs layer
67 */
68
69/* Note about llseek():
70 *
71 * st.c and tpqic.c update fp->f_pos but don't implment llseek() and
72 * initialize the llseek component of the file_ops struct with NULL.
73 * This means that the user will get the default seek, but the tape
74 * device will not respect the new position, but happily read from the
75 * old position. Think a zftape specific llseek() function would be
76 * better, returning -ESPIPE. TODO.
77 */
78
79static int zft_open (struct inode *ino, struct file *filep);
80static int zft_close(struct inode *ino, struct file *filep);
81static int zft_ioctl(struct inode *ino, struct file *filep,
82 unsigned int command, unsigned long arg);
83static int zft_mmap(struct file *filep, struct vm_area_struct *vma);
84static ssize_t zft_read (struct file *fp, char __user *buff,
85 size_t req_len, loff_t *ppos);
86static ssize_t zft_write(struct file *fp, const char __user *buff,
87 size_t req_len, loff_t *ppos);
88
89static const struct file_operations zft_cdev =
90{
91 .owner = THIS_MODULE,
92 .read = zft_read,
93 .write = zft_write,
94 .ioctl = zft_ioctl,
95 .mmap = zft_mmap,
96 .open = zft_open,
97 .release = zft_close,
98};
99
100static struct class *zft_class;
101
102/* Open floppy tape device
103 */
104static int zft_open(struct inode *ino, struct file *filep)
105{
106 int result;
107 TRACE_FUN(ft_t_flow);
108
109 nonseekable_open(ino, filep);
110 TRACE(ft_t_flow, "called for minor %d", iminor(ino));
111 if ( test_and_set_bit(0,&busy_flag) ) {
112 TRACE_ABORT(-EBUSY, ft_t_warn, "failed: already busy");
113 }
114 if ((iminor(ino) & ~(ZFT_MINOR_OP_MASK | FTAPE_NO_REWIND))
115 >
116 FTAPE_SEL_D) {
117 clear_bit(0,&busy_flag);
118 TRACE_ABORT(-ENXIO, ft_t_err, "failed: invalid unit nr");
119 }
120 orig_sigmask = current->blocked;
121 sigfillset(&current->blocked);
122 result = _zft_open(iminor(ino), filep->f_flags & O_ACCMODE);
123 if (result < 0) {
124 current->blocked = orig_sigmask; /* restore mask */
125 clear_bit(0,&busy_flag);
126 TRACE_ABORT(result, ft_t_err, "_ftape_open failed");
127 } else {
128 /* Mask signals that will disturb proper operation of the
129 * program that is calling.
130 */
131 current->blocked = orig_sigmask;
132 sigaddsetmask (&current->blocked, _DO_BLOCK);
133 TRACE_EXIT 0;
134 }
135}
136
137/* Close floppy tape device
138 */
139static int zft_close(struct inode *ino, struct file *filep)
140{
141 int result;
142 TRACE_FUN(ft_t_flow);
143
144 if ( !test_bit(0,&busy_flag) || iminor(ino) != zft_unit) {
145 TRACE(ft_t_err, "failed: not busy or wrong unit");
146 TRACE_EXIT 0;
147 }
148 sigfillset(&current->blocked);
149 result = _zft_close();
150 if (result < 0) {
151 TRACE(ft_t_err, "_zft_close failed");
152 }
153 current->blocked = orig_sigmask; /* restore before open state */
154 clear_bit(0,&busy_flag);
155 TRACE_EXIT 0;
156}
157
158/* Ioctl for floppy tape device
159 */
160static int zft_ioctl(struct inode *ino, struct file *filep,
161 unsigned int command, unsigned long arg)
162{
163 int result = -EIO;
164 sigset_t old_sigmask;
165 TRACE_FUN(ft_t_flow);
166
167 if ( !test_bit(0,&busy_flag) || iminor(ino) != zft_unit || ft_failure) {
168 TRACE_ABORT(-EIO, ft_t_err,
169 "failed: not busy, failure or wrong unit");
170 }
171 old_sigmask = current->blocked; /* save mask */
172 sigfillset(&current->blocked);
173 /* This will work as long as sizeof(void *) == sizeof(long) */
174 result = _zft_ioctl(command, (void __user *) arg);
175 current->blocked = old_sigmask; /* restore mask */
176 TRACE_EXIT result;
177}
178
179/* Ioctl for floppy tape device
180 */
181static int zft_mmap(struct file *filep, struct vm_area_struct *vma)
182{
183 int result = -EIO;
184 sigset_t old_sigmask;
185 TRACE_FUN(ft_t_flow);
186
187 if ( !test_bit(0,&busy_flag) ||
188 iminor(filep->f_dentry->d_inode) != zft_unit ||
189 ft_failure)
190 {
191 TRACE_ABORT(-EIO, ft_t_err,
192 "failed: not busy, failure or wrong unit");
193 }
194 old_sigmask = current->blocked; /* save mask */
195 sigfillset(&current->blocked);
196 if ((result = ftape_mmap(vma)) >= 0) {
197#ifndef MSYNC_BUG_WAS_FIXED
198 static struct vm_operations_struct dummy = { NULL, };
199 vma->vm_ops = &dummy;
200#endif
201 }
202 current->blocked = old_sigmask; /* restore mask */
203 TRACE_EXIT result;
204}
205
206/* Read from floppy tape device
207 */
208static ssize_t zft_read(struct file *fp, char __user *buff,
209 size_t req_len, loff_t *ppos)
210{
211 int result = -EIO;
212 sigset_t old_sigmask;
213 struct inode *ino = fp->f_dentry->d_inode;
214 TRACE_FUN(ft_t_flow);
215
216 TRACE(ft_t_data_flow, "called with count: %ld", (unsigned long)req_len);
217 if (!test_bit(0,&busy_flag) || iminor(ino) != zft_unit || ft_failure) {
218 TRACE_ABORT(-EIO, ft_t_err,
219 "failed: not busy, failure or wrong unit");
220 }
221 old_sigmask = current->blocked; /* save mask */
222 sigfillset(&current->blocked);
223 result = _zft_read(buff, req_len);
224 current->blocked = old_sigmask; /* restore mask */
225 TRACE(ft_t_data_flow, "return with count: %d", result);
226 TRACE_EXIT result;
227}
228
229/* Write to tape device
230 */
231static ssize_t zft_write(struct file *fp, const char __user *buff,
232 size_t req_len, loff_t *ppos)
233{
234 int result = -EIO;
235 sigset_t old_sigmask;
236 struct inode *ino = fp->f_dentry->d_inode;
237 TRACE_FUN(ft_t_flow);
238
239 TRACE(ft_t_flow, "called with count: %ld", (unsigned long)req_len);
240 if (!test_bit(0,&busy_flag) || iminor(ino) != zft_unit || ft_failure) {
241 TRACE_ABORT(-EIO, ft_t_err,
242 "failed: not busy, failure or wrong unit");
243 }
244 old_sigmask = current->blocked; /* save mask */
245 sigfillset(&current->blocked);
246 result = _zft_write(buff, req_len);
247 current->blocked = old_sigmask; /* restore mask */
248 TRACE(ft_t_data_flow, "return with count: %d", result);
249 TRACE_EXIT result;
250}
251
252/* END OF VFS INTERFACE
253 *
254 *****************************************************************************/
255
256/* driver/module initialization
257 */
258
259/* the compression module has to call this function to hook into the zftape
260 * code
261 */
262int zft_cmpr_register(struct zft_cmpr_ops *new_ops)
263{
264 TRACE_FUN(ft_t_flow);
265
266 if (zft_cmpr_ops != NULL) {
267 TRACE_EXIT -EBUSY;
268 } else {
269 zft_cmpr_ops = new_ops;
270 TRACE_EXIT 0;
271 }
272}
273
274/* lock the zft-compressor() module.
275 */
276int zft_cmpr_lock(int try_to_load)
277{
278 if (zft_cmpr_ops == NULL) {
279#ifdef CONFIG_KMOD
280 if (try_to_load) {
281 request_module("zft-compressor");
282 if (zft_cmpr_ops == NULL) {
283 return -ENOSYS;
284 }
285 } else {
286 return -ENOSYS;
287 }
288#else
289 return -ENOSYS;
290#endif
291 }
292 (*zft_cmpr_ops->lock)();
293 return 0;
294}
295
296#ifdef CONFIG_ZFT_COMPRESSOR
297extern int zft_compressor_init(void);
298#endif
299
300/* Called by modules package when installing the driver or by kernel
301 * during the initialization phase
302 */
303int __init zft_init(void)
304{
305 int i;
306 TRACE_FUN(ft_t_flow);
307
308#ifdef MODULE
309 printk(KERN_INFO ZFTAPE_VERSION "\n");
310 if (TRACE_LEVEL >= ft_t_info) {
311 printk(
312KERN_INFO
313"(c) 1996, 1997 Claus-Justus Heine (claus@momo.math.rwth-aachen.de)\n"
314KERN_INFO
315"vfs interface for ftape floppy tape driver.\n"
316KERN_INFO
317"Support for QIC-113 compatible volume table, dynamic memory allocation\n"
318KERN_INFO
319"and builtin compression (lzrw3 algorithm).\n");
320 }
321#else /* !MODULE */
322 /* print a short no-nonsense boot message */
323 printk(KERN_INFO ZFTAPE_VERSION "\n");
324#endif /* MODULE */
325 TRACE(ft_t_info, "zft_init @ 0x%p", zft_init);
326 TRACE(ft_t_info,
327 "installing zftape VFS interface for ftape driver ...");
328 TRACE_CATCH(register_chrdev(QIC117_TAPE_MAJOR, "zft", &zft_cdev),);
329
330 zft_class = class_create(THIS_MODULE, "zft");
331 for (i = 0; i < 4; i++) {
332 class_device_create(zft_class, NULL, MKDEV(QIC117_TAPE_MAJOR, i), NULL, "qft%i", i);
333 class_device_create(zft_class, NULL, MKDEV(QIC117_TAPE_MAJOR, i + 4), NULL, "nqft%i", i);
334 class_device_create(zft_class, NULL, MKDEV(QIC117_TAPE_MAJOR, i + 16), NULL, "zqft%i", i);
335 class_device_create(zft_class, NULL, MKDEV(QIC117_TAPE_MAJOR, i + 20), NULL, "nzqft%i", i);
336 class_device_create(zft_class, NULL, MKDEV(QIC117_TAPE_MAJOR, i + 32), NULL, "rawqft%i", i);
337 class_device_create(zft_class, NULL, MKDEV(QIC117_TAPE_MAJOR, i + 36), NULL, "nrawrawqft%i", i);
338 }
339
340#ifdef CONFIG_ZFT_COMPRESSOR
341 (void)zft_compressor_init();
342#endif
343 zft_status = ftape_get_status(); /* fetch global data of ftape
344 * hardware driver
345 */
346 TRACE_EXIT 0;
347}
348
349
350/* Called by modules package when removing the driver
351 */
352static void zft_exit(void)
353{
354 int i;
355 TRACE_FUN(ft_t_flow);
356
357 if (unregister_chrdev(QIC117_TAPE_MAJOR, "zft") != 0) {
358 TRACE(ft_t_warn, "failed");
359 } else {
360 TRACE(ft_t_info, "successful");
361 }
362 for (i = 0; i < 4; i++) {
363 class_device_destroy(zft_class, MKDEV(QIC117_TAPE_MAJOR, i));
364 class_device_destroy(zft_class, MKDEV(QIC117_TAPE_MAJOR, i + 4));
365 class_device_destroy(zft_class, MKDEV(QIC117_TAPE_MAJOR, i + 16));
366 class_device_destroy(zft_class, MKDEV(QIC117_TAPE_MAJOR, i + 20));
367 class_device_destroy(zft_class, MKDEV(QIC117_TAPE_MAJOR, i + 32));
368 class_device_destroy(zft_class, MKDEV(QIC117_TAPE_MAJOR, i + 36));
369 }
370 class_destroy(zft_class);
371 zft_uninit_mem(); /* release remaining memory, if any */
372 printk(KERN_INFO "zftape successfully unloaded.\n");
373 TRACE_EXIT;
374}
375
376module_init(zft_init);
377module_exit(zft_exit);
diff --git a/drivers/char/ftape/zftape/zftape-init.h b/drivers/char/ftape/zftape/zftape-init.h
deleted file mode 100644
index 937e5d48c20e..000000000000
--- a/drivers/char/ftape/zftape/zftape-init.h
+++ /dev/null
@@ -1,77 +0,0 @@
1#ifndef _ZFTAPE_INIT_H
2#define _ZFTAPE_INIT_H
3
4/*
5 * Copyright (C) 1996, 1997 Claus Heine.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 *
22 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-init.h,v $
23 * $Revision: 1.2 $
24 * $Date: 1997/10/05 19:19:05 $
25 *
26 * This file contains definitions and macro for the vfs
27 * interface defined by zftape
28 *
29 */
30
31#include <linux/ftape-header-segment.h>
32
33#include "../lowlevel/ftape-tracing.h"
34#include "../lowlevel/ftape-ctl.h"
35#include "../lowlevel/ftape-read.h"
36#include "../lowlevel/ftape-write.h"
37#include "../lowlevel/ftape-bsm.h"
38#include "../lowlevel/ftape-io.h"
39#include "../lowlevel/ftape-buffer.h"
40#include "../lowlevel/ftape-format.h"
41
42#include "../zftape/zftape-rw.h"
43
44#ifdef MODULE
45#define ftape_status (*zft_status)
46#endif
47
48extern const ftape_info *zft_status; /* needed for zftape-vtbl.h */
49
50#include "../zftape/zftape-vtbl.h"
51
52struct zft_cmpr_ops {
53 int (*write)(int *write_cnt,
54 __u8 *dst_buf, const int seg_sz,
55 const __u8 __user *src_buf, const int req_len,
56 const zft_position *pos, const zft_volinfo *volume);
57 int (*read)(int *read_cnt,
58 __u8 __user *dst_buf, const int req_len,
59 const __u8 *src_buf, const int seg_sz,
60 const zft_position *pos, const zft_volinfo *volume);
61 int (*seek)(unsigned int new_block_pos,
62 zft_position *pos, const zft_volinfo *volume,
63 __u8 *buffer);
64 void (*lock) (void);
65 void (*reset) (void);
66 void (*cleanup)(void);
67};
68
69extern struct zft_cmpr_ops *zft_cmpr_ops;
70/* zftape-init.c defined global functions.
71 */
72extern int zft_cmpr_register(struct zft_cmpr_ops *new_ops);
73extern int zft_cmpr_lock(int try_to_load);
74
75#endif
76
77
diff --git a/drivers/char/ftape/zftape/zftape-read.c b/drivers/char/ftape/zftape/zftape-read.c
deleted file mode 100644
index 214bf03dce68..000000000000
--- a/drivers/char/ftape/zftape/zftape-read.c
+++ /dev/null
@@ -1,377 +0,0 @@
1/*
2 * Copyright (C) 1996, 1997 Claus-Justus Heine
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 *
19 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-read.c,v $
20 * $Revision: 1.2 $
21 * $Date: 1997/10/05 19:19:06 $
22 *
23 * This file contains the high level reading code
24 * for the QIC-117 floppy-tape driver for Linux.
25 */
26
27#include <linux/errno.h>
28#include <linux/mm.h>
29
30#include <linux/zftape.h>
31
32#include <asm/uaccess.h>
33
34#include "../zftape/zftape-init.h"
35#include "../zftape/zftape-eof.h"
36#include "../zftape/zftape-ctl.h"
37#include "../zftape/zftape-write.h"
38#include "../zftape/zftape-read.h"
39#include "../zftape/zftape-rw.h"
40#include "../zftape/zftape-vtbl.h"
41
42/* Global vars.
43 */
44int zft_just_before_eof;
45
46/* Local vars.
47 */
48static int buf_len_rd;
49
50void zft_zap_read_buffers(void)
51{
52 buf_len_rd = 0;
53}
54
55int zft_read_header_segments(void)
56{
57 TRACE_FUN(ft_t_flow);
58
59 zft_header_read = 0;
60 TRACE_CATCH(zft_vmalloc_once(&zft_hseg_buf, FT_SEGMENT_SIZE),);
61 TRACE_CATCH(ftape_read_header_segment(zft_hseg_buf),);
62 TRACE(ft_t_info, "Segments written since first format: %d",
63 (int)GET4(zft_hseg_buf, FT_SEG_CNT));
64 zft_qic113 = (ft_format_code != fmt_normal &&
65 ft_format_code != fmt_1100ft &&
66 ft_format_code != fmt_425ft);
67 TRACE(ft_t_info, "ft_first_data_segment: %d, ft_last_data_segment: %d",
68 ft_first_data_segment, ft_last_data_segment);
69 zft_capacity = zft_get_capacity();
70 zft_old_ftape = zft_ftape_validate_label(&zft_hseg_buf[FT_LABEL]);
71 if (zft_old_ftape) {
72 TRACE(ft_t_info,
73"Found old ftaped tape, emulating eof marks, entering read-only mode");
74 zft_ftape_extract_file_marks(zft_hseg_buf);
75 TRACE_CATCH(zft_fake_volume_headers(zft_eof_map,
76 zft_nr_eof_marks),);
77 } else {
78 /* the specs say that the volume table must be
79 * initialized with zeroes during formatting, so it
80 * MUST be readable, i.e. contain vaid ECC
81 * information.
82 */
83 TRACE_CATCH(ftape_read_segment(ft_first_data_segment,
84 zft_deblock_buf,
85 FT_RD_SINGLE),);
86 TRACE_CATCH(zft_extract_volume_headers(zft_deblock_buf),);
87 }
88 zft_header_read = 1;
89 zft_set_flags(zft_unit);
90 zft_reset_position(&zft_pos);
91 TRACE_EXIT 0;
92}
93
94int zft_fetch_segment_fraction(const unsigned int segment, void *buffer,
95 const ft_read_mode_t read_mode,
96 const unsigned int start,
97 const unsigned int size)
98{
99 int seg_sz;
100 TRACE_FUN(ft_t_flow);
101
102 if (segment == zft_deblock_segment) {
103 TRACE(ft_t_data_flow,
104 "re-using segment %d already in deblock buffer",
105 segment);
106 seg_sz = zft_get_seg_sz(segment);
107 if (start > seg_sz) {
108 TRACE_ABORT(-EINVAL, ft_t_bug,
109 "trying to read beyond end of segment:\n"
110 KERN_INFO "seg_sz : %d\n"
111 KERN_INFO "start : %d\n"
112 KERN_INFO "segment: %d",
113 seg_sz, start, segment);
114 }
115 if ((start + size) > seg_sz) {
116 TRACE_EXIT seg_sz - start;
117 }
118 TRACE_EXIT size;
119 }
120 seg_sz = ftape_read_segment_fraction(segment, buffer, read_mode,
121 start, size);
122 TRACE(ft_t_data_flow, "segment %d, result %d", segment, seg_sz);
123 if ((int)seg_sz >= 0 && start == 0 && size == FT_SEGMENT_SIZE) {
124 /* this implicitly assumes that we are always called with
125 * buffer == zft_deblock_buf
126 */
127 zft_deblock_segment = segment;
128 } else {
129 zft_deblock_segment = -1;
130 }
131 TRACE_EXIT seg_sz;
132}
133
134/*
135 * out:
136 *
137 * int *read_cnt: the number of bytes we removed from the
138 * zft_deblock_buf (result)
139 *
140 * int *to_do : the remaining size of the read-request. Is changed.
141 *
142 * in:
143 *
144 * char *buff : buff is the address of the upper part of the user
145 * buffer, that hasn't been filled with data yet.
146 * int buf_pos_read: copy of buf_pos_rd
147 * int buf_len_read: copy of buf_len_rd
148 * char *zft_deblock_buf: ftape_zft_deblock_buf
149 *
150 * returns the amount of data actually copied to the user-buffer
151 *
152 * to_do MUST NOT SHRINK except to indicate an EOT. In this case to_do
153 * has to be set to 0. We cannot return -ENOSPC, because we return the
154 * amount of data actually * copied to the user-buffer
155 */
156static int zft_simple_read (int *read_cnt,
157 __u8 __user *dst_buf,
158 const int to_do,
159 const __u8 *src_buf,
160 const int seg_sz,
161 const zft_position *pos,
162 const zft_volinfo *volume)
163{
164 TRACE_FUN(ft_t_flow);
165
166 if (seg_sz - pos->seg_byte_pos < to_do) {
167 *read_cnt = seg_sz - pos->seg_byte_pos;
168 } else {
169 *read_cnt = to_do;
170 }
171 if (copy_to_user(dst_buf,
172 src_buf + pos->seg_byte_pos, *read_cnt) != 0) {
173 TRACE_EXIT -EFAULT;
174 }
175 TRACE(ft_t_noise, "nr bytes just read: %d", *read_cnt);
176 TRACE_EXIT *read_cnt;
177}
178
179/* req_len: gets clipped due to EOT of EOF.
180 * req_clipped: is a flag indicating whether req_len was clipped or not
181 * volume: contains information on current volume (blk_sz etc.)
182 */
183static int check_read_access(int *req_len,
184 const zft_volinfo **volume,
185 int *req_clipped,
186 const zft_position *pos)
187{
188 static __s64 remaining;
189 static int eod;
190 TRACE_FUN(ft_t_flow);
191
192 if (zft_io_state != zft_reading) {
193 if (zft_offline) { /* offline includes no_tape */
194 TRACE_ABORT(-ENXIO, ft_t_warn,
195 "tape is offline or no cartridge");
196 }
197 if (!ft_formatted) {
198 TRACE_ABORT(-EACCES,
199 ft_t_warn, "tape is not formatted");
200 }
201 /* now enter defined state, read header segment if not
202 * already done and flush write buffers
203 */
204 TRACE_CATCH(zft_def_idle_state(),);
205 zft_io_state = zft_reading;
206 if (zft_tape_at_eod(pos)) {
207 eod = 1;
208 TRACE_EXIT 1;
209 }
210 eod = 0;
211 *volume = zft_find_volume(pos->seg_pos);
212 /* get the space left until EOF */
213 remaining = zft_check_for_eof(*volume, pos);
214 buf_len_rd = 0;
215 TRACE(ft_t_noise, "remaining: " LL_X ", vol_no: %d",
216 LL(remaining), (*volume)->count);
217 } else if (zft_tape_at_eod(pos)) {
218 if (++eod > 2) {
219 TRACE_EXIT -EIO; /* st.c also returns -EIO */
220 } else {
221 TRACE_EXIT 1;
222 }
223 }
224 if ((*req_len % (*volume)->blk_sz) != 0) {
225 /* this message is informational only. The user gets the
226 * proper return value
227 */
228 TRACE_ABORT(-EINVAL, ft_t_info,
229 "req_len %d not a multiple of block size %d",
230 *req_len, (*volume)->blk_sz);
231 }
232 /* As GNU tar doesn't accept partial read counts when the
233 * multiple volume flag is set, we make sure to return the
234 * requested amount of data. Except, of course, at the end of
235 * the tape or file mark.
236 */
237 remaining -= *req_len;
238 if (remaining <= 0) {
239 TRACE(ft_t_noise,
240 "clipped request from %d to %d.",
241 *req_len, (int)(*req_len + remaining));
242 *req_len += remaining;
243 *req_clipped = 1;
244 } else {
245 *req_clipped = 0;
246 }
247 TRACE_EXIT 0;
248}
249
250/* this_segs_size: the current segment's size.
251 * buff: the USER-SPACE buffer provided by the calling function.
252 * req_len: how much data should be read at most.
253 * volume: contains information on current volume (blk_sz etc.)
254 */
255static int empty_deblock_buf(__u8 __user *usr_buf, const int req_len,
256 const __u8 *src_buf, const int seg_sz,
257 zft_position *pos,
258 const zft_volinfo *volume)
259{
260 int cnt;
261 int result = 0;
262 TRACE_FUN(ft_t_flow);
263
264 TRACE(ft_t_data_flow, "this_segs_size: %d", seg_sz);
265 if (zft_use_compression && volume->use_compression) {
266 TRACE_CATCH(zft_cmpr_lock(1 /* try to load */),);
267 TRACE_CATCH(result= (*zft_cmpr_ops->read)(&cnt,
268 usr_buf, req_len,
269 src_buf, seg_sz,
270 pos, volume),);
271 } else {
272 TRACE_CATCH(result= zft_simple_read (&cnt,
273 usr_buf, req_len,
274 src_buf, seg_sz,
275 pos, volume),);
276 }
277 pos->volume_pos += result;
278 pos->tape_pos += cnt;
279 pos->seg_byte_pos += cnt;
280 buf_len_rd -= cnt; /* remaining bytes in buffer */
281 TRACE(ft_t_data_flow, "buf_len_rd: %d, cnt: %d", buf_len_rd, cnt);
282 if(pos->seg_byte_pos >= seg_sz) {
283 pos->seg_pos++;
284 pos->seg_byte_pos = 0;
285 }
286 TRACE(ft_t_data_flow, "bytes moved out of deblock-buffer: %d", cnt);
287 TRACE_EXIT result;
288}
289
290
291/* note: we store the segment id of the segment that is inside the
292 * deblock buffer. This spares a lot of ftape_read_segment()s when we
293 * use small block-sizes. The block-size may be 1kb (SECTOR_SIZE). In
294 * this case a MTFSR 28 maybe still inside the same segment.
295 */
296int _zft_read(char __user *buff, int req_len)
297{
298 int req_clipped;
299 int result = 0;
300 int bytes_read = 0;
301 static unsigned int seg_sz = 0;
302 static const zft_volinfo *volume = NULL;
303 TRACE_FUN(ft_t_flow);
304
305 zft_resid = req_len;
306 result = check_read_access(&req_len, &volume,
307 &req_clipped, &zft_pos);
308 switch(result) {
309 case 0:
310 break; /* nothing special */
311 case 1:
312 TRACE(ft_t_noise, "EOD reached");
313 TRACE_EXIT 0; /* EOD */
314 default:
315 TRACE_ABORT(result, ft_t_noise,
316 "check_read_access() failed with result %d",
317 result);
318 TRACE_EXIT result;
319 }
320 while (req_len > 0) {
321 /* Allow escape from this loop on signal !
322 */
323 FT_SIGNAL_EXIT(_DONT_BLOCK);
324 /* buf_len_rd == 0 means that we need to read a new
325 * segment.
326 */
327 if (buf_len_rd == 0) {
328 while((result = zft_fetch_segment(zft_pos.seg_pos,
329 zft_deblock_buf,
330 FT_RD_AHEAD)) == 0) {
331 zft_pos.seg_pos ++;
332 zft_pos.seg_byte_pos = 0;
333 }
334 if (result < 0) {
335 zft_resid -= bytes_read;
336 TRACE_ABORT(result, ft_t_noise,
337 "zft_fetch_segment(): %d",
338 result);
339 }
340 seg_sz = result;
341 buf_len_rd = seg_sz - zft_pos.seg_byte_pos;
342 }
343 TRACE_CATCH(result = empty_deblock_buf(buff,
344 req_len,
345 zft_deblock_buf,
346 seg_sz,
347 &zft_pos,
348 volume),
349 zft_resid -= bytes_read);
350 TRACE(ft_t_data_flow, "bytes just read: %d", result);
351 bytes_read += result; /* what we got so far */
352 buff += result; /* index in user-buffer */
353 req_len -= result; /* what's left from req_len */
354 } /* while (req_len > 0) */
355 if (req_clipped) {
356 TRACE(ft_t_data_flow,
357 "maybe partial count because of eof mark");
358 if (zft_just_before_eof && bytes_read == 0) {
359 /* req_len was > 0, but user didn't get
360 * anything the user has read in the eof-mark
361 */
362 zft_move_past_eof(&zft_pos);
363 ftape_abort_operation();
364 } else {
365 /* don't skip to the next file before the user
366 * tried to read a second time past EOF Just
367 * mark that we are at EOF and maybe decrement
368 * zft_seg_pos to stay in the same volume;
369 */
370 zft_just_before_eof = 1;
371 zft_position_before_eof(&zft_pos, volume);
372 TRACE(ft_t_noise, "just before eof");
373 }
374 }
375 zft_resid -= result; /* for MTSTATUS */
376 TRACE_EXIT bytes_read;
377}
diff --git a/drivers/char/ftape/zftape/zftape-read.h b/drivers/char/ftape/zftape/zftape-read.h
deleted file mode 100644
index 42941de0c23a..000000000000
--- a/drivers/char/ftape/zftape/zftape-read.h
+++ /dev/null
@@ -1,53 +0,0 @@
1#ifndef _ZFTAPE_READ_H
2#define _ZFTAPE_READ_H
3
4/*
5 * Copyright (C) 1996, 1997 Claus-Justus Heine
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 *
22 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-read.h,v $
23 * $Revision: 1.2 $
24 * $Date: 1997/10/05 19:19:07 $
25 *
26 * This file contains the definitions for the read functions
27 * for the zftape driver for Linux.
28 *
29 */
30
31#include "../lowlevel/ftape-read.h"
32
33/* ftape-read.c defined global vars.
34 */
35extern int zft_just_before_eof;
36
37/* ftape-read.c defined global functions.
38 */
39extern void zft_zap_read_buffers(void);
40extern int zft_read_header_segments(void);
41extern int zft_fetch_segment_fraction(const unsigned int segment,
42 void *buffer,
43 const ft_read_mode_t read_mode,
44 const unsigned int start,
45 const unsigned int size);
46#define zft_fetch_segment(segment, address, read_mode) \
47 zft_fetch_segment_fraction(segment, address, read_mode, \
48 0, FT_SEGMENT_SIZE)
49/* hook for the VFS interface
50 */
51extern int _zft_read(char __user *buff, int req_len);
52
53#endif /* _ZFTAPE_READ_H */
diff --git a/drivers/char/ftape/zftape/zftape-rw.c b/drivers/char/ftape/zftape/zftape-rw.c
deleted file mode 100644
index a61ef50f3dfc..000000000000
--- a/drivers/char/ftape/zftape/zftape-rw.c
+++ /dev/null
@@ -1,376 +0,0 @@
1/*
2 * Copyright (C) 1996, 1997 Claus-Justus Heine
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 *
19 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-rw.c,v $
20 * $Revision: 1.2 $
21 * $Date: 1997/10/05 19:19:08 $
22 *
23 * This file contains some common code for the r/w code for
24 * zftape.
25 */
26
27#include <linux/config.h> /* for CONFIG_ZFT_DFLT_BLK_SZ */
28#include <linux/errno.h>
29#include <linux/mm.h>
30
31#include <linux/zftape.h>
32#include "../zftape/zftape-init.h"
33#include "../zftape/zftape-eof.h"
34#include "../zftape/zftape-ctl.h"
35#include "../zftape/zftape-write.h"
36#include "../zftape/zftape-read.h"
37#include "../zftape/zftape-rw.h"
38#include "../zftape/zftape-vtbl.h"
39
40/* Global vars.
41 */
42
43__u8 *zft_deblock_buf;
44__u8 *zft_hseg_buf;
45int zft_deblock_segment = -1;
46zft_status_enum zft_io_state = zft_idle;
47int zft_header_changed;
48int zft_qic113; /* conform to old specs. and old zftape */
49int zft_use_compression;
50zft_position zft_pos = {
51 -1, /* seg_pos */
52 0, /* seg_byte_pos */
53 0, /* tape_pos */
54 0 /* volume_pos */
55};
56unsigned int zft_blk_sz = CONFIG_ZFT_DFLT_BLK_SZ;
57__s64 zft_capacity;
58
59unsigned int zft_written_segments;
60int zft_label_changed;
61
62/* Local vars.
63 */
64
65unsigned int zft_get_seg_sz(unsigned int segment)
66{
67 int size;
68 TRACE_FUN(ft_t_any);
69
70 size = FT_SEGMENT_SIZE -
71 count_ones(ftape_get_bad_sector_entry(segment))*FT_SECTOR_SIZE;
72 if (size > 0) {
73 TRACE_EXIT (unsigned)size;
74 } else {
75 TRACE_EXIT 0;
76 }
77}
78
79/* ftape_set_flags(). Claus-Justus Heine, 1994/1995
80 */
81void zft_set_flags(unsigned minor_unit)
82{
83 TRACE_FUN(ft_t_flow);
84
85 zft_use_compression = zft_qic_mode = 0;
86 switch (minor_unit & ZFT_MINOR_OP_MASK) {
87 case (ZFT_Q80_MODE | ZFT_ZIP_MODE):
88 case ZFT_ZIP_MODE:
89 zft_use_compression = 1;
90 case 0:
91 case ZFT_Q80_MODE:
92 zft_qic_mode = 1;
93 if (zft_mt_compression) { /* override the default */
94 zft_use_compression = 1;
95 }
96 break;
97 case ZFT_RAW_MODE:
98 TRACE(ft_t_noise, "switching to raw mode");
99 break;
100 default:
101 TRACE(ft_t_warn, "Warning:\n"
102 KERN_INFO "Wrong combination of minor device bits.\n"
103 KERN_INFO "Switching to raw read-only mode.");
104 zft_write_protected = 1;
105 break;
106 }
107 TRACE_EXIT;
108}
109
110/* computes the segment and byte offset inside the segment
111 * corresponding to tape_pos.
112 *
113 * tape_pos gives the offset in bytes from the beginning of the
114 * ft_first_data_segment *seg_byte_pos is the offset in the current
115 * segment in bytes
116 *
117 * Of, if this routine was called often one should cache the last data
118 * pos it was called with, but actually this is only needed in
119 * ftape_seek_block(), that is, almost never.
120 */
121int zft_calc_seg_byte_coord(int *seg_byte_pos, __s64 tape_pos)
122{
123 int segment;
124 int seg_sz;
125 TRACE_FUN(ft_t_flow);
126
127 if (tape_pos == 0) {
128 *seg_byte_pos = 0;
129 segment = ft_first_data_segment;
130 } else {
131 seg_sz = 0;
132
133 for (segment = ft_first_data_segment;
134 ((tape_pos > 0) && (segment <= ft_last_data_segment));
135 segment++) {
136 seg_sz = zft_get_seg_sz(segment);
137 tape_pos -= seg_sz;
138 }
139 if(tape_pos >= 0) {
140 /* the case tape_pos > != 0 means that the
141 * argument tape_pos lies beyond the EOT.
142 */
143 *seg_byte_pos= 0;
144 } else { /* tape_pos < 0 */
145 segment--;
146 *seg_byte_pos= tape_pos + seg_sz;
147 }
148 }
149 TRACE_EXIT(segment);
150}
151
152/* ftape_calc_tape_pos().
153 *
154 * computes the offset in bytes from the beginning of the
155 * ft_first_data_segment inverse to ftape_calc_seg_byte_coord
156 *
157 * We should do some caching. But how:
158 *
159 * Each time the header segments are read in, this routine is called
160 * with ft_tracks_per_tape*segments_per_track argumnet. So this should be
161 * the time to reset the cache.
162 *
163 * Also, it might be in the future that the bad sector map gets
164 * changed. -> reset the cache
165 */
166static int seg_pos;
167static __s64 tape_pos;
168
169__s64 zft_get_capacity(void)
170{
171 seg_pos = ft_first_data_segment;
172 tape_pos = 0;
173
174 while (seg_pos <= ft_last_data_segment) {
175 tape_pos += zft_get_seg_sz(seg_pos ++);
176 }
177 return tape_pos;
178}
179
180__s64 zft_calc_tape_pos(int segment)
181{
182 int d1, d2, d3;
183 TRACE_FUN(ft_t_any);
184
185 if (segment > ft_last_data_segment) {
186 TRACE_EXIT zft_capacity;
187 }
188 if (segment < ft_first_data_segment) {
189 TRACE_EXIT 0;
190 }
191 d2 = segment - seg_pos;
192 if (-d2 > 10) {
193 d1 = segment - ft_first_data_segment;
194 if (-d2 > d1) {
195 tape_pos = 0;
196 seg_pos = ft_first_data_segment;
197 d2 = d1;
198 }
199 }
200 if (d2 > 10) {
201 d3 = ft_last_data_segment - segment;
202 if (d2 > d3) {
203 tape_pos = zft_capacity;
204 seg_pos = ft_last_data_segment + 1;
205 d2 = -d3;
206 }
207 }
208 if (d2 > 0) {
209 while (seg_pos < segment) {
210 tape_pos += zft_get_seg_sz(seg_pos++);
211 }
212 } else {
213 while (seg_pos > segment) {
214 tape_pos -= zft_get_seg_sz(--seg_pos);
215 }
216 }
217 TRACE(ft_t_noise, "new cached pos: %d", seg_pos);
218
219 TRACE_EXIT tape_pos;
220}
221
222/* copy Z-label string to buffer, keeps track of the correct offset in
223 * `buffer'
224 */
225void zft_update_label(__u8 *buffer)
226{
227 TRACE_FUN(ft_t_flow);
228
229 if (strncmp(&buffer[FT_LABEL], ZFTAPE_LABEL,
230 sizeof(ZFTAPE_LABEL)-1) != 0) {
231 TRACE(ft_t_info, "updating label from \"%s\" to \"%s\"",
232 &buffer[FT_LABEL], ZFTAPE_LABEL);
233 strcpy(&buffer[FT_LABEL], ZFTAPE_LABEL);
234 memset(&buffer[FT_LABEL] + sizeof(ZFTAPE_LABEL) - 1, ' ',
235 FT_LABEL_SZ - sizeof(ZFTAPE_LABEL + 1));
236 PUT4(buffer, FT_LABEL_DATE, 0);
237 zft_label_changed = zft_header_changed = 1; /* changed */
238 }
239 TRACE_EXIT;
240}
241
242int zft_verify_write_segments(unsigned int segment,
243 __u8 *data, size_t size,
244 __u8 *buffer)
245{
246 int result;
247 __u8 *write_buf;
248 __u8 *src_buf;
249 int single;
250 int seg_pos;
251 int seg_sz;
252 int remaining;
253 ft_write_mode_t write_mode;
254 TRACE_FUN(ft_t_flow);
255
256 seg_pos = segment;
257 seg_sz = zft_get_seg_sz(seg_pos);
258 src_buf = data;
259 single = size <= seg_sz;
260 remaining = size;
261 do {
262 TRACE(ft_t_noise, "\n"
263 KERN_INFO "remaining: %d\n"
264 KERN_INFO "seg_sz : %d\n"
265 KERN_INFO "segment : %d",
266 remaining, seg_sz, seg_pos);
267 if (remaining == seg_sz) {
268 write_buf = src_buf;
269 write_mode = single ? FT_WR_SINGLE : FT_WR_MULTI;
270 remaining = 0;
271 } else if (remaining > seg_sz) {
272 write_buf = src_buf;
273 write_mode = FT_WR_ASYNC; /* don't start tape */
274 remaining -= seg_sz;
275 } else { /* remaining < seg_sz */
276 write_buf = buffer;
277 memcpy(write_buf, src_buf, remaining);
278 memset(&write_buf[remaining],'\0',seg_sz-remaining);
279 write_mode = single ? FT_WR_SINGLE : FT_WR_MULTI;
280 remaining = 0;
281 }
282 if ((result = ftape_write_segment(seg_pos,
283 write_buf,
284 write_mode)) != seg_sz) {
285 TRACE(ft_t_err, "Error: "
286 "Couldn't write segment %d", seg_pos);
287 TRACE_EXIT result < 0 ? result : -EIO; /* bail out */
288 }
289 zft_written_segments ++;
290 seg_sz = zft_get_seg_sz(++seg_pos);
291 src_buf += result;
292 } while (remaining > 0);
293 if (ftape_get_status()->fti_state == writing) {
294 TRACE_CATCH(ftape_loop_until_writes_done(),);
295 TRACE_CATCH(ftape_abort_operation(),);
296 zft_prevent_flush();
297 }
298 seg_pos = segment;
299 src_buf = data;
300 remaining = size;
301 do {
302 TRACE_CATCH(result = ftape_read_segment(seg_pos, buffer,
303 single ? FT_RD_SINGLE
304 : FT_RD_AHEAD),);
305 if (memcmp(src_buf, buffer,
306 remaining > result ? result : remaining) != 0) {
307 TRACE_ABORT(-EIO, ft_t_err,
308 "Failed to verify written segment %d",
309 seg_pos);
310 }
311 remaining -= result;
312 TRACE(ft_t_noise, "verify successful:\n"
313 KERN_INFO "segment : %d\n"
314 KERN_INFO "segsize : %d\n"
315 KERN_INFO "remaining: %d",
316 seg_pos, result, remaining);
317 src_buf += seg_sz;
318 seg_pos++;
319 } while (remaining > 0);
320 TRACE_EXIT size;
321}
322
323
324/* zft_erase(). implemented compression-handling
325 *
326 * calculate the first data-segment when using/not using compression.
327 *
328 * update header-segment and compression-map-segment.
329 */
330int zft_erase(void)
331{
332 int result = 0;
333 TRACE_FUN(ft_t_flow);
334
335 if (!zft_header_read) {
336 TRACE_CATCH(zft_vmalloc_once((void **)&zft_hseg_buf,
337 FT_SEGMENT_SIZE),);
338 /* no need to read the vtbl and compression map */
339 TRACE_CATCH(ftape_read_header_segment(zft_hseg_buf),);
340 if ((zft_old_ftape =
341 zft_ftape_validate_label(&zft_hseg_buf[FT_LABEL]))) {
342 zft_ftape_extract_file_marks(zft_hseg_buf);
343 }
344 TRACE(ft_t_noise,
345 "ft_first_data_segment: %d, ft_last_data_segment: %d",
346 ft_first_data_segment, ft_last_data_segment);
347 zft_qic113 = (ft_format_code != fmt_normal &&
348 ft_format_code != fmt_1100ft &&
349 ft_format_code != fmt_425ft);
350 }
351 if (zft_old_ftape) {
352 zft_clear_ftape_file_marks();
353 zft_old_ftape = 0; /* no longer old ftape */
354 }
355 PUT2(zft_hseg_buf, FT_CMAP_START, 0);
356 zft_volume_table_changed = 1;
357 zft_capacity = zft_get_capacity();
358 zft_init_vtbl();
359 /* the rest must be done in ftape_update_header_segments
360 */
361 zft_header_read = 1;
362 zft_header_changed = 1; /* force update of timestamp */
363 result = zft_update_header_segments();
364
365 ftape_abort_operation();
366
367 zft_reset_position(&zft_pos);
368 zft_set_flags (zft_unit);
369 TRACE_EXIT result;
370}
371
372unsigned int zft_get_time(void)
373{
374 unsigned int date = FT_TIME_STAMP(2097, 11, 30, 23, 59, 59); /* fun */
375 return date;
376}
diff --git a/drivers/char/ftape/zftape/zftape-rw.h b/drivers/char/ftape/zftape/zftape-rw.h
deleted file mode 100644
index 14c07f086575..000000000000
--- a/drivers/char/ftape/zftape/zftape-rw.h
+++ /dev/null
@@ -1,102 +0,0 @@
1#ifndef _ZFTAPE_RW_H
2#define _ZFTAPE_RW_H
3
4/*
5 * Copyright (C) 1996, 1997 Claus-Justus Heine.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 *
22 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-rw.h,v $
23 * $Revision: 1.2 $
24 * $Date: 1997/10/05 19:19:09 $
25 *
26 * This file contains the definitions for the read and write
27 * functions for the QIC-117 floppy-tape driver for Linux.
28 *
29 */
30
31#include <linux/config.h> /* for CONFIG_ZFT_DFLT_BLK_SZ */
32#include "../zftape/zftape-buffers.h"
33
34#define SEGMENTS_PER_TAPE (ft_segments_per_track * ft_tracks_per_tape)
35
36/* QIC-113 Rev. G says that `a maximum of 63488 raw bytes may be
37 * compressed into a single frame'.
38 * Maybe we should stick to 32kb to make it more `beautiful'
39 */
40#define ZFT_MAX_BLK_SZ (62*1024) /* bytes */
41#if !defined(CONFIG_ZFT_DFLT_BLK_SZ)
42# define CONFIG_ZFT_DFLT_BLK_SZ (10*1024) /* bytes, default of gnu tar */
43#elif CONFIG_ZFT_DFLT_BLK_SZ == 0
44# undef CONFIG_ZFT_DFLT_BLK_SZ
45# define CONFIG_ZFT_DFLT_BLK_SZ 1
46#elif (CONFIG_ZFT_DFLT_BLK_SZ % 1024) != 0
47# error CONFIG_ZFT_DFLT_BLK_SZ must be 1 or a multiple of 1024
48#endif
49/* The *optional* compression routines need some overhead per tape
50 * block for their purposes. Instead of asking the actual compression
51 * implementation how much it needs, we restrict this overhead to be
52 * maximal of ZFT_CMPT_OVERHEAD size. We need this for EOT
53 * conditions. The tape is assumed to be logical at EOT when the
54 * distance from the physical EOT is less than
55 * one tape block + ZFT_CMPR_OVERHEAD
56 */
57#define ZFT_CMPR_OVERHEAD 16 /* bytes */
58
59typedef enum
60{
61 zft_idle = 0,
62 zft_reading,
63 zft_writing,
64} zft_status_enum;
65
66typedef struct /* all values measured in bytes */
67{
68 int seg_pos; /* segment currently positioned at */
69 int seg_byte_pos; /* offset in current segment */
70 __s64 tape_pos; /* real offset from BOT */
71 __s64 volume_pos; /* pos. in uncompressed data stream in
72 * current volume
73 */
74} zft_position;
75
76extern zft_position zft_pos;
77extern __u8 *zft_deblock_buf;
78extern __u8 *zft_hseg_buf;
79extern int zft_deblock_segment;
80extern zft_status_enum zft_io_state;
81extern int zft_header_changed;
82extern int zft_qic113; /* conform to old specs. and old zftape */
83extern int zft_use_compression;
84extern unsigned int zft_blk_sz;
85extern __s64 zft_capacity;
86extern unsigned int zft_written_segments;
87extern int zft_label_changed;
88
89/* zftape-rw.c exported functions
90 */
91extern unsigned int zft_get_seg_sz(unsigned int segment);
92extern void zft_set_flags(unsigned int minor_unit);
93extern int zft_calc_seg_byte_coord(int *seg_byte_pos, __s64 tape_pos);
94extern __s64 zft_calc_tape_pos(int segment);
95extern __s64 zft_get_capacity(void);
96extern void zft_update_label(__u8 *buffer);
97extern int zft_erase(void);
98extern int zft_verify_write_segments(unsigned int segment,
99 __u8 *data, size_t size, __u8 *buffer);
100extern unsigned int zft_get_time(void);
101#endif /* _ZFTAPE_RW_H */
102
diff --git a/drivers/char/ftape/zftape/zftape-vtbl.c b/drivers/char/ftape/zftape/zftape-vtbl.c
deleted file mode 100644
index ad7f8be6340b..000000000000
--- a/drivers/char/ftape/zftape/zftape-vtbl.c
+++ /dev/null
@@ -1,757 +0,0 @@
1/*
2 * Copyright (c) 1995-1997 Claus-Justus Heine
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2, or (at
7 your option) any later version.
8
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
17 USA.
18
19 *
20 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-vtbl.c,v $
21 * $Revision: 1.7.6.1 $
22 * $Date: 1997/11/24 13:48:31 $
23 *
24 * This file defines a volume table as defined in various QIC
25 * standards.
26 *
27 * This is a minimal implementation, just allowing ordinary DOS
28 * :( prgrams to identify the cartridge as used.
29 */
30
31#include <linux/errno.h>
32#include <linux/mm.h>
33#include <linux/slab.h>
34
35#include <linux/zftape.h>
36#include "../zftape/zftape-init.h"
37#include "../zftape/zftape-eof.h"
38#include "../zftape/zftape-ctl.h"
39#include "../zftape/zftape-write.h"
40#include "../zftape/zftape-read.h"
41#include "../zftape/zftape-rw.h"
42#include "../zftape/zftape-vtbl.h"
43
44#define ZFT_CMAP_HACK /* leave this defined to hide the compression map */
45
46/*
47 * global variables
48 */
49int zft_qic_mode = 1; /* use the vtbl */
50int zft_old_ftape; /* prevents old ftaped tapes to be overwritten */
51int zft_volume_table_changed; /* for write_header_segments() */
52
53/*
54 * private variables (only exported for inline functions)
55 */
56LIST_HEAD(zft_vtbl);
57
58/* We could also allocate these dynamically when extracting the volume table
59 * sizeof(zft_volinfo) is about 32 or something close to that
60 */
61static zft_volinfo tape_vtbl;
62static zft_volinfo eot_vtbl;
63static zft_volinfo *cur_vtbl;
64
65static inline void zft_new_vtbl_entry(void)
66{
67 struct list_head *tmp = &zft_last_vtbl->node;
68 zft_volinfo *new = zft_kmalloc(sizeof(zft_volinfo));
69
70 list_add(&new->node, tmp);
71 new->count = zft_eom_vtbl->count ++;
72}
73
74void zft_free_vtbl(void)
75{
76 for (;;) {
77 struct list_head *tmp = zft_vtbl.prev;
78 zft_volinfo *vtbl;
79
80 if (tmp == &zft_vtbl)
81 break;
82 list_del(tmp);
83 vtbl = list_entry(tmp, zft_volinfo, node);
84 zft_kfree(vtbl, sizeof(zft_volinfo));
85 }
86 INIT_LIST_HEAD(&zft_vtbl);
87 cur_vtbl = NULL;
88}
89
90/* initialize vtbl, called by ftape_new_cartridge()
91 */
92void zft_init_vtbl(void)
93{
94 zft_volinfo *new;
95
96 zft_free_vtbl();
97
98 /* Create the two dummy vtbl entries
99 */
100 new = zft_kmalloc(sizeof(zft_volinfo));
101 list_add(&new->node, &zft_vtbl);
102 new = zft_kmalloc(sizeof(zft_volinfo));
103 list_add(&new->node, &zft_vtbl);
104 zft_head_vtbl->end_seg = ft_first_data_segment;
105 zft_head_vtbl->blk_sz = zft_blk_sz;
106 zft_head_vtbl->count = -1;
107 zft_eom_vtbl->start_seg = ft_first_data_segment + 1;
108 zft_eom_vtbl->end_seg = ft_last_data_segment + 1;
109 zft_eom_vtbl->blk_sz = zft_blk_sz;
110 zft_eom_vtbl->count = 0;
111
112 /* Reset the pointer for zft_find_volume()
113 */
114 cur_vtbl = zft_eom_vtbl;
115
116 /* initialize the dummy vtbl entries for zft_qic_mode == 0
117 */
118 eot_vtbl.start_seg = ft_last_data_segment + 1;
119 eot_vtbl.end_seg = ft_last_data_segment + 1;
120 eot_vtbl.blk_sz = zft_blk_sz;
121 eot_vtbl.count = -1;
122 tape_vtbl.start_seg = ft_first_data_segment;
123 tape_vtbl.end_seg = ft_last_data_segment;
124 tape_vtbl.blk_sz = zft_blk_sz;
125 tape_vtbl.size = zft_capacity;
126 tape_vtbl.count = 0;
127}
128
129/* check for a valid VTBL signature.
130 */
131static int vtbl_signature_valid(__u8 signature[4])
132{
133 const char *vtbl_ids[] = VTBL_IDS; /* valid signatures */
134 int j;
135
136 for (j = 0;
137 (j < NR_ITEMS(vtbl_ids)) && (memcmp(signature, vtbl_ids[j], 4) != 0);
138 j++);
139 return j < NR_ITEMS(vtbl_ids);
140}
141
142/* We used to store the block-size of the volume in the volume-label,
143 * using the keyword "blocksize". The blocksize written to the
144 * volume-label is in bytes.
145 *
146 * We use this now only for compatibility with old zftape version. We
147 * store the blocksize directly as binary number in the vendor
148 * extension part of the volume entry.
149 */
150static int check_volume_label(const char *label, int *blk_sz)
151{
152 int valid_format;
153 char *blocksize;
154 TRACE_FUN(ft_t_flow);
155
156 TRACE(ft_t_noise, "called with \"%s\" / \"%s\"", label, ZFT_VOL_NAME);
157 if (strncmp(label, ZFT_VOL_NAME, strlen(ZFT_VOL_NAME)) != 0) {
158 *blk_sz = 1; /* smallest block size that we allow */
159 valid_format = 0;
160 } else {
161 TRACE(ft_t_noise, "got old style zftape vtbl entry");
162 /* get the default blocksize */
163 /* use the kernel strstr() */
164 blocksize= strstr(label, " blocksize ");
165 if (blocksize) {
166 blocksize += strlen(" blocksize ");
167 for(*blk_sz= 0;
168 *blocksize >= '0' && *blocksize <= '9';
169 blocksize++) {
170 *blk_sz *= 10;
171 *blk_sz += *blocksize - '0';
172 }
173 if (*blk_sz > ZFT_MAX_BLK_SZ) {
174 *blk_sz= 1;
175 valid_format= 0;
176 } else {
177 valid_format = 1;
178 }
179 } else {
180 *blk_sz= 1;
181 valid_format= 0;
182 }
183 }
184 TRACE_EXIT valid_format;
185}
186
187/* check for a zftape volume
188 */
189static int check_volume(__u8 *entry, zft_volinfo *volume)
190{
191 TRACE_FUN(ft_t_flow);
192
193 if(strncmp(&entry[VTBL_EXT+EXT_ZFTAPE_SIG], ZFTAPE_SIG,
194 strlen(ZFTAPE_SIG)) == 0) {
195 TRACE(ft_t_noise, "got new style zftape vtbl entry");
196 volume->blk_sz = GET2(entry, VTBL_EXT+EXT_ZFTAPE_BLKSZ);
197 volume->qic113 = entry[VTBL_EXT+EXT_ZFTAPE_QIC113];
198 TRACE_EXIT 1;
199 } else {
200 TRACE_EXIT check_volume_label(&entry[VTBL_DESC], &volume->blk_sz);
201 }
202}
203
204
205/* create zftape specific vtbl entry, the volume bounds are inserted
206 * in the calling function, zft_create_volume_headers()
207 */
208static void create_zft_volume(__u8 *entry, zft_volinfo *vtbl)
209{
210 TRACE_FUN(ft_t_flow);
211
212 memset(entry, 0, VTBL_SIZE);
213 memcpy(&entry[VTBL_SIG], VTBL_ID, 4);
214 sprintf(&entry[VTBL_DESC], ZFT_VOL_NAME" %03d", vtbl->count);
215 entry[VTBL_FLAGS] = (VTBL_FL_NOT_VERIFIED | VTBL_FL_SEG_SPANNING);
216 entry[VTBL_M_NO] = 1; /* multi_cartridge_count */
217 strcpy(&entry[VTBL_EXT+EXT_ZFTAPE_SIG], ZFTAPE_SIG);
218 PUT2(entry, VTBL_EXT+EXT_ZFTAPE_BLKSZ, vtbl->blk_sz);
219 if (zft_qic113) {
220 PUT8(entry, VTBL_DATA_SIZE, vtbl->size);
221 entry[VTBL_CMPR] = VTBL_CMPR_UNREG;
222 if (vtbl->use_compression) { /* use compression: */
223 entry[VTBL_CMPR] |= VTBL_CMPR_USED;
224 }
225 entry[VTBL_EXT+EXT_ZFTAPE_QIC113] = 1;
226 } else {
227 PUT4(entry, VTBL_DATA_SIZE, vtbl->size);
228 entry[VTBL_K_CMPR] = VTBL_CMPR_UNREG;
229 if (vtbl->use_compression) { /* use compression: */
230 entry[VTBL_K_CMPR] |= VTBL_CMPR_USED;
231 }
232 }
233 if (ft_format_code == fmt_big) {
234 /* SCSI like vtbl, store the number of used
235 * segments as 4 byte value
236 */
237 PUT4(entry, VTBL_SCSI_SEGS, vtbl->end_seg-vtbl->start_seg + 1);
238 } else {
239 /* normal, QIC-80MC like vtbl
240 */
241 PUT2(entry, VTBL_START, vtbl->start_seg);
242 PUT2(entry, VTBL_END, vtbl->end_seg);
243 }
244 TRACE_EXIT;
245}
246
247/* this one creates the volume headers for each volume. It is assumed
248 * that buffer already contains the old volume-table, so that vtbl
249 * entries without the zft_volume flag set can savely be ignored.
250 */
251static void zft_create_volume_headers(__u8 *buffer)
252{
253 __u8 *entry;
254 struct list_head *tmp;
255 zft_volinfo *vtbl;
256 TRACE_FUN(ft_t_flow);
257
258#ifdef ZFT_CMAP_HACK
259 if((strncmp(&buffer[VTBL_EXT+EXT_ZFTAPE_SIG], ZFTAPE_SIG,
260 strlen(ZFTAPE_SIG)) == 0) &&
261 buffer[VTBL_EXT+EXT_ZFTAPE_CMAP] != 0) {
262 TRACE(ft_t_noise, "deleting cmap volume");
263 memmove(buffer, buffer + VTBL_SIZE,
264 FT_SEGMENT_SIZE - VTBL_SIZE);
265 }
266#endif
267 entry = buffer;
268 for (tmp = zft_head_vtbl->node.next;
269 tmp != &zft_eom_vtbl->node;
270 tmp = tmp->next) {
271 vtbl = list_entry(tmp, zft_volinfo, node);
272 /* we now fill in the values only for newly created volumes.
273 */
274 if (vtbl->new_volume) {
275 create_zft_volume(entry, vtbl);
276 vtbl->new_volume = 0; /* clear the flag */
277 }
278
279 DUMP_VOLINFO(ft_t_noise, &entry[VTBL_DESC], vtbl);
280 entry += VTBL_SIZE;
281 }
282 memset(entry, 0, FT_SEGMENT_SIZE - zft_eom_vtbl->count * VTBL_SIZE);
283 TRACE_EXIT;
284}
285
286/* write volume table to tape. Calls zft_create_volume_headers()
287 */
288int zft_update_volume_table(unsigned int segment)
289{
290 int result = 0;
291 __u8 *verify_buf = NULL;
292 TRACE_FUN(ft_t_flow);
293
294 TRACE_CATCH(result = ftape_read_segment(ft_first_data_segment,
295 zft_deblock_buf,
296 FT_RD_SINGLE),);
297 zft_create_volume_headers(zft_deblock_buf);
298 TRACE(ft_t_noise, "writing volume table segment %d", segment);
299 if (zft_vmalloc_once(&verify_buf, FT_SEGMENT_SIZE) == 0) {
300 TRACE_CATCH(zft_verify_write_segments(segment,
301 zft_deblock_buf, result,
302 verify_buf),
303 zft_vfree(&verify_buf, FT_SEGMENT_SIZE));
304 zft_vfree(&verify_buf, FT_SEGMENT_SIZE);
305 } else {
306 TRACE_CATCH(ftape_write_segment(segment, zft_deblock_buf,
307 FT_WR_SINGLE),);
308 }
309 TRACE_EXIT 0;
310}
311
312/* non zftape volumes are handled in raw mode. Thus we need to
313 * calculate the raw amount of data contained in those segments.
314 */
315static void extract_alien_volume(__u8 *entry, zft_volinfo *vtbl)
316{
317 TRACE_FUN(ft_t_flow);
318
319 vtbl->size = (zft_calc_tape_pos(zft_last_vtbl->end_seg+1) -
320 zft_calc_tape_pos(zft_last_vtbl->start_seg));
321 vtbl->use_compression = 0;
322 vtbl->qic113 = zft_qic113;
323 if (vtbl->qic113) {
324 TRACE(ft_t_noise,
325 "Fake alien volume's size from " LL_X " to " LL_X,
326 LL(GET8(entry, VTBL_DATA_SIZE)), LL(vtbl->size));
327 } else {
328 TRACE(ft_t_noise,
329 "Fake alien volume's size from %d to " LL_X,
330 (int)GET4(entry, VTBL_DATA_SIZE), LL(vtbl->size));
331 }
332 TRACE_EXIT;
333}
334
335
336/* extract an zftape specific volume
337 */
338static void extract_zft_volume(__u8 *entry, zft_volinfo *vtbl)
339{
340 TRACE_FUN(ft_t_flow);
341
342 if (vtbl->qic113) {
343 vtbl->size = GET8(entry, VTBL_DATA_SIZE);
344 vtbl->use_compression =
345 (entry[VTBL_CMPR] & VTBL_CMPR_USED) != 0;
346 } else {
347 vtbl->size = GET4(entry, VTBL_DATA_SIZE);
348 if (entry[VTBL_K_CMPR] & VTBL_CMPR_UNREG) {
349 vtbl->use_compression =
350 (entry[VTBL_K_CMPR] & VTBL_CMPR_USED) != 0;
351 } else if (entry[VTBL_CMPR] & VTBL_CMPR_UNREG) {
352 vtbl->use_compression =
353 (entry[VTBL_CMPR] & VTBL_CMPR_USED) != 0;
354 } else {
355 TRACE(ft_t_warn, "Geeh! There is something wrong:\n"
356 KERN_INFO "QIC compression (Rev = K): %x\n"
357 KERN_INFO "QIC compression (Rev > K): %x",
358 entry[VTBL_K_CMPR], entry[VTBL_CMPR]);
359 }
360 }
361 TRACE_EXIT;
362}
363
364/* extract the volume table from buffer. "buffer" must already contain
365 * the vtbl-segment
366 */
367int zft_extract_volume_headers(__u8 *buffer)
368{
369 __u8 *entry;
370 TRACE_FUN(ft_t_flow);
371
372 zft_init_vtbl();
373 entry = buffer;
374#ifdef ZFT_CMAP_HACK
375 if ((strncmp(&entry[VTBL_EXT+EXT_ZFTAPE_SIG], ZFTAPE_SIG,
376 strlen(ZFTAPE_SIG)) == 0) &&
377 entry[VTBL_EXT+EXT_ZFTAPE_CMAP] != 0) {
378 TRACE(ft_t_noise, "ignoring cmap volume");
379 entry += VTBL_SIZE;
380 }
381#endif
382 /* the end of the vtbl is indicated by an invalid signature
383 */
384 while (vtbl_signature_valid(&entry[VTBL_SIG]) &&
385 (entry - buffer) < FT_SEGMENT_SIZE) {
386 zft_new_vtbl_entry();
387 if (ft_format_code == fmt_big) {
388 /* SCSI like vtbl, stores only the number of
389 * segments used
390 */
391 unsigned int num_segments= GET4(entry, VTBL_SCSI_SEGS);
392 zft_last_vtbl->start_seg = zft_eom_vtbl->start_seg;
393 zft_last_vtbl->end_seg =
394 zft_last_vtbl->start_seg + num_segments - 1;
395 } else {
396 /* `normal', QIC-80 like vtbl
397 */
398 zft_last_vtbl->start_seg = GET2(entry, VTBL_START);
399 zft_last_vtbl->end_seg = GET2(entry, VTBL_END);
400 }
401 zft_eom_vtbl->start_seg = zft_last_vtbl->end_seg + 1;
402 /* check if we created this volume and get the
403 * blk_sz
404 */
405 zft_last_vtbl->zft_volume = check_volume(entry, zft_last_vtbl);
406 if (zft_last_vtbl->zft_volume == 0) {
407 extract_alien_volume(entry, zft_last_vtbl);
408 } else {
409 extract_zft_volume(entry, zft_last_vtbl);
410 }
411 DUMP_VOLINFO(ft_t_noise, &entry[VTBL_DESC], zft_last_vtbl);
412 entry +=VTBL_SIZE;
413 }
414#if 0
415/*
416 * undefine to test end of tape handling
417 */
418 zft_new_vtbl_entry();
419 zft_last_vtbl->start_seg = zft_eom_vtbl->start_seg;
420 zft_last_vtbl->end_seg = ft_last_data_segment - 10;
421 zft_last_vtbl->blk_sz = zft_blk_sz;
422 zft_last_vtbl->zft_volume = 1;
423 zft_last_vtbl->qic113 = zft_qic113;
424 zft_last_vtbl->size = (zft_calc_tape_pos(zft_last_vtbl->end_seg+1)
425 - zft_calc_tape_pos(zft_last_vtbl->start_seg));
426#endif
427 TRACE_EXIT 0;
428}
429
430/* this functions translates the failed_sector_log, misused as
431 * EOF-marker list, into a virtual volume table. The table mustn't be
432 * written to tape, because this would occupy the first data segment,
433 * which should be the volume table, but is actually the first segment
434 * that is filled with data (when using standard ftape). We assume,
435 * that we get a non-empty failed_sector_log.
436 */
437int zft_fake_volume_headers (eof_mark_union *eof_map, int num_failed_sectors)
438{
439 unsigned int segment, sector;
440 int have_eom = 0;
441 int vol_no;
442 TRACE_FUN(ft_t_flow);
443
444 if ((num_failed_sectors >= 2) &&
445 (GET2(&eof_map[num_failed_sectors - 1].mark.segment, 0)
446 ==
447 GET2(&eof_map[num_failed_sectors - 2].mark.segment, 0) + 1) &&
448 (GET2(&eof_map[num_failed_sectors - 1].mark.date, 0) == 1)) {
449 /* this should be eom. We keep the remainder of the
450 * tape as another volume.
451 */
452 have_eom = 1;
453 }
454 zft_init_vtbl();
455 zft_eom_vtbl->start_seg = ft_first_data_segment;
456 for(vol_no = 0; vol_no < num_failed_sectors - have_eom; vol_no ++) {
457 zft_new_vtbl_entry();
458
459 segment = GET2(&eof_map[vol_no].mark.segment, 0);
460 sector = GET2(&eof_map[vol_no].mark.date, 0);
461
462 zft_last_vtbl->start_seg = zft_eom_vtbl->start_seg;
463 zft_last_vtbl->end_seg = segment;
464 zft_eom_vtbl->start_seg = segment + 1;
465 zft_last_vtbl->blk_sz = 1;
466 zft_last_vtbl->size =
467 (zft_calc_tape_pos(zft_last_vtbl->end_seg)
468 - zft_calc_tape_pos(zft_last_vtbl->start_seg)
469 + (sector-1) * FT_SECTOR_SIZE);
470 TRACE(ft_t_noise,
471 "failed sector log: segment: %d, sector: %d",
472 segment, sector);
473 DUMP_VOLINFO(ft_t_noise, "Faked volume", zft_last_vtbl);
474 }
475 if (!have_eom) {
476 zft_new_vtbl_entry();
477 zft_last_vtbl->start_seg = zft_eom_vtbl->start_seg;
478 zft_last_vtbl->end_seg = ft_last_data_segment;
479 zft_eom_vtbl->start_seg = ft_last_data_segment + 1;
480 zft_last_vtbl->size = zft_capacity;
481 zft_last_vtbl->size -= zft_calc_tape_pos(zft_last_vtbl->start_seg);
482 zft_last_vtbl->blk_sz = 1;
483 DUMP_VOLINFO(ft_t_noise, "Faked volume",zft_last_vtbl);
484 }
485 TRACE_EXIT 0;
486}
487
488/* update the internal volume table
489 *
490 * if before start of last volume: erase all following volumes if
491 * inside a volume: set end of volume to infinity
492 *
493 * this function is intended to be called every time _ftape_write() is
494 * called
495 *
496 * return: 0 if no new volume was created, 1 if a new volume was
497 * created
498 *
499 * NOTE: we don't need to check for zft_mode as ftape_write() does
500 * that already. This function gets never called without accessing
501 * zftape via the *qft* devices
502 */
503
504int zft_open_volume(zft_position *pos, int blk_sz, int use_compression)
505{
506 TRACE_FUN(ft_t_flow);
507
508 if (!zft_qic_mode) {
509 TRACE_EXIT 0;
510 }
511 if (zft_tape_at_lbot(pos)) {
512 zft_init_vtbl();
513 if(zft_old_ftape) {
514 /* clear old ftape's eof marks */
515 zft_clear_ftape_file_marks();
516 zft_old_ftape = 0; /* no longer old ftape */
517 }
518 zft_reset_position(pos);
519 }
520 if (pos->seg_pos != zft_last_vtbl->end_seg + 1) {
521 TRACE_ABORT(-EIO, ft_t_bug,
522 "BUG: seg_pos: %d, zft_last_vtbl->end_seg: %d",
523 pos->seg_pos, zft_last_vtbl->end_seg);
524 }
525 TRACE(ft_t_noise, "create new volume");
526 if (zft_eom_vtbl->count >= ZFT_MAX_VOLUMES) {
527 TRACE_ABORT(-ENOSPC, ft_t_err,
528 "Error: maxmimal number of volumes exhausted "
529 "(maxmimum is %d)", ZFT_MAX_VOLUMES);
530 }
531 zft_new_vtbl_entry();
532 pos->volume_pos = pos->seg_byte_pos = 0;
533 zft_last_vtbl->start_seg = pos->seg_pos;
534 zft_last_vtbl->end_seg = ft_last_data_segment; /* infinity */
535 zft_last_vtbl->blk_sz = blk_sz;
536 zft_last_vtbl->size = zft_capacity;
537 zft_last_vtbl->zft_volume = 1;
538 zft_last_vtbl->use_compression = use_compression;
539 zft_last_vtbl->qic113 = zft_qic113;
540 zft_last_vtbl->new_volume = 1;
541 zft_last_vtbl->open = 1;
542 zft_volume_table_changed = 1;
543 zft_eom_vtbl->start_seg = ft_last_data_segment + 1;
544 TRACE_EXIT 0;
545}
546
547/* perform mtfsf, mtbsf, not allowed without zft_qic_mode
548 */
549int zft_skip_volumes(int count, zft_position *pos)
550{
551 const zft_volinfo *vtbl;
552 TRACE_FUN(ft_t_flow);
553
554 TRACE(ft_t_noise, "count: %d", count);
555
556 vtbl= zft_find_volume(pos->seg_pos);
557 while (count > 0 && vtbl != zft_eom_vtbl) {
558 vtbl = list_entry(vtbl->node.next, zft_volinfo, node);
559 count --;
560 }
561 while (count < 0 && vtbl != zft_first_vtbl) {
562 vtbl = list_entry(vtbl->node.prev, zft_volinfo, node);
563 count ++;
564 }
565 pos->seg_pos = vtbl->start_seg;
566 pos->seg_byte_pos = 0;
567 pos->volume_pos = 0;
568 pos->tape_pos = zft_calc_tape_pos(pos->seg_pos);
569 zft_just_before_eof = vtbl->size == 0;
570 if (zft_cmpr_ops) {
571 (*zft_cmpr_ops->reset)();
572 }
573 zft_deblock_segment = -1; /* no need to keep cache */
574 TRACE(ft_t_noise, "repositioning to:\n"
575 KERN_INFO "zft_seg_pos : %d\n"
576 KERN_INFO "zft_seg_byte_pos : %d\n"
577 KERN_INFO "zft_tape_pos : " LL_X "\n"
578 KERN_INFO "zft_volume_pos : " LL_X "\n"
579 KERN_INFO "file number : %d",
580 pos->seg_pos, pos->seg_byte_pos,
581 LL(pos->tape_pos), LL(pos->volume_pos), vtbl->count);
582 zft_resid = count < 0 ? -count : count;
583 TRACE_EXIT zft_resid ? -EINVAL : 0;
584}
585
586/* the following simply returns the raw data position of the EOM
587 * marker, MTIOCSIZE ioctl
588 */
589__s64 zft_get_eom_pos(void)
590{
591 if (zft_qic_mode) {
592 return zft_calc_tape_pos(zft_eom_vtbl->start_seg);
593 } else {
594 /* there is only one volume in raw mode */
595 return zft_capacity;
596 }
597}
598
599/* skip to eom, used for MTEOM
600 */
601void zft_skip_to_eom(zft_position *pos)
602{
603 TRACE_FUN(ft_t_flow);
604 pos->seg_pos = zft_eom_vtbl->start_seg;
605 pos->seg_byte_pos =
606 pos->volume_pos =
607 zft_just_before_eof = 0;
608 pos->tape_pos = zft_calc_tape_pos(pos->seg_pos);
609 TRACE(ft_t_noise, "ftape positioned to segment %d, data pos " LL_X,
610 pos->seg_pos, LL(pos->tape_pos));
611 TRACE_EXIT;
612}
613
614/* write an EOF-marker by setting zft_last_vtbl->end_seg to seg_pos.
615 * NOTE: this function assumes that zft_last_vtbl points to a valid
616 * vtbl entry
617 *
618 * NOTE: this routine always positions before the EOF marker
619 */
620int zft_close_volume(zft_position *pos)
621{
622 TRACE_FUN(ft_t_any);
623
624 if (zft_vtbl_empty || !zft_last_vtbl->open) { /* should not happen */
625 TRACE(ft_t_noise, "There are no volumes to finish");
626 TRACE_EXIT -EIO;
627 }
628 if (pos->seg_byte_pos == 0 &&
629 pos->seg_pos != zft_last_vtbl->start_seg) {
630 pos->seg_pos --;
631 pos->seg_byte_pos = zft_get_seg_sz(pos->seg_pos);
632 }
633 zft_last_vtbl->end_seg = pos->seg_pos;
634 zft_last_vtbl->size = pos->volume_pos;
635 zft_volume_table_changed = 1;
636 zft_just_before_eof = 1;
637 zft_eom_vtbl->start_seg = zft_last_vtbl->end_seg + 1;
638 zft_last_vtbl->open = 0; /* closed */
639 TRACE_EXIT 0;
640}
641
642/* write count file-marks at current position.
643 *
644 * The tape is positioned after the eof-marker, that is at byte 0 of
645 * the segment following the eof-marker
646 *
647 * this function is only allowed in zft_qic_mode
648 *
649 * Only allowed when tape is at BOT or EOD.
650 */
651int zft_weof(unsigned int count, zft_position *pos)
652{
653
654 TRACE_FUN(ft_t_flow);
655
656 if (!count) { /* write zero EOF marks should be a real no-op */
657 TRACE_EXIT 0;
658 }
659 zft_volume_table_changed = 1;
660 if (zft_tape_at_lbot(pos)) {
661 zft_init_vtbl();
662 if(zft_old_ftape) {
663 /* clear old ftape's eof marks */
664 zft_clear_ftape_file_marks();
665 zft_old_ftape = 0; /* no longer old ftape */
666 }
667 }
668 if (zft_last_vtbl->open) {
669 zft_close_volume(pos);
670 zft_move_past_eof(pos);
671 count --;
672 }
673 /* now it's easy, just append eof-marks, that is empty
674 * volumes, to the end of the already recorded media.
675 */
676 while (count > 0 &&
677 pos->seg_pos <= ft_last_data_segment &&
678 zft_eom_vtbl->count < ZFT_MAX_VOLUMES) {
679 TRACE(ft_t_noise,
680 "Writing zero sized file at segment %d", pos->seg_pos);
681 zft_new_vtbl_entry();
682 zft_last_vtbl->start_seg = pos->seg_pos;
683 zft_last_vtbl->end_seg = pos->seg_pos;
684 zft_last_vtbl->size = 0;
685 zft_last_vtbl->blk_sz = zft_blk_sz;
686 zft_last_vtbl->zft_volume = 1;
687 zft_last_vtbl->use_compression = 0;
688 pos->tape_pos += zft_get_seg_sz(pos->seg_pos);
689 zft_eom_vtbl->start_seg = ++ pos->seg_pos;
690 count --;
691 }
692 if (count > 0) {
693 /* there are two possibilities: end of tape, or the
694 * maximum number of files is exhausted.
695 */
696 zft_resid = count;
697 TRACE(ft_t_noise,"Number of marks NOT written: %d", zft_resid);
698 if (zft_eom_vtbl->count == ZFT_MAX_VOLUMES) {
699 TRACE_ABORT(-EINVAL, ft_t_warn,
700 "maximum allowed number of files "
701 "exhausted: %d", ZFT_MAX_VOLUMES);
702 } else {
703 TRACE_ABORT(-ENOSPC,
704 ft_t_noise, "reached end of tape");
705 }
706 }
707 TRACE_EXIT 0;
708}
709
710const zft_volinfo *zft_find_volume(unsigned int seg_pos)
711{
712 TRACE_FUN(ft_t_flow);
713
714 TRACE(ft_t_any, "called with seg_pos %d",seg_pos);
715 if (!zft_qic_mode) {
716 if (seg_pos > ft_last_data_segment) {
717 TRACE_EXIT &eot_vtbl;
718 }
719 tape_vtbl.blk_sz = zft_blk_sz;
720 TRACE_EXIT &tape_vtbl;
721 }
722 if (seg_pos < zft_first_vtbl->start_seg) {
723 TRACE_EXIT (cur_vtbl = zft_first_vtbl);
724 }
725 while (seg_pos > cur_vtbl->end_seg) {
726 cur_vtbl = list_entry(cur_vtbl->node.next, zft_volinfo, node);
727 TRACE(ft_t_noise, "%d - %d", cur_vtbl->start_seg, cur_vtbl->end_seg);
728 }
729 while (seg_pos < cur_vtbl->start_seg) {
730 cur_vtbl = list_entry(cur_vtbl->node.prev, zft_volinfo, node);
731 TRACE(ft_t_noise, "%d - %d", cur_vtbl->start_seg, cur_vtbl->end_seg);
732 }
733 if (seg_pos > cur_vtbl->end_seg || seg_pos < cur_vtbl->start_seg) {
734 TRACE(ft_t_bug, "This cannot happen");
735 }
736 DUMP_VOLINFO(ft_t_noise, "", cur_vtbl);
737 TRACE_EXIT cur_vtbl;
738}
739
740/* this function really assumes that we are just before eof
741 */
742void zft_move_past_eof(zft_position *pos)
743{
744 TRACE_FUN(ft_t_flow);
745
746 TRACE(ft_t_noise, "old seg. pos: %d", pos->seg_pos);
747 pos->tape_pos += zft_get_seg_sz(pos->seg_pos++) - pos->seg_byte_pos;
748 pos->seg_byte_pos = 0;
749 pos->volume_pos = 0;
750 if (zft_cmpr_ops) {
751 (*zft_cmpr_ops->reset)();
752 }
753 zft_just_before_eof = 0;
754 zft_deblock_segment = -1; /* no need to cache it anymore */
755 TRACE(ft_t_noise, "new seg. pos: %d", pos->seg_pos);
756 TRACE_EXIT;
757}
diff --git a/drivers/char/ftape/zftape/zftape-vtbl.h b/drivers/char/ftape/zftape/zftape-vtbl.h
deleted file mode 100644
index f31d196d1759..000000000000
--- a/drivers/char/ftape/zftape/zftape-vtbl.h
+++ /dev/null
@@ -1,227 +0,0 @@
1#ifndef _ZFTAPE_VTBL_H
2#define _ZFTAPE_VTBL_H
3
4/*
5 * Copyright (c) 1995-1997 Claus-Justus Heine
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
11
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
20 USA.
21
22 *
23 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-vtbl.h,v $
24 * $Revision: 1.3 $
25 * $Date: 1997/10/28 14:30:09 $
26 *
27 * This file defines a volume table as defined in the QIC-80
28 * development standards.
29 */
30
31#include <linux/list.h>
32
33#include "../lowlevel/ftape-tracing.h"
34
35#include "../zftape/zftape-eof.h"
36#include "../zftape/zftape-ctl.h"
37#include "../zftape/zftape-rw.h"
38
39#define VTBL_SIZE 128 /* bytes */
40
41/* The following are offsets in the vtbl. */
42#define VTBL_SIG 0
43#define VTBL_START 4
44#define VTBL_END 6
45#define VTBL_DESC 8
46#define VTBL_DATE 52
47#define VTBL_FLAGS 56
48#define VTBL_FL_VENDOR_SPECIFIC (1<<0)
49#define VTBL_FL_MUTLI_CARTRIDGE (1<<1)
50#define VTBL_FL_NOT_VERIFIED (1<<2)
51#define VTBL_FL_REDIR_INHIBIT (1<<3)
52#define VTBL_FL_SEG_SPANNING (1<<4)
53#define VTBL_FL_DIRECTORY_LAST (1<<5)
54#define VTBL_FL_RESERVED_6 (1<<6)
55#define VTBL_FL_RESERVED_7 (1<<7)
56#define VTBL_M_NO 57
57#define VTBL_EXT 58
58#define EXT_ZFTAPE_SIG 0
59#define EXT_ZFTAPE_BLKSZ 10
60#define EXT_ZFTAPE_CMAP 12
61#define EXT_ZFTAPE_QIC113 13
62#define VTBL_PWD 84
63#define VTBL_DIR_SIZE 92
64#define VTBL_DATA_SIZE 96
65#define VTBL_OS_VERSION 104
66#define VTBL_SRC_DRIVE 106
67#define VTBL_DEV 122
68#define VTBL_RESERVED_1 123
69#define VTBL_CMPR 124
70#define VTBL_CMPR_UNREG 0x3f
71#define VTBL_CMPR_USED 0x80
72#define VTBL_FMT 125
73#define VTBL_RESERVED_2 126
74#define VTBL_RESERVED_3 127
75/* compatibility with pre revision K */
76#define VTBL_K_CMPR 120
77
78/* the next is used by QIC-3020 tapes with format code 6 (>2^16
79 * segments) It is specified in QIC-113, Rev. G, Section 5 (SCSI
80 * volume table). The difference is simply, that we only store the
81 * number of segments used, not the starting segment.
82 */
83#define VTBL_SCSI_SEGS 4 /* is a 4 byte value */
84
85/* one vtbl is 128 bytes, that results in a maximum number of
86 * 29*1024/128 = 232 volumes.
87 */
88#define ZFT_MAX_VOLUMES (FT_SEGMENT_SIZE/VTBL_SIZE)
89#define VTBL_ID "VTBL"
90#define VTBL_IDS { VTBL_ID, "XTBL", "UTID", "EXVT" } /* other valid ids */
91#define ZFT_VOL_NAME "zftape volume" /* volume label used by me */
92#define ZFTAPE_SIG "LINUX ZFT"
93
94/* global variables
95 */
96typedef struct zft_internal_vtbl
97{
98 struct list_head node;
99 int count;
100 unsigned int start_seg; /* 32 bits are enough for now */
101 unsigned int end_seg; /* 32 bits are enough for now */
102 __s64 size; /* uncompressed size */
103 unsigned int blk_sz; /* block size for this volume */
104 unsigned int zft_volume :1; /* zftape created this volume */
105 unsigned int use_compression:1; /* compressed volume */
106 unsigned int qic113 :1; /* layout of compressed block
107 * info and vtbl conforms to
108 * QIC-113, Rev. G
109 */
110 unsigned int new_volume :1; /* it was created by us, this
111 * run. this allows the
112 * fields that aren't really
113 * used by zftape to be filled
114 * in by some user level
115 * program.
116 */
117 unsigned int open :1; /* just in progress of being
118 * written
119 */
120} zft_volinfo;
121
122extern struct list_head zft_vtbl;
123#define zft_head_vtbl list_entry(zft_vtbl.next, zft_volinfo, node)
124#define zft_eom_vtbl list_entry(zft_vtbl.prev, zft_volinfo, node)
125#define zft_last_vtbl list_entry(zft_eom_vtbl->node.prev, zft_volinfo, node)
126#define zft_first_vtbl list_entry(zft_head_vtbl->node.next, zft_volinfo, node)
127#define zft_vtbl_empty (zft_eom_vtbl->node.prev == &zft_head_vtbl->node)
128
129#define DUMP_VOLINFO(level, desc, info) \
130{ \
131 char tmp[21]; \
132 strlcpy(tmp, desc, sizeof(tmp)); \
133 TRACE(level, "Volume %d:\n" \
134 KERN_INFO "description : %s\n" \
135 KERN_INFO "first segment: %d\n" \
136 KERN_INFO "last segment: %d\n" \
137 KERN_INFO "size : " LL_X "\n" \
138 KERN_INFO "block size : %d\n" \
139 KERN_INFO "compression : %d\n" \
140 KERN_INFO "zftape volume: %d\n" \
141 KERN_INFO "QIC-113 conf.: %d", \
142 (info)->count, tmp, (info)->start_seg, (info)->end_seg, \
143 LL((info)->size), (info)->blk_sz, \
144 (info)->use_compression != 0, (info)->zft_volume != 0, \
145 (info)->qic113 != 0); \
146}
147
148extern int zft_qic_mode;
149extern int zft_old_ftape;
150extern int zft_volume_table_changed;
151
152/* exported functions */
153extern void zft_init_vtbl (void);
154extern void zft_free_vtbl (void);
155extern int zft_extract_volume_headers(__u8 *buffer);
156extern int zft_update_volume_table (unsigned int segment);
157extern int zft_open_volume (zft_position *pos,
158 int blk_sz, int use_compression);
159extern int zft_close_volume (zft_position *pos);
160extern const zft_volinfo *zft_find_volume(unsigned int seg_pos);
161extern int zft_skip_volumes (int count, zft_position *pos);
162extern __s64 zft_get_eom_pos (void);
163extern void zft_skip_to_eom (zft_position *pos);
164extern int zft_fake_volume_headers (eof_mark_union *eof_map,
165 int num_failed_sectors);
166extern int zft_weof (unsigned int count, zft_position *pos);
167extern void zft_move_past_eof (zft_position *pos);
168
169static inline int zft_tape_at_eod (const zft_position *pos);
170static inline int zft_tape_at_lbot (const zft_position *pos);
171static inline void zft_position_before_eof (zft_position *pos,
172 const zft_volinfo *volume);
173static inline __s64 zft_check_for_eof(const zft_volinfo *vtbl,
174 const zft_position *pos);
175
176/* this function decrements the zft_seg_pos counter if we are right
177 * at the beginning of a segment. This is to handle fsfm/bsfm -- we
178 * need to position before the eof mark. NOTE: zft_tape_pos is not
179 * changed
180 */
181static inline void zft_position_before_eof(zft_position *pos,
182 const zft_volinfo *volume)
183{
184 TRACE_FUN(ft_t_flow);
185
186 if (pos->seg_pos == volume->end_seg + 1 && pos->seg_byte_pos == 0) {
187 pos->seg_pos --;
188 pos->seg_byte_pos = zft_get_seg_sz(pos->seg_pos);
189 }
190 TRACE_EXIT;
191}
192
193/* Mmmh. Is the position at the end of the last volume, that is right
194 * before the last EOF mark also logical an EOD condition?
195 */
196static inline int zft_tape_at_eod(const zft_position *pos)
197{
198 TRACE_FUN(ft_t_any);
199
200 if (zft_qic_mode) {
201 TRACE_EXIT (pos->seg_pos >= zft_eom_vtbl->start_seg ||
202 zft_last_vtbl->open);
203 } else {
204 TRACE_EXIT pos->seg_pos > ft_last_data_segment;
205 }
206}
207
208static inline int zft_tape_at_lbot(const zft_position *pos)
209{
210 if (zft_qic_mode) {
211 return (pos->seg_pos <= zft_first_vtbl->start_seg &&
212 pos->volume_pos == 0);
213 } else {
214 return (pos->seg_pos <= ft_first_data_segment &&
215 pos->volume_pos == 0);
216 }
217}
218
219/* This one checks for EOF. return remaing space (may be negative)
220 */
221static inline __s64 zft_check_for_eof(const zft_volinfo *vtbl,
222 const zft_position *pos)
223{
224 return (__s64)(vtbl->size - pos->volume_pos);
225}
226
227#endif /* _ZFTAPE_VTBL_H */
diff --git a/drivers/char/ftape/zftape/zftape-write.c b/drivers/char/ftape/zftape/zftape-write.c
deleted file mode 100644
index 94327b8c97b9..000000000000
--- a/drivers/char/ftape/zftape/zftape-write.c
+++ /dev/null
@@ -1,483 +0,0 @@
1/*
2 * Copyright (C) 1996, 1997 Claus Heine
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 *
19 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-write.c,v $
20 * $Revision: 1.3 $
21 * $Date: 1997/11/06 00:50:29 $
22 *
23 * This file contains the writing code
24 * for the QIC-117 floppy-tape driver for Linux.
25 */
26
27#include <linux/errno.h>
28#include <linux/mm.h>
29
30#include <linux/zftape.h>
31
32#include <asm/uaccess.h>
33
34#include "../zftape/zftape-init.h"
35#include "../zftape/zftape-eof.h"
36#include "../zftape/zftape-ctl.h"
37#include "../zftape/zftape-write.h"
38#include "../zftape/zftape-read.h"
39#include "../zftape/zftape-rw.h"
40#include "../zftape/zftape-vtbl.h"
41
42/* Global vars.
43 */
44
45/* Local vars.
46 */
47static int last_write_failed;
48static int need_flush;
49
50void zft_prevent_flush(void)
51{
52 need_flush = 0;
53}
54
55static int zft_write_header_segments(__u8* buffer)
56{
57 int header_1_ok = 0;
58 int header_2_ok = 0;
59 unsigned int time_stamp;
60 TRACE_FUN(ft_t_noise);
61
62 TRACE_CATCH(ftape_abort_operation(),);
63 ftape_seek_to_bot(); /* prevents extra rewind */
64 if (GET4(buffer, 0) != FT_HSEG_MAGIC) {
65 TRACE_ABORT(-EIO, ft_t_err,
66 "wrong header signature found, aborting");
67 }
68 /* Be optimistic: */
69 PUT4(buffer, FT_SEG_CNT,
70 zft_written_segments + GET4(buffer, FT_SEG_CNT) + 2);
71 if ((time_stamp = zft_get_time()) != 0) {
72 PUT4(buffer, FT_WR_DATE, time_stamp);
73 if (zft_label_changed) {
74 PUT4(buffer, FT_LABEL_DATE, time_stamp);
75 }
76 }
77 TRACE(ft_t_noise,
78 "writing first header segment %d", ft_header_segment_1);
79 header_1_ok = zft_verify_write_segments(ft_header_segment_1,
80 buffer, FT_SEGMENT_SIZE,
81 zft_deblock_buf) >= 0;
82 TRACE(ft_t_noise,
83 "writing second header segment %d", ft_header_segment_2);
84 header_2_ok = zft_verify_write_segments(ft_header_segment_2,
85 buffer, FT_SEGMENT_SIZE,
86 zft_deblock_buf) >= 0;
87 if (!header_1_ok) {
88 TRACE(ft_t_warn, "Warning: "
89 "update of first header segment failed");
90 }
91 if (!header_2_ok) {
92 TRACE(ft_t_warn, "Warning: "
93 "update of second header segment failed");
94 }
95 if (!header_1_ok && !header_2_ok) {
96 TRACE_ABORT(-EIO, ft_t_err, "Error: "
97 "update of both header segments failed.");
98 }
99 TRACE_EXIT 0;
100}
101
102int zft_update_header_segments(void)
103{
104 TRACE_FUN(ft_t_noise);
105
106 /* must NOT use zft_write_protected, as it also includes the
107 * file access mode. But we also want to update when soft
108 * write protection is enabled (O_RDONLY)
109 */
110 if (ft_write_protected || zft_old_ftape) {
111 TRACE_ABORT(0, ft_t_noise, "Tape set read-only: no update");
112 }
113 if (!zft_header_read) {
114 TRACE_ABORT(0, ft_t_noise, "Nothing to update");
115 }
116 if (!zft_header_changed) {
117 zft_header_changed = zft_written_segments > 0;
118 }
119 if (!zft_header_changed && !zft_volume_table_changed) {
120 TRACE_ABORT(0, ft_t_noise, "Nothing to update");
121 }
122 TRACE(ft_t_noise, "Updating header segments");
123 if (ftape_get_status()->fti_state == writing) {
124 TRACE_CATCH(ftape_loop_until_writes_done(),);
125 }
126 TRACE_CATCH(ftape_abort_operation(),);
127
128 zft_deblock_segment = -1; /* invalidate the cache */
129 if (zft_header_changed) {
130 TRACE_CATCH(zft_write_header_segments(zft_hseg_buf),);
131 }
132 if (zft_volume_table_changed) {
133 TRACE_CATCH(zft_update_volume_table(ft_first_data_segment),);
134 }
135 zft_header_changed =
136 zft_volume_table_changed =
137 zft_label_changed =
138 zft_written_segments = 0;
139 TRACE_CATCH(ftape_abort_operation(),);
140 ftape_seek_to_bot();
141 TRACE_EXIT 0;
142}
143
144static int read_merge_buffer(int seg_pos, __u8 *buffer, int offset, int seg_sz)
145{
146 int result = 0;
147 const ft_trace_t old_tracing = TRACE_LEVEL;
148 TRACE_FUN(ft_t_flow);
149
150 if (zft_qic_mode) {
151 /* writing in the middle of a volume is NOT allowed
152 *
153 */
154 TRACE(ft_t_noise, "No need to read a segment");
155 memset(buffer + offset, 0, seg_sz - offset);
156 TRACE_EXIT 0;
157 }
158 TRACE(ft_t_any, "waiting");
159 ftape_start_writing(FT_WR_MULTI);
160 TRACE_CATCH(ftape_loop_until_writes_done(),);
161
162 TRACE(ft_t_noise, "trying to read segment %d from offset %d",
163 seg_pos, offset);
164 SET_TRACE_LEVEL(ft_t_bug);
165 result = zft_fetch_segment_fraction(seg_pos, buffer,
166 FT_RD_SINGLE,
167 offset, seg_sz - offset);
168 SET_TRACE_LEVEL(old_tracing);
169 if (result != (seg_sz - offset)) {
170 TRACE(ft_t_noise, "Ignore error: read_segment() result: %d",
171 result);
172 memset(buffer + offset, 0, seg_sz - offset);
173 }
174 TRACE_EXIT 0;
175}
176
177/* flush the write buffer to tape and write an eof-marker at the
178 * current position if not in raw mode. This function always
179 * positions the tape before the eof-marker. _ftape_close() should
180 * then advance to the next segment.
181 *
182 * the parameter "finish_volume" describes whether to position before
183 * or after the possibly created file-mark. We always position after
184 * the file-mark when called from ftape_close() and a flush was needed
185 * (that is ftape_write() was the last tape operation before calling
186 * ftape_flush) But we always position before the file-mark when this
187 * function get's called from outside ftape_close()
188 */
189int zft_flush_buffers(void)
190{
191 int result;
192 int data_remaining;
193 int this_segs_size;
194 TRACE_FUN(ft_t_flow);
195
196 TRACE(ft_t_data_flow,
197 "entered, ftape_state = %d", ftape_get_status()->fti_state);
198 if (ftape_get_status()->fti_state != writing && !need_flush) {
199 TRACE_ABORT(0, ft_t_noise, "no need for flush");
200 }
201 zft_io_state = zft_idle; /* triggers some initializations for the
202 * read and write routines
203 */
204 if (last_write_failed) {
205 ftape_abort_operation();
206 TRACE_EXIT -EIO;
207 }
208 TRACE(ft_t_noise, "flushing write buffers");
209 this_segs_size = zft_get_seg_sz(zft_pos.seg_pos);
210 if (this_segs_size == zft_pos.seg_byte_pos) {
211 zft_pos.seg_pos ++;
212 data_remaining = zft_pos.seg_byte_pos = 0;
213 } else {
214 data_remaining = zft_pos.seg_byte_pos;
215 }
216 /* If there is any data not written to tape yet, append zero's
217 * up to the end of the sector (if using compression) or merge
218 * it with the data existing on the tape Then write the
219 * segment(s) to tape.
220 */
221 TRACE(ft_t_noise, "Position:\n"
222 KERN_INFO "seg_pos : %d\n"
223 KERN_INFO "byte pos : %d\n"
224 KERN_INFO "remaining: %d",
225 zft_pos.seg_pos, zft_pos.seg_byte_pos, data_remaining);
226 if (data_remaining > 0) {
227 do {
228 this_segs_size = zft_get_seg_sz(zft_pos.seg_pos);
229 if (this_segs_size > data_remaining) {
230 TRACE_CATCH(read_merge_buffer(zft_pos.seg_pos,
231 zft_deblock_buf,
232 data_remaining,
233 this_segs_size),
234 last_write_failed = 1);
235 }
236 result = ftape_write_segment(zft_pos.seg_pos,
237 zft_deblock_buf,
238 FT_WR_MULTI);
239 if (result != this_segs_size) {
240 TRACE(ft_t_err, "flush buffers failed");
241 zft_pos.tape_pos -= zft_pos.seg_byte_pos;
242 zft_pos.seg_byte_pos = 0;
243
244 last_write_failed = 1;
245 TRACE_EXIT result;
246 }
247 zft_written_segments ++;
248 TRACE(ft_t_data_flow,
249 "flush, moved out buffer: %d", result);
250 /* need next segment for more data (empty segments?)
251 */
252 if (result < data_remaining) {
253 if (result > 0) {
254 /* move remainder to buffer beginning
255 */
256 memmove(zft_deblock_buf,
257 zft_deblock_buf + result,
258 FT_SEGMENT_SIZE - result);
259 }
260 }
261 data_remaining -= result;
262 zft_pos.seg_pos ++;
263 } while (data_remaining > 0);
264 TRACE(ft_t_any, "result: %d", result);
265 zft_deblock_segment = --zft_pos.seg_pos;
266 if (data_remaining == 0) { /* first byte next segment */
267 zft_pos.seg_byte_pos = this_segs_size;
268 } else { /* after data previous segment, data_remaining < 0 */
269 zft_pos.seg_byte_pos = data_remaining + result;
270 }
271 } else {
272 TRACE(ft_t_noise, "zft_deblock_buf empty");
273 zft_pos.seg_pos --;
274 zft_pos.seg_byte_pos = zft_get_seg_sz (zft_pos.seg_pos);
275 ftape_start_writing(FT_WR_MULTI);
276 }
277 TRACE(ft_t_any, "waiting");
278 if ((result = ftape_loop_until_writes_done()) < 0) {
279 /* that's really bad. What to to with zft_tape_pos?
280 */
281 TRACE(ft_t_err, "flush buffers failed");
282 }
283 TRACE(ft_t_any, "zft_seg_pos: %d, zft_seg_byte_pos: %d",
284 zft_pos.seg_pos, zft_pos.seg_byte_pos);
285 last_write_failed =
286 need_flush = 0;
287 TRACE_EXIT result;
288}
289
290/* return-value: the number of bytes removed from the user-buffer
291 *
292 * out:
293 * int *write_cnt: how much actually has been moved to the
294 * zft_deblock_buf
295 * int req_len : MUST NOT BE CHANGED, except at EOT, in
296 * which case it may be adjusted
297 * in :
298 * char *buff : the user buffer
299 * int buf_pos_write : copy of buf_len_wr int
300 * this_segs_size : the size in bytes of the actual segment
301 * char
302 * *zft_deblock_buf : zft_deblock_buf
303 */
304static int zft_simple_write(int *cnt,
305 __u8 *dst_buf, const int seg_sz,
306 const __u8 __user *src_buf, const int req_len,
307 const zft_position *pos,const zft_volinfo *volume)
308{
309 int space_left;
310 TRACE_FUN(ft_t_flow);
311
312 /* volume->size holds the tape capacity while volume is open */
313 if (pos->tape_pos + volume->blk_sz > volume->size) {
314 TRACE_EXIT -ENOSPC;
315 }
316 /* remaining space in this segment, NOT zft_deblock_buf
317 */
318 space_left = seg_sz - pos->seg_byte_pos;
319 *cnt = req_len < space_left ? req_len : space_left;
320 if (copy_from_user(dst_buf + pos->seg_byte_pos, src_buf, *cnt) != 0) {
321 TRACE_EXIT -EFAULT;
322 }
323 TRACE_EXIT *cnt;
324}
325
326static int check_write_access(int req_len,
327 const zft_volinfo **volume,
328 zft_position *pos,
329 const unsigned int blk_sz)
330{
331 int result;
332 TRACE_FUN(ft_t_flow);
333
334 if ((req_len % zft_blk_sz) != 0) {
335 TRACE_ABORT(-EINVAL, ft_t_info,
336 "write-count %d must be multiple of block-size %d",
337 req_len, blk_sz);
338 }
339 if (zft_io_state == zft_writing) {
340 /* all other error conditions have been checked earlier
341 */
342 TRACE_EXIT 0;
343 }
344 zft_io_state = zft_idle;
345 TRACE_CATCH(zft_check_write_access(pos),);
346 /* If we haven't read the header segment yet, do it now.
347 * This will verify the configuration, get the bad sector
348 * table and read the volume table segment
349 */
350 if (!zft_header_read) {
351 TRACE_CATCH(zft_read_header_segments(),);
352 }
353 /* fine. Now the tape is either at BOT or at EOD,
354 * Write start of volume now
355 */
356 TRACE_CATCH(zft_open_volume(pos, blk_sz, zft_use_compression),);
357 *volume = zft_find_volume(pos->seg_pos);
358 DUMP_VOLINFO(ft_t_noise, "", *volume);
359 zft_just_before_eof = 0;
360 /* now merge with old data if necessary */
361 if (!zft_qic_mode && pos->seg_byte_pos != 0){
362 result = zft_fetch_segment(pos->seg_pos,
363 zft_deblock_buf,
364 FT_RD_SINGLE);
365 if (result < 0) {
366 if (result == -EINTR || result == -ENOSPC) {
367 TRACE_EXIT result;
368 }
369 TRACE(ft_t_noise,
370 "ftape_read_segment() result: %d. "
371 "This might be normal when using "
372 "a newly\nformatted tape", result);
373 memset(zft_deblock_buf, '\0', pos->seg_byte_pos);
374 }
375 }
376 zft_io_state = zft_writing;
377 TRACE_EXIT 0;
378}
379
380static int fill_deblock_buf(__u8 *dst_buf, const int seg_sz,
381 zft_position *pos, const zft_volinfo *volume,
382 const char __user *usr_buf, const int req_len)
383{
384 int cnt = 0;
385 int result = 0;
386 TRACE_FUN(ft_t_flow);
387
388 if (seg_sz == 0) {
389 TRACE_ABORT(0, ft_t_data_flow, "empty segment");
390 }
391 TRACE(ft_t_data_flow, "\n"
392 KERN_INFO "remaining req_len: %d\n"
393 KERN_INFO " buf_pos: %d",
394 req_len, pos->seg_byte_pos);
395 /* zft_deblock_buf will not contain a valid segment any longer */
396 zft_deblock_segment = -1;
397 if (zft_use_compression) {
398 TRACE_CATCH(zft_cmpr_lock(1 /* try to load */),);
399 TRACE_CATCH(result= (*zft_cmpr_ops->write)(&cnt,
400 dst_buf, seg_sz,
401 usr_buf, req_len,
402 pos, volume),);
403 } else {
404 TRACE_CATCH(result= zft_simple_write(&cnt,
405 dst_buf, seg_sz,
406 usr_buf, req_len,
407 pos, volume),);
408 }
409 pos->volume_pos += result;
410 pos->seg_byte_pos += cnt;
411 pos->tape_pos += cnt;
412 TRACE(ft_t_data_flow, "\n"
413 KERN_INFO "removed from user-buffer : %d bytes.\n"
414 KERN_INFO "copied to zft_deblock_buf: %d bytes.\n"
415 KERN_INFO "zft_tape_pos : " LL_X " bytes.",
416 result, cnt, LL(pos->tape_pos));
417 TRACE_EXIT result;
418}
419
420
421/* called by the kernel-interface routine "zft_write()"
422 */
423int _zft_write(const char __user *buff, int req_len)
424{
425 int result = 0;
426 int written = 0;
427 int write_cnt;
428 int seg_sz;
429 static const zft_volinfo *volume = NULL;
430 TRACE_FUN(ft_t_flow);
431
432 zft_resid = req_len;
433 last_write_failed = 1; /* reset to 0 when successful */
434 /* check if write is allowed
435 */
436 TRACE_CATCH(check_write_access(req_len, &volume,&zft_pos,zft_blk_sz),);
437 while (req_len > 0) {
438 /* Allow us to escape from this loop with a signal !
439 */
440 FT_SIGNAL_EXIT(_DONT_BLOCK);
441 seg_sz = zft_get_seg_sz(zft_pos.seg_pos);
442 if ((write_cnt = fill_deblock_buf(zft_deblock_buf,
443 seg_sz,
444 &zft_pos,
445 volume,
446 buff,
447 req_len)) < 0) {
448 zft_resid -= written;
449 if (write_cnt == -ENOSPC) {
450 /* leave the remainder to flush_buffers()
451 */
452 TRACE(ft_t_info, "No space left on device");
453 last_write_failed = 0;
454 if (!need_flush) {
455 need_flush = written > 0;
456 }
457 TRACE_EXIT written > 0 ? written : -ENOSPC;
458 } else {
459 TRACE_EXIT result;
460 }
461 }
462 if (zft_pos.seg_byte_pos == seg_sz) {
463 TRACE_CATCH(ftape_write_segment(zft_pos.seg_pos,
464 zft_deblock_buf,
465 FT_WR_ASYNC),
466 zft_resid -= written);
467 zft_written_segments ++;
468 zft_pos.seg_byte_pos = 0;
469 zft_deblock_segment = zft_pos.seg_pos;
470 ++zft_pos.seg_pos;
471 }
472 written += write_cnt;
473 buff += write_cnt;
474 req_len -= write_cnt;
475 } /* while (req_len > 0) */
476 TRACE(ft_t_data_flow, "remaining in blocking buffer: %d",
477 zft_pos.seg_byte_pos);
478 TRACE(ft_t_data_flow, "just written bytes: %d", written);
479 last_write_failed = 0;
480 zft_resid -= written;
481 need_flush = need_flush || written > 0;
482 TRACE_EXIT written; /* bytes written */
483}
diff --git a/drivers/char/ftape/zftape/zftape-write.h b/drivers/char/ftape/zftape/zftape-write.h
deleted file mode 100644
index ea887015b493..000000000000
--- a/drivers/char/ftape/zftape/zftape-write.h
+++ /dev/null
@@ -1,38 +0,0 @@
1#ifndef _ZFTAPE_WRITE_H
2#define _ZFTAPE_WRITE_H
3
4/*
5 * Copyright (C) 1996, 1997 Claus-Justus Heine
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 *
22 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-write.h,v $
23 * $Revision: 1.2 $
24 * $Date: 1997/10/05 19:19:13 $
25 *
26 * This file contains the definitions for the write functions
27 * for the zftape driver for Linux.
28 *
29 */
30
31extern int zft_flush_buffers(void);
32extern int zft_update_header_segments(void);
33extern void zft_prevent_flush(void);
34
35/* hook for the VFS interface
36 */
37extern int _zft_write(const char __user *buff, int req_len);
38#endif /* _ZFTAPE_WRITE_H */
diff --git a/drivers/char/ftape/zftape/zftape_syms.c b/drivers/char/ftape/zftape/zftape_syms.c
deleted file mode 100644
index 2db1401682df..000000000000
--- a/drivers/char/ftape/zftape/zftape_syms.c
+++ /dev/null
@@ -1,43 +0,0 @@
1/*
2 * Copyright (C) 1997 Claus-Justus Heine
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 *
19 * $Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape_syms.c,v $
20 * $Revision: 1.3 $
21 * $Date: 1997/10/05 19:19:14 $
22 *
23 * This file contains the symbols that the zftape frontend to
24 * the ftape floppy tape driver exports
25 */
26
27#include <linux/module.h>
28
29#include <linux/zftape.h>
30
31#include "../zftape/zftape-init.h"
32#include "../zftape/zftape-read.h"
33#include "../zftape/zftape-buffers.h"
34#include "../zftape/zftape-ctl.h"
35
36/* zftape-init.c */
37EXPORT_SYMBOL(zft_cmpr_register);
38/* zftape-read.c */
39EXPORT_SYMBOL(zft_fetch_segment_fraction);
40/* zftape-buffers.c */
41EXPORT_SYMBOL(zft_vmalloc_once);
42EXPORT_SYMBOL(zft_vmalloc_always);
43EXPORT_SYMBOL(zft_vfree);
diff --git a/drivers/char/generic_serial.c b/drivers/char/generic_serial.c
index 5e59c0b42731..e769811e7417 100644
--- a/drivers/char/generic_serial.c
+++ b/drivers/char/generic_serial.c
@@ -33,8 +33,6 @@
33 33
34#define DEBUG 34#define DEBUG
35 35
36static char * tmp_buf;
37
38static int gs_debug; 36static int gs_debug;
39 37
40#ifdef DEBUG 38#ifdef DEBUG
@@ -205,7 +203,7 @@ int gs_write(struct tty_struct * tty,
205 if (!tty) return -EIO; 203 if (!tty) return -EIO;
206 204
207 port = tty->driver_data; 205 port = tty->driver_data;
208 if (!port || !port->xmit_buf || !tmp_buf) 206 if (!port || !port->xmit_buf)
209 return -EIO; 207 return -EIO;
210 208
211 local_save_flags(flags); 209 local_save_flags(flags);
@@ -720,11 +718,11 @@ static unsigned int gs_baudrates[] = {
720 718
721 719
722void gs_set_termios (struct tty_struct * tty, 720void gs_set_termios (struct tty_struct * tty,
723 struct termios * old_termios) 721 struct ktermios * old_termios)
724{ 722{
725 struct gs_port *port; 723 struct gs_port *port;
726 int baudrate, tmp, rv; 724 int baudrate, tmp, rv;
727 struct termios *tiosp; 725 struct ktermios *tiosp;
728 726
729 func_enter(); 727 func_enter();
730 728
@@ -746,11 +744,9 @@ void gs_set_termios (struct tty_struct * tty,
746 gs_dprintk (GS_DEBUG_TERMIOS, "termios structure (%p):\n", tiosp); 744 gs_dprintk (GS_DEBUG_TERMIOS, "termios structure (%p):\n", tiosp);
747 } 745 }
748 746
749#if 0
750 /* This is an optimization that is only allowed for dumb cards */ 747 /* This is an optimization that is only allowed for dumb cards */
751 /* Smart cards require knowledge of iflags and oflags too: that 748 /* Smart cards require knowledge of iflags and oflags too: that
752 might change hardware cooking mode.... */ 749 might change hardware cooking mode.... */
753#endif
754 if (old_termios) { 750 if (old_termios) {
755 if( (tiosp->c_iflag == old_termios->c_iflag) 751 if( (tiosp->c_iflag == old_termios->c_iflag)
756 && (tiosp->c_oflag == old_termios->c_oflag) 752 && (tiosp->c_oflag == old_termios->c_oflag)
@@ -774,14 +770,7 @@ void gs_set_termios (struct tty_struct * tty,
774 if(!memcmp(tiosp->c_cc, old_termios->c_cc, NCC)) printk("c_cc changed\n"); 770 if(!memcmp(tiosp->c_cc, old_termios->c_cc, NCC)) printk("c_cc changed\n");
775 } 771 }
776 772
777 baudrate = tiosp->c_cflag & CBAUD; 773 baudrate = tty_get_baud_rate(tty);
778 if (baudrate & CBAUDEX) {
779 baudrate &= ~CBAUDEX;
780 if ((baudrate < 1) || (baudrate > 4))
781 tiosp->c_cflag &= ~CBAUDEX;
782 else
783 baudrate += 15;
784 }
785 774
786 baudrate = gs_baudrates[baudrate]; 775 baudrate = gs_baudrates[baudrate];
787 if ((tiosp->c_cflag & CBAUD) == B38400) { 776 if ((tiosp->c_cflag & CBAUD) == B38400) {
@@ -846,24 +835,9 @@ void gs_set_termios (struct tty_struct * tty,
846int gs_init_port(struct gs_port *port) 835int gs_init_port(struct gs_port *port)
847{ 836{
848 unsigned long flags; 837 unsigned long flags;
849 unsigned long page;
850 838
851 func_enter (); 839 func_enter ();
852 840
853 if (!tmp_buf) {
854 page = get_zeroed_page(GFP_KERNEL);
855 spin_lock_irqsave (&port->driver_lock, flags); /* Don't expect this to make a difference. */
856 if (tmp_buf)
857 free_page(page);
858 else
859 tmp_buf = (unsigned char *) page;
860 spin_unlock_irqrestore (&port->driver_lock, flags);
861 if (!tmp_buf) {
862 func_exit ();
863 return -ENOMEM;
864 }
865 }
866
867 if (port->flags & ASYNC_INITIALIZED) { 841 if (port->flags & ASYNC_INITIALIZED) {
868 func_exit (); 842 func_exit ();
869 return 0; 843 return 0;
diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
index 817dc409ac20..23b25ada65ea 100644
--- a/drivers/char/genrtc.c
+++ b/drivers/char/genrtc.c
@@ -102,7 +102,7 @@ static void gen_rtc_interrupt(unsigned long arg);
102 * Routine to poll RTC seconds field for change as often as possible, 102 * Routine to poll RTC seconds field for change as often as possible,
103 * after first RTC_UIE use timer to reduce polling 103 * after first RTC_UIE use timer to reduce polling
104 */ 104 */
105static void genrtc_troutine(void *data) 105static void genrtc_troutine(struct work_struct *work)
106{ 106{
107 unsigned int tmp = get_rtc_ss(); 107 unsigned int tmp = get_rtc_ss();
108 108
@@ -255,7 +255,7 @@ static inline int gen_set_rtc_irq_bit(unsigned char bit)
255 irq_active = 1; 255 irq_active = 1;
256 stop_rtc_timers = 0; 256 stop_rtc_timers = 0;
257 lostint = 0; 257 lostint = 0;
258 INIT_WORK(&genrtc_task, genrtc_troutine, NULL); 258 INIT_WORK(&genrtc_task, genrtc_troutine);
259 oldsecs = get_rtc_ss(); 259 oldsecs = get_rtc_ss();
260 init_timer(&timer_task); 260 init_timer(&timer_task);
261 261
diff --git a/drivers/char/hangcheck-timer.c b/drivers/char/hangcheck-timer.c
index d69f2ad9a67d..1aa93a752a9c 100644
--- a/drivers/char/hangcheck-timer.c
+++ b/drivers/char/hangcheck-timer.c
@@ -159,7 +159,7 @@ static void hangcheck_fire(unsigned long data)
159 if (hangcheck_dump_tasks) { 159 if (hangcheck_dump_tasks) {
160 printk(KERN_CRIT "Hangcheck: Task state:\n"); 160 printk(KERN_CRIT "Hangcheck: Task state:\n");
161#ifdef CONFIG_MAGIC_SYSRQ 161#ifdef CONFIG_MAGIC_SYSRQ
162 handle_sysrq('t', NULL, NULL); 162 handle_sysrq('t', NULL);
163#endif /* CONFIG_MAGIC_SYSRQ */ 163#endif /* CONFIG_MAGIC_SYSRQ */
164 } 164 }
165 if (hangcheck_reboot) { 165 if (hangcheck_reboot) {
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index 58b0eb581114..20dc3be5ecfc 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -21,6 +21,7 @@
21#include <linux/fcntl.h> 21#include <linux/fcntl.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/poll.h> 23#include <linux/poll.h>
24#include <linux/mm.h>
24#include <linux/proc_fs.h> 25#include <linux/proc_fs.h>
25#include <linux/spinlock.h> 26#include <linux/spinlock.h>
26#include <linux/sysctl.h> 27#include <linux/sysctl.h>
@@ -116,7 +117,7 @@ static inline void writeq(unsigned long long v, void __iomem *addr)
116} 117}
117#endif 118#endif
118 119
119static irqreturn_t hpet_interrupt(int irq, void *data, struct pt_regs *regs) 120static irqreturn_t hpet_interrupt(int irq, void *data)
120{ 121{
121 struct hpet_dev *devp; 122 struct hpet_dev *devp;
122 unsigned long isr; 123 unsigned long isr;
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index a76d2c40dd5e..cc2cd46bedc6 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -38,6 +38,7 @@
38#include <linux/sched.h> 38#include <linux/sched.h>
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <linux/delay.h> 40#include <linux/delay.h>
41#include <linux/freezer.h>
41 42
42#include <asm/uaccess.h> 43#include <asm/uaccess.h>
43 44
@@ -294,7 +295,7 @@ static int hvc_poll(struct hvc_struct *hp);
294 * NOTE: This API isn't used if the console adapter doesn't support interrupts. 295 * NOTE: This API isn't used if the console adapter doesn't support interrupts.
295 * In this case the console is poll driven. 296 * In this case the console is poll driven.
296 */ 297 */
297static irqreturn_t hvc_handle_interrupt(int irq, void *dev_instance, struct pt_regs *regs) 298static irqreturn_t hvc_handle_interrupt(int irq, void *dev_instance)
298{ 299{
299 /* if hvc_poll request a repoll, then kick the hvcd thread */ 300 /* if hvc_poll request a repoll, then kick the hvcd thread */
300 if (hvc_poll(dev_instance)) 301 if (hvc_poll(dev_instance))
@@ -621,7 +622,7 @@ static int hvc_poll(struct hvc_struct *hp)
621 sysrq_pressed = 1; 622 sysrq_pressed = 1;
622 continue; 623 continue;
623 } else if (sysrq_pressed) { 624 } else if (sysrq_pressed) {
624 handle_sysrq(buf[i], NULL, tty); 625 handle_sysrq(buf[i], tty);
625 sysrq_pressed = 0; 626 sysrq_pressed = 0;
626 continue; 627 continue;
627 } 628 }
@@ -696,7 +697,7 @@ int khvcd(void *unused)
696 return 0; 697 return 0;
697} 698}
698 699
699static struct tty_operations hvc_ops = { 700static const struct tty_operations hvc_ops = {
700 .open = hvc_open, 701 .open = hvc_open,
701 .close = hvc_close, 702 .close = hvc_close,
702 .write = hvc_write, 703 .write = hvc_write,
diff --git a/drivers/char/hvc_iseries.c b/drivers/char/hvc_iseries.c
index 4747729459c7..f144a947bd17 100644
--- a/drivers/char/hvc_iseries.c
+++ b/drivers/char/hvc_iseries.c
@@ -29,6 +29,7 @@
29#include <asm/hvconsole.h> 29#include <asm/hvconsole.h>
30#include <asm/vio.h> 30#include <asm/vio.h>
31#include <asm/prom.h> 31#include <asm/prom.h>
32#include <asm/firmware.h>
32#include <asm/iseries/vio.h> 33#include <asm/iseries/vio.h>
33#include <asm/iseries/hv_call.h> 34#include <asm/iseries/hv_call.h>
34#include <asm/iseries/hv_lp_config.h> 35#include <asm/iseries/hv_lp_config.h>
@@ -153,9 +154,7 @@ static int put_chars(uint32_t vtermno, const char *buf, int count)
153 spin_lock_irqsave(&consolelock, flags); 154 spin_lock_irqsave(&consolelock, flags);
154 155
155 if (viochar_is_console(pi) && !viopath_isactive(pi->lp)) { 156 if (viochar_is_console(pi) && !viopath_isactive(pi->lp)) {
156 spin_lock_irqsave(&consoleloglock, flags);
157 HvCall_writeLogBuffer(buf, count); 157 HvCall_writeLogBuffer(buf, count);
158 spin_unlock_irqrestore(&consoleloglock, flags);
159 sent = count; 158 sent = count;
160 goto done; 159 goto done;
161 } 160 }
@@ -171,11 +170,8 @@ static int put_chars(uint32_t vtermno, const char *buf, int count)
171 170
172 len = (count > VIOCHAR_MAX_DATA) ? VIOCHAR_MAX_DATA : count; 171 len = (count > VIOCHAR_MAX_DATA) ? VIOCHAR_MAX_DATA : count;
173 172
174 if (viochar_is_console(pi)) { 173 if (viochar_is_console(pi))
175 spin_lock_irqsave(&consoleloglock, flags);
176 HvCall_writeLogBuffer(buf, len); 174 HvCall_writeLogBuffer(buf, len);
177 spin_unlock_irqrestore(&consoleloglock, flags);
178 }
179 175
180 init_data_event(viochar, pi->lp); 176 init_data_event(viochar, pi->lp);
181 177
@@ -493,6 +489,9 @@ static int hvc_vio_init(void)
493 atomic_t wait_flag; 489 atomic_t wait_flag;
494 int rc; 490 int rc;
495 491
492 if (!firmware_has_feature(FW_FEATURE_ISERIES))
493 return -EIO;
494
496 /* +2 for fudge */ 495 /* +2 for fudge */
497 rc = viopath_open(HvLpConfig_getPrimaryLpIndex(), 496 rc = viopath_open(HvLpConfig_getPrimaryLpIndex(),
498 viomajorsubtype_chario, VIOCHAR_WINDOW + 2); 497 viomajorsubtype_chario, VIOCHAR_WINDOW + 2);
@@ -567,7 +566,7 @@ static int hvc_find_vtys(void)
567 566
568 for (vty = of_find_node_by_name(NULL, "vty"); vty != NULL; 567 for (vty = of_find_node_by_name(NULL, "vty"); vty != NULL;
569 vty = of_find_node_by_name(vty, "vty")) { 568 vty = of_find_node_by_name(vty, "vty")) {
570 uint32_t *vtermno; 569 const uint32_t *vtermno;
571 570
572 /* We have statically defined space for only a certain number 571 /* We have statically defined space for only a certain number
573 * of console adapters. 572 * of console adapters.
@@ -576,7 +575,7 @@ static int hvc_find_vtys(void)
576 (num_found >= VTTY_PORTS)) 575 (num_found >= VTTY_PORTS))
577 break; 576 break;
578 577
579 vtermno = (uint32_t *)get_property(vty, "reg", NULL); 578 vtermno = get_property(vty, "reg", NULL);
580 if (!vtermno) 579 if (!vtermno)
581 continue; 580 continue;
582 581
diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c
index cc95941148fb..f9c00844d2bf 100644
--- a/drivers/char/hvc_vio.c
+++ b/drivers/char/hvc_vio.c
@@ -35,6 +35,7 @@
35#include <asm/hvconsole.h> 35#include <asm/hvconsole.h>
36#include <asm/vio.h> 36#include <asm/vio.h>
37#include <asm/prom.h> 37#include <asm/prom.h>
38#include <asm/firmware.h>
38 39
39#include "hvc_console.h" 40#include "hvc_console.h"
40 41
@@ -120,6 +121,9 @@ static int hvc_vio_init(void)
120{ 121{
121 int rc; 122 int rc;
122 123
124 if (firmware_has_feature(FW_FEATURE_ISERIES))
125 return -EIO;
126
123 /* Register as a vio device to receive callbacks */ 127 /* Register as a vio device to receive callbacks */
124 rc = vio_register_driver(&hvc_vio_driver); 128 rc = vio_register_driver(&hvc_vio_driver);
125 129
diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
index 4589ff302b07..207f7343ba60 100644
--- a/drivers/char/hvcs.c
+++ b/drivers/char/hvcs.c
@@ -192,11 +192,13 @@ MODULE_VERSION(HVCS_DRIVER_VERSION);
192 * that will cause echoing or we'll go into recursive loop echoing chars back 192 * that will cause echoing or we'll go into recursive loop echoing chars back
193 * and forth with the console drivers. 193 * and forth with the console drivers.
194 */ 194 */
195static struct termios hvcs_tty_termios = { 195static struct ktermios hvcs_tty_termios = {
196 .c_iflag = IGNBRK | IGNPAR, 196 .c_iflag = IGNBRK | IGNPAR,
197 .c_oflag = OPOST, 197 .c_oflag = OPOST,
198 .c_cflag = B38400 | CS8 | CREAD | HUPCL, 198 .c_cflag = B38400 | CS8 | CREAD | HUPCL,
199 .c_cc = INIT_C_CC 199 .c_cc = INIT_C_CC,
200 .c_ispeed = 38400,
201 .c_ospeed = 38400
200}; 202};
201 203
202/* 204/*
@@ -313,8 +315,7 @@ static DEFINE_SPINLOCK(hvcs_structs_lock);
313 315
314static void hvcs_unthrottle(struct tty_struct *tty); 316static void hvcs_unthrottle(struct tty_struct *tty);
315static void hvcs_throttle(struct tty_struct *tty); 317static void hvcs_throttle(struct tty_struct *tty);
316static irqreturn_t hvcs_handle_interrupt(int irq, void *dev_instance, 318static irqreturn_t hvcs_handle_interrupt(int irq, void *dev_instance);
317 struct pt_regs *regs);
318 319
319static int hvcs_write(struct tty_struct *tty, 320static int hvcs_write(struct tty_struct *tty,
320 const unsigned char *buf, int count); 321 const unsigned char *buf, int count);
@@ -338,11 +339,6 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp);
338static void hvcs_close(struct tty_struct *tty, struct file *filp); 339static void hvcs_close(struct tty_struct *tty, struct file *filp);
339static void hvcs_hangup(struct tty_struct * tty); 340static void hvcs_hangup(struct tty_struct * tty);
340 341
341static void hvcs_create_device_attrs(struct hvcs_struct *hvcsd);
342static void hvcs_remove_device_attrs(struct vio_dev *vdev);
343static void hvcs_create_driver_attrs(void);
344static void hvcs_remove_driver_attrs(void);
345
346static int __devinit hvcs_probe(struct vio_dev *dev, 342static int __devinit hvcs_probe(struct vio_dev *dev,
347 const struct vio_device_id *id); 343 const struct vio_device_id *id);
348static int __devexit hvcs_remove(struct vio_dev *dev); 344static int __devexit hvcs_remove(struct vio_dev *dev);
@@ -354,6 +350,172 @@ static void __exit hvcs_module_exit(void);
354#define HVCS_TRY_WRITE 0x00000004 350#define HVCS_TRY_WRITE 0x00000004
355#define HVCS_READ_MASK (HVCS_SCHED_READ | HVCS_QUICK_READ) 351#define HVCS_READ_MASK (HVCS_SCHED_READ | HVCS_QUICK_READ)
356 352
353static inline struct hvcs_struct *from_vio_dev(struct vio_dev *viod)
354{
355 return viod->dev.driver_data;
356}
357/* The sysfs interface for the driver and devices */
358
359static ssize_t hvcs_partner_vtys_show(struct device *dev, struct device_attribute *attr, char *buf)
360{
361 struct vio_dev *viod = to_vio_dev(dev);
362 struct hvcs_struct *hvcsd = from_vio_dev(viod);
363 unsigned long flags;
364 int retval;
365
366 spin_lock_irqsave(&hvcsd->lock, flags);
367 retval = sprintf(buf, "%X\n", hvcsd->p_unit_address);
368 spin_unlock_irqrestore(&hvcsd->lock, flags);
369 return retval;
370}
371static DEVICE_ATTR(partner_vtys, S_IRUGO, hvcs_partner_vtys_show, NULL);
372
373static ssize_t hvcs_partner_clcs_show(struct device *dev, struct device_attribute *attr, char *buf)
374{
375 struct vio_dev *viod = to_vio_dev(dev);
376 struct hvcs_struct *hvcsd = from_vio_dev(viod);
377 unsigned long flags;
378 int retval;
379
380 spin_lock_irqsave(&hvcsd->lock, flags);
381 retval = sprintf(buf, "%s\n", &hvcsd->p_location_code[0]);
382 spin_unlock_irqrestore(&hvcsd->lock, flags);
383 return retval;
384}
385static DEVICE_ATTR(partner_clcs, S_IRUGO, hvcs_partner_clcs_show, NULL);
386
387static ssize_t hvcs_current_vty_store(struct device *dev, struct device_attribute *attr, const char * buf,
388 size_t count)
389{
390 /*
391 * Don't need this feature at the present time because firmware doesn't
392 * yet support multiple partners.
393 */
394 printk(KERN_INFO "HVCS: Denied current_vty change: -EPERM.\n");
395 return -EPERM;
396}
397
398static ssize_t hvcs_current_vty_show(struct device *dev, struct device_attribute *attr, char *buf)
399{
400 struct vio_dev *viod = to_vio_dev(dev);
401 struct hvcs_struct *hvcsd = from_vio_dev(viod);
402 unsigned long flags;
403 int retval;
404
405 spin_lock_irqsave(&hvcsd->lock, flags);
406 retval = sprintf(buf, "%s\n", &hvcsd->p_location_code[0]);
407 spin_unlock_irqrestore(&hvcsd->lock, flags);
408 return retval;
409}
410
411static DEVICE_ATTR(current_vty,
412 S_IRUGO | S_IWUSR, hvcs_current_vty_show, hvcs_current_vty_store);
413
414static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribute *attr, const char *buf,
415 size_t count)
416{
417 struct vio_dev *viod = to_vio_dev(dev);
418 struct hvcs_struct *hvcsd = from_vio_dev(viod);
419 unsigned long flags;
420
421 /* writing a '0' to this sysfs entry will result in the disconnect. */
422 if (simple_strtol(buf, NULL, 0) != 0)
423 return -EINVAL;
424
425 spin_lock_irqsave(&hvcsd->lock, flags);
426
427 if (hvcsd->open_count > 0) {
428 spin_unlock_irqrestore(&hvcsd->lock, flags);
429 printk(KERN_INFO "HVCS: vterm state unchanged. "
430 "The hvcs device node is still in use.\n");
431 return -EPERM;
432 }
433
434 if (hvcsd->connected == 0) {
435 spin_unlock_irqrestore(&hvcsd->lock, flags);
436 printk(KERN_INFO "HVCS: vterm state unchanged. The"
437 " vty-server is not connected to a vty.\n");
438 return -EPERM;
439 }
440
441 hvcs_partner_free(hvcsd);
442 printk(KERN_INFO "HVCS: Closed vty-server@%X and"
443 " partner vty@%X:%d connection.\n",
444 hvcsd->vdev->unit_address,
445 hvcsd->p_unit_address,
446 (uint32_t)hvcsd->p_partition_ID);
447
448 spin_unlock_irqrestore(&hvcsd->lock, flags);
449 return count;
450}
451
452static ssize_t hvcs_vterm_state_show(struct device *dev, struct device_attribute *attr, char *buf)
453{
454 struct vio_dev *viod = to_vio_dev(dev);
455 struct hvcs_struct *hvcsd = from_vio_dev(viod);
456 unsigned long flags;
457 int retval;
458
459 spin_lock_irqsave(&hvcsd->lock, flags);
460 retval = sprintf(buf, "%d\n", hvcsd->connected);
461 spin_unlock_irqrestore(&hvcsd->lock, flags);
462 return retval;
463}
464static DEVICE_ATTR(vterm_state, S_IRUGO | S_IWUSR,
465 hvcs_vterm_state_show, hvcs_vterm_state_store);
466
467static ssize_t hvcs_index_show(struct device *dev, struct device_attribute *attr, char *buf)
468{
469 struct vio_dev *viod = to_vio_dev(dev);
470 struct hvcs_struct *hvcsd = from_vio_dev(viod);
471 unsigned long flags;
472 int retval;
473
474 spin_lock_irqsave(&hvcsd->lock, flags);
475 retval = sprintf(buf, "%d\n", hvcsd->index);
476 spin_unlock_irqrestore(&hvcsd->lock, flags);
477 return retval;
478}
479
480static DEVICE_ATTR(index, S_IRUGO, hvcs_index_show, NULL);
481
482static struct attribute *hvcs_attrs[] = {
483 &dev_attr_partner_vtys.attr,
484 &dev_attr_partner_clcs.attr,
485 &dev_attr_current_vty.attr,
486 &dev_attr_vterm_state.attr,
487 &dev_attr_index.attr,
488 NULL,
489};
490
491static struct attribute_group hvcs_attr_group = {
492 .attrs = hvcs_attrs,
493};
494
495static ssize_t hvcs_rescan_show(struct device_driver *ddp, char *buf)
496{
497 /* A 1 means it is updating, a 0 means it is done updating */
498 return snprintf(buf, PAGE_SIZE, "%d\n", hvcs_rescan_status);
499}
500
501static ssize_t hvcs_rescan_store(struct device_driver *ddp, const char * buf,
502 size_t count)
503{
504 if ((simple_strtol(buf, NULL, 0) != 1)
505 && (hvcs_rescan_status != 0))
506 return -EINVAL;
507
508 hvcs_rescan_status = 1;
509 printk(KERN_INFO "HVCS: rescanning partner info for all"
510 " vty-servers.\n");
511 hvcs_rescan_devices_list();
512 hvcs_rescan_status = 0;
513 return count;
514}
515
516static DRIVER_ATTR(rescan,
517 S_IRUGO | S_IWUSR, hvcs_rescan_show, hvcs_rescan_store);
518
357static void hvcs_kick(void) 519static void hvcs_kick(void)
358{ 520{
359 hvcs_kicked = 1; 521 hvcs_kicked = 1;
@@ -387,8 +549,7 @@ static void hvcs_throttle(struct tty_struct *tty)
387 * handler taking any further interrupts because they are disabled which means 549 * handler taking any further interrupts because they are disabled which means
388 * the hvcs_struct will always be valid in this handler. 550 * the hvcs_struct will always be valid in this handler.
389 */ 551 */
390static irqreturn_t hvcs_handle_interrupt(int irq, void *dev_instance, 552static irqreturn_t hvcs_handle_interrupt(int irq, void *dev_instance)
391 struct pt_regs *regs)
392{ 553{
393 struct hvcs_struct *hvcsd = dev_instance; 554 struct hvcs_struct *hvcsd = dev_instance;
394 555
@@ -577,7 +738,7 @@ static void destroy_hvcs_struct(struct kobject *kobj)
577 spin_unlock_irqrestore(&hvcsd->lock, flags); 738 spin_unlock_irqrestore(&hvcsd->lock, flags);
578 spin_unlock(&hvcs_structs_lock); 739 spin_unlock(&hvcs_structs_lock);
579 740
580 hvcs_remove_device_attrs(vdev); 741 sysfs_remove_group(&vdev->dev.kobj, &hvcs_attr_group);
581 742
582 kfree(hvcsd); 743 kfree(hvcsd);
583} 744}
@@ -610,6 +771,7 @@ static int __devinit hvcs_probe(
610{ 771{
611 struct hvcs_struct *hvcsd; 772 struct hvcs_struct *hvcsd;
612 int index; 773 int index;
774 int retval;
613 775
614 if (!dev || !id) { 776 if (!dev || !id) {
615 printk(KERN_ERR "HVCS: probed with invalid parameter.\n"); 777 printk(KERN_ERR "HVCS: probed with invalid parameter.\n");
@@ -660,14 +822,16 @@ static int __devinit hvcs_probe(
660 * the hvcs_struct has been added to the devices list then the user app 822 * the hvcs_struct has been added to the devices list then the user app
661 * will get -ENODEV. 823 * will get -ENODEV.
662 */ 824 */
663
664 spin_lock(&hvcs_structs_lock); 825 spin_lock(&hvcs_structs_lock);
665
666 list_add_tail(&(hvcsd->next), &hvcs_structs); 826 list_add_tail(&(hvcsd->next), &hvcs_structs);
667
668 spin_unlock(&hvcs_structs_lock); 827 spin_unlock(&hvcs_structs_lock);
669 828
670 hvcs_create_device_attrs(hvcsd); 829 retval = sysfs_create_group(&dev->dev.kobj, &hvcs_attr_group);
830 if (retval) {
831 printk(KERN_ERR "HVCS: Can't create sysfs attrs for vty-server@%X\n",
832 hvcsd->vdev->unit_address);
833 return retval;
834 }
671 835
672 printk(KERN_INFO "HVCS: vty-server@%X added to the vio bus.\n", dev->unit_address); 836 printk(KERN_INFO "HVCS: vty-server@%X added to the vio bus.\n", dev->unit_address);
673 837
@@ -1306,7 +1470,7 @@ static int hvcs_chars_in_buffer(struct tty_struct *tty)
1306 return hvcsd->chars_in_buffer; 1470 return hvcsd->chars_in_buffer;
1307} 1471}
1308 1472
1309static struct tty_operations hvcs_ops = { 1473static const struct tty_operations hvcs_ops = {
1310 .open = hvcs_open, 1474 .open = hvcs_open,
1311 .close = hvcs_close, 1475 .close = hvcs_close,
1312 .hangup = hvcs_hangup, 1476 .hangup = hvcs_hangup,
@@ -1356,8 +1520,10 @@ static int __init hvcs_module_init(void)
1356 if (!hvcs_tty_driver) 1520 if (!hvcs_tty_driver)
1357 return -ENOMEM; 1521 return -ENOMEM;
1358 1522
1359 if (hvcs_alloc_index_list(num_ttys_to_alloc)) 1523 if (hvcs_alloc_index_list(num_ttys_to_alloc)) {
1360 return -ENOMEM; 1524 rc = -ENOMEM;
1525 goto index_fail;
1526 }
1361 1527
1362 hvcs_tty_driver->owner = THIS_MODULE; 1528 hvcs_tty_driver->owner = THIS_MODULE;
1363 1529
@@ -1387,41 +1553,57 @@ static int __init hvcs_module_init(void)
1387 * dynamically assigned major and minor numbers for our devices. 1553 * dynamically assigned major and minor numbers for our devices.
1388 */ 1554 */
1389 if (tty_register_driver(hvcs_tty_driver)) { 1555 if (tty_register_driver(hvcs_tty_driver)) {
1390 printk(KERN_ERR "HVCS: registration " 1556 printk(KERN_ERR "HVCS: registration as a tty driver failed.\n");
1391 " as a tty driver failed.\n"); 1557 rc = -EIO;
1392 hvcs_free_index_list(); 1558 goto register_fail;
1393 put_tty_driver(hvcs_tty_driver);
1394 return -EIO;
1395 } 1559 }
1396 1560
1397 hvcs_pi_buff = kmalloc(PAGE_SIZE, GFP_KERNEL); 1561 hvcs_pi_buff = kmalloc(PAGE_SIZE, GFP_KERNEL);
1398 if (!hvcs_pi_buff) { 1562 if (!hvcs_pi_buff) {
1399 tty_unregister_driver(hvcs_tty_driver); 1563 rc = -ENOMEM;
1400 hvcs_free_index_list(); 1564 goto buff_alloc_fail;
1401 put_tty_driver(hvcs_tty_driver);
1402 return -ENOMEM;
1403 } 1565 }
1404 1566
1405 hvcs_task = kthread_run(khvcsd, NULL, "khvcsd"); 1567 hvcs_task = kthread_run(khvcsd, NULL, "khvcsd");
1406 if (IS_ERR(hvcs_task)) { 1568 if (IS_ERR(hvcs_task)) {
1407 printk(KERN_ERR "HVCS: khvcsd creation failed. Driver not loaded.\n"); 1569 printk(KERN_ERR "HVCS: khvcsd creation failed. Driver not loaded.\n");
1408 kfree(hvcs_pi_buff); 1570 rc = -EIO;
1409 tty_unregister_driver(hvcs_tty_driver); 1571 goto kthread_fail;
1410 hvcs_free_index_list();
1411 put_tty_driver(hvcs_tty_driver);
1412 return -EIO;
1413 } 1572 }
1414 1573
1415 rc = vio_register_driver(&hvcs_vio_driver); 1574 rc = vio_register_driver(&hvcs_vio_driver);
1575 if (rc) {
1576 printk(KERN_ERR "HVCS: can't register vio driver\n");
1577 goto vio_fail;
1578 }
1416 1579
1417 /* 1580 /*
1418 * This needs to be done AFTER the vio_register_driver() call or else 1581 * This needs to be done AFTER the vio_register_driver() call or else
1419 * the kobjects won't be initialized properly. 1582 * the kobjects won't be initialized properly.
1420 */ 1583 */
1421 hvcs_create_driver_attrs(); 1584 rc = driver_create_file(&(hvcs_vio_driver.driver), &driver_attr_rescan);
1585 if (rc) {
1586 printk(KERN_ERR "HVCS: sysfs attr create failed\n");
1587 goto attr_fail;
1588 }
1422 1589
1423 printk(KERN_INFO "HVCS: driver module inserted.\n"); 1590 printk(KERN_INFO "HVCS: driver module inserted.\n");
1424 1591
1592 return 0;
1593
1594attr_fail:
1595 vio_unregister_driver(&hvcs_vio_driver);
1596vio_fail:
1597 kthread_stop(hvcs_task);
1598kthread_fail:
1599 kfree(hvcs_pi_buff);
1600buff_alloc_fail:
1601 tty_unregister_driver(hvcs_tty_driver);
1602register_fail:
1603 hvcs_free_index_list();
1604index_fail:
1605 put_tty_driver(hvcs_tty_driver);
1606 hvcs_tty_driver = NULL;
1425 return rc; 1607 return rc;
1426} 1608}
1427 1609
@@ -1443,7 +1625,7 @@ static void __exit hvcs_module_exit(void)
1443 hvcs_pi_buff = NULL; 1625 hvcs_pi_buff = NULL;
1444 spin_unlock(&hvcs_pi_lock); 1626 spin_unlock(&hvcs_pi_lock);
1445 1627
1446 hvcs_remove_driver_attrs(); 1628 driver_remove_file(&hvcs_vio_driver.driver, &driver_attr_rescan);
1447 1629
1448 vio_unregister_driver(&hvcs_vio_driver); 1630 vio_unregister_driver(&hvcs_vio_driver);
1449 1631
@@ -1458,191 +1640,3 @@ static void __exit hvcs_module_exit(void)
1458 1640
1459module_init(hvcs_module_init); 1641module_init(hvcs_module_init);
1460module_exit(hvcs_module_exit); 1642module_exit(hvcs_module_exit);
1461
1462static inline struct hvcs_struct *from_vio_dev(struct vio_dev *viod)
1463{
1464 return viod->dev.driver_data;
1465}
1466/* The sysfs interface for the driver and devices */
1467
1468static ssize_t hvcs_partner_vtys_show(struct device *dev, struct device_attribute *attr, char *buf)
1469{
1470 struct vio_dev *viod = to_vio_dev(dev);
1471 struct hvcs_struct *hvcsd = from_vio_dev(viod);
1472 unsigned long flags;
1473 int retval;
1474
1475 spin_lock_irqsave(&hvcsd->lock, flags);
1476 retval = sprintf(buf, "%X\n", hvcsd->p_unit_address);
1477 spin_unlock_irqrestore(&hvcsd->lock, flags);
1478 return retval;
1479}
1480static DEVICE_ATTR(partner_vtys, S_IRUGO, hvcs_partner_vtys_show, NULL);
1481
1482static ssize_t hvcs_partner_clcs_show(struct device *dev, struct device_attribute *attr, char *buf)
1483{
1484 struct vio_dev *viod = to_vio_dev(dev);
1485 struct hvcs_struct *hvcsd = from_vio_dev(viod);
1486 unsigned long flags;
1487 int retval;
1488
1489 spin_lock_irqsave(&hvcsd->lock, flags);
1490 retval = sprintf(buf, "%s\n", &hvcsd->p_location_code[0]);
1491 spin_unlock_irqrestore(&hvcsd->lock, flags);
1492 return retval;
1493}
1494static DEVICE_ATTR(partner_clcs, S_IRUGO, hvcs_partner_clcs_show, NULL);
1495
1496static ssize_t hvcs_current_vty_store(struct device *dev, struct device_attribute *attr, const char * buf,
1497 size_t count)
1498{
1499 /*
1500 * Don't need this feature at the present time because firmware doesn't
1501 * yet support multiple partners.
1502 */
1503 printk(KERN_INFO "HVCS: Denied current_vty change: -EPERM.\n");
1504 return -EPERM;
1505}
1506
1507static ssize_t hvcs_current_vty_show(struct device *dev, struct device_attribute *attr, char *buf)
1508{
1509 struct vio_dev *viod = to_vio_dev(dev);
1510 struct hvcs_struct *hvcsd = from_vio_dev(viod);
1511 unsigned long flags;
1512 int retval;
1513
1514 spin_lock_irqsave(&hvcsd->lock, flags);
1515 retval = sprintf(buf, "%s\n", &hvcsd->p_location_code[0]);
1516 spin_unlock_irqrestore(&hvcsd->lock, flags);
1517 return retval;
1518}
1519
1520static DEVICE_ATTR(current_vty,
1521 S_IRUGO | S_IWUSR, hvcs_current_vty_show, hvcs_current_vty_store);
1522
1523static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribute *attr, const char *buf,
1524 size_t count)
1525{
1526 struct vio_dev *viod = to_vio_dev(dev);
1527 struct hvcs_struct *hvcsd = from_vio_dev(viod);
1528 unsigned long flags;
1529
1530 /* writing a '0' to this sysfs entry will result in the disconnect. */
1531 if (simple_strtol(buf, NULL, 0) != 0)
1532 return -EINVAL;
1533
1534 spin_lock_irqsave(&hvcsd->lock, flags);
1535
1536 if (hvcsd->open_count > 0) {
1537 spin_unlock_irqrestore(&hvcsd->lock, flags);
1538 printk(KERN_INFO "HVCS: vterm state unchanged. "
1539 "The hvcs device node is still in use.\n");
1540 return -EPERM;
1541 }
1542
1543 if (hvcsd->connected == 0) {
1544 spin_unlock_irqrestore(&hvcsd->lock, flags);
1545 printk(KERN_INFO "HVCS: vterm state unchanged. The"
1546 " vty-server is not connected to a vty.\n");
1547 return -EPERM;
1548 }
1549
1550 hvcs_partner_free(hvcsd);
1551 printk(KERN_INFO "HVCS: Closed vty-server@%X and"
1552 " partner vty@%X:%d connection.\n",
1553 hvcsd->vdev->unit_address,
1554 hvcsd->p_unit_address,
1555 (uint32_t)hvcsd->p_partition_ID);
1556
1557 spin_unlock_irqrestore(&hvcsd->lock, flags);
1558 return count;
1559}
1560
1561static ssize_t hvcs_vterm_state_show(struct device *dev, struct device_attribute *attr, char *buf)
1562{
1563 struct vio_dev *viod = to_vio_dev(dev);
1564 struct hvcs_struct *hvcsd = from_vio_dev(viod);
1565 unsigned long flags;
1566 int retval;
1567
1568 spin_lock_irqsave(&hvcsd->lock, flags);
1569 retval = sprintf(buf, "%d\n", hvcsd->connected);
1570 spin_unlock_irqrestore(&hvcsd->lock, flags);
1571 return retval;
1572}
1573static DEVICE_ATTR(vterm_state, S_IRUGO | S_IWUSR,
1574 hvcs_vterm_state_show, hvcs_vterm_state_store);
1575
1576static ssize_t hvcs_index_show(struct device *dev, struct device_attribute *attr, char *buf)
1577{
1578 struct vio_dev *viod = to_vio_dev(dev);
1579 struct hvcs_struct *hvcsd = from_vio_dev(viod);
1580 unsigned long flags;
1581 int retval;
1582
1583 spin_lock_irqsave(&hvcsd->lock, flags);
1584 retval = sprintf(buf, "%d\n", hvcsd->index);
1585 spin_unlock_irqrestore(&hvcsd->lock, flags);
1586 return retval;
1587}
1588
1589static DEVICE_ATTR(index, S_IRUGO, hvcs_index_show, NULL);
1590
1591static struct attribute *hvcs_attrs[] = {
1592 &dev_attr_partner_vtys.attr,
1593 &dev_attr_partner_clcs.attr,
1594 &dev_attr_current_vty.attr,
1595 &dev_attr_vterm_state.attr,
1596 &dev_attr_index.attr,
1597 NULL,
1598};
1599
1600static struct attribute_group hvcs_attr_group = {
1601 .attrs = hvcs_attrs,
1602};
1603
1604static void hvcs_create_device_attrs(struct hvcs_struct *hvcsd)
1605{
1606 struct vio_dev *vdev = hvcsd->vdev;
1607 sysfs_create_group(&vdev->dev.kobj, &hvcs_attr_group);
1608}
1609
1610static void hvcs_remove_device_attrs(struct vio_dev *vdev)
1611{
1612 sysfs_remove_group(&vdev->dev.kobj, &hvcs_attr_group);
1613}
1614
1615static ssize_t hvcs_rescan_show(struct device_driver *ddp, char *buf)
1616{
1617 /* A 1 means it is updating, a 0 means it is done updating */
1618 return snprintf(buf, PAGE_SIZE, "%d\n", hvcs_rescan_status);
1619}
1620
1621static ssize_t hvcs_rescan_store(struct device_driver *ddp, const char * buf,
1622 size_t count)
1623{
1624 if ((simple_strtol(buf, NULL, 0) != 1)
1625 && (hvcs_rescan_status != 0))
1626 return -EINVAL;
1627
1628 hvcs_rescan_status = 1;
1629 printk(KERN_INFO "HVCS: rescanning partner info for all"
1630 " vty-servers.\n");
1631 hvcs_rescan_devices_list();
1632 hvcs_rescan_status = 0;
1633 return count;
1634}
1635static DRIVER_ATTR(rescan,
1636 S_IRUGO | S_IWUSR, hvcs_rescan_show, hvcs_rescan_store);
1637
1638static void hvcs_create_driver_attrs(void)
1639{
1640 struct device_driver *driverfs = &(hvcs_vio_driver.driver);
1641 driver_create_file(driverfs, &driver_attr_rescan);
1642}
1643
1644static void hvcs_remove_driver_attrs(void)
1645{
1646 struct device_driver *driverfs = &(hvcs_vio_driver.driver);
1647 driver_remove_file(driverfs, &driver_attr_rescan);
1648}
diff --git a/drivers/char/hvsi.c b/drivers/char/hvsi.c
index a89a95fb5e40..d7806834fc17 100644
--- a/drivers/char/hvsi.c
+++ b/drivers/char/hvsi.c
@@ -69,7 +69,7 @@
69#define __ALIGNED__ __attribute__((__aligned__(sizeof(long)))) 69#define __ALIGNED__ __attribute__((__aligned__(sizeof(long))))
70 70
71struct hvsi_struct { 71struct hvsi_struct {
72 struct work_struct writer; 72 struct delayed_work writer;
73 struct work_struct handshaker; 73 struct work_struct handshaker;
74 wait_queue_head_t emptyq; /* woken when outbuf is emptied */ 74 wait_queue_head_t emptyq; /* woken when outbuf is emptied */
75 wait_queue_head_t stateq; /* woken when HVSI state changes */ 75 wait_queue_head_t stateq; /* woken when HVSI state changes */
@@ -406,7 +406,7 @@ static void hvsi_insert_chars(struct hvsi_struct *hp, const char *buf, int len)
406 hp->sysrq = 1; 406 hp->sysrq = 1;
407 continue; 407 continue;
408 } else if (hp->sysrq) { 408 } else if (hp->sysrq) {
409 handle_sysrq(c, NULL, hp->tty); 409 handle_sysrq(c, hp->tty);
410 hp->sysrq = 0; 410 hp->sysrq = 0;
411 continue; 411 continue;
412 } 412 }
@@ -555,7 +555,7 @@ static void hvsi_send_overflow(struct hvsi_struct *hp)
555 * must get all pending data because we only get an irq on empty->non-empty 555 * must get all pending data because we only get an irq on empty->non-empty
556 * transition 556 * transition
557 */ 557 */
558static irqreturn_t hvsi_interrupt(int irq, void *arg, struct pt_regs *regs) 558static irqreturn_t hvsi_interrupt(int irq, void *arg)
559{ 559{
560 struct hvsi_struct *hp = (struct hvsi_struct *)arg; 560 struct hvsi_struct *hp = (struct hvsi_struct *)arg;
561 struct tty_struct *flip; 561 struct tty_struct *flip;
@@ -616,7 +616,7 @@ static int __init poll_for_state(struct hvsi_struct *hp, int state)
616 unsigned long end_jiffies = jiffies + HVSI_TIMEOUT; 616 unsigned long end_jiffies = jiffies + HVSI_TIMEOUT;
617 617
618 for (;;) { 618 for (;;) {
619 hvsi_interrupt(hp->virq, (void *)hp, NULL); /* get pending data */ 619 hvsi_interrupt(hp->virq, (void *)hp); /* get pending data */
620 620
621 if (hp->state == state) 621 if (hp->state == state)
622 return 0; 622 return 0;
@@ -744,9 +744,10 @@ static int hvsi_handshake(struct hvsi_struct *hp)
744 return 0; 744 return 0;
745} 745}
746 746
747static void hvsi_handshaker(void *arg) 747static void hvsi_handshaker(struct work_struct *work)
748{ 748{
749 struct hvsi_struct *hp = (struct hvsi_struct *)arg; 749 struct hvsi_struct *hp =
750 container_of(work, struct hvsi_struct, handshaker);
750 751
751 if (hvsi_handshake(hp) >= 0) 752 if (hvsi_handshake(hp) >= 0)
752 return; 753 return;
@@ -951,9 +952,10 @@ static void hvsi_push(struct hvsi_struct *hp)
951} 952}
952 953
953/* hvsi_write_worker will keep rescheduling itself until outbuf is empty */ 954/* hvsi_write_worker will keep rescheduling itself until outbuf is empty */
954static void hvsi_write_worker(void *arg) 955static void hvsi_write_worker(struct work_struct *work)
955{ 956{
956 struct hvsi_struct *hp = (struct hvsi_struct *)arg; 957 struct hvsi_struct *hp =
958 container_of(work, struct hvsi_struct, writer.work);
957 unsigned long flags; 959 unsigned long flags;
958#ifdef DEBUG 960#ifdef DEBUG
959 static long start_j = 0; 961 static long start_j = 0;
@@ -1130,7 +1132,7 @@ static int hvsi_tiocmset(struct tty_struct *tty, struct file *file,
1130} 1132}
1131 1133
1132 1134
1133static struct tty_operations hvsi_ops = { 1135static const struct tty_operations hvsi_ops = {
1134 .open = hvsi_open, 1136 .open = hvsi_open,
1135 .close = hvsi_close, 1137 .close = hvsi_close,
1136 .write = hvsi_write, 1138 .write = hvsi_write,
@@ -1159,6 +1161,8 @@ static int __init hvsi_init(void)
1159 hvsi_driver->type = TTY_DRIVER_TYPE_SYSTEM; 1161 hvsi_driver->type = TTY_DRIVER_TYPE_SYSTEM;
1160 hvsi_driver->init_termios = tty_std_termios; 1162 hvsi_driver->init_termios = tty_std_termios;
1161 hvsi_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL; 1163 hvsi_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1164 hvsi_driver->init_termios.c_ispeed = 9600;
1165 hvsi_driver->init_termios.c_ospeed = 9600;
1162 hvsi_driver->flags = TTY_DRIVER_REAL_RAW; 1166 hvsi_driver->flags = TTY_DRIVER_REAL_RAW;
1163 tty_set_operations(hvsi_driver, &hvsi_ops); 1167 tty_set_operations(hvsi_driver, &hvsi_ops);
1164 1168
@@ -1287,8 +1291,8 @@ static int __init hvsi_console_init(void)
1287 } 1291 }
1288 1292
1289 hp = &hvsi_ports[hvsi_count]; 1293 hp = &hvsi_ports[hvsi_count];
1290 INIT_WORK(&hp->writer, hvsi_write_worker, hp); 1294 INIT_DELAYED_WORK(&hp->writer, hvsi_write_worker);
1291 INIT_WORK(&hp->handshaker, hvsi_handshaker, hp); 1295 INIT_WORK(&hp->handshaker, hvsi_handshaker);
1292 init_waitqueue_head(&hp->emptyq); 1296 init_waitqueue_head(&hp->emptyq);
1293 init_waitqueue_head(&hp->stateq); 1297 init_waitqueue_head(&hp->stateq);
1294 spin_lock_init(&hp->lock); 1298 spin_lock_init(&hp->lock);
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index 9f7635f75178..5f3acd8e64b8 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -3,17 +3,20 @@
3# 3#
4 4
5config HW_RANDOM 5config HW_RANDOM
6 bool "Hardware Random Number Generator Core support" 6 tristate "Hardware Random Number Generator Core support"
7 default y 7 default m
8 ---help--- 8 ---help---
9 Hardware Random Number Generator Core infrastructure. 9 Hardware Random Number Generator Core infrastructure.
10 10
11 To compile this driver as a module, choose M here: the
12 module will be called rng-core.
13
11 If unsure, say Y. 14 If unsure, say Y.
12 15
13config HW_RANDOM_INTEL 16config HW_RANDOM_INTEL
14 tristate "Intel HW Random Number Generator support" 17 tristate "Intel HW Random Number Generator support"
15 depends on HW_RANDOM && (X86 || IA64) && PCI 18 depends on HW_RANDOM && (X86 || IA64) && PCI
16 default y 19 default HW_RANDOM
17 ---help--- 20 ---help---
18 This driver provides kernel-side support for the Random Number 21 This driver provides kernel-side support for the Random Number
19 Generator hardware found on Intel i8xx-based motherboards. 22 Generator hardware found on Intel i8xx-based motherboards.
@@ -26,7 +29,7 @@ config HW_RANDOM_INTEL
26config HW_RANDOM_AMD 29config HW_RANDOM_AMD
27 tristate "AMD HW Random Number Generator support" 30 tristate "AMD HW Random Number Generator support"
28 depends on HW_RANDOM && X86 && PCI 31 depends on HW_RANDOM && X86 && PCI
29 default y 32 default HW_RANDOM
30 ---help--- 33 ---help---
31 This driver provides kernel-side support for the Random Number 34 This driver provides kernel-side support for the Random Number
32 Generator hardware found on AMD 76x-based motherboards. 35 Generator hardware found on AMD 76x-based motherboards.
@@ -39,7 +42,7 @@ config HW_RANDOM_AMD
39config HW_RANDOM_GEODE 42config HW_RANDOM_GEODE
40 tristate "AMD Geode HW Random Number Generator support" 43 tristate "AMD Geode HW Random Number Generator support"
41 depends on HW_RANDOM && X86 && PCI 44 depends on HW_RANDOM && X86 && PCI
42 default y 45 default HW_RANDOM
43 ---help--- 46 ---help---
44 This driver provides kernel-side support for the Random Number 47 This driver provides kernel-side support for the Random Number
45 Generator hardware found on the AMD Geode LX. 48 Generator hardware found on the AMD Geode LX.
@@ -52,7 +55,7 @@ config HW_RANDOM_GEODE
52config HW_RANDOM_VIA 55config HW_RANDOM_VIA
53 tristate "VIA HW Random Number Generator support" 56 tristate "VIA HW Random Number Generator support"
54 depends on HW_RANDOM && X86_32 57 depends on HW_RANDOM && X86_32
55 default y 58 default HW_RANDOM
56 ---help--- 59 ---help---
57 This driver provides kernel-side support for the Random Number 60 This driver provides kernel-side support for the Random Number
58 Generator hardware found on VIA based motherboards. 61 Generator hardware found on VIA based motherboards.
@@ -65,7 +68,7 @@ config HW_RANDOM_VIA
65config HW_RANDOM_IXP4XX 68config HW_RANDOM_IXP4XX
66 tristate "Intel IXP4xx NPU HW Random Number Generator support" 69 tristate "Intel IXP4xx NPU HW Random Number Generator support"
67 depends on HW_RANDOM && ARCH_IXP4XX 70 depends on HW_RANDOM && ARCH_IXP4XX
68 default y 71 default HW_RANDOM
69 ---help--- 72 ---help---
70 This driver provides kernel-side support for the Random 73 This driver provides kernel-side support for the Random
71 Number Generator hardware found on the Intel IXP4xx NPU. 74 Number Generator hardware found on the Intel IXP4xx NPU.
@@ -78,7 +81,7 @@ config HW_RANDOM_IXP4XX
78config HW_RANDOM_OMAP 81config HW_RANDOM_OMAP
79 tristate "OMAP Random Number Generator support" 82 tristate "OMAP Random Number Generator support"
80 depends on HW_RANDOM && (ARCH_OMAP16XX || ARCH_OMAP24XX) 83 depends on HW_RANDOM && (ARCH_OMAP16XX || ARCH_OMAP24XX)
81 default y 84 default HW_RANDOM
82 ---help--- 85 ---help---
83 This driver provides kernel-side support for the Random Number 86 This driver provides kernel-side support for the Random Number
84 Generator hardware found on OMAP16xx and OMAP24xx multimedia 87 Generator hardware found on OMAP16xx and OMAP24xx multimedia
diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile
index e263ae96f940..c41fa19454e3 100644
--- a/drivers/char/hw_random/Makefile
+++ b/drivers/char/hw_random/Makefile
@@ -2,7 +2,8 @@
2# Makefile for HW Random Number Generator (RNG) device drivers. 2# Makefile for HW Random Number Generator (RNG) device drivers.
3# 3#
4 4
5obj-$(CONFIG_HW_RANDOM) += core.o 5obj-$(CONFIG_HW_RANDOM) += rng-core.o
6rng-core-y := core.o
6obj-$(CONFIG_HW_RANDOM_INTEL) += intel-rng.o 7obj-$(CONFIG_HW_RANDOM_INTEL) += intel-rng.o
7obj-$(CONFIG_HW_RANDOM_AMD) += amd-rng.o 8obj-$(CONFIG_HW_RANDOM_AMD) += amd-rng.o
8obj-$(CONFIG_HW_RANDOM_GEODE) += geode-rng.o 9obj-$(CONFIG_HW_RANDOM_GEODE) += geode-rng.o
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 154a81d328c1..26a860adcb38 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -36,6 +36,7 @@
36#include <linux/module.h> 36#include <linux/module.h>
37#include <linux/kernel.h> 37#include <linux/kernel.h>
38#include <linux/fs.h> 38#include <linux/fs.h>
39#include <linux/sched.h>
39#include <linux/init.h> 40#include <linux/init.h>
40#include <linux/miscdevice.h> 41#include <linux/miscdevice.h>
41#include <linux/delay.h> 42#include <linux/delay.h>
@@ -162,7 +163,8 @@ static struct miscdevice rng_miscdev = {
162}; 163};
163 164
164 165
165static ssize_t hwrng_attr_current_store(struct class_device *class, 166static ssize_t hwrng_attr_current_store(struct device *dev,
167 struct device_attribute *attr,
166 const char *buf, size_t len) 168 const char *buf, size_t len)
167{ 169{
168 int err; 170 int err;
@@ -192,7 +194,8 @@ static ssize_t hwrng_attr_current_store(struct class_device *class,
192 return err ? : len; 194 return err ? : len;
193} 195}
194 196
195static ssize_t hwrng_attr_current_show(struct class_device *class, 197static ssize_t hwrng_attr_current_show(struct device *dev,
198 struct device_attribute *attr,
196 char *buf) 199 char *buf)
197{ 200{
198 int err; 201 int err;
@@ -210,7 +213,8 @@ static ssize_t hwrng_attr_current_show(struct class_device *class,
210 return ret; 213 return ret;
211} 214}
212 215
213static ssize_t hwrng_attr_available_show(struct class_device *class, 216static ssize_t hwrng_attr_available_show(struct device *dev,
217 struct device_attribute *attr,
214 char *buf) 218 char *buf)
215{ 219{
216 int err; 220 int err;
@@ -234,20 +238,18 @@ static ssize_t hwrng_attr_available_show(struct class_device *class,
234 return ret; 238 return ret;
235} 239}
236 240
237static CLASS_DEVICE_ATTR(rng_current, S_IRUGO | S_IWUSR, 241static DEVICE_ATTR(rng_current, S_IRUGO | S_IWUSR,
238 hwrng_attr_current_show, 242 hwrng_attr_current_show,
239 hwrng_attr_current_store); 243 hwrng_attr_current_store);
240static CLASS_DEVICE_ATTR(rng_available, S_IRUGO, 244static DEVICE_ATTR(rng_available, S_IRUGO,
241 hwrng_attr_available_show, 245 hwrng_attr_available_show,
242 NULL); 246 NULL);
243 247
244 248
245static void unregister_miscdev(void) 249static void unregister_miscdev(void)
246{ 250{
247 class_device_remove_file(rng_miscdev.class, 251 device_remove_file(rng_miscdev.this_device, &dev_attr_rng_available);
248 &class_device_attr_rng_available); 252 device_remove_file(rng_miscdev.this_device, &dev_attr_rng_current);
249 class_device_remove_file(rng_miscdev.class,
250 &class_device_attr_rng_current);
251 misc_deregister(&rng_miscdev); 253 misc_deregister(&rng_miscdev);
252} 254}
253 255
@@ -258,20 +260,19 @@ static int register_miscdev(void)
258 err = misc_register(&rng_miscdev); 260 err = misc_register(&rng_miscdev);
259 if (err) 261 if (err)
260 goto out; 262 goto out;
261 err = class_device_create_file(rng_miscdev.class, 263 err = device_create_file(rng_miscdev.this_device,
262 &class_device_attr_rng_current); 264 &dev_attr_rng_current);
263 if (err) 265 if (err)
264 goto err_misc_dereg; 266 goto err_misc_dereg;
265 err = class_device_create_file(rng_miscdev.class, 267 err = device_create_file(rng_miscdev.this_device,
266 &class_device_attr_rng_available); 268 &dev_attr_rng_available);
267 if (err) 269 if (err)
268 goto err_remove_current; 270 goto err_remove_current;
269out: 271out:
270 return err; 272 return err;
271 273
272err_remove_current: 274err_remove_current:
273 class_device_remove_file(rng_miscdev.class, 275 device_remove_file(rng_miscdev.this_device, &dev_attr_rng_current);
274 &class_device_attr_rng_current);
275err_misc_dereg: 276err_misc_dereg:
276 misc_deregister(&rng_miscdev); 277 misc_deregister(&rng_miscdev);
277 goto out; 278 goto out;
diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
index ccd7e7102234..8efbc9c0e545 100644
--- a/drivers/char/hw_random/intel-rng.c
+++ b/drivers/char/hw_random/intel-rng.c
@@ -50,6 +50,43 @@
50#define INTEL_RNG_ADDR_LEN 3 50#define INTEL_RNG_ADDR_LEN 3
51 51
52/* 52/*
53 * LPC bridge PCI config space registers
54 */
55#define FWH_DEC_EN1_REG_OLD 0xe3
56#define FWH_DEC_EN1_REG_NEW 0xd9 /* high byte of 16-bit register */
57#define FWH_F8_EN_MASK 0x80
58
59#define BIOS_CNTL_REG_OLD 0x4e
60#define BIOS_CNTL_REG_NEW 0xdc
61#define BIOS_CNTL_WRITE_ENABLE_MASK 0x01
62#define BIOS_CNTL_LOCK_ENABLE_MASK 0x02
63
64/*
65 * Magic address at which Intel Firmware Hubs get accessed
66 */
67#define INTEL_FWH_ADDR 0xffff0000
68#define INTEL_FWH_ADDR_LEN 2
69
70/*
71 * Intel Firmware Hub command codes (write to any address inside the device)
72 */
73#define INTEL_FWH_RESET_CMD 0xff /* aka READ_ARRAY */
74#define INTEL_FWH_READ_ID_CMD 0x90
75
76/*
77 * Intel Firmware Hub Read ID command result addresses
78 */
79#define INTEL_FWH_MANUFACTURER_CODE_ADDRESS 0x000000
80#define INTEL_FWH_DEVICE_CODE_ADDRESS 0x000001
81
82/*
83 * Intel Firmware Hub Read ID command result values
84 */
85#define INTEL_FWH_MANUFACTURER_CODE 0x89
86#define INTEL_FWH_DEVICE_CODE_8M 0xac
87#define INTEL_FWH_DEVICE_CODE_4M 0xad
88
89/*
53 * Data for PCI driver interface 90 * Data for PCI driver interface
54 * 91 *
55 * This data only exists for exporting the supported 92 * This data only exists for exporting the supported
@@ -58,12 +95,50 @@
58 * want to register another driver on the same PCI id. 95 * want to register another driver on the same PCI id.
59 */ 96 */
60static const struct pci_device_id pci_tbl[] = { 97static const struct pci_device_id pci_tbl[] = {
61 { 0x8086, 0x2418, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 98/* AA
62 { 0x8086, 0x2428, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 99 { 0x8086, 0x2418, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
63 { 0x8086, 0x2430, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 100 { 0x8086, 0x2410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* AA */
64 { 0x8086, 0x2448, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 101/* AB
65 { 0x8086, 0x244e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 102 { 0x8086, 0x2428, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
66 { 0x8086, 0x245e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 103 { 0x8086, 0x2420, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* AB */
104/* ??
105 { 0x8086, 0x2430, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
106/* BAM, CAM, DBM, FBM, GxM
107 { 0x8086, 0x2448, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
108 { 0x8086, 0x244c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* BAM */
109 { 0x8086, 0x248c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CAM */
110 { 0x8086, 0x24cc, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* DBM */
111 { 0x8086, 0x2641, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* FBM */
112 { 0x8086, 0x27b9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* GxM */
113 { 0x8086, 0x27bd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* GxM DH */
114/* BA, CA, DB, Ex, 6300, Fx, 631x/632x, Gx
115 { 0x8086, 0x244e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
116 { 0x8086, 0x2440, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* BA */
117 { 0x8086, 0x2480, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CA */
118 { 0x8086, 0x24c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* DB */
119 { 0x8086, 0x24d0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Ex */
120 { 0x8086, 0x25a1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 6300 */
121 { 0x8086, 0x2640, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Fx */
122 { 0x8086, 0x2670, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
123 { 0x8086, 0x2671, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
124 { 0x8086, 0x2672, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
125 { 0x8086, 0x2673, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
126 { 0x8086, 0x2674, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
127 { 0x8086, 0x2675, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
128 { 0x8086, 0x2676, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
129 { 0x8086, 0x2677, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
130 { 0x8086, 0x2678, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
131 { 0x8086, 0x2679, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
132 { 0x8086, 0x267a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
133 { 0x8086, 0x267b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
134 { 0x8086, 0x267c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
135 { 0x8086, 0x267d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
136 { 0x8086, 0x267e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
137 { 0x8086, 0x267f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
138 { 0x8086, 0x27b8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Gx */
139/* E
140 { 0x8086, 0x245e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
141 { 0x8086, 0x2450, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* E */
67 { 0, }, /* terminate list */ 142 { 0, }, /* terminate list */
68}; 143};
69MODULE_DEVICE_TABLE(pci, pci_tbl); 144MODULE_DEVICE_TABLE(pci, pci_tbl);
@@ -138,22 +213,115 @@ static struct hwrng intel_rng = {
138}; 213};
139 214
140 215
216#ifdef CONFIG_SMP
217static char __initdata waitflag;
218
219static void __init intel_init_wait(void *unused)
220{
221 while (waitflag)
222 cpu_relax();
223}
224#endif
225
141static int __init mod_init(void) 226static int __init mod_init(void)
142{ 227{
143 int err = -ENODEV; 228 int err = -ENODEV;
229 unsigned i;
230 struct pci_dev *dev = NULL;
144 void __iomem *mem; 231 void __iomem *mem;
145 u8 hw_status; 232 unsigned long flags;
233 u8 bios_cntl_off, fwh_dec_en1_off;
234 u8 bios_cntl_val = 0xff, fwh_dec_en1_val = 0xff;
235 u8 hw_status, mfc, dvc;
146 236
147 if (!pci_dev_present(pci_tbl)) 237 for (i = 0; !dev && pci_tbl[i].vendor; ++i)
238 dev = pci_get_device(pci_tbl[i].vendor, pci_tbl[i].device, NULL);
239
240 if (!dev)
148 goto out; /* Device not found. */ 241 goto out; /* Device not found. */
149 242
243 /* Check for Intel 82802 */
244 if (dev->device < 0x2640) {
245 fwh_dec_en1_off = FWH_DEC_EN1_REG_OLD;
246 bios_cntl_off = BIOS_CNTL_REG_OLD;
247 } else {
248 fwh_dec_en1_off = FWH_DEC_EN1_REG_NEW;
249 bios_cntl_off = BIOS_CNTL_REG_NEW;
250 }
251
252 pci_read_config_byte(dev, fwh_dec_en1_off, &fwh_dec_en1_val);
253 pci_read_config_byte(dev, bios_cntl_off, &bios_cntl_val);
254
255 mem = ioremap_nocache(INTEL_FWH_ADDR, INTEL_FWH_ADDR_LEN);
256 if (mem == NULL) {
257 pci_dev_put(dev);
258 err = -EBUSY;
259 goto out;
260 }
261
262 /*
263 * Since the BIOS code/data is going to disappear from its normal
264 * location with the Read ID command, all activity on the system
265 * must be stopped until the state is back to normal.
266 */
267#ifdef CONFIG_SMP
268 set_mb(waitflag, 1);
269 if (smp_call_function(intel_init_wait, NULL, 1, 0) != 0) {
270 set_mb(waitflag, 0);
271 pci_dev_put(dev);
272 printk(KERN_ERR PFX "cannot run on all processors\n");
273 err = -EAGAIN;
274 goto err_unmap;
275 }
276#endif
277 local_irq_save(flags);
278
279 if (!(fwh_dec_en1_val & FWH_F8_EN_MASK))
280 pci_write_config_byte(dev,
281 fwh_dec_en1_off,
282 fwh_dec_en1_val | FWH_F8_EN_MASK);
283 if (!(bios_cntl_val &
284 (BIOS_CNTL_LOCK_ENABLE_MASK|BIOS_CNTL_WRITE_ENABLE_MASK)))
285 pci_write_config_byte(dev,
286 bios_cntl_off,
287 bios_cntl_val | BIOS_CNTL_WRITE_ENABLE_MASK);
288
289 writeb(INTEL_FWH_RESET_CMD, mem);
290 writeb(INTEL_FWH_READ_ID_CMD, mem);
291 mfc = readb(mem + INTEL_FWH_MANUFACTURER_CODE_ADDRESS);
292 dvc = readb(mem + INTEL_FWH_DEVICE_CODE_ADDRESS);
293 writeb(INTEL_FWH_RESET_CMD, mem);
294
295 if (!(bios_cntl_val &
296 (BIOS_CNTL_LOCK_ENABLE_MASK|BIOS_CNTL_WRITE_ENABLE_MASK)))
297 pci_write_config_byte(dev, bios_cntl_off, bios_cntl_val);
298 if (!(fwh_dec_en1_val & FWH_F8_EN_MASK))
299 pci_write_config_byte(dev, fwh_dec_en1_off, fwh_dec_en1_val);
300
301 local_irq_restore(flags);
302#ifdef CONFIG_SMP
303 /* Tell other CPUs to resume. */
304 set_mb(waitflag, 0);
305#endif
306
307 iounmap(mem);
308 pci_dev_put(dev);
309
310 if (mfc != INTEL_FWH_MANUFACTURER_CODE ||
311 (dvc != INTEL_FWH_DEVICE_CODE_8M &&
312 dvc != INTEL_FWH_DEVICE_CODE_4M)) {
313 printk(KERN_ERR PFX "FWH not detected\n");
314 err = -ENODEV;
315 goto out;
316 }
317
150 err = -ENOMEM; 318 err = -ENOMEM;
151 mem = ioremap(INTEL_RNG_ADDR, INTEL_RNG_ADDR_LEN); 319 mem = ioremap(INTEL_RNG_ADDR, INTEL_RNG_ADDR_LEN);
152 if (!mem) 320 if (!mem)
153 goto out; 321 goto out;
154 intel_rng.priv = (unsigned long)mem; 322 intel_rng.priv = (unsigned long)mem;
155 323
156 /* Check for Intel 82802 */ 324 /* Check for Random Number Generator */
157 err = -ENODEV; 325 err = -ENODEV;
158 hw_status = hwstatus_get(mem); 326 hw_status = hwstatus_get(mem);
159 if ((hw_status & INTEL_RNG_PRESENT) == 0) 327 if ((hw_status & INTEL_RNG_PRESENT) == 0)
diff --git a/drivers/char/hw_random/ixp4xx-rng.c b/drivers/char/hw_random/ixp4xx-rng.c
index ef71022423c9..c9caff57db85 100644
--- a/drivers/char/hw_random/ixp4xx-rng.c
+++ b/drivers/char/hw_random/ixp4xx-rng.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * drivers/char/rng/ixp4xx-rng.c 2 * drivers/char/hw_random/ixp4xx-rng.c
3 * 3 *
4 * RNG driver for Intel IXP4xx family of NPUs 4 * RNG driver for Intel IXP4xx family of NPUs
5 * 5 *
@@ -15,7 +15,6 @@
15 */ 15 */
16 16
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/config.h>
19#include <linux/types.h> 18#include <linux/types.h>
20#include <linux/module.h> 19#include <linux/module.h>
21#include <linux/moduleparam.h> 20#include <linux/moduleparam.h>
diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c
index a01d796d1eeb..e13dd1892bfd 100644
--- a/drivers/char/hw_random/omap-rng.c
+++ b/drivers/char/hw_random/omap-rng.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * driver/char/hw_random/omap-rng.c 2 * drivers/char/hw_random/omap-rng.c
3 * 3 *
4 * RNG driver for TI OMAP CPU family 4 * RNG driver for TI OMAP CPU family
5 * 5 *
diff --git a/drivers/char/ip2/i2cmd.h b/drivers/char/ip2/i2cmd.h
index baa4e721b758..29277ec6b8ed 100644
--- a/drivers/char/ip2/i2cmd.h
+++ b/drivers/char/ip2/i2cmd.h
@@ -367,11 +367,6 @@ static UCHAR cc02[];
367#define CSE_NULL 3 // Replace with a null 367#define CSE_NULL 3 // Replace with a null
368#define CSE_MARK 4 // Replace with a 3-character sequence (as Unix) 368#define CSE_MARK 4 // Replace with a 3-character sequence (as Unix)
369 369
370#define CMD_SET_REPLACEMENT(arg,ch) \
371 (((cmdSyntaxPtr)(ct36a))->cmd[1] = (arg), \
372 (((cmdSyntaxPtr)(ct36a))->cmd[2] = (ch), \
373 (cmdSyntaxPtr)(ct36a))
374
375#define CSE_REPLACE 0x8 // Replace the errored character with the 370#define CSE_REPLACE 0x8 // Replace the errored character with the
376 // replacement character defined here 371 // replacement character defined here
377 372
diff --git a/drivers/char/ip2/i2lib.c b/drivers/char/ip2/i2lib.c
index fc944d375be7..78045767ec33 100644
--- a/drivers/char/ip2/i2lib.c
+++ b/drivers/char/ip2/i2lib.c
@@ -84,8 +84,8 @@ static void iiSendPendingMail(i2eBordStrPtr);
84static void serviceOutgoingFifo(i2eBordStrPtr); 84static void serviceOutgoingFifo(i2eBordStrPtr);
85 85
86// Functions defined in ip2.c as part of interrupt handling 86// Functions defined in ip2.c as part of interrupt handling
87static void do_input(void *); 87static void do_input(struct work_struct *);
88static void do_status(void *); 88static void do_status(struct work_struct *);
89 89
90//*************** 90//***************
91//* Debug Data * 91//* Debug Data *
@@ -331,8 +331,8 @@ i2InitChannels ( i2eBordStrPtr pB, int nChannels, i2ChanStrPtr pCh)
331 pCh->ClosingWaitTime = 30*HZ; 331 pCh->ClosingWaitTime = 30*HZ;
332 332
333 // Initialize task queue objects 333 // Initialize task queue objects
334 INIT_WORK(&pCh->tqueue_input, do_input, pCh); 334 INIT_WORK(&pCh->tqueue_input, do_input);
335 INIT_WORK(&pCh->tqueue_status, do_status, pCh); 335 INIT_WORK(&pCh->tqueue_status, do_status);
336 336
337#ifdef IP2DEBUG_TRACE 337#ifdef IP2DEBUG_TRACE
338 pCh->trace = ip2trace; 338 pCh->trace = ip2trace;
@@ -1007,7 +1007,7 @@ i2InputAvailable(i2ChanStrPtr pCh)
1007// applications that one cannot break out of. 1007// applications that one cannot break out of.
1008//****************************************************************************** 1008//******************************************************************************
1009static int 1009static int
1010i2Output(i2ChanStrPtr pCh, const char *pSource, int count, int user ) 1010i2Output(i2ChanStrPtr pCh, const char *pSource, int count)
1011{ 1011{
1012 i2eBordStrPtr pB; 1012 i2eBordStrPtr pB;
1013 unsigned char *pInsert; 1013 unsigned char *pInsert;
@@ -1016,11 +1016,10 @@ i2Output(i2ChanStrPtr pCh, const char *pSource, int count, int user )
1016 unsigned short channel; 1016 unsigned short channel;
1017 unsigned short stuffIndex; 1017 unsigned short stuffIndex;
1018 unsigned long flags; 1018 unsigned long flags;
1019 int rc = 0;
1020 1019
1021 int bailout = 10; 1020 int bailout = 10;
1022 1021
1023 ip2trace (CHANN, ITRC_OUTPUT, ITRC_ENTER, 2, count, user ); 1022 ip2trace (CHANN, ITRC_OUTPUT, ITRC_ENTER, 2, count, 0 );
1024 1023
1025 // Ensure channel structure seems real 1024 // Ensure channel structure seems real
1026 if ( !i2Validate ( pCh ) ) 1025 if ( !i2Validate ( pCh ) )
@@ -1087,12 +1086,7 @@ i2Output(i2ChanStrPtr pCh, const char *pSource, int count, int user )
1087 DATA_COUNT_OF(pInsert) = amountToMove; 1086 DATA_COUNT_OF(pInsert) = amountToMove;
1088 1087
1089 // Move the data 1088 // Move the data
1090 if ( user ) { 1089 memcpy( (char*)(DATA_OF(pInsert)), pSource, amountToMove );
1091 rc = copy_from_user((char*)(DATA_OF(pInsert)), pSource,
1092 amountToMove );
1093 } else {
1094 memcpy( (char*)(DATA_OF(pInsert)), pSource, amountToMove );
1095 }
1096 // Adjust pointers and indices 1090 // Adjust pointers and indices
1097 pSource += amountToMove; 1091 pSource += amountToMove;
1098 pCh->Obuf_char_count += amountToMove; 1092 pCh->Obuf_char_count += amountToMove;
@@ -1578,7 +1572,7 @@ i2StripFifo(i2eBordStrPtr pB)
1578#ifdef USE_IQ 1572#ifdef USE_IQ
1579 schedule_work(&pCh->tqueue_input); 1573 schedule_work(&pCh->tqueue_input);
1580#else 1574#else
1581 do_input(pCh); 1575 do_input(&pCh->tqueue_input);
1582#endif 1576#endif
1583 1577
1584 // Note we do not need to maintain any flow-control credits at this 1578 // Note we do not need to maintain any flow-control credits at this
@@ -1815,7 +1809,7 @@ i2StripFifo(i2eBordStrPtr pB)
1815#ifdef USE_IQ 1809#ifdef USE_IQ
1816 schedule_work(&pCh->tqueue_status); 1810 schedule_work(&pCh->tqueue_status);
1817#else 1811#else
1818 do_status(pCh); 1812 do_status(&pCh->tqueue_status);
1819#endif 1813#endif
1820 } 1814 }
1821 } 1815 }
diff --git a/drivers/char/ip2/i2lib.h b/drivers/char/ip2/i2lib.h
index 952e113ccd8a..e559e9bac06d 100644
--- a/drivers/char/ip2/i2lib.h
+++ b/drivers/char/ip2/i2lib.h
@@ -332,7 +332,7 @@ static int i2QueueCommands(int, i2ChanStrPtr, int, int, cmdSyntaxPtr,...);
332static int i2GetStatus(i2ChanStrPtr, int); 332static int i2GetStatus(i2ChanStrPtr, int);
333static int i2Input(i2ChanStrPtr); 333static int i2Input(i2ChanStrPtr);
334static int i2InputFlush(i2ChanStrPtr); 334static int i2InputFlush(i2ChanStrPtr);
335static int i2Output(i2ChanStrPtr, const char *, int, int); 335static int i2Output(i2ChanStrPtr, const char *, int);
336static int i2OutputFree(i2ChanStrPtr); 336static int i2OutputFree(i2ChanStrPtr);
337static int i2ServiceBoard(i2eBordStrPtr); 337static int i2ServiceBoard(i2eBordStrPtr);
338static void i2DrainOutput(i2ChanStrPtr, int); 338static void i2DrainOutput(i2ChanStrPtr, int);
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c
index 7907ae88c2f4..7c70310a49b5 100644
--- a/drivers/char/ip2/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -177,7 +177,7 @@ static int ip2_write_room(PTTY);
177static int ip2_chars_in_buf(PTTY); 177static int ip2_chars_in_buf(PTTY);
178static void ip2_flush_buffer(PTTY); 178static void ip2_flush_buffer(PTTY);
179static int ip2_ioctl(PTTY, struct file *, UINT, ULONG); 179static int ip2_ioctl(PTTY, struct file *, UINT, ULONG);
180static void ip2_set_termios(PTTY, struct termios *); 180static void ip2_set_termios(PTTY, struct ktermios *);
181static void ip2_set_line_discipline(PTTY); 181static void ip2_set_line_discipline(PTTY);
182static void ip2_throttle(PTTY); 182static void ip2_throttle(PTTY);
183static void ip2_unthrottle(PTTY); 183static void ip2_unthrottle(PTTY);
@@ -189,16 +189,16 @@ static int ip2_tiocmset(struct tty_struct *tty, struct file *file,
189 unsigned int set, unsigned int clear); 189 unsigned int set, unsigned int clear);
190 190
191static void set_irq(int, int); 191static void set_irq(int, int);
192static void ip2_interrupt_bh(i2eBordStrPtr pB); 192static void ip2_interrupt_bh(struct work_struct *work);
193static irqreturn_t ip2_interrupt(int irq, void *dev_id, struct pt_regs * regs); 193static irqreturn_t ip2_interrupt(int irq, void *dev_id);
194static void ip2_poll(unsigned long arg); 194static void ip2_poll(unsigned long arg);
195static inline void service_all_boards(void); 195static inline void service_all_boards(void);
196static void do_input(void *p); 196static void do_input(struct work_struct *);
197static void do_status(void *p); 197static void do_status(struct work_struct *);
198 198
199static void ip2_wait_until_sent(PTTY,int); 199static void ip2_wait_until_sent(PTTY,int);
200 200
201static void set_params (i2ChanStrPtr, struct termios *); 201static void set_params (i2ChanStrPtr, struct ktermios *);
202static int get_serial_info(i2ChanStrPtr, struct serial_struct __user *); 202static int get_serial_info(i2ChanStrPtr, struct serial_struct __user *);
203static int set_serial_info(i2ChanStrPtr, struct serial_struct __user *); 203static int set_serial_info(i2ChanStrPtr, struct serial_struct __user *);
204 204
@@ -436,6 +436,7 @@ cleanup_module(void)
436#ifdef CONFIG_PCI 436#ifdef CONFIG_PCI
437 if (ip2config.type[i] == PCI && ip2config.pci_dev[i]) { 437 if (ip2config.type[i] == PCI && ip2config.pci_dev[i]) {
438 pci_disable_device(ip2config.pci_dev[i]); 438 pci_disable_device(ip2config.pci_dev[i]);
439 pci_dev_put(ip2config.pci_dev[i]);
439 ip2config.pci_dev[i] = NULL; 440 ip2config.pci_dev[i] = NULL;
440 } 441 }
441#endif 442#endif
@@ -457,7 +458,7 @@ cleanup_module(void)
457} 458}
458#endif /* MODULE */ 459#endif /* MODULE */
459 460
460static struct tty_operations ip2_ops = { 461static const struct tty_operations ip2_ops = {
461 .open = ip2_open, 462 .open = ip2_open,
462 .close = ip2_close, 463 .close = ip2_close,
463 .write = ip2_write, 464 .write = ip2_write,
@@ -505,6 +506,7 @@ ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
505 static int loaded; 506 static int loaded;
506 i2eBordStrPtr pB = NULL; 507 i2eBordStrPtr pB = NULL;
507 int rc = -1; 508 int rc = -1;
509 static struct pci_dev *pci_dev_i = NULL;
508 510
509 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_ENTER, 0 ); 511 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_ENTER, 0 );
510 512
@@ -588,8 +590,7 @@ ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
588 case PCI: 590 case PCI:
589#ifdef CONFIG_PCI 591#ifdef CONFIG_PCI
590 { 592 {
591 struct pci_dev *pci_dev_i = NULL; 593 pci_dev_i = pci_get_device(PCI_VENDOR_ID_COMPUTONE,
592 pci_dev_i = pci_find_device(PCI_VENDOR_ID_COMPUTONE,
593 PCI_DEVICE_ID_COMPUTONE_IP2EX, pci_dev_i); 594 PCI_DEVICE_ID_COMPUTONE_IP2EX, pci_dev_i);
594 if (pci_dev_i != NULL) { 595 if (pci_dev_i != NULL) {
595 unsigned int addr; 596 unsigned int addr;
@@ -600,7 +601,7 @@ ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
600 break; 601 break;
601 } 602 }
602 ip2config.type[i] = PCI; 603 ip2config.type[i] = PCI;
603 ip2config.pci_dev[i] = pci_dev_i; 604 ip2config.pci_dev[i] = pci_dev_get(pci_dev_i);
604 status = 605 status =
605 pci_read_config_dword(pci_dev_i, PCI_BASE_ADDRESS_1, &addr); 606 pci_read_config_dword(pci_dev_i, PCI_BASE_ADDRESS_1, &addr);
606 if ( addr & 1 ) { 607 if ( addr & 1 ) {
@@ -641,6 +642,9 @@ ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
641 break; 642 break;
642 } /* switch */ 643 } /* switch */
643 } /* for */ 644 } /* for */
645 if (pci_dev_i)
646 pci_dev_put(pci_dev_i);
647
644 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) { 648 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
645 if ( ip2config.addr[i] ) { 649 if ( ip2config.addr[i] ) {
646 pB = kmalloc( sizeof(i2eBordStr), GFP_KERNEL); 650 pB = kmalloc( sizeof(i2eBordStr), GFP_KERNEL);
@@ -775,8 +779,6 @@ retry:
775 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_RETURN, 0 ); 779 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_RETURN, 0 );
776 goto out; 780 goto out;
777 781
778out_class:
779 class_destroy(ip2_class);
780out_chrdev: 782out_chrdev:
781 unregister_chrdev(IP2_IPL_MAJOR, "ip2"); 783 unregister_chrdev(IP2_IPL_MAJOR, "ip2");
782out: 784out:
@@ -916,7 +918,7 @@ ip2_init_board( int boardnum )
916 pCh++; 918 pCh++;
917 } 919 }
918ex_exit: 920ex_exit:
919 INIT_WORK(&pB->tqueue_interrupt, (void(*)(void*)) ip2_interrupt_bh, pB); 921 INIT_WORK(&pB->tqueue_interrupt, ip2_interrupt_bh);
920 return; 922 return;
921 923
922err_release_region: 924err_release_region:
@@ -1123,8 +1125,8 @@ service_all_boards(void)
1123 1125
1124 1126
1125/******************************************************************************/ 1127/******************************************************************************/
1126/* Function: ip2_interrupt_bh(pB) */ 1128/* Function: ip2_interrupt_bh(work) */
1127/* Parameters: pB - pointer to the board structure */ 1129/* Parameters: work - pointer to the board structure */
1128/* Returns: Nothing */ 1130/* Returns: Nothing */
1129/* */ 1131/* */
1130/* Description: */ 1132/* Description: */
@@ -1133,8 +1135,9 @@ service_all_boards(void)
1133/* */ 1135/* */
1134/******************************************************************************/ 1136/******************************************************************************/
1135static void 1137static void
1136ip2_interrupt_bh(i2eBordStrPtr pB) 1138ip2_interrupt_bh(struct work_struct *work)
1137{ 1139{
1140 i2eBordStrPtr pB = container_of(work, i2eBordStr, tqueue_interrupt);
1138// pB better well be set or we have a problem! We can only get 1141// pB better well be set or we have a problem! We can only get
1139// here from the IMMEDIATE queue. Here, we process the boards. 1142// here from the IMMEDIATE queue. Here, we process the boards.
1140// Checking pB doesn't cost much and it saves us from the sanity checkers. 1143// Checking pB doesn't cost much and it saves us from the sanity checkers.
@@ -1152,10 +1155,9 @@ ip2_interrupt_bh(i2eBordStrPtr pB)
1152 1155
1153 1156
1154/******************************************************************************/ 1157/******************************************************************************/
1155/* Function: ip2_interrupt(int irq, void *dev_id, struct pt_regs * regs) */ 1158/* Function: ip2_interrupt(int irq, void *dev_id) */
1156/* Parameters: irq - interrupt number */ 1159/* Parameters: irq - interrupt number */
1157/* pointer to optional device ID structure */ 1160/* pointer to optional device ID structure */
1158/* pointer to register structure */
1159/* Returns: Nothing */ 1161/* Returns: Nothing */
1160/* */ 1162/* */
1161/* Description: */ 1163/* Description: */
@@ -1171,7 +1173,7 @@ ip2_interrupt_bh(i2eBordStrPtr pB)
1171/* */ 1173/* */
1172/******************************************************************************/ 1174/******************************************************************************/
1173static irqreturn_t 1175static irqreturn_t
1174ip2_interrupt(int irq, void *dev_id, struct pt_regs * regs) 1176ip2_interrupt(int irq, void *dev_id)
1175{ 1177{
1176 int i; 1178 int i;
1177 i2eBordStrPtr pB; 1179 i2eBordStrPtr pB;
@@ -1235,7 +1237,7 @@ ip2_poll(unsigned long arg)
1235 // Just polled boards, IRQ = 0 will hit all non-interrupt boards. 1237 // Just polled boards, IRQ = 0 will hit all non-interrupt boards.
1236 // It will NOT poll boards handled by hard interrupts. 1238 // It will NOT poll boards handled by hard interrupts.
1237 // The issue of queued BH interrups is handled in ip2_interrupt(). 1239 // The issue of queued BH interrups is handled in ip2_interrupt().
1238 ip2_interrupt(0, NULL, NULL); 1240 ip2_interrupt(0, NULL);
1239 1241
1240 PollTimer.expires = POLL_TIMEOUT; 1242 PollTimer.expires = POLL_TIMEOUT;
1241 add_timer( &PollTimer ); 1243 add_timer( &PollTimer );
@@ -1244,9 +1246,9 @@ ip2_poll(unsigned long arg)
1244 ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 ); 1246 ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
1245} 1247}
1246 1248
1247static void do_input(void *p) 1249static void do_input(struct work_struct *work)
1248{ 1250{
1249 i2ChanStrPtr pCh = p; 1251 i2ChanStrPtr pCh = container_of(work, i2ChanStr, tqueue_input);
1250 unsigned long flags; 1252 unsigned long flags;
1251 1253
1252 ip2trace(CHANN, ITRC_INPUT, 21, 0 ); 1254 ip2trace(CHANN, ITRC_INPUT, 21, 0 );
@@ -1278,9 +1280,9 @@ static inline void isig(int sig, struct tty_struct *tty, int flush)
1278 } 1280 }
1279} 1281}
1280 1282
1281static void do_status(void *p) 1283static void do_status(struct work_struct *work)
1282{ 1284{
1283 i2ChanStrPtr pCh = p; 1285 i2ChanStrPtr pCh = container_of(work, i2ChanStr, tqueue_status);
1284 int status; 1286 int status;
1285 1287
1286 status = i2GetStatus( pCh, (I2_BRK|I2_PAR|I2_FRA|I2_OVR) ); 1288 status = i2GetStatus( pCh, (I2_BRK|I2_PAR|I2_FRA|I2_OVR) );
@@ -1703,7 +1705,7 @@ ip2_write( PTTY tty, const unsigned char *pData, int count)
1703 1705
1704 /* This is the actual move bit. Make sure it does what we need!!!!! */ 1706 /* This is the actual move bit. Make sure it does what we need!!!!! */
1705 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags); 1707 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1706 bytesSent = i2Output( pCh, pData, count, 0 ); 1708 bytesSent = i2Output( pCh, pData, count);
1707 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags); 1709 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1708 1710
1709 ip2trace (CHANN, ITRC_WRITE, ITRC_RETURN, 1, bytesSent ); 1711 ip2trace (CHANN, ITRC_WRITE, ITRC_RETURN, 1, bytesSent );
@@ -1763,7 +1765,7 @@ ip2_flush_chars( PTTY tty )
1763 // 1765 //
1764 // We may need to restart i2Output if it does not fullfill this request 1766 // We may need to restart i2Output if it does not fullfill this request
1765 // 1767 //
1766 strip = i2Output( pCh, pCh->Pbuf, pCh->Pbuf_stuff, 0 ); 1768 strip = i2Output( pCh, pCh->Pbuf, pCh->Pbuf_stuff);
1767 if ( strip != pCh->Pbuf_stuff ) { 1769 if ( strip != pCh->Pbuf_stuff ) {
1768 memmove( pCh->Pbuf, &pCh->Pbuf[strip], pCh->Pbuf_stuff - strip ); 1770 memmove( pCh->Pbuf, &pCh->Pbuf[strip], pCh->Pbuf_stuff - strip );
1769 } 1771 }
@@ -2396,7 +2398,7 @@ set_serial_info( i2ChanStrPtr pCh, struct serial_struct __user *new_info )
2396/* */ 2398/* */
2397/******************************************************************************/ 2399/******************************************************************************/
2398static void 2400static void
2399ip2_set_termios( PTTY tty, struct termios *old_termios ) 2401ip2_set_termios( PTTY tty, struct ktermios *old_termios )
2400{ 2402{
2401 i2ChanStrPtr pCh = (i2ChanStrPtr)tty->driver_data; 2403 i2ChanStrPtr pCh = (i2ChanStrPtr)tty->driver_data;
2402 2404
@@ -2438,11 +2440,11 @@ ip2_set_line_discipline ( PTTY tty )
2438/* change. */ 2440/* change. */
2439/******************************************************************************/ 2441/******************************************************************************/
2440static void 2442static void
2441set_params( i2ChanStrPtr pCh, struct termios *o_tios ) 2443set_params( i2ChanStrPtr pCh, struct ktermios *o_tios )
2442{ 2444{
2443 tcflag_t cflag, iflag, lflag; 2445 tcflag_t cflag, iflag, lflag;
2444 char stop_char, start_char; 2446 char stop_char, start_char;
2445 struct termios dummy; 2447 struct ktermios dummy;
2446 2448
2447 lflag = pCh->pTTY->termios->c_lflag; 2449 lflag = pCh->pTTY->termios->c_lflag;
2448 cflag = pCh->pTTY->termios->c_cflag; 2450 cflag = pCh->pTTY->termios->c_cflag;
@@ -2698,7 +2700,7 @@ static
2698ssize_t 2700ssize_t
2699ip2_ipl_read(struct file *pFile, char __user *pData, size_t count, loff_t *off ) 2701ip2_ipl_read(struct file *pFile, char __user *pData, size_t count, loff_t *off )
2700{ 2702{
2701 unsigned int minor = iminor(pFile->f_dentry->d_inode); 2703 unsigned int minor = iminor(pFile->f_path.dentry->d_inode);
2702 int rc = 0; 2704 int rc = 0;
2703 2705
2704#ifdef IP2DEBUG_IPL 2706#ifdef IP2DEBUG_IPL
diff --git a/drivers/char/ipmi/ipmi_bt_sm.c b/drivers/char/ipmi/ipmi_bt_sm.c
index 0030cd8e2e95..e736119b6497 100644
--- a/drivers/char/ipmi/ipmi_bt_sm.c
+++ b/drivers/char/ipmi/ipmi_bt_sm.c
@@ -33,11 +33,15 @@
33#include <linux/ipmi_msgdefs.h> /* for completion codes */ 33#include <linux/ipmi_msgdefs.h> /* for completion codes */
34#include "ipmi_si_sm.h" 34#include "ipmi_si_sm.h"
35 35
36static int bt_debug = 0x00; /* Production value 0, see following flags */ 36#define BT_DEBUG_OFF 0 /* Used in production */
37#define BT_DEBUG_ENABLE 1 /* Generic messages */
38#define BT_DEBUG_MSG 2 /* Prints all request/response buffers */
39#define BT_DEBUG_STATES 4 /* Verbose look at state changes */
40/* BT_DEBUG_OFF must be zero to correspond to the default uninitialized
41 value */
42
43static int bt_debug; /* 0 == BT_DEBUG_OFF */
37 44
38#define BT_DEBUG_ENABLE 1
39#define BT_DEBUG_MSG 2
40#define BT_DEBUG_STATES 4
41module_param(bt_debug, int, 0644); 45module_param(bt_debug, int, 0644);
42MODULE_PARM_DESC(bt_debug, "debug bitmask, 1=enable, 2=messages, 4=states"); 46MODULE_PARM_DESC(bt_debug, "debug bitmask, 1=enable, 2=messages, 4=states");
43 47
@@ -47,38 +51,54 @@ MODULE_PARM_DESC(bt_debug, "debug bitmask, 1=enable, 2=messages, 4=states");
47 Since the Open IPMI architecture is single-message oriented at this 51 Since the Open IPMI architecture is single-message oriented at this
48 stage, the queue depth of BT is of no concern. */ 52 stage, the queue depth of BT is of no concern. */
49 53
50#define BT_NORMAL_TIMEOUT 5000000 /* seconds in microseconds */ 54#define BT_NORMAL_TIMEOUT 5 /* seconds */
51#define BT_RETRY_LIMIT 2 55#define BT_NORMAL_RETRY_LIMIT 2
52#define BT_RESET_DELAY 6000000 /* 6 seconds after warm reset */ 56#define BT_RESET_DELAY 6 /* seconds after warm reset */
57
58/* States are written in chronological order and usually cover
59 multiple rows of the state table discussion in the IPMI spec. */
53 60
54enum bt_states { 61enum bt_states {
55 BT_STATE_IDLE, 62 BT_STATE_IDLE = 0, /* Order is critical in this list */
56 BT_STATE_XACTION_START, 63 BT_STATE_XACTION_START,
57 BT_STATE_WRITE_BYTES, 64 BT_STATE_WRITE_BYTES,
58 BT_STATE_WRITE_END,
59 BT_STATE_WRITE_CONSUME, 65 BT_STATE_WRITE_CONSUME,
60 BT_STATE_B2H_WAIT, 66 BT_STATE_READ_WAIT,
61 BT_STATE_READ_END, 67 BT_STATE_CLEAR_B2H,
62 BT_STATE_RESET1, /* These must come last */ 68 BT_STATE_READ_BYTES,
69 BT_STATE_RESET1, /* These must come last */
63 BT_STATE_RESET2, 70 BT_STATE_RESET2,
64 BT_STATE_RESET3, 71 BT_STATE_RESET3,
65 BT_STATE_RESTART, 72 BT_STATE_RESTART,
66 BT_STATE_HOSED 73 BT_STATE_PRINTME,
74 BT_STATE_CAPABILITIES_BEGIN,
75 BT_STATE_CAPABILITIES_END,
76 BT_STATE_LONG_BUSY /* BT doesn't get hosed :-) */
67}; 77};
68 78
79/* Macros seen at the end of state "case" blocks. They help with legibility
80 and debugging. */
81
82#define BT_STATE_CHANGE(X,Y) { bt->state = X; return Y; }
83
84#define BT_SI_SM_RETURN(Y) { last_printed = BT_STATE_PRINTME; return Y; }
85
69struct si_sm_data { 86struct si_sm_data {
70 enum bt_states state; 87 enum bt_states state;
71 enum bt_states last_state; /* assist printing and resets */
72 unsigned char seq; /* BT sequence number */ 88 unsigned char seq; /* BT sequence number */
73 struct si_sm_io *io; 89 struct si_sm_io *io;
74 unsigned char write_data[IPMI_MAX_MSG_LENGTH]; 90 unsigned char write_data[IPMI_MAX_MSG_LENGTH];
75 int write_count; 91 int write_count;
76 unsigned char read_data[IPMI_MAX_MSG_LENGTH]; 92 unsigned char read_data[IPMI_MAX_MSG_LENGTH];
77 int read_count; 93 int read_count;
78 int truncated; 94 int truncated;
79 long timeout; 95 long timeout; /* microseconds countdown */
80 unsigned int error_retries; /* end of "common" fields */ 96 int error_retries; /* end of "common" fields */
81 int nonzero_status; /* hung BMCs stay all 0 */ 97 int nonzero_status; /* hung BMCs stay all 0 */
98 enum bt_states complete; /* to divert the state machine */
99 int BT_CAP_outreqs;
100 long BT_CAP_req2rsp;
101 int BT_CAP_retries; /* Recommended retries */
82}; 102};
83 103
84#define BT_CLR_WR_PTR 0x01 /* See IPMI 1.5 table 11.6.4 */ 104#define BT_CLR_WR_PTR 0x01 /* See IPMI 1.5 table 11.6.4 */
@@ -111,86 +131,118 @@ struct si_sm_data {
111static char *state2txt(unsigned char state) 131static char *state2txt(unsigned char state)
112{ 132{
113 switch (state) { 133 switch (state) {
114 case BT_STATE_IDLE: return("IDLE"); 134 case BT_STATE_IDLE: return("IDLE");
115 case BT_STATE_XACTION_START: return("XACTION"); 135 case BT_STATE_XACTION_START: return("XACTION");
116 case BT_STATE_WRITE_BYTES: return("WR_BYTES"); 136 case BT_STATE_WRITE_BYTES: return("WR_BYTES");
117 case BT_STATE_WRITE_END: return("WR_END"); 137 case BT_STATE_WRITE_CONSUME: return("WR_CONSUME");
118 case BT_STATE_WRITE_CONSUME: return("WR_CONSUME"); 138 case BT_STATE_READ_WAIT: return("RD_WAIT");
119 case BT_STATE_B2H_WAIT: return("B2H_WAIT"); 139 case BT_STATE_CLEAR_B2H: return("CLEAR_B2H");
120 case BT_STATE_READ_END: return("RD_END"); 140 case BT_STATE_READ_BYTES: return("RD_BYTES");
121 case BT_STATE_RESET1: return("RESET1"); 141 case BT_STATE_RESET1: return("RESET1");
122 case BT_STATE_RESET2: return("RESET2"); 142 case BT_STATE_RESET2: return("RESET2");
123 case BT_STATE_RESET3: return("RESET3"); 143 case BT_STATE_RESET3: return("RESET3");
124 case BT_STATE_RESTART: return("RESTART"); 144 case BT_STATE_RESTART: return("RESTART");
125 case BT_STATE_HOSED: return("HOSED"); 145 case BT_STATE_LONG_BUSY: return("LONG_BUSY");
146 case BT_STATE_CAPABILITIES_BEGIN: return("CAP_BEGIN");
147 case BT_STATE_CAPABILITIES_END: return("CAP_END");
126 } 148 }
127 return("BAD STATE"); 149 return("BAD STATE");
128} 150}
129#define STATE2TXT state2txt(bt->state) 151#define STATE2TXT state2txt(bt->state)
130 152
131static char *status2txt(unsigned char status, char *buf) 153static char *status2txt(unsigned char status)
132{ 154{
155 /*
156 * This cannot be called by two threads at the same time and
157 * the buffer is always consumed immediately, so the static is
158 * safe to use.
159 */
160 static char buf[40];
161
133 strcpy(buf, "[ "); 162 strcpy(buf, "[ ");
134 if (status & BT_B_BUSY) strcat(buf, "B_BUSY "); 163 if (status & BT_B_BUSY)
135 if (status & BT_H_BUSY) strcat(buf, "H_BUSY "); 164 strcat(buf, "B_BUSY ");
136 if (status & BT_OEM0) strcat(buf, "OEM0 "); 165 if (status & BT_H_BUSY)
137 if (status & BT_SMS_ATN) strcat(buf, "SMS "); 166 strcat(buf, "H_BUSY ");
138 if (status & BT_B2H_ATN) strcat(buf, "B2H "); 167 if (status & BT_OEM0)
139 if (status & BT_H2B_ATN) strcat(buf, "H2B "); 168 strcat(buf, "OEM0 ");
169 if (status & BT_SMS_ATN)
170 strcat(buf, "SMS ");
171 if (status & BT_B2H_ATN)
172 strcat(buf, "B2H ");
173 if (status & BT_H2B_ATN)
174 strcat(buf, "H2B ");
140 strcat(buf, "]"); 175 strcat(buf, "]");
141 return buf; 176 return buf;
142} 177}
143#define STATUS2TXT(buf) status2txt(status, buf) 178#define STATUS2TXT status2txt(status)
179
180/* called externally at insmod time, and internally on cleanup */
144 181
145/* This will be called from within this module on a hosed condition */
146#define FIRST_SEQ 0
147static unsigned int bt_init_data(struct si_sm_data *bt, struct si_sm_io *io) 182static unsigned int bt_init_data(struct si_sm_data *bt, struct si_sm_io *io)
148{ 183{
149 bt->state = BT_STATE_IDLE; 184 memset(bt, 0, sizeof(struct si_sm_data));
150 bt->last_state = BT_STATE_IDLE; 185 if (bt->io != io) { /* external: one-time only things */
151 bt->seq = FIRST_SEQ; 186 bt->io = io;
152 bt->io = io; 187 bt->seq = 0;
153 bt->write_count = 0; 188 }
154 bt->read_count = 0; 189 bt->state = BT_STATE_IDLE; /* start here */
155 bt->error_retries = 0; 190 bt->complete = BT_STATE_IDLE; /* end here */
156 bt->nonzero_status = 0; 191 bt->BT_CAP_req2rsp = BT_NORMAL_TIMEOUT * 1000000;
157 bt->truncated = 0; 192 bt->BT_CAP_retries = BT_NORMAL_RETRY_LIMIT;
158 bt->timeout = BT_NORMAL_TIMEOUT; 193 /* BT_CAP_outreqs == zero is a flag to read BT Capabilities */
159 return 3; /* We claim 3 bytes of space; ought to check SPMI table */ 194 return 3; /* We claim 3 bytes of space; ought to check SPMI table */
160} 195}
161 196
197/* Jam a completion code (probably an error) into a response */
198
199static void force_result(struct si_sm_data *bt, unsigned char completion_code)
200{
201 bt->read_data[0] = 4; /* # following bytes */
202 bt->read_data[1] = bt->write_data[1] | 4; /* Odd NetFn/LUN */
203 bt->read_data[2] = bt->write_data[2]; /* seq (ignored) */
204 bt->read_data[3] = bt->write_data[3]; /* Command */
205 bt->read_data[4] = completion_code;
206 bt->read_count = 5;
207}
208
209/* The upper state machine starts here */
210
162static int bt_start_transaction(struct si_sm_data *bt, 211static int bt_start_transaction(struct si_sm_data *bt,
163 unsigned char *data, 212 unsigned char *data,
164 unsigned int size) 213 unsigned int size)
165{ 214{
166 unsigned int i; 215 unsigned int i;
167 216
168 if ((size < 2) || (size > (IPMI_MAX_MSG_LENGTH - 2))) 217 if (size < 2)
169 return -1; 218 return IPMI_REQ_LEN_INVALID_ERR;
219 if (size > IPMI_MAX_MSG_LENGTH)
220 return IPMI_REQ_LEN_EXCEEDED_ERR;
170 221
171 if ((bt->state != BT_STATE_IDLE) && (bt->state != BT_STATE_HOSED)) 222 if (bt->state == BT_STATE_LONG_BUSY)
172 return -2; 223 return IPMI_NODE_BUSY_ERR;
224
225 if (bt->state != BT_STATE_IDLE)
226 return IPMI_NOT_IN_MY_STATE_ERR;
173 227
174 if (bt_debug & BT_DEBUG_MSG) { 228 if (bt_debug & BT_DEBUG_MSG) {
175 printk(KERN_WARNING "+++++++++++++++++++++++++++++++++++++\n"); 229 printk(KERN_WARNING "BT: +++++++++++++++++ New command\n");
176 printk(KERN_WARNING "BT: write seq=0x%02X:", bt->seq); 230 printk(KERN_WARNING "BT: NetFn/LUN CMD [%d data]:", size - 2);
177 for (i = 0; i < size; i ++) 231 for (i = 0; i < size; i ++)
178 printk (" %02x", data[i]); 232 printk (" %02x", data[i]);
179 printk("\n"); 233 printk("\n");
180 } 234 }
181 bt->write_data[0] = size + 1; /* all data plus seq byte */ 235 bt->write_data[0] = size + 1; /* all data plus seq byte */
182 bt->write_data[1] = *data; /* NetFn/LUN */ 236 bt->write_data[1] = *data; /* NetFn/LUN */
183 bt->write_data[2] = bt->seq; 237 bt->write_data[2] = bt->seq++;
184 memcpy(bt->write_data + 3, data + 1, size - 1); 238 memcpy(bt->write_data + 3, data + 1, size - 1);
185 bt->write_count = size + 2; 239 bt->write_count = size + 2;
186
187 bt->error_retries = 0; 240 bt->error_retries = 0;
188 bt->nonzero_status = 0; 241 bt->nonzero_status = 0;
189 bt->read_count = 0;
190 bt->truncated = 0; 242 bt->truncated = 0;
191 bt->state = BT_STATE_XACTION_START; 243 bt->state = BT_STATE_XACTION_START;
192 bt->last_state = BT_STATE_IDLE; 244 bt->timeout = bt->BT_CAP_req2rsp;
193 bt->timeout = BT_NORMAL_TIMEOUT; 245 force_result(bt, IPMI_ERR_UNSPECIFIED);
194 return 0; 246 return 0;
195} 247}
196 248
@@ -198,38 +250,30 @@ static int bt_start_transaction(struct si_sm_data *bt,
198 it calls this. Strip out the length and seq bytes. */ 250 it calls this. Strip out the length and seq bytes. */
199 251
200static int bt_get_result(struct si_sm_data *bt, 252static int bt_get_result(struct si_sm_data *bt,
201 unsigned char *data, 253 unsigned char *data,
202 unsigned int length) 254 unsigned int length)
203{ 255{
204 int i, msg_len; 256 int i, msg_len;
205 257
206 msg_len = bt->read_count - 2; /* account for length & seq */ 258 msg_len = bt->read_count - 2; /* account for length & seq */
207 /* Always NetFn, Cmd, cCode */
208 if (msg_len < 3 || msg_len > IPMI_MAX_MSG_LENGTH) { 259 if (msg_len < 3 || msg_len > IPMI_MAX_MSG_LENGTH) {
209 printk(KERN_DEBUG "BT results: bad msg_len = %d\n", msg_len); 260 force_result(bt, IPMI_ERR_UNSPECIFIED);
210 data[0] = bt->write_data[1] | 0x4; /* Kludge a response */
211 data[1] = bt->write_data[3];
212 data[2] = IPMI_ERR_UNSPECIFIED;
213 msg_len = 3; 261 msg_len = 3;
214 } else { 262 }
215 data[0] = bt->read_data[1]; 263 data[0] = bt->read_data[1];
216 data[1] = bt->read_data[3]; 264 data[1] = bt->read_data[3];
217 if (length < msg_len) 265 if (length < msg_len || bt->truncated) {
218 bt->truncated = 1; 266 data[2] = IPMI_ERR_MSG_TRUNCATED;
219 if (bt->truncated) { /* can be set in read_all_bytes() */ 267 msg_len = 3;
220 data[2] = IPMI_ERR_MSG_TRUNCATED; 268 } else
221 msg_len = 3; 269 memcpy(data + 2, bt->read_data + 4, msg_len - 2);
222 } else
223 memcpy(data + 2, bt->read_data + 4, msg_len - 2);
224 270
225 if (bt_debug & BT_DEBUG_MSG) { 271 if (bt_debug & BT_DEBUG_MSG) {
226 printk (KERN_WARNING "BT: res (raw)"); 272 printk (KERN_WARNING "BT: result %d bytes:", msg_len);
227 for (i = 0; i < msg_len; i++) 273 for (i = 0; i < msg_len; i++)
228 printk(" %02x", data[i]); 274 printk(" %02x", data[i]);
229 printk ("\n"); 275 printk ("\n");
230 }
231 } 276 }
232 bt->read_count = 0; /* paranoia */
233 return msg_len; 277 return msg_len;
234} 278}
235 279
@@ -238,22 +282,40 @@ static int bt_get_result(struct si_sm_data *bt,
238 282
239static void reset_flags(struct si_sm_data *bt) 283static void reset_flags(struct si_sm_data *bt)
240{ 284{
285 if (bt_debug)
286 printk(KERN_WARNING "IPMI BT: flag reset %s\n",
287 status2txt(BT_STATUS));
241 if (BT_STATUS & BT_H_BUSY) 288 if (BT_STATUS & BT_H_BUSY)
242 BT_CONTROL(BT_H_BUSY); 289 BT_CONTROL(BT_H_BUSY); /* force clear */
243 if (BT_STATUS & BT_B_BUSY) 290 BT_CONTROL(BT_CLR_WR_PTR); /* always reset */
244 BT_CONTROL(BT_B_BUSY); 291 BT_CONTROL(BT_SMS_ATN); /* always clear */
245 BT_CONTROL(BT_CLR_WR_PTR); 292 BT_INTMASK_W(BT_BMC_HWRST);
246 BT_CONTROL(BT_SMS_ATN); 293}
247 294
248 if (BT_STATUS & BT_B2H_ATN) { 295/* Get rid of an unwanted/stale response. This should only be needed for
249 int i; 296 BMCs that support multiple outstanding requests. */
250 BT_CONTROL(BT_H_BUSY); 297
251 BT_CONTROL(BT_B2H_ATN); 298static void drain_BMC2HOST(struct si_sm_data *bt)
252 BT_CONTROL(BT_CLR_RD_PTR); 299{
253 for (i = 0; i < IPMI_MAX_MSG_LENGTH + 2; i++) 300 int i, size;
254 BMC2HOST; 301
255 BT_CONTROL(BT_H_BUSY); 302 if (!(BT_STATUS & BT_B2H_ATN)) /* Not signalling a response */
256 } 303 return;
304
305 BT_CONTROL(BT_H_BUSY); /* now set */
306 BT_CONTROL(BT_B2H_ATN); /* always clear */
307 BT_STATUS; /* pause */
308 BT_CONTROL(BT_B2H_ATN); /* some BMCs are stubborn */
309 BT_CONTROL(BT_CLR_RD_PTR); /* always reset */
310 if (bt_debug)
311 printk(KERN_WARNING "IPMI BT: stale response %s; ",
312 status2txt(BT_STATUS));
313 size = BMC2HOST;
314 for (i = 0; i < size ; i++)
315 BMC2HOST;
316 BT_CONTROL(BT_H_BUSY); /* now clear */
317 if (bt_debug)
318 printk("drained %d bytes\n", size + 1);
257} 319}
258 320
259static inline void write_all_bytes(struct si_sm_data *bt) 321static inline void write_all_bytes(struct si_sm_data *bt)
@@ -261,201 +323,256 @@ static inline void write_all_bytes(struct si_sm_data *bt)
261 int i; 323 int i;
262 324
263 if (bt_debug & BT_DEBUG_MSG) { 325 if (bt_debug & BT_DEBUG_MSG) {
264 printk(KERN_WARNING "BT: write %d bytes seq=0x%02X", 326 printk(KERN_WARNING "BT: write %d bytes seq=0x%02X",
265 bt->write_count, bt->seq); 327 bt->write_count, bt->seq);
266 for (i = 0; i < bt->write_count; i++) 328 for (i = 0; i < bt->write_count; i++)
267 printk (" %02x", bt->write_data[i]); 329 printk (" %02x", bt->write_data[i]);
268 printk ("\n"); 330 printk ("\n");
269 } 331 }
270 for (i = 0; i < bt->write_count; i++) 332 for (i = 0; i < bt->write_count; i++)
271 HOST2BMC(bt->write_data[i]); 333 HOST2BMC(bt->write_data[i]);
272} 334}
273 335
274static inline int read_all_bytes(struct si_sm_data *bt) 336static inline int read_all_bytes(struct si_sm_data *bt)
275{ 337{
276 unsigned char i; 338 unsigned char i;
277 339
340 /* length is "framing info", minimum = 4: NetFn, Seq, Cmd, cCode.
341 Keep layout of first four bytes aligned with write_data[] */
342
278 bt->read_data[0] = BMC2HOST; 343 bt->read_data[0] = BMC2HOST;
279 bt->read_count = bt->read_data[0]; 344 bt->read_count = bt->read_data[0];
280 if (bt_debug & BT_DEBUG_MSG)
281 printk(KERN_WARNING "BT: read %d bytes:", bt->read_count);
282 345
283 /* minimum: length, NetFn, Seq, Cmd, cCode == 5 total, or 4 more
284 following the length byte. */
285 if (bt->read_count < 4 || bt->read_count >= IPMI_MAX_MSG_LENGTH) { 346 if (bt->read_count < 4 || bt->read_count >= IPMI_MAX_MSG_LENGTH) {
286 if (bt_debug & BT_DEBUG_MSG) 347 if (bt_debug & BT_DEBUG_MSG)
287 printk("bad length %d\n", bt->read_count); 348 printk(KERN_WARNING "BT: bad raw rsp len=%d\n",
349 bt->read_count);
288 bt->truncated = 1; 350 bt->truncated = 1;
289 return 1; /* let next XACTION START clean it up */ 351 return 1; /* let next XACTION START clean it up */
290 } 352 }
291 for (i = 1; i <= bt->read_count; i++) 353 for (i = 1; i <= bt->read_count; i++)
292 bt->read_data[i] = BMC2HOST; 354 bt->read_data[i] = BMC2HOST;
293 bt->read_count++; /* account for the length byte */ 355 bt->read_count++; /* Account internally for length byte */
294 356
295 if (bt_debug & BT_DEBUG_MSG) { 357 if (bt_debug & BT_DEBUG_MSG) {
296 for (i = 0; i < bt->read_count; i++) 358 int max = bt->read_count;
359
360 printk(KERN_WARNING "BT: got %d bytes seq=0x%02X",
361 max, bt->read_data[2]);
362 if (max > 16)
363 max = 16;
364 for (i = 0; i < max; i++)
297 printk (" %02x", bt->read_data[i]); 365 printk (" %02x", bt->read_data[i]);
298 printk ("\n"); 366 printk ("%s\n", bt->read_count == max ? "" : " ...");
299 } 367 }
300 if (bt->seq != bt->write_data[2]) /* idiot check */
301 printk(KERN_DEBUG "BT: internal error: sequence mismatch\n");
302 368
303 /* per the spec, the (NetFn, Seq, Cmd) tuples should match */ 369 /* per the spec, the (NetFn[1], Seq[2], Cmd[3]) tuples must match */
304 if ((bt->read_data[3] == bt->write_data[3]) && /* Cmd */ 370 if ((bt->read_data[3] == bt->write_data[3]) &&
305 (bt->read_data[2] == bt->write_data[2]) && /* Sequence */ 371 (bt->read_data[2] == bt->write_data[2]) &&
306 ((bt->read_data[1] & 0xF8) == (bt->write_data[1] & 0xF8))) 372 ((bt->read_data[1] & 0xF8) == (bt->write_data[1] & 0xF8)))
307 return 1; 373 return 1;
308 374
309 if (bt_debug & BT_DEBUG_MSG) 375 if (bt_debug & BT_DEBUG_MSG)
310 printk(KERN_WARNING "BT: bad packet: " 376 printk(KERN_WARNING "IPMI BT: bad packet: "
311 "want 0x(%02X, %02X, %02X) got (%02X, %02X, %02X)\n", 377 "want 0x(%02X, %02X, %02X) got (%02X, %02X, %02X)\n",
312 bt->write_data[1], bt->write_data[2], bt->write_data[3], 378 bt->write_data[1] | 0x04, bt->write_data[2], bt->write_data[3],
313 bt->read_data[1], bt->read_data[2], bt->read_data[3]); 379 bt->read_data[1], bt->read_data[2], bt->read_data[3]);
314 return 0; 380 return 0;
315} 381}
316 382
317/* Modifies bt->state appropriately, need to get into the bt_event() switch */ 383/* Restart if retries are left, or return an error completion code */
318 384
319static void error_recovery(struct si_sm_data *bt, char *reason) 385static enum si_sm_result error_recovery(struct si_sm_data *bt,
386 unsigned char status,
387 unsigned char cCode)
320{ 388{
321 unsigned char status; 389 char *reason;
322 char buf[40]; /* For getting status */
323 390
324 bt->timeout = BT_NORMAL_TIMEOUT; /* various places want to retry */ 391 bt->timeout = bt->BT_CAP_req2rsp;
325 392
326 status = BT_STATUS; 393 switch (cCode) {
327 printk(KERN_DEBUG "BT: %s in %s %s\n", reason, STATE2TXT, 394 case IPMI_TIMEOUT_ERR:
328 STATUS2TXT(buf)); 395 reason = "timeout";
396 break;
397 default:
398 reason = "internal error";
399 break;
400 }
401
402 printk(KERN_WARNING "IPMI BT: %s in %s %s ", /* open-ended line */
403 reason, STATE2TXT, STATUS2TXT);
329 404
405 /* Per the IPMI spec, retries are based on the sequence number
406 known only to this module, so manage a restart here. */
330 (bt->error_retries)++; 407 (bt->error_retries)++;
331 if (bt->error_retries > BT_RETRY_LIMIT) { 408 if (bt->error_retries < bt->BT_CAP_retries) {
332 printk(KERN_DEBUG "retry limit (%d) exceeded\n", BT_RETRY_LIMIT); 409 printk("%d retries left\n",
333 bt->state = BT_STATE_HOSED; 410 bt->BT_CAP_retries - bt->error_retries);
334 if (!bt->nonzero_status) 411 bt->state = BT_STATE_RESTART;
335 printk(KERN_ERR "IPMI: BT stuck, try power cycle\n"); 412 return SI_SM_CALL_WITHOUT_DELAY;
336 else if (bt->error_retries <= BT_RETRY_LIMIT + 1) {
337 printk(KERN_DEBUG "IPMI: BT reset (takes 5 secs)\n");
338 bt->state = BT_STATE_RESET1;
339 }
340 return;
341 } 413 }
342 414
343 /* Sometimes the BMC queues get in an "off-by-one" state...*/ 415 printk("failed %d retries, sending error response\n",
344 if ((bt->state == BT_STATE_B2H_WAIT) && (status & BT_B2H_ATN)) { 416 bt->BT_CAP_retries);
345 printk(KERN_DEBUG "retry B2H_WAIT\n"); 417 if (!bt->nonzero_status)
346 return; 418 printk(KERN_ERR "IPMI BT: stuck, try power cycle\n");
419
420 /* this is most likely during insmod */
421 else if (bt->seq <= (unsigned char)(bt->BT_CAP_retries & 0xFF)) {
422 printk(KERN_WARNING "IPMI: BT reset (takes 5 secs)\n");
423 bt->state = BT_STATE_RESET1;
424 return SI_SM_CALL_WITHOUT_DELAY;
347 } 425 }
348 426
349 printk(KERN_DEBUG "restart command\n"); 427 /* Concoct a useful error message, set up the next state, and
350 bt->state = BT_STATE_RESTART; 428 be done with this sequence. */
429
430 bt->state = BT_STATE_IDLE;
431 switch (cCode) {
432 case IPMI_TIMEOUT_ERR:
433 if (status & BT_B_BUSY) {
434 cCode = IPMI_NODE_BUSY_ERR;
435 bt->state = BT_STATE_LONG_BUSY;
436 }
437 break;
438 default:
439 break;
440 }
441 force_result(bt, cCode);
442 return SI_SM_TRANSACTION_COMPLETE;
351} 443}
352 444
353/* Check the status and (possibly) advance the BT state machine. The 445/* Check status and (usually) take action and change this state machine. */
354 default return is SI_SM_CALL_WITH_DELAY. */
355 446
356static enum si_sm_result bt_event(struct si_sm_data *bt, long time) 447static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
357{ 448{
358 unsigned char status; 449 unsigned char status, BT_CAP[8];
359 char buf[40]; /* For getting status */ 450 static enum bt_states last_printed = BT_STATE_PRINTME;
360 int i; 451 int i;
361 452
362 status = BT_STATUS; 453 status = BT_STATUS;
363 bt->nonzero_status |= status; 454 bt->nonzero_status |= status;
364 455 if ((bt_debug & BT_DEBUG_STATES) && (bt->state != last_printed)) {
365 if ((bt_debug & BT_DEBUG_STATES) && (bt->state != bt->last_state))
366 printk(KERN_WARNING "BT: %s %s TO=%ld - %ld \n", 456 printk(KERN_WARNING "BT: %s %s TO=%ld - %ld \n",
367 STATE2TXT, 457 STATE2TXT,
368 STATUS2TXT(buf), 458 STATUS2TXT,
369 bt->timeout, 459 bt->timeout,
370 time); 460 time);
371 bt->last_state = bt->state; 461 last_printed = bt->state;
462 }
372 463
373 if (bt->state == BT_STATE_HOSED) 464 /* Commands that time out may still (eventually) provide a response.
374 return SI_SM_HOSED; 465 This stale response will get in the way of a new response so remove
466 it if possible (hopefully during IDLE). Even if it comes up later
467 it will be rejected by its (now-forgotten) seq number. */
468
469 if ((bt->state < BT_STATE_WRITE_BYTES) && (status & BT_B2H_ATN)) {
470 drain_BMC2HOST(bt);
471 BT_SI_SM_RETURN(SI_SM_CALL_WITH_DELAY);
472 }
375 473
376 if (bt->state != BT_STATE_IDLE) { /* do timeout test */ 474 if ((bt->state != BT_STATE_IDLE) &&
475 (bt->state < BT_STATE_PRINTME)) { /* check timeout */
377 bt->timeout -= time; 476 bt->timeout -= time;
378 if ((bt->timeout < 0) && (bt->state < BT_STATE_RESET1)) { 477 if ((bt->timeout < 0) && (bt->state < BT_STATE_RESET1))
379 error_recovery(bt, "timed out"); 478 return error_recovery(bt,
380 return SI_SM_CALL_WITHOUT_DELAY; 479 status,
381 } 480 IPMI_TIMEOUT_ERR);
382 } 481 }
383 482
384 switch (bt->state) { 483 switch (bt->state) {
385 484
386 case BT_STATE_IDLE: /* check for asynchronous messages */ 485 /* Idle state first checks for asynchronous messages from another
486 channel, then does some opportunistic housekeeping. */
487
488 case BT_STATE_IDLE:
387 if (status & BT_SMS_ATN) { 489 if (status & BT_SMS_ATN) {
388 BT_CONTROL(BT_SMS_ATN); /* clear it */ 490 BT_CONTROL(BT_SMS_ATN); /* clear it */
389 return SI_SM_ATTN; 491 return SI_SM_ATTN;
390 } 492 }
391 return SI_SM_IDLE;
392 493
393 case BT_STATE_XACTION_START: 494 if (status & BT_H_BUSY) /* clear a leftover H_BUSY */
394 if (status & BT_H_BUSY) {
395 BT_CONTROL(BT_H_BUSY); 495 BT_CONTROL(BT_H_BUSY);
396 break;
397 }
398 if (status & BT_B2H_ATN)
399 break;
400 bt->state = BT_STATE_WRITE_BYTES;
401 return SI_SM_CALL_WITHOUT_DELAY; /* for logging */
402 496
403 case BT_STATE_WRITE_BYTES: 497 /* Read BT capabilities if it hasn't been done yet */
498 if (!bt->BT_CAP_outreqs)
499 BT_STATE_CHANGE(BT_STATE_CAPABILITIES_BEGIN,
500 SI_SM_CALL_WITHOUT_DELAY);
501 bt->timeout = bt->BT_CAP_req2rsp;
502 BT_SI_SM_RETURN(SI_SM_IDLE);
503
504 case BT_STATE_XACTION_START:
404 if (status & (BT_B_BUSY | BT_H2B_ATN)) 505 if (status & (BT_B_BUSY | BT_H2B_ATN))
405 break; 506 BT_SI_SM_RETURN(SI_SM_CALL_WITH_DELAY);
507 if (BT_STATUS & BT_H_BUSY)
508 BT_CONTROL(BT_H_BUSY); /* force clear */
509 BT_STATE_CHANGE(BT_STATE_WRITE_BYTES,
510 SI_SM_CALL_WITHOUT_DELAY);
511
512 case BT_STATE_WRITE_BYTES:
513 if (status & BT_H_BUSY)
514 BT_CONTROL(BT_H_BUSY); /* clear */
406 BT_CONTROL(BT_CLR_WR_PTR); 515 BT_CONTROL(BT_CLR_WR_PTR);
407 write_all_bytes(bt); 516 write_all_bytes(bt);
408 BT_CONTROL(BT_H2B_ATN); /* clears too fast to catch? */ 517 BT_CONTROL(BT_H2B_ATN); /* can clear too fast to catch */
409 bt->state = BT_STATE_WRITE_CONSUME; 518 BT_STATE_CHANGE(BT_STATE_WRITE_CONSUME,
410 return SI_SM_CALL_WITHOUT_DELAY; /* it MIGHT sail through */ 519 SI_SM_CALL_WITHOUT_DELAY);
411
412 case BT_STATE_WRITE_CONSUME: /* BMCs usually blow right thru here */
413 if (status & (BT_H2B_ATN | BT_B_BUSY))
414 break;
415 bt->state = BT_STATE_B2H_WAIT;
416 /* fall through with status */
417
418 /* Stay in BT_STATE_B2H_WAIT until a packet matches. However, spinning
419 hard here, constantly reading status, seems to hold off the
420 generation of B2H_ATN so ALWAYS return CALL_WITH_DELAY. */
421
422 case BT_STATE_B2H_WAIT:
423 if (!(status & BT_B2H_ATN))
424 break;
425
426 /* Assume ordered, uncached writes: no need to wait */
427 if (!(status & BT_H_BUSY))
428 BT_CONTROL(BT_H_BUSY); /* set */
429 BT_CONTROL(BT_B2H_ATN); /* clear it, ACK to the BMC */
430 BT_CONTROL(BT_CLR_RD_PTR); /* reset the queue */
431 i = read_all_bytes(bt);
432 BT_CONTROL(BT_H_BUSY); /* clear */
433 if (!i) /* Try this state again */
434 break;
435 bt->state = BT_STATE_READ_END;
436 return SI_SM_CALL_WITHOUT_DELAY; /* for logging */
437
438 case BT_STATE_READ_END:
439
440 /* I could wait on BT_H_BUSY to go clear for a truly clean
441 exit. However, this is already done in XACTION_START
442 and the (possible) extra loop/status/possible wait affects
443 performance. So, as long as it works, just ignore H_BUSY */
444
445#ifdef MAKE_THIS_TRUE_IF_NECESSARY
446 520
447 if (status & BT_H_BUSY) 521 case BT_STATE_WRITE_CONSUME:
448 break; 522 if (status & (BT_B_BUSY | BT_H2B_ATN))
449#endif 523 BT_SI_SM_RETURN(SI_SM_CALL_WITH_DELAY);
450 bt->seq++; 524 BT_STATE_CHANGE(BT_STATE_READ_WAIT,
451 bt->state = BT_STATE_IDLE; 525 SI_SM_CALL_WITHOUT_DELAY);
452 return SI_SM_TRANSACTION_COMPLETE; 526
527 /* Spinning hard can suppress B2H_ATN and force a timeout */
528
529 case BT_STATE_READ_WAIT:
530 if (!(status & BT_B2H_ATN))
531 BT_SI_SM_RETURN(SI_SM_CALL_WITH_DELAY);
532 BT_CONTROL(BT_H_BUSY); /* set */
533
534 /* Uncached, ordered writes should just proceeed serially but
535 some BMCs don't clear B2H_ATN with one hit. Fast-path a
536 workaround without too much penalty to the general case. */
537
538 BT_CONTROL(BT_B2H_ATN); /* clear it to ACK the BMC */
539 BT_STATE_CHANGE(BT_STATE_CLEAR_B2H,
540 SI_SM_CALL_WITHOUT_DELAY);
541
542 case BT_STATE_CLEAR_B2H:
543 if (status & BT_B2H_ATN) { /* keep hitting it */
544 BT_CONTROL(BT_B2H_ATN);
545 BT_SI_SM_RETURN(SI_SM_CALL_WITH_DELAY);
546 }
547 BT_STATE_CHANGE(BT_STATE_READ_BYTES,
548 SI_SM_CALL_WITHOUT_DELAY);
549
550 case BT_STATE_READ_BYTES:
551 if (!(status & BT_H_BUSY)) /* check in case of retry */
552 BT_CONTROL(BT_H_BUSY);
553 BT_CONTROL(BT_CLR_RD_PTR); /* start of BMC2HOST buffer */
554 i = read_all_bytes(bt); /* true == packet seq match */
555 BT_CONTROL(BT_H_BUSY); /* NOW clear */
556 if (!i) /* Not my message */
557 BT_STATE_CHANGE(BT_STATE_READ_WAIT,
558 SI_SM_CALL_WITHOUT_DELAY);
559 bt->state = bt->complete;
560 return bt->state == BT_STATE_IDLE ? /* where to next? */
561 SI_SM_TRANSACTION_COMPLETE : /* normal */
562 SI_SM_CALL_WITHOUT_DELAY; /* Startup magic */
563
564 case BT_STATE_LONG_BUSY: /* For example: after FW update */
565 if (!(status & BT_B_BUSY)) {
566 reset_flags(bt); /* next state is now IDLE */
567 bt_init_data(bt, bt->io);
568 }
569 return SI_SM_CALL_WITH_DELAY; /* No repeat printing */
453 570
454 case BT_STATE_RESET1: 571 case BT_STATE_RESET1:
455 reset_flags(bt); 572 reset_flags(bt);
456 bt->timeout = BT_RESET_DELAY; 573 drain_BMC2HOST(bt);
457 bt->state = BT_STATE_RESET2; 574 BT_STATE_CHANGE(BT_STATE_RESET2,
458 break; 575 SI_SM_CALL_WITH_DELAY);
459 576
460 case BT_STATE_RESET2: /* Send a soft reset */ 577 case BT_STATE_RESET2: /* Send a soft reset */
461 BT_CONTROL(BT_CLR_WR_PTR); 578 BT_CONTROL(BT_CLR_WR_PTR);
@@ -464,29 +581,59 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
464 HOST2BMC(42); /* Sequence number */ 581 HOST2BMC(42); /* Sequence number */
465 HOST2BMC(3); /* Cmd == Soft reset */ 582 HOST2BMC(3); /* Cmd == Soft reset */
466 BT_CONTROL(BT_H2B_ATN); 583 BT_CONTROL(BT_H2B_ATN);
467 bt->state = BT_STATE_RESET3; 584 bt->timeout = BT_RESET_DELAY * 1000000;
468 break; 585 BT_STATE_CHANGE(BT_STATE_RESET3,
586 SI_SM_CALL_WITH_DELAY);
469 587
470 case BT_STATE_RESET3: 588 case BT_STATE_RESET3: /* Hold off everything for a bit */
471 if (bt->timeout > 0) 589 if (bt->timeout > 0)
472 return SI_SM_CALL_WITH_DELAY; 590 return SI_SM_CALL_WITH_DELAY;
473 bt->state = BT_STATE_RESTART; /* printk in debug modes */ 591 drain_BMC2HOST(bt);
474 break; 592 BT_STATE_CHANGE(BT_STATE_RESTART,
593 SI_SM_CALL_WITH_DELAY);
475 594
476 case BT_STATE_RESTART: /* don't reset retries! */ 595 case BT_STATE_RESTART: /* don't reset retries or seq! */
477 reset_flags(bt);
478 bt->write_data[2] = ++bt->seq;
479 bt->read_count = 0; 596 bt->read_count = 0;
480 bt->nonzero_status = 0; 597 bt->nonzero_status = 0;
481 bt->timeout = BT_NORMAL_TIMEOUT; 598 bt->timeout = bt->BT_CAP_req2rsp;
482 bt->state = BT_STATE_XACTION_START; 599 BT_STATE_CHANGE(BT_STATE_XACTION_START,
483 break; 600 SI_SM_CALL_WITH_DELAY);
484 601
485 default: /* HOSED is supposed to be caught much earlier */ 602 /* Get BT Capabilities, using timing of upper level state machine.
486 error_recovery(bt, "internal logic error"); 603 Set outreqs to prevent infinite loop on timeout. */
487 break; 604 case BT_STATE_CAPABILITIES_BEGIN:
488 } 605 bt->BT_CAP_outreqs = 1;
489 return SI_SM_CALL_WITH_DELAY; 606 {
607 unsigned char GetBT_CAP[] = { 0x18, 0x36 };
608 bt->state = BT_STATE_IDLE;
609 bt_start_transaction(bt, GetBT_CAP, sizeof(GetBT_CAP));
610 }
611 bt->complete = BT_STATE_CAPABILITIES_END;
612 BT_STATE_CHANGE(BT_STATE_XACTION_START,
613 SI_SM_CALL_WITH_DELAY);
614
615 case BT_STATE_CAPABILITIES_END:
616 i = bt_get_result(bt, BT_CAP, sizeof(BT_CAP));
617 bt_init_data(bt, bt->io);
618 if ((i == 8) && !BT_CAP[2]) {
619 bt->BT_CAP_outreqs = BT_CAP[3];
620 bt->BT_CAP_req2rsp = BT_CAP[6] * 1000000;
621 bt->BT_CAP_retries = BT_CAP[7];
622 } else
623 printk(KERN_WARNING "IPMI BT: using default values\n");
624 if (!bt->BT_CAP_outreqs)
625 bt->BT_CAP_outreqs = 1;
626 printk(KERN_WARNING "IPMI BT: req2rsp=%ld secs retries=%d\n",
627 bt->BT_CAP_req2rsp / 1000000L, bt->BT_CAP_retries);
628 bt->timeout = bt->BT_CAP_req2rsp;
629 return SI_SM_CALL_WITHOUT_DELAY;
630
631 default: /* should never occur */
632 return error_recovery(bt,
633 status,
634 IPMI_ERR_UNSPECIFIED);
635 }
636 return SI_SM_CALL_WITH_DELAY;
490} 637}
491 638
492static int bt_detect(struct si_sm_data *bt) 639static int bt_detect(struct si_sm_data *bt)
@@ -497,7 +644,7 @@ static int bt_detect(struct si_sm_data *bt)
497 test that first. The calling routine uses negative logic. */ 644 test that first. The calling routine uses negative logic. */
498 645
499 if ((BT_STATUS == 0xFF) && (BT_INTMASK_R == 0xFF)) 646 if ((BT_STATUS == 0xFF) && (BT_INTMASK_R == 0xFF))
500 return 1; 647 return 1;
501 reset_flags(bt); 648 reset_flags(bt);
502 return 0; 649 return 0;
503} 650}
@@ -513,11 +660,11 @@ static int bt_size(void)
513 660
514struct si_sm_handlers bt_smi_handlers = 661struct si_sm_handlers bt_smi_handlers =
515{ 662{
516 .init_data = bt_init_data, 663 .init_data = bt_init_data,
517 .start_transaction = bt_start_transaction, 664 .start_transaction = bt_start_transaction,
518 .get_result = bt_get_result, 665 .get_result = bt_get_result,
519 .event = bt_event, 666 .event = bt_event,
520 .detect = bt_detect, 667 .detect = bt_detect,
521 .cleanup = bt_cleanup, 668 .cleanup = bt_cleanup,
522 .size = bt_size, 669 .size = bt_size,
523}; 670};
diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index 68d7c61a864e..ff2d052177cb 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -377,7 +377,8 @@ static int ipmi_ioctl(struct inode *inode,
377 break; 377 break;
378 } 378 }
379 379
380 rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd); 380 rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd,
381 IPMI_CHAN_ALL);
381 break; 382 break;
382 } 383 }
383 384
@@ -390,7 +391,36 @@ static int ipmi_ioctl(struct inode *inode,
390 break; 391 break;
391 } 392 }
392 393
393 rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd); 394 rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd,
395 IPMI_CHAN_ALL);
396 break;
397 }
398
399 case IPMICTL_REGISTER_FOR_CMD_CHANS:
400 {
401 struct ipmi_cmdspec_chans val;
402
403 if (copy_from_user(&val, arg, sizeof(val))) {
404 rv = -EFAULT;
405 break;
406 }
407
408 rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd,
409 val.chans);
410 break;
411 }
412
413 case IPMICTL_UNREGISTER_FOR_CMD_CHANS:
414 {
415 struct ipmi_cmdspec_chans val;
416
417 if (copy_from_user(&val, arg, sizeof(val))) {
418 rv = -EFAULT;
419 break;
420 }
421
422 rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd,
423 val.chans);
394 break; 424 break;
395 } 425 }
396 426
@@ -566,6 +596,31 @@ static int ipmi_ioctl(struct inode *inode,
566 rv = 0; 596 rv = 0;
567 break; 597 break;
568 } 598 }
599
600 case IPMICTL_GET_MAINTENANCE_MODE_CMD:
601 {
602 int mode;
603
604 mode = ipmi_get_maintenance_mode(priv->user);
605 if (copy_to_user(arg, &mode, sizeof(mode))) {
606 rv = -EFAULT;
607 break;
608 }
609 rv = 0;
610 break;
611 }
612
613 case IPMICTL_SET_MAINTENANCE_MODE_CMD:
614 {
615 int mode;
616
617 if (copy_from_user(&mode, arg, sizeof(mode))) {
618 rv = -EFAULT;
619 break;
620 }
621 rv = ipmi_set_maintenance_mode(priv->user, mode);
622 break;
623 }
569 } 624 }
570 625
571 return rv; 626 return rv;
@@ -743,7 +798,7 @@ static long compat_ipmi_ioctl(struct file *filep, unsigned int cmd,
743 if (copy_to_user(precv64, &recv64, sizeof(recv64))) 798 if (copy_to_user(precv64, &recv64, sizeof(recv64)))
744 return -EFAULT; 799 return -EFAULT;
745 800
746 rc = ipmi_ioctl(filep->f_dentry->d_inode, filep, 801 rc = ipmi_ioctl(filep->f_path.dentry->d_inode, filep,
747 ((cmd == COMPAT_IPMICTL_RECEIVE_MSG) 802 ((cmd == COMPAT_IPMICTL_RECEIVE_MSG)
748 ? IPMICTL_RECEIVE_MSG 803 ? IPMICTL_RECEIVE_MSG
749 : IPMICTL_RECEIVE_MSG_TRUNC), 804 : IPMICTL_RECEIVE_MSG_TRUNC),
@@ -760,7 +815,7 @@ static long compat_ipmi_ioctl(struct file *filep, unsigned int cmd,
760 return rc; 815 return rc;
761 } 816 }
762 default: 817 default:
763 return ipmi_ioctl(filep->f_dentry->d_inode, filep, cmd, arg); 818 return ipmi_ioctl(filep->f_path.dentry->d_inode, filep, cmd, arg);
764 } 819 }
765} 820}
766#endif 821#endif
@@ -779,7 +834,7 @@ static const struct file_operations ipmi_fops = {
779 834
780#define DEVICE_NAME "ipmidev" 835#define DEVICE_NAME "ipmidev"
781 836
782static int ipmi_major = 0; 837static int ipmi_major;
783module_param(ipmi_major, int, 0); 838module_param(ipmi_major, int, 0);
784MODULE_PARM_DESC(ipmi_major, "Sets the major number of the IPMI device. By" 839MODULE_PARM_DESC(ipmi_major, "Sets the major number of the IPMI device. By"
785 " default, or if you set it to zero, it will choose the next" 840 " default, or if you set it to zero, it will choose the next"
diff --git a/drivers/char/ipmi/ipmi_kcs_sm.c b/drivers/char/ipmi/ipmi_kcs_sm.c
index 2062675f9e99..c1b8228cb7b6 100644
--- a/drivers/char/ipmi/ipmi_kcs_sm.c
+++ b/drivers/char/ipmi/ipmi_kcs_sm.c
@@ -93,8 +93,8 @@ enum kcs_states {
93 state machine. */ 93 state machine. */
94}; 94};
95 95
96#define MAX_KCS_READ_SIZE 80 96#define MAX_KCS_READ_SIZE IPMI_MAX_MSG_LENGTH
97#define MAX_KCS_WRITE_SIZE 80 97#define MAX_KCS_WRITE_SIZE IPMI_MAX_MSG_LENGTH
98 98
99/* Timeouts in microseconds. */ 99/* Timeouts in microseconds. */
100#define IBF_RETRY_TIMEOUT 1000000 100#define IBF_RETRY_TIMEOUT 1000000
@@ -261,12 +261,14 @@ static int start_kcs_transaction(struct si_sm_data *kcs, unsigned char *data,
261{ 261{
262 unsigned int i; 262 unsigned int i;
263 263
264 if ((size < 2) || (size > MAX_KCS_WRITE_SIZE)) { 264 if (size < 2)
265 return -1; 265 return IPMI_REQ_LEN_INVALID_ERR;
266 } 266 if (size > MAX_KCS_WRITE_SIZE)
267 if ((kcs->state != KCS_IDLE) && (kcs->state != KCS_HOSED)) { 267 return IPMI_REQ_LEN_EXCEEDED_ERR;
268 return -2; 268
269 } 269 if ((kcs->state != KCS_IDLE) && (kcs->state != KCS_HOSED))
270 return IPMI_NOT_IN_MY_STATE_ERR;
271
270 if (kcs_debug & KCS_DEBUG_MSG) { 272 if (kcs_debug & KCS_DEBUG_MSG) {
271 printk(KERN_DEBUG "start_kcs_transaction -"); 273 printk(KERN_DEBUG "start_kcs_transaction -");
272 for (i = 0; i < size; i ++) { 274 for (i = 0; i < size; i ++) {
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 843d34c8627c..4e4691a53890 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -48,17 +48,20 @@
48 48
49#define PFX "IPMI message handler: " 49#define PFX "IPMI message handler: "
50 50
51#define IPMI_DRIVER_VERSION "39.0" 51#define IPMI_DRIVER_VERSION "39.1"
52 52
53static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void); 53static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void);
54static int ipmi_init_msghandler(void); 54static int ipmi_init_msghandler(void);
55 55
56static int initialized = 0; 56static int initialized;
57 57
58#ifdef CONFIG_PROC_FS 58#ifdef CONFIG_PROC_FS
59static struct proc_dir_entry *proc_ipmi_root = NULL; 59static struct proc_dir_entry *proc_ipmi_root;
60#endif /* CONFIG_PROC_FS */ 60#endif /* CONFIG_PROC_FS */
61 61
62/* Remain in auto-maintenance mode for this amount of time (in ms). */
63#define IPMI_MAINTENANCE_MODE_TIMEOUT 30000
64
62#define MAX_EVENTS_IN_QUEUE 25 65#define MAX_EVENTS_IN_QUEUE 25
63 66
64/* Don't let a message sit in a queue forever, always time it with at lest 67/* Don't let a message sit in a queue forever, always time it with at lest
@@ -96,6 +99,7 @@ struct cmd_rcvr
96 ipmi_user_t user; 99 ipmi_user_t user;
97 unsigned char netfn; 100 unsigned char netfn;
98 unsigned char cmd; 101 unsigned char cmd;
102 unsigned int chans;
99 103
100 /* 104 /*
101 * This is used to form a linked lised during mass deletion. 105 * This is used to form a linked lised during mass deletion.
@@ -192,17 +196,28 @@ struct ipmi_smi
192 196
193 struct kref refcount; 197 struct kref refcount;
194 198
199 /* Used for a list of interfaces. */
200 struct list_head link;
201
195 /* The list of upper layers that are using me. seq_lock 202 /* The list of upper layers that are using me. seq_lock
196 * protects this. */ 203 * protects this. */
197 struct list_head users; 204 struct list_head users;
198 205
206 /* Information to supply to users. */
207 unsigned char ipmi_version_major;
208 unsigned char ipmi_version_minor;
209
199 /* Used for wake ups at startup. */ 210 /* Used for wake ups at startup. */
200 wait_queue_head_t waitq; 211 wait_queue_head_t waitq;
201 212
202 struct bmc_device *bmc; 213 struct bmc_device *bmc;
203 char *my_dev_name; 214 char *my_dev_name;
215 char *sysfs_name;
204 216
205 /* This is the lower-layer's sender routine. */ 217 /* This is the lower-layer's sender routine. Note that you
218 * must either be holding the ipmi_interfaces_mutex or be in
219 * an umpreemptible region to use this. You must fetch the
220 * value into a local variable and make sure it is not NULL. */
206 struct ipmi_smi_handlers *handlers; 221 struct ipmi_smi_handlers *handlers;
207 void *send_info; 222 void *send_info;
208 223
@@ -241,6 +256,7 @@ struct ipmi_smi
241 spinlock_t events_lock; /* For dealing with event stuff. */ 256 spinlock_t events_lock; /* For dealing with event stuff. */
242 struct list_head waiting_events; 257 struct list_head waiting_events;
243 unsigned int waiting_events_count; /* How many events in queue? */ 258 unsigned int waiting_events_count; /* How many events in queue? */
259 int delivering_events;
244 260
245 /* The event receiver for my BMC, only really used at panic 261 /* The event receiver for my BMC, only really used at panic
246 shutdown as a place to store this. */ 262 shutdown as a place to store this. */
@@ -249,6 +265,12 @@ struct ipmi_smi
249 unsigned char local_sel_device; 265 unsigned char local_sel_device;
250 unsigned char local_event_generator; 266 unsigned char local_event_generator;
251 267
268 /* For handling of maintenance mode. */
269 int maintenance_mode;
270 int maintenance_mode_enable;
271 int auto_maintenance_timeout;
272 spinlock_t maintenance_mode_lock; /* Used in a timer... */
273
252 /* A cheap hack, if this is non-null and a message to an 274 /* A cheap hack, if this is non-null and a message to an
253 interface comes in with a NULL user, call this routine with 275 interface comes in with a NULL user, call this routine with
254 it. Note that the message will still be freed by the 276 it. Note that the message will still be freed by the
@@ -337,13 +359,6 @@ struct ipmi_smi
337}; 359};
338#define to_si_intf_from_dev(device) container_of(device, struct ipmi_smi, dev) 360#define to_si_intf_from_dev(device) container_of(device, struct ipmi_smi, dev)
339 361
340/* Used to mark an interface entry that cannot be used but is not a
341 * free entry, either, primarily used at creation and deletion time so
342 * a slot doesn't get reused too quickly. */
343#define IPMI_INVALID_INTERFACE_ENTRY ((ipmi_smi_t) ((long) 1))
344#define IPMI_INVALID_INTERFACE(i) (((i) == NULL) \
345 || (i == IPMI_INVALID_INTERFACE_ENTRY))
346
347/** 362/**
348 * The driver model view of the IPMI messaging driver. 363 * The driver model view of the IPMI messaging driver.
349 */ 364 */
@@ -353,16 +368,13 @@ static struct device_driver ipmidriver = {
353}; 368};
354static DEFINE_MUTEX(ipmidriver_mutex); 369static DEFINE_MUTEX(ipmidriver_mutex);
355 370
356#define MAX_IPMI_INTERFACES 4 371static struct list_head ipmi_interfaces = LIST_HEAD_INIT(ipmi_interfaces);
357static ipmi_smi_t ipmi_interfaces[MAX_IPMI_INTERFACES]; 372static DEFINE_MUTEX(ipmi_interfaces_mutex);
358
359/* Directly protects the ipmi_interfaces data structure. */
360static DEFINE_SPINLOCK(interfaces_lock);
361 373
362/* List of watchers that want to know when smi's are added and 374/* List of watchers that want to know when smi's are added and
363 deleted. */ 375 deleted. */
364static struct list_head smi_watchers = LIST_HEAD_INIT(smi_watchers); 376static struct list_head smi_watchers = LIST_HEAD_INIT(smi_watchers);
365static DECLARE_RWSEM(smi_watchers_sem); 377static DEFINE_MUTEX(smi_watchers_mutex);
366 378
367 379
368static void free_recv_msg_list(struct list_head *q) 380static void free_recv_msg_list(struct list_head *q)
@@ -375,13 +387,23 @@ static void free_recv_msg_list(struct list_head *q)
375 } 387 }
376} 388}
377 389
390static void free_smi_msg_list(struct list_head *q)
391{
392 struct ipmi_smi_msg *msg, *msg2;
393
394 list_for_each_entry_safe(msg, msg2, q, link) {
395 list_del(&msg->link);
396 ipmi_free_smi_msg(msg);
397 }
398}
399
378static void clean_up_interface_data(ipmi_smi_t intf) 400static void clean_up_interface_data(ipmi_smi_t intf)
379{ 401{
380 int i; 402 int i;
381 struct cmd_rcvr *rcvr, *rcvr2; 403 struct cmd_rcvr *rcvr, *rcvr2;
382 struct list_head list; 404 struct list_head list;
383 405
384 free_recv_msg_list(&intf->waiting_msgs); 406 free_smi_msg_list(&intf->waiting_msgs);
385 free_recv_msg_list(&intf->waiting_events); 407 free_recv_msg_list(&intf->waiting_events);
386 408
387 /* Wholesale remove all the entries from the list in the 409 /* Wholesale remove all the entries from the list in the
@@ -412,48 +434,84 @@ static void intf_free(struct kref *ref)
412 kfree(intf); 434 kfree(intf);
413} 435}
414 436
437struct watcher_entry {
438 int intf_num;
439 ipmi_smi_t intf;
440 struct list_head link;
441};
442
415int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher) 443int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher)
416{ 444{
417 int i; 445 ipmi_smi_t intf;
418 unsigned long flags; 446 struct list_head to_deliver = LIST_HEAD_INIT(to_deliver);
447 struct watcher_entry *e, *e2;
419 448
420 down_write(&smi_watchers_sem); 449 mutex_lock(&smi_watchers_mutex);
421 list_add(&(watcher->link), &smi_watchers); 450
422 up_write(&smi_watchers_sem); 451 mutex_lock(&ipmi_interfaces_mutex);
423 spin_lock_irqsave(&interfaces_lock, flags); 452
424 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 453 /* Build a list of things to deliver. */
425 ipmi_smi_t intf = ipmi_interfaces[i]; 454 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
426 if (IPMI_INVALID_INTERFACE(intf)) 455 if (intf->intf_num == -1)
427 continue; 456 continue;
428 spin_unlock_irqrestore(&interfaces_lock, flags); 457 e = kmalloc(sizeof(*e), GFP_KERNEL);
429 watcher->new_smi(i, intf->si_dev); 458 if (!e)
430 spin_lock_irqsave(&interfaces_lock, flags); 459 goto out_err;
460 kref_get(&intf->refcount);
461 e->intf = intf;
462 e->intf_num = intf->intf_num;
463 list_add_tail(&e->link, &to_deliver);
431 } 464 }
432 spin_unlock_irqrestore(&interfaces_lock, flags); 465
466 /* We will succeed, so add it to the list. */
467 list_add(&watcher->link, &smi_watchers);
468
469 mutex_unlock(&ipmi_interfaces_mutex);
470
471 list_for_each_entry_safe(e, e2, &to_deliver, link) {
472 list_del(&e->link);
473 watcher->new_smi(e->intf_num, e->intf->si_dev);
474 kref_put(&e->intf->refcount, intf_free);
475 kfree(e);
476 }
477
478 mutex_unlock(&smi_watchers_mutex);
479
433 return 0; 480 return 0;
481
482 out_err:
483 mutex_unlock(&ipmi_interfaces_mutex);
484 mutex_unlock(&smi_watchers_mutex);
485 list_for_each_entry_safe(e, e2, &to_deliver, link) {
486 list_del(&e->link);
487 kref_put(&e->intf->refcount, intf_free);
488 kfree(e);
489 }
490 return -ENOMEM;
434} 491}
435 492
436int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher) 493int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher)
437{ 494{
438 down_write(&smi_watchers_sem); 495 mutex_lock(&smi_watchers_mutex);
439 list_del(&(watcher->link)); 496 list_del(&(watcher->link));
440 up_write(&smi_watchers_sem); 497 mutex_unlock(&smi_watchers_mutex);
441 return 0; 498 return 0;
442} 499}
443 500
501/*
502 * Must be called with smi_watchers_mutex held.
503 */
444static void 504static void
445call_smi_watchers(int i, struct device *dev) 505call_smi_watchers(int i, struct device *dev)
446{ 506{
447 struct ipmi_smi_watcher *w; 507 struct ipmi_smi_watcher *w;
448 508
449 down_read(&smi_watchers_sem);
450 list_for_each_entry(w, &smi_watchers, link) { 509 list_for_each_entry(w, &smi_watchers, link) {
451 if (try_module_get(w->owner)) { 510 if (try_module_get(w->owner)) {
452 w->new_smi(i, dev); 511 w->new_smi(i, dev);
453 module_put(w->owner); 512 module_put(w->owner);
454 } 513 }
455 } 514 }
456 up_read(&smi_watchers_sem);
457} 515}
458 516
459static int 517static int
@@ -579,6 +637,17 @@ static void deliver_response(struct ipmi_recv_msg *msg)
579 } 637 }
580} 638}
581 639
640static void
641deliver_err_response(struct ipmi_recv_msg *msg, int err)
642{
643 msg->recv_type = IPMI_RESPONSE_RECV_TYPE;
644 msg->msg_data[0] = err;
645 msg->msg.netfn |= 1; /* Convert to a response. */
646 msg->msg.data_len = 1;
647 msg->msg.data = msg->msg_data;
648 deliver_response(msg);
649}
650
582/* Find the next sequence number not being used and add the given 651/* Find the next sequence number not being used and add the given
583 message with the given timeout to the sequence table. This must be 652 message with the given timeout to the sequence table. This must be
584 called with the interface's seq_lock held. */ 653 called with the interface's seq_lock held. */
@@ -716,14 +785,8 @@ static int intf_err_seq(ipmi_smi_t intf,
716 } 785 }
717 spin_unlock_irqrestore(&(intf->seq_lock), flags); 786 spin_unlock_irqrestore(&(intf->seq_lock), flags);
718 787
719 if (msg) { 788 if (msg)
720 msg->recv_type = IPMI_RESPONSE_RECV_TYPE; 789 deliver_err_response(msg, err);
721 msg->msg_data[0] = err;
722 msg->msg.netfn |= 1; /* Convert to a response. */
723 msg->msg.data_len = 1;
724 msg->msg.data = msg->msg_data;
725 deliver_response(msg);
726 }
727 790
728 return rv; 791 return rv;
729} 792}
@@ -765,17 +828,18 @@ int ipmi_create_user(unsigned int if_num,
765 if (!new_user) 828 if (!new_user)
766 return -ENOMEM; 829 return -ENOMEM;
767 830
768 spin_lock_irqsave(&interfaces_lock, flags); 831 mutex_lock(&ipmi_interfaces_mutex);
769 intf = ipmi_interfaces[if_num]; 832 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
770 if ((if_num >= MAX_IPMI_INTERFACES) || IPMI_INVALID_INTERFACE(intf)) { 833 if (intf->intf_num == if_num)
771 spin_unlock_irqrestore(&interfaces_lock, flags); 834 goto found;
772 rv = -EINVAL;
773 goto out_kfree;
774 } 835 }
836 /* Not found, return an error */
837 rv = -EINVAL;
838 goto out_kfree;
775 839
840 found:
776 /* Note that each existing user holds a refcount to the interface. */ 841 /* Note that each existing user holds a refcount to the interface. */
777 kref_get(&intf->refcount); 842 kref_get(&intf->refcount);
778 spin_unlock_irqrestore(&interfaces_lock, flags);
779 843
780 kref_init(&new_user->refcount); 844 kref_init(&new_user->refcount);
781 new_user->handler = handler; 845 new_user->handler = handler;
@@ -796,6 +860,10 @@ int ipmi_create_user(unsigned int if_num,
796 } 860 }
797 } 861 }
798 862
863 /* Hold the lock so intf->handlers is guaranteed to be good
864 * until now */
865 mutex_unlock(&ipmi_interfaces_mutex);
866
799 new_user->valid = 1; 867 new_user->valid = 1;
800 spin_lock_irqsave(&intf->seq_lock, flags); 868 spin_lock_irqsave(&intf->seq_lock, flags);
801 list_add_rcu(&new_user->link, &intf->users); 869 list_add_rcu(&new_user->link, &intf->users);
@@ -806,6 +874,7 @@ int ipmi_create_user(unsigned int if_num,
806out_kref: 874out_kref:
807 kref_put(&intf->refcount, intf_free); 875 kref_put(&intf->refcount, intf_free);
808out_kfree: 876out_kfree:
877 mutex_unlock(&ipmi_interfaces_mutex);
809 kfree(new_user); 878 kfree(new_user);
810 return rv; 879 return rv;
811} 880}
@@ -835,6 +904,7 @@ int ipmi_destroy_user(ipmi_user_t user)
835 && (intf->seq_table[i].recv_msg->user == user)) 904 && (intf->seq_table[i].recv_msg->user == user))
836 { 905 {
837 intf->seq_table[i].inuse = 0; 906 intf->seq_table[i].inuse = 0;
907 ipmi_free_recv_msg(intf->seq_table[i].recv_msg);
838 } 908 }
839 } 909 }
840 spin_unlock_irqrestore(&intf->seq_lock, flags); 910 spin_unlock_irqrestore(&intf->seq_lock, flags);
@@ -861,9 +931,13 @@ int ipmi_destroy_user(ipmi_user_t user)
861 kfree(rcvr); 931 kfree(rcvr);
862 } 932 }
863 933
864 module_put(intf->handlers->owner); 934 mutex_lock(&ipmi_interfaces_mutex);
865 if (intf->handlers->dec_usecount) 935 if (intf->handlers) {
866 intf->handlers->dec_usecount(intf->send_info); 936 module_put(intf->handlers->owner);
937 if (intf->handlers->dec_usecount)
938 intf->handlers->dec_usecount(intf->send_info);
939 }
940 mutex_unlock(&ipmi_interfaces_mutex);
867 941
868 kref_put(&intf->refcount, intf_free); 942 kref_put(&intf->refcount, intf_free);
869 943
@@ -876,8 +950,8 @@ void ipmi_get_version(ipmi_user_t user,
876 unsigned char *major, 950 unsigned char *major,
877 unsigned char *minor) 951 unsigned char *minor)
878{ 952{
879 *major = ipmi_version_major(&user->intf->bmc->id); 953 *major = user->intf->ipmi_version_major;
880 *minor = ipmi_version_minor(&user->intf->bmc->id); 954 *minor = user->intf->ipmi_version_minor;
881} 955}
882 956
883int ipmi_set_my_address(ipmi_user_t user, 957int ipmi_set_my_address(ipmi_user_t user,
@@ -920,6 +994,65 @@ int ipmi_get_my_LUN(ipmi_user_t user,
920 return 0; 994 return 0;
921} 995}
922 996
997int ipmi_get_maintenance_mode(ipmi_user_t user)
998{
999 int mode;
1000 unsigned long flags;
1001
1002 spin_lock_irqsave(&user->intf->maintenance_mode_lock, flags);
1003 mode = user->intf->maintenance_mode;
1004 spin_unlock_irqrestore(&user->intf->maintenance_mode_lock, flags);
1005
1006 return mode;
1007}
1008EXPORT_SYMBOL(ipmi_get_maintenance_mode);
1009
1010static void maintenance_mode_update(ipmi_smi_t intf)
1011{
1012 if (intf->handlers->set_maintenance_mode)
1013 intf->handlers->set_maintenance_mode(
1014 intf->send_info, intf->maintenance_mode_enable);
1015}
1016
1017int ipmi_set_maintenance_mode(ipmi_user_t user, int mode)
1018{
1019 int rv = 0;
1020 unsigned long flags;
1021 ipmi_smi_t intf = user->intf;
1022
1023 spin_lock_irqsave(&intf->maintenance_mode_lock, flags);
1024 if (intf->maintenance_mode != mode) {
1025 switch (mode) {
1026 case IPMI_MAINTENANCE_MODE_AUTO:
1027 intf->maintenance_mode = mode;
1028 intf->maintenance_mode_enable
1029 = (intf->auto_maintenance_timeout > 0);
1030 break;
1031
1032 case IPMI_MAINTENANCE_MODE_OFF:
1033 intf->maintenance_mode = mode;
1034 intf->maintenance_mode_enable = 0;
1035 break;
1036
1037 case IPMI_MAINTENANCE_MODE_ON:
1038 intf->maintenance_mode = mode;
1039 intf->maintenance_mode_enable = 1;
1040 break;
1041
1042 default:
1043 rv = -EINVAL;
1044 goto out_unlock;
1045 }
1046
1047 maintenance_mode_update(intf);
1048 }
1049 out_unlock:
1050 spin_unlock_irqrestore(&intf->maintenance_mode_lock, flags);
1051
1052 return rv;
1053}
1054EXPORT_SYMBOL(ipmi_set_maintenance_mode);
1055
923int ipmi_set_gets_events(ipmi_user_t user, int val) 1056int ipmi_set_gets_events(ipmi_user_t user, int val)
924{ 1057{
925 unsigned long flags; 1058 unsigned long flags;
@@ -932,20 +1065,33 @@ int ipmi_set_gets_events(ipmi_user_t user, int val)
932 spin_lock_irqsave(&intf->events_lock, flags); 1065 spin_lock_irqsave(&intf->events_lock, flags);
933 user->gets_events = val; 1066 user->gets_events = val;
934 1067
935 if (val) { 1068 if (intf->delivering_events)
936 /* Deliver any queued events. */ 1069 /*
1070 * Another thread is delivering events for this, so
1071 * let it handle any new events.
1072 */
1073 goto out;
1074
1075 /* Deliver any queued events. */
1076 while (user->gets_events && !list_empty(&intf->waiting_events)) {
937 list_for_each_entry_safe(msg, msg2, &intf->waiting_events, link) 1077 list_for_each_entry_safe(msg, msg2, &intf->waiting_events, link)
938 list_move_tail(&msg->link, &msgs); 1078 list_move_tail(&msg->link, &msgs);
939 intf->waiting_events_count = 0; 1079 intf->waiting_events_count = 0;
940 }
941 1080
942 /* Hold the events lock while doing this to preserve order. */ 1081 intf->delivering_events = 1;
943 list_for_each_entry_safe(msg, msg2, &msgs, link) { 1082 spin_unlock_irqrestore(&intf->events_lock, flags);
944 msg->user = user; 1083
945 kref_get(&user->refcount); 1084 list_for_each_entry_safe(msg, msg2, &msgs, link) {
946 deliver_response(msg); 1085 msg->user = user;
1086 kref_get(&user->refcount);
1087 deliver_response(msg);
1088 }
1089
1090 spin_lock_irqsave(&intf->events_lock, flags);
1091 intf->delivering_events = 0;
947 } 1092 }
948 1093
1094 out:
949 spin_unlock_irqrestore(&intf->events_lock, flags); 1095 spin_unlock_irqrestore(&intf->events_lock, flags);
950 1096
951 return 0; 1097 return 0;
@@ -953,24 +1099,41 @@ int ipmi_set_gets_events(ipmi_user_t user, int val)
953 1099
954static struct cmd_rcvr *find_cmd_rcvr(ipmi_smi_t intf, 1100static struct cmd_rcvr *find_cmd_rcvr(ipmi_smi_t intf,
955 unsigned char netfn, 1101 unsigned char netfn,
956 unsigned char cmd) 1102 unsigned char cmd,
1103 unsigned char chan)
957{ 1104{
958 struct cmd_rcvr *rcvr; 1105 struct cmd_rcvr *rcvr;
959 1106
960 list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { 1107 list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) {
961 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) 1108 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)
1109 && (rcvr->chans & (1 << chan)))
962 return rcvr; 1110 return rcvr;
963 } 1111 }
964 return NULL; 1112 return NULL;
965} 1113}
966 1114
1115static int is_cmd_rcvr_exclusive(ipmi_smi_t intf,
1116 unsigned char netfn,
1117 unsigned char cmd,
1118 unsigned int chans)
1119{
1120 struct cmd_rcvr *rcvr;
1121
1122 list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) {
1123 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)
1124 && (rcvr->chans & chans))
1125 return 0;
1126 }
1127 return 1;
1128}
1129
967int ipmi_register_for_cmd(ipmi_user_t user, 1130int ipmi_register_for_cmd(ipmi_user_t user,
968 unsigned char netfn, 1131 unsigned char netfn,
969 unsigned char cmd) 1132 unsigned char cmd,
1133 unsigned int chans)
970{ 1134{
971 ipmi_smi_t intf = user->intf; 1135 ipmi_smi_t intf = user->intf;
972 struct cmd_rcvr *rcvr; 1136 struct cmd_rcvr *rcvr;
973 struct cmd_rcvr *entry;
974 int rv = 0; 1137 int rv = 0;
975 1138
976 1139
@@ -979,12 +1142,12 @@ int ipmi_register_for_cmd(ipmi_user_t user,
979 return -ENOMEM; 1142 return -ENOMEM;
980 rcvr->cmd = cmd; 1143 rcvr->cmd = cmd;
981 rcvr->netfn = netfn; 1144 rcvr->netfn = netfn;
1145 rcvr->chans = chans;
982 rcvr->user = user; 1146 rcvr->user = user;
983 1147
984 mutex_lock(&intf->cmd_rcvrs_mutex); 1148 mutex_lock(&intf->cmd_rcvrs_mutex);
985 /* Make sure the command/netfn is not already registered. */ 1149 /* Make sure the command/netfn is not already registered. */
986 entry = find_cmd_rcvr(intf, netfn, cmd); 1150 if (!is_cmd_rcvr_exclusive(intf, netfn, cmd, chans)) {
987 if (entry) {
988 rv = -EBUSY; 1151 rv = -EBUSY;
989 goto out_unlock; 1152 goto out_unlock;
990 } 1153 }
@@ -1001,30 +1164,46 @@ int ipmi_register_for_cmd(ipmi_user_t user,
1001 1164
1002int ipmi_unregister_for_cmd(ipmi_user_t user, 1165int ipmi_unregister_for_cmd(ipmi_user_t user,
1003 unsigned char netfn, 1166 unsigned char netfn,
1004 unsigned char cmd) 1167 unsigned char cmd,
1168 unsigned int chans)
1005{ 1169{
1006 ipmi_smi_t intf = user->intf; 1170 ipmi_smi_t intf = user->intf;
1007 struct cmd_rcvr *rcvr; 1171 struct cmd_rcvr *rcvr;
1172 struct cmd_rcvr *rcvrs = NULL;
1173 int i, rv = -ENOENT;
1008 1174
1009 mutex_lock(&intf->cmd_rcvrs_mutex); 1175 mutex_lock(&intf->cmd_rcvrs_mutex);
1010 /* Make sure the command/netfn is not already registered. */ 1176 for (i = 0; i < IPMI_NUM_CHANNELS; i++) {
1011 rcvr = find_cmd_rcvr(intf, netfn, cmd); 1177 if (((1 << i) & chans) == 0)
1012 if ((rcvr) && (rcvr->user == user)) { 1178 continue;
1013 list_del_rcu(&rcvr->link); 1179 rcvr = find_cmd_rcvr(intf, netfn, cmd, i);
1014 mutex_unlock(&intf->cmd_rcvrs_mutex); 1180 if (rcvr == NULL)
1015 synchronize_rcu(); 1181 continue;
1182 if (rcvr->user == user) {
1183 rv = 0;
1184 rcvr->chans &= ~chans;
1185 if (rcvr->chans == 0) {
1186 list_del_rcu(&rcvr->link);
1187 rcvr->next = rcvrs;
1188 rcvrs = rcvr;
1189 }
1190 }
1191 }
1192 mutex_unlock(&intf->cmd_rcvrs_mutex);
1193 synchronize_rcu();
1194 while (rcvrs) {
1195 rcvr = rcvrs;
1196 rcvrs = rcvr->next;
1016 kfree(rcvr); 1197 kfree(rcvr);
1017 return 0;
1018 } else {
1019 mutex_unlock(&intf->cmd_rcvrs_mutex);
1020 return -ENOENT;
1021 } 1198 }
1199 return rv;
1022} 1200}
1023 1201
1024void ipmi_user_set_run_to_completion(ipmi_user_t user, int val) 1202void ipmi_user_set_run_to_completion(ipmi_user_t user, int val)
1025{ 1203{
1026 ipmi_smi_t intf = user->intf; 1204 ipmi_smi_t intf = user->intf;
1027 intf->handlers->set_run_to_completion(intf->send_info, val); 1205 if (intf->handlers)
1206 intf->handlers->set_run_to_completion(intf->send_info, val);
1028} 1207}
1029 1208
1030static unsigned char 1209static unsigned char
@@ -1135,10 +1314,11 @@ static int i_ipmi_request(ipmi_user_t user,
1135 int retries, 1314 int retries,
1136 unsigned int retry_time_ms) 1315 unsigned int retry_time_ms)
1137{ 1316{
1138 int rv = 0; 1317 int rv = 0;
1139 struct ipmi_smi_msg *smi_msg; 1318 struct ipmi_smi_msg *smi_msg;
1140 struct ipmi_recv_msg *recv_msg; 1319 struct ipmi_recv_msg *recv_msg;
1141 unsigned long flags; 1320 unsigned long flags;
1321 struct ipmi_smi_handlers *handlers;
1142 1322
1143 1323
1144 if (supplied_recv) { 1324 if (supplied_recv) {
@@ -1161,6 +1341,13 @@ static int i_ipmi_request(ipmi_user_t user,
1161 } 1341 }
1162 } 1342 }
1163 1343
1344 rcu_read_lock();
1345 handlers = intf->handlers;
1346 if (!handlers) {
1347 rv = -ENODEV;
1348 goto out_err;
1349 }
1350
1164 recv_msg->user = user; 1351 recv_msg->user = user;
1165 if (user) 1352 if (user)
1166 kref_get(&user->refcount); 1353 kref_get(&user->refcount);
@@ -1203,6 +1390,24 @@ static int i_ipmi_request(ipmi_user_t user,
1203 goto out_err; 1390 goto out_err;
1204 } 1391 }
1205 1392
1393 if (((msg->netfn == IPMI_NETFN_APP_REQUEST)
1394 && ((msg->cmd == IPMI_COLD_RESET_CMD)
1395 || (msg->cmd == IPMI_WARM_RESET_CMD)))
1396 || (msg->netfn == IPMI_NETFN_FIRMWARE_REQUEST))
1397 {
1398 spin_lock_irqsave(&intf->maintenance_mode_lock, flags);
1399 intf->auto_maintenance_timeout
1400 = IPMI_MAINTENANCE_MODE_TIMEOUT;
1401 if (!intf->maintenance_mode
1402 && !intf->maintenance_mode_enable)
1403 {
1404 intf->maintenance_mode_enable = 1;
1405 maintenance_mode_update(intf);
1406 }
1407 spin_unlock_irqrestore(&intf->maintenance_mode_lock,
1408 flags);
1409 }
1410
1206 if ((msg->data_len + 2) > IPMI_MAX_MSG_LENGTH) { 1411 if ((msg->data_len + 2) > IPMI_MAX_MSG_LENGTH) {
1207 spin_lock_irqsave(&intf->counter_lock, flags); 1412 spin_lock_irqsave(&intf->counter_lock, flags);
1208 intf->sent_invalid_commands++; 1413 intf->sent_invalid_commands++;
@@ -1477,11 +1682,14 @@ static int i_ipmi_request(ipmi_user_t user,
1477 printk("\n"); 1682 printk("\n");
1478 } 1683 }
1479#endif 1684#endif
1480 intf->handlers->sender(intf->send_info, smi_msg, priority); 1685
1686 handlers->sender(intf->send_info, smi_msg, priority);
1687 rcu_read_unlock();
1481 1688
1482 return 0; 1689 return 0;
1483 1690
1484 out_err: 1691 out_err:
1692 rcu_read_unlock();
1485 ipmi_free_smi_msg(smi_msg); 1693 ipmi_free_smi_msg(smi_msg);
1486 ipmi_free_recv_msg(recv_msg); 1694 ipmi_free_recv_msg(recv_msg);
1487 return rv; 1695 return rv;
@@ -1561,6 +1769,7 @@ int ipmi_request_supply_msgs(ipmi_user_t user,
1561 -1, 0); 1769 -1, 0);
1562} 1770}
1563 1771
1772#ifdef CONFIG_PROC_FS
1564static int ipmb_file_read_proc(char *page, char **start, off_t off, 1773static int ipmb_file_read_proc(char *page, char **start, off_t off,
1565 int count, int *eof, void *data) 1774 int count, int *eof, void *data)
1566{ 1775{
@@ -1649,6 +1858,7 @@ static int stat_file_read_proc(char *page, char **start, off_t off,
1649 1858
1650 return (out - ((char *) page)); 1859 return (out - ((char *) page));
1651} 1860}
1861#endif /* CONFIG_PROC_FS */
1652 1862
1653int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name, 1863int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
1654 read_proc_t *read_proc, write_proc_t *write_proc, 1864 read_proc_t *read_proc, write_proc_t *write_proc,
@@ -1774,13 +1984,12 @@ static int __find_bmc_prod_dev_id(struct device *dev, void *data)
1774 struct bmc_device *bmc = dev_get_drvdata(dev); 1984 struct bmc_device *bmc = dev_get_drvdata(dev);
1775 1985
1776 return (bmc->id.product_id == id->product_id 1986 return (bmc->id.product_id == id->product_id
1777 && bmc->id.product_id == id->product_id
1778 && bmc->id.device_id == id->device_id); 1987 && bmc->id.device_id == id->device_id);
1779} 1988}
1780 1989
1781static struct bmc_device *ipmi_find_bmc_prod_dev_id( 1990static struct bmc_device *ipmi_find_bmc_prod_dev_id(
1782 struct device_driver *drv, 1991 struct device_driver *drv,
1783 unsigned char product_id, unsigned char device_id) 1992 unsigned int product_id, unsigned char device_id)
1784{ 1993{
1785 struct prod_dev_id id = { 1994 struct prod_dev_id id = {
1786 .product_id = product_id, 1995 .product_id = product_id,
@@ -1811,7 +2020,7 @@ static ssize_t provides_dev_sdrs_show(struct device *dev,
1811 struct bmc_device *bmc = dev_get_drvdata(dev); 2020 struct bmc_device *bmc = dev_get_drvdata(dev);
1812 2021
1813 return snprintf(buf, 10, "%u\n", 2022 return snprintf(buf, 10, "%u\n",
1814 bmc->id.device_revision && 0x80 >> 7); 2023 (bmc->id.device_revision & 0x80) >> 7);
1815} 2024}
1816 2025
1817static ssize_t revision_show(struct device *dev, struct device_attribute *attr, 2026static ssize_t revision_show(struct device *dev, struct device_attribute *attr,
@@ -1820,7 +2029,7 @@ static ssize_t revision_show(struct device *dev, struct device_attribute *attr,
1820 struct bmc_device *bmc = dev_get_drvdata(dev); 2029 struct bmc_device *bmc = dev_get_drvdata(dev);
1821 2030
1822 return snprintf(buf, 20, "%u\n", 2031 return snprintf(buf, 20, "%u\n",
1823 bmc->id.device_revision && 0x0F); 2032 bmc->id.device_revision & 0x0F);
1824} 2033}
1825 2034
1826static ssize_t firmware_rev_show(struct device *dev, 2035static ssize_t firmware_rev_show(struct device *dev,
@@ -1895,12 +2104,10 @@ static ssize_t guid_show(struct device *dev, struct device_attribute *attr,
1895 (long long) bmc->guid[8]); 2104 (long long) bmc->guid[8]);
1896} 2105}
1897 2106
1898static void 2107static void remove_files(struct bmc_device *bmc)
1899cleanup_bmc_device(struct kref *ref)
1900{ 2108{
1901 struct bmc_device *bmc; 2109 if (!bmc->dev)
1902 2110 return;
1903 bmc = container_of(ref, struct bmc_device, refcount);
1904 2111
1905 device_remove_file(&bmc->dev->dev, 2112 device_remove_file(&bmc->dev->dev,
1906 &bmc->device_id_attr); 2113 &bmc->device_id_attr);
@@ -1918,12 +2125,23 @@ cleanup_bmc_device(struct kref *ref)
1918 &bmc->manufacturer_id_attr); 2125 &bmc->manufacturer_id_attr);
1919 device_remove_file(&bmc->dev->dev, 2126 device_remove_file(&bmc->dev->dev,
1920 &bmc->product_id_attr); 2127 &bmc->product_id_attr);
2128
1921 if (bmc->id.aux_firmware_revision_set) 2129 if (bmc->id.aux_firmware_revision_set)
1922 device_remove_file(&bmc->dev->dev, 2130 device_remove_file(&bmc->dev->dev,
1923 &bmc->aux_firmware_rev_attr); 2131 &bmc->aux_firmware_rev_attr);
1924 if (bmc->guid_set) 2132 if (bmc->guid_set)
1925 device_remove_file(&bmc->dev->dev, 2133 device_remove_file(&bmc->dev->dev,
1926 &bmc->guid_attr); 2134 &bmc->guid_attr);
2135}
2136
2137static void
2138cleanup_bmc_device(struct kref *ref)
2139{
2140 struct bmc_device *bmc;
2141
2142 bmc = container_of(ref, struct bmc_device, refcount);
2143
2144 remove_files(bmc);
1927 platform_device_unregister(bmc->dev); 2145 platform_device_unregister(bmc->dev);
1928 kfree(bmc); 2146 kfree(bmc);
1929} 2147}
@@ -1932,7 +2150,11 @@ static void ipmi_bmc_unregister(ipmi_smi_t intf)
1932{ 2150{
1933 struct bmc_device *bmc = intf->bmc; 2151 struct bmc_device *bmc = intf->bmc;
1934 2152
1935 sysfs_remove_link(&intf->si_dev->kobj, "bmc"); 2153 if (intf->sysfs_name) {
2154 sysfs_remove_link(&intf->si_dev->kobj, intf->sysfs_name);
2155 kfree(intf->sysfs_name);
2156 intf->sysfs_name = NULL;
2157 }
1936 if (intf->my_dev_name) { 2158 if (intf->my_dev_name) {
1937 sysfs_remove_link(&bmc->dev->dev.kobj, intf->my_dev_name); 2159 sysfs_remove_link(&bmc->dev->dev.kobj, intf->my_dev_name);
1938 kfree(intf->my_dev_name); 2160 kfree(intf->my_dev_name);
@@ -1941,10 +2163,135 @@ static void ipmi_bmc_unregister(ipmi_smi_t intf)
1941 2163
1942 mutex_lock(&ipmidriver_mutex); 2164 mutex_lock(&ipmidriver_mutex);
1943 kref_put(&bmc->refcount, cleanup_bmc_device); 2165 kref_put(&bmc->refcount, cleanup_bmc_device);
2166 intf->bmc = NULL;
1944 mutex_unlock(&ipmidriver_mutex); 2167 mutex_unlock(&ipmidriver_mutex);
1945} 2168}
1946 2169
1947static int ipmi_bmc_register(ipmi_smi_t intf) 2170static int create_files(struct bmc_device *bmc)
2171{
2172 int err;
2173
2174 bmc->device_id_attr.attr.name = "device_id";
2175 bmc->device_id_attr.attr.owner = THIS_MODULE;
2176 bmc->device_id_attr.attr.mode = S_IRUGO;
2177 bmc->device_id_attr.show = device_id_show;
2178
2179 bmc->provides_dev_sdrs_attr.attr.name = "provides_device_sdrs";
2180 bmc->provides_dev_sdrs_attr.attr.owner = THIS_MODULE;
2181 bmc->provides_dev_sdrs_attr.attr.mode = S_IRUGO;
2182 bmc->provides_dev_sdrs_attr.show = provides_dev_sdrs_show;
2183
2184 bmc->revision_attr.attr.name = "revision";
2185 bmc->revision_attr.attr.owner = THIS_MODULE;
2186 bmc->revision_attr.attr.mode = S_IRUGO;
2187 bmc->revision_attr.show = revision_show;
2188
2189 bmc->firmware_rev_attr.attr.name = "firmware_revision";
2190 bmc->firmware_rev_attr.attr.owner = THIS_MODULE;
2191 bmc->firmware_rev_attr.attr.mode = S_IRUGO;
2192 bmc->firmware_rev_attr.show = firmware_rev_show;
2193
2194 bmc->version_attr.attr.name = "ipmi_version";
2195 bmc->version_attr.attr.owner = THIS_MODULE;
2196 bmc->version_attr.attr.mode = S_IRUGO;
2197 bmc->version_attr.show = ipmi_version_show;
2198
2199 bmc->add_dev_support_attr.attr.name = "additional_device_support";
2200 bmc->add_dev_support_attr.attr.owner = THIS_MODULE;
2201 bmc->add_dev_support_attr.attr.mode = S_IRUGO;
2202 bmc->add_dev_support_attr.show = add_dev_support_show;
2203
2204 bmc->manufacturer_id_attr.attr.name = "manufacturer_id";
2205 bmc->manufacturer_id_attr.attr.owner = THIS_MODULE;
2206 bmc->manufacturer_id_attr.attr.mode = S_IRUGO;
2207 bmc->manufacturer_id_attr.show = manufacturer_id_show;
2208
2209 bmc->product_id_attr.attr.name = "product_id";
2210 bmc->product_id_attr.attr.owner = THIS_MODULE;
2211 bmc->product_id_attr.attr.mode = S_IRUGO;
2212 bmc->product_id_attr.show = product_id_show;
2213
2214 bmc->guid_attr.attr.name = "guid";
2215 bmc->guid_attr.attr.owner = THIS_MODULE;
2216 bmc->guid_attr.attr.mode = S_IRUGO;
2217 bmc->guid_attr.show = guid_show;
2218
2219 bmc->aux_firmware_rev_attr.attr.name = "aux_firmware_revision";
2220 bmc->aux_firmware_rev_attr.attr.owner = THIS_MODULE;
2221 bmc->aux_firmware_rev_attr.attr.mode = S_IRUGO;
2222 bmc->aux_firmware_rev_attr.show = aux_firmware_rev_show;
2223
2224 err = device_create_file(&bmc->dev->dev,
2225 &bmc->device_id_attr);
2226 if (err) goto out;
2227 err = device_create_file(&bmc->dev->dev,
2228 &bmc->provides_dev_sdrs_attr);
2229 if (err) goto out_devid;
2230 err = device_create_file(&bmc->dev->dev,
2231 &bmc->revision_attr);
2232 if (err) goto out_sdrs;
2233 err = device_create_file(&bmc->dev->dev,
2234 &bmc->firmware_rev_attr);
2235 if (err) goto out_rev;
2236 err = device_create_file(&bmc->dev->dev,
2237 &bmc->version_attr);
2238 if (err) goto out_firm;
2239 err = device_create_file(&bmc->dev->dev,
2240 &bmc->add_dev_support_attr);
2241 if (err) goto out_version;
2242 err = device_create_file(&bmc->dev->dev,
2243 &bmc->manufacturer_id_attr);
2244 if (err) goto out_add_dev;
2245 err = device_create_file(&bmc->dev->dev,
2246 &bmc->product_id_attr);
2247 if (err) goto out_manu;
2248 if (bmc->id.aux_firmware_revision_set) {
2249 err = device_create_file(&bmc->dev->dev,
2250 &bmc->aux_firmware_rev_attr);
2251 if (err) goto out_prod_id;
2252 }
2253 if (bmc->guid_set) {
2254 err = device_create_file(&bmc->dev->dev,
2255 &bmc->guid_attr);
2256 if (err) goto out_aux_firm;
2257 }
2258
2259 return 0;
2260
2261out_aux_firm:
2262 if (bmc->id.aux_firmware_revision_set)
2263 device_remove_file(&bmc->dev->dev,
2264 &bmc->aux_firmware_rev_attr);
2265out_prod_id:
2266 device_remove_file(&bmc->dev->dev,
2267 &bmc->product_id_attr);
2268out_manu:
2269 device_remove_file(&bmc->dev->dev,
2270 &bmc->manufacturer_id_attr);
2271out_add_dev:
2272 device_remove_file(&bmc->dev->dev,
2273 &bmc->add_dev_support_attr);
2274out_version:
2275 device_remove_file(&bmc->dev->dev,
2276 &bmc->version_attr);
2277out_firm:
2278 device_remove_file(&bmc->dev->dev,
2279 &bmc->firmware_rev_attr);
2280out_rev:
2281 device_remove_file(&bmc->dev->dev,
2282 &bmc->revision_attr);
2283out_sdrs:
2284 device_remove_file(&bmc->dev->dev,
2285 &bmc->provides_dev_sdrs_attr);
2286out_devid:
2287 device_remove_file(&bmc->dev->dev,
2288 &bmc->device_id_attr);
2289out:
2290 return err;
2291}
2292
2293static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum,
2294 const char *sysfs_name)
1948{ 2295{
1949 int rv; 2296 int rv;
1950 struct bmc_device *bmc = intf->bmc; 2297 struct bmc_device *bmc = intf->bmc;
@@ -1984,9 +2331,38 @@ static int ipmi_bmc_register(ipmi_smi_t intf)
1984 bmc->id.product_id, 2331 bmc->id.product_id,
1985 bmc->id.device_id); 2332 bmc->id.device_id);
1986 } else { 2333 } else {
1987 bmc->dev = platform_device_alloc("ipmi_bmc", 2334 char name[14];
1988 bmc->id.device_id); 2335 unsigned char orig_dev_id = bmc->id.device_id;
2336 int warn_printed = 0;
2337
2338 snprintf(name, sizeof(name),
2339 "ipmi_bmc.%4.4x", bmc->id.product_id);
2340
2341 while (ipmi_find_bmc_prod_dev_id(&ipmidriver,
2342 bmc->id.product_id,
2343 bmc->id.device_id)) {
2344 if (!warn_printed) {
2345 printk(KERN_WARNING PFX
2346 "This machine has two different BMCs"
2347 " with the same product id and device"
2348 " id. This is an error in the"
2349 " firmware, but incrementing the"
2350 " device id to work around the problem."
2351 " Prod ID = 0x%x, Dev ID = 0x%x\n",
2352 bmc->id.product_id, bmc->id.device_id);
2353 warn_printed = 1;
2354 }
2355 bmc->id.device_id++; /* Wraps at 255 */
2356 if (bmc->id.device_id == orig_dev_id) {
2357 printk(KERN_ERR PFX
2358 "Out of device ids!\n");
2359 break;
2360 }
2361 }
2362
2363 bmc->dev = platform_device_alloc(name, bmc->id.device_id);
1989 if (!bmc->dev) { 2364 if (!bmc->dev) {
2365 mutex_unlock(&ipmidriver_mutex);
1990 printk(KERN_ERR 2366 printk(KERN_ERR
1991 "ipmi_msghandler:" 2367 "ipmi_msghandler:"
1992 " Unable to allocate platform device\n"); 2368 " Unable to allocate platform device\n");
@@ -1996,9 +2372,11 @@ static int ipmi_bmc_register(ipmi_smi_t intf)
1996 dev_set_drvdata(&bmc->dev->dev, bmc); 2372 dev_set_drvdata(&bmc->dev->dev, bmc);
1997 kref_init(&bmc->refcount); 2373 kref_init(&bmc->refcount);
1998 2374
1999 rv = platform_device_register(bmc->dev); 2375 rv = platform_device_add(bmc->dev);
2000 mutex_unlock(&ipmidriver_mutex); 2376 mutex_unlock(&ipmidriver_mutex);
2001 if (rv) { 2377 if (rv) {
2378 platform_device_put(bmc->dev);
2379 bmc->dev = NULL;
2002 printk(KERN_ERR 2380 printk(KERN_ERR
2003 "ipmi_msghandler:" 2381 "ipmi_msghandler:"
2004 " Unable to register bmc device: %d\n", 2382 " Unable to register bmc device: %d\n",
@@ -2008,80 +2386,14 @@ static int ipmi_bmc_register(ipmi_smi_t intf)
2008 return rv; 2386 return rv;
2009 } 2387 }
2010 2388
2011 bmc->device_id_attr.attr.name = "device_id"; 2389 rv = create_files(bmc);
2012 bmc->device_id_attr.attr.owner = THIS_MODULE; 2390 if (rv) {
2013 bmc->device_id_attr.attr.mode = S_IRUGO; 2391 mutex_lock(&ipmidriver_mutex);
2014 bmc->device_id_attr.show = device_id_show; 2392 platform_device_unregister(bmc->dev);
2015 2393 mutex_unlock(&ipmidriver_mutex);
2016 bmc->provides_dev_sdrs_attr.attr.name = "provides_device_sdrs"; 2394
2017 bmc->provides_dev_sdrs_attr.attr.owner = THIS_MODULE; 2395 return rv;
2018 bmc->provides_dev_sdrs_attr.attr.mode = S_IRUGO; 2396 }
2019 bmc->provides_dev_sdrs_attr.show = provides_dev_sdrs_show;
2020
2021
2022 bmc->revision_attr.attr.name = "revision";
2023 bmc->revision_attr.attr.owner = THIS_MODULE;
2024 bmc->revision_attr.attr.mode = S_IRUGO;
2025 bmc->revision_attr.show = revision_show;
2026
2027 bmc->firmware_rev_attr.attr.name = "firmware_revision";
2028 bmc->firmware_rev_attr.attr.owner = THIS_MODULE;
2029 bmc->firmware_rev_attr.attr.mode = S_IRUGO;
2030 bmc->firmware_rev_attr.show = firmware_rev_show;
2031
2032 bmc->version_attr.attr.name = "ipmi_version";
2033 bmc->version_attr.attr.owner = THIS_MODULE;
2034 bmc->version_attr.attr.mode = S_IRUGO;
2035 bmc->version_attr.show = ipmi_version_show;
2036
2037 bmc->add_dev_support_attr.attr.name
2038 = "additional_device_support";
2039 bmc->add_dev_support_attr.attr.owner = THIS_MODULE;
2040 bmc->add_dev_support_attr.attr.mode = S_IRUGO;
2041 bmc->add_dev_support_attr.show = add_dev_support_show;
2042
2043 bmc->manufacturer_id_attr.attr.name = "manufacturer_id";
2044 bmc->manufacturer_id_attr.attr.owner = THIS_MODULE;
2045 bmc->manufacturer_id_attr.attr.mode = S_IRUGO;
2046 bmc->manufacturer_id_attr.show = manufacturer_id_show;
2047
2048 bmc->product_id_attr.attr.name = "product_id";
2049 bmc->product_id_attr.attr.owner = THIS_MODULE;
2050 bmc->product_id_attr.attr.mode = S_IRUGO;
2051 bmc->product_id_attr.show = product_id_show;
2052
2053 bmc->guid_attr.attr.name = "guid";
2054 bmc->guid_attr.attr.owner = THIS_MODULE;
2055 bmc->guid_attr.attr.mode = S_IRUGO;
2056 bmc->guid_attr.show = guid_show;
2057
2058 bmc->aux_firmware_rev_attr.attr.name = "aux_firmware_revision";
2059 bmc->aux_firmware_rev_attr.attr.owner = THIS_MODULE;
2060 bmc->aux_firmware_rev_attr.attr.mode = S_IRUGO;
2061 bmc->aux_firmware_rev_attr.show = aux_firmware_rev_show;
2062
2063 device_create_file(&bmc->dev->dev,
2064 &bmc->device_id_attr);
2065 device_create_file(&bmc->dev->dev,
2066 &bmc->provides_dev_sdrs_attr);
2067 device_create_file(&bmc->dev->dev,
2068 &bmc->revision_attr);
2069 device_create_file(&bmc->dev->dev,
2070 &bmc->firmware_rev_attr);
2071 device_create_file(&bmc->dev->dev,
2072 &bmc->version_attr);
2073 device_create_file(&bmc->dev->dev,
2074 &bmc->add_dev_support_attr);
2075 device_create_file(&bmc->dev->dev,
2076 &bmc->manufacturer_id_attr);
2077 device_create_file(&bmc->dev->dev,
2078 &bmc->product_id_attr);
2079 if (bmc->id.aux_firmware_revision_set)
2080 device_create_file(&bmc->dev->dev,
2081 &bmc->aux_firmware_rev_attr);
2082 if (bmc->guid_set)
2083 device_create_file(&bmc->dev->dev,
2084 &bmc->guid_attr);
2085 2397
2086 printk(KERN_INFO 2398 printk(KERN_INFO
2087 "ipmi: Found new BMC (man_id: 0x%6.6x, " 2399 "ipmi: Found new BMC (man_id: 0x%6.6x, "
@@ -2095,29 +2407,44 @@ static int ipmi_bmc_register(ipmi_smi_t intf)
2095 * create symlink from system interface device to bmc device 2407 * create symlink from system interface device to bmc device
2096 * and back. 2408 * and back.
2097 */ 2409 */
2410 intf->sysfs_name = kstrdup(sysfs_name, GFP_KERNEL);
2411 if (!intf->sysfs_name) {
2412 rv = -ENOMEM;
2413 printk(KERN_ERR
2414 "ipmi_msghandler: allocate link to BMC: %d\n",
2415 rv);
2416 goto out_err;
2417 }
2418
2098 rv = sysfs_create_link(&intf->si_dev->kobj, 2419 rv = sysfs_create_link(&intf->si_dev->kobj,
2099 &bmc->dev->dev.kobj, "bmc"); 2420 &bmc->dev->dev.kobj, intf->sysfs_name);
2100 if (rv) { 2421 if (rv) {
2422 kfree(intf->sysfs_name);
2423 intf->sysfs_name = NULL;
2101 printk(KERN_ERR 2424 printk(KERN_ERR
2102 "ipmi_msghandler: Unable to create bmc symlink: %d\n", 2425 "ipmi_msghandler: Unable to create bmc symlink: %d\n",
2103 rv); 2426 rv);
2104 goto out_err; 2427 goto out_err;
2105 } 2428 }
2106 2429
2107 size = snprintf(dummy, 0, "ipmi%d", intf->intf_num); 2430 size = snprintf(dummy, 0, "ipmi%d", ifnum);
2108 intf->my_dev_name = kmalloc(size+1, GFP_KERNEL); 2431 intf->my_dev_name = kmalloc(size+1, GFP_KERNEL);
2109 if (!intf->my_dev_name) { 2432 if (!intf->my_dev_name) {
2433 kfree(intf->sysfs_name);
2434 intf->sysfs_name = NULL;
2110 rv = -ENOMEM; 2435 rv = -ENOMEM;
2111 printk(KERN_ERR 2436 printk(KERN_ERR
2112 "ipmi_msghandler: allocate link from BMC: %d\n", 2437 "ipmi_msghandler: allocate link from BMC: %d\n",
2113 rv); 2438 rv);
2114 goto out_err; 2439 goto out_err;
2115 } 2440 }
2116 snprintf(intf->my_dev_name, size+1, "ipmi%d", intf->intf_num); 2441 snprintf(intf->my_dev_name, size+1, "ipmi%d", ifnum);
2117 2442
2118 rv = sysfs_create_link(&bmc->dev->dev.kobj, &intf->si_dev->kobj, 2443 rv = sysfs_create_link(&bmc->dev->dev.kobj, &intf->si_dev->kobj,
2119 intf->my_dev_name); 2444 intf->my_dev_name);
2120 if (rv) { 2445 if (rv) {
2446 kfree(intf->sysfs_name);
2447 intf->sysfs_name = NULL;
2121 kfree(intf->my_dev_name); 2448 kfree(intf->my_dev_name);
2122 intf->my_dev_name = NULL; 2449 intf->my_dev_name = NULL;
2123 printk(KERN_ERR 2450 printk(KERN_ERR
@@ -2302,17 +2629,14 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
2302 void *send_info, 2629 void *send_info,
2303 struct ipmi_device_id *device_id, 2630 struct ipmi_device_id *device_id,
2304 struct device *si_dev, 2631 struct device *si_dev,
2632 const char *sysfs_name,
2305 unsigned char slave_addr) 2633 unsigned char slave_addr)
2306{ 2634{
2307 int i, j; 2635 int i, j;
2308 int rv; 2636 int rv;
2309 ipmi_smi_t intf; 2637 ipmi_smi_t intf;
2310 unsigned long flags; 2638 ipmi_smi_t tintf;
2311 int version_major; 2639 struct list_head *link;
2312 int version_minor;
2313
2314 version_major = ipmi_version_major(device_id);
2315 version_minor = ipmi_version_minor(device_id);
2316 2640
2317 /* Make sure the driver is actually initialized, this handles 2641 /* Make sure the driver is actually initialized, this handles
2318 problems with initialization order. */ 2642 problems with initialization order. */
@@ -2330,12 +2654,16 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
2330 if (!intf) 2654 if (!intf)
2331 return -ENOMEM; 2655 return -ENOMEM;
2332 memset(intf, 0, sizeof(*intf)); 2656 memset(intf, 0, sizeof(*intf));
2657
2658 intf->ipmi_version_major = ipmi_version_major(device_id);
2659 intf->ipmi_version_minor = ipmi_version_minor(device_id);
2660
2333 intf->bmc = kzalloc(sizeof(*intf->bmc), GFP_KERNEL); 2661 intf->bmc = kzalloc(sizeof(*intf->bmc), GFP_KERNEL);
2334 if (!intf->bmc) { 2662 if (!intf->bmc) {
2335 kfree(intf); 2663 kfree(intf);
2336 return -ENOMEM; 2664 return -ENOMEM;
2337 } 2665 }
2338 intf->intf_num = -1; 2666 intf->intf_num = -1; /* Mark it invalid for now. */
2339 kref_init(&intf->refcount); 2667 kref_init(&intf->refcount);
2340 intf->bmc->id = *device_id; 2668 intf->bmc->id = *device_id;
2341 intf->si_dev = si_dev; 2669 intf->si_dev = si_dev;
@@ -2363,26 +2691,30 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
2363 INIT_LIST_HEAD(&intf->waiting_events); 2691 INIT_LIST_HEAD(&intf->waiting_events);
2364 intf->waiting_events_count = 0; 2692 intf->waiting_events_count = 0;
2365 mutex_init(&intf->cmd_rcvrs_mutex); 2693 mutex_init(&intf->cmd_rcvrs_mutex);
2694 spin_lock_init(&intf->maintenance_mode_lock);
2366 INIT_LIST_HEAD(&intf->cmd_rcvrs); 2695 INIT_LIST_HEAD(&intf->cmd_rcvrs);
2367 init_waitqueue_head(&intf->waitq); 2696 init_waitqueue_head(&intf->waitq);
2368 2697
2369 spin_lock_init(&intf->counter_lock); 2698 spin_lock_init(&intf->counter_lock);
2370 intf->proc_dir = NULL; 2699 intf->proc_dir = NULL;
2371 2700
2372 rv = -ENOMEM; 2701 mutex_lock(&smi_watchers_mutex);
2373 spin_lock_irqsave(&interfaces_lock, flags); 2702 mutex_lock(&ipmi_interfaces_mutex);
2374 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 2703 /* Look for a hole in the numbers. */
2375 if (ipmi_interfaces[i] == NULL) { 2704 i = 0;
2376 intf->intf_num = i; 2705 link = &ipmi_interfaces;
2377 /* Reserve the entry till we are done. */ 2706 list_for_each_entry_rcu(tintf, &ipmi_interfaces, link) {
2378 ipmi_interfaces[i] = IPMI_INVALID_INTERFACE_ENTRY; 2707 if (tintf->intf_num != i) {
2379 rv = 0; 2708 link = &tintf->link;
2380 break; 2709 break;
2381 } 2710 }
2711 i++;
2382 } 2712 }
2383 spin_unlock_irqrestore(&interfaces_lock, flags); 2713 /* Add the new interface in numeric order. */
2384 if (rv) 2714 if (i == 0)
2385 goto out; 2715 list_add_rcu(&intf->link, &ipmi_interfaces);
2716 else
2717 list_add_tail_rcu(&intf->link, link);
2386 2718
2387 rv = handlers->start_processing(send_info, intf); 2719 rv = handlers->start_processing(send_info, intf);
2388 if (rv) 2720 if (rv)
@@ -2390,8 +2722,9 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
2390 2722
2391 get_guid(intf); 2723 get_guid(intf);
2392 2724
2393 if ((version_major > 1) 2725 if ((intf->ipmi_version_major > 1)
2394 || ((version_major == 1) && (version_minor >= 5))) 2726 || ((intf->ipmi_version_major == 1)
2727 && (intf->ipmi_version_minor >= 5)))
2395 { 2728 {
2396 /* Start scanning the channels to see what is 2729 /* Start scanning the channels to see what is
2397 available. */ 2730 available. */
@@ -2414,64 +2747,67 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
2414 if (rv == 0) 2747 if (rv == 0)
2415 rv = add_proc_entries(intf, i); 2748 rv = add_proc_entries(intf, i);
2416 2749
2417 rv = ipmi_bmc_register(intf); 2750 rv = ipmi_bmc_register(intf, i, sysfs_name);
2418 2751
2419 out: 2752 out:
2420 if (rv) { 2753 if (rv) {
2421 if (intf->proc_dir) 2754 if (intf->proc_dir)
2422 remove_proc_entries(intf); 2755 remove_proc_entries(intf);
2756 intf->handlers = NULL;
2757 list_del_rcu(&intf->link);
2758 mutex_unlock(&ipmi_interfaces_mutex);
2759 mutex_unlock(&smi_watchers_mutex);
2760 synchronize_rcu();
2423 kref_put(&intf->refcount, intf_free); 2761 kref_put(&intf->refcount, intf_free);
2424 if (i < MAX_IPMI_INTERFACES) {
2425 spin_lock_irqsave(&interfaces_lock, flags);
2426 ipmi_interfaces[i] = NULL;
2427 spin_unlock_irqrestore(&interfaces_lock, flags);
2428 }
2429 } else { 2762 } else {
2430 spin_lock_irqsave(&interfaces_lock, flags); 2763 /* After this point the interface is legal to use. */
2431 ipmi_interfaces[i] = intf; 2764 intf->intf_num = i;
2432 spin_unlock_irqrestore(&interfaces_lock, flags); 2765 mutex_unlock(&ipmi_interfaces_mutex);
2433 call_smi_watchers(i, intf->si_dev); 2766 call_smi_watchers(i, intf->si_dev);
2767 mutex_unlock(&smi_watchers_mutex);
2434 } 2768 }
2435 2769
2436 return rv; 2770 return rv;
2437} 2771}
2438 2772
2773static void cleanup_smi_msgs(ipmi_smi_t intf)
2774{
2775 int i;
2776 struct seq_table *ent;
2777
2778 /* No need for locks, the interface is down. */
2779 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) {
2780 ent = &(intf->seq_table[i]);
2781 if (!ent->inuse)
2782 continue;
2783 deliver_err_response(ent->recv_msg, IPMI_ERR_UNSPECIFIED);
2784 }
2785}
2786
2439int ipmi_unregister_smi(ipmi_smi_t intf) 2787int ipmi_unregister_smi(ipmi_smi_t intf)
2440{ 2788{
2441 int i;
2442 struct ipmi_smi_watcher *w; 2789 struct ipmi_smi_watcher *w;
2443 unsigned long flags; 2790 int intf_num = intf->intf_num;
2444 2791
2445 ipmi_bmc_unregister(intf); 2792 ipmi_bmc_unregister(intf);
2446 2793
2447 spin_lock_irqsave(&interfaces_lock, flags); 2794 mutex_lock(&smi_watchers_mutex);
2448 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 2795 mutex_lock(&ipmi_interfaces_mutex);
2449 if (ipmi_interfaces[i] == intf) { 2796 intf->intf_num = -1;
2450 /* Set the interface number reserved until we 2797 intf->handlers = NULL;
2451 * are done. */ 2798 list_del_rcu(&intf->link);
2452 ipmi_interfaces[i] = IPMI_INVALID_INTERFACE_ENTRY; 2799 mutex_unlock(&ipmi_interfaces_mutex);
2453 intf->intf_num = -1; 2800 synchronize_rcu();
2454 break;
2455 }
2456 }
2457 spin_unlock_irqrestore(&interfaces_lock,flags);
2458 2801
2459 if (i == MAX_IPMI_INTERFACES) 2802 cleanup_smi_msgs(intf);
2460 return -ENODEV;
2461 2803
2462 remove_proc_entries(intf); 2804 remove_proc_entries(intf);
2463 2805
2464 /* Call all the watcher interfaces to tell them that 2806 /* Call all the watcher interfaces to tell them that
2465 an interface is gone. */ 2807 an interface is gone. */
2466 down_read(&smi_watchers_sem);
2467 list_for_each_entry(w, &smi_watchers, link) 2808 list_for_each_entry(w, &smi_watchers, link)
2468 w->smi_gone(i); 2809 w->smi_gone(intf_num);
2469 up_read(&smi_watchers_sem); 2810 mutex_unlock(&smi_watchers_mutex);
2470
2471 /* Allow the entry to be reused now. */
2472 spin_lock_irqsave(&interfaces_lock, flags);
2473 ipmi_interfaces[i] = NULL;
2474 spin_unlock_irqrestore(&interfaces_lock,flags);
2475 2811
2476 kref_put(&intf->refcount, intf_free); 2812 kref_put(&intf->refcount, intf_free);
2477 return 0; 2813 return 0;
@@ -2548,10 +2884,12 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
2548 int rv = 0; 2884 int rv = 0;
2549 unsigned char netfn; 2885 unsigned char netfn;
2550 unsigned char cmd; 2886 unsigned char cmd;
2887 unsigned char chan;
2551 ipmi_user_t user = NULL; 2888 ipmi_user_t user = NULL;
2552 struct ipmi_ipmb_addr *ipmb_addr; 2889 struct ipmi_ipmb_addr *ipmb_addr;
2553 struct ipmi_recv_msg *recv_msg; 2890 struct ipmi_recv_msg *recv_msg;
2554 unsigned long flags; 2891 unsigned long flags;
2892 struct ipmi_smi_handlers *handlers;
2555 2893
2556 if (msg->rsp_size < 10) { 2894 if (msg->rsp_size < 10) {
2557 /* Message not big enough, just ignore it. */ 2895 /* Message not big enough, just ignore it. */
@@ -2568,9 +2906,10 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
2568 2906
2569 netfn = msg->rsp[4] >> 2; 2907 netfn = msg->rsp[4] >> 2;
2570 cmd = msg->rsp[8]; 2908 cmd = msg->rsp[8];
2909 chan = msg->rsp[3] & 0xf;
2571 2910
2572 rcu_read_lock(); 2911 rcu_read_lock();
2573 rcvr = find_cmd_rcvr(intf, netfn, cmd); 2912 rcvr = find_cmd_rcvr(intf, netfn, cmd, chan);
2574 if (rcvr) { 2913 if (rcvr) {
2575 user = rcvr->user; 2914 user = rcvr->user;
2576 kref_get(&user->refcount); 2915 kref_get(&user->refcount);
@@ -2607,10 +2946,16 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
2607 printk("\n"); 2946 printk("\n");
2608 } 2947 }
2609#endif 2948#endif
2610 intf->handlers->sender(intf->send_info, msg, 0); 2949 rcu_read_lock();
2611 2950 handlers = intf->handlers;
2612 rv = -1; /* We used the message, so return the value that 2951 if (handlers) {
2613 causes it to not be freed or queued. */ 2952 handlers->sender(intf->send_info, msg, 0);
2953 /* We used the message, so return the value
2954 that causes it to not be freed or
2955 queued. */
2956 rv = -1;
2957 }
2958 rcu_read_unlock();
2614 } else { 2959 } else {
2615 /* Deliver the message to the user. */ 2960 /* Deliver the message to the user. */
2616 spin_lock_irqsave(&intf->counter_lock, flags); 2961 spin_lock_irqsave(&intf->counter_lock, flags);
@@ -2728,6 +3073,7 @@ static int handle_lan_get_msg_cmd(ipmi_smi_t intf,
2728 int rv = 0; 3073 int rv = 0;
2729 unsigned char netfn; 3074 unsigned char netfn;
2730 unsigned char cmd; 3075 unsigned char cmd;
3076 unsigned char chan;
2731 ipmi_user_t user = NULL; 3077 ipmi_user_t user = NULL;
2732 struct ipmi_lan_addr *lan_addr; 3078 struct ipmi_lan_addr *lan_addr;
2733 struct ipmi_recv_msg *recv_msg; 3079 struct ipmi_recv_msg *recv_msg;
@@ -2748,9 +3094,10 @@ static int handle_lan_get_msg_cmd(ipmi_smi_t intf,
2748 3094
2749 netfn = msg->rsp[6] >> 2; 3095 netfn = msg->rsp[6] >> 2;
2750 cmd = msg->rsp[10]; 3096 cmd = msg->rsp[10];
3097 chan = msg->rsp[3] & 0xf;
2751 3098
2752 rcu_read_lock(); 3099 rcu_read_lock();
2753 rcvr = find_cmd_rcvr(intf, netfn, cmd); 3100 rcvr = find_cmd_rcvr(intf, netfn, cmd, chan);
2754 if (rcvr) { 3101 if (rcvr) {
2755 user = rcvr->user; 3102 user = rcvr->user;
2756 kref_get(&user->refcount); 3103 kref_get(&user->refcount);
@@ -3131,7 +3478,9 @@ void ipmi_smi_msg_received(ipmi_smi_t intf,
3131 report the error immediately. */ 3478 report the error immediately. */
3132 if ((msg->rsp_size >= 3) && (msg->rsp[2] != 0) 3479 if ((msg->rsp_size >= 3) && (msg->rsp[2] != 0)
3133 && (msg->rsp[2] != IPMI_NODE_BUSY_ERR) 3480 && (msg->rsp[2] != IPMI_NODE_BUSY_ERR)
3134 && (msg->rsp[2] != IPMI_LOST_ARBITRATION_ERR)) 3481 && (msg->rsp[2] != IPMI_LOST_ARBITRATION_ERR)
3482 && (msg->rsp[2] != IPMI_BUS_ERR)
3483 && (msg->rsp[2] != IPMI_NAK_ON_WRITE_ERR))
3135 { 3484 {
3136 int chan = msg->rsp[3] & 0xf; 3485 int chan = msg->rsp[3] & 0xf;
3137 3486
@@ -3196,16 +3545,6 @@ void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf)
3196 rcu_read_unlock(); 3545 rcu_read_unlock();
3197} 3546}
3198 3547
3199static void
3200handle_msg_timeout(struct ipmi_recv_msg *msg)
3201{
3202 msg->recv_type = IPMI_RESPONSE_RECV_TYPE;
3203 msg->msg_data[0] = IPMI_TIMEOUT_COMPLETION_CODE;
3204 msg->msg.netfn |= 1; /* Convert to a response. */
3205 msg->msg.data_len = 1;
3206 msg->msg.data = msg->msg_data;
3207 deliver_response(msg);
3208}
3209 3548
3210static struct ipmi_smi_msg * 3549static struct ipmi_smi_msg *
3211smi_from_recv_msg(ipmi_smi_t intf, struct ipmi_recv_msg *recv_msg, 3550smi_from_recv_msg(ipmi_smi_t intf, struct ipmi_recv_msg *recv_msg,
@@ -3237,7 +3576,11 @@ static void check_msg_timeout(ipmi_smi_t intf, struct seq_table *ent,
3237 struct list_head *timeouts, long timeout_period, 3576 struct list_head *timeouts, long timeout_period,
3238 int slot, unsigned long *flags) 3577 int slot, unsigned long *flags)
3239{ 3578{
3240 struct ipmi_recv_msg *msg; 3579 struct ipmi_recv_msg *msg;
3580 struct ipmi_smi_handlers *handlers;
3581
3582 if (intf->intf_num == -1)
3583 return;
3241 3584
3242 if (!ent->inuse) 3585 if (!ent->inuse)
3243 return; 3586 return;
@@ -3280,13 +3623,19 @@ static void check_msg_timeout(ipmi_smi_t intf, struct seq_table *ent,
3280 return; 3623 return;
3281 3624
3282 spin_unlock_irqrestore(&intf->seq_lock, *flags); 3625 spin_unlock_irqrestore(&intf->seq_lock, *flags);
3626
3283 /* Send the new message. We send with a zero 3627 /* Send the new message. We send with a zero
3284 * priority. It timed out, I doubt time is 3628 * priority. It timed out, I doubt time is
3285 * that critical now, and high priority 3629 * that critical now, and high priority
3286 * messages are really only for messages to the 3630 * messages are really only for messages to the
3287 * local MC, which don't get resent. */ 3631 * local MC, which don't get resent. */
3288 intf->handlers->sender(intf->send_info, 3632 handlers = intf->handlers;
3289 smi_msg, 0); 3633 if (handlers)
3634 intf->handlers->sender(intf->send_info,
3635 smi_msg, 0);
3636 else
3637 ipmi_free_smi_msg(smi_msg);
3638
3290 spin_lock_irqsave(&intf->seq_lock, *flags); 3639 spin_lock_irqsave(&intf->seq_lock, *flags);
3291 } 3640 }
3292} 3641}
@@ -3298,18 +3647,12 @@ static void ipmi_timeout_handler(long timeout_period)
3298 struct ipmi_recv_msg *msg, *msg2; 3647 struct ipmi_recv_msg *msg, *msg2;
3299 struct ipmi_smi_msg *smi_msg, *smi_msg2; 3648 struct ipmi_smi_msg *smi_msg, *smi_msg2;
3300 unsigned long flags; 3649 unsigned long flags;
3301 int i, j; 3650 int i;
3302 3651
3303 INIT_LIST_HEAD(&timeouts); 3652 INIT_LIST_HEAD(&timeouts);
3304 3653
3305 spin_lock(&interfaces_lock); 3654 rcu_read_lock();
3306 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 3655 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
3307 intf = ipmi_interfaces[i];
3308 if (IPMI_INVALID_INTERFACE(intf))
3309 continue;
3310 kref_get(&intf->refcount);
3311 spin_unlock(&interfaces_lock);
3312
3313 /* See if any waiting messages need to be processed. */ 3656 /* See if any waiting messages need to be processed. */
3314 spin_lock_irqsave(&intf->waiting_msgs_lock, flags); 3657 spin_lock_irqsave(&intf->waiting_msgs_lock, flags);
3315 list_for_each_entry_safe(smi_msg, smi_msg2, 3658 list_for_each_entry_safe(smi_msg, smi_msg2,
@@ -3329,35 +3672,60 @@ static void ipmi_timeout_handler(long timeout_period)
3329 have timed out, putting them in the timeouts 3672 have timed out, putting them in the timeouts
3330 list. */ 3673 list. */
3331 spin_lock_irqsave(&intf->seq_lock, flags); 3674 spin_lock_irqsave(&intf->seq_lock, flags);
3332 for (j = 0; j < IPMI_IPMB_NUM_SEQ; j++) 3675 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++)
3333 check_msg_timeout(intf, &(intf->seq_table[j]), 3676 check_msg_timeout(intf, &(intf->seq_table[i]),
3334 &timeouts, timeout_period, j, 3677 &timeouts, timeout_period, i,
3335 &flags); 3678 &flags);
3336 spin_unlock_irqrestore(&intf->seq_lock, flags); 3679 spin_unlock_irqrestore(&intf->seq_lock, flags);
3337 3680
3338 list_for_each_entry_safe(msg, msg2, &timeouts, link) 3681 list_for_each_entry_safe(msg, msg2, &timeouts, link)
3339 handle_msg_timeout(msg); 3682 deliver_err_response(msg, IPMI_TIMEOUT_COMPLETION_CODE);
3340 3683
3341 kref_put(&intf->refcount, intf_free); 3684 /*
3342 spin_lock(&interfaces_lock); 3685 * Maintenance mode handling. Check the timeout
3686 * optimistically before we claim the lock. It may
3687 * mean a timeout gets missed occasionally, but that
3688 * only means the timeout gets extended by one period
3689 * in that case. No big deal, and it avoids the lock
3690 * most of the time.
3691 */
3692 if (intf->auto_maintenance_timeout > 0) {
3693 spin_lock_irqsave(&intf->maintenance_mode_lock, flags);
3694 if (intf->auto_maintenance_timeout > 0) {
3695 intf->auto_maintenance_timeout
3696 -= timeout_period;
3697 if (!intf->maintenance_mode
3698 && (intf->auto_maintenance_timeout <= 0))
3699 {
3700 intf->maintenance_mode_enable = 0;
3701 maintenance_mode_update(intf);
3702 }
3703 }
3704 spin_unlock_irqrestore(&intf->maintenance_mode_lock,
3705 flags);
3706 }
3343 } 3707 }
3344 spin_unlock(&interfaces_lock); 3708 rcu_read_unlock();
3345} 3709}
3346 3710
3347static void ipmi_request_event(void) 3711static void ipmi_request_event(void)
3348{ 3712{
3349 ipmi_smi_t intf; 3713 ipmi_smi_t intf;
3350 int i; 3714 struct ipmi_smi_handlers *handlers;
3351 3715
3352 spin_lock(&interfaces_lock); 3716 rcu_read_lock();
3353 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 3717 /* Called from the timer, no need to check if handlers is
3354 intf = ipmi_interfaces[i]; 3718 * valid. */
3355 if (IPMI_INVALID_INTERFACE(intf)) 3719 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
3720 /* No event requests when in maintenance mode. */
3721 if (intf->maintenance_mode_enable)
3356 continue; 3722 continue;
3357 3723
3358 intf->handlers->request_events(intf->send_info); 3724 handlers = intf->handlers;
3725 if (handlers)
3726 handlers->request_events(intf->send_info);
3359 } 3727 }
3360 spin_unlock(&interfaces_lock); 3728 rcu_read_unlock();
3361} 3729}
3362 3730
3363static struct timer_list ipmi_timer; 3731static struct timer_list ipmi_timer;
@@ -3486,7 +3854,6 @@ static void send_panic_events(char *str)
3486 struct kernel_ipmi_msg msg; 3854 struct kernel_ipmi_msg msg;
3487 ipmi_smi_t intf; 3855 ipmi_smi_t intf;
3488 unsigned char data[16]; 3856 unsigned char data[16];
3489 int i;
3490 struct ipmi_system_interface_addr *si; 3857 struct ipmi_system_interface_addr *si;
3491 struct ipmi_addr addr; 3858 struct ipmi_addr addr;
3492 struct ipmi_smi_msg smi_msg; 3859 struct ipmi_smi_msg smi_msg;
@@ -3520,9 +3887,9 @@ static void send_panic_events(char *str)
3520 recv_msg.done = dummy_recv_done_handler; 3887 recv_msg.done = dummy_recv_done_handler;
3521 3888
3522 /* For every registered interface, send the event. */ 3889 /* For every registered interface, send the event. */
3523 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 3890 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
3524 intf = ipmi_interfaces[i]; 3891 if (!intf->handlers)
3525 if (IPMI_INVALID_INTERFACE(intf)) 3892 /* Interface is not ready. */
3526 continue; 3893 continue;
3527 3894
3528 /* Send the event announcing the panic. */ 3895 /* Send the event announcing the panic. */
@@ -3547,13 +3914,14 @@ static void send_panic_events(char *str)
3547 if (!str) 3914 if (!str)
3548 return; 3915 return;
3549 3916
3550 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 3917 /* For every registered interface, send the event. */
3918 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
3551 char *p = str; 3919 char *p = str;
3552 struct ipmi_ipmb_addr *ipmb; 3920 struct ipmi_ipmb_addr *ipmb;
3553 int j; 3921 int j;
3554 3922
3555 intf = ipmi_interfaces[i]; 3923 if (intf->intf_num == -1)
3556 if (IPMI_INVALID_INTERFACE(intf)) 3924 /* Interface was not ready yet. */
3557 continue; 3925 continue;
3558 3926
3559 /* First job here is to figure out where to send the 3927 /* First job here is to figure out where to send the
@@ -3673,13 +4041,12 @@ static void send_panic_events(char *str)
3673} 4041}
3674#endif /* CONFIG_IPMI_PANIC_EVENT */ 4042#endif /* CONFIG_IPMI_PANIC_EVENT */
3675 4043
3676static int has_panicked = 0; 4044static int has_panicked;
3677 4045
3678static int panic_event(struct notifier_block *this, 4046static int panic_event(struct notifier_block *this,
3679 unsigned long event, 4047 unsigned long event,
3680 void *ptr) 4048 void *ptr)
3681{ 4049{
3682 int i;
3683 ipmi_smi_t intf; 4050 ipmi_smi_t intf;
3684 4051
3685 if (has_panicked) 4052 if (has_panicked)
@@ -3687,9 +4054,9 @@ static int panic_event(struct notifier_block *this,
3687 has_panicked = 1; 4054 has_panicked = 1;
3688 4055
3689 /* For every registered interface, set it to run to completion. */ 4056 /* For every registered interface, set it to run to completion. */
3690 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 4057 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
3691 intf = ipmi_interfaces[i]; 4058 if (!intf->handlers)
3692 if (IPMI_INVALID_INTERFACE(intf)) 4059 /* Interface is not ready. */
3693 continue; 4060 continue;
3694 4061
3695 intf->handlers->set_run_to_completion(intf->send_info, 1); 4062 intf->handlers->set_run_to_completion(intf->send_info, 1);
@@ -3710,7 +4077,6 @@ static struct notifier_block panic_block = {
3710 4077
3711static int ipmi_init_msghandler(void) 4078static int ipmi_init_msghandler(void)
3712{ 4079{
3713 int i;
3714 int rv; 4080 int rv;
3715 4081
3716 if (initialized) 4082 if (initialized)
@@ -3725,9 +4091,6 @@ static int ipmi_init_msghandler(void)
3725 printk(KERN_INFO "ipmi message handler version " 4091 printk(KERN_INFO "ipmi message handler version "
3726 IPMI_DRIVER_VERSION "\n"); 4092 IPMI_DRIVER_VERSION "\n");
3727 4093
3728 for (i = 0; i < MAX_IPMI_INTERFACES; i++)
3729 ipmi_interfaces[i] = NULL;
3730
3731#ifdef CONFIG_PROC_FS 4094#ifdef CONFIG_PROC_FS
3732 proc_ipmi_root = proc_mkdir("ipmi", NULL); 4095 proc_ipmi_root = proc_mkdir("ipmi", NULL);
3733 if (!proc_ipmi_root) { 4096 if (!proc_ipmi_root) {
diff --git a/drivers/char/ipmi/ipmi_poweroff.c b/drivers/char/ipmi/ipmi_poweroff.c
index 8d941db83457..9d23136e598a 100644
--- a/drivers/char/ipmi/ipmi_poweroff.c
+++ b/drivers/char/ipmi/ipmi_poweroff.c
@@ -43,6 +43,9 @@
43 43
44#define PFX "IPMI poweroff: " 44#define PFX "IPMI poweroff: "
45 45
46static void ipmi_po_smi_gone(int if_num);
47static void ipmi_po_new_smi(int if_num, struct device *device);
48
46/* Definitions for controlling power off (if the system supports it). It 49/* Definitions for controlling power off (if the system supports it). It
47 * conveniently matches the IPMI chassis control values. */ 50 * conveniently matches the IPMI chassis control values. */
48#define IPMI_CHASSIS_POWER_DOWN 0 /* power down, the default. */ 51#define IPMI_CHASSIS_POWER_DOWN 0 /* power down, the default. */
@@ -51,6 +54,37 @@
51/* the IPMI data command */ 54/* the IPMI data command */
52static int poweroff_powercycle; 55static int poweroff_powercycle;
53 56
57/* Which interface to use, -1 means the first we see. */
58static int ifnum_to_use = -1;
59
60/* Our local state. */
61static int ready;
62static ipmi_user_t ipmi_user;
63static int ipmi_ifnum;
64static void (*specific_poweroff_func)(ipmi_user_t user);
65
66/* Holds the old poweroff function so we can restore it on removal. */
67static void (*old_poweroff_func)(void);
68
69static int set_param_ifnum(const char *val, struct kernel_param *kp)
70{
71 int rv = param_set_int(val, kp);
72 if (rv)
73 return rv;
74 if ((ifnum_to_use < 0) || (ifnum_to_use == ipmi_ifnum))
75 return 0;
76
77 ipmi_po_smi_gone(ipmi_ifnum);
78 ipmi_po_new_smi(ifnum_to_use, NULL);
79 return 0;
80}
81
82module_param_call(ifnum_to_use, set_param_ifnum, param_get_int,
83 &ifnum_to_use, 0644);
84MODULE_PARM_DESC(ifnum_to_use, "The interface number to use for the watchdog "
85 "timer. Setting to -1 defaults to the first registered "
86 "interface");
87
54/* parameter definition to allow user to flag power cycle */ 88/* parameter definition to allow user to flag power cycle */
55module_param(poweroff_powercycle, int, 0644); 89module_param(poweroff_powercycle, int, 0644);
56MODULE_PARM_DESC(poweroff_powercycle, " Set to non-zero to enable power cycle instead of power down. Power cycle is contingent on hardware support, otherwise it defaults back to power down."); 90MODULE_PARM_DESC(poweroff_powercycle, " Set to non-zero to enable power cycle instead of power down. Power cycle is contingent on hardware support, otherwise it defaults back to power down.");
@@ -142,6 +176,42 @@ static int ipmi_request_in_rc_mode(ipmi_user_t user,
142#define IPMI_ATCA_GET_ADDR_INFO_CMD 0x01 176#define IPMI_ATCA_GET_ADDR_INFO_CMD 0x01
143#define IPMI_PICMG_ID 0 177#define IPMI_PICMG_ID 0
144 178
179#define IPMI_NETFN_OEM 0x2e
180#define IPMI_ATCA_PPS_GRACEFUL_RESTART 0x11
181#define IPMI_ATCA_PPS_IANA "\x00\x40\x0A"
182#define IPMI_MOTOROLA_MANUFACTURER_ID 0x0000A1
183#define IPMI_MOTOROLA_PPS_IPMC_PRODUCT_ID 0x0051
184
185static void (*atca_oem_poweroff_hook)(ipmi_user_t user);
186
187static void pps_poweroff_atca (ipmi_user_t user)
188{
189 struct ipmi_system_interface_addr smi_addr;
190 struct kernel_ipmi_msg send_msg;
191 int rv;
192 /*
193 * Configure IPMI address for local access
194 */
195 smi_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
196 smi_addr.channel = IPMI_BMC_CHANNEL;
197 smi_addr.lun = 0;
198
199 printk(KERN_INFO PFX "PPS powerdown hook used");
200
201 send_msg.netfn = IPMI_NETFN_OEM;
202 send_msg.cmd = IPMI_ATCA_PPS_GRACEFUL_RESTART;
203 send_msg.data = IPMI_ATCA_PPS_IANA;
204 send_msg.data_len = 3;
205 rv = ipmi_request_in_rc_mode(user,
206 (struct ipmi_addr *) &smi_addr,
207 &send_msg);
208 if (rv && rv != IPMI_UNKNOWN_ERR_COMPLETION_CODE) {
209 printk(KERN_ERR PFX "Unable to send ATCA ,"
210 " IPMI error 0x%x\n", rv);
211 }
212 return;
213}
214
145static int ipmi_atca_detect (ipmi_user_t user) 215static int ipmi_atca_detect (ipmi_user_t user)
146{ 216{
147 struct ipmi_system_interface_addr smi_addr; 217 struct ipmi_system_interface_addr smi_addr;
@@ -167,6 +237,13 @@ static int ipmi_atca_detect (ipmi_user_t user)
167 rv = ipmi_request_wait_for_response(user, 237 rv = ipmi_request_wait_for_response(user,
168 (struct ipmi_addr *) &smi_addr, 238 (struct ipmi_addr *) &smi_addr,
169 &send_msg); 239 &send_msg);
240
241 printk(KERN_INFO PFX "ATCA Detect mfg 0x%X prod 0x%X\n", mfg_id, prod_id);
242 if((mfg_id == IPMI_MOTOROLA_MANUFACTURER_ID)
243 && (prod_id == IPMI_MOTOROLA_PPS_IPMC_PRODUCT_ID)) {
244 printk(KERN_INFO PFX "Installing Pigeon Point Systems Poweroff Hook\n");
245 atca_oem_poweroff_hook = pps_poweroff_atca;
246 }
170 return !rv; 247 return !rv;
171} 248}
172 249
@@ -200,12 +277,19 @@ static void ipmi_poweroff_atca (ipmi_user_t user)
200 rv = ipmi_request_in_rc_mode(user, 277 rv = ipmi_request_in_rc_mode(user,
201 (struct ipmi_addr *) &smi_addr, 278 (struct ipmi_addr *) &smi_addr,
202 &send_msg); 279 &send_msg);
203 if (rv) { 280 /** At this point, the system may be shutting down, and most
281 ** serial drivers (if used) will have interrupts turned off
282 ** it may be better to ignore IPMI_UNKNOWN_ERR_COMPLETION_CODE
283 ** return code
284 **/
285 if (rv && rv != IPMI_UNKNOWN_ERR_COMPLETION_CODE) {
204 printk(KERN_ERR PFX "Unable to send ATCA powerdown message," 286 printk(KERN_ERR PFX "Unable to send ATCA powerdown message,"
205 " IPMI error 0x%x\n", rv); 287 " IPMI error 0x%x\n", rv);
206 goto out; 288 goto out;
207 } 289 }
208 290
291 if(atca_oem_poweroff_hook)
292 return atca_oem_poweroff_hook(user);
209 out: 293 out:
210 return; 294 return;
211} 295}
@@ -440,15 +524,6 @@ static struct poweroff_function poweroff_functions[] = {
440 / sizeof(struct poweroff_function)) 524 / sizeof(struct poweroff_function))
441 525
442 526
443/* Our local state. */
444static int ready = 0;
445static ipmi_user_t ipmi_user;
446static void (*specific_poweroff_func)(ipmi_user_t user) = NULL;
447
448/* Holds the old poweroff function so we can restore it on removal. */
449static void (*old_poweroff_func)(void);
450
451
452/* Called on a powerdown request. */ 527/* Called on a powerdown request. */
453static void ipmi_poweroff_function (void) 528static void ipmi_poweroff_function (void)
454{ 529{
@@ -473,6 +548,9 @@ static void ipmi_po_new_smi(int if_num, struct device *device)
473 if (ready) 548 if (ready)
474 return; 549 return;
475 550
551 if ((ifnum_to_use >= 0) && (ifnum_to_use != if_num))
552 return;
553
476 rv = ipmi_create_user(if_num, &ipmi_poweroff_handler, NULL, 554 rv = ipmi_create_user(if_num, &ipmi_poweroff_handler, NULL,
477 &ipmi_user); 555 &ipmi_user);
478 if (rv) { 556 if (rv) {
@@ -481,6 +559,8 @@ static void ipmi_po_new_smi(int if_num, struct device *device)
481 return; 559 return;
482 } 560 }
483 561
562 ipmi_ifnum = if_num;
563
484 /* 564 /*
485 * Do a get device ide and store some results, since this is 565 * Do a get device ide and store some results, since this is
486 * used by several functions. 566 * used by several functions.
@@ -541,9 +621,15 @@ static void ipmi_po_new_smi(int if_num, struct device *device)
541 621
542static void ipmi_po_smi_gone(int if_num) 622static void ipmi_po_smi_gone(int if_num)
543{ 623{
544 /* This can never be called, because once poweroff driver is 624 if (!ready)
545 registered, the interface can't go away until the power 625 return;
546 driver is unregistered. */ 626
627 if (ipmi_ifnum != if_num)
628 return;
629
630 ready = 0;
631 ipmi_destroy_user(ipmi_user);
632 pm_power_off = old_poweroff_func;
547} 633}
548 634
549static struct ipmi_smi_watcher smi_watcher = 635static struct ipmi_smi_watcher smi_watcher =
@@ -616,9 +702,9 @@ static int ipmi_poweroff_init (void)
616 printk(KERN_ERR PFX "Unable to register SMI watcher: %d\n", rv); 702 printk(KERN_ERR PFX "Unable to register SMI watcher: %d\n", rv);
617 goto out_err; 703 goto out_err;
618 } 704 }
619#endif
620 705
621 out_err: 706 out_err:
707#endif
622 return rv; 708 return rv;
623} 709}
624 710
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index abca98beac14..f1afd26a509f 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -61,6 +61,10 @@
61#include "ipmi_si_sm.h" 61#include "ipmi_si_sm.h"
62#include <linux/init.h> 62#include <linux/init.h>
63#include <linux/dmi.h> 63#include <linux/dmi.h>
64#include <linux/string.h>
65#include <linux/ctype.h>
66
67#define PFX "ipmi_si: "
64 68
65/* Measure times between events in the driver. */ 69/* Measure times between events in the driver. */
66#undef DEBUG_TIMING 70#undef DEBUG_TIMING
@@ -92,7 +96,7 @@ enum si_intf_state {
92enum si_type { 96enum si_type {
93 SI_KCS, SI_SMIC, SI_BT 97 SI_KCS, SI_SMIC, SI_BT
94}; 98};
95static char *si_to_str[] = { "KCS", "SMIC", "BT" }; 99static char *si_to_str[] = { "kcs", "smic", "bt" };
96 100
97#define DEVICE_NAME "ipmi_si" 101#define DEVICE_NAME "ipmi_si"
98 102
@@ -217,7 +221,15 @@ struct smi_info
217 struct list_head link; 221 struct list_head link;
218}; 222};
219 223
224#define SI_MAX_PARMS 4
225
226static int force_kipmid[SI_MAX_PARMS];
227static int num_force_kipmid;
228
229static int unload_when_empty = 1;
230
220static int try_smi_init(struct smi_info *smi); 231static int try_smi_init(struct smi_info *smi);
232static void cleanup_one_si(struct smi_info *to_clean);
221 233
222static ATOMIC_NOTIFIER_HEAD(xaction_notifier_list); 234static ATOMIC_NOTIFIER_HEAD(xaction_notifier_list);
223static int register_xaction_notifier(struct notifier_block * nb) 235static int register_xaction_notifier(struct notifier_block * nb)
@@ -235,14 +247,18 @@ static void deliver_recv_msg(struct smi_info *smi_info,
235 spin_lock(&(smi_info->si_lock)); 247 spin_lock(&(smi_info->si_lock));
236} 248}
237 249
238static void return_hosed_msg(struct smi_info *smi_info) 250static void return_hosed_msg(struct smi_info *smi_info, int cCode)
239{ 251{
240 struct ipmi_smi_msg *msg = smi_info->curr_msg; 252 struct ipmi_smi_msg *msg = smi_info->curr_msg;
241 253
254 if (cCode < 0 || cCode > IPMI_ERR_UNSPECIFIED)
255 cCode = IPMI_ERR_UNSPECIFIED;
256 /* else use it as is */
257
242 /* Make it a reponse */ 258 /* Make it a reponse */
243 msg->rsp[0] = msg->data[0] | 4; 259 msg->rsp[0] = msg->data[0] | 4;
244 msg->rsp[1] = msg->data[1]; 260 msg->rsp[1] = msg->data[1];
245 msg->rsp[2] = 0xFF; /* Unknown error. */ 261 msg->rsp[2] = cCode;
246 msg->rsp_size = 3; 262 msg->rsp_size = 3;
247 263
248 smi_info->curr_msg = NULL; 264 smi_info->curr_msg = NULL;
@@ -293,7 +309,7 @@ static enum si_sm_result start_next_msg(struct smi_info *smi_info)
293 smi_info->curr_msg->data, 309 smi_info->curr_msg->data,
294 smi_info->curr_msg->data_size); 310 smi_info->curr_msg->data_size);
295 if (err) { 311 if (err) {
296 return_hosed_msg(smi_info); 312 return_hosed_msg(smi_info, err);
297 } 313 }
298 314
299 rv = SI_SM_CALL_WITHOUT_DELAY; 315 rv = SI_SM_CALL_WITHOUT_DELAY;
@@ -635,7 +651,7 @@ static enum si_sm_result smi_event_handler(struct smi_info *smi_info,
635 /* If we were handling a user message, format 651 /* If we were handling a user message, format
636 a response to send to the upper layer to 652 a response to send to the upper layer to
637 tell it about the error. */ 653 tell it about the error. */
638 return_hosed_msg(smi_info); 654 return_hosed_msg(smi_info, IPMI_ERR_UNSPECIFIED);
639 } 655 }
640 si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0); 656 si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0);
641 } 657 }
@@ -679,22 +695,24 @@ static enum si_sm_result smi_event_handler(struct smi_info *smi_info,
679 { 695 {
680 /* We are idle and the upper layer requested that I fetch 696 /* We are idle and the upper layer requested that I fetch
681 events, so do so. */ 697 events, so do so. */
682 unsigned char msg[2]; 698 atomic_set(&smi_info->req_events, 0);
683 699
684 spin_lock(&smi_info->count_lock); 700 smi_info->curr_msg = ipmi_alloc_smi_msg();
685 smi_info->flag_fetches++; 701 if (!smi_info->curr_msg)
686 spin_unlock(&smi_info->count_lock); 702 goto out;
687 703
688 atomic_set(&smi_info->req_events, 0); 704 smi_info->curr_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
689 msg[0] = (IPMI_NETFN_APP_REQUEST << 2); 705 smi_info->curr_msg->data[1] = IPMI_READ_EVENT_MSG_BUFFER_CMD;
690 msg[1] = IPMI_GET_MSG_FLAGS_CMD; 706 smi_info->curr_msg->data_size = 2;
691 707
692 smi_info->handlers->start_transaction( 708 smi_info->handlers->start_transaction(
693 smi_info->si_sm, msg, 2); 709 smi_info->si_sm,
694 smi_info->si_state = SI_GETTING_FLAGS; 710 smi_info->curr_msg->data,
711 smi_info->curr_msg->data_size);
712 smi_info->si_state = SI_GETTING_EVENTS;
695 goto restart; 713 goto restart;
696 } 714 }
697 715 out:
698 return si_sm_result; 716 return si_sm_result;
699} 717}
700 718
@@ -709,6 +727,15 @@ static void sender(void *send_info,
709 struct timeval t; 727 struct timeval t;
710#endif 728#endif
711 729
730 if (atomic_read(&smi_info->stop_operation)) {
731 msg->rsp[0] = msg->data[0] | 4;
732 msg->rsp[1] = msg->data[1];
733 msg->rsp[2] = IPMI_ERR_UNSPECIFIED;
734 msg->rsp_size = 3;
735 deliver_recv_msg(smi_info, msg);
736 return;
737 }
738
712 spin_lock_irqsave(&(smi_info->msg_lock), flags); 739 spin_lock_irqsave(&(smi_info->msg_lock), flags);
713#ifdef DEBUG_TIMING 740#ifdef DEBUG_TIMING
714 do_gettimeofday(&t); 741 do_gettimeofday(&t);
@@ -800,17 +827,25 @@ static void poll(void *send_info)
800{ 827{
801 struct smi_info *smi_info = send_info; 828 struct smi_info *smi_info = send_info;
802 829
803 smi_event_handler(smi_info, 0); 830 /*
831 * Make sure there is some delay in the poll loop so we can
832 * drive time forward and timeout things.
833 */
834 udelay(10);
835 smi_event_handler(smi_info, 10);
804} 836}
805 837
806static void request_events(void *send_info) 838static void request_events(void *send_info)
807{ 839{
808 struct smi_info *smi_info = send_info; 840 struct smi_info *smi_info = send_info;
809 841
842 if (atomic_read(&smi_info->stop_operation))
843 return;
844
810 atomic_set(&smi_info->req_events, 1); 845 atomic_set(&smi_info->req_events, 1);
811} 846}
812 847
813static int initialized = 0; 848static int initialized;
814 849
815static void smi_timeout(unsigned long data) 850static void smi_timeout(unsigned long data)
816{ 851{
@@ -867,7 +902,7 @@ static void smi_timeout(unsigned long data)
867 add_timer(&(smi_info->si_timer)); 902 add_timer(&(smi_info->si_timer));
868} 903}
869 904
870static irqreturn_t si_irq_handler(int irq, void *data, struct pt_regs *regs) 905static irqreturn_t si_irq_handler(int irq, void *data)
871{ 906{
872 struct smi_info *smi_info = data; 907 struct smi_info *smi_info = data;
873 unsigned long flags; 908 unsigned long flags;
@@ -894,20 +929,21 @@ static irqreturn_t si_irq_handler(int irq, void *data, struct pt_regs *regs)
894 return IRQ_HANDLED; 929 return IRQ_HANDLED;
895} 930}
896 931
897static irqreturn_t si_bt_irq_handler(int irq, void *data, struct pt_regs *regs) 932static irqreturn_t si_bt_irq_handler(int irq, void *data)
898{ 933{
899 struct smi_info *smi_info = data; 934 struct smi_info *smi_info = data;
900 /* We need to clear the IRQ flag for the BT interface. */ 935 /* We need to clear the IRQ flag for the BT interface. */
901 smi_info->io.outputb(&smi_info->io, IPMI_BT_INTMASK_REG, 936 smi_info->io.outputb(&smi_info->io, IPMI_BT_INTMASK_REG,
902 IPMI_BT_INTMASK_CLEAR_IRQ_BIT 937 IPMI_BT_INTMASK_CLEAR_IRQ_BIT
903 | IPMI_BT_INTMASK_ENABLE_IRQ_BIT); 938 | IPMI_BT_INTMASK_ENABLE_IRQ_BIT);
904 return si_irq_handler(irq, data, regs); 939 return si_irq_handler(irq, data);
905} 940}
906 941
907static int smi_start_processing(void *send_info, 942static int smi_start_processing(void *send_info,
908 ipmi_smi_t intf) 943 ipmi_smi_t intf)
909{ 944{
910 struct smi_info *new_smi = send_info; 945 struct smi_info *new_smi = send_info;
946 int enable = 0;
911 947
912 new_smi->intf = intf; 948 new_smi->intf = intf;
913 949
@@ -916,7 +952,19 @@ static int smi_start_processing(void *send_info,
916 new_smi->last_timeout_jiffies = jiffies; 952 new_smi->last_timeout_jiffies = jiffies;
917 mod_timer(&new_smi->si_timer, jiffies + SI_TIMEOUT_JIFFIES); 953 mod_timer(&new_smi->si_timer, jiffies + SI_TIMEOUT_JIFFIES);
918 954
919 if (new_smi->si_type != SI_BT) { 955 /*
956 * Check if the user forcefully enabled the daemon.
957 */
958 if (new_smi->intf_num < num_force_kipmid)
959 enable = force_kipmid[new_smi->intf_num];
960 /*
961 * The BT interface is efficient enough to not need a thread,
962 * and there is no need for a thread if we have interrupts.
963 */
964 else if ((new_smi->si_type != SI_BT) && (!new_smi->irq))
965 enable = 1;
966
967 if (enable) {
920 new_smi->thread = kthread_run(ipmi_thread, new_smi, 968 new_smi->thread = kthread_run(ipmi_thread, new_smi,
921 "kipmi%d", new_smi->intf_num); 969 "kipmi%d", new_smi->intf_num);
922 if (IS_ERR(new_smi->thread)) { 970 if (IS_ERR(new_smi->thread)) {
@@ -931,12 +979,21 @@ static int smi_start_processing(void *send_info,
931 return 0; 979 return 0;
932} 980}
933 981
982static void set_maintenance_mode(void *send_info, int enable)
983{
984 struct smi_info *smi_info = send_info;
985
986 if (!enable)
987 atomic_set(&smi_info->req_events, 0);
988}
989
934static struct ipmi_smi_handlers handlers = 990static struct ipmi_smi_handlers handlers =
935{ 991{
936 .owner = THIS_MODULE, 992 .owner = THIS_MODULE,
937 .start_processing = smi_start_processing, 993 .start_processing = smi_start_processing,
938 .sender = sender, 994 .sender = sender,
939 .request_events = request_events, 995 .request_events = request_events,
996 .set_maintenance_mode = set_maintenance_mode,
940 .set_run_to_completion = set_run_to_completion, 997 .set_run_to_completion = set_run_to_completion,
941 .poll = poll, 998 .poll = poll,
942}; 999};
@@ -944,7 +1001,6 @@ static struct ipmi_smi_handlers handlers =
944/* There can be 4 IO ports passed in (with or without IRQs), 4 addresses, 1001/* There can be 4 IO ports passed in (with or without IRQs), 4 addresses,
945 a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS */ 1002 a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS */
946 1003
947#define SI_MAX_PARMS 4
948static LIST_HEAD(smi_infos); 1004static LIST_HEAD(smi_infos);
949static DEFINE_MUTEX(smi_infos_lock); 1005static DEFINE_MUTEX(smi_infos_lock);
950static int smi_num; /* Used to sequence the SMIs */ 1006static int smi_num; /* Used to sequence the SMIs */
@@ -962,14 +1018,24 @@ static int num_ports;
962static int irqs[SI_MAX_PARMS]; 1018static int irqs[SI_MAX_PARMS];
963static int num_irqs; 1019static int num_irqs;
964static int regspacings[SI_MAX_PARMS]; 1020static int regspacings[SI_MAX_PARMS];
965static int num_regspacings = 0; 1021static int num_regspacings;
966static int regsizes[SI_MAX_PARMS]; 1022static int regsizes[SI_MAX_PARMS];
967static int num_regsizes = 0; 1023static int num_regsizes;
968static int regshifts[SI_MAX_PARMS]; 1024static int regshifts[SI_MAX_PARMS];
969static int num_regshifts = 0; 1025static int num_regshifts;
970static int slave_addrs[SI_MAX_PARMS]; 1026static int slave_addrs[SI_MAX_PARMS];
971static int num_slave_addrs = 0; 1027static int num_slave_addrs;
1028
1029#define IPMI_IO_ADDR_SPACE 0
1030#define IPMI_MEM_ADDR_SPACE 1
1031static char *addr_space_to_str[] = { "i/o", "mem" };
1032
1033static int hotmod_handler(const char *val, struct kernel_param *kp);
972 1034
1035module_param_call(hotmod, hotmod_handler, NULL, NULL, 0200);
1036MODULE_PARM_DESC(hotmod, "Add and remove interfaces. See"
1037 " Documentation/IPMI.txt in the kernel sources for the"
1038 " gory details.");
973 1039
974module_param_named(trydefaults, si_trydefaults, bool, 0); 1040module_param_named(trydefaults, si_trydefaults, bool, 0);
975MODULE_PARM_DESC(trydefaults, "Setting this to 'false' will disable the" 1041MODULE_PARM_DESC(trydefaults, "Setting this to 'false' will disable the"
@@ -1017,12 +1083,16 @@ MODULE_PARM_DESC(slave_addrs, "Set the default IPMB slave address for"
1017 " the controller. Normally this is 0x20, but can be" 1083 " the controller. Normally this is 0x20, but can be"
1018 " overridden by this parm. This is an array indexed" 1084 " overridden by this parm. This is an array indexed"
1019 " by interface number."); 1085 " by interface number.");
1086module_param_array(force_kipmid, int, &num_force_kipmid, 0);
1087MODULE_PARM_DESC(force_kipmid, "Force the kipmi daemon to be enabled (1) or"
1088 " disabled(0). Normally the IPMI driver auto-detects"
1089 " this, but the value may be overridden by this parm.");
1090module_param(unload_when_empty, int, 0);
1091MODULE_PARM_DESC(unload_when_empty, "Unload the module if no interfaces are"
1092 " specified or found, default is 1. Setting to 0"
1093 " is useful for hot add of devices using hotmod.");
1020 1094
1021 1095
1022#define IPMI_IO_ADDR_SPACE 0
1023#define IPMI_MEM_ADDR_SPACE 1
1024static char *addr_space_to_str[] = { "I/O", "memory" };
1025
1026static void std_irq_cleanup(struct smi_info *info) 1096static void std_irq_cleanup(struct smi_info *info)
1027{ 1097{
1028 if (info->si_type == SI_BT) 1098 if (info->si_type == SI_BT)
@@ -1190,7 +1260,7 @@ static void intf_mem_outb(struct si_sm_io *io, unsigned int offset,
1190static unsigned char intf_mem_inw(struct si_sm_io *io, unsigned int offset) 1260static unsigned char intf_mem_inw(struct si_sm_io *io, unsigned int offset)
1191{ 1261{
1192 return (readw((io->addr)+(offset * io->regspacing)) >> io->regshift) 1262 return (readw((io->addr)+(offset * io->regspacing)) >> io->regshift)
1193 && 0xff; 1263 & 0xff;
1194} 1264}
1195 1265
1196static void intf_mem_outw(struct si_sm_io *io, unsigned int offset, 1266static void intf_mem_outw(struct si_sm_io *io, unsigned int offset,
@@ -1202,7 +1272,7 @@ static void intf_mem_outw(struct si_sm_io *io, unsigned int offset,
1202static unsigned char intf_mem_inl(struct si_sm_io *io, unsigned int offset) 1272static unsigned char intf_mem_inl(struct si_sm_io *io, unsigned int offset)
1203{ 1273{
1204 return (readl((io->addr)+(offset * io->regspacing)) >> io->regshift) 1274 return (readl((io->addr)+(offset * io->regspacing)) >> io->regshift)
1205 && 0xff; 1275 & 0xff;
1206} 1276}
1207 1277
1208static void intf_mem_outl(struct si_sm_io *io, unsigned int offset, 1278static void intf_mem_outl(struct si_sm_io *io, unsigned int offset,
@@ -1215,7 +1285,7 @@ static void intf_mem_outl(struct si_sm_io *io, unsigned int offset,
1215static unsigned char mem_inq(struct si_sm_io *io, unsigned int offset) 1285static unsigned char mem_inq(struct si_sm_io *io, unsigned int offset)
1216{ 1286{
1217 return (readq((io->addr)+(offset * io->regspacing)) >> io->regshift) 1287 return (readq((io->addr)+(offset * io->regspacing)) >> io->regshift)
1218 && 0xff; 1288 & 0xff;
1219} 1289}
1220 1290
1221static void mem_outq(struct si_sm_io *io, unsigned int offset, 1291static void mem_outq(struct si_sm_io *io, unsigned int offset,
@@ -1296,6 +1366,250 @@ static int mem_setup(struct smi_info *info)
1296 return 0; 1366 return 0;
1297} 1367}
1298 1368
1369/*
1370 * Parms come in as <op1>[:op2[:op3...]]. ops are:
1371 * add|remove,kcs|bt|smic,mem|i/o,<address>[,<opt1>[,<opt2>[,...]]]
1372 * Options are:
1373 * rsp=<regspacing>
1374 * rsi=<regsize>
1375 * rsh=<regshift>
1376 * irq=<irq>
1377 * ipmb=<ipmb addr>
1378 */
1379enum hotmod_op { HM_ADD, HM_REMOVE };
1380struct hotmod_vals {
1381 char *name;
1382 int val;
1383};
1384static struct hotmod_vals hotmod_ops[] = {
1385 { "add", HM_ADD },
1386 { "remove", HM_REMOVE },
1387 { NULL }
1388};
1389static struct hotmod_vals hotmod_si[] = {
1390 { "kcs", SI_KCS },
1391 { "smic", SI_SMIC },
1392 { "bt", SI_BT },
1393 { NULL }
1394};
1395static struct hotmod_vals hotmod_as[] = {
1396 { "mem", IPMI_MEM_ADDR_SPACE },
1397 { "i/o", IPMI_IO_ADDR_SPACE },
1398 { NULL }
1399};
1400
1401static int parse_str(struct hotmod_vals *v, int *val, char *name, char **curr)
1402{
1403 char *s;
1404 int i;
1405
1406 s = strchr(*curr, ',');
1407 if (!s) {
1408 printk(KERN_WARNING PFX "No hotmod %s given.\n", name);
1409 return -EINVAL;
1410 }
1411 *s = '\0';
1412 s++;
1413 for (i = 0; hotmod_ops[i].name; i++) {
1414 if (strcmp(*curr, v[i].name) == 0) {
1415 *val = v[i].val;
1416 *curr = s;
1417 return 0;
1418 }
1419 }
1420
1421 printk(KERN_WARNING PFX "Invalid hotmod %s '%s'\n", name, *curr);
1422 return -EINVAL;
1423}
1424
1425static int check_hotmod_int_op(const char *curr, const char *option,
1426 const char *name, int *val)
1427{
1428 char *n;
1429
1430 if (strcmp(curr, name) == 0) {
1431 if (!option) {
1432 printk(KERN_WARNING PFX
1433 "No option given for '%s'\n",
1434 curr);
1435 return -EINVAL;
1436 }
1437 *val = simple_strtoul(option, &n, 0);
1438 if ((*n != '\0') || (*option == '\0')) {
1439 printk(KERN_WARNING PFX
1440 "Bad option given for '%s'\n",
1441 curr);
1442 return -EINVAL;
1443 }
1444 return 1;
1445 }
1446 return 0;
1447}
1448
1449static int hotmod_handler(const char *val, struct kernel_param *kp)
1450{
1451 char *str = kstrdup(val, GFP_KERNEL);
1452 int rv;
1453 char *next, *curr, *s, *n, *o;
1454 enum hotmod_op op;
1455 enum si_type si_type;
1456 int addr_space;
1457 unsigned long addr;
1458 int regspacing;
1459 int regsize;
1460 int regshift;
1461 int irq;
1462 int ipmb;
1463 int ival;
1464 int len;
1465 struct smi_info *info;
1466
1467 if (!str)
1468 return -ENOMEM;
1469
1470 /* Kill any trailing spaces, as we can get a "\n" from echo. */
1471 len = strlen(str);
1472 ival = len - 1;
1473 while ((ival >= 0) && isspace(str[ival])) {
1474 str[ival] = '\0';
1475 ival--;
1476 }
1477
1478 for (curr = str; curr; curr = next) {
1479 regspacing = 1;
1480 regsize = 1;
1481 regshift = 0;
1482 irq = 0;
1483 ipmb = 0x20;
1484
1485 next = strchr(curr, ':');
1486 if (next) {
1487 *next = '\0';
1488 next++;
1489 }
1490
1491 rv = parse_str(hotmod_ops, &ival, "operation", &curr);
1492 if (rv)
1493 break;
1494 op = ival;
1495
1496 rv = parse_str(hotmod_si, &ival, "interface type", &curr);
1497 if (rv)
1498 break;
1499 si_type = ival;
1500
1501 rv = parse_str(hotmod_as, &addr_space, "address space", &curr);
1502 if (rv)
1503 break;
1504
1505 s = strchr(curr, ',');
1506 if (s) {
1507 *s = '\0';
1508 s++;
1509 }
1510 addr = simple_strtoul(curr, &n, 0);
1511 if ((*n != '\0') || (*curr == '\0')) {
1512 printk(KERN_WARNING PFX "Invalid hotmod address"
1513 " '%s'\n", curr);
1514 break;
1515 }
1516
1517 while (s) {
1518 curr = s;
1519 s = strchr(curr, ',');
1520 if (s) {
1521 *s = '\0';
1522 s++;
1523 }
1524 o = strchr(curr, '=');
1525 if (o) {
1526 *o = '\0';
1527 o++;
1528 }
1529 rv = check_hotmod_int_op(curr, o, "rsp", &regspacing);
1530 if (rv < 0)
1531 goto out;
1532 else if (rv)
1533 continue;
1534 rv = check_hotmod_int_op(curr, o, "rsi", &regsize);
1535 if (rv < 0)
1536 goto out;
1537 else if (rv)
1538 continue;
1539 rv = check_hotmod_int_op(curr, o, "rsh", &regshift);
1540 if (rv < 0)
1541 goto out;
1542 else if (rv)
1543 continue;
1544 rv = check_hotmod_int_op(curr, o, "irq", &irq);
1545 if (rv < 0)
1546 goto out;
1547 else if (rv)
1548 continue;
1549 rv = check_hotmod_int_op(curr, o, "ipmb", &ipmb);
1550 if (rv < 0)
1551 goto out;
1552 else if (rv)
1553 continue;
1554
1555 rv = -EINVAL;
1556 printk(KERN_WARNING PFX
1557 "Invalid hotmod option '%s'\n",
1558 curr);
1559 goto out;
1560 }
1561
1562 if (op == HM_ADD) {
1563 info = kzalloc(sizeof(*info), GFP_KERNEL);
1564 if (!info) {
1565 rv = -ENOMEM;
1566 goto out;
1567 }
1568
1569 info->addr_source = "hotmod";
1570 info->si_type = si_type;
1571 info->io.addr_data = addr;
1572 info->io.addr_type = addr_space;
1573 if (addr_space == IPMI_MEM_ADDR_SPACE)
1574 info->io_setup = mem_setup;
1575 else
1576 info->io_setup = port_setup;
1577
1578 info->io.addr = NULL;
1579 info->io.regspacing = regspacing;
1580 if (!info->io.regspacing)
1581 info->io.regspacing = DEFAULT_REGSPACING;
1582 info->io.regsize = regsize;
1583 if (!info->io.regsize)
1584 info->io.regsize = DEFAULT_REGSPACING;
1585 info->io.regshift = regshift;
1586 info->irq = irq;
1587 if (info->irq)
1588 info->irq_setup = std_irq_setup;
1589 info->slave_addr = ipmb;
1590
1591 try_smi_init(info);
1592 } else {
1593 /* remove */
1594 struct smi_info *e, *tmp_e;
1595
1596 mutex_lock(&smi_infos_lock);
1597 list_for_each_entry_safe(e, tmp_e, &smi_infos, link) {
1598 if (e->io.addr_type != addr_space)
1599 continue;
1600 if (e->si_type != si_type)
1601 continue;
1602 if (e->io.addr_data == addr)
1603 cleanup_one_si(e);
1604 }
1605 mutex_unlock(&smi_infos_lock);
1606 }
1607 }
1608 rv = len;
1609 out:
1610 kfree(str);
1611 return rv;
1612}
1299 1613
1300static __devinit void hardcode_find_bmc(void) 1614static __devinit void hardcode_find_bmc(void)
1301{ 1615{
@@ -1370,7 +1684,7 @@ static __devinit void hardcode_find_bmc(void)
1370/* Once we get an ACPI failure, we don't try any more, because we go 1684/* Once we get an ACPI failure, we don't try any more, because we go
1371 through the tables sequentially. Once we don't find a table, there 1685 through the tables sequentially. Once we don't find a table, there
1372 are no more. */ 1686 are no more. */
1373static int acpi_failure = 0; 1687static int acpi_failure;
1374 1688
1375/* For GPE-type interrupts. */ 1689/* For GPE-type interrupts. */
1376static u32 ipmi_acpi_gpe(void *context) 1690static u32 ipmi_acpi_gpe(void *context)
@@ -1481,7 +1795,6 @@ struct SPMITable {
1481static __devinit int try_init_acpi(struct SPMITable *spmi) 1795static __devinit int try_init_acpi(struct SPMITable *spmi)
1482{ 1796{
1483 struct smi_info *info; 1797 struct smi_info *info;
1484 char *io_type;
1485 u8 addr_space; 1798 u8 addr_space;
1486 1799
1487 if (spmi->IPMIlegacy != 1) { 1800 if (spmi->IPMIlegacy != 1) {
@@ -1545,11 +1858,9 @@ static __devinit int try_init_acpi(struct SPMITable *spmi)
1545 info->io.regshift = spmi->addr.register_bit_offset; 1858 info->io.regshift = spmi->addr.register_bit_offset;
1546 1859
1547 if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { 1860 if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
1548 io_type = "memory";
1549 info->io_setup = mem_setup; 1861 info->io_setup = mem_setup;
1550 info->io.addr_type = IPMI_IO_ADDR_SPACE; 1862 info->io.addr_type = IPMI_IO_ADDR_SPACE;
1551 } else if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_IO) { 1863 } else if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
1552 io_type = "I/O";
1553 info->io_setup = port_setup; 1864 info->io_setup = port_setup;
1554 info->io.addr_type = IPMI_MEM_ADDR_SPACE; 1865 info->io.addr_type = IPMI_MEM_ADDR_SPACE;
1555 } else { 1866 } else {
@@ -1730,6 +2041,7 @@ static void __devinit dmi_find_bmc(void)
1730 int rv; 2041 int rv;
1731 2042
1732 while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) { 2043 while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) {
2044 memset(&data, 0, sizeof(data));
1733 rv = decode_dmi((struct dmi_header *) dev->device_data, &data); 2045 rv = decode_dmi((struct dmi_header *) dev->device_data, &data);
1734 if (!rv) 2046 if (!rv)
1735 try_init_dmi(&data); 2047 try_init_dmi(&data);
@@ -1767,7 +2079,7 @@ static int __devinit ipmi_pci_probe(struct pci_dev *pdev,
1767 2079
1768 info = kzalloc(sizeof(*info), GFP_KERNEL); 2080 info = kzalloc(sizeof(*info), GFP_KERNEL);
1769 if (!info) 2081 if (!info)
1770 return ENOMEM; 2082 return -ENOMEM;
1771 2083
1772 info->addr_source = "PCI"; 2084 info->addr_source = "PCI";
1773 2085
@@ -1788,7 +2100,7 @@ static int __devinit ipmi_pci_probe(struct pci_dev *pdev,
1788 kfree(info); 2100 kfree(info);
1789 printk(KERN_INFO "ipmi_si: %s: Unknown IPMI type: %d\n", 2101 printk(KERN_INFO "ipmi_si: %s: Unknown IPMI type: %d\n",
1790 pci_name(pdev), class_type); 2102 pci_name(pdev), class_type);
1791 return ENOMEM; 2103 return -ENOMEM;
1792 } 2104 }
1793 2105
1794 rv = pci_enable_device(pdev); 2106 rv = pci_enable_device(pdev);
@@ -1845,7 +2157,7 @@ static int ipmi_pci_resume(struct pci_dev *pdev)
1845 2157
1846static struct pci_device_id ipmi_pci_devices[] = { 2158static struct pci_device_id ipmi_pci_devices[] = {
1847 { PCI_DEVICE(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID) }, 2159 { PCI_DEVICE(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID) },
1848 { PCI_DEVICE_CLASS(PCI_ERMC_CLASSCODE, PCI_ERMC_CLASSCODE) } 2160 { PCI_DEVICE_CLASS(PCI_ERMC_CLASSCODE, PCI_ERMC_CLASSCODE_MASK) }
1849}; 2161};
1850MODULE_DEVICE_TABLE(pci, ipmi_pci_devices); 2162MODULE_DEVICE_TABLE(pci, ipmi_pci_devices);
1851 2163
@@ -1930,19 +2242,9 @@ static int try_get_dev_id(struct smi_info *smi_info)
1930static int type_file_read_proc(char *page, char **start, off_t off, 2242static int type_file_read_proc(char *page, char **start, off_t off,
1931 int count, int *eof, void *data) 2243 int count, int *eof, void *data)
1932{ 2244{
1933 char *out = (char *) page;
1934 struct smi_info *smi = data; 2245 struct smi_info *smi = data;
1935 2246
1936 switch (smi->si_type) { 2247 return sprintf(page, "%s\n", si_to_str[smi->si_type]);
1937 case SI_KCS:
1938 return sprintf(out, "kcs\n");
1939 case SI_SMIC:
1940 return sprintf(out, "smic\n");
1941 case SI_BT:
1942 return sprintf(out, "bt\n");
1943 default:
1944 return 0;
1945 }
1946} 2248}
1947 2249
1948static int stat_file_read_proc(char *page, char **start, off_t off, 2250static int stat_file_read_proc(char *page, char **start, off_t off,
@@ -1978,7 +2280,24 @@ static int stat_file_read_proc(char *page, char **start, off_t off,
1978 out += sprintf(out, "incoming_messages: %ld\n", 2280 out += sprintf(out, "incoming_messages: %ld\n",
1979 smi->incoming_messages); 2281 smi->incoming_messages);
1980 2282
1981 return (out - ((char *) page)); 2283 return out - page;
2284}
2285
2286static int param_read_proc(char *page, char **start, off_t off,
2287 int count, int *eof, void *data)
2288{
2289 struct smi_info *smi = data;
2290
2291 return sprintf(page,
2292 "%s,%s,0x%lx,rsp=%d,rsi=%d,rsh=%d,irq=%d,ipmb=%d\n",
2293 si_to_str[smi->si_type],
2294 addr_space_to_str[smi->io.addr_type],
2295 smi->io.addr_data,
2296 smi->io.regspacing,
2297 smi->io.regsize,
2298 smi->io.regshift,
2299 smi->irq,
2300 smi->slave_addr);
1982} 2301}
1983 2302
1984/* 2303/*
@@ -2324,7 +2643,7 @@ static int try_smi_init(struct smi_info *new_smi)
2324 new_smi->dev = &new_smi->pdev->dev; 2643 new_smi->dev = &new_smi->pdev->dev;
2325 new_smi->dev->driver = &ipmi_driver; 2644 new_smi->dev->driver = &ipmi_driver;
2326 2645
2327 rv = platform_device_register(new_smi->pdev); 2646 rv = platform_device_add(new_smi->pdev);
2328 if (rv) { 2647 if (rv) {
2329 printk(KERN_ERR 2648 printk(KERN_ERR
2330 "ipmi_si_intf:" 2649 "ipmi_si_intf:"
@@ -2340,6 +2659,7 @@ static int try_smi_init(struct smi_info *new_smi)
2340 new_smi, 2659 new_smi,
2341 &new_smi->device_id, 2660 &new_smi->device_id,
2342 new_smi->dev, 2661 new_smi->dev,
2662 "bmc",
2343 new_smi->slave_addr); 2663 new_smi->slave_addr);
2344 if (rv) { 2664 if (rv) {
2345 printk(KERN_ERR 2665 printk(KERN_ERR
@@ -2368,6 +2688,16 @@ static int try_smi_init(struct smi_info *new_smi)
2368 goto out_err_stop_timer; 2688 goto out_err_stop_timer;
2369 } 2689 }
2370 2690
2691 rv = ipmi_smi_add_proc_entry(new_smi->intf, "params",
2692 param_read_proc, NULL,
2693 new_smi, THIS_MODULE);
2694 if (rv) {
2695 printk(KERN_ERR
2696 "ipmi_si: Unable to create proc entry: %d\n",
2697 rv);
2698 goto out_err_stop_timer;
2699 }
2700
2371 list_add_tail(&new_smi->link, &smi_infos); 2701 list_add_tail(&new_smi->link, &smi_infos);
2372 2702
2373 mutex_unlock(&smi_infos_lock); 2703 mutex_unlock(&smi_infos_lock);
@@ -2456,12 +2786,16 @@ static __devinit int init_ipmi_si(void)
2456#endif 2786#endif
2457 2787
2458#ifdef CONFIG_ACPI 2788#ifdef CONFIG_ACPI
2459 if (si_trydefaults) 2789 acpi_find_bmc();
2460 acpi_find_bmc();
2461#endif 2790#endif
2462 2791
2463#ifdef CONFIG_PCI 2792#ifdef CONFIG_PCI
2464 pci_module_init(&ipmi_pci_driver); 2793 rv = pci_register_driver(&ipmi_pci_driver);
2794 if (rv){
2795 printk(KERN_ERR
2796 "init_ipmi_si: Unable to register PCI driver: %d\n",
2797 rv);
2798 }
2465#endif 2799#endif
2466 2800
2467 if (si_trydefaults) { 2801 if (si_trydefaults) {
@@ -2476,7 +2810,7 @@ static __devinit int init_ipmi_si(void)
2476 } 2810 }
2477 2811
2478 mutex_lock(&smi_infos_lock); 2812 mutex_lock(&smi_infos_lock);
2479 if (list_empty(&smi_infos)) { 2813 if (unload_when_empty && list_empty(&smi_infos)) {
2480 mutex_unlock(&smi_infos_lock); 2814 mutex_unlock(&smi_infos_lock);
2481#ifdef CONFIG_PCI 2815#ifdef CONFIG_PCI
2482 pci_unregister_driver(&ipmi_pci_driver); 2816 pci_unregister_driver(&ipmi_pci_driver);
@@ -2491,7 +2825,7 @@ static __devinit int init_ipmi_si(void)
2491} 2825}
2492module_init(init_ipmi_si); 2826module_init(init_ipmi_si);
2493 2827
2494static void __devexit cleanup_one_si(struct smi_info *to_clean) 2828static void cleanup_one_si(struct smi_info *to_clean)
2495{ 2829{
2496 int rv; 2830 int rv;
2497 unsigned long flags; 2831 unsigned long flags;
diff --git a/drivers/char/ipmi/ipmi_smic_sm.c b/drivers/char/ipmi/ipmi_smic_sm.c
index 39d7e5ef1a2b..e64ea7d25d24 100644
--- a/drivers/char/ipmi/ipmi_smic_sm.c
+++ b/drivers/char/ipmi/ipmi_smic_sm.c
@@ -141,12 +141,14 @@ static int start_smic_transaction(struct si_sm_data *smic,
141{ 141{
142 unsigned int i; 142 unsigned int i;
143 143
144 if ((size < 2) || (size > MAX_SMIC_WRITE_SIZE)) { 144 if (size < 2)
145 return -1; 145 return IPMI_REQ_LEN_INVALID_ERR;
146 } 146 if (size > MAX_SMIC_WRITE_SIZE)
147 if ((smic->state != SMIC_IDLE) && (smic->state != SMIC_HOSED)) { 147 return IPMI_REQ_LEN_EXCEEDED_ERR;
148 return -2; 148
149 } 149 if ((smic->state != SMIC_IDLE) && (smic->state != SMIC_HOSED))
150 return IPMI_NOT_IN_MY_STATE_ERR;
151
150 if (smic_debug & SMIC_DEBUG_MSG) { 152 if (smic_debug & SMIC_DEBUG_MSG) {
151 printk(KERN_INFO "start_smic_transaction -"); 153 printk(KERN_INFO "start_smic_transaction -");
152 for (i = 0; i < size; i ++) { 154 for (i = 0; i < size; i ++) {
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index accaaf1a6b69..78280380a905 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -134,13 +134,14 @@
134 134
135static int nowayout = WATCHDOG_NOWAYOUT; 135static int nowayout = WATCHDOG_NOWAYOUT;
136 136
137static ipmi_user_t watchdog_user = NULL; 137static ipmi_user_t watchdog_user;
138static int watchdog_ifnum;
138 139
139/* Default the timeout to 10 seconds. */ 140/* Default the timeout to 10 seconds. */
140static int timeout = 10; 141static int timeout = 10;
141 142
142/* The pre-timeout is disabled by default. */ 143/* The pre-timeout is disabled by default. */
143static int pretimeout = 0; 144static int pretimeout;
144 145
145/* Default action is to reset the board on a timeout. */ 146/* Default action is to reset the board on a timeout. */
146static unsigned char action_val = WDOG_TIMEOUT_RESET; 147static unsigned char action_val = WDOG_TIMEOUT_RESET;
@@ -155,12 +156,14 @@ static unsigned char preop_val = WDOG_PREOP_NONE;
155 156
156static char preop[16] = "preop_none"; 157static char preop[16] = "preop_none";
157static DEFINE_SPINLOCK(ipmi_read_lock); 158static DEFINE_SPINLOCK(ipmi_read_lock);
158static char data_to_read = 0; 159static char data_to_read;
159static DECLARE_WAIT_QUEUE_HEAD(read_q); 160static DECLARE_WAIT_QUEUE_HEAD(read_q);
160static struct fasync_struct *fasync_q = NULL; 161static struct fasync_struct *fasync_q;
161static char pretimeout_since_last_heartbeat = 0; 162static char pretimeout_since_last_heartbeat;
162static char expect_close; 163static char expect_close;
163 164
165static int ifnum_to_use = -1;
166
164static DECLARE_RWSEM(register_sem); 167static DECLARE_RWSEM(register_sem);
165 168
166/* Parameters to ipmi_set_timeout */ 169/* Parameters to ipmi_set_timeout */
@@ -169,10 +172,12 @@ static DECLARE_RWSEM(register_sem);
169#define IPMI_SET_TIMEOUT_FORCE_HB 2 172#define IPMI_SET_TIMEOUT_FORCE_HB 2
170 173
171static int ipmi_set_timeout(int do_heartbeat); 174static int ipmi_set_timeout(int do_heartbeat);
175static void ipmi_register_watchdog(int ipmi_intf);
176static void ipmi_unregister_watchdog(int ipmi_intf);
172 177
173/* If true, the driver will start running as soon as it is configured 178/* If true, the driver will start running as soon as it is configured
174 and ready. */ 179 and ready. */
175static int start_now = 0; 180static int start_now;
176 181
177static int set_param_int(const char *val, struct kernel_param *kp) 182static int set_param_int(const char *val, struct kernel_param *kp)
178{ 183{
@@ -245,6 +250,26 @@ static int get_param_str(char *buffer, struct kernel_param *kp)
245 return strlen(buffer); 250 return strlen(buffer);
246} 251}
247 252
253
254static int set_param_wdog_ifnum(const char *val, struct kernel_param *kp)
255{
256 int rv = param_set_int(val, kp);
257 if (rv)
258 return rv;
259 if ((ifnum_to_use < 0) || (ifnum_to_use == watchdog_ifnum))
260 return 0;
261
262 ipmi_unregister_watchdog(watchdog_ifnum);
263 ipmi_register_watchdog(ifnum_to_use);
264 return 0;
265}
266
267module_param_call(ifnum_to_use, set_param_wdog_ifnum, get_param_int,
268 &ifnum_to_use, 0644);
269MODULE_PARM_DESC(ifnum_to_use, "The interface number to use for the watchdog "
270 "timer. Setting to -1 defaults to the first registered "
271 "interface");
272
248module_param_call(timeout, set_param_int, get_param_int, &timeout, 0644); 273module_param_call(timeout, set_param_int, get_param_int, &timeout, 0644);
249MODULE_PARM_DESC(timeout, "Timeout value in seconds."); 274MODULE_PARM_DESC(timeout, "Timeout value in seconds.");
250 275
@@ -263,27 +288,28 @@ module_param_call(preop, set_param_str, get_param_str, preop_op, 0644);
263MODULE_PARM_DESC(preop, "Pretimeout driver operation. One of: " 288MODULE_PARM_DESC(preop, "Pretimeout driver operation. One of: "
264 "preop_none, preop_panic, preop_give_data."); 289 "preop_none, preop_panic, preop_give_data.");
265 290
266module_param(start_now, int, 0); 291module_param(start_now, int, 0444);
267MODULE_PARM_DESC(start_now, "Set to 1 to start the watchdog as" 292MODULE_PARM_DESC(start_now, "Set to 1 to start the watchdog as"
268 "soon as the driver is loaded."); 293 "soon as the driver is loaded.");
269 294
270module_param(nowayout, int, 0644); 295module_param(nowayout, int, 0644);
271MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 296MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
297 "(default=CONFIG_WATCHDOG_NOWAYOUT)");
272 298
273/* Default state of the timer. */ 299/* Default state of the timer. */
274static unsigned char ipmi_watchdog_state = WDOG_TIMEOUT_NONE; 300static unsigned char ipmi_watchdog_state = WDOG_TIMEOUT_NONE;
275 301
276/* If shutting down via IPMI, we ignore the heartbeat. */ 302/* If shutting down via IPMI, we ignore the heartbeat. */
277static int ipmi_ignore_heartbeat = 0; 303static int ipmi_ignore_heartbeat;
278 304
279/* Is someone using the watchdog? Only one user is allowed. */ 305/* Is someone using the watchdog? Only one user is allowed. */
280static unsigned long ipmi_wdog_open = 0; 306static unsigned long ipmi_wdog_open;
281 307
282/* If set to 1, the heartbeat command will set the state to reset and 308/* If set to 1, the heartbeat command will set the state to reset and
283 start the timer. The timer doesn't normally run when the driver is 309 start the timer. The timer doesn't normally run when the driver is
284 first opened until the heartbeat is set the first time, this 310 first opened until the heartbeat is set the first time, this
285 variable is used to accomplish this. */ 311 variable is used to accomplish this. */
286static int ipmi_start_timer_on_heartbeat = 0; 312static int ipmi_start_timer_on_heartbeat;
287 313
288/* IPMI version of the BMC. */ 314/* IPMI version of the BMC. */
289static unsigned char ipmi_version_major; 315static unsigned char ipmi_version_major;
@@ -872,6 +898,11 @@ static void ipmi_register_watchdog(int ipmi_intf)
872 if (watchdog_user) 898 if (watchdog_user)
873 goto out; 899 goto out;
874 900
901 if ((ifnum_to_use >= 0) && (ifnum_to_use != ipmi_intf))
902 goto out;
903
904 watchdog_ifnum = ipmi_intf;
905
875 rv = ipmi_create_user(ipmi_intf, &ipmi_hndlrs, NULL, &watchdog_user); 906 rv = ipmi_create_user(ipmi_intf, &ipmi_hndlrs, NULL, &watchdog_user);
876 if (rv < 0) { 907 if (rv < 0) {
877 printk(KERN_CRIT PFX "Unable to register with ipmi\n"); 908 printk(KERN_CRIT PFX "Unable to register with ipmi\n");
@@ -901,9 +932,42 @@ static void ipmi_register_watchdog(int ipmi_intf)
901 } 932 }
902} 933}
903 934
935static void ipmi_unregister_watchdog(int ipmi_intf)
936{
937 int rv;
938
939 down_write(&register_sem);
940
941 if (!watchdog_user)
942 goto out;
943
944 if (watchdog_ifnum != ipmi_intf)
945 goto out;
946
947 /* Make sure no one can call us any more. */
948 misc_deregister(&ipmi_wdog_miscdev);
949
950 /* Wait to make sure the message makes it out. The lower layer has
951 pointers to our buffers, we want to make sure they are done before
952 we release our memory. */
953 while (atomic_read(&set_timeout_tofree))
954 schedule_timeout_uninterruptible(1);
955
956 /* Disconnect from IPMI. */
957 rv = ipmi_destroy_user(watchdog_user);
958 if (rv) {
959 printk(KERN_WARNING PFX "error unlinking from IPMI: %d\n",
960 rv);
961 }
962 watchdog_user = NULL;
963
964 out:
965 up_write(&register_sem);
966}
967
904#ifdef HAVE_NMI_HANDLER 968#ifdef HAVE_NMI_HANDLER
905static int 969static int
906ipmi_nmi(void *dev_id, struct pt_regs *regs, int cpu, int handled) 970ipmi_nmi(void *dev_id, int cpu, int handled)
907{ 971{
908 /* If we are not expecting a timeout, ignore it. */ 972 /* If we are not expecting a timeout, ignore it. */
909 if (ipmi_watchdog_state == WDOG_TIMEOUT_NONE) 973 if (ipmi_watchdog_state == WDOG_TIMEOUT_NONE)
@@ -1004,9 +1068,7 @@ static void ipmi_new_smi(int if_num, struct device *device)
1004 1068
1005static void ipmi_smi_gone(int if_num) 1069static void ipmi_smi_gone(int if_num)
1006{ 1070{
1007 /* This can never be called, because once the watchdog is 1071 ipmi_unregister_watchdog(if_num);
1008 registered, the interface can't go away until the watchdog
1009 is unregistered. */
1010} 1072}
1011 1073
1012static struct ipmi_smi_watcher smi_watcher = 1074static struct ipmi_smi_watcher smi_watcher =
@@ -1148,30 +1210,32 @@ static int __init ipmi_wdog_init(void)
1148 1210
1149 check_parms(); 1211 check_parms();
1150 1212
1213 register_reboot_notifier(&wdog_reboot_notifier);
1214 atomic_notifier_chain_register(&panic_notifier_list,
1215 &wdog_panic_notifier);
1216
1151 rv = ipmi_smi_watcher_register(&smi_watcher); 1217 rv = ipmi_smi_watcher_register(&smi_watcher);
1152 if (rv) { 1218 if (rv) {
1153#ifdef HAVE_NMI_HANDLER 1219#ifdef HAVE_NMI_HANDLER
1154 if (preaction_val == WDOG_PRETIMEOUT_NMI) 1220 if (preaction_val == WDOG_PRETIMEOUT_NMI)
1155 release_nmi(&ipmi_nmi_handler); 1221 release_nmi(&ipmi_nmi_handler);
1156#endif 1222#endif
1223 atomic_notifier_chain_unregister(&panic_notifier_list,
1224 &wdog_panic_notifier);
1225 unregister_reboot_notifier(&wdog_reboot_notifier);
1157 printk(KERN_WARNING PFX "can't register smi watcher\n"); 1226 printk(KERN_WARNING PFX "can't register smi watcher\n");
1158 return rv; 1227 return rv;
1159 } 1228 }
1160 1229
1161 register_reboot_notifier(&wdog_reboot_notifier);
1162 atomic_notifier_chain_register(&panic_notifier_list,
1163 &wdog_panic_notifier);
1164
1165 printk(KERN_INFO PFX "driver initialized\n"); 1230 printk(KERN_INFO PFX "driver initialized\n");
1166 1231
1167 return 0; 1232 return 0;
1168} 1233}
1169 1234
1170static __exit void ipmi_unregister_watchdog(void) 1235static void __exit ipmi_wdog_exit(void)
1171{ 1236{
1172 int rv; 1237 ipmi_smi_watcher_unregister(&smi_watcher);
1173 1238 ipmi_unregister_watchdog(watchdog_ifnum);
1174 down_write(&register_sem);
1175 1239
1176#ifdef HAVE_NMI_HANDLER 1240#ifdef HAVE_NMI_HANDLER
1177 if (nmi_handler_registered) 1241 if (nmi_handler_registered)
@@ -1179,37 +1243,8 @@ static __exit void ipmi_unregister_watchdog(void)
1179#endif 1243#endif
1180 1244
1181 atomic_notifier_chain_unregister(&panic_notifier_list, 1245 atomic_notifier_chain_unregister(&panic_notifier_list,
1182 &wdog_panic_notifier); 1246 &wdog_panic_notifier);
1183 unregister_reboot_notifier(&wdog_reboot_notifier); 1247 unregister_reboot_notifier(&wdog_reboot_notifier);
1184
1185 if (! watchdog_user)
1186 goto out;
1187
1188 /* Make sure no one can call us any more. */
1189 misc_deregister(&ipmi_wdog_miscdev);
1190
1191 /* Wait to make sure the message makes it out. The lower layer has
1192 pointers to our buffers, we want to make sure they are done before
1193 we release our memory. */
1194 while (atomic_read(&set_timeout_tofree))
1195 schedule_timeout_uninterruptible(1);
1196
1197 /* Disconnect from IPMI. */
1198 rv = ipmi_destroy_user(watchdog_user);
1199 if (rv) {
1200 printk(KERN_WARNING PFX "error unlinking from IPMI: %d\n",
1201 rv);
1202 }
1203 watchdog_user = NULL;
1204
1205 out:
1206 up_write(&register_sem);
1207}
1208
1209static void __exit ipmi_wdog_exit(void)
1210{
1211 ipmi_smi_watcher_unregister(&smi_watcher);
1212 ipmi_unregister_watchdog();
1213} 1248}
1214module_exit(ipmi_wdog_exit); 1249module_exit(ipmi_wdog_exit);
1215module_init(ipmi_wdog_init); 1250module_init(ipmi_wdog_init);
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index 913be23e0a24..5a747e685993 100644
--- a/drivers/char/isicom.c
+++ b/drivers/char/isicom.c
@@ -172,12 +172,14 @@ static struct pci_driver isicom_driver = {
172static int prev_card = 3; /* start servicing isi_card[0] */ 172static int prev_card = 3; /* start servicing isi_card[0] */
173static struct tty_driver *isicom_normal; 173static struct tty_driver *isicom_normal;
174 174
175static struct timer_list tx; 175static DECLARE_COMPLETION(isi_timerdone);
176static char re_schedule = 1; 176static char re_schedule = 1;
177 177
178static void isicom_tx(unsigned long _data); 178static void isicom_tx(unsigned long _data);
179static void isicom_start(struct tty_struct *tty); 179static void isicom_start(struct tty_struct *tty);
180 180
181static DEFINE_TIMER(tx, isicom_tx, 0, 0);
182
181/* baud index mappings from linux defns to isi */ 183/* baud index mappings from linux defns to isi */
182 184
183static signed char linuxb_to_isib[] = { 185static signed char linuxb_to_isib[] = {
@@ -193,9 +195,9 @@ struct isi_board {
193 unsigned short shift_count; 195 unsigned short shift_count;
194 struct isi_port * ports; 196 struct isi_port * ports;
195 signed char count; 197 signed char count;
196 unsigned char isa;
197 spinlock_t card_lock; /* Card wide lock 11/5/00 -sameer */ 198 spinlock_t card_lock; /* Card wide lock 11/5/00 -sameer */
198 unsigned long flags; 199 unsigned long flags;
200 unsigned int index;
199}; 201};
200 202
201struct isi_port { 203struct isi_port {
@@ -514,25 +516,19 @@ static void isicom_tx(unsigned long _data)
514 /* schedule another tx for hopefully in about 10ms */ 516 /* schedule another tx for hopefully in about 10ms */
515sched_again: 517sched_again:
516 if (!re_schedule) { 518 if (!re_schedule) {
517 re_schedule = 2; 519 complete(&isi_timerdone);
518 return; 520 return;
519 } 521 }
520 522
521 init_timer(&tx); 523 mod_timer(&tx, jiffies + msecs_to_jiffies(10));
522 tx.expires = jiffies + HZ/100;
523 tx.data = 0;
524 tx.function = isicom_tx;
525 add_timer(&tx);
526
527 return;
528} 524}
529 525
530/* Interrupt handlers */ 526/* Interrupt handlers */
531 527
532 528
533static void isicom_bottomhalf(void *data) 529static void isicom_bottomhalf(struct work_struct *work)
534{ 530{
535 struct isi_port *port = (struct isi_port *) data; 531 struct isi_port *port = container_of(work, struct isi_port, bh_tqueue);
536 struct tty_struct *tty = port->tty; 532 struct tty_struct *tty = port->tty;
537 533
538 if (!tty) 534 if (!tty)
@@ -546,7 +542,7 @@ static void isicom_bottomhalf(void *data)
546 * Main interrupt handler routine 542 * Main interrupt handler routine
547 */ 543 */
548 544
549static irqreturn_t isicom_interrupt(int irq, void *dev_id, struct pt_regs *regs) 545static irqreturn_t isicom_interrupt(int irq, void *dev_id)
550{ 546{
551 struct isi_board *card = dev_id; 547 struct isi_board *card = dev_id;
552 struct isi_port *port; 548 struct isi_port *port;
@@ -562,14 +558,12 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id, struct pt_regs *regs)
562 base = card->base; 558 base = card->base;
563 spin_lock(&card->card_lock); 559 spin_lock(&card->card_lock);
564 560
565 if (card->isa == NO) { 561 /*
566 /* 562 * disable any interrupts from the PCI card and lower the
567 * disable any interrupts from the PCI card and lower the 563 * interrupt line
568 * interrupt line 564 */
569 */ 565 outw(0x8000, base+0x04);
570 outw(0x8000, base+0x04); 566 ClearInterrupt(base);
571 ClearInterrupt(base);
572 }
573 567
574 inw(base); /* get the dummy word out */ 568 inw(base); /* get the dummy word out */
575 header = inw(base); 569 header = inw(base);
@@ -579,19 +573,13 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id, struct pt_regs *regs)
579 if (channel + 1 > card->port_count) { 573 if (channel + 1 > card->port_count) {
580 printk(KERN_WARNING "ISICOM: isicom_interrupt(0x%lx): " 574 printk(KERN_WARNING "ISICOM: isicom_interrupt(0x%lx): "
581 "%d(channel) > port_count.\n", base, channel+1); 575 "%d(channel) > port_count.\n", base, channel+1);
582 if (card->isa) 576 outw(0x0000, base+0x04); /* enable interrupts */
583 ClearInterrupt(base);
584 else
585 outw(0x0000, base+0x04); /* enable interrupts */
586 spin_unlock(&card->card_lock); 577 spin_unlock(&card->card_lock);
587 return IRQ_HANDLED; 578 return IRQ_HANDLED;
588 } 579 }
589 port = card->ports + channel; 580 port = card->ports + channel;
590 if (!(port->flags & ASYNC_INITIALIZED)) { 581 if (!(port->flags & ASYNC_INITIALIZED)) {
591 if (card->isa) 582 outw(0x0000, base+0x04); /* enable interrupts */
592 ClearInterrupt(base);
593 else
594 outw(0x0000, base+0x04); /* enable interrupts */
595 return IRQ_HANDLED; 583 return IRQ_HANDLED;
596 } 584 }
597 585
@@ -604,10 +592,7 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id, struct pt_regs *regs)
604 } 592 }
605 if (byte_count & 0x01) 593 if (byte_count & 0x01)
606 inw(base); 594 inw(base);
607 if (card->isa == YES) 595 outw(0x0000, base+0x04); /* enable interrupts */
608 ClearInterrupt(base);
609 else
610 outw(0x0000, base+0x04); /* enable interrupts */
611 spin_unlock(&card->card_lock); 596 spin_unlock(&card->card_lock);
612 return IRQ_HANDLED; 597 return IRQ_HANDLED;
613 } 598 }
@@ -708,10 +693,7 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id, struct pt_regs *regs)
708 } 693 }
709 tty_flip_buffer_push(tty); 694 tty_flip_buffer_push(tty);
710 } 695 }
711 if (card->isa == YES) 696 outw(0x0000, base+0x04); /* enable interrupts */
712 ClearInterrupt(base);
713 else
714 outw(0x0000, base+0x04); /* enable interrupts */
715 697
716 return IRQ_HANDLED; 698 return IRQ_HANDLED;
717} 699}
@@ -964,8 +946,8 @@ static int isicom_open(struct tty_struct *tty, struct file *filp)
964{ 946{
965 struct isi_port *port; 947 struct isi_port *port;
966 struct isi_board *card; 948 struct isi_board *card;
967 unsigned int line, board; 949 unsigned int board;
968 int error; 950 int error, line;
969 951
970 line = tty->index; 952 line = tty->index;
971 if (line < 0 || line > PORT_COUNT-1) 953 if (line < 0 || line > PORT_COUNT-1)
@@ -1062,11 +1044,12 @@ static void isicom_shutdown_port(struct isi_port *port)
1062static void isicom_close(struct tty_struct *tty, struct file *filp) 1044static void isicom_close(struct tty_struct *tty, struct file *filp)
1063{ 1045{
1064 struct isi_port *port = tty->driver_data; 1046 struct isi_port *port = tty->driver_data;
1065 struct isi_board *card = port->card; 1047 struct isi_board *card;
1066 unsigned long flags; 1048 unsigned long flags;
1067 1049
1068 if (!port) 1050 if (!port)
1069 return; 1051 return;
1052 card = port->card;
1070 if (isicom_paranoia_check(port, tty->name, "isicom_close")) 1053 if (isicom_paranoia_check(port, tty->name, "isicom_close"))
1071 return; 1054 return;
1072 1055
@@ -1398,7 +1381,7 @@ static int isicom_ioctl(struct tty_struct *tty, struct file *filp,
1398 1381
1399/* set_termios et all */ 1382/* set_termios et all */
1400static void isicom_set_termios(struct tty_struct *tty, 1383static void isicom_set_termios(struct tty_struct *tty,
1401 struct termios *old_termios) 1384 struct ktermios *old_termios)
1402{ 1385{
1403 struct isi_port *port = tty->driver_data; 1386 struct isi_port *port = tty->driver_data;
1404 1387
@@ -1473,9 +1456,9 @@ static void isicom_start(struct tty_struct *tty)
1473} 1456}
1474 1457
1475/* hangup et all */ 1458/* hangup et all */
1476static void do_isicom_hangup(void *data) 1459static void do_isicom_hangup(struct work_struct *work)
1477{ 1460{
1478 struct isi_port *port = data; 1461 struct isi_port *port = container_of(work, struct isi_port, hangup_tq);
1479 struct tty_struct *tty; 1462 struct tty_struct *tty;
1480 1463
1481 tty = port->tty; 1464 tty = port->tty;
@@ -1519,38 +1502,7 @@ static void isicom_flush_buffer(struct tty_struct *tty)
1519 * Driver init and deinit functions 1502 * Driver init and deinit functions
1520 */ 1503 */
1521 1504
1522static int __devinit isicom_register_ioregion(struct pci_dev *pdev, 1505static const struct tty_operations isicom_ops = {
1523 const unsigned int index)
1524{
1525 struct isi_board *board = pci_get_drvdata(pdev);
1526
1527 if (!board->base)
1528 return -EINVAL;
1529
1530 if (!request_region(board->base, 16, ISICOM_NAME)) {
1531 dev_dbg(&pdev->dev, "I/O Region 0x%lx-0x%lx is busy. Card%d "
1532 "will be disabled.\n", board->base, board->base + 15,
1533 index + 1);
1534 return -EBUSY;
1535 }
1536
1537 return 0;
1538}
1539
1540static void isicom_unregister_ioregion(struct pci_dev *pdev)
1541{
1542 struct isi_board *board = pci_get_drvdata(pdev);
1543
1544 if (!board->base)
1545 return;
1546
1547 release_region(board->base, 16);
1548 dev_dbg(&pdev->dev, "I/O Region 0x%lx-0x%lx released.\n",
1549 board->base, board->base + 15);
1550 board->base = 0;
1551}
1552
1553static struct tty_operations isicom_ops = {
1554 .open = isicom_open, 1506 .open = isicom_open,
1555 .close = isicom_close, 1507 .close = isicom_close,
1556 .write = isicom_write, 1508 .write = isicom_write,
@@ -1570,70 +1522,6 @@ static struct tty_operations isicom_ops = {
1570 .tiocmset = isicom_tiocmset, 1522 .tiocmset = isicom_tiocmset,
1571}; 1523};
1572 1524
1573static int __devinit isicom_register_tty_driver(void)
1574{
1575 int error = -ENOMEM;
1576
1577 /* tty driver structure initialization */
1578 isicom_normal = alloc_tty_driver(PORT_COUNT);
1579 if (!isicom_normal)
1580 goto end;
1581
1582 isicom_normal->owner = THIS_MODULE;
1583 isicom_normal->name = "ttyM";
1584 isicom_normal->major = ISICOM_NMAJOR;
1585 isicom_normal->minor_start = 0;
1586 isicom_normal->type = TTY_DRIVER_TYPE_SERIAL;
1587 isicom_normal->subtype = SERIAL_TYPE_NORMAL;
1588 isicom_normal->init_termios = tty_std_termios;
1589 isicom_normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL |
1590 CLOCAL;
1591 isicom_normal->flags = TTY_DRIVER_REAL_RAW;
1592 tty_set_operations(isicom_normal, &isicom_ops);
1593
1594 if ((error = tty_register_driver(isicom_normal))) {
1595 pr_dbg("Couldn't register the dialin driver, error=%d\n",
1596 error);
1597 put_tty_driver(isicom_normal);
1598 }
1599end:
1600 return error;
1601}
1602
1603static void isicom_unregister_tty_driver(void)
1604{
1605 int error;
1606
1607 if ((error = tty_unregister_driver(isicom_normal)))
1608 pr_dbg("couldn't unregister normal driver, error=%d.\n", error);
1609
1610 put_tty_driver(isicom_normal);
1611}
1612
1613static int __devinit isicom_register_isr(struct pci_dev *pdev,
1614 const unsigned int index)
1615{
1616 struct isi_board *board = pci_get_drvdata(pdev);
1617 unsigned long irqflags = IRQF_DISABLED;
1618 int retval = -EINVAL;
1619
1620 if (!board->base)
1621 goto end;
1622
1623 if (board->isa == NO)
1624 irqflags |= IRQF_SHARED;
1625
1626 retval = request_irq(board->irq, isicom_interrupt, irqflags,
1627 ISICOM_NAME, board);
1628 if (retval < 0)
1629 dev_warn(&pdev->dev, "Could not install handler at Irq %d. "
1630 "Card%d will be disabled.\n", board->irq, index + 1);
1631 else
1632 retval = 0;
1633end:
1634 return retval;
1635}
1636
1637static int __devinit reset_card(struct pci_dev *pdev, 1525static int __devinit reset_card(struct pci_dev *pdev,
1638 const unsigned int card, unsigned int *signature) 1526 const unsigned int card, unsigned int *signature)
1639{ 1527{
@@ -1655,36 +1543,23 @@ static int __devinit reset_card(struct pci_dev *pdev,
1655 1543
1656 *signature = inw(base + 0x4) & 0xff; 1544 *signature = inw(base + 0x4) & 0xff;
1657 1545
1658 if (board->isa == YES) { 1546 portcount = inw(base + 0x2);
1659 if (!(inw(base + 0xe) & 0x1) || (inw(base + 0x2))) { 1547 if (!(inw(base + 0xe) & 0x1) || ((portcount != 0) &&
1660 dev_dbg(&pdev->dev, "base+0x2=0x%lx, base+0xe=0x%lx\n", 1548 (portcount != 4) && (portcount != 8))) {
1661 inw(base + 0x2), inw(base + 0xe)); 1549 dev_dbg(&pdev->dev, "base+0x2=0x%lx, base+0xe=0x%lx\n",
1662 dev_err(&pdev->dev, "ISILoad:ISA Card%d reset failure " 1550 inw(base + 0x2), inw(base + 0xe));
1663 "(Possible bad I/O Port Address 0x%lx).\n", 1551 dev_err(&pdev->dev, "ISILoad:PCI Card%d reset failure "
1664 card + 1, base); 1552 "(Possible bad I/O Port Address 0x%lx).\n",
1665 retval = -EIO; 1553 card + 1, base);
1666 goto end; 1554 retval = -EIO;
1667 } 1555 goto end;
1668 } else {
1669 portcount = inw(base + 0x2);
1670 if (!(inw(base + 0xe) & 0x1) || ((portcount != 0) &&
1671 (portcount != 4) && (portcount != 8))) {
1672 dev_dbg(&pdev->dev, "base+0x2=0x%lx, base+0xe=0x%lx\n",
1673 inw(base + 0x2), inw(base + 0xe));
1674 dev_err(&pdev->dev, "ISILoad:PCI Card%d reset failure "
1675 "(Possible bad I/O Port Address 0x%lx).\n",
1676 card + 1, base);
1677 retval = -EIO;
1678 goto end;
1679 }
1680 } 1556 }
1681 1557
1682 switch (*signature) { 1558 switch (*signature) {
1683 case 0xa5: 1559 case 0xa5:
1684 case 0xbb: 1560 case 0xbb:
1685 case 0xdd: 1561 case 0xdd:
1686 board->port_count = (board->isa == NO && portcount == 4) ? 4 : 1562 board->port_count = (portcount == 4) ? 4 : 8;
1687 8;
1688 board->shift_count = 12; 1563 board->shift_count = 12;
1689 break; 1564 break;
1690 case 0xcc: 1565 case 0xcc:
@@ -1756,9 +1631,12 @@ static int __devinit load_firmware(struct pci_dev *pdev,
1756 if (retval) 1631 if (retval)
1757 goto end; 1632 goto end;
1758 1633
1634 retval = -EIO;
1635
1759 for (frame = (struct stframe *)fw->data; 1636 for (frame = (struct stframe *)fw->data;
1760 frame < (struct stframe *)(fw->data + fw->size); 1637 frame < (struct stframe *)(fw->data + fw->size);
1761 frame++) { 1638 frame = (struct stframe *)((u8 *)(frame + 1) +
1639 frame->count)) {
1762 if (WaitTillCardIsFree(base)) 1640 if (WaitTillCardIsFree(base))
1763 goto errrelfw; 1641 goto errrelfw;
1764 1642
@@ -1797,23 +1675,12 @@ static int __devinit load_firmware(struct pci_dev *pdev,
1797 } 1675 }
1798 } 1676 }
1799 1677
1800 retval = -EIO;
1801
1802 if (WaitTillCardIsFree(base))
1803 goto errrelfw;
1804
1805 outw(0xf2, base);
1806 outw(0x800, base);
1807 outw(0x0, base);
1808 outw(0x0, base);
1809 InterruptTheCard(base);
1810 outw(0x0, base + 0x4); /* for ISI4608 cards */
1811
1812/* XXX: should we test it by reading it back and comparing with original like 1678/* XXX: should we test it by reading it back and comparing with original like
1813 * in load firmware package? */ 1679 * in load firmware package? */
1814 for (frame = (struct stframe*)fw->data; 1680 for (frame = (struct stframe *)fw->data;
1815 frame < (struct stframe*)(fw->data + fw->size); 1681 frame < (struct stframe *)(fw->data + fw->size);
1816 frame++) { 1682 frame = (struct stframe *)((u8 *)(frame + 1) +
1683 frame->count)) {
1817 if (WaitTillCardIsFree(base)) 1684 if (WaitTillCardIsFree(base))
1818 goto errrelfw; 1685 goto errrelfw;
1819 1686
@@ -1838,6 +1705,11 @@ static int __devinit load_firmware(struct pci_dev *pdev,
1838 } 1705 }
1839 1706
1840 data = kmalloc(word_count * 2, GFP_KERNEL); 1707 data = kmalloc(word_count * 2, GFP_KERNEL);
1708 if (data == NULL) {
1709 dev_err(&pdev->dev, "Card%d, firmware upload "
1710 "failed, not enough memory\n", index + 1);
1711 goto errrelfw;
1712 }
1841 inw(base); 1713 inw(base);
1842 insw(base, data, word_count); 1714 insw(base, data, word_count);
1843 InterruptTheCard(base); 1715 InterruptTheCard(base);
@@ -1863,6 +1735,17 @@ static int __devinit load_firmware(struct pci_dev *pdev,
1863 } 1735 }
1864 } 1736 }
1865 1737
1738 /* xfer ctrl */
1739 if (WaitTillCardIsFree(base))
1740 goto errrelfw;
1741
1742 outw(0xf2, base);
1743 outw(0x800, base);
1744 outw(0x0, base);
1745 outw(0x0, base);
1746 InterruptTheCard(base);
1747 outw(0x0, base + 0x4); /* for ISI4608 cards */
1748
1866 board->status |= FIRMWARE_LOADED; 1749 board->status |= FIRMWARE_LOADED;
1867 retval = 0; 1750 retval = 0;
1868 1751
@@ -1875,8 +1758,6 @@ end:
1875/* 1758/*
1876 * Insmod can set static symbols so keep these static 1759 * Insmod can set static symbols so keep these static
1877 */ 1760 */
1878static int io[4];
1879static int irq[4];
1880static int card; 1761static int card;
1881 1762
1882static int __devinit isicom_probe(struct pci_dev *pdev, 1763static int __devinit isicom_probe(struct pci_dev *pdev,
@@ -1902,20 +1783,29 @@ static int __devinit isicom_probe(struct pci_dev *pdev,
1902 break; 1783 break;
1903 } 1784 }
1904 1785
1786 board->index = index;
1905 board->base = ioaddr; 1787 board->base = ioaddr;
1906 board->irq = pciirq; 1788 board->irq = pciirq;
1907 board->isa = NO;
1908 card++; 1789 card++;
1909 1790
1910 pci_set_drvdata(pdev, board); 1791 pci_set_drvdata(pdev, board);
1911 1792
1912 retval = isicom_register_ioregion(pdev, index); 1793 retval = pci_request_region(pdev, 3, ISICOM_NAME);
1913 if (retval < 0) 1794 if (retval) {
1795 dev_err(&pdev->dev, "I/O Region 0x%lx-0x%lx is busy. Card%d "
1796 "will be disabled.\n", board->base, board->base + 15,
1797 index + 1);
1798 retval = -EBUSY;
1914 goto err; 1799 goto err;
1800 }
1915 1801
1916 retval = isicom_register_isr(pdev, index); 1802 retval = request_irq(board->irq, isicom_interrupt,
1917 if (retval < 0) 1803 IRQF_SHARED | IRQF_DISABLED, ISICOM_NAME, board);
1804 if (retval < 0) {
1805 dev_err(&pdev->dev, "Could not install handler at Irq %d. "
1806 "Card%d will be disabled.\n", board->irq, index + 1);
1918 goto errunrr; 1807 goto errunrr;
1808 }
1919 1809
1920 retval = reset_card(pdev, index, &signature); 1810 retval = reset_card(pdev, index, &signature);
1921 if (retval < 0) 1811 if (retval < 0)
@@ -1925,12 +1815,16 @@ static int __devinit isicom_probe(struct pci_dev *pdev,
1925 if (retval < 0) 1815 if (retval < 0)
1926 goto errunri; 1816 goto errunri;
1927 1817
1818 for (index = 0; index < board->port_count; index++)
1819 tty_register_device(isicom_normal, board->index * 16 + index,
1820 &pdev->dev);
1821
1928 return 0; 1822 return 0;
1929 1823
1930errunri: 1824errunri:
1931 free_irq(board->irq, board); 1825 free_irq(board->irq, board);
1932errunrr: 1826errunrr:
1933 isicom_unregister_ioregion(pdev); 1827 pci_release_region(pdev, 3);
1934err: 1828err:
1935 board->base = 0; 1829 board->base = 0;
1936 return retval; 1830 return retval;
@@ -1939,18 +1833,21 @@ err:
1939static void __devexit isicom_remove(struct pci_dev *pdev) 1833static void __devexit isicom_remove(struct pci_dev *pdev)
1940{ 1834{
1941 struct isi_board *board = pci_get_drvdata(pdev); 1835 struct isi_board *board = pci_get_drvdata(pdev);
1836 unsigned int i;
1837
1838 for (i = 0; i < board->port_count; i++)
1839 tty_unregister_device(isicom_normal, board->index * 16 + i);
1942 1840
1943 free_irq(board->irq, board); 1841 free_irq(board->irq, board);
1944 isicom_unregister_ioregion(pdev); 1842 pci_release_region(pdev, 3);
1945} 1843}
1946 1844
1947static int __devinit isicom_setup(void) 1845static int __init isicom_init(void)
1948{ 1846{
1949 int retval, idx, channel; 1847 int retval, idx, channel;
1950 struct isi_port *port; 1848 struct isi_port *port;
1951 1849
1952 card = 0; 1850 card = 0;
1953 memset(isi_ports, 0, sizeof(isi_ports));
1954 1851
1955 for(idx = 0; idx < BOARD_COUNT; idx++) { 1852 for(idx = 0; idx < BOARD_COUNT; idx++) {
1956 port = &isi_ports[idx * 16]; 1853 port = &isi_ports[idx * 16];
@@ -1962,8 +1859,8 @@ static int __devinit isicom_setup(void)
1962 port->channel = channel; 1859 port->channel = channel;
1963 port->close_delay = 50 * HZ/100; 1860 port->close_delay = 50 * HZ/100;
1964 port->closing_wait = 3000 * HZ/100; 1861 port->closing_wait = 3000 * HZ/100;
1965 INIT_WORK(&port->hangup_tq, do_isicom_hangup, port); 1862 INIT_WORK(&port->hangup_tq, do_isicom_hangup);
1966 INIT_WORK(&port->bh_tqueue, isicom_bottomhalf, port); 1863 INIT_WORK(&port->bh_tqueue, isicom_bottomhalf);
1967 port->status = 0; 1864 port->status = 0;
1968 init_waitqueue_head(&port->open_wait); 1865 init_waitqueue_head(&port->open_wait);
1969 init_waitqueue_head(&port->close_wait); 1866 init_waitqueue_head(&port->close_wait);
@@ -1971,66 +1868,65 @@ static int __devinit isicom_setup(void)
1971 } 1868 }
1972 isi_card[idx].base = 0; 1869 isi_card[idx].base = 0;
1973 isi_card[idx].irq = 0; 1870 isi_card[idx].irq = 0;
1974
1975 if (!io[idx])
1976 continue;
1977
1978 if (irq[idx] == 2 || irq[idx] == 3 || irq[idx] == 4 ||
1979 irq[idx] == 5 || irq[idx] == 7 ||
1980 irq[idx] == 10 || irq[idx] == 11 ||
1981 irq[idx] == 12 || irq[idx] == 15) {
1982 printk(KERN_ERR "ISICOM: ISA not supported yet.\n");
1983 retval = -EINVAL;
1984 goto error;
1985 } else
1986 printk(KERN_ERR "ISICOM: Irq %d unsupported. "
1987 "Disabling Card%d...\n", irq[idx], idx + 1);
1988 } 1871 }
1989 1872
1990 retval = isicom_register_tty_driver(); 1873 /* tty driver structure initialization */
1991 if (retval < 0) 1874 isicom_normal = alloc_tty_driver(PORT_COUNT);
1875 if (!isicom_normal) {
1876 retval = -ENOMEM;
1992 goto error; 1877 goto error;
1878 }
1879
1880 isicom_normal->owner = THIS_MODULE;
1881 isicom_normal->name = "ttyM";
1882 isicom_normal->major = ISICOM_NMAJOR;
1883 isicom_normal->minor_start = 0;
1884 isicom_normal->type = TTY_DRIVER_TYPE_SERIAL;
1885 isicom_normal->subtype = SERIAL_TYPE_NORMAL;
1886 isicom_normal->init_termios = tty_std_termios;
1887 isicom_normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL |
1888 CLOCAL;
1889 isicom_normal->flags = TTY_DRIVER_REAL_RAW |
1890 TTY_DRIVER_DYNAMIC_DEV;
1891 tty_set_operations(isicom_normal, &isicom_ops);
1892
1893 retval = tty_register_driver(isicom_normal);
1894 if (retval) {
1895 pr_dbg("Couldn't register the dialin driver\n");
1896 goto err_puttty;
1897 }
1993 1898
1994 retval = pci_register_driver(&isicom_driver); 1899 retval = pci_register_driver(&isicom_driver);
1995 if (retval < 0) { 1900 if (retval < 0) {
1996 printk(KERN_ERR "ISICOM: Unable to register pci driver.\n"); 1901 printk(KERN_ERR "ISICOM: Unable to register pci driver.\n");
1997 goto errtty; 1902 goto err_unrtty;
1998 } 1903 }
1999 1904
2000 init_timer(&tx); 1905 mod_timer(&tx, jiffies + 1);
2001 tx.expires = jiffies + 1;
2002 tx.data = 0;
2003 tx.function = isicom_tx;
2004 re_schedule = 1;
2005 add_timer(&tx);
2006 1906
2007 return 0; 1907 return 0;
2008errtty: 1908err_unrtty:
2009 isicom_unregister_tty_driver(); 1909 tty_unregister_driver(isicom_normal);
1910err_puttty:
1911 put_tty_driver(isicom_normal);
2010error: 1912error:
2011 return retval; 1913 return retval;
2012} 1914}
2013 1915
2014static void __exit isicom_exit(void) 1916static void __exit isicom_exit(void)
2015{ 1917{
2016 unsigned int index = 0;
2017
2018 re_schedule = 0; 1918 re_schedule = 0;
2019 1919
2020 while (re_schedule != 2 && index++ < 100) 1920 wait_for_completion_timeout(&isi_timerdone, HZ);
2021 msleep(10);
2022 1921
2023 pci_unregister_driver(&isicom_driver); 1922 pci_unregister_driver(&isicom_driver);
2024 isicom_unregister_tty_driver(); 1923 tty_unregister_driver(isicom_normal);
1924 put_tty_driver(isicom_normal);
2025} 1925}
2026 1926
2027module_init(isicom_setup); 1927module_init(isicom_init);
2028module_exit(isicom_exit); 1928module_exit(isicom_exit);
2029 1929
2030MODULE_AUTHOR("MultiTech"); 1930MODULE_AUTHOR("MultiTech");
2031MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech"); 1931MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech");
2032MODULE_LICENSE("GPL"); 1932MODULE_LICENSE("GPL");
2033module_param_array(io, int, NULL, 0);
2034MODULE_PARM_DESC(io, "I/O ports for the cards");
2035module_param_array(irq, int, NULL, 0);
2036MODULE_PARM_DESC(irq, "Interrupts for the cards");
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index 8c09997cc3d6..68645d351873 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -14,14 +14,6 @@
14 * the Free Software Foundation; either version 2 of the License, or 14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version. 15 * (at your option) any later version.
16 * 16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */ 17 */
26 18
27/*****************************************************************************/ 19/*****************************************************************************/
@@ -41,6 +33,7 @@
41#include <linux/device.h> 33#include <linux/device.h>
42#include <linux/wait.h> 34#include <linux/wait.h>
43#include <linux/eisa.h> 35#include <linux/eisa.h>
36#include <linux/ctype.h>
44 37
45#include <asm/io.h> 38#include <asm/io.h>
46#include <asm/uaccess.h> 39#include <asm/uaccess.h>
@@ -61,21 +54,10 @@
61#define BRD_BRUMBY4 2 54#define BRD_BRUMBY4 2
62#define BRD_ONBOARD2 3 55#define BRD_ONBOARD2 3
63#define BRD_ONBOARD 4 56#define BRD_ONBOARD 4
64#define BRD_BRUMBY8 5
65#define BRD_BRUMBY16 6
66#define BRD_ONBOARDE 7 57#define BRD_ONBOARDE 7
67#define BRD_ONBOARD32 9
68#define BRD_ONBOARD2_32 10
69#define BRD_ONBOARDRS 11
70#define BRD_EASYIO 20
71#define BRD_ECH 21
72#define BRD_ECHMC 22
73#define BRD_ECP 23 58#define BRD_ECP 23
74#define BRD_ECPE 24 59#define BRD_ECPE 24
75#define BRD_ECPMC 25 60#define BRD_ECPMC 25
76#define BRD_ECHPCI 26
77#define BRD_ECH64PCI 27
78#define BRD_EASYIOPCI 28
79#define BRD_ECPPCI 29 61#define BRD_ECPPCI 29
80 62
81#define BRD_BRUMBY BRD_BRUMBY4 63#define BRD_BRUMBY BRD_BRUMBY4
@@ -119,20 +101,16 @@
119 * interrupt is required. 101 * interrupt is required.
120 */ 102 */
121 103
122typedef struct { 104struct stlconf {
123 int brdtype; 105 int brdtype;
124 int ioaddr1; 106 int ioaddr1;
125 int ioaddr2; 107 int ioaddr2;
126 unsigned long memaddr; 108 unsigned long memaddr;
127 int irq; 109 int irq;
128 int irqtype; 110 int irqtype;
129} stlconf_t;
130
131static stlconf_t stli_brdconf[] = {
132 /*{ BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },*/
133}; 111};
134 112
135static int stli_nrbrds = ARRAY_SIZE(stli_brdconf); 113static unsigned int stli_nrbrds;
136 114
137/* stli_lock must NOT be taken holding brd_lock */ 115/* stli_lock must NOT be taken holding brd_lock */
138static spinlock_t stli_lock; /* TTY logic lock */ 116static spinlock_t stli_lock; /* TTY logic lock */
@@ -194,9 +172,11 @@ static struct tty_struct *stli_txcooktty;
194 * with this termios initially. Basically all it defines is a raw port 172 * with this termios initially. Basically all it defines is a raw port
195 * at 9600 baud, 8 data bits, no parity, 1 stop bit. 173 * at 9600 baud, 8 data bits, no parity, 1 stop bit.
196 */ 174 */
197static struct termios stli_deftermios = { 175static struct ktermios stli_deftermios = {
198 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL), 176 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
199 .c_cc = INIT_C_CC, 177 .c_cc = INIT_C_CC,
178 .c_ispeed = 9600,
179 .c_ospeed = 9600,
200}; 180};
201 181
202/* 182/*
@@ -205,13 +185,12 @@ static struct termios stli_deftermios = {
205 */ 185 */
206static comstats_t stli_comstats; 186static comstats_t stli_comstats;
207static combrd_t stli_brdstats; 187static combrd_t stli_brdstats;
208static asystats_t stli_cdkstats; 188static struct asystats stli_cdkstats;
209static stlibrd_t stli_dummybrd;
210static stliport_t stli_dummyport;
211 189
212/*****************************************************************************/ 190/*****************************************************************************/
213 191
214static stlibrd_t *stli_brds[STL_MAXBRDS]; 192static DEFINE_MUTEX(stli_brdslock);
193static struct stlibrd *stli_brds[STL_MAXBRDS];
215 194
216static int stli_shared; 195static int stli_shared;
217 196
@@ -223,6 +202,7 @@ static int stli_shared;
223 */ 202 */
224#define BST_FOUND 0x1 203#define BST_FOUND 0x1
225#define BST_STARTED 0x2 204#define BST_STARTED 0x2
205#define BST_PROBED 0x4
226 206
227/* 207/*
228 * Define the set of port state flags. These are marked for internal 208 * Define the set of port state flags. These are marked for internal
@@ -255,18 +235,18 @@ static char *stli_brdnames[] = {
255 "Brumby", 235 "Brumby",
256 "Brumby", 236 "Brumby",
257 "ONboard-EI", 237 "ONboard-EI",
258 (char *) NULL, 238 NULL,
259 "ONboard", 239 "ONboard",
260 "ONboard-MC", 240 "ONboard-MC",
261 "ONboard-MC", 241 "ONboard-MC",
262 (char *) NULL, 242 NULL,
263 (char *) NULL, 243 NULL,
264 (char *) NULL, 244 NULL,
265 (char *) NULL, 245 NULL,
266 (char *) NULL, 246 NULL,
267 (char *) NULL, 247 NULL,
268 (char *) NULL, 248 NULL,
269 (char *) NULL, 249 NULL,
270 "EasyIO", 250 "EasyIO",
271 "EC8/32-AT", 251 "EC8/32-AT",
272 "EC8/32-MC", 252 "EC8/32-MC",
@@ -304,12 +284,10 @@ static char **stli_brdsp[] = {
304 * parse any module arguments. 284 * parse any module arguments.
305 */ 285 */
306 286
307typedef struct stlibrdtype { 287static struct stlibrdtype {
308 char *name; 288 char *name;
309 int type; 289 int type;
310} stlibrdtype_t; 290} stli_brdstr[] = {
311
312static stlibrdtype_t stli_brdstr[] = {
313 { "stallion", BRD_STALLION }, 291 { "stallion", BRD_STALLION },
314 { "1", BRD_STALLION }, 292 { "1", BRD_STALLION },
315 { "brumby", BRD_BRUMBY }, 293 { "brumby", BRD_BRUMBY },
@@ -379,6 +357,7 @@ MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
379module_param_array(board3, charp, NULL, 0); 357module_param_array(board3, charp, NULL, 0);
380MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]"); 358MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
381 359
360#if STLI_EISAPROBE != 0
382/* 361/*
383 * Set up a default memory address table for EISA board probing. 362 * Set up a default memory address table for EISA board probing.
384 * The default addresses are all bellow 1Mbyte, which has to be the 363 * The default addresses are all bellow 1Mbyte, which has to be the
@@ -396,14 +375,11 @@ static unsigned long stli_eisamemprobeaddrs[] = {
396}; 375};
397 376
398static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs); 377static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
378#endif
399 379
400/* 380/*
401 * Define the Stallion PCI vendor and device IDs. 381 * Define the Stallion PCI vendor and device IDs.
402 */ 382 */
403#ifdef CONFIG_PCI
404#ifndef PCI_VENDOR_ID_STALLION
405#define PCI_VENDOR_ID_STALLION 0x124d
406#endif
407#ifndef PCI_DEVICE_ID_ECRA 383#ifndef PCI_DEVICE_ID_ECRA
408#define PCI_DEVICE_ID_ECRA 0x0004 384#define PCI_DEVICE_ID_ECRA 0x0004
409#endif 385#endif
@@ -414,7 +390,7 @@ static struct pci_device_id istallion_pci_tbl[] = {
414}; 390};
415MODULE_DEVICE_TABLE(pci, istallion_pci_tbl); 391MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
416 392
417#endif /* CONFIG_PCI */ 393static struct pci_driver stli_pcidriver;
418 394
419/*****************************************************************************/ 395/*****************************************************************************/
420 396
@@ -612,35 +588,13 @@ MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
612#define MINOR2BRD(min) (((min) & 0xc0) >> 6) 588#define MINOR2BRD(min) (((min) & 0xc0) >> 6)
613#define MINOR2PORT(min) ((min) & 0x3f) 589#define MINOR2PORT(min) ((min) & 0x3f)
614 590
615/*
616 * Define a baud rate table that converts termios baud rate selector
617 * into the actual baud rate value. All baud rate calculations are based
618 * on the actual baud rate required.
619 */
620static unsigned int stli_baudrates[] = {
621 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
622 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
623};
624
625/*****************************************************************************/
626
627/*
628 * Define some handy local macros...
629 */
630#undef MIN
631#define MIN(a,b) (((a) <= (b)) ? (a) : (b))
632
633#undef TOLOWER
634#define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
635
636/*****************************************************************************/ 591/*****************************************************************************/
637 592
638/* 593/*
639 * Prototype all functions in this driver! 594 * Prototype all functions in this driver!
640 */ 595 */
641 596
642static int stli_parsebrd(stlconf_t *confp, char **argp); 597static int stli_parsebrd(struct stlconf *confp, char **argp);
643static int stli_init(void);
644static int stli_open(struct tty_struct *tty, struct file *filp); 598static int stli_open(struct tty_struct *tty, struct file *filp);
645static void stli_close(struct tty_struct *tty, struct file *filp); 599static void stli_close(struct tty_struct *tty, struct file *filp);
646static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count); 600static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
@@ -649,7 +603,7 @@ static void stli_flushchars(struct tty_struct *tty);
649static int stli_writeroom(struct tty_struct *tty); 603static int stli_writeroom(struct tty_struct *tty);
650static int stli_charsinbuffer(struct tty_struct *tty); 604static int stli_charsinbuffer(struct tty_struct *tty);
651static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg); 605static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
652static void stli_settermios(struct tty_struct *tty, struct termios *old); 606static void stli_settermios(struct tty_struct *tty, struct ktermios *old);
653static void stli_throttle(struct tty_struct *tty); 607static void stli_throttle(struct tty_struct *tty);
654static void stli_unthrottle(struct tty_struct *tty); 608static void stli_unthrottle(struct tty_struct *tty);
655static void stli_stop(struct tty_struct *tty); 609static void stli_stop(struct tty_struct *tty);
@@ -659,86 +613,84 @@ static void stli_breakctl(struct tty_struct *tty, int state);
659static void stli_waituntilsent(struct tty_struct *tty, int timeout); 613static void stli_waituntilsent(struct tty_struct *tty, int timeout);
660static void stli_sendxchar(struct tty_struct *tty, char ch); 614static void stli_sendxchar(struct tty_struct *tty, char ch);
661static void stli_hangup(struct tty_struct *tty); 615static void stli_hangup(struct tty_struct *tty);
662static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos); 616static int stli_portinfo(struct stlibrd *brdp, struct stliport *portp, int portnr, char *pos);
663 617
664static int stli_brdinit(stlibrd_t *brdp); 618static int stli_brdinit(struct stlibrd *brdp);
665static int stli_startbrd(stlibrd_t *brdp); 619static int stli_startbrd(struct stlibrd *brdp);
666static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp); 620static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
667static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp); 621static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
668static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg); 622static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
669static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp); 623static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp);
670static void stli_poll(unsigned long arg); 624static void stli_poll(unsigned long arg);
671static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp); 625static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp);
672static int stli_initopen(stlibrd_t *brdp, stliport_t *portp); 626static int stli_initopen(struct stlibrd *brdp, struct stliport *portp);
673static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait); 627static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
674static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait); 628static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
675static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp); 629static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct file *filp);
676static void stli_dohangup(void *arg); 630static void stli_dohangup(struct work_struct *);
677static int stli_setport(stliport_t *portp); 631static int stli_setport(struct stliport *portp);
678static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback); 632static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
679static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback); 633static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
680static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback); 634static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
681static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp); 635static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp);
682static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp); 636static void stli_mkasyport(struct stliport *portp, asyport_t *pp, struct ktermios *tiosp);
683static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts); 637static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
684static long stli_mktiocm(unsigned long sigvalue); 638static long stli_mktiocm(unsigned long sigvalue);
685static void stli_read(stlibrd_t *brdp, stliport_t *portp); 639static void stli_read(struct stlibrd *brdp, struct stliport *portp);
686static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp); 640static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp);
687static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp); 641static int stli_setserial(struct stliport *portp, struct serial_struct __user *sp);
688static int stli_getbrdstats(combrd_t __user *bp); 642static int stli_getbrdstats(combrd_t __user *bp);
689static int stli_getportstats(stliport_t *portp, comstats_t __user *cp); 643static int stli_getportstats(struct stliport *portp, comstats_t __user *cp);
690static int stli_portcmdstats(stliport_t *portp); 644static int stli_portcmdstats(struct stliport *portp);
691static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp); 645static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp);
692static int stli_getportstruct(stliport_t __user *arg); 646static int stli_getportstruct(struct stliport __user *arg);
693static int stli_getbrdstruct(stlibrd_t __user *arg); 647static int stli_getbrdstruct(struct stlibrd __user *arg);
694static stlibrd_t *stli_allocbrd(void); 648static struct stlibrd *stli_allocbrd(void);
695 649
696static void stli_ecpinit(stlibrd_t *brdp); 650static void stli_ecpinit(struct stlibrd *brdp);
697static void stli_ecpenable(stlibrd_t *brdp); 651static void stli_ecpenable(struct stlibrd *brdp);
698static void stli_ecpdisable(stlibrd_t *brdp); 652static void stli_ecpdisable(struct stlibrd *brdp);
699static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line); 653static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
700static void stli_ecpreset(stlibrd_t *brdp); 654static void stli_ecpreset(struct stlibrd *brdp);
701static void stli_ecpintr(stlibrd_t *brdp); 655static void stli_ecpintr(struct stlibrd *brdp);
702static void stli_ecpeiinit(stlibrd_t *brdp); 656static void stli_ecpeiinit(struct stlibrd *brdp);
703static void stli_ecpeienable(stlibrd_t *brdp); 657static void stli_ecpeienable(struct stlibrd *brdp);
704static void stli_ecpeidisable(stlibrd_t *brdp); 658static void stli_ecpeidisable(struct stlibrd *brdp);
705static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line); 659static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
706static void stli_ecpeireset(stlibrd_t *brdp); 660static void stli_ecpeireset(struct stlibrd *brdp);
707static void stli_ecpmcenable(stlibrd_t *brdp); 661static void stli_ecpmcenable(struct stlibrd *brdp);
708static void stli_ecpmcdisable(stlibrd_t *brdp); 662static void stli_ecpmcdisable(struct stlibrd *brdp);
709static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line); 663static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
710static void stli_ecpmcreset(stlibrd_t *brdp); 664static void stli_ecpmcreset(struct stlibrd *brdp);
711static void stli_ecppciinit(stlibrd_t *brdp); 665static void stli_ecppciinit(struct stlibrd *brdp);
712static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line); 666static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
713static void stli_ecppcireset(stlibrd_t *brdp); 667static void stli_ecppcireset(struct stlibrd *brdp);
714 668
715static void stli_onbinit(stlibrd_t *brdp); 669static void stli_onbinit(struct stlibrd *brdp);
716static void stli_onbenable(stlibrd_t *brdp); 670static void stli_onbenable(struct stlibrd *brdp);
717static void stli_onbdisable(stlibrd_t *brdp); 671static void stli_onbdisable(struct stlibrd *brdp);
718static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line); 672static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
719static void stli_onbreset(stlibrd_t *brdp); 673static void stli_onbreset(struct stlibrd *brdp);
720static void stli_onbeinit(stlibrd_t *brdp); 674static void stli_onbeinit(struct stlibrd *brdp);
721static void stli_onbeenable(stlibrd_t *brdp); 675static void stli_onbeenable(struct stlibrd *brdp);
722static void stli_onbedisable(stlibrd_t *brdp); 676static void stli_onbedisable(struct stlibrd *brdp);
723static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line); 677static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
724static void stli_onbereset(stlibrd_t *brdp); 678static void stli_onbereset(struct stlibrd *brdp);
725static void stli_bbyinit(stlibrd_t *brdp); 679static void stli_bbyinit(struct stlibrd *brdp);
726static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line); 680static void __iomem *stli_bbygetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
727static void stli_bbyreset(stlibrd_t *brdp); 681static void stli_bbyreset(struct stlibrd *brdp);
728static void stli_stalinit(stlibrd_t *brdp); 682static void stli_stalinit(struct stlibrd *brdp);
729static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line); 683static void __iomem *stli_stalgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
730static void stli_stalreset(stlibrd_t *brdp); 684static void stli_stalreset(struct stlibrd *brdp);
731 685
732static stliport_t *stli_getport(int brdnr, int panelnr, int portnr); 686static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr, unsigned int portnr);
733 687
734static int stli_initecp(stlibrd_t *brdp); 688static int stli_initecp(struct stlibrd *brdp);
735static int stli_initonb(stlibrd_t *brdp); 689static int stli_initonb(struct stlibrd *brdp);
736static int stli_eisamemprobe(stlibrd_t *brdp); 690#if STLI_EISAPROBE != 0
737static int stli_initports(stlibrd_t *brdp); 691static int stli_eisamemprobe(struct stlibrd *brdp);
738
739#ifdef CONFIG_PCI
740static int stli_initpcibrd(int brdtype, struct pci_dev *devp);
741#endif 692#endif
693static int stli_initports(struct stlibrd *brdp);
742 694
743/*****************************************************************************/ 695/*****************************************************************************/
744 696
@@ -776,154 +728,37 @@ static int stli_timeron;
776 728
777static struct class *istallion_class; 729static struct class *istallion_class;
778 730
779/* 731static void stli_cleanup_ports(struct stlibrd *brdp)
780 * Loadable module initialization stuff.
781 */
782
783static int __init istallion_module_init(void)
784{ 732{
785 stli_init(); 733 struct stliport *portp;
786 return 0; 734 unsigned int j;
787} 735
788 736 for (j = 0; j < STL_MAXPORTS; j++) {
789/*****************************************************************************/ 737 portp = brdp->ports[j];
790 738 if (portp != NULL) {
791static void __exit istallion_module_exit(void) 739 if (portp->tty != NULL)
792{ 740 tty_hangup(portp->tty);
793 stlibrd_t *brdp; 741 kfree(portp);
794 stliport_t *portp;
795 int i, j;
796
797 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
798 stli_drvversion);
799
800 /*
801 * Free up all allocated resources used by the ports. This includes
802 * memory and interrupts.
803 */
804 if (stli_timeron) {
805 stli_timeron = 0;
806 del_timer_sync(&stli_timerlist);
807 }
808
809 i = tty_unregister_driver(stli_serial);
810 if (i) {
811 printk("STALLION: failed to un-register tty driver, "
812 "errno=%d\n", -i);
813 return;
814 }
815 put_tty_driver(stli_serial);
816 for (i = 0; i < 4; i++)
817 class_device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR, i));
818 class_destroy(istallion_class);
819 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
820 printk("STALLION: failed to un-register serial memory device, "
821 "errno=%d\n", -i);
822
823 kfree(stli_txcookbuf);
824
825 for (i = 0; (i < stli_nrbrds); i++) {
826 if ((brdp = stli_brds[i]) == NULL)
827 continue;
828 for (j = 0; (j < STL_MAXPORTS); j++) {
829 portp = brdp->ports[j];
830 if (portp != NULL) {
831 if (portp->tty != NULL)
832 tty_hangup(portp->tty);
833 kfree(portp);
834 }
835 } 742 }
836
837 iounmap(brdp->membase);
838 if (brdp->iosize > 0)
839 release_region(brdp->iobase, brdp->iosize);
840 kfree(brdp);
841 stli_brds[i] = NULL;
842 } 743 }
843} 744}
844 745
845module_init(istallion_module_init);
846module_exit(istallion_module_exit);
847
848/*****************************************************************************/
849
850/*
851 * Check for any arguments passed in on the module load command line.
852 */
853
854static void stli_argbrds(void)
855{
856 stlconf_t conf;
857 stlibrd_t *brdp;
858 int i;
859
860 for (i = stli_nrbrds; i < ARRAY_SIZE(stli_brdsp); i++) {
861 memset(&conf, 0, sizeof(conf));
862 if (stli_parsebrd(&conf, stli_brdsp[i]) == 0)
863 continue;
864 if ((brdp = stli_allocbrd()) == NULL)
865 continue;
866 stli_nrbrds = i + 1;
867 brdp->brdnr = i;
868 brdp->brdtype = conf.brdtype;
869 brdp->iobase = conf.ioaddr1;
870 brdp->memaddr = conf.memaddr;
871 stli_brdinit(brdp);
872 }
873}
874
875/*****************************************************************************/
876
877/*
878 * Convert an ascii string number into an unsigned long.
879 */
880
881static unsigned long stli_atol(char *str)
882{
883 unsigned long val;
884 int base, c;
885 char *sp;
886
887 val = 0;
888 sp = str;
889 if ((*sp == '0') && (*(sp+1) == 'x')) {
890 base = 16;
891 sp += 2;
892 } else if (*sp == '0') {
893 base = 8;
894 sp++;
895 } else {
896 base = 10;
897 }
898
899 for (; (*sp != 0); sp++) {
900 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
901 if ((c < 0) || (c >= base)) {
902 printk("STALLION: invalid argument %s\n", str);
903 val = 0;
904 break;
905 }
906 val = (val * base) + c;
907 }
908 return(val);
909}
910
911/*****************************************************************************/ 746/*****************************************************************************/
912 747
913/* 748/*
914 * Parse the supplied argument string, into the board conf struct. 749 * Parse the supplied argument string, into the board conf struct.
915 */ 750 */
916 751
917static int stli_parsebrd(stlconf_t *confp, char **argp) 752static int stli_parsebrd(struct stlconf *confp, char **argp)
918{ 753{
754 unsigned int i;
919 char *sp; 755 char *sp;
920 int i;
921 756
922 if (argp[0] == NULL || *argp[0] == 0) 757 if (argp[0] == NULL || *argp[0] == 0)
923 return 0; 758 return 0;
924 759
925 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++) 760 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
926 *sp = TOLOWER(*sp); 761 *sp = tolower(*sp);
927 762
928 for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) { 763 for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) {
929 if (strcmp(stli_brdstr[i].name, argp[0]) == 0) 764 if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
@@ -936,9 +771,9 @@ static int stli_parsebrd(stlconf_t *confp, char **argp)
936 771
937 confp->brdtype = stli_brdstr[i].type; 772 confp->brdtype = stli_brdstr[i].type;
938 if (argp[1] != NULL && *argp[1] != 0) 773 if (argp[1] != NULL && *argp[1] != 0)
939 confp->ioaddr1 = stli_atol(argp[1]); 774 confp->ioaddr1 = simple_strtoul(argp[1], NULL, 0);
940 if (argp[2] != NULL && *argp[2] != 0) 775 if (argp[2] != NULL && *argp[2] != 0)
941 confp->memaddr = stli_atol(argp[2]); 776 confp->memaddr = simple_strtoul(argp[2], NULL, 0);
942 return(1); 777 return(1);
943} 778}
944 779
@@ -946,10 +781,10 @@ static int stli_parsebrd(stlconf_t *confp, char **argp)
946 781
947static int stli_open(struct tty_struct *tty, struct file *filp) 782static int stli_open(struct tty_struct *tty, struct file *filp)
948{ 783{
949 stlibrd_t *brdp; 784 struct stlibrd *brdp;
950 stliport_t *portp; 785 struct stliport *portp;
951 unsigned int minordev; 786 unsigned int minordev, brdnr, portnr;
952 int brdnr, portnr, rc; 787 int rc;
953 788
954 minordev = tty->index; 789 minordev = tty->index;
955 brdnr = MINOR2BRD(minordev); 790 brdnr = MINOR2BRD(minordev);
@@ -961,7 +796,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
961 if ((brdp->state & BST_STARTED) == 0) 796 if ((brdp->state & BST_STARTED) == 0)
962 return -ENODEV; 797 return -ENODEV;
963 portnr = MINOR2PORT(minordev); 798 portnr = MINOR2PORT(minordev);
964 if ((portnr < 0) || (portnr > brdp->nrports)) 799 if (portnr > brdp->nrports)
965 return -ENODEV; 800 return -ENODEV;
966 801
967 portp = brdp->ports[portnr]; 802 portp = brdp->ports[portnr];
@@ -1041,8 +876,8 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
1041 876
1042static void stli_close(struct tty_struct *tty, struct file *filp) 877static void stli_close(struct tty_struct *tty, struct file *filp)
1043{ 878{
1044 stlibrd_t *brdp; 879 struct stlibrd *brdp;
1045 stliport_t *portp; 880 struct stliport *portp;
1046 unsigned long flags; 881 unsigned long flags;
1047 882
1048 portp = tty->driver_data; 883 portp = tty->driver_data;
@@ -1119,7 +954,7 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
1119 * this still all happens pretty quickly. 954 * this still all happens pretty quickly.
1120 */ 955 */
1121 956
1122static int stli_initopen(stlibrd_t *brdp, stliport_t *portp) 957static int stli_initopen(struct stlibrd *brdp, struct stliport *portp)
1123{ 958{
1124 struct tty_struct *tty; 959 struct tty_struct *tty;
1125 asynotify_t nt; 960 asynotify_t nt;
@@ -1167,7 +1002,7 @@ static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
1167 * to overlap. 1002 * to overlap.
1168 */ 1003 */
1169 1004
1170static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait) 1005static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait)
1171{ 1006{
1172 cdkhdr_t __iomem *hdrp; 1007 cdkhdr_t __iomem *hdrp;
1173 cdkctrl_t __iomem *cp; 1008 cdkctrl_t __iomem *cp;
@@ -1238,7 +1073,7 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
1238 * wait is true then must have user context (to sleep). 1073 * wait is true then must have user context (to sleep).
1239 */ 1074 */
1240 1075
1241static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait) 1076static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait)
1242{ 1077{
1243 cdkhdr_t __iomem *hdrp; 1078 cdkhdr_t __iomem *hdrp;
1244 cdkctrl_t __iomem *cp; 1079 cdkctrl_t __iomem *cp;
@@ -1302,7 +1137,7 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
1302 * to complete (as opposed to initiating the command then returning). 1137 * to complete (as opposed to initiating the command then returning).
1303 */ 1138 */
1304 1139
1305static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback) 1140static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
1306{ 1141{
1307 wait_event_interruptible(portp->raw_wait, 1142 wait_event_interruptible(portp->raw_wait,
1308 !test_bit(ST_CMDING, &portp->state)); 1143 !test_bit(ST_CMDING, &portp->state));
@@ -1328,16 +1163,16 @@ static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, v
1328 * waiting for the command to complete - so must have user context. 1163 * waiting for the command to complete - so must have user context.
1329 */ 1164 */
1330 1165
1331static int stli_setport(stliport_t *portp) 1166static int stli_setport(struct stliport *portp)
1332{ 1167{
1333 stlibrd_t *brdp; 1168 struct stlibrd *brdp;
1334 asyport_t aport; 1169 asyport_t aport;
1335 1170
1336 if (portp == NULL) 1171 if (portp == NULL)
1337 return -ENODEV; 1172 return -ENODEV;
1338 if (portp->tty == NULL) 1173 if (portp->tty == NULL)
1339 return -ENODEV; 1174 return -ENODEV;
1340 if (portp->brdnr < 0 && portp->brdnr >= stli_nrbrds) 1175 if (portp->brdnr >= stli_nrbrds)
1341 return -ENODEV; 1176 return -ENODEV;
1342 brdp = stli_brds[portp->brdnr]; 1177 brdp = stli_brds[portp->brdnr];
1343 if (brdp == NULL) 1178 if (brdp == NULL)
@@ -1354,7 +1189,7 @@ static int stli_setport(stliport_t *portp)
1354 * maybe because if we are clocal then we don't need to wait... 1189 * maybe because if we are clocal then we don't need to wait...
1355 */ 1190 */
1356 1191
1357static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp) 1192static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct file *filp)
1358{ 1193{
1359 unsigned long flags; 1194 unsigned long flags;
1360 int rc, doclocal; 1195 int rc, doclocal;
@@ -1419,8 +1254,8 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
1419 unsigned char __iomem *bits; 1254 unsigned char __iomem *bits;
1420 unsigned char __iomem *shbuf; 1255 unsigned char __iomem *shbuf;
1421 unsigned char *chbuf; 1256 unsigned char *chbuf;
1422 stliport_t *portp; 1257 struct stliport *portp;
1423 stlibrd_t *brdp; 1258 struct stlibrd *brdp;
1424 unsigned int len, stlen, head, tail, size; 1259 unsigned int len, stlen, head, tail, size;
1425 unsigned long flags; 1260 unsigned long flags;
1426 1261
@@ -1429,7 +1264,7 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
1429 portp = tty->driver_data; 1264 portp = tty->driver_data;
1430 if (portp == NULL) 1265 if (portp == NULL)
1431 return 0; 1266 return 0;
1432 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1267 if (portp->brdnr >= stli_nrbrds)
1433 return 0; 1268 return 0;
1434 brdp = stli_brds[portp->brdnr]; 1269 brdp = stli_brds[portp->brdnr];
1435 if (brdp == NULL) 1270 if (brdp == NULL)
@@ -1455,12 +1290,12 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
1455 stlen = len; 1290 stlen = len;
1456 } 1291 }
1457 1292
1458 len = MIN(len, count); 1293 len = min(len, (unsigned int)count);
1459 count = 0; 1294 count = 0;
1460 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset); 1295 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
1461 1296
1462 while (len > 0) { 1297 while (len > 0) {
1463 stlen = MIN(len, stlen); 1298 stlen = min(len, stlen);
1464 memcpy_toio(shbuf + head, chbuf, stlen); 1299 memcpy_toio(shbuf + head, chbuf, stlen);
1465 chbuf += stlen; 1300 chbuf += stlen;
1466 len -= stlen; 1301 len -= stlen;
@@ -1526,8 +1361,8 @@ static void stli_flushchars(struct tty_struct *tty)
1526 unsigned char __iomem *bits; 1361 unsigned char __iomem *bits;
1527 cdkasy_t __iomem *ap; 1362 cdkasy_t __iomem *ap;
1528 struct tty_struct *cooktty; 1363 struct tty_struct *cooktty;
1529 stliport_t *portp; 1364 struct stliport *portp;
1530 stlibrd_t *brdp; 1365 struct stlibrd *brdp;
1531 unsigned int len, stlen, head, tail, size, count, cooksize; 1366 unsigned int len, stlen, head, tail, size, count, cooksize;
1532 unsigned char *buf; 1367 unsigned char *buf;
1533 unsigned char __iomem *shbuf; 1368 unsigned char __iomem *shbuf;
@@ -1551,7 +1386,7 @@ static void stli_flushchars(struct tty_struct *tty)
1551 portp = tty->driver_data; 1386 portp = tty->driver_data;
1552 if (portp == NULL) 1387 if (portp == NULL)
1553 return; 1388 return;
1554 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1389 if (portp->brdnr >= stli_nrbrds)
1555 return; 1390 return;
1556 brdp = stli_brds[portp->brdnr]; 1391 brdp = stli_brds[portp->brdnr];
1557 if (brdp == NULL) 1392 if (brdp == NULL)
@@ -1574,13 +1409,13 @@ static void stli_flushchars(struct tty_struct *tty)
1574 stlen = len; 1409 stlen = len;
1575 } 1410 }
1576 1411
1577 len = MIN(len, cooksize); 1412 len = min(len, cooksize);
1578 count = 0; 1413 count = 0;
1579 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset); 1414 shbuf = EBRDGETMEMPTR(brdp, portp->txoffset);
1580 buf = stli_txcookbuf; 1415 buf = stli_txcookbuf;
1581 1416
1582 while (len > 0) { 1417 while (len > 0) {
1583 stlen = MIN(len, stlen); 1418 stlen = min(len, stlen);
1584 memcpy_toio(shbuf + head, buf, stlen); 1419 memcpy_toio(shbuf + head, buf, stlen);
1585 buf += stlen; 1420 buf += stlen;
1586 len -= stlen; 1421 len -= stlen;
@@ -1614,8 +1449,8 @@ static void stli_flushchars(struct tty_struct *tty)
1614static int stli_writeroom(struct tty_struct *tty) 1449static int stli_writeroom(struct tty_struct *tty)
1615{ 1450{
1616 cdkasyrq_t __iomem *rp; 1451 cdkasyrq_t __iomem *rp;
1617 stliport_t *portp; 1452 struct stliport *portp;
1618 stlibrd_t *brdp; 1453 struct stlibrd *brdp;
1619 unsigned int head, tail, len; 1454 unsigned int head, tail, len;
1620 unsigned long flags; 1455 unsigned long flags;
1621 1456
@@ -1629,7 +1464,7 @@ static int stli_writeroom(struct tty_struct *tty)
1629 portp = tty->driver_data; 1464 portp = tty->driver_data;
1630 if (portp == NULL) 1465 if (portp == NULL)
1631 return 0; 1466 return 0;
1632 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1467 if (portp->brdnr >= stli_nrbrds)
1633 return 0; 1468 return 0;
1634 brdp = stli_brds[portp->brdnr]; 1469 brdp = stli_brds[portp->brdnr];
1635 if (brdp == NULL) 1470 if (brdp == NULL)
@@ -1667,8 +1502,8 @@ static int stli_writeroom(struct tty_struct *tty)
1667static int stli_charsinbuffer(struct tty_struct *tty) 1502static int stli_charsinbuffer(struct tty_struct *tty)
1668{ 1503{
1669 cdkasyrq_t __iomem *rp; 1504 cdkasyrq_t __iomem *rp;
1670 stliport_t *portp; 1505 struct stliport *portp;
1671 stlibrd_t *brdp; 1506 struct stlibrd *brdp;
1672 unsigned int head, tail, len; 1507 unsigned int head, tail, len;
1673 unsigned long flags; 1508 unsigned long flags;
1674 1509
@@ -1677,7 +1512,7 @@ static int stli_charsinbuffer(struct tty_struct *tty)
1677 portp = tty->driver_data; 1512 portp = tty->driver_data;
1678 if (portp == NULL) 1513 if (portp == NULL)
1679 return 0; 1514 return 0;
1680 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1515 if (portp->brdnr >= stli_nrbrds)
1681 return 0; 1516 return 0;
1682 brdp = stli_brds[portp->brdnr]; 1517 brdp = stli_brds[portp->brdnr];
1683 if (brdp == NULL) 1518 if (brdp == NULL)
@@ -1705,10 +1540,10 @@ static int stli_charsinbuffer(struct tty_struct *tty)
1705 * Generate the serial struct info. 1540 * Generate the serial struct info.
1706 */ 1541 */
1707 1542
1708static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp) 1543static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp)
1709{ 1544{
1710 struct serial_struct sio; 1545 struct serial_struct sio;
1711 stlibrd_t *brdp; 1546 struct stlibrd *brdp;
1712 1547
1713 memset(&sio, 0, sizeof(struct serial_struct)); 1548 memset(&sio, 0, sizeof(struct serial_struct));
1714 sio.type = PORT_UNKNOWN; 1549 sio.type = PORT_UNKNOWN;
@@ -1738,7 +1573,7 @@ static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
1738 * just quietly ignore any requests to change irq, etc. 1573 * just quietly ignore any requests to change irq, etc.
1739 */ 1574 */
1740 1575
1741static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp) 1576static int stli_setserial(struct stliport *portp, struct serial_struct __user *sp)
1742{ 1577{
1743 struct serial_struct sio; 1578 struct serial_struct sio;
1744 int rc; 1579 int rc;
@@ -1769,13 +1604,13 @@ static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
1769 1604
1770static int stli_tiocmget(struct tty_struct *tty, struct file *file) 1605static int stli_tiocmget(struct tty_struct *tty, struct file *file)
1771{ 1606{
1772 stliport_t *portp = tty->driver_data; 1607 struct stliport *portp = tty->driver_data;
1773 stlibrd_t *brdp; 1608 struct stlibrd *brdp;
1774 int rc; 1609 int rc;
1775 1610
1776 if (portp == NULL) 1611 if (portp == NULL)
1777 return -ENODEV; 1612 return -ENODEV;
1778 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds) 1613 if (portp->brdnr >= stli_nrbrds)
1779 return 0; 1614 return 0;
1780 brdp = stli_brds[portp->brdnr]; 1615 brdp = stli_brds[portp->brdnr];
1781 if (brdp == NULL) 1616 if (brdp == NULL)
@@ -1793,13 +1628,13 @@ static int stli_tiocmget(struct tty_struct *tty, struct file *file)
1793static int stli_tiocmset(struct tty_struct *tty, struct file *file, 1628static int stli_tiocmset(struct tty_struct *tty, struct file *file,
1794 unsigned int set, unsigned int clear) 1629 unsigned int set, unsigned int clear)
1795{ 1630{
1796 stliport_t *portp = tty->driver_data; 1631 struct stliport *portp = tty->driver_data;
1797 stlibrd_t *brdp; 1632 struct stlibrd *brdp;
1798 int rts = -1, dtr = -1; 1633 int rts = -1, dtr = -1;
1799 1634
1800 if (portp == NULL) 1635 if (portp == NULL)
1801 return -ENODEV; 1636 return -ENODEV;
1802 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds) 1637 if (portp->brdnr >= stli_nrbrds)
1803 return 0; 1638 return 0;
1804 brdp = stli_brds[portp->brdnr]; 1639 brdp = stli_brds[portp->brdnr];
1805 if (brdp == NULL) 1640 if (brdp == NULL)
@@ -1824,8 +1659,8 @@ static int stli_tiocmset(struct tty_struct *tty, struct file *file,
1824 1659
1825static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) 1660static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1826{ 1661{
1827 stliport_t *portp; 1662 struct stliport *portp;
1828 stlibrd_t *brdp; 1663 struct stlibrd *brdp;
1829 unsigned int ival; 1664 unsigned int ival;
1830 int rc; 1665 int rc;
1831 void __user *argp = (void __user *)arg; 1666 void __user *argp = (void __user *)arg;
@@ -1833,7 +1668,7 @@ static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm
1833 portp = tty->driver_data; 1668 portp = tty->driver_data;
1834 if (portp == NULL) 1669 if (portp == NULL)
1835 return -ENODEV; 1670 return -ENODEV;
1836 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds) 1671 if (portp->brdnr >= stli_nrbrds)
1837 return 0; 1672 return 0;
1838 brdp = stli_brds[portp->brdnr]; 1673 brdp = stli_brds[portp->brdnr];
1839 if (brdp == NULL) 1674 if (brdp == NULL)
@@ -1899,11 +1734,11 @@ static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm
1899 * Looks like it is true for the current ttys implementation..!! 1734 * Looks like it is true for the current ttys implementation..!!
1900 */ 1735 */
1901 1736
1902static void stli_settermios(struct tty_struct *tty, struct termios *old) 1737static void stli_settermios(struct tty_struct *tty, struct ktermios *old)
1903{ 1738{
1904 stliport_t *portp; 1739 struct stliport *portp;
1905 stlibrd_t *brdp; 1740 struct stlibrd *brdp;
1906 struct termios *tiosp; 1741 struct ktermios *tiosp;
1907 asyport_t aport; 1742 asyport_t aport;
1908 1743
1909 if (tty == NULL) 1744 if (tty == NULL)
@@ -1911,7 +1746,7 @@ static void stli_settermios(struct tty_struct *tty, struct termios *old)
1911 portp = tty->driver_data; 1746 portp = tty->driver_data;
1912 if (portp == NULL) 1747 if (portp == NULL)
1913 return; 1748 return;
1914 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds) 1749 if (portp->brdnr >= stli_nrbrds)
1915 return; 1750 return;
1916 brdp = stli_brds[portp->brdnr]; 1751 brdp = stli_brds[portp->brdnr];
1917 if (brdp == NULL) 1752 if (brdp == NULL)
@@ -1947,7 +1782,7 @@ static void stli_settermios(struct tty_struct *tty, struct termios *old)
1947 1782
1948static void stli_throttle(struct tty_struct *tty) 1783static void stli_throttle(struct tty_struct *tty)
1949{ 1784{
1950 stliport_t *portp = tty->driver_data; 1785 struct stliport *portp = tty->driver_data;
1951 if (portp == NULL) 1786 if (portp == NULL)
1952 return; 1787 return;
1953 set_bit(ST_RXSTOP, &portp->state); 1788 set_bit(ST_RXSTOP, &portp->state);
@@ -1963,7 +1798,7 @@ static void stli_throttle(struct tty_struct *tty)
1963 1798
1964static void stli_unthrottle(struct tty_struct *tty) 1799static void stli_unthrottle(struct tty_struct *tty)
1965{ 1800{
1966 stliport_t *portp = tty->driver_data; 1801 struct stliport *portp = tty->driver_data;
1967 if (portp == NULL) 1802 if (portp == NULL)
1968 return; 1803 return;
1969 clear_bit(ST_RXSTOP, &portp->state); 1804 clear_bit(ST_RXSTOP, &portp->state);
@@ -2000,9 +1835,9 @@ static void stli_start(struct tty_struct *tty)
2000 * aren't that time critical). 1835 * aren't that time critical).
2001 */ 1836 */
2002 1837
2003static void stli_dohangup(void *arg) 1838static void stli_dohangup(struct work_struct *ugly_api)
2004{ 1839{
2005 stliport_t *portp = (stliport_t *) arg; 1840 struct stliport *portp = container_of(ugly_api, struct stliport, tqhangup);
2006 if (portp->tty != NULL) { 1841 if (portp->tty != NULL) {
2007 tty_hangup(portp->tty); 1842 tty_hangup(portp->tty);
2008 } 1843 }
@@ -2019,14 +1854,14 @@ static void stli_dohangup(void *arg)
2019 1854
2020static void stli_hangup(struct tty_struct *tty) 1855static void stli_hangup(struct tty_struct *tty)
2021{ 1856{
2022 stliport_t *portp; 1857 struct stliport *portp;
2023 stlibrd_t *brdp; 1858 struct stlibrd *brdp;
2024 unsigned long flags; 1859 unsigned long flags;
2025 1860
2026 portp = tty->driver_data; 1861 portp = tty->driver_data;
2027 if (portp == NULL) 1862 if (portp == NULL)
2028 return; 1863 return;
2029 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds) 1864 if (portp->brdnr >= stli_nrbrds)
2030 return; 1865 return;
2031 brdp = stli_brds[portp->brdnr]; 1866 brdp = stli_brds[portp->brdnr];
2032 if (brdp == NULL) 1867 if (brdp == NULL)
@@ -2072,14 +1907,14 @@ static void stli_hangup(struct tty_struct *tty)
2072 1907
2073static void stli_flushbuffer(struct tty_struct *tty) 1908static void stli_flushbuffer(struct tty_struct *tty)
2074{ 1909{
2075 stliport_t *portp; 1910 struct stliport *portp;
2076 stlibrd_t *brdp; 1911 struct stlibrd *brdp;
2077 unsigned long ftype, flags; 1912 unsigned long ftype, flags;
2078 1913
2079 portp = tty->driver_data; 1914 portp = tty->driver_data;
2080 if (portp == NULL) 1915 if (portp == NULL)
2081 return; 1916 return;
2082 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds) 1917 if (portp->brdnr >= stli_nrbrds)
2083 return; 1918 return;
2084 brdp = stli_brds[portp->brdnr]; 1919 brdp = stli_brds[portp->brdnr];
2085 if (brdp == NULL) 1920 if (brdp == NULL)
@@ -2109,14 +1944,14 @@ static void stli_flushbuffer(struct tty_struct *tty)
2109 1944
2110static void stli_breakctl(struct tty_struct *tty, int state) 1945static void stli_breakctl(struct tty_struct *tty, int state)
2111{ 1946{
2112 stlibrd_t *brdp; 1947 struct stlibrd *brdp;
2113 stliport_t *portp; 1948 struct stliport *portp;
2114 long arg; 1949 long arg;
2115 1950
2116 portp = tty->driver_data; 1951 portp = tty->driver_data;
2117 if (portp == NULL) 1952 if (portp == NULL)
2118 return; 1953 return;
2119 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds) 1954 if (portp->brdnr >= stli_nrbrds)
2120 return; 1955 return;
2121 brdp = stli_brds[portp->brdnr]; 1956 brdp = stli_brds[portp->brdnr];
2122 if (brdp == NULL) 1957 if (brdp == NULL)
@@ -2130,7 +1965,7 @@ static void stli_breakctl(struct tty_struct *tty, int state)
2130 1965
2131static void stli_waituntilsent(struct tty_struct *tty, int timeout) 1966static void stli_waituntilsent(struct tty_struct *tty, int timeout)
2132{ 1967{
2133 stliport_t *portp; 1968 struct stliport *portp;
2134 unsigned long tend; 1969 unsigned long tend;
2135 1970
2136 if (tty == NULL) 1971 if (tty == NULL)
@@ -2156,14 +1991,14 @@ static void stli_waituntilsent(struct tty_struct *tty, int timeout)
2156 1991
2157static void stli_sendxchar(struct tty_struct *tty, char ch) 1992static void stli_sendxchar(struct tty_struct *tty, char ch)
2158{ 1993{
2159 stlibrd_t *brdp; 1994 struct stlibrd *brdp;
2160 stliport_t *portp; 1995 struct stliport *portp;
2161 asyctrl_t actrl; 1996 asyctrl_t actrl;
2162 1997
2163 portp = tty->driver_data; 1998 portp = tty->driver_data;
2164 if (portp == NULL) 1999 if (portp == NULL)
2165 return; 2000 return;
2166 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds) 2001 if (portp->brdnr >= stli_nrbrds)
2167 return; 2002 return;
2168 brdp = stli_brds[portp->brdnr]; 2003 brdp = stli_brds[portp->brdnr];
2169 if (brdp == NULL) 2004 if (brdp == NULL)
@@ -2191,7 +2026,7 @@ static void stli_sendxchar(struct tty_struct *tty, char ch)
2191 * short then padded with spaces). 2026 * short then padded with spaces).
2192 */ 2027 */
2193 2028
2194static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos) 2029static int stli_portinfo(struct stlibrd *brdp, struct stliport *portp, int portnr, char *pos)
2195{ 2030{
2196 char *sp, *uart; 2031 char *sp, *uart;
2197 int rc, cnt; 2032 int rc, cnt;
@@ -2254,9 +2089,9 @@ static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *p
2254 2089
2255static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data) 2090static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
2256{ 2091{
2257 stlibrd_t *brdp; 2092 struct stlibrd *brdp;
2258 stliport_t *portp; 2093 struct stliport *portp;
2259 int brdnr, portnr, totalport; 2094 unsigned int brdnr, portnr, totalport;
2260 int curoff, maxoff; 2095 int curoff, maxoff;
2261 char *pos; 2096 char *pos;
2262 2097
@@ -2326,7 +2161,7 @@ stli_readdone:
2326 * entry point) 2161 * entry point)
2327 */ 2162 */
2328 2163
2329static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback) 2164static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
2330{ 2165{
2331 cdkhdr_t __iomem *hdrp; 2166 cdkhdr_t __iomem *hdrp;
2332 cdkctrl_t __iomem *cp; 2167 cdkctrl_t __iomem *cp;
@@ -2362,7 +2197,7 @@ static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd
2362 spin_unlock_irqrestore(&brd_lock, flags); 2197 spin_unlock_irqrestore(&brd_lock, flags);
2363} 2198}
2364 2199
2365static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback) 2200static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
2366{ 2201{
2367 unsigned long flags; 2202 unsigned long flags;
2368 2203
@@ -2381,7 +2216,7 @@ static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd,
2381 * more chars to unload. 2216 * more chars to unload.
2382 */ 2217 */
2383 2218
2384static void stli_read(stlibrd_t *brdp, stliport_t *portp) 2219static void stli_read(struct stlibrd *brdp, struct stliport *portp)
2385{ 2220{
2386 cdkasyrq_t __iomem *rp; 2221 cdkasyrq_t __iomem *rp;
2387 char __iomem *shbuf; 2222 char __iomem *shbuf;
@@ -2416,7 +2251,7 @@ static void stli_read(stlibrd_t *brdp, stliport_t *portp)
2416 while (len > 0) { 2251 while (len > 0) {
2417 unsigned char *cptr; 2252 unsigned char *cptr;
2418 2253
2419 stlen = MIN(len, stlen); 2254 stlen = min(len, stlen);
2420 tty_prepare_flip_string(tty, &cptr, stlen); 2255 tty_prepare_flip_string(tty, &cptr, stlen);
2421 memcpy_fromio(cptr, shbuf + tail, stlen); 2256 memcpy_fromio(cptr, shbuf + tail, stlen);
2422 len -= stlen; 2257 len -= stlen;
@@ -2443,7 +2278,7 @@ static void stli_read(stlibrd_t *brdp, stliport_t *portp)
2443 * difficult to deal with them here. 2278 * difficult to deal with them here.
2444 */ 2279 */
2445 2280
2446static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp) 2281static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp)
2447{ 2282{
2448 int cmd; 2283 int cmd;
2449 2284
@@ -2491,7 +2326,7 @@ static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp)
2491 * then port is still busy, otherwise no longer busy. 2326 * then port is still busy, otherwise no longer busy.
2492 */ 2327 */
2493 2328
2494static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp) 2329static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp)
2495{ 2330{
2496 cdkasy_t __iomem *ap; 2331 cdkasy_t __iomem *ap;
2497 cdkctrl_t __iomem *cp; 2332 cdkctrl_t __iomem *cp;
@@ -2638,9 +2473,9 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2638 * at the cdk header structure. 2473 * at the cdk header structure.
2639 */ 2474 */
2640 2475
2641static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp) 2476static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp)
2642{ 2477{
2643 stliport_t *portp; 2478 struct stliport *portp;
2644 unsigned char hostbits[(STL_MAXCHANS / 8) + 1]; 2479 unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
2645 unsigned char slavebits[(STL_MAXCHANS / 8) + 1]; 2480 unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
2646 unsigned char __iomem *slavep; 2481 unsigned char __iomem *slavep;
@@ -2707,11 +2542,10 @@ static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp)
2707static void stli_poll(unsigned long arg) 2542static void stli_poll(unsigned long arg)
2708{ 2543{
2709 cdkhdr_t __iomem *hdrp; 2544 cdkhdr_t __iomem *hdrp;
2710 stlibrd_t *brdp; 2545 struct stlibrd *brdp;
2711 int brdnr; 2546 unsigned int brdnr;
2712 2547
2713 stli_timerlist.expires = STLI_TIMEOUT; 2548 mod_timer(&stli_timerlist, STLI_TIMEOUT);
2714 add_timer(&stli_timerlist);
2715 2549
2716/* 2550/*
2717 * Check each board and do any servicing required. 2551 * Check each board and do any servicing required.
@@ -2740,22 +2574,14 @@ static void stli_poll(unsigned long arg)
2740 * the slave. 2574 * the slave.
2741 */ 2575 */
2742 2576
2743static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp) 2577static void stli_mkasyport(struct stliport *portp, asyport_t *pp, struct ktermios *tiosp)
2744{ 2578{
2745 memset(pp, 0, sizeof(asyport_t)); 2579 memset(pp, 0, sizeof(asyport_t));
2746 2580
2747/* 2581/*
2748 * Start of by setting the baud, char size, parity and stop bit info. 2582 * Start of by setting the baud, char size, parity and stop bit info.
2749 */ 2583 */
2750 pp->baudout = tiosp->c_cflag & CBAUD; 2584 pp->baudout = tty_get_baud_rate(portp->tty);
2751 if (pp->baudout & CBAUDEX) {
2752 pp->baudout &= ~CBAUDEX;
2753 if ((pp->baudout < 1) || (pp->baudout > 4))
2754 tiosp->c_cflag &= ~CBAUDEX;
2755 else
2756 pp->baudout += 15;
2757 }
2758 pp->baudout = stli_baudrates[pp->baudout];
2759 if ((tiosp->c_cflag & CBAUD) == B38400) { 2585 if ((tiosp->c_cflag & CBAUD) == B38400) {
2760 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 2586 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2761 pp->baudout = 57600; 2587 pp->baudout = 57600;
@@ -2897,13 +2723,13 @@ static long stli_mktiocm(unsigned long sigvalue)
2897 * we need to do here is set up the appropriate per port data structures. 2723 * we need to do here is set up the appropriate per port data structures.
2898 */ 2724 */
2899 2725
2900static int stli_initports(stlibrd_t *brdp) 2726static int stli_initports(struct stlibrd *brdp)
2901{ 2727{
2902 stliport_t *portp; 2728 struct stliport *portp;
2903 int i, panelnr, panelport; 2729 unsigned int i, panelnr, panelport;
2904 2730
2905 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) { 2731 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
2906 portp = kzalloc(sizeof(stliport_t), GFP_KERNEL); 2732 portp = kzalloc(sizeof(struct stliport), GFP_KERNEL);
2907 if (!portp) { 2733 if (!portp) {
2908 printk("STALLION: failed to allocate port structure\n"); 2734 printk("STALLION: failed to allocate port structure\n");
2909 continue; 2735 continue;
@@ -2916,7 +2742,7 @@ static int stli_initports(stlibrd_t *brdp)
2916 portp->baud_base = STL_BAUDBASE; 2742 portp->baud_base = STL_BAUDBASE;
2917 portp->close_delay = STL_CLOSEDELAY; 2743 portp->close_delay = STL_CLOSEDELAY;
2918 portp->closing_wait = 30 * HZ; 2744 portp->closing_wait = 30 * HZ;
2919 INIT_WORK(&portp->tqhangup, stli_dohangup, portp); 2745 INIT_WORK(&portp->tqhangup, stli_dohangup);
2920 init_waitqueue_head(&portp->open_wait); 2746 init_waitqueue_head(&portp->open_wait);
2921 init_waitqueue_head(&portp->close_wait); 2747 init_waitqueue_head(&portp->close_wait);
2922 init_waitqueue_head(&portp->raw_wait); 2748 init_waitqueue_head(&portp->raw_wait);
@@ -2937,7 +2763,7 @@ static int stli_initports(stlibrd_t *brdp)
2937 * All the following routines are board specific hardware operations. 2763 * All the following routines are board specific hardware operations.
2938 */ 2764 */
2939 2765
2940static void stli_ecpinit(stlibrd_t *brdp) 2766static void stli_ecpinit(struct stlibrd *brdp)
2941{ 2767{
2942 unsigned long memconf; 2768 unsigned long memconf;
2943 2769
@@ -2952,23 +2778,23 @@ static void stli_ecpinit(stlibrd_t *brdp)
2952 2778
2953/*****************************************************************************/ 2779/*****************************************************************************/
2954 2780
2955static void stli_ecpenable(stlibrd_t *brdp) 2781static void stli_ecpenable(struct stlibrd *brdp)
2956{ 2782{
2957 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR)); 2783 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
2958} 2784}
2959 2785
2960/*****************************************************************************/ 2786/*****************************************************************************/
2961 2787
2962static void stli_ecpdisable(stlibrd_t *brdp) 2788static void stli_ecpdisable(struct stlibrd *brdp)
2963{ 2789{
2964 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR)); 2790 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2965} 2791}
2966 2792
2967/*****************************************************************************/ 2793/*****************************************************************************/
2968 2794
2969static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 2795static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
2970{ 2796{
2971 void *ptr; 2797 void __iomem *ptr;
2972 unsigned char val; 2798 unsigned char val;
2973 2799
2974 if (offset > brdp->memsize) { 2800 if (offset > brdp->memsize) {
@@ -2987,7 +2813,7 @@ static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
2987 2813
2988/*****************************************************************************/ 2814/*****************************************************************************/
2989 2815
2990static void stli_ecpreset(stlibrd_t *brdp) 2816static void stli_ecpreset(struct stlibrd *brdp)
2991{ 2817{
2992 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR)); 2818 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2993 udelay(10); 2819 udelay(10);
@@ -2997,7 +2823,7 @@ static void stli_ecpreset(stlibrd_t *brdp)
2997 2823
2998/*****************************************************************************/ 2824/*****************************************************************************/
2999 2825
3000static void stli_ecpintr(stlibrd_t *brdp) 2826static void stli_ecpintr(struct stlibrd *brdp)
3001{ 2827{
3002 outb(0x1, brdp->iobase); 2828 outb(0x1, brdp->iobase);
3003} 2829}
@@ -3008,7 +2834,7 @@ static void stli_ecpintr(stlibrd_t *brdp)
3008 * The following set of functions act on ECP EISA boards. 2834 * The following set of functions act on ECP EISA boards.
3009 */ 2835 */
3010 2836
3011static void stli_ecpeiinit(stlibrd_t *brdp) 2837static void stli_ecpeiinit(struct stlibrd *brdp)
3012{ 2838{
3013 unsigned long memconf; 2839 unsigned long memconf;
3014 2840
@@ -3026,23 +2852,23 @@ static void stli_ecpeiinit(stlibrd_t *brdp)
3026 2852
3027/*****************************************************************************/ 2853/*****************************************************************************/
3028 2854
3029static void stli_ecpeienable(stlibrd_t *brdp) 2855static void stli_ecpeienable(struct stlibrd *brdp)
3030{ 2856{
3031 outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR)); 2857 outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
3032} 2858}
3033 2859
3034/*****************************************************************************/ 2860/*****************************************************************************/
3035 2861
3036static void stli_ecpeidisable(stlibrd_t *brdp) 2862static void stli_ecpeidisable(struct stlibrd *brdp)
3037{ 2863{
3038 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR)); 2864 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3039} 2865}
3040 2866
3041/*****************************************************************************/ 2867/*****************************************************************************/
3042 2868
3043static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 2869static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3044{ 2870{
3045 void *ptr; 2871 void __iomem *ptr;
3046 unsigned char val; 2872 unsigned char val;
3047 2873
3048 if (offset > brdp->memsize) { 2874 if (offset > brdp->memsize) {
@@ -3064,7 +2890,7 @@ static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line
3064 2890
3065/*****************************************************************************/ 2891/*****************************************************************************/
3066 2892
3067static void stli_ecpeireset(stlibrd_t *brdp) 2893static void stli_ecpeireset(struct stlibrd *brdp)
3068{ 2894{
3069 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR)); 2895 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3070 udelay(10); 2896 udelay(10);
@@ -3078,23 +2904,23 @@ static void stli_ecpeireset(stlibrd_t *brdp)
3078 * The following set of functions act on ECP MCA boards. 2904 * The following set of functions act on ECP MCA boards.
3079 */ 2905 */
3080 2906
3081static void stli_ecpmcenable(stlibrd_t *brdp) 2907static void stli_ecpmcenable(struct stlibrd *brdp)
3082{ 2908{
3083 outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR)); 2909 outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
3084} 2910}
3085 2911
3086/*****************************************************************************/ 2912/*****************************************************************************/
3087 2913
3088static void stli_ecpmcdisable(stlibrd_t *brdp) 2914static void stli_ecpmcdisable(struct stlibrd *brdp)
3089{ 2915{
3090 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR)); 2916 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3091} 2917}
3092 2918
3093/*****************************************************************************/ 2919/*****************************************************************************/
3094 2920
3095static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 2921static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3096{ 2922{
3097 void *ptr; 2923 void __iomem *ptr;
3098 unsigned char val; 2924 unsigned char val;
3099 2925
3100 if (offset > brdp->memsize) { 2926 if (offset > brdp->memsize) {
@@ -3113,7 +2939,7 @@ static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line
3113 2939
3114/*****************************************************************************/ 2940/*****************************************************************************/
3115 2941
3116static void stli_ecpmcreset(stlibrd_t *brdp) 2942static void stli_ecpmcreset(struct stlibrd *brdp)
3117{ 2943{
3118 outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR)); 2944 outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
3119 udelay(10); 2945 udelay(10);
@@ -3127,7 +2953,7 @@ static void stli_ecpmcreset(stlibrd_t *brdp)
3127 * The following set of functions act on ECP PCI boards. 2953 * The following set of functions act on ECP PCI boards.
3128 */ 2954 */
3129 2955
3130static void stli_ecppciinit(stlibrd_t *brdp) 2956static void stli_ecppciinit(struct stlibrd *brdp)
3131{ 2957{
3132 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR)); 2958 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3133 udelay(10); 2959 udelay(10);
@@ -3137,9 +2963,9 @@ static void stli_ecppciinit(stlibrd_t *brdp)
3137 2963
3138/*****************************************************************************/ 2964/*****************************************************************************/
3139 2965
3140static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 2966static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3141{ 2967{
3142 void *ptr; 2968 void __iomem *ptr;
3143 unsigned char val; 2969 unsigned char val;
3144 2970
3145 if (offset > brdp->memsize) { 2971 if (offset > brdp->memsize) {
@@ -3158,7 +2984,7 @@ static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int lin
3158 2984
3159/*****************************************************************************/ 2985/*****************************************************************************/
3160 2986
3161static void stli_ecppcireset(stlibrd_t *brdp) 2987static void stli_ecppcireset(struct stlibrd *brdp)
3162{ 2988{
3163 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR)); 2989 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3164 udelay(10); 2990 udelay(10);
@@ -3172,7 +2998,7 @@ static void stli_ecppcireset(stlibrd_t *brdp)
3172 * The following routines act on ONboards. 2998 * The following routines act on ONboards.
3173 */ 2999 */
3174 3000
3175static void stli_onbinit(stlibrd_t *brdp) 3001static void stli_onbinit(struct stlibrd *brdp)
3176{ 3002{
3177 unsigned long memconf; 3003 unsigned long memconf;
3178 3004
@@ -3189,23 +3015,23 @@ static void stli_onbinit(stlibrd_t *brdp)
3189 3015
3190/*****************************************************************************/ 3016/*****************************************************************************/
3191 3017
3192static void stli_onbenable(stlibrd_t *brdp) 3018static void stli_onbenable(struct stlibrd *brdp)
3193{ 3019{
3194 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR)); 3020 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
3195} 3021}
3196 3022
3197/*****************************************************************************/ 3023/*****************************************************************************/
3198 3024
3199static void stli_onbdisable(stlibrd_t *brdp) 3025static void stli_onbdisable(struct stlibrd *brdp)
3200{ 3026{
3201 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR)); 3027 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
3202} 3028}
3203 3029
3204/*****************************************************************************/ 3030/*****************************************************************************/
3205 3031
3206static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 3032static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3207{ 3033{
3208 void *ptr; 3034 void __iomem *ptr;
3209 3035
3210 if (offset > brdp->memsize) { 3036 if (offset > brdp->memsize) {
3211 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 3037 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
@@ -3220,7 +3046,7 @@ static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3220 3046
3221/*****************************************************************************/ 3047/*****************************************************************************/
3222 3048
3223static void stli_onbreset(stlibrd_t *brdp) 3049static void stli_onbreset(struct stlibrd *brdp)
3224{ 3050{
3225 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR)); 3051 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3226 udelay(10); 3052 udelay(10);
@@ -3234,7 +3060,7 @@ static void stli_onbreset(stlibrd_t *brdp)
3234 * The following routines act on ONboard EISA. 3060 * The following routines act on ONboard EISA.
3235 */ 3061 */
3236 3062
3237static void stli_onbeinit(stlibrd_t *brdp) 3063static void stli_onbeinit(struct stlibrd *brdp)
3238{ 3064{
3239 unsigned long memconf; 3065 unsigned long memconf;
3240 3066
@@ -3254,23 +3080,23 @@ static void stli_onbeinit(stlibrd_t *brdp)
3254 3080
3255/*****************************************************************************/ 3081/*****************************************************************************/
3256 3082
3257static void stli_onbeenable(stlibrd_t *brdp) 3083static void stli_onbeenable(struct stlibrd *brdp)
3258{ 3084{
3259 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR)); 3085 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3260} 3086}
3261 3087
3262/*****************************************************************************/ 3088/*****************************************************************************/
3263 3089
3264static void stli_onbedisable(stlibrd_t *brdp) 3090static void stli_onbedisable(struct stlibrd *brdp)
3265{ 3091{
3266 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR)); 3092 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3267} 3093}
3268 3094
3269/*****************************************************************************/ 3095/*****************************************************************************/
3270 3096
3271static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 3097static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3272{ 3098{
3273 void *ptr; 3099 void __iomem *ptr;
3274 unsigned char val; 3100 unsigned char val;
3275 3101
3276 if (offset > brdp->memsize) { 3102 if (offset > brdp->memsize) {
@@ -3292,7 +3118,7 @@ static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3292 3118
3293/*****************************************************************************/ 3119/*****************************************************************************/
3294 3120
3295static void stli_onbereset(stlibrd_t *brdp) 3121static void stli_onbereset(struct stlibrd *brdp)
3296{ 3122{
3297 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR)); 3123 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3298 udelay(10); 3124 udelay(10);
@@ -3306,7 +3132,7 @@ static void stli_onbereset(stlibrd_t *brdp)
3306 * The following routines act on Brumby boards. 3132 * The following routines act on Brumby boards.
3307 */ 3133 */
3308 3134
3309static void stli_bbyinit(stlibrd_t *brdp) 3135static void stli_bbyinit(struct stlibrd *brdp)
3310{ 3136{
3311 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR)); 3137 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3312 udelay(10); 3138 udelay(10);
@@ -3318,9 +3144,9 @@ static void stli_bbyinit(stlibrd_t *brdp)
3318 3144
3319/*****************************************************************************/ 3145/*****************************************************************************/
3320 3146
3321static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 3147static void __iomem *stli_bbygetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3322{ 3148{
3323 void *ptr; 3149 void __iomem *ptr;
3324 unsigned char val; 3150 unsigned char val;
3325 3151
3326 BUG_ON(offset > brdp->memsize); 3152 BUG_ON(offset > brdp->memsize);
@@ -3333,7 +3159,7 @@ static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3333 3159
3334/*****************************************************************************/ 3160/*****************************************************************************/
3335 3161
3336static void stli_bbyreset(stlibrd_t *brdp) 3162static void stli_bbyreset(struct stlibrd *brdp)
3337{ 3163{
3338 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR)); 3164 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3339 udelay(10); 3165 udelay(10);
@@ -3347,7 +3173,7 @@ static void stli_bbyreset(stlibrd_t *brdp)
3347 * The following routines act on original old Stallion boards. 3173 * The following routines act on original old Stallion boards.
3348 */ 3174 */
3349 3175
3350static void stli_stalinit(stlibrd_t *brdp) 3176static void stli_stalinit(struct stlibrd *brdp)
3351{ 3177{
3352 outb(0x1, brdp->iobase); 3178 outb(0x1, brdp->iobase);
3353 mdelay(1000); 3179 mdelay(1000);
@@ -3355,7 +3181,7 @@ static void stli_stalinit(stlibrd_t *brdp)
3355 3181
3356/*****************************************************************************/ 3182/*****************************************************************************/
3357 3183
3358static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 3184static void __iomem *stli_stalgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3359{ 3185{
3360 BUG_ON(offset > brdp->memsize); 3186 BUG_ON(offset > brdp->memsize);
3361 return brdp->membase + (offset % STAL_PAGESIZE); 3187 return brdp->membase + (offset % STAL_PAGESIZE);
@@ -3363,7 +3189,7 @@ static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3363 3189
3364/*****************************************************************************/ 3190/*****************************************************************************/
3365 3191
3366static void stli_stalreset(stlibrd_t *brdp) 3192static void stli_stalreset(struct stlibrd *brdp)
3367{ 3193{
3368 u32 __iomem *vecp; 3194 u32 __iomem *vecp;
3369 3195
@@ -3380,21 +3206,22 @@ static void stli_stalreset(stlibrd_t *brdp)
3380 * board types. 3206 * board types.
3381 */ 3207 */
3382 3208
3383static int stli_initecp(stlibrd_t *brdp) 3209static int stli_initecp(struct stlibrd *brdp)
3384{ 3210{
3385 cdkecpsig_t sig; 3211 cdkecpsig_t sig;
3386 cdkecpsig_t __iomem *sigsp; 3212 cdkecpsig_t __iomem *sigsp;
3387 unsigned int status, nxtid; 3213 unsigned int status, nxtid;
3388 char *name; 3214 char *name;
3389 int panelnr, nrports; 3215 int retval, panelnr, nrports;
3390 3216
3391 if (!request_region(brdp->iobase, brdp->iosize, "istallion")) 3217 if ((brdp->iobase == 0) || (brdp->memaddr == 0)) {
3392 return -EIO; 3218 retval = -ENODEV;
3393 3219 goto err;
3394 if ((brdp->iobase == 0) || (brdp->memaddr == 0)) 3220 }
3395 { 3221
3396 release_region(brdp->iobase, brdp->iosize); 3222 if (!request_region(brdp->iobase, brdp->iosize, "istallion")) {
3397 return -ENODEV; 3223 retval = -EIO;
3224 goto err;
3398 } 3225 }
3399 3226
3400 brdp->iosize = ECP_IOSIZE; 3227 brdp->iosize = ECP_IOSIZE;
@@ -3406,7 +3233,6 @@ static int stli_initecp(stlibrd_t *brdp)
3406 */ 3233 */
3407 switch (brdp->brdtype) { 3234 switch (brdp->brdtype) {
3408 case BRD_ECP: 3235 case BRD_ECP:
3409 brdp->membase = (void *) brdp->memaddr;
3410 brdp->memsize = ECP_MEMSIZE; 3236 brdp->memsize = ECP_MEMSIZE;
3411 brdp->pagesize = ECP_ATPAGESIZE; 3237 brdp->pagesize = ECP_ATPAGESIZE;
3412 brdp->init = stli_ecpinit; 3238 brdp->init = stli_ecpinit;
@@ -3420,7 +3246,6 @@ static int stli_initecp(stlibrd_t *brdp)
3420 break; 3246 break;
3421 3247
3422 case BRD_ECPE: 3248 case BRD_ECPE:
3423 brdp->membase = (void *) brdp->memaddr;
3424 brdp->memsize = ECP_MEMSIZE; 3249 brdp->memsize = ECP_MEMSIZE;
3425 brdp->pagesize = ECP_EIPAGESIZE; 3250 brdp->pagesize = ECP_EIPAGESIZE;
3426 brdp->init = stli_ecpeiinit; 3251 brdp->init = stli_ecpeiinit;
@@ -3434,7 +3259,6 @@ static int stli_initecp(stlibrd_t *brdp)
3434 break; 3259 break;
3435 3260
3436 case BRD_ECPMC: 3261 case BRD_ECPMC:
3437 brdp->membase = (void *) brdp->memaddr;
3438 brdp->memsize = ECP_MEMSIZE; 3262 brdp->memsize = ECP_MEMSIZE;
3439 brdp->pagesize = ECP_MCPAGESIZE; 3263 brdp->pagesize = ECP_MCPAGESIZE;
3440 brdp->init = NULL; 3264 brdp->init = NULL;
@@ -3448,7 +3272,6 @@ static int stli_initecp(stlibrd_t *brdp)
3448 break; 3272 break;
3449 3273
3450 case BRD_ECPPCI: 3274 case BRD_ECPPCI:
3451 brdp->membase = (void *) brdp->memaddr;
3452 brdp->memsize = ECP_PCIMEMSIZE; 3275 brdp->memsize = ECP_PCIMEMSIZE;
3453 brdp->pagesize = ECP_PCIPAGESIZE; 3276 brdp->pagesize = ECP_PCIPAGESIZE;
3454 brdp->init = stli_ecppciinit; 3277 brdp->init = stli_ecppciinit;
@@ -3462,8 +3285,8 @@ static int stli_initecp(stlibrd_t *brdp)
3462 break; 3285 break;
3463 3286
3464 default: 3287 default:
3465 release_region(brdp->iobase, brdp->iosize); 3288 retval = -EINVAL;
3466 return -EINVAL; 3289 goto err_reg;
3467 } 3290 }
3468 3291
3469/* 3292/*
@@ -3475,10 +3298,9 @@ static int stli_initecp(stlibrd_t *brdp)
3475 EBRDINIT(brdp); 3298 EBRDINIT(brdp);
3476 3299
3477 brdp->membase = ioremap(brdp->memaddr, brdp->memsize); 3300 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3478 if (brdp->membase == NULL) 3301 if (brdp->membase == NULL) {
3479 { 3302 retval = -ENOMEM;
3480 release_region(brdp->iobase, brdp->iosize); 3303 goto err_reg;
3481 return -ENOMEM;
3482 } 3304 }
3483 3305
3484/* 3306/*
@@ -3491,10 +3313,9 @@ static int stli_initecp(stlibrd_t *brdp)
3491 memcpy_fromio(&sig, sigsp, sizeof(cdkecpsig_t)); 3313 memcpy_fromio(&sig, sigsp, sizeof(cdkecpsig_t));
3492 EBRDDISABLE(brdp); 3314 EBRDDISABLE(brdp);
3493 3315
3494 if (sig.magic != cpu_to_le32(ECP_MAGIC)) 3316 if (sig.magic != cpu_to_le32(ECP_MAGIC)) {
3495 { 3317 retval = -ENODEV;
3496 release_region(brdp->iobase, brdp->iosize); 3318 goto err_unmap;
3497 return -ENODEV;
3498 } 3319 }
3499 3320
3500/* 3321/*
@@ -3519,6 +3340,13 @@ static int stli_initecp(stlibrd_t *brdp)
3519 3340
3520 brdp->state |= BST_FOUND; 3341 brdp->state |= BST_FOUND;
3521 return 0; 3342 return 0;
3343err_unmap:
3344 iounmap(brdp->membase);
3345 brdp->membase = NULL;
3346err_reg:
3347 release_region(brdp->iobase, brdp->iosize);
3348err:
3349 return retval;
3522} 3350}
3523 3351
3524/*****************************************************************************/ 3352/*****************************************************************************/
@@ -3528,23 +3356,27 @@ static int stli_initecp(stlibrd_t *brdp)
3528 * This handles only these board types. 3356 * This handles only these board types.
3529 */ 3357 */
3530 3358
3531static int stli_initonb(stlibrd_t *brdp) 3359static int stli_initonb(struct stlibrd *brdp)
3532{ 3360{
3533 cdkonbsig_t sig; 3361 cdkonbsig_t sig;
3534 cdkonbsig_t __iomem *sigsp; 3362 cdkonbsig_t __iomem *sigsp;
3535 char *name; 3363 char *name;
3536 int i; 3364 int i, retval;
3537 3365
3538/* 3366/*
3539 * Do a basic sanity check on the IO and memory addresses. 3367 * Do a basic sanity check on the IO and memory addresses.
3540 */ 3368 */
3541 if (brdp->iobase == 0 || brdp->memaddr == 0) 3369 if (brdp->iobase == 0 || brdp->memaddr == 0) {
3542 return -ENODEV; 3370 retval = -ENODEV;
3371 goto err;
3372 }
3543 3373
3544 brdp->iosize = ONB_IOSIZE; 3374 brdp->iosize = ONB_IOSIZE;
3545 3375
3546 if (!request_region(brdp->iobase, brdp->iosize, "istallion")) 3376 if (!request_region(brdp->iobase, brdp->iosize, "istallion")) {
3547 return -EIO; 3377 retval = -EIO;
3378 goto err;
3379 }
3548 3380
3549/* 3381/*
3550 * Based on the specific board type setup the common vars to access 3382 * Based on the specific board type setup the common vars to access
@@ -3553,10 +3385,7 @@ static int stli_initonb(stlibrd_t *brdp)
3553 */ 3385 */
3554 switch (brdp->brdtype) { 3386 switch (brdp->brdtype) {
3555 case BRD_ONBOARD: 3387 case BRD_ONBOARD:
3556 case BRD_ONBOARD32:
3557 case BRD_ONBOARD2: 3388 case BRD_ONBOARD2:
3558 case BRD_ONBOARD2_32:
3559 case BRD_ONBOARDRS:
3560 brdp->memsize = ONB_MEMSIZE; 3389 brdp->memsize = ONB_MEMSIZE;
3561 brdp->pagesize = ONB_ATPAGESIZE; 3390 brdp->pagesize = ONB_ATPAGESIZE;
3562 brdp->init = stli_onbinit; 3391 brdp->init = stli_onbinit;
@@ -3587,8 +3416,6 @@ static int stli_initonb(stlibrd_t *brdp)
3587 break; 3416 break;
3588 3417
3589 case BRD_BRUMBY4: 3418 case BRD_BRUMBY4:
3590 case BRD_BRUMBY8:
3591 case BRD_BRUMBY16:
3592 brdp->memsize = BBY_MEMSIZE; 3419 brdp->memsize = BBY_MEMSIZE;
3593 brdp->pagesize = BBY_PAGESIZE; 3420 brdp->pagesize = BBY_PAGESIZE;
3594 brdp->init = stli_bbyinit; 3421 brdp->init = stli_bbyinit;
@@ -3615,8 +3442,8 @@ static int stli_initonb(stlibrd_t *brdp)
3615 break; 3442 break;
3616 3443
3617 default: 3444 default:
3618 release_region(brdp->iobase, brdp->iosize); 3445 retval = -EINVAL;
3619 return -EINVAL; 3446 goto err_reg;
3620 } 3447 }
3621 3448
3622/* 3449/*
@@ -3628,10 +3455,9 @@ static int stli_initonb(stlibrd_t *brdp)
3628 EBRDINIT(brdp); 3455 EBRDINIT(brdp);
3629 3456
3630 brdp->membase = ioremap(brdp->memaddr, brdp->memsize); 3457 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3631 if (brdp->membase == NULL) 3458 if (brdp->membase == NULL) {
3632 { 3459 retval = -ENOMEM;
3633 release_region(brdp->iobase, brdp->iosize); 3460 goto err_reg;
3634 return -ENOMEM;
3635 } 3461 }
3636 3462
3637/* 3463/*
@@ -3647,10 +3473,9 @@ static int stli_initonb(stlibrd_t *brdp)
3647 if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) || 3473 if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
3648 sig.magic1 != cpu_to_le16(ONB_MAGIC1) || 3474 sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
3649 sig.magic2 != cpu_to_le16(ONB_MAGIC2) || 3475 sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
3650 sig.magic3 != cpu_to_le16(ONB_MAGIC3)) 3476 sig.magic3 != cpu_to_le16(ONB_MAGIC3)) {
3651 { 3477 retval = -ENODEV;
3652 release_region(brdp->iobase, brdp->iosize); 3478 goto err_unmap;
3653 return -ENODEV;
3654 } 3479 }
3655 3480
3656/* 3481/*
@@ -3672,6 +3497,13 @@ static int stli_initonb(stlibrd_t *brdp)
3672 3497
3673 brdp->state |= BST_FOUND; 3498 brdp->state |= BST_FOUND;
3674 return 0; 3499 return 0;
3500err_unmap:
3501 iounmap(brdp->membase);
3502 brdp->membase = NULL;
3503err_reg:
3504 release_region(brdp->iobase, brdp->iosize);
3505err:
3506 return retval;
3675} 3507}
3676 3508
3677/*****************************************************************************/ 3509/*****************************************************************************/
@@ -3682,14 +3514,15 @@ static int stli_initonb(stlibrd_t *brdp)
3682 * read in the memory map, and get the show on the road... 3514 * read in the memory map, and get the show on the road...
3683 */ 3515 */
3684 3516
3685static int stli_startbrd(stlibrd_t *brdp) 3517static int stli_startbrd(struct stlibrd *brdp)
3686{ 3518{
3687 cdkhdr_t __iomem *hdrp; 3519 cdkhdr_t __iomem *hdrp;
3688 cdkmem_t __iomem *memp; 3520 cdkmem_t __iomem *memp;
3689 cdkasy_t __iomem *ap; 3521 cdkasy_t __iomem *ap;
3690 unsigned long flags; 3522 unsigned long flags;
3691 stliport_t *portp; 3523 unsigned int portnr, nrdevs, i;
3692 int portnr, nrdevs, i, rc = 0; 3524 struct stliport *portp;
3525 int rc = 0;
3693 u32 memoff; 3526 u32 memoff;
3694 3527
3695 spin_lock_irqsave(&brd_lock, flags); 3528 spin_lock_irqsave(&brd_lock, flags);
@@ -3776,8 +3609,7 @@ stli_donestartup:
3776 3609
3777 if (! stli_timeron) { 3610 if (! stli_timeron) {
3778 stli_timeron++; 3611 stli_timeron++;
3779 stli_timerlist.expires = STLI_TIMEOUT; 3612 mod_timer(&stli_timerlist, STLI_TIMEOUT);
3780 add_timer(&stli_timerlist);
3781 } 3613 }
3782 3614
3783 return rc; 3615 return rc;
@@ -3789,49 +3621,32 @@ stli_donestartup:
3789 * Probe and initialize the specified board. 3621 * Probe and initialize the specified board.
3790 */ 3622 */
3791 3623
3792static int __init stli_brdinit(stlibrd_t *brdp) 3624static int __devinit stli_brdinit(struct stlibrd *brdp)
3793{ 3625{
3794 stli_brds[brdp->brdnr] = brdp; 3626 int retval;
3795 3627
3796 switch (brdp->brdtype) { 3628 switch (brdp->brdtype) {
3797 case BRD_ECP: 3629 case BRD_ECP:
3798 case BRD_ECPE: 3630 case BRD_ECPE:
3799 case BRD_ECPMC: 3631 case BRD_ECPMC:
3800 case BRD_ECPPCI: 3632 case BRD_ECPPCI:
3801 stli_initecp(brdp); 3633 retval = stli_initecp(brdp);
3802 break; 3634 break;
3803 case BRD_ONBOARD: 3635 case BRD_ONBOARD:
3804 case BRD_ONBOARDE: 3636 case BRD_ONBOARDE:
3805 case BRD_ONBOARD2: 3637 case BRD_ONBOARD2:
3806 case BRD_ONBOARD32:
3807 case BRD_ONBOARD2_32:
3808 case BRD_ONBOARDRS:
3809 case BRD_BRUMBY4: 3638 case BRD_BRUMBY4:
3810 case BRD_BRUMBY8:
3811 case BRD_BRUMBY16:
3812 case BRD_STALLION: 3639 case BRD_STALLION:
3813 stli_initonb(brdp); 3640 retval = stli_initonb(brdp);
3814 break; 3641 break;
3815 case BRD_EASYIO:
3816 case BRD_ECH:
3817 case BRD_ECHMC:
3818 case BRD_ECHPCI:
3819 printk(KERN_ERR "STALLION: %s board type not supported in "
3820 "this driver\n", stli_brdnames[brdp->brdtype]);
3821 return -ENODEV;
3822 default: 3642 default:
3823 printk(KERN_ERR "STALLION: board=%d is unknown board " 3643 printk(KERN_ERR "STALLION: board=%d is unknown board "
3824 "type=%d\n", brdp->brdnr, brdp->brdtype); 3644 "type=%d\n", brdp->brdnr, brdp->brdtype);
3825 return -ENODEV; 3645 retval = -ENODEV;
3826 } 3646 }
3827 3647
3828 if ((brdp->state & BST_FOUND) == 0) { 3648 if (retval)
3829 printk(KERN_ERR "STALLION: %s board not found, board=%d " 3649 return retval;
3830 "io=%x mem=%x\n",
3831 stli_brdnames[brdp->brdtype], brdp->brdnr,
3832 brdp->iobase, (int) brdp->memaddr);
3833 return -ENODEV;
3834 }
3835 3650
3836 stli_initports(brdp); 3651 stli_initports(brdp);
3837 printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x " 3652 printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x "
@@ -3841,6 +3656,7 @@ static int __init stli_brdinit(stlibrd_t *brdp)
3841 return 0; 3656 return 0;
3842} 3657}
3843 3658
3659#if STLI_EISAPROBE != 0
3844/*****************************************************************************/ 3660/*****************************************************************************/
3845 3661
3846/* 3662/*
@@ -3848,7 +3664,7 @@ static int __init stli_brdinit(stlibrd_t *brdp)
3848 * might be. This is a bit if hack, but it is the best we can do. 3664 * might be. This is a bit if hack, but it is the best we can do.
3849 */ 3665 */
3850 3666
3851static int stli_eisamemprobe(stlibrd_t *brdp) 3667static int stli_eisamemprobe(struct stlibrd *brdp)
3852{ 3668{
3853 cdkecpsig_t ecpsig, __iomem *ecpsigp; 3669 cdkecpsig_t ecpsig, __iomem *ecpsigp;
3854 cdkonbsig_t onbsig, __iomem *onbsigp; 3670 cdkonbsig_t onbsig, __iomem *onbsigp;
@@ -3894,7 +3710,7 @@ static int stli_eisamemprobe(stlibrd_t *brdp)
3894 continue; 3710 continue;
3895 3711
3896 if (brdp->brdtype == BRD_ECPE) { 3712 if (brdp->brdtype == BRD_ECPE) {
3897 ecpsigp = (cdkecpsig_t __iomem *) stli_ecpeigetmemptr(brdp, 3713 ecpsigp = stli_ecpeigetmemptr(brdp,
3898 CDK_SIGADDR, __LINE__); 3714 CDK_SIGADDR, __LINE__);
3899 memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t)); 3715 memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
3900 if (ecpsig.magic == cpu_to_le32(ECP_MAGIC)) 3716 if (ecpsig.magic == cpu_to_le32(ECP_MAGIC))
@@ -3934,10 +3750,11 @@ static int stli_eisamemprobe(stlibrd_t *brdp)
3934 } 3750 }
3935 return 0; 3751 return 0;
3936} 3752}
3753#endif
3937 3754
3938static int stli_getbrdnr(void) 3755static int stli_getbrdnr(void)
3939{ 3756{
3940 int i; 3757 unsigned int i;
3941 3758
3942 for (i = 0; i < STL_MAXBRDS; i++) { 3759 for (i = 0; i < STL_MAXBRDS; i++) {
3943 if (!stli_brds[i]) { 3760 if (!stli_brds[i]) {
@@ -3949,6 +3766,7 @@ static int stli_getbrdnr(void)
3949 return -1; 3766 return -1;
3950} 3767}
3951 3768
3769#if STLI_EISAPROBE != 0
3952/*****************************************************************************/ 3770/*****************************************************************************/
3953 3771
3954/* 3772/*
@@ -3963,9 +3781,9 @@ static int stli_getbrdnr(void)
3963 3781
3964static int stli_findeisabrds(void) 3782static int stli_findeisabrds(void)
3965{ 3783{
3966 stlibrd_t *brdp; 3784 struct stlibrd *brdp;
3967 unsigned int iobase, eid; 3785 unsigned int iobase, eid, i;
3968 int i; 3786 int brdnr, found = 0;
3969 3787
3970/* 3788/*
3971 * Firstly check if this is an EISA system. If this is not an EISA system then 3789 * Firstly check if this is an EISA system. If this is not an EISA system then
@@ -4003,9 +3821,11 @@ static int stli_findeisabrds(void)
4003 * Allocate a board structure and initialize it. 3821 * Allocate a board structure and initialize it.
4004 */ 3822 */
4005 if ((brdp = stli_allocbrd()) == NULL) 3823 if ((brdp = stli_allocbrd()) == NULL)
4006 return -ENOMEM; 3824 return found ? : -ENOMEM;
4007 if ((brdp->brdnr = stli_getbrdnr()) < 0) 3825 brdnr = stli_getbrdnr();
4008 return -ENOMEM; 3826 if (brdnr < 0)
3827 return found ? : -ENOMEM;
3828 brdp->brdnr = (unsigned int)brdnr;
4009 eid = inb(iobase + 0xc82); 3829 eid = inb(iobase + 0xc82);
4010 if (eid == ECP_EISAID) 3830 if (eid == ECP_EISAID)
4011 brdp->brdtype = BRD_ECPE; 3831 brdp->brdtype = BRD_ECPE;
@@ -4017,11 +3837,24 @@ static int stli_findeisabrds(void)
4017 outb(0x1, (iobase + 0xc84)); 3837 outb(0x1, (iobase + 0xc84));
4018 if (stli_eisamemprobe(brdp)) 3838 if (stli_eisamemprobe(brdp))
4019 outb(0, (iobase + 0xc84)); 3839 outb(0, (iobase + 0xc84));
4020 stli_brdinit(brdp); 3840 if (stli_brdinit(brdp) < 0) {
3841 kfree(brdp);
3842 continue;
3843 }
3844
3845 stli_brds[brdp->brdnr] = brdp;
3846 found++;
3847
3848 for (i = 0; i < brdp->nrports; i++)
3849 tty_register_device(stli_serial,
3850 brdp->brdnr * STL_MAXPORTS + i, NULL);
4021 } 3851 }
4022 3852
4023 return 0; 3853 return found;
4024} 3854}
3855#else
3856static inline int stli_findeisabrds(void) { return 0; }
3857#endif
4025 3858
4026/*****************************************************************************/ 3859/*****************************************************************************/
4027 3860
@@ -4031,72 +3864,104 @@ static int stli_findeisabrds(void)
4031 3864
4032/*****************************************************************************/ 3865/*****************************************************************************/
4033 3866
4034#ifdef CONFIG_PCI
4035
4036/* 3867/*
4037 * We have a Stallion board. Allocate a board structure and 3868 * We have a Stallion board. Allocate a board structure and
4038 * initialize it. Read its IO and MEMORY resources from PCI 3869 * initialize it. Read its IO and MEMORY resources from PCI
4039 * configuration space. 3870 * configuration space.
4040 */ 3871 */
4041 3872
4042static int stli_initpcibrd(int brdtype, struct pci_dev *devp) 3873static int __devinit stli_pciprobe(struct pci_dev *pdev,
3874 const struct pci_device_id *ent)
4043{ 3875{
4044 stlibrd_t *brdp; 3876 struct stlibrd *brdp;
4045 3877 unsigned int i;
4046 if (pci_enable_device(devp)) 3878 int brdnr, retval = -EIO;
4047 return -EIO; 3879
4048 if ((brdp = stli_allocbrd()) == NULL) 3880 retval = pci_enable_device(pdev);
4049 return -ENOMEM; 3881 if (retval)
4050 if ((brdp->brdnr = stli_getbrdnr()) < 0) { 3882 goto err;
3883 brdp = stli_allocbrd();
3884 if (brdp == NULL) {
3885 retval = -ENOMEM;
3886 goto err;
3887 }
3888 mutex_lock(&stli_brdslock);
3889 brdnr = stli_getbrdnr();
3890 if (brdnr < 0) {
4051 printk(KERN_INFO "STALLION: too many boards found, " 3891 printk(KERN_INFO "STALLION: too many boards found, "
4052 "maximum supported %d\n", STL_MAXBRDS); 3892 "maximum supported %d\n", STL_MAXBRDS);
4053 return 0; 3893 mutex_unlock(&stli_brdslock);
3894 retval = -EIO;
3895 goto err_fr;
4054 } 3896 }
4055 brdp->brdtype = brdtype; 3897 brdp->brdnr = (unsigned int)brdnr;
3898 stli_brds[brdp->brdnr] = brdp;
3899 mutex_unlock(&stli_brdslock);
3900 brdp->brdtype = BRD_ECPPCI;
4056/* 3901/*
4057 * We have all resources from the board, so lets setup the actual 3902 * We have all resources from the board, so lets setup the actual
4058 * board structure now. 3903 * board structure now.
4059 */ 3904 */
4060 brdp->iobase = pci_resource_start(devp, 3); 3905 brdp->iobase = pci_resource_start(pdev, 3);
4061 brdp->memaddr = pci_resource_start(devp, 2); 3906 brdp->memaddr = pci_resource_start(pdev, 2);
4062 stli_brdinit(brdp); 3907 retval = stli_brdinit(brdp);
3908 if (retval)
3909 goto err_null;
3910
3911 brdp->state |= BST_PROBED;
3912 pci_set_drvdata(pdev, brdp);
3913
3914 EBRDENABLE(brdp);
3915 brdp->enable = NULL;
3916 brdp->disable = NULL;
3917
3918 for (i = 0; i < brdp->nrports; i++)
3919 tty_register_device(stli_serial, brdp->brdnr * STL_MAXPORTS + i,
3920 &pdev->dev);
4063 3921
4064 return 0; 3922 return 0;
3923err_null:
3924 stli_brds[brdp->brdnr] = NULL;
3925err_fr:
3926 kfree(brdp);
3927err:
3928 return retval;
4065} 3929}
4066 3930
4067/*****************************************************************************/ 3931static void stli_pciremove(struct pci_dev *pdev)
3932{
3933 struct stlibrd *brdp = pci_get_drvdata(pdev);
4068 3934
4069/* 3935 stli_cleanup_ports(brdp);
4070 * Find all Stallion PCI boards that might be installed. Initialize each
4071 * one as it is found.
4072 */
4073 3936
4074static int stli_findpcibrds(void) 3937 iounmap(brdp->membase);
4075{ 3938 if (brdp->iosize > 0)
4076 struct pci_dev *dev = NULL; 3939 release_region(brdp->iobase, brdp->iosize);
4077 3940
4078 while ((dev = pci_get_device(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, dev))) { 3941 stli_brds[brdp->brdnr] = NULL;
4079 stli_initpcibrd(BRD_ECPPCI, dev); 3942 kfree(brdp);
4080 }
4081 return 0;
4082} 3943}
4083 3944
4084#endif 3945static struct pci_driver stli_pcidriver = {
4085 3946 .name = "istallion",
3947 .id_table = istallion_pci_tbl,
3948 .probe = stli_pciprobe,
3949 .remove = __devexit_p(stli_pciremove)
3950};
4086/*****************************************************************************/ 3951/*****************************************************************************/
4087 3952
4088/* 3953/*
4089 * Allocate a new board structure. Fill out the basic info in it. 3954 * Allocate a new board structure. Fill out the basic info in it.
4090 */ 3955 */
4091 3956
4092static stlibrd_t *stli_allocbrd(void) 3957static struct stlibrd *stli_allocbrd(void)
4093{ 3958{
4094 stlibrd_t *brdp; 3959 struct stlibrd *brdp;
4095 3960
4096 brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL); 3961 brdp = kzalloc(sizeof(struct stlibrd), GFP_KERNEL);
4097 if (!brdp) { 3962 if (!brdp) {
4098 printk(KERN_ERR "STALLION: failed to allocate memory " 3963 printk(KERN_ERR "STALLION: failed to allocate memory "
4099 "(size=%Zd)\n", sizeof(stlibrd_t)); 3964 "(size=%Zd)\n", sizeof(struct stlibrd));
4100 return NULL; 3965 return NULL;
4101 } 3966 }
4102 brdp->magic = STLI_BOARDMAGIC; 3967 brdp->magic = STLI_BOARDMAGIC;
@@ -4112,43 +3977,37 @@ static stlibrd_t *stli_allocbrd(void)
4112 3977
4113static int stli_initbrds(void) 3978static int stli_initbrds(void)
4114{ 3979{
4115 stlibrd_t *brdp, *nxtbrdp; 3980 struct stlibrd *brdp, *nxtbrdp;
4116 stlconf_t *confp; 3981 struct stlconf conf;
4117 int i, j; 3982 unsigned int i, j, found = 0;
4118 3983 int retval;
4119 if (stli_nrbrds > STL_MAXBRDS) {
4120 printk(KERN_INFO "STALLION: too many boards in configuration "
4121 "table, truncating to %d\n", STL_MAXBRDS);
4122 stli_nrbrds = STL_MAXBRDS;
4123 }
4124 3984
4125/* 3985 for (stli_nrbrds = 0; stli_nrbrds < ARRAY_SIZE(stli_brdsp);
4126 * Firstly scan the list of static boards configured. Allocate 3986 stli_nrbrds++) {
4127 * resources and initialize the boards as found. If this is a 3987 memset(&conf, 0, sizeof(conf));
4128 * module then let the module args override static configuration. 3988 if (stli_parsebrd(&conf, stli_brdsp[stli_nrbrds]) == 0)
4129 */ 3989 continue;
4130 for (i = 0; (i < stli_nrbrds); i++) {
4131 confp = &stli_brdconf[i];
4132 stli_parsebrd(confp, stli_brdsp[i]);
4133 if ((brdp = stli_allocbrd()) == NULL) 3990 if ((brdp = stli_allocbrd()) == NULL)
4134 return -ENOMEM; 3991 continue;
4135 brdp->brdnr = i; 3992 brdp->brdnr = stli_nrbrds;
4136 brdp->brdtype = confp->brdtype; 3993 brdp->brdtype = conf.brdtype;
4137 brdp->iobase = confp->ioaddr1; 3994 brdp->iobase = conf.ioaddr1;
4138 brdp->memaddr = confp->memaddr; 3995 brdp->memaddr = conf.memaddr;
4139 stli_brdinit(brdp); 3996 if (stli_brdinit(brdp) < 0) {
3997 kfree(brdp);
3998 continue;
3999 }
4000 stli_brds[brdp->brdnr] = brdp;
4001 found++;
4002
4003 for (i = 0; i < brdp->nrports; i++)
4004 tty_register_device(stli_serial,
4005 brdp->brdnr * STL_MAXPORTS + i, NULL);
4140 } 4006 }
4141 4007
4142/* 4008 retval = stli_findeisabrds();
4143 * Static configuration table done, so now use dynamic methods to 4009 if (retval > 0)
4144 * see if any more boards should be configured. 4010 found += retval;
4145 */
4146 stli_argbrds();
4147 if (STLI_EISAPROBE)
4148 stli_findeisabrds();
4149#ifdef CONFIG_PCI
4150 stli_findpcibrds();
4151#endif
4152 4011
4153/* 4012/*
4154 * All found boards are initialized. Now for a little optimization, if 4013 * All found boards are initialized. Now for a little optimization, if
@@ -4188,7 +4047,16 @@ static int stli_initbrds(void)
4188 } 4047 }
4189 } 4048 }
4190 4049
4050 retval = pci_register_driver(&stli_pcidriver);
4051 if (retval && found == 0) {
4052 printk(KERN_ERR "Neither isa nor eisa cards found nor pci "
4053 "driver can be registered!\n");
4054 goto err;
4055 }
4056
4191 return 0; 4057 return 0;
4058err:
4059 return retval;
4192} 4060}
4193 4061
4194/*****************************************************************************/ 4062/*****************************************************************************/
@@ -4202,13 +4070,14 @@ static int stli_initbrds(void)
4202static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp) 4070static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
4203{ 4071{
4204 unsigned long flags; 4072 unsigned long flags;
4205 void *memptr; 4073 void __iomem *memptr;
4206 stlibrd_t *brdp; 4074 struct stlibrd *brdp;
4207 int brdnr, size, n; 4075 unsigned int brdnr;
4076 int size, n;
4208 void *p; 4077 void *p;
4209 loff_t off = *offp; 4078 loff_t off = *offp;
4210 4079
4211 brdnr = iminor(fp->f_dentry->d_inode); 4080 brdnr = iminor(fp->f_path.dentry->d_inode);
4212 if (brdnr >= stli_nrbrds) 4081 if (brdnr >= stli_nrbrds)
4213 return -ENODEV; 4082 return -ENODEV;
4214 brdp = stli_brds[brdnr]; 4083 brdp = stli_brds[brdnr];
@@ -4219,7 +4088,7 @@ static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, lof
4219 if (off >= brdp->memsize || off + count < off) 4088 if (off >= brdp->memsize || off + count < off)
4220 return 0; 4089 return 0;
4221 4090
4222 size = MIN(count, (brdp->memsize - off)); 4091 size = min(count, (size_t)(brdp->memsize - off));
4223 4092
4224 /* 4093 /*
4225 * Copy the data a page at a time 4094 * Copy the data a page at a time
@@ -4232,9 +4101,9 @@ static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, lof
4232 while (size > 0) { 4101 while (size > 0) {
4233 spin_lock_irqsave(&brd_lock, flags); 4102 spin_lock_irqsave(&brd_lock, flags);
4234 EBRDENABLE(brdp); 4103 EBRDENABLE(brdp);
4235 memptr = (void *) EBRDGETMEMPTR(brdp, off); 4104 memptr = EBRDGETMEMPTR(brdp, off);
4236 n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize))); 4105 n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4237 n = MIN(n, PAGE_SIZE); 4106 n = min(n, (int)PAGE_SIZE);
4238 memcpy_fromio(p, memptr, n); 4107 memcpy_fromio(p, memptr, n);
4239 EBRDDISABLE(brdp); 4108 EBRDDISABLE(brdp);
4240 spin_unlock_irqrestore(&brd_lock, flags); 4109 spin_unlock_irqrestore(&brd_lock, flags);
@@ -4265,14 +4134,15 @@ out:
4265static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp) 4134static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
4266{ 4135{
4267 unsigned long flags; 4136 unsigned long flags;
4268 void *memptr; 4137 void __iomem *memptr;
4269 stlibrd_t *brdp; 4138 struct stlibrd *brdp;
4270 char __user *chbuf; 4139 char __user *chbuf;
4271 int brdnr, size, n; 4140 unsigned int brdnr;
4141 int size, n;
4272 void *p; 4142 void *p;
4273 loff_t off = *offp; 4143 loff_t off = *offp;
4274 4144
4275 brdnr = iminor(fp->f_dentry->d_inode); 4145 brdnr = iminor(fp->f_path.dentry->d_inode);
4276 4146
4277 if (brdnr >= stli_nrbrds) 4147 if (brdnr >= stli_nrbrds)
4278 return -ENODEV; 4148 return -ENODEV;
@@ -4285,7 +4155,7 @@ static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t cou
4285 return 0; 4155 return 0;
4286 4156
4287 chbuf = (char __user *) buf; 4157 chbuf = (char __user *) buf;
4288 size = MIN(count, (brdp->memsize - off)); 4158 size = min(count, (size_t)(brdp->memsize - off));
4289 4159
4290 /* 4160 /*
4291 * Copy the data a page at a time 4161 * Copy the data a page at a time
@@ -4296,8 +4166,8 @@ static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t cou
4296 return -ENOMEM; 4166 return -ENOMEM;
4297 4167
4298 while (size > 0) { 4168 while (size > 0) {
4299 n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize))); 4169 n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4300 n = MIN(n, PAGE_SIZE); 4170 n = min(n, (int)PAGE_SIZE);
4301 if (copy_from_user(p, chbuf, n)) { 4171 if (copy_from_user(p, chbuf, n)) {
4302 if (count == 0) 4172 if (count == 0)
4303 count = -EFAULT; 4173 count = -EFAULT;
@@ -4305,7 +4175,7 @@ static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t cou
4305 } 4175 }
4306 spin_lock_irqsave(&brd_lock, flags); 4176 spin_lock_irqsave(&brd_lock, flags);
4307 EBRDENABLE(brdp); 4177 EBRDENABLE(brdp);
4308 memptr = (void *) EBRDGETMEMPTR(brdp, off); 4178 memptr = EBRDGETMEMPTR(brdp, off);
4309 memcpy_toio(memptr, p, n); 4179 memcpy_toio(memptr, p, n);
4310 EBRDDISABLE(brdp); 4180 EBRDDISABLE(brdp);
4311 spin_unlock_irqrestore(&brd_lock, flags); 4181 spin_unlock_irqrestore(&brd_lock, flags);
@@ -4327,8 +4197,8 @@ out:
4327 4197
4328static int stli_getbrdstats(combrd_t __user *bp) 4198static int stli_getbrdstats(combrd_t __user *bp)
4329{ 4199{
4330 stlibrd_t *brdp; 4200 struct stlibrd *brdp;
4331 int i; 4201 unsigned int i;
4332 4202
4333 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t))) 4203 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
4334 return -EFAULT; 4204 return -EFAULT;
@@ -4364,19 +4234,20 @@ static int stli_getbrdstats(combrd_t __user *bp)
4364 * Resolve the referenced port number into a port struct pointer. 4234 * Resolve the referenced port number into a port struct pointer.
4365 */ 4235 */
4366 4236
4367static stliport_t *stli_getport(int brdnr, int panelnr, int portnr) 4237static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr,
4238 unsigned int portnr)
4368{ 4239{
4369 stlibrd_t *brdp; 4240 struct stlibrd *brdp;
4370 int i; 4241 unsigned int i;
4371 4242
4372 if (brdnr < 0 || brdnr >= STL_MAXBRDS) 4243 if (brdnr >= STL_MAXBRDS)
4373 return NULL; 4244 return NULL;
4374 brdp = stli_brds[brdnr]; 4245 brdp = stli_brds[brdnr];
4375 if (brdp == NULL) 4246 if (brdp == NULL)
4376 return NULL; 4247 return NULL;
4377 for (i = 0; (i < panelnr); i++) 4248 for (i = 0; (i < panelnr); i++)
4378 portnr += brdp->panels[i]; 4249 portnr += brdp->panels[i];
4379 if ((portnr < 0) || (portnr >= brdp->nrports)) 4250 if (portnr >= brdp->nrports)
4380 return NULL; 4251 return NULL;
4381 return brdp->ports[portnr]; 4252 return brdp->ports[portnr];
4382} 4253}
@@ -4389,10 +4260,10 @@ static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
4389 * what port to get stats for (used through board control device). 4260 * what port to get stats for (used through board control device).
4390 */ 4261 */
4391 4262
4392static int stli_portcmdstats(stliport_t *portp) 4263static int stli_portcmdstats(struct stliport *portp)
4393{ 4264{
4394 unsigned long flags; 4265 unsigned long flags;
4395 stlibrd_t *brdp; 4266 struct stlibrd *brdp;
4396 int rc; 4267 int rc;
4397 4268
4398 memset(&stli_comstats, 0, sizeof(comstats_t)); 4269 memset(&stli_comstats, 0, sizeof(comstats_t));
@@ -4463,9 +4334,9 @@ static int stli_portcmdstats(stliport_t *portp)
4463 * what port to get stats for (used through board control device). 4334 * what port to get stats for (used through board control device).
4464 */ 4335 */
4465 4336
4466static int stli_getportstats(stliport_t *portp, comstats_t __user *cp) 4337static int stli_getportstats(struct stliport *portp, comstats_t __user *cp)
4467{ 4338{
4468 stlibrd_t *brdp; 4339 struct stlibrd *brdp;
4469 int rc; 4340 int rc;
4470 4341
4471 if (!portp) { 4342 if (!portp) {
@@ -4494,9 +4365,9 @@ static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
4494 * Clear the port stats structure. We also return it zeroed out... 4365 * Clear the port stats structure. We also return it zeroed out...
4495 */ 4366 */
4496 4367
4497static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp) 4368static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp)
4498{ 4369{
4499 stlibrd_t *brdp; 4370 struct stlibrd *brdp;
4500 int rc; 4371 int rc;
4501 4372
4502 if (!portp) { 4373 if (!portp) {
@@ -4533,17 +4404,18 @@ static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
4533 * Return the entire driver ports structure to a user app. 4404 * Return the entire driver ports structure to a user app.
4534 */ 4405 */
4535 4406
4536static int stli_getportstruct(stliport_t __user *arg) 4407static int stli_getportstruct(struct stliport __user *arg)
4537{ 4408{
4538 stliport_t *portp; 4409 struct stliport stli_dummyport;
4410 struct stliport *portp;
4539 4411
4540 if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t))) 4412 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
4541 return -EFAULT; 4413 return -EFAULT;
4542 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr, 4414 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
4543 stli_dummyport.portnr); 4415 stli_dummyport.portnr);
4544 if (!portp) 4416 if (!portp)
4545 return -ENODEV; 4417 return -ENODEV;
4546 if (copy_to_user(arg, portp, sizeof(stliport_t))) 4418 if (copy_to_user(arg, portp, sizeof(struct stliport)))
4547 return -EFAULT; 4419 return -EFAULT;
4548 return 0; 4420 return 0;
4549} 4421}
@@ -4554,18 +4426,19 @@ static int stli_getportstruct(stliport_t __user *arg)
4554 * Return the entire driver board structure to a user app. 4426 * Return the entire driver board structure to a user app.
4555 */ 4427 */
4556 4428
4557static int stli_getbrdstruct(stlibrd_t __user *arg) 4429static int stli_getbrdstruct(struct stlibrd __user *arg)
4558{ 4430{
4559 stlibrd_t *brdp; 4431 struct stlibrd stli_dummybrd;
4432 struct stlibrd *brdp;
4560 4433
4561 if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t))) 4434 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
4562 return -EFAULT; 4435 return -EFAULT;
4563 if ((stli_dummybrd.brdnr < 0) || (stli_dummybrd.brdnr >= STL_MAXBRDS)) 4436 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
4564 return -ENODEV; 4437 return -ENODEV;
4565 brdp = stli_brds[stli_dummybrd.brdnr]; 4438 brdp = stli_brds[stli_dummybrd.brdnr];
4566 if (!brdp) 4439 if (!brdp)
4567 return -ENODEV; 4440 return -ENODEV;
4568 if (copy_to_user(arg, brdp, sizeof(stlibrd_t))) 4441 if (copy_to_user(arg, brdp, sizeof(struct stlibrd)))
4569 return -EFAULT; 4442 return -EFAULT;
4570 return 0; 4443 return 0;
4571} 4444}
@@ -4580,7 +4453,7 @@ static int stli_getbrdstruct(stlibrd_t __user *arg)
4580 4453
4581static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg) 4454static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
4582{ 4455{
4583 stlibrd_t *brdp; 4456 struct stlibrd *brdp;
4584 int brdnr, rc, done; 4457 int brdnr, rc, done;
4585 void __user *argp = (void __user *)arg; 4458 void __user *argp = (void __user *)arg;
4586 4459
@@ -4654,7 +4527,7 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
4654 return rc; 4527 return rc;
4655} 4528}
4656 4529
4657static struct tty_operations stli_ops = { 4530static const struct tty_operations stli_ops = {
4658 .open = stli_open, 4531 .open = stli_open,
4659 .close = stli_close, 4532 .close = stli_close,
4660 .write = stli_write, 4533 .write = stli_write,
@@ -4679,46 +4552,53 @@ static struct tty_operations stli_ops = {
4679}; 4552};
4680 4553
4681/*****************************************************************************/ 4554/*****************************************************************************/
4555/*
4556 * Loadable module initialization stuff.
4557 */
4558
4559static void istallion_cleanup_isa(void)
4560{
4561 struct stlibrd *brdp;
4562 unsigned int j;
4682 4563
4683static int __init stli_init(void) 4564 for (j = 0; (j < stli_nrbrds); j++) {
4565 if ((brdp = stli_brds[j]) == NULL || (brdp->state & BST_PROBED))
4566 continue;
4567
4568 stli_cleanup_ports(brdp);
4569
4570 iounmap(brdp->membase);
4571 if (brdp->iosize > 0)
4572 release_region(brdp->iobase, brdp->iosize);
4573 kfree(brdp);
4574 stli_brds[j] = NULL;
4575 }
4576}
4577
4578static int __init istallion_module_init(void)
4684{ 4579{
4685 int i; 4580 unsigned int i;
4581 int retval;
4582
4686 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion); 4583 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
4687 4584
4688 spin_lock_init(&stli_lock); 4585 spin_lock_init(&stli_lock);
4689 spin_lock_init(&brd_lock); 4586 spin_lock_init(&brd_lock);
4690 4587
4691 stli_initbrds();
4692
4693 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4694 if (!stli_serial)
4695 return -ENOMEM;
4696
4697/*
4698 * Allocate a temporary write buffer.
4699 */
4700 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL); 4588 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
4701 if (!stli_txcookbuf) 4589 if (!stli_txcookbuf) {
4702 printk(KERN_ERR "STALLION: failed to allocate memory " 4590 printk(KERN_ERR "STALLION: failed to allocate memory "
4703 "(size=%d)\n", STLI_TXBUFSIZE); 4591 "(size=%d)\n", STLI_TXBUFSIZE);
4592 retval = -ENOMEM;
4593 goto err;
4594 }
4704 4595
4705/* 4596 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4706 * Set up a character driver for the shared memory region. We need this 4597 if (!stli_serial) {
4707 * to down load the slave code image. Also it is a useful debugging tool. 4598 retval = -ENOMEM;
4708 */ 4599 goto err_free;
4709 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem)) 4600 }
4710 printk(KERN_ERR "STALLION: failed to register serial memory "
4711 "device\n");
4712
4713 istallion_class = class_create(THIS_MODULE, "staliomem");
4714 for (i = 0; i < 4; i++)
4715 class_device_create(istallion_class, NULL,
4716 MKDEV(STL_SIOMEMMAJOR, i),
4717 NULL, "staliomem%d", i);
4718 4601
4719/*
4720 * Set up the tty driver structure and register us as a driver.
4721 */
4722 stli_serial->owner = THIS_MODULE; 4602 stli_serial->owner = THIS_MODULE;
4723 stli_serial->driver_name = stli_drvname; 4603 stli_serial->driver_name = stli_drvname;
4724 stli_serial->name = stli_serialname; 4604 stli_serial->name = stli_serialname;
@@ -4727,15 +4607,79 @@ static int __init stli_init(void)
4727 stli_serial->type = TTY_DRIVER_TYPE_SERIAL; 4607 stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
4728 stli_serial->subtype = SERIAL_TYPE_NORMAL; 4608 stli_serial->subtype = SERIAL_TYPE_NORMAL;
4729 stli_serial->init_termios = stli_deftermios; 4609 stli_serial->init_termios = stli_deftermios;
4730 stli_serial->flags = TTY_DRIVER_REAL_RAW; 4610 stli_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
4731 tty_set_operations(stli_serial, &stli_ops); 4611 tty_set_operations(stli_serial, &stli_ops);
4732 4612
4733 if (tty_register_driver(stli_serial)) { 4613 retval = tty_register_driver(stli_serial);
4734 put_tty_driver(stli_serial); 4614 if (retval) {
4735 printk(KERN_ERR "STALLION: failed to register serial driver\n"); 4615 printk(KERN_ERR "STALLION: failed to register serial driver\n");
4736 return -EBUSY; 4616 goto err_ttyput;
4737 } 4617 }
4618
4619 retval = stli_initbrds();
4620 if (retval)
4621 goto err_ttyunr;
4622
4623/*
4624 * Set up a character driver for the shared memory region. We need this
4625 * to down load the slave code image. Also it is a useful debugging tool.
4626 */
4627 retval = register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem);
4628 if (retval) {
4629 printk(KERN_ERR "STALLION: failed to register serial memory "
4630 "device\n");
4631 goto err_deinit;
4632 }
4633
4634 istallion_class = class_create(THIS_MODULE, "staliomem");
4635 for (i = 0; i < 4; i++)
4636 class_device_create(istallion_class, NULL,
4637 MKDEV(STL_SIOMEMMAJOR, i),
4638 NULL, "staliomem%d", i);
4639
4738 return 0; 4640 return 0;
4641err_deinit:
4642 pci_unregister_driver(&stli_pcidriver);
4643 istallion_cleanup_isa();
4644err_ttyunr:
4645 tty_unregister_driver(stli_serial);
4646err_ttyput:
4647 put_tty_driver(stli_serial);
4648err_free:
4649 kfree(stli_txcookbuf);
4650err:
4651 return retval;
4739} 4652}
4740 4653
4741/*****************************************************************************/ 4654/*****************************************************************************/
4655
4656static void __exit istallion_module_exit(void)
4657{
4658 unsigned int j;
4659
4660 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
4661 stli_drvversion);
4662
4663 if (stli_timeron) {
4664 stli_timeron = 0;
4665 del_timer_sync(&stli_timerlist);
4666 }
4667
4668 unregister_chrdev(STL_SIOMEMMAJOR, "staliomem");
4669
4670 for (j = 0; j < 4; j++)
4671 class_device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR,
4672 j));
4673 class_destroy(istallion_class);
4674
4675 pci_unregister_driver(&stli_pcidriver);
4676 istallion_cleanup_isa();
4677
4678 tty_unregister_driver(stli_serial);
4679 put_tty_driver(stli_serial);
4680
4681 kfree(stli_txcookbuf);
4682}
4683
4684module_init(istallion_module_init);
4685module_exit(istallion_module_exit);
diff --git a/drivers/char/ite_gpio.c b/drivers/char/ite_gpio.c
deleted file mode 100644
index cde562d70c4f..000000000000
--- a/drivers/char/ite_gpio.c
+++ /dev/null
@@ -1,419 +0,0 @@
1/*
2 * FILE NAME ite_gpio.c
3 *
4 * BRIEF MODULE DESCRIPTION
5 * API for ITE GPIO device.
6 * Driver for ITE GPIO device.
7 *
8 * Author: MontaVista Software, Inc. <source@mvista.com>
9 * Hai-Pao Fan <haipao@mvista.com>
10 *
11 * Copyright 2001 MontaVista Software Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
21 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * You should have received a copy of the GNU General Public License along
30 * with this program; if not, write to the Free Software Foundation, Inc.,
31 * 675 Mass Ave, Cambridge, MA 02139, USA.
32 */
33#include <linux/module.h>
34#include <linux/types.h>
35#include <linux/kernel.h>
36#include <linux/miscdevice.h>
37#include <linux/init.h>
38#include <linux/ioport.h>
39#include <asm/uaccess.h>
40#include <asm/addrspace.h>
41#include <asm/it8172/it8172_int.h>
42#include <linux/sched.h>
43#include <linux/ite_gpio.h>
44
45#define ite_gpio_base 0x14013800
46
47#define ITE_GPADR (*(volatile __u8 *)(0x14013800 + KSEG1))
48#define ITE_GPBDR (*(volatile __u8 *)(0x14013808 + KSEG1))
49#define ITE_GPCDR (*(volatile __u8 *)(0x14013810 + KSEG1))
50#define ITE_GPACR (*(volatile __u16 *)(0x14013802 + KSEG1))
51#define ITE_GPBCR (*(volatile __u16 *)(0x1401380a + KSEG1))
52#define ITE_GPCCR (*(volatile __u16 *)(0x14013812 + KSEG1))
53#define ITE_GPAICR (*(volatile __u16 *)(0x14013804 + KSEG1))
54#define ITE_GPBICR (*(volatile __u16 *)(0x1401380c + KSEG1))
55#define ITE_GPCICR (*(volatile __u16 *)(0x14013814 + KSEG1))
56#define ITE_GPAISR (*(volatile __u8 *)(0x14013806 + KSEG1))
57#define ITE_GPBISR (*(volatile __u8 *)(0x1401380e + KSEG1))
58#define ITE_GPCISR (*(volatile __u8 *)(0x14013816 + KSEG1))
59#define ITE_GCR (*(volatile __u8 *)(0x14013818 + KSEG1))
60
61#define MAX_GPIO_LINE 21
62static int ite_gpio_irq=IT8172_GPIO_IRQ;
63
64static long ite_irq_counter[MAX_GPIO_LINE];
65wait_queue_head_t ite_gpio_wait[MAX_GPIO_LINE];
66static int ite_gpio_irq_pending[MAX_GPIO_LINE];
67
68static int ite_gpio_debug=0;
69#define DEB(x) if (ite_gpio_debug>=1) x
70
71int ite_gpio_in(__u32 device, __u32 mask, volatile __u32 *data)
72{
73 DEB(printk("ite_gpio_in mask=0x%x\n",mask));
74
75 switch (device) {
76 case ITE_GPIO_PORTA:
77 ITE_GPACR = (__u16)mask; /* 0xffff */
78 *data = ITE_GPADR;
79 break;
80 case ITE_GPIO_PORTB:
81 ITE_GPBCR = (__u16)mask; /* 0xffff */
82 *data = ITE_GPBDR;
83 break;
84 case ITE_GPIO_PORTC:
85 ITE_GPCCR = (__u16)mask; /* 0x03ff */
86 *data = ITE_GPCDR;
87 break;
88 default:
89 return -EFAULT;
90 }
91
92 return 0;
93}
94
95
96int ite_gpio_out(__u32 device, __u32 mask, __u32 data)
97{
98 switch (device) {
99 case ITE_GPIO_PORTA:
100 ITE_GPACR = (__u16)mask; /* 0x5555 */
101 ITE_GPADR = (__u8)data;
102 break;
103 case ITE_GPIO_PORTB:
104 ITE_GPBCR = (__u16)mask; /* 0x5555 */
105 ITE_GPBDR = (__u8)data;
106 break;
107 case ITE_GPIO_PORTC:
108 ITE_GPCCR = (__u16)mask; /* 0x0155 */
109 ITE_GPCDR = (__u8)data;
110 break;
111 default:
112 return -EFAULT;
113 }
114
115 return 0;
116}
117
118int ite_gpio_int_ctrl(__u32 device, __u32 mask, __u32 data)
119{
120 switch (device) {
121 case ITE_GPIO_PORTA:
122 ITE_GPAICR = (ITE_GPAICR & ~mask) | (data & mask);
123 break;
124 case ITE_GPIO_PORTB:
125 ITE_GPBICR = (ITE_GPBICR & ~mask) | (data & mask);
126 break;
127 case ITE_GPIO_PORTC:
128 ITE_GPCICR = (ITE_GPCICR & ~mask) | (data & mask);
129 break;
130 default:
131 return -EFAULT;
132 }
133
134 return 0;
135}
136
137int ite_gpio_in_status(__u32 device, __u32 mask, volatile __u32 *data)
138{
139 int ret=-1;
140
141 if ((MAX_GPIO_LINE > *data) && (*data >= 0))
142 ret=ite_gpio_irq_pending[*data];
143
144 DEB(printk("ite_gpio_in_status %d ret=%d\n",*data, ret));
145
146 switch (device) {
147 case ITE_GPIO_PORTA:
148 *data = ITE_GPAISR & mask;
149 break;
150 case ITE_GPIO_PORTB:
151 *data = ITE_GPBISR & mask;
152 break;
153 case ITE_GPIO_PORTC:
154 *data = ITE_GPCISR & mask;
155 break;
156 default:
157 return -EFAULT;
158 }
159
160 return ret;
161}
162
163int ite_gpio_out_status(__u32 device, __u32 mask, __u32 data)
164{
165 switch (device) {
166 case ITE_GPIO_PORTA:
167 ITE_GPAISR = (ITE_GPAISR & ~mask) | (data & mask);
168 break;
169 case ITE_GPIO_PORTB:
170 ITE_GPBISR = (ITE_GPBISR & ~mask) | (data & mask);
171 break;
172 case ITE_GPIO_PORTC:
173 ITE_GPCISR = (ITE_GPCISR & ~mask) | (data & mask);
174 break;
175 default:
176 return -EFAULT;
177 }
178
179 return 0;
180}
181
182int ite_gpio_gen_ctrl(__u32 device, __u32 mask, __u32 data)
183{
184 ITE_GCR = (ITE_GCR & ~mask) | (data & mask);
185
186 return 0;
187}
188
189int ite_gpio_int_wait (__u32 device, __u32 mask, __u32 data)
190{
191 int i,line=0, ret=0;
192 unsigned long flags;
193
194 switch (device) {
195 case ITE_GPIO_PORTA:
196 line = data & mask;
197 break;
198 case ITE_GPIO_PORTB:
199 line = (data & mask) <<8;
200 break;
201 case ITE_GPIO_PORTC:
202 line = (data & mask) <<16;
203 break;
204 }
205 for (i=MAX_GPIO_LINE-1; i >= 0; i--) {
206 if ( (line) & (1 << i))
207 break;
208 }
209
210 DEB(printk("wait device=0x%d mask=0x%x data=0x%x index %d\n",
211 device, mask, data, i));
212
213 if (line & ~(1<<i))
214 return -EFAULT;
215
216 if (ite_gpio_irq_pending[i]==1)
217 return -EFAULT;
218
219 save_flags (flags);
220 cli();
221 ite_gpio_irq_pending[i] = 1;
222 ret = interruptible_sleep_on_timeout(&ite_gpio_wait[i], 3*HZ);
223 restore_flags (flags);
224 ite_gpio_irq_pending[i] = 0;
225
226 return ret;
227}
228
229EXPORT_SYMBOL(ite_gpio_in);
230EXPORT_SYMBOL(ite_gpio_out);
231EXPORT_SYMBOL(ite_gpio_int_ctrl);
232EXPORT_SYMBOL(ite_gpio_in_status);
233EXPORT_SYMBOL(ite_gpio_out_status);
234EXPORT_SYMBOL(ite_gpio_gen_ctrl);
235EXPORT_SYMBOL(ite_gpio_int_wait);
236
237static int ite_gpio_open(struct inode *inode, struct file *file)
238{
239 return 0;
240}
241
242
243static int ite_gpio_release(struct inode *inode, struct file *file)
244{
245 return 0;
246}
247
248
249static int ite_gpio_ioctl(struct inode *inode, struct file *file,
250 unsigned int cmd, unsigned long arg)
251{
252 static struct ite_gpio_ioctl_data ioctl_data;
253
254 if (copy_from_user(&ioctl_data, (struct ite_gpio_ioctl_data *)arg,
255 sizeof(ioctl_data)))
256 return -EFAULT;
257 if ((ioctl_data.device < ITE_GPIO_PORTA) ||
258 (ioctl_data.device > ITE_GPIO_PORTC) )
259 return -EFAULT;
260
261 switch(cmd) {
262 case ITE_GPIO_IN:
263 if (ite_gpio_in(ioctl_data.device, ioctl_data.mask,
264 &ioctl_data.data))
265 return -EFAULT;
266
267 if (copy_to_user((struct ite_gpio_ioctl_data *)arg,
268 &ioctl_data, sizeof(ioctl_data)))
269 return -EFAULT;
270 break;
271
272 case ITE_GPIO_OUT:
273 return ite_gpio_out(ioctl_data.device,
274 ioctl_data.mask, ioctl_data.data);
275 break;
276
277 case ITE_GPIO_INT_CTRL:
278 return ite_gpio_int_ctrl(ioctl_data.device,
279 ioctl_data.mask, ioctl_data.data);
280 break;
281
282 case ITE_GPIO_IN_STATUS:
283 if (ite_gpio_in_status(ioctl_data.device, ioctl_data.mask,
284 &ioctl_data.data))
285 return -EFAULT;
286 if (copy_to_user((struct ite_gpio_ioctl_data *)arg,
287 &ioctl_data, sizeof(ioctl_data)))
288 return -EFAULT;
289 break;
290
291 case ITE_GPIO_OUT_STATUS:
292 return ite_gpio_out_status(ioctl_data.device,
293 ioctl_data.mask, ioctl_data.data);
294 break;
295
296 case ITE_GPIO_GEN_CTRL:
297 return ite_gpio_gen_ctrl(ioctl_data.device,
298 ioctl_data.mask, ioctl_data.data);
299 break;
300
301 case ITE_GPIO_INT_WAIT:
302 return ite_gpio_int_wait(ioctl_data.device,
303 ioctl_data.mask, ioctl_data.data);
304 break;
305
306 default:
307 return -ENOIOCTLCMD;
308
309 }
310
311 return 0;
312}
313
314static void ite_gpio_irq_handler(int this_irq, void *dev_id,
315 struct pt_regs *regs)
316{
317 int i,line;
318
319 line = ITE_GPCISR & 0x1f;
320 for (i=4; i >=0; i--) {
321 if ( line & (1 << i)) {
322 ++ite_irq_counter[i+16];
323 ite_gpio_irq_pending[i+16] = 2;
324 wake_up_interruptible(&ite_gpio_wait[i+16]);
325
326DEB(printk("interrupt 0x%x %d\n", &ite_gpio_wait[i+16], i+16));
327
328 ITE_GPCISR = ITE_GPCISR & (1<<i);
329 return;
330 }
331 }
332 line = ITE_GPBISR;
333 for (i=7; i >= 0; i--) {
334 if ( line & (1 << i)) {
335 ++ite_irq_counter[i+8];
336 ite_gpio_irq_pending[i+8] = 2;
337 wake_up_interruptible(&ite_gpio_wait[i+8]);
338
339DEB(printk("interrupt 0x%x %d\n",ITE_GPBISR, i+8));
340
341 ITE_GPBISR = ITE_GPBISR & (1<<i);
342 return;
343 }
344 }
345 line = ITE_GPAISR;
346 for (i=7; i >= 0; i--) {
347 if ( line & (1 << i)) {
348 ++ite_irq_counter[i];
349 ite_gpio_irq_pending[i] = 2;
350 wake_up_interruptible(&ite_gpio_wait[i]);
351
352DEB(printk("interrupt 0x%x %d\n",ITE_GPAISR, i));
353
354 ITE_GPAISR = ITE_GPAISR & (1<<i);
355 return;
356 }
357 }
358}
359
360static const struct file_operations ite_gpio_fops = {
361 .owner = THIS_MODULE,
362 .ioctl = ite_gpio_ioctl,
363 .open = ite_gpio_open,
364 .release = ite_gpio_release,
365};
366
367static struct miscdevice ite_gpio_miscdev = {
368 MISC_DYNAMIC_MINOR,
369 "ite_gpio",
370 &ite_gpio_fops
371};
372
373int __init ite_gpio_init(void)
374{
375 int i;
376
377 if (misc_register(&ite_gpio_miscdev))
378 return -ENODEV;
379
380 if (!request_region(ite_gpio_base, 0x1c, "ITE GPIO"))
381 {
382 misc_deregister(&ite_gpio_miscdev);
383 return -EIO;
384 }
385
386 /* initialize registers */
387 ITE_GPACR = 0xffff;
388 ITE_GPBCR = 0xffff;
389 ITE_GPCCR = 0xffff;
390 ITE_GPAICR = 0x00ff;
391 ITE_GPBICR = 0x00ff;
392 ITE_GPCICR = 0x00ff;
393 ITE_GCR = 0;
394
395 for (i = 0; i < MAX_GPIO_LINE; i++) {
396 ite_gpio_irq_pending[i]=0;
397 init_waitqueue_head(&ite_gpio_wait[i]);
398 }
399
400 if (request_irq(ite_gpio_irq, ite_gpio_irq_handler, IRQF_SHARED, "gpio", 0) < 0) {
401 misc_deregister(&ite_gpio_miscdev);
402 release_region(ite_gpio_base, 0x1c);
403 return 0;
404 }
405
406 printk("GPIO at 0x%x (irq = %d)\n", ite_gpio_base, ite_gpio_irq);
407
408 return 0;
409}
410
411static void __exit ite_gpio_exit(void)
412{
413 misc_deregister(&ite_gpio_miscdev);
414}
415
416module_init(ite_gpio_init);
417module_exit(ite_gpio_exit);
418
419MODULE_LICENSE("GPL");
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index 3e90aac37510..7a6c1c0b7a95 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -32,6 +32,7 @@
32#include <linux/string.h> 32#include <linux/string.h>
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/irq.h>
35 36
36#include <linux/kbd_kern.h> 37#include <linux/kbd_kern.h>
37#include <linux/kbd_diacr.h> 38#include <linux/kbd_diacr.h>
@@ -77,7 +78,7 @@ void compute_shiftstate(void);
77 k_slock, k_dead2, k_brl, k_ignore 78 k_slock, k_dead2, k_brl, k_ignore
78 79
79typedef void (k_handler_fn)(struct vc_data *vc, unsigned char value, 80typedef void (k_handler_fn)(struct vc_data *vc, unsigned char value,
80 char up_flag, struct pt_regs *regs); 81 char up_flag);
81static k_handler_fn K_HANDLERS; 82static k_handler_fn K_HANDLERS;
82static k_handler_fn *k_handler[16] = { K_HANDLERS }; 83static k_handler_fn *k_handler[16] = { K_HANDLERS };
83 84
@@ -88,7 +89,7 @@ static k_handler_fn *k_handler[16] = { K_HANDLERS };
88 fn_boot_it, fn_caps_on, fn_compose, fn_SAK,\ 89 fn_boot_it, fn_caps_on, fn_compose, fn_SAK,\
89 fn_dec_console, fn_inc_console, fn_spawn_con, fn_bare_num 90 fn_dec_console, fn_inc_console, fn_spawn_con, fn_bare_num
90 91
91typedef void (fn_handler_fn)(struct vc_data *vc, struct pt_regs *regs); 92typedef void (fn_handler_fn)(struct vc_data *vc);
92static fn_handler_fn FN_HANDLERS; 93static fn_handler_fn FN_HANDLERS;
93static fn_handler_fn *fn_handler[] = { FN_HANDLERS }; 94static fn_handler_fn *fn_handler[] = { FN_HANDLERS };
94 95
@@ -108,7 +109,11 @@ const int NR_TYPES = ARRAY_SIZE(max_vals);
108struct kbd_struct kbd_table[MAX_NR_CONSOLES]; 109struct kbd_struct kbd_table[MAX_NR_CONSOLES];
109static struct kbd_struct *kbd = kbd_table; 110static struct kbd_struct *kbd = kbd_table;
110 111
111int spawnpid, spawnsig; 112struct vt_spawn_console vt_spawn_con = {
113 .lock = SPIN_LOCK_UNLOCKED,
114 .pid = NULL,
115 .sig = 0,
116};
112 117
113/* 118/*
114 * Variables exported for vt.c 119 * Variables exported for vt.c
@@ -424,7 +429,7 @@ static unsigned int handle_diacr(struct vc_data *vc, unsigned int ch)
424/* 429/*
425 * Special function handlers 430 * Special function handlers
426 */ 431 */
427static void fn_enter(struct vc_data *vc, struct pt_regs *regs) 432static void fn_enter(struct vc_data *vc)
428{ 433{
429 if (diacr) { 434 if (diacr) {
430 if (kbd->kbdmode == VC_UNICODE) 435 if (kbd->kbdmode == VC_UNICODE)
@@ -438,27 +443,28 @@ static void fn_enter(struct vc_data *vc, struct pt_regs *regs)
438 put_queue(vc, 10); 443 put_queue(vc, 10);
439} 444}
440 445
441static void fn_caps_toggle(struct vc_data *vc, struct pt_regs *regs) 446static void fn_caps_toggle(struct vc_data *vc)
442{ 447{
443 if (rep) 448 if (rep)
444 return; 449 return;
445 chg_vc_kbd_led(kbd, VC_CAPSLOCK); 450 chg_vc_kbd_led(kbd, VC_CAPSLOCK);
446} 451}
447 452
448static void fn_caps_on(struct vc_data *vc, struct pt_regs *regs) 453static void fn_caps_on(struct vc_data *vc)
449{ 454{
450 if (rep) 455 if (rep)
451 return; 456 return;
452 set_vc_kbd_led(kbd, VC_CAPSLOCK); 457 set_vc_kbd_led(kbd, VC_CAPSLOCK);
453} 458}
454 459
455static void fn_show_ptregs(struct vc_data *vc, struct pt_regs *regs) 460static void fn_show_ptregs(struct vc_data *vc)
456{ 461{
462 struct pt_regs *regs = get_irq_regs();
457 if (regs) 463 if (regs)
458 show_regs(regs); 464 show_regs(regs);
459} 465}
460 466
461static void fn_hold(struct vc_data *vc, struct pt_regs *regs) 467static void fn_hold(struct vc_data *vc)
462{ 468{
463 struct tty_struct *tty = vc->vc_tty; 469 struct tty_struct *tty = vc->vc_tty;
464 470
@@ -476,12 +482,12 @@ static void fn_hold(struct vc_data *vc, struct pt_regs *regs)
476 stop_tty(tty); 482 stop_tty(tty);
477} 483}
478 484
479static void fn_num(struct vc_data *vc, struct pt_regs *regs) 485static void fn_num(struct vc_data *vc)
480{ 486{
481 if (vc_kbd_mode(kbd,VC_APPLIC)) 487 if (vc_kbd_mode(kbd,VC_APPLIC))
482 applkey(vc, 'P', 1); 488 applkey(vc, 'P', 1);
483 else 489 else
484 fn_bare_num(vc, regs); 490 fn_bare_num(vc);
485} 491}
486 492
487/* 493/*
@@ -490,19 +496,19 @@ static void fn_num(struct vc_data *vc, struct pt_regs *regs)
490 * Bind this to NumLock if you prefer that the NumLock key always 496 * Bind this to NumLock if you prefer that the NumLock key always
491 * changes the NumLock flag. 497 * changes the NumLock flag.
492 */ 498 */
493static void fn_bare_num(struct vc_data *vc, struct pt_regs *regs) 499static void fn_bare_num(struct vc_data *vc)
494{ 500{
495 if (!rep) 501 if (!rep)
496 chg_vc_kbd_led(kbd, VC_NUMLOCK); 502 chg_vc_kbd_led(kbd, VC_NUMLOCK);
497} 503}
498 504
499static void fn_lastcons(struct vc_data *vc, struct pt_regs *regs) 505static void fn_lastcons(struct vc_data *vc)
500{ 506{
501 /* switch to the last used console, ChN */ 507 /* switch to the last used console, ChN */
502 set_console(last_console); 508 set_console(last_console);
503} 509}
504 510
505static void fn_dec_console(struct vc_data *vc, struct pt_regs *regs) 511static void fn_dec_console(struct vc_data *vc)
506{ 512{
507 int i, cur = fg_console; 513 int i, cur = fg_console;
508 514
@@ -519,7 +525,7 @@ static void fn_dec_console(struct vc_data *vc, struct pt_regs *regs)
519 set_console(i); 525 set_console(i);
520} 526}
521 527
522static void fn_inc_console(struct vc_data *vc, struct pt_regs *regs) 528static void fn_inc_console(struct vc_data *vc)
523{ 529{
524 int i, cur = fg_console; 530 int i, cur = fg_console;
525 531
@@ -536,7 +542,7 @@ static void fn_inc_console(struct vc_data *vc, struct pt_regs *regs)
536 set_console(i); 542 set_console(i);
537} 543}
538 544
539static void fn_send_intr(struct vc_data *vc, struct pt_regs *regs) 545static void fn_send_intr(struct vc_data *vc)
540{ 546{
541 struct tty_struct *tty = vc->vc_tty; 547 struct tty_struct *tty = vc->vc_tty;
542 548
@@ -546,44 +552,48 @@ static void fn_send_intr(struct vc_data *vc, struct pt_regs *regs)
546 con_schedule_flip(tty); 552 con_schedule_flip(tty);
547} 553}
548 554
549static void fn_scroll_forw(struct vc_data *vc, struct pt_regs *regs) 555static void fn_scroll_forw(struct vc_data *vc)
550{ 556{
551 scrollfront(vc, 0); 557 scrollfront(vc, 0);
552} 558}
553 559
554static void fn_scroll_back(struct vc_data *vc, struct pt_regs *regs) 560static void fn_scroll_back(struct vc_data *vc)
555{ 561{
556 scrollback(vc, 0); 562 scrollback(vc, 0);
557} 563}
558 564
559static void fn_show_mem(struct vc_data *vc, struct pt_regs *regs) 565static void fn_show_mem(struct vc_data *vc)
560{ 566{
561 show_mem(); 567 show_mem();
562} 568}
563 569
564static void fn_show_state(struct vc_data *vc, struct pt_regs *regs) 570static void fn_show_state(struct vc_data *vc)
565{ 571{
566 show_state(); 572 show_state();
567} 573}
568 574
569static void fn_boot_it(struct vc_data *vc, struct pt_regs *regs) 575static void fn_boot_it(struct vc_data *vc)
570{ 576{
571 ctrl_alt_del(); 577 ctrl_alt_del();
572} 578}
573 579
574static void fn_compose(struct vc_data *vc, struct pt_regs *regs) 580static void fn_compose(struct vc_data *vc)
575{ 581{
576 dead_key_next = 1; 582 dead_key_next = 1;
577} 583}
578 584
579static void fn_spawn_con(struct vc_data *vc, struct pt_regs *regs) 585static void fn_spawn_con(struct vc_data *vc)
580{ 586{
581 if (spawnpid) 587 spin_lock(&vt_spawn_con.lock);
582 if (kill_proc(spawnpid, spawnsig, 1)) 588 if (vt_spawn_con.pid)
583 spawnpid = 0; 589 if (kill_pid(vt_spawn_con.pid, vt_spawn_con.sig, 1)) {
590 put_pid(vt_spawn_con.pid);
591 vt_spawn_con.pid = NULL;
592 }
593 spin_unlock(&vt_spawn_con.lock);
584} 594}
585 595
586static void fn_SAK(struct vc_data *vc, struct pt_regs *regs) 596static void fn_SAK(struct vc_data *vc)
587{ 597{
588 struct tty_struct *tty = vc->vc_tty; 598 struct tty_struct *tty = vc->vc_tty;
589 599
@@ -596,7 +606,7 @@ static void fn_SAK(struct vc_data *vc, struct pt_regs *regs)
596 reset_vc(vc); 606 reset_vc(vc);
597} 607}
598 608
599static void fn_null(struct vc_data *vc, struct pt_regs *regs) 609static void fn_null(struct vc_data *vc)
600{ 610{
601 compute_shiftstate(); 611 compute_shiftstate();
602} 612}
@@ -604,11 +614,11 @@ static void fn_null(struct vc_data *vc, struct pt_regs *regs)
604/* 614/*
605 * Special key handlers 615 * Special key handlers
606 */ 616 */
607static void k_ignore(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 617static void k_ignore(struct vc_data *vc, unsigned char value, char up_flag)
608{ 618{
609} 619}
610 620
611static void k_spec(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 621static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
612{ 622{
613 if (up_flag) 623 if (up_flag)
614 return; 624 return;
@@ -618,15 +628,15 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag, struct
618 kbd->kbdmode == VC_MEDIUMRAW) && 628 kbd->kbdmode == VC_MEDIUMRAW) &&
619 value != KVAL(K_SAK)) 629 value != KVAL(K_SAK))
620 return; /* SAK is allowed even in raw mode */ 630 return; /* SAK is allowed even in raw mode */
621 fn_handler[value](vc, regs); 631 fn_handler[value](vc);
622} 632}
623 633
624static void k_lowercase(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 634static void k_lowercase(struct vc_data *vc, unsigned char value, char up_flag)
625{ 635{
626 printk(KERN_ERR "keyboard.c: k_lowercase was called - impossible\n"); 636 printk(KERN_ERR "keyboard.c: k_lowercase was called - impossible\n");
627} 637}
628 638
629static void k_unicode(struct vc_data *vc, unsigned int value, char up_flag, struct pt_regs *regs) 639static void k_unicode(struct vc_data *vc, unsigned int value, char up_flag)
630{ 640{
631 if (up_flag) 641 if (up_flag)
632 return; /* no action, if this is a key release */ 642 return; /* no action, if this is a key release */
@@ -650,41 +660,41 @@ static void k_unicode(struct vc_data *vc, unsigned int value, char up_flag, stru
650 * dead keys modifying the same character. Very useful 660 * dead keys modifying the same character. Very useful
651 * for Vietnamese. 661 * for Vietnamese.
652 */ 662 */
653static void k_deadunicode(struct vc_data *vc, unsigned int value, char up_flag, struct pt_regs *regs) 663static void k_deadunicode(struct vc_data *vc, unsigned int value, char up_flag)
654{ 664{
655 if (up_flag) 665 if (up_flag)
656 return; 666 return;
657 diacr = (diacr ? handle_diacr(vc, value) : value); 667 diacr = (diacr ? handle_diacr(vc, value) : value);
658} 668}
659 669
660static void k_self(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 670static void k_self(struct vc_data *vc, unsigned char value, char up_flag)
661{ 671{
662 k_unicode(vc, value, up_flag, regs); 672 k_unicode(vc, value, up_flag);
663} 673}
664 674
665static void k_dead2(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 675static void k_dead2(struct vc_data *vc, unsigned char value, char up_flag)
666{ 676{
667 k_deadunicode(vc, value, up_flag, regs); 677 k_deadunicode(vc, value, up_flag);
668} 678}
669 679
670/* 680/*
671 * Obsolete - for backwards compatibility only 681 * Obsolete - for backwards compatibility only
672 */ 682 */
673static void k_dead(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 683static void k_dead(struct vc_data *vc, unsigned char value, char up_flag)
674{ 684{
675 static const unsigned char ret_diacr[NR_DEAD] = {'`', '\'', '^', '~', '"', ',' }; 685 static const unsigned char ret_diacr[NR_DEAD] = {'`', '\'', '^', '~', '"', ',' };
676 value = ret_diacr[value]; 686 value = ret_diacr[value];
677 k_deadunicode(vc, value, up_flag, regs); 687 k_deadunicode(vc, value, up_flag);
678} 688}
679 689
680static void k_cons(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 690static void k_cons(struct vc_data *vc, unsigned char value, char up_flag)
681{ 691{
682 if (up_flag) 692 if (up_flag)
683 return; 693 return;
684 set_console(value); 694 set_console(value);
685} 695}
686 696
687static void k_fn(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 697static void k_fn(struct vc_data *vc, unsigned char value, char up_flag)
688{ 698{
689 unsigned v; 699 unsigned v;
690 700
@@ -698,16 +708,16 @@ static void k_fn(struct vc_data *vc, unsigned char value, char up_flag, struct p
698 printk(KERN_ERR "k_fn called with value=%d\n", value); 708 printk(KERN_ERR "k_fn called with value=%d\n", value);
699} 709}
700 710
701static void k_cur(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 711static void k_cur(struct vc_data *vc, unsigned char value, char up_flag)
702{ 712{
703 static const char *cur_chars = "BDCA"; 713 static const char cur_chars[] = "BDCA";
704 714
705 if (up_flag) 715 if (up_flag)
706 return; 716 return;
707 applkey(vc, cur_chars[value], vc_kbd_mode(kbd, VC_CKMODE)); 717 applkey(vc, cur_chars[value], vc_kbd_mode(kbd, VC_CKMODE));
708} 718}
709 719
710static void k_pad(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 720static void k_pad(struct vc_data *vc, unsigned char value, char up_flag)
711{ 721{
712 static const char pad_chars[] = "0123456789+-*/\015,.?()#"; 722 static const char pad_chars[] = "0123456789+-*/\015,.?()#";
713 static const char app_map[] = "pqrstuvwxylSRQMnnmPQS"; 723 static const char app_map[] = "pqrstuvwxylSRQMnnmPQS";
@@ -725,34 +735,34 @@ static void k_pad(struct vc_data *vc, unsigned char value, char up_flag, struct
725 switch (value) { 735 switch (value) {
726 case KVAL(K_PCOMMA): 736 case KVAL(K_PCOMMA):
727 case KVAL(K_PDOT): 737 case KVAL(K_PDOT):
728 k_fn(vc, KVAL(K_REMOVE), 0, regs); 738 k_fn(vc, KVAL(K_REMOVE), 0);
729 return; 739 return;
730 case KVAL(K_P0): 740 case KVAL(K_P0):
731 k_fn(vc, KVAL(K_INSERT), 0, regs); 741 k_fn(vc, KVAL(K_INSERT), 0);
732 return; 742 return;
733 case KVAL(K_P1): 743 case KVAL(K_P1):
734 k_fn(vc, KVAL(K_SELECT), 0, regs); 744 k_fn(vc, KVAL(K_SELECT), 0);
735 return; 745 return;
736 case KVAL(K_P2): 746 case KVAL(K_P2):
737 k_cur(vc, KVAL(K_DOWN), 0, regs); 747 k_cur(vc, KVAL(K_DOWN), 0);
738 return; 748 return;
739 case KVAL(K_P3): 749 case KVAL(K_P3):
740 k_fn(vc, KVAL(K_PGDN), 0, regs); 750 k_fn(vc, KVAL(K_PGDN), 0);
741 return; 751 return;
742 case KVAL(K_P4): 752 case KVAL(K_P4):
743 k_cur(vc, KVAL(K_LEFT), 0, regs); 753 k_cur(vc, KVAL(K_LEFT), 0);
744 return; 754 return;
745 case KVAL(K_P6): 755 case KVAL(K_P6):
746 k_cur(vc, KVAL(K_RIGHT), 0, regs); 756 k_cur(vc, KVAL(K_RIGHT), 0);
747 return; 757 return;
748 case KVAL(K_P7): 758 case KVAL(K_P7):
749 k_fn(vc, KVAL(K_FIND), 0, regs); 759 k_fn(vc, KVAL(K_FIND), 0);
750 return; 760 return;
751 case KVAL(K_P8): 761 case KVAL(K_P8):
752 k_cur(vc, KVAL(K_UP), 0, regs); 762 k_cur(vc, KVAL(K_UP), 0);
753 return; 763 return;
754 case KVAL(K_P9): 764 case KVAL(K_P9):
755 k_fn(vc, KVAL(K_PGUP), 0, regs); 765 k_fn(vc, KVAL(K_PGUP), 0);
756 return; 766 return;
757 case KVAL(K_P5): 767 case KVAL(K_P5):
758 applkey(vc, 'G', vc_kbd_mode(kbd, VC_APPLIC)); 768 applkey(vc, 'G', vc_kbd_mode(kbd, VC_APPLIC));
@@ -764,7 +774,7 @@ static void k_pad(struct vc_data *vc, unsigned char value, char up_flag, struct
764 put_queue(vc, 10); 774 put_queue(vc, 10);
765} 775}
766 776
767static void k_shift(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 777static void k_shift(struct vc_data *vc, unsigned char value, char up_flag)
768{ 778{
769 int old_state = shift_state; 779 int old_state = shift_state;
770 780
@@ -805,7 +815,7 @@ static void k_shift(struct vc_data *vc, unsigned char value, char up_flag, struc
805 } 815 }
806} 816}
807 817
808static void k_meta(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 818static void k_meta(struct vc_data *vc, unsigned char value, char up_flag)
809{ 819{
810 if (up_flag) 820 if (up_flag)
811 return; 821 return;
@@ -817,7 +827,7 @@ static void k_meta(struct vc_data *vc, unsigned char value, char up_flag, struct
817 put_queue(vc, value | 0x80); 827 put_queue(vc, value | 0x80);
818} 828}
819 829
820static void k_ascii(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 830static void k_ascii(struct vc_data *vc, unsigned char value, char up_flag)
821{ 831{
822 int base; 832 int base;
823 833
@@ -839,16 +849,16 @@ static void k_ascii(struct vc_data *vc, unsigned char value, char up_flag, struc
839 npadch = npadch * base + value; 849 npadch = npadch * base + value;
840} 850}
841 851
842static void k_lock(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 852static void k_lock(struct vc_data *vc, unsigned char value, char up_flag)
843{ 853{
844 if (up_flag || rep) 854 if (up_flag || rep)
845 return; 855 return;
846 chg_vc_kbd_lock(kbd, value); 856 chg_vc_kbd_lock(kbd, value);
847} 857}
848 858
849static void k_slock(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 859static void k_slock(struct vc_data *vc, unsigned char value, char up_flag)
850{ 860{
851 k_shift(vc, value, up_flag, regs); 861 k_shift(vc, value, up_flag);
852 if (up_flag || rep) 862 if (up_flag || rep)
853 return; 863 return;
854 chg_vc_kbd_slock(kbd, value); 864 chg_vc_kbd_slock(kbd, value);
@@ -868,25 +878,25 @@ static unsigned brl_nbchords = 1;
868MODULE_PARM_DESC(brl_nbchords, "Number of chords that produce a braille pattern (0 for dead chords)"); 878MODULE_PARM_DESC(brl_nbchords, "Number of chords that produce a braille pattern (0 for dead chords)");
869module_param(brl_nbchords, uint, 0644); 879module_param(brl_nbchords, uint, 0644);
870 880
871static void k_brlcommit(struct vc_data *vc, unsigned int pattern, char up_flag, struct pt_regs *regs) 881static void k_brlcommit(struct vc_data *vc, unsigned int pattern, char up_flag)
872{ 882{
873 static unsigned long chords; 883 static unsigned long chords;
874 static unsigned committed; 884 static unsigned committed;
875 885
876 if (!brl_nbchords) 886 if (!brl_nbchords)
877 k_deadunicode(vc, BRL_UC_ROW | pattern, up_flag, regs); 887 k_deadunicode(vc, BRL_UC_ROW | pattern, up_flag);
878 else { 888 else {
879 committed |= pattern; 889 committed |= pattern;
880 chords++; 890 chords++;
881 if (chords == brl_nbchords) { 891 if (chords == brl_nbchords) {
882 k_unicode(vc, BRL_UC_ROW | committed, up_flag, regs); 892 k_unicode(vc, BRL_UC_ROW | committed, up_flag);
883 chords = 0; 893 chords = 0;
884 committed = 0; 894 committed = 0;
885 } 895 }
886 } 896 }
887} 897}
888 898
889static void k_brl(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 899static void k_brl(struct vc_data *vc, unsigned char value, char up_flag)
890{ 900{
891 static unsigned pressed,committing; 901 static unsigned pressed,committing;
892 static unsigned long releasestart; 902 static unsigned long releasestart;
@@ -898,7 +908,7 @@ static void k_brl(struct vc_data *vc, unsigned char value, char up_flag, struct
898 } 908 }
899 909
900 if (!value) { 910 if (!value) {
901 k_unicode(vc, BRL_UC_ROW, up_flag, regs); 911 k_unicode(vc, BRL_UC_ROW, up_flag);
902 return; 912 return;
903 } 913 }
904 914
@@ -915,13 +925,13 @@ static void k_brl(struct vc_data *vc, unsigned char value, char up_flag, struct
915 pressed &= ~(1 << (value - 1)); 925 pressed &= ~(1 << (value - 1));
916 if (!pressed) { 926 if (!pressed) {
917 if (committing) { 927 if (committing) {
918 k_brlcommit(vc, committing, 0, regs); 928 k_brlcommit(vc, committing, 0);
919 committing = 0; 929 committing = 0;
920 } 930 }
921 } 931 }
922 } else { 932 } else {
923 if (committing) { 933 if (committing) {
924 k_brlcommit(vc, committing, 0, regs); 934 k_brlcommit(vc, committing, 0);
925 committing = 0; 935 committing = 0;
926 } 936 }
927 pressed &= ~(1 << (value - 1)); 937 pressed &= ~(1 << (value - 1));
@@ -1125,8 +1135,7 @@ static void kbd_rawcode(unsigned char data)
1125 put_queue(vc, data); 1135 put_queue(vc, data);
1126} 1136}
1127 1137
1128static void kbd_keycode(unsigned int keycode, int down, 1138static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
1129 int hw_raw, struct pt_regs *regs)
1130{ 1139{
1131 struct vc_data *vc = vc_cons[fg_console].d; 1140 struct vc_data *vc = vc_cons[fg_console].d;
1132 unsigned short keysym, *key_map; 1141 unsigned short keysym, *key_map;
@@ -1173,7 +1182,7 @@ static void kbd_keycode(unsigned int keycode, int down,
1173 if (sysrq_down && !down && keycode == sysrq_alt_use) 1182 if (sysrq_down && !down && keycode == sysrq_alt_use)
1174 sysrq_down = 0; 1183 sysrq_down = 0;
1175 if (sysrq_down && down && !rep) { 1184 if (sysrq_down && down && !rep) {
1176 handle_sysrq(kbd_sysrq_xlate[keycode], regs, tty); 1185 handle_sysrq(kbd_sysrq_xlate[keycode], tty);
1177 return; 1186 return;
1178 } 1187 }
1179#endif 1188#endif
@@ -1259,7 +1268,7 @@ static void kbd_keycode(unsigned int keycode, int down,
1259 } 1268 }
1260 } 1269 }
1261 1270
1262 (*k_handler[type])(vc, keysym & 0xff, !down, regs); 1271 (*k_handler[type])(vc, keysym & 0xff, !down);
1263 1272
1264 if (type != KT_SLOCK) 1273 if (type != KT_SLOCK)
1265 kbd->slockstate = 0; 1274 kbd->slockstate = 0;
@@ -1271,7 +1280,7 @@ static void kbd_event(struct input_handle *handle, unsigned int event_type,
1271 if (event_type == EV_MSC && event_code == MSC_RAW && HW_RAW(handle->dev)) 1280 if (event_type == EV_MSC && event_code == MSC_RAW && HW_RAW(handle->dev))
1272 kbd_rawcode(value); 1281 kbd_rawcode(value);
1273 if (event_type == EV_KEY) 1282 if (event_type == EV_KEY)
1274 kbd_keycode(event_code, value, HW_RAW(handle->dev), handle->dev->regs); 1283 kbd_keycode(event_code, value, HW_RAW(handle->dev));
1275 tasklet_schedule(&keyboard_tasklet); 1284 tasklet_schedule(&keyboard_tasklet);
1276 do_poke_blanked_console = 1; 1285 do_poke_blanked_console = 1;
1277 schedule_console_callback(); 1286 schedule_console_callback();
@@ -1285,7 +1294,7 @@ static void kbd_event(struct input_handle *handle, unsigned int event_type,
1285 */ 1294 */
1286static struct input_handle *kbd_connect(struct input_handler *handler, 1295static struct input_handle *kbd_connect(struct input_handler *handler,
1287 struct input_dev *dev, 1296 struct input_dev *dev,
1288 struct input_device_id *id) 1297 const struct input_device_id *id)
1289{ 1298{
1290 struct input_handle *handle; 1299 struct input_handle *handle;
1291 int i; 1300 int i;
@@ -1334,7 +1343,7 @@ static void kbd_start(struct input_handle *handle)
1334 tasklet_enable(&keyboard_tasklet); 1343 tasklet_enable(&keyboard_tasklet);
1335} 1344}
1336 1345
1337static struct input_device_id kbd_ids[] = { 1346static const struct input_device_id kbd_ids[] = {
1338 { 1347 {
1339 .flags = INPUT_DEVICE_ID_MATCH_EVBIT, 1348 .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
1340 .evbit = { BIT(EV_KEY) }, 1349 .evbit = { BIT(EV_KEY) },
@@ -1362,6 +1371,7 @@ static struct input_handler kbd_handler = {
1362int __init kbd_init(void) 1371int __init kbd_init(void)
1363{ 1372{
1364 int i; 1373 int i;
1374 int error;
1365 1375
1366 for (i = 0; i < MAX_NR_CONSOLES; i++) { 1376 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1367 kbd_table[i].ledflagstate = KBD_DEFLEDS; 1377 kbd_table[i].ledflagstate = KBD_DEFLEDS;
@@ -1373,7 +1383,9 @@ int __init kbd_init(void)
1373 kbd_table[i].kbdmode = VC_XLATE; 1383 kbd_table[i].kbdmode = VC_XLATE;
1374 } 1384 }
1375 1385
1376 input_register_handler(&kbd_handler); 1386 error = input_register_handler(&kbd_handler);
1387 if (error)
1388 return error;
1377 1389
1378 tasklet_enable(&keyboard_tasklet); 1390 tasklet_enable(&keyboard_tasklet);
1379 tasklet_schedule(&keyboard_tasklet); 1391 tasklet_schedule(&keyboard_tasklet);
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index f875fda3b089..b70b5388b5a8 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -296,7 +296,7 @@ static int lp_wait_ready(int minor, int nonblock)
296static ssize_t lp_write(struct file * file, const char __user * buf, 296static ssize_t lp_write(struct file * file, const char __user * buf,
297 size_t count, loff_t *ppos) 297 size_t count, loff_t *ppos)
298{ 298{
299 unsigned int minor = iminor(file->f_dentry->d_inode); 299 unsigned int minor = iminor(file->f_path.dentry->d_inode);
300 struct parport *port = lp_table[minor].dev->port; 300 struct parport *port = lp_table[minor].dev->port;
301 char *kbuf = lp_table[minor].lp_buffer; 301 char *kbuf = lp_table[minor].lp_buffer;
302 ssize_t retv = 0; 302 ssize_t retv = 0;
@@ -415,7 +415,7 @@ static ssize_t lp_read(struct file * file, char __user * buf,
415 size_t count, loff_t *ppos) 415 size_t count, loff_t *ppos)
416{ 416{
417 DEFINE_WAIT(wait); 417 DEFINE_WAIT(wait);
418 unsigned int minor=iminor(file->f_dentry->d_inode); 418 unsigned int minor=iminor(file->f_path.dentry->d_inode);
419 struct parport *port = lp_table[minor].dev->port; 419 struct parport *port = lp_table[minor].dev->port;
420 ssize_t retval = 0; 420 ssize_t retval = 0;
421 char *kbuf = lp_table[minor].lp_buffer; 421 char *kbuf = lp_table[minor].lp_buffer;
@@ -906,7 +906,7 @@ static int __init lp_init (void)
906 lp_class = class_create(THIS_MODULE, "printer"); 906 lp_class = class_create(THIS_MODULE, "printer");
907 if (IS_ERR(lp_class)) { 907 if (IS_ERR(lp_class)) {
908 err = PTR_ERR(lp_class); 908 err = PTR_ERR(lp_class);
909 goto out_devfs; 909 goto out_reg;
910 } 910 }
911 911
912 if (parport_register_driver (&lp_driver)) { 912 if (parport_register_driver (&lp_driver)) {
@@ -927,7 +927,7 @@ static int __init lp_init (void)
927 927
928out_class: 928out_class:
929 class_destroy(lp_class); 929 class_destroy(lp_class);
930out_devfs: 930out_reg:
931 unregister_chrdev(LP_MAJOR, "lp"); 931 unregister_chrdev(LP_MAJOR, "lp");
932 return err; 932 return err;
933} 933}
diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
index 0385650f6077..0afb7ba999cf 100644
--- a/drivers/char/mbcs.c
+++ b/drivers/char/mbcs.c
@@ -22,6 +22,7 @@
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/device.h> 23#include <linux/device.h>
24#include <linux/mm.h> 24#include <linux/mm.h>
25#include <linux/fs.h>
25#include <linux/uio.h> 26#include <linux/uio.h>
26#include <asm/io.h> 27#include <asm/io.h>
27#include <asm/uaccess.h> 28#include <asm/uaccess.h>
@@ -447,15 +448,15 @@ loff_t mbcs_sram_llseek(struct file * filp, loff_t off, int whence)
447 loff_t newpos; 448 loff_t newpos;
448 449
449 switch (whence) { 450 switch (whence) {
450 case 0: /* SEEK_SET */ 451 case SEEK_SET:
451 newpos = off; 452 newpos = off;
452 break; 453 break;
453 454
454 case 1: /* SEEK_CUR */ 455 case SEEK_CUR:
455 newpos = filp->f_pos + off; 456 newpos = filp->f_pos + off;
456 break; 457 break;
457 458
458 case 2: /* SEEK_END */ 459 case SEEK_END:
459 newpos = MBCS_SRAM_SIZE + off; 460 newpos = MBCS_SRAM_SIZE + off;
460 break; 461 break;
461 462
@@ -515,11 +516,10 @@ int mbcs_gscr_mmap(struct file *fp, struct vm_area_struct *vma)
515 * mbcs_completion_intr_handler - Primary completion handler. 516 * mbcs_completion_intr_handler - Primary completion handler.
516 * @irq: irq 517 * @irq: irq
517 * @arg: soft struct for device 518 * @arg: soft struct for device
518 * @ep: regs
519 * 519 *
520 */ 520 */
521static irqreturn_t 521static irqreturn_t
522mbcs_completion_intr_handler(int irq, void *arg, struct pt_regs *ep) 522mbcs_completion_intr_handler(int irq, void *arg)
523{ 523{
524 struct mbcs_soft *soft = (struct mbcs_soft *)arg; 524 struct mbcs_soft *soft = (struct mbcs_soft *)arg;
525 void *mmr_base; 525 void *mmr_base;
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 917b20402664..4f1813e04754 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -26,6 +26,7 @@
26#include <linux/backing-dev.h> 26#include <linux/backing-dev.h>
27#include <linux/bootmem.h> 27#include <linux/bootmem.h>
28#include <linux/pipe_fs_i.h> 28#include <linux/pipe_fs_i.h>
29#include <linux/pfn.h>
29 30
30#include <asm/uaccess.h> 31#include <asm/uaccess.h>
31#include <asm/io.h> 32#include <asm/io.h>
@@ -238,6 +239,32 @@ static pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
238} 239}
239#endif 240#endif
240 241
242#ifndef CONFIG_MMU
243static unsigned long get_unmapped_area_mem(struct file *file,
244 unsigned long addr,
245 unsigned long len,
246 unsigned long pgoff,
247 unsigned long flags)
248{
249 if (!valid_mmap_phys_addr_range(pgoff, len))
250 return (unsigned long) -EINVAL;
251 return pgoff;
252}
253
254/* can't do an in-place private mapping if there's no MMU */
255static inline int private_mapping_ok(struct vm_area_struct *vma)
256{
257 return vma->vm_flags & VM_MAYSHARE;
258}
259#else
260#define get_unmapped_area_mem NULL
261
262static inline int private_mapping_ok(struct vm_area_struct *vma)
263{
264 return 1;
265}
266#endif
267
241static int mmap_mem(struct file * file, struct vm_area_struct * vma) 268static int mmap_mem(struct file * file, struct vm_area_struct * vma)
242{ 269{
243 size_t size = vma->vm_end - vma->vm_start; 270 size_t size = vma->vm_end - vma->vm_start;
@@ -245,6 +272,9 @@ static int mmap_mem(struct file * file, struct vm_area_struct * vma)
245 if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size)) 272 if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size))
246 return -EINVAL; 273 return -EINVAL;
247 274
275 if (!private_mapping_ok(vma))
276 return -ENOSYS;
277
248 vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff, 278 vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
249 size, 279 size,
250 vma->vm_page_prot); 280 vma->vm_page_prot);
@@ -263,8 +293,8 @@ static int mmap_kmem(struct file * file, struct vm_area_struct * vma)
263{ 293{
264 unsigned long pfn; 294 unsigned long pfn;
265 295
266 /* Turn a kernel-virtual address into a physical page frame */ 296 /* Turn a pfn offset into an absolute pfn */
267 pfn = __pa((u64)vma->vm_pgoff << PAGE_SHIFT) >> PAGE_SHIFT; 297 pfn = PFN_DOWN(virt_to_phys((void *)PAGE_OFFSET)) + vma->vm_pgoff;
268 298
269 /* 299 /*
270 * RED-PEN: on some architectures there is more mapped memory 300 * RED-PEN: on some architectures there is more mapped memory
@@ -522,7 +552,7 @@ static ssize_t write_kmem(struct file * file, const char __user * buf,
522 return virtr + wrote; 552 return virtr + wrote;
523} 553}
524 554
525#if defined(CONFIG_ISA) || !defined(__mc68000__) 555#if (defined(CONFIG_ISA) || defined(CONFIG_PCI)) && !defined(__mc68000__)
526static ssize_t read_port(struct file * file, char __user * buf, 556static ssize_t read_port(struct file * file, char __user * buf,
527 size_t count, loff_t *ppos) 557 size_t count, loff_t *ppos)
528{ 558{
@@ -616,7 +646,8 @@ static inline size_t read_zero_pagealigned(char __user * buf, size_t size)
616 count = size; 646 count = size;
617 647
618 zap_page_range(vma, addr, count, NULL); 648 zap_page_range(vma, addr, count, NULL);
619 zeromap_page_range(vma, addr, count, PAGE_COPY); 649 if (zeromap_page_range(vma, addr, count, PAGE_COPY))
650 break;
620 651
621 size -= count; 652 size -= count;
622 buf += count; 653 buf += count;
@@ -683,11 +714,14 @@ out:
683 714
684static int mmap_zero(struct file * file, struct vm_area_struct * vma) 715static int mmap_zero(struct file * file, struct vm_area_struct * vma)
685{ 716{
717 int err;
718
686 if (vma->vm_flags & VM_SHARED) 719 if (vma->vm_flags & VM_SHARED)
687 return shmem_zero_setup(vma); 720 return shmem_zero_setup(vma);
688 if (zeromap_page_range(vma, vma->vm_start, vma->vm_end - vma->vm_start, vma->vm_page_prot)) 721 err = zeromap_page_range(vma, vma->vm_start,
689 return -EAGAIN; 722 vma->vm_end - vma->vm_start, vma->vm_page_prot);
690 return 0; 723 BUG_ON(err == -EEXIST);
724 return err;
691} 725}
692#else /* CONFIG_MMU */ 726#else /* CONFIG_MMU */
693static ssize_t read_zero(struct file * file, char * buf, 727static ssize_t read_zero(struct file * file, char * buf,
@@ -744,7 +778,7 @@ static loff_t memory_lseek(struct file * file, loff_t offset, int orig)
744{ 778{
745 loff_t ret; 779 loff_t ret;
746 780
747 mutex_lock(&file->f_dentry->d_inode->i_mutex); 781 mutex_lock(&file->f_path.dentry->d_inode->i_mutex);
748 switch (orig) { 782 switch (orig) {
749 case 0: 783 case 0:
750 file->f_pos = offset; 784 file->f_pos = offset;
@@ -759,7 +793,7 @@ static loff_t memory_lseek(struct file * file, loff_t offset, int orig)
759 default: 793 default:
760 ret = -EINVAL; 794 ret = -EINVAL;
761 } 795 }
762 mutex_unlock(&file->f_dentry->d_inode->i_mutex); 796 mutex_unlock(&file->f_path.dentry->d_inode->i_mutex);
763 return ret; 797 return ret;
764} 798}
765 799
@@ -782,6 +816,7 @@ static const struct file_operations mem_fops = {
782 .write = write_mem, 816 .write = write_mem,
783 .mmap = mmap_mem, 817 .mmap = mmap_mem,
784 .open = open_mem, 818 .open = open_mem,
819 .get_unmapped_area = get_unmapped_area_mem,
785}; 820};
786 821
787static const struct file_operations kmem_fops = { 822static const struct file_operations kmem_fops = {
@@ -790,6 +825,7 @@ static const struct file_operations kmem_fops = {
790 .write = write_kmem, 825 .write = write_kmem,
791 .mmap = mmap_kmem, 826 .mmap = mmap_kmem,
792 .open = open_kmem, 827 .open = open_kmem,
828 .get_unmapped_area = get_unmapped_area_mem,
793}; 829};
794 830
795static const struct file_operations null_fops = { 831static const struct file_operations null_fops = {
@@ -799,7 +835,7 @@ static const struct file_operations null_fops = {
799 .splice_write = splice_write_null, 835 .splice_write = splice_write_null,
800}; 836};
801 837
802#if defined(CONFIG_ISA) || !defined(__mc68000__) 838#if (defined(CONFIG_ISA) || defined(CONFIG_PCI)) && !defined(__mc68000__)
803static const struct file_operations port_fops = { 839static const struct file_operations port_fops = {
804 .llseek = memory_lseek, 840 .llseek = memory_lseek,
805 .read = read_port, 841 .read = read_port,
@@ -815,6 +851,10 @@ static const struct file_operations zero_fops = {
815 .mmap = mmap_zero, 851 .mmap = mmap_zero,
816}; 852};
817 853
854/*
855 * capabilities for /dev/zero
856 * - permits private mappings, "copies" are taken of the source of zeros
857 */
818static struct backing_dev_info zero_bdi = { 858static struct backing_dev_info zero_bdi = {
819 .capabilities = BDI_CAP_MAP_COPY, 859 .capabilities = BDI_CAP_MAP_COPY,
820}; 860};
@@ -862,14 +902,18 @@ static int memory_open(struct inode * inode, struct file * filp)
862 switch (iminor(inode)) { 902 switch (iminor(inode)) {
863 case 1: 903 case 1:
864 filp->f_op = &mem_fops; 904 filp->f_op = &mem_fops;
905 filp->f_mapping->backing_dev_info =
906 &directly_mappable_cdev_bdi;
865 break; 907 break;
866 case 2: 908 case 2:
867 filp->f_op = &kmem_fops; 909 filp->f_op = &kmem_fops;
910 filp->f_mapping->backing_dev_info =
911 &directly_mappable_cdev_bdi;
868 break; 912 break;
869 case 3: 913 case 3:
870 filp->f_op = &null_fops; 914 filp->f_op = &null_fops;
871 break; 915 break;
872#if defined(CONFIG_ISA) || !defined(__mc68000__) 916#if (defined(CONFIG_ISA) || defined(CONFIG_PCI)) && !defined(__mc68000__)
873 case 4: 917 case 4:
874 filp->f_op = &port_fops; 918 filp->f_op = &port_fops;
875 break; 919 break;
@@ -916,7 +960,7 @@ static const struct {
916 {1, "mem", S_IRUSR | S_IWUSR | S_IRGRP, &mem_fops}, 960 {1, "mem", S_IRUSR | S_IWUSR | S_IRGRP, &mem_fops},
917 {2, "kmem", S_IRUSR | S_IWUSR | S_IRGRP, &kmem_fops}, 961 {2, "kmem", S_IRUSR | S_IWUSR | S_IRGRP, &kmem_fops},
918 {3, "null", S_IRUGO | S_IWUGO, &null_fops}, 962 {3, "null", S_IRUGO | S_IWUGO, &null_fops},
919#if defined(CONFIG_ISA) || !defined(__mc68000__) 963#if (defined(CONFIG_ISA) || defined(CONFIG_PCI)) && !defined(__mc68000__)
920 {4, "port", S_IRUSR | S_IWUSR | S_IRGRP, &port_fops}, 964 {4, "port", S_IRUSR | S_IWUSR | S_IRGRP, &port_fops},
921#endif 965#endif
922 {5, "zero", S_IRUGO | S_IWUGO, &zero_fops}, 966 {5, "zero", S_IRUGO | S_IWUGO, &zero_fops},
@@ -940,10 +984,10 @@ static int __init chr_dev_init(void)
940 984
941 mem_class = class_create(THIS_MODULE, "mem"); 985 mem_class = class_create(THIS_MODULE, "mem");
942 for (i = 0; i < ARRAY_SIZE(devlist); i++) 986 for (i = 0; i < ARRAY_SIZE(devlist); i++)
943 class_device_create(mem_class, NULL, 987 device_create(mem_class, NULL,
944 MKDEV(MEM_MAJOR, devlist[i].minor), 988 MKDEV(MEM_MAJOR, devlist[i].minor),
945 NULL, devlist[i].name); 989 devlist[i].name);
946 990
947 return 0; 991 return 0;
948} 992}
949 993
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 62ebe09656e3..7e975f606924 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -169,11 +169,6 @@ fail:
169 return err; 169 return err;
170} 170}
171 171
172/*
173 * TODO for 2.7:
174 * - add a struct kref to struct miscdevice and make all usages of
175 * them dynamic.
176 */
177static struct class *misc_class; 172static struct class *misc_class;
178 173
179static const struct file_operations misc_fops = { 174static const struct file_operations misc_fops = {
@@ -204,6 +199,8 @@ int misc_register(struct miscdevice * misc)
204 dev_t dev; 199 dev_t dev;
205 int err = 0; 200 int err = 0;
206 201
202 INIT_LIST_HEAD(&misc->list);
203
207 down(&misc_sem); 204 down(&misc_sem);
208 list_for_each_entry(c, &misc_list, list) { 205 list_for_each_entry(c, &misc_list, list) {
209 if (c->minor == misc->minor) { 206 if (c->minor == misc->minor) {
@@ -228,10 +225,10 @@ int misc_register(struct miscdevice * misc)
228 misc_minors[misc->minor >> 3] |= 1 << (misc->minor & 7); 225 misc_minors[misc->minor >> 3] |= 1 << (misc->minor & 7);
229 dev = MKDEV(MISC_MAJOR, misc->minor); 226 dev = MKDEV(MISC_MAJOR, misc->minor);
230 227
231 misc->class = class_device_create(misc_class, NULL, dev, misc->dev, 228 misc->this_device = device_create(misc_class, misc->parent, dev,
232 "%s", misc->name); 229 "%s", misc->name);
233 if (IS_ERR(misc->class)) { 230 if (IS_ERR(misc->this_device)) {
234 err = PTR_ERR(misc->class); 231 err = PTR_ERR(misc->this_device);
235 goto out; 232 goto out;
236 } 233 }
237 234
@@ -264,7 +261,7 @@ int misc_deregister(struct miscdevice * misc)
264 261
265 down(&misc_sem); 262 down(&misc_sem);
266 list_del(&misc->list); 263 list_del(&misc->list);
267 class_device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor)); 264 device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor));
268 if (i < DYNAMIC_MINORS && i>0) { 265 if (i < DYNAMIC_MINORS && i>0) {
269 misc_minors[i>>3] &= ~(1 << (misc->minor & 7)); 266 misc_minors[i>>3] &= ~(1 << (misc->minor & 7));
270 } 267 }
diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 1f0f2b6dae26..c09160383a53 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -422,7 +422,6 @@ static int inline reschedule_periodic_timer(mmtimer_t *x)
422 * mmtimer_interrupt - timer interrupt handler 422 * mmtimer_interrupt - timer interrupt handler
423 * @irq: irq received 423 * @irq: irq received
424 * @dev_id: device the irq came from 424 * @dev_id: device the irq came from
425 * @regs: register state upon receipt of the interrupt
426 * 425 *
427 * Called when one of the comarators matches the counter, This 426 * Called when one of the comarators matches the counter, This
428 * routine will send signals to processes that have requested 427 * routine will send signals to processes that have requested
@@ -433,7 +432,7 @@ static int inline reschedule_periodic_timer(mmtimer_t *x)
433 * registers. 432 * registers.
434 */ 433 */
435static irqreturn_t 434static irqreturn_t
436mmtimer_interrupt(int irq, void *dev_id, struct pt_regs *regs) 435mmtimer_interrupt(int irq, void *dev_id)
437{ 436{
438 int i; 437 int i;
439 unsigned long expires = 0; 438 unsigned long expires = 0;
@@ -681,7 +680,7 @@ static int __init mmtimer_init(void)
681 if (sn_rtc_cycles_per_second < 100000) { 680 if (sn_rtc_cycles_per_second < 100000) {
682 printk(KERN_ERR "%s: unable to determine clock frequency\n", 681 printk(KERN_ERR "%s: unable to determine clock frequency\n",
683 MMTIMER_NAME); 682 MMTIMER_NAME);
684 return -1; 683 goto out1;
685 } 684 }
686 685
687 mmtimer_femtoperiod = ((unsigned long)1E15 + sn_rtc_cycles_per_second / 686 mmtimer_femtoperiod = ((unsigned long)1E15 + sn_rtc_cycles_per_second /
@@ -690,13 +689,13 @@ static int __init mmtimer_init(void)
690 if (request_irq(SGI_MMTIMER_VECTOR, mmtimer_interrupt, IRQF_PERCPU, MMTIMER_NAME, NULL)) { 689 if (request_irq(SGI_MMTIMER_VECTOR, mmtimer_interrupt, IRQF_PERCPU, MMTIMER_NAME, NULL)) {
691 printk(KERN_WARNING "%s: unable to allocate interrupt.", 690 printk(KERN_WARNING "%s: unable to allocate interrupt.",
692 MMTIMER_NAME); 691 MMTIMER_NAME);
693 return -1; 692 goto out1;
694 } 693 }
695 694
696 if (misc_register(&mmtimer_miscdev)) { 695 if (misc_register(&mmtimer_miscdev)) {
697 printk(KERN_ERR "%s: failed to register device\n", 696 printk(KERN_ERR "%s: failed to register device\n",
698 MMTIMER_NAME); 697 MMTIMER_NAME);
699 return -1; 698 goto out2;
700 } 699 }
701 700
702 /* Get max numbered node, calculate slots needed */ 701 /* Get max numbered node, calculate slots needed */
@@ -710,16 +709,18 @@ static int __init mmtimer_init(void)
710 if (timers == NULL) { 709 if (timers == NULL) {
711 printk(KERN_ERR "%s: failed to allocate memory for device\n", 710 printk(KERN_ERR "%s: failed to allocate memory for device\n",
712 MMTIMER_NAME); 711 MMTIMER_NAME);
713 return -1; 712 goto out3;
714 } 713 }
715 714
715 memset(timers,0,(sizeof(mmtimer_t *)*maxn));
716
716 /* Allocate mmtimer_t's for each online node */ 717 /* Allocate mmtimer_t's for each online node */
717 for_each_online_node(node) { 718 for_each_online_node(node) {
718 timers[node] = kmalloc_node(sizeof(mmtimer_t)*NUM_COMPARATORS, GFP_KERNEL, node); 719 timers[node] = kmalloc_node(sizeof(mmtimer_t)*NUM_COMPARATORS, GFP_KERNEL, node);
719 if (timers[node] == NULL) { 720 if (timers[node] == NULL) {
720 printk(KERN_ERR "%s: failed to allocate memory for device\n", 721 printk(KERN_ERR "%s: failed to allocate memory for device\n",
721 MMTIMER_NAME); 722 MMTIMER_NAME);
722 return -1; 723 goto out4;
723 } 724 }
724 for (i=0; i< NUM_COMPARATORS; i++) { 725 for (i=0; i< NUM_COMPARATORS; i++) {
725 mmtimer_t * base = timers[node] + i; 726 mmtimer_t * base = timers[node] + i;
@@ -740,6 +741,17 @@ static int __init mmtimer_init(void)
740 sn_rtc_cycles_per_second/(unsigned long)1E6); 741 sn_rtc_cycles_per_second/(unsigned long)1E6);
741 742
742 return 0; 743 return 0;
744
745out4:
746 for_each_online_node(node) {
747 kfree(timers[node]);
748 }
749out3:
750 misc_deregister(&mmtimer_miscdev);
751out2:
752 free_irq(SGI_MMTIMER_VECTOR, NULL);
753out1:
754 return -1;
743} 755}
744 756
745module_init(mmtimer_init); 757module_init(mmtimer_init);
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index a369dd6877d8..f391a24a1b44 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -130,6 +130,7 @@ static moxa_isa_board_conf moxa_isa_boards[] =
130typedef struct _moxa_pci_devinfo { 130typedef struct _moxa_pci_devinfo {
131 ushort busNum; 131 ushort busNum;
132 ushort devNum; 132 ushort devNum;
133 struct pci_dev *pdev;
133} moxa_pci_devinfo; 134} moxa_pci_devinfo;
134 135
135typedef struct _moxa_board_conf { 136typedef struct _moxa_board_conf {
@@ -221,7 +222,7 @@ static struct semaphore moxaBuffSem;
221/* 222/*
222 * static functions: 223 * static functions:
223 */ 224 */
224static void do_moxa_softint(void *); 225static void do_moxa_softint(struct work_struct *);
225static int moxa_open(struct tty_struct *, struct file *); 226static int moxa_open(struct tty_struct *, struct file *);
226static void moxa_close(struct tty_struct *, struct file *); 227static void moxa_close(struct tty_struct *, struct file *);
227static int moxa_write(struct tty_struct *, const unsigned char *, int); 228static int moxa_write(struct tty_struct *, const unsigned char *, int);
@@ -233,7 +234,7 @@ static void moxa_put_char(struct tty_struct *, unsigned char);
233static int moxa_ioctl(struct tty_struct *, struct file *, unsigned int, unsigned long); 234static int moxa_ioctl(struct tty_struct *, struct file *, unsigned int, unsigned long);
234static void moxa_throttle(struct tty_struct *); 235static void moxa_throttle(struct tty_struct *);
235static void moxa_unthrottle(struct tty_struct *); 236static void moxa_unthrottle(struct tty_struct *);
236static void moxa_set_termios(struct tty_struct *, struct termios *); 237static void moxa_set_termios(struct tty_struct *, struct ktermios *);
237static void moxa_stop(struct tty_struct *); 238static void moxa_stop(struct tty_struct *);
238static void moxa_start(struct tty_struct *); 239static void moxa_start(struct tty_struct *);
239static void moxa_hangup(struct tty_struct *); 240static void moxa_hangup(struct tty_struct *);
@@ -260,7 +261,7 @@ static void MoxaPortEnable(int);
260static void MoxaPortDisable(int); 261static void MoxaPortDisable(int);
261static long MoxaPortGetMaxBaud(int); 262static long MoxaPortGetMaxBaud(int);
262static long MoxaPortSetBaud(int, long); 263static long MoxaPortSetBaud(int, long);
263static int MoxaPortSetTermio(int, struct termios *); 264static int MoxaPortSetTermio(int, struct ktermios *, speed_t);
264static int MoxaPortGetLineOut(int, int *, int *); 265static int MoxaPortGetLineOut(int, int *, int *);
265static void MoxaPortLineCtrl(int, int, int); 266static void MoxaPortLineCtrl(int, int, int);
266static void MoxaPortFlowCtrl(int, int, int, int, int, int); 267static void MoxaPortFlowCtrl(int, int, int, int, int, int);
@@ -281,7 +282,7 @@ static int moxa_get_serial_info(struct moxa_str *, struct serial_struct __user *
281static int moxa_set_serial_info(struct moxa_str *, struct serial_struct __user *); 282static int moxa_set_serial_info(struct moxa_str *, struct serial_struct __user *);
282static void MoxaSetFifo(int port, int enable); 283static void MoxaSetFifo(int port, int enable);
283 284
284static struct tty_operations moxa_ops = { 285static const struct tty_operations moxa_ops = {
285 .open = moxa_open, 286 .open = moxa_open,
286 .close = moxa_close, 287 .close = moxa_close,
287 .write = moxa_write, 288 .write = moxa_write,
@@ -324,6 +325,9 @@ static int moxa_get_PCI_conf(struct pci_dev *p, int board_type, moxa_board_conf
324 board->busType = MOXA_BUS_TYPE_PCI; 325 board->busType = MOXA_BUS_TYPE_PCI;
325 board->pciInfo.busNum = p->bus->number; 326 board->pciInfo.busNum = p->bus->number;
326 board->pciInfo.devNum = p->devfn >> 3; 327 board->pciInfo.devNum = p->devfn >> 3;
328 board->pciInfo.pdev = p;
329 /* don't lose the reference in the next pci_get_device iteration */
330 pci_dev_get(p);
327 331
328 return (0); 332 return (0);
329} 333}
@@ -351,6 +355,8 @@ static int __init moxa_init(void)
351 moxaDriver->init_termios.c_oflag = 0; 355 moxaDriver->init_termios.c_oflag = 0;
352 moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; 356 moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
353 moxaDriver->init_termios.c_lflag = 0; 357 moxaDriver->init_termios.c_lflag = 0;
358 moxaDriver->init_termios.c_ispeed = 9600;
359 moxaDriver->init_termios.c_ospeed = 9600;
354 moxaDriver->flags = TTY_DRIVER_REAL_RAW; 360 moxaDriver->flags = TTY_DRIVER_REAL_RAW;
355 tty_set_operations(moxaDriver, &moxa_ops); 361 tty_set_operations(moxaDriver, &moxa_ops);
356 362
@@ -359,7 +365,7 @@ static int __init moxa_init(void)
359 for (i = 0, ch = moxaChannels; i < MAX_PORTS; i++, ch++) { 365 for (i = 0, ch = moxaChannels; i < MAX_PORTS; i++, ch++) {
360 ch->type = PORT_16550A; 366 ch->type = PORT_16550A;
361 ch->port = i; 367 ch->port = i;
362 INIT_WORK(&ch->tqueue, do_moxa_softint, ch); 368 INIT_WORK(&ch->tqueue, do_moxa_softint);
363 ch->tty = NULL; 369 ch->tty = NULL;
364 ch->close_delay = 5 * HZ / 10; 370 ch->close_delay = 5 * HZ / 10;
365 ch->closing_wait = 30 * HZ; 371 ch->closing_wait = 30 * HZ;
@@ -493,6 +499,14 @@ static void __exit moxa_exit(void)
493 if (tty_unregister_driver(moxaDriver)) 499 if (tty_unregister_driver(moxaDriver))
494 printk("Couldn't unregister MOXA Intellio family serial driver\n"); 500 printk("Couldn't unregister MOXA Intellio family serial driver\n");
495 put_tty_driver(moxaDriver); 501 put_tty_driver(moxaDriver);
502
503 for (i = 0; i < MAX_BOARDS; i++) {
504 if (moxaBaseAddr[i])
505 iounmap(moxaBaseAddr[i]);
506 if (moxa_boards[i].busType == MOXA_BUS_TYPE_PCI)
507 pci_dev_put(moxa_boards[i].pciInfo.pdev);
508 }
509
496 if (verbose) 510 if (verbose)
497 printk("Done\n"); 511 printk("Done\n");
498} 512}
@@ -500,9 +514,9 @@ static void __exit moxa_exit(void)
500module_init(moxa_init); 514module_init(moxa_init);
501module_exit(moxa_exit); 515module_exit(moxa_exit);
502 516
503static void do_moxa_softint(void *private_) 517static void do_moxa_softint(struct work_struct *work)
504{ 518{
505 struct moxa_str *ch = (struct moxa_str *) private_; 519 struct moxa_str *ch = container_of(work, struct moxa_str, tqueue);
506 struct tty_struct *tty; 520 struct tty_struct *tty;
507 521
508 if (ch && (tty = ch->tty)) { 522 if (ch && (tty = ch->tty)) {
@@ -852,7 +866,7 @@ static void moxa_unthrottle(struct tty_struct *tty)
852} 866}
853 867
854static void moxa_set_termios(struct tty_struct *tty, 868static void moxa_set_termios(struct tty_struct *tty,
855 struct termios *old_termios) 869 struct ktermios *old_termios)
856{ 870{
857 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 871 struct moxa_str *ch = (struct moxa_str *) tty->driver_data;
858 872
@@ -966,7 +980,7 @@ static void moxa_poll(unsigned long ignored)
966 980
967static void set_tty_param(struct tty_struct *tty) 981static void set_tty_param(struct tty_struct *tty)
968{ 982{
969 register struct termios *ts; 983 register struct ktermios *ts;
970 struct moxa_str *ch; 984 struct moxa_str *ch;
971 int rts, cts, txflow, rxflow, xany; 985 int rts, cts, txflow, rxflow, xany;
972 986
@@ -986,7 +1000,7 @@ static void set_tty_param(struct tty_struct *tty)
986 if (ts->c_iflag & IXANY) 1000 if (ts->c_iflag & IXANY)
987 xany = 1; 1001 xany = 1;
988 MoxaPortFlowCtrl(ch->port, rts, cts, txflow, rxflow, xany); 1002 MoxaPortFlowCtrl(ch->port, rts, cts, txflow, rxflow, xany);
989 MoxaPortSetTermio(ch->port, ts); 1003 MoxaPortSetTermio(ch->port, ts, tty_get_baud_rate(tty));
990} 1004}
991 1005
992static int block_till_ready(struct tty_struct *tty, struct file *filp, 1006static int block_till_ready(struct tty_struct *tty, struct file *filp,
@@ -1137,7 +1151,7 @@ static void shut_down(struct moxa_str *ch)
1137static void receive_data(struct moxa_str *ch) 1151static void receive_data(struct moxa_str *ch)
1138{ 1152{
1139 struct tty_struct *tp; 1153 struct tty_struct *tp;
1140 struct termios *ts; 1154 struct ktermios *ts;
1141 unsigned long flags; 1155 unsigned long flags;
1142 1156
1143 ts = NULL; 1157 ts = NULL;
@@ -1900,9 +1914,10 @@ int MoxaPortsOfCard(int cardno)
1900 * 1914 *
1901 * Function 12: Configure the port. 1915 * Function 12: Configure the port.
1902 * Syntax: 1916 * Syntax:
1903 * int MoxaPortSetTermio(int port, struct termios *termio); 1917 * int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud);
1904 * int port : port number (0 - 127) 1918 * int port : port number (0 - 127)
1905 * struct termios * termio : termio structure pointer 1919 * struct ktermios * termio : termio structure pointer
1920 * speed_t baud : baud rate
1906 * 1921 *
1907 * return: -1 : this port is invalid or termio == NULL 1922 * return: -1 : this port is invalid or termio == NULL
1908 * 0 : setting O.K. 1923 * 0 : setting O.K.
@@ -2182,11 +2197,10 @@ long MoxaPortSetBaud(int port, long baud)
2182 return (baud); 2197 return (baud);
2183} 2198}
2184 2199
2185int MoxaPortSetTermio(int port, struct termios *termio) 2200int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud)
2186{ 2201{
2187 void __iomem *ofsAddr; 2202 void __iomem *ofsAddr;
2188 tcflag_t cflag; 2203 tcflag_t cflag;
2189 long baud;
2190 tcflag_t mode = 0; 2204 tcflag_t mode = 0;
2191 2205
2192 if (moxaChkPort[port] == 0 || termio == 0) 2206 if (moxaChkPort[port] == 0 || termio == 0)
@@ -2222,77 +2236,9 @@ int MoxaPortSetTermio(int port, struct termios *termio)
2222 2236
2223 moxafunc(ofsAddr, FC_SetDataMode, (ushort) mode); 2237 moxafunc(ofsAddr, FC_SetDataMode, (ushort) mode);
2224 2238
2225 cflag &= (CBAUD | CBAUDEX);
2226#ifndef B921600
2227#define B921600 (B460800+1)
2228#endif
2229 switch (cflag) {
2230 case B921600:
2231 baud = 921600L;
2232 break;
2233 case B460800:
2234 baud = 460800L;
2235 break;
2236 case B230400:
2237 baud = 230400L;
2238 break;
2239 case B115200:
2240 baud = 115200L;
2241 break;
2242 case B57600:
2243 baud = 57600L;
2244 break;
2245 case B38400:
2246 baud = 38400L;
2247 break;
2248 case B19200:
2249 baud = 19200L;
2250 break;
2251 case B9600:
2252 baud = 9600L;
2253 break;
2254 case B4800:
2255 baud = 4800L;
2256 break;
2257 case B2400:
2258 baud = 2400L;
2259 break;
2260 case B1800:
2261 baud = 1800L;
2262 break;
2263 case B1200:
2264 baud = 1200L;
2265 break;
2266 case B600:
2267 baud = 600L;
2268 break;
2269 case B300:
2270 baud = 300L;
2271 break;
2272 case B200:
2273 baud = 200L;
2274 break;
2275 case B150:
2276 baud = 150L;
2277 break;
2278 case B134:
2279 baud = 134L;
2280 break;
2281 case B110:
2282 baud = 110L;
2283 break;
2284 case B75:
2285 baud = 75L;
2286 break;
2287 case B50:
2288 baud = 50L;
2289 break;
2290 default:
2291 baud = 0;
2292 }
2293 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || 2239 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) ||
2294 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) { 2240 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) {
2295 if (baud == 921600L) 2241 if (baud >= 921600L)
2296 return (-1); 2242 return (-1);
2297 } 2243 }
2298 MoxaPortSetBaud(port, baud); 2244 MoxaPortSetBaud(port, baud);
diff --git a/drivers/char/mspec.c b/drivers/char/mspec.c
new file mode 100644
index 000000000000..235e89226112
--- /dev/null
+++ b/drivers/char/mspec.c
@@ -0,0 +1,426 @@
1/*
2 * Copyright (C) 2001-2006 Silicon Graphics, Inc. All rights
3 * reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License
7 * as published by the Free Software Foundation.
8 */
9
10/*
11 * SN Platform Special Memory (mspec) Support
12 *
13 * This driver exports the SN special memory (mspec) facility to user
14 * processes.
15 * There are three types of memory made available thru this driver:
16 * fetchops, uncached and cached.
17 *
18 * Fetchops are atomic memory operations that are implemented in the
19 * memory controller on SGI SN hardware.
20 *
21 * Uncached are used for memory write combining feature of the ia64
22 * cpu.
23 *
24 * Cached are used for areas of memory that are used as cached addresses
25 * on our partition and used as uncached addresses from other partitions.
26 * Due to a design constraint of the SN2 Shub, you can not have processors
27 * on the same FSB perform both a cached and uncached reference to the
28 * same cache line. These special memory cached regions prevent the
29 * kernel from ever dropping in a TLB entry and therefore prevent the
30 * processor from ever speculating a cache line from this page.
31 */
32
33#include <linux/types.h>
34#include <linux/kernel.h>
35#include <linux/module.h>
36#include <linux/init.h>
37#include <linux/errno.h>
38#include <linux/miscdevice.h>
39#include <linux/spinlock.h>
40#include <linux/mm.h>
41#include <linux/vmalloc.h>
42#include <linux/string.h>
43#include <linux/slab.h>
44#include <linux/numa.h>
45#include <asm/page.h>
46#include <asm/system.h>
47#include <asm/pgtable.h>
48#include <asm/atomic.h>
49#include <asm/tlbflush.h>
50#include <asm/uncached.h>
51#include <asm/sn/addrs.h>
52#include <asm/sn/arch.h>
53#include <asm/sn/mspec.h>
54#include <asm/sn/sn_cpuid.h>
55#include <asm/sn/io.h>
56#include <asm/sn/bte.h>
57#include <asm/sn/shubio.h>
58
59
60#define FETCHOP_ID "SGI Fetchop,"
61#define CACHED_ID "Cached,"
62#define UNCACHED_ID "Uncached"
63#define REVISION "4.0"
64#define MSPEC_BASENAME "mspec"
65
66/*
67 * Page types allocated by the device.
68 */
69enum {
70 MSPEC_FETCHOP = 1,
71 MSPEC_CACHED,
72 MSPEC_UNCACHED
73};
74
75#ifdef CONFIG_SGI_SN
76static int is_sn2;
77#else
78#define is_sn2 0
79#endif
80
81/*
82 * One of these structures is allocated when an mspec region is mmaped. The
83 * structure is pointed to by the vma->vm_private_data field in the vma struct.
84 * This structure is used to record the addresses of the mspec pages.
85 */
86struct vma_data {
87 atomic_t refcnt; /* Number of vmas sharing the data. */
88 spinlock_t lock; /* Serialize access to the vma. */
89 int count; /* Number of pages allocated. */
90 int type; /* Type of pages allocated. */
91 unsigned long maddr[0]; /* Array of MSPEC addresses. */
92};
93
94/* used on shub2 to clear FOP cache in the HUB */
95static unsigned long scratch_page[MAX_NUMNODES];
96#define SH2_AMO_CACHE_ENTRIES 4
97
98static inline int
99mspec_zero_block(unsigned long addr, int len)
100{
101 int status;
102
103 if (is_sn2) {
104 if (is_shub2()) {
105 int nid;
106 void *p;
107 int i;
108
109 nid = nasid_to_cnodeid(get_node_number(__pa(addr)));
110 p = (void *)TO_AMO(scratch_page[nid]);
111
112 for (i=0; i < SH2_AMO_CACHE_ENTRIES; i++) {
113 FETCHOP_LOAD_OP(p, FETCHOP_LOAD);
114 p += FETCHOP_VAR_SIZE;
115 }
116 }
117
118 status = bte_copy(0, addr & ~__IA64_UNCACHED_OFFSET, len,
119 BTE_WACQUIRE | BTE_ZERO_FILL, NULL);
120 } else {
121 memset((char *) addr, 0, len);
122 status = 0;
123 }
124 return status;
125}
126
127/*
128 * mspec_open
129 *
130 * Called when a device mapping is created by a means other than mmap
131 * (via fork, etc.). Increments the reference count on the underlying
132 * mspec data so it is not freed prematurely.
133 */
134static void
135mspec_open(struct vm_area_struct *vma)
136{
137 struct vma_data *vdata;
138
139 vdata = vma->vm_private_data;
140 atomic_inc(&vdata->refcnt);
141}
142
143/*
144 * mspec_close
145 *
146 * Called when unmapping a device mapping. Frees all mspec pages
147 * belonging to the vma.
148 */
149static void
150mspec_close(struct vm_area_struct *vma)
151{
152 struct vma_data *vdata;
153 int i, pages, result, vdata_size;
154
155 vdata = vma->vm_private_data;
156 if (!atomic_dec_and_test(&vdata->refcnt))
157 return;
158
159 pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
160 vdata_size = sizeof(struct vma_data) + pages * sizeof(long);
161 for (i = 0; i < pages; i++) {
162 if (vdata->maddr[i] == 0)
163 continue;
164 /*
165 * Clear the page before sticking it back
166 * into the pool.
167 */
168 result = mspec_zero_block(vdata->maddr[i], PAGE_SIZE);
169 if (!result)
170 uncached_free_page(vdata->maddr[i]);
171 else
172 printk(KERN_WARNING "mspec_close(): "
173 "failed to zero page %i\n",
174 result);
175 }
176
177 if (vdata_size <= PAGE_SIZE)
178 kfree(vdata);
179 else
180 vfree(vdata);
181}
182
183
184/*
185 * mspec_nopfn
186 *
187 * Creates a mspec page and maps it to user space.
188 */
189static unsigned long
190mspec_nopfn(struct vm_area_struct *vma, unsigned long address)
191{
192 unsigned long paddr, maddr;
193 unsigned long pfn;
194 int index;
195 struct vma_data *vdata = vma->vm_private_data;
196
197 index = (address - vma->vm_start) >> PAGE_SHIFT;
198 maddr = (volatile unsigned long) vdata->maddr[index];
199 if (maddr == 0) {
200 maddr = uncached_alloc_page(numa_node_id());
201 if (maddr == 0)
202 return NOPFN_OOM;
203
204 spin_lock(&vdata->lock);
205 if (vdata->maddr[index] == 0) {
206 vdata->count++;
207 vdata->maddr[index] = maddr;
208 } else {
209 uncached_free_page(maddr);
210 maddr = vdata->maddr[index];
211 }
212 spin_unlock(&vdata->lock);
213 }
214
215 if (vdata->type == MSPEC_FETCHOP)
216 paddr = TO_AMO(maddr);
217 else
218 paddr = maddr & ~__IA64_UNCACHED_OFFSET;
219
220 pfn = paddr >> PAGE_SHIFT;
221
222 return pfn;
223}
224
225static struct vm_operations_struct mspec_vm_ops = {
226 .open = mspec_open,
227 .close = mspec_close,
228 .nopfn = mspec_nopfn
229};
230
231/*
232 * mspec_mmap
233 *
234 * Called when mmaping the device. Initializes the vma with a fault handler
235 * and private data structure necessary to allocate, track, and free the
236 * underlying pages.
237 */
238static int
239mspec_mmap(struct file *file, struct vm_area_struct *vma, int type)
240{
241 struct vma_data *vdata;
242 int pages, vdata_size;
243
244 if (vma->vm_pgoff != 0)
245 return -EINVAL;
246
247 if ((vma->vm_flags & VM_SHARED) == 0)
248 return -EINVAL;
249
250 if ((vma->vm_flags & VM_WRITE) == 0)
251 return -EPERM;
252
253 pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
254 vdata_size = sizeof(struct vma_data) + pages * sizeof(long);
255 if (vdata_size <= PAGE_SIZE)
256 vdata = kmalloc(vdata_size, GFP_KERNEL);
257 else
258 vdata = vmalloc(vdata_size);
259 if (!vdata)
260 return -ENOMEM;
261 memset(vdata, 0, vdata_size);
262
263 vdata->type = type;
264 spin_lock_init(&vdata->lock);
265 vdata->refcnt = ATOMIC_INIT(1);
266 vma->vm_private_data = vdata;
267
268 vma->vm_flags |= (VM_IO | VM_LOCKED | VM_RESERVED | VM_PFNMAP);
269 if (vdata->type == MSPEC_FETCHOP || vdata->type == MSPEC_UNCACHED)
270 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
271 vma->vm_ops = &mspec_vm_ops;
272
273 return 0;
274}
275
276static int
277fetchop_mmap(struct file *file, struct vm_area_struct *vma)
278{
279 return mspec_mmap(file, vma, MSPEC_FETCHOP);
280}
281
282static int
283cached_mmap(struct file *file, struct vm_area_struct *vma)
284{
285 return mspec_mmap(file, vma, MSPEC_CACHED);
286}
287
288static int
289uncached_mmap(struct file *file, struct vm_area_struct *vma)
290{
291 return mspec_mmap(file, vma, MSPEC_UNCACHED);
292}
293
294static struct file_operations fetchop_fops = {
295 .owner = THIS_MODULE,
296 .mmap = fetchop_mmap
297};
298
299static struct miscdevice fetchop_miscdev = {
300 .minor = MISC_DYNAMIC_MINOR,
301 .name = "sgi_fetchop",
302 .fops = &fetchop_fops
303};
304
305static struct file_operations cached_fops = {
306 .owner = THIS_MODULE,
307 .mmap = cached_mmap
308};
309
310static struct miscdevice cached_miscdev = {
311 .minor = MISC_DYNAMIC_MINOR,
312 .name = "mspec_cached",
313 .fops = &cached_fops
314};
315
316static struct file_operations uncached_fops = {
317 .owner = THIS_MODULE,
318 .mmap = uncached_mmap
319};
320
321static struct miscdevice uncached_miscdev = {
322 .minor = MISC_DYNAMIC_MINOR,
323 .name = "mspec_uncached",
324 .fops = &uncached_fops
325};
326
327/*
328 * mspec_init
329 *
330 * Called at boot time to initialize the mspec facility.
331 */
332static int __init
333mspec_init(void)
334{
335 int ret;
336 int nid;
337
338 /*
339 * The fetchop device only works on SN2 hardware, uncached and cached
340 * memory drivers should both be valid on all ia64 hardware
341 */
342#ifdef CONFIG_SGI_SN
343 if (ia64_platform_is("sn2")) {
344 is_sn2 = 1;
345 if (is_shub2()) {
346 ret = -ENOMEM;
347 for_each_online_node(nid) {
348 int actual_nid;
349 int nasid;
350 unsigned long phys;
351
352 scratch_page[nid] = uncached_alloc_page(nid);
353 if (scratch_page[nid] == 0)
354 goto free_scratch_pages;
355 phys = __pa(scratch_page[nid]);
356 nasid = get_node_number(phys);
357 actual_nid = nasid_to_cnodeid(nasid);
358 if (actual_nid != nid)
359 goto free_scratch_pages;
360 }
361 }
362
363 ret = misc_register(&fetchop_miscdev);
364 if (ret) {
365 printk(KERN_ERR
366 "%s: failed to register device %i\n",
367 FETCHOP_ID, ret);
368 goto free_scratch_pages;
369 }
370 }
371#endif
372 ret = misc_register(&cached_miscdev);
373 if (ret) {
374 printk(KERN_ERR "%s: failed to register device %i\n",
375 CACHED_ID, ret);
376 if (is_sn2)
377 misc_deregister(&fetchop_miscdev);
378 goto free_scratch_pages;
379 }
380 ret = misc_register(&uncached_miscdev);
381 if (ret) {
382 printk(KERN_ERR "%s: failed to register device %i\n",
383 UNCACHED_ID, ret);
384 misc_deregister(&cached_miscdev);
385 if (is_sn2)
386 misc_deregister(&fetchop_miscdev);
387 goto free_scratch_pages;
388 }
389
390 printk(KERN_INFO "%s %s initialized devices: %s %s %s\n",
391 MSPEC_BASENAME, REVISION, is_sn2 ? FETCHOP_ID : "",
392 CACHED_ID, UNCACHED_ID);
393
394 return 0;
395
396 free_scratch_pages:
397 for_each_node(nid) {
398 if (scratch_page[nid] != 0)
399 uncached_free_page(scratch_page[nid]);
400 }
401 return ret;
402}
403
404static void __exit
405mspec_exit(void)
406{
407 int nid;
408
409 misc_deregister(&uncached_miscdev);
410 misc_deregister(&cached_miscdev);
411 if (is_sn2) {
412 misc_deregister(&fetchop_miscdev);
413
414 for_each_node(nid) {
415 if (scratch_page[nid] != 0)
416 uncached_free_page(scratch_page[nid]);
417 }
418 }
419}
420
421module_init(mspec_init);
422module_exit(mspec_exit);
423
424MODULE_AUTHOR("Silicon Graphics, Inc. <linux-altix@sgi.com>");
425MODULE_DESCRIPTION("Driver for SGI SN special memory operations");
426MODULE_LICENSE("GPL");
diff --git a/drivers/char/mwave/README b/drivers/char/mwave/README
index 70f8d19fb79f..480251fc78e2 100644
--- a/drivers/char/mwave/README
+++ b/drivers/char/mwave/README
@@ -41,10 +41,7 @@ Example to enable the 3780i DSP using ttyS1 resources:
41Accessing the driver 41Accessing the driver
42-------------------- 42--------------------
43 43
44You must also create a node for the driver. Without devfs: 44You must also create a node for the driver:
45 mkdir -p /dev/modems 45 mkdir -p /dev/modems
46 mknod --mode=660 /dev/modems/mwave c 10 219 46 mknod --mode=660 /dev/modems/mwave c 10 219
47With devfs:
48 mkdir -p /dev/modems
49 ln -s ../misc/mwave /dev/modems/mwave
50 47
diff --git a/drivers/char/mwave/mwavedd.c b/drivers/char/mwave/mwavedd.c
index 39a2e661ff55..8d14823b0514 100644
--- a/drivers/char/mwave/mwavedd.c
+++ b/drivers/char/mwave/mwavedd.c
@@ -297,7 +297,7 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
297 " ipcnum %x, usIntCount %x\n", 297 " ipcnum %x, usIntCount %x\n",
298 ipcnum, 298 ipcnum,
299 pDrvData->IPCs[ipcnum].usIntCount); 299 pDrvData->IPCs[ipcnum].usIntCount);
300 if (ipcnum > ARRAY_SIZE(pDrvData->IPCs)) { 300 if (ipcnum >= ARRAY_SIZE(pDrvData->IPCs)) {
301 PRINTK_ERROR(KERN_ERR_MWAVE 301 PRINTK_ERROR(KERN_ERR_MWAVE
302 "mwavedd::mwave_ioctl:" 302 "mwavedd::mwave_ioctl:"
303 " IOCTL_MW_GET_IPC: Error:" 303 " IOCTL_MW_GET_IPC: Error:"
@@ -355,7 +355,7 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
355 "mwavedd::mwave_ioctl IOCTL_MW_UNREGISTER_IPC" 355 "mwavedd::mwave_ioctl IOCTL_MW_UNREGISTER_IPC"
356 " ipcnum %x\n", 356 " ipcnum %x\n",
357 ipcnum); 357 ipcnum);
358 if (ipcnum > ARRAY_SIZE(pDrvData->IPCs)) { 358 if (ipcnum >= ARRAY_SIZE(pDrvData->IPCs)) {
359 PRINTK_ERROR(KERN_ERR_MWAVE 359 PRINTK_ERROR(KERN_ERR_MWAVE
360 "mwavedd::mwave_ioctl:" 360 "mwavedd::mwave_ioctl:"
361 " IOCTL_MW_UNREGISTER_IPC:" 361 " IOCTL_MW_UNREGISTER_IPC:"
diff --git a/drivers/char/mwave/tp3780i.c b/drivers/char/mwave/tp3780i.c
index cc3e54dd7234..f282976daaac 100644
--- a/drivers/char/mwave/tp3780i.c
+++ b/drivers/char/mwave/tp3780i.c
@@ -95,14 +95,14 @@ static void EnableSRAM(THINKPAD_BD_DATA * pBDData)
95} 95}
96 96
97 97
98static irqreturn_t UartInterrupt(int irq, void *dev_id, struct pt_regs *regs) 98static irqreturn_t UartInterrupt(int irq, void *dev_id)
99{ 99{
100 PRINTK_3(TRACE_TP3780I, 100 PRINTK_3(TRACE_TP3780I,
101 "tp3780i::UartInterrupt entry irq %x dev_id %p\n", irq, dev_id); 101 "tp3780i::UartInterrupt entry irq %x dev_id %p\n", irq, dev_id);
102 return IRQ_HANDLED; 102 return IRQ_HANDLED;
103} 103}
104 104
105static irqreturn_t DspInterrupt(int irq, void *dev_id, struct pt_regs *regs) 105static irqreturn_t DspInterrupt(int irq, void *dev_id)
106{ 106{
107 pMWAVE_DEVICE_DATA pDrvData = &mwave_s_mdd; 107 pMWAVE_DEVICE_DATA pDrvData = &mwave_s_mdd;
108 DSP_3780I_CONFIG_SETTINGS *pSettings = &pDrvData->rBDData.rDspSettings; 108 DSP_3780I_CONFIG_SETTINGS *pSettings = &pDrvData->rBDData.rDspSettings;
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 556abd3e0d07..c063359baf78 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -328,8 +328,8 @@ struct mxser_struct {
328 int xmit_tail; 328 int xmit_tail;
329 int xmit_cnt; 329 int xmit_cnt;
330 struct work_struct tqueue; 330 struct work_struct tqueue;
331 struct termios normal_termios; 331 struct ktermios normal_termios;
332 struct termios callout_termios; 332 struct ktermios callout_termios;
333 wait_queue_head_t open_wait; 333 wait_queue_head_t open_wait;
334 wait_queue_head_t close_wait; 334 wait_queue_head_t close_wait;
335 wait_queue_head_t delta_msr_wait; 335 wait_queue_head_t delta_msr_wait;
@@ -364,8 +364,8 @@ static int mxserBoardCAP[MXSER_BOARDS] = {
364static struct tty_driver *mxvar_sdriver; 364static struct tty_driver *mxvar_sdriver;
365static struct mxser_struct mxvar_table[MXSER_PORTS]; 365static struct mxser_struct mxvar_table[MXSER_PORTS];
366static struct tty_struct *mxvar_tty[MXSER_PORTS + 1]; 366static struct tty_struct *mxvar_tty[MXSER_PORTS + 1];
367static struct termios *mxvar_termios[MXSER_PORTS + 1]; 367static struct ktermios *mxvar_termios[MXSER_PORTS + 1];
368static struct termios *mxvar_termios_locked[MXSER_PORTS + 1]; 368static struct ktermios *mxvar_termios_locked[MXSER_PORTS + 1];
369static struct mxser_log mxvar_log; 369static struct mxser_log mxvar_log;
370static int mxvar_diagflag; 370static int mxvar_diagflag;
371static unsigned char mxser_msr[MXSER_PORTS + 1]; 371static unsigned char mxser_msr[MXSER_PORTS + 1];
@@ -389,7 +389,7 @@ static int mxser_init(void);
389/* static void mxser_poll(unsigned long); */ 389/* static void mxser_poll(unsigned long); */
390static int mxser_get_ISA_conf(int, struct mxser_hwconf *); 390static int mxser_get_ISA_conf(int, struct mxser_hwconf *);
391static int mxser_get_PCI_conf(int, int, int, struct mxser_hwconf *); 391static int mxser_get_PCI_conf(int, int, int, struct mxser_hwconf *);
392static void mxser_do_softint(void *); 392static void mxser_do_softint(struct work_struct *);
393static int mxser_open(struct tty_struct *, struct file *); 393static int mxser_open(struct tty_struct *, struct file *);
394static void mxser_close(struct tty_struct *, struct file *); 394static void mxser_close(struct tty_struct *, struct file *);
395static int mxser_write(struct tty_struct *, const unsigned char *, int); 395static int mxser_write(struct tty_struct *, const unsigned char *, int);
@@ -402,19 +402,19 @@ static int mxser_ioctl(struct tty_struct *, struct file *, uint, ulong);
402static int mxser_ioctl_special(unsigned int, void __user *); 402static int mxser_ioctl_special(unsigned int, void __user *);
403static void mxser_throttle(struct tty_struct *); 403static void mxser_throttle(struct tty_struct *);
404static void mxser_unthrottle(struct tty_struct *); 404static void mxser_unthrottle(struct tty_struct *);
405static void mxser_set_termios(struct tty_struct *, struct termios *); 405static void mxser_set_termios(struct tty_struct *, struct ktermios *);
406static void mxser_stop(struct tty_struct *); 406static void mxser_stop(struct tty_struct *);
407static void mxser_start(struct tty_struct *); 407static void mxser_start(struct tty_struct *);
408static void mxser_hangup(struct tty_struct *); 408static void mxser_hangup(struct tty_struct *);
409static void mxser_rs_break(struct tty_struct *, int); 409static void mxser_rs_break(struct tty_struct *, int);
410static irqreturn_t mxser_interrupt(int, void *, struct pt_regs *); 410static irqreturn_t mxser_interrupt(int, void *);
411static void mxser_receive_chars(struct mxser_struct *, int *); 411static void mxser_receive_chars(struct mxser_struct *, int *);
412static void mxser_transmit_chars(struct mxser_struct *); 412static void mxser_transmit_chars(struct mxser_struct *);
413static void mxser_check_modem_status(struct mxser_struct *, int); 413static void mxser_check_modem_status(struct mxser_struct *, int);
414static int mxser_block_til_ready(struct tty_struct *, struct file *, struct mxser_struct *); 414static int mxser_block_til_ready(struct tty_struct *, struct file *, struct mxser_struct *);
415static int mxser_startup(struct mxser_struct *); 415static int mxser_startup(struct mxser_struct *);
416static void mxser_shutdown(struct mxser_struct *); 416static void mxser_shutdown(struct mxser_struct *);
417static int mxser_change_speed(struct mxser_struct *, struct termios *old_termios); 417static int mxser_change_speed(struct mxser_struct *, struct ktermios *old_termios);
418static int mxser_get_serial_info(struct mxser_struct *, struct serial_struct __user *); 418static int mxser_get_serial_info(struct mxser_struct *, struct serial_struct __user *);
419static int mxser_set_serial_info(struct mxser_struct *, struct serial_struct __user *); 419static int mxser_set_serial_info(struct mxser_struct *, struct serial_struct __user *);
420static int mxser_get_lsr_info(struct mxser_struct *, unsigned int __user *); 420static int mxser_get_lsr_info(struct mxser_struct *, unsigned int __user *);
@@ -453,7 +453,7 @@ static int CheckIsMoxaMust(int io)
453 453
454/* above is modified by Victor Yu. 08-15-2002 */ 454/* above is modified by Victor Yu. 08-15-2002 */
455 455
456static struct tty_operations mxser_ops = { 456static const struct tty_operations mxser_ops = {
457 .open = mxser_open, 457 .open = mxser_open,
458 .close = mxser_close, 458 .close = mxser_close,
459 .write = mxser_write, 459 .write = mxser_write,
@@ -515,6 +515,7 @@ static void __exit mxser_module_exit(void)
515 if (pdev != NULL) { /* PCI */ 515 if (pdev != NULL) { /* PCI */
516 release_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2)); 516 release_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2));
517 release_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3)); 517 release_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3));
518 pci_dev_put(pdev);
518 } else { 519 } else {
519 release_region(mxsercfg[i].ioaddr[0], 8 * mxsercfg[i].ports); 520 release_region(mxsercfg[i].ioaddr[0], 8 * mxsercfg[i].ports);
520 release_region(mxsercfg[i].vector, 1); 521 release_region(mxsercfg[i].vector, 1);
@@ -556,7 +557,7 @@ static int mxser_initbrd(int board, struct mxser_hwconf *hwconf)
556 n = board * MXSER_PORTS_PER_BOARD; 557 n = board * MXSER_PORTS_PER_BOARD;
557 info = &mxvar_table[n]; 558 info = &mxvar_table[n];
558 /*if (verbose) */ { 559 /*if (verbose) */ {
559 printk(KERN_DEBUG " ttyM%d - ttyM%d ", 560 printk(KERN_DEBUG " ttyMI%d - ttyMI%d ",
560 n, n + hwconf->ports - 1); 561 n, n + hwconf->ports - 1);
561 printk(" max. baud rate = %d bps.\n", 562 printk(" max. baud rate = %d bps.\n",
562 hwconf->MaxCanSetBaudRate[0]); 563 hwconf->MaxCanSetBaudRate[0]);
@@ -590,7 +591,7 @@ static int mxser_initbrd(int board, struct mxser_hwconf *hwconf)
590 info->custom_divisor = hwconf->baud_base[i] * 16; 591 info->custom_divisor = hwconf->baud_base[i] * 16;
591 info->close_delay = 5 * HZ / 10; 592 info->close_delay = 5 * HZ / 10;
592 info->closing_wait = 30 * HZ; 593 info->closing_wait = 30 * HZ;
593 INIT_WORK(&info->tqueue, mxser_do_softint, info); 594 INIT_WORK(&info->tqueue, mxser_do_softint);
594 info->normal_termios = mxvar_sdriver->init_termios; 595 info->normal_termios = mxvar_sdriver->init_termios;
595 init_waitqueue_head(&info->open_wait); 596 init_waitqueue_head(&info->open_wait);
596 init_waitqueue_head(&info->close_wait); 597 init_waitqueue_head(&info->close_wait);
@@ -717,7 +718,7 @@ static int mxser_init(void)
717 /* Initialize the tty_driver structure */ 718 /* Initialize the tty_driver structure */
718 memset(mxvar_sdriver, 0, sizeof(struct tty_driver)); 719 memset(mxvar_sdriver, 0, sizeof(struct tty_driver));
719 mxvar_sdriver->magic = TTY_DRIVER_MAGIC; 720 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
720 mxvar_sdriver->name = "ttyM"; 721 mxvar_sdriver->name = "ttyMI";
721 mxvar_sdriver->major = ttymajor; 722 mxvar_sdriver->major = ttymajor;
722 mxvar_sdriver->minor_start = 0; 723 mxvar_sdriver->minor_start = 0;
723 mxvar_sdriver->num = MXSER_PORTS + 1; 724 mxvar_sdriver->num = MXSER_PORTS + 1;
@@ -725,6 +726,8 @@ static int mxser_init(void)
725 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL; 726 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
726 mxvar_sdriver->init_termios = tty_std_termios; 727 mxvar_sdriver->init_termios = tty_std_termios;
727 mxvar_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL; 728 mxvar_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
729 mxvar_sdriver->init_termios.c_ispeed = 9600;
730 mxvar_sdriver->init_termios.c_ospeed = 9600;
728 mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW; 731 mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW;
729 tty_set_operations(mxvar_sdriver, &mxser_ops); 732 tty_set_operations(mxvar_sdriver, &mxser_ops);
730 mxvar_sdriver->ttys = mxvar_tty; 733 mxvar_sdriver->ttys = mxvar_tty;
@@ -839,9 +842,9 @@ static int mxser_init(void)
839 index = 0; 842 index = 0;
840 b = 0; 843 b = 0;
841 while (b < n) { 844 while (b < n) {
842 pdev = pci_find_device(mxser_pcibrds[b].vendor, 845 pdev = pci_get_device(mxser_pcibrds[b].vendor,
843 mxser_pcibrds[b].device, pdev); 846 mxser_pcibrds[b].device, pdev);
844 if (pdev == NULL) { 847 if (pdev == NULL) {
845 b++; 848 b++;
846 continue; 849 continue;
847 } 850 }
@@ -893,6 +896,9 @@ static int mxser_init(void)
893 if (mxser_initbrd(m, &hwconf) < 0) 896 if (mxser_initbrd(m, &hwconf) < 0)
894 continue; 897 continue;
895 m++; 898 m++;
899 /* Keep an extra reference if we succeeded. It will
900 be returned at unload time */
901 pci_dev_get(pdev);
896 } 902 }
897 } 903 }
898#endif 904#endif
@@ -917,9 +923,10 @@ static int mxser_init(void)
917 return 0; 923 return 0;
918} 924}
919 925
920static void mxser_do_softint(void *private_) 926static void mxser_do_softint(struct work_struct *work)
921{ 927{
922 struct mxser_struct *info = private_; 928 struct mxser_struct *info =
929 container_of(work, struct mxser_struct, tqueue);
923 struct tty_struct *tty; 930 struct tty_struct *tty;
924 931
925 tty = info->tty; 932 tty = info->tty;
@@ -993,7 +1000,7 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
993 mxser_change_speed(info, NULL); 1000 mxser_change_speed(info, NULL);
994 } 1001 }
995 1002
996 info->session = current->signal->session; 1003 info->session = process_session(current);
997 info->pgrp = process_group(current); 1004 info->pgrp = process_group(current);
998 1005
999 /* 1006 /*
@@ -1744,7 +1751,7 @@ static void mxser_unthrottle(struct tty_struct *tty)
1744 /* MX_UNLOCK(&info->slock); */ 1751 /* MX_UNLOCK(&info->slock); */
1745} 1752}
1746 1753
1747static void mxser_set_termios(struct tty_struct *tty, struct termios *old_termios) 1754static void mxser_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1748{ 1755{
1749 struct mxser_struct *info = tty->driver_data; 1756 struct mxser_struct *info = tty->driver_data;
1750 unsigned long flags; 1757 unsigned long flags;
@@ -1916,7 +1923,7 @@ static void mxser_rs_break(struct tty_struct *tty, int break_state)
1916/* 1923/*
1917 * This is the serial driver's generic interrupt routine 1924 * This is the serial driver's generic interrupt routine
1918 */ 1925 */
1919static irqreturn_t mxser_interrupt(int irq, void *dev_id, struct pt_regs *regs) 1926static irqreturn_t mxser_interrupt(int irq, void *dev_id)
1920{ 1927{
1921 int status, iir, i; 1928 int status, iir, i;
1922 struct mxser_struct *info; 1929 struct mxser_struct *info;
@@ -2536,7 +2543,7 @@ static void mxser_shutdown(struct mxser_struct *info)
2536 * This routine is called to set the UART divisor registers to match 2543 * This routine is called to set the UART divisor registers to match
2537 * the specified baud rate for a serial port. 2544 * the specified baud rate for a serial port.
2538 */ 2545 */
2539static int mxser_change_speed(struct mxser_struct *info, struct termios *old_termios) 2546static int mxser_change_speed(struct mxser_struct *info, struct ktermios *old_termios)
2540{ 2547{
2541 unsigned cflag, cval, fcr; 2548 unsigned cflag, cval, fcr;
2542 int ret = 0; 2549 int ret = 0;
@@ -2554,71 +2561,7 @@ static int mxser_change_speed(struct mxser_struct *info, struct termios *old_ter
2554#define B921600 (B460800 +1) 2561#define B921600 (B460800 +1)
2555#endif 2562#endif
2556 if (mxser_set_baud_method[info->port] == 0) { 2563 if (mxser_set_baud_method[info->port] == 0) {
2557 switch (cflag & (CBAUD | CBAUDEX)) { 2564 baud = tty_get_baud_rate(info->tty);
2558 case B921600:
2559 baud = 921600;
2560 break;
2561 case B460800:
2562 baud = 460800;
2563 break;
2564 case B230400:
2565 baud = 230400;
2566 break;
2567 case B115200:
2568 baud = 115200;
2569 break;
2570 case B57600:
2571 baud = 57600;
2572 break;
2573 case B38400:
2574 baud = 38400;
2575 break;
2576 case B19200:
2577 baud = 19200;
2578 break;
2579 case B9600:
2580 baud = 9600;
2581 break;
2582 case B4800:
2583 baud = 4800;
2584 break;
2585 case B2400:
2586 baud = 2400;
2587 break;
2588 case B1800:
2589 baud = 1800;
2590 break;
2591 case B1200:
2592 baud = 1200;
2593 break;
2594 case B600:
2595 baud = 600;
2596 break;
2597 case B300:
2598 baud = 300;
2599 break;
2600 case B200:
2601 baud = 200;
2602 break;
2603 case B150:
2604 baud = 150;
2605 break;
2606 case B134:
2607 baud = 134;
2608 break;
2609 case B110:
2610 baud = 110;
2611 break;
2612 case B75:
2613 baud = 75;
2614 break;
2615 case B50:
2616 baud = 50;
2617 break;
2618 default:
2619 baud = 0;
2620 break;
2621 }
2622 mxser_set_baud(info, baud); 2565 mxser_set_baud(info, baud);
2623 } 2566 }
2624 2567
diff --git a/drivers/char/mxser_new.c b/drivers/char/mxser_new.c
new file mode 100644
index 000000000000..efa8076c33e0
--- /dev/null
+++ b/drivers/char/mxser_new.c
@@ -0,0 +1,2804 @@
1/*
2 * mxser.c -- MOXA Smartio/Industio family multiport serial driver.
3 *
4 * Copyright (C) 1999-2006 Moxa Technologies (support@moxa.com.tw).
5 * Copyright (C) 2006 Jiri Slaby <jirislaby@gmail.com>
6 *
7 * This code is loosely based on the 1.8 moxa driver which is based on
8 * Linux serial driver, written by Linus Torvalds, Theodore T'so and
9 * others.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * Fed through a cleanup, indent and remove of non 2.6 code by Alan Cox
17 * <alan@redhat.com>. The original 1.8 code is available on www.moxa.com.
18 * - Fixed x86_64 cleanness
19 * - Fixed sleep with spinlock held in mxser_send_break
20 */
21
22#include <linux/module.h>
23#include <linux/autoconf.h>
24#include <linux/errno.h>
25#include <linux/signal.h>
26#include <linux/sched.h>
27#include <linux/timer.h>
28#include <linux/interrupt.h>
29#include <linux/tty.h>
30#include <linux/tty_flip.h>
31#include <linux/serial.h>
32#include <linux/serial_reg.h>
33#include <linux/major.h>
34#include <linux/string.h>
35#include <linux/fcntl.h>
36#include <linux/ptrace.h>
37#include <linux/gfp.h>
38#include <linux/ioport.h>
39#include <linux/mm.h>
40#include <linux/smp_lock.h>
41#include <linux/delay.h>
42#include <linux/pci.h>
43
44#include <asm/system.h>
45#include <asm/io.h>
46#include <asm/irq.h>
47#include <asm/bitops.h>
48#include <asm/uaccess.h>
49
50#include "mxser_new.h"
51
52#define MXSER_VERSION "2.0"
53#define MXSERMAJOR 174
54#define MXSERCUMAJOR 175
55
56#define MXSER_EVENT_TXLOW 1
57
58#define MXSER_BOARDS 4 /* Max. boards */
59#define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
60#define MXSER_PORTS (MXSER_BOARDS * MXSER_PORTS_PER_BOARD)
61#define MXSER_ISR_PASS_LIMIT 99999L
62
63#define MXSER_ERR_IOADDR -1
64#define MXSER_ERR_IRQ -2
65#define MXSER_ERR_IRQ_CONFLIT -3
66#define MXSER_ERR_VECTOR -4
67
68#define WAKEUP_CHARS 256
69
70#define UART_MCR_AFE 0x20
71#define UART_LSR_SPECIAL 0x1E
72
73#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|\
74 IXON|IXOFF))
75
76#define C168_ASIC_ID 1
77#define C104_ASIC_ID 2
78#define C102_ASIC_ID 0xB
79#define CI132_ASIC_ID 4
80#define CI134_ASIC_ID 3
81#define CI104J_ASIC_ID 5
82
83#define MXSER_HIGHBAUD 1
84#define MXSER_HAS2 2
85
86/* This is only for PCI */
87static const struct {
88 int type;
89 int tx_fifo;
90 int rx_fifo;
91 int xmit_fifo_size;
92 int rx_high_water;
93 int rx_trigger;
94 int rx_low_water;
95 long max_baud;
96} Gpci_uart_info[] = {
97 {MOXA_OTHER_UART, 16, 16, 16, 14, 14, 1, 921600L},
98 {MOXA_MUST_MU150_HWID, 64, 64, 64, 48, 48, 16, 230400L},
99 {MOXA_MUST_MU860_HWID, 128, 128, 128, 96, 96, 32, 921600L}
100};
101#define UART_INFO_NUM ARRAY_SIZE(Gpci_uart_info)
102
103struct mxser_cardinfo {
104 unsigned int nports;
105 char *name;
106 unsigned int flags;
107};
108
109static const struct mxser_cardinfo mxser_cards[] = {
110 { 8, "C168 series", }, /* C168-ISA */
111 { 4, "C104 series", }, /* C104-ISA */
112 { 4, "CI-104J series", }, /* CI104J */
113 { 8, "C168H/PCI series", }, /* C168-PCI */
114 { 4, "C104H/PCI series", }, /* C104-PCI */
115 { 4, "C102 series", MXSER_HAS2 }, /* C102-ISA */
116 { 4, "CI-132 series", MXSER_HAS2 }, /* CI132 */
117 { 4, "CI-134 series", }, /* CI134 */
118 { 2, "CP-132 series", }, /* CP132 */
119 { 4, "CP-114 series", }, /* CP114 */
120 { 4, "CT-114 series", }, /* CT114 */
121 { 2, "CP-102 series", MXSER_HIGHBAUD }, /* CP102 */
122 { 4, "CP-104U series", }, /* CP104U */
123 { 8, "CP-168U series", }, /* CP168U */
124 { 2, "CP-132U series", }, /* CP132U */
125 { 4, "CP-134U series", }, /* CP134U */
126 { 4, "CP-104JU series", }, /* CP104JU */
127 { 8, "Moxa UC7000 Serial", }, /* RC7000 */
128 { 8, "CP-118U series", }, /* CP118U */
129 { 2, "CP-102UL series", }, /* CP102UL */
130 { 2, "CP-102U series", }, /* CP102U */
131 { 8, "CP-118EL series", }, /* CP118EL */
132 { 8, "CP-168EL series", }, /* CP168EL */
133 { 4, "CP-104EL series", } /* CP104EL */
134};
135
136/* driver_data correspond to the lines in the structure above
137 see also ISA probe function before you change something */
138static struct pci_device_id mxser_pcibrds[] = {
139 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C168),
140 .driver_data = 3 },
141 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C104),
142 .driver_data = 4 },
143 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132),
144 .driver_data = 8 },
145 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP114),
146 .driver_data = 9 },
147 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CT114),
148 .driver_data = 10 },
149 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102),
150 .driver_data = 11 },
151 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104U),
152 .driver_data = 12 },
153 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP168U),
154 .driver_data = 13 },
155 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132U),
156 .driver_data = 14 },
157 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP134U),
158 .driver_data = 15 },
159 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104JU),
160 .driver_data = 16 },
161 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_RC7000),
162 .driver_data = 17 },
163 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118U),
164 .driver_data = 18 },
165 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102UL),
166 .driver_data = 19 },
167 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102U),
168 .driver_data = 20 },
169 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118EL),
170 .driver_data = 21 },
171 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP168EL),
172 .driver_data = 22 },
173 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104EL),
174 .driver_data = 23 },
175 { }
176};
177MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
178
179static int ioaddr[MXSER_BOARDS] = { 0, 0, 0, 0 };
180static int ttymajor = MXSERMAJOR;
181static int calloutmajor = MXSERCUMAJOR;
182
183/* Variables for insmod */
184
185MODULE_AUTHOR("Casper Yang");
186MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
187module_param_array(ioaddr, int, NULL, 0);
188module_param(ttymajor, int, 0);
189MODULE_LICENSE("GPL");
190
191struct mxser_log {
192 int tick;
193 unsigned long rxcnt[MXSER_PORTS];
194 unsigned long txcnt[MXSER_PORTS];
195};
196
197
198struct mxser_mon {
199 unsigned long rxcnt;
200 unsigned long txcnt;
201 unsigned long up_rxcnt;
202 unsigned long up_txcnt;
203 int modem_status;
204 unsigned char hold_reason;
205};
206
207struct mxser_mon_ext {
208 unsigned long rx_cnt[32];
209 unsigned long tx_cnt[32];
210 unsigned long up_rxcnt[32];
211 unsigned long up_txcnt[32];
212 int modem_status[32];
213
214 long baudrate[32];
215 int databits[32];
216 int stopbits[32];
217 int parity[32];
218 int flowctrl[32];
219 int fifo[32];
220 int iftype[32];
221};
222
223struct mxser_board;
224
225struct mxser_port {
226 struct mxser_board *board;
227 struct tty_struct *tty;
228
229 unsigned long ioaddr;
230 unsigned long opmode_ioaddr;
231 int max_baud;
232
233 int rx_high_water;
234 int rx_trigger; /* Rx fifo trigger level */
235 int rx_low_water;
236 int baud_base; /* max. speed */
237 long realbaud;
238 int type; /* UART type */
239 int flags; /* defined in tty.h */
240 long session; /* Session of opening process */
241 long pgrp; /* pgrp of opening process */
242
243 int x_char; /* xon/xoff character */
244 int IER; /* Interrupt Enable Register */
245 int MCR; /* Modem control register */
246
247 unsigned char stop_rx;
248 unsigned char ldisc_stop_rx;
249
250 int custom_divisor;
251 int close_delay;
252 unsigned short closing_wait;
253 unsigned char err_shadow;
254 unsigned long event;
255
256 int count; /* # of fd on device */
257 int blocked_open; /* # of blocked opens */
258 struct async_icount icount; /* kernel counters for 4 input interrupts */
259 int timeout;
260
261 int read_status_mask;
262 int ignore_status_mask;
263 int xmit_fifo_size;
264 unsigned char *xmit_buf;
265 int xmit_head;
266 int xmit_tail;
267 int xmit_cnt;
268
269 struct ktermios normal_termios;
270 struct ktermios callout_termios;
271
272 struct mxser_mon mon_data;
273
274 spinlock_t slock;
275 struct work_struct tqueue;
276 wait_queue_head_t open_wait;
277 wait_queue_head_t close_wait;
278 wait_queue_head_t delta_msr_wait;
279};
280
281struct mxser_board {
282 unsigned int idx;
283 int irq;
284 const struct mxser_cardinfo *info;
285 unsigned long vector;
286 unsigned long vector_mask;
287
288 int chip_flag;
289 int uart_type;
290
291 struct mxser_port ports[MXSER_PORTS_PER_BOARD];
292};
293
294struct mxser_mstatus {
295 tcflag_t cflag;
296 int cts;
297 int dsr;
298 int ri;
299 int dcd;
300};
301
302static struct mxser_mstatus GMStatus[MXSER_PORTS];
303
304static int mxserBoardCAP[MXSER_BOARDS] = {
305 0, 0, 0, 0
306 /* 0x180, 0x280, 0x200, 0x320 */
307};
308
309static struct mxser_board mxser_boards[MXSER_BOARDS];
310static struct tty_driver *mxvar_sdriver;
311static struct mxser_log mxvar_log;
312static int mxvar_diagflag;
313static unsigned char mxser_msr[MXSER_PORTS + 1];
314static struct mxser_mon_ext mon_data_ext;
315static int mxser_set_baud_method[MXSER_PORTS + 1];
316static spinlock_t gm_lock;
317
318static int CheckIsMoxaMust(int io)
319{
320 u8 oldmcr, hwid;
321 int i;
322
323 outb(0, io + UART_LCR);
324 DISABLE_MOXA_MUST_ENCHANCE_MODE(io);
325 oldmcr = inb(io + UART_MCR);
326 outb(0, io + UART_MCR);
327 SET_MOXA_MUST_XON1_VALUE(io, 0x11);
328 if ((hwid = inb(io + UART_MCR)) != 0) {
329 outb(oldmcr, io + UART_MCR);
330 return MOXA_OTHER_UART;
331 }
332
333 GET_MOXA_MUST_HARDWARE_ID(io, &hwid);
334 for (i = 1; i < UART_INFO_NUM; i++) { /* 0 = OTHER_UART */
335 if (hwid == Gpci_uart_info[i].type)
336 return (int)hwid;
337 }
338 return MOXA_OTHER_UART;
339}
340
341static void process_txrx_fifo(struct mxser_port *info)
342{
343 int i;
344
345 if ((info->type == PORT_16450) || (info->type == PORT_8250)) {
346 info->rx_trigger = 1;
347 info->rx_high_water = 1;
348 info->rx_low_water = 1;
349 info->xmit_fifo_size = 1;
350 } else
351 for (i = 0; i < UART_INFO_NUM; i++)
352 if (info->board->chip_flag == Gpci_uart_info[i].type) {
353 info->rx_trigger = Gpci_uart_info[i].rx_trigger;
354 info->rx_low_water = Gpci_uart_info[i].rx_low_water;
355 info->rx_high_water = Gpci_uart_info[i].rx_high_water;
356 info->xmit_fifo_size = Gpci_uart_info[i].xmit_fifo_size;
357 break;
358 }
359}
360
361static void mxser_do_softint(struct work_struct *work)
362{
363 struct mxser_port *info = container_of(work, struct mxser_port, tqueue);
364 struct tty_struct *tty = info->tty;
365
366 if (test_and_clear_bit(MXSER_EVENT_TXLOW, &info->event))
367 tty_wakeup(tty);
368}
369
370static unsigned char mxser_get_msr(int baseaddr, int mode, int port)
371{
372 unsigned char status = 0;
373
374 status = inb(baseaddr + UART_MSR);
375
376 mxser_msr[port] &= 0x0F;
377 mxser_msr[port] |= status;
378 status = mxser_msr[port];
379 if (mode)
380 mxser_msr[port] = 0;
381
382 return status;
383}
384
385static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp,
386 struct mxser_port *port)
387{
388 DECLARE_WAITQUEUE(wait, current);
389 int retval;
390 int do_clocal = 0;
391 unsigned long flags;
392
393 /*
394 * If non-blocking mode is set, or the port is not enabled,
395 * then make the check up front and then exit.
396 */
397 if ((filp->f_flags & O_NONBLOCK) ||
398 test_bit(TTY_IO_ERROR, &tty->flags)) {
399 port->flags |= ASYNC_NORMAL_ACTIVE;
400 return 0;
401 }
402
403 if (tty->termios->c_cflag & CLOCAL)
404 do_clocal = 1;
405
406 /*
407 * Block waiting for the carrier detect and the line to become
408 * free (i.e., not in use by the callout). While we are in
409 * this loop, port->count is dropped by one, so that
410 * mxser_close() knows when to free things. We restore it upon
411 * exit, either normal or abnormal.
412 */
413 retval = 0;
414 add_wait_queue(&port->open_wait, &wait);
415
416 spin_lock_irqsave(&port->slock, flags);
417 if (!tty_hung_up_p(filp))
418 port->count--;
419 spin_unlock_irqrestore(&port->slock, flags);
420 port->blocked_open++;
421 while (1) {
422 spin_lock_irqsave(&port->slock, flags);
423 outb(inb(port->ioaddr + UART_MCR) |
424 UART_MCR_DTR | UART_MCR_RTS, port->ioaddr + UART_MCR);
425 spin_unlock_irqrestore(&port->slock, flags);
426 set_current_state(TASK_INTERRUPTIBLE);
427 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) {
428 if (port->flags & ASYNC_HUP_NOTIFY)
429 retval = -EAGAIN;
430 else
431 retval = -ERESTARTSYS;
432 break;
433 }
434 if (!(port->flags & ASYNC_CLOSING) &&
435 (do_clocal ||
436 (inb(port->ioaddr + UART_MSR) & UART_MSR_DCD)))
437 break;
438 if (signal_pending(current)) {
439 retval = -ERESTARTSYS;
440 break;
441 }
442 schedule();
443 }
444 set_current_state(TASK_RUNNING);
445 remove_wait_queue(&port->open_wait, &wait);
446 if (!tty_hung_up_p(filp))
447 port->count++;
448 port->blocked_open--;
449 if (retval)
450 return retval;
451 port->flags |= ASYNC_NORMAL_ACTIVE;
452 return 0;
453}
454
455static int mxser_set_baud(struct mxser_port *info, long newspd)
456{
457 int quot = 0;
458 unsigned char cval;
459 int ret = 0;
460 unsigned long flags;
461
462 if (!info->tty || !info->tty->termios)
463 return ret;
464
465 if (!(info->ioaddr))
466 return ret;
467
468 if (newspd > info->max_baud)
469 return 0;
470
471 info->realbaud = newspd;
472 if (newspd == 134) {
473 quot = (2 * info->baud_base / 269);
474 } else if (newspd) {
475 quot = info->baud_base / newspd;
476 if (quot == 0)
477 quot = 1;
478 } else {
479 quot = 0;
480 }
481
482 info->timeout = ((info->xmit_fifo_size * HZ * 10 * quot) / info->baud_base);
483 info->timeout += HZ / 50; /* Add .02 seconds of slop */
484
485 if (quot) {
486 spin_lock_irqsave(&info->slock, flags);
487 info->MCR |= UART_MCR_DTR;
488 outb(info->MCR, info->ioaddr + UART_MCR);
489 spin_unlock_irqrestore(&info->slock, flags);
490 } else {
491 spin_lock_irqsave(&info->slock, flags);
492 info->MCR &= ~UART_MCR_DTR;
493 outb(info->MCR, info->ioaddr + UART_MCR);
494 spin_unlock_irqrestore(&info->slock, flags);
495 return ret;
496 }
497
498 cval = inb(info->ioaddr + UART_LCR);
499
500 outb(cval | UART_LCR_DLAB, info->ioaddr + UART_LCR); /* set DLAB */
501
502 outb(quot & 0xff, info->ioaddr + UART_DLL); /* LS of divisor */
503 outb(quot >> 8, info->ioaddr + UART_DLM); /* MS of divisor */
504 outb(cval, info->ioaddr + UART_LCR); /* reset DLAB */
505
506
507 return ret;
508}
509
510/*
511 * This routine is called to set the UART divisor registers to match
512 * the specified baud rate for a serial port.
513 */
514static int mxser_change_speed(struct mxser_port *info,
515 struct ktermios *old_termios)
516{
517 unsigned cflag, cval, fcr;
518 int ret = 0;
519 unsigned char status;
520 long baud;
521 unsigned long flags;
522
523 if (!info->tty || !info->tty->termios)
524 return ret;
525 cflag = info->tty->termios->c_cflag;
526 if (!(info->ioaddr))
527 return ret;
528
529 if (mxser_set_baud_method[info->tty->index] == 0) {
530 baud = tty_get_baud_rate(info->tty);
531 mxser_set_baud(info, baud);
532 }
533
534 /* byte size and parity */
535 switch (cflag & CSIZE) {
536 case CS5:
537 cval = 0x00;
538 break;
539 case CS6:
540 cval = 0x01;
541 break;
542 case CS7:
543 cval = 0x02;
544 break;
545 case CS8:
546 cval = 0x03;
547 break;
548 default:
549 cval = 0x00;
550 break; /* too keep GCC shut... */
551 }
552 if (cflag & CSTOPB)
553 cval |= 0x04;
554 if (cflag & PARENB)
555 cval |= UART_LCR_PARITY;
556 if (!(cflag & PARODD))
557 cval |= UART_LCR_EPAR;
558 if (cflag & CMSPAR)
559 cval |= UART_LCR_SPAR;
560
561 if ((info->type == PORT_8250) || (info->type == PORT_16450)) {
562 if (info->board->chip_flag) {
563 fcr = UART_FCR_ENABLE_FIFO;
564 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
565 SET_MOXA_MUST_FIFO_VALUE(info);
566 } else
567 fcr = 0;
568 } else {
569 fcr = UART_FCR_ENABLE_FIFO;
570 if (info->board->chip_flag) {
571 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
572 SET_MOXA_MUST_FIFO_VALUE(info);
573 } else {
574 switch (info->rx_trigger) {
575 case 1:
576 fcr |= UART_FCR_TRIGGER_1;
577 break;
578 case 4:
579 fcr |= UART_FCR_TRIGGER_4;
580 break;
581 case 8:
582 fcr |= UART_FCR_TRIGGER_8;
583 break;
584 default:
585 fcr |= UART_FCR_TRIGGER_14;
586 break;
587 }
588 }
589 }
590
591 /* CTS flow control flag and modem status interrupts */
592 info->IER &= ~UART_IER_MSI;
593 info->MCR &= ~UART_MCR_AFE;
594 if (cflag & CRTSCTS) {
595 info->flags |= ASYNC_CTS_FLOW;
596 info->IER |= UART_IER_MSI;
597 if ((info->type == PORT_16550A) || (info->board->chip_flag)) {
598 info->MCR |= UART_MCR_AFE;
599 } else {
600 status = inb(info->ioaddr + UART_MSR);
601 if (info->tty->hw_stopped) {
602 if (status & UART_MSR_CTS) {
603 info->tty->hw_stopped = 0;
604 if (info->type != PORT_16550A &&
605 !info->board->chip_flag) {
606 outb(info->IER & ~UART_IER_THRI,
607 info->ioaddr +
608 UART_IER);
609 info->IER |= UART_IER_THRI;
610 outb(info->IER, info->ioaddr +
611 UART_IER);
612 }
613 set_bit(MXSER_EVENT_TXLOW, &info->event);
614 schedule_work(&info->tqueue); }
615 } else {
616 if (!(status & UART_MSR_CTS)) {
617 info->tty->hw_stopped = 1;
618 if ((info->type != PORT_16550A) &&
619 (!info->board->chip_flag)) {
620 info->IER &= ~UART_IER_THRI;
621 outb(info->IER, info->ioaddr +
622 UART_IER);
623 }
624 }
625 }
626 }
627 } else {
628 info->flags &= ~ASYNC_CTS_FLOW;
629 }
630 outb(info->MCR, info->ioaddr + UART_MCR);
631 if (cflag & CLOCAL) {
632 info->flags &= ~ASYNC_CHECK_CD;
633 } else {
634 info->flags |= ASYNC_CHECK_CD;
635 info->IER |= UART_IER_MSI;
636 }
637 outb(info->IER, info->ioaddr + UART_IER);
638
639 /*
640 * Set up parity check flag
641 */
642 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
643 if (I_INPCK(info->tty))
644 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
645 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
646 info->read_status_mask |= UART_LSR_BI;
647
648 info->ignore_status_mask = 0;
649
650 if (I_IGNBRK(info->tty)) {
651 info->ignore_status_mask |= UART_LSR_BI;
652 info->read_status_mask |= UART_LSR_BI;
653 /*
654 * If we're ignore parity and break indicators, ignore
655 * overruns too. (For real raw support).
656 */
657 if (I_IGNPAR(info->tty)) {
658 info->ignore_status_mask |=
659 UART_LSR_OE |
660 UART_LSR_PE |
661 UART_LSR_FE;
662 info->read_status_mask |=
663 UART_LSR_OE |
664 UART_LSR_PE |
665 UART_LSR_FE;
666 }
667 }
668 if (info->board->chip_flag) {
669 spin_lock_irqsave(&info->slock, flags);
670 SET_MOXA_MUST_XON1_VALUE(info->ioaddr, START_CHAR(info->tty));
671 SET_MOXA_MUST_XOFF1_VALUE(info->ioaddr, STOP_CHAR(info->tty));
672 if (I_IXON(info->tty)) {
673 ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->ioaddr);
674 } else {
675 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->ioaddr);
676 }
677 if (I_IXOFF(info->tty)) {
678 ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->ioaddr);
679 } else {
680 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->ioaddr);
681 }
682 spin_unlock_irqrestore(&info->slock, flags);
683 }
684
685
686 outb(fcr, info->ioaddr + UART_FCR); /* set fcr */
687 outb(cval, info->ioaddr + UART_LCR);
688
689 return ret;
690}
691
692static void mxser_check_modem_status(struct mxser_port *port, int status)
693{
694 /* update input line counters */
695 if (status & UART_MSR_TERI)
696 port->icount.rng++;
697 if (status & UART_MSR_DDSR)
698 port->icount.dsr++;
699 if (status & UART_MSR_DDCD)
700 port->icount.dcd++;
701 if (status & UART_MSR_DCTS)
702 port->icount.cts++;
703 port->mon_data.modem_status = status;
704 wake_up_interruptible(&port->delta_msr_wait);
705
706 if ((port->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
707 if (status & UART_MSR_DCD)
708 wake_up_interruptible(&port->open_wait);
709 schedule_work(&port->tqueue);
710 }
711
712 if (port->flags & ASYNC_CTS_FLOW) {
713 if (port->tty->hw_stopped) {
714 if (status & UART_MSR_CTS) {
715 port->tty->hw_stopped = 0;
716
717 if ((port->type != PORT_16550A) &&
718 (!port->board->chip_flag)) {
719 outb(port->IER & ~UART_IER_THRI,
720 port->ioaddr + UART_IER);
721 port->IER |= UART_IER_THRI;
722 outb(port->IER, port->ioaddr +
723 UART_IER);
724 }
725 set_bit(MXSER_EVENT_TXLOW, &port->event);
726 schedule_work(&port->tqueue);
727 }
728 } else {
729 if (!(status & UART_MSR_CTS)) {
730 port->tty->hw_stopped = 1;
731 if (port->type != PORT_16550A &&
732 !port->board->chip_flag) {
733 port->IER &= ~UART_IER_THRI;
734 outb(port->IER, port->ioaddr +
735 UART_IER);
736 }
737 }
738 }
739 }
740}
741
742static int mxser_startup(struct mxser_port *info)
743{
744 unsigned long page;
745 unsigned long flags;
746
747 page = __get_free_page(GFP_KERNEL);
748 if (!page)
749 return -ENOMEM;
750
751 spin_lock_irqsave(&info->slock, flags);
752
753 if (info->flags & ASYNC_INITIALIZED) {
754 free_page(page);
755 spin_unlock_irqrestore(&info->slock, flags);
756 return 0;
757 }
758
759 if (!info->ioaddr || !info->type) {
760 if (info->tty)
761 set_bit(TTY_IO_ERROR, &info->tty->flags);
762 free_page(page);
763 spin_unlock_irqrestore(&info->slock, flags);
764 return 0;
765 }
766 if (info->xmit_buf)
767 free_page(page);
768 else
769 info->xmit_buf = (unsigned char *) page;
770
771 /*
772 * Clear the FIFO buffers and disable them
773 * (they will be reenabled in mxser_change_speed())
774 */
775 if (info->board->chip_flag)
776 outb((UART_FCR_CLEAR_RCVR |
777 UART_FCR_CLEAR_XMIT |
778 MOXA_MUST_FCR_GDA_MODE_ENABLE), info->ioaddr + UART_FCR);
779 else
780 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
781 info->ioaddr + UART_FCR);
782
783 /*
784 * At this point there's no way the LSR could still be 0xFF;
785 * if it is, then bail out, because there's likely no UART
786 * here.
787 */
788 if (inb(info->ioaddr + UART_LSR) == 0xff) {
789 spin_unlock_irqrestore(&info->slock, flags);
790 if (capable(CAP_SYS_ADMIN)) {
791 if (info->tty)
792 set_bit(TTY_IO_ERROR, &info->tty->flags);
793 return 0;
794 } else
795 return -ENODEV;
796 }
797
798 /*
799 * Clear the interrupt registers.
800 */
801 (void) inb(info->ioaddr + UART_LSR);
802 (void) inb(info->ioaddr + UART_RX);
803 (void) inb(info->ioaddr + UART_IIR);
804 (void) inb(info->ioaddr + UART_MSR);
805
806 /*
807 * Now, initialize the UART
808 */
809 outb(UART_LCR_WLEN8, info->ioaddr + UART_LCR); /* reset DLAB */
810 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
811 outb(info->MCR, info->ioaddr + UART_MCR);
812
813 /*
814 * Finally, enable interrupts
815 */
816 info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
817
818 if (info->board->chip_flag)
819 info->IER |= MOXA_MUST_IER_EGDAI;
820 outb(info->IER, info->ioaddr + UART_IER); /* enable interrupts */
821
822 /*
823 * And clear the interrupt registers again for luck.
824 */
825 (void) inb(info->ioaddr + UART_LSR);
826 (void) inb(info->ioaddr + UART_RX);
827 (void) inb(info->ioaddr + UART_IIR);
828 (void) inb(info->ioaddr + UART_MSR);
829
830 if (info->tty)
831 clear_bit(TTY_IO_ERROR, &info->tty->flags);
832 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
833
834 /*
835 * and set the speed of the serial port
836 */
837 spin_unlock_irqrestore(&info->slock, flags);
838 mxser_change_speed(info, NULL);
839
840 info->flags |= ASYNC_INITIALIZED;
841 return 0;
842}
843
844/*
845 * This routine will shutdown a serial port; interrupts maybe disabled, and
846 * DTR is dropped if the hangup on close termio flag is on.
847 */
848static void mxser_shutdown(struct mxser_port *info)
849{
850 unsigned long flags;
851
852 if (!(info->flags & ASYNC_INITIALIZED))
853 return;
854
855 spin_lock_irqsave(&info->slock, flags);
856
857 /*
858 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
859 * here so the queue might never be waken up
860 */
861 wake_up_interruptible(&info->delta_msr_wait);
862
863 /*
864 * Free the IRQ, if necessary
865 */
866 if (info->xmit_buf) {
867 free_page((unsigned long) info->xmit_buf);
868 info->xmit_buf = NULL;
869 }
870
871 info->IER = 0;
872 outb(0x00, info->ioaddr + UART_IER);
873
874 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
875 info->MCR &= ~(UART_MCR_DTR | UART_MCR_RTS);
876 outb(info->MCR, info->ioaddr + UART_MCR);
877
878 /* clear Rx/Tx FIFO's */
879 if (info->board->chip_flag)
880 outb(UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT |
881 MOXA_MUST_FCR_GDA_MODE_ENABLE,
882 info->ioaddr + UART_FCR);
883 else
884 outb(UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
885 info->ioaddr + UART_FCR);
886
887 /* read data port to reset things */
888 (void) inb(info->ioaddr + UART_RX);
889
890 if (info->tty)
891 set_bit(TTY_IO_ERROR, &info->tty->flags);
892
893 info->flags &= ~ASYNC_INITIALIZED;
894
895 if (info->board->chip_flag)
896 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info->ioaddr);
897
898 spin_unlock_irqrestore(&info->slock, flags);
899}
900
901/*
902 * This routine is called whenever a serial port is opened. It
903 * enables interrupts for a serial port, linking in its async structure into
904 * the IRQ chain. It also performs the serial-specific
905 * initialization for the tty structure.
906 */
907static int mxser_open(struct tty_struct *tty, struct file *filp)
908{
909 struct mxser_port *info;
910 int retval, line;
911
912 /* initialize driver_data in case something fails */
913 tty->driver_data = NULL;
914
915 line = tty->index;
916 if (line == MXSER_PORTS)
917 return 0;
918 if (line < 0 || line > MXSER_PORTS)
919 return -ENODEV;
920 info = &mxser_boards[line / MXSER_PORTS_PER_BOARD].ports[line % MXSER_PORTS_PER_BOARD];
921 if (!info->ioaddr)
922 return -ENODEV;
923
924 tty->driver_data = info;
925 info->tty = tty;
926 /*
927 * Start up serial port
928 */
929 info->count++;
930 retval = mxser_startup(info);
931 if (retval)
932 return retval;
933
934 retval = mxser_block_til_ready(tty, filp, info);
935 if (retval)
936 return retval;
937
938 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
939 if (tty->driver->subtype == SERIAL_TYPE_NORMAL)
940 *tty->termios = info->normal_termios;
941 else
942 *tty->termios = info->callout_termios;
943 mxser_change_speed(info, NULL);
944 }
945
946 info->session = process_session(current);
947 info->pgrp = process_group(current);
948
949 /* unmark here for very high baud rate (ex. 921600 bps) used */
950 tty->low_latency = 1;
951 return 0;
952}
953
954/*
955 * This routine is called when the serial port gets closed. First, we
956 * wait for the last remaining data to be sent. Then, we unlink its
957 * async structure from the interrupt chain if necessary, and we free
958 * that IRQ if nothing is left in the chain.
959 */
960static void mxser_close(struct tty_struct *tty, struct file *filp)
961{
962 struct mxser_port *info = tty->driver_data;
963
964 unsigned long timeout;
965 unsigned long flags;
966
967 if (tty->index == MXSER_PORTS)
968 return;
969 if (!info)
970 return;
971
972 spin_lock_irqsave(&info->slock, flags);
973
974 if (tty_hung_up_p(filp)) {
975 spin_unlock_irqrestore(&info->slock, flags);
976 return;
977 }
978 if ((tty->count == 1) && (info->count != 1)) {
979 /*
980 * Uh, oh. tty->count is 1, which means that the tty
981 * structure will be freed. Info->count should always
982 * be one in these conditions. If it's greater than
983 * one, we've got real problems, since it means the
984 * serial port won't be shutdown.
985 */
986 printk(KERN_ERR "mxser_close: bad serial port count; "
987 "tty->count is 1, info->count is %d\n", info->count);
988 info->count = 1;
989 }
990 if (--info->count < 0) {
991 printk(KERN_ERR "mxser_close: bad serial port count for "
992 "ttys%d: %d\n", tty->index, info->count);
993 info->count = 0;
994 }
995 if (info->count) {
996 spin_unlock_irqrestore(&info->slock, flags);
997 return;
998 }
999 info->flags |= ASYNC_CLOSING;
1000 spin_unlock_irqrestore(&info->slock, flags);
1001 /*
1002 * Save the termios structure, since this port may have
1003 * separate termios for callout and dialin.
1004 */
1005 if (info->flags & ASYNC_NORMAL_ACTIVE)
1006 info->normal_termios = *tty->termios;
1007 /*
1008 * Now we wait for the transmit buffer to clear; and we notify
1009 * the line discipline to only process XON/XOFF characters.
1010 */
1011 tty->closing = 1;
1012 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1013 tty_wait_until_sent(tty, info->closing_wait);
1014 /*
1015 * At this point we stop accepting input. To do this, we
1016 * disable the receive line status interrupts, and tell the
1017 * interrupt driver to stop checking the data ready bit in the
1018 * line status register.
1019 */
1020 info->IER &= ~UART_IER_RLSI;
1021 if (info->board->chip_flag)
1022 info->IER &= ~MOXA_MUST_RECV_ISR;
1023
1024 if (info->flags & ASYNC_INITIALIZED) {
1025 outb(info->IER, info->ioaddr + UART_IER);
1026 /*
1027 * Before we drop DTR, make sure the UART transmitter
1028 * has completely drained; this is especially
1029 * important if there is a transmit FIFO!
1030 */
1031 timeout = jiffies + HZ;
1032 while (!(inb(info->ioaddr + UART_LSR) & UART_LSR_TEMT)) {
1033 schedule_timeout_interruptible(5);
1034 if (time_after(jiffies, timeout))
1035 break;
1036 }
1037 }
1038 mxser_shutdown(info);
1039
1040 if (tty->driver->flush_buffer)
1041 tty->driver->flush_buffer(tty);
1042
1043 tty_ldisc_flush(tty);
1044
1045 tty->closing = 0;
1046 info->event = 0;
1047 info->tty = NULL;
1048 if (info->blocked_open) {
1049 if (info->close_delay)
1050 schedule_timeout_interruptible(info->close_delay);
1051 wake_up_interruptible(&info->open_wait);
1052 }
1053
1054 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1055 wake_up_interruptible(&info->close_wait);
1056
1057}
1058
1059static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
1060{
1061 int c, total = 0;
1062 struct mxser_port *info = tty->driver_data;
1063 unsigned long flags;
1064
1065 if (!info->xmit_buf)
1066 return 0;
1067
1068 while (1) {
1069 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1070 SERIAL_XMIT_SIZE - info->xmit_head));
1071 if (c <= 0)
1072 break;
1073
1074 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1075 spin_lock_irqsave(&info->slock, flags);
1076 info->xmit_head = (info->xmit_head + c) &
1077 (SERIAL_XMIT_SIZE - 1);
1078 info->xmit_cnt += c;
1079 spin_unlock_irqrestore(&info->slock, flags);
1080
1081 buf += c;
1082 count -= c;
1083 total += c;
1084 }
1085
1086 if (info->xmit_cnt && !tty->stopped) {
1087 if (!tty->hw_stopped ||
1088 (info->type == PORT_16550A) ||
1089 (info->board->chip_flag)) {
1090 spin_lock_irqsave(&info->slock, flags);
1091 outb(info->IER & ~UART_IER_THRI, info->ioaddr +
1092 UART_IER);
1093 info->IER |= UART_IER_THRI;
1094 outb(info->IER, info->ioaddr + UART_IER);
1095 spin_unlock_irqrestore(&info->slock, flags);
1096 }
1097 }
1098 return total;
1099}
1100
1101static void mxser_put_char(struct tty_struct *tty, unsigned char ch)
1102{
1103 struct mxser_port *info = tty->driver_data;
1104 unsigned long flags;
1105
1106 if (!info->xmit_buf)
1107 return;
1108
1109 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1110 return;
1111
1112 spin_lock_irqsave(&info->slock, flags);
1113 info->xmit_buf[info->xmit_head++] = ch;
1114 info->xmit_head &= SERIAL_XMIT_SIZE - 1;
1115 info->xmit_cnt++;
1116 spin_unlock_irqrestore(&info->slock, flags);
1117 if (!tty->stopped) {
1118 if (!tty->hw_stopped ||
1119 (info->type == PORT_16550A) ||
1120 info->board->chip_flag) {
1121 spin_lock_irqsave(&info->slock, flags);
1122 outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER);
1123 info->IER |= UART_IER_THRI;
1124 outb(info->IER, info->ioaddr + UART_IER);
1125 spin_unlock_irqrestore(&info->slock, flags);
1126 }
1127 }
1128}
1129
1130
1131static void mxser_flush_chars(struct tty_struct *tty)
1132{
1133 struct mxser_port *info = tty->driver_data;
1134 unsigned long flags;
1135
1136 if (info->xmit_cnt <= 0 ||
1137 tty->stopped ||
1138 !info->xmit_buf ||
1139 (tty->hw_stopped &&
1140 (info->type != PORT_16550A) &&
1141 (!info->board->chip_flag)
1142 ))
1143 return;
1144
1145 spin_lock_irqsave(&info->slock, flags);
1146
1147 outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER);
1148 info->IER |= UART_IER_THRI;
1149 outb(info->IER, info->ioaddr + UART_IER);
1150
1151 spin_unlock_irqrestore(&info->slock, flags);
1152}
1153
1154static int mxser_write_room(struct tty_struct *tty)
1155{
1156 struct mxser_port *info = tty->driver_data;
1157 int ret;
1158
1159 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1160 if (ret < 0)
1161 ret = 0;
1162 return ret;
1163}
1164
1165static int mxser_chars_in_buffer(struct tty_struct *tty)
1166{
1167 struct mxser_port *info = tty->driver_data;
1168 return info->xmit_cnt;
1169}
1170
1171static void mxser_flush_buffer(struct tty_struct *tty)
1172{
1173 struct mxser_port *info = tty->driver_data;
1174 char fcr;
1175 unsigned long flags;
1176
1177
1178 spin_lock_irqsave(&info->slock, flags);
1179 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1180
1181 fcr = inb(info->ioaddr + UART_FCR);
1182 outb((fcr | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
1183 info->ioaddr + UART_FCR);
1184 outb(fcr, info->ioaddr + UART_FCR);
1185
1186 spin_unlock_irqrestore(&info->slock, flags);
1187
1188 tty_wakeup(tty);
1189}
1190
1191/*
1192 * ------------------------------------------------------------
1193 * friends of mxser_ioctl()
1194 * ------------------------------------------------------------
1195 */
1196static int mxser_get_serial_info(struct mxser_port *info,
1197 struct serial_struct __user *retinfo)
1198{
1199 struct serial_struct tmp;
1200
1201 if (!retinfo)
1202 return -EFAULT;
1203 memset(&tmp, 0, sizeof(tmp));
1204 tmp.type = info->type;
1205 tmp.line = info->tty->index;
1206 tmp.port = info->ioaddr;
1207 tmp.irq = info->board->irq;
1208 tmp.flags = info->flags;
1209 tmp.baud_base = info->baud_base;
1210 tmp.close_delay = info->close_delay;
1211 tmp.closing_wait = info->closing_wait;
1212 tmp.custom_divisor = info->custom_divisor;
1213 tmp.hub6 = 0;
1214 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1215 return -EFAULT;
1216 return 0;
1217}
1218
1219static int mxser_set_serial_info(struct mxser_port *info,
1220 struct serial_struct __user *new_info)
1221{
1222 struct serial_struct new_serial;
1223 unsigned int flags;
1224 int retval = 0;
1225
1226 if (!new_info || !info->ioaddr)
1227 return -EFAULT;
1228 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
1229 return -EFAULT;
1230
1231 if ((new_serial.irq != info->board->irq) ||
1232 (new_serial.port != info->ioaddr) ||
1233 (new_serial.custom_divisor != info->custom_divisor) ||
1234 (new_serial.baud_base != info->baud_base))
1235 return -EPERM;
1236
1237 flags = info->flags & ASYNC_SPD_MASK;
1238
1239 if (!capable(CAP_SYS_ADMIN)) {
1240 if ((new_serial.baud_base != info->baud_base) ||
1241 (new_serial.close_delay != info->close_delay) ||
1242 ((new_serial.flags & ~ASYNC_USR_MASK) != (info->flags & ~ASYNC_USR_MASK)))
1243 return -EPERM;
1244 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1245 (new_serial.flags & ASYNC_USR_MASK));
1246 } else {
1247 /*
1248 * OK, past this point, all the error checking has been done.
1249 * At this point, we start making changes.....
1250 */
1251 info->flags = ((info->flags & ~ASYNC_FLAGS) |
1252 (new_serial.flags & ASYNC_FLAGS));
1253 info->close_delay = new_serial.close_delay * HZ / 100;
1254 info->closing_wait = new_serial.closing_wait * HZ / 100;
1255 info->tty->low_latency =
1256 (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1257 info->tty->low_latency = 0;
1258 }
1259
1260 info->type = new_serial.type;
1261
1262 process_txrx_fifo(info);
1263
1264 if (info->flags & ASYNC_INITIALIZED) {
1265 if (flags != (info->flags & ASYNC_SPD_MASK))
1266 mxser_change_speed(info, NULL);
1267 } else
1268 retval = mxser_startup(info);
1269
1270 return retval;
1271}
1272
1273/*
1274 * mxser_get_lsr_info - get line status register info
1275 *
1276 * Purpose: Let user call ioctl() to get info when the UART physically
1277 * is emptied. On bus types like RS485, the transmitter must
1278 * release the bus after transmitting. This must be done when
1279 * the transmit shift register is empty, not be done when the
1280 * transmit holding register is empty. This functionality
1281 * allows an RS485 driver to be written in user space.
1282 */
1283static int mxser_get_lsr_info(struct mxser_port *info,
1284 unsigned int __user *value)
1285{
1286 unsigned char status;
1287 unsigned int result;
1288 unsigned long flags;
1289
1290 spin_lock_irqsave(&info->slock, flags);
1291 status = inb(info->ioaddr + UART_LSR);
1292 spin_unlock_irqrestore(&info->slock, flags);
1293 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1294 return put_user(result, value);
1295}
1296
1297/*
1298 * This routine sends a break character out the serial port.
1299 */
1300static void mxser_send_break(struct mxser_port *info, int duration)
1301{
1302 unsigned long flags;
1303
1304 if (!info->ioaddr)
1305 return;
1306 set_current_state(TASK_INTERRUPTIBLE);
1307 spin_lock_irqsave(&info->slock, flags);
1308 outb(inb(info->ioaddr + UART_LCR) | UART_LCR_SBC,
1309 info->ioaddr + UART_LCR);
1310 spin_unlock_irqrestore(&info->slock, flags);
1311 schedule_timeout(duration);
1312 spin_lock_irqsave(&info->slock, flags);
1313 outb(inb(info->ioaddr + UART_LCR) & ~UART_LCR_SBC,
1314 info->ioaddr + UART_LCR);
1315 spin_unlock_irqrestore(&info->slock, flags);
1316}
1317
1318static int mxser_tiocmget(struct tty_struct *tty, struct file *file)
1319{
1320 struct mxser_port *info = tty->driver_data;
1321 unsigned char control, status;
1322 unsigned long flags;
1323
1324
1325 if (tty->index == MXSER_PORTS)
1326 return -ENOIOCTLCMD;
1327 if (test_bit(TTY_IO_ERROR, &tty->flags))
1328 return -EIO;
1329
1330 control = info->MCR;
1331
1332 spin_lock_irqsave(&info->slock, flags);
1333 status = inb(info->ioaddr + UART_MSR);
1334 if (status & UART_MSR_ANY_DELTA)
1335 mxser_check_modem_status(info, status);
1336 spin_unlock_irqrestore(&info->slock, flags);
1337 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
1338 ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) |
1339 ((status & UART_MSR_DCD) ? TIOCM_CAR : 0) |
1340 ((status & UART_MSR_RI) ? TIOCM_RNG : 0) |
1341 ((status & UART_MSR_DSR) ? TIOCM_DSR : 0) |
1342 ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
1343}
1344
1345static int mxser_tiocmset(struct tty_struct *tty, struct file *file,
1346 unsigned int set, unsigned int clear)
1347{
1348 struct mxser_port *info = tty->driver_data;
1349 unsigned long flags;
1350
1351
1352 if (tty->index == MXSER_PORTS)
1353 return -ENOIOCTLCMD;
1354 if (test_bit(TTY_IO_ERROR, &tty->flags))
1355 return -EIO;
1356
1357 spin_lock_irqsave(&info->slock, flags);
1358
1359 if (set & TIOCM_RTS)
1360 info->MCR |= UART_MCR_RTS;
1361 if (set & TIOCM_DTR)
1362 info->MCR |= UART_MCR_DTR;
1363
1364 if (clear & TIOCM_RTS)
1365 info->MCR &= ~UART_MCR_RTS;
1366 if (clear & TIOCM_DTR)
1367 info->MCR &= ~UART_MCR_DTR;
1368
1369 outb(info->MCR, info->ioaddr + UART_MCR);
1370 spin_unlock_irqrestore(&info->slock, flags);
1371 return 0;
1372}
1373
1374static int mxser_program_mode(int port)
1375{
1376 int id, i, j, n;
1377
1378 spin_lock(&gm_lock);
1379 outb(0, port);
1380 outb(0, port);
1381 outb(0, port);
1382 (void)inb(port);
1383 (void)inb(port);
1384 outb(0, port);
1385 (void)inb(port);
1386 spin_unlock(&gm_lock);
1387
1388 id = inb(port + 1) & 0x1F;
1389 if ((id != C168_ASIC_ID) &&
1390 (id != C104_ASIC_ID) &&
1391 (id != C102_ASIC_ID) &&
1392 (id != CI132_ASIC_ID) &&
1393 (id != CI134_ASIC_ID) &&
1394 (id != CI104J_ASIC_ID))
1395 return -1;
1396 for (i = 0, j = 0; i < 4; i++) {
1397 n = inb(port + 2);
1398 if (n == 'M') {
1399 j = 1;
1400 } else if ((j == 1) && (n == 1)) {
1401 j = 2;
1402 break;
1403 } else
1404 j = 0;
1405 }
1406 if (j != 2)
1407 id = -2;
1408 return id;
1409}
1410
1411static void mxser_normal_mode(int port)
1412{
1413 int i, n;
1414
1415 outb(0xA5, port + 1);
1416 outb(0x80, port + 3);
1417 outb(12, port + 0); /* 9600 bps */
1418 outb(0, port + 1);
1419 outb(0x03, port + 3); /* 8 data bits */
1420 outb(0x13, port + 4); /* loop back mode */
1421 for (i = 0; i < 16; i++) {
1422 n = inb(port + 5);
1423 if ((n & 0x61) == 0x60)
1424 break;
1425 if ((n & 1) == 1)
1426 (void)inb(port);
1427 }
1428 outb(0x00, port + 4);
1429}
1430
1431#define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
1432#define CHIP_DO 0x02 /* Serial Data Output in Eprom */
1433#define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
1434#define CHIP_DI 0x08 /* Serial Data Input in Eprom */
1435#define EN_CCMD 0x000 /* Chip's command register */
1436#define EN0_RSARLO 0x008 /* Remote start address reg 0 */
1437#define EN0_RSARHI 0x009 /* Remote start address reg 1 */
1438#define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
1439#define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
1440#define EN0_DCFG 0x00E /* Data configuration reg WR */
1441#define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
1442#define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
1443#define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
1444static int mxser_read_register(int port, unsigned short *regs)
1445{
1446 int i, k, value, id;
1447 unsigned int j;
1448
1449 id = mxser_program_mode(port);
1450 if (id < 0)
1451 return id;
1452 for (i = 0; i < 14; i++) {
1453 k = (i & 0x3F) | 0x180;
1454 for (j = 0x100; j > 0; j >>= 1) {
1455 outb(CHIP_CS, port);
1456 if (k & j) {
1457 outb(CHIP_CS | CHIP_DO, port);
1458 outb(CHIP_CS | CHIP_DO | CHIP_SK, port); /* A? bit of read */
1459 } else {
1460 outb(CHIP_CS, port);
1461 outb(CHIP_CS | CHIP_SK, port); /* A? bit of read */
1462 }
1463 }
1464 (void)inb(port);
1465 value = 0;
1466 for (k = 0, j = 0x8000; k < 16; k++, j >>= 1) {
1467 outb(CHIP_CS, port);
1468 outb(CHIP_CS | CHIP_SK, port);
1469 if (inb(port) & CHIP_DI)
1470 value |= j;
1471 }
1472 regs[i] = value;
1473 outb(0, port);
1474 }
1475 mxser_normal_mode(port);
1476 return id;
1477}
1478
1479static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1480{
1481 struct mxser_port *port;
1482 int result, status;
1483 unsigned int i, j;
1484
1485 switch (cmd) {
1486 case MOXA_GET_CONF:
1487/* if (copy_to_user(argp, mxsercfg,
1488 sizeof(struct mxser_hwconf) * 4))
1489 return -EFAULT;
1490 return 0;*/
1491 return -ENXIO;
1492 case MOXA_GET_MAJOR:
1493 if (copy_to_user(argp, &ttymajor, sizeof(int)))
1494 return -EFAULT;
1495 return 0;
1496
1497 case MOXA_GET_CUMAJOR:
1498 if (copy_to_user(argp, &calloutmajor, sizeof(int)))
1499 return -EFAULT;
1500 return 0;
1501
1502 case MOXA_CHKPORTENABLE:
1503 result = 0;
1504
1505 for (i = 0; i < MXSER_BOARDS; i++)
1506 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++)
1507 if (mxser_boards[i].ports[j].ioaddr)
1508 result |= (1 << i);
1509
1510 return put_user(result, (unsigned long __user *)argp);
1511 case MOXA_GETDATACOUNT:
1512 if (copy_to_user(argp, &mxvar_log, sizeof(mxvar_log)))
1513 return -EFAULT;
1514 return 0;
1515 case MOXA_GETMSTATUS:
1516 for (i = 0; i < MXSER_BOARDS; i++)
1517 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) {
1518 port = &mxser_boards[i].ports[j];
1519
1520 GMStatus[i].ri = 0;
1521 if (!port->ioaddr) {
1522 GMStatus[i].dcd = 0;
1523 GMStatus[i].dsr = 0;
1524 GMStatus[i].cts = 0;
1525 continue;
1526 }
1527
1528 if (!port->tty || !port->tty->termios)
1529 GMStatus[i].cflag =
1530 port->normal_termios.c_cflag;
1531 else
1532 GMStatus[i].cflag =
1533 port->tty->termios->c_cflag;
1534
1535 status = inb(port->ioaddr + UART_MSR);
1536 if (status & 0x80 /*UART_MSR_DCD */ )
1537 GMStatus[i].dcd = 1;
1538 else
1539 GMStatus[i].dcd = 0;
1540
1541 if (status & 0x20 /*UART_MSR_DSR */ )
1542 GMStatus[i].dsr = 1;
1543 else
1544 GMStatus[i].dsr = 0;
1545
1546
1547 if (status & 0x10 /*UART_MSR_CTS */ )
1548 GMStatus[i].cts = 1;
1549 else
1550 GMStatus[i].cts = 0;
1551 }
1552 if (copy_to_user(argp, GMStatus,
1553 sizeof(struct mxser_mstatus) * MXSER_PORTS))
1554 return -EFAULT;
1555 return 0;
1556 case MOXA_ASPP_MON_EXT: {
1557 int status, p, shiftbit;
1558 unsigned long opmode;
1559 unsigned cflag, iflag;
1560
1561 for (i = 0; i < MXSER_BOARDS; i++)
1562 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) {
1563 port = &mxser_boards[i].ports[j];
1564 if (!port->ioaddr)
1565 continue;
1566
1567 status = mxser_get_msr(port->ioaddr, 0, i);
1568
1569 if (status & UART_MSR_TERI)
1570 port->icount.rng++;
1571 if (status & UART_MSR_DDSR)
1572 port->icount.dsr++;
1573 if (status & UART_MSR_DDCD)
1574 port->icount.dcd++;
1575 if (status & UART_MSR_DCTS)
1576 port->icount.cts++;
1577
1578 port->mon_data.modem_status = status;
1579 mon_data_ext.rx_cnt[i] = port->mon_data.rxcnt;
1580 mon_data_ext.tx_cnt[i] = port->mon_data.txcnt;
1581 mon_data_ext.up_rxcnt[i] =
1582 port->mon_data.up_rxcnt;
1583 mon_data_ext.up_txcnt[i] =
1584 port->mon_data.up_txcnt;
1585 mon_data_ext.modem_status[i] =
1586 port->mon_data.modem_status;
1587 mon_data_ext.baudrate[i] = port->realbaud;
1588
1589 if (!port->tty || !port->tty->termios) {
1590 cflag = port->normal_termios.c_cflag;
1591 iflag = port->normal_termios.c_iflag;
1592 } else {
1593 cflag = port->tty->termios->c_cflag;
1594 iflag = port->tty->termios->c_iflag;
1595 }
1596
1597 mon_data_ext.databits[i] = cflag & CSIZE;
1598
1599 mon_data_ext.stopbits[i] = cflag & CSTOPB;
1600
1601 mon_data_ext.parity[i] =
1602 cflag & (PARENB | PARODD | CMSPAR);
1603
1604 mon_data_ext.flowctrl[i] = 0x00;
1605
1606 if (cflag & CRTSCTS)
1607 mon_data_ext.flowctrl[i] |= 0x03;
1608
1609 if (iflag & (IXON | IXOFF))
1610 mon_data_ext.flowctrl[i] |= 0x0C;
1611
1612 if (port->type == PORT_16550A)
1613 mon_data_ext.fifo[i] = 1;
1614 else
1615 mon_data_ext.fifo[i] = 0;
1616
1617 p = i % 4;
1618 shiftbit = p * 2;
1619 opmode = inb(port->opmode_ioaddr) >> shiftbit;
1620 opmode &= OP_MODE_MASK;
1621
1622 mon_data_ext.iftype[i] = opmode;
1623
1624 }
1625 if (copy_to_user(argp, &mon_data_ext,
1626 sizeof(mon_data_ext)))
1627 return -EFAULT;
1628
1629 return 0;
1630
1631 } default:
1632 return -ENOIOCTLCMD;
1633 }
1634 return 0;
1635}
1636
1637static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1638 unsigned int cmd, unsigned long arg)
1639{
1640 struct mxser_port *info = tty->driver_data;
1641 struct async_icount cprev, cnow; /* kernel counter temps */
1642 struct serial_icounter_struct __user *p_cuser;
1643 unsigned long templ;
1644 unsigned long flags;
1645 void __user *argp = (void __user *)arg;
1646 int retval;
1647
1648 if (tty->index == MXSER_PORTS)
1649 return mxser_ioctl_special(cmd, argp);
1650
1651 if (cmd == MOXA_SET_OP_MODE || cmd == MOXA_GET_OP_MODE) {
1652 int p;
1653 unsigned long opmode;
1654 static unsigned char ModeMask[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1655 int shiftbit;
1656 unsigned char val, mask;
1657
1658 p = tty->index % 4;
1659 if (cmd == MOXA_SET_OP_MODE) {
1660 if (get_user(opmode, (int __user *) argp))
1661 return -EFAULT;
1662 if (opmode != RS232_MODE &&
1663 opmode != RS485_2WIRE_MODE &&
1664 opmode != RS422_MODE &&
1665 opmode != RS485_4WIRE_MODE)
1666 return -EFAULT;
1667 mask = ModeMask[p];
1668 shiftbit = p * 2;
1669 val = inb(info->opmode_ioaddr);
1670 val &= mask;
1671 val |= (opmode << shiftbit);
1672 outb(val, info->opmode_ioaddr);
1673 } else {
1674 shiftbit = p * 2;
1675 opmode = inb(info->opmode_ioaddr) >> shiftbit;
1676 opmode &= OP_MODE_MASK;
1677 if (copy_to_user(argp, &opmode, sizeof(int)))
1678 return -EFAULT;
1679 }
1680 return 0;
1681 }
1682
1683 if (cmd != TIOCGSERIAL && cmd != TIOCMIWAIT && cmd != TIOCGICOUNT &&
1684 test_bit(TTY_IO_ERROR, &tty->flags))
1685 return -EIO;
1686
1687 switch (cmd) {
1688 case TCSBRK: /* SVID version: non-zero arg --> no break */
1689 retval = tty_check_change(tty);
1690 if (retval)
1691 return retval;
1692 tty_wait_until_sent(tty, 0);
1693 if (!arg)
1694 mxser_send_break(info, HZ / 4); /* 1/4 second */
1695 return 0;
1696 case TCSBRKP: /* support for POSIX tcsendbreak() */
1697 retval = tty_check_change(tty);
1698 if (retval)
1699 return retval;
1700 tty_wait_until_sent(tty, 0);
1701 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1702 return 0;
1703 case TIOCGSOFTCAR:
1704 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
1705 case TIOCSSOFTCAR:
1706 if (get_user(templ, (unsigned long __user *) argp))
1707 return -EFAULT;
1708 arg = templ;
1709 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
1710 return 0;
1711 case TIOCGSERIAL:
1712 return mxser_get_serial_info(info, argp);
1713 case TIOCSSERIAL:
1714 return mxser_set_serial_info(info, argp);
1715 case TIOCSERGETLSR: /* Get line status register */
1716 return mxser_get_lsr_info(info, argp);
1717 /*
1718 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1719 * - mask passed in arg for lines of interest
1720 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1721 * Caller should use TIOCGICOUNT to see which one it was
1722 */
1723 case TIOCMIWAIT: {
1724 DECLARE_WAITQUEUE(wait, current);
1725 int ret;
1726 spin_lock_irqsave(&info->slock, flags);
1727 cprev = info->icount; /* note the counters on entry */
1728 spin_unlock_irqrestore(&info->slock, flags);
1729
1730 add_wait_queue(&info->delta_msr_wait, &wait);
1731 while (1) {
1732 spin_lock_irqsave(&info->slock, flags);
1733 cnow = info->icount; /* atomic copy */
1734 spin_unlock_irqrestore(&info->slock, flags);
1735
1736 set_current_state(TASK_INTERRUPTIBLE);
1737 if (((arg & TIOCM_RNG) &&
1738 (cnow.rng != cprev.rng)) ||
1739 ((arg & TIOCM_DSR) &&
1740 (cnow.dsr != cprev.dsr)) ||
1741 ((arg & TIOCM_CD) &&
1742 (cnow.dcd != cprev.dcd)) ||
1743 ((arg & TIOCM_CTS) &&
1744 (cnow.cts != cprev.cts))) {
1745 ret = 0;
1746 break;
1747 }
1748 /* see if a signal did it */
1749 if (signal_pending(current)) {
1750 ret = -ERESTARTSYS;
1751 break;
1752 }
1753 cprev = cnow;
1754 }
1755 current->state = TASK_RUNNING;
1756 remove_wait_queue(&info->delta_msr_wait, &wait);
1757 break;
1758 }
1759 /* NOTREACHED */
1760 /*
1761 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1762 * Return: write counters to the user passed counter struct
1763 * NB: both 1->0 and 0->1 transitions are counted except for
1764 * RI where only 0->1 is counted.
1765 */
1766 case TIOCGICOUNT:
1767 spin_lock_irqsave(&info->slock, flags);
1768 cnow = info->icount;
1769 spin_unlock_irqrestore(&info->slock, flags);
1770 p_cuser = argp;
1771 if (put_user(cnow.frame, &p_cuser->frame))
1772 return -EFAULT;
1773 if (put_user(cnow.brk, &p_cuser->brk))
1774 return -EFAULT;
1775 if (put_user(cnow.overrun, &p_cuser->overrun))
1776 return -EFAULT;
1777 if (put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
1778 return -EFAULT;
1779 if (put_user(cnow.parity, &p_cuser->parity))
1780 return -EFAULT;
1781 if (put_user(cnow.rx, &p_cuser->rx))
1782 return -EFAULT;
1783 if (put_user(cnow.tx, &p_cuser->tx))
1784 return -EFAULT;
1785 put_user(cnow.cts, &p_cuser->cts);
1786 put_user(cnow.dsr, &p_cuser->dsr);
1787 put_user(cnow.rng, &p_cuser->rng);
1788 put_user(cnow.dcd, &p_cuser->dcd);
1789 return 0;
1790 case MOXA_HighSpeedOn:
1791 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp);
1792 case MOXA_SDS_RSTICOUNTER:
1793 info->mon_data.rxcnt = 0;
1794 info->mon_data.txcnt = 0;
1795 return 0;
1796 case MOXA_ASPP_SETBAUD:{
1797 long baud;
1798 if (get_user(baud, (long __user *)argp))
1799 return -EFAULT;
1800 mxser_set_baud(info, baud);
1801 return 0;
1802 }
1803 case MOXA_ASPP_GETBAUD:
1804 if (copy_to_user(argp, &info->realbaud, sizeof(long)))
1805 return -EFAULT;
1806
1807 return 0;
1808
1809 case MOXA_ASPP_OQUEUE:{
1810 int len, lsr;
1811
1812 len = mxser_chars_in_buffer(tty);
1813
1814 lsr = inb(info->ioaddr + UART_LSR) & UART_LSR_TEMT;
1815
1816 len += (lsr ? 0 : 1);
1817
1818 if (copy_to_user(argp, &len, sizeof(int)))
1819 return -EFAULT;
1820
1821 return 0;
1822 }
1823 case MOXA_ASPP_MON: {
1824 int mcr, status;
1825
1826 status = mxser_get_msr(info->ioaddr, 1, tty->index);
1827 mxser_check_modem_status(info, status);
1828
1829 mcr = inb(info->ioaddr + UART_MCR);
1830 if (mcr & MOXA_MUST_MCR_XON_FLAG)
1831 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFHOLD;
1832 else
1833 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFHOLD;
1834
1835 if (mcr & MOXA_MUST_MCR_TX_XON)
1836 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFXENT;
1837 else
1838 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFXENT;
1839
1840 if (info->tty->hw_stopped)
1841 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD;
1842 else
1843 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD;
1844
1845 if (copy_to_user(argp, &info->mon_data,
1846 sizeof(struct mxser_mon)))
1847 return -EFAULT;
1848
1849 return 0;
1850 }
1851 case MOXA_ASPP_LSTATUS: {
1852 if (copy_to_user(argp, &info->err_shadow,
1853 sizeof(unsigned char)))
1854 return -EFAULT;
1855
1856 info->err_shadow = 0;
1857 return 0;
1858 }
1859 case MOXA_SET_BAUD_METHOD: {
1860 int method;
1861
1862 if (get_user(method, (int __user *)argp))
1863 return -EFAULT;
1864 mxser_set_baud_method[tty->index] = method;
1865 if (copy_to_user(argp, &method, sizeof(int)))
1866 return -EFAULT;
1867
1868 return 0;
1869 }
1870 default:
1871 return -ENOIOCTLCMD;
1872 }
1873 return 0;
1874}
1875
1876static void mxser_stoprx(struct tty_struct *tty)
1877{
1878 struct mxser_port *info = tty->driver_data;
1879
1880 info->ldisc_stop_rx = 1;
1881 if (I_IXOFF(tty)) {
1882 if (info->board->chip_flag) {
1883 info->IER &= ~MOXA_MUST_RECV_ISR;
1884 outb(info->IER, info->ioaddr + UART_IER);
1885 } else {
1886 info->x_char = STOP_CHAR(tty);
1887 outb(0, info->ioaddr + UART_IER);
1888 info->IER |= UART_IER_THRI;
1889 outb(info->IER, info->ioaddr + UART_IER);
1890 }
1891 }
1892
1893 if (info->tty->termios->c_cflag & CRTSCTS) {
1894 info->MCR &= ~UART_MCR_RTS;
1895 outb(info->MCR, info->ioaddr + UART_MCR);
1896 }
1897}
1898
1899/*
1900 * This routine is called by the upper-layer tty layer to signal that
1901 * incoming characters should be throttled.
1902 */
1903static void mxser_throttle(struct tty_struct *tty)
1904{
1905 mxser_stoprx(tty);
1906}
1907
1908static void mxser_unthrottle(struct tty_struct *tty)
1909{
1910 struct mxser_port *info = tty->driver_data;
1911
1912 /* startrx */
1913 info->ldisc_stop_rx = 0;
1914 if (I_IXOFF(tty)) {
1915 if (info->x_char)
1916 info->x_char = 0;
1917 else {
1918 if (info->board->chip_flag) {
1919 info->IER |= MOXA_MUST_RECV_ISR;
1920 outb(info->IER, info->ioaddr + UART_IER);
1921 } else {
1922 info->x_char = START_CHAR(tty);
1923 outb(0, info->ioaddr + UART_IER);
1924 info->IER |= UART_IER_THRI;
1925 outb(info->IER, info->ioaddr + UART_IER);
1926 }
1927 }
1928 }
1929
1930 if (info->tty->termios->c_cflag & CRTSCTS) {
1931 info->MCR |= UART_MCR_RTS;
1932 outb(info->MCR, info->ioaddr + UART_MCR);
1933 }
1934}
1935
1936/*
1937 * mxser_stop() and mxser_start()
1938 *
1939 * This routines are called before setting or resetting tty->stopped.
1940 * They enable or disable transmitter interrupts, as necessary.
1941 */
1942static void mxser_stop(struct tty_struct *tty)
1943{
1944 struct mxser_port *info = tty->driver_data;
1945 unsigned long flags;
1946
1947 spin_lock_irqsave(&info->slock, flags);
1948 if (info->IER & UART_IER_THRI) {
1949 info->IER &= ~UART_IER_THRI;
1950 outb(info->IER, info->ioaddr + UART_IER);
1951 }
1952 spin_unlock_irqrestore(&info->slock, flags);
1953}
1954
1955static void mxser_start(struct tty_struct *tty)
1956{
1957 struct mxser_port *info = tty->driver_data;
1958 unsigned long flags;
1959
1960 spin_lock_irqsave(&info->slock, flags);
1961 if (info->xmit_cnt && info->xmit_buf) {
1962 outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER);
1963 info->IER |= UART_IER_THRI;
1964 outb(info->IER, info->ioaddr + UART_IER);
1965 }
1966 spin_unlock_irqrestore(&info->slock, flags);
1967}
1968
1969static void mxser_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1970{
1971 struct mxser_port *info = tty->driver_data;
1972 unsigned long flags;
1973
1974 if ((tty->termios->c_cflag != old_termios->c_cflag) ||
1975 (RELEVANT_IFLAG(tty->termios->c_iflag) != RELEVANT_IFLAG(old_termios->c_iflag))) {
1976
1977 mxser_change_speed(info, old_termios);
1978
1979 if ((old_termios->c_cflag & CRTSCTS) &&
1980 !(tty->termios->c_cflag & CRTSCTS)) {
1981 tty->hw_stopped = 0;
1982 mxser_start(tty);
1983 }
1984 }
1985
1986 /* Handle sw stopped */
1987 if ((old_termios->c_iflag & IXON) &&
1988 !(tty->termios->c_iflag & IXON)) {
1989 tty->stopped = 0;
1990
1991 if (info->board->chip_flag) {
1992 spin_lock_irqsave(&info->slock, flags);
1993 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->ioaddr);
1994 spin_unlock_irqrestore(&info->slock, flags);
1995 }
1996
1997 mxser_start(tty);
1998 }
1999}
2000
2001/*
2002 * mxser_wait_until_sent() --- wait until the transmitter is empty
2003 */
2004static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
2005{
2006 struct mxser_port *info = tty->driver_data;
2007 unsigned long orig_jiffies, char_time;
2008 int lsr;
2009
2010 if (info->type == PORT_UNKNOWN)
2011 return;
2012
2013 if (info->xmit_fifo_size == 0)
2014 return; /* Just in case.... */
2015
2016 orig_jiffies = jiffies;
2017 /*
2018 * Set the check interval to be 1/5 of the estimated time to
2019 * send a single character, and make it at least 1. The check
2020 * interval should also be less than the timeout.
2021 *
2022 * Note: we have to use pretty tight timings here to satisfy
2023 * the NIST-PCTS.
2024 */
2025 char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
2026 char_time = char_time / 5;
2027 if (char_time == 0)
2028 char_time = 1;
2029 if (timeout && timeout < char_time)
2030 char_time = timeout;
2031 /*
2032 * If the transmitter hasn't cleared in twice the approximate
2033 * amount of time to send the entire FIFO, it probably won't
2034 * ever clear. This assumes the UART isn't doing flow
2035 * control, which is currently the case. Hence, if it ever
2036 * takes longer than info->timeout, this is probably due to a
2037 * UART bug of some kind. So, we clamp the timeout parameter at
2038 * 2*info->timeout.
2039 */
2040 if (!timeout || timeout > 2 * info->timeout)
2041 timeout = 2 * info->timeout;
2042#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2043 printk(KERN_DEBUG "In rs_wait_until_sent(%d) check=%lu...",
2044 timeout, char_time);
2045 printk("jiff=%lu...", jiffies);
2046#endif
2047 while (!((lsr = inb(info->ioaddr + UART_LSR)) & UART_LSR_TEMT)) {
2048#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2049 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
2050#endif
2051 schedule_timeout_interruptible(char_time);
2052 if (signal_pending(current))
2053 break;
2054 if (timeout && time_after(jiffies, orig_jiffies + timeout))
2055 break;
2056 }
2057 set_current_state(TASK_RUNNING);
2058
2059#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2060 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
2061#endif
2062}
2063
2064/*
2065 * This routine is called by tty_hangup() when a hangup is signaled.
2066 */
2067void mxser_hangup(struct tty_struct *tty)
2068{
2069 struct mxser_port *info = tty->driver_data;
2070
2071 mxser_flush_buffer(tty);
2072 mxser_shutdown(info);
2073 info->event = 0;
2074 info->count = 0;
2075 info->flags &= ~ASYNC_NORMAL_ACTIVE;
2076 info->tty = NULL;
2077 wake_up_interruptible(&info->open_wait);
2078}
2079
2080/*
2081 * mxser_rs_break() --- routine which turns the break handling on or off
2082 */
2083static void mxser_rs_break(struct tty_struct *tty, int break_state)
2084{
2085 struct mxser_port *info = tty->driver_data;
2086 unsigned long flags;
2087
2088 spin_lock_irqsave(&info->slock, flags);
2089 if (break_state == -1)
2090 outb(inb(info->ioaddr + UART_LCR) | UART_LCR_SBC,
2091 info->ioaddr + UART_LCR);
2092 else
2093 outb(inb(info->ioaddr + UART_LCR) & ~UART_LCR_SBC,
2094 info->ioaddr + UART_LCR);
2095 spin_unlock_irqrestore(&info->slock, flags);
2096}
2097
2098static void mxser_receive_chars(struct mxser_port *port, int *status)
2099{
2100 struct tty_struct *tty = port->tty;
2101 unsigned char ch, gdl;
2102 int ignored = 0;
2103 int cnt = 0;
2104 int recv_room;
2105 int max = 256;
2106 unsigned long flags;
2107
2108 spin_lock_irqsave(&port->slock, flags);
2109
2110 recv_room = tty->receive_room;
2111 if ((recv_room == 0) && (!port->ldisc_stop_rx))
2112 mxser_stoprx(tty);
2113
2114 if (port->board->chip_flag != MOXA_OTHER_UART) {
2115
2116 if (*status & UART_LSR_SPECIAL)
2117 goto intr_old;
2118 if (port->board->chip_flag == MOXA_MUST_MU860_HWID &&
2119 (*status & MOXA_MUST_LSR_RERR))
2120 goto intr_old;
2121 if (*status & MOXA_MUST_LSR_RERR)
2122 goto intr_old;
2123
2124 gdl = inb(port->ioaddr + MOXA_MUST_GDL_REGISTER);
2125
2126 if (port->board->chip_flag == MOXA_MUST_MU150_HWID)
2127 gdl &= MOXA_MUST_GDL_MASK;
2128 if (gdl >= recv_room) {
2129 if (!port->ldisc_stop_rx)
2130 mxser_stoprx(tty);
2131 }
2132 while (gdl--) {
2133 ch = inb(port->ioaddr + UART_RX);
2134 tty_insert_flip_char(tty, ch, 0);
2135 cnt++;
2136 }
2137 goto end_intr;
2138 }
2139intr_old:
2140
2141 do {
2142 if (max-- < 0)
2143 break;
2144
2145 ch = inb(port->ioaddr + UART_RX);
2146 if (port->board->chip_flag && (*status & UART_LSR_OE))
2147 outb(0x23, port->ioaddr + UART_FCR);
2148 *status &= port->read_status_mask;
2149 if (*status & port->ignore_status_mask) {
2150 if (++ignored > 100)
2151 break;
2152 } else {
2153 char flag = 0;
2154 if (*status & UART_LSR_SPECIAL) {
2155 if (*status & UART_LSR_BI) {
2156 flag = TTY_BREAK;
2157 port->icount.brk++;
2158
2159 if (port->flags & ASYNC_SAK)
2160 do_SAK(tty);
2161 } else if (*status & UART_LSR_PE) {
2162 flag = TTY_PARITY;
2163 port->icount.parity++;
2164 } else if (*status & UART_LSR_FE) {
2165 flag = TTY_FRAME;
2166 port->icount.frame++;
2167 } else if (*status & UART_LSR_OE) {
2168 flag = TTY_OVERRUN;
2169 port->icount.overrun++;
2170 }
2171 }
2172 tty_insert_flip_char(tty, ch, flag);
2173 cnt++;
2174 if (cnt >= recv_room) {
2175 if (!port->ldisc_stop_rx)
2176 mxser_stoprx(tty);
2177 break;
2178 }
2179
2180 }
2181
2182 if (port->board->chip_flag)
2183 break;
2184
2185 *status = inb(port->ioaddr + UART_LSR);
2186 } while (*status & UART_LSR_DR);
2187
2188end_intr:
2189 mxvar_log.rxcnt[port->tty->index] += cnt;
2190 port->mon_data.rxcnt += cnt;
2191 port->mon_data.up_rxcnt += cnt;
2192 spin_unlock_irqrestore(&port->slock, flags);
2193
2194 tty_flip_buffer_push(tty);
2195}
2196
2197static void mxser_transmit_chars(struct mxser_port *port)
2198{
2199 int count, cnt;
2200 unsigned long flags;
2201
2202 spin_lock_irqsave(&port->slock, flags);
2203
2204 if (port->x_char) {
2205 outb(port->x_char, port->ioaddr + UART_TX);
2206 port->x_char = 0;
2207 mxvar_log.txcnt[port->tty->index]++;
2208 port->mon_data.txcnt++;
2209 port->mon_data.up_txcnt++;
2210 port->icount.tx++;
2211 goto unlock;
2212 }
2213
2214 if (port->xmit_buf == 0)
2215 goto unlock;
2216
2217 if ((port->xmit_cnt <= 0) || port->tty->stopped ||
2218 (port->tty->hw_stopped &&
2219 (port->type != PORT_16550A) &&
2220 (!port->board->chip_flag))) {
2221 port->IER &= ~UART_IER_THRI;
2222 outb(port->IER, port->ioaddr + UART_IER);
2223 goto unlock;
2224 }
2225
2226 cnt = port->xmit_cnt;
2227 count = port->xmit_fifo_size;
2228 do {
2229 outb(port->xmit_buf[port->xmit_tail++],
2230 port->ioaddr + UART_TX);
2231 port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE - 1);
2232 if (--port->xmit_cnt <= 0)
2233 break;
2234 } while (--count > 0);
2235 mxvar_log.txcnt[port->tty->index] += (cnt - port->xmit_cnt);
2236
2237 port->mon_data.txcnt += (cnt - port->xmit_cnt);
2238 port->mon_data.up_txcnt += (cnt - port->xmit_cnt);
2239 port->icount.tx += (cnt - port->xmit_cnt);
2240
2241 if (port->xmit_cnt < WAKEUP_CHARS) {
2242 set_bit(MXSER_EVENT_TXLOW, &port->event);
2243 schedule_work(&port->tqueue);
2244 }
2245 if (port->xmit_cnt <= 0) {
2246 port->IER &= ~UART_IER_THRI;
2247 outb(port->IER, port->ioaddr + UART_IER);
2248 }
2249unlock:
2250 spin_unlock_irqrestore(&port->slock, flags);
2251}
2252
2253/*
2254 * This is the serial driver's generic interrupt routine
2255 */
2256static irqreturn_t mxser_interrupt(int irq, void *dev_id)
2257{
2258 int status, iir, i;
2259 struct mxser_board *brd = NULL;
2260 struct mxser_port *port;
2261 int max, irqbits, bits, msr;
2262 int pass_counter = 0;
2263 unsigned int int_cnt;
2264 int handled = IRQ_NONE;
2265
2266 for (i = 0; i < MXSER_BOARDS; i++)
2267 if (dev_id == &mxser_boards[i]) {
2268 brd = dev_id;
2269 break;
2270 }
2271
2272 if (i == MXSER_BOARDS)
2273 goto irq_stop;
2274 if (brd == NULL)
2275 goto irq_stop;
2276 max = brd->info->nports;
2277 while (1) {
2278 irqbits = inb(brd->vector) & brd->vector_mask;
2279 if (irqbits == brd->vector_mask)
2280 break;
2281
2282 handled = IRQ_HANDLED;
2283 for (i = 0, bits = 1; i < max; i++, irqbits |= bits, bits <<= 1) {
2284 if (irqbits == brd->vector_mask)
2285 break;
2286 if (bits & irqbits)
2287 continue;
2288 port = &brd->ports[i];
2289
2290 int_cnt = 0;
2291 do {
2292 iir = inb(port->ioaddr + UART_IIR);
2293 if (iir & UART_IIR_NO_INT)
2294 break;
2295 iir &= MOXA_MUST_IIR_MASK;
2296 if (!port->tty) {
2297 status = inb(port->ioaddr + UART_LSR);
2298 outb(0x27, port->ioaddr + UART_FCR);
2299 inb(port->ioaddr + UART_MSR);
2300 break;
2301 }
2302
2303 status = inb(port->ioaddr + UART_LSR);
2304
2305 if (status & UART_LSR_PE)
2306 port->err_shadow |= NPPI_NOTIFY_PARITY;
2307 if (status & UART_LSR_FE)
2308 port->err_shadow |= NPPI_NOTIFY_FRAMING;
2309 if (status & UART_LSR_OE)
2310 port->err_shadow |=
2311 NPPI_NOTIFY_HW_OVERRUN;
2312 if (status & UART_LSR_BI)
2313 port->err_shadow |= NPPI_NOTIFY_BREAK;
2314
2315 if (port->board->chip_flag) {
2316 if (iir == MOXA_MUST_IIR_GDA ||
2317 iir == MOXA_MUST_IIR_RDA ||
2318 iir == MOXA_MUST_IIR_RTO ||
2319 iir == MOXA_MUST_IIR_LSR)
2320 mxser_receive_chars(port,
2321 &status);
2322
2323 } else {
2324 status &= port->read_status_mask;
2325 if (status & UART_LSR_DR)
2326 mxser_receive_chars(port,
2327 &status);
2328 }
2329 msr = inb(port->ioaddr + UART_MSR);
2330 if (msr & UART_MSR_ANY_DELTA)
2331 mxser_check_modem_status(port, msr);
2332
2333 if (port->board->chip_flag) {
2334 if (iir == 0x02 && (status &
2335 UART_LSR_THRE))
2336 mxser_transmit_chars(port);
2337 } else {
2338 if (status & UART_LSR_THRE)
2339 mxser_transmit_chars(port);
2340 }
2341 } while (int_cnt++ < MXSER_ISR_PASS_LIMIT);
2342 }
2343 if (pass_counter++ > MXSER_ISR_PASS_LIMIT)
2344 break; /* Prevent infinite loops */
2345 }
2346
2347irq_stop:
2348 return handled;
2349}
2350
2351static const struct tty_operations mxser_ops = {
2352 .open = mxser_open,
2353 .close = mxser_close,
2354 .write = mxser_write,
2355 .put_char = mxser_put_char,
2356 .flush_chars = mxser_flush_chars,
2357 .write_room = mxser_write_room,
2358 .chars_in_buffer = mxser_chars_in_buffer,
2359 .flush_buffer = mxser_flush_buffer,
2360 .ioctl = mxser_ioctl,
2361 .throttle = mxser_throttle,
2362 .unthrottle = mxser_unthrottle,
2363 .set_termios = mxser_set_termios,
2364 .stop = mxser_stop,
2365 .start = mxser_start,
2366 .hangup = mxser_hangup,
2367 .break_ctl = mxser_rs_break,
2368 .wait_until_sent = mxser_wait_until_sent,
2369 .tiocmget = mxser_tiocmget,
2370 .tiocmset = mxser_tiocmset,
2371};
2372
2373/*
2374 * The MOXA Smartio/Industio serial driver boot-time initialization code!
2375 */
2376
2377static void mxser_release_res(struct mxser_board *brd, struct pci_dev *pdev,
2378 unsigned int irq)
2379{
2380 if (irq)
2381 free_irq(brd->irq, brd);
2382 if (pdev != NULL) { /* PCI */
2383 pci_release_region(pdev, 2);
2384 pci_release_region(pdev, 3);
2385 pci_dev_put(pdev);
2386 } else {
2387 release_region(brd->ports[0].ioaddr, 8 * brd->info->nports);
2388 release_region(brd->vector, 1);
2389 }
2390}
2391
2392static int __devinit mxser_initbrd(struct mxser_board *brd,
2393 struct pci_dev *pdev)
2394{
2395 struct mxser_port *info;
2396 unsigned int i;
2397 int retval;
2398
2399 printk(KERN_INFO "max. baud rate = %d bps.\n", brd->ports[0].max_baud);
2400
2401 for (i = 0; i < brd->info->nports; i++) {
2402 info = &brd->ports[i];
2403 info->board = brd;
2404 info->stop_rx = 0;
2405 info->ldisc_stop_rx = 0;
2406
2407 /* Enhance mode enabled here */
2408 if (brd->chip_flag != MOXA_OTHER_UART)
2409 ENABLE_MOXA_MUST_ENCHANCE_MODE(info->ioaddr);
2410
2411 info->flags = ASYNC_SHARE_IRQ;
2412 info->type = brd->uart_type;
2413
2414 process_txrx_fifo(info);
2415
2416 info->custom_divisor = info->baud_base * 16;
2417 info->close_delay = 5 * HZ / 10;
2418 info->closing_wait = 30 * HZ;
2419 INIT_WORK(&info->tqueue, mxser_do_softint);
2420 info->normal_termios = mxvar_sdriver->init_termios;
2421 init_waitqueue_head(&info->open_wait);
2422 init_waitqueue_head(&info->close_wait);
2423 init_waitqueue_head(&info->delta_msr_wait);
2424 memset(&info->mon_data, 0, sizeof(struct mxser_mon));
2425 info->err_shadow = 0;
2426 spin_lock_init(&info->slock);
2427
2428 /* before set INT ISR, disable all int */
2429 outb(inb(info->ioaddr + UART_IER) & 0xf0,
2430 info->ioaddr + UART_IER);
2431 }
2432 /*
2433 * Allocate the IRQ if necessary
2434 */
2435
2436 retval = request_irq(brd->irq, mxser_interrupt,
2437 (brd->ports[0].flags & ASYNC_SHARE_IRQ) ? IRQF_SHARED :
2438 IRQF_DISABLED, "mxser", brd);
2439 if (retval) {
2440 printk(KERN_ERR "Board %s: Request irq failed, IRQ (%d) may "
2441 "conflict with another device.\n",
2442 brd->info->name, brd->irq);
2443 /* We hold resources, we need to release them. */
2444 mxser_release_res(brd, pdev, 0);
2445 return retval;
2446 }
2447 return 0;
2448}
2449
2450static int __init mxser_get_ISA_conf(int cap, struct mxser_board *brd)
2451{
2452 int id, i, bits;
2453 unsigned short regs[16], irq;
2454 unsigned char scratch, scratch2;
2455
2456 brd->chip_flag = MOXA_OTHER_UART;
2457
2458 id = mxser_read_register(cap, regs);
2459 switch (id) {
2460 case C168_ASIC_ID:
2461 brd->info = &mxser_cards[0];
2462 break;
2463 case C104_ASIC_ID:
2464 brd->info = &mxser_cards[1];
2465 break;
2466 case CI104J_ASIC_ID:
2467 brd->info = &mxser_cards[2];
2468 break;
2469 case C102_ASIC_ID:
2470 brd->info = &mxser_cards[5];
2471 break;
2472 case CI132_ASIC_ID:
2473 brd->info = &mxser_cards[6];
2474 break;
2475 case CI134_ASIC_ID:
2476 brd->info = &mxser_cards[7];
2477 break;
2478 default:
2479 return 0;
2480 }
2481
2482 irq = 0;
2483 /* some ISA cards have 2 ports, but we want to see them as 4-port (why?)
2484 Flag-hack checks if configuration should be read as 2-port here. */
2485 if (brd->info->nports == 2 || (brd->info->flags & MXSER_HAS2)) {
2486 irq = regs[9] & 0xF000;
2487 irq = irq | (irq >> 4);
2488 if (irq != (regs[9] & 0xFF00))
2489 return MXSER_ERR_IRQ_CONFLIT;
2490 } else if (brd->info->nports == 4) {
2491 irq = regs[9] & 0xF000;
2492 irq = irq | (irq >> 4);
2493 irq = irq | (irq >> 8);
2494 if (irq != regs[9])
2495 return MXSER_ERR_IRQ_CONFLIT;
2496 } else if (brd->info->nports == 8) {
2497 irq = regs[9] & 0xF000;
2498 irq = irq | (irq >> 4);
2499 irq = irq | (irq >> 8);
2500 if ((irq != regs[9]) || (irq != regs[10]))
2501 return MXSER_ERR_IRQ_CONFLIT;
2502 }
2503
2504 if (!irq)
2505 return MXSER_ERR_IRQ;
2506 brd->irq = ((int)(irq & 0xF000) >> 12);
2507 for (i = 0; i < 8; i++)
2508 brd->ports[i].ioaddr = (int) regs[i + 1] & 0xFFF8;
2509 if ((regs[12] & 0x80) == 0)
2510 return MXSER_ERR_VECTOR;
2511 brd->vector = (int)regs[11]; /* interrupt vector */
2512 if (id == 1)
2513 brd->vector_mask = 0x00FF;
2514 else
2515 brd->vector_mask = 0x000F;
2516 for (i = 7, bits = 0x0100; i >= 0; i--, bits <<= 1) {
2517 if (regs[12] & bits) {
2518 brd->ports[i].baud_base = 921600;
2519 brd->ports[i].max_baud = 921600;
2520 } else {
2521 brd->ports[i].baud_base = 115200;
2522 brd->ports[i].max_baud = 115200;
2523 }
2524 }
2525 scratch2 = inb(cap + UART_LCR) & (~UART_LCR_DLAB);
2526 outb(scratch2 | UART_LCR_DLAB, cap + UART_LCR);
2527 outb(0, cap + UART_EFR); /* EFR is the same as FCR */
2528 outb(scratch2, cap + UART_LCR);
2529 outb(UART_FCR_ENABLE_FIFO, cap + UART_FCR);
2530 scratch = inb(cap + UART_IIR);
2531
2532 if (scratch & 0xC0)
2533 brd->uart_type = PORT_16550A;
2534 else
2535 brd->uart_type = PORT_16450;
2536 if (!request_region(brd->ports[0].ioaddr, 8 * brd->info->nports,
2537 "mxser(IO)"))
2538 return MXSER_ERR_IOADDR;
2539 if (!request_region(brd->vector, 1, "mxser(vector)")) {
2540 release_region(brd->ports[0].ioaddr, 8 * brd->info->nports);
2541 return MXSER_ERR_VECTOR;
2542 }
2543 return brd->info->nports;
2544}
2545
2546static int __devinit mxser_probe(struct pci_dev *pdev,
2547 const struct pci_device_id *ent)
2548{
2549 struct mxser_board *brd;
2550 unsigned int i, j;
2551 unsigned long ioaddress;
2552 int retval = -EINVAL;
2553
2554 for (i = 0; i < MXSER_BOARDS; i++)
2555 if (mxser_boards[i].info == NULL)
2556 break;
2557
2558 if (i >= MXSER_BOARDS) {
2559 printk(KERN_ERR "Too many Smartio/Industio family boards found "
2560 "(maximum %d), board not configured\n", MXSER_BOARDS);
2561 goto err;
2562 }
2563
2564 brd = &mxser_boards[i];
2565 brd->idx = i * MXSER_PORTS_PER_BOARD;
2566 printk(KERN_INFO "Found MOXA %s board (BusNo=%d, DevNo=%d)\n",
2567 mxser_cards[ent->driver_data].name,
2568 pdev->bus->number, PCI_SLOT(pdev->devfn));
2569
2570 retval = pci_enable_device(pdev);
2571 if (retval) {
2572 printk(KERN_ERR "Moxa SmartI/O PCI enable fail !\n");
2573 goto err;
2574 }
2575
2576 /* io address */
2577 ioaddress = pci_resource_start(pdev, 2);
2578 retval = pci_request_region(pdev, 2, "mxser(IO)");
2579 if (retval)
2580 goto err;
2581
2582 brd->info = &mxser_cards[ent->driver_data];
2583 for (i = 0; i < brd->info->nports; i++)
2584 brd->ports[i].ioaddr = ioaddress + 8 * i;
2585
2586 /* vector */
2587 ioaddress = pci_resource_start(pdev, 3);
2588 retval = pci_request_region(pdev, 3, "mxser(vector)");
2589 if (retval)
2590 goto err_relio;
2591 brd->vector = ioaddress;
2592
2593 /* irq */
2594 brd->irq = pdev->irq;
2595
2596 brd->chip_flag = CheckIsMoxaMust(brd->ports[0].ioaddr);
2597 brd->uart_type = PORT_16550A;
2598 brd->vector_mask = 0;
2599
2600 for (i = 0; i < brd->info->nports; i++) {
2601 for (j = 0; j < UART_INFO_NUM; j++) {
2602 if (Gpci_uart_info[j].type == brd->chip_flag) {
2603 brd->ports[i].max_baud =
2604 Gpci_uart_info[j].max_baud;
2605
2606 /* exception....CP-102 */
2607 if (brd->info->flags & MXSER_HIGHBAUD)
2608 brd->ports[i].max_baud = 921600;
2609 break;
2610 }
2611 }
2612 }
2613
2614 if (brd->chip_flag == MOXA_MUST_MU860_HWID) {
2615 for (i = 0; i < brd->info->nports; i++) {
2616 if (i < 4)
2617 brd->ports[i].opmode_ioaddr = ioaddress + 4;
2618 else
2619 brd->ports[i].opmode_ioaddr = ioaddress + 0x0c;
2620 }
2621 outb(0, ioaddress + 4); /* default set to RS232 mode */
2622 outb(0, ioaddress + 0x0c); /* default set to RS232 mode */
2623 }
2624
2625 for (i = 0; i < brd->info->nports; i++) {
2626 brd->vector_mask |= (1 << i);
2627 brd->ports[i].baud_base = 921600;
2628 }
2629
2630 /* mxser_initbrd will hook ISR. */
2631 if (mxser_initbrd(brd, pdev) < 0)
2632 goto err_relvec;
2633
2634 for (i = 0; i < brd->info->nports; i++)
2635 tty_register_device(mxvar_sdriver, brd->idx + i, &pdev->dev);
2636
2637 pci_set_drvdata(pdev, brd);
2638
2639 return 0;
2640err_relvec:
2641 pci_release_region(pdev, 3);
2642err_relio:
2643 pci_release_region(pdev, 2);
2644 brd->info = NULL;
2645err:
2646 return retval;
2647}
2648
2649static void __devexit mxser_remove(struct pci_dev *pdev)
2650{
2651 struct mxser_board *brd = pci_get_drvdata(pdev);
2652 unsigned int i;
2653
2654 for (i = 0; i < brd->info->nports; i++)
2655 tty_unregister_device(mxvar_sdriver, brd->idx + i);
2656
2657 mxser_release_res(brd, pdev, 1);
2658}
2659
2660static struct pci_driver mxser_driver = {
2661 .name = "mxser",
2662 .id_table = mxser_pcibrds,
2663 .probe = mxser_probe,
2664 .remove = __devexit_p(mxser_remove)
2665};
2666
2667static int __init mxser_module_init(void)
2668{
2669 struct mxser_board *brd;
2670 unsigned long cap;
2671 unsigned int i, m, isaloop;
2672 int retval, b;
2673
2674 pr_debug("Loading module mxser ...\n");
2675
2676 mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1);
2677 if (!mxvar_sdriver)
2678 return -ENOMEM;
2679 spin_lock_init(&gm_lock);
2680
2681 printk(KERN_INFO "MOXA Smartio/Industio family driver version %s\n",
2682 MXSER_VERSION);
2683
2684 /* Initialize the tty_driver structure */
2685 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
2686 mxvar_sdriver->name = "ttyMI";
2687 mxvar_sdriver->major = ttymajor;
2688 mxvar_sdriver->minor_start = 0;
2689 mxvar_sdriver->num = MXSER_PORTS + 1;
2690 mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL;
2691 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
2692 mxvar_sdriver->init_termios = tty_std_termios;
2693 mxvar_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
2694 mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_DYNAMIC_DEV;
2695 tty_set_operations(mxvar_sdriver, &mxser_ops);
2696
2697 retval = tty_register_driver(mxvar_sdriver);
2698 if (retval) {
2699 printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family "
2700 "tty driver !\n");
2701 goto err_put;
2702 }
2703
2704 mxvar_diagflag = 0;
2705
2706 m = 0;
2707 /* Start finding ISA boards here */
2708 for (isaloop = 0; isaloop < 2; isaloop++)
2709 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
2710 if (!isaloop)
2711 cap = mxserBoardCAP[b]; /* predefined */
2712 else
2713 cap = ioaddr[b]; /* module param */
2714
2715 if (!cap)
2716 continue;
2717
2718 brd = &mxser_boards[m];
2719 retval = mxser_get_ISA_conf(cap, brd);
2720
2721 if (retval != 0)
2722 printk(KERN_INFO "Found MOXA %s board "
2723 "(CAP=0x%x)\n",
2724 brd->info->name, ioaddr[b]);
2725
2726 if (retval <= 0) {
2727 if (retval == MXSER_ERR_IRQ)
2728 printk(KERN_ERR "Invalid interrupt "
2729 "number, board not "
2730 "configured\n");
2731 else if (retval == MXSER_ERR_IRQ_CONFLIT)
2732 printk(KERN_ERR "Invalid interrupt "
2733 "number, board not "
2734 "configured\n");
2735 else if (retval == MXSER_ERR_VECTOR)
2736 printk(KERN_ERR "Invalid interrupt "
2737 "vector, board not "
2738 "configured\n");
2739 else if (retval == MXSER_ERR_IOADDR)
2740 printk(KERN_ERR "Invalid I/O address, "
2741 "board not configured\n");
2742
2743 brd->info = NULL;
2744 continue;
2745 }
2746
2747 /* mxser_initbrd will hook ISR. */
2748 if (mxser_initbrd(brd, NULL) < 0) {
2749 brd->info = NULL;
2750 continue;
2751 }
2752
2753 brd->idx = m * MXSER_PORTS_PER_BOARD;
2754 for (i = 0; i < brd->info->nports; i++)
2755 tty_register_device(mxvar_sdriver, brd->idx + i,
2756 NULL);
2757
2758 m++;
2759 }
2760
2761 retval = pci_register_driver(&mxser_driver);
2762 if (retval) {
2763 printk(KERN_ERR "Can't register pci driver\n");
2764 if (!m) {
2765 retval = -ENODEV;
2766 goto err_unr;
2767 } /* else: we have some ISA cards under control */
2768 }
2769
2770 pr_debug("Done.\n");
2771
2772 return 0;
2773err_unr:
2774 tty_unregister_driver(mxvar_sdriver);
2775err_put:
2776 put_tty_driver(mxvar_sdriver);
2777 return retval;
2778}
2779
2780static void __exit mxser_module_exit(void)
2781{
2782 unsigned int i, j;
2783
2784 pr_debug("Unloading module mxser ...\n");
2785
2786 pci_unregister_driver(&mxser_driver);
2787
2788 for (i = 0; i < MXSER_BOARDS; i++) /* ISA remains */
2789 if (mxser_boards[i].info != NULL)
2790 for (j = 0; j < mxser_boards[i].info->nports; j++)
2791 tty_unregister_device(mxvar_sdriver,
2792 mxser_boards[i].idx + j);
2793 tty_unregister_driver(mxvar_sdriver);
2794 put_tty_driver(mxvar_sdriver);
2795
2796 for (i = 0; i < MXSER_BOARDS; i++)
2797 if (mxser_boards[i].info != NULL)
2798 mxser_release_res(&mxser_boards[i], NULL, 1);
2799
2800 pr_debug("Done.\n");
2801}
2802
2803module_init(mxser_module_init);
2804module_exit(mxser_module_exit);
diff --git a/drivers/char/mxser_new.h b/drivers/char/mxser_new.h
new file mode 100644
index 000000000000..a08f0ecb09ba
--- /dev/null
+++ b/drivers/char/mxser_new.h
@@ -0,0 +1,450 @@
1#ifndef _MXSER_H
2#define _MXSER_H
3
4/*
5 * Semi-public control interfaces
6 */
7
8/*
9 * MOXA ioctls
10 */
11
12#define MOXA 0x400
13#define MOXA_GETDATACOUNT (MOXA + 23)
14#define MOXA_GET_CONF (MOXA + 35)
15#define MOXA_DIAGNOSE (MOXA + 50)
16#define MOXA_CHKPORTENABLE (MOXA + 60)
17#define MOXA_HighSpeedOn (MOXA + 61)
18#define MOXA_GET_MAJOR (MOXA + 63)
19#define MOXA_GET_CUMAJOR (MOXA + 64)
20#define MOXA_GETMSTATUS (MOXA + 65)
21#define MOXA_SET_OP_MODE (MOXA + 66)
22#define MOXA_GET_OP_MODE (MOXA + 67)
23
24#define RS232_MODE 0
25#define RS485_2WIRE_MODE 1
26#define RS422_MODE 2
27#define RS485_4WIRE_MODE 3
28#define OP_MODE_MASK 3
29// above add by Victor Yu. 01-05-2004
30
31#define TTY_THRESHOLD_THROTTLE 128
32
33#define LO_WATER (TTY_FLIPBUF_SIZE)
34#define HI_WATER (TTY_FLIPBUF_SIZE*2*3/4)
35
36// added by James. 03-11-2004.
37#define MOXA_SDS_GETICOUNTER (MOXA + 68)
38#define MOXA_SDS_RSTICOUNTER (MOXA + 69)
39// (above) added by James.
40
41#define MOXA_ASPP_OQUEUE (MOXA + 70)
42#define MOXA_ASPP_SETBAUD (MOXA + 71)
43#define MOXA_ASPP_GETBAUD (MOXA + 72)
44#define MOXA_ASPP_MON (MOXA + 73)
45#define MOXA_ASPP_LSTATUS (MOXA + 74)
46#define MOXA_ASPP_MON_EXT (MOXA + 75)
47#define MOXA_SET_BAUD_METHOD (MOXA + 76)
48
49
50/* --------------------------------------------------- */
51
52#define NPPI_NOTIFY_PARITY 0x01
53#define NPPI_NOTIFY_FRAMING 0x02
54#define NPPI_NOTIFY_HW_OVERRUN 0x04
55#define NPPI_NOTIFY_SW_OVERRUN 0x08
56#define NPPI_NOTIFY_BREAK 0x10
57
58#define NPPI_NOTIFY_CTSHOLD 0x01 // Tx hold by CTS low
59#define NPPI_NOTIFY_DSRHOLD 0x02 // Tx hold by DSR low
60#define NPPI_NOTIFY_XOFFHOLD 0x08 // Tx hold by Xoff received
61#define NPPI_NOTIFY_XOFFXENT 0x10 // Xoff Sent
62
63//CheckIsMoxaMust return value
64#define MOXA_OTHER_UART 0x00
65#define MOXA_MUST_MU150_HWID 0x01
66#define MOXA_MUST_MU860_HWID 0x02
67
68// follow just for Moxa Must chip define.
69//
70// when LCR register (offset 0x03) write following value,
71// the Must chip will enter enchance mode. And write value
72// on EFR (offset 0x02) bit 6,7 to change bank.
73#define MOXA_MUST_ENTER_ENCHANCE 0xBF
74
75// when enhance mode enable, access on general bank register
76#define MOXA_MUST_GDL_REGISTER 0x07
77#define MOXA_MUST_GDL_MASK 0x7F
78#define MOXA_MUST_GDL_HAS_BAD_DATA 0x80
79
80#define MOXA_MUST_LSR_RERR 0x80 // error in receive FIFO
81// enchance register bank select and enchance mode setting register
82// when LCR register equal to 0xBF
83#define MOXA_MUST_EFR_REGISTER 0x02
84// enchance mode enable
85#define MOXA_MUST_EFR_EFRB_ENABLE 0x10
86// enchance reister bank set 0, 1, 2
87#define MOXA_MUST_EFR_BANK0 0x00
88#define MOXA_MUST_EFR_BANK1 0x40
89#define MOXA_MUST_EFR_BANK2 0x80
90#define MOXA_MUST_EFR_BANK3 0xC0
91#define MOXA_MUST_EFR_BANK_MASK 0xC0
92
93// set XON1 value register, when LCR=0xBF and change to bank0
94#define MOXA_MUST_XON1_REGISTER 0x04
95
96// set XON2 value register, when LCR=0xBF and change to bank0
97#define MOXA_MUST_XON2_REGISTER 0x05
98
99// set XOFF1 value register, when LCR=0xBF and change to bank0
100#define MOXA_MUST_XOFF1_REGISTER 0x06
101
102// set XOFF2 value register, when LCR=0xBF and change to bank0
103#define MOXA_MUST_XOFF2_REGISTER 0x07
104
105#define MOXA_MUST_RBRTL_REGISTER 0x04
106#define MOXA_MUST_RBRTH_REGISTER 0x05
107#define MOXA_MUST_RBRTI_REGISTER 0x06
108#define MOXA_MUST_THRTL_REGISTER 0x07
109#define MOXA_MUST_ENUM_REGISTER 0x04
110#define MOXA_MUST_HWID_REGISTER 0x05
111#define MOXA_MUST_ECR_REGISTER 0x06
112#define MOXA_MUST_CSR_REGISTER 0x07
113
114// good data mode enable
115#define MOXA_MUST_FCR_GDA_MODE_ENABLE 0x20
116// only good data put into RxFIFO
117#define MOXA_MUST_FCR_GDA_ONLY_ENABLE 0x10
118
119// enable CTS interrupt
120#define MOXA_MUST_IER_ECTSI 0x80
121// enable RTS interrupt
122#define MOXA_MUST_IER_ERTSI 0x40
123// enable Xon/Xoff interrupt
124#define MOXA_MUST_IER_XINT 0x20
125// enable GDA interrupt
126#define MOXA_MUST_IER_EGDAI 0x10
127
128#define MOXA_MUST_RECV_ISR (UART_IER_RDI | MOXA_MUST_IER_EGDAI)
129
130// GDA interrupt pending
131#define MOXA_MUST_IIR_GDA 0x1C
132#define MOXA_MUST_IIR_RDA 0x04
133#define MOXA_MUST_IIR_RTO 0x0C
134#define MOXA_MUST_IIR_LSR 0x06
135
136// recieved Xon/Xoff or specical interrupt pending
137#define MOXA_MUST_IIR_XSC 0x10
138
139// RTS/CTS change state interrupt pending
140#define MOXA_MUST_IIR_RTSCTS 0x20
141#define MOXA_MUST_IIR_MASK 0x3E
142
143#define MOXA_MUST_MCR_XON_FLAG 0x40
144#define MOXA_MUST_MCR_XON_ANY 0x80
145#define MOXA_MUST_MCR_TX_XON 0x08
146
147
148// software flow control on chip mask value
149#define MOXA_MUST_EFR_SF_MASK 0x0F
150// send Xon1/Xoff1
151#define MOXA_MUST_EFR_SF_TX1 0x08
152// send Xon2/Xoff2
153#define MOXA_MUST_EFR_SF_TX2 0x04
154// send Xon1,Xon2/Xoff1,Xoff2
155#define MOXA_MUST_EFR_SF_TX12 0x0C
156// don't send Xon/Xoff
157#define MOXA_MUST_EFR_SF_TX_NO 0x00
158// Tx software flow control mask
159#define MOXA_MUST_EFR_SF_TX_MASK 0x0C
160// don't receive Xon/Xoff
161#define MOXA_MUST_EFR_SF_RX_NO 0x00
162// receive Xon1/Xoff1
163#define MOXA_MUST_EFR_SF_RX1 0x02
164// receive Xon2/Xoff2
165#define MOXA_MUST_EFR_SF_RX2 0x01
166// receive Xon1,Xon2/Xoff1,Xoff2
167#define MOXA_MUST_EFR_SF_RX12 0x03
168// Rx software flow control mask
169#define MOXA_MUST_EFR_SF_RX_MASK 0x03
170
171//#define MOXA_MUST_MIN_XOFFLIMIT 66
172//#define MOXA_MUST_MIN_XONLIMIT 20
173//#define ID1_RX_TRIG 120
174
175
176#define CHECK_MOXA_MUST_XOFFLIMIT(info) { \
177 if ( (info)->IsMoxaMustChipFlag && \
178 (info)->HandFlow.XoffLimit < MOXA_MUST_MIN_XOFFLIMIT ) { \
179 (info)->HandFlow.XoffLimit = MOXA_MUST_MIN_XOFFLIMIT; \
180 (info)->HandFlow.XonLimit = MOXA_MUST_MIN_XONLIMIT; \
181 } \
182}
183
184#define ENABLE_MOXA_MUST_ENCHANCE_MODE(baseio) { \
185 u8 __oldlcr, __efr; \
186 __oldlcr = inb((baseio)+UART_LCR); \
187 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
188 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
189 __efr |= MOXA_MUST_EFR_EFRB_ENABLE; \
190 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
191 outb(__oldlcr, (baseio)+UART_LCR); \
192}
193
194#define DISABLE_MOXA_MUST_ENCHANCE_MODE(baseio) { \
195 u8 __oldlcr, __efr; \
196 __oldlcr = inb((baseio)+UART_LCR); \
197 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
198 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
199 __efr &= ~MOXA_MUST_EFR_EFRB_ENABLE; \
200 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
201 outb(__oldlcr, (baseio)+UART_LCR); \
202}
203
204#define SET_MOXA_MUST_XON1_VALUE(baseio, Value) { \
205 u8 __oldlcr, __efr; \
206 __oldlcr = inb((baseio)+UART_LCR); \
207 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
208 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
209 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
210 __efr |= MOXA_MUST_EFR_BANK0; \
211 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
212 outb((u8)(Value), (baseio)+MOXA_MUST_XON1_REGISTER); \
213 outb(__oldlcr, (baseio)+UART_LCR); \
214}
215
216#define SET_MOXA_MUST_XON2_VALUE(baseio, Value) { \
217 u8 __oldlcr, __efr; \
218 __oldlcr = inb((baseio)+UART_LCR); \
219 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
220 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
221 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
222 __efr |= MOXA_MUST_EFR_BANK0; \
223 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
224 outb((u8)(Value), (baseio)+MOXA_MUST_XON2_REGISTER); \
225 outb(__oldlcr, (baseio)+UART_LCR); \
226}
227
228#define SET_MOXA_MUST_XOFF1_VALUE(baseio, Value) { \
229 u8 __oldlcr, __efr; \
230 __oldlcr = inb((baseio)+UART_LCR); \
231 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
232 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
233 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
234 __efr |= MOXA_MUST_EFR_BANK0; \
235 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
236 outb((u8)(Value), (baseio)+MOXA_MUST_XOFF1_REGISTER); \
237 outb(__oldlcr, (baseio)+UART_LCR); \
238}
239
240#define SET_MOXA_MUST_XOFF2_VALUE(baseio, Value) { \
241 u8 __oldlcr, __efr; \
242 __oldlcr = inb((baseio)+UART_LCR); \
243 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
244 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
245 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
246 __efr |= MOXA_MUST_EFR_BANK0; \
247 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
248 outb((u8)(Value), (baseio)+MOXA_MUST_XOFF2_REGISTER); \
249 outb(__oldlcr, (baseio)+UART_LCR); \
250}
251
252#define SET_MOXA_MUST_RBRTL_VALUE(baseio, Value) { \
253 u8 __oldlcr, __efr; \
254 __oldlcr = inb((baseio)+UART_LCR); \
255 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
256 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
257 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
258 __efr |= MOXA_MUST_EFR_BANK1; \
259 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
260 outb((u8)(Value), (baseio)+MOXA_MUST_RBRTL_REGISTER); \
261 outb(__oldlcr, (baseio)+UART_LCR); \
262}
263
264#define SET_MOXA_MUST_RBRTH_VALUE(baseio, Value) { \
265 u8 __oldlcr, __efr; \
266 __oldlcr = inb((baseio)+UART_LCR); \
267 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
268 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
269 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
270 __efr |= MOXA_MUST_EFR_BANK1; \
271 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
272 outb((u8)(Value), (baseio)+MOXA_MUST_RBRTH_REGISTER); \
273 outb(__oldlcr, (baseio)+UART_LCR); \
274}
275
276#define SET_MOXA_MUST_RBRTI_VALUE(baseio, Value) { \
277 u8 __oldlcr, __efr; \
278 __oldlcr = inb((baseio)+UART_LCR); \
279 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
280 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
281 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
282 __efr |= MOXA_MUST_EFR_BANK1; \
283 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
284 outb((u8)(Value), (baseio)+MOXA_MUST_RBRTI_REGISTER); \
285 outb(__oldlcr, (baseio)+UART_LCR); \
286}
287
288#define SET_MOXA_MUST_THRTL_VALUE(baseio, Value) { \
289 u8 __oldlcr, __efr; \
290 __oldlcr = inb((baseio)+UART_LCR); \
291 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
292 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
293 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
294 __efr |= MOXA_MUST_EFR_BANK1; \
295 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
296 outb((u8)(Value), (baseio)+MOXA_MUST_THRTL_REGISTER); \
297 outb(__oldlcr, (baseio)+UART_LCR); \
298}
299
300//#define MOXA_MUST_RBRL_VALUE 4
301#define SET_MOXA_MUST_FIFO_VALUE(info) { \
302 u8 __oldlcr, __efr; \
303 __oldlcr = inb((info)->ioaddr+UART_LCR); \
304 outb(MOXA_MUST_ENTER_ENCHANCE, (info)->ioaddr+UART_LCR); \
305 __efr = inb((info)->ioaddr+MOXA_MUST_EFR_REGISTER); \
306 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
307 __efr |= MOXA_MUST_EFR_BANK1; \
308 outb(__efr, (info)->ioaddr+MOXA_MUST_EFR_REGISTER); \
309 outb((u8)((info)->rx_high_water), (info)->ioaddr+MOXA_MUST_RBRTH_REGISTER); \
310 outb((u8)((info)->rx_trigger), (info)->ioaddr+MOXA_MUST_RBRTI_REGISTER); \
311 outb((u8)((info)->rx_low_water), (info)->ioaddr+MOXA_MUST_RBRTL_REGISTER); \
312 outb(__oldlcr, (info)->ioaddr+UART_LCR); \
313}
314
315
316
317#define SET_MOXA_MUST_ENUM_VALUE(baseio, Value) { \
318 u8 __oldlcr, __efr; \
319 __oldlcr = inb((baseio)+UART_LCR); \
320 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
321 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
322 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
323 __efr |= MOXA_MUST_EFR_BANK2; \
324 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
325 outb((u8)(Value), (baseio)+MOXA_MUST_ENUM_REGISTER); \
326 outb(__oldlcr, (baseio)+UART_LCR); \
327}
328
329#define GET_MOXA_MUST_HARDWARE_ID(baseio, pId) { \
330 u8 __oldlcr, __efr; \
331 __oldlcr = inb((baseio)+UART_LCR); \
332 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
333 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
334 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
335 __efr |= MOXA_MUST_EFR_BANK2; \
336 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
337 *pId = inb((baseio)+MOXA_MUST_HWID_REGISTER); \
338 outb(__oldlcr, (baseio)+UART_LCR); \
339}
340
341#define SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(baseio) { \
342 u8 __oldlcr, __efr; \
343 __oldlcr = inb((baseio)+UART_LCR); \
344 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
345 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
346 __efr &= ~MOXA_MUST_EFR_SF_MASK; \
347 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
348 outb(__oldlcr, (baseio)+UART_LCR); \
349}
350
351#define SET_MOXA_MUST_JUST_TX_SOFTWARE_FLOW_CONTROL(baseio) { \
352 u8 __oldlcr, __efr; \
353 __oldlcr = inb((baseio)+UART_LCR); \
354 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
355 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
356 __efr &= ~MOXA_MUST_EFR_SF_MASK; \
357 __efr |= MOXA_MUST_EFR_SF_TX1; \
358 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
359 outb(__oldlcr, (baseio)+UART_LCR); \
360}
361
362#define ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(baseio) { \
363 u8 __oldlcr, __efr; \
364 __oldlcr = inb((baseio)+UART_LCR); \
365 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
366 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
367 __efr &= ~MOXA_MUST_EFR_SF_TX_MASK; \
368 __efr |= MOXA_MUST_EFR_SF_TX1; \
369 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
370 outb(__oldlcr, (baseio)+UART_LCR); \
371}
372
373#define DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(baseio) { \
374 u8 __oldlcr, __efr; \
375 __oldlcr = inb((baseio)+UART_LCR); \
376 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
377 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
378 __efr &= ~MOXA_MUST_EFR_SF_TX_MASK; \
379 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
380 outb(__oldlcr, (baseio)+UART_LCR); \
381}
382
383#define SET_MOXA_MUST_JUST_RX_SOFTWARE_FLOW_CONTROL(baseio) { \
384 u8 __oldlcr, __efr; \
385 __oldlcr = inb((baseio)+UART_LCR); \
386 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
387 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
388 __efr &= ~MOXA_MUST_EFR_SF_MASK; \
389 __efr |= MOXA_MUST_EFR_SF_RX1; \
390 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
391 outb(__oldlcr, (baseio)+UART_LCR); \
392}
393
394#define ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(baseio) { \
395 u8 __oldlcr, __efr; \
396 __oldlcr = inb((baseio)+UART_LCR); \
397 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
398 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
399 __efr &= ~MOXA_MUST_EFR_SF_RX_MASK; \
400 __efr |= MOXA_MUST_EFR_SF_RX1; \
401 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
402 outb(__oldlcr, (baseio)+UART_LCR); \
403}
404
405#define DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(baseio) { \
406 u8 __oldlcr, __efr; \
407 __oldlcr = inb((baseio)+UART_LCR); \
408 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
409 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
410 __efr &= ~MOXA_MUST_EFR_SF_RX_MASK; \
411 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
412 outb(__oldlcr, (baseio)+UART_LCR); \
413}
414
415#define ENABLE_MOXA_MUST_TX_RX_SOFTWARE_FLOW_CONTROL(baseio) { \
416 u8 __oldlcr, __efr; \
417 __oldlcr = inb((baseio)+UART_LCR); \
418 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
419 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
420 __efr &= ~MOXA_MUST_EFR_SF_MASK; \
421 __efr |= (MOXA_MUST_EFR_SF_RX1|MOXA_MUST_EFR_SF_TX1); \
422 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
423 outb(__oldlcr, (baseio)+UART_LCR); \
424}
425
426#define ENABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(baseio) { \
427 u8 __oldmcr; \
428 __oldmcr = inb((baseio)+UART_MCR); \
429 __oldmcr |= MOXA_MUST_MCR_XON_ANY; \
430 outb(__oldmcr, (baseio)+UART_MCR); \
431}
432
433#define DISABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(baseio) { \
434 u8 __oldmcr; \
435 __oldmcr = inb((baseio)+UART_MCR); \
436 __oldmcr &= ~MOXA_MUST_MCR_XON_ANY; \
437 outb(__oldmcr, (baseio)+UART_MCR); \
438}
439
440#define READ_MOXA_MUST_GDL(baseio) inb((baseio)+MOXA_MUST_GDL_REGISTER)
441
442
443#ifndef INIT_WORK
444#define INIT_WORK(_work, _func, _data){ \
445 _data->tqueue.routine = _func;\
446 _data->tqueue.data = _data;\
447 }
448#endif
449
450#endif
diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c
index 203dc2b661d5..103d338f21e2 100644
--- a/drivers/char/n_r3964.c
+++ b/drivers/char/n_r3964.c
@@ -142,7 +142,7 @@ static ssize_t r3964_write(struct tty_struct * tty, struct file * file,
142 const unsigned char * buf, size_t nr); 142 const unsigned char * buf, size_t nr);
143static int r3964_ioctl(struct tty_struct * tty, struct file * file, 143static int r3964_ioctl(struct tty_struct * tty, struct file * file,
144 unsigned int cmd, unsigned long arg); 144 unsigned int cmd, unsigned long arg);
145static void r3964_set_termios(struct tty_struct *tty, struct termios * old); 145static void r3964_set_termios(struct tty_struct *tty, struct ktermios * old);
146static unsigned int r3964_poll(struct tty_struct * tty, struct file * file, 146static unsigned int r3964_poll(struct tty_struct * tty, struct file * file,
147 struct poll_table_struct *wait); 147 struct poll_table_struct *wait);
148static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp, 148static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp,
@@ -1347,7 +1347,7 @@ static int r3964_ioctl(struct tty_struct * tty, struct file * file,
1347 } 1347 }
1348} 1348}
1349 1349
1350static void r3964_set_termios(struct tty_struct *tty, struct termios * old) 1350static void r3964_set_termios(struct tty_struct *tty, struct ktermios * old)
1351{ 1351{
1352 TRACE_L("set_termios"); 1352 TRACE_L("set_termios");
1353} 1353}
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index 603b9ade5eb0..e96a00fe1389 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -994,7 +994,7 @@ int is_ignored(int sig)
994 * when the ldisc is closed. 994 * when the ldisc is closed.
995 */ 995 */
996 996
997static void n_tty_set_termios(struct tty_struct *tty, struct termios * old) 997static void n_tty_set_termios(struct tty_struct *tty, struct ktermios * old)
998{ 998{
999 if (!tty) 999 if (!tty)
1000 return; 1000 return;
diff --git a/drivers/char/nsc_gpio.c b/drivers/char/nsc_gpio.c
index 7719bd75810b..808d44e9a32a 100644
--- a/drivers/char/nsc_gpio.c
+++ b/drivers/char/nsc_gpio.c
@@ -7,7 +7,6 @@
7 Copyright (c) 2005 Jim Cromie <jim.cromie@gmail.com> 7 Copyright (c) 2005 Jim Cromie <jim.cromie@gmail.com>
8*/ 8*/
9 9
10#include <linux/config.h>
11#include <linux/fs.h> 10#include <linux/fs.h>
12#include <linux/module.h> 11#include <linux/module.h>
13#include <linux/errno.h> 12#include <linux/errno.h>
@@ -42,7 +41,7 @@ void nsc_gpio_dump(struct nsc_gpio_ops *amp, unsigned index)
42ssize_t nsc_gpio_write(struct file *file, const char __user *data, 41ssize_t nsc_gpio_write(struct file *file, const char __user *data,
43 size_t len, loff_t *ppos) 42 size_t len, loff_t *ppos)
44{ 43{
45 unsigned m = iminor(file->f_dentry->d_inode); 44 unsigned m = iminor(file->f_path.dentry->d_inode);
46 struct nsc_gpio_ops *amp = file->private_data; 45 struct nsc_gpio_ops *amp = file->private_data;
47 struct device *dev = amp->dev; 46 struct device *dev = amp->dev;
48 size_t i; 47 size_t i;
@@ -105,7 +104,7 @@ ssize_t nsc_gpio_write(struct file *file, const char __user *data,
105ssize_t nsc_gpio_read(struct file *file, char __user * buf, 104ssize_t nsc_gpio_read(struct file *file, char __user * buf,
106 size_t len, loff_t * ppos) 105 size_t len, loff_t * ppos)
107{ 106{
108 unsigned m = iminor(file->f_dentry->d_inode); 107 unsigned m = iminor(file->f_path.dentry->d_inode);
109 int value; 108 int value;
110 struct nsc_gpio_ops *amp = file->private_data; 109 struct nsc_gpio_ops *amp = file->private_data;
111 110
diff --git a/drivers/char/nwbutton.c b/drivers/char/nwbutton.c
index 7c57ebfa8640..2d264971d839 100644
--- a/drivers/char/nwbutton.c
+++ b/drivers/char/nwbutton.c
@@ -127,9 +127,8 @@ static void button_consume_callbacks (int bpcount)
127static void button_sequence_finished (unsigned long parameters) 127static void button_sequence_finished (unsigned long parameters)
128{ 128{
129#ifdef CONFIG_NWBUTTON_REBOOT /* Reboot using button is enabled */ 129#ifdef CONFIG_NWBUTTON_REBOOT /* Reboot using button is enabled */
130 if (button_press_count == reboot_count) { 130 if (button_press_count == reboot_count)
131 kill_proc (1, SIGINT, 1); /* Ask init to reboot us */ 131 kill_cad_pid(SIGINT, 1); /* Ask init to reboot us */
132 }
133#endif /* CONFIG_NWBUTTON_REBOOT */ 132#endif /* CONFIG_NWBUTTON_REBOOT */
134 button_consume_callbacks (button_press_count); 133 button_consume_callbacks (button_press_count);
135 bcount = sprintf (button_output_buffer, "%d\n", button_press_count); 134 bcount = sprintf (button_output_buffer, "%d\n", button_press_count);
@@ -145,7 +144,7 @@ static void button_sequence_finished (unsigned long parameters)
145 * increments the counter. 144 * increments the counter.
146 */ 145 */
147 146
148static irqreturn_t button_handler (int irq, void *dev_id, struct pt_regs *regs) 147static irqreturn_t button_handler (int irq, void *dev_id)
149{ 148{
150 if (button_press_count) { 149 if (button_press_count) {
151 del_timer (&button_timer); 150 del_timer (&button_timer);
diff --git a/drivers/char/nwbutton.h b/drivers/char/nwbutton.h
index ddb7b928dcbb..c3ebc16ce8a7 100644
--- a/drivers/char/nwbutton.h
+++ b/drivers/char/nwbutton.h
@@ -25,7 +25,7 @@ struct button_callback {
25/* Function prototypes: */ 25/* Function prototypes: */
26 26
27static void button_sequence_finished (unsigned long parameters); 27static void button_sequence_finished (unsigned long parameters);
28static irqreturn_t button_handler (int irq, void *dev_id, struct pt_regs *regs); 28static irqreturn_t button_handler (int irq, void *dev_id);
29int button_init (void); 29int button_init (void);
30int button_add_callback (void (*callback) (void), int count); 30int button_add_callback (void (*callback) (void), int count);
31int button_del_callback (void (*callback) (void)); 31int button_del_callback (void (*callback) (void));
diff --git a/drivers/char/pc8736x_gpio.c b/drivers/char/pc8736x_gpio.c
index 84e5a68635f1..ecfaf180e5bd 100644
--- a/drivers/char/pc8736x_gpio.c
+++ b/drivers/char/pc8736x_gpio.c
@@ -188,16 +188,6 @@ static void pc8736x_gpio_set(unsigned minor, int val)
188 pc8736x_gpio_shadow[port] = val; 188 pc8736x_gpio_shadow[port] = val;
189} 189}
190 190
191static void pc8736x_gpio_set_high(unsigned index)
192{
193 pc8736x_gpio_set(index, 1);
194}
195
196static void pc8736x_gpio_set_low(unsigned index)
197{
198 pc8736x_gpio_set(index, 0);
199}
200
201static int pc8736x_gpio_current(unsigned minor) 191static int pc8736x_gpio_current(unsigned minor)
202{ 192{
203 int port, bit; 193 int port, bit;
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index 50d20aafeb18..211c93fda6fc 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -1764,29 +1764,11 @@ static int cm4000_config(struct pcmcia_device * link, int devno)
1764 int rc; 1764 int rc;
1765 1765
1766 /* read the config-tuples */ 1766 /* read the config-tuples */
1767 tuple.DesiredTuple = CISTPL_CONFIG;
1768 tuple.Attributes = 0; 1767 tuple.Attributes = 0;
1769 tuple.TupleData = buf; 1768 tuple.TupleData = buf;
1770 tuple.TupleDataMax = sizeof(buf); 1769 tuple.TupleDataMax = sizeof(buf);
1771 tuple.TupleOffset = 0; 1770 tuple.TupleOffset = 0;
1772 1771
1773 if ((fail_rc = pcmcia_get_first_tuple(link, &tuple)) != CS_SUCCESS) {
1774 fail_fn = GetFirstTuple;
1775 goto cs_failed;
1776 }
1777 if ((fail_rc = pcmcia_get_tuple_data(link, &tuple)) != CS_SUCCESS) {
1778 fail_fn = GetTupleData;
1779 goto cs_failed;
1780 }
1781 if ((fail_rc =
1782 pcmcia_parse_tuple(link, &tuple, &parse)) != CS_SUCCESS) {
1783 fail_fn = ParseTuple;
1784 goto cs_failed;
1785 }
1786
1787 link->conf.ConfigBase = parse.config.base;
1788 link->conf.Present = parse.config.rmask[0];
1789
1790 link->io.BasePort2 = 0; 1772 link->io.BasePort2 = 0;
1791 link->io.NumPorts2 = 0; 1773 link->io.NumPorts2 = 0;
1792 link->io.Attributes2 = 0; 1774 link->io.Attributes2 = 0;
@@ -1841,8 +1823,6 @@ static int cm4000_config(struct pcmcia_device * link, int devno)
1841 1823
1842 return 0; 1824 return 0;
1843 1825
1844cs_failed:
1845 cs_error(link, fail_fn, fail_rc);
1846cs_release: 1826cs_release:
1847 cm4000_release(link); 1827 cm4000_release(link);
1848 return -ENODEV; 1828 return -ENODEV;
@@ -1973,14 +1953,14 @@ static int __init cmm_init(void)
1973 printk(KERN_INFO "%s\n", version); 1953 printk(KERN_INFO "%s\n", version);
1974 1954
1975 cmm_class = class_create(THIS_MODULE, "cardman_4000"); 1955 cmm_class = class_create(THIS_MODULE, "cardman_4000");
1976 if (!cmm_class) 1956 if (IS_ERR(cmm_class))
1977 return -1; 1957 return PTR_ERR(cmm_class);
1978 1958
1979 major = register_chrdev(0, DEVICE_NAME, &cm4000_fops); 1959 major = register_chrdev(0, DEVICE_NAME, &cm4000_fops);
1980 if (major < 0) { 1960 if (major < 0) {
1981 printk(KERN_WARNING MODULE_NAME 1961 printk(KERN_WARNING MODULE_NAME
1982 ": could not get major number\n"); 1962 ": could not get major number\n");
1983 return -1; 1963 return major;
1984 } 1964 }
1985 1965
1986 rc = pcmcia_register_driver(&cm4000_driver); 1966 rc = pcmcia_register_driver(&cm4000_driver);
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
index 55cf4be42976..9b1ff7e8f896 100644
--- a/drivers/char/pcmcia/cm4040_cs.c
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -523,29 +523,11 @@ static int reader_config(struct pcmcia_device *link, int devno)
523 int fail_fn, fail_rc; 523 int fail_fn, fail_rc;
524 int rc; 524 int rc;
525 525
526 tuple.DesiredTuple = CISTPL_CONFIG;
527 tuple.Attributes = 0; 526 tuple.Attributes = 0;
528 tuple.TupleData = buf; 527 tuple.TupleData = buf;
529 tuple.TupleDataMax = sizeof(buf); 528 tuple.TupleDataMax = sizeof(buf);
530 tuple.TupleOffset = 0; 529 tuple.TupleOffset = 0;
531 530
532 if ((fail_rc = pcmcia_get_first_tuple(link, &tuple)) != CS_SUCCESS) {
533 fail_fn = GetFirstTuple;
534 goto cs_failed;
535 }
536 if ((fail_rc = pcmcia_get_tuple_data(link, &tuple)) != CS_SUCCESS) {
537 fail_fn = GetTupleData;
538 goto cs_failed;
539 }
540 if ((fail_rc = pcmcia_parse_tuple(link, &tuple, &parse))
541 != CS_SUCCESS) {
542 fail_fn = ParseTuple;
543 goto cs_failed;
544 }
545
546 link->conf.ConfigBase = parse.config.base;
547 link->conf.Present = parse.config.rmask[0];
548
549 link->io.BasePort2 = 0; 531 link->io.BasePort2 = 0;
550 link->io.NumPorts2 = 0; 532 link->io.NumPorts2 = 0;
551 link->io.Attributes2 = 0; 533 link->io.Attributes2 = 0;
@@ -609,8 +591,6 @@ static int reader_config(struct pcmcia_device *link, int devno)
609 591
610 return 0; 592 return 0;
611 593
612cs_failed:
613 cs_error(link, fail_fn, fail_rc);
614cs_release: 594cs_release:
615 reader_release(link); 595 reader_release(link);
616 return -ENODEV; 596 return -ENODEV;
@@ -721,14 +701,14 @@ static int __init cm4040_init(void)
721 701
722 printk(KERN_INFO "%s\n", version); 702 printk(KERN_INFO "%s\n", version);
723 cmx_class = class_create(THIS_MODULE, "cardman_4040"); 703 cmx_class = class_create(THIS_MODULE, "cardman_4040");
724 if (!cmx_class) 704 if (IS_ERR(cmx_class))
725 return -1; 705 return PTR_ERR(cmx_class);
726 706
727 major = register_chrdev(0, DEVICE_NAME, &reader_fops); 707 major = register_chrdev(0, DEVICE_NAME, &reader_fops);
728 if (major < 0) { 708 if (major < 0) {
729 printk(KERN_WARNING MODULE_NAME 709 printk(KERN_WARNING MODULE_NAME
730 ": could not get major number\n"); 710 ": could not get major number\n");
731 return -1; 711 return major;
732 } 712 }
733 713
734 rc = pcmcia_register_driver(&reader_driver); 714 rc = pcmcia_register_driver(&reader_driver);
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 00f574cbb0d4..5152cedd8878 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -35,7 +35,6 @@
35 35
36#define MAX_DEVICE_COUNT 4 36#define MAX_DEVICE_COUNT 4
37 37
38#include <linux/config.h>
39#include <linux/module.h> 38#include <linux/module.h>
40#include <linux/errno.h> 39#include <linux/errno.h>
41#include <linux/signal.h> 40#include <linux/signal.h>
@@ -57,7 +56,6 @@
57#include <linux/netdevice.h> 56#include <linux/netdevice.h>
58#include <linux/vmalloc.h> 57#include <linux/vmalloc.h>
59#include <linux/init.h> 58#include <linux/init.h>
60#include <asm/serial.h>
61#include <linux/delay.h> 59#include <linux/delay.h>
62#include <linux/ioctl.h> 60#include <linux/ioctl.h>
63 61
@@ -77,8 +75,10 @@
77#include <pcmcia/cisreg.h> 75#include <pcmcia/cisreg.h>
78#include <pcmcia/ds.h> 76#include <pcmcia/ds.h>
79 77
80#ifdef CONFIG_HDLC_MODULE 78#if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINK_CS_MODULE))
81#define CONFIG_HDLC 1 79#define SYNCLINK_GENERIC_HDLC 1
80#else
81#define SYNCLINK_GENERIC_HDLC 0
82#endif 82#endif
83 83
84#define GET_USER(error,value,addr) error = get_user(value,addr) 84#define GET_USER(error,value,addr) error = get_user(value,addr)
@@ -237,7 +237,7 @@ typedef struct _mgslpc_info {
237 int dosyncppp; 237 int dosyncppp;
238 spinlock_t netlock; 238 spinlock_t netlock;
239 239
240#ifdef CONFIG_HDLC 240#if SYNCLINK_GENERIC_HDLC
241 struct net_device *netdev; 241 struct net_device *netdev;
242#endif 242#endif
243 243
@@ -394,7 +394,7 @@ static void tx_timeout(unsigned long context);
394 394
395static int ioctl_common(MGSLPC_INFO *info, unsigned int cmd, unsigned long arg); 395static int ioctl_common(MGSLPC_INFO *info, unsigned int cmd, unsigned long arg);
396 396
397#ifdef CONFIG_HDLC 397#if SYNCLINK_GENERIC_HDLC
398#define dev_to_port(D) (dev_to_hdlc(D)->priv) 398#define dev_to_port(D) (dev_to_hdlc(D)->priv)
399static void hdlcdev_tx_done(MGSLPC_INFO *info); 399static void hdlcdev_tx_done(MGSLPC_INFO *info);
400static void hdlcdev_rx(MGSLPC_INFO *info, char *buf, int size); 400static void hdlcdev_rx(MGSLPC_INFO *info, char *buf, int size);
@@ -418,12 +418,12 @@ static void rx_reset_buffers(MGSLPC_INFO *info);
418static int rx_alloc_buffers(MGSLPC_INFO *info); 418static int rx_alloc_buffers(MGSLPC_INFO *info);
419static void rx_free_buffers(MGSLPC_INFO *info); 419static void rx_free_buffers(MGSLPC_INFO *info);
420 420
421static irqreturn_t mgslpc_isr(int irq, void *dev_id, struct pt_regs * regs); 421static irqreturn_t mgslpc_isr(int irq, void *dev_id);
422 422
423/* 423/*
424 * Bottom half interrupt handlers 424 * Bottom half interrupt handlers
425 */ 425 */
426static void bh_handler(void* Context); 426static void bh_handler(struct work_struct *work);
427static void bh_transmit(MGSLPC_INFO *info); 427static void bh_transmit(MGSLPC_INFO *info);
428static void bh_status(MGSLPC_INFO *info); 428static void bh_status(MGSLPC_INFO *info);
429 429
@@ -549,7 +549,7 @@ static int mgslpc_probe(struct pcmcia_device *link)
549 549
550 memset(info, 0, sizeof(MGSLPC_INFO)); 550 memset(info, 0, sizeof(MGSLPC_INFO));
551 info->magic = MGSLPC_MAGIC; 551 info->magic = MGSLPC_MAGIC;
552 INIT_WORK(&info->task, bh_handler, info); 552 INIT_WORK(&info->task, bh_handler);
553 info->max_frame_size = 4096; 553 info->max_frame_size = 4096;
554 info->close_delay = 5*HZ/10; 554 info->close_delay = 5*HZ/10;
555 info->closing_wait = 30*HZ; 555 info->closing_wait = 30*HZ;
@@ -606,17 +606,10 @@ static int mgslpc_config(struct pcmcia_device *link)
606 if (debug_level >= DEBUG_LEVEL_INFO) 606 if (debug_level >= DEBUG_LEVEL_INFO)
607 printk("mgslpc_config(0x%p)\n", link); 607 printk("mgslpc_config(0x%p)\n", link);
608 608
609 /* read CONFIG tuple to find its configuration registers */
610 tuple.DesiredTuple = CISTPL_CONFIG;
611 tuple.Attributes = 0; 609 tuple.Attributes = 0;
612 tuple.TupleData = buf; 610 tuple.TupleData = buf;
613 tuple.TupleDataMax = sizeof(buf); 611 tuple.TupleDataMax = sizeof(buf);
614 tuple.TupleOffset = 0; 612 tuple.TupleOffset = 0;
615 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
616 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
617 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
618 link->conf.ConfigBase = parse.config.base;
619 link->conf.Present = parse.config.rmask[0];
620 613
621 /* get CIS configuration entry */ 614 /* get CIS configuration entry */
622 615
@@ -844,9 +837,9 @@ static int bh_action(MGSLPC_INFO *info)
844 return rc; 837 return rc;
845} 838}
846 839
847static void bh_handler(void* Context) 840static void bh_handler(struct work_struct *work)
848{ 841{
849 MGSLPC_INFO *info = (MGSLPC_INFO*)Context; 842 MGSLPC_INFO *info = container_of(work, MGSLPC_INFO, task);
850 int action; 843 int action;
851 844
852 if (!info) 845 if (!info)
@@ -1062,7 +1055,7 @@ static void tx_done(MGSLPC_INFO *info)
1062 info->drop_rts_on_tx_done = 0; 1055 info->drop_rts_on_tx_done = 0;
1063 } 1056 }
1064 1057
1065#ifdef CONFIG_HDLC 1058#if SYNCLINK_GENERIC_HDLC
1066 if (info->netcount) 1059 if (info->netcount)
1067 hdlcdev_tx_done(info); 1060 hdlcdev_tx_done(info);
1068 else 1061 else
@@ -1173,7 +1166,7 @@ static void dcd_change(MGSLPC_INFO *info)
1173 } 1166 }
1174 else 1167 else
1175 info->input_signal_events.dcd_down++; 1168 info->input_signal_events.dcd_down++;
1176#ifdef CONFIG_HDLC 1169#if SYNCLINK_GENERIC_HDLC
1177 if (info->netcount) { 1170 if (info->netcount) {
1178 if (info->serial_signals & SerialSignal_DCD) 1171 if (info->serial_signals & SerialSignal_DCD)
1179 netif_carrier_on(info->netdev); 1172 netif_carrier_on(info->netdev);
@@ -1236,9 +1229,8 @@ static void ri_change(MGSLPC_INFO *info)
1236 * 1229 *
1237 * irq interrupt number that caused interrupt 1230 * irq interrupt number that caused interrupt
1238 * dev_id device ID supplied during interrupt registration 1231 * dev_id device ID supplied during interrupt registration
1239 * regs interrupted processor context
1240 */ 1232 */
1241static irqreturn_t mgslpc_isr(int irq, void *dev_id, struct pt_regs * regs) 1233static irqreturn_t mgslpc_isr(int irq, void *dev_id)
1242{ 1234{
1243 MGSLPC_INFO * info = (MGSLPC_INFO *)dev_id; 1235 MGSLPC_INFO * info = (MGSLPC_INFO *)dev_id;
1244 unsigned short isr; 1236 unsigned short isr;
@@ -2383,7 +2375,7 @@ static int ioctl_common(MGSLPC_INFO *info, unsigned int cmd, unsigned long arg)
2383 * tty pointer to tty structure 2375 * tty pointer to tty structure
2384 * termios pointer to buffer to hold returned old termios 2376 * termios pointer to buffer to hold returned old termios
2385 */ 2377 */
2386static void mgslpc_set_termios(struct tty_struct *tty, struct termios *old_termios) 2378static void mgslpc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2387{ 2379{
2388 MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data; 2380 MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
2389 unsigned long flags; 2381 unsigned long flags;
@@ -2963,7 +2955,7 @@ static void mgslpc_add_device(MGSLPC_INFO *info)
2963 printk( "SyncLink PC Card %s:IO=%04X IRQ=%d\n", 2955 printk( "SyncLink PC Card %s:IO=%04X IRQ=%d\n",
2964 info->device_name, info->io_base, info->irq_level); 2956 info->device_name, info->io_base, info->irq_level);
2965 2957
2966#ifdef CONFIG_HDLC 2958#if SYNCLINK_GENERIC_HDLC
2967 hdlcdev_init(info); 2959 hdlcdev_init(info);
2968#endif 2960#endif
2969} 2961}
@@ -2979,7 +2971,7 @@ static void mgslpc_remove_device(MGSLPC_INFO *remove_info)
2979 last->next_device = info->next_device; 2971 last->next_device = info->next_device;
2980 else 2972 else
2981 mgslpc_device_list = info->next_device; 2973 mgslpc_device_list = info->next_device;
2982#ifdef CONFIG_HDLC 2974#if SYNCLINK_GENERIC_HDLC
2983 hdlcdev_exit(info); 2975 hdlcdev_exit(info);
2984#endif 2976#endif
2985 release_resources(info); 2977 release_resources(info);
@@ -3010,7 +3002,7 @@ static struct pcmcia_driver mgslpc_driver = {
3010 .resume = mgslpc_resume, 3002 .resume = mgslpc_resume,
3011}; 3003};
3012 3004
3013static struct tty_operations mgslpc_ops = { 3005static const struct tty_operations mgslpc_ops = {
3014 .open = mgslpc_open, 3006 .open = mgslpc_open,
3015 .close = mgslpc_close, 3007 .close = mgslpc_close,
3016 .write = mgslpc_write, 3008 .write = mgslpc_write,
@@ -3911,7 +3903,7 @@ static int rx_get_frame(MGSLPC_INFO *info)
3911 return_frame = 1; 3903 return_frame = 1;
3912 } 3904 }
3913 framesize = 0; 3905 framesize = 0;
3914#ifdef CONFIG_HDLC 3906#if SYNCLINK_GENERIC_HDLC
3915 { 3907 {
3916 struct net_device_stats *stats = hdlc_stats(info->netdev); 3908 struct net_device_stats *stats = hdlc_stats(info->netdev);
3917 stats->rx_errors++; 3909 stats->rx_errors++;
@@ -3945,7 +3937,7 @@ static int rx_get_frame(MGSLPC_INFO *info)
3945 ++framesize; 3937 ++framesize;
3946 } 3938 }
3947 3939
3948#ifdef CONFIG_HDLC 3940#if SYNCLINK_GENERIC_HDLC
3949 if (info->netcount) 3941 if (info->netcount)
3950 hdlcdev_rx(info, buf->data, framesize); 3942 hdlcdev_rx(info, buf->data, framesize);
3951 else 3943 else
@@ -4101,7 +4093,7 @@ static void tx_timeout(unsigned long context)
4101 4093
4102 spin_unlock_irqrestore(&info->lock,flags); 4094 spin_unlock_irqrestore(&info->lock,flags);
4103 4095
4104#ifdef CONFIG_HDLC 4096#if SYNCLINK_GENERIC_HDLC
4105 if (info->netcount) 4097 if (info->netcount)
4106 hdlcdev_tx_done(info); 4098 hdlcdev_tx_done(info);
4107 else 4099 else
@@ -4109,7 +4101,7 @@ static void tx_timeout(unsigned long context)
4109 bh_transmit(info); 4101 bh_transmit(info);
4110} 4102}
4111 4103
4112#ifdef CONFIG_HDLC 4104#if SYNCLINK_GENERIC_HDLC
4113 4105
4114/** 4106/**
4115 * called by generic HDLC layer when protocol selected (PPP, frame relay, etc.) 4107 * called by generic HDLC layer when protocol selected (PPP, frame relay, etc.)
diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index 520d2cf82bc0..4abd1eff61d6 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -106,7 +106,7 @@ static inline void pp_enable_irq (struct pp_struct *pp)
106static ssize_t pp_read (struct file * file, char __user * buf, size_t count, 106static ssize_t pp_read (struct file * file, char __user * buf, size_t count,
107 loff_t * ppos) 107 loff_t * ppos)
108{ 108{
109 unsigned int minor = iminor(file->f_dentry->d_inode); 109 unsigned int minor = iminor(file->f_path.dentry->d_inode);
110 struct pp_struct *pp = file->private_data; 110 struct pp_struct *pp = file->private_data;
111 char * kbuffer; 111 char * kbuffer;
112 ssize_t bytes_read = 0; 112 ssize_t bytes_read = 0;
@@ -189,7 +189,7 @@ static ssize_t pp_read (struct file * file, char __user * buf, size_t count,
189static ssize_t pp_write (struct file * file, const char __user * buf, 189static ssize_t pp_write (struct file * file, const char __user * buf,
190 size_t count, loff_t * ppos) 190 size_t count, loff_t * ppos)
191{ 191{
192 unsigned int minor = iminor(file->f_dentry->d_inode); 192 unsigned int minor = iminor(file->f_path.dentry->d_inode);
193 struct pp_struct *pp = file->private_data; 193 struct pp_struct *pp = file->private_data;
194 char * kbuffer; 194 char * kbuffer;
195 ssize_t bytes_written = 0; 195 ssize_t bytes_written = 0;
@@ -269,7 +269,7 @@ static ssize_t pp_write (struct file * file, const char __user * buf,
269 return bytes_written; 269 return bytes_written;
270} 270}
271 271
272static void pp_irq (int irq, void * private, struct pt_regs * unused) 272static void pp_irq (int irq, void * private)
273{ 273{
274 struct pp_struct * pp = (struct pp_struct *) private; 274 struct pp_struct * pp = (struct pp_struct *) private;
275 275
@@ -752,13 +752,13 @@ static const struct file_operations pp_fops = {
752 752
753static void pp_attach(struct parport *port) 753static void pp_attach(struct parport *port)
754{ 754{
755 class_device_create(ppdev_class, NULL, MKDEV(PP_MAJOR, port->number), 755 device_create(ppdev_class, NULL, MKDEV(PP_MAJOR, port->number),
756 NULL, "parport%d", port->number); 756 "parport%d", port->number);
757} 757}
758 758
759static void pp_detach(struct parport *port) 759static void pp_detach(struct parport *port)
760{ 760{
761 class_device_destroy(ppdev_class, MKDEV(PP_MAJOR, port->number)); 761 device_destroy(ppdev_class, MKDEV(PP_MAJOR, port->number));
762} 762}
763 763
764static struct parport_driver pp_driver = { 764static struct parport_driver pp_driver = {
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index 34dd4c38110e..c07a1b5cd05d 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -218,13 +218,13 @@ out:
218 return retval; 218 return retval;
219} 219}
220 220
221static void pty_set_termios(struct tty_struct *tty, struct termios *old_termios) 221static void pty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
222{ 222{
223 tty->termios->c_cflag &= ~(CSIZE | PARENB); 223 tty->termios->c_cflag &= ~(CSIZE | PARENB);
224 tty->termios->c_cflag |= (CS8 | CREAD); 224 tty->termios->c_cflag |= (CS8 | CREAD);
225} 225}
226 226
227static struct tty_operations pty_ops = { 227static const struct tty_operations pty_ops = {
228 .open = pty_open, 228 .open = pty_open,
229 .close = pty_close, 229 .close = pty_close,
230 .write = pty_write, 230 .write = pty_write,
@@ -272,6 +272,8 @@ static void __init legacy_pty_init(void)
272 pty_driver->init_termios.c_oflag = 0; 272 pty_driver->init_termios.c_oflag = 0;
273 pty_driver->init_termios.c_cflag = B38400 | CS8 | CREAD; 273 pty_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
274 pty_driver->init_termios.c_lflag = 0; 274 pty_driver->init_termios.c_lflag = 0;
275 pty_driver->init_termios.c_ispeed = 38400;
276 pty_driver->init_termios.c_ospeed = 38400;
275 pty_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW; 277 pty_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW;
276 pty_driver->other = pty_slave_driver; 278 pty_driver->other = pty_slave_driver;
277 tty_set_operations(pty_driver, &pty_ops); 279 tty_set_operations(pty_driver, &pty_ops);
@@ -286,6 +288,8 @@ static void __init legacy_pty_init(void)
286 pty_slave_driver->subtype = PTY_TYPE_SLAVE; 288 pty_slave_driver->subtype = PTY_TYPE_SLAVE;
287 pty_slave_driver->init_termios = tty_std_termios; 289 pty_slave_driver->init_termios = tty_std_termios;
288 pty_slave_driver->init_termios.c_cflag = B38400 | CS8 | CREAD; 290 pty_slave_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
291 pty_slave_driver->init_termios.c_ispeed = 38400;
292 pty_slave_driver->init_termios.c_ospeed = 38400;
289 pty_slave_driver->flags = TTY_DRIVER_RESET_TERMIOS | 293 pty_slave_driver->flags = TTY_DRIVER_RESET_TERMIOS |
290 TTY_DRIVER_REAL_RAW; 294 TTY_DRIVER_REAL_RAW;
291 pty_slave_driver->other = pty_driver; 295 pty_slave_driver->other = pty_driver;
@@ -366,6 +370,8 @@ static void __init unix98_pty_init(void)
366 ptm_driver->init_termios.c_oflag = 0; 370 ptm_driver->init_termios.c_oflag = 0;
367 ptm_driver->init_termios.c_cflag = B38400 | CS8 | CREAD; 371 ptm_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
368 ptm_driver->init_termios.c_lflag = 0; 372 ptm_driver->init_termios.c_lflag = 0;
373 ptm_driver->init_termios.c_ispeed = 38400;
374 ptm_driver->init_termios.c_ospeed = 38400;
369 ptm_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW | 375 ptm_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW |
370 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM; 376 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM;
371 ptm_driver->other = pts_driver; 377 ptm_driver->other = pts_driver;
@@ -381,6 +387,8 @@ static void __init unix98_pty_init(void)
381 pts_driver->subtype = PTY_TYPE_SLAVE; 387 pts_driver->subtype = PTY_TYPE_SLAVE;
382 pts_driver->init_termios = tty_std_termios; 388 pts_driver->init_termios = tty_std_termios;
383 pts_driver->init_termios.c_cflag = B38400 | CS8 | CREAD; 389 pts_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
390 pts_driver->init_termios.c_ispeed = 38400;
391 pts_driver->init_termios.c_ospeed = 38400;
384 pts_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW | 392 pts_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW |
385 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM; 393 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM;
386 pts_driver->other = ptm_driver; 394 pts_driver->other = ptm_driver;
diff --git a/drivers/char/qtronix.c b/drivers/char/qtronix.c
deleted file mode 100644
index 9d134e98d2a0..000000000000
--- a/drivers/char/qtronix.c
+++ /dev/null
@@ -1,605 +0,0 @@
1/*
2 *
3 * BRIEF MODULE DESCRIPTION
4 * Qtronix 990P infrared keyboard driver.
5 *
6 *
7 * Copyright 2001 MontaVista Software Inc.
8 * Author: MontaVista Software, Inc.
9 * ppopov@mvista.com or source@mvista.com
10 *
11 *
12 * The bottom portion of this driver was take from
13 * pc_keyb.c Please see that file for copyrights.
14 *
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the
17 * Free Software Foundation; either version 2 of the License, or (at your
18 * option) any later version.
19 *
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
23 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * You should have received a copy of the GNU General Public License along
32 * with this program; if not, write to the Free Software Foundation, Inc.,
33 * 675 Mass Ave, Cambridge, MA 02139, USA.
34 */
35
36
37/*
38 * NOTE:
39 *
40 * This driver has only been tested with the Consumer IR
41 * port of the ITE 8172 system controller.
42 *
43 * You do not need this driver if you are using the ps/2 or
44 * USB adapter that the keyboard ships with. You only need
45 * this driver if your board has a IR port and the keyboard
46 * data is being sent directly to the IR. In that case,
47 * you also need some low-level IR support. See it8172_cir.c.
48 *
49 */
50
51#ifdef CONFIG_QTRONIX_KEYBOARD
52
53#include <linux/module.h>
54#include <linux/types.h>
55#include <linux/pci.h>
56#include <linux/kernel.h>
57
58#include <asm/it8172/it8172.h>
59#include <asm/it8172/it8172_int.h>
60#include <asm/it8172/it8172_cir.h>
61
62#include <linux/spinlock.h>
63#include <linux/sched.h>
64#include <linux/interrupt.h>
65#include <linux/tty.h>
66#include <linux/mm.h>
67#include <linux/signal.h>
68#include <linux/init.h>
69#include <linux/kbd_ll.h>
70#include <linux/delay.h>
71#include <linux/poll.h>
72#include <linux/miscdevice.h>
73#include <linux/slab.h>
74#include <linux/kbd_kern.h>
75#include <linux/smp_lock.h>
76#include <asm/io.h>
77#include <linux/pc_keyb.h>
78
79#include <asm/keyboard.h>
80#include <linux/bitops.h>
81#include <asm/uaccess.h>
82#include <asm/irq.h>
83#include <asm/system.h>
84
85#define leading1 0
86#define leading2 0xF
87
88#define KBD_CIR_PORT 0
89#define AUX_RECONNECT 170 /* scancode when ps2 device is plugged (back) in */
90
91static int data_index;
92struct cir_port *cir;
93static unsigned char kbdbytes[5];
94static unsigned char cir_data[32]; /* we only need 16 chars */
95
96static void kbd_int_handler(int irq, void *dev_id, struct pt_regs *regs);
97static int handle_data(unsigned char *p_data);
98static inline void handle_mouse_event(unsigned char scancode);
99static inline void handle_keyboard_event(unsigned char scancode, int down);
100static int __init psaux_init(void);
101
102static struct aux_queue *queue; /* Mouse data buffer. */
103static int aux_count = 0;
104
105/*
106 * Keys accessed through the 'Fn' key
107 * The Fn key does not produce a key-up sequence. So, the first
108 * time the user presses it, it will be key-down event. The key
109 * stays down until the user presses it again.
110 */
111#define NUM_FN_KEYS 56
112static unsigned char fn_keys[NUM_FN_KEYS] = {
113 0,0,0,0,0,0,0,0, /* 0 7 */
114 8,9,10,93,0,0,0,0, /* 8 15 */
115 0,0,0,0,0,0,0,5, /* 16 23 */
116 6,7,91,0,0,0,0,0, /* 24 31 */
117 0,0,0,0,0,2,3,4, /* 32 39 */
118 92,0,0,0,0,0,0,0, /* 40 47 */
119 0,0,0,0,11,0,94,95 /* 48 55 */
120
121};
122
123void __init init_qtronix_990P_kbd(void)
124{
125 int retval;
126
127 cir = (struct cir_port *)kmalloc(sizeof(struct cir_port), GFP_KERNEL);
128 if (!cir) {
129 printk("Unable to initialize Qtronix keyboard\n");
130 return;
131 }
132
133 /*
134 * revisit
135 * this should be programmable, somehow by the, by the user.
136 */
137 cir->port = KBD_CIR_PORT;
138 cir->baud_rate = 0x1d;
139 cir->rdwos = 0;
140 cir->rxdcr = 0x3;
141 cir->hcfs = 0;
142 cir->fifo_tl = 0;
143 cir->cfq = 0x1d;
144 cir_port_init(cir);
145
146 retval = request_irq(IT8172_CIR0_IRQ, kbd_int_handler,
147 (unsigned long )(IRQF_DISABLED|IRQF_SHARED),
148 (const char *)"Qtronix IR Keyboard", (void *)cir);
149
150 if (retval) {
151 printk("unable to allocate cir %d irq %d\n",
152 cir->port, IT8172_CIR0_IRQ);
153 }
154#ifdef CONFIG_PSMOUSE
155 psaux_init();
156#endif
157}
158
159static inline unsigned char BitReverse(unsigned short key)
160{
161 unsigned char rkey = 0;
162 rkey |= (key & 0x1) << 7;
163 rkey |= (key & 0x2) << 5;
164 rkey |= (key & 0x4) << 3;
165 rkey |= (key & 0x8) << 1;
166 rkey |= (key & 0x10) >> 1;
167 rkey |= (key & 0x20) >> 3;
168 rkey |= (key & 0x40) >> 5;
169 rkey |= (key & 0x80) >> 7;
170 return rkey;
171
172}
173
174
175static inline u_int8_t UpperByte(u_int8_t data)
176{
177 return (data >> 4);
178}
179
180
181static inline u_int8_t LowerByte(u_int8_t data)
182{
183 return (data & 0xF);
184}
185
186
187int CheckSumOk(u_int8_t byte1, u_int8_t byte2,
188 u_int8_t byte3, u_int8_t byte4, u_int8_t byte5)
189{
190 u_int8_t CheckSum;
191
192 CheckSum = (byte1 & 0x0F) + byte2 + byte3 + byte4 + byte5;
193 if ( LowerByte(UpperByte(CheckSum) + LowerByte(CheckSum)) != UpperByte(byte1) )
194 return 0;
195 else
196 return 1;
197}
198
199
200static void kbd_int_handler(int irq, void *dev_id, struct pt_regs *regs)
201{
202 struct cir_port *cir;
203 int j;
204 unsigned char int_status;
205
206 cir = (struct cir_port *)dev_id;
207 int_status = get_int_status(cir);
208 if (int_status & 0x4) {
209 clear_fifo(cir);
210 return;
211 }
212
213 while (cir_get_rx_count(cir)) {
214
215 cir_data[data_index] = cir_read_data(cir);
216
217 if (data_index == 0) {/* expecting first byte */
218 if (cir_data[data_index] != leading1) {
219 //printk("!leading byte %x\n", cir_data[data_index]);
220 set_rx_active(cir);
221 clear_fifo(cir);
222 continue;
223 }
224 }
225 if (data_index == 1) {
226 if ((cir_data[data_index] & 0xf) != leading2) {
227 set_rx_active(cir);
228 data_index = 0; /* start over */
229 clear_fifo(cir);
230 continue;
231 }
232 }
233
234 if ( (cir_data[data_index] == 0xff)) { /* last byte */
235 //printk("data_index %d\n", data_index);
236 set_rx_active(cir);
237#if 0
238 for (j=0; j<=data_index; j++) {
239 printk("rx_data %d: %x\n", j, cir_data[j]);
240 }
241#endif
242 data_index = 0;
243 handle_data(cir_data);
244 return;
245 }
246 else if (data_index>16) {
247 set_rx_active(cir);
248#if 0
249 printk("warning: data_index %d\n", data_index);
250 for (j=0; j<=data_index; j++) {
251 printk("rx_data %d: %x\n", j, cir_data[j]);
252 }
253#endif
254 data_index = 0;
255 clear_fifo(cir);
256 return;
257 }
258 data_index++;
259 }
260}
261
262
263#define NUM_KBD_BYTES 5
264static int handle_data(unsigned char *p_data)
265{
266 u_int32_t bit_bucket;
267 u_int32_t i, j;
268 u_int32_t got_bits, next_byte;
269 int down = 0;
270
271 /* Reorganize the bit stream */
272 for (i=0; i<16; i++)
273 p_data[i] = BitReverse(~p_data[i]);
274
275 /*
276 * We've already previously checked that p_data[0]
277 * is equal to leading1 and that (p_data[1] & 0xf)
278 * is equal to leading2. These twelve bits are the
279 * leader code. We can now throw them away (the 12
280 * bits) and continue parsing the stream.
281 */
282 bit_bucket = p_data[1] << 12;
283 got_bits = 4;
284 next_byte = 2;
285
286 /*
287 * Process four bits at a time
288 */
289 for (i=0; i<NUM_KBD_BYTES; i++) {
290
291 kbdbytes[i]=0;
292
293 for (j=0; j<8; j++) /* 8 bits per byte */
294 {
295 if (got_bits < 4) {
296 bit_bucket |= (p_data[next_byte++] << (8 - got_bits));
297 got_bits += 8;
298 }
299
300 if ((bit_bucket & 0xF000) == 0x8000) {
301 /* Convert 1000b to 1 */
302 kbdbytes[i] = 0x80 | (kbdbytes[i] >> 1);
303 got_bits -= 4;
304 bit_bucket = bit_bucket << 4;
305 }
306 else if ((bit_bucket & 0xC000) == 0x8000) {
307 /* Convert 10b to 0 */
308 kbdbytes[i] = kbdbytes[i] >> 1;
309 got_bits -= 2;
310 bit_bucket = bit_bucket << 2;
311 }
312 else {
313 /* bad serial stream */
314 return 1;
315 }
316
317 if (next_byte > 16) {
318 //printk("error: too many bytes\n");
319 return 1;
320 }
321 }
322 }
323
324
325 if (!CheckSumOk(kbdbytes[0], kbdbytes[1],
326 kbdbytes[2], kbdbytes[3], kbdbytes[4])) {
327 //printk("checksum failed\n");
328 return 1;
329 }
330
331 if (kbdbytes[1] & 0x08) {
332 //printk("m: %x %x %x\n", kbdbytes[1], kbdbytes[2], kbdbytes[3]);
333 handle_mouse_event(kbdbytes[1]);
334 handle_mouse_event(kbdbytes[2]);
335 handle_mouse_event(kbdbytes[3]);
336 }
337 else {
338 if (kbdbytes[2] == 0) down = 1;
339#if 0
340 if (down)
341 printk("down %d\n", kbdbytes[3]);
342 else
343 printk("up %d\n", kbdbytes[3]);
344#endif
345 handle_keyboard_event(kbdbytes[3], down);
346 }
347 return 0;
348}
349
350
351DEFINE_SPINLOCK(kbd_controller_lock);
352static unsigned char handle_kbd_event(void);
353
354
355int kbd_setkeycode(unsigned int scancode, unsigned int keycode)
356{
357 printk("kbd_setkeycode scancode %x keycode %x\n", scancode, keycode);
358 return 0;
359}
360
361int kbd_getkeycode(unsigned int scancode)
362{
363 return scancode;
364}
365
366
367int kbd_translate(unsigned char scancode, unsigned char *keycode,
368 char raw_mode)
369{
370 static int prev_scancode = 0;
371
372 if (scancode == 0x00 || scancode == 0xff) {
373 prev_scancode = 0;
374 return 0;
375 }
376
377 /* todo */
378 if (!prev_scancode && scancode == 160) { /* Fn key down */
379 //printk("Fn key down\n");
380 prev_scancode = 160;
381 return 0;
382 }
383 else if (prev_scancode && scancode == 160) { /* Fn key up */
384 //printk("Fn key up\n");
385 prev_scancode = 0;
386 return 0;
387 }
388
389 /* todo */
390 if (prev_scancode == 160) {
391 if (scancode <= NUM_FN_KEYS) {
392 *keycode = fn_keys[scancode];
393 //printk("fn keycode %d\n", *keycode);
394 }
395 else
396 return 0;
397 }
398 else if (scancode <= 127) {
399 *keycode = scancode;
400 }
401 else
402 return 0;
403
404
405 return 1;
406}
407
408char kbd_unexpected_up(unsigned char keycode)
409{
410 //printk("kbd_unexpected_up\n");
411 return 0;
412}
413
414static unsigned char kbd_exists = 1;
415
416static inline void handle_keyboard_event(unsigned char scancode, int down)
417{
418 kbd_exists = 1;
419 handle_scancode(scancode, down);
420 tasklet_schedule(&keyboard_tasklet);
421}
422
423
424void kbd_leds(unsigned char leds)
425{
426}
427
428/* dummy */
429void kbd_init_hw(void)
430{
431}
432
433
434
435static inline void handle_mouse_event(unsigned char scancode)
436{
437 if(scancode == AUX_RECONNECT){
438 queue->head = queue->tail = 0; /* Flush input queue */
439 // __aux_write_ack(AUX_ENABLE_DEV); /* ping the mouse :) */
440 return;
441 }
442
443 if (aux_count) {
444 int head = queue->head;
445
446 queue->buf[head] = scancode;
447 head = (head + 1) & (AUX_BUF_SIZE-1);
448 if (head != queue->tail) {
449 queue->head = head;
450 kill_fasync(&queue->fasync, SIGIO, POLL_IN);
451 wake_up_interruptible(&queue->proc_list);
452 }
453 }
454}
455
456static unsigned char get_from_queue(void)
457{
458 unsigned char result;
459 unsigned long flags;
460
461 spin_lock_irqsave(&kbd_controller_lock, flags);
462 result = queue->buf[queue->tail];
463 queue->tail = (queue->tail + 1) & (AUX_BUF_SIZE-1);
464 spin_unlock_irqrestore(&kbd_controller_lock, flags);
465 return result;
466}
467
468
469static inline int queue_empty(void)
470{
471 return queue->head == queue->tail;
472}
473
474static int fasync_aux(int fd, struct file *filp, int on)
475{
476 int retval;
477
478 //printk("fasync_aux\n");
479 retval = fasync_helper(fd, filp, on, &queue->fasync);
480 if (retval < 0)
481 return retval;
482 return 0;
483}
484
485
486/*
487 * Random magic cookie for the aux device
488 */
489#define AUX_DEV ((void *)queue)
490
491static int release_aux(struct inode * inode, struct file * file)
492{
493 fasync_aux(-1, file, 0);
494 aux_count--;
495 return 0;
496}
497
498static int open_aux(struct inode * inode, struct file * file)
499{
500 if (aux_count++) {
501 return 0;
502 }
503 queue->head = queue->tail = 0; /* Flush input queue */
504 return 0;
505}
506
507/*
508 * Put bytes from input queue to buffer.
509 */
510
511static ssize_t read_aux(struct file * file, char * buffer,
512 size_t count, loff_t *ppos)
513{
514 DECLARE_WAITQUEUE(wait, current);
515 ssize_t i = count;
516 unsigned char c;
517
518 if (queue_empty()) {
519 if (file->f_flags & O_NONBLOCK)
520 return -EAGAIN;
521 add_wait_queue(&queue->proc_list, &wait);
522repeat:
523 set_current_state(TASK_INTERRUPTIBLE);
524 if (queue_empty() && !signal_pending(current)) {
525 schedule();
526 goto repeat;
527 }
528 current->state = TASK_RUNNING;
529 remove_wait_queue(&queue->proc_list, &wait);
530 }
531 while (i > 0 && !queue_empty()) {
532 c = get_from_queue();
533 put_user(c, buffer++);
534 i--;
535 }
536 if (count-i) {
537 struct inode *inode = file->f_dentry->d_inode;
538 inode->i_atime = current_fs_time(inode->i_sb);
539 return count-i;
540 }
541 if (signal_pending(current))
542 return -ERESTARTSYS;
543 return 0;
544}
545
546/*
547 * Write to the aux device.
548 */
549
550static ssize_t write_aux(struct file * file, const char * buffer,
551 size_t count, loff_t *ppos)
552{
553 /*
554 * The ITE boards this was tested on did not have the
555 * transmit wires connected.
556 */
557 return count;
558}
559
560static unsigned int aux_poll(struct file *file, poll_table * wait)
561{
562 poll_wait(file, &queue->proc_list, wait);
563 if (!queue_empty())
564 return POLLIN | POLLRDNORM;
565 return 0;
566}
567
568struct file_operations psaux_fops = {
569 .read = read_aux,
570 .write = write_aux,
571 .poll = aux_poll,
572 .open = open_aux,
573 .release = release_aux,
574 .fasync = fasync_aux,
575};
576
577/*
578 * Initialize driver.
579 */
580static struct miscdevice psaux_mouse = {
581 PSMOUSE_MINOR, "psaux", &psaux_fops
582};
583
584static int __init psaux_init(void)
585{
586 int retval;
587
588 retval = misc_register(&psaux_mouse);
589 if(retval < 0)
590 return retval;
591
592 queue = (struct aux_queue *) kmalloc(sizeof(*queue), GFP_KERNEL);
593 if (!queue) {
594 misc_deregister(&psaux_mouse);
595 return -ENOMEM;
596 }
597
598 memset(queue, 0, sizeof(*queue));
599 queue->head = queue->tail = 0;
600 init_waitqueue_head(&queue->proc_list);
601
602 return 0;
603}
604module_init(init_qtronix_990P_kbd);
605#endif
diff --git a/drivers/char/qtronixmap.c_shipped b/drivers/char/qtronixmap.c_shipped
deleted file mode 100644
index 1e2b92b7d57a..000000000000
--- a/drivers/char/qtronixmap.c_shipped
+++ /dev/null
@@ -1,265 +0,0 @@
1
2/* Do not edit this file! It was automatically generated by */
3/* loadkeys --mktable defkeymap.map > defkeymap.c */
4
5#include <linux/types.h>
6#include <linux/keyboard.h>
7#include <linux/kd.h>
8
9u_short plain_map[NR_KEYS] = {
10 0xf200, 0xf060, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
11 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf200, 0xf07f,
12 0xf009, 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75,
13 0xfb69, 0xfb6f, 0xfb70, 0xf05b, 0xf05d, 0xf05c, 0xf207, 0xfb61,
14 0xfb73, 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c,
15 0xf03b, 0xf027, 0xf060, 0xf201, 0xf700, 0xf200, 0xfb7a, 0xfb78,
16 0xfb63, 0xfb76, 0xfb62, 0xfb6e, 0xfb6d, 0xf02c, 0xf02e, 0xf02f,
17 0xf200, 0xf700, 0xf702, 0xf200, 0xf703, 0xf020, 0xf703, 0xf200,
18 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
19 0xf200, 0xf200, 0xf200, 0xf115, 0xf07f, 0xf200, 0xf200, 0xf601,
20 0xf200, 0xf200, 0xf200, 0xf603, 0xf600, 0xf118, 0xf119, 0xf200,
21 0xf200, 0xf602, 0xf208, 0xf02d, 0xf02b, 0xf30c, 0xf02e, 0xf30d,
22 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
23 0xf200, 0xf200, 0xf200, 0xf117, 0xf600, 0xf200, 0xf01b, 0xf200,
24 0xf100, 0xf101, 0xf102, 0xf103, 0xf104, 0xf105, 0xf106, 0xf107,
25 0xf108, 0xf109, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d, 0xf200,
26};
27
28u_short shift_map[NR_KEYS] = {
29 0xf200, 0xf07e, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
30 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf200, 0xf07f,
31 0xf009, 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55,
32 0xfb49, 0xfb4f, 0xfb50, 0xf07b, 0xf07d, 0xf07c, 0xf207, 0xfb41,
33 0xfb53, 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c,
34 0xf03a, 0xf022, 0xf07e, 0xf201, 0xf700, 0xf200, 0xfb5a, 0xfb58,
35 0xfb43, 0xfb56, 0xfb42, 0xfb4e, 0xfb4d, 0xf03c, 0xf03e, 0xf03f,
36 0xf200, 0xf700, 0xf702, 0xf200, 0xf703, 0xf020, 0xf703, 0xf200,
37 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
38 0xf200, 0xf200, 0xf200, 0xf115, 0xf07f, 0xf200, 0xf200, 0xf601,
39 0xf200, 0xf200, 0xf200, 0xf603, 0xf600, 0xf20b, 0xf20a, 0xf200,
40 0xf200, 0xf602, 0xf213, 0xf02d, 0xf02b, 0xf30c, 0xf02e, 0xf30d,
41 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
42 0xf200, 0xf200, 0xf200, 0xf117, 0xf600, 0xf200, 0xf01b, 0xf200,
43 0xf10a, 0xf10b, 0xf10c, 0xf10d, 0xf10e, 0xf10f, 0xf110, 0xf111,
44 0xf112, 0xf113, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d, 0xf200,
45};
46
47u_short altgr_map[NR_KEYS] = {
48 0xf200, 0xf200, 0xf200, 0xf040, 0xf200, 0xf024, 0xf200, 0xf200,
49 0xf07b, 0xf05b, 0xf05d, 0xf07d, 0xf05c, 0xf200, 0xf200, 0xf200,
50 0xf200, 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75,
51 0xfb69, 0xfb6f, 0xfb70, 0xf200, 0xf200, 0xf200, 0xf207, 0xfb61,
52 0xfb73, 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c,
53 0xf200, 0xf200, 0xf200, 0xf201, 0xf700, 0xf200, 0xfb7a, 0xfb78,
54 0xfb63, 0xfb76, 0xfb62, 0xfb6e, 0xfb6d, 0xf200, 0xf200, 0xf200,
55 0xf200, 0xf700, 0xf702, 0xf200, 0xf703, 0xf200, 0xf703, 0xf200,
56 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
57 0xf200, 0xf200, 0xf200, 0xf115, 0xf07f, 0xf200, 0xf200, 0xf601,
58 0xf200, 0xf200, 0xf200, 0xf603, 0xf600, 0xf118, 0xf119, 0xf200,
59 0xf200, 0xf602, 0xf208, 0xf02d, 0xf02b, 0xf30c, 0xf02e, 0xf30d,
60 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
61 0xf200, 0xf200, 0xf200, 0xf117, 0xf600, 0xf200, 0xf200, 0xf200,
62 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510, 0xf511, 0xf512, 0xf513,
63 0xf514, 0xf515, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d, 0xf200,
64};
65
66u_short ctrl_map[NR_KEYS] = {
67 0xf200, 0xf200, 0xf200, 0xf000, 0xf01b, 0xf01c, 0xf01d, 0xf01e,
68 0xf01f, 0xf07f, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf200, 0xf008,
69 0xf200, 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015,
70 0xf009, 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf01c, 0xf207, 0xf001,
71 0xf013, 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c,
72 0xf007, 0xf000, 0xf200, 0xf201, 0xf700, 0xf200, 0xf01a, 0xf018,
73 0xf003, 0xf016, 0xf002, 0xf00e, 0xf20e, 0xf07f, 0xf200, 0xf200,
74 0xf200, 0xf700, 0xf702, 0xf200, 0xf703, 0xf000, 0xf703, 0xf200,
75 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
76 0xf200, 0xf200, 0xf200, 0xf115, 0xf07f, 0xf200, 0xf200, 0xf601,
77 0xf200, 0xf200, 0xf200, 0xf603, 0xf600, 0xf118, 0xf119, 0xf200,
78 0xf200, 0xf602, 0xf208, 0xf02d, 0xf02b, 0xf30c, 0xf02e, 0xf30d,
79 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
80 0xf200, 0xf200, 0xf200, 0xf117, 0xf600, 0xf200, 0xf200, 0xf200,
81 0xf100, 0xf101, 0xf102, 0xf103, 0xf104, 0xf105, 0xf106, 0xf107,
82 0xf108, 0xf109, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d, 0xf200,
83};
84
85u_short shift_ctrl_map[NR_KEYS] = {
86 0xf200, 0xf200, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf200,
87 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf200, 0xf200,
88 0xf200, 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015,
89 0xf009, 0xf00f, 0xf010, 0xf200, 0xf200, 0xf200, 0xf207, 0xf001,
90 0xf013, 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c,
91 0xf200, 0xf200, 0xf200, 0xf201, 0xf700, 0xf200, 0xf01a, 0xf018,
92 0xf003, 0xf016, 0xf002, 0xf00e, 0xf00d, 0xf200, 0xf200, 0xf200,
93 0xf200, 0xf700, 0xf702, 0xf200, 0xf703, 0xf200, 0xf703, 0xf200,
94 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
95 0xf200, 0xf200, 0xf200, 0xf115, 0xf07f, 0xf200, 0xf200, 0xf601,
96 0xf200, 0xf200, 0xf200, 0xf603, 0xf600, 0xf118, 0xf119, 0xf200,
97 0xf200, 0xf602, 0xf208, 0xf02d, 0xf02b, 0xf30c, 0xf02e, 0xf30d,
98 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
99 0xf200, 0xf200, 0xf200, 0xf117, 0xf600, 0xf200, 0xf200, 0xf200,
100 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
101 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d, 0xf200,
102};
103
104u_short alt_map[NR_KEYS] = {
105 0xf200, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
106 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf200, 0xf87f,
107 0xf809, 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875,
108 0xf869, 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf85c, 0xf207, 0xf861,
109 0xf873, 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf83b,
110 0xf827, 0xf860, 0xf200, 0xf80d, 0xf700, 0xf200, 0xf87a, 0xf878,
111 0xf863, 0xf876, 0xf862, 0xf82c, 0xf82e, 0xf82f, 0xf200, 0xf200,
112 0xf200, 0xf700, 0xf702, 0xf200, 0xf703, 0xf820, 0xf703, 0xf200,
113 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
114 0xf200, 0xf200, 0xf200, 0xf115, 0xf07f, 0xf200, 0xf200, 0xf210,
115 0xf200, 0xf200, 0xf200, 0xf603, 0xf600, 0xf118, 0xf119, 0xf200,
116 0xf200, 0xf211, 0xf208, 0xf02d, 0xf02b, 0xf30c, 0xf02e, 0xf30d,
117 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
118 0xf200, 0xf200, 0xf200, 0xf117, 0xf600, 0xf200, 0xf200, 0xf200,
119 0xf500, 0xf501, 0xf502, 0xf503, 0xf504, 0xf505, 0xf506, 0xf507,
120 0xf508, 0xf509, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d, 0xf200,
121};
122
123u_short ctrl_alt_map[NR_KEYS] = {
124 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
125 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
126 0xf200, 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815,
127 0xf809, 0xf80f, 0xf810, 0xf200, 0xf200, 0xf200, 0xf207, 0xf801,
128 0xf813, 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c,
129 0xf200, 0xf200, 0xf200, 0xf201, 0xf700, 0xf200, 0xf81a, 0xf818,
130 0xf803, 0xf816, 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf200, 0xf200,
131 0xf200, 0xf700, 0xf702, 0xf200, 0xf703, 0xf200, 0xf703, 0xf200,
132 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
133 0xf200, 0xf200, 0xf200, 0xf115, 0xf07f, 0xf200, 0xf200, 0xf601,
134 0xf200, 0xf200, 0xf200, 0xf603, 0xf600, 0xf118, 0xf119, 0xf200,
135 0xf200, 0xf602, 0xf208, 0xf02d, 0xf02b, 0xf30c, 0xf02e, 0xf30d,
136 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
137 0xf200, 0xf200, 0xf200, 0xf117, 0xf600, 0xf200, 0xf200, 0xf200,
138 0xf500, 0xf501, 0xf502, 0xf503, 0xf504, 0xf505, 0xf506, 0xf507,
139 0xf508, 0xf509, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d, 0xf200,
140};
141
142ushort *key_maps[MAX_NR_KEYMAPS] = {
143 plain_map, shift_map, altgr_map, 0,
144 ctrl_map, shift_ctrl_map, 0, 0,
145 alt_map, 0, 0, 0,
146 ctrl_alt_map, 0
147};
148
149unsigned int keymap_count = 7;
150
151
152/*
153 * Philosophy: most people do not define more strings, but they who do
154 * often want quite a lot of string space. So, we statically allocate
155 * the default and allocate dynamically in chunks of 512 bytes.
156 */
157
158char func_buf[] = {
159 '\033', '[', '[', 'A', 0,
160 '\033', '[', '[', 'B', 0,
161 '\033', '[', '[', 'C', 0,
162 '\033', '[', '[', 'D', 0,
163 '\033', '[', '[', 'E', 0,
164 '\033', '[', '1', '7', '~', 0,
165 '\033', '[', '1', '8', '~', 0,
166 '\033', '[', '1', '9', '~', 0,
167 '\033', '[', '2', '0', '~', 0,
168 '\033', '[', '2', '1', '~', 0,
169 '\033', '[', '2', '3', '~', 0,
170 '\033', '[', '2', '4', '~', 0,
171 '\033', '[', '2', '5', '~', 0,
172 '\033', '[', '2', '6', '~', 0,
173 '\033', '[', '2', '8', '~', 0,
174 '\033', '[', '2', '9', '~', 0,
175 '\033', '[', '3', '1', '~', 0,
176 '\033', '[', '3', '2', '~', 0,
177 '\033', '[', '3', '3', '~', 0,
178 '\033', '[', '3', '4', '~', 0,
179 '\033', '[', '1', '~', 0,
180 '\033', '[', '2', '~', 0,
181 '\033', '[', '3', '~', 0,
182 '\033', '[', '4', '~', 0,
183 '\033', '[', '5', '~', 0,
184 '\033', '[', '6', '~', 0,
185 '\033', '[', 'M', 0,
186 '\033', '[', 'P', 0,
187};
188
189
190char *funcbufptr = func_buf;
191int funcbufsize = sizeof(func_buf);
192int funcbufleft = 0; /* space left */
193
194char *func_table[MAX_NR_FUNC] = {
195 func_buf + 0,
196 func_buf + 5,
197 func_buf + 10,
198 func_buf + 15,
199 func_buf + 20,
200 func_buf + 25,
201 func_buf + 31,
202 func_buf + 37,
203 func_buf + 43,
204 func_buf + 49,
205 func_buf + 55,
206 func_buf + 61,
207 func_buf + 67,
208 func_buf + 73,
209 func_buf + 79,
210 func_buf + 85,
211 func_buf + 91,
212 func_buf + 97,
213 func_buf + 103,
214 func_buf + 109,
215 func_buf + 115,
216 func_buf + 120,
217 func_buf + 125,
218 func_buf + 130,
219 func_buf + 135,
220 func_buf + 140,
221 func_buf + 145,
222 0,
223 0,
224 func_buf + 149,
225 0,
226};
227
228struct kbdiacr accent_table[MAX_DIACR] = {
229 {'`', 'A', 'À'}, {'`', 'a', 'à'},
230 {'\'', 'A', 'Á'}, {'\'', 'a', 'á'},
231 {'^', 'A', 'Â'}, {'^', 'a', 'â'},
232 {'~', 'A', 'Ã'}, {'~', 'a', 'ã'},
233 {'"', 'A', 'Ä'}, {'"', 'a', 'ä'},
234 {'O', 'A', 'Å'}, {'o', 'a', 'å'},
235 {'0', 'A', 'Å'}, {'0', 'a', 'å'},
236 {'A', 'A', 'Å'}, {'a', 'a', 'å'},
237 {'A', 'E', 'Æ'}, {'a', 'e', 'æ'},
238 {',', 'C', 'Ç'}, {',', 'c', 'ç'},
239 {'`', 'E', 'È'}, {'`', 'e', 'è'},
240 {'\'', 'E', 'É'}, {'\'', 'e', 'é'},
241 {'^', 'E', 'Ê'}, {'^', 'e', 'ê'},
242 {'"', 'E', 'Ë'}, {'"', 'e', 'ë'},
243 {'`', 'I', 'Ì'}, {'`', 'i', 'ì'},
244 {'\'', 'I', 'Í'}, {'\'', 'i', 'í'},
245 {'^', 'I', 'Î'}, {'^', 'i', 'î'},
246 {'"', 'I', 'Ï'}, {'"', 'i', 'ï'},
247 {'-', 'D', 'Ð'}, {'-', 'd', 'ð'},
248 {'~', 'N', 'Ñ'}, {'~', 'n', 'ñ'},
249 {'`', 'O', 'Ò'}, {'`', 'o', 'ò'},
250 {'\'', 'O', 'Ó'}, {'\'', 'o', 'ó'},
251 {'^', 'O', 'Ô'}, {'^', 'o', 'ô'},
252 {'~', 'O', 'Õ'}, {'~', 'o', 'õ'},
253 {'"', 'O', 'Ö'}, {'"', 'o', 'ö'},
254 {'/', 'O', 'Ø'}, {'/', 'o', 'ø'},
255 {'`', 'U', 'Ù'}, {'`', 'u', 'ù'},
256 {'\'', 'U', 'Ú'}, {'\'', 'u', 'ú'},
257 {'^', 'U', 'Û'}, {'^', 'u', 'û'},
258 {'"', 'U', 'Ü'}, {'"', 'u', 'ü'},
259 {'\'', 'Y', 'Ý'}, {'\'', 'y', 'ý'},
260 {'T', 'H', 'Þ'}, {'t', 'h', 'þ'},
261 {'s', 's', 'ß'}, {'"', 'y', 'ÿ'},
262 {'s', 'z', 'ß'}, {'i', 'j', 'ÿ'},
263};
264
265unsigned int accent_table_size = 68;
diff --git a/drivers/char/qtronixmap.map b/drivers/char/qtronixmap.map
deleted file mode 100644
index 8d1ff5c1e281..000000000000
--- a/drivers/char/qtronixmap.map
+++ /dev/null
@@ -1,287 +0,0 @@
1# Default kernel keymap. This uses 7 modifier combinations.
2keymaps 0-2,4-5,8,12
3# Change the above line into
4# keymaps 0-2,4-6,8,12
5# in case you want the entries
6# altgr control keycode 83 = Boot
7# altgr control keycode 111 = Boot
8# below.
9#
10# In fact AltGr is used very little, and one more keymap can
11# be saved by mapping AltGr to Alt (and adapting a few entries):
12# keycode 100 = Alt
13#
14keycode 1 = grave asciitilde
15 alt keycode 1 = Meta_Escape
16keycode 2 = one exclam
17 alt keycode 2 = Meta_one
18keycode 3 = two at at
19 control keycode 3 = nul
20 shift control keycode 3 = nul
21 alt keycode 3 = Meta_two
22keycode 4 = three numbersign
23 control keycode 4 = Escape
24 alt keycode 4 = Meta_three
25keycode 5 = four dollar dollar
26 control keycode 5 = Control_backslash
27 alt keycode 5 = Meta_four
28keycode 6 = five percent
29 control keycode 6 = Control_bracketright
30 alt keycode 6 = Meta_five
31keycode 7 = six asciicircum
32 control keycode 7 = Control_asciicircum
33 alt keycode 7 = Meta_six
34keycode 8 = seven ampersand braceleft
35 control keycode 8 = Control_underscore
36 alt keycode 8 = Meta_seven
37keycode 9 = eight asterisk bracketleft
38 control keycode 9 = Delete
39 alt keycode 9 = Meta_eight
40keycode 10 = nine parenleft bracketright
41 alt keycode 10 = Meta_nine
42keycode 11 = zero parenright braceright
43 alt keycode 11 = Meta_zero
44keycode 12 = minus underscore backslash
45 control keycode 12 = Control_underscore
46 shift control keycode 12 = Control_underscore
47 alt keycode 12 = Meta_minus
48keycode 13 = equal plus
49 alt keycode 13 = Meta_equal
50keycode 15 = Delete Delete
51 control keycode 15 = BackSpace
52 alt keycode 15 = Meta_Delete
53keycode 16 = Tab Tab
54 alt keycode 16 = Meta_Tab
55keycode 17 = q
56keycode 18 = w
57keycode 19 = e
58keycode 20 = r
59keycode 21 = t
60keycode 22 = y
61keycode 23 = u
62keycode 24 = i
63keycode 25 = o
64keycode 26 = p
65keycode 27 = bracketleft braceleft
66 control keycode 27 = Escape
67 alt keycode 27 = Meta_bracketleft
68keycode 28 = bracketright braceright
69 control keycode 28 = Control_bracketright
70 alt keycode 28 = Meta_bracketright
71keycode 29 = backslash bar
72 control keycode 29 = Control_backslash
73 alt keycode 29 = Meta_backslash
74keycode 30 = Caps_Lock
75keycode 31 = a
76keycode 32 = s
77keycode 33 = d
78keycode 34 = f
79keycode 35 = g
80keycode 36 = h
81keycode 37 = j
82keycode 38 = k
83keycode 39 = l
84keycode 40 = semicolon colon
85 alt keycode 39 = Meta_semicolon
86keycode 41 = apostrophe quotedbl
87 control keycode 40 = Control_g
88 alt keycode 40 = Meta_apostrophe
89keycode 42 = grave asciitilde
90 control keycode 41 = nul
91 alt keycode 41 = Meta_grave
92keycode 43 = Return
93 alt keycode 43 = Meta_Control_m
94keycode 44 = Shift
95keycode 46 = z
96keycode 47 = x
97keycode 48 = c
98keycode 49 = v
99keycode 50 = b
100keycode 51 = n
101keycode 52 = m
102keycode 53 = comma less
103 alt keycode 51 = Meta_comma
104keycode 54 = period greater
105 control keycode 52 = Compose
106 alt keycode 52 = Meta_period
107keycode 55 = slash question
108 control keycode 53 = Delete
109 alt keycode 53 = Meta_slash
110keycode 57 = Shift
111keycode 58 = Control
112keycode 60 = Alt
113keycode 61 = space space
114 control keycode 61 = nul
115 alt keycode 61 = Meta_space
116keycode 62 = Alt
117
118keycode 75 = Insert
119keycode 76 = Delete
120
121keycode 83 = Up
122keycode 84 = Down
123
124keycode 85 = Prior
125 shift keycode 85 = Scroll_Backward
126keycode 86 = Next
127 shift keycode 86 = Scroll_Forward
128keycode 89 = Right
129 alt keycode 89 = Incr_Console
130keycode 79 = Left
131 alt keycode 79 = Decr_Console
132
133keycode 90 = Num_Lock
134 shift keycode 90 = Bare_Num_Lock
135
136keycode 91 = minus
137keycode 92 = plus
138keycode 93 = KP_Multiply
139keycode 94 = period
140keycode 95 = KP_Divide
141
142keycode 107 = Select
143keycode 108 = Down
144
145keycode 110 = Escape Escape
146 alt keycode 1 = Meta_Escape
147
148keycode 112 = F1 F11 Console_13
149 control keycode 112 = F1
150 alt keycode 112 = Console_1
151 control alt keycode 112 = Console_1
152keycode 113 = F2 F12 Console_14
153 control keycode 113 = F2
154 alt keycode 113 = Console_2
155 control alt keycode 113 = Console_2
156keycode 114 = F3 F13 Console_15
157 control keycode 114 = F3
158 alt keycode 114 = Console_3
159 control alt keycode 114 = Console_3
160keycode 115 = F4 F14 Console_16
161 control keycode 115 = F4
162 alt keycode 115 = Console_4
163 control alt keycode 115 = Console_4
164keycode 116 = F5 F15 Console_17
165 control keycode 116 = F5
166 alt keycode 116 = Console_5
167 control alt keycode 116 = Console_5
168keycode 117 = F6 F16 Console_18
169 control keycode 117 = F6
170 alt keycode 117 = Console_6
171 control alt keycode 117 = Console_6
172keycode 118 = F7 F17 Console_19
173 control keycode 118 = F7
174 alt keycode 118 = Console_7
175 control alt keycode 118 = Console_7
176keycode 119 = F8 F18 Console_20
177 control keycode 119 = F8
178 alt keycode 119 = Console_8
179 control alt keycode 119 = Console_8
180keycode 120 = F9 F19 Console_21
181 control keycode 120 = F9
182 alt keycode 120 = Console_9
183 control alt keycode 120 = Console_9
184keycode 121 = F10 F20 Console_22
185 control keycode 121 = F10
186 alt keycode 121 = Console_10
187 control alt keycode 121 = Console_10
188
189keycode 126 = Pause
190
191
192string F1 = "\033[[A"
193string F2 = "\033[[B"
194string F3 = "\033[[C"
195string F4 = "\033[[D"
196string F5 = "\033[[E"
197string F6 = "\033[17~"
198string F7 = "\033[18~"
199string F8 = "\033[19~"
200string F9 = "\033[20~"
201string F10 = "\033[21~"
202string F11 = "\033[23~"
203string F12 = "\033[24~"
204string F13 = "\033[25~"
205string F14 = "\033[26~"
206string F15 = "\033[28~"
207string F16 = "\033[29~"
208string F17 = "\033[31~"
209string F18 = "\033[32~"
210string F19 = "\033[33~"
211string F20 = "\033[34~"
212string Find = "\033[1~"
213string Insert = "\033[2~"
214string Remove = "\033[3~"
215string Select = "\033[4~"
216string Prior = "\033[5~"
217string Next = "\033[6~"
218string Macro = "\033[M"
219string Pause = "\033[P"
220compose '`' 'A' to 'À'
221compose '`' 'a' to 'à'
222compose '\'' 'A' to 'Á'
223compose '\'' 'a' to 'á'
224compose '^' 'A' to 'Â'
225compose '^' 'a' to 'â'
226compose '~' 'A' to 'Ã'
227compose '~' 'a' to 'ã'
228compose '"' 'A' to 'Ä'
229compose '"' 'a' to 'ä'
230compose 'O' 'A' to 'Å'
231compose 'o' 'a' to 'å'
232compose '0' 'A' to 'Å'
233compose '0' 'a' to 'å'
234compose 'A' 'A' to 'Å'
235compose 'a' 'a' to 'å'
236compose 'A' 'E' to 'Æ'
237compose 'a' 'e' to 'æ'
238compose ',' 'C' to 'Ç'
239compose ',' 'c' to 'ç'
240compose '`' 'E' to 'È'
241compose '`' 'e' to 'è'
242compose '\'' 'E' to 'É'
243compose '\'' 'e' to 'é'
244compose '^' 'E' to 'Ê'
245compose '^' 'e' to 'ê'
246compose '"' 'E' to 'Ë'
247compose '"' 'e' to 'ë'
248compose '`' 'I' to 'Ì'
249compose '`' 'i' to 'ì'
250compose '\'' 'I' to 'Í'
251compose '\'' 'i' to 'í'
252compose '^' 'I' to 'Î'
253compose '^' 'i' to 'î'
254compose '"' 'I' to 'Ï'
255compose '"' 'i' to 'ï'
256compose '-' 'D' to 'Ð'
257compose '-' 'd' to 'ð'
258compose '~' 'N' to 'Ñ'
259compose '~' 'n' to 'ñ'
260compose '`' 'O' to 'Ò'
261compose '`' 'o' to 'ò'
262compose '\'' 'O' to 'Ó'
263compose '\'' 'o' to 'ó'
264compose '^' 'O' to 'Ô'
265compose '^' 'o' to 'ô'
266compose '~' 'O' to 'Õ'
267compose '~' 'o' to 'õ'
268compose '"' 'O' to 'Ö'
269compose '"' 'o' to 'ö'
270compose '/' 'O' to 'Ø'
271compose '/' 'o' to 'ø'
272compose '`' 'U' to 'Ù'
273compose '`' 'u' to 'ù'
274compose '\'' 'U' to 'Ú'
275compose '\'' 'u' to 'ú'
276compose '^' 'U' to 'Û'
277compose '^' 'u' to 'û'
278compose '"' 'U' to 'Ü'
279compose '"' 'u' to 'ü'
280compose '\'' 'Y' to 'Ý'
281compose '\'' 'y' to 'ý'
282compose 'T' 'H' to 'Þ'
283compose 't' 'h' to 'þ'
284compose 's' 's' to 'ß'
285compose '"' 'y' to 'ÿ'
286compose 's' 'z' to 'ß'
287compose 'i' 'j' to 'ÿ'
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 4c3a5ca9d8f7..13d0b1350a62 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -645,6 +645,7 @@ void add_input_randomness(unsigned int type, unsigned int code,
645 add_timer_randomness(&input_timer_state, 645 add_timer_randomness(&input_timer_state,
646 (type << 4) ^ code ^ (code >> 4) ^ value); 646 (type << 4) ^ code ^ (code >> 4) ^ value);
647} 647}
648EXPORT_SYMBOL_GPL(add_input_randomness);
648 649
649void add_interrupt_randomness(int irq) 650void add_interrupt_randomness(int irq)
650{ 651{
@@ -655,6 +656,7 @@ void add_interrupt_randomness(int irq)
655 add_timer_randomness(irq_timer_state[irq], 0x100 + irq); 656 add_timer_randomness(irq_timer_state[irq], 0x100 + irq);
656} 657}
657 658
659#ifdef CONFIG_BLOCK
658void add_disk_randomness(struct gendisk *disk) 660void add_disk_randomness(struct gendisk *disk)
659{ 661{
660 if (!disk || !disk->random) 662 if (!disk || !disk->random)
@@ -667,6 +669,7 @@ void add_disk_randomness(struct gendisk *disk)
667} 669}
668 670
669EXPORT_SYMBOL(add_disk_randomness); 671EXPORT_SYMBOL(add_disk_randomness);
672#endif
670 673
671#define EXTRACT_SIZE 10 674#define EXTRACT_SIZE 10
672 675
@@ -887,8 +890,8 @@ static void init_std_data(struct entropy_store *r)
887 890
888 do_gettimeofday(&tv); 891 do_gettimeofday(&tv);
889 add_entropy_words(r, (__u32 *)&tv, sizeof(tv)/4); 892 add_entropy_words(r, (__u32 *)&tv, sizeof(tv)/4);
890 add_entropy_words(r, (__u32 *)&system_utsname, 893 add_entropy_words(r, (__u32 *)utsname(),
891 sizeof(system_utsname)/4); 894 sizeof(*(utsname()))/4);
892} 895}
893 896
894static int __init rand_initialize(void) 897static int __init rand_initialize(void)
@@ -918,6 +921,7 @@ void rand_initialize_irq(int irq)
918 } 921 }
919} 922}
920 923
924#ifdef CONFIG_BLOCK
921void rand_initialize_disk(struct gendisk *disk) 925void rand_initialize_disk(struct gendisk *disk)
922{ 926{
923 struct timer_rand_state *state; 927 struct timer_rand_state *state;
@@ -932,6 +936,7 @@ void rand_initialize_disk(struct gendisk *disk)
932 disk->random = state; 936 disk->random = state;
933 } 937 }
934} 938}
939#endif
935 940
936static ssize_t 941static ssize_t
937random_read(struct file * file, char __user * buf, size_t nbytes, loff_t *ppos) 942random_read(struct file * file, char __user * buf, size_t nbytes, loff_t *ppos)
@@ -1043,7 +1048,7 @@ random_write(struct file * file, const char __user * buffer,
1043 if (p == buffer) { 1048 if (p == buffer) {
1044 return (ssize_t)ret; 1049 return (ssize_t)ret;
1045 } else { 1050 } else {
1046 struct inode *inode = file->f_dentry->d_inode; 1051 struct inode *inode = file->f_path.dentry->d_inode;
1047 inode->i_mtime = current_fs_time(inode->i_sb); 1052 inode->i_mtime = current_fs_time(inode->i_sb);
1048 mark_inode_dirty(inode); 1053 mark_inode_dirty(inode);
1049 return (ssize_t)(p - buffer); 1054 return (ssize_t)(p - buffer);
@@ -1198,7 +1203,7 @@ static int proc_do_uuid(ctl_table *table, int write, struct file *filp,
1198 1203
1199static int uuid_strategy(ctl_table *table, int __user *name, int nlen, 1204static int uuid_strategy(ctl_table *table, int __user *name, int nlen,
1200 void __user *oldval, size_t __user *oldlenp, 1205 void __user *oldval, size_t __user *oldlenp,
1201 void __user *newval, size_t newlen, void **context) 1206 void __user *newval, size_t newlen)
1202{ 1207{
1203 unsigned char tmp_uuid[16], *uuid; 1208 unsigned char tmp_uuid[16], *uuid;
1204 unsigned int len; 1209 unsigned int len;
@@ -1417,9 +1422,9 @@ static struct keydata {
1417 1422
1418static unsigned int ip_cnt; 1423static unsigned int ip_cnt;
1419 1424
1420static void rekey_seq_generator(void *private_); 1425static void rekey_seq_generator(struct work_struct *work);
1421 1426
1422static DECLARE_WORK(rekey_work, rekey_seq_generator, NULL); 1427static DECLARE_DELAYED_WORK(rekey_work, rekey_seq_generator);
1423 1428
1424/* 1429/*
1425 * Lock avoidance: 1430 * Lock avoidance:
@@ -1433,7 +1438,7 @@ static DECLARE_WORK(rekey_work, rekey_seq_generator, NULL);
1433 * happen, and even if that happens only a not perfectly compliant 1438 * happen, and even if that happens only a not perfectly compliant
1434 * ISN is generated, nothing fatal. 1439 * ISN is generated, nothing fatal.
1435 */ 1440 */
1436static void rekey_seq_generator(void *private_) 1441static void rekey_seq_generator(struct work_struct *work)
1437{ 1442{
1438 struct keydata *keyptr = &ip_keydata[1 ^ (ip_cnt & 1)]; 1443 struct keydata *keyptr = &ip_keydata[1 ^ (ip_cnt & 1)];
1439 1444
@@ -1461,8 +1466,8 @@ static __init int seqgen_init(void)
1461late_initcall(seqgen_init); 1466late_initcall(seqgen_init);
1462 1467
1463#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 1468#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1464__u32 secure_tcpv6_sequence_number(__u32 *saddr, __u32 *daddr, 1469__u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
1465 __u16 sport, __u16 dport) 1470 __be16 sport, __be16 dport)
1466{ 1471{
1467 struct timeval tv; 1472 struct timeval tv;
1468 __u32 seq; 1473 __u32 seq;
@@ -1474,10 +1479,10 @@ __u32 secure_tcpv6_sequence_number(__u32 *saddr, __u32 *daddr,
1474 */ 1479 */
1475 1480
1476 memcpy(hash, saddr, 16); 1481 memcpy(hash, saddr, 16);
1477 hash[4]=(sport << 16) + dport; 1482 hash[4]=((__force u16)sport << 16) + (__force u16)dport;
1478 memcpy(&hash[5],keyptr->secret,sizeof(__u32) * 7); 1483 memcpy(&hash[5],keyptr->secret,sizeof(__u32) * 7);
1479 1484
1480 seq = twothirdsMD4Transform(daddr, hash) & HASH_MASK; 1485 seq = twothirdsMD4Transform((const __u32 *)daddr, hash) & HASH_MASK;
1481 seq += keyptr->count; 1486 seq += keyptr->count;
1482 1487
1483 do_gettimeofday(&tv); 1488 do_gettimeofday(&tv);
@@ -1491,7 +1496,7 @@ EXPORT_SYMBOL(secure_tcpv6_sequence_number);
1491/* The code below is shamelessly stolen from secure_tcp_sequence_number(). 1496/* The code below is shamelessly stolen from secure_tcp_sequence_number().
1492 * All blames to Andrey V. Savochkin <saw@msu.ru>. 1497 * All blames to Andrey V. Savochkin <saw@msu.ru>.
1493 */ 1498 */
1494__u32 secure_ip_id(__u32 daddr) 1499__u32 secure_ip_id(__be32 daddr)
1495{ 1500{
1496 struct keydata *keyptr; 1501 struct keydata *keyptr;
1497 __u32 hash[4]; 1502 __u32 hash[4];
@@ -1503,7 +1508,7 @@ __u32 secure_ip_id(__u32 daddr)
1503 * The dest ip address is placed in the starting vector, 1508 * The dest ip address is placed in the starting vector,
1504 * which is then hashed with random data. 1509 * which is then hashed with random data.
1505 */ 1510 */
1506 hash[0] = daddr; 1511 hash[0] = (__force __u32)daddr;
1507 hash[1] = keyptr->secret[9]; 1512 hash[1] = keyptr->secret[9];
1508 hash[2] = keyptr->secret[10]; 1513 hash[2] = keyptr->secret[10];
1509 hash[3] = keyptr->secret[11]; 1514 hash[3] = keyptr->secret[11];
@@ -1513,8 +1518,8 @@ __u32 secure_ip_id(__u32 daddr)
1513 1518
1514#ifdef CONFIG_INET 1519#ifdef CONFIG_INET
1515 1520
1516__u32 secure_tcp_sequence_number(__u32 saddr, __u32 daddr, 1521__u32 secure_tcp_sequence_number(__be32 saddr, __be32 daddr,
1517 __u16 sport, __u16 dport) 1522 __be16 sport, __be16 dport)
1518{ 1523{
1519 struct timeval tv; 1524 struct timeval tv;
1520 __u32 seq; 1525 __u32 seq;
@@ -1527,9 +1532,9 @@ __u32 secure_tcp_sequence_number(__u32 saddr, __u32 daddr,
1527 * Note that the words are placed into the starting vector, which is 1532 * Note that the words are placed into the starting vector, which is
1528 * then mixed with a partial MD4 over random data. 1533 * then mixed with a partial MD4 over random data.
1529 */ 1534 */
1530 hash[0]=saddr; 1535 hash[0]=(__force u32)saddr;
1531 hash[1]=daddr; 1536 hash[1]=(__force u32)daddr;
1532 hash[2]=(sport << 16) + dport; 1537 hash[2]=((__force u16)sport << 16) + (__force u16)dport;
1533 hash[3]=keyptr->secret[11]; 1538 hash[3]=keyptr->secret[11];
1534 1539
1535 seq = half_md4_transform(hash, keyptr->secret) & HASH_MASK; 1540 seq = half_md4_transform(hash, keyptr->secret) & HASH_MASK;
@@ -1554,7 +1559,7 @@ __u32 secure_tcp_sequence_number(__u32 saddr, __u32 daddr,
1554EXPORT_SYMBOL(secure_tcp_sequence_number); 1559EXPORT_SYMBOL(secure_tcp_sequence_number);
1555 1560
1556/* Generate secure starting point for ephemeral IPV4 transport port search */ 1561/* Generate secure starting point for ephemeral IPV4 transport port search */
1557u32 secure_ipv4_port_ephemeral(__u32 saddr, __u32 daddr, __u16 dport) 1562u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport)
1558{ 1563{
1559 struct keydata *keyptr = get_keyptr(); 1564 struct keydata *keyptr = get_keyptr();
1560 u32 hash[4]; 1565 u32 hash[4];
@@ -1563,25 +1568,25 @@ u32 secure_ipv4_port_ephemeral(__u32 saddr, __u32 daddr, __u16 dport)
1563 * Pick a unique starting offset for each ephemeral port search 1568 * Pick a unique starting offset for each ephemeral port search
1564 * (saddr, daddr, dport) and 48bits of random data. 1569 * (saddr, daddr, dport) and 48bits of random data.
1565 */ 1570 */
1566 hash[0] = saddr; 1571 hash[0] = (__force u32)saddr;
1567 hash[1] = daddr; 1572 hash[1] = (__force u32)daddr;
1568 hash[2] = dport ^ keyptr->secret[10]; 1573 hash[2] = (__force u32)dport ^ keyptr->secret[10];
1569 hash[3] = keyptr->secret[11]; 1574 hash[3] = keyptr->secret[11];
1570 1575
1571 return half_md4_transform(hash, keyptr->secret); 1576 return half_md4_transform(hash, keyptr->secret);
1572} 1577}
1573 1578
1574#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 1579#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1575u32 secure_ipv6_port_ephemeral(const __u32 *saddr, const __u32 *daddr, __u16 dport) 1580u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr, __be16 dport)
1576{ 1581{
1577 struct keydata *keyptr = get_keyptr(); 1582 struct keydata *keyptr = get_keyptr();
1578 u32 hash[12]; 1583 u32 hash[12];
1579 1584
1580 memcpy(hash, saddr, 16); 1585 memcpy(hash, saddr, 16);
1581 hash[4] = dport; 1586 hash[4] = (__force u32)dport;
1582 memcpy(&hash[5],keyptr->secret,sizeof(__u32) * 7); 1587 memcpy(&hash[5],keyptr->secret,sizeof(__u32) * 7);
1583 1588
1584 return twothirdsMD4Transform(daddr, hash); 1589 return twothirdsMD4Transform((const __u32 *)daddr, hash);
1585} 1590}
1586#endif 1591#endif
1587 1592
@@ -1590,17 +1595,17 @@ u32 secure_ipv6_port_ephemeral(const __u32 *saddr, const __u32 *daddr, __u16 dpo
1590 * bit's 32-47 increase every key exchange 1595 * bit's 32-47 increase every key exchange
1591 * 0-31 hash(source, dest) 1596 * 0-31 hash(source, dest)
1592 */ 1597 */
1593u64 secure_dccp_sequence_number(__u32 saddr, __u32 daddr, 1598u64 secure_dccp_sequence_number(__be32 saddr, __be32 daddr,
1594 __u16 sport, __u16 dport) 1599 __be16 sport, __be16 dport)
1595{ 1600{
1596 struct timeval tv; 1601 struct timeval tv;
1597 u64 seq; 1602 u64 seq;
1598 __u32 hash[4]; 1603 __u32 hash[4];
1599 struct keydata *keyptr = get_keyptr(); 1604 struct keydata *keyptr = get_keyptr();
1600 1605
1601 hash[0] = saddr; 1606 hash[0] = (__force u32)saddr;
1602 hash[1] = daddr; 1607 hash[1] = (__force u32)daddr;
1603 hash[2] = (sport << 16) + dport; 1608 hash[2] = ((__force u16)sport << 16) + (__force u16)dport;
1604 hash[3] = keyptr->secret[11]; 1609 hash[3] = keyptr->secret[11];
1605 1610
1606 seq = half_md4_transform(hash, keyptr->secret); 1611 seq = half_md4_transform(hash, keyptr->secret);
@@ -1636,7 +1641,7 @@ unsigned int get_random_int(void)
1636 * drain on it), and uses halfMD4Transform within the second. We 1641 * drain on it), and uses halfMD4Transform within the second. We
1637 * also mix it with jiffies and the PID: 1642 * also mix it with jiffies and the PID:
1638 */ 1643 */
1639 return secure_ip_id(current->pid + jiffies); 1644 return secure_ip_id((__force __be32)(current->pid + jiffies));
1640} 1645}
1641 1646
1642/* 1647/*
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 579868af4a54..645e20a06ece 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -75,7 +75,7 @@ static int raw_open(struct inode *inode, struct file *filp)
75 filp->f_flags |= O_DIRECT; 75 filp->f_flags |= O_DIRECT;
76 filp->f_mapping = bdev->bd_inode->i_mapping; 76 filp->f_mapping = bdev->bd_inode->i_mapping;
77 if (++raw_devices[minor].inuse == 1) 77 if (++raw_devices[minor].inuse == 1)
78 filp->f_dentry->d_inode->i_mapping = 78 filp->f_path.dentry->d_inode->i_mapping =
79 bdev->bd_inode->i_mapping; 79 bdev->bd_inode->i_mapping;
80 filp->private_data = bdev; 80 filp->private_data = bdev;
81 mutex_unlock(&raw_mutex); 81 mutex_unlock(&raw_mutex);
@@ -127,9 +127,9 @@ raw_ioctl(struct inode *inode, struct file *filp,
127 127
128static void bind_device(struct raw_config_request *rq) 128static void bind_device(struct raw_config_request *rq)
129{ 129{
130 class_device_destroy(raw_class, MKDEV(RAW_MAJOR, rq->raw_minor)); 130 device_destroy(raw_class, MKDEV(RAW_MAJOR, rq->raw_minor));
131 class_device_create(raw_class, NULL, MKDEV(RAW_MAJOR, rq->raw_minor), 131 device_create(raw_class, NULL, MKDEV(RAW_MAJOR, rq->raw_minor),
132 NULL, "raw%d", rq->raw_minor); 132 "raw%d", rq->raw_minor);
133} 133}
134 134
135/* 135/*
@@ -200,7 +200,7 @@ static int raw_ctl_ioctl(struct inode *inode, struct file *filp,
200 if (rq.block_major == 0 && rq.block_minor == 0) { 200 if (rq.block_major == 0 && rq.block_minor == 0) {
201 /* unbind */ 201 /* unbind */
202 rawdev->binding = NULL; 202 rawdev->binding = NULL;
203 class_device_destroy(raw_class, 203 device_destroy(raw_class,
204 MKDEV(RAW_MAJOR, rq.raw_minor)); 204 MKDEV(RAW_MAJOR, rq.raw_minor));
205 } else { 205 } else {
206 rawdev->binding = bdget(dev); 206 rawdev->binding = bdget(dev);
@@ -238,39 +238,14 @@ out:
238 return err; 238 return err;
239} 239}
240 240
241static ssize_t raw_file_write(struct file *file, const char __user *buf,
242 size_t count, loff_t *ppos)
243{
244 struct iovec local_iov = {
245 .iov_base = (char __user *)buf,
246 .iov_len = count
247 };
248
249 return generic_file_write_nolock(file, &local_iov, 1, ppos);
250}
251
252static ssize_t raw_file_aio_write(struct kiocb *iocb, const char __user *buf,
253 size_t count, loff_t pos)
254{
255 struct iovec local_iov = {
256 .iov_base = (char __user *)buf,
257 .iov_len = count
258 };
259
260 return generic_file_aio_write_nolock(iocb, &local_iov, 1, &iocb->ki_pos);
261}
262
263
264static const struct file_operations raw_fops = { 241static const struct file_operations raw_fops = {
265 .read = generic_file_read, 242 .read = do_sync_read,
266 .aio_read = generic_file_aio_read, 243 .aio_read = generic_file_aio_read,
267 .write = raw_file_write, 244 .write = do_sync_write,
268 .aio_write = raw_file_aio_write, 245 .aio_write = generic_file_aio_write_nolock,
269 .open = raw_open, 246 .open = raw_open,
270 .release= raw_release, 247 .release= raw_release,
271 .ioctl = raw_ioctl, 248 .ioctl = raw_ioctl,
272 .readv = generic_file_readv,
273 .writev = generic_file_writev,
274 .owner = THIS_MODULE, 249 .owner = THIS_MODULE,
275}; 250};
276 251
@@ -288,36 +263,39 @@ static struct cdev raw_cdev = {
288static int __init raw_init(void) 263static int __init raw_init(void)
289{ 264{
290 dev_t dev = MKDEV(RAW_MAJOR, 0); 265 dev_t dev = MKDEV(RAW_MAJOR, 0);
266 int ret;
291 267
292 if (register_chrdev_region(dev, MAX_RAW_MINORS, "raw")) 268 ret = register_chrdev_region(dev, MAX_RAW_MINORS, "raw");
269 if (ret)
293 goto error; 270 goto error;
294 271
295 cdev_init(&raw_cdev, &raw_fops); 272 cdev_init(&raw_cdev, &raw_fops);
296 if (cdev_add(&raw_cdev, dev, MAX_RAW_MINORS)) { 273 ret = cdev_add(&raw_cdev, dev, MAX_RAW_MINORS);
274 if (ret) {
297 kobject_put(&raw_cdev.kobj); 275 kobject_put(&raw_cdev.kobj);
298 unregister_chrdev_region(dev, MAX_RAW_MINORS); 276 goto error_region;
299 goto error;
300 } 277 }
301 278
302 raw_class = class_create(THIS_MODULE, "raw"); 279 raw_class = class_create(THIS_MODULE, "raw");
303 if (IS_ERR(raw_class)) { 280 if (IS_ERR(raw_class)) {
304 printk(KERN_ERR "Error creating raw class.\n"); 281 printk(KERN_ERR "Error creating raw class.\n");
305 cdev_del(&raw_cdev); 282 cdev_del(&raw_cdev);
306 unregister_chrdev_region(dev, MAX_RAW_MINORS); 283 ret = PTR_ERR(raw_class);
307 goto error; 284 goto error_region;
308 } 285 }
309 class_device_create(raw_class, NULL, MKDEV(RAW_MAJOR, 0), NULL, "rawctl"); 286 device_create(raw_class, NULL, MKDEV(RAW_MAJOR, 0), "rawctl");
310 287
311 return 0; 288 return 0;
312 289
290error_region:
291 unregister_chrdev_region(dev, MAX_RAW_MINORS);
313error: 292error:
314 printk(KERN_ERR "error register raw device\n"); 293 return ret;
315 return 1;
316} 294}
317 295
318static void __exit raw_exit(void) 296static void __exit raw_exit(void)
319{ 297{
320 class_device_destroy(raw_class, MKDEV(RAW_MAJOR, 0)); 298 device_destroy(raw_class, MKDEV(RAW_MAJOR, 0));
321 class_destroy(raw_class); 299 class_destroy(raw_class);
322 cdev_del(&raw_cdev); 300 cdev_del(&raw_cdev);
323 unregister_chrdev_region(MKDEV(RAW_MAJOR, 0), MAX_RAW_MINORS); 301 unregister_chrdev_region(MKDEV(RAW_MAJOR, 0), MAX_RAW_MINORS);
diff --git a/drivers/char/rio/func.h b/drivers/char/rio/func.h
index 6b039186856d..9e7283bd81a0 100644
--- a/drivers/char/rio/func.h
+++ b/drivers/char/rio/func.h
@@ -88,7 +88,7 @@ void RIOHostReset(unsigned int, struct DpRam __iomem *, unsigned int);
88 88
89/* riointr.c */ 89/* riointr.c */
90void RIOTxEnable(char *); 90void RIOTxEnable(char *);
91void RIOServiceHost(struct rio_info *, struct Host *, int); 91void RIOServiceHost(struct rio_info *, struct Host *);
92int riotproc(struct rio_info *, struct ttystatics *, int, int); 92int riotproc(struct rio_info *, struct ttystatics *, int, int);
93 93
94/* rioparam.c */ 94/* rioparam.c */
diff --git a/drivers/char/rio/host.h b/drivers/char/rio/host.h
index ee2ddea7a63a..23d0681fe491 100644
--- a/drivers/char/rio/host.h
+++ b/drivers/char/rio/host.h
@@ -44,6 +44,7 @@
44** the host. 44** the host.
45*/ 45*/
46struct Host { 46struct Host {
47 struct pci_dev *pdev;
47 unsigned char Type; /* RIO_EISA, RIO_MCA, ... */ 48 unsigned char Type; /* RIO_EISA, RIO_MCA, ... */
48 unsigned char Ivec; /* POLLED or ivec number */ 49 unsigned char Ivec; /* POLLED or ivec number */
49 unsigned char Mode; /* Control stuff */ 50 unsigned char Mode; /* Control stuff */
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c
index 3fa80aaf4527..e79b2ede8510 100644
--- a/drivers/char/rio/rio_linux.c
+++ b/drivers/char/rio/rio_linux.c
@@ -363,12 +363,12 @@ static void rio_reset_interrupt(struct Host *HostP)
363} 363}
364 364
365 365
366static irqreturn_t rio_interrupt(int irq, void *ptr, struct pt_regs *regs) 366static irqreturn_t rio_interrupt(int irq, void *ptr)
367{ 367{
368 struct Host *HostP; 368 struct Host *HostP;
369 func_enter(); 369 func_enter();
370 370
371 HostP = (struct Host *) ptr; /* &p->RIOHosts[(long)ptr]; */ 371 HostP = ptr; /* &p->RIOHosts[(long)ptr]; */
372 rio_dprintk(RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", irq, HostP->Ivec); 372 rio_dprintk(RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
373 373
374 /* AAargh! The order in which to do these things is essential and 374 /* AAargh! The order in which to do these things is essential and
@@ -402,7 +402,7 @@ static irqreturn_t rio_interrupt(int irq, void *ptr, struct pt_regs *regs)
402 return IRQ_HANDLED; 402 return IRQ_HANDLED;
403 } 403 }
404 404
405 RIOServiceHost(p, HostP, irq); 405 RIOServiceHost(p, HostP);
406 406
407 rio_dprintk(RIO_DEBUG_IFLOW, "riointr() doing host %p type %d\n", ptr, HostP->Type); 407 rio_dprintk(RIO_DEBUG_IFLOW, "riointr() doing host %p type %d\n", ptr, HostP->Type);
408 408
@@ -417,7 +417,7 @@ static void rio_pollfunc(unsigned long data)
417{ 417{
418 func_enter(); 418 func_enter();
419 419
420 rio_interrupt(0, &p->RIOHosts[data], NULL); 420 rio_interrupt(0, &p->RIOHosts[data]);
421 p->RIOHosts[data].timer.expires = jiffies + rio_poll; 421 p->RIOHosts[data].timer.expires = jiffies + rio_poll;
422 add_timer(&p->RIOHosts[data].timer); 422 add_timer(&p->RIOHosts[data].timer);
423 423
@@ -727,7 +727,7 @@ static struct vpd_prom *get_VPD_PROM(struct Host *hp)
727 return &vpdp; 727 return &vpdp;
728} 728}
729 729
730static struct tty_operations rio_ops = { 730static const struct tty_operations rio_ops = {
731 .open = riotopen, 731 .open = riotopen,
732 .close = gs_close, 732 .close = gs_close,
733 .write = gs_write, 733 .write = gs_write,
@@ -1017,11 +1017,16 @@ static int __init rio_init(void)
1017 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum); 1017 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1018 1018
1019 fix_rio_pci(pdev); 1019 fix_rio_pci(pdev);
1020
1021 p->RIOHosts[p->RIONumHosts].pdev = pdev;
1022 pci_dev_get(pdev);
1023
1020 p->RIOLastPCISearch = 0; 1024 p->RIOLastPCISearch = 0;
1021 p->RIONumHosts++; 1025 p->RIONumHosts++;
1022 found++; 1026 found++;
1023 } else { 1027 } else {
1024 iounmap(p->RIOHosts[p->RIONumHosts].Caddr); 1028 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
1029 p->RIOHosts[p->RIONumHosts].Caddr = NULL;
1025 } 1030 }
1026 } 1031 }
1027 1032
@@ -1066,11 +1071,15 @@ static int __init rio_init(void)
1066 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24); 1071 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24);
1067 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum); 1072 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1068 1073
1074 p->RIOHosts[p->RIONumHosts].pdev = pdev;
1075 pci_dev_get(pdev);
1076
1069 p->RIOLastPCISearch = 0; 1077 p->RIOLastPCISearch = 0;
1070 p->RIONumHosts++; 1078 p->RIONumHosts++;
1071 found++; 1079 found++;
1072 } else { 1080 } else {
1073 iounmap(p->RIOHosts[p->RIONumHosts].Caddr); 1081 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
1082 p->RIOHosts[p->RIONumHosts].Caddr = NULL;
1074 } 1083 }
1075#else 1084#else
1076 printk(KERN_ERR "Found an older RIO PCI card, but the driver is not " "compiled to support it.\n"); 1085 printk(KERN_ERR "Found an older RIO PCI card, but the driver is not " "compiled to support it.\n");
@@ -1110,8 +1119,10 @@ static int __init rio_init(void)
1110 } 1119 }
1111 } 1120 }
1112 1121
1113 if (!okboard) 1122 if (!okboard) {
1114 iounmap(hp->Caddr); 1123 iounmap(hp->Caddr);
1124 hp->Caddr = NULL;
1125 }
1115 } 1126 }
1116 } 1127 }
1117 1128
@@ -1181,6 +1192,10 @@ static void __exit rio_exit(void)
1181 } 1192 }
1182 /* It is safe/allowed to del_timer a non-active timer */ 1193 /* It is safe/allowed to del_timer a non-active timer */
1183 del_timer(&hp->timer); 1194 del_timer(&hp->timer);
1195 if (hp->Caddr)
1196 iounmap(hp->Caddr);
1197 if (hp->Type == RIO_PCI)
1198 pci_dev_put(hp->pdev);
1184 } 1199 }
1185 1200
1186 if (misc_deregister(&rio_fw_device) < 0) { 1201 if (misc_deregister(&rio_fw_device) < 0) {
diff --git a/drivers/char/rio/riocmd.c b/drivers/char/rio/riocmd.c
index 4df6ab2206a1..167ebc84e8d7 100644
--- a/drivers/char/rio/riocmd.c
+++ b/drivers/char/rio/riocmd.c
@@ -922,7 +922,7 @@ int RIOUnUse(unsigned long iPortP, struct CmdBlk *CmdBlkP)
922** 922**
923** Packet is an actual packet structure to be filled in with the packet 923** Packet is an actual packet structure to be filled in with the packet
924** information associated with the command. You need to fill in everything, 924** information associated with the command. You need to fill in everything,
925** as the command processore doesn't process the command packet in any way. 925** as the command processor doesn't process the command packet in any way.
926** 926**
927** The PreFuncP is called before the packet is enqueued on the host rup. 927** The PreFuncP is called before the packet is enqueued on the host rup.
928** PreFuncP is called as (*PreFuncP)(PreArg, CmdBlkP);. PreFuncP must 928** PreFuncP is called as (*PreFuncP)(PreArg, CmdBlkP);. PreFuncP must
diff --git a/drivers/char/rio/rioctrl.c b/drivers/char/rio/rioctrl.c
index 052e8120a471..7ce77619707c 100644
--- a/drivers/char/rio/rioctrl.c
+++ b/drivers/char/rio/rioctrl.c
@@ -662,7 +662,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
662 p->RIOError.Error = COPYIN_FAILED; 662 p->RIOError.Error = COPYIN_FAILED;
663 return -EFAULT; 663 return -EFAULT;
664 } 664 }
665 if (portStats.port >= RIO_PORTS) { 665 if (portStats.port < 0 || portStats.port >= RIO_PORTS) {
666 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; 666 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
667 return -ENXIO; 667 return -ENXIO;
668 } 668 }
@@ -702,7 +702,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
702 p->RIOError.Error = COPYIN_FAILED; 702 p->RIOError.Error = COPYIN_FAILED;
703 return -EFAULT; 703 return -EFAULT;
704 } 704 }
705 if (portStats.port >= RIO_PORTS) { 705 if (portStats.port < 0 || portStats.port >= RIO_PORTS) {
706 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; 706 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
707 return -ENXIO; 707 return -ENXIO;
708 } 708 }
diff --git a/drivers/char/rio/rioinit.c b/drivers/char/rio/rioinit.c
index 99f3df02b61c..0794844369d6 100644
--- a/drivers/char/rio/rioinit.c
+++ b/drivers/char/rio/rioinit.c
@@ -222,7 +222,7 @@ int RIOBoardTest(unsigned long paddr, void __iomem *caddr, unsigned char type, i
222** which value will be written into memory. 222** which value will be written into memory.
223** Call with op set to zero means that the RAM will not be read and checked 223** Call with op set to zero means that the RAM will not be read and checked
224** before it is written. 224** before it is written.
225** Call with op not zero, and the RAM will be read and compated with val[op-1] 225** Call with op not zero and the RAM will be read and compared with val[op-1]
226** to check that the data from the previous phase was retained. 226** to check that the data from the previous phase was retained.
227*/ 227*/
228 228
diff --git a/drivers/char/rio/riointr.c b/drivers/char/rio/riointr.c
index 0bd09040a5c0..eeda40c5e189 100644
--- a/drivers/char/rio/riointr.c
+++ b/drivers/char/rio/riointr.c
@@ -181,7 +181,7 @@ static int RupIntr;
181static int RxIntr; 181static int RxIntr;
182static int TxIntr; 182static int TxIntr;
183 183
184void RIOServiceHost(struct rio_info *p, struct Host *HostP, int From) 184void RIOServiceHost(struct rio_info *p, struct Host *HostP)
185{ 185{
186 rio_spin_lock(&HostP->HostLock); 186 rio_spin_lock(&HostP->HostLock);
187 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) { 187 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
diff --git a/drivers/char/rio/rioparam.c b/drivers/char/rio/rioparam.c
index 1066d9760704..bb498d24adcc 100644
--- a/drivers/char/rio/rioparam.c
+++ b/drivers/char/rio/rioparam.c
@@ -87,8 +87,8 @@ static char *_rioparam_c_sccs_ = "@(#)rioparam.c 1.3";
87** command bit set onto the port. The command bit is in the len field, 87** command bit set onto the port. The command bit is in the len field,
88** and gets ORed in with the actual byte count. 88** and gets ORed in with the actual byte count.
89** 89**
90** When you send a packet with the command bit set, then the first 90** When you send a packet with the command bit set the first
91** data byte ( data[0] ) is interpretted as the command to execute. 91** data byte (data[0]) is interpreted as the command to execute.
92** It also governs what data structure overlay should accompany the packet. 92** It also governs what data structure overlay should accompany the packet.
93** Commands are defined in cirrus/cirrus.h 93** Commands are defined in cirrus/cirrus.h
94** 94**
@@ -103,7 +103,7 @@ static char *_rioparam_c_sccs_ = "@(#)rioparam.c 1.3";
103** 103**
104** Most commands do not use the remaining bytes in the data array. The 104** Most commands do not use the remaining bytes in the data array. The
105** exceptions are OPEN MOPEN and CONFIG. (NB. As with the SI CONFIG and 105** exceptions are OPEN MOPEN and CONFIG. (NB. As with the SI CONFIG and
106** OPEN are currently analagous). With these three commands the following 106** OPEN are currently analogous). With these three commands the following
107** 11 data bytes are all used to pass config information such as baud rate etc. 107** 11 data bytes are all used to pass config information such as baud rate etc.
108** The fields are also defined in cirrus.h. Some contain straightforward 108** The fields are also defined in cirrus.h. Some contain straightforward
109** information such as the transmit XON character. Two contain the transmit and 109** information such as the transmit XON character. Two contain the transmit and
diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c
index f1c94f771af5..e2a94bfb2a43 100644
--- a/drivers/char/riscom8.c
+++ b/drivers/char/riscom8.c
@@ -81,12 +81,6 @@
81 81
82static struct riscom_board * IRQ_to_board[16]; 82static struct riscom_board * IRQ_to_board[16];
83static struct tty_driver *riscom_driver; 83static struct tty_driver *riscom_driver;
84static unsigned char * tmp_buf;
85
86static unsigned long baud_table[] = {
87 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
88 9600, 19200, 38400, 57600, 76800, 0,
89};
90 84
91static struct riscom_board rc_board[RC_NBOARD] = { 85static struct riscom_board rc_board[RC_NBOARD] = {
92 { 86 {
@@ -551,7 +545,7 @@ static inline void rc_check_modem(struct riscom_board const * bp)
551} 545}
552 546
553/* The main interrupt processing routine */ 547/* The main interrupt processing routine */
554static irqreturn_t rc_interrupt(int irq, void * dev_id, struct pt_regs * regs) 548static irqreturn_t rc_interrupt(int irq, void * dev_id)
555{ 549{
556 unsigned char status; 550 unsigned char status;
557 unsigned char ack; 551 unsigned char ack;
@@ -560,11 +554,10 @@ static irqreturn_t rc_interrupt(int irq, void * dev_id, struct pt_regs * regs)
560 int handled = 0; 554 int handled = 0;
561 555
562 bp = IRQ_to_board[irq]; 556 bp = IRQ_to_board[irq];
563 557
564 if (!bp || !(bp->flags & RC_BOARD_ACTIVE)) { 558 if (!(bp->flags & RC_BOARD_ACTIVE))
565 return IRQ_NONE; 559 return IRQ_NONE;
566 } 560
567
568 while ((++loop < 16) && ((status = ~(rc_in(bp, RC_BSR))) & 561 while ((++loop < 16) && ((status = ~(rc_in(bp, RC_BSR))) &
569 (RC_BSR_TOUT | RC_BSR_TINT | 562 (RC_BSR_TOUT | RC_BSR_TINT |
570 RC_BSR_MINT | RC_BSR_RINT))) { 563 RC_BSR_MINT | RC_BSR_RINT))) {
@@ -675,26 +668,12 @@ static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
675 port->COR2 = 0; 668 port->COR2 = 0;
676 port->MSVR = MSVR_RTS; 669 port->MSVR = MSVR_RTS;
677 670
678 baud = C_BAUD(tty); 671 baud = tty_get_baud_rate(tty);
679
680 if (baud & CBAUDEX) {
681 baud &= ~CBAUDEX;
682 if (baud < 1 || baud > 2)
683 port->tty->termios->c_cflag &= ~CBAUDEX;
684 else
685 baud += 15;
686 }
687 if (baud == 15) {
688 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
689 baud ++;
690 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
691 baud += 2;
692 }
693 672
694 /* Select port on the board */ 673 /* Select port on the board */
695 rc_out(bp, CD180_CAR, port_No(port)); 674 rc_out(bp, CD180_CAR, port_No(port));
696 675
697 if (!baud_table[baud]) { 676 if (!baud) {
698 /* Drop DTR & exit */ 677 /* Drop DTR & exit */
699 bp->DTR |= (1u << port_No(port)); 678 bp->DTR |= (1u << port_No(port));
700 rc_out(bp, RC_DTR, bp->DTR); 679 rc_out(bp, RC_DTR, bp->DTR);
@@ -710,7 +689,7 @@ static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
710 */ 689 */
711 690
712 /* Set baud rate for port */ 691 /* Set baud rate for port */
713 tmp = (((RC_OSCFREQ + baud_table[baud]/2) / baud_table[baud] + 692 tmp = (((RC_OSCFREQ + baud/2) / baud +
714 CD180_TPC/2) / CD180_TPC); 693 CD180_TPC/2) / CD180_TPC);
715 694
716 rc_out(bp, CD180_RBPRH, (tmp >> 8) & 0xff); 695 rc_out(bp, CD180_RBPRH, (tmp >> 8) & 0xff);
@@ -718,7 +697,7 @@ static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
718 rc_out(bp, CD180_RBPRL, tmp & 0xff); 697 rc_out(bp, CD180_RBPRL, tmp & 0xff);
719 rc_out(bp, CD180_TBPRL, tmp & 0xff); 698 rc_out(bp, CD180_TBPRL, tmp & 0xff);
720 699
721 baud = (baud_table[baud] + 5) / 10; /* Estimated CPS */ 700 baud = (baud + 5) / 10; /* Estimated CPS */
722 701
723 /* Two timer ticks seems enough to wakeup something like SLIP driver */ 702 /* Two timer ticks seems enough to wakeup something like SLIP driver */
724 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO; 703 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;
@@ -1138,7 +1117,7 @@ static int rc_write(struct tty_struct * tty,
1138 1117
1139 bp = port_Board(port); 1118 bp = port_Board(port);
1140 1119
1141 if (!tty || !port->xmit_buf || !tmp_buf) 1120 if (!tty || !port->xmit_buf)
1142 return 0; 1121 return 0;
1143 1122
1144 save_flags(flags); 1123 save_flags(flags);
@@ -1532,9 +1511,9 @@ static void rc_start(struct tty_struct * tty)
1532 * do_rc_hangup() -> tty->hangup() -> rc_hangup() 1511 * do_rc_hangup() -> tty->hangup() -> rc_hangup()
1533 * 1512 *
1534 */ 1513 */
1535static void do_rc_hangup(void *private_) 1514static void do_rc_hangup(struct work_struct *ugly_api)
1536{ 1515{
1537 struct riscom_port *port = (struct riscom_port *) private_; 1516 struct riscom_port *port = container_of(ugly_api, struct riscom_port, tqueue_hangup);
1538 struct tty_struct *tty; 1517 struct tty_struct *tty;
1539 1518
1540 tty = port->tty; 1519 tty = port->tty;
@@ -1560,7 +1539,7 @@ static void rc_hangup(struct tty_struct * tty)
1560 wake_up_interruptible(&port->open_wait); 1539 wake_up_interruptible(&port->open_wait);
1561} 1540}
1562 1541
1563static void rc_set_termios(struct tty_struct * tty, struct termios * old_termios) 1542static void rc_set_termios(struct tty_struct * tty, struct ktermios * old_termios)
1564{ 1543{
1565 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1544 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1566 unsigned long flags; 1545 unsigned long flags;
@@ -1583,9 +1562,9 @@ static void rc_set_termios(struct tty_struct * tty, struct termios * old_termios
1583 } 1562 }
1584} 1563}
1585 1564
1586static void do_softint(void *private_) 1565static void do_softint(struct work_struct *ugly_api)
1587{ 1566{
1588 struct riscom_port *port = (struct riscom_port *) private_; 1567 struct riscom_port *port = container_of(ugly_api, struct riscom_port, tqueue);
1589 struct tty_struct *tty; 1568 struct tty_struct *tty;
1590 1569
1591 if(!(tty = port->tty)) 1570 if(!(tty = port->tty))
@@ -1597,7 +1576,7 @@ static void do_softint(void *private_)
1597 } 1576 }
1598} 1577}
1599 1578
1600static struct tty_operations riscom_ops = { 1579static const struct tty_operations riscom_ops = {
1601 .open = rc_open, 1580 .open = rc_open,
1602 .close = rc_close, 1581 .close = rc_close,
1603 .write = rc_write, 1582 .write = rc_write,
@@ -1626,11 +1605,6 @@ static inline int rc_init_drivers(void)
1626 if (!riscom_driver) 1605 if (!riscom_driver)
1627 return -ENOMEM; 1606 return -ENOMEM;
1628 1607
1629 if (!(tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL))) {
1630 printk(KERN_ERR "rc: Couldn't get free page.\n");
1631 put_tty_driver(riscom_driver);
1632 return 1;
1633 }
1634 memset(IRQ_to_board, 0, sizeof(IRQ_to_board)); 1608 memset(IRQ_to_board, 0, sizeof(IRQ_to_board));
1635 riscom_driver->owner = THIS_MODULE; 1609 riscom_driver->owner = THIS_MODULE;
1636 riscom_driver->name = "ttyL"; 1610 riscom_driver->name = "ttyL";
@@ -1640,10 +1614,11 @@ static inline int rc_init_drivers(void)
1640 riscom_driver->init_termios = tty_std_termios; 1614 riscom_driver->init_termios = tty_std_termios;
1641 riscom_driver->init_termios.c_cflag = 1615 riscom_driver->init_termios.c_cflag =
1642 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 1616 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1617 riscom_driver->init_termios.c_ispeed = 9600;
1618 riscom_driver->init_termios.c_ospeed = 9600;
1643 riscom_driver->flags = TTY_DRIVER_REAL_RAW; 1619 riscom_driver->flags = TTY_DRIVER_REAL_RAW;
1644 tty_set_operations(riscom_driver, &riscom_ops); 1620 tty_set_operations(riscom_driver, &riscom_ops);
1645 if ((error = tty_register_driver(riscom_driver))) { 1621 if ((error = tty_register_driver(riscom_driver))) {
1646 free_page((unsigned long)tmp_buf);
1647 put_tty_driver(riscom_driver); 1622 put_tty_driver(riscom_driver);
1648 printk(KERN_ERR "rc: Couldn't register RISCom/8 driver, " 1623 printk(KERN_ERR "rc: Couldn't register RISCom/8 driver, "
1649 "error = %d\n", 1624 "error = %d\n",
@@ -1654,8 +1629,8 @@ static inline int rc_init_drivers(void)
1654 memset(rc_port, 0, sizeof(rc_port)); 1629 memset(rc_port, 0, sizeof(rc_port));
1655 for (i = 0; i < RC_NPORT * RC_NBOARD; i++) { 1630 for (i = 0; i < RC_NPORT * RC_NBOARD; i++) {
1656 rc_port[i].magic = RISCOM8_MAGIC; 1631 rc_port[i].magic = RISCOM8_MAGIC;
1657 INIT_WORK(&rc_port[i].tqueue, do_softint, &rc_port[i]); 1632 INIT_WORK(&rc_port[i].tqueue, do_softint);
1658 INIT_WORK(&rc_port[i].tqueue_hangup, do_rc_hangup, &rc_port[i]); 1633 INIT_WORK(&rc_port[i].tqueue_hangup, do_rc_hangup);
1659 rc_port[i].close_delay = 50 * HZ/100; 1634 rc_port[i].close_delay = 50 * HZ/100;
1660 rc_port[i].closing_wait = 3000 * HZ/100; 1635 rc_port[i].closing_wait = 3000 * HZ/100;
1661 init_waitqueue_head(&rc_port[i].open_wait); 1636 init_waitqueue_head(&rc_port[i].open_wait);
@@ -1671,7 +1646,6 @@ static void rc_release_drivers(void)
1671 1646
1672 save_flags(flags); 1647 save_flags(flags);
1673 cli(); 1648 cli();
1674 free_page((unsigned long)tmp_buf);
1675 tty_unregister_driver(riscom_driver); 1649 tty_unregister_driver(riscom_driver);
1676 put_tty_driver(riscom_driver); 1650 put_tty_driver(riscom_driver);
1677 restore_flags(flags); 1651 restore_flags(flags);
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index 0ac131881322..e94a62e30fc4 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -712,7 +712,7 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
712 * user mode into the driver (exception handler). *info CD manipulation is spinlock protected. 712 * user mode into the driver (exception handler). *info CD manipulation is spinlock protected.
713 */ 713 */
714static void configure_r_port(struct r_port *info, 714static void configure_r_port(struct r_port *info,
715 struct termios *old_termios) 715 struct ktermios *old_termios)
716{ 716{
717 unsigned cflag; 717 unsigned cflag;
718 unsigned long flags; 718 unsigned long flags;
@@ -1017,7 +1017,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
1017 /* 1017 /*
1018 * Info->count is now 1; so it's safe to sleep now. 1018 * Info->count is now 1; so it's safe to sleep now.
1019 */ 1019 */
1020 info->session = current->signal->session; 1020 info->session = process_session(current);
1021 info->pgrp = process_group(current); 1021 info->pgrp = process_group(current);
1022 1022
1023 if ((info->flags & ROCKET_INITIALIZED) == 0) { 1023 if ((info->flags & ROCKET_INITIALIZED) == 0) {
@@ -1194,7 +1194,7 @@ static void rp_close(struct tty_struct *tty, struct file *filp)
1194} 1194}
1195 1195
1196static void rp_set_termios(struct tty_struct *tty, 1196static void rp_set_termios(struct tty_struct *tty,
1197 struct termios *old_termios) 1197 struct ktermios *old_termios)
1198{ 1198{
1199 struct r_port *info = (struct r_port *) tty->driver_data; 1199 struct r_port *info = (struct r_port *) tty->driver_data;
1200 CHANNEL_t *cp; 1200 CHANNEL_t *cp;
@@ -2214,7 +2214,7 @@ static int __init init_PCI(int boards_found)
2214 int count = 0; 2214 int count = 0;
2215 2215
2216 /* Work through the PCI device list, pulling out ours */ 2216 /* Work through the PCI device list, pulling out ours */
2217 while ((dev = pci_find_device(PCI_VENDOR_ID_RP, PCI_ANY_ID, dev))) { 2217 while ((dev = pci_get_device(PCI_VENDOR_ID_RP, PCI_ANY_ID, dev))) {
2218 if (register_PCI(count + boards_found, dev)) 2218 if (register_PCI(count + boards_found, dev))
2219 count++; 2219 count++;
2220 } 2220 }
@@ -2334,7 +2334,7 @@ static int __init init_ISA(int i)
2334 return (1); 2334 return (1);
2335} 2335}
2336 2336
2337static struct tty_operations rocket_ops = { 2337static const struct tty_operations rocket_ops = {
2338 .open = rp_open, 2338 .open = rp_open,
2339 .close = rp_close, 2339 .close = rp_close,
2340 .write = rp_write, 2340 .write = rp_write,
@@ -2436,6 +2436,8 @@ static int __init rp_init(void)
2436 rocket_driver->init_termios = tty_std_termios; 2436 rocket_driver->init_termios = tty_std_termios;
2437 rocket_driver->init_termios.c_cflag = 2437 rocket_driver->init_termios.c_cflag =
2438 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 2438 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2439 rocket_driver->init_termios.c_ispeed = 9600;
2440 rocket_driver->init_termios.c_ospeed = 9600;
2439#ifdef ROCKET_SOFT_FLOW 2441#ifdef ROCKET_SOFT_FLOW
2440 rocket_driver->flags |= TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 2442 rocket_driver->flags |= TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
2441#endif 2443#endif
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index ab6429b4a84e..66a7385bc34a 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -35,13 +35,13 @@
35 * 1.09a Pete Zaitcev: Sun SPARC 35 * 1.09a Pete Zaitcev: Sun SPARC
36 * 1.09b Jeff Garzik: Modularize, init cleanup 36 * 1.09b Jeff Garzik: Modularize, init cleanup
37 * 1.09c Jeff Garzik: SMP cleanup 37 * 1.09c Jeff Garzik: SMP cleanup
38 * 1.10 Paul Barton-Davis: add support for async I/O 38 * 1.10 Paul Barton-Davis: add support for async I/O
39 * 1.10a Andrea Arcangeli: Alpha updates 39 * 1.10a Andrea Arcangeli: Alpha updates
40 * 1.10b Andrew Morton: SMP lock fix 40 * 1.10b Andrew Morton: SMP lock fix
41 * 1.10c Cesar Barros: SMP locking fixes and cleanup 41 * 1.10c Cesar Barros: SMP locking fixes and cleanup
42 * 1.10d Paul Gortmaker: delete paranoia check in rtc_exit 42 * 1.10d Paul Gortmaker: delete paranoia check in rtc_exit
43 * 1.10e Maciej W. Rozycki: Handle DECstation's year weirdness. 43 * 1.10e Maciej W. Rozycki: Handle DECstation's year weirdness.
44 * 1.11 Takashi Iwai: Kernel access functions 44 * 1.11 Takashi Iwai: Kernel access functions
45 * rtc_register/rtc_unregister/rtc_control 45 * rtc_register/rtc_unregister/rtc_control
46 * 1.11a Daniele Bellucci: Audit create_proc_read_entry in rtc_init 46 * 1.11a Daniele Bellucci: Audit create_proc_read_entry in rtc_init
47 * 1.12 Venkatesh Pallipadi: Hooks for emulating rtc on HPET base-timer 47 * 1.12 Venkatesh Pallipadi: Hooks for emulating rtc on HPET base-timer
@@ -113,9 +113,9 @@ static int rtc_has_irq = 1;
113#define hpet_set_rtc_irq_bit(arg) 0 113#define hpet_set_rtc_irq_bit(arg) 0
114#define hpet_rtc_timer_init() do { } while (0) 114#define hpet_rtc_timer_init() do { } while (0)
115#define hpet_rtc_dropped_irq() 0 115#define hpet_rtc_dropped_irq() 0
116static inline irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id, struct pt_regs *regs) {return 0;} 116static inline irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id) {return 0;}
117#else 117#else
118extern irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id, struct pt_regs *regs); 118extern irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id);
119#endif 119#endif
120 120
121/* 121/*
@@ -229,7 +229,7 @@ static inline unsigned char rtc_is_updating(void)
229 * (See ./arch/XXXX/kernel/time.c for the set_rtc_mmss() function.) 229 * (See ./arch/XXXX/kernel/time.c for the set_rtc_mmss() function.)
230 */ 230 */
231 231
232irqreturn_t rtc_interrupt(int irq, void *dev_id, struct pt_regs *regs) 232irqreturn_t rtc_interrupt(int irq, void *dev_id)
233{ 233{
234 /* 234 /*
235 * Can be an alarm interrupt, update complete interrupt, 235 * Can be an alarm interrupt, update complete interrupt,
@@ -915,7 +915,7 @@ static const struct file_operations rtc_proc_fops = {
915}; 915};
916 916
917#if defined(RTC_IRQ) && !defined(__sparc__) 917#if defined(RTC_IRQ) && !defined(__sparc__)
918static irqreturn_t (*rtc_int_handler_ptr)(int irq, void *dev_id, struct pt_regs *regs); 918static irq_handler_t rtc_int_handler_ptr;
919#endif 919#endif
920 920
921static int __init rtc_init(void) 921static int __init rtc_init(void)
@@ -1262,10 +1262,8 @@ void rtc_get_rtc_time(struct rtc_time *rtc_tm)
1262 * Once the read clears, read the RTC time (again via ioctl). Easy. 1262 * Once the read clears, read the RTC time (again via ioctl). Easy.
1263 */ 1263 */
1264 1264
1265 while (rtc_is_updating() != 0 && jiffies - uip_watchdog < 2*HZ/100) { 1265 while (rtc_is_updating() != 0 && jiffies - uip_watchdog < 2*HZ/100)
1266 barrier();
1267 cpu_relax(); 1266 cpu_relax();
1268 }
1269 1267
1270 /* 1268 /*
1271 * Only the values that we read from the RTC are set. We leave 1269 * Only the values that we read from the RTC are set. We leave
diff --git a/drivers/char/s3c2410-rtc.c b/drivers/char/s3c2410-rtc.c
deleted file mode 100644
index 5458ef1634e5..000000000000
--- a/drivers/char/s3c2410-rtc.c
+++ /dev/null
@@ -1,591 +0,0 @@
1/* drivers/char/s3c2410_rtc.c
2 *
3 * Copyright (c) 2004 Simtec Electronics <linux@simtec.co.uk>
4 * http://www.simtec.co.uk/products/SWLINUX/
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * S3C2410 Internal RTC Driver
11 *
12 * Changelog:
13 * 08-Nov-2004 BJD Initial creation
14 * 12-Nov-2004 BJD Added periodic IRQ and PM code
15 * 22-Nov-2004 BJD Sign-test on alarm code to check for <0
16 * 10-Mar-2005 LCVR Changed S3C2410_VA_RTC to S3C24XX_VA_RTC
17*/
18
19#include <linux/module.h>
20#include <linux/fs.h>
21#include <linux/string.h>
22#include <linux/init.h>
23#include <linux/platform_device.h>
24#include <linux/interrupt.h>
25#include <linux/rtc.h>
26#include <linux/bcd.h>
27#include <linux/clk.h>
28
29#include <asm/hardware.h>
30#include <asm/uaccess.h>
31#include <asm/io.h>
32#include <asm/irq.h>
33#include <asm/rtc.h>
34
35#include <asm/mach/time.h>
36
37#include <asm/arch/regs-rtc.h>
38
39/* need this for the RTC_AF definitions */
40#include <linux/mc146818rtc.h>
41
42#undef S3C24XX_VA_RTC
43#define S3C24XX_VA_RTC s3c2410_rtc_base
44
45static struct resource *s3c2410_rtc_mem;
46
47static void __iomem *s3c2410_rtc_base;
48static int s3c2410_rtc_alarmno = NO_IRQ;
49static int s3c2410_rtc_tickno = NO_IRQ;
50static int s3c2410_rtc_freq = 1;
51
52static DEFINE_SPINLOCK(s3c2410_rtc_pie_lock);
53
54/* IRQ Handlers */
55
56static irqreturn_t s3c2410_rtc_alarmirq(int irq, void *id, struct pt_regs *r)
57{
58 rtc_update(1, RTC_AF | RTC_IRQF);
59 return IRQ_HANDLED;
60}
61
62static irqreturn_t s3c2410_rtc_tickirq(int irq, void *id, struct pt_regs *r)
63{
64 rtc_update(1, RTC_PF | RTC_IRQF);
65 return IRQ_HANDLED;
66}
67
68/* Update control registers */
69static void s3c2410_rtc_setaie(int to)
70{
71 unsigned int tmp;
72
73 pr_debug("%s: aie=%d\n", __FUNCTION__, to);
74
75 tmp = readb(S3C2410_RTCALM);
76
77 if (to)
78 tmp |= S3C2410_RTCALM_ALMEN;
79 else
80 tmp &= ~S3C2410_RTCALM_ALMEN;
81
82
83 writeb(tmp, S3C2410_RTCALM);
84}
85
86static void s3c2410_rtc_setpie(int to)
87{
88 unsigned int tmp;
89
90 pr_debug("%s: pie=%d\n", __FUNCTION__, to);
91
92 spin_lock_irq(&s3c2410_rtc_pie_lock);
93 tmp = readb(S3C2410_TICNT) & ~S3C2410_TICNT_ENABLE;
94
95 if (to)
96 tmp |= S3C2410_TICNT_ENABLE;
97
98 writeb(tmp, S3C2410_TICNT);
99 spin_unlock_irq(&s3c2410_rtc_pie_lock);
100}
101
102static void s3c2410_rtc_setfreq(int freq)
103{
104 unsigned int tmp;
105
106 spin_lock_irq(&s3c2410_rtc_pie_lock);
107 tmp = readb(S3C2410_TICNT) & S3C2410_TICNT_ENABLE;
108
109 s3c2410_rtc_freq = freq;
110
111 tmp |= (128 / freq)-1;
112
113 writeb(tmp, S3C2410_TICNT);
114 spin_unlock_irq(&s3c2410_rtc_pie_lock);
115}
116
117/* Time read/write */
118
119static int s3c2410_rtc_gettime(struct rtc_time *rtc_tm)
120{
121 unsigned int have_retried = 0;
122
123 retry_get_time:
124 rtc_tm->tm_min = readb(S3C2410_RTCMIN);
125 rtc_tm->tm_hour = readb(S3C2410_RTCHOUR);
126 rtc_tm->tm_mday = readb(S3C2410_RTCDATE);
127 rtc_tm->tm_mon = readb(S3C2410_RTCMON);
128 rtc_tm->tm_year = readb(S3C2410_RTCYEAR);
129 rtc_tm->tm_sec = readb(S3C2410_RTCSEC);
130
131 /* the only way to work out wether the system was mid-update
132 * when we read it is to check the second counter, and if it
133 * is zero, then we re-try the entire read
134 */
135
136 if (rtc_tm->tm_sec == 0 && !have_retried) {
137 have_retried = 1;
138 goto retry_get_time;
139 }
140
141 pr_debug("read time %02x.%02x.%02x %02x/%02x/%02x\n",
142 rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday,
143 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec);
144
145 BCD_TO_BIN(rtc_tm->tm_sec);
146 BCD_TO_BIN(rtc_tm->tm_min);
147 BCD_TO_BIN(rtc_tm->tm_hour);
148 BCD_TO_BIN(rtc_tm->tm_mday);
149 BCD_TO_BIN(rtc_tm->tm_mon);
150 BCD_TO_BIN(rtc_tm->tm_year);
151
152 rtc_tm->tm_year += 100;
153 rtc_tm->tm_mon -= 1;
154
155 return 0;
156}
157
158
159static int s3c2410_rtc_settime(struct rtc_time *tm)
160{
161 /* the rtc gets round the y2k problem by just not supporting it */
162
163 if (tm->tm_year < 100)
164 return -EINVAL;
165
166 writeb(BIN2BCD(tm->tm_sec), S3C2410_RTCSEC);
167 writeb(BIN2BCD(tm->tm_min), S3C2410_RTCMIN);
168 writeb(BIN2BCD(tm->tm_hour), S3C2410_RTCHOUR);
169 writeb(BIN2BCD(tm->tm_mday), S3C2410_RTCDATE);
170 writeb(BIN2BCD(tm->tm_mon + 1), S3C2410_RTCMON);
171 writeb(BIN2BCD(tm->tm_year - 100), S3C2410_RTCYEAR);
172
173 return 0;
174}
175
176static int s3c2410_rtc_getalarm(struct rtc_wkalrm *alrm)
177{
178 struct rtc_time *alm_tm = &alrm->time;
179 unsigned int alm_en;
180
181 alm_tm->tm_sec = readb(S3C2410_ALMSEC);
182 alm_tm->tm_min = readb(S3C2410_ALMMIN);
183 alm_tm->tm_hour = readb(S3C2410_ALMHOUR);
184 alm_tm->tm_mon = readb(S3C2410_ALMMON);
185 alm_tm->tm_mday = readb(S3C2410_ALMDATE);
186 alm_tm->tm_year = readb(S3C2410_ALMYEAR);
187
188 alm_en = readb(S3C2410_RTCALM);
189
190 pr_debug("read alarm %02x %02x.%02x.%02x %02x/%02x/%02x\n",
191 alm_en,
192 alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday,
193 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec);
194
195
196 /* decode the alarm enable field */
197
198 if (alm_en & S3C2410_RTCALM_SECEN) {
199 BCD_TO_BIN(alm_tm->tm_sec);
200 } else {
201 alm_tm->tm_sec = 0xff;
202 }
203
204 if (alm_en & S3C2410_RTCALM_MINEN) {
205 BCD_TO_BIN(alm_tm->tm_min);
206 } else {
207 alm_tm->tm_min = 0xff;
208 }
209
210 if (alm_en & S3C2410_RTCALM_HOUREN) {
211 BCD_TO_BIN(alm_tm->tm_hour);
212 } else {
213 alm_tm->tm_hour = 0xff;
214 }
215
216 if (alm_en & S3C2410_RTCALM_DAYEN) {
217 BCD_TO_BIN(alm_tm->tm_mday);
218 } else {
219 alm_tm->tm_mday = 0xff;
220 }
221
222 if (alm_en & S3C2410_RTCALM_MONEN) {
223 BCD_TO_BIN(alm_tm->tm_mon);
224 alm_tm->tm_mon -= 1;
225 } else {
226 alm_tm->tm_mon = 0xff;
227 }
228
229 if (alm_en & S3C2410_RTCALM_YEAREN) {
230 BCD_TO_BIN(alm_tm->tm_year);
231 } else {
232 alm_tm->tm_year = 0xffff;
233 }
234
235 /* todo - set alrm->enabled ? */
236
237 return 0;
238}
239
240static int s3c2410_rtc_setalarm(struct rtc_wkalrm *alrm)
241{
242 struct rtc_time *tm = &alrm->time;
243 unsigned int alrm_en;
244
245 pr_debug("s3c2410_rtc_setalarm: %d, %02x/%02x/%02x %02x.%02x.%02x\n",
246 alrm->enabled,
247 tm->tm_mday & 0xff, tm->tm_mon & 0xff, tm->tm_year & 0xff,
248 tm->tm_hour & 0xff, tm->tm_min & 0xff, tm->tm_sec);
249
250 if (alrm->enabled || 1) {
251 alrm_en = readb(S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN;
252 writeb(0x00, S3C2410_RTCALM);
253
254 if (tm->tm_sec < 60 && tm->tm_sec >= 0) {
255 alrm_en |= S3C2410_RTCALM_SECEN;
256 writeb(BIN2BCD(tm->tm_sec), S3C2410_ALMSEC);
257 }
258
259 if (tm->tm_min < 60 && tm->tm_min >= 0) {
260 alrm_en |= S3C2410_RTCALM_MINEN;
261 writeb(BIN2BCD(tm->tm_min), S3C2410_ALMMIN);
262 }
263
264 if (tm->tm_hour < 24 && tm->tm_hour >= 0) {
265 alrm_en |= S3C2410_RTCALM_HOUREN;
266 writeb(BIN2BCD(tm->tm_hour), S3C2410_ALMHOUR);
267 }
268
269 pr_debug("setting S3C2410_RTCALM to %08x\n", alrm_en);
270
271 writeb(alrm_en, S3C2410_RTCALM);
272 enable_irq_wake(s3c2410_rtc_alarmno);
273 } else {
274 alrm_en = readb(S3C2410_RTCALM);
275 alrm_en &= ~S3C2410_RTCALM_ALMEN;
276 writeb(alrm_en, S3C2410_RTCALM);
277 disable_irq_wake(s3c2410_rtc_alarmno);
278 }
279
280 return 0;
281}
282
283static int s3c2410_rtc_ioctl(unsigned int cmd, unsigned long arg)
284{
285 switch (cmd) {
286 case RTC_AIE_OFF:
287 case RTC_AIE_ON:
288 s3c2410_rtc_setaie((cmd == RTC_AIE_ON) ? 1 : 0);
289 return 0;
290
291 case RTC_PIE_OFF:
292 case RTC_PIE_ON:
293 s3c2410_rtc_setpie((cmd == RTC_PIE_ON) ? 1 : 0);
294 return 0;
295
296 case RTC_IRQP_READ:
297 return put_user(s3c2410_rtc_freq, (unsigned long __user *)arg);
298
299 case RTC_IRQP_SET:
300 if (arg < 1 || arg > 64)
301 return -EINVAL;
302
303 if (!capable(CAP_SYS_RESOURCE))
304 return -EACCES;
305
306 /* check for power of 2 */
307
308 if ((arg & (arg-1)) != 0)
309 return -EINVAL;
310
311 pr_debug("s3c2410_rtc: setting frequency %ld\n", arg);
312
313 s3c2410_rtc_setfreq(arg);
314 return 0;
315
316 case RTC_UIE_ON:
317 case RTC_UIE_OFF:
318 return -EINVAL;
319 }
320
321 return -EINVAL;
322}
323
324static int s3c2410_rtc_proc(char *buf)
325{
326 unsigned int rtcalm = readb(S3C2410_RTCALM);
327 unsigned int ticnt = readb (S3C2410_TICNT);
328 char *p = buf;
329
330 p += sprintf(p, "alarm_IRQ\t: %s\n",
331 (rtcalm & S3C2410_RTCALM_ALMEN) ? "yes" : "no" );
332 p += sprintf(p, "periodic_IRQ\t: %s\n",
333 (ticnt & S3C2410_TICNT_ENABLE) ? "yes" : "no" );
334 p += sprintf(p, "periodic_freq\t: %d\n", s3c2410_rtc_freq);
335
336 return p - buf;
337}
338
339static int s3c2410_rtc_open(void)
340{
341 int ret;
342
343 ret = request_irq(s3c2410_rtc_alarmno, s3c2410_rtc_alarmirq,
344 IRQF_DISABLED, "s3c2410-rtc alarm", NULL);
345
346 if (ret)
347 printk(KERN_ERR "IRQ%d already in use\n", s3c2410_rtc_alarmno);
348
349 ret = request_irq(s3c2410_rtc_tickno, s3c2410_rtc_tickirq,
350 IRQF_DISABLED, "s3c2410-rtc tick", NULL);
351
352 if (ret) {
353 printk(KERN_ERR "IRQ%d already in use\n", s3c2410_rtc_tickno);
354 goto tick_err;
355 }
356
357 return ret;
358
359 tick_err:
360 free_irq(s3c2410_rtc_alarmno, NULL);
361 return ret;
362}
363
364static void s3c2410_rtc_release(void)
365{
366 /* do not clear AIE here, it may be needed for wake */
367
368 s3c2410_rtc_setpie(0);
369 free_irq(s3c2410_rtc_alarmno, NULL);
370 free_irq(s3c2410_rtc_tickno, NULL);
371}
372
373static struct rtc_ops s3c2410_rtcops = {
374 .owner = THIS_MODULE,
375 .open = s3c2410_rtc_open,
376 .release = s3c2410_rtc_release,
377 .ioctl = s3c2410_rtc_ioctl,
378 .read_time = s3c2410_rtc_gettime,
379 .set_time = s3c2410_rtc_settime,
380 .read_alarm = s3c2410_rtc_getalarm,
381 .set_alarm = s3c2410_rtc_setalarm,
382 .proc = s3c2410_rtc_proc,
383};
384
385static void s3c2410_rtc_enable(struct platform_device *pdev, int en)
386{
387 unsigned int tmp;
388
389 if (s3c2410_rtc_base == NULL)
390 return;
391
392 if (!en) {
393 tmp = readb(S3C2410_RTCCON);
394 writeb(tmp & ~S3C2410_RTCCON_RTCEN, S3C2410_RTCCON);
395
396 tmp = readb(S3C2410_TICNT);
397 writeb(tmp & ~S3C2410_TICNT_ENABLE, S3C2410_TICNT);
398 } else {
399 /* re-enable the device, and check it is ok */
400
401 if ((readb(S3C2410_RTCCON) & S3C2410_RTCCON_RTCEN) == 0){
402 dev_info(&pdev->dev, "rtc disabled, re-enabling\n");
403
404 tmp = readb(S3C2410_RTCCON);
405 writeb(tmp | S3C2410_RTCCON_RTCEN , S3C2410_RTCCON);
406 }
407
408 if ((readb(S3C2410_RTCCON) & S3C2410_RTCCON_CNTSEL)){
409 dev_info(&pdev->dev, "removing S3C2410_RTCCON_CNTSEL\n");
410
411 tmp = readb(S3C2410_RTCCON);
412 writeb(tmp& ~S3C2410_RTCCON_CNTSEL , S3C2410_RTCCON);
413 }
414
415 if ((readb(S3C2410_RTCCON) & S3C2410_RTCCON_CLKRST)){
416 dev_info(&pdev->dev, "removing S3C2410_RTCCON_CLKRST\n");
417
418 tmp = readb(S3C2410_RTCCON);
419 writeb(tmp & ~S3C2410_RTCCON_CLKRST, S3C2410_RTCCON);
420 }
421 }
422}
423
424static int s3c2410_rtc_remove(struct platform_device *dev)
425{
426 unregister_rtc(&s3c2410_rtcops);
427
428 s3c2410_rtc_setpie(0);
429 s3c2410_rtc_setaie(0);
430
431 if (s3c2410_rtc_mem != NULL) {
432 pr_debug("s3c2410_rtc: releasing s3c2410_rtc_mem\n");
433 iounmap(s3c2410_rtc_base);
434 release_resource(s3c2410_rtc_mem);
435 kfree(s3c2410_rtc_mem);
436 }
437
438 return 0;
439}
440
441static int s3c2410_rtc_probe(struct platform_device *pdev)
442{
443 struct resource *res;
444 int ret;
445
446 pr_debug("%s: probe=%p\n", __FUNCTION__, pdev);
447
448 /* find the IRQs */
449
450 s3c2410_rtc_tickno = platform_get_irq(pdev, 1);
451 if (s3c2410_rtc_tickno < 0) {
452 dev_err(&pdev->dev, "no irq for rtc tick\n");
453 return -ENOENT;
454 }
455
456 s3c2410_rtc_alarmno = platform_get_irq(pdev, 0);
457 if (s3c2410_rtc_alarmno < 0) {
458 dev_err(&pdev->dev, "no irq for alarm\n");
459 return -ENOENT;
460 }
461
462 pr_debug("s3c2410_rtc: tick irq %d, alarm irq %d\n",
463 s3c2410_rtc_tickno, s3c2410_rtc_alarmno);
464
465 /* get the memory region */
466
467 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
468 if (res == NULL) {
469 dev_err(&pdev->dev, "failed to get memory region resource\n");
470 return -ENOENT;
471 }
472
473 s3c2410_rtc_mem = request_mem_region(res->start, res->end-res->start+1,
474 pdev->name);
475
476 if (s3c2410_rtc_mem == NULL) {
477 dev_err(&pdev->dev, "failed to reserve memory region\n");
478 ret = -ENOENT;
479 goto exit_err;
480 }
481
482 s3c2410_rtc_base = ioremap(res->start, res->end - res->start + 1);
483 if (s3c2410_rtc_base == NULL) {
484 dev_err(&pdev->dev, "failed ioremap()\n");
485 ret = -EINVAL;
486 goto exit_err;
487 }
488
489 s3c2410_rtc_mem = res;
490 pr_debug("s3c2410_rtc_base=%p\n", s3c2410_rtc_base);
491
492 pr_debug("s3c2410_rtc: RTCCON=%02x\n", readb(S3C2410_RTCCON));
493
494 /* check to see if everything is setup correctly */
495
496 s3c2410_rtc_enable(pdev, 1);
497
498 pr_debug("s3c2410_rtc: RTCCON=%02x\n", readb(S3C2410_RTCCON));
499
500 s3c2410_rtc_setfreq(s3c2410_rtc_freq);
501
502 /* register RTC and exit */
503
504 register_rtc(&s3c2410_rtcops);
505 return 0;
506
507 exit_err:
508 dev_err(&pdev->dev, "error %d during initialisation\n", ret);
509
510 return ret;
511}
512
513#ifdef CONFIG_PM
514
515/* S3C2410 RTC Power management control */
516
517static struct timespec s3c2410_rtc_delta;
518
519static int ticnt_save;
520
521static int s3c2410_rtc_suspend(struct platform_device *pdev, pm_message_t state)
522{
523 struct rtc_time tm;
524 struct timespec time;
525
526 time.tv_nsec = 0;
527
528 /* save TICNT for anyone using periodic interrupts */
529
530 ticnt_save = readb(S3C2410_TICNT);
531
532 /* calculate time delta for suspend */
533
534 s3c2410_rtc_gettime(&tm);
535 rtc_tm_to_time(&tm, &time.tv_sec);
536 save_time_delta(&s3c2410_rtc_delta, &time);
537 s3c2410_rtc_enable(pdev, 0);
538
539 return 0;
540}
541
542static int s3c2410_rtc_resume(struct platform_device *pdev)
543{
544 struct rtc_time tm;
545 struct timespec time;
546
547 time.tv_nsec = 0;
548
549 s3c2410_rtc_enable(pdev, 1);
550 s3c2410_rtc_gettime(&tm);
551 rtc_tm_to_time(&tm, &time.tv_sec);
552 restore_time_delta(&s3c2410_rtc_delta, &time);
553
554 writeb(ticnt_save, S3C2410_TICNT);
555 return 0;
556}
557#else
558#define s3c2410_rtc_suspend NULL
559#define s3c2410_rtc_resume NULL
560#endif
561
562static struct platform_driver s3c2410_rtcdrv = {
563 .probe = s3c2410_rtc_probe,
564 .remove = s3c2410_rtc_remove,
565 .suspend = s3c2410_rtc_suspend,
566 .resume = s3c2410_rtc_resume,
567 .driver = {
568 .name = "s3c2410-rtc",
569 .owner = THIS_MODULE,
570 },
571};
572
573static char __initdata banner[] = "S3C2410 RTC, (c) 2004 Simtec Electronics\n";
574
575static int __init s3c2410_rtc_init(void)
576{
577 printk(banner);
578 return platform_driver_register(&s3c2410_rtcdrv);
579}
580
581static void __exit s3c2410_rtc_exit(void)
582{
583 platform_driver_unregister(&s3c2410_rtcdrv);
584}
585
586module_init(s3c2410_rtc_init);
587module_exit(s3c2410_rtc_exit);
588
589MODULE_DESCRIPTION("S3C24XX RTC Driver");
590MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
591MODULE_LICENSE("GPL");
diff --git a/drivers/char/scx200_gpio.c b/drivers/char/scx200_gpio.c
index b956c7babd18..99e5272e3c53 100644
--- a/drivers/char/scx200_gpio.c
+++ b/drivers/char/scx200_gpio.c
@@ -44,7 +44,7 @@ struct nsc_gpio_ops scx200_gpio_ops = {
44 .gpio_change = scx200_gpio_change, 44 .gpio_change = scx200_gpio_change,
45 .gpio_current = scx200_gpio_current 45 .gpio_current = scx200_gpio_current
46}; 46};
47EXPORT_SYMBOL(scx200_gpio_ops); 47EXPORT_SYMBOL_GPL(scx200_gpio_ops);
48 48
49static int scx200_gpio_open(struct inode *inode, struct file *file) 49static int scx200_gpio_open(struct inode *inode, struct file *file)
50{ 50{
@@ -69,7 +69,7 @@ static const struct file_operations scx200_gpio_fileops = {
69 .release = scx200_gpio_release, 69 .release = scx200_gpio_release,
70}; 70};
71 71
72struct cdev scx200_gpio_cdev; /* use 1 cdev for all pins */ 72static struct cdev scx200_gpio_cdev; /* use 1 cdev for all pins */
73 73
74static int __init scx200_gpio_init(void) 74static int __init scx200_gpio_init(void)
75{ 75{
diff --git a/drivers/char/selection.c b/drivers/char/selection.c
index 71093a9fc462..74cff839c857 100644
--- a/drivers/char/selection.c
+++ b/drivers/char/selection.c
@@ -33,7 +33,7 @@ extern void poke_blanked_console(void);
33 33
34/* Variables for selection control. */ 34/* Variables for selection control. */
35/* Use a dynamic buffer, instead of static (Dec 1994) */ 35/* Use a dynamic buffer, instead of static (Dec 1994) */
36struct vc_data *sel_cons; /* must not be disallocated */ 36struct vc_data *sel_cons; /* must not be deallocated */
37static volatile int sel_start = -1; /* cleared by clear_selection */ 37static volatile int sel_start = -1; /* cleared by clear_selection */
38static int sel_end; 38static int sel_end;
39static int sel_buffer_lth; 39static int sel_buffer_lth;
diff --git a/drivers/char/ser_a2232.c b/drivers/char/ser_a2232.c
index 510bd3e0e88b..75de5f66517a 100644
--- a/drivers/char/ser_a2232.c
+++ b/drivers/char/ser_a2232.c
@@ -111,7 +111,7 @@
111 111
112/***************************** Prototypes ***************************/ 112/***************************** Prototypes ***************************/
113/* The interrupt service routine */ 113/* The interrupt service routine */
114static irqreturn_t a2232_vbl_inter(int irq, void *data, struct pt_regs *fp); 114static irqreturn_t a2232_vbl_inter(int irq, void *data);
115/* Initialize the port structures */ 115/* Initialize the port structures */
116static void a2232_init_portstructs(void); 116static void a2232_init_portstructs(void);
117/* Initialize and register TTY drivers. */ 117/* Initialize and register TTY drivers. */
@@ -504,7 +504,7 @@ static int a2232_open(struct tty_struct * tty, struct file * filp)
504} 504}
505/*** END OF FUNCTIONS EXPECTED BY TTY DRIVER STRUCTS ***/ 505/*** END OF FUNCTIONS EXPECTED BY TTY DRIVER STRUCTS ***/
506 506
507static irqreturn_t a2232_vbl_inter(int irq, void *data, struct pt_regs *fp) 507static irqreturn_t a2232_vbl_inter(int irq, void *data)
508{ 508{
509#if A2232_IOBUFLEN != 256 509#if A2232_IOBUFLEN != 256
510#error "Re-Implement a2232_vbl_inter()!" 510#error "Re-Implement a2232_vbl_inter()!"
@@ -661,7 +661,7 @@ static void a2232_init_portstructs(void)
661 } 661 }
662} 662}
663 663
664static struct tty_operations a2232_ops = { 664static const struct tty_operations a2232_ops = {
665 .open = a2232_open, 665 .open = a2232_open,
666 .close = gs_close, 666 .close = gs_close,
667 .write = gs_write, 667 .write = gs_write,
@@ -695,6 +695,8 @@ static int a2232_init_drivers(void)
695 a2232_driver->init_termios = tty_std_termios; 695 a2232_driver->init_termios = tty_std_termios;
696 a2232_driver->init_termios.c_cflag = 696 a2232_driver->init_termios.c_cflag =
697 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 697 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
698 a2232_driver->init_termios.c_ispeed = 9600;
699 a2232_driver->init_termios.c_ospeed = 9600;
698 a2232_driver->flags = TTY_DRIVER_REAL_RAW; 700 a2232_driver->flags = TTY_DRIVER_REAL_RAW;
699 tty_set_operations(a2232_driver, &a2232_ops); 701 tty_set_operations(a2232_driver, &a2232_ops);
700 if ((error = tty_register_driver(a2232_driver))) { 702 if ((error = tty_register_driver(a2232_driver))) {
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c
index 21a710cb4bba..af50d32ae2c7 100644
--- a/drivers/char/serial167.c
+++ b/drivers/char/serial167.c
@@ -62,6 +62,7 @@
62#include <linux/console.h> 62#include <linux/console.h>
63#include <linux/module.h> 63#include <linux/module.h>
64#include <linux/bitops.h> 64#include <linux/bitops.h>
65#include <linux/tty_flip.h>
65 66
66#include <asm/system.h> 67#include <asm/system.h>
67#include <asm/io.h> 68#include <asm/io.h>
@@ -119,17 +120,6 @@ struct cyclades_port cy_port[] = {
119#define NR_PORTS ARRAY_SIZE(cy_port) 120#define NR_PORTS ARRAY_SIZE(cy_port)
120 121
121/* 122/*
122 * tmp_buf is used as a temporary buffer by serial_write. We need to
123 * lock it in case the copy_from_user blocks while swapping in a page,
124 * and some other program tries to do a serial write at the same time.
125 * Since the lock will only come under contention when the system is
126 * swapping and available memory is low, it makes sense to share one
127 * buffer across all the serial ports, since it significantly saves
128 * memory if large numbers of serial ports are open.
129 */
130static unsigned char *tmp_buf = 0;
131
132/*
133 * This is used to look up the divisor speeds and the timeouts 123 * This is used to look up the divisor speeds and the timeouts
134 * We're normally limited to 15 distinct baud rates. The extra 124 * We're normally limited to 15 distinct baud rates. The extra
135 * are accessed via settings in info->flags. 125 * are accessed via settings in info->flags.
@@ -381,7 +371,7 @@ cy_sched_event(struct cyclades_port *info, int event)
381 received, out buffer empty, modem change, etc. 371 received, out buffer empty, modem change, etc.
382 */ 372 */
383static irqreturn_t 373static irqreturn_t
384cd2401_rxerr_interrupt(int irq, void *dev_id, struct pt_regs *fp) 374cd2401_rxerr_interrupt(int irq, void *dev_id)
385{ 375{
386 struct tty_struct *tty; 376 struct tty_struct *tty;
387 struct cyclades_port *info; 377 struct cyclades_port *info;
@@ -438,8 +428,9 @@ cd2401_rxerr_interrupt(int irq, void *dev_id, struct pt_regs *fp)
438 overflowing, we still loose 428 overflowing, we still loose
439 the next incoming character. 429 the next incoming character.
440 */ 430 */
441 tty_insert_flip_char(tty, data, TTY_NORMAL); 431 if (tty_buffer_request_room(tty, 1) != 0){
442 } 432 tty_insert_flip_char(tty, data, TTY_FRAME);
433 }
443 /* These two conditions may imply */ 434 /* These two conditions may imply */
444 /* a normal read should be done. */ 435 /* a normal read should be done. */
445 /* else if(data & CyTIMEOUT) */ 436 /* else if(data & CyTIMEOUT) */
@@ -448,21 +439,21 @@ cd2401_rxerr_interrupt(int irq, void *dev_id, struct pt_regs *fp)
448 tty_insert_flip_char(tty, 0, TTY_NORMAL); 439 tty_insert_flip_char(tty, 0, TTY_NORMAL);
449 } 440 }
450 }else{ 441 }else{
451 tty_insert_flip_char(tty, data, TTY_NORMAL); 442 tty_insert_flip_char(tty, data, TTY_NORMAL);
452 } 443 }
453 }else{ 444 }else{
454 /* there was a software buffer overrun 445 /* there was a software buffer overrun
455 and nothing could be done about it!!! */ 446 and nothing could be done about it!!! */
456 } 447 }
457 } 448 }
458 schedule_delayed_work(&tty->flip.work, 1); 449 tty_schedule_flip(tty);
459 /* end of service */ 450 /* end of service */
460 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS; 451 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
461 return IRQ_HANDLED; 452 return IRQ_HANDLED;
462} /* cy_rxerr_interrupt */ 453} /* cy_rxerr_interrupt */
463 454
464static irqreturn_t 455static irqreturn_t
465cd2401_modem_interrupt(int irq, void *dev_id, struct pt_regs *fp) 456cd2401_modem_interrupt(int irq, void *dev_id)
466{ 457{
467 struct cyclades_port *info; 458 struct cyclades_port *info;
468 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 459 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
@@ -517,7 +508,7 @@ cd2401_modem_interrupt(int irq, void *dev_id, struct pt_regs *fp)
517} /* cy_modem_interrupt */ 508} /* cy_modem_interrupt */
518 509
519static irqreturn_t 510static irqreturn_t
520cd2401_tx_interrupt(int irq, void *dev_id, struct pt_regs *fp) 511cd2401_tx_interrupt(int irq, void *dev_id)
521{ 512{
522 struct cyclades_port *info; 513 struct cyclades_port *info;
523 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 514 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
@@ -637,7 +628,7 @@ cd2401_tx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
637} /* cy_tx_interrupt */ 628} /* cy_tx_interrupt */
638 629
639static irqreturn_t 630static irqreturn_t
640cd2401_rx_interrupt(int irq, void *dev_id, struct pt_regs *fp) 631cd2401_rx_interrupt(int irq, void *dev_id)
641{ 632{
642 struct tty_struct *tty; 633 struct tty_struct *tty;
643 struct cyclades_port *info; 634 struct cyclades_port *info;
@@ -646,6 +637,7 @@ cd2401_rx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
646 char data; 637 char data;
647 int char_count; 638 int char_count;
648 int save_cnt; 639 int save_cnt;
640 int len;
649 641
650 /* determine the channel and change to that context */ 642 /* determine the channel and change to that context */
651 channel = (u_short ) (base_addr[CyLICR] >> 2); 643 channel = (u_short ) (base_addr[CyLICR] >> 2);
@@ -678,14 +670,15 @@ cd2401_rx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
678 info->mon.char_max = char_count; 670 info->mon.char_max = char_count;
679 info->mon.char_last = char_count; 671 info->mon.char_last = char_count;
680#endif 672#endif
681 while(char_count--){ 673 len = tty_buffer_request_room(tty, char_count);
674 while(len--){
682 data = base_addr[CyRDR]; 675 data = base_addr[CyRDR];
683 tty_insert_flip_char(tty, data, TTY_NORMAL); 676 tty_insert_flip_char(tty, data, TTY_NORMAL);
684#ifdef CYCLOM_16Y_HACK 677#ifdef CYCLOM_16Y_HACK
685 udelay(10L); 678 udelay(10L);
686#endif 679#endif
687 } 680 }
688 schedule_delayed_work(&tty->flip.work, 1); 681 tty_schedule_flip(tty);
689 } 682 }
690 /* end of service */ 683 /* end of service */
691 base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS; 684 base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS;
@@ -713,9 +706,9 @@ cd2401_rx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
713 * had to poll every port to see if that port needed servicing. 706 * had to poll every port to see if that port needed servicing.
714 */ 707 */
715static void 708static void
716do_softint(void *private_) 709do_softint(struct work_struct *ugly_api)
717{ 710{
718 struct cyclades_port *info = (struct cyclades_port *) private_; 711 struct cyclades_port *info = container_of(ugly_api, struct cyclades_port, tqueue);
719 struct tty_struct *tty; 712 struct tty_struct *tty;
720 713
721 tty = info->tty; 714 tty = info->tty;
@@ -846,7 +839,7 @@ shutdown(struct cyclades_port * info)
846 local_irq_save(flags); 839 local_irq_save(flags);
847 if (info->xmit_buf){ 840 if (info->xmit_buf){
848 free_page((unsigned long) info->xmit_buf); 841 free_page((unsigned long) info->xmit_buf);
849 info->xmit_buf = 0; 842 info->xmit_buf = NULL;
850 } 843 }
851 844
852 base_addr[CyCAR] = (u_char)channel; 845 base_addr[CyCAR] = (u_char)channel;
@@ -1132,7 +1125,7 @@ cy_put_char(struct tty_struct *tty, unsigned char ch)
1132 if (serial_paranoia_check(info, tty->name, "cy_put_char")) 1125 if (serial_paranoia_check(info, tty->name, "cy_put_char"))
1133 return; 1126 return;
1134 1127
1135 if (!tty || !info->xmit_buf) 1128 if (!info->xmit_buf)
1136 return; 1129 return;
1137 1130
1138 local_irq_save(flags); 1131 local_irq_save(flags);
@@ -1198,7 +1191,7 @@ cy_write(struct tty_struct * tty,
1198 return 0; 1191 return 0;
1199 } 1192 }
1200 1193
1201 if (!tty || !info->xmit_buf || !tmp_buf){ 1194 if (!info->xmit_buf){
1202 return 0; 1195 return 0;
1203 } 1196 }
1204 1197
@@ -1361,7 +1354,7 @@ cy_unthrottle(struct tty_struct * tty)
1361 1354
1362static int 1355static int
1363get_serial_info(struct cyclades_port * info, 1356get_serial_info(struct cyclades_port * info,
1364 struct serial_struct * retinfo) 1357 struct serial_struct __user * retinfo)
1365{ 1358{
1366 struct serial_struct tmp; 1359 struct serial_struct tmp;
1367 1360
@@ -1383,7 +1376,7 @@ get_serial_info(struct cyclades_port * info,
1383 1376
1384static int 1377static int
1385set_serial_info(struct cyclades_port * info, 1378set_serial_info(struct cyclades_port * info,
1386 struct serial_struct * new_info) 1379 struct serial_struct __user * new_info)
1387{ 1380{
1388 struct serial_struct new_serial; 1381 struct serial_struct new_serial;
1389 struct cyclades_port old_info; 1382 struct cyclades_port old_info;
@@ -1433,7 +1426,6 @@ cy_tiocmget(struct tty_struct *tty, struct file *file)
1433 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1426 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1434 unsigned long flags; 1427 unsigned long flags;
1435 unsigned char status; 1428 unsigned char status;
1436 unsigned int result;
1437 1429
1438 channel = info->line; 1430 channel = info->line;
1439 1431
@@ -1457,7 +1449,6 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
1457 int channel; 1449 int channel;
1458 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1450 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1459 unsigned long flags; 1451 unsigned long flags;
1460 unsigned int arg;
1461 1452
1462 channel = info->line; 1453 channel = info->line;
1463 1454
@@ -1512,7 +1503,7 @@ send_break( struct cyclades_port * info, int duration)
1512} /* send_break */ 1503} /* send_break */
1513 1504
1514static int 1505static int
1515get_mon_info(struct cyclades_port * info, struct cyclades_monitor * mon) 1506get_mon_info(struct cyclades_port * info, struct cyclades_monitor __user * mon)
1516{ 1507{
1517 1508
1518 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor))) 1509 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
@@ -1525,7 +1516,7 @@ get_mon_info(struct cyclades_port * info, struct cyclades_monitor * mon)
1525} 1516}
1526 1517
1527static int 1518static int
1528set_threshold(struct cyclades_port * info, unsigned long *arg) 1519set_threshold(struct cyclades_port * info, unsigned long __user *arg)
1529{ 1520{
1530 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1521 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1531 unsigned long value; 1522 unsigned long value;
@@ -1542,7 +1533,7 @@ set_threshold(struct cyclades_port * info, unsigned long *arg)
1542} 1533}
1543 1534
1544static int 1535static int
1545get_threshold(struct cyclades_port * info, unsigned long *value) 1536get_threshold(struct cyclades_port * info, unsigned long __user *value)
1546{ 1537{
1547 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1538 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1548 int channel; 1539 int channel;
@@ -1555,7 +1546,7 @@ get_threshold(struct cyclades_port * info, unsigned long *value)
1555} 1546}
1556 1547
1557static int 1548static int
1558set_default_threshold(struct cyclades_port * info, unsigned long *arg) 1549set_default_threshold(struct cyclades_port * info, unsigned long __user *arg)
1559{ 1550{
1560 unsigned long value; 1551 unsigned long value;
1561 1552
@@ -1567,13 +1558,13 @@ set_default_threshold(struct cyclades_port * info, unsigned long *arg)
1567} 1558}
1568 1559
1569static int 1560static int
1570get_default_threshold(struct cyclades_port * info, unsigned long *value) 1561get_default_threshold(struct cyclades_port * info, unsigned long __user *value)
1571{ 1562{
1572 return put_user(info->default_threshold,value); 1563 return put_user(info->default_threshold,value);
1573} 1564}
1574 1565
1575static int 1566static int
1576set_timeout(struct cyclades_port * info, unsigned long *arg) 1567set_timeout(struct cyclades_port * info, unsigned long __user *arg)
1577{ 1568{
1578 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1569 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1579 int channel; 1570 int channel;
@@ -1590,7 +1581,7 @@ set_timeout(struct cyclades_port * info, unsigned long *arg)
1590} 1581}
1591 1582
1592static int 1583static int
1593get_timeout(struct cyclades_port * info, unsigned long *value) 1584get_timeout(struct cyclades_port * info, unsigned long __user *value)
1594{ 1585{
1595 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1586 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1596 int channel; 1587 int channel;
@@ -1610,7 +1601,7 @@ set_default_timeout(struct cyclades_port * info, unsigned long value)
1610} 1601}
1611 1602
1612static int 1603static int
1613get_default_timeout(struct cyclades_port * info, unsigned long *value) 1604get_default_timeout(struct cyclades_port * info, unsigned long __user *value)
1614{ 1605{
1615 return put_user(info->default_timeout,value); 1606 return put_user(info->default_timeout,value);
1616} 1607}
@@ -1622,6 +1613,7 @@ cy_ioctl(struct tty_struct *tty, struct file * file,
1622 unsigned long val; 1613 unsigned long val;
1623 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 1614 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1624 int ret_val = 0; 1615 int ret_val = 0;
1616 void __user *argp = (void __user *)arg;
1625 1617
1626#ifdef SERIAL_DEBUG_OTHER 1618#ifdef SERIAL_DEBUG_OTHER
1627 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */ 1619 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */
@@ -1629,28 +1621,28 @@ cy_ioctl(struct tty_struct *tty, struct file * file,
1629 1621
1630 switch (cmd) { 1622 switch (cmd) {
1631 case CYGETMON: 1623 case CYGETMON:
1632 ret_val = get_mon_info(info, (struct cyclades_monitor *)arg); 1624 ret_val = get_mon_info(info, argp);
1633 break; 1625 break;
1634 case CYGETTHRESH: 1626 case CYGETTHRESH:
1635 ret_val = get_threshold(info, (unsigned long *)arg); 1627 ret_val = get_threshold(info, argp);
1636 break; 1628 break;
1637 case CYSETTHRESH: 1629 case CYSETTHRESH:
1638 ret_val = set_threshold(info, (unsigned long *)arg); 1630 ret_val = set_threshold(info, argp);
1639 break; 1631 break;
1640 case CYGETDEFTHRESH: 1632 case CYGETDEFTHRESH:
1641 ret_val = get_default_threshold(info, (unsigned long *)arg); 1633 ret_val = get_default_threshold(info, argp);
1642 break; 1634 break;
1643 case CYSETDEFTHRESH: 1635 case CYSETDEFTHRESH:
1644 ret_val = set_default_threshold(info, (unsigned long *)arg); 1636 ret_val = set_default_threshold(info, argp);
1645 break; 1637 break;
1646 case CYGETTIMEOUT: 1638 case CYGETTIMEOUT:
1647 ret_val = get_timeout(info, (unsigned long *)arg); 1639 ret_val = get_timeout(info, argp);
1648 break; 1640 break;
1649 case CYSETTIMEOUT: 1641 case CYSETTIMEOUT:
1650 ret_val = set_timeout(info, (unsigned long *)arg); 1642 ret_val = set_timeout(info, argp);
1651 break; 1643 break;
1652 case CYGETDEFTIMEOUT: 1644 case CYGETDEFTIMEOUT:
1653 ret_val = get_default_timeout(info, (unsigned long *)arg); 1645 ret_val = get_default_timeout(info, argp);
1654 break; 1646 break;
1655 case CYSETDEFTIMEOUT: 1647 case CYSETDEFTIMEOUT:
1656 ret_val = set_default_timeout(info, (unsigned long)arg); 1648 ret_val = set_default_timeout(info, (unsigned long)arg);
@@ -1673,21 +1665,20 @@ cy_ioctl(struct tty_struct *tty, struct file * file,
1673 1665
1674/* The following commands are incompletely implemented!!! */ 1666/* The following commands are incompletely implemented!!! */
1675 case TIOCGSOFTCAR: 1667 case TIOCGSOFTCAR:
1676 ret_val = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *) arg); 1668 ret_val = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) argp);
1677 break; 1669 break;
1678 case TIOCSSOFTCAR: 1670 case TIOCSSOFTCAR:
1679 ret_val = get_user(val, (unsigned long *) arg); 1671 ret_val = get_user(val, (unsigned long __user *) argp);
1680 if (ret_val) 1672 if (ret_val)
1681 break; 1673 break;
1682 tty->termios->c_cflag = 1674 tty->termios->c_cflag =
1683 ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0)); 1675 ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0));
1684 break; 1676 break;
1685 case TIOCGSERIAL: 1677 case TIOCGSERIAL:
1686 ret_val = get_serial_info(info, (struct serial_struct *) arg); 1678 ret_val = get_serial_info(info, argp);
1687 break; 1679 break;
1688 case TIOCSSERIAL: 1680 case TIOCSSERIAL:
1689 ret_val = set_serial_info(info, 1681 ret_val = set_serial_info(info, argp);
1690 (struct serial_struct *) arg);
1691 break; 1682 break;
1692 default: 1683 default:
1693 ret_val = -ENOIOCTLCMD; 1684 ret_val = -ENOIOCTLCMD;
@@ -1704,7 +1695,7 @@ cy_ioctl(struct tty_struct *tty, struct file * file,
1704 1695
1705 1696
1706static void 1697static void
1707cy_set_termios(struct tty_struct *tty, struct termios * old_termios) 1698cy_set_termios(struct tty_struct *tty, struct ktermios * old_termios)
1708{ 1699{
1709 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1700 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1710 1701
@@ -1782,7 +1773,7 @@ cy_close(struct tty_struct * tty, struct file * filp)
1782 tty->driver->flush_buffer(tty); 1773 tty->driver->flush_buffer(tty);
1783 tty_ldisc_flush(tty); 1774 tty_ldisc_flush(tty);
1784 info->event = 0; 1775 info->event = 0;
1785 info->tty = 0; 1776 info->tty = NULL;
1786 if (info->blocked_open) { 1777 if (info->blocked_open) {
1787 if (info->close_delay) { 1778 if (info->close_delay) {
1788 msleep_interruptible(jiffies_to_msecs(info->close_delay)); 1779 msleep_interruptible(jiffies_to_msecs(info->close_delay));
@@ -1983,13 +1974,6 @@ cy_open(struct tty_struct *tty, struct file * filp)
1983 tty->driver_data = info; 1974 tty->driver_data = info;
1984 info->tty = tty; 1975 info->tty = tty;
1985 1976
1986 if (!tmp_buf) {
1987 tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL);
1988 if (!tmp_buf){
1989 return -ENOMEM;
1990 }
1991 }
1992
1993 /* 1977 /*
1994 * Start up serial port 1978 * Start up serial port
1995 */ 1979 */
@@ -2158,7 +2142,7 @@ mvme167_serial_console_setup(int cflag)
2158 rcor >> 5, rbpr); 2142 rcor >> 5, rbpr);
2159} /* serial_console_init */ 2143} /* serial_console_init */
2160 2144
2161static struct tty_operations cy_ops = { 2145static const struct tty_operations cy_ops = {
2162 .open = cy_open, 2146 .open = cy_open,
2163 .close = cy_close, 2147 .close = cy_close,
2164 .write = cy_write, 2148 .write = cy_write,
@@ -2266,7 +2250,7 @@ scrn[1] = '\0';
2266 info->card = index; 2250 info->card = index;
2267 info->line = port_num; 2251 info->line = port_num;
2268 info->flags = STD_COM_FLAGS; 2252 info->flags = STD_COM_FLAGS;
2269 info->tty = 0; 2253 info->tty = NULL;
2270 info->xmit_fifo_size = 12; 2254 info->xmit_fifo_size = 12;
2271 info->cor1 = CyPARITY_NONE|Cy_8_BITS; 2255 info->cor1 = CyPARITY_NONE|Cy_8_BITS;
2272 info->cor2 = CyETC; 2256 info->cor2 = CyETC;
@@ -2289,7 +2273,7 @@ scrn[1] = '\0';
2289 info->blocked_open = 0; 2273 info->blocked_open = 0;
2290 info->default_threshold = 0; 2274 info->default_threshold = 0;
2291 info->default_timeout = 0; 2275 info->default_timeout = 0;
2292 INIT_WORK(&info->tqueue, do_softint, info); 2276 INIT_WORK(&info->tqueue, do_softint);
2293 init_waitqueue_head(&info->open_wait); 2277 init_waitqueue_head(&info->open_wait);
2294 init_waitqueue_head(&info->close_wait); 2278 init_waitqueue_head(&info->close_wait);
2295 /* info->session */ 2279 /* info->session */
diff --git a/drivers/char/snsc.c b/drivers/char/snsc.c
index 07e0b75f2338..52753e723eaa 100644
--- a/drivers/char/snsc.c
+++ b/drivers/char/snsc.c
@@ -34,7 +34,7 @@
34#define SCDRV_TIMEOUT 1000 34#define SCDRV_TIMEOUT 1000
35 35
36static irqreturn_t 36static irqreturn_t
37scdrv_interrupt(int irq, void *subch_data, struct pt_regs *regs) 37scdrv_interrupt(int irq, void *subch_data)
38{ 38{
39 struct subch_data_s *sd = subch_data; 39 struct subch_data_s *sd = subch_data;
40 unsigned long flags; 40 unsigned long flags;
diff --git a/drivers/char/snsc_event.c b/drivers/char/snsc_event.c
index d12d4f629cec..2f56e8c54897 100644
--- a/drivers/char/snsc_event.c
+++ b/drivers/char/snsc_event.c
@@ -36,7 +36,7 @@ DECLARE_TASKLET(sn_sysctl_event, scdrv_event, 0);
36 * destination. 36 * destination.
37 */ 37 */
38static irqreturn_t 38static irqreturn_t
39scdrv_event_interrupt(int irq, void *subch_data, struct pt_regs *regs) 39scdrv_event_interrupt(int irq, void *subch_data)
40{ 40{
41 struct subch_data_s *sd = subch_data; 41 struct subch_data_s *sd = subch_data;
42 unsigned long flags; 42 unsigned long flags;
@@ -220,7 +220,7 @@ scdrv_dispatch_event(char *event, int len)
220 " Sending SIGPWR to init...\n"); 220 " Sending SIGPWR to init...\n");
221 221
222 /* give a SIGPWR signal to init proc */ 222 /* give a SIGPWR signal to init proc */
223 kill_proc(1, SIGPWR, 0); 223 kill_cad_pid(SIGPWR, 0);
224 } else { 224 } else {
225 /* print to system log */ 225 /* print to system log */
226 printk("%s|$(0x%x)%s\n", severity, esp_code, desc); 226 printk("%s|$(0x%x)%s\n", severity, esp_code, desc);
diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
index d4e434d694b7..17d54e1331b2 100644
--- a/drivers/char/sonypi.c
+++ b/drivers/char/sonypi.c
@@ -765,7 +765,7 @@ static void sonypi_setbluetoothpower(u8 state)
765 sonypi_device.bluetooth_power = state; 765 sonypi_device.bluetooth_power = state;
766} 766}
767 767
768static void input_keyrelease(void *data) 768static void input_keyrelease(struct work_struct *work)
769{ 769{
770 struct sonypi_keypress kp; 770 struct sonypi_keypress kp;
771 771
@@ -826,7 +826,7 @@ static void sonypi_report_input_event(u8 event)
826} 826}
827 827
828/* Interrupt handler: some event is available */ 828/* Interrupt handler: some event is available */
829static irqreturn_t sonypi_irq(int irq, void *dev_id, struct pt_regs *regs) 829static irqreturn_t sonypi_irq(int irq, void *dev_id)
830{ 830{
831 u8 v1, v2, event = 0; 831 u8 v1, v2, event = 0;
832 int i, j; 832 int i, j;
@@ -979,7 +979,7 @@ static ssize_t sonypi_misc_read(struct file *file, char __user *buf,
979 } 979 }
980 980
981 if (ret > 0) { 981 if (ret > 0) {
982 struct inode *inode = file->f_dentry->d_inode; 982 struct inode *inode = file->f_path.dentry->d_inode;
983 inode->i_atime = current_fs_time(inode->i_sb); 983 inode->i_atime = current_fs_time(inode->i_sb);
984 } 984 }
985 985
@@ -1412,7 +1412,7 @@ static int __devinit sonypi_probe(struct platform_device *dev)
1412 goto err_inpdev_unregister; 1412 goto err_inpdev_unregister;
1413 } 1413 }
1414 1414
1415 INIT_WORK(&sonypi_device.input_work, input_keyrelease, NULL); 1415 INIT_WORK(&sonypi_device.input_work, input_keyrelease);
1416 } 1416 }
1417 1417
1418 sonypi_enable(0); 1418 sonypi_enable(0);
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c
index a1d303f9a33d..20946f5127e0 100644
--- a/drivers/char/specialix.c
+++ b/drivers/char/specialix.c
@@ -182,12 +182,6 @@ static int sx_poll = HZ;
182#define RS_EVENT_WRITE_WAKEUP 0 182#define RS_EVENT_WRITE_WAKEUP 0
183 183
184static struct tty_driver *specialix_driver; 184static struct tty_driver *specialix_driver;
185static unsigned char * tmp_buf;
186
187static unsigned long baud_table[] = {
188 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
189 9600, 19200, 38400, 57600, 115200, 0,
190};
191 185
192static struct specialix_board sx_board[SX_NBOARD] = { 186static struct specialix_board sx_board[SX_NBOARD] = {
193 { 0, SX_IOBASE1, 9, }, 187 { 0, SX_IOBASE1, 9, },
@@ -201,7 +195,7 @@ static struct specialix_port sx_port[SX_NBOARD * SX_NPORT];
201 195
202#ifdef SPECIALIX_TIMER 196#ifdef SPECIALIX_TIMER
203static struct timer_list missed_irq_timer; 197static struct timer_list missed_irq_timer;
204static irqreturn_t sx_interrupt(int irq, void * dev_id, struct pt_regs * regs); 198static irqreturn_t sx_interrupt(int irq, void * dev_id);
205#endif 199#endif
206 200
207 201
@@ -898,7 +892,7 @@ static inline void sx_check_modem(struct specialix_board * bp)
898 892
899 893
900/* The main interrupt processing routine */ 894/* The main interrupt processing routine */
901static irqreturn_t sx_interrupt(int irq, void *dev_id, struct pt_regs *regs) 895static irqreturn_t sx_interrupt(int irq, void *dev_id)
902{ 896{
903 unsigned char status; 897 unsigned char status;
904 unsigned char ack; 898 unsigned char ack;
@@ -913,7 +907,7 @@ static irqreturn_t sx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
913 spin_lock_irqsave(&bp->lock, flags); 907 spin_lock_irqsave(&bp->lock, flags);
914 908
915 dprintk (SX_DEBUG_FLOW, "enter %s port %d room: %ld\n", __FUNCTION__, port_No(sx_get_port(bp, "INT")), SERIAL_XMIT_SIZE - sx_get_port(bp, "ITN")->xmit_cnt - 1); 909 dprintk (SX_DEBUG_FLOW, "enter %s port %d room: %ld\n", __FUNCTION__, port_No(sx_get_port(bp, "INT")), SERIAL_XMIT_SIZE - sx_get_port(bp, "ITN")->xmit_cnt - 1);
916 if (!bp || !(bp->flags & SX_BOARD_ACTIVE)) { 910 if (!(bp->flags & SX_BOARD_ACTIVE)) {
917 dprintk (SX_DEBUG_IRQ, "sx: False interrupt. irq %d.\n", irq); 911 dprintk (SX_DEBUG_IRQ, "sx: False interrupt. irq %d.\n", irq);
918 spin_unlock_irqrestore(&bp->lock, flags); 912 spin_unlock_irqrestore(&bp->lock, flags);
919 func_exit(); 913 func_exit();
@@ -1087,24 +1081,16 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1087 port->MSVR = (sx_in(bp, CD186x_MSVR) & MSVR_RTS); 1081 port->MSVR = (sx_in(bp, CD186x_MSVR) & MSVR_RTS);
1088 spin_unlock_irqrestore(&bp->lock, flags); 1082 spin_unlock_irqrestore(&bp->lock, flags);
1089 dprintk (SX_DEBUG_TERMIOS, "sx: got MSVR=%02x.\n", port->MSVR); 1083 dprintk (SX_DEBUG_TERMIOS, "sx: got MSVR=%02x.\n", port->MSVR);
1090 baud = C_BAUD(tty); 1084 baud = tty_get_baud_rate(tty);
1091 1085
1092 if (baud & CBAUDEX) { 1086 if (baud == 38400) {
1093 baud &= ~CBAUDEX;
1094 if (baud < 1 || baud > 2)
1095 port->tty->termios->c_cflag &= ~CBAUDEX;
1096 else
1097 baud += 15;
1098 }
1099 if (baud == 15) {
1100 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 1087 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
1101 baud ++; 1088 baud = 57600;
1102 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 1089 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1103 baud += 2; 1090 baud = 115200;
1104 } 1091 }
1105 1092
1106 1093 if (!baud) {
1107 if (!baud_table[baud]) {
1108 /* Drop DTR & exit */ 1094 /* Drop DTR & exit */
1109 dprintk (SX_DEBUG_TERMIOS, "Dropping DTR... Hmm....\n"); 1095 dprintk (SX_DEBUG_TERMIOS, "Dropping DTR... Hmm....\n");
1110 if (!SX_CRTSCTS (tty)) { 1096 if (!SX_CRTSCTS (tty)) {
@@ -1134,7 +1120,7 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1134 "This is an untested option, please be carefull.\n", 1120 "This is an untested option, please be carefull.\n",
1135 port_No (port), tmp); 1121 port_No (port), tmp);
1136 else 1122 else
1137 tmp = (((SX_OSCFREQ + baud_table[baud]/2) / baud_table[baud] + 1123 tmp = (((SX_OSCFREQ + baud/2) / baud +
1138 CD186x_TPC/2) / CD186x_TPC); 1124 CD186x_TPC/2) / CD186x_TPC);
1139 1125
1140 if ((tmp < 0x10) && time_before(again, jiffies)) { 1126 if ((tmp < 0x10) && time_before(again, jiffies)) {
@@ -1159,11 +1145,9 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1159 sx_out(bp, CD186x_RBPRL, tmp & 0xff); 1145 sx_out(bp, CD186x_RBPRL, tmp & 0xff);
1160 sx_out(bp, CD186x_TBPRL, tmp & 0xff); 1146 sx_out(bp, CD186x_TBPRL, tmp & 0xff);
1161 spin_unlock_irqrestore(&bp->lock, flags); 1147 spin_unlock_irqrestore(&bp->lock, flags);
1162 if (port->custom_divisor) { 1148 if (port->custom_divisor)
1163 baud = (SX_OSCFREQ + port->custom_divisor/2) / port->custom_divisor; 1149 baud = (SX_OSCFREQ + port->custom_divisor/2) / port->custom_divisor;
1164 baud = ( baud + 5 ) / 10; 1150 baud = (baud + 5) / 10; /* Estimated CPS */
1165 } else
1166 baud = (baud_table[baud] + 5) / 10; /* Estimated CPS */
1167 1151
1168 /* Two timer ticks seems enough to wakeup something like SLIP driver */ 1152 /* Two timer ticks seems enough to wakeup something like SLIP driver */
1169 tmp = ((baud + HZ/2) / HZ) * 2 - CD186x_NFIFO; 1153 tmp = ((baud + HZ/2) / HZ) * 2 - CD186x_NFIFO;
@@ -1682,7 +1666,7 @@ static int sx_write(struct tty_struct * tty,
1682 1666
1683 bp = port_Board(port); 1667 bp = port_Board(port);
1684 1668
1685 if (!port->xmit_buf || !tmp_buf) { 1669 if (!port->xmit_buf) {
1686 func_exit(); 1670 func_exit();
1687 return 0; 1671 return 0;
1688 } 1672 }
@@ -2277,9 +2261,10 @@ static void sx_start(struct tty_struct * tty)
2277 * do_sx_hangup() -> tty->hangup() -> sx_hangup() 2261 * do_sx_hangup() -> tty->hangup() -> sx_hangup()
2278 * 2262 *
2279 */ 2263 */
2280static void do_sx_hangup(void *private_) 2264static void do_sx_hangup(struct work_struct *work)
2281{ 2265{
2282 struct specialix_port *port = (struct specialix_port *) private_; 2266 struct specialix_port *port =
2267 container_of(work, struct specialix_port, tqueue_hangup);
2283 struct tty_struct *tty; 2268 struct tty_struct *tty;
2284 2269
2285 func_enter(); 2270 func_enter();
@@ -2326,7 +2311,7 @@ static void sx_hangup(struct tty_struct * tty)
2326} 2311}
2327 2312
2328 2313
2329static void sx_set_termios(struct tty_struct * tty, struct termios * old_termios) 2314static void sx_set_termios(struct tty_struct * tty, struct ktermios * old_termios)
2330{ 2315{
2331 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2316 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2332 unsigned long flags; 2317 unsigned long flags;
@@ -2352,9 +2337,10 @@ static void sx_set_termios(struct tty_struct * tty, struct termios * old_termios
2352} 2337}
2353 2338
2354 2339
2355static void do_softint(void *private_) 2340static void do_softint(struct work_struct *work)
2356{ 2341{
2357 struct specialix_port *port = (struct specialix_port *) private_; 2342 struct specialix_port *port =
2343 container_of(work, struct specialix_port, tqueue);
2358 struct tty_struct *tty; 2344 struct tty_struct *tty;
2359 2345
2360 func_enter(); 2346 func_enter();
@@ -2372,7 +2358,7 @@ static void do_softint(void *private_)
2372 func_exit(); 2358 func_exit();
2373} 2359}
2374 2360
2375static struct tty_operations sx_ops = { 2361static const struct tty_operations sx_ops = {
2376 .open = sx_open, 2362 .open = sx_open,
2377 .close = sx_close, 2363 .close = sx_close,
2378 .write = sx_write, 2364 .write = sx_write,
@@ -2406,12 +2392,6 @@ static int sx_init_drivers(void)
2406 return 1; 2392 return 1;
2407 } 2393 }
2408 2394
2409 if (!(tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL))) {
2410 printk(KERN_ERR "sx: Couldn't get free page.\n");
2411 put_tty_driver(specialix_driver);
2412 func_exit();
2413 return 1;
2414 }
2415 specialix_driver->owner = THIS_MODULE; 2395 specialix_driver->owner = THIS_MODULE;
2416 specialix_driver->name = "ttyW"; 2396 specialix_driver->name = "ttyW";
2417 specialix_driver->major = SPECIALIX_NORMAL_MAJOR; 2397 specialix_driver->major = SPECIALIX_NORMAL_MAJOR;
@@ -2420,12 +2400,13 @@ static int sx_init_drivers(void)
2420 specialix_driver->init_termios = tty_std_termios; 2400 specialix_driver->init_termios = tty_std_termios;
2421 specialix_driver->init_termios.c_cflag = 2401 specialix_driver->init_termios.c_cflag =
2422 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 2402 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2403 specialix_driver->init_termios.c_ispeed = 9600;
2404 specialix_driver->init_termios.c_ospeed = 9600;
2423 specialix_driver->flags = TTY_DRIVER_REAL_RAW; 2405 specialix_driver->flags = TTY_DRIVER_REAL_RAW;
2424 tty_set_operations(specialix_driver, &sx_ops); 2406 tty_set_operations(specialix_driver, &sx_ops);
2425 2407
2426 if ((error = tty_register_driver(specialix_driver))) { 2408 if ((error = tty_register_driver(specialix_driver))) {
2427 put_tty_driver(specialix_driver); 2409 put_tty_driver(specialix_driver);
2428 free_page((unsigned long)tmp_buf);
2429 printk(KERN_ERR "sx: Couldn't register specialix IO8+ driver, error = %d\n", 2410 printk(KERN_ERR "sx: Couldn't register specialix IO8+ driver, error = %d\n",
2430 error); 2411 error);
2431 func_exit(); 2412 func_exit();
@@ -2434,8 +2415,8 @@ static int sx_init_drivers(void)
2434 memset(sx_port, 0, sizeof(sx_port)); 2415 memset(sx_port, 0, sizeof(sx_port));
2435 for (i = 0; i < SX_NPORT * SX_NBOARD; i++) { 2416 for (i = 0; i < SX_NPORT * SX_NBOARD; i++) {
2436 sx_port[i].magic = SPECIALIX_MAGIC; 2417 sx_port[i].magic = SPECIALIX_MAGIC;
2437 INIT_WORK(&sx_port[i].tqueue, do_softint, &sx_port[i]); 2418 INIT_WORK(&sx_port[i].tqueue, do_softint);
2438 INIT_WORK(&sx_port[i].tqueue_hangup, do_sx_hangup, &sx_port[i]); 2419 INIT_WORK(&sx_port[i].tqueue_hangup, do_sx_hangup);
2439 sx_port[i].close_delay = 50 * HZ/100; 2420 sx_port[i].close_delay = 50 * HZ/100;
2440 sx_port[i].closing_wait = 3000 * HZ/100; 2421 sx_port[i].closing_wait = 3000 * HZ/100;
2441 init_waitqueue_head(&sx_port[i].open_wait); 2422 init_waitqueue_head(&sx_port[i].open_wait);
@@ -2451,7 +2432,6 @@ static void sx_release_drivers(void)
2451{ 2432{
2452 func_enter(); 2433 func_enter();
2453 2434
2454 free_page((unsigned long)tmp_buf);
2455 tty_unregister_driver(specialix_driver); 2435 tty_unregister_driver(specialix_driver);
2456 put_tty_driver(specialix_driver); 2436 put_tty_driver(specialix_driver);
2457 func_exit(); 2437 func_exit();
@@ -2497,7 +2477,7 @@ static int __init specialix_init(void)
2497 i++; 2477 i++;
2498 continue; 2478 continue;
2499 } 2479 }
2500 pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX, 2480 pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX,
2501 PCI_DEVICE_ID_SPECIALIX_IO8, 2481 PCI_DEVICE_ID_SPECIALIX_IO8,
2502 pdev); 2482 pdev);
2503 if (!pdev) break; 2483 if (!pdev) break;
@@ -2513,6 +2493,9 @@ static int __init specialix_init(void)
2513 if (!sx_probe(&sx_board[i])) 2493 if (!sx_probe(&sx_board[i]))
2514 found ++; 2494 found ++;
2515 } 2495 }
2496 /* May exit pci_get sequence early with lots of boards */
2497 if (pdev != NULL)
2498 pci_dev_put(pdev);
2516 } 2499 }
2517#endif 2500#endif
2518 2501
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 3beb2203d24b..e45113a7a472 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -41,13 +41,12 @@
41#include <linux/smp_lock.h> 41#include <linux/smp_lock.h>
42#include <linux/device.h> 42#include <linux/device.h>
43#include <linux/delay.h> 43#include <linux/delay.h>
44#include <linux/ctype.h>
44 45
45#include <asm/io.h> 46#include <asm/io.h>
46#include <asm/uaccess.h> 47#include <asm/uaccess.h>
47 48
48#ifdef CONFIG_PCI
49#include <linux/pci.h> 49#include <linux/pci.h>
50#endif
51 50
52/*****************************************************************************/ 51/*****************************************************************************/
53 52
@@ -63,45 +62,16 @@
63#define BRD_ECH64PCI 27 62#define BRD_ECH64PCI 27
64#define BRD_EASYIOPCI 28 63#define BRD_EASYIOPCI 28
65 64
66/* 65struct stlconf {
67 * Define a configuration structure to hold the board configuration. 66 unsigned int brdtype;
68 * Need to set this up in the code (for now) with the boards that are
69 * to be configured into the system. This is what needs to be modified
70 * when adding/removing/modifying boards. Each line entry in the
71 * stl_brdconf[] array is a board. Each line contains io/irq/memory
72 * ranges for that board (as well as what type of board it is).
73 * Some examples:
74 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
75 * This line would configure an EasyIO board (4 or 8, no difference),
76 * at io address 2a0 and irq 10.
77 * Another example:
78 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
79 * This line will configure an EasyConnection 8/32 board at primary io
80 * address 2a8, secondary io address 280 and irq 12.
81 * Enter as many lines into this array as you want (only the first 4
82 * will actually be used!). Any combination of EasyIO and EasyConnection
83 * boards can be specified. EasyConnection 8/32 boards can share their
84 * secondary io addresses between each other.
85 *
86 * NOTE: there is no need to put any entries in this table for PCI
87 * boards. They will be found automatically by the driver - provided
88 * PCI BIOS32 support is compiled into the kernel.
89 */
90
91typedef struct {
92 int brdtype;
93 int ioaddr1; 67 int ioaddr1;
94 int ioaddr2; 68 int ioaddr2;
95 unsigned long memaddr; 69 unsigned long memaddr;
96 int irq; 70 int irq;
97 int irqtype; 71 int irqtype;
98} stlconf_t;
99
100static stlconf_t stl_brdconf[] = {
101 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
102}; 72};
103 73
104static int stl_nrbrds = ARRAY_SIZE(stl_brdconf); 74static unsigned int stl_nrbrds;
105 75
106/*****************************************************************************/ 76/*****************************************************************************/
107 77
@@ -143,34 +113,30 @@ static struct tty_driver *stl_serial;
143 * with this termios initially. Basically all it defines is a raw port 113 * with this termios initially. Basically all it defines is a raw port
144 * at 9600, 8 data bits, 1 stop bit. 114 * at 9600, 8 data bits, 1 stop bit.
145 */ 115 */
146static struct termios stl_deftermios = { 116static struct ktermios stl_deftermios = {
147 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL), 117 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
148 .c_cc = INIT_C_CC, 118 .c_cc = INIT_C_CC,
119 .c_ispeed = 9600,
120 .c_ospeed = 9600,
149}; 121};
150 122
151/* 123/*
152 * Define global stats structures. Not used often, and can be
153 * re-used for each stats call.
154 */
155static comstats_t stl_comstats;
156static combrd_t stl_brdstats;
157static stlbrd_t stl_dummybrd;
158static stlport_t stl_dummyport;
159
160/*
161 * Define global place to put buffer overflow characters. 124 * Define global place to put buffer overflow characters.
162 */ 125 */
163static char stl_unwanted[SC26198_RXFIFOSIZE]; 126static char stl_unwanted[SC26198_RXFIFOSIZE];
164 127
165/*****************************************************************************/ 128/*****************************************************************************/
166 129
167static stlbrd_t *stl_brds[STL_MAXBRDS]; 130static DEFINE_MUTEX(stl_brdslock);
131static struct stlbrd *stl_brds[STL_MAXBRDS];
168 132
169/* 133/*
170 * Per board state flags. Used with the state field of the board struct. 134 * Per board state flags. Used with the state field of the board struct.
171 * Not really much here! 135 * Not really much here!
172 */ 136 */
173#define BRD_FOUND 0x1 137#define BRD_FOUND 0x1
138#define STL_PROBED 0x2
139
174 140
175/* 141/*
176 * Define the port structure istate flags. These set of flags are 142 * Define the port structure istate flags. These set of flags are
@@ -187,32 +153,32 @@ static stlbrd_t *stl_brds[STL_MAXBRDS];
187 * referencing boards when printing trace and stuff. 153 * referencing boards when printing trace and stuff.
188 */ 154 */
189static char *stl_brdnames[] = { 155static char *stl_brdnames[] = {
190 (char *) NULL, 156 NULL,
191 (char *) NULL, 157 NULL,
192 (char *) NULL, 158 NULL,
193 (char *) NULL, 159 NULL,
194 (char *) NULL, 160 NULL,
195 (char *) NULL, 161 NULL,
196 (char *) NULL, 162 NULL,
197 (char *) NULL, 163 NULL,
198 (char *) NULL, 164 NULL,
199 (char *) NULL, 165 NULL,
200 (char *) NULL, 166 NULL,
201 (char *) NULL, 167 NULL,
202 (char *) NULL, 168 NULL,
203 (char *) NULL, 169 NULL,
204 (char *) NULL, 170 NULL,
205 (char *) NULL, 171 NULL,
206 (char *) NULL, 172 NULL,
207 (char *) NULL, 173 NULL,
208 (char *) NULL, 174 NULL,
209 (char *) NULL, 175 NULL,
210 "EasyIO", 176 "EasyIO",
211 "EC8/32-AT", 177 "EC8/32-AT",
212 "EC8/32-MC", 178 "EC8/32-MC",
213 (char *) NULL, 179 NULL,
214 (char *) NULL, 180 NULL,
215 (char *) NULL, 181 NULL,
216 "EC8/32-PCI", 182 "EC8/32-PCI",
217 "EC8/64-PCI", 183 "EC8/64-PCI",
218 "EasyIO-PCI", 184 "EasyIO-PCI",
@@ -225,7 +191,7 @@ static char *stl_brdnames[] = {
225 * load line. These allow for easy board definitions, and easy 191 * load line. These allow for easy board definitions, and easy
226 * modification of the io, memory and irq resoucres. 192 * modification of the io, memory and irq resoucres.
227 */ 193 */
228static int stl_nargs = 0; 194static unsigned int stl_nargs;
229static char *board0[4]; 195static char *board0[4];
230static char *board1[4]; 196static char *board1[4];
231static char *board2[4]; 197static char *board2[4];
@@ -243,12 +209,10 @@ static char **stl_brdsp[] = {
243 * parse any module arguments. 209 * parse any module arguments.
244 */ 210 */
245 211
246typedef struct stlbrdtype { 212static struct {
247 char *name; 213 char *name;
248 int type; 214 int type;
249} stlbrdtype_t; 215} stl_brdstr[] = {
250
251static stlbrdtype_t stl_brdstr[] = {
252 { "easyio", BRD_EASYIO }, 216 { "easyio", BRD_EASYIO },
253 { "eio", BRD_EASYIO }, 217 { "eio", BRD_EASYIO },
254 { "20", BRD_EASYIO }, 218 { "20", BRD_EASYIO },
@@ -282,9 +246,6 @@ static stlbrdtype_t stl_brdstr[] = {
282/* 246/*
283 * Define the module agruments. 247 * Define the module agruments.
284 */ 248 */
285MODULE_AUTHOR("Greg Ungerer");
286MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
287MODULE_LICENSE("GPL");
288 249
289module_param_array(board0, charp, &stl_nargs, 0); 250module_param_array(board0, charp, &stl_nargs, 0);
290MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]"); 251MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
@@ -386,8 +347,6 @@ static spinlock_t stallion_lock; /* Guard the tty driver */
386 347
387/*****************************************************************************/ 348/*****************************************************************************/
388 349
389#ifdef CONFIG_PCI
390
391/* 350/*
392 * Define the Stallion PCI vendor and device IDs. 351 * Define the Stallion PCI vendor and device IDs.
393 */ 352 */
@@ -407,22 +366,19 @@ static spinlock_t stallion_lock; /* Guard the tty driver */
407/* 366/*
408 * Define structure to hold all Stallion PCI boards. 367 * Define structure to hold all Stallion PCI boards.
409 */ 368 */
410typedef struct stlpcibrd {
411 unsigned short vendid;
412 unsigned short devid;
413 int brdtype;
414} stlpcibrd_t;
415
416static stlpcibrd_t stl_pcibrds[] = {
417 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
418 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
419 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
420 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
421};
422
423static int stl_nrpcibrds = ARRAY_SIZE(stl_pcibrds);
424 369
425#endif 370static struct pci_device_id stl_pcibrds[] = {
371 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864),
372 .driver_data = BRD_ECH64PCI },
373 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI),
374 .driver_data = BRD_EASYIOPCI },
375 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832),
376 .driver_data = BRD_ECHPCI },
377 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410),
378 .driver_data = BRD_ECHPCI },
379 { }
380};
381MODULE_DEVICE_TABLE(pci, stl_pcibrds);
426 382
427/*****************************************************************************/ 383/*****************************************************************************/
428 384
@@ -442,134 +398,74 @@ static unsigned int stl_baudrates[] = {
442 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600 398 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
443}; 399};
444 400
445/*
446 * Define some handy local macros...
447 */
448#undef MIN
449#define MIN(a,b) (((a) <= (b)) ? (a) : (b))
450
451#undef TOLOWER
452#define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
453
454/*****************************************************************************/ 401/*****************************************************************************/
455 402
456/* 403/*
457 * Declare all those functions in this driver! 404 * Declare all those functions in this driver!
458 */ 405 */
459 406
460static void stl_argbrds(void);
461static int stl_parsebrd(stlconf_t *confp, char **argp);
462
463static unsigned long stl_atol(char *str);
464
465static int stl_init(void);
466static int stl_open(struct tty_struct *tty, struct file *filp);
467static void stl_close(struct tty_struct *tty, struct file *filp);
468static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
469static void stl_putchar(struct tty_struct *tty, unsigned char ch);
470static void stl_flushchars(struct tty_struct *tty);
471static int stl_writeroom(struct tty_struct *tty);
472static int stl_charsinbuffer(struct tty_struct *tty);
473static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
474static void stl_settermios(struct tty_struct *tty, struct termios *old);
475static void stl_throttle(struct tty_struct *tty);
476static void stl_unthrottle(struct tty_struct *tty);
477static void stl_stop(struct tty_struct *tty);
478static void stl_start(struct tty_struct *tty);
479static void stl_flushbuffer(struct tty_struct *tty);
480static void stl_breakctl(struct tty_struct *tty, int state);
481static void stl_waituntilsent(struct tty_struct *tty, int timeout);
482static void stl_sendxchar(struct tty_struct *tty, char ch);
483static void stl_hangup(struct tty_struct *tty);
484static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg); 407static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
485static int stl_portinfo(stlport_t *portp, int portnr, char *pos); 408static int stl_brdinit(struct stlbrd *brdp);
486static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data); 409static int stl_getportstats(struct stlport *portp, comstats_t __user *cp);
487 410static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp);
488static int stl_brdinit(stlbrd_t *brdp); 411static int stl_waitcarrier(struct stlport *portp, struct file *filp);
489static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
490static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp);
491static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp);
492static int stl_getbrdstats(combrd_t __user *bp);
493static int stl_getportstats(stlport_t *portp, comstats_t __user *cp);
494static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp);
495static int stl_getportstruct(stlport_t __user *arg);
496static int stl_getbrdstruct(stlbrd_t __user *arg);
497static int stl_waitcarrier(stlport_t *portp, struct file *filp);
498static int stl_eiointr(stlbrd_t *brdp);
499static int stl_echatintr(stlbrd_t *brdp);
500static int stl_echmcaintr(stlbrd_t *brdp);
501static int stl_echpciintr(stlbrd_t *brdp);
502static int stl_echpci64intr(stlbrd_t *brdp);
503static void stl_offintr(void *private);
504static stlbrd_t *stl_allocbrd(void);
505static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
506
507static inline int stl_initbrds(void);
508static inline int stl_initeio(stlbrd_t *brdp);
509static inline int stl_initech(stlbrd_t *brdp);
510static inline int stl_getbrdnr(void);
511
512#ifdef CONFIG_PCI
513static inline int stl_findpcibrds(void);
514static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
515#endif
516 412
517/* 413/*
518 * CD1400 uart specific handling functions. 414 * CD1400 uart specific handling functions.
519 */ 415 */
520static void stl_cd1400setreg(stlport_t *portp, int regnr, int value); 416static void stl_cd1400setreg(struct stlport *portp, int regnr, int value);
521static int stl_cd1400getreg(stlport_t *portp, int regnr); 417static int stl_cd1400getreg(struct stlport *portp, int regnr);
522static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value); 418static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value);
523static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp); 419static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
524static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp); 420static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
525static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp); 421static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp);
526static int stl_cd1400getsignals(stlport_t *portp); 422static int stl_cd1400getsignals(struct stlport *portp);
527static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts); 423static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts);
528static void stl_cd1400ccrwait(stlport_t *portp); 424static void stl_cd1400ccrwait(struct stlport *portp);
529static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx); 425static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx);
530static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx); 426static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx);
531static void stl_cd1400disableintrs(stlport_t *portp); 427static void stl_cd1400disableintrs(struct stlport *portp);
532static void stl_cd1400sendbreak(stlport_t *portp, int len); 428static void stl_cd1400sendbreak(struct stlport *portp, int len);
533static void stl_cd1400flowctrl(stlport_t *portp, int state); 429static void stl_cd1400flowctrl(struct stlport *portp, int state);
534static void stl_cd1400sendflow(stlport_t *portp, int state); 430static void stl_cd1400sendflow(struct stlport *portp, int state);
535static void stl_cd1400flush(stlport_t *portp); 431static void stl_cd1400flush(struct stlport *portp);
536static int stl_cd1400datastate(stlport_t *portp); 432static int stl_cd1400datastate(struct stlport *portp);
537static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase); 433static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase);
538static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase); 434static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase);
539static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr); 435static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr);
540static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr); 436static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr);
541static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr); 437static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr);
542 438
543static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr); 439static inline int stl_cd1400breakisr(struct stlport *portp, int ioaddr);
544 440
545/* 441/*
546 * SC26198 uart specific handling functions. 442 * SC26198 uart specific handling functions.
547 */ 443 */
548static void stl_sc26198setreg(stlport_t *portp, int regnr, int value); 444static void stl_sc26198setreg(struct stlport *portp, int regnr, int value);
549static int stl_sc26198getreg(stlport_t *portp, int regnr); 445static int stl_sc26198getreg(struct stlport *portp, int regnr);
550static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value); 446static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value);
551static int stl_sc26198getglobreg(stlport_t *portp, int regnr); 447static int stl_sc26198getglobreg(struct stlport *portp, int regnr);
552static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp); 448static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
553static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp); 449static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
554static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp); 450static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp);
555static int stl_sc26198getsignals(stlport_t *portp); 451static int stl_sc26198getsignals(struct stlport *portp);
556static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts); 452static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts);
557static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx); 453static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx);
558static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx); 454static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx);
559static void stl_sc26198disableintrs(stlport_t *portp); 455static void stl_sc26198disableintrs(struct stlport *portp);
560static void stl_sc26198sendbreak(stlport_t *portp, int len); 456static void stl_sc26198sendbreak(struct stlport *portp, int len);
561static void stl_sc26198flowctrl(stlport_t *portp, int state); 457static void stl_sc26198flowctrl(struct stlport *portp, int state);
562static void stl_sc26198sendflow(stlport_t *portp, int state); 458static void stl_sc26198sendflow(struct stlport *portp, int state);
563static void stl_sc26198flush(stlport_t *portp); 459static void stl_sc26198flush(struct stlport *portp);
564static int stl_sc26198datastate(stlport_t *portp); 460static int stl_sc26198datastate(struct stlport *portp);
565static void stl_sc26198wait(stlport_t *portp); 461static void stl_sc26198wait(struct stlport *portp);
566static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty); 462static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty);
567static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase); 463static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase);
568static void stl_sc26198txisr(stlport_t *port); 464static void stl_sc26198txisr(struct stlport *port);
569static void stl_sc26198rxisr(stlport_t *port, unsigned int iack); 465static void stl_sc26198rxisr(struct stlport *port, unsigned int iack);
570static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch); 466static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch);
571static void stl_sc26198rxbadchars(stlport_t *portp); 467static void stl_sc26198rxbadchars(struct stlport *portp);
572static void stl_sc26198otherisr(stlport_t *port, unsigned int iack); 468static void stl_sc26198otherisr(struct stlport *port, unsigned int iack);
573 469
574/*****************************************************************************/ 470/*****************************************************************************/
575 471
@@ -577,20 +473,20 @@ static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
577 * Generic UART support structure. 473 * Generic UART support structure.
578 */ 474 */
579typedef struct uart { 475typedef struct uart {
580 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp); 476 int (*panelinit)(struct stlbrd *brdp, struct stlpanel *panelp);
581 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp); 477 void (*portinit)(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
582 void (*setport)(stlport_t *portp, struct termios *tiosp); 478 void (*setport)(struct stlport *portp, struct ktermios *tiosp);
583 int (*getsignals)(stlport_t *portp); 479 int (*getsignals)(struct stlport *portp);
584 void (*setsignals)(stlport_t *portp, int dtr, int rts); 480 void (*setsignals)(struct stlport *portp, int dtr, int rts);
585 void (*enablerxtx)(stlport_t *portp, int rx, int tx); 481 void (*enablerxtx)(struct stlport *portp, int rx, int tx);
586 void (*startrxtx)(stlport_t *portp, int rx, int tx); 482 void (*startrxtx)(struct stlport *portp, int rx, int tx);
587 void (*disableintrs)(stlport_t *portp); 483 void (*disableintrs)(struct stlport *portp);
588 void (*sendbreak)(stlport_t *portp, int len); 484 void (*sendbreak)(struct stlport *portp, int len);
589 void (*flowctrl)(stlport_t *portp, int state); 485 void (*flowctrl)(struct stlport *portp, int state);
590 void (*sendflow)(stlport_t *portp, int state); 486 void (*sendflow)(struct stlport *portp, int state);
591 void (*flush)(stlport_t *portp); 487 void (*flush)(struct stlport *portp);
592 int (*datastate)(stlport_t *portp); 488 int (*datastate)(struct stlport *portp);
593 void (*intr)(stlpanel_t *panelp, unsigned int iobase); 489 void (*intr)(struct stlpanel *panelp, unsigned int iobase);
594} uart_t; 490} uart_t;
595 491
596/* 492/*
@@ -712,184 +608,35 @@ static const struct file_operations stl_fsiomem = {
712 .ioctl = stl_memioctl, 608 .ioctl = stl_memioctl,
713}; 609};
714 610
715/*****************************************************************************/
716
717static struct class *stallion_class; 611static struct class *stallion_class;
718 612
719/* 613/*
720 * Loadable module initialization stuff.
721 */
722
723static int __init stallion_module_init(void)
724{
725 stl_init();
726 return 0;
727}
728
729/*****************************************************************************/
730
731static void __exit stallion_module_exit(void)
732{
733 stlbrd_t *brdp;
734 stlpanel_t *panelp;
735 stlport_t *portp;
736 int i, j, k;
737
738#ifdef DEBUG
739 printk("cleanup_module()\n");
740#endif
741
742 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
743 stl_drvversion);
744
745/*
746 * Free up all allocated resources used by the ports. This includes
747 * memory and interrupts. As part of this process we will also do
748 * a hangup on every open port - to try to flush out any processes
749 * hanging onto ports.
750 */
751 i = tty_unregister_driver(stl_serial);
752 put_tty_driver(stl_serial);
753 if (i) {
754 printk("STALLION: failed to un-register tty driver, "
755 "errno=%d\n", -i);
756 return;
757 }
758 for (i = 0; i < 4; i++)
759 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
760 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
761 printk("STALLION: failed to un-register serial memory device, "
762 "errno=%d\n", -i);
763 class_destroy(stallion_class);
764
765 for (i = 0; (i < stl_nrbrds); i++) {
766 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
767 continue;
768
769 free_irq(brdp->irq, brdp);
770
771 for (j = 0; (j < STL_MAXPANELS); j++) {
772 panelp = brdp->panels[j];
773 if (panelp == (stlpanel_t *) NULL)
774 continue;
775 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
776 portp = panelp->ports[k];
777 if (portp == (stlport_t *) NULL)
778 continue;
779 if (portp->tty != (struct tty_struct *) NULL)
780 stl_hangup(portp->tty);
781 kfree(portp->tx.buf);
782 kfree(portp);
783 }
784 kfree(panelp);
785 }
786
787 release_region(brdp->ioaddr1, brdp->iosize1);
788 if (brdp->iosize2 > 0)
789 release_region(brdp->ioaddr2, brdp->iosize2);
790
791 kfree(brdp);
792 stl_brds[i] = (stlbrd_t *) NULL;
793 }
794}
795
796module_init(stallion_module_init);
797module_exit(stallion_module_exit);
798
799/*****************************************************************************/
800
801/*
802 * Check for any arguments passed in on the module load command line. 614 * Check for any arguments passed in on the module load command line.
803 */ 615 */
804 616
805static void stl_argbrds(void)
806{
807 stlconf_t conf;
808 stlbrd_t *brdp;
809 int i;
810
811#ifdef DEBUG
812 printk("stl_argbrds()\n");
813#endif
814
815 for (i = stl_nrbrds; (i < stl_nargs); i++) {
816 memset(&conf, 0, sizeof(conf));
817 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
818 continue;
819 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
820 continue;
821 stl_nrbrds = i + 1;
822 brdp->brdnr = i;
823 brdp->brdtype = conf.brdtype;
824 brdp->ioaddr1 = conf.ioaddr1;
825 brdp->ioaddr2 = conf.ioaddr2;
826 brdp->irq = conf.irq;
827 brdp->irqtype = conf.irqtype;
828 stl_brdinit(brdp);
829 }
830}
831
832/*****************************************************************************/
833
834/*
835 * Convert an ascii string number into an unsigned long.
836 */
837
838static unsigned long stl_atol(char *str)
839{
840 unsigned long val;
841 int base, c;
842 char *sp;
843
844 val = 0;
845 sp = str;
846 if ((*sp == '0') && (*(sp+1) == 'x')) {
847 base = 16;
848 sp += 2;
849 } else if (*sp == '0') {
850 base = 8;
851 sp++;
852 } else {
853 base = 10;
854 }
855
856 for (; (*sp != 0); sp++) {
857 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
858 if ((c < 0) || (c >= base)) {
859 printk("STALLION: invalid argument %s\n", str);
860 val = 0;
861 break;
862 }
863 val = (val * base) + c;
864 }
865 return val;
866}
867
868/*****************************************************************************/ 617/*****************************************************************************/
869 618
870/* 619/*
871 * Parse the supplied argument string, into the board conf struct. 620 * Parse the supplied argument string, into the board conf struct.
872 */ 621 */
873 622
874static int stl_parsebrd(stlconf_t *confp, char **argp) 623static int __init stl_parsebrd(struct stlconf *confp, char **argp)
875{ 624{
876 char *sp; 625 char *sp;
877 int i; 626 unsigned int i;
878 627
879#ifdef DEBUG 628 pr_debug("stl_parsebrd(confp=%p,argp=%p)\n", confp, argp);
880 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
881#endif
882 629
883 if ((argp[0] == (char *) NULL) || (*argp[0] == 0)) 630 if ((argp[0] == NULL) || (*argp[0] == 0))
884 return 0; 631 return 0;
885 632
886 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++) 633 for (sp = argp[0], i = 0; (*sp != 0) && (i < 25); sp++, i++)
887 *sp = TOLOWER(*sp); 634 *sp = tolower(*sp);
888 635
889 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) { 636 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++)
890 if (strcmp(stl_brdstr[i].name, argp[0]) == 0) 637 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
891 break; 638 break;
892 } 639
893 if (i == ARRAY_SIZE(stl_brdstr)) { 640 if (i == ARRAY_SIZE(stl_brdstr)) {
894 printk("STALLION: unknown board name, %s?\n", argp[0]); 641 printk("STALLION: unknown board name, %s?\n", argp[0]);
895 return 0; 642 return 0;
@@ -898,16 +645,16 @@ static int stl_parsebrd(stlconf_t *confp, char **argp)
898 confp->brdtype = stl_brdstr[i].type; 645 confp->brdtype = stl_brdstr[i].type;
899 646
900 i = 1; 647 i = 1;
901 if ((argp[i] != (char *) NULL) && (*argp[i] != 0)) 648 if ((argp[i] != NULL) && (*argp[i] != 0))
902 confp->ioaddr1 = stl_atol(argp[i]); 649 confp->ioaddr1 = simple_strtoul(argp[i], NULL, 0);
903 i++; 650 i++;
904 if (confp->brdtype == BRD_ECH) { 651 if (confp->brdtype == BRD_ECH) {
905 if ((argp[i] != (char *) NULL) && (*argp[i] != 0)) 652 if ((argp[i] != NULL) && (*argp[i] != 0))
906 confp->ioaddr2 = stl_atol(argp[i]); 653 confp->ioaddr2 = simple_strtoul(argp[i], NULL, 0);
907 i++; 654 i++;
908 } 655 }
909 if ((argp[i] != (char *) NULL) && (*argp[i] != 0)) 656 if ((argp[i] != NULL) && (*argp[i] != 0))
910 confp->irq = stl_atol(argp[i]); 657 confp->irq = simple_strtoul(argp[i], NULL, 0);
911 return 1; 658 return 1;
912} 659}
913 660
@@ -917,14 +664,14 @@ static int stl_parsebrd(stlconf_t *confp, char **argp)
917 * Allocate a new board structure. Fill out the basic info in it. 664 * Allocate a new board structure. Fill out the basic info in it.
918 */ 665 */
919 666
920static stlbrd_t *stl_allocbrd(void) 667static struct stlbrd *stl_allocbrd(void)
921{ 668{
922 stlbrd_t *brdp; 669 struct stlbrd *brdp;
923 670
924 brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL); 671 brdp = kzalloc(sizeof(struct stlbrd), GFP_KERNEL);
925 if (!brdp) { 672 if (!brdp) {
926 printk("STALLION: failed to allocate memory (size=%Zd)\n", 673 printk("STALLION: failed to allocate memory (size=%Zd)\n",
927 sizeof(stlbrd_t)); 674 sizeof(struct stlbrd));
928 return NULL; 675 return NULL;
929 } 676 }
930 677
@@ -936,26 +683,23 @@ static stlbrd_t *stl_allocbrd(void)
936 683
937static int stl_open(struct tty_struct *tty, struct file *filp) 684static int stl_open(struct tty_struct *tty, struct file *filp)
938{ 685{
939 stlport_t *portp; 686 struct stlport *portp;
940 stlbrd_t *brdp; 687 struct stlbrd *brdp;
941 unsigned int minordev; 688 unsigned int minordev, brdnr, panelnr;
942 int brdnr, panelnr, portnr, rc; 689 int portnr, rc;
943 690
944#ifdef DEBUG 691 pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name);
945 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
946 (int) filp, tty->name);
947#endif
948 692
949 minordev = tty->index; 693 minordev = tty->index;
950 brdnr = MINOR2BRD(minordev); 694 brdnr = MINOR2BRD(minordev);
951 if (brdnr >= stl_nrbrds) 695 if (brdnr >= stl_nrbrds)
952 return -ENODEV; 696 return -ENODEV;
953 brdp = stl_brds[brdnr]; 697 brdp = stl_brds[brdnr];
954 if (brdp == (stlbrd_t *) NULL) 698 if (brdp == NULL)
955 return -ENODEV; 699 return -ENODEV;
956 minordev = MINOR2PORT(minordev); 700 minordev = MINOR2PORT(minordev);
957 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) { 701 for (portnr = -1, panelnr = 0; panelnr < STL_MAXPANELS; panelnr++) {
958 if (brdp->panels[panelnr] == (stlpanel_t *) NULL) 702 if (brdp->panels[panelnr] == NULL)
959 break; 703 break;
960 if (minordev < brdp->panels[panelnr]->nrports) { 704 if (minordev < brdp->panels[panelnr]->nrports) {
961 portnr = minordev; 705 portnr = minordev;
@@ -967,7 +711,7 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
967 return -ENODEV; 711 return -ENODEV;
968 712
969 portp = brdp->panels[panelnr]->ports[portnr]; 713 portp = brdp->panels[panelnr]->ports[portnr];
970 if (portp == (stlport_t *) NULL) 714 if (portp == NULL)
971 return -ENODEV; 715 return -ENODEV;
972 716
973/* 717/*
@@ -1013,10 +757,10 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
1013 * previous opens still in effect. If we are a normal serial device 757 * previous opens still in effect. If we are a normal serial device
1014 * then also we might have to wait for carrier. 758 * then also we might have to wait for carrier.
1015 */ 759 */
1016 if (!(filp->f_flags & O_NONBLOCK)) { 760 if (!(filp->f_flags & O_NONBLOCK))
1017 if ((rc = stl_waitcarrier(portp, filp)) != 0) 761 if ((rc = stl_waitcarrier(portp, filp)) != 0)
1018 return rc; 762 return rc;
1019 } 763
1020 portp->flags |= ASYNC_NORMAL_ACTIVE; 764 portp->flags |= ASYNC_NORMAL_ACTIVE;
1021 765
1022 return 0; 766 return 0;
@@ -1029,14 +773,12 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
1029 * maybe because if we are clocal then we don't need to wait... 773 * maybe because if we are clocal then we don't need to wait...
1030 */ 774 */
1031 775
1032static int stl_waitcarrier(stlport_t *portp, struct file *filp) 776static int stl_waitcarrier(struct stlport *portp, struct file *filp)
1033{ 777{
1034 unsigned long flags; 778 unsigned long flags;
1035 int rc, doclocal; 779 int rc, doclocal;
1036 780
1037#ifdef DEBUG 781 pr_debug("stl_waitcarrier(portp=%p,filp=%p)\n", portp, filp);
1038 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
1039#endif
1040 782
1041 rc = 0; 783 rc = 0;
1042 doclocal = 0; 784 doclocal = 0;
@@ -1062,9 +804,8 @@ static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1062 break; 804 break;
1063 } 805 }
1064 if (((portp->flags & ASYNC_CLOSING) == 0) && 806 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1065 (doclocal || (portp->sigs & TIOCM_CD))) { 807 (doclocal || (portp->sigs & TIOCM_CD)))
1066 break; 808 break;
1067 }
1068 if (signal_pending(current)) { 809 if (signal_pending(current)) {
1069 rc = -ERESTARTSYS; 810 rc = -ERESTARTSYS;
1070 break; 811 break;
@@ -1083,17 +824,61 @@ static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1083 824
1084/*****************************************************************************/ 825/*****************************************************************************/
1085 826
827static void stl_flushbuffer(struct tty_struct *tty)
828{
829 struct stlport *portp;
830
831 pr_debug("stl_flushbuffer(tty=%p)\n", tty);
832
833 if (tty == NULL)
834 return;
835 portp = tty->driver_data;
836 if (portp == NULL)
837 return;
838
839 stl_flush(portp);
840 tty_wakeup(tty);
841}
842
843/*****************************************************************************/
844
845static void stl_waituntilsent(struct tty_struct *tty, int timeout)
846{
847 struct stlport *portp;
848 unsigned long tend;
849
850 pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty, timeout);
851
852 if (tty == NULL)
853 return;
854 portp = tty->driver_data;
855 if (portp == NULL)
856 return;
857
858 if (timeout == 0)
859 timeout = HZ;
860 tend = jiffies + timeout;
861
862 while (stl_datastate(portp)) {
863 if (signal_pending(current))
864 break;
865 msleep_interruptible(20);
866 if (time_after_eq(jiffies, tend))
867 break;
868 }
869}
870
871/*****************************************************************************/
872
1086static void stl_close(struct tty_struct *tty, struct file *filp) 873static void stl_close(struct tty_struct *tty, struct file *filp)
1087{ 874{
1088 stlport_t *portp; 875 struct stlport *portp;
1089 unsigned long flags; 876 unsigned long flags;
1090 877
1091#ifdef DEBUG 878 pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp);
1092 printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1093#endif
1094 879
1095 portp = tty->driver_data; 880 portp = tty->driver_data;
1096 if (portp == (stlport_t *) NULL) 881 if (portp == NULL)
1097 return; 882 return;
1098 883
1099 spin_lock_irqsave(&stallion_lock, flags); 884 spin_lock_irqsave(&stallion_lock, flags);
@@ -1136,17 +921,17 @@ static void stl_close(struct tty_struct *tty, struct file *filp)
1136 stl_enablerxtx(portp, 0, 0); 921 stl_enablerxtx(portp, 0, 0);
1137 stl_flushbuffer(tty); 922 stl_flushbuffer(tty);
1138 portp->istate = 0; 923 portp->istate = 0;
1139 if (portp->tx.buf != (char *) NULL) { 924 if (portp->tx.buf != NULL) {
1140 kfree(portp->tx.buf); 925 kfree(portp->tx.buf);
1141 portp->tx.buf = (char *) NULL; 926 portp->tx.buf = NULL;
1142 portp->tx.head = (char *) NULL; 927 portp->tx.head = NULL;
1143 portp->tx.tail = (char *) NULL; 928 portp->tx.tail = NULL;
1144 } 929 }
1145 set_bit(TTY_IO_ERROR, &tty->flags); 930 set_bit(TTY_IO_ERROR, &tty->flags);
1146 tty_ldisc_flush(tty); 931 tty_ldisc_flush(tty);
1147 932
1148 tty->closing = 0; 933 tty->closing = 0;
1149 portp->tty = (struct tty_struct *) NULL; 934 portp->tty = NULL;
1150 935
1151 if (portp->openwaitcnt) { 936 if (portp->openwaitcnt) {
1152 if (portp->close_delay) 937 if (portp->close_delay)
@@ -1167,20 +952,17 @@ static void stl_close(struct tty_struct *tty, struct file *filp)
1167 952
1168static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count) 953static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
1169{ 954{
1170 stlport_t *portp; 955 struct stlport *portp;
1171 unsigned int len, stlen; 956 unsigned int len, stlen;
1172 unsigned char *chbuf; 957 unsigned char *chbuf;
1173 char *head, *tail; 958 char *head, *tail;
1174 959
1175#ifdef DEBUG 960 pr_debug("stl_write(tty=%p,buf=%p,count=%d)\n", tty, buf, count);
1176 printk("stl_write(tty=%x,buf=%x,count=%d)\n",
1177 (int) tty, (int) buf, count);
1178#endif
1179 961
1180 portp = tty->driver_data; 962 portp = tty->driver_data;
1181 if (portp == (stlport_t *) NULL) 963 if (portp == NULL)
1182 return 0; 964 return 0;
1183 if (portp->tx.buf == (char *) NULL) 965 if (portp->tx.buf == NULL)
1184 return 0; 966 return 0;
1185 967
1186/* 968/*
@@ -1201,10 +983,10 @@ static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count
1201 stlen = len; 983 stlen = len;
1202 } 984 }
1203 985
1204 len = MIN(len, count); 986 len = min(len, (unsigned int)count);
1205 count = 0; 987 count = 0;
1206 while (len > 0) { 988 while (len > 0) {
1207 stlen = MIN(len, stlen); 989 stlen = min(len, stlen);
1208 memcpy(head, chbuf, stlen); 990 memcpy(head, chbuf, stlen);
1209 len -= stlen; 991 len -= stlen;
1210 chbuf += stlen; 992 chbuf += stlen;
@@ -1227,20 +1009,18 @@ static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count
1227 1009
1228static void stl_putchar(struct tty_struct *tty, unsigned char ch) 1010static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1229{ 1011{
1230 stlport_t *portp; 1012 struct stlport *portp;
1231 unsigned int len; 1013 unsigned int len;
1232 char *head, *tail; 1014 char *head, *tail;
1233 1015
1234#ifdef DEBUG 1016 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
1235 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1236#endif
1237 1017
1238 if (tty == (struct tty_struct *) NULL) 1018 if (tty == NULL)
1239 return; 1019 return;
1240 portp = tty->driver_data; 1020 portp = tty->driver_data;
1241 if (portp == (stlport_t *) NULL) 1021 if (portp == NULL)
1242 return; 1022 return;
1243 if (portp->tx.buf == (char *) NULL) 1023 if (portp->tx.buf == NULL)
1244 return; 1024 return;
1245 1025
1246 head = portp->tx.head; 1026 head = portp->tx.head;
@@ -1267,18 +1047,16 @@ static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1267 1047
1268static void stl_flushchars(struct tty_struct *tty) 1048static void stl_flushchars(struct tty_struct *tty)
1269{ 1049{
1270 stlport_t *portp; 1050 struct stlport *portp;
1271 1051
1272#ifdef DEBUG 1052 pr_debug("stl_flushchars(tty=%p)\n", tty);
1273 printk("stl_flushchars(tty=%x)\n", (int) tty);
1274#endif
1275 1053
1276 if (tty == (struct tty_struct *) NULL) 1054 if (tty == NULL)
1277 return; 1055 return;
1278 portp = tty->driver_data; 1056 portp = tty->driver_data;
1279 if (portp == (stlport_t *) NULL) 1057 if (portp == NULL)
1280 return; 1058 return;
1281 if (portp->tx.buf == (char *) NULL) 1059 if (portp->tx.buf == NULL)
1282 return; 1060 return;
1283 1061
1284 stl_startrxtx(portp, -1, 1); 1062 stl_startrxtx(portp, -1, 1);
@@ -1288,24 +1066,22 @@ static void stl_flushchars(struct tty_struct *tty)
1288 1066
1289static int stl_writeroom(struct tty_struct *tty) 1067static int stl_writeroom(struct tty_struct *tty)
1290{ 1068{
1291 stlport_t *portp; 1069 struct stlport *portp;
1292 char *head, *tail; 1070 char *head, *tail;
1293 1071
1294#ifdef DEBUG 1072 pr_debug("stl_writeroom(tty=%p)\n", tty);
1295 printk("stl_writeroom(tty=%x)\n", (int) tty);
1296#endif
1297 1073
1298 if (tty == (struct tty_struct *) NULL) 1074 if (tty == NULL)
1299 return 0; 1075 return 0;
1300 portp = tty->driver_data; 1076 portp = tty->driver_data;
1301 if (portp == (stlport_t *) NULL) 1077 if (portp == NULL)
1302 return 0; 1078 return 0;
1303 if (portp->tx.buf == (char *) NULL) 1079 if (portp->tx.buf == NULL)
1304 return 0; 1080 return 0;
1305 1081
1306 head = portp->tx.head; 1082 head = portp->tx.head;
1307 tail = portp->tx.tail; 1083 tail = portp->tx.tail;
1308 return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1)); 1084 return (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1);
1309} 1085}
1310 1086
1311/*****************************************************************************/ 1087/*****************************************************************************/
@@ -1321,20 +1097,18 @@ static int stl_writeroom(struct tty_struct *tty)
1321 1097
1322static int stl_charsinbuffer(struct tty_struct *tty) 1098static int stl_charsinbuffer(struct tty_struct *tty)
1323{ 1099{
1324 stlport_t *portp; 1100 struct stlport *portp;
1325 unsigned int size; 1101 unsigned int size;
1326 char *head, *tail; 1102 char *head, *tail;
1327 1103
1328#ifdef DEBUG 1104 pr_debug("stl_charsinbuffer(tty=%p)\n", tty);
1329 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1330#endif
1331 1105
1332 if (tty == (struct tty_struct *) NULL) 1106 if (tty == NULL)
1333 return 0; 1107 return 0;
1334 portp = tty->driver_data; 1108 portp = tty->driver_data;
1335 if (portp == (stlport_t *) NULL) 1109 if (portp == NULL)
1336 return 0; 1110 return 0;
1337 if (portp->tx.buf == (char *) NULL) 1111 if (portp->tx.buf == NULL)
1338 return 0; 1112 return 0;
1339 1113
1340 head = portp->tx.head; 1114 head = portp->tx.head;
@@ -1351,14 +1125,12 @@ static int stl_charsinbuffer(struct tty_struct *tty)
1351 * Generate the serial struct info. 1125 * Generate the serial struct info.
1352 */ 1126 */
1353 1127
1354static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp) 1128static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
1355{ 1129{
1356 struct serial_struct sio; 1130 struct serial_struct sio;
1357 stlbrd_t *brdp; 1131 struct stlbrd *brdp;
1358 1132
1359#ifdef DEBUG 1133 pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp);
1360 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1361#endif
1362 1134
1363 memset(&sio, 0, sizeof(struct serial_struct)); 1135 memset(&sio, 0, sizeof(struct serial_struct));
1364 sio.line = portp->portnr; 1136 sio.line = portp->portnr;
@@ -1378,7 +1150,7 @@ static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
1378 } 1150 }
1379 1151
1380 brdp = stl_brds[portp->brdnr]; 1152 brdp = stl_brds[portp->brdnr];
1381 if (brdp != (stlbrd_t *) NULL) 1153 if (brdp != NULL)
1382 sio.irq = brdp->irq; 1154 sio.irq = brdp->irq;
1383 1155
1384 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0; 1156 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
@@ -1392,13 +1164,11 @@ static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
1392 * just quietly ignore any requests to change irq, etc. 1164 * just quietly ignore any requests to change irq, etc.
1393 */ 1165 */
1394 1166
1395static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp) 1167static int stl_setserial(struct stlport *portp, struct serial_struct __user *sp)
1396{ 1168{
1397 struct serial_struct sio; 1169 struct serial_struct sio;
1398 1170
1399#ifdef DEBUG 1171 pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp);
1400 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1401#endif
1402 1172
1403 if (copy_from_user(&sio, sp, sizeof(struct serial_struct))) 1173 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1404 return -EFAULT; 1174 return -EFAULT;
@@ -1424,12 +1194,12 @@ static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp)
1424 1194
1425static int stl_tiocmget(struct tty_struct *tty, struct file *file) 1195static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1426{ 1196{
1427 stlport_t *portp; 1197 struct stlport *portp;
1428 1198
1429 if (tty == (struct tty_struct *) NULL) 1199 if (tty == NULL)
1430 return -ENODEV; 1200 return -ENODEV;
1431 portp = tty->driver_data; 1201 portp = tty->driver_data;
1432 if (portp == (stlport_t *) NULL) 1202 if (portp == NULL)
1433 return -ENODEV; 1203 return -ENODEV;
1434 if (tty->flags & (1 << TTY_IO_ERROR)) 1204 if (tty->flags & (1 << TTY_IO_ERROR))
1435 return -EIO; 1205 return -EIO;
@@ -1440,13 +1210,13 @@ static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1440static int stl_tiocmset(struct tty_struct *tty, struct file *file, 1210static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1441 unsigned int set, unsigned int clear) 1211 unsigned int set, unsigned int clear)
1442{ 1212{
1443 stlport_t *portp; 1213 struct stlport *portp;
1444 int rts = -1, dtr = -1; 1214 int rts = -1, dtr = -1;
1445 1215
1446 if (tty == (struct tty_struct *) NULL) 1216 if (tty == NULL)
1447 return -ENODEV; 1217 return -ENODEV;
1448 portp = tty->driver_data; 1218 portp = tty->driver_data;
1449 if (portp == (stlport_t *) NULL) 1219 if (portp == NULL)
1450 return -ENODEV; 1220 return -ENODEV;
1451 if (tty->flags & (1 << TTY_IO_ERROR)) 1221 if (tty->flags & (1 << TTY_IO_ERROR))
1452 return -EIO; 1222 return -EIO;
@@ -1466,27 +1236,24 @@ static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1466 1236
1467static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) 1237static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1468{ 1238{
1469 stlport_t *portp; 1239 struct stlport *portp;
1470 unsigned int ival; 1240 unsigned int ival;
1471 int rc; 1241 int rc;
1472 void __user *argp = (void __user *)arg; 1242 void __user *argp = (void __user *)arg;
1473 1243
1474#ifdef DEBUG 1244 pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty, file, cmd,
1475 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n", 1245 arg);
1476 (int) tty, (int) file, cmd, (int) arg);
1477#endif
1478 1246
1479 if (tty == (struct tty_struct *) NULL) 1247 if (tty == NULL)
1480 return -ENODEV; 1248 return -ENODEV;
1481 portp = tty->driver_data; 1249 portp = tty->driver_data;
1482 if (portp == (stlport_t *) NULL) 1250 if (portp == NULL)
1483 return -ENODEV; 1251 return -ENODEV;
1484 1252
1485 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && 1253 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1486 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) { 1254 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS))
1487 if (tty->flags & (1 << TTY_IO_ERROR)) 1255 if (tty->flags & (1 << TTY_IO_ERROR))
1488 return -EIO; 1256 return -EIO;
1489 }
1490 1257
1491 rc = 0; 1258 rc = 0;
1492 1259
@@ -1531,19 +1298,37 @@ static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd
1531 1298
1532/*****************************************************************************/ 1299/*****************************************************************************/
1533 1300
1534static void stl_settermios(struct tty_struct *tty, struct termios *old) 1301/*
1302 * Start the transmitter again. Just turn TX interrupts back on.
1303 */
1304
1305static void stl_start(struct tty_struct *tty)
1535{ 1306{
1536 stlport_t *portp; 1307 struct stlport *portp;
1537 struct termios *tiosp;
1538 1308
1539#ifdef DEBUG 1309 pr_debug("stl_start(tty=%p)\n", tty);
1540 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1541#endif
1542 1310
1543 if (tty == (struct tty_struct *) NULL) 1311 if (tty == NULL)
1544 return; 1312 return;
1545 portp = tty->driver_data; 1313 portp = tty->driver_data;
1546 if (portp == (stlport_t *) NULL) 1314 if (portp == NULL)
1315 return;
1316 stl_startrxtx(portp, -1, 1);
1317}
1318
1319/*****************************************************************************/
1320
1321static void stl_settermios(struct tty_struct *tty, struct ktermios *old)
1322{
1323 struct stlport *portp;
1324 struct ktermios *tiosp;
1325
1326 pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old);
1327
1328 if (tty == NULL)
1329 return;
1330 portp = tty->driver_data;
1331 if (portp == NULL)
1547 return; 1332 return;
1548 1333
1549 tiosp = tty->termios; 1334 tiosp = tty->termios;
@@ -1571,16 +1356,14 @@ static void stl_settermios(struct tty_struct *tty, struct termios *old)
1571 1356
1572static void stl_throttle(struct tty_struct *tty) 1357static void stl_throttle(struct tty_struct *tty)
1573{ 1358{
1574 stlport_t *portp; 1359 struct stlport *portp;
1575 1360
1576#ifdef DEBUG 1361 pr_debug("stl_throttle(tty=%p)\n", tty);
1577 printk("stl_throttle(tty=%x)\n", (int) tty);
1578#endif
1579 1362
1580 if (tty == (struct tty_struct *) NULL) 1363 if (tty == NULL)
1581 return; 1364 return;
1582 portp = tty->driver_data; 1365 portp = tty->driver_data;
1583 if (portp == (stlport_t *) NULL) 1366 if (portp == NULL)
1584 return; 1367 return;
1585 stl_flowctrl(portp, 0); 1368 stl_flowctrl(portp, 0);
1586} 1369}
@@ -1593,16 +1376,14 @@ static void stl_throttle(struct tty_struct *tty)
1593 1376
1594static void stl_unthrottle(struct tty_struct *tty) 1377static void stl_unthrottle(struct tty_struct *tty)
1595{ 1378{
1596 stlport_t *portp; 1379 struct stlport *portp;
1597 1380
1598#ifdef DEBUG 1381 pr_debug("stl_unthrottle(tty=%p)\n", tty);
1599 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1600#endif
1601 1382
1602 if (tty == (struct tty_struct *) NULL) 1383 if (tty == NULL)
1603 return; 1384 return;
1604 portp = tty->driver_data; 1385 portp = tty->driver_data;
1605 if (portp == (stlport_t *) NULL) 1386 if (portp == NULL)
1606 return; 1387 return;
1607 stl_flowctrl(portp, 1); 1388 stl_flowctrl(portp, 1);
1608} 1389}
@@ -1616,16 +1397,14 @@ static void stl_unthrottle(struct tty_struct *tty)
1616 1397
1617static void stl_stop(struct tty_struct *tty) 1398static void stl_stop(struct tty_struct *tty)
1618{ 1399{
1619 stlport_t *portp; 1400 struct stlport *portp;
1620 1401
1621#ifdef DEBUG 1402 pr_debug("stl_stop(tty=%p)\n", tty);
1622 printk("stl_stop(tty=%x)\n", (int) tty);
1623#endif
1624 1403
1625 if (tty == (struct tty_struct *) NULL) 1404 if (tty == NULL)
1626 return; 1405 return;
1627 portp = tty->driver_data; 1406 portp = tty->driver_data;
1628 if (portp == (stlport_t *) NULL) 1407 if (portp == NULL)
1629 return; 1408 return;
1630 stl_startrxtx(portp, -1, 0); 1409 stl_startrxtx(portp, -1, 0);
1631} 1410}
@@ -1633,28 +1412,6 @@ static void stl_stop(struct tty_struct *tty)
1633/*****************************************************************************/ 1412/*****************************************************************************/
1634 1413
1635/* 1414/*
1636 * Start the transmitter again. Just turn TX interrupts back on.
1637 */
1638
1639static void stl_start(struct tty_struct *tty)
1640{
1641 stlport_t *portp;
1642
1643#ifdef DEBUG
1644 printk("stl_start(tty=%x)\n", (int) tty);
1645#endif
1646
1647 if (tty == (struct tty_struct *) NULL)
1648 return;
1649 portp = tty->driver_data;
1650 if (portp == (stlport_t *) NULL)
1651 return;
1652 stl_startrxtx(portp, -1, 1);
1653}
1654
1655/*****************************************************************************/
1656
1657/*
1658 * Hangup this port. This is pretty much like closing the port, only 1415 * Hangup this port. This is pretty much like closing the port, only
1659 * a little more brutal. No waiting for data to drain. Shutdown the 1416 * a little more brutal. No waiting for data to drain. Shutdown the
1660 * port and maybe drop signals. 1417 * port and maybe drop signals.
@@ -1662,16 +1419,14 @@ static void stl_start(struct tty_struct *tty)
1662 1419
1663static void stl_hangup(struct tty_struct *tty) 1420static void stl_hangup(struct tty_struct *tty)
1664{ 1421{
1665 stlport_t *portp; 1422 struct stlport *portp;
1666 1423
1667#ifdef DEBUG 1424 pr_debug("stl_hangup(tty=%p)\n", tty);
1668 printk("stl_hangup(tty=%x)\n", (int) tty);
1669#endif
1670 1425
1671 if (tty == (struct tty_struct *) NULL) 1426 if (tty == NULL)
1672 return; 1427 return;
1673 portp = tty->driver_data; 1428 portp = tty->driver_data;
1674 if (portp == (stlport_t *) NULL) 1429 if (portp == NULL)
1675 return; 1430 return;
1676 1431
1677 portp->flags &= ~ASYNC_INITIALIZED; 1432 portp->flags &= ~ASYNC_INITIALIZED;
@@ -1682,13 +1437,13 @@ static void stl_hangup(struct tty_struct *tty)
1682 stl_flushbuffer(tty); 1437 stl_flushbuffer(tty);
1683 portp->istate = 0; 1438 portp->istate = 0;
1684 set_bit(TTY_IO_ERROR, &tty->flags); 1439 set_bit(TTY_IO_ERROR, &tty->flags);
1685 if (portp->tx.buf != (char *) NULL) { 1440 if (portp->tx.buf != NULL) {
1686 kfree(portp->tx.buf); 1441 kfree(portp->tx.buf);
1687 portp->tx.buf = (char *) NULL; 1442 portp->tx.buf = NULL;
1688 portp->tx.head = (char *) NULL; 1443 portp->tx.head = NULL;
1689 portp->tx.tail = (char *) NULL; 1444 portp->tx.tail = NULL;
1690 } 1445 }
1691 portp->tty = (struct tty_struct *) NULL; 1446 portp->tty = NULL;
1692 portp->flags &= ~ASYNC_NORMAL_ACTIVE; 1447 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1693 portp->refcount = 0; 1448 portp->refcount = 0;
1694 wake_up_interruptible(&portp->open_wait); 1449 wake_up_interruptible(&portp->open_wait);
@@ -1696,38 +1451,16 @@ static void stl_hangup(struct tty_struct *tty)
1696 1451
1697/*****************************************************************************/ 1452/*****************************************************************************/
1698 1453
1699static void stl_flushbuffer(struct tty_struct *tty)
1700{
1701 stlport_t *portp;
1702
1703#ifdef DEBUG
1704 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1705#endif
1706
1707 if (tty == (struct tty_struct *) NULL)
1708 return;
1709 portp = tty->driver_data;
1710 if (portp == (stlport_t *) NULL)
1711 return;
1712
1713 stl_flush(portp);
1714 tty_wakeup(tty);
1715}
1716
1717/*****************************************************************************/
1718
1719static void stl_breakctl(struct tty_struct *tty, int state) 1454static void stl_breakctl(struct tty_struct *tty, int state)
1720{ 1455{
1721 stlport_t *portp; 1456 struct stlport *portp;
1722 1457
1723#ifdef DEBUG 1458 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
1724 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
1725#endif
1726 1459
1727 if (tty == (struct tty_struct *) NULL) 1460 if (tty == NULL)
1728 return; 1461 return;
1729 portp = tty->driver_data; 1462 portp = tty->driver_data;
1730 if (portp == (stlport_t *) NULL) 1463 if (portp == NULL)
1731 return; 1464 return;
1732 1465
1733 stl_sendbreak(portp, ((state == -1) ? 1 : 2)); 1466 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
@@ -1735,48 +1468,16 @@ static void stl_breakctl(struct tty_struct *tty, int state)
1735 1468
1736/*****************************************************************************/ 1469/*****************************************************************************/
1737 1470
1738static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1739{
1740 stlport_t *portp;
1741 unsigned long tend;
1742
1743#ifdef DEBUG
1744 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
1745#endif
1746
1747 if (tty == (struct tty_struct *) NULL)
1748 return;
1749 portp = tty->driver_data;
1750 if (portp == (stlport_t *) NULL)
1751 return;
1752
1753 if (timeout == 0)
1754 timeout = HZ;
1755 tend = jiffies + timeout;
1756
1757 while (stl_datastate(portp)) {
1758 if (signal_pending(current))
1759 break;
1760 msleep_interruptible(20);
1761 if (time_after_eq(jiffies, tend))
1762 break;
1763 }
1764}
1765
1766/*****************************************************************************/
1767
1768static void stl_sendxchar(struct tty_struct *tty, char ch) 1471static void stl_sendxchar(struct tty_struct *tty, char ch)
1769{ 1472{
1770 stlport_t *portp; 1473 struct stlport *portp;
1771 1474
1772#ifdef DEBUG 1475 pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch);
1773 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
1774#endif
1775 1476
1776 if (tty == (struct tty_struct *) NULL) 1477 if (tty == NULL)
1777 return; 1478 return;
1778 portp = tty->driver_data; 1479 portp = tty->driver_data;
1779 if (portp == (stlport_t *) NULL) 1480 if (portp == NULL)
1780 return; 1481 return;
1781 1482
1782 if (ch == STOP_CHAR(tty)) 1483 if (ch == STOP_CHAR(tty))
@@ -1797,7 +1498,7 @@ static void stl_sendxchar(struct tty_struct *tty, char ch)
1797 * short then padded with spaces). 1498 * short then padded with spaces).
1798 */ 1499 */
1799 1500
1800static int stl_portinfo(stlport_t *portp, int portnr, char *pos) 1501static int stl_portinfo(struct stlport *portp, int portnr, char *pos)
1801{ 1502{
1802 char *sp; 1503 char *sp;
1803 int sigs, cnt; 1504 int sigs, cnt;
@@ -1826,7 +1527,7 @@ static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1826 *sp = ' '; 1527 *sp = ' ';
1827 sp += cnt; 1528 sp += cnt;
1828 1529
1829 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++) 1530 for (cnt = sp - pos; cnt < (MAXLINE - 1); cnt++)
1830 *sp++ = ' '; 1531 *sp++ = ' ';
1831 if (cnt >= MAXLINE) 1532 if (cnt >= MAXLINE)
1832 pos[(MAXLINE - 2)] = '+'; 1533 pos[(MAXLINE - 2)] = '+';
@@ -1843,18 +1544,15 @@ static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1843 1544
1844static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data) 1545static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1845{ 1546{
1846 stlbrd_t *brdp; 1547 struct stlbrd *brdp;
1847 stlpanel_t *panelp; 1548 struct stlpanel *panelp;
1848 stlport_t *portp; 1549 struct stlport *portp;
1849 int brdnr, panelnr, portnr, totalport; 1550 unsigned int brdnr, panelnr, portnr;
1850 int curoff, maxoff; 1551 int totalport, curoff, maxoff;
1851 char *pos; 1552 char *pos;
1852 1553
1853#ifdef DEBUG 1554 pr_debug("stl_readproc(page=%p,start=%p,off=%lx,count=%d,eof=%p,"
1854 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x," 1555 "data=%p\n", page, start, off, count, eof, data);
1855 "data=%x\n", (int) page, (int) start, (int) off, count,
1856 (int) eof, (int) data);
1857#endif
1858 1556
1859 pos = page; 1557 pos = page;
1860 totalport = 0; 1558 totalport = 0;
@@ -1873,9 +1571,9 @@ static int stl_readproc(char *page, char **start, off_t off, int count, int *eof
1873 * We scan through for each board, panel and port. The offset is 1571 * We scan through for each board, panel and port. The offset is
1874 * calculated on the fly, and irrelevant ports are skipped. 1572 * calculated on the fly, and irrelevant ports are skipped.
1875 */ 1573 */
1876 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) { 1574 for (brdnr = 0; brdnr < stl_nrbrds; brdnr++) {
1877 brdp = stl_brds[brdnr]; 1575 brdp = stl_brds[brdnr];
1878 if (brdp == (stlbrd_t *) NULL) 1576 if (brdp == NULL)
1879 continue; 1577 continue;
1880 if (brdp->state == 0) 1578 if (brdp->state == 0)
1881 continue; 1579 continue;
@@ -1887,9 +1585,9 @@ static int stl_readproc(char *page, char **start, off_t off, int count, int *eof
1887 } 1585 }
1888 1586
1889 totalport = brdnr * STL_MAXPORTS; 1587 totalport = brdnr * STL_MAXPORTS;
1890 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) { 1588 for (panelnr = 0; panelnr < brdp->nrpanels; panelnr++) {
1891 panelp = brdp->panels[panelnr]; 1589 panelp = brdp->panels[panelnr];
1892 if (panelp == (stlpanel_t *) NULL) 1590 if (panelp == NULL)
1893 continue; 1591 continue;
1894 1592
1895 maxoff = curoff + (panelp->nrports * MAXLINE); 1593 maxoff = curoff + (panelp->nrports * MAXLINE);
@@ -1899,10 +1597,10 @@ static int stl_readproc(char *page, char **start, off_t off, int count, int *eof
1899 continue; 1597 continue;
1900 } 1598 }
1901 1599
1902 for (portnr = 0; (portnr < panelp->nrports); portnr++, 1600 for (portnr = 0; portnr < panelp->nrports; portnr++,
1903 totalport++) { 1601 totalport++) {
1904 portp = panelp->ports[portnr]; 1602 portp = panelp->ports[portnr];
1905 if (portp == (stlport_t *) NULL) 1603 if (portp == NULL)
1906 continue; 1604 continue;
1907 if (off >= (curoff += MAXLINE)) 1605 if (off >= (curoff += MAXLINE))
1908 continue; 1606 continue;
@@ -1917,7 +1615,7 @@ static int stl_readproc(char *page, char **start, off_t off, int count, int *eof
1917 1615
1918stl_readdone: 1616stl_readdone:
1919 *start = page; 1617 *start = page;
1920 return (pos - page); 1618 return pos - page;
1921} 1619}
1922 1620
1923/*****************************************************************************/ 1621/*****************************************************************************/
@@ -1927,14 +1625,11 @@ stl_readdone:
1927 * calls off to the approrpriate board interrupt handlers. 1625 * calls off to the approrpriate board interrupt handlers.
1928 */ 1626 */
1929 1627
1930static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs) 1628static irqreturn_t stl_intr(int irq, void *dev_id)
1931{ 1629{
1932 stlbrd_t *brdp = (stlbrd_t *) dev_id; 1630 struct stlbrd *brdp = dev_id;
1933 1631
1934#ifdef DEBUG 1632 pr_debug("stl_intr(brdp=%p,irq=%d)\n", brdp, irq);
1935 printk("stl_intr(brdp=%x,irq=%d,regs=%x)\n", (int) brdp, irq,
1936 (int) regs);
1937#endif
1938 1633
1939 return IRQ_RETVAL((* brdp->isr)(brdp)); 1634 return IRQ_RETVAL((* brdp->isr)(brdp));
1940} 1635}
@@ -1945,9 +1640,9 @@ static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
1945 * Interrupt service routine for EasyIO board types. 1640 * Interrupt service routine for EasyIO board types.
1946 */ 1641 */
1947 1642
1948static int stl_eiointr(stlbrd_t *brdp) 1643static int stl_eiointr(struct stlbrd *brdp)
1949{ 1644{
1950 stlpanel_t *panelp; 1645 struct stlpanel *panelp;
1951 unsigned int iobase; 1646 unsigned int iobase;
1952 int handled = 0; 1647 int handled = 0;
1953 1648
@@ -1968,18 +1663,17 @@ static int stl_eiointr(stlbrd_t *brdp)
1968 * Interrupt service routine for ECH-AT board types. 1663 * Interrupt service routine for ECH-AT board types.
1969 */ 1664 */
1970 1665
1971static int stl_echatintr(stlbrd_t *brdp) 1666static int stl_echatintr(struct stlbrd *brdp)
1972{ 1667{
1973 stlpanel_t *panelp; 1668 struct stlpanel *panelp;
1974 unsigned int ioaddr; 1669 unsigned int ioaddr, bnknr;
1975 int bnknr;
1976 int handled = 0; 1670 int handled = 0;
1977 1671
1978 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl); 1672 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1979 1673
1980 while (inb(brdp->iostatus) & ECH_INTRPEND) { 1674 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1981 handled = 1; 1675 handled = 1;
1982 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) { 1676 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1983 ioaddr = brdp->bnkstataddr[bnknr]; 1677 ioaddr = brdp->bnkstataddr[bnknr];
1984 if (inb(ioaddr) & ECH_PNLINTRPEND) { 1678 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1985 panelp = brdp->bnk2panel[bnknr]; 1679 panelp = brdp->bnk2panel[bnknr];
@@ -1999,16 +1693,15 @@ static int stl_echatintr(stlbrd_t *brdp)
1999 * Interrupt service routine for ECH-MCA board types. 1693 * Interrupt service routine for ECH-MCA board types.
2000 */ 1694 */
2001 1695
2002static int stl_echmcaintr(stlbrd_t *brdp) 1696static int stl_echmcaintr(struct stlbrd *brdp)
2003{ 1697{
2004 stlpanel_t *panelp; 1698 struct stlpanel *panelp;
2005 unsigned int ioaddr; 1699 unsigned int ioaddr, bnknr;
2006 int bnknr;
2007 int handled = 0; 1700 int handled = 0;
2008 1701
2009 while (inb(brdp->iostatus) & ECH_INTRPEND) { 1702 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2010 handled = 1; 1703 handled = 1;
2011 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) { 1704 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
2012 ioaddr = brdp->bnkstataddr[bnknr]; 1705 ioaddr = brdp->bnkstataddr[bnknr];
2013 if (inb(ioaddr) & ECH_PNLINTRPEND) { 1706 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2014 panelp = brdp->bnk2panel[bnknr]; 1707 panelp = brdp->bnk2panel[bnknr];
@@ -2025,16 +1718,15 @@ static int stl_echmcaintr(stlbrd_t *brdp)
2025 * Interrupt service routine for ECH-PCI board types. 1718 * Interrupt service routine for ECH-PCI board types.
2026 */ 1719 */
2027 1720
2028static int stl_echpciintr(stlbrd_t *brdp) 1721static int stl_echpciintr(struct stlbrd *brdp)
2029{ 1722{
2030 stlpanel_t *panelp; 1723 struct stlpanel *panelp;
2031 unsigned int ioaddr; 1724 unsigned int ioaddr, bnknr, recheck;
2032 int bnknr, recheck;
2033 int handled = 0; 1725 int handled = 0;
2034 1726
2035 while (1) { 1727 while (1) {
2036 recheck = 0; 1728 recheck = 0;
2037 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) { 1729 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
2038 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl); 1730 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
2039 ioaddr = brdp->bnkstataddr[bnknr]; 1731 ioaddr = brdp->bnkstataddr[bnknr];
2040 if (inb(ioaddr) & ECH_PNLINTRPEND) { 1732 if (inb(ioaddr) & ECH_PNLINTRPEND) {
@@ -2056,16 +1748,15 @@ static int stl_echpciintr(stlbrd_t *brdp)
2056 * Interrupt service routine for ECH-8/64-PCI board types. 1748 * Interrupt service routine for ECH-8/64-PCI board types.
2057 */ 1749 */
2058 1750
2059static int stl_echpci64intr(stlbrd_t *brdp) 1751static int stl_echpci64intr(struct stlbrd *brdp)
2060{ 1752{
2061 stlpanel_t *panelp; 1753 struct stlpanel *panelp;
2062 unsigned int ioaddr; 1754 unsigned int ioaddr, bnknr;
2063 int bnknr;
2064 int handled = 0; 1755 int handled = 0;
2065 1756
2066 while (inb(brdp->ioctrl) & 0x1) { 1757 while (inb(brdp->ioctrl) & 0x1) {
2067 handled = 1; 1758 handled = 1;
2068 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) { 1759 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
2069 ioaddr = brdp->bnkstataddr[bnknr]; 1760 ioaddr = brdp->bnkstataddr[bnknr];
2070 if (inb(ioaddr) & ECH_PNLINTRPEND) { 1761 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2071 panelp = brdp->bnk2panel[bnknr]; 1762 panelp = brdp->bnk2panel[bnknr];
@@ -2082,39 +1773,34 @@ static int stl_echpci64intr(stlbrd_t *brdp)
2082/* 1773/*
2083 * Service an off-level request for some channel. 1774 * Service an off-level request for some channel.
2084 */ 1775 */
2085static void stl_offintr(void *private) 1776static void stl_offintr(struct work_struct *work)
2086{ 1777{
2087 stlport_t *portp; 1778 struct stlport *portp = container_of(work, struct stlport, tqueue);
2088 struct tty_struct *tty; 1779 struct tty_struct *tty;
2089 unsigned int oldsigs; 1780 unsigned int oldsigs;
2090 1781
2091 portp = private; 1782 pr_debug("stl_offintr(portp=%p)\n", portp);
2092 1783
2093#ifdef DEBUG 1784 if (portp == NULL)
2094 printk("stl_offintr(portp=%x)\n", (int) portp);
2095#endif
2096
2097 if (portp == (stlport_t *) NULL)
2098 return; 1785 return;
2099 1786
2100 tty = portp->tty; 1787 tty = portp->tty;
2101 if (tty == (struct tty_struct *) NULL) 1788 if (tty == NULL)
2102 return; 1789 return;
2103 1790
2104 lock_kernel(); 1791 lock_kernel();
2105 if (test_bit(ASYI_TXLOW, &portp->istate)) { 1792 if (test_bit(ASYI_TXLOW, &portp->istate))
2106 tty_wakeup(tty); 1793 tty_wakeup(tty);
2107 } 1794
2108 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) { 1795 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2109 clear_bit(ASYI_DCDCHANGE, &portp->istate); 1796 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2110 oldsigs = portp->sigs; 1797 oldsigs = portp->sigs;
2111 portp->sigs = stl_getsignals(portp); 1798 portp->sigs = stl_getsignals(portp);
2112 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0)) 1799 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2113 wake_up_interruptible(&portp->open_wait); 1800 wake_up_interruptible(&portp->open_wait);
2114 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) { 1801 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0))
2115 if (portp->flags & ASYNC_CHECK_CD) 1802 if (portp->flags & ASYNC_CHECK_CD)
2116 tty_hangup(tty); /* FIXME: module removal race here - AKPM */ 1803 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2117 }
2118 } 1804 }
2119 unlock_kernel(); 1805 unlock_kernel();
2120} 1806}
@@ -2125,14 +1811,13 @@ static void stl_offintr(void *private)
2125 * Initialize all the ports on a panel. 1811 * Initialize all the ports on a panel.
2126 */ 1812 */
2127 1813
2128static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp) 1814static int __devinit stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
2129{ 1815{
2130 stlport_t *portp; 1816 struct stlport *portp;
2131 int chipmask, i; 1817 unsigned int i;
1818 int chipmask;
2132 1819
2133#ifdef DEBUG 1820 pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp, panelp);
2134 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
2135#endif
2136 1821
2137 chipmask = stl_panelinit(brdp, panelp); 1822 chipmask = stl_panelinit(brdp, panelp);
2138 1823
@@ -2140,11 +1825,11 @@ static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2140 * All UART's are initialized (if found!). Now go through and setup 1825 * All UART's are initialized (if found!). Now go through and setup
2141 * each ports data structures. 1826 * each ports data structures.
2142 */ 1827 */
2143 for (i = 0; (i < panelp->nrports); i++) { 1828 for (i = 0; i < panelp->nrports; i++) {
2144 portp = kzalloc(sizeof(stlport_t), GFP_KERNEL); 1829 portp = kzalloc(sizeof(struct stlport), GFP_KERNEL);
2145 if (!portp) { 1830 if (!portp) {
2146 printk("STALLION: failed to allocate memory " 1831 printk("STALLION: failed to allocate memory "
2147 "(size=%Zd)\n", sizeof(stlport_t)); 1832 "(size=%Zd)\n", sizeof(struct stlport));
2148 break; 1833 break;
2149 } 1834 }
2150 1835
@@ -2157,7 +1842,7 @@ static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2157 portp->baud_base = STL_BAUDBASE; 1842 portp->baud_base = STL_BAUDBASE;
2158 portp->close_delay = STL_CLOSEDELAY; 1843 portp->close_delay = STL_CLOSEDELAY;
2159 portp->closing_wait = 30 * HZ; 1844 portp->closing_wait = 30 * HZ;
2160 INIT_WORK(&portp->tqueue, stl_offintr, portp); 1845 INIT_WORK(&portp->tqueue, stl_offintr);
2161 init_waitqueue_head(&portp->open_wait); 1846 init_waitqueue_head(&portp->open_wait);
2162 init_waitqueue_head(&portp->close_wait); 1847 init_waitqueue_head(&portp->close_wait);
2163 portp->stats.brd = portp->brdnr; 1848 portp->stats.brd = portp->brdnr;
@@ -2167,7 +1852,30 @@ static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2167 stl_portinit(brdp, panelp, portp); 1852 stl_portinit(brdp, panelp, portp);
2168 } 1853 }
2169 1854
2170 return(0); 1855 return 0;
1856}
1857
1858static void stl_cleanup_panels(struct stlbrd *brdp)
1859{
1860 struct stlpanel *panelp;
1861 struct stlport *portp;
1862 unsigned int j, k;
1863
1864 for (j = 0; j < STL_MAXPANELS; j++) {
1865 panelp = brdp->panels[j];
1866 if (panelp == NULL)
1867 continue;
1868 for (k = 0; k < STL_PORTSPERPANEL; k++) {
1869 portp = panelp->ports[k];
1870 if (portp == NULL)
1871 continue;
1872 if (portp->tty != NULL)
1873 stl_hangup(portp->tty);
1874 kfree(portp->tx.buf);
1875 kfree(portp);
1876 }
1877 kfree(panelp);
1878 }
2171} 1879}
2172 1880
2173/*****************************************************************************/ 1881/*****************************************************************************/
@@ -2176,16 +1884,14 @@ static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2176 * Try to find and initialize an EasyIO board. 1884 * Try to find and initialize an EasyIO board.
2177 */ 1885 */
2178 1886
2179static inline int stl_initeio(stlbrd_t *brdp) 1887static int __devinit stl_initeio(struct stlbrd *brdp)
2180{ 1888{
2181 stlpanel_t *panelp; 1889 struct stlpanel *panelp;
2182 unsigned int status; 1890 unsigned int status;
2183 char *name; 1891 char *name;
2184 int rc; 1892 int retval;
2185 1893
2186#ifdef DEBUG 1894 pr_debug("stl_initeio(brdp=%p)\n", brdp);
2187 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2188#endif
2189 1895
2190 brdp->ioctrl = brdp->ioaddr1 + 1; 1896 brdp->ioctrl = brdp->ioaddr1 + 1;
2191 brdp->iostatus = brdp->ioaddr1 + 2; 1897 brdp->iostatus = brdp->ioaddr1 + 2;
@@ -2210,18 +1916,20 @@ static inline int stl_initeio(stlbrd_t *brdp)
2210 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) { 1916 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2211 printk("STALLION: invalid irq=%d for brd=%d\n", 1917 printk("STALLION: invalid irq=%d for brd=%d\n",
2212 brdp->irq, brdp->brdnr); 1918 brdp->irq, brdp->brdnr);
2213 return(-EINVAL); 1919 retval = -EINVAL;
1920 goto err;
2214 } 1921 }
2215 outb((stl_vecmap[brdp->irq] | EIO_0WS | 1922 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2216 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)), 1923 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2217 brdp->ioctrl); 1924 brdp->ioctrl);
2218 } 1925 }
2219 1926
1927 retval = -EBUSY;
2220 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) { 1928 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2221 printk(KERN_WARNING "STALLION: Warning, board %d I/O address " 1929 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2222 "%x conflicts with another device\n", brdp->brdnr, 1930 "%x conflicts with another device\n", brdp->brdnr,
2223 brdp->ioaddr1); 1931 brdp->ioaddr1);
2224 return(-EBUSY); 1932 goto err;
2225 } 1933 }
2226 1934
2227 if (brdp->iosize2 > 0) 1935 if (brdp->iosize2 > 0)
@@ -2232,8 +1940,7 @@ static inline int stl_initeio(stlbrd_t *brdp)
2232 printk(KERN_WARNING "STALLION: Warning, also " 1940 printk(KERN_WARNING "STALLION: Warning, also "
2233 "releasing board %d I/O address %x \n", 1941 "releasing board %d I/O address %x \n",
2234 brdp->brdnr, brdp->ioaddr1); 1942 brdp->brdnr, brdp->ioaddr1);
2235 release_region(brdp->ioaddr1, brdp->iosize1); 1943 goto err_rel1;
2236 return(-EBUSY);
2237 } 1944 }
2238 1945
2239/* 1946/*
@@ -2242,6 +1949,7 @@ static inline int stl_initeio(stlbrd_t *brdp)
2242 brdp->clk = CD1400_CLK; 1949 brdp->clk = CD1400_CLK;
2243 brdp->isr = stl_eiointr; 1950 brdp->isr = stl_eiointr;
2244 1951
1952 retval = -ENODEV;
2245 switch (status & EIO_IDBITMASK) { 1953 switch (status & EIO_IDBITMASK) {
2246 case EIO_8PORTM: 1954 case EIO_8PORTM:
2247 brdp->clk = CD1400_CLK8M; 1955 brdp->clk = CD1400_CLK8M;
@@ -2265,11 +1973,11 @@ static inline int stl_initeio(stlbrd_t *brdp)
2265 brdp->nrports = 16; 1973 brdp->nrports = 16;
2266 break; 1974 break;
2267 default: 1975 default:
2268 return(-ENODEV); 1976 goto err_rel2;
2269 } 1977 }
2270 break; 1978 break;
2271 default: 1979 default:
2272 return(-ENODEV); 1980 goto err_rel2;
2273 } 1981 }
2274 1982
2275/* 1983/*
@@ -2277,11 +1985,12 @@ static inline int stl_initeio(stlbrd_t *brdp)
2277 * can complete the setup. 1985 * can complete the setup.
2278 */ 1986 */
2279 1987
2280 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL); 1988 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
2281 if (!panelp) { 1989 if (!panelp) {
2282 printk(KERN_WARNING "STALLION: failed to allocate memory " 1990 printk(KERN_WARNING "STALLION: failed to allocate memory "
2283 "(size=%Zd)\n", sizeof(stlpanel_t)); 1991 "(size=%Zd)\n", sizeof(struct stlpanel));
2284 return -ENOMEM; 1992 retval = -ENOMEM;
1993 goto err_rel2;
2285 } 1994 }
2286 1995
2287 panelp->magic = STL_PANELMAGIC; 1996 panelp->magic = STL_PANELMAGIC;
@@ -2291,10 +2000,10 @@ static inline int stl_initeio(stlbrd_t *brdp)
2291 panelp->iobase = brdp->ioaddr1; 2000 panelp->iobase = brdp->ioaddr1;
2292 panelp->hwid = status; 2001 panelp->hwid = status;
2293 if ((status & EIO_IDBITMASK) == EIO_MK3) { 2002 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2294 panelp->uartp = (void *) &stl_sc26198uart; 2003 panelp->uartp = &stl_sc26198uart;
2295 panelp->isr = stl_sc26198intr; 2004 panelp->isr = stl_sc26198intr;
2296 } else { 2005 } else {
2297 panelp->uartp = (void *) &stl_cd1400uart; 2006 panelp->uartp = &stl_cd1400uart;
2298 panelp->isr = stl_cd1400eiointr; 2007 panelp->isr = stl_cd1400eiointr;
2299 } 2008 }
2300 2009
@@ -2305,11 +2014,20 @@ static inline int stl_initeio(stlbrd_t *brdp)
2305 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) { 2014 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2306 printk("STALLION: failed to register interrupt " 2015 printk("STALLION: failed to register interrupt "
2307 "routine for %s irq=%d\n", name, brdp->irq); 2016 "routine for %s irq=%d\n", name, brdp->irq);
2308 rc = -ENODEV; 2017 retval = -ENODEV;
2309 } else { 2018 goto err_fr;
2310 rc = 0;
2311 } 2019 }
2312 return rc; 2020
2021 return 0;
2022err_fr:
2023 stl_cleanup_panels(brdp);
2024err_rel2:
2025 if (brdp->iosize2 > 0)
2026 release_region(brdp->ioaddr2, brdp->iosize2);
2027err_rel1:
2028 release_region(brdp->ioaddr1, brdp->iosize1);
2029err:
2030 return retval;
2313} 2031}
2314 2032
2315/*****************************************************************************/ 2033/*****************************************************************************/
@@ -2319,16 +2037,14 @@ static inline int stl_initeio(stlbrd_t *brdp)
2319 * dealing with all types of ECH board. 2037 * dealing with all types of ECH board.
2320 */ 2038 */
2321 2039
2322static inline int stl_initech(stlbrd_t *brdp) 2040static int __devinit stl_initech(struct stlbrd *brdp)
2323{ 2041{
2324 stlpanel_t *panelp; 2042 struct stlpanel *panelp;
2325 unsigned int status, nxtid, ioaddr, conflict; 2043 unsigned int status, nxtid, ioaddr, conflict, panelnr, banknr, i;
2326 int panelnr, banknr, i; 2044 int retval;
2327 char *name; 2045 char *name;
2328 2046
2329#ifdef DEBUG 2047 pr_debug("stl_initech(brdp=%p)\n", brdp);
2330 printk("stl_initech(brdp=%x)\n", (int) brdp);
2331#endif
2332 2048
2333 status = 0; 2049 status = 0;
2334 conflict = 0; 2050 conflict = 0;
@@ -2345,20 +2061,23 @@ static inline int stl_initech(stlbrd_t *brdp)
2345 brdp->ioctrl = brdp->ioaddr1 + 1; 2061 brdp->ioctrl = brdp->ioaddr1 + 1;
2346 brdp->iostatus = brdp->ioaddr1 + 1; 2062 brdp->iostatus = brdp->ioaddr1 + 1;
2347 status = inb(brdp->iostatus); 2063 status = inb(brdp->iostatus);
2348 if ((status & ECH_IDBITMASK) != ECH_ID) 2064 if ((status & ECH_IDBITMASK) != ECH_ID) {
2349 return(-ENODEV); 2065 retval = -ENODEV;
2066 goto err;
2067 }
2350 if ((brdp->irq < 0) || (brdp->irq > 15) || 2068 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2351 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) { 2069 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2352 printk("STALLION: invalid irq=%d for brd=%d\n", 2070 printk("STALLION: invalid irq=%d for brd=%d\n",
2353 brdp->irq, brdp->brdnr); 2071 brdp->irq, brdp->brdnr);
2354 return(-EINVAL); 2072 retval = -EINVAL;
2073 goto err;
2355 } 2074 }
2356 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1); 2075 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2357 status |= (stl_vecmap[brdp->irq] << 1); 2076 status |= (stl_vecmap[brdp->irq] << 1);
2358 outb((status | ECH_BRDRESET), brdp->ioaddr1); 2077 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2359 brdp->ioctrlval = ECH_INTENABLE | 2078 brdp->ioctrlval = ECH_INTENABLE |
2360 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE); 2079 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2361 for (i = 0; (i < 10); i++) 2080 for (i = 0; i < 10; i++)
2362 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl); 2081 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2363 brdp->iosize1 = 2; 2082 brdp->iosize1 = 2;
2364 brdp->iosize2 = 32; 2083 brdp->iosize2 = 32;
@@ -2371,13 +2090,16 @@ static inline int stl_initech(stlbrd_t *brdp)
2371 brdp->ioctrl = brdp->ioaddr1 + 0x20; 2090 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2372 brdp->iostatus = brdp->ioctrl; 2091 brdp->iostatus = brdp->ioctrl;
2373 status = inb(brdp->iostatus); 2092 status = inb(brdp->iostatus);
2374 if ((status & ECH_IDBITMASK) != ECH_ID) 2093 if ((status & ECH_IDBITMASK) != ECH_ID) {
2375 return(-ENODEV); 2094 retval = -ENODEV;
2095 goto err;
2096 }
2376 if ((brdp->irq < 0) || (brdp->irq > 15) || 2097 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2377 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) { 2098 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2378 printk("STALLION: invalid irq=%d for brd=%d\n", 2099 printk("STALLION: invalid irq=%d for brd=%d\n",
2379 brdp->irq, brdp->brdnr); 2100 brdp->irq, brdp->brdnr);
2380 return(-EINVAL); 2101 retval = -EINVAL;
2102 goto err;
2381 } 2103 }
2382 outb(ECHMC_BRDRESET, brdp->ioctrl); 2104 outb(ECHMC_BRDRESET, brdp->ioctrl);
2383 outb(ECHMC_INTENABLE, brdp->ioctrl); 2105 outb(ECHMC_INTENABLE, brdp->ioctrl);
@@ -2404,19 +2126,20 @@ static inline int stl_initech(stlbrd_t *brdp)
2404 2126
2405 default: 2127 default:
2406 printk("STALLION: unknown board type=%d\n", brdp->brdtype); 2128 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2407 return(-EINVAL); 2129 retval = -EINVAL;
2408 break; 2130 goto err;
2409 } 2131 }
2410 2132
2411/* 2133/*
2412 * Check boards for possible IO address conflicts and return fail status 2134 * Check boards for possible IO address conflicts and return fail status
2413 * if an IO conflict found. 2135 * if an IO conflict found.
2414 */ 2136 */
2137 retval = -EBUSY;
2415 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) { 2138 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2416 printk(KERN_WARNING "STALLION: Warning, board %d I/O address " 2139 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2417 "%x conflicts with another device\n", brdp->brdnr, 2140 "%x conflicts with another device\n", brdp->brdnr,
2418 brdp->ioaddr1); 2141 brdp->ioaddr1);
2419 return(-EBUSY); 2142 goto err;
2420 } 2143 }
2421 2144
2422 if (brdp->iosize2 > 0) 2145 if (brdp->iosize2 > 0)
@@ -2427,8 +2150,7 @@ static inline int stl_initech(stlbrd_t *brdp)
2427 printk(KERN_WARNING "STALLION: Warning, also " 2150 printk(KERN_WARNING "STALLION: Warning, also "
2428 "releasing board %d I/O address %x \n", 2151 "releasing board %d I/O address %x \n",
2429 brdp->brdnr, brdp->ioaddr1); 2152 brdp->brdnr, brdp->ioaddr1);
2430 release_region(brdp->ioaddr1, brdp->iosize1); 2153 goto err_rel1;
2431 return(-EBUSY);
2432 } 2154 }
2433 2155
2434/* 2156/*
@@ -2443,19 +2165,19 @@ static inline int stl_initech(stlbrd_t *brdp)
2443 panelnr = 0; 2165 panelnr = 0;
2444 nxtid = 0; 2166 nxtid = 0;
2445 2167
2446 for (i = 0; (i < STL_MAXPANELS); i++) { 2168 for (i = 0; i < STL_MAXPANELS; i++) {
2447 if (brdp->brdtype == BRD_ECHPCI) { 2169 if (brdp->brdtype == BRD_ECHPCI) {
2448 outb(nxtid, brdp->ioctrl); 2170 outb(nxtid, brdp->ioctrl);
2449 ioaddr = brdp->ioaddr2; 2171 ioaddr = brdp->ioaddr2;
2450 } 2172 }
2451 status = inb(ioaddr + ECH_PNLSTATUS); 2173 status = inb(ioaddr + ECH_PNLSTATUS);
2452 if ((status & ECH_PNLIDMASK) != nxtid) 2174 if ((status & ECH_PNLIDMASK) != nxtid)
2453 break; 2175 goto err_fr;
2454 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL); 2176 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
2455 if (!panelp) { 2177 if (!panelp) {
2456 printk("STALLION: failed to allocate memory " 2178 printk("STALLION: failed to allocate memory "
2457 "(size=%Zd)\n", sizeof(stlpanel_t)); 2179 "(size=%Zd)\n", sizeof(struct stlpanel));
2458 break; 2180 goto err_fr;
2459 } 2181 }
2460 panelp->magic = STL_PANELMAGIC; 2182 panelp->magic = STL_PANELMAGIC;
2461 panelp->brdnr = brdp->brdnr; 2183 panelp->brdnr = brdp->brdnr;
@@ -2468,7 +2190,7 @@ static inline int stl_initech(stlbrd_t *brdp)
2468 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS; 2190 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2469 2191
2470 if (status & ECH_PNLXPID) { 2192 if (status & ECH_PNLXPID) {
2471 panelp->uartp = (void *) &stl_sc26198uart; 2193 panelp->uartp = &stl_sc26198uart;
2472 panelp->isr = stl_sc26198intr; 2194 panelp->isr = stl_sc26198intr;
2473 if (status & ECH_PNL16PORT) { 2195 if (status & ECH_PNL16PORT) {
2474 panelp->nrports = 16; 2196 panelp->nrports = 16;
@@ -2476,11 +2198,10 @@ static inline int stl_initech(stlbrd_t *brdp)
2476 brdp->bnkpageaddr[banknr] = nxtid; 2198 brdp->bnkpageaddr[banknr] = nxtid;
2477 brdp->bnkstataddr[banknr++] = ioaddr + 4 + 2199 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2478 ECH_PNLSTATUS; 2200 ECH_PNLSTATUS;
2479 } else { 2201 } else
2480 panelp->nrports = 8; 2202 panelp->nrports = 8;
2481 }
2482 } else { 2203 } else {
2483 panelp->uartp = (void *) &stl_cd1400uart; 2204 panelp->uartp = &stl_cd1400uart;
2484 panelp->isr = stl_cd1400echintr; 2205 panelp->isr = stl_cd1400echintr;
2485 if (status & ECH_PNL16PORT) { 2206 if (status & ECH_PNL16PORT) {
2486 panelp->nrports = 16; 2207 panelp->nrports = 16;
@@ -2503,7 +2224,7 @@ static inline int stl_initech(stlbrd_t *brdp)
2503 brdp->panels[panelnr++] = panelp; 2224 brdp->panels[panelnr++] = panelp;
2504 if ((brdp->brdtype != BRD_ECHPCI) && 2225 if ((brdp->brdtype != BRD_ECHPCI) &&
2505 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2))) 2226 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2506 break; 2227 goto err_fr;
2507 } 2228 }
2508 2229
2509 brdp->nrpanels = panelnr; 2230 brdp->nrpanels = panelnr;
@@ -2515,12 +2236,19 @@ static inline int stl_initech(stlbrd_t *brdp)
2515 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) { 2236 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2516 printk("STALLION: failed to register interrupt " 2237 printk("STALLION: failed to register interrupt "
2517 "routine for %s irq=%d\n", name, brdp->irq); 2238 "routine for %s irq=%d\n", name, brdp->irq);
2518 i = -ENODEV; 2239 retval = -ENODEV;
2519 } else { 2240 goto err_fr;
2520 i = 0;
2521 } 2241 }
2522 2242
2523 return(i); 2243 return 0;
2244err_fr:
2245 stl_cleanup_panels(brdp);
2246 if (brdp->iosize2 > 0)
2247 release_region(brdp->ioaddr2, brdp->iosize2);
2248err_rel1:
2249 release_region(brdp->ioaddr1, brdp->iosize1);
2250err:
2251 return retval;
2524} 2252}
2525 2253
2526/*****************************************************************************/ 2254/*****************************************************************************/
@@ -2532,48 +2260,61 @@ static inline int stl_initech(stlbrd_t *brdp)
2532 * since the initial search and setup is very different. 2260 * since the initial search and setup is very different.
2533 */ 2261 */
2534 2262
2535static int __init stl_brdinit(stlbrd_t *brdp) 2263static int __devinit stl_brdinit(struct stlbrd *brdp)
2536{ 2264{
2537 int i; 2265 int i, retval;
2538 2266
2539#ifdef DEBUG 2267 pr_debug("stl_brdinit(brdp=%p)\n", brdp);
2540 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2541#endif
2542 2268
2543 switch (brdp->brdtype) { 2269 switch (brdp->brdtype) {
2544 case BRD_EASYIO: 2270 case BRD_EASYIO:
2545 case BRD_EASYIOPCI: 2271 case BRD_EASYIOPCI:
2546 stl_initeio(brdp); 2272 retval = stl_initeio(brdp);
2273 if (retval)
2274 goto err;
2547 break; 2275 break;
2548 case BRD_ECH: 2276 case BRD_ECH:
2549 case BRD_ECHMC: 2277 case BRD_ECHMC:
2550 case BRD_ECHPCI: 2278 case BRD_ECHPCI:
2551 case BRD_ECH64PCI: 2279 case BRD_ECH64PCI:
2552 stl_initech(brdp); 2280 retval = stl_initech(brdp);
2281 if (retval)
2282 goto err;
2553 break; 2283 break;
2554 default: 2284 default:
2555 printk("STALLION: board=%d is unknown board type=%d\n", 2285 printk("STALLION: board=%d is unknown board type=%d\n",
2556 brdp->brdnr, brdp->brdtype); 2286 brdp->brdnr, brdp->brdtype);
2557 return(ENODEV); 2287 retval = -ENODEV;
2288 goto err;
2558 } 2289 }
2559 2290
2560 stl_brds[brdp->brdnr] = brdp;
2561 if ((brdp->state & BRD_FOUND) == 0) { 2291 if ((brdp->state & BRD_FOUND) == 0) {
2562 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n", 2292 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2563 stl_brdnames[brdp->brdtype], brdp->brdnr, 2293 stl_brdnames[brdp->brdtype], brdp->brdnr,
2564 brdp->ioaddr1, brdp->irq); 2294 brdp->ioaddr1, brdp->irq);
2565 return(ENODEV); 2295 goto err_free;
2566 } 2296 }
2567 2297
2568 for (i = 0; (i < STL_MAXPANELS); i++) 2298 for (i = 0; i < STL_MAXPANELS; i++)
2569 if (brdp->panels[i] != (stlpanel_t *) NULL) 2299 if (brdp->panels[i] != NULL)
2570 stl_initports(brdp, brdp->panels[i]); 2300 stl_initports(brdp, brdp->panels[i]);
2571 2301
2572 printk("STALLION: %s found, board=%d io=%x irq=%d " 2302 printk("STALLION: %s found, board=%d io=%x irq=%d "
2573 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype], 2303 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2574 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels, 2304 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2575 brdp->nrports); 2305 brdp->nrports);
2576 return(0); 2306
2307 return 0;
2308err_free:
2309 free_irq(brdp->irq, brdp);
2310
2311 stl_cleanup_panels(brdp);
2312
2313 release_region(brdp->ioaddr1, brdp->iosize1);
2314 if (brdp->iosize2 > 0)
2315 release_region(brdp->ioaddr2, brdp->iosize2);
2316err:
2317 return retval;
2577} 2318}
2578 2319
2579/*****************************************************************************/ 2320/*****************************************************************************/
@@ -2582,59 +2323,62 @@ static int __init stl_brdinit(stlbrd_t *brdp)
2582 * Find the next available board number that is free. 2323 * Find the next available board number that is free.
2583 */ 2324 */
2584 2325
2585static inline int stl_getbrdnr(void) 2326static int __devinit stl_getbrdnr(void)
2586{ 2327{
2587 int i; 2328 unsigned int i;
2588 2329
2589 for (i = 0; (i < STL_MAXBRDS); i++) { 2330 for (i = 0; i < STL_MAXBRDS; i++)
2590 if (stl_brds[i] == (stlbrd_t *) NULL) { 2331 if (stl_brds[i] == NULL) {
2591 if (i >= stl_nrbrds) 2332 if (i >= stl_nrbrds)
2592 stl_nrbrds = i + 1; 2333 stl_nrbrds = i + 1;
2593 return(i); 2334 return i;
2594 } 2335 }
2595 } 2336
2596 return(-1); 2337 return -1;
2597} 2338}
2598 2339
2599/*****************************************************************************/ 2340/*****************************************************************************/
2600
2601#ifdef CONFIG_PCI
2602
2603/* 2341/*
2604 * We have a Stallion board. Allocate a board structure and 2342 * We have a Stallion board. Allocate a board structure and
2605 * initialize it. Read its IO and IRQ resources from PCI 2343 * initialize it. Read its IO and IRQ resources from PCI
2606 * configuration space. 2344 * configuration space.
2607 */ 2345 */
2608 2346
2609static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp) 2347static int __devinit stl_pciprobe(struct pci_dev *pdev,
2348 const struct pci_device_id *ent)
2610{ 2349{
2611 stlbrd_t *brdp; 2350 struct stlbrd *brdp;
2612 2351 unsigned int i, brdtype = ent->driver_data;
2613#ifdef DEBUG 2352 int brdnr, retval = -ENODEV;
2614 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype, 2353
2615 devp->bus->number, devp->devfn); 2354 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2616#endif 2355 goto err;
2617 2356
2618 if (pci_enable_device(devp)) 2357 dev_info(&pdev->dev, "please, report this to LKML: %x/%x/%x\n",
2619 return(-EIO); 2358 pdev->vendor, pdev->device, pdev->class);
2620 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL) 2359
2621 return(-ENOMEM); 2360 retval = pci_enable_device(pdev);
2622 if ((brdp->brdnr = stl_getbrdnr()) < 0) { 2361 if (retval)
2623 printk("STALLION: too many boards found, " 2362 goto err;
2363 brdp = stl_allocbrd();
2364 if (brdp == NULL) {
2365 retval = -ENOMEM;
2366 goto err;
2367 }
2368 mutex_lock(&stl_brdslock);
2369 brdnr = stl_getbrdnr();
2370 if (brdnr < 0) {
2371 dev_err(&pdev->dev, "too many boards found, "
2624 "maximum supported %d\n", STL_MAXBRDS); 2372 "maximum supported %d\n", STL_MAXBRDS);
2625 return(0); 2373 mutex_unlock(&stl_brdslock);
2374 goto err_fr;
2626 } 2375 }
2627 brdp->brdtype = brdtype; 2376 brdp->brdnr = (unsigned int)brdnr;
2377 stl_brds[brdp->brdnr] = brdp;
2378 mutex_unlock(&stl_brdslock);
2628 2379
2629/* 2380 brdp->brdtype = brdtype;
2630 * Different Stallion boards use the BAR registers in different ways, 2381 brdp->state |= STL_PROBED;
2631 * so set up io addresses based on board type.
2632 */
2633#ifdef DEBUG
2634 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
2635 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2636 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2637#endif
2638 2382
2639/* 2383/*
2640 * We have all resources from the board, so let's setup the actual 2384 * We have all resources from the board, so let's setup the actual
@@ -2642,120 +2386,70 @@ static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2642 */ 2386 */
2643 switch (brdtype) { 2387 switch (brdtype) {
2644 case BRD_ECHPCI: 2388 case BRD_ECHPCI:
2645 brdp->ioaddr2 = pci_resource_start(devp, 0); 2389 brdp->ioaddr2 = pci_resource_start(pdev, 0);
2646 brdp->ioaddr1 = pci_resource_start(devp, 1); 2390 brdp->ioaddr1 = pci_resource_start(pdev, 1);
2647 break; 2391 break;
2648 case BRD_ECH64PCI: 2392 case BRD_ECH64PCI:
2649 brdp->ioaddr2 = pci_resource_start(devp, 2); 2393 brdp->ioaddr2 = pci_resource_start(pdev, 2);
2650 brdp->ioaddr1 = pci_resource_start(devp, 1); 2394 brdp->ioaddr1 = pci_resource_start(pdev, 1);
2651 break; 2395 break;
2652 case BRD_EASYIOPCI: 2396 case BRD_EASYIOPCI:
2653 brdp->ioaddr1 = pci_resource_start(devp, 2); 2397 brdp->ioaddr1 = pci_resource_start(pdev, 2);
2654 brdp->ioaddr2 = pci_resource_start(devp, 1); 2398 brdp->ioaddr2 = pci_resource_start(pdev, 1);
2655 break; 2399 break;
2656 default: 2400 default:
2657 printk("STALLION: unknown PCI board type=%d\n", brdtype); 2401 dev_err(&pdev->dev, "unknown PCI board type=%u\n", brdtype);
2658 break; 2402 break;
2659 } 2403 }
2660 2404
2661 brdp->irq = devp->irq; 2405 brdp->irq = pdev->irq;
2662 stl_brdinit(brdp); 2406 retval = stl_brdinit(brdp);
2663 2407 if (retval)
2664 return(0); 2408 goto err_null;
2665}
2666
2667/*****************************************************************************/
2668
2669/*
2670 * Find all Stallion PCI boards that might be installed. Initialize each
2671 * one as it is found.
2672 */
2673
2674 2409
2675static inline int stl_findpcibrds(void) 2410 pci_set_drvdata(pdev, brdp);
2676{
2677 struct pci_dev *dev = NULL;
2678 int i, rc;
2679 2411
2680#ifdef DEBUG 2412 for (i = 0; i < brdp->nrports; i++)
2681 printk("stl_findpcibrds()\n"); 2413 tty_register_device(stl_serial,
2682#endif 2414 brdp->brdnr * STL_MAXPORTS + i, &pdev->dev);
2683 2415
2684 for (i = 0; (i < stl_nrpcibrds); i++) 2416 return 0;
2685 while ((dev = pci_find_device(stl_pcibrds[i].vendid, 2417err_null:
2686 stl_pcibrds[i].devid, dev))) { 2418 stl_brds[brdp->brdnr] = NULL;
2687 2419err_fr:
2688/* 2420 kfree(brdp);
2689 * Found a device on the PCI bus that has our vendor and 2421err:
2690 * device ID. Need to check now that it is really us. 2422 return retval;
2691 */
2692 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2693 continue;
2694
2695 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2696 if (rc)
2697 return(rc);
2698 }
2699
2700 return(0);
2701} 2423}
2702 2424
2703#endif 2425static void __devexit stl_pciremove(struct pci_dev *pdev)
2704
2705/*****************************************************************************/
2706
2707/*
2708 * Scan through all the boards in the configuration and see what we
2709 * can find. Handle EIO and the ECH boards a little differently here
2710 * since the initial search and setup is too different.
2711 */
2712
2713static inline int stl_initbrds(void)
2714{ 2426{
2715 stlbrd_t *brdp; 2427 struct stlbrd *brdp = pci_get_drvdata(pdev);
2716 stlconf_t *confp; 2428 unsigned int i;
2717 int i;
2718 2429
2719#ifdef DEBUG 2430 free_irq(brdp->irq, brdp);
2720 printk("stl_initbrds()\n");
2721#endif
2722 2431
2723 if (stl_nrbrds > STL_MAXBRDS) { 2432 stl_cleanup_panels(brdp);
2724 printk("STALLION: too many boards in configuration table, "
2725 "truncating to %d\n", STL_MAXBRDS);
2726 stl_nrbrds = STL_MAXBRDS;
2727 }
2728 2433
2729/* 2434 release_region(brdp->ioaddr1, brdp->iosize1);
2730 * Firstly scan the list of static boards configured. Allocate 2435 if (brdp->iosize2 > 0)
2731 * resources and initialize the boards as found. 2436 release_region(brdp->ioaddr2, brdp->iosize2);
2732 */
2733 for (i = 0; (i < stl_nrbrds); i++) {
2734 confp = &stl_brdconf[i];
2735 stl_parsebrd(confp, stl_brdsp[i]);
2736 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2737 return(-ENOMEM);
2738 brdp->brdnr = i;
2739 brdp->brdtype = confp->brdtype;
2740 brdp->ioaddr1 = confp->ioaddr1;
2741 brdp->ioaddr2 = confp->ioaddr2;
2742 brdp->irq = confp->irq;
2743 brdp->irqtype = confp->irqtype;
2744 stl_brdinit(brdp);
2745 }
2746 2437
2747/* 2438 for (i = 0; i < brdp->nrports; i++)
2748 * Find any dynamically supported boards. That is via module load 2439 tty_unregister_device(stl_serial,
2749 * line options or auto-detected on the PCI bus. 2440 brdp->brdnr * STL_MAXPORTS + i);
2750 */
2751 stl_argbrds();
2752#ifdef CONFIG_PCI
2753 stl_findpcibrds();
2754#endif
2755 2441
2756 return(0); 2442 stl_brds[brdp->brdnr] = NULL;
2443 kfree(brdp);
2757} 2444}
2758 2445
2446static struct pci_driver stl_pcidriver = {
2447 .name = "stallion",
2448 .id_table = stl_pcibrds,
2449 .probe = stl_pciprobe,
2450 .remove = __devexit_p(stl_pciremove)
2451};
2452
2759/*****************************************************************************/ 2453/*****************************************************************************/
2760 2454
2761/* 2455/*
@@ -2764,17 +2458,18 @@ static inline int stl_initbrds(void)
2764 2458
2765static int stl_getbrdstats(combrd_t __user *bp) 2459static int stl_getbrdstats(combrd_t __user *bp)
2766{ 2460{
2767 stlbrd_t *brdp; 2461 combrd_t stl_brdstats;
2768 stlpanel_t *panelp; 2462 struct stlbrd *brdp;
2769 int i; 2463 struct stlpanel *panelp;
2464 unsigned int i;
2770 2465
2771 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t))) 2466 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2772 return -EFAULT; 2467 return -EFAULT;
2773 if (stl_brdstats.brd >= STL_MAXBRDS) 2468 if (stl_brdstats.brd >= STL_MAXBRDS)
2774 return(-ENODEV); 2469 return -ENODEV;
2775 brdp = stl_brds[stl_brdstats.brd]; 2470 brdp = stl_brds[stl_brdstats.brd];
2776 if (brdp == (stlbrd_t *) NULL) 2471 if (brdp == NULL)
2777 return(-ENODEV); 2472 return -ENODEV;
2778 2473
2779 memset(&stl_brdstats, 0, sizeof(combrd_t)); 2474 memset(&stl_brdstats, 0, sizeof(combrd_t));
2780 stl_brdstats.brd = brdp->brdnr; 2475 stl_brdstats.brd = brdp->brdnr;
@@ -2786,7 +2481,7 @@ static int stl_getbrdstats(combrd_t __user *bp)
2786 stl_brdstats.irq = brdp->irq; 2481 stl_brdstats.irq = brdp->irq;
2787 stl_brdstats.nrpanels = brdp->nrpanels; 2482 stl_brdstats.nrpanels = brdp->nrpanels;
2788 stl_brdstats.nrports = brdp->nrports; 2483 stl_brdstats.nrports = brdp->nrports;
2789 for (i = 0; (i < brdp->nrpanels); i++) { 2484 for (i = 0; i < brdp->nrpanels; i++) {
2790 panelp = brdp->panels[i]; 2485 panelp = brdp->panels[i];
2791 stl_brdstats.panels[i].panel = i; 2486 stl_brdstats.panels[i].panel = i;
2792 stl_brdstats.panels[i].hwid = panelp->hwid; 2487 stl_brdstats.panels[i].hwid = panelp->hwid;
@@ -2802,24 +2497,24 @@ static int stl_getbrdstats(combrd_t __user *bp)
2802 * Resolve the referenced port number into a port struct pointer. 2497 * Resolve the referenced port number into a port struct pointer.
2803 */ 2498 */
2804 2499
2805static stlport_t *stl_getport(int brdnr, int panelnr, int portnr) 2500static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
2806{ 2501{
2807 stlbrd_t *brdp; 2502 struct stlbrd *brdp;
2808 stlpanel_t *panelp; 2503 struct stlpanel *panelp;
2809 2504
2810 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS)) 2505 if (brdnr < 0 || brdnr >= STL_MAXBRDS)
2811 return((stlport_t *) NULL); 2506 return NULL;
2812 brdp = stl_brds[brdnr]; 2507 brdp = stl_brds[brdnr];
2813 if (brdp == (stlbrd_t *) NULL) 2508 if (brdp == NULL)
2814 return((stlport_t *) NULL); 2509 return NULL;
2815 if ((panelnr < 0) || (panelnr >= brdp->nrpanels)) 2510 if (panelnr < 0 || (unsigned int)panelnr >= brdp->nrpanels)
2816 return((stlport_t *) NULL); 2511 return NULL;
2817 panelp = brdp->panels[panelnr]; 2512 panelp = brdp->panels[panelnr];
2818 if (panelp == (stlpanel_t *) NULL) 2513 if (panelp == NULL)
2819 return((stlport_t *) NULL); 2514 return NULL;
2820 if ((portnr < 0) || (portnr >= panelp->nrports)) 2515 if (portnr < 0 || (unsigned int)portnr >= panelp->nrports)
2821 return((stlport_t *) NULL); 2516 return NULL;
2822 return(panelp->ports[portnr]); 2517 return panelp->ports[portnr];
2823} 2518}
2824 2519
2825/*****************************************************************************/ 2520/*****************************************************************************/
@@ -2830,8 +2525,9 @@ static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2830 * what port to get stats for (used through board control device). 2525 * what port to get stats for (used through board control device).
2831 */ 2526 */
2832 2527
2833static int stl_getportstats(stlport_t *portp, comstats_t __user *cp) 2528static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
2834{ 2529{
2530 comstats_t stl_comstats;
2835 unsigned char *head, *tail; 2531 unsigned char *head, *tail;
2836 unsigned long flags; 2532 unsigned long flags;
2837 2533
@@ -2840,8 +2536,8 @@ static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2840 return -EFAULT; 2536 return -EFAULT;
2841 portp = stl_getport(stl_comstats.brd, stl_comstats.panel, 2537 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2842 stl_comstats.port); 2538 stl_comstats.port);
2843 if (portp == (stlport_t *) NULL) 2539 if (portp == NULL)
2844 return(-ENODEV); 2540 return -ENODEV;
2845 } 2541 }
2846 2542
2847 portp->stats.state = portp->istate; 2543 portp->stats.state = portp->istate;
@@ -2856,25 +2552,24 @@ static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2856 portp->stats.rxbuffered = 0; 2552 portp->stats.rxbuffered = 0;
2857 2553
2858 spin_lock_irqsave(&stallion_lock, flags); 2554 spin_lock_irqsave(&stallion_lock, flags);
2859 if (portp->tty != (struct tty_struct *) NULL) { 2555 if (portp->tty != NULL)
2860 if (portp->tty->driver_data == portp) { 2556 if (portp->tty->driver_data == portp) {
2861 portp->stats.ttystate = portp->tty->flags; 2557 portp->stats.ttystate = portp->tty->flags;
2862 /* No longer available as a statistic */ 2558 /* No longer available as a statistic */
2863 portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */ 2559 portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
2864 if (portp->tty->termios != (struct termios *) NULL) { 2560 if (portp->tty->termios != NULL) {
2865 portp->stats.cflags = portp->tty->termios->c_cflag; 2561 portp->stats.cflags = portp->tty->termios->c_cflag;
2866 portp->stats.iflags = portp->tty->termios->c_iflag; 2562 portp->stats.iflags = portp->tty->termios->c_iflag;
2867 portp->stats.oflags = portp->tty->termios->c_oflag; 2563 portp->stats.oflags = portp->tty->termios->c_oflag;
2868 portp->stats.lflags = portp->tty->termios->c_lflag; 2564 portp->stats.lflags = portp->tty->termios->c_lflag;
2869 } 2565 }
2870 } 2566 }
2871 }
2872 spin_unlock_irqrestore(&stallion_lock, flags); 2567 spin_unlock_irqrestore(&stallion_lock, flags);
2873 2568
2874 head = portp->tx.head; 2569 head = portp->tx.head;
2875 tail = portp->tx.tail; 2570 tail = portp->tx.tail;
2876 portp->stats.txbuffered = ((head >= tail) ? (head - tail) : 2571 portp->stats.txbuffered = (head >= tail) ? (head - tail) :
2877 (STL_TXBUFSIZE - (tail - head))); 2572 (STL_TXBUFSIZE - (tail - head));
2878 2573
2879 portp->stats.signals = (unsigned long) stl_getsignals(portp); 2574 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2880 2575
@@ -2888,15 +2583,17 @@ static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2888 * Clear the port stats structure. We also return it zeroed out... 2583 * Clear the port stats structure. We also return it zeroed out...
2889 */ 2584 */
2890 2585
2891static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp) 2586static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
2892{ 2587{
2588 comstats_t stl_comstats;
2589
2893 if (!portp) { 2590 if (!portp) {
2894 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t))) 2591 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2895 return -EFAULT; 2592 return -EFAULT;
2896 portp = stl_getport(stl_comstats.brd, stl_comstats.panel, 2593 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2897 stl_comstats.port); 2594 stl_comstats.port);
2898 if (portp == (stlport_t *) NULL) 2595 if (portp == NULL)
2899 return(-ENODEV); 2596 return -ENODEV;
2900 } 2597 }
2901 2598
2902 memset(&portp->stats, 0, sizeof(comstats_t)); 2599 memset(&portp->stats, 0, sizeof(comstats_t));
@@ -2913,17 +2610,18 @@ static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp)
2913 * Return the entire driver ports structure to a user app. 2610 * Return the entire driver ports structure to a user app.
2914 */ 2611 */
2915 2612
2916static int stl_getportstruct(stlport_t __user *arg) 2613static int stl_getportstruct(struct stlport __user *arg)
2917{ 2614{
2918 stlport_t *portp; 2615 struct stlport stl_dummyport;
2616 struct stlport *portp;
2919 2617
2920 if (copy_from_user(&stl_dummyport, arg, sizeof(stlport_t))) 2618 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
2921 return -EFAULT; 2619 return -EFAULT;
2922 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr, 2620 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2923 stl_dummyport.portnr); 2621 stl_dummyport.portnr);
2924 if (!portp) 2622 if (!portp)
2925 return -ENODEV; 2623 return -ENODEV;
2926 return copy_to_user(arg, portp, sizeof(stlport_t)) ? -EFAULT : 0; 2624 return copy_to_user(arg, portp, sizeof(struct stlport)) ? -EFAULT : 0;
2927} 2625}
2928 2626
2929/*****************************************************************************/ 2627/*****************************************************************************/
@@ -2932,18 +2630,19 @@ static int stl_getportstruct(stlport_t __user *arg)
2932 * Return the entire driver board structure to a user app. 2630 * Return the entire driver board structure to a user app.
2933 */ 2631 */
2934 2632
2935static int stl_getbrdstruct(stlbrd_t __user *arg) 2633static int stl_getbrdstruct(struct stlbrd __user *arg)
2936{ 2634{
2937 stlbrd_t *brdp; 2635 struct stlbrd stl_dummybrd;
2636 struct stlbrd *brdp;
2938 2637
2939 if (copy_from_user(&stl_dummybrd, arg, sizeof(stlbrd_t))) 2638 if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd)))
2940 return -EFAULT; 2639 return -EFAULT;
2941 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS)) 2640 if (stl_dummybrd.brdnr >= STL_MAXBRDS)
2942 return -ENODEV; 2641 return -ENODEV;
2943 brdp = stl_brds[stl_dummybrd.brdnr]; 2642 brdp = stl_brds[stl_dummybrd.brdnr];
2944 if (!brdp) 2643 if (!brdp)
2945 return(-ENODEV); 2644 return -ENODEV;
2946 return copy_to_user(arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0; 2645 return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0;
2947} 2646}
2948 2647
2949/*****************************************************************************/ 2648/*****************************************************************************/
@@ -2959,14 +2658,11 @@ static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, uns
2959 int brdnr, rc; 2658 int brdnr, rc;
2960 void __user *argp = (void __user *)arg; 2659 void __user *argp = (void __user *)arg;
2961 2660
2962#ifdef DEBUG 2661 pr_debug("stl_memioctl(ip=%p,fp=%p,cmd=%x,arg=%lx)\n", ip, fp, cmd,arg);
2963 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
2964 (int) fp, cmd, (int) arg);
2965#endif
2966 2662
2967 brdnr = iminor(ip); 2663 brdnr = iminor(ip);
2968 if (brdnr >= STL_MAXBRDS) 2664 if (brdnr >= STL_MAXBRDS)
2969 return(-ENODEV); 2665 return -ENODEV;
2970 rc = 0; 2666 rc = 0;
2971 2667
2972 switch (cmd) { 2668 switch (cmd) {
@@ -2990,10 +2686,10 @@ static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, uns
2990 break; 2686 break;
2991 } 2687 }
2992 2688
2993 return(rc); 2689 return rc;
2994} 2690}
2995 2691
2996static struct tty_operations stl_ops = { 2692static const struct tty_operations stl_ops = {
2997 .open = stl_open, 2693 .open = stl_open,
2998 .close = stl_close, 2694 .close = stl_close,
2999 .write = stl_write, 2695 .write = stl_write,
@@ -3018,55 +2714,6 @@ static struct tty_operations stl_ops = {
3018}; 2714};
3019 2715
3020/*****************************************************************************/ 2716/*****************************************************************************/
3021
3022static int __init stl_init(void)
3023{
3024 int i;
3025 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3026
3027 spin_lock_init(&stallion_lock);
3028 spin_lock_init(&brd_lock);
3029
3030 stl_initbrds();
3031
3032 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
3033 if (!stl_serial)
3034 return -1;
3035
3036/*
3037 * Set up a character driver for per board stuff. This is mainly used
3038 * to do stats ioctls on the ports.
3039 */
3040 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
3041 printk("STALLION: failed to register serial board device\n");
3042
3043 stallion_class = class_create(THIS_MODULE, "staliomem");
3044 for (i = 0; i < 4; i++)
3045 class_device_create(stallion_class, NULL,
3046 MKDEV(STL_SIOMEMMAJOR, i), NULL,
3047 "staliomem%d", i);
3048
3049 stl_serial->owner = THIS_MODULE;
3050 stl_serial->driver_name = stl_drvname;
3051 stl_serial->name = "ttyE";
3052 stl_serial->major = STL_SERIALMAJOR;
3053 stl_serial->minor_start = 0;
3054 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
3055 stl_serial->subtype = SERIAL_TYPE_NORMAL;
3056 stl_serial->init_termios = stl_deftermios;
3057 stl_serial->flags = TTY_DRIVER_REAL_RAW;
3058 tty_set_operations(stl_serial, &stl_ops);
3059
3060 if (tty_register_driver(stl_serial)) {
3061 put_tty_driver(stl_serial);
3062 printk("STALLION: failed to register serial driver\n");
3063 return -1;
3064 }
3065
3066 return 0;
3067}
3068
3069/*****************************************************************************/
3070/* CD1400 HARDWARE FUNCTIONS */ 2717/* CD1400 HARDWARE FUNCTIONS */
3071/*****************************************************************************/ 2718/*****************************************************************************/
3072 2719
@@ -3076,21 +2723,21 @@ static int __init stl_init(void)
3076 * (Maybe should make this inline...) 2723 * (Maybe should make this inline...)
3077 */ 2724 */
3078 2725
3079static int stl_cd1400getreg(stlport_t *portp, int regnr) 2726static int stl_cd1400getreg(struct stlport *portp, int regnr)
3080{ 2727{
3081 outb((regnr + portp->uartaddr), portp->ioaddr); 2728 outb((regnr + portp->uartaddr), portp->ioaddr);
3082 return inb(portp->ioaddr + EREG_DATA); 2729 return inb(portp->ioaddr + EREG_DATA);
3083} 2730}
3084 2731
3085static void stl_cd1400setreg(stlport_t *portp, int regnr, int value) 2732static void stl_cd1400setreg(struct stlport *portp, int regnr, int value)
3086{ 2733{
3087 outb((regnr + portp->uartaddr), portp->ioaddr); 2734 outb(regnr + portp->uartaddr, portp->ioaddr);
3088 outb(value, portp->ioaddr + EREG_DATA); 2735 outb(value, portp->ioaddr + EREG_DATA);
3089} 2736}
3090 2737
3091static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value) 2738static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value)
3092{ 2739{
3093 outb((regnr + portp->uartaddr), portp->ioaddr); 2740 outb(regnr + portp->uartaddr, portp->ioaddr);
3094 if (inb(portp->ioaddr + EREG_DATA) != value) { 2741 if (inb(portp->ioaddr + EREG_DATA) != value) {
3095 outb(value, portp->ioaddr + EREG_DATA); 2742 outb(value, portp->ioaddr + EREG_DATA);
3096 return 1; 2743 return 1;
@@ -3106,16 +2753,14 @@ static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3106 * identical when dealing with ports. 2753 * identical when dealing with ports.
3107 */ 2754 */
3108 2755
3109static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp) 2756static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
3110{ 2757{
3111 unsigned int gfrcr; 2758 unsigned int gfrcr;
3112 int chipmask, i, j; 2759 int chipmask, i, j;
3113 int nrchips, uartaddr, ioaddr; 2760 int nrchips, uartaddr, ioaddr;
3114 unsigned long flags; 2761 unsigned long flags;
3115 2762
3116#ifdef DEBUG 2763 pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
3117 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3118#endif
3119 2764
3120 spin_lock_irqsave(&brd_lock, flags); 2765 spin_lock_irqsave(&brd_lock, flags);
3121 BRDENABLE(panelp->brdnr, panelp->pagenr); 2766 BRDENABLE(panelp->brdnr, panelp->pagenr);
@@ -3125,13 +2770,12 @@ static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3125 */ 2770 */
3126 chipmask = 0; 2771 chipmask = 0;
3127 nrchips = panelp->nrports / CD1400_PORTS; 2772 nrchips = panelp->nrports / CD1400_PORTS;
3128 for (i = 0; (i < nrchips); i++) { 2773 for (i = 0; i < nrchips; i++) {
3129 if (brdp->brdtype == BRD_ECHPCI) { 2774 if (brdp->brdtype == BRD_ECHPCI) {
3130 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl); 2775 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3131 ioaddr = panelp->iobase; 2776 ioaddr = panelp->iobase;
3132 } else { 2777 } else
3133 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1)); 2778 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3134 }
3135 uartaddr = (i & 0x01) ? 0x080 : 0; 2779 uartaddr = (i & 0x01) ? 0x080 : 0;
3136 outb((GFRCR + uartaddr), ioaddr); 2780 outb((GFRCR + uartaddr), ioaddr);
3137 outb(0, (ioaddr + EREG_DATA)); 2781 outb(0, (ioaddr + EREG_DATA));
@@ -3139,10 +2783,10 @@ static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3139 outb(CCR_RESETFULL, (ioaddr + EREG_DATA)); 2783 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3140 outb(CCR_RESETFULL, (ioaddr + EREG_DATA)); 2784 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3141 outb((GFRCR + uartaddr), ioaddr); 2785 outb((GFRCR + uartaddr), ioaddr);
3142 for (j = 0; (j < CCR_MAXWAIT); j++) { 2786 for (j = 0; j < CCR_MAXWAIT; j++)
3143 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0) 2787 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3144 break; 2788 break;
3145 } 2789
3146 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) { 2790 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3147 printk("STALLION: cd1400 not responding, " 2791 printk("STALLION: cd1400 not responding, "
3148 "brd=%d panel=%d chip=%d\n", 2792 "brd=%d panel=%d chip=%d\n",
@@ -3165,16 +2809,14 @@ static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3165 * Initialize hardware specific port registers. 2809 * Initialize hardware specific port registers.
3166 */ 2810 */
3167 2811
3168static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp) 2812static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
3169{ 2813{
3170 unsigned long flags; 2814 unsigned long flags;
3171#ifdef DEBUG 2815 pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
3172 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n", 2816 panelp, portp);
3173 (int) brdp, (int) panelp, (int) portp);
3174#endif
3175 2817
3176 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) || 2818 if ((brdp == NULL) || (panelp == NULL) ||
3177 (portp == (stlport_t *) NULL)) 2819 (portp == NULL))
3178 return; 2820 return;
3179 2821
3180 spin_lock_irqsave(&brd_lock, flags); 2822 spin_lock_irqsave(&brd_lock, flags);
@@ -3198,15 +2840,13 @@ static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *po
3198 * since it won't usually take too long to be ready. 2840 * since it won't usually take too long to be ready.
3199 */ 2841 */
3200 2842
3201static void stl_cd1400ccrwait(stlport_t *portp) 2843static void stl_cd1400ccrwait(struct stlport *portp)
3202{ 2844{
3203 int i; 2845 int i;
3204 2846
3205 for (i = 0; (i < CCR_MAXWAIT); i++) { 2847 for (i = 0; i < CCR_MAXWAIT; i++)
3206 if (stl_cd1400getreg(portp, CCR) == 0) { 2848 if (stl_cd1400getreg(portp, CCR) == 0)
3207 return; 2849 return;
3208 }
3209 }
3210 2850
3211 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n", 2851 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3212 portp->portnr, portp->panelnr, portp->brdnr); 2852 portp->portnr, portp->panelnr, portp->brdnr);
@@ -3219,9 +2859,9 @@ static void stl_cd1400ccrwait(stlport_t *portp)
3219 * settings. 2859 * settings.
3220 */ 2860 */
3221 2861
3222static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp) 2862static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp)
3223{ 2863{
3224 stlbrd_t *brdp; 2864 struct stlbrd *brdp;
3225 unsigned long flags; 2865 unsigned long flags;
3226 unsigned int clkdiv, baudrate; 2866 unsigned int clkdiv, baudrate;
3227 unsigned char cor1, cor2, cor3; 2867 unsigned char cor1, cor2, cor3;
@@ -3245,7 +2885,7 @@ static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3245 sreroff = 0; 2885 sreroff = 0;
3246 2886
3247 brdp = stl_brds[portp->brdnr]; 2887 brdp = stl_brds[portp->brdnr];
3248 if (brdp == (stlbrd_t *) NULL) 2888 if (brdp == NULL)
3249 return; 2889 return;
3250 2890
3251/* 2891/*
@@ -3342,8 +2982,8 @@ static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3342 baudrate = STL_CD1400MAXBAUD; 2982 baudrate = STL_CD1400MAXBAUD;
3343 2983
3344 if (baudrate > 0) { 2984 if (baudrate > 0) {
3345 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) { 2985 for (clk = 0; clk < CD1400_NUMCLKS; clk++) {
3346 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate); 2986 clkdiv = (portp->clk / stl_cd1400clkdivs[clk]) / baudrate;
3347 if (clkdiv < 0x100) 2987 if (clkdiv < 0x100)
3348 break; 2988 break;
3349 } 2989 }
@@ -3358,9 +2998,8 @@ static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3358 mcor2 |= MCOR2_DCD; 2998 mcor2 |= MCOR2_DCD;
3359 sreron |= SRER_MODEM; 2999 sreron |= SRER_MODEM;
3360 portp->flags |= ASYNC_CHECK_CD; 3000 portp->flags |= ASYNC_CHECK_CD;
3361 } else { 3001 } else
3362 portp->flags &= ~ASYNC_CHECK_CD; 3002 portp->flags &= ~ASYNC_CHECK_CD;
3363 }
3364 3003
3365/* 3004/*
3366 * Setup cd1400 enhanced modes if we can. In particular we want to 3005 * Setup cd1400 enhanced modes if we can. In particular we want to
@@ -3385,18 +3024,16 @@ static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3385 * them all up. 3024 * them all up.
3386 */ 3025 */
3387 3026
3388#ifdef DEBUG 3027 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3389 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3390 portp->portnr, portp->panelnr, portp->brdnr); 3028 portp->portnr, portp->panelnr, portp->brdnr);
3391 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n", 3029 pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3392 cor1, cor2, cor3, cor4, cor5); 3030 cor1, cor2, cor3, cor4, cor5);
3393 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n", 3031 pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3394 mcor1, mcor2, rtpr, sreron, sreroff); 3032 mcor1, mcor2, rtpr, sreron, sreroff);
3395 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div); 3033 pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3396 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n", 3034 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3397 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], 3035 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3398 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]); 3036 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3399#endif
3400 3037
3401 spin_lock_irqsave(&brd_lock, flags); 3038 spin_lock_irqsave(&brd_lock, flags);
3402 BRDENABLE(portp->brdnr, portp->pagenr); 3039 BRDENABLE(portp->brdnr, portp->pagenr);
@@ -3444,15 +3081,13 @@ static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3444 * Set the state of the DTR and RTS signals. 3081 * Set the state of the DTR and RTS signals.
3445 */ 3082 */
3446 3083
3447static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts) 3084static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts)
3448{ 3085{
3449 unsigned char msvr1, msvr2; 3086 unsigned char msvr1, msvr2;
3450 unsigned long flags; 3087 unsigned long flags;
3451 3088
3452#ifdef DEBUG 3089 pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n",
3453 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n", 3090 portp, dtr, rts);
3454 (int) portp, dtr, rts);
3455#endif
3456 3091
3457 msvr1 = 0; 3092 msvr1 = 0;
3458 msvr2 = 0; 3093 msvr2 = 0;
@@ -3478,15 +3113,13 @@ static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3478 * Return the state of the signals. 3113 * Return the state of the signals.
3479 */ 3114 */
3480 3115
3481static int stl_cd1400getsignals(stlport_t *portp) 3116static int stl_cd1400getsignals(struct stlport *portp)
3482{ 3117{
3483 unsigned char msvr1, msvr2; 3118 unsigned char msvr1, msvr2;
3484 unsigned long flags; 3119 unsigned long flags;
3485 int sigs; 3120 int sigs;
3486 3121
3487#ifdef DEBUG 3122 pr_debug("stl_cd1400getsignals(portp=%p)\n", portp);
3488 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3489#endif
3490 3123
3491 spin_lock_irqsave(&brd_lock, flags); 3124 spin_lock_irqsave(&brd_lock, flags);
3492 BRDENABLE(portp->brdnr, portp->pagenr); 3125 BRDENABLE(portp->brdnr, portp->pagenr);
@@ -3516,15 +3149,13 @@ static int stl_cd1400getsignals(stlport_t *portp)
3516 * Enable/Disable the Transmitter and/or Receiver. 3149 * Enable/Disable the Transmitter and/or Receiver.
3517 */ 3150 */
3518 3151
3519static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx) 3152static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx)
3520{ 3153{
3521 unsigned char ccr; 3154 unsigned char ccr;
3522 unsigned long flags; 3155 unsigned long flags;
3523 3156
3524#ifdef DEBUG 3157 pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3525 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n", 3158
3526 (int) portp, rx, tx);
3527#endif
3528 ccr = 0; 3159 ccr = 0;
3529 3160
3530 if (tx == 0) 3161 if (tx == 0)
@@ -3552,15 +3183,12 @@ static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3552 * Start/stop the Transmitter and/or Receiver. 3183 * Start/stop the Transmitter and/or Receiver.
3553 */ 3184 */
3554 3185
3555static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx) 3186static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx)
3556{ 3187{
3557 unsigned char sreron, sreroff; 3188 unsigned char sreron, sreroff;
3558 unsigned long flags; 3189 unsigned long flags;
3559 3190
3560#ifdef DEBUG 3191 pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3561 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3562 (int) portp, rx, tx);
3563#endif
3564 3192
3565 sreron = 0; 3193 sreron = 0;
3566 sreroff = 0; 3194 sreroff = 0;
@@ -3592,13 +3220,12 @@ static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3592 * Disable all interrupts from this port. 3220 * Disable all interrupts from this port.
3593 */ 3221 */
3594 3222
3595static void stl_cd1400disableintrs(stlport_t *portp) 3223static void stl_cd1400disableintrs(struct stlport *portp)
3596{ 3224{
3597 unsigned long flags; 3225 unsigned long flags;
3598 3226
3599#ifdef DEBUG 3227 pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp);
3600 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp); 3228
3601#endif
3602 spin_lock_irqsave(&brd_lock, flags); 3229 spin_lock_irqsave(&brd_lock, flags);
3603 BRDENABLE(portp->brdnr, portp->pagenr); 3230 BRDENABLE(portp->brdnr, portp->pagenr);
3604 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3231 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
@@ -3609,13 +3236,11 @@ static void stl_cd1400disableintrs(stlport_t *portp)
3609 3236
3610/*****************************************************************************/ 3237/*****************************************************************************/
3611 3238
3612static void stl_cd1400sendbreak(stlport_t *portp, int len) 3239static void stl_cd1400sendbreak(struct stlport *portp, int len)
3613{ 3240{
3614 unsigned long flags; 3241 unsigned long flags;
3615 3242
3616#ifdef DEBUG 3243 pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp, len);
3617 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3618#endif
3619 3244
3620 spin_lock_irqsave(&brd_lock, flags); 3245 spin_lock_irqsave(&brd_lock, flags);
3621 BRDENABLE(portp->brdnr, portp->pagenr); 3246 BRDENABLE(portp->brdnr, portp->pagenr);
@@ -3636,19 +3261,17 @@ static void stl_cd1400sendbreak(stlport_t *portp, int len)
3636 * Take flow control actions... 3261 * Take flow control actions...
3637 */ 3262 */
3638 3263
3639static void stl_cd1400flowctrl(stlport_t *portp, int state) 3264static void stl_cd1400flowctrl(struct stlport *portp, int state)
3640{ 3265{
3641 struct tty_struct *tty; 3266 struct tty_struct *tty;
3642 unsigned long flags; 3267 unsigned long flags;
3643 3268
3644#ifdef DEBUG 3269 pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp, state);
3645 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3646#endif
3647 3270
3648 if (portp == (stlport_t *) NULL) 3271 if (portp == NULL)
3649 return; 3272 return;
3650 tty = portp->tty; 3273 tty = portp->tty;
3651 if (tty == (struct tty_struct *) NULL) 3274 if (tty == NULL)
3652 return; 3275 return;
3653 3276
3654 spin_lock_irqsave(&brd_lock, flags); 3277 spin_lock_irqsave(&brd_lock, flags);
@@ -3700,19 +3323,17 @@ static void stl_cd1400flowctrl(stlport_t *portp, int state)
3700 * Send a flow control character... 3323 * Send a flow control character...
3701 */ 3324 */
3702 3325
3703static void stl_cd1400sendflow(stlport_t *portp, int state) 3326static void stl_cd1400sendflow(struct stlport *portp, int state)
3704{ 3327{
3705 struct tty_struct *tty; 3328 struct tty_struct *tty;
3706 unsigned long flags; 3329 unsigned long flags;
3707 3330
3708#ifdef DEBUG 3331 pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp, state);
3709 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3710#endif
3711 3332
3712 if (portp == (stlport_t *) NULL) 3333 if (portp == NULL)
3713 return; 3334 return;
3714 tty = portp->tty; 3335 tty = portp->tty;
3715 if (tty == (struct tty_struct *) NULL) 3336 if (tty == NULL)
3716 return; 3337 return;
3717 3338
3718 spin_lock_irqsave(&brd_lock, flags); 3339 spin_lock_irqsave(&brd_lock, flags);
@@ -3735,15 +3356,13 @@ static void stl_cd1400sendflow(stlport_t *portp, int state)
3735 3356
3736/*****************************************************************************/ 3357/*****************************************************************************/
3737 3358
3738static void stl_cd1400flush(stlport_t *portp) 3359static void stl_cd1400flush(struct stlport *portp)
3739{ 3360{
3740 unsigned long flags; 3361 unsigned long flags;
3741 3362
3742#ifdef DEBUG 3363 pr_debug("stl_cd1400flush(portp=%p)\n", portp);
3743 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3744#endif
3745 3364
3746 if (portp == (stlport_t *) NULL) 3365 if (portp == NULL)
3747 return; 3366 return;
3748 3367
3749 spin_lock_irqsave(&brd_lock, flags); 3368 spin_lock_irqsave(&brd_lock, flags);
@@ -3766,13 +3385,11 @@ static void stl_cd1400flush(stlport_t *portp)
3766 * maintains the busy port flag. 3385 * maintains the busy port flag.
3767 */ 3386 */
3768 3387
3769static int stl_cd1400datastate(stlport_t *portp) 3388static int stl_cd1400datastate(struct stlport *portp)
3770{ 3389{
3771#ifdef DEBUG 3390 pr_debug("stl_cd1400datastate(portp=%p)\n", portp);
3772 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3773#endif
3774 3391
3775 if (portp == (stlport_t *) NULL) 3392 if (portp == NULL)
3776 return 0; 3393 return 0;
3777 3394
3778 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0; 3395 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
@@ -3784,14 +3401,11 @@ static int stl_cd1400datastate(stlport_t *portp)
3784 * Interrupt service routine for cd1400 EasyIO boards. 3401 * Interrupt service routine for cd1400 EasyIO boards.
3785 */ 3402 */
3786 3403
3787static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase) 3404static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase)
3788{ 3405{
3789 unsigned char svrtype; 3406 unsigned char svrtype;
3790 3407
3791#ifdef DEBUG 3408 pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp, iobase);
3792 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3793 (int) panelp, iobase);
3794#endif
3795 3409
3796 spin_lock(&brd_lock); 3410 spin_lock(&brd_lock);
3797 outb(SVRR, iobase); 3411 outb(SVRR, iobase);
@@ -3817,14 +3431,11 @@ static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3817 * Interrupt service routine for cd1400 panels. 3431 * Interrupt service routine for cd1400 panels.
3818 */ 3432 */
3819 3433
3820static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase) 3434static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase)
3821{ 3435{
3822 unsigned char svrtype; 3436 unsigned char svrtype;
3823 3437
3824#ifdef DEBUG 3438 pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp, iobase);
3825 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3826 iobase);
3827#endif
3828 3439
3829 outb(SVRR, iobase); 3440 outb(SVRR, iobase);
3830 svrtype = inb(iobase + EREG_DATA); 3441 svrtype = inb(iobase + EREG_DATA);
@@ -3846,7 +3457,7 @@ static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3846 * this is the only way to generate them on the cd1400. 3457 * this is the only way to generate them on the cd1400.
3847 */ 3458 */
3848 3459
3849static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr) 3460static int stl_cd1400breakisr(struct stlport *portp, int ioaddr)
3850{ 3461{
3851 if (portp->brklen == 1) { 3462 if (portp->brklen == 1) {
3852 outb((COR2 + portp->uartaddr), ioaddr); 3463 outb((COR2 + portp->uartaddr), ioaddr);
@@ -3888,16 +3499,14 @@ static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
3888 * be NULL if the buffer has been freed. 3499 * be NULL if the buffer has been freed.
3889 */ 3500 */
3890 3501
3891static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr) 3502static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
3892{ 3503{
3893 stlport_t *portp; 3504 struct stlport *portp;
3894 int len, stlen; 3505 int len, stlen;
3895 char *head, *tail; 3506 char *head, *tail;
3896 unsigned char ioack, srer; 3507 unsigned char ioack, srer;
3897 3508
3898#ifdef DEBUG 3509 pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3899 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3900#endif
3901 3510
3902 ioack = inb(ioaddr + EREG_TXACK); 3511 ioack = inb(ioaddr + EREG_TXACK);
3903 if (((ioack & panelp->ackmask) != 0) || 3512 if (((ioack & panelp->ackmask) != 0) ||
@@ -3936,9 +3545,9 @@ static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
3936 } 3545 }
3937 outb(srer, (ioaddr + EREG_DATA)); 3546 outb(srer, (ioaddr + EREG_DATA));
3938 } else { 3547 } else {
3939 len = MIN(len, CD1400_TXFIFOSIZE); 3548 len = min(len, CD1400_TXFIFOSIZE);
3940 portp->stats.txtotal += len; 3549 portp->stats.txtotal += len;
3941 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail)); 3550 stlen = min(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
3942 outb((TDR + portp->uartaddr), ioaddr); 3551 outb((TDR + portp->uartaddr), ioaddr);
3943 outsb((ioaddr + EREG_DATA), tail, stlen); 3552 outsb((ioaddr + EREG_DATA), tail, stlen);
3944 len -= stlen; 3553 len -= stlen;
@@ -3969,17 +3578,15 @@ stl_txalldone:
3969 * shutdown a port not in user context. Need to handle this case. 3578 * shutdown a port not in user context. Need to handle this case.
3970 */ 3579 */
3971 3580
3972static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr) 3581static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
3973{ 3582{
3974 stlport_t *portp; 3583 struct stlport *portp;
3975 struct tty_struct *tty; 3584 struct tty_struct *tty;
3976 unsigned int ioack, len, buflen; 3585 unsigned int ioack, len, buflen;
3977 unsigned char status; 3586 unsigned char status;
3978 char ch; 3587 char ch;
3979 3588
3980#ifdef DEBUG 3589 pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3981 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3982#endif
3983 3590
3984 ioack = inb(ioaddr + EREG_RXACK); 3591 ioack = inb(ioaddr + EREG_RXACK);
3985 if ((ioack & panelp->ackmask) != 0) { 3592 if ((ioack & panelp->ackmask) != 0) {
@@ -3993,13 +3600,13 @@ static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
3993 outb((RDCR + portp->uartaddr), ioaddr); 3600 outb((RDCR + portp->uartaddr), ioaddr);
3994 len = inb(ioaddr + EREG_DATA); 3601 len = inb(ioaddr + EREG_DATA);
3995 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) { 3602 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
3996 len = MIN(len, sizeof(stl_unwanted)); 3603 len = min(len, sizeof(stl_unwanted));
3997 outb((RDSR + portp->uartaddr), ioaddr); 3604 outb((RDSR + portp->uartaddr), ioaddr);
3998 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len); 3605 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3999 portp->stats.rxlost += len; 3606 portp->stats.rxlost += len;
4000 portp->stats.rxtotal += len; 3607 portp->stats.rxtotal += len;
4001 } else { 3608 } else {
4002 len = MIN(len, buflen); 3609 len = min(len, buflen);
4003 if (len > 0) { 3610 if (len > 0) {
4004 unsigned char *ptr; 3611 unsigned char *ptr;
4005 outb((RDSR + portp->uartaddr), ioaddr); 3612 outb((RDSR + portp->uartaddr), ioaddr);
@@ -4036,18 +3643,16 @@ static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4036 do_SAK(tty); 3643 do_SAK(tty);
4037 BRDENABLE(portp->brdnr, portp->pagenr); 3644 BRDENABLE(portp->brdnr, portp->pagenr);
4038 } 3645 }
4039 } else if (status & ST_PARITY) { 3646 } else if (status & ST_PARITY)
4040 status = TTY_PARITY; 3647 status = TTY_PARITY;
4041 } else if (status & ST_FRAMING) { 3648 else if (status & ST_FRAMING)
4042 status = TTY_FRAME; 3649 status = TTY_FRAME;
4043 } else if(status & ST_OVERRUN) { 3650 else if(status & ST_OVERRUN)
4044 status = TTY_OVERRUN; 3651 status = TTY_OVERRUN;
4045 } else { 3652 else
4046 status = 0; 3653 status = 0;
4047 } 3654 } else
4048 } else {
4049 status = 0; 3655 status = 0;
4050 }
4051 tty_insert_flip_char(tty, ch, status); 3656 tty_insert_flip_char(tty, ch, status);
4052 tty_schedule_flip(tty); 3657 tty_schedule_flip(tty);
4053 } 3658 }
@@ -4069,15 +3674,13 @@ stl_rxalldone:
4069 * processing routine. 3674 * processing routine.
4070 */ 3675 */
4071 3676
4072static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr) 3677static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr)
4073{ 3678{
4074 stlport_t *portp; 3679 struct stlport *portp;
4075 unsigned int ioack; 3680 unsigned int ioack;
4076 unsigned char misr; 3681 unsigned char misr;
4077 3682
4078#ifdef DEBUG 3683 pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp);
4079 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4080#endif
4081 3684
4082 ioack = inb(ioaddr + EREG_MDACK); 3685 ioack = inb(ioaddr + EREG_MDACK);
4083 if (((ioack & panelp->ackmask) != 0) || 3686 if (((ioack & panelp->ackmask) != 0) ||
@@ -4109,19 +3712,19 @@ static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4109 * (Maybe should make this inline...) 3712 * (Maybe should make this inline...)
4110 */ 3713 */
4111 3714
4112static int stl_sc26198getreg(stlport_t *portp, int regnr) 3715static int stl_sc26198getreg(struct stlport *portp, int regnr)
4113{ 3716{
4114 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR)); 3717 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4115 return inb(portp->ioaddr + XP_DATA); 3718 return inb(portp->ioaddr + XP_DATA);
4116} 3719}
4117 3720
4118static void stl_sc26198setreg(stlport_t *portp, int regnr, int value) 3721static void stl_sc26198setreg(struct stlport *portp, int regnr, int value)
4119{ 3722{
4120 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR)); 3723 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4121 outb(value, (portp->ioaddr + XP_DATA)); 3724 outb(value, (portp->ioaddr + XP_DATA));
4122} 3725}
4123 3726
4124static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value) 3727static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value)
4125{ 3728{
4126 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR)); 3729 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4127 if (inb(portp->ioaddr + XP_DATA) != value) { 3730 if (inb(portp->ioaddr + XP_DATA) != value) {
@@ -4137,14 +3740,14 @@ static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4137 * Functions to get and set the sc26198 global registers. 3740 * Functions to get and set the sc26198 global registers.
4138 */ 3741 */
4139 3742
4140static int stl_sc26198getglobreg(stlport_t *portp, int regnr) 3743static int stl_sc26198getglobreg(struct stlport *portp, int regnr)
4141{ 3744{
4142 outb(regnr, (portp->ioaddr + XP_ADDR)); 3745 outb(regnr, (portp->ioaddr + XP_ADDR));
4143 return inb(portp->ioaddr + XP_DATA); 3746 return inb(portp->ioaddr + XP_DATA);
4144} 3747}
4145 3748
4146#if 0 3749#if 0
4147static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value) 3750static void stl_sc26198setglobreg(struct stlport *portp, int regnr, int value)
4148{ 3751{
4149 outb(regnr, (portp->ioaddr + XP_ADDR)); 3752 outb(regnr, (portp->ioaddr + XP_ADDR));
4150 outb(value, (portp->ioaddr + XP_DATA)); 3753 outb(value, (portp->ioaddr + XP_DATA));
@@ -4159,15 +3762,12 @@ static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4159 * identical when dealing with ports. 3762 * identical when dealing with ports.
4160 */ 3763 */
4161 3764
4162static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp) 3765static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
4163{ 3766{
4164 int chipmask, i; 3767 int chipmask, i;
4165 int nrchips, ioaddr; 3768 int nrchips, ioaddr;
4166 3769
4167#ifdef DEBUG 3770 pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
4168 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4169 (int) brdp, (int) panelp);
4170#endif
4171 3771
4172 BRDENABLE(panelp->brdnr, panelp->pagenr); 3772 BRDENABLE(panelp->brdnr, panelp->pagenr);
4173 3773
@@ -4179,7 +3779,7 @@ static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4179 if (brdp->brdtype == BRD_ECHPCI) 3779 if (brdp->brdtype == BRD_ECHPCI)
4180 outb(panelp->pagenr, brdp->ioctrl); 3780 outb(panelp->pagenr, brdp->ioctrl);
4181 3781
4182 for (i = 0; (i < nrchips); i++) { 3782 for (i = 0; i < nrchips; i++) {
4183 ioaddr = panelp->iobase + (i * 4); 3783 ioaddr = panelp->iobase + (i * 4);
4184 outb(SCCR, (ioaddr + XP_ADDR)); 3784 outb(SCCR, (ioaddr + XP_ADDR));
4185 outb(CR_RESETALL, (ioaddr + XP_DATA)); 3785 outb(CR_RESETALL, (ioaddr + XP_DATA));
@@ -4207,15 +3807,13 @@ static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4207 * Initialize hardware specific port registers. 3807 * Initialize hardware specific port registers.
4208 */ 3808 */
4209 3809
4210static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp) 3810static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
4211{ 3811{
4212#ifdef DEBUG 3812 pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
4213 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n", 3813 panelp, portp);
4214 (int) brdp, (int) panelp, (int) portp);
4215#endif
4216 3814
4217 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) || 3815 if ((brdp == NULL) || (panelp == NULL) ||
4218 (portp == (stlport_t *) NULL)) 3816 (portp == NULL))
4219 return; 3817 return;
4220 3818
4221 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4); 3819 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
@@ -4235,9 +3833,9 @@ static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *p
4235 * settings. 3833 * settings.
4236 */ 3834 */
4237 3835
4238static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp) 3836static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp)
4239{ 3837{
4240 stlbrd_t *brdp; 3838 struct stlbrd *brdp;
4241 unsigned long flags; 3839 unsigned long flags;
4242 unsigned int baudrate; 3840 unsigned int baudrate;
4243 unsigned char mr0, mr1, mr2, clk; 3841 unsigned char mr0, mr1, mr2, clk;
@@ -4252,7 +3850,7 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4252 imroff = 0; 3850 imroff = 0;
4253 3851
4254 brdp = stl_brds[portp->brdnr]; 3852 brdp = stl_brds[portp->brdnr];
4255 if (brdp == (stlbrd_t *) NULL) 3853 if (brdp == NULL)
4256 return; 3854 return;
4257 3855
4258/* 3856/*
@@ -4301,9 +3899,8 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4301 mr1 |= (MR1_PARENB | MR1_PARODD); 3899 mr1 |= (MR1_PARENB | MR1_PARODD);
4302 else 3900 else
4303 mr1 |= (MR1_PARENB | MR1_PAREVEN); 3901 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4304 } else { 3902 } else
4305 mr1 |= MR1_PARNONE; 3903 mr1 |= MR1_PARNONE;
4306 }
4307 3904
4308 mr1 |= MR1_ERRBLOCK; 3905 mr1 |= MR1_ERRBLOCK;
4309 3906
@@ -4343,12 +3940,10 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4343 if (baudrate > STL_SC26198MAXBAUD) 3940 if (baudrate > STL_SC26198MAXBAUD)
4344 baudrate = STL_SC26198MAXBAUD; 3941 baudrate = STL_SC26198MAXBAUD;
4345 3942
4346 if (baudrate > 0) { 3943 if (baudrate > 0)
4347 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) { 3944 for (clk = 0; clk < SC26198_NRBAUDS; clk++)
4348 if (baudrate <= sc26198_baudtable[clk]) 3945 if (baudrate <= sc26198_baudtable[clk])
4349 break; 3946 break;
4350 }
4351 }
4352 3947
4353/* 3948/*
4354 * Check what form of modem signaling is required and set it up. 3949 * Check what form of modem signaling is required and set it up.
@@ -4370,9 +3965,9 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4370 if (tiosp->c_iflag & IXON) { 3965 if (tiosp->c_iflag & IXON) {
4371 mr0 |= MR0_SWFTX | MR0_SWFT; 3966 mr0 |= MR0_SWFTX | MR0_SWFT;
4372 imron |= IR_XONXOFF; 3967 imron |= IR_XONXOFF;
4373 } else { 3968 } else
4374 imroff |= IR_XONXOFF; 3969 imroff |= IR_XONXOFF;
4375 } 3970
4376 if (tiosp->c_iflag & IXOFF) 3971 if (tiosp->c_iflag & IXOFF)
4377 mr0 |= MR0_SWFRX; 3972 mr0 |= MR0_SWFRX;
4378 3973
@@ -4386,15 +3981,13 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4386 * them all up. 3981 * them all up.
4387 */ 3982 */
4388 3983
4389#ifdef DEBUG 3984 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4390 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4391 portp->portnr, portp->panelnr, portp->brdnr); 3985 portp->portnr, portp->panelnr, portp->brdnr);
4392 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk); 3986 pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4393 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff); 3987 pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4394 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n", 3988 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4395 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], 3989 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4396 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]); 3990 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4397#endif
4398 3991
4399 spin_lock_irqsave(&brd_lock, flags); 3992 spin_lock_irqsave(&brd_lock, flags);
4400 BRDENABLE(portp->brdnr, portp->pagenr); 3993 BRDENABLE(portp->brdnr, portp->pagenr);
@@ -4432,15 +4025,13 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4432 * Set the state of the DTR and RTS signals. 4025 * Set the state of the DTR and RTS signals.
4433 */ 4026 */
4434 4027
4435static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts) 4028static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts)
4436{ 4029{
4437 unsigned char iopioron, iopioroff; 4030 unsigned char iopioron, iopioroff;
4438 unsigned long flags; 4031 unsigned long flags;
4439 4032
4440#ifdef DEBUG 4033 pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp,
4441 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n", 4034 dtr, rts);
4442 (int) portp, dtr, rts);
4443#endif
4444 4035
4445 iopioron = 0; 4036 iopioron = 0;
4446 iopioroff = 0; 4037 iopioroff = 0;
@@ -4467,15 +4058,13 @@ static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4467 * Return the state of the signals. 4058 * Return the state of the signals.
4468 */ 4059 */
4469 4060
4470static int stl_sc26198getsignals(stlport_t *portp) 4061static int stl_sc26198getsignals(struct stlport *portp)
4471{ 4062{
4472 unsigned char ipr; 4063 unsigned char ipr;
4473 unsigned long flags; 4064 unsigned long flags;
4474 int sigs; 4065 int sigs;
4475 4066
4476#ifdef DEBUG 4067 pr_debug("stl_sc26198getsignals(portp=%p)\n", portp);
4477 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4478#endif
4479 4068
4480 spin_lock_irqsave(&brd_lock, flags); 4069 spin_lock_irqsave(&brd_lock, flags);
4481 BRDENABLE(portp->brdnr, portp->pagenr); 4070 BRDENABLE(portp->brdnr, portp->pagenr);
@@ -4498,15 +4087,12 @@ static int stl_sc26198getsignals(stlport_t *portp)
4498 * Enable/Disable the Transmitter and/or Receiver. 4087 * Enable/Disable the Transmitter and/or Receiver.
4499 */ 4088 */
4500 4089
4501static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx) 4090static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx)
4502{ 4091{
4503 unsigned char ccr; 4092 unsigned char ccr;
4504 unsigned long flags; 4093 unsigned long flags;
4505 4094
4506#ifdef DEBUG 4095 pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx,tx);
4507 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4508 (int) portp, rx, tx);
4509#endif
4510 4096
4511 ccr = portp->crenable; 4097 ccr = portp->crenable;
4512 if (tx == 0) 4098 if (tx == 0)
@@ -4532,15 +4118,12 @@ static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4532 * Start/stop the Transmitter and/or Receiver. 4118 * Start/stop the Transmitter and/or Receiver.
4533 */ 4119 */
4534 4120
4535static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx) 4121static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx)
4536{ 4122{
4537 unsigned char imr; 4123 unsigned char imr;
4538 unsigned long flags; 4124 unsigned long flags;
4539 4125
4540#ifdef DEBUG 4126 pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
4541 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4542 (int) portp, rx, tx);
4543#endif
4544 4127
4545 imr = portp->imr; 4128 imr = portp->imr;
4546 if (tx == 0) 4129 if (tx == 0)
@@ -4568,13 +4151,11 @@ static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4568 * Disable all interrupts from this port. 4151 * Disable all interrupts from this port.
4569 */ 4152 */
4570 4153
4571static void stl_sc26198disableintrs(stlport_t *portp) 4154static void stl_sc26198disableintrs(struct stlport *portp)
4572{ 4155{
4573 unsigned long flags; 4156 unsigned long flags;
4574 4157
4575#ifdef DEBUG 4158 pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp);
4576 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4577#endif
4578 4159
4579 spin_lock_irqsave(&brd_lock, flags); 4160 spin_lock_irqsave(&brd_lock, flags);
4580 BRDENABLE(portp->brdnr, portp->pagenr); 4161 BRDENABLE(portp->brdnr, portp->pagenr);
@@ -4586,22 +4167,20 @@ static void stl_sc26198disableintrs(stlport_t *portp)
4586 4167
4587/*****************************************************************************/ 4168/*****************************************************************************/
4588 4169
4589static void stl_sc26198sendbreak(stlport_t *portp, int len) 4170static void stl_sc26198sendbreak(struct stlport *portp, int len)
4590{ 4171{
4591 unsigned long flags; 4172 unsigned long flags;
4592 4173
4593#ifdef DEBUG 4174 pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp, len);
4594 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4595#endif
4596 4175
4597 spin_lock_irqsave(&brd_lock, flags); 4176 spin_lock_irqsave(&brd_lock, flags);
4598 BRDENABLE(portp->brdnr, portp->pagenr); 4177 BRDENABLE(portp->brdnr, portp->pagenr);
4599 if (len == 1) { 4178 if (len == 1) {
4600 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK); 4179 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4601 portp->stats.txbreaks++; 4180 portp->stats.txbreaks++;
4602 } else { 4181 } else
4603 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK); 4182 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4604 } 4183
4605 BRDDISABLE(portp->brdnr); 4184 BRDDISABLE(portp->brdnr);
4606 spin_unlock_irqrestore(&brd_lock, flags); 4185 spin_unlock_irqrestore(&brd_lock, flags);
4607} 4186}
@@ -4612,20 +4191,18 @@ static void stl_sc26198sendbreak(stlport_t *portp, int len)
4612 * Take flow control actions... 4191 * Take flow control actions...
4613 */ 4192 */
4614 4193
4615static void stl_sc26198flowctrl(stlport_t *portp, int state) 4194static void stl_sc26198flowctrl(struct stlport *portp, int state)
4616{ 4195{
4617 struct tty_struct *tty; 4196 struct tty_struct *tty;
4618 unsigned long flags; 4197 unsigned long flags;
4619 unsigned char mr0; 4198 unsigned char mr0;
4620 4199
4621#ifdef DEBUG 4200 pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp, state);
4622 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4623#endif
4624 4201
4625 if (portp == (stlport_t *) NULL) 4202 if (portp == NULL)
4626 return; 4203 return;
4627 tty = portp->tty; 4204 tty = portp->tty;
4628 if (tty == (struct tty_struct *) NULL) 4205 if (tty == NULL)
4629 return; 4206 return;
4630 4207
4631 spin_lock_irqsave(&brd_lock, flags); 4208 spin_lock_irqsave(&brd_lock, flags);
@@ -4683,20 +4260,18 @@ static void stl_sc26198flowctrl(stlport_t *portp, int state)
4683 * Send a flow control character. 4260 * Send a flow control character.
4684 */ 4261 */
4685 4262
4686static void stl_sc26198sendflow(stlport_t *portp, int state) 4263static void stl_sc26198sendflow(struct stlport *portp, int state)
4687{ 4264{
4688 struct tty_struct *tty; 4265 struct tty_struct *tty;
4689 unsigned long flags; 4266 unsigned long flags;
4690 unsigned char mr0; 4267 unsigned char mr0;
4691 4268
4692#ifdef DEBUG 4269 pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp, state);
4693 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4694#endif
4695 4270
4696 if (portp == (stlport_t *) NULL) 4271 if (portp == NULL)
4697 return; 4272 return;
4698 tty = portp->tty; 4273 tty = portp->tty;
4699 if (tty == (struct tty_struct *) NULL) 4274 if (tty == NULL)
4700 return; 4275 return;
4701 4276
4702 spin_lock_irqsave(&brd_lock, flags); 4277 spin_lock_irqsave(&brd_lock, flags);
@@ -4724,15 +4299,13 @@ static void stl_sc26198sendflow(stlport_t *portp, int state)
4724 4299
4725/*****************************************************************************/ 4300/*****************************************************************************/
4726 4301
4727static void stl_sc26198flush(stlport_t *portp) 4302static void stl_sc26198flush(struct stlport *portp)
4728{ 4303{
4729 unsigned long flags; 4304 unsigned long flags;
4730 4305
4731#ifdef DEBUG 4306 pr_debug("stl_sc26198flush(portp=%p)\n", portp);
4732 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4733#endif
4734 4307
4735 if (portp == (stlport_t *) NULL) 4308 if (portp == NULL)
4736 return; 4309 return;
4737 4310
4738 spin_lock_irqsave(&brd_lock, flags); 4311 spin_lock_irqsave(&brd_lock, flags);
@@ -4754,16 +4327,14 @@ static void stl_sc26198flush(stlport_t *portp)
4754 * check the port statusy register to be sure. 4327 * check the port statusy register to be sure.
4755 */ 4328 */
4756 4329
4757static int stl_sc26198datastate(stlport_t *portp) 4330static int stl_sc26198datastate(struct stlport *portp)
4758{ 4331{
4759 unsigned long flags; 4332 unsigned long flags;
4760 unsigned char sr; 4333 unsigned char sr;
4761 4334
4762#ifdef DEBUG 4335 pr_debug("stl_sc26198datastate(portp=%p)\n", portp);
4763 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4764#endif
4765 4336
4766 if (portp == (stlport_t *) NULL) 4337 if (portp == NULL)
4767 return 0; 4338 return 0;
4768 if (test_bit(ASYI_TXBUSY, &portp->istate)) 4339 if (test_bit(ASYI_TXBUSY, &portp->istate))
4769 return 1; 4340 return 1;
@@ -4784,18 +4355,16 @@ static int stl_sc26198datastate(stlport_t *portp)
4784 * to process a command... 4355 * to process a command...
4785 */ 4356 */
4786 4357
4787static void stl_sc26198wait(stlport_t *portp) 4358static void stl_sc26198wait(struct stlport *portp)
4788{ 4359{
4789 int i; 4360 int i;
4790 4361
4791#ifdef DEBUG 4362 pr_debug("stl_sc26198wait(portp=%p)\n", portp);
4792 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
4793#endif
4794 4363
4795 if (portp == (stlport_t *) NULL) 4364 if (portp == NULL)
4796 return; 4365 return;
4797 4366
4798 for (i = 0; (i < 20); i++) 4367 for (i = 0; i < 20; i++)
4799 stl_sc26198getglobreg(portp, TSTR); 4368 stl_sc26198getglobreg(portp, TSTR);
4800} 4369}
4801 4370
@@ -4807,7 +4376,7 @@ static void stl_sc26198wait(stlport_t *portp)
4807 * automatic flow control modes of the sc26198. 4376 * automatic flow control modes of the sc26198.
4808 */ 4377 */
4809 4378
4810static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty) 4379static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty)
4811{ 4380{
4812 unsigned char mr0; 4381 unsigned char mr0;
4813 4382
@@ -4825,9 +4394,9 @@ static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
4825 * Interrupt service routine for sc26198 panels. 4394 * Interrupt service routine for sc26198 panels.
4826 */ 4395 */
4827 4396
4828static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase) 4397static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase)
4829{ 4398{
4830 stlport_t *portp; 4399 struct stlport *portp;
4831 unsigned int iack; 4400 unsigned int iack;
4832 4401
4833 spin_lock(&brd_lock); 4402 spin_lock(&brd_lock);
@@ -4863,16 +4432,14 @@ static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4863 * be NULL if the buffer has been freed. 4432 * be NULL if the buffer has been freed.
4864 */ 4433 */
4865 4434
4866static void stl_sc26198txisr(stlport_t *portp) 4435static void stl_sc26198txisr(struct stlport *portp)
4867{ 4436{
4868 unsigned int ioaddr; 4437 unsigned int ioaddr;
4869 unsigned char mr0; 4438 unsigned char mr0;
4870 int len, stlen; 4439 int len, stlen;
4871 char *head, *tail; 4440 char *head, *tail;
4872 4441
4873#ifdef DEBUG 4442 pr_debug("stl_sc26198txisr(portp=%p)\n", portp);
4874 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
4875#endif
4876 4443
4877 ioaddr = portp->ioaddr; 4444 ioaddr = portp->ioaddr;
4878 head = portp->tx.head; 4445 head = portp->tx.head;
@@ -4897,9 +4464,9 @@ static void stl_sc26198txisr(stlport_t *portp)
4897 outb(mr0, (ioaddr + XP_DATA)); 4464 outb(mr0, (ioaddr + XP_DATA));
4898 } 4465 }
4899 } else { 4466 } else {
4900 len = MIN(len, SC26198_TXFIFOSIZE); 4467 len = min(len, SC26198_TXFIFOSIZE);
4901 portp->stats.txtotal += len; 4468 portp->stats.txtotal += len;
4902 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail)); 4469 stlen = min(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4903 outb(GTXFIFO, (ioaddr + XP_ADDR)); 4470 outb(GTXFIFO, (ioaddr + XP_ADDR));
4904 outsb((ioaddr + XP_DATA), tail, stlen); 4471 outsb((ioaddr + XP_DATA), tail, stlen);
4905 len -= stlen; 4472 len -= stlen;
@@ -4926,14 +4493,12 @@ static void stl_sc26198txisr(stlport_t *portp)
4926 * shutdown a port not in user context. Need to handle this case. 4493 * shutdown a port not in user context. Need to handle this case.
4927 */ 4494 */
4928 4495
4929static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack) 4496static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
4930{ 4497{
4931 struct tty_struct *tty; 4498 struct tty_struct *tty;
4932 unsigned int len, buflen, ioaddr; 4499 unsigned int len, buflen, ioaddr;
4933 4500
4934#ifdef DEBUG 4501 pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack);
4935 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
4936#endif
4937 4502
4938 tty = portp->tty; 4503 tty = portp->tty;
4939 ioaddr = portp->ioaddr; 4504 ioaddr = portp->ioaddr;
@@ -4942,13 +4507,13 @@ static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4942 4507
4943 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) { 4508 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4944 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) { 4509 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4945 len = MIN(len, sizeof(stl_unwanted)); 4510 len = min(len, sizeof(stl_unwanted));
4946 outb(GRXFIFO, (ioaddr + XP_ADDR)); 4511 outb(GRXFIFO, (ioaddr + XP_ADDR));
4947 insb((ioaddr + XP_DATA), &stl_unwanted[0], len); 4512 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4948 portp->stats.rxlost += len; 4513 portp->stats.rxlost += len;
4949 portp->stats.rxtotal += len; 4514 portp->stats.rxtotal += len;
4950 } else { 4515 } else {
4951 len = MIN(len, buflen); 4516 len = min(len, buflen);
4952 if (len > 0) { 4517 if (len > 0) {
4953 unsigned char *ptr; 4518 unsigned char *ptr;
4954 outb(GRXFIFO, (ioaddr + XP_ADDR)); 4519 outb(GRXFIFO, (ioaddr + XP_ADDR));
@@ -4968,8 +4533,8 @@ static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4968 * flow control modes of the sc26198. 4533 * flow control modes of the sc26198.
4969 */ 4534 */
4970 if (test_bit(ASYI_TXFLOWED, &portp->istate)) { 4535 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
4971 if ((tty != (struct tty_struct *) NULL) && 4536 if ((tty != NULL) &&
4972 (tty->termios != (struct termios *) NULL) && 4537 (tty->termios != NULL) &&
4973 (tty->termios->c_iflag & IXANY)) { 4538 (tty->termios->c_iflag & IXANY)) {
4974 stl_sc26198txunflow(portp, tty); 4539 stl_sc26198txunflow(portp, tty);
4975 } 4540 }
@@ -4982,7 +4547,7 @@ static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4982 * Process an RX bad character. 4547 * Process an RX bad character.
4983 */ 4548 */
4984 4549
4985static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch) 4550static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch)
4986{ 4551{
4987 struct tty_struct *tty; 4552 struct tty_struct *tty;
4988 unsigned int ioaddr; 4553 unsigned int ioaddr;
@@ -4999,7 +4564,7 @@ static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, ch
4999 if (status & SR_RXBREAK) 4564 if (status & SR_RXBREAK)
5000 portp->stats.rxbreaks++; 4565 portp->stats.rxbreaks++;
5001 4566
5002 if ((tty != (struct tty_struct *) NULL) && 4567 if ((tty != NULL) &&
5003 ((portp->rxignoremsk & status) == 0)) { 4568 ((portp->rxignoremsk & status) == 0)) {
5004 if (portp->rxmarkmsk & status) { 4569 if (portp->rxmarkmsk & status) {
5005 if (status & SR_RXBREAK) { 4570 if (status & SR_RXBREAK) {
@@ -5008,18 +4573,16 @@ static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, ch
5008 do_SAK(tty); 4573 do_SAK(tty);
5009 BRDENABLE(portp->brdnr, portp->pagenr); 4574 BRDENABLE(portp->brdnr, portp->pagenr);
5010 } 4575 }
5011 } else if (status & SR_RXPARITY) { 4576 } else if (status & SR_RXPARITY)
5012 status = TTY_PARITY; 4577 status = TTY_PARITY;
5013 } else if (status & SR_RXFRAMING) { 4578 else if (status & SR_RXFRAMING)
5014 status = TTY_FRAME; 4579 status = TTY_FRAME;
5015 } else if(status & SR_RXOVERRUN) { 4580 else if(status & SR_RXOVERRUN)
5016 status = TTY_OVERRUN; 4581 status = TTY_OVERRUN;
5017 } else { 4582 else
5018 status = 0; 4583 status = 0;
5019 } 4584 } else
5020 } else {
5021 status = 0; 4585 status = 0;
5022 }
5023 4586
5024 tty_insert_flip_char(tty, ch, status); 4587 tty_insert_flip_char(tty, ch, status);
5025 tty_schedule_flip(tty); 4588 tty_schedule_flip(tty);
@@ -5040,7 +4603,7 @@ static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, ch
5040 * the FIFO). 4603 * the FIFO).
5041 */ 4604 */
5042 4605
5043static void stl_sc26198rxbadchars(stlport_t *portp) 4606static void stl_sc26198rxbadchars(struct stlport *portp)
5044{ 4607{
5045 unsigned char status, mr1; 4608 unsigned char status, mr1;
5046 char ch; 4609 char ch;
@@ -5073,13 +4636,11 @@ static void stl_sc26198rxbadchars(stlport_t *portp)
5073 * processing time. 4636 * processing time.
5074 */ 4637 */
5075 4638
5076static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack) 4639static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
5077{ 4640{
5078 unsigned char cir, ipr, xisr; 4641 unsigned char cir, ipr, xisr;
5079 4642
5080#ifdef DEBUG 4643 pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp, iack);
5081 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5082#endif
5083 4644
5084 cir = stl_sc26198getglobreg(portp, CIR); 4645 cir = stl_sc26198getglobreg(portp, CIR);
5085 4646
@@ -5112,4 +4673,172 @@ static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5112 } 4673 }
5113} 4674}
5114 4675
5115/*****************************************************************************/ 4676static void stl_free_isabrds(void)
4677{
4678 struct stlbrd *brdp;
4679 unsigned int i;
4680
4681 for (i = 0; i < stl_nrbrds; i++) {
4682 if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED))
4683 continue;
4684
4685 free_irq(brdp->irq, brdp);
4686
4687 stl_cleanup_panels(brdp);
4688
4689 release_region(brdp->ioaddr1, brdp->iosize1);
4690 if (brdp->iosize2 > 0)
4691 release_region(brdp->ioaddr2, brdp->iosize2);
4692
4693 kfree(brdp);
4694 stl_brds[i] = NULL;
4695 }
4696}
4697
4698/*
4699 * Loadable module initialization stuff.
4700 */
4701static int __init stallion_module_init(void)
4702{
4703 struct stlbrd *brdp;
4704 struct stlconf conf;
4705 unsigned int i, j;
4706 int retval;
4707
4708 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
4709
4710 spin_lock_init(&stallion_lock);
4711 spin_lock_init(&brd_lock);
4712
4713/*
4714 * Find any dynamically supported boards. That is via module load
4715 * line options.
4716 */
4717 for (i = stl_nrbrds; i < stl_nargs; i++) {
4718 memset(&conf, 0, sizeof(conf));
4719 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
4720 continue;
4721 if ((brdp = stl_allocbrd()) == NULL)
4722 continue;
4723 brdp->brdnr = i;
4724 brdp->brdtype = conf.brdtype;
4725 brdp->ioaddr1 = conf.ioaddr1;
4726 brdp->ioaddr2 = conf.ioaddr2;
4727 brdp->irq = conf.irq;
4728 brdp->irqtype = conf.irqtype;
4729 if (stl_brdinit(brdp))
4730 kfree(brdp);
4731 else {
4732 for (j = 0; j < brdp->nrports; j++)
4733 tty_register_device(stl_serial,
4734 brdp->brdnr * STL_MAXPORTS + j, NULL);
4735 stl_brds[brdp->brdnr] = brdp;
4736 stl_nrbrds = i + 1;
4737 }
4738 }
4739
4740 /* this has to be _after_ isa finding because of locking */
4741 retval = pci_register_driver(&stl_pcidriver);
4742 if (retval && stl_nrbrds == 0)
4743 goto err;
4744
4745 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4746 if (!stl_serial) {
4747 retval = -ENOMEM;
4748 goto err_pcidr;
4749 }
4750
4751/*
4752 * Set up a character driver for per board stuff. This is mainly used
4753 * to do stats ioctls on the ports.
4754 */
4755 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
4756 printk("STALLION: failed to register serial board device\n");
4757
4758 stallion_class = class_create(THIS_MODULE, "staliomem");
4759 if (IS_ERR(stallion_class)) {
4760 retval = PTR_ERR(stallion_class);
4761 goto err_reg;
4762 }
4763 for (i = 0; i < 4; i++)
4764 class_device_create(stallion_class, NULL,
4765 MKDEV(STL_SIOMEMMAJOR, i), NULL,
4766 "staliomem%d", i);
4767
4768 stl_serial->owner = THIS_MODULE;
4769 stl_serial->driver_name = stl_drvname;
4770 stl_serial->name = "ttyE";
4771 stl_serial->major = STL_SERIALMAJOR;
4772 stl_serial->minor_start = 0;
4773 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
4774 stl_serial->subtype = SERIAL_TYPE_NORMAL;
4775 stl_serial->init_termios = stl_deftermios;
4776 stl_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
4777 tty_set_operations(stl_serial, &stl_ops);
4778
4779 retval = tty_register_driver(stl_serial);
4780 if (retval) {
4781 printk("STALLION: failed to register serial driver\n");
4782 goto err_clsdev;
4783 }
4784
4785 return 0;
4786err_clsdev:
4787 for (i = 0; i < 4; i++)
4788 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
4789 class_destroy(stallion_class);
4790err_reg:
4791 unregister_chrdev(STL_SIOMEMMAJOR, "staliomem");
4792 put_tty_driver(stl_serial);
4793err_pcidr:
4794 pci_unregister_driver(&stl_pcidriver);
4795 stl_free_isabrds();
4796err:
4797 return retval;
4798}
4799
4800static void __exit stallion_module_exit(void)
4801{
4802 struct stlbrd *brdp;
4803 unsigned int i, j;
4804 int retval;
4805
4806 pr_debug("cleanup_module()\n");
4807
4808 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
4809 stl_drvversion);
4810
4811/*
4812 * Free up all allocated resources used by the ports. This includes
4813 * memory and interrupts. As part of this process we will also do
4814 * a hangup on every open port - to try to flush out any processes
4815 * hanging onto ports.
4816 */
4817 for (i = 0; i < stl_nrbrds; i++) {
4818 if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED))
4819 continue;
4820 for (j = 0; j < brdp->nrports; j++)
4821 tty_unregister_device(stl_serial,
4822 brdp->brdnr * STL_MAXPORTS + j);
4823 }
4824 tty_unregister_driver(stl_serial);
4825 put_tty_driver(stl_serial);
4826
4827 for (i = 0; i < 4; i++)
4828 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
4829 if ((retval = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
4830 printk("STALLION: failed to un-register serial memory device, "
4831 "errno=%d\n", -retval);
4832 class_destroy(stallion_class);
4833
4834 pci_unregister_driver(&stl_pcidriver);
4835
4836 stl_free_isabrds();
4837}
4838
4839module_init(stallion_module_init);
4840module_exit(stallion_module_exit);
4841
4842MODULE_AUTHOR("Greg Ungerer");
4843MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
4844MODULE_LICENSE("GPL");
diff --git a/drivers/char/sx.c b/drivers/char/sx.c
index e1cd2bc4b1e4..a3008ce13015 100644
--- a/drivers/char/sx.c
+++ b/drivers/char/sx.c
@@ -32,7 +32,6 @@
32 * USA. 32 * USA.
33 * 33 *
34 * Revision history: 34 * Revision history:
35 * $Log: sx.c,v $
36 * Revision 1.33 2000/03/09 10:00:00 pvdl,wolff 35 * Revision 1.33 2000/03/09 10:00:00 pvdl,wolff
37 * - Fixed module and port counting 36 * - Fixed module and port counting
38 * - Fixed signal handling 37 * - Fixed signal handling
@@ -199,13 +198,9 @@
199 * 198 *
200 * */ 199 * */
201 200
202 201#define SX_VERSION 1.33
203#define RCS_ID "$Id: sx.c,v 1.33 2000/03/08 10:01:02 wolff, pvdl Exp $"
204#define RCS_REV "$Revision: 1.33 $"
205
206 202
207#include <linux/module.h> 203#include <linux/module.h>
208#include <linux/config.h>
209#include <linux/kdev_t.h> 204#include <linux/kdev_t.h>
210#include <linux/kernel.h> 205#include <linux/kernel.h>
211#include <linux/sched.h> 206#include <linux/sched.h>
@@ -219,6 +214,7 @@
219#include <linux/fcntl.h> 214#include <linux/fcntl.h>
220#include <linux/major.h> 215#include <linux/major.h>
221#include <linux/delay.h> 216#include <linux/delay.h>
217#include <linux/eisa.h>
222#include <linux/pci.h> 218#include <linux/pci.h>
223#include <linux/slab.h> 219#include <linux/slab.h>
224#include <linux/init.h> 220#include <linux/init.h>
@@ -242,7 +238,6 @@
242#include <linux/generic_serial.h> 238#include <linux/generic_serial.h>
243#include "sx.h" 239#include "sx.h"
244 240
245
246/* I don't think that this driver can handle more than 256 ports on 241/* I don't think that this driver can handle more than 256 ports on
247 one machine. You'll have to increase the number of boards in sx.h 242 one machine. You'll have to increase the number of boards in sx.h
248 if you want more than 4 boards. */ 243 if you want more than 4 boards. */
@@ -251,21 +246,12 @@
251#define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000 246#define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
252#endif 247#endif
253 248
254#ifdef CONFIG_PCI
255static struct pci_device_id sx_pci_tbl[] = {
256 { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, PCI_ANY_ID, PCI_ANY_ID },
257 { 0 }
258};
259MODULE_DEVICE_TABLE(pci, sx_pci_tbl);
260#endif /* CONFIG_PCI */
261
262/* Configurable options: 249/* Configurable options:
263 (Don't be too sure that it'll work if you toggle them) */ 250 (Don't be too sure that it'll work if you toggle them) */
264 251
265/* Am I paranoid or not ? ;-) */ 252/* Am I paranoid or not ? ;-) */
266#undef SX_PARANOIA_CHECK 253#undef SX_PARANOIA_CHECK
267 254
268
269/* 20 -> 2000 per second. The card should rate-limit interrupts at 100 255/* 20 -> 2000 per second. The card should rate-limit interrupts at 100
270 Hz, but it is user configurable. I don't recommend going above 1000 256 Hz, but it is user configurable. I don't recommend going above 1000
271 Hz. The interrupt ratelimit might trigger if the interrupt is 257 Hz. The interrupt ratelimit might trigger if the interrupt is
@@ -279,7 +265,6 @@ MODULE_DEVICE_TABLE(pci, sx_pci_tbl);
279 interrupt. Use polling. */ 265 interrupt. Use polling. */
280#undef IRQ_RATE_LIMIT 266#undef IRQ_RATE_LIMIT
281 267
282
283#if 0 268#if 0
284/* Not implemented */ 269/* Not implemented */
285/* 270/*
@@ -288,35 +273,33 @@ MODULE_DEVICE_TABLE(pci, sx_pci_tbl);
288 */ 273 */
289#define SX_REPORT_FIFO 274#define SX_REPORT_FIFO
290#define SX_REPORT_OVERRUN 275#define SX_REPORT_OVERRUN
291#endif 276#endif
292
293 277
294/* Function prototypes */ 278/* Function prototypes */
295static void sx_disable_tx_interrupts (void * ptr); 279static void sx_disable_tx_interrupts(void *ptr);
296static void sx_enable_tx_interrupts (void * ptr); 280static void sx_enable_tx_interrupts(void *ptr);
297static void sx_disable_rx_interrupts (void * ptr); 281static void sx_disable_rx_interrupts(void *ptr);
298static void sx_enable_rx_interrupts (void * ptr); 282static void sx_enable_rx_interrupts(void *ptr);
299static int sx_get_CD (void * ptr); 283static int sx_get_CD(void *ptr);
300static void sx_shutdown_port (void * ptr); 284static void sx_shutdown_port(void *ptr);
301static int sx_set_real_termios (void *ptr); 285static int sx_set_real_termios(void *ptr);
302static void sx_close (void *ptr); 286static void sx_close(void *ptr);
303static int sx_chars_in_buffer (void * ptr); 287static int sx_chars_in_buffer(void *ptr);
304static int sx_init_board (struct sx_board *board); 288static int sx_init_board(struct sx_board *board);
305static int sx_init_portstructs (int nboards, int nports); 289static int sx_init_portstructs(int nboards, int nports);
306static int sx_fw_ioctl (struct inode *inode, struct file *filp, 290static int sx_fw_ioctl(struct inode *inode, struct file *filp,
307 unsigned int cmd, unsigned long arg); 291 unsigned int cmd, unsigned long arg);
308static int sx_init_drivers(void); 292static int sx_init_drivers(void);
309 293
310
311static struct tty_driver *sx_driver; 294static struct tty_driver *sx_driver;
312 295
296static DEFINE_MUTEX(sx_boards_lock);
313static struct sx_board boards[SX_NBOARDS]; 297static struct sx_board boards[SX_NBOARDS];
314static struct sx_port *sx_ports; 298static struct sx_port *sx_ports;
315static int sx_initialized; 299static int sx_initialized;
316static int sx_nports; 300static int sx_nports;
317static int sx_debug; 301static int sx_debug;
318 302
319
320/* You can have the driver poll your card. 303/* You can have the driver poll your card.
321 - Set sx_poll to 1 to poll every timer tick (10ms on Intel). 304 - Set sx_poll to 1 to poll every timer tick (10ms on Intel).
322 This is used when the card cannot use an interrupt for some reason. 305 This is used when the card cannot use an interrupt for some reason.
@@ -335,27 +318,36 @@ static int sx_slowpoll;
335 318
336static int sx_maxints = 100; 319static int sx_maxints = 100;
337 320
321#ifdef CONFIG_ISA
322
338/* These are the only open spaces in my computer. Yours may have more 323/* These are the only open spaces in my computer. Yours may have more
339 or less.... -- REW 324 or less.... -- REW
340 duh: Card at 0xa0000 is possible on HP Netserver?? -- pvdl 325 duh: Card at 0xa0000 is possible on HP Netserver?? -- pvdl
341*/ 326*/
342static int sx_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000, 327static int sx_probe_addrs[] = {
343 0xc8000, 0xd8000, 0xe8000}; 328 0xc0000, 0xd0000, 0xe0000,
344static int si_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000, 329 0xc8000, 0xd8000, 0xe8000
345 0xc8000, 0xd8000, 0xe8000, 0xa0000}; 330};
346static int si1_probe_addrs[]= { 0xd0000}; 331static int si_probe_addrs[] = {
332 0xc0000, 0xd0000, 0xe0000,
333 0xc8000, 0xd8000, 0xe8000, 0xa0000
334};
335static int si1_probe_addrs[] = {
336 0xd0000
337};
347 338
348#define NR_SX_ADDRS ARRAY_SIZE(sx_probe_addrs) 339#define NR_SX_ADDRS ARRAY_SIZE(sx_probe_addrs)
349#define NR_SI_ADDRS ARRAY_SIZE(si_probe_addrs) 340#define NR_SI_ADDRS ARRAY_SIZE(si_probe_addrs)
350#define NR_SI1_ADDRS ARRAY_SIZE(si1_probe_addrs) 341#define NR_SI1_ADDRS ARRAY_SIZE(si1_probe_addrs)
351 342
343module_param_array(sx_probe_addrs, int, NULL, 0);
344module_param_array(si_probe_addrs, int, NULL, 0);
345#endif
352 346
353/* Set the mask to all-ones. This alas, only supports 32 interrupts. 347/* Set the mask to all-ones. This alas, only supports 32 interrupts.
354 Some architectures may need more. */ 348 Some architectures may need more. */
355static int sx_irqmask = -1; 349static int sx_irqmask = -1;
356 350
357module_param_array(sx_probe_addrs, int, NULL, 0);
358module_param_array(si_probe_addrs, int, NULL, 0);
359module_param(sx_poll, int, 0); 351module_param(sx_poll, int, 0);
360module_param(sx_slowpoll, int, 0); 352module_param(sx_slowpoll, int, 0);
361module_param(sx_maxints, int, 0); 353module_param(sx_maxints, int, 0);
@@ -370,13 +362,12 @@ static struct real_driver sx_real_driver = {
370 sx_disable_rx_interrupts, 362 sx_disable_rx_interrupts,
371 sx_enable_rx_interrupts, 363 sx_enable_rx_interrupts,
372 sx_get_CD, 364 sx_get_CD,
373 sx_shutdown_port, 365 sx_shutdown_port,
374 sx_set_real_termios, 366 sx_set_real_termios,
375 sx_chars_in_buffer, 367 sx_chars_in_buffer,
376 sx_close, 368 sx_close,
377}; 369};
378 370
379
380/* 371/*
381 This driver can spew a whole lot of debugging output at you. If you 372 This driver can spew a whole lot of debugging output at you. If you
382 need maximum performance, you should disable the DEBUG define. To 373 need maximum performance, you should disable the DEBUG define. To
@@ -387,23 +378,17 @@ static struct real_driver sx_real_driver = {
387*/ 378*/
388#define DEBUG 379#define DEBUG
389 380
390
391#ifdef DEBUG 381#ifdef DEBUG
392#define sx_dprintk(f, str...) if (sx_debug & f) printk (str) 382#define sx_dprintk(f, str...) if (sx_debug & f) printk (str)
393#else 383#else
394#define sx_dprintk(f, str...) /* nothing */ 384#define sx_dprintk(f, str...) /* nothing */
395#endif 385#endif
396 386
387#define func_enter() sx_dprintk(SX_DEBUG_FLOW, "sx: enter %s\n",__FUNCTION__)
388#define func_exit() sx_dprintk(SX_DEBUG_FLOW, "sx: exit %s\n",__FUNCTION__)
397 389
398 390#define func_enter2() sx_dprintk(SX_DEBUG_FLOW, "sx: enter %s (port %d)\n", \
399#define func_enter() sx_dprintk (SX_DEBUG_FLOW, "sx: enter %s\n",__FUNCTION__) 391 __FUNCTION__, port->line)
400#define func_exit() sx_dprintk (SX_DEBUG_FLOW, "sx: exit %s\n", __FUNCTION__)
401
402#define func_enter2() sx_dprintk (SX_DEBUG_FLOW, "sx: enter %s (port %d)\n", \
403 __FUNCTION__, port->line)
404
405
406
407 392
408/* 393/*
409 * Firmware loader driver specific routines 394 * Firmware loader driver specific routines
@@ -411,31 +396,26 @@ static struct real_driver sx_real_driver = {
411 */ 396 */
412 397
413static const struct file_operations sx_fw_fops = { 398static const struct file_operations sx_fw_fops = {
414 .owner = THIS_MODULE, 399 .owner = THIS_MODULE,
415 .ioctl = sx_fw_ioctl, 400 .ioctl = sx_fw_ioctl,
416}; 401};
417 402
418static struct miscdevice sx_fw_device = { 403static struct miscdevice sx_fw_device = {
419 SXCTL_MISC_MINOR, "sxctl", &sx_fw_fops 404 SXCTL_MISC_MINOR, "sxctl", &sx_fw_fops
420}; 405};
421 406
422
423
424
425
426#ifdef SX_PARANOIA_CHECK 407#ifdef SX_PARANOIA_CHECK
427 408
428/* This doesn't work. Who's paranoid around here? Not me! */ 409/* This doesn't work. Who's paranoid around here? Not me! */
429 410
430static inline int sx_paranoia_check(struct sx_port const * port, 411static inline int sx_paranoia_check(struct sx_port const *port,
431 char *name, const char *routine) 412 char *name, const char *routine)
432{ 413{
414 static const char *badmagic = KERN_ERR "sx: Warning: bad sx port magic "
415 "number for device %s in %s\n";
416 static const char *badinfo = KERN_ERR "sx: Warning: null sx port for "
417 "device %s in %s\n";
433 418
434 static const char *badmagic =
435 KERN_ERR "sx: Warning: bad sx port magic number for device %s in %s\n";
436 static const char *badinfo =
437 KERN_ERR "sx: Warning: null sx port for device %s in %s\n";
438
439 if (!port) { 419 if (!port) {
440 printk(badinfo, name, routine); 420 printk(badinfo, name, routine);
441 return 1; 421 return 1;
@@ -458,23 +438,24 @@ static inline int sx_paranoia_check(struct sx_port const * port,
458#define TIMEOUT_1 30 438#define TIMEOUT_1 30
459#define TIMEOUT_2 1000000 439#define TIMEOUT_2 1000000
460 440
461
462#ifdef DEBUG 441#ifdef DEBUG
463static void my_hd_io(void __iomem *p, int len) 442static void my_hd_io(void __iomem *p, int len)
464{ 443{
465 int i, j, ch; 444 int i, j, ch;
466 unsigned char __iomem *addr = p; 445 unsigned char __iomem *addr = p;
467 446
468 for (i=0;i<len;i+=16) { 447 for (i = 0; i < len; i += 16) {
469 printk ("%p ", addr+i); 448 printk("%p ", addr + i);
470 for (j=0;j<16;j++) { 449 for (j = 0; j < 16; j++) {
471 printk ("%02x %s", readb(addr+j+i), (j==7)?" ":""); 450 printk("%02x %s", readb(addr + j + i),
451 (j == 7) ? " " : "");
472 } 452 }
473 for (j=0;j<16;j++) { 453 for (j = 0; j < 16; j++) {
474 ch = readb(addr+j+i); 454 ch = readb(addr + j + i);
475 printk ("%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch)); 455 printk("%c", (ch < 0x20) ? '.' :
456 ((ch > 0x7f) ? '.' : ch));
476 } 457 }
477 printk ("\n"); 458 printk("\n");
478 } 459 }
479} 460}
480static void my_hd(void *p, int len) 461static void my_hd(void *p, int len)
@@ -482,419 +463,468 @@ static void my_hd(void *p, int len)
482 int i, j, ch; 463 int i, j, ch;
483 unsigned char *addr = p; 464 unsigned char *addr = p;
484 465
485 for (i=0;i<len;i+=16) { 466 for (i = 0; i < len; i += 16) {
486 printk ("%p ", addr+i); 467 printk("%p ", addr + i);
487 for (j=0;j<16;j++) { 468 for (j = 0; j < 16; j++) {
488 printk ("%02x %s", addr[j+i], (j==7)?" ":""); 469 printk("%02x %s", addr[j + i], (j == 7) ? " " : "");
489 } 470 }
490 for (j=0;j<16;j++) { 471 for (j = 0; j < 16; j++) {
491 ch = addr[j+i]; 472 ch = addr[j + i];
492 printk ("%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch)); 473 printk("%c", (ch < 0x20) ? '.' :
474 ((ch > 0x7f) ? '.' : ch));
493 } 475 }
494 printk ("\n"); 476 printk("\n");
495 } 477 }
496} 478}
497#endif 479#endif
498 480
499
500
501/* This needs redoing for Alpha -- REW -- Done. */ 481/* This needs redoing for Alpha -- REW -- Done. */
502 482
503static inline void write_sx_byte (struct sx_board *board, int offset, u8 byte) 483static inline void write_sx_byte(struct sx_board *board, int offset, u8 byte)
504{ 484{
505 writeb (byte, board->base+offset); 485 writeb(byte, board->base + offset);
506} 486}
507 487
508static inline u8 read_sx_byte (struct sx_board *board, int offset) 488static inline u8 read_sx_byte(struct sx_board *board, int offset)
509{ 489{
510 return readb (board->base+offset); 490 return readb(board->base + offset);
511} 491}
512 492
513 493static inline void write_sx_word(struct sx_board *board, int offset, u16 word)
514static inline void write_sx_word (struct sx_board *board, int offset, u16 word)
515{ 494{
516 writew (word, board->base+offset); 495 writew(word, board->base + offset);
517} 496}
518 497
519static inline u16 read_sx_word (struct sx_board *board, int offset) 498static inline u16 read_sx_word(struct sx_board *board, int offset)
520{ 499{
521 return readw (board->base + offset); 500 return readw(board->base + offset);
522} 501}
523 502
524 503static int sx_busy_wait_eq(struct sx_board *board,
525static int sx_busy_wait_eq (struct sx_board *board, 504 int offset, int mask, int correctval)
526 int offset, int mask, int correctval)
527{ 505{
528 int i; 506 int i;
529 507
530 func_enter (); 508 func_enter();
531 509
532 for (i=0; i < TIMEOUT_1 ;i++) 510 for (i = 0; i < TIMEOUT_1; i++)
533 if ((read_sx_byte (board, offset) & mask) == correctval) { 511 if ((read_sx_byte(board, offset) & mask) == correctval) {
534 func_exit (); 512 func_exit();
535 return 1; 513 return 1;
536 } 514 }
537 515
538 for (i=0; i < TIMEOUT_2 ;i++) { 516 for (i = 0; i < TIMEOUT_2; i++) {
539 if ((read_sx_byte (board, offset) & mask) == correctval) { 517 if ((read_sx_byte(board, offset) & mask) == correctval) {
540 func_exit (); 518 func_exit();
541 return 1; 519 return 1;
542 } 520 }
543 udelay (1); 521 udelay(1);
544 } 522 }
545 523
546 func_exit (); 524 func_exit();
547 return 0; 525 return 0;
548} 526}
549 527
550 528static int sx_busy_wait_neq(struct sx_board *board,
551static int sx_busy_wait_neq (struct sx_board *board, 529 int offset, int mask, int badval)
552 int offset, int mask, int badval)
553{ 530{
554 int i; 531 int i;
555 532
556 func_enter (); 533 func_enter();
557 534
558 for (i=0; i < TIMEOUT_1 ;i++) 535 for (i = 0; i < TIMEOUT_1; i++)
559 if ((read_sx_byte (board, offset) & mask) != badval) { 536 if ((read_sx_byte(board, offset) & mask) != badval) {
560 func_exit (); 537 func_exit();
561 return 1; 538 return 1;
562 } 539 }
563 540
564 for (i=0; i < TIMEOUT_2 ;i++) { 541 for (i = 0; i < TIMEOUT_2; i++) {
565 if ((read_sx_byte (board, offset) & mask) != badval) { 542 if ((read_sx_byte(board, offset) & mask) != badval) {
566 func_exit (); 543 func_exit();
567 return 1; 544 return 1;
568 } 545 }
569 udelay (1); 546 udelay(1);
570 } 547 }
571 548
572 func_exit (); 549 func_exit();
573 return 0; 550 return 0;
574} 551}
575 552
576
577
578/* 5.6.4 of 6210028 r2.3 */ 553/* 5.6.4 of 6210028 r2.3 */
579static int sx_reset (struct sx_board *board) 554static int sx_reset(struct sx_board *board)
580{ 555{
581 func_enter (); 556 func_enter();
582 557
583 if (IS_SX_BOARD (board)) { 558 if (IS_SX_BOARD(board)) {
584 559
585 write_sx_byte (board, SX_CONFIG, 0); 560 write_sx_byte(board, SX_CONFIG, 0);
586 write_sx_byte (board, SX_RESET, 1); /* Value doesn't matter */ 561 write_sx_byte(board, SX_RESET, 1); /* Value doesn't matter */
587 562
588 if (!sx_busy_wait_eq (board, SX_RESET_STATUS, 1, 0)) { 563 if (!sx_busy_wait_eq(board, SX_RESET_STATUS, 1, 0)) {
589 printk (KERN_INFO "sx: Card doesn't respond to reset....\n"); 564 printk(KERN_INFO "sx: Card doesn't respond to "
565 "reset...\n");
590 return 0; 566 return 0;
591 } 567 }
592 } else if (IS_EISA_BOARD(board)) { 568 } else if (IS_EISA_BOARD(board)) {
593 outb(board->irq<<4, board->eisa_base+0xc02); 569 outb(board->irq << 4, board->eisa_base + 0xc02);
594 } else if (IS_SI1_BOARD(board)) { 570 } else if (IS_SI1_BOARD(board)) {
595 write_sx_byte (board, SI1_ISA_RESET, 0); // value does not matter 571 write_sx_byte(board, SI1_ISA_RESET, 0); /*value doesn't matter*/
596 } else { 572 } else {
597 /* Gory details of the SI/ISA board */ 573 /* Gory details of the SI/ISA board */
598 write_sx_byte (board, SI2_ISA_RESET, SI2_ISA_RESET_SET); 574 write_sx_byte(board, SI2_ISA_RESET, SI2_ISA_RESET_SET);
599 write_sx_byte (board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_CLEAR); 575 write_sx_byte(board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_CLEAR);
600 write_sx_byte (board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_CLEAR); 576 write_sx_byte(board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_CLEAR);
601 write_sx_byte (board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_CLEAR); 577 write_sx_byte(board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_CLEAR);
602 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_CLEAR); 578 write_sx_byte(board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_CLEAR);
603 write_sx_byte (board, SI2_ISA_IRQSET, SI2_ISA_IRQSET_CLEAR); 579 write_sx_byte(board, SI2_ISA_IRQSET, SI2_ISA_IRQSET_CLEAR);
604 } 580 }
605 581
606 func_exit (); 582 func_exit();
607 return 1; 583 return 1;
608} 584}
609 585
610
611/* This doesn't work on machines where "NULL" isn't 0 */ 586/* This doesn't work on machines where "NULL" isn't 0 */
612/* If you have one of those, someone will need to write 587/* If you have one of those, someone will need to write
613 the equivalent of this, which will amount to about 3 lines. I don't 588 the equivalent of this, which will amount to about 3 lines. I don't
614 want to complicate this right now. -- REW 589 want to complicate this right now. -- REW
615 (See, I do write comments every now and then :-) */ 590 (See, I do write comments every now and then :-) */
616#define OFFSETOF(strct, elem) ((long)&(((struct strct *)NULL)->elem)) 591#define OFFSETOF(strct, elem) ((long)&(((struct strct *)NULL)->elem))
617
618
619#define CHAN_OFFSET(port,elem) (port->ch_base + OFFSETOF (_SXCHANNEL, elem))
620#define MODU_OFFSET(board,addr,elem) (addr + OFFSETOF (_SXMODULE, elem))
621#define BRD_OFFSET(board,elem) (OFFSETOF (_SXCARD, elem))
622 592
593#define CHAN_OFFSET(port,elem) (port->ch_base + OFFSETOF (_SXCHANNEL, elem))
594#define MODU_OFFSET(board,addr,elem) (addr + OFFSETOF (_SXMODULE, elem))
595#define BRD_OFFSET(board,elem) (OFFSETOF (_SXCARD, elem))
623 596
624#define sx_write_channel_byte(port, elem, val) \ 597#define sx_write_channel_byte(port, elem, val) \
625 write_sx_byte (port->board, CHAN_OFFSET (port, elem), val) 598 write_sx_byte (port->board, CHAN_OFFSET (port, elem), val)
626 599
627#define sx_read_channel_byte(port, elem) \ 600#define sx_read_channel_byte(port, elem) \
628 read_sx_byte (port->board, CHAN_OFFSET (port, elem)) 601 read_sx_byte (port->board, CHAN_OFFSET (port, elem))
629 602
630#define sx_write_channel_word(port, elem, val) \ 603#define sx_write_channel_word(port, elem, val) \
631 write_sx_word (port->board, CHAN_OFFSET (port, elem), val) 604 write_sx_word (port->board, CHAN_OFFSET (port, elem), val)
632 605
633#define sx_read_channel_word(port, elem) \ 606#define sx_read_channel_word(port, elem) \
634 read_sx_word (port->board, CHAN_OFFSET (port, elem)) 607 read_sx_word (port->board, CHAN_OFFSET (port, elem))
635
636 608
637#define sx_write_module_byte(board, addr, elem, val) \ 609#define sx_write_module_byte(board, addr, elem, val) \
638 write_sx_byte (board, MODU_OFFSET (board, addr, elem), val) 610 write_sx_byte (board, MODU_OFFSET (board, addr, elem), val)
639 611
640#define sx_read_module_byte(board, addr, elem) \ 612#define sx_read_module_byte(board, addr, elem) \
641 read_sx_byte (board, MODU_OFFSET (board, addr, elem)) 613 read_sx_byte (board, MODU_OFFSET (board, addr, elem))
642 614
643#define sx_write_module_word(board, addr, elem, val) \ 615#define sx_write_module_word(board, addr, elem, val) \
644 write_sx_word (board, MODU_OFFSET (board, addr, elem), val) 616 write_sx_word (board, MODU_OFFSET (board, addr, elem), val)
645 617
646#define sx_read_module_word(board, addr, elem) \ 618#define sx_read_module_word(board, addr, elem) \
647 read_sx_word (board, MODU_OFFSET (board, addr, elem)) 619 read_sx_word (board, MODU_OFFSET (board, addr, elem))
648
649 620
650#define sx_write_board_byte(board, elem, val) \ 621#define sx_write_board_byte(board, elem, val) \
651 write_sx_byte (board, BRD_OFFSET (board, elem), val) 622 write_sx_byte (board, BRD_OFFSET (board, elem), val)
652 623
653#define sx_read_board_byte(board, elem) \ 624#define sx_read_board_byte(board, elem) \
654 read_sx_byte (board, BRD_OFFSET (board, elem)) 625 read_sx_byte (board, BRD_OFFSET (board, elem))
655 626
656#define sx_write_board_word(board, elem, val) \ 627#define sx_write_board_word(board, elem, val) \
657 write_sx_word (board, BRD_OFFSET (board, elem), val) 628 write_sx_word (board, BRD_OFFSET (board, elem), val)
658 629
659#define sx_read_board_word(board, elem) \ 630#define sx_read_board_word(board, elem) \
660 read_sx_word (board, BRD_OFFSET (board, elem)) 631 read_sx_word (board, BRD_OFFSET (board, elem))
661
662 632
663static int sx_start_board (struct sx_board *board) 633static int sx_start_board(struct sx_board *board)
664{ 634{
665 if (IS_SX_BOARD (board)) { 635 if (IS_SX_BOARD(board)) {
666 write_sx_byte (board, SX_CONFIG, SX_CONF_BUSEN); 636 write_sx_byte(board, SX_CONFIG, SX_CONF_BUSEN);
667 } else if (IS_EISA_BOARD(board)) { 637 } else if (IS_EISA_BOARD(board)) {
668 write_sx_byte(board, SI2_EISA_OFF, SI2_EISA_VAL); 638 write_sx_byte(board, SI2_EISA_OFF, SI2_EISA_VAL);
669 outb((board->irq<<4)|4, board->eisa_base+0xc02); 639 outb((board->irq << 4) | 4, board->eisa_base + 0xc02);
670 } else if (IS_SI1_BOARD(board)) { 640 } else if (IS_SI1_BOARD(board)) {
671 write_sx_byte (board, SI1_ISA_RESET_CLEAR, 0); 641 write_sx_byte(board, SI1_ISA_RESET_CLEAR, 0);
672 write_sx_byte (board, SI1_ISA_INTCL, 0); 642 write_sx_byte(board, SI1_ISA_INTCL, 0);
673 } else { 643 } else {
674 /* Don't bug me about the clear_set. 644 /* Don't bug me about the clear_set.
675 I haven't the foggiest idea what it's about -- REW */ 645 I haven't the foggiest idea what it's about -- REW */
676 write_sx_byte (board, SI2_ISA_RESET, SI2_ISA_RESET_CLEAR); 646 write_sx_byte(board, SI2_ISA_RESET, SI2_ISA_RESET_CLEAR);
677 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET); 647 write_sx_byte(board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
678 } 648 }
679 return 1; 649 return 1;
680} 650}
681 651
682#define SX_IRQ_REG_VAL(board) \ 652#define SX_IRQ_REG_VAL(board) \
683 ((board->flags & SX_ISA_BOARD)?(board->irq << 4):0) 653 ((board->flags & SX_ISA_BOARD) ? (board->irq << 4) : 0)
684 654
685/* Note. The SX register is write-only. Therefore, we have to enable the 655/* Note. The SX register is write-only. Therefore, we have to enable the
686 bus too. This is a no-op, if you don't mess with this driver... */ 656 bus too. This is a no-op, if you don't mess with this driver... */
687static int sx_start_interrupts (struct sx_board *board) 657static int sx_start_interrupts(struct sx_board *board)
688{ 658{
689 659
690 /* Don't call this with board->irq == 0 */ 660 /* Don't call this with board->irq == 0 */
691 661
692 if (IS_SX_BOARD(board)) { 662 if (IS_SX_BOARD(board)) {
693 write_sx_byte (board, SX_CONFIG, SX_IRQ_REG_VAL (board) | 663 write_sx_byte(board, SX_CONFIG, SX_IRQ_REG_VAL(board) |
694 SX_CONF_BUSEN | 664 SX_CONF_BUSEN | SX_CONF_HOSTIRQ);
695 SX_CONF_HOSTIRQ);
696 } else if (IS_EISA_BOARD(board)) { 665 } else if (IS_EISA_BOARD(board)) {
697 inb(board->eisa_base+0xc03); 666 inb(board->eisa_base + 0xc03);
698 } else if (IS_SI1_BOARD(board)) { 667 } else if (IS_SI1_BOARD(board)) {
699 write_sx_byte (board, SI1_ISA_INTCL,0); 668 write_sx_byte(board, SI1_ISA_INTCL, 0);
700 write_sx_byte (board, SI1_ISA_INTCL_CLEAR,0); 669 write_sx_byte(board, SI1_ISA_INTCL_CLEAR, 0);
701 } else { 670 } else {
702 switch (board->irq) { 671 switch (board->irq) {
703 case 11:write_sx_byte (board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_SET);break; 672 case 11:
704 case 12:write_sx_byte (board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_SET);break; 673 write_sx_byte(board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_SET);
705 case 15:write_sx_byte (board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_SET);break; 674 break;
706 default:printk (KERN_INFO "sx: SI/XIO card doesn't support interrupt %d.\n", 675 case 12:
707 board->irq); 676 write_sx_byte(board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_SET);
708 return 0; 677 break;
678 case 15:
679 write_sx_byte(board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_SET);
680 break;
681 default:
682 printk(KERN_INFO "sx: SI/XIO card doesn't support "
683 "interrupt %d.\n", board->irq);
684 return 0;
709 } 685 }
710 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET); 686 write_sx_byte(board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
711 } 687 }
712 688
713 return 1; 689 return 1;
714} 690}
715 691
716 692static int sx_send_command(struct sx_port *port,
717static int sx_send_command (struct sx_port *port, 693 int command, int mask, int newstat)
718 int command, int mask, int newstat)
719{ 694{
720 func_enter2 (); 695 func_enter2();
721 write_sx_byte (port->board, CHAN_OFFSET (port, hi_hstat), command); 696 write_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat), command);
722 func_exit (); 697 func_exit();
723 return sx_busy_wait_eq (port->board, CHAN_OFFSET (port, hi_hstat), mask, newstat); 698 return sx_busy_wait_eq(port->board, CHAN_OFFSET(port, hi_hstat), mask,
699 newstat);
724} 700}
725 701
726 702static char *mod_type_s(int module_type)
727static char *mod_type_s (int module_type)
728{ 703{
729 switch (module_type) { 704 switch (module_type) {
730 case TA4: return "TA4"; 705 case TA4:
731 case TA8: return "TA8"; 706 return "TA4";
732 case TA4_ASIC: return "TA4_ASIC"; 707 case TA8:
733 case TA8_ASIC: return "TA8_ASIC"; 708 return "TA8";
734 case MTA_CD1400:return "MTA_CD1400"; 709 case TA4_ASIC:
735 case SXDC: return "SXDC"; 710 return "TA4_ASIC";
736 default:return "Unknown/invalid"; 711 case TA8_ASIC:
712 return "TA8_ASIC";
713 case MTA_CD1400:
714 return "MTA_CD1400";
715 case SXDC:
716 return "SXDC";
717 default:
718 return "Unknown/invalid";
737 } 719 }
738} 720}
739 721
740 722static char *pan_type_s(int pan_type)
741static char *pan_type_s (int pan_type)
742{ 723{
743 switch (pan_type) { 724 switch (pan_type) {
744 case MOD_RS232DB25: return "MOD_RS232DB25"; 725 case MOD_RS232DB25:
745 case MOD_RS232RJ45: return "MOD_RS232RJ45"; 726 return "MOD_RS232DB25";
746 case MOD_RS422DB25: return "MOD_RS422DB25"; 727 case MOD_RS232RJ45:
747 case MOD_PARALLEL: return "MOD_PARALLEL"; 728 return "MOD_RS232RJ45";
748 case MOD_2_RS232DB25: return "MOD_2_RS232DB25"; 729 case MOD_RS422DB25:
749 case MOD_2_RS232RJ45: return "MOD_2_RS232RJ45"; 730 return "MOD_RS422DB25";
750 case MOD_2_RS422DB25: return "MOD_2_RS422DB25"; 731 case MOD_PARALLEL:
751 case MOD_RS232DB25MALE: return "MOD_RS232DB25MALE"; 732 return "MOD_PARALLEL";
752 case MOD_2_PARALLEL: return "MOD_2_PARALLEL"; 733 case MOD_2_RS232DB25:
753 case MOD_BLANK: return "empty"; 734 return "MOD_2_RS232DB25";
754 default:return "invalid"; 735 case MOD_2_RS232RJ45:
736 return "MOD_2_RS232RJ45";
737 case MOD_2_RS422DB25:
738 return "MOD_2_RS422DB25";
739 case MOD_RS232DB25MALE:
740 return "MOD_RS232DB25MALE";
741 case MOD_2_PARALLEL:
742 return "MOD_2_PARALLEL";
743 case MOD_BLANK:
744 return "empty";
745 default:
746 return "invalid";
755 } 747 }
756} 748}
757 749
758 750static int mod_compat_type(int module_type)
759static int mod_compat_type (int module_type)
760{ 751{
761 return module_type >> 4; 752 return module_type >> 4;
762} 753}
763 754
764static void sx_reconfigure_port(struct sx_port *port) 755static void sx_reconfigure_port(struct sx_port *port)
765{ 756{
766 if (sx_read_channel_byte (port, hi_hstat) == HS_IDLE_OPEN) { 757 if (sx_read_channel_byte(port, hi_hstat) == HS_IDLE_OPEN) {
767 if (sx_send_command (port, HS_CONFIG, -1, HS_IDLE_OPEN) != 1) { 758 if (sx_send_command(port, HS_CONFIG, -1, HS_IDLE_OPEN) != 1) {
768 printk (KERN_WARNING "sx: Sent reconfigure command, but card didn't react.\n"); 759 printk(KERN_WARNING "sx: Sent reconfigure command, but "
760 "card didn't react.\n");
769 } 761 }
770 } else { 762 } else {
771 sx_dprintk (SX_DEBUG_TERMIOS, 763 sx_dprintk(SX_DEBUG_TERMIOS, "sx: Not sending reconfigure: "
772 "sx: Not sending reconfigure: port isn't open (%02x).\n", 764 "port isn't open (%02x).\n",
773 sx_read_channel_byte (port, hi_hstat)); 765 sx_read_channel_byte(port, hi_hstat));
774 } 766 }
775} 767}
776 768
777static void sx_setsignals (struct sx_port *port, int dtr, int rts) 769static void sx_setsignals(struct sx_port *port, int dtr, int rts)
778{ 770{
779 int t; 771 int t;
780 func_enter2 (); 772 func_enter2();
781 773
782 t = sx_read_channel_byte (port, hi_op); 774 t = sx_read_channel_byte(port, hi_op);
783 if (dtr >= 0) t = dtr? (t | OP_DTR): (t & ~OP_DTR); 775 if (dtr >= 0)
784 if (rts >= 0) t = rts? (t | OP_RTS): (t & ~OP_RTS); 776 t = dtr ? (t | OP_DTR) : (t & ~OP_DTR);
785 sx_write_channel_byte (port, hi_op, t); 777 if (rts >= 0)
786 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "setsignals: %d/%d\n", dtr, rts); 778 t = rts ? (t | OP_RTS) : (t & ~OP_RTS);
779 sx_write_channel_byte(port, hi_op, t);
780 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "setsignals: %d/%d\n", dtr, rts);
787 781
788 func_exit (); 782 func_exit();
789} 783}
790 784
791 785static int sx_getsignals(struct sx_port *port)
792
793static int sx_getsignals (struct sx_port *port)
794{ 786{
795 int i_stat,o_stat; 787 int i_stat, o_stat;
796 788
797 o_stat = sx_read_channel_byte (port, hi_op); 789 o_stat = sx_read_channel_byte(port, hi_op);
798 i_stat = sx_read_channel_byte (port, hi_ip); 790 i_stat = sx_read_channel_byte(port, hi_ip);
799 791
800 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "getsignals: %d/%d (%d/%d) %02x/%02x\n", 792 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "getsignals: %d/%d (%d/%d) "
801 (o_stat & OP_DTR) != 0, (o_stat & OP_RTS) != 0, 793 "%02x/%02x\n",
802 port->c_dcd, sx_get_CD (port), 794 (o_stat & OP_DTR) != 0, (o_stat & OP_RTS) != 0,
803 sx_read_channel_byte (port, hi_ip), 795 port->c_dcd, sx_get_CD(port),
804 sx_read_channel_byte (port, hi_state)); 796 sx_read_channel_byte(port, hi_ip),
805 797 sx_read_channel_byte(port, hi_state));
806 return (((o_stat & OP_DTR)?TIOCM_DTR:0) | 798
807 ((o_stat & OP_RTS)?TIOCM_RTS:0) | 799 return (((o_stat & OP_DTR) ? TIOCM_DTR : 0) |
808 ((i_stat & IP_CTS)?TIOCM_CTS:0) | 800 ((o_stat & OP_RTS) ? TIOCM_RTS : 0) |
809 ((i_stat & IP_DCD)?TIOCM_CAR:0) | 801 ((i_stat & IP_CTS) ? TIOCM_CTS : 0) |
810 ((i_stat & IP_DSR)?TIOCM_DSR:0) | 802 ((i_stat & IP_DCD) ? TIOCM_CAR : 0) |
811 ((i_stat & IP_RI)?TIOCM_RNG:0) 803 ((i_stat & IP_DSR) ? TIOCM_DSR : 0) |
812 ); 804 ((i_stat & IP_RI) ? TIOCM_RNG : 0));
813} 805}
814 806
815 807static void sx_set_baud(struct sx_port *port)
816static void sx_set_baud (struct sx_port *port)
817{ 808{
818 int t; 809 int t;
819 810
820 if (port->board->ta_type == MOD_SXDC) { 811 if (port->board->ta_type == MOD_SXDC) {
821 switch (port->gs.baud) { 812 switch (port->gs.baud) {
822 /* Save some typing work... */ 813 /* Save some typing work... */
823#define e(x) case x:t= BAUD_ ## x ; break 814#define e(x) case x: t = BAUD_ ## x; break
824 e(50);e(75);e(110);e(150);e(200);e(300);e(600); 815 e(50);
825 e(1200);e(1800);e(2000);e(2400);e(4800);e(7200); 816 e(75);
826 e(9600);e(14400);e(19200);e(28800);e(38400); 817 e(110);
827 e(56000);e(57600);e(64000);e(76800);e(115200); 818 e(150);
828 e(128000);e(150000);e(230400);e(256000);e(460800); 819 e(200);
829 e(921600); 820 e(300);
830 case 134 :t = BAUD_134_5; break; 821 e(600);
831 case 0 :t = -1; 822 e(1200);
832 break; 823 e(1800);
824 e(2000);
825 e(2400);
826 e(4800);
827 e(7200);
828 e(9600);
829 e(14400);
830 e(19200);
831 e(28800);
832 e(38400);
833 e(56000);
834 e(57600);
835 e(64000);
836 e(76800);
837 e(115200);
838 e(128000);
839 e(150000);
840 e(230400);
841 e(256000);
842 e(460800);
843 e(921600);
844 case 134:
845 t = BAUD_134_5;
846 break;
847 case 0:
848 t = -1;
849 break;
833 default: 850 default:
834 /* Can I return "invalid"? */ 851 /* Can I return "invalid"? */
835 t = BAUD_9600; 852 t = BAUD_9600;
836 printk (KERN_INFO "sx: unsupported baud rate: %d.\n", port->gs.baud); 853 printk(KERN_INFO "sx: unsupported baud rate: %d.\n",
854 port->gs.baud);
837 break; 855 break;
838 } 856 }
839#undef e 857#undef e
840 if (t > 0) { 858 if (t > 0) {
841 /* The baud rate is not set to 0, so we're enabeling DTR... -- REW */ 859/* The baud rate is not set to 0, so we're enabeling DTR... -- REW */
842 sx_setsignals (port, 1, -1); 860 sx_setsignals(port, 1, -1);
843 /* XXX This is not TA & MTA compatible */ 861 /* XXX This is not TA & MTA compatible */
844 sx_write_channel_byte (port, hi_csr, 0xff); 862 sx_write_channel_byte(port, hi_csr, 0xff);
845 863
846 sx_write_channel_byte (port, hi_txbaud, t); 864 sx_write_channel_byte(port, hi_txbaud, t);
847 sx_write_channel_byte (port, hi_rxbaud, t); 865 sx_write_channel_byte(port, hi_rxbaud, t);
848 } else { 866 } else {
849 sx_setsignals (port, 0, -1); 867 sx_setsignals(port, 0, -1);
850 } 868 }
851 } else { 869 } else {
852 switch (port->gs.baud) { 870 switch (port->gs.baud) {
853#define e(x) case x:t= CSR_ ## x ; break 871#define e(x) case x: t = CSR_ ## x; break
854 e(75);e(150);e(300);e(600);e(1200);e(2400);e(4800); 872 e(75);
855 e(1800);e(9600); 873 e(150);
856 e(19200);e(57600);e(38400); 874 e(300);
857 /* TA supports 110, but not 115200, MTA supports 115200, but not 110 */ 875 e(600);
858 case 110: 876 e(1200);
877 e(2400);
878 e(4800);
879 e(1800);
880 e(9600);
881 e(19200);
882 e(57600);
883 e(38400);
884/* TA supports 110, but not 115200, MTA supports 115200, but not 110 */
885 case 110:
859 if (port->board->ta_type == MOD_TA) { 886 if (port->board->ta_type == MOD_TA) {
860 t = CSR_110; 887 t = CSR_110;
861 break; 888 break;
862 } else { 889 } else {
863 t = CSR_9600; 890 t = CSR_9600;
864 printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud); 891 printk(KERN_INFO "sx: Unsupported baud rate: "
892 "%d.\n", port->gs.baud);
865 break; 893 break;
866 } 894 }
867 case 115200: 895 case 115200:
868 if (port->board->ta_type == MOD_TA) { 896 if (port->board->ta_type == MOD_TA) {
869 t = CSR_9600; 897 t = CSR_9600;
870 printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud); 898 printk(KERN_INFO "sx: Unsupported baud rate: "
899 "%d.\n", port->gs.baud);
871 break; 900 break;
872 } else { 901 } else {
873 t = CSR_110; 902 t = CSR_110;
874 break; 903 break;
875 } 904 }
876 case 0 :t = -1; 905 case 0:
877 break; 906 t = -1;
907 break;
878 default: 908 default:
879 t = CSR_9600; 909 t = CSR_9600;
880 printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud); 910 printk(KERN_INFO "sx: Unsupported baud rate: %d.\n",
911 port->gs.baud);
881 break; 912 break;
882 } 913 }
883#undef e 914#undef e
884 if (t >= 0) { 915 if (t >= 0) {
885 sx_setsignals (port, 1, -1); 916 sx_setsignals(port, 1, -1);
886 sx_write_channel_byte (port, hi_csr, t * 0x11); 917 sx_write_channel_byte(port, hi_csr, t * 0x11);
887 } else { 918 } else {
888 sx_setsignals (port, 0, -1); 919 sx_setsignals(port, 0, -1);
889 } 920 }
890 } 921 }
891} 922}
892 923
893
894/* Simon Allen's version of this routine was 225 lines long. 85 is a lot 924/* Simon Allen's version of this routine was 225 lines long. 85 is a lot
895 better. -- REW */ 925 better. -- REW */
896 926
897static int sx_set_real_termios (void *ptr) 927static int sx_set_real_termios(void *ptr)
898{ 928{
899 struct sx_port *port = ptr; 929 struct sx_port *port = ptr;
900 930
@@ -909,80 +939,83 @@ static int sx_set_real_termios (void *ptr)
909 belongs (next to the drop dtr if baud == 0) -- REW */ 939 belongs (next to the drop dtr if baud == 0) -- REW */
910 /* sx_setsignals (port, 1, -1); */ 940 /* sx_setsignals (port, 1, -1); */
911 941
912 sx_set_baud (port); 942 sx_set_baud(port);
913 943
914#define CFLAG port->gs.tty->termios->c_cflag 944#define CFLAG port->gs.tty->termios->c_cflag
915 sx_write_channel_byte (port, hi_mr1, 945 sx_write_channel_byte(port, hi_mr1,
916 (C_PARENB (port->gs.tty)? MR1_WITH:MR1_NONE) | 946 (C_PARENB(port->gs.tty) ? MR1_WITH : MR1_NONE) |
917 (C_PARODD (port->gs.tty)? MR1_ODD:MR1_EVEN) | 947 (C_PARODD(port->gs.tty) ? MR1_ODD : MR1_EVEN) |
918 (C_CRTSCTS(port->gs.tty)? MR1_RTS_RXFLOW:0) | 948 (C_CRTSCTS(port->gs.tty) ? MR1_RTS_RXFLOW : 0) |
919 (((CFLAG & CSIZE)==CS8) ? MR1_8_BITS:0) | 949 (((CFLAG & CSIZE) == CS8) ? MR1_8_BITS : 0) |
920 (((CFLAG & CSIZE)==CS7) ? MR1_7_BITS:0) | 950 (((CFLAG & CSIZE) == CS7) ? MR1_7_BITS : 0) |
921 (((CFLAG & CSIZE)==CS6) ? MR1_6_BITS:0) | 951 (((CFLAG & CSIZE) == CS6) ? MR1_6_BITS : 0) |
922 (((CFLAG & CSIZE)==CS5) ? MR1_5_BITS:0) ); 952 (((CFLAG & CSIZE) == CS5) ? MR1_5_BITS : 0));
923 953
924 sx_write_channel_byte (port, hi_mr2, 954 sx_write_channel_byte(port, hi_mr2,
925 (C_CRTSCTS(port->gs.tty)?MR2_CTS_TXFLOW:0) | 955 (C_CRTSCTS(port->gs.tty) ? MR2_CTS_TXFLOW : 0) |
926 (C_CSTOPB (port->gs.tty)?MR2_2_STOP:MR2_1_STOP)); 956 (C_CSTOPB(port->gs.tty) ? MR2_2_STOP :
957 MR2_1_STOP));
927 958
928 switch (CFLAG & CSIZE) { 959 switch (CFLAG & CSIZE) {
929 case CS8:sx_write_channel_byte (port, hi_mask, 0xff);break; 960 case CS8:
930 case CS7:sx_write_channel_byte (port, hi_mask, 0x7f);break; 961 sx_write_channel_byte(port, hi_mask, 0xff);
931 case CS6:sx_write_channel_byte (port, hi_mask, 0x3f);break; 962 break;
932 case CS5:sx_write_channel_byte (port, hi_mask, 0x1f);break; 963 case CS7:
964 sx_write_channel_byte(port, hi_mask, 0x7f);
965 break;
966 case CS6:
967 sx_write_channel_byte(port, hi_mask, 0x3f);
968 break;
969 case CS5:
970 sx_write_channel_byte(port, hi_mask, 0x1f);
971 break;
933 default: 972 default:
934 printk (KERN_INFO "sx: Invalid wordsize: %u\n", CFLAG & CSIZE); 973 printk(KERN_INFO "sx: Invalid wordsize: %u\n", CFLAG & CSIZE);
935 break; 974 break;
936 } 975 }
937 976
938 sx_write_channel_byte (port, hi_prtcl, 977 sx_write_channel_byte(port, hi_prtcl,
939 (I_IXON (port->gs.tty)?SP_TXEN:0) | 978 (I_IXON(port->gs.tty) ? SP_TXEN : 0) |
940 (I_IXOFF (port->gs.tty)?SP_RXEN:0) | 979 (I_IXOFF(port->gs.tty) ? SP_RXEN : 0) |
941 (I_IXANY (port->gs.tty)?SP_TANY:0) | 980 (I_IXANY(port->gs.tty) ? SP_TANY : 0) | SP_DCEN);
942 SP_DCEN);
943 981
944 sx_write_channel_byte (port, hi_break, 982 sx_write_channel_byte(port, hi_break,
945 (I_IGNBRK(port->gs.tty)?BR_IGN:0 | 983 (I_IGNBRK(port->gs.tty) ? BR_IGN : 0 |
946 I_BRKINT(port->gs.tty)?BR_INT:0)); 984 I_BRKINT(port->gs.tty) ? BR_INT : 0));
947 985
948 sx_write_channel_byte (port, hi_txon, START_CHAR (port->gs.tty)); 986 sx_write_channel_byte(port, hi_txon, START_CHAR(port->gs.tty));
949 sx_write_channel_byte (port, hi_rxon, START_CHAR (port->gs.tty)); 987 sx_write_channel_byte(port, hi_rxon, START_CHAR(port->gs.tty));
950 sx_write_channel_byte (port, hi_txoff, STOP_CHAR (port->gs.tty)); 988 sx_write_channel_byte(port, hi_txoff, STOP_CHAR(port->gs.tty));
951 sx_write_channel_byte (port, hi_rxoff, STOP_CHAR (port->gs.tty)); 989 sx_write_channel_byte(port, hi_rxoff, STOP_CHAR(port->gs.tty));
952 990
953 sx_reconfigure_port(port); 991 sx_reconfigure_port(port);
954 992
955 /* Tell line discipline whether we will do input cooking */ 993 /* Tell line discipline whether we will do input cooking */
956 if(I_OTHER(port->gs.tty)) { 994 if (I_OTHER(port->gs.tty)) {
957 clear_bit(TTY_HW_COOK_IN, &port->gs.tty->flags); 995 clear_bit(TTY_HW_COOK_IN, &port->gs.tty->flags);
958 } else { 996 } else {
959 set_bit(TTY_HW_COOK_IN, &port->gs.tty->flags); 997 set_bit(TTY_HW_COOK_IN, &port->gs.tty->flags);
960 } 998 }
961 sx_dprintk (SX_DEBUG_TERMIOS, "iflags: %x(%d) ", 999 sx_dprintk(SX_DEBUG_TERMIOS, "iflags: %x(%d) ",
962 port->gs.tty->termios->c_iflag, 1000 port->gs.tty->termios->c_iflag, I_OTHER(port->gs.tty));
963 I_OTHER(port->gs.tty));
964
965 1001
966/* Tell line discipline whether we will do output cooking. 1002/* Tell line discipline whether we will do output cooking.
967 * If OPOST is set and no other output flags are set then we can do output 1003 * If OPOST is set and no other output flags are set then we can do output
968 * processing. Even if only *one* other flag in the O_OTHER group is set 1004 * processing. Even if only *one* other flag in the O_OTHER group is set
969 * we do cooking in software. 1005 * we do cooking in software.
970 */ 1006 */
971 if(O_OPOST(port->gs.tty) && !O_OTHER(port->gs.tty)) { 1007 if (O_OPOST(port->gs.tty) && !O_OTHER(port->gs.tty)) {
972 set_bit(TTY_HW_COOK_OUT, &port->gs.tty->flags); 1008 set_bit(TTY_HW_COOK_OUT, &port->gs.tty->flags);
973 } else { 1009 } else {
974 clear_bit(TTY_HW_COOK_OUT, &port->gs.tty->flags); 1010 clear_bit(TTY_HW_COOK_OUT, &port->gs.tty->flags);
975 } 1011 }
976 sx_dprintk (SX_DEBUG_TERMIOS, "oflags: %x(%d)\n", 1012 sx_dprintk(SX_DEBUG_TERMIOS, "oflags: %x(%d)\n",
977 port->gs.tty->termios->c_oflag, 1013 port->gs.tty->termios->c_oflag, O_OTHER(port->gs.tty));
978 O_OTHER(port->gs.tty));
979 /* port->c_dcd = sx_get_CD (port); */ 1014 /* port->c_dcd = sx_get_CD (port); */
980 func_exit (); 1015 func_exit();
981 return 0; 1016 return 0;
982} 1017}
983 1018
984
985
986/* ********************************************************************** * 1019/* ********************************************************************** *
987 * the interrupt related routines * 1020 * the interrupt related routines *
988 * ********************************************************************** */ 1021 * ********************************************************************** */
@@ -998,245 +1031,260 @@ static int sx_set_real_termios (void *ptr)
998 know I'm dead against that, but I think it is required in this 1031 know I'm dead against that, but I think it is required in this
999 case. */ 1032 case. */
1000 1033
1001 1034static void sx_transmit_chars(struct sx_port *port)
1002static void sx_transmit_chars (struct sx_port *port)
1003{ 1035{
1004 int c; 1036 int c;
1005 int tx_ip; 1037 int tx_ip;
1006 int txroom; 1038 int txroom;
1007 1039
1008 func_enter2 (); 1040 func_enter2();
1009 sx_dprintk (SX_DEBUG_TRANSMIT, "Port %p: transmit %d chars\n", 1041 sx_dprintk(SX_DEBUG_TRANSMIT, "Port %p: transmit %d chars\n",
1010 port, port->gs.xmit_cnt); 1042 port, port->gs.xmit_cnt);
1011 1043
1012 if (test_and_set_bit (SX_PORT_TRANSMIT_LOCK, &port->locks)) { 1044 if (test_and_set_bit(SX_PORT_TRANSMIT_LOCK, &port->locks)) {
1013 return; 1045 return;
1014 } 1046 }
1015 1047
1016 while (1) { 1048 while (1) {
1017 c = port->gs.xmit_cnt; 1049 c = port->gs.xmit_cnt;
1018 1050
1019 sx_dprintk (SX_DEBUG_TRANSMIT, "Copying %d ", c); 1051 sx_dprintk(SX_DEBUG_TRANSMIT, "Copying %d ", c);
1020 tx_ip = sx_read_channel_byte (port, hi_txipos); 1052 tx_ip = sx_read_channel_byte(port, hi_txipos);
1021 1053
1022 /* Took me 5 minutes to deduce this formula. 1054 /* Took me 5 minutes to deduce this formula.
1023 Luckily it is literally in the manual in section 6.5.4.3.5 */ 1055 Luckily it is literally in the manual in section 6.5.4.3.5 */
1024 txroom = (sx_read_channel_byte (port, hi_txopos) - tx_ip - 1) & 0xff; 1056 txroom = (sx_read_channel_byte(port, hi_txopos) - tx_ip - 1) &
1057 0xff;
1025 1058
1026 /* Don't copy more bytes than there is room for in the buffer */ 1059 /* Don't copy more bytes than there is room for in the buffer */
1027 if (c > txroom) 1060 if (c > txroom)
1028 c = txroom; 1061 c = txroom;
1029 sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%d) ", c, txroom ); 1062 sx_dprintk(SX_DEBUG_TRANSMIT, " %d(%d) ", c, txroom);
1030 1063
1031 /* Don't copy past the end of the hardware transmit buffer */ 1064 /* Don't copy past the end of the hardware transmit buffer */
1032 if (c > 0x100 - tx_ip) 1065 if (c > 0x100 - tx_ip)
1033 c = 0x100 - tx_ip; 1066 c = 0x100 - tx_ip;
1034 1067
1035 sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%d) ", c, 0x100-tx_ip ); 1068 sx_dprintk(SX_DEBUG_TRANSMIT, " %d(%d) ", c, 0x100 - tx_ip);
1036 1069
1037 /* Don't copy pas the end of the source buffer */ 1070 /* Don't copy pas the end of the source buffer */
1038 if (c > SERIAL_XMIT_SIZE - port->gs.xmit_tail) 1071 if (c > SERIAL_XMIT_SIZE - port->gs.xmit_tail)
1039 c = SERIAL_XMIT_SIZE - port->gs.xmit_tail; 1072 c = SERIAL_XMIT_SIZE - port->gs.xmit_tail;
1040 1073
1041 sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%ld) \n", 1074 sx_dprintk(SX_DEBUG_TRANSMIT, " %d(%ld) \n",
1042 c, SERIAL_XMIT_SIZE- port->gs.xmit_tail); 1075 c, SERIAL_XMIT_SIZE - port->gs.xmit_tail);
1043
1044 /* If for one reason or another, we can't copy more data, we're done! */
1045 if (c == 0) break;
1046 1076
1077 /* If for one reason or another, we can't copy more data, we're
1078 done! */
1079 if (c == 0)
1080 break;
1047 1081
1048 memcpy_toio (port->board->base + CHAN_OFFSET(port,hi_txbuf) + tx_ip, 1082 memcpy_toio(port->board->base + CHAN_OFFSET(port, hi_txbuf) +
1049 port->gs.xmit_buf + port->gs.xmit_tail, c); 1083 tx_ip, port->gs.xmit_buf + port->gs.xmit_tail, c);
1050 1084
1051 /* Update the pointer in the card */ 1085 /* Update the pointer in the card */
1052 sx_write_channel_byte (port, hi_txipos, (tx_ip+c) & 0xff); 1086 sx_write_channel_byte(port, hi_txipos, (tx_ip + c) & 0xff);
1053 1087
1054 /* Update the kernel buffer end */ 1088 /* Update the kernel buffer end */
1055 port->gs.xmit_tail = (port->gs.xmit_tail + c) & (SERIAL_XMIT_SIZE-1); 1089 port->gs.xmit_tail = (port->gs.xmit_tail + c) &
1090 (SERIAL_XMIT_SIZE - 1);
1056 1091
1057 /* This one last. (this is essential) 1092 /* This one last. (this is essential)
1058 It would allow others to start putting more data into the buffer! */ 1093 It would allow others to start putting more data into the
1094 buffer! */
1059 port->gs.xmit_cnt -= c; 1095 port->gs.xmit_cnt -= c;
1060 } 1096 }
1061 1097
1062 if (port->gs.xmit_cnt == 0) { 1098 if (port->gs.xmit_cnt == 0) {
1063 sx_disable_tx_interrupts (port); 1099 sx_disable_tx_interrupts(port);
1064 } 1100 }
1065 1101
1066 if ((port->gs.xmit_cnt <= port->gs.wakeup_chars) && port->gs.tty) { 1102 if ((port->gs.xmit_cnt <= port->gs.wakeup_chars) && port->gs.tty) {
1067 tty_wakeup(port->gs.tty); 1103 tty_wakeup(port->gs.tty);
1068 sx_dprintk (SX_DEBUG_TRANSMIT, "Waking up.... ldisc (%d)....\n", 1104 sx_dprintk(SX_DEBUG_TRANSMIT, "Waking up.... ldisc (%d)....\n",
1069 port->gs.wakeup_chars); 1105 port->gs.wakeup_chars);
1070 } 1106 }
1071 1107
1072 clear_bit (SX_PORT_TRANSMIT_LOCK, &port->locks); 1108 clear_bit(SX_PORT_TRANSMIT_LOCK, &port->locks);
1073 func_exit (); 1109 func_exit();
1074} 1110}
1075 1111
1076
1077/* Note the symmetry between receiving chars and transmitting them! 1112/* Note the symmetry between receiving chars and transmitting them!
1078 Note: The kernel should have implemented both a receive buffer and 1113 Note: The kernel should have implemented both a receive buffer and
1079 a transmit buffer. */ 1114 a transmit buffer. */
1080 1115
1081/* Inlined: Called only once. Remove the inline when you add another call */ 1116/* Inlined: Called only once. Remove the inline when you add another call */
1082static inline void sx_receive_chars (struct sx_port *port) 1117static inline void sx_receive_chars(struct sx_port *port)
1083{ 1118{
1084 int c; 1119 int c;
1085 int rx_op; 1120 int rx_op;
1086 struct tty_struct *tty; 1121 struct tty_struct *tty;
1087 int copied=0; 1122 int copied = 0;
1088 unsigned char *rp; 1123 unsigned char *rp;
1089 1124
1090 func_enter2 (); 1125 func_enter2();
1091 tty = port->gs.tty; 1126 tty = port->gs.tty;
1092 while (1) { 1127 while (1) {
1093 rx_op = sx_read_channel_byte (port, hi_rxopos); 1128 rx_op = sx_read_channel_byte(port, hi_rxopos);
1094 c = (sx_read_channel_byte (port, hi_rxipos) - rx_op) & 0xff; 1129 c = (sx_read_channel_byte(port, hi_rxipos) - rx_op) & 0xff;
1095 1130
1096 sx_dprintk (SX_DEBUG_RECEIVE, "rxop=%d, c = %d.\n", rx_op, c); 1131 sx_dprintk(SX_DEBUG_RECEIVE, "rxop=%d, c = %d.\n", rx_op, c);
1097 1132
1098 /* Don't copy past the end of the hardware receive buffer */ 1133 /* Don't copy past the end of the hardware receive buffer */
1099 if (rx_op + c > 0x100) c = 0x100 - rx_op; 1134 if (rx_op + c > 0x100)
1135 c = 0x100 - rx_op;
1100 1136
1101 sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c); 1137 sx_dprintk(SX_DEBUG_RECEIVE, "c = %d.\n", c);
1102 1138
1103 /* Don't copy more bytes than there is room for in the buffer */ 1139 /* Don't copy more bytes than there is room for in the buffer */
1104 1140
1105 c = tty_prepare_flip_string(tty, &rp, c); 1141 c = tty_prepare_flip_string(tty, &rp, c);
1106 1142
1107 sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c); 1143 sx_dprintk(SX_DEBUG_RECEIVE, "c = %d.\n", c);
1108 1144
1109 /* If for one reason or another, we can't copy more data, we're done! */ 1145 /* If for one reason or another, we can't copy more data, we're done! */
1110 if (c == 0) break; 1146 if (c == 0)
1147 break;
1111 1148
1112 sx_dprintk (SX_DEBUG_RECEIVE , "Copying over %d chars. First is %d at %lx\n", c, 1149 sx_dprintk(SX_DEBUG_RECEIVE, "Copying over %d chars. First is "
1113 read_sx_byte (port->board, CHAN_OFFSET(port,hi_rxbuf) + rx_op), 1150 "%d at %lx\n", c, read_sx_byte(port->board,
1114 CHAN_OFFSET(port, hi_rxbuf)); 1151 CHAN_OFFSET(port, hi_rxbuf) + rx_op),
1115 memcpy_fromio (rp, 1152 CHAN_OFFSET(port, hi_rxbuf));
1116 port->board->base + CHAN_OFFSET(port,hi_rxbuf) + rx_op, c); 1153 memcpy_fromio(rp, port->board->base +
1154 CHAN_OFFSET(port, hi_rxbuf) + rx_op, c);
1117 1155
1118 /* This one last. ( Not essential.) 1156 /* This one last. ( Not essential.)
1119 It allows the card to start putting more data into the buffer! 1157 It allows the card to start putting more data into the
1158 buffer!
1120 Update the pointer in the card */ 1159 Update the pointer in the card */
1121 sx_write_channel_byte (port, hi_rxopos, (rx_op + c) & 0xff); 1160 sx_write_channel_byte(port, hi_rxopos, (rx_op + c) & 0xff);
1122 1161
1123 copied += c; 1162 copied += c;
1124 } 1163 }
1125 if (copied) { 1164 if (copied) {
1126 struct timeval tv; 1165 struct timeval tv;
1127 1166
1128 do_gettimeofday (&tv); 1167 do_gettimeofday(&tv);
1129 sx_dprintk (SX_DEBUG_RECEIVE, 1168 sx_dprintk(SX_DEBUG_RECEIVE, "pushing flipq port %d (%3d "
1130 "pushing flipq port %d (%3d chars): %d.%06d (%d/%d)\n", 1169 "chars): %d.%06d (%d/%d)\n", port->line,
1131 port->line, copied, 1170 copied, (int)(tv.tv_sec % 60), (int)tv.tv_usec,
1132 (int) (tv.tv_sec % 60), (int)tv.tv_usec, tty->raw, tty->real_raw); 1171 tty->raw, tty->real_raw);
1133 1172
1134 /* Tell the rest of the system the news. Great news. New characters! */ 1173 /* Tell the rest of the system the news. Great news. New
1135 tty_flip_buffer_push (tty); 1174 characters! */
1175 tty_flip_buffer_push(tty);
1136 /* tty_schedule_flip (tty); */ 1176 /* tty_schedule_flip (tty); */
1137 } 1177 }
1138 1178
1139 func_exit (); 1179 func_exit();
1140} 1180}
1141 1181
1142/* Inlined: it is called only once. Remove the inline if you add another 1182/* Inlined: it is called only once. Remove the inline if you add another
1143 call */ 1183 call */
1144static inline void sx_check_modem_signals (struct sx_port *port) 1184static inline void sx_check_modem_signals(struct sx_port *port)
1145{ 1185{
1146 int hi_state; 1186 int hi_state;
1147 int c_dcd; 1187 int c_dcd;
1148 1188
1149 hi_state = sx_read_channel_byte (port, hi_state); 1189 hi_state = sx_read_channel_byte(port, hi_state);
1150 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "Checking modem signals (%d/%d)\n", 1190 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "Checking modem signals (%d/%d)\n",
1151 port->c_dcd, sx_get_CD (port)); 1191 port->c_dcd, sx_get_CD(port));
1152 1192
1153 if (hi_state & ST_BREAK) { 1193 if (hi_state & ST_BREAK) {
1154 hi_state &= ~ST_BREAK; 1194 hi_state &= ~ST_BREAK;
1155 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "got a break.\n"); 1195 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "got a break.\n");
1156 sx_write_channel_byte (port, hi_state, hi_state); 1196 sx_write_channel_byte(port, hi_state, hi_state);
1157 gs_got_break (&port->gs); 1197 gs_got_break(&port->gs);
1158 } 1198 }
1159 if (hi_state & ST_DCD) { 1199 if (hi_state & ST_DCD) {
1160 hi_state &= ~ST_DCD; 1200 hi_state &= ~ST_DCD;
1161 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "got a DCD change.\n"); 1201 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "got a DCD change.\n");
1162 sx_write_channel_byte (port, hi_state, hi_state); 1202 sx_write_channel_byte(port, hi_state, hi_state);
1163 c_dcd = sx_get_CD (port); 1203 c_dcd = sx_get_CD(port);
1164 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD is now %d\n", c_dcd); 1204 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD is now %d\n", c_dcd);
1165 if (c_dcd != port->c_dcd) { 1205 if (c_dcd != port->c_dcd) {
1166 port->c_dcd = c_dcd; 1206 port->c_dcd = c_dcd;
1167 if (sx_get_CD (port)) { 1207 if (sx_get_CD(port)) {
1168 /* DCD went UP */ 1208 /* DCD went UP */
1169 if ((sx_read_channel_byte(port, hi_hstat) != HS_IDLE_CLOSED) && 1209 if ((sx_read_channel_byte(port, hi_hstat) !=
1170 !(port->gs.tty->termios->c_cflag & CLOCAL) ) { 1210 HS_IDLE_CLOSED) &&
1171 /* Are we blocking in open?*/ 1211 !(port->gs.tty->termios->
1172 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD active, unblocking open\n"); 1212 c_cflag & CLOCAL)) {
1173 wake_up_interruptible(&port->gs.open_wait); 1213 /* Are we blocking in open? */
1214 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD "
1215 "active, unblocking open\n");
1216 wake_up_interruptible(&port->gs.
1217 open_wait);
1174 } else { 1218 } else {
1175 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD raised. Ignoring.\n"); 1219 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD "
1220 "raised. Ignoring.\n");
1176 } 1221 }
1177 } else { 1222 } else {
1178 /* DCD went down! */ 1223 /* DCD went down! */
1179 if (!(port->gs.tty->termios->c_cflag & CLOCAL) ) { 1224 if (!(port->gs.tty->termios->c_cflag & CLOCAL)){
1180 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD dropped. hanging up....\n"); 1225 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD "
1181 tty_hangup (port->gs.tty); 1226 "dropped. hanging up....\n");
1227 tty_hangup(port->gs.tty);
1182 } else { 1228 } else {
1183 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD dropped. ignoring.\n"); 1229 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD "
1230 "dropped. ignoring.\n");
1184 } 1231 }
1185 } 1232 }
1186 } else { 1233 } else {
1187 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "Hmmm. card told us DCD changed, but it didn't.\n"); 1234 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "Hmmm. card told us "
1235 "DCD changed, but it didn't.\n");
1188 } 1236 }
1189 } 1237 }
1190} 1238}
1191 1239
1192
1193/* This is what an interrupt routine should look like. 1240/* This is what an interrupt routine should look like.
1194 * Small, elegant, clear. 1241 * Small, elegant, clear.
1195 */ 1242 */
1196 1243
1197static irqreturn_t sx_interrupt (int irq, void *ptr, struct pt_regs *regs) 1244static irqreturn_t sx_interrupt(int irq, void *ptr)
1198{ 1245{
1199 struct sx_board *board = ptr; 1246 struct sx_board *board = ptr;
1200 struct sx_port *port; 1247 struct sx_port *port;
1201 int i; 1248 int i;
1202 1249
1203 func_enter (); 1250 func_enter();
1204 sx_dprintk (SX_DEBUG_FLOW, "sx: enter sx_interrupt (%d/%d)\n", irq, board->irq); 1251 sx_dprintk(SX_DEBUG_FLOW, "sx: enter sx_interrupt (%d/%d)\n", irq,
1252 board->irq);
1205 1253
1206 /* AAargh! The order in which to do these things is essential and 1254 /* AAargh! The order in which to do these things is essential and
1207 not trivial. 1255 not trivial.
1208 1256
1209 - Rate limit goes before "recursive". Otherwise a series of 1257 - Rate limit goes before "recursive". Otherwise a series of
1210 recursive calls will hang the machine in the interrupt routine. 1258 recursive calls will hang the machine in the interrupt routine.
1211 1259
1212 - hardware twiddling goes before "recursive". Otherwise when we 1260 - hardware twiddling goes before "recursive". Otherwise when we
1213 poll the card, and a recursive interrupt happens, we won't 1261 poll the card, and a recursive interrupt happens, we won't
1214 ack the card, so it might keep on interrupting us. (especially 1262 ack the card, so it might keep on interrupting us. (especially
1215 level sensitive interrupt systems like PCI). 1263 level sensitive interrupt systems like PCI).
1216 1264
1217 - Rate limit goes before hardware twiddling. Otherwise we won't 1265 - Rate limit goes before hardware twiddling. Otherwise we won't
1218 catch a card that has gone bonkers. 1266 catch a card that has gone bonkers.
1219 1267
1220 - The "initialized" test goes after the hardware twiddling. Otherwise 1268 - The "initialized" test goes after the hardware twiddling. Otherwise
1221 the card will stick us in the interrupt routine again. 1269 the card will stick us in the interrupt routine again.
1222 1270
1223 - The initialized test goes before recursive. 1271 - The initialized test goes before recursive.
1224 */ 1272 */
1225
1226
1227 1273
1228#ifdef IRQ_RATE_LIMIT 1274#ifdef IRQ_RATE_LIMIT
1229 /* Aaargh! I'm ashamed. This costs more lines-of-code than the 1275 /* Aaargh! I'm ashamed. This costs more lines-of-code than the
1230 actual interrupt routine!. (Well, used to when I wrote that comment) */ 1276 actual interrupt routine!. (Well, used to when I wrote that
1277 comment) */
1231 { 1278 {
1232 static int lastjif; 1279 static int lastjif;
1233 static int nintr=0; 1280 static int nintr = 0;
1234 1281
1235 if (lastjif == jiffies) { 1282 if (lastjif == jiffies) {
1236 if (++nintr > IRQ_RATE_LIMIT) { 1283 if (++nintr > IRQ_RATE_LIMIT) {
1237 free_irq (board->irq, board); 1284 free_irq(board->irq, board);
1238 printk (KERN_ERR "sx: Too many interrupts. Turning off interrupt %d.\n", 1285 printk(KERN_ERR "sx: Too many interrupts. "
1239 board->irq); 1286 "Turning off interrupt %d.\n",
1287 board->irq);
1240 } 1288 }
1241 } else { 1289 } else {
1242 lastjif = jiffies; 1290 lastjif = jiffies;
@@ -1245,19 +1293,20 @@ static irqreturn_t sx_interrupt (int irq, void *ptr, struct pt_regs *regs)
1245 } 1293 }
1246#endif 1294#endif
1247 1295
1248
1249 if (board->irq == irq) { 1296 if (board->irq == irq) {
1250 /* Tell the card we've noticed the interrupt. */ 1297 /* Tell the card we've noticed the interrupt. */
1251 1298
1252 sx_write_board_word (board, cc_int_pending, 0); 1299 sx_write_board_word(board, cc_int_pending, 0);
1253 if (IS_SX_BOARD (board)) { 1300 if (IS_SX_BOARD(board)) {
1254 write_sx_byte (board, SX_RESET_IRQ, 1); 1301 write_sx_byte(board, SX_RESET_IRQ, 1);
1255 } else if (IS_EISA_BOARD(board)) { 1302 } else if (IS_EISA_BOARD(board)) {
1256 inb(board->eisa_base+0xc03); 1303 inb(board->eisa_base + 0xc03);
1257 write_sx_word(board, 8, 0); 1304 write_sx_word(board, 8, 0);
1258 } else { 1305 } else {
1259 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_CLEAR); 1306 write_sx_byte(board, SI2_ISA_INTCLEAR,
1260 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET); 1307 SI2_ISA_INTCLEAR_CLEAR);
1308 write_sx_byte(board, SI2_ISA_INTCLEAR,
1309 SI2_ISA_INTCLEAR_SET);
1261 } 1310 }
1262 } 1311 }
1263 1312
@@ -1266,53 +1315,48 @@ static irqreturn_t sx_interrupt (int irq, void *ptr, struct pt_regs *regs)
1266 if (!(board->flags & SX_BOARD_INITIALIZED)) 1315 if (!(board->flags & SX_BOARD_INITIALIZED))
1267 return IRQ_HANDLED; 1316 return IRQ_HANDLED;
1268 1317
1269 if (test_and_set_bit (SX_BOARD_INTR_LOCK, &board->locks)) { 1318 if (test_and_set_bit(SX_BOARD_INTR_LOCK, &board->locks)) {
1270 printk (KERN_ERR "Recursive interrupt! (%d)\n", board->irq); 1319 printk(KERN_ERR "Recursive interrupt! (%d)\n", board->irq);
1271 return IRQ_HANDLED; 1320 return IRQ_HANDLED;
1272 } 1321 }
1273 1322
1274 for (i=0;i<board->nports;i++) { 1323 for (i = 0; i < board->nports; i++) {
1275 port = &board->ports[i]; 1324 port = &board->ports[i];
1276 if (port->gs.flags & GS_ACTIVE) { 1325 if (port->gs.flags & GS_ACTIVE) {
1277 if (sx_read_channel_byte (port, hi_state)) { 1326 if (sx_read_channel_byte(port, hi_state)) {
1278 sx_dprintk (SX_DEBUG_INTERRUPTS, 1327 sx_dprintk(SX_DEBUG_INTERRUPTS, "Port %d: "
1279 "Port %d: modem signal change?... \n", i); 1328 "modem signal change?... \n",i);
1280 sx_check_modem_signals (port); 1329 sx_check_modem_signals(port);
1281 } 1330 }
1282 if (port->gs.xmit_cnt) { 1331 if (port->gs.xmit_cnt) {
1283 sx_transmit_chars (port); 1332 sx_transmit_chars(port);
1284 } 1333 }
1285 if (!(port->gs.flags & SX_RX_THROTTLE)) { 1334 if (!(port->gs.flags & SX_RX_THROTTLE)) {
1286 sx_receive_chars (port); 1335 sx_receive_chars(port);
1287 } 1336 }
1288 } 1337 }
1289 } 1338 }
1290 1339
1291 clear_bit (SX_BOARD_INTR_LOCK, &board->locks); 1340 clear_bit(SX_BOARD_INTR_LOCK, &board->locks);
1292 1341
1293 sx_dprintk (SX_DEBUG_FLOW, "sx: exit sx_interrupt (%d/%d)\n", irq, board->irq); 1342 sx_dprintk(SX_DEBUG_FLOW, "sx: exit sx_interrupt (%d/%d)\n", irq,
1294 func_exit (); 1343 board->irq);
1344 func_exit();
1295 return IRQ_HANDLED; 1345 return IRQ_HANDLED;
1296} 1346}
1297 1347
1298 1348static void sx_pollfunc(unsigned long data)
1299static void sx_pollfunc (unsigned long data)
1300{ 1349{
1301 struct sx_board *board = (struct sx_board *) data; 1350 struct sx_board *board = (struct sx_board *)data;
1302
1303 func_enter ();
1304 1351
1305 sx_interrupt (0, board, NULL); 1352 func_enter();
1306 1353
1307 init_timer(&board->timer); 1354 sx_interrupt(0, board);
1308 1355
1309 board->timer.expires = jiffies + sx_poll; 1356 mod_timer(&board->timer, jiffies + sx_poll);
1310 add_timer (&board->timer); 1357 func_exit();
1311 func_exit ();
1312} 1358}
1313 1359
1314
1315
1316/* ********************************************************************** * 1360/* ********************************************************************** *
1317 * Here are the routines that actually * 1361 * Here are the routines that actually *
1318 * interface with the generic_serial driver * 1362 * interface with the generic_serial driver *
@@ -1321,9 +1365,9 @@ static void sx_pollfunc (unsigned long data)
1321/* Ehhm. I don't know how to fiddle with interrupts on the SX card. --REW */ 1365/* Ehhm. I don't know how to fiddle with interrupts on the SX card. --REW */
1322/* Hmm. Ok I figured it out. You don't. */ 1366/* Hmm. Ok I figured it out. You don't. */
1323 1367
1324static void sx_disable_tx_interrupts (void * ptr) 1368static void sx_disable_tx_interrupts(void *ptr)
1325{ 1369{
1326 struct sx_port *port = ptr; 1370 struct sx_port *port = ptr;
1327 func_enter2(); 1371 func_enter2();
1328 1372
1329 port->gs.flags &= ~GS_TX_INTEN; 1373 port->gs.flags &= ~GS_TX_INTEN;
@@ -1331,30 +1375,28 @@ static void sx_disable_tx_interrupts (void * ptr)
1331 func_exit(); 1375 func_exit();
1332} 1376}
1333 1377
1334 1378static void sx_enable_tx_interrupts(void *ptr)
1335static void sx_enable_tx_interrupts (void * ptr)
1336{ 1379{
1337 struct sx_port *port = ptr; 1380 struct sx_port *port = ptr;
1338 int data_in_buffer; 1381 int data_in_buffer;
1339 func_enter2(); 1382 func_enter2();
1340 1383
1341 /* First transmit the characters that we're supposed to */ 1384 /* First transmit the characters that we're supposed to */
1342 sx_transmit_chars (port); 1385 sx_transmit_chars(port);
1343 1386
1344 /* The sx card will never interrupt us if we don't fill the buffer 1387 /* The sx card will never interrupt us if we don't fill the buffer
1345 past 25%. So we keep considering interrupts off if that's the case. */ 1388 past 25%. So we keep considering interrupts off if that's the case. */
1346 data_in_buffer = (sx_read_channel_byte (port, hi_txipos) - 1389 data_in_buffer = (sx_read_channel_byte(port, hi_txipos) -
1347 sx_read_channel_byte (port, hi_txopos)) & 0xff; 1390 sx_read_channel_byte(port, hi_txopos)) & 0xff;
1348 1391
1349 /* XXX Must be "HIGH_WATER" for SI card according to doc. */ 1392 /* XXX Must be "HIGH_WATER" for SI card according to doc. */
1350 if (data_in_buffer < LOW_WATER) 1393 if (data_in_buffer < LOW_WATER)
1351 port->gs.flags &= ~GS_TX_INTEN; 1394 port->gs.flags &= ~GS_TX_INTEN;
1352 1395
1353 func_exit(); 1396 func_exit();
1354} 1397}
1355 1398
1356 1399static void sx_disable_rx_interrupts(void *ptr)
1357static void sx_disable_rx_interrupts (void * ptr)
1358{ 1400{
1359 /* struct sx_port *port = ptr; */ 1401 /* struct sx_port *port = ptr; */
1360 func_enter(); 1402 func_enter();
@@ -1362,7 +1404,7 @@ static void sx_disable_rx_interrupts (void * ptr)
1362 func_exit(); 1404 func_exit();
1363} 1405}
1364 1406
1365static void sx_enable_rx_interrupts (void * ptr) 1407static void sx_enable_rx_interrupts(void *ptr)
1366{ 1408{
1367 /* struct sx_port *port = ptr; */ 1409 /* struct sx_port *port = ptr; */
1368 func_enter(); 1410 func_enter();
@@ -1370,55 +1412,48 @@ static void sx_enable_rx_interrupts (void * ptr)
1370 func_exit(); 1412 func_exit();
1371} 1413}
1372 1414
1373
1374/* Jeez. Isn't this simple? */ 1415/* Jeez. Isn't this simple? */
1375static int sx_get_CD (void * ptr) 1416static int sx_get_CD(void *ptr)
1376{ 1417{
1377 struct sx_port *port = ptr; 1418 struct sx_port *port = ptr;
1378 func_enter2(); 1419 func_enter2();
1379 1420
1380 func_exit(); 1421 func_exit();
1381 return ((sx_read_channel_byte (port, hi_ip) & IP_DCD) != 0); 1422 return ((sx_read_channel_byte(port, hi_ip) & IP_DCD) != 0);
1382} 1423}
1383 1424
1384
1385/* Jeez. Isn't this simple? */ 1425/* Jeez. Isn't this simple? */
1386static int sx_chars_in_buffer (void * ptr) 1426static int sx_chars_in_buffer(void *ptr)
1387{ 1427{
1388 struct sx_port *port = ptr; 1428 struct sx_port *port = ptr;
1389 func_enter2(); 1429 func_enter2();
1390 1430
1391 func_exit(); 1431 func_exit();
1392 return ((sx_read_channel_byte (port, hi_txipos) - 1432 return ((sx_read_channel_byte(port, hi_txipos) -
1393 sx_read_channel_byte (port, hi_txopos)) & 0xff); 1433 sx_read_channel_byte(port, hi_txopos)) & 0xff);
1394} 1434}
1395 1435
1396 1436static void sx_shutdown_port(void *ptr)
1397static void sx_shutdown_port (void * ptr)
1398{ 1437{
1399 struct sx_port *port = ptr; 1438 struct sx_port *port = ptr;
1400 1439
1401 func_enter(); 1440 func_enter();
1402 1441
1403 port->gs.flags &= ~ GS_ACTIVE; 1442 port->gs.flags &= ~GS_ACTIVE;
1404 if (port->gs.tty && (port->gs.tty->termios->c_cflag & HUPCL)) { 1443 if (port->gs.tty && (port->gs.tty->termios->c_cflag & HUPCL)) {
1405 sx_setsignals (port, 0, 0); 1444 sx_setsignals(port, 0, 0);
1406 sx_reconfigure_port(port); 1445 sx_reconfigure_port(port);
1407 } 1446 }
1408 1447
1409 func_exit(); 1448 func_exit();
1410} 1449}
1411 1450
1412
1413
1414
1415
1416/* ********************************************************************** * 1451/* ********************************************************************** *
1417 * Here are the routines that actually * 1452 * Here are the routines that actually *
1418 * interface with the rest of the system * 1453 * interface with the rest of the system *
1419 * ********************************************************************** */ 1454 * ********************************************************************** */
1420 1455
1421static int sx_open (struct tty_struct * tty, struct file * filp) 1456static int sx_open(struct tty_struct *tty, struct file *filp)
1422{ 1457{
1423 struct sx_port *port; 1458 struct sx_port *port;
1424 int retval, line; 1459 int retval, line;
@@ -1431,18 +1466,18 @@ static int sx_open (struct tty_struct * tty, struct file * filp)
1431 } 1466 }
1432 1467
1433 line = tty->index; 1468 line = tty->index;
1434 sx_dprintk (SX_DEBUG_OPEN, "%d: opening line %d. tty=%p ctty=%p, np=%d)\n", 1469 sx_dprintk(SX_DEBUG_OPEN, "%d: opening line %d. tty=%p ctty=%p, "
1435 current->pid, line, tty, current->signal->tty, sx_nports); 1470 "np=%d)\n", current->pid, line, tty,
1471 current->signal->tty, sx_nports);
1436 1472
1437 if ((line < 0) || (line >= SX_NPORTS) || (line >= sx_nports)) 1473 if ((line < 0) || (line >= SX_NPORTS) || (line >= sx_nports))
1438 return -ENODEV; 1474 return -ENODEV;
1439 1475
1440 port = & sx_ports[line]; 1476 port = &sx_ports[line];
1441 port->c_dcd = 0; /* Make sure that the first interrupt doesn't detect a 1477 port->c_dcd = 0; /* Make sure that the first interrupt doesn't detect a
1442 1 -> 0 transition. */ 1478 1 -> 0 transition. */
1443 1479
1444 1480 sx_dprintk(SX_DEBUG_OPEN, "port = %p c_dcd = %d\n", port, port->c_dcd);
1445 sx_dprintk (SX_DEBUG_OPEN, "port = %p c_dcd = %d\n", port, port->c_dcd);
1446 1481
1447 spin_lock_irqsave(&port->gs.driver_lock, flags); 1482 spin_lock_irqsave(&port->gs.driver_lock, flags);
1448 1483
@@ -1451,13 +1486,13 @@ static int sx_open (struct tty_struct * tty, struct file * filp)
1451 port->gs.count++; 1486 port->gs.count++;
1452 spin_unlock_irqrestore(&port->gs.driver_lock, flags); 1487 spin_unlock_irqrestore(&port->gs.driver_lock, flags);
1453 1488
1454 sx_dprintk (SX_DEBUG_OPEN, "starting port\n"); 1489 sx_dprintk(SX_DEBUG_OPEN, "starting port\n");
1455 1490
1456 /* 1491 /*
1457 * Start up serial port 1492 * Start up serial port
1458 */ 1493 */
1459 retval = gs_init_port(&port->gs); 1494 retval = gs_init_port(&port->gs);
1460 sx_dprintk (SX_DEBUG_OPEN, "done gs_init\n"); 1495 sx_dprintk(SX_DEBUG_OPEN, "done gs_init\n");
1461 if (retval) { 1496 if (retval) {
1462 port->gs.count--; 1497 port->gs.count--;
1463 return retval; 1498 return retval;
@@ -1465,19 +1500,20 @@ static int sx_open (struct tty_struct * tty, struct file * filp)
1465 1500
1466 port->gs.flags |= GS_ACTIVE; 1501 port->gs.flags |= GS_ACTIVE;
1467 if (port->gs.count <= 1) 1502 if (port->gs.count <= 1)
1468 sx_setsignals (port, 1,1); 1503 sx_setsignals(port, 1, 1);
1469 1504
1470#if 0 1505#if 0
1471 if (sx_debug & SX_DEBUG_OPEN) 1506 if (sx_debug & SX_DEBUG_OPEN)
1472 my_hd (port, sizeof (*port)); 1507 my_hd(port, sizeof(*port));
1473#else 1508#else
1474 if (sx_debug & SX_DEBUG_OPEN) 1509 if (sx_debug & SX_DEBUG_OPEN)
1475 my_hd_io (port->board->base + port->ch_base, sizeof (*port)); 1510 my_hd_io(port->board->base + port->ch_base, sizeof(*port));
1476#endif 1511#endif
1477 1512
1478 if (port->gs.count <= 1) { 1513 if (port->gs.count <= 1) {
1479 if (sx_send_command (port, HS_LOPEN, -1, HS_IDLE_OPEN) != 1) { 1514 if (sx_send_command(port, HS_LOPEN, -1, HS_IDLE_OPEN) != 1) {
1480 printk (KERN_ERR "sx: Card didn't respond to LOPEN command.\n"); 1515 printk(KERN_ERR "sx: Card didn't respond to LOPEN "
1516 "command.\n");
1481 spin_lock_irqsave(&port->gs.driver_lock, flags); 1517 spin_lock_irqsave(&port->gs.driver_lock, flags);
1482 port->gs.count--; 1518 port->gs.count--;
1483 spin_unlock_irqrestore(&port->gs.driver_lock, flags); 1519 spin_unlock_irqrestore(&port->gs.driver_lock, flags);
@@ -1486,75 +1522,76 @@ static int sx_open (struct tty_struct * tty, struct file * filp)
1486 } 1522 }
1487 1523
1488 retval = gs_block_til_ready(port, filp); 1524 retval = gs_block_til_ready(port, filp);
1489 sx_dprintk (SX_DEBUG_OPEN, "Block til ready returned %d. Count=%d\n", 1525 sx_dprintk(SX_DEBUG_OPEN, "Block til ready returned %d. Count=%d\n",
1490 retval, port->gs.count); 1526 retval, port->gs.count);
1491 1527
1492 if (retval) { 1528 if (retval) {
1493 /* 1529/*
1494 * Don't lower gs.count here because sx_close() will be called later 1530 * Don't lower gs.count here because sx_close() will be called later
1495 */ 1531 */
1496 1532
1497 return retval; 1533 return retval;
1498 } 1534 }
1499 /* tty->low_latency = 1; */ 1535 /* tty->low_latency = 1; */
1500 1536
1501 port->c_dcd = sx_get_CD (port); 1537 port->c_dcd = sx_get_CD(port);
1502 sx_dprintk (SX_DEBUG_OPEN, "at open: cd=%d\n", port->c_dcd); 1538 sx_dprintk(SX_DEBUG_OPEN, "at open: cd=%d\n", port->c_dcd);
1503 1539
1504 func_exit(); 1540 func_exit();
1505 return 0; 1541 return 0;
1506 1542
1507} 1543}
1508 1544
1509 1545static void sx_close(void *ptr)
1510static void sx_close (void *ptr)
1511{ 1546{
1512 struct sx_port *port = ptr; 1547 struct sx_port *port = ptr;
1513 /* Give the port 5 seconds to close down. */ 1548 /* Give the port 5 seconds to close down. */
1514 int to = 5 * HZ; 1549 int to = 5 * HZ;
1515 1550
1516 func_enter (); 1551 func_enter();
1517 1552
1518 sx_setsignals (port, 0, 0); 1553 sx_setsignals(port, 0, 0);
1519 sx_reconfigure_port(port); 1554 sx_reconfigure_port(port);
1520 sx_send_command (port, HS_CLOSE, 0, 0); 1555 sx_send_command(port, HS_CLOSE, 0, 0);
1521 1556
1522 while (to-- && (sx_read_channel_byte (port, hi_hstat) != HS_IDLE_CLOSED)) 1557 while (to-- && (sx_read_channel_byte(port, hi_hstat) != HS_IDLE_CLOSED))
1523 if (msleep_interruptible(10)) 1558 if (msleep_interruptible(10))
1524 break; 1559 break;
1525 if (sx_read_channel_byte (port, hi_hstat) != HS_IDLE_CLOSED) { 1560 if (sx_read_channel_byte(port, hi_hstat) != HS_IDLE_CLOSED) {
1526 if (sx_send_command (port, HS_FORCE_CLOSED, -1, HS_IDLE_CLOSED) != 1) { 1561 if (sx_send_command(port, HS_FORCE_CLOSED, -1, HS_IDLE_CLOSED)
1527 printk (KERN_ERR 1562 != 1) {
1528 "sx: sent the force_close command, but card didn't react\n"); 1563 printk(KERN_ERR "sx: sent the force_close command, but "
1564 "card didn't react\n");
1529 } else 1565 } else
1530 sx_dprintk (SX_DEBUG_CLOSE, "sent the force_close command.\n"); 1566 sx_dprintk(SX_DEBUG_CLOSE, "sent the force_close "
1567 "command.\n");
1531 } 1568 }
1532 1569
1533 sx_dprintk (SX_DEBUG_CLOSE, "waited %d jiffies for close. count=%d\n", 1570 sx_dprintk(SX_DEBUG_CLOSE, "waited %d jiffies for close. count=%d\n",
1534 5 * HZ - to - 1, port->gs.count); 1571 5 * HZ - to - 1, port->gs.count);
1535 1572
1536 if(port->gs.count) { 1573 if (port->gs.count) {
1537 sx_dprintk(SX_DEBUG_CLOSE, "WARNING port count:%d\n", port->gs.count); 1574 sx_dprintk(SX_DEBUG_CLOSE, "WARNING port count:%d\n",
1538 //printk ("%s SETTING port count to zero: %p count: %d\n", __FUNCTION__, port, port->gs.count); 1575 port->gs.count);
1539 //port->gs.count = 0; 1576 /*printk("%s SETTING port count to zero: %p count: %d\n",
1577 __FUNCTION__, port, port->gs.count);
1578 port->gs.count = 0;*/
1540 } 1579 }
1541 1580
1542 func_exit (); 1581 func_exit();
1543} 1582}
1544 1583
1545
1546
1547/* This is relatively thorough. But then again it is only 20 lines. */ 1584/* This is relatively thorough. But then again it is only 20 lines. */
1548#define MARCHUP for (i=min;i<max;i++) 1585#define MARCHUP for (i = min; i < max; i++)
1549#define MARCHDOWN for (i=max-1;i>=min;i--) 1586#define MARCHDOWN for (i = max - 1; i >= min; i--)
1550#define W0 write_sx_byte (board, i, 0x55) 1587#define W0 write_sx_byte(board, i, 0x55)
1551#define W1 write_sx_byte (board, i, 0xaa) 1588#define W1 write_sx_byte(board, i, 0xaa)
1552#define R0 if (read_sx_byte (board, i) != 0x55) return 1 1589#define R0 if (read_sx_byte(board, i) != 0x55) return 1
1553#define R1 if (read_sx_byte (board, i) != 0xaa) return 1 1590#define R1 if (read_sx_byte(board, i) != 0xaa) return 1
1554 1591
1555/* This memtest takes a human-noticable time. You normally only do it 1592/* This memtest takes a human-noticable time. You normally only do it
1556 once a boot, so I guess that it is worth it. */ 1593 once a boot, so I guess that it is worth it. */
1557static int do_memtest (struct sx_board *board, int min, int max) 1594static int do_memtest(struct sx_board *board, int min, int max)
1558{ 1595{
1559 int i; 1596 int i;
1560 1597
@@ -1563,16 +1600,37 @@ static int do_memtest (struct sx_board *board, int min, int max)
1563 intermittent errors. -- REW 1600 intermittent errors. -- REW
1564 (For the theory behind memory testing see: 1601 (For the theory behind memory testing see:
1565 Testing Semiconductor Memories by A.J. van de Goor.) */ 1602 Testing Semiconductor Memories by A.J. van de Goor.) */
1566 MARCHUP {W0;} 1603 MARCHUP {
1567 MARCHUP {R0;W1;R1;W0;R0;W1;} 1604 W0;
1568 MARCHUP {R1;W0;W1;} 1605 }
1569 MARCHDOWN {R1;W0;W1;W0;} 1606 MARCHUP {
1570 MARCHDOWN {R0;W1;W0;} 1607 R0;
1608 W1;
1609 R1;
1610 W0;
1611 R0;
1612 W1;
1613 }
1614 MARCHUP {
1615 R1;
1616 W0;
1617 W1;
1618 }
1619 MARCHDOWN {
1620 R1;
1621 W0;
1622 W1;
1623 W0;
1624 }
1625 MARCHDOWN {
1626 R0;
1627 W1;
1628 W0;
1629 }
1571 1630
1572 return 0; 1631 return 0;
1573} 1632}
1574 1633
1575
1576#undef MARCHUP 1634#undef MARCHUP
1577#undef MARCHDOWN 1635#undef MARCHDOWN
1578#undef W0 1636#undef W0
@@ -1580,33 +1638,54 @@ static int do_memtest (struct sx_board *board, int min, int max)
1580#undef R0 1638#undef R0
1581#undef R1 1639#undef R1
1582 1640
1583#define MARCHUP for (i=min;i<max;i+=2) 1641#define MARCHUP for (i = min; i < max; i += 2)
1584#define MARCHDOWN for (i=max-1;i>=min;i-=2) 1642#define MARCHDOWN for (i = max - 1; i >= min; i -= 2)
1585#define W0 write_sx_word (board, i, 0x55aa) 1643#define W0 write_sx_word(board, i, 0x55aa)
1586#define W1 write_sx_word (board, i, 0xaa55) 1644#define W1 write_sx_word(board, i, 0xaa55)
1587#define R0 if (read_sx_word (board, i) != 0x55aa) return 1 1645#define R0 if (read_sx_word(board, i) != 0x55aa) return 1
1588#define R1 if (read_sx_word (board, i) != 0xaa55) return 1 1646#define R1 if (read_sx_word(board, i) != 0xaa55) return 1
1589 1647
1590#if 0 1648#if 0
1591/* This memtest takes a human-noticable time. You normally only do it 1649/* This memtest takes a human-noticable time. You normally only do it
1592 once a boot, so I guess that it is worth it. */ 1650 once a boot, so I guess that it is worth it. */
1593static int do_memtest_w (struct sx_board *board, int min, int max) 1651static int do_memtest_w(struct sx_board *board, int min, int max)
1594{ 1652{
1595 int i; 1653 int i;
1596 1654
1597 MARCHUP {W0;} 1655 MARCHUP {
1598 MARCHUP {R0;W1;R1;W0;R0;W1;} 1656 W0;
1599 MARCHUP {R1;W0;W1;} 1657 }
1600 MARCHDOWN {R1;W0;W1;W0;} 1658 MARCHUP {
1601 MARCHDOWN {R0;W1;W0;} 1659 R0;
1660 W1;
1661 R1;
1662 W0;
1663 R0;
1664 W1;
1665 }
1666 MARCHUP {
1667 R1;
1668 W0;
1669 W1;
1670 }
1671 MARCHDOWN {
1672 R1;
1673 W0;
1674 W1;
1675 W0;
1676 }
1677 MARCHDOWN {
1678 R0;
1679 W1;
1680 W0;
1681 }
1602 1682
1603 return 0; 1683 return 0;
1604} 1684}
1605#endif 1685#endif
1606 1686
1607 1687static int sx_fw_ioctl(struct inode *inode, struct file *filp,
1608static int sx_fw_ioctl (struct inode *inode, struct file *filp, 1688 unsigned int cmd, unsigned long arg)
1609 unsigned int cmd, unsigned long arg)
1610{ 1689{
1611 int rc = 0; 1690 int rc = 0;
1612 int __user *descr = (int __user *)arg; 1691 int __user *descr = (int __user *)arg;
@@ -1618,7 +1697,7 @@ static int sx_fw_ioctl (struct inode *inode, struct file *filp,
1618 1697
1619 func_enter(); 1698 func_enter();
1620 1699
1621#if 0 1700#if 0
1622 /* Removed superuser check: Sysops can use the permissions on the device 1701 /* Removed superuser check: Sysops can use the permissions on the device
1623 file to restrict access. Recommendation: Root only. (root.root 600) */ 1702 file to restrict access. Recommendation: Root only. (root.root 600) */
1624 if (!capable(CAP_SYS_ADMIN)) { 1703 if (!capable(CAP_SYS_ADMIN)) {
@@ -1626,103 +1705,115 @@ static int sx_fw_ioctl (struct inode *inode, struct file *filp,
1626 } 1705 }
1627#endif 1706#endif
1628 1707
1629 sx_dprintk (SX_DEBUG_FIRMWARE, "IOCTL %x: %lx\n", cmd, arg); 1708 sx_dprintk(SX_DEBUG_FIRMWARE, "IOCTL %x: %lx\n", cmd, arg);
1630 1709
1631 if (!board) board = &boards[0]; 1710 if (!board)
1711 board = &boards[0];
1632 if (board->flags & SX_BOARD_PRESENT) { 1712 if (board->flags & SX_BOARD_PRESENT) {
1633 sx_dprintk (SX_DEBUG_FIRMWARE, "Board present! (%x)\n", 1713 sx_dprintk(SX_DEBUG_FIRMWARE, "Board present! (%x)\n",
1634 board->flags); 1714 board->flags);
1635 } else { 1715 } else {
1636 sx_dprintk (SX_DEBUG_FIRMWARE, "Board not present! (%x) all:", 1716 sx_dprintk(SX_DEBUG_FIRMWARE, "Board not present! (%x) all:",
1637 board->flags); 1717 board->flags);
1638 for (i=0;i< SX_NBOARDS;i++) 1718 for (i = 0; i < SX_NBOARDS; i++)
1639 sx_dprintk (SX_DEBUG_FIRMWARE, "<%x> ", boards[i].flags); 1719 sx_dprintk(SX_DEBUG_FIRMWARE, "<%x> ", boards[i].flags);
1640 sx_dprintk (SX_DEBUG_FIRMWARE, "\n"); 1720 sx_dprintk(SX_DEBUG_FIRMWARE, "\n");
1641 return -EIO; 1721 return -EIO;
1642 } 1722 }
1643 1723
1644 switch (cmd) { 1724 switch (cmd) {
1645 case SXIO_SET_BOARD: 1725 case SXIO_SET_BOARD:
1646 sx_dprintk (SX_DEBUG_FIRMWARE, "set board to %ld\n", arg); 1726 sx_dprintk(SX_DEBUG_FIRMWARE, "set board to %ld\n", arg);
1647 if (arg >= SX_NBOARDS) return -EIO; 1727 if (arg >= SX_NBOARDS)
1648 sx_dprintk (SX_DEBUG_FIRMWARE, "not out of range\n"); 1728 return -EIO;
1649 if (!(boards[arg].flags & SX_BOARD_PRESENT)) return -EIO; 1729 sx_dprintk(SX_DEBUG_FIRMWARE, "not out of range\n");
1650 sx_dprintk (SX_DEBUG_FIRMWARE, ".. and present!\n"); 1730 if (!(boards[arg].flags & SX_BOARD_PRESENT))
1731 return -EIO;
1732 sx_dprintk(SX_DEBUG_FIRMWARE, ".. and present!\n");
1651 board = &boards[arg]; 1733 board = &boards[arg];
1652 break; 1734 break;
1653 case SXIO_GET_TYPE: 1735 case SXIO_GET_TYPE:
1654 rc = -ENOENT; /* If we manage to miss one, return error. */ 1736 rc = -ENOENT; /* If we manage to miss one, return error. */
1655 if (IS_SX_BOARD (board)) rc = SX_TYPE_SX; 1737 if (IS_SX_BOARD(board))
1656 if (IS_CF_BOARD (board)) rc = SX_TYPE_CF; 1738 rc = SX_TYPE_SX;
1657 if (IS_SI_BOARD (board)) rc = SX_TYPE_SI; 1739 if (IS_CF_BOARD(board))
1658 if (IS_SI1_BOARD (board)) rc = SX_TYPE_SI; 1740 rc = SX_TYPE_CF;
1659 if (IS_EISA_BOARD (board)) rc = SX_TYPE_SI; 1741 if (IS_SI_BOARD(board))
1660 sx_dprintk (SX_DEBUG_FIRMWARE, "returning type= %d\n", rc); 1742 rc = SX_TYPE_SI;
1743 if (IS_SI1_BOARD(board))
1744 rc = SX_TYPE_SI;
1745 if (IS_EISA_BOARD(board))
1746 rc = SX_TYPE_SI;
1747 sx_dprintk(SX_DEBUG_FIRMWARE, "returning type= %d\n", rc);
1661 break; 1748 break;
1662 case SXIO_DO_RAMTEST: 1749 case SXIO_DO_RAMTEST:
1663 if (sx_initialized) /* Already initialized: better not ramtest the board. */ 1750 if (sx_initialized) /* Already initialized: better not ramtest the board. */
1664 return -EPERM; 1751 return -EPERM;
1665 if (IS_SX_BOARD (board)) { 1752 if (IS_SX_BOARD(board)) {
1666 rc = do_memtest (board, 0, 0x7000); 1753 rc = do_memtest(board, 0, 0x7000);
1667 if (!rc) rc = do_memtest (board, 0, 0x7000); 1754 if (!rc)
1668 /*if (!rc) rc = do_memtest_w (board, 0, 0x7000);*/ 1755 rc = do_memtest(board, 0, 0x7000);
1756 /*if (!rc) rc = do_memtest_w (board, 0, 0x7000); */
1669 } else { 1757 } else {
1670 rc = do_memtest (board, 0, 0x7ff8); 1758 rc = do_memtest(board, 0, 0x7ff8);
1671 /* if (!rc) rc = do_memtest_w (board, 0, 0x7ff8); */ 1759 /* if (!rc) rc = do_memtest_w (board, 0, 0x7ff8); */
1672 } 1760 }
1673 sx_dprintk (SX_DEBUG_FIRMWARE, "returning memtest result= %d\n", rc); 1761 sx_dprintk(SX_DEBUG_FIRMWARE, "returning memtest result= %d\n",
1762 rc);
1674 break; 1763 break;
1675 case SXIO_DOWNLOAD: 1764 case SXIO_DOWNLOAD:
1676 if (sx_initialized) /* Already initialized */ 1765 if (sx_initialized) /* Already initialized */
1677 return -EEXIST; 1766 return -EEXIST;
1678 if (!sx_reset (board)) 1767 if (!sx_reset(board))
1679 return -EIO; 1768 return -EIO;
1680 sx_dprintk (SX_DEBUG_INIT, "reset the board...\n"); 1769 sx_dprintk(SX_DEBUG_INIT, "reset the board...\n");
1681 1770
1682 tmp = kmalloc (SX_CHUNK_SIZE, GFP_USER); 1771 tmp = kmalloc(SX_CHUNK_SIZE, GFP_USER);
1683 if (!tmp) return -ENOMEM; 1772 if (!tmp)
1684 get_user (nbytes, descr++); 1773 return -ENOMEM;
1685 get_user (offset, descr++); 1774 get_user(nbytes, descr++);
1686 get_user (data, descr++); 1775 get_user(offset, descr++);
1776 get_user(data, descr++);
1687 while (nbytes && data) { 1777 while (nbytes && data) {
1688 for (i=0;i<nbytes;i += SX_CHUNK_SIZE) { 1778 for (i = 0; i < nbytes; i += SX_CHUNK_SIZE) {
1689 if (copy_from_user(tmp, (char __user *)data+i, 1779 if (copy_from_user(tmp, (char __user *)data + i,
1690 (i + SX_CHUNK_SIZE > 1780 (i + SX_CHUNK_SIZE > nbytes) ?
1691 nbytes) ? nbytes - i : 1781 nbytes - i : SX_CHUNK_SIZE)) {
1692 SX_CHUNK_SIZE)) { 1782 kfree(tmp);
1693 kfree (tmp);
1694 return -EFAULT; 1783 return -EFAULT;
1695 } 1784 }
1696 memcpy_toio(board->base2 + offset + i, tmp, 1785 memcpy_toio(board->base2 + offset + i, tmp,
1697 (i+SX_CHUNK_SIZE>nbytes)?nbytes-i:SX_CHUNK_SIZE); 1786 (i + SX_CHUNK_SIZE > nbytes) ?
1787 nbytes - i : SX_CHUNK_SIZE);
1698 } 1788 }
1699 1789
1700 get_user (nbytes, descr++); 1790 get_user(nbytes, descr++);
1701 get_user (offset, descr++); 1791 get_user(offset, descr++);
1702 get_user (data, descr++); 1792 get_user(data, descr++);
1703 } 1793 }
1704 kfree (tmp); 1794 kfree(tmp);
1705 sx_nports += sx_init_board (board); 1795 sx_nports += sx_init_board(board);
1706 rc = sx_nports; 1796 rc = sx_nports;
1707 break; 1797 break;
1708 case SXIO_INIT: 1798 case SXIO_INIT:
1709 if (sx_initialized) /* Already initialized */ 1799 if (sx_initialized) /* Already initialized */
1710 return -EEXIST; 1800 return -EEXIST;
1711 /* This is not allowed until all boards are initialized... */ 1801 /* This is not allowed until all boards are initialized... */
1712 for (i=0;i<SX_NBOARDS;i++) { 1802 for (i = 0; i < SX_NBOARDS; i++) {
1713 if ( (boards[i].flags & SX_BOARD_PRESENT) && 1803 if ((boards[i].flags & SX_BOARD_PRESENT) &&
1714 !(boards[i].flags & SX_BOARD_INITIALIZED)) 1804 !(boards[i].flags & SX_BOARD_INITIALIZED))
1715 return -EIO; 1805 return -EIO;
1716 } 1806 }
1717 for (i=0;i<SX_NBOARDS;i++) 1807 for (i = 0; i < SX_NBOARDS; i++)
1718 if (!(boards[i].flags & SX_BOARD_PRESENT)) break; 1808 if (!(boards[i].flags & SX_BOARD_PRESENT))
1719 1809 break;
1720 sx_dprintk (SX_DEBUG_FIRMWARE, "initing portstructs, %d boards, " 1810
1721 "%d channels, first board: %d ports\n", 1811 sx_dprintk(SX_DEBUG_FIRMWARE, "initing portstructs, %d boards, "
1722 i, sx_nports, boards[0].nports); 1812 "%d channels, first board: %d ports\n",
1723 rc = sx_init_portstructs (i, sx_nports); 1813 i, sx_nports, boards[0].nports);
1724 sx_init_drivers (); 1814 rc = sx_init_portstructs(i, sx_nports);
1725 if (rc >= 0) 1815 sx_init_drivers();
1816 if (rc >= 0)
1726 sx_initialized++; 1817 sx_initialized++;
1727 break; 1818 break;
1728 case SXIO_SETDEBUG: 1819 case SXIO_SETDEBUG:
@@ -1739,32 +1830,32 @@ static int sx_fw_ioctl (struct inode *inode, struct file *filp,
1739 rc = sx_nports; 1830 rc = sx_nports;
1740 break; 1831 break;
1741 default: 1832 default:
1742 printk (KERN_WARNING "Unknown ioctl on firmware device (%x).\n", cmd); 1833 printk(KERN_WARNING "Unknown ioctl on firmware device (%x).\n",
1834 cmd);
1743 break; 1835 break;
1744 } 1836 }
1745 func_exit (); 1837 func_exit();
1746 return rc; 1838 return rc;
1747} 1839}
1748 1840
1749 1841static void sx_break(struct tty_struct *tty, int flag)
1750static void sx_break (struct tty_struct * tty, int flag)
1751{ 1842{
1752 struct sx_port *port = tty->driver_data; 1843 struct sx_port *port = tty->driver_data;
1753 int rv; 1844 int rv;
1754 1845
1755 func_enter (); 1846 func_enter();
1756 1847
1757 if (flag) 1848 if (flag)
1758 rv = sx_send_command (port, HS_START, -1, HS_IDLE_BREAK); 1849 rv = sx_send_command(port, HS_START, -1, HS_IDLE_BREAK);
1759 else 1850 else
1760 rv = sx_send_command (port, HS_STOP, -1, HS_IDLE_OPEN); 1851 rv = sx_send_command(port, HS_STOP, -1, HS_IDLE_OPEN);
1761 if (rv != 1) printk (KERN_ERR "sx: couldn't send break (%x).\n", 1852 if (rv != 1)
1762 read_sx_byte (port->board, CHAN_OFFSET (port, hi_hstat))); 1853 printk(KERN_ERR "sx: couldn't send break (%x).\n",
1854 read_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat)));
1763 1855
1764 func_exit (); 1856 func_exit();
1765} 1857}
1766 1858
1767
1768static int sx_tiocmget(struct tty_struct *tty, struct file *file) 1859static int sx_tiocmget(struct tty_struct *tty, struct file *file)
1769{ 1860{
1770 struct sx_port *port = tty->driver_data; 1861 struct sx_port *port = tty->driver_data;
@@ -1772,7 +1863,7 @@ static int sx_tiocmget(struct tty_struct *tty, struct file *file)
1772} 1863}
1773 1864
1774static int sx_tiocmset(struct tty_struct *tty, struct file *file, 1865static int sx_tiocmset(struct tty_struct *tty, struct file *file,
1775 unsigned int set, unsigned int clear) 1866 unsigned int set, unsigned int clear)
1776{ 1867{
1777 struct sx_port *port = tty->driver_data; 1868 struct sx_port *port = tty->driver_data;
1778 int rts = -1, dtr = -1; 1869 int rts = -1, dtr = -1;
@@ -1791,8 +1882,8 @@ static int sx_tiocmset(struct tty_struct *tty, struct file *file,
1791 return 0; 1882 return 0;
1792} 1883}
1793 1884
1794static int sx_ioctl (struct tty_struct * tty, struct file * filp, 1885static int sx_ioctl(struct tty_struct *tty, struct file *filp,
1795 unsigned int cmd, unsigned long arg) 1886 unsigned int cmd, unsigned long arg)
1796{ 1887{
1797 int rc; 1888 int rc;
1798 struct sx_port *port = tty->driver_data; 1889 struct sx_port *port = tty->driver_data;
@@ -1805,10 +1896,10 @@ static int sx_ioctl (struct tty_struct * tty, struct file * filp,
1805 switch (cmd) { 1896 switch (cmd) {
1806 case TIOCGSOFTCAR: 1897 case TIOCGSOFTCAR:
1807 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0), 1898 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1808 (unsigned __user *) argp); 1899 (unsigned __user *)argp);
1809 break; 1900 break;
1810 case TIOCSSOFTCAR: 1901 case TIOCSSOFTCAR:
1811 if ((rc = get_user(ival, (unsigned __user *) argp)) == 0) { 1902 if ((rc = get_user(ival, (unsigned __user *)argp)) == 0) {
1812 tty->termios->c_cflag = 1903 tty->termios->c_cflag =
1813 (tty->termios->c_cflag & ~CLOCAL) | 1904 (tty->termios->c_cflag & ~CLOCAL) |
1814 (ival ? CLOCAL : 0); 1905 (ival ? CLOCAL : 0);
@@ -1829,7 +1920,6 @@ static int sx_ioctl (struct tty_struct * tty, struct file * filp,
1829 return rc; 1920 return rc;
1830} 1921}
1831 1922
1832
1833/* The throttle/unthrottle scheme for the Specialix card is different 1923/* The throttle/unthrottle scheme for the Specialix card is different
1834 * from other drivers and deserves some explanation. 1924 * from other drivers and deserves some explanation.
1835 * The Specialix hardware takes care of XON/XOFF 1925 * The Specialix hardware takes care of XON/XOFF
@@ -1846,7 +1936,7 @@ static int sx_ioctl (struct tty_struct * tty, struct file * filp,
1846 * flow control scheme is in use for that port. -- Simon Allen 1936 * flow control scheme is in use for that port. -- Simon Allen
1847 */ 1937 */
1848 1938
1849static void sx_throttle (struct tty_struct * tty) 1939static void sx_throttle(struct tty_struct *tty)
1850{ 1940{
1851 struct sx_port *port = (struct sx_port *)tty->driver_data; 1941 struct sx_port *port = (struct sx_port *)tty->driver_data;
1852 1942
@@ -1854,14 +1944,13 @@ static void sx_throttle (struct tty_struct * tty)
1854 /* If the port is using any type of input flow 1944 /* If the port is using any type of input flow
1855 * control then throttle the port. 1945 * control then throttle the port.
1856 */ 1946 */
1857 if((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty)) ) { 1947 if ((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty))) {
1858 port->gs.flags |= SX_RX_THROTTLE; 1948 port->gs.flags |= SX_RX_THROTTLE;
1859 } 1949 }
1860 func_exit(); 1950 func_exit();
1861} 1951}
1862 1952
1863 1953static void sx_unthrottle(struct tty_struct *tty)
1864static void sx_unthrottle (struct tty_struct * tty)
1865{ 1954{
1866 struct sx_port *port = (struct sx_port *)tty->driver_data; 1955 struct sx_port *port = (struct sx_port *)tty->driver_data;
1867 1956
@@ -1875,15 +1964,11 @@ static void sx_unthrottle (struct tty_struct * tty)
1875 return; 1964 return;
1876} 1965}
1877 1966
1878
1879/* ********************************************************************** * 1967/* ********************************************************************** *
1880 * Here are the initialization routines. * 1968 * Here are the initialization routines. *
1881 * ********************************************************************** */ 1969 * ********************************************************************** */
1882 1970
1883 1971static int sx_init_board(struct sx_board *board)
1884
1885
1886static int sx_init_board (struct sx_board *board)
1887{ 1972{
1888 int addr; 1973 int addr;
1889 int chans; 1974 int chans;
@@ -1895,36 +1980,38 @@ static int sx_init_board (struct sx_board *board)
1895 1980
1896 board->flags |= SX_BOARD_INITIALIZED; 1981 board->flags |= SX_BOARD_INITIALIZED;
1897 1982
1898 if (read_sx_byte (board, 0)) 1983 if (read_sx_byte(board, 0))
1899 /* CF boards may need this. */ 1984 /* CF boards may need this. */
1900 write_sx_byte(board,0, 0); 1985 write_sx_byte(board, 0, 0);
1901 1986
1902 /* This resets the processor again, to make sure it didn't do any 1987 /* This resets the processor again, to make sure it didn't do any
1903 foolish things while we were downloading the image */ 1988 foolish things while we were downloading the image */
1904 if (!sx_reset (board)) 1989 if (!sx_reset(board))
1905 return 0; 1990 return 0;
1906 1991
1907 sx_start_board (board); 1992 sx_start_board(board);
1908 udelay (10); 1993 udelay(10);
1909 if (!sx_busy_wait_neq (board, 0, 0xff, 0)) { 1994 if (!sx_busy_wait_neq(board, 0, 0xff, 0)) {
1910 printk (KERN_ERR "sx: Ooops. Board won't initialize.\n"); 1995 printk(KERN_ERR "sx: Ooops. Board won't initialize.\n");
1911 return 0; 1996 return 0;
1912 } 1997 }
1913 1998
1914 /* Ok. So now the processor on the card is running. It gathered 1999 /* Ok. So now the processor on the card is running. It gathered
1915 some info for us... */ 2000 some info for us... */
1916 sx_dprintk (SX_DEBUG_INIT, "The sxcard structure:\n"); 2001 sx_dprintk(SX_DEBUG_INIT, "The sxcard structure:\n");
1917 if (sx_debug & SX_DEBUG_INIT) my_hd_io (board->base, 0x10); 2002 if (sx_debug & SX_DEBUG_INIT)
1918 sx_dprintk (SX_DEBUG_INIT, "the first sx_module structure:\n"); 2003 my_hd_io(board->base, 0x10);
1919 if (sx_debug & SX_DEBUG_INIT) my_hd_io (board->base + 0x80, 0x30); 2004 sx_dprintk(SX_DEBUG_INIT, "the first sx_module structure:\n");
1920 2005 if (sx_debug & SX_DEBUG_INIT)
1921 sx_dprintk (SX_DEBUG_INIT, 2006 my_hd_io(board->base + 0x80, 0x30);
1922 "init_status: %x, %dk memory, firmware V%x.%02x,\n", 2007
1923 read_sx_byte (board, 0), read_sx_byte(board, 1), 2008 sx_dprintk(SX_DEBUG_INIT, "init_status: %x, %dk memory, firmware "
1924 read_sx_byte (board, 5), read_sx_byte(board, 4)); 2009 "V%x.%02x,\n",
1925 2010 read_sx_byte(board, 0), read_sx_byte(board, 1),
1926 if (read_sx_byte (board, 0) == 0xff) { 2011 read_sx_byte(board, 5), read_sx_byte(board, 4));
1927 printk (KERN_INFO "sx: No modules found. Sorry.\n"); 2012
2013 if (read_sx_byte(board, 0) == 0xff) {
2014 printk(KERN_INFO "sx: No modules found. Sorry.\n");
1928 board->nports = 0; 2015 board->nports = 0;
1929 return 0; 2016 return 0;
1930 } 2017 }
@@ -1932,82 +2019,97 @@ static int sx_init_board (struct sx_board *board)
1932 chans = 0; 2019 chans = 0;
1933 2020
1934 if (IS_SX_BOARD(board)) { 2021 if (IS_SX_BOARD(board)) {
1935 sx_write_board_word (board, cc_int_count, sx_maxints); 2022 sx_write_board_word(board, cc_int_count, sx_maxints);
1936 } else { 2023 } else {
1937 if (sx_maxints) 2024 if (sx_maxints)
1938 sx_write_board_word (board, cc_int_count, SI_PROCESSOR_CLOCK/8/sx_maxints); 2025 sx_write_board_word(board, cc_int_count,
2026 SI_PROCESSOR_CLOCK / 8 / sx_maxints);
1939 } 2027 }
1940 2028
1941 /* grab the first module type... */ 2029 /* grab the first module type... */
1942 /* board->ta_type = mod_compat_type (read_sx_byte (board, 0x80 + 0x08)); */ 2030 /* board->ta_type = mod_compat_type (read_sx_byte (board, 0x80 + 0x08)); */
1943 board->ta_type = mod_compat_type (sx_read_module_byte (board, 0x80, mc_chip)); 2031 board->ta_type = mod_compat_type(sx_read_module_byte(board, 0x80,
2032 mc_chip));
1944 2033
1945 /* XXX byteorder */ 2034 /* XXX byteorder */
1946 for (addr = 0x80;addr != 0;addr = read_sx_word (board, addr) & 0x7fff) { 2035 for (addr = 0x80; addr != 0; addr = read_sx_word(board, addr) & 0x7fff){
1947 type = sx_read_module_byte (board, addr, mc_chip); 2036 type = sx_read_module_byte(board, addr, mc_chip);
1948 sx_dprintk (SX_DEBUG_INIT, "Module at %x: %d channels\n", 2037 sx_dprintk(SX_DEBUG_INIT, "Module at %x: %d channels\n",
1949 addr, read_sx_byte (board, addr + 2)); 2038 addr, read_sx_byte(board, addr + 2));
1950 2039
1951 chans += sx_read_module_byte (board, addr, mc_type); 2040 chans += sx_read_module_byte(board, addr, mc_type);
1952 2041
1953 sx_dprintk (SX_DEBUG_INIT, "module is an %s, which has %s/%s panels\n", 2042 sx_dprintk(SX_DEBUG_INIT, "module is an %s, which has %s/%s "
1954 mod_type_s (type), 2043 "panels\n",
1955 pan_type_s (sx_read_module_byte (board, addr, mc_mods) & 0xf), 2044 mod_type_s(type),
1956 pan_type_s (sx_read_module_byte (board, addr, mc_mods) >> 4)); 2045 pan_type_s(sx_read_module_byte(board, addr,
1957 2046 mc_mods) & 0xf),
1958 sx_dprintk (SX_DEBUG_INIT, "CD1400 versions: %x/%x, ASIC version: %x\n", 2047 pan_type_s(sx_read_module_byte(board, addr,
1959 sx_read_module_byte (board, addr, mc_rev1), 2048 mc_mods) >> 4));
1960 sx_read_module_byte (board, addr, mc_rev2), 2049
1961 sx_read_module_byte (board, addr, mc_mtaasic_rev)); 2050 sx_dprintk(SX_DEBUG_INIT, "CD1400 versions: %x/%x, ASIC "
2051 "version: %x\n",
2052 sx_read_module_byte(board, addr, mc_rev1),
2053 sx_read_module_byte(board, addr, mc_rev2),
2054 sx_read_module_byte(board, addr, mc_mtaasic_rev));
1962 2055
1963 /* The following combinations are illegal: It should theoretically 2056 /* The following combinations are illegal: It should theoretically
1964 work, but timing problems make the bus HANG. */ 2057 work, but timing problems make the bus HANG. */
1965 2058
1966 if (mod_compat_type (type) != board->ta_type) { 2059 if (mod_compat_type(type) != board->ta_type) {
1967 printk (KERN_ERR "sx: This is an invalid configuration.\n" 2060 printk(KERN_ERR "sx: This is an invalid "
1968 "Don't mix TA/MTA/SXDC on the same hostadapter.\n"); 2061 "configuration.\nDon't mix TA/MTA/SXDC on the "
1969 chans=0; 2062 "same hostadapter.\n");
2063 chans = 0;
1970 break; 2064 break;
1971 } 2065 }
1972 if ((IS_EISA_BOARD(board) || 2066 if ((IS_EISA_BOARD(board) ||
1973 IS_SI_BOARD(board)) && (mod_compat_type(type) == 4)) { 2067 IS_SI_BOARD(board)) &&
1974 printk (KERN_ERR "sx: This is an invalid configuration.\n" 2068 (mod_compat_type(type) == 4)) {
1975 "Don't use SXDCs on an SI/XIO adapter.\n"); 2069 printk(KERN_ERR "sx: This is an invalid "
1976 chans=0; 2070 "configuration.\nDon't use SXDCs on an SI/XIO "
2071 "adapter.\n");
2072 chans = 0;
1977 break; 2073 break;
1978 } 2074 }
1979#if 0 /* Problem fixed: firmware 3.05 */ 2075#if 0 /* Problem fixed: firmware 3.05 */
1980 if (IS_SX_BOARD(board) && (type == TA8)) { 2076 if (IS_SX_BOARD(board) && (type == TA8)) {
1981 /* There are some issues with the firmware and the DCD/RTS 2077 /* There are some issues with the firmware and the DCD/RTS
1982 lines. It might work if you tie them together or something. 2078 lines. It might work if you tie them together or something.
1983 It might also work if you get a newer sx_firmware. Therefore 2079 It might also work if you get a newer sx_firmware. Therefore
1984 this is just a warning. */ 2080 this is just a warning. */
1985 printk (KERN_WARNING "sx: The SX host doesn't work too well " 2081 printk(KERN_WARNING
1986 "with the TA8 adapters.\nSpecialix is working on it.\n"); 2082 "sx: The SX host doesn't work too well "
2083 "with the TA8 adapters.\nSpecialix is working on it.\n");
1987 } 2084 }
1988#endif 2085#endif
1989 } 2086 }
1990 2087
1991 if (chans) { 2088 if (chans) {
1992 /* board->flags |= SX_BOARD_PRESENT; */ 2089 if (board->irq > 0) {
1993 if(board->irq > 0) {
1994 /* fixed irq, probably PCI */ 2090 /* fixed irq, probably PCI */
1995 if(sx_irqmask & (1 << board->irq)) { /* may we use this irq? */ 2091 if (sx_irqmask & (1 << board->irq)) { /* may we use this irq? */
1996 if(request_irq(board->irq, sx_interrupt, IRQF_SHARED | IRQF_DISABLED, "sx", board)) { 2092 if (request_irq(board->irq, sx_interrupt,
1997 printk(KERN_ERR "sx: Cannot allocate irq %d.\n", board->irq); 2093 IRQF_SHARED | IRQF_DISABLED,
2094 "sx", board)) {
2095 printk(KERN_ERR "sx: Cannot allocate "
2096 "irq %d.\n", board->irq);
1998 board->irq = 0; 2097 board->irq = 0;
1999 } 2098 }
2000 } else 2099 } else
2001 board->irq = 0; 2100 board->irq = 0;
2002 } else if(board->irq < 0 && sx_irqmask) { 2101 } else if (board->irq < 0 && sx_irqmask) {
2003 /* auto-allocate irq */ 2102 /* auto-allocate irq */
2004 int irqnr; 2103 int irqnr;
2005 int irqmask = sx_irqmask & (IS_SX_BOARD(board) ? SX_ISA_IRQ_MASK : SI2_ISA_IRQ_MASK); 2104 int irqmask = sx_irqmask & (IS_SX_BOARD(board) ?
2006 for(irqnr = 15; irqnr > 0; irqnr--) 2105 SX_ISA_IRQ_MASK : SI2_ISA_IRQ_MASK);
2007 if(irqmask & (1 << irqnr)) 2106 for (irqnr = 15; irqnr > 0; irqnr--)
2008 if(! request_irq(irqnr, sx_interrupt, IRQF_SHARED | IRQF_DISABLED, "sx", board)) 2107 if (irqmask & (1 << irqnr))
2108 if (!request_irq(irqnr, sx_interrupt,
2109 IRQF_SHARED | IRQF_DISABLED,
2110 "sx", board))
2009 break; 2111 break;
2010 if(! irqnr) 2112 if (!irqnr)
2011 printk(KERN_ERR "sx: Cannot allocate IRQ.\n"); 2113 printk(KERN_ERR "sx: Cannot allocate IRQ.\n");
2012 board->irq = irqnr; 2114 board->irq = irqnr;
2013 } else 2115 } else
@@ -2015,52 +2117,48 @@ static int sx_init_board (struct sx_board *board)
2015 2117
2016 if (board->irq) { 2118 if (board->irq) {
2017 /* Found a valid interrupt, start up interrupts! */ 2119 /* Found a valid interrupt, start up interrupts! */
2018 sx_dprintk (SX_DEBUG_INIT, "Using irq %d.\n", board->irq); 2120 sx_dprintk(SX_DEBUG_INIT, "Using irq %d.\n",
2019 sx_start_interrupts (board); 2121 board->irq);
2122 sx_start_interrupts(board);
2020 board->poll = sx_slowpoll; 2123 board->poll = sx_slowpoll;
2021 board->flags |= SX_IRQ_ALLOCATED; 2124 board->flags |= SX_IRQ_ALLOCATED;
2022 } else { 2125 } else {
2023 /* no irq: setup board for polled operation */ 2126 /* no irq: setup board for polled operation */
2024 board->poll = sx_poll; 2127 board->poll = sx_poll;
2025 sx_dprintk (SX_DEBUG_INIT, "Using poll-interval %d.\n", board->poll); 2128 sx_dprintk(SX_DEBUG_INIT, "Using poll-interval %d.\n",
2129 board->poll);
2026 } 2130 }
2027 2131
2028 /* The timer should be initialized anyway: That way we can safely 2132 /* The timer should be initialized anyway: That way we can
2029 del_timer it when the module is unloaded. */ 2133 safely del_timer it when the module is unloaded. */
2030 init_timer (&board->timer); 2134 setup_timer(&board->timer, sx_pollfunc, (unsigned long)board);
2031 2135
2032 if (board->poll) { 2136 if (board->poll)
2033 board->timer.data = (unsigned long) board; 2137 mod_timer(&board->timer, jiffies + board->poll);
2034 board->timer.function = sx_pollfunc;
2035 board->timer.expires = jiffies + board->poll;
2036 add_timer (&board->timer);
2037 }
2038 } else { 2138 } else {
2039 board->irq = 0; 2139 board->irq = 0;
2040 } 2140 }
2041 2141
2042 board->nports = chans; 2142 board->nports = chans;
2043 sx_dprintk (SX_DEBUG_INIT, "returning %d ports.", board->nports); 2143 sx_dprintk(SX_DEBUG_INIT, "returning %d ports.", board->nports);
2044 2144
2045 func_exit(); 2145 func_exit();
2046 return chans; 2146 return chans;
2047} 2147}
2048 2148
2049 2149static void __devinit printheader(void)
2050static void printheader(void)
2051{ 2150{
2052 static int header_printed; 2151 static int header_printed;
2053 2152
2054 if (!header_printed) { 2153 if (!header_printed) {
2055 printk (KERN_INFO "Specialix SX driver " 2154 printk(KERN_INFO "Specialix SX driver "
2056 "(C) 1998/1999 R.E.Wolff@BitWizard.nl \n"); 2155 "(C) 1998/1999 R.E.Wolff@BitWizard.nl\n");
2057 printk (KERN_INFO "sx: version %s\n", RCS_ID); 2156 printk(KERN_INFO "sx: version " __stringify(SX_VERSION) "\n");
2058 header_printed = 1; 2157 header_printed = 1;
2059 } 2158 }
2060} 2159}
2061 2160
2062 2161static int __devinit probe_sx(struct sx_board *board)
2063static int probe_sx (struct sx_board *board)
2064{ 2162{
2065 struct vpd_prom vpdp; 2163 struct vpd_prom vpdp;
2066 char *p; 2164 char *p;
@@ -2068,51 +2166,57 @@ static int probe_sx (struct sx_board *board)
2068 2166
2069 func_enter(); 2167 func_enter();
2070 2168
2071 if (!IS_CF_BOARD (board)) { 2169 if (!IS_CF_BOARD(board)) {
2072 sx_dprintk (SX_DEBUG_PROBE, "Going to verify vpd prom at %p.\n", 2170 sx_dprintk(SX_DEBUG_PROBE, "Going to verify vpd prom at %p.\n",
2073 board->base + SX_VPD_ROM); 2171 board->base + SX_VPD_ROM);
2074 2172
2075 if (sx_debug & SX_DEBUG_PROBE) 2173 if (sx_debug & SX_DEBUG_PROBE)
2076 my_hd_io(board->base + SX_VPD_ROM, 0x40); 2174 my_hd_io(board->base + SX_VPD_ROM, 0x40);
2077 2175
2078 p = (char *) &vpdp; 2176 p = (char *)&vpdp;
2079 for (i=0;i< sizeof (struct vpd_prom);i++) 2177 for (i = 0; i < sizeof(struct vpd_prom); i++)
2080 *p++ = read_sx_byte (board, SX_VPD_ROM + i*2); 2178 *p++ = read_sx_byte(board, SX_VPD_ROM + i * 2);
2081 2179
2082 if (sx_debug & SX_DEBUG_PROBE) 2180 if (sx_debug & SX_DEBUG_PROBE)
2083 my_hd (&vpdp, 0x20); 2181 my_hd(&vpdp, 0x20);
2084 2182
2085 sx_dprintk (SX_DEBUG_PROBE, "checking identifier...\n"); 2183 sx_dprintk(SX_DEBUG_PROBE, "checking identifier...\n");
2086 2184
2087 if (strncmp (vpdp.identifier, SX_VPD_IDENT_STRING, 16) != 0) { 2185 if (strncmp(vpdp.identifier, SX_VPD_IDENT_STRING, 16) != 0) {
2088 sx_dprintk (SX_DEBUG_PROBE, "Got non-SX identifier: '%s'\n", 2186 sx_dprintk(SX_DEBUG_PROBE, "Got non-SX identifier: "
2089 vpdp.identifier); 2187 "'%s'\n", vpdp.identifier);
2090 return 0; 2188 return 0;
2091 } 2189 }
2092 } 2190 }
2093 2191
2094 printheader (); 2192 printheader();
2095
2096 if (!IS_CF_BOARD (board)) {
2097 printk (KERN_DEBUG "sx: Found an SX board at %lx\n", board->hw_base);
2098 printk (KERN_DEBUG "sx: hw_rev: %d, assembly level: %d, uniq ID:%08x, ",
2099 vpdp.hwrev, vpdp.hwass, vpdp.uniqid);
2100 printk ( "Manufactured: %d/%d\n",
2101 1970 + vpdp.myear, vpdp.mweek);
2102 2193
2194 if (!IS_CF_BOARD(board)) {
2195 printk(KERN_DEBUG "sx: Found an SX board at %lx\n",
2196 board->hw_base);
2197 printk(KERN_DEBUG "sx: hw_rev: %d, assembly level: %d, "
2198 "uniq ID:%08x, ",
2199 vpdp.hwrev, vpdp.hwass, vpdp.uniqid);
2200 printk("Manufactured: %d/%d\n", 1970 + vpdp.myear, vpdp.mweek);
2103 2201
2104 if ((((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) != SX_PCI_UNIQUEID1) && 2202 if ((((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) !=
2105 (((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) != SX_ISA_UNIQUEID1)) { 2203 SX_PCI_UNIQUEID1) && (((vpdp.uniqid >> 24) &
2106 /* This might be a bit harsh. This was the primary reason the 2204 SX_UNIQUEID_MASK) != SX_ISA_UNIQUEID1)) {
2107 SX/ISA card didn't work at first... */ 2205 /* This might be a bit harsh. This was the primary
2108 printk (KERN_ERR "sx: Hmm. Not an SX/PCI or SX/ISA card. Sorry: giving up.\n"); 2206 reason the SX/ISA card didn't work at first... */
2207 printk(KERN_ERR "sx: Hmm. Not an SX/PCI or SX/ISA "
2208 "card. Sorry: giving up.\n");
2109 return (0); 2209 return (0);
2110 } 2210 }
2111 2211
2112 if (((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) == SX_ISA_UNIQUEID1) { 2212 if (((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) ==
2213 SX_ISA_UNIQUEID1) {
2113 if (((unsigned long)board->hw_base) & 0x8000) { 2214 if (((unsigned long)board->hw_base) & 0x8000) {
2114 printk (KERN_WARNING "sx: Warning: There may be hardware problems with the card at %lx.\n", board->hw_base); 2215 printk(KERN_WARNING "sx: Warning: There may be "
2115 printk (KERN_WARNING "sx: Read sx.txt for more info.\n"); 2216 "hardware problems with the card at "
2217 "%lx.\n", board->hw_base);
2218 printk(KERN_WARNING "sx: Read sx.txt for more "
2219 "info.\n");
2116 } 2220 }
2117 } 2221 }
2118 } 2222 }
@@ -2120,17 +2224,15 @@ static int probe_sx (struct sx_board *board)
2120 board->nports = -1; 2224 board->nports = -1;
2121 2225
2122 /* This resets the processor, and keeps it off the bus. */ 2226 /* This resets the processor, and keeps it off the bus. */
2123 if (!sx_reset (board)) 2227 if (!sx_reset(board))
2124 return 0; 2228 return 0;
2125 sx_dprintk (SX_DEBUG_INIT, "reset the board...\n"); 2229 sx_dprintk(SX_DEBUG_INIT, "reset the board...\n");
2126
2127 board->flags |= SX_BOARD_PRESENT;
2128 2230
2129 func_exit(); 2231 func_exit();
2130 return 1; 2232 return 1;
2131} 2233}
2132 2234
2133 2235#if defined(CONFIG_ISA) || defined(CONFIG_EISA)
2134 2236
2135/* Specialix probes for this card at 32k increments from 640k to 16M. 2237/* Specialix probes for this card at 32k increments from 640k to 16M.
2136 I consider machines with less than 16M unlikely nowadays, so I'm 2238 I consider machines with less than 16M unlikely nowadays, so I'm
@@ -2138,28 +2240,27 @@ static int probe_sx (struct sx_board *board)
2138 card. 0xe0000 and 0xf0000 are taken by the BIOS. That only leaves 2240 card. 0xe0000 and 0xf0000 are taken by the BIOS. That only leaves
2139 0xc0000, 0xc8000, 0xd0000 and 0xd8000 . */ 2241 0xc0000, 0xc8000, 0xd0000 and 0xd8000 . */
2140 2242
2141static int probe_si (struct sx_board *board) 2243static int __devinit probe_si(struct sx_board *board)
2142{ 2244{
2143 int i; 2245 int i;
2144 2246
2145 func_enter(); 2247 func_enter();
2146 sx_dprintk (SX_DEBUG_PROBE, "Going to verify SI signature hw %lx at %p.\n", board->hw_base, 2248 sx_dprintk(SX_DEBUG_PROBE, "Going to verify SI signature hw %lx at "
2147 board->base + SI2_ISA_ID_BASE); 2249 "%p.\n", board->hw_base, board->base + SI2_ISA_ID_BASE);
2148 2250
2149 if (sx_debug & SX_DEBUG_PROBE) 2251 if (sx_debug & SX_DEBUG_PROBE)
2150 my_hd_io(board->base + SI2_ISA_ID_BASE, 0x8); 2252 my_hd_io(board->base + SI2_ISA_ID_BASE, 0x8);
2151 2253
2152 if (!IS_EISA_BOARD(board)) { 2254 if (!IS_EISA_BOARD(board)) {
2153 if( IS_SI1_BOARD(board) ) 2255 if (IS_SI1_BOARD(board)) {
2154 { 2256 for (i = 0; i < 8; i++) {
2155 for (i=0;i<8;i++) { 2257 write_sx_byte(board, SI2_ISA_ID_BASE + 7 - i,i);
2156 write_sx_byte (board, SI2_ISA_ID_BASE+7-i,i); 2258 }
2157
2158 } 2259 }
2159 } 2260 for (i = 0; i < 8; i++) {
2160 for (i=0;i<8;i++) { 2261 if ((read_sx_byte(board, SI2_ISA_ID_BASE + 7 - i) & 7)
2161 if ((read_sx_byte (board, SI2_ISA_ID_BASE+7-i) & 7) != i) { 2262 != i) {
2162 func_exit (); 2263 func_exit();
2163 return 0; 2264 return 0;
2164 } 2265 }
2165 } 2266 }
@@ -2169,20 +2270,20 @@ static int probe_si (struct sx_board *board)
2169 but to prevent trouble, we'd better double check that we don't 2270 but to prevent trouble, we'd better double check that we don't
2170 have an SI1 board when we're probing for an SI2 board.... */ 2271 have an SI1 board when we're probing for an SI2 board.... */
2171 2272
2172 write_sx_byte (board, SI2_ISA_ID_BASE,0x10); 2273 write_sx_byte(board, SI2_ISA_ID_BASE, 0x10);
2173 if ( IS_SI1_BOARD(board)) { 2274 if (IS_SI1_BOARD(board)) {
2174 /* This should be an SI1 board, which has this 2275 /* This should be an SI1 board, which has this
2175 location writable... */ 2276 location writable... */
2176 if (read_sx_byte (board, SI2_ISA_ID_BASE) != 0x10) { 2277 if (read_sx_byte(board, SI2_ISA_ID_BASE) != 0x10) {
2177 func_exit (); 2278 func_exit();
2178 return 0; 2279 return 0;
2179 } 2280 }
2180 } else { 2281 } else {
2181 /* This should be an SI2 board, which has the bottom 2282 /* This should be an SI2 board, which has the bottom
2182 3 bits non-writable... */ 2283 3 bits non-writable... */
2183 if (read_sx_byte (board, SI2_ISA_ID_BASE) == 0x10) { 2284 if (read_sx_byte(board, SI2_ISA_ID_BASE) == 0x10) {
2184 func_exit (); 2285 func_exit();
2185 return 0; 2286 return 0;
2186 } 2287 }
2187 } 2288 }
2188 2289
@@ -2190,45 +2291,44 @@ static int probe_si (struct sx_board *board)
2190 but to prevent trouble, we'd better double check that we don't 2291 but to prevent trouble, we'd better double check that we don't
2191 have an SI1 board when we're probing for an SI2 board.... */ 2292 have an SI1 board when we're probing for an SI2 board.... */
2192 2293
2193 write_sx_byte (board, SI2_ISA_ID_BASE,0x10); 2294 write_sx_byte(board, SI2_ISA_ID_BASE, 0x10);
2194 if ( IS_SI1_BOARD(board)) { 2295 if (IS_SI1_BOARD(board)) {
2195 /* This should be an SI1 board, which has this 2296 /* This should be an SI1 board, which has this
2196 location writable... */ 2297 location writable... */
2197 if (read_sx_byte (board, SI2_ISA_ID_BASE) != 0x10) { 2298 if (read_sx_byte(board, SI2_ISA_ID_BASE) != 0x10) {
2198 func_exit(); 2299 func_exit();
2199 return 0; 2300 return 0;
2200 } 2301 }
2201 } else { 2302 } else {
2202 /* This should be an SI2 board, which has the bottom 2303 /* This should be an SI2 board, which has the bottom
2203 3 bits non-writable... */ 2304 3 bits non-writable... */
2204 if (read_sx_byte (board, SI2_ISA_ID_BASE) == 0x10) { 2305 if (read_sx_byte(board, SI2_ISA_ID_BASE) == 0x10) {
2205 func_exit (); 2306 func_exit();
2206 return 0; 2307 return 0;
2207 } 2308 }
2208 } 2309 }
2209 2310
2210 printheader (); 2311 printheader();
2211 2312
2212 printk (KERN_DEBUG "sx: Found an SI board at %lx\n", board->hw_base); 2313 printk(KERN_DEBUG "sx: Found an SI board at %lx\n", board->hw_base);
2213 /* Compared to the SX boards, it is a complete guess as to what 2314 /* Compared to the SX boards, it is a complete guess as to what
2214 this card is up to... */ 2315 this card is up to... */
2215 2316
2216 board->nports = -1; 2317 board->nports = -1;
2217 2318
2218 /* This resets the processor, and keeps it off the bus. */ 2319 /* This resets the processor, and keeps it off the bus. */
2219 if (!sx_reset (board)) 2320 if (!sx_reset(board))
2220 return 0; 2321 return 0;
2221 sx_dprintk (SX_DEBUG_INIT, "reset the board...\n"); 2322 sx_dprintk(SX_DEBUG_INIT, "reset the board...\n");
2222
2223 board->flags |= SX_BOARD_PRESENT;
2224 2323
2225 func_exit(); 2324 func_exit();
2226 return 1; 2325 return 1;
2227} 2326}
2327#endif
2228 2328
2229static struct tty_operations sx_ops = { 2329static const struct tty_operations sx_ops = {
2230 .break_ctl = sx_break, 2330 .break_ctl = sx_break,
2231 .open = sx_open, 2331 .open = sx_open,
2232 .close = gs_close, 2332 .close = gs_close,
2233 .write = gs_write, 2333 .write = gs_write,
2234 .put_char = gs_put_char, 2334 .put_char = gs_put_char,
@@ -2263,34 +2363,23 @@ static int sx_init_drivers(void)
2263 sx_driver->type = TTY_DRIVER_TYPE_SERIAL; 2363 sx_driver->type = TTY_DRIVER_TYPE_SERIAL;
2264 sx_driver->subtype = SERIAL_TYPE_NORMAL; 2364 sx_driver->subtype = SERIAL_TYPE_NORMAL;
2265 sx_driver->init_termios = tty_std_termios; 2365 sx_driver->init_termios = tty_std_termios;
2266 sx_driver->init_termios.c_cflag = 2366 sx_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2267 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 2367 sx_driver->init_termios.c_ispeed = 9600;
2368 sx_driver->init_termios.c_ospeed = 9600;
2268 sx_driver->flags = TTY_DRIVER_REAL_RAW; 2369 sx_driver->flags = TTY_DRIVER_REAL_RAW;
2269 tty_set_operations(sx_driver, &sx_ops); 2370 tty_set_operations(sx_driver, &sx_ops);
2270 2371
2271 if ((error = tty_register_driver(sx_driver))) { 2372 if ((error = tty_register_driver(sx_driver))) {
2272 put_tty_driver(sx_driver); 2373 put_tty_driver(sx_driver);
2273 printk(KERN_ERR "sx: Couldn't register sx driver, error = %d\n", 2374 printk(KERN_ERR "sx: Couldn't register sx driver, error = %d\n",
2274 error); 2375 error);
2275 return 1; 2376 return 1;
2276 } 2377 }
2277 func_exit(); 2378 func_exit();
2278 return 0; 2379 return 0;
2279} 2380}
2280 2381
2281 2382static int sx_init_portstructs(int nboards, int nports)
2282static void * ckmalloc (int size)
2283{
2284 void *p;
2285
2286 p = kmalloc(size, GFP_KERNEL);
2287 if (p)
2288 memset(p, 0, size);
2289 return p;
2290}
2291
2292
2293static int sx_init_portstructs (int nboards, int nports)
2294{ 2383{
2295 struct sx_board *board; 2384 struct sx_board *board;
2296 struct sx_port *port; 2385 struct sx_port *port;
@@ -2301,8 +2390,9 @@ static int sx_init_portstructs (int nboards, int nports)
2301 func_enter(); 2390 func_enter();
2302 2391
2303 /* Many drivers statically allocate the maximum number of ports 2392 /* Many drivers statically allocate the maximum number of ports
2304 There is no reason not to allocate them dynamically. Is there? -- REW */ 2393 There is no reason not to allocate them dynamically.
2305 sx_ports = ckmalloc(nports * sizeof (struct sx_port)); 2394 Is there? -- REW */
2395 sx_ports = kcalloc(nports, sizeof(struct sx_port), GFP_KERNEL);
2306 if (!sx_ports) 2396 if (!sx_ports)
2307 return -ENOMEM; 2397 return -ENOMEM;
2308 2398
@@ -2310,10 +2400,10 @@ static int sx_init_portstructs (int nboards, int nports)
2310 for (i = 0; i < nboards; i++) { 2400 for (i = 0; i < nboards; i++) {
2311 board = &boards[i]; 2401 board = &boards[i];
2312 board->ports = port; 2402 board->ports = port;
2313 for (j=0; j < boards[i].nports;j++) { 2403 for (j = 0; j < boards[i].nports; j++) {
2314 sx_dprintk (SX_DEBUG_INIT, "initing port %d\n", j); 2404 sx_dprintk(SX_DEBUG_INIT, "initing port %d\n", j);
2315 port->gs.magic = SX_MAGIC; 2405 port->gs.magic = SX_MAGIC;
2316 port->gs.close_delay = HZ/2; 2406 port->gs.close_delay = HZ / 2;
2317 port->gs.closing_wait = 30 * HZ; 2407 port->gs.closing_wait = 30 * HZ;
2318 port->board = board; 2408 port->board = board;
2319 port->gs.rd = &sx_real_driver; 2409 port->gs.rd = &sx_real_driver;
@@ -2325,8 +2415,8 @@ static int sx_init_portstructs (int nboards, int nports)
2325 * Initializing wait queue 2415 * Initializing wait queue
2326 */ 2416 */
2327 init_waitqueue_head(&port->gs.open_wait); 2417 init_waitqueue_head(&port->gs.open_wait);
2328 init_waitqueue_head(&port->gs.close_wait); 2418 init_waitqueue_head(&port->gs.close_wait);
2329 2419
2330 port++; 2420 port++;
2331 } 2421 }
2332 } 2422 }
@@ -2337,28 +2427,36 @@ static int sx_init_portstructs (int nboards, int nports)
2337 board = &boards[i]; 2427 board = &boards[i];
2338 board->port_base = portno; 2428 board->port_base = portno;
2339 /* Possibly the configuration was rejected. */ 2429 /* Possibly the configuration was rejected. */
2340 sx_dprintk (SX_DEBUG_PROBE, "Board has %d channels\n", board->nports); 2430 sx_dprintk(SX_DEBUG_PROBE, "Board has %d channels\n",
2341 if (board->nports <= 0) continue; 2431 board->nports);
2432 if (board->nports <= 0)
2433 continue;
2342 /* XXX byteorder ?? */ 2434 /* XXX byteorder ?? */
2343 for (addr = 0x80;addr != 0;addr = read_sx_word (board, addr) & 0x7fff) { 2435 for (addr = 0x80; addr != 0;
2344 chans = sx_read_module_byte (board, addr, mc_type); 2436 addr = read_sx_word(board, addr) & 0x7fff) {
2345 sx_dprintk (SX_DEBUG_PROBE, "Module at %x: %d channels\n", addr, chans); 2437 chans = sx_read_module_byte(board, addr, mc_type);
2346 sx_dprintk (SX_DEBUG_PROBE, "Port at"); 2438 sx_dprintk(SX_DEBUG_PROBE, "Module at %x: %d "
2347 for (j=0;j<chans;j++) { 2439 "channels\n", addr, chans);
2348 /* The "sx-way" is the way it SHOULD be done. That way in the 2440 sx_dprintk(SX_DEBUG_PROBE, "Port at");
2349 future, the firmware may for example pack the structures a bit 2441 for (j = 0; j < chans; j++) {
2350 more efficient. Neil tells me it isn't going to happen anytime 2442 /* The "sx-way" is the way it SHOULD be done.
2351 soon though. */ 2443 That way in the future, the firmware may for
2444 example pack the structures a bit more
2445 efficient. Neil tells me it isn't going to
2446 happen anytime soon though. */
2352 if (IS_SX_BOARD(board)) 2447 if (IS_SX_BOARD(board))
2353 port->ch_base = sx_read_module_word (board, addr+j*2, mc_chan_pointer); 2448 port->ch_base = sx_read_module_word(
2449 board, addr + j * 2,
2450 mc_chan_pointer);
2354 else 2451 else
2355 port->ch_base = addr + 0x100 + 0x300*j; 2452 port->ch_base = addr + 0x100 + 0x300 *j;
2356 2453
2357 sx_dprintk (SX_DEBUG_PROBE, " %x", port->ch_base); 2454 sx_dprintk(SX_DEBUG_PROBE, " %x",
2455 port->ch_base);
2358 port->line = portno++; 2456 port->line = portno++;
2359 port++; 2457 port++;
2360 } 2458 }
2361 sx_dprintk (SX_DEBUG_PROBE, "\n"); 2459 sx_dprintk(SX_DEBUG_PROBE, "\n");
2362 } 2460 }
2363 /* This has to be done earlier. */ 2461 /* This has to be done earlier. */
2364 /* board->flags |= SX_BOARD_INITIALIZED; */ 2462 /* board->flags |= SX_BOARD_INITIALIZED; */
@@ -2368,6 +2466,17 @@ static int sx_init_portstructs (int nboards, int nports)
2368 return 0; 2466 return 0;
2369} 2467}
2370 2468
2469static unsigned int sx_find_free_board(void)
2470{
2471 unsigned int i;
2472
2473 for (i = 0; i < SX_NBOARDS; i++)
2474 if (!(boards[i].flags & SX_BOARD_PRESENT))
2475 break;
2476
2477 return i;
2478}
2479
2371static void __exit sx_release_drivers(void) 2480static void __exit sx_release_drivers(void)
2372{ 2481{
2373 func_enter(); 2482 func_enter();
@@ -2376,7 +2485,122 @@ static void __exit sx_release_drivers(void)
2376 func_exit(); 2485 func_exit();
2377} 2486}
2378 2487
2379#ifdef CONFIG_PCI 2488static void __devexit sx_remove_card(struct sx_board *board,
2489 struct pci_dev *pdev)
2490{
2491 if (board->flags & SX_BOARD_INITIALIZED) {
2492 /* The board should stop messing with us. (actually I mean the
2493 interrupt) */
2494 sx_reset(board);
2495 if ((board->irq) && (board->flags & SX_IRQ_ALLOCATED))
2496 free_irq(board->irq, board);
2497
2498 /* It is safe/allowed to del_timer a non-active timer */
2499 del_timer(&board->timer);
2500 if (pdev) {
2501 pci_iounmap(pdev, board->base);
2502 pci_release_region(pdev, IS_CF_BOARD(board) ? 3 : 2);
2503 } else {
2504 iounmap(board->base);
2505 release_region(board->hw_base, board->hw_len);
2506 }
2507
2508 board->flags &= ~(SX_BOARD_INITIALIZED | SX_BOARD_PRESENT);
2509 }
2510}
2511
2512#ifdef CONFIG_EISA
2513
2514static int __devinit sx_eisa_probe(struct device *dev)
2515{
2516 struct eisa_device *edev = to_eisa_device(dev);
2517 struct sx_board *board;
2518 unsigned long eisa_slot = edev->base_addr;
2519 unsigned int i;
2520 int retval = -EIO;
2521
2522 mutex_lock(&sx_boards_lock);
2523 i = sx_find_free_board();
2524 if (i == SX_NBOARDS) {
2525 mutex_unlock(&sx_boards_lock);
2526 goto err;
2527 }
2528 board = &boards[i];
2529 board->flags |= SX_BOARD_PRESENT;
2530 mutex_unlock(&sx_boards_lock);
2531
2532 dev_info(dev, "XIO : Signature found in EISA slot %lu, "
2533 "Product %d Rev %d (REPORT THIS TO LKLM)\n",
2534 eisa_slot >> 12,
2535 inb(eisa_slot + EISA_VENDOR_ID_OFFSET + 2),
2536 inb(eisa_slot + EISA_VENDOR_ID_OFFSET + 3));
2537
2538 board->eisa_base = eisa_slot;
2539 board->flags &= ~SX_BOARD_TYPE;
2540 board->flags |= SI_EISA_BOARD;
2541
2542 board->hw_base = ((inb(eisa_slot + 0xc01) << 8) +
2543 inb(eisa_slot + 0xc00)) << 16;
2544 board->hw_len = SI2_EISA_WINDOW_LEN;
2545 if (!request_region(board->hw_base, board->hw_len, "sx")) {
2546 dev_err(dev, "can't request region\n");
2547 goto err_flag;
2548 }
2549 board->base2 =
2550 board->base = ioremap(board->hw_base, SI2_EISA_WINDOW_LEN);
2551 if (!board->base) {
2552 dev_err(dev, "can't remap memory\n");
2553 goto err_reg;
2554 }
2555
2556 sx_dprintk(SX_DEBUG_PROBE, "IO hw_base address: %lx\n", board->hw_base);
2557 sx_dprintk(SX_DEBUG_PROBE, "base: %p\n", board->base);
2558 board->irq = inb(eisa_slot + 0xc02) >> 4;
2559 sx_dprintk(SX_DEBUG_PROBE, "IRQ: %d\n", board->irq);
2560
2561 if (!probe_si(board))
2562 goto err_unmap;
2563
2564 dev_set_drvdata(dev, board);
2565
2566 return 0;
2567err_unmap:
2568 iounmap(board->base);
2569err_reg:
2570 release_region(board->hw_base, board->hw_len);
2571err_flag:
2572 board->flags &= ~SX_BOARD_PRESENT;
2573err:
2574 return retval;
2575}
2576
2577static int __devexit sx_eisa_remove(struct device *dev)
2578{
2579 struct sx_board *board = dev_get_drvdata(dev);
2580
2581 sx_remove_card(board, NULL);
2582
2583 return 0;
2584}
2585
2586static struct eisa_device_id sx_eisa_tbl[] = {
2587 { "SLX" },
2588 { "" }
2589};
2590
2591MODULE_DEVICE_TABLE(eisa, sx_eisa_tbl);
2592
2593static struct eisa_driver sx_eisadriver = {
2594 .id_table = sx_eisa_tbl,
2595 .driver = {
2596 .name = "sx",
2597 .probe = sx_eisa_probe,
2598 .remove = __devexit_p(sx_eisa_remove),
2599 }
2600};
2601
2602#endif
2603
2380 /******************************************************** 2604 /********************************************************
2381 * Setting bit 17 in the CNTRL register of the PLX 9050 * 2605 * Setting bit 17 in the CNTRL register of the PLX 9050 *
2382 * chip forces a retry on writes while a read is pending.* 2606 * chip forces a retry on writes while a read is pending.*
@@ -2388,233 +2612,265 @@ static void __exit sx_release_drivers(void)
2388 EEprom. As the bit is read/write for the CPU, we can fix it here, 2612 EEprom. As the bit is read/write for the CPU, we can fix it here,
2389 if we detect that it isn't set correctly. -- REW */ 2613 if we detect that it isn't set correctly. -- REW */
2390 2614
2391static void fix_sx_pci (struct pci_dev *pdev, struct sx_board *board) 2615static void __devinit fix_sx_pci(struct pci_dev *pdev, struct sx_board *board)
2392{ 2616{
2393 unsigned int hwbase; 2617 unsigned int hwbase;
2394 void __iomem *rebase; 2618 void __iomem *rebase;
2395 unsigned int t; 2619 unsigned int t;
2396 2620
2397#define CNTRL_REG_OFFSET 0x50 2621#define CNTRL_REG_OFFSET 0x50
2398#define CNTRL_REG_GOODVALUE 0x18260000 2622#define CNTRL_REG_GOODVALUE 0x18260000
2399 2623
2400 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase); 2624 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
2401 hwbase &= PCI_BASE_ADDRESS_MEM_MASK; 2625 hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
2402 rebase = ioremap(hwbase, 0x80); 2626 rebase = ioremap(hwbase, 0x80);
2403 t = readl (rebase + CNTRL_REG_OFFSET); 2627 t = readl(rebase + CNTRL_REG_OFFSET);
2404 if (t != CNTRL_REG_GOODVALUE) { 2628 if (t != CNTRL_REG_GOODVALUE) {
2405 printk (KERN_DEBUG "sx: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE); 2629 printk(KERN_DEBUG "sx: performing cntrl reg fix: %08x -> "
2406 writel (CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET); 2630 "%08x\n", t, CNTRL_REG_GOODVALUE);
2631 writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
2407 } 2632 }
2408 iounmap(rebase); 2633 iounmap(rebase);
2409} 2634}
2410#endif
2411
2412 2635
2413static int __init sx_init(void) 2636static int __devinit sx_pci_probe(struct pci_dev *pdev,
2637 const struct pci_device_id *ent)
2414{ 2638{
2415 int i;
2416 int found = 0;
2417 int eisa_slot;
2418 struct sx_board *board; 2639 struct sx_board *board;
2640 unsigned int i, reg;
2641 int retval = -EIO;
2419 2642
2420#ifdef CONFIG_PCI 2643 mutex_lock(&sx_boards_lock);
2421 struct pci_dev *pdev = NULL; 2644 i = sx_find_free_board();
2422 unsigned int tint; 2645 if (i == SX_NBOARDS) {
2423 unsigned short tshort; 2646 mutex_unlock(&sx_boards_lock);
2424#endif 2647 goto err;
2648 }
2649 board = &boards[i];
2650 board->flags |= SX_BOARD_PRESENT;
2651 mutex_unlock(&sx_boards_lock);
2425 2652
2426 func_enter(); 2653 retval = pci_enable_device(pdev);
2427 sx_dprintk (SX_DEBUG_INIT, "Initing sx module... (sx_debug=%d)\n", sx_debug); 2654 if (retval)
2428 if (abs ((long) (&sx_debug) - sx_debug) < 0x10000) { 2655 goto err_flag;
2429 printk (KERN_WARNING "sx: sx_debug is an address, instead of a value. " 2656
2430 "Assuming -1.\n"); 2657 board->flags &= ~SX_BOARD_TYPE;
2431 printk ("(%p)\n", &sx_debug); 2658 board->flags |= (pdev->subsystem_vendor == 0x200) ? SX_PCI_BOARD :
2432 sx_debug=-1; 2659 SX_CFPCI_BOARD;
2660
2661 /* CF boards use base address 3.... */
2662 reg = IS_CF_BOARD(board) ? 3 : 2;
2663 retval = pci_request_region(pdev, reg, "sx");
2664 if (retval) {
2665 dev_err(&pdev->dev, "can't request region\n");
2666 goto err_flag;
2667 }
2668 board->hw_base = pci_resource_start(pdev, reg);
2669 board->base2 =
2670 board->base = pci_iomap(pdev, reg, WINDOW_LEN(board));
2671 if (!board->base) {
2672 dev_err(&pdev->dev, "ioremap failed\n");
2673 goto err_reg;
2433 } 2674 }
2434 2675
2435 if (misc_register(&sx_fw_device) < 0) { 2676 /* Most of the stuff on the CF board is offset by 0x18000 .... */
2436 printk(KERN_ERR "SX: Unable to register firmware loader driver.\n"); 2677 if (IS_CF_BOARD(board))
2437 return -EIO; 2678 board->base += 0x18000;
2679
2680 board->irq = pdev->irq;
2681
2682 dev_info(&pdev->dev, "Got a specialix card: %p(%d) %x.\n", board->base,
2683 board->irq, board->flags);
2684
2685 if (!probe_sx(board)) {
2686 retval = -EIO;
2687 goto err_unmap;
2438 } 2688 }
2439 2689
2440#ifdef CONFIG_PCI 2690 fix_sx_pci(pdev, board);
2441 while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX,
2442 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
2443 pdev))) {
2444 if (pci_enable_device(pdev))
2445 continue;
2446 2691
2447 /* Specialix has a whole bunch of cards with 2692 pci_set_drvdata(pdev, board);
2448 0x2000 as the device ID. They say its because
2449 the standard requires it. Stupid standard. */
2450 /* It seems that reading a word doesn't work reliably on 2.0.
2451 Also, reading a non-aligned dword doesn't work. So we read the
2452 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
2453 ourselves */
2454 /* I don't know why the define doesn't work, constant 0x2c does --REW */
2455 pci_read_config_dword (pdev, 0x2c, &tint);
2456 tshort = (tint >> 16) & 0xffff;
2457 sx_dprintk (SX_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
2458 /* sx_dprintk (SX_DEBUG_PROBE, "pdev = %d/%d (%x)\n", pdev, tint); */
2459 if ((tshort != 0x0200) && (tshort != 0x0300)) {
2460 sx_dprintk (SX_DEBUG_PROBE, "But it's not an SX card (%d)...\n",
2461 tshort);
2462 continue;
2463 }
2464 board = &boards[found];
2465 2693
2466 board->flags &= ~SX_BOARD_TYPE; 2694 return 0;
2467 board->flags |= (tshort == 0x200)?SX_PCI_BOARD: 2695err_unmap:
2468 SX_CFPCI_BOARD; 2696 pci_iounmap(pdev, board->base);
2469 2697err_reg:
2470 /* CF boards use base address 3.... */ 2698 pci_release_region(pdev, reg);
2471 if (IS_CF_BOARD (board)) 2699err_flag:
2472 board->hw_base = pci_resource_start (pdev, 3); 2700 board->flags &= ~SX_BOARD_PRESENT;
2473 else 2701err:
2474 board->hw_base = pci_resource_start (pdev, 2); 2702 return retval;
2475 board->base2 = 2703}
2476 board->base = ioremap(board->hw_base, WINDOW_LEN (board));
2477 if (!board->base) {
2478 printk(KERN_ERR "ioremap failed\n");
2479 /* XXX handle error */
2480 }
2481 2704
2482 /* Most of the stuff on the CF board is offset by 2705static void __devexit sx_pci_remove(struct pci_dev *pdev)
2483 0x18000 .... */ 2706{
2484 if (IS_CF_BOARD (board)) board->base += 0x18000; 2707 struct sx_board *board = pci_get_drvdata(pdev);
2485 2708
2486 board->irq = pdev->irq; 2709 sx_remove_card(board, pdev);
2710}
2487 2711
2488 sx_dprintk (SX_DEBUG_PROBE, "Got a specialix card: %x/%p(%d) %x.\n", 2712/* Specialix has a whole bunch of cards with 0x2000 as the device ID. They say
2489 tint, boards[found].base, board->irq, board->flags); 2713 its because the standard requires it. So check for SUBVENDOR_ID. */
2714static struct pci_device_id sx_pci_tbl[] = {
2715 { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
2716 .subvendor = 0x0200,.subdevice = PCI_ANY_ID },
2717 { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
2718 .subvendor = 0x0300,.subdevice = PCI_ANY_ID },
2719 { 0 }
2720};
2490 2721
2491 if (probe_sx (board)) { 2722MODULE_DEVICE_TABLE(pci, sx_pci_tbl);
2492 found++; 2723
2493 fix_sx_pci (pdev, board); 2724static struct pci_driver sx_pcidriver = {
2494 } else 2725 .name = "sx",
2495 iounmap(board->base2); 2726 .id_table = sx_pci_tbl,
2496 } 2727 .probe = sx_pci_probe,
2728 .remove = __devexit_p(sx_pci_remove)
2729};
2730
2731static int __init sx_init(void)
2732{
2733#ifdef CONFIG_EISA
2734 int retval1;
2497#endif 2735#endif
2736#ifdef CONFIG_ISA
2737 struct sx_board *board;
2738 unsigned int i;
2739#endif
2740 unsigned int found = 0;
2741 int retval;
2742
2743 func_enter();
2744 sx_dprintk(SX_DEBUG_INIT, "Initing sx module... (sx_debug=%d)\n",
2745 sx_debug);
2746 if (abs((long)(&sx_debug) - sx_debug) < 0x10000) {
2747 printk(KERN_WARNING "sx: sx_debug is an address, instead of a "
2748 "value. Assuming -1.\n(%p)\n", &sx_debug);
2749 sx_debug = -1;
2750 }
2498 2751
2499 for (i=0;i<NR_SX_ADDRS;i++) { 2752 if (misc_register(&sx_fw_device) < 0) {
2753 printk(KERN_ERR "SX: Unable to register firmware loader "
2754 "driver.\n");
2755 return -EIO;
2756 }
2757#ifdef CONFIG_ISA
2758 for (i = 0; i < NR_SX_ADDRS; i++) {
2500 board = &boards[found]; 2759 board = &boards[found];
2501 board->hw_base = sx_probe_addrs[i]; 2760 board->hw_base = sx_probe_addrs[i];
2761 board->hw_len = SX_WINDOW_LEN;
2762 if (!request_region(board->hw_base, board->hw_len, "sx"))
2763 continue;
2502 board->base2 = 2764 board->base2 =
2503 board->base = ioremap(board->hw_base, SX_WINDOW_LEN); 2765 board->base = ioremap(board->hw_base, board->hw_len);
2766 if (!board->base)
2767 goto err_sx_reg;
2504 board->flags &= ~SX_BOARD_TYPE; 2768 board->flags &= ~SX_BOARD_TYPE;
2505 board->flags |= SX_ISA_BOARD; 2769 board->flags |= SX_ISA_BOARD;
2506 board->irq = sx_irqmask?-1:0; 2770 board->irq = sx_irqmask ? -1 : 0;
2507 2771
2508 if (probe_sx (board)) { 2772 if (probe_sx(board)) {
2773 board->flags |= SX_BOARD_PRESENT;
2509 found++; 2774 found++;
2510 } else { 2775 } else {
2511 iounmap(board->base); 2776 iounmap(board->base);
2777err_sx_reg:
2778 release_region(board->hw_base, board->hw_len);
2512 } 2779 }
2513 } 2780 }
2514 2781
2515 for (i=0;i<NR_SI_ADDRS;i++) { 2782 for (i = 0; i < NR_SI_ADDRS; i++) {
2516 board = &boards[found]; 2783 board = &boards[found];
2517 board->hw_base = si_probe_addrs[i]; 2784 board->hw_base = si_probe_addrs[i];
2785 board->hw_len = SI2_ISA_WINDOW_LEN;
2786 if (!request_region(board->hw_base, board->hw_len, "sx"))
2787 continue;
2518 board->base2 = 2788 board->base2 =
2519 board->base = ioremap(board->hw_base, SI2_ISA_WINDOW_LEN); 2789 board->base = ioremap(board->hw_base, board->hw_len);
2790 if (!board->base)
2791 goto err_si_reg;
2520 board->flags &= ~SX_BOARD_TYPE; 2792 board->flags &= ~SX_BOARD_TYPE;
2521 board->flags |= SI_ISA_BOARD; 2793 board->flags |= SI_ISA_BOARD;
2522 board->irq = sx_irqmask ?-1:0; 2794 board->irq = sx_irqmask ? -1 : 0;
2523 2795
2524 if (probe_si (board)) { 2796 if (probe_si(board)) {
2797 board->flags |= SX_BOARD_PRESENT;
2525 found++; 2798 found++;
2526 } else { 2799 } else {
2527 iounmap (board->base); 2800 iounmap(board->base);
2801err_si_reg:
2802 release_region(board->hw_base, board->hw_len);
2528 } 2803 }
2529 } 2804 }
2530 for (i=0;i<NR_SI1_ADDRS;i++) { 2805 for (i = 0; i < NR_SI1_ADDRS; i++) {
2531 board = &boards[found]; 2806 board = &boards[found];
2532 board->hw_base = si1_probe_addrs[i]; 2807 board->hw_base = si1_probe_addrs[i];
2808 board->hw_len = SI1_ISA_WINDOW_LEN;
2809 if (!request_region(board->hw_base, board->hw_len, "sx"))
2810 continue;
2533 board->base2 = 2811 board->base2 =
2534 board->base = ioremap(board->hw_base, SI1_ISA_WINDOW_LEN); 2812 board->base = ioremap(board->hw_base, board->hw_len);
2813 if (!board->base)
2814 goto err_si1_reg;
2535 board->flags &= ~SX_BOARD_TYPE; 2815 board->flags &= ~SX_BOARD_TYPE;
2536 board->flags |= SI1_ISA_BOARD; 2816 board->flags |= SI1_ISA_BOARD;
2537 board->irq = sx_irqmask ?-1:0; 2817 board->irq = sx_irqmask ? -1 : 0;
2538 2818
2539 if (probe_si (board)) { 2819 if (probe_si(board)) {
2820 board->flags |= SX_BOARD_PRESENT;
2540 found++; 2821 found++;
2541 } else { 2822 } else {
2542 iounmap (board->base); 2823 iounmap(board->base);
2824err_si1_reg:
2825 release_region(board->hw_base, board->hw_len);
2543 } 2826 }
2544 } 2827 }
2828#endif
2829#ifdef CONFIG_EISA
2830 retval1 = eisa_driver_register(&sx_eisadriver);
2831#endif
2832 retval = pci_register_driver(&sx_pcidriver);
2545 2833
2546 sx_dprintk(SX_DEBUG_PROBE, "Probing for EISA cards\n");
2547 for(eisa_slot=0x1000; eisa_slot<0x10000; eisa_slot+=0x1000)
2548 {
2549 if((inb(eisa_slot+0xc80)==0x4d) &&
2550 (inb(eisa_slot+0xc81)==0x98))
2551 {
2552 sx_dprintk(SX_DEBUG_PROBE, "%s : Signature found in EISA slot %d, Product %d Rev %d\n",
2553 "XIO", (eisa_slot>>12), inb(eisa_slot+0xc82), inb(eisa_slot+0xc83));
2554
2555 board = &boards[found];
2556 board->eisa_base = eisa_slot;
2557 board->flags &= ~SX_BOARD_TYPE;
2558 board->flags |= SI_EISA_BOARD;
2559
2560 board->hw_base = (((inb(0xc01+eisa_slot) << 8) + inb(0xc00+eisa_slot)) << 16);
2561 board->base2 =
2562 board->base = ioremap(board->hw_base, SI2_EISA_WINDOW_LEN);
2563
2564 sx_dprintk(SX_DEBUG_PROBE, "IO hw_base address: %lx\n", board->hw_base);
2565 sx_dprintk(SX_DEBUG_PROBE, "base: %p\n", board->base);
2566 board->irq = inb(board->eisa_base+0xc02)>>4;
2567 sx_dprintk(SX_DEBUG_PROBE, "IRQ: %d\n", board->irq);
2568
2569 probe_si(board);
2570
2571 found++;
2572 }
2573 }
2574 if (found) { 2834 if (found) {
2575 printk (KERN_INFO "sx: total of %d boards detected.\n", found); 2835 printk(KERN_INFO "sx: total of %d boards detected.\n", found);
2576 } else { 2836 retval = 0;
2577 misc_deregister(&sx_fw_device); 2837 } else if (retval) {
2838#ifdef CONFIG_EISA
2839 retval = retval1;
2840 if (retval1)
2841#endif
2842 misc_deregister(&sx_fw_device);
2578 } 2843 }
2579 2844
2580 func_exit(); 2845 func_exit();
2581 return found?0:-EIO; 2846 return retval;
2582} 2847}
2583 2848
2584 2849static void __exit sx_exit(void)
2585static void __exit sx_exit (void)
2586{ 2850{
2587 int i; 2851 int i;
2588 struct sx_board *board;
2589 2852
2590 func_enter(); 2853 func_enter();
2591 for (i = 0; i < SX_NBOARDS; i++) { 2854#ifdef CONFIG_EISA
2592 board = &boards[i]; 2855 eisa_driver_unregister(&sx_eisadriver);
2593 if (board->flags & SX_BOARD_INITIALIZED) { 2856#endif
2594 sx_dprintk (SX_DEBUG_CLEANUP, "Cleaning up board at %p\n", board->base); 2857 pci_unregister_driver(&sx_pcidriver);
2595 /* The board should stop messing with us. 2858
2596 (actually I mean the interrupt) */ 2859 for (i = 0; i < SX_NBOARDS; i++)
2597 sx_reset (board); 2860 sx_remove_card(&boards[i], NULL);
2598 if ((board->irq) && (board->flags & SX_IRQ_ALLOCATED)) 2861
2599 free_irq (board->irq, board);
2600
2601 /* It is safe/allowed to del_timer a non-active timer */
2602 del_timer (& board->timer);
2603 iounmap(board->base);
2604 }
2605 }
2606 if (misc_deregister(&sx_fw_device) < 0) { 2862 if (misc_deregister(&sx_fw_device) < 0) {
2607 printk (KERN_INFO "sx: couldn't deregister firmware loader devic\n"); 2863 printk(KERN_INFO "sx: couldn't deregister firmware loader "
2864 "device\n");
2608 } 2865 }
2609 sx_dprintk (SX_DEBUG_CLEANUP, "Cleaning up drivers (%d)\n", sx_initialized); 2866 sx_dprintk(SX_DEBUG_CLEANUP, "Cleaning up drivers (%d)\n",
2867 sx_initialized);
2610 if (sx_initialized) 2868 if (sx_initialized)
2611 sx_release_drivers (); 2869 sx_release_drivers();
2612 2870
2613 kfree (sx_ports); 2871 kfree(sx_ports);
2614 func_exit(); 2872 func_exit();
2615} 2873}
2616 2874
2617module_init(sx_init); 2875module_init(sx_init);
2618module_exit(sx_exit); 2876module_exit(sx_exit);
2619
2620
diff --git a/drivers/char/sx.h b/drivers/char/sx.h
index e01f83cbe299..432aad0a2ddd 100644
--- a/drivers/char/sx.h
+++ b/drivers/char/sx.h
@@ -35,6 +35,7 @@ struct sx_board {
35 void __iomem *base; 35 void __iomem *base;
36 void __iomem *base2; 36 void __iomem *base2;
37 unsigned long hw_base; 37 unsigned long hw_base;
38 resource_size_t hw_len;
38 int eisa_base; 39 int eisa_base;
39 int port_base; /* Number of the first port */ 40 int port_base; /* Number of the first port */
40 struct sx_port *ports; 41 struct sx_port *ports;
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index 78b1b1a2732b..acc6fab601cc 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -63,7 +63,6 @@
63#define MAX_PCI_DEVICES 10 63#define MAX_PCI_DEVICES 10
64#define MAX_TOTAL_DEVICES 20 64#define MAX_TOTAL_DEVICES 20
65 65
66#include <linux/config.h>
67#include <linux/module.h> 66#include <linux/module.h>
68#include <linux/errno.h> 67#include <linux/errno.h>
69#include <linux/signal.h> 68#include <linux/signal.h>
@@ -87,7 +86,6 @@
87 86
88#include <linux/vmalloc.h> 87#include <linux/vmalloc.h>
89#include <linux/init.h> 88#include <linux/init.h>
90#include <asm/serial.h>
91 89
92#include <linux/delay.h> 90#include <linux/delay.h>
93#include <linux/ioctl.h> 91#include <linux/ioctl.h>
@@ -103,8 +101,10 @@
103#include <linux/hdlc.h> 101#include <linux/hdlc.h>
104#include <linux/dma-mapping.h> 102#include <linux/dma-mapping.h>
105 103
106#ifdef CONFIG_HDLC_MODULE 104#if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINK_MODULE))
107#define CONFIG_HDLC 1 105#define SYNCLINK_GENERIC_HDLC 1
106#else
107#define SYNCLINK_GENERIC_HDLC 0
108#endif 108#endif
109 109
110#define GET_USER(error,value,addr) error = get_user(value,addr) 110#define GET_USER(error,value,addr) error = get_user(value,addr)
@@ -135,8 +135,8 @@ static MGSL_PARAMS default_params = {
135}; 135};
136 136
137#define SHARED_MEM_ADDRESS_SIZE 0x40000 137#define SHARED_MEM_ADDRESS_SIZE 0x40000
138#define BUFFERLISTSIZE (PAGE_SIZE) 138#define BUFFERLISTSIZE 4096
139#define DMABUFFERSIZE (PAGE_SIZE) 139#define DMABUFFERSIZE 4096
140#define MAXRXFRAMES 7 140#define MAXRXFRAMES 7
141 141
142typedef struct _DMABUFFERENTRY 142typedef struct _DMABUFFERENTRY
@@ -322,7 +322,7 @@ struct mgsl_struct {
322 int dosyncppp; 322 int dosyncppp;
323 spinlock_t netlock; 323 spinlock_t netlock;
324 324
325#ifdef CONFIG_HDLC 325#if SYNCLINK_GENERIC_HDLC
326 struct net_device *netdev; 326 struct net_device *netdev;
327#endif 327#endif
328}; 328};
@@ -730,7 +730,7 @@ static void usc_loopmode_send_done( struct mgsl_struct * info );
730 730
731static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigned long arg); 731static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigned long arg);
732 732
733#ifdef CONFIG_HDLC 733#if SYNCLINK_GENERIC_HDLC
734#define dev_to_port(D) (dev_to_hdlc(D)->priv) 734#define dev_to_port(D) (dev_to_hdlc(D)->priv)
735static void hdlcdev_tx_done(struct mgsl_struct *info); 735static void hdlcdev_tx_done(struct mgsl_struct *info);
736static void hdlcdev_rx(struct mgsl_struct *info, char *buf, int size); 736static void hdlcdev_rx(struct mgsl_struct *info, char *buf, int size);
@@ -804,7 +804,7 @@ static int save_tx_buffer_request(struct mgsl_struct *info,const char *Buffer, u
804/* 804/*
805 * Bottom half interrupt handlers 805 * Bottom half interrupt handlers
806 */ 806 */
807static void mgsl_bh_handler(void* Context); 807static void mgsl_bh_handler(struct work_struct *work);
808static void mgsl_bh_receive(struct mgsl_struct *info); 808static void mgsl_bh_receive(struct mgsl_struct *info);
809static void mgsl_bh_transmit(struct mgsl_struct *info); 809static void mgsl_bh_transmit(struct mgsl_struct *info);
810static void mgsl_bh_status(struct mgsl_struct *info); 810static void mgsl_bh_status(struct mgsl_struct *info);
@@ -1073,9 +1073,10 @@ static int mgsl_bh_action(struct mgsl_struct *info)
1073/* 1073/*
1074 * Perform bottom half processing of work items queued by ISR. 1074 * Perform bottom half processing of work items queued by ISR.
1075 */ 1075 */
1076static void mgsl_bh_handler(void* Context) 1076static void mgsl_bh_handler(struct work_struct *work)
1077{ 1077{
1078 struct mgsl_struct *info = (struct mgsl_struct*)Context; 1078 struct mgsl_struct *info =
1079 container_of(work, struct mgsl_struct, task);
1079 int action; 1080 int action;
1080 1081
1081 if (!info) 1082 if (!info)
@@ -1278,7 +1279,7 @@ static void mgsl_isr_transmit_status( struct mgsl_struct *info )
1278 info->drop_rts_on_tx_done = 0; 1279 info->drop_rts_on_tx_done = 0;
1279 } 1280 }
1280 1281
1281#ifdef CONFIG_HDLC 1282#if SYNCLINK_GENERIC_HDLC
1282 if (info->netcount) 1283 if (info->netcount)
1283 hdlcdev_tx_done(info); 1284 hdlcdev_tx_done(info);
1284 else 1285 else
@@ -1343,7 +1344,7 @@ static void mgsl_isr_io_pin( struct mgsl_struct *info )
1343 info->input_signal_events.dcd_up++; 1344 info->input_signal_events.dcd_up++;
1344 } else 1345 } else
1345 info->input_signal_events.dcd_down++; 1346 info->input_signal_events.dcd_down++;
1346#ifdef CONFIG_HDLC 1347#if SYNCLINK_GENERIC_HDLC
1347 if (info->netcount) { 1348 if (info->netcount) {
1348 if (status & MISCSTATUS_DCD) 1349 if (status & MISCSTATUS_DCD)
1349 netif_carrier_on(info->netdev); 1350 netif_carrier_on(info->netdev);
@@ -1700,11 +1701,10 @@ static void mgsl_isr_transmit_dma( struct mgsl_struct *info )
1700 * 1701 *
1701 * irq interrupt number that caused interrupt 1702 * irq interrupt number that caused interrupt
1702 * dev_id device ID supplied during interrupt registration 1703 * dev_id device ID supplied during interrupt registration
1703 * regs interrupted processor context
1704 * 1704 *
1705 * Return Value: None 1705 * Return Value: None
1706 */ 1706 */
1707static irqreturn_t mgsl_interrupt(int irq, void *dev_id, struct pt_regs * regs) 1707static irqreturn_t mgsl_interrupt(int irq, void *dev_id)
1708{ 1708{
1709 struct mgsl_struct * info; 1709 struct mgsl_struct * info;
1710 u16 UscVector; 1710 u16 UscVector;
@@ -3060,7 +3060,7 @@ static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigne
3060 * 3060 *
3061 * Return Value: None 3061 * Return Value: None
3062 */ 3062 */
3063static void mgsl_set_termios(struct tty_struct *tty, struct termios *old_termios) 3063static void mgsl_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
3064{ 3064{
3065 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; 3065 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
3066 unsigned long flags; 3066 unsigned long flags;
@@ -4315,7 +4315,7 @@ static void mgsl_add_device( struct mgsl_struct *info )
4315 info->max_frame_size ); 4315 info->max_frame_size );
4316 } 4316 }
4317 4317
4318#ifdef CONFIG_HDLC 4318#if SYNCLINK_GENERIC_HDLC
4319 hdlcdev_init(info); 4319 hdlcdev_init(info);
4320#endif 4320#endif
4321 4321
@@ -4340,7 +4340,7 @@ static struct mgsl_struct* mgsl_allocate_device(void)
4340 } else { 4340 } else {
4341 memset(info, 0, sizeof(struct mgsl_struct)); 4341 memset(info, 0, sizeof(struct mgsl_struct));
4342 info->magic = MGSL_MAGIC; 4342 info->magic = MGSL_MAGIC;
4343 INIT_WORK(&info->task, mgsl_bh_handler, info); 4343 INIT_WORK(&info->task, mgsl_bh_handler);
4344 info->max_frame_size = 4096; 4344 info->max_frame_size = 4096;
4345 info->close_delay = 5*HZ/10; 4345 info->close_delay = 5*HZ/10;
4346 info->closing_wait = 30*HZ; 4346 info->closing_wait = 30*HZ;
@@ -4360,7 +4360,7 @@ static struct mgsl_struct* mgsl_allocate_device(void)
4360 4360
4361} /* end of mgsl_allocate_device()*/ 4361} /* end of mgsl_allocate_device()*/
4362 4362
4363static struct tty_operations mgsl_ops = { 4363static const struct tty_operations mgsl_ops = {
4364 .open = mgsl_open, 4364 .open = mgsl_open,
4365 .close = mgsl_close, 4365 .close = mgsl_close,
4366 .write = mgsl_write, 4366 .write = mgsl_write,
@@ -4405,6 +4405,8 @@ static int mgsl_init_tty(void)
4405 serial_driver->init_termios = tty_std_termios; 4405 serial_driver->init_termios = tty_std_termios;
4406 serial_driver->init_termios.c_cflag = 4406 serial_driver->init_termios.c_cflag =
4407 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 4407 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
4408 serial_driver->init_termios.c_ispeed = 9600;
4409 serial_driver->init_termios.c_ospeed = 9600;
4408 serial_driver->flags = TTY_DRIVER_REAL_RAW; 4410 serial_driver->flags = TTY_DRIVER_REAL_RAW;
4409 tty_set_operations(serial_driver, &mgsl_ops); 4411 tty_set_operations(serial_driver, &mgsl_ops);
4410 if ((rc = tty_register_driver(serial_driver)) < 0) { 4412 if ((rc = tty_register_driver(serial_driver)) < 0) {
@@ -4473,7 +4475,7 @@ static void synclink_cleanup(void)
4473 4475
4474 info = mgsl_device_list; 4476 info = mgsl_device_list;
4475 while(info) { 4477 while(info) {
4476#ifdef CONFIG_HDLC 4478#if SYNCLINK_GENERIC_HDLC
4477 hdlcdev_exit(info); 4479 hdlcdev_exit(info);
4478#endif 4480#endif
4479 mgsl_release_resources(info); 4481 mgsl_release_resources(info);
@@ -6647,7 +6649,7 @@ static int mgsl_get_rx_frame(struct mgsl_struct *info)
6647 return_frame = 1; 6649 return_frame = 1;
6648 } 6650 }
6649 framesize = 0; 6651 framesize = 0;
6650#ifdef CONFIG_HDLC 6652#if SYNCLINK_GENERIC_HDLC
6651 { 6653 {
6652 struct net_device_stats *stats = hdlc_stats(info->netdev); 6654 struct net_device_stats *stats = hdlc_stats(info->netdev);
6653 stats->rx_errors++; 6655 stats->rx_errors++;
@@ -6723,7 +6725,7 @@ static int mgsl_get_rx_frame(struct mgsl_struct *info)
6723 *ptmp); 6725 *ptmp);
6724 } 6726 }
6725 6727
6726#ifdef CONFIG_HDLC 6728#if SYNCLINK_GENERIC_HDLC
6727 if (info->netcount) 6729 if (info->netcount)
6728 hdlcdev_rx(info,info->intermediate_rxbuffer,framesize); 6730 hdlcdev_rx(info,info->intermediate_rxbuffer,framesize);
6729 else 6731 else
@@ -7627,7 +7629,7 @@ static void mgsl_tx_timeout(unsigned long context)
7627 7629
7628 spin_unlock_irqrestore(&info->irq_spinlock,flags); 7630 spin_unlock_irqrestore(&info->irq_spinlock,flags);
7629 7631
7630#ifdef CONFIG_HDLC 7632#if SYNCLINK_GENERIC_HDLC
7631 if (info->netcount) 7633 if (info->netcount)
7632 hdlcdev_tx_done(info); 7634 hdlcdev_tx_done(info);
7633 else 7635 else
@@ -7703,7 +7705,7 @@ static int usc_loopmode_active( struct mgsl_struct * info)
7703 return usc_InReg( info, CCSR ) & BIT7 ? 1 : 0 ; 7705 return usc_InReg( info, CCSR ) & BIT7 ? 1 : 0 ;
7704} 7706}
7705 7707
7706#ifdef CONFIG_HDLC 7708#if SYNCLINK_GENERIC_HDLC
7707 7709
7708/** 7710/**
7709 * called by generic HDLC layer when protocol selected (PPP, frame relay, etc.) 7711 * called by generic HDLC layer when protocol selected (PPP, frame relay, etc.)
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index 2f07b085536b..792c79c315e0 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: synclink_gt.c,v 4.25 2006/02/06 21:20:33 paulkf Exp $ 2 * $Id: synclink_gt.c,v 4.36 2006/08/28 20:47:14 paulkf Exp $
3 * 3 *
4 * Device driver for Microgate SyncLink GT serial adapters. 4 * Device driver for Microgate SyncLink GT serial adapters.
5 * 5 *
@@ -83,20 +83,22 @@
83 83
84#include "linux/synclink.h" 84#include "linux/synclink.h"
85 85
86#ifdef CONFIG_HDLC_MODULE 86#if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINK_GT_MODULE))
87#define CONFIG_HDLC 1 87#define SYNCLINK_GENERIC_HDLC 1
88#else
89#define SYNCLINK_GENERIC_HDLC 0
88#endif 90#endif
89 91
90/* 92/*
91 * module identification 93 * module identification
92 */ 94 */
93static char *driver_name = "SyncLink GT"; 95static char *driver_name = "SyncLink GT";
94static char *driver_version = "$Revision: 4.25 $"; 96static char *driver_version = "$Revision: 4.36 $";
95static char *tty_driver_name = "synclink_gt"; 97static char *tty_driver_name = "synclink_gt";
96static char *tty_dev_prefix = "ttySLG"; 98static char *tty_dev_prefix = "ttySLG";
97MODULE_LICENSE("GPL"); 99MODULE_LICENSE("GPL");
98#define MGSL_MAGIC 0x5401 100#define MGSL_MAGIC 0x5401
99#define MAX_DEVICES 12 101#define MAX_DEVICES 32
100 102
101static struct pci_device_id pci_table[] = { 103static struct pci_device_id pci_table[] = {
102 {PCI_VENDOR_ID_MICROGATE, SYNCLINK_GT_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,}, 104 {PCI_VENDOR_ID_MICROGATE, SYNCLINK_GT_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
@@ -149,7 +151,7 @@ static struct tty_driver *serial_driver;
149static int open(struct tty_struct *tty, struct file * filp); 151static int open(struct tty_struct *tty, struct file * filp);
150static void close(struct tty_struct *tty, struct file * filp); 152static void close(struct tty_struct *tty, struct file * filp);
151static void hangup(struct tty_struct *tty); 153static void hangup(struct tty_struct *tty);
152static void set_termios(struct tty_struct *tty, struct termios *old_termios); 154static void set_termios(struct tty_struct *tty, struct ktermios *old_termios);
153 155
154static int write(struct tty_struct *tty, const unsigned char *buf, int count); 156static int write(struct tty_struct *tty, const unsigned char *buf, int count);
155static void put_char(struct tty_struct *tty, unsigned char ch); 157static void put_char(struct tty_struct *tty, unsigned char ch);
@@ -171,7 +173,7 @@ static void set_break(struct tty_struct *tty, int break_state);
171/* 173/*
172 * generic HDLC support and callbacks 174 * generic HDLC support and callbacks
173 */ 175 */
174#ifdef CONFIG_HDLC 176#if SYNCLINK_GENERIC_HDLC
175#define dev_to_port(D) (dev_to_hdlc(D)->priv) 177#define dev_to_port(D) (dev_to_hdlc(D)->priv)
176static void hdlcdev_tx_done(struct slgt_info *info); 178static void hdlcdev_tx_done(struct slgt_info *info);
177static void hdlcdev_rx(struct slgt_info *info, char *buf, int size); 179static void hdlcdev_rx(struct slgt_info *info, char *buf, int size);
@@ -359,7 +361,7 @@ struct slgt_info {
359 int netcount; 361 int netcount;
360 int dosyncppp; 362 int dosyncppp;
361 spinlock_t netlock; 363 spinlock_t netlock;
362#ifdef CONFIG_HDLC 364#if SYNCLINK_GENERIC_HDLC
363 struct net_device *netdev; 365 struct net_device *netdev;
364#endif 366#endif
365 367
@@ -461,7 +463,7 @@ static int adapter_test(struct slgt_info *info);
461static void reset_adapter(struct slgt_info *info); 463static void reset_adapter(struct slgt_info *info);
462static void reset_port(struct slgt_info *info); 464static void reset_port(struct slgt_info *info);
463static void async_mode(struct slgt_info *info); 465static void async_mode(struct slgt_info *info);
464static void hdlc_mode(struct slgt_info *info); 466static void sync_mode(struct slgt_info *info);
465 467
466static void rx_stop(struct slgt_info *info); 468static void rx_stop(struct slgt_info *info);
467static void rx_start(struct slgt_info *info); 469static void rx_start(struct slgt_info *info);
@@ -485,13 +487,13 @@ static void enable_loopback(struct slgt_info *info);
485static void set_rate(struct slgt_info *info, u32 data_rate); 487static void set_rate(struct slgt_info *info, u32 data_rate);
486 488
487static int bh_action(struct slgt_info *info); 489static int bh_action(struct slgt_info *info);
488static void bh_handler(void* context); 490static void bh_handler(struct work_struct *work);
489static void bh_transmit(struct slgt_info *info); 491static void bh_transmit(struct slgt_info *info);
490static void isr_serial(struct slgt_info *info); 492static void isr_serial(struct slgt_info *info);
491static void isr_rdma(struct slgt_info *info); 493static void isr_rdma(struct slgt_info *info);
492static void isr_txeom(struct slgt_info *info, unsigned short status); 494static void isr_txeom(struct slgt_info *info, unsigned short status);
493static void isr_tdma(struct slgt_info *info); 495static void isr_tdma(struct slgt_info *info);
494static irqreturn_t slgt_interrupt(int irq, void *dev_id, struct pt_regs * regs); 496static irqreturn_t slgt_interrupt(int irq, void *dev_id);
495 497
496static int alloc_dma_bufs(struct slgt_info *info); 498static int alloc_dma_bufs(struct slgt_info *info);
497static void free_dma_bufs(struct slgt_info *info); 499static void free_dma_bufs(struct slgt_info *info);
@@ -814,7 +816,7 @@ static void hangup(struct tty_struct *tty)
814 wake_up_interruptible(&info->open_wait); 816 wake_up_interruptible(&info->open_wait);
815} 817}
816 818
817static void set_termios(struct tty_struct *tty, struct termios *old_termios) 819static void set_termios(struct tty_struct *tty, struct ktermios *old_termios)
818{ 820{
819 struct slgt_info *info = tty->driver_data; 821 struct slgt_info *info = tty->driver_data;
820 unsigned long flags; 822 unsigned long flags;
@@ -881,7 +883,9 @@ static int write(struct tty_struct *tty,
881 if (!count) 883 if (!count)
882 goto cleanup; 884 goto cleanup;
883 885
884 if (info->params.mode == MGSL_MODE_RAW) { 886 if (info->params.mode == MGSL_MODE_RAW ||
887 info->params.mode == MGSL_MODE_MONOSYNC ||
888 info->params.mode == MGSL_MODE_BISYNC) {
885 unsigned int bufs_needed = (count/DMABUFSIZE); 889 unsigned int bufs_needed = (count/DMABUFSIZE);
886 unsigned int bufs_free = free_tbuf_count(info); 890 unsigned int bufs_free = free_tbuf_count(info);
887 if (count % DMABUFSIZE) 891 if (count % DMABUFSIZE)
@@ -1352,7 +1356,7 @@ static void set_break(struct tty_struct *tty, int break_state)
1352 spin_unlock_irqrestore(&info->lock,flags); 1356 spin_unlock_irqrestore(&info->lock,flags);
1353} 1357}
1354 1358
1355#ifdef CONFIG_HDLC 1359#if SYNCLINK_GENERIC_HDLC
1356 1360
1357/** 1361/**
1358 * called by generic HDLC layer when protocol selected (PPP, frame relay, etc.) 1362 * called by generic HDLC layer when protocol selected (PPP, frame relay, etc.)
@@ -1876,9 +1880,9 @@ static int bh_action(struct slgt_info *info)
1876/* 1880/*
1877 * perform bottom half processing 1881 * perform bottom half processing
1878 */ 1882 */
1879static void bh_handler(void* context) 1883static void bh_handler(struct work_struct *work)
1880{ 1884{
1881 struct slgt_info *info = context; 1885 struct slgt_info *info = container_of(work, struct slgt_info, task);
1882 int action; 1886 int action;
1883 1887
1884 if (!info) 1888 if (!info)
@@ -1897,6 +1901,8 @@ static void bh_handler(void* context)
1897 while(rx_get_frame(info)); 1901 while(rx_get_frame(info));
1898 break; 1902 break;
1899 case MGSL_MODE_RAW: 1903 case MGSL_MODE_RAW:
1904 case MGSL_MODE_MONOSYNC:
1905 case MGSL_MODE_BISYNC:
1900 while(rx_get_buf(info)); 1906 while(rx_get_buf(info));
1901 break; 1907 break;
1902 } 1908 }
@@ -1998,7 +2004,7 @@ static void dcd_change(struct slgt_info *info)
1998 } else { 2004 } else {
1999 info->input_signal_events.dcd_down++; 2005 info->input_signal_events.dcd_down++;
2000 } 2006 }
2001#ifdef CONFIG_HDLC 2007#if SYNCLINK_GENERIC_HDLC
2002 if (info->netcount) { 2008 if (info->netcount) {
2003 if (info->signals & SerialSignal_DCD) 2009 if (info->signals & SerialSignal_DCD)
2004 netif_carrier_on(info->netdev); 2010 netif_carrier_on(info->netdev);
@@ -2176,7 +2182,7 @@ static void isr_txeom(struct slgt_info *info, unsigned short status)
2176 set_signals(info); 2182 set_signals(info);
2177 } 2183 }
2178 2184
2179#ifdef CONFIG_HDLC 2185#if SYNCLINK_GENERIC_HDLC
2180 if (info->netcount) 2186 if (info->netcount)
2181 hdlcdev_tx_done(info); 2187 hdlcdev_tx_done(info);
2182 else 2188 else
@@ -2213,9 +2219,8 @@ static void isr_gpio(struct slgt_info *info, unsigned int changed, unsigned int
2213 * 2219 *
2214 * irq interrupt number 2220 * irq interrupt number
2215 * dev_id device ID supplied during interrupt registration 2221 * dev_id device ID supplied during interrupt registration
2216 * regs interrupted processor context
2217 */ 2222 */
2218static irqreturn_t slgt_interrupt(int irq, void *dev_id, struct pt_regs * regs) 2223static irqreturn_t slgt_interrupt(int irq, void *dev_id)
2219{ 2224{
2220 struct slgt_info *info; 2225 struct slgt_info *info;
2221 unsigned int gsr; 2226 unsigned int gsr;
@@ -2362,10 +2367,9 @@ static void program_hw(struct slgt_info *info)
2362 rx_stop(info); 2367 rx_stop(info);
2363 tx_stop(info); 2368 tx_stop(info);
2364 2369
2365 if (info->params.mode == MGSL_MODE_HDLC || 2370 if (info->params.mode != MGSL_MODE_ASYNC ||
2366 info->params.mode == MGSL_MODE_RAW ||
2367 info->netcount) 2371 info->netcount)
2368 hdlc_mode(info); 2372 sync_mode(info);
2369 else 2373 else
2370 async_mode(info); 2374 async_mode(info);
2371 2375
@@ -2564,6 +2568,10 @@ static int rx_enable(struct slgt_info *info, int enable)
2564 if (enable) { 2568 if (enable) {
2565 if (!info->rx_enabled) 2569 if (!info->rx_enabled)
2566 rx_start(info); 2570 rx_start(info);
2571 else if (enable == 2) {
2572 /* force hunt mode (write 1 to RCR[3]) */
2573 wr_reg16(info, RCR, rd_reg16(info, RCR) | BIT3);
2574 }
2567 } else { 2575 } else {
2568 if (info->rx_enabled) 2576 if (info->rx_enabled)
2569 rx_stop(info); 2577 rx_stop(info);
@@ -3300,7 +3308,7 @@ static void add_device(struct slgt_info *info)
3300 devstr, info->device_name, info->phys_reg_addr, 3308 devstr, info->device_name, info->phys_reg_addr,
3301 info->irq_level, info->max_frame_size); 3309 info->irq_level, info->max_frame_size);
3302 3310
3303#ifdef CONFIG_HDLC 3311#if SYNCLINK_GENERIC_HDLC
3304 hdlcdev_init(info); 3312 hdlcdev_init(info);
3305#endif 3313#endif
3306} 3314}
@@ -3320,7 +3328,7 @@ static struct slgt_info *alloc_dev(int adapter_num, int port_num, struct pci_dev
3320 } else { 3328 } else {
3321 memset(info, 0, sizeof(struct slgt_info)); 3329 memset(info, 0, sizeof(struct slgt_info));
3322 info->magic = MGSL_MAGIC; 3330 info->magic = MGSL_MAGIC;
3323 INIT_WORK(&info->task, bh_handler, info); 3331 INIT_WORK(&info->task, bh_handler);
3324 info->max_frame_size = 4096; 3332 info->max_frame_size = 4096;
3325 info->raw_rx_size = DMABUFSIZE; 3333 info->raw_rx_size = DMABUFSIZE;
3326 info->close_delay = 5*HZ/10; 3334 info->close_delay = 5*HZ/10;
@@ -3434,7 +3442,7 @@ static void __devexit remove_one(struct pci_dev *dev)
3434{ 3442{
3435} 3443}
3436 3444
3437static struct tty_operations ops = { 3445static const struct tty_operations ops = {
3438 .open = open, 3446 .open = open,
3439 .close = close, 3447 .close = close,
3440 .write = write, 3448 .write = write,
@@ -3482,7 +3490,7 @@ static void slgt_cleanup(void)
3482 /* release devices */ 3490 /* release devices */
3483 info = slgt_device_list; 3491 info = slgt_device_list;
3484 while(info) { 3492 while(info) {
3485#ifdef CONFIG_HDLC 3493#if SYNCLINK_GENERIC_HDLC
3486 hdlcdev_exit(info); 3494 hdlcdev_exit(info);
3487#endif 3495#endif
3488 free_dma_bufs(info); 3496 free_dma_bufs(info);
@@ -3516,6 +3524,7 @@ static int __init slgt_init(void)
3516 3524
3517 if (!slgt_device_list) { 3525 if (!slgt_device_list) {
3518 printk("%s no devices found\n",driver_name); 3526 printk("%s no devices found\n",driver_name);
3527 pci_unregister_driver(&pci_driver);
3519 return -ENODEV; 3528 return -ENODEV;
3520 } 3529 }
3521 3530
@@ -3537,6 +3546,8 @@ static int __init slgt_init(void)
3537 serial_driver->init_termios = tty_std_termios; 3546 serial_driver->init_termios = tty_std_termios;
3538 serial_driver->init_termios.c_cflag = 3547 serial_driver->init_termios.c_cflag =
3539 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 3548 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
3549 serial_driver->init_termios.c_ispeed = 9600;
3550 serial_driver->init_termios.c_ospeed = 9600;
3540 serial_driver->flags = TTY_DRIVER_REAL_RAW; 3551 serial_driver->flags = TTY_DRIVER_REAL_RAW;
3541 tty_set_operations(serial_driver, &ops); 3552 tty_set_operations(serial_driver, &ops);
3542 if ((rc = tty_register_driver(serial_driver)) < 0) { 3553 if ((rc = tty_register_driver(serial_driver)) < 0) {
@@ -3748,7 +3759,7 @@ static void tx_start(struct slgt_info *info)
3748{ 3759{
3749 if (!info->tx_enabled) { 3760 if (!info->tx_enabled) {
3750 wr_reg16(info, TCR, 3761 wr_reg16(info, TCR,
3751 (unsigned short)(rd_reg16(info, TCR) | BIT1)); 3762 (unsigned short)((rd_reg16(info, TCR) | BIT1) & ~BIT2));
3752 info->tx_enabled = TRUE; 3763 info->tx_enabled = TRUE;
3753 } 3764 }
3754 3765
@@ -3775,13 +3786,18 @@ static void tx_start(struct slgt_info *info)
3775 tdma_reset(info); 3786 tdma_reset(info);
3776 /* set 1st descriptor address */ 3787 /* set 1st descriptor address */
3777 wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc); 3788 wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc);
3778 if (info->params.mode == MGSL_MODE_RAW) 3789 switch(info->params.mode) {
3790 case MGSL_MODE_RAW:
3791 case MGSL_MODE_MONOSYNC:
3792 case MGSL_MODE_BISYNC:
3779 wr_reg32(info, TDCSR, BIT2 + BIT0); /* IRQ + DMA enable */ 3793 wr_reg32(info, TDCSR, BIT2 + BIT0); /* IRQ + DMA enable */
3780 else 3794 break;
3795 default:
3781 wr_reg32(info, TDCSR, BIT0); /* DMA enable */ 3796 wr_reg32(info, TDCSR, BIT0); /* DMA enable */
3797 }
3782 } 3798 }
3783 3799
3784 if (info->params.mode != MGSL_MODE_RAW) { 3800 if (info->params.mode == MGSL_MODE_HDLC) {
3785 info->tx_timer.expires = jiffies + msecs_to_jiffies(5000); 3801 info->tx_timer.expires = jiffies + msecs_to_jiffies(5000);
3786 add_timer(&info->tx_timer); 3802 add_timer(&info->tx_timer);
3787 } 3803 }
@@ -3814,7 +3830,6 @@ static void tx_stop(struct slgt_info *info)
3814 /* reset and disable transmitter */ 3830 /* reset and disable transmitter */
3815 val = rd_reg16(info, TCR) & ~BIT1; /* clear enable bit */ 3831 val = rd_reg16(info, TCR) & ~BIT1; /* clear enable bit */
3816 wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */ 3832 wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */
3817 wr_reg16(info, TCR, val); /* clear reset */
3818 3833
3819 slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER); 3834 slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER);
3820 3835
@@ -3982,7 +3997,7 @@ static void async_mode(struct slgt_info *info)
3982 enable_loopback(info); 3997 enable_loopback(info);
3983} 3998}
3984 3999
3985static void hdlc_mode(struct slgt_info *info) 4000static void sync_mode(struct slgt_info *info)
3986{ 4001{
3987 unsigned short val; 4002 unsigned short val;
3988 4003
@@ -3992,7 +4007,7 @@ static void hdlc_mode(struct slgt_info *info)
3992 4007
3993 /* TCR (tx control) 4008 /* TCR (tx control)
3994 * 4009 *
3995 * 15..13 mode, 000=HDLC 001=raw sync 4010 * 15..13 mode, 000=HDLC 001=raw 010=async 011=monosync 100=bisync
3996 * 12..10 encoding 4011 * 12..10 encoding
3997 * 09 CRC enable 4012 * 09 CRC enable
3998 * 08 CRC32 4013 * 08 CRC32
@@ -4006,8 +4021,11 @@ static void hdlc_mode(struct slgt_info *info)
4006 */ 4021 */
4007 val = 0; 4022 val = 0;
4008 4023
4009 if (info->params.mode == MGSL_MODE_RAW) 4024 switch(info->params.mode) {
4010 val |= BIT13; 4025 case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
4026 case MGSL_MODE_BISYNC: val |= BIT15; break;
4027 case MGSL_MODE_RAW: val |= BIT13; break;
4028 }
4011 if (info->if_mode & MGSL_INTERFACE_RTS_EN) 4029 if (info->if_mode & MGSL_INTERFACE_RTS_EN)
4012 val |= BIT7; 4030 val |= BIT7;
4013 4031
@@ -4058,7 +4076,7 @@ static void hdlc_mode(struct slgt_info *info)
4058 4076
4059 /* RCR (rx control) 4077 /* RCR (rx control)
4060 * 4078 *
4061 * 15..13 mode, 000=HDLC 001=raw sync 4079 * 15..13 mode, 000=HDLC 001=raw 010=async 011=monosync 100=bisync
4062 * 12..10 encoding 4080 * 12..10 encoding
4063 * 09 CRC enable 4081 * 09 CRC enable
4064 * 08 CRC32 4082 * 08 CRC32
@@ -4069,8 +4087,11 @@ static void hdlc_mode(struct slgt_info *info)
4069 */ 4087 */
4070 val = 0; 4088 val = 0;
4071 4089
4072 if (info->params.mode == MGSL_MODE_RAW) 4090 switch(info->params.mode) {
4073 val |= BIT13; 4091 case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
4092 case MGSL_MODE_BISYNC: val |= BIT15; break;
4093 case MGSL_MODE_RAW: val |= BIT13; break;
4094 }
4074 4095
4075 switch(info->params.encoding) 4096 switch(info->params.encoding)
4076 { 4097 {
@@ -4309,10 +4330,15 @@ static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last
4309 while(!done) { 4330 while(!done) {
4310 /* reset current buffer for reuse */ 4331 /* reset current buffer for reuse */
4311 info->rbufs[i].status = 0; 4332 info->rbufs[i].status = 0;
4312 if (info->params.mode == MGSL_MODE_RAW) 4333 switch(info->params.mode) {
4334 case MGSL_MODE_RAW:
4335 case MGSL_MODE_MONOSYNC:
4336 case MGSL_MODE_BISYNC:
4313 set_desc_count(info->rbufs[i], info->raw_rx_size); 4337 set_desc_count(info->rbufs[i], info->raw_rx_size);
4314 else 4338 break;
4339 default:
4315 set_desc_count(info->rbufs[i], DMABUFSIZE); 4340 set_desc_count(info->rbufs[i], DMABUFSIZE);
4341 }
4316 4342
4317 if (i == last) 4343 if (i == last)
4318 done = 1; 4344 done = 1;
@@ -4412,7 +4438,7 @@ check_again:
4412 framesize = 0; 4438 framesize = 0;
4413 } 4439 }
4414 4440
4415#ifdef CONFIG_HDLC 4441#if SYNCLINK_GENERIC_HDLC
4416 if (framesize == 0) { 4442 if (framesize == 0) {
4417 struct net_device_stats *stats = hdlc_stats(info->netdev); 4443 struct net_device_stats *stats = hdlc_stats(info->netdev);
4418 stats->rx_errors++; 4444 stats->rx_errors++;
@@ -4455,7 +4481,7 @@ check_again:
4455 framesize++; 4481 framesize++;
4456 } 4482 }
4457 4483
4458#ifdef CONFIG_HDLC 4484#if SYNCLINK_GENERIC_HDLC
4459 if (info->netcount) 4485 if (info->netcount)
4460 hdlcdev_rx(info,info->tmp_rbuf, framesize); 4486 hdlcdev_rx(info,info->tmp_rbuf, framesize);
4461 else 4487 else
@@ -4477,13 +4503,24 @@ cleanup:
4477static int rx_get_buf(struct slgt_info *info) 4503static int rx_get_buf(struct slgt_info *info)
4478{ 4504{
4479 unsigned int i = info->rbuf_current; 4505 unsigned int i = info->rbuf_current;
4506 unsigned int count;
4480 4507
4481 if (!desc_complete(info->rbufs[i])) 4508 if (!desc_complete(info->rbufs[i]))
4482 return 0; 4509 return 0;
4483 DBGDATA(info, info->rbufs[i].buf, desc_count(info->rbufs[i]), "rx"); 4510 count = desc_count(info->rbufs[i]);
4484 DBGINFO(("rx_get_buf size=%d\n", desc_count(info->rbufs[i]))); 4511 switch(info->params.mode) {
4485 ldisc_receive_buf(info->tty, info->rbufs[i].buf, 4512 case MGSL_MODE_MONOSYNC:
4486 info->flag_buf, desc_count(info->rbufs[i])); 4513 case MGSL_MODE_BISYNC:
4514 /* ignore residue in byte synchronous modes */
4515 if (desc_residue(info->rbufs[i]))
4516 count--;
4517 break;
4518 }
4519 DBGDATA(info, info->rbufs[i].buf, count, "rx");
4520 DBGINFO(("rx_get_buf size=%d\n", count));
4521 if (count)
4522 ldisc_receive_buf(info->tty, info->rbufs[i].buf,
4523 info->flag_buf, count);
4487 free_rbufs(info, i, i); 4524 free_rbufs(info, i, i);
4488 return 1; 4525 return 1;
4489} 4526}
@@ -4549,8 +4586,13 @@ static void tx_load(struct slgt_info *info, const char *buf, unsigned int size)
4549 size -= count; 4586 size -= count;
4550 buf += count; 4587 buf += count;
4551 4588
4552 if (!size && info->params.mode != MGSL_MODE_RAW) 4589 /*
4553 set_desc_eof(*d, 1); /* HDLC: set EOF of last desc */ 4590 * set EOF bit for last buffer of HDLC frame or
4591 * for every buffer in raw mode
4592 */
4593 if ((!size && info->params.mode == MGSL_MODE_HDLC) ||
4594 info->params.mode == MGSL_MODE_RAW)
4595 set_desc_eof(*d, 1);
4554 else 4596 else
4555 set_desc_eof(*d, 0); 4597 set_desc_eof(*d, 0);
4556 4598
@@ -4742,7 +4784,7 @@ static void tx_timeout(unsigned long context)
4742 info->tx_count = 0; 4784 info->tx_count = 0;
4743 spin_unlock_irqrestore(&info->lock,flags); 4785 spin_unlock_irqrestore(&info->lock,flags);
4744 4786
4745#ifdef CONFIG_HDLC 4787#if SYNCLINK_GENERIC_HDLC
4746 if (info->netcount) 4788 if (info->netcount)
4747 hdlcdev_tx_done(info); 4789 hdlcdev_tx_done(info);
4748 else 4790 else
@@ -4762,6 +4804,6 @@ static void rx_timeout(unsigned long context)
4762 spin_lock_irqsave(&info->lock, flags); 4804 spin_lock_irqsave(&info->lock, flags);
4763 info->pending_bh |= BH_RECEIVE; 4805 info->pending_bh |= BH_RECEIVE;
4764 spin_unlock_irqrestore(&info->lock, flags); 4806 spin_unlock_irqrestore(&info->lock, flags);
4765 bh_handler(info); 4807 bh_handler(&info->task);
4766} 4808}
4767 4809
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index 66f3754fbbdf..53e8ccf94fe3 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -67,8 +67,10 @@
67#include <linux/workqueue.h> 67#include <linux/workqueue.h>
68#include <linux/hdlc.h> 68#include <linux/hdlc.h>
69 69
70#ifdef CONFIG_HDLC_MODULE 70#if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINKMP_MODULE))
71#define CONFIG_HDLC 1 71#define SYNCLINK_GENERIC_HDLC 1
72#else
73#define SYNCLINK_GENERIC_HDLC 0
72#endif 74#endif
73 75
74#define GET_USER(error,value,addr) error = get_user(value,addr) 76#define GET_USER(error,value,addr) error = get_user(value,addr)
@@ -280,7 +282,7 @@ typedef struct _synclinkmp_info {
280 int dosyncppp; 282 int dosyncppp;
281 spinlock_t netlock; 283 spinlock_t netlock;
282 284
283#ifdef CONFIG_HDLC 285#if SYNCLINK_GENERIC_HDLC
284 struct net_device *netdev; 286 struct net_device *netdev;
285#endif 287#endif
286 288
@@ -517,7 +519,7 @@ static struct tty_driver *serial_driver;
517static int open(struct tty_struct *tty, struct file * filp); 519static int open(struct tty_struct *tty, struct file * filp);
518static void close(struct tty_struct *tty, struct file * filp); 520static void close(struct tty_struct *tty, struct file * filp);
519static void hangup(struct tty_struct *tty); 521static void hangup(struct tty_struct *tty);
520static void set_termios(struct tty_struct *tty, struct termios *old_termios); 522static void set_termios(struct tty_struct *tty, struct ktermios *old_termios);
521 523
522static int write(struct tty_struct *tty, const unsigned char *buf, int count); 524static int write(struct tty_struct *tty, const unsigned char *buf, int count);
523static void put_char(struct tty_struct *tty, unsigned char ch); 525static void put_char(struct tty_struct *tty, unsigned char ch);
@@ -536,7 +538,7 @@ static void throttle(struct tty_struct * tty);
536static void unthrottle(struct tty_struct * tty); 538static void unthrottle(struct tty_struct * tty);
537static void set_break(struct tty_struct *tty, int break_state); 539static void set_break(struct tty_struct *tty, int break_state);
538 540
539#ifdef CONFIG_HDLC 541#if SYNCLINK_GENERIC_HDLC
540#define dev_to_port(D) (dev_to_hdlc(D)->priv) 542#define dev_to_port(D) (dev_to_hdlc(D)->priv)
541static void hdlcdev_tx_done(SLMP_INFO *info); 543static void hdlcdev_tx_done(SLMP_INFO *info);
542static void hdlcdev_rx(SLMP_INFO *info, char *buf, int size); 544static void hdlcdev_rx(SLMP_INFO *info, char *buf, int size);
@@ -602,7 +604,7 @@ static void enable_loopback(SLMP_INFO *info, int enable);
602static void set_rate(SLMP_INFO *info, u32 data_rate); 604static void set_rate(SLMP_INFO *info, u32 data_rate);
603 605
604static int bh_action(SLMP_INFO *info); 606static int bh_action(SLMP_INFO *info);
605static void bh_handler(void* Context); 607static void bh_handler(struct work_struct *work);
606static void bh_receive(SLMP_INFO *info); 608static void bh_receive(SLMP_INFO *info);
607static void bh_transmit(SLMP_INFO *info); 609static void bh_transmit(SLMP_INFO *info);
608static void bh_status(SLMP_INFO *info); 610static void bh_status(SLMP_INFO *info);
@@ -916,7 +918,7 @@ static void hangup(struct tty_struct *tty)
916 918
917/* Set new termios settings 919/* Set new termios settings
918 */ 920 */
919static void set_termios(struct tty_struct *tty, struct termios *old_termios) 921static void set_termios(struct tty_struct *tty, struct ktermios *old_termios)
920{ 922{
921 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 923 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
922 unsigned long flags; 924 unsigned long flags;
@@ -1607,7 +1609,7 @@ static void set_break(struct tty_struct *tty, int break_state)
1607 spin_unlock_irqrestore(&info->lock,flags); 1609 spin_unlock_irqrestore(&info->lock,flags);
1608} 1610}
1609 1611
1610#ifdef CONFIG_HDLC 1612#if SYNCLINK_GENERIC_HDLC
1611 1613
1612/** 1614/**
1613 * called by generic HDLC layer when protocol selected (PPP, frame relay, etc.) 1615 * called by generic HDLC layer when protocol selected (PPP, frame relay, etc.)
@@ -2063,9 +2065,9 @@ int bh_action(SLMP_INFO *info)
2063 2065
2064/* Perform bottom half processing of work items queued by ISR. 2066/* Perform bottom half processing of work items queued by ISR.
2065 */ 2067 */
2066void bh_handler(void* Context) 2068void bh_handler(struct work_struct *work)
2067{ 2069{
2068 SLMP_INFO *info = (SLMP_INFO*)Context; 2070 SLMP_INFO *info = container_of(work, SLMP_INFO, task);
2069 int action; 2071 int action;
2070 2072
2071 if (!info) 2073 if (!info)
@@ -2339,7 +2341,7 @@ static void isr_txeom(SLMP_INFO * info, unsigned char status)
2339 set_signals(info); 2341 set_signals(info);
2340 } 2342 }
2341 2343
2342#ifdef CONFIG_HDLC 2344#if SYNCLINK_GENERIC_HDLC
2343 if (info->netcount) 2345 if (info->netcount)
2344 hdlcdev_tx_done(info); 2346 hdlcdev_tx_done(info);
2345 else 2347 else
@@ -2523,7 +2525,7 @@ void isr_io_pin( SLMP_INFO *info, u16 status )
2523 info->input_signal_events.dcd_up++; 2525 info->input_signal_events.dcd_up++;
2524 } else 2526 } else
2525 info->input_signal_events.dcd_down++; 2527 info->input_signal_events.dcd_down++;
2526#ifdef CONFIG_HDLC 2528#if SYNCLINK_GENERIC_HDLC
2527 if (info->netcount) { 2529 if (info->netcount) {
2528 if (status & SerialSignal_DCD) 2530 if (status & SerialSignal_DCD)
2529 netif_carrier_on(info->netdev); 2531 netif_carrier_on(info->netdev);
@@ -2596,8 +2598,7 @@ void isr_io_pin( SLMP_INFO *info, u16 status )
2596 * dev_id device ID supplied during interrupt registration 2598 * dev_id device ID supplied during interrupt registration
2597 * regs interrupted processor context 2599 * regs interrupted processor context
2598 */ 2600 */
2599static irqreturn_t synclinkmp_interrupt(int irq, void *dev_id, 2601static irqreturn_t synclinkmp_interrupt(int irq, void *dev_id)
2600 struct pt_regs *regs)
2601{ 2602{
2602 SLMP_INFO * info; 2603 SLMP_INFO * info;
2603 unsigned char status, status0, status1=0; 2604 unsigned char status, status0, status1=0;
@@ -3784,7 +3785,7 @@ void add_device(SLMP_INFO *info)
3784 info->irq_level, 3785 info->irq_level,
3785 info->max_frame_size ); 3786 info->max_frame_size );
3786 3787
3787#ifdef CONFIG_HDLC 3788#if SYNCLINK_GENERIC_HDLC
3788 hdlcdev_init(info); 3789 hdlcdev_init(info);
3789#endif 3790#endif
3790} 3791}
@@ -3806,7 +3807,7 @@ static SLMP_INFO *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev)
3806 } else { 3807 } else {
3807 memset(info, 0, sizeof(SLMP_INFO)); 3808 memset(info, 0, sizeof(SLMP_INFO));
3808 info->magic = MGSL_MAGIC; 3809 info->magic = MGSL_MAGIC;
3809 INIT_WORK(&info->task, bh_handler, info); 3810 INIT_WORK(&info->task, bh_handler);
3810 info->max_frame_size = 4096; 3811 info->max_frame_size = 4096;
3811 info->close_delay = 5*HZ/10; 3812 info->close_delay = 5*HZ/10;
3812 info->closing_wait = 30*HZ; 3813 info->closing_wait = 30*HZ;
@@ -3929,7 +3930,7 @@ void device_init(int adapter_num, struct pci_dev *pdev)
3929 } 3930 }
3930} 3931}
3931 3932
3932static struct tty_operations ops = { 3933static const struct tty_operations ops = {
3933 .open = open, 3934 .open = open,
3934 .close = close, 3935 .close = close,
3935 .write = write, 3936 .write = write,
@@ -3978,7 +3979,7 @@ static void synclinkmp_cleanup(void)
3978 /* release devices */ 3979 /* release devices */
3979 info = synclinkmp_device_list; 3980 info = synclinkmp_device_list;
3980 while(info) { 3981 while(info) {
3981#ifdef CONFIG_HDLC 3982#if SYNCLINK_GENERIC_HDLC
3982 hdlcdev_exit(info); 3983 hdlcdev_exit(info);
3983#endif 3984#endif
3984 free_dma_bufs(info); 3985 free_dma_bufs(info);
@@ -4033,6 +4034,8 @@ static int __init synclinkmp_init(void)
4033 serial_driver->init_termios = tty_std_termios; 4034 serial_driver->init_termios = tty_std_termios;
4034 serial_driver->init_termios.c_cflag = 4035 serial_driver->init_termios.c_cflag =
4035 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 4036 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
4037 serial_driver->init_termios.c_ispeed = 9600;
4038 serial_driver->init_termios.c_ospeed = 9600;
4036 serial_driver->flags = TTY_DRIVER_REAL_RAW; 4039 serial_driver->flags = TTY_DRIVER_REAL_RAW;
4037 tty_set_operations(serial_driver, &ops); 4040 tty_set_operations(serial_driver, &ops);
4038 if ((rc = tty_register_driver(serial_driver)) < 0) { 4041 if ((rc = tty_register_driver(serial_driver)) < 0) {
@@ -4980,7 +4983,7 @@ CheckAgain:
4980 info->icount.rxcrc++; 4983 info->icount.rxcrc++;
4981 4984
4982 framesize = 0; 4985 framesize = 0;
4983#ifdef CONFIG_HDLC 4986#if SYNCLINK_GENERIC_HDLC
4984 { 4987 {
4985 struct net_device_stats *stats = hdlc_stats(info->netdev); 4988 struct net_device_stats *stats = hdlc_stats(info->netdev);
4986 stats->rx_errors++; 4989 stats->rx_errors++;
@@ -5021,7 +5024,7 @@ CheckAgain:
5021 index = 0; 5024 index = 0;
5022 } 5025 }
5023 5026
5024#ifdef CONFIG_HDLC 5027#if SYNCLINK_GENERIC_HDLC
5025 if (info->netcount) 5028 if (info->netcount)
5026 hdlcdev_rx(info,info->tmp_rx_buf,framesize); 5029 hdlcdev_rx(info,info->tmp_rx_buf,framesize);
5027 else 5030 else
@@ -5532,7 +5535,7 @@ void tx_timeout(unsigned long context)
5532 5535
5533 spin_unlock_irqrestore(&info->lock,flags); 5536 spin_unlock_irqrestore(&info->lock,flags);
5534 5537
5535#ifdef CONFIG_HDLC 5538#if SYNCLINK_GENERIC_HDLC
5536 if (info->netcount) 5539 if (info->netcount)
5537 hdlcdev_tx_done(info); 5540 hdlcdev_tx_done(info);
5538 else 5541 else
diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c
index ee3ca8f1768e..05810c8d20bc 100644
--- a/drivers/char/sysrq.c
+++ b/drivers/char/sysrq.c
@@ -35,14 +35,15 @@
35#include <linux/vt_kern.h> 35#include <linux/vt_kern.h>
36#include <linux/workqueue.h> 36#include <linux/workqueue.h>
37#include <linux/kexec.h> 37#include <linux/kexec.h>
38#include <linux/irq.h>
38 39
39#include <asm/ptrace.h> 40#include <asm/ptrace.h>
41#include <asm/irq_regs.h>
40 42
41/* Whether we react on sysrq keys or just ignore them */ 43/* Whether we react on sysrq keys or just ignore them */
42int sysrq_enabled = 1; 44int sysrq_enabled = 1;
43 45
44static void sysrq_handle_loglevel(int key, struct pt_regs *pt_regs, 46static void sysrq_handle_loglevel(int key, struct tty_struct *tty)
45 struct tty_struct *tty)
46{ 47{
47 int i; 48 int i;
48 i = key - '0'; 49 i = key - '0';
@@ -58,8 +59,7 @@ static struct sysrq_key_op sysrq_loglevel_op = {
58}; 59};
59 60
60#ifdef CONFIG_VT 61#ifdef CONFIG_VT
61static void sysrq_handle_SAK(int key, struct pt_regs *pt_regs, 62static void sysrq_handle_SAK(int key, struct tty_struct *tty)
62 struct tty_struct *tty)
63{ 63{
64 if (tty) 64 if (tty)
65 do_SAK(tty); 65 do_SAK(tty);
@@ -76,8 +76,7 @@ static struct sysrq_key_op sysrq_SAK_op = {
76#endif 76#endif
77 77
78#ifdef CONFIG_VT 78#ifdef CONFIG_VT
79static void sysrq_handle_unraw(int key, struct pt_regs *pt_regs, 79static void sysrq_handle_unraw(int key, struct tty_struct *tty)
80 struct tty_struct *tty)
81{ 80{
82 struct kbd_struct *kbd = &kbd_table[fg_console]; 81 struct kbd_struct *kbd = &kbd_table[fg_console];
83 82
@@ -95,10 +94,9 @@ static struct sysrq_key_op sysrq_unraw_op = {
95#endif /* CONFIG_VT */ 94#endif /* CONFIG_VT */
96 95
97#ifdef CONFIG_KEXEC 96#ifdef CONFIG_KEXEC
98static void sysrq_handle_crashdump(int key, struct pt_regs *pt_regs, 97static void sysrq_handle_crashdump(int key, struct tty_struct *tty)
99 struct tty_struct *tty)
100{ 98{
101 crash_kexec(pt_regs); 99 crash_kexec(get_irq_regs());
102} 100}
103static struct sysrq_key_op sysrq_crashdump_op = { 101static struct sysrq_key_op sysrq_crashdump_op = {
104 .handler = sysrq_handle_crashdump, 102 .handler = sysrq_handle_crashdump,
@@ -110,9 +108,9 @@ static struct sysrq_key_op sysrq_crashdump_op = {
110#define sysrq_crashdump_op (*(struct sysrq_key_op *)0) 108#define sysrq_crashdump_op (*(struct sysrq_key_op *)0)
111#endif 109#endif
112 110
113static void sysrq_handle_reboot(int key, struct pt_regs *pt_regs, 111static void sysrq_handle_reboot(int key, struct tty_struct *tty)
114 struct tty_struct *tty)
115{ 112{
113 lockdep_off();
116 local_irq_enable(); 114 local_irq_enable();
117 emergency_restart(); 115 emergency_restart();
118} 116}
@@ -123,8 +121,7 @@ static struct sysrq_key_op sysrq_reboot_op = {
123 .enable_mask = SYSRQ_ENABLE_BOOT, 121 .enable_mask = SYSRQ_ENABLE_BOOT,
124}; 122};
125 123
126static void sysrq_handle_sync(int key, struct pt_regs *pt_regs, 124static void sysrq_handle_sync(int key, struct tty_struct *tty)
127 struct tty_struct *tty)
128{ 125{
129 emergency_sync(); 126 emergency_sync();
130} 127}
@@ -135,8 +132,7 @@ static struct sysrq_key_op sysrq_sync_op = {
135 .enable_mask = SYSRQ_ENABLE_SYNC, 132 .enable_mask = SYSRQ_ENABLE_SYNC,
136}; 133};
137 134
138static void sysrq_handle_mountro(int key, struct pt_regs *pt_regs, 135static void sysrq_handle_mountro(int key, struct tty_struct *tty)
139 struct tty_struct *tty)
140{ 136{
141 emergency_remount(); 137 emergency_remount();
142} 138}
@@ -148,8 +144,7 @@ static struct sysrq_key_op sysrq_mountro_op = {
148}; 144};
149 145
150#ifdef CONFIG_LOCKDEP 146#ifdef CONFIG_LOCKDEP
151static void sysrq_handle_showlocks(int key, struct pt_regs *pt_regs, 147static void sysrq_handle_showlocks(int key, struct tty_struct *tty)
152 struct tty_struct *tty)
153{ 148{
154 debug_show_all_locks(); 149 debug_show_all_locks();
155} 150}
@@ -163,11 +158,11 @@ static struct sysrq_key_op sysrq_showlocks_op = {
163#define sysrq_showlocks_op (*(struct sysrq_key_op *)0) 158#define sysrq_showlocks_op (*(struct sysrq_key_op *)0)
164#endif 159#endif
165 160
166static void sysrq_handle_showregs(int key, struct pt_regs *pt_regs, 161static void sysrq_handle_showregs(int key, struct tty_struct *tty)
167 struct tty_struct *tty)
168{ 162{
169 if (pt_regs) 163 struct pt_regs *regs = get_irq_regs();
170 show_regs(pt_regs); 164 if (regs)
165 show_regs(regs);
171} 166}
172static struct sysrq_key_op sysrq_showregs_op = { 167static struct sysrq_key_op sysrq_showregs_op = {
173 .handler = sysrq_handle_showregs, 168 .handler = sysrq_handle_showregs,
@@ -176,8 +171,7 @@ static struct sysrq_key_op sysrq_showregs_op = {
176 .enable_mask = SYSRQ_ENABLE_DUMP, 171 .enable_mask = SYSRQ_ENABLE_DUMP,
177}; 172};
178 173
179static void sysrq_handle_showstate(int key, struct pt_regs *pt_regs, 174static void sysrq_handle_showstate(int key, struct tty_struct *tty)
180 struct tty_struct *tty)
181{ 175{
182 show_state(); 176 show_state();
183} 177}
@@ -188,8 +182,19 @@ static struct sysrq_key_op sysrq_showstate_op = {
188 .enable_mask = SYSRQ_ENABLE_DUMP, 182 .enable_mask = SYSRQ_ENABLE_DUMP,
189}; 183};
190 184
191static void sysrq_handle_showmem(int key, struct pt_regs *pt_regs, 185static void sysrq_handle_showstate_blocked(int key, struct tty_struct *tty)
192 struct tty_struct *tty) 186{
187 show_state_filter(TASK_UNINTERRUPTIBLE);
188}
189static struct sysrq_key_op sysrq_showstate_blocked_op = {
190 .handler = sysrq_handle_showstate_blocked,
191 .help_msg = "showBlockedTasks",
192 .action_msg = "Show Blocked State",
193 .enable_mask = SYSRQ_ENABLE_DUMP,
194};
195
196
197static void sysrq_handle_showmem(int key, struct tty_struct *tty)
193{ 198{
194 show_mem(); 199 show_mem();
195} 200}
@@ -208,14 +213,13 @@ static void send_sig_all(int sig)
208 struct task_struct *p; 213 struct task_struct *p;
209 214
210 for_each_process(p) { 215 for_each_process(p) {
211 if (p->mm && p->pid != 1) 216 if (p->mm && !is_init(p))
212 /* Not swapper, init nor kernel thread */ 217 /* Not swapper, init nor kernel thread */
213 force_sig(sig, p); 218 force_sig(sig, p);
214 } 219 }
215} 220}
216 221
217static void sysrq_handle_term(int key, struct pt_regs *pt_regs, 222static void sysrq_handle_term(int key, struct tty_struct *tty)
218 struct tty_struct *tty)
219{ 223{
220 send_sig_all(SIGTERM); 224 send_sig_all(SIGTERM);
221 console_loglevel = 8; 225 console_loglevel = 8;
@@ -227,16 +231,15 @@ static struct sysrq_key_op sysrq_term_op = {
227 .enable_mask = SYSRQ_ENABLE_SIGNAL, 231 .enable_mask = SYSRQ_ENABLE_SIGNAL,
228}; 232};
229 233
230static void moom_callback(void *ignored) 234static void moom_callback(struct work_struct *ignored)
231{ 235{
232 out_of_memory(&NODE_DATA(0)->node_zonelists[ZONE_NORMAL], 236 out_of_memory(&NODE_DATA(0)->node_zonelists[ZONE_NORMAL],
233 GFP_KERNEL, 0); 237 GFP_KERNEL, 0);
234} 238}
235 239
236static DECLARE_WORK(moom_work, moom_callback, NULL); 240static DECLARE_WORK(moom_work, moom_callback);
237 241
238static void sysrq_handle_moom(int key, struct pt_regs *pt_regs, 242static void sysrq_handle_moom(int key, struct tty_struct *tty)
239 struct tty_struct *tty)
240{ 243{
241 schedule_work(&moom_work); 244 schedule_work(&moom_work);
242} 245}
@@ -246,8 +249,7 @@ static struct sysrq_key_op sysrq_moom_op = {
246 .action_msg = "Manual OOM execution", 249 .action_msg = "Manual OOM execution",
247}; 250};
248 251
249static void sysrq_handle_kill(int key, struct pt_regs *pt_regs, 252static void sysrq_handle_kill(int key, struct tty_struct *tty)
250 struct tty_struct *tty)
251{ 253{
252 send_sig_all(SIGKILL); 254 send_sig_all(SIGKILL);
253 console_loglevel = 8; 255 console_loglevel = 8;
@@ -259,8 +261,7 @@ static struct sysrq_key_op sysrq_kill_op = {
259 .enable_mask = SYSRQ_ENABLE_SIGNAL, 261 .enable_mask = SYSRQ_ENABLE_SIGNAL,
260}; 262};
261 263
262static void sysrq_handle_unrt(int key, struct pt_regs *pt_regs, 264static void sysrq_handle_unrt(int key, struct tty_struct *tty)
263 struct tty_struct *tty)
264{ 265{
265 normalize_rt_tasks(); 266 normalize_rt_tasks();
266} 267}
@@ -315,7 +316,7 @@ static struct sysrq_key_op *sysrq_key_table[36] = {
315 /* May be assigned at init time by SMP VOYAGER */ 316 /* May be assigned at init time by SMP VOYAGER */
316 NULL, /* v */ 317 NULL, /* v */
317 NULL, /* w */ 318 NULL, /* w */
318 NULL, /* x */ 319 &sysrq_showstate_blocked_op, /* x */
319 NULL, /* y */ 320 NULL, /* y */
320 NULL /* z */ 321 NULL /* z */
321}; 322};
@@ -360,8 +361,7 @@ static void __sysrq_put_key_op(int key, struct sysrq_key_op *op_p)
360 * This is the non-locking version of handle_sysrq. It must/can only be called 361 * This is the non-locking version of handle_sysrq. It must/can only be called
361 * by sysrq key handlers, as they are inside of the lock 362 * by sysrq key handlers, as they are inside of the lock
362 */ 363 */
363void __handle_sysrq(int key, struct pt_regs *pt_regs, struct tty_struct *tty, 364void __handle_sysrq(int key, struct tty_struct *tty, int check_mask)
364 int check_mask)
365{ 365{
366 struct sysrq_key_op *op_p; 366 struct sysrq_key_op *op_p;
367 int orig_log_level; 367 int orig_log_level;
@@ -383,7 +383,7 @@ void __handle_sysrq(int key, struct pt_regs *pt_regs, struct tty_struct *tty,
383 (sysrq_enabled & op_p->enable_mask)) { 383 (sysrq_enabled & op_p->enable_mask)) {
384 printk("%s\n", op_p->action_msg); 384 printk("%s\n", op_p->action_msg);
385 console_loglevel = orig_log_level; 385 console_loglevel = orig_log_level;
386 op_p->handler(key, pt_regs, tty); 386 op_p->handler(key, tty);
387 } else { 387 } else {
388 printk("This sysrq operation is disabled.\n"); 388 printk("This sysrq operation is disabled.\n");
389 } 389 }
@@ -412,11 +412,11 @@ void __handle_sysrq(int key, struct pt_regs *pt_regs, struct tty_struct *tty,
412 * This function is called by the keyboard handler when SysRq is pressed 412 * This function is called by the keyboard handler when SysRq is pressed
413 * and any other keycode arrives. 413 * and any other keycode arrives.
414 */ 414 */
415void handle_sysrq(int key, struct pt_regs *pt_regs, struct tty_struct *tty) 415void handle_sysrq(int key, struct tty_struct *tty)
416{ 416{
417 if (!sysrq_enabled) 417 if (!sysrq_enabled)
418 return; 418 return;
419 __handle_sysrq(key, pt_regs, tty, 1); 419 __handle_sysrq(key, tty, 1);
420} 420}
421EXPORT_SYMBOL(handle_sysrq); 421EXPORT_SYMBOL(handle_sysrq);
422 422
diff --git a/drivers/char/tb0219.c b/drivers/char/tb0219.c
index bb1bad4c18f9..4c431cb7cf1b 100644
--- a/drivers/char/tb0219.c
+++ b/drivers/char/tb0219.c
@@ -164,7 +164,7 @@ static ssize_t tanbac_tb0219_read(struct file *file, char __user *buf, size_t le
164 unsigned int minor; 164 unsigned int minor;
165 char value; 165 char value;
166 166
167 minor = iminor(file->f_dentry->d_inode); 167 minor = iminor(file->f_path.dentry->d_inode);
168 switch (minor) { 168 switch (minor) {
169 case 0: 169 case 0:
170 value = get_led(); 170 value = get_led();
@@ -200,7 +200,7 @@ static ssize_t tanbac_tb0219_write(struct file *file, const char __user *data,
200 int retval = 0; 200 int retval = 0;
201 char c; 201 char c;
202 202
203 minor = iminor(file->f_dentry->d_inode); 203 minor = iminor(file->f_path.dentry->d_inode);
204 switch (minor) { 204 switch (minor) {
205 case 0: 205 case 0:
206 type = TYPE_LED; 206 type = TYPE_LED;
diff --git a/drivers/char/tipar.c b/drivers/char/tipar.c
index d30dc09dbbc9..47fb20f69695 100644
--- a/drivers/char/tipar.c
+++ b/drivers/char/tipar.c
@@ -224,14 +224,16 @@ probe_ti_parallel(int minor)
224{ 224{
225 int i; 225 int i;
226 int seq[] = { 0x00, 0x20, 0x10, 0x30 }; 226 int seq[] = { 0x00, 0x20, 0x10, 0x30 };
227 int data;
227 228
228 for (i = 3; i >= 0; i--) { 229 for (i = 3; i >= 0; i--) {
229 outbyte(3, minor); 230 outbyte(3, minor);
230 outbyte(i, minor); 231 outbyte(i, minor);
231 udelay(delay); 232 udelay(delay);
233 data = inbyte(minor) & 0x30;
232 pr_debug("tipar: Probing -> %i: 0x%02x 0x%02x\n", i, 234 pr_debug("tipar: Probing -> %i: 0x%02x 0x%02x\n", i,
233 data & 0x30, seq[i]); 235 data, seq[i]);
234 if ((inbyte(minor) & 0x30) != seq[i]) { 236 if (data != seq[i]) {
235 outbyte(3, minor); 237 outbyte(3, minor);
236 return -1; 238 return -1;
237 } 239 }
@@ -283,7 +285,7 @@ static ssize_t
283tipar_write (struct file *file, const char __user *buf, size_t count, 285tipar_write (struct file *file, const char __user *buf, size_t count,
284 loff_t * ppos) 286 loff_t * ppos)
285{ 287{
286 unsigned int minor = iminor(file->f_dentry->d_inode) - TIPAR_MINOR; 288 unsigned int minor = iminor(file->f_path.dentry->d_inode) - TIPAR_MINOR;
287 ssize_t n; 289 ssize_t n;
288 290
289 parport_claim_or_block(table[minor].dev); 291 parport_claim_or_block(table[minor].dev);
@@ -311,7 +313,7 @@ static ssize_t
311tipar_read(struct file *file, char __user *buf, size_t count, loff_t * ppos) 313tipar_read(struct file *file, char __user *buf, size_t count, loff_t * ppos)
312{ 314{
313 int b = 0; 315 int b = 0;
314 unsigned int minor = iminor(file->f_dentry->d_inode) - TIPAR_MINOR; 316 unsigned int minor = iminor(file->f_path.dentry->d_inode) - TIPAR_MINOR;
315 ssize_t retval = 0; 317 ssize_t retval = 0;
316 ssize_t n = 0; 318 ssize_t n = 0;
317 319
diff --git a/drivers/char/tlclk.c b/drivers/char/tlclk.c
index d2c5ba4e83b8..244d30a03fef 100644
--- a/drivers/char/tlclk.c
+++ b/drivers/char/tlclk.c
@@ -193,7 +193,7 @@ static DEFINE_SPINLOCK(event_lock);
193 193
194static int tlclk_major = TLCLK_MAJOR; 194static int tlclk_major = TLCLK_MAJOR;
195 195
196static irqreturn_t tlclk_interrupt(int irq, void *dev_id, struct pt_regs *regs); 196static irqreturn_t tlclk_interrupt(int irq, void *dev_id);
197 197
198static DECLARE_WAIT_QUEUE_HEAD(wq); 198static DECLARE_WAIT_QUEUE_HEAD(wq);
199 199
@@ -792,15 +792,14 @@ static int __init tlclk_init(void)
792 ret = misc_register(&tlclk_miscdev); 792 ret = misc_register(&tlclk_miscdev);
793 if (ret < 0) { 793 if (ret < 0) {
794 printk(KERN_ERR "tlclk: misc_register returns %d.\n", ret); 794 printk(KERN_ERR "tlclk: misc_register returns %d.\n", ret);
795 ret = -EBUSY;
796 goto out3; 795 goto out3;
797 } 796 }
798 797
799 tlclk_device = platform_device_register_simple("telco_clock", 798 tlclk_device = platform_device_register_simple("telco_clock",
800 -1, NULL, 0); 799 -1, NULL, 0);
801 if (!tlclk_device) { 800 if (IS_ERR(tlclk_device)) {
802 printk(KERN_ERR "tlclk: platform_device_register failed.\n"); 801 printk(KERN_ERR "tlclk: platform_device_register failed.\n");
803 ret = -EBUSY; 802 ret = PTR_ERR(tlclk_device);
804 goto out4; 803 goto out4;
805 } 804 }
806 805
@@ -856,7 +855,7 @@ static void switchover_timeout(unsigned long data)
856 wake_up(&wq); 855 wake_up(&wq);
857} 856}
858 857
859static irqreturn_t tlclk_interrupt(int irq, void *dev_id, struct pt_regs *regs) 858static irqreturn_t tlclk_interrupt(int irq, void *dev_id)
860{ 859{
861 unsigned long flags; 860 unsigned long flags;
862 861
diff --git a/drivers/char/toshiba.c b/drivers/char/toshiba.c
index dd36fd04a842..07067c31c4ec 100644
--- a/drivers/char/toshiba.c
+++ b/drivers/char/toshiba.c
@@ -249,6 +249,7 @@ int tosh_smm(SMMRegisters *regs)
249 249
250 return eax; 250 return eax;
251} 251}
252EXPORT_SYMBOL(tosh_smm);
252 253
253 254
254static int tosh_ioctl(struct inode *ip, struct file *fp, unsigned int cmd, 255static int tosh_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index a082a2e34252..33e1f66e39cb 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -325,9 +325,9 @@ static void user_reader_timeout(unsigned long ptr)
325 schedule_work(&chip->work); 325 schedule_work(&chip->work);
326} 326}
327 327
328static void timeout_work(void *ptr) 328static void timeout_work(struct work_struct *work)
329{ 329{
330 struct tpm_chip *chip = ptr; 330 struct tpm_chip *chip = container_of(work, struct tpm_chip, work);
331 331
332 down(&chip->buffer_mutex); 332 down(&chip->buffer_mutex);
333 atomic_set(&chip->data_pending, 0); 333 atomic_set(&chip->data_pending, 0);
@@ -1105,7 +1105,7 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
1105 init_MUTEX(&chip->tpm_mutex); 1105 init_MUTEX(&chip->tpm_mutex);
1106 INIT_LIST_HEAD(&chip->list); 1106 INIT_LIST_HEAD(&chip->list);
1107 1107
1108 INIT_WORK(&chip->work, timeout_work, chip); 1108 INIT_WORK(&chip->work, timeout_work);
1109 1109
1110 init_timer(&chip->user_read_timer); 1110 init_timer(&chip->user_read_timer);
1111 chip->user_read_timer.function = user_reader_timeout; 1111 chip->user_read_timer.function = user_reader_timeout;
@@ -1130,7 +1130,7 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
1130 scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num); 1130 scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num);
1131 chip->vendor.miscdev.name = devname; 1131 chip->vendor.miscdev.name = devname;
1132 1132
1133 chip->vendor.miscdev.dev = dev; 1133 chip->vendor.miscdev.parent = dev;
1134 chip->dev = get_device(dev); 1134 chip->dev = get_device(dev);
1135 1135
1136 if (misc_register(&chip->vendor.miscdev)) { 1136 if (misc_register(&chip->vendor.miscdev)) {
@@ -1153,7 +1153,15 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
1153 1153
1154 spin_unlock(&driver_lock); 1154 spin_unlock(&driver_lock);
1155 1155
1156 sysfs_create_group(&dev->kobj, chip->vendor.attr_group); 1156 if (sysfs_create_group(&dev->kobj, chip->vendor.attr_group)) {
1157 list_del(&chip->list);
1158 misc_deregister(&chip->vendor.miscdev);
1159 put_device(dev);
1160 clear_bit(chip->dev_num, dev_mask);
1161 kfree(chip);
1162 kfree(devname);
1163 return NULL;
1164 }
1157 1165
1158 chip->bios_dir = tpm_bios_log_setup(devname); 1166 chip->bios_dir = tpm_bios_log_setup(devname);
1159 1167
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 050ced247f68..bb9a43c6cf3d 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -22,6 +22,7 @@
22#include <linux/pci.h> 22#include <linux/pci.h>
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/fs.h> 24#include <linux/fs.h>
25#include <linux/sched.h>
25#include <linux/miscdevice.h> 26#include <linux/miscdevice.h>
26#include <linux/platform_device.h> 27#include <linux/platform_device.h>
27#include <linux/io.h> 28#include <linux/io.h>
diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
index ad8ffe49256f..1ab0896070be 100644
--- a/drivers/char/tpm/tpm_atmel.c
+++ b/drivers/char/tpm/tpm_atmel.c
@@ -184,7 +184,9 @@ static int __init init_atmel(void)
184 unsigned long base; 184 unsigned long base;
185 struct tpm_chip *chip; 185 struct tpm_chip *chip;
186 186
187 driver_register(&atml_drv); 187 rc = driver_register(&atml_drv);
188 if (rc)
189 return rc;
188 190
189 if ((iobase = atmel_get_base_addr(&base, &region_size)) == NULL) { 191 if ((iobase = atmel_get_base_addr(&base, &region_size)) == NULL) {
190 rc = -ENODEV; 192 rc = -ENODEV;
@@ -195,10 +197,8 @@ static int __init init_atmel(void)
195 (atmel_request_region 197 (atmel_request_region
196 (tpm_atmel.base, region_size, "tpm_atmel0") == NULL) ? 0 : 1; 198 (tpm_atmel.base, region_size, "tpm_atmel0") == NULL) ? 0 : 1;
197 199
198 200 pdev = platform_device_register_simple("tpm_atmel", -1, NULL, 0);
199 if (IS_ERR 201 if (IS_ERR(pdev)) {
200 (pdev =
201 platform_device_register_simple("tpm_atmel", -1, NULL, 0))) {
202 rc = PTR_ERR(pdev); 202 rc = PTR_ERR(pdev);
203 goto err_rel_reg; 203 goto err_rel_reg;
204 } 204 }
diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c
index 26287aace87d..608f73071bef 100644
--- a/drivers/char/tpm/tpm_nsc.c
+++ b/drivers/char/tpm/tpm_nsc.c
@@ -284,7 +284,7 @@ static struct device_driver nsc_drv = {
284static int __init init_nsc(void) 284static int __init init_nsc(void)
285{ 285{
286 int rc = 0; 286 int rc = 0;
287 int lo, hi; 287 int lo, hi, err;
288 int nscAddrBase = TPM_ADDR; 288 int nscAddrBase = TPM_ADDR;
289 struct tpm_chip *chip; 289 struct tpm_chip *chip;
290 unsigned long base; 290 unsigned long base;
@@ -297,7 +297,9 @@ static int __init init_nsc(void)
297 return -ENODEV; 297 return -ENODEV;
298 } 298 }
299 299
300 driver_register(&nsc_drv); 300 err = driver_register(&nsc_drv);
301 if (err)
302 return err;
301 303
302 hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI); 304 hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI);
303 lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO); 305 lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO);
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index ee7ac6f43c65..483f3f60013c 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -377,7 +377,7 @@ static struct tpm_vendor_specific tpm_tis = {
377 .fops = &tis_ops,}, 377 .fops = &tis_ops,},
378}; 378};
379 379
380static irqreturn_t tis_int_probe(int irq, void *dev_id, struct pt_regs *regs) 380static irqreturn_t tis_int_probe(int irq, void *dev_id)
381{ 381{
382 struct tpm_chip *chip = (struct tpm_chip *) dev_id; 382 struct tpm_chip *chip = (struct tpm_chip *) dev_id;
383 u32 interrupt; 383 u32 interrupt;
@@ -397,7 +397,7 @@ static irqreturn_t tis_int_probe(int irq, void *dev_id, struct pt_regs *regs)
397 return IRQ_HANDLED; 397 return IRQ_HANDLED;
398} 398}
399 399
400static irqreturn_t tis_int_handler(int irq, void *dev_id, struct pt_regs *regs) 400static irqreturn_t tis_int_handler(int irq, void *dev_id)
401{ 401{
402 struct tpm_chip *chip = (struct tpm_chip *) dev_id; 402 struct tpm_chip *chip = (struct tpm_chip *) dev_id;
403 u32 interrupt; 403 u32 interrupt;
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index bb0d9199e994..4044c864fdd4 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -109,13 +109,15 @@
109#define TTY_PARANOIA_CHECK 1 109#define TTY_PARANOIA_CHECK 1
110#define CHECK_TTY_COUNT 1 110#define CHECK_TTY_COUNT 1
111 111
112struct termios tty_std_termios = { /* for the benefit of tty drivers */ 112struct ktermios tty_std_termios = { /* for the benefit of tty drivers */
113 .c_iflag = ICRNL | IXON, 113 .c_iflag = ICRNL | IXON,
114 .c_oflag = OPOST | ONLCR, 114 .c_oflag = OPOST | ONLCR,
115 .c_cflag = B38400 | CS8 | CREAD | HUPCL, 115 .c_cflag = B38400 | CS8 | CREAD | HUPCL,
116 .c_lflag = ISIG | ICANON | ECHO | ECHOE | ECHOK | 116 .c_lflag = ISIG | ICANON | ECHO | ECHOE | ECHOK |
117 ECHOCTL | ECHOKE | IEXTEN, 117 ECHOCTL | ECHOKE | IEXTEN,
118 .c_cc = INIT_C_CC 118 .c_cc = INIT_C_CC,
119 .c_ispeed = 38400,
120 .c_ospeed = 38400
119}; 121};
120 122
121EXPORT_SYMBOL(tty_std_termios); 123EXPORT_SYMBOL(tty_std_termios);
@@ -126,9 +128,10 @@ EXPORT_SYMBOL(tty_std_termios);
126 128
127LIST_HEAD(tty_drivers); /* linked list of tty drivers */ 129LIST_HEAD(tty_drivers); /* linked list of tty drivers */
128 130
129/* Semaphore to protect creating and releasing a tty. This is shared with 131/* Mutex to protect creating and releasing a tty. This is shared with
130 vt.c for deeply disgusting hack reasons */ 132 vt.c for deeply disgusting hack reasons */
131DEFINE_MUTEX(tty_mutex); 133DEFINE_MUTEX(tty_mutex);
134EXPORT_SYMBOL(tty_mutex);
132 135
133#ifdef CONFIG_UNIX98_PTYS 136#ifdef CONFIG_UNIX98_PTYS
134extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */ 137extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */
@@ -160,17 +163,11 @@ static void release_mem(struct tty_struct *tty, int idx);
160 * been initialized in any way but has been zeroed 163 * been initialized in any way but has been zeroed
161 * 164 *
162 * Locking: none 165 * Locking: none
163 * FIXME: use kzalloc
164 */ 166 */
165 167
166static struct tty_struct *alloc_tty_struct(void) 168static struct tty_struct *alloc_tty_struct(void)
167{ 169{
168 struct tty_struct *tty; 170 return kzalloc(sizeof(struct tty_struct), GFP_KERNEL);
169
170 tty = kmalloc(sizeof(struct tty_struct), GFP_KERNEL);
171 if (tty)
172 memset(tty, 0, sizeof(struct tty_struct));
173 return tty;
174} 171}
175 172
176static void tty_buffer_free_all(struct tty_struct *); 173static void tty_buffer_free_all(struct tty_struct *);
@@ -255,7 +252,7 @@ static int check_tty_count(struct tty_struct *tty, const char *routine)
255 "!= #fd's(%d) in %s\n", 252 "!= #fd's(%d) in %s\n",
256 tty->name, tty->count, count, routine); 253 tty->name, tty->count, count, routine);
257 return count; 254 return count;
258 } 255 }
259#endif 256#endif
260 return 0; 257 return 0;
261} 258}
@@ -264,18 +261,6 @@ static int check_tty_count(struct tty_struct *tty, const char *routine)
264 * Tty buffer allocation management 261 * Tty buffer allocation management
265 */ 262 */
266 263
267
268/**
269 * tty_buffer_free_all - free buffers used by a tty
270 * @tty: tty to free from
271 *
272 * Remove all the buffers pending on a tty whether queued with data
273 * or in the free ring. Must be called when the tty is no longer in use
274 *
275 * Locking: none
276 */
277
278
279/** 264/**
280 * tty_buffer_free_all - free buffers used by a tty 265 * tty_buffer_free_all - free buffers used by a tty
281 * @tty: tty to free from 266 * @tty: tty to free from
@@ -483,10 +468,9 @@ int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars,
483 tb->used += space; 468 tb->used += space;
484 copied += space; 469 copied += space;
485 chars += space; 470 chars += space;
486 } 471 /* There is a small chance that we need to split the data over
487 /* There is a small chance that we need to split the data over 472 several buffers. If this is the case we must loop */
488 several buffers. If this is the case we must loop */ 473 } while (unlikely(size > copied));
489 while (unlikely(size > copied));
490 return copied; 474 return copied;
491} 475}
492EXPORT_SYMBOL(tty_insert_flip_string); 476EXPORT_SYMBOL(tty_insert_flip_string);
@@ -521,10 +505,9 @@ int tty_insert_flip_string_flags(struct tty_struct *tty,
521 copied += space; 505 copied += space;
522 chars += space; 506 chars += space;
523 flags += space; 507 flags += space;
524 } 508 /* There is a small chance that we need to split the data over
525 /* There is a small chance that we need to split the data over 509 several buffers. If this is the case we must loop */
526 several buffers. If this is the case we must loop */ 510 } while (unlikely(size > copied));
527 while (unlikely(size > copied));
528 return copied; 511 return copied;
529} 512}
530EXPORT_SYMBOL(tty_insert_flip_string_flags); 513EXPORT_SYMBOL(tty_insert_flip_string_flags);
@@ -621,14 +604,14 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
621 * they are not on hot paths so a little discipline won't do 604 * they are not on hot paths so a little discipline won't do
622 * any harm. 605 * any harm.
623 * 606 *
624 * Locking: takes termios_sem 607 * Locking: takes termios_mutex
625 */ 608 */
626 609
627static void tty_set_termios_ldisc(struct tty_struct *tty, int num) 610static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
628{ 611{
629 down(&tty->termios_sem); 612 mutex_lock(&tty->termios_mutex);
630 tty->termios->c_line = num; 613 tty->termios->c_line = num;
631 up(&tty->termios_sem); 614 mutex_unlock(&tty->termios_mutex);
632} 615}
633 616
634/* 617/*
@@ -922,7 +905,7 @@ static void tty_ldisc_enable(struct tty_struct *tty)
922 * context. 905 * context.
923 * 906 *
924 * Locking: takes tty_ldisc_lock. 907 * Locking: takes tty_ldisc_lock.
925 * called functions take termios_sem 908 * called functions take termios_mutex
926 */ 909 */
927 910
928static int tty_set_ldisc(struct tty_struct *tty, int ldisc) 911static int tty_set_ldisc(struct tty_struct *tty, int ldisc)
@@ -1258,10 +1241,26 @@ void tty_ldisc_flush(struct tty_struct *tty)
1258} 1241}
1259 1242
1260EXPORT_SYMBOL_GPL(tty_ldisc_flush); 1243EXPORT_SYMBOL_GPL(tty_ldisc_flush);
1244
1245/**
1246 * tty_reset_termios - reset terminal state
1247 * @tty: tty to reset
1248 *
1249 * Restore a terminal to the driver default state
1250 */
1251
1252static void tty_reset_termios(struct tty_struct *tty)
1253{
1254 mutex_lock(&tty->termios_mutex);
1255 *tty->termios = tty->driver->init_termios;
1256 tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios);
1257 tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
1258 mutex_unlock(&tty->termios_mutex);
1259}
1261 1260
1262/** 1261/**
1263 * do_tty_hangup - actual handler for hangup events 1262 * do_tty_hangup - actual handler for hangup events
1264 * @data: tty device 1263 * @work: tty device
1265 * 1264 *
1266 * This can be called by the "eventd" kernel thread. That is process 1265 * This can be called by the "eventd" kernel thread. That is process
1267 * synchronous but doesn't hold any locks, so we need to make sure we 1266 * synchronous but doesn't hold any locks, so we need to make sure we
@@ -1274,16 +1273,17 @@ EXPORT_SYMBOL_GPL(tty_ldisc_flush);
1274 * 1273 *
1275 * Locking: 1274 * Locking:
1276 * BKL 1275 * BKL
1277 * redirect lock for undoing redirection 1276 * redirect lock for undoing redirection
1278 * file list lock for manipulating list of ttys 1277 * file list lock for manipulating list of ttys
1279 * tty_ldisc_lock from called functions 1278 * tty_ldisc_lock from called functions
1280 * termios_sem resetting termios data 1279 * termios_mutex resetting termios data
1281 * tasklist_lock to walk task list for hangup event 1280 * tasklist_lock to walk task list for hangup event
1282 * 1281 * ->siglock to protect ->signal/->sighand
1283 */ 1282 */
1284static void do_tty_hangup(void *data) 1283static void do_tty_hangup(struct work_struct *work)
1285{ 1284{
1286 struct tty_struct *tty = (struct tty_struct *) data; 1285 struct tty_struct *tty =
1286 container_of(work, struct tty_struct, hangup_work);
1287 struct file * cons_filp = NULL; 1287 struct file * cons_filp = NULL;
1288 struct file *filp, *f = NULL; 1288 struct file *filp, *f = NULL;
1289 struct task_struct *p; 1289 struct task_struct *p;
@@ -1345,11 +1345,7 @@ static void do_tty_hangup(void *data)
1345 * N_TTY. 1345 * N_TTY.
1346 */ 1346 */
1347 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) 1347 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS)
1348 { 1348 tty_reset_termios(tty);
1349 down(&tty->termios_sem);
1350 *tty->termios = tty->driver->init_termios;
1351 up(&tty->termios_sem);
1352 }
1353 1349
1354 /* Defer ldisc switch */ 1350 /* Defer ldisc switch */
1355 /* tty_deferred_ldisc_switch(N_TTY); 1351 /* tty_deferred_ldisc_switch(N_TTY);
@@ -1360,14 +1356,18 @@ static void do_tty_hangup(void *data)
1360 read_lock(&tasklist_lock); 1356 read_lock(&tasklist_lock);
1361 if (tty->session > 0) { 1357 if (tty->session > 0) {
1362 do_each_task_pid(tty->session, PIDTYPE_SID, p) { 1358 do_each_task_pid(tty->session, PIDTYPE_SID, p) {
1359 spin_lock_irq(&p->sighand->siglock);
1363 if (p->signal->tty == tty) 1360 if (p->signal->tty == tty)
1364 p->signal->tty = NULL; 1361 p->signal->tty = NULL;
1365 if (!p->signal->leader) 1362 if (!p->signal->leader) {
1363 spin_unlock_irq(&p->sighand->siglock);
1366 continue; 1364 continue;
1367 group_send_sig_info(SIGHUP, SEND_SIG_PRIV, p); 1365 }
1368 group_send_sig_info(SIGCONT, SEND_SIG_PRIV, p); 1366 __group_send_sig_info(SIGHUP, SEND_SIG_PRIV, p);
1367 __group_send_sig_info(SIGCONT, SEND_SIG_PRIV, p);
1369 if (tty->pgrp > 0) 1368 if (tty->pgrp > 0)
1370 p->signal->tty_old_pgrp = tty->pgrp; 1369 p->signal->tty_old_pgrp = tty->pgrp;
1370 spin_unlock_irq(&p->sighand->siglock);
1371 } while_each_task_pid(tty->session, PIDTYPE_SID, p); 1371 } while_each_task_pid(tty->session, PIDTYPE_SID, p);
1372 } 1372 }
1373 read_unlock(&tasklist_lock); 1373 read_unlock(&tasklist_lock);
@@ -1440,7 +1440,7 @@ void tty_vhangup(struct tty_struct * tty)
1440 1440
1441 printk(KERN_DEBUG "%s vhangup...\n", tty_name(tty, buf)); 1441 printk(KERN_DEBUG "%s vhangup...\n", tty_name(tty, buf));
1442#endif 1442#endif
1443 do_tty_hangup((void *) tty); 1443 do_tty_hangup(&tty->hangup_work);
1444} 1444}
1445EXPORT_SYMBOL(tty_vhangup); 1445EXPORT_SYMBOL(tty_vhangup);
1446 1446
@@ -1459,6 +1459,14 @@ int tty_hung_up_p(struct file * filp)
1459 1459
1460EXPORT_SYMBOL(tty_hung_up_p); 1460EXPORT_SYMBOL(tty_hung_up_p);
1461 1461
1462static void session_clear_tty(pid_t session)
1463{
1464 struct task_struct *p;
1465 do_each_task_pid(session, PIDTYPE_SID, p) {
1466 proc_clear_tty(p);
1467 } while_each_task_pid(session, PIDTYPE_SID, p);
1468}
1469
1462/** 1470/**
1463 * disassociate_ctty - disconnect controlling tty 1471 * disassociate_ctty - disconnect controlling tty
1464 * @on_exit: true if exiting so need to "hang up" the session 1472 * @on_exit: true if exiting so need to "hang up" the session
@@ -1475,31 +1483,35 @@ EXPORT_SYMBOL(tty_hung_up_p);
1475 * The argument on_exit is set to 1 if called when a process is 1483 * The argument on_exit is set to 1 if called when a process is
1476 * exiting; it is 0 if called by the ioctl TIOCNOTTY. 1484 * exiting; it is 0 if called by the ioctl TIOCNOTTY.
1477 * 1485 *
1478 * Locking: tty_mutex is taken to protect current->signal->tty 1486 * Locking:
1479 * BKL is taken for hysterical raisins 1487 * BKL is taken for hysterical raisins
1480 * Tasklist lock is taken (under tty_mutex) to walk process 1488 * tty_mutex is taken to protect tty
1481 * lists for the session. 1489 * ->siglock is taken to protect ->signal/->sighand
1490 * tasklist_lock is taken to walk process list for sessions
1491 * ->siglock is taken to protect ->signal/->sighand
1482 */ 1492 */
1483 1493
1484void disassociate_ctty(int on_exit) 1494void disassociate_ctty(int on_exit)
1485{ 1495{
1486 struct tty_struct *tty; 1496 struct tty_struct *tty;
1487 struct task_struct *p;
1488 int tty_pgrp = -1; 1497 int tty_pgrp = -1;
1498 int session;
1489 1499
1490 lock_kernel(); 1500 lock_kernel();
1491 1501
1492 mutex_lock(&tty_mutex); 1502 mutex_lock(&tty_mutex);
1493 tty = current->signal->tty; 1503 tty = get_current_tty();
1494 if (tty) { 1504 if (tty) {
1495 tty_pgrp = tty->pgrp; 1505 tty_pgrp = tty->pgrp;
1496 mutex_unlock(&tty_mutex); 1506 mutex_unlock(&tty_mutex);
1507 /* XXX: here we race, there is nothing protecting tty */
1497 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) 1508 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY)
1498 tty_vhangup(tty); 1509 tty_vhangup(tty);
1499 } else { 1510 } else {
1500 if (current->signal->tty_old_pgrp) { 1511 pid_t old_pgrp = current->signal->tty_old_pgrp;
1501 kill_pg(current->signal->tty_old_pgrp, SIGHUP, on_exit); 1512 if (old_pgrp) {
1502 kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit); 1513 kill_pg(old_pgrp, SIGHUP, on_exit);
1514 kill_pg(old_pgrp, SIGCONT, on_exit);
1503 } 1515 }
1504 mutex_unlock(&tty_mutex); 1516 mutex_unlock(&tty_mutex);
1505 unlock_kernel(); 1517 unlock_kernel();
@@ -1511,19 +1523,29 @@ void disassociate_ctty(int on_exit)
1511 kill_pg(tty_pgrp, SIGCONT, on_exit); 1523 kill_pg(tty_pgrp, SIGCONT, on_exit);
1512 } 1524 }
1513 1525
1514 /* Must lock changes to tty_old_pgrp */ 1526 spin_lock_irq(&current->sighand->siglock);
1515 mutex_lock(&tty_mutex);
1516 current->signal->tty_old_pgrp = 0; 1527 current->signal->tty_old_pgrp = 0;
1517 tty->session = 0; 1528 session = process_session(current);
1518 tty->pgrp = -1; 1529 spin_unlock_irq(&current->sighand->siglock);
1530
1531 mutex_lock(&tty_mutex);
1532 /* It is possible that do_tty_hangup has free'd this tty */
1533 tty = get_current_tty();
1534 if (tty) {
1535 tty->session = 0;
1536 tty->pgrp = 0;
1537 } else {
1538#ifdef TTY_DEBUG_HANGUP
1539 printk(KERN_DEBUG "error attempted to write to tty [0x%p]"
1540 " = NULL", tty);
1541#endif
1542 }
1543 mutex_unlock(&tty_mutex);
1519 1544
1520 /* Now clear signal->tty under the lock */ 1545 /* Now clear signal->tty under the lock */
1521 read_lock(&tasklist_lock); 1546 read_lock(&tasklist_lock);
1522 do_each_task_pid(current->signal->session, PIDTYPE_SID, p) { 1547 session_clear_tty(session);
1523 p->signal->tty = NULL;
1524 } while_each_task_pid(current->signal->session, PIDTYPE_SID, p);
1525 read_unlock(&tasklist_lock); 1548 read_unlock(&tasklist_lock);
1526 mutex_unlock(&tty_mutex);
1527 unlock_kernel(); 1549 unlock_kernel();
1528} 1550}
1529 1551
@@ -1621,7 +1643,7 @@ static ssize_t tty_read(struct file * file, char __user * buf, size_t count,
1621 struct tty_ldisc *ld; 1643 struct tty_ldisc *ld;
1622 1644
1623 tty = (struct tty_struct *)file->private_data; 1645 tty = (struct tty_struct *)file->private_data;
1624 inode = file->f_dentry->d_inode; 1646 inode = file->f_path.dentry->d_inode;
1625 if (tty_paranoia_check(tty, inode, "tty_read")) 1647 if (tty_paranoia_check(tty, inode, "tty_read"))
1626 return -EIO; 1648 return -EIO;
1627 if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags))) 1649 if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags)))
@@ -1724,7 +1746,7 @@ static inline ssize_t do_tty_write(
1724 cond_resched(); 1746 cond_resched();
1725 } 1747 }
1726 if (written) { 1748 if (written) {
1727 struct inode *inode = file->f_dentry->d_inode; 1749 struct inode *inode = file->f_path.dentry->d_inode;
1728 inode->i_mtime = current_fs_time(inode->i_sb); 1750 inode->i_mtime = current_fs_time(inode->i_sb);
1729 ret = written; 1751 ret = written;
1730 } 1752 }
@@ -1755,7 +1777,7 @@ static ssize_t tty_write(struct file * file, const char __user * buf, size_t cou
1755 loff_t *ppos) 1777 loff_t *ppos)
1756{ 1778{
1757 struct tty_struct * tty; 1779 struct tty_struct * tty;
1758 struct inode *inode = file->f_dentry->d_inode; 1780 struct inode *inode = file->f_path.dentry->d_inode;
1759 ssize_t ret; 1781 ssize_t ret;
1760 struct tty_ldisc *ld; 1782 struct tty_ldisc *ld;
1761 1783
@@ -1862,8 +1884,8 @@ static int init_dev(struct tty_driver *driver, int idx,
1862 struct tty_struct **ret_tty) 1884 struct tty_struct **ret_tty)
1863{ 1885{
1864 struct tty_struct *tty, *o_tty; 1886 struct tty_struct *tty, *o_tty;
1865 struct termios *tp, **tp_loc, *o_tp, **o_tp_loc; 1887 struct ktermios *tp, **tp_loc, *o_tp, **o_tp_loc;
1866 struct termios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc; 1888 struct ktermios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc;
1867 int retval = 0; 1889 int retval = 0;
1868 1890
1869 /* check whether we're reopening an existing tty */ 1891 /* check whether we're reopening an existing tty */
@@ -1910,7 +1932,7 @@ static int init_dev(struct tty_driver *driver, int idx,
1910 } 1932 }
1911 1933
1912 if (!*tp_loc) { 1934 if (!*tp_loc) {
1913 tp = (struct termios *) kmalloc(sizeof(struct termios), 1935 tp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
1914 GFP_KERNEL); 1936 GFP_KERNEL);
1915 if (!tp) 1937 if (!tp)
1916 goto free_mem_out; 1938 goto free_mem_out;
@@ -1918,11 +1940,11 @@ static int init_dev(struct tty_driver *driver, int idx,
1918 } 1940 }
1919 1941
1920 if (!*ltp_loc) { 1942 if (!*ltp_loc) {
1921 ltp = (struct termios *) kmalloc(sizeof(struct termios), 1943 ltp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
1922 GFP_KERNEL); 1944 GFP_KERNEL);
1923 if (!ltp) 1945 if (!ltp)
1924 goto free_mem_out; 1946 goto free_mem_out;
1925 memset(ltp, 0, sizeof(struct termios)); 1947 memset(ltp, 0, sizeof(struct ktermios));
1926 } 1948 }
1927 1949
1928 if (driver->type == TTY_DRIVER_TYPE_PTY) { 1950 if (driver->type == TTY_DRIVER_TYPE_PTY) {
@@ -1943,19 +1965,19 @@ static int init_dev(struct tty_driver *driver, int idx,
1943 } 1965 }
1944 1966
1945 if (!*o_tp_loc) { 1967 if (!*o_tp_loc) {
1946 o_tp = (struct termios *) 1968 o_tp = (struct ktermios *)
1947 kmalloc(sizeof(struct termios), GFP_KERNEL); 1969 kmalloc(sizeof(struct ktermios), GFP_KERNEL);
1948 if (!o_tp) 1970 if (!o_tp)
1949 goto free_mem_out; 1971 goto free_mem_out;
1950 *o_tp = driver->other->init_termios; 1972 *o_tp = driver->other->init_termios;
1951 } 1973 }
1952 1974
1953 if (!*o_ltp_loc) { 1975 if (!*o_ltp_loc) {
1954 o_ltp = (struct termios *) 1976 o_ltp = (struct ktermios *)
1955 kmalloc(sizeof(struct termios), GFP_KERNEL); 1977 kmalloc(sizeof(struct ktermios), GFP_KERNEL);
1956 if (!o_ltp) 1978 if (!o_ltp)
1957 goto free_mem_out; 1979 goto free_mem_out;
1958 memset(o_ltp, 0, sizeof(struct termios)); 1980 memset(o_ltp, 0, sizeof(struct ktermios));
1959 } 1981 }
1960 1982
1961 /* 1983 /*
@@ -1994,6 +2016,9 @@ static int init_dev(struct tty_driver *driver, int idx,
1994 *ltp_loc = ltp; 2016 *ltp_loc = ltp;
1995 tty->termios = *tp_loc; 2017 tty->termios = *tp_loc;
1996 tty->termios_locked = *ltp_loc; 2018 tty->termios_locked = *ltp_loc;
2019 /* Compatibility until drivers always set this */
2020 tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios);
2021 tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
1997 driver->refcount++; 2022 driver->refcount++;
1998 tty->count++; 2023 tty->count++;
1999 2024
@@ -2072,8 +2097,9 @@ fail_no_mem:
2072 2097
2073 /* call the tty release_mem routine to clean out this slot */ 2098 /* call the tty release_mem routine to clean out this slot */
2074release_mem_out: 2099release_mem_out:
2075 printk(KERN_INFO "init_dev: ldisc open failed, " 2100 if (printk_ratelimit())
2076 "clearing slot %d\n", idx); 2101 printk(KERN_INFO "init_dev: ldisc open failed, "
2102 "clearing slot %d\n", idx);
2077 release_mem(tty, idx); 2103 release_mem(tty, idx);
2078 goto end_init; 2104 goto end_init;
2079} 2105}
@@ -2095,7 +2121,7 @@ release_mem_out:
2095static void release_mem(struct tty_struct *tty, int idx) 2121static void release_mem(struct tty_struct *tty, int idx)
2096{ 2122{
2097 struct tty_struct *o_tty; 2123 struct tty_struct *o_tty;
2098 struct termios *tp; 2124 struct ktermios *tp;
2099 int devpts = tty->driver->flags & TTY_DRIVER_DEVPTS_MEM; 2125 int devpts = tty->driver->flags & TTY_DRIVER_DEVPTS_MEM;
2100 2126
2101 if ((o_tty = tty->link) != NULL) { 2127 if ((o_tty = tty->link) != NULL) {
@@ -2161,7 +2187,7 @@ static void release_dev(struct file * filp)
2161 unsigned long flags; 2187 unsigned long flags;
2162 2188
2163 tty = (struct tty_struct *)filp->private_data; 2189 tty = (struct tty_struct *)filp->private_data;
2164 if (tty_paranoia_check(tty, filp->f_dentry->d_inode, "release_dev")) 2190 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "release_dev"))
2165 return; 2191 return;
2166 2192
2167 check_tty_count(tty, "release_dev"); 2193 check_tty_count(tty, "release_dev");
@@ -2342,16 +2368,10 @@ static void release_dev(struct file * filp)
2342 * tty. 2368 * tty.
2343 */ 2369 */
2344 if (tty_closing || o_tty_closing) { 2370 if (tty_closing || o_tty_closing) {
2345 struct task_struct *p;
2346
2347 read_lock(&tasklist_lock); 2371 read_lock(&tasklist_lock);
2348 do_each_task_pid(tty->session, PIDTYPE_SID, p) { 2372 session_clear_tty(tty->session);
2349 p->signal->tty = NULL;
2350 } while_each_task_pid(tty->session, PIDTYPE_SID, p);
2351 if (o_tty) 2373 if (o_tty)
2352 do_each_task_pid(o_tty->session, PIDTYPE_SID, p) { 2374 session_clear_tty(o_tty->session);
2353 p->signal->tty = NULL;
2354 } while_each_task_pid(o_tty->session, PIDTYPE_SID, p);
2355 read_unlock(&tasklist_lock); 2375 read_unlock(&tasklist_lock);
2356 } 2376 }
2357 2377
@@ -2448,9 +2468,9 @@ static void release_dev(struct file * filp)
2448 * The termios state of a pty is reset on first open so that 2468 * The termios state of a pty is reset on first open so that
2449 * settings don't persist across reuse. 2469 * settings don't persist across reuse.
2450 * 2470 *
2451 * Locking: tty_mutex protects current->signal->tty, get_tty_driver and 2471 * Locking: tty_mutex protects tty, get_tty_driver and init_dev work.
2452 * init_dev work. tty->count should protect the rest. 2472 * tty->count should protect the rest.
2453 * task_lock is held to update task details for sessions 2473 * ->siglock protects ->signal/->sighand
2454 */ 2474 */
2455 2475
2456static int tty_open(struct inode * inode, struct file * filp) 2476static int tty_open(struct inode * inode, struct file * filp)
@@ -2472,12 +2492,13 @@ retry_open:
2472 mutex_lock(&tty_mutex); 2492 mutex_lock(&tty_mutex);
2473 2493
2474 if (device == MKDEV(TTYAUX_MAJOR,0)) { 2494 if (device == MKDEV(TTYAUX_MAJOR,0)) {
2475 if (!current->signal->tty) { 2495 tty = get_current_tty();
2496 if (!tty) {
2476 mutex_unlock(&tty_mutex); 2497 mutex_unlock(&tty_mutex);
2477 return -ENXIO; 2498 return -ENXIO;
2478 } 2499 }
2479 driver = current->signal->tty->driver; 2500 driver = tty->driver;
2480 index = current->signal->tty->index; 2501 index = tty->index;
2481 filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */ 2502 filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */
2482 /* noctty = 1; */ 2503 /* noctty = 1; */
2483 goto got_driver; 2504 goto got_driver;
@@ -2552,17 +2573,16 @@ got_driver:
2552 filp->f_op = &tty_fops; 2573 filp->f_op = &tty_fops;
2553 goto retry_open; 2574 goto retry_open;
2554 } 2575 }
2576
2577 mutex_lock(&tty_mutex);
2578 spin_lock_irq(&current->sighand->siglock);
2555 if (!noctty && 2579 if (!noctty &&
2556 current->signal->leader && 2580 current->signal->leader &&
2557 !current->signal->tty && 2581 !current->signal->tty &&
2558 tty->session == 0) { 2582 tty->session == 0)
2559 task_lock(current); 2583 __proc_set_tty(current, tty);
2560 current->signal->tty = tty; 2584 spin_unlock_irq(&current->sighand->siglock);
2561 task_unlock(current); 2585 mutex_unlock(&tty_mutex);
2562 current->signal->tty_old_pgrp = 0;
2563 tty->session = current->signal->session;
2564 tty->pgrp = process_group(current);
2565 }
2566 return 0; 2586 return 0;
2567} 2587}
2568 2588
@@ -2677,7 +2697,7 @@ static unsigned int tty_poll(struct file * filp, poll_table * wait)
2677 int ret = 0; 2697 int ret = 0;
2678 2698
2679 tty = (struct tty_struct *)filp->private_data; 2699 tty = (struct tty_struct *)filp->private_data;
2680 if (tty_paranoia_check(tty, filp->f_dentry->d_inode, "tty_poll")) 2700 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_poll"))
2681 return 0; 2701 return 0;
2682 2702
2683 ld = tty_ldisc_ref_wait(tty); 2703 ld = tty_ldisc_ref_wait(tty);
@@ -2693,7 +2713,7 @@ static int tty_fasync(int fd, struct file * filp, int on)
2693 int retval; 2713 int retval;
2694 2714
2695 tty = (struct tty_struct *)filp->private_data; 2715 tty = (struct tty_struct *)filp->private_data;
2696 if (tty_paranoia_check(tty, filp->f_dentry->d_inode, "tty_fasync")) 2716 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_fasync"))
2697 return 0; 2717 return 0;
2698 2718
2699 retval = fasync_helper(fd, filp, on, &tty->fasync); 2719 retval = fasync_helper(fd, filp, on, &tty->fasync);
@@ -2726,6 +2746,8 @@ static int tty_fasync(int fd, struct file * filp, int on)
2726 * Locking: 2746 * Locking:
2727 * Called functions take tty_ldisc_lock 2747 * Called functions take tty_ldisc_lock
2728 * current->signal->tty check is safe without locks 2748 * current->signal->tty check is safe without locks
2749 *
2750 * FIXME: may race normal receive processing
2729 */ 2751 */
2730 2752
2731static int tiocsti(struct tty_struct *tty, char __user *p) 2753static int tiocsti(struct tty_struct *tty, char __user *p)
@@ -2748,18 +2770,21 @@ static int tiocsti(struct tty_struct *tty, char __user *p)
2748 * @tty; tty 2770 * @tty; tty
2749 * @arg: user buffer for result 2771 * @arg: user buffer for result
2750 * 2772 *
2751 * Copies the kernel idea of the window size into the user buffer. No 2773 * Copies the kernel idea of the window size into the user buffer.
2752 * locking is done.
2753 * 2774 *
2754 * FIXME: Returning random values racing a window size set is wrong 2775 * Locking: tty->termios_mutex is taken to ensure the winsize data
2755 * should lock here against that 2776 * is consistent.
2756 */ 2777 */
2757 2778
2758static int tiocgwinsz(struct tty_struct *tty, struct winsize __user * arg) 2779static int tiocgwinsz(struct tty_struct *tty, struct winsize __user * arg)
2759{ 2780{
2760 if (copy_to_user(arg, &tty->winsize, sizeof(*arg))) 2781 int err;
2761 return -EFAULT; 2782
2762 return 0; 2783 mutex_lock(&tty->termios_mutex);
2784 err = copy_to_user(arg, &tty->winsize, sizeof(*arg));
2785 mutex_unlock(&tty->termios_mutex);
2786
2787 return err ? -EFAULT: 0;
2763} 2788}
2764 2789
2765/** 2790/**
@@ -2772,12 +2797,11 @@ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user * arg)
2772 * actually has driver level meaning and triggers a VC resize. 2797 * actually has driver level meaning and triggers a VC resize.
2773 * 2798 *
2774 * Locking: 2799 * Locking:
2775 * The console_sem is used to ensure we do not try and resize 2800 * Called function use the console_sem is used to ensure we do
2776 * the console twice at once. 2801 * not try and resize the console twice at once.
2777 * FIXME: Two racing size sets may leave the console and kernel 2802 * The tty->termios_mutex is used to ensure we don't double
2778 * parameters disagreeing. Is this exploitable ? 2803 * resize and get confused. Lock order - tty->termios_mutex before
2779 * FIXME: Random values racing a window size get is wrong 2804 * console sem
2780 * should lock here against that
2781 */ 2805 */
2782 2806
2783static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty, 2807static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
@@ -2787,17 +2811,18 @@ static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
2787 2811
2788 if (copy_from_user(&tmp_ws, arg, sizeof(*arg))) 2812 if (copy_from_user(&tmp_ws, arg, sizeof(*arg)))
2789 return -EFAULT; 2813 return -EFAULT;
2814
2815 mutex_lock(&tty->termios_mutex);
2790 if (!memcmp(&tmp_ws, &tty->winsize, sizeof(*arg))) 2816 if (!memcmp(&tmp_ws, &tty->winsize, sizeof(*arg)))
2791 return 0; 2817 goto done;
2818
2792#ifdef CONFIG_VT 2819#ifdef CONFIG_VT
2793 if (tty->driver->type == TTY_DRIVER_TYPE_CONSOLE) { 2820 if (tty->driver->type == TTY_DRIVER_TYPE_CONSOLE) {
2794 int rc; 2821 if (vc_lock_resize(tty->driver_data, tmp_ws.ws_col,
2795 2822 tmp_ws.ws_row)) {
2796 acquire_console_sem(); 2823 mutex_unlock(&tty->termios_mutex);
2797 rc = vc_resize(tty->driver_data, tmp_ws.ws_col, tmp_ws.ws_row); 2824 return -ENXIO;
2798 release_console_sem(); 2825 }
2799 if (rc)
2800 return -ENXIO;
2801 } 2826 }
2802#endif 2827#endif
2803 if (tty->pgrp > 0) 2828 if (tty->pgrp > 0)
@@ -2806,6 +2831,8 @@ static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
2806 kill_pg(real_tty->pgrp, SIGWINCH, 1); 2831 kill_pg(real_tty->pgrp, SIGWINCH, 1);
2807 tty->winsize = tmp_ws; 2832 tty->winsize = tmp_ws;
2808 real_tty->winsize = tmp_ws; 2833 real_tty->winsize = tmp_ws;
2834done:
2835 mutex_unlock(&tty->termios_mutex);
2809 return 0; 2836 return 0;
2810} 2837}
2811 2838
@@ -2878,27 +2905,28 @@ static int fionbio(struct file *file, int __user *p)
2878 * leader to set this tty as the controlling tty for the session. 2905 * leader to set this tty as the controlling tty for the session.
2879 * 2906 *
2880 * Locking: 2907 * Locking:
2881 * Takes tasklist lock internally to walk sessions 2908 * Takes tty_mutex() to protect tty instance
2882 * Takes task_lock() when updating signal->tty 2909 * Takes tasklist_lock internally to walk sessions
2883 * 2910 * Takes ->siglock() when updating signal->tty
2884 * FIXME: tty_mutex is needed to protect signal->tty references.
2885 * FIXME: why task_lock on the signal->tty reference ??
2886 *
2887 */ 2911 */
2888 2912
2889static int tiocsctty(struct tty_struct *tty, int arg) 2913static int tiocsctty(struct tty_struct *tty, int arg)
2890{ 2914{
2891 struct task_struct *p; 2915 int ret = 0;
2892
2893 if (current->signal->leader && 2916 if (current->signal->leader &&
2894 (current->signal->session == tty->session)) 2917 (process_session(current) == tty->session))
2895 return 0; 2918 return ret;
2919
2920 mutex_lock(&tty_mutex);
2896 /* 2921 /*
2897 * The process must be a session leader and 2922 * The process must be a session leader and
2898 * not have a controlling tty already. 2923 * not have a controlling tty already.
2899 */ 2924 */
2900 if (!current->signal->leader || current->signal->tty) 2925 if (!current->signal->leader || current->signal->tty) {
2901 return -EPERM; 2926 ret = -EPERM;
2927 goto unlock;
2928 }
2929
2902 if (tty->session > 0) { 2930 if (tty->session > 0) {
2903 /* 2931 /*
2904 * This tty is already the controlling 2932 * This tty is already the controlling
@@ -2908,22 +2936,18 @@ static int tiocsctty(struct tty_struct *tty, int arg)
2908 /* 2936 /*
2909 * Steal it away 2937 * Steal it away
2910 */ 2938 */
2911
2912 read_lock(&tasklist_lock); 2939 read_lock(&tasklist_lock);
2913 do_each_task_pid(tty->session, PIDTYPE_SID, p) { 2940 session_clear_tty(tty->session);
2914 p->signal->tty = NULL;
2915 } while_each_task_pid(tty->session, PIDTYPE_SID, p);
2916 read_unlock(&tasklist_lock); 2941 read_unlock(&tasklist_lock);
2917 } else 2942 } else {
2918 return -EPERM; 2943 ret = -EPERM;
2944 goto unlock;
2945 }
2919 } 2946 }
2920 task_lock(current); 2947 proc_set_tty(current, tty);
2921 current->signal->tty = tty; 2948unlock:
2922 task_unlock(current); 2949 mutex_unlock(&tty_mutex);
2923 current->signal->tty_old_pgrp = 0; 2950 return ret;
2924 tty->session = current->signal->session;
2925 tty->pgrp = process_group(current);
2926 return 0;
2927} 2951}
2928 2952
2929/** 2953/**
@@ -2935,7 +2959,7 @@ static int tiocsctty(struct tty_struct *tty, int arg)
2935 * Obtain the process group of the tty. If there is no process group 2959 * Obtain the process group of the tty. If there is no process group
2936 * return an error. 2960 * return an error.
2937 * 2961 *
2938 * Locking: none. Reference to ->signal->tty is safe. 2962 * Locking: none. Reference to current->signal->tty is safe.
2939 */ 2963 */
2940 2964
2941static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) 2965static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
@@ -2959,8 +2983,6 @@ static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
2959 * permitted where the tty session is our session. 2983 * permitted where the tty session is our session.
2960 * 2984 *
2961 * Locking: None 2985 * Locking: None
2962 *
2963 * FIXME: current->signal->tty referencing is unsafe.
2964 */ 2986 */
2965 2987
2966static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) 2988static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
@@ -2974,13 +2996,13 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
2974 return retval; 2996 return retval;
2975 if (!current->signal->tty || 2997 if (!current->signal->tty ||
2976 (current->signal->tty != real_tty) || 2998 (current->signal->tty != real_tty) ||
2977 (real_tty->session != current->signal->session)) 2999 (real_tty->session != process_session(current)))
2978 return -ENOTTY; 3000 return -ENOTTY;
2979 if (get_user(pgrp, p)) 3001 if (get_user(pgrp, p))
2980 return -EFAULT; 3002 return -EFAULT;
2981 if (pgrp < 0) 3003 if (pgrp < 0)
2982 return -EINVAL; 3004 return -EINVAL;
2983 if (session_of_pgrp(pgrp) != current->signal->session) 3005 if (session_of_pgrp(pgrp) != process_session(current))
2984 return -EPERM; 3006 return -EPERM;
2985 real_tty->pgrp = pgrp; 3007 real_tty->pgrp = pgrp;
2986 return 0; 3008 return 0;
@@ -2995,7 +3017,7 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
2995 * Obtain the session id of the tty. If there is no session 3017 * Obtain the session id of the tty. If there is no session
2996 * return an error. 3018 * return an error.
2997 * 3019 *
2998 * Locking: none. Reference to ->signal->tty is safe. 3020 * Locking: none. Reference to current->signal->tty is safe.
2999 */ 3021 */
3000 3022
3001static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) 3023static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
@@ -3039,19 +3061,20 @@ static int tiocsetd(struct tty_struct *tty, int __user *p)
3039 * timed break functionality. 3061 * timed break functionality.
3040 * 3062 *
3041 * Locking: 3063 * Locking:
3042 * None 3064 * atomic_write_lock serializes
3043 * 3065 *
3044 * FIXME:
3045 * What if two overlap
3046 */ 3066 */
3047 3067
3048static int send_break(struct tty_struct *tty, unsigned int duration) 3068static int send_break(struct tty_struct *tty, unsigned int duration)
3049{ 3069{
3070 if (mutex_lock_interruptible(&tty->atomic_write_lock))
3071 return -EINTR;
3050 tty->driver->break_ctl(tty, -1); 3072 tty->driver->break_ctl(tty, -1);
3051 if (!signal_pending(current)) { 3073 if (!signal_pending(current)) {
3052 msleep_interruptible(duration); 3074 msleep_interruptible(duration);
3053 } 3075 }
3054 tty->driver->break_ctl(tty, 0); 3076 tty->driver->break_ctl(tty, 0);
3077 mutex_unlock(&tty->atomic_write_lock);
3055 if (signal_pending(current)) 3078 if (signal_pending(current))
3056 return -EINTR; 3079 return -EINTR;
3057 return 0; 3080 return 0;
@@ -3144,6 +3167,8 @@ int tty_ioctl(struct inode * inode, struct file * file,
3144 if (tty_paranoia_check(tty, inode, "tty_ioctl")) 3167 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
3145 return -EINVAL; 3168 return -EINVAL;
3146 3169
3170 /* CHECKME: is this safe as one end closes ? */
3171
3147 real_tty = tty; 3172 real_tty = tty;
3148 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 3173 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
3149 tty->driver->subtype == PTY_TYPE_MASTER) 3174 tty->driver->subtype == PTY_TYPE_MASTER)
@@ -3211,14 +3236,11 @@ int tty_ioctl(struct inode * inode, struct file * file,
3211 clear_bit(TTY_EXCLUSIVE, &tty->flags); 3236 clear_bit(TTY_EXCLUSIVE, &tty->flags);
3212 return 0; 3237 return 0;
3213 case TIOCNOTTY: 3238 case TIOCNOTTY:
3214 /* FIXME: taks lock or tty_mutex ? */
3215 if (current->signal->tty != tty) 3239 if (current->signal->tty != tty)
3216 return -ENOTTY; 3240 return -ENOTTY;
3217 if (current->signal->leader) 3241 if (current->signal->leader)
3218 disassociate_ctty(0); 3242 disassociate_ctty(0);
3219 task_lock(current); 3243 proc_clear_tty(current);
3220 current->signal->tty = NULL;
3221 task_unlock(current);
3222 return 0; 3244 return 0;
3223 case TIOCSCTTY: 3245 case TIOCSCTTY:
3224 return tiocsctty(tty, arg); 3246 return tiocsctty(tty, arg);
@@ -3302,12 +3324,13 @@ int tty_ioctl(struct inode * inode, struct file * file,
3302 * Nasty bug: do_SAK is being called in interrupt context. This can 3324 * Nasty bug: do_SAK is being called in interrupt context. This can
3303 * deadlock. We punt it up to process context. AKPM - 16Mar2001 3325 * deadlock. We punt it up to process context. AKPM - 16Mar2001
3304 */ 3326 */
3305static void __do_SAK(void *arg) 3327static void __do_SAK(struct work_struct *work)
3306{ 3328{
3329 struct tty_struct *tty =
3330 container_of(work, struct tty_struct, SAK_work);
3307#ifdef TTY_SOFT_SAK 3331#ifdef TTY_SOFT_SAK
3308 tty_hangup(tty); 3332 tty_hangup(tty);
3309#else 3333#else
3310 struct tty_struct *tty = arg;
3311 struct task_struct *g, *p; 3334 struct task_struct *g, *p;
3312 int session; 3335 int session;
3313 int i; 3336 int i;
@@ -3317,7 +3340,7 @@ static void __do_SAK(void *arg)
3317 3340
3318 if (!tty) 3341 if (!tty)
3319 return; 3342 return;
3320 session = tty->session; 3343 session = tty->session;
3321 3344
3322 /* We don't want an ldisc switch during this */ 3345 /* We don't want an ldisc switch during this */
3323 disc = tty_ldisc_ref(tty); 3346 disc = tty_ldisc_ref(tty);
@@ -3332,7 +3355,7 @@ static void __do_SAK(void *arg)
3332 /* Kill the entire session */ 3355 /* Kill the entire session */
3333 do_each_task_pid(session, PIDTYPE_SID, p) { 3356 do_each_task_pid(session, PIDTYPE_SID, p) {
3334 printk(KERN_NOTICE "SAK: killed process %d" 3357 printk(KERN_NOTICE "SAK: killed process %d"
3335 " (%s): p->signal->session==tty->session\n", 3358 " (%s): process_session(p)==tty->session\n",
3336 p->pid, p->comm); 3359 p->pid, p->comm);
3337 send_sig(SIGKILL, p, 1); 3360 send_sig(SIGKILL, p, 1);
3338 } while_each_task_pid(session, PIDTYPE_SID, p); 3361 } while_each_task_pid(session, PIDTYPE_SID, p);
@@ -3342,7 +3365,7 @@ static void __do_SAK(void *arg)
3342 do_each_thread(g, p) { 3365 do_each_thread(g, p) {
3343 if (p->signal->tty == tty) { 3366 if (p->signal->tty == tty) {
3344 printk(KERN_NOTICE "SAK: killed process %d" 3367 printk(KERN_NOTICE "SAK: killed process %d"
3345 " (%s): p->signal->session==tty->session\n", 3368 " (%s): process_session(p)==tty->session\n",
3346 p->pid, p->comm); 3369 p->pid, p->comm);
3347 send_sig(SIGKILL, p, 1); 3370 send_sig(SIGKILL, p, 1);
3348 continue; 3371 continue;
@@ -3386,7 +3409,7 @@ void do_SAK(struct tty_struct *tty)
3386{ 3409{
3387 if (!tty) 3410 if (!tty)
3388 return; 3411 return;
3389 PREPARE_WORK(&tty->SAK_work, __do_SAK, tty); 3412 PREPARE_WORK(&tty->SAK_work, __do_SAK);
3390 schedule_work(&tty->SAK_work); 3413 schedule_work(&tty->SAK_work);
3391} 3414}
3392 3415
@@ -3394,7 +3417,7 @@ EXPORT_SYMBOL(do_SAK);
3394 3417
3395/** 3418/**
3396 * flush_to_ldisc 3419 * flush_to_ldisc
3397 * @private_: tty structure passed from work queue. 3420 * @work: tty structure passed from work queue.
3398 * 3421 *
3399 * This routine is called out of the software interrupt to flush data 3422 * This routine is called out of the software interrupt to flush data
3400 * from the buffer chain to the line discipline. 3423 * from the buffer chain to the line discipline.
@@ -3404,9 +3427,10 @@ EXPORT_SYMBOL(do_SAK);
3404 * receive_buf method is single threaded for each tty instance. 3427 * receive_buf method is single threaded for each tty instance.
3405 */ 3428 */
3406 3429
3407static void flush_to_ldisc(void *private_) 3430static void flush_to_ldisc(struct work_struct *work)
3408{ 3431{
3409 struct tty_struct *tty = (struct tty_struct *) private_; 3432 struct tty_struct *tty =
3433 container_of(work, struct tty_struct, buf.work.work);
3410 unsigned long flags; 3434 unsigned long flags;
3411 struct tty_ldisc *disc; 3435 struct tty_ldisc *disc;
3412 struct tty_buffer *tbuf, *head; 3436 struct tty_buffer *tbuf, *head;
@@ -3451,84 +3475,6 @@ static void flush_to_ldisc(void *private_)
3451 tty_ldisc_deref(disc); 3475 tty_ldisc_deref(disc);
3452} 3476}
3453 3477
3454/*
3455 * Routine which returns the baud rate of the tty
3456 *
3457 * Note that the baud_table needs to be kept in sync with the
3458 * include/asm/termbits.h file.
3459 */
3460static int baud_table[] = {
3461 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
3462 9600, 19200, 38400, 57600, 115200, 230400, 460800,
3463#ifdef __sparc__
3464 76800, 153600, 307200, 614400, 921600
3465#else
3466 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000,
3467 2500000, 3000000, 3500000, 4000000
3468#endif
3469};
3470
3471static int n_baud_table = ARRAY_SIZE(baud_table);
3472
3473/**
3474 * tty_termios_baud_rate
3475 * @termios: termios structure
3476 *
3477 * Convert termios baud rate data into a speed. This should be called
3478 * with the termios lock held if this termios is a terminal termios
3479 * structure. May change the termios data.
3480 *
3481 * Locking: none
3482 */
3483
3484int tty_termios_baud_rate(struct termios *termios)
3485{
3486 unsigned int cbaud;
3487
3488 cbaud = termios->c_cflag & CBAUD;
3489
3490 if (cbaud & CBAUDEX) {
3491 cbaud &= ~CBAUDEX;
3492
3493 if (cbaud < 1 || cbaud + 15 > n_baud_table)
3494 termios->c_cflag &= ~CBAUDEX;
3495 else
3496 cbaud += 15;
3497 }
3498 return baud_table[cbaud];
3499}
3500
3501EXPORT_SYMBOL(tty_termios_baud_rate);
3502
3503/**
3504 * tty_get_baud_rate - get tty bit rates
3505 * @tty: tty to query
3506 *
3507 * Returns the baud rate as an integer for this terminal. The
3508 * termios lock must be held by the caller and the terminal bit
3509 * flags may be updated.
3510 *
3511 * Locking: none
3512 */
3513
3514int tty_get_baud_rate(struct tty_struct *tty)
3515{
3516 int baud = tty_termios_baud_rate(tty->termios);
3517
3518 if (baud == 38400 && tty->alt_speed) {
3519 if (!tty->warned) {
3520 printk(KERN_WARNING "Use of setserial/setrocket to "
3521 "set SPD_* flags is deprecated\n");
3522 tty->warned = 1;
3523 }
3524 baud = tty->alt_speed;
3525 }
3526
3527 return baud;
3528}
3529
3530EXPORT_SYMBOL(tty_get_baud_rate);
3531
3532/** 3478/**
3533 * tty_flip_buffer_push - terminal 3479 * tty_flip_buffer_push - terminal
3534 * @tty: tty to push 3480 * @tty: tty to push
@@ -3551,7 +3497,7 @@ void tty_flip_buffer_push(struct tty_struct *tty)
3551 spin_unlock_irqrestore(&tty->buf.lock, flags); 3497 spin_unlock_irqrestore(&tty->buf.lock, flags);
3552 3498
3553 if (tty->low_latency) 3499 if (tty->low_latency)
3554 flush_to_ldisc((void *) tty); 3500 flush_to_ldisc(&tty->buf.work.work);
3555 else 3501 else
3556 schedule_delayed_work(&tty->buf.work, 1); 3502 schedule_delayed_work(&tty->buf.work, 1);
3557} 3503}
@@ -3578,17 +3524,17 @@ static void initialize_tty_struct(struct tty_struct *tty)
3578 tty->overrun_time = jiffies; 3524 tty->overrun_time = jiffies;
3579 tty->buf.head = tty->buf.tail = NULL; 3525 tty->buf.head = tty->buf.tail = NULL;
3580 tty_buffer_init(tty); 3526 tty_buffer_init(tty);
3581 INIT_WORK(&tty->buf.work, flush_to_ldisc, tty); 3527 INIT_DELAYED_WORK(&tty->buf.work, flush_to_ldisc);
3582 init_MUTEX(&tty->buf.pty_sem); 3528 init_MUTEX(&tty->buf.pty_sem);
3583 init_MUTEX(&tty->termios_sem); 3529 mutex_init(&tty->termios_mutex);
3584 init_waitqueue_head(&tty->write_wait); 3530 init_waitqueue_head(&tty->write_wait);
3585 init_waitqueue_head(&tty->read_wait); 3531 init_waitqueue_head(&tty->read_wait);
3586 INIT_WORK(&tty->hangup_work, do_tty_hangup, tty); 3532 INIT_WORK(&tty->hangup_work, do_tty_hangup);
3587 mutex_init(&tty->atomic_read_lock); 3533 mutex_init(&tty->atomic_read_lock);
3588 mutex_init(&tty->atomic_write_lock); 3534 mutex_init(&tty->atomic_write_lock);
3589 spin_lock_init(&tty->read_lock); 3535 spin_lock_init(&tty->read_lock);
3590 INIT_LIST_HEAD(&tty->tty_files); 3536 INIT_LIST_HEAD(&tty->tty_files);
3591 INIT_WORK(&tty->SAK_work, NULL, NULL); 3537 INIT_WORK(&tty->SAK_work, NULL);
3592} 3538}
3593 3539
3594/* 3540/*
@@ -3610,7 +3556,8 @@ static struct class *tty_class;
3610 * This field is optional, if there is no known struct device 3556 * This field is optional, if there is no known struct device
3611 * for this tty device it can be set to NULL safely. 3557 * for this tty device it can be set to NULL safely.
3612 * 3558 *
3613 * Returns a pointer to the class device (or ERR_PTR(-EFOO) on error). 3559 * Returns a pointer to the struct device for this tty device
3560 * (or ERR_PTR(-EFOO) on error).
3614 * 3561 *
3615 * This call is required to be made to register an individual tty device 3562 * This call is required to be made to register an individual tty device
3616 * if the tty driver's flags have the TTY_DRIVER_DYNAMIC_DEV bit set. If 3563 * if the tty driver's flags have the TTY_DRIVER_DYNAMIC_DEV bit set. If
@@ -3620,8 +3567,8 @@ static struct class *tty_class;
3620 * Locking: ?? 3567 * Locking: ??
3621 */ 3568 */
3622 3569
3623struct class_device *tty_register_device(struct tty_driver *driver, 3570struct device *tty_register_device(struct tty_driver *driver, unsigned index,
3624 unsigned index, struct device *device) 3571 struct device *device)
3625{ 3572{
3626 char name[64]; 3573 char name[64];
3627 dev_t dev = MKDEV(driver->major, driver->minor_start) + index; 3574 dev_t dev = MKDEV(driver->major, driver->minor_start) + index;
@@ -3637,7 +3584,7 @@ struct class_device *tty_register_device(struct tty_driver *driver,
3637 else 3584 else
3638 tty_line_name(driver, index, name); 3585 tty_line_name(driver, index, name);
3639 3586
3640 return class_device_create(tty_class, NULL, dev, device, "%s", name); 3587 return device_create(tty_class, device, dev, name);
3641} 3588}
3642 3589
3643/** 3590/**
@@ -3653,7 +3600,7 @@ struct class_device *tty_register_device(struct tty_driver *driver,
3653 3600
3654void tty_unregister_device(struct tty_driver *driver, unsigned index) 3601void tty_unregister_device(struct tty_driver *driver, unsigned index)
3655{ 3602{
3656 class_device_destroy(tty_class, MKDEV(driver->major, driver->minor_start) + index); 3603 device_destroy(tty_class, MKDEV(driver->major, driver->minor_start) + index);
3657} 3604}
3658 3605
3659EXPORT_SYMBOL(tty_register_device); 3606EXPORT_SYMBOL(tty_register_device);
@@ -3678,7 +3625,8 @@ void put_tty_driver(struct tty_driver *driver)
3678 kfree(driver); 3625 kfree(driver);
3679} 3626}
3680 3627
3681void tty_set_operations(struct tty_driver *driver, struct tty_operations *op) 3628void tty_set_operations(struct tty_driver *driver,
3629 const struct tty_operations *op)
3682{ 3630{
3683 driver->open = op->open; 3631 driver->open = op->open;
3684 driver->close = op->close; 3632 driver->close = op->close;
@@ -3749,8 +3697,8 @@ int tty_register_driver(struct tty_driver *driver)
3749 3697
3750 if (p) { 3698 if (p) {
3751 driver->ttys = (struct tty_struct **)p; 3699 driver->ttys = (struct tty_struct **)p;
3752 driver->termios = (struct termios **)(p + driver->num); 3700 driver->termios = (struct ktermios **)(p + driver->num);
3753 driver->termios_locked = (struct termios **)(p + driver->num * 2); 3701 driver->termios_locked = (struct ktermios **)(p + driver->num * 2);
3754 } else { 3702 } else {
3755 driver->ttys = NULL; 3703 driver->ttys = NULL;
3756 driver->termios = NULL; 3704 driver->termios = NULL;
@@ -3789,7 +3737,7 @@ EXPORT_SYMBOL(tty_register_driver);
3789int tty_unregister_driver(struct tty_driver *driver) 3737int tty_unregister_driver(struct tty_driver *driver)
3790{ 3738{
3791 int i; 3739 int i;
3792 struct termios *tp; 3740 struct ktermios *tp;
3793 void *p; 3741 void *p;
3794 3742
3795 if (driver->refcount) 3743 if (driver->refcount)
@@ -3827,9 +3775,52 @@ int tty_unregister_driver(struct tty_driver *driver)
3827 cdev_del(&driver->cdev); 3775 cdev_del(&driver->cdev);
3828 return 0; 3776 return 0;
3829} 3777}
3830
3831EXPORT_SYMBOL(tty_unregister_driver); 3778EXPORT_SYMBOL(tty_unregister_driver);
3832 3779
3780dev_t tty_devnum(struct tty_struct *tty)
3781{
3782 return MKDEV(tty->driver->major, tty->driver->minor_start) + tty->index;
3783}
3784EXPORT_SYMBOL(tty_devnum);
3785
3786void proc_clear_tty(struct task_struct *p)
3787{
3788 spin_lock_irq(&p->sighand->siglock);
3789 p->signal->tty = NULL;
3790 spin_unlock_irq(&p->sighand->siglock);
3791}
3792EXPORT_SYMBOL(proc_clear_tty);
3793
3794void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
3795{
3796 if (tty) {
3797 tty->session = process_session(tsk);
3798 tty->pgrp = process_group(tsk);
3799 }
3800 tsk->signal->tty = tty;
3801 tsk->signal->tty_old_pgrp = 0;
3802}
3803
3804void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
3805{
3806 spin_lock_irq(&tsk->sighand->siglock);
3807 __proc_set_tty(tsk, tty);
3808 spin_unlock_irq(&tsk->sighand->siglock);
3809}
3810
3811struct tty_struct *get_current_tty(void)
3812{
3813 struct tty_struct *tty;
3814 WARN_ON_ONCE(!mutex_is_locked(&tty_mutex));
3815 tty = current->signal->tty;
3816 /*
3817 * session->tty can be changed/cleared from under us, make sure we
3818 * issue the load. The obtained pointer, when not NULL, is valid as
3819 * long as we hold tty_mutex.
3820 */
3821 barrier();
3822 return tty;
3823}
3833 3824
3834/* 3825/*
3835 * Initialize the console device. This is called *early*, so 3826 * Initialize the console device. This is called *early*, so
@@ -3892,20 +3883,20 @@ static int __init tty_init(void)
3892 if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) || 3883 if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) ||
3893 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0) 3884 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0)
3894 panic("Couldn't register /dev/tty driver\n"); 3885 panic("Couldn't register /dev/tty driver\n");
3895 class_device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty"); 3886 device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), "tty");
3896 3887
3897 cdev_init(&console_cdev, &console_fops); 3888 cdev_init(&console_cdev, &console_fops);
3898 if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) || 3889 if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) ||
3899 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0) 3890 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0)
3900 panic("Couldn't register /dev/console driver\n"); 3891 panic("Couldn't register /dev/console driver\n");
3901 class_device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), NULL, "console"); 3892 device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), "console");
3902 3893
3903#ifdef CONFIG_UNIX98_PTYS 3894#ifdef CONFIG_UNIX98_PTYS
3904 cdev_init(&ptmx_cdev, &ptmx_fops); 3895 cdev_init(&ptmx_cdev, &ptmx_fops);
3905 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) || 3896 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
3906 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0) 3897 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
3907 panic("Couldn't register /dev/ptmx driver\n"); 3898 panic("Couldn't register /dev/ptmx driver\n");
3908 class_device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx"); 3899 device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), "ptmx");
3909#endif 3900#endif
3910 3901
3911#ifdef CONFIG_VT 3902#ifdef CONFIG_VT
@@ -3913,7 +3904,7 @@ static int __init tty_init(void)
3913 if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) || 3904 if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) ||
3914 register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0) 3905 register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)
3915 panic("Couldn't register /dev/tty0 driver\n"); 3906 panic("Couldn't register /dev/tty0 driver\n");
3916 class_device_create(tty_class, NULL, MKDEV(TTY_MAJOR, 0), NULL, "tty0"); 3907 device_create(tty_class, NULL, MKDEV(TTY_MAJOR, 0), "tty0");
3917 3908
3918 vty_init(); 3909 vty_init();
3919#endif 3910#endif
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index 4ad47d321bd4..dee47f40c6a3 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -20,6 +20,7 @@
20#include <linux/mm.h> 20#include <linux/mm.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/bitops.h> 22#include <linux/bitops.h>
23#include <linux/mutex.h>
23 24
24#include <asm/io.h> 25#include <asm/io.h>
25#include <asm/uaccess.h> 26#include <asm/uaccess.h>
@@ -35,6 +36,7 @@
35#define TERMIOS_FLUSH 1 36#define TERMIOS_FLUSH 1
36#define TERMIOS_WAIT 2 37#define TERMIOS_WAIT 2
37#define TERMIOS_TERMIO 4 38#define TERMIOS_TERMIO 4
39#define TERMIOS_OLD 8
38 40
39 41
40/** 42/**
@@ -83,9 +85,9 @@ stop_waiting:
83 85
84EXPORT_SYMBOL(tty_wait_until_sent); 86EXPORT_SYMBOL(tty_wait_until_sent);
85 87
86static void unset_locked_termios(struct termios *termios, 88static void unset_locked_termios(struct ktermios *termios,
87 struct termios *old, 89 struct ktermios *old,
88 struct termios *locked) 90 struct ktermios *locked)
89{ 91{
90 int i; 92 int i;
91 93
@@ -104,8 +106,204 @@ static void unset_locked_termios(struct termios *termios,
104 for (i=0; i < NCCS; i++) 106 for (i=0; i < NCCS; i++)
105 termios->c_cc[i] = locked->c_cc[i] ? 107 termios->c_cc[i] = locked->c_cc[i] ?
106 old->c_cc[i] : termios->c_cc[i]; 108 old->c_cc[i] : termios->c_cc[i];
109 /* FIXME: What should we do for i/ospeed */
107} 110}
108 111
112/*
113 * Routine which returns the baud rate of the tty
114 *
115 * Note that the baud_table needs to be kept in sync with the
116 * include/asm/termbits.h file.
117 */
118static const speed_t baud_table[] = {
119 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
120 9600, 19200, 38400, 57600, 115200, 230400, 460800,
121#ifdef __sparc__
122 76800, 153600, 307200, 614400, 921600
123#else
124 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000,
125 2500000, 3000000, 3500000, 4000000
126#endif
127};
128
129#ifndef __sparc__
130static const tcflag_t baud_bits[] = {
131 B0, B50, B75, B110, B134, B150, B200, B300, B600,
132 B1200, B1800, B2400, B4800, B9600, B19200, B38400,
133 B57600, B115200, B230400, B460800, B500000, B576000,
134 B921600, B1000000, B1152000, B1500000, B2000000, B2500000,
135 B3000000, B3500000, B4000000
136};
137#else
138static const tcflag_t baud_bits[] = {
139 B0, B50, B75, B110, B134, B150, B200, B300, B600,
140 B1200, B1800, B2400, B4800, B9600, B19200, B38400,
141 B57600, B115200, B230400, B460800, B76800, B153600,
142 B307200, B614400, B921600
143};
144#endif
145
146static int n_baud_table = ARRAY_SIZE(baud_table);
147
148/**
149 * tty_termios_baud_rate
150 * @termios: termios structure
151 *
152 * Convert termios baud rate data into a speed. This should be called
153 * with the termios lock held if this termios is a terminal termios
154 * structure. May change the termios data. Device drivers can call this
155 * function but should use ->c_[io]speed directly as they are updated.
156 *
157 * Locking: none
158 */
159
160speed_t tty_termios_baud_rate(struct ktermios *termios)
161{
162 unsigned int cbaud;
163
164 cbaud = termios->c_cflag & CBAUD;
165
166#ifdef BOTHER
167 /* Magic token for arbitary speed via c_ispeed/c_ospeed */
168 if (cbaud == BOTHER)
169 return termios->c_ospeed;
170#endif
171 if (cbaud & CBAUDEX) {
172 cbaud &= ~CBAUDEX;
173
174 if (cbaud < 1 || cbaud + 15 > n_baud_table)
175 termios->c_cflag &= ~CBAUDEX;
176 else
177 cbaud += 15;
178 }
179 return baud_table[cbaud];
180}
181
182EXPORT_SYMBOL(tty_termios_baud_rate);
183
184/**
185 * tty_termios_input_baud_rate
186 * @termios: termios structure
187 *
188 * Convert termios baud rate data into a speed. This should be called
189 * with the termios lock held if this termios is a terminal termios
190 * structure. May change the termios data. Device drivers can call this
191 * function but should use ->c_[io]speed directly as they are updated.
192 *
193 * Locking: none
194 */
195
196speed_t tty_termios_input_baud_rate(struct ktermios *termios)
197{
198#ifdef IBSHIFT
199 unsigned int cbaud = (termios->c_cflag >> IBSHIFT) & CBAUD;
200
201 if (cbaud == B0)
202 return tty_termios_baud_rate(termios);
203
204 /* Magic token for arbitary speed via c_ispeed*/
205 if (cbaud == BOTHER)
206 return termios->c_ispeed;
207
208 if (cbaud & CBAUDEX) {
209 cbaud &= ~CBAUDEX;
210
211 if (cbaud < 1 || cbaud + 15 > n_baud_table)
212 termios->c_cflag &= ~(CBAUDEX << IBSHIFT);
213 else
214 cbaud += 15;
215 }
216 return baud_table[cbaud];
217#else
218 return tty_termios_baud_rate(termios);
219#endif
220}
221
222EXPORT_SYMBOL(tty_termios_input_baud_rate);
223
224#ifdef BOTHER
225
226/**
227 * tty_termios_encode_baud_rate
228 * @termios: termios structure
229 * @ispeed: input speed
230 * @ospeed: output speed
231 *
232 * Encode the speeds set into the passed termios structure. This is
233 * used as a library helper for drivers os that they can report back
234 * the actual speed selected when it differs from the speed requested
235 *
236 * For now input and output speed must agree.
237 *
238 * Locking: Caller should hold termios lock. This is already held
239 * when calling this function from the driver termios handler.
240 */
241
242void tty_termios_encode_baud_rate(struct ktermios *termios, speed_t ibaud, speed_t obaud)
243{
244 int i = 0;
245 int ifound = 0, ofound = 0;
246
247 termios->c_ispeed = ibaud;
248 termios->c_ospeed = obaud;
249
250 termios->c_cflag &= ~CBAUD;
251 /* Identical speed means no input encoding (ie B0 << IBSHIFT)*/
252 if (termios->c_ispeed == termios->c_ospeed)
253 ifound = 1;
254
255 do {
256 if (obaud == baud_table[i]) {
257 termios->c_cflag |= baud_bits[i];
258 ofound = 1;
259 /* So that if ibaud == obaud we don't set it */
260 continue;
261 }
262 if (ibaud == baud_table[i]) {
263 termios->c_cflag |= (baud_bits[i] << IBSHIFT);
264 ifound = 1;
265 }
266 }
267 while(++i < n_baud_table);
268 if (!ofound)
269 termios->c_cflag |= BOTHER;
270 if (!ifound)
271 termios->c_cflag |= (BOTHER << IBSHIFT);
272}
273
274EXPORT_SYMBOL_GPL(tty_termios_encode_baud_rate);
275
276#endif
277
278/**
279 * tty_get_baud_rate - get tty bit rates
280 * @tty: tty to query
281 *
282 * Returns the baud rate as an integer for this terminal. The
283 * termios lock must be held by the caller and the terminal bit
284 * flags may be updated.
285 *
286 * Locking: none
287 */
288
289speed_t tty_get_baud_rate(struct tty_struct *tty)
290{
291 speed_t baud = tty_termios_baud_rate(tty->termios);
292
293 if (baud == 38400 && tty->alt_speed) {
294 if (!tty->warned) {
295 printk(KERN_WARNING "Use of setserial/setrocket to "
296 "set SPD_* flags is deprecated\n");
297 tty->warned = 1;
298 }
299 baud = tty->alt_speed;
300 }
301
302 return baud;
303}
304
305EXPORT_SYMBOL(tty_get_baud_rate);
306
109/** 307/**
110 * change_termios - update termios values 308 * change_termios - update termios values
111 * @tty: tty to update 309 * @tty: tty to update
@@ -118,10 +316,10 @@ static void unset_locked_termios(struct termios *termios,
118 * Locking: termios_sem 316 * Locking: termios_sem
119 */ 317 */
120 318
121static void change_termios(struct tty_struct * tty, struct termios * new_termios) 319static void change_termios(struct tty_struct * tty, struct ktermios * new_termios)
122{ 320{
123 int canon_change; 321 int canon_change;
124 struct termios old_termios = *tty->termios; 322 struct ktermios old_termios = *tty->termios;
125 struct tty_ldisc *ld; 323 struct tty_ldisc *ld;
126 324
127 /* 325 /*
@@ -131,7 +329,7 @@ static void change_termios(struct tty_struct * tty, struct termios * new_termios
131 329
132 /* FIXME: we need to decide on some locking/ordering semantics 330 /* FIXME: we need to decide on some locking/ordering semantics
133 for the set_termios notification eventually */ 331 for the set_termios notification eventually */
134 down(&tty->termios_sem); 332 mutex_lock(&tty->termios_mutex);
135 333
136 *tty->termios = *new_termios; 334 *tty->termios = *new_termios;
137 unset_locked_termios(tty->termios, &old_termios, tty->termios_locked); 335 unset_locked_termios(tty->termios, &old_termios, tty->termios_locked);
@@ -176,7 +374,7 @@ static void change_termios(struct tty_struct * tty, struct termios * new_termios
176 (ld->set_termios)(tty, &old_termios); 374 (ld->set_termios)(tty, &old_termios);
177 tty_ldisc_deref(ld); 375 tty_ldisc_deref(ld);
178 } 376 }
179 up(&tty->termios_sem); 377 mutex_unlock(&tty->termios_mutex);
180} 378}
181 379
182/** 380/**
@@ -194,23 +392,39 @@ static void change_termios(struct tty_struct * tty, struct termios * new_termios
194 392
195static int set_termios(struct tty_struct * tty, void __user *arg, int opt) 393static int set_termios(struct tty_struct * tty, void __user *arg, int opt)
196{ 394{
197 struct termios tmp_termios; 395 struct ktermios tmp_termios;
198 struct tty_ldisc *ld; 396 struct tty_ldisc *ld;
199 int retval = tty_check_change(tty); 397 int retval = tty_check_change(tty);
200 398
201 if (retval) 399 if (retval)
202 return retval; 400 return retval;
203 401
402 memcpy(&tmp_termios, tty->termios, sizeof(struct ktermios));
403
204 if (opt & TERMIOS_TERMIO) { 404 if (opt & TERMIOS_TERMIO) {
205 memcpy(&tmp_termios, tty->termios, sizeof(struct termios));
206 if (user_termio_to_kernel_termios(&tmp_termios, 405 if (user_termio_to_kernel_termios(&tmp_termios,
207 (struct termio __user *)arg)) 406 (struct termio __user *)arg))
208 return -EFAULT; 407 return -EFAULT;
408#ifdef TCGETS2
409 } else if (opt & TERMIOS_OLD) {
410 if (user_termios_to_kernel_termios_1(&tmp_termios,
411 (struct termios __user *)arg))
412 return -EFAULT;
209 } else { 413 } else {
210 if (user_termios_to_kernel_termios(&tmp_termios, 414 if (user_termios_to_kernel_termios(&tmp_termios,
211 (struct termios __user *)arg)) 415 (struct termios2 __user *)arg))
212 return -EFAULT; 416 return -EFAULT;
213 } 417 }
418#else
419 } else if (user_termios_to_kernel_termios(&tmp_termios,
420 (struct termios __user *)arg))
421 return -EFAULT;
422#endif
423
424 /* If old style Bfoo values are used then load c_ispeed/c_ospeed with the real speed
425 so its unconditionally usable */
426 tmp_termios.c_ispeed = tty_termios_input_baud_rate(&tmp_termios);
427 tmp_termios.c_ospeed = tty_termios_baud_rate(&tmp_termios);
214 428
215 ld = tty_ldisc_ref(tty); 429 ld = tty_ldisc_ref(tty);
216 430
@@ -284,18 +498,18 @@ static int get_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
284{ 498{
285 struct sgttyb tmp; 499 struct sgttyb tmp;
286 500
287 down(&tty->termios_sem); 501 mutex_lock(&tty->termios_mutex);
288 tmp.sg_ispeed = 0; 502 tmp.sg_ispeed = tty->termios->c_ispeed;
289 tmp.sg_ospeed = 0; 503 tmp.sg_ospeed = tty->termios->c_ospeed;
290 tmp.sg_erase = tty->termios->c_cc[VERASE]; 504 tmp.sg_erase = tty->termios->c_cc[VERASE];
291 tmp.sg_kill = tty->termios->c_cc[VKILL]; 505 tmp.sg_kill = tty->termios->c_cc[VKILL];
292 tmp.sg_flags = get_sgflags(tty); 506 tmp.sg_flags = get_sgflags(tty);
293 up(&tty->termios_sem); 507 mutex_unlock(&tty->termios_mutex);
294 508
295 return copy_to_user(sgttyb, &tmp, sizeof(tmp)) ? -EFAULT : 0; 509 return copy_to_user(sgttyb, &tmp, sizeof(tmp)) ? -EFAULT : 0;
296} 510}
297 511
298static void set_sgflags(struct termios * termios, int flags) 512static void set_sgflags(struct ktermios * termios, int flags)
299{ 513{
300 termios->c_iflag = ICRNL | IXON; 514 termios->c_iflag = ICRNL | IXON;
301 termios->c_oflag = 0; 515 termios->c_oflag = 0;
@@ -336,7 +550,7 @@ static int set_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
336{ 550{
337 int retval; 551 int retval;
338 struct sgttyb tmp; 552 struct sgttyb tmp;
339 struct termios termios; 553 struct ktermios termios;
340 554
341 retval = tty_check_change(tty); 555 retval = tty_check_change(tty);
342 if (retval) 556 if (retval)
@@ -345,12 +559,16 @@ static int set_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
345 if (copy_from_user(&tmp, sgttyb, sizeof(tmp))) 559 if (copy_from_user(&tmp, sgttyb, sizeof(tmp)))
346 return -EFAULT; 560 return -EFAULT;
347 561
348 down(&tty->termios_sem); 562 mutex_lock(&tty->termios_mutex);
349 termios = *tty->termios; 563 termios = *tty->termios;
350 termios.c_cc[VERASE] = tmp.sg_erase; 564 termios.c_cc[VERASE] = tmp.sg_erase;
351 termios.c_cc[VKILL] = tmp.sg_kill; 565 termios.c_cc[VKILL] = tmp.sg_kill;
352 set_sgflags(&termios, tmp.sg_flags); 566 set_sgflags(&termios, tmp.sg_flags);
353 up(&tty->termios_sem); 567 /* Try and encode into Bfoo format */
568#ifdef BOTHER
569 tty_termios_encode_baud_rate(&termios, termios.c_ispeed, termios.c_ospeed);
570#endif
571 mutex_unlock(&tty->termios_mutex);
354 change_termios(tty, &termios); 572 change_termios(tty, &termios);
355 return 0; 573 return 0;
356} 574}
@@ -422,24 +640,28 @@ static int set_ltchars(struct tty_struct * tty, struct ltchars __user * ltchars)
422 * 640 *
423 * Send a high priority character to the tty even if stopped 641 * Send a high priority character to the tty even if stopped
424 * 642 *
425 * Locking: none 643 * Locking: none for xchar method, write ordering for write method.
426 *
427 * FIXME: overlapping calls with start/stop tty lose state of tty
428 */ 644 */
429 645
430static void send_prio_char(struct tty_struct *tty, char ch) 646static int send_prio_char(struct tty_struct *tty, char ch)
431{ 647{
432 int was_stopped = tty->stopped; 648 int was_stopped = tty->stopped;
433 649
434 if (tty->driver->send_xchar) { 650 if (tty->driver->send_xchar) {
435 tty->driver->send_xchar(tty, ch); 651 tty->driver->send_xchar(tty, ch);
436 return; 652 return 0;
437 } 653 }
654
655 if (mutex_lock_interruptible(&tty->atomic_write_lock))
656 return -ERESTARTSYS;
657
438 if (was_stopped) 658 if (was_stopped)
439 start_tty(tty); 659 start_tty(tty);
440 tty->driver->write(tty, &ch, 1); 660 tty->driver->write(tty, &ch, 1);
441 if (was_stopped) 661 if (was_stopped)
442 stop_tty(tty); 662 stop_tty(tty);
663 mutex_unlock(&tty->atomic_write_lock);
664 return 0;
443} 665}
444 666
445int n_tty_ioctl(struct tty_struct * tty, struct file * file, 667int n_tty_ioctl(struct tty_struct * tty, struct file * file,
@@ -476,16 +698,33 @@ int n_tty_ioctl(struct tty_struct * tty, struct file * file,
476 case TIOCSLTC: 698 case TIOCSLTC:
477 return set_ltchars(real_tty, p); 699 return set_ltchars(real_tty, p);
478#endif 700#endif
701 case TCSETSF:
702 return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT | TERMIOS_OLD);
703 case TCSETSW:
704 return set_termios(real_tty, p, TERMIOS_WAIT | TERMIOS_OLD);
705 case TCSETS:
706 return set_termios(real_tty, p, TERMIOS_OLD);
707#ifndef TCGETS2
479 case TCGETS: 708 case TCGETS:
480 if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios)) 709 if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios))
481 return -EFAULT; 710 return -EFAULT;
482 return 0; 711 return 0;
483 case TCSETSF: 712#else
713 case TCGETS:
714 if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios))
715 return -EFAULT;
716 return 0;
717 case TCGETS2:
718 if (kernel_termios_to_user_termios((struct termios2 __user *)arg, real_tty->termios))
719 return -EFAULT;
720 return 0;
721 case TCSETSF2:
484 return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT); 722 return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT);
485 case TCSETSW: 723 case TCSETSW2:
486 return set_termios(real_tty, p, TERMIOS_WAIT); 724 return set_termios(real_tty, p, TERMIOS_WAIT);
487 case TCSETS: 725 case TCSETS2:
488 return set_termios(real_tty, p, 0); 726 return set_termios(real_tty, p, 0);
727#endif
489 case TCGETA: 728 case TCGETA:
490 return get_termio(real_tty, p); 729 return get_termio(real_tty, p);
491 case TCSETAF: 730 case TCSETAF:
@@ -513,11 +752,11 @@ int n_tty_ioctl(struct tty_struct * tty, struct file * file,
513 break; 752 break;
514 case TCIOFF: 753 case TCIOFF:
515 if (STOP_CHAR(tty) != __DISABLED_CHAR) 754 if (STOP_CHAR(tty) != __DISABLED_CHAR)
516 send_prio_char(tty, STOP_CHAR(tty)); 755 return send_prio_char(tty, STOP_CHAR(tty));
517 break; 756 break;
518 case TCION: 757 case TCION:
519 if (START_CHAR(tty) != __DISABLED_CHAR) 758 if (START_CHAR(tty) != __DISABLED_CHAR)
520 send_prio_char(tty, START_CHAR(tty)); 759 return send_prio_char(tty, START_CHAR(tty));
521 break; 760 break;
522 default: 761 default:
523 return -EINVAL; 762 return -EINVAL;
@@ -592,11 +831,11 @@ int n_tty_ioctl(struct tty_struct * tty, struct file * file,
592 case TIOCSSOFTCAR: 831 case TIOCSSOFTCAR:
593 if (get_user(arg, (unsigned int __user *) arg)) 832 if (get_user(arg, (unsigned int __user *) arg))
594 return -EFAULT; 833 return -EFAULT;
595 down(&tty->termios_sem); 834 mutex_lock(&tty->termios_mutex);
596 tty->termios->c_cflag = 835 tty->termios->c_cflag =
597 ((tty->termios->c_cflag & ~CLOCAL) | 836 ((tty->termios->c_cflag & ~CLOCAL) |
598 (arg ? CLOCAL : 0)); 837 (arg ? CLOCAL : 0));
599 up(&tty->termios_sem); 838 mutex_unlock(&tty->termios_mutex);
600 return 0; 839 return 0;
601 default: 840 default:
602 return -ENOIOCTLCMD; 841 return -ENOIOCTLCMD;
diff --git a/drivers/char/vc_screen.c b/drivers/char/vc_screen.c
index a9247b5213d5..26776517f04c 100644
--- a/drivers/char/vc_screen.c
+++ b/drivers/char/vc_screen.c
@@ -72,7 +72,7 @@ static loff_t vcs_lseek(struct file *file, loff_t offset, int orig)
72 int size; 72 int size;
73 73
74 down(&con_buf_sem); 74 down(&con_buf_sem);
75 size = vcs_size(file->f_dentry->d_inode); 75 size = vcs_size(file->f_path.dentry->d_inode);
76 switch (orig) { 76 switch (orig) {
77 default: 77 default:
78 up(&con_buf_sem); 78 up(&con_buf_sem);
@@ -98,7 +98,7 @@ static loff_t vcs_lseek(struct file *file, loff_t offset, int orig)
98static ssize_t 98static ssize_t
99vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) 99vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
100{ 100{
101 struct inode *inode = file->f_dentry->d_inode; 101 struct inode *inode = file->f_path.dentry->d_inode;
102 unsigned int currcons = iminor(inode); 102 unsigned int currcons = iminor(inode);
103 struct vc_data *vc; 103 struct vc_data *vc;
104 long pos; 104 long pos;
@@ -271,7 +271,7 @@ unlock_out:
271static ssize_t 271static ssize_t
272vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) 272vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
273{ 273{
274 struct inode *inode = file->f_dentry->d_inode; 274 struct inode *inode = file->f_path.dentry->d_inode;
275 unsigned int currcons = iminor(inode); 275 unsigned int currcons = iminor(inode);
276 struct vc_data *vc; 276 struct vc_data *vc;
277 long pos; 277 long pos;
@@ -474,17 +474,18 @@ static const struct file_operations vcs_fops = {
474 474
475static struct class *vc_class; 475static struct class *vc_class;
476 476
477void vcs_make_devfs(struct tty_struct *tty) 477void vcs_make_sysfs(struct tty_struct *tty)
478{ 478{
479 class_device_create(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 1), 479 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 1),
480 NULL, "vcs%u", tty->index + 1); 480 "vcs%u", tty->index + 1);
481 class_device_create(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 129), 481 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 129),
482 NULL, "vcsa%u", tty->index + 1); 482 "vcsa%u", tty->index + 1);
483} 483}
484void vcs_remove_devfs(struct tty_struct *tty) 484
485void vcs_remove_sysfs(struct tty_struct *tty)
485{ 486{
486 class_device_destroy(vc_class, MKDEV(VCS_MAJOR, tty->index + 1)); 487 device_destroy(vc_class, MKDEV(VCS_MAJOR, tty->index + 1));
487 class_device_destroy(vc_class, MKDEV(VCS_MAJOR, tty->index + 129)); 488 device_destroy(vc_class, MKDEV(VCS_MAJOR, tty->index + 129));
488} 489}
489 490
490int __init vcs_init(void) 491int __init vcs_init(void)
@@ -493,7 +494,7 @@ int __init vcs_init(void)
493 panic("unable to get major %d for vcs device", VCS_MAJOR); 494 panic("unable to get major %d for vcs device", VCS_MAJOR);
494 vc_class = class_create(THIS_MODULE, "vc"); 495 vc_class = class_create(THIS_MODULE, "vc");
495 496
496 class_device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 0), NULL, "vcs"); 497 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 0), "vcs");
497 class_device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 128), NULL, "vcsa"); 498 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 128), "vcsa");
498 return 0; 499 return 0;
499} 500}
diff --git a/drivers/char/viocons.c b/drivers/char/viocons.c
index f3efeaf2826e..6d2e314860df 100644
--- a/drivers/char/viocons.c
+++ b/drivers/char/viocons.c
@@ -947,7 +947,7 @@ static void vioHandleData(struct HvLpEvent *event)
947 */ 947 */
948 continue; 948 continue;
949 } else if (vio_sysrq_pressed) { 949 } else if (vio_sysrq_pressed) {
950 handle_sysrq(cevent->data[index], NULL, tty); 950 handle_sysrq(cevent->data[index], tty);
951 vio_sysrq_pressed = 0; 951 vio_sysrq_pressed = 0;
952 /* 952 /*
953 * continue because we don't want to add 953 * continue because we don't want to add
@@ -1047,7 +1047,7 @@ static int send_open(HvLpIndex remoteLp, void *sem)
1047 0, 0, 0, 0); 1047 0, 0, 0, 0);
1048} 1048}
1049 1049
1050static struct tty_operations serial_ops = { 1050static const struct tty_operations serial_ops = {
1051 .open = viotty_open, 1051 .open = viotty_open,
1052 .close = viotty_close, 1052 .close = viotty_close,
1053 .write = viotty_write, 1053 .write = viotty_write,
diff --git a/drivers/char/viotape.c b/drivers/char/viotape.c
index 73c78bf75d7f..94d79cb8ce8d 100644
--- a/drivers/char/viotape.c
+++ b/drivers/char/viotape.c
@@ -442,7 +442,7 @@ static ssize_t viotap_write(struct file *file, const char *buf,
442 if (op == NULL) 442 if (op == NULL)
443 return -ENOMEM; 443 return -ENOMEM;
444 444
445 get_dev_info(file->f_dentry->d_inode, &devi); 445 get_dev_info(file->f_path.dentry->d_inode, &devi);
446 446
447 /* 447 /*
448 * We need to make sure we can send a request. We use 448 * We need to make sure we can send a request. We use
@@ -532,7 +532,7 @@ static ssize_t viotap_read(struct file *file, char *buf, size_t count,
532 if (op == NULL) 532 if (op == NULL)
533 return -ENOMEM; 533 return -ENOMEM;
534 534
535 get_dev_info(file->f_dentry->d_inode, &devi); 535 get_dev_info(file->f_path.dentry->d_inode, &devi);
536 536
537 /* 537 /*
538 * We need to make sure we can send a request. We use 538 * We need to make sure we can send a request. We use
@@ -612,7 +612,7 @@ static int viotap_ioctl(struct inode *inode, struct file *file,
612 if (op == NULL) 612 if (op == NULL)
613 return -ENOMEM; 613 return -ENOMEM;
614 614
615 get_dev_info(file->f_dentry->d_inode, &devi); 615 get_dev_info(file->f_path.dentry->d_inode, &devi);
616 616
617 down(&reqSem); 617 down(&reqSem);
618 618
@@ -777,7 +777,7 @@ static int viotap_open(struct inode *inode, struct file *file)
777 if (op == NULL) 777 if (op == NULL)
778 return -ENOMEM; 778 return -ENOMEM;
779 779
780 get_dev_info(file->f_dentry->d_inode, &devi); 780 get_dev_info(file->f_path.dentry->d_inode, &devi);
781 781
782 /* Note: We currently only support one mode! */ 782 /* Note: We currently only support one mode! */
783 if ((devi.devno >= viotape_numdev) || (devi.mode)) { 783 if ((devi.devno >= viotape_numdev) || (devi.mode)) {
@@ -822,7 +822,7 @@ static int viotap_release(struct inode *inode, struct file *file)
822 return -ENOMEM; 822 return -ENOMEM;
823 init_completion(&op->com); 823 init_completion(&op->com);
824 824
825 get_dev_info(file->f_dentry->d_inode, &devi); 825 get_dev_info(file->f_path.dentry->d_inode, &devi);
826 826
827 if (devi.devno >= viotape_numdev) { 827 if (devi.devno >= viotape_numdev) {
828 ret = -ENODEV; 828 ret = -ENODEV;
diff --git a/drivers/char/vme_scc.c b/drivers/char/vme_scc.c
index bfe5ea948f6a..e01317cb1a0e 100644
--- a/drivers/char/vme_scc.c
+++ b/drivers/char/vme_scc.c
@@ -81,10 +81,10 @@ static int scc_ioctl(struct tty_struct * tty, struct file * filp,
81 unsigned int cmd, unsigned long arg); 81 unsigned int cmd, unsigned long arg);
82static void scc_throttle(struct tty_struct *tty); 82static void scc_throttle(struct tty_struct *tty);
83static void scc_unthrottle(struct tty_struct *tty); 83static void scc_unthrottle(struct tty_struct *tty);
84static irqreturn_t scc_tx_int(int irq, void *data, struct pt_regs *fp); 84static irqreturn_t scc_tx_int(int irq, void *data);
85static irqreturn_t scc_rx_int(int irq, void *data, struct pt_regs *fp); 85static irqreturn_t scc_rx_int(int irq, void *data);
86static irqreturn_t scc_stat_int(int irq, void *data, struct pt_regs *fp); 86static irqreturn_t scc_stat_int(int irq, void *data);
87static irqreturn_t scc_spcond_int(int irq, void *data, struct pt_regs *fp); 87static irqreturn_t scc_spcond_int(int irq, void *data);
88static void scc_setsignals(struct scc_port *port, int dtr, int rts); 88static void scc_setsignals(struct scc_port *port, int dtr, int rts);
89static void scc_break_ctl(struct tty_struct *tty, int break_state); 89static void scc_break_ctl(struct tty_struct *tty, int break_state);
90 90
@@ -113,7 +113,7 @@ static struct real_driver scc_real_driver = {
113}; 113};
114 114
115 115
116static struct tty_operations scc_ops = { 116static const struct tty_operations scc_ops = {
117 .open = scc_open, 117 .open = scc_open,
118 .close = gs_close, 118 .close = gs_close,
119 .write = gs_write, 119 .write = gs_write,
@@ -153,6 +153,8 @@ static int scc_init_drivers(void)
153 scc_driver->init_termios = tty_std_termios; 153 scc_driver->init_termios = tty_std_termios;
154 scc_driver->init_termios.c_cflag = 154 scc_driver->init_termios.c_cflag =
155 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 155 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
156 scc_driver->init_termios.c_ispeed = 9600;
157 scc_driver->init_termios.c_ospeed = 9600;
156 scc_driver->flags = TTY_DRIVER_REAL_RAW; 158 scc_driver->flags = TTY_DRIVER_REAL_RAW;
157 tty_set_operations(scc_driver, &scc_ops); 159 tty_set_operations(scc_driver, &scc_ops);
158 160
@@ -419,7 +421,7 @@ module_init(vme_scc_init);
419 * Interrupt handlers 421 * Interrupt handlers
420 *--------------------------------------------------------------------------*/ 422 *--------------------------------------------------------------------------*/
421 423
422static irqreturn_t scc_rx_int(int irq, void *data, struct pt_regs *fp) 424static irqreturn_t scc_rx_int(int irq, void *data)
423{ 425{
424 unsigned char ch; 426 unsigned char ch;
425 struct scc_port *port = data; 427 struct scc_port *port = data;
@@ -440,7 +442,7 @@ static irqreturn_t scc_rx_int(int irq, void *data, struct pt_regs *fp)
440 */ 442 */
441 if (SCCread(INT_PENDING_REG) & 443 if (SCCread(INT_PENDING_REG) &
442 (port->channel == CHANNEL_A ? IPR_A_RX : IPR_B_RX)) { 444 (port->channel == CHANNEL_A ? IPR_A_RX : IPR_B_RX)) {
443 scc_spcond_int (irq, data, fp); 445 scc_spcond_int (irq, data);
444 return IRQ_HANDLED; 446 return IRQ_HANDLED;
445 } 447 }
446 448
@@ -451,7 +453,7 @@ static irqreturn_t scc_rx_int(int irq, void *data, struct pt_regs *fp)
451} 453}
452 454
453 455
454static irqreturn_t scc_spcond_int(int irq, void *data, struct pt_regs *fp) 456static irqreturn_t scc_spcond_int(int irq, void *data)
455{ 457{
456 struct scc_port *port = data; 458 struct scc_port *port = data;
457 struct tty_struct *tty = port->gs.tty; 459 struct tty_struct *tty = port->gs.tty;
@@ -496,7 +498,7 @@ static irqreturn_t scc_spcond_int(int irq, void *data, struct pt_regs *fp)
496} 498}
497 499
498 500
499static irqreturn_t scc_tx_int(int irq, void *data, struct pt_regs *fp) 501static irqreturn_t scc_tx_int(int irq, void *data)
500{ 502{
501 struct scc_port *port = data; 503 struct scc_port *port = data;
502 SCC_ACCESS_INIT(port); 504 SCC_ACCESS_INIT(port);
@@ -538,7 +540,7 @@ static irqreturn_t scc_tx_int(int irq, void *data, struct pt_regs *fp)
538} 540}
539 541
540 542
541static irqreturn_t scc_stat_int(int irq, void *data, struct pt_regs *fp) 543static irqreturn_t scc_stat_int(int irq, void *data)
542{ 544{
543 struct scc_port *port = data; 545 struct scc_port *port = data;
544 unsigned channel = port->channel; 546 unsigned channel = port->channel;
@@ -593,7 +595,7 @@ static void scc_enable_tx_interrupts(void *ptr)
593 local_irq_save(flags); 595 local_irq_save(flags);
594 SCCmod(INT_AND_DMA_REG, 0xff, IDR_TX_INT_ENAB); 596 SCCmod(INT_AND_DMA_REG, 0xff, IDR_TX_INT_ENAB);
595 /* restart the transmitter */ 597 /* restart the transmitter */
596 scc_tx_int (0, port, 0); 598 scc_tx_int (0, port);
597 local_irq_restore(flags); 599 local_irq_restore(flags);
598} 600}
599 601
diff --git a/drivers/char/vr41xx_giu.c b/drivers/char/vr41xx_giu.c
index 8116a47b80f4..a744dad9cf45 100644
--- a/drivers/char/vr41xx_giu.c
+++ b/drivers/char/vr41xx_giu.c
@@ -221,7 +221,7 @@ static struct hw_interrupt_type giuint_high_irq_type = {
221 .end = end_giuint_high_irq, 221 .end = end_giuint_high_irq,
222}; 222};
223 223
224static int giu_get_irq(unsigned int irq, struct pt_regs *regs) 224static int giu_get_irq(unsigned int irq)
225{ 225{
226 uint16_t pendl, pendh, maskl, maskh; 226 uint16_t pendl, pendh, maskl, maskh;
227 int i; 227 int i;
@@ -506,7 +506,7 @@ static ssize_t gpio_read(struct file *file, char __user *buf, size_t len,
506 unsigned int pin; 506 unsigned int pin;
507 char value = '0'; 507 char value = '0';
508 508
509 pin = iminor(file->f_dentry->d_inode); 509 pin = iminor(file->f_path.dentry->d_inode);
510 if (pin >= giu_nr_pins) 510 if (pin >= giu_nr_pins)
511 return -EBADF; 511 return -EBADF;
512 512
@@ -530,7 +530,7 @@ static ssize_t gpio_write(struct file *file, const char __user *data,
530 char c; 530 char c;
531 int retval = 0; 531 int retval = 0;
532 532
533 pin = iminor(file->f_dentry->d_inode); 533 pin = iminor(file->f_path.dentry->d_inode);
534 if (pin >= giu_nr_pins) 534 if (pin >= giu_nr_pins)
535 return -EBADF; 535 return -EBADF;
536 536
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index da7e66a2a38b..a8239dac994f 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -63,6 +63,13 @@
63 * 63 *
64 * Removed console_lock, enabled interrupts across all console operations 64 * Removed console_lock, enabled interrupts across all console operations
65 * 13 March 2001, Andrew Morton 65 * 13 March 2001, Andrew Morton
66 *
67 * Fixed UTF-8 mode so alternate charset modes always work according
68 * to control sequences interpreted in do_con_trol function
69 * preserving backward VT100 semigraphics compatibility,
70 * malformed UTF sequences represented as sequences of replacement glyphs,
71 * original codes or '?' as a last resort if replacement glyph is undefined
72 * by Adam Tla/lka <atlka@pg.gda.pl>, Aug 2006
66 */ 73 */
67 74
68#include <linux/module.h> 75#include <linux/module.h>
@@ -99,12 +106,13 @@
99#define MAX_NR_CON_DRIVER 16 106#define MAX_NR_CON_DRIVER 16
100 107
101#define CON_DRIVER_FLAG_MODULE 1 108#define CON_DRIVER_FLAG_MODULE 1
102#define CON_DRIVER_FLAG_INIT 2 109#define CON_DRIVER_FLAG_INIT 2
110#define CON_DRIVER_FLAG_ATTR 4
103 111
104struct con_driver { 112struct con_driver {
105 const struct consw *con; 113 const struct consw *con;
106 const char *desc; 114 const char *desc;
107 struct class_device *class_dev; 115 struct device *dev;
108 int node; 116 int node;
109 int first; 117 int first;
110 int last; 118 int last;
@@ -128,16 +136,8 @@ const struct consw *conswitchp;
128#define DEFAULT_BELL_PITCH 750 136#define DEFAULT_BELL_PITCH 750
129#define DEFAULT_BELL_DURATION (HZ/8) 137#define DEFAULT_BELL_DURATION (HZ/8)
130 138
131extern void vcs_make_devfs(struct tty_struct *tty); 139extern void vcs_make_sysfs(struct tty_struct *tty);
132extern void vcs_remove_devfs(struct tty_struct *tty); 140extern void vcs_remove_sysfs(struct tty_struct *tty);
133
134extern void console_map_init(void);
135#ifdef CONFIG_PROM_CONSOLE
136extern void prom_con_init(void);
137#endif
138#ifdef CONFIG_MDA_CONSOLE
139extern int mda_console_init(void);
140#endif
141 141
142struct vc vc_cons [MAX_NR_CONSOLES]; 142struct vc vc_cons [MAX_NR_CONSOLES];
143 143
@@ -152,10 +152,10 @@ static void gotoxy(struct vc_data *vc, int new_x, int new_y);
152static void save_cur(struct vc_data *vc); 152static void save_cur(struct vc_data *vc);
153static void reset_terminal(struct vc_data *vc, int do_clear); 153static void reset_terminal(struct vc_data *vc, int do_clear);
154static void con_flush_chars(struct tty_struct *tty); 154static void con_flush_chars(struct tty_struct *tty);
155static void set_vesa_blanking(char __user *p); 155static int set_vesa_blanking(char __user *p);
156static void set_cursor(struct vc_data *vc); 156static void set_cursor(struct vc_data *vc);
157static void hide_cursor(struct vc_data *vc); 157static void hide_cursor(struct vc_data *vc);
158static void console_callback(void *ignored); 158static void console_callback(struct work_struct *ignored);
159static void blank_screen_t(unsigned long dummy); 159static void blank_screen_t(unsigned long dummy);
160static void set_palette(struct vc_data *vc); 160static void set_palette(struct vc_data *vc);
161 161
@@ -174,7 +174,7 @@ static int vesa_blank_mode; /* 0:none 1:suspendV 2:suspendH 3:powerdown */
174static int blankinterval = 10*60*HZ; 174static int blankinterval = 10*60*HZ;
175static int vesa_off_interval; 175static int vesa_off_interval;
176 176
177static DECLARE_WORK(console_work, console_callback, NULL); 177static DECLARE_WORK(console_work, console_callback);
178 178
179/* 179/*
180 * fg_console is the current virtual console, 180 * fg_console is the current virtual console,
@@ -730,7 +730,8 @@ int vc_allocate(unsigned int currcons) /* return 0 on success */
730 visual_init(vc, currcons, 1); 730 visual_init(vc, currcons, 1);
731 if (!*vc->vc_uni_pagedir_loc) 731 if (!*vc->vc_uni_pagedir_loc)
732 con_set_default_unimap(vc); 732 con_set_default_unimap(vc);
733 vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL); 733 if (!vc->vc_kmalloced)
734 vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL);
734 if (!vc->vc_screenbuf) { 735 if (!vc->vc_screenbuf) {
735 kfree(vc); 736 kfree(vc);
736 vc_cons[currcons].d = NULL; 737 vc_cons[currcons].d = NULL;
@@ -878,14 +879,24 @@ int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines)
878 return err; 879 return err;
879} 880}
880 881
882int vc_lock_resize(struct vc_data *vc, unsigned int cols, unsigned int lines)
883{
884 int rc;
885
886 acquire_console_sem();
887 rc = vc_resize(vc, cols, lines);
888 release_console_sem();
889 return rc;
890}
881 891
882void vc_disallocate(unsigned int currcons) 892void vc_deallocate(unsigned int currcons)
883{ 893{
884 WARN_CONSOLE_UNLOCKED(); 894 WARN_CONSOLE_UNLOCKED();
885 895
886 if (vc_cons_allocated(currcons)) { 896 if (vc_cons_allocated(currcons)) {
887 struct vc_data *vc = vc_cons[currcons].d; 897 struct vc_data *vc = vc_cons[currcons].d;
888 vc->vc_sw->con_deinit(vc); 898 vc->vc_sw->con_deinit(vc);
899 put_pid(vc->vt_pid);
889 module_put(vc->vc_sw->owner); 900 module_put(vc->vc_sw->owner);
890 if (vc->vc_kmalloced) 901 if (vc->vc_kmalloced)
891 kfree(vc->vc_screenbuf); 902 kfree(vc->vc_screenbuf);
@@ -2005,17 +2016,23 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
2005 /* Do no translation at all in control states */ 2016 /* Do no translation at all in control states */
2006 if (vc->vc_state != ESnormal) { 2017 if (vc->vc_state != ESnormal) {
2007 tc = c; 2018 tc = c;
2008 } else if (vc->vc_utf) { 2019 } else if (vc->vc_utf && !vc->vc_disp_ctrl) {
2009 /* Combine UTF-8 into Unicode */ 2020 /* Combine UTF-8 into Unicode */
2010 /* Incomplete characters silently ignored */ 2021 /* Malformed sequences as sequences of replacement glyphs */
2022rescan_last_byte:
2011 if(c > 0x7f) { 2023 if(c > 0x7f) {
2012 if (vc->vc_utf_count > 0 && (c & 0xc0) == 0x80) { 2024 if (vc->vc_utf_count) {
2013 vc->vc_utf_char = (vc->vc_utf_char << 6) | (c & 0x3f); 2025 if ((c & 0xc0) == 0x80) {
2014 vc->vc_utf_count--; 2026 vc->vc_utf_char = (vc->vc_utf_char << 6) | (c & 0x3f);
2015 if (vc->vc_utf_count == 0) 2027 if (--vc->vc_utf_count) {
2016 tc = c = vc->vc_utf_char; 2028 vc->vc_npar++;
2017 else continue; 2029 continue;
2030 }
2031 tc = c = vc->vc_utf_char;
2032 } else
2033 goto replacement_glyph;
2018 } else { 2034 } else {
2035 vc->vc_npar = 0;
2019 if ((c & 0xe0) == 0xc0) { 2036 if ((c & 0xe0) == 0xc0) {
2020 vc->vc_utf_count = 1; 2037 vc->vc_utf_count = 1;
2021 vc->vc_utf_char = (c & 0x1f); 2038 vc->vc_utf_char = (c & 0x1f);
@@ -2032,14 +2049,15 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
2032 vc->vc_utf_count = 5; 2049 vc->vc_utf_count = 5;
2033 vc->vc_utf_char = (c & 0x01); 2050 vc->vc_utf_char = (c & 0x01);
2034 } else 2051 } else
2035 vc->vc_utf_count = 0; 2052 goto replacement_glyph;
2036 continue; 2053 continue;
2037 } 2054 }
2038 } else { 2055 } else {
2056 if (vc->vc_utf_count)
2057 goto replacement_glyph;
2039 tc = c; 2058 tc = c;
2040 vc->vc_utf_count = 0;
2041 } 2059 }
2042 } else { /* no utf */ 2060 } else { /* no utf or alternate charset mode */
2043 tc = vc->vc_translate[vc->vc_toggle_meta ? (c | 0x80) : c]; 2061 tc = vc->vc_translate[vc->vc_toggle_meta ? (c | 0x80) : c];
2044 } 2062 }
2045 2063
@@ -2054,31 +2072,33 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
2054 * direct-to-font zone in UTF-8 mode. 2072 * direct-to-font zone in UTF-8 mode.
2055 */ 2073 */
2056 ok = tc && (c >= 32 || 2074 ok = tc && (c >= 32 ||
2057 (!vc->vc_utf && !(((vc->vc_disp_ctrl ? CTRL_ALWAYS 2075 !(vc->vc_disp_ctrl ? (CTRL_ALWAYS >> c) & 1 :
2058 : CTRL_ACTION) >> c) & 1))) 2076 vc->vc_utf || ((CTRL_ACTION >> c) & 1)))
2059 && (c != 127 || vc->vc_disp_ctrl) 2077 && (c != 127 || vc->vc_disp_ctrl)
2060 && (c != 128+27); 2078 && (c != 128+27);
2061 2079
2062 if (vc->vc_state == ESnormal && ok) { 2080 if (vc->vc_state == ESnormal && ok) {
2063 /* Now try to find out how to display it */ 2081 /* Now try to find out how to display it */
2064 tc = conv_uni_to_pc(vc, tc); 2082 tc = conv_uni_to_pc(vc, tc);
2065 if ( tc == -4 ) { 2083 if (tc & ~charmask) {
2084 if ( tc == -4 ) {
2066 /* If we got -4 (not found) then see if we have 2085 /* If we got -4 (not found) then see if we have
2067 defined a replacement character (U+FFFD) */ 2086 defined a replacement character (U+FFFD) */
2068 tc = conv_uni_to_pc(vc, 0xfffd); 2087replacement_glyph:
2069 2088 tc = conv_uni_to_pc(vc, 0xfffd);
2070 /* One reason for the -4 can be that we just 2089 if (!(tc & ~charmask))
2071 did a clear_unimap(); 2090 goto display_glyph;
2072 try at least to show something. */ 2091 } else if ( tc != -3 )
2073 if (tc == -4) 2092 continue; /* nothing to display */
2074 tc = c; 2093 /* no hash table or no replacement --
2075 } else if ( tc == -3 ) { 2094 * hope for the best */
2076 /* Bad hash table -- hope for the best */ 2095 if ( c & ~charmask )
2077 tc = c; 2096 tc = '?';
2078 } 2097 else
2079 if (tc & ~charmask) 2098 tc = c;
2080 continue; /* Conversion failed */ 2099 }
2081 2100
2101display_glyph:
2082 if (vc->vc_need_wrap || vc->vc_decim) 2102 if (vc->vc_need_wrap || vc->vc_decim)
2083 FLUSH 2103 FLUSH
2084 if (vc->vc_need_wrap) { 2104 if (vc->vc_need_wrap) {
@@ -2102,6 +2122,15 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
2102 vc->vc_x++; 2122 vc->vc_x++;
2103 draw_to = (vc->vc_pos += 2); 2123 draw_to = (vc->vc_pos += 2);
2104 } 2124 }
2125 if (vc->vc_utf_count) {
2126 if (vc->vc_npar) {
2127 vc->vc_npar--;
2128 goto display_glyph;
2129 }
2130 vc->vc_utf_count = 0;
2131 c = orig;
2132 goto rescan_last_byte;
2133 }
2105 continue; 2134 continue;
2106 } 2135 }
2107 FLUSH 2136 FLUSH
@@ -2125,7 +2154,7 @@ out:
2125 * with other console code and prevention of re-entrancy is 2154 * with other console code and prevention of re-entrancy is
2126 * ensured with console_sem. 2155 * ensured with console_sem.
2127 */ 2156 */
2128static void console_callback(void *ignored) 2157static void console_callback(struct work_struct *ignored)
2129{ 2158{
2130 acquire_console_sem(); 2159 acquire_console_sem();
2131 2160
@@ -2340,7 +2369,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2340 ret = __put_user(data, p); 2369 ret = __put_user(data, p);
2341 break; 2370 break;
2342 case TIOCL_SETVESABLANK: 2371 case TIOCL_SETVESABLANK:
2343 set_vesa_blanking(p); 2372 ret = set_vesa_blanking(p);
2344 break; 2373 break;
2345 case TIOCL_GETKMSGREDIRECT: 2374 case TIOCL_GETKMSGREDIRECT:
2346 data = kmsg_redirect; 2375 data = kmsg_redirect;
@@ -2498,7 +2527,7 @@ static int con_open(struct tty_struct *tty, struct file *filp)
2498 tty->winsize.ws_col = vc_cons[currcons].d->vc_cols; 2527 tty->winsize.ws_col = vc_cons[currcons].d->vc_cols;
2499 } 2528 }
2500 release_console_sem(); 2529 release_console_sem();
2501 vcs_make_devfs(tty); 2530 vcs_make_sysfs(tty);
2502 return ret; 2531 return ret;
2503 } 2532 }
2504 } 2533 }
@@ -2511,7 +2540,7 @@ static int con_open(struct tty_struct *tty, struct file *filp)
2511 * and taking a ref against the tty while we're in the process of forgetting 2540 * and taking a ref against the tty while we're in the process of forgetting
2512 * about it and cleaning things up. 2541 * about it and cleaning things up.
2513 * 2542 *
2514 * This is because vcs_remove_devfs() can sleep and will drop the BKL. 2543 * This is because vcs_remove_sysfs() can sleep and will drop the BKL.
2515 */ 2544 */
2516static void con_close(struct tty_struct *tty, struct file *filp) 2545static void con_close(struct tty_struct *tty, struct file *filp)
2517{ 2546{
@@ -2524,7 +2553,7 @@ static void con_close(struct tty_struct *tty, struct file *filp)
2524 vc->vc_tty = NULL; 2553 vc->vc_tty = NULL;
2525 tty->driver_data = NULL; 2554 tty->driver_data = NULL;
2526 release_console_sem(); 2555 release_console_sem();
2527 vcs_remove_devfs(tty); 2556 vcs_remove_sysfs(tty);
2528 mutex_unlock(&tty_mutex); 2557 mutex_unlock(&tty_mutex);
2529 /* 2558 /*
2530 * tty_mutex is released, but we still hold BKL, so there is 2559 * tty_mutex is released, but we still hold BKL, so there is
@@ -2639,7 +2668,7 @@ static int __init con_init(void)
2639} 2668}
2640console_initcall(con_init); 2669console_initcall(con_init);
2641 2670
2642static struct tty_operations con_ops = { 2671static const struct tty_operations con_ops = {
2643 .open = con_open, 2672 .open = con_open,
2644 .close = con_close, 2673 .close = con_close,
2645 .write = con_write, 2674 .write = con_write,
@@ -2994,10 +3023,10 @@ static inline int vt_unbind(struct con_driver *con)
2994} 3023}
2995#endif /* CONFIG_VT_HW_CONSOLE_BINDING */ 3024#endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2996 3025
2997static ssize_t store_bind(struct class_device *class_device, 3026static ssize_t store_bind(struct device *dev, struct device_attribute *attr,
2998 const char *buf, size_t count) 3027 const char *buf, size_t count)
2999{ 3028{
3000 struct con_driver *con = class_get_devdata(class_device); 3029 struct con_driver *con = dev_get_drvdata(dev);
3001 int bind = simple_strtoul(buf, NULL, 0); 3030 int bind = simple_strtoul(buf, NULL, 0);
3002 3031
3003 if (bind) 3032 if (bind)
@@ -3008,17 +3037,19 @@ static ssize_t store_bind(struct class_device *class_device,
3008 return count; 3037 return count;
3009} 3038}
3010 3039
3011static ssize_t show_bind(struct class_device *class_device, char *buf) 3040static ssize_t show_bind(struct device *dev, struct device_attribute *attr,
3041 char *buf)
3012{ 3042{
3013 struct con_driver *con = class_get_devdata(class_device); 3043 struct con_driver *con = dev_get_drvdata(dev);
3014 int bind = con_is_bound(con->con); 3044 int bind = con_is_bound(con->con);
3015 3045
3016 return snprintf(buf, PAGE_SIZE, "%i\n", bind); 3046 return snprintf(buf, PAGE_SIZE, "%i\n", bind);
3017} 3047}
3018 3048
3019static ssize_t show_name(struct class_device *class_device, char *buf) 3049static ssize_t show_name(struct device *dev, struct device_attribute *attr,
3050 char *buf)
3020{ 3051{
3021 struct con_driver *con = class_get_devdata(class_device); 3052 struct con_driver *con = dev_get_drvdata(dev);
3022 3053
3023 return snprintf(buf, PAGE_SIZE, "%s %s\n", 3054 return snprintf(buf, PAGE_SIZE, "%s %s\n",
3024 (con->flag & CON_DRIVER_FLAG_MODULE) ? "(M)" : "(S)", 3055 (con->flag & CON_DRIVER_FLAG_MODULE) ? "(M)" : "(S)",
@@ -3026,30 +3057,42 @@ static ssize_t show_name(struct class_device *class_device, char *buf)
3026 3057
3027} 3058}
3028 3059
3029static struct class_device_attribute class_device_attrs[] = { 3060static struct device_attribute device_attrs[] = {
3030 __ATTR(bind, S_IRUGO|S_IWUSR, show_bind, store_bind), 3061 __ATTR(bind, S_IRUGO|S_IWUSR, show_bind, store_bind),
3031 __ATTR(name, S_IRUGO, show_name, NULL), 3062 __ATTR(name, S_IRUGO, show_name, NULL),
3032}; 3063};
3033 3064
3034static int vtconsole_init_class_device(struct con_driver *con) 3065static int vtconsole_init_device(struct con_driver *con)
3035{ 3066{
3036 int i; 3067 int i;
3068 int error = 0;
3037 3069
3038 class_set_devdata(con->class_dev, con); 3070 con->flag |= CON_DRIVER_FLAG_ATTR;
3039 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) 3071 dev_set_drvdata(con->dev, con);
3040 class_device_create_file(con->class_dev, 3072 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3041 &class_device_attrs[i]); 3073 error = device_create_file(con->dev, &device_attrs[i]);
3074 if (error)
3075 break;
3076 }
3042 3077
3043 return 0; 3078 if (error) {
3079 while (--i >= 0)
3080 device_remove_file(con->dev, &device_attrs[i]);
3081 con->flag &= ~CON_DRIVER_FLAG_ATTR;
3082 }
3083
3084 return error;
3044} 3085}
3045 3086
3046static void vtconsole_deinit_class_device(struct con_driver *con) 3087static void vtconsole_deinit_device(struct con_driver *con)
3047{ 3088{
3048 int i; 3089 int i;
3049 3090
3050 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) 3091 if (con->flag & CON_DRIVER_FLAG_ATTR) {
3051 class_device_remove_file(con->class_dev, 3092 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3052 &class_device_attrs[i]); 3093 device_remove_file(con->dev, &device_attrs[i]);
3094 con->flag &= ~CON_DRIVER_FLAG_ATTR;
3095 }
3053} 3096}
3054 3097
3055/** 3098/**
@@ -3135,19 +3178,19 @@ int register_con_driver(const struct consw *csw, int first, int last)
3135 if (retval) 3178 if (retval)
3136 goto err; 3179 goto err;
3137 3180
3138 con_driver->class_dev = class_device_create(vtconsole_class, NULL, 3181 con_driver->dev = device_create(vtconsole_class, NULL,
3139 MKDEV(0, con_driver->node), 3182 MKDEV(0, con_driver->node),
3140 NULL, "vtcon%i", 3183 "vtcon%i", con_driver->node);
3141 con_driver->node);
3142 3184
3143 if (IS_ERR(con_driver->class_dev)) { 3185 if (IS_ERR(con_driver->dev)) {
3144 printk(KERN_WARNING "Unable to create class_device for %s; " 3186 printk(KERN_WARNING "Unable to create device for %s; "
3145 "errno = %ld\n", con_driver->desc, 3187 "errno = %ld\n", con_driver->desc,
3146 PTR_ERR(con_driver->class_dev)); 3188 PTR_ERR(con_driver->dev));
3147 con_driver->class_dev = NULL; 3189 con_driver->dev = NULL;
3148 } else { 3190 } else {
3149 vtconsole_init_class_device(con_driver); 3191 vtconsole_init_device(con_driver);
3150 } 3192 }
3193
3151err: 3194err:
3152 release_console_sem(); 3195 release_console_sem();
3153 module_put(owner); 3196 module_put(owner);
@@ -3181,12 +3224,12 @@ int unregister_con_driver(const struct consw *csw)
3181 3224
3182 if (con_driver->con == csw && 3225 if (con_driver->con == csw &&
3183 con_driver->flag & CON_DRIVER_FLAG_MODULE) { 3226 con_driver->flag & CON_DRIVER_FLAG_MODULE) {
3184 vtconsole_deinit_class_device(con_driver); 3227 vtconsole_deinit_device(con_driver);
3185 class_device_destroy(vtconsole_class, 3228 device_destroy(vtconsole_class,
3186 MKDEV(0, con_driver->node)); 3229 MKDEV(0, con_driver->node));
3187 con_driver->con = NULL; 3230 con_driver->con = NULL;
3188 con_driver->desc = NULL; 3231 con_driver->desc = NULL;
3189 con_driver->class_dev = NULL; 3232 con_driver->dev = NULL;
3190 con_driver->node = 0; 3233 con_driver->node = 0;
3191 con_driver->flag = 0; 3234 con_driver->flag = 0;
3192 con_driver->first = 0; 3235 con_driver->first = 0;
@@ -3244,19 +3287,18 @@ static int __init vtconsole_class_init(void)
3244 for (i = 0; i < MAX_NR_CON_DRIVER; i++) { 3287 for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
3245 struct con_driver *con = &registered_con_driver[i]; 3288 struct con_driver *con = &registered_con_driver[i];
3246 3289
3247 if (con->con && !con->class_dev) { 3290 if (con->con && !con->dev) {
3248 con->class_dev = 3291 con->dev = device_create(vtconsole_class, NULL,
3249 class_device_create(vtconsole_class, NULL, 3292 MKDEV(0, con->node),
3250 MKDEV(0, con->node), NULL, 3293 "vtcon%i", con->node);
3251 "vtcon%i", con->node);
3252 3294
3253 if (IS_ERR(con->class_dev)) { 3295 if (IS_ERR(con->dev)) {
3254 printk(KERN_WARNING "Unable to create " 3296 printk(KERN_WARNING "Unable to create "
3255 "class_device for %s; errno = %ld\n", 3297 "device for %s; errno = %ld\n",
3256 con->desc, PTR_ERR(con->class_dev)); 3298 con->desc, PTR_ERR(con->dev));
3257 con->class_dev = NULL; 3299 con->dev = NULL;
3258 } else { 3300 } else {
3259 vtconsole_init_class_device(con); 3301 vtconsole_init_device(con);
3260 } 3302 }
3261 } 3303 }
3262 } 3304 }
@@ -3271,11 +3313,15 @@ postcore_initcall(vtconsole_class_init);
3271 * Screen blanking 3313 * Screen blanking
3272 */ 3314 */
3273 3315
3274static void set_vesa_blanking(char __user *p) 3316static int set_vesa_blanking(char __user *p)
3275{ 3317{
3276 unsigned int mode; 3318 unsigned int mode;
3277 get_user(mode, p + 1); 3319
3278 vesa_blank_mode = (mode < 4) ? mode : 0; 3320 if (get_user(mode, p + 1))
3321 return -EFAULT;
3322
3323 vesa_blank_mode = (mode < 4) ? mode : 0;
3324 return 0;
3279} 3325}
3280 3326
3281void do_blank_screen(int entering_gfx) 3327void do_blank_screen(int entering_gfx)
@@ -3765,6 +3811,7 @@ EXPORT_SYMBOL(default_blu);
3765EXPORT_SYMBOL(update_region); 3811EXPORT_SYMBOL(update_region);
3766EXPORT_SYMBOL(redraw_screen); 3812EXPORT_SYMBOL(redraw_screen);
3767EXPORT_SYMBOL(vc_resize); 3813EXPORT_SYMBOL(vc_resize);
3814EXPORT_SYMBOL(vc_lock_resize);
3768EXPORT_SYMBOL(fg_console); 3815EXPORT_SYMBOL(fg_console);
3769EXPORT_SYMBOL(console_blank_hook); 3816EXPORT_SYMBOL(console_blank_hook);
3770EXPORT_SYMBOL(console_blanked); 3817EXPORT_SYMBOL(console_blanked);
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index a5628a8b6620..ac5d60edbafa 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -96,7 +96,7 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
96 if (!perm) 96 if (!perm)
97 return -EPERM; 97 return -EPERM;
98 if (!i && v == K_NOSUCHMAP) { 98 if (!i && v == K_NOSUCHMAP) {
99 /* disallocate map */ 99 /* deallocate map */
100 key_map = key_maps[s]; 100 key_map = key_maps[s];
101 if (s && key_map) { 101 if (s && key_map) {
102 key_maps[s] = NULL; 102 key_maps[s] = NULL;
@@ -645,13 +645,16 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
645 */ 645 */
646 case KDSIGACCEPT: 646 case KDSIGACCEPT:
647 { 647 {
648 extern int spawnpid, spawnsig;
649 if (!perm || !capable(CAP_KILL)) 648 if (!perm || !capable(CAP_KILL))
650 return -EPERM; 649 return -EPERM;
651 if (!valid_signal(arg) || arg < 1 || arg == SIGKILL) 650 if (!valid_signal(arg) || arg < 1 || arg == SIGKILL)
652 return -EINVAL; 651 return -EINVAL;
653 spawnpid = current->pid; 652
654 spawnsig = arg; 653 spin_lock_irq(&vt_spawn_con.lock);
654 put_pid(vt_spawn_con.pid);
655 vt_spawn_con.pid = get_pid(task_pid(current));
656 vt_spawn_con.sig = arg;
657 spin_unlock_irq(&vt_spawn_con.lock);
655 return 0; 658 return 0;
656 } 659 }
657 660
@@ -669,7 +672,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
669 vc->vt_mode = tmp; 672 vc->vt_mode = tmp;
670 /* the frsig is ignored, so we set it to 0 */ 673 /* the frsig is ignored, so we set it to 0 */
671 vc->vt_mode.frsig = 0; 674 vc->vt_mode.frsig = 0;
672 vc->vt_pid = current->pid; 675 put_pid(xchg(&vc->vt_pid, get_pid(task_pid(current))));
673 /* no switch is required -- saw@shade.msu.ru */ 676 /* no switch is required -- saw@shade.msu.ru */
674 vc->vt_newvt = -1; 677 vc->vt_newvt = -1;
675 release_console_sem(); 678 release_console_sem();
@@ -819,20 +822,20 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
819 if (arg > MAX_NR_CONSOLES) 822 if (arg > MAX_NR_CONSOLES)
820 return -ENXIO; 823 return -ENXIO;
821 if (arg == 0) { 824 if (arg == 0) {
822 /* disallocate all unused consoles, but leave 0 */ 825 /* deallocate all unused consoles, but leave 0 */
823 acquire_console_sem(); 826 acquire_console_sem();
824 for (i=1; i<MAX_NR_CONSOLES; i++) 827 for (i=1; i<MAX_NR_CONSOLES; i++)
825 if (! VT_BUSY(i)) 828 if (! VT_BUSY(i))
826 vc_disallocate(i); 829 vc_deallocate(i);
827 release_console_sem(); 830 release_console_sem();
828 } else { 831 } else {
829 /* disallocate a single console, if possible */ 832 /* deallocate a single console, if possible */
830 arg--; 833 arg--;
831 if (VT_BUSY(arg)) 834 if (VT_BUSY(arg))
832 return -EBUSY; 835 return -EBUSY;
833 if (arg) { /* leave 0 */ 836 if (arg) { /* leave 0 */
834 acquire_console_sem(); 837 acquire_console_sem();
835 vc_disallocate(arg); 838 vc_deallocate(arg);
836 release_console_sem(); 839 release_console_sem();
837 } 840 }
838 } 841 }
@@ -847,11 +850,8 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
847 if (get_user(ll, &vtsizes->v_rows) || 850 if (get_user(ll, &vtsizes->v_rows) ||
848 get_user(cc, &vtsizes->v_cols)) 851 get_user(cc, &vtsizes->v_cols))
849 return -EFAULT; 852 return -EFAULT;
850 for (i = 0; i < MAX_NR_CONSOLES; i++) { 853 for (i = 0; i < MAX_NR_CONSOLES; i++)
851 acquire_console_sem(); 854 vc_lock_resize(vc_cons[i].d, cc, ll);
852 vc_resize(vc_cons[i].d, cc, ll);
853 release_console_sem();
854 }
855 return 0; 855 return 0;
856 } 856 }
857 857
@@ -1063,7 +1063,7 @@ void reset_vc(struct vc_data *vc)
1063 vc->vt_mode.relsig = 0; 1063 vc->vt_mode.relsig = 0;
1064 vc->vt_mode.acqsig = 0; 1064 vc->vt_mode.acqsig = 0;
1065 vc->vt_mode.frsig = 0; 1065 vc->vt_mode.frsig = 0;
1066 vc->vt_pid = -1; 1066 put_pid(xchg(&vc->vt_pid, NULL));
1067 vc->vt_newvt = -1; 1067 vc->vt_newvt = -1;
1068 if (!in_interrupt()) /* Via keyboard.c:SAK() - akpm */ 1068 if (!in_interrupt()) /* Via keyboard.c:SAK() - akpm */
1069 reset_palette(vc); 1069 reset_palette(vc);
@@ -1114,7 +1114,7 @@ static void complete_change_console(struct vc_data *vc)
1114 * tell us if the process has gone or something else 1114 * tell us if the process has gone or something else
1115 * is awry 1115 * is awry
1116 */ 1116 */
1117 if (kill_proc(vc->vt_pid, vc->vt_mode.acqsig, 1) != 0) { 1117 if (kill_pid(vc->vt_pid, vc->vt_mode.acqsig, 1) != 0) {
1118 /* 1118 /*
1119 * The controlling process has died, so we revert back to 1119 * The controlling process has died, so we revert back to
1120 * normal operation. In this case, we'll also change back 1120 * normal operation. In this case, we'll also change back
@@ -1174,7 +1174,7 @@ void change_console(struct vc_data *new_vc)
1174 * tell us if the process has gone or something else 1174 * tell us if the process has gone or something else
1175 * is awry 1175 * is awry
1176 */ 1176 */
1177 if (kill_proc(vc->vt_pid, vc->vt_mode.relsig, 1) == 0) { 1177 if (kill_pid(vc->vt_pid, vc->vt_mode.relsig, 1) == 0) {
1178 /* 1178 /*
1179 * It worked. Mark the vt to switch to and 1179 * It worked. Mark the vt to switch to and
1180 * return. The process needs to send us a 1180 * return. The process needs to send us a
diff --git a/drivers/char/watchdog/Kconfig b/drivers/char/watchdog/Kconfig
index fff89c2d88fd..ea09d0c974ea 100644
--- a/drivers/char/watchdog/Kconfig
+++ b/drivers/char/watchdog/Kconfig
@@ -13,7 +13,7 @@ config WATCHDOG
13 subsequently opening the file and then failing to write to it for 13 subsequently opening the file and then failing to write to it for
14 longer than 1 minute will result in rebooting the machine. This 14 longer than 1 minute will result in rebooting the machine. This
15 could be useful for a networked machine that needs to come back 15 could be useful for a networked machine that needs to come back
16 online as fast as possible after a lock-up. There's both a watchdog 16 on-line as fast as possible after a lock-up. There's both a watchdog
17 implementation entirely in software (which can sometimes fail to 17 implementation entirely in software (which can sometimes fail to
18 reboot the machine) and a driver for hardware watchdog boards, which 18 reboot the machine) and a driver for hardware watchdog boards, which
19 are more robust and can also keep track of the temperature inside 19 are more robust and can also keep track of the temperature inside
@@ -60,7 +60,7 @@ config SOFT_WATCHDOG
60 60
61# ARM Architecture 61# ARM Architecture
62 62
63config AT91_WATCHDOG 63config AT91RM9200_WATCHDOG
64 tristate "AT91RM9200 watchdog" 64 tristate "AT91RM9200 watchdog"
65 depends on WATCHDOG && ARCH_AT91RM9200 65 depends on WATCHDOG && ARCH_AT91RM9200
66 help 66 help
@@ -71,7 +71,7 @@ config 21285_WATCHDOG
71 tristate "DC21285 watchdog" 71 tristate "DC21285 watchdog"
72 depends on WATCHDOG && FOOTBRIDGE 72 depends on WATCHDOG && FOOTBRIDGE
73 help 73 help
74 The Intel Footbridge chip contains a builtin watchdog circuit. Say Y 74 The Intel Footbridge chip contains a built-in watchdog circuit. Say Y
75 here if you wish to use this. Alternatively say M to compile the 75 here if you wish to use this. Alternatively say M to compile the
76 driver as a module, which will be called wdt285. 76 driver as a module, which will be called wdt285.
77 77
@@ -165,6 +165,24 @@ config EP93XX_WATCHDOG
165 To compile this driver as a module, choose M here: the 165 To compile this driver as a module, choose M here: the
166 module will be called ep93xx_wdt. 166 module will be called ep93xx_wdt.
167 167
168config OMAP_WATCHDOG
169 tristate "OMAP Watchdog"
170 depends on WATCHDOG && (ARCH_OMAP16XX || ARCH_OMAP24XX)
171 help
172 Support for TI OMAP1610/OMAP1710/OMAP2420 watchdog. Say 'Y' here to
173 enable the OMAP1610/OMAP1710 watchdog timer.
174
175config PNX4008_WATCHDOG
176 tristate "PNX4008 Watchdog"
177 depends on WATCHDOG && ARCH_PNX4008
178 help
179 Say Y here if to include support for the watchdog timer
180 in the PNX4008 processor.
181 This driver can be built as a module by choosing M. The module
182 will be called pnx4008_wdt.
183
184 Say N if you are unsure.
185
168# X86 (i386 + ia64 + x86_64) Architecture 186# X86 (i386 + ia64 + x86_64) Architecture
169 187
170config ACQUIRE_WDT 188config ACQUIRE_WDT
@@ -251,11 +269,11 @@ config IB700_WDT
251 Most people will say N. 269 Most people will say N.
252 270
253config IBMASR 271config IBMASR
254 tristate "IBM Automatic Server Restart" 272 tristate "IBM Automatic Server Restart"
255 depends on WATCHDOG && X86 273 depends on WATCHDOG && X86
256 help 274 help
257 This is the driver for the IBM Automatic Server Restart watchdog 275 This is the driver for the IBM Automatic Server Restart watchdog
258 timer builtin into some eServer xSeries machines. 276 timer built-in into some eServer xSeries machines.
259 277
260 To compile this driver as a module, choose M here: the 278 To compile this driver as a module, choose M here: the
261 module will be called ibmasr. 279 module will be called ibmasr.
@@ -298,6 +316,38 @@ config I8XX_TCO
298 To compile this driver as a module, choose M here: the 316 To compile this driver as a module, choose M here: the
299 module will be called i8xx_tco. 317 module will be called i8xx_tco.
300 318
319 Note: This driver will be removed in the near future. Please
320 use the Intel TCO Timer/Watchdog driver.
321
322config ITCO_WDT
323 tristate "Intel TCO Timer/Watchdog"
324 depends on WATCHDOG && (X86 || IA64) && PCI
325 ---help---
326 Hardware driver for the intel TCO timer based watchdog devices.
327 These drivers are included in the Intel 82801 I/O Controller
328 Hub family (from ICH0 up to ICH8) and in the Intel 6300ESB
329 controller hub.
330
331 The TCO (Total Cost of Ownership) timer is a watchdog timer
332 that will reboot the machine after its second expiration. The
333 expiration time can be configured with the "heartbeat" parameter.
334
335 On some motherboards the driver may fail to reset the chipset's
336 NO_REBOOT flag which prevents the watchdog from rebooting the
337 machine. If this is the case you will get a kernel message like
338 "failed to reset NO_REBOOT flag, reboot disabled by hardware".
339
340 To compile this driver as a module, choose M here: the
341 module will be called iTCO_wdt.
342
343config ITCO_VENDOR_SUPPORT
344 bool "Intel TCO Timer/Watchdog Specific Vendor Support"
345 depends on ITCO_WDT
346 ---help---
347 Add vendor specific support to the intel TCO timer based watchdog
348 devices. At this moment we only have additional support for some
349 SuperMicro Inc. motherboards.
350
301config SC1200_WDT 351config SC1200_WDT
302 tristate "National Semiconductor PC87307/PC97307 (ala SC1200) Watchdog" 352 tristate "National Semiconductor PC87307/PC97307 (ala SC1200) Watchdog"
303 depends on WATCHDOG && X86 353 depends on WATCHDOG && X86
@@ -321,6 +371,20 @@ config SCx200_WDT
321 371
322 If compiled as a module, it will be called scx200_wdt. 372 If compiled as a module, it will be called scx200_wdt.
323 373
374config PC87413_WDT
375 tristate "NS PC87413 watchdog"
376 depends on WATCHDOG && X86
377 ---help---
378 This is the driver for the hardware watchdog on the PC87413 chipset
379 This watchdog simply watches your kernel to make sure it doesn't
380 freeze, and if it does, it reboots your computer after a certain
381 amount of time.
382
383 To compile this driver as a module, choose M here: the
384 module will be called pc87413_wdt.
385
386 Most people will say N.
387
324config 60XX_WDT 388config 60XX_WDT
325 tristate "SBC-60XX Watchdog Timer" 389 tristate "SBC-60XX Watchdog Timer"
326 depends on WATCHDOG && X86 390 depends on WATCHDOG && X86
@@ -356,6 +420,26 @@ config CPU5_WDT
356 To compile this driver as a module, choose M here: the 420 To compile this driver as a module, choose M here: the
357 module will be called cpu5wdt. 421 module will be called cpu5wdt.
358 422
423config SMSC37B787_WDT
424 tristate "Winbond SMsC37B787 Watchdog Timer"
425 depends on WATCHDOG && X86
426 ---help---
427 This is the driver for the hardware watchdog component on the
428 Winbond SMsC37B787 chipset as used on the NetRunner Mainboard
429 from Vision Systems and maybe others.
430
431 This watchdog simply watches your kernel to make sure it doesn't
432 freeze, and if it does, it reboots your computer after a certain
433 amount of time.
434
435 Usually a userspace daemon will notify the kernel WDT driver that
436 userspace is still alive, at regular intervals.
437
438 To compile this driver as a module, choose M here: the
439 module will be called smsc37b787_wdt.
440
441 Most people will say N.
442
359config W83627HF_WDT 443config W83627HF_WDT
360 tristate "W83627HF Watchdog Timer" 444 tristate "W83627HF Watchdog Timer"
361 depends on WATCHDOG && X86 445 depends on WATCHDOG && X86
@@ -371,6 +455,21 @@ config W83627HF_WDT
371 455
372 Most people will say N. 456 Most people will say N.
373 457
458config W83697HF_WDT
459 tristate "W83697HF/W83697HG Watchdog Timer"
460 depends on WATCHDOG && X86
461 ---help---
462 This is the driver for the hardware watchdog on the W83697HF/HG
463 chipset as used in Dedibox/VIA motherboards (and likely others).
464 This watchdog simply watches your kernel to make sure it doesn't
465 freeze, and if it does, it reboots your computer after a certain
466 amount of time.
467
468 To compile this driver as a module, choose M here: the
469 module will be called w83697hf_wdt.
470
471 Most people will say N.
472
374config W83877F_WDT 473config W83877F_WDT
375 tristate "W83877F (EMACS) Watchdog Timer" 474 tristate "W83877F (EMACS) Watchdog Timer"
376 depends on WATCHDOG && X86 475 depends on WATCHDOG && X86
@@ -404,7 +503,7 @@ config MACHZ_WDT
404 depends on WATCHDOG && X86 503 depends on WATCHDOG && X86
405 ---help--- 504 ---help---
406 If you are using a ZF Micro MachZ processor, say Y here, otherwise 505 If you are using a ZF Micro MachZ processor, say Y here, otherwise
407 N. This is the driver for the watchdog timer builtin on that 506 N. This is the driver for the watchdog timer built-in on that
408 processor using ZF-Logic interface. This watchdog simply watches 507 processor using ZF-Logic interface. This watchdog simply watches
409 your kernel to make sure it doesn't freeze, and if it does, it 508 your kernel to make sure it doesn't freeze, and if it does, it
410 reboots your computer after a certain amount of time. 509 reboots your computer after a certain amount of time.
@@ -433,7 +532,6 @@ config SBC_EPX_C3_WATCHDOG
433 To compile this driver as a module, choose M here: the 532 To compile this driver as a module, choose M here: the
434 module will be called sbc_epx_c3. 533 module will be called sbc_epx_c3.
435 534
436
437# PowerPC Architecture 535# PowerPC Architecture
438 536
439config 8xx_WDT 537config 8xx_WDT
@@ -463,7 +561,7 @@ config WATCHDOG_RTAS
463 help 561 help
464 This driver adds watchdog support for the RTAS watchdog. 562 This driver adds watchdog support for the RTAS watchdog.
465 563
466 To compile this driver as a module, choose M here. The module 564 To compile this driver as a module, choose M here. The module
467 will be called wdrtas. 565 will be called wdrtas.
468 566
469# MIPS Architecture 567# MIPS Architecture
@@ -477,6 +575,16 @@ config INDYDOG
477 timer expired and no process has written to /dev/watchdog during 575 timer expired and no process has written to /dev/watchdog during
478 that time. 576 that time.
479 577
578config WDT_RM9K_GPI
579 tristate "RM9000/GPI hardware watchdog"
580 depends on WATCHDOG && CPU_RM9000
581 help
582 Watchdog implementation using the GPI hardware found on
583 PMC-Sierra RM9xxx CPUs.
584
585 To compile this driver as a module, choose M here: the
586 module will be called rm9k_wdt.
587
480# S390 Architecture 588# S390 Architecture
481 589
482config ZVM_WATCHDOG 590config ZVM_WATCHDOG
@@ -510,6 +618,14 @@ config SH_WDT
510 To compile this driver as a module, choose M here: the 618 To compile this driver as a module, choose M here: the
511 module will be called shwdt. 619 module will be called shwdt.
512 620
621config SH_WDT_MMAP
622 bool "Allow mmap of SH WDT"
623 default n
624 depends on SH_WDT
625 help
626 If you say Y here, user applications will be able to mmap the
627 WDT/CPG registers.
628
513# SPARC64 Architecture 629# SPARC64 Architecture
514 630
515config WATCHDOG_CP1XXX 631config WATCHDOG_CP1XXX
diff --git a/drivers/char/watchdog/Makefile b/drivers/char/watchdog/Makefile
index 6ab77b61a643..2cd8ff8d10ac 100644
--- a/drivers/char/watchdog/Makefile
+++ b/drivers/char/watchdog/Makefile
@@ -23,7 +23,8 @@ obj-$(CONFIG_WDTPCI) += wdt_pci.o
23obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o 23obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o
24 24
25# ARM Architecture 25# ARM Architecture
26obj-$(CONFIG_AT91_WATCHDOG) += at91_wdt.o 26obj-$(CONFIG_AT91RM9200_WATCHDOG) += at91rm9200_wdt.o
27obj-$(CONFIG_OMAP_WATCHDOG) += omap_wdt.o
27obj-$(CONFIG_21285_WATCHDOG) += wdt285.o 28obj-$(CONFIG_21285_WATCHDOG) += wdt285.o
28obj-$(CONFIG_977_WATCHDOG) += wdt977.o 29obj-$(CONFIG_977_WATCHDOG) += wdt977.o
29obj-$(CONFIG_IXP2000_WATCHDOG) += ixp2000_wdt.o 30obj-$(CONFIG_IXP2000_WATCHDOG) += ixp2000_wdt.o
@@ -32,6 +33,7 @@ obj-$(CONFIG_S3C2410_WATCHDOG) += s3c2410_wdt.o
32obj-$(CONFIG_SA1100_WATCHDOG) += sa1100_wdt.o 33obj-$(CONFIG_SA1100_WATCHDOG) += sa1100_wdt.o
33obj-$(CONFIG_MPCORE_WATCHDOG) += mpcore_wdt.o 34obj-$(CONFIG_MPCORE_WATCHDOG) += mpcore_wdt.o
34obj-$(CONFIG_EP93XX_WATCHDOG) += ep93xx_wdt.o 35obj-$(CONFIG_EP93XX_WATCHDOG) += ep93xx_wdt.o
36obj-$(CONFIG_PNX4008_WATCHDOG) += pnx4008_wdt.o
35 37
36# X86 (i386 + ia64 + x86_64) Architecture 38# X86 (i386 + ia64 + x86_64) Architecture
37obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o 39obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
@@ -45,12 +47,16 @@ obj-$(CONFIG_IBMASR) += ibmasr.o
45obj-$(CONFIG_WAFER_WDT) += wafer5823wdt.o 47obj-$(CONFIG_WAFER_WDT) += wafer5823wdt.o
46obj-$(CONFIG_I6300ESB_WDT) += i6300esb.o 48obj-$(CONFIG_I6300ESB_WDT) += i6300esb.o
47obj-$(CONFIG_I8XX_TCO) += i8xx_tco.o 49obj-$(CONFIG_I8XX_TCO) += i8xx_tco.o
50obj-$(CONFIG_ITCO_WDT) += iTCO_wdt.o iTCO_vendor_support.o
48obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o 51obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o
49obj-$(CONFIG_SCx200_WDT) += scx200_wdt.o 52obj-$(CONFIG_SCx200_WDT) += scx200_wdt.o
53obj-$(CONFIG_PC87413_WDT) += pc87413_wdt.o
50obj-$(CONFIG_60XX_WDT) += sbc60xxwdt.o 54obj-$(CONFIG_60XX_WDT) += sbc60xxwdt.o
51obj-$(CONFIG_SBC8360_WDT) += sbc8360.o 55obj-$(CONFIG_SBC8360_WDT) += sbc8360.o
52obj-$(CONFIG_CPU5_WDT) += cpu5wdt.o 56obj-$(CONFIG_CPU5_WDT) += cpu5wdt.o
57obj-$(CONFIG_SMSC37B787_WDT) += smsc37b787_wdt.o
53obj-$(CONFIG_W83627HF_WDT) += w83627hf_wdt.o 58obj-$(CONFIG_W83627HF_WDT) += w83627hf_wdt.o
59obj-$(CONFIG_W83697HF_WDT) += w83697hf_wdt.o
54obj-$(CONFIG_W83877F_WDT) += w83877f_wdt.o 60obj-$(CONFIG_W83877F_WDT) += w83877f_wdt.o
55obj-$(CONFIG_W83977F_WDT) += w83977f_wdt.o 61obj-$(CONFIG_W83977F_WDT) += w83977f_wdt.o
56obj-$(CONFIG_MACHZ_WDT) += machzwd.o 62obj-$(CONFIG_MACHZ_WDT) += machzwd.o
@@ -67,6 +73,7 @@ obj-$(CONFIG_WATCHDOG_RTAS) += wdrtas.o
67 73
68# MIPS Architecture 74# MIPS Architecture
69obj-$(CONFIG_INDYDOG) += indydog.o 75obj-$(CONFIG_INDYDOG) += indydog.o
76obj-$(CONFIG_WDT_RM9K_GPI) += rm9k_wdt.o
70 77
71# S390 Architecture 78# S390 Architecture
72 79
diff --git a/drivers/char/watchdog/acquirewdt.c b/drivers/char/watchdog/acquirewdt.c
index c77fe3cf2852..154d67e591e5 100644
--- a/drivers/char/watchdog/acquirewdt.c
+++ b/drivers/char/watchdog/acquirewdt.c
@@ -183,7 +183,7 @@ static int acq_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
183 } 183 }
184 184
185 default: 185 default:
186 return -ENOIOCTLCMD; 186 return -ENOTTY;
187 } 187 }
188} 188}
189 189
diff --git a/drivers/char/watchdog/advantechwdt.c b/drivers/char/watchdog/advantechwdt.c
index 8069be445edc..9d732769ba01 100644
--- a/drivers/char/watchdog/advantechwdt.c
+++ b/drivers/char/watchdog/advantechwdt.c
@@ -176,7 +176,7 @@ advwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
176 } 176 }
177 177
178 default: 178 default:
179 return -ENOIOCTLCMD; 179 return -ENOTTY;
180 } 180 }
181 return 0; 181 return 0;
182} 182}
diff --git a/drivers/char/watchdog/alim1535_wdt.c b/drivers/char/watchdog/alim1535_wdt.c
index c5c94e4c9495..01b0d132ee41 100644
--- a/drivers/char/watchdog/alim1535_wdt.c
+++ b/drivers/char/watchdog/alim1535_wdt.c
@@ -236,7 +236,7 @@ static int ali_ioctl(struct inode *inode, struct file *file,
236 return put_user(timeout, p); 236 return put_user(timeout, p);
237 237
238 default: 238 default:
239 return -ENOIOCTLCMD; 239 return -ENOTTY;
240 } 240 }
241} 241}
242 242
@@ -330,17 +330,20 @@ static int __init ali_find_watchdog(void)
330 u32 wdog; 330 u32 wdog;
331 331
332 /* Check for a 1535 series bridge */ 332 /* Check for a 1535 series bridge */
333 pdev = pci_find_device(PCI_VENDOR_ID_AL, 0x1535, NULL); 333 pdev = pci_get_device(PCI_VENDOR_ID_AL, 0x1535, NULL);
334 if(pdev == NULL) 334 if(pdev == NULL)
335 return -ENODEV; 335 return -ENODEV;
336 pci_dev_put(pdev);
336 337
337 /* Check for the a 7101 PMU */ 338 /* Check for the a 7101 PMU */
338 pdev = pci_find_device(PCI_VENDOR_ID_AL, 0x7101, NULL); 339 pdev = pci_get_device(PCI_VENDOR_ID_AL, 0x7101, NULL);
339 if(pdev == NULL) 340 if(pdev == NULL)
340 return -ENODEV; 341 return -ENODEV;
341 342
342 if(pci_enable_device(pdev)) 343 if(pci_enable_device(pdev)) {
344 pci_dev_put(pdev);
343 return -EIO; 345 return -EIO;
346 }
344 347
345 ali_pci = pdev; 348 ali_pci = pdev;
346 349
@@ -447,6 +450,7 @@ static void __exit watchdog_exit(void)
447 /* Deregister */ 450 /* Deregister */
448 unregister_reboot_notifier(&ali_notifier); 451 unregister_reboot_notifier(&ali_notifier);
449 misc_deregister(&ali_miscdev); 452 misc_deregister(&ali_miscdev);
453 pci_dev_put(ali_pci);
450} 454}
451 455
452module_init(watchdog_init); 456module_init(watchdog_init);
diff --git a/drivers/char/watchdog/alim7101_wdt.c b/drivers/char/watchdog/alim7101_wdt.c
index ffd7684f999b..bf25d0a55a99 100644
--- a/drivers/char/watchdog/alim7101_wdt.c
+++ b/drivers/char/watchdog/alim7101_wdt.c
@@ -77,7 +77,8 @@ static struct pci_dev *alim7101_pmu;
77 77
78static int nowayout = WATCHDOG_NOWAYOUT; 78static int nowayout = WATCHDOG_NOWAYOUT;
79module_param(nowayout, int, 0); 79module_param(nowayout, int, 0);
80MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 80MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
81 __stringify(CONFIG_WATCHDOG_NOWAYOUT) ")");
81 82
82/* 83/*
83 * Whack the dog 84 * Whack the dog
@@ -277,7 +278,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u
277 case WDIOC_GETTIMEOUT: 278 case WDIOC_GETTIMEOUT:
278 return put_user(timeout, p); 279 return put_user(timeout, p);
279 default: 280 default:
280 return -ENOIOCTLCMD; 281 return -ENOTTY;
281 } 282 }
282} 283}
283 284
@@ -333,6 +334,7 @@ static void __exit alim7101_wdt_unload(void)
333 /* Deregister */ 334 /* Deregister */
334 misc_deregister(&wdt_miscdev); 335 misc_deregister(&wdt_miscdev);
335 unregister_reboot_notifier(&wdt_notifier); 336 unregister_reboot_notifier(&wdt_notifier);
337 pci_dev_put(alim7101_pmu);
336} 338}
337 339
338static int __init alim7101_wdt_init(void) 340static int __init alim7101_wdt_init(void)
@@ -342,7 +344,8 @@ static int __init alim7101_wdt_init(void)
342 char tmp; 344 char tmp;
343 345
344 printk(KERN_INFO PFX "Steve Hill <steve@navaho.co.uk>.\n"); 346 printk(KERN_INFO PFX "Steve Hill <steve@navaho.co.uk>.\n");
345 alim7101_pmu = pci_find_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101,NULL); 347 alim7101_pmu = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101,
348 NULL);
346 if (!alim7101_pmu) { 349 if (!alim7101_pmu) {
347 printk(KERN_INFO PFX "ALi M7101 PMU not present - WDT not set\n"); 350 printk(KERN_INFO PFX "ALi M7101 PMU not present - WDT not set\n");
348 return -EBUSY; 351 return -EBUSY;
@@ -351,21 +354,23 @@ static int __init alim7101_wdt_init(void)
351 /* Set the WDT in the PMU to 1 second */ 354 /* Set the WDT in the PMU to 1 second */
352 pci_write_config_byte(alim7101_pmu, ALI_7101_WDT, 0x02); 355 pci_write_config_byte(alim7101_pmu, ALI_7101_WDT, 0x02);
353 356
354 ali1543_south = pci_find_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL); 357 ali1543_south = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533,
358 NULL);
355 if (!ali1543_south) { 359 if (!ali1543_south) {
356 printk(KERN_INFO PFX "ALi 1543 South-Bridge not present - WDT not set\n"); 360 printk(KERN_INFO PFX "ALi 1543 South-Bridge not present - WDT not set\n");
357 return -EBUSY; 361 goto err_out;
358 } 362 }
359 pci_read_config_byte(ali1543_south, 0x5e, &tmp); 363 pci_read_config_byte(ali1543_south, 0x5e, &tmp);
364 pci_dev_put(ali1543_south);
360 if ((tmp & 0x1e) == 0x00) { 365 if ((tmp & 0x1e) == 0x00) {
361 if (!use_gpio) { 366 if (!use_gpio) {
362 printk(KERN_INFO PFX "Detected old alim7101 revision 'a1d'. If this is a cobalt board, set the 'use_gpio' module parameter.\n"); 367 printk(KERN_INFO PFX "Detected old alim7101 revision 'a1d'. If this is a cobalt board, set the 'use_gpio' module parameter.\n");
363 return -EBUSY; 368 goto err_out;
364 } 369 }
365 nowayout = 1; 370 nowayout = 1;
366 } else if ((tmp & 0x1e) != 0x12 && (tmp & 0x1e) != 0x00) { 371 } else if ((tmp & 0x1e) != 0x12 && (tmp & 0x1e) != 0x00) {
367 printk(KERN_INFO PFX "ALi 1543 South-Bridge does not have the correct revision number (???1001?) - WDT not set\n"); 372 printk(KERN_INFO PFX "ALi 1543 South-Bridge does not have the correct revision number (???1001?) - WDT not set\n");
368 return -EBUSY; 373 goto err_out;
369 } 374 }
370 375
371 if(timeout < 1 || timeout > 3600) /* arbitrary upper limit */ 376 if(timeout < 1 || timeout > 3600) /* arbitrary upper limit */
@@ -404,12 +409,23 @@ static int __init alim7101_wdt_init(void)
404err_out_miscdev: 409err_out_miscdev:
405 misc_deregister(&wdt_miscdev); 410 misc_deregister(&wdt_miscdev);
406err_out: 411err_out:
412 pci_dev_put(alim7101_pmu);
407 return rc; 413 return rc;
408} 414}
409 415
410module_init(alim7101_wdt_init); 416module_init(alim7101_wdt_init);
411module_exit(alim7101_wdt_unload); 417module_exit(alim7101_wdt_unload);
412 418
419static struct pci_device_id alim7101_pci_tbl[] __devinitdata = {
420 { PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533,
421 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
422 { PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101,
423 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
424 { }
425};
426
427MODULE_DEVICE_TABLE(pci, alim7101_pci_tbl);
428
413MODULE_AUTHOR("Steve Hill"); 429MODULE_AUTHOR("Steve Hill");
414MODULE_DESCRIPTION("ALi M7101 PMU Computer Watchdog Timer driver"); 430MODULE_DESCRIPTION("ALi M7101 PMU Computer Watchdog Timer driver");
415MODULE_LICENSE("GPL"); 431MODULE_LICENSE("GPL");
diff --git a/drivers/char/watchdog/at91_wdt.c b/drivers/char/watchdog/at91rm9200_wdt.c
index cc266715ea32..cb86967e2c5f 100644
--- a/drivers/char/watchdog/at91_wdt.c
+++ b/drivers/char/watchdog/at91rm9200_wdt.c
@@ -21,6 +21,7 @@
21#include <linux/watchdog.h> 21#include <linux/watchdog.h>
22#include <asm/bitops.h> 22#include <asm/bitops.h>
23#include <asm/uaccess.h> 23#include <asm/uaccess.h>
24#include <asm/arch/at91_st.h>
24 25
25 26
26#define WDT_DEFAULT_TIME 5 /* seconds */ 27#define WDT_DEFAULT_TIME 5 /* seconds */
@@ -168,7 +169,7 @@ static int at91_wdt_ioctl(struct inode *inode, struct file *file,
168 return 0; 169 return 0;
169 170
170 default: 171 default:
171 return -ENOIOCTLCMD; 172 return -ENOTTY;
172 } 173 }
173} 174}
174 175
diff --git a/drivers/char/watchdog/booke_wdt.c b/drivers/char/watchdog/booke_wdt.c
index e3cefc538b40..488902231cc2 100644
--- a/drivers/char/watchdog/booke_wdt.c
+++ b/drivers/char/watchdog/booke_wdt.c
@@ -125,7 +125,7 @@ static int booke_wdt_ioctl (struct inode *inode, struct file *file,
125 return -EINVAL; 125 return -EINVAL;
126 return 0; 126 return 0;
127 default: 127 default:
128 return -ENOIOCTLCMD; 128 return -ENOTTY;
129 } 129 }
130 130
131 return 0; 131 return 0;
diff --git a/drivers/char/watchdog/cpu5wdt.c b/drivers/char/watchdog/cpu5wdt.c
index 04c7e49918db..00bdabb90f27 100644
--- a/drivers/char/watchdog/cpu5wdt.c
+++ b/drivers/char/watchdog/cpu5wdt.c
@@ -183,7 +183,7 @@ static int cpu5wdt_ioctl(struct inode *inode, struct file *file, unsigned int cm
183 } 183 }
184 break; 184 break;
185 default: 185 default:
186 return -ENOIOCTLCMD; 186 return -ENOTTY;
187 } 187 }
188 return 0; 188 return 0;
189} 189}
diff --git a/drivers/char/watchdog/ep93xx_wdt.c b/drivers/char/watchdog/ep93xx_wdt.c
index 77c8a955ae9e..01cf123b1616 100644
--- a/drivers/char/watchdog/ep93xx_wdt.c
+++ b/drivers/char/watchdog/ep93xx_wdt.c
@@ -144,7 +144,7 @@ static int
144ep93xx_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 144ep93xx_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
145 unsigned long arg) 145 unsigned long arg)
146{ 146{
147 int ret = -ENOIOCTLCMD; 147 int ret = -ENOTTY;
148 148
149 switch (cmd) { 149 switch (cmd) {
150 case WDIOC_GETSUPPORT: 150 case WDIOC_GETSUPPORT:
diff --git a/drivers/char/watchdog/eurotechwdt.c b/drivers/char/watchdog/eurotechwdt.c
index 62dbccb2f6df..e228d6e173ce 100644
--- a/drivers/char/watchdog/eurotechwdt.c
+++ b/drivers/char/watchdog/eurotechwdt.c
@@ -153,7 +153,7 @@ static void eurwdt_activate_timer(void)
153 * Kernel methods. 153 * Kernel methods.
154 */ 154 */
155 155
156static irqreturn_t eurwdt_interrupt(int irq, void *dev_id, struct pt_regs *regs) 156static irqreturn_t eurwdt_interrupt(int irq, void *dev_id)
157{ 157{
158 printk(KERN_CRIT "timeout WDT timeout\n"); 158 printk(KERN_CRIT "timeout WDT timeout\n");
159 159
@@ -240,7 +240,7 @@ static int eurwdt_ioctl(struct inode *inode, struct file *file,
240 240
241 switch(cmd) { 241 switch(cmd) {
242 default: 242 default:
243 return -ENOIOCTLCMD; 243 return -ENOTTY;
244 244
245 case WDIOC_GETSUPPORT: 245 case WDIOC_GETSUPPORT:
246 return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; 246 return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
diff --git a/drivers/char/watchdog/i6300esb.c b/drivers/char/watchdog/i6300esb.c
index 870539eabbf3..fb64df4d7c87 100644
--- a/drivers/char/watchdog/i6300esb.c
+++ b/drivers/char/watchdog/i6300esb.c
@@ -315,7 +315,7 @@ static int esb_ioctl (struct inode *inode, struct file *file,
315 return put_user(heartbeat, p); 315 return put_user(heartbeat, p);
316 316
317 default: 317 default:
318 return -ENOIOCTLCMD; 318 return -ENOTTY;
319 } 319 }
320} 320}
321 321
diff --git a/drivers/char/watchdog/i8xx_tco.c b/drivers/char/watchdog/i8xx_tco.c
index 8385dd36eefe..e0627d79707b 100644
--- a/drivers/char/watchdog/i8xx_tco.c
+++ b/drivers/char/watchdog/i8xx_tco.c
@@ -356,7 +356,7 @@ static int i8xx_tco_ioctl (struct inode *inode, struct file *file,
356 } 356 }
357 357
358 default: 358 default:
359 return -ENOIOCTLCMD; 359 return -ENOTTY;
360 } 360 }
361} 361}
362 362
@@ -406,18 +406,18 @@ static struct notifier_block i8xx_tco_notifier = {
406 * want to register another driver on the same PCI id. 406 * want to register another driver on the same PCI id.
407 */ 407 */
408static struct pci_device_id i8xx_tco_pci_tbl[] = { 408static struct pci_device_id i8xx_tco_pci_tbl[] = {
409 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, PCI_ANY_ID, PCI_ANY_ID, }, 409 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0) },
410 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_0, PCI_ANY_ID, PCI_ANY_ID, }, 410 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_0) },
411 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, PCI_ANY_ID, PCI_ANY_ID, }, 411 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0) },
412 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_10, PCI_ANY_ID, PCI_ANY_ID, }, 412 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_10) },
413 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, PCI_ANY_ID, PCI_ANY_ID, }, 413 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0) },
414 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, PCI_ANY_ID, PCI_ANY_ID, }, 414 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12) },
415 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, PCI_ANY_ID, PCI_ANY_ID, }, 415 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0) },
416 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, PCI_ANY_ID, PCI_ANY_ID, }, 416 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12) },
417 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801E_0, PCI_ANY_ID, PCI_ANY_ID, }, 417 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801E_0) },
418 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, PCI_ANY_ID, PCI_ANY_ID, }, 418 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0) },
419 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1, PCI_ANY_ID, PCI_ANY_ID, }, 419 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1) },
420 { 0, }, /* End of list */ 420 { }, /* End of list */
421}; 421};
422MODULE_DEVICE_TABLE (pci, i8xx_tco_pci_tbl); 422MODULE_DEVICE_TABLE (pci, i8xx_tco_pci_tbl);
423 423
@@ -434,12 +434,11 @@ static unsigned char __init i8xx_tco_getdevice (void)
434 * Find the PCI device 434 * Find the PCI device
435 */ 435 */
436 436
437 while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { 437 for_each_pci_dev(dev)
438 if (pci_match_id(i8xx_tco_pci_tbl, dev)) { 438 if (pci_match_id(i8xx_tco_pci_tbl, dev)) {
439 i8xx_tco_pci = dev; 439 i8xx_tco_pci = dev;
440 break; 440 break;
441 } 441 }
442 }
443 442
444 if (i8xx_tco_pci) { 443 if (i8xx_tco_pci) {
445 /* 444 /*
@@ -454,6 +453,7 @@ static unsigned char __init i8xx_tco_getdevice (void)
454 /* Something's wrong here, ACPIBASE has to be set */ 453 /* Something's wrong here, ACPIBASE has to be set */
455 if (badr == 0x0001 || badr == 0x0000) { 454 if (badr == 0x0001 || badr == 0x0000) {
456 printk (KERN_ERR PFX "failed to get TCOBASE address\n"); 455 printk (KERN_ERR PFX "failed to get TCOBASE address\n");
456 pci_dev_put(i8xx_tco_pci);
457 return 0; 457 return 0;
458 } 458 }
459 459
@@ -465,6 +465,7 @@ static unsigned char __init i8xx_tco_getdevice (void)
465 pci_read_config_byte (i8xx_tco_pci, 0xd4, &val1); 465 pci_read_config_byte (i8xx_tco_pci, 0xd4, &val1);
466 if (val1 & 0x02) { 466 if (val1 & 0x02) {
467 printk (KERN_ERR PFX "failed to reset NO_REBOOT flag, reboot disabled by hardware\n"); 467 printk (KERN_ERR PFX "failed to reset NO_REBOOT flag, reboot disabled by hardware\n");
468 pci_dev_put(i8xx_tco_pci);
468 return 0; /* Cannot reset NO_REBOOT bit */ 469 return 0; /* Cannot reset NO_REBOOT bit */
469 } 470 }
470 } 471 }
@@ -476,6 +477,7 @@ static unsigned char __init i8xx_tco_getdevice (void)
476 if (!request_region (SMI_EN + 1, 1, "i8xx TCO")) { 477 if (!request_region (SMI_EN + 1, 1, "i8xx TCO")) {
477 printk (KERN_ERR PFX "I/O address 0x%04x already in use\n", 478 printk (KERN_ERR PFX "I/O address 0x%04x already in use\n",
478 SMI_EN + 1); 479 SMI_EN + 1);
480 pci_dev_put(i8xx_tco_pci);
479 return 0; 481 return 0;
480 } 482 }
481 val1 = inb (SMI_EN + 1); 483 val1 = inb (SMI_EN + 1);
@@ -542,6 +544,7 @@ unreg_notifier:
542unreg_region: 544unreg_region:
543 release_region (TCOBASE, 0x10); 545 release_region (TCOBASE, 0x10);
544out: 546out:
547 pci_dev_put(i8xx_tco_pci);
545 return ret; 548 return ret;
546} 549}
547 550
@@ -555,6 +558,8 @@ static void __exit watchdog_cleanup (void)
555 misc_deregister (&i8xx_tco_miscdev); 558 misc_deregister (&i8xx_tco_miscdev);
556 unregister_reboot_notifier(&i8xx_tco_notifier); 559 unregister_reboot_notifier(&i8xx_tco_notifier);
557 release_region (TCOBASE, 0x10); 560 release_region (TCOBASE, 0x10);
561
562 pci_dev_put(i8xx_tco_pci);
558} 563}
559 564
560module_init(watchdog_init); 565module_init(watchdog_init);
diff --git a/drivers/char/watchdog/iTCO_vendor_support.c b/drivers/char/watchdog/iTCO_vendor_support.c
new file mode 100644
index 000000000000..415083990097
--- /dev/null
+++ b/drivers/char/watchdog/iTCO_vendor_support.c
@@ -0,0 +1,307 @@
1/*
2 * intel TCO vendor specific watchdog driver support
3 *
4 * (c) Copyright 2006 Wim Van Sebroeck <wim@iguana.be>.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 * Neither Wim Van Sebroeck nor Iguana vzw. admit liability nor
12 * provide warranty for any of this software. This material is
13 * provided "AS-IS" and at no charge.
14 */
15
16/*
17 * Includes, defines, variables, module parameters, ...
18 */
19
20/* Module and version information */
21#define DRV_NAME "iTCO_vendor_support"
22#define DRV_VERSION "1.01"
23#define DRV_RELDATE "11-Nov-2006"
24#define PFX DRV_NAME ": "
25
26/* Includes */
27#include <linux/module.h> /* For module specific items */
28#include <linux/moduleparam.h> /* For new moduleparam's */
29#include <linux/types.h> /* For standard types (like size_t) */
30#include <linux/errno.h> /* For the -ENODEV/... values */
31#include <linux/kernel.h> /* For printk/panic/... */
32#include <linux/init.h> /* For __init/__exit/... */
33#include <linux/ioport.h> /* For io-port access */
34
35#include <asm/io.h> /* For inb/outb/... */
36
37/* iTCO defines */
38#define SMI_EN acpibase + 0x30 /* SMI Control and Enable Register */
39#define TCOBASE acpibase + 0x60 /* TCO base address */
40#define TCO1_STS TCOBASE + 0x04 /* TCO1 Status Register */
41
42/* List of vendor support modes */
43#define SUPERMICRO_OLD_BOARD 1 /* SuperMicro Pentium 3 Era 370SSE+-OEM1/P3TSSE */
44#define SUPERMICRO_NEW_BOARD 2 /* SuperMicro Pentium 4 / Xeon 4 / EMT64T Era Systems */
45
46static int vendorsupport = 0;
47module_param(vendorsupport, int, 0);
48MODULE_PARM_DESC(vendorsupport, "iTCO vendor specific support mode, default=0 (none), 1=SuperMicro Pent3, 2=SuperMicro Pent4+");
49
50/*
51 * Vendor Specific Support
52 */
53
54/*
55 * Vendor Support: 1
56 * Board: Super Micro Computer Inc. 370SSE+-OEM1/P3TSSE
57 * iTCO chipset: ICH2
58 *
59 * Code contributed by: R. Seretny <lkpatches@paypc.com>
60 * Documentation obtained by R. Seretny from SuperMicro Technical Support
61 *
62 * To enable Watchdog function:
63 * BIOS setup -> Power -> TCO Logic SMI Enable -> Within5Minutes
64 * This setting enables SMI to clear the watchdog expired flag.
65 * If BIOS or CPU fail which may cause SMI hang, then system will
66 * reboot. When application starts to use watchdog function,
67 * application has to take over the control from SMI.
68 *
69 * For P3TSSE, J36 jumper needs to be removed to enable the Watchdog
70 * function.
71 *
72 * Note: The system will reboot when Expire Flag is set TWICE.
73 * So, if the watchdog timer is 20 seconds, then the maximum hang
74 * time is about 40 seconds, and the minimum hang time is about
75 * 20.6 seconds.
76 */
77
78static void supermicro_old_pre_start(unsigned long acpibase)
79{
80 unsigned long val32;
81
82 val32 = inl(SMI_EN);
83 val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
84 outl(val32, SMI_EN); /* Needed to activate watchdog */
85}
86
87static void supermicro_old_pre_stop(unsigned long acpibase)
88{
89 unsigned long val32;
90
91 val32 = inl(SMI_EN);
92 val32 &= 0x00002000; /* Turn on SMI clearing watchdog */
93 outl(val32, SMI_EN); /* Needed to deactivate watchdog */
94}
95
96static void supermicro_old_pre_keepalive(unsigned long acpibase)
97{
98 /* Reload TCO Timer (done in iTCO_wdt_keepalive) + */
99 /* Clear "Expire Flag" (Bit 3 of TC01_STS register) */
100 outb(0x08, TCO1_STS);
101}
102
103/*
104 * Vendor Support: 2
105 * Board: Super Micro Computer Inc. P4SBx, P4DPx
106 * iTCO chipset: ICH4
107 *
108 * Code contributed by: R. Seretny <lkpatches@paypc.com>
109 * Documentation obtained by R. Seretny from SuperMicro Technical Support
110 *
111 * To enable Watchdog function:
112 * 1. BIOS
113 * For P4SBx:
114 * BIOS setup -> Advanced -> Integrated Peripherals -> Watch Dog Feature
115 * For P4DPx:
116 * BIOS setup -> Advanced -> I/O Device Configuration -> Watch Dog
117 * This setting enables or disables Watchdog function. When enabled, the
118 * default watchdog timer is set to be 5 minutes (about 4’35â€). It is
119 * enough to load and run the OS. The application (service or driver) has
120 * to take over the control once OS is running up and before watchdog
121 * expires.
122 *
123 * 2. JUMPER
124 * For P4SBx: JP39
125 * For P4DPx: JP37
126 * This jumper is used for safety. Closed is enabled. This jumper
127 * prevents user enables watchdog in BIOS by accident.
128 *
129 * To enable Watch Dog function, both BIOS and JUMPER must be enabled.
130 *
131 * The documentation lists motherboards P4SBx and P4DPx series as of
132 * 20-March-2002. However, this code works flawlessly with much newer
133 * motherboards, such as my X6DHR-8G2 (SuperServer 6014H-82).
134 *
135 * The original iTCO driver as written does not actually reset the
136 * watchdog timer on these machines, as a result they reboot after five
137 * minutes.
138 *
139 * NOTE: You may leave the Watchdog function disabled in the SuperMicro
140 * BIOS to avoid a "boot-race"... This driver will enable watchdog
141 * functionality even if it's disabled in the BIOS once the /dev/watchdog
142 * file is opened.
143 */
144
145/* I/O Port's */
146#define SM_REGINDEX 0x2e /* SuperMicro ICH4+ Register Index */
147#define SM_DATAIO 0x2f /* SuperMicro ICH4+ Register Data I/O */
148
149/* Control Register's */
150#define SM_CTLPAGESW 0x07 /* SuperMicro ICH4+ Control Page Switch */
151#define SM_CTLPAGE 0x08 /* SuperMicro ICH4+ Control Page Num */
152
153#define SM_WATCHENABLE 0x30 /* Watchdog enable: Bit 0: 0=off, 1=on */
154
155#define SM_WATCHPAGE 0x87 /* Watchdog unlock control page */
156
157#define SM_ENDWATCH 0xAA /* Watchdog lock control page */
158
159#define SM_COUNTMODE 0xf5 /* Watchdog count mode select */
160 /* (Bit 3: 0 = seconds, 1 = minutes */
161
162#define SM_WATCHTIMER 0xf6 /* 8-bits, Watchdog timer counter (RW) */
163
164#define SM_RESETCONTROL 0xf7 /* Watchdog reset control */
165 /* Bit 6: timer is reset by kbd interrupt */
166 /* Bit 7: timer is reset by mouse interrupt */
167
168static void supermicro_new_unlock_watchdog(void)
169{
170 outb(SM_WATCHPAGE, SM_REGINDEX); /* Write 0x87 to port 0x2e twice */
171 outb(SM_WATCHPAGE, SM_REGINDEX);
172
173 outb(SM_CTLPAGESW, SM_REGINDEX); /* Switch to watchdog control page */
174 outb(SM_CTLPAGE, SM_DATAIO);
175}
176
177static void supermicro_new_lock_watchdog(void)
178{
179 outb(SM_ENDWATCH, SM_REGINDEX);
180}
181
182static void supermicro_new_pre_start(unsigned int heartbeat)
183{
184 unsigned int val;
185
186 supermicro_new_unlock_watchdog();
187
188 /* Watchdog timer setting needs to be in seconds*/
189 outb(SM_COUNTMODE, SM_REGINDEX);
190 val = inb(SM_DATAIO);
191 val &= 0xF7;
192 outb(val, SM_DATAIO);
193
194 /* Write heartbeat interval to WDOG */
195 outb (SM_WATCHTIMER, SM_REGINDEX);
196 outb((heartbeat & 255), SM_DATAIO);
197
198 /* Make sure keyboard/mouse interrupts don't interfere */
199 outb(SM_RESETCONTROL, SM_REGINDEX);
200 val = inb(SM_DATAIO);
201 val &= 0x3f;
202 outb(val, SM_DATAIO);
203
204 /* enable watchdog by setting bit 0 of Watchdog Enable to 1 */
205 outb(SM_WATCHENABLE, SM_REGINDEX);
206 val = inb(SM_DATAIO);
207 val |= 0x01;
208 outb(val, SM_DATAIO);
209
210 supermicro_new_lock_watchdog();
211}
212
213static void supermicro_new_pre_stop(void)
214{
215 unsigned int val;
216
217 supermicro_new_unlock_watchdog();
218
219 /* disable watchdog by setting bit 0 of Watchdog Enable to 0 */
220 outb(SM_WATCHENABLE, SM_REGINDEX);
221 val = inb(SM_DATAIO);
222 val &= 0xFE;
223 outb(val, SM_DATAIO);
224
225 supermicro_new_lock_watchdog();
226}
227
228static void supermicro_new_pre_set_heartbeat(unsigned int heartbeat)
229{
230 supermicro_new_unlock_watchdog();
231
232 /* reset watchdog timeout to heartveat value */
233 outb(SM_WATCHTIMER, SM_REGINDEX);
234 outb((heartbeat & 255), SM_DATAIO);
235
236 supermicro_new_lock_watchdog();
237}
238
239/*
240 * Generic Support Functions
241 */
242
243void iTCO_vendor_pre_start(unsigned long acpibase,
244 unsigned int heartbeat)
245{
246 if (vendorsupport == SUPERMICRO_OLD_BOARD)
247 supermicro_old_pre_start(acpibase);
248 else if (vendorsupport == SUPERMICRO_NEW_BOARD)
249 supermicro_new_pre_start(heartbeat);
250}
251EXPORT_SYMBOL(iTCO_vendor_pre_start);
252
253void iTCO_vendor_pre_stop(unsigned long acpibase)
254{
255 if (vendorsupport == SUPERMICRO_OLD_BOARD)
256 supermicro_old_pre_stop(acpibase);
257 else if (vendorsupport == SUPERMICRO_NEW_BOARD)
258 supermicro_new_pre_stop();
259}
260EXPORT_SYMBOL(iTCO_vendor_pre_stop);
261
262void iTCO_vendor_pre_keepalive(unsigned long acpibase, unsigned int heartbeat)
263{
264 if (vendorsupport == SUPERMICRO_OLD_BOARD)
265 supermicro_old_pre_keepalive(acpibase);
266 else if (vendorsupport == SUPERMICRO_NEW_BOARD)
267 supermicro_new_pre_set_heartbeat(heartbeat);
268}
269EXPORT_SYMBOL(iTCO_vendor_pre_keepalive);
270
271void iTCO_vendor_pre_set_heartbeat(unsigned int heartbeat)
272{
273 if (vendorsupport == SUPERMICRO_NEW_BOARD)
274 supermicro_new_pre_set_heartbeat(heartbeat);
275}
276EXPORT_SYMBOL(iTCO_vendor_pre_set_heartbeat);
277
278int iTCO_vendor_check_noreboot_on(void)
279{
280 switch(vendorsupport) {
281 case SUPERMICRO_OLD_BOARD:
282 return 0;
283 default:
284 return 1;
285 }
286}
287EXPORT_SYMBOL(iTCO_vendor_check_noreboot_on);
288
289static int __init iTCO_vendor_init_module(void)
290{
291 printk (KERN_INFO PFX "vendor-support=%d\n", vendorsupport);
292 return 0;
293}
294
295static void __exit iTCO_vendor_exit_module(void)
296{
297 printk (KERN_INFO PFX "Module Unloaded\n");
298}
299
300module_init(iTCO_vendor_init_module);
301module_exit(iTCO_vendor_exit_module);
302
303MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>, R. Seretny <lkpatches@paypc.com>");
304MODULE_DESCRIPTION("Intel TCO Vendor Specific WatchDog Timer Driver Support");
305MODULE_VERSION(DRV_VERSION);
306MODULE_LICENSE("GPL");
307
diff --git a/drivers/char/watchdog/iTCO_wdt.c b/drivers/char/watchdog/iTCO_wdt.c
new file mode 100644
index 000000000000..7eac922df867
--- /dev/null
+++ b/drivers/char/watchdog/iTCO_wdt.c
@@ -0,0 +1,772 @@
1/*
2 * intel TCO Watchdog Driver (Used in i82801 and i6300ESB chipsets)
3 *
4 * (c) Copyright 2006 Wim Van Sebroeck <wim@iguana.be>.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 * Neither Wim Van Sebroeck nor Iguana vzw. admit liability nor
12 * provide warranty for any of this software. This material is
13 * provided "AS-IS" and at no charge.
14 *
15 * The TCO watchdog is implemented in the following I/O controller hubs:
16 * (See the intel documentation on http://developer.intel.com.)
17 * 82801AA (ICH) : document number 290655-003, 290677-014,
18 * 82801AB (ICHO) : document number 290655-003, 290677-014,
19 * 82801BA (ICH2) : document number 290687-002, 298242-027,
20 * 82801BAM (ICH2-M) : document number 290687-002, 298242-027,
21 * 82801CA (ICH3-S) : document number 290733-003, 290739-013,
22 * 82801CAM (ICH3-M) : document number 290716-001, 290718-007,
23 * 82801DB (ICH4) : document number 290744-001, 290745-020,
24 * 82801DBM (ICH4-M) : document number 252337-001, 252663-005,
25 * 82801E (C-ICH) : document number 273599-001, 273645-002,
26 * 82801EB (ICH5) : document number 252516-001, 252517-003,
27 * 82801ER (ICH5R) : document number 252516-001, 252517-003,
28 * 82801FB (ICH6) : document number 301473-002, 301474-007,
29 * 82801FR (ICH6R) : document number 301473-002, 301474-007,
30 * 82801FBM (ICH6-M) : document number 301473-002, 301474-007,
31 * 82801FW (ICH6W) : document number 301473-001, 301474-007,
32 * 82801FRW (ICH6RW) : document number 301473-001, 301474-007,
33 * 82801GB (ICH7) : document number 307013-002, 307014-009,
34 * 82801GR (ICH7R) : document number 307013-002, 307014-009,
35 * 82801GDH (ICH7DH) : document number 307013-002, 307014-009,
36 * 82801GBM (ICH7-M) : document number 307013-002, 307014-009,
37 * 82801GHM (ICH7-M DH) : document number 307013-002, 307014-009,
38 * 82801HB (ICH8) : document number 313056-002, 313057-004,
39 * 82801HR (ICH8R) : document number 313056-002, 313057-004,
40 * 82801HH (ICH8DH) : document number 313056-002, 313057-004,
41 * 82801HO (ICH8DO) : document number 313056-002, 313057-004,
42 * 6300ESB (6300ESB) : document number 300641-003
43 */
44
45/*
46 * Includes, defines, variables, module parameters, ...
47 */
48
49/* Module and version information */
50#define DRV_NAME "iTCO_wdt"
51#define DRV_VERSION "1.01"
52#define DRV_RELDATE "11-Nov-2006"
53#define PFX DRV_NAME ": "
54
55/* Includes */
56#include <linux/module.h> /* For module specific items */
57#include <linux/moduleparam.h> /* For new moduleparam's */
58#include <linux/types.h> /* For standard types (like size_t) */
59#include <linux/errno.h> /* For the -ENODEV/... values */
60#include <linux/kernel.h> /* For printk/panic/... */
61#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */
62#include <linux/watchdog.h> /* For the watchdog specific items */
63#include <linux/init.h> /* For __init/__exit/... */
64#include <linux/fs.h> /* For file operations */
65#include <linux/platform_device.h> /* For platform_driver framework */
66#include <linux/pci.h> /* For pci functions */
67#include <linux/ioport.h> /* For io-port access */
68#include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
69
70#include <asm/uaccess.h> /* For copy_to_user/put_user/... */
71#include <asm/io.h> /* For inb/outb/... */
72
73/* TCO related info */
74enum iTCO_chipsets {
75 TCO_ICH = 0, /* ICH */
76 TCO_ICH0, /* ICH0 */
77 TCO_ICH2, /* ICH2 */
78 TCO_ICH2M, /* ICH2-M */
79 TCO_ICH3, /* ICH3-S */
80 TCO_ICH3M, /* ICH3-M */
81 TCO_ICH4, /* ICH4 */
82 TCO_ICH4M, /* ICH4-M */
83 TCO_CICH, /* C-ICH */
84 TCO_ICH5, /* ICH5 & ICH5R */
85 TCO_6300ESB, /* 6300ESB */
86 TCO_ICH6, /* ICH6 & ICH6R */
87 TCO_ICH6M, /* ICH6-M */
88 TCO_ICH6W, /* ICH6W & ICH6RW */
89 TCO_ICH7, /* ICH7 & ICH7R */
90 TCO_ICH7M, /* ICH7-M */
91 TCO_ICH7MDH, /* ICH7-M DH */
92 TCO_ICH8, /* ICH8 & ICH8R */
93 TCO_ICH8DH, /* ICH8DH */
94 TCO_ICH8DO, /* ICH8DO */
95};
96
97static struct {
98 char *name;
99 unsigned int iTCO_version;
100} iTCO_chipset_info[] __devinitdata = {
101 {"ICH", 1},
102 {"ICH0", 1},
103 {"ICH2", 1},
104 {"ICH2-M", 1},
105 {"ICH3-S", 1},
106 {"ICH3-M", 1},
107 {"ICH4", 1},
108 {"ICH4-M", 1},
109 {"C-ICH", 1},
110 {"ICH5 or ICH5R", 1},
111 {"6300ESB", 1},
112 {"ICH6 or ICH6R", 2},
113 {"ICH6-M", 2},
114 {"ICH6W or ICH6RW", 2},
115 {"ICH7 or ICH7R", 2},
116 {"ICH7-M", 2},
117 {"ICH7-M DH", 2},
118 {"ICH8 or ICH8R", 2},
119 {"ICH8DH", 2},
120 {"ICH8DO", 2},
121 {NULL,0}
122};
123
124/*
125 * This data only exists for exporting the supported PCI ids
126 * via MODULE_DEVICE_TABLE. We do not actually register a
127 * pci_driver, because the I/O Controller Hub has also other
128 * functions that probably will be registered by other drivers.
129 */
130static struct pci_device_id iTCO_wdt_pci_tbl[] = {
131 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH },
132 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH0 },
133 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH2 },
134 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_10, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH2M },
135 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH3 },
136 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH3M },
137 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH4 },
138 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH4M },
139 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801E_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_CICH },
140 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH5 },
141 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_6300ESB },
142 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH6 },
143 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH6M },
144 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH6W },
145 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH7 },
146 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH7M },
147 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_31, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH7MDH },
148 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH8 },
149 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH8DH },
150 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TCO_ICH8DO },
151 { 0, }, /* End of list */
152};
153MODULE_DEVICE_TABLE (pci, iTCO_wdt_pci_tbl);
154
155/* Address definitions for the TCO */
156#define TCOBASE iTCO_wdt_private.ACPIBASE + 0x60 /* TCO base address */
157#define SMI_EN iTCO_wdt_private.ACPIBASE + 0x30 /* SMI Control and Enable Register */
158
159#define TCO_RLD TCOBASE + 0x00 /* TCO Timer Reload and Current Value */
160#define TCOv1_TMR TCOBASE + 0x01 /* TCOv1 Timer Initial Value */
161#define TCO_DAT_IN TCOBASE + 0x02 /* TCO Data In Register */
162#define TCO_DAT_OUT TCOBASE + 0x03 /* TCO Data Out Register */
163#define TCO1_STS TCOBASE + 0x04 /* TCO1 Status Register */
164#define TCO2_STS TCOBASE + 0x06 /* TCO2 Status Register */
165#define TCO1_CNT TCOBASE + 0x08 /* TCO1 Control Register */
166#define TCO2_CNT TCOBASE + 0x0a /* TCO2 Control Register */
167#define TCOv2_TMR TCOBASE + 0x12 /* TCOv2 Timer Initial Value */
168
169/* internal variables */
170static unsigned long is_active;
171static char expect_release;
172static struct { /* this is private data for the iTCO_wdt device */
173 unsigned int iTCO_version; /* TCO version/generation */
174 unsigned long ACPIBASE; /* The cards ACPIBASE address (TCOBASE = ACPIBASE+0x60) */
175 unsigned long __iomem *gcs; /* NO_REBOOT flag is Memory-Mapped GCS register bit 5 (TCO version 2) */
176 spinlock_t io_lock; /* the lock for io operations */
177 struct pci_dev *pdev; /* the PCI-device */
178} iTCO_wdt_private;
179
180static struct platform_device *iTCO_wdt_platform_device; /* the watchdog platform device */
181
182/* module parameters */
183#define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat */
184static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
185module_param(heartbeat, int, 0);
186MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2<heartbeat<39 (TCO v1) or 613 (TCO v2), default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
187
188static int nowayout = WATCHDOG_NOWAYOUT;
189module_param(nowayout, int, 0);
190MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
191
192/* iTCO Vendor Specific Support hooks */
193#ifdef CONFIG_ITCO_VENDOR_SUPPORT
194extern void iTCO_vendor_pre_start(unsigned long, unsigned int);
195extern void iTCO_vendor_pre_stop(unsigned long);
196extern void iTCO_vendor_pre_keepalive(unsigned long, unsigned int);
197extern void iTCO_vendor_pre_set_heartbeat(unsigned int);
198extern int iTCO_vendor_check_noreboot_on(void);
199#else
200#define iTCO_vendor_pre_start(acpibase, heartbeat) {}
201#define iTCO_vendor_pre_stop(acpibase) {}
202#define iTCO_vendor_pre_keepalive(acpibase,heartbeat) {}
203#define iTCO_vendor_pre_set_heartbeat(heartbeat) {}
204#define iTCO_vendor_check_noreboot_on() 1 /* 1=check noreboot; 0=don't check */
205#endif
206
207/*
208 * Some TCO specific functions
209 */
210
211static inline unsigned int seconds_to_ticks(int seconds)
212{
213 /* the internal timer is stored as ticks which decrement
214 * every 0.6 seconds */
215 return (seconds * 10) / 6;
216}
217
218static void iTCO_wdt_set_NO_REBOOT_bit(void)
219{
220 u32 val32;
221
222 /* Set the NO_REBOOT bit: this disables reboots */
223 if (iTCO_wdt_private.iTCO_version == 2) {
224 val32 = readl(iTCO_wdt_private.gcs);
225 val32 |= 0x00000020;
226 writel(val32, iTCO_wdt_private.gcs);
227 } else if (iTCO_wdt_private.iTCO_version == 1) {
228 pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
229 val32 |= 0x00000002;
230 pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
231 }
232}
233
234static int iTCO_wdt_unset_NO_REBOOT_bit(void)
235{
236 int ret = 0;
237 u32 val32;
238
239 /* Unset the NO_REBOOT bit: this enables reboots */
240 if (iTCO_wdt_private.iTCO_version == 2) {
241 val32 = readl(iTCO_wdt_private.gcs);
242 val32 &= 0xffffffdf;
243 writel(val32, iTCO_wdt_private.gcs);
244
245 val32 = readl(iTCO_wdt_private.gcs);
246 if (val32 & 0x00000020)
247 ret = -EIO;
248 } else if (iTCO_wdt_private.iTCO_version == 1) {
249 pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
250 val32 &= 0xfffffffd;
251 pci_write_config_dword(iTCO_wdt_private.pdev, 0xd4, val32);
252
253 pci_read_config_dword(iTCO_wdt_private.pdev, 0xd4, &val32);
254 if (val32 & 0x00000002)
255 ret = -EIO;
256 }
257
258 return ret; /* returns: 0 = OK, -EIO = Error */
259}
260
261static int iTCO_wdt_start(void)
262{
263 unsigned int val;
264
265 spin_lock(&iTCO_wdt_private.io_lock);
266
267 iTCO_vendor_pre_start(iTCO_wdt_private.ACPIBASE, heartbeat);
268
269 /* disable chipset's NO_REBOOT bit */
270 if (iTCO_wdt_unset_NO_REBOOT_bit()) {
271 printk(KERN_ERR PFX "failed to reset NO_REBOOT flag, reboot disabled by hardware\n");
272 return -EIO;
273 }
274
275 /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled to count */
276 val = inw(TCO1_CNT);
277 val &= 0xf7ff;
278 outw(val, TCO1_CNT);
279 val = inw(TCO1_CNT);
280 spin_unlock(&iTCO_wdt_private.io_lock);
281
282 if (val & 0x0800)
283 return -1;
284 return 0;
285}
286
287static int iTCO_wdt_stop(void)
288{
289 unsigned int val;
290
291 spin_lock(&iTCO_wdt_private.io_lock);
292
293 iTCO_vendor_pre_stop(iTCO_wdt_private.ACPIBASE);
294
295 /* Bit 11: TCO Timer Halt -> 1 = The TCO timer is disabled */
296 val = inw(TCO1_CNT);
297 val |= 0x0800;
298 outw(val, TCO1_CNT);
299 val = inw(TCO1_CNT);
300
301 /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
302 iTCO_wdt_set_NO_REBOOT_bit();
303
304 spin_unlock(&iTCO_wdt_private.io_lock);
305
306 if ((val & 0x0800) == 0)
307 return -1;
308 return 0;
309}
310
311static int iTCO_wdt_keepalive(void)
312{
313 spin_lock(&iTCO_wdt_private.io_lock);
314
315 iTCO_vendor_pre_keepalive(iTCO_wdt_private.ACPIBASE, heartbeat);
316
317 /* Reload the timer by writing to the TCO Timer Counter register */
318 if (iTCO_wdt_private.iTCO_version == 2) {
319 outw(0x01, TCO_RLD);
320 } else if (iTCO_wdt_private.iTCO_version == 1) {
321 outb(0x01, TCO_RLD);
322 }
323
324 spin_unlock(&iTCO_wdt_private.io_lock);
325 return 0;
326}
327
328static int iTCO_wdt_set_heartbeat(int t)
329{
330 unsigned int val16;
331 unsigned char val8;
332 unsigned int tmrval;
333
334 tmrval = seconds_to_ticks(t);
335 /* from the specs: */
336 /* "Values of 0h-3h are ignored and should not be attempted" */
337 if (tmrval < 0x04)
338 return -EINVAL;
339 if (((iTCO_wdt_private.iTCO_version == 2) && (tmrval > 0x3ff)) ||
340 ((iTCO_wdt_private.iTCO_version == 1) && (tmrval > 0x03f)))
341 return -EINVAL;
342
343 iTCO_vendor_pre_set_heartbeat(tmrval);
344
345 /* Write new heartbeat to watchdog */
346 if (iTCO_wdt_private.iTCO_version == 2) {
347 spin_lock(&iTCO_wdt_private.io_lock);
348 val16 = inw(TCOv2_TMR);
349 val16 &= 0xfc00;
350 val16 |= tmrval;
351 outw(val16, TCOv2_TMR);
352 val16 = inw(TCOv2_TMR);
353 spin_unlock(&iTCO_wdt_private.io_lock);
354
355 if ((val16 & 0x3ff) != tmrval)
356 return -EINVAL;
357 } else if (iTCO_wdt_private.iTCO_version == 1) {
358 spin_lock(&iTCO_wdt_private.io_lock);
359 val8 = inb(TCOv1_TMR);
360 val8 &= 0xc0;
361 val8 |= (tmrval & 0xff);
362 outb(val8, TCOv1_TMR);
363 val8 = inb(TCOv1_TMR);
364 spin_unlock(&iTCO_wdt_private.io_lock);
365
366 if ((val8 & 0x3f) != tmrval)
367 return -EINVAL;
368 }
369
370 heartbeat = t;
371 return 0;
372}
373
374static int iTCO_wdt_get_timeleft (int *time_left)
375{
376 unsigned int val16;
377 unsigned char val8;
378
379 /* read the TCO Timer */
380 if (iTCO_wdt_private.iTCO_version == 2) {
381 spin_lock(&iTCO_wdt_private.io_lock);
382 val16 = inw(TCO_RLD);
383 val16 &= 0x3ff;
384 spin_unlock(&iTCO_wdt_private.io_lock);
385
386 *time_left = (val16 * 6) / 10;
387 } else if (iTCO_wdt_private.iTCO_version == 1) {
388 spin_lock(&iTCO_wdt_private.io_lock);
389 val8 = inb(TCO_RLD);
390 val8 &= 0x3f;
391 spin_unlock(&iTCO_wdt_private.io_lock);
392
393 *time_left = (val8 * 6) / 10;
394 } else
395 return -EINVAL;
396 return 0;
397}
398
399/*
400 * /dev/watchdog handling
401 */
402
403static int iTCO_wdt_open (struct inode *inode, struct file *file)
404{
405 /* /dev/watchdog can only be opened once */
406 if (test_and_set_bit(0, &is_active))
407 return -EBUSY;
408
409 /*
410 * Reload and activate timer
411 */
412 iTCO_wdt_keepalive();
413 iTCO_wdt_start();
414 return nonseekable_open(inode, file);
415}
416
417static int iTCO_wdt_release (struct inode *inode, struct file *file)
418{
419 /*
420 * Shut off the timer.
421 */
422 if (expect_release == 42) {
423 iTCO_wdt_stop();
424 } else {
425 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
426 iTCO_wdt_keepalive();
427 }
428 clear_bit(0, &is_active);
429 expect_release = 0;
430 return 0;
431}
432
433static ssize_t iTCO_wdt_write (struct file *file, const char __user *data,
434 size_t len, loff_t * ppos)
435{
436 /* See if we got the magic character 'V' and reload the timer */
437 if (len) {
438 if (!nowayout) {
439 size_t i;
440
441 /* note: just in case someone wrote the magic character
442 * five months ago... */
443 expect_release = 0;
444
445 /* scan to see whether or not we got the magic character */
446 for (i = 0; i != len; i++) {
447 char c;
448 if (get_user(c, data+i))
449 return -EFAULT;
450 if (c == 'V')
451 expect_release = 42;
452 }
453 }
454
455 /* someone wrote to us, we should reload the timer */
456 iTCO_wdt_keepalive();
457 }
458 return len;
459}
460
461static int iTCO_wdt_ioctl (struct inode *inode, struct file *file,
462 unsigned int cmd, unsigned long arg)
463{
464 int new_options, retval = -EINVAL;
465 int new_heartbeat;
466 void __user *argp = (void __user *)arg;
467 int __user *p = argp;
468 static struct watchdog_info ident = {
469 .options = WDIOF_SETTIMEOUT |
470 WDIOF_KEEPALIVEPING |
471 WDIOF_MAGICCLOSE,
472 .firmware_version = 0,
473 .identity = DRV_NAME,
474 };
475
476 switch (cmd) {
477 case WDIOC_GETSUPPORT:
478 return copy_to_user(argp, &ident,
479 sizeof (ident)) ? -EFAULT : 0;
480
481 case WDIOC_GETSTATUS:
482 case WDIOC_GETBOOTSTATUS:
483 return put_user(0, p);
484
485 case WDIOC_KEEPALIVE:
486 iTCO_wdt_keepalive();
487 return 0;
488
489 case WDIOC_SETOPTIONS:
490 {
491 if (get_user(new_options, p))
492 return -EFAULT;
493
494 if (new_options & WDIOS_DISABLECARD) {
495 iTCO_wdt_stop();
496 retval = 0;
497 }
498
499 if (new_options & WDIOS_ENABLECARD) {
500 iTCO_wdt_keepalive();
501 iTCO_wdt_start();
502 retval = 0;
503 }
504
505 return retval;
506 }
507
508 case WDIOC_SETTIMEOUT:
509 {
510 if (get_user(new_heartbeat, p))
511 return -EFAULT;
512
513 if (iTCO_wdt_set_heartbeat(new_heartbeat))
514 return -EINVAL;
515
516 iTCO_wdt_keepalive();
517 /* Fall */
518 }
519
520 case WDIOC_GETTIMEOUT:
521 return put_user(heartbeat, p);
522
523 case WDIOC_GETTIMELEFT:
524 {
525 int time_left;
526
527 if (iTCO_wdt_get_timeleft(&time_left))
528 return -EINVAL;
529
530 return put_user(time_left, p);
531 }
532
533 default:
534 return -ENOTTY;
535 }
536}
537
538/*
539 * Kernel Interfaces
540 */
541
542static struct file_operations iTCO_wdt_fops = {
543 .owner = THIS_MODULE,
544 .llseek = no_llseek,
545 .write = iTCO_wdt_write,
546 .ioctl = iTCO_wdt_ioctl,
547 .open = iTCO_wdt_open,
548 .release = iTCO_wdt_release,
549};
550
551static struct miscdevice iTCO_wdt_miscdev = {
552 .minor = WATCHDOG_MINOR,
553 .name = "watchdog",
554 .fops = &iTCO_wdt_fops,
555};
556
557/*
558 * Init & exit routines
559 */
560
561static int iTCO_wdt_init(struct pci_dev *pdev, const struct pci_device_id *ent, struct platform_device *dev)
562{
563 int ret;
564 u32 base_address;
565 unsigned long RCBA;
566 unsigned long val32;
567
568 /*
569 * Find the ACPI/PM base I/O address which is the base
570 * for the TCO registers (TCOBASE=ACPIBASE + 0x60)
571 * ACPIBASE is bits [15:7] from 0x40-0x43
572 */
573 pci_read_config_dword(pdev, 0x40, &base_address);
574 base_address &= 0x00007f80;
575 if (base_address == 0x00000000) {
576 /* Something's wrong here, ACPIBASE has to be set */
577 printk(KERN_ERR PFX "failed to get TCOBASE address\n");
578 pci_dev_put(pdev);
579 return -ENODEV;
580 }
581 iTCO_wdt_private.iTCO_version = iTCO_chipset_info[ent->driver_data].iTCO_version;
582 iTCO_wdt_private.ACPIBASE = base_address;
583 iTCO_wdt_private.pdev = pdev;
584
585 /* Get the Memory-Mapped GCS register, we need it for the NO_REBOOT flag (TCO v2) */
586 /* To get access to it you have to read RCBA from PCI Config space 0xf0
587 and use it as base. GCS = RCBA + ICH6_GCS(0x3410). */
588 if (iTCO_wdt_private.iTCO_version == 2) {
589 pci_read_config_dword(pdev, 0xf0, &base_address);
590 RCBA = base_address & 0xffffc000;
591 iTCO_wdt_private.gcs = ioremap((RCBA + 0x3410),4);
592 }
593
594 /* Check chipset's NO_REBOOT bit */
595 if (iTCO_wdt_unset_NO_REBOOT_bit() && iTCO_vendor_check_noreboot_on()) {
596 printk(KERN_ERR PFX "failed to reset NO_REBOOT flag, reboot disabled by hardware\n");
597 ret = -ENODEV; /* Cannot reset NO_REBOOT bit */
598 goto out;
599 }
600
601 /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
602 iTCO_wdt_set_NO_REBOOT_bit();
603
604 /* Set the TCO_EN bit in SMI_EN register */
605 if (!request_region(SMI_EN, 4, "iTCO_wdt")) {
606 printk(KERN_ERR PFX "I/O address 0x%04lx already in use\n",
607 SMI_EN );
608 ret = -EIO;
609 goto out;
610 }
611 val32 = inl(SMI_EN);
612 val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
613 outl(val32, SMI_EN);
614 release_region(SMI_EN, 4);
615
616 /* The TCO I/O registers reside in a 32-byte range pointed to by the TCOBASE value */
617 if (!request_region (TCOBASE, 0x20, "iTCO_wdt")) {
618 printk (KERN_ERR PFX "I/O address 0x%04lx already in use\n",
619 TCOBASE);
620 ret = -EIO;
621 goto out;
622 }
623
624 printk(KERN_INFO PFX "Found a %s TCO device (Version=%d, TCOBASE=0x%04lx)\n",
625 iTCO_chipset_info[ent->driver_data].name,
626 iTCO_chipset_info[ent->driver_data].iTCO_version,
627 TCOBASE);
628
629 /* Clear out the (probably old) status */
630 outb(0, TCO1_STS);
631 outb(3, TCO2_STS);
632
633 /* Make sure the watchdog is not running */
634 iTCO_wdt_stop();
635
636 /* Check that the heartbeat value is within it's range ; if not reset to the default */
637 if (iTCO_wdt_set_heartbeat(heartbeat)) {
638 iTCO_wdt_set_heartbeat(WATCHDOG_HEARTBEAT);
639 printk(KERN_INFO PFX "heartbeat value must be 2<heartbeat<39 (TCO v1) or 613 (TCO v2), using %d\n",
640 heartbeat);
641 }
642
643 ret = misc_register(&iTCO_wdt_miscdev);
644 if (ret != 0) {
645 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
646 WATCHDOG_MINOR, ret);
647 goto unreg_region;
648 }
649
650 printk (KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
651 heartbeat, nowayout);
652
653 return 0;
654
655unreg_region:
656 release_region (TCOBASE, 0x20);
657out:
658 if (iTCO_wdt_private.iTCO_version == 2)
659 iounmap(iTCO_wdt_private.gcs);
660 pci_dev_put(iTCO_wdt_private.pdev);
661 iTCO_wdt_private.ACPIBASE = 0;
662 return ret;
663}
664
665static void iTCO_wdt_cleanup(void)
666{
667 /* Stop the timer before we leave */
668 if (!nowayout)
669 iTCO_wdt_stop();
670
671 /* Deregister */
672 misc_deregister(&iTCO_wdt_miscdev);
673 release_region(TCOBASE, 0x20);
674 if (iTCO_wdt_private.iTCO_version == 2)
675 iounmap(iTCO_wdt_private.gcs);
676 pci_dev_put(iTCO_wdt_private.pdev);
677 iTCO_wdt_private.ACPIBASE = 0;
678}
679
680static int iTCO_wdt_probe(struct platform_device *dev)
681{
682 int found = 0;
683 struct pci_dev *pdev = NULL;
684 const struct pci_device_id *ent;
685
686 spin_lock_init(&iTCO_wdt_private.io_lock);
687
688 for_each_pci_dev(pdev) {
689 ent = pci_match_id(iTCO_wdt_pci_tbl, pdev);
690 if (ent) {
691 if (!(iTCO_wdt_init(pdev, ent, dev))) {
692 found++;
693 break;
694 }
695 }
696 }
697
698 if (!found) {
699 printk(KERN_INFO PFX "No card detected\n");
700 return -ENODEV;
701 }
702
703 return 0;
704}
705
706static int iTCO_wdt_remove(struct platform_device *dev)
707{
708 if (iTCO_wdt_private.ACPIBASE)
709 iTCO_wdt_cleanup();
710
711 return 0;
712}
713
714static void iTCO_wdt_shutdown(struct platform_device *dev)
715{
716 iTCO_wdt_stop();
717}
718
719#define iTCO_wdt_suspend NULL
720#define iTCO_wdt_resume NULL
721
722static struct platform_driver iTCO_wdt_driver = {
723 .probe = iTCO_wdt_probe,
724 .remove = iTCO_wdt_remove,
725 .shutdown = iTCO_wdt_shutdown,
726 .suspend = iTCO_wdt_suspend,
727 .resume = iTCO_wdt_resume,
728 .driver = {
729 .owner = THIS_MODULE,
730 .name = DRV_NAME,
731 },
732};
733
734static int __init iTCO_wdt_init_module(void)
735{
736 int err;
737
738 printk(KERN_INFO PFX "Intel TCO WatchDog Timer Driver v%s (%s)\n",
739 DRV_VERSION, DRV_RELDATE);
740
741 err = platform_driver_register(&iTCO_wdt_driver);
742 if (err)
743 return err;
744
745 iTCO_wdt_platform_device = platform_device_register_simple(DRV_NAME, -1, NULL, 0);
746 if (IS_ERR(iTCO_wdt_platform_device)) {
747 err = PTR_ERR(iTCO_wdt_platform_device);
748 goto unreg_platform_driver;
749 }
750
751 return 0;
752
753unreg_platform_driver:
754 platform_driver_unregister(&iTCO_wdt_driver);
755 return err;
756}
757
758static void __exit iTCO_wdt_cleanup_module(void)
759{
760 platform_device_unregister(iTCO_wdt_platform_device);
761 platform_driver_unregister(&iTCO_wdt_driver);
762 printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
763}
764
765module_init(iTCO_wdt_init_module);
766module_exit(iTCO_wdt_cleanup_module);
767
768MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
769MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver");
770MODULE_VERSION(DRV_VERSION);
771MODULE_LICENSE("GPL");
772MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/char/watchdog/ib700wdt.c b/drivers/char/watchdog/ib700wdt.c
index fd95f7327798..c1ed209a138c 100644
--- a/drivers/char/watchdog/ib700wdt.c
+++ b/drivers/char/watchdog/ib700wdt.c
@@ -199,7 +199,7 @@ ibwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
199 break; 199 break;
200 200
201 default: 201 default:
202 return -ENOIOCTLCMD; 202 return -ENOTTY;
203 } 203 }
204 return 0; 204 return 0;
205} 205}
diff --git a/drivers/char/watchdog/ibmasr.c b/drivers/char/watchdog/ibmasr.c
index 26ceee7a4df0..dd6760f1a23b 100644
--- a/drivers/char/watchdog/ibmasr.c
+++ b/drivers/char/watchdog/ibmasr.c
@@ -295,7 +295,7 @@ static int asr_ioctl(struct inode *inode, struct file *file,
295 } 295 }
296 } 296 }
297 297
298 return -ENOIOCTLCMD; 298 return -ENOTTY;
299} 299}
300 300
301static int asr_open(struct inode *inode, struct file *file) 301static int asr_open(struct inode *inode, struct file *file)
diff --git a/drivers/char/watchdog/indydog.c b/drivers/char/watchdog/indydog.c
index dacc1c20a310..0bc239308989 100644
--- a/drivers/char/watchdog/indydog.c
+++ b/drivers/char/watchdog/indydog.c
@@ -112,7 +112,7 @@ static int indydog_ioctl(struct inode *inode, struct file *file,
112 112
113 switch (cmd) { 113 switch (cmd) {
114 default: 114 default:
115 return -ENOIOCTLCMD; 115 return -ENOTTY;
116 case WDIOC_GETSUPPORT: 116 case WDIOC_GETSUPPORT:
117 if (copy_to_user((struct watchdog_info *)arg, 117 if (copy_to_user((struct watchdog_info *)arg,
118 &ident, sizeof(ident))) 118 &ident, sizeof(ident)))
diff --git a/drivers/char/watchdog/ixp2000_wdt.c b/drivers/char/watchdog/ixp2000_wdt.c
index 692908819e26..fd955dbd588c 100644
--- a/drivers/char/watchdog/ixp2000_wdt.c
+++ b/drivers/char/watchdog/ixp2000_wdt.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * drivers/watchdog/ixp2000_wdt.c 2 * drivers/char/watchdog/ixp2000_wdt.c
3 * 3 *
4 * Watchdog driver for Intel IXP2000 network processors 4 * Watchdog driver for Intel IXP2000 network processors
5 * 5 *
@@ -107,7 +107,7 @@ static int
107ixp2000_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 107ixp2000_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
108 unsigned long arg) 108 unsigned long arg)
109{ 109{
110 int ret = -ENOIOCTLCMD; 110 int ret = -ENOTTY;
111 int time; 111 int time;
112 112
113 switch (cmd) { 113 switch (cmd) {
diff --git a/drivers/char/watchdog/ixp4xx_wdt.c b/drivers/char/watchdog/ixp4xx_wdt.c
index 9db5cf2c38c3..5864bb865cfe 100644
--- a/drivers/char/watchdog/ixp4xx_wdt.c
+++ b/drivers/char/watchdog/ixp4xx_wdt.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * drivers/watchdog/ixp4xx_wdt.c 2 * drivers/char/watchdog/ixp4xx_wdt.c
3 * 3 *
4 * Watchdog driver for Intel IXP4xx network processors 4 * Watchdog driver for Intel IXP4xx network processors
5 * 5 *
@@ -102,7 +102,7 @@ static int
102ixp4xx_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 102ixp4xx_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
103 unsigned long arg) 103 unsigned long arg)
104{ 104{
105 int ret = -ENOIOCTLCMD; 105 int ret = -ENOTTY;
106 int time; 106 int time;
107 107
108 switch (cmd) { 108 switch (cmd) {
diff --git a/drivers/char/watchdog/machzwd.c b/drivers/char/watchdog/machzwd.c
index 23734e07fb22..276577d08fba 100644
--- a/drivers/char/watchdog/machzwd.c
+++ b/drivers/char/watchdog/machzwd.c
@@ -329,7 +329,7 @@ static int zf_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
329 break; 329 break;
330 330
331 default: 331 default:
332 return -ENOIOCTLCMD; 332 return -ENOTTY;
333 } 333 }
334 334
335 return 0; 335 return 0;
@@ -426,8 +426,7 @@ static int __init zf_init(void)
426 printk(KERN_INFO PFX ": MachZ ZF-Logic Watchdog driver initializing.\n"); 426 printk(KERN_INFO PFX ": MachZ ZF-Logic Watchdog driver initializing.\n");
427 427
428 ret = zf_get_ZFL_version(); 428 ret = zf_get_ZFL_version();
429 printk("%#x\n", ret); 429 if ((!ret) || (ret == 0xffff)) {
430 if((!ret) || (ret != 0xffff)){
431 printk(KERN_WARNING PFX ": no ZF-Logic found\n"); 430 printk(KERN_WARNING PFX ": no ZF-Logic found\n");
432 return -ENODEV; 431 return -ENODEV;
433 } 432 }
diff --git a/drivers/char/watchdog/mixcomwd.c b/drivers/char/watchdog/mixcomwd.c
index ae943324d251..c2dac0aa1d62 100644
--- a/drivers/char/watchdog/mixcomwd.c
+++ b/drivers/char/watchdog/mixcomwd.c
@@ -185,7 +185,7 @@ static int mixcomwd_ioctl(struct inode *inode, struct file *file,
185 mixcomwd_ping(); 185 mixcomwd_ping();
186 break; 186 break;
187 default: 187 default:
188 return -ENOIOCTLCMD; 188 return -ENOTTY;
189 } 189 }
190 return 0; 190 return 0;
191} 191}
diff --git a/drivers/char/watchdog/mpc83xx_wdt.c b/drivers/char/watchdog/mpc83xx_wdt.c
index a480903ee1a5..18ca752e2f90 100644
--- a/drivers/char/watchdog/mpc83xx_wdt.c
+++ b/drivers/char/watchdog/mpc83xx_wdt.c
@@ -125,7 +125,7 @@ static int mpc83xx_wdt_ioctl(struct inode *inode, struct file *file,
125 case WDIOC_GETTIMEOUT: 125 case WDIOC_GETTIMEOUT:
126 return put_user(timeout_sec, p); 126 return put_user(timeout_sec, p);
127 default: 127 default:
128 return -ENOIOCTLCMD; 128 return -ENOTTY;
129 } 129 }
130} 130}
131 131
diff --git a/drivers/char/watchdog/mpc8xx_wdt.c b/drivers/char/watchdog/mpc8xx_wdt.c
index 35dd9e6e1140..8aaed10dd499 100644
--- a/drivers/char/watchdog/mpc8xx_wdt.c
+++ b/drivers/char/watchdog/mpc8xx_wdt.c
@@ -126,7 +126,7 @@ static int mpc8xx_wdt_ioctl(struct inode *inode, struct file *file,
126 break; 126 break;
127 127
128 default: 128 default:
129 return -ENOIOCTLCMD; 129 return -ENOTTY;
130 } 130 }
131 131
132 return 0; 132 return 0;
diff --git a/drivers/char/watchdog/mpcore_wdt.c b/drivers/char/watchdog/mpcore_wdt.c
index 54b3c56ead0d..3404a9c67f08 100644
--- a/drivers/char/watchdog/mpcore_wdt.c
+++ b/drivers/char/watchdog/mpcore_wdt.c
@@ -64,7 +64,7 @@ MODULE_PARM_DESC(mpcore_noboot, "MPcore watchdog action, set to 1 to ignore rebo
64 * This is the interrupt handler. Note that we only use this 64 * This is the interrupt handler. Note that we only use this
65 * in testing mode, so don't actually do a reboot here. 65 * in testing mode, so don't actually do a reboot here.
66 */ 66 */
67static irqreturn_t mpcore_wdt_fire(int irq, void *arg, struct pt_regs *regs) 67static irqreturn_t mpcore_wdt_fire(int irq, void *arg)
68{ 68{
69 struct mpcore_wdt *wdt = arg; 69 struct mpcore_wdt *wdt = arg;
70 70
@@ -221,7 +221,7 @@ static int mpcore_wdt_ioctl(struct inode *inode, struct file *file,
221 } uarg; 221 } uarg;
222 222
223 if (_IOC_DIR(cmd) && _IOC_SIZE(cmd) > sizeof(uarg)) 223 if (_IOC_DIR(cmd) && _IOC_SIZE(cmd) > sizeof(uarg))
224 return -ENOIOCTLCMD; 224 return -ENOTTY;
225 225
226 if (_IOC_DIR(cmd) & _IOC_WRITE) { 226 if (_IOC_DIR(cmd) & _IOC_WRITE) {
227 ret = copy_from_user(&uarg, (void __user *)arg, _IOC_SIZE(cmd)); 227 ret = copy_from_user(&uarg, (void __user *)arg, _IOC_SIZE(cmd));
@@ -271,7 +271,7 @@ static int mpcore_wdt_ioctl(struct inode *inode, struct file *file,
271 break; 271 break;
272 272
273 default: 273 default:
274 return -ENOIOCTLCMD; 274 return -ENOTTY;
275 } 275 }
276 276
277 if (ret == 0 && _IOC_DIR(cmd) & _IOC_READ) { 277 if (ret == 0 && _IOC_DIR(cmd) & _IOC_READ) {
diff --git a/drivers/char/watchdog/mv64x60_wdt.c b/drivers/char/watchdog/mv64x60_wdt.c
index 5c8fab345b40..b887cdb01334 100644
--- a/drivers/char/watchdog/mv64x60_wdt.c
+++ b/drivers/char/watchdog/mv64x60_wdt.c
@@ -160,7 +160,7 @@ static int mv64x60_wdt_ioctl(struct inode *inode, struct file *file,
160 break; 160 break;
161 161
162 default: 162 default:
163 return -ENOIOCTLCMD; 163 return -ENOTTY;
164 } 164 }
165 165
166 return 0; 166 return 0;
diff --git a/drivers/char/watchdog/omap_wdt.c b/drivers/char/watchdog/omap_wdt.c
new file mode 100644
index 000000000000..5dbd7dc2936f
--- /dev/null
+++ b/drivers/char/watchdog/omap_wdt.c
@@ -0,0 +1,390 @@
1/*
2 * linux/drivers/char/watchdog/omap_wdt.c
3 *
4 * Watchdog driver for the TI OMAP 16xx & 24xx 32KHz (non-secure) watchdog
5 *
6 * Author: MontaVista Software, Inc.
7 * <gdavis@mvista.com> or <source@mvista.com>
8 *
9 * 2003 (c) MontaVista Software, Inc. This file is licensed under the
10 * terms of the GNU General Public License version 2. This program is
11 * licensed "as is" without any warranty of any kind, whether express
12 * or implied.
13 *
14 * History:
15 *
16 * 20030527: George G. Davis <gdavis@mvista.com>
17 * Initially based on linux-2.4.19-rmk7-pxa1/drivers/char/sa1100_wdt.c
18 * (c) Copyright 2000 Oleg Drokin <green@crimea.edu>
19 * Based on SoftDog driver by Alan Cox <alan@redhat.com>
20 *
21 * Copyright (c) 2004 Texas Instruments.
22 * 1. Modified to support OMAP1610 32-KHz watchdog timer
23 * 2. Ported to 2.6 kernel
24 *
25 * Copyright (c) 2005 David Brownell
26 * Use the driver model and standard identifiers; handle bigger timeouts.
27 */
28
29#include <linux/module.h>
30#include <linux/types.h>
31#include <linux/kernel.h>
32#include <linux/fs.h>
33#include <linux/mm.h>
34#include <linux/miscdevice.h>
35#include <linux/watchdog.h>
36#include <linux/reboot.h>
37#include <linux/smp_lock.h>
38#include <linux/init.h>
39#include <linux/err.h>
40#include <linux/platform_device.h>
41#include <linux/moduleparam.h>
42#include <linux/clk.h>
43
44#include <asm/io.h>
45#include <asm/uaccess.h>
46#include <asm/hardware.h>
47#include <asm/bitops.h>
48
49#include <asm/arch/prcm.h>
50
51#include "omap_wdt.h"
52
53static unsigned timer_margin;
54module_param(timer_margin, uint, 0);
55MODULE_PARM_DESC(timer_margin, "initial watchdog timeout (in seconds)");
56
57static int omap_wdt_users;
58static struct clk *armwdt_ck = NULL;
59static struct clk *mpu_wdt_ick = NULL;
60static struct clk *mpu_wdt_fck = NULL;
61
62static unsigned int wdt_trgr_pattern = 0x1234;
63
64static void omap_wdt_ping(void)
65{
66 /* wait for posted write to complete */
67 while ((omap_readl(OMAP_WATCHDOG_WPS)) & 0x08)
68 cpu_relax();
69 wdt_trgr_pattern = ~wdt_trgr_pattern;
70 omap_writel(wdt_trgr_pattern, (OMAP_WATCHDOG_TGR));
71 /* wait for posted write to complete */
72 while ((omap_readl(OMAP_WATCHDOG_WPS)) & 0x08)
73 cpu_relax();
74 /* reloaded WCRR from WLDR */
75}
76
77static void omap_wdt_enable(void)
78{
79 /* Sequence to enable the watchdog */
80 omap_writel(0xBBBB, OMAP_WATCHDOG_SPR);
81 while ((omap_readl(OMAP_WATCHDOG_WPS)) & 0x10)
82 cpu_relax();
83 omap_writel(0x4444, OMAP_WATCHDOG_SPR);
84 while ((omap_readl(OMAP_WATCHDOG_WPS)) & 0x10)
85 cpu_relax();
86}
87
88static void omap_wdt_disable(void)
89{
90 /* sequence required to disable watchdog */
91 omap_writel(0xAAAA, OMAP_WATCHDOG_SPR); /* TIMER_MODE */
92 while (omap_readl(OMAP_WATCHDOG_WPS) & 0x10)
93 cpu_relax();
94 omap_writel(0x5555, OMAP_WATCHDOG_SPR); /* TIMER_MODE */
95 while (omap_readl(OMAP_WATCHDOG_WPS) & 0x10)
96 cpu_relax();
97}
98
99static void omap_wdt_adjust_timeout(unsigned new_timeout)
100{
101 if (new_timeout < TIMER_MARGIN_MIN)
102 new_timeout = TIMER_MARGIN_DEFAULT;
103 if (new_timeout > TIMER_MARGIN_MAX)
104 new_timeout = TIMER_MARGIN_MAX;
105 timer_margin = new_timeout;
106}
107
108static void omap_wdt_set_timeout(void)
109{
110 u32 pre_margin = GET_WLDR_VAL(timer_margin);
111
112 /* just count up at 32 KHz */
113 while (omap_readl(OMAP_WATCHDOG_WPS) & 0x04)
114 cpu_relax();
115 omap_writel(pre_margin, OMAP_WATCHDOG_LDR);
116 while (omap_readl(OMAP_WATCHDOG_WPS) & 0x04)
117 cpu_relax();
118}
119
120/*
121 * Allow only one task to hold it open
122 */
123
124static int omap_wdt_open(struct inode *inode, struct file *file)
125{
126 if (test_and_set_bit(1, (unsigned long *)&omap_wdt_users))
127 return -EBUSY;
128
129 if (cpu_is_omap16xx())
130 clk_enable(armwdt_ck); /* Enable the clock */
131
132 if (cpu_is_omap24xx()) {
133 clk_enable(mpu_wdt_ick); /* Enable the interface clock */
134 clk_enable(mpu_wdt_fck); /* Enable the functional clock */
135 }
136
137 /* initialize prescaler */
138 while (omap_readl(OMAP_WATCHDOG_WPS) & 0x01)
139 cpu_relax();
140 omap_writel((1 << 5) | (PTV << 2), OMAP_WATCHDOG_CNTRL);
141 while (omap_readl(OMAP_WATCHDOG_WPS) & 0x01)
142 cpu_relax();
143
144 omap_wdt_set_timeout();
145 omap_wdt_enable();
146 return 0;
147}
148
149static int omap_wdt_release(struct inode *inode, struct file *file)
150{
151 /*
152 * Shut off the timer unless NOWAYOUT is defined.
153 */
154#ifndef CONFIG_WATCHDOG_NOWAYOUT
155 omap_wdt_disable();
156
157 if (cpu_is_omap16xx()) {
158 clk_disable(armwdt_ck); /* Disable the clock */
159 clk_put(armwdt_ck);
160 armwdt_ck = NULL;
161 }
162
163 if (cpu_is_omap24xx()) {
164 clk_disable(mpu_wdt_ick); /* Disable the clock */
165 clk_disable(mpu_wdt_fck); /* Disable the clock */
166 clk_put(mpu_wdt_ick);
167 clk_put(mpu_wdt_fck);
168 mpu_wdt_ick = NULL;
169 mpu_wdt_fck = NULL;
170 }
171#else
172 printk(KERN_CRIT "omap_wdt: Unexpected close, not stopping!\n");
173#endif
174 omap_wdt_users = 0;
175 return 0;
176}
177
178static ssize_t
179omap_wdt_write(struct file *file, const char __user *data,
180 size_t len, loff_t *ppos)
181{
182 /* Refresh LOAD_TIME. */
183 if (len)
184 omap_wdt_ping();
185 return len;
186}
187
188static int
189omap_wdt_ioctl(struct inode *inode, struct file *file,
190 unsigned int cmd, unsigned long arg)
191{
192 int new_margin;
193 static struct watchdog_info ident = {
194 .identity = "OMAP Watchdog",
195 .options = WDIOF_SETTIMEOUT,
196 .firmware_version = 0,
197 };
198
199 switch (cmd) {
200 default:
201 return -ENOIOCTLCMD;
202 case WDIOC_GETSUPPORT:
203 return copy_to_user((struct watchdog_info __user *)arg, &ident,
204 sizeof(ident));
205 case WDIOC_GETSTATUS:
206 return put_user(0, (int __user *)arg);
207 case WDIOC_GETBOOTSTATUS:
208 if (cpu_is_omap16xx())
209 return put_user(omap_readw(ARM_SYSST),
210 (int __user *)arg);
211 if (cpu_is_omap24xx())
212 return put_user(omap_prcm_get_reset_sources(),
213 (int __user *)arg);
214 case WDIOC_KEEPALIVE:
215 omap_wdt_ping();
216 return 0;
217 case WDIOC_SETTIMEOUT:
218 if (get_user(new_margin, (int __user *)arg))
219 return -EFAULT;
220 omap_wdt_adjust_timeout(new_margin);
221
222 omap_wdt_disable();
223 omap_wdt_set_timeout();
224 omap_wdt_enable();
225
226 omap_wdt_ping();
227 /* Fall */
228 case WDIOC_GETTIMEOUT:
229 return put_user(timer_margin, (int __user *)arg);
230 }
231}
232
233static struct file_operations omap_wdt_fops = {
234 .owner = THIS_MODULE,
235 .write = omap_wdt_write,
236 .ioctl = omap_wdt_ioctl,
237 .open = omap_wdt_open,
238 .release = omap_wdt_release,
239};
240
241static struct miscdevice omap_wdt_miscdev = {
242 .minor = WATCHDOG_MINOR,
243 .name = "watchdog",
244 .fops = &omap_wdt_fops
245};
246
247static int __init omap_wdt_probe(struct platform_device *pdev)
248{
249 struct resource *res, *mem;
250 int ret;
251
252 /* reserve static register mappings */
253 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
254 if (!res)
255 return -ENOENT;
256
257 mem = request_mem_region(res->start, res->end - res->start + 1,
258 pdev->name);
259 if (mem == NULL)
260 return -EBUSY;
261
262 platform_set_drvdata(pdev, mem);
263
264 omap_wdt_users = 0;
265
266 if (cpu_is_omap16xx()) {
267 armwdt_ck = clk_get(&pdev->dev, "armwdt_ck");
268 if (IS_ERR(armwdt_ck)) {
269 ret = PTR_ERR(armwdt_ck);
270 armwdt_ck = NULL;
271 goto fail;
272 }
273 }
274
275 if (cpu_is_omap24xx()) {
276 mpu_wdt_ick = clk_get(&pdev->dev, "mpu_wdt_ick");
277 if (IS_ERR(mpu_wdt_ick)) {
278 ret = PTR_ERR(mpu_wdt_ick);
279 mpu_wdt_ick = NULL;
280 goto fail;
281 }
282 mpu_wdt_fck = clk_get(&pdev->dev, "mpu_wdt_fck");
283 if (IS_ERR(mpu_wdt_fck)) {
284 ret = PTR_ERR(mpu_wdt_fck);
285 mpu_wdt_fck = NULL;
286 goto fail;
287 }
288 }
289
290 omap_wdt_disable();
291 omap_wdt_adjust_timeout(timer_margin);
292
293 omap_wdt_miscdev.dev = &pdev->dev;
294 ret = misc_register(&omap_wdt_miscdev);
295 if (ret)
296 goto fail;
297
298 pr_info("OMAP Watchdog Timer: initial timeout %d sec\n", timer_margin);
299
300 /* autogate OCP interface clock */
301 omap_writel(0x01, OMAP_WATCHDOG_SYS_CONFIG);
302 return 0;
303
304fail:
305 if (armwdt_ck)
306 clk_put(armwdt_ck);
307 if (mpu_wdt_ick)
308 clk_put(mpu_wdt_ick);
309 if (mpu_wdt_fck)
310 clk_put(mpu_wdt_fck);
311 release_resource(mem);
312 return ret;
313}
314
315static void omap_wdt_shutdown(struct platform_device *pdev)
316{
317 omap_wdt_disable();
318}
319
320static int omap_wdt_remove(struct platform_device *pdev)
321{
322 struct resource *mem = platform_get_drvdata(pdev);
323 misc_deregister(&omap_wdt_miscdev);
324 release_resource(mem);
325 if (armwdt_ck)
326 clk_put(armwdt_ck);
327 if (mpu_wdt_ick)
328 clk_put(mpu_wdt_ick);
329 if (mpu_wdt_fck)
330 clk_put(mpu_wdt_fck);
331 return 0;
332}
333
334#ifdef CONFIG_PM
335
336/* REVISIT ... not clear this is the best way to handle system suspend; and
337 * it's very inappropriate for selective device suspend (e.g. suspending this
338 * through sysfs rather than by stopping the watchdog daemon). Also, this
339 * may not play well enough with NOWAYOUT...
340 */
341
342static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state)
343{
344 if (omap_wdt_users)
345 omap_wdt_disable();
346 return 0;
347}
348
349static int omap_wdt_resume(struct platform_device *pdev)
350{
351 if (omap_wdt_users) {
352 omap_wdt_enable();
353 omap_wdt_ping();
354 }
355 return 0;
356}
357
358#else
359#define omap_wdt_suspend NULL
360#define omap_wdt_resume NULL
361#endif
362
363static struct platform_driver omap_wdt_driver = {
364 .probe = omap_wdt_probe,
365 .remove = omap_wdt_remove,
366 .shutdown = omap_wdt_shutdown,
367 .suspend = omap_wdt_suspend,
368 .resume = omap_wdt_resume,
369 .driver = {
370 .owner = THIS_MODULE,
371 .name = "omap_wdt",
372 },
373};
374
375static int __init omap_wdt_init(void)
376{
377 return platform_driver_register(&omap_wdt_driver);
378}
379
380static void __exit omap_wdt_exit(void)
381{
382 platform_driver_unregister(&omap_wdt_driver);
383}
384
385module_init(omap_wdt_init);
386module_exit(omap_wdt_exit);
387
388MODULE_AUTHOR("George G. Davis");
389MODULE_LICENSE("GPL");
390MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/char/watchdog/omap_wdt.h b/drivers/char/watchdog/omap_wdt.h
new file mode 100644
index 000000000000..52a532a5114a
--- /dev/null
+++ b/drivers/char/watchdog/omap_wdt.h
@@ -0,0 +1,64 @@
1/*
2 * linux/drivers/char/watchdog/omap_wdt.h
3 *
4 * BRIEF MODULE DESCRIPTION
5 * OMAP Watchdog timer register definitions
6 *
7 * Copyright (C) 2004 Texas Instruments.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
20 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 675 Mass Ave, Cambridge, MA 02139, USA.
28 */
29
30#ifndef _OMAP_WATCHDOG_H
31#define _OMAP_WATCHDOG_H
32
33#define OMAP1610_WATCHDOG_BASE 0xfffeb000
34#define OMAP2420_WATCHDOG_BASE 0x48022000 /*WDT Timer 2 */
35
36#ifdef CONFIG_ARCH_OMAP24XX
37#define OMAP_WATCHDOG_BASE OMAP2420_WATCHDOG_BASE
38#else
39#define OMAP_WATCHDOG_BASE OMAP1610_WATCHDOG_BASE
40#define RM_RSTST_WKUP 0
41#endif
42
43#define OMAP_WATCHDOG_REV (OMAP_WATCHDOG_BASE + 0x00)
44#define OMAP_WATCHDOG_SYS_CONFIG (OMAP_WATCHDOG_BASE + 0x10)
45#define OMAP_WATCHDOG_STATUS (OMAP_WATCHDOG_BASE + 0x14)
46#define OMAP_WATCHDOG_CNTRL (OMAP_WATCHDOG_BASE + 0x24)
47#define OMAP_WATCHDOG_CRR (OMAP_WATCHDOG_BASE + 0x28)
48#define OMAP_WATCHDOG_LDR (OMAP_WATCHDOG_BASE + 0x2c)
49#define OMAP_WATCHDOG_TGR (OMAP_WATCHDOG_BASE + 0x30)
50#define OMAP_WATCHDOG_WPS (OMAP_WATCHDOG_BASE + 0x34)
51#define OMAP_WATCHDOG_SPR (OMAP_WATCHDOG_BASE + 0x48)
52
53/* Using the prescaler, the OMAP watchdog could go for many
54 * months before firing. These limits work without scaling,
55 * with the 60 second default assumed by most tools and docs.
56 */
57#define TIMER_MARGIN_MAX (24 * 60 * 60) /* 1 day */
58#define TIMER_MARGIN_DEFAULT 60 /* 60 secs */
59#define TIMER_MARGIN_MIN 1
60
61#define PTV 0 /* prescale */
62#define GET_WLDR_VAL(secs) (0xffffffff - ((secs) * (32768/(1<<PTV))) + 1)
63
64#endif /* _OMAP_WATCHDOG_H */
diff --git a/drivers/char/watchdog/pc87413_wdt.c b/drivers/char/watchdog/pc87413_wdt.c
new file mode 100644
index 000000000000..1d447e32af41
--- /dev/null
+++ b/drivers/char/watchdog/pc87413_wdt.c
@@ -0,0 +1,635 @@
1/*
2 * NS pc87413-wdt Watchdog Timer driver for Linux 2.6.x.x
3 *
4 * This code is based on wdt.c with original copyright.
5 *
6 * (C) Copyright 2006 Sven Anders, <anders@anduras.de>
7 * and Marcus Junker, <junker@anduras.de>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 *
14 * Neither Sven Anders, Marcus Junker nor ANDURAS AG
15 * admit liability nor provide warranty for any of this software.
16 * This material is provided "AS-IS" and at no charge.
17 *
18 * Release 1.1
19 */
20
21#include <linux/module.h>
22#include <linux/types.h>
23#include <linux/miscdevice.h>
24#include <linux/watchdog.h>
25#include <linux/ioport.h>
26#include <linux/delay.h>
27#include <linux/notifier.h>
28#include <linux/fs.h>
29#include <linux/reboot.h>
30#include <linux/init.h>
31#include <linux/spinlock.h>
32#include <linux/moduleparam.h>
33#include <linux/version.h>
34
35#include <asm/io.h>
36#include <asm/uaccess.h>
37#include <asm/system.h>
38
39/* #define DEBUG 1 */
40
41#define DEFAULT_TIMEOUT 1 /* 1 minute */
42#define MAX_TIMEOUT 255
43
44#define VERSION "1.1"
45#define MODNAME "pc87413 WDT"
46#define PFX MODNAME ": "
47#define DPFX MODNAME " - DEBUG: "
48
49#define WDT_INDEX_IO_PORT (io+0) /* I/O port base (index register) */
50#define WDT_DATA_IO_PORT (WDT_INDEX_IO_PORT+1)
51#define SWC_LDN 0x04
52#define SIOCFG2 0x22 /* Serial IO register */
53#define WDCTL 0x10 /* Watchdog-Timer-Controll-Register */
54#define WDTO 0x11 /* Watchdog timeout register */
55#define WDCFG 0x12 /* Watchdog config register */
56
57static int io = 0x2E; /* Address used on Portwell Boards */
58
59static int timeout = DEFAULT_TIMEOUT; /* timeout value */
60static unsigned long timer_enabled = 0; /* is the timer enabled? */
61
62static char expect_close; /* is the close expected? */
63
64static spinlock_t io_lock; /* to guard the watchdog from io races */
65
66static int nowayout = WATCHDOG_NOWAYOUT;
67
68/* -- Low level function ----------------------------------------*/
69
70/* Select pins for Watchdog output */
71
72static inline void pc87413_select_wdt_out (void)
73{
74 unsigned int cr_data = 0;
75
76 /* Step 1: Select multiple pin,pin55,as WDT output */
77
78 outb_p(SIOCFG2, WDT_INDEX_IO_PORT);
79
80 cr_data = inb (WDT_DATA_IO_PORT);
81
82 cr_data |= 0x80; /* Set Bit7 to 1*/
83 outb_p(SIOCFG2, WDT_INDEX_IO_PORT);
84
85 outb_p(cr_data, WDT_DATA_IO_PORT);
86
87#ifdef DEBUG
88 printk(KERN_INFO DPFX "Select multiple pin,pin55,as WDT output:"
89 " Bit7 to 1: %d\n", cr_data);
90#endif
91}
92
93/* Enable SWC functions */
94
95static inline void pc87413_enable_swc(void)
96{
97 unsigned int cr_data=0;
98
99 /* Step 2: Enable SWC functions */
100
101 outb_p(0x07, WDT_INDEX_IO_PORT); /* Point SWC_LDN (LDN=4) */
102 outb_p(SWC_LDN, WDT_DATA_IO_PORT);
103
104 outb_p(0x30, WDT_INDEX_IO_PORT); /* Read Index 0x30 First */
105 cr_data = inb(WDT_DATA_IO_PORT);
106 cr_data |= 0x01; /* Set Bit0 to 1 */
107 outb_p(0x30, WDT_INDEX_IO_PORT);
108 outb_p(cr_data, WDT_DATA_IO_PORT); /* Index0x30_bit0P1 */
109
110#ifdef DEBUG
111 printk(KERN_INFO DPFX "pc87413 - Enable SWC functions\n");
112#endif
113}
114
115/* Read SWC I/O base address */
116
117static inline unsigned int pc87413_get_swc_base(void)
118{
119 unsigned int swc_base_addr = 0;
120 unsigned char addr_l, addr_h = 0;
121
122 /* Step 3: Read SWC I/O Base Address */
123
124 outb_p(0x60, WDT_INDEX_IO_PORT); /* Read Index 0x60 */
125 addr_h = inb(WDT_DATA_IO_PORT);
126
127 outb_p(0x61, WDT_INDEX_IO_PORT); /* Read Index 0x61 */
128
129 addr_l = inb(WDT_DATA_IO_PORT);
130
131 swc_base_addr = (addr_h << 8) + addr_l;
132
133#ifdef DEBUG
134 printk(KERN_INFO DPFX "Read SWC I/O Base Address: low %d, high %d,"
135 " res %d\n", addr_l, addr_h, swc_base_addr);
136#endif
137
138 return swc_base_addr;
139}
140
141/* Select Bank 3 of SWC */
142
143static inline void pc87413_swc_bank3(unsigned int swc_base_addr)
144{
145 /* Step 4: Select Bank3 of SWC */
146
147 outb_p(inb(swc_base_addr + 0x0f) | 0x03, swc_base_addr + 0x0f);
148
149#ifdef DEBUG
150 printk(KERN_INFO DPFX "Select Bank3 of SWC\n");
151#endif
152}
153
154/* Set watchdog timeout to x minutes */
155
156static inline void pc87413_programm_wdto(unsigned int swc_base_addr,
157 char pc87413_time)
158{
159 /* Step 5: Programm WDTO, Twd. */
160
161 outb_p(pc87413_time, swc_base_addr + WDTO);
162
163#ifdef DEBUG
164 printk(KERN_INFO DPFX "Set WDTO to %d minutes\n", pc87413_time);
165#endif
166}
167
168/* Enable WDEN */
169
170static inline void pc87413_enable_wden(unsigned int swc_base_addr)
171{
172 /* Step 6: Enable WDEN */
173
174 outb_p(inb (swc_base_addr + WDCTL) | 0x01, swc_base_addr + WDCTL);
175
176#ifdef DEBUG
177 printk(KERN_INFO DPFX "Enable WDEN\n");
178#endif
179}
180
181/* Enable SW_WD_TREN */
182static inline void pc87413_enable_sw_wd_tren(unsigned int swc_base_addr)
183{
184 /* Enable SW_WD_TREN */
185
186 outb_p(inb (swc_base_addr + WDCFG) | 0x80, swc_base_addr + WDCFG);
187
188#ifdef DEBUG
189 printk(KERN_INFO DPFX "Enable SW_WD_TREN\n");
190#endif
191}
192
193/* Disable SW_WD_TREN */
194
195static inline void pc87413_disable_sw_wd_tren(unsigned int swc_base_addr)
196{
197 /* Disable SW_WD_TREN */
198
199 outb_p(inb (swc_base_addr + WDCFG) & 0x7f, swc_base_addr + WDCFG);
200
201#ifdef DEBUG
202 printk(KERN_INFO DPFX "pc87413 - Disable SW_WD_TREN\n");
203#endif
204}
205
206/* Enable SW_WD_TRG */
207
208static inline void pc87413_enable_sw_wd_trg(unsigned int swc_base_addr)
209{
210 /* Enable SW_WD_TRG */
211
212 outb_p(inb (swc_base_addr + WDCTL) | 0x80, swc_base_addr + WDCTL);
213
214#ifdef DEBUG
215 printk(KERN_INFO DPFX "pc87413 - Enable SW_WD_TRG\n");
216#endif
217}
218
219/* Disable SW_WD_TRG */
220
221static inline void pc87413_disable_sw_wd_trg(unsigned int swc_base_addr)
222{
223 /* Disable SW_WD_TRG */
224
225 outb_p(inb (swc_base_addr + WDCTL) & 0x7f, swc_base_addr + WDCTL);
226
227#ifdef DEBUG
228 printk(KERN_INFO DPFX "Disable SW_WD_TRG\n");
229#endif
230}
231
232/* -- Higher level functions ------------------------------------*/
233
234/* Enable the watchdog */
235
236static void pc87413_enable(void)
237{
238 unsigned int swc_base_addr;
239
240 spin_lock(&io_lock);
241
242 pc87413_select_wdt_out();
243 pc87413_enable_swc();
244 swc_base_addr = pc87413_get_swc_base();
245 pc87413_swc_bank3(swc_base_addr);
246 pc87413_programm_wdto(swc_base_addr, timeout);
247 pc87413_enable_wden(swc_base_addr);
248 pc87413_enable_sw_wd_tren(swc_base_addr);
249 pc87413_enable_sw_wd_trg(swc_base_addr);
250
251 spin_unlock(&io_lock);
252}
253
254/* Disable the watchdog */
255
256static void pc87413_disable(void)
257{
258 unsigned int swc_base_addr;
259
260 spin_lock(&io_lock);
261
262 pc87413_select_wdt_out();
263 pc87413_enable_swc();
264 swc_base_addr = pc87413_get_swc_base();
265 pc87413_swc_bank3(swc_base_addr);
266 pc87413_disable_sw_wd_tren(swc_base_addr);
267 pc87413_disable_sw_wd_trg(swc_base_addr);
268 pc87413_programm_wdto(swc_base_addr, 0);
269
270 spin_unlock(&io_lock);
271}
272
273/* Refresh the watchdog */
274
275static void pc87413_refresh(void)
276{
277 unsigned int swc_base_addr;
278
279 spin_lock(&io_lock);
280
281 pc87413_select_wdt_out();
282 pc87413_enable_swc();
283 swc_base_addr = pc87413_get_swc_base();
284 pc87413_swc_bank3(swc_base_addr);
285 pc87413_disable_sw_wd_tren(swc_base_addr);
286 pc87413_disable_sw_wd_trg(swc_base_addr);
287 pc87413_programm_wdto(swc_base_addr, timeout);
288 pc87413_enable_wden(swc_base_addr);
289 pc87413_enable_sw_wd_tren(swc_base_addr);
290 pc87413_enable_sw_wd_trg(swc_base_addr);
291
292 spin_unlock(&io_lock);
293}
294
295/* -- File operations -------------------------------------------*/
296
297/**
298 * pc87413_open:
299 * @inode: inode of device
300 * @file: file handle to device
301 *
302 */
303
304static int pc87413_open(struct inode *inode, struct file *file)
305{
306 /* /dev/watchdog can only be opened once */
307
308 if (test_and_set_bit(0, &timer_enabled))
309 return -EBUSY;
310
311 if (nowayout)
312 __module_get(THIS_MODULE);
313
314 /* Reload and activate timer */
315 pc87413_refresh();
316
317 printk(KERN_INFO MODNAME "Watchdog enabled. Timeout set to"
318 " %d minute(s).\n", timeout);
319
320 return nonseekable_open(inode, file);
321}
322
323/**
324 * pc87413_release:
325 * @inode: inode to board
326 * @file: file handle to board
327 *
328 * The watchdog has a configurable API. There is a religious dispute
329 * between people who want their watchdog to be able to shut down and
330 * those who want to be sure if the watchdog manager dies the machine
331 * reboots. In the former case we disable the counters, in the latter
332 * case you have to open it again very soon.
333 */
334
335static int pc87413_release(struct inode *inode, struct file *file)
336{
337 /* Shut off the timer. */
338
339 if (expect_close == 42) {
340 pc87413_disable();
341 printk(KERN_INFO MODNAME "Watchdog disabled,"
342 " sleeping again...\n");
343 } else {
344 printk(KERN_CRIT MODNAME "Unexpected close, not stopping"
345 " watchdog!\n");
346 pc87413_refresh();
347 }
348
349 clear_bit(0, &timer_enabled);
350 expect_close = 0;
351
352 return 0;
353}
354
355/**
356 * pc87413_status:
357 *
358 * return, if the watchdog is enabled (timeout is set...)
359 */
360
361
362static int pc87413_status(void)
363{
364 return 0; /* currently not supported */
365}
366
367/**
368 * pc87413_write:
369 * @file: file handle to the watchdog
370 * @data: data buffer to write
371 * @len: length in bytes
372 * @ppos: pointer to the position to write. No seeks allowed
373 *
374 * A write to a watchdog device is defined as a keepalive signal. Any
375 * write of data will do, as we we don't define content meaning.
376 */
377
378static ssize_t pc87413_write(struct file *file, const char __user *data,
379 size_t len, loff_t *ppos)
380{
381 /* See if we got the magic character 'V' and reload the timer */
382 if (len) {
383 if (!nowayout) {
384 size_t i;
385
386 /* reset expect flag */
387 expect_close = 0;
388
389 /* scan to see whether or not we got the magic character */
390 for (i = 0; i != len; i++) {
391 char c;
392 if (get_user(c, data+i))
393 return -EFAULT;
394 if (c == 'V')
395 expect_close = 42;
396 }
397 }
398
399 /* someone wrote to us, we should reload the timer */
400 pc87413_refresh();
401 }
402 return len;
403}
404
405/**
406 * pc87413_ioctl:
407 * @inode: inode of the device
408 * @file: file handle to the device
409 * @cmd: watchdog command
410 * @arg: argument pointer
411 *
412 * The watchdog API defines a common set of functions for all watchdogs
413 * according to their available features. We only actually usefully support
414 * querying capabilities and current status.
415 */
416
417static int pc87413_ioctl(struct inode *inode, struct file *file,
418 unsigned int cmd, unsigned long arg)
419{
420 int new_timeout;
421
422 union {
423 struct watchdog_info __user *ident;
424 int __user *i;
425 } uarg;
426
427 static struct watchdog_info ident = {
428 .options = WDIOF_KEEPALIVEPING |
429 WDIOF_SETTIMEOUT |
430 WDIOF_MAGICCLOSE,
431 .firmware_version = 1,
432 .identity = "PC87413(HF/F) watchdog"
433 };
434
435 uarg.i = (int __user *)arg;
436
437 switch(cmd) {
438 default:
439 return -ENOTTY;
440
441 case WDIOC_GETSUPPORT:
442 return copy_to_user(uarg.ident, &ident,
443 sizeof(ident)) ? -EFAULT : 0;
444
445 case WDIOC_GETSTATUS:
446 return put_user(pc87413_status(), uarg.i);
447
448 case WDIOC_GETBOOTSTATUS:
449 return put_user(0, uarg.i);
450
451 case WDIOC_KEEPALIVE:
452 pc87413_refresh();
453#ifdef DEBUG
454 printk(KERN_INFO DPFX "keepalive\n");
455#endif
456 return 0;
457
458 case WDIOC_SETTIMEOUT:
459 if (get_user(new_timeout, uarg.i))
460 return -EFAULT;
461
462 // the API states this is given in secs
463 new_timeout /= 60;
464
465 if (new_timeout < 0 || new_timeout > MAX_TIMEOUT)
466 return -EINVAL;
467
468 timeout = new_timeout;
469 pc87413_refresh();
470
471 // fall through and return the new timeout...
472
473 case WDIOC_GETTIMEOUT:
474
475 new_timeout = timeout * 60;
476
477 return put_user(new_timeout, uarg.i);
478
479 case WDIOC_SETOPTIONS:
480 {
481 int options, retval = -EINVAL;
482
483 if (get_user(options, uarg.i))
484 return -EFAULT;
485
486 if (options & WDIOS_DISABLECARD) {
487 pc87413_disable();
488 retval = 0;
489 }
490
491 if (options & WDIOS_ENABLECARD) {
492 pc87413_enable();
493 retval = 0;
494 }
495
496 return retval;
497 }
498 }
499}
500
501/* -- Notifier funtions -----------------------------------------*/
502
503/**
504 * notify_sys:
505 * @this: our notifier block
506 * @code: the event being reported
507 * @unused: unused
508 *
509 * Our notifier is called on system shutdowns. We want to turn the card
510 * off at reboot otherwise the machine will reboot again during memory
511 * test or worse yet during the following fsck. This would suck, in fact
512 * trust me - if it happens it does suck.
513 */
514
515static int pc87413_notify_sys(struct notifier_block *this,
516 unsigned long code,
517 void *unused)
518{
519 if (code == SYS_DOWN || code == SYS_HALT)
520 {
521 /* Turn the card off */
522 pc87413_disable();
523 }
524 return NOTIFY_DONE;
525}
526
527/* -- Module's structures ---------------------------------------*/
528
529static struct file_operations pc87413_fops = {
530 .owner = THIS_MODULE,
531 .llseek = no_llseek,
532 .write = pc87413_write,
533 .ioctl = pc87413_ioctl,
534 .open = pc87413_open,
535 .release = pc87413_release,
536};
537
538static struct notifier_block pc87413_notifier =
539{
540 .notifier_call = pc87413_notify_sys,
541};
542
543static struct miscdevice pc87413_miscdev=
544{
545 .minor = WATCHDOG_MINOR,
546 .name = "watchdog",
547 .fops = &pc87413_fops
548};
549
550/* -- Module init functions -------------------------------------*/
551
552/**
553 * pc87413_init: module's "constructor"
554 *
555 * Set up the WDT watchdog board. All we have to do is grab the
556 * resources we require and bitch if anyone beat us to them.
557 * The open() function will actually kick the board off.
558 */
559
560static int __init pc87413_init(void)
561{
562 int ret;
563
564 spin_lock_init(&io_lock);
565
566 printk(KERN_INFO PFX "Version " VERSION " at io 0x%X\n", WDT_INDEX_IO_PORT);
567
568 /* request_region(io, 2, "pc87413"); */
569
570 ret = register_reboot_notifier(&pc87413_notifier);
571 if (ret != 0) {
572 printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
573 ret);
574 }
575
576 ret = misc_register(&pc87413_miscdev);
577
578 if (ret != 0) {
579 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
580 WATCHDOG_MINOR, ret);
581 unregister_reboot_notifier(&pc87413_notifier);
582 return ret;
583 }
584
585 printk(KERN_INFO PFX "initialized. timeout=%d min \n", timeout);
586
587 pc87413_enable();
588
589 return 0;
590}
591
592/**
593 * pc87413_exit: module's "destructor"
594 *
595 * Unload the watchdog. You cannot do this with any file handles open.
596 * If your watchdog is set to continue ticking on close and you unload
597 * it, well it keeps ticking. We won't get the interrupt but the board
598 * will not touch PC memory so all is fine. You just have to load a new
599 * module in 60 seconds or reboot.
600 */
601
602static void __exit pc87413_exit(void)
603{
604 /* Stop the timer before we leave */
605 if (!nowayout)
606 {
607 pc87413_disable();
608 printk(KERN_INFO MODNAME "Watchdog disabled.\n");
609 }
610
611 misc_deregister(&pc87413_miscdev);
612 unregister_reboot_notifier(&pc87413_notifier);
613 /* release_region(io,2); */
614
615 printk(MODNAME " watchdog component driver removed.\n");
616}
617
618module_init(pc87413_init);
619module_exit(pc87413_exit);
620
621MODULE_AUTHOR("Sven Anders <anders@anduras.de>, Marcus Junker <junker@anduras.de>,");
622MODULE_DESCRIPTION("PC87413 WDT driver");
623MODULE_LICENSE("GPL");
624
625MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
626
627module_param(io, int, 0);
628MODULE_PARM_DESC(io, MODNAME " I/O port (default: " __MODULE_STRING(io) ").");
629
630module_param(timeout, int, 0);
631MODULE_PARM_DESC(timeout, "Watchdog timeout in minutes (default=" __MODULE_STRING(timeout) ").");
632
633module_param(nowayout, int, 0);
634MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
635
diff --git a/drivers/char/watchdog/pcwd.c b/drivers/char/watchdog/pcwd.c
index cd7d1b6a5d9f..8e1e6e48e0a7 100644
--- a/drivers/char/watchdog/pcwd.c
+++ b/drivers/char/watchdog/pcwd.c
@@ -49,7 +49,6 @@
49 * More info available at http://www.berkprod.com/ or http://www.pcwatchdog.com/ 49 * More info available at http://www.berkprod.com/ or http://www.pcwatchdog.com/
50 */ 50 */
51 51
52#include <linux/config.h> /* For CONFIG_WATCHDOG_NOWAYOUT/... */
53#include <linux/module.h> /* For module specific items */ 52#include <linux/module.h> /* For module specific items */
54#include <linux/moduleparam.h> /* For new moduleparam's */ 53#include <linux/moduleparam.h> /* For new moduleparam's */
55#include <linux/types.h> /* For standard types (like size_t) */ 54#include <linux/types.h> /* For standard types (like size_t) */
@@ -572,7 +571,7 @@ static int pcwd_ioctl(struct inode *inode, struct file *file,
572 571
573 switch(cmd) { 572 switch(cmd) {
574 default: 573 default:
575 return -ENOIOCTLCMD; 574 return -ENOTTY;
576 575
577 case WDIOC_GETSUPPORT: 576 case WDIOC_GETSUPPORT:
578 if(copy_to_user(argp, &ident, sizeof(ident))) 577 if(copy_to_user(argp, &ident, sizeof(ident)))
diff --git a/drivers/char/watchdog/pcwd_pci.c b/drivers/char/watchdog/pcwd_pci.c
index c7cfd6dbfe1b..f4872c871063 100644
--- a/drivers/char/watchdog/pcwd_pci.c
+++ b/drivers/char/watchdog/pcwd_pci.c
@@ -31,7 +31,6 @@
31 * Includes, defines, variables, module parameters, ... 31 * Includes, defines, variables, module parameters, ...
32 */ 32 */
33 33
34#include <linux/config.h> /* For CONFIG_WATCHDOG_NOWAYOUT/... */
35#include <linux/module.h> /* For module specific items */ 34#include <linux/module.h> /* For module specific items */
36#include <linux/moduleparam.h> /* For new moduleparam's */ 35#include <linux/moduleparam.h> /* For new moduleparam's */
37#include <linux/types.h> /* For standard types (like size_t) */ 36#include <linux/types.h> /* For standard types (like size_t) */
@@ -541,7 +540,7 @@ static int pcipcwd_ioctl(struct inode *inode, struct file *file,
541 } 540 }
542 541
543 default: 542 default:
544 return -ENOIOCTLCMD; 543 return -ENOTTY;
545 } 544 }
546} 545}
547 546
diff --git a/drivers/char/watchdog/pcwd_usb.c b/drivers/char/watchdog/pcwd_usb.c
index b7ae73dcdd08..61138726b501 100644
--- a/drivers/char/watchdog/pcwd_usb.c
+++ b/drivers/char/watchdog/pcwd_usb.c
@@ -158,7 +158,7 @@ static struct usb_driver usb_pcwd_driver = {
158}; 158};
159 159
160 160
161static void usb_pcwd_intr_done(struct urb *urb, struct pt_regs *regs) 161static void usb_pcwd_intr_done(struct urb *urb)
162{ 162{
163 struct usb_pcwd_private *usb_pcwd = (struct usb_pcwd_private *)urb->context; 163 struct usb_pcwd_private *usb_pcwd = (struct usb_pcwd_private *)urb->context;
164 unsigned char *data = usb_pcwd->intr_buffer; 164 unsigned char *data = usb_pcwd->intr_buffer;
@@ -445,7 +445,7 @@ static int usb_pcwd_ioctl(struct inode *inode, struct file *file,
445 } 445 }
446 446
447 default: 447 default:
448 return -ENOIOCTLCMD; 448 return -ENOTTY;
449 } 449 }
450} 450}
451 451
@@ -561,8 +561,7 @@ static struct notifier_block usb_pcwd_notifier = {
561 */ 561 */
562static inline void usb_pcwd_delete (struct usb_pcwd_private *usb_pcwd) 562static inline void usb_pcwd_delete (struct usb_pcwd_private *usb_pcwd)
563{ 563{
564 if (usb_pcwd->intr_urb != NULL) 564 usb_free_urb(usb_pcwd->intr_urb);
565 usb_free_urb (usb_pcwd->intr_urb);
566 if (usb_pcwd->intr_buffer != NULL) 565 if (usb_pcwd->intr_buffer != NULL)
567 usb_buffer_free(usb_pcwd->udev, usb_pcwd->intr_size, 566 usb_buffer_free(usb_pcwd->udev, usb_pcwd->intr_size,
568 usb_pcwd->intr_buffer, usb_pcwd->intr_dma); 567 usb_pcwd->intr_buffer, usb_pcwd->intr_dma);
@@ -635,7 +634,7 @@ static int usb_pcwd_probe(struct usb_interface *interface, const struct usb_devi
635 usb_pcwd->intr_size = (le16_to_cpu(endpoint->wMaxPacketSize) > 8 ? le16_to_cpu(endpoint->wMaxPacketSize) : 8); 634 usb_pcwd->intr_size = (le16_to_cpu(endpoint->wMaxPacketSize) > 8 ? le16_to_cpu(endpoint->wMaxPacketSize) : 8);
636 635
637 /* set up the memory buffer's */ 636 /* set up the memory buffer's */
638 if (!(usb_pcwd->intr_buffer = usb_buffer_alloc(udev, usb_pcwd->intr_size, SLAB_ATOMIC, &usb_pcwd->intr_dma))) { 637 if (!(usb_pcwd->intr_buffer = usb_buffer_alloc(udev, usb_pcwd->intr_size, GFP_ATOMIC, &usb_pcwd->intr_dma))) {
639 printk(KERN_ERR PFX "Out of memory\n"); 638 printk(KERN_ERR PFX "Out of memory\n");
640 goto error; 639 goto error;
641 } 640 }
diff --git a/drivers/char/watchdog/pnx4008_wdt.c b/drivers/char/watchdog/pnx4008_wdt.c
new file mode 100644
index 000000000000..3a55fc6abcd8
--- /dev/null
+++ b/drivers/char/watchdog/pnx4008_wdt.c
@@ -0,0 +1,361 @@
1/*
2 * drivers/char/watchdog/pnx4008_wdt.c
3 *
4 * Watchdog driver for PNX4008 board
5 *
6 * Authors: Dmitry Chigirev <source@mvista.com>,
7 * Vitaly Wool <vitalywool@gmail.com>
8 * Based on sa1100 driver,
9 * Copyright (C) 2000 Oleg Drokin <green@crimea.edu>
10 *
11 * 2005-2006 (c) MontaVista Software, Inc. This file is licensed under
12 * the terms of the GNU General Public License version 2. This program
13 * is licensed "as is" without any warranty of any kind, whether express
14 * or implied.
15 */
16
17#include <linux/module.h>
18#include <linux/moduleparam.h>
19#include <linux/types.h>
20#include <linux/kernel.h>
21#include <linux/fs.h>
22#include <linux/miscdevice.h>
23#include <linux/watchdog.h>
24#include <linux/init.h>
25#include <linux/bitops.h>
26#include <linux/ioport.h>
27#include <linux/device.h>
28#include <linux/platform_device.h>
29#include <linux/clk.h>
30#include <linux/spinlock.h>
31
32#include <asm/hardware.h>
33#include <asm/uaccess.h>
34#include <asm/io.h>
35
36#define MODULE_NAME "PNX4008-WDT: "
37
38/* WatchDog Timer - Chapter 23 Page 207 */
39
40#define DEFAULT_HEARTBEAT 19
41#define MAX_HEARTBEAT 60
42
43/* Watchdog timer register set definition */
44#define WDTIM_INT(p) ((p) + 0x0)
45#define WDTIM_CTRL(p) ((p) + 0x4)
46#define WDTIM_COUNTER(p) ((p) + 0x8)
47#define WDTIM_MCTRL(p) ((p) + 0xC)
48#define WDTIM_MATCH0(p) ((p) + 0x10)
49#define WDTIM_EMR(p) ((p) + 0x14)
50#define WDTIM_PULSE(p) ((p) + 0x18)
51#define WDTIM_RES(p) ((p) + 0x1C)
52
53/* WDTIM_INT bit definitions */
54#define MATCH_INT 1
55
56/* WDTIM_CTRL bit definitions */
57#define COUNT_ENAB 1
58#define RESET_COUNT (1<<1)
59#define DEBUG_EN (1<<2)
60
61/* WDTIM_MCTRL bit definitions */
62#define MR0_INT 1
63#undef RESET_COUNT0
64#define RESET_COUNT0 (1<<2)
65#define STOP_COUNT0 (1<<2)
66#define M_RES1 (1<<3)
67#define M_RES2 (1<<4)
68#define RESFRC1 (1<<5)
69#define RESFRC2 (1<<6)
70
71/* WDTIM_EMR bit definitions */
72#define EXT_MATCH0 1
73#define MATCH_OUTPUT_HIGH (2<<4) /*a MATCH_CTRL setting */
74
75/* WDTIM_RES bit definitions */
76#define WDOG_RESET 1 /* read only */
77
78#define WDOG_COUNTER_RATE 13000000 /*the counter clock is 13 MHz fixed */
79
80static int nowayout = WATCHDOG_NOWAYOUT;
81static int heartbeat = DEFAULT_HEARTBEAT;
82
83static spinlock_t io_lock;
84static unsigned long wdt_status;
85#define WDT_IN_USE 0
86#define WDT_OK_TO_CLOSE 1
87#define WDT_REGION_INITED 2
88#define WDT_DEVICE_INITED 3
89
90static unsigned long boot_status;
91
92static struct resource *wdt_mem;
93static void __iomem *wdt_base;
94struct clk *wdt_clk;
95
96static void wdt_enable(void)
97{
98 spin_lock(&io_lock);
99
100 if (wdt_clk)
101 clk_set_rate(wdt_clk, 1);
102
103 /* stop counter, initiate counter reset */
104 __raw_writel(RESET_COUNT, WDTIM_CTRL(wdt_base));
105 /*wait for reset to complete. 100% guarantee event */
106 while (__raw_readl(WDTIM_COUNTER(wdt_base)))
107 cpu_relax();
108 /* internal and external reset, stop after that */
109 __raw_writel(M_RES2 | STOP_COUNT0 | RESET_COUNT0,
110 WDTIM_MCTRL(wdt_base));
111 /* configure match output */
112 __raw_writel(MATCH_OUTPUT_HIGH, WDTIM_EMR(wdt_base));
113 /* clear interrupt, just in case */
114 __raw_writel(MATCH_INT, WDTIM_INT(wdt_base));
115 /* the longest pulse period 65541/(13*10^6) seconds ~ 5 ms. */
116 __raw_writel(0xFFFF, WDTIM_PULSE(wdt_base));
117 __raw_writel(heartbeat * WDOG_COUNTER_RATE, WDTIM_MATCH0(wdt_base));
118 /*enable counter, stop when debugger active */
119 __raw_writel(COUNT_ENAB | DEBUG_EN, WDTIM_CTRL(wdt_base));
120
121 spin_unlock(&io_lock);
122}
123
124static void wdt_disable(void)
125{
126 spin_lock(&io_lock);
127
128 __raw_writel(0, WDTIM_CTRL(wdt_base)); /*stop counter */
129 if (wdt_clk)
130 clk_set_rate(wdt_clk, 0);
131
132 spin_unlock(&io_lock);
133}
134
135static int pnx4008_wdt_open(struct inode *inode, struct file *file)
136{
137 if (test_and_set_bit(WDT_IN_USE, &wdt_status))
138 return -EBUSY;
139
140 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
141
142 wdt_enable();
143
144 return nonseekable_open(inode, file);
145}
146
147static ssize_t
148pnx4008_wdt_write(struct file *file, const char *data, size_t len,
149 loff_t * ppos)
150{
151 /* Can't seek (pwrite) on this device */
152 if (ppos != &file->f_pos)
153 return -ESPIPE;
154
155 if (len) {
156 if (!nowayout) {
157 size_t i;
158
159 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
160
161 for (i = 0; i != len; i++) {
162 char c;
163
164 if (get_user(c, data + i))
165 return -EFAULT;
166 if (c == 'V')
167 set_bit(WDT_OK_TO_CLOSE, &wdt_status);
168 }
169 }
170 wdt_enable();
171 }
172
173 return len;
174}
175
176static struct watchdog_info ident = {
177 .options = WDIOF_CARDRESET | WDIOF_MAGICCLOSE |
178 WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
179 .identity = "PNX4008 Watchdog",
180};
181
182static int
183pnx4008_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
184 unsigned long arg)
185{
186 int ret = -ENOTTY;
187 int time;
188
189 switch (cmd) {
190 case WDIOC_GETSUPPORT:
191 ret = copy_to_user((struct watchdog_info *)arg, &ident,
192 sizeof(ident)) ? -EFAULT : 0;
193 break;
194
195 case WDIOC_GETSTATUS:
196 ret = put_user(0, (int *)arg);
197 break;
198
199 case WDIOC_GETBOOTSTATUS:
200 ret = put_user(boot_status, (int *)arg);
201 break;
202
203 case WDIOC_SETTIMEOUT:
204 ret = get_user(time, (int *)arg);
205 if (ret)
206 break;
207
208 if (time <= 0 || time > MAX_HEARTBEAT) {
209 ret = -EINVAL;
210 break;
211 }
212
213 heartbeat = time;
214 wdt_enable();
215 /* Fall through */
216
217 case WDIOC_GETTIMEOUT:
218 ret = put_user(heartbeat, (int *)arg);
219 break;
220
221 case WDIOC_KEEPALIVE:
222 wdt_enable();
223 ret = 0;
224 break;
225 }
226 return ret;
227}
228
229static int pnx4008_wdt_release(struct inode *inode, struct file *file)
230{
231 if (!test_bit(WDT_OK_TO_CLOSE, &wdt_status))
232 printk(KERN_WARNING "WATCHDOG: Device closed unexpectdly\n");
233
234 wdt_disable();
235 clear_bit(WDT_IN_USE, &wdt_status);
236 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
237
238 return 0;
239}
240
241static struct file_operations pnx4008_wdt_fops = {
242 .owner = THIS_MODULE,
243 .llseek = no_llseek,
244 .write = pnx4008_wdt_write,
245 .ioctl = pnx4008_wdt_ioctl,
246 .open = pnx4008_wdt_open,
247 .release = pnx4008_wdt_release,
248};
249
250static struct miscdevice pnx4008_wdt_miscdev = {
251 .minor = WATCHDOG_MINOR,
252 .name = "watchdog",
253 .fops = &pnx4008_wdt_fops,
254};
255
256static int pnx4008_wdt_probe(struct platform_device *pdev)
257{
258 int ret = 0, size;
259 struct resource *res;
260
261 spin_lock_init(&io_lock);
262
263 if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT)
264 heartbeat = DEFAULT_HEARTBEAT;
265
266 printk(KERN_INFO MODULE_NAME
267 "PNX4008 Watchdog Timer: heartbeat %d sec\n", heartbeat);
268
269 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
270 if (res == NULL) {
271 printk(KERN_INFO MODULE_NAME
272 "failed to get memory region resouce\n");
273 return -ENOENT;
274 }
275
276 size = res->end - res->start + 1;
277 wdt_mem = request_mem_region(res->start, size, pdev->name);
278
279 if (wdt_mem == NULL) {
280 printk(KERN_INFO MODULE_NAME "failed to get memory region\n");
281 return -ENOENT;
282 }
283 wdt_base = (void __iomem *)IO_ADDRESS(res->start);
284
285 wdt_clk = clk_get(&pdev->dev, "wdt_ck");
286 if (!wdt_clk) {
287 release_resource(wdt_mem);
288 kfree(wdt_mem);
289 goto out;
290 } else
291 clk_set_rate(wdt_clk, 1);
292
293 ret = misc_register(&pnx4008_wdt_miscdev);
294 if (ret < 0) {
295 printk(KERN_ERR MODULE_NAME "cannot register misc device\n");
296 release_resource(wdt_mem);
297 kfree(wdt_mem);
298 clk_set_rate(wdt_clk, 0);
299 } else {
300 boot_status = (__raw_readl(WDTIM_RES(wdt_base)) & WDOG_RESET) ?
301 WDIOF_CARDRESET : 0;
302 wdt_disable(); /*disable for now */
303 set_bit(WDT_DEVICE_INITED, &wdt_status);
304 }
305
306out:
307 return ret;
308}
309
310static int pnx4008_wdt_remove(struct platform_device *pdev)
311{
312 misc_deregister(&pnx4008_wdt_miscdev);
313 if (wdt_clk) {
314 clk_set_rate(wdt_clk, 0);
315 clk_put(wdt_clk);
316 wdt_clk = NULL;
317 }
318 if (wdt_mem) {
319 release_resource(wdt_mem);
320 kfree(wdt_mem);
321 wdt_mem = NULL;
322 }
323 return 0;
324}
325
326static struct platform_driver platform_wdt_driver = {
327 .driver = {
328 .name = "watchdog",
329 },
330 .probe = pnx4008_wdt_probe,
331 .remove = pnx4008_wdt_remove,
332};
333
334static int __init pnx4008_wdt_init(void)
335{
336 return platform_driver_register(&platform_wdt_driver);
337}
338
339static void __exit pnx4008_wdt_exit(void)
340{
341 return platform_driver_unregister(&platform_wdt_driver);
342}
343
344module_init(pnx4008_wdt_init);
345module_exit(pnx4008_wdt_exit);
346
347MODULE_AUTHOR("MontaVista Software, Inc. <source@mvista.com>");
348MODULE_DESCRIPTION("PNX4008 Watchdog Driver");
349
350module_param(heartbeat, int, 0);
351MODULE_PARM_DESC(heartbeat,
352 "Watchdog heartbeat period in seconds from 1 to "
353 __MODULE_STRING(MAX_HEARTBEAT) ", default "
354 __MODULE_STRING(DEFAULT_HEARTBEAT));
355
356module_param(nowayout, int, 0);
357MODULE_PARM_DESC(nowayout,
358 "Set to 1 to keep watchdog running after device release");
359
360MODULE_LICENSE("GPL");
361MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/char/watchdog/rm9k_wdt.c b/drivers/char/watchdog/rm9k_wdt.c
new file mode 100644
index 000000000000..ec3909371c21
--- /dev/null
+++ b/drivers/char/watchdog/rm9k_wdt.c
@@ -0,0 +1,420 @@
1/*
2 * Watchdog implementation for GPI h/w found on PMC-Sierra RM9xxx
3 * chips.
4 *
5 * Copyright (C) 2004 by Basler Vision Technologies AG
6 * Author: Thomas Koeller <thomas.koeller@baslerweb.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/platform_device.h>
24#include <linux/module.h>
25#include <linux/moduleparam.h>
26#include <linux/interrupt.h>
27#include <linux/fs.h>
28#include <linux/reboot.h>
29#include <linux/notifier.h>
30#include <linux/miscdevice.h>
31#include <linux/watchdog.h>
32#include <asm/io.h>
33#include <asm/atomic.h>
34#include <asm/processor.h>
35#include <asm/uaccess.h>
36#include <asm/system.h>
37#include <asm/rm9k-ocd.h>
38
39#include <rm9k_wdt.h>
40
41
42#define CLOCK 125000000
43#define MAX_TIMEOUT_SECONDS 32
44#define CPCCR 0x0080
45#define CPGIG1SR 0x0044
46#define CPGIG1ER 0x0054
47
48
49/* Function prototypes */
50static irqreturn_t wdt_gpi_irqhdl(int, void *, struct pt_regs *);
51static void wdt_gpi_start(void);
52static void wdt_gpi_stop(void);
53static void wdt_gpi_set_timeout(unsigned int);
54static int wdt_gpi_open(struct inode *, struct file *);
55static int wdt_gpi_release(struct inode *, struct file *);
56static ssize_t wdt_gpi_write(struct file *, const char __user *, size_t, loff_t *);
57static long wdt_gpi_ioctl(struct file *, unsigned int, unsigned long);
58static int wdt_gpi_notify(struct notifier_block *, unsigned long, void *);
59static const struct resource *wdt_gpi_get_resource(struct platform_device *, const char *, unsigned int);
60static int __init wdt_gpi_probe(struct device *);
61static int __exit wdt_gpi_remove(struct device *);
62
63
64static const char wdt_gpi_name[] = "wdt_gpi";
65static atomic_t opencnt;
66static int expect_close;
67static int locked;
68
69
70/* These are set from device resources */
71static void __iomem * wd_regs;
72static unsigned int wd_irq, wd_ctr;
73
74
75/* Module arguments */
76static int timeout = MAX_TIMEOUT_SECONDS;
77module_param(timeout, int, 0444);
78MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds");
79
80static unsigned long resetaddr = 0xbffdc200;
81module_param(resetaddr, ulong, 0444);
82MODULE_PARM_DESC(resetaddr, "Address to write to to force a reset");
83
84static unsigned long flagaddr = 0xbffdc104;
85module_param(flagaddr, ulong, 0444);
86MODULE_PARM_DESC(flagaddr, "Address to write to boot flags to");
87
88static int powercycle;
89module_param(powercycle, bool, 0444);
90MODULE_PARM_DESC(powercycle, "Cycle power if watchdog expires");
91
92static int nowayout = WATCHDOG_NOWAYOUT;
93module_param(nowayout, bool, 0444);
94MODULE_PARM_DESC(nowayout, "Watchdog cannot be disabled once started");
95
96
97/* Interrupt handler */
98static irqreturn_t wdt_gpi_irqhdl(int irq, void *ctxt, struct pt_regs *regs)
99{
100 if (!unlikely(__raw_readl(wd_regs + 0x0008) & 0x1))
101 return IRQ_NONE;
102 __raw_writel(0x1, wd_regs + 0x0008);
103
104
105 printk(KERN_CRIT "%s: watchdog expired - resetting system\n",
106 wdt_gpi_name);
107
108 *(volatile char *) flagaddr |= 0x01;
109 *(volatile char *) resetaddr = powercycle ? 0x01 : 0x2;
110 iob();
111 while (1)
112 cpu_relax();
113}
114
115
116/* Watchdog functions */
117static void wdt_gpi_start(void)
118{
119 u32 reg;
120
121 lock_titan_regs();
122 reg = titan_readl(CPGIG1ER);
123 titan_writel(reg | (0x100 << wd_ctr), CPGIG1ER);
124 iob();
125 unlock_titan_regs();
126}
127
128static void wdt_gpi_stop(void)
129{
130 u32 reg;
131
132 lock_titan_regs();
133 reg = titan_readl(CPCCR) & ~(0xf << (wd_ctr * 4));
134 titan_writel(reg, CPCCR);
135 reg = titan_readl(CPGIG1ER);
136 titan_writel(reg & ~(0x100 << wd_ctr), CPGIG1ER);
137 iob();
138 unlock_titan_regs();
139}
140
141static void wdt_gpi_set_timeout(unsigned int to)
142{
143 u32 reg;
144 const u32 wdval = (to * CLOCK) & ~0x0000000f;
145
146 lock_titan_regs();
147 reg = titan_readl(CPCCR) & ~(0xf << (wd_ctr * 4));
148 titan_writel(reg, CPCCR);
149 wmb();
150 __raw_writel(wdval, wd_regs + 0x0000);
151 wmb();
152 titan_writel(reg | (0x2 << (wd_ctr * 4)), CPCCR);
153 wmb();
154 titan_writel(reg | (0x5 << (wd_ctr * 4)), CPCCR);
155 iob();
156 unlock_titan_regs();
157}
158
159
160/* /dev/watchdog operations */
161static int wdt_gpi_open(struct inode *inode, struct file *file)
162{
163 int res;
164
165 if (unlikely(atomic_dec_if_positive(&opencnt) < 0))
166 return -EBUSY;
167
168 expect_close = 0;
169 if (locked) {
170 module_put(THIS_MODULE);
171 free_irq(wd_irq, &miscdev);
172 locked = 0;
173 }
174
175 res = request_irq(wd_irq, wdt_gpi_irqhdl, SA_SHIRQ | SA_INTERRUPT,
176 wdt_gpi_name, &miscdev);
177 if (unlikely(res))
178 return res;
179
180 wdt_gpi_set_timeout(timeout);
181 wdt_gpi_start();
182
183 printk(KERN_INFO "%s: watchdog started, timeout = %u seconds\n",
184 wdt_gpi_name, timeout);
185 return nonseekable_open(inode, file);
186}
187
188static int wdt_gpi_release(struct inode *inode, struct file *file)
189{
190 if (nowayout) {
191 printk(KERN_INFO "%s: no way out - watchdog left running\n",
192 wdt_gpi_name);
193 __module_get(THIS_MODULE);
194 locked = 1;
195 } else {
196 if (expect_close) {
197 wdt_gpi_stop();
198 free_irq(wd_irq, &miscdev);
199 printk(KERN_INFO "%s: watchdog stopped\n", wdt_gpi_name);
200 } else {
201 printk(KERN_CRIT "%s: unexpected close() -"
202 " watchdog left running\n",
203 wdt_gpi_name);
204 wdt_gpi_set_timeout(timeout);
205 __module_get(THIS_MODULE);
206 locked = 1;
207 }
208 }
209
210 atomic_inc(&opencnt);
211 return 0;
212}
213
214static ssize_t
215wdt_gpi_write(struct file *f, const char __user *d, size_t s, loff_t *o)
216{
217 char val;
218
219 wdt_gpi_set_timeout(timeout);
220 expect_close = (s > 0) && !get_user(val, d) && (val == 'V');
221 return s ? 1 : 0;
222}
223
224static long
225wdt_gpi_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
226{
227 long res = -ENOTTY;
228 const long size = _IOC_SIZE(cmd);
229 int stat;
230 void __user *argp = (void __user *)arg;
231 static struct watchdog_info wdinfo = {
232 .identity = "RM9xxx/GPI watchdog",
233 .firmware_version = 0,
234 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING
235 };
236
237 if (unlikely(_IOC_TYPE(cmd) != WATCHDOG_IOCTL_BASE))
238 return -ENOTTY;
239
240 if ((_IOC_DIR(cmd) & _IOC_READ)
241 && !access_ok(VERIFY_WRITE, arg, size))
242 return -EFAULT;
243
244 if ((_IOC_DIR(cmd) & _IOC_WRITE)
245 && !access_ok(VERIFY_READ, arg, size))
246 return -EFAULT;
247
248 expect_close = 0;
249
250 switch (cmd) {
251 case WDIOC_GETSUPPORT:
252 wdinfo.options = nowayout ?
253 WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING :
254 WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE;
255 res = __copy_to_user(argp, &wdinfo, size) ? -EFAULT : size;
256 break;
257
258 case WDIOC_GETSTATUS:
259 break;
260
261 case WDIOC_GETBOOTSTATUS:
262 stat = (*(volatile char *) flagaddr & 0x01)
263 ? WDIOF_CARDRESET : 0;
264 res = __copy_to_user(argp, &stat, size) ?
265 -EFAULT : size;
266 break;
267
268 case WDIOC_SETOPTIONS:
269 break;
270
271 case WDIOC_KEEPALIVE:
272 wdt_gpi_set_timeout(timeout);
273 res = size;
274 break;
275
276 case WDIOC_SETTIMEOUT:
277 {
278 int val;
279 if (unlikely(__copy_from_user(&val, argp, size))) {
280 res = -EFAULT;
281 break;
282 }
283
284 if (val > MAX_TIMEOUT_SECONDS)
285 val = MAX_TIMEOUT_SECONDS;
286 timeout = val;
287 wdt_gpi_set_timeout(val);
288 res = size;
289 printk(KERN_INFO "%s: timeout set to %u seconds\n",
290 wdt_gpi_name, timeout);
291 }
292 break;
293
294 case WDIOC_GETTIMEOUT:
295 res = __copy_to_user(argp, &timeout, size) ?
296 -EFAULT : size;
297 break;
298 }
299
300 return res;
301}
302
303
304/* Shutdown notifier */
305static int
306wdt_gpi_notify(struct notifier_block *this, unsigned long code, void *unused)
307{
308 if (code == SYS_DOWN || code == SYS_HALT)
309 wdt_gpi_stop();
310
311 return NOTIFY_DONE;
312}
313
314
315/* Kernel interfaces */
316static struct file_operations fops = {
317 .owner = THIS_MODULE,
318 .open = wdt_gpi_open,
319 .release = wdt_gpi_release,
320 .write = wdt_gpi_write,
321 .unlocked_ioctl = wdt_gpi_ioctl,
322};
323
324static struct miscdevice miscdev = {
325 .minor = WATCHDOG_MINOR,
326 .name = wdt_gpi_name,
327 .fops = &fops,
328};
329
330static struct notifier_block wdt_gpi_shutdown = {
331 .notifier_call = wdt_gpi_notify,
332};
333
334
335/* Init & exit procedures */
336static const struct resource *
337wdt_gpi_get_resource(struct platform_device *pdv, const char *name,
338 unsigned int type)
339{
340 char buf[80];
341 if (snprintf(buf, sizeof buf, "%s_0", name) >= sizeof buf)
342 return NULL;
343 return platform_get_resource_byname(pdv, type, buf);
344}
345
346/* No hotplugging on the platform bus - use __init */
347static int __init wdt_gpi_probe(struct device *dev)
348{
349 int res;
350 struct platform_device * const pdv = to_platform_device(dev);
351 const struct resource
352 * const rr = wdt_gpi_get_resource(pdv, WDT_RESOURCE_REGS,
353 IORESOURCE_MEM),
354 * const ri = wdt_gpi_get_resource(pdv, WDT_RESOURCE_IRQ,
355 IORESOURCE_IRQ),
356 * const rc = wdt_gpi_get_resource(pdv, WDT_RESOURCE_COUNTER,
357 0);
358
359 if (unlikely(!rr || !ri || !rc))
360 return -ENXIO;
361
362 wd_regs = ioremap_nocache(rr->start, rr->end + 1 - rr->start);
363 if (unlikely(!wd_regs))
364 return -ENOMEM;
365 wd_irq = ri->start;
366 wd_ctr = rc->start;
367 res = misc_register(&miscdev);
368 if (res)
369 iounmap(wd_regs);
370 else
371 register_reboot_notifier(&wdt_gpi_shutdown);
372 return res;
373}
374
375static int __exit wdt_gpi_remove(struct device *dev)
376{
377 int res;
378
379 unregister_reboot_notifier(&wdt_gpi_shutdown);
380 res = misc_deregister(&miscdev);
381 iounmap(wd_regs);
382 wd_regs = NULL;
383 return res;
384}
385
386
387/* Device driver init & exit */
388static struct device_driver wdt_gpi_driver = {
389 .name = (char *) wdt_gpi_name,
390 .bus = &platform_bus_type,
391 .owner = THIS_MODULE,
392 .probe = wdt_gpi_probe,
393 .remove = __exit_p(wdt_gpi_remove),
394 .shutdown = NULL,
395 .suspend = NULL,
396 .resume = NULL,
397};
398
399static int __init wdt_gpi_init_module(void)
400{
401 atomic_set(&opencnt, 1);
402 if (timeout > MAX_TIMEOUT_SECONDS)
403 timeout = MAX_TIMEOUT_SECONDS;
404 return driver_register(&wdt_gpi_driver);
405}
406
407static void __exit wdt_gpi_cleanup_module(void)
408{
409 driver_unregister(&wdt_gpi_driver);
410}
411
412module_init(wdt_gpi_init_module);
413module_exit(wdt_gpi_cleanup_module);
414
415MODULE_AUTHOR("Thomas Koeller <thomas.koeller@baslerweb.com>");
416MODULE_DESCRIPTION("Basler eXcite watchdog driver for gpi devices");
417MODULE_VERSION("0.1");
418MODULE_LICENSE("GPL");
419MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
420
diff --git a/drivers/char/watchdog/s3c2410_wdt.c b/drivers/char/watchdog/s3c2410_wdt.c
index be978e8ed754..18cb050c3862 100644
--- a/drivers/char/watchdog/s3c2410_wdt.c
+++ b/drivers/char/watchdog/s3c2410_wdt.c
@@ -62,7 +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
65static int nowayout = WATCHDOG_NOWAYOUT; 65static int nowayout = WATCHDOG_NOWAYOUT;
66static int tmr_margin = CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME; 66static int tmr_margin = CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME;
67static int tmr_atboot = CONFIG_S3C2410_WATCHDOG_ATBOOT; 67static int tmr_atboot = CONFIG_S3C2410_WATCHDOG_ATBOOT;
68static int soft_noboot = 0; 68static int soft_noboot = 0;
@@ -213,11 +213,10 @@ static int s3c2410wdt_open(struct inode *inode, struct file *file)
213 if(down_trylock(&open_lock)) 213 if(down_trylock(&open_lock))
214 return -EBUSY; 214 return -EBUSY;
215 215
216 if (nowayout) { 216 if (nowayout)
217 __module_get(THIS_MODULE); 217 __module_get(THIS_MODULE);
218 } else { 218
219 allow_close = CLOSE_STATE_ALLOW; 219 allow_close = CLOSE_STATE_NOT;
220 }
221 220
222 /* start the timer */ 221 /* start the timer */
223 s3c2410wdt_start(); 222 s3c2410wdt_start();
@@ -230,6 +229,7 @@ static int s3c2410wdt_release(struct inode *inode, struct file *file)
230 * Shut off the timer. 229 * Shut off the timer.
231 * Lock it in if it's a module and we set nowayout 230 * Lock it in if it's a module and we set nowayout
232 */ 231 */
232
233 if (allow_close == CLOSE_STATE_ALLOW) { 233 if (allow_close == CLOSE_STATE_ALLOW) {
234 s3c2410wdt_stop(); 234 s3c2410wdt_stop();
235 } else { 235 } else {
@@ -288,7 +288,7 @@ static int s3c2410wdt_ioctl(struct inode *inode, struct file *file,
288 288
289 switch (cmd) { 289 switch (cmd) {
290 default: 290 default:
291 return -ENOIOCTLCMD; 291 return -ENOTTY;
292 292
293 case WDIOC_GETSUPPORT: 293 case WDIOC_GETSUPPORT:
294 return copy_to_user(argp, &s3c2410_wdt_ident, 294 return copy_to_user(argp, &s3c2410_wdt_ident,
@@ -336,8 +336,7 @@ static struct miscdevice s3c2410wdt_miscdev = {
336 336
337/* interrupt handler code */ 337/* interrupt handler code */
338 338
339static irqreturn_t s3c2410wdt_irq(int irqno, void *param, 339static irqreturn_t s3c2410wdt_irq(int irqno, void *param)
340 struct pt_regs *regs)
341{ 340{
342 printk(KERN_INFO PFX "Watchdog timer expired!\n"); 341 printk(KERN_INFO PFX "Watchdog timer expired!\n");
343 342
@@ -381,18 +380,21 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
381 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 380 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
382 if (res == NULL) { 381 if (res == NULL) {
383 printk(KERN_INFO PFX "failed to get irq resource\n"); 382 printk(KERN_INFO PFX "failed to get irq resource\n");
383 iounmap(wdt_base);
384 return -ENOENT; 384 return -ENOENT;
385 } 385 }
386 386
387 ret = request_irq(res->start, s3c2410wdt_irq, 0, pdev->name, pdev); 387 ret = request_irq(res->start, s3c2410wdt_irq, 0, pdev->name, pdev);
388 if (ret != 0) { 388 if (ret != 0) {
389 printk(KERN_INFO PFX "failed to install irq (%d)\n", ret); 389 printk(KERN_INFO PFX "failed to install irq (%d)\n", ret);
390 iounmap(wdt_base);
390 return ret; 391 return ret;
391 } 392 }
392 393
393 wdt_clock = clk_get(&pdev->dev, "watchdog"); 394 wdt_clock = clk_get(&pdev->dev, "watchdog");
394 if (wdt_clock == NULL) { 395 if (wdt_clock == NULL) {
395 printk(KERN_INFO PFX "failed to find watchdog clock source\n"); 396 printk(KERN_INFO PFX "failed to find watchdog clock source\n");
397 iounmap(wdt_base);
396 return -ENOENT; 398 return -ENOENT;
397 } 399 }
398 400
@@ -416,6 +418,7 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
416 if (ret) { 418 if (ret) {
417 printk (KERN_ERR PFX "cannot register miscdev on minor=%d (%d)\n", 419 printk (KERN_ERR PFX "cannot register miscdev on minor=%d (%d)\n",
418 WATCHDOG_MINOR, ret); 420 WATCHDOG_MINOR, ret);
421 iounmap(wdt_base);
419 return ret; 422 return ret;
420 } 423 }
421 424
@@ -452,6 +455,7 @@ static int s3c2410wdt_remove(struct platform_device *dev)
452 wdt_clock = NULL; 455 wdt_clock = NULL;
453 } 456 }
454 457
458 iounmap(wdt_base);
455 misc_deregister(&s3c2410wdt_miscdev); 459 misc_deregister(&s3c2410wdt_miscdev);
456 return 0; 460 return 0;
457} 461}
diff --git a/drivers/char/watchdog/sa1100_wdt.c b/drivers/char/watchdog/sa1100_wdt.c
index 1fc16d995788..33c1137f17d6 100644
--- a/drivers/char/watchdog/sa1100_wdt.c
+++ b/drivers/char/watchdog/sa1100_wdt.c
@@ -90,7 +90,7 @@ static struct watchdog_info ident = {
90static int sa1100dog_ioctl(struct inode *inode, struct file *file, 90static int sa1100dog_ioctl(struct inode *inode, struct file *file,
91 unsigned int cmd, unsigned long arg) 91 unsigned int cmd, unsigned long arg)
92{ 92{
93 int ret = -ENOIOCTLCMD; 93 int ret = -ENOTTY;
94 int time; 94 int time;
95 void __user *argp = (void __user *)arg; 95 void __user *argp = (void __user *)arg;
96 int __user *p = argp; 96 int __user *p = argp;
diff --git a/drivers/char/watchdog/sbc60xxwdt.c b/drivers/char/watchdog/sbc60xxwdt.c
index 4663c2fd53cd..c7b2045bc76b 100644
--- a/drivers/char/watchdog/sbc60xxwdt.c
+++ b/drivers/char/watchdog/sbc60xxwdt.c
@@ -235,7 +235,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
235 switch(cmd) 235 switch(cmd)
236 { 236 {
237 default: 237 default:
238 return -ENOIOCTLCMD; 238 return -ENOTTY;
239 case WDIOC_GETSUPPORT: 239 case WDIOC_GETSUPPORT:
240 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0; 240 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0;
241 case WDIOC_GETSTATUS: 241 case WDIOC_GETSTATUS:
diff --git a/drivers/char/watchdog/sbc_epx_c3.c b/drivers/char/watchdog/sbc_epx_c3.c
index bfc475dabe6d..8882b427d24f 100644
--- a/drivers/char/watchdog/sbc_epx_c3.c
+++ b/drivers/char/watchdog/sbc_epx_c3.c
@@ -141,7 +141,7 @@ static int epx_c3_ioctl(struct inode *inode, struct file *file,
141 141
142 return retval; 142 return retval;
143 default: 143 default:
144 return -ENOIOCTLCMD; 144 return -ENOTTY;
145 } 145 }
146} 146}
147 147
diff --git a/drivers/char/watchdog/sc1200wdt.c b/drivers/char/watchdog/sc1200wdt.c
index 7c3cf293a5af..e3239833e4b0 100644
--- a/drivers/char/watchdog/sc1200wdt.c
+++ b/drivers/char/watchdog/sc1200wdt.c
@@ -180,7 +180,7 @@ static int sc1200wdt_ioctl(struct inode *inode, struct file *file, unsigned int
180 180
181 switch (cmd) { 181 switch (cmd) {
182 default: 182 default:
183 return -ENOIOCTLCMD; /* Keep Pavel Machek amused ;) */ 183 return -ENOTTY;
184 184
185 case WDIOC_GETSUPPORT: 185 case WDIOC_GETSUPPORT:
186 if (copy_to_user(argp, &ident, sizeof ident)) 186 if (copy_to_user(argp, &ident, sizeof ident))
@@ -392,7 +392,7 @@ static int __init sc1200wdt_init(void)
392 if (io == -1) { 392 if (io == -1) {
393 printk(KERN_ERR PFX "io parameter must be specified\n"); 393 printk(KERN_ERR PFX "io parameter must be specified\n");
394 ret = -EINVAL; 394 ret = -EINVAL;
395 goto out_clean; 395 goto out_pnp;
396 } 396 }
397 397
398#if defined CONFIG_PNP 398#if defined CONFIG_PNP
@@ -405,7 +405,7 @@ static int __init sc1200wdt_init(void)
405 if (!request_region(io, io_len, SC1200_MODULE_NAME)) { 405 if (!request_region(io, io_len, SC1200_MODULE_NAME)) {
406 printk(KERN_ERR PFX "Unable to register IO port %#x\n", io); 406 printk(KERN_ERR PFX "Unable to register IO port %#x\n", io);
407 ret = -EBUSY; 407 ret = -EBUSY;
408 goto out_clean; 408 goto out_pnp;
409 } 409 }
410 410
411 ret = sc1200wdt_probe(); 411 ret = sc1200wdt_probe();
@@ -435,6 +435,11 @@ out_rbt:
435out_io: 435out_io:
436 release_region(io, io_len); 436 release_region(io, io_len);
437 437
438out_pnp:
439#if defined CONFIG_PNP
440 if (isapnp)
441 pnp_unregister_driver(&scl200wdt_pnp_driver);
442#endif
438 goto out_clean; 443 goto out_clean;
439} 444}
440 445
diff --git a/drivers/char/watchdog/sc520_wdt.c b/drivers/char/watchdog/sc520_wdt.c
index 2c7c9db71be8..caec37ba750a 100644
--- a/drivers/char/watchdog/sc520_wdt.c
+++ b/drivers/char/watchdog/sc520_wdt.c
@@ -290,7 +290,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
290 switch(cmd) 290 switch(cmd)
291 { 291 {
292 default: 292 default:
293 return -ENOIOCTLCMD; 293 return -ENOTTY;
294 case WDIOC_GETSUPPORT: 294 case WDIOC_GETSUPPORT:
295 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0; 295 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0;
296 case WDIOC_GETSTATUS: 296 case WDIOC_GETSTATUS:
diff --git a/drivers/char/watchdog/scx200_wdt.c b/drivers/char/watchdog/scx200_wdt.c
index c561299a5537..fc0e0347f9d2 100644
--- a/drivers/char/watchdog/scx200_wdt.c
+++ b/drivers/char/watchdog/scx200_wdt.c
@@ -166,7 +166,7 @@ static int scx200_wdt_ioctl(struct inode *inode, struct file *file,
166 166
167 switch (cmd) { 167 switch (cmd) {
168 default: 168 default:
169 return -ENOIOCTLCMD; 169 return -ENOTTY;
170 case WDIOC_GETSUPPORT: 170 case WDIOC_GETSUPPORT:
171 if(copy_to_user(argp, &ident, sizeof(ident))) 171 if(copy_to_user(argp, &ident, sizeof(ident)))
172 return -EFAULT; 172 return -EFAULT;
diff --git a/drivers/char/watchdog/shwdt.c b/drivers/char/watchdog/shwdt.c
index 1355038f1044..dc403629aeb3 100644
--- a/drivers/char/watchdog/shwdt.c
+++ b/drivers/char/watchdog/shwdt.c
@@ -27,7 +27,7 @@
27#include <linux/notifier.h> 27#include <linux/notifier.h>
28#include <linux/ioport.h> 28#include <linux/ioport.h>
29#include <linux/fs.h> 29#include <linux/fs.h>
30 30#include <linux/mm.h>
31#include <asm/io.h> 31#include <asm/io.h>
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33#include <asm/watchdog.h> 33#include <asm/watchdog.h>
@@ -125,7 +125,6 @@ static void sh_wdt_start(void)
125 125
126/** 126/**
127 * sh_wdt_stop - Stop the Watchdog 127 * sh_wdt_stop - Stop the Watchdog
128 *
129 * Stops the watchdog. 128 * Stops the watchdog.
130 */ 129 */
131static void sh_wdt_stop(void) 130static void sh_wdt_stop(void)
@@ -141,22 +140,20 @@ static void sh_wdt_stop(void)
141 140
142/** 141/**
143 * sh_wdt_keepalive - Keep the Userspace Watchdog Alive 142 * sh_wdt_keepalive - Keep the Userspace Watchdog Alive
144 *
145 * The Userspace watchdog got a KeepAlive: schedule the next heartbeat. 143 * The Userspace watchdog got a KeepAlive: schedule the next heartbeat.
146 */ 144 */
147static void sh_wdt_keepalive(void) 145static inline void sh_wdt_keepalive(void)
148{ 146{
149 next_heartbeat = jiffies + (heartbeat * HZ); 147 next_heartbeat = jiffies + (heartbeat * HZ);
150} 148}
151 149
152/** 150/**
153 * sh_wdt_set_heartbeat - Set the Userspace Watchdog heartbeat 151 * sh_wdt_set_heartbeat - Set the Userspace Watchdog heartbeat
154 *
155 * Set the Userspace Watchdog heartbeat 152 * Set the Userspace Watchdog heartbeat
156 */ 153 */
157static int sh_wdt_set_heartbeat(int t) 154static int sh_wdt_set_heartbeat(int t)
158{ 155{
159 if ((t < 1) || (t > 3600)) /* arbitrary upper limit */ 156 if (unlikely((t < 1) || (t > 3600))) /* arbitrary upper limit */
160 return -EINVAL; 157 return -EINVAL;
161 158
162 heartbeat = t; 159 heartbeat = t;
@@ -165,7 +162,6 @@ static int sh_wdt_set_heartbeat(int t)
165 162
166/** 163/**
167 * sh_wdt_ping - Ping the Watchdog 164 * sh_wdt_ping - Ping the Watchdog
168 *
169 * @data: Unused 165 * @data: Unused
170 * 166 *
171 * Clears overflow bit, resets timer counter. 167 * Clears overflow bit, resets timer counter.
@@ -182,14 +178,13 @@ static void sh_wdt_ping(unsigned long data)
182 sh_wdt_write_cnt(0); 178 sh_wdt_write_cnt(0);
183 179
184 mod_timer(&timer, next_ping_period(clock_division_ratio)); 180 mod_timer(&timer, next_ping_period(clock_division_ratio));
185 } else { 181 } else
186 printk(KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n"); 182 printk(KERN_WARNING PFX "Heartbeat lost! Will not ping "
187 } 183 "the watchdog\n");
188} 184}
189 185
190/** 186/**
191 * sh_wdt_open - Open the Device 187 * sh_wdt_open - Open the Device
192 *
193 * @inode: inode of device 188 * @inode: inode of device
194 * @file: file handle of device 189 * @file: file handle of device
195 * 190 *
@@ -209,7 +204,6 @@ static int sh_wdt_open(struct inode *inode, struct file *file)
209 204
210/** 205/**
211 * sh_wdt_close - Close the Device 206 * sh_wdt_close - Close the Device
212 *
213 * @inode: inode of device 207 * @inode: inode of device
214 * @file: file handle of device 208 * @file: file handle of device
215 * 209 *
@@ -220,7 +214,8 @@ static int sh_wdt_close(struct inode *inode, struct file *file)
220 if (shwdt_expect_close == 42) { 214 if (shwdt_expect_close == 42) {
221 sh_wdt_stop(); 215 sh_wdt_stop();
222 } else { 216 } else {
223 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); 217 printk(KERN_CRIT PFX "Unexpected close, not "
218 "stopping watchdog!\n");
224 sh_wdt_keepalive(); 219 sh_wdt_keepalive();
225 } 220 }
226 221
@@ -232,7 +227,6 @@ static int sh_wdt_close(struct inode *inode, struct file *file)
232 227
233/** 228/**
234 * sh_wdt_write - Write to Device 229 * sh_wdt_write - Write to Device
235 *
236 * @file: file handle of device 230 * @file: file handle of device
237 * @buf: buffer to write 231 * @buf: buffer to write
238 * @count: length of buffer 232 * @count: length of buffer
@@ -264,8 +258,56 @@ static ssize_t sh_wdt_write(struct file *file, const char *buf,
264} 258}
265 259
266/** 260/**
267 * sh_wdt_ioctl - Query Device 261 * sh_wdt_mmap - map WDT/CPG registers into userspace
262 * @file: file structure for the device
263 * @vma: VMA to map the registers into
264 *
265 * A simple mmap() implementation for the corner cases where the counter
266 * needs to be mapped in userspace directly. Due to the relatively small
267 * size of the area, neighbouring registers not necessarily tied to the
268 * CPG will also be accessible through the register page, so this remains
269 * configurable for users that really know what they're doing.
268 * 270 *
271 * Additionaly, the register page maps in the CPG register base relative
272 * to the nearest page-aligned boundary, which requires that userspace do
273 * the appropriate CPU subtype math for calculating the page offset for
274 * the counter value.
275 */
276static int sh_wdt_mmap(struct file *file, struct vm_area_struct *vma)
277{
278 int ret = -ENOSYS;
279
280#ifdef CONFIG_SH_WDT_MMAP
281 unsigned long addr;
282
283 /* Only support the simple cases where we map in a register page. */
284 if (((vma->vm_end - vma->vm_start) != PAGE_SIZE) || vma->vm_pgoff)
285 return -EINVAL;
286
287 /*
288 * Pick WTCNT as the start, it's usually the first register after the
289 * FRQCR, and neither one are generally page-aligned out of the box.
290 */
291 addr = WTCNT & ~(PAGE_SIZE - 1);
292
293 vma->vm_flags |= VM_IO;
294 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
295
296 if (io_remap_pfn_range(vma, vma->vm_start, addr >> PAGE_SHIFT,
297 PAGE_SIZE, vma->vm_page_prot)) {
298 printk(KERN_ERR PFX "%s: io_remap_pfn_range failed\n",
299 __FUNCTION__);
300 return -EAGAIN;
301 }
302
303 ret = 0;
304#endif
305
306 return ret;
307}
308
309/**
310 * sh_wdt_ioctl - Query Device
269 * @inode: inode of device 311 * @inode: inode of device
270 * @file: file handle of device 312 * @file: file handle of device
271 * @cmd: watchdog command 313 * @cmd: watchdog command
@@ -318,7 +360,7 @@ static int sh_wdt_ioctl(struct inode *inode, struct file *file,
318 360
319 return retval; 361 return retval;
320 default: 362 default:
321 return -ENOIOCTLCMD; 363 return -ENOTTY;
322 } 364 }
323 365
324 return 0; 366 return 0;
@@ -326,7 +368,6 @@ static int sh_wdt_ioctl(struct inode *inode, struct file *file,
326 368
327/** 369/**
328 * sh_wdt_notify_sys - Notifier Handler 370 * sh_wdt_notify_sys - Notifier Handler
329 *
330 * @this: notifier block 371 * @this: notifier block
331 * @code: notifier event 372 * @code: notifier event
332 * @unused: unused 373 * @unused: unused
@@ -337,9 +378,8 @@ static int sh_wdt_ioctl(struct inode *inode, struct file *file,
337static int sh_wdt_notify_sys(struct notifier_block *this, 378static int sh_wdt_notify_sys(struct notifier_block *this,
338 unsigned long code, void *unused) 379 unsigned long code, void *unused)
339{ 380{
340 if (code == SYS_DOWN || code == SYS_HALT) { 381 if (code == SYS_DOWN || code == SYS_HALT)
341 sh_wdt_stop(); 382 sh_wdt_stop();
342 }
343 383
344 return NOTIFY_DONE; 384 return NOTIFY_DONE;
345} 385}
@@ -351,10 +391,12 @@ static const struct file_operations sh_wdt_fops = {
351 .ioctl = sh_wdt_ioctl, 391 .ioctl = sh_wdt_ioctl,
352 .open = sh_wdt_open, 392 .open = sh_wdt_open,
353 .release = sh_wdt_close, 393 .release = sh_wdt_close,
394 .mmap = sh_wdt_mmap,
354}; 395};
355 396
356static struct watchdog_info sh_wdt_info = { 397static struct watchdog_info sh_wdt_info = {
357 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, 398 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
399 WDIOF_MAGICCLOSE,
358 .firmware_version = 1, 400 .firmware_version = 1,
359 .identity = "SH WDT", 401 .identity = "SH WDT",
360}; 402};
@@ -371,7 +413,6 @@ static struct miscdevice sh_wdt_miscdev = {
371 413
372/** 414/**
373 * sh_wdt_init - Initialize module 415 * sh_wdt_init - Initialize module
374 *
375 * Registers the device and notifier handler. Actual device 416 * Registers the device and notifier handler. Actual device
376 * initialization is handled by sh_wdt_open(). 417 * initialization is handled by sh_wdt_open().
377 */ 418 */
@@ -381,15 +422,15 @@ static int __init sh_wdt_init(void)
381 422
382 if ((clock_division_ratio < 0x5) || (clock_division_ratio > 0x7)) { 423 if ((clock_division_ratio < 0x5) || (clock_division_ratio > 0x7)) {
383 clock_division_ratio = WTCSR_CKS_4096; 424 clock_division_ratio = WTCSR_CKS_4096;
384 printk(KERN_INFO PFX "clock_division_ratio value must be 0x5<=x<=0x7, using %d\n", 425 printk(KERN_INFO PFX "clock_division_ratio value must "
385 clock_division_ratio); 426 "be 0x5<=x<=0x7, using %d\n", clock_division_ratio);
386 } 427 }
387 428
388 if (sh_wdt_set_heartbeat(heartbeat)) 429 rc = sh_wdt_set_heartbeat(heartbeat);
389 { 430 if (unlikely(rc)) {
390 heartbeat = WATCHDOG_HEARTBEAT; 431 heartbeat = WATCHDOG_HEARTBEAT;
391 printk(KERN_INFO PFX "heartbeat value must be 1<=x<=3600, using %d\n", 432 printk(KERN_INFO PFX "heartbeat value must "
392 heartbeat); 433 "be 1<=x<=3600, using %d\n", heartbeat);
393 } 434 }
394 435
395 init_timer(&timer); 436 init_timer(&timer);
@@ -397,15 +438,16 @@ static int __init sh_wdt_init(void)
397 timer.data = 0; 438 timer.data = 0;
398 439
399 rc = register_reboot_notifier(&sh_wdt_notifier); 440 rc = register_reboot_notifier(&sh_wdt_notifier);
400 if (rc) { 441 if (unlikely(rc)) {
401 printk(KERN_ERR PFX "Can't register reboot notifier (err=%d)\n", rc); 442 printk(KERN_ERR PFX "Can't register reboot notifier (err=%d)\n",
443 rc);
402 return rc; 444 return rc;
403 } 445 }
404 446
405 rc = misc_register(&sh_wdt_miscdev); 447 rc = misc_register(&sh_wdt_miscdev);
406 if (rc) { 448 if (unlikely(rc)) {
407 printk(KERN_ERR PFX "Can't register miscdev on minor=%d (err=%d)\n", 449 printk(KERN_ERR PFX "Can't register miscdev on "
408 sh_wdt_miscdev.minor, rc); 450 "minor=%d (err=%d)\n", sh_wdt_miscdev.minor, rc);
409 unregister_reboot_notifier(&sh_wdt_notifier); 451 unregister_reboot_notifier(&sh_wdt_notifier);
410 return rc; 452 return rc;
411 } 453 }
@@ -418,7 +460,6 @@ static int __init sh_wdt_init(void)
418 460
419/** 461/**
420 * sh_wdt_exit - Deinitialize module 462 * sh_wdt_exit - Deinitialize module
421 *
422 * Unregisters the device and notifier handler. Actual device 463 * Unregisters the device and notifier handler. Actual device
423 * deinitialization is handled by sh_wdt_close(). 464 * deinitialization is handled by sh_wdt_close().
424 */ 465 */
@@ -434,14 +475,13 @@ MODULE_LICENSE("GPL");
434MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); 475MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
435 476
436module_param(clock_division_ratio, int, 0); 477module_param(clock_division_ratio, int, 0);
437MODULE_PARM_DESC(clock_division_ratio, "Clock division ratio. Valid ranges are from 0x5 (1.31ms) to 0x7 (5.25ms). Defaults to 0x7."); 478MODULE_PARM_DESC(clock_division_ratio, "Clock division ratio. Valid ranges are from 0x5 (1.31ms) to 0x7 (5.25ms). (default=" __MODULE_STRING(clock_division_ratio) ")");
438 479
439module_param(heartbeat, int, 0); 480module_param(heartbeat, int, 0);
440MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (1<=heartbeat<=3600, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")"); 481MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (1<=heartbeat<=3600, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
441 482
442module_param(nowayout, int, 0); 483module_param(nowayout, int, 0);
443MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 484MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
444 485
445module_init(sh_wdt_init); 486module_init(sh_wdt_init);
446module_exit(sh_wdt_exit); 487module_exit(sh_wdt_exit);
447
diff --git a/drivers/char/watchdog/smsc37b787_wdt.c b/drivers/char/watchdog/smsc37b787_wdt.c
new file mode 100644
index 000000000000..9f56913b484f
--- /dev/null
+++ b/drivers/char/watchdog/smsc37b787_wdt.c
@@ -0,0 +1,627 @@
1/*
2 * SMsC 37B787 Watchdog Timer driver for Linux 2.6.x.x
3 *
4 * Based on acquirewdt.c by Alan Cox <alan@redhat.com>
5 * and some other existing drivers
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 * The authors do NOT admit liability nor provide warranty for
13 * any of this software. This material is provided "AS-IS" in
14 * the hope that it may be useful for others.
15 *
16 * (C) Copyright 2003-2006 Sven Anders <anders@anduras.de>
17 *
18 * History:
19 * 2003 - Created version 1.0 for Linux 2.4.x.
20 * 2006 - Ported to Linux 2.6, added nowayout and MAGICCLOSE
21 * features. Released version 1.1
22 *
23 * Theory of operation:
24 *
25 * A Watchdog Timer (WDT) is a hardware circuit that can
26 * reset the computer system in case of a software fault.
27 * You probably knew that already.
28 *
29 * Usually a userspace daemon will notify the kernel WDT driver
30 * via the /dev/watchdog special device file that userspace is
31 * still alive, at regular intervals. When such a notification
32 * occurs, the driver will usually tell the hardware watchdog
33 * that everything is in order, and that the watchdog should wait
34 * for yet another little while to reset the system.
35 * If userspace fails (RAM error, kernel bug, whatever), the
36 * notifications cease to occur, and the hardware watchdog will
37 * reset the system (causing a reboot) after the timeout occurs.
38 *
39 * Create device with:
40 * mknod /dev/watchdog c 10 130
41 *
42 * For an example userspace keep-alive daemon, see:
43 * Documentation/watchdog/watchdog.txt
44 */
45
46#include <linux/module.h>
47#include <linux/moduleparam.h>
48#include <linux/types.h>
49#include <linux/miscdevice.h>
50#include <linux/watchdog.h>
51#include <linux/delay.h>
52#include <linux/fs.h>
53#include <linux/ioport.h>
54#include <linux/notifier.h>
55#include <linux/reboot.h>
56#include <linux/init.h>
57#include <linux/spinlock.h>
58
59#include <asm/io.h>
60#include <asm/uaccess.h>
61#include <asm/system.h>
62
63/* enable support for minutes as units? */
64/* (does not always work correctly, so disabled by default!) */
65#define SMSC_SUPPORT_MINUTES
66#undef SMSC_SUPPORT_MINUTES
67
68#define MAX_TIMEOUT 255
69
70#define UNIT_SECOND 0
71#define UNIT_MINUTE 1
72
73#define MODNAME "smsc37b787_wdt: "
74#define VERSION "1.1"
75
76#define IOPORT 0x3F0
77#define IOPORT_SIZE 2
78#define IODEV_NO 8
79
80static int unit = UNIT_SECOND; /* timer's unit */
81static int timeout = 60; /* timeout value: default is 60 "units" */
82static unsigned long timer_enabled = 0; /* is the timer enabled? */
83
84static char expect_close; /* is the close expected? */
85
86static spinlock_t io_lock; /* to guard the watchdog from io races */
87
88static int nowayout = WATCHDOG_NOWAYOUT;
89
90/* -- Low level function ----------------------------------------*/
91
92/* unlock the IO chip */
93
94static inline void open_io_config(void)
95{
96 outb(0x55, IOPORT);
97 mdelay(1);
98 outb(0x55, IOPORT);
99}
100
101/* lock the IO chip */
102static inline void close_io_config(void)
103{
104 outb(0xAA, IOPORT);
105}
106
107/* select the IO device */
108static inline void select_io_device(unsigned char devno)
109{
110 outb(0x07, IOPORT);
111 outb(devno, IOPORT+1);
112}
113
114/* write to the control register */
115static inline void write_io_cr(unsigned char reg, unsigned char data)
116{
117 outb(reg, IOPORT);
118 outb(data, IOPORT+1);
119}
120
121/* read from the control register */
122static inline char read_io_cr(unsigned char reg)
123{
124 outb(reg, IOPORT);
125 return inb(IOPORT+1);
126}
127
128/* -- Medium level functions ------------------------------------*/
129
130static inline void gpio_bit12(unsigned char reg)
131{
132 // -- General Purpose I/O Bit 1.2 --
133 // Bit 0, In/Out: 0 = Output, 1 = Input
134 // Bit 1, Polarity: 0 = No Invert, 1 = Invert
135 // Bit 2, Group Enable Intr.: 0 = Disable, 1 = Enable
136 // Bit 3/4, Function select: 00 = GPI/O, 01 = WDT, 10 = P17,
137 // 11 = Either Edge Triggered Intr. 2
138 // Bit 5/6 (Reserved)
139 // Bit 7, Output Type: 0 = Push Pull Bit, 1 = Open Drain
140 write_io_cr(0xE2, reg);
141}
142
143static inline void gpio_bit13(unsigned char reg)
144{
145 // -- General Purpose I/O Bit 1.3 --
146 // Bit 0, In/Out: 0 = Output, 1 = Input
147 // Bit 1, Polarity: 0 = No Invert, 1 = Invert
148 // Bit 2, Group Enable Intr.: 0 = Disable, 1 = Enable
149 // Bit 3, Function select: 0 = GPI/O, 1 = LED
150 // Bit 4-6 (Reserved)
151 // Bit 7, Output Type: 0 = Push Pull Bit, 1 = Open Drain
152 write_io_cr(0xE3, reg);
153}
154
155static inline void wdt_timer_units(unsigned char new_units)
156{
157 // -- Watchdog timer units --
158 // Bit 0-6 (Reserved)
159 // Bit 7, WDT Time-out Value Units Select
160 // (0 = Minutes, 1 = Seconds)
161 write_io_cr(0xF1, new_units);
162}
163
164static inline void wdt_timeout_value(unsigned char new_timeout)
165{
166 // -- Watchdog Timer Time-out Value --
167 // Bit 0-7 Binary coded units (0=Disabled, 1..255)
168 write_io_cr(0xF2, new_timeout);
169}
170
171static inline void wdt_timer_conf(unsigned char conf)
172{
173 // -- Watchdog timer configuration --
174 // Bit 0 Joystick enable: 0* = No Reset, 1 = Reset WDT upon Gameport I/O
175 // Bit 1 Keyboard enable: 0* = No Reset, 1 = Reset WDT upon KBD Intr.
176 // Bit 2 Mouse enable: 0* = No Reset, 1 = Reset WDT upon Mouse Intr.
177 // Bit 3 Reset the timer
178 // (Wrong in SMsC documentation? Given as: PowerLED Timout Enabled)
179 // Bit 4-7 WDT Interrupt Mapping: (0000* = Disabled,
180 // 0001=IRQ1, 0010=(Invalid), 0011=IRQ3 to 1111=IRQ15)
181 write_io_cr(0xF3, conf);
182}
183
184static inline void wdt_timer_ctrl(unsigned char reg)
185{
186 // -- Watchdog timer control --
187 // Bit 0 Status Bit: 0 = Timer counting, 1 = Timeout occured
188 // Bit 1 Power LED Toggle: 0 = Disable Toggle, 1 = Toggle at 1 Hz
189 // Bit 2 Force Timeout: 1 = Forces WD timeout event (self-cleaning)
190 // Bit 3 P20 Force Timeout enabled:
191 // 0 = P20 activity does not generate the WD timeout event
192 // 1 = P20 Allows rising edge of P20, from the keyboard
193 // controller, to force the WD timeout event.
194 // Bit 4 (Reserved)
195 // -- Soft power management --
196 // Bit 5 Stop Counter: 1 = Stop software power down counter
197 // set via register 0xB8, (self-cleaning)
198 // (Upon read: 0 = Counter running, 1 = Counter stopped)
199 // Bit 6 Restart Counter: 1 = Restart software power down counter
200 // set via register 0xB8, (self-cleaning)
201 // Bit 7 SPOFF: 1 = Force software power down (self-cleaning)
202
203 write_io_cr(0xF4, reg);
204}
205
206/* -- Higher level functions ------------------------------------*/
207
208/* initialize watchdog */
209
210static void wb_smsc_wdt_initialize(void)
211{
212 unsigned char old;
213
214 spin_lock(&io_lock);
215 open_io_config();
216 select_io_device(IODEV_NO);
217
218 // enable the watchdog
219 gpio_bit13(0x08); // Select pin 80 = LED not GPIO
220 gpio_bit12(0x0A); // Set pin 79 = WDT not GPIO/Output/Polarity=Invert
221
222 // disable the timeout
223 wdt_timeout_value(0);
224
225 // reset control register
226 wdt_timer_ctrl(0x00);
227
228 // reset configuration register
229 wdt_timer_conf(0x00);
230
231 // read old (timer units) register
232 old = read_io_cr(0xF1) & 0x7F;
233 if (unit == UNIT_SECOND) old |= 0x80; // set to seconds
234
235 // set the watchdog timer units
236 wdt_timer_units(old);
237
238 close_io_config();
239 spin_unlock(&io_lock);
240}
241
242/* shutdown the watchdog */
243
244static void wb_smsc_wdt_shutdown(void)
245{
246 spin_lock(&io_lock);
247 open_io_config();
248 select_io_device(IODEV_NO);
249
250 // disable the watchdog
251 gpio_bit13(0x09);
252 gpio_bit12(0x09);
253
254 // reset watchdog config register
255 wdt_timer_conf(0x00);
256
257 // reset watchdog control register
258 wdt_timer_ctrl(0x00);
259
260 // disable timeout
261 wdt_timeout_value(0x00);
262
263 close_io_config();
264 spin_unlock(&io_lock);
265}
266
267/* set timeout => enable watchdog */
268
269static void wb_smsc_wdt_set_timeout(unsigned char new_timeout)
270{
271 spin_lock(&io_lock);
272 open_io_config();
273 select_io_device(IODEV_NO);
274
275 // set Power LED to blink, if we enable the timeout
276 wdt_timer_ctrl((new_timeout == 0) ? 0x00 : 0x02);
277
278 // set timeout value
279 wdt_timeout_value(new_timeout);
280
281 close_io_config();
282 spin_unlock(&io_lock);
283}
284
285/* get timeout */
286
287static unsigned char wb_smsc_wdt_get_timeout(void)
288{
289 unsigned char set_timeout;
290
291 spin_lock(&io_lock);
292 open_io_config();
293 select_io_device(IODEV_NO);
294 set_timeout = read_io_cr(0xF2);
295 close_io_config();
296 spin_unlock(&io_lock);
297
298 return set_timeout;
299}
300
301/* disable watchdog */
302
303static void wb_smsc_wdt_disable(void)
304{
305 // set the timeout to 0 to disable the watchdog
306 wb_smsc_wdt_set_timeout(0);
307}
308
309/* enable watchdog by setting the current timeout */
310
311static void wb_smsc_wdt_enable(void)
312{
313 // set the current timeout...
314 wb_smsc_wdt_set_timeout(timeout);
315}
316
317/* reset the timer */
318
319static void wb_smsc_wdt_reset_timer(void)
320{
321 spin_lock(&io_lock);
322 open_io_config();
323 select_io_device(IODEV_NO);
324
325 // reset the timer
326 wdt_timeout_value(timeout);
327 wdt_timer_conf(0x08);
328
329 close_io_config();
330 spin_unlock(&io_lock);
331}
332
333/* return, if the watchdog is enabled (timeout is set...) */
334
335static int wb_smsc_wdt_status(void)
336{
337 return (wb_smsc_wdt_get_timeout() == 0) ? 0 : WDIOF_KEEPALIVEPING;
338}
339
340
341/* -- File operations -------------------------------------------*/
342
343/* open => enable watchdog and set initial timeout */
344
345static int wb_smsc_wdt_open(struct inode *inode, struct file *file)
346{
347 /* /dev/watchdog can only be opened once */
348
349 if (test_and_set_bit(0, &timer_enabled))
350 return -EBUSY;
351
352 if (nowayout)
353 __module_get(THIS_MODULE);
354
355 /* Reload and activate timer */
356 wb_smsc_wdt_enable();
357
358 printk(KERN_INFO MODNAME "Watchdog enabled. Timeout set to %d %s.\n", timeout, (unit == UNIT_SECOND) ? "second(s)" : "minute(s)");
359
360 return nonseekable_open(inode, file);
361}
362
363/* close => shut off the timer */
364
365static int wb_smsc_wdt_release(struct inode *inode, struct file *file)
366{
367 /* Shut off the timer. */
368
369 if (expect_close == 42) {
370 wb_smsc_wdt_disable();
371 printk(KERN_INFO MODNAME "Watchdog disabled, sleeping again...\n");
372 } else {
373 printk(KERN_CRIT MODNAME "Unexpected close, not stopping watchdog!\n");
374 wb_smsc_wdt_reset_timer();
375 }
376
377 clear_bit(0, &timer_enabled);
378 expect_close = 0;
379 return 0;
380}
381
382/* write => update the timer to keep the machine alive */
383
384static ssize_t wb_smsc_wdt_write(struct file *file, const char __user *data,
385 size_t len, loff_t *ppos)
386{
387 /* See if we got the magic character 'V' and reload the timer */
388 if (len) {
389 if (!nowayout) {
390 size_t i;
391
392 /* reset expect flag */
393 expect_close = 0;
394
395 /* scan to see whether or not we got the magic character */
396 for (i = 0; i != len; i++) {
397 char c;
398 if (get_user(c, data+i))
399 return -EFAULT;
400 if (c == 'V')
401 expect_close = 42;
402 }
403 }
404
405 /* someone wrote to us, we should reload the timer */
406 wb_smsc_wdt_reset_timer();
407 }
408 return len;
409}
410
411/* ioctl => control interface */
412
413static int wb_smsc_wdt_ioctl(struct inode *inode, struct file *file,
414 unsigned int cmd, unsigned long arg)
415{
416 int new_timeout;
417
418 union {
419 struct watchdog_info __user *ident;
420 int __user *i;
421 } uarg;
422
423 static struct watchdog_info ident = {
424 .options = WDIOF_KEEPALIVEPING |
425 WDIOF_SETTIMEOUT |
426 WDIOF_MAGICCLOSE,
427 .firmware_version = 0,
428 .identity = "SMsC 37B787 Watchdog"
429 };
430
431 uarg.i = (int __user *)arg;
432
433 switch (cmd) {
434 default:
435 return -ENOTTY;
436
437 case WDIOC_GETSUPPORT:
438 return copy_to_user(uarg.ident, &ident,
439 sizeof(ident)) ? -EFAULT : 0;
440
441 case WDIOC_GETSTATUS:
442 return put_user(wb_smsc_wdt_status(), uarg.i);
443
444 case WDIOC_GETBOOTSTATUS:
445 return put_user(0, uarg.i);
446
447 case WDIOC_KEEPALIVE:
448 wb_smsc_wdt_reset_timer();
449 return 0;
450
451 case WDIOC_SETTIMEOUT:
452 if (get_user(new_timeout, uarg.i))
453 return -EFAULT;
454
455 // the API states this is given in secs
456 if (unit == UNIT_MINUTE)
457 new_timeout /= 60;
458
459 if (new_timeout < 0 || new_timeout > MAX_TIMEOUT)
460 return -EINVAL;
461
462 timeout = new_timeout;
463 wb_smsc_wdt_set_timeout(timeout);
464
465 // fall through and return the new timeout...
466
467 case WDIOC_GETTIMEOUT:
468
469 new_timeout = timeout;
470
471 if (unit == UNIT_MINUTE)
472 new_timeout *= 60;
473
474 return put_user(new_timeout, uarg.i);
475
476 case WDIOC_SETOPTIONS:
477 {
478 int options, retval = -EINVAL;
479
480 if (get_user(options, uarg.i))
481 return -EFAULT;
482
483 if (options & WDIOS_DISABLECARD) {
484 wb_smsc_wdt_disable();
485 retval = 0;
486 }
487
488 if (options & WDIOS_ENABLECARD) {
489 wb_smsc_wdt_enable();
490 retval = 0;
491 }
492
493 return retval;
494 }
495 }
496}
497
498/* -- Notifier funtions -----------------------------------------*/
499
500static int wb_smsc_wdt_notify_sys(struct notifier_block *this, unsigned long code, void *unused)
501{
502 if (code == SYS_DOWN || code == SYS_HALT)
503 {
504 // set timeout to 0, to avoid possible race-condition
505 timeout = 0;
506 wb_smsc_wdt_disable();
507 }
508 return NOTIFY_DONE;
509}
510
511/* -- Module's structures ---------------------------------------*/
512
513static struct file_operations wb_smsc_wdt_fops =
514{
515 .owner = THIS_MODULE,
516 .llseek = no_llseek,
517 .write = wb_smsc_wdt_write,
518 .ioctl = wb_smsc_wdt_ioctl,
519 .open = wb_smsc_wdt_open,
520 .release = wb_smsc_wdt_release,
521};
522
523static struct notifier_block wb_smsc_wdt_notifier =
524{
525 .notifier_call = wb_smsc_wdt_notify_sys,
526};
527
528static struct miscdevice wb_smsc_wdt_miscdev =
529{
530 .minor = WATCHDOG_MINOR,
531 .name = "watchdog",
532 .fops = &wb_smsc_wdt_fops,
533};
534
535/* -- Module init functions -------------------------------------*/
536
537/* module's "constructor" */
538
539static int __init wb_smsc_wdt_init(void)
540{
541 int ret;
542
543 spin_lock_init(&io_lock);
544
545 printk("SMsC 37B787 watchdog component driver " VERSION " initialising...\n");
546
547 if (!request_region(IOPORT, IOPORT_SIZE, "SMsC 37B787 watchdog")) {
548 printk(KERN_ERR MODNAME "Unable to register IO port %#x\n", IOPORT);
549 ret = -EBUSY;
550 goto out_pnp;
551 }
552
553 // set new maximum, if it's too big
554 if (timeout > MAX_TIMEOUT)
555 timeout = MAX_TIMEOUT;
556
557 // init the watchdog timer
558 wb_smsc_wdt_initialize();
559
560 ret = register_reboot_notifier(&wb_smsc_wdt_notifier);
561 if (ret) {
562 printk(KERN_ERR MODNAME "Unable to register reboot notifier err = %d\n", ret);
563 goto out_io;
564 }
565
566 ret = misc_register(&wb_smsc_wdt_miscdev);
567 if (ret) {
568 printk(KERN_ERR MODNAME "Unable to register miscdev on minor %d\n", WATCHDOG_MINOR);
569 goto out_rbt;
570 }
571
572 // output info
573 printk(KERN_INFO MODNAME "Timeout set to %d %s.\n", timeout, (unit == UNIT_SECOND) ? "second(s)" : "minute(s)");
574 printk(KERN_INFO MODNAME "Watchdog initialized and sleeping (nowayout=%d)...\n", nowayout);
575
576 // ret = 0
577
578out_clean:
579 return ret;
580
581out_rbt:
582 unregister_reboot_notifier(&wb_smsc_wdt_notifier);
583
584out_io:
585 release_region(IOPORT, IOPORT_SIZE);
586
587out_pnp:
588 goto out_clean;
589}
590
591/* module's "destructor" */
592
593static void __exit wb_smsc_wdt_exit(void)
594{
595 /* Stop the timer before we leave */
596 if (!nowayout)
597 {
598 wb_smsc_wdt_shutdown();
599 printk(KERN_INFO MODNAME "Watchdog disabled.\n");
600 }
601
602 misc_deregister(&wb_smsc_wdt_miscdev);
603 unregister_reboot_notifier(&wb_smsc_wdt_notifier);
604 release_region(IOPORT, IOPORT_SIZE);
605
606 printk("SMsC 37B787 watchdog component driver removed.\n");
607}
608
609module_init(wb_smsc_wdt_init);
610module_exit(wb_smsc_wdt_exit);
611
612MODULE_AUTHOR("Sven Anders <anders@anduras.de>");
613MODULE_DESCRIPTION("Driver for SMsC 37B787 watchdog component (Version " VERSION ")");
614MODULE_LICENSE("GPL");
615
616MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
617
618#ifdef SMSC_SUPPORT_MINUTES
619module_param(unit, int, 0);
620MODULE_PARM_DESC(unit, "set unit to use, 0=seconds or 1=minutes, default is 0");
621#endif
622
623module_param(timeout, int, 0);
624MODULE_PARM_DESC(timeout, "range is 1-255 units, default is 60");
625
626module_param(nowayout, int, 0);
627MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
diff --git a/drivers/char/watchdog/softdog.c b/drivers/char/watchdog/softdog.c
index ef8da517545a..4067e1f8a368 100644
--- a/drivers/char/watchdog/softdog.c
+++ b/drivers/char/watchdog/softdog.c
@@ -203,7 +203,7 @@ static int softdog_ioctl(struct inode *inode, struct file *file,
203 }; 203 };
204 switch (cmd) { 204 switch (cmd) {
205 default: 205 default:
206 return -ENOIOCTLCMD; 206 return -ENOTTY;
207 case WDIOC_GETSUPPORT: 207 case WDIOC_GETSUPPORT:
208 return copy_to_user(argp, &ident, 208 return copy_to_user(argp, &ident,
209 sizeof(ident)) ? -EFAULT : 0; 209 sizeof(ident)) ? -EFAULT : 0;
diff --git a/drivers/char/watchdog/w83627hf_wdt.c b/drivers/char/watchdog/w83627hf_wdt.c
index 13f16d41c2fd..07d4bff27226 100644
--- a/drivers/char/watchdog/w83627hf_wdt.c
+++ b/drivers/char/watchdog/w83627hf_wdt.c
@@ -33,6 +33,7 @@
33#include <linux/notifier.h> 33#include <linux/notifier.h>
34#include <linux/reboot.h> 34#include <linux/reboot.h>
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/spinlock.h>
36 37
37#include <asm/io.h> 38#include <asm/io.h>
38#include <asm/uaccess.h> 39#include <asm/uaccess.h>
@@ -44,6 +45,7 @@
44 45
45static unsigned long wdt_is_open; 46static unsigned long wdt_is_open;
46static char expect_close; 47static char expect_close;
48static spinlock_t io_lock;
47 49
48/* You must set this - there is no sane way to probe for this board. */ 50/* You must set this - there is no sane way to probe for this board. */
49static int wdt_io = 0x2E; 51static int wdt_io = 0x2E;
@@ -110,12 +112,16 @@ w83627hf_init(void)
110static void 112static void
111wdt_ctrl(int timeout) 113wdt_ctrl(int timeout)
112{ 114{
115 spin_lock(&io_lock);
116
113 w83627hf_select_wd_register(); 117 w83627hf_select_wd_register();
114 118
115 outb_p(0xF6, WDT_EFER); /* Select CRF6 */ 119 outb_p(0xF6, WDT_EFER); /* Select CRF6 */
116 outb_p(timeout, WDT_EFDR); /* Write Timeout counter to CRF6 */ 120 outb_p(timeout, WDT_EFDR); /* Write Timeout counter to CRF6 */
117 121
118 w83627hf_unselect_wd_register(); 122 w83627hf_unselect_wd_register();
123
124 spin_unlock(&io_lock);
119} 125}
120 126
121static int 127static int
@@ -223,7 +229,7 @@ wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
223 } 229 }
224 230
225 default: 231 default:
226 return -ENOIOCTLCMD; 232 return -ENOTTY;
227 } 233 }
228 return 0; 234 return 0;
229} 235}
@@ -303,6 +309,8 @@ wdt_init(void)
303{ 309{
304 int ret; 310 int ret;
305 311
312 spin_lock_init(&io_lock);
313
306 printk(KERN_INFO "WDT driver for the Winbond(TM) W83627HF Super I/O chip initialising.\n"); 314 printk(KERN_INFO "WDT driver for the Winbond(TM) W83627HF Super I/O chip initialising.\n");
307 315
308 if (wdt_set_heartbeat(timeout)) { 316 if (wdt_set_heartbeat(timeout)) {
diff --git a/drivers/char/watchdog/w83697hf_wdt.c b/drivers/char/watchdog/w83697hf_wdt.c
new file mode 100644
index 000000000000..7768b55487c8
--- /dev/null
+++ b/drivers/char/watchdog/w83697hf_wdt.c
@@ -0,0 +1,450 @@
1/*
2 * w83697hf/hg WDT driver
3 *
4 * (c) Copyright 2006 Samuel Tardieu <sam@rfc1149.net>
5 * (c) Copyright 2006 Marcus Junker <junker@anduras.de>
6 *
7 * Based on w83627hf_wdt.c which is based on advantechwdt.c
8 * which is based on wdt.c.
9 * Original copyright messages:
10 *
11 * (c) Copyright 2003 Pádraig Brady <P@draigBrady.com>
12 *
13 * (c) Copyright 2000-2001 Marek Michalkiewicz <marekm@linux.org.pl>
14 *
15 * (c) Copyright 1996 Alan Cox <alan@redhat.com>, All Rights Reserved.
16 * http://www.redhat.com
17 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
22 *
23 * Neither Marcus Junker nor ANDURAS AG admit liability nor provide
24 * warranty for any of this software. This material is provided
25 * "AS-IS" and at no charge.
26 */
27
28#include <linux/module.h>
29#include <linux/moduleparam.h>
30#include <linux/types.h>
31#include <linux/miscdevice.h>
32#include <linux/watchdog.h>
33#include <linux/fs.h>
34#include <linux/ioport.h>
35#include <linux/notifier.h>
36#include <linux/reboot.h>
37#include <linux/init.h>
38#include <linux/spinlock.h>
39
40#include <asm/io.h>
41#include <asm/uaccess.h>
42#include <asm/system.h>
43
44#define WATCHDOG_NAME "w83697hf/hg WDT"
45#define PFX WATCHDOG_NAME ": "
46#define WATCHDOG_TIMEOUT 60 /* 60 sec default timeout */
47
48static unsigned long wdt_is_open;
49static char expect_close;
50static spinlock_t io_lock;
51
52/* You must set this - there is no sane way to probe for this board. */
53static int wdt_io = 0x2e;
54module_param(wdt_io, int, 0);
55MODULE_PARM_DESC(wdt_io, "w83697hf/hg WDT io port (default 0x2e, 0 = autodetect)");
56
57static int timeout = WATCHDOG_TIMEOUT; /* in seconds */
58module_param(timeout, int, 0);
59MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. 1<= timeout <=255, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ".");
60
61static int nowayout = WATCHDOG_NOWAYOUT;
62module_param(nowayout, int, 0);
63MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
64
65/*
66 * Kernel methods.
67 */
68
69#define W83697HF_EFER (wdt_io+0) /* Extended Function Enable Register */
70#define W83697HF_EFIR (wdt_io+0) /* Extended Function Index Register (same as EFER) */
71#define W83697HF_EFDR (wdt_io+1) /* Extended Function Data Register */
72
73static inline void
74w83697hf_unlock(void)
75{
76 outb_p(0x87, W83697HF_EFER); /* Enter extended function mode */
77 outb_p(0x87, W83697HF_EFER); /* Again according to manual */
78}
79
80static inline void
81w83697hf_lock(void)
82{
83 outb_p(0xAA, W83697HF_EFER); /* Leave extended function mode */
84}
85
86/*
87 * The three functions w83697hf_get_reg(), w83697hf_set_reg() and
88 * w83697hf_write_timeout() must be called with the device unlocked.
89 */
90
91static unsigned char
92w83697hf_get_reg(unsigned char reg)
93{
94 outb_p(reg, W83697HF_EFIR);
95 return inb_p(W83697HF_EFDR);
96}
97
98static void
99w83697hf_set_reg(unsigned char reg, unsigned char data)
100{
101 outb_p(reg, W83697HF_EFIR);
102 outb_p(data, W83697HF_EFDR);
103}
104
105static void
106w83697hf_write_timeout(int timeout)
107{
108 w83697hf_set_reg(0xF4, timeout); /* Write Timeout counter to CRF4 */
109}
110
111static void
112w83697hf_select_wdt(void)
113{
114 w83697hf_unlock();
115 w83697hf_set_reg(0x07, 0x08); /* Switch to logic device 8 (GPIO2) */
116}
117
118static inline void
119w83697hf_deselect_wdt(void)
120{
121 w83697hf_lock();
122}
123
124static void
125w83697hf_init(void)
126{
127 unsigned char bbuf;
128
129 w83697hf_select_wdt();
130
131 bbuf = w83697hf_get_reg(0x29);
132 bbuf &= ~0x60;
133 bbuf |= 0x20;
134 w83697hf_set_reg(0x29, bbuf); /* Set pin 119 to WDTO# mode (= CR29, WDT0) */
135
136 bbuf = w83697hf_get_reg(0xF3);
137 bbuf &= ~0x04;
138 w83697hf_set_reg(0xF3, bbuf); /* Count mode is seconds */
139
140 w83697hf_deselect_wdt();
141}
142
143static int
144wdt_ping(void)
145{
146 spin_lock(&io_lock);
147 w83697hf_select_wdt();
148
149 w83697hf_write_timeout(timeout);
150
151 w83697hf_deselect_wdt();
152 spin_unlock(&io_lock);
153 return 0;
154}
155
156static int
157wdt_enable(void)
158{
159 spin_lock(&io_lock);
160 w83697hf_select_wdt();
161
162 w83697hf_write_timeout(timeout);
163 w83697hf_set_reg(0x30, 1); /* Enable timer */
164
165 w83697hf_deselect_wdt();
166 spin_unlock(&io_lock);
167 return 0;
168}
169
170static int
171wdt_disable(void)
172{
173 spin_lock(&io_lock);
174 w83697hf_select_wdt();
175
176 w83697hf_set_reg(0x30, 0); /* Disable timer */
177 w83697hf_write_timeout(0);
178
179 w83697hf_deselect_wdt();
180 spin_unlock(&io_lock);
181 return 0;
182}
183
184static int
185wdt_set_heartbeat(int t)
186{
187 if ((t < 1) || (t > 255))
188 return -EINVAL;
189
190 timeout = t;
191 return 0;
192}
193
194static ssize_t
195wdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
196{
197 if (count) {
198 if (!nowayout) {
199 size_t i;
200
201 expect_close = 0;
202
203 for (i = 0; i != count; i++) {
204 char c;
205 if (get_user(c, buf+i))
206 return -EFAULT;
207 if (c == 'V')
208 expect_close = 42;
209 }
210 }
211 wdt_ping();
212 }
213 return count;
214}
215
216static int
217wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
218 unsigned long arg)
219{
220 void __user *argp = (void __user *)arg;
221 int __user *p = argp;
222 int new_timeout;
223 static struct watchdog_info ident = {
224 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE,
225 .firmware_version = 1,
226 .identity = "W83697HF WDT",
227 };
228
229 switch (cmd) {
230 case WDIOC_GETSUPPORT:
231 if (copy_to_user(argp, &ident, sizeof(ident)))
232 return -EFAULT;
233 break;
234
235 case WDIOC_GETSTATUS:
236 case WDIOC_GETBOOTSTATUS:
237 return put_user(0, p);
238
239 case WDIOC_KEEPALIVE:
240 wdt_ping();
241 break;
242
243 case WDIOC_SETTIMEOUT:
244 if (get_user(new_timeout, p))
245 return -EFAULT;
246 if (wdt_set_heartbeat(new_timeout))
247 return -EINVAL;
248 wdt_ping();
249 /* Fall */
250
251 case WDIOC_GETTIMEOUT:
252 return put_user(timeout, p);
253
254 case WDIOC_SETOPTIONS:
255 {
256 int options, retval = -EINVAL;
257
258 if (get_user(options, p))
259 return -EFAULT;
260
261 if (options & WDIOS_DISABLECARD) {
262 wdt_disable();
263 retval = 0;
264 }
265
266 if (options & WDIOS_ENABLECARD) {
267 wdt_enable();
268 retval = 0;
269 }
270
271 return retval;
272 }
273
274 default:
275 return -ENOTTY;
276 }
277 return 0;
278}
279
280static int
281wdt_open(struct inode *inode, struct file *file)
282{
283 if (test_and_set_bit(0, &wdt_is_open))
284 return -EBUSY;
285 /*
286 * Activate
287 */
288
289 wdt_enable();
290 return nonseekable_open(inode, file);
291}
292
293static int
294wdt_close(struct inode *inode, struct file *file)
295{
296 if (expect_close == 42) {
297 wdt_disable();
298 } else {
299 printk (KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
300 wdt_ping();
301 }
302 expect_close = 0;
303 clear_bit(0, &wdt_is_open);
304 return 0;
305}
306
307/*
308 * Notifier for system down
309 */
310
311static int
312wdt_notify_sys(struct notifier_block *this, unsigned long code,
313 void *unused)
314{
315 if (code == SYS_DOWN || code == SYS_HALT) {
316 /* Turn the WDT off */
317 wdt_disable();
318 }
319 return NOTIFY_DONE;
320}
321
322/*
323 * Kernel Interfaces
324 */
325
326static struct file_operations wdt_fops = {
327 .owner = THIS_MODULE,
328 .llseek = no_llseek,
329 .write = wdt_write,
330 .ioctl = wdt_ioctl,
331 .open = wdt_open,
332 .release = wdt_close,
333};
334
335static struct miscdevice wdt_miscdev = {
336 .minor = WATCHDOG_MINOR,
337 .name = "watchdog",
338 .fops = &wdt_fops,
339};
340
341/*
342 * The WDT needs to learn about soft shutdowns in order to
343 * turn the timebomb registers off.
344 */
345
346static struct notifier_block wdt_notifier = {
347 .notifier_call = wdt_notify_sys,
348};
349
350static int
351w83697hf_check_wdt(void)
352{
353 if (!request_region(wdt_io, 2, WATCHDOG_NAME)) {
354 printk (KERN_ERR PFX "I/O address 0x%x already in use\n", wdt_io);
355 return -EIO;
356 }
357
358 printk (KERN_DEBUG PFX "Looking for watchdog at address 0x%x\n", wdt_io);
359 w83697hf_unlock();
360 if (w83697hf_get_reg(0x20) == 0x60) {
361 printk (KERN_INFO PFX "watchdog found at address 0x%x\n", wdt_io);
362 w83697hf_lock();
363 return 0;
364 }
365 w83697hf_lock(); /* Reprotect in case it was a compatible device */
366
367 printk (KERN_INFO PFX "watchdog not found at address 0x%x\n", wdt_io);
368 release_region(wdt_io, 2);
369 return -EIO;
370}
371
372static int w83697hf_ioports[] = { 0x2e, 0x4e, 0x00 };
373
374static int __init
375wdt_init(void)
376{
377 int ret, i, found = 0;
378
379 spin_lock_init(&io_lock);
380
381 printk (KERN_INFO PFX "WDT driver for W83697HF/HG initializing\n");
382
383 if (wdt_io == 0) {
384 /* we will autodetect the W83697HF/HG watchdog */
385 for (i = 0; ((!found) && (w83697hf_ioports[i] != 0)); i++) {
386 wdt_io = w83697hf_ioports[i];
387 if (!w83697hf_check_wdt())
388 found++;
389 }
390 } else {
391 if (!w83697hf_check_wdt())
392 found++;
393 }
394
395 if (!found) {
396 printk (KERN_ERR PFX "No W83697HF/HG could be found\n");
397 ret = -EIO;
398 goto out;
399 }
400
401 w83697hf_init();
402 wdt_disable(); /* Disable watchdog until first use */
403
404 if (wdt_set_heartbeat(timeout)) {
405 wdt_set_heartbeat(WATCHDOG_TIMEOUT);
406 printk (KERN_INFO PFX "timeout value must be 1<=timeout<=255, using %d\n",
407 WATCHDOG_TIMEOUT);
408 }
409
410 ret = register_reboot_notifier(&wdt_notifier);
411 if (ret != 0) {
412 printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
413 ret);
414 goto unreg_regions;
415 }
416
417 ret = misc_register(&wdt_miscdev);
418 if (ret != 0) {
419 printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
420 WATCHDOG_MINOR, ret);
421 goto unreg_reboot;
422 }
423
424 printk (KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d)\n",
425 timeout, nowayout);
426
427out:
428 return ret;
429unreg_reboot:
430 unregister_reboot_notifier(&wdt_notifier);
431unreg_regions:
432 release_region(wdt_io, 2);
433 goto out;
434}
435
436static void __exit
437wdt_exit(void)
438{
439 misc_deregister(&wdt_miscdev);
440 unregister_reboot_notifier(&wdt_notifier);
441 release_region(wdt_io, 2);
442}
443
444module_init(wdt_init);
445module_exit(wdt_exit);
446
447MODULE_LICENSE("GPL");
448MODULE_AUTHOR("Marcus Junker <junker@anduras.de>, Samuel Tardieu <sam@rfc1149.net>");
449MODULE_DESCRIPTION("w83697hf/hg WDT driver");
450MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/char/watchdog/w83877f_wdt.c b/drivers/char/watchdog/w83877f_wdt.c
index ccf6c0915945..b0e5f84d6baf 100644
--- a/drivers/char/watchdog/w83877f_wdt.c
+++ b/drivers/char/watchdog/w83877f_wdt.c
@@ -252,7 +252,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
252 switch(cmd) 252 switch(cmd)
253 { 253 {
254 default: 254 default:
255 return -ENOIOCTLCMD; 255 return -ENOTTY;
256 case WDIOC_GETSUPPORT: 256 case WDIOC_GETSUPPORT:
257 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0; 257 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0;
258 case WDIOC_GETSTATUS: 258 case WDIOC_GETSTATUS:
diff --git a/drivers/char/watchdog/w83977f_wdt.c b/drivers/char/watchdog/w83977f_wdt.c
index 98f4e17db70a..2c8d5d8bd4e8 100644
--- a/drivers/char/watchdog/w83977f_wdt.c
+++ b/drivers/char/watchdog/w83977f_wdt.c
@@ -393,7 +393,7 @@ static int wdt_ioctl(struct inode *inode, struct file *file,
393 switch(cmd) 393 switch(cmd)
394 { 394 {
395 default: 395 default:
396 return -ENOIOCTLCMD; 396 return -ENOTTY;
397 397
398 case WDIOC_GETSUPPORT: 398 case WDIOC_GETSUPPORT:
399 return copy_to_user(uarg.ident, &ident, sizeof(ident)) ? -EFAULT : 0; 399 return copy_to_user(uarg.ident, &ident, sizeof(ident)) ? -EFAULT : 0;
diff --git a/drivers/char/watchdog/wafer5823wdt.c b/drivers/char/watchdog/wafer5823wdt.c
index 2bb6a9d6ad28..163e028ef9ed 100644
--- a/drivers/char/watchdog/wafer5823wdt.c
+++ b/drivers/char/watchdog/wafer5823wdt.c
@@ -174,7 +174,7 @@ static int wafwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd
174 } 174 }
175 175
176 default: 176 default:
177 return -ENOIOCTLCMD; 177 return -ENOTTY;
178 } 178 }
179 return 0; 179 return 0;
180} 180}
diff --git a/drivers/char/watchdog/wdrtas.c b/drivers/char/watchdog/wdrtas.c
index 5c38cdf41731..1d64e277567d 100644
--- a/drivers/char/watchdog/wdrtas.c
+++ b/drivers/char/watchdog/wdrtas.c
@@ -385,7 +385,7 @@ wdrtas_ioctl(struct inode *inode, struct file *file,
385 return put_user(wdrtas_interval, argp); 385 return put_user(wdrtas_interval, argp);
386 386
387 default: 387 default:
388 return -ENOIOCTLCMD; 388 return -ENOTTY;
389 } 389 }
390} 390}
391 391
diff --git a/drivers/char/watchdog/wdt.c b/drivers/char/watchdog/wdt.c
index 70be81e39a61..517fbd8643f8 100644
--- a/drivers/char/watchdog/wdt.c
+++ b/drivers/char/watchdog/wdt.c
@@ -225,14 +225,13 @@ static int wdt_get_temperature(int *temperature)
225 * wdt_interrupt: 225 * wdt_interrupt:
226 * @irq: Interrupt number 226 * @irq: Interrupt number
227 * @dev_id: Unused as we don't allow multiple devices. 227 * @dev_id: Unused as we don't allow multiple devices.
228 * @regs: Unused.
229 * 228 *
230 * Handle an interrupt from the board. These are raised when the status 229 * Handle an interrupt from the board. These are raised when the status
231 * map changes in what the board considers an interesting way. That means 230 * map changes in what the board considers an interesting way. That means
232 * a failure condition occurring. 231 * a failure condition occurring.
233 */ 232 */
234 233
235static irqreturn_t wdt_interrupt(int irq, void *dev_id, struct pt_regs *regs) 234static irqreturn_t wdt_interrupt(int irq, void *dev_id)
236{ 235{
237 /* 236 /*
238 * Read the status register see what is up and 237 * Read the status register see what is up and
@@ -341,7 +340,7 @@ static int wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
341 switch(cmd) 340 switch(cmd)
342 { 341 {
343 default: 342 default:
344 return -ENOIOCTLCMD; 343 return -ENOTTY;
345 case WDIOC_GETSUPPORT: 344 case WDIOC_GETSUPPORT:
346 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0; 345 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0;
347 346
diff --git a/drivers/char/watchdog/wdt285.c b/drivers/char/watchdog/wdt285.c
index 6555fb844f23..e4cf661dc890 100644
--- a/drivers/char/watchdog/wdt285.c
+++ b/drivers/char/watchdog/wdt285.c
@@ -46,7 +46,7 @@ static unsigned long timer_alive;
46/* 46/*
47 * If the timer expires.. 47 * If the timer expires..
48 */ 48 */
49static void watchdog_fire(int irq, void *dev_id, struct pt_regs *regs) 49static void watchdog_fire(int irq, void *dev_id)
50{ 50{
51 printk(KERN_CRIT "Watchdog: Would Reboot.\n"); 51 printk(KERN_CRIT "Watchdog: Would Reboot.\n");
52 *CSR_TIMER4_CNTL = 0; 52 *CSR_TIMER4_CNTL = 0;
@@ -137,7 +137,7 @@ watchdog_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
137 unsigned long arg) 137 unsigned long arg)
138{ 138{
139 unsigned int new_margin; 139 unsigned int new_margin;
140 int ret = -ENOIOCTLCMD; 140 int ret = -ENOTTY;
141 141
142 switch(cmd) { 142 switch(cmd) {
143 case WDIOC_GETSUPPORT: 143 case WDIOC_GETSUPPORT:
diff --git a/drivers/char/watchdog/wdt977.c b/drivers/char/watchdog/wdt977.c
index a0935bc775f8..6253041b235b 100644
--- a/drivers/char/watchdog/wdt977.c
+++ b/drivers/char/watchdog/wdt977.c
@@ -361,7 +361,7 @@ static int wdt977_ioctl(struct inode *inode, struct file *file,
361 switch(cmd) 361 switch(cmd)
362 { 362 {
363 default: 363 default:
364 return -ENOIOCTLCMD; 364 return -ENOTTY;
365 365
366 case WDIOC_GETSUPPORT: 366 case WDIOC_GETSUPPORT:
367 return copy_to_user(uarg.ident, &ident, 367 return copy_to_user(uarg.ident, &ident,
diff --git a/drivers/char/watchdog/wdt_pci.c b/drivers/char/watchdog/wdt_pci.c
index 5918ca2c9c35..ce1261c5cbce 100644
--- a/drivers/char/watchdog/wdt_pci.c
+++ b/drivers/char/watchdog/wdt_pci.c
@@ -270,14 +270,13 @@ static int wdtpci_get_temperature(int *temperature)
270 * wdtpci_interrupt: 270 * wdtpci_interrupt:
271 * @irq: Interrupt number 271 * @irq: Interrupt number
272 * @dev_id: Unused as we don't allow multiple devices. 272 * @dev_id: Unused as we don't allow multiple devices.
273 * @regs: Unused.
274 * 273 *
275 * Handle an interrupt from the board. These are raised when the status 274 * Handle an interrupt from the board. These are raised when the status
276 * map changes in what the board considers an interesting way. That means 275 * map changes in what the board considers an interesting way. That means
277 * a failure condition occurring. 276 * a failure condition occurring.
278 */ 277 */
279 278
280static irqreturn_t wdtpci_interrupt(int irq, void *dev_id, struct pt_regs *regs) 279static irqreturn_t wdtpci_interrupt(int irq, void *dev_id)
281{ 280{
282 /* 281 /*
283 * Read the status register see what is up and 282 * Read the status register see what is up and
@@ -386,7 +385,7 @@ static int wdtpci_ioctl(struct inode *inode, struct file *file, unsigned int cmd
386 switch(cmd) 385 switch(cmd)
387 { 386 {
388 default: 387 default:
389 return -ENOIOCTLCMD; 388 return -ENOTTY;
390 case WDIOC_GETSUPPORT: 389 case WDIOC_GETSUPPORT:
391 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0; 390 return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0;
392 391