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