OSDN Git Service

f2fs: Revert rapid GC
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / include / linux / usb_bam.h
1 /* Copyright (c) 2011-2017, 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 #ifndef _USB_BAM_H_
14 #define _USB_BAM_H_
15 #include <linux/msm-sps.h>
16 #include <linux/ipa.h>
17 #include <linux/usb/msm_hsusb.h>
18
19 #define MAX_BAMS        NUM_CTRL        /* Bam per USB controllers */
20
21
22 enum usb_bam_mode {
23         USB_BAM_DEVICE = 0,
24         USB_BAM_HOST,
25 };
26
27 enum peer_bam {
28         QDSS_P_BAM = 0,
29         IPA_P_BAM,
30         MAX_PEER_BAMS,
31 };
32
33 enum usb_bam_pipe_dir {
34         USB_TO_PEER_PERIPHERAL,
35         PEER_PERIPHERAL_TO_USB,
36 };
37
38 enum usb_pipe_mem_type {
39         SPS_PIPE_MEM = 0,       /* Default, SPS dedicated pipe memory */
40         SYSTEM_MEM,             /* System RAM, requires allocation */
41         OCI_MEM,                /* Shared memory among peripherals */
42 };
43
44 enum usb_bam_event_type {
45         USB_BAM_EVENT_WAKEUP_PIPE = 0,  /* Wake a pipe */
46         USB_BAM_EVENT_WAKEUP,           /* Wake a bam (first pipe waked) */
47         USB_BAM_EVENT_INACTIVITY,       /* Inactivity on all pipes */
48 };
49
50 enum usb_bam_pipe_type {
51         USB_BAM_PIPE_BAM2BAM = 0,       /* Connection is BAM2BAM (default) */
52         USB_BAM_PIPE_SYS2BAM,           /* Connection is SYS2BAM or BAM2SYS
53                                          * depending on usb_bam_pipe_dir
54                                          */
55         USB_BAM_MAX_PIPE_TYPES,
56 };
57
58 /**
59 * struct usb_bam_connect_ipa_params: Connect Bam pipe to IPA peer infromation.
60 * @ src_idx: Source pipe index in usb bam pipes lists.
61 * @ dst_idx: Destination pipe index in usb bam pipes lists.
62 * @ src_pipe: The source pipe index in the sps level.
63 * @ dst_pipe: The destination pipe index in the sps level.
64 * @ keep_ipa_awake: When true, IPA will not be clock gated.
65 * @ ipa_cons_ep_idx: The pipe index on the IPA peer bam side, consumer.
66 * @ ipa_prod_ep_idx: The pipe index on the IPA peer bam side, producer.
67 * @ prod_clnt_hdl: Producer client handle returned by IPA driver
68 * @ cons_clnt_hdl: Consumer client handle returned by IPA driver
69 * @ src_client: Source IPA client type.
70 * @ dst_client: Destination IPA client type.
71 * @ ipa_ep_cfg: Configuration of IPA end-point (see struct ipa_ep_cfg)
72 * @priv: Callback cookie to the notify event.
73 * @notify: Callback on data path event by IPA (see enum ipa_dp_evt_type)
74 *        This call back gets back the priv cookie.
75 *        for Bam2Bam mode, this callback is in the tethering bridge.
76 * @ activity_notify: Callback to be notified on and data being pushed into the
77 *                USB consumer pipe.
78 * @ inactivity_notify: Callback to be notified on inactivity of all the current
79 *                  open pipes between the USB bam and its peer.
80 * @ skip_ep_cfg: boolean field that determines if Apps-processor
81 *                   should or should not confiugre this end-point.
82 *                   (Please see struct teth_bridge_init_params)
83 * @ reset_pipe_after_lpm: bool to indicate if IPA should reset pipe after LPM.
84 * @ usb_connection_speed: The actual speed the USB core currently works at.
85 */
86 struct usb_bam_connect_ipa_params {
87         u8 src_idx;
88         u8 dst_idx;
89         u32 *src_pipe;
90         u32 *dst_pipe;
91         bool keep_ipa_awake;
92         enum usb_bam_pipe_dir dir;
93         /* Parameters for Port Mapper */
94         u32 ipa_cons_ep_idx;
95         u32 ipa_prod_ep_idx;
96         /* client handle assigned by IPA to client */
97         u32 prod_clnt_hdl;
98         u32 cons_clnt_hdl;
99         /* params assigned by the CD */
100         enum ipa_client_type src_client;
101         enum ipa_client_type dst_client;
102         struct ipa_ep_cfg ipa_ep_cfg;
103         void *priv;
104         void (*notify)(void *priv, enum ipa_dp_evt_type evt,
105                         unsigned long data);
106         int (*activity_notify)(void *priv);
107         int (*inactivity_notify)(void *priv);
108         bool skip_ep_cfg;
109         bool reset_pipe_after_lpm;
110         enum usb_device_speed usb_connection_speed;
111 };
112
113 /**
114 * struct usb_bam_event_info: suspend/resume event information.
115 * @type: usb bam event type.
116 * @event: holds event data.
117 * @callback: suspend/resume callback.
118 * @param: port num (for suspend) or NULL (for resume).
119 * @event_w: holds work queue parameters.
120 */
121 struct usb_bam_event_info {
122         enum usb_bam_event_type type;
123         struct sps_register_event event;
124         int (*callback)(void *);
125         void *param;
126         struct work_struct event_w;
127 };
128
129 /**
130 * struct usb_bam_pipe_connect: pipe connection information
131 * between USB/HSIC BAM and another BAM. USB/HSIC BAM can be
132 * either src BAM or dst BAM
133 * @name: pipe description.
134 * @mem_type: type of memory used for BAM FIFOs
135 * @src_phy_addr: src bam physical address.
136 * @src_pipe_index: src bam pipe index.
137 * @dst_phy_addr: dst bam physical address.
138 * @dst_pipe_index: dst bam pipe index.
139 * @data_fifo_base_offset: data fifo offset.
140 * @data_fifo_size: data fifo size.
141 * @desc_fifo_base_offset: descriptor fifo offset.
142 * @desc_fifo_size: descriptor fifo size.
143 * @data_mem_buf: data fifo buffer.
144 * @desc_mem_buf: descriptor fifo buffer.
145 * @event: event for wakeup.
146 * @enabled: true if pipe is enabled.
147 * @suspended: true if pipe is suspended.
148 * @cons_stopped: true is pipe has consumer requests stopped.
149 * @prod_stopped: true if pipe has producer requests stopped.
150 * @ipa_clnt_hdl : pipe handle to ipa api.
151 * @priv: private data to return upon activity_notify
152 *       or inactivity_notify callbacks.
153 * @activity_notify: callback to invoke on activity on one of the in pipes.
154 * @inactivity_notify: callback to invoke on inactivity on all pipes.
155 * @start: callback to invoke to enqueue transfers on a pipe.
156 * @stop: callback to invoke on dequeue transfers on a pipe.
157 * @start_stop_param: param for the start/stop callbacks.
158 */
159 struct usb_bam_pipe_connect {
160         const char *name;
161         u32 pipe_num;
162         enum usb_pipe_mem_type mem_type;
163         enum usb_bam_pipe_dir dir;
164         enum usb_ctrl bam_type;
165         enum usb_bam_mode bam_mode;
166         enum peer_bam peer_bam;
167         enum usb_bam_pipe_type pipe_type;
168         u32 src_phy_addr;
169         u32 src_pipe_index;
170         u32 dst_phy_addr;
171         u32 dst_pipe_index;
172         u32 data_fifo_base_offset;
173         u32 data_fifo_size;
174         u32 desc_fifo_base_offset;
175         u32 desc_fifo_size;
176         struct sps_mem_buffer data_mem_buf;
177         struct sps_mem_buffer desc_mem_buf;
178         struct usb_bam_event_info event;
179         bool enabled;
180         bool suspended;
181         bool cons_stopped;
182         bool prod_stopped;
183         int ipa_clnt_hdl;
184         void *priv;
185         int (*activity_notify)(void *priv);
186         int (*inactivity_notify)(void *priv);
187         void (*start)(void *, enum usb_bam_pipe_dir);
188         void (*stop)(void *, enum usb_bam_pipe_dir);
189         void *start_stop_param;
190         bool reset_pipe_after_lpm;
191 };
192
193 /**
194  * struct msm_usb_bam_data: pipe connection information
195  * between USB/HSIC BAM and another BAM. USB/HSIC BAM can be
196  * either src BAM or dst BAM
197  * @usb_bam_num_pipes: max number of pipes to use.
198  * @active_conn_num: number of active pipe connections.
199  * @usb_bam_fifo_baseaddr: base address for bam pipe's data and descriptor
200  *                         fifos. This can be on chip memory (ocimem) or usb
201  *                         private memory.
202  * @ignore_core_reset_ack: BAM can ignore ACK from USB core during PIPE RESET
203  * @reset_on_connect: BAM must be reset before its first pipe connect
204  * @reset_on_disconnect: BAM must be reset after its last pipe disconnect
205  * @disable_clk_gating: Disable clock gating
206  * @override_threshold: Override the default threshold value for Read/Write
207  *                         event generation by the BAM towards another BAM.
208  * @max_mbps_highspeed: Maximum Mbits per seconds that the USB core
209  *              can work at in bam2bam mode when connected to HS host.
210  * @max_mbps_superspeed: Maximum Mbits per seconds that the USB core
211  *              can work at in bam2bam mode when connected to SS host.
212  * @enable_hsusb_bam_on_boot: Enable HSUSB BAM (non-NDP) on bootup itself
213  */
214 struct msm_usb_bam_data {
215         u8 max_connections;
216         int usb_bam_num_pipes;
217         phys_addr_t usb_bam_fifo_baseaddr;
218         bool ignore_core_reset_ack;
219         bool reset_on_connect;
220         bool reset_on_disconnect;
221         bool disable_clk_gating;
222         u32 override_threshold;
223         u32 max_mbps_highspeed;
224         u32 max_mbps_superspeed;
225         bool enable_hsusb_bam_on_boot;
226         enum usb_ctrl bam_type;
227 };
228
229 #if  IS_ENABLED(CONFIG_USB_BAM)
230 /**
231  * Connect USB-to-Peripheral SPS connection.
232  *
233  * This function returns the allocated pipe number.
234  *
235  * @bam_type - USB BAM type - dwc3/CI/hsic
236  *
237  * @idx - Connection index.
238  *
239  * @bam_pipe_idx - allocated pipe index.
240  *
241  * @return 0 on success, negative value on error
242  *
243  */
244 int usb_bam_connect(enum usb_ctrl bam_type, int idx, u32 *bam_pipe_idx);
245
246 /**
247  * Connect USB-to-IPA SPS connection.
248  *
249  * This function returns the allocated pipes number and clnt
250  * handles. Assumes that the user first connects producer pipes
251  * and only after that consumer pipes, since that's the correct
252  * sequence for the handshake with the IPA.
253  *
254  * @bam_type - USB BAM type - dwc3/CI/hsic
255  *
256  * @ipa_params - in/out parameters
257  *
258  * @return 0 on success, negative value on error
259  */
260 int usb_bam_connect_ipa(enum usb_ctrl bam_type,
261                         struct usb_bam_connect_ipa_params *ipa_params);
262
263 /**
264  * Disconnect USB-to-IPA SPS connection.
265  *
266  * @bam_type - USB BAM type - dwc3/CI/hsic
267  *
268  * @ipa_params - in/out parameters
269  *
270  * @return 0 on success, negative value on error
271  */
272 int usb_bam_disconnect_ipa(enum usb_ctrl bam_type,
273                 struct usb_bam_connect_ipa_params *ipa_params);
274
275 /**
276  * Register a wakeup callback from peer BAM.
277  *
278  * @bam_type - USB BAM type - dwc3/CI/hsic
279  *
280  * @idx - Connection index.
281  *
282  * @callback - the callback function
283  *
284  * @return 0 on success, negative value on error
285  */
286 int usb_bam_register_wake_cb(enum usb_ctrl bam_type, u8 idx,
287         int (*callback)(void *), void *param);
288
289 /**
290  * Register callbacks for start/stop of transfers.
291  *
292  * @bam_type - USB BAM type - dwc3/CI/hsic
293  *
294  * @idx - Connection index
295  *
296  * @start - the callback function that will be called in USB
297  *                              driver to start transfers
298  * @stop - the callback function that will be called in USB
299  *                              driver to stop transfers
300  *
301  * @param - context that the caller can supply
302  *
303  * @return 0 on success, negative value on error
304  */
305 int usb_bam_register_start_stop_cbs(enum usb_ctrl bam_type,
306         u8 idx,
307         void (*start)(void *, enum usb_bam_pipe_dir),
308         void (*stop)(void *, enum usb_bam_pipe_dir),
309         void *param);
310
311 /**
312  * Start usb suspend sequence
313  *
314  * @ipa_params -  in/out parameters
315  *
316  * @bam_type - USB BAM type - dwc3/CI/hsic
317  */
318 void usb_bam_suspend(enum usb_ctrl bam_type,
319                      struct usb_bam_connect_ipa_params *ipa_params);
320
321 /**
322  * Start usb resume sequence
323  *
324  * @bam_type - USB BAM type - dwc3/CI/hsic
325  *
326  * @ipa_params -  in/out parameters
327  */
328 void usb_bam_resume(enum usb_ctrl bam_type,
329                      struct usb_bam_connect_ipa_params *ipa_params);
330 /**
331  * Disconnect USB-to-Periperal SPS connection.
332  *
333  * @bam_type - USB BAM type - dwc3/CI/hsic
334  *
335  * @idx - Connection index.
336  *
337  * @return 0 on success, negative value on error
338  */
339 int usb_bam_disconnect_pipe(enum usb_ctrl bam_type, u8 idx);
340
341 /**
342  * Returns usb bam connection parameters.
343  *
344  * @bam_type - USB BAM type - dwc3/CI/hsic
345  *
346  * @idx - Connection index.
347  *
348  * @usb_bam_pipe_idx - Usb bam pipe index.
349  *
350  * @desc_fifo - Descriptor fifo parameters.
351  *
352  * @data_fifo - Data fifo parameters.
353  *
354  * @return pipe index on success, negative value on error.
355  */
356 int get_bam2bam_connection_info(enum usb_ctrl bam_type, u8 idx,
357         u32 *usb_bam_pipe_idx, struct sps_mem_buffer *desc_fifo,
358         struct sps_mem_buffer *data_fifo, enum usb_pipe_mem_type *mem_type);
359
360 /**
361  * Returns usb bam connection parameters for qdss pipe.
362  * @usb_bam_handle - Usb bam handle.
363  * @usb_bam_pipe_idx - Usb bam pipe index.
364  * @peer_pipe_idx - Peer pipe index.
365  * @desc_fifo - Descriptor fifo parameters.
366  * @data_fifo - Data fifo parameters.
367  * @return pipe index on success, negative value on error.
368  */
369 int get_qdss_bam_connection_info(
370         unsigned long *usb_bam_handle, u32 *usb_bam_pipe_idx,
371         u32 *peer_pipe_idx, struct sps_mem_buffer *desc_fifo,
372         struct sps_mem_buffer *data_fifo, enum usb_pipe_mem_type *mem_type);
373
374 /**
375 * Indicates if the client of the USB BAM is ready to start
376 * sending/receiving transfers.
377 *
378 *@bam_type - USB BAM type - dwc3/CI/hsic
379 *
380 * @client - Usb pipe peer (a2, ipa, qdss...)
381 *
382 * @dir - In (from peer to usb) or out (from usb to peer)
383 *
384 * @num - Pipe number.
385 *
386 * @return 0 on success, negative value on error
387 */
388 int usb_bam_get_connection_idx(enum usb_ctrl bam_type, enum peer_bam client,
389         enum usb_bam_pipe_dir dir, enum usb_bam_mode bam_mode, u32 num);
390
391 /**
392 * return the usb controller bam type used for the supplied connection index
393 *
394 * @core_name - Core name (ssusb/hsusb/hsic).
395 *
396 * @return usb control bam type
397 */
398 int usb_bam_get_bam_type(const char *core_name);
399
400 /**
401 * Indicates the type of connection the USB side of the connection is.
402 *
403 * @bam_type - USB BAM type - dwc3/CI/hsic
404 *
405 * @idx - Pipe number.
406 *
407 * @type - Type of connection
408 *
409 * @return 0 on success, negative value on error
410 */
411 int usb_bam_get_pipe_type(enum usb_ctrl bam_type,
412                           u8 idx, enum usb_bam_pipe_type *type);
413
414 /**
415 * Indicates whether USB producer is granted to IPA resource manager.
416 *
417 * @return true when producer granted, false when prodcuer is released.
418 */
419 bool usb_bam_get_prod_granted(enum usb_ctrl bam_type, u8 idx);
420
421 /**
422 * Allocates memory for data fifo and descriptor fifos.
423 */
424 int usb_bam_alloc_fifos(enum usb_ctrl cur_bam, u8 idx);
425
426 /**
427 * Frees memory for data fifo and descriptor fifos.
428 */
429 int usb_bam_free_fifos(enum usb_ctrl cur_bam, u8 idx);
430
431 #else
432 static inline int usb_bam_connect(enum usb_ctrl bam, u8 idx, u32 *bam_pipe_idx)
433 {
434         return -ENODEV;
435 }
436
437 static inline int usb_bam_connect_ipa(enum usb_ctrl bam_type,
438                         struct usb_bam_connect_ipa_params *ipa_params)
439 {
440         return -ENODEV;
441 }
442
443 static inline int usb_bam_disconnect_ipa(enum usb_ctrl bam_type,
444                         struct usb_bam_connect_ipa_params *ipa_params)
445 {
446         return -ENODEV;
447 }
448
449 static inline void usb_bam_wait_for_cons_granted(
450                         struct usb_bam_connect_ipa_params *ipa_params)
451 {
452         return;
453 }
454
455 static inline int usb_bam_register_wake_cb(enum usb_ctrl bam_type, u8 idx,
456         int (*callback)(void *), void *param)
457 {
458         return -ENODEV;
459 }
460
461 static inline int usb_bam_register_start_stop_cbs(enum usb_ctrl bam, u8 idx,
462         void (*start)(void *, enum usb_bam_pipe_dir),
463         void (*stop)(void *, enum usb_bam_pipe_dir),
464         void *param)
465 {
466         return -ENODEV;
467 }
468
469 static inline void usb_bam_suspend(enum usb_ctrl bam_type,
470         struct usb_bam_connect_ipa_params *ipa_params){}
471
472 static inline void usb_bam_resume(enum usb_ctrl bam_type,
473         struct usb_bam_connect_ipa_params *ipa_params) {}
474
475 static inline int usb_bam_disconnect_pipe(enum usb_ctrl bam_type, u8 idx)
476 {
477         return -ENODEV;
478 }
479
480 static inline int get_bam2bam_connection_info(enum usb_ctrl bam_type, u8 idx,
481         u32 *usb_bam_pipe_idx, struct sps_mem_buffer *desc_fifo,
482         struct sps_mem_buffer *data_fifo, enum usb_pipe_mem_type *mem_type)
483 {
484         return -ENODEV;
485 }
486
487 static inline int get_qdss_bam_connection_info(
488         unsigned long *usb_bam_handle, u32 *usb_bam_pipe_idx,
489         u32 *peer_pipe_idx, struct sps_mem_buffer *desc_fifo,
490         struct sps_mem_buffer *data_fifo, enum usb_pipe_mem_type *mem_type)
491 {
492         return -ENODEV;
493 }
494
495 static inline int usb_bam_get_connection_idx(enum usb_ctrl bam_type,
496                 enum peer_bam client, enum usb_bam_pipe_dir dir,
497                 enum usb_bam_mode bam_mode, u32 num)
498 {
499         return -ENODEV;
500 }
501
502 static inline int usb_bam_get_bam_type(const char *core_nam)
503 {
504         return -ENODEV;
505 }
506
507 static inline int usb_bam_get_pipe_type(enum usb_ctrl bam_type, u8 idx,
508                                         enum usb_bam_pipe_type *type)
509 {
510         return -ENODEV;
511 }
512
513 static inline bool usb_bam_get_prod_granted(enum usb_ctrl bam_type, u8 idx)
514 {
515         return false;
516 }
517
518 int usb_bam_alloc_fifos(enum usb_ctrl cur_bam, u8 idx)
519 {
520         return false;
521 }
522
523 int usb_bam_free_fifos(enum usb_ctrl cur_bam, u8 idx)
524 {
525         return false;
526 }
527
528 #endif
529 #endif                          /* _USB_BAM_H_ */