dprc.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
  2. /*
  3. * Copyright 2013-2016 Freescale Semiconductor Inc.
  4. * Copyright 2020 NXP
  5. *
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/fsl/mc.h>
  9. #include "fsl-mc-private.h"
  10. /*
  11. * cache the DPRC version to reduce the number of commands
  12. * towards the mc firmware
  13. */
  14. static u16 dprc_major_ver;
  15. static u16 dprc_minor_ver;
  16. /**
  17. * dprc_open() - Open DPRC object for use
  18. * @mc_io: Pointer to MC portal's I/O object
  19. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  20. * @container_id: Container ID to open
  21. * @token: Returned token of DPRC object
  22. *
  23. * Return: '0' on Success; Error code otherwise.
  24. *
  25. * @warning Required before any operation on the object.
  26. */
  27. int dprc_open(struct fsl_mc_io *mc_io,
  28. u32 cmd_flags,
  29. int container_id,
  30. u16 *token)
  31. {
  32. struct fsl_mc_command cmd = { 0 };
  33. struct dprc_cmd_open *cmd_params;
  34. int err;
  35. /* prepare command */
  36. cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
  37. 0);
  38. cmd_params = (struct dprc_cmd_open *)cmd.params;
  39. cmd_params->container_id = cpu_to_le32(container_id);
  40. /* send command to mc*/
  41. err = mc_send_command(mc_io, &cmd);
  42. if (err)
  43. return err;
  44. /* retrieve response parameters */
  45. *token = mc_cmd_hdr_read_token(&cmd);
  46. return 0;
  47. }
  48. EXPORT_SYMBOL_GPL(dprc_open);
  49. /**
  50. * dprc_close() - Close the control session of the object
  51. * @mc_io: Pointer to MC portal's I/O object
  52. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  53. * @token: Token of DPRC object
  54. *
  55. * After this function is called, no further operations are
  56. * allowed on the object without opening a new control session.
  57. *
  58. * Return: '0' on Success; Error code otherwise.
  59. */
  60. int dprc_close(struct fsl_mc_io *mc_io,
  61. u32 cmd_flags,
  62. u16 token)
  63. {
  64. struct fsl_mc_command cmd = { 0 };
  65. /* prepare command */
  66. cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
  67. token);
  68. /* send command to mc*/
  69. return mc_send_command(mc_io, &cmd);
  70. }
  71. EXPORT_SYMBOL_GPL(dprc_close);
  72. /**
  73. * dprc_reset_container - Reset child container.
  74. * @mc_io: Pointer to MC portal's I/O object
  75. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  76. * @token: Token of DPRC object
  77. * @child_container_id: ID of the container to reset
  78. * @options: 32 bit options:
  79. * - 0 (no bits set) - all the objects inside the container are
  80. * reset. The child containers are entered recursively and the
  81. * objects reset. All the objects (including the child containers)
  82. * are closed.
  83. * - bit 0 set - all the objects inside the container are reset.
  84. * However the child containers are not entered recursively.
  85. * This option is supported for API versions >= 6.5
  86. * In case a software context crashes or becomes non-responsive, the parent
  87. * may wish to reset its resources container before the software context is
  88. * restarted.
  89. *
  90. * This routine informs all objects assigned to the child container that the
  91. * container is being reset, so they may perform any cleanup operations that are
  92. * needed. All objects handles that were owned by the child container shall be
  93. * closed.
  94. *
  95. * Note that such request may be submitted even if the child software context
  96. * has not crashed, but the resulting object cleanup operations will not be
  97. * aware of that.
  98. *
  99. * Return: '0' on Success; Error code otherwise.
  100. */
  101. int dprc_reset_container(struct fsl_mc_io *mc_io,
  102. u32 cmd_flags,
  103. u16 token,
  104. int child_container_id,
  105. u32 options)
  106. {
  107. struct fsl_mc_command cmd = { 0 };
  108. struct dprc_cmd_reset_container *cmd_params;
  109. u32 cmdid = DPRC_CMDID_RESET_CONT;
  110. int err;
  111. /*
  112. * If the DPRC object version was not yet cached, cache it now.
  113. * Otherwise use the already cached value.
  114. */
  115. if (!dprc_major_ver && !dprc_minor_ver) {
  116. err = dprc_get_api_version(mc_io, 0,
  117. &dprc_major_ver,
  118. &dprc_minor_ver);
  119. if (err)
  120. return err;
  121. }
  122. /*
  123. * MC API 6.5 introduced a new field in the command used to pass
  124. * some flags.
  125. * Bit 0 indicates that the child containers are not recursively reset.
  126. */
  127. if (dprc_major_ver > 6 || (dprc_major_ver == 6 && dprc_minor_ver >= 5))
  128. cmdid = DPRC_CMDID_RESET_CONT_V2;
  129. /* prepare command */
  130. cmd.header = mc_encode_cmd_header(cmdid, cmd_flags, token);
  131. cmd_params = (struct dprc_cmd_reset_container *)cmd.params;
  132. cmd_params->child_container_id = cpu_to_le32(child_container_id);
  133. cmd_params->options = cpu_to_le32(options);
  134. /* send command to mc*/
  135. return mc_send_command(mc_io, &cmd);
  136. }
  137. EXPORT_SYMBOL_GPL(dprc_reset_container);
  138. /**
  139. * dprc_set_irq() - Set IRQ information for the DPRC to trigger an interrupt.
  140. * @mc_io: Pointer to MC portal's I/O object
  141. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  142. * @token: Token of DPRC object
  143. * @irq_index: Identifies the interrupt index to configure
  144. * @irq_cfg: IRQ configuration
  145. *
  146. * Return: '0' on Success; Error code otherwise.
  147. */
  148. int dprc_set_irq(struct fsl_mc_io *mc_io,
  149. u32 cmd_flags,
  150. u16 token,
  151. u8 irq_index,
  152. struct dprc_irq_cfg *irq_cfg)
  153. {
  154. struct fsl_mc_command cmd = { 0 };
  155. struct dprc_cmd_set_irq *cmd_params;
  156. /* prepare command */
  157. cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ,
  158. cmd_flags,
  159. token);
  160. cmd_params = (struct dprc_cmd_set_irq *)cmd.params;
  161. cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
  162. cmd_params->irq_index = irq_index;
  163. cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
  164. cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
  165. /* send command to mc*/
  166. return mc_send_command(mc_io, &cmd);
  167. }
  168. /**
  169. * dprc_set_irq_enable() - Set overall interrupt state.
  170. * @mc_io: Pointer to MC portal's I/O object
  171. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  172. * @token: Token of DPRC object
  173. * @irq_index: The interrupt index to configure
  174. * @en: Interrupt state - enable = 1, disable = 0
  175. *
  176. * Allows GPP software to control when interrupts are generated.
  177. * Each interrupt can have up to 32 causes. The enable/disable control's the
  178. * overall interrupt state. if the interrupt is disabled no causes will cause
  179. * an interrupt.
  180. *
  181. * Return: '0' on Success; Error code otherwise.
  182. */
  183. int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
  184. u32 cmd_flags,
  185. u16 token,
  186. u8 irq_index,
  187. u8 en)
  188. {
  189. struct fsl_mc_command cmd = { 0 };
  190. struct dprc_cmd_set_irq_enable *cmd_params;
  191. /* prepare command */
  192. cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_ENABLE,
  193. cmd_flags, token);
  194. cmd_params = (struct dprc_cmd_set_irq_enable *)cmd.params;
  195. cmd_params->enable = en & DPRC_ENABLE;
  196. cmd_params->irq_index = irq_index;
  197. /* send command to mc*/
  198. return mc_send_command(mc_io, &cmd);
  199. }
  200. /**
  201. * dprc_set_irq_mask() - Set interrupt mask.
  202. * @mc_io: Pointer to MC portal's I/O object
  203. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  204. * @token: Token of DPRC object
  205. * @irq_index: The interrupt index to configure
  206. * @mask: event mask to trigger interrupt;
  207. * each bit:
  208. * 0 = ignore event
  209. * 1 = consider event for asserting irq
  210. *
  211. * Every interrupt can have up to 32 causes and the interrupt model supports
  212. * masking/unmasking each cause independently
  213. *
  214. * Return: '0' on Success; Error code otherwise.
  215. */
  216. int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
  217. u32 cmd_flags,
  218. u16 token,
  219. u8 irq_index,
  220. u32 mask)
  221. {
  222. struct fsl_mc_command cmd = { 0 };
  223. struct dprc_cmd_set_irq_mask *cmd_params;
  224. /* prepare command */
  225. cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_MASK,
  226. cmd_flags, token);
  227. cmd_params = (struct dprc_cmd_set_irq_mask *)cmd.params;
  228. cmd_params->mask = cpu_to_le32(mask);
  229. cmd_params->irq_index = irq_index;
  230. /* send command to mc*/
  231. return mc_send_command(mc_io, &cmd);
  232. }
  233. /**
  234. * dprc_get_irq_status() - Get the current status of any pending interrupts.
  235. * @mc_io: Pointer to MC portal's I/O object
  236. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  237. * @token: Token of DPRC object
  238. * @irq_index: The interrupt index to configure
  239. * @status: Returned interrupts status - one bit per cause:
  240. * 0 = no interrupt pending
  241. * 1 = interrupt pending
  242. *
  243. * Return: '0' on Success; Error code otherwise.
  244. */
  245. int dprc_get_irq_status(struct fsl_mc_io *mc_io,
  246. u32 cmd_flags,
  247. u16 token,
  248. u8 irq_index,
  249. u32 *status)
  250. {
  251. struct fsl_mc_command cmd = { 0 };
  252. struct dprc_cmd_get_irq_status *cmd_params;
  253. struct dprc_rsp_get_irq_status *rsp_params;
  254. int err;
  255. /* prepare command */
  256. cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_STATUS,
  257. cmd_flags, token);
  258. cmd_params = (struct dprc_cmd_get_irq_status *)cmd.params;
  259. cmd_params->status = cpu_to_le32(*status);
  260. cmd_params->irq_index = irq_index;
  261. /* send command to mc*/
  262. err = mc_send_command(mc_io, &cmd);
  263. if (err)
  264. return err;
  265. /* retrieve response parameters */
  266. rsp_params = (struct dprc_rsp_get_irq_status *)cmd.params;
  267. *status = le32_to_cpu(rsp_params->status);
  268. return 0;
  269. }
  270. /**
  271. * dprc_clear_irq_status() - Clear a pending interrupt's status
  272. * @mc_io: Pointer to MC portal's I/O object
  273. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  274. * @token: Token of DPRC object
  275. * @irq_index: The interrupt index to configure
  276. * @status: bits to clear (W1C) - one bit per cause:
  277. * 0 = don't change
  278. * 1 = clear status bit
  279. *
  280. * Return: '0' on Success; Error code otherwise.
  281. */
  282. int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
  283. u32 cmd_flags,
  284. u16 token,
  285. u8 irq_index,
  286. u32 status)
  287. {
  288. struct fsl_mc_command cmd = { 0 };
  289. struct dprc_cmd_clear_irq_status *cmd_params;
  290. /* prepare command */
  291. cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLEAR_IRQ_STATUS,
  292. cmd_flags, token);
  293. cmd_params = (struct dprc_cmd_clear_irq_status *)cmd.params;
  294. cmd_params->status = cpu_to_le32(status);
  295. cmd_params->irq_index = irq_index;
  296. /* send command to mc*/
  297. return mc_send_command(mc_io, &cmd);
  298. }
  299. /**
  300. * dprc_get_attributes() - Obtains container attributes
  301. * @mc_io: Pointer to MC portal's I/O object
  302. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  303. * @token: Token of DPRC object
  304. * @attr: Returned container attributes
  305. *
  306. * Return: '0' on Success; Error code otherwise.
  307. */
  308. int dprc_get_attributes(struct fsl_mc_io *mc_io,
  309. u32 cmd_flags,
  310. u16 token,
  311. struct dprc_attributes *attr)
  312. {
  313. struct fsl_mc_command cmd = { 0 };
  314. struct dprc_rsp_get_attributes *rsp_params;
  315. int err;
  316. /* prepare command */
  317. cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
  318. cmd_flags,
  319. token);
  320. /* send command to mc*/
  321. err = mc_send_command(mc_io, &cmd);
  322. if (err)
  323. return err;
  324. /* retrieve response parameters */
  325. rsp_params = (struct dprc_rsp_get_attributes *)cmd.params;
  326. attr->container_id = le32_to_cpu(rsp_params->container_id);
  327. attr->icid = le32_to_cpu(rsp_params->icid);
  328. attr->options = le32_to_cpu(rsp_params->options);
  329. attr->portal_id = le32_to_cpu(rsp_params->portal_id);
  330. return 0;
  331. }
  332. /**
  333. * dprc_get_obj_count() - Obtains the number of objects in the DPRC
  334. * @mc_io: Pointer to MC portal's I/O object
  335. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  336. * @token: Token of DPRC object
  337. * @obj_count: Number of objects assigned to the DPRC
  338. *
  339. * Return: '0' on Success; Error code otherwise.
  340. */
  341. int dprc_get_obj_count(struct fsl_mc_io *mc_io,
  342. u32 cmd_flags,
  343. u16 token,
  344. int *obj_count)
  345. {
  346. struct fsl_mc_command cmd = { 0 };
  347. struct dprc_rsp_get_obj_count *rsp_params;
  348. int err;
  349. /* prepare command */
  350. cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
  351. cmd_flags, token);
  352. /* send command to mc*/
  353. err = mc_send_command(mc_io, &cmd);
  354. if (err)
  355. return err;
  356. /* retrieve response parameters */
  357. rsp_params = (struct dprc_rsp_get_obj_count *)cmd.params;
  358. *obj_count = le32_to_cpu(rsp_params->obj_count);
  359. return 0;
  360. }
  361. EXPORT_SYMBOL_GPL(dprc_get_obj_count);
  362. /**
  363. * dprc_get_obj() - Get general information on an object
  364. * @mc_io: Pointer to MC portal's I/O object
  365. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  366. * @token: Token of DPRC object
  367. * @obj_index: Index of the object to be queried (< obj_count)
  368. * @obj_desc: Returns the requested object descriptor
  369. *
  370. * The object descriptors are retrieved one by one by incrementing
  371. * obj_index up to (not including) the value of obj_count returned
  372. * from dprc_get_obj_count(). dprc_get_obj_count() must
  373. * be called prior to dprc_get_obj().
  374. *
  375. * Return: '0' on Success; Error code otherwise.
  376. */
  377. int dprc_get_obj(struct fsl_mc_io *mc_io,
  378. u32 cmd_flags,
  379. u16 token,
  380. int obj_index,
  381. struct fsl_mc_obj_desc *obj_desc)
  382. {
  383. struct fsl_mc_command cmd = { 0 };
  384. struct dprc_cmd_get_obj *cmd_params;
  385. struct dprc_rsp_get_obj *rsp_params;
  386. int err;
  387. /* prepare command */
  388. cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
  389. cmd_flags,
  390. token);
  391. cmd_params = (struct dprc_cmd_get_obj *)cmd.params;
  392. cmd_params->obj_index = cpu_to_le32(obj_index);
  393. /* send command to mc*/
  394. err = mc_send_command(mc_io, &cmd);
  395. if (err)
  396. return err;
  397. /* retrieve response parameters */
  398. rsp_params = (struct dprc_rsp_get_obj *)cmd.params;
  399. obj_desc->id = le32_to_cpu(rsp_params->id);
  400. obj_desc->vendor = le16_to_cpu(rsp_params->vendor);
  401. obj_desc->irq_count = rsp_params->irq_count;
  402. obj_desc->region_count = rsp_params->region_count;
  403. obj_desc->state = le32_to_cpu(rsp_params->state);
  404. obj_desc->ver_major = le16_to_cpu(rsp_params->version_major);
  405. obj_desc->ver_minor = le16_to_cpu(rsp_params->version_minor);
  406. obj_desc->flags = le16_to_cpu(rsp_params->flags);
  407. strncpy(obj_desc->type, rsp_params->type, 16);
  408. obj_desc->type[15] = '\0';
  409. strncpy(obj_desc->label, rsp_params->label, 16);
  410. obj_desc->label[15] = '\0';
  411. return 0;
  412. }
  413. EXPORT_SYMBOL_GPL(dprc_get_obj);
  414. /**
  415. * dprc_set_obj_irq() - Set IRQ information for object to trigger an interrupt.
  416. * @mc_io: Pointer to MC portal's I/O object
  417. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  418. * @token: Token of DPRC object
  419. * @obj_type: Type of the object to set its IRQ
  420. * @obj_id: ID of the object to set its IRQ
  421. * @irq_index: The interrupt index to configure
  422. * @irq_cfg: IRQ configuration
  423. *
  424. * Return: '0' on Success; Error code otherwise.
  425. */
  426. int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
  427. u32 cmd_flags,
  428. u16 token,
  429. char *obj_type,
  430. int obj_id,
  431. u8 irq_index,
  432. struct dprc_irq_cfg *irq_cfg)
  433. {
  434. struct fsl_mc_command cmd = { 0 };
  435. struct dprc_cmd_set_obj_irq *cmd_params;
  436. /* prepare command */
  437. cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_IRQ,
  438. cmd_flags,
  439. token);
  440. cmd_params = (struct dprc_cmd_set_obj_irq *)cmd.params;
  441. cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
  442. cmd_params->irq_index = irq_index;
  443. cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
  444. cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
  445. cmd_params->obj_id = cpu_to_le32(obj_id);
  446. strncpy(cmd_params->obj_type, obj_type, 16);
  447. cmd_params->obj_type[15] = '\0';
  448. /* send command to mc*/
  449. return mc_send_command(mc_io, &cmd);
  450. }
  451. EXPORT_SYMBOL_GPL(dprc_set_obj_irq);
  452. /**
  453. * dprc_get_obj_region() - Get region information for a specified object.
  454. * @mc_io: Pointer to MC portal's I/O object
  455. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  456. * @token: Token of DPRC object
  457. * @obj_type: Object type as returned in dprc_get_obj()
  458. * @obj_id: Unique object instance as returned in dprc_get_obj()
  459. * @region_index: The specific region to query
  460. * @region_desc: Returns the requested region descriptor
  461. *
  462. * Return: '0' on Success; Error code otherwise.
  463. */
  464. int dprc_get_obj_region(struct fsl_mc_io *mc_io,
  465. u32 cmd_flags,
  466. u16 token,
  467. char *obj_type,
  468. int obj_id,
  469. u8 region_index,
  470. struct dprc_region_desc *region_desc)
  471. {
  472. struct fsl_mc_command cmd = { 0 };
  473. struct dprc_cmd_get_obj_region *cmd_params;
  474. struct dprc_rsp_get_obj_region *rsp_params;
  475. int err;
  476. /*
  477. * If the DPRC object version was not yet cached, cache it now.
  478. * Otherwise use the already cached value.
  479. */
  480. if (!dprc_major_ver && !dprc_minor_ver) {
  481. err = dprc_get_api_version(mc_io, 0,
  482. &dprc_major_ver,
  483. &dprc_minor_ver);
  484. if (err)
  485. return err;
  486. }
  487. if (dprc_major_ver > 6 || (dprc_major_ver == 6 && dprc_minor_ver >= 6)) {
  488. /*
  489. * MC API version 6.6 changed the size of the MC portals and software
  490. * portals to 64K (as implemented by hardware). If older API is in use the
  491. * size reported is less (64 bytes for mc portals and 4K for software
  492. * portals).
  493. */
  494. cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG_V3,
  495. cmd_flags, token);
  496. } else if (dprc_major_ver == 6 && dprc_minor_ver >= 3) {
  497. /*
  498. * MC API version 6.3 introduced a new field to the region
  499. * descriptor: base_address. If the older API is in use then the base
  500. * address is set to zero to indicate it needs to be obtained elsewhere
  501. * (typically the device tree).
  502. */
  503. cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG_V2,
  504. cmd_flags, token);
  505. } else {
  506. cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
  507. cmd_flags, token);
  508. }
  509. cmd_params = (struct dprc_cmd_get_obj_region *)cmd.params;
  510. cmd_params->obj_id = cpu_to_le32(obj_id);
  511. cmd_params->region_index = region_index;
  512. strncpy(cmd_params->obj_type, obj_type, 16);
  513. cmd_params->obj_type[15] = '\0';
  514. /* send command to mc*/
  515. err = mc_send_command(mc_io, &cmd);
  516. if (err)
  517. return err;
  518. /* retrieve response parameters */
  519. rsp_params = (struct dprc_rsp_get_obj_region *)cmd.params;
  520. region_desc->base_offset = le64_to_cpu(rsp_params->base_offset);
  521. region_desc->size = le32_to_cpu(rsp_params->size);
  522. region_desc->type = rsp_params->type;
  523. region_desc->flags = le32_to_cpu(rsp_params->flags);
  524. if (dprc_major_ver > 6 || (dprc_major_ver == 6 && dprc_minor_ver >= 3))
  525. region_desc->base_address = le64_to_cpu(rsp_params->base_addr);
  526. else
  527. region_desc->base_address = 0;
  528. return 0;
  529. }
  530. EXPORT_SYMBOL_GPL(dprc_get_obj_region);
  531. /**
  532. * dprc_get_api_version - Get Data Path Resource Container API version
  533. * @mc_io: Pointer to Mc portal's I/O object
  534. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  535. * @major_ver: Major version of Data Path Resource Container API
  536. * @minor_ver: Minor version of Data Path Resource Container API
  537. *
  538. * Return: '0' on Success; Error code otherwise.
  539. */
  540. int dprc_get_api_version(struct fsl_mc_io *mc_io,
  541. u32 cmd_flags,
  542. u16 *major_ver,
  543. u16 *minor_ver)
  544. {
  545. struct fsl_mc_command cmd = { 0 };
  546. int err;
  547. /* prepare command */
  548. cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_API_VERSION,
  549. cmd_flags, 0);
  550. /* send command to mc */
  551. err = mc_send_command(mc_io, &cmd);
  552. if (err)
  553. return err;
  554. /* retrieve response parameters */
  555. mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
  556. return 0;
  557. }
  558. /**
  559. * dprc_get_container_id - Get container ID associated with a given portal.
  560. * @mc_io: Pointer to Mc portal's I/O object
  561. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  562. * @container_id: Requested container id
  563. *
  564. * Return: '0' on Success; Error code otherwise.
  565. */
  566. int dprc_get_container_id(struct fsl_mc_io *mc_io,
  567. u32 cmd_flags,
  568. int *container_id)
  569. {
  570. struct fsl_mc_command cmd = { 0 };
  571. int err;
  572. /* prepare command */
  573. cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONT_ID,
  574. cmd_flags,
  575. 0);
  576. /* send command to mc*/
  577. err = mc_send_command(mc_io, &cmd);
  578. if (err)
  579. return err;
  580. /* retrieve response parameters */
  581. *container_id = (int)mc_cmd_read_object_id(&cmd);
  582. return 0;
  583. }
  584. /**
  585. * dprc_get_connection() - Get connected endpoint and link status if connection
  586. * exists.
  587. * @mc_io: Pointer to MC portal's I/O object
  588. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  589. * @token: Token of DPRC object
  590. * @endpoint1: Endpoint 1 configuration parameters
  591. * @endpoint2: Returned endpoint 2 configuration parameters
  592. * @state: Returned link state:
  593. * 1 - link is up;
  594. * 0 - link is down;
  595. * -1 - no connection (endpoint2 information is irrelevant)
  596. *
  597. * Return: '0' on Success; -ENOTCONN if connection does not exist.
  598. */
  599. int dprc_get_connection(struct fsl_mc_io *mc_io,
  600. u32 cmd_flags,
  601. u16 token,
  602. const struct dprc_endpoint *endpoint1,
  603. struct dprc_endpoint *endpoint2,
  604. int *state)
  605. {
  606. struct dprc_cmd_get_connection *cmd_params;
  607. struct dprc_rsp_get_connection *rsp_params;
  608. struct fsl_mc_command cmd = { 0 };
  609. int err, i;
  610. /* prepare command */
  611. cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
  612. cmd_flags,
  613. token);
  614. cmd_params = (struct dprc_cmd_get_connection *)cmd.params;
  615. cmd_params->ep1_id = cpu_to_le32(endpoint1->id);
  616. cmd_params->ep1_interface_id = cpu_to_le16(endpoint1->if_id);
  617. for (i = 0; i < 16; i++)
  618. cmd_params->ep1_type[i] = endpoint1->type[i];
  619. /* send command to mc */
  620. err = mc_send_command(mc_io, &cmd);
  621. if (err)
  622. return -ENOTCONN;
  623. /* retrieve response parameters */
  624. rsp_params = (struct dprc_rsp_get_connection *)cmd.params;
  625. endpoint2->id = le32_to_cpu(rsp_params->ep2_id);
  626. endpoint2->if_id = le16_to_cpu(rsp_params->ep2_interface_id);
  627. *state = le32_to_cpu(rsp_params->state);
  628. for (i = 0; i < 16; i++)
  629. endpoint2->type[i] = rsp_params->ep2_type[i];
  630. return 0;
  631. }