debug.c 54 KB

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