debug.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/debugfs.h>
  19. #include <linux/vmalloc.h>
  20. #include <linux/utsname.h>
  21. #include "core.h"
  22. #include "debug.h"
  23. #include "hif.h"
  24. #include "wmi-ops.h"
  25. /* ms */
  26. #define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000
  27. #define ATH10K_FW_CRASH_DUMP_VERSION 1
  28. /**
  29. * enum ath10k_fw_crash_dump_type - types of data in the dump file
  30. * @ATH10K_FW_CRASH_DUMP_REGDUMP: Register crash dump in binary format
  31. */
  32. enum ath10k_fw_crash_dump_type {
  33. ATH10K_FW_CRASH_DUMP_REGISTERS = 0,
  34. ATH10K_FW_CRASH_DUMP_MAX,
  35. };
  36. struct ath10k_tlv_dump_data {
  37. /* see ath10k_fw_crash_dump_type above */
  38. __le32 type;
  39. /* in bytes */
  40. __le32 tlv_len;
  41. /* pad to 32-bit boundaries as needed */
  42. u8 tlv_data[];
  43. } __packed;
  44. struct ath10k_dump_file_data {
  45. /* dump file information */
  46. /* "ATH10K-FW-DUMP" */
  47. char df_magic[16];
  48. __le32 len;
  49. /* file dump version */
  50. __le32 version;
  51. /* some info we can get from ath10k struct that might help */
  52. u8 uuid[16];
  53. __le32 chip_id;
  54. /* 0 for now, in place for later hardware */
  55. __le32 bus_type;
  56. __le32 target_version;
  57. __le32 fw_version_major;
  58. __le32 fw_version_minor;
  59. __le32 fw_version_release;
  60. __le32 fw_version_build;
  61. __le32 phy_capability;
  62. __le32 hw_min_tx_power;
  63. __le32 hw_max_tx_power;
  64. __le32 ht_cap_info;
  65. __le32 vht_cap_info;
  66. __le32 num_rf_chains;
  67. /* firmware version string */
  68. char fw_ver[ETHTOOL_FWVERS_LEN];
  69. /* Kernel related information */
  70. /* time-of-day stamp */
  71. __le64 tv_sec;
  72. /* time-of-day stamp, nano-seconds */
  73. __le64 tv_nsec;
  74. /* LINUX_VERSION_CODE */
  75. __le32 kernel_ver_code;
  76. /* VERMAGIC_STRING */
  77. char kernel_ver[64];
  78. /* room for growth w/out changing binary format */
  79. u8 unused[128];
  80. /* struct ath10k_tlv_dump_data + more */
  81. u8 data[0];
  82. } __packed;
  83. void ath10k_info(struct ath10k *ar, const char *fmt, ...)
  84. {
  85. struct va_format vaf = {
  86. .fmt = fmt,
  87. };
  88. va_list args;
  89. va_start(args, fmt);
  90. vaf.va = &args;
  91. dev_info(ar->dev, "%pV", &vaf);
  92. trace_ath10k_log_info(ar, &vaf);
  93. va_end(args);
  94. }
  95. EXPORT_SYMBOL(ath10k_info);
  96. void ath10k_print_driver_info(struct ath10k *ar)
  97. {
  98. ath10k_info(ar, "%s (0x%08x, 0x%08x%s%s%s) fw %s api %d htt %d.%d wmi %d cal %s max_sta %d\n",
  99. ar->hw_params.name,
  100. ar->target_version,
  101. ar->chip_id,
  102. (strlen(ar->spec_board_id) > 0 ? ", " : ""),
  103. ar->spec_board_id,
  104. (strlen(ar->spec_board_id) > 0 && !ar->spec_board_loaded
  105. ? " fallback" : ""),
  106. ar->hw->wiphy->fw_version,
  107. ar->fw_api,
  108. ar->htt.target_version_major,
  109. ar->htt.target_version_minor,
  110. ar->wmi.op_version,
  111. ath10k_cal_mode_str(ar->cal_mode),
  112. ar->max_num_stations);
  113. ath10k_info(ar, "debug %d debugfs %d tracing %d dfs %d testmode %d\n",
  114. config_enabled(CONFIG_ATH10K_DEBUG),
  115. config_enabled(CONFIG_ATH10K_DEBUGFS),
  116. config_enabled(CONFIG_ATH10K_TRACING),
  117. config_enabled(CONFIG_ATH10K_DFS_CERTIFIED),
  118. config_enabled(CONFIG_NL80211_TESTMODE));
  119. }
  120. EXPORT_SYMBOL(ath10k_print_driver_info);
  121. void ath10k_err(struct ath10k *ar, const char *fmt, ...)
  122. {
  123. struct va_format vaf = {
  124. .fmt = fmt,
  125. };
  126. va_list args;
  127. va_start(args, fmt);
  128. vaf.va = &args;
  129. dev_err(ar->dev, "%pV", &vaf);
  130. trace_ath10k_log_err(ar, &vaf);
  131. va_end(args);
  132. }
  133. EXPORT_SYMBOL(ath10k_err);
  134. void ath10k_warn(struct ath10k *ar, const char *fmt, ...)
  135. {
  136. struct va_format vaf = {
  137. .fmt = fmt,
  138. };
  139. va_list args;
  140. va_start(args, fmt);
  141. vaf.va = &args;
  142. dev_warn_ratelimited(ar->dev, "%pV", &vaf);
  143. trace_ath10k_log_warn(ar, &vaf);
  144. va_end(args);
  145. }
  146. EXPORT_SYMBOL(ath10k_warn);
  147. #ifdef CONFIG_ATH10K_DEBUGFS
  148. static ssize_t ath10k_read_wmi_services(struct file *file,
  149. char __user *user_buf,
  150. size_t count, loff_t *ppos)
  151. {
  152. struct ath10k *ar = file->private_data;
  153. char *buf;
  154. unsigned int len = 0, buf_len = 4096;
  155. const char *name;
  156. ssize_t ret_cnt;
  157. bool enabled;
  158. int i;
  159. buf = kzalloc(buf_len, GFP_KERNEL);
  160. if (!buf)
  161. return -ENOMEM;
  162. mutex_lock(&ar->conf_mutex);
  163. if (len > buf_len)
  164. len = buf_len;
  165. spin_lock_bh(&ar->data_lock);
  166. for (i = 0; i < WMI_SERVICE_MAX; i++) {
  167. enabled = test_bit(i, ar->wmi.svc_map);
  168. name = wmi_service_name(i);
  169. if (!name) {
  170. if (enabled)
  171. len += scnprintf(buf + len, buf_len - len,
  172. "%-40s %s (bit %d)\n",
  173. "unknown", "enabled", i);
  174. continue;
  175. }
  176. len += scnprintf(buf + len, buf_len - len,
  177. "%-40s %s\n",
  178. name, enabled ? "enabled" : "-");
  179. }
  180. spin_unlock_bh(&ar->data_lock);
  181. ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  182. mutex_unlock(&ar->conf_mutex);
  183. kfree(buf);
  184. return ret_cnt;
  185. }
  186. static const struct file_operations fops_wmi_services = {
  187. .read = ath10k_read_wmi_services,
  188. .open = simple_open,
  189. .owner = THIS_MODULE,
  190. .llseek = default_llseek,
  191. };
  192. static void ath10k_debug_fw_stats_pdevs_free(struct list_head *head)
  193. {
  194. struct ath10k_fw_stats_pdev *i, *tmp;
  195. list_for_each_entry_safe(i, tmp, head, list) {
  196. list_del(&i->list);
  197. kfree(i);
  198. }
  199. }
  200. static void ath10k_debug_fw_stats_vdevs_free(struct list_head *head)
  201. {
  202. struct ath10k_fw_stats_vdev *i, *tmp;
  203. list_for_each_entry_safe(i, tmp, head, list) {
  204. list_del(&i->list);
  205. kfree(i);
  206. }
  207. }
  208. static void ath10k_debug_fw_stats_peers_free(struct list_head *head)
  209. {
  210. struct ath10k_fw_stats_peer *i, *tmp;
  211. list_for_each_entry_safe(i, tmp, head, list) {
  212. list_del(&i->list);
  213. kfree(i);
  214. }
  215. }
  216. static void ath10k_debug_fw_stats_reset(struct ath10k *ar)
  217. {
  218. spin_lock_bh(&ar->data_lock);
  219. ar->debug.fw_stats_done = false;
  220. ath10k_debug_fw_stats_pdevs_free(&ar->debug.fw_stats.pdevs);
  221. ath10k_debug_fw_stats_vdevs_free(&ar->debug.fw_stats.vdevs);
  222. ath10k_debug_fw_stats_peers_free(&ar->debug.fw_stats.peers);
  223. spin_unlock_bh(&ar->data_lock);
  224. }
  225. static size_t ath10k_debug_fw_stats_num_peers(struct list_head *head)
  226. {
  227. struct ath10k_fw_stats_peer *i;
  228. size_t num = 0;
  229. list_for_each_entry(i, head, list)
  230. ++num;
  231. return num;
  232. }
  233. static size_t ath10k_debug_fw_stats_num_vdevs(struct list_head *head)
  234. {
  235. struct ath10k_fw_stats_vdev *i;
  236. size_t num = 0;
  237. list_for_each_entry(i, head, list)
  238. ++num;
  239. return num;
  240. }
  241. void ath10k_debug_fw_stats_process(struct ath10k *ar, struct sk_buff *skb)
  242. {
  243. struct ath10k_fw_stats stats = {};
  244. bool is_start, is_started, is_end;
  245. size_t num_peers;
  246. size_t num_vdevs;
  247. int ret;
  248. INIT_LIST_HEAD(&stats.pdevs);
  249. INIT_LIST_HEAD(&stats.vdevs);
  250. INIT_LIST_HEAD(&stats.peers);
  251. spin_lock_bh(&ar->data_lock);
  252. ret = ath10k_wmi_pull_fw_stats(ar, skb, &stats);
  253. if (ret) {
  254. ath10k_warn(ar, "failed to pull fw stats: %d\n", ret);
  255. goto unlock;
  256. }
  257. /* Stat data may exceed htc-wmi buffer limit. In such case firmware
  258. * splits the stats data and delivers it in a ping-pong fashion of
  259. * request cmd-update event.
  260. *
  261. * However there is no explicit end-of-data. Instead start-of-data is
  262. * used as an implicit one. This works as follows:
  263. * a) discard stat update events until one with pdev stats is
  264. * delivered - this skips session started at end of (b)
  265. * b) consume stat update events until another one with pdev stats is
  266. * delivered which is treated as end-of-data and is itself discarded
  267. */
  268. if (ar->debug.fw_stats_done) {
  269. ath10k_warn(ar, "received unsolicited stats update event\n");
  270. goto free;
  271. }
  272. num_peers = ath10k_debug_fw_stats_num_peers(&ar->debug.fw_stats.peers);
  273. num_vdevs = ath10k_debug_fw_stats_num_vdevs(&ar->debug.fw_stats.vdevs);
  274. is_start = (list_empty(&ar->debug.fw_stats.pdevs) &&
  275. !list_empty(&stats.pdevs));
  276. is_end = (!list_empty(&ar->debug.fw_stats.pdevs) &&
  277. !list_empty(&stats.pdevs));
  278. if (is_start)
  279. list_splice_tail_init(&stats.pdevs, &ar->debug.fw_stats.pdevs);
  280. if (is_end)
  281. ar->debug.fw_stats_done = true;
  282. is_started = !list_empty(&ar->debug.fw_stats.pdevs);
  283. if (is_started && !is_end) {
  284. if (num_peers >= ATH10K_MAX_NUM_PEER_IDS) {
  285. /* Although this is unlikely impose a sane limit to
  286. * prevent firmware from DoS-ing the host.
  287. */
  288. ath10k_warn(ar, "dropping fw peer stats\n");
  289. goto free;
  290. }
  291. if (num_vdevs >= BITS_PER_LONG) {
  292. ath10k_warn(ar, "dropping fw vdev stats\n");
  293. goto free;
  294. }
  295. list_splice_tail_init(&stats.peers, &ar->debug.fw_stats.peers);
  296. list_splice_tail_init(&stats.vdevs, &ar->debug.fw_stats.vdevs);
  297. }
  298. complete(&ar->debug.fw_stats_complete);
  299. free:
  300. /* In some cases lists have been spliced and cleared. Free up
  301. * resources if that is not the case.
  302. */
  303. ath10k_debug_fw_stats_pdevs_free(&stats.pdevs);
  304. ath10k_debug_fw_stats_vdevs_free(&stats.vdevs);
  305. ath10k_debug_fw_stats_peers_free(&stats.peers);
  306. unlock:
  307. spin_unlock_bh(&ar->data_lock);
  308. }
  309. static int ath10k_debug_fw_stats_request(struct ath10k *ar)
  310. {
  311. unsigned long timeout, time_left;
  312. int ret;
  313. lockdep_assert_held(&ar->conf_mutex);
  314. timeout = jiffies + msecs_to_jiffies(1 * HZ);
  315. ath10k_debug_fw_stats_reset(ar);
  316. for (;;) {
  317. if (time_after(jiffies, timeout))
  318. return -ETIMEDOUT;
  319. reinit_completion(&ar->debug.fw_stats_complete);
  320. ret = ath10k_wmi_request_stats(ar, ar->fw_stats_req_mask);
  321. if (ret) {
  322. ath10k_warn(ar, "could not request stats (%d)\n", ret);
  323. return ret;
  324. }
  325. time_left =
  326. wait_for_completion_timeout(&ar->debug.fw_stats_complete,
  327. 1 * HZ);
  328. if (!time_left)
  329. return -ETIMEDOUT;
  330. spin_lock_bh(&ar->data_lock);
  331. if (ar->debug.fw_stats_done) {
  332. spin_unlock_bh(&ar->data_lock);
  333. break;
  334. }
  335. spin_unlock_bh(&ar->data_lock);
  336. }
  337. return 0;
  338. }
  339. /* FIXME: How to calculate the buffer size sanely? */
  340. #define ATH10K_FW_STATS_BUF_SIZE (1024*1024)
  341. static void ath10k_fw_stats_fill(struct ath10k *ar,
  342. struct ath10k_fw_stats *fw_stats,
  343. char *buf)
  344. {
  345. unsigned int len = 0;
  346. unsigned int buf_len = ATH10K_FW_STATS_BUF_SIZE;
  347. const struct ath10k_fw_stats_pdev *pdev;
  348. const struct ath10k_fw_stats_vdev *vdev;
  349. const struct ath10k_fw_stats_peer *peer;
  350. size_t num_peers;
  351. size_t num_vdevs;
  352. int i;
  353. spin_lock_bh(&ar->data_lock);
  354. pdev = list_first_entry_or_null(&fw_stats->pdevs,
  355. struct ath10k_fw_stats_pdev, list);
  356. if (!pdev) {
  357. ath10k_warn(ar, "failed to get pdev stats\n");
  358. goto unlock;
  359. }
  360. num_peers = ath10k_debug_fw_stats_num_peers(&fw_stats->peers);
  361. num_vdevs = ath10k_debug_fw_stats_num_vdevs(&fw_stats->vdevs);
  362. len += scnprintf(buf + len, buf_len - len, "\n");
  363. len += scnprintf(buf + len, buf_len - len, "%30s\n",
  364. "ath10k PDEV stats");
  365. len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
  366. "=================");
  367. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  368. "Channel noise floor", pdev->ch_noise_floor);
  369. len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
  370. "Channel TX power", pdev->chan_tx_power);
  371. len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
  372. "TX frame count", pdev->tx_frame_count);
  373. len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
  374. "RX frame count", pdev->rx_frame_count);
  375. len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
  376. "RX clear count", pdev->rx_clear_count);
  377. len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
  378. "Cycle count", pdev->cycle_count);
  379. len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
  380. "PHY error count", pdev->phy_err_count);
  381. len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
  382. "RTS bad count", pdev->rts_bad);
  383. len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
  384. "RTS good count", pdev->rts_good);
  385. len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
  386. "FCS bad count", pdev->fcs_bad);
  387. len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
  388. "No beacon count", pdev->no_beacons);
  389. len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
  390. "MIB int count", pdev->mib_int_count);
  391. len += scnprintf(buf + len, buf_len - len, "\n");
  392. len += scnprintf(buf + len, buf_len - len, "%30s\n",
  393. "ath10k PDEV TX stats");
  394. len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
  395. "=================");
  396. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  397. "HTT cookies queued", pdev->comp_queued);
  398. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  399. "HTT cookies disp.", pdev->comp_delivered);
  400. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  401. "MSDU queued", pdev->msdu_enqued);
  402. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  403. "MPDU queued", pdev->mpdu_enqued);
  404. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  405. "MSDUs dropped", pdev->wmm_drop);
  406. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  407. "Local enqued", pdev->local_enqued);
  408. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  409. "Local freed", pdev->local_freed);
  410. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  411. "HW queued", pdev->hw_queued);
  412. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  413. "PPDUs reaped", pdev->hw_reaped);
  414. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  415. "Num underruns", pdev->underrun);
  416. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  417. "PPDUs cleaned", pdev->tx_abort);
  418. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  419. "MPDUs requed", pdev->mpdus_requed);
  420. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  421. "Excessive retries", pdev->tx_ko);
  422. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  423. "HW rate", pdev->data_rc);
  424. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  425. "Sched self tiggers", pdev->self_triggers);
  426. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  427. "Dropped due to SW retries",
  428. pdev->sw_retry_failure);
  429. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  430. "Illegal rate phy errors",
  431. pdev->illgl_rate_phy_err);
  432. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  433. "Pdev continous xretry", pdev->pdev_cont_xretry);
  434. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  435. "TX timeout", pdev->pdev_tx_timeout);
  436. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  437. "PDEV resets", pdev->pdev_resets);
  438. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  439. "PHY underrun", pdev->phy_underrun);
  440. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  441. "MPDU is more than txop limit", pdev->txop_ovf);
  442. len += scnprintf(buf + len, buf_len - len, "\n");
  443. len += scnprintf(buf + len, buf_len - len, "%30s\n",
  444. "ath10k PDEV RX stats");
  445. len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
  446. "=================");
  447. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  448. "Mid PPDU route change",
  449. pdev->mid_ppdu_route_change);
  450. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  451. "Tot. number of statuses", pdev->status_rcvd);
  452. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  453. "Extra frags on rings 0", pdev->r0_frags);
  454. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  455. "Extra frags on rings 1", pdev->r1_frags);
  456. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  457. "Extra frags on rings 2", pdev->r2_frags);
  458. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  459. "Extra frags on rings 3", pdev->r3_frags);
  460. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  461. "MSDUs delivered to HTT", pdev->htt_msdus);
  462. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  463. "MPDUs delivered to HTT", pdev->htt_mpdus);
  464. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  465. "MSDUs delivered to stack", pdev->loc_msdus);
  466. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  467. "MPDUs delivered to stack", pdev->loc_mpdus);
  468. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  469. "Oversized AMSUs", pdev->oversize_amsdu);
  470. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  471. "PHY errors", pdev->phy_errs);
  472. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  473. "PHY errors drops", pdev->phy_err_drop);
  474. len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
  475. "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs);
  476. len += scnprintf(buf + len, buf_len - len, "\n");
  477. len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
  478. "ath10k VDEV stats", num_vdevs);
  479. len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
  480. "=================");
  481. list_for_each_entry(vdev, &fw_stats->vdevs, list) {
  482. len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
  483. "vdev id", vdev->vdev_id);
  484. len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
  485. "beacon snr", vdev->beacon_snr);
  486. len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
  487. "data snr", vdev->data_snr);
  488. len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
  489. "num rx frames", vdev->num_rx_frames);
  490. len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
  491. "num rts fail", vdev->num_rts_fail);
  492. len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
  493. "num rts success", vdev->num_rts_success);
  494. len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
  495. "num rx err", vdev->num_rx_err);
  496. len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
  497. "num rx discard", vdev->num_rx_discard);
  498. len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
  499. "num tx not acked", vdev->num_tx_not_acked);
  500. for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames); i++)
  501. len += scnprintf(buf + len, buf_len - len,
  502. "%25s [%02d] %u\n",
  503. "num tx frames", i,
  504. vdev->num_tx_frames[i]);
  505. for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_retries); i++)
  506. len += scnprintf(buf + len, buf_len - len,
  507. "%25s [%02d] %u\n",
  508. "num tx frames retries", i,
  509. vdev->num_tx_frames_retries[i]);
  510. for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_failures); i++)
  511. len += scnprintf(buf + len, buf_len - len,
  512. "%25s [%02d] %u\n",
  513. "num tx frames failures", i,
  514. vdev->num_tx_frames_failures[i]);
  515. for (i = 0 ; i < ARRAY_SIZE(vdev->tx_rate_history); i++)
  516. len += scnprintf(buf + len, buf_len - len,
  517. "%25s [%02d] 0x%08x\n",
  518. "tx rate history", i,
  519. vdev->tx_rate_history[i]);
  520. for (i = 0 ; i < ARRAY_SIZE(vdev->beacon_rssi_history); i++)
  521. len += scnprintf(buf + len, buf_len - len,
  522. "%25s [%02d] %u\n",
  523. "beacon rssi history", i,
  524. vdev->beacon_rssi_history[i]);
  525. len += scnprintf(buf + len, buf_len - len, "\n");
  526. }
  527. len += scnprintf(buf + len, buf_len - len, "\n");
  528. len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
  529. "ath10k PEER stats", num_peers);
  530. len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
  531. "=================");
  532. list_for_each_entry(peer, &fw_stats->peers, list) {
  533. len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
  534. "Peer MAC address", peer->peer_macaddr);
  535. len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
  536. "Peer RSSI", peer->peer_rssi);
  537. len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
  538. "Peer TX rate", peer->peer_tx_rate);
  539. len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
  540. "Peer RX rate", peer->peer_rx_rate);
  541. len += scnprintf(buf + len, buf_len - len, "\n");
  542. }
  543. unlock:
  544. spin_unlock_bh(&ar->data_lock);
  545. if (len >= buf_len)
  546. buf[len - 1] = 0;
  547. else
  548. buf[len] = 0;
  549. }
  550. static int ath10k_fw_stats_open(struct inode *inode, struct file *file)
  551. {
  552. struct ath10k *ar = inode->i_private;
  553. void *buf = NULL;
  554. int ret;
  555. mutex_lock(&ar->conf_mutex);
  556. if (ar->state != ATH10K_STATE_ON) {
  557. ret = -ENETDOWN;
  558. goto err_unlock;
  559. }
  560. buf = vmalloc(ATH10K_FW_STATS_BUF_SIZE);
  561. if (!buf) {
  562. ret = -ENOMEM;
  563. goto err_unlock;
  564. }
  565. ret = ath10k_debug_fw_stats_request(ar);
  566. if (ret) {
  567. ath10k_warn(ar, "failed to request fw stats: %d\n", ret);
  568. goto err_free;
  569. }
  570. ath10k_fw_stats_fill(ar, &ar->debug.fw_stats, buf);
  571. file->private_data = buf;
  572. mutex_unlock(&ar->conf_mutex);
  573. return 0;
  574. err_free:
  575. vfree(buf);
  576. err_unlock:
  577. mutex_unlock(&ar->conf_mutex);
  578. return ret;
  579. }
  580. static int ath10k_fw_stats_release(struct inode *inode, struct file *file)
  581. {
  582. vfree(file->private_data);
  583. return 0;
  584. }
  585. static ssize_t ath10k_fw_stats_read(struct file *file, char __user *user_buf,
  586. size_t count, loff_t *ppos)
  587. {
  588. const char *buf = file->private_data;
  589. unsigned int len = strlen(buf);
  590. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  591. }
  592. static const struct file_operations fops_fw_stats = {
  593. .open = ath10k_fw_stats_open,
  594. .release = ath10k_fw_stats_release,
  595. .read = ath10k_fw_stats_read,
  596. .owner = THIS_MODULE,
  597. .llseek = default_llseek,
  598. };
  599. static ssize_t ath10k_debug_fw_reset_stats_read(struct file *file,
  600. char __user *user_buf,
  601. size_t count, loff_t *ppos)
  602. {
  603. struct ath10k *ar = file->private_data;
  604. int ret, len, buf_len;
  605. char *buf;
  606. buf_len = 500;
  607. buf = kmalloc(buf_len, GFP_KERNEL);
  608. if (!buf)
  609. return -ENOMEM;
  610. spin_lock_bh(&ar->data_lock);
  611. len = 0;
  612. len += scnprintf(buf + len, buf_len - len,
  613. "fw_crash_counter\t\t%d\n", ar->stats.fw_crash_counter);
  614. len += scnprintf(buf + len, buf_len - len,
  615. "fw_warm_reset_counter\t\t%d\n",
  616. ar->stats.fw_warm_reset_counter);
  617. len += scnprintf(buf + len, buf_len - len,
  618. "fw_cold_reset_counter\t\t%d\n",
  619. ar->stats.fw_cold_reset_counter);
  620. spin_unlock_bh(&ar->data_lock);
  621. ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  622. kfree(buf);
  623. return ret;
  624. }
  625. static const struct file_operations fops_fw_reset_stats = {
  626. .open = simple_open,
  627. .read = ath10k_debug_fw_reset_stats_read,
  628. .owner = THIS_MODULE,
  629. .llseek = default_llseek,
  630. };
  631. /* This is a clean assert crash in firmware. */
  632. static int ath10k_debug_fw_assert(struct ath10k *ar)
  633. {
  634. struct wmi_vdev_install_key_cmd *cmd;
  635. struct sk_buff *skb;
  636. skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + 16);
  637. if (!skb)
  638. return -ENOMEM;
  639. cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
  640. memset(cmd, 0, sizeof(*cmd));
  641. /* big enough number so that firmware asserts */
  642. cmd->vdev_id = __cpu_to_le32(0x7ffe);
  643. return ath10k_wmi_cmd_send(ar, skb,
  644. ar->wmi.cmd->vdev_install_key_cmdid);
  645. }
  646. static ssize_t ath10k_read_simulate_fw_crash(struct file *file,
  647. char __user *user_buf,
  648. size_t count, loff_t *ppos)
  649. {
  650. const char buf[] =
  651. "To simulate firmware crash write one of the keywords to this file:\n"
  652. "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n"
  653. "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n"
  654. "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"
  655. "`hw-restart` - this will simply queue hw restart without fw/hw actually crashing.\n";
  656. return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
  657. }
  658. /* Simulate firmware crash:
  659. * 'soft': Call wmi command causing firmware hang. This firmware hang is
  660. * recoverable by warm firmware reset.
  661. * 'hard': Force firmware crash by setting any vdev parameter for not allowed
  662. * vdev id. This is hard firmware crash because it is recoverable only by cold
  663. * firmware reset.
  664. */
  665. static ssize_t ath10k_write_simulate_fw_crash(struct file *file,
  666. const char __user *user_buf,
  667. size_t count, loff_t *ppos)
  668. {
  669. struct ath10k *ar = file->private_data;
  670. char buf[32];
  671. int ret;
  672. mutex_lock(&ar->conf_mutex);
  673. simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
  674. /* make sure that buf is null terminated */
  675. buf[sizeof(buf) - 1] = 0;
  676. if (ar->state != ATH10K_STATE_ON &&
  677. ar->state != ATH10K_STATE_RESTARTED) {
  678. ret = -ENETDOWN;
  679. goto exit;
  680. }
  681. /* drop the possible '\n' from the end */
  682. if (buf[count - 1] == '\n') {
  683. buf[count - 1] = 0;
  684. count--;
  685. }
  686. if (!strcmp(buf, "soft")) {
  687. ath10k_info(ar, "simulating soft firmware crash\n");
  688. ret = ath10k_wmi_force_fw_hang(ar, WMI_FORCE_FW_HANG_ASSERT, 0);
  689. } else if (!strcmp(buf, "hard")) {
  690. ath10k_info(ar, "simulating hard firmware crash\n");
  691. /* 0x7fff is vdev id, and it is always out of range for all
  692. * firmware variants in order to force a firmware crash.
  693. */
  694. ret = ath10k_wmi_vdev_set_param(ar, 0x7fff,
  695. ar->wmi.vdev_param->rts_threshold,
  696. 0);
  697. } else if (!strcmp(buf, "assert")) {
  698. ath10k_info(ar, "simulating firmware assert crash\n");
  699. ret = ath10k_debug_fw_assert(ar);
  700. } else if (!strcmp(buf, "hw-restart")) {
  701. ath10k_info(ar, "user requested hw restart\n");
  702. queue_work(ar->workqueue, &ar->restart_work);
  703. ret = 0;
  704. } else {
  705. ret = -EINVAL;
  706. goto exit;
  707. }
  708. if (ret) {
  709. ath10k_warn(ar, "failed to simulate firmware crash: %d\n", ret);
  710. goto exit;
  711. }
  712. ret = count;
  713. exit:
  714. mutex_unlock(&ar->conf_mutex);
  715. return ret;
  716. }
  717. static const struct file_operations fops_simulate_fw_crash = {
  718. .read = ath10k_read_simulate_fw_crash,
  719. .write = ath10k_write_simulate_fw_crash,
  720. .open = simple_open,
  721. .owner = THIS_MODULE,
  722. .llseek = default_llseek,
  723. };
  724. static ssize_t ath10k_read_chip_id(struct file *file, char __user *user_buf,
  725. size_t count, loff_t *ppos)
  726. {
  727. struct ath10k *ar = file->private_data;
  728. unsigned int len;
  729. char buf[50];
  730. len = scnprintf(buf, sizeof(buf), "0x%08x\n", ar->chip_id);
  731. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  732. }
  733. static const struct file_operations fops_chip_id = {
  734. .read = ath10k_read_chip_id,
  735. .open = simple_open,
  736. .owner = THIS_MODULE,
  737. .llseek = default_llseek,
  738. };
  739. struct ath10k_fw_crash_data *
  740. ath10k_debug_get_new_fw_crash_data(struct ath10k *ar)
  741. {
  742. struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
  743. lockdep_assert_held(&ar->data_lock);
  744. crash_data->crashed_since_read = true;
  745. uuid_le_gen(&crash_data->uuid);
  746. getnstimeofday(&crash_data->timestamp);
  747. return crash_data;
  748. }
  749. EXPORT_SYMBOL(ath10k_debug_get_new_fw_crash_data);
  750. static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar)
  751. {
  752. struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
  753. struct ath10k_dump_file_data *dump_data;
  754. struct ath10k_tlv_dump_data *dump_tlv;
  755. int hdr_len = sizeof(*dump_data);
  756. unsigned int len, sofar = 0;
  757. unsigned char *buf;
  758. len = hdr_len;
  759. len += sizeof(*dump_tlv) + sizeof(crash_data->registers);
  760. sofar += hdr_len;
  761. /* This is going to get big when we start dumping FW RAM and such,
  762. * so go ahead and use vmalloc.
  763. */
  764. buf = vzalloc(len);
  765. if (!buf)
  766. return NULL;
  767. spin_lock_bh(&ar->data_lock);
  768. if (!crash_data->crashed_since_read) {
  769. spin_unlock_bh(&ar->data_lock);
  770. vfree(buf);
  771. return NULL;
  772. }
  773. dump_data = (struct ath10k_dump_file_data *)(buf);
  774. strlcpy(dump_data->df_magic, "ATH10K-FW-DUMP",
  775. sizeof(dump_data->df_magic));
  776. dump_data->len = cpu_to_le32(len);
  777. dump_data->version = cpu_to_le32(ATH10K_FW_CRASH_DUMP_VERSION);
  778. memcpy(dump_data->uuid, &crash_data->uuid, sizeof(dump_data->uuid));
  779. dump_data->chip_id = cpu_to_le32(ar->chip_id);
  780. dump_data->bus_type = cpu_to_le32(0);
  781. dump_data->target_version = cpu_to_le32(ar->target_version);
  782. dump_data->fw_version_major = cpu_to_le32(ar->fw_version_major);
  783. dump_data->fw_version_minor = cpu_to_le32(ar->fw_version_minor);
  784. dump_data->fw_version_release = cpu_to_le32(ar->fw_version_release);
  785. dump_data->fw_version_build = cpu_to_le32(ar->fw_version_build);
  786. dump_data->phy_capability = cpu_to_le32(ar->phy_capability);
  787. dump_data->hw_min_tx_power = cpu_to_le32(ar->hw_min_tx_power);
  788. dump_data->hw_max_tx_power = cpu_to_le32(ar->hw_max_tx_power);
  789. dump_data->ht_cap_info = cpu_to_le32(ar->ht_cap_info);
  790. dump_data->vht_cap_info = cpu_to_le32(ar->vht_cap_info);
  791. dump_data->num_rf_chains = cpu_to_le32(ar->num_rf_chains);
  792. strlcpy(dump_data->fw_ver, ar->hw->wiphy->fw_version,
  793. sizeof(dump_data->fw_ver));
  794. dump_data->kernel_ver_code = 0;
  795. strlcpy(dump_data->kernel_ver, init_utsname()->release,
  796. sizeof(dump_data->kernel_ver));
  797. dump_data->tv_sec = cpu_to_le64(crash_data->timestamp.tv_sec);
  798. dump_data->tv_nsec = cpu_to_le64(crash_data->timestamp.tv_nsec);
  799. /* Gather crash-dump */
  800. dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
  801. dump_tlv->type = cpu_to_le32(ATH10K_FW_CRASH_DUMP_REGISTERS);
  802. dump_tlv->tlv_len = cpu_to_le32(sizeof(crash_data->registers));
  803. memcpy(dump_tlv->tlv_data, &crash_data->registers,
  804. sizeof(crash_data->registers));
  805. sofar += sizeof(*dump_tlv) + sizeof(crash_data->registers);
  806. ar->debug.fw_crash_data->crashed_since_read = false;
  807. spin_unlock_bh(&ar->data_lock);
  808. return dump_data;
  809. }
  810. static int ath10k_fw_crash_dump_open(struct inode *inode, struct file *file)
  811. {
  812. struct ath10k *ar = inode->i_private;
  813. struct ath10k_dump_file_data *dump;
  814. dump = ath10k_build_dump_file(ar);
  815. if (!dump)
  816. return -ENODATA;
  817. file->private_data = dump;
  818. return 0;
  819. }
  820. static ssize_t ath10k_fw_crash_dump_read(struct file *file,
  821. char __user *user_buf,
  822. size_t count, loff_t *ppos)
  823. {
  824. struct ath10k_dump_file_data *dump_file = file->private_data;
  825. return simple_read_from_buffer(user_buf, count, ppos,
  826. dump_file,
  827. le32_to_cpu(dump_file->len));
  828. }
  829. static int ath10k_fw_crash_dump_release(struct inode *inode,
  830. struct file *file)
  831. {
  832. vfree(file->private_data);
  833. return 0;
  834. }
  835. static const struct file_operations fops_fw_crash_dump = {
  836. .open = ath10k_fw_crash_dump_open,
  837. .read = ath10k_fw_crash_dump_read,
  838. .release = ath10k_fw_crash_dump_release,
  839. .owner = THIS_MODULE,
  840. .llseek = default_llseek,
  841. };
  842. static ssize_t ath10k_reg_addr_read(struct file *file,
  843. char __user *user_buf,
  844. size_t count, loff_t *ppos)
  845. {
  846. struct ath10k *ar = file->private_data;
  847. u8 buf[32];
  848. unsigned int len = 0;
  849. u32 reg_addr;
  850. mutex_lock(&ar->conf_mutex);
  851. reg_addr = ar->debug.reg_addr;
  852. mutex_unlock(&ar->conf_mutex);
  853. len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n", reg_addr);
  854. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  855. }
  856. static ssize_t ath10k_reg_addr_write(struct file *file,
  857. const char __user *user_buf,
  858. size_t count, loff_t *ppos)
  859. {
  860. struct ath10k *ar = file->private_data;
  861. u32 reg_addr;
  862. int ret;
  863. ret = kstrtou32_from_user(user_buf, count, 0, &reg_addr);
  864. if (ret)
  865. return ret;
  866. if (!IS_ALIGNED(reg_addr, 4))
  867. return -EFAULT;
  868. mutex_lock(&ar->conf_mutex);
  869. ar->debug.reg_addr = reg_addr;
  870. mutex_unlock(&ar->conf_mutex);
  871. return count;
  872. }
  873. static const struct file_operations fops_reg_addr = {
  874. .read = ath10k_reg_addr_read,
  875. .write = ath10k_reg_addr_write,
  876. .open = simple_open,
  877. .owner = THIS_MODULE,
  878. .llseek = default_llseek,
  879. };
  880. static ssize_t ath10k_reg_value_read(struct file *file,
  881. char __user *user_buf,
  882. size_t count, loff_t *ppos)
  883. {
  884. struct ath10k *ar = file->private_data;
  885. u8 buf[48];
  886. unsigned int len;
  887. u32 reg_addr, reg_val;
  888. int ret;
  889. mutex_lock(&ar->conf_mutex);
  890. if (ar->state != ATH10K_STATE_ON &&
  891. ar->state != ATH10K_STATE_UTF) {
  892. ret = -ENETDOWN;
  893. goto exit;
  894. }
  895. reg_addr = ar->debug.reg_addr;
  896. reg_val = ath10k_hif_read32(ar, reg_addr);
  897. len = scnprintf(buf, sizeof(buf), "0x%08x:0x%08x\n", reg_addr, reg_val);
  898. ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  899. exit:
  900. mutex_unlock(&ar->conf_mutex);
  901. return ret;
  902. }
  903. static ssize_t ath10k_reg_value_write(struct file *file,
  904. const char __user *user_buf,
  905. size_t count, loff_t *ppos)
  906. {
  907. struct ath10k *ar = file->private_data;
  908. u32 reg_addr, reg_val;
  909. int ret;
  910. mutex_lock(&ar->conf_mutex);
  911. if (ar->state != ATH10K_STATE_ON &&
  912. ar->state != ATH10K_STATE_UTF) {
  913. ret = -ENETDOWN;
  914. goto exit;
  915. }
  916. reg_addr = ar->debug.reg_addr;
  917. ret = kstrtou32_from_user(user_buf, count, 0, &reg_val);
  918. if (ret)
  919. goto exit;
  920. ath10k_hif_write32(ar, reg_addr, reg_val);
  921. ret = count;
  922. exit:
  923. mutex_unlock(&ar->conf_mutex);
  924. return ret;
  925. }
  926. static const struct file_operations fops_reg_value = {
  927. .read = ath10k_reg_value_read,
  928. .write = ath10k_reg_value_write,
  929. .open = simple_open,
  930. .owner = THIS_MODULE,
  931. .llseek = default_llseek,
  932. };
  933. static ssize_t ath10k_mem_value_read(struct file *file,
  934. char __user *user_buf,
  935. size_t count, loff_t *ppos)
  936. {
  937. struct ath10k *ar = file->private_data;
  938. u8 *buf;
  939. int ret;
  940. if (*ppos < 0)
  941. return -EINVAL;
  942. if (!count)
  943. return 0;
  944. mutex_lock(&ar->conf_mutex);
  945. buf = vmalloc(count);
  946. if (!buf) {
  947. ret = -ENOMEM;
  948. goto exit;
  949. }
  950. if (ar->state != ATH10K_STATE_ON &&
  951. ar->state != ATH10K_STATE_UTF) {
  952. ret = -ENETDOWN;
  953. goto exit;
  954. }
  955. ret = ath10k_hif_diag_read(ar, *ppos, buf, count);
  956. if (ret) {
  957. ath10k_warn(ar, "failed to read address 0x%08x via diagnose window fnrom debugfs: %d\n",
  958. (u32)(*ppos), ret);
  959. goto exit;
  960. }
  961. ret = copy_to_user(user_buf, buf, count);
  962. if (ret) {
  963. ret = -EFAULT;
  964. goto exit;
  965. }
  966. count -= ret;
  967. *ppos += count;
  968. ret = count;
  969. exit:
  970. vfree(buf);
  971. mutex_unlock(&ar->conf_mutex);
  972. return ret;
  973. }
  974. static ssize_t ath10k_mem_value_write(struct file *file,
  975. const char __user *user_buf,
  976. size_t count, loff_t *ppos)
  977. {
  978. struct ath10k *ar = file->private_data;
  979. u8 *buf;
  980. int ret;
  981. if (*ppos < 0)
  982. return -EINVAL;
  983. if (!count)
  984. return 0;
  985. mutex_lock(&ar->conf_mutex);
  986. buf = vmalloc(count);
  987. if (!buf) {
  988. ret = -ENOMEM;
  989. goto exit;
  990. }
  991. if (ar->state != ATH10K_STATE_ON &&
  992. ar->state != ATH10K_STATE_UTF) {
  993. ret = -ENETDOWN;
  994. goto exit;
  995. }
  996. ret = copy_from_user(buf, user_buf, count);
  997. if (ret) {
  998. ret = -EFAULT;
  999. goto exit;
  1000. }
  1001. ret = ath10k_hif_diag_write(ar, *ppos, buf, count);
  1002. if (ret) {
  1003. ath10k_warn(ar, "failed to write address 0x%08x via diagnose window from debugfs: %d\n",
  1004. (u32)(*ppos), ret);
  1005. goto exit;
  1006. }
  1007. *ppos += count;
  1008. ret = count;
  1009. exit:
  1010. vfree(buf);
  1011. mutex_unlock(&ar->conf_mutex);
  1012. return ret;
  1013. }
  1014. static const struct file_operations fops_mem_value = {
  1015. .read = ath10k_mem_value_read,
  1016. .write = ath10k_mem_value_write,
  1017. .open = simple_open,
  1018. .owner = THIS_MODULE,
  1019. .llseek = default_llseek,
  1020. };
  1021. static int ath10k_debug_htt_stats_req(struct ath10k *ar)
  1022. {
  1023. u64 cookie;
  1024. int ret;
  1025. lockdep_assert_held(&ar->conf_mutex);
  1026. if (ar->debug.htt_stats_mask == 0)
  1027. /* htt stats are disabled */
  1028. return 0;
  1029. if (ar->state != ATH10K_STATE_ON)
  1030. return 0;
  1031. cookie = get_jiffies_64();
  1032. ret = ath10k_htt_h2t_stats_req(&ar->htt, ar->debug.htt_stats_mask,
  1033. cookie);
  1034. if (ret) {
  1035. ath10k_warn(ar, "failed to send htt stats request: %d\n", ret);
  1036. return ret;
  1037. }
  1038. queue_delayed_work(ar->workqueue, &ar->debug.htt_stats_dwork,
  1039. msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL));
  1040. return 0;
  1041. }
  1042. static void ath10k_debug_htt_stats_dwork(struct work_struct *work)
  1043. {
  1044. struct ath10k *ar = container_of(work, struct ath10k,
  1045. debug.htt_stats_dwork.work);
  1046. mutex_lock(&ar->conf_mutex);
  1047. ath10k_debug_htt_stats_req(ar);
  1048. mutex_unlock(&ar->conf_mutex);
  1049. }
  1050. static ssize_t ath10k_read_htt_stats_mask(struct file *file,
  1051. char __user *user_buf,
  1052. size_t count, loff_t *ppos)
  1053. {
  1054. struct ath10k *ar = file->private_data;
  1055. char buf[32];
  1056. unsigned int len;
  1057. len = scnprintf(buf, sizeof(buf), "%lu\n", ar->debug.htt_stats_mask);
  1058. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1059. }
  1060. static ssize_t ath10k_write_htt_stats_mask(struct file *file,
  1061. const char __user *user_buf,
  1062. size_t count, loff_t *ppos)
  1063. {
  1064. struct ath10k *ar = file->private_data;
  1065. unsigned long mask;
  1066. int ret;
  1067. ret = kstrtoul_from_user(user_buf, count, 0, &mask);
  1068. if (ret)
  1069. return ret;
  1070. /* max 8 bit masks (for now) */
  1071. if (mask > 0xff)
  1072. return -E2BIG;
  1073. mutex_lock(&ar->conf_mutex);
  1074. ar->debug.htt_stats_mask = mask;
  1075. ret = ath10k_debug_htt_stats_req(ar);
  1076. if (ret)
  1077. goto out;
  1078. ret = count;
  1079. out:
  1080. mutex_unlock(&ar->conf_mutex);
  1081. return ret;
  1082. }
  1083. static const struct file_operations fops_htt_stats_mask = {
  1084. .read = ath10k_read_htt_stats_mask,
  1085. .write = ath10k_write_htt_stats_mask,
  1086. .open = simple_open,
  1087. .owner = THIS_MODULE,
  1088. .llseek = default_llseek,
  1089. };
  1090. static ssize_t ath10k_read_htt_max_amsdu_ampdu(struct file *file,
  1091. char __user *user_buf,
  1092. size_t count, loff_t *ppos)
  1093. {
  1094. struct ath10k *ar = file->private_data;
  1095. char buf[64];
  1096. u8 amsdu = 3, ampdu = 64;
  1097. unsigned int len;
  1098. mutex_lock(&ar->conf_mutex);
  1099. if (ar->debug.htt_max_amsdu)
  1100. amsdu = ar->debug.htt_max_amsdu;
  1101. if (ar->debug.htt_max_ampdu)
  1102. ampdu = ar->debug.htt_max_ampdu;
  1103. mutex_unlock(&ar->conf_mutex);
  1104. len = scnprintf(buf, sizeof(buf), "%u %u\n", amsdu, ampdu);
  1105. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1106. }
  1107. static ssize_t ath10k_write_htt_max_amsdu_ampdu(struct file *file,
  1108. const char __user *user_buf,
  1109. size_t count, loff_t *ppos)
  1110. {
  1111. struct ath10k *ar = file->private_data;
  1112. int res;
  1113. char buf[64];
  1114. unsigned int amsdu, ampdu;
  1115. simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
  1116. /* make sure that buf is null terminated */
  1117. buf[sizeof(buf) - 1] = 0;
  1118. res = sscanf(buf, "%u %u", &amsdu, &ampdu);
  1119. if (res != 2)
  1120. return -EINVAL;
  1121. mutex_lock(&ar->conf_mutex);
  1122. res = ath10k_htt_h2t_aggr_cfg_msg(&ar->htt, ampdu, amsdu);
  1123. if (res)
  1124. goto out;
  1125. res = count;
  1126. ar->debug.htt_max_amsdu = amsdu;
  1127. ar->debug.htt_max_ampdu = ampdu;
  1128. out:
  1129. mutex_unlock(&ar->conf_mutex);
  1130. return res;
  1131. }
  1132. static const struct file_operations fops_htt_max_amsdu_ampdu = {
  1133. .read = ath10k_read_htt_max_amsdu_ampdu,
  1134. .write = ath10k_write_htt_max_amsdu_ampdu,
  1135. .open = simple_open,
  1136. .owner = THIS_MODULE,
  1137. .llseek = default_llseek,
  1138. };
  1139. static ssize_t ath10k_read_fw_dbglog(struct file *file,
  1140. char __user *user_buf,
  1141. size_t count, loff_t *ppos)
  1142. {
  1143. struct ath10k *ar = file->private_data;
  1144. unsigned int len;
  1145. char buf[64];
  1146. len = scnprintf(buf, sizeof(buf), "0x%08x %u\n",
  1147. ar->debug.fw_dbglog_mask, ar->debug.fw_dbglog_level);
  1148. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1149. }
  1150. static ssize_t ath10k_write_fw_dbglog(struct file *file,
  1151. const char __user *user_buf,
  1152. size_t count, loff_t *ppos)
  1153. {
  1154. struct ath10k *ar = file->private_data;
  1155. int ret;
  1156. char buf[64];
  1157. unsigned int log_level, mask;
  1158. simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
  1159. /* make sure that buf is null terminated */
  1160. buf[sizeof(buf) - 1] = 0;
  1161. ret = sscanf(buf, "%x %u", &mask, &log_level);
  1162. if (!ret)
  1163. return -EINVAL;
  1164. if (ret == 1)
  1165. /* default if user did not specify */
  1166. log_level = ATH10K_DBGLOG_LEVEL_WARN;
  1167. mutex_lock(&ar->conf_mutex);
  1168. ar->debug.fw_dbglog_mask = mask;
  1169. ar->debug.fw_dbglog_level = log_level;
  1170. if (ar->state == ATH10K_STATE_ON) {
  1171. ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask,
  1172. ar->debug.fw_dbglog_level);
  1173. if (ret) {
  1174. ath10k_warn(ar, "dbglog cfg failed from debugfs: %d\n",
  1175. ret);
  1176. goto exit;
  1177. }
  1178. }
  1179. ret = count;
  1180. exit:
  1181. mutex_unlock(&ar->conf_mutex);
  1182. return ret;
  1183. }
  1184. /* TODO: Would be nice to always support ethtool stats, would need to
  1185. * move the stats storage out of ath10k_debug, or always have ath10k_debug
  1186. * struct available..
  1187. */
  1188. /* This generally cooresponds to the debugfs fw_stats file */
  1189. static const char ath10k_gstrings_stats[][ETH_GSTRING_LEN] = {
  1190. "tx_pkts_nic",
  1191. "tx_bytes_nic",
  1192. "rx_pkts_nic",
  1193. "rx_bytes_nic",
  1194. "d_noise_floor",
  1195. "d_cycle_count",
  1196. "d_phy_error",
  1197. "d_rts_bad",
  1198. "d_rts_good",
  1199. "d_tx_power", /* in .5 dbM I think */
  1200. "d_rx_crc_err", /* fcs_bad */
  1201. "d_no_beacon",
  1202. "d_tx_mpdus_queued",
  1203. "d_tx_msdu_queued",
  1204. "d_tx_msdu_dropped",
  1205. "d_local_enqued",
  1206. "d_local_freed",
  1207. "d_tx_ppdu_hw_queued",
  1208. "d_tx_ppdu_reaped",
  1209. "d_tx_fifo_underrun",
  1210. "d_tx_ppdu_abort",
  1211. "d_tx_mpdu_requed",
  1212. "d_tx_excessive_retries",
  1213. "d_tx_hw_rate",
  1214. "d_tx_dropped_sw_retries",
  1215. "d_tx_illegal_rate",
  1216. "d_tx_continuous_xretries",
  1217. "d_tx_timeout",
  1218. "d_tx_mpdu_txop_limit",
  1219. "d_pdev_resets",
  1220. "d_rx_mid_ppdu_route_change",
  1221. "d_rx_status",
  1222. "d_rx_extra_frags_ring0",
  1223. "d_rx_extra_frags_ring1",
  1224. "d_rx_extra_frags_ring2",
  1225. "d_rx_extra_frags_ring3",
  1226. "d_rx_msdu_htt",
  1227. "d_rx_mpdu_htt",
  1228. "d_rx_msdu_stack",
  1229. "d_rx_mpdu_stack",
  1230. "d_rx_phy_err",
  1231. "d_rx_phy_err_drops",
  1232. "d_rx_mpdu_errors", /* FCS, MIC, ENC */
  1233. "d_fw_crash_count",
  1234. "d_fw_warm_reset_count",
  1235. "d_fw_cold_reset_count",
  1236. };
  1237. #define ATH10K_SSTATS_LEN ARRAY_SIZE(ath10k_gstrings_stats)
  1238. void ath10k_debug_get_et_strings(struct ieee80211_hw *hw,
  1239. struct ieee80211_vif *vif,
  1240. u32 sset, u8 *data)
  1241. {
  1242. if (sset == ETH_SS_STATS)
  1243. memcpy(data, *ath10k_gstrings_stats,
  1244. sizeof(ath10k_gstrings_stats));
  1245. }
  1246. int ath10k_debug_get_et_sset_count(struct ieee80211_hw *hw,
  1247. struct ieee80211_vif *vif, int sset)
  1248. {
  1249. if (sset == ETH_SS_STATS)
  1250. return ATH10K_SSTATS_LEN;
  1251. return 0;
  1252. }
  1253. void ath10k_debug_get_et_stats(struct ieee80211_hw *hw,
  1254. struct ieee80211_vif *vif,
  1255. struct ethtool_stats *stats, u64 *data)
  1256. {
  1257. struct ath10k *ar = hw->priv;
  1258. static const struct ath10k_fw_stats_pdev zero_stats = {};
  1259. const struct ath10k_fw_stats_pdev *pdev_stats;
  1260. int i = 0, ret;
  1261. mutex_lock(&ar->conf_mutex);
  1262. if (ar->state == ATH10K_STATE_ON) {
  1263. ret = ath10k_debug_fw_stats_request(ar);
  1264. if (ret) {
  1265. /* just print a warning and try to use older results */
  1266. ath10k_warn(ar,
  1267. "failed to get fw stats for ethtool: %d\n",
  1268. ret);
  1269. }
  1270. }
  1271. pdev_stats = list_first_entry_or_null(&ar->debug.fw_stats.pdevs,
  1272. struct ath10k_fw_stats_pdev,
  1273. list);
  1274. if (!pdev_stats) {
  1275. /* no results available so just return zeroes */
  1276. pdev_stats = &zero_stats;
  1277. }
  1278. spin_lock_bh(&ar->data_lock);
  1279. data[i++] = pdev_stats->hw_reaped; /* ppdu reaped */
  1280. data[i++] = 0; /* tx bytes */
  1281. data[i++] = pdev_stats->htt_mpdus;
  1282. data[i++] = 0; /* rx bytes */
  1283. data[i++] = pdev_stats->ch_noise_floor;
  1284. data[i++] = pdev_stats->cycle_count;
  1285. data[i++] = pdev_stats->phy_err_count;
  1286. data[i++] = pdev_stats->rts_bad;
  1287. data[i++] = pdev_stats->rts_good;
  1288. data[i++] = pdev_stats->chan_tx_power;
  1289. data[i++] = pdev_stats->fcs_bad;
  1290. data[i++] = pdev_stats->no_beacons;
  1291. data[i++] = pdev_stats->mpdu_enqued;
  1292. data[i++] = pdev_stats->msdu_enqued;
  1293. data[i++] = pdev_stats->wmm_drop;
  1294. data[i++] = pdev_stats->local_enqued;
  1295. data[i++] = pdev_stats->local_freed;
  1296. data[i++] = pdev_stats->hw_queued;
  1297. data[i++] = pdev_stats->hw_reaped;
  1298. data[i++] = pdev_stats->underrun;
  1299. data[i++] = pdev_stats->tx_abort;
  1300. data[i++] = pdev_stats->mpdus_requed;
  1301. data[i++] = pdev_stats->tx_ko;
  1302. data[i++] = pdev_stats->data_rc;
  1303. data[i++] = pdev_stats->sw_retry_failure;
  1304. data[i++] = pdev_stats->illgl_rate_phy_err;
  1305. data[i++] = pdev_stats->pdev_cont_xretry;
  1306. data[i++] = pdev_stats->pdev_tx_timeout;
  1307. data[i++] = pdev_stats->txop_ovf;
  1308. data[i++] = pdev_stats->pdev_resets;
  1309. data[i++] = pdev_stats->mid_ppdu_route_change;
  1310. data[i++] = pdev_stats->status_rcvd;
  1311. data[i++] = pdev_stats->r0_frags;
  1312. data[i++] = pdev_stats->r1_frags;
  1313. data[i++] = pdev_stats->r2_frags;
  1314. data[i++] = pdev_stats->r3_frags;
  1315. data[i++] = pdev_stats->htt_msdus;
  1316. data[i++] = pdev_stats->htt_mpdus;
  1317. data[i++] = pdev_stats->loc_msdus;
  1318. data[i++] = pdev_stats->loc_mpdus;
  1319. data[i++] = pdev_stats->phy_errs;
  1320. data[i++] = pdev_stats->phy_err_drop;
  1321. data[i++] = pdev_stats->mpdu_errs;
  1322. data[i++] = ar->stats.fw_crash_counter;
  1323. data[i++] = ar->stats.fw_warm_reset_counter;
  1324. data[i++] = ar->stats.fw_cold_reset_counter;
  1325. spin_unlock_bh(&ar->data_lock);
  1326. mutex_unlock(&ar->conf_mutex);
  1327. WARN_ON(i != ATH10K_SSTATS_LEN);
  1328. }
  1329. static const struct file_operations fops_fw_dbglog = {
  1330. .read = ath10k_read_fw_dbglog,
  1331. .write = ath10k_write_fw_dbglog,
  1332. .open = simple_open,
  1333. .owner = THIS_MODULE,
  1334. .llseek = default_llseek,
  1335. };
  1336. static int ath10k_debug_cal_data_open(struct inode *inode, struct file *file)
  1337. {
  1338. struct ath10k *ar = inode->i_private;
  1339. void *buf;
  1340. u32 hi_addr;
  1341. __le32 addr;
  1342. int ret;
  1343. mutex_lock(&ar->conf_mutex);
  1344. if (ar->state != ATH10K_STATE_ON &&
  1345. ar->state != ATH10K_STATE_UTF) {
  1346. ret = -ENETDOWN;
  1347. goto err;
  1348. }
  1349. buf = vmalloc(QCA988X_CAL_DATA_LEN);
  1350. if (!buf) {
  1351. ret = -ENOMEM;
  1352. goto err;
  1353. }
  1354. hi_addr = host_interest_item_address(HI_ITEM(hi_board_data));
  1355. ret = ath10k_hif_diag_read(ar, hi_addr, &addr, sizeof(addr));
  1356. if (ret) {
  1357. ath10k_warn(ar, "failed to read hi_board_data address: %d\n", ret);
  1358. goto err_vfree;
  1359. }
  1360. ret = ath10k_hif_diag_read(ar, le32_to_cpu(addr), buf,
  1361. QCA988X_CAL_DATA_LEN);
  1362. if (ret) {
  1363. ath10k_warn(ar, "failed to read calibration data: %d\n", ret);
  1364. goto err_vfree;
  1365. }
  1366. file->private_data = buf;
  1367. mutex_unlock(&ar->conf_mutex);
  1368. return 0;
  1369. err_vfree:
  1370. vfree(buf);
  1371. err:
  1372. mutex_unlock(&ar->conf_mutex);
  1373. return ret;
  1374. }
  1375. static ssize_t ath10k_debug_cal_data_read(struct file *file,
  1376. char __user *user_buf,
  1377. size_t count, loff_t *ppos)
  1378. {
  1379. void *buf = file->private_data;
  1380. return simple_read_from_buffer(user_buf, count, ppos,
  1381. buf, QCA988X_CAL_DATA_LEN);
  1382. }
  1383. static int ath10k_debug_cal_data_release(struct inode *inode,
  1384. struct file *file)
  1385. {
  1386. vfree(file->private_data);
  1387. return 0;
  1388. }
  1389. static ssize_t ath10k_write_ani_enable(struct file *file,
  1390. const char __user *user_buf,
  1391. size_t count, loff_t *ppos)
  1392. {
  1393. struct ath10k *ar = file->private_data;
  1394. int ret;
  1395. u8 enable;
  1396. if (kstrtou8_from_user(user_buf, count, 0, &enable))
  1397. return -EINVAL;
  1398. mutex_lock(&ar->conf_mutex);
  1399. if (ar->ani_enabled == enable) {
  1400. ret = count;
  1401. goto exit;
  1402. }
  1403. ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->ani_enable,
  1404. enable);
  1405. if (ret) {
  1406. ath10k_warn(ar, "ani_enable failed from debugfs: %d\n", ret);
  1407. goto exit;
  1408. }
  1409. ar->ani_enabled = enable;
  1410. ret = count;
  1411. exit:
  1412. mutex_unlock(&ar->conf_mutex);
  1413. return ret;
  1414. }
  1415. static ssize_t ath10k_read_ani_enable(struct file *file, char __user *user_buf,
  1416. size_t count, loff_t *ppos)
  1417. {
  1418. struct ath10k *ar = file->private_data;
  1419. int len = 0;
  1420. char buf[32];
  1421. len = scnprintf(buf, sizeof(buf) - len, "%d\n",
  1422. ar->ani_enabled);
  1423. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1424. }
  1425. static const struct file_operations fops_ani_enable = {
  1426. .read = ath10k_read_ani_enable,
  1427. .write = ath10k_write_ani_enable,
  1428. .open = simple_open,
  1429. .owner = THIS_MODULE,
  1430. .llseek = default_llseek,
  1431. };
  1432. static const struct file_operations fops_cal_data = {
  1433. .open = ath10k_debug_cal_data_open,
  1434. .read = ath10k_debug_cal_data_read,
  1435. .release = ath10k_debug_cal_data_release,
  1436. .owner = THIS_MODULE,
  1437. .llseek = default_llseek,
  1438. };
  1439. static ssize_t ath10k_read_nf_cal_period(struct file *file,
  1440. char __user *user_buf,
  1441. size_t count, loff_t *ppos)
  1442. {
  1443. struct ath10k *ar = file->private_data;
  1444. unsigned int len;
  1445. char buf[32];
  1446. len = scnprintf(buf, sizeof(buf), "%d\n",
  1447. ar->debug.nf_cal_period);
  1448. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1449. }
  1450. static ssize_t ath10k_write_nf_cal_period(struct file *file,
  1451. const char __user *user_buf,
  1452. size_t count, loff_t *ppos)
  1453. {
  1454. struct ath10k *ar = file->private_data;
  1455. unsigned long period;
  1456. int ret;
  1457. ret = kstrtoul_from_user(user_buf, count, 0, &period);
  1458. if (ret)
  1459. return ret;
  1460. if (period > WMI_PDEV_PARAM_CAL_PERIOD_MAX)
  1461. return -EINVAL;
  1462. /* there's no way to switch back to the firmware default */
  1463. if (period == 0)
  1464. return -EINVAL;
  1465. mutex_lock(&ar->conf_mutex);
  1466. ar->debug.nf_cal_period = period;
  1467. if (ar->state != ATH10K_STATE_ON) {
  1468. /* firmware is not running, nothing else to do */
  1469. ret = count;
  1470. goto exit;
  1471. }
  1472. ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->cal_period,
  1473. ar->debug.nf_cal_period);
  1474. if (ret) {
  1475. ath10k_warn(ar, "cal period cfg failed from debugfs: %d\n",
  1476. ret);
  1477. goto exit;
  1478. }
  1479. ret = count;
  1480. exit:
  1481. mutex_unlock(&ar->conf_mutex);
  1482. return ret;
  1483. }
  1484. static const struct file_operations fops_nf_cal_period = {
  1485. .read = ath10k_read_nf_cal_period,
  1486. .write = ath10k_write_nf_cal_period,
  1487. .open = simple_open,
  1488. .owner = THIS_MODULE,
  1489. .llseek = default_llseek,
  1490. };
  1491. int ath10k_debug_start(struct ath10k *ar)
  1492. {
  1493. int ret;
  1494. lockdep_assert_held(&ar->conf_mutex);
  1495. ret = ath10k_debug_htt_stats_req(ar);
  1496. if (ret)
  1497. /* continue normally anyway, this isn't serious */
  1498. ath10k_warn(ar, "failed to start htt stats workqueue: %d\n",
  1499. ret);
  1500. if (ar->debug.fw_dbglog_mask) {
  1501. ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask,
  1502. ATH10K_DBGLOG_LEVEL_WARN);
  1503. if (ret)
  1504. /* not serious */
  1505. ath10k_warn(ar, "failed to enable dbglog during start: %d",
  1506. ret);
  1507. }
  1508. if (ar->debug.pktlog_filter) {
  1509. ret = ath10k_wmi_pdev_pktlog_enable(ar,
  1510. ar->debug.pktlog_filter);
  1511. if (ret)
  1512. /* not serious */
  1513. ath10k_warn(ar,
  1514. "failed to enable pktlog filter %x: %d\n",
  1515. ar->debug.pktlog_filter, ret);
  1516. } else {
  1517. ret = ath10k_wmi_pdev_pktlog_disable(ar);
  1518. if (ret)
  1519. /* not serious */
  1520. ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
  1521. }
  1522. if (ar->debug.nf_cal_period) {
  1523. ret = ath10k_wmi_pdev_set_param(ar,
  1524. ar->wmi.pdev_param->cal_period,
  1525. ar->debug.nf_cal_period);
  1526. if (ret)
  1527. /* not serious */
  1528. ath10k_warn(ar, "cal period cfg failed from debug start: %d\n",
  1529. ret);
  1530. }
  1531. return ret;
  1532. }
  1533. void ath10k_debug_stop(struct ath10k *ar)
  1534. {
  1535. lockdep_assert_held(&ar->conf_mutex);
  1536. /* Must not use _sync to avoid deadlock, we do that in
  1537. * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid
  1538. * warning from del_timer(). */
  1539. if (ar->debug.htt_stats_mask != 0)
  1540. cancel_delayed_work(&ar->debug.htt_stats_dwork);
  1541. ar->debug.htt_max_amsdu = 0;
  1542. ar->debug.htt_max_ampdu = 0;
  1543. ath10k_wmi_pdev_pktlog_disable(ar);
  1544. }
  1545. static ssize_t ath10k_write_simulate_radar(struct file *file,
  1546. const char __user *user_buf,
  1547. size_t count, loff_t *ppos)
  1548. {
  1549. struct ath10k *ar = file->private_data;
  1550. ieee80211_radar_detected(ar->hw);
  1551. return count;
  1552. }
  1553. static const struct file_operations fops_simulate_radar = {
  1554. .write = ath10k_write_simulate_radar,
  1555. .open = simple_open,
  1556. .owner = THIS_MODULE,
  1557. .llseek = default_llseek,
  1558. };
  1559. #define ATH10K_DFS_STAT(s, p) (\
  1560. len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
  1561. ar->debug.dfs_stats.p))
  1562. #define ATH10K_DFS_POOL_STAT(s, p) (\
  1563. len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
  1564. ar->debug.dfs_pool_stats.p))
  1565. static ssize_t ath10k_read_dfs_stats(struct file *file, char __user *user_buf,
  1566. size_t count, loff_t *ppos)
  1567. {
  1568. int retval = 0, len = 0;
  1569. const int size = 8000;
  1570. struct ath10k *ar = file->private_data;
  1571. char *buf;
  1572. buf = kzalloc(size, GFP_KERNEL);
  1573. if (buf == NULL)
  1574. return -ENOMEM;
  1575. if (!ar->dfs_detector) {
  1576. len += scnprintf(buf + len, size - len, "DFS not enabled\n");
  1577. goto exit;
  1578. }
  1579. ar->debug.dfs_pool_stats =
  1580. ar->dfs_detector->get_stats(ar->dfs_detector);
  1581. len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
  1582. ATH10K_DFS_STAT("reported phy errors", phy_errors);
  1583. ATH10K_DFS_STAT("pulse events reported", pulses_total);
  1584. ATH10K_DFS_STAT("DFS pulses detected", pulses_detected);
  1585. ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded);
  1586. ATH10K_DFS_STAT("Radars detected", radar_detected);
  1587. len += scnprintf(buf + len, size - len, "Global Pool statistics:\n");
  1588. ATH10K_DFS_POOL_STAT("Pool references", pool_reference);
  1589. ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated);
  1590. ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error);
  1591. ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used);
  1592. ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated);
  1593. ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error);
  1594. ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used);
  1595. exit:
  1596. if (len > size)
  1597. len = size;
  1598. retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1599. kfree(buf);
  1600. return retval;
  1601. }
  1602. static const struct file_operations fops_dfs_stats = {
  1603. .read = ath10k_read_dfs_stats,
  1604. .open = simple_open,
  1605. .owner = THIS_MODULE,
  1606. .llseek = default_llseek,
  1607. };
  1608. static ssize_t ath10k_write_pktlog_filter(struct file *file,
  1609. const char __user *ubuf,
  1610. size_t count, loff_t *ppos)
  1611. {
  1612. struct ath10k *ar = file->private_data;
  1613. u32 filter;
  1614. int ret;
  1615. if (kstrtouint_from_user(ubuf, count, 0, &filter))
  1616. return -EINVAL;
  1617. mutex_lock(&ar->conf_mutex);
  1618. if (ar->state != ATH10K_STATE_ON) {
  1619. ar->debug.pktlog_filter = filter;
  1620. ret = count;
  1621. goto out;
  1622. }
  1623. if (filter && (filter != ar->debug.pktlog_filter)) {
  1624. ret = ath10k_wmi_pdev_pktlog_enable(ar, filter);
  1625. if (ret) {
  1626. ath10k_warn(ar, "failed to enable pktlog filter %x: %d\n",
  1627. ar->debug.pktlog_filter, ret);
  1628. goto out;
  1629. }
  1630. } else {
  1631. ret = ath10k_wmi_pdev_pktlog_disable(ar);
  1632. if (ret) {
  1633. ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
  1634. goto out;
  1635. }
  1636. }
  1637. ar->debug.pktlog_filter = filter;
  1638. ret = count;
  1639. out:
  1640. mutex_unlock(&ar->conf_mutex);
  1641. return ret;
  1642. }
  1643. static ssize_t ath10k_read_pktlog_filter(struct file *file, char __user *ubuf,
  1644. size_t count, loff_t *ppos)
  1645. {
  1646. char buf[32];
  1647. struct ath10k *ar = file->private_data;
  1648. int len = 0;
  1649. mutex_lock(&ar->conf_mutex);
  1650. len = scnprintf(buf, sizeof(buf) - len, "%08x\n",
  1651. ar->debug.pktlog_filter);
  1652. mutex_unlock(&ar->conf_mutex);
  1653. return simple_read_from_buffer(ubuf, count, ppos, buf, len);
  1654. }
  1655. static const struct file_operations fops_pktlog_filter = {
  1656. .read = ath10k_read_pktlog_filter,
  1657. .write = ath10k_write_pktlog_filter,
  1658. .open = simple_open
  1659. };
  1660. static ssize_t ath10k_write_quiet_period(struct file *file,
  1661. const char __user *ubuf,
  1662. size_t count, loff_t *ppos)
  1663. {
  1664. struct ath10k *ar = file->private_data;
  1665. u32 period;
  1666. if (kstrtouint_from_user(ubuf, count, 0, &period))
  1667. return -EINVAL;
  1668. if (period < ATH10K_QUIET_PERIOD_MIN) {
  1669. ath10k_warn(ar, "Quiet period %u can not be lesser than 25ms\n",
  1670. period);
  1671. return -EINVAL;
  1672. }
  1673. mutex_lock(&ar->conf_mutex);
  1674. ar->thermal.quiet_period = period;
  1675. ath10k_thermal_set_throttling(ar);
  1676. mutex_unlock(&ar->conf_mutex);
  1677. return count;
  1678. }
  1679. static ssize_t ath10k_read_quiet_period(struct file *file, char __user *ubuf,
  1680. size_t count, loff_t *ppos)
  1681. {
  1682. char buf[32];
  1683. struct ath10k *ar = file->private_data;
  1684. int len = 0;
  1685. mutex_lock(&ar->conf_mutex);
  1686. len = scnprintf(buf, sizeof(buf) - len, "%d\n",
  1687. ar->thermal.quiet_period);
  1688. mutex_unlock(&ar->conf_mutex);
  1689. return simple_read_from_buffer(ubuf, count, ppos, buf, len);
  1690. }
  1691. static const struct file_operations fops_quiet_period = {
  1692. .read = ath10k_read_quiet_period,
  1693. .write = ath10k_write_quiet_period,
  1694. .open = simple_open
  1695. };
  1696. int ath10k_debug_create(struct ath10k *ar)
  1697. {
  1698. ar->debug.fw_crash_data = vzalloc(sizeof(*ar->debug.fw_crash_data));
  1699. if (!ar->debug.fw_crash_data)
  1700. return -ENOMEM;
  1701. INIT_LIST_HEAD(&ar->debug.fw_stats.pdevs);
  1702. INIT_LIST_HEAD(&ar->debug.fw_stats.vdevs);
  1703. INIT_LIST_HEAD(&ar->debug.fw_stats.peers);
  1704. return 0;
  1705. }
  1706. void ath10k_debug_destroy(struct ath10k *ar)
  1707. {
  1708. vfree(ar->debug.fw_crash_data);
  1709. ar->debug.fw_crash_data = NULL;
  1710. ath10k_debug_fw_stats_reset(ar);
  1711. }
  1712. int ath10k_debug_register(struct ath10k *ar)
  1713. {
  1714. ar->debug.debugfs_phy = debugfs_create_dir("ath10k",
  1715. ar->hw->wiphy->debugfsdir);
  1716. if (IS_ERR_OR_NULL(ar->debug.debugfs_phy)) {
  1717. if (IS_ERR(ar->debug.debugfs_phy))
  1718. return PTR_ERR(ar->debug.debugfs_phy);
  1719. return -ENOMEM;
  1720. }
  1721. INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork,
  1722. ath10k_debug_htt_stats_dwork);
  1723. init_completion(&ar->debug.fw_stats_complete);
  1724. debugfs_create_file("fw_stats", S_IRUSR, ar->debug.debugfs_phy, ar,
  1725. &fops_fw_stats);
  1726. debugfs_create_file("fw_reset_stats", S_IRUSR, ar->debug.debugfs_phy,
  1727. ar, &fops_fw_reset_stats);
  1728. debugfs_create_file("wmi_services", S_IRUSR, ar->debug.debugfs_phy, ar,
  1729. &fops_wmi_services);
  1730. debugfs_create_file("simulate_fw_crash", S_IRUSR, ar->debug.debugfs_phy,
  1731. ar, &fops_simulate_fw_crash);
  1732. debugfs_create_file("fw_crash_dump", S_IRUSR, ar->debug.debugfs_phy,
  1733. ar, &fops_fw_crash_dump);
  1734. debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR,
  1735. ar->debug.debugfs_phy, ar, &fops_reg_addr);
  1736. debugfs_create_file("reg_value", S_IRUSR | S_IWUSR,
  1737. ar->debug.debugfs_phy, ar, &fops_reg_value);
  1738. debugfs_create_file("mem_value", S_IRUSR | S_IWUSR,
  1739. ar->debug.debugfs_phy, ar, &fops_mem_value);
  1740. debugfs_create_file("chip_id", S_IRUSR, ar->debug.debugfs_phy,
  1741. ar, &fops_chip_id);
  1742. debugfs_create_file("htt_stats_mask", S_IRUSR, ar->debug.debugfs_phy,
  1743. ar, &fops_htt_stats_mask);
  1744. debugfs_create_file("htt_max_amsdu_ampdu", S_IRUSR | S_IWUSR,
  1745. ar->debug.debugfs_phy, ar,
  1746. &fops_htt_max_amsdu_ampdu);
  1747. debugfs_create_file("fw_dbglog", S_IRUSR, ar->debug.debugfs_phy,
  1748. ar, &fops_fw_dbglog);
  1749. debugfs_create_file("cal_data", S_IRUSR, ar->debug.debugfs_phy,
  1750. ar, &fops_cal_data);
  1751. debugfs_create_file("ani_enable", S_IRUSR | S_IWUSR,
  1752. ar->debug.debugfs_phy, ar, &fops_ani_enable);
  1753. debugfs_create_file("nf_cal_period", S_IRUSR | S_IWUSR,
  1754. ar->debug.debugfs_phy, ar, &fops_nf_cal_period);
  1755. if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
  1756. debugfs_create_file("dfs_simulate_radar", S_IWUSR,
  1757. ar->debug.debugfs_phy, ar,
  1758. &fops_simulate_radar);
  1759. debugfs_create_bool("dfs_block_radar_events", S_IWUSR,
  1760. ar->debug.debugfs_phy,
  1761. &ar->dfs_block_radar_events);
  1762. debugfs_create_file("dfs_stats", S_IRUSR,
  1763. ar->debug.debugfs_phy, ar,
  1764. &fops_dfs_stats);
  1765. }
  1766. debugfs_create_file("pktlog_filter", S_IRUGO | S_IWUSR,
  1767. ar->debug.debugfs_phy, ar, &fops_pktlog_filter);
  1768. debugfs_create_file("quiet_period", S_IRUGO | S_IWUSR,
  1769. ar->debug.debugfs_phy, ar, &fops_quiet_period);
  1770. return 0;
  1771. }
  1772. void ath10k_debug_unregister(struct ath10k *ar)
  1773. {
  1774. cancel_delayed_work_sync(&ar->debug.htt_stats_dwork);
  1775. }
  1776. #endif /* CONFIG_ATH10K_DEBUGFS */
  1777. #ifdef CONFIG_ATH10K_DEBUG
  1778. void ath10k_dbg(struct ath10k *ar, enum ath10k_debug_mask mask,
  1779. const char *fmt, ...)
  1780. {
  1781. struct va_format vaf;
  1782. va_list args;
  1783. va_start(args, fmt);
  1784. vaf.fmt = fmt;
  1785. vaf.va = &args;
  1786. if (ath10k_debug_mask & mask)
  1787. dev_printk(KERN_DEBUG, ar->dev, "%pV", &vaf);
  1788. trace_ath10k_log_dbg(ar, mask, &vaf);
  1789. va_end(args);
  1790. }
  1791. EXPORT_SYMBOL(ath10k_dbg);
  1792. void ath10k_dbg_dump(struct ath10k *ar,
  1793. enum ath10k_debug_mask mask,
  1794. const char *msg, const char *prefix,
  1795. const void *buf, size_t len)
  1796. {
  1797. char linebuf[256];
  1798. unsigned int linebuflen;
  1799. const void *ptr;
  1800. if (ath10k_debug_mask & mask) {
  1801. if (msg)
  1802. ath10k_dbg(ar, mask, "%s\n", msg);
  1803. for (ptr = buf; (ptr - buf) < len; ptr += 16) {
  1804. linebuflen = 0;
  1805. linebuflen += scnprintf(linebuf + linebuflen,
  1806. sizeof(linebuf) - linebuflen,
  1807. "%s%08x: ",
  1808. (prefix ? prefix : ""),
  1809. (unsigned int)(ptr - buf));
  1810. hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1,
  1811. linebuf + linebuflen,
  1812. sizeof(linebuf) - linebuflen, true);
  1813. dev_printk(KERN_DEBUG, ar->dev, "%s\n", linebuf);
  1814. }
  1815. }
  1816. /* tracing code doesn't like null strings :/ */
  1817. trace_ath10k_log_dbg_dump(ar, msg ? msg : "", prefix ? prefix : "",
  1818. buf, len);
  1819. }
  1820. EXPORT_SYMBOL(ath10k_dbg_dump);
  1821. #endif /* CONFIG_ATH10K_DEBUG */