knav_qmss.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Keystone Navigator QMSS driver internal header
  4. *
  5. * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
  6. * Author: Sandeep Nair <sandeep_n@ti.com>
  7. * Cyril Chemparathy <cyril@ti.com>
  8. * Santosh Shilimkar <santosh.shilimkar@ti.com>
  9. */
  10. #ifndef __KNAV_QMSS_H__
  11. #define __KNAV_QMSS_H__
  12. #include <linux/percpu.h>
  13. #define THRESH_GTE BIT(7)
  14. #define THRESH_LT 0
  15. #define PDSP_CTRL_PC_MASK 0xffff0000
  16. #define PDSP_CTRL_SOFT_RESET BIT(0)
  17. #define PDSP_CTRL_ENABLE BIT(1)
  18. #define PDSP_CTRL_RUNNING BIT(15)
  19. #define ACC_MAX_CHANNEL 48
  20. #define ACC_DEFAULT_PERIOD 25 /* usecs */
  21. #define ACC_CHANNEL_INT_BASE 2
  22. #define ACC_LIST_ENTRY_TYPE 1
  23. #define ACC_LIST_ENTRY_WORDS (1 << ACC_LIST_ENTRY_TYPE)
  24. #define ACC_LIST_ENTRY_QUEUE_IDX 0
  25. #define ACC_LIST_ENTRY_DESC_IDX (ACC_LIST_ENTRY_WORDS - 1)
  26. #define ACC_CMD_DISABLE_CHANNEL 0x80
  27. #define ACC_CMD_ENABLE_CHANNEL 0x81
  28. #define ACC_CFG_MULTI_QUEUE BIT(21)
  29. #define ACC_INTD_OFFSET_EOI (0x0010)
  30. #define ACC_INTD_OFFSET_COUNT(ch) (0x0300 + 4 * (ch))
  31. #define ACC_INTD_OFFSET_STATUS(ch) (0x0200 + 4 * ((ch) / 32))
  32. #define RANGE_MAX_IRQS 64
  33. #define ACC_DESCS_MAX SZ_1K
  34. #define ACC_DESCS_MASK (ACC_DESCS_MAX - 1)
  35. #define DESC_SIZE_MASK 0xful
  36. #define DESC_PTR_MASK (~DESC_SIZE_MASK)
  37. #define KNAV_NAME_SIZE 32
  38. enum knav_acc_result {
  39. ACC_RET_IDLE,
  40. ACC_RET_SUCCESS,
  41. ACC_RET_INVALID_COMMAND,
  42. ACC_RET_INVALID_CHANNEL,
  43. ACC_RET_INACTIVE_CHANNEL,
  44. ACC_RET_ACTIVE_CHANNEL,
  45. ACC_RET_INVALID_QUEUE,
  46. ACC_RET_INVALID_RET,
  47. };
  48. struct knav_reg_config {
  49. u32 revision;
  50. u32 __pad1;
  51. u32 divert;
  52. u32 link_ram_base0;
  53. u32 link_ram_size0;
  54. u32 link_ram_base1;
  55. u32 __pad2[2];
  56. u32 starvation[0];
  57. };
  58. struct knav_reg_region {
  59. u32 base;
  60. u32 start_index;
  61. u32 size_count;
  62. u32 __pad;
  63. };
  64. struct knav_reg_pdsp_regs {
  65. u32 control;
  66. u32 status;
  67. u32 cycle_count;
  68. u32 stall_count;
  69. };
  70. struct knav_reg_acc_command {
  71. u32 command;
  72. u32 queue_mask;
  73. u32 list_dma;
  74. u32 queue_num;
  75. u32 timer_config;
  76. };
  77. struct knav_link_ram_block {
  78. dma_addr_t dma;
  79. void *virt;
  80. size_t size;
  81. };
  82. struct knav_acc_info {
  83. u32 pdsp_id;
  84. u32 start_channel;
  85. u32 list_entries;
  86. u32 pacing_mode;
  87. u32 timer_count;
  88. int mem_size;
  89. int list_size;
  90. struct knav_pdsp_info *pdsp;
  91. };
  92. struct knav_acc_channel {
  93. u32 channel;
  94. u32 list_index;
  95. u32 open_mask;
  96. u32 *list_cpu[2];
  97. dma_addr_t list_dma[2];
  98. char name[KNAV_NAME_SIZE];
  99. atomic_t retrigger_count;
  100. };
  101. struct knav_pdsp_info {
  102. const char *name;
  103. struct knav_reg_pdsp_regs __iomem *regs;
  104. union {
  105. void __iomem *command;
  106. struct knav_reg_acc_command __iomem *acc_command;
  107. u32 __iomem *qos_command;
  108. };
  109. void __iomem *intd;
  110. u32 __iomem *iram;
  111. u32 id;
  112. struct list_head list;
  113. bool loaded;
  114. bool started;
  115. };
  116. struct knav_qmgr_info {
  117. unsigned start_queue;
  118. unsigned num_queues;
  119. struct knav_reg_config __iomem *reg_config;
  120. struct knav_reg_region __iomem *reg_region;
  121. struct knav_reg_queue __iomem *reg_push, *reg_pop, *reg_peek;
  122. void __iomem *reg_status;
  123. struct list_head list;
  124. };
  125. #define KNAV_NUM_LINKRAM 2
  126. /**
  127. * struct knav_queue_stats: queue statistics
  128. * pushes: number of push operations
  129. * pops: number of pop operations
  130. * push_errors: number of push errors
  131. * pop_errors: number of pop errors
  132. * notifies: notifier counts
  133. */
  134. struct knav_queue_stats {
  135. unsigned int pushes;
  136. unsigned int pops;
  137. unsigned int push_errors;
  138. unsigned int pop_errors;
  139. unsigned int notifies;
  140. };
  141. /**
  142. * struct knav_reg_queue: queue registers
  143. * @entry_count: valid entries in the queue
  144. * @byte_count: total byte count in thhe queue
  145. * @packet_size: packet size for the queue
  146. * @ptr_size_thresh: packet pointer size threshold
  147. */
  148. struct knav_reg_queue {
  149. u32 entry_count;
  150. u32 byte_count;
  151. u32 packet_size;
  152. u32 ptr_size_thresh;
  153. };
  154. /**
  155. * struct knav_region: qmss region info
  156. * @dma_start, dma_end: start and end dma address
  157. * @virt_start, virt_end: start and end virtual address
  158. * @desc_size: descriptor size
  159. * @used_desc: consumed descriptors
  160. * @id: region number
  161. * @num_desc: total descriptors
  162. * @link_index: index of the first descriptor
  163. * @name: region name
  164. * @list: instance in the device's region list
  165. * @pools: list of descriptor pools in the region
  166. */
  167. struct knav_region {
  168. dma_addr_t dma_start, dma_end;
  169. void *virt_start, *virt_end;
  170. unsigned desc_size;
  171. unsigned used_desc;
  172. unsigned id;
  173. unsigned num_desc;
  174. unsigned link_index;
  175. const char *name;
  176. struct list_head list;
  177. struct list_head pools;
  178. };
  179. /**
  180. * struct knav_pool: qmss pools
  181. * @dev: device pointer
  182. * @region: qmss region info
  183. * @queue: queue registers
  184. * @kdev: qmss device pointer
  185. * @region_offset: offset from the base
  186. * @num_desc: total descriptors
  187. * @desc_size: descriptor size
  188. * @region_id: region number
  189. * @name: pool name
  190. * @list: list head
  191. * @region_inst: instance in the region's pool list
  192. */
  193. struct knav_pool {
  194. struct device *dev;
  195. struct knav_region *region;
  196. struct knav_queue *queue;
  197. struct knav_device *kdev;
  198. int region_offset;
  199. int num_desc;
  200. int desc_size;
  201. int region_id;
  202. const char *name;
  203. struct list_head list;
  204. struct list_head region_inst;
  205. };
  206. /**
  207. * struct knav_queue_inst: qmss queue instance properties
  208. * @descs: descriptor pointer
  209. * @desc_head, desc_tail, desc_count: descriptor counters
  210. * @acc: accumulator channel pointer
  211. * @kdev: qmss device pointer
  212. * @range: range info
  213. * @qmgr: queue manager info
  214. * @id: queue instance id
  215. * @irq_num: irq line number
  216. * @notify_needed: notifier needed based on queue type
  217. * @num_notifiers: total notifiers
  218. * @handles: list head
  219. * @name: queue instance name
  220. * @irq_name: irq line name
  221. */
  222. struct knav_queue_inst {
  223. u32 *descs;
  224. atomic_t desc_head, desc_tail, desc_count;
  225. struct knav_acc_channel *acc;
  226. struct knav_device *kdev;
  227. struct knav_range_info *range;
  228. struct knav_qmgr_info *qmgr;
  229. u32 id;
  230. int irq_num;
  231. int notify_needed;
  232. atomic_t num_notifiers;
  233. struct list_head handles;
  234. const char *name;
  235. const char *irq_name;
  236. };
  237. /**
  238. * struct knav_queue: qmss queue properties
  239. * @reg_push, reg_pop, reg_peek: push, pop queue registers
  240. * @inst: qmss queue instance properties
  241. * @notifier_fn: notifier function
  242. * @notifier_fn_arg: notifier function argument
  243. * @notifier_enabled: notier enabled for a give queue
  244. * @rcu: rcu head
  245. * @flags: queue flags
  246. * @list: list head
  247. */
  248. struct knav_queue {
  249. struct knav_reg_queue __iomem *reg_push, *reg_pop, *reg_peek;
  250. struct knav_queue_inst *inst;
  251. struct knav_queue_stats __percpu *stats;
  252. knav_queue_notify_fn notifier_fn;
  253. void *notifier_fn_arg;
  254. atomic_t notifier_enabled;
  255. struct rcu_head rcu;
  256. unsigned flags;
  257. struct list_head list;
  258. };
  259. enum qmss_version {
  260. QMSS,
  261. QMSS_66AK2G,
  262. };
  263. struct knav_device {
  264. struct device *dev;
  265. unsigned base_id;
  266. unsigned num_queues;
  267. unsigned num_queues_in_use;
  268. unsigned inst_shift;
  269. struct knav_link_ram_block link_rams[KNAV_NUM_LINKRAM];
  270. void *instances;
  271. struct list_head regions;
  272. struct list_head queue_ranges;
  273. struct list_head pools;
  274. struct list_head pdsps;
  275. struct list_head qmgrs;
  276. enum qmss_version version;
  277. };
  278. struct knav_range_ops {
  279. int (*init_range)(struct knav_range_info *range);
  280. int (*free_range)(struct knav_range_info *range);
  281. int (*init_queue)(struct knav_range_info *range,
  282. struct knav_queue_inst *inst);
  283. int (*open_queue)(struct knav_range_info *range,
  284. struct knav_queue_inst *inst, unsigned flags);
  285. int (*close_queue)(struct knav_range_info *range,
  286. struct knav_queue_inst *inst);
  287. int (*set_notify)(struct knav_range_info *range,
  288. struct knav_queue_inst *inst, bool enabled);
  289. };
  290. struct knav_irq_info {
  291. int irq;
  292. struct cpumask *cpu_mask;
  293. };
  294. struct knav_range_info {
  295. const char *name;
  296. struct knav_device *kdev;
  297. unsigned queue_base;
  298. unsigned num_queues;
  299. void *queue_base_inst;
  300. unsigned flags;
  301. struct list_head list;
  302. struct knav_range_ops *ops;
  303. struct knav_acc_info acc_info;
  304. struct knav_acc_channel *acc;
  305. unsigned num_irqs;
  306. struct knav_irq_info irqs[RANGE_MAX_IRQS];
  307. };
  308. #define RANGE_RESERVED BIT(0)
  309. #define RANGE_HAS_IRQ BIT(1)
  310. #define RANGE_HAS_ACCUMULATOR BIT(2)
  311. #define RANGE_MULTI_QUEUE BIT(3)
  312. #define for_each_region(kdev, region) \
  313. list_for_each_entry(region, &kdev->regions, list)
  314. #define first_region(kdev) \
  315. list_first_entry_or_null(&kdev->regions, \
  316. struct knav_region, list)
  317. #define for_each_queue_range(kdev, range) \
  318. list_for_each_entry(range, &kdev->queue_ranges, list)
  319. #define first_queue_range(kdev) \
  320. list_first_entry_or_null(&kdev->queue_ranges, \
  321. struct knav_range_info, list)
  322. #define for_each_pool(kdev, pool) \
  323. list_for_each_entry(pool, &kdev->pools, list)
  324. #define for_each_pdsp(kdev, pdsp) \
  325. list_for_each_entry(pdsp, &kdev->pdsps, list)
  326. #define for_each_qmgr(kdev, qmgr) \
  327. list_for_each_entry(qmgr, &kdev->qmgrs, list)
  328. static inline struct knav_pdsp_info *
  329. knav_find_pdsp(struct knav_device *kdev, unsigned pdsp_id)
  330. {
  331. struct knav_pdsp_info *pdsp;
  332. for_each_pdsp(kdev, pdsp)
  333. if (pdsp_id == pdsp->id)
  334. return pdsp;
  335. return NULL;
  336. }
  337. extern int knav_init_acc_range(struct knav_device *kdev,
  338. struct device_node *node,
  339. struct knav_range_info *range);
  340. extern void knav_queue_notify(struct knav_queue_inst *inst);
  341. #endif /* __KNAV_QMSS_H__ */