mhi.rst 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ==========================
  3. MHI (Modem Host Interface)
  4. ==========================
  5. This document provides information about the MHI protocol.
  6. Overview
  7. ========
  8. MHI is a protocol developed by Qualcomm Innovation Center, Inc. It is used
  9. by the host processors to control and communicate with modem devices over high
  10. speed peripheral buses or shared memory. Even though MHI can be easily adapted
  11. to any peripheral buses, it is primarily used with PCIe based devices. MHI
  12. provides logical channels over the physical buses and allows transporting the
  13. modem protocols, such as IP data packets, modem control messages, and
  14. diagnostics over at least one of those logical channels. Also, the MHI
  15. protocol provides data acknowledgment feature and manages the power state of the
  16. modems via one or more logical channels.
  17. MHI Internals
  18. =============
  19. MMIO
  20. ----
  21. MMIO (Memory mapped IO) consists of a set of registers in the device hardware,
  22. which are mapped to the host memory space by the peripheral buses like PCIe.
  23. Following are the major components of MMIO register space:
  24. MHI control registers: Access to MHI configurations registers
  25. MHI BHI registers: BHI (Boot Host Interface) registers are used by the host
  26. for downloading the firmware to the device before MHI initialization.
  27. Channel Doorbell array: Channel Doorbell (DB) registers used by the host to
  28. notify the device when there is new work to do.
  29. Event Doorbell array: Associated with event context array, the Event Doorbell
  30. (DB) registers are used by the host to notify the device when new events are
  31. available.
  32. Debug registers: A set of registers and counters used by the device to expose
  33. debugging information like performance, functional, and stability to the host.
  34. Data structures
  35. ---------------
  36. All data structures used by MHI are in the host system memory. Using the
  37. physical interface, the device accesses those data structures. MHI data
  38. structures and data buffers in the host system memory regions are mapped for
  39. the device.
  40. Channel context array: All channel configurations are organized in channel
  41. context data array.
  42. Transfer rings: Used by the host to schedule work items for a channel. The
  43. transfer rings are organized as a circular queue of Transfer Descriptors (TD).
  44. Event context array: All event configurations are organized in the event context
  45. data array.
  46. Event rings: Used by the device to send completion and state transition messages
  47. to the host
  48. Command context array: All command configurations are organized in command
  49. context data array.
  50. Command rings: Used by the host to send MHI commands to the device. The command
  51. rings are organized as a circular queue of Command Descriptors (CD).
  52. Channels
  53. --------
  54. MHI channels are logical, unidirectional data pipes between a host and a device.
  55. The concept of channels in MHI is similar to endpoints in USB. MHI supports up
  56. to 256 channels. However, specific device implementations may support less than
  57. the maximum number of channels allowed.
  58. Two unidirectional channels with their associated transfer rings form a
  59. bidirectional data pipe, which can be used by the upper-layer protocols to
  60. transport application data packets (such as IP packets, modem control messages,
  61. diagnostics messages, and so on). Each channel is associated with a single
  62. transfer ring.
  63. Transfer rings
  64. --------------
  65. Transfers between the host and device are organized by channels and defined by
  66. Transfer Descriptors (TD). TDs are managed through transfer rings, which are
  67. defined for each channel between the device and host and reside in the host
  68. memory. TDs consist of one or more ring elements (or transfer blocks)::
  69. [Read Pointer (RP)] ----------->[Ring Element] } TD
  70. [Write Pointer (WP)]- [Ring Element]
  71. - [Ring Element]
  72. --------->[Ring Element]
  73. [Ring Element]
  74. Below is the basic usage of transfer rings:
  75. * Host allocates memory for transfer ring.
  76. * Host sets the base pointer, read pointer, and write pointer in corresponding
  77. channel context.
  78. * Ring is considered empty when RP == WP.
  79. * Ring is considered full when WP + 1 == RP.
  80. * RP indicates the next element to be serviced by the device.
  81. * When the host has a new buffer to send, it updates the ring element with
  82. buffer information, increments the WP to the next element and rings the
  83. associated channel DB.
  84. Event rings
  85. -----------
  86. Events from the device to host are organized in event rings and defined by Event
  87. Descriptors (ED). Event rings are used by the device to report events such as
  88. data transfer completion status, command completion status, and state changes
  89. to the host. Event rings are the array of EDs that resides in the host
  90. memory. EDs consist of one or more ring elements (or transfer blocks)::
  91. [Read Pointer (RP)] ----------->[Ring Element] } ED
  92. [Write Pointer (WP)]- [Ring Element]
  93. - [Ring Element]
  94. --------->[Ring Element]
  95. [Ring Element]
  96. Below is the basic usage of event rings:
  97. * Host allocates memory for event ring.
  98. * Host sets the base pointer, read pointer, and write pointer in corresponding
  99. channel context.
  100. * Both host and device has a local copy of RP, WP.
  101. * Ring is considered empty (no events to service) when WP + 1 == RP.
  102. * Ring is considered full of events when RP == WP.
  103. * When there is a new event the device needs to send, the device updates ED
  104. pointed by RP, increments the RP to the next element and triggers the
  105. interrupt.
  106. Ring Element
  107. ------------
  108. A Ring Element is a data structure used to transfer a single block
  109. of data between the host and the device. Transfer ring element types contain a
  110. single buffer pointer, the size of the buffer, and additional control
  111. information. Other ring element types may only contain control and status
  112. information. For single buffer operations, a ring descriptor is composed of a
  113. single element. For large multi-buffer operations (such as scatter and gather),
  114. elements can be chained to form a longer descriptor.
  115. MHI Operations
  116. ==============
  117. MHI States
  118. ----------
  119. MHI_STATE_RESET
  120. ~~~~~~~~~~~~~~~
  121. MHI is in reset state after power-up or hardware reset. The host is not allowed
  122. to access device MMIO register space.
  123. MHI_STATE_READY
  124. ~~~~~~~~~~~~~~~
  125. MHI is ready for initialization. The host can start MHI initialization by
  126. programming MMIO registers.
  127. MHI_STATE_M0
  128. ~~~~~~~~~~~~
  129. MHI is running and operational in the device. The host can start channels by
  130. issuing channel start command.
  131. MHI_STATE_M1
  132. ~~~~~~~~~~~~
  133. MHI operation is suspended by the device. This state is entered when the
  134. device detects inactivity at the physical interface within a preset time.
  135. MHI_STATE_M2
  136. ~~~~~~~~~~~~
  137. MHI is in low power state. MHI operation is suspended and the device may
  138. enter lower power mode.
  139. MHI_STATE_M3
  140. ~~~~~~~~~~~~
  141. MHI operation stopped by the host. This state is entered when the host suspends
  142. MHI operation.
  143. MHI Initialization
  144. ------------------
  145. After system boots, the device is enumerated over the physical interface.
  146. In the case of PCIe, the device is enumerated and assigned BAR-0 for
  147. the device's MMIO register space. To initialize the MHI in a device,
  148. the host performs the following operations:
  149. * Allocates the MHI context for event, channel and command arrays.
  150. * Initializes the context array, and prepares interrupts.
  151. * Waits until the device enters READY state.
  152. * Programs MHI MMIO registers and sets device into MHI_M0 state.
  153. * Waits for the device to enter M0 state.
  154. MHI Data Transfer
  155. -----------------
  156. MHI data transfer is initiated by the host to transfer data to the device.
  157. Following are the sequence of operations performed by the host to transfer
  158. data to device:
  159. * Host prepares TD with buffer information.
  160. * Host increments the WP of the corresponding channel transfer ring.
  161. * Host rings the channel DB register.
  162. * Device wakes up to process the TD.
  163. * Device generates a completion event for the processed TD by updating ED.
  164. * Device increments the RP of the corresponding event ring.
  165. * Device triggers IRQ to wake up the host.
  166. * Host wakes up and checks the event ring for completion event.
  167. * Host updates the WP of the corresponding event ring to indicate that the
  168. data transfer has been completed successfully.