1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
9 #include <linux/device.h>
10 #include <linux/dma-direction.h>
11 #include <linux/mutex.h>
12 #include <linux/skbuff.h>
13 #include <linux/slab.h>
14 #include <linux/spinlock.h>
15 #include <linux/wait.h>
16 #include <linux/workqueue.h>
18 #define MHI_MAX_OEM_PK_HASH_SEGMENTS 16
27 * enum mhi_callback - MHI callback
28 * @MHI_CB_IDLE: MHI entered idle state
29 * @MHI_CB_PENDING_DATA: New data available for client to process
30 * @MHI_CB_LPM_ENTER: MHI host entered low power mode
31 * @MHI_CB_LPM_EXIT: MHI host about to exit low power mode
32 * @MHI_CB_EE_RDDM: MHI device entered RDDM exec env
33 * @MHI_CB_EE_MISSION_MODE: MHI device entered Mission Mode exec env
34 * @MHI_CB_SYS_ERROR: MHI device entered error state (may recover)
35 * @MHI_CB_FATAL_ERROR: MHI device entered fatal error state
36 * @MHI_CB_BW_REQ: Received a bandwidth switch request from device
44 MHI_CB_EE_MISSION_MODE,
51 * enum mhi_flags - Transfer flags
52 * @MHI_EOB: End of buffer for bulk transfer
53 * @MHI_EOT: End of transfer
54 * @MHI_CHAIN: Linked transfer
63 * enum mhi_device_type - Device types
64 * @MHI_DEVICE_XFER: Handles data transfer
65 * @MHI_DEVICE_CONTROLLER: Control device
67 enum mhi_device_type {
69 MHI_DEVICE_CONTROLLER,
73 * enum mhi_ch_type - Channel types
74 * @MHI_CH_TYPE_INVALID: Invalid channel type
75 * @MHI_CH_TYPE_OUTBOUND: Outbound channel to the device
76 * @MHI_CH_TYPE_INBOUND: Inbound channel from the device
77 * @MHI_CH_TYPE_INBOUND_COALESCED: Coalesced channel for the device to combine
78 * multiple packets and send them as a single
79 * large packet to reduce CPU consumption
82 MHI_CH_TYPE_INVALID = 0,
83 MHI_CH_TYPE_OUTBOUND = DMA_TO_DEVICE,
84 MHI_CH_TYPE_INBOUND = DMA_FROM_DEVICE,
85 MHI_CH_TYPE_INBOUND_COALESCED = 3,
89 * struct image_info - Firmware and RDDM table
90 * @mhi_buf: Buffer for firmware and RDDM table
91 * @entries: # of entries in table
94 struct mhi_buf *mhi_buf;
95 /* private: from internal.h */
96 struct bhi_vec_entry *bhi_vec;
102 * struct mhi_link_info - BW requirement
103 * target_link_speed - Link speed as defined by TLS bits in LinkControl reg
104 * target_link_width - Link width as defined by NLW bits in LinkStatus reg
106 struct mhi_link_info {
107 unsigned int target_link_speed;
108 unsigned int target_link_width;
112 * enum mhi_ee_type - Execution environment types
113 * @MHI_EE_PBL: Primary Bootloader
114 * @MHI_EE_SBL: Secondary Bootloader
115 * @MHI_EE_AMSS: Modem, aka the primary runtime EE
116 * @MHI_EE_RDDM: Ram dump download mode
117 * @MHI_EE_WFW: WLAN firmware mode
118 * @MHI_EE_PTHRU: Passthrough
119 * @MHI_EE_EDL: Embedded downloader
120 * @MHI_EE_FP: Flash Programmer Environment
131 MHI_EE_MAX_SUPPORTED = MHI_EE_FP,
132 MHI_EE_DISABLE_TRANSITION, /* local EE, not related to mhi spec */
133 MHI_EE_NOT_SUPPORTED,
138 * enum mhi_state - MHI states
139 * @MHI_STATE_RESET: Reset state
140 * @MHI_STATE_READY: Ready state
141 * @MHI_STATE_M0: M0 state
142 * @MHI_STATE_M1: M1 state
143 * @MHI_STATE_M2: M2 state
144 * @MHI_STATE_M3: M3 state
145 * @MHI_STATE_M3_FAST: M3 Fast state
146 * @MHI_STATE_BHI: BHI state
147 * @MHI_STATE_SYS_ERR: System Error state
150 MHI_STATE_RESET = 0x0,
151 MHI_STATE_READY = 0x1,
156 MHI_STATE_M3_FAST = 0x6,
158 MHI_STATE_SYS_ERR = 0xFF,
163 * enum mhi_ch_ee_mask - Execution environment mask for channel
164 * @MHI_CH_EE_PBL: Allow channel to be used in PBL EE
165 * @MHI_CH_EE_SBL: Allow channel to be used in SBL EE
166 * @MHI_CH_EE_AMSS: Allow channel to be used in AMSS EE
167 * @MHI_CH_EE_RDDM: Allow channel to be used in RDDM EE
168 * @MHI_CH_EE_PTHRU: Allow channel to be used in PTHRU EE
169 * @MHI_CH_EE_WFW: Allow channel to be used in WFW EE
170 * @MHI_CH_EE_EDL: Allow channel to be used in EDL EE
172 enum mhi_ch_ee_mask {
173 MHI_CH_EE_PBL = BIT(MHI_EE_PBL),
174 MHI_CH_EE_SBL = BIT(MHI_EE_SBL),
175 MHI_CH_EE_AMSS = BIT(MHI_EE_AMSS),
176 MHI_CH_EE_RDDM = BIT(MHI_EE_RDDM),
177 MHI_CH_EE_PTHRU = BIT(MHI_EE_PTHRU),
178 MHI_CH_EE_WFW = BIT(MHI_EE_WFW),
179 MHI_CH_EE_EDL = BIT(MHI_EE_EDL),
183 * enum mhi_er_data_type - Event ring data types
184 * @MHI_ER_DATA: Only client data over this ring
185 * @MHI_ER_CTRL: MHI control data and client data
187 enum mhi_er_data_type {
193 * enum mhi_db_brst_mode - Doorbell mode
194 * @MHI_DB_BRST_DISABLE: Burst mode disable
195 * @MHI_DB_BRST_ENABLE: Burst mode enable
197 enum mhi_db_brst_mode {
198 MHI_DB_BRST_DISABLE = 0x2,
199 MHI_DB_BRST_ENABLE = 0x3,
203 * struct mhi_channel_config - Channel configuration structure for controller
204 * @name: The name of this channel
205 * @num: The number assigned to this channel
206 * @num_elements: The number of elements that can be queued to this channel
207 * @local_elements: The local ring length of the channel
208 * @event_ring: The event ring index that services this channel
209 * @dir: Direction that data may flow on this channel
210 * @type: Channel type
211 * @ee_mask: Execution Environment mask for this channel
212 * @pollcfg: Polling configuration for burst mode. 0 is default. milliseconds
213 for UL channels, multiple of 8 ring elements for DL channels
214 * @doorbell: Doorbell mode
215 * @lpm_notify: The channel master requires low power mode notifications
216 * @offload_channel: The client manages the channel completely
217 * @doorbell_mode_switch: Channel switches to doorbell mode on M0 transition
218 * @auto_queue: Framework will automatically queue buffers for DL traffic
219 * @wake-capable: Channel capable of waking up the system
221 struct mhi_channel_config {
227 enum dma_data_direction dir;
228 enum mhi_ch_type type;
231 enum mhi_db_brst_mode doorbell;
233 bool offload_channel;
234 bool doorbell_mode_switch;
240 * struct mhi_event_config - Event ring configuration structure for controller
241 * @num_elements: The number of elements that can be queued to this ring
242 * @irq_moderation_ms: Delay irq for additional events to be aggregated
243 * @irq: IRQ associated with this ring
244 * @channel: Dedicated channel number. U32_MAX indicates a non-dedicated ring
245 * @priority: Priority of this ring. Use 1 for now
246 * @mode: Doorbell mode
247 * @data_type: Type of data this ring will process
248 * @hardware_event: This ring is associated with hardware channels
249 * @client_managed: This ring is client managed
250 * @offload_channel: This ring is associated with an offloaded channel
252 struct mhi_event_config {
254 u32 irq_moderation_ms;
258 enum mhi_db_brst_mode mode;
259 enum mhi_er_data_type data_type;
262 bool offload_channel;
266 * struct mhi_controller_config - Root MHI controller configuration
267 * @max_channels: Maximum number of channels supported
268 * @timeout_ms: Timeout value for operations. 0 means use default
269 * @ready_timeout_ms: Timeout value for waiting device to be ready (optional)
270 * @buf_len: Size of automatically allocated buffers. 0 means use default
271 * @num_channels: Number of channels defined in @ch_cfg
272 * @ch_cfg: Array of defined channels
273 * @num_events: Number of event rings defined in @event_cfg
274 * @event_cfg: Array of defined event rings
275 * @use_bounce_buf: Use a bounce buffer pool due to limited DDR access
276 * @m2_no_db: Host is not allowed to ring DB in M2 state
278 struct mhi_controller_config {
281 u32 ready_timeout_ms;
284 const struct mhi_channel_config *ch_cfg;
286 struct mhi_event_config *event_cfg;
292 * struct mhi_controller - Master MHI controller structure
293 * @cntrl_dev: Pointer to the struct device of physical bus acting as the MHI
294 * controller (required)
295 * @mhi_dev: MHI device instance for the controller
296 * @debugfs_dentry: MHI controller debugfs directory
297 * @regs: Base address of MHI MMIO register space (required)
298 * @bhi: Points to base of MHI BHI register space
299 * @bhie: Points to base of MHI BHIe register space
300 * @wake_db: MHI WAKE doorbell register address
301 * @iova_start: IOMMU starting address for data (required)
302 * @iova_stop: IOMMU stop address for data (required)
303 * @fw_image: Firmware image name for normal booting (optional)
304 * @fw_data: Firmware image data content for normal booting, used only
305 * if fw_image is NULL and fbc_download is true (optional)
306 * @fw_sz: Firmware image data size for normal booting, used only if fw_image
307 * is NULL and fbc_download is true (optional)
308 * @edl_image: Firmware image name for emergency download mode (optional)
309 * @rddm_size: RAM dump size that host should allocate for debugging purpose
310 * @sbl_size: SBL image size downloaded through BHIe (optional)
311 * @seg_len: BHIe vector size (optional)
312 * @reg_len: Length of the MHI MMIO region (required)
313 * @fbc_image: Points to firmware image buffer
314 * @rddm_image: Points to RAM dump buffer
315 * @mhi_chan: Points to the channel configuration table
316 * @lpm_chans: List of channels that require LPM notifications
317 * @irq: base irq # to request (required)
318 * @max_chan: Maximum number of channels the controller supports
319 * @total_ev_rings: Total # of event rings allocated
320 * @hw_ev_rings: Number of hardware event rings
321 * @sw_ev_rings: Number of software event rings
322 * @nr_irqs: Number of IRQ allocated by bus master (required)
323 * @serial_number: MHI controller serial number obtained from BHI
324 * @mhi_event: MHI event ring configurations table
325 * @mhi_cmd: MHI command ring configurations table
326 * @mhi_ctxt: MHI device context, shared memory between host and device
327 * @pm_mutex: Mutex for suspend/resume operation
328 * @pm_lock: Lock for protecting MHI power management state
329 * @timeout_ms: Timeout in ms for state transitions
330 * @ready_timeout_ms: Timeout in ms for waiting device to be ready (optional)
331 * @pm_state: MHI power management state
332 * @db_access: DB access states
333 * @ee: MHI device execution environment
334 * @dev_state: MHI device state
335 * @dev_wake: Device wakeup count
336 * @pending_pkts: Pending packets for the controller
337 * @M0, M2, M3: Counters to track number of device MHI state changes
338 * @transition_list: List of MHI state transitions
339 * @transition_lock: Lock for protecting MHI state transition list
340 * @wlock: Lock for protecting device wakeup
341 * @mhi_link_info: Device bandwidth info
342 * @st_worker: State transition worker
343 * @hiprio_wq: High priority workqueue for MHI work such as state transitions
344 * @state_event: State change event
345 * @status_cb: CB function to notify power states of the device (required)
346 * @wake_get: CB function to assert device wake (optional)
347 * @wake_put: CB function to de-assert device wake (optional)
348 * @wake_toggle: CB function to assert and de-assert device wake (optional)
349 * @runtime_get: CB function to controller runtime resume (required)
350 * @runtime_put: CB function to decrement pm usage (required)
351 * @map_single: CB function to create TRE buffer
352 * @unmap_single: CB function to destroy TRE buffer
353 * @read_reg: Read a MHI register via the physical link (required)
354 * @write_reg: Write a MHI register via the physical link (required)
355 * @reset: Controller specific reset function (optional)
356 * @edl_trigger: CB function to trigger EDL mode (optional)
357 * @buffer_len: Bounce buffer length
358 * @index: Index of the MHI controller instance
359 * @bounce_buf: Use of bounce buffer
360 * @fbc_download: MHI host needs to do complete image transfer (optional)
361 * @wake_set: Device wakeup set flag
362 * @irq_flags: irq flags passed to request_irq (optional)
363 * @mru: the default MRU for the MHI device
365 * Fields marked as (required) need to be populated by the controller driver
366 * before calling mhi_register_controller(). For the fields marked as (optional)
367 * they can be populated depending on the usecase.
369 struct mhi_controller {
370 struct device *cntrl_dev;
371 struct mhi_device *mhi_dev;
372 struct dentry *debugfs_dentry;
376 void __iomem *wake_db;
378 dma_addr_t iova_start;
379 dma_addr_t iova_stop;
380 const char *fw_image;
383 const char *edl_image;
388 struct image_info *fbc_image;
389 struct image_info *rddm_image;
390 struct mhi_chan *mhi_chan;
391 struct list_head lpm_chans;
400 struct mhi_event *mhi_event;
401 struct mhi_cmd *mhi_cmd;
402 struct mhi_ctxt *mhi_ctxt;
404 struct mutex pm_mutex;
407 u32 ready_timeout_ms;
411 enum mhi_state dev_state;
413 atomic_t pending_pkts;
415 struct list_head transition_list;
416 spinlock_t transition_lock;
418 struct mhi_link_info mhi_link_info;
419 struct work_struct st_worker;
420 struct workqueue_struct *hiprio_wq;
421 wait_queue_head_t state_event;
423 void (*status_cb)(struct mhi_controller *mhi_cntrl,
424 enum mhi_callback cb);
425 void (*wake_get)(struct mhi_controller *mhi_cntrl, bool override);
426 void (*wake_put)(struct mhi_controller *mhi_cntrl, bool override);
427 void (*wake_toggle)(struct mhi_controller *mhi_cntrl);
428 int (*runtime_get)(struct mhi_controller *mhi_cntrl);
429 void (*runtime_put)(struct mhi_controller *mhi_cntrl);
430 int (*map_single)(struct mhi_controller *mhi_cntrl,
431 struct mhi_buf_info *buf);
432 void (*unmap_single)(struct mhi_controller *mhi_cntrl,
433 struct mhi_buf_info *buf);
434 int (*read_reg)(struct mhi_controller *mhi_cntrl, void __iomem *addr,
436 void (*write_reg)(struct mhi_controller *mhi_cntrl, void __iomem *addr,
438 void (*reset)(struct mhi_controller *mhi_cntrl);
439 int (*edl_trigger)(struct mhi_controller *mhi_cntrl);
446 unsigned long irq_flags;
451 * struct mhi_device - Structure representing an MHI device which binds
452 * to channels or is associated with controllers
453 * @id: Pointer to MHI device ID struct
454 * @name: Name of the associated MHI device
455 * @mhi_cntrl: Controller the device belongs to
456 * @ul_chan: UL channel for the device
457 * @dl_chan: DL channel for the device
458 * @dev: Driver model device node for the MHI device
459 * @dev_type: MHI device type
460 * @ul_chan_id: MHI channel id for UL transfer
461 * @dl_chan_id: MHI channel id for DL transfer
462 * @dev_wake: Device wakeup counter
465 const struct mhi_device_id *id;
467 struct mhi_controller *mhi_cntrl;
468 struct mhi_chan *ul_chan;
469 struct mhi_chan *dl_chan;
471 enum mhi_device_type dev_type;
478 * struct mhi_result - Completed buffer information
479 * @buf_addr: Address of data buffer
480 * @bytes_xferd: # of bytes transferred
481 * @dir: Channel direction
482 * @transaction_status: Status of last transaction
487 enum dma_data_direction dir;
488 int transaction_status;
492 * struct mhi_buf - MHI Buffer description
493 * @buf: Virtual address of the buffer
494 * @name: Buffer label. For offload channel, configurations name must be:
495 * ECA - Event context array data
496 * CCA - Channel context array data
497 * @dma_addr: IOMMU address of the buffer
508 * struct mhi_driver - Structure representing a MHI client driver
509 * @probe: CB function for client driver probe function
510 * @remove: CB function for client driver remove function
511 * @ul_xfer_cb: CB function for UL data transfer
512 * @dl_xfer_cb: CB function for DL data transfer
513 * @status_cb: CB functions for asynchronous status
514 * @driver: Device driver model driver
517 const struct mhi_device_id *id_table;
518 int (*probe)(struct mhi_device *mhi_dev,
519 const struct mhi_device_id *id);
520 void (*remove)(struct mhi_device *mhi_dev);
521 void (*ul_xfer_cb)(struct mhi_device *mhi_dev,
522 struct mhi_result *result);
523 void (*dl_xfer_cb)(struct mhi_device *mhi_dev,
524 struct mhi_result *result);
525 void (*status_cb)(struct mhi_device *mhi_dev, enum mhi_callback mhi_cb);
526 struct device_driver driver;
529 #define to_mhi_driver(drv) container_of(drv, struct mhi_driver, driver)
530 #define to_mhi_device(dev) container_of(dev, struct mhi_device, dev)
533 * mhi_alloc_controller - Allocate the MHI Controller structure
534 * Allocate the mhi_controller structure using zero initialized memory
536 struct mhi_controller *mhi_alloc_controller(void);
539 * mhi_free_controller - Free the MHI Controller structure
540 * Free the mhi_controller structure which was previously allocated
542 void mhi_free_controller(struct mhi_controller *mhi_cntrl);
545 * mhi_register_controller - Register MHI controller
546 * @mhi_cntrl: MHI controller to register
547 * @config: Configuration to use for the controller
549 int mhi_register_controller(struct mhi_controller *mhi_cntrl,
550 const struct mhi_controller_config *config);
553 * mhi_unregister_controller - Unregister MHI controller
554 * @mhi_cntrl: MHI controller to unregister
556 void mhi_unregister_controller(struct mhi_controller *mhi_cntrl);
559 * module_mhi_driver() - Helper macro for drivers that don't do
560 * anything special other than using default mhi_driver_register() and
561 * mhi_driver_unregister(). This eliminates a lot of boilerplate.
562 * Each module may only use this macro once.
564 #define module_mhi_driver(mhi_drv) \
565 module_driver(mhi_drv, mhi_driver_register, \
566 mhi_driver_unregister)
569 * Macro to avoid include chaining to get THIS_MODULE
571 #define mhi_driver_register(mhi_drv) \
572 __mhi_driver_register(mhi_drv, THIS_MODULE)
575 * __mhi_driver_register - Register driver with MHI framework
576 * @mhi_drv: Driver associated with the device
577 * @owner: The module owner
579 int __mhi_driver_register(struct mhi_driver *mhi_drv, struct module *owner);
582 * mhi_driver_unregister - Unregister a driver for mhi_devices
583 * @mhi_drv: Driver associated with the device
585 void mhi_driver_unregister(struct mhi_driver *mhi_drv);
588 * mhi_set_mhi_state - Set MHI device state
589 * @mhi_cntrl: MHI controller
590 * @state: State to set
592 void mhi_set_mhi_state(struct mhi_controller *mhi_cntrl,
593 enum mhi_state state);
596 * mhi_notify - Notify the MHI client driver about client device status
597 * @mhi_dev: MHI device instance
598 * @cb_reason: MHI callback reason
600 void mhi_notify(struct mhi_device *mhi_dev, enum mhi_callback cb_reason);
603 * mhi_get_free_desc_count - Get transfer ring length
604 * Get # of TD available to queue buffers
605 * @mhi_dev: Device associated with the channels
606 * @dir: Direction of the channel
608 int mhi_get_free_desc_count(struct mhi_device *mhi_dev,
609 enum dma_data_direction dir);
612 * mhi_prepare_for_power_up - Do pre-initialization before power up.
613 * This is optional, call this before power up if
614 * the controller does not want bus framework to
615 * automatically free any allocated memory during
617 * @mhi_cntrl: MHI controller
619 int mhi_prepare_for_power_up(struct mhi_controller *mhi_cntrl);
622 * mhi_async_power_up - Start MHI power up sequence
623 * @mhi_cntrl: MHI controller
625 int mhi_async_power_up(struct mhi_controller *mhi_cntrl);
628 * mhi_sync_power_up - Start MHI power up sequence and wait till the device
629 * enters valid EE state
630 * @mhi_cntrl: MHI controller
632 int mhi_sync_power_up(struct mhi_controller *mhi_cntrl);
635 * mhi_power_down - Power down the MHI device and also destroy the
636 * 'struct device' for the channels associated with it.
637 * See also mhi_power_down_keep_dev() which is a variant
638 * of this API that keeps the 'struct device' for channels
639 * (useful during suspend/hibernation).
640 * @mhi_cntrl: MHI controller
641 * @graceful: Link is still accessible, so do a graceful shutdown process
643 void mhi_power_down(struct mhi_controller *mhi_cntrl, bool graceful);
646 * mhi_power_down_keep_dev - Power down the MHI device but keep the 'struct
647 * device' for the channels associated with it.
648 * This is a variant of 'mhi_power_down()' and
649 * useful in scenarios such as suspend/hibernation
650 * where destroying of the 'struct device' is not
652 * @mhi_cntrl: MHI controller
653 * @graceful: Link is still accessible, so do a graceful shutdown process
655 void mhi_power_down_keep_dev(struct mhi_controller *mhi_cntrl, bool graceful);
658 * mhi_unprepare_after_power_down - Free any allocated memory after power down
659 * @mhi_cntrl: MHI controller
661 void mhi_unprepare_after_power_down(struct mhi_controller *mhi_cntrl);
664 * mhi_pm_suspend - Move MHI into a suspended state
665 * @mhi_cntrl: MHI controller
667 int mhi_pm_suspend(struct mhi_controller *mhi_cntrl);
670 * mhi_pm_resume - Resume MHI from suspended state
671 * @mhi_cntrl: MHI controller
673 int mhi_pm_resume(struct mhi_controller *mhi_cntrl);
676 * mhi_pm_resume_force - Force resume MHI from suspended state
677 * @mhi_cntrl: MHI controller
679 * Resume the device irrespective of its MHI state. As per the MHI spec, devices
680 * has to be in M3 state during resume. But some devices seem to be in a
681 * different MHI state other than M3 but they continue working fine if allowed.
682 * This API is intented to be used for such devices.
684 * Return: 0 if the resume succeeds, a negative error code otherwise
686 int mhi_pm_resume_force(struct mhi_controller *mhi_cntrl);
689 * mhi_download_rddm_image - Download ramdump image from device for
691 * @mhi_cntrl: MHI controller
692 * @in_panic: Download rddm image during kernel panic
694 int mhi_download_rddm_image(struct mhi_controller *mhi_cntrl, bool in_panic);
697 * mhi_force_rddm_mode - Force device into rddm mode
698 * @mhi_cntrl: MHI controller
700 int mhi_force_rddm_mode(struct mhi_controller *mhi_cntrl);
703 * mhi_get_exec_env - Get BHI execution environment of the device
704 * @mhi_cntrl: MHI controller
706 enum mhi_ee_type mhi_get_exec_env(struct mhi_controller *mhi_cntrl);
709 * mhi_get_mhi_state - Get MHI state of the device
710 * @mhi_cntrl: MHI controller
712 enum mhi_state mhi_get_mhi_state(struct mhi_controller *mhi_cntrl);
715 * mhi_soc_reset - Trigger a device reset. This can be used as a last resort
716 * to reset and recover a device.
717 * @mhi_cntrl: MHI controller
719 void mhi_soc_reset(struct mhi_controller *mhi_cntrl);
722 * mhi_device_get - Disable device low power mode
723 * @mhi_dev: Device associated with the channel
725 void mhi_device_get(struct mhi_device *mhi_dev);
728 * mhi_device_get_sync - Disable device low power mode. Synchronously
729 * take the controller out of suspended state
730 * @mhi_dev: Device associated with the channel
732 int mhi_device_get_sync(struct mhi_device *mhi_dev);
735 * mhi_device_put - Re-enable device low power mode
736 * @mhi_dev: Device associated with the channel
738 void mhi_device_put(struct mhi_device *mhi_dev);
741 * mhi_prepare_for_transfer - Setup UL and DL channels for data transfer.
742 * @mhi_dev: Device associated with the channels
744 * Allocate and initialize the channel context and also issue the START channel
745 * command to both channels. Channels can be started only if both host and
746 * device execution environments match and channels are in a DISABLED state.
748 int mhi_prepare_for_transfer(struct mhi_device *mhi_dev);
751 * mhi_prepare_for_transfer_autoqueue - Setup UL and DL channels with auto queue
752 * buffers for DL traffic
753 * @mhi_dev: Device associated with the channels
755 * Allocate and initialize the channel context and also issue the START channel
756 * command to both channels. Channels can be started only if both host and
757 * device execution environments match and channels are in a DISABLED state.
758 * The MHI core will automatically allocate and queue buffers for the DL traffic.
760 int mhi_prepare_for_transfer_autoqueue(struct mhi_device *mhi_dev);
763 * mhi_unprepare_from_transfer - Reset UL and DL channels for data transfer.
764 * Issue the RESET channel command and let the
765 * device clean-up the context so no incoming
766 * transfers are seen on the host. Free memory
767 * associated with the context on host. If device
768 * is unresponsive, only perform a host side
769 * clean-up. Channels can be reset only if both
770 * host and device execution environments match
771 * and channels are in an ENABLED, STOPPED or
773 * @mhi_dev: Device associated with the channels
775 void mhi_unprepare_from_transfer(struct mhi_device *mhi_dev);
778 * mhi_queue_dma - Send or receive DMA mapped buffers from client device
780 * @mhi_dev: Device associated with the channels
781 * @dir: DMA direction for the channel
782 * @mhi_buf: Buffer for holding the DMA mapped data
783 * @len: Buffer length
784 * @mflags: MHI transfer flags used for the transfer
786 int mhi_queue_dma(struct mhi_device *mhi_dev, enum dma_data_direction dir,
787 struct mhi_buf *mhi_buf, size_t len, enum mhi_flags mflags);
790 * mhi_queue_buf - Send or receive raw buffers from client device over MHI
792 * @mhi_dev: Device associated with the channels
793 * @dir: DMA direction for the channel
794 * @buf: Buffer for holding the data
795 * @len: Buffer length
796 * @mflags: MHI transfer flags used for the transfer
798 int mhi_queue_buf(struct mhi_device *mhi_dev, enum dma_data_direction dir,
799 void *buf, size_t len, enum mhi_flags mflags);
802 * mhi_queue_skb - Send or receive SKBs from client device over MHI channel
803 * @mhi_dev: Device associated with the channels
804 * @dir: DMA direction for the channel
805 * @skb: Buffer for holding SKBs
806 * @len: Buffer length
807 * @mflags: MHI transfer flags used for the transfer
809 int mhi_queue_skb(struct mhi_device *mhi_dev, enum dma_data_direction dir,
810 struct sk_buff *skb, size_t len, enum mhi_flags mflags);
813 * mhi_queue_is_full - Determine whether queueing new elements is possible
814 * @mhi_dev: Device associated with the channels
815 * @dir: DMA direction for the channel
817 bool mhi_queue_is_full(struct mhi_device *mhi_dev, enum dma_data_direction dir);
820 * mhi_get_channel_doorbell_offset - Get the channel doorbell offset
821 * @mhi_cntrl: MHI controller
822 * @chdb_offset: Read channel doorbell offset
824 * Return: 0 if the read succeeds, a negative error code otherwise
826 int mhi_get_channel_doorbell_offset(struct mhi_controller *mhi_cntrl, u32 *chdb_offset);