ipa_usb.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2012-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _IPA_USB_H_
  7. #define _IPA_USB_H_
  8. #include <linux/if_ether.h>
  9. #include <linux/types.h>
  10. enum ipa_usb_teth_prot {
  11. IPA_USB_RNDIS = 0,
  12. IPA_USB_ECM = 1,
  13. IPA_USB_RMNET = 2,
  14. IPA_USB_MBIM = 3,
  15. IPA_USB_DIAG = 4,
  16. IPA_USB_RMNET_CV2X = 5,
  17. IPA_USB_MAX_TETH_PROT_SIZE
  18. };
  19. enum teth_bridge_params {
  20. IPA_TETH_BRIDGE_1 = 0,
  21. IPA_TETH_BRIDGE_2 = 1,
  22. IPA_TETH_BRIDGE_MAX
  23. };
  24. /**
  25. * ipa_usb_teth_params - parameters for RDNIS/ECM initialization API
  26. *
  27. * @host_ethaddr: host Ethernet address in network order
  28. * @device_ethaddr: device Ethernet address in network order
  29. */
  30. struct ipa_usb_teth_params {
  31. u8 host_ethaddr[ETH_ALEN];
  32. u8 device_ethaddr[ETH_ALEN];
  33. };
  34. enum ipa_usb_notify_event {
  35. IPA_USB_DEVICE_READY,
  36. IPA_USB_REMOTE_WAKEUP,
  37. IPA_USB_SUSPEND_COMPLETED
  38. };
  39. enum ipa_usb_max_usb_packet_size {
  40. IPA_USB_FULL_SPEED_64B = 64,
  41. IPA_USB_HIGH_SPEED_512B = 512,
  42. IPA_USB_SUPER_SPEED_1024B = 1024
  43. };
  44. enum ipa_usb_gsi_chan_dir {
  45. CHAN_DIR_FROM_GSI = 0x0,
  46. CHAN_DIR_TO_GSI = 0x1
  47. };
  48. /**
  49. * ipa_usb_teth_prot_params - parameters for connecting RNDIS
  50. *
  51. * @max_xfer_size_bytes_to_dev: max size of UL packets in bytes
  52. * @max_packet_number_to_dev: max number of UL aggregated packets
  53. * @max_xfer_size_bytes_to_host: max size of DL packets in bytes
  54. *
  55. */
  56. struct ipa_usb_teth_prot_params {
  57. u32 max_xfer_size_bytes_to_dev;
  58. u32 max_packet_number_to_dev;
  59. u32 max_xfer_size_bytes_to_host;
  60. };
  61. /**
  62. * ipa_usb_xdci_connect_params - parameters required to start IN, OUT
  63. * channels, and connect RNDIS/ECM/teth_bridge
  64. *
  65. * @max_pkt_size: USB speed (full/high/super/super-speed plus)
  66. * @ipa_to_usb_xferrscidx: Transfer Resource Index (XferRscIdx) for IN channel.
  67. * The hardware-assigned transfer resource index for the
  68. * transfer, which was returned in response to the
  69. * Start Transfer command. This field is used for
  70. * "Update Transfer" command.
  71. * Should be 0 =< ipa_to_usb_xferrscidx <= 127.
  72. * @ipa_to_usb_xferrscidx_valid: true if xferRscIdx should be updated for IN
  73. * channel
  74. * @usb_to_ipa_xferrscidx: Transfer Resource Index (XferRscIdx) for OUT channel
  75. * Should be 0 =< usb_to_ipa_xferrscidx <= 127.
  76. * @usb_to_ipa_xferrscidx_valid: true if xferRscIdx should be updated for OUT
  77. * channel
  78. * @teth_prot: tethering protocol
  79. * @teth_prot_params: parameters for connecting the tethering protocol.
  80. * @max_supported_bandwidth_mbps: maximum bandwidth need of the client in Mbps
  81. */
  82. struct ipa_usb_xdci_connect_params {
  83. enum ipa_usb_max_usb_packet_size max_pkt_size;
  84. u8 ipa_to_usb_xferrscidx;
  85. bool ipa_to_usb_xferrscidx_valid;
  86. u8 usb_to_ipa_xferrscidx;
  87. bool usb_to_ipa_xferrscidx_valid;
  88. enum ipa_usb_teth_prot teth_prot;
  89. struct ipa_usb_teth_prot_params teth_prot_params;
  90. u32 max_supported_bandwidth_mbps;
  91. };
  92. /**
  93. * ipa_usb_xdci_chan_scratch - xDCI protocol SW config area of
  94. * channel scratch
  95. *
  96. * @last_trb_addr_iova: Address (iova LSB - based on alignment restrictions) of
  97. * last TRB in queue. Used to identify roll over case
  98. * @const_buffer_size: TRB buffer size in KB (similar to IPA aggregation
  99. * configuration). Must be aligned to max USB Packet Size.
  100. * Should be 1 <= const_buffer_size <= 31.
  101. * @depcmd_low_addr: Used to generate "Update Transfer" command
  102. * @depcmd_hi_addr: Used to generate "Update Transfer" command.
  103. */
  104. struct ipa_usb_xdci_chan_scratch {
  105. u16 last_trb_addr_iova;
  106. u8 const_buffer_size;
  107. u32 depcmd_low_addr;
  108. u8 depcmd_hi_addr;
  109. };
  110. /**
  111. * ipa_usb_xdci_chan_params - xDCI channel related properties
  112. *
  113. * @keep_ipa_awake: when true, IPA will not be clock gated
  114. * @teth_prot: tethering protocol for which the channel is created
  115. * @gevntcount_low_addr: GEVNCOUNT low address for event scratch
  116. * @gevntcount_hi_addr: GEVNCOUNT high address for event scratch
  117. * @dir: channel direction
  118. * @xfer_ring_len: length of transfer ring in bytes (must be integral
  119. * multiple of transfer element size - 16B for xDCI)
  120. * @xfer_scratch: parameters for xDCI channel scratch
  121. * @xfer_ring_base_addr_iova: IO virtual address mapped to pysical base address
  122. * @data_buff_base_len: length of data buffer allocated by USB driver
  123. * @data_buff_base_addr_iova: IO virtual address mapped to pysical base address
  124. * @sgt_xfer_rings: Scatter table for Xfer rings,contains valid non NULL
  125. * value
  126. * when USB S1-SMMU enabed, else NULL.
  127. * @sgt_data_buff: Scatter table for data buffs,contains valid non NULL
  128. * value
  129. * when USB S1-SMMU enabed, else NULL.
  130. *
  131. */
  132. struct ipa_usb_xdci_chan_params {
  133. /* IPA EP params */
  134. bool keep_ipa_awake;
  135. enum ipa_usb_teth_prot teth_prot;
  136. /* event ring params */
  137. u32 gevntcount_low_addr;
  138. u8 gevntcount_hi_addr;
  139. /* transfer ring params */
  140. enum ipa_usb_gsi_chan_dir dir;
  141. u16 xfer_ring_len;
  142. struct ipa_usb_xdci_chan_scratch xfer_scratch;
  143. u64 xfer_ring_base_addr_iova;
  144. u32 data_buff_base_len;
  145. u64 data_buff_base_addr_iova;
  146. struct sg_table *sgt_xfer_rings;
  147. struct sg_table *sgt_data_buff;
  148. };
  149. /**
  150. * ipa_usb_chan_out_params - out parameters for channel request
  151. *
  152. * @clnt_hdl: opaque client handle assigned by IPA to client
  153. * @db_reg_phs_addr_lsb: Physical address of doorbell register where the 32
  154. * LSBs of the doorbell value should be written
  155. * @db_reg_phs_addr_msb: Physical address of doorbell register where the 32
  156. * MSBs of the doorbell value should be written
  157. *
  158. */
  159. struct ipa_req_chan_out_params {
  160. u32 clnt_hdl;
  161. u32 db_reg_phs_addr_lsb;
  162. u32 db_reg_phs_addr_msb;
  163. };
  164. struct ipa_usb_ops {
  165. int (*init_teth_prot)(enum ipa_usb_teth_prot teth_prot,
  166. struct ipa_usb_teth_params *teth_params,
  167. int (*ipa_usb_notify_cb)(enum ipa_usb_notify_event, void *),
  168. void *user_data);
  169. int (*xdci_connect)
  170. (struct ipa_usb_xdci_chan_params *ul_chan_params,
  171. struct ipa_usb_xdci_chan_params *dl_chan_params,
  172. struct ipa_req_chan_out_params *ul_out_params,
  173. struct ipa_req_chan_out_params *dl_out_params,
  174. struct ipa_usb_xdci_connect_params *connect_params);
  175. int (*xdci_disconnect)(u32 ul_clnt_hdl, u32 dl_clnt_hdl,
  176. enum ipa_usb_teth_prot teth_prot);
  177. int (*deinit_teth_prot)(enum ipa_usb_teth_prot teth_prot);
  178. int (*xdci_suspend)(u32 ul_clnt_hdl, u32 dl_clnt_hdl,
  179. enum ipa_usb_teth_prot teth_prot,
  180. bool with_remote_wakeup);
  181. int (*xdci_resume)(u32 ul_clnt_hdl, u32 dl_clnt_hdl,
  182. enum ipa_usb_teth_prot teth_prot);
  183. bool (*ipa_usb_is_teth_prot_connected)
  184. (enum ipa_usb_teth_prot usb_teth_prot);
  185. };
  186. #if IS_ENABLED(CONFIG_USB_F_GSI)
  187. void ipa_ready_callback(void *ops);
  188. #else
  189. static inline void ipa_ready_callback(void *ops)
  190. { }
  191. #endif
  192. #endif /* _IPA_USB_H_ */