dfc_qmi.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583
  1. /*
  2. * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <net/pkt_sched.h>
  14. #include "rmnet_qmi.h"
  15. #include "qmi_rmnet.h"
  16. #include "dfc_defs.h"
  17. #define CREATE_TRACE_POINTS
  18. #include "dfc.h"
  19. struct dfc_qmap_header {
  20. u8 pad_len:6;
  21. u8 reserved_bit:1;
  22. u8 cd_bit:1;
  23. u8 mux_id;
  24. __be16 pkt_len;
  25. } __aligned(1);
  26. struct dfc_ack_cmd {
  27. struct dfc_qmap_header header;
  28. u8 command_name;
  29. u8 cmd_type:2;
  30. u8 reserved:6;
  31. u16 reserved2;
  32. u32 transaction_id;
  33. u8 ver:2;
  34. u8 reserved3:6;
  35. u8 type:2;
  36. u8 reserved4:6;
  37. u16 dfc_seq;
  38. u8 reserved5[3];
  39. u8 bearer_id;
  40. } __aligned(1);
  41. static void dfc_svc_init(struct work_struct *work);
  42. extern int dfc_ps_ext;
  43. /* **************************************************** */
  44. #define DFC_SERVICE_ID_V01 0x4E
  45. #define DFC_SERVICE_VERS_V01 0x01
  46. #define DFC_TIMEOUT_JF msecs_to_jiffies(1000)
  47. #define QMI_DFC_BIND_CLIENT_REQ_V01 0x0020
  48. #define QMI_DFC_BIND_CLIENT_RESP_V01 0x0020
  49. #define QMI_DFC_BIND_CLIENT_REQ_V01_MAX_MSG_LEN 11
  50. #define QMI_DFC_BIND_CLIENT_RESP_V01_MAX_MSG_LEN 7
  51. #define QMI_DFC_INDICATION_REGISTER_REQ_V01 0x0001
  52. #define QMI_DFC_INDICATION_REGISTER_RESP_V01 0x0001
  53. #define QMI_DFC_INDICATION_REGISTER_REQ_V01_MAX_MSG_LEN 8
  54. #define QMI_DFC_INDICATION_REGISTER_RESP_V01_MAX_MSG_LEN 7
  55. #define QMI_DFC_FLOW_STATUS_IND_V01 0x0022
  56. #define QMI_DFC_TX_LINK_STATUS_IND_V01 0x0024
  57. #define QMI_DFC_GET_FLOW_STATUS_REQ_V01 0x0023
  58. #define QMI_DFC_GET_FLOW_STATUS_RESP_V01 0x0023
  59. #define QMI_DFC_GET_FLOW_STATUS_REQ_V01_MAX_MSG_LEN 20
  60. #define QMI_DFC_GET_FLOW_STATUS_RESP_V01_MAX_MSG_LEN 543
  61. struct dfc_bind_client_req_msg_v01 {
  62. u8 ep_id_valid;
  63. struct data_ep_id_type_v01 ep_id;
  64. };
  65. struct dfc_bind_client_resp_msg_v01 {
  66. struct qmi_response_type_v01 resp;
  67. };
  68. struct dfc_indication_register_req_msg_v01 {
  69. u8 report_flow_status_valid;
  70. u8 report_flow_status;
  71. u8 report_tx_link_status_valid;
  72. u8 report_tx_link_status;
  73. };
  74. struct dfc_indication_register_resp_msg_v01 {
  75. struct qmi_response_type_v01 resp;
  76. };
  77. static struct qmi_elem_info dfc_qos_id_type_v01_ei[] = {
  78. {
  79. .data_type = QMI_UNSIGNED_4_BYTE,
  80. .elem_len = 1,
  81. .elem_size = sizeof(u32),
  82. .array_type = NO_ARRAY,
  83. .tlv_type = QMI_COMMON_TLV_TYPE,
  84. .offset = offsetof(struct dfc_qos_id_type_v01,
  85. qos_id),
  86. .ei_array = NULL,
  87. },
  88. {
  89. .data_type = QMI_SIGNED_4_BYTE_ENUM,
  90. .elem_len = 1,
  91. .elem_size = sizeof(enum dfc_ip_type_enum_v01),
  92. .array_type = NO_ARRAY,
  93. .tlv_type = QMI_COMMON_TLV_TYPE,
  94. .offset = offsetof(struct dfc_qos_id_type_v01,
  95. ip_type),
  96. .ei_array = NULL,
  97. },
  98. {
  99. .data_type = QMI_EOTI,
  100. .array_type = NO_ARRAY,
  101. .tlv_type = QMI_COMMON_TLV_TYPE,
  102. },
  103. };
  104. static struct qmi_elem_info dfc_flow_status_info_type_v01_ei[] = {
  105. {
  106. .data_type = QMI_UNSIGNED_1_BYTE,
  107. .elem_len = 1,
  108. .elem_size = sizeof(u8),
  109. .array_type = NO_ARRAY,
  110. .tlv_type = QMI_COMMON_TLV_TYPE,
  111. .offset = offsetof(struct
  112. dfc_flow_status_info_type_v01,
  113. subs_id),
  114. .ei_array = NULL,
  115. },
  116. {
  117. .data_type = QMI_UNSIGNED_1_BYTE,
  118. .elem_len = 1,
  119. .elem_size = sizeof(u8),
  120. .array_type = NO_ARRAY,
  121. .tlv_type = QMI_COMMON_TLV_TYPE,
  122. .offset = offsetof(struct
  123. dfc_flow_status_info_type_v01,
  124. mux_id),
  125. .ei_array = NULL,
  126. },
  127. {
  128. .data_type = QMI_UNSIGNED_1_BYTE,
  129. .elem_len = 1,
  130. .elem_size = sizeof(u8),
  131. .array_type = NO_ARRAY,
  132. .tlv_type = QMI_COMMON_TLV_TYPE,
  133. .offset = offsetof(struct
  134. dfc_flow_status_info_type_v01,
  135. bearer_id),
  136. .ei_array = NULL,
  137. },
  138. {
  139. .data_type = QMI_UNSIGNED_4_BYTE,
  140. .elem_len = 1,
  141. .elem_size = sizeof(u32),
  142. .array_type = NO_ARRAY,
  143. .tlv_type = QMI_COMMON_TLV_TYPE,
  144. .offset = offsetof(struct
  145. dfc_flow_status_info_type_v01,
  146. num_bytes),
  147. .ei_array = NULL,
  148. },
  149. {
  150. .data_type = QMI_UNSIGNED_2_BYTE,
  151. .elem_len = 1,
  152. .elem_size = sizeof(u16),
  153. .array_type = NO_ARRAY,
  154. .tlv_type = QMI_COMMON_TLV_TYPE,
  155. .offset = offsetof(struct
  156. dfc_flow_status_info_type_v01,
  157. seq_num),
  158. .ei_array = NULL,
  159. },
  160. {
  161. .data_type = QMI_DATA_LEN,
  162. .elem_len = 1,
  163. .elem_size = sizeof(u8),
  164. .array_type = NO_ARRAY,
  165. .tlv_type = QMI_COMMON_TLV_TYPE,
  166. .offset = offsetof(struct
  167. dfc_flow_status_info_type_v01,
  168. qos_ids_len),
  169. .ei_array = NULL,
  170. },
  171. {
  172. .data_type = QMI_STRUCT,
  173. .elem_len = DFC_MAX_QOS_ID_V01,
  174. .elem_size = sizeof(struct dfc_qos_id_type_v01),
  175. .array_type = VAR_LEN_ARRAY,
  176. .tlv_type = 0x10,
  177. .offset = offsetof(struct
  178. dfc_flow_status_info_type_v01,
  179. qos_ids),
  180. .ei_array = dfc_qos_id_type_v01_ei,
  181. },
  182. {
  183. .data_type = QMI_EOTI,
  184. .array_type = NO_ARRAY,
  185. .tlv_type = QMI_COMMON_TLV_TYPE,
  186. },
  187. };
  188. static struct qmi_elem_info dfc_ancillary_info_type_v01_ei[] = {
  189. {
  190. .data_type = QMI_UNSIGNED_1_BYTE,
  191. .elem_len = 1,
  192. .elem_size = sizeof(u8),
  193. .array_type = NO_ARRAY,
  194. .tlv_type = QMI_COMMON_TLV_TYPE,
  195. .offset = offsetof(struct
  196. dfc_ancillary_info_type_v01,
  197. subs_id),
  198. .ei_array = NULL,
  199. },
  200. {
  201. .data_type = QMI_UNSIGNED_1_BYTE,
  202. .elem_len = 1,
  203. .elem_size = sizeof(u8),
  204. .array_type = NO_ARRAY,
  205. .tlv_type = QMI_COMMON_TLV_TYPE,
  206. .offset = offsetof(struct
  207. dfc_ancillary_info_type_v01,
  208. mux_id),
  209. .ei_array = NULL,
  210. },
  211. {
  212. .data_type = QMI_UNSIGNED_1_BYTE,
  213. .elem_len = 1,
  214. .elem_size = sizeof(u8),
  215. .array_type = NO_ARRAY,
  216. .tlv_type = QMI_COMMON_TLV_TYPE,
  217. .offset = offsetof(struct
  218. dfc_ancillary_info_type_v01,
  219. bearer_id),
  220. .ei_array = NULL,
  221. },
  222. {
  223. .data_type = QMI_UNSIGNED_4_BYTE,
  224. .elem_len = 1,
  225. .elem_size = sizeof(u32),
  226. .array_type = NO_ARRAY,
  227. .tlv_type = QMI_COMMON_TLV_TYPE,
  228. .offset = offsetof(struct
  229. dfc_ancillary_info_type_v01,
  230. reserved),
  231. .ei_array = NULL,
  232. },
  233. {
  234. .data_type = QMI_EOTI,
  235. .array_type = NO_ARRAY,
  236. .tlv_type = QMI_COMMON_TLV_TYPE,
  237. },
  238. };
  239. struct dfc_get_flow_status_req_msg_v01 {
  240. u8 bearer_id_list_valid;
  241. u8 bearer_id_list_len;
  242. u8 bearer_id_list[DFC_MAX_BEARERS_V01];
  243. };
  244. struct dfc_get_flow_status_resp_msg_v01 {
  245. struct qmi_response_type_v01 resp;
  246. u8 flow_status_valid;
  247. u8 flow_status_len;
  248. struct dfc_flow_status_info_type_v01 flow_status[DFC_MAX_BEARERS_V01];
  249. };
  250. struct dfc_svc_ind {
  251. struct list_head list;
  252. u16 msg_id;
  253. union {
  254. struct dfc_flow_status_ind_msg_v01 dfc_info;
  255. struct dfc_tx_link_status_ind_msg_v01 tx_status;
  256. } d;
  257. };
  258. static struct qmi_elem_info dfc_bind_client_req_msg_v01_ei[] = {
  259. {
  260. .data_type = QMI_OPT_FLAG,
  261. .elem_len = 1,
  262. .elem_size = sizeof(u8),
  263. .array_type = NO_ARRAY,
  264. .tlv_type = 0x10,
  265. .offset = offsetof(struct dfc_bind_client_req_msg_v01,
  266. ep_id_valid),
  267. .ei_array = NULL,
  268. },
  269. {
  270. .data_type = QMI_STRUCT,
  271. .elem_len = 1,
  272. .elem_size = sizeof(struct data_ep_id_type_v01),
  273. .array_type = NO_ARRAY,
  274. .tlv_type = 0x10,
  275. .offset = offsetof(struct dfc_bind_client_req_msg_v01,
  276. ep_id),
  277. .ei_array = data_ep_id_type_v01_ei,
  278. },
  279. {
  280. .data_type = QMI_EOTI,
  281. .array_type = NO_ARRAY,
  282. .tlv_type = QMI_COMMON_TLV_TYPE,
  283. },
  284. };
  285. static struct qmi_elem_info dfc_bind_client_resp_msg_v01_ei[] = {
  286. {
  287. .data_type = QMI_STRUCT,
  288. .elem_len = 1,
  289. .elem_size = sizeof(struct qmi_response_type_v01),
  290. .array_type = NO_ARRAY,
  291. .tlv_type = 0x02,
  292. .offset = offsetof(struct dfc_bind_client_resp_msg_v01,
  293. resp),
  294. .ei_array = qmi_response_type_v01_ei,
  295. },
  296. {
  297. .data_type = QMI_EOTI,
  298. .array_type = NO_ARRAY,
  299. .tlv_type = QMI_COMMON_TLV_TYPE,
  300. },
  301. };
  302. static struct qmi_elem_info dfc_indication_register_req_msg_v01_ei[] = {
  303. {
  304. .data_type = QMI_OPT_FLAG,
  305. .elem_len = 1,
  306. .elem_size = sizeof(u8),
  307. .array_type = NO_ARRAY,
  308. .tlv_type = 0x10,
  309. .offset = offsetof(struct
  310. dfc_indication_register_req_msg_v01,
  311. report_flow_status_valid),
  312. .ei_array = NULL,
  313. },
  314. {
  315. .data_type = QMI_UNSIGNED_1_BYTE,
  316. .elem_len = 1,
  317. .elem_size = sizeof(u8),
  318. .array_type = NO_ARRAY,
  319. .tlv_type = 0x10,
  320. .offset = offsetof(struct
  321. dfc_indication_register_req_msg_v01,
  322. report_flow_status),
  323. .ei_array = NULL,
  324. },
  325. {
  326. .data_type = QMI_OPT_FLAG,
  327. .elem_len = 1,
  328. .elem_size = sizeof(u8),
  329. .array_type = NO_ARRAY,
  330. .tlv_type = 0x11,
  331. .offset = offsetof(struct
  332. dfc_indication_register_req_msg_v01,
  333. report_tx_link_status_valid),
  334. .ei_array = NULL,
  335. },
  336. {
  337. .data_type = QMI_UNSIGNED_1_BYTE,
  338. .elem_len = 1,
  339. .elem_size = sizeof(u8),
  340. .array_type = NO_ARRAY,
  341. .tlv_type = 0x11,
  342. .offset = offsetof(struct
  343. dfc_indication_register_req_msg_v01,
  344. report_tx_link_status),
  345. .ei_array = NULL,
  346. },
  347. {
  348. .data_type = QMI_EOTI,
  349. .array_type = NO_ARRAY,
  350. .tlv_type = QMI_COMMON_TLV_TYPE,
  351. },
  352. };
  353. static struct qmi_elem_info dfc_indication_register_resp_msg_v01_ei[] = {
  354. {
  355. .data_type = QMI_STRUCT,
  356. .elem_len = 1,
  357. .elem_size = sizeof(struct qmi_response_type_v01),
  358. .array_type = NO_ARRAY,
  359. .tlv_type = 0x02,
  360. .offset = offsetof(struct
  361. dfc_indication_register_resp_msg_v01,
  362. resp),
  363. .ei_array = qmi_response_type_v01_ei,
  364. },
  365. {
  366. .data_type = QMI_EOTI,
  367. .array_type = NO_ARRAY,
  368. .tlv_type = QMI_COMMON_TLV_TYPE,
  369. },
  370. };
  371. static struct qmi_elem_info dfc_flow_status_ind_v01_ei[] = {
  372. {
  373. .data_type = QMI_OPT_FLAG,
  374. .elem_len = 1,
  375. .elem_size = sizeof(u8),
  376. .array_type = NO_ARRAY,
  377. .tlv_type = 0x10,
  378. .offset = offsetof(struct
  379. dfc_flow_status_ind_msg_v01,
  380. flow_status_valid),
  381. .ei_array = NULL,
  382. },
  383. {
  384. .data_type = QMI_DATA_LEN,
  385. .elem_len = 1,
  386. .elem_size = sizeof(u8),
  387. .array_type = NO_ARRAY,
  388. .tlv_type = 0x10,
  389. .offset = offsetof(struct
  390. dfc_flow_status_ind_msg_v01,
  391. flow_status_len),
  392. .ei_array = NULL,
  393. },
  394. {
  395. .data_type = QMI_STRUCT,
  396. .elem_len = DFC_MAX_BEARERS_V01,
  397. .elem_size = sizeof(struct
  398. dfc_flow_status_info_type_v01),
  399. .array_type = VAR_LEN_ARRAY,
  400. .tlv_type = 0x10,
  401. .offset = offsetof(struct
  402. dfc_flow_status_ind_msg_v01,
  403. flow_status),
  404. .ei_array = dfc_flow_status_info_type_v01_ei,
  405. },
  406. {
  407. .data_type = QMI_OPT_FLAG,
  408. .elem_len = 1,
  409. .elem_size = sizeof(u8),
  410. .array_type = NO_ARRAY,
  411. .tlv_type = 0x11,
  412. .offset = offsetof(struct
  413. dfc_flow_status_ind_msg_v01,
  414. eod_ack_reqd_valid),
  415. .ei_array = NULL,
  416. },
  417. {
  418. .data_type = QMI_UNSIGNED_1_BYTE,
  419. .elem_len = 1,
  420. .elem_size = sizeof(u8),
  421. .array_type = NO_ARRAY,
  422. .tlv_type = 0x11,
  423. .offset = offsetof(struct
  424. dfc_flow_status_ind_msg_v01,
  425. eod_ack_reqd),
  426. .ei_array = NULL,
  427. },
  428. {
  429. .data_type = QMI_OPT_FLAG,
  430. .elem_len = 1,
  431. .elem_size = sizeof(u8),
  432. .array_type = NO_ARRAY,
  433. .tlv_type = 0x12,
  434. .offset = offsetof(struct
  435. dfc_flow_status_ind_msg_v01,
  436. ancillary_info_valid),
  437. .ei_array = NULL,
  438. },
  439. {
  440. .data_type = QMI_DATA_LEN,
  441. .elem_len = 1,
  442. .elem_size = sizeof(u8),
  443. .array_type = NO_ARRAY,
  444. .tlv_type = 0x12,
  445. .offset = offsetof(struct
  446. dfc_flow_status_ind_msg_v01,
  447. ancillary_info_len),
  448. .ei_array = NULL,
  449. },
  450. {
  451. .data_type = QMI_STRUCT,
  452. .elem_len = DFC_MAX_BEARERS_V01,
  453. .elem_size = sizeof(struct
  454. dfc_ancillary_info_type_v01),
  455. .array_type = VAR_LEN_ARRAY,
  456. .tlv_type = 0x12,
  457. .offset = offsetof(struct
  458. dfc_flow_status_ind_msg_v01,
  459. ancillary_info),
  460. .ei_array = dfc_ancillary_info_type_v01_ei,
  461. },
  462. {
  463. .data_type = QMI_EOTI,
  464. .array_type = NO_ARRAY,
  465. .tlv_type = QMI_COMMON_TLV_TYPE,
  466. },
  467. };
  468. static struct qmi_elem_info dfc_get_flow_status_req_msg_v01_ei[] = {
  469. {
  470. .data_type = QMI_OPT_FLAG,
  471. .elem_len = 1,
  472. .elem_size = sizeof(u8),
  473. .array_type = NO_ARRAY,
  474. .tlv_type = 0x10,
  475. .offset = offsetof(struct
  476. dfc_get_flow_status_req_msg_v01,
  477. bearer_id_list_valid),
  478. .ei_array = NULL,
  479. },
  480. {
  481. .data_type = QMI_DATA_LEN,
  482. .elem_len = 1,
  483. .elem_size = sizeof(u8),
  484. .array_type = NO_ARRAY,
  485. .tlv_type = 0x10,
  486. .offset = offsetof(struct
  487. dfc_get_flow_status_req_msg_v01,
  488. bearer_id_list_len),
  489. .ei_array = NULL,
  490. },
  491. {
  492. .data_type = QMI_UNSIGNED_1_BYTE,
  493. .elem_len = DFC_MAX_BEARERS_V01,
  494. .elem_size = sizeof(u8),
  495. .array_type = VAR_LEN_ARRAY,
  496. .tlv_type = 0x10,
  497. .offset = offsetof(struct
  498. dfc_get_flow_status_req_msg_v01,
  499. bearer_id_list),
  500. .ei_array = NULL,
  501. },
  502. {
  503. .data_type = QMI_EOTI,
  504. .array_type = NO_ARRAY,
  505. .tlv_type = QMI_COMMON_TLV_TYPE,
  506. },
  507. };
  508. static struct qmi_elem_info dfc_get_flow_status_resp_msg_v01_ei[] = {
  509. {
  510. .data_type = QMI_STRUCT,
  511. .elem_len = 1,
  512. .elem_size = sizeof(struct qmi_response_type_v01),
  513. .array_type = NO_ARRAY,
  514. .tlv_type = 0x02,
  515. .offset = offsetof(struct
  516. dfc_get_flow_status_resp_msg_v01,
  517. resp),
  518. .ei_array = qmi_response_type_v01_ei,
  519. },
  520. {
  521. .data_type = QMI_OPT_FLAG,
  522. .elem_len = 1,
  523. .elem_size = sizeof(u8),
  524. .array_type = NO_ARRAY,
  525. .tlv_type = 0x10,
  526. .offset = offsetof(struct
  527. dfc_get_flow_status_resp_msg_v01,
  528. flow_status_valid),
  529. .ei_array = NULL,
  530. },
  531. {
  532. .data_type = QMI_DATA_LEN,
  533. .elem_len = 1,
  534. .elem_size = sizeof(u8),
  535. .array_type = NO_ARRAY,
  536. .tlv_type = 0x10,
  537. .offset = offsetof(struct
  538. dfc_get_flow_status_resp_msg_v01,
  539. flow_status_len),
  540. .ei_array = NULL,
  541. },
  542. {
  543. .data_type = QMI_STRUCT,
  544. .elem_len = DFC_MAX_BEARERS_V01,
  545. .elem_size = sizeof(struct
  546. dfc_flow_status_info_type_v01),
  547. .array_type = VAR_LEN_ARRAY,
  548. .tlv_type = 0x10,
  549. .offset = offsetof(struct
  550. dfc_get_flow_status_resp_msg_v01,
  551. flow_status),
  552. .ei_array = dfc_flow_status_info_type_v01_ei,
  553. },
  554. {
  555. .data_type = QMI_EOTI,
  556. .array_type = NO_ARRAY,
  557. .tlv_type = QMI_COMMON_TLV_TYPE,
  558. },
  559. };
  560. static struct qmi_elem_info dfc_bearer_info_type_v01_ei[] = {
  561. {
  562. .data_type = QMI_UNSIGNED_1_BYTE,
  563. .elem_len = 1,
  564. .elem_size = sizeof(u8),
  565. .array_type = NO_ARRAY,
  566. .tlv_type = QMI_COMMON_TLV_TYPE,
  567. .offset = offsetof(struct
  568. dfc_bearer_info_type_v01,
  569. subs_id),
  570. .ei_array = NULL,
  571. },
  572. {
  573. .data_type = QMI_UNSIGNED_1_BYTE,
  574. .elem_len = 1,
  575. .elem_size = sizeof(u8),
  576. .array_type = NO_ARRAY,
  577. .tlv_type = QMI_COMMON_TLV_TYPE,
  578. .offset = offsetof(struct
  579. dfc_bearer_info_type_v01,
  580. mux_id),
  581. .ei_array = NULL,
  582. },
  583. {
  584. .data_type = QMI_UNSIGNED_1_BYTE,
  585. .elem_len = 1,
  586. .elem_size = sizeof(u8),
  587. .array_type = NO_ARRAY,
  588. .tlv_type = QMI_COMMON_TLV_TYPE,
  589. .offset = offsetof(struct
  590. dfc_bearer_info_type_v01,
  591. bearer_id),
  592. .ei_array = NULL,
  593. },
  594. {
  595. .data_type = QMI_SIGNED_4_BYTE_ENUM,
  596. .elem_len = 1,
  597. .elem_size = sizeof(enum dfc_ip_type_enum_v01),
  598. .array_type = NO_ARRAY,
  599. .tlv_type = QMI_COMMON_TLV_TYPE,
  600. .offset = offsetof(struct
  601. dfc_bearer_info_type_v01,
  602. ip_type),
  603. .ei_array = NULL,
  604. },
  605. {
  606. .data_type = QMI_EOTI,
  607. .array_type = NO_ARRAY,
  608. .tlv_type = QMI_COMMON_TLV_TYPE,
  609. },
  610. };
  611. static struct qmi_elem_info dfc_tx_link_status_ind_v01_ei[] = {
  612. {
  613. .data_type = QMI_UNSIGNED_1_BYTE,
  614. .elem_len = 1,
  615. .elem_size = sizeof(u8),
  616. .array_type = NO_ARRAY,
  617. .tlv_type = 0x01,
  618. .offset = offsetof(struct
  619. dfc_tx_link_status_ind_msg_v01,
  620. tx_status),
  621. .ei_array = NULL,
  622. },
  623. {
  624. .data_type = QMI_OPT_FLAG,
  625. .elem_len = 1,
  626. .elem_size = sizeof(u8),
  627. .array_type = NO_ARRAY,
  628. .tlv_type = 0x10,
  629. .offset = offsetof(struct
  630. dfc_tx_link_status_ind_msg_v01,
  631. bearer_info_valid),
  632. .ei_array = NULL,
  633. },
  634. {
  635. .data_type = QMI_DATA_LEN,
  636. .elem_len = 1,
  637. .elem_size = sizeof(u8),
  638. .array_type = NO_ARRAY,
  639. .tlv_type = 0x10,
  640. .offset = offsetof(struct
  641. dfc_tx_link_status_ind_msg_v01,
  642. bearer_info_len),
  643. .ei_array = NULL,
  644. },
  645. {
  646. .data_type = QMI_STRUCT,
  647. .elem_len = DFC_MAX_BEARERS_V01,
  648. .elem_size = sizeof(struct
  649. dfc_bearer_info_type_v01),
  650. .array_type = VAR_LEN_ARRAY,
  651. .tlv_type = 0x10,
  652. .offset = offsetof(struct
  653. dfc_tx_link_status_ind_msg_v01,
  654. bearer_info),
  655. .ei_array = dfc_bearer_info_type_v01_ei,
  656. },
  657. {
  658. .data_type = QMI_EOTI,
  659. .array_type = NO_ARRAY,
  660. .tlv_type = QMI_COMMON_TLV_TYPE,
  661. },
  662. };
  663. static int
  664. dfc_bind_client_req(struct qmi_handle *dfc_handle,
  665. struct sockaddr_qrtr *ssctl, struct svc_info *svc)
  666. {
  667. struct dfc_bind_client_resp_msg_v01 *resp;
  668. struct dfc_bind_client_req_msg_v01 *req;
  669. struct qmi_txn txn;
  670. int ret;
  671. req = kzalloc(sizeof(*req), GFP_ATOMIC);
  672. if (!req)
  673. return -ENOMEM;
  674. resp = kzalloc(sizeof(*resp), GFP_ATOMIC);
  675. if (!resp) {
  676. kfree(req);
  677. return -ENOMEM;
  678. }
  679. ret = qmi_txn_init(dfc_handle, &txn,
  680. dfc_bind_client_resp_msg_v01_ei, resp);
  681. if (ret < 0) {
  682. pr_err("%s() Failed init for response, err: %d\n",
  683. __func__, ret);
  684. goto out;
  685. }
  686. req->ep_id_valid = 1;
  687. req->ep_id.ep_type = svc->ep_type;
  688. req->ep_id.iface_id = svc->iface_id;
  689. ret = qmi_send_request(dfc_handle, ssctl, &txn,
  690. QMI_DFC_BIND_CLIENT_REQ_V01,
  691. QMI_DFC_BIND_CLIENT_REQ_V01_MAX_MSG_LEN,
  692. dfc_bind_client_req_msg_v01_ei, req);
  693. if (ret < 0) {
  694. qmi_txn_cancel(&txn);
  695. pr_err("%s() Failed sending request, err: %d\n",
  696. __func__, ret);
  697. goto out;
  698. }
  699. ret = qmi_txn_wait(&txn, DFC_TIMEOUT_JF);
  700. if (ret < 0) {
  701. pr_err("%s() Response waiting failed, err: %d\n",
  702. __func__, ret);
  703. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  704. pr_err("%s() Request rejected, result: %d, err: %d\n",
  705. __func__, resp->resp.result, resp->resp.error);
  706. ret = -resp->resp.result;
  707. }
  708. out:
  709. kfree(resp);
  710. kfree(req);
  711. return ret;
  712. }
  713. static int
  714. dfc_indication_register_req(struct qmi_handle *dfc_handle,
  715. struct sockaddr_qrtr *ssctl, u8 reg)
  716. {
  717. struct dfc_indication_register_resp_msg_v01 *resp;
  718. struct dfc_indication_register_req_msg_v01 *req;
  719. struct qmi_txn txn;
  720. int ret;
  721. req = kzalloc(sizeof(*req), GFP_ATOMIC);
  722. if (!req)
  723. return -ENOMEM;
  724. resp = kzalloc(sizeof(*resp), GFP_ATOMIC);
  725. if (!resp) {
  726. kfree(req);
  727. return -ENOMEM;
  728. }
  729. ret = qmi_txn_init(dfc_handle, &txn,
  730. dfc_indication_register_resp_msg_v01_ei, resp);
  731. if (ret < 0) {
  732. pr_err("%s() Failed init for response, err: %d\n",
  733. __func__, ret);
  734. goto out;
  735. }
  736. req->report_flow_status_valid = 1;
  737. req->report_flow_status = reg;
  738. if (!dfc_ps_ext) {
  739. req->report_tx_link_status_valid = 1;
  740. req->report_tx_link_status = reg;
  741. }
  742. ret = qmi_send_request(dfc_handle, ssctl, &txn,
  743. QMI_DFC_INDICATION_REGISTER_REQ_V01,
  744. QMI_DFC_INDICATION_REGISTER_REQ_V01_MAX_MSG_LEN,
  745. dfc_indication_register_req_msg_v01_ei, req);
  746. if (ret < 0) {
  747. qmi_txn_cancel(&txn);
  748. pr_err("%s() Failed sending request, err: %d\n",
  749. __func__, ret);
  750. goto out;
  751. }
  752. ret = qmi_txn_wait(&txn, DFC_TIMEOUT_JF);
  753. if (ret < 0) {
  754. pr_err("%s() Response waiting failed, err: %d\n",
  755. __func__, ret);
  756. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  757. pr_err("%s() Request rejected, result: %d, err: %d\n",
  758. __func__, resp->resp.result, resp->resp.error);
  759. ret = -resp->resp.result;
  760. }
  761. out:
  762. kfree(resp);
  763. kfree(req);
  764. return ret;
  765. }
  766. static int
  767. dfc_get_flow_status_req(struct qmi_handle *dfc_handle,
  768. struct sockaddr_qrtr *ssctl,
  769. struct dfc_get_flow_status_resp_msg_v01 *resp)
  770. {
  771. struct dfc_get_flow_status_req_msg_v01 *req;
  772. struct qmi_txn *txn;
  773. int ret;
  774. req = kzalloc(sizeof(*req), GFP_ATOMIC);
  775. if (!req)
  776. return -ENOMEM;
  777. txn = kzalloc(sizeof(*txn), GFP_ATOMIC);
  778. if (!txn) {
  779. kfree(req);
  780. return -ENOMEM;
  781. }
  782. ret = qmi_txn_init(dfc_handle, txn,
  783. dfc_get_flow_status_resp_msg_v01_ei, resp);
  784. if (ret < 0) {
  785. pr_err("%s() Failed init for response, err: %d\n",
  786. __func__, ret);
  787. goto out;
  788. }
  789. ret = qmi_send_request(dfc_handle, ssctl, txn,
  790. QMI_DFC_GET_FLOW_STATUS_REQ_V01,
  791. QMI_DFC_GET_FLOW_STATUS_REQ_V01_MAX_MSG_LEN,
  792. dfc_get_flow_status_req_msg_v01_ei, req);
  793. if (ret < 0) {
  794. qmi_txn_cancel(txn);
  795. pr_err("%s() Failed sending request, err: %d\n",
  796. __func__, ret);
  797. goto out;
  798. }
  799. ret = qmi_txn_wait(txn, DFC_TIMEOUT_JF);
  800. if (ret < 0) {
  801. pr_err("%s() Response waiting failed, err: %d\n",
  802. __func__, ret);
  803. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  804. pr_err("%s() Request rejected, result: %d, err: %d\n",
  805. __func__, resp->resp.result, resp->resp.error);
  806. ret = -resp->resp.result;
  807. }
  808. out:
  809. kfree(txn);
  810. kfree(req);
  811. return ret;
  812. }
  813. static int dfc_init_service(struct dfc_qmi_data *data)
  814. {
  815. int rc;
  816. rc = dfc_bind_client_req(&data->handle, &data->ssctl, &data->svc);
  817. if (rc < 0)
  818. return rc;
  819. return dfc_indication_register_req(&data->handle, &data->ssctl, 1);
  820. }
  821. static void
  822. dfc_send_ack(struct net_device *dev, u8 bearer_id, u16 seq, u8 mux_id, u8 type)
  823. {
  824. struct qos_info *qos = rmnet_get_qos_pt(dev);
  825. struct sk_buff *skb;
  826. struct dfc_ack_cmd *msg;
  827. int data_size = sizeof(struct dfc_ack_cmd);
  828. int header_size = sizeof(struct dfc_qmap_header);
  829. if (!qos)
  830. return;
  831. if (dfc_qmap) {
  832. dfc_qmap_send_ack(qos, bearer_id, seq, type);
  833. return;
  834. }
  835. skb = alloc_skb(data_size, GFP_ATOMIC);
  836. if (!skb)
  837. return;
  838. msg = (struct dfc_ack_cmd *)skb_put(skb, data_size);
  839. memset(msg, 0, data_size);
  840. msg->header.cd_bit = 1;
  841. msg->header.mux_id = mux_id;
  842. msg->header.pkt_len = htons(data_size - header_size);
  843. msg->bearer_id = bearer_id;
  844. msg->command_name = 4;
  845. msg->cmd_type = 0;
  846. msg->dfc_seq = htons(seq);
  847. msg->type = type;
  848. msg->ver = 2;
  849. msg->transaction_id = htonl(qos->tran_num);
  850. skb->dev = qos->real_dev;
  851. skb->protocol = htons(ETH_P_MAP);
  852. trace_dfc_qmap_cmd(mux_id, bearer_id, seq, type, qos->tran_num);
  853. qos->tran_num++;
  854. rmnet_map_tx_qmap_cmd(skb, RMNET_CH_DEFAULT, true);
  855. }
  856. int dfc_bearer_flow_ctl(struct net_device *dev,
  857. struct rmnet_bearer_map *bearer,
  858. struct qos_info *qos)
  859. {
  860. bool enable;
  861. enable = bearer->grant_size ? true : false;
  862. /* Do not flow disable tcp ack q in tcp bidir
  863. * ACK queue opened first to drain ACKs faster
  864. * Although since tcp ancillary is true most of the time,
  865. * this shouldn't really make a difference
  866. * If there is non zero grant but tcp ancillary is false,
  867. * send out ACKs anyway
  868. */
  869. if (bearer->ack_mq_idx != INVALID_MQ)
  870. qmi_rmnet_flow_control(dev, bearer->ack_mq_idx,
  871. enable || bearer->tcp_bidir);
  872. qmi_rmnet_flow_control(dev, bearer->mq_idx, enable);
  873. if (!enable && bearer->ack_req)
  874. dfc_send_ack(dev, bearer->bearer_id,
  875. bearer->seq, qos->mux_id,
  876. DFC_ACK_TYPE_DISABLE);
  877. return 0;
  878. }
  879. static int dfc_all_bearer_flow_ctl(struct net_device *dev,
  880. struct qos_info *qos, u8 ack_req, u32 ancillary,
  881. struct dfc_flow_status_info_type_v01 *fc_info)
  882. {
  883. struct rmnet_bearer_map *bearer;
  884. list_for_each_entry(bearer, &qos->bearer_head, list) {
  885. bearer->grant_size = fc_info->num_bytes;
  886. bearer->grant_thresh =
  887. qmi_rmnet_grant_per(bearer->grant_size);
  888. bearer->seq = fc_info->seq_num;
  889. bearer->ack_req = ack_req;
  890. bearer->tcp_bidir = DFC_IS_TCP_BIDIR(ancillary);
  891. bearer->last_grant = fc_info->num_bytes;
  892. bearer->last_seq = fc_info->seq_num;
  893. bearer->last_adjusted_grant = fc_info->num_bytes;
  894. dfc_bearer_flow_ctl(dev, bearer, qos);
  895. }
  896. return 0;
  897. }
  898. static u32 dfc_adjust_grant(struct rmnet_bearer_map *bearer,
  899. struct dfc_flow_status_info_type_v01 *fc_info)
  900. {
  901. u32 grant;
  902. if (!fc_info->rx_bytes_valid)
  903. return fc_info->num_bytes;
  904. if (bearer->bytes_in_flight > fc_info->rx_bytes)
  905. bearer->bytes_in_flight -= fc_info->rx_bytes;
  906. else
  907. bearer->bytes_in_flight = 0;
  908. /* Adjusted grant = grant - bytes_in_flight */
  909. if (fc_info->num_bytes > bearer->bytes_in_flight)
  910. grant = fc_info->num_bytes - bearer->bytes_in_flight;
  911. else
  912. grant = 0;
  913. trace_dfc_adjust_grant(fc_info->mux_id, fc_info->bearer_id,
  914. fc_info->num_bytes, fc_info->rx_bytes,
  915. bearer->bytes_in_flight, grant);
  916. return grant;
  917. }
  918. static int dfc_update_fc_map(struct net_device *dev, struct qos_info *qos,
  919. u8 ack_req, u32 ancillary,
  920. struct dfc_flow_status_info_type_v01 *fc_info,
  921. bool is_query)
  922. {
  923. struct rmnet_bearer_map *itm = NULL;
  924. int rc = 0;
  925. bool action = false;
  926. u32 adjusted_grant;
  927. itm = qmi_rmnet_get_bearer_map(qos, fc_info->bearer_id);
  928. /* cache the bearer assuming it is a new bearer */
  929. if (unlikely(!itm && !is_query && fc_info->num_bytes))
  930. itm = qmi_rmnet_get_bearer_noref(qos, fc_info->bearer_id);
  931. if (itm) {
  932. /* The RAT switch flag indicates the start and end of
  933. * the switch. Ignore indications in between.
  934. */
  935. if (DFC_IS_RAT_SWITCH(ancillary))
  936. itm->rat_switch = !fc_info->num_bytes;
  937. else
  938. if (itm->rat_switch)
  939. return 0;
  940. /* If TX is OFF but we received grant, ignore it */
  941. if (itm->tx_off && fc_info->num_bytes > 0)
  942. return 0;
  943. /* Adjuste grant for query */
  944. if (dfc_qmap && is_query) {
  945. adjusted_grant = dfc_adjust_grant(itm, fc_info);
  946. } else {
  947. adjusted_grant = fc_info->num_bytes;
  948. itm->bytes_in_flight = 0;
  949. }
  950. /* update queue state only if there is a change in grant
  951. * or change in ancillary tcp state
  952. */
  953. if ((itm->grant_size == 0 && adjusted_grant > 0) ||
  954. (itm->grant_size > 0 && adjusted_grant == 0) ||
  955. (itm->tcp_bidir ^ DFC_IS_TCP_BIDIR(ancillary)))
  956. action = true;
  957. /* This is needed by qmap */
  958. if (dfc_qmap && itm->ack_req && !ack_req && itm->grant_size)
  959. dfc_qmap_send_ack(qos, itm->bearer_id,
  960. itm->seq, DFC_ACK_TYPE_DISABLE);
  961. itm->grant_size = adjusted_grant;
  962. /* No further query if the adjusted grant is less
  963. * than 20% of the original grant. Add to watch to
  964. * recover if no indication is received.
  965. */
  966. if (dfc_qmap && is_query &&
  967. itm->grant_size < (fc_info->num_bytes / 5)) {
  968. itm->grant_thresh = itm->grant_size;
  969. qmi_rmnet_watchdog_add(itm);
  970. } else {
  971. itm->grant_thresh =
  972. qmi_rmnet_grant_per(itm->grant_size);
  973. qmi_rmnet_watchdog_remove(itm);
  974. }
  975. itm->seq = fc_info->seq_num;
  976. itm->ack_req = ack_req;
  977. itm->tcp_bidir = DFC_IS_TCP_BIDIR(ancillary);
  978. itm->last_grant = fc_info->num_bytes;
  979. itm->last_seq = fc_info->seq_num;
  980. itm->last_adjusted_grant = adjusted_grant;
  981. if (action)
  982. rc = dfc_bearer_flow_ctl(dev, itm, qos);
  983. }
  984. return rc;
  985. }
  986. void dfc_do_burst_flow_control(struct dfc_qmi_data *dfc,
  987. struct dfc_flow_status_ind_msg_v01 *ind,
  988. bool is_query)
  989. {
  990. struct net_device *dev;
  991. struct qos_info *qos;
  992. struct dfc_flow_status_info_type_v01 *flow_status;
  993. struct dfc_ancillary_info_type_v01 *ai;
  994. u8 ack_req = ind->eod_ack_reqd_valid ? ind->eod_ack_reqd : 0;
  995. u32 ancillary;
  996. int i, j;
  997. rcu_read_lock();
  998. for (i = 0; i < ind->flow_status_len; i++) {
  999. flow_status = &ind->flow_status[i];
  1000. ancillary = 0;
  1001. if (ind->ancillary_info_valid) {
  1002. for (j = 0; j < ind->ancillary_info_len; j++) {
  1003. ai = &ind->ancillary_info[j];
  1004. if (ai->mux_id == flow_status->mux_id &&
  1005. ai->bearer_id == flow_status->bearer_id) {
  1006. ancillary = ai->reserved;
  1007. break;
  1008. }
  1009. }
  1010. }
  1011. trace_dfc_flow_ind(dfc->index,
  1012. i, flow_status->mux_id,
  1013. flow_status->bearer_id,
  1014. flow_status->num_bytes,
  1015. flow_status->seq_num,
  1016. ack_req,
  1017. ancillary);
  1018. dev = rmnet_get_rmnet_dev(dfc->rmnet_port,
  1019. flow_status->mux_id);
  1020. if (!dev)
  1021. goto clean_out;
  1022. qos = (struct qos_info *)rmnet_get_qos_pt(dev);
  1023. if (!qos)
  1024. continue;
  1025. spin_lock_bh(&qos->qos_lock);
  1026. /* In powersave, change grant to 1 if it is a enable */
  1027. if (qmi_rmnet_ignore_grant(dfc->rmnet_port)) {
  1028. if (flow_status->num_bytes) {
  1029. flow_status->num_bytes = DEFAULT_GRANT;
  1030. flow_status->seq_num = 0;
  1031. /* below is to reset bytes-in-flight */
  1032. flow_status->rx_bytes_valid = 1;
  1033. flow_status->rx_bytes = 0xFFFFFFFF;
  1034. } else {
  1035. spin_unlock_bh(&qos->qos_lock);
  1036. continue;
  1037. }
  1038. }
  1039. if (unlikely(flow_status->bearer_id == 0xFF))
  1040. dfc_all_bearer_flow_ctl(
  1041. dev, qos, ack_req, ancillary, flow_status);
  1042. else
  1043. dfc_update_fc_map(
  1044. dev, qos, ack_req, ancillary, flow_status,
  1045. is_query);
  1046. spin_unlock_bh(&qos->qos_lock);
  1047. }
  1048. clean_out:
  1049. rcu_read_unlock();
  1050. }
  1051. static void dfc_update_tx_link_status(struct net_device *dev,
  1052. struct qos_info *qos, u8 tx_status,
  1053. struct dfc_bearer_info_type_v01 *binfo)
  1054. {
  1055. struct rmnet_bearer_map *itm = NULL;
  1056. itm = qmi_rmnet_get_bearer_map(qos, binfo->bearer_id);
  1057. if (!itm)
  1058. return;
  1059. /* If no change in tx status, ignore */
  1060. if (itm->tx_off == !tx_status)
  1061. return;
  1062. if (itm->grant_size && !tx_status) {
  1063. itm->grant_size = 0;
  1064. itm->tcp_bidir = false;
  1065. itm->bytes_in_flight = 0;
  1066. qmi_rmnet_watchdog_remove(itm);
  1067. dfc_bearer_flow_ctl(dev, itm, qos);
  1068. } else if (itm->grant_size == 0 && tx_status && !itm->rat_switch) {
  1069. itm->grant_size = DEFAULT_GRANT;
  1070. itm->grant_thresh = qmi_rmnet_grant_per(DEFAULT_GRANT);
  1071. itm->seq = 0;
  1072. itm->ack_req = 0;
  1073. dfc_bearer_flow_ctl(dev, itm, qos);
  1074. }
  1075. itm->tx_off = !tx_status;
  1076. }
  1077. void dfc_handle_tx_link_status_ind(struct dfc_qmi_data *dfc,
  1078. struct dfc_tx_link_status_ind_msg_v01 *ind)
  1079. {
  1080. struct net_device *dev;
  1081. struct qos_info *qos;
  1082. struct dfc_bearer_info_type_v01 *bearer_info;
  1083. int i;
  1084. rcu_read_lock();
  1085. for (i = 0; i < ind->bearer_info_len; i++) {
  1086. bearer_info = &ind->bearer_info[i];
  1087. trace_dfc_tx_link_status_ind(dfc->index, i,
  1088. ind->tx_status,
  1089. bearer_info->mux_id,
  1090. bearer_info->bearer_id);
  1091. dev = rmnet_get_rmnet_dev(dfc->rmnet_port,
  1092. bearer_info->mux_id);
  1093. if (!dev)
  1094. goto clean_out;
  1095. qos = (struct qos_info *)rmnet_get_qos_pt(dev);
  1096. if (!qos)
  1097. continue;
  1098. spin_lock_bh(&qos->qos_lock);
  1099. dfc_update_tx_link_status(
  1100. dev, qos, ind->tx_status, bearer_info);
  1101. spin_unlock_bh(&qos->qos_lock);
  1102. }
  1103. clean_out:
  1104. rcu_read_unlock();
  1105. }
  1106. static void dfc_qmi_ind_work(struct work_struct *work)
  1107. {
  1108. struct dfc_qmi_data *dfc = container_of(work, struct dfc_qmi_data,
  1109. qmi_ind_work);
  1110. struct dfc_svc_ind *svc_ind;
  1111. unsigned long flags;
  1112. if (!dfc)
  1113. return;
  1114. local_bh_disable();
  1115. do {
  1116. spin_lock_irqsave(&dfc->qmi_ind_lock, flags);
  1117. svc_ind = list_first_entry_or_null(&dfc->qmi_ind_q,
  1118. struct dfc_svc_ind, list);
  1119. if (svc_ind)
  1120. list_del(&svc_ind->list);
  1121. spin_unlock_irqrestore(&dfc->qmi_ind_lock, flags);
  1122. if (!svc_ind)
  1123. break;
  1124. if (!dfc->restart_state) {
  1125. if (svc_ind->msg_id == QMI_DFC_FLOW_STATUS_IND_V01)
  1126. dfc_do_burst_flow_control(
  1127. dfc, &svc_ind->d.dfc_info,
  1128. false);
  1129. else if (svc_ind->msg_id ==
  1130. QMI_DFC_TX_LINK_STATUS_IND_V01)
  1131. dfc_handle_tx_link_status_ind(
  1132. dfc, &svc_ind->d.tx_status);
  1133. }
  1134. kfree(svc_ind);
  1135. } while (1);
  1136. local_bh_enable();
  1137. qmi_rmnet_set_dl_msg_active(dfc->rmnet_port);
  1138. }
  1139. static void dfc_clnt_ind_cb(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
  1140. struct qmi_txn *txn, const void *data)
  1141. {
  1142. struct dfc_qmi_data *dfc = container_of(qmi, struct dfc_qmi_data,
  1143. handle);
  1144. struct dfc_flow_status_ind_msg_v01 *ind_msg;
  1145. struct dfc_svc_ind *svc_ind;
  1146. unsigned long flags;
  1147. if (qmi != &dfc->handle)
  1148. return;
  1149. ind_msg = (struct dfc_flow_status_ind_msg_v01 *)data;
  1150. if (ind_msg->flow_status_valid) {
  1151. if (ind_msg->flow_status_len > DFC_MAX_BEARERS_V01) {
  1152. pr_err("%s() Invalid fc info len: %d\n",
  1153. __func__, ind_msg->flow_status_len);
  1154. return;
  1155. }
  1156. svc_ind = kzalloc(sizeof(struct dfc_svc_ind), GFP_ATOMIC);
  1157. if (!svc_ind)
  1158. return;
  1159. svc_ind->msg_id = QMI_DFC_FLOW_STATUS_IND_V01;
  1160. memcpy(&svc_ind->d.dfc_info, ind_msg, sizeof(*ind_msg));
  1161. spin_lock_irqsave(&dfc->qmi_ind_lock, flags);
  1162. list_add_tail(&svc_ind->list, &dfc->qmi_ind_q);
  1163. spin_unlock_irqrestore(&dfc->qmi_ind_lock, flags);
  1164. queue_work(dfc->dfc_wq, &dfc->qmi_ind_work);
  1165. }
  1166. }
  1167. static void dfc_tx_link_status_ind_cb(struct qmi_handle *qmi,
  1168. struct sockaddr_qrtr *sq,
  1169. struct qmi_txn *txn, const void *data)
  1170. {
  1171. struct dfc_qmi_data *dfc = container_of(qmi, struct dfc_qmi_data,
  1172. handle);
  1173. struct dfc_tx_link_status_ind_msg_v01 *ind_msg;
  1174. struct dfc_svc_ind *svc_ind;
  1175. unsigned long flags;
  1176. if (qmi != &dfc->handle)
  1177. return;
  1178. ind_msg = (struct dfc_tx_link_status_ind_msg_v01 *)data;
  1179. if (ind_msg->bearer_info_valid) {
  1180. if (ind_msg->bearer_info_len > DFC_MAX_BEARERS_V01) {
  1181. pr_err("%s() Invalid bearer info len: %d\n",
  1182. __func__, ind_msg->bearer_info_len);
  1183. return;
  1184. }
  1185. svc_ind = kzalloc(sizeof(struct dfc_svc_ind), GFP_ATOMIC);
  1186. if (!svc_ind)
  1187. return;
  1188. svc_ind->msg_id = QMI_DFC_TX_LINK_STATUS_IND_V01;
  1189. memcpy(&svc_ind->d.tx_status, ind_msg, sizeof(*ind_msg));
  1190. spin_lock_irqsave(&dfc->qmi_ind_lock, flags);
  1191. list_add_tail(&svc_ind->list, &dfc->qmi_ind_q);
  1192. spin_unlock_irqrestore(&dfc->qmi_ind_lock, flags);
  1193. queue_work(dfc->dfc_wq, &dfc->qmi_ind_work);
  1194. }
  1195. }
  1196. static void dfc_svc_init(struct work_struct *work)
  1197. {
  1198. int rc = 0;
  1199. struct dfc_qmi_data *data = container_of(work, struct dfc_qmi_data,
  1200. svc_arrive);
  1201. struct qmi_info *qmi;
  1202. if (data->restart_state == 1)
  1203. return;
  1204. rc = dfc_init_service(data);
  1205. if (rc < 0) {
  1206. pr_err("%s Failed to init service, err[%d]\n", __func__, rc);
  1207. return;
  1208. }
  1209. if (data->restart_state == 1)
  1210. return;
  1211. while (!rtnl_trylock()) {
  1212. if (!data->restart_state)
  1213. cond_resched();
  1214. else
  1215. return;
  1216. }
  1217. qmi = (struct qmi_info *)rmnet_get_qmi_pt(data->rmnet_port);
  1218. if (!qmi) {
  1219. rtnl_unlock();
  1220. return;
  1221. }
  1222. qmi->dfc_pending[data->index] = NULL;
  1223. qmi->dfc_clients[data->index] = (void *)data;
  1224. trace_dfc_client_state_up(data->index,
  1225. data->svc.instance,
  1226. data->svc.ep_type,
  1227. data->svc.iface_id);
  1228. rtnl_unlock();
  1229. pr_info("Connection established with the DFC Service\n");
  1230. }
  1231. static int dfc_svc_arrive(struct qmi_handle *qmi, struct qmi_service *svc)
  1232. {
  1233. struct dfc_qmi_data *data = container_of(qmi, struct dfc_qmi_data,
  1234. handle);
  1235. data->ssctl.sq_family = AF_QIPCRTR;
  1236. data->ssctl.sq_node = svc->node;
  1237. data->ssctl.sq_port = svc->port;
  1238. queue_work(data->dfc_wq, &data->svc_arrive);
  1239. return 0;
  1240. }
  1241. static void dfc_svc_exit(struct qmi_handle *qmi, struct qmi_service *svc)
  1242. {
  1243. struct dfc_qmi_data *data = container_of(qmi, struct dfc_qmi_data,
  1244. handle);
  1245. if (!data)
  1246. pr_debug("%s() data is null\n", __func__);
  1247. }
  1248. static struct qmi_ops server_ops = {
  1249. .new_server = dfc_svc_arrive,
  1250. .del_server = dfc_svc_exit,
  1251. };
  1252. static struct qmi_msg_handler qmi_indication_handler[] = {
  1253. {
  1254. .type = QMI_INDICATION,
  1255. .msg_id = QMI_DFC_FLOW_STATUS_IND_V01,
  1256. .ei = dfc_flow_status_ind_v01_ei,
  1257. .decoded_size = sizeof(struct dfc_flow_status_ind_msg_v01),
  1258. .fn = dfc_clnt_ind_cb,
  1259. },
  1260. {
  1261. .type = QMI_INDICATION,
  1262. .msg_id = QMI_DFC_TX_LINK_STATUS_IND_V01,
  1263. .ei = dfc_tx_link_status_ind_v01_ei,
  1264. .decoded_size = sizeof(struct dfc_tx_link_status_ind_msg_v01),
  1265. .fn = dfc_tx_link_status_ind_cb,
  1266. },
  1267. {},
  1268. };
  1269. int dfc_qmi_client_init(void *port, int index, struct svc_info *psvc,
  1270. struct qmi_info *qmi)
  1271. {
  1272. struct dfc_qmi_data *data;
  1273. int rc = -ENOMEM;
  1274. if (!port || !qmi)
  1275. return -EINVAL;
  1276. data = kzalloc(sizeof(struct dfc_qmi_data), GFP_KERNEL);
  1277. if (!data)
  1278. return -ENOMEM;
  1279. data->rmnet_port = port;
  1280. data->index = index;
  1281. data->restart_state = 0;
  1282. memcpy(&data->svc, psvc, sizeof(data->svc));
  1283. INIT_WORK(&data->qmi_ind_work, dfc_qmi_ind_work);
  1284. INIT_LIST_HEAD(&data->qmi_ind_q);
  1285. spin_lock_init(&data->qmi_ind_lock);
  1286. data->dfc_wq = create_singlethread_workqueue("dfc_wq");
  1287. if (!data->dfc_wq) {
  1288. pr_err("%s Could not create workqueue\n", __func__);
  1289. goto err0;
  1290. }
  1291. INIT_WORK(&data->svc_arrive, dfc_svc_init);
  1292. rc = qmi_handle_init(&data->handle,
  1293. QMI_DFC_GET_FLOW_STATUS_RESP_V01_MAX_MSG_LEN,
  1294. &server_ops, qmi_indication_handler);
  1295. if (rc < 0) {
  1296. pr_err("%s: failed qmi_handle_init - rc[%d]\n", __func__, rc);
  1297. goto err1;
  1298. }
  1299. rc = qmi_add_lookup(&data->handle, DFC_SERVICE_ID_V01,
  1300. DFC_SERVICE_VERS_V01,
  1301. psvc->instance);
  1302. if (rc < 0) {
  1303. pr_err("%s: failed qmi_add_lookup - rc[%d]\n", __func__, rc);
  1304. goto err2;
  1305. }
  1306. qmi->dfc_pending[index] = (void *)data;
  1307. return 0;
  1308. err2:
  1309. qmi_handle_release(&data->handle);
  1310. err1:
  1311. destroy_workqueue(data->dfc_wq);
  1312. err0:
  1313. kfree(data);
  1314. return rc;
  1315. }
  1316. void dfc_qmi_client_exit(void *dfc_data)
  1317. {
  1318. struct dfc_qmi_data *data = (struct dfc_qmi_data *)dfc_data;
  1319. if (!data) {
  1320. pr_err("%s() data is null\n", __func__);
  1321. return;
  1322. }
  1323. data->restart_state = 1;
  1324. trace_dfc_client_state_down(data->index, 0);
  1325. qmi_handle_release(&data->handle);
  1326. drain_workqueue(data->dfc_wq);
  1327. destroy_workqueue(data->dfc_wq);
  1328. kfree(data);
  1329. }
  1330. void dfc_qmi_burst_check(struct net_device *dev, struct qos_info *qos,
  1331. int ip_type, u32 mark, unsigned int len)
  1332. {
  1333. struct rmnet_bearer_map *bearer = NULL;
  1334. struct rmnet_flow_map *itm;
  1335. u32 start_grant;
  1336. spin_lock_bh(&qos->qos_lock);
  1337. /* Mark is flow_id */
  1338. itm = qmi_rmnet_get_flow_map(qos, mark, ip_type);
  1339. if (likely(itm))
  1340. bearer = itm->bearer;
  1341. if (unlikely(!bearer))
  1342. goto out;
  1343. trace_dfc_flow_check(dev->name, bearer->bearer_id,
  1344. len, mark, bearer->grant_size);
  1345. bearer->bytes_in_flight += len;
  1346. if (!bearer->grant_size)
  1347. goto out;
  1348. start_grant = bearer->grant_size;
  1349. if (len >= bearer->grant_size)
  1350. bearer->grant_size = 0;
  1351. else
  1352. bearer->grant_size -= len;
  1353. if (start_grant > bearer->grant_thresh &&
  1354. bearer->grant_size <= bearer->grant_thresh) {
  1355. dfc_send_ack(dev, bearer->bearer_id,
  1356. bearer->seq, qos->mux_id,
  1357. DFC_ACK_TYPE_THRESHOLD);
  1358. }
  1359. if (!bearer->grant_size)
  1360. dfc_bearer_flow_ctl(dev, bearer, qos);
  1361. out:
  1362. spin_unlock_bh(&qos->qos_lock);
  1363. }
  1364. void dfc_qmi_query_flow(void *dfc_data)
  1365. {
  1366. struct dfc_qmi_data *data = (struct dfc_qmi_data *)dfc_data;
  1367. struct dfc_get_flow_status_resp_msg_v01 *resp;
  1368. struct dfc_svc_ind *svc_ind;
  1369. int rc;
  1370. resp = kzalloc(sizeof(*resp), GFP_ATOMIC);
  1371. if (!resp)
  1372. return;
  1373. svc_ind = kzalloc(sizeof(*svc_ind), GFP_ATOMIC);
  1374. if (!svc_ind) {
  1375. kfree(resp);
  1376. return;
  1377. }
  1378. if (!data)
  1379. goto done;
  1380. rc = dfc_get_flow_status_req(&data->handle, &data->ssctl, resp);
  1381. if (rc < 0 || !resp->flow_status_valid || resp->flow_status_len < 1 ||
  1382. resp->flow_status_len > DFC_MAX_BEARERS_V01)
  1383. goto done;
  1384. svc_ind->d.dfc_info.flow_status_valid = resp->flow_status_valid;
  1385. svc_ind->d.dfc_info.flow_status_len = resp->flow_status_len;
  1386. memcpy(&svc_ind->d.dfc_info.flow_status, resp->flow_status,
  1387. sizeof(resp->flow_status[0]) * resp->flow_status_len);
  1388. dfc_do_burst_flow_control(data, &svc_ind->d.dfc_info, true);
  1389. done:
  1390. kfree(svc_ind);
  1391. kfree(resp);
  1392. }