gadget_rmnet.txt 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. Introduction
  2. ============
  3. QUALCOMM MSM Interface (QMI) defines the interface between MSM and
  4. attached Terminal Equipment (TE). RmNet interface is a new logical
  5. device in QMI framework for data services. RmNet in accordance with
  6. QMI architecture defines channels for control and data transfers and
  7. for example it uses Data I/O channel for IP data transfer and control
  8. I/O channel for QMI messaging (functionality similar to AT commands).
  9. RmNet may be used in place of legacy USB modem interface.
  10. Tethered networking is one of the function from MSM which can also be
  11. supported using QMI protocol. There are other standard protocols exists
  12. such as CDC-ECM and Windows proprietary RNDIS. On the host-side system,
  13. the gadget rmnet device looks like a ethernet adapter.
  14. Hardware description
  15. ====================
  16. QMI is a messaging protocol to expose various functionalities of MSM
  17. and one of the functionality to be tethered networking which is being
  18. exposed over QMI using RmNet protocol. This usb gadget has one bulk-in,
  19. one bulk-out and one interrupt-in endpoint.
  20. Design:
  21. =======
  22. RmNet function driver design follows two approaches:
  23. Approach 1:
  24. -----------
  25. Single function driver is used to communicate with
  26. Modem(both for data and control). Most of the initial
  27. MSM targets are following this approach.
  28. The main disadvantage with this approach is there are
  29. multiple RmNet drivers for any change in DATA and Control
  30. Layer. There is no re-use in the code.
  31. Approach 2:
  32. -----------
  33. RmNet driver is divided into 3 components
  34. 1. USB:
  35. This component has the functionality to deal with composite layer.
  36. Allocates Interfaces, Endpoints, listens to connect/disconnect
  37. interrupts and gives connect/disconnect notifications to DATA and
  38. CONTROL modules.
  39. 2. Data:
  40. This component talks to modem to transfer IP data. Usually DATA
  41. and CONTROL go over same channel. However, to achieve higher
  42. data rates new transport channel for DATA may be used.
  43. 3. Control:
  44. This component talks to modem to transfer rmnet control data.
  45. Software description
  46. ====================
  47. The RmNet suports following data and control transports:
  48. as follows:
  49. 1. SMD Interface
  50. 2. SDIO Interface
  51. 3. BAM Interface
  52. 4. SMD Control Interface
  53. SMD interface uses the Shared memory for the RmNet driver to communicate
  54. with the MSM modem processor.
  55. SDIO interface acts as a link for communication of RmNet driver with the
  56. MDM modem processor.
  57. USB INTERACTION:
  58. ----------------
  59. The RmNet function driver binds with the USB using the struct usb_function.
  60. The function is added using the usb_function_add().
  61. Control Transfers: The RmNet handles two Class-specific control
  62. transfers: SEND_ENCAPSULATED_COMMAND and GET_ENCAPSULATED_RESPONSE.
  63. The asynchronous protocol QMI which consists of the QMI requests/responses
  64. is used for handling the transfers between the RmNet and the Host where the
  65. host sends a new QMI request before receiving the response for the current
  66. QMI request.
  67. Control & Data flow:
  68. 1. Host issues a SEND_ENCAPSULATED command to send a QMI request.
  69. SMD: If the SMD control channel has enough room to accomodate a QMI request,
  70. it is written into the SMD buffer. Otherwise, append/add that request to
  71. qmi_request queue. A tasklet is scheduled to drain all QMI requests in
  72. qmi_request queue.
  73. SDIO: Add each request in the qmi_request queue and is processed until
  74. the queue is empty.
  75. 2. Append/Add QMI response from modem to qmi_response queue.
  76. A notification on an interrupt end point is used to communicate the QMI
  77. response to host.
  78. 3. Host issues a GET_ENCAPSULATED command to retrieve the QMI response.
  79. The response from qmi_response queue will be sent to the host.
  80. 4. After the connection is fully established data can be sent to
  81. bulk-out endpoint and data can be received from bulk-in endpoint.
  82. 5. Host can send QMI requests even after the connection is established.
  83. RmNet gadget driver is completely unaware of QMI/IP protocol. It just
  84. acts as a bridge between the modem and the PC.
  85. All the request/response queues in the driver can be accessed either
  86. from tasklet/workqueue or from interrupt context (either usb or smd/sdio
  87. interrupt handler). Hence a spinlock is used to protect all data/control req
  88. lists.
  89. SMD Interface:
  90. --------------
  91. 1. Each QMI request/response can at most be 2048 bytes. Eight 2KB buffers
  92. are allocated using kmalloc for storing maximum of 8 requests/responses.
  93. 2. Four 2KB buffers are allocated using kmalloc for data transfers on
  94. each bulk endpoint.
  95. Data structures:
  96. struct qmi_buf - Buffer to handle QMI requests & responses
  97. struct rmnet_smd_info - Control & Data SMD channel private data
  98. struct rmnet_dev - Endpoint and driver specific data
  99. Workqueues:
  100. rmnet_connect_work - Called on device connection.
  101. Opens SMD channels; enables endpoints
  102. rmnet_disconnect_work - Called on device disconnection.
  103. Closes SMD channels.
  104. Tasklets:
  105. rmnet_control_rx_tlet
  106. rmnet_control_tx_tlet - Control transfer data reception and transmission
  107. handler
  108. rmnet_data_rx_tlet
  109. rmnet_data_tx_tlet - Data transfer data reception and transmission handler
  110. SMD control interface
  111. ----------------------
  112. This function driver implements exchnage of control informtion with
  113. modem over SMD. Uses smd_read/write commands to read or write rmnet
  114. ctrl packets. Exposes a call back function to usb component to write
  115. control packet and at the same time call a call back usb component
  116. callback to send data to usb host.
  117. Data structures and Interfaces are very similar to control interfaces
  118. explained in "SMD Interface"
  119. BAM MUX interface
  120. ------------------
  121. BAM Mux interface is very similar to SDIO MUX interface. However there
  122. are differences in the way BAM and SDIO operate but all of the details
  123. are masked by MUX Driver.
  124. Refer to the SDIO interfaces for more information on data structures
  125. SDIO Interface:
  126. ---------------
  127. 1. Each QMI request/response buffer is allocated depending on the size
  128. of data to be transmitted for the request/response.
  129. 2. A 2KB network buffer is allocated for data transfer on bulk-out
  130. endpoint. The SDIO allocates the required buffer for data transfers
  131. on an bulk-in endpoint.
  132. Data structures:
  133. struct rmnet_sdio_qmi_buf - Buffer to handle QMI requests/responses.
  134. struct rmnet_dev - Endpoint and driver specific data
  135. Workqueues:
  136. rmnet_connect_work - Device connection handler. Opens SDIO
  137. channels; enables and allocate buffer for
  138. endpoints
  139. rmnet_disconnect_work - Device disconnection handler. Closes
  140. SDIO channels; Frees allocated buffers.
  141. rmnet_control_rx_work - Control data reception handler.
  142. rmnet_data_rx_work - Network data reception handler.
  143. Two SMD/SDIO channels (control and data) are used as communication channels
  144. between Modem and Apps processor. The driver opens the SMD/SDIO channels
  145. on USB device connection. Data is either read from/written to the channels
  146. as one complete packet.
  147. SMD/SDIO provides a notification whenever the Modem processor completes
  148. read/write of a packet. Based on these SMD/SDIO notifications all the
  149. pending read/write requests will be handled. Tasklets(SMD)/Workqueues(SDIO)
  150. are used to get the requests done.
  151. There is another variant of rmnet driver called rmnet_smd_sdio which is used
  152. on some boards. This driver allows the transport (SMD/SDIO) to be chosen
  153. at runtime. This is required because either MDM processor or MODEM processor
  154. is only active at a time for data transfers. As SMD and SDIO interfaces
  155. are different, different endpoint completion handlers are used. This driver
  156. leverage the existing rmnet over smd and rmnet over sdio drivers. The control
  157. messages (QMI) always routed over SDIO. After the control messages exchange,
  158. user space will come to know about the available data transport (SMD/SDIO).
  159. User space notify the same to driver and the corresponding transport is
  160. activated. It is assumed that transport will not change while a USB cable
  161. is connected.
  162. Rmnet over SMD and rmnet over SDIO doesn't expose any of its interfaces to
  163. either kernelspace or userspace. But rmnet over smd/sdio expose a sysfs
  164. interface for userspace to notify the available transport to driver.
  165. The sysfs file can be found at
  166. /sys/class/usb_composite/rmnet_smd_sdio/transport
  167. The below command activates the SMD transport
  168. echo 0 > /sys/class/usb_composite/rmnet_smd_sdio/transport
  169. The below command activates the SDIO transport
  170. echo 1 > /sys/class/usb_composite/rmnet_smd_sdio/transport
  171. -EINVAL is returned if a write is attempted to transport when a USB cable
  172. is not connected.