qman_priv.h 12 KB

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