xref: /linux/drivers/firmware/stratix10-rsu.c (revision 5b45759c0b58ade7c6a552fb58f2ce74ebaab053)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2018-2019, Intel Corporation
4  */
5 
6 #include <linux/arm-smccc.h>
7 #include <linux/bitfield.h>
8 #include <linux/completion.h>
9 #include <linux/kobject.h>
10 #include <linux/module.h>
11 #include <linux/mutex.h>
12 #include <linux/of.h>
13 #include <linux/platform_device.h>
14 #include <linux/firmware/intel/stratix10-svc-client.h>
15 #include <linux/string.h>
16 #include <linux/sysfs.h>
17 
18 #define RSU_STATE_MASK			GENMASK_ULL(31, 0)
19 #define RSU_VERSION_MASK		GENMASK_ULL(63, 32)
20 #define RSU_ERROR_LOCATION_MASK		GENMASK_ULL(31, 0)
21 #define RSU_ERROR_DETAIL_MASK		GENMASK_ULL(63, 32)
22 #define RSU_DCMF0_MASK			GENMASK_ULL(31, 0)
23 #define RSU_DCMF1_MASK			GENMASK_ULL(63, 32)
24 #define RSU_DCMF2_MASK			GENMASK_ULL(31, 0)
25 #define RSU_DCMF3_MASK			GENMASK_ULL(63, 32)
26 #define RSU_DCMF0_STATUS_MASK		GENMASK_ULL(15, 0)
27 #define RSU_DCMF1_STATUS_MASK		GENMASK_ULL(31, 16)
28 #define RSU_DCMF2_STATUS_MASK		GENMASK_ULL(47, 32)
29 #define RSU_DCMF3_STATUS_MASK		GENMASK_ULL(63, 48)
30 
31 #define RSU_TIMEOUT	(msecs_to_jiffies(SVC_RSU_REQUEST_TIMEOUT_MS))
32 
33 #define INVALID_RETRY_COUNTER		0xFF
34 #define INVALID_DCMF_VERSION		0xFF
35 #define INVALID_DCMF_STATUS		0xFFFFFFFF
36 
37 typedef void (*rsu_callback)(struct stratix10_svc_client *client,
38 			     struct stratix10_svc_cb_data *data);
39 /**
40  * struct stratix10_rsu_priv - rsu data structure
41  * @chan: pointer to the allocated service channel
42  * @client: active service client
43  * @completion: state for callback completion
44  * @lock: a mutex to protect callback completion state
45  * @status.current_image: address of image currently running in flash
46  * @status.fail_image: address of failed image in flash
47  * @status.version: the interface version number of RSU firmware
48  * @status.state: the state of RSU system
49  * @status.error_details: error code
50  * @status.error_location: the error offset inside the image that failed
51  * @dcmf_version.dcmf0: Quartus dcmf0 version
52  * @dcmf_version.dcmf1: Quartus dcmf1 version
53  * @dcmf_version.dcmf2: Quartus dcmf2 version
54  * @dcmf_version.dcmf3: Quartus dcmf3 version
55  * @dcmf_status.dcmf0: dcmf0 status
56  * @dcmf_status.dcmf1: dcmf1 status
57  * @dcmf_status.dcmf2: dcmf2 status
58  * @dcmf_status.dcmf3: dcmf3 status
59  * @retry_counter: the current image's retry counter
60  * @max_retry: the preset max retry value
61  */
62 struct stratix10_rsu_priv {
63 	struct stratix10_svc_chan *chan;
64 	struct stratix10_svc_client client;
65 	struct completion completion;
66 	struct mutex lock;
67 	struct {
68 		unsigned long current_image;
69 		unsigned long fail_image;
70 		unsigned int version;
71 		unsigned int state;
72 		unsigned int error_details;
73 		unsigned int error_location;
74 	} status;
75 
76 	struct {
77 		unsigned int dcmf0;
78 		unsigned int dcmf1;
79 		unsigned int dcmf2;
80 		unsigned int dcmf3;
81 	} dcmf_version;
82 
83 	struct {
84 		unsigned int dcmf0;
85 		unsigned int dcmf1;
86 		unsigned int dcmf2;
87 		unsigned int dcmf3;
88 	} dcmf_status;
89 
90 	unsigned int retry_counter;
91 	unsigned int max_retry;
92 };
93 
94 /**
95  * rsu_status_callback() - Status callback from Intel Service Layer
96  * @client: pointer to service client
97  * @data: pointer to callback data structure
98  *
99  * Callback from Intel service layer for RSU status request. Status is
100  * only updated after a system reboot, so a get updated status call is
101  * made during driver probe.
102  */
103 static void rsu_status_callback(struct stratix10_svc_client *client,
104 				struct stratix10_svc_cb_data *data)
105 {
106 	struct stratix10_rsu_priv *priv = client->priv;
107 	struct arm_smccc_res *res = (struct arm_smccc_res *)data->kaddr1;
108 
109 	if (data->status == BIT(SVC_STATUS_OK)) {
110 		priv->status.version = FIELD_GET(RSU_VERSION_MASK,
111 						 res->a2);
112 		priv->status.state = FIELD_GET(RSU_STATE_MASK, res->a2);
113 		priv->status.fail_image = res->a1;
114 		priv->status.current_image = res->a0;
115 		priv->status.error_location =
116 			FIELD_GET(RSU_ERROR_LOCATION_MASK, res->a3);
117 		priv->status.error_details =
118 			FIELD_GET(RSU_ERROR_DETAIL_MASK, res->a3);
119 	} else {
120 		dev_err(client->dev, "COMMAND_RSU_STATUS returned 0x%lX\n",
121 			res->a0);
122 		priv->status.version = 0;
123 		priv->status.state = 0;
124 		priv->status.fail_image = 0;
125 		priv->status.current_image = 0;
126 		priv->status.error_location = 0;
127 		priv->status.error_details = 0;
128 	}
129 
130 	complete(&priv->completion);
131 }
132 
133 /**
134  * rsu_command_callback() - Update callback from Intel Service Layer
135  * @client: pointer to client
136  * @data: pointer to callback data structure
137  *
138  * Callback from Intel service layer for RSU commands.
139  */
140 static void rsu_command_callback(struct stratix10_svc_client *client,
141 				 struct stratix10_svc_cb_data *data)
142 {
143 	struct stratix10_rsu_priv *priv = client->priv;
144 
145 	if (data->status == BIT(SVC_STATUS_NO_SUPPORT))
146 		dev_warn(client->dev, "Secure FW doesn't support notify\n");
147 	else if (data->status == BIT(SVC_STATUS_ERROR))
148 		dev_err(client->dev, "Failure, returned status is %lu\n",
149 			BIT(data->status));
150 
151 	complete(&priv->completion);
152 }
153 
154 /**
155  * rsu_retry_callback() - Callback from Intel service layer for getting
156  * the current image's retry counter from the firmware
157  * @client: pointer to client
158  * @data: pointer to callback data structure
159  *
160  * Callback from Intel service layer for retry counter, which is used by
161  * user to know how many times the images is still allowed to reload
162  * itself before giving up and starting RSU fail-over flow.
163  */
164 static void rsu_retry_callback(struct stratix10_svc_client *client,
165 			       struct stratix10_svc_cb_data *data)
166 {
167 	struct stratix10_rsu_priv *priv = client->priv;
168 	unsigned int *counter = (unsigned int *)data->kaddr1;
169 
170 	if (data->status == BIT(SVC_STATUS_OK))
171 		priv->retry_counter = *counter;
172 	else if (data->status == BIT(SVC_STATUS_NO_SUPPORT))
173 		dev_warn(client->dev, "Secure FW doesn't support retry\n");
174 	else
175 		dev_err(client->dev, "Failed to get retry counter %lu\n",
176 			BIT(data->status));
177 
178 	complete(&priv->completion);
179 }
180 
181 /**
182  * rsu_max_retry_callback() - Callback from Intel service layer for getting
183  * the max retry value from the firmware
184  * @client: pointer to client
185  * @data: pointer to callback data structure
186  *
187  * Callback from Intel service layer for max retry.
188  */
189 static void rsu_max_retry_callback(struct stratix10_svc_client *client,
190 				   struct stratix10_svc_cb_data *data)
191 {
192 	struct stratix10_rsu_priv *priv = client->priv;
193 	unsigned int *max_retry = (unsigned int *)data->kaddr1;
194 
195 	if (data->status == BIT(SVC_STATUS_OK))
196 		priv->max_retry = *max_retry;
197 	else if (data->status == BIT(SVC_STATUS_NO_SUPPORT))
198 		dev_warn(client->dev, "Secure FW doesn't support max retry\n");
199 	else
200 		dev_err(client->dev, "Failed to get max retry %lu\n",
201 			BIT(data->status));
202 
203 	complete(&priv->completion);
204 }
205 
206 /**
207  * rsu_dcmf_version_callback() - Callback from Intel service layer for getting
208  * the DCMF version
209  * @client: pointer to client
210  * @data: pointer to callback data structure
211  *
212  * Callback from Intel service layer for DCMF version number
213  */
214 static void rsu_dcmf_version_callback(struct stratix10_svc_client *client,
215 				      struct stratix10_svc_cb_data *data)
216 {
217 	struct stratix10_rsu_priv *priv = client->priv;
218 	unsigned long long *value1 = (unsigned long long *)data->kaddr1;
219 	unsigned long long *value2 = (unsigned long long *)data->kaddr2;
220 
221 	if (data->status == BIT(SVC_STATUS_OK)) {
222 		priv->dcmf_version.dcmf0 = FIELD_GET(RSU_DCMF0_MASK, *value1);
223 		priv->dcmf_version.dcmf1 = FIELD_GET(RSU_DCMF1_MASK, *value1);
224 		priv->dcmf_version.dcmf2 = FIELD_GET(RSU_DCMF2_MASK, *value2);
225 		priv->dcmf_version.dcmf3 = FIELD_GET(RSU_DCMF3_MASK, *value2);
226 	} else
227 		dev_err(client->dev, "failed to get DCMF version\n");
228 
229 	complete(&priv->completion);
230 }
231 
232 /**
233  * rsu_dcmf_status_callback() - Callback from Intel service layer for getting
234  * the DCMF status
235  * @client: pointer to client
236  * @data: pointer to callback data structure
237  *
238  * Callback from Intel service layer for DCMF status
239  */
240 static void rsu_dcmf_status_callback(struct stratix10_svc_client *client,
241 				     struct stratix10_svc_cb_data *data)
242 {
243 	struct stratix10_rsu_priv *priv = client->priv;
244 	unsigned long long *value = (unsigned long long *)data->kaddr1;
245 
246 	if (data->status == BIT(SVC_STATUS_OK)) {
247 		priv->dcmf_status.dcmf0 = FIELD_GET(RSU_DCMF0_STATUS_MASK,
248 						    *value);
249 		priv->dcmf_status.dcmf1 = FIELD_GET(RSU_DCMF1_STATUS_MASK,
250 						    *value);
251 		priv->dcmf_status.dcmf2 = FIELD_GET(RSU_DCMF2_STATUS_MASK,
252 						    *value);
253 		priv->dcmf_status.dcmf3 = FIELD_GET(RSU_DCMF3_STATUS_MASK,
254 						    *value);
255 	} else
256 		dev_err(client->dev, "failed to get DCMF status\n");
257 
258 	complete(&priv->completion);
259 }
260 
261 /**
262  * rsu_send_msg() - send a message to Intel service layer
263  * @priv: pointer to rsu private data
264  * @command: RSU status or update command
265  * @arg: the request argument, the bitstream address or notify status
266  * @callback: function pointer for the callback (status or update)
267  *
268  * Start an Intel service layer transaction to perform the SMC call that
269  * is necessary to get RSU boot log or set the address of bitstream to
270  * boot after reboot.
271  *
272  * Returns 0 on success or -ETIMEDOUT on error.
273  */
274 static int rsu_send_msg(struct stratix10_rsu_priv *priv,
275 			enum stratix10_svc_command_code command,
276 			unsigned long arg,
277 			rsu_callback callback)
278 {
279 	struct stratix10_svc_client_msg msg;
280 	int ret;
281 
282 	mutex_lock(&priv->lock);
283 	reinit_completion(&priv->completion);
284 	priv->client.receive_cb = callback;
285 
286 	msg.command = command;
287 	if (arg)
288 		msg.arg[0] = arg;
289 
290 	ret = stratix10_svc_send(priv->chan, &msg);
291 	if (ret < 0)
292 		goto status_done;
293 
294 	ret = wait_for_completion_interruptible_timeout(&priv->completion,
295 							RSU_TIMEOUT);
296 	if (!ret) {
297 		dev_err(priv->client.dev,
298 			"timeout waiting for SMC call\n");
299 		ret = -ETIMEDOUT;
300 		goto status_done;
301 	} else if (ret < 0) {
302 		dev_err(priv->client.dev,
303 			"error %d waiting for SMC call\n", ret);
304 		goto status_done;
305 	} else {
306 		ret = 0;
307 	}
308 
309 status_done:
310 	stratix10_svc_done(priv->chan);
311 	mutex_unlock(&priv->lock);
312 	return ret;
313 }
314 
315 /*
316  * This driver exposes some optional features of the Intel Stratix 10 SoC FPGA.
317  * The sysfs interfaces exposed here are FPGA Remote System Update (RSU)
318  * related. They allow user space software to query the configuration system
319  * status and to request optional reboot behavior specific to Intel FPGAs.
320  */
321 
322 static ssize_t current_image_show(struct device *dev,
323 				  struct device_attribute *attr, char *buf)
324 {
325 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
326 
327 	if (!priv)
328 		return -ENODEV;
329 
330 	return sprintf(buf, "0x%08lx\n", priv->status.current_image);
331 }
332 
333 static ssize_t fail_image_show(struct device *dev,
334 			       struct device_attribute *attr, char *buf)
335 {
336 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
337 
338 	if (!priv)
339 		return -ENODEV;
340 
341 	return sprintf(buf, "0x%08lx\n", priv->status.fail_image);
342 }
343 
344 static ssize_t version_show(struct device *dev, struct device_attribute *attr,
345 			    char *buf)
346 {
347 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
348 
349 	if (!priv)
350 		return -ENODEV;
351 
352 	return sprintf(buf, "0x%08x\n", priv->status.version);
353 }
354 
355 static ssize_t state_show(struct device *dev, struct device_attribute *attr,
356 			  char *buf)
357 {
358 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
359 
360 	if (!priv)
361 		return -ENODEV;
362 
363 	return sprintf(buf, "0x%08x\n", priv->status.state);
364 }
365 
366 static ssize_t error_location_show(struct device *dev,
367 				   struct device_attribute *attr, char *buf)
368 {
369 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
370 
371 	if (!priv)
372 		return -ENODEV;
373 
374 	return sprintf(buf, "0x%08x\n", priv->status.error_location);
375 }
376 
377 static ssize_t error_details_show(struct device *dev,
378 				  struct device_attribute *attr, char *buf)
379 {
380 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
381 
382 	if (!priv)
383 		return -ENODEV;
384 
385 	return sprintf(buf, "0x%08x\n", priv->status.error_details);
386 }
387 
388 static ssize_t retry_counter_show(struct device *dev,
389 				  struct device_attribute *attr, char *buf)
390 {
391 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
392 
393 	if (!priv)
394 		return -ENODEV;
395 
396 	return sprintf(buf, "0x%08x\n", priv->retry_counter);
397 }
398 
399 static ssize_t max_retry_show(struct device *dev,
400 			      struct device_attribute *attr, char *buf)
401 {
402 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
403 
404 	if (!priv)
405 		return -ENODEV;
406 
407 	return scnprintf(buf, sizeof(priv->max_retry),
408 			 "0x%08x\n", priv->max_retry);
409 }
410 
411 static ssize_t dcmf0_show(struct device *dev,
412 			  struct device_attribute *attr, char *buf)
413 {
414 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
415 
416 	if (!priv)
417 		return -ENODEV;
418 
419 	return sprintf(buf, "0x%08x\n", priv->dcmf_version.dcmf0);
420 }
421 
422 static ssize_t dcmf1_show(struct device *dev,
423 			  struct device_attribute *attr, char *buf)
424 {
425 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
426 
427 	if (!priv)
428 		return -ENODEV;
429 
430 	return sprintf(buf, "0x%08x\n", priv->dcmf_version.dcmf1);
431 }
432 
433 static ssize_t dcmf2_show(struct device *dev,
434 			  struct device_attribute *attr, char *buf)
435 {
436 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
437 
438 	if (!priv)
439 		return -ENODEV;
440 
441 	return sprintf(buf, "0x%08x\n", priv->dcmf_version.dcmf2);
442 }
443 
444 static ssize_t dcmf3_show(struct device *dev,
445 			  struct device_attribute *attr, char *buf)
446 {
447 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
448 
449 	if (!priv)
450 		return -ENODEV;
451 
452 	return sprintf(buf, "0x%08x\n", priv->dcmf_version.dcmf3);
453 }
454 
455 static ssize_t dcmf0_status_show(struct device *dev,
456 				 struct device_attribute *attr, char *buf)
457 {
458 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
459 
460 	if (!priv)
461 		return -ENODEV;
462 
463 	if (priv->dcmf_status.dcmf0 == INVALID_DCMF_STATUS)
464 		return -EIO;
465 
466 	return sprintf(buf, "0x%08x\n", priv->dcmf_status.dcmf0);
467 }
468 
469 static ssize_t dcmf1_status_show(struct device *dev,
470 				 struct device_attribute *attr, char *buf)
471 {
472 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
473 
474 	if (!priv)
475 		return -ENODEV;
476 
477 	if (priv->dcmf_status.dcmf1 == INVALID_DCMF_STATUS)
478 		return -EIO;
479 
480 	return sprintf(buf, "0x%08x\n", priv->dcmf_status.dcmf1);
481 }
482 
483 static ssize_t dcmf2_status_show(struct device *dev,
484 				struct device_attribute *attr, char *buf)
485 {
486 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
487 
488 	if (!priv)
489 		return -ENODEV;
490 
491 	if (priv->dcmf_status.dcmf2 == INVALID_DCMF_STATUS)
492 		return -EIO;
493 
494 	return sprintf(buf, "0x%08x\n", priv->dcmf_status.dcmf2);
495 }
496 
497 static ssize_t dcmf3_status_show(struct device *dev,
498 				 struct device_attribute *attr, char *buf)
499 {
500 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
501 
502 	if (!priv)
503 		return -ENODEV;
504 
505 	if (priv->dcmf_status.dcmf3 == INVALID_DCMF_STATUS)
506 		return -EIO;
507 
508 	return sprintf(buf, "0x%08x\n", priv->dcmf_status.dcmf3);
509 }
510 static ssize_t reboot_image_store(struct device *dev,
511 				  struct device_attribute *attr,
512 				  const char *buf, size_t count)
513 {
514 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
515 	unsigned long address;
516 	int ret;
517 
518 	if (!priv)
519 		return -ENODEV;
520 
521 	ret = kstrtoul(buf, 0, &address);
522 	if (ret)
523 		return ret;
524 
525 	ret = rsu_send_msg(priv, COMMAND_RSU_UPDATE,
526 			   address, rsu_command_callback);
527 	if (ret) {
528 		dev_err(dev, "Error, RSU update returned %i\n", ret);
529 		return ret;
530 	}
531 
532 	return count;
533 }
534 
535 static ssize_t notify_store(struct device *dev,
536 			    struct device_attribute *attr,
537 			    const char *buf, size_t count)
538 {
539 	struct stratix10_rsu_priv *priv = dev_get_drvdata(dev);
540 	unsigned long status;
541 	int ret;
542 
543 	if (!priv)
544 		return -ENODEV;
545 
546 	ret = kstrtoul(buf, 0, &status);
547 	if (ret)
548 		return ret;
549 
550 	ret = rsu_send_msg(priv, COMMAND_RSU_NOTIFY,
551 			   status, rsu_command_callback);
552 	if (ret) {
553 		dev_err(dev, "Error, RSU notify returned %i\n", ret);
554 		return ret;
555 	}
556 
557 	/* to get the updated state */
558 	ret = rsu_send_msg(priv, COMMAND_RSU_STATUS,
559 			   0, rsu_status_callback);
560 	if (ret) {
561 		dev_err(dev, "Error, getting RSU status %i\n", ret);
562 		return ret;
563 	}
564 
565 	ret = rsu_send_msg(priv, COMMAND_RSU_RETRY, 0, rsu_retry_callback);
566 	if (ret) {
567 		dev_err(dev, "Error, getting RSU retry %i\n", ret);
568 		return ret;
569 	}
570 
571 	return count;
572 }
573 
574 static DEVICE_ATTR_RO(current_image);
575 static DEVICE_ATTR_RO(fail_image);
576 static DEVICE_ATTR_RO(state);
577 static DEVICE_ATTR_RO(version);
578 static DEVICE_ATTR_RO(error_location);
579 static DEVICE_ATTR_RO(error_details);
580 static DEVICE_ATTR_RO(retry_counter);
581 static DEVICE_ATTR_RO(max_retry);
582 static DEVICE_ATTR_RO(dcmf0);
583 static DEVICE_ATTR_RO(dcmf1);
584 static DEVICE_ATTR_RO(dcmf2);
585 static DEVICE_ATTR_RO(dcmf3);
586 static DEVICE_ATTR_RO(dcmf0_status);
587 static DEVICE_ATTR_RO(dcmf1_status);
588 static DEVICE_ATTR_RO(dcmf2_status);
589 static DEVICE_ATTR_RO(dcmf3_status);
590 static DEVICE_ATTR_WO(reboot_image);
591 static DEVICE_ATTR_WO(notify);
592 
593 static struct attribute *rsu_attrs[] = {
594 	&dev_attr_current_image.attr,
595 	&dev_attr_fail_image.attr,
596 	&dev_attr_state.attr,
597 	&dev_attr_version.attr,
598 	&dev_attr_error_location.attr,
599 	&dev_attr_error_details.attr,
600 	&dev_attr_retry_counter.attr,
601 	&dev_attr_max_retry.attr,
602 	&dev_attr_dcmf0.attr,
603 	&dev_attr_dcmf1.attr,
604 	&dev_attr_dcmf2.attr,
605 	&dev_attr_dcmf3.attr,
606 	&dev_attr_dcmf0_status.attr,
607 	&dev_attr_dcmf1_status.attr,
608 	&dev_attr_dcmf2_status.attr,
609 	&dev_attr_dcmf3_status.attr,
610 	&dev_attr_reboot_image.attr,
611 	&dev_attr_notify.attr,
612 	NULL
613 };
614 
615 ATTRIBUTE_GROUPS(rsu);
616 
617 static int stratix10_rsu_probe(struct platform_device *pdev)
618 {
619 	struct device *dev = &pdev->dev;
620 	struct stratix10_rsu_priv *priv;
621 	int ret;
622 
623 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
624 	if (!priv)
625 		return -ENOMEM;
626 
627 	priv->client.dev = dev;
628 	priv->client.receive_cb = NULL;
629 	priv->client.priv = priv;
630 	priv->status.current_image = 0;
631 	priv->status.fail_image = 0;
632 	priv->status.error_location = 0;
633 	priv->status.error_details = 0;
634 	priv->status.version = 0;
635 	priv->status.state = 0;
636 	priv->retry_counter = INVALID_RETRY_COUNTER;
637 	priv->dcmf_version.dcmf0 = INVALID_DCMF_VERSION;
638 	priv->dcmf_version.dcmf1 = INVALID_DCMF_VERSION;
639 	priv->dcmf_version.dcmf2 = INVALID_DCMF_VERSION;
640 	priv->dcmf_version.dcmf3 = INVALID_DCMF_VERSION;
641 	priv->max_retry = INVALID_RETRY_COUNTER;
642 	priv->dcmf_status.dcmf0 = INVALID_DCMF_STATUS;
643 	priv->dcmf_status.dcmf1 = INVALID_DCMF_STATUS;
644 	priv->dcmf_status.dcmf2 = INVALID_DCMF_STATUS;
645 	priv->dcmf_status.dcmf3 = INVALID_DCMF_STATUS;
646 
647 	mutex_init(&priv->lock);
648 	priv->chan = stratix10_svc_request_channel_byname(&priv->client,
649 							  SVC_CLIENT_RSU);
650 	if (IS_ERR(priv->chan)) {
651 		dev_err(dev, "couldn't get service channel %s\n",
652 			SVC_CLIENT_RSU);
653 		return PTR_ERR(priv->chan);
654 	}
655 
656 	init_completion(&priv->completion);
657 	platform_set_drvdata(pdev, priv);
658 
659 	/* get the initial state from firmware */
660 	ret = rsu_send_msg(priv, COMMAND_RSU_STATUS,
661 			   0, rsu_status_callback);
662 	if (ret) {
663 		dev_err(dev, "Error, getting RSU status %i\n", ret);
664 		stratix10_svc_free_channel(priv->chan);
665 	}
666 
667 	/* get DCMF version from firmware */
668 	ret = rsu_send_msg(priv, COMMAND_RSU_DCMF_VERSION,
669 			   0, rsu_dcmf_version_callback);
670 	if (ret) {
671 		dev_err(dev, "Error, getting DCMF version %i\n", ret);
672 		stratix10_svc_free_channel(priv->chan);
673 	}
674 
675 	ret = rsu_send_msg(priv, COMMAND_RSU_DCMF_STATUS,
676 			   0, rsu_dcmf_status_callback);
677 	if (ret) {
678 		dev_err(dev, "Error, getting DCMF status %i\n", ret);
679 		stratix10_svc_free_channel(priv->chan);
680 	}
681 
682 	ret = rsu_send_msg(priv, COMMAND_RSU_RETRY, 0, rsu_retry_callback);
683 	if (ret) {
684 		dev_err(dev, "Error, getting RSU retry %i\n", ret);
685 		stratix10_svc_free_channel(priv->chan);
686 	}
687 
688 	ret = rsu_send_msg(priv, COMMAND_RSU_MAX_RETRY, 0,
689 			   rsu_max_retry_callback);
690 	if (ret) {
691 		dev_err(dev, "Error, getting RSU max retry %i\n", ret);
692 		stratix10_svc_free_channel(priv->chan);
693 	}
694 
695 	return ret;
696 }
697 
698 static int stratix10_rsu_remove(struct platform_device *pdev)
699 {
700 	struct stratix10_rsu_priv *priv = platform_get_drvdata(pdev);
701 
702 	stratix10_svc_free_channel(priv->chan);
703 	return 0;
704 }
705 
706 static struct platform_driver stratix10_rsu_driver = {
707 	.probe = stratix10_rsu_probe,
708 	.remove = stratix10_rsu_remove,
709 	.driver = {
710 		.name = "stratix10-rsu",
711 		.dev_groups = rsu_groups,
712 	},
713 };
714 
715 module_platform_driver(stratix10_rsu_driver);
716 
717 MODULE_LICENSE("GPL v2");
718 MODULE_DESCRIPTION("Intel Remote System Update Driver");
719 MODULE_AUTHOR("Richard Gong <richard.gong@intel.com>");
720