forked from Minki/linux
c5bf68fe0c
Using scripts/coccinelle/api/stream_open.cocci added in10dce8af34
("fs: stream_open - opener for stream-like files so that read and write can run simultaneously without deadlock"), search and convert to stream_open all in-kernel nonseekable_open users for which read and write actually do not depend on ppos and where there is no other methods in file_operations which assume @offset access. I've verified each generated change manually - that it is correct to convert - and each other nonseekable_open instance left - that it is either not correct to convert there, or that it is not converted due to current stream_open.cocci limitations. The script also does not convert files that should be valid to convert, but that currently have .llseek = noop_llseek or generic_file_llseek for unknown reason despite file being opened with nonseekable_open (e.g. drivers/input/mousedev.c) Among cases converted 14 were potentially vulnerable to read vs write deadlock (see details in10dce8af34
): drivers/char/pcmcia/cm4000_cs.c:1685:7-23: ERROR: cm4000_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix. drivers/gnss/core.c:45:1-17: ERROR: gnss_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix. drivers/hid/uhid.c:635:1-17: ERROR: uhid_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix. drivers/infiniband/core/user_mad.c:988:1-17: ERROR: umad_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix. drivers/input/evdev.c:527:1-17: ERROR: evdev_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix. drivers/input/misc/uinput.c:401:1-17: ERROR: uinput_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix. drivers/isdn/capi/capi.c:963:8-24: ERROR: capi_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix. drivers/leds/uleds.c:77:1-17: ERROR: uleds_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix. drivers/media/rc/lirc_dev.c:198:1-17: ERROR: lirc_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix. drivers/s390/char/fs3270.c:488:1-17: ERROR: fs3270_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix. drivers/usb/misc/ldusb.c:310:1-17: ERROR: ld_usb_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix. drivers/xen/evtchn.c:667:8-24: ERROR: evtchn_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix. net/batman-adv/icmp_socket.c:80:1-17: ERROR: batadv_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix. net/rfkill/core.c:1146:8-24: ERROR: rfkill_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix. and the rest were just safe to convert to stream_open because their read and write do not use ppos at all and corresponding file_operations do not have methods that assume @offset file access(*): arch/powerpc/platforms/52xx/mpc52xx_gpt.c:631:8-24: WARNING: mpc52xx_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. arch/powerpc/platforms/cell/spufs/file.c:591:8-24: WARNING: spufs_ibox_fops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. arch/powerpc/platforms/cell/spufs/file.c:591:8-24: WARNING: spufs_ibox_stat_fops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. arch/powerpc/platforms/cell/spufs/file.c:591:8-24: WARNING: spufs_mbox_fops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. arch/powerpc/platforms/cell/spufs/file.c:591:8-24: WARNING: spufs_mbox_stat_fops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. arch/powerpc/platforms/cell/spufs/file.c:591:8-24: WARNING: spufs_wbox_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. arch/powerpc/platforms/cell/spufs/file.c:591:8-24: WARNING: spufs_wbox_stat_fops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. arch/um/drivers/harddog_kern.c:88:8-24: WARNING: harddog_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. arch/x86/kernel/cpu/microcode/core.c:430:33-49: WARNING: microcode_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/char/ds1620.c:215:8-24: WARNING: ds1620_fops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/char/dtlk.c:301:1-17: WARNING: dtlk_fops: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open. drivers/char/ipmi/ipmi_watchdog.c:840:9-25: WARNING: ipmi_wdog_fops: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open. drivers/char/pcmcia/scr24x_cs.c:95:8-24: WARNING: scr24x_fops: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open. drivers/char/tb0219.c:246:9-25: WARNING: tb0219_fops: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open. drivers/firewire/nosy.c:306:8-24: WARNING: nosy_ops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/hwmon/fschmd.c:840:8-24: WARNING: watchdog_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/hwmon/w83793.c:1344:8-24: WARNING: watchdog_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/infiniband/core/ucma.c:1747:8-24: WARNING: ucma_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/infiniband/core/ucm.c:1178:8-24: WARNING: ucm_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/infiniband/core/uverbs_main.c:1086:8-24: WARNING: uverbs_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/input/joydev.c:282:1-17: WARNING: joydev_fops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/pci/switch/switchtec.c:393:1-17: WARNING: switchtec_fops: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open. drivers/platform/chrome/cros_ec_debugfs.c:135:8-24: WARNING: cros_ec_console_log_fops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/rtc/rtc-ds1374.c:470:9-25: WARNING: ds1374_wdt_fops: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open. drivers/rtc/rtc-m41t80.c:805:9-25: WARNING: wdt_fops: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open. drivers/s390/char/tape_char.c:293:2-18: WARNING: tape_fops: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open. drivers/s390/char/zcore.c:194:8-24: WARNING: zcore_reipl_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/s390/crypto/zcrypt_api.c:528:8-24: WARNING: zcrypt_fops: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open. drivers/spi/spidev.c:594:1-17: WARNING: spidev_fops: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open. drivers/staging/pi433/pi433_if.c:974:1-17: WARNING: pi433_fops: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/acquirewdt.c:203:8-24: WARNING: acq_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/advantechwdt.c:202:8-24: WARNING: advwdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/alim1535_wdt.c:252:8-24: WARNING: ali_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/alim7101_wdt.c:217:8-24: WARNING: wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/ar7_wdt.c:166:8-24: WARNING: ar7_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/at91rm9200_wdt.c:113:8-24: WARNING: at91wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/ath79_wdt.c:135:8-24: WARNING: ath79_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/bcm63xx_wdt.c:119:8-24: WARNING: bcm63xx_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/cpu5wdt.c:143:8-24: WARNING: cpu5wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/cpwd.c:397:8-24: WARNING: cpwd_fops: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/eurotechwdt.c:319:8-24: WARNING: eurwdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/f71808e_wdt.c:528:8-24: WARNING: watchdog_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/gef_wdt.c:232:8-24: WARNING: gef_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/geodewdt.c:95:8-24: WARNING: geodewdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/ib700wdt.c:241:8-24: WARNING: ibwdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/ibmasr.c:326:8-24: WARNING: asr_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/indydog.c:80:8-24: WARNING: indydog_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/intel_scu_watchdog.c:307:8-24: WARNING: intel_scu_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/iop_wdt.c:104:8-24: WARNING: iop_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/it8712f_wdt.c:330:8-24: WARNING: it8712f_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/ixp4xx_wdt.c:68:8-24: WARNING: ixp4xx_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/ks8695_wdt.c:145:8-24: WARNING: ks8695wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/m54xx_wdt.c:88:8-24: WARNING: m54xx_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/machzwd.c:336:8-24: WARNING: zf_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/mixcomwd.c:153:8-24: WARNING: mixcomwd_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/mtx-1_wdt.c:121:8-24: WARNING: mtx1_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/mv64x60_wdt.c:136:8-24: WARNING: mv64x60_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/nuc900_wdt.c:134:8-24: WARNING: nuc900wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/nv_tco.c:164:8-24: WARNING: nv_tco_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/pc87413_wdt.c:289:8-24: WARNING: pc87413_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/pcwd.c:698:8-24: WARNING: pcwd_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/pcwd.c:737:8-24: WARNING: pcwd_temp_fops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/pcwd_pci.c:581:8-24: WARNING: pcipcwd_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/pcwd_pci.c:623:8-24: WARNING: pcipcwd_temp_fops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/pcwd_usb.c:488:8-24: WARNING: usb_pcwd_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/pcwd_usb.c:527:8-24: WARNING: usb_pcwd_temperature_fops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/pika_wdt.c:121:8-24: WARNING: pikawdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/pnx833x_wdt.c:119:8-24: WARNING: pnx833x_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/rc32434_wdt.c:153:8-24: WARNING: rc32434_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/rdc321x_wdt.c:145:8-24: WARNING: rdc321x_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/riowd.c:79:1-17: WARNING: riowd_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/sa1100_wdt.c:62:8-24: WARNING: sa1100dog_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/sbc60xxwdt.c:211:8-24: WARNING: wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/sbc7240_wdt.c:139:8-24: WARNING: wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/sbc8360.c:274:8-24: WARNING: sbc8360_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/sbc_epx_c3.c:81:8-24: WARNING: epx_c3_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/sbc_fitpc2_wdt.c:78:8-24: WARNING: fitpc2_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/sb_wdog.c:108:1-17: WARNING: sbwdog_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/sc1200wdt.c:181:8-24: WARNING: sc1200wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/sc520_wdt.c:261:8-24: WARNING: wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/sch311x_wdt.c:319:8-24: WARNING: sch311x_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/scx200_wdt.c:105:8-24: WARNING: scx200_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/smsc37b787_wdt.c:369:8-24: WARNING: wb_smsc_wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/w83877f_wdt.c:227:8-24: WARNING: wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/w83977f_wdt.c:301:8-24: WARNING: wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/wafer5823wdt.c:200:8-24: WARNING: wafwdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/watchdog_dev.c:828:8-24: WARNING: watchdog_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/wdrtas.c:379:8-24: WARNING: wdrtas_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/wdrtas.c:445:8-24: WARNING: wdrtas_temp_fops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/wdt285.c:104:1-17: WARNING: watchdog_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/wdt977.c:276:8-24: WARNING: wdt977_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/wdt.c:424:8-24: WARNING: wdt_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/wdt.c:484:8-24: WARNING: wdt_temp_fops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/wdt_pci.c:464:8-24: WARNING: wdtpci_fops: .write() has stream semantic; safe to change nonseekable_open -> stream_open. drivers/watchdog/wdt_pci.c:527:8-24: WARNING: wdtpci_temp_fops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. net/batman-adv/log.c:105:1-17: WARNING: batadv_log_fops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. sound/core/control.c:57:7-23: WARNING: snd_ctl_f_ops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. sound/core/rawmidi.c:385:7-23: WARNING: snd_rawmidi_f_ops: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open. sound/core/seq/seq_clientmgr.c:310:7-23: WARNING: snd_seq_f_ops: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open. sound/core/timer.c:1428:7-23: WARNING: snd_timer_f_ops: .read() has stream semantic; safe to change nonseekable_open -> stream_open. One can also recheck/review the patch via generating it with explanation comments included via $ make coccicheck MODE=patch COCCI=scripts/coccinelle/api/stream_open.cocci SPFLAGS="-D explain" (*) This second group also contains cases with read/write deadlocks that stream_open.cocci don't yet detect, but which are still valid to convert to stream_open since ppos is not used. For example drivers/pci/switch/switchtec.c calls wait_for_completion_interruptible() in its .read, but stream_open.cocci currently detects only "wait_event*" as blocking. Cc: Michael Kerrisk <mtk.manpages@gmail.com> Cc: Yongzhi Pan <panyongzhi@gmail.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: David Vrabel <david.vrabel@citrix.com> Cc: Juergen Gross <jgross@suse.com> Cc: Miklos Szeredi <miklos@szeredi.hu> Cc: Tejun Heo <tj@kernel.org> Cc: Kirill Tkhai <ktkhai@virtuozzo.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Christoph Hellwig <hch@lst.de> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Julia Lawall <Julia.Lawall@lip6.fr> Cc: Nikolaus Rath <Nikolaus@rath.org> Cc: Han-Wen Nienhuys <hanwen@google.com> Cc: Anatolij Gustschin <agust@denx.de> Cc: Jeff Dike <jdike@addtoit.com> Cc: Richard Weinberger <richard@nod.at> Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: "James R. Van Zandt" <jrv@vanzandt.mv.com> Cc: Corey Minyard <minyard@acm.org> Cc: Harald Welte <laforge@gnumonks.org> Acked-by: Lubomir Rintel <lkundrak@v3.sk> [scr24x_cs] Cc: Stefan Richter <stefanr@s5r6.in-berlin.de> Cc: Johan Hovold <johan@kernel.org> Cc: David Herrmann <dh.herrmann@googlemail.com> Cc: Jiri Kosina <jikos@kernel.org> Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com> Cc: Jean Delvare <jdelvare@suse.com> Acked-by: Guenter Roeck <linux@roeck-us.net> [watchdog/* hwmon/*] Cc: Rudolf Marek <r.marek@assembler.cz> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com> Cc: Karsten Keil <isdn@linux-pingi.de> Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com> Cc: Pavel Machek <pavel@ucw.cz> Cc: Mauro Carvalho Chehab <mchehab@kernel.org> Cc: Kurt Schwemmer <kurt.schwemmer@microsemi.com> Acked-by: Logan Gunthorpe <logang@deltatee.com> [drivers/pci/switch/switchtec] Acked-by: Bjorn Helgaas <bhelgaas@google.com> [drivers/pci/switch/switchtec] Cc: Benson Leung <bleung@chromium.org> Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com> [platform/chrome] Cc: Alessandro Zummo <a.zummo@towertech.it> Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> [rtc/*] Cc: Mark Brown <broonie@kernel.org> Cc: Wim Van Sebroeck <wim@linux-watchdog.org> Cc: Florian Fainelli <f.fainelli@gmail.com> Cc: bcm-kernel-feedback-list@broadcom.com Cc: Wan ZongShun <mcuos.com@gmail.com> Cc: Zwane Mwaikambo <zwanem@gmail.com> Cc: Marek Lindner <mareklindner@neomailbox.ch> Cc: Simon Wunderlich <sw@simonwunderlich.de> Cc: Antonio Quartulli <a@unstable.cc> Cc: "David S. Miller" <davem@davemloft.net> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: Jaroslav Kysela <perex@perex.cz> Cc: Takashi Iwai <tiwai@suse.com> Signed-off-by: Kirill Smelkov <kirr@nexedi.com>
823 lines
20 KiB
C
823 lines
20 KiB
C
/*
|
|
* Berkshire PCI-PC Watchdog Card Driver
|
|
*
|
|
* (c) Copyright 2003-2007 Wim Van Sebroeck <wim@iguana.be>.
|
|
*
|
|
* Based on source code of the following authors:
|
|
* Ken Hollis <kenji@bitgate.com>,
|
|
* Lindsay Harris <lindsay@bluegum.com>,
|
|
* Alan Cox <alan@lxorguk.ukuu.org.uk>,
|
|
* Matt Domsch <Matt_Domsch@dell.com>,
|
|
* Rob Radez <rob@osinvestor.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version
|
|
* 2 of the License, or (at your option) any later version.
|
|
*
|
|
* Neither Wim Van Sebroeck nor Iguana vzw. admit liability nor
|
|
* provide warranty for any of this software. This material is
|
|
* provided "AS-IS" and at no charge.
|
|
*/
|
|
|
|
/*
|
|
* A bells and whistles driver is available from:
|
|
* http://www.kernel.org/pub/linux/kernel/people/wim/pcwd/pcwd_pci/
|
|
*
|
|
* More info available at
|
|
* http://www.berkprod.com/ or http://www.pcwatchdog.com/
|
|
*/
|
|
|
|
/*
|
|
* Includes, defines, variables, module parameters, ...
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include <linux/module.h> /* For module specific items */
|
|
#include <linux/moduleparam.h> /* For new moduleparam's */
|
|
#include <linux/types.h> /* For standard types (like size_t) */
|
|
#include <linux/errno.h> /* For the -ENODEV/... values */
|
|
#include <linux/kernel.h> /* For printk/panic/... */
|
|
#include <linux/delay.h> /* For mdelay function */
|
|
#include <linux/miscdevice.h> /* For struct miscdevice */
|
|
#include <linux/watchdog.h> /* For the watchdog specific items */
|
|
#include <linux/notifier.h> /* For notifier support */
|
|
#include <linux/reboot.h> /* For reboot_notifier stuff */
|
|
#include <linux/init.h> /* For __init/__exit/... */
|
|
#include <linux/fs.h> /* For file operations */
|
|
#include <linux/pci.h> /* For pci functions */
|
|
#include <linux/ioport.h> /* For io-port access */
|
|
#include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
|
|
#include <linux/uaccess.h> /* For copy_to_user/put_user/... */
|
|
#include <linux/io.h> /* For inb/outb/... */
|
|
|
|
/* Module and version information */
|
|
#define WATCHDOG_VERSION "1.03"
|
|
#define WATCHDOG_DRIVER_NAME "PCI-PC Watchdog"
|
|
#define WATCHDOG_NAME "pcwd_pci"
|
|
#define DRIVER_VERSION WATCHDOG_DRIVER_NAME " driver, v" WATCHDOG_VERSION
|
|
|
|
/* Stuff for the PCI ID's */
|
|
#ifndef PCI_VENDOR_ID_QUICKLOGIC
|
|
#define PCI_VENDOR_ID_QUICKLOGIC 0x11e3
|
|
#endif
|
|
|
|
#ifndef PCI_DEVICE_ID_WATCHDOG_PCIPCWD
|
|
#define PCI_DEVICE_ID_WATCHDOG_PCIPCWD 0x5030
|
|
#endif
|
|
|
|
/*
|
|
* These are the defines that describe the control status bits for the
|
|
* PCI-PC Watchdog card.
|
|
*/
|
|
/* Port 1 : Control Status #1 */
|
|
#define WD_PCI_WTRP 0x01 /* Watchdog Trip status */
|
|
#define WD_PCI_HRBT 0x02 /* Watchdog Heartbeat */
|
|
#define WD_PCI_TTRP 0x04 /* Temperature Trip status */
|
|
#define WD_PCI_RL2A 0x08 /* Relay 2 Active */
|
|
#define WD_PCI_RL1A 0x10 /* Relay 1 Active */
|
|
#define WD_PCI_R2DS 0x40 /* Relay 2 Disable Temperature-trip /
|
|
reset */
|
|
#define WD_PCI_RLY2 0x80 /* Activate Relay 2 on the board */
|
|
/* Port 2 : Control Status #2 */
|
|
#define WD_PCI_WDIS 0x10 /* Watchdog Disable */
|
|
#define WD_PCI_ENTP 0x20 /* Enable Temperature Trip Reset */
|
|
#define WD_PCI_WRSP 0x40 /* Watchdog wrote response */
|
|
#define WD_PCI_PCMD 0x80 /* PC has sent command */
|
|
|
|
/* according to documentation max. time to process a command for the pci
|
|
* watchdog card is 100 ms, so we give it 150 ms to do it's job */
|
|
#define PCI_COMMAND_TIMEOUT 150
|
|
|
|
/* Watchdog's internal commands */
|
|
#define CMD_GET_STATUS 0x04
|
|
#define CMD_GET_FIRMWARE_VERSION 0x08
|
|
#define CMD_READ_WATCHDOG_TIMEOUT 0x18
|
|
#define CMD_WRITE_WATCHDOG_TIMEOUT 0x19
|
|
#define CMD_GET_CLEAR_RESET_COUNT 0x84
|
|
|
|
/* Watchdog's Dip Switch heartbeat values */
|
|
static const int heartbeat_tbl[] = {
|
|
5, /* OFF-OFF-OFF = 5 Sec */
|
|
10, /* OFF-OFF-ON = 10 Sec */
|
|
30, /* OFF-ON-OFF = 30 Sec */
|
|
60, /* OFF-ON-ON = 1 Min */
|
|
300, /* ON-OFF-OFF = 5 Min */
|
|
600, /* ON-OFF-ON = 10 Min */
|
|
1800, /* ON-ON-OFF = 30 Min */
|
|
3600, /* ON-ON-ON = 1 hour */
|
|
};
|
|
|
|
/* We can only use 1 card due to the /dev/watchdog restriction */
|
|
static int cards_found;
|
|
|
|
/* internal variables */
|
|
static int temp_panic;
|
|
static unsigned long is_active;
|
|
static char expect_release;
|
|
/* this is private data for each PCI-PC watchdog card */
|
|
static struct {
|
|
/* Wether or not the card has a temperature device */
|
|
int supports_temp;
|
|
/* The card's boot status */
|
|
int boot_status;
|
|
/* The cards I/O address */
|
|
unsigned long io_addr;
|
|
/* the lock for io operations */
|
|
spinlock_t io_lock;
|
|
/* the PCI-device */
|
|
struct pci_dev *pdev;
|
|
} pcipcwd_private;
|
|
|
|
/* module parameters */
|
|
#define QUIET 0 /* Default */
|
|
#define VERBOSE 1 /* Verbose */
|
|
#define DEBUG 2 /* print fancy stuff too */
|
|
static int debug = QUIET;
|
|
module_param(debug, int, 0);
|
|
MODULE_PARM_DESC(debug, "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)");
|
|
|
|
#define WATCHDOG_HEARTBEAT 0 /* default heartbeat =
|
|
delay-time from dip-switches */
|
|
static int heartbeat = WATCHDOG_HEARTBEAT;
|
|
module_param(heartbeat, int, 0);
|
|
MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. "
|
|
"(0<heartbeat<65536 or 0=delay-time from dip-switches, default="
|
|
__MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
|
|
|
|
static bool nowayout = WATCHDOG_NOWAYOUT;
|
|
module_param(nowayout, bool, 0);
|
|
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
|
|
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
|
|
|
|
/*
|
|
* Internal functions
|
|
*/
|
|
|
|
static int send_command(int cmd, int *msb, int *lsb)
|
|
{
|
|
int got_response, count;
|
|
|
|
if (debug >= DEBUG)
|
|
pr_debug("sending following data cmd=0x%02x msb=0x%02x lsb=0x%02x\n",
|
|
cmd, *msb, *lsb);
|
|
|
|
spin_lock(&pcipcwd_private.io_lock);
|
|
/* If a command requires data it should be written first.
|
|
* Data for commands with 8 bits of data should be written to port 4.
|
|
* Commands with 16 bits of data, should be written as LSB to port 4
|
|
* and MSB to port 5.
|
|
* After the required data has been written then write the command to
|
|
* port 6. */
|
|
outb_p(*lsb, pcipcwd_private.io_addr + 4);
|
|
outb_p(*msb, pcipcwd_private.io_addr + 5);
|
|
outb_p(cmd, pcipcwd_private.io_addr + 6);
|
|
|
|
/* wait till the pci card processed the command, signaled by
|
|
* the WRSP bit in port 2 and give it a max. timeout of
|
|
* PCI_COMMAND_TIMEOUT to process */
|
|
got_response = inb_p(pcipcwd_private.io_addr + 2) & WD_PCI_WRSP;
|
|
for (count = 0; (count < PCI_COMMAND_TIMEOUT) && (!got_response);
|
|
count++) {
|
|
mdelay(1);
|
|
got_response = inb_p(pcipcwd_private.io_addr + 2) & WD_PCI_WRSP;
|
|
}
|
|
|
|
if (debug >= DEBUG) {
|
|
if (got_response) {
|
|
pr_debug("time to process command was: %d ms\n",
|
|
count);
|
|
} else {
|
|
pr_debug("card did not respond on command!\n");
|
|
}
|
|
}
|
|
|
|
if (got_response) {
|
|
/* read back response */
|
|
*lsb = inb_p(pcipcwd_private.io_addr + 4);
|
|
*msb = inb_p(pcipcwd_private.io_addr + 5);
|
|
|
|
/* clear WRSP bit */
|
|
inb_p(pcipcwd_private.io_addr + 6);
|
|
|
|
if (debug >= DEBUG)
|
|
pr_debug("received following data for cmd=0x%02x: msb=0x%02x lsb=0x%02x\n",
|
|
cmd, *msb, *lsb);
|
|
}
|
|
|
|
spin_unlock(&pcipcwd_private.io_lock);
|
|
|
|
return got_response;
|
|
}
|
|
|
|
static inline void pcipcwd_check_temperature_support(void)
|
|
{
|
|
if (inb_p(pcipcwd_private.io_addr) != 0xF0)
|
|
pcipcwd_private.supports_temp = 1;
|
|
}
|
|
|
|
static int pcipcwd_get_option_switches(void)
|
|
{
|
|
int option_switches;
|
|
|
|
option_switches = inb_p(pcipcwd_private.io_addr + 3);
|
|
return option_switches;
|
|
}
|
|
|
|
static void pcipcwd_show_card_info(void)
|
|
{
|
|
int got_fw_rev, fw_rev_major, fw_rev_minor;
|
|
char fw_ver_str[20]; /* The cards firmware version */
|
|
int option_switches;
|
|
|
|
got_fw_rev = send_command(CMD_GET_FIRMWARE_VERSION, &fw_rev_major,
|
|
&fw_rev_minor);
|
|
if (got_fw_rev)
|
|
sprintf(fw_ver_str, "%u.%02u", fw_rev_major, fw_rev_minor);
|
|
else
|
|
sprintf(fw_ver_str, "<card no answer>");
|
|
|
|
/* Get switch settings */
|
|
option_switches = pcipcwd_get_option_switches();
|
|
|
|
pr_info("Found card at port 0x%04x (Firmware: %s) %s temp option\n",
|
|
(int) pcipcwd_private.io_addr, fw_ver_str,
|
|
(pcipcwd_private.supports_temp ? "with" : "without"));
|
|
|
|
pr_info("Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n",
|
|
option_switches,
|
|
((option_switches & 0x10) ? "ON" : "OFF"),
|
|
((option_switches & 0x08) ? "ON" : "OFF"));
|
|
|
|
if (pcipcwd_private.boot_status & WDIOF_CARDRESET)
|
|
pr_info("Previous reset was caused by the Watchdog card\n");
|
|
|
|
if (pcipcwd_private.boot_status & WDIOF_OVERHEAT)
|
|
pr_info("Card sensed a CPU Overheat\n");
|
|
|
|
if (pcipcwd_private.boot_status == 0)
|
|
pr_info("No previous trip detected - Cold boot or reset\n");
|
|
}
|
|
|
|
static int pcipcwd_start(void)
|
|
{
|
|
int stat_reg;
|
|
|
|
spin_lock(&pcipcwd_private.io_lock);
|
|
outb_p(0x00, pcipcwd_private.io_addr + 3);
|
|
udelay(1000);
|
|
|
|
stat_reg = inb_p(pcipcwd_private.io_addr + 2);
|
|
spin_unlock(&pcipcwd_private.io_lock);
|
|
|
|
if (stat_reg & WD_PCI_WDIS) {
|
|
pr_err("Card timer not enabled\n");
|
|
return -1;
|
|
}
|
|
|
|
if (debug >= VERBOSE)
|
|
pr_debug("Watchdog started\n");
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int pcipcwd_stop(void)
|
|
{
|
|
int stat_reg;
|
|
|
|
spin_lock(&pcipcwd_private.io_lock);
|
|
outb_p(0xA5, pcipcwd_private.io_addr + 3);
|
|
udelay(1000);
|
|
|
|
outb_p(0xA5, pcipcwd_private.io_addr + 3);
|
|
udelay(1000);
|
|
|
|
stat_reg = inb_p(pcipcwd_private.io_addr + 2);
|
|
spin_unlock(&pcipcwd_private.io_lock);
|
|
|
|
if (!(stat_reg & WD_PCI_WDIS)) {
|
|
pr_err("Card did not acknowledge disable attempt\n");
|
|
return -1;
|
|
}
|
|
|
|
if (debug >= VERBOSE)
|
|
pr_debug("Watchdog stopped\n");
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int pcipcwd_keepalive(void)
|
|
{
|
|
/* Re-trigger watchdog by writing to port 0 */
|
|
spin_lock(&pcipcwd_private.io_lock);
|
|
outb_p(0x42, pcipcwd_private.io_addr); /* send out any data */
|
|
spin_unlock(&pcipcwd_private.io_lock);
|
|
|
|
if (debug >= DEBUG)
|
|
pr_debug("Watchdog keepalive signal send\n");
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int pcipcwd_set_heartbeat(int t)
|
|
{
|
|
int t_msb = t / 256;
|
|
int t_lsb = t % 256;
|
|
|
|
if ((t < 0x0001) || (t > 0xFFFF))
|
|
return -EINVAL;
|
|
|
|
/* Write new heartbeat to watchdog */
|
|
send_command(CMD_WRITE_WATCHDOG_TIMEOUT, &t_msb, &t_lsb);
|
|
|
|
heartbeat = t;
|
|
if (debug >= VERBOSE)
|
|
pr_debug("New heartbeat: %d\n", heartbeat);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int pcipcwd_get_status(int *status)
|
|
{
|
|
int control_status;
|
|
|
|
*status = 0;
|
|
control_status = inb_p(pcipcwd_private.io_addr + 1);
|
|
if (control_status & WD_PCI_WTRP)
|
|
*status |= WDIOF_CARDRESET;
|
|
if (control_status & WD_PCI_TTRP) {
|
|
*status |= WDIOF_OVERHEAT;
|
|
if (temp_panic)
|
|
panic(KBUILD_MODNAME ": Temperature overheat trip!\n");
|
|
}
|
|
|
|
if (debug >= DEBUG)
|
|
pr_debug("Control Status #1: 0x%02x\n", control_status);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int pcipcwd_clear_status(void)
|
|
{
|
|
int control_status;
|
|
int msb;
|
|
int reset_counter;
|
|
|
|
if (debug >= VERBOSE)
|
|
pr_info("clearing watchdog trip status & LED\n");
|
|
|
|
control_status = inb_p(pcipcwd_private.io_addr + 1);
|
|
|
|
if (debug >= DEBUG) {
|
|
pr_debug("status was: 0x%02x\n", control_status);
|
|
pr_debug("sending: 0x%02x\n",
|
|
(control_status & WD_PCI_R2DS) | WD_PCI_WTRP);
|
|
}
|
|
|
|
/* clear trip status & LED and keep mode of relay 2 */
|
|
outb_p((control_status & WD_PCI_R2DS) | WD_PCI_WTRP,
|
|
pcipcwd_private.io_addr + 1);
|
|
|
|
/* clear reset counter */
|
|
msb = 0;
|
|
reset_counter = 0xff;
|
|
send_command(CMD_GET_CLEAR_RESET_COUNT, &msb, &reset_counter);
|
|
|
|
if (debug >= DEBUG) {
|
|
pr_debug("reset count was: 0x%02x\n", reset_counter);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int pcipcwd_get_temperature(int *temperature)
|
|
{
|
|
*temperature = 0;
|
|
if (!pcipcwd_private.supports_temp)
|
|
return -ENODEV;
|
|
|
|
spin_lock(&pcipcwd_private.io_lock);
|
|
*temperature = inb_p(pcipcwd_private.io_addr);
|
|
spin_unlock(&pcipcwd_private.io_lock);
|
|
|
|
/*
|
|
* Convert celsius to fahrenheit, since this was
|
|
* the decided 'standard' for this return value.
|
|
*/
|
|
*temperature = (*temperature * 9 / 5) + 32;
|
|
|
|
if (debug >= DEBUG) {
|
|
pr_debug("temperature is: %d F\n", *temperature);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int pcipcwd_get_timeleft(int *time_left)
|
|
{
|
|
int msb;
|
|
int lsb;
|
|
|
|
/* Read the time that's left before rebooting */
|
|
/* Note: if the board is not yet armed then we will read 0xFFFF */
|
|
send_command(CMD_READ_WATCHDOG_TIMEOUT, &msb, &lsb);
|
|
|
|
*time_left = (msb << 8) + lsb;
|
|
|
|
if (debug >= VERBOSE)
|
|
pr_debug("Time left before next reboot: %d\n", *time_left);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* /dev/watchdog handling
|
|
*/
|
|
|
|
static ssize_t pcipcwd_write(struct file *file, const char __user *data,
|
|
size_t len, loff_t *ppos)
|
|
{
|
|
/* See if we got the magic character 'V' and reload the timer */
|
|
if (len) {
|
|
if (!nowayout) {
|
|
size_t i;
|
|
|
|
/* note: just in case someone wrote the magic character
|
|
* five months ago... */
|
|
expect_release = 0;
|
|
|
|
/* scan to see whether or not we got the
|
|
* magic character */
|
|
for (i = 0; i != len; i++) {
|
|
char c;
|
|
if (get_user(c, data + i))
|
|
return -EFAULT;
|
|
if (c == 'V')
|
|
expect_release = 42;
|
|
}
|
|
}
|
|
|
|
/* someone wrote to us, we should reload the timer */
|
|
pcipcwd_keepalive();
|
|
}
|
|
return len;
|
|
}
|
|
|
|
static long pcipcwd_ioctl(struct file *file, unsigned int cmd,
|
|
unsigned long arg)
|
|
{
|
|
void __user *argp = (void __user *)arg;
|
|
int __user *p = argp;
|
|
static const struct watchdog_info ident = {
|
|
.options = WDIOF_OVERHEAT |
|
|
WDIOF_CARDRESET |
|
|
WDIOF_KEEPALIVEPING |
|
|
WDIOF_SETTIMEOUT |
|
|
WDIOF_MAGICCLOSE,
|
|
.firmware_version = 1,
|
|
.identity = WATCHDOG_DRIVER_NAME,
|
|
};
|
|
|
|
switch (cmd) {
|
|
case WDIOC_GETSUPPORT:
|
|
return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
|
|
|
|
case WDIOC_GETSTATUS:
|
|
{
|
|
int status;
|
|
pcipcwd_get_status(&status);
|
|
return put_user(status, p);
|
|
}
|
|
|
|
case WDIOC_GETBOOTSTATUS:
|
|
return put_user(pcipcwd_private.boot_status, p);
|
|
|
|
case WDIOC_GETTEMP:
|
|
{
|
|
int temperature;
|
|
|
|
if (pcipcwd_get_temperature(&temperature))
|
|
return -EFAULT;
|
|
|
|
return put_user(temperature, p);
|
|
}
|
|
|
|
case WDIOC_SETOPTIONS:
|
|
{
|
|
int new_options, retval = -EINVAL;
|
|
|
|
if (get_user(new_options, p))
|
|
return -EFAULT;
|
|
|
|
if (new_options & WDIOS_DISABLECARD) {
|
|
if (pcipcwd_stop())
|
|
return -EIO;
|
|
retval = 0;
|
|
}
|
|
|
|
if (new_options & WDIOS_ENABLECARD) {
|
|
if (pcipcwd_start())
|
|
return -EIO;
|
|
retval = 0;
|
|
}
|
|
|
|
if (new_options & WDIOS_TEMPPANIC) {
|
|
temp_panic = 1;
|
|
retval = 0;
|
|
}
|
|
|
|
return retval;
|
|
}
|
|
|
|
case WDIOC_KEEPALIVE:
|
|
pcipcwd_keepalive();
|
|
return 0;
|
|
|
|
case WDIOC_SETTIMEOUT:
|
|
{
|
|
int new_heartbeat;
|
|
|
|
if (get_user(new_heartbeat, p))
|
|
return -EFAULT;
|
|
|
|
if (pcipcwd_set_heartbeat(new_heartbeat))
|
|
return -EINVAL;
|
|
|
|
pcipcwd_keepalive();
|
|
}
|
|
/* fall through */
|
|
|
|
case WDIOC_GETTIMEOUT:
|
|
return put_user(heartbeat, p);
|
|
|
|
case WDIOC_GETTIMELEFT:
|
|
{
|
|
int time_left;
|
|
|
|
if (pcipcwd_get_timeleft(&time_left))
|
|
return -EFAULT;
|
|
|
|
return put_user(time_left, p);
|
|
}
|
|
|
|
default:
|
|
return -ENOTTY;
|
|
}
|
|
}
|
|
|
|
static int pcipcwd_open(struct inode *inode, struct file *file)
|
|
{
|
|
/* /dev/watchdog can only be opened once */
|
|
if (test_and_set_bit(0, &is_active)) {
|
|
if (debug >= VERBOSE)
|
|
pr_err("Attempt to open already opened device\n");
|
|
return -EBUSY;
|
|
}
|
|
|
|
/* Activate */
|
|
pcipcwd_start();
|
|
pcipcwd_keepalive();
|
|
return stream_open(inode, file);
|
|
}
|
|
|
|
static int pcipcwd_release(struct inode *inode, struct file *file)
|
|
{
|
|
/*
|
|
* Shut off the timer.
|
|
*/
|
|
if (expect_release == 42) {
|
|
pcipcwd_stop();
|
|
} else {
|
|
pr_crit("Unexpected close, not stopping watchdog!\n");
|
|
pcipcwd_keepalive();
|
|
}
|
|
expect_release = 0;
|
|
clear_bit(0, &is_active);
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* /dev/temperature handling
|
|
*/
|
|
|
|
static ssize_t pcipcwd_temp_read(struct file *file, char __user *data,
|
|
size_t len, loff_t *ppos)
|
|
{
|
|
int temperature;
|
|
|
|
if (pcipcwd_get_temperature(&temperature))
|
|
return -EFAULT;
|
|
|
|
if (copy_to_user(data, &temperature, 1))
|
|
return -EFAULT;
|
|
|
|
return 1;
|
|
}
|
|
|
|
static int pcipcwd_temp_open(struct inode *inode, struct file *file)
|
|
{
|
|
if (!pcipcwd_private.supports_temp)
|
|
return -ENODEV;
|
|
|
|
return stream_open(inode, file);
|
|
}
|
|
|
|
static int pcipcwd_temp_release(struct inode *inode, struct file *file)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Notify system
|
|
*/
|
|
|
|
static int pcipcwd_notify_sys(struct notifier_block *this, unsigned long code,
|
|
void *unused)
|
|
{
|
|
if (code == SYS_DOWN || code == SYS_HALT)
|
|
pcipcwd_stop(); /* Turn the WDT off */
|
|
|
|
return NOTIFY_DONE;
|
|
}
|
|
|
|
/*
|
|
* Kernel Interfaces
|
|
*/
|
|
|
|
static const struct file_operations pcipcwd_fops = {
|
|
.owner = THIS_MODULE,
|
|
.llseek = no_llseek,
|
|
.write = pcipcwd_write,
|
|
.unlocked_ioctl = pcipcwd_ioctl,
|
|
.open = pcipcwd_open,
|
|
.release = pcipcwd_release,
|
|
};
|
|
|
|
static struct miscdevice pcipcwd_miscdev = {
|
|
.minor = WATCHDOG_MINOR,
|
|
.name = "watchdog",
|
|
.fops = &pcipcwd_fops,
|
|
};
|
|
|
|
static const struct file_operations pcipcwd_temp_fops = {
|
|
.owner = THIS_MODULE,
|
|
.llseek = no_llseek,
|
|
.read = pcipcwd_temp_read,
|
|
.open = pcipcwd_temp_open,
|
|
.release = pcipcwd_temp_release,
|
|
};
|
|
|
|
static struct miscdevice pcipcwd_temp_miscdev = {
|
|
.minor = TEMP_MINOR,
|
|
.name = "temperature",
|
|
.fops = &pcipcwd_temp_fops,
|
|
};
|
|
|
|
static struct notifier_block pcipcwd_notifier = {
|
|
.notifier_call = pcipcwd_notify_sys,
|
|
};
|
|
|
|
/*
|
|
* Init & exit routines
|
|
*/
|
|
|
|
static int pcipcwd_card_init(struct pci_dev *pdev,
|
|
const struct pci_device_id *ent)
|
|
{
|
|
int ret = -EIO;
|
|
|
|
cards_found++;
|
|
if (cards_found == 1)
|
|
pr_info("%s\n", DRIVER_VERSION);
|
|
|
|
if (cards_found > 1) {
|
|
pr_err("This driver only supports 1 device\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
if (pci_enable_device(pdev)) {
|
|
pr_err("Not possible to enable PCI Device\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
if (pci_resource_start(pdev, 0) == 0x0000) {
|
|
pr_err("No I/O-Address for card detected\n");
|
|
ret = -ENODEV;
|
|
goto err_out_disable_device;
|
|
}
|
|
|
|
spin_lock_init(&pcipcwd_private.io_lock);
|
|
pcipcwd_private.pdev = pdev;
|
|
pcipcwd_private.io_addr = pci_resource_start(pdev, 0);
|
|
|
|
if (pci_request_regions(pdev, WATCHDOG_NAME)) {
|
|
pr_err("I/O address 0x%04x already in use\n",
|
|
(int) pcipcwd_private.io_addr);
|
|
ret = -EIO;
|
|
goto err_out_disable_device;
|
|
}
|
|
|
|
/* get the boot_status */
|
|
pcipcwd_get_status(&pcipcwd_private.boot_status);
|
|
|
|
/* clear the "card caused reboot" flag */
|
|
pcipcwd_clear_status();
|
|
|
|
/* disable card */
|
|
pcipcwd_stop();
|
|
|
|
/* Check whether or not the card supports the temperature device */
|
|
pcipcwd_check_temperature_support();
|
|
|
|
/* Show info about the card itself */
|
|
pcipcwd_show_card_info();
|
|
|
|
/* If heartbeat = 0 then we use the heartbeat from the dip-switches */
|
|
if (heartbeat == 0)
|
|
heartbeat =
|
|
heartbeat_tbl[(pcipcwd_get_option_switches() & 0x07)];
|
|
|
|
/* Check that the heartbeat value is within it's range ;
|
|
* if not reset to the default */
|
|
if (pcipcwd_set_heartbeat(heartbeat)) {
|
|
pcipcwd_set_heartbeat(WATCHDOG_HEARTBEAT);
|
|
pr_info("heartbeat value must be 0<heartbeat<65536, using %d\n",
|
|
WATCHDOG_HEARTBEAT);
|
|
}
|
|
|
|
ret = register_reboot_notifier(&pcipcwd_notifier);
|
|
if (ret != 0) {
|
|
pr_err("cannot register reboot notifier (err=%d)\n", ret);
|
|
goto err_out_release_region;
|
|
}
|
|
|
|
if (pcipcwd_private.supports_temp) {
|
|
ret = misc_register(&pcipcwd_temp_miscdev);
|
|
if (ret != 0) {
|
|
pr_err("cannot register miscdev on minor=%d (err=%d)\n",
|
|
TEMP_MINOR, ret);
|
|
goto err_out_unregister_reboot;
|
|
}
|
|
}
|
|
|
|
ret = misc_register(&pcipcwd_miscdev);
|
|
if (ret != 0) {
|
|
pr_err("cannot register miscdev on minor=%d (err=%d)\n",
|
|
WATCHDOG_MINOR, ret);
|
|
goto err_out_misc_deregister;
|
|
}
|
|
|
|
pr_info("initialized. heartbeat=%d sec (nowayout=%d)\n",
|
|
heartbeat, nowayout);
|
|
|
|
return 0;
|
|
|
|
err_out_misc_deregister:
|
|
if (pcipcwd_private.supports_temp)
|
|
misc_deregister(&pcipcwd_temp_miscdev);
|
|
err_out_unregister_reboot:
|
|
unregister_reboot_notifier(&pcipcwd_notifier);
|
|
err_out_release_region:
|
|
pci_release_regions(pdev);
|
|
err_out_disable_device:
|
|
pci_disable_device(pdev);
|
|
return ret;
|
|
}
|
|
|
|
static void pcipcwd_card_exit(struct pci_dev *pdev)
|
|
{
|
|
/* Stop the timer before we leave */
|
|
if (!nowayout)
|
|
pcipcwd_stop();
|
|
|
|
/* Deregister */
|
|
misc_deregister(&pcipcwd_miscdev);
|
|
if (pcipcwd_private.supports_temp)
|
|
misc_deregister(&pcipcwd_temp_miscdev);
|
|
unregister_reboot_notifier(&pcipcwd_notifier);
|
|
pci_release_regions(pdev);
|
|
pci_disable_device(pdev);
|
|
cards_found--;
|
|
}
|
|
|
|
static const struct pci_device_id pcipcwd_pci_tbl[] = {
|
|
{ PCI_VENDOR_ID_QUICKLOGIC, PCI_DEVICE_ID_WATCHDOG_PCIPCWD,
|
|
PCI_ANY_ID, PCI_ANY_ID, },
|
|
{ 0 }, /* End of list */
|
|
};
|
|
MODULE_DEVICE_TABLE(pci, pcipcwd_pci_tbl);
|
|
|
|
static struct pci_driver pcipcwd_driver = {
|
|
.name = WATCHDOG_NAME,
|
|
.id_table = pcipcwd_pci_tbl,
|
|
.probe = pcipcwd_card_init,
|
|
.remove = pcipcwd_card_exit,
|
|
};
|
|
|
|
module_pci_driver(pcipcwd_driver);
|
|
|
|
MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
|
|
MODULE_DESCRIPTION("Berkshire PCI-PC Watchdog driver");
|
|
MODULE_LICENSE("GPL");
|