mc-cmd.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* Copyright 2013-2015 Freescale Semiconductor Inc.
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are met:
  5. * * Redistributions of source code must retain the above copyright
  6. * notice, this list of conditions and the following disclaimer.
  7. * * Redistributions in binary form must reproduce the above copyright
  8. * notice, this list of conditions and the following disclaimer in the
  9. * documentation and/or other materials provided with the distribution.
  10. * * Neither the name of the above-listed copyright holders nor the
  11. * names of any contributors may be used to endorse or promote products
  12. * derived from this software without specific prior written permission.
  13. *
  14. *
  15. * ALTERNATIVELY, this software may be distributed under the terms of the
  16. * GNU General Public License ("GPL") as published by the Free Software
  17. * Foundation, either version 2 of that License or (at your option) any
  18. * later version.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  24. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. * POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #ifndef __FSL_MC_CMD_H
  33. #define __FSL_MC_CMD_H
  34. #define MC_CMD_NUM_OF_PARAMS 7
  35. #define MAKE_UMASK64(_width) \
  36. ((u64)((_width) < 64 ? ((u64)1 << (_width)) - 1 : -1))
  37. static inline u64 mc_enc(int lsoffset, int width, u64 val)
  38. {
  39. return (u64)(((u64)val & MAKE_UMASK64(width)) << lsoffset);
  40. }
  41. static inline u64 mc_dec(u64 val, int lsoffset, int width)
  42. {
  43. return (u64)((val >> lsoffset) & MAKE_UMASK64(width));
  44. }
  45. struct mc_command {
  46. u64 header;
  47. u64 params[MC_CMD_NUM_OF_PARAMS];
  48. };
  49. enum mc_cmd_status {
  50. MC_CMD_STATUS_OK = 0x0, /* Completed successfully */
  51. MC_CMD_STATUS_READY = 0x1, /* Ready to be processed */
  52. MC_CMD_STATUS_AUTH_ERR = 0x3, /* Authentication error */
  53. MC_CMD_STATUS_NO_PRIVILEGE = 0x4, /* No privilege */
  54. MC_CMD_STATUS_DMA_ERR = 0x5, /* DMA or I/O error */
  55. MC_CMD_STATUS_CONFIG_ERR = 0x6, /* Configuration error */
  56. MC_CMD_STATUS_TIMEOUT = 0x7, /* Operation timed out */
  57. MC_CMD_STATUS_NO_RESOURCE = 0x8, /* No resources */
  58. MC_CMD_STATUS_NO_MEMORY = 0x9, /* No memory available */
  59. MC_CMD_STATUS_BUSY = 0xA, /* Device is busy */
  60. MC_CMD_STATUS_UNSUPPORTED_OP = 0xB, /* Unsupported operation */
  61. MC_CMD_STATUS_INVALID_STATE = 0xC /* Invalid state */
  62. };
  63. /*
  64. * MC command flags
  65. */
  66. /* High priority flag */
  67. #define MC_CMD_FLAG_PRI 0x00008000
  68. /* Command completion flag */
  69. #define MC_CMD_FLAG_INTR_DIS 0x01000000
  70. /*
  71. * TODO Remove following two defines after completion of flib 8.0.0
  72. * integration
  73. */
  74. #define MC_CMD_PRI_LOW 0 /*!< Low Priority command indication */
  75. #define MC_CMD_PRI_HIGH 1 /*!< High Priority command indication */
  76. #define MC_CMD_HDR_CMDID_O 52 /* Command ID field offset */
  77. #define MC_CMD_HDR_CMDID_S 12 /* Command ID field size */
  78. #define MC_CMD_HDR_TOKEN_O 38 /* Token field offset */
  79. #define MC_CMD_HDR_TOKEN_S 10 /* Token field size */
  80. #define MC_CMD_HDR_STATUS_O 16 /* Status field offset */
  81. #define MC_CMD_HDR_STATUS_S 8 /* Status field size*/
  82. #define MC_CMD_HDR_FLAGS_O 0 /* Flags field offset */
  83. #define MC_CMD_HDR_FLAGS_S 32 /* Flags field size*/
  84. #define MC_CMD_HDR_FLAGS_MASK 0xFF00FF00 /* Command flags mask */
  85. #define MC_CMD_HDR_READ_STATUS(_hdr) \
  86. ((enum mc_cmd_status)mc_dec((_hdr), \
  87. MC_CMD_HDR_STATUS_O, MC_CMD_HDR_STATUS_S))
  88. #define MC_CMD_HDR_READ_TOKEN(_hdr) \
  89. ((u16)mc_dec((_hdr), MC_CMD_HDR_TOKEN_O, MC_CMD_HDR_TOKEN_S))
  90. #define MC_CMD_HDR_READ_FLAGS(_hdr) \
  91. ((u32)mc_dec((_hdr), MC_CMD_HDR_FLAGS_O, MC_CMD_HDR_FLAGS_S))
  92. #define MC_EXT_OP(_ext, _param, _offset, _width, _type, _arg) \
  93. ((_ext)[_param] |= mc_enc((_offset), (_width), _arg))
  94. #define MC_CMD_OP(_cmd, _param, _offset, _width, _type, _arg) \
  95. ((_cmd).params[_param] |= mc_enc((_offset), (_width), _arg))
  96. #define MC_RSP_OP(_cmd, _param, _offset, _width, _type, _arg) \
  97. (_arg = (_type)mc_dec(_cmd.params[_param], (_offset), (_width)))
  98. static inline u64 mc_encode_cmd_header(u16 cmd_id,
  99. u32 cmd_flags,
  100. u16 token)
  101. {
  102. u64 hdr;
  103. hdr = mc_enc(MC_CMD_HDR_CMDID_O, MC_CMD_HDR_CMDID_S, cmd_id);
  104. hdr |= mc_enc(MC_CMD_HDR_FLAGS_O, MC_CMD_HDR_FLAGS_S,
  105. (cmd_flags & MC_CMD_HDR_FLAGS_MASK));
  106. hdr |= mc_enc(MC_CMD_HDR_TOKEN_O, MC_CMD_HDR_TOKEN_S, token);
  107. hdr |= mc_enc(MC_CMD_HDR_STATUS_O, MC_CMD_HDR_STATUS_S,
  108. MC_CMD_STATUS_READY);
  109. return hdr;
  110. }
  111. #endif /* __FSL_MC_CMD_H */