summaryrefslogtreecommitdiff
path: root/inc/mhi_misc.h
blob: 3108ac607057a1bd14fddd1051cad69dae7fe0fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
 *
 */

#ifndef _MHI_MISC_H_
#define _MHI_MISC_H_

#ifdef CONFIG_CNSS_OUT_OF_TREE
#include "mhi.h"
#include "ipc_logging.h"
#else
#include <linux/mhi.h>
#include <linux/ipc_logging.h>
#endif

/**
 * enum MHI_DEBUG_LEVEL - various debugging levels
 */
enum MHI_DEBUG_LEVEL {
	MHI_MSG_LVL_VERBOSE,
	MHI_MSG_LVL_INFO,
	MHI_MSG_LVL_ERROR,
	MHI_MSG_LVL_CRITICAL,
	MHI_MSG_LVL_MASK_ALL,
	MHI_MSG_LVL_MAX,
};

#ifdef CONFIG_MHI_BUS_MISC

/**
 * mhi_report_error - Can be used by controller to signal error condition to the
 * MHI core driver in case of any need to halt processing or incoming sideband
 * signal detects an error on endpoint
 * @mhi_cntrl: MHI controller
 *
 * Returns:
 * 0 if success in reporting the error condition to MHI core
 * error code on failure
 */
int mhi_report_error(struct mhi_controller *mhi_cntrl);

/**
 * mhi_controller_set_privdata - Set private data for MHI controller
 * @mhi_cntrl: MHI controller
 * @priv: pointer to data
 */
void mhi_controller_set_privdata(struct mhi_controller *mhi_cntrl, void *priv);

/**
 * mhi_controller_get_privdata - Get private data from MHI controller
 * @mhi_cntrl: MHI controller
 */
void *mhi_controller_get_privdata(struct mhi_controller *mhi_cntrl);

/**
 * mhi_bdf_to_controller - Get controller associated with given BDF values
 * @domain: Domain or root complex of PCIe port
 * @bus: Bus number
 * @slot: PCI slot or function number
 * @dev_id: Device ID of the endpoint
 *
 * Returns:
 * MHI controller structure pointer if BDF match is found
 * NULL if cookie is not found
 */
struct mhi_controller *mhi_bdf_to_controller(u32 domain, u32 bus, u32 slot, u32 dev_id);

/**
 * mhi_set_m2_timeout_ms - Set M2 timeout in milliseconds to wait before a
 * fast/silent suspend
 * @mhi_cntrl: MHI controller
 * @timeout: timeout in ms
 */
void mhi_set_m2_timeout_ms(struct mhi_controller *mhi_cntrl, u32 timeout);

/**
 * mhi_pm_fast_resume - Resume MHI from a fast/silent suspended state
 * @mhi_cntrl: MHI controller
 * @notify_clients: if true, clients will be notified of the resume transition
 */
int mhi_pm_fast_resume(struct mhi_controller *mhi_cntrl, bool notify_clients);

/**
 * mhi_pm_fast_suspend - Move MHI into a fast/silent suspended state
 * @mhi_cntrl: MHI controller
 * @notify_clients: if true, clients will be notified of the suspend transition
 */
int mhi_pm_fast_suspend(struct mhi_controller *mhi_cntrl, bool notify_clients);

/**
 * mhi_debug_reg_dump - dump MHI registers for debug purpose
 * @mhi_cntrl: MHI controller
 */
void mhi_debug_reg_dump(struct mhi_controller *mhi_cntrl);

/**
 * mhi_dump_sfr - Print SFR string from RDDM table.
 * @mhi_cntrl: MHI controller
 */
#if IS_ENABLED(CONFIG_WCN_GOOGLE)
void mhi_dump_sfr(struct mhi_controller *mhi_cntrl, void (*crash_info_handler)(u8*));
#else
void mhi_dump_sfr(struct mhi_controller *mhi_cntrl);
#endif //CONFIG_WCN_GOOGLE

/**
 * mhi_device_configure - Allow devices with offload channels to setup their own
 * channel and event ring context.
 * @mhi_dev: MHI device
 * @dir: direction associated with the channel needed to configure
 * @cfg_tbl: Buffer with ECA/CCA information and data needed to setup context
 * @elements: Number of items to iterate over from the configuration table
 */
int mhi_device_configure(struct mhi_device *mhi_dev,
			 enum dma_data_direction dir,
			 struct mhi_buf *cfg_tbl,
			 int elements);

/**
 * mhi_scan_rddm_cookie - Look for supplied cookie value in the BHI debug
 * registers set by device to indicate rddm readiness for debugging purposes.
 * @mhi_cntrl: MHI controller
 * @cookie: cookie/pattern value to match
 *
 * Returns:
 * true if cookie is found
 * false if cookie is not found
 */
bool mhi_scan_rddm_cookie(struct mhi_controller *mhi_cntrl, u32 cookie);

/**
 * mhi_device_get_sync_atomic - Asserts device_wait and moves device to M0
 * @mhi_dev: Device associated with the channels
 * @timeout_us: timeout, in micro-seconds
 * @in_panic: If requested while kernel is in panic state and no ISRs expected
 *
 * The device_wake is asserted to keep device in M0 or bring it to M0.
 * If device is not in M0 state, then this function will wait for device to
 * move to M0, until @timeout_us elapses.
 * However, if device's M1 state-change event races with this function
 * then there is a possiblity of device moving from M0 to M2 and back
 * to M0. That can't be avoided as host must transition device from M1 to M2
 * as per the spec.
 * Clients can ignore that transition after this function returns as the device
 * is expected to immediately  move from M2 to M0 as wake is asserted and
 * wouldn't enter low power state.
 * If in_panic boolean is set, no ISRs are expected, hence this API will have to
 * resort to reading the MHI status register and poll on M0 state change.
 *
 * Returns:
 * 0 if operation was successful (however, M0 -> M2 -> M0 is possible later) as
 * mentioned above.
 * -ETIMEDOUT is device faled to move to M0 before @timeout_us elapsed
 * -EIO if the MHI state is one of the ERROR states.
 */
int mhi_device_get_sync_atomic(struct mhi_device *mhi_dev, int timeout_us,
			       bool in_panic);

/**
 * mhi_controller_set_bw_scale_cb - Set the BW scale callback for MHI controller
 * @mhi_cntrl: MHI controller
 * @cb_func: Callback to set for the MHI controller to receive BW scale requests
 */
void mhi_controller_set_bw_scale_cb(struct mhi_controller *mhi_cntrl,
				int (*cb_func)(struct mhi_controller *mhi_cntrl,
					      struct mhi_link_info *link_info));
/**
 * mhi_controller_set_base - Set the controller base / resource start address
 * @mhi_cntrl: MHI controller
 * @base: Physical address to be set for future reference
 */
void mhi_controller_set_base(struct mhi_controller *mhi_cntrl,
			     phys_addr_t base);

/**
 * mhi_get_channel_db_base - retrieve the channel doorbell base address
 * @mhi_dev: Device associated with the channels
 * @value: Pointer to an address value which will be populated
 */
int mhi_get_channel_db_base(struct mhi_device *mhi_dev, phys_addr_t *value);

/**
 * mhi_get_event_ring_db_base - retrieve the event ring doorbell base address
 * @mhi_dev: Device associated with the channels
 * @value: Pointer to an address value which will be populated
 */
int mhi_get_event_ring_db_base(struct mhi_device *mhi_dev, phys_addr_t *value);

/**
 * mhi_get_device_for_channel - get the MHI device for a specific channel number
 * @mhi_cntrl: MHI controller
 * @channel - channel number
 *
 * Returns:
 * Pointer to the MHI device associated with the channel
 */
struct mhi_device *mhi_get_device_for_channel(struct mhi_controller *mhi_cntrl,
					      u32 channel);

/**
 * mhi_device_ioctl - user space IOCTL support for MHI channels
 * Native support for setting TIOCM
 * @mhi_dev: Device associated with the channels
 * @cmd: IOCTL cmd
 * @arg: Optional parameter, iotcl cmd specific
 */
long mhi_device_ioctl(struct mhi_device *mhi_dev, unsigned int cmd,
		      unsigned long arg);

/**
 * mhi_controller_set_sfr_support - Set support for subsystem failure reason
 * @mhi_cntrl: MHI controller
 *
 * Returns:
 * 0 for success, error code for failure
 */
int mhi_controller_set_sfr_support(struct mhi_controller *mhi_cntrl,
				   size_t len);

/**
 * mhi_controller_setup_timesync - Set support for time synchronization feature
 * @mhi_cntrl: MHI controller
 * @time_get: Callback to set for the MHI controller to receive host time
 * @lpm_disable: Callback to set for the MHI controller to disable link LPM
 * @lpm_enable: Callback to set for the MHI controller to enable link LPM
 *
 * Returns:
 * 0 for success, error code for failure
 */
int mhi_controller_setup_timesync(struct mhi_controller *mhi_cntrl,
				  u64 (*time_get)(struct mhi_controller *c),
				  int (*lpm_disable)(struct mhi_controller *c),
				  int (*lpm_enable)(struct mhi_controller *c));

/**
 * mhi_get_remote_time_sync - Get external soc time relative to local soc time
 * using MMIO method.
 * @mhi_dev: Device associated with the channels
 * @t_host: Pointer to output local soc time
 * @t_dev: Pointer to output remote soc time
 *
 * Returns:
 * 0 for success, error code for failure
 */
int mhi_get_remote_time_sync(struct mhi_device *mhi_dev,
			     u64 *t_host,
			     u64 *t_dev);

/**
 * mhi_get_remote_time - Get external modem time relative to host time
 * Trigger event to capture modem time, also capture host time so client
 * can do a relative drift comparision.
 * Recommended only tsync device calls this method and do not call this
 * from atomic context
 * @mhi_dev: Device associated with the channels
 * @sequence:unique sequence id track event
 * @cb_func: callback function to call back
 *
 * Returns:
 * 0 for success, error code for failure
 */
int mhi_get_remote_time(struct mhi_device *mhi_dev,
			u32 sequence,
			void (*cb_func)(struct mhi_device *mhi_dev,
					u32 sequence,
					u64 local_time,
					u64 remote_time));

/**
 * mhi_force_reset - does host reset request to collect device side dumps
 * for debugging purpose
 * @mhi_cntrl: MHI controller
 */
int mhi_force_reset(struct mhi_controller *mhi_cntrl);

#else

/**
 * mhi_report_error - Can be used by controller to signal error condition to the
 * MHI core driver in case of any need to halt processing or incoming sideband
 * signal detects an error on endpoint
 * @mhi_cntrl: MHI controller
 *
 * Returns:
 * 0 if success in reporting the error condition to MHI core
 * error code on failure
 */
static inline int mhi_report_error(struct mhi_controller *mhi_cntrl)
{
	return -EPERM;
}

/**
 * mhi_controller_set_privdata - Set private data for MHI controller
 * @mhi_cntrl: MHI controller
 * @priv: pointer to data
 */
void mhi_controller_set_privdata(struct mhi_controller *mhi_cntrl, void *priv)
{
}

/**
 * mhi_controller_get_privdata - Get private data from MHI controller
 * @mhi_cntrl: MHI controller
 */
void *mhi_controller_get_privdata(struct mhi_controller *mhi_cntrl)
{
	return ERR_PTR(-EINVAL);
}

/**
 * mhi_bdf_to_controller - Get controller associated with given BDF values
 * @domain: Domain or root complex of PCIe port
 * @bus: Bus number
 * @slot: PCI slot or function number
 * @dev_id: Device ID of the endpoint
 *
 * Returns:
 * MHI controller structure pointer if BDF match is found
 * NULL if cookie is not found
 */
struct mhi_controller *mhi_bdf_to_controller(u32 domain, u32 bus, u32 slot, u32 dev_id)
{
	return ERR_PTR(-EINVAL);
}

/**
 * mhi_set_m2_timeout_ms - Set M2 timeout in milliseconds to wait before a
 * fast/silent suspend
 * @mhi_cntrl: MHI controller
 * @timeout: timeout in ms
 */
void mhi_set_m2_timeout_ms(struct mhi_controller *mhi_cntrl, u32 timeout)
{
}

/**
 * mhi_pm_fast_resume - Resume MHI from a fast/silent suspended state
 * @mhi_cntrl: MHI controller
 * @notify_clients: if true, clients will be notified of the resume transition
 */
int mhi_pm_fast_resume(struct mhi_controller *mhi_cntrl, bool notify_clients)
{
	return -EPERM;
}

/**
 * mhi_pm_fast_suspend - Move MHI into a fast/silent suspended state
 * @mhi_cntrl: MHI controller
 * @notify_clients: if true, clients will be notified of the suspend transition
 */
int mhi_pm_fast_suspend(struct mhi_controller *mhi_cntrl, bool notify_clients)
{
	return -EPERM;
}

/**
 * mhi_debug_reg_dump - dump MHI registers for debug purpose
 * @mhi_cntrl: MHI controller
 */
void mhi_debug_reg_dump(struct mhi_controller *mhi_cntrl)
{
}

/**
 * mhi_dump_sfr - Print SFR string from RDDM table.
 * @mhi_cntrl: MHI controller
 */
#if IS_ENABLED(CONFIG_WCN_GOOGLE)
void mhi_dump_sfr(struct mhi_controller *mhi_cntrl, void (*crash_info_handler)(u8*))
{
}
#else
void mhi_dump_sfr(struct mhi_controller *mhi_cntrl)
{
}
#endif //CONFIG_WCN_GOOGLE

/**
 * mhi_device_configure - Allow devices with offload channels to setup their own
 * channel and event ring context.
 * @mhi_dev: MHI device
 * @dir: direction associated with the channel needed to configure
 * @cfg_tbl: Buffer with ECA/CCA information and data needed to setup context
 * @elements: Number of items to iterate over from the configuration table
 */
int mhi_device_configure(struct mhi_device *mhi_dev,
			 enum dma_data_direction dir,
			 struct mhi_buf *cfg_tbl,
			 int elements)
{
	return -EPERM;
}

/**
 * mhi_scan_rddm_cookie - Look for supplied cookie value in the BHI debug
 * registers set by device to indicate rddm readiness for debugging purposes.
 * @mhi_cntrl: MHI controller
 * @cookie: cookie/pattern value to match
 *
 * Returns:
 * true if cookie is found
 * false if cookie is not found
 */
bool mhi_scan_rddm_cookie(struct mhi_controller *mhi_cntrl, u32 cookie)
{
	return false;
}

/**
 * mhi_device_get_sync_atomic - Asserts device_wait and moves device to M0
 * @mhi_dev: Device associated with the channels
 * @timeout_us: timeout, in micro-seconds
 * @in_panic: If requested while kernel is in panic state and no ISRs expected
 *
 * The device_wake is asserted to keep device in M0 or bring it to M0.
 * If device is not in M0 state, then this function will wait for device to
 * move to M0, until @timeout_us elapses.
 * However, if device's M1 state-change event races with this function
 * then there is a possiblity of device moving from M0 to M2 and back
 * to M0. That can't be avoided as host must transition device from M1 to M2
 * as per the spec.
 * Clients can ignore that transition after this function returns as the device
 * is expected to immediately  move from M2 to M0 as wake is asserted and
 * wouldn't enter low power state.
 * If in_panic boolean is set, no ISRs are expected, hence this API will have to
 * resort to reading the MHI status register and poll on M0 state change.
 *
 * Returns:
 * 0 if operation was successful (however, M0 -> M2 -> M0 is possible later) as
 * mentioned above.
 * -ETIMEDOUT is device faled to move to M0 before @timeout_us elapsed
 * -EIO if the MHI state is one of the ERROR states.
 */
int mhi_device_get_sync_atomic(struct mhi_device *mhi_dev, int timeout_us,
			       bool in_panic)
{
	return -EPERM;
}

/**
 * mhi_controller_set_bw_scale_cb - Set the BW scale callback for MHI controller
 * @mhi_cntrl: MHI controller
 * @cb_func: Callback to set for the MHI controller to receive BW scale requests
 */
void mhi_controller_set_bw_scale_cb(struct mhi_controller *mhi_cntrl,
				int (*cb_func)(struct mhi_controller *mhi_cntrl,
					      struct mhi_link_info *link_info))
{
}

/**
 * mhi_controller_set_base - Set the controller base / resource start address
 * @mhi_cntrl: MHI controller
 * @base: Physical address to be set for future reference
 */
void mhi_controller_set_base(struct mhi_controller *mhi_cntrl,
			     phys_addr_t base)
{
}

/**
 * mhi_get_channel_db_base - retrieve the channel doorbell base address
 * @mhi_dev: Device associated with the channels
 * @value: Pointer to an address value which will be populated
 */
int mhi_get_channel_db_base(struct mhi_device *mhi_dev, phys_addr_t *value)
{
	return -EPERM;
}

/**
 * mhi_get_event_ring_db_base - retrieve the event ring doorbell base address
 * @mhi_dev: Device associated with the channels
 * @value: Pointer to an address value which will be populated
 */
int mhi_get_event_ring_db_base(struct mhi_device *mhi_dev, phys_addr_t *value)
{
	return -EPERM;
}

/**
 * mhi_get_device_for_channel - get the MHI device for a specific channel number
 * @mhi_cntrl: MHI controller
 * @channel - channel number
 *
 * Returns:
 * Pointer to the MHI device associated with the channel
 */
struct mhi_device *mhi_get_device_for_channel(struct mhi_controller *mhi_cntrl,
					      u32 channel)
{
	return ERR_PTR(-EINVAL);
}

/**
 * mhi_device_ioctl - user space IOCTL support for MHI channels
 * Native support for setting TIOCM
 * @mhi_dev: Device associated with the channels
 * @cmd: IOCTL cmd
 * @arg: Optional parameter, iotcl cmd specific
 */
long mhi_device_ioctl(struct mhi_device *mhi_dev, unsigned int cmd,
		      unsigned long arg)
{
	return -EPERM;
}

/**
 * mhi_controller_set_sfr_support - Set support for subsystem failure reason
 * @mhi_cntrl: MHI controller
 *
 * Returns:
 * 0 for success, error code for failure
 */
int mhi_controller_set_sfr_support(struct mhi_controller *mhi_cntrl,
				   size_t len)
{
	return -EPERM;
}

/**
 * mhi_controller_setup_timesync - Set support for time synchronization feature
 * @mhi_cntrl: MHI controller
 * @time_get: Callback to set for the MHI controller to receive host time
 * @lpm_disable: Callback to set for the MHI controller to disable link LPM
 * @lpm_enable: Callback to set for the MHI controller to enable link LPM
 *
 * Returns:
 * 0 for success, error code for failure
 */
int mhi_controller_setup_timesync(struct mhi_controller *mhi_cntrl,
				  u64 (*time_get)(struct mhi_controller *c),
				  int (*lpm_disable)(struct mhi_controller *c),
				  int (*lpm_enable)(struct mhi_controller *c))
{
	return -EPERM;
}

/**
 * mhi_get_remote_time_sync - Get external soc time relative to local soc time
 * using MMIO method.
 * @mhi_dev: Device associated with the channels
 * @t_host: Pointer to output local soc time
 * @t_dev: Pointer to output remote soc time
 *
 * Returns:
 * 0 for success, error code for failure
 */
int mhi_get_remote_time_sync(struct mhi_device *mhi_dev,
			     u64 *t_host,
			     u64 *t_dev)
{
	return -EPERM;
}

/**
 * mhi_get_remote_time - Get external modem time relative to host time
 * Trigger event to capture modem time, also capture host time so client
 * can do a relative drift comparision.
 * Recommended only tsync device calls this method and do not call this
 * from atomic context
 * @mhi_dev: Device associated with the channels
 * @sequence:unique sequence id track event
 * @cb_func: callback function to call back
 *
 * Returns:
 * 0 for success, error code for failure
 */
int mhi_get_remote_time(struct mhi_device *mhi_dev,
			u32 sequence,
			void (*cb_func)(struct mhi_device *mhi_dev,
					u32 sequence,
					u64 local_time,
					u64 remote_time))
{
	return -EPERM;
}

/**
 * mhi_force_reset - does host reset request to collect device side dumps
 * for debugging purpose
 * @mhi_cntrl: MHI controller
 */
int mhi_force_reset(struct mhi_controller *mhi_cntrl)
{
	return -EINVAL;
}

#endif /* CONFIG_MHI_BUS_MISC */

#endif /* _MHI_MISC_H_ */