qmi_rmnet_i.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*
  2. * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 and
  7. * only version 2 as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef _RMNET_QMI_I_H
  15. #define _RMNET_QMI_I_H
  16. #include <linux/netdevice.h>
  17. #include <linux/skbuff.h>
  18. #include <linux/timer.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 PS_MAX_BEARERS 32
  32. #define CONFIG_QTI_QMI_RMNET 1
  33. #define CONFIG_QTI_QMI_DFC 1
  34. #define CONFIG_QTI_QMI_POWER_COLLAPSE 1
  35. extern int dfc_mode;
  36. extern int dfc_qmap;
  37. struct qos_info;
  38. enum {
  39. RMNET_CH_DEFAULT,
  40. RMNET_CH_LL,
  41. RMNET_CH_MAX,
  42. RMNET_CH_CTL = 0xFF
  43. };
  44. enum rmnet_ch_switch_state {
  45. CH_SWITCH_NONE,
  46. CH_SWITCH_STARTED,
  47. CH_SWITCH_ACKED,
  48. CH_SWITCH_FAILED_RETRY
  49. };
  50. struct rmnet_ch_switch {
  51. u8 current_ch;
  52. u8 switch_to_ch;
  53. u8 retry_left;
  54. u8 status_code;
  55. bool auto_switched;
  56. enum rmnet_ch_switch_state state;
  57. __be32 switch_txid;
  58. u32 flags;
  59. bool timer_quit;
  60. struct timer_list guard_timer;
  61. u32 nl_pid;
  62. u32 nl_seq;
  63. };
  64. struct rmnet_bearer_map {
  65. struct list_head list;
  66. u8 bearer_id;
  67. int flow_ref;
  68. u32 grant_size;
  69. u32 grant_thresh;
  70. u16 seq;
  71. u8 ack_req;
  72. u32 last_grant;
  73. u16 last_seq;
  74. u32 bytes_in_flight;
  75. u32 last_adjusted_grant;
  76. bool tcp_bidir;
  77. bool rat_switch;
  78. bool tx_off;
  79. u32 ack_txid;
  80. u32 mq_idx;
  81. u32 ack_mq_idx;
  82. struct qos_info *qos;
  83. struct timer_list watchdog;
  84. bool watchdog_started;
  85. bool watchdog_quit;
  86. u32 watchdog_expire_cnt;
  87. struct rmnet_ch_switch ch_switch;
  88. };
  89. struct rmnet_flow_map {
  90. struct list_head list;
  91. u8 bearer_id;
  92. u32 flow_id;
  93. int ip_type;
  94. u32 mq_idx;
  95. struct rmnet_bearer_map *bearer;
  96. };
  97. struct svc_info {
  98. u32 instance;
  99. u32 ep_type;
  100. u32 iface_id;
  101. };
  102. struct mq_map {
  103. struct rmnet_bearer_map *bearer;
  104. bool is_ll_ch;
  105. bool drop_on_remove;
  106. };
  107. struct qos_info {
  108. struct list_head list;
  109. u8 mux_id;
  110. struct net_device *real_dev;
  111. struct net_device *vnd_dev;
  112. struct list_head flow_head;
  113. struct list_head bearer_head;
  114. struct mq_map mq[MAX_MQ_NUM];
  115. u32 tran_num;
  116. spinlock_t qos_lock;
  117. struct rmnet_bearer_map *removed_bearer;
  118. };
  119. struct qmi_info {
  120. int flag;
  121. void *wda_client;
  122. void *wda_pending;
  123. void *dfc_clients[MAX_CLIENT_NUM];
  124. void *dfc_pending[MAX_CLIENT_NUM];
  125. bool dfc_client_exiting[MAX_CLIENT_NUM];
  126. unsigned long ps_work_active;
  127. bool ps_enabled;
  128. bool dl_msg_active;
  129. bool ps_ignore_grant;
  130. int ps_ext;
  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, u8 num_bearers,
  227. u8 *bearer_id);
  228. void qmi_rmnet_flush_ps_wq(void);
  229. void wda_qmi_client_release(void *wda_data);
  230. int dfc_qmap_set_powersave(u8 enable, u8 num_bearers, u8 *bearer_id);
  231. #else
  232. static inline int
  233. wda_qmi_client_init(void *port, struct svc_info *psvc, struct qmi_info *qmi)
  234. {
  235. return -EINVAL;
  236. }
  237. static inline void wda_qmi_client_exit(void *wda_data)
  238. {
  239. }
  240. static inline int wda_set_powersave_mode(void *wda_data, u8 enable,
  241. u8 num_bearers, u8 *bearer_id)
  242. {
  243. return -EINVAL;
  244. }
  245. static inline void qmi_rmnet_flush_ps_wq(void)
  246. {
  247. }
  248. static inline void wda_qmi_client_release(void *wda_data)
  249. {
  250. }
  251. #endif
  252. #endif /*_RMNET_QMI_I_H*/