sps_bam.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2011-2019, 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. /*
  7. * Function and data structure declarations for SPS BAM handling.
  8. */
  9. #ifndef _SPSBAM_H_
  10. #define _SPSBAM_H_
  11. #include <linux/types.h>
  12. #include <linux/completion.h>
  13. #include <linux/list.h>
  14. #include <linux/mutex.h>
  15. #include <linux/spinlock.h>
  16. #include "spsi.h"
  17. #define BAM_HANDLE_INVALID 0
  18. #define to_sps_bam_dev(x) \
  19. container_of((x), struct sps_bam, base)
  20. enum bam_irq {
  21. BAM_DEV_IRQ_RDY_TO_SLEEP = 0x00000001,
  22. BAM_DEV_IRQ_HRESP_ERROR = 0x00000002,
  23. BAM_DEV_IRQ_ERROR = 0x00000004,
  24. BAM_DEV_IRQ_TIMER = 0x00000010,
  25. };
  26. /* Pipe interrupt mask */
  27. enum bam_pipe_irq {
  28. /* BAM finishes descriptor which has INT bit selected */
  29. BAM_PIPE_IRQ_DESC_INT = 0x00000001,
  30. /* Inactivity timer Expires */
  31. BAM_PIPE_IRQ_TIMER = 0x00000002,
  32. /* Wakeup peripheral (i.e. USB) */
  33. BAM_PIPE_IRQ_WAKE = 0x00000004,
  34. /* Producer - no free space for adding a descriptor */
  35. /* Consumer - no descriptors for processing */
  36. BAM_PIPE_IRQ_OUT_OF_DESC = 0x00000008,
  37. /* Pipe Error interrupt */
  38. BAM_PIPE_IRQ_ERROR = 0x00000010,
  39. /* End-Of-Transfer */
  40. BAM_PIPE_IRQ_EOT = 0x00000020,
  41. /* Pipe RESET unsuccessful */
  42. BAM_PIPE_IRQ_RST_ERROR = 0x00000040,
  43. /* Errorneous Hresponse by AHB MASTER */
  44. BAM_PIPE_IRQ_HRESP_ERROR = 0x00000080,
  45. };
  46. /* Halt Type */
  47. enum bam_halt {
  48. BAM_HALT_OFF = 0,
  49. BAM_HALT_ON = 1,
  50. };
  51. /* Threshold values of the DMA channels */
  52. enum bam_dma_thresh_dma {
  53. BAM_DMA_THRESH_512 = 0x3,
  54. BAM_DMA_THRESH_256 = 0x2,
  55. BAM_DMA_THRESH_128 = 0x1,
  56. BAM_DMA_THRESH_64 = 0x0,
  57. };
  58. /* Weight values of the DMA channels */
  59. enum bam_dma_weight_dma {
  60. BAM_DMA_WEIGHT_HIGH = 7,
  61. BAM_DMA_WEIGHT_MED = 3,
  62. BAM_DMA_WEIGHT_LOW = 1,
  63. BAM_DMA_WEIGHT_DEFAULT = BAM_DMA_WEIGHT_LOW,
  64. BAM_DMA_WEIGHT_DISABLE = 0,
  65. };
  66. /* Invalid pipe index value */
  67. #define SPS_BAM_PIPE_INVALID ((u32)(-1))
  68. /* Parameters for sps_bam_pipe_connect() */
  69. struct sps_bam_connect_param {
  70. /* which end point must be initialized */
  71. enum sps_mode mode;
  72. /* OR'd connection end point options (see SPS_O defines) */
  73. u32 options;
  74. /* SETPEND/MTI interrupt generation parameters */
  75. u32 irq_gen_addr;
  76. u32 irq_gen_data;
  77. };
  78. /* Event registration struct */
  79. struct sps_bam_event_reg {
  80. /* Client's event object handle */
  81. struct completion *xfer_done;
  82. void (*callback)(struct sps_event_notify *notify);
  83. /* Event trigger mode */
  84. enum sps_trigger mode;
  85. /* User pointer that will be provided in event payload data */
  86. void *user;
  87. };
  88. /* Descriptor FIFO cache entry */
  89. struct sps_bam_desc_cache {
  90. struct sps_iovec iovec;
  91. void *user; /* User pointer registered with this transfer */
  92. };
  93. /* Forward declaration */
  94. struct sps_bam;
  95. /* System mode control */
  96. struct sps_bam_sys_mode {
  97. /* Descriptor FIFO control */
  98. u8 *desc_buf; /* Descriptor FIFO for BAM pipe */
  99. u32 desc_offset; /* Next new descriptor to be written to hardware */
  100. u32 acked_offset; /* Next descriptor to be retired by software */
  101. /* Descriptor cache control (!no_queue only) */
  102. u8 *desc_cache; /* Software cache of descriptor FIFO contents */
  103. u32 cache_offset; /* Next descriptor to be cached (ack_xfers only) */
  104. /* User pointers associated with cached descriptors */
  105. void **user_ptrs;
  106. /* Event handling */
  107. struct sps_bam_event_reg event_regs[SPS_EVENT_INDEX(SPS_EVENT_MAX)];
  108. struct list_head events_q;
  109. struct sps_q_event event; /* Temp storage for event creation */
  110. int no_queue; /* Whether events are queued */
  111. int ack_xfers; /* Whether client must ACK all descriptors */
  112. int handler_eot; /* Whether EOT handling is in progress (debug) */
  113. /* Statistics */
  114. #ifdef SPS_BAM_STATISTICS
  115. u32 desc_wr_count;
  116. u32 desc_rd_count;
  117. u32 user_ptrs_count;
  118. u32 user_found;
  119. u32 int_flags;
  120. u32 eot_flags;
  121. u32 callback_events;
  122. u32 wait_events;
  123. u32 queued_events;
  124. u32 get_events;
  125. u32 get_iovecs;
  126. #endif /* SPS_BAM_STATISTICS */
  127. };
  128. /* BAM pipe descriptor */
  129. struct sps_pipe {
  130. struct list_head list;
  131. /* Client state */
  132. u32 client_state;
  133. struct sps_bam *bam;
  134. struct sps_connect connect;
  135. const struct sps_connection *map;
  136. /* Pipe parameters */
  137. u32 state;
  138. u32 pipe_index;
  139. u32 pipe_index_mask;
  140. u32 irq_mask;
  141. int polled;
  142. int hybrid;
  143. bool late_eot;
  144. u32 irq_gen_addr;
  145. enum sps_mode mode;
  146. u32 num_descs; /* Size (number of elements) of descriptor FIFO */
  147. u32 desc_size; /* Size (bytes) of descriptor FIFO */
  148. int wake_up_is_one_shot; /* Whether WAKEUP event is a one-shot or not */
  149. /* System mode control */
  150. struct sps_bam_sys_mode sys;
  151. bool disconnecting;
  152. };
  153. /* BAM device descriptor */
  154. struct sps_bam {
  155. struct list_head list;
  156. /* BAM device properties, including connection defaults */
  157. struct sps_bam_props props;
  158. /* BAM device state */
  159. u32 state;
  160. struct mutex lock;
  161. void __iomem *base; /* BAM virtual base address */
  162. u32 version;
  163. spinlock_t isr_lock;
  164. spinlock_t connection_lock;
  165. unsigned long irqsave_flags;
  166. /* Pipe state */
  167. u32 pipe_active_mask;
  168. u32 pipe_remote_mask;
  169. struct sps_pipe *pipes[BAM_MAX_PIPES];
  170. struct list_head pipes_q;
  171. /* Statistics */
  172. u32 irq_from_disabled_pipe;
  173. u32 event_trigger_failures;
  174. void *ipc_log0;
  175. void *ipc_log1;
  176. void *ipc_log2;
  177. void *ipc_log3;
  178. void *ipc_log4;
  179. u32 ipc_loglevel;
  180. /* Desc cache pointers */
  181. u8 *desc_cache_pointers[BAM_MAX_PIPES];
  182. /* ISR behavior */
  183. bool no_serve_irq;
  184. };
  185. /**
  186. * BAM driver initialization
  187. *
  188. * This function initializes the BAM driver.
  189. *
  190. * @options - driver options bitflags (see SPS_OPT_*)
  191. *
  192. * @return 0 on success, negative value on error
  193. *
  194. */
  195. int sps_bam_driver_init(u32 options);
  196. /**
  197. * BAM device initialization
  198. *
  199. * This function initializes a BAM device.
  200. *
  201. * @dev - pointer to BAM device descriptor
  202. *
  203. * @return 0 on success, negative value on error
  204. *
  205. */
  206. int sps_bam_device_init(struct sps_bam *dev);
  207. /**
  208. * BAM device de-initialization
  209. *
  210. * This function de-initializes a BAM device.
  211. *
  212. * @dev - pointer to BAM device descriptor
  213. *
  214. * @return 0 on success, negative value on error
  215. *
  216. */
  217. int sps_bam_device_de_init(struct sps_bam *dev);
  218. /**
  219. * BAM device reset
  220. *
  221. * This Function resets a BAM device.
  222. *
  223. * @dev - pointer to BAM device descriptor
  224. *
  225. * @return 0 on success, negative value on error
  226. *
  227. */
  228. int sps_bam_reset(struct sps_bam *dev);
  229. /**
  230. * BAM device enable
  231. *
  232. * This function enables a BAM device.
  233. *
  234. * @dev - pointer to BAM device descriptor
  235. *
  236. * @return 0 on success, negative value on error
  237. *
  238. */
  239. int sps_bam_enable(struct sps_bam *dev);
  240. /**
  241. * BAM device disable
  242. *
  243. * This Function disables a BAM device.
  244. *
  245. * @dev - pointer to BAM device descriptor
  246. *
  247. * @return 0 on success, negative value on error
  248. *
  249. */
  250. int sps_bam_disable(struct sps_bam *dev);
  251. /**
  252. * Allocate a BAM pipe
  253. *
  254. * This function allocates a BAM pipe.
  255. *
  256. * @dev - pointer to BAM device descriptor
  257. *
  258. * @pipe_index - client-specified pipe index, or SPS_BAM_PIPE_INVALID if
  259. * any available pipe is acceptable
  260. *
  261. * @return - allocated pipe index, or SPS_BAM_PIPE_INVALID on error
  262. *
  263. */
  264. u32 sps_bam_pipe_alloc(struct sps_bam *dev, u32 pipe_index);
  265. /**
  266. * Free a BAM pipe
  267. *
  268. * This function frees a BAM pipe.
  269. *
  270. * @dev - pointer to BAM device descriptor
  271. *
  272. * @pipe_index - pipe index
  273. *
  274. */
  275. void sps_bam_pipe_free(struct sps_bam *dev, u32 pipe_index);
  276. /**
  277. * Establish BAM pipe connection
  278. *
  279. * This function establishes a connection for a BAM pipe (end point).
  280. *
  281. * @client - pointer to client pipe state struct
  282. *
  283. * @params - connection parameters
  284. *
  285. * @return 0 on success, negative value on error
  286. *
  287. */
  288. int sps_bam_pipe_connect(struct sps_pipe *client,
  289. const struct sps_bam_connect_param *params);
  290. /**
  291. * Disconnect a BAM pipe connection
  292. *
  293. * This function disconnects a connection for a BAM pipe (end point).
  294. *
  295. * @dev - pointer to BAM device descriptor
  296. *
  297. * @pipe_index - pipe index
  298. *
  299. * @return 0 on success, negative value on error
  300. *
  301. */
  302. int sps_bam_pipe_disconnect(struct sps_bam *dev, u32 pipe_index);
  303. /**
  304. * Set BAM pipe parameters
  305. *
  306. * This function sets parameters for a BAM pipe.
  307. *
  308. * @dev - pointer to BAM device descriptor
  309. *
  310. * @pipe_index - pipe index
  311. *
  312. * @options - bitflag options (see SPS_O_*)
  313. *
  314. * @return 0 on success, negative value on error
  315. *
  316. */
  317. int sps_bam_pipe_set_params(struct sps_bam *dev, u32 pipe_index, u32 options);
  318. /**
  319. * Enable a BAM pipe
  320. *
  321. * This function enables a BAM pipe. Note that this function
  322. * is separate from the pipe connect function to allow proper
  323. * sequencing of consumer enable followed by producer enable.
  324. *
  325. * @dev - pointer to BAM device descriptor
  326. *
  327. * @pipe_index - pipe index
  328. *
  329. * @return 0 on success, negative value on error
  330. *
  331. */
  332. int sps_bam_pipe_enable(struct sps_bam *dev, u32 pipe_index);
  333. /**
  334. * Disable a BAM pipe
  335. *
  336. * This function disables a BAM pipe.
  337. *
  338. * @dev - pointer to BAM device descriptor
  339. *
  340. * @pipe_index - pipe index
  341. *
  342. * @return 0 on success, negative value on error
  343. *
  344. */
  345. int sps_bam_pipe_disable(struct sps_bam *dev, u32 pipe_index);
  346. /**
  347. * Register an event for a BAM pipe
  348. *
  349. * This function registers an event for a BAM pipe.
  350. *
  351. * @dev - pointer to BAM device descriptor
  352. *
  353. * @pipe_index - pipe index
  354. *
  355. * @reg - pointer to event registration struct
  356. *
  357. * @return 0 on success, negative value on error
  358. *
  359. */
  360. int sps_bam_pipe_reg_event(struct sps_bam *dev, u32 pipe_index,
  361. struct sps_register_event *reg);
  362. /**
  363. * Submit a transfer of a single buffer to a BAM pipe
  364. *
  365. * This function submits a transfer of a single buffer to a BAM pipe.
  366. *
  367. * @dev - pointer to BAM device descriptor
  368. *
  369. * @pipe_index - pipe index
  370. *
  371. * @addr - physical address of buffer to transfer
  372. *
  373. * @size - number of bytes to transfer
  374. *
  375. * @user - user pointer to register for event
  376. *
  377. * @flags - descriptor flags (see SPS_IOVEC_FLAG defines)
  378. *
  379. * @return 0 on success, negative value on error
  380. *
  381. */
  382. int sps_bam_pipe_transfer_one(struct sps_bam *dev, u32 pipe_index, u32 addr,
  383. u32 size, void *user, u32 flags);
  384. /**
  385. * Submit a transfer to a BAM pipe
  386. *
  387. * This function submits a transfer to a BAM pipe.
  388. *
  389. * @dev - pointer to BAM device descriptor
  390. *
  391. * @pipe_index - pipe index
  392. *
  393. * @transfer - pointer to transfer struct
  394. *
  395. * @return 0 on success, negative value on error
  396. *
  397. */
  398. int sps_bam_pipe_transfer(struct sps_bam *dev, u32 pipe_index,
  399. struct sps_transfer *transfer);
  400. /**
  401. * Get a BAM pipe event
  402. *
  403. * This function polls for a BAM pipe event.
  404. *
  405. * @dev - pointer to BAM device descriptor
  406. *
  407. * @pipe_index - pipe index
  408. *
  409. * @notify - pointer to event notification struct
  410. *
  411. * @return 0 on success, negative value on error
  412. *
  413. */
  414. int sps_bam_pipe_get_event(struct sps_bam *dev, u32 pipe_index,
  415. struct sps_event_notify *notify);
  416. /**
  417. * Get processed I/O vector
  418. *
  419. * This function fetches the next processed I/O vector.
  420. *
  421. * @dev - pointer to BAM device descriptor
  422. *
  423. * @pipe_index - pipe index
  424. *
  425. * @iovec - Pointer to I/O vector struct (output).
  426. * This struct will be zeroed if there are no more processed I/O vectors.
  427. *
  428. * @return 0 on success, negative value on error
  429. */
  430. int sps_bam_pipe_get_iovec(struct sps_bam *dev, u32 pipe_index,
  431. struct sps_iovec *iovec);
  432. /**
  433. * Determine whether a BAM pipe descriptor FIFO is empty
  434. *
  435. * This function returns the empty state of a BAM pipe descriptor FIFO.
  436. *
  437. * The pipe mutex must be locked before calling this function.
  438. *
  439. * @dev - pointer to BAM device descriptor
  440. *
  441. * @pipe_index - pipe index
  442. *
  443. * @empty - pointer to client's empty status word (boolean)
  444. *
  445. * @return 0 on success, negative value on error
  446. *
  447. */
  448. int sps_bam_pipe_is_empty(struct sps_bam *dev, u32 pipe_index, u32 *empty);
  449. /**
  450. * Get number of free slots in a BAM pipe descriptor FIFO
  451. *
  452. * This function returns the number of free slots in a BAM pipe descriptor FIFO.
  453. *
  454. * The pipe mutex must be locked before calling this function.
  455. *
  456. * @dev - pointer to BAM device descriptor
  457. *
  458. * @pipe_index - pipe index
  459. *
  460. * @count - pointer to count status
  461. *
  462. * @return 0 on success, negative value on error
  463. *
  464. */
  465. int sps_bam_get_free_count(struct sps_bam *dev, u32 pipe_index, u32 *count);
  466. /**
  467. * Set BAM pipe to satellite ownership
  468. *
  469. * This function sets the BAM pipe to satellite ownership.
  470. *
  471. * @dev - pointer to BAM device descriptor
  472. *
  473. * @pipe_index - pipe index
  474. *
  475. * @return 0 on success, negative value on error
  476. *
  477. */
  478. int sps_bam_set_satellite(struct sps_bam *dev, u32 pipe_index);
  479. /**
  480. * Perform BAM pipe timer control
  481. *
  482. * This function performs BAM pipe timer control operations.
  483. *
  484. * @dev - pointer to BAM device descriptor
  485. *
  486. * @pipe_index - pipe index
  487. *
  488. * @timer_ctrl - Pointer to timer control specification
  489. *
  490. * @timer_result - Pointer to buffer for timer operation result.
  491. * This argument can be NULL if no result is expected for the operation.
  492. * If non-NULL, the current timer value will always provided.
  493. *
  494. * @return 0 on success, negative value on error
  495. *
  496. */
  497. int sps_bam_pipe_timer_ctrl(struct sps_bam *dev, u32 pipe_index,
  498. struct sps_timer_ctrl *timer_ctrl,
  499. struct sps_timer_result *timer_result);
  500. /**
  501. * Get the number of unused descriptors in the descriptor FIFO
  502. * of a pipe
  503. *
  504. * @dev - pointer to BAM device descriptor
  505. *
  506. * @pipe_index - pipe index
  507. *
  508. * @desc_num - number of unused descriptors
  509. *
  510. */
  511. int sps_bam_pipe_get_unused_desc_num(struct sps_bam *dev, u32 pipe_index,
  512. u32 *desc_num);
  513. /*
  514. * sps_bam_check_irq - check IRQ of a BAM device.
  515. * @dev - pointer to BAM device descriptor
  516. *
  517. * This function checks any pending interrupt of a BAM device.
  518. *
  519. * Return: 0 on success, negative value on error
  520. */
  521. int sps_bam_check_irq(struct sps_bam *dev);
  522. /*
  523. * sps_bam_enable_all_irqs - Enable all IRQs of a BAM
  524. * @dev - pointer to BAM device descriptor
  525. *
  526. * This function enables all irqs of a BAM and its pipes.
  527. *
  528. */
  529. void sps_bam_enable_all_irqs(struct sps_bam *dev);
  530. /*
  531. * sps_bam_disable_all_irqs - Disable all IRQs of a BAM
  532. * @dev - pointer to BAM device descriptor
  533. *
  534. * This function disables all irqs of a BAM and its pipes.
  535. *
  536. */
  537. void sps_bam_disable_all_irqs(struct sps_bam *dev);
  538. /*
  539. * sps_bam_pipe_pending_desc - checking pending descriptor.
  540. * @dev: BAM device handle
  541. * @pipe_index: pipe index
  542. *
  543. * This function checks if a pipe of a BAM has any pending descriptor.
  544. *
  545. * @return true if there is any desc pending
  546. */
  547. bool sps_bam_pipe_pending_desc(struct sps_bam *dev, u32 pipe_index);
  548. /*
  549. * sps_bam_pipe_inject_zlt - inject a ZLT with EOT.
  550. * @dev: BAM device handle
  551. * @pipe_index: pipe index
  552. *
  553. * This function injects a ZLT with EOT for a pipe of a BAM.
  554. *
  555. * Return: 0 on success, negative value on error
  556. */
  557. int sps_bam_pipe_inject_zlt(struct sps_bam *dev, u32 pipe_index);
  558. #endif /* _SPSBAM_H_ */