sps_bam.h 14 KB

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