public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christer Weinigel <wingel@acolyte.hack.org>
To: jgarzik@mandrakesoft.com
Cc: zwane@linux.realnet.co.sz, roy@karlsbakk.net,
	alan@lxorguk.ukuu.org.uk, linux-kernel@vger.kernel.org
Subject: Re: [DRIVER][RFC] SC1200 Watchdog driver
Date: Thu, 21 Feb 2002 13:57:43 +0100 (CET)	[thread overview]
Message-ID: <20020221125743.10F0BF5B@acolyte.hack.org> (raw)
In-Reply-To: <3C74E698.D3A0BFEB@mandrakesoft.com> (message from Jeff Garzik on Thu, 21 Feb 2002 07:22:48 -0500)
In-Reply-To: <Pine.LNX.4.44.0202211134080.7649-100000@netfinity.realnet.co.sz> <3C74C8C7.25D7BCD@mandrakesoft.com> <20020221111910.57235F5B@acolyte.hack.org> <20020221115916.9FD5AF5B@acolyte.hack.org> <3C74E698.D3A0BFEB@mandrakesoft.com>

[-- Attachment #1: Type: text/plain, Size: 2673 bytes --]

Jeff Garzik wrote:
> MODULE_PARM_DESC would be nice

Done.  

> > static void scx200_watchdog_update_margin(void)
> > {
> >         printk(KERN_INFO "%s: timer margin %d seconds\n", name, margin);
> >         wdto_restart = 32768 / 1024 * margin;
> >         scx200_watchdog_ping();
> > }
> 
> if you can turn multiplication and division of powers-of-2 into left and
> right shifts, other simplications sometimes follow.  Certainly you want
> to avoid division especially and multiplication also if possible.

Since this is only called on initialization I'm not overly concerned
with performance here, I prefer code clarity.  This ought to be
optimized by gcc anyways.

> now, a policy question -- do you want to fail or simply put to sleep
> multiple openers?  if you want to fail, this should be ok I think.  if
> you want to sleep, you can look at sound/oss/* in 2.5.x or
> drivers/sound/* in 2.4.x for some examples of semaphore use on
> open(2).

I'm not even sure if single-open sematics are neccesary at all, but I
copied most of the interface from wdt285.c so I copied this too.  The
watchdog API seems to be a rather ad hoc thing.  For example I just
noticed that the WDIOC_SETTIMEOUT call probably takes a parameter
which seems to be minutes, not seconds.  "Someone (tm)" ought to write
a more formal API specification.

> I wonder why 'name' is not simply a macro defining a string constant? 
> Oh yeah, it matters very little.  You might want to make 'name' const,
> though.

Because "%s: " is less text than "scx200_watchdog" and I'm not sure if
gcc is able to merge duplicate strings.  Not much of a difference.

> > static struct notifier_block scx200_watchdog_notifier =
> > {
> >         scx200_watchdog_notify_sys,
> >         NULL,
> >         0
> > };
> 
> use name:value style of struct initialization, and omit any struct
> members which are 0/NULL (that's implicit).

Done.  I also changed the notifier codes that cause the watchdog to
shut down to something that seems more useful.

> > static int __init scx200_watchdog_init(void)
> > {
> >         int r;
> 
> Here's a big one, I still don't like this lack of probing in the
> driver.  Sure we have "probed elsewhere", but IMO each driver like this
> one needs to check -something- to ensure that SC1200 hardware is
> present.  Otherwise, a random user from a distro-that-builds-all-drivers
> might "modprobe sc1200_watchdog" and things go boom.

You're right, I just assumed that nobody would load this driver unless
they are on a SCx200 system.  Done.  I'll update all the other drivers
too.

  /Christer (off to lunch)

-- 
Blatant plug: I'm a freelance consultant looking for interesting work.

[-- Attachment #2: d.diff --]
[-- Type: application/octet-stream, Size: 2483 bytes --]

diff -urw nano/drivers/char/scx200_watchdog.c.orig nano/drivers/char/scx200_watchdog.c
--- nano/drivers/char/scx200_watchdog.c.orig	Thu Feb 21 13:49:53 2002
+++ nano/drivers/char/scx200_watchdog.c	Thu Feb 21 13:55:30 2002
@@ -38,13 +38,15 @@
 #define CONFIG_WATCHDOG_NOWAYOUT 0
 #endif
 
-static char name[] = "scx200_watchdog";
+static const char name[] = "scx200_watchdog";
 
 static int margin = 60;		/* in seconds */
 MODULE_PARM(margin, "i");
+MODULE_PARM_DESC(margin, "Watchdog margin in seconds");
 
 static int nowayout = CONFIG_WATCHDOG_NOWAYOUT;
 MODULE_PARM(nowayout, "i");
+MODULE_PARM_DESC(nowayout, "If true the watchdog can't be disabled\n");
 
 static u16 wdto_restart;
 static struct semaphore open_sem;
@@ -57,6 +59,8 @@
 #define WDSTS 0x04		/* Status Register */
 #define    WDOVF (1<<0)		/* Overflow */
 
+#define W_SCALE (32768/1024)	/* This depends on the value of W_ENABLE */
+
 static void scx200_watchdog_ping(void)
 {
 	outw(wdto_restart, scx200_config_block + WDTO);
@@ -65,7 +69,7 @@
 static void scx200_watchdog_update_margin(void)
 {
 	printk(KERN_INFO "%s: timer margin %d seconds\n", name, margin);
-	wdto_restart = 32768 / 1024 * margin;
+	wdto_restart = margin * W_SCALE;
 	scx200_watchdog_ping();	
 }
 
@@ -117,7 +121,7 @@
 static int scx200_watchdog_notify_sys(struct notifier_block *this, 
 				      unsigned long code, void *unused)
 {
-        if (code == SYS_DOWN || code == SYS_HALT)
+        if (code == SYS_HALT || code == SYS_POWER_OFF)
 		scx200_watchdog_disable();
 
         return NOTIFY_DONE;
@@ -125,9 +129,7 @@
 
 static struct notifier_block scx200_watchdog_notifier =
 {
-        scx200_watchdog_notify_sys,
-        NULL,
-        0
+        notifier_call: scx200_watchdog_notify_sys
 };
 
 static ssize_t scx200_watchdog_write(struct file *file, const char *data, 
@@ -182,13 +184,12 @@
 	case WDIOC_SETTIMEOUT:
 		if (get_user(new_margin, (int *)arg))
 			return -EFAULT;
-		margin = new_margin;
+		margin = new_margin * 60; /* convert minutes to seconds */
 		scx200_watchdog_update_margin();
 		return 0;
-
 #ifdef WDIOC_GETTIMEOUT		
 	case WDIOC_GETTIMEOUT:
-		return put_user(margin, (int *)arg);
+		return put_user((margin + 59) / 60, (int *)arg);
 #endif
 	}
 }
@@ -210,6 +211,11 @@
 static int __init scx200_watchdog_init(void)
 {
 	int r;
+
+	if (scx200_f0_pdev == NULL) {
+		printk(KERN_ERR "%s: Not a SCx200 CPU\n", name);
+		return -ENODEV;
+	}
 
 	scx200_watchdog_update_margin();
         sema_init(&open_sem, 1);

  parent reply	other threads:[~2002-02-21 12:58 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-20 13:32 SC1200 support? Roy Sigurd Karlsbakk
2002-02-20 15:14 ` Alan Cox
2002-02-21  5:54   ` [DRIVER][RFC] SC1200 Watchdog driver Zwane Mwaikambo
2002-02-21  9:39     ` Jeff Garzik
2002-02-21  9:48       ` Zwane Mwaikambo
2002-02-21 10:15         ` Jeff Garzik
2002-02-21 10:10           ` Zwane Mwaikambo
2002-02-21 11:19           ` Christer Weinigel
2002-02-21 11:59             ` Christer Weinigel
2002-02-21 12:07               ` Zwane Mwaikambo
2002-02-21 13:37                 ` Alan Cox
2002-02-21 14:27                   ` Zwane Mwaikambo
2002-02-21 14:54                     ` Dave Jones
2002-02-21 15:16                     ` Alan Cox
2002-02-21 12:22               ` Jeff Garzik
2002-02-21 12:32                 ` Zwane Mwaikambo
2002-02-21 12:46                   ` Jeff Garzik
2002-02-21 12:57                 ` Christer Weinigel [this message]
2002-02-21 13:20                   ` Jeff Garzik
2002-02-22 19:57                     ` Christer Weinigel
     [not found]                       ` <20020222210107.A6828@fafner.intra.cogenit.fr>
2002-02-22 20:48                         ` Christer Weinigel
2002-02-22 22:56                           ` Joel Becker
2002-02-25 22:20                           ` Randy.Dunlap
2002-02-26  1:22                             ` Christer Weinigel
2002-02-26  1:37                               ` Christer Weinigel
2002-02-26  1:59                                 ` Jakob Østergaard
2002-02-26  2:42                                 ` Alan Cox
2002-02-21 15:53                   ` Joel Becker
2002-02-24 17:30         ` Roy Sigurd Karlsbakk
2002-02-25  8:22           ` Zwane Mwaikambo
2002-02-25 21:01             ` Roy Sigurd Karlsbakk
2002-02-21  0:02 ` SC1200 support? Christer Weinigel
2002-02-21  0:27   ` Keith Owens
2002-02-21  6:19   ` Zwane Mwaikambo
2002-02-21  6:35     ` nick
2002-02-21  6:31       ` Zwane Mwaikambo
2002-02-21 12:05     ` Christer Weinigel
2002-02-21 10:56   ` Christer Weinigel
2002-02-21 11:14     ` Keith Owens
2002-02-21 11:24   ` David Woodhouse
  -- strict thread matches above, loose matches on Subject: below --
2002-02-22 10:15 [DRIVER][RFC] SC1200 Watchdog driver Zwane Mwaikambo
2002-02-22 19:32 ` Roy Sigurd Karlsbakk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020221125743.10F0BF5B@acolyte.hack.org \
    --to=wingel@acolyte.hack.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=jgarzik@mandrakesoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roy@karlsbakk.net \
    --cc=zwane@linux.realnet.co.sz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox