ipa_debugfs.c 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #ifdef CONFIG_DEBUG_FS
  6. #include <linux/debugfs.h>
  7. #include <linux/kernel.h>
  8. #include <linux/stringify.h>
  9. #include "ipa_i.h"
  10. #include "../ipa_rm_i.h"
  11. #include "ipahal/ipahal_nat.h"
  12. #include "ipa_odl.h"
  13. #define IPA_MAX_ENTRY_STRING_LEN 500
  14. #define IPA_MAX_MSG_LEN 4096
  15. #define IPA_DBG_MAX_RULE_IN_TBL 128
  16. #define IPA_DBG_ACTIVE_CLIENT_BUF_SIZE ((IPA3_ACTIVE_CLIENTS_LOG_LINE_LEN \
  17. * IPA3_ACTIVE_CLIENTS_LOG_BUFFER_SIZE_LINES) + IPA_MAX_MSG_LEN)
  18. #define IPA_DUMP_STATUS_FIELD(f) \
  19. pr_err(#f "=0x%x\n", status->f)
  20. #define IPA_READ_ONLY_MODE 0444
  21. #define IPA_READ_WRITE_MODE 0664
  22. #define IPA_WRITE_ONLY_MODE 0220
  23. struct ipa3_debugfs_file {
  24. const char *name;
  25. umode_t mode;
  26. void *data;
  27. const struct file_operations fops;
  28. };
  29. const char *ipa3_event_name[IPA_EVENT_MAX_NUM] = {
  30. __stringify(WLAN_CLIENT_CONNECT),
  31. __stringify(WLAN_CLIENT_DISCONNECT),
  32. __stringify(WLAN_CLIENT_POWER_SAVE_MODE),
  33. __stringify(WLAN_CLIENT_NORMAL_MODE),
  34. __stringify(SW_ROUTING_ENABLE),
  35. __stringify(SW_ROUTING_DISABLE),
  36. __stringify(WLAN_AP_CONNECT),
  37. __stringify(WLAN_AP_DISCONNECT),
  38. __stringify(WLAN_STA_CONNECT),
  39. __stringify(WLAN_STA_DISCONNECT),
  40. __stringify(WLAN_CLIENT_CONNECT_EX),
  41. __stringify(WLAN_SWITCH_TO_SCC),
  42. __stringify(WLAN_SWITCH_TO_MCC),
  43. __stringify(WLAN_WDI_ENABLE),
  44. __stringify(WLAN_WDI_DISABLE),
  45. __stringify(WAN_UPSTREAM_ROUTE_ADD),
  46. __stringify(WAN_UPSTREAM_ROUTE_DEL),
  47. __stringify(WAN_EMBMS_CONNECT),
  48. __stringify(WAN_XLAT_CONNECT),
  49. __stringify(ECM_CONNECT),
  50. __stringify(ECM_DISCONNECT),
  51. __stringify(IPA_TETHERING_STATS_UPDATE_STATS),
  52. __stringify(IPA_TETHERING_STATS_UPDATE_NETWORK_STATS),
  53. __stringify(IPA_QUOTA_REACH),
  54. __stringify(IPA_SSR_BEFORE_SHUTDOWN),
  55. __stringify(IPA_SSR_AFTER_POWERUP),
  56. __stringify(ADD_VLAN_IFACE),
  57. __stringify(DEL_VLAN_IFACE),
  58. __stringify(ADD_L2TP_VLAN_MAPPING),
  59. __stringify(DEL_L2TP_VLAN_MAPPING),
  60. __stringify(IPA_PER_CLIENT_STATS_CONNECT_EVENT),
  61. __stringify(IPA_PER_CLIENT_STATS_DISCONNECT_EVENT),
  62. __stringify(ADD_BRIDGE_VLAN_MAPPING),
  63. __stringify(DEL_BRIDGE_VLAN_MAPPING),
  64. __stringify(WLAN_FWR_SSR_BEFORE_SHUTDOWN),
  65. __stringify(IPA_GSB_CONNECT),
  66. __stringify(IPA_GSB_DISCONNECT),
  67. __stringify(IPA_COALESCE_ENABLE),
  68. __stringify(IPA_COALESCE_DISABLE),
  69. __stringify_1(WIGIG_CLIENT_CONNECT),
  70. __stringify_1(WIGIG_FST_SWITCH),
  71. };
  72. const char *ipa3_hdr_l2_type_name[] = {
  73. __stringify(IPA_HDR_L2_NONE),
  74. __stringify(IPA_HDR_L2_ETHERNET_II),
  75. __stringify(IPA_HDR_L2_802_3),
  76. };
  77. const char *ipa3_hdr_proc_type_name[] = {
  78. __stringify(IPA_HDR_PROC_NONE),
  79. __stringify(IPA_HDR_PROC_ETHII_TO_ETHII),
  80. __stringify(IPA_HDR_PROC_ETHII_TO_802_3),
  81. __stringify(IPA_HDR_PROC_802_3_TO_ETHII),
  82. __stringify(IPA_HDR_PROC_802_3_TO_802_3),
  83. __stringify(IPA_HDR_PROC_L2TP_HEADER_ADD),
  84. __stringify(IPA_HDR_PROC_L2TP_HEADER_REMOVE),
  85. };
  86. static struct dentry *dent;
  87. static char dbg_buff[IPA_MAX_MSG_LEN];
  88. static char *active_clients_buf;
  89. static s8 ep_reg_idx;
  90. static void *ipa_ipc_low_buff;
  91. static ssize_t ipa3_read_gen_reg(struct file *file, char __user *ubuf,
  92. size_t count, loff_t *ppos)
  93. {
  94. int nbytes;
  95. struct ipahal_reg_shared_mem_size smem_sz;
  96. memset(&smem_sz, 0, sizeof(smem_sz));
  97. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  98. ipahal_read_reg_fields(IPA_SHARED_MEM_SIZE, &smem_sz);
  99. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  100. "IPA_VERSION=0x%x\n"
  101. "IPA_COMP_HW_VERSION=0x%x\n"
  102. "IPA_ROUTE=0x%x\n"
  103. "IPA_SHARED_MEM_RESTRICTED=0x%x\n"
  104. "IPA_SHARED_MEM_SIZE=0x%x\n"
  105. "IPA_QTIME_TIMESTAMP_CFG=0x%x\n"
  106. "IPA_TIMERS_PULSE_GRAN_CFG=0x%x\n"
  107. "IPA_TIMERS_XO_CLK_DIV_CFG=0x%x\n",
  108. ipahal_read_reg(IPA_VERSION),
  109. ipahal_read_reg(IPA_COMP_HW_VERSION),
  110. ipahal_read_reg(IPA_ROUTE),
  111. smem_sz.shared_mem_baddr,
  112. smem_sz.shared_mem_sz,
  113. ipahal_read_reg(IPA_QTIME_TIMESTAMP_CFG),
  114. ipahal_read_reg(IPA_TIMERS_PULSE_GRAN_CFG),
  115. ipahal_read_reg(IPA_TIMERS_XO_CLK_DIV_CFG));
  116. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  117. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, nbytes);
  118. }
  119. static ssize_t ipa3_write_ep_holb(struct file *file,
  120. const char __user *buf, size_t count, loff_t *ppos)
  121. {
  122. struct ipa_ep_cfg_holb holb;
  123. u32 en;
  124. u32 tmr_val;
  125. u32 ep_idx;
  126. unsigned long missing;
  127. char *sptr, *token;
  128. if (count >= sizeof(dbg_buff))
  129. return -EFAULT;
  130. missing = copy_from_user(dbg_buff, buf, count);
  131. if (missing)
  132. return -EFAULT;
  133. dbg_buff[count] = '\0';
  134. sptr = dbg_buff;
  135. token = strsep(&sptr, " ");
  136. if (!token)
  137. return -EINVAL;
  138. if (kstrtou32(token, 0, &ep_idx))
  139. return -EINVAL;
  140. token = strsep(&sptr, " ");
  141. if (!token)
  142. return -EINVAL;
  143. if (kstrtou32(token, 0, &en))
  144. return -EINVAL;
  145. token = strsep(&sptr, " ");
  146. if (!token)
  147. return -EINVAL;
  148. if (kstrtou32(token, 0, &tmr_val))
  149. return -EINVAL;
  150. holb.en = en;
  151. holb.tmr_val = tmr_val;
  152. ipa3_cfg_ep_holb(ep_idx, &holb);
  153. return count;
  154. }
  155. static ssize_t ipa3_write_ep_reg(struct file *file, const char __user *buf,
  156. size_t count, loff_t *ppos)
  157. {
  158. s8 option;
  159. int ret;
  160. ret = kstrtos8_from_user(buf, count, 0, &option);
  161. if (ret)
  162. return ret;
  163. if (option >= ipa3_ctx->ipa_num_pipes) {
  164. IPAERR("bad pipe specified %u\n", option);
  165. return count;
  166. }
  167. ep_reg_idx = option;
  168. return count;
  169. }
  170. /**
  171. * _ipa_read_ep_reg_v3_0() - Reads and prints endpoint configuration registers
  172. *
  173. * Returns the number of characters printed
  174. */
  175. int _ipa_read_ep_reg_v3_0(char *buf, int max_len, int pipe)
  176. {
  177. return scnprintf(
  178. dbg_buff, IPA_MAX_MSG_LEN,
  179. "IPA_ENDP_INIT_NAT_%u=0x%x\n"
  180. "IPA_ENDP_INIT_HDR_%u=0x%x\n"
  181. "IPA_ENDP_INIT_HDR_EXT_%u=0x%x\n"
  182. "IPA_ENDP_INIT_MODE_%u=0x%x\n"
  183. "IPA_ENDP_INIT_AGGR_%u=0x%x\n"
  184. "IPA_ENDP_INIT_ROUTE_%u=0x%x\n"
  185. "IPA_ENDP_INIT_CTRL_%u=0x%x\n"
  186. "IPA_ENDP_INIT_HOL_EN_%u=0x%x\n"
  187. "IPA_ENDP_INIT_HOL_TIMER_%u=0x%x\n"
  188. "IPA_ENDP_INIT_DEAGGR_%u=0x%x\n"
  189. "IPA_ENDP_INIT_CFG_%u=0x%x\n",
  190. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_NAT_n, pipe),
  191. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_HDR_n, pipe),
  192. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_HDR_EXT_n, pipe),
  193. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_MODE_n, pipe),
  194. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_AGGR_n, pipe),
  195. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_ROUTE_n, pipe),
  196. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_CTRL_n, pipe),
  197. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_HOL_BLOCK_EN_n, pipe),
  198. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_HOL_BLOCK_TIMER_n, pipe),
  199. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_DEAGGR_n, pipe),
  200. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_CFG_n, pipe));
  201. }
  202. /**
  203. * _ipa_read_ep_reg_v4_0() - Reads and prints endpoint configuration registers
  204. *
  205. * Returns the number of characters printed
  206. * Removed IPA_ENDP_INIT_ROUTE_n from v3
  207. */
  208. int _ipa_read_ep_reg_v4_0(char *buf, int max_len, int pipe)
  209. {
  210. return scnprintf(
  211. dbg_buff, IPA_MAX_MSG_LEN,
  212. "IPA_ENDP_INIT_NAT_%u=0x%x\n"
  213. "IPA_ENDP_INIT_CONN_TRACK_n%u=0x%x\n"
  214. "IPA_ENDP_INIT_HDR_%u=0x%x\n"
  215. "IPA_ENDP_INIT_HDR_EXT_%u=0x%x\n"
  216. "IPA_ENDP_INIT_MODE_%u=0x%x\n"
  217. "IPA_ENDP_INIT_AGGR_%u=0x%x\n"
  218. "IPA_ENDP_INIT_CTRL_%u=0x%x\n"
  219. "IPA_ENDP_INIT_HOL_EN_%u=0x%x\n"
  220. "IPA_ENDP_INIT_HOL_TIMER_%u=0x%x\n"
  221. "IPA_ENDP_INIT_DEAGGR_%u=0x%x\n"
  222. "IPA_ENDP_INIT_CFG_%u=0x%x\n",
  223. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_NAT_n, pipe),
  224. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_CONN_TRACK_n, pipe),
  225. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_HDR_n, pipe),
  226. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_HDR_EXT_n, pipe),
  227. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_MODE_n, pipe),
  228. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_AGGR_n, pipe),
  229. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_CTRL_n, pipe),
  230. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_HOL_BLOCK_EN_n, pipe),
  231. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_HOL_BLOCK_TIMER_n, pipe),
  232. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_DEAGGR_n, pipe),
  233. pipe, ipahal_read_reg_n(IPA_ENDP_INIT_CFG_n, pipe));
  234. }
  235. static ssize_t ipa3_read_ep_reg(struct file *file, char __user *ubuf,
  236. size_t count, loff_t *ppos)
  237. {
  238. int nbytes;
  239. int i;
  240. int start_idx;
  241. int end_idx;
  242. int size = 0;
  243. int ret;
  244. loff_t pos;
  245. /* negative ep_reg_idx means all registers */
  246. if (ep_reg_idx < 0) {
  247. start_idx = 0;
  248. end_idx = ipa3_ctx->ipa_num_pipes;
  249. } else {
  250. start_idx = ep_reg_idx;
  251. end_idx = start_idx + 1;
  252. }
  253. pos = *ppos;
  254. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  255. for (i = start_idx; i < end_idx; i++) {
  256. nbytes = ipa3_ctx->ctrl->ipa3_read_ep_reg(dbg_buff,
  257. IPA_MAX_MSG_LEN, i);
  258. *ppos = pos;
  259. ret = simple_read_from_buffer(ubuf, count, ppos, dbg_buff,
  260. nbytes);
  261. if (ret < 0) {
  262. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  263. return ret;
  264. }
  265. size += ret;
  266. ubuf += nbytes;
  267. count -= nbytes;
  268. }
  269. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  270. *ppos = pos + size;
  271. return size;
  272. }
  273. static ssize_t ipa3_write_keep_awake(struct file *file, const char __user *buf,
  274. size_t count, loff_t *ppos)
  275. {
  276. s8 option = 0;
  277. int ret;
  278. ret = kstrtos8_from_user(buf, count, 0, &option);
  279. if (ret)
  280. return ret;
  281. if (option == 1)
  282. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  283. else if (option == 0)
  284. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  285. else
  286. return -EFAULT;
  287. return count;
  288. }
  289. static ssize_t ipa3_read_keep_awake(struct file *file, char __user *ubuf,
  290. size_t count, loff_t *ppos)
  291. {
  292. int nbytes;
  293. mutex_lock(&ipa3_ctx->ipa3_active_clients.mutex);
  294. if (atomic_read(&ipa3_ctx->ipa3_active_clients.cnt))
  295. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  296. "IPA APPS power state is ON\n");
  297. else
  298. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  299. "IPA APPS power state is OFF\n");
  300. mutex_unlock(&ipa3_ctx->ipa3_active_clients.mutex);
  301. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, nbytes);
  302. }
  303. static ssize_t ipa3_read_hdr(struct file *file, char __user *ubuf, size_t count,
  304. loff_t *ppos)
  305. {
  306. int nbytes = 0;
  307. int i = 0;
  308. struct ipa3_hdr_entry *entry;
  309. mutex_lock(&ipa3_ctx->lock);
  310. if (ipa3_ctx->hdr_tbl_lcl)
  311. pr_err("Table resides on local memory\n");
  312. else
  313. pr_err("Table resides on system (ddr) memory\n");
  314. list_for_each_entry(entry, &ipa3_ctx->hdr_tbl.head_hdr_entry_list,
  315. link) {
  316. if (entry->cookie != IPA_HDR_COOKIE)
  317. continue;
  318. nbytes = scnprintf(
  319. dbg_buff,
  320. IPA_MAX_MSG_LEN,
  321. "name:%s len=%d ref=%d partial=%d type=%s ",
  322. entry->name,
  323. entry->hdr_len,
  324. entry->ref_cnt,
  325. entry->is_partial,
  326. ipa3_hdr_l2_type_name[entry->type]);
  327. if (entry->is_hdr_proc_ctx) {
  328. nbytes += scnprintf(
  329. dbg_buff + nbytes,
  330. IPA_MAX_MSG_LEN - nbytes,
  331. "phys_base=0x%pa ",
  332. &entry->phys_base);
  333. } else {
  334. nbytes += scnprintf(
  335. dbg_buff + nbytes,
  336. IPA_MAX_MSG_LEN - nbytes,
  337. "ofst=%u ",
  338. entry->offset_entry->offset >> 2);
  339. }
  340. for (i = 0; i < entry->hdr_len; i++) {
  341. scnprintf(dbg_buff + nbytes + i * 2,
  342. IPA_MAX_MSG_LEN - nbytes - i * 2,
  343. "%02x", entry->hdr[i]);
  344. }
  345. scnprintf(dbg_buff + nbytes + entry->hdr_len * 2,
  346. IPA_MAX_MSG_LEN - nbytes - entry->hdr_len * 2,
  347. "\n");
  348. pr_err("%s", dbg_buff);
  349. }
  350. mutex_unlock(&ipa3_ctx->lock);
  351. return 0;
  352. }
  353. static int ipa3_attrib_dump(struct ipa_rule_attrib *attrib,
  354. enum ipa_ip_type ip)
  355. {
  356. uint32_t addr[4];
  357. uint32_t mask[4];
  358. int i;
  359. if (attrib->attrib_mask & IPA_FLT_IS_PURE_ACK)
  360. pr_err("is_pure_ack ");
  361. if (attrib->attrib_mask & IPA_FLT_TOS)
  362. pr_err("tos:%d ", attrib->u.v4.tos);
  363. if (attrib->attrib_mask & IPA_FLT_TOS_MASKED) {
  364. pr_err("tos_value:%d ", attrib->tos_value);
  365. pr_err("tos_mask:%d ", attrib->tos_mask);
  366. }
  367. if (attrib->attrib_mask & IPA_FLT_PROTOCOL)
  368. pr_err("protocol:%d ", attrib->u.v4.protocol);
  369. if (attrib->attrib_mask & IPA_FLT_SRC_ADDR) {
  370. if (ip == IPA_IP_v4) {
  371. addr[0] = htonl(attrib->u.v4.src_addr);
  372. mask[0] = htonl(attrib->u.v4.src_addr_mask);
  373. pr_err(
  374. "src_addr:%pI4 src_addr_mask:%pI4 ",
  375. addr + 0, mask + 0);
  376. } else if (ip == IPA_IP_v6) {
  377. for (i = 0; i < 4; i++) {
  378. addr[i] = htonl(attrib->u.v6.src_addr[i]);
  379. mask[i] = htonl(attrib->u.v6.src_addr_mask[i]);
  380. }
  381. pr_err(
  382. "src_addr:%pI6 src_addr_mask:%pI6 ",
  383. addr + 0, mask + 0);
  384. }
  385. }
  386. if (attrib->attrib_mask & IPA_FLT_DST_ADDR) {
  387. if (ip == IPA_IP_v4) {
  388. addr[0] = htonl(attrib->u.v4.dst_addr);
  389. mask[0] = htonl(attrib->u.v4.dst_addr_mask);
  390. pr_err(
  391. "dst_addr:%pI4 dst_addr_mask:%pI4 ",
  392. addr + 0, mask + 0);
  393. } else if (ip == IPA_IP_v6) {
  394. for (i = 0; i < 4; i++) {
  395. addr[i] = htonl(attrib->u.v6.dst_addr[i]);
  396. mask[i] = htonl(attrib->u.v6.dst_addr_mask[i]);
  397. }
  398. pr_err(
  399. "dst_addr:%pI6 dst_addr_mask:%pI6 ",
  400. addr + 0, mask + 0);
  401. }
  402. }
  403. if (attrib->attrib_mask & IPA_FLT_SRC_PORT_RANGE) {
  404. pr_err("src_port_range:%u %u ",
  405. attrib->src_port_lo,
  406. attrib->src_port_hi);
  407. }
  408. if (attrib->attrib_mask & IPA_FLT_DST_PORT_RANGE) {
  409. pr_err("dst_port_range:%u %u ",
  410. attrib->dst_port_lo,
  411. attrib->dst_port_hi);
  412. }
  413. if (attrib->attrib_mask & IPA_FLT_TYPE)
  414. pr_err("type:%d ", attrib->type);
  415. if (attrib->attrib_mask & IPA_FLT_CODE)
  416. pr_err("code:%d ", attrib->code);
  417. if (attrib->attrib_mask & IPA_FLT_SPI)
  418. pr_err("spi:%x ", attrib->spi);
  419. if (attrib->attrib_mask & IPA_FLT_SRC_PORT)
  420. pr_err("src_port:%u ", attrib->src_port);
  421. if (attrib->attrib_mask & IPA_FLT_DST_PORT)
  422. pr_err("dst_port:%u ", attrib->dst_port);
  423. if (attrib->attrib_mask & IPA_FLT_TC)
  424. pr_err("tc:%d ", attrib->u.v6.tc);
  425. if (attrib->attrib_mask & IPA_FLT_FLOW_LABEL)
  426. pr_err("flow_label:%x ", attrib->u.v6.flow_label);
  427. if (attrib->attrib_mask & IPA_FLT_NEXT_HDR)
  428. pr_err("next_hdr:%d ", attrib->u.v6.next_hdr);
  429. if (attrib->attrib_mask & IPA_FLT_META_DATA) {
  430. pr_err(
  431. "metadata:%x metadata_mask:%x ",
  432. attrib->meta_data, attrib->meta_data_mask);
  433. }
  434. if (attrib->attrib_mask & IPA_FLT_FRAGMENT)
  435. pr_err("frg ");
  436. if ((attrib->attrib_mask & IPA_FLT_MAC_SRC_ADDR_ETHER_II) ||
  437. (attrib->attrib_mask & IPA_FLT_MAC_SRC_ADDR_802_3)) {
  438. pr_err("src_mac_addr:%pM ", attrib->src_mac_addr);
  439. }
  440. if ((attrib->attrib_mask & IPA_FLT_MAC_DST_ADDR_ETHER_II) ||
  441. (attrib->attrib_mask & IPA_FLT_MAC_DST_ADDR_802_3) ||
  442. (attrib->attrib_mask & IPA_FLT_MAC_DST_ADDR_L2TP)) {
  443. pr_err("dst_mac_addr:%pM ", attrib->dst_mac_addr);
  444. }
  445. if (attrib->attrib_mask & IPA_FLT_MAC_ETHER_TYPE)
  446. pr_err("ether_type:%x ", attrib->ether_type);
  447. if (attrib->attrib_mask & IPA_FLT_TCP_SYN)
  448. pr_err("tcp syn ");
  449. if (attrib->attrib_mask & IPA_FLT_TCP_SYN_L2TP)
  450. pr_err("tcp syn l2tp ");
  451. if (attrib->attrib_mask & IPA_FLT_L2TP_INNER_IP_TYPE)
  452. pr_err("l2tp inner ip type: %d ", attrib->type);
  453. if (attrib->attrib_mask & IPA_FLT_L2TP_INNER_IPV4_DST_ADDR) {
  454. addr[0] = htonl(attrib->u.v4.dst_addr);
  455. mask[0] = htonl(attrib->u.v4.dst_addr_mask);
  456. pr_err("dst_addr:%pI4 dst_addr_mask:%pI4 ", addr, mask);
  457. }
  458. pr_err("\n");
  459. return 0;
  460. }
  461. static int ipa3_attrib_dump_eq(struct ipa_ipfltri_rule_eq *attrib)
  462. {
  463. uint8_t addr[16];
  464. uint8_t mask[16];
  465. int i;
  466. int j;
  467. if (attrib->tos_eq_present) {
  468. if (ipa3_ctx->ipa_hw_type >= IPA_HW_v4_5)
  469. pr_err("pure_ack ");
  470. else
  471. pr_err("tos:%d ", attrib->tos_eq);
  472. }
  473. if (attrib->protocol_eq_present)
  474. pr_err("protocol:%d ", attrib->protocol_eq);
  475. if (attrib->tc_eq_present)
  476. pr_err("tc:%d ", attrib->tc_eq);
  477. if (attrib->num_offset_meq_128 > IPA_IPFLTR_NUM_MEQ_128_EQNS) {
  478. IPAERR_RL("num_offset_meq_128 Max %d passed value %d\n",
  479. IPA_IPFLTR_NUM_MEQ_128_EQNS, attrib->num_offset_meq_128);
  480. return -EPERM;
  481. }
  482. for (i = 0; i < attrib->num_offset_meq_128; i++) {
  483. for (j = 0; j < 16; j++) {
  484. addr[j] = attrib->offset_meq_128[i].value[j];
  485. mask[j] = attrib->offset_meq_128[i].mask[j];
  486. }
  487. pr_err(
  488. "(ofst_meq128: ofst:%d mask:%pI6 val:%pI6) ",
  489. attrib->offset_meq_128[i].offset,
  490. mask, addr);
  491. }
  492. if (attrib->num_offset_meq_32 > IPA_IPFLTR_NUM_MEQ_32_EQNS) {
  493. IPAERR_RL("num_offset_meq_32 Max %d passed value %d\n",
  494. IPA_IPFLTR_NUM_MEQ_32_EQNS, attrib->num_offset_meq_32);
  495. return -EPERM;
  496. }
  497. for (i = 0; i < attrib->num_offset_meq_32; i++)
  498. pr_err(
  499. "(ofst_meq32: ofst:%u mask:0x%x val:0x%x) ",
  500. attrib->offset_meq_32[i].offset,
  501. attrib->offset_meq_32[i].mask,
  502. attrib->offset_meq_32[i].value);
  503. if (attrib->num_ihl_offset_meq_32 > IPA_IPFLTR_NUM_IHL_MEQ_32_EQNS) {
  504. IPAERR_RL("num_ihl_offset_meq_32 Max %d passed value %d\n",
  505. IPA_IPFLTR_NUM_IHL_MEQ_32_EQNS, attrib->num_ihl_offset_meq_32);
  506. return -EPERM;
  507. }
  508. for (i = 0; i < attrib->num_ihl_offset_meq_32; i++)
  509. pr_err(
  510. "(ihl_ofst_meq32: ofts:%d mask:0x%x val:0x%x) ",
  511. attrib->ihl_offset_meq_32[i].offset,
  512. attrib->ihl_offset_meq_32[i].mask,
  513. attrib->ihl_offset_meq_32[i].value);
  514. if (attrib->metadata_meq32_present)
  515. pr_err(
  516. "(metadata: ofst:%u mask:0x%x val:0x%x) ",
  517. attrib->metadata_meq32.offset,
  518. attrib->metadata_meq32.mask,
  519. attrib->metadata_meq32.value);
  520. if (attrib->num_ihl_offset_range_16 >
  521. IPA_IPFLTR_NUM_IHL_RANGE_16_EQNS) {
  522. IPAERR_RL("num_ihl_offset_range_16 Max %d passed value %d\n",
  523. IPA_IPFLTR_NUM_IHL_RANGE_16_EQNS,
  524. attrib->num_ihl_offset_range_16);
  525. return -EPERM;
  526. }
  527. for (i = 0; i < attrib->num_ihl_offset_range_16; i++)
  528. pr_err(
  529. "(ihl_ofst_range16: ofst:%u lo:%u hi:%u) ",
  530. attrib->ihl_offset_range_16[i].offset,
  531. attrib->ihl_offset_range_16[i].range_low,
  532. attrib->ihl_offset_range_16[i].range_high);
  533. if (attrib->ihl_offset_eq_32_present)
  534. pr_err(
  535. "(ihl_ofst_eq32:%d val:0x%x) ",
  536. attrib->ihl_offset_eq_32.offset,
  537. attrib->ihl_offset_eq_32.value);
  538. if (attrib->ihl_offset_eq_16_present)
  539. pr_err(
  540. "(ihl_ofst_eq16:%d val:0x%x) ",
  541. attrib->ihl_offset_eq_16.offset,
  542. attrib->ihl_offset_eq_16.value);
  543. if (attrib->fl_eq_present)
  544. pr_err("flow_label:%d ", attrib->fl_eq);
  545. if (attrib->ipv4_frag_eq_present)
  546. pr_err("frag ");
  547. pr_err("\n");
  548. return 0;
  549. }
  550. static int ipa3_open_dbg(struct inode *inode, struct file *file)
  551. {
  552. file->private_data = inode->i_private;
  553. return 0;
  554. }
  555. static ssize_t ipa3_read_rt(struct file *file, char __user *ubuf, size_t count,
  556. loff_t *ppos)
  557. {
  558. int i = 0;
  559. struct ipa3_rt_tbl *tbl;
  560. struct ipa3_rt_entry *entry;
  561. struct ipa3_rt_tbl_set *set;
  562. enum ipa_ip_type ip = (enum ipa_ip_type)file->private_data;
  563. u32 ofst;
  564. u32 ofst_words;
  565. set = &ipa3_ctx->rt_tbl_set[ip];
  566. mutex_lock(&ipa3_ctx->lock);
  567. if (ip == IPA_IP_v6) {
  568. if (ipa3_ctx->ip6_rt_tbl_hash_lcl)
  569. pr_err("Hashable table resides on local memory\n");
  570. else
  571. pr_err("Hashable table resides on system (ddr) memory\n");
  572. if (ipa3_ctx->ip6_rt_tbl_nhash_lcl)
  573. pr_err("Non-Hashable table resides on local memory\n");
  574. else
  575. pr_err("Non-Hashable table resides on system (ddr) memory\n");
  576. } else if (ip == IPA_IP_v4) {
  577. if (ipa3_ctx->ip4_rt_tbl_hash_lcl)
  578. pr_err("Hashable table resides on local memory\n");
  579. else
  580. pr_err("Hashable table resides on system (ddr) memory\n");
  581. if (ipa3_ctx->ip4_rt_tbl_nhash_lcl)
  582. pr_err("Non-Hashable table resides on local memory\n");
  583. else
  584. pr_err("Non-Hashable table resides on system (ddr) memory\n");
  585. }
  586. list_for_each_entry(tbl, &set->head_rt_tbl_list, link) {
  587. i = 0;
  588. list_for_each_entry(entry, &tbl->head_rt_rule_list, link) {
  589. if (entry->proc_ctx) {
  590. ofst = entry->proc_ctx->offset_entry->offset;
  591. ofst_words =
  592. (ofst +
  593. ipa3_ctx->hdr_proc_ctx_tbl.start_offset)
  594. >> 5;
  595. pr_err("tbl_idx:%d tbl_name:%s tbl_ref:%u ",
  596. entry->tbl->idx, entry->tbl->name,
  597. entry->tbl->ref_cnt);
  598. pr_err("rule_idx:%d dst:%d ep:%d S:%u ",
  599. i, entry->rule.dst,
  600. ipa3_get_ep_mapping(entry->rule.dst),
  601. !ipa3_ctx->hdr_proc_ctx_tbl_lcl);
  602. pr_err("proc_ctx[32B]:%u attrib_mask:%08x ",
  603. ofst_words,
  604. entry->rule.attrib.attrib_mask);
  605. pr_err("rule_id:%u max_prio:%u prio:%u ",
  606. entry->rule_id, entry->rule.max_prio,
  607. entry->prio);
  608. pr_err("enable_stats:%u counter_id:%u\n",
  609. entry->rule.enable_stats,
  610. entry->rule.cnt_idx);
  611. pr_err("hashable:%u retain_hdr:%u ",
  612. entry->rule.hashable,
  613. entry->rule.retain_hdr);
  614. } else {
  615. if (entry->hdr)
  616. ofst = entry->hdr->offset_entry->offset;
  617. else
  618. ofst = 0;
  619. pr_err("tbl_idx:%d tbl_name:%s tbl_ref:%u ",
  620. entry->tbl->idx, entry->tbl->name,
  621. entry->tbl->ref_cnt);
  622. pr_err("rule_idx:%d dst:%d ep:%d S:%u ",
  623. i, entry->rule.dst,
  624. ipa3_get_ep_mapping(entry->rule.dst),
  625. !ipa3_ctx->hdr_tbl_lcl);
  626. pr_err("hdr_ofst[words]:%u attrib_mask:%08x ",
  627. ofst >> 2,
  628. entry->rule.attrib.attrib_mask);
  629. pr_err("rule_id:%u max_prio:%u prio:%u ",
  630. entry->rule_id, entry->rule.max_prio,
  631. entry->prio);
  632. pr_err("enable_stats:%u counter_id:%u\n",
  633. entry->rule.enable_stats,
  634. entry->rule.cnt_idx);
  635. pr_err("hashable:%u retain_hdr:%u ",
  636. entry->rule.hashable,
  637. entry->rule.retain_hdr);
  638. }
  639. ipa3_attrib_dump(&entry->rule.attrib, ip);
  640. i++;
  641. }
  642. }
  643. mutex_unlock(&ipa3_ctx->lock);
  644. return 0;
  645. }
  646. static ssize_t ipa3_read_rt_hw(struct file *file, char __user *ubuf,
  647. size_t count, loff_t *ppos)
  648. {
  649. enum ipa_ip_type ip = (enum ipa_ip_type)file->private_data;
  650. int tbls_num;
  651. int rules_num;
  652. int tbl;
  653. int rl;
  654. int res = 0;
  655. struct ipahal_rt_rule_entry *rules = NULL;
  656. switch (ip) {
  657. case IPA_IP_v4:
  658. tbls_num = IPA_MEM_PART(v4_rt_num_index);
  659. break;
  660. case IPA_IP_v6:
  661. tbls_num = IPA_MEM_PART(v6_rt_num_index);
  662. break;
  663. default:
  664. IPAERR("ip type error %d\n", ip);
  665. return -EINVAL;
  666. }
  667. IPADBG("Tring to parse %d H/W routing tables - IP=%d\n", tbls_num, ip);
  668. rules = kzalloc(sizeof(*rules) * IPA_DBG_MAX_RULE_IN_TBL, GFP_KERNEL);
  669. if (!rules) {
  670. IPAERR("failed to allocate mem for tbl rules\n");
  671. return -ENOMEM;
  672. }
  673. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  674. mutex_lock(&ipa3_ctx->lock);
  675. for (tbl = 0 ; tbl < tbls_num ; tbl++) {
  676. pr_err("=== Routing Table %d = Hashable Rules ===\n", tbl);
  677. rules_num = IPA_DBG_MAX_RULE_IN_TBL;
  678. res = ipa3_rt_read_tbl_from_hw(tbl, ip, true, rules,
  679. &rules_num);
  680. if (res) {
  681. pr_err("ERROR - Check the logs\n");
  682. IPAERR("failed reading tbl from hw\n");
  683. goto bail;
  684. }
  685. if (!rules_num)
  686. pr_err("-->No rules. Empty tbl or modem system table\n");
  687. for (rl = 0 ; rl < rules_num ; rl++) {
  688. pr_err("rule_idx:%d dst ep:%d L:%u ",
  689. rl, rules[rl].dst_pipe_idx, rules[rl].hdr_lcl);
  690. if (rules[rl].hdr_type == IPAHAL_RT_RULE_HDR_PROC_CTX)
  691. pr_err("proc_ctx:%u attrib_mask:%08x ",
  692. rules[rl].hdr_ofst,
  693. rules[rl].eq_attrib.rule_eq_bitmap);
  694. else
  695. pr_err("hdr_ofst:%u attrib_mask:%08x ",
  696. rules[rl].hdr_ofst,
  697. rules[rl].eq_attrib.rule_eq_bitmap);
  698. pr_err("rule_id:%u cnt_id:%hhu prio:%u retain_hdr:%u\n",
  699. rules[rl].id, rules[rl].cnt_idx,
  700. rules[rl].priority, rules[rl].retain_hdr);
  701. res = ipa3_attrib_dump_eq(&rules[rl].eq_attrib);
  702. if (res) {
  703. IPAERR_RL("failed read attrib eq\n");
  704. goto bail;
  705. }
  706. }
  707. pr_err("=== Routing Table %d = Non-Hashable Rules ===\n", tbl);
  708. rules_num = IPA_DBG_MAX_RULE_IN_TBL;
  709. res = ipa3_rt_read_tbl_from_hw(tbl, ip, false, rules,
  710. &rules_num);
  711. if (res) {
  712. pr_err("ERROR - Check the logs\n");
  713. IPAERR("failed reading tbl from hw\n");
  714. goto bail;
  715. }
  716. if (!rules_num)
  717. pr_err("-->No rules. Empty tbl or modem system table\n");
  718. for (rl = 0 ; rl < rules_num ; rl++) {
  719. pr_err("rule_idx:%d dst ep:%d L:%u ",
  720. rl, rules[rl].dst_pipe_idx, rules[rl].hdr_lcl);
  721. if (rules[rl].hdr_type == IPAHAL_RT_RULE_HDR_PROC_CTX)
  722. pr_err("proc_ctx:%u attrib_mask:%08x ",
  723. rules[rl].hdr_ofst,
  724. rules[rl].eq_attrib.rule_eq_bitmap);
  725. else
  726. pr_err("hdr_ofst:%u attrib_mask:%08x ",
  727. rules[rl].hdr_ofst,
  728. rules[rl].eq_attrib.rule_eq_bitmap);
  729. pr_err("rule_id:%u cnt_id:%hhu prio:%u retain_hdr:%u\n",
  730. rules[rl].id, rules[rl].cnt_idx,
  731. rules[rl].priority, rules[rl].retain_hdr);
  732. res = ipa3_attrib_dump_eq(&rules[rl].eq_attrib);
  733. if (res) {
  734. IPAERR_RL("failed read attrib eq\n");
  735. goto bail;
  736. }
  737. }
  738. pr_err("\n");
  739. }
  740. bail:
  741. mutex_unlock(&ipa3_ctx->lock);
  742. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  743. kfree(rules);
  744. return res;
  745. }
  746. static ssize_t ipa3_read_proc_ctx(struct file *file, char __user *ubuf,
  747. size_t count, loff_t *ppos)
  748. {
  749. int nbytes = 0;
  750. struct ipa3_hdr_proc_ctx_tbl *tbl;
  751. struct ipa3_hdr_proc_ctx_entry *entry;
  752. u32 ofst_words;
  753. tbl = &ipa3_ctx->hdr_proc_ctx_tbl;
  754. mutex_lock(&ipa3_ctx->lock);
  755. if (ipa3_ctx->hdr_proc_ctx_tbl_lcl)
  756. pr_info("Table resides on local memory\n");
  757. else
  758. pr_info("Table resides on system(ddr) memory\n");
  759. list_for_each_entry(entry, &tbl->head_proc_ctx_entry_list, link) {
  760. ofst_words = (entry->offset_entry->offset +
  761. ipa3_ctx->hdr_proc_ctx_tbl.start_offset)
  762. >> 5;
  763. if (entry->hdr->is_hdr_proc_ctx) {
  764. nbytes += scnprintf(dbg_buff + nbytes,
  765. IPA_MAX_MSG_LEN - nbytes,
  766. "id:%u hdr_proc_type:%s proc_ctx[32B]:%u ",
  767. entry->id,
  768. ipa3_hdr_proc_type_name[entry->type],
  769. ofst_words);
  770. nbytes += scnprintf(dbg_buff + nbytes,
  771. IPA_MAX_MSG_LEN - nbytes,
  772. "hdr_phys_base:0x%pa\n",
  773. &entry->hdr->phys_base);
  774. } else {
  775. nbytes += scnprintf(dbg_buff + nbytes,
  776. IPA_MAX_MSG_LEN - nbytes,
  777. "id:%u hdr_proc_type:%s proc_ctx[32B]:%u ",
  778. entry->id,
  779. ipa3_hdr_proc_type_name[entry->type],
  780. ofst_words);
  781. nbytes += scnprintf(dbg_buff + nbytes,
  782. IPA_MAX_MSG_LEN - nbytes,
  783. "hdr[words]:%u\n",
  784. entry->hdr->offset_entry->offset >> 2);
  785. }
  786. }
  787. mutex_unlock(&ipa3_ctx->lock);
  788. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, nbytes);
  789. }
  790. static ssize_t ipa3_read_flt(struct file *file, char __user *ubuf, size_t count,
  791. loff_t *ppos)
  792. {
  793. int i;
  794. int j;
  795. struct ipa3_flt_tbl *tbl;
  796. struct ipa3_flt_entry *entry;
  797. enum ipa_ip_type ip = (enum ipa_ip_type)file->private_data;
  798. struct ipa3_rt_tbl *rt_tbl;
  799. u32 rt_tbl_idx;
  800. u32 bitmap;
  801. bool eq;
  802. int res = 0;
  803. mutex_lock(&ipa3_ctx->lock);
  804. for (j = 0; j < ipa3_ctx->ipa_num_pipes; j++) {
  805. if (!ipa_is_ep_support_flt(j))
  806. continue;
  807. tbl = &ipa3_ctx->flt_tbl[j][ip];
  808. i = 0;
  809. list_for_each_entry(entry, &tbl->head_flt_rule_list, link) {
  810. if (entry->cookie != IPA_FLT_COOKIE)
  811. continue;
  812. if (entry->rule.eq_attrib_type) {
  813. rt_tbl_idx = entry->rule.rt_tbl_idx;
  814. bitmap = entry->rule.eq_attrib.rule_eq_bitmap;
  815. eq = true;
  816. } else {
  817. rt_tbl = ipa3_id_find(entry->rule.rt_tbl_hdl);
  818. if (rt_tbl == NULL ||
  819. rt_tbl->cookie != IPA_RT_TBL_COOKIE)
  820. rt_tbl_idx = ~0;
  821. else
  822. rt_tbl_idx = rt_tbl->idx;
  823. bitmap = entry->rule.attrib.attrib_mask;
  824. eq = false;
  825. }
  826. pr_err("ep_idx:%d rule_idx:%d act:%d rt_tbl_idx:%d ",
  827. j, i, entry->rule.action, rt_tbl_idx);
  828. pr_err("attrib_mask:%08x retain_hdr:%d eq:%d ",
  829. bitmap, entry->rule.retain_hdr, eq);
  830. pr_err("hashable:%u rule_id:%u max_prio:%u prio:%u ",
  831. entry->rule.hashable, entry->rule_id,
  832. entry->rule.max_prio, entry->prio);
  833. pr_err("enable_stats:%u counter_id:%u\n",
  834. entry->rule.enable_stats,
  835. entry->rule.cnt_idx);
  836. if (ipa3_ctx->ipa_hw_type >= IPA_HW_v4_0)
  837. pr_err("pdn index %d, set metadata %d ",
  838. entry->rule.pdn_idx,
  839. entry->rule.set_metadata);
  840. if (eq) {
  841. res = ipa3_attrib_dump_eq(
  842. &entry->rule.eq_attrib);
  843. if (res) {
  844. IPAERR_RL("failed read attrib eq\n");
  845. goto bail;
  846. }
  847. } else
  848. ipa3_attrib_dump(
  849. &entry->rule.attrib, ip);
  850. i++;
  851. }
  852. }
  853. bail:
  854. mutex_unlock(&ipa3_ctx->lock);
  855. return res;
  856. }
  857. static ssize_t ipa3_read_flt_hw(struct file *file, char __user *ubuf,
  858. size_t count, loff_t *ppos)
  859. {
  860. int pipe;
  861. int rl;
  862. int rules_num;
  863. struct ipahal_flt_rule_entry *rules;
  864. enum ipa_ip_type ip = (enum ipa_ip_type)file->private_data;
  865. u32 rt_tbl_idx;
  866. u32 bitmap;
  867. int res = 0;
  868. IPADBG("Tring to parse %d H/W filtering tables - IP=%d\n",
  869. ipa3_ctx->ep_flt_num, ip);
  870. rules = kzalloc(sizeof(*rules) * IPA_DBG_MAX_RULE_IN_TBL, GFP_KERNEL);
  871. if (!rules)
  872. return -ENOMEM;
  873. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  874. mutex_lock(&ipa3_ctx->lock);
  875. for (pipe = 0; pipe < ipa3_ctx->ipa_num_pipes; pipe++) {
  876. if (!ipa_is_ep_support_flt(pipe))
  877. continue;
  878. pr_err("=== Filtering Table ep:%d = Hashable Rules ===\n",
  879. pipe);
  880. rules_num = IPA_DBG_MAX_RULE_IN_TBL;
  881. res = ipa3_flt_read_tbl_from_hw(pipe, ip, true, rules,
  882. &rules_num);
  883. if (res) {
  884. pr_err("ERROR - Check the logs\n");
  885. IPAERR("failed reading tbl from hw\n");
  886. goto bail;
  887. }
  888. if (!rules_num)
  889. pr_err("-->No rules. Empty tbl or modem sys table\n");
  890. for (rl = 0; rl < rules_num; rl++) {
  891. rt_tbl_idx = rules[rl].rule.rt_tbl_idx;
  892. bitmap = rules[rl].rule.eq_attrib.rule_eq_bitmap;
  893. pr_err("ep_idx:%d rule_idx:%d act:%d rt_tbl_idx:%d ",
  894. pipe, rl, rules[rl].rule.action, rt_tbl_idx);
  895. pr_err("attrib_mask:%08x retain_hdr:%d ",
  896. bitmap, rules[rl].rule.retain_hdr);
  897. pr_err("rule_id:%u cnt_id:%hhu prio:%u\n",
  898. rules[rl].id, rules[rl].cnt_idx,
  899. rules[rl].priority);
  900. if (ipa3_ctx->ipa_hw_type >= IPA_HW_v4_0)
  901. pr_err("pdn: %u, set_metadata: %u ",
  902. rules[rl].rule.pdn_idx,
  903. rules[rl].rule.set_metadata);
  904. res = ipa3_attrib_dump_eq(&rules[rl].rule.eq_attrib);
  905. if (res) {
  906. IPAERR_RL("failed read attrib eq\n");
  907. goto bail;
  908. }
  909. }
  910. pr_err("=== Filtering Table ep:%d = Non-Hashable Rules ===\n",
  911. pipe);
  912. rules_num = IPA_DBG_MAX_RULE_IN_TBL;
  913. res = ipa3_flt_read_tbl_from_hw(pipe, ip, false, rules,
  914. &rules_num);
  915. if (res) {
  916. IPAERR("failed reading tbl from hw\n");
  917. goto bail;
  918. }
  919. if (!rules_num)
  920. pr_err("-->No rules. Empty tbl or modem sys table\n");
  921. for (rl = 0; rl < rules_num; rl++) {
  922. rt_tbl_idx = rules[rl].rule.rt_tbl_idx;
  923. bitmap = rules[rl].rule.eq_attrib.rule_eq_bitmap;
  924. pr_err("ep_idx:%d rule_idx:%d act:%d rt_tbl_idx:%d ",
  925. pipe, rl, rules[rl].rule.action, rt_tbl_idx);
  926. pr_err("attrib_mask:%08x retain_hdr:%d ",
  927. bitmap, rules[rl].rule.retain_hdr);
  928. pr_err("rule_id:%u cnt_id:%hhu prio:%u\n",
  929. rules[rl].id, rules[rl].cnt_idx,
  930. rules[rl].priority);
  931. if (ipa3_ctx->ipa_hw_type >= IPA_HW_v4_0)
  932. pr_err("pdn: %u, set_metadata: %u ",
  933. rules[rl].rule.pdn_idx,
  934. rules[rl].rule.set_metadata);
  935. res = ipa3_attrib_dump_eq(&rules[rl].rule.eq_attrib);
  936. if (res) {
  937. IPAERR_RL("failed read attrib eq\n");
  938. goto bail;
  939. }
  940. }
  941. pr_err("\n");
  942. }
  943. bail:
  944. mutex_unlock(&ipa3_ctx->lock);
  945. kfree(rules);
  946. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  947. return res;
  948. }
  949. static ssize_t ipa3_read_stats(struct file *file, char __user *ubuf,
  950. size_t count, loff_t *ppos)
  951. {
  952. int nbytes;
  953. int i;
  954. int cnt = 0;
  955. uint connect = 0;
  956. for (i = 0; i < ipa3_ctx->ipa_num_pipes; i++)
  957. connect |= (ipa3_ctx->ep[i].valid << i);
  958. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  959. "sw_tx=%u\n"
  960. "hw_tx=%u\n"
  961. "tx_non_linear=%u\n"
  962. "tx_compl=%u\n"
  963. "wan_rx=%u\n"
  964. "stat_compl=%u\n"
  965. "lan_aggr_close=%u\n"
  966. "wan_aggr_close=%u\n"
  967. "act_clnt=%u\n"
  968. "con_clnt_bmap=0x%x\n"
  969. "wan_rx_empty=%u\n"
  970. "wan_repl_rx_empty=%u\n"
  971. "lan_rx_empty=%u\n"
  972. "lan_repl_rx_empty=%u\n"
  973. "flow_enable=%u\n"
  974. "flow_disable=%u\n",
  975. ipa3_ctx->stats.tx_sw_pkts,
  976. ipa3_ctx->stats.tx_hw_pkts,
  977. ipa3_ctx->stats.tx_non_linear,
  978. ipa3_ctx->stats.tx_pkts_compl,
  979. ipa3_ctx->stats.rx_pkts,
  980. ipa3_ctx->stats.stat_compl,
  981. ipa3_ctx->stats.aggr_close,
  982. ipa3_ctx->stats.wan_aggr_close,
  983. atomic_read(&ipa3_ctx->ipa3_active_clients.cnt),
  984. connect,
  985. ipa3_ctx->stats.wan_rx_empty,
  986. ipa3_ctx->stats.wan_repl_rx_empty,
  987. ipa3_ctx->stats.lan_rx_empty,
  988. ipa3_ctx->stats.lan_repl_rx_empty,
  989. ipa3_ctx->stats.flow_enable,
  990. ipa3_ctx->stats.flow_disable);
  991. cnt += nbytes;
  992. for (i = 0; i < IPAHAL_PKT_STATUS_EXCEPTION_MAX; i++) {
  993. nbytes = scnprintf(dbg_buff + cnt,
  994. IPA_MAX_MSG_LEN - cnt,
  995. "lan_rx_excp[%u:%20s]=%u\n", i,
  996. ipahal_pkt_status_exception_str(i),
  997. ipa3_ctx->stats.rx_excp_pkts[i]);
  998. cnt += nbytes;
  999. }
  1000. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, cnt);
  1001. }
  1002. static ssize_t ipa3_read_odlstats(struct file *file, char __user *ubuf,
  1003. size_t count, loff_t *ppos)
  1004. {
  1005. int nbytes;
  1006. int cnt = 0;
  1007. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1008. "ODL received pkt =%u\n"
  1009. "ODL processed pkt to DIAG=%u\n"
  1010. "ODL dropped pkt =%u\n"
  1011. "ODL packet in queue =%u\n",
  1012. ipa3_odl_ctx->stats.odl_rx_pkt,
  1013. ipa3_odl_ctx->stats.odl_tx_diag_pkt,
  1014. ipa3_odl_ctx->stats.odl_drop_pkt,
  1015. atomic_read(&ipa3_odl_ctx->stats.numer_in_queue));
  1016. cnt += nbytes;
  1017. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, cnt);
  1018. }
  1019. static ssize_t ipa3_read_wstats(struct file *file, char __user *ubuf,
  1020. size_t count, loff_t *ppos)
  1021. {
  1022. #define HEAD_FRMT_STR "%25s\n"
  1023. #define FRMT_STR "%25s %10u\n"
  1024. #define FRMT_STR1 "%25s %10u\n\n"
  1025. int cnt = 0;
  1026. int nbytes;
  1027. int ipa_ep_idx;
  1028. enum ipa_client_type client = IPA_CLIENT_WLAN1_PROD;
  1029. struct ipa3_ep_context *ep;
  1030. do {
  1031. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1032. HEAD_FRMT_STR, "Client IPA_CLIENT_WLAN1_PROD Stats:");
  1033. cnt += nbytes;
  1034. ipa_ep_idx = ipa3_get_ep_mapping(client);
  1035. if (ipa_ep_idx == -1) {
  1036. nbytes = scnprintf(dbg_buff + cnt,
  1037. IPA_MAX_MSG_LEN - cnt, HEAD_FRMT_STR, "Not up");
  1038. cnt += nbytes;
  1039. break;
  1040. }
  1041. ep = &ipa3_ctx->ep[ipa_ep_idx];
  1042. if (ep->valid != 1) {
  1043. nbytes = scnprintf(dbg_buff + cnt,
  1044. IPA_MAX_MSG_LEN - cnt, HEAD_FRMT_STR, "Not up");
  1045. cnt += nbytes;
  1046. break;
  1047. }
  1048. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1049. FRMT_STR, "Avail Fifo Desc:",
  1050. atomic_read(&ep->avail_fifo_desc));
  1051. cnt += nbytes;
  1052. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1053. FRMT_STR, "Rx Pkts Rcvd:", ep->wstats.rx_pkts_rcvd);
  1054. cnt += nbytes;
  1055. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1056. FRMT_STR, "Rx Pkts Status Rcvd:",
  1057. ep->wstats.rx_pkts_status_rcvd);
  1058. cnt += nbytes;
  1059. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1060. FRMT_STR, "Rx DH Rcvd:", ep->wstats.rx_hd_rcvd);
  1061. cnt += nbytes;
  1062. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1063. FRMT_STR, "Rx DH Processed:",
  1064. ep->wstats.rx_hd_processed);
  1065. cnt += nbytes;
  1066. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1067. FRMT_STR, "Rx DH Sent Back:", ep->wstats.rx_hd_reply);
  1068. cnt += nbytes;
  1069. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1070. FRMT_STR, "Rx Pkt Leak:", ep->wstats.rx_pkt_leak);
  1071. cnt += nbytes;
  1072. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1073. FRMT_STR1, "Rx DP Fail:", ep->wstats.rx_dp_fail);
  1074. cnt += nbytes;
  1075. } while (0);
  1076. client = IPA_CLIENT_WLAN1_CONS;
  1077. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt, HEAD_FRMT_STR,
  1078. "Client IPA_CLIENT_WLAN1_CONS Stats:");
  1079. cnt += nbytes;
  1080. while (1) {
  1081. ipa_ep_idx = ipa3_get_ep_mapping(client);
  1082. if (ipa_ep_idx == -1) {
  1083. nbytes = scnprintf(dbg_buff + cnt,
  1084. IPA_MAX_MSG_LEN - cnt, HEAD_FRMT_STR, "Not up");
  1085. cnt += nbytes;
  1086. goto nxt_clnt_cons;
  1087. }
  1088. ep = &ipa3_ctx->ep[ipa_ep_idx];
  1089. if (ep->valid != 1) {
  1090. nbytes = scnprintf(dbg_buff + cnt,
  1091. IPA_MAX_MSG_LEN - cnt, HEAD_FRMT_STR, "Not up");
  1092. cnt += nbytes;
  1093. goto nxt_clnt_cons;
  1094. }
  1095. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1096. FRMT_STR, "Tx Pkts Received:", ep->wstats.tx_pkts_rcvd);
  1097. cnt += nbytes;
  1098. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1099. FRMT_STR, "Tx Pkts Sent:", ep->wstats.tx_pkts_sent);
  1100. cnt += nbytes;
  1101. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1102. FRMT_STR1, "Tx Pkts Dropped:",
  1103. ep->wstats.tx_pkts_dropped);
  1104. cnt += nbytes;
  1105. nxt_clnt_cons:
  1106. switch (client) {
  1107. case IPA_CLIENT_WLAN1_CONS:
  1108. client = IPA_CLIENT_WLAN2_CONS;
  1109. nbytes = scnprintf(dbg_buff + cnt,
  1110. IPA_MAX_MSG_LEN - cnt, HEAD_FRMT_STR,
  1111. "Client IPA_CLIENT_WLAN2_CONS Stats:");
  1112. cnt += nbytes;
  1113. continue;
  1114. case IPA_CLIENT_WLAN2_CONS:
  1115. client = IPA_CLIENT_WLAN3_CONS;
  1116. nbytes = scnprintf(dbg_buff + cnt,
  1117. IPA_MAX_MSG_LEN - cnt, HEAD_FRMT_STR,
  1118. "Client IPA_CLIENT_WLAN3_CONS Stats:");
  1119. cnt += nbytes;
  1120. continue;
  1121. case IPA_CLIENT_WLAN3_CONS:
  1122. client = IPA_CLIENT_WLAN4_CONS;
  1123. nbytes = scnprintf(dbg_buff + cnt,
  1124. IPA_MAX_MSG_LEN - cnt, HEAD_FRMT_STR,
  1125. "Client IPA_CLIENT_WLAN4_CONS Stats:");
  1126. cnt += nbytes;
  1127. continue;
  1128. case IPA_CLIENT_WLAN4_CONS:
  1129. default:
  1130. break;
  1131. }
  1132. break;
  1133. }
  1134. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1135. "\n"HEAD_FRMT_STR, "All Wlan Consumer pipes stats:");
  1136. cnt += nbytes;
  1137. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt, FRMT_STR,
  1138. "Tx Comm Buff Allocated:",
  1139. ipa3_ctx->wc_memb.wlan_comm_total_cnt);
  1140. cnt += nbytes;
  1141. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt, FRMT_STR,
  1142. "Tx Comm Buff Avail:", ipa3_ctx->wc_memb.wlan_comm_free_cnt);
  1143. cnt += nbytes;
  1144. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt, FRMT_STR1,
  1145. "Total Tx Pkts Freed:", ipa3_ctx->wc_memb.total_tx_pkts_freed);
  1146. cnt += nbytes;
  1147. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, cnt);
  1148. }
  1149. static ssize_t ipa3_read_ntn(struct file *file, char __user *ubuf,
  1150. size_t count, loff_t *ppos)
  1151. {
  1152. #define TX_STATS(y) \
  1153. ipa3_ctx->uc_ntn_ctx.ntn_uc_stats_mmio->tx_ch_stats[0].y
  1154. #define RX_STATS(y) \
  1155. ipa3_ctx->uc_ntn_ctx.ntn_uc_stats_mmio->rx_ch_stats[0].y
  1156. struct Ipa3HwStatsNTNInfoData_t stats;
  1157. int nbytes;
  1158. int cnt = 0;
  1159. if (!ipa3_get_ntn_stats(&stats)) {
  1160. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1161. "TX num_pkts_processed=%u\n"
  1162. "TX ringFull=%u\n"
  1163. "TX ringEmpty=%u\n"
  1164. "TX ringUsageHigh=%u\n"
  1165. "TX ringUsageLow=%u\n"
  1166. "TX RingUtilCount=%u\n"
  1167. "TX bamFifoFull=%u\n"
  1168. "TX bamFifoEmpty=%u\n"
  1169. "TX bamFifoUsageHigh=%u\n"
  1170. "TX bamFifoUsageLow=%u\n"
  1171. "TX bamUtilCount=%u\n"
  1172. "TX num_db=%u\n"
  1173. "TX num_qmb_int_handled=%u\n"
  1174. "TX ipa_pipe_number=%u\n",
  1175. TX_STATS(num_pkts_processed),
  1176. TX_STATS(ring_stats.ringFull),
  1177. TX_STATS(ring_stats.ringEmpty),
  1178. TX_STATS(ring_stats.ringUsageHigh),
  1179. TX_STATS(ring_stats.ringUsageLow),
  1180. TX_STATS(ring_stats.RingUtilCount),
  1181. TX_STATS(gsi_stats.bamFifoFull),
  1182. TX_STATS(gsi_stats.bamFifoEmpty),
  1183. TX_STATS(gsi_stats.bamFifoUsageHigh),
  1184. TX_STATS(gsi_stats.bamFifoUsageLow),
  1185. TX_STATS(gsi_stats.bamUtilCount),
  1186. TX_STATS(num_db),
  1187. TX_STATS(num_qmb_int_handled),
  1188. TX_STATS(ipa_pipe_number));
  1189. cnt += nbytes;
  1190. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1191. "RX num_pkts_processed=%u\n"
  1192. "RX ringFull=%u\n"
  1193. "RX ringEmpty=%u\n"
  1194. "RX ringUsageHigh=%u\n"
  1195. "RX ringUsageLow=%u\n"
  1196. "RX RingUtilCount=%u\n"
  1197. "RX bamFifoFull=%u\n"
  1198. "RX bamFifoEmpty=%u\n"
  1199. "RX bamFifoUsageHigh=%u\n"
  1200. "RX bamFifoUsageLow=%u\n"
  1201. "RX bamUtilCount=%u\n"
  1202. "RX num_db=%u\n"
  1203. "RX num_qmb_int_handled=%u\n"
  1204. "RX ipa_pipe_number=%u\n",
  1205. RX_STATS(num_pkts_processed),
  1206. RX_STATS(ring_stats.ringFull),
  1207. RX_STATS(ring_stats.ringEmpty),
  1208. RX_STATS(ring_stats.ringUsageHigh),
  1209. RX_STATS(ring_stats.ringUsageLow),
  1210. RX_STATS(ring_stats.RingUtilCount),
  1211. RX_STATS(gsi_stats.bamFifoFull),
  1212. RX_STATS(gsi_stats.bamFifoEmpty),
  1213. RX_STATS(gsi_stats.bamFifoUsageHigh),
  1214. RX_STATS(gsi_stats.bamFifoUsageLow),
  1215. RX_STATS(gsi_stats.bamUtilCount),
  1216. RX_STATS(num_db),
  1217. RX_STATS(num_qmb_int_handled),
  1218. RX_STATS(ipa_pipe_number));
  1219. cnt += nbytes;
  1220. } else {
  1221. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1222. "Fail to read NTN stats\n");
  1223. cnt += nbytes;
  1224. }
  1225. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, cnt);
  1226. }
  1227. static ssize_t ipa3_read_wdi(struct file *file, char __user *ubuf,
  1228. size_t count, loff_t *ppos)
  1229. {
  1230. struct IpaHwStatsWDIInfoData_t stats;
  1231. int nbytes;
  1232. int cnt = 0;
  1233. struct IpaHwStatsWDITxInfoData_t *tx_ch_ptr;
  1234. if (!ipa3_get_wdi_stats(&stats)) {
  1235. tx_ch_ptr = &stats.tx_ch_stats;
  1236. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1237. "TX num_pkts_processed=%u\n"
  1238. "TX copy_engine_doorbell_value=%u\n"
  1239. "TX num_db_fired=%u\n"
  1240. "TX ringFull=%u\n"
  1241. "TX ringEmpty=%u\n"
  1242. "TX ringUsageHigh=%u\n"
  1243. "TX ringUsageLow=%u\n"
  1244. "TX RingUtilCount=%u\n"
  1245. "TX bamFifoFull=%u\n"
  1246. "TX bamFifoEmpty=%u\n"
  1247. "TX bamFifoUsageHigh=%u\n"
  1248. "TX bamFifoUsageLow=%u\n"
  1249. "TX bamUtilCount=%u\n"
  1250. "TX num_db=%u\n"
  1251. "TX num_unexpected_db=%u\n"
  1252. "TX num_bam_int_handled=%u\n"
  1253. "TX num_bam_int_in_non_running_state=%u\n"
  1254. "TX num_qmb_int_handled=%u\n"
  1255. "TX num_bam_int_handled_while_wait_for_bam=%u\n",
  1256. tx_ch_ptr->num_pkts_processed,
  1257. tx_ch_ptr->copy_engine_doorbell_value,
  1258. tx_ch_ptr->num_db_fired,
  1259. tx_ch_ptr->tx_comp_ring_stats.ringFull,
  1260. tx_ch_ptr->tx_comp_ring_stats.ringEmpty,
  1261. tx_ch_ptr->tx_comp_ring_stats.ringUsageHigh,
  1262. tx_ch_ptr->tx_comp_ring_stats.ringUsageLow,
  1263. tx_ch_ptr->tx_comp_ring_stats.RingUtilCount,
  1264. tx_ch_ptr->bam_stats.bamFifoFull,
  1265. tx_ch_ptr->bam_stats.bamFifoEmpty,
  1266. tx_ch_ptr->bam_stats.bamFifoUsageHigh,
  1267. tx_ch_ptr->bam_stats.bamFifoUsageLow,
  1268. tx_ch_ptr->bam_stats.bamUtilCount,
  1269. tx_ch_ptr->num_db,
  1270. tx_ch_ptr->num_unexpected_db,
  1271. tx_ch_ptr->num_bam_int_handled,
  1272. tx_ch_ptr->num_bam_int_in_non_running_state,
  1273. tx_ch_ptr->num_qmb_int_handled,
  1274. tx_ch_ptr->num_bam_int_handled_while_wait_for_bam);
  1275. cnt += nbytes;
  1276. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1277. "RX max_outstanding_pkts=%u\n"
  1278. "RX num_pkts_processed=%u\n"
  1279. "RX rx_ring_rp_value=%u\n"
  1280. "RX ringFull=%u\n"
  1281. "RX ringEmpty=%u\n"
  1282. "RX ringUsageHigh=%u\n"
  1283. "RX ringUsageLow=%u\n"
  1284. "RX RingUtilCount=%u\n"
  1285. "RX bamFifoFull=%u\n"
  1286. "RX bamFifoEmpty=%u\n"
  1287. "RX bamFifoUsageHigh=%u\n"
  1288. "RX bamFifoUsageLow=%u\n"
  1289. "RX bamUtilCount=%u\n"
  1290. "RX num_bam_int_handled=%u\n"
  1291. "RX num_db=%u\n"
  1292. "RX num_unexpected_db=%u\n"
  1293. "RX num_pkts_in_dis_uninit_state=%u\n"
  1294. "RX num_ic_inj_vdev_change=%u\n"
  1295. "RX num_ic_inj_fw_desc_change=%u\n"
  1296. "RX num_qmb_int_handled=%u\n"
  1297. "RX reserved1=%u\n"
  1298. "RX reserved2=%u\n",
  1299. stats.rx_ch_stats.max_outstanding_pkts,
  1300. stats.rx_ch_stats.num_pkts_processed,
  1301. stats.rx_ch_stats.rx_ring_rp_value,
  1302. stats.rx_ch_stats.rx_ind_ring_stats.ringFull,
  1303. stats.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
  1304. stats.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
  1305. stats.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
  1306. stats.rx_ch_stats.rx_ind_ring_stats.RingUtilCount,
  1307. stats.rx_ch_stats.bam_stats.bamFifoFull,
  1308. stats.rx_ch_stats.bam_stats.bamFifoEmpty,
  1309. stats.rx_ch_stats.bam_stats.bamFifoUsageHigh,
  1310. stats.rx_ch_stats.bam_stats.bamFifoUsageLow,
  1311. stats.rx_ch_stats.bam_stats.bamUtilCount,
  1312. stats.rx_ch_stats.num_bam_int_handled,
  1313. stats.rx_ch_stats.num_db,
  1314. stats.rx_ch_stats.num_unexpected_db,
  1315. stats.rx_ch_stats.num_pkts_in_dis_uninit_state,
  1316. stats.rx_ch_stats.num_ic_inj_vdev_change,
  1317. stats.rx_ch_stats.num_ic_inj_fw_desc_change,
  1318. stats.rx_ch_stats.num_qmb_int_handled,
  1319. stats.rx_ch_stats.reserved1,
  1320. stats.rx_ch_stats.reserved2);
  1321. cnt += nbytes;
  1322. } else {
  1323. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1324. "Fail to read WDI stats\n");
  1325. cnt += nbytes;
  1326. }
  1327. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, cnt);
  1328. }
  1329. static ssize_t ipa3_write_dbg_cnt(struct file *file, const char __user *buf,
  1330. size_t count, loff_t *ppos)
  1331. {
  1332. u32 option = 0;
  1333. struct ipahal_reg_debug_cnt_ctrl dbg_cnt_ctrl;
  1334. int ret;
  1335. if (ipa3_ctx->ipa_hw_type >= IPA_HW_v4_0) {
  1336. IPAERR("IPA_DEBUG_CNT_CTRL is not supported in IPA 4.0\n");
  1337. return -EPERM;
  1338. }
  1339. ret = kstrtou32_from_user(buf, count, 0, &option);
  1340. if (ret)
  1341. return ret;
  1342. memset(&dbg_cnt_ctrl, 0, sizeof(dbg_cnt_ctrl));
  1343. dbg_cnt_ctrl.type = DBG_CNT_TYPE_GENERAL;
  1344. dbg_cnt_ctrl.product = true;
  1345. dbg_cnt_ctrl.src_pipe = 0xff;
  1346. dbg_cnt_ctrl.rule_idx_pipe_rule = false;
  1347. dbg_cnt_ctrl.rule_idx = 0;
  1348. if (option == 1)
  1349. dbg_cnt_ctrl.en = true;
  1350. else
  1351. dbg_cnt_ctrl.en = false;
  1352. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  1353. ipahal_write_reg_n_fields(IPA_DEBUG_CNT_CTRL_n, 0, &dbg_cnt_ctrl);
  1354. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  1355. return count;
  1356. }
  1357. static ssize_t ipa3_read_dbg_cnt(struct file *file, char __user *ubuf,
  1358. size_t count, loff_t *ppos)
  1359. {
  1360. int nbytes;
  1361. u32 regval;
  1362. if (ipa3_ctx->ipa_hw_type >= IPA_HW_v4_0) {
  1363. IPAERR("IPA_DEBUG_CNT_REG is not supported in IPA 4.0\n");
  1364. return -EPERM;
  1365. }
  1366. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  1367. regval =
  1368. ipahal_read_reg_n(IPA_DEBUG_CNT_REG_n, 0);
  1369. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1370. "IPA_DEBUG_CNT_REG_0=0x%x\n", regval);
  1371. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  1372. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, nbytes);
  1373. }
  1374. static ssize_t ipa3_read_msg(struct file *file, char __user *ubuf,
  1375. size_t count, loff_t *ppos)
  1376. {
  1377. int nbytes;
  1378. int cnt = 0;
  1379. int i;
  1380. for (i = 0; i < ARRAY_SIZE(ipa3_event_name); i++) {
  1381. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1382. "msg[%u:%27s] W:%u R:%u\n", i,
  1383. ipa3_event_name[i],
  1384. ipa3_ctx->stats.msg_w[i],
  1385. ipa3_ctx->stats.msg_r[i]);
  1386. cnt += nbytes;
  1387. }
  1388. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, cnt);
  1389. }
  1390. static void ipa3_read_table(
  1391. char *table_addr, u32 table_size,
  1392. u32 *total_num_entries,
  1393. u32 *rule_id,
  1394. enum ipahal_nat_type nat_type)
  1395. {
  1396. int result;
  1397. char *entry;
  1398. size_t entry_size;
  1399. bool entry_zeroed;
  1400. bool entry_valid;
  1401. u32 i, num_entries = 0, id = *rule_id;
  1402. char *buff;
  1403. size_t buff_size = 2 * IPA_MAX_ENTRY_STRING_LEN;
  1404. IPADBG("\n");
  1405. if (table_addr == NULL) {
  1406. pr_err("NULL NAT table\n");
  1407. return;
  1408. }
  1409. result = ipahal_nat_entry_size(nat_type, &entry_size);
  1410. if (result) {
  1411. IPAERR("Failed to retrieve size of %s entry\n",
  1412. ipahal_nat_type_str(nat_type));
  1413. return;
  1414. }
  1415. buff = kzalloc(buff_size, GFP_KERNEL);
  1416. if (!buff) {
  1417. IPAERR("Out of memory\n");
  1418. return;
  1419. }
  1420. for (i = 0, entry = table_addr;
  1421. i < table_size;
  1422. ++i, ++id, entry += entry_size) {
  1423. result = ipahal_nat_is_entry_zeroed(nat_type, entry,
  1424. &entry_zeroed);
  1425. if (result) {
  1426. IPAERR(
  1427. "Failed to determine whether the %s entry is definitely zero\n"
  1428. , ipahal_nat_type_str(nat_type));
  1429. goto bail;
  1430. }
  1431. if (entry_zeroed)
  1432. continue;
  1433. result = ipahal_nat_is_entry_valid(nat_type, entry,
  1434. &entry_valid);
  1435. if (result) {
  1436. IPAERR(
  1437. "Failed to determine whether the %s entry is valid\n"
  1438. , ipahal_nat_type_str(nat_type));
  1439. goto bail;
  1440. }
  1441. if (entry_valid) {
  1442. ++num_entries;
  1443. pr_err("\tEntry_Index=%d\n", id);
  1444. } else
  1445. pr_err("\tEntry_Index=%d - Invalid Entry\n", id);
  1446. ipahal_nat_stringify_entry(nat_type, entry,
  1447. buff, buff_size);
  1448. pr_err("%s\n", buff);
  1449. memset(buff, 0, buff_size);
  1450. }
  1451. if (num_entries)
  1452. pr_err("\n");
  1453. else
  1454. pr_err("\tEmpty\n\n");
  1455. IPADBG("return\n");
  1456. bail:
  1457. kfree(buff);
  1458. *rule_id = id;
  1459. *total_num_entries += num_entries;
  1460. }
  1461. static void ipa3_start_read_memory_device(
  1462. struct ipa3_nat_ipv6ct_common_mem *dev,
  1463. enum ipahal_nat_type nat_type,
  1464. u32 *num_entries)
  1465. {
  1466. u32 rule_id = 0;
  1467. IPADBG("\n");
  1468. pr_err("%s_Table_Size=%d\n",
  1469. dev->name, dev->table_entries + 1);
  1470. pr_err("%s_Expansion_Table_Size=%d\n",
  1471. dev->name, dev->expn_table_entries);
  1472. if (!dev->is_sys_mem)
  1473. pr_err("Not supported for local(shared) memory\n");
  1474. pr_err("\n%s Base Table:\n", dev->name);
  1475. ipa3_read_table(dev->base_table_addr, dev->table_entries + 1,
  1476. num_entries, &rule_id, nat_type);
  1477. pr_err("%s Expansion Table:\n", dev->name);
  1478. ipa3_read_table(
  1479. dev->expansion_table_addr, dev->expn_table_entries,
  1480. num_entries,
  1481. &rule_id,
  1482. nat_type);
  1483. IPADBG("return\n");
  1484. }
  1485. static void ipa3_finish_read_memory_device(
  1486. struct ipa3_nat_ipv6ct_common_mem *dev,
  1487. u32 num_entries)
  1488. {
  1489. IPADBG("\n");
  1490. pr_err("Overall number %s entries: %d\n\n", dev->name, num_entries);
  1491. IPADBG("return\n");
  1492. }
  1493. static void ipa3_read_pdn_table(void)
  1494. {
  1495. int i, result;
  1496. char *pdn_entry;
  1497. size_t pdn_entry_size;
  1498. bool entry_zeroed;
  1499. bool entry_valid;
  1500. char *buff;
  1501. size_t buff_size = 128;
  1502. IPADBG("\n");
  1503. result = ipahal_nat_entry_size(IPAHAL_NAT_IPV4_PDN, &pdn_entry_size);
  1504. if (result) {
  1505. IPAERR("Failed to retrieve size of PDN entry");
  1506. return;
  1507. }
  1508. buff = kzalloc(buff_size, GFP_KERNEL);
  1509. if (!buff) {
  1510. IPAERR("Out of memory\n");
  1511. return;
  1512. }
  1513. for (i = 0, pdn_entry = ipa3_ctx->nat_mem.pdn_mem.base;
  1514. i < IPA_MAX_PDN_NUM;
  1515. ++i, pdn_entry += pdn_entry_size) {
  1516. result = ipahal_nat_is_entry_zeroed(IPAHAL_NAT_IPV4_PDN,
  1517. pdn_entry, &entry_zeroed);
  1518. if (result) {
  1519. IPAERR(
  1520. "Failed to determine whether the PDN entry is definitely zero\n");
  1521. goto bail;
  1522. }
  1523. if (entry_zeroed)
  1524. continue;
  1525. result = ipahal_nat_is_entry_valid(IPAHAL_NAT_IPV4_PDN,
  1526. pdn_entry, &entry_valid);
  1527. if (result) {
  1528. IPAERR(
  1529. "Failed to determine whether the PDN entry is valid\n");
  1530. goto bail;
  1531. }
  1532. if (entry_valid)
  1533. pr_err("PDN %d:\n", i);
  1534. else
  1535. pr_err("PDN %d - Invalid:\n", i);
  1536. ipahal_nat_stringify_entry(IPAHAL_NAT_IPV4_PDN,
  1537. pdn_entry, buff, buff_size);
  1538. pr_err("%s\n", buff);
  1539. memset(buff, 0, buff_size);
  1540. }
  1541. pr_err("\n");
  1542. bail:
  1543. kfree(buff);
  1544. IPADBG("return\n");
  1545. }
  1546. static ssize_t ipa3_read_nat4(struct file *file,
  1547. char __user *ubuf, size_t count,
  1548. loff_t *ppos)
  1549. {
  1550. u32 rule_id = 0, num_entries = 0, index_num_entries = 0;
  1551. pr_err("IPA3 NAT stats\n");
  1552. if (!ipa3_ctx->nat_mem.dev.is_dev_init) {
  1553. pr_err("NAT hasn't been initialized or not supported\n");
  1554. goto ret;
  1555. }
  1556. mutex_lock(&ipa3_ctx->nat_mem.dev.lock);
  1557. if (!ipa3_ctx->nat_mem.dev.is_hw_init) {
  1558. pr_err("NAT H/W hasn't been initialized\n");
  1559. goto bail;
  1560. }
  1561. if (ipa3_ctx->ipa_hw_type >= IPA_HW_v4_0) {
  1562. ipa3_read_pdn_table();
  1563. } else {
  1564. pr_err("NAT Table IP Address=%pI4h\n\n",
  1565. &ipa3_ctx->nat_mem.public_ip_addr);
  1566. }
  1567. ipa3_start_read_memory_device(&ipa3_ctx->nat_mem.dev,
  1568. IPAHAL_NAT_IPV4, &num_entries);
  1569. /* Print Index tables */
  1570. pr_err("ipaNatTable Index Table:\n");
  1571. ipa3_read_table(
  1572. ipa3_ctx->nat_mem.index_table_addr,
  1573. ipa3_ctx->nat_mem.dev.table_entries + 1,
  1574. &index_num_entries,
  1575. &rule_id,
  1576. IPAHAL_NAT_IPV4_INDEX);
  1577. pr_err("ipaNatTable Expansion Index Table:\n");
  1578. ipa3_read_table(
  1579. ipa3_ctx->nat_mem.index_table_expansion_addr,
  1580. ipa3_ctx->nat_mem.dev.expn_table_entries,
  1581. &index_num_entries,
  1582. &rule_id,
  1583. IPAHAL_NAT_IPV4_INDEX);
  1584. if (num_entries != index_num_entries)
  1585. IPAERR(
  1586. "The NAT table number of entries %d is different from index table number of entries %d\n",
  1587. num_entries, index_num_entries);
  1588. ipa3_finish_read_memory_device(&ipa3_ctx->nat_mem.dev, num_entries);
  1589. IPADBG("return\n");
  1590. bail:
  1591. mutex_unlock(&ipa3_ctx->nat_mem.dev.lock);
  1592. ret:
  1593. return 0;
  1594. }
  1595. static ssize_t ipa3_read_ipv6ct(struct file *file,
  1596. char __user *ubuf, size_t count,
  1597. loff_t *ppos)
  1598. {
  1599. u32 num_entries = 0;
  1600. pr_err("\n");
  1601. if (!ipa3_ctx->ipv6ct_mem.dev.is_dev_init) {
  1602. pr_err("IPv6 Conntrack not initialized or not supported\n");
  1603. return 0;
  1604. }
  1605. mutex_lock(&ipa3_ctx->ipv6ct_mem.dev.lock);
  1606. if (!ipa3_ctx->ipv6ct_mem.dev.is_hw_init) {
  1607. pr_err("IPv6 connection tracking H/W hasn't been initialized\n");
  1608. goto bail;
  1609. }
  1610. ipa3_start_read_memory_device(&ipa3_ctx->ipv6ct_mem.dev,
  1611. IPAHAL_NAT_IPV6CT, &num_entries);
  1612. ipa3_finish_read_memory_device(&ipa3_ctx->ipv6ct_mem.dev,
  1613. num_entries);
  1614. IPADBG("return\n");
  1615. bail:
  1616. mutex_unlock(&ipa3_ctx->ipv6ct_mem.dev.lock);
  1617. return 0;
  1618. }
  1619. static ssize_t ipa3_rm_read_stats(struct file *file, char __user *ubuf,
  1620. size_t count, loff_t *ppos)
  1621. {
  1622. int result, cnt = 0;
  1623. /* deprecate if IPA PM is used */
  1624. if (ipa3_ctx->use_ipa_pm) {
  1625. cnt += scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1626. "IPA RM is disabled\n");
  1627. goto ret;
  1628. }
  1629. result = ipa_rm_stat(dbg_buff, IPA_MAX_MSG_LEN);
  1630. if (result < 0) {
  1631. cnt += scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1632. "Error in printing RM stat %d\n", result);
  1633. goto ret;
  1634. }
  1635. cnt += result;
  1636. ret:
  1637. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, cnt);
  1638. }
  1639. static ssize_t ipa3_pm_read_stats(struct file *file, char __user *ubuf,
  1640. size_t count, loff_t *ppos)
  1641. {
  1642. int result, cnt = 0;
  1643. if (!ipa3_ctx->use_ipa_pm) {
  1644. cnt += scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1645. "IPA PM is disabled\n");
  1646. goto ret;
  1647. }
  1648. result = ipa_pm_stat(dbg_buff, IPA_MAX_MSG_LEN);
  1649. if (result < 0) {
  1650. cnt += scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1651. "Error in printing PM stat %d\n", result);
  1652. goto ret;
  1653. }
  1654. cnt += result;
  1655. ret:
  1656. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, cnt);
  1657. }
  1658. static ssize_t ipa3_pm_ex_read_stats(struct file *file, char __user *ubuf,
  1659. size_t count, loff_t *ppos)
  1660. {
  1661. int result, cnt = 0;
  1662. if (!ipa3_ctx->use_ipa_pm) {
  1663. cnt += scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1664. "IPA PM is disabled\n");
  1665. goto ret;
  1666. }
  1667. result = ipa_pm_exceptions_stat(dbg_buff, IPA_MAX_MSG_LEN);
  1668. if (result < 0) {
  1669. cnt += scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1670. "Error in printing PM stat %d\n", result);
  1671. goto ret;
  1672. }
  1673. cnt += result;
  1674. ret:
  1675. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, cnt);
  1676. }
  1677. static ssize_t ipa3_read_ipahal_regs(struct file *file, char __user *ubuf,
  1678. size_t count, loff_t *ppos)
  1679. {
  1680. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  1681. ipahal_print_all_regs(true);
  1682. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  1683. return 0;
  1684. }
  1685. static ssize_t ipa3_read_wdi_gsi_stats(struct file *file,
  1686. char __user *ubuf, size_t count, loff_t *ppos)
  1687. {
  1688. struct ipa3_uc_dbg_ring_stats stats;
  1689. int nbytes;
  1690. int cnt = 0;
  1691. if (ipa3_ctx->ipa_hw_type < IPA_HW_v4_5) {
  1692. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1693. "This feature only support on IPA4.5+\n");
  1694. cnt += nbytes;
  1695. goto done;
  1696. }
  1697. if (!ipa3_get_wdi_gsi_stats(&stats)) {
  1698. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1699. "TX ringFull=%u\n"
  1700. "TX ringEmpty=%u\n"
  1701. "TX ringUsageHigh=%u\n"
  1702. "TX ringUsageLow=%u\n"
  1703. "TX RingUtilCount=%u\n",
  1704. stats.ring[1].ringFull,
  1705. stats.ring[1].ringEmpty,
  1706. stats.ring[1].ringUsageHigh,
  1707. stats.ring[1].ringUsageLow,
  1708. stats.ring[1].RingUtilCount);
  1709. cnt += nbytes;
  1710. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1711. "RX ringFull=%u\n"
  1712. "RX ringEmpty=%u\n"
  1713. "RX ringUsageHigh=%u\n"
  1714. "RX ringUsageLow=%u\n"
  1715. "RX RingUtilCount=%u\n",
  1716. stats.ring[0].ringFull,
  1717. stats.ring[0].ringEmpty,
  1718. stats.ring[0].ringUsageHigh,
  1719. stats.ring[0].ringUsageLow,
  1720. stats.ring[0].RingUtilCount);
  1721. cnt += nbytes;
  1722. } else {
  1723. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1724. "Fail to read WDI GSI stats\n");
  1725. cnt += nbytes;
  1726. }
  1727. done:
  1728. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, cnt);
  1729. }
  1730. static ssize_t ipa3_read_wdi3_gsi_stats(struct file *file,
  1731. char __user *ubuf, size_t count, loff_t *ppos)
  1732. {
  1733. struct ipa3_uc_dbg_ring_stats stats;
  1734. int nbytes;
  1735. int cnt = 0;
  1736. if (ipa3_ctx->ipa_hw_type < IPA_HW_v4_5) {
  1737. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1738. "This feature only support on IPA4.5+\n");
  1739. cnt += nbytes;
  1740. goto done;
  1741. }
  1742. if (!ipa3_get_wdi3_gsi_stats(&stats)) {
  1743. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1744. "TX ringFull=%u\n"
  1745. "TX ringEmpty=%u\n"
  1746. "TX ringUsageHigh=%u\n"
  1747. "TX ringUsageLow=%u\n"
  1748. "TX RingUtilCount=%u\n",
  1749. stats.ring[1].ringFull,
  1750. stats.ring[1].ringEmpty,
  1751. stats.ring[1].ringUsageHigh,
  1752. stats.ring[1].ringUsageLow,
  1753. stats.ring[1].RingUtilCount);
  1754. cnt += nbytes;
  1755. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1756. "RX ringFull=%u\n"
  1757. "RX ringEmpty=%u\n"
  1758. "RX ringUsageHigh=%u\n"
  1759. "RX ringUsageLow=%u\n"
  1760. "RX RingUtilCount=%u\n",
  1761. stats.ring[0].ringFull,
  1762. stats.ring[0].ringEmpty,
  1763. stats.ring[0].ringUsageHigh,
  1764. stats.ring[0].ringUsageLow,
  1765. stats.ring[0].RingUtilCount);
  1766. cnt += nbytes;
  1767. } else {
  1768. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1769. "Fail to read WDI GSI stats\n");
  1770. cnt += nbytes;
  1771. }
  1772. done:
  1773. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, cnt);
  1774. }
  1775. static ssize_t ipa3_read_11ad_gsi_stats(struct file *file,
  1776. char __user *ubuf, size_t count, loff_t *ppos)
  1777. {
  1778. int nbytes;
  1779. int cnt = 0;
  1780. if (ipa3_ctx->ipa_hw_type < IPA_HW_v4_5) {
  1781. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1782. "This feature only support on IPA4.5+\n");
  1783. cnt += nbytes;
  1784. goto done;
  1785. }
  1786. return 0;
  1787. done:
  1788. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, cnt);
  1789. }
  1790. static ssize_t ipa3_read_aqc_gsi_stats(struct file *file,
  1791. char __user *ubuf, size_t count, loff_t *ppos)
  1792. {
  1793. int nbytes;
  1794. int cnt = 0;
  1795. if (ipa3_ctx->ipa_hw_type < IPA_HW_v4_5) {
  1796. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1797. "This feature only support on IPA4.5+\n");
  1798. cnt += nbytes;
  1799. goto done;
  1800. }
  1801. return 0;
  1802. done:
  1803. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, cnt);
  1804. }
  1805. static ssize_t ipa3_read_mhip_gsi_stats(struct file *file,
  1806. char __user *ubuf, size_t count, loff_t *ppos)
  1807. {
  1808. struct ipa3_uc_dbg_ring_stats stats;
  1809. int nbytes;
  1810. int cnt = 0;
  1811. if (ipa3_ctx->ipa_hw_type < IPA_HW_v4_5) {
  1812. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1813. "This feature only support on IPA4.5+\n");
  1814. cnt += nbytes;
  1815. goto done;
  1816. }
  1817. if (!ipa3_get_mhip_gsi_stats(&stats)) {
  1818. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1819. "IPA_CLIENT_MHI_PRIME_TETH_CONS ringFull=%u\n"
  1820. "IPA_CLIENT_MHI_PRIME_TETH_CONS ringEmpty=%u\n"
  1821. "IPA_CLIENT_MHI_PRIME_TETH_CONS ringUsageHigh=%u\n"
  1822. "IPA_CLIENT_MHI_PRIME_TETH_CONS ringUsageLow=%u\n"
  1823. "IPA_CLIENT_MHI_PRIME_TETH_CONS RingUtilCount=%u\n",
  1824. stats.ring[1].ringFull,
  1825. stats.ring[1].ringEmpty,
  1826. stats.ring[1].ringUsageHigh,
  1827. stats.ring[1].ringUsageLow,
  1828. stats.ring[1].RingUtilCount);
  1829. cnt += nbytes;
  1830. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1831. "IPA_CLIENT_MHI_PRIME_TETH_PROD ringFull=%u\n"
  1832. "IPA_CLIENT_MHI_PRIME_TETH_PROD ringEmpty=%u\n"
  1833. "IPA_CLIENT_MHI_PRIME_TETH_PROD ringUsageHigh=%u\n"
  1834. "IPA_CLIENT_MHI_PRIME_TETH_PROD ringUsageLow=%u\n"
  1835. "IPA_CLIENT_MHI_PRIME_TETH_PROD RingUtilCount=%u\n",
  1836. stats.ring[0].ringFull,
  1837. stats.ring[0].ringEmpty,
  1838. stats.ring[0].ringUsageHigh,
  1839. stats.ring[0].ringUsageLow,
  1840. stats.ring[0].RingUtilCount);
  1841. cnt += nbytes;
  1842. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1843. "IPA_CLIENT_MHI_PRIME_RMNET_CONS ringFull=%u\n"
  1844. "IPA_CLIENT_MHI_PRIME_RMNET_CONS ringEmpty=%u\n"
  1845. "IPA_CLIENT_MHI_PRIME_RMNET_CONS ringUsageHigh=%u\n"
  1846. "IPA_CLIENT_MHI_PRIME_RMNET_CONS ringUsageLow=%u\n"
  1847. "IPA_CLIENT_MHI_PRIME_RMNET_CONS RingUtilCount=%u\n",
  1848. stats.ring[3].ringFull,
  1849. stats.ring[3].ringEmpty,
  1850. stats.ring[3].ringUsageHigh,
  1851. stats.ring[3].ringUsageLow,
  1852. stats.ring[3].RingUtilCount);
  1853. cnt += nbytes;
  1854. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1855. "IPA_CLIENT_MHI_PRIME_RMNET_PROD ringFull=%u\n"
  1856. "IPA_CLIENT_MHI_PRIME_RMNET_PROD ringEmpty=%u\n"
  1857. "IPA_CLIENT_MHI_PRIME_RMNET_PROD ringUsageHigh=%u\n"
  1858. "IPA_CLIENT_MHI_PRIME_RMNET_PROD ringUsageLow=%u\n"
  1859. "IPA_CLIENT_MHI_PRIME_RMNET_PROD RingUtilCount=%u\n",
  1860. stats.ring[2].ringFull,
  1861. stats.ring[2].ringEmpty,
  1862. stats.ring[2].ringUsageHigh,
  1863. stats.ring[2].ringUsageLow,
  1864. stats.ring[2].RingUtilCount);
  1865. cnt += nbytes;
  1866. } else {
  1867. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1868. "Fail to read WDI GSI stats\n");
  1869. cnt += nbytes;
  1870. }
  1871. done:
  1872. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, cnt);
  1873. }
  1874. static ssize_t ipa3_read_usb_gsi_stats(struct file *file,
  1875. char __user *ubuf, size_t count, loff_t *ppos)
  1876. {
  1877. struct ipa3_uc_dbg_ring_stats stats;
  1878. int nbytes;
  1879. int cnt = 0;
  1880. if (ipa3_ctx->ipa_hw_type < IPA_HW_v4_5) {
  1881. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1882. "This feature only support on IPA4.5+\n");
  1883. cnt += nbytes;
  1884. goto done;
  1885. }
  1886. if (!ipa3_get_usb_gsi_stats(&stats)) {
  1887. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1888. "TX ringFull=%u\n"
  1889. "TX ringEmpty=%u\n"
  1890. "TX ringUsageHigh=%u\n"
  1891. "TX ringUsageLow=%u\n"
  1892. "TX RingUtilCount=%u\n",
  1893. stats.ring[1].ringFull,
  1894. stats.ring[1].ringEmpty,
  1895. stats.ring[1].ringUsageHigh,
  1896. stats.ring[1].ringUsageLow,
  1897. stats.ring[1].RingUtilCount);
  1898. cnt += nbytes;
  1899. nbytes = scnprintf(dbg_buff + cnt, IPA_MAX_MSG_LEN - cnt,
  1900. "RX ringFull=%u\n"
  1901. "RX ringEmpty=%u\n"
  1902. "RX ringUsageHigh=%u\n"
  1903. "RX ringUsageLow=%u\n"
  1904. "RX RingUtilCount=%u\n",
  1905. stats.ring[0].ringFull,
  1906. stats.ring[0].ringEmpty,
  1907. stats.ring[0].ringUsageHigh,
  1908. stats.ring[0].ringUsageLow,
  1909. stats.ring[0].RingUtilCount);
  1910. cnt += nbytes;
  1911. } else {
  1912. nbytes = scnprintf(dbg_buff, IPA_MAX_MSG_LEN,
  1913. "Fail to read WDI GSI stats\n");
  1914. cnt += nbytes;
  1915. }
  1916. done:
  1917. return simple_read_from_buffer(ubuf, count, ppos, dbg_buff, cnt);
  1918. }
  1919. static void ipa_dump_status(struct ipahal_pkt_status *status)
  1920. {
  1921. IPA_DUMP_STATUS_FIELD(status_opcode);
  1922. IPA_DUMP_STATUS_FIELD(exception);
  1923. IPA_DUMP_STATUS_FIELD(status_mask);
  1924. IPA_DUMP_STATUS_FIELD(pkt_len);
  1925. IPA_DUMP_STATUS_FIELD(endp_src_idx);
  1926. IPA_DUMP_STATUS_FIELD(endp_dest_idx);
  1927. IPA_DUMP_STATUS_FIELD(metadata);
  1928. IPA_DUMP_STATUS_FIELD(flt_local);
  1929. IPA_DUMP_STATUS_FIELD(flt_hash);
  1930. IPA_DUMP_STATUS_FIELD(flt_global);
  1931. IPA_DUMP_STATUS_FIELD(flt_ret_hdr);
  1932. IPA_DUMP_STATUS_FIELD(flt_miss);
  1933. IPA_DUMP_STATUS_FIELD(flt_rule_id);
  1934. IPA_DUMP_STATUS_FIELD(rt_local);
  1935. IPA_DUMP_STATUS_FIELD(rt_hash);
  1936. IPA_DUMP_STATUS_FIELD(ucp);
  1937. IPA_DUMP_STATUS_FIELD(rt_tbl_idx);
  1938. IPA_DUMP_STATUS_FIELD(rt_miss);
  1939. IPA_DUMP_STATUS_FIELD(rt_rule_id);
  1940. IPA_DUMP_STATUS_FIELD(nat_hit);
  1941. IPA_DUMP_STATUS_FIELD(nat_entry_idx);
  1942. IPA_DUMP_STATUS_FIELD(nat_type);
  1943. pr_err("tag = 0x%llx\n", (u64)status->tag_info & 0xFFFFFFFFFFFF);
  1944. IPA_DUMP_STATUS_FIELD(seq_num);
  1945. IPA_DUMP_STATUS_FIELD(time_of_day_ctr);
  1946. IPA_DUMP_STATUS_FIELD(hdr_local);
  1947. IPA_DUMP_STATUS_FIELD(hdr_offset);
  1948. IPA_DUMP_STATUS_FIELD(frag_hit);
  1949. IPA_DUMP_STATUS_FIELD(frag_rule);
  1950. }
  1951. static ssize_t ipa_status_stats_read(struct file *file, char __user *ubuf,
  1952. size_t count, loff_t *ppos)
  1953. {
  1954. struct ipa3_status_stats *stats;
  1955. int i, j;
  1956. stats = kzalloc(sizeof(*stats), GFP_KERNEL);
  1957. if (!stats)
  1958. return -EFAULT;
  1959. for (i = 0; i < ipa3_ctx->ipa_num_pipes; i++) {
  1960. if (!ipa3_ctx->ep[i].sys || !ipa3_ctx->ep[i].sys->status_stat)
  1961. continue;
  1962. memcpy(stats, ipa3_ctx->ep[i].sys->status_stat, sizeof(*stats));
  1963. pr_err("Statuses for pipe %d\n", i);
  1964. for (j = 0; j < IPA_MAX_STATUS_STAT_NUM; j++) {
  1965. pr_err("curr=%d\n", stats->curr);
  1966. ipa_dump_status(&stats->status[stats->curr]);
  1967. pr_err("\n\n\n");
  1968. stats->curr = (stats->curr + 1) %
  1969. IPA_MAX_STATUS_STAT_NUM;
  1970. }
  1971. }
  1972. kfree(stats);
  1973. return 0;
  1974. }
  1975. static ssize_t ipa3_print_active_clients_log(struct file *file,
  1976. char __user *ubuf, size_t count, loff_t *ppos)
  1977. {
  1978. int cnt;
  1979. int table_size;
  1980. if (active_clients_buf == NULL) {
  1981. IPAERR("Active Clients buffer is not allocated");
  1982. return 0;
  1983. }
  1984. memset(active_clients_buf, 0, IPA_DBG_ACTIVE_CLIENT_BUF_SIZE);
  1985. mutex_lock(&ipa3_ctx->ipa3_active_clients.mutex);
  1986. cnt = ipa3_active_clients_log_print_buffer(active_clients_buf,
  1987. IPA_DBG_ACTIVE_CLIENT_BUF_SIZE - IPA_MAX_MSG_LEN);
  1988. table_size = ipa3_active_clients_log_print_table(active_clients_buf
  1989. + cnt, IPA_MAX_MSG_LEN);
  1990. mutex_unlock(&ipa3_ctx->ipa3_active_clients.mutex);
  1991. return simple_read_from_buffer(ubuf, count, ppos,
  1992. active_clients_buf, cnt + table_size);
  1993. }
  1994. static ssize_t ipa3_clear_active_clients_log(struct file *file,
  1995. const char __user *ubuf, size_t count, loff_t *ppos)
  1996. {
  1997. ipa3_active_clients_log_clear();
  1998. return count;
  1999. }
  2000. static ssize_t ipa3_enable_ipc_low(struct file *file,
  2001. const char __user *ubuf, size_t count, loff_t *ppos)
  2002. {
  2003. s8 option = 0;
  2004. int ret;
  2005. ret = kstrtos8_from_user(ubuf, count, 0, &option);
  2006. if (ret)
  2007. return ret;
  2008. mutex_lock(&ipa3_ctx->lock);
  2009. if (option) {
  2010. if (!ipa_ipc_low_buff) {
  2011. ipa_ipc_low_buff =
  2012. ipc_log_context_create(IPA_IPC_LOG_PAGES,
  2013. "ipa_low", 0);
  2014. }
  2015. if (ipa_ipc_low_buff == NULL)
  2016. IPADBG("failed to get logbuf_low\n");
  2017. ipa3_ctx->logbuf_low = ipa_ipc_low_buff;
  2018. } else {
  2019. ipa3_ctx->logbuf_low = NULL;
  2020. }
  2021. mutex_unlock(&ipa3_ctx->lock);
  2022. return count;
  2023. }
  2024. static const struct ipa3_debugfs_file debugfs_files[] = {
  2025. {
  2026. "gen_reg", IPA_READ_ONLY_MODE, NULL, {
  2027. .read = ipa3_read_gen_reg
  2028. }
  2029. }, {
  2030. "active_clients", IPA_READ_WRITE_MODE, NULL, {
  2031. .read = ipa3_print_active_clients_log,
  2032. .write = ipa3_clear_active_clients_log
  2033. }
  2034. }, {
  2035. "ep_reg", IPA_READ_WRITE_MODE, NULL, {
  2036. .read = ipa3_read_ep_reg,
  2037. .write = ipa3_write_ep_reg,
  2038. }
  2039. }, {
  2040. "keep_awake", IPA_READ_WRITE_MODE, NULL, {
  2041. .read = ipa3_read_keep_awake,
  2042. .write = ipa3_write_keep_awake,
  2043. }
  2044. }, {
  2045. "holb", IPA_WRITE_ONLY_MODE, NULL, {
  2046. .write = ipa3_write_ep_holb,
  2047. }
  2048. }, {
  2049. "hdr", IPA_READ_ONLY_MODE, NULL, {
  2050. .read = ipa3_read_hdr,
  2051. }
  2052. }, {
  2053. "proc_ctx", IPA_READ_ONLY_MODE, NULL, {
  2054. .read = ipa3_read_proc_ctx,
  2055. }
  2056. }, {
  2057. "ip4_rt", IPA_READ_ONLY_MODE, (void *)IPA_IP_v4, {
  2058. .read = ipa3_read_rt,
  2059. .open = ipa3_open_dbg,
  2060. }
  2061. }, {
  2062. "ip4_rt_hw", IPA_READ_ONLY_MODE, (void *)IPA_IP_v4, {
  2063. .read = ipa3_read_rt_hw,
  2064. .open = ipa3_open_dbg,
  2065. }
  2066. }, {
  2067. "ip6_rt", IPA_READ_ONLY_MODE, (void *)IPA_IP_v6, {
  2068. .read = ipa3_read_rt,
  2069. .open = ipa3_open_dbg,
  2070. }
  2071. }, {
  2072. "ip6_rt_hw", IPA_READ_ONLY_MODE, (void *)IPA_IP_v6, {
  2073. .read = ipa3_read_rt_hw,
  2074. .open = ipa3_open_dbg,
  2075. }
  2076. }, {
  2077. "ip4_flt", IPA_READ_ONLY_MODE, (void *)IPA_IP_v4, {
  2078. .read = ipa3_read_flt,
  2079. .open = ipa3_open_dbg,
  2080. }
  2081. }, {
  2082. "ip4_flt_hw", IPA_READ_ONLY_MODE, (void *)IPA_IP_v4, {
  2083. .read = ipa3_read_flt_hw,
  2084. .open = ipa3_open_dbg,
  2085. }
  2086. }, {
  2087. "ip6_flt", IPA_READ_ONLY_MODE, (void *)IPA_IP_v6, {
  2088. .read = ipa3_read_flt,
  2089. .open = ipa3_open_dbg,
  2090. }
  2091. }, {
  2092. "ip6_flt_hw", IPA_READ_ONLY_MODE, (void *)IPA_IP_v6, {
  2093. .read = ipa3_read_flt_hw,
  2094. .open = ipa3_open_dbg,
  2095. }
  2096. }, {
  2097. "stats", IPA_READ_ONLY_MODE, NULL, {
  2098. .read = ipa3_read_stats,
  2099. }
  2100. }, {
  2101. "wstats", IPA_READ_ONLY_MODE, NULL, {
  2102. .read = ipa3_read_wstats,
  2103. }
  2104. }, {
  2105. "odlstats", IPA_READ_ONLY_MODE, NULL, {
  2106. .read = ipa3_read_odlstats,
  2107. }
  2108. }, {
  2109. "wdi", IPA_READ_ONLY_MODE, NULL, {
  2110. .read = ipa3_read_wdi,
  2111. }
  2112. }, {
  2113. "ntn", IPA_READ_ONLY_MODE, NULL, {
  2114. .read = ipa3_read_ntn,
  2115. }
  2116. }, {
  2117. "dbg_cnt", IPA_READ_WRITE_MODE, NULL, {
  2118. .read = ipa3_read_dbg_cnt,
  2119. .write = ipa3_write_dbg_cnt,
  2120. }
  2121. }, {
  2122. "msg", IPA_READ_ONLY_MODE, NULL, {
  2123. .read = ipa3_read_msg,
  2124. }
  2125. }, {
  2126. "ip4_nat", IPA_READ_ONLY_MODE, NULL, {
  2127. .read = ipa3_read_nat4,
  2128. }
  2129. }, {
  2130. "ipv6ct", IPA_READ_ONLY_MODE, NULL, {
  2131. .read = ipa3_read_ipv6ct,
  2132. }
  2133. }, {
  2134. "rm_stats", IPA_READ_ONLY_MODE, NULL, {
  2135. .read = ipa3_rm_read_stats,
  2136. }
  2137. }, {
  2138. "pm_stats", IPA_READ_ONLY_MODE, NULL, {
  2139. .read = ipa3_pm_read_stats,
  2140. }
  2141. }, {
  2142. "pm_ex_stats", IPA_READ_ONLY_MODE, NULL, {
  2143. .read = ipa3_pm_ex_read_stats,
  2144. }
  2145. }, {
  2146. "status_stats", IPA_READ_ONLY_MODE, NULL, {
  2147. .read = ipa_status_stats_read,
  2148. }
  2149. }, {
  2150. "enable_low_prio_print", IPA_WRITE_ONLY_MODE, NULL, {
  2151. .write = ipa3_enable_ipc_low,
  2152. }
  2153. }, {
  2154. "ipa_dump_regs", IPA_READ_ONLY_MODE, NULL, {
  2155. .read = ipa3_read_ipahal_regs,
  2156. }
  2157. }, {
  2158. "wdi_gsi_stats", IPA_READ_ONLY_MODE, NULL, {
  2159. .read = ipa3_read_wdi_gsi_stats,
  2160. }
  2161. }, {
  2162. "wdi3_gsi_stats", IPA_READ_ONLY_MODE, NULL, {
  2163. .read = ipa3_read_wdi3_gsi_stats,
  2164. }
  2165. }, {
  2166. "11ad_gsi_stats", IPA_READ_ONLY_MODE, NULL, {
  2167. .read = ipa3_read_11ad_gsi_stats,
  2168. }
  2169. }, {
  2170. "aqc_gsi_stats", IPA_READ_ONLY_MODE, NULL, {
  2171. .read = ipa3_read_aqc_gsi_stats,
  2172. }
  2173. }, {
  2174. "mhip_gsi_stats", IPA_READ_ONLY_MODE, NULL, {
  2175. .read = ipa3_read_mhip_gsi_stats,
  2176. }
  2177. }, {
  2178. "usb_gsi_stats", IPA_READ_ONLY_MODE, NULL, {
  2179. .read = ipa3_read_usb_gsi_stats,
  2180. }
  2181. }
  2182. };
  2183. void ipa3_debugfs_init(void)
  2184. {
  2185. const size_t debugfs_files_num =
  2186. sizeof(debugfs_files) / sizeof(struct ipa3_debugfs_file);
  2187. size_t i;
  2188. struct dentry *file;
  2189. dent = debugfs_create_dir("ipa", 0);
  2190. if (IS_ERR(dent)) {
  2191. IPAERR("fail to create folder in debug_fs.\n");
  2192. return;
  2193. }
  2194. file = debugfs_create_u32("hw_type", IPA_READ_ONLY_MODE,
  2195. dent, &ipa3_ctx->ipa_hw_type);
  2196. if (!file) {
  2197. IPAERR("could not create hw_type file\n");
  2198. goto fail;
  2199. }
  2200. for (i = 0; i < debugfs_files_num; ++i) {
  2201. const struct ipa3_debugfs_file *curr = &debugfs_files[i];
  2202. file = debugfs_create_file(curr->name, curr->mode, dent,
  2203. curr->data, &curr->fops);
  2204. if (!file || IS_ERR(file)) {
  2205. IPAERR("fail to create file for debug_fs %s\n",
  2206. curr->name);
  2207. goto fail;
  2208. }
  2209. }
  2210. active_clients_buf = NULL;
  2211. active_clients_buf = kzalloc(IPA_DBG_ACTIVE_CLIENT_BUF_SIZE,
  2212. GFP_KERNEL);
  2213. if (active_clients_buf == NULL)
  2214. goto fail;
  2215. file = debugfs_create_u32("enable_clock_scaling", IPA_READ_WRITE_MODE,
  2216. dent, &ipa3_ctx->enable_clock_scaling);
  2217. if (!file) {
  2218. IPAERR("could not create enable_clock_scaling file\n");
  2219. goto fail;
  2220. }
  2221. file = debugfs_create_u32("enable_napi_chain", IPA_READ_WRITE_MODE,
  2222. dent, &ipa3_ctx->enable_napi_chain);
  2223. if (!file) {
  2224. IPAERR("could not create enable_napi_chain file\n");
  2225. goto fail;
  2226. }
  2227. file = debugfs_create_u32("clock_scaling_bw_threshold_nominal_mbps",
  2228. IPA_READ_WRITE_MODE, dent,
  2229. &ipa3_ctx->ctrl->clock_scaling_bw_threshold_nominal);
  2230. if (!file) {
  2231. IPAERR("could not create bw_threshold_nominal_mbps\n");
  2232. goto fail;
  2233. }
  2234. file = debugfs_create_u32("clock_scaling_bw_threshold_turbo_mbps",
  2235. IPA_READ_WRITE_MODE, dent,
  2236. &ipa3_ctx->ctrl->clock_scaling_bw_threshold_turbo);
  2237. if (!file) {
  2238. IPAERR("could not create bw_threshold_turbo_mbps\n");
  2239. goto fail;
  2240. }
  2241. file = debugfs_create_u32("clk_rate", IPA_READ_ONLY_MODE,
  2242. dent, &ipa3_ctx->curr_ipa_clk_rate);
  2243. if (!file) {
  2244. IPAERR("could not create clk_rate file\n");
  2245. goto fail;
  2246. }
  2247. ipa_debugfs_init_stats(dent);
  2248. return;
  2249. fail:
  2250. debugfs_remove_recursive(dent);
  2251. }
  2252. void ipa3_debugfs_remove(void)
  2253. {
  2254. if (IS_ERR(dent)) {
  2255. IPAERR("Debugfs:folder was not created.\n");
  2256. return;
  2257. }
  2258. if (active_clients_buf != NULL) {
  2259. kfree(active_clients_buf);
  2260. active_clients_buf = NULL;
  2261. }
  2262. debugfs_remove_recursive(dent);
  2263. }
  2264. struct dentry *ipa_debugfs_get_root(void)
  2265. {
  2266. return dent;
  2267. }
  2268. EXPORT_SYMBOL(ipa_debugfs_get_root);
  2269. #else /* !CONFIG_DEBUG_FS */
  2270. void ipa3_debugfs_init(void) {}
  2271. void ipa3_debugfs_remove(void) {}
  2272. #endif