cfg802154: add PM hooks
authorVarka Bhadram <varkabhadram@gmail.com>
Wed, 24 Jun 2015 09:36:35 +0000 (11:36 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 23 Jul 2015 15:10:49 +0000 (17:10 +0200)
This patch help to implement suspend/resume in mac802154, these
hooks will be run before the device is suspended and after it
resumes.

Signed-off-by: Varka Bhadram <varkab@cdac.in>
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
include/net/cfg802154.h
net/ieee802154/rdev-ops.h
net/ieee802154/sysfs.c
net/ieee802154/trace.h

index 290a9a69af0788794619b0ededc4a6ccfbab5e07..382f94b59f2f706eab23f2f6ebe9c2f007c5ed2e 100644 (file)
@@ -34,6 +34,8 @@ struct cfg802154_ops {
                                                           int type);
        void    (*del_virtual_intf_deprecated)(struct wpan_phy *wpan_phy,
                                               struct net_device *dev);
+       int     (*suspend)(struct wpan_phy *wpan_phy);
+       int     (*resume)(struct wpan_phy *wpan_phy);
        int     (*add_virtual_intf)(struct wpan_phy *wpan_phy,
                                    const char *name,
                                    unsigned char name_assign_type,
index b2155a123f6c88980c180eeb7b4ffdcf68bea4fb..8d5960a37195136380032644b65a8b741a03ab00 100644 (file)
@@ -23,6 +23,26 @@ rdev_del_virtual_intf_deprecated(struct cfg802154_registered_device *rdev,
        rdev->ops->del_virtual_intf_deprecated(&rdev->wpan_phy, dev);
 }
 
+static inline int
+rdev_suspend(struct cfg802154_registered_device *rdev)
+{
+       int ret;
+       trace_802154_rdev_suspend(&rdev->wpan_phy);
+       ret = rdev->ops->suspend(&rdev->wpan_phy);
+       trace_802154_rdev_return_int(&rdev->wpan_phy, ret);
+       return ret;
+}
+
+static inline int
+rdev_resume(struct cfg802154_registered_device *rdev)
+{
+       int ret;
+       trace_802154_rdev_resume(&rdev->wpan_phy);
+       ret = rdev->ops->resume(&rdev->wpan_phy);
+       trace_802154_rdev_return_int(&rdev->wpan_phy, ret);
+       return ret;
+}
+
 static inline int
 rdev_add_virtual_intf(struct cfg802154_registered_device *rdev, char *name,
                      unsigned char name_assign_type,
index 133b4280660cfc2f9b651a56a95502991e21840b..bd88525b041e79c62a0458c499968315c5a56e4e 100644 (file)
  */
 
 #include <linux/device.h>
+#include <linux/rtnetlink.h>
 
 #include <net/cfg802154.h>
 
 #include "core.h"
 #include "sysfs.h"
+#include "rdev-ops.h"
 
 static inline struct cfg802154_registered_device *
 dev_to_rdev(struct device *dev)
@@ -62,10 +64,46 @@ static struct attribute *pmib_attrs[] = {
 };
 ATTRIBUTE_GROUPS(pmib);
 
+#ifdef CONFIG_PM_SLEEP
+static int wpan_phy_suspend(struct device *dev)
+{
+       struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
+       int ret = 0;
+
+       if (rdev->ops->suspend) {
+               rtnl_lock();
+               ret = rdev_suspend(rdev);
+               rtnl_unlock();
+       }
+
+       return ret;
+}
+
+static int wpan_phy_resume(struct device *dev)
+{
+       struct cfg802154_registered_device *rdev = dev_to_rdev(dev);
+       int ret = 0;
+
+       if (rdev->ops->resume) {
+               rtnl_lock();
+               ret = rdev_resume(rdev);
+               rtnl_unlock();
+       }
+
+       return ret;
+}
+
+static SIMPLE_DEV_PM_OPS(wpan_phy_pm_ops, wpan_phy_suspend, wpan_phy_resume);
+#define WPAN_PHY_PM_OPS (&wpan_phy_pm_ops)
+#else
+#define WPAN_PHY_PM_OPS NULL
+#endif
+
 struct class wpan_phy_class = {
        .name = "ieee802154",
        .dev_release = wpan_phy_release,
        .dev_groups = pmib_groups,
+       .pm = WPAN_PHY_PM_OPS,
 };
 
 int wpan_phy_sysfs_init(void)
index 9b5f0eb366969c0c968935389b97ad0893b41cf1..4399b7fbaa31481c402079680e3509ed05fb9479 100644 (file)
  *                     rdev->ops traces                     *
  *************************************************************/
 
+DECLARE_EVENT_CLASS(wpan_phy_only_evt,
+       TP_PROTO(struct wpan_phy *wpan_phy),
+       TP_ARGS(wpan_phy),
+       TP_STRUCT__entry(
+               WPAN_PHY_ENTRY
+       ),
+       TP_fast_assign(
+               WPAN_PHY_ASSIGN;
+       ),
+       TP_printk(WPAN_PHY_PR_FMT, WPAN_PHY_PR_ARG)
+);
+
+DEFINE_EVENT(wpan_phy_only_evt, 802154_rdev_suspend,
+       TP_PROTO(struct wpan_phy *wpan_phy),
+       TP_ARGS(wpan_phy)
+);
+
+DEFINE_EVENT(wpan_phy_only_evt, 802154_rdev_resume,
+       TP_PROTO(struct wpan_phy *wpan_phy),
+       TP_ARGS(wpan_phy)
+);
+
 TRACE_EVENT(802154_rdev_add_virtual_intf,
        TP_PROTO(struct wpan_phy *wpan_phy, char *name,
                 enum nl802154_iftype type, __le64 extended_addr),