io_uring: ensure finish_wait() is always called in __io_uring_task_cancel()
[linux/fpc-iii.git] / drivers / rpmsg / qcom_glink_ssr.c
blobdcd1ce61697473dae35a1c97f3d99212b5560636
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
4 * Copyright (c) 2017, Linaro Ltd.
5 */
7 #include <linux/completion.h>
8 #include <linux/module.h>
9 #include <linux/notifier.h>
10 #include <linux/rpmsg.h>
11 #include <linux/remoteproc/qcom_rproc.h>
13 /**
14 * struct do_cleanup_msg - The data structure for an SSR do_cleanup message
15 * version: The G-Link SSR protocol version
16 * command: The G-Link SSR command - do_cleanup
17 * seq_num: Sequence number
18 * name_len: Length of the name of the subsystem being restarted
19 * name: G-Link edge name of the subsystem being restarted
21 struct do_cleanup_msg {
22 __le32 version;
23 __le32 command;
24 __le32 seq_num;
25 __le32 name_len;
26 char name[32];
29 /**
30 * struct cleanup_done_msg - The data structure for an SSR cleanup_done message
31 * version: The G-Link SSR protocol version
32 * response: The G-Link SSR response to a do_cleanup command, cleanup_done
33 * seq_num: Sequence number
35 struct cleanup_done_msg {
36 __le32 version;
37 __le32 response;
38 __le32 seq_num;
41 /**
42 * G-Link SSR protocol commands
44 #define GLINK_SSR_DO_CLEANUP 0
45 #define GLINK_SSR_CLEANUP_DONE 1
47 struct glink_ssr {
48 struct device *dev;
49 struct rpmsg_endpoint *ept;
51 struct notifier_block nb;
53 u32 seq_num;
54 struct completion completion;
57 /* Notifier list for all registered glink_ssr instances */
58 static BLOCKING_NOTIFIER_HEAD(ssr_notifiers);
60 /**
61 * qcom_glink_ssr_notify() - notify GLINK SSR about stopped remoteproc
62 * @ssr_name: name of the remoteproc that has been stopped
64 void qcom_glink_ssr_notify(const char *ssr_name)
66 blocking_notifier_call_chain(&ssr_notifiers, 0, (void *)ssr_name);
68 EXPORT_SYMBOL_GPL(qcom_glink_ssr_notify);
70 static int qcom_glink_ssr_callback(struct rpmsg_device *rpdev,
71 void *data, int len, void *priv, u32 addr)
73 struct cleanup_done_msg *msg = data;
74 struct glink_ssr *ssr = dev_get_drvdata(&rpdev->dev);
76 if (len < sizeof(*msg)) {
77 dev_err(ssr->dev, "message too short\n");
78 return -EINVAL;
81 if (le32_to_cpu(msg->version) != 0)
82 return -EINVAL;
84 if (le32_to_cpu(msg->response) != GLINK_SSR_CLEANUP_DONE)
85 return 0;
87 if (le32_to_cpu(msg->seq_num) != ssr->seq_num) {
88 dev_err(ssr->dev, "invalid sequence number of response\n");
89 return -EINVAL;
92 complete(&ssr->completion);
94 return 0;
97 static int qcom_glink_ssr_notifier_call(struct notifier_block *nb,
98 unsigned long event,
99 void *data)
101 struct glink_ssr *ssr = container_of(nb, struct glink_ssr, nb);
102 struct do_cleanup_msg msg;
103 char *ssr_name = data;
104 int ret;
106 ssr->seq_num++;
107 reinit_completion(&ssr->completion);
109 memset(&msg, 0, sizeof(msg));
110 msg.command = cpu_to_le32(GLINK_SSR_DO_CLEANUP);
111 msg.seq_num = cpu_to_le32(ssr->seq_num);
112 msg.name_len = cpu_to_le32(strlen(ssr_name));
113 strlcpy(msg.name, ssr_name, sizeof(msg.name));
115 ret = rpmsg_send(ssr->ept, &msg, sizeof(msg));
116 if (ret < 0)
117 dev_err(ssr->dev, "failed to send cleanup message\n");
119 ret = wait_for_completion_timeout(&ssr->completion, HZ);
120 if (!ret)
121 dev_err(ssr->dev, "timeout waiting for cleanup done message\n");
123 return NOTIFY_DONE;
126 static int qcom_glink_ssr_probe(struct rpmsg_device *rpdev)
128 struct glink_ssr *ssr;
130 ssr = devm_kzalloc(&rpdev->dev, sizeof(*ssr), GFP_KERNEL);
131 if (!ssr)
132 return -ENOMEM;
134 init_completion(&ssr->completion);
136 ssr->dev = &rpdev->dev;
137 ssr->ept = rpdev->ept;
138 ssr->nb.notifier_call = qcom_glink_ssr_notifier_call;
140 dev_set_drvdata(&rpdev->dev, ssr);
142 return blocking_notifier_chain_register(&ssr_notifiers, &ssr->nb);
145 static void qcom_glink_ssr_remove(struct rpmsg_device *rpdev)
147 struct glink_ssr *ssr = dev_get_drvdata(&rpdev->dev);
149 blocking_notifier_chain_unregister(&ssr_notifiers, &ssr->nb);
152 static const struct rpmsg_device_id qcom_glink_ssr_match[] = {
153 { "glink_ssr" },
157 static struct rpmsg_driver qcom_glink_ssr_driver = {
158 .probe = qcom_glink_ssr_probe,
159 .remove = qcom_glink_ssr_remove,
160 .callback = qcom_glink_ssr_callback,
161 .id_table = qcom_glink_ssr_match,
162 .drv = {
163 .name = "qcom_glink_ssr",
166 module_rpmsg_driver(qcom_glink_ssr_driver);