Skip to content

Commit cf580ad

Browse files
sgruszkarafaeljw
authored andcommitted
thermal: netlink: Add genetlink bind/unbind notifications
Introduce a new feature to the thermal netlink framework, enabling the registration of sub drivers to receive events via a notifier mechanism. Specifically, implement genetlink family bind and unbind callbacks to send BIND and UNBIND events. The primary purpose of this enhancement is to facilitate the tracking of user-space consumers by the Intel HFI driver. By leveraging these notifications, the driver can determine when consumers are present or absent. Suggested-by: Jakub Kicinski <[email protected]> Signed-off-by: Stanislaw Gruszka <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent f67cf45 commit cf580ad

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

drivers/thermal/thermal_netlink.c

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,13 @@
77
* Generic netlink for thermal management framework
88
*/
99
#include <linux/module.h>
10+
#include <linux/notifier.h>
1011
#include <linux/kernel.h>
1112
#include <net/genetlink.h>
1213
#include <uapi/linux/thermal.h>
1314

1415
#include "thermal_core.h"
1516

16-
enum thermal_genl_multicast_groups {
17-
THERMAL_GENL_SAMPLING_GROUP = 0,
18-
THERMAL_GENL_EVENT_GROUP = 1,
19-
};
20-
2117
static const struct genl_multicast_group thermal_genl_mcgrps[] = {
2218
[THERMAL_GENL_SAMPLING_GROUP] = { .name = THERMAL_GENL_SAMPLING_GROUP_NAME, },
2319
[THERMAL_GENL_EVENT_GROUP] = { .name = THERMAL_GENL_EVENT_GROUP_NAME, },
@@ -75,6 +71,7 @@ struct param {
7571
typedef int (*cb_t)(struct param *);
7672

7773
static struct genl_family thermal_gnl_family;
74+
static BLOCKING_NOTIFIER_HEAD(thermal_genl_chain);
7875

7976
static int thermal_group_has_listeners(enum thermal_genl_multicast_groups group)
8077
{
@@ -645,6 +642,27 @@ static int thermal_genl_cmd_doit(struct sk_buff *skb,
645642
return ret;
646643
}
647644

645+
static int thermal_genl_bind(int mcgrp)
646+
{
647+
struct thermal_genl_notify n = { .mcgrp = mcgrp };
648+
649+
if (WARN_ON_ONCE(mcgrp > THERMAL_GENL_MAX_GROUP))
650+
return -EINVAL;
651+
652+
blocking_notifier_call_chain(&thermal_genl_chain, THERMAL_NOTIFY_BIND, &n);
653+
return 0;
654+
}
655+
656+
static void thermal_genl_unbind(int mcgrp)
657+
{
658+
struct thermal_genl_notify n = { .mcgrp = mcgrp };
659+
660+
if (WARN_ON_ONCE(mcgrp > THERMAL_GENL_MAX_GROUP))
661+
return;
662+
663+
blocking_notifier_call_chain(&thermal_genl_chain, THERMAL_NOTIFY_UNBIND, &n);
664+
}
665+
648666
static const struct genl_small_ops thermal_genl_ops[] = {
649667
{
650668
.cmd = THERMAL_GENL_CMD_TZ_GET_ID,
@@ -679,13 +697,25 @@ static struct genl_family thermal_gnl_family __ro_after_init = {
679697
.version = THERMAL_GENL_VERSION,
680698
.maxattr = THERMAL_GENL_ATTR_MAX,
681699
.policy = thermal_genl_policy,
700+
.bind = thermal_genl_bind,
701+
.unbind = thermal_genl_unbind,
682702
.small_ops = thermal_genl_ops,
683703
.n_small_ops = ARRAY_SIZE(thermal_genl_ops),
684704
.resv_start_op = THERMAL_GENL_CMD_CDEV_GET + 1,
685705
.mcgrps = thermal_genl_mcgrps,
686706
.n_mcgrps = ARRAY_SIZE(thermal_genl_mcgrps),
687707
};
688708

709+
int thermal_genl_register_notifier(struct notifier_block *nb)
710+
{
711+
return blocking_notifier_chain_register(&thermal_genl_chain, nb);
712+
}
713+
714+
int thermal_genl_unregister_notifier(struct notifier_block *nb)
715+
{
716+
return blocking_notifier_chain_unregister(&thermal_genl_chain, nb);
717+
}
718+
689719
int __init thermal_netlink_init(void)
690720
{
691721
return genl_register_family(&thermal_gnl_family);

drivers/thermal/thermal_netlink.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ struct thermal_genl_cpu_caps {
1010
int efficiency;
1111
};
1212

13+
enum thermal_genl_multicast_groups {
14+
THERMAL_GENL_SAMPLING_GROUP = 0,
15+
THERMAL_GENL_EVENT_GROUP = 1,
16+
THERMAL_GENL_MAX_GROUP = THERMAL_GENL_EVENT_GROUP,
17+
};
18+
19+
#define THERMAL_NOTIFY_BIND 0
20+
#define THERMAL_NOTIFY_UNBIND 1
21+
22+
struct thermal_genl_notify {
23+
int mcgrp;
24+
};
25+
1326
struct thermal_zone_device;
1427
struct thermal_trip;
1528
struct thermal_cooling_device;
@@ -18,6 +31,9 @@ struct thermal_cooling_device;
1831
#ifdef CONFIG_THERMAL_NETLINK
1932
int __init thermal_netlink_init(void);
2033
void __init thermal_netlink_exit(void);
34+
int thermal_genl_register_notifier(struct notifier_block *nb);
35+
int thermal_genl_unregister_notifier(struct notifier_block *nb);
36+
2137
int thermal_notify_tz_create(const struct thermal_zone_device *tz);
2238
int thermal_notify_tz_delete(const struct thermal_zone_device *tz);
2339
int thermal_notify_tz_enable(const struct thermal_zone_device *tz);
@@ -48,6 +64,16 @@ static inline int thermal_notify_tz_create(const struct thermal_zone_device *tz)
4864
return 0;
4965
}
5066

67+
static inline int thermal_genl_register_notifier(struct notifier_block *nb)
68+
{
69+
return 0;
70+
}
71+
72+
static inline int thermal_genl_unregister_notifier(struct notifier_block *nb)
73+
{
74+
return 0;
75+
}
76+
5177
static inline int thermal_notify_tz_delete(const struct thermal_zone_device *tz)
5278
{
5379
return 0;

0 commit comments

Comments
 (0)