qmi_rmnet_i.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef _RMNET_QMI_I_H
  14. #define _RMNET_QMI_I_H
  15. #include <linux/netdevice.h>
  16. #include <linux/skbuff.h>
  17. #include <linux/timer.h>
  18. #include <linux/pm_wakeup.h>
  19. #include <uapi/linux/rtnetlink.h>
  20. #include <linux/soc/qcom/qmi.h>
  21. #define MAX_MQ_NUM 16
  22. #define MAX_CLIENT_NUM 2
  23. #define MAX_FLOW_NUM 32
  24. #define DEFAULT_GRANT 1
  25. #define DEFAULT_CALL_GRANT 20480
  26. #define DFC_MAX_BEARERS_V01 16
  27. #define DEFAULT_MQ_NUM 0
  28. #define ACK_MQ_OFFSET (MAX_MQ_NUM - 1)
  29. #define INVALID_MQ 0xFF
  30. #define DFC_MODE_SA 4
  31. #define CONFIG_QTI_QMI_RMNET 1
  32. #define CONFIG_QTI_QMI_DFC 1
  33. #define CONFIG_QTI_QMI_POWER_COLLAPSE 1
  34. extern int dfc_mode;
  35. extern int dfc_qmap;
  36. struct qos_info;
  37. enum {
  38. RMNET_CH_DEFAULT,
  39. RMNET_CH_LL,
  40. RMNET_CH_MAX,
  41. RMNET_CH_CTL = 0xFF
  42. };
  43. enum rmnet_ch_switch_state {
  44. CH_SWITCH_NONE,
  45. CH_SWITCH_STARTED,
  46. CH_SWITCH_ACKED,
  47. CH_SWITCH_FAILED_RETRY
  48. };
  49. struct rmnet_ch_switch {
  50. u8 current_ch;
  51. u8 switch_to_ch;
  52. u8 retry_left;
  53. u8 status_code;
  54. enum rmnet_ch_switch_state state;
  55. __be32 switch_txid;
  56. u32 flags;
  57. bool timer_quit;
  58. struct timer_list guard_timer;
  59. u32 nl_pid;
  60. u32 nl_seq;
  61. };
  62. struct rmnet_bearer_map {
  63. struct list_head list;
  64. u8 bearer_id;
  65. int flow_ref;
  66. u32 grant_size;
  67. u32 grant_thresh;
  68. u16 seq;
  69. u8 ack_req;
  70. u32 last_grant;
  71. u16 last_seq;
  72. u32 bytes_in_flight;
  73. u32 last_adjusted_grant;
  74. bool tcp_bidir;
  75. bool rat_switch;
  76. bool tx_off;
  77. u32 ack_txid;
  78. u32 mq_idx;
  79. u32 ack_mq_idx;
  80. struct qos_info *qos;
  81. struct timer_list watchdog;
  82. bool watchdog_started;
  83. bool watchdog_quit;
  84. u32 watchdog_expire_cnt;
  85. struct rmnet_ch_switch ch_switch;
  86. };
  87. struct rmnet_flow_map {
  88. struct list_head list;
  89. u8 bearer_id;
  90. u32 flow_id;
  91. int ip_type;
  92. u32 mq_idx;
  93. struct rmnet_bearer_map *bearer;
  94. };
  95. struct svc_info {
  96. u32 instance;
  97. u32 ep_type;
  98. u32 iface_id;
  99. };
  100. struct mq_map {
  101. struct rmnet_bearer_map *bearer;
  102. bool is_ll_ch;
  103. bool drop_on_remove;
  104. };
  105. struct qos_info {
  106. struct list_head list;
  107. u8 mux_id;
  108. struct net_device *real_dev;
  109. struct net_device *vnd_dev;
  110. struct list_head flow_head;
  111. struct list_head bearer_head;
  112. struct mq_map mq[MAX_MQ_NUM];
  113. u32 tran_num;
  114. spinlock_t qos_lock;
  115. struct rmnet_bearer_map *removed_bearer;
  116. };
  117. struct qmi_info {
  118. int flag;
  119. void *wda_client;
  120. void *wda_pending;
  121. void *dfc_clients[MAX_CLIENT_NUM];
  122. void *dfc_pending[MAX_CLIENT_NUM];
  123. bool dfc_client_exiting[MAX_CLIENT_NUM];
  124. unsigned long ps_work_active;
  125. bool ps_enabled;
  126. bool dl_msg_active;
  127. bool ps_ignore_grant;
  128. int ps_ext;
  129. bool wakelock_active;
  130. struct wakeup_source *ws;
  131. };
  132. enum data_ep_type_enum_v01 {
  133. DATA_EP_TYPE_ENUM_MIN_ENUM_VAL_V01 = INT_MIN,
  134. DATA_EP_TYPE_RESERVED_V01 = 0x00,
  135. DATA_EP_TYPE_HSIC_V01 = 0x01,
  136. DATA_EP_TYPE_HSUSB_V01 = 0x02,
  137. DATA_EP_TYPE_PCIE_V01 = 0x03,
  138. DATA_EP_TYPE_EMBEDDED_V01 = 0x04,
  139. DATA_EP_TYPE_ENUM_MAX_ENUM_VAL_V01 = INT_MAX
  140. };
  141. struct data_ep_id_type_v01 {
  142. enum data_ep_type_enum_v01 ep_type;
  143. u32 iface_id;
  144. };
  145. extern struct qmi_elem_info data_ep_id_type_v01_ei[];
  146. void *qmi_rmnet_has_dfc_client(struct qmi_info *qmi);
  147. #ifdef CONFIG_QTI_QMI_DFC
  148. struct rmnet_flow_map *
  149. qmi_rmnet_get_flow_map(struct qos_info *qos_info,
  150. u32 flow_id, int ip_type);
  151. struct rmnet_bearer_map *
  152. qmi_rmnet_get_bearer_map(struct qos_info *qos_info, u8 bearer_id);
  153. unsigned int qmi_rmnet_grant_per(unsigned int grant);
  154. int dfc_qmi_client_init(void *port, int index, struct svc_info *psvc,
  155. struct qmi_info *qmi);
  156. void dfc_qmi_client_exit(void *dfc_data);
  157. void dfc_qmi_burst_check(struct net_device *dev, struct qos_info *qos,
  158. int ip_type, u32 mark, unsigned int len);
  159. int qmi_rmnet_flow_control(struct net_device *dev, u32 mq_idx, int enable);
  160. void dfc_qmi_query_flow(void *dfc_data);
  161. int dfc_bearer_flow_ctl(struct net_device *dev,
  162. struct rmnet_bearer_map *bearer,
  163. struct qos_info *qos);
  164. int dfc_qmap_client_init(void *port, int index, struct svc_info *psvc,
  165. struct qmi_info *qmi);
  166. void dfc_qmap_client_exit(void *dfc_data);
  167. void dfc_qmap_send_ack(struct qos_info *qos, u8 bearer_id, u16 seq, u8 type);
  168. struct rmnet_bearer_map *qmi_rmnet_get_bearer_noref(struct qos_info *qos_info,
  169. u8 bearer_id);
  170. void qmi_rmnet_watchdog_add(struct rmnet_bearer_map *bearer);
  171. void qmi_rmnet_watchdog_remove(struct rmnet_bearer_map *bearer);
  172. int rmnet_ll_switch(struct net_device *dev, struct tcmsg *tcm, int attrlen);
  173. void rmnet_ll_guard_fn(struct timer_list *t);
  174. void rmnet_ll_wq_init(void);
  175. void rmnet_ll_wq_exit(void);
  176. #else
  177. static inline struct rmnet_flow_map *
  178. qmi_rmnet_get_flow_map(struct qos_info *qos_info,
  179. uint32_t flow_id, int ip_type)
  180. {
  181. return NULL;
  182. }
  183. static inline struct rmnet_bearer_map *
  184. qmi_rmnet_get_bearer_map(struct qos_info *qos_info, u8 bearer_id)
  185. {
  186. return NULL;
  187. }
  188. static inline int
  189. dfc_qmi_client_init(void *port, int index, struct svc_info *psvc,
  190. struct qmi_info *qmi)
  191. {
  192. return -EINVAL;
  193. }
  194. static inline void dfc_qmi_client_exit(void *dfc_data)
  195. {
  196. }
  197. static inline int
  198. dfc_bearer_flow_ctl(struct net_device *dev,
  199. struct rmnet_bearer_map *bearer,
  200. struct qos_info *qos)
  201. {
  202. return 0;
  203. }
  204. static inline int
  205. dfc_qmap_client_init(void *port, int index, struct svc_info *psvc,
  206. struct qmi_info *qmi)
  207. {
  208. return -EINVAL;
  209. }
  210. static inline void dfc_qmap_client_exit(void *dfc_data)
  211. {
  212. }
  213. static inline void qmi_rmnet_watchdog_remove(struct rmnet_bearer_map *bearer)
  214. {
  215. }
  216. static int rmnet_ll_switch(struct net_device *dev,
  217. struct tcmsg *tcm, int attrlen)
  218. {
  219. return -EINVAL;
  220. }
  221. #endif
  222. #ifdef CONFIG_QTI_QMI_POWER_COLLAPSE
  223. int
  224. wda_qmi_client_init(void *port, struct svc_info *psvc, struct qmi_info *qmi);
  225. void wda_qmi_client_exit(void *wda_data);
  226. int wda_set_powersave_mode(void *wda_data, u8 enable);
  227. void qmi_rmnet_flush_ps_wq(void);
  228. void wda_qmi_client_release(void *wda_data);
  229. int dfc_qmap_set_powersave(u8 enable, u8 num_bearers, u8 *bearer_id);
  230. #else
  231. static inline int
  232. wda_qmi_client_init(void *port, struct svc_info *psvc, struct qmi_info *qmi)
  233. {
  234. return -EINVAL;
  235. }
  236. static inline void wda_qmi_client_exit(void *wda_data)
  237. {
  238. }
  239. static inline int wda_set_powersave_mode(void *wda_data, u8 enable)
  240. {
  241. return -EINVAL;
  242. }
  243. static inline void qmi_rmnet_flush_ps_wq(void)
  244. {
  245. }
  246. static inline void wda_qmi_client_release(void *wda_data)
  247. {
  248. }
  249. #endif
  250. #endif /*_RMNET_QMI_I_H*/