blob: cceae83ae920a5327fdc87393410e36a8d606b81 [file] [log] [blame]
Michael Adisumarta363f02f2018-01-24 16:21:04 -08001/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
Amir Levy9659e592016-10-27 18:08:27 +03002 *
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 _IPA_USB_H_
14#define _IPA_USB_H_
15
16enum ipa_usb_teth_prot {
17 IPA_USB_RNDIS = 0,
18 IPA_USB_ECM = 1,
19 IPA_USB_RMNET = 2,
20 IPA_USB_MBIM = 3,
21 IPA_USB_DIAG = 4,
22 IPA_USB_MAX_TETH_PROT_SIZE
23};
24
25/**
26 * ipa_usb_teth_params - parameters for RDNIS/ECM initialization API
27 *
28 * @host_ethaddr: host Ethernet address in network order
29 * @device_ethaddr: device Ethernet address in network order
30 */
31struct ipa_usb_teth_params {
32 u8 host_ethaddr[ETH_ALEN];
33 u8 device_ethaddr[ETH_ALEN];
34};
35
36enum ipa_usb_notify_event {
37 IPA_USB_DEVICE_READY,
38 IPA_USB_REMOTE_WAKEUP,
39 IPA_USB_SUSPEND_COMPLETED
40};
41
42enum ipa_usb_max_usb_packet_size {
43 IPA_USB_HIGH_SPEED_512B = 512,
44 IPA_USB_SUPER_SPEED_1024B = 1024
45};
46
47/**
48 * ipa_usb_teth_prot_params - parameters for connecting RNDIS
49 *
50 * @max_xfer_size_bytes_to_dev: max size of UL packets in bytes
51 * @max_packet_number_to_dev: max number of UL aggregated packets
52 * @max_xfer_size_bytes_to_host: max size of DL packets in bytes
53 *
54 */
55struct ipa_usb_teth_prot_params {
56 u32 max_xfer_size_bytes_to_dev;
57 u32 max_packet_number_to_dev;
58 u32 max_xfer_size_bytes_to_host;
59};
60
61/**
62 * ipa_usb_xdci_connect_params - parameters required to start IN, OUT
63 * channels, and connect RNDIS/ECM/teth_bridge
64 *
65 * @max_pkt_size: high speed or full speed
66 * @ipa_to_usb_xferrscidx: Transfer Resource Index (XferRscIdx) for IN channel.
67 * The hardware-assigned transfer resource index for the
68 * transfer, which was returned in response to the
69 * Start Transfer command. This field is used for
70 * "Update Transfer" command.
71 * Should be 0 =< ipa_to_usb_xferrscidx <= 127.
72 * @ipa_to_usb_xferrscidx_valid: true if xferRscIdx should be updated for IN
73 * channel
74 * @usb_to_ipa_xferrscidx: Transfer Resource Index (XferRscIdx) for OUT channel
75 * Should be 0 =< usb_to_ipa_xferrscidx <= 127.
76 * @usb_to_ipa_xferrscidx_valid: true if xferRscIdx should be updated for OUT
77 * channel
78 * @teth_prot: tethering protocol
79 * @teth_prot_params: parameters for connecting the tethering protocol.
80 * @max_supported_bandwidth_mbps: maximum bandwidth need of the client in Mbps
81 */
82struct ipa_usb_xdci_connect_params {
83 enum ipa_usb_max_usb_packet_size max_pkt_size;
84 u8 ipa_to_usb_xferrscidx;
85 bool ipa_to_usb_xferrscidx_valid;
86 u8 usb_to_ipa_xferrscidx;
87 bool usb_to_ipa_xferrscidx_valid;
88 enum ipa_usb_teth_prot teth_prot;
89 struct ipa_usb_teth_prot_params teth_prot_params;
90 u32 max_supported_bandwidth_mbps;
91};
92
93/**
94 * ipa_usb_xdci_chan_scratch - xDCI protocol SW config area of
95 * channel scratch
96 *
97 * @last_trb_addr_iova: Address (iova LSB - based on alignment restrictions) of
98 * last TRB in queue. Used to identify roll over case
99 * @const_buffer_size: TRB buffer size in KB (similar to IPA aggregation
100 * configuration). Must be aligned to max USB Packet Size.
101 * Should be 1 <= const_buffer_size <= 31.
102 * @depcmd_low_addr: Used to generate "Update Transfer" command
103 * @depcmd_hi_addr: Used to generate "Update Transfer" command.
104 */
105struct ipa_usb_xdci_chan_scratch {
106 u16 last_trb_addr_iova;
107 u8 const_buffer_size;
108 u32 depcmd_low_addr;
109 u8 depcmd_hi_addr;
110};
111
112/**
113 * ipa_usb_xdci_chan_params - xDCI channel related properties
114 *
115 * @client: type of "client"
116 * @ipa_ep_cfg: IPA EP configuration
117 * @keep_ipa_awake: when true, IPA will not be clock gated
118 * @teth_prot: tethering protocol for which the channel is created
119 * @gevntcount_low_addr: GEVNCOUNT low address for event scratch
120 * @gevntcount_hi_addr: GEVNCOUNT high address for event scratch
121 * @dir: channel direction
122 * @xfer_ring_len: length of transfer ring in bytes (must be integral
123 * multiple of transfer element size - 16B for xDCI)
Amir Levy9659e592016-10-27 18:08:27 +0300124 * @xfer_scratch: parameters for xDCI channel scratch
Michael Adisumarta363f02f2018-01-24 16:21:04 -0800125 * @xfer_ring_base_addr_iova: IO virtual address mapped to pysical base address
Amir Levy9659e592016-10-27 18:08:27 +0300126 * @data_buff_base_len: length of data buffer allocated by USB driver
Michael Adisumarta363f02f2018-01-24 16:21:04 -0800127 * @data_buff_base_addr_iova: IO virtual address mapped to pysical base address
128 * @sgt_xfer_rings: Scatter table for Xfer rings,contains valid non NULL
129 * value
130 * when USB S1-SMMU enabed, else NULL.
131 * @sgt_data_buff: Scatter table for data buffs,contains valid non NULL
132 * value
133 * when USB S1-SMMU enabed, else NULL.
Amir Levy9659e592016-10-27 18:08:27 +0300134 *
135 */
136struct ipa_usb_xdci_chan_params {
137 /* IPA EP params */
138 enum ipa_client_type client;
139 struct ipa_ep_cfg ipa_ep_cfg;
140 bool keep_ipa_awake;
141 enum ipa_usb_teth_prot teth_prot;
142 /* event ring params */
143 u32 gevntcount_low_addr;
144 u8 gevntcount_hi_addr;
145 /* transfer ring params */
146 enum gsi_chan_dir dir;
147 u16 xfer_ring_len;
Amir Levy9659e592016-10-27 18:08:27 +0300148 struct ipa_usb_xdci_chan_scratch xfer_scratch;
149 u64 xfer_ring_base_addr_iova;
150 u32 data_buff_base_len;
Amir Levy9659e592016-10-27 18:08:27 +0300151 u64 data_buff_base_addr_iova;
Michael Adisumarta363f02f2018-01-24 16:21:04 -0800152 struct sg_table *sgt_xfer_rings;
153 struct sg_table *sgt_data_buff;
Amir Levy9659e592016-10-27 18:08:27 +0300154};
155
156/**
157 * ipa_usb_chan_out_params - out parameters for channel request
158 *
159 * @clnt_hdl: opaque client handle assigned by IPA to client
160 * @db_reg_phs_addr_lsb: Physical address of doorbell register where the 32
161 * LSBs of the doorbell value should be written
162 * @db_reg_phs_addr_msb: Physical address of doorbell register where the 32
163 * MSBs of the doorbell value should be written
164 *
165 */
166struct ipa_req_chan_out_params {
167 u32 clnt_hdl;
168 u32 db_reg_phs_addr_lsb;
169 u32 db_reg_phs_addr_msb;
170};
171
172#ifdef CONFIG_IPA3
173
174/**
175 * ipa_usb_init_teth_prot - Peripheral should call this function to initialize
176 * RNDIS/ECM/teth_bridge/DPL, prior to calling ipa_usb_xdci_connect()
177 *
178 * @usb_teth_type: tethering protocol type
179 * @teth_params: pointer to tethering protocol parameters.
180 * Should be struct ipa_usb_teth_params for RNDIS/ECM,
181 * or NULL for teth_bridge
182 * @ipa_usb_notify_cb: will be called to notify USB driver on certain events
183 * @user_data: cookie used for ipa_usb_notify_cb
184 *
185 * @Return 0 on success, negative on failure
186 */
187int ipa_usb_init_teth_prot(enum ipa_usb_teth_prot teth_prot,
188 struct ipa_usb_teth_params *teth_params,
189 int (*ipa_usb_notify_cb)(enum ipa_usb_notify_event,
190 void *),
191 void *user_data);
192
193/**
194 * ipa_usb_xdci_connect - Peripheral should call this function to start IN &
195 * OUT xDCI channels, and connect RNDIS/ECM/MBIM/RMNET.
196 * For DPL, only starts IN channel.
197 *
198 * @ul_chan_params: parameters for allocating UL xDCI channel. containing
199 * required info on event and transfer rings, and IPA EP
200 * configuration
201 * @ul_out_params: [out] opaque client handle assigned by IPA to client & DB
202 * registers physical address for UL channel
203 * @dl_chan_params: parameters for allocating DL xDCI channel. containing
204 * required info on event and transfer rings, and IPA EP
205 * configuration
206 * @dl_out_params: [out] opaque client handle assigned by IPA to client & DB
207 * registers physical address for DL channel
208 * @connect_params: handles and scratch params of the required channels,
209 * tethering protocol and the tethering protocol parameters.
210 *
211 * Note: Should not be called from atomic context
212 *
213 * @Return 0 on success, negative on failure
214 */
215int ipa_usb_xdci_connect(struct ipa_usb_xdci_chan_params *ul_chan_params,
216 struct ipa_usb_xdci_chan_params *dl_chan_params,
217 struct ipa_req_chan_out_params *ul_out_params,
218 struct ipa_req_chan_out_params *dl_out_params,
219 struct ipa_usb_xdci_connect_params *connect_params);
220
221/**
222 * ipa_usb_xdci_disconnect - Peripheral should call this function to stop
223 * IN & OUT xDCI channels
224 * For DPL, only stops IN channel.
225 *
226 * @ul_clnt_hdl: client handle received from ipa_usb_xdci_connect()
227 * for OUT channel
228 * @dl_clnt_hdl: client handle received from ipa_usb_xdci_connect()
229 * for IN channel
230 * @teth_prot: tethering protocol
231 *
232 * Note: Should not be called from atomic context
233 *
234 * @Return 0 on success, negative on failure
235 */
236int ipa_usb_xdci_disconnect(u32 ul_clnt_hdl, u32 dl_clnt_hdl,
237 enum ipa_usb_teth_prot teth_prot);
238
239/**
240 * ipa_usb_deinit_teth_prot - Peripheral should call this function to deinit
241 * RNDIS/ECM/MBIM/RMNET
242 *
243 * @teth_prot: tethering protocol
244 *
245 * @Return 0 on success, negative on failure
246 */
247int ipa_usb_deinit_teth_prot(enum ipa_usb_teth_prot teth_prot);
248
249/**
250 * ipa_usb_xdci_suspend - Peripheral should call this function to suspend
251 * IN & OUT or DPL xDCI channels
252 *
253 * @ul_clnt_hdl: client handle previously obtained from
254 * ipa_usb_xdci_connect() for OUT channel
255 * @dl_clnt_hdl: client handle previously obtained from
256 * ipa_usb_xdci_connect() for IN channel
257 * @teth_prot: tethering protocol
Ghanim Fodi93a61112016-10-05 11:59:18 +0300258 * @with_remote_wakeup: Does host support remote wakeup?
Amir Levy9659e592016-10-27 18:08:27 +0300259 *
260 * Note: Should not be called from atomic context
261 * Note: for DPL, the ul will be ignored as irrelevant
262 *
263 * @Return 0 on success, negative on failure
264 */
265int ipa_usb_xdci_suspend(u32 ul_clnt_hdl, u32 dl_clnt_hdl,
Ghanim Fodi93a61112016-10-05 11:59:18 +0300266 enum ipa_usb_teth_prot teth_prot,
267 bool with_remote_wakeup);
Amir Levy9659e592016-10-27 18:08:27 +0300268
269/**
270 * ipa_usb_xdci_resume - Peripheral should call this function to resume
271 * IN & OUT or DPL xDCI channels
272 *
273 * @ul_clnt_hdl: client handle received from ipa_usb_xdci_connect()
274 * for OUT channel
275 * @dl_clnt_hdl: client handle received from ipa_usb_xdci_connect()
276 * for IN channel
277 * @teth_prot: tethering protocol
278 *
279 * Note: Should not be called from atomic context
280 * Note: for DPL, the ul will be ignored as irrelevant
281 *
282 * @Return 0 on success, negative on failure
283 */
284int ipa_usb_xdci_resume(u32 ul_clnt_hdl, u32 dl_clnt_hdl,
285 enum ipa_usb_teth_prot teth_prot);
286
287#else /* CONFIG_IPA3 */
288
289static inline int ipa_usb_init_teth_prot(enum ipa_usb_teth_prot teth_prot,
290 struct ipa_usb_teth_params *teth_params,
291 int (*ipa_usb_notify_cb)(enum ipa_usb_notify_event,
292 void *),
293 void *user_data)
294{
295 return -EPERM;
296}
297
298static inline int ipa_usb_xdci_connect(
299 struct ipa_usb_xdci_chan_params *ul_chan_params,
300 struct ipa_usb_xdci_chan_params *dl_chan_params,
301 struct ipa_req_chan_out_params *ul_out_params,
302 struct ipa_req_chan_out_params *dl_out_params,
303 struct ipa_usb_xdci_connect_params *connect_params)
304{
305 return -EPERM;
306}
307
308static inline int ipa_usb_xdci_disconnect(u32 ul_clnt_hdl, u32 dl_clnt_hdl,
309 enum ipa_usb_teth_prot teth_prot)
310{
311 return -EPERM;
312}
313
314static inline int ipa_usb_deinit_teth_prot(enum ipa_usb_teth_prot teth_prot)
315{
316 return -EPERM;
317}
318
319static inline int ipa_usb_xdci_suspend(u32 ul_clnt_hdl, u32 dl_clnt_hdl,
Ghanim Fodi93a61112016-10-05 11:59:18 +0300320 enum ipa_usb_teth_prot teth_prot,
321 bool with_remote_wakeup)
Amir Levy9659e592016-10-27 18:08:27 +0300322{
323 return -EPERM;
324}
325
326static inline int ipa_usb_xdci_resume(u32 ul_clnt_hdl, u32 dl_clnt_hdl,
327 enum ipa_usb_teth_prot teth_prot)
328{
329 return -EPERM;
330}
331
332
333#endif /* CONFIG_IPA3 */
334
335#endif /* _IPA_USB_H_ */