1 /* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
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.
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.
15 #include <linux/msm-sps.h>
16 #include <linux/ipa.h>
17 #include <linux/usb/msm_hsusb.h>
19 #define MAX_BAMS NUM_CTRL /* Bam per USB controllers */
33 enum usb_bam_pipe_dir {
34 USB_TO_PEER_PERIPHERAL,
35 PEER_PERIPHERAL_TO_USB,
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 */
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 */
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
55 USB_BAM_MAX_PIPE_TYPES,
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
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.
86 struct usb_bam_connect_ipa_params {
92 enum usb_bam_pipe_dir dir;
93 /* Parameters for Port Mapper */
96 /* client handle assigned by IPA to client */
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;
104 void (*notify)(void *priv, enum ipa_dp_evt_type evt,
106 int (*activity_notify)(void *priv);
107 int (*inactivity_notify)(void *priv);
109 bool reset_pipe_after_lpm;
110 enum usb_device_speed usb_connection_speed;
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.
121 struct usb_bam_event_info {
122 enum usb_bam_event_type type;
123 struct sps_register_event event;
124 int (*callback)(void *);
126 struct work_struct event_w;
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.
159 struct usb_bam_pipe_connect {
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;
172 u32 data_fifo_base_offset;
174 u32 desc_fifo_base_offset;
176 struct sps_mem_buffer data_mem_buf;
177 struct sps_mem_buffer desc_mem_buf;
178 struct usb_bam_event_info event;
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;
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
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
214 struct msm_usb_bam_data {
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;
229 #if IS_ENABLED(CONFIG_USB_BAM)
231 * Connect USB-to-Peripheral SPS connection.
233 * This function returns the allocated pipe number.
235 * @bam_type - USB BAM type - dwc3/CI/hsic
237 * @idx - Connection index.
239 * @bam_pipe_idx - allocated pipe index.
241 * @return 0 on success, negative value on error
244 int usb_bam_connect(enum usb_ctrl bam_type, int idx, u32 *bam_pipe_idx);
247 * Connect USB-to-IPA SPS connection.
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.
254 * @bam_type - USB BAM type - dwc3/CI/hsic
256 * @ipa_params - in/out parameters
258 * @return 0 on success, negative value on error
260 int usb_bam_connect_ipa(enum usb_ctrl bam_type,
261 struct usb_bam_connect_ipa_params *ipa_params);
264 * Disconnect USB-to-IPA SPS connection.
266 * @bam_type - USB BAM type - dwc3/CI/hsic
268 * @ipa_params - in/out parameters
270 * @return 0 on success, negative value on error
272 int usb_bam_disconnect_ipa(enum usb_ctrl bam_type,
273 struct usb_bam_connect_ipa_params *ipa_params);
276 * Register a wakeup callback from peer BAM.
278 * @bam_type - USB BAM type - dwc3/CI/hsic
280 * @idx - Connection index.
282 * @callback - the callback function
284 * @return 0 on success, negative value on error
286 int usb_bam_register_wake_cb(enum usb_ctrl bam_type, u8 idx,
287 int (*callback)(void *), void *param);
290 * Register callbacks for start/stop of transfers.
292 * @bam_type - USB BAM type - dwc3/CI/hsic
294 * @idx - Connection index
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
301 * @param - context that the caller can supply
303 * @return 0 on success, negative value on error
305 int usb_bam_register_start_stop_cbs(enum usb_ctrl bam_type,
307 void (*start)(void *, enum usb_bam_pipe_dir),
308 void (*stop)(void *, enum usb_bam_pipe_dir),
312 * Start usb suspend sequence
314 * @ipa_params - in/out parameters
316 * @bam_type - USB BAM type - dwc3/CI/hsic
318 void usb_bam_suspend(enum usb_ctrl bam_type,
319 struct usb_bam_connect_ipa_params *ipa_params);
322 * Start usb resume sequence
324 * @bam_type - USB BAM type - dwc3/CI/hsic
326 * @ipa_params - in/out parameters
328 void usb_bam_resume(enum usb_ctrl bam_type,
329 struct usb_bam_connect_ipa_params *ipa_params);
331 * Disconnect USB-to-Periperal SPS connection.
333 * @bam_type - USB BAM type - dwc3/CI/hsic
335 * @idx - Connection index.
337 * @return 0 on success, negative value on error
339 int usb_bam_disconnect_pipe(enum usb_ctrl bam_type, u8 idx);
342 * Returns usb bam connection parameters.
344 * @bam_type - USB BAM type - dwc3/CI/hsic
346 * @idx - Connection index.
348 * @usb_bam_pipe_idx - Usb bam pipe index.
350 * @desc_fifo - Descriptor fifo parameters.
352 * @data_fifo - Data fifo parameters.
354 * @return pipe index on success, negative value on error.
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);
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.
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);
375 * Indicates if the client of the USB BAM is ready to start
376 * sending/receiving transfers.
378 *@bam_type - USB BAM type - dwc3/CI/hsic
380 * @client - Usb pipe peer (a2, ipa, qdss...)
382 * @dir - In (from peer to usb) or out (from usb to peer)
384 * @num - Pipe number.
386 * @return 0 on success, negative value on error
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);
392 * return the usb controller bam type used for the supplied connection index
394 * @core_name - Core name (ssusb/hsusb/hsic).
396 * @return usb control bam type
398 int usb_bam_get_bam_type(const char *core_name);
401 * Indicates the type of connection the USB side of the connection is.
403 * @bam_type - USB BAM type - dwc3/CI/hsic
405 * @idx - Pipe number.
407 * @type - Type of connection
409 * @return 0 on success, negative value on error
411 int usb_bam_get_pipe_type(enum usb_ctrl bam_type,
412 u8 idx, enum usb_bam_pipe_type *type);
415 * Indicates whether USB producer is granted to IPA resource manager.
417 * @return true when producer granted, false when prodcuer is released.
419 bool usb_bam_get_prod_granted(enum usb_ctrl bam_type, u8 idx);
422 * Allocates memory for data fifo and descriptor fifos.
424 int usb_bam_alloc_fifos(enum usb_ctrl cur_bam, u8 idx);
427 * Frees memory for data fifo and descriptor fifos.
429 int usb_bam_free_fifos(enum usb_ctrl cur_bam, u8 idx);
432 static inline int usb_bam_connect(enum usb_ctrl bam, u8 idx, u32 *bam_pipe_idx)
437 static inline int usb_bam_connect_ipa(enum usb_ctrl bam_type,
438 struct usb_bam_connect_ipa_params *ipa_params)
443 static inline int usb_bam_disconnect_ipa(enum usb_ctrl bam_type,
444 struct usb_bam_connect_ipa_params *ipa_params)
449 static inline void usb_bam_wait_for_cons_granted(
450 struct usb_bam_connect_ipa_params *ipa_params)
455 static inline int usb_bam_register_wake_cb(enum usb_ctrl bam_type, u8 idx,
456 int (*callback)(void *), void *param)
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),
469 static inline void usb_bam_suspend(enum usb_ctrl bam_type,
470 struct usb_bam_connect_ipa_params *ipa_params){}
472 static inline void usb_bam_resume(enum usb_ctrl bam_type,
473 struct usb_bam_connect_ipa_params *ipa_params) {}
475 static inline int usb_bam_disconnect_pipe(enum usb_ctrl bam_type, u8 idx)
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)
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)
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)
502 static inline int usb_bam_get_bam_type(const char *core_nam)
507 static inline int usb_bam_get_pipe_type(enum usb_ctrl bam_type, u8 idx,
508 enum usb_bam_pipe_type *type)
513 static inline bool usb_bam_get_prod_granted(enum usb_ctrl bam_type, u8 idx)
518 int usb_bam_alloc_fifos(enum usb_ctrl cur_bam, u8 idx)
523 int usb_bam_free_fifos(enum usb_ctrl cur_bam, u8 idx)
529 #endif /* _USB_BAM_H_ */