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