qman_priv.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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/iommu.h>
  34. #if defined(CONFIG_FSL_PAMU)
  35. #include <asm/fsl_pamu_stash.h>
  36. #endif
  37. struct qm_mcr_querywq {
  38. u8 verb;
  39. u8 result;
  40. u16 channel_wq; /* ignores wq (3 lsbits): _res[0-2] */
  41. u8 __reserved[28];
  42. u32 wq_len[8];
  43. } __packed;
  44. static inline u16 qm_mcr_querywq_get_chan(const struct qm_mcr_querywq *wq)
  45. {
  46. return wq->channel_wq >> 3;
  47. }
  48. struct __qm_mcr_querycongestion {
  49. u32 state[8];
  50. };
  51. /* "Query Congestion Group State" */
  52. struct qm_mcr_querycongestion {
  53. u8 verb;
  54. u8 result;
  55. u8 __reserved[30];
  56. /* Access this struct using qman_cgrs_get() */
  57. struct __qm_mcr_querycongestion state;
  58. } __packed;
  59. /* "Query CGR" */
  60. struct qm_mcr_querycgr {
  61. u8 verb;
  62. u8 result;
  63. u16 __reserved1;
  64. struct __qm_mc_cgr cgr; /* CGR fields */
  65. u8 __reserved2[6];
  66. u8 i_bcnt_hi; /* high 8-bits of 40-bit "Instant" */
  67. __be32 i_bcnt_lo; /* low 32-bits of 40-bit */
  68. u8 __reserved3[3];
  69. u8 a_bcnt_hi; /* high 8-bits of 40-bit "Average" */
  70. __be32 a_bcnt_lo; /* low 32-bits of 40-bit */
  71. __be32 cscn_targ_swp[4];
  72. } __packed;
  73. static inline u64 qm_mcr_querycgr_i_get64(const struct qm_mcr_querycgr *q)
  74. {
  75. return ((u64)q->i_bcnt_hi << 32) | be32_to_cpu(q->i_bcnt_lo);
  76. }
  77. static inline u64 qm_mcr_querycgr_a_get64(const struct qm_mcr_querycgr *q)
  78. {
  79. return ((u64)q->a_bcnt_hi << 32) | be32_to_cpu(q->a_bcnt_lo);
  80. }
  81. /* "Query FQ Non-Programmable Fields" */
  82. struct qm_mcr_queryfq_np {
  83. u8 verb;
  84. u8 result;
  85. u8 __reserved1;
  86. u8 state; /* QM_MCR_NP_STATE_*** */
  87. u32 fqd_link; /* 24-bit, _res2[24-31] */
  88. u16 odp_seq; /* 14-bit, _res3[14-15] */
  89. u16 orp_nesn; /* 14-bit, _res4[14-15] */
  90. u16 orp_ea_hseq; /* 15-bit, _res5[15] */
  91. u16 orp_ea_tseq; /* 15-bit, _res6[15] */
  92. u32 orp_ea_hptr; /* 24-bit, _res7[24-31] */
  93. u32 orp_ea_tptr; /* 24-bit, _res8[24-31] */
  94. u32 pfdr_hptr; /* 24-bit, _res9[24-31] */
  95. u32 pfdr_tptr; /* 24-bit, _res10[24-31] */
  96. u8 __reserved2[5];
  97. u8 is; /* 1-bit, _res12[1-7] */
  98. u16 ics_surp;
  99. u32 byte_cnt;
  100. u32 frm_cnt; /* 24-bit, _res13[24-31] */
  101. u32 __reserved3;
  102. u16 ra1_sfdr; /* QM_MCR_NP_RA1_*** */
  103. u16 ra2_sfdr; /* QM_MCR_NP_RA2_*** */
  104. u16 __reserved4;
  105. u16 od1_sfdr; /* QM_MCR_NP_OD1_*** */
  106. u16 od2_sfdr; /* QM_MCR_NP_OD2_*** */
  107. u16 od3_sfdr; /* QM_MCR_NP_OD3_*** */
  108. } __packed;
  109. #define QM_MCR_NP_STATE_FE 0x10
  110. #define QM_MCR_NP_STATE_R 0x08
  111. #define QM_MCR_NP_STATE_MASK 0x07 /* Reads FQD::STATE; */
  112. #define QM_MCR_NP_STATE_OOS 0x00
  113. #define QM_MCR_NP_STATE_RETIRED 0x01
  114. #define QM_MCR_NP_STATE_TEN_SCHED 0x02
  115. #define QM_MCR_NP_STATE_TRU_SCHED 0x03
  116. #define QM_MCR_NP_STATE_PARKED 0x04
  117. #define QM_MCR_NP_STATE_ACTIVE 0x05
  118. #define QM_MCR_NP_PTR_MASK 0x07ff /* for RA[12] & OD[123] */
  119. #define QM_MCR_NP_RA1_NRA(v) (((v) >> 14) & 0x3) /* FQD::NRA */
  120. #define QM_MCR_NP_RA2_IT(v) (((v) >> 14) & 0x1) /* FQD::IT */
  121. #define QM_MCR_NP_OD1_NOD(v) (((v) >> 14) & 0x3) /* FQD::NOD */
  122. #define QM_MCR_NP_OD3_NPC(v) (((v) >> 14) & 0x3) /* FQD::NPC */
  123. enum qm_mcr_queryfq_np_masks {
  124. qm_mcr_fqd_link_mask = BIT(24)-1,
  125. qm_mcr_odp_seq_mask = BIT(14)-1,
  126. qm_mcr_orp_nesn_mask = BIT(14)-1,
  127. qm_mcr_orp_ea_hseq_mask = BIT(15)-1,
  128. qm_mcr_orp_ea_tseq_mask = BIT(15)-1,
  129. qm_mcr_orp_ea_hptr_mask = BIT(24)-1,
  130. qm_mcr_orp_ea_tptr_mask = BIT(24)-1,
  131. qm_mcr_pfdr_hptr_mask = BIT(24)-1,
  132. qm_mcr_pfdr_tptr_mask = BIT(24)-1,
  133. qm_mcr_is_mask = BIT(1)-1,
  134. qm_mcr_frm_cnt_mask = BIT(24)-1,
  135. };
  136. #define qm_mcr_np_get(np, field) \
  137. ((np)->field & (qm_mcr_##field##_mask))
  138. /* Congestion Groups */
  139. /*
  140. * This wrapper represents a bit-array for the state of the 256 QMan congestion
  141. * groups. Is also used as a *mask* for congestion groups, eg. so we ignore
  142. * those that don't concern us. We harness the structure and accessor details
  143. * already used in the management command to query congestion groups.
  144. */
  145. #define CGR_BITS_PER_WORD 5
  146. #define CGR_WORD(x) ((x) >> CGR_BITS_PER_WORD)
  147. #define CGR_BIT(x) (BIT(31) >> ((x) & 0x1f))
  148. #define CGR_NUM (sizeof(struct __qm_mcr_querycongestion) << 3)
  149. struct qman_cgrs {
  150. struct __qm_mcr_querycongestion q;
  151. };
  152. static inline void qman_cgrs_init(struct qman_cgrs *c)
  153. {
  154. memset(c, 0, sizeof(*c));
  155. }
  156. static inline void qman_cgrs_fill(struct qman_cgrs *c)
  157. {
  158. memset(c, 0xff, sizeof(*c));
  159. }
  160. static inline int qman_cgrs_get(struct qman_cgrs *c, u8 cgr)
  161. {
  162. return c->q.state[CGR_WORD(cgr)] & CGR_BIT(cgr);
  163. }
  164. static inline void qman_cgrs_cp(struct qman_cgrs *dest,
  165. const struct qman_cgrs *src)
  166. {
  167. *dest = *src;
  168. }
  169. static inline void qman_cgrs_and(struct qman_cgrs *dest,
  170. const struct qman_cgrs *a, const struct qman_cgrs *b)
  171. {
  172. int ret;
  173. u32 *_d = dest->q.state;
  174. const u32 *_a = a->q.state;
  175. const u32 *_b = b->q.state;
  176. for (ret = 0; ret < 8; ret++)
  177. *_d++ = *_a++ & *_b++;
  178. }
  179. static inline void qman_cgrs_xor(struct qman_cgrs *dest,
  180. const struct qman_cgrs *a, const struct qman_cgrs *b)
  181. {
  182. int ret;
  183. u32 *_d = dest->q.state;
  184. const u32 *_a = a->q.state;
  185. const u32 *_b = b->q.state;
  186. for (ret = 0; ret < 8; ret++)
  187. *_d++ = *_a++ ^ *_b++;
  188. }
  189. void qman_init_cgr_all(void);
  190. struct qm_portal_config {
  191. /*
  192. * Corenet portal addresses;
  193. * [0]==cache-enabled, [1]==cache-inhibited.
  194. */
  195. void __iomem *addr_virt[2];
  196. struct device *dev;
  197. struct iommu_domain *iommu_domain;
  198. /* Allow these to be joined in lists */
  199. struct list_head list;
  200. /* User-visible portal configuration settings */
  201. /* portal is affined to this cpu */
  202. int cpu;
  203. /* portal interrupt line */
  204. int irq;
  205. /*
  206. * the portal's dedicated channel id, used initialising
  207. * frame queues to target this portal when scheduled
  208. */
  209. u16 channel;
  210. /*
  211. * mask of pool channels this portal has dequeue access to
  212. * (using QM_SDQCR_CHANNELS_POOL(n) for the bitmask)
  213. */
  214. u32 pools;
  215. };
  216. /* Revision info (for errata and feature handling) */
  217. #define QMAN_REV11 0x0101
  218. #define QMAN_REV12 0x0102
  219. #define QMAN_REV20 0x0200
  220. #define QMAN_REV30 0x0300
  221. #define QMAN_REV31 0x0301
  222. extern u16 qman_ip_rev; /* 0 if uninitialised, otherwise QMAN_REVx */
  223. #define QM_FQID_RANGE_START 1 /* FQID 0 reserved for internal use */
  224. extern struct gen_pool *qm_fqalloc; /* FQID allocator */
  225. extern struct gen_pool *qm_qpalloc; /* pool-channel allocator */
  226. extern struct gen_pool *qm_cgralloc; /* CGR ID allocator */
  227. u32 qm_get_pools_sdqcr(void);
  228. int qman_wq_alloc(void);
  229. void qman_liodn_fixup(u16 channel);
  230. void qman_set_sdest(u16 channel, unsigned int cpu_idx);
  231. struct qman_portal *qman_create_affine_portal(
  232. const struct qm_portal_config *config,
  233. const struct qman_cgrs *cgrs);
  234. const struct qm_portal_config *qman_destroy_affine_portal(void);
  235. /*
  236. * qman_query_fq - Queries FQD fields (via h/w query command)
  237. * @fq: the frame queue object to be queried
  238. * @fqd: storage for the queried FQD fields
  239. */
  240. int qman_query_fq(struct qman_fq *fq, struct qm_fqd *fqd);
  241. /*
  242. * For qman_volatile_dequeue(); Choose one PRECEDENCE. EXACT is optional. Use
  243. * NUMFRAMES(n) (6-bit) or NUMFRAMES_TILLEMPTY to fill in the frame-count. Use
  244. * FQID(n) to fill in the frame queue ID.
  245. */
  246. #define QM_VDQCR_PRECEDENCE_VDQCR 0x0
  247. #define QM_VDQCR_PRECEDENCE_SDQCR 0x80000000
  248. #define QM_VDQCR_EXACT 0x40000000
  249. #define QM_VDQCR_NUMFRAMES_MASK 0x3f000000
  250. #define QM_VDQCR_NUMFRAMES_SET(n) (((n) & 0x3f) << 24)
  251. #define QM_VDQCR_NUMFRAMES_GET(n) (((n) >> 24) & 0x3f)
  252. #define QM_VDQCR_NUMFRAMES_TILLEMPTY QM_VDQCR_NUMFRAMES_SET(0)
  253. #define QMAN_VOLATILE_FLAG_WAIT 0x00000001 /* wait if VDQCR is in use */
  254. #define QMAN_VOLATILE_FLAG_WAIT_INT 0x00000002 /* if wait, interruptible? */
  255. #define QMAN_VOLATILE_FLAG_FINISH 0x00000004 /* wait till VDQCR completes */
  256. /*
  257. * qman_volatile_dequeue - Issue a volatile dequeue command
  258. * @fq: the frame queue object to dequeue from
  259. * @flags: a bit-mask of QMAN_VOLATILE_FLAG_*** options
  260. * @vdqcr: bit mask of QM_VDQCR_*** options, as per qm_dqrr_vdqcr_set()
  261. *
  262. * Attempts to lock access to the portal's VDQCR volatile dequeue functionality.
  263. * The function will block and sleep if QMAN_VOLATILE_FLAG_WAIT is specified and
  264. * the VDQCR is already in use, otherwise returns non-zero for failure. If
  265. * QMAN_VOLATILE_FLAG_FINISH is specified, the function will only return once
  266. * the VDQCR command has finished executing (ie. once the callback for the last
  267. * DQRR entry resulting from the VDQCR command has been called). If not using
  268. * the FINISH flag, completion can be determined either by detecting the
  269. * presence of the QM_DQRR_STAT_UNSCHEDULED and QM_DQRR_STAT_DQCR_EXPIRED bits
  270. * in the "stat" parameter passed to the FQ's dequeue callback, or by waiting
  271. * for the QMAN_FQ_STATE_VDQCR bit to disappear.
  272. */
  273. int qman_volatile_dequeue(struct qman_fq *fq, u32 flags, u32 vdqcr);
  274. int qman_alloc_fq_table(u32 num_fqids);
  275. /* QMan s/w corenet portal, low-level i/face */
  276. /*
  277. * For qm_dqrr_sdqcr_set(); Choose one SOURCE. Choose one COUNT. Choose one
  278. * dequeue TYPE. Choose TOKEN (8-bit).
  279. * If SOURCE == CHANNELS,
  280. * Choose CHANNELS_DEDICATED and/or CHANNELS_POOL(n).
  281. * You can choose DEDICATED_PRECEDENCE if the portal channel should have
  282. * priority.
  283. * If SOURCE == SPECIFICWQ,
  284. * Either select the work-queue ID with SPECIFICWQ_WQ(), or select the
  285. * channel (SPECIFICWQ_DEDICATED or SPECIFICWQ_POOL()) and specify the
  286. * work-queue priority (0-7) with SPECIFICWQ_WQ() - either way, you get the
  287. * same value.
  288. */
  289. #define QM_SDQCR_SOURCE_CHANNELS 0x0
  290. #define QM_SDQCR_SOURCE_SPECIFICWQ 0x40000000
  291. #define QM_SDQCR_COUNT_EXACT1 0x0
  292. #define QM_SDQCR_COUNT_UPTO3 0x20000000
  293. #define QM_SDQCR_DEDICATED_PRECEDENCE 0x10000000
  294. #define QM_SDQCR_TYPE_MASK 0x03000000
  295. #define QM_SDQCR_TYPE_NULL 0x0
  296. #define QM_SDQCR_TYPE_PRIO_QOS 0x01000000
  297. #define QM_SDQCR_TYPE_ACTIVE_QOS 0x02000000
  298. #define QM_SDQCR_TYPE_ACTIVE 0x03000000
  299. #define QM_SDQCR_TOKEN_MASK 0x00ff0000
  300. #define QM_SDQCR_TOKEN_SET(v) (((v) & 0xff) << 16)
  301. #define QM_SDQCR_TOKEN_GET(v) (((v) >> 16) & 0xff)
  302. #define QM_SDQCR_CHANNELS_DEDICATED 0x00008000
  303. #define QM_SDQCR_SPECIFICWQ_MASK 0x000000f7
  304. #define QM_SDQCR_SPECIFICWQ_DEDICATED 0x00000000
  305. #define QM_SDQCR_SPECIFICWQ_POOL(n) ((n) << 4)
  306. #define QM_SDQCR_SPECIFICWQ_WQ(n) (n)
  307. /* For qm_dqrr_vdqcr_set(): use FQID(n) to fill in the frame queue ID */
  308. #define QM_VDQCR_FQID_MASK 0x00ffffff
  309. #define QM_VDQCR_FQID(n) ((n) & QM_VDQCR_FQID_MASK)
  310. /*
  311. * Used by all portal interrupt registers except 'inhibit'
  312. * Channels with frame availability
  313. */
  314. #define QM_PIRQ_DQAVAIL 0x0000ffff
  315. /* The DQAVAIL interrupt fields break down into these bits; */
  316. #define QM_DQAVAIL_PORTAL 0x8000 /* Portal channel */
  317. #define QM_DQAVAIL_POOL(n) (0x8000 >> (n)) /* Pool channel, n==[1..15] */
  318. #define QM_DQAVAIL_MASK 0xffff
  319. /* This mask contains all the "irqsource" bits visible to API users */
  320. #define QM_PIRQ_VISIBLE (QM_PIRQ_SLOW | QM_PIRQ_DQRI)
  321. extern struct qman_portal *affine_portals[NR_CPUS];
  322. extern struct qman_portal *qman_dma_portal;
  323. const struct qm_portal_config *qman_get_qm_portal_config(
  324. struct qman_portal *portal);