qbman_portal.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (C) 2014 Freescale Semiconductor
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include "qbman_private.h"
  7. #include <fsl-mc/fsl_qbman_portal.h>
  8. #include <fsl-mc/fsl_dpaa_fd.h>
  9. /* All QBMan command and result structures use this "valid bit" encoding */
  10. #define QB_VALID_BIT ((uint32_t)0x80)
  11. /* Management command result codes */
  12. #define QBMAN_MC_RSLT_OK 0xf0
  13. #define QBMAN_VER_4_0_DQRR_SIZE 4
  14. #define QBMAN_VER_4_1_DQRR_SIZE 8
  15. /* --------------------- */
  16. /* portal data structure */
  17. /* --------------------- */
  18. struct qbman_swp {
  19. const struct qbman_swp_desc *desc;
  20. /* The qbman_sys (ie. arch/OS-specific) support code can put anything it
  21. * needs in here. */
  22. struct qbman_swp_sys sys;
  23. /* Management commands */
  24. struct {
  25. #ifdef QBMAN_CHECKING
  26. enum swp_mc_check {
  27. swp_mc_can_start, /* call __qbman_swp_mc_start() */
  28. swp_mc_can_submit, /* call __qbman_swp_mc_submit() */
  29. swp_mc_can_poll, /* call __qbman_swp_mc_result() */
  30. } check;
  31. #endif
  32. uint32_t valid_bit; /* 0x00 or 0x80 */
  33. } mc;
  34. /* Push dequeues */
  35. uint32_t sdq;
  36. /* Volatile dequeues */
  37. struct {
  38. /* VDQCR supports a "1 deep pipeline", meaning that if you know
  39. * the last-submitted command is already executing in the
  40. * hardware (as evidenced by at least 1 valid dequeue result),
  41. * you can write another dequeue command to the register, the
  42. * hardware will start executing it as soon as the
  43. * already-executing command terminates. (This minimises latency
  44. * and stalls.) With that in mind, this "busy" variable refers
  45. * to whether or not a command can be submitted, not whether or
  46. * not a previously-submitted command is still executing. In
  47. * other words, once proof is seen that the previously-submitted
  48. * command is executing, "vdq" is no longer "busy".
  49. */
  50. atomic_t busy;
  51. uint32_t valid_bit; /* 0x00 or 0x80 */
  52. /* We need to determine when vdq is no longer busy. This depends
  53. * on whether the "busy" (last-submitted) dequeue command is
  54. * targeting DQRR or main-memory, and detected is based on the
  55. * presence of the dequeue command's "token" showing up in
  56. * dequeue entries in DQRR or main-memory (respectively). Debug
  57. * builds will, when submitting vdq commands, verify that the
  58. * dequeue result location is not already equal to the command's
  59. * token value. */
  60. struct ldpaa_dq *storage; /* NULL if DQRR */
  61. uint32_t token;
  62. } vdq;
  63. /* DQRR */
  64. struct {
  65. uint32_t next_idx;
  66. uint32_t valid_bit;
  67. uint8_t dqrr_size;
  68. } dqrr;
  69. };
  70. /* -------------------------- */
  71. /* portal management commands */
  72. /* -------------------------- */
  73. /* Different management commands all use this common base layer of code to issue
  74. * commands and poll for results. The first function returns a pointer to where
  75. * the caller should fill in their MC command (though they should ignore the
  76. * verb byte), the second function commits merges in the caller-supplied command
  77. * verb (which should not include the valid-bit) and submits the command to
  78. * hardware, and the third function checks for a completed response (returns
  79. * non-NULL if only if the response is complete). */
  80. void *qbman_swp_mc_start(struct qbman_swp *p);
  81. void qbman_swp_mc_submit(struct qbman_swp *p, void *cmd, uint32_t cmd_verb);
  82. void *qbman_swp_mc_result(struct qbman_swp *p);
  83. /* Wraps up submit + poll-for-result */
  84. static inline void *qbman_swp_mc_complete(struct qbman_swp *swp, void *cmd,
  85. uint32_t cmd_verb)
  86. {
  87. int loopvar;
  88. qbman_swp_mc_submit(swp, cmd, cmd_verb);
  89. DBG_POLL_START(loopvar);
  90. do {
  91. DBG_POLL_CHECK(loopvar);
  92. cmd = qbman_swp_mc_result(swp);
  93. } while (!cmd);
  94. return cmd;
  95. }
  96. /* ------------ */
  97. /* qb_attr_code */
  98. /* ------------ */
  99. /* This struct locates a sub-field within a QBMan portal (CENA) cacheline which
  100. * is either serving as a configuration command or a query result. The
  101. * representation is inherently little-endian, as the indexing of the words is
  102. * itself little-endian in nature and layerscape is little endian for anything
  103. * that crosses a word boundary too (64-bit fields are the obvious examples).
  104. */
  105. struct qb_attr_code {
  106. unsigned int word; /* which uint32_t[] array member encodes the field */
  107. unsigned int lsoffset; /* encoding offset from ls-bit */
  108. unsigned int width; /* encoding width. (bool must be 1.) */
  109. };
  110. /* Macros to define codes */
  111. #define QB_CODE(a, b, c) { a, b, c}
  112. /* decode a field from a cacheline */
  113. static inline uint32_t qb_attr_code_decode(const struct qb_attr_code *code,
  114. const uint32_t *cacheline)
  115. {
  116. return d32_uint32_t(code->lsoffset, code->width, cacheline[code->word]);
  117. }
  118. /* encode a field to a cacheline */
  119. static inline void qb_attr_code_encode(const struct qb_attr_code *code,
  120. uint32_t *cacheline, uint32_t val)
  121. {
  122. cacheline[code->word] =
  123. r32_uint32_t(code->lsoffset, code->width, cacheline[code->word])
  124. | e32_uint32_t(code->lsoffset, code->width, val);
  125. }
  126. static inline void qb_attr_code_encode_64(const struct qb_attr_code *code,
  127. uint64_t *cacheline, uint64_t val)
  128. {
  129. cacheline[code->word / 2] = val;
  130. }
  131. /* ---------------------- */
  132. /* Descriptors/cachelines */
  133. /* ---------------------- */
  134. /* To avoid needless dynamic allocation, the driver API often gives the caller
  135. * a "descriptor" type that the caller can instantiate however they like.
  136. * Ultimately though, it is just a cacheline of binary storage (or something
  137. * smaller when it is known that the descriptor doesn't need all 64 bytes) for
  138. * holding pre-formatted pieces of hardware commands. The performance-critical
  139. * code can then copy these descriptors directly into hardware command
  140. * registers more efficiently than trying to construct/format commands
  141. * on-the-fly. The API user sees the descriptor as an array of 32-bit words in
  142. * order for the compiler to know its size, but the internal details are not
  143. * exposed. The following macro is used within the driver for converting *any*
  144. * descriptor pointer to a usable array pointer. The use of a macro (instead of
  145. * an inline) is necessary to work with different descriptor types and to work
  146. * correctly with const and non-const inputs (and similarly-qualified outputs).
  147. */
  148. #define qb_cl(d) (&(d)->dont_manipulate_directly[0])