2 * SVC Greybus "watchdog" driver.
4 * Copyright 2016 Google Inc.
6 * Released under the GPLv2 only.
9 #include <linux/delay.h>
10 #include <linux/workqueue.h>
13 #define SVC_WATCHDOG_PERIOD (2*HZ)
15 struct gb_svc_watchdog {
16 struct delayed_work work;
21 static struct delayed_work reset_work;
23 static void greybus_reset(struct work_struct *work)
25 static char start_path[256] = "/system/bin/start";
26 static char *envp[] = {
28 "PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin",
31 static char *argv[] = {
37 printk(KERN_ERR "svc_watchdog: calling \"%s %s\" to reset greybus network!\n",
39 call_usermodehelper(start_path, argv, envp, UMH_WAIT_EXEC);
42 static void do_work(struct work_struct *work)
44 struct gb_svc_watchdog *watchdog;
48 watchdog = container_of(work, struct gb_svc_watchdog, work.work);
51 dev_dbg(&svc->dev, "%s: ping.\n", __func__);
52 retval = gb_svc_ping(svc);
55 * Something went really wrong, let's warn userspace and then
56 * pull the plug and reset the whole greybus network.
57 * We need to do this outside of this workqueue as we will be
58 * tearing down the svc device itself. So queue up
59 * yet-another-callback to do that.
62 "SVC ping has returned %d, something is wrong!!!\n",
64 dev_err(&svc->dev, "Resetting the greybus network, watch out!!!\n");
66 INIT_DELAYED_WORK(&reset_work, greybus_reset);
67 queue_delayed_work(system_wq, &reset_work, HZ/2);
71 /* resubmit our work to happen again, if we are still "alive" */
72 if (!watchdog->finished)
73 queue_delayed_work(system_wq, &watchdog->work,
77 int gb_svc_watchdog_create(struct gb_svc *svc)
79 struct gb_svc_watchdog *watchdog;
84 watchdog = kmalloc(sizeof(*watchdog), GFP_KERNEL);
88 watchdog->finished = false;
90 INIT_DELAYED_WORK(&watchdog->work, do_work);
91 svc->watchdog = watchdog;
93 queue_delayed_work(system_wq, &watchdog->work,
98 void gb_svc_watchdog_destroy(struct gb_svc *svc)
100 struct gb_svc_watchdog *watchdog = svc->watchdog;
105 watchdog->finished = true;
106 cancel_delayed_work_sync(&watchdog->work);
107 svc->watchdog = NULL;