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