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