ipa_qmi_service.c 63 KB

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