qman_priv.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* Copyright 2008 - 2016 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 Freescale Semiconductor nor the
  11. * names of its contributors may be used to endorse or promote products
  12. * derived from this software without specific prior written permission.
  13. *
  14. * ALTERNATIVELY, this software may be distributed under the terms of the
  15. * GNU General Public License ("GPL") as published by the Free Software
  16. * Foundation, either version 2 of that License or (at your option) any
  17. * later version.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  20. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  23. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  31. #include "dpaa_sys.h"
  32. #include <soc/fsl/qman.h>
  33. #include <linux/dma-mapping.h>
  34. #include <linux/iommu.h>
  35. #if defined(CONFIG_FSL_PAMU)
  36. #include <asm/fsl_pamu_stash.h>
  37. #endif
  38. struct qm_mcr_querywq {
  39. u8 verb;
  40. u8 result;
  41. u16 channel_wq; /* ignores wq (3 lsbits): _res[0-2] */
  42. u8 __reserved[28];
  43. u32 wq_len[8];
  44. } __packed;
  45. static inline u16 qm_mcr_querywq_get_chan(const struct qm_mcr_querywq *wq)
  46. {
  47. return wq->channel_wq >> 3;
  48. }
  49. struct __qm_mcr_querycongestion {
  50. u32 state[8];
  51. };
  52. /* "Query Congestion Group State" */
  53. struct qm_mcr_querycongestion {
  54. u8 verb;
  55. u8 result;
  56. u8 __reserved[30];
  57. /* Access this struct using qman_cgrs_get() */
  58. struct __qm_mcr_querycongestion state;
  59. } __packed;
  60. /* "Query CGR" */
  61. struct qm_mcr_querycgr {
  62. u8 verb;
  63. u8 result;
  64. u16 __reserved1;
  65. struct __qm_mc_cgr cgr; /* CGR fields */
  66. u8 __reserved2[6];
  67. u8 i_bcnt_hi; /* high 8-bits of 40-bit "Instant" */
  68. __be32 i_bcnt_lo; /* low 32-bits of 40-bit */
  69. u8 __reserved3[3];
  70. u8 a_bcnt_hi; /* high 8-bits of 40-bit "Average" */
  71. __be32 a_bcnt_lo; /* low 32-bits of 40-bit */
  72. __be32 cscn_targ_swp[4];
  73. } __packed;
  74. static inline u64 qm_mcr_querycgr_i_get64(const struct qm_mcr_querycgr *q)
  75. {
  76. return ((u64)q->i_bcnt_hi << 32) | be32_to_cpu(q->i_bcnt_lo);
  77. }
  78. static inline u64 qm_mcr_querycgr_a_get64(const struct qm_mcr_querycgr *q)
  79. {
  80. return ((u64)q->a_bcnt_hi << 32) | be32_to_cpu(q->a_bcnt_lo);
  81. }
  82. /* Congestion Groups */
  83. /*
  84. * This wrapper represents a bit-array for the state of the 256 QMan congestion
  85. * groups. Is also used as a *mask* for congestion groups, eg. so we ignore
  86. * those that don't concern us. We harness the structure and accessor details
  87. * already used in the management command to query congestion groups.
  88. */
  89. #define CGR_BITS_PER_WORD 5
  90. #define CGR_WORD(x) ((x) >> CGR_BITS_PER_WORD)
  91. #define CGR_BIT(x) (BIT(31) >> ((x) & 0x1f))
  92. #define CGR_NUM (sizeof(struct __qm_mcr_querycongestion) << 3)
  93. struct qman_cgrs {
  94. struct __qm_mcr_querycongestion q;
  95. };
  96. static inline void qman_cgrs_init(struct qman_cgrs *c)
  97. {
  98. memset(c, 0, sizeof(*c));
  99. }
  100. static inline void qman_cgrs_fill(struct qman_cgrs *c)
  101. {
  102. memset(c, 0xff, sizeof(*c));
  103. }
  104. static inline int qman_cgrs_get(struct qman_cgrs *c, u8 cgr)
  105. {
  106. return c->q.state[CGR_WORD(cgr)] & CGR_BIT(cgr);
  107. }
  108. static inline void qman_cgrs_cp(struct qman_cgrs *dest,
  109. const struct qman_cgrs *src)
  110. {
  111. *dest = *src;
  112. }
  113. static inline void qman_cgrs_and(struct qman_cgrs *dest,
  114. const struct qman_cgrs *a, const struct qman_cgrs *b)
  115. {
  116. int ret;
  117. u32 *_d = dest->q.state;
  118. const u32 *_a = a->q.state;
  119. const u32 *_b = b->q.state;
  120. for (ret = 0; ret < 8; ret++)
  121. *_d++ = *_a++ & *_b++;
  122. }
  123. static inline void qman_cgrs_xor(struct qman_cgrs *dest,
  124. const struct qman_cgrs *a, const struct qman_cgrs *b)
  125. {
  126. int ret;
  127. u32 *_d = dest->q.state;
  128. const u32 *_a = a->q.state;
  129. const u32 *_b = b->q.state;
  130. for (ret = 0; ret < 8; ret++)
  131. *_d++ = *_a++ ^ *_b++;
  132. }
  133. void qman_init_cgr_all(void);
  134. struct qm_portal_config {
  135. /*
  136. * Corenet portal addresses;
  137. * [0]==cache-enabled, [1]==cache-inhibited.
  138. */
  139. void __iomem *addr_virt[2];
  140. struct device *dev;
  141. struct iommu_domain *iommu_domain;
  142. /* Allow these to be joined in lists */
  143. struct list_head list;
  144. /* User-visible portal configuration settings */
  145. /* portal is affined to this cpu */
  146. int cpu;
  147. /* portal interrupt line */
  148. int irq;
  149. /*
  150. * the portal's dedicated channel id, used initialising
  151. * frame queues to target this portal when scheduled
  152. */
  153. u16 channel;
  154. /*
  155. * mask of pool channels this portal has dequeue access to
  156. * (using QM_SDQCR_CHANNELS_POOL(n) for the bitmask)
  157. */
  158. u32 pools;
  159. };
  160. /* Revision info (for errata and feature handling) */
  161. #define QMAN_REV11 0x0101
  162. #define QMAN_REV12 0x0102
  163. #define QMAN_REV20 0x0200
  164. #define QMAN_REV30 0x0300
  165. #define QMAN_REV31 0x0301
  166. extern u16 qman_ip_rev; /* 0 if uninitialised, otherwise QMAN_REVx */
  167. #define QM_FQID_RANGE_START 1 /* FQID 0 reserved for internal use */
  168. extern struct gen_pool *qm_fqalloc; /* FQID allocator */
  169. extern struct gen_pool *qm_qpalloc; /* pool-channel allocator */
  170. extern struct gen_pool *qm_cgralloc; /* CGR ID allocator */
  171. u32 qm_get_pools_sdqcr(void);
  172. int qman_wq_alloc(void);
  173. void qman_liodn_fixup(u16 channel);
  174. void qman_set_sdest(u16 channel, unsigned int cpu_idx);
  175. struct qman_portal *qman_create_affine_portal(
  176. const struct qm_portal_config *config,
  177. const struct qman_cgrs *cgrs);
  178. const struct qm_portal_config *qman_destroy_affine_portal(void);
  179. /*
  180. * qman_query_fq - Queries FQD fields (via h/w query command)
  181. * @fq: the frame queue object to be queried
  182. * @fqd: storage for the queried FQD fields
  183. */
  184. int qman_query_fq(struct qman_fq *fq, struct qm_fqd *fqd);
  185. int qman_alloc_fq_table(u32 num_fqids);
  186. /* QMan s/w corenet portal, low-level i/face */
  187. /*
  188. * For qm_dqrr_sdqcr_set(); Choose one SOURCE. Choose one COUNT. Choose one
  189. * dequeue TYPE. Choose TOKEN (8-bit).
  190. * If SOURCE == CHANNELS,
  191. * Choose CHANNELS_DEDICATED and/or CHANNELS_POOL(n).
  192. * You can choose DEDICATED_PRECEDENCE if the portal channel should have
  193. * priority.
  194. * If SOURCE == SPECIFICWQ,
  195. * Either select the work-queue ID with SPECIFICWQ_WQ(), or select the
  196. * channel (SPECIFICWQ_DEDICATED or SPECIFICWQ_POOL()) and specify the
  197. * work-queue priority (0-7) with SPECIFICWQ_WQ() - either way, you get the
  198. * same value.
  199. */
  200. #define QM_SDQCR_SOURCE_CHANNELS 0x0
  201. #define QM_SDQCR_SOURCE_SPECIFICWQ 0x40000000
  202. #define QM_SDQCR_COUNT_EXACT1 0x0
  203. #define QM_SDQCR_COUNT_UPTO3 0x20000000
  204. #define QM_SDQCR_DEDICATED_PRECEDENCE 0x10000000
  205. #define QM_SDQCR_TYPE_MASK 0x03000000
  206. #define QM_SDQCR_TYPE_NULL 0x0
  207. #define QM_SDQCR_TYPE_PRIO_QOS 0x01000000
  208. #define QM_SDQCR_TYPE_ACTIVE_QOS 0x02000000
  209. #define QM_SDQCR_TYPE_ACTIVE 0x03000000
  210. #define QM_SDQCR_TOKEN_MASK 0x00ff0000
  211. #define QM_SDQCR_TOKEN_SET(v) (((v) & 0xff) << 16)
  212. #define QM_SDQCR_TOKEN_GET(v) (((v) >> 16) & 0xff)
  213. #define QM_SDQCR_CHANNELS_DEDICATED 0x00008000
  214. #define QM_SDQCR_SPECIFICWQ_MASK 0x000000f7
  215. #define QM_SDQCR_SPECIFICWQ_DEDICATED 0x00000000
  216. #define QM_SDQCR_SPECIFICWQ_POOL(n) ((n) << 4)
  217. #define QM_SDQCR_SPECIFICWQ_WQ(n) (n)
  218. /* For qm_dqrr_vdqcr_set(): use FQID(n) to fill in the frame queue ID */
  219. #define QM_VDQCR_FQID_MASK 0x00ffffff
  220. #define QM_VDQCR_FQID(n) ((n) & QM_VDQCR_FQID_MASK)
  221. /*
  222. * Used by all portal interrupt registers except 'inhibit'
  223. * Channels with frame availability
  224. */
  225. #define QM_PIRQ_DQAVAIL 0x0000ffff
  226. /* The DQAVAIL interrupt fields break down into these bits; */
  227. #define QM_DQAVAIL_PORTAL 0x8000 /* Portal channel */
  228. #define QM_DQAVAIL_POOL(n) (0x8000 >> (n)) /* Pool channel, n==[1..15] */
  229. #define QM_DQAVAIL_MASK 0xffff
  230. /* This mask contains all the "irqsource" bits visible to API users */
  231. #define QM_PIRQ_VISIBLE (QM_PIRQ_SLOW | QM_PIRQ_DQRI)
  232. extern struct qman_portal *affine_portals[NR_CPUS];
  233. extern struct qman_portal *qman_dma_portal;
  234. const struct qm_portal_config *qman_get_qm_portal_config(
  235. struct qman_portal *portal);