ipa_qmi_service.c 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2013-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/module.h>
  6. #include <linux/slab.h>
  7. #include <linux/errno.h>
  8. #include <linux/delay.h>
  9. #include <linux/debugfs.h>
  10. #include <linux/delay.h>
  11. #include <linux/uaccess.h>
  12. #include <soc/qcom/subsystem_restart.h>
  13. #include <linux/ipa.h>
  14. #include <linux/vmalloc.h>
  15. #include "ipa_qmi_service.h"
  16. #include "ipa_mhi_proxy.h"
  17. #define IPA_Q6_SVC_VERS 1
  18. #define IPA_A5_SVC_VERS 1
  19. #define Q6_QMI_COMPLETION_TIMEOUT (60*HZ)
  20. #define IPA_A5_SERVICE_SVC_ID 0x31
  21. #define IPA_A5_SERVICE_INS_ID 1
  22. #define IPA_Q6_SERVICE_SVC_ID 0x31
  23. #define IPA_Q6_SERVICE_INS_ID 2
  24. #define QMI_SEND_STATS_REQ_TIMEOUT_MS 5000
  25. #define QMI_SEND_REQ_TIMEOUT_MS 60000
  26. #define QMI_MHI_SEND_REQ_TIMEOUT_MS 1000
  27. #define QMI_IPA_FORCE_CLEAR_DATAPATH_TIMEOUT_MS 1000
  28. static struct qmi_handle *ipa3_svc_handle;
  29. static struct workqueue_struct *ipa_clnt_req_workqueue;
  30. static bool ipa3_qmi_modem_init_fin, ipa3_qmi_indication_fin;
  31. static struct work_struct ipa3_qmi_service_init_work;
  32. static uint32_t ipa_wan_platform;
  33. struct ipa3_qmi_context *ipa3_qmi_ctx;
  34. static bool workqueues_stopped;
  35. static bool ipa3_modem_init_cmplt;
  36. static bool first_time_handshake;
  37. static bool send_qmi_init_q6;
  38. struct mutex ipa3_qmi_lock;
  39. struct ipa_msg_desc {
  40. uint16_t msg_id;
  41. int max_msg_len;
  42. struct qmi_elem_info *ei_array;
  43. };
  44. static struct ipa_mhi_prime_aggr_info_req_msg_v01 aggr_req = {
  45. .aggr_info_valid = 1,
  46. .aggr_info_len = 5,
  47. .aggr_info[0] = {
  48. .ic_type = DATA_IC_TYPE_MHI_PRIME_V01,
  49. .ep_type = DATA_EP_DESC_TYPE_DPL_PROD_V01,
  50. .bytes_count = 16,
  51. },
  52. .aggr_info[1] = {
  53. .ic_type = DATA_IC_TYPE_MHI_PRIME_V01,
  54. .ep_type = DATA_EP_DESC_TYPE_TETH_CONS_V01,
  55. .bytes_count = 24,
  56. .aggr_type = DATA_AGGR_TYPE_QMAPv5_V01,
  57. },
  58. .aggr_info[2] = {
  59. .ic_type = DATA_IC_TYPE_MHI_PRIME_V01,
  60. .ep_type = DATA_EP_DESC_TYPE_TETH_PROD_V01,
  61. .bytes_count = 16,
  62. .aggr_type = DATA_AGGR_TYPE_QMAPv5_V01,
  63. },
  64. .aggr_info[3] = {
  65. .ic_type = DATA_IC_TYPE_MHI_PRIME_V01,
  66. .ep_type = DATA_EP_DESC_TYPE_TETH_RMNET_CONS_V01,
  67. .bytes_count = 31,
  68. .aggr_type = DATA_AGGR_TYPE_QMAPv5_V01,
  69. },
  70. .aggr_info[4] = {
  71. .ic_type = DATA_IC_TYPE_MHI_PRIME_V01,
  72. .ep_type = DATA_EP_DESC_TYPE_TETH_RMNET_PROD_V01,
  73. .bytes_count = 31,
  74. .aggr_type = DATA_AGGR_TYPE_QMAPv5_V01,
  75. },
  76. };
  77. /* QMI A5 service */
  78. static void ipa3_handle_indication_req(struct qmi_handle *qmi_handle,
  79. struct sockaddr_qrtr *sq,
  80. struct qmi_txn *txn,
  81. const void *decoded_msg)
  82. {
  83. struct ipa_indication_reg_req_msg_v01 *indication_req;
  84. struct ipa_indication_reg_resp_msg_v01 resp;
  85. struct ipa_master_driver_init_complt_ind_msg_v01 ind;
  86. int rc;
  87. indication_req = (struct ipa_indication_reg_req_msg_v01 *)decoded_msg;
  88. IPAWANDBG("Received INDICATION Request\n");
  89. /* cache the client sq */
  90. memcpy(&ipa3_qmi_ctx->client_sq, sq, sizeof(*sq));
  91. memset(&resp, 0, sizeof(struct ipa_indication_reg_resp_msg_v01));
  92. resp.resp.result = IPA_QMI_RESULT_SUCCESS_V01;
  93. IPAWANDBG("qmi_snd_rsp: result %d, err %d\n",
  94. resp.resp.result, resp.resp.error);
  95. rc = qmi_send_response(qmi_handle, sq, txn,
  96. QMI_IPA_INDICATION_REGISTER_RESP_V01,
  97. QMI_IPA_INDICATION_REGISTER_RESP_MAX_MSG_LEN_V01,
  98. ipa3_indication_reg_resp_msg_data_v01_ei,
  99. &resp);
  100. if (rc < 0) {
  101. IPAWANERR("send response for Indication register failed\n");
  102. return;
  103. }
  104. ipa3_qmi_indication_fin = true;
  105. /* check if need sending indication to modem */
  106. if (ipa3_qmi_modem_init_fin) {
  107. IPAWANDBG("send indication to modem (%d)\n",
  108. ipa3_qmi_modem_init_fin);
  109. memset(&ind, 0, sizeof(struct
  110. ipa_master_driver_init_complt_ind_msg_v01));
  111. ind.master_driver_init_status.result =
  112. IPA_QMI_RESULT_SUCCESS_V01;
  113. rc = qmi_send_indication(qmi_handle,
  114. &(ipa3_qmi_ctx->client_sq),
  115. QMI_IPA_MASTER_DRIVER_INIT_COMPLETE_IND_V01,
  116. QMI_IPA_MASTER_DRIVER_INIT_COMPLETE_IND_MAX_MSG_LEN_V01,
  117. ipa3_master_driver_init_complt_ind_msg_data_v01_ei,
  118. &ind);
  119. if (rc < 0) {
  120. IPAWANERR("send indication failed\n");
  121. ipa3_qmi_indication_fin = false;
  122. }
  123. } else {
  124. IPAWANERR("not send indication\n");
  125. }
  126. }
  127. static void ipa3_handle_install_filter_rule_req(struct qmi_handle *qmi_handle,
  128. struct sockaddr_qrtr *sq,
  129. struct qmi_txn *txn,
  130. const void *decoded_msg)
  131. {
  132. struct ipa_install_fltr_rule_req_msg_v01 *rule_req;
  133. struct ipa_install_fltr_rule_resp_msg_v01 resp;
  134. uint32_t rule_hdl[MAX_NUM_Q6_RULE];
  135. int rc = 0, i;
  136. rule_req = (struct ipa_install_fltr_rule_req_msg_v01 *)decoded_msg;
  137. memset(rule_hdl, 0, sizeof(rule_hdl));
  138. memset(&resp, 0, sizeof(struct ipa_install_fltr_rule_resp_msg_v01));
  139. IPAWANDBG("Received install filter Request\n");
  140. rc = ipa3_copy_ul_filter_rule_to_ipa((struct
  141. ipa_install_fltr_rule_req_msg_v01*)decoded_msg);
  142. if (rc) {
  143. IPAWANERR("copy UL rules from modem is failed\n");
  144. return;
  145. }
  146. resp.resp.result = IPA_QMI_RESULT_SUCCESS_V01;
  147. if (rule_req->filter_spec_ex_list_valid == true) {
  148. resp.rule_id_valid = 1;
  149. if (rule_req->filter_spec_ex_list_len > MAX_NUM_Q6_RULE) {
  150. resp.rule_id_len = MAX_NUM_Q6_RULE;
  151. IPAWANERR("installed (%d) max Q6-UL rules ",
  152. MAX_NUM_Q6_RULE);
  153. IPAWANERR("but modem gives total (%u)\n",
  154. rule_req->filter_spec_ex_list_len);
  155. } else {
  156. resp.rule_id_len =
  157. rule_req->filter_spec_ex_list_len;
  158. }
  159. } else {
  160. resp.rule_id_valid = 0;
  161. resp.rule_id_len = 0;
  162. }
  163. /* construct UL filter rules response to Modem*/
  164. for (i = 0; i < resp.rule_id_len; i++) {
  165. resp.rule_id[i] =
  166. rule_req->filter_spec_ex_list[i].rule_id;
  167. }
  168. IPAWANDBG("qmi_snd_rsp: result %d, err %d\n",
  169. resp.resp.result, resp.resp.error);
  170. rc = qmi_send_response(qmi_handle, sq, txn,
  171. QMI_IPA_INSTALL_FILTER_RULE_RESP_V01,
  172. QMI_IPA_INSTALL_FILTER_RULE_RESP_MAX_MSG_LEN_V01,
  173. ipa3_install_fltr_rule_resp_msg_data_v01_ei,
  174. &resp);
  175. if (rc < 0)
  176. IPAWANERR("install filter rules failed\n");
  177. else
  178. IPAWANDBG("Replied to install filter request\n");
  179. }
  180. static void ipa3_handle_filter_installed_notify_req(
  181. struct qmi_handle *qmi_handle,
  182. struct sockaddr_qrtr *sq,
  183. struct qmi_txn *txn,
  184. const void *decoded_msg)
  185. {
  186. struct ipa_fltr_installed_notif_resp_msg_v01 resp;
  187. int rc = 0;
  188. memset(&resp, 0, sizeof(struct ipa_fltr_installed_notif_resp_msg_v01));
  189. IPAWANDBG("Received filter_install_notify Request\n");
  190. resp.resp.result = IPA_QMI_RESULT_SUCCESS_V01;
  191. IPAWANDBG("qmi_snd_rsp: result %d, err %d\n",
  192. resp.resp.result, resp.resp.error);
  193. rc = qmi_send_response(qmi_handle, sq, txn,
  194. QMI_IPA_FILTER_INSTALLED_NOTIF_RESP_V01,
  195. QMI_IPA_FILTER_INSTALLED_NOTIF_RESP_MAX_MSG_LEN_V01,
  196. ipa3_fltr_installed_notif_resp_msg_data_v01_ei,
  197. &resp);
  198. if (rc < 0)
  199. IPAWANERR("handle filter rules failed\n");
  200. else
  201. IPAWANDBG("Responsed filter_install_notify Request\n");
  202. }
  203. static void handle_ipa_config_req(struct qmi_handle *qmi_handle,
  204. struct sockaddr_qrtr *sq,
  205. struct qmi_txn *txn,
  206. const void *decoded_msg)
  207. {
  208. struct ipa_config_resp_msg_v01 resp;
  209. int rc;
  210. memset(&resp, 0, sizeof(struct ipa_config_resp_msg_v01));
  211. resp.resp.result = IPA_QMI_RESULT_SUCCESS_V01;
  212. IPAWANDBG("Received IPA CONFIG Request\n");
  213. rc = ipa_mhi_handle_ipa_config_req(
  214. (struct ipa_config_req_msg_v01 *)decoded_msg);
  215. if (rc) {
  216. IPAERR("ipa3_mhi_handle_ipa_config_req failed %d\n", rc);
  217. resp.resp.result = IPA_QMI_RESULT_FAILURE_V01;
  218. }
  219. IPAWANDBG("qmi_snd_rsp: result %d, err %d\n",
  220. resp.resp.result, resp.resp.error);
  221. rc = qmi_send_response(qmi_handle, sq, txn,
  222. QMI_IPA_CONFIG_RESP_V01,
  223. QMI_IPA_CONFIG_RESP_MAX_MSG_LEN_V01,
  224. ipa3_config_resp_msg_data_v01_ei,
  225. &resp);
  226. if (rc < 0)
  227. IPAWANERR("QMI_IPA_CONFIG_RESP_V01 failed\n");
  228. else
  229. IPAWANDBG("Responsed QMI_IPA_CONFIG_RESP_V01\n");
  230. }
  231. static void ipa3_handle_modem_init_cmplt_req(struct qmi_handle *qmi_handle,
  232. struct sockaddr_qrtr *sq,
  233. struct qmi_txn *txn,
  234. const void *decoded_msg)
  235. {
  236. struct ipa_init_modem_driver_cmplt_req_msg_v01 *cmplt_req;
  237. struct ipa_init_modem_driver_cmplt_resp_msg_v01 resp;
  238. int rc;
  239. IPAWANDBG("Received QMI_IPA_INIT_MODEM_DRIVER_CMPLT_REQ_V01\n");
  240. cmplt_req = (struct ipa_init_modem_driver_cmplt_req_msg_v01 *)
  241. decoded_msg;
  242. if (!ipa3_modem_init_cmplt)
  243. ipa3_modem_init_cmplt = true;
  244. memset(&resp, 0, sizeof(resp));
  245. resp.resp.result = IPA_QMI_RESULT_SUCCESS_V01;
  246. IPAWANDBG("qmi_snd_rsp: result %d, err %d\n",
  247. resp.resp.result, resp.resp.error);
  248. rc = qmi_send_response(qmi_handle, sq, txn,
  249. QMI_IPA_INIT_MODEM_DRIVER_CMPLT_RESP_V01,
  250. QMI_IPA_INIT_MODEM_DRIVER_CMPLT_RESP_MAX_MSG_LEN_V01,
  251. ipa3_init_modem_driver_cmplt_resp_msg_data_v01_ei,
  252. &resp);
  253. if (rc < 0)
  254. IPAWANERR("QMI_IPA_INIT_MODEM_DRIVER_CMPLT_RESP_V01 failed\n");
  255. else
  256. IPAWANDBG("Sent QMI_IPA_INIT_MODEM_DRIVER_CMPLT_RESP_V01\n");
  257. }
  258. static void ipa3_handle_mhi_alloc_channel_req(struct qmi_handle *qmi_handle,
  259. struct sockaddr_qrtr *sq,
  260. struct qmi_txn *txn,
  261. const void *decoded_msg)
  262. {
  263. struct ipa_mhi_alloc_channel_req_msg_v01 *ch_alloc_req;
  264. struct ipa_mhi_alloc_channel_resp_msg_v01 *resp = NULL;
  265. int rc;
  266. IPAWANDBG("Received QMI_IPA_MHI_ALLOC_CHANNEL_REQ_V01\n");
  267. ch_alloc_req = (struct ipa_mhi_alloc_channel_req_msg_v01 *)decoded_msg;
  268. resp = imp_handle_allocate_channel_req(ch_alloc_req);
  269. if (!resp) {
  270. IPAWANERR("imp handle allocate channel req fails\n");
  271. return;
  272. }
  273. IPAWANDBG("qmi_snd_rsp: result %d, err %d, arr_vald: %d, arr_len %d\n",
  274. resp->resp.result, resp->resp.error, resp->alloc_resp_arr_valid,
  275. resp->alloc_resp_arr_len);
  276. rc = qmi_send_response(qmi_handle, sq, txn,
  277. QMI_IPA_MHI_ALLOC_CHANNEL_RESP_V01,
  278. IPA_MHI_ALLOC_CHANNEL_RESP_MSG_V01_MAX_MSG_LEN,
  279. ipa_mhi_alloc_channel_resp_msg_v01_ei,
  280. resp);
  281. if (rc < 0)
  282. IPAWANERR("QMI_IPA_MHI_ALLOC_CHANNEL_RESP_V01 failed\n");
  283. else
  284. IPAWANDBG("Sent QMI_IPA_MHI_ALLOC_CHANNEL_RESP_V01\n");
  285. }
  286. static void ipa3_handle_mhi_vote_req(struct qmi_handle *qmi_handle,
  287. struct sockaddr_qrtr *sq,
  288. struct qmi_txn *txn,
  289. const void *decoded_msg)
  290. {
  291. struct ipa_mhi_clk_vote_req_msg_v01 *vote_req;
  292. struct ipa_mhi_clk_vote_resp_msg_v01 *resp = NULL, resp2;
  293. int rc;
  294. uint32_t bw_mbps = 0;
  295. vote_req = (struct ipa_mhi_clk_vote_req_msg_v01 *)decoded_msg;
  296. IPAWANDBG("Received QMI_IPA_MHI_CLK_VOTE_REQ_V01(%d)\n",
  297. vote_req->mhi_vote);
  298. memset(&resp2, 0, sizeof(struct ipa_mhi_clk_vote_resp_msg_v01));
  299. /* for mpm used for ipa clk voting */
  300. if (ipa3_is_apq()) {
  301. IPAWANDBG("Throughput(%d:%d) clk-rate(%d:%d)\n",
  302. vote_req->tput_value_valid,
  303. vote_req->tput_value,
  304. vote_req->clk_rate_valid,
  305. vote_req->clk_rate);
  306. if (vote_req->clk_rate_valid) {
  307. switch (vote_req->clk_rate) {
  308. case QMI_IPA_CLOCK_RATE_LOW_SVS_V01:
  309. bw_mbps = 0;
  310. break;
  311. case QMI_IPA_CLOCK_RATE_SVS_V01:
  312. bw_mbps = 350;
  313. break;
  314. case QMI_IPA_CLOCK_RATE_NOMINAL_V01:
  315. bw_mbps = 690;
  316. break;
  317. case QMI_IPA_CLOCK_RATE_TURBO_V01:
  318. bw_mbps = 1200;
  319. break;
  320. default:
  321. IPAWANERR("Note supported clk_rate (%d)\n",
  322. vote_req->clk_rate);
  323. bw_mbps = 0;
  324. resp2.resp.result = IPA_QMI_RESULT_FAILURE_V01;
  325. resp2.resp.error =
  326. IPA_QMI_ERR_NOT_SUPPORTED_V01;
  327. break;
  328. }
  329. if (ipa3_vote_for_bus_bw(&bw_mbps)) {
  330. IPAWANERR("Failed to vote BW (%u)\n", bw_mbps);
  331. resp2.resp.result = IPA_QMI_RESULT_FAILURE_V01;
  332. resp2.resp.error =
  333. IPA_QMI_ERR_NOT_SUPPORTED_V01;
  334. }
  335. resp = &resp2;
  336. } else {
  337. IPAWANERR("clk_rate_valid is false\n");
  338. return;
  339. }
  340. } else {
  341. resp = imp_handle_vote_req(vote_req->mhi_vote);
  342. if (!resp) {
  343. IPAWANERR("imp handle vote req fails\n");
  344. return;
  345. }
  346. IPAWANDBG("start sending QMI_IPA_MHI_CLK_VOTE_RESP_V01\n");
  347. }
  348. IPAWANDBG("qmi_snd_rsp: result %d, err %d\n",
  349. resp->resp.result, resp->resp.error);
  350. rc = qmi_send_response(qmi_handle, sq, txn,
  351. QMI_IPA_MHI_CLK_VOTE_RESP_V01,
  352. IPA_MHI_CLK_VOTE_RESP_MSG_V01_MAX_MSG_LEN,
  353. ipa_mhi_clk_vote_resp_msg_v01_ei,
  354. resp);
  355. if (rc < 0)
  356. IPAWANERR("QMI_IPA_MHI_CLK_VOTE_RESP_V01 failed\n");
  357. else
  358. IPAWANDBG("Finished senting QMI_IPA_MHI_CLK_VOTE_RESP_V01\n");
  359. }
  360. static void ipa3_a5_svc_disconnect_cb(struct qmi_handle *qmi,
  361. unsigned int node, unsigned int port)
  362. {
  363. IPAWANDBG_LOW("Received QMI client disconnect\n");
  364. }
  365. /****************************************************/
  366. /* QMI A5 client ->Q6 */
  367. /****************************************************/
  368. static void ipa3_q6_clnt_svc_arrive(struct work_struct *work);
  369. static DECLARE_DELAYED_WORK(ipa3_work_svc_arrive, ipa3_q6_clnt_svc_arrive);
  370. static void ipa3_q6_clnt_svc_exit(struct work_struct *work);
  371. static DECLARE_DELAYED_WORK(ipa3_work_svc_exit, ipa3_q6_clnt_svc_exit);
  372. /* Test client port for IPC Router */
  373. static struct qmi_handle *ipa_q6_clnt;
  374. static int ipa3_check_qmi_response(int rc,
  375. int req_id,
  376. enum ipa_qmi_result_type_v01 result,
  377. enum ipa_qmi_error_type_v01 error,
  378. char *resp_type)
  379. {
  380. if (rc < 0) {
  381. if (rc == -ETIMEDOUT && ipa3_rmnet_ctx.ipa_rmnet_ssr) {
  382. IPAWANERR(
  383. "Timeout for qmi request id %d\n", req_id);
  384. return rc;
  385. }
  386. if ((rc == -ENETRESET) || (rc == -ENODEV)) {
  387. IPAWANERR(
  388. "SSR while waiting for qmi request id %d\n", req_id);
  389. return rc;
  390. }
  391. IPAWANERR("Error sending qmi request id %d, rc = %d\n",
  392. req_id, rc);
  393. return rc;
  394. }
  395. if (result != IPA_QMI_RESULT_SUCCESS_V01 &&
  396. ipa3_rmnet_ctx.ipa_rmnet_ssr) {
  397. IPAWANERR(
  398. "Got bad response %d from request id %d (error %d)\n",
  399. req_id, result, error);
  400. return result;
  401. }
  402. IPAWANDBG_LOW("Received %s successfully\n", resp_type);
  403. return 0;
  404. }
  405. static int ipa3_qmi_send_req_wait(struct qmi_handle *client_handle,
  406. struct ipa_msg_desc *req_desc, void *req,
  407. struct ipa_msg_desc *resp_desc, void *resp,
  408. unsigned long timeout_ms)
  409. {
  410. struct qmi_txn txn;
  411. int ret;
  412. ret = qmi_txn_init(client_handle, &txn, resp_desc->ei_array, resp);
  413. if (ret < 0) {
  414. IPAWANERR("QMI txn init failed, ret= %d\n", ret);
  415. return ret;
  416. }
  417. ret = qmi_send_request(client_handle,
  418. &ipa3_qmi_ctx->server_sq,
  419. &txn,
  420. req_desc->msg_id,
  421. req_desc->max_msg_len,
  422. req_desc->ei_array,
  423. req);
  424. if (ret < 0) {
  425. qmi_txn_cancel(&txn);
  426. return ret;
  427. }
  428. ret = qmi_txn_wait(&txn, msecs_to_jiffies(timeout_ms));
  429. return ret;
  430. }
  431. static int ipa3_qmi_init_modem_send_sync_msg(void)
  432. {
  433. struct ipa_init_modem_driver_req_msg_v01 req;
  434. struct ipa_init_modem_driver_resp_msg_v01 resp;
  435. struct ipa_msg_desc req_desc, resp_desc;
  436. int rc;
  437. u16 smem_restr_bytes = ipa3_get_smem_restr_bytes();
  438. int wan_cons_ep;
  439. memset(&req, 0, sizeof(struct ipa_init_modem_driver_req_msg_v01));
  440. memset(&resp, 0, sizeof(struct ipa_init_modem_driver_resp_msg_v01));
  441. req.platform_type_valid = true;
  442. req.platform_type = ipa_wan_platform;
  443. req.hdr_tbl_info_valid = (IPA_MEM_PART(modem_hdr_size) != 0);
  444. req.hdr_tbl_info.modem_offset_start =
  445. IPA_MEM_PART(modem_hdr_ofst) + smem_restr_bytes;
  446. req.hdr_tbl_info.modem_offset_end = IPA_MEM_PART(modem_hdr_ofst) +
  447. smem_restr_bytes + IPA_MEM_PART(modem_hdr_size) - 1;
  448. req.v4_route_tbl_info_valid = true;
  449. req.v4_route_tbl_info.route_tbl_start_addr =
  450. IPA_MEM_PART(v4_rt_nhash_ofst) + smem_restr_bytes;
  451. req.v4_route_tbl_info.num_indices =
  452. IPA_MEM_PART(v4_modem_rt_index_hi);
  453. req.v6_route_tbl_info_valid = true;
  454. req.v6_route_tbl_info.route_tbl_start_addr =
  455. IPA_MEM_PART(v6_rt_nhash_ofst) + smem_restr_bytes;
  456. req.v6_route_tbl_info.num_indices =
  457. IPA_MEM_PART(v6_modem_rt_index_hi);
  458. req.v4_filter_tbl_start_addr_valid = true;
  459. req.v4_filter_tbl_start_addr =
  460. IPA_MEM_PART(v4_flt_nhash_ofst) + smem_restr_bytes;
  461. req.v6_filter_tbl_start_addr_valid = true;
  462. req.v6_filter_tbl_start_addr =
  463. IPA_MEM_PART(v6_flt_nhash_ofst) + smem_restr_bytes;
  464. req.modem_mem_info_valid = (IPA_MEM_PART(modem_size) != 0);
  465. req.modem_mem_info.block_start_addr =
  466. IPA_MEM_PART(modem_ofst) + smem_restr_bytes;
  467. req.modem_mem_info.size = IPA_MEM_PART(modem_size);
  468. wan_cons_ep = ipa_get_ep_mapping(IPA_CLIENT_APPS_WAN_CONS);
  469. if (wan_cons_ep == IPA_EP_NOT_ALLOCATED) {
  470. IPAWANDBG("APPS_WAN_CONS is not valid\n");
  471. req.ctrl_comm_dest_end_pt_valid = false;
  472. req.ctrl_comm_dest_end_pt = 0;
  473. } else {
  474. req.ctrl_comm_dest_end_pt_valid = true;
  475. req.ctrl_comm_dest_end_pt =
  476. ipa_get_ep_mapping(IPA_CLIENT_APPS_WAN_CONS);
  477. }
  478. req.hdr_proc_ctx_tbl_info_valid =
  479. (IPA_MEM_PART(modem_hdr_proc_ctx_size) != 0);
  480. req.hdr_proc_ctx_tbl_info.modem_offset_start =
  481. IPA_MEM_PART(modem_hdr_proc_ctx_ofst) + smem_restr_bytes;
  482. req.hdr_proc_ctx_tbl_info.modem_offset_end =
  483. IPA_MEM_PART(modem_hdr_proc_ctx_ofst) +
  484. IPA_MEM_PART(modem_hdr_proc_ctx_size) + smem_restr_bytes - 1;
  485. req.zip_tbl_info_valid = (IPA_MEM_PART(modem_comp_decomp_size) != 0);
  486. req.zip_tbl_info.modem_offset_start =
  487. IPA_MEM_PART(modem_comp_decomp_size) + smem_restr_bytes;
  488. req.zip_tbl_info.modem_offset_end =
  489. IPA_MEM_PART(modem_comp_decomp_ofst) +
  490. IPA_MEM_PART(modem_comp_decomp_size) + smem_restr_bytes - 1;
  491. /* if hashing not supported, Modem filter/routing hash
  492. * tables should not fill with valid data.
  493. */
  494. if (!ipa3_ctx_get_flag(IPA_FLTRT_NOT_HASHABLE_EN)) {
  495. req.v4_hash_route_tbl_info_valid = true;
  496. req.v4_hash_route_tbl_info.route_tbl_start_addr =
  497. IPA_MEM_PART(v4_rt_hash_ofst) + smem_restr_bytes;
  498. req.v4_hash_route_tbl_info.num_indices =
  499. IPA_MEM_PART(v4_modem_rt_index_hi);
  500. req.v6_hash_route_tbl_info_valid = true;
  501. req.v6_hash_route_tbl_info.route_tbl_start_addr =
  502. IPA_MEM_PART(v6_rt_hash_ofst) + smem_restr_bytes;
  503. req.v6_hash_route_tbl_info.num_indices =
  504. IPA_MEM_PART(v6_modem_rt_index_hi);
  505. req.v4_hash_filter_tbl_start_addr_valid = true;
  506. req.v4_hash_filter_tbl_start_addr =
  507. IPA_MEM_PART(v4_flt_hash_ofst) + smem_restr_bytes;
  508. req.v6_hash_filter_tbl_start_addr_valid = true;
  509. req.v6_hash_filter_tbl_start_addr =
  510. IPA_MEM_PART(v6_flt_hash_ofst) + smem_restr_bytes;
  511. }
  512. req.hw_stats_quota_base_addr_valid = true;
  513. req.hw_stats_quota_base_addr =
  514. IPA_MEM_PART(stats_quota_ofst) + smem_restr_bytes;
  515. req.hw_stats_quota_size_valid = true;
  516. req.hw_stats_quota_size = IPA_MEM_PART(stats_quota_size);
  517. req.hw_drop_stats_base_addr_valid = true;
  518. req.hw_drop_stats_base_addr =
  519. IPA_MEM_PART(stats_drop_ofst) + smem_restr_bytes;
  520. req.hw_drop_stats_table_size_valid = true;
  521. req.hw_drop_stats_table_size = IPA_MEM_PART(stats_drop_size);
  522. if (!ipa3_uc_loaded_check()) { /* First time boot */
  523. req.is_ssr_bootup_valid = false;
  524. req.is_ssr_bootup = 0;
  525. } else { /* After SSR boot */
  526. req.is_ssr_bootup_valid = true;
  527. req.is_ssr_bootup = 1;
  528. }
  529. IPAWANDBG("platform_type %d\n", req.platform_type);
  530. IPAWANDBG("hdr_tbl_info.modem_offset_start %d\n",
  531. req.hdr_tbl_info.modem_offset_start);
  532. IPAWANDBG("hdr_tbl_info.modem_offset_end %d\n",
  533. req.hdr_tbl_info.modem_offset_end);
  534. IPAWANDBG("v4_route_tbl_info.route_tbl_start_addr %d\n",
  535. req.v4_route_tbl_info.route_tbl_start_addr);
  536. IPAWANDBG("v4_route_tbl_info.num_indices %d\n",
  537. req.v4_route_tbl_info.num_indices);
  538. IPAWANDBG("v6_route_tbl_info.route_tbl_start_addr %d\n",
  539. req.v6_route_tbl_info.route_tbl_start_addr);
  540. IPAWANDBG("v6_route_tbl_info.num_indices %d\n",
  541. req.v6_route_tbl_info.num_indices);
  542. IPAWANDBG("v4_filter_tbl_start_addr %d\n",
  543. req.v4_filter_tbl_start_addr);
  544. IPAWANDBG("v6_filter_tbl_start_addr %d\n",
  545. req.v6_filter_tbl_start_addr);
  546. IPAWANDBG("modem_mem_info.block_start_addr %d\n",
  547. req.modem_mem_info.block_start_addr);
  548. IPAWANDBG("modem_mem_info.size %d\n",
  549. req.modem_mem_info.size);
  550. IPAWANDBG("ctrl_comm_dest_end_pt %d\n",
  551. req.ctrl_comm_dest_end_pt);
  552. IPAWANDBG("is_ssr_bootup %d\n",
  553. req.is_ssr_bootup);
  554. IPAWANDBG("v4_hash_route_tbl_info.route_tbl_start_addr %d\n",
  555. req.v4_hash_route_tbl_info.route_tbl_start_addr);
  556. IPAWANDBG("v4_hash_route_tbl_info.num_indices %d\n",
  557. req.v4_hash_route_tbl_info.num_indices);
  558. IPAWANDBG("v6_hash_route_tbl_info.route_tbl_start_addr %d\n",
  559. req.v6_hash_route_tbl_info.route_tbl_start_addr);
  560. IPAWANDBG("v6_hash_route_tbl_info.num_indices %d\n",
  561. req.v6_hash_route_tbl_info.num_indices);
  562. IPAWANDBG("v4_hash_filter_tbl_start_addr %d\n",
  563. req.v4_hash_filter_tbl_start_addr);
  564. IPAWANDBG("v6_hash_filter_tbl_start_addr %d\n",
  565. req.v6_hash_filter_tbl_start_addr);
  566. req_desc.max_msg_len = QMI_IPA_INIT_MODEM_DRIVER_REQ_MAX_MSG_LEN_V01;
  567. req_desc.msg_id = QMI_IPA_INIT_MODEM_DRIVER_REQ_V01;
  568. req_desc.ei_array = ipa3_init_modem_driver_req_msg_data_v01_ei;
  569. resp_desc.max_msg_len = QMI_IPA_INIT_MODEM_DRIVER_RESP_MAX_MSG_LEN_V01;
  570. resp_desc.msg_id = QMI_IPA_INIT_MODEM_DRIVER_RESP_V01;
  571. resp_desc.ei_array = ipa3_init_modem_driver_resp_msg_data_v01_ei;
  572. pr_info("Sending QMI_IPA_INIT_MODEM_DRIVER_REQ_V01\n");
  573. if (unlikely(!ipa_q6_clnt))
  574. return -ETIMEDOUT;
  575. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  576. &req_desc, &req,
  577. &resp_desc, &resp,
  578. QMI_SEND_REQ_TIMEOUT_MS);
  579. if (rc < 0) {
  580. IPAWANERR("QMI send Req %d failed, rc= %d\n",
  581. QMI_IPA_INIT_MODEM_DRIVER_REQ_V01,
  582. rc);
  583. return rc;
  584. }
  585. pr_info("QMI_IPA_INIT_MODEM_DRIVER_REQ_V01 response received\n");
  586. return ipa3_check_qmi_response(rc,
  587. QMI_IPA_INIT_MODEM_DRIVER_REQ_V01, resp.resp.result,
  588. resp.resp.error, "ipa_init_modem_driver_resp_msg_v01");
  589. }
  590. /* sending filter-install-request to modem*/
  591. int ipa3_qmi_filter_request_send(struct ipa_install_fltr_rule_req_msg_v01 *req)
  592. {
  593. struct ipa_install_fltr_rule_resp_msg_v01 resp;
  594. struct ipa_msg_desc req_desc, resp_desc;
  595. int rc;
  596. int i;
  597. /* check if modem up */
  598. if (!ipa3_qmi_indication_fin ||
  599. !ipa3_qmi_modem_init_fin ||
  600. !ipa_q6_clnt) {
  601. IPAWANDBG("modem QMI haven't up yet\n");
  602. return -EINVAL;
  603. }
  604. /* check if the filter rules from IPACM is valid */
  605. if (req->filter_spec_list_len == 0) {
  606. IPAWANDBG("IPACM pass zero rules to Q6\n");
  607. } else {
  608. IPAWANDBG("IPACM pass %u rules to Q6\n",
  609. req->filter_spec_list_len);
  610. }
  611. if (req->filter_spec_list_len >= QMI_IPA_MAX_FILTERS_V01) {
  612. IPAWANDBG(
  613. "IPACM passes the number of filtering rules exceed limit\n");
  614. return -EINVAL;
  615. } else if (req->source_pipe_index_valid != 0) {
  616. IPAWANDBG(
  617. "IPACM passes source_pipe_index_valid not zero 0 != %d\n",
  618. req->source_pipe_index_valid);
  619. return -EINVAL;
  620. } else if (req->source_pipe_index >= ipa3_ctx_get_num_pipes()) {
  621. IPAWANDBG(
  622. "IPACM passes source pipe index not valid ID = %d\n",
  623. req->source_pipe_index);
  624. return -EINVAL;
  625. }
  626. for (i = 0; i < req->filter_spec_list_len; i++) {
  627. if ((req->filter_spec_list[i].ip_type !=
  628. QMI_IPA_IP_TYPE_V4_V01) &&
  629. (req->filter_spec_list[i].ip_type !=
  630. QMI_IPA_IP_TYPE_V6_V01))
  631. return -EINVAL;
  632. if (req->filter_spec_list[i].is_mux_id_valid == false)
  633. return -EINVAL;
  634. if (req->filter_spec_list[i].is_routing_table_index_valid
  635. == false)
  636. return -EINVAL;
  637. if ((req->filter_spec_list[i].filter_action <=
  638. QMI_IPA_FILTER_ACTION_INVALID_V01) ||
  639. (req->filter_spec_list[i].filter_action >
  640. QMI_IPA_FILTER_ACTION_EXCEPTION_V01))
  641. return -EINVAL;
  642. }
  643. mutex_lock(&ipa3_qmi_lock);
  644. if (ipa3_qmi_ctx != NULL) {
  645. /* cache the qmi_filter_request */
  646. memcpy(&(ipa3_qmi_ctx->ipa_install_fltr_rule_req_msg_cache[
  647. ipa3_qmi_ctx->num_ipa_install_fltr_rule_req_msg]),
  648. req,
  649. sizeof(struct ipa_install_fltr_rule_req_msg_v01));
  650. ipa3_qmi_ctx->num_ipa_install_fltr_rule_req_msg++;
  651. ipa3_qmi_ctx->num_ipa_install_fltr_rule_req_msg %= 10;
  652. }
  653. mutex_unlock(&ipa3_qmi_lock);
  654. req_desc.max_msg_len = QMI_IPA_INSTALL_FILTER_RULE_REQ_MAX_MSG_LEN_V01;
  655. req_desc.msg_id = QMI_IPA_INSTALL_FILTER_RULE_REQ_V01;
  656. req_desc.ei_array = ipa3_install_fltr_rule_req_msg_data_v01_ei;
  657. memset(&resp, 0, sizeof(struct ipa_install_fltr_rule_resp_msg_v01));
  658. resp_desc.max_msg_len =
  659. QMI_IPA_INSTALL_FILTER_RULE_RESP_MAX_MSG_LEN_V01;
  660. resp_desc.msg_id = QMI_IPA_INSTALL_FILTER_RULE_RESP_V01;
  661. resp_desc.ei_array = ipa3_install_fltr_rule_resp_msg_data_v01_ei;
  662. if (unlikely(!ipa_q6_clnt))
  663. return -ETIMEDOUT;
  664. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  665. &req_desc, req,
  666. &resp_desc, &resp,
  667. QMI_SEND_REQ_TIMEOUT_MS);
  668. if (rc < 0) {
  669. IPAWANERR("QMI send Req %d failed, rc= %d\n",
  670. QMI_IPA_INSTALL_FILTER_RULE_REQ_V01,
  671. rc);
  672. return rc;
  673. }
  674. return ipa3_check_qmi_response(rc,
  675. QMI_IPA_INSTALL_FILTER_RULE_REQ_V01, resp.resp.result,
  676. resp.resp.error, "ipa_install_filter");
  677. }
  678. /* sending filter-install-request to modem*/
  679. int ipa3_qmi_filter_request_ex_send(
  680. struct ipa_install_fltr_rule_req_ex_msg_v01 *req)
  681. {
  682. struct ipa_install_fltr_rule_resp_ex_msg_v01 resp;
  683. struct ipa_msg_desc req_desc, resp_desc;
  684. int rc;
  685. int i;
  686. /* check if modem up */
  687. if (!ipa3_qmi_indication_fin ||
  688. !ipa3_qmi_modem_init_fin ||
  689. !ipa_q6_clnt) {
  690. IPAWANDBG("modem QMI haven't up yet\n");
  691. return -EINVAL;
  692. }
  693. /* check if the filter rules from IPACM is valid */
  694. if (req->filter_spec_ex_list_len == 0) {
  695. IPAWANDBG("IPACM pass zero rules to Q6\n");
  696. } else {
  697. IPAWANDBG("IPACM pass %u rules to Q6\n",
  698. req->filter_spec_ex_list_len);
  699. }
  700. if (req->filter_spec_ex_list_len >= QMI_IPA_MAX_FILTERS_EX_V01) {
  701. IPAWANDBG(
  702. "IPACM pass the number of filtering rules exceed limit\n");
  703. return -EINVAL;
  704. } else if (req->source_pipe_index_valid != 0) {
  705. IPAWANDBG(
  706. "IPACM passes source_pipe_index_valid not zero 0 != %d\n",
  707. req->source_pipe_index_valid);
  708. return -EINVAL;
  709. }
  710. for (i = 0; i < req->filter_spec_ex_list_len; i++) {
  711. if ((req->filter_spec_ex_list[i].ip_type !=
  712. QMI_IPA_IP_TYPE_V4_V01) &&
  713. (req->filter_spec_ex_list[i].ip_type !=
  714. QMI_IPA_IP_TYPE_V6_V01))
  715. return -EINVAL;
  716. if (req->filter_spec_ex_list[i].is_mux_id_valid == false)
  717. return -EINVAL;
  718. if (req->filter_spec_ex_list[i].is_routing_table_index_valid
  719. == false)
  720. return -EINVAL;
  721. if ((req->filter_spec_ex_list[i].filter_action <=
  722. QMI_IPA_FILTER_ACTION_INVALID_V01) ||
  723. (req->filter_spec_ex_list[i].filter_action >
  724. QMI_IPA_FILTER_ACTION_EXCEPTION_V01))
  725. return -EINVAL;
  726. }
  727. mutex_lock(&ipa3_qmi_lock);
  728. if (ipa3_qmi_ctx != NULL) {
  729. /* cache the qmi_filter_request */
  730. memcpy(&(ipa3_qmi_ctx->ipa_install_fltr_rule_req_ex_msg_cache[
  731. ipa3_qmi_ctx->num_ipa_install_fltr_rule_req_ex_msg]),
  732. req,
  733. sizeof(struct ipa_install_fltr_rule_req_ex_msg_v01));
  734. ipa3_qmi_ctx->num_ipa_install_fltr_rule_req_ex_msg++;
  735. ipa3_qmi_ctx->num_ipa_install_fltr_rule_req_ex_msg %= 10;
  736. }
  737. mutex_unlock(&ipa3_qmi_lock);
  738. req_desc.max_msg_len =
  739. QMI_IPA_INSTALL_FILTER_RULE_EX_REQ_MAX_MSG_LEN_V01;
  740. req_desc.msg_id = QMI_IPA_INSTALL_FILTER_RULE_EX_REQ_V01;
  741. req_desc.ei_array = ipa3_install_fltr_rule_req_ex_msg_data_v01_ei;
  742. memset(&resp, 0, sizeof(struct ipa_install_fltr_rule_resp_ex_msg_v01));
  743. resp_desc.max_msg_len =
  744. QMI_IPA_INSTALL_FILTER_RULE_EX_RESP_MAX_MSG_LEN_V01;
  745. resp_desc.msg_id = QMI_IPA_INSTALL_FILTER_RULE_EX_RESP_V01;
  746. resp_desc.ei_array = ipa3_install_fltr_rule_resp_ex_msg_data_v01_ei;
  747. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  748. &req_desc, req,
  749. &resp_desc, &resp,
  750. QMI_SEND_REQ_TIMEOUT_MS);
  751. if (rc < 0) {
  752. IPAWANERR("QMI send Req %d failed, rc= %d\n",
  753. QMI_IPA_INSTALL_FILTER_RULE_EX_REQ_V01,
  754. rc);
  755. return rc;
  756. }
  757. return ipa3_check_qmi_response(rc,
  758. QMI_IPA_INSTALL_FILTER_RULE_EX_REQ_V01, resp.resp.result,
  759. resp.resp.error, "ipa_install_filter");
  760. }
  761. /* sending add offload-connection-request to modem*/
  762. int ipa3_qmi_add_offload_request_send(
  763. struct ipa_add_offload_connection_req_msg_v01 *req)
  764. {
  765. struct ipa_add_offload_connection_resp_msg_v01 resp;
  766. struct ipa_msg_desc req_desc, resp_desc;
  767. int rc = 0;
  768. int i, j;
  769. uint32_t id;
  770. /* check if modem up */
  771. if (!ipa3_qmi_modem_init_fin ||
  772. !ipa_q6_clnt) {
  773. IPAWANDBG("modem QMI haven't up yet\n");
  774. return -EINVAL;
  775. }
  776. /* check if the filter rules from IPACM is valid */
  777. if (req->filter_spec_ex2_list_len == 0) {
  778. IPAWANDBG("IPACM pass zero rules to Q6\n");
  779. } else {
  780. IPAWANDBG("IPACM pass %u rules to Q6\n",
  781. req->filter_spec_ex2_list_len);
  782. }
  783. /* currently set total max to 64 */
  784. if (req->filter_spec_ex2_list_len +
  785. ipa3_qmi_ctx->num_ipa_offload_connection
  786. >= QMI_IPA_MAX_FILTERS_V01) {
  787. IPAWANDBG(
  788. "cur(%d), req(%d), exceed limit (%d)\n",
  789. ipa3_qmi_ctx->num_ipa_offload_connection,
  790. req->filter_spec_ex2_list_len,
  791. QMI_IPA_MAX_FILTERS_V01);
  792. return -EINVAL;
  793. }
  794. for (i = 0; i < req->filter_spec_ex2_list_len; i++) {
  795. if ((req->filter_spec_ex2_list[i].ip_type !=
  796. QMI_IPA_IP_TYPE_V4_V01) &&
  797. (req->filter_spec_ex2_list[i].ip_type !=
  798. QMI_IPA_IP_TYPE_V6_V01))
  799. return -EINVAL;
  800. if (req->filter_spec_ex2_list[i].is_mux_id_valid == false)
  801. return -EINVAL;
  802. if ((req->filter_spec_ex2_list[i].filter_action <=
  803. QMI_IPA_FILTER_ACTION_INVALID_V01) ||
  804. (req->filter_spec_ex2_list[i].filter_action >
  805. QMI_IPA_FILTER_ACTION_EXCEPTION_V01))
  806. return -EINVAL;
  807. }
  808. req_desc.max_msg_len =
  809. IPA_ADD_OFFLOAD_CONNECTION_REQ_MSG_V01_MAX_MSG_LEN;
  810. req_desc.msg_id = QMI_IPA_ADD_OFFLOAD_CONNECTION_REQ_V01;
  811. req_desc.ei_array = ipa_add_offload_connection_req_msg_v01_ei;
  812. memset(&resp, 0, sizeof(struct
  813. ipa_add_offload_connection_resp_msg_v01));
  814. resp_desc.max_msg_len =
  815. IPA_ADD_OFFLOAD_CONNECTION_RESP_MSG_V01_MAX_MSG_LEN;
  816. resp_desc.msg_id = QMI_IPA_ADD_OFFLOAD_CONNECTION_RESP_V01;
  817. resp_desc.ei_array = ipa_add_offload_connection_resp_msg_v01_ei;
  818. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  819. &req_desc, req,
  820. &resp_desc, &resp,
  821. QMI_SEND_REQ_TIMEOUT_MS);
  822. if (rc < 0) {
  823. IPAWANERR("QMI send Req %d failed, rc= %d\n",
  824. QMI_IPA_ADD_OFFLOAD_CONNECTION_REQ_V01,
  825. rc);
  826. return rc;
  827. }
  828. rc = ipa3_check_qmi_response(rc,
  829. QMI_IPA_ADD_OFFLOAD_CONNECTION_REQ_V01, resp.resp.result,
  830. resp.resp.error, "ipa_add_offload_connection");
  831. if (rc) {
  832. IPAWANERR("QMI get Response %d failed, rc= %d\n",
  833. QMI_IPA_ADD_OFFLOAD_CONNECTION_REQ_V01,
  834. rc);
  835. return rc;
  836. }
  837. /* Check & copy rule-handle */
  838. if (!resp.filter_handle_list_valid) {
  839. IPAWANERR("QMI resp invalid %d failed\n",
  840. resp.filter_handle_list_valid);
  841. return -ERANGE;
  842. }
  843. if (resp.filter_handle_list_len !=
  844. req->filter_spec_ex2_list_len) {
  845. IPAWANERR("QMI resp invalid size %d req %d\n",
  846. resp.filter_handle_list_len,
  847. req->filter_spec_ex2_list_len);
  848. return -ERANGE;
  849. }
  850. mutex_lock(&ipa3_qmi_lock);
  851. for (i = 0; i < req->filter_spec_ex2_list_len; i++) {
  852. id = resp.filter_handle_list[i].filter_spec_identifier;
  853. /* check rule-id matched or not */
  854. if (req->filter_spec_ex2_list[i].rule_id !=
  855. id) {
  856. IPAWANERR("QMI error (%d)st-(%d) rule-id (%d)\n",
  857. i,
  858. id,
  859. req->filter_spec_ex2_list[i].rule_id);
  860. mutex_unlock(&ipa3_qmi_lock);
  861. return -EINVAL;
  862. }
  863. /* find free spot*/
  864. for (j = 0; j < QMI_IPA_MAX_FILTERS_V01; j++) {
  865. if (!ipa3_qmi_ctx->ipa_offload_cache[j].valid)
  866. break;
  867. }
  868. if (j == QMI_IPA_MAX_FILTERS_V01) {
  869. IPAWANERR("can't find free spot for rule-id %d\n",
  870. id);
  871. mutex_unlock(&ipa3_qmi_lock);
  872. return -EINVAL;
  873. }
  874. /* save rule-id handle to cache */
  875. ipa3_qmi_ctx->ipa_offload_cache[j].rule_id =
  876. resp.filter_handle_list[i].filter_spec_identifier;
  877. ipa3_qmi_ctx->ipa_offload_cache[j].rule_hdl =
  878. resp.filter_handle_list[i].filter_handle;
  879. ipa3_qmi_ctx->ipa_offload_cache[j].valid = true;
  880. ipa3_qmi_ctx->ipa_offload_cache[j].ip_type =
  881. req->filter_spec_ex2_list[i].ip_type;
  882. ipa3_qmi_ctx->num_ipa_offload_connection++;
  883. }
  884. mutex_unlock(&ipa3_qmi_lock);
  885. IPAWANDBG("Update cached conntrack entries (%d)\n",
  886. ipa3_qmi_ctx->num_ipa_offload_connection);
  887. return rc;
  888. }
  889. /* sending rmv offload-connection-request to modem*/
  890. int ipa3_qmi_rmv_offload_request_send(
  891. struct ipa_remove_offload_connection_req_msg_v01 *req)
  892. {
  893. struct ipa_remove_offload_connection_resp_msg_v01 resp;
  894. struct ipa_msg_desc req_desc, resp_desc;
  895. int rc = 0;
  896. int i, j;
  897. uint32_t id;
  898. /* check if modem up */
  899. if (!ipa3_qmi_modem_init_fin ||
  900. !ipa_q6_clnt) {
  901. IPAWANDBG("modem QMI haven't up yet\n");
  902. return -EINVAL;
  903. }
  904. /* check if the # of handles from IPACM is valid */
  905. if (!req->clean_all_rules_valid && req->filter_handle_list_len == 0) {
  906. IPAWANDBG("IPACM deleted zero rules !\n");
  907. return -EINVAL;
  908. }
  909. IPAWANDBG("IPACM pass (%d) rules handles to Q6, cur (%d)\n",
  910. req->filter_handle_list_len,
  911. ipa3_qmi_ctx->num_ipa_offload_connection);
  912. /* max as num_ipa_offload_connection */
  913. if (req->filter_handle_list_len >
  914. ipa3_qmi_ctx->num_ipa_offload_connection) {
  915. IPAWANDBG(
  916. "cur(%d), req_rmv(%d)\n",
  917. ipa3_qmi_ctx->num_ipa_offload_connection,
  918. req->filter_handle_list_len);
  919. return -EINVAL;
  920. }
  921. mutex_lock(&ipa3_qmi_lock);
  922. for (i = 0; i < req->filter_handle_list_len; i++) {
  923. /* check if rule-id match */
  924. id =
  925. req->filter_handle_list[i].filter_spec_identifier;
  926. for (j = 0; j < QMI_IPA_MAX_FILTERS_V01; j++) {
  927. if ((ipa3_qmi_ctx->ipa_offload_cache[j].valid) &&
  928. (ipa3_qmi_ctx->ipa_offload_cache[j].rule_id ==
  929. id))
  930. break;
  931. }
  932. if (j == QMI_IPA_MAX_FILTERS_V01) {
  933. IPAWANERR("can't find rule-id %d\n",
  934. id);
  935. mutex_unlock(&ipa3_qmi_lock);
  936. return -EINVAL;
  937. }
  938. /* fill up the filter_handle */
  939. req->filter_handle_list[i].filter_handle =
  940. ipa3_qmi_ctx->ipa_offload_cache[j].rule_hdl;
  941. ipa3_qmi_ctx->ipa_offload_cache[j].valid = false;
  942. ipa3_qmi_ctx->num_ipa_offload_connection--;
  943. }
  944. mutex_unlock(&ipa3_qmi_lock);
  945. req_desc.max_msg_len =
  946. IPA_REMOVE_OFFLOAD_CONNECTION_REQ_MSG_V01_MAX_MSG_LEN;
  947. req_desc.msg_id = QMI_IPA_REMOVE_OFFLOAD_CONNECTION_REQ_V01;
  948. req_desc.ei_array = ipa_remove_offload_connection_req_msg_v01_ei;
  949. /* clean the Dl rules in the cache if flag is set */
  950. if (req->clean_all_rules) {
  951. for (i = 0; i < QMI_IPA_MAX_FILTERS_V01; i++)
  952. if (ipa3_qmi_ctx->ipa_offload_cache[i].valid)
  953. ipa3_qmi_ctx->ipa_offload_cache[i].valid =
  954. false;
  955. }
  956. memset(&resp, 0, sizeof(struct
  957. ipa_remove_offload_connection_resp_msg_v01));
  958. resp_desc.max_msg_len =
  959. IPA_REMOVE_OFFLOAD_CONNECTION_RESP_MSG_V01_MAX_MSG_LEN;
  960. resp_desc.msg_id = QMI_IPA_REMOVE_OFFLOAD_CONNECTION_RESP_V01;
  961. resp_desc.ei_array = ipa_remove_offload_connection_resp_msg_v01_ei;
  962. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  963. &req_desc, req,
  964. &resp_desc, &resp,
  965. QMI_SEND_REQ_TIMEOUT_MS);
  966. if (rc < 0) {
  967. IPAWANERR("QMI send Req %d failed, rc= %d\n",
  968. QMI_IPA_REMOVE_OFFLOAD_CONNECTION_REQ_V01,
  969. rc);
  970. return rc;
  971. }
  972. IPAWANDBG("left cached conntrack entries (%d)\n",
  973. ipa3_qmi_ctx->num_ipa_offload_connection);
  974. return ipa3_check_qmi_response(rc,
  975. QMI_IPA_REMOVE_OFFLOAD_CONNECTION_REQ_V01, resp.resp.result,
  976. resp.resp.error, "ipa_rmv_offload_connection");
  977. }
  978. /* sending ul-filter-install-request to modem*/
  979. int ipa3_qmi_ul_filter_request_send(
  980. struct ipa_configure_ul_firewall_rules_req_msg_v01 *req)
  981. {
  982. struct ipa_configure_ul_firewall_rules_resp_msg_v01 resp;
  983. struct ipa_msg_desc req_desc, resp_desc;
  984. int rc, i;
  985. IPAWANDBG("IPACM pass %u rules to Q6\n",
  986. req->firewall_rules_list_len);
  987. mutex_lock(&ipa3_qmi_lock);
  988. if (ipa3_qmi_ctx != NULL) {
  989. /* cache the qmi_filter_request */
  990. memcpy(
  991. &(ipa3_qmi_ctx->ipa_configure_ul_firewall_rules_req_msg_cache[
  992. ipa3_qmi_ctx->num_ipa_configure_ul_firewall_rules_req_msg]),
  993. req,
  994. sizeof(struct
  995. ipa_configure_ul_firewall_rules_req_msg_v01));
  996. ipa3_qmi_ctx->num_ipa_configure_ul_firewall_rules_req_msg++;
  997. ipa3_qmi_ctx->num_ipa_configure_ul_firewall_rules_req_msg %=
  998. MAX_NUM_QMI_RULE_CACHE;
  999. }
  1000. mutex_unlock(&ipa3_qmi_lock);
  1001. /* check if modem is up */
  1002. if (!ipa3_qmi_indication_fin ||
  1003. !ipa3_qmi_modem_init_fin ||
  1004. !ipa_q6_clnt) {
  1005. IPAWANDBG("modem QMI service is not up yet\n");
  1006. return -EINVAL;
  1007. }
  1008. /* Passing 0 rules means that firewall is disabled */
  1009. if (req->firewall_rules_list_len == 0)
  1010. IPAWANDBG("IPACM passed 0 rules to Q6\n");
  1011. if (req->firewall_rules_list_len >= QMI_IPA_MAX_UL_FIREWALL_RULES_V01) {
  1012. IPAWANERR(
  1013. "Number of rules passed by IPACM, %d, exceed limit %d\n",
  1014. req->firewall_rules_list_len,
  1015. QMI_IPA_MAX_UL_FIREWALL_RULES_V01);
  1016. return -EINVAL;
  1017. }
  1018. /* Check for valid IP type */
  1019. for (i = 0; i < req->firewall_rules_list_len; i++) {
  1020. if (req->firewall_rules_list[i].ip_type !=
  1021. QMI_IPA_IP_TYPE_V4_V01 &&
  1022. req->firewall_rules_list[i].ip_type !=
  1023. QMI_IPA_IP_TYPE_V6_V01) {
  1024. IPAWANERR("Invalid IP type %d\n",
  1025. req->firewall_rules_list[i].ip_type);
  1026. return -EINVAL;
  1027. }
  1028. }
  1029. req_desc.max_msg_len =
  1030. QMI_IPA_INSTALL_UL_FIREWALL_RULES_REQ_MAX_MSG_LEN_V01;
  1031. req_desc.msg_id = QMI_IPA_INSTALL_UL_FIREWALL_RULES_REQ_V01;
  1032. req_desc.ei_array =
  1033. ipa3_configure_ul_firewall_rules_req_msg_data_v01_ei;
  1034. memset(&resp, 0,
  1035. sizeof(struct ipa_configure_ul_firewall_rules_resp_msg_v01));
  1036. resp_desc.max_msg_len =
  1037. QMI_IPA_INSTALL_UL_FIREWALL_RULES_RESP_MAX_MSG_LEN_V01;
  1038. resp_desc.msg_id = QMI_IPA_INSTALL_UL_FIREWALL_RULES_RESP_V01;
  1039. resp_desc.ei_array =
  1040. ipa3_configure_ul_firewall_rules_resp_msg_data_v01_ei;
  1041. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  1042. &req_desc, req,
  1043. &resp_desc, &resp,
  1044. QMI_SEND_REQ_TIMEOUT_MS);
  1045. if (rc < 0) {
  1046. IPAWANERR("send Req %d failed, rc= %d\n",
  1047. QMI_IPA_INSTALL_UL_FIREWALL_RULES_REQ_V01,
  1048. rc);
  1049. return rc;
  1050. }
  1051. return ipa3_check_qmi_response(rc,
  1052. QMI_IPA_INSTALL_UL_FIREWALL_RULES_REQ_V01,
  1053. resp.resp.result,
  1054. resp.resp.error, "ipa_received_ul_firewall_filter");
  1055. }
  1056. int ipa3_qmi_enable_force_clear_datapath_send(
  1057. struct ipa_enable_force_clear_datapath_req_msg_v01 *req)
  1058. {
  1059. struct ipa_enable_force_clear_datapath_resp_msg_v01 resp;
  1060. struct ipa_msg_desc req_desc, resp_desc;
  1061. int rc = 0;
  1062. if (!req || !req->source_pipe_bitmask) {
  1063. IPAWANERR("invalid params\n");
  1064. return -EINVAL;
  1065. }
  1066. if (ipa3_ctx_get_type(IPA3_HW_MODE) == IPA_HW_MODE_VIRTUAL ||
  1067. ipa3_ctx_get_type(IPA3_HW_MODE) == IPA_HW_MODE_EMULATION) {
  1068. IPAWANDBG("Simulating success on emu/virt mode\n");
  1069. return 0;
  1070. }
  1071. req_desc.max_msg_len =
  1072. QMI_IPA_ENABLE_FORCE_CLEAR_DATAPATH_REQ_MAX_MSG_LEN_V01;
  1073. req_desc.msg_id = QMI_IPA_ENABLE_FORCE_CLEAR_DATAPATH_REQ_V01;
  1074. req_desc.ei_array =
  1075. ipa3_enable_force_clear_datapath_req_msg_data_v01_ei;
  1076. memset(&resp, 0, sizeof(struct ipa_fltr_installed_notif_resp_msg_v01));
  1077. resp_desc.max_msg_len =
  1078. QMI_IPA_ENABLE_FORCE_CLEAR_DATAPATH_RESP_MAX_MSG_LEN_V01;
  1079. resp_desc.msg_id = QMI_IPA_ENABLE_FORCE_CLEAR_DATAPATH_RESP_V01;
  1080. resp_desc.ei_array =
  1081. ipa3_enable_force_clear_datapath_resp_msg_data_v01_ei;
  1082. if (unlikely(!ipa_q6_clnt))
  1083. return -ETIMEDOUT;
  1084. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  1085. &req_desc, req,
  1086. &resp_desc, &resp,
  1087. QMI_IPA_FORCE_CLEAR_DATAPATH_TIMEOUT_MS);
  1088. if (rc < 0) {
  1089. IPAWANERR("send Req %d failed, rc= %d\n",
  1090. QMI_IPA_ENABLE_FORCE_CLEAR_DATAPATH_REQ_V01,
  1091. rc);
  1092. return rc;
  1093. }
  1094. if (resp.resp.result != IPA_QMI_RESULT_SUCCESS_V01) {
  1095. IPAWANERR("filter_notify failed %d\n",
  1096. resp.resp.result);
  1097. return resp.resp.result;
  1098. }
  1099. return ipa3_check_qmi_response(rc,
  1100. QMI_IPA_ENABLE_FORCE_CLEAR_DATAPATH_REQ_V01,
  1101. resp.resp.result,
  1102. resp.resp.error, "ipa_enable_force_clear_datapath");
  1103. }
  1104. int ipa3_qmi_disable_force_clear_datapath_send(
  1105. struct ipa_disable_force_clear_datapath_req_msg_v01 *req)
  1106. {
  1107. struct ipa_disable_force_clear_datapath_resp_msg_v01 resp;
  1108. struct ipa_msg_desc req_desc, resp_desc;
  1109. int rc = 0;
  1110. if (!req) {
  1111. IPAWANERR("invalid params\n");
  1112. return -EINVAL;
  1113. }
  1114. if (ipa3_ctx_get_type(IPA3_HW_MODE) == IPA_HW_MODE_VIRTUAL ||
  1115. ipa3_ctx_get_type(IPA3_HW_MODE) == IPA_HW_MODE_EMULATION) {
  1116. IPAWANDBG("Simulating success on emu/virt mode\n");
  1117. return 0;
  1118. }
  1119. req_desc.max_msg_len =
  1120. QMI_IPA_DISABLE_FORCE_CLEAR_DATAPATH_REQ_MAX_MSG_LEN_V01;
  1121. req_desc.msg_id = QMI_IPA_DISABLE_FORCE_CLEAR_DATAPATH_REQ_V01;
  1122. req_desc.ei_array =
  1123. ipa3_disable_force_clear_datapath_req_msg_data_v01_ei;
  1124. memset(&resp, 0, sizeof(struct ipa_fltr_installed_notif_resp_msg_v01));
  1125. resp_desc.max_msg_len =
  1126. QMI_IPA_DISABLE_FORCE_CLEAR_DATAPATH_RESP_MAX_MSG_LEN_V01;
  1127. resp_desc.msg_id = QMI_IPA_DISABLE_FORCE_CLEAR_DATAPATH_RESP_V01;
  1128. resp_desc.ei_array =
  1129. ipa3_disable_force_clear_datapath_resp_msg_data_v01_ei;
  1130. if (unlikely(!ipa_q6_clnt))
  1131. return -ETIMEDOUT;
  1132. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  1133. &req_desc, req,
  1134. &resp_desc, &resp,
  1135. QMI_IPA_FORCE_CLEAR_DATAPATH_TIMEOUT_MS);
  1136. if (rc < 0) {
  1137. IPAWANERR("send Req %d failed, rc= %d\n",
  1138. QMI_IPA_DISABLE_FORCE_CLEAR_DATAPATH_REQ_V01,
  1139. rc);
  1140. return rc;
  1141. }
  1142. if (resp.resp.result != IPA_QMI_RESULT_SUCCESS_V01) {
  1143. IPAWANERR("filter_notify failed %d\n",
  1144. resp.resp.result);
  1145. return resp.resp.result;
  1146. }
  1147. return ipa3_check_qmi_response(rc,
  1148. QMI_IPA_DISABLE_FORCE_CLEAR_DATAPATH_REQ_V01,
  1149. resp.resp.result,
  1150. resp.resp.error, "ipa_disable_force_clear_datapath");
  1151. }
  1152. /* sending filter-installed-notify-request to modem*/
  1153. int ipa3_qmi_filter_notify_send(
  1154. struct ipa_fltr_installed_notif_req_msg_v01 *req)
  1155. {
  1156. struct ipa_fltr_installed_notif_resp_msg_v01 resp;
  1157. struct ipa_msg_desc req_desc, resp_desc;
  1158. int rc = 0;
  1159. /* check if the filter rules from IPACM is valid */
  1160. if (req->rule_id_len == 0) {
  1161. IPAWANDBG(" delete UL filter rule for pipe %d\n",
  1162. req->source_pipe_index);
  1163. } else if (req->rule_id_len > QMI_IPA_MAX_FILTERS_V01) {
  1164. IPAWANERR(" UL filter rule for pipe %d exceed max (%u)\n",
  1165. req->source_pipe_index,
  1166. req->rule_id_len);
  1167. return -EINVAL;
  1168. }
  1169. if (req->rule_id_ex_len == 0) {
  1170. IPAWANDBG(" delete UL filter rule for pipe %d\n",
  1171. req->source_pipe_index);
  1172. } else if (req->rule_id_ex_len > QMI_IPA_MAX_FILTERS_EX2_V01) {
  1173. IPAWANERR(" UL filter rule for pipe %d exceed max (%u)\n",
  1174. req->source_pipe_index,
  1175. req->rule_id_ex_len);
  1176. return -EINVAL;
  1177. }
  1178. if (req->install_status != IPA_QMI_RESULT_SUCCESS_V01) {
  1179. IPAWANERR(" UL filter rule for pipe %d install_status = %d\n",
  1180. req->source_pipe_index, req->install_status);
  1181. return -EINVAL;
  1182. } else if ((req->rule_id_valid != 1) &&
  1183. (req->rule_id_ex_valid != 1)) {
  1184. IPAWANERR(" UL filter rule for pipe %d rule_id_valid = %d/%d\n",
  1185. req->source_pipe_index, req->rule_id_valid,
  1186. req->rule_id_ex_valid);
  1187. return -EINVAL;
  1188. } else if (req->source_pipe_index >= ipa3_ctx_get_num_pipes()) {
  1189. IPAWANDBG(
  1190. "IPACM passes source pipe index not valid ID = %d\n",
  1191. req->source_pipe_index);
  1192. return -EINVAL;
  1193. } else if (((req->embedded_pipe_index_valid != true) ||
  1194. (req->embedded_call_mux_id_valid != true)) &&
  1195. ((req->embedded_pipe_index_valid != false) ||
  1196. (req->embedded_call_mux_id_valid != false))) {
  1197. IPAWANERR(
  1198. "IPACM passes embedded pipe and mux valid not valid\n");
  1199. return -EINVAL;
  1200. } else if (req->embedded_pipe_index >= ipa3_ctx_get_num_pipes()) {
  1201. IPAWANERR("IPACM passes source pipe index not valid ID = %d\n",
  1202. req->source_pipe_index);
  1203. return -EINVAL;
  1204. }
  1205. if (req->source_pipe_index == -1) {
  1206. IPAWANERR("Source pipe index invalid\n");
  1207. return -EINVAL;
  1208. }
  1209. mutex_lock(&ipa3_qmi_lock);
  1210. if (ipa3_qmi_ctx != NULL) {
  1211. /* cache the qmi_filter_request */
  1212. memcpy(&(ipa3_qmi_ctx->ipa_fltr_installed_notif_req_msg_cache[
  1213. ipa3_qmi_ctx->num_ipa_fltr_installed_notif_req_msg]),
  1214. req,
  1215. sizeof(struct ipa_fltr_installed_notif_req_msg_v01));
  1216. ipa3_qmi_ctx->num_ipa_fltr_installed_notif_req_msg++;
  1217. ipa3_qmi_ctx->num_ipa_fltr_installed_notif_req_msg %= 10;
  1218. }
  1219. mutex_unlock(&ipa3_qmi_lock);
  1220. req_desc.max_msg_len =
  1221. QMI_IPA_FILTER_INSTALLED_NOTIF_REQ_MAX_MSG_LEN_V01;
  1222. req_desc.msg_id = QMI_IPA_FILTER_INSTALLED_NOTIF_REQ_V01;
  1223. req_desc.ei_array = ipa3_fltr_installed_notif_req_msg_data_v01_ei;
  1224. memset(&resp, 0, sizeof(struct ipa_fltr_installed_notif_resp_msg_v01));
  1225. resp_desc.max_msg_len =
  1226. QMI_IPA_FILTER_INSTALLED_NOTIF_RESP_MAX_MSG_LEN_V01;
  1227. resp_desc.msg_id = QMI_IPA_FILTER_INSTALLED_NOTIF_RESP_V01;
  1228. resp_desc.ei_array = ipa3_fltr_installed_notif_resp_msg_data_v01_ei;
  1229. if (unlikely(!ipa_q6_clnt))
  1230. return -ETIMEDOUT;
  1231. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  1232. &req_desc, req,
  1233. &resp_desc, &resp,
  1234. QMI_SEND_REQ_TIMEOUT_MS);
  1235. if (rc < 0) {
  1236. IPAWANERR("send Req %d failed, rc= %d\n",
  1237. QMI_IPA_FILTER_INSTALLED_NOTIF_REQ_V01,
  1238. rc);
  1239. return rc;
  1240. }
  1241. return ipa3_check_qmi_response(rc,
  1242. QMI_IPA_FILTER_INSTALLED_NOTIF_REQ_V01, resp.resp.result,
  1243. resp.resp.error, "ipa_fltr_installed_notif_resp");
  1244. }
  1245. static void ipa3_q6_clnt_quota_reached_ind_cb(struct qmi_handle *handle,
  1246. struct sockaddr_qrtr *sq,
  1247. struct qmi_txn *txn,
  1248. const void *data)
  1249. {
  1250. struct ipa_data_usage_quota_reached_ind_msg_v01 *qmi_ind;
  1251. if (handle != ipa_q6_clnt) {
  1252. IPAWANERR("Wrong client\n");
  1253. return;
  1254. }
  1255. qmi_ind = (struct ipa_data_usage_quota_reached_ind_msg_v01 *) data;
  1256. IPAWANDBG("Quota reached indication on qmux(%d) Mbytes(%lu)\n",
  1257. qmi_ind->apn.mux_id, (unsigned long) qmi_ind->apn.num_Mbytes);
  1258. ipa3_broadcast_quota_reach_ind(qmi_ind->apn.mux_id,
  1259. IPA_UPSTEAM_MODEM);
  1260. }
  1261. static void ipa3_q6_clnt_install_firewall_rules_ind_cb(
  1262. struct qmi_handle *handle,
  1263. struct sockaddr_qrtr *sq,
  1264. struct qmi_txn *txn,
  1265. const void *data)
  1266. {
  1267. struct ipa_configure_ul_firewall_rules_ind_msg_v01 qmi_ul_firewall_ind;
  1268. memset(&qmi_ul_firewall_ind, 0, sizeof(
  1269. struct ipa_configure_ul_firewall_rules_ind_msg_v01));
  1270. memcpy(&qmi_ul_firewall_ind, data, sizeof(
  1271. struct ipa_configure_ul_firewall_rules_ind_msg_v01));
  1272. IPAWANDBG("UL firewall rules install indication on Q6");
  1273. if (qmi_ul_firewall_ind.result.is_success ==
  1274. QMI_IPA_UL_FIREWALL_STATUS_SUCCESS_V01) {
  1275. IPAWANDBG(" : Success\n");
  1276. IPAWANDBG
  1277. ("Mux ID : %d\n", qmi_ul_firewall_ind.result.mux_id);
  1278. } else if (qmi_ul_firewall_ind.result.is_success ==
  1279. QMI_IPA_UL_FIREWALL_STATUS_FAILURE_V01) {
  1280. IPAWANERR(": Failure\n");
  1281. } else {
  1282. IPAWANERR(": Unexpected Result");
  1283. }
  1284. }
  1285. static void ipa3_q6_clnt_svc_arrive(struct work_struct *work)
  1286. {
  1287. int rc;
  1288. struct ipa_master_driver_init_complt_ind_msg_v01 ind;
  1289. rc = kernel_connect(ipa_q6_clnt->sock,
  1290. (struct sockaddr *) &ipa3_qmi_ctx->server_sq,
  1291. sizeof(ipa3_qmi_ctx->server_sq),
  1292. 0);
  1293. if (rc < 0) {
  1294. IPAWANERR("Couldnt connect Server\n");
  1295. return;
  1296. }
  1297. if (!send_qmi_init_q6)
  1298. return;
  1299. IPAWANDBG("Q6 QMI service available now\n");
  1300. if (ipa3_is_apq()) {
  1301. ipa3_qmi_modem_init_fin = true;
  1302. IPAWANDBG("QMI-client complete, ipa3_qmi_modem_init_fin : %d\n",
  1303. ipa3_qmi_modem_init_fin);
  1304. return;
  1305. }
  1306. /* Initialize modem IPA-driver */
  1307. IPAWANDBG("send ipa3_qmi_init_modem_send_sync_msg to modem\n");
  1308. rc = ipa3_qmi_init_modem_send_sync_msg();
  1309. if ((rc == -ENETRESET) || (rc == -ENODEV)) {
  1310. IPAWANERR(
  1311. "ipa3_qmi_init_modem_send_sync_msg failed due to SSR!\n");
  1312. /* Cleanup when ipa3_wwan_remove is called */
  1313. vfree(ipa_q6_clnt);
  1314. ipa_q6_clnt = NULL;
  1315. return;
  1316. }
  1317. if (rc != 0) {
  1318. IPAWANERR("ipa3_qmi_init_modem_send_sync_msg failed\n");
  1319. /*
  1320. * Hardware not responding.
  1321. * This is a very unexpected scenario
  1322. * which requires a kernel panic in
  1323. * order to force dumps for QMI/Q6 side analysis.
  1324. */
  1325. BUG();
  1326. }
  1327. ipa3_qmi_modem_init_fin = true;
  1328. /* In cold-bootup, first_time_handshake = false */
  1329. ipa3_q6_handshake_complete(first_time_handshake);
  1330. first_time_handshake = true;
  1331. IPAWANDBG("complete, ipa3_qmi_modem_init_fin : %d\n",
  1332. ipa3_qmi_modem_init_fin);
  1333. if (ipa3_qmi_indication_fin) {
  1334. IPAWANDBG("send indication to modem (%d)\n",
  1335. ipa3_qmi_indication_fin);
  1336. memset(&ind, 0, sizeof(struct
  1337. ipa_master_driver_init_complt_ind_msg_v01));
  1338. ind.master_driver_init_status.result =
  1339. IPA_QMI_RESULT_SUCCESS_V01;
  1340. if (unlikely(!ipa3_svc_handle)) {
  1341. IPAWANERR("Invalid svc handle.Ignore sending ind.");
  1342. return;
  1343. }
  1344. rc = qmi_send_indication(ipa3_svc_handle,
  1345. &ipa3_qmi_ctx->client_sq,
  1346. QMI_IPA_MASTER_DRIVER_INIT_COMPLETE_IND_V01,
  1347. QMI_IPA_MASTER_DRIVER_INIT_COMPLETE_IND_MAX_MSG_LEN_V01,
  1348. ipa3_master_driver_init_complt_ind_msg_data_v01_ei,
  1349. &ind);
  1350. IPAWANDBG("ipa_qmi_service_client good\n");
  1351. } else {
  1352. IPAWANERR("not send indication (%d)\n",
  1353. ipa3_qmi_indication_fin);
  1354. }
  1355. send_qmi_init_q6 = false;
  1356. }
  1357. static void ipa3_q6_clnt_svc_exit(struct work_struct *work)
  1358. {
  1359. if (ipa3_qmi_ctx != NULL) {
  1360. ipa3_qmi_ctx->server_sq.sq_family = 0;
  1361. ipa3_qmi_ctx->server_sq.sq_node = 0;
  1362. ipa3_qmi_ctx->server_sq.sq_port = 0;
  1363. }
  1364. }
  1365. static int ipa3_q6_clnt_svc_event_notify_svc_new(struct qmi_handle *qmi,
  1366. struct qmi_service *service)
  1367. {
  1368. IPAWANDBG("QMI svc:%d vers:%d ins:%d node:%d port:%d\n",
  1369. service->service, service->version, service->instance,
  1370. service->node, service->port);
  1371. if (ipa3_qmi_ctx != NULL) {
  1372. ipa3_qmi_ctx->server_sq.sq_family = AF_QIPCRTR;
  1373. ipa3_qmi_ctx->server_sq.sq_node = service->node;
  1374. ipa3_qmi_ctx->server_sq.sq_port = service->port;
  1375. }
  1376. if (!workqueues_stopped) {
  1377. queue_delayed_work(ipa_clnt_req_workqueue,
  1378. &ipa3_work_svc_arrive, 0);
  1379. }
  1380. return 0;
  1381. }
  1382. static void ipa3_q6_clnt_svc_event_notify_net_reset(struct qmi_handle *qmi)
  1383. {
  1384. if (!workqueues_stopped)
  1385. queue_delayed_work(ipa_clnt_req_workqueue,
  1386. &ipa3_work_svc_exit, 0);
  1387. }
  1388. static void ipa3_q6_clnt_svc_event_notify_svc_exit(struct qmi_handle *qmi,
  1389. struct qmi_service *svc)
  1390. {
  1391. IPAWANDBG("QMI svc:%d vers:%d ins:%d node:%d port:%d\n", svc->service,
  1392. svc->version, svc->instance, svc->node, svc->port);
  1393. if (!workqueues_stopped)
  1394. queue_delayed_work(ipa_clnt_req_workqueue,
  1395. &ipa3_work_svc_exit, 0);
  1396. }
  1397. static struct qmi_ops server_ops = {
  1398. .del_client = ipa3_a5_svc_disconnect_cb,
  1399. };
  1400. static struct qmi_ops client_ops = {
  1401. .new_server = ipa3_q6_clnt_svc_event_notify_svc_new,
  1402. .del_server = ipa3_q6_clnt_svc_event_notify_svc_exit,
  1403. .net_reset = ipa3_q6_clnt_svc_event_notify_net_reset,
  1404. };
  1405. static struct qmi_msg_handler server_handlers[] = {
  1406. {
  1407. .type = QMI_REQUEST,
  1408. .msg_id = QMI_IPA_INDICATION_REGISTER_REQ_V01,
  1409. .ei = ipa3_indication_reg_req_msg_data_v01_ei,
  1410. .decoded_size = sizeof(struct ipa_indication_reg_req_msg_v01),
  1411. .fn = ipa3_handle_indication_req,
  1412. },
  1413. {
  1414. .type = QMI_REQUEST,
  1415. .msg_id = QMI_IPA_INSTALL_FILTER_RULE_REQ_V01,
  1416. .ei = ipa3_install_fltr_rule_req_msg_data_v01_ei,
  1417. .decoded_size = sizeof(
  1418. struct ipa_install_fltr_rule_req_msg_v01),
  1419. .fn = ipa3_handle_install_filter_rule_req,
  1420. },
  1421. {
  1422. .type = QMI_REQUEST,
  1423. .msg_id = QMI_IPA_FILTER_INSTALLED_NOTIF_REQ_V01,
  1424. .ei = ipa3_fltr_installed_notif_req_msg_data_v01_ei,
  1425. .decoded_size = sizeof(
  1426. struct ipa_fltr_installed_notif_req_msg_v01),
  1427. .fn = ipa3_handle_filter_installed_notify_req,
  1428. },
  1429. {
  1430. .type = QMI_REQUEST,
  1431. .msg_id = QMI_IPA_CONFIG_REQ_V01,
  1432. .ei = ipa3_config_req_msg_data_v01_ei,
  1433. .decoded_size = sizeof(struct ipa_config_req_msg_v01),
  1434. .fn = handle_ipa_config_req,
  1435. },
  1436. {
  1437. .type = QMI_REQUEST,
  1438. .msg_id = QMI_IPA_INIT_MODEM_DRIVER_CMPLT_REQ_V01,
  1439. .ei = ipa3_init_modem_driver_cmplt_req_msg_data_v01_ei,
  1440. .decoded_size = sizeof(
  1441. struct ipa_init_modem_driver_cmplt_req_msg_v01),
  1442. .fn = ipa3_handle_modem_init_cmplt_req,
  1443. },
  1444. {
  1445. .type = QMI_REQUEST,
  1446. .msg_id = QMI_IPA_INIT_MODEM_DRIVER_CMPLT_REQ_V01,
  1447. .ei = ipa3_init_modem_driver_cmplt_req_msg_data_v01_ei,
  1448. .decoded_size = sizeof(
  1449. struct ipa_init_modem_driver_cmplt_req_msg_v01),
  1450. .fn = ipa3_handle_modem_init_cmplt_req,
  1451. },
  1452. {
  1453. .type = QMI_REQUEST,
  1454. .msg_id = QMI_IPA_MHI_ALLOC_CHANNEL_REQ_V01,
  1455. .ei = ipa_mhi_alloc_channel_req_msg_v01_ei,
  1456. .decoded_size = sizeof(
  1457. struct ipa_mhi_alloc_channel_req_msg_v01),
  1458. .fn = ipa3_handle_mhi_alloc_channel_req,
  1459. },
  1460. {
  1461. .type = QMI_REQUEST,
  1462. .msg_id = QMI_IPA_MHI_CLK_VOTE_REQ_V01,
  1463. .ei = ipa_mhi_clk_vote_req_msg_v01_ei,
  1464. .decoded_size = sizeof(struct ipa_mhi_clk_vote_req_msg_v01),
  1465. .fn = ipa3_handle_mhi_vote_req,
  1466. },
  1467. };
  1468. /* clinet_handlers are client callbacks that will be called from QMI context
  1469. * when an indication from Q6 server arrives.
  1470. * In our case, client_handlers needs handling only for QMI_INDICATION,
  1471. * since the QMI_REQUEST/ QMI_RESPONSE are handled in a blocking fashion
  1472. * at the time of sending QMI_REQUESTs.
  1473. */
  1474. static struct qmi_msg_handler client_handlers[] = {
  1475. {
  1476. .type = QMI_INDICATION,
  1477. .msg_id = QMI_IPA_DATA_USAGE_QUOTA_REACHED_IND_V01,
  1478. .ei = ipa3_data_usage_quota_reached_ind_msg_data_v01_ei,
  1479. .decoded_size = sizeof(
  1480. struct ipa_data_usage_quota_reached_ind_msg_v01),
  1481. .fn = ipa3_q6_clnt_quota_reached_ind_cb,
  1482. },
  1483. {
  1484. .type = QMI_INDICATION,
  1485. .msg_id = QMI_IPA_INSTALL_UL_FIREWALL_RULES_IND_V01,
  1486. .ei = ipa3_install_fltr_rule_req_msg_data_v01_ei,
  1487. .decoded_size = sizeof(
  1488. struct ipa_configure_ul_firewall_rules_ind_msg_v01),
  1489. .fn = ipa3_q6_clnt_install_firewall_rules_ind_cb,
  1490. },
  1491. };
  1492. static void ipa3_qmi_service_init_worker(struct work_struct *work)
  1493. {
  1494. int rc;
  1495. /* start the QMI msg cache */
  1496. ipa3_qmi_ctx = vzalloc(sizeof(*ipa3_qmi_ctx));
  1497. if (!ipa3_qmi_ctx) {
  1498. IPAWANERR("Failed to allocate ipa3_qmi_ctx\n");
  1499. return;
  1500. }
  1501. if (ipa3_is_apq()) {
  1502. /* Only start QMI-client */
  1503. IPAWANDBG("Only start IPA A7 QMI client\n");
  1504. goto qmi_client_start;
  1505. }
  1506. /* Initialize QMI-service*/
  1507. IPAWANDBG("IPA A7 QMI init OK :>>>>\n");
  1508. ipa3_qmi_ctx->modem_cfg_emb_pipe_flt =
  1509. ipa_get_modem_cfg_emb_pipe_flt();
  1510. ipa3_qmi_ctx->num_ipa_offload_connection = 0;
  1511. ipa3_svc_handle = vzalloc(sizeof(*ipa3_svc_handle));
  1512. if (!ipa3_svc_handle)
  1513. goto destroy_ipa_A7_svc_wq;
  1514. rc = qmi_handle_init(ipa3_svc_handle,
  1515. QMI_IPA_MAX_MSG_LEN,
  1516. &server_ops,
  1517. server_handlers);
  1518. if (rc < 0) {
  1519. IPAWANERR("Initializing ipa_a5 svc failed %d\n", rc);
  1520. goto destroy_qmi_handle;
  1521. }
  1522. rc = qmi_add_server(ipa3_svc_handle,
  1523. IPA_A5_SERVICE_SVC_ID,
  1524. IPA_A5_SVC_VERS,
  1525. IPA_A5_SERVICE_INS_ID);
  1526. if (rc < 0) {
  1527. IPAWANERR("Registering ipa_a5 svc failed %d\n",
  1528. rc);
  1529. goto deregister_qmi_srv;
  1530. }
  1531. qmi_client_start:
  1532. /* Initialize QMI-client */
  1533. ipa_clnt_req_workqueue = create_singlethread_workqueue("clnt_req");
  1534. if (!ipa_clnt_req_workqueue) {
  1535. IPAWANERR("Creating clnt_req workqueue failed\n");
  1536. goto deregister_qmi_srv;
  1537. }
  1538. /* Create a Local client port for QMI communication */
  1539. ipa_q6_clnt = vzalloc(sizeof(*ipa_q6_clnt));
  1540. if (!ipa_q6_clnt)
  1541. goto destroy_clnt_req_wq;
  1542. rc = qmi_handle_init(ipa_q6_clnt,
  1543. QMI_IPA_MAX_MSG_LEN,
  1544. &client_ops,
  1545. client_handlers);
  1546. if (rc < 0) {
  1547. IPAWANERR("Creating clnt handle failed\n");
  1548. goto destroy_qmi_client_handle;
  1549. }
  1550. rc = qmi_add_lookup(ipa_q6_clnt,
  1551. IPA_Q6_SERVICE_SVC_ID,
  1552. IPA_Q6_SVC_VERS,
  1553. IPA_Q6_SERVICE_INS_ID);
  1554. if (rc < 0) {
  1555. IPAWANERR("Adding Q6 Svc failed\n");
  1556. goto deregister_qmi_client;
  1557. }
  1558. /* get Q6 service and start send modem-initial to Q6 */
  1559. IPAWANDBG("wait service available\n");
  1560. return;
  1561. deregister_qmi_client:
  1562. qmi_handle_release(ipa_q6_clnt);
  1563. destroy_qmi_client_handle:
  1564. vfree(ipa_q6_clnt);
  1565. ipa_q6_clnt = NULL;
  1566. destroy_clnt_req_wq:
  1567. destroy_workqueue(ipa_clnt_req_workqueue);
  1568. ipa_clnt_req_workqueue = NULL;
  1569. deregister_qmi_srv:
  1570. if (!ipa3_is_apq())
  1571. qmi_handle_release(ipa3_svc_handle);
  1572. destroy_qmi_handle:
  1573. vfree(ipa3_qmi_ctx);
  1574. destroy_ipa_A7_svc_wq:
  1575. if (!ipa3_is_apq()) {
  1576. vfree(ipa3_svc_handle);
  1577. ipa3_svc_handle = NULL;
  1578. }
  1579. ipa3_qmi_ctx = NULL;
  1580. }
  1581. int ipa3_qmi_service_init(uint32_t wan_platform_type)
  1582. {
  1583. ipa_wan_platform = wan_platform_type;
  1584. ipa3_qmi_modem_init_fin = false;
  1585. ipa3_qmi_indication_fin = false;
  1586. ipa3_modem_init_cmplt = false;
  1587. send_qmi_init_q6 = true;
  1588. workqueues_stopped = false;
  1589. if (!ipa3_svc_handle) {
  1590. INIT_WORK(&ipa3_qmi_service_init_work,
  1591. ipa3_qmi_service_init_worker);
  1592. schedule_work(&ipa3_qmi_service_init_work);
  1593. }
  1594. return 0;
  1595. }
  1596. void ipa3_qmi_service_exit(void)
  1597. {
  1598. workqueues_stopped = true;
  1599. /* qmi-service */
  1600. if (ipa3_svc_handle != NULL) {
  1601. qmi_handle_release(ipa3_svc_handle);
  1602. vfree(ipa3_svc_handle);
  1603. ipa3_svc_handle = NULL;
  1604. }
  1605. /* qmi-client */
  1606. /* Release client handle */
  1607. if (ipa_q6_clnt != NULL) {
  1608. qmi_handle_release(ipa_q6_clnt);
  1609. vfree(ipa_q6_clnt);
  1610. ipa_q6_clnt = NULL;
  1611. if (ipa_clnt_req_workqueue) {
  1612. destroy_workqueue(ipa_clnt_req_workqueue);
  1613. ipa_clnt_req_workqueue = NULL;
  1614. }
  1615. }
  1616. /* clean the QMI msg cache */
  1617. mutex_lock(&ipa3_qmi_lock);
  1618. if (ipa3_qmi_ctx != NULL) {
  1619. vfree(ipa3_qmi_ctx);
  1620. ipa3_qmi_ctx = NULL;
  1621. }
  1622. mutex_unlock(&ipa3_qmi_lock);
  1623. ipa3_qmi_modem_init_fin = false;
  1624. ipa3_qmi_indication_fin = false;
  1625. ipa3_modem_init_cmplt = false;
  1626. send_qmi_init_q6 = true;
  1627. }
  1628. void ipa3_qmi_stop_workqueues(void)
  1629. {
  1630. IPAWANDBG("Stopping all QMI workqueues\n");
  1631. /* Stopping all workqueues so new work won't be scheduled */
  1632. workqueues_stopped = true;
  1633. /* Making sure that the current scheduled work won't be executed */
  1634. cancel_delayed_work(&ipa3_work_svc_arrive);
  1635. cancel_delayed_work(&ipa3_work_svc_exit);
  1636. }
  1637. /* voting for bus BW to ipa_rm*/
  1638. int ipa3_vote_for_bus_bw(uint32_t *bw_mbps)
  1639. {
  1640. int ret;
  1641. IPAWANDBG("Bus BW is %d\n", *bw_mbps);
  1642. if (bw_mbps == NULL) {
  1643. IPAWANERR("Bus BW is invalid\n");
  1644. return -EINVAL;
  1645. }
  1646. ret = ipa3_wwan_set_modem_perf_profile(*bw_mbps);
  1647. if (ret)
  1648. IPAWANERR("Failed to set perf profile to BW %u\n",
  1649. *bw_mbps);
  1650. else
  1651. IPAWANDBG("Succeeded to set perf profile to BW %u\n",
  1652. *bw_mbps);
  1653. return ret;
  1654. }
  1655. int ipa3_qmi_get_data_stats(struct ipa_get_data_stats_req_msg_v01 *req,
  1656. struct ipa_get_data_stats_resp_msg_v01 *resp)
  1657. {
  1658. struct ipa_msg_desc req_desc, resp_desc;
  1659. int rc;
  1660. req_desc.max_msg_len = QMI_IPA_GET_DATA_STATS_REQ_MAX_MSG_LEN_V01;
  1661. req_desc.msg_id = QMI_IPA_GET_DATA_STATS_REQ_V01;
  1662. req_desc.ei_array = ipa3_get_data_stats_req_msg_data_v01_ei;
  1663. resp_desc.max_msg_len = QMI_IPA_GET_DATA_STATS_RESP_MAX_MSG_LEN_V01;
  1664. resp_desc.msg_id = QMI_IPA_GET_DATA_STATS_RESP_V01;
  1665. resp_desc.ei_array = ipa3_get_data_stats_resp_msg_data_v01_ei;
  1666. IPAWANDBG_LOW("Sending QMI_IPA_GET_DATA_STATS_REQ_V01\n");
  1667. if (unlikely(!ipa_q6_clnt))
  1668. return -ETIMEDOUT;
  1669. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  1670. &req_desc, req,
  1671. &resp_desc, resp,
  1672. QMI_SEND_STATS_REQ_TIMEOUT_MS);
  1673. if (rc < 0) {
  1674. IPAWANERR("QMI send Req %d failed, rc= %d\n",
  1675. QMI_IPA_GET_DATA_STATS_REQ_V01,
  1676. rc);
  1677. return rc;
  1678. }
  1679. IPAWANDBG_LOW("QMI_IPA_GET_DATA_STATS_RESP_V01 received\n");
  1680. return ipa3_check_qmi_response(rc,
  1681. QMI_IPA_GET_DATA_STATS_REQ_V01, resp->resp.result,
  1682. resp->resp.error, "ipa_get_data_stats_resp_msg_v01");
  1683. }
  1684. int ipa3_qmi_get_network_stats(struct ipa_get_apn_data_stats_req_msg_v01 *req,
  1685. struct ipa_get_apn_data_stats_resp_msg_v01 *resp)
  1686. {
  1687. struct ipa_msg_desc req_desc, resp_desc;
  1688. int rc;
  1689. req_desc.max_msg_len = QMI_IPA_GET_APN_DATA_STATS_REQ_MAX_MSG_LEN_V01;
  1690. req_desc.msg_id = QMI_IPA_GET_APN_DATA_STATS_REQ_V01;
  1691. req_desc.ei_array = ipa3_get_apn_data_stats_req_msg_data_v01_ei;
  1692. resp_desc.max_msg_len = QMI_IPA_GET_APN_DATA_STATS_RESP_MAX_MSG_LEN_V01;
  1693. resp_desc.msg_id = QMI_IPA_GET_APN_DATA_STATS_RESP_V01;
  1694. resp_desc.ei_array = ipa3_get_apn_data_stats_resp_msg_data_v01_ei;
  1695. IPAWANDBG_LOW("Sending QMI_IPA_GET_APN_DATA_STATS_REQ_V01\n");
  1696. if (unlikely(!ipa_q6_clnt))
  1697. return -ETIMEDOUT;
  1698. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  1699. &req_desc, req,
  1700. &resp_desc, resp,
  1701. QMI_SEND_STATS_REQ_TIMEOUT_MS);
  1702. if (rc < 0) {
  1703. IPAWANERR("QMI send Req %d failed, rc= %d\n",
  1704. QMI_IPA_GET_APN_DATA_STATS_REQ_V01,
  1705. rc);
  1706. return rc;
  1707. }
  1708. IPAWANDBG_LOW("QMI_IPA_GET_APN_DATA_STATS_RESP_V01 received\n");
  1709. return ipa3_check_qmi_response(rc,
  1710. QMI_IPA_GET_APN_DATA_STATS_REQ_V01, resp->resp.result,
  1711. resp->resp.error, "ipa_get_apn_data_stats_req_msg_v01");
  1712. }
  1713. int ipa3_qmi_set_data_quota(struct ipa_set_data_usage_quota_req_msg_v01 *req)
  1714. {
  1715. struct ipa_set_data_usage_quota_resp_msg_v01 resp;
  1716. struct ipa_msg_desc req_desc, resp_desc;
  1717. int rc;
  1718. memset(&resp, 0, sizeof(struct ipa_set_data_usage_quota_resp_msg_v01));
  1719. req_desc.max_msg_len = QMI_IPA_SET_DATA_USAGE_QUOTA_REQ_MAX_MSG_LEN_V01;
  1720. req_desc.msg_id = QMI_IPA_SET_DATA_USAGE_QUOTA_REQ_V01;
  1721. req_desc.ei_array = ipa3_set_data_usage_quota_req_msg_data_v01_ei;
  1722. resp_desc.max_msg_len =
  1723. QMI_IPA_SET_DATA_USAGE_QUOTA_RESP_MAX_MSG_LEN_V01;
  1724. resp_desc.msg_id = QMI_IPA_SET_DATA_USAGE_QUOTA_RESP_V01;
  1725. resp_desc.ei_array = ipa3_set_data_usage_quota_resp_msg_data_v01_ei;
  1726. IPAWANDBG_LOW("Sending QMI_IPA_SET_DATA_USAGE_QUOTA_REQ_V01\n");
  1727. if (unlikely(!ipa_q6_clnt))
  1728. return -ETIMEDOUT;
  1729. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  1730. &req_desc, req,
  1731. &resp_desc, &resp,
  1732. QMI_SEND_STATS_REQ_TIMEOUT_MS);
  1733. if (rc < 0) {
  1734. IPAWANERR("QMI send Req %d failed, rc= %d\n",
  1735. QMI_IPA_SET_DATA_USAGE_QUOTA_REQ_V01,
  1736. rc);
  1737. return rc;
  1738. }
  1739. IPAWANDBG_LOW("QMI_IPA_SET_DATA_USAGE_QUOTA_RESP_V01 received\n");
  1740. return ipa3_check_qmi_response(rc,
  1741. QMI_IPA_SET_DATA_USAGE_QUOTA_REQ_V01, resp.resp.result,
  1742. resp.resp.error, "ipa_set_data_usage_quota_req_msg_v01");
  1743. }
  1744. int ipa3_qmi_set_aggr_info(enum ipa_aggr_enum_type_v01 aggr_enum_type)
  1745. {
  1746. struct ipa_mhi_prime_aggr_info_resp_msg_v01 resp;
  1747. struct ipa_msg_desc req_desc, resp_desc;
  1748. int rc;
  1749. IPAWANDBG("sending aggr_info_request\n");
  1750. /* replace to right qmap format */
  1751. aggr_req.aggr_info[1].aggr_type = aggr_enum_type;
  1752. aggr_req.aggr_info[2].aggr_type = aggr_enum_type;
  1753. aggr_req.aggr_info[3].aggr_type = aggr_enum_type;
  1754. aggr_req.aggr_info[4].aggr_type = aggr_enum_type;
  1755. memset(&resp, 0, sizeof(struct ipa_mhi_prime_aggr_info_resp_msg_v01));
  1756. req_desc.max_msg_len = IPA_MHI_PRIME_AGGR_INFO_REQ_MSG_V01_MAX_MSG_LEN;
  1757. req_desc.msg_id = QMI_IPA_MHI_PRIME_AGGR_INFO_REQ_V01;
  1758. req_desc.ei_array = ipa_mhi_prime_aggr_info_req_msg_v01_ei;
  1759. resp_desc.max_msg_len =
  1760. IPA_MHI_PRIME_AGGR_INFO_RESP_MSG_V01_MAX_MSG_LEN;
  1761. resp_desc.msg_id = QMI_IPA_MHI_PRIME_AGGR_INFO_RESP_V01;
  1762. resp_desc.ei_array = ipa_mhi_prime_aggr_info_resp_msg_v01_ei;
  1763. IPAWANDBG("Sending QMI_IPA_MHI_PRIME_AGGR_INFO_REQ_V01(%d)\n",
  1764. aggr_enum_type);
  1765. if (unlikely(!ipa_q6_clnt)) {
  1766. IPAWANERR(" ipa_q6_clnt not initialized\n");
  1767. return -ETIMEDOUT;
  1768. }
  1769. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  1770. &req_desc, &aggr_req,
  1771. &resp_desc, &resp,
  1772. QMI_SEND_STATS_REQ_TIMEOUT_MS);
  1773. if (rc < 0) {
  1774. IPAWANERR("QMI send Req %d failed, rc= %d\n",
  1775. QMI_IPA_SET_DATA_USAGE_QUOTA_REQ_V01,
  1776. rc);
  1777. return rc;
  1778. }
  1779. IPAWANDBG_LOW("QMI_IPA_MHI_PRIME_AGGR_INFO_RESP_V01 received\n");
  1780. return ipa3_check_qmi_response(rc,
  1781. QMI_IPA_SET_DATA_USAGE_QUOTA_REQ_V01, resp.resp.result,
  1782. resp.resp.error, "ipa_mhi_prime_aggr_info_req_msg_v01");
  1783. }
  1784. int ipa3_qmi_stop_data_qouta(void)
  1785. {
  1786. struct ipa_stop_data_usage_quota_req_msg_v01 req;
  1787. struct ipa_stop_data_usage_quota_resp_msg_v01 resp;
  1788. struct ipa_msg_desc req_desc, resp_desc;
  1789. int rc;
  1790. memset(&req, 0, sizeof(struct ipa_stop_data_usage_quota_req_msg_v01));
  1791. memset(&resp, 0, sizeof(struct ipa_stop_data_usage_quota_resp_msg_v01));
  1792. req_desc.max_msg_len =
  1793. QMI_IPA_STOP_DATA_USAGE_QUOTA_REQ_MAX_MSG_LEN_V01;
  1794. req_desc.msg_id = QMI_IPA_STOP_DATA_USAGE_QUOTA_REQ_V01;
  1795. req_desc.ei_array = ipa3_stop_data_usage_quota_req_msg_data_v01_ei;
  1796. resp_desc.max_msg_len =
  1797. QMI_IPA_STOP_DATA_USAGE_QUOTA_RESP_MAX_MSG_LEN_V01;
  1798. resp_desc.msg_id = QMI_IPA_STOP_DATA_USAGE_QUOTA_RESP_V01;
  1799. resp_desc.ei_array = ipa3_stop_data_usage_quota_resp_msg_data_v01_ei;
  1800. IPAWANDBG_LOW("Sending QMI_IPA_STOP_DATA_USAGE_QUOTA_REQ_V01\n");
  1801. if (unlikely(!ipa_q6_clnt))
  1802. return -ETIMEDOUT;
  1803. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  1804. &req_desc, &req,
  1805. &resp_desc, &resp,
  1806. QMI_SEND_STATS_REQ_TIMEOUT_MS);
  1807. if (rc < 0) {
  1808. IPAWANERR("QMI send Req %d failed, rc= %d\n",
  1809. QMI_IPA_STOP_DATA_USAGE_QUOTA_REQ_V01,
  1810. rc);
  1811. return rc;
  1812. }
  1813. IPAWANDBG_LOW("QMI_IPA_STOP_DATA_USAGE_QUOTA_RESP_V01 received\n");
  1814. return ipa3_check_qmi_response(rc,
  1815. QMI_IPA_STOP_DATA_USAGE_QUOTA_REQ_V01, resp.resp.result,
  1816. resp.resp.error, "ipa_stop_data_usage_quota_req_msg_v01");
  1817. }
  1818. int ipa3_qmi_enable_per_client_stats(
  1819. struct ipa_enable_per_client_stats_req_msg_v01 *req,
  1820. struct ipa_enable_per_client_stats_resp_msg_v01 *resp)
  1821. {
  1822. struct ipa_msg_desc req_desc, resp_desc;
  1823. int rc = 0;
  1824. req_desc.max_msg_len =
  1825. QMI_IPA_ENABLE_PER_CLIENT_STATS_REQ_MAX_MSG_LEN_V01;
  1826. req_desc.msg_id =
  1827. QMI_IPA_ENABLE_PER_CLIENT_STATS_REQ_V01;
  1828. req_desc.ei_array =
  1829. ipa3_enable_per_client_stats_req_msg_data_v01_ei;
  1830. resp_desc.max_msg_len =
  1831. QMI_IPA_ENABLE_PER_CLIENT_STATS_RESP_MAX_MSG_LEN_V01;
  1832. resp_desc.msg_id =
  1833. QMI_IPA_ENABLE_PER_CLIENT_STATS_RESP_V01;
  1834. resp_desc.ei_array =
  1835. ipa3_enable_per_client_stats_resp_msg_data_v01_ei;
  1836. IPAWANDBG("Sending QMI_IPA_ENABLE_PER_CLIENT_STATS_REQ_V01\n");
  1837. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  1838. &req_desc, req,
  1839. &resp_desc, resp,
  1840. QMI_SEND_STATS_REQ_TIMEOUT_MS);
  1841. if (rc < 0) {
  1842. IPAWANERR("send Req %d failed, rc= %d\n",
  1843. QMI_IPA_ENABLE_PER_CLIENT_STATS_REQ_V01,
  1844. rc);
  1845. return rc;
  1846. }
  1847. IPAWANDBG("QMI_IPA_ENABLE_PER_CLIENT_STATS_RESP_V01 received\n");
  1848. return ipa3_check_qmi_response(rc,
  1849. QMI_IPA_ENABLE_PER_CLIENT_STATS_REQ_V01, resp->resp.result,
  1850. resp->resp.error, "ipa3_qmi_enable_per_client_stats");
  1851. }
  1852. int ipa3_qmi_get_per_client_packet_stats(
  1853. struct ipa_get_stats_per_client_req_msg_v01 *req,
  1854. struct ipa_get_stats_per_client_resp_msg_v01 *resp)
  1855. {
  1856. struct ipa_msg_desc req_desc, resp_desc;
  1857. int rc;
  1858. req_desc.max_msg_len = QMI_IPA_GET_STATS_PER_CLIENT_REQ_MAX_MSG_LEN_V01;
  1859. req_desc.msg_id = QMI_IPA_GET_STATS_PER_CLIENT_REQ_V01;
  1860. req_desc.ei_array = ipa3_get_stats_per_client_req_msg_data_v01_ei;
  1861. resp_desc.max_msg_len =
  1862. QMI_IPA_GET_STATS_PER_CLIENT_RESP_MAX_MSG_LEN_V01;
  1863. resp_desc.msg_id = QMI_IPA_GET_STATS_PER_CLIENT_RESP_V01;
  1864. resp_desc.ei_array = ipa3_get_stats_per_client_resp_msg_data_v01_ei;
  1865. IPAWANDBG("Sending QMI_IPA_GET_STATS_PER_CLIENT_REQ_V01\n");
  1866. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  1867. &req_desc, req,
  1868. &resp_desc, resp,
  1869. QMI_SEND_STATS_REQ_TIMEOUT_MS);
  1870. if (rc < 0) {
  1871. IPAWANERR("send Req %d failed, rc= %d\n",
  1872. QMI_IPA_GET_STATS_PER_CLIENT_REQ_V01,
  1873. rc);
  1874. return rc;
  1875. }
  1876. IPAWANDBG("QMI_IPA_GET_STATS_PER_CLIENT_RESP_V01 received\n");
  1877. return ipa3_check_qmi_response(rc,
  1878. QMI_IPA_GET_STATS_PER_CLIENT_REQ_V01, resp->resp.result,
  1879. resp->resp.error,
  1880. "struct ipa_get_stats_per_client_req_msg_v01");
  1881. }
  1882. int ipa3_qmi_send_mhi_ready_indication(
  1883. struct ipa_mhi_ready_indication_msg_v01 *req)
  1884. {
  1885. IPAWANDBG("Sending QMI_IPA_MHI_READY_IND_V01\n");
  1886. if (unlikely(!ipa3_svc_handle))
  1887. return -ETIMEDOUT;
  1888. return qmi_send_indication(ipa3_svc_handle,
  1889. &ipa3_qmi_ctx->client_sq,
  1890. QMI_IPA_MHI_READY_IND_V01,
  1891. IPA_MHI_READY_INDICATION_MSG_V01_MAX_MSG_LEN,
  1892. ipa_mhi_ready_indication_msg_v01_ei,
  1893. req);
  1894. }
  1895. int ipa3_qmi_send_mhi_cleanup_request(struct ipa_mhi_cleanup_req_msg_v01 *req)
  1896. {
  1897. struct ipa_msg_desc req_desc, resp_desc;
  1898. struct ipa_mhi_cleanup_resp_msg_v01 resp;
  1899. int rc;
  1900. memset(&resp, 0, sizeof(resp));
  1901. IPAWANDBG("Sending QMI_IPA_MHI_CLEANUP_REQ_V01\n");
  1902. if (unlikely(!ipa_q6_clnt))
  1903. return -ETIMEDOUT;
  1904. req_desc.max_msg_len = IPA_MHI_CLK_VOTE_REQ_MSG_V01_MAX_MSG_LEN;
  1905. req_desc.msg_id = QMI_IPA_MHI_CLEANUP_REQ_V01;
  1906. req_desc.ei_array = ipa_mhi_cleanup_req_msg_v01_ei;
  1907. resp_desc.max_msg_len = IPA_MHI_CLK_VOTE_RESP_MSG_V01_MAX_MSG_LEN;
  1908. resp_desc.msg_id = QMI_IPA_MHI_CLEANUP_RESP_V01;
  1909. resp_desc.ei_array = ipa_mhi_cleanup_resp_msg_v01_ei;
  1910. rc = ipa3_qmi_send_req_wait(ipa_q6_clnt,
  1911. &req_desc, req,
  1912. &resp_desc, &resp,
  1913. QMI_MHI_SEND_REQ_TIMEOUT_MS);
  1914. IPAWANDBG("QMI_IPA_MHI_CLEANUP_RESP_V01 received\n");
  1915. return ipa3_check_qmi_response(rc,
  1916. QMI_IPA_MHI_CLEANUP_REQ_V01, resp.resp.result,
  1917. resp.resp.error, "ipa_mhi_cleanup_req_msg");
  1918. }
  1919. int ipa3_qmi_send_rsc_pipe_indication(
  1920. struct ipa_endp_desc_indication_msg_v01 *req)
  1921. {
  1922. IPAWANDBG("Sending QMI_IPA_ENDP_DESC_INDICATION_V01\n");
  1923. if (unlikely(!ipa3_svc_handle))
  1924. return -ETIMEDOUT;
  1925. return qmi_send_indication(ipa3_svc_handle,
  1926. &ipa3_qmi_ctx->client_sq,
  1927. QMI_IPA_ENDP_DESC_INDICATION_V01,
  1928. IPA_ENDP_DESC_INDICATION_MSG_V01_MAX_MSG_LEN,
  1929. ipa_endp_desc_indication_msg_v01_ei,
  1930. req);
  1931. }
  1932. void ipa3_qmi_init(void)
  1933. {
  1934. mutex_init(&ipa3_qmi_lock);
  1935. }
  1936. void ipa3_qmi_cleanup(void)
  1937. {
  1938. mutex_destroy(&ipa3_qmi_lock);
  1939. }