stratix10-rsu.c 20 KB

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