Re: [RFC] watchdog: Add watchdog device control through sysfs attributes

2015-08-30 Thread Pratyush Anand
On 29/08/2015:09:51:24 AM, Guenter Roeck wrote:
> > * timeout - reads current timeout and writes to program a new timeout.

Now, this is the only file which has write permission. I hope, that is fine. Pl
let me know if you expected this to be as RO as well.

~Pratyush
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC] watchdog: Add watchdog device control through sysfs attributes

2015-08-30 Thread Pratyush Anand
Hi Guenter,

Thanks for review.

On 29/08/2015:09:51:24 AM, Guenter Roeck wrote:
> On Fri, Aug 21, 2015 at 11:18:12PM +0530, Pratyush Anand wrote:
> > This patch adds following attributes to watchdog device's sysfs interface.
> > 
> > * start - writes non zero value to start and zero to stop
> 
> I would suggest to drop this attribute, as well as 'keepalive'.
> Both will make keeping the internal state very difficult, especially
> when we add support for heartbeats triggered by the watchdog core.
> 

OK.

> > * state - reads whether device is active or not(1 for active and 0 for
> > inactive)
> 
> How about reporting the state as text ?

Will change

> 
> > * identity - reads Watchdog device's identity string.
> > * keepalive - writes to ping a watchdog device
> > * timeout - reads current timeout and writes to program a new timeout.
> > * timeleft - reads timeleft before watchdog generates a reset
> > * bootstatus - reads status of the watchdog device at boot
> > * status - reads watchdog device's  internal status bits
> > * nowayout - reads whether nowayout feature was set or not
> > 
> > Testing with iTCO_wdt:
> >  # cd /sys/class/watchdog/watchdog1/
> >  # ls
> > bootstatus  dev  device  identity  keepalive  nowayout  power  start  state
> > status  subsystem  timeleft  timeout  uevent
> >  # cat identity
> > iTCO_wdt
> >  # cat timeout
> > 30
> >  # echo 1 > start
> >  # cat timeleft
> > 26
> >  # echo 120 > timeout
> >  # cat timeleft
> > 116
> >  # echo > keepalive
> >  # cat timeleft
> > 118
> >  # cat state
> > 1
> >  # echo 0 > start
> >  # cat state
> > 0
> >  # cat bootstatus
> > 0
> >  # cat nowayout
> > 0
> >  # cat status
> > cat: status: Operation not supported
> > 
> Unsupported attributes should not appear in the first place.
> Please use is_visible to determine if an attribute should
> be there or not.

Thanks :-).. Will modify.

> 
> > Signed-off-by: Pratyush Anand 
> > ---
> >  Documentation/ABI/testing/sysfs-class-watchdog |  74 +
> >  drivers/watchdog/watchdog_core.c   |   6 +-
> >  drivers/watchdog/watchdog_core.h   |   2 +
> >  drivers/watchdog/watchdog_dev.c| 206 
> > +
> >  4 files changed, 284 insertions(+), 4 deletions(-)
> >  create mode 100644 Documentation/ABI/testing/sysfs-class-watchdog
> > 
> > diff --git a/Documentation/ABI/testing/sysfs-class-watchdog 
> > b/Documentation/ABI/testing/sysfs-class-watchdog
> > new file mode 100644
> > index ..31e7be53edf8
> > --- /dev/null
> > +++ b/Documentation/ABI/testing/sysfs-class-watchdog
> > @@ -0,0 +1,74 @@
> > +What:  /sys/class/watchdog/watchdogn/bootstatus
> > +Date:  August 2015
> > +Contact:   Pratyush Anand 
> 
> Who is normally listed here ? Shouldn't it be the maintainer ?

I am not sure.. Will be happy to change it to
Wim Van Sebroeck .

> 
> >  static int __watchdog_register_device(struct watchdog_device *wdd)
> >  {
> > -   int ret, id, devno;
> > +   int ret, id;
> >  
> > if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL)
> > return -EINVAL;
> > @@ -181,9 +181,7 @@ static int __watchdog_register_device(struct 
> > watchdog_device *wdd)
> > }
> > }
> >  
> > -   devno = wdd->cdev.dev;
> > -   wdd->dev = device_create(watchdog_class, wdd->parent, devno,
> > -   NULL, "watchdog%d", wdd->id);
> > +   wdd->dev = watchdog_device_create(watchdog_class, wdd);
> 
> Can we do this in watchdog_dev_register() ?
> Seems to make more sense than adding another callback into watchdog_dev.c.

I had thought of this, but then will have to change prototype of
watchdog_dev_register() to accept struct class *wdc and which in turn will cause
to change all users of watchdog_dev_register().
Other option could be to add struct class *wdc in struct watchdog_device, but it
did not look nice to me.

> 
> > if (IS_ERR(wdd->dev)) {
> > +static ssize_t nowayout_show(struct device *dev,
> > +   struct device_attribute *attr, char *buf)
> > +{
> > +   struct watchdog_device *wdd = dev_get_drvdata(dev);
> > +   bool nowayout = false;
> > +
> > +   mutex_lock(>lock);
> > +   if (test_bit(WDOG_NO_WAY_OUT, >status))
> > +   nowayout = true;
> > +   mutex_unlock(>lock);
> > +
> > +   return sprintf(buf, "%d\n", nowayout);
> 
>   return sprintf(buf, "%d\n", !!test_bit(WDOG_NO_WAY_OUT, >status));
> 
> should do it, and the lock doesn't seem to be very helpful,
> as it doesn't make a difference when the flag is evaluated.

OK.

> 
> > +}
> > +static DEVICE_ATTR_RO(nowayout);
> > +
> > +static ssize_t status_show(struct device *dev,
> > +   struct device_attribute *attr, char *buf)
> 
> Please align continuation lines with '('.

OK.

> 
> > +{
> > +   struct watchdog_device *wdd = dev_get_drvdata(dev);
> > +   ssize_t status;
> > +   unsigned int val;
> > +
> > +   status = watchdog_get_status(wdd, );
> > +   if (!status)
> > +   status = 

Re: [RFC] watchdog: Add watchdog device control through sysfs attributes

2015-08-30 Thread Pratyush Anand
Hi Guenter,

Thanks for review.

On 29/08/2015:09:51:24 AM, Guenter Roeck wrote:
 On Fri, Aug 21, 2015 at 11:18:12PM +0530, Pratyush Anand wrote:
  This patch adds following attributes to watchdog device's sysfs interface.
  
  * start - writes non zero value to start and zero to stop
 
 I would suggest to drop this attribute, as well as 'keepalive'.
 Both will make keeping the internal state very difficult, especially
 when we add support for heartbeats triggered by the watchdog core.
 

OK.

  * state - reads whether device is active or not(1 for active and 0 for
  inactive)
 
 How about reporting the state as text ?

Will change

 
  * identity - reads Watchdog device's identity string.
  * keepalive - writes to ping a watchdog device
  * timeout - reads current timeout and writes to program a new timeout.
  * timeleft - reads timeleft before watchdog generates a reset
  * bootstatus - reads status of the watchdog device at boot
  * status - reads watchdog device's  internal status bits
  * nowayout - reads whether nowayout feature was set or not
  
  Testing with iTCO_wdt:
   # cd /sys/class/watchdog/watchdog1/
   # ls
  bootstatus  dev  device  identity  keepalive  nowayout  power  start  state
  status  subsystem  timeleft  timeout  uevent
   # cat identity
  iTCO_wdt
   # cat timeout
  30
   # echo 1  start
   # cat timeleft
  26
   # echo 120  timeout
   # cat timeleft
  116
   # echo  keepalive
   # cat timeleft
  118
   # cat state
  1
   # echo 0  start
   # cat state
  0
   # cat bootstatus
  0
   # cat nowayout
  0
   # cat status
  cat: status: Operation not supported
  
 Unsupported attributes should not appear in the first place.
 Please use is_visible to determine if an attribute should
 be there or not.

Thanks :-).. Will modify.

 
  Signed-off-by: Pratyush Anand pan...@redhat.com
  ---
   Documentation/ABI/testing/sysfs-class-watchdog |  74 +
   drivers/watchdog/watchdog_core.c   |   6 +-
   drivers/watchdog/watchdog_core.h   |   2 +
   drivers/watchdog/watchdog_dev.c| 206 
  +
   4 files changed, 284 insertions(+), 4 deletions(-)
   create mode 100644 Documentation/ABI/testing/sysfs-class-watchdog
  
  diff --git a/Documentation/ABI/testing/sysfs-class-watchdog 
  b/Documentation/ABI/testing/sysfs-class-watchdog
  new file mode 100644
  index ..31e7be53edf8
  --- /dev/null
  +++ b/Documentation/ABI/testing/sysfs-class-watchdog
  @@ -0,0 +1,74 @@
  +What:  /sys/class/watchdog/watchdogn/bootstatus
  +Date:  August 2015
  +Contact:   Pratyush Anand pan...@redhat.com
 
 Who is normally listed here ? Shouldn't it be the maintainer ?

I am not sure.. Will be happy to change it to
Wim Van Sebroeck w...@iguana.be.

 
   static int __watchdog_register_device(struct watchdog_device *wdd)
   {
  -   int ret, id, devno;
  +   int ret, id;
   
  if (wdd == NULL || wdd-info == NULL || wdd-ops == NULL)
  return -EINVAL;
  @@ -181,9 +181,7 @@ static int __watchdog_register_device(struct 
  watchdog_device *wdd)
  }
  }
   
  -   devno = wdd-cdev.dev;
  -   wdd-dev = device_create(watchdog_class, wdd-parent, devno,
  -   NULL, watchdog%d, wdd-id);
  +   wdd-dev = watchdog_device_create(watchdog_class, wdd);
 
 Can we do this in watchdog_dev_register() ?
 Seems to make more sense than adding another callback into watchdog_dev.c.

I had thought of this, but then will have to change prototype of
watchdog_dev_register() to accept struct class *wdc and which in turn will cause
to change all users of watchdog_dev_register().
Other option could be to add struct class *wdc in struct watchdog_device, but it
did not look nice to me.

 
  if (IS_ERR(wdd-dev)) {
  +static ssize_t nowayout_show(struct device *dev,
  +   struct device_attribute *attr, char *buf)
  +{
  +   struct watchdog_device *wdd = dev_get_drvdata(dev);
  +   bool nowayout = false;
  +
  +   mutex_lock(wdd-lock);
  +   if (test_bit(WDOG_NO_WAY_OUT, wdd-status))
  +   nowayout = true;
  +   mutex_unlock(wdd-lock);
  +
  +   return sprintf(buf, %d\n, nowayout);
 
   return sprintf(buf, %d\n, !!test_bit(WDOG_NO_WAY_OUT, wdd-status));
 
 should do it, and the lock doesn't seem to be very helpful,
 as it doesn't make a difference when the flag is evaluated.

OK.

 
  +}
  +static DEVICE_ATTR_RO(nowayout);
  +
  +static ssize_t status_show(struct device *dev,
  +   struct device_attribute *attr, char *buf)
 
 Please align continuation lines with '('.

OK.

 
  +{
  +   struct watchdog_device *wdd = dev_get_drvdata(dev);
  +   ssize_t status;
  +   unsigned int val;
  +
  +   status = watchdog_get_status(wdd, val);
  +   if (!status)
  +   status = sprintf(buf, %u\n, val);
  +
 
 This attribute should only be visible if supported.

yes.

 
  +   return status;
  +}
  +static DEVICE_ATTR_RO(status);
  +
  +static ssize_t bootstatus_show(struct 

Re: [RFC] watchdog: Add watchdog device control through sysfs attributes

2015-08-30 Thread Pratyush Anand
On 29/08/2015:09:51:24 AM, Guenter Roeck wrote:
  * timeout - reads current timeout and writes to program a new timeout.

Now, this is the only file which has write permission. I hope, that is fine. Pl
let me know if you expected this to be as RO as well.

~Pratyush
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC] watchdog: Add watchdog device control through sysfs attributes

2015-08-29 Thread Guenter Roeck
On Fri, Aug 21, 2015 at 11:18:12PM +0530, Pratyush Anand wrote:
> This patch adds following attributes to watchdog device's sysfs interface.
> 
> * start - writes non zero value to start and zero to stop

I would suggest to drop this attribute, as well as 'keepalive'.
Both will make keeping the internal state very difficult, especially
when we add support for heartbeats triggered by the watchdog core.

> * state - reads whether device is active or not(1 for active and 0 for
> inactive)

How about reporting the state as text ?

> * identity - reads Watchdog device's identity string.
> * keepalive - writes to ping a watchdog device
> * timeout - reads current timeout and writes to program a new timeout.
> * timeleft - reads timeleft before watchdog generates a reset
> * bootstatus - reads status of the watchdog device at boot
> * status - reads watchdog device's  internal status bits
> * nowayout - reads whether nowayout feature was set or not
> 
> Testing with iTCO_wdt:
>  # cd /sys/class/watchdog/watchdog1/
>  # ls
> bootstatus  dev  device  identity  keepalive  nowayout  power  start  state
> status  subsystem  timeleft  timeout  uevent
>  # cat identity
> iTCO_wdt
>  # cat timeout
> 30
>  # echo 1 > start
>  # cat timeleft
> 26
>  # echo 120 > timeout
>  # cat timeleft
> 116
>  # echo > keepalive
>  # cat timeleft
> 118
>  # cat state
> 1
>  # echo 0 > start
>  # cat state
> 0
>  # cat bootstatus
> 0
>  # cat nowayout
> 0
>  # cat status
> cat: status: Operation not supported
> 
Unsupported attributes should not appear in the first place.
Please use is_visible to determine if an attribute should
be there or not.

> Signed-off-by: Pratyush Anand 
> ---
>  Documentation/ABI/testing/sysfs-class-watchdog |  74 +
>  drivers/watchdog/watchdog_core.c   |   6 +-
>  drivers/watchdog/watchdog_core.h   |   2 +
>  drivers/watchdog/watchdog_dev.c| 206 
> +
>  4 files changed, 284 insertions(+), 4 deletions(-)
>  create mode 100644 Documentation/ABI/testing/sysfs-class-watchdog
> 
> diff --git a/Documentation/ABI/testing/sysfs-class-watchdog 
> b/Documentation/ABI/testing/sysfs-class-watchdog
> new file mode 100644
> index ..31e7be53edf8
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-class-watchdog
> @@ -0,0 +1,74 @@
> +What:/sys/class/watchdog/watchdogn/bootstatus
> +Date:August 2015
> +Contact: Pratyush Anand 

Who is normally listed here ? Shouldn't it be the maintainer ?

> +Description:
> + It is a read only file. It contains status of the watchdog
> + device at boot. It is equivalent to WDIOC_GETBOOTSTATUS of
> + ioctl interface.
> +
> +What:/sys/class/watchdog/watchdogn/identity
> +Date:August 2015
> +Contact: Pratyush Anand 
> +Description:
> + It is a read only file. It contains identity string of
> + watchdog device.
> +
> +What:/sys/class/watchdog/watchdogn/keepalive
> +Date:August 2015
> +Contact: Pratyush Anand 
> +Description:
> + It is a write only file. It is written to ping a watchdog
> + device to keep it alive. It is equivalent to
> + WDIOC_KEEPALIVE of ioctl interface.
> +
> +What:/sys/class/watchdog/watchdogn/nowayout
> +Date:August 2015
> +Contact: Pratyush Anand 
> +Description:
> + It is a read only file. While reading, it gives '1' if that
> + device supports nowayout feature else, it gives '0'.
> +
> +What:/sys/class/watchdog/watchdogn/start
> +Date:August 2015
> +Contact: Pratyush Anand 
> +Description:
> + It is a write only file. Writing '1' will trigger that
> + watchdog device and writing '0' will stop it. These are
> + equivalent to WDIOS_ENABLECARD and WDIOS_DISABLECARD of ioctl
> + interface. If a device has nowayout programmed, then that
> + can not be stopped. Therefore, it is recommended to read
> + state file to insure that whether watchdog device was
> + stopped or not after writing '0'.
> +
> +What:/sys/class/watchdog/watchdogn/state
> +Date:August 2015
> +Contact: Pratyush Anand 
> +Description:
> + It is a read only file. If it is read as '1' then a watchdog
> + device is active. If it is read as '0' then a watchdog
> + device is inactive.
> +
> +What:/sys/class/watchdog/watchdogn/status
> +Date:August 2015
> +Contact: Pratyush Anand 
> +Description:
> + It is a read only file. It contains watchdog device's
> + internal status bits. It is equivalent to WDIOC_GETSTATUS
> + of ioctl interface.
> +
> +What:/sys/class/watchdog/watchdogn/timeleft
> +Date:  

Re: [RFC] watchdog: Add watchdog device control through sysfs attributes

2015-08-29 Thread Guenter Roeck
On Fri, Aug 21, 2015 at 11:18:12PM +0530, Pratyush Anand wrote:
 This patch adds following attributes to watchdog device's sysfs interface.
 
 * start - writes non zero value to start and zero to stop

I would suggest to drop this attribute, as well as 'keepalive'.
Both will make keeping the internal state very difficult, especially
when we add support for heartbeats triggered by the watchdog core.

 * state - reads whether device is active or not(1 for active and 0 for
 inactive)

How about reporting the state as text ?

 * identity - reads Watchdog device's identity string.
 * keepalive - writes to ping a watchdog device
 * timeout - reads current timeout and writes to program a new timeout.
 * timeleft - reads timeleft before watchdog generates a reset
 * bootstatus - reads status of the watchdog device at boot
 * status - reads watchdog device's  internal status bits
 * nowayout - reads whether nowayout feature was set or not
 
 Testing with iTCO_wdt:
  # cd /sys/class/watchdog/watchdog1/
  # ls
 bootstatus  dev  device  identity  keepalive  nowayout  power  start  state
 status  subsystem  timeleft  timeout  uevent
  # cat identity
 iTCO_wdt
  # cat timeout
 30
  # echo 1  start
  # cat timeleft
 26
  # echo 120  timeout
  # cat timeleft
 116
  # echo  keepalive
  # cat timeleft
 118
  # cat state
 1
  # echo 0  start
  # cat state
 0
  # cat bootstatus
 0
  # cat nowayout
 0
  # cat status
 cat: status: Operation not supported
 
Unsupported attributes should not appear in the first place.
Please use is_visible to determine if an attribute should
be there or not.

 Signed-off-by: Pratyush Anand pan...@redhat.com
 ---
  Documentation/ABI/testing/sysfs-class-watchdog |  74 +
  drivers/watchdog/watchdog_core.c   |   6 +-
  drivers/watchdog/watchdog_core.h   |   2 +
  drivers/watchdog/watchdog_dev.c| 206 
 +
  4 files changed, 284 insertions(+), 4 deletions(-)
  create mode 100644 Documentation/ABI/testing/sysfs-class-watchdog
 
 diff --git a/Documentation/ABI/testing/sysfs-class-watchdog 
 b/Documentation/ABI/testing/sysfs-class-watchdog
 new file mode 100644
 index ..31e7be53edf8
 --- /dev/null
 +++ b/Documentation/ABI/testing/sysfs-class-watchdog
 @@ -0,0 +1,74 @@
 +What:/sys/class/watchdog/watchdogn/bootstatus
 +Date:August 2015
 +Contact: Pratyush Anand pan...@redhat.com

Who is normally listed here ? Shouldn't it be the maintainer ?

 +Description:
 + It is a read only file. It contains status of the watchdog
 + device at boot. It is equivalent to WDIOC_GETBOOTSTATUS of
 + ioctl interface.
 +
 +What:/sys/class/watchdog/watchdogn/identity
 +Date:August 2015
 +Contact: Pratyush Anand pan...@redhat.com
 +Description:
 + It is a read only file. It contains identity string of
 + watchdog device.
 +
 +What:/sys/class/watchdog/watchdogn/keepalive
 +Date:August 2015
 +Contact: Pratyush Anand pan...@redhat.com
 +Description:
 + It is a write only file. It is written to ping a watchdog
 + device to keep it alive. It is equivalent to
 + WDIOC_KEEPALIVE of ioctl interface.
 +
 +What:/sys/class/watchdog/watchdogn/nowayout
 +Date:August 2015
 +Contact: Pratyush Anand pan...@redhat.com
 +Description:
 + It is a read only file. While reading, it gives '1' if that
 + device supports nowayout feature else, it gives '0'.
 +
 +What:/sys/class/watchdog/watchdogn/start
 +Date:August 2015
 +Contact: Pratyush Anand pan...@redhat.com
 +Description:
 + It is a write only file. Writing '1' will trigger that
 + watchdog device and writing '0' will stop it. These are
 + equivalent to WDIOS_ENABLECARD and WDIOS_DISABLECARD of ioctl
 + interface. If a device has nowayout programmed, then that
 + can not be stopped. Therefore, it is recommended to read
 + state file to insure that whether watchdog device was
 + stopped or not after writing '0'.
 +
 +What:/sys/class/watchdog/watchdogn/state
 +Date:August 2015
 +Contact: Pratyush Anand pan...@redhat.com
 +Description:
 + It is a read only file. If it is read as '1' then a watchdog
 + device is active. If it is read as '0' then a watchdog
 + device is inactive.
 +
 +What:/sys/class/watchdog/watchdogn/status
 +Date:August 2015
 +Contact: Pratyush Anand pan...@redhat.com
 +Description:
 + It is a read only file. It contains watchdog device's
 + internal status bits. It is equivalent to WDIOC_GETSTATUS
 + of ioctl interface.
 +
 +What:

Re: [PATCH RFC] watchdog: Add watchdog device control through sysfs attributes

2015-08-25 Thread Pratyush Anand
Hi Guenter,

On 21/08/2015:11:18:12 PM, Pratyush Anand wrote:
> This patch adds following attributes to watchdog device's sysfs interface.

Please see if you can review it.

Does this patch look fine to you? If yes then do I need to resend it by removing
RFC tag.

~Pratyush
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC] watchdog: Add watchdog device control through sysfs attributes

2015-08-25 Thread Pratyush Anand
Hi Guenter,

On 21/08/2015:11:18:12 PM, Pratyush Anand wrote:
 This patch adds following attributes to watchdog device's sysfs interface.

Please see if you can review it.

Does this patch look fine to you? If yes then do I need to resend it by removing
RFC tag.

~Pratyush
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RFC] watchdog: Add watchdog device control through sysfs attributes

2015-08-21 Thread Pratyush Anand
This patch adds following attributes to watchdog device's sysfs interface.

* start - writes non zero value to start and zero to stop
* state - reads whether device is active or not(1 for active and 0 for
inactive)
* identity - reads Watchdog device's identity string.
* keepalive - writes to ping a watchdog device
* timeout - reads current timeout and writes to program a new timeout.
* timeleft - reads timeleft before watchdog generates a reset
* bootstatus - reads status of the watchdog device at boot
* status - reads watchdog device's  internal status bits
* nowayout - reads whether nowayout feature was set or not

Testing with iTCO_wdt:
 # cd /sys/class/watchdog/watchdog1/
 # ls
bootstatus  dev  device  identity  keepalive  nowayout  power  start  state
status  subsystem  timeleft  timeout  uevent
 # cat identity
iTCO_wdt
 # cat timeout
30
 # echo 1 > start
 # cat timeleft
26
 # echo 120 > timeout
 # cat timeleft
116
 # echo > keepalive
 # cat timeleft
118
 # cat state
1
 # echo 0 > start
 # cat state
0
 # cat bootstatus
0
 # cat nowayout
0
 # cat status
cat: status: Operation not supported

Signed-off-by: Pratyush Anand 
---
 Documentation/ABI/testing/sysfs-class-watchdog |  74 +
 drivers/watchdog/watchdog_core.c   |   6 +-
 drivers/watchdog/watchdog_core.h   |   2 +
 drivers/watchdog/watchdog_dev.c| 206 +
 4 files changed, 284 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-watchdog

diff --git a/Documentation/ABI/testing/sysfs-class-watchdog 
b/Documentation/ABI/testing/sysfs-class-watchdog
new file mode 100644
index ..31e7be53edf8
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-watchdog
@@ -0,0 +1,74 @@
+What:  /sys/class/watchdog/watchdogn/bootstatus
+Date:  August 2015
+Contact:   Pratyush Anand 
+Description:
+   It is a read only file. It contains status of the watchdog
+   device at boot. It is equivalent to WDIOC_GETBOOTSTATUS of
+   ioctl interface.
+
+What:  /sys/class/watchdog/watchdogn/identity
+Date:  August 2015
+Contact:   Pratyush Anand 
+Description:
+   It is a read only file. It contains identity string of
+   watchdog device.
+
+What:  /sys/class/watchdog/watchdogn/keepalive
+Date:  August 2015
+Contact:   Pratyush Anand 
+Description:
+   It is a write only file. It is written to ping a watchdog
+   device to keep it alive. It is equivalent to
+   WDIOC_KEEPALIVE of ioctl interface.
+
+What:  /sys/class/watchdog/watchdogn/nowayout
+Date:  August 2015
+Contact:   Pratyush Anand 
+Description:
+   It is a read only file. While reading, it gives '1' if that
+   device supports nowayout feature else, it gives '0'.
+
+What:  /sys/class/watchdog/watchdogn/start
+Date:  August 2015
+Contact:   Pratyush Anand 
+Description:
+   It is a write only file. Writing '1' will trigger that
+   watchdog device and writing '0' will stop it. These are
+   equivalent to WDIOS_ENABLECARD and WDIOS_DISABLECARD of ioctl
+   interface. If a device has nowayout programmed, then that
+   can not be stopped. Therefore, it is recommended to read
+   state file to insure that whether watchdog device was
+   stopped or not after writing '0'.
+
+What:  /sys/class/watchdog/watchdogn/state
+Date:  August 2015
+Contact:   Pratyush Anand 
+Description:
+   It is a read only file. If it is read as '1' then a watchdog
+   device is active. If it is read as '0' then a watchdog
+   device is inactive.
+
+What:  /sys/class/watchdog/watchdogn/status
+Date:  August 2015
+Contact:   Pratyush Anand 
+Description:
+   It is a read only file. It contains watchdog device's
+   internal status bits. It is equivalent to WDIOC_GETSTATUS
+   of ioctl interface.
+
+What:  /sys/class/watchdog/watchdogn/timeleft
+Date:  August 2015
+Contact:   Pratyush Anand 
+Description:
+   It is a read only file. It contains value of time left for
+   reset generation. It is equivalent to WDIOC_GETTIMELEFT of
+   ioctl interface.
+
+What:  /sys/class/watchdog/watchdogn/timeout
+Date:  August 2015
+Contact:   Pratyush Anand 
+Description:
+   It is a read/write file. It is read to know about current
+   timeout and written to program a new timeout value. These
+   are equivalent to WDIOC_SETTIMEOUT and WDIOC_GETTIMEOUT of
+   ioctl interface.
diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c
index 1a8059455413..703ff7b23f31 100644
--- 

[PATCH RFC] watchdog: Add watchdog device control through sysfs attributes

2015-08-21 Thread Pratyush Anand
This patch adds following attributes to watchdog device's sysfs interface.

* start - writes non zero value to start and zero to stop
* state - reads whether device is active or not(1 for active and 0 for
inactive)
* identity - reads Watchdog device's identity string.
* keepalive - writes to ping a watchdog device
* timeout - reads current timeout and writes to program a new timeout.
* timeleft - reads timeleft before watchdog generates a reset
* bootstatus - reads status of the watchdog device at boot
* status - reads watchdog device's  internal status bits
* nowayout - reads whether nowayout feature was set or not

Testing with iTCO_wdt:
 # cd /sys/class/watchdog/watchdog1/
 # ls
bootstatus  dev  device  identity  keepalive  nowayout  power  start  state
status  subsystem  timeleft  timeout  uevent
 # cat identity
iTCO_wdt
 # cat timeout
30
 # echo 1  start
 # cat timeleft
26
 # echo 120  timeout
 # cat timeleft
116
 # echo  keepalive
 # cat timeleft
118
 # cat state
1
 # echo 0  start
 # cat state
0
 # cat bootstatus
0
 # cat nowayout
0
 # cat status
cat: status: Operation not supported

Signed-off-by: Pratyush Anand pan...@redhat.com
---
 Documentation/ABI/testing/sysfs-class-watchdog |  74 +
 drivers/watchdog/watchdog_core.c   |   6 +-
 drivers/watchdog/watchdog_core.h   |   2 +
 drivers/watchdog/watchdog_dev.c| 206 +
 4 files changed, 284 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-watchdog

diff --git a/Documentation/ABI/testing/sysfs-class-watchdog 
b/Documentation/ABI/testing/sysfs-class-watchdog
new file mode 100644
index ..31e7be53edf8
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-watchdog
@@ -0,0 +1,74 @@
+What:  /sys/class/watchdog/watchdogn/bootstatus
+Date:  August 2015
+Contact:   Pratyush Anand pan...@redhat.com
+Description:
+   It is a read only file. It contains status of the watchdog
+   device at boot. It is equivalent to WDIOC_GETBOOTSTATUS of
+   ioctl interface.
+
+What:  /sys/class/watchdog/watchdogn/identity
+Date:  August 2015
+Contact:   Pratyush Anand pan...@redhat.com
+Description:
+   It is a read only file. It contains identity string of
+   watchdog device.
+
+What:  /sys/class/watchdog/watchdogn/keepalive
+Date:  August 2015
+Contact:   Pratyush Anand pan...@redhat.com
+Description:
+   It is a write only file. It is written to ping a watchdog
+   device to keep it alive. It is equivalent to
+   WDIOC_KEEPALIVE of ioctl interface.
+
+What:  /sys/class/watchdog/watchdogn/nowayout
+Date:  August 2015
+Contact:   Pratyush Anand pan...@redhat.com
+Description:
+   It is a read only file. While reading, it gives '1' if that
+   device supports nowayout feature else, it gives '0'.
+
+What:  /sys/class/watchdog/watchdogn/start
+Date:  August 2015
+Contact:   Pratyush Anand pan...@redhat.com
+Description:
+   It is a write only file. Writing '1' will trigger that
+   watchdog device and writing '0' will stop it. These are
+   equivalent to WDIOS_ENABLECARD and WDIOS_DISABLECARD of ioctl
+   interface. If a device has nowayout programmed, then that
+   can not be stopped. Therefore, it is recommended to read
+   state file to insure that whether watchdog device was
+   stopped or not after writing '0'.
+
+What:  /sys/class/watchdog/watchdogn/state
+Date:  August 2015
+Contact:   Pratyush Anand pan...@redhat.com
+Description:
+   It is a read only file. If it is read as '1' then a watchdog
+   device is active. If it is read as '0' then a watchdog
+   device is inactive.
+
+What:  /sys/class/watchdog/watchdogn/status
+Date:  August 2015
+Contact:   Pratyush Anand pan...@redhat.com
+Description:
+   It is a read only file. It contains watchdog device's
+   internal status bits. It is equivalent to WDIOC_GETSTATUS
+   of ioctl interface.
+
+What:  /sys/class/watchdog/watchdogn/timeleft
+Date:  August 2015
+Contact:   Pratyush Anand pan...@redhat.com
+Description:
+   It is a read only file. It contains value of time left for
+   reset generation. It is equivalent to WDIOC_GETTIMELEFT of
+   ioctl interface.
+
+What:  /sys/class/watchdog/watchdogn/timeout
+Date:  August 2015
+Contact:   Pratyush Anand pan...@redhat.com
+Description:
+   It is a read/write file. It is read to know about current
+   timeout and written to program a new timeout value. These
+   are equivalent to WDIOC_SETTIMEOUT and WDIOC_GETTIMEOUT of
+