iwl-debugfs.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2009 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *****************************************************************************/
  28. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/debugfs.h>
  31. #include <linux/ieee80211.h>
  32. #include <net/mac80211.h>
  33. #include "iwl-dev.h"
  34. #include "iwl-debug.h"
  35. #include "iwl-core.h"
  36. #include "iwl-io.h"
  37. #include "iwl-calib.h"
  38. /* create and remove of files */
  39. #define DEBUGFS_ADD_DIR(name, parent) do { \
  40. dbgfs->dir_##name = debugfs_create_dir(#name, parent); \
  41. if (!(dbgfs->dir_##name)) \
  42. goto err; \
  43. } while (0)
  44. #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
  45. dbgfs->dbgfs_##parent##_files.file_##name = \
  46. debugfs_create_file(#name, mode, \
  47. dbgfs->dir_##parent, priv, \
  48. &iwl_dbgfs_##name##_ops); \
  49. if (!(dbgfs->dbgfs_##parent##_files.file_##name)) \
  50. goto err; \
  51. } while (0)
  52. #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
  53. dbgfs->dbgfs_##parent##_files.file_##name = \
  54. debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
  55. dbgfs->dir_##parent, ptr); \
  56. if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
  57. || !dbgfs->dbgfs_##parent##_files.file_##name) \
  58. goto err; \
  59. } while (0)
  60. #define DEBUGFS_ADD_X32(name, parent, ptr) do { \
  61. dbgfs->dbgfs_##parent##_files.file_##name = \
  62. debugfs_create_x32(#name, S_IRUSR, dbgfs->dir_##parent, ptr); \
  63. if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
  64. || !dbgfs->dbgfs_##parent##_files.file_##name) \
  65. goto err; \
  66. } while (0)
  67. #define DEBUGFS_REMOVE(name) do { \
  68. debugfs_remove(name); \
  69. name = NULL; \
  70. } while (0);
  71. /* file operation */
  72. #define DEBUGFS_READ_FUNC(name) \
  73. static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
  74. char __user *user_buf, \
  75. size_t count, loff_t *ppos);
  76. #define DEBUGFS_WRITE_FUNC(name) \
  77. static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
  78. const char __user *user_buf, \
  79. size_t count, loff_t *ppos);
  80. static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
  81. {
  82. file->private_data = inode->i_private;
  83. return 0;
  84. }
  85. #define DEBUGFS_READ_FILE_OPS(name) \
  86. DEBUGFS_READ_FUNC(name); \
  87. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  88. .read = iwl_dbgfs_##name##_read, \
  89. .open = iwl_dbgfs_open_file_generic, \
  90. };
  91. #define DEBUGFS_WRITE_FILE_OPS(name) \
  92. DEBUGFS_WRITE_FUNC(name); \
  93. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  94. .write = iwl_dbgfs_##name##_write, \
  95. .open = iwl_dbgfs_open_file_generic, \
  96. };
  97. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  98. DEBUGFS_READ_FUNC(name); \
  99. DEBUGFS_WRITE_FUNC(name); \
  100. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  101. .write = iwl_dbgfs_##name##_write, \
  102. .read = iwl_dbgfs_##name##_read, \
  103. .open = iwl_dbgfs_open_file_generic, \
  104. };
  105. static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
  106. char __user *user_buf,
  107. size_t count, loff_t *ppos) {
  108. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  109. char *buf;
  110. int pos = 0;
  111. int cnt;
  112. ssize_t ret;
  113. const size_t bufsz = 100 +
  114. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  115. buf = kzalloc(bufsz, GFP_KERNEL);
  116. if (!buf)
  117. return -ENOMEM;
  118. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  119. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  120. pos += scnprintf(buf + pos, bufsz - pos,
  121. "\t%25s\t\t: %u\n",
  122. get_mgmt_string(cnt),
  123. priv->tx_stats.mgmt[cnt]);
  124. }
  125. pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
  126. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  127. pos += scnprintf(buf + pos, bufsz - pos,
  128. "\t%25s\t\t: %u\n",
  129. get_ctrl_string(cnt),
  130. priv->tx_stats.ctrl[cnt]);
  131. }
  132. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  133. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  134. priv->tx_stats.data_cnt);
  135. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  136. priv->tx_stats.data_bytes);
  137. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  138. kfree(buf);
  139. return ret;
  140. }
  141. static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
  142. const char __user *user_buf,
  143. size_t count, loff_t *ppos)
  144. {
  145. struct iwl_priv *priv = file->private_data;
  146. u32 clear_flag;
  147. char buf[8];
  148. int buf_size;
  149. memset(buf, 0, sizeof(buf));
  150. buf_size = min(count, sizeof(buf) - 1);
  151. if (copy_from_user(buf, user_buf, buf_size))
  152. return -EFAULT;
  153. if (sscanf(buf, "%x", &clear_flag) != 1)
  154. return -EFAULT;
  155. iwl_clear_traffic_stats(priv);
  156. return count;
  157. }
  158. static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
  159. char __user *user_buf,
  160. size_t count, loff_t *ppos) {
  161. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  162. char *buf;
  163. int pos = 0;
  164. int cnt;
  165. ssize_t ret;
  166. const size_t bufsz = 100 +
  167. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  168. buf = kzalloc(bufsz, GFP_KERNEL);
  169. if (!buf)
  170. return -ENOMEM;
  171. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  172. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  173. pos += scnprintf(buf + pos, bufsz - pos,
  174. "\t%25s\t\t: %u\n",
  175. get_mgmt_string(cnt),
  176. priv->rx_stats.mgmt[cnt]);
  177. }
  178. pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
  179. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  180. pos += scnprintf(buf + pos, bufsz - pos,
  181. "\t%25s\t\t: %u\n",
  182. get_ctrl_string(cnt),
  183. priv->rx_stats.ctrl[cnt]);
  184. }
  185. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  186. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  187. priv->rx_stats.data_cnt);
  188. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  189. priv->rx_stats.data_bytes);
  190. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  191. kfree(buf);
  192. return ret;
  193. }
  194. #define BYTE1_MASK 0x000000ff;
  195. #define BYTE2_MASK 0x0000ffff;
  196. #define BYTE3_MASK 0x00ffffff;
  197. static ssize_t iwl_dbgfs_sram_read(struct file *file,
  198. char __user *user_buf,
  199. size_t count, loff_t *ppos)
  200. {
  201. u32 val;
  202. char *buf;
  203. ssize_t ret;
  204. int i;
  205. int pos = 0;
  206. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  207. size_t bufsz;
  208. /* default is to dump the entire data segment */
  209. if (!priv->dbgfs->sram_offset && !priv->dbgfs->sram_len) {
  210. priv->dbgfs->sram_offset = 0x800000;
  211. if (priv->ucode_type == UCODE_INIT)
  212. priv->dbgfs->sram_len = priv->ucode_init_data.len;
  213. else
  214. priv->dbgfs->sram_len = priv->ucode_data.len;
  215. }
  216. bufsz = 30 + priv->dbgfs->sram_len * sizeof(char) * 10;
  217. buf = kmalloc(bufsz, GFP_KERNEL);
  218. if (!buf)
  219. return -ENOMEM;
  220. pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
  221. priv->dbgfs->sram_len);
  222. pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
  223. priv->dbgfs->sram_offset);
  224. for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
  225. val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
  226. priv->dbgfs->sram_len - i);
  227. if (i < 4) {
  228. switch (i) {
  229. case 1:
  230. val &= BYTE1_MASK;
  231. break;
  232. case 2:
  233. val &= BYTE2_MASK;
  234. break;
  235. case 3:
  236. val &= BYTE3_MASK;
  237. break;
  238. }
  239. }
  240. if (!(i % 16))
  241. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  242. pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
  243. }
  244. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  245. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  246. kfree(buf);
  247. return ret;
  248. }
  249. static ssize_t iwl_dbgfs_sram_write(struct file *file,
  250. const char __user *user_buf,
  251. size_t count, loff_t *ppos)
  252. {
  253. struct iwl_priv *priv = file->private_data;
  254. char buf[64];
  255. int buf_size;
  256. u32 offset, len;
  257. memset(buf, 0, sizeof(buf));
  258. buf_size = min(count, sizeof(buf) - 1);
  259. if (copy_from_user(buf, user_buf, buf_size))
  260. return -EFAULT;
  261. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  262. priv->dbgfs->sram_offset = offset;
  263. priv->dbgfs->sram_len = len;
  264. } else {
  265. priv->dbgfs->sram_offset = 0;
  266. priv->dbgfs->sram_len = 0;
  267. }
  268. return count;
  269. }
  270. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  271. size_t count, loff_t *ppos)
  272. {
  273. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  274. struct iwl_station_entry *station;
  275. int max_sta = priv->hw_params.max_stations;
  276. char *buf;
  277. int i, j, pos = 0;
  278. ssize_t ret;
  279. /* Add 30 for initial string */
  280. const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
  281. buf = kmalloc(bufsz, GFP_KERNEL);
  282. if (!buf)
  283. return -ENOMEM;
  284. pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
  285. priv->num_stations);
  286. for (i = 0; i < max_sta; i++) {
  287. station = &priv->stations[i];
  288. if (station->used) {
  289. pos += scnprintf(buf + pos, bufsz - pos,
  290. "station %d:\ngeneral data:\n", i+1);
  291. pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
  292. station->sta.sta.sta_id);
  293. pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
  294. station->sta.mode);
  295. pos += scnprintf(buf + pos, bufsz - pos,
  296. "flags: 0x%x\n",
  297. station->sta.station_flags_msk);
  298. pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
  299. pos += scnprintf(buf + pos, bufsz - pos,
  300. "seq_num\t\ttxq_id");
  301. pos += scnprintf(buf + pos, bufsz - pos,
  302. "\tframe_count\twait_for_ba\t");
  303. pos += scnprintf(buf + pos, bufsz - pos,
  304. "start_idx\tbitmap0\t");
  305. pos += scnprintf(buf + pos, bufsz - pos,
  306. "bitmap1\trate_n_flags");
  307. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  308. for (j = 0; j < MAX_TID_COUNT; j++) {
  309. pos += scnprintf(buf + pos, bufsz - pos,
  310. "[%d]:\t\t%u", j,
  311. station->tid[j].seq_number);
  312. pos += scnprintf(buf + pos, bufsz - pos,
  313. "\t%u\t\t%u\t\t%u\t\t",
  314. station->tid[j].agg.txq_id,
  315. station->tid[j].agg.frame_count,
  316. station->tid[j].agg.wait_for_ba);
  317. pos += scnprintf(buf + pos, bufsz - pos,
  318. "%u\t%llu\t%u",
  319. station->tid[j].agg.start_idx,
  320. (unsigned long long)station->tid[j].agg.bitmap,
  321. station->tid[j].agg.rate_n_flags);
  322. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  323. }
  324. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  325. }
  326. }
  327. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  328. kfree(buf);
  329. return ret;
  330. }
  331. static ssize_t iwl_dbgfs_nvm_read(struct file *file,
  332. char __user *user_buf,
  333. size_t count,
  334. loff_t *ppos)
  335. {
  336. ssize_t ret;
  337. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  338. int pos = 0, ofs = 0, buf_size = 0;
  339. const u8 *ptr;
  340. char *buf;
  341. u16 eeprom_ver;
  342. size_t eeprom_len = priv->cfg->eeprom_size;
  343. buf_size = 4 * eeprom_len + 256;
  344. if (eeprom_len % 16) {
  345. IWL_ERR(priv, "NVM size is not multiple of 16.\n");
  346. return -ENODATA;
  347. }
  348. ptr = priv->eeprom;
  349. if (!ptr) {
  350. IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
  351. return -ENOMEM;
  352. }
  353. /* 4 characters for byte 0xYY */
  354. buf = kzalloc(buf_size, GFP_KERNEL);
  355. if (!buf) {
  356. IWL_ERR(priv, "Can not allocate Buffer\n");
  357. return -ENOMEM;
  358. }
  359. eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
  360. pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
  361. "version: 0x%x\n",
  362. (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
  363. ? "OTP" : "EEPROM", eeprom_ver);
  364. for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
  365. pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
  366. hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
  367. buf_size - pos, 0);
  368. pos += strlen(buf + pos);
  369. if (buf_size - pos > 0)
  370. buf[pos++] = '\n';
  371. }
  372. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  373. kfree(buf);
  374. return ret;
  375. }
  376. static ssize_t iwl_dbgfs_log_event_write(struct file *file,
  377. const char __user *user_buf,
  378. size_t count, loff_t *ppos)
  379. {
  380. struct iwl_priv *priv = file->private_data;
  381. u32 event_log_flag;
  382. char buf[8];
  383. int buf_size;
  384. memset(buf, 0, sizeof(buf));
  385. buf_size = min(count, sizeof(buf) - 1);
  386. if (copy_from_user(buf, user_buf, buf_size))
  387. return -EFAULT;
  388. if (sscanf(buf, "%d", &event_log_flag) != 1)
  389. return -EFAULT;
  390. if (event_log_flag == 1)
  391. priv->cfg->ops->lib->dump_nic_event_log(priv, true);
  392. return count;
  393. }
  394. static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
  395. size_t count, loff_t *ppos)
  396. {
  397. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  398. struct ieee80211_channel *channels = NULL;
  399. const struct ieee80211_supported_band *supp_band = NULL;
  400. int pos = 0, i, bufsz = PAGE_SIZE;
  401. char *buf;
  402. ssize_t ret;
  403. if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
  404. return -EAGAIN;
  405. buf = kzalloc(bufsz, GFP_KERNEL);
  406. if (!buf) {
  407. IWL_ERR(priv, "Can not allocate Buffer\n");
  408. return -ENOMEM;
  409. }
  410. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
  411. if (supp_band) {
  412. channels = supp_band->channels;
  413. pos += scnprintf(buf + pos, bufsz - pos,
  414. "Displaying %d channels in 2.4GHz band 802.11bg):\n",
  415. supp_band->n_channels);
  416. for (i = 0; i < supp_band->n_channels; i++)
  417. pos += scnprintf(buf + pos, bufsz - pos,
  418. "%d: %ddBm: BSS%s%s, %s.\n",
  419. ieee80211_frequency_to_channel(
  420. channels[i].center_freq),
  421. channels[i].max_power,
  422. channels[i].flags & IEEE80211_CHAN_RADAR ?
  423. " (IEEE 802.11h required)" : "",
  424. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  425. || (channels[i].flags &
  426. IEEE80211_CHAN_RADAR)) ? "" :
  427. ", IBSS",
  428. channels[i].flags &
  429. IEEE80211_CHAN_PASSIVE_SCAN ?
  430. "passive only" : "active/passive");
  431. }
  432. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
  433. if (supp_band) {
  434. channels = supp_band->channels;
  435. pos += scnprintf(buf + pos, bufsz - pos,
  436. "Displaying %d channels in 5.2GHz band (802.11a)\n",
  437. supp_band->n_channels);
  438. for (i = 0; i < supp_band->n_channels; i++)
  439. pos += scnprintf(buf + pos, bufsz - pos,
  440. "%d: %ddBm: BSS%s%s, %s.\n",
  441. ieee80211_frequency_to_channel(
  442. channels[i].center_freq),
  443. channels[i].max_power,
  444. channels[i].flags & IEEE80211_CHAN_RADAR ?
  445. " (IEEE 802.11h required)" : "",
  446. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  447. || (channels[i].flags &
  448. IEEE80211_CHAN_RADAR)) ? "" :
  449. ", IBSS",
  450. channels[i].flags &
  451. IEEE80211_CHAN_PASSIVE_SCAN ?
  452. "passive only" : "active/passive");
  453. }
  454. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  455. kfree(buf);
  456. return ret;
  457. }
  458. static ssize_t iwl_dbgfs_status_read(struct file *file,
  459. char __user *user_buf,
  460. size_t count, loff_t *ppos) {
  461. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  462. char buf[512];
  463. int pos = 0;
  464. const size_t bufsz = sizeof(buf);
  465. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
  466. test_bit(STATUS_HCMD_ACTIVE, &priv->status));
  467. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
  468. test_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status));
  469. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
  470. test_bit(STATUS_INT_ENABLED, &priv->status));
  471. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
  472. test_bit(STATUS_RF_KILL_HW, &priv->status));
  473. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
  474. test_bit(STATUS_CT_KILL, &priv->status));
  475. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
  476. test_bit(STATUS_INIT, &priv->status));
  477. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
  478. test_bit(STATUS_ALIVE, &priv->status));
  479. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
  480. test_bit(STATUS_READY, &priv->status));
  481. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
  482. test_bit(STATUS_TEMPERATURE, &priv->status));
  483. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
  484. test_bit(STATUS_GEO_CONFIGURED, &priv->status));
  485. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
  486. test_bit(STATUS_EXIT_PENDING, &priv->status));
  487. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
  488. test_bit(STATUS_STATISTICS, &priv->status));
  489. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
  490. test_bit(STATUS_SCANNING, &priv->status));
  491. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
  492. test_bit(STATUS_SCAN_ABORTING, &priv->status));
  493. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
  494. test_bit(STATUS_SCAN_HW, &priv->status));
  495. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
  496. test_bit(STATUS_POWER_PMI, &priv->status));
  497. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
  498. test_bit(STATUS_FW_ERROR, &priv->status));
  499. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_MODE_PENDING:\t %d\n",
  500. test_bit(STATUS_MODE_PENDING, &priv->status));
  501. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  502. }
  503. static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
  504. char __user *user_buf,
  505. size_t count, loff_t *ppos) {
  506. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  507. int pos = 0;
  508. int cnt = 0;
  509. char *buf;
  510. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  511. ssize_t ret;
  512. buf = kzalloc(bufsz, GFP_KERNEL);
  513. if (!buf) {
  514. IWL_ERR(priv, "Can not allocate Buffer\n");
  515. return -ENOMEM;
  516. }
  517. pos += scnprintf(buf + pos, bufsz - pos,
  518. "Interrupt Statistics Report:\n");
  519. pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
  520. priv->isr_stats.hw);
  521. pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
  522. priv->isr_stats.sw);
  523. if (priv->isr_stats.sw > 0) {
  524. pos += scnprintf(buf + pos, bufsz - pos,
  525. "\tLast Restarting Code: 0x%X\n",
  526. priv->isr_stats.sw_err);
  527. }
  528. #ifdef CONFIG_IWLWIFI_DEBUG
  529. pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
  530. priv->isr_stats.sch);
  531. pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
  532. priv->isr_stats.alive);
  533. #endif
  534. pos += scnprintf(buf + pos, bufsz - pos,
  535. "HW RF KILL switch toggled:\t %u\n",
  536. priv->isr_stats.rfkill);
  537. pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
  538. priv->isr_stats.ctkill);
  539. pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
  540. priv->isr_stats.wakeup);
  541. pos += scnprintf(buf + pos, bufsz - pos,
  542. "Rx command responses:\t\t %u\n",
  543. priv->isr_stats.rx);
  544. for (cnt = 0; cnt < REPLY_MAX; cnt++) {
  545. if (priv->isr_stats.rx_handlers[cnt] > 0)
  546. pos += scnprintf(buf + pos, bufsz - pos,
  547. "\tRx handler[%36s]:\t\t %u\n",
  548. get_cmd_string(cnt),
  549. priv->isr_stats.rx_handlers[cnt]);
  550. }
  551. pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
  552. priv->isr_stats.tx);
  553. pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
  554. priv->isr_stats.unhandled);
  555. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  556. kfree(buf);
  557. return ret;
  558. }
  559. static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
  560. const char __user *user_buf,
  561. size_t count, loff_t *ppos)
  562. {
  563. struct iwl_priv *priv = file->private_data;
  564. char buf[8];
  565. int buf_size;
  566. u32 reset_flag;
  567. memset(buf, 0, sizeof(buf));
  568. buf_size = min(count, sizeof(buf) - 1);
  569. if (copy_from_user(buf, user_buf, buf_size))
  570. return -EFAULT;
  571. if (sscanf(buf, "%x", &reset_flag) != 1)
  572. return -EFAULT;
  573. if (reset_flag == 0)
  574. iwl_clear_isr_stats(priv);
  575. return count;
  576. }
  577. static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
  578. size_t count, loff_t *ppos)
  579. {
  580. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  581. int pos = 0, i;
  582. char buf[256];
  583. const size_t bufsz = sizeof(buf);
  584. ssize_t ret;
  585. for (i = 0; i < AC_NUM; i++) {
  586. pos += scnprintf(buf + pos, bufsz - pos,
  587. "\tcw_min\tcw_max\taifsn\ttxop\n");
  588. pos += scnprintf(buf + pos, bufsz - pos,
  589. "AC[%d]\t%u\t%u\t%u\t%u\n", i,
  590. priv->qos_data.def_qos_parm.ac[i].cw_min,
  591. priv->qos_data.def_qos_parm.ac[i].cw_max,
  592. priv->qos_data.def_qos_parm.ac[i].aifsn,
  593. priv->qos_data.def_qos_parm.ac[i].edca_txop);
  594. }
  595. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  596. return ret;
  597. }
  598. static ssize_t iwl_dbgfs_led_read(struct file *file, char __user *user_buf,
  599. size_t count, loff_t *ppos)
  600. {
  601. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  602. int pos = 0;
  603. char buf[256];
  604. const size_t bufsz = sizeof(buf);
  605. ssize_t ret;
  606. pos += scnprintf(buf + pos, bufsz - pos,
  607. "allow blinking: %s\n",
  608. (priv->allow_blinking) ? "True" : "False");
  609. if (priv->allow_blinking) {
  610. pos += scnprintf(buf + pos, bufsz - pos,
  611. "Led blinking rate: %u\n",
  612. priv->last_blink_rate);
  613. pos += scnprintf(buf + pos, bufsz - pos,
  614. "Last blink time: %lu\n",
  615. priv->last_blink_time);
  616. }
  617. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  618. return ret;
  619. }
  620. static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
  621. char __user *user_buf,
  622. size_t count, loff_t *ppos)
  623. {
  624. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  625. struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
  626. struct iwl_tt_restriction *restriction;
  627. char buf[100];
  628. int pos = 0;
  629. const size_t bufsz = sizeof(buf);
  630. ssize_t ret;
  631. pos += scnprintf(buf + pos, bufsz - pos,
  632. "Thermal Throttling Mode: %s\n",
  633. tt->advanced_tt ? "Advance" : "Legacy");
  634. pos += scnprintf(buf + pos, bufsz - pos,
  635. "Thermal Throttling State: %d\n",
  636. tt->state);
  637. if (tt->advanced_tt) {
  638. restriction = tt->restriction + tt->state;
  639. pos += scnprintf(buf + pos, bufsz - pos,
  640. "Tx mode: %d\n",
  641. restriction->tx_stream);
  642. pos += scnprintf(buf + pos, bufsz - pos,
  643. "Rx mode: %d\n",
  644. restriction->rx_stream);
  645. pos += scnprintf(buf + pos, bufsz - pos,
  646. "HT mode: %d\n",
  647. restriction->is_ht);
  648. }
  649. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  650. return ret;
  651. }
  652. static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
  653. const char __user *user_buf,
  654. size_t count, loff_t *ppos)
  655. {
  656. struct iwl_priv *priv = file->private_data;
  657. char buf[8];
  658. int buf_size;
  659. int ht40;
  660. memset(buf, 0, sizeof(buf));
  661. buf_size = min(count, sizeof(buf) - 1);
  662. if (copy_from_user(buf, user_buf, buf_size))
  663. return -EFAULT;
  664. if (sscanf(buf, "%d", &ht40) != 1)
  665. return -EFAULT;
  666. if (!iwl_is_associated(priv))
  667. priv->disable_ht40 = ht40 ? true : false;
  668. else {
  669. IWL_ERR(priv, "Sta associated with AP - "
  670. "Change to 40MHz channel support is not allowed\n");
  671. return -EINVAL;
  672. }
  673. return count;
  674. }
  675. static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
  676. char __user *user_buf,
  677. size_t count, loff_t *ppos)
  678. {
  679. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  680. char buf[100];
  681. int pos = 0;
  682. const size_t bufsz = sizeof(buf);
  683. ssize_t ret;
  684. pos += scnprintf(buf + pos, bufsz - pos,
  685. "11n 40MHz Mode: %s\n",
  686. priv->disable_ht40 ? "Disabled" : "Enabled");
  687. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  688. return ret;
  689. }
  690. static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
  691. const char __user *user_buf,
  692. size_t count, loff_t *ppos)
  693. {
  694. struct iwl_priv *priv = file->private_data;
  695. char buf[8];
  696. int buf_size;
  697. int value;
  698. memset(buf, 0, sizeof(buf));
  699. buf_size = min(count, sizeof(buf) - 1);
  700. if (copy_from_user(buf, user_buf, buf_size))
  701. return -EFAULT;
  702. if (sscanf(buf, "%d", &value) != 1)
  703. return -EINVAL;
  704. /*
  705. * Our users expect 0 to be "CAM", but 0 isn't actually
  706. * valid here. However, let's not confuse them and present
  707. * IWL_POWER_INDEX_1 as "1", not "0".
  708. */
  709. if (value == 0)
  710. return -EINVAL;
  711. else if (value > 0)
  712. value -= 1;
  713. if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
  714. return -EINVAL;
  715. if (!iwl_is_ready_rf(priv))
  716. return -EAGAIN;
  717. priv->power_data.debug_sleep_level_override = value;
  718. iwl_power_update_mode(priv, true);
  719. return count;
  720. }
  721. static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
  722. char __user *user_buf,
  723. size_t count, loff_t *ppos)
  724. {
  725. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  726. char buf[10];
  727. int pos, value;
  728. const size_t bufsz = sizeof(buf);
  729. /* see the write function */
  730. value = priv->power_data.debug_sleep_level_override;
  731. if (value >= 0)
  732. value += 1;
  733. pos = scnprintf(buf, bufsz, "%d\n", value);
  734. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  735. }
  736. static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
  737. char __user *user_buf,
  738. size_t count, loff_t *ppos)
  739. {
  740. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  741. char buf[200];
  742. int pos = 0, i;
  743. const size_t bufsz = sizeof(buf);
  744. struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
  745. pos += scnprintf(buf + pos, bufsz - pos,
  746. "flags: %#.2x\n", le16_to_cpu(cmd->flags));
  747. pos += scnprintf(buf + pos, bufsz - pos,
  748. "RX/TX timeout: %d/%d usec\n",
  749. le32_to_cpu(cmd->rx_data_timeout),
  750. le32_to_cpu(cmd->tx_data_timeout));
  751. for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
  752. pos += scnprintf(buf + pos, bufsz - pos,
  753. "sleep_interval[%d]: %d\n", i,
  754. le32_to_cpu(cmd->sleep_interval[i]));
  755. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  756. }
  757. DEBUGFS_READ_WRITE_FILE_OPS(sram);
  758. DEBUGFS_WRITE_FILE_OPS(log_event);
  759. DEBUGFS_READ_FILE_OPS(nvm);
  760. DEBUGFS_READ_FILE_OPS(stations);
  761. DEBUGFS_READ_FILE_OPS(channels);
  762. DEBUGFS_READ_FILE_OPS(status);
  763. DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
  764. DEBUGFS_READ_FILE_OPS(qos);
  765. DEBUGFS_READ_FILE_OPS(led);
  766. DEBUGFS_READ_FILE_OPS(thermal_throttling);
  767. DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
  768. DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
  769. DEBUGFS_READ_FILE_OPS(current_sleep_command);
  770. static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
  771. char __user *user_buf,
  772. size_t count, loff_t *ppos)
  773. {
  774. struct iwl_priv *priv = file->private_data;
  775. int pos = 0, ofs = 0;
  776. int cnt = 0, entry;
  777. struct iwl_tx_queue *txq;
  778. struct iwl_queue *q;
  779. struct iwl_rx_queue *rxq = &priv->rxq;
  780. char *buf;
  781. int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
  782. (priv->cfg->num_of_queues * 32 * 8) + 400;
  783. const u8 *ptr;
  784. ssize_t ret;
  785. if (!priv->txq) {
  786. IWL_ERR(priv, "txq not ready\n");
  787. return -EAGAIN;
  788. }
  789. buf = kzalloc(bufsz, GFP_KERNEL);
  790. if (!buf) {
  791. IWL_ERR(priv, "Can not allocate buffer\n");
  792. return -ENOMEM;
  793. }
  794. pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
  795. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  796. txq = &priv->txq[cnt];
  797. q = &txq->q;
  798. pos += scnprintf(buf + pos, bufsz - pos,
  799. "q[%d]: read_ptr: %u, write_ptr: %u\n",
  800. cnt, q->read_ptr, q->write_ptr);
  801. }
  802. if (priv->tx_traffic && (iwl_debug_level & IWL_DL_TX)) {
  803. ptr = priv->tx_traffic;
  804. pos += scnprintf(buf + pos, bufsz - pos,
  805. "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
  806. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  807. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  808. entry++, ofs += 16) {
  809. pos += scnprintf(buf + pos, bufsz - pos,
  810. "0x%.4x ", ofs);
  811. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  812. buf + pos, bufsz - pos, 0);
  813. pos += strlen(buf + pos);
  814. if (bufsz - pos > 0)
  815. buf[pos++] = '\n';
  816. }
  817. }
  818. }
  819. pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
  820. pos += scnprintf(buf + pos, bufsz - pos,
  821. "read: %u, write: %u\n",
  822. rxq->read, rxq->write);
  823. if (priv->rx_traffic && (iwl_debug_level & IWL_DL_RX)) {
  824. ptr = priv->rx_traffic;
  825. pos += scnprintf(buf + pos, bufsz - pos,
  826. "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
  827. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  828. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  829. entry++, ofs += 16) {
  830. pos += scnprintf(buf + pos, bufsz - pos,
  831. "0x%.4x ", ofs);
  832. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  833. buf + pos, bufsz - pos, 0);
  834. pos += strlen(buf + pos);
  835. if (bufsz - pos > 0)
  836. buf[pos++] = '\n';
  837. }
  838. }
  839. }
  840. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  841. kfree(buf);
  842. return ret;
  843. }
  844. static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
  845. const char __user *user_buf,
  846. size_t count, loff_t *ppos)
  847. {
  848. struct iwl_priv *priv = file->private_data;
  849. char buf[8];
  850. int buf_size;
  851. int traffic_log;
  852. memset(buf, 0, sizeof(buf));
  853. buf_size = min(count, sizeof(buf) - 1);
  854. if (copy_from_user(buf, user_buf, buf_size))
  855. return -EFAULT;
  856. if (sscanf(buf, "%d", &traffic_log) != 1)
  857. return -EFAULT;
  858. if (traffic_log == 0)
  859. iwl_reset_traffic_log(priv);
  860. return count;
  861. }
  862. static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
  863. char __user *user_buf,
  864. size_t count, loff_t *ppos) {
  865. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  866. struct iwl_tx_queue *txq;
  867. struct iwl_queue *q;
  868. char *buf;
  869. int pos = 0;
  870. int cnt;
  871. int ret;
  872. const size_t bufsz = sizeof(char) * 64 * priv->cfg->num_of_queues;
  873. if (!priv->txq) {
  874. IWL_ERR(priv, "txq not ready\n");
  875. return -EAGAIN;
  876. }
  877. buf = kzalloc(bufsz, GFP_KERNEL);
  878. if (!buf)
  879. return -ENOMEM;
  880. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  881. txq = &priv->txq[cnt];
  882. q = &txq->q;
  883. pos += scnprintf(buf + pos, bufsz - pos,
  884. "hwq %.2d: read=%u write=%u stop=%d"
  885. " swq_id=%#.2x (ac %d/hwq %d)\n",
  886. cnt, q->read_ptr, q->write_ptr,
  887. !!test_bit(cnt, priv->queue_stopped),
  888. txq->swq_id,
  889. txq->swq_id & 0x80 ? txq->swq_id & 3 :
  890. txq->swq_id,
  891. txq->swq_id & 0x80 ? (txq->swq_id >> 2) &
  892. 0x1f : txq->swq_id);
  893. if (cnt >= 4)
  894. continue;
  895. /* for the ACs, display the stop count too */
  896. pos += scnprintf(buf + pos, bufsz - pos,
  897. " stop-count: %d\n",
  898. atomic_read(&priv->queue_stop_count[cnt]));
  899. }
  900. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  901. kfree(buf);
  902. return ret;
  903. }
  904. static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
  905. char __user *user_buf,
  906. size_t count, loff_t *ppos) {
  907. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  908. struct iwl_rx_queue *rxq = &priv->rxq;
  909. char buf[256];
  910. int pos = 0;
  911. const size_t bufsz = sizeof(buf);
  912. pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
  913. rxq->read);
  914. pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
  915. rxq->write);
  916. pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
  917. rxq->free_count);
  918. pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
  919. le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
  920. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  921. }
  922. static int iwl_dbgfs_statistics_flag(struct iwl_priv *priv, char *buf,
  923. int bufsz)
  924. {
  925. int p = 0;
  926. p += scnprintf(buf + p, bufsz - p,
  927. "Statistics Flag(0x%X):\n",
  928. le32_to_cpu(priv->statistics.flag));
  929. if (le32_to_cpu(priv->statistics.flag) & UCODE_STATISTICS_CLEAR_MSK)
  930. p += scnprintf(buf + p, bufsz - p,
  931. "\tStatistics have been cleared\n");
  932. p += scnprintf(buf + p, bufsz - p,
  933. "\tOperational Frequency: %s\n",
  934. (le32_to_cpu(priv->statistics.flag) &
  935. UCODE_STATISTICS_FREQUENCY_MSK)
  936. ? "2.4 GHz" : "5.2 GHz");
  937. p += scnprintf(buf + p, bufsz - p,
  938. "\tTGj Narrow Band: %s\n",
  939. (le32_to_cpu(priv->statistics.flag) &
  940. UCODE_STATISTICS_NARROW_BAND_MSK)
  941. ? "enabled" : "disabled");
  942. return p;
  943. }
  944. static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
  945. char __user *user_buf,
  946. size_t count, loff_t *ppos)
  947. {
  948. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  949. int pos = 0;
  950. char *buf;
  951. int bufsz = sizeof(struct statistics_rx_phy) * 20 +
  952. sizeof(struct statistics_rx_non_phy) * 20 +
  953. sizeof(struct statistics_rx_ht_phy) * 20 + 400;
  954. ssize_t ret;
  955. struct statistics_rx_phy *ofdm, *accum_ofdm;
  956. struct statistics_rx_phy *cck, *accum_cck;
  957. struct statistics_rx_non_phy *general, *accum_general;
  958. struct statistics_rx_ht_phy *ht, *accum_ht;
  959. if (!iwl_is_alive(priv))
  960. return -EAGAIN;
  961. /* make request to uCode to retrieve statistics information */
  962. mutex_lock(&priv->mutex);
  963. ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
  964. mutex_unlock(&priv->mutex);
  965. if (ret) {
  966. IWL_ERR(priv,
  967. "Error sending statistics request: %zd\n", ret);
  968. return -EAGAIN;
  969. }
  970. buf = kzalloc(bufsz, GFP_KERNEL);
  971. if (!buf) {
  972. IWL_ERR(priv, "Can not allocate Buffer\n");
  973. return -ENOMEM;
  974. }
  975. /* the statistic information display here is based on
  976. * the last statistics notification from uCode
  977. * might not reflect the current uCode activity
  978. */
  979. ofdm = &priv->statistics.rx.ofdm;
  980. cck = &priv->statistics.rx.cck;
  981. general = &priv->statistics.rx.general;
  982. ht = &priv->statistics.rx.ofdm_ht;
  983. accum_ofdm = &priv->accum_statistics.rx.ofdm;
  984. accum_cck = &priv->accum_statistics.rx.cck;
  985. accum_general = &priv->accum_statistics.rx.general;
  986. accum_ht = &priv->accum_statistics.rx.ofdm_ht;
  987. pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
  988. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - OFDM:\n");
  989. pos += scnprintf(buf + pos, bufsz - pos,
  990. "\t\t\tcurrent\t\t\taccumulative\n");
  991. pos += scnprintf(buf + pos, bufsz - pos, "ina_cnt:\t\t%u\t\t\t%u\n",
  992. le32_to_cpu(ofdm->ina_cnt), accum_ofdm->ina_cnt);
  993. pos += scnprintf(buf + pos, bufsz - pos, "fina_cnt:\t\t%u\t\t\t%u\n",
  994. le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt);
  995. pos += scnprintf(buf + pos, bufsz - pos, "plcp_err:\t\t%u\t\t\t%u\n",
  996. le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err);
  997. pos += scnprintf(buf + pos, bufsz - pos, "crc32_err:\t\t%u\t\t\t%u\n",
  998. le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err);
  999. pos += scnprintf(buf + pos, bufsz - pos,
  1000. "overrun_err:\t\t%u\t\t\t%u\n",
  1001. le32_to_cpu(ofdm->overrun_err),
  1002. accum_ofdm->overrun_err);
  1003. pos += scnprintf(buf + pos, bufsz - pos,
  1004. "early_overrun_err:\t%u\t\t\t%u\n",
  1005. le32_to_cpu(ofdm->early_overrun_err),
  1006. accum_ofdm->early_overrun_err);
  1007. pos += scnprintf(buf + pos, bufsz - pos, "crc32_good:\t\t%u\t\t\t%u\n",
  1008. le32_to_cpu(ofdm->crc32_good),
  1009. accum_ofdm->crc32_good);
  1010. pos += scnprintf(buf + pos, bufsz - pos,
  1011. "false_alarm_cnt:\t%u\t\t\t%u\n",
  1012. le32_to_cpu(ofdm->false_alarm_cnt),
  1013. accum_ofdm->false_alarm_cnt);
  1014. pos += scnprintf(buf + pos, bufsz - pos,
  1015. "fina_sync_err_cnt:\t%u\t\t\t%u\n",
  1016. le32_to_cpu(ofdm->fina_sync_err_cnt),
  1017. accum_ofdm->fina_sync_err_cnt);
  1018. pos += scnprintf(buf + pos, bufsz - pos,
  1019. "sfd_timeout:\t\t%u\t\t\t%u\n",
  1020. le32_to_cpu(ofdm->sfd_timeout),
  1021. accum_ofdm->sfd_timeout);
  1022. pos += scnprintf(buf + pos, bufsz - pos,
  1023. "fina_timeout:\t\t%u\t\t\t%u\n",
  1024. le32_to_cpu(ofdm->fina_timeout),
  1025. accum_ofdm->fina_timeout);
  1026. pos += scnprintf(buf + pos, bufsz - pos,
  1027. "unresponded_rts:\t%u\t\t\t%u\n",
  1028. le32_to_cpu(ofdm->unresponded_rts),
  1029. accum_ofdm->unresponded_rts);
  1030. pos += scnprintf(buf + pos, bufsz - pos,
  1031. "rxe_frame_lmt_ovrun:\t%u\t\t\t%u\n",
  1032. le32_to_cpu(ofdm->rxe_frame_limit_overrun),
  1033. accum_ofdm->rxe_frame_limit_overrun);
  1034. pos += scnprintf(buf + pos, bufsz - pos,
  1035. "sent_ack_cnt:\t\t%u\t\t\t%u\n",
  1036. le32_to_cpu(ofdm->sent_ack_cnt),
  1037. accum_ofdm->sent_ack_cnt);
  1038. pos += scnprintf(buf + pos, bufsz - pos,
  1039. "sent_cts_cnt:\t\t%u\t\t\t%u\n",
  1040. le32_to_cpu(ofdm->sent_cts_cnt),
  1041. accum_ofdm->sent_cts_cnt);
  1042. pos += scnprintf(buf + pos, bufsz - pos,
  1043. "sent_ba_rsp_cnt:\t%u\t\t\t%u\n",
  1044. le32_to_cpu(ofdm->sent_ba_rsp_cnt),
  1045. accum_ofdm->sent_ba_rsp_cnt);
  1046. pos += scnprintf(buf + pos, bufsz - pos,
  1047. "dsp_self_kill:\t\t%u\t\t\t%u\n",
  1048. le32_to_cpu(ofdm->dsp_self_kill),
  1049. accum_ofdm->dsp_self_kill);
  1050. pos += scnprintf(buf + pos, bufsz - pos,
  1051. "mh_format_err:\t\t%u\t\t\t%u\n",
  1052. le32_to_cpu(ofdm->mh_format_err),
  1053. accum_ofdm->mh_format_err);
  1054. pos += scnprintf(buf + pos, bufsz - pos,
  1055. "re_acq_main_rssi_sum:\t%u\t\t\t%u\n",
  1056. le32_to_cpu(ofdm->re_acq_main_rssi_sum),
  1057. accum_ofdm->re_acq_main_rssi_sum);
  1058. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - CCK:\n");
  1059. pos += scnprintf(buf + pos, bufsz - pos,
  1060. "\t\t\tcurrent\t\t\taccumulative\n");
  1061. pos += scnprintf(buf + pos, bufsz - pos, "ina_cnt:\t\t%u\t\t\t%u\n",
  1062. le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt);
  1063. pos += scnprintf(buf + pos, bufsz - pos, "fina_cnt:\t\t%u\t\t\t%u\n",
  1064. le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt);
  1065. pos += scnprintf(buf + pos, bufsz - pos, "plcp_err:\t\t%u\t\t\t%u\n",
  1066. le32_to_cpu(cck->plcp_err), accum_cck->plcp_err);
  1067. pos += scnprintf(buf + pos, bufsz - pos, "crc32_err:\t\t%u\t\t\t%u\n",
  1068. le32_to_cpu(cck->crc32_err), accum_cck->crc32_err);
  1069. pos += scnprintf(buf + pos, bufsz - pos,
  1070. "overrun_err:\t\t%u\t\t\t%u\n",
  1071. le32_to_cpu(cck->overrun_err),
  1072. accum_cck->overrun_err);
  1073. pos += scnprintf(buf + pos, bufsz - pos,
  1074. "early_overrun_err:\t%u\t\t\t%u\n",
  1075. le32_to_cpu(cck->early_overrun_err),
  1076. accum_cck->early_overrun_err);
  1077. pos += scnprintf(buf + pos, bufsz - pos, "crc32_good:\t\t%u\t\t\t%u\n",
  1078. le32_to_cpu(cck->crc32_good), accum_cck->crc32_good);
  1079. pos += scnprintf(buf + pos, bufsz - pos,
  1080. "false_alarm_cnt:\t%u\t\t\t%u\n",
  1081. le32_to_cpu(cck->false_alarm_cnt),
  1082. accum_cck->false_alarm_cnt);
  1083. pos += scnprintf(buf + pos, bufsz - pos,
  1084. "fina_sync_err_cnt:\t%u\t\t\t%u\n",
  1085. le32_to_cpu(cck->fina_sync_err_cnt),
  1086. accum_cck->fina_sync_err_cnt);
  1087. pos += scnprintf(buf + pos, bufsz - pos,
  1088. "sfd_timeout:\t\t%u\t\t\t%u\n",
  1089. le32_to_cpu(cck->sfd_timeout),
  1090. accum_cck->sfd_timeout);
  1091. pos += scnprintf(buf + pos, bufsz - pos,
  1092. "fina_timeout:\t\t%u\t\t\t%u\n",
  1093. le32_to_cpu(cck->fina_timeout),
  1094. accum_cck->fina_timeout);
  1095. pos += scnprintf(buf + pos, bufsz - pos,
  1096. "unresponded_rts:\t%u\t\t\t%u\n",
  1097. le32_to_cpu(cck->unresponded_rts),
  1098. accum_cck->unresponded_rts);
  1099. pos += scnprintf(buf + pos, bufsz - pos,
  1100. "rxe_frame_lmt_ovrun:\t%u\t\t\t%u\n",
  1101. le32_to_cpu(cck->rxe_frame_limit_overrun),
  1102. accum_cck->rxe_frame_limit_overrun);
  1103. pos += scnprintf(buf + pos, bufsz - pos,
  1104. "sent_ack_cnt:\t\t%u\t\t\t%u\n",
  1105. le32_to_cpu(cck->sent_ack_cnt),
  1106. accum_cck->sent_ack_cnt);
  1107. pos += scnprintf(buf + pos, bufsz - pos,
  1108. "sent_cts_cnt:\t\t%u\t\t\t%u\n",
  1109. le32_to_cpu(cck->sent_cts_cnt),
  1110. accum_cck->sent_cts_cnt);
  1111. pos += scnprintf(buf + pos, bufsz - pos,
  1112. "sent_ba_rsp_cnt:\t%u\t\t\t%u\n",
  1113. le32_to_cpu(cck->sent_ba_rsp_cnt),
  1114. accum_cck->sent_ba_rsp_cnt);
  1115. pos += scnprintf(buf + pos, bufsz - pos,
  1116. "dsp_self_kill:\t\t%u\t\t\t%u\n",
  1117. le32_to_cpu(cck->dsp_self_kill),
  1118. accum_cck->dsp_self_kill);
  1119. pos += scnprintf(buf + pos, bufsz - pos,
  1120. "mh_format_err:\t\t%u\t\t\t%u\n",
  1121. le32_to_cpu(cck->mh_format_err),
  1122. accum_cck->mh_format_err);
  1123. pos += scnprintf(buf + pos, bufsz - pos,
  1124. "re_acq_main_rssi_sum:\t%u\t\t\t%u\n",
  1125. le32_to_cpu(cck->re_acq_main_rssi_sum),
  1126. accum_cck->re_acq_main_rssi_sum);
  1127. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - GENERAL:\n");
  1128. pos += scnprintf(buf + pos, bufsz - pos,
  1129. "\t\t\tcurrent\t\t\taccumulative\n");
  1130. pos += scnprintf(buf + pos, bufsz - pos, "bogus_cts:\t\t%u\t\t\t%u\n",
  1131. le32_to_cpu(general->bogus_cts),
  1132. accum_general->bogus_cts);
  1133. pos += scnprintf(buf + pos, bufsz - pos, "bogus_ack:\t\t%u\t\t\t%u\n",
  1134. le32_to_cpu(general->bogus_ack),
  1135. accum_general->bogus_ack);
  1136. pos += scnprintf(buf + pos, bufsz - pos,
  1137. "non_bssid_frames:\t%u\t\t\t%u\n",
  1138. le32_to_cpu(general->non_bssid_frames),
  1139. accum_general->non_bssid_frames);
  1140. pos += scnprintf(buf + pos, bufsz - pos,
  1141. "filtered_frames:\t%u\t\t\t%u\n",
  1142. le32_to_cpu(general->filtered_frames),
  1143. accum_general->filtered_frames);
  1144. pos += scnprintf(buf + pos, bufsz - pos,
  1145. "non_channel_beacons:\t%u\t\t\t%u\n",
  1146. le32_to_cpu(general->non_channel_beacons),
  1147. accum_general->non_channel_beacons);
  1148. pos += scnprintf(buf + pos, bufsz - pos,
  1149. "channel_beacons:\t%u\t\t\t%u\n",
  1150. le32_to_cpu(general->channel_beacons),
  1151. accum_general->channel_beacons);
  1152. pos += scnprintf(buf + pos, bufsz - pos,
  1153. "num_missed_bcon:\t%u\t\t\t%u\n",
  1154. le32_to_cpu(general->num_missed_bcon),
  1155. accum_general->num_missed_bcon);
  1156. pos += scnprintf(buf + pos, bufsz - pos,
  1157. "adc_rx_saturation_time:\t%u\t\t\t%u\n",
  1158. le32_to_cpu(general->adc_rx_saturation_time),
  1159. accum_general->adc_rx_saturation_time);
  1160. pos += scnprintf(buf + pos, bufsz - pos,
  1161. "ina_detect_search_tm:\t%u\t\t\t%u\n",
  1162. le32_to_cpu(general->ina_detection_search_time),
  1163. accum_general->ina_detection_search_time);
  1164. pos += scnprintf(buf + pos, bufsz - pos,
  1165. "beacon_silence_rssi_a:\t%u\t\t\t%u\n",
  1166. le32_to_cpu(general->beacon_silence_rssi_a),
  1167. accum_general->beacon_silence_rssi_a);
  1168. pos += scnprintf(buf + pos, bufsz - pos,
  1169. "beacon_silence_rssi_b:\t%u\t\t\t%u\n",
  1170. le32_to_cpu(general->beacon_silence_rssi_b),
  1171. accum_general->beacon_silence_rssi_b);
  1172. pos += scnprintf(buf + pos, bufsz - pos,
  1173. "beacon_silence_rssi_c:\t%u\t\t\t%u\n",
  1174. le32_to_cpu(general->beacon_silence_rssi_c),
  1175. accum_general->beacon_silence_rssi_c);
  1176. pos += scnprintf(buf + pos, bufsz - pos,
  1177. "interference_data_flag:\t%u\t\t\t%u\n",
  1178. le32_to_cpu(general->interference_data_flag),
  1179. accum_general->interference_data_flag);
  1180. pos += scnprintf(buf + pos, bufsz - pos,
  1181. "channel_load:\t\t%u\t\t\t%u\n",
  1182. le32_to_cpu(general->channel_load),
  1183. accum_general->channel_load);
  1184. pos += scnprintf(buf + pos, bufsz - pos,
  1185. "dsp_false_alarms:\t%u\t\t\t%u\n",
  1186. le32_to_cpu(general->dsp_false_alarms),
  1187. accum_general->dsp_false_alarms);
  1188. pos += scnprintf(buf + pos, bufsz - pos,
  1189. "beacon_rssi_a:\t\t%u\t\t\t%u\n",
  1190. le32_to_cpu(general->beacon_rssi_a),
  1191. accum_general->beacon_rssi_a);
  1192. pos += scnprintf(buf + pos, bufsz - pos,
  1193. "beacon_rssi_b:\t\t%u\t\t\t%u\n",
  1194. le32_to_cpu(general->beacon_rssi_b),
  1195. accum_general->beacon_rssi_b);
  1196. pos += scnprintf(buf + pos, bufsz - pos,
  1197. "beacon_rssi_c:\t\t%u\t\t\t%u\n",
  1198. le32_to_cpu(general->beacon_rssi_c),
  1199. accum_general->beacon_rssi_c);
  1200. pos += scnprintf(buf + pos, bufsz - pos,
  1201. "beacon_energy_a:\t%u\t\t\t%u\n",
  1202. le32_to_cpu(general->beacon_energy_a),
  1203. accum_general->beacon_energy_a);
  1204. pos += scnprintf(buf + pos, bufsz - pos,
  1205. "beacon_energy_b:\t%u\t\t\t%u\n",
  1206. le32_to_cpu(general->beacon_energy_b),
  1207. accum_general->beacon_energy_b);
  1208. pos += scnprintf(buf + pos, bufsz - pos,
  1209. "beacon_energy_c:\t%u\t\t\t%u\n",
  1210. le32_to_cpu(general->beacon_energy_c),
  1211. accum_general->beacon_energy_c);
  1212. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - OFDM_HT:\n");
  1213. pos += scnprintf(buf + pos, bufsz - pos,
  1214. "\t\t\tcurrent\t\t\taccumulative\n");
  1215. pos += scnprintf(buf + pos, bufsz - pos, "plcp_err:\t\t%u\t\t\t%u\n",
  1216. le32_to_cpu(ht->plcp_err), accum_ht->plcp_err);
  1217. pos += scnprintf(buf + pos, bufsz - pos,
  1218. "overrun_err:\t\t%u\t\t\t%u\n",
  1219. le32_to_cpu(ht->overrun_err), accum_ht->overrun_err);
  1220. pos += scnprintf(buf + pos, bufsz - pos,
  1221. "early_overrun_err:\t%u\t\t\t%u\n",
  1222. le32_to_cpu(ht->early_overrun_err),
  1223. accum_ht->early_overrun_err);
  1224. pos += scnprintf(buf + pos, bufsz - pos, "crc32_good:\t\t%u\t\t\t%u\n",
  1225. le32_to_cpu(ht->crc32_good), accum_ht->crc32_good);
  1226. pos += scnprintf(buf + pos, bufsz - pos, "crc32_err:\t\t%u\t\t\t%u\n",
  1227. le32_to_cpu(ht->crc32_err), accum_ht->crc32_err);
  1228. pos += scnprintf(buf + pos, bufsz - pos,
  1229. "mh_format_err:\t\t%u\t\t\t%u\n",
  1230. le32_to_cpu(ht->mh_format_err),
  1231. accum_ht->mh_format_err);
  1232. pos += scnprintf(buf + pos, bufsz - pos,
  1233. "agg_crc32_good:\t\t%u\t\t\t%u\n",
  1234. le32_to_cpu(ht->agg_crc32_good),
  1235. accum_ht->agg_crc32_good);
  1236. pos += scnprintf(buf + pos, bufsz - pos,
  1237. "agg_mpdu_cnt:\t\t%u\t\t\t%u\n",
  1238. le32_to_cpu(ht->agg_mpdu_cnt),
  1239. accum_ht->agg_mpdu_cnt);
  1240. pos += scnprintf(buf + pos, bufsz - pos, "agg_cnt:\t\t%u\t\t\t%u\n",
  1241. le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt);
  1242. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1243. kfree(buf);
  1244. return ret;
  1245. }
  1246. static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
  1247. char __user *user_buf,
  1248. size_t count, loff_t *ppos)
  1249. {
  1250. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1251. int pos = 0;
  1252. char *buf;
  1253. int bufsz = (sizeof(struct statistics_tx) * 24) + 250;
  1254. ssize_t ret;
  1255. struct statistics_tx *tx, *accum_tx;
  1256. if (!iwl_is_alive(priv))
  1257. return -EAGAIN;
  1258. /* make request to uCode to retrieve statistics information */
  1259. mutex_lock(&priv->mutex);
  1260. ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
  1261. mutex_unlock(&priv->mutex);
  1262. if (ret) {
  1263. IWL_ERR(priv,
  1264. "Error sending statistics request: %zd\n", ret);
  1265. return -EAGAIN;
  1266. }
  1267. buf = kzalloc(bufsz, GFP_KERNEL);
  1268. if (!buf) {
  1269. IWL_ERR(priv, "Can not allocate Buffer\n");
  1270. return -ENOMEM;
  1271. }
  1272. /* the statistic information display here is based on
  1273. * the last statistics notification from uCode
  1274. * might not reflect the current uCode activity
  1275. */
  1276. tx = &priv->statistics.tx;
  1277. accum_tx = &priv->accum_statistics.tx;
  1278. pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
  1279. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Tx:\n");
  1280. pos += scnprintf(buf + pos, bufsz - pos,
  1281. "\t\t\tcurrent\t\t\taccumulative\n");
  1282. pos += scnprintf(buf + pos, bufsz - pos, "preamble:\t\t\t%u\t\t\t%u\n",
  1283. le32_to_cpu(tx->preamble_cnt),
  1284. accum_tx->preamble_cnt);
  1285. pos += scnprintf(buf + pos, bufsz - pos,
  1286. "rx_detected_cnt:\t\t%u\t\t\t%u\n",
  1287. le32_to_cpu(tx->rx_detected_cnt),
  1288. accum_tx->rx_detected_cnt);
  1289. pos += scnprintf(buf + pos, bufsz - pos,
  1290. "bt_prio_defer_cnt:\t\t%u\t\t\t%u\n",
  1291. le32_to_cpu(tx->bt_prio_defer_cnt),
  1292. accum_tx->bt_prio_defer_cnt);
  1293. pos += scnprintf(buf + pos, bufsz - pos,
  1294. "bt_prio_kill_cnt:\t\t%u\t\t\t%u\n",
  1295. le32_to_cpu(tx->bt_prio_kill_cnt),
  1296. accum_tx->bt_prio_kill_cnt);
  1297. pos += scnprintf(buf + pos, bufsz - pos,
  1298. "few_bytes_cnt:\t\t\t%u\t\t\t%u\n",
  1299. le32_to_cpu(tx->few_bytes_cnt),
  1300. accum_tx->few_bytes_cnt);
  1301. pos += scnprintf(buf + pos, bufsz - pos,
  1302. "cts_timeout:\t\t\t%u\t\t\t%u\n",
  1303. le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout);
  1304. pos += scnprintf(buf + pos, bufsz - pos,
  1305. "ack_timeout:\t\t\t%u\t\t\t%u\n",
  1306. le32_to_cpu(tx->ack_timeout),
  1307. accum_tx->ack_timeout);
  1308. pos += scnprintf(buf + pos, bufsz - pos,
  1309. "expected_ack_cnt:\t\t%u\t\t\t%u\n",
  1310. le32_to_cpu(tx->expected_ack_cnt),
  1311. accum_tx->expected_ack_cnt);
  1312. pos += scnprintf(buf + pos, bufsz - pos,
  1313. "actual_ack_cnt:\t\t\t%u\t\t\t%u\n",
  1314. le32_to_cpu(tx->actual_ack_cnt),
  1315. accum_tx->actual_ack_cnt);
  1316. pos += scnprintf(buf + pos, bufsz - pos,
  1317. "dump_msdu_cnt:\t\t\t%u\t\t\t%u\n",
  1318. le32_to_cpu(tx->dump_msdu_cnt),
  1319. accum_tx->dump_msdu_cnt);
  1320. pos += scnprintf(buf + pos, bufsz - pos,
  1321. "abort_nxt_frame_mismatch:"
  1322. "\t%u\t\t\t%u\n",
  1323. le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
  1324. accum_tx->burst_abort_next_frame_mismatch_cnt);
  1325. pos += scnprintf(buf + pos, bufsz - pos,
  1326. "abort_missing_nxt_frame:"
  1327. "\t%u\t\t\t%u\n",
  1328. le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
  1329. accum_tx->burst_abort_missing_next_frame_cnt);
  1330. pos += scnprintf(buf + pos, bufsz - pos,
  1331. "cts_timeout_collision:\t\t%u\t\t\t%u\n",
  1332. le32_to_cpu(tx->cts_timeout_collision),
  1333. accum_tx->cts_timeout_collision);
  1334. pos += scnprintf(buf + pos, bufsz - pos,
  1335. "ack_ba_timeout_collision:\t%u\t\t\t%u\n",
  1336. le32_to_cpu(tx->ack_or_ba_timeout_collision),
  1337. accum_tx->ack_or_ba_timeout_collision);
  1338. pos += scnprintf(buf + pos, bufsz - pos,
  1339. "agg ba_timeout:\t\t\t%u\t\t\t%u\n",
  1340. le32_to_cpu(tx->agg.ba_timeout),
  1341. accum_tx->agg.ba_timeout);
  1342. pos += scnprintf(buf + pos, bufsz - pos,
  1343. "agg ba_resched_frames:\t\t%u\t\t\t%u\n",
  1344. le32_to_cpu(tx->agg.ba_reschedule_frames),
  1345. accum_tx->agg.ba_reschedule_frames);
  1346. pos += scnprintf(buf + pos, bufsz - pos,
  1347. "agg scd_query_agg_frame:\t%u\t\t\t%u\n",
  1348. le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
  1349. accum_tx->agg.scd_query_agg_frame_cnt);
  1350. pos += scnprintf(buf + pos, bufsz - pos,
  1351. "agg scd_query_no_agg:\t\t%u\t\t\t%u\n",
  1352. le32_to_cpu(tx->agg.scd_query_no_agg),
  1353. accum_tx->agg.scd_query_no_agg);
  1354. pos += scnprintf(buf + pos, bufsz - pos,
  1355. "agg scd_query_agg:\t\t%u\t\t\t%u\n",
  1356. le32_to_cpu(tx->agg.scd_query_agg),
  1357. accum_tx->agg.scd_query_agg);
  1358. pos += scnprintf(buf + pos, bufsz - pos,
  1359. "agg scd_query_mismatch:\t\t%u\t\t\t%u\n",
  1360. le32_to_cpu(tx->agg.scd_query_mismatch),
  1361. accum_tx->agg.scd_query_mismatch);
  1362. pos += scnprintf(buf + pos, bufsz - pos,
  1363. "agg frame_not_ready:\t\t%u\t\t\t%u\n",
  1364. le32_to_cpu(tx->agg.frame_not_ready),
  1365. accum_tx->agg.frame_not_ready);
  1366. pos += scnprintf(buf + pos, bufsz - pos,
  1367. "agg underrun:\t\t\t%u\t\t\t%u\n",
  1368. le32_to_cpu(tx->agg.underrun),
  1369. accum_tx->agg.underrun);
  1370. pos += scnprintf(buf + pos, bufsz - pos,
  1371. "agg bt_prio_kill:\t\t%u\t\t\t%u\n",
  1372. le32_to_cpu(tx->agg.bt_prio_kill),
  1373. accum_tx->agg.bt_prio_kill);
  1374. pos += scnprintf(buf + pos, bufsz - pos,
  1375. "agg rx_ba_rsp_cnt:\t\t%u\t\t\t%u\n",
  1376. le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
  1377. accum_tx->agg.rx_ba_rsp_cnt);
  1378. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1379. kfree(buf);
  1380. return ret;
  1381. }
  1382. static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
  1383. char __user *user_buf,
  1384. size_t count, loff_t *ppos)
  1385. {
  1386. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1387. int pos = 0;
  1388. char *buf;
  1389. int bufsz = sizeof(struct statistics_general) * 4 + 250;
  1390. ssize_t ret;
  1391. struct statistics_general *general, *accum_general;
  1392. struct statistics_dbg *dbg, *accum_dbg;
  1393. struct statistics_div *div, *accum_div;
  1394. if (!iwl_is_alive(priv))
  1395. return -EAGAIN;
  1396. /* make request to uCode to retrieve statistics information */
  1397. mutex_lock(&priv->mutex);
  1398. ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
  1399. mutex_unlock(&priv->mutex);
  1400. if (ret) {
  1401. IWL_ERR(priv,
  1402. "Error sending statistics request: %zd\n", ret);
  1403. return -EAGAIN;
  1404. }
  1405. buf = kzalloc(bufsz, GFP_KERNEL);
  1406. if (!buf) {
  1407. IWL_ERR(priv, "Can not allocate Buffer\n");
  1408. return -ENOMEM;
  1409. }
  1410. /* the statistic information display here is based on
  1411. * the last statistics notification from uCode
  1412. * might not reflect the current uCode activity
  1413. */
  1414. general = &priv->statistics.general;
  1415. dbg = &priv->statistics.general.dbg;
  1416. div = &priv->statistics.general.div;
  1417. accum_general = &priv->accum_statistics.general;
  1418. accum_dbg = &priv->accum_statistics.general.dbg;
  1419. accum_div = &priv->accum_statistics.general.div;
  1420. pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
  1421. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_General:\n");
  1422. pos += scnprintf(buf + pos, bufsz - pos,
  1423. "\t\t\tcurrent\t\t\taccumulative\n");
  1424. pos += scnprintf(buf + pos, bufsz - pos, "temperature:\t\t\t%u\n",
  1425. le32_to_cpu(general->temperature));
  1426. pos += scnprintf(buf + pos, bufsz - pos, "temperature_m:\t\t\t%u\n",
  1427. le32_to_cpu(general->temperature_m));
  1428. pos += scnprintf(buf + pos, bufsz - pos,
  1429. "burst_check:\t\t\t%u\t\t\t%u\n",
  1430. le32_to_cpu(dbg->burst_check),
  1431. accum_dbg->burst_check);
  1432. pos += scnprintf(buf + pos, bufsz - pos,
  1433. "burst_count:\t\t\t%u\t\t\t%u\n",
  1434. le32_to_cpu(dbg->burst_count),
  1435. accum_dbg->burst_count);
  1436. pos += scnprintf(buf + pos, bufsz - pos,
  1437. "sleep_time:\t\t\t%u\t\t\t%u\n",
  1438. le32_to_cpu(general->sleep_time),
  1439. accum_general->sleep_time);
  1440. pos += scnprintf(buf + pos, bufsz - pos,
  1441. "slots_out:\t\t\t%u\t\t\t%u\n",
  1442. le32_to_cpu(general->slots_out),
  1443. accum_general->slots_out);
  1444. pos += scnprintf(buf + pos, bufsz - pos,
  1445. "slots_idle:\t\t\t%u\t\t\t%u\n",
  1446. le32_to_cpu(general->slots_idle),
  1447. accum_general->slots_idle);
  1448. pos += scnprintf(buf + pos, bufsz - pos, "ttl_timestamp:\t\t\t%u\n",
  1449. le32_to_cpu(general->ttl_timestamp));
  1450. pos += scnprintf(buf + pos, bufsz - pos, "tx_on_a:\t\t\t%u\t\t\t%u\n",
  1451. le32_to_cpu(div->tx_on_a), accum_div->tx_on_a);
  1452. pos += scnprintf(buf + pos, bufsz - pos, "tx_on_b:\t\t\t%u\t\t\t%u\n",
  1453. le32_to_cpu(div->tx_on_b), accum_div->tx_on_b);
  1454. pos += scnprintf(buf + pos, bufsz - pos,
  1455. "exec_time:\t\t\t%u\t\t\t%u\n",
  1456. le32_to_cpu(div->exec_time), accum_div->exec_time);
  1457. pos += scnprintf(buf + pos, bufsz - pos,
  1458. "probe_time:\t\t\t%u\t\t\t%u\n",
  1459. le32_to_cpu(div->probe_time), accum_div->probe_time);
  1460. pos += scnprintf(buf + pos, bufsz - pos,
  1461. "rx_enable_counter:\t\t%u\t\t\t%u\n",
  1462. le32_to_cpu(general->rx_enable_counter),
  1463. accum_general->rx_enable_counter);
  1464. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1465. kfree(buf);
  1466. return ret;
  1467. }
  1468. static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
  1469. char __user *user_buf,
  1470. size_t count, loff_t *ppos) {
  1471. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1472. int pos = 0;
  1473. int cnt = 0;
  1474. char *buf;
  1475. int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
  1476. ssize_t ret;
  1477. struct iwl_sensitivity_data *data;
  1478. data = &priv->sensitivity_data;
  1479. buf = kzalloc(bufsz, GFP_KERNEL);
  1480. if (!buf) {
  1481. IWL_ERR(priv, "Can not allocate Buffer\n");
  1482. return -ENOMEM;
  1483. }
  1484. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
  1485. data->auto_corr_ofdm);
  1486. pos += scnprintf(buf + pos, bufsz - pos,
  1487. "auto_corr_ofdm_mrc:\t\t %u\n",
  1488. data->auto_corr_ofdm_mrc);
  1489. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
  1490. data->auto_corr_ofdm_x1);
  1491. pos += scnprintf(buf + pos, bufsz - pos,
  1492. "auto_corr_ofdm_mrc_x1:\t\t %u\n",
  1493. data->auto_corr_ofdm_mrc_x1);
  1494. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
  1495. data->auto_corr_cck);
  1496. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
  1497. data->auto_corr_cck_mrc);
  1498. pos += scnprintf(buf + pos, bufsz - pos,
  1499. "last_bad_plcp_cnt_ofdm:\t\t %u\n",
  1500. data->last_bad_plcp_cnt_ofdm);
  1501. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
  1502. data->last_fa_cnt_ofdm);
  1503. pos += scnprintf(buf + pos, bufsz - pos,
  1504. "last_bad_plcp_cnt_cck:\t\t %u\n",
  1505. data->last_bad_plcp_cnt_cck);
  1506. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
  1507. data->last_fa_cnt_cck);
  1508. pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
  1509. data->nrg_curr_state);
  1510. pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
  1511. data->nrg_prev_state);
  1512. pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
  1513. for (cnt = 0; cnt < 10; cnt++) {
  1514. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1515. data->nrg_value[cnt]);
  1516. }
  1517. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1518. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
  1519. for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
  1520. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1521. data->nrg_silence_rssi[cnt]);
  1522. }
  1523. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1524. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
  1525. data->nrg_silence_ref);
  1526. pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
  1527. data->nrg_energy_idx);
  1528. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
  1529. data->nrg_silence_idx);
  1530. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
  1531. data->nrg_th_cck);
  1532. pos += scnprintf(buf + pos, bufsz - pos,
  1533. "nrg_auto_corr_silence_diff:\t %u\n",
  1534. data->nrg_auto_corr_silence_diff);
  1535. pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
  1536. data->num_in_cck_no_fa);
  1537. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
  1538. data->nrg_th_ofdm);
  1539. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1540. kfree(buf);
  1541. return ret;
  1542. }
  1543. static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
  1544. char __user *user_buf,
  1545. size_t count, loff_t *ppos) {
  1546. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1547. int pos = 0;
  1548. int cnt = 0;
  1549. char *buf;
  1550. int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
  1551. ssize_t ret;
  1552. struct iwl_chain_noise_data *data;
  1553. data = &priv->chain_noise_data;
  1554. buf = kzalloc(bufsz, GFP_KERNEL);
  1555. if (!buf) {
  1556. IWL_ERR(priv, "Can not allocate Buffer\n");
  1557. return -ENOMEM;
  1558. }
  1559. pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
  1560. data->active_chains);
  1561. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
  1562. data->chain_noise_a);
  1563. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
  1564. data->chain_noise_b);
  1565. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
  1566. data->chain_noise_c);
  1567. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
  1568. data->chain_signal_a);
  1569. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
  1570. data->chain_signal_b);
  1571. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
  1572. data->chain_signal_c);
  1573. pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
  1574. data->beacon_count);
  1575. pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
  1576. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1577. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1578. data->disconn_array[cnt]);
  1579. }
  1580. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1581. pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
  1582. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1583. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1584. data->delta_gain_code[cnt]);
  1585. }
  1586. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1587. pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
  1588. data->radio_write);
  1589. pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
  1590. data->state);
  1591. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1592. kfree(buf);
  1593. return ret;
  1594. }
  1595. static ssize_t iwl_dbgfs_tx_power_read(struct file *file,
  1596. char __user *user_buf,
  1597. size_t count, loff_t *ppos) {
  1598. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1599. char buf[128];
  1600. int pos = 0;
  1601. ssize_t ret;
  1602. const size_t bufsz = sizeof(buf);
  1603. struct statistics_tx *tx;
  1604. if (!iwl_is_alive(priv))
  1605. pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
  1606. else {
  1607. /* make request to uCode to retrieve statistics information */
  1608. mutex_lock(&priv->mutex);
  1609. ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
  1610. mutex_unlock(&priv->mutex);
  1611. if (ret) {
  1612. IWL_ERR(priv, "Error sending statistics request: %zd\n",
  1613. ret);
  1614. return -EAGAIN;
  1615. }
  1616. tx = &priv->statistics.tx;
  1617. if (tx->tx_power.ant_a ||
  1618. tx->tx_power.ant_b ||
  1619. tx->tx_power.ant_c) {
  1620. pos += scnprintf(buf + pos, bufsz - pos,
  1621. "tx power: (1/2 dB step)\n");
  1622. if ((priv->cfg->valid_tx_ant & ANT_A) &&
  1623. tx->tx_power.ant_a)
  1624. pos += scnprintf(buf + pos, bufsz - pos,
  1625. "\tantenna A: 0x%X\n",
  1626. tx->tx_power.ant_a);
  1627. if ((priv->cfg->valid_tx_ant & ANT_B) &&
  1628. tx->tx_power.ant_b)
  1629. pos += scnprintf(buf + pos, bufsz - pos,
  1630. "\tantenna B: 0x%X\n",
  1631. tx->tx_power.ant_b);
  1632. if ((priv->cfg->valid_tx_ant & ANT_C) &&
  1633. tx->tx_power.ant_c)
  1634. pos += scnprintf(buf + pos, bufsz - pos,
  1635. "\tantenna C: 0x%X\n",
  1636. tx->tx_power.ant_c);
  1637. } else
  1638. pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
  1639. }
  1640. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1641. }
  1642. static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
  1643. char __user *user_buf,
  1644. size_t count, loff_t *ppos)
  1645. {
  1646. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1647. char buf[60];
  1648. int pos = 0;
  1649. const size_t bufsz = sizeof(buf);
  1650. u32 pwrsave_status;
  1651. pwrsave_status = iwl_read32(priv, CSR_GP_CNTRL) &
  1652. CSR_GP_REG_POWER_SAVE_STATUS_MSK;
  1653. pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
  1654. pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
  1655. (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
  1656. (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
  1657. (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
  1658. "error");
  1659. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1660. }
  1661. static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
  1662. const char __user *user_buf,
  1663. size_t count, loff_t *ppos)
  1664. {
  1665. struct iwl_priv *priv = file->private_data;
  1666. char buf[8];
  1667. int buf_size;
  1668. int clear;
  1669. memset(buf, 0, sizeof(buf));
  1670. buf_size = min(count, sizeof(buf) - 1);
  1671. if (copy_from_user(buf, user_buf, buf_size))
  1672. return -EFAULT;
  1673. if (sscanf(buf, "%d", &clear) != 1)
  1674. return -EFAULT;
  1675. /* make request to uCode to retrieve statistics information */
  1676. mutex_lock(&priv->mutex);
  1677. iwl_send_statistics_request(priv, CMD_SYNC, true);
  1678. mutex_unlock(&priv->mutex);
  1679. return count;
  1680. }
  1681. static ssize_t iwl_dbgfs_csr_write(struct file *file,
  1682. const char __user *user_buf,
  1683. size_t count, loff_t *ppos)
  1684. {
  1685. struct iwl_priv *priv = file->private_data;
  1686. char buf[8];
  1687. int buf_size;
  1688. int csr;
  1689. memset(buf, 0, sizeof(buf));
  1690. buf_size = min(count, sizeof(buf) - 1);
  1691. if (copy_from_user(buf, user_buf, buf_size))
  1692. return -EFAULT;
  1693. if (sscanf(buf, "%d", &csr) != 1)
  1694. return -EFAULT;
  1695. if (priv->cfg->ops->lib->dump_csr)
  1696. priv->cfg->ops->lib->dump_csr(priv);
  1697. return count;
  1698. }
  1699. DEBUGFS_READ_FILE_OPS(rx_statistics);
  1700. DEBUGFS_READ_FILE_OPS(tx_statistics);
  1701. DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
  1702. DEBUGFS_READ_FILE_OPS(rx_queue);
  1703. DEBUGFS_READ_FILE_OPS(tx_queue);
  1704. DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
  1705. DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
  1706. DEBUGFS_READ_FILE_OPS(ucode_general_stats);
  1707. DEBUGFS_READ_FILE_OPS(sensitivity);
  1708. DEBUGFS_READ_FILE_OPS(chain_noise);
  1709. DEBUGFS_READ_FILE_OPS(tx_power);
  1710. DEBUGFS_READ_FILE_OPS(power_save_status);
  1711. DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
  1712. DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
  1713. DEBUGFS_WRITE_FILE_OPS(csr);
  1714. /*
  1715. * Create the debugfs files and directories
  1716. *
  1717. */
  1718. int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
  1719. {
  1720. struct iwl_debugfs *dbgfs;
  1721. struct dentry *phyd = priv->hw->wiphy->debugfsdir;
  1722. int ret = 0;
  1723. dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
  1724. if (!dbgfs) {
  1725. ret = -ENOMEM;
  1726. goto err;
  1727. }
  1728. priv->dbgfs = dbgfs;
  1729. dbgfs->name = name;
  1730. dbgfs->dir_drv = debugfs_create_dir(name, phyd);
  1731. if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)) {
  1732. ret = -ENOENT;
  1733. goto err;
  1734. }
  1735. DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
  1736. DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv);
  1737. DEBUGFS_ADD_DIR(debug, dbgfs->dir_drv);
  1738. DEBUGFS_ADD_FILE(nvm, data, S_IRUSR);
  1739. DEBUGFS_ADD_FILE(sram, data, S_IWUSR | S_IRUSR);
  1740. DEBUGFS_ADD_FILE(log_event, data, S_IWUSR);
  1741. DEBUGFS_ADD_FILE(stations, data, S_IRUSR);
  1742. DEBUGFS_ADD_FILE(channels, data, S_IRUSR);
  1743. DEBUGFS_ADD_FILE(status, data, S_IRUSR);
  1744. DEBUGFS_ADD_FILE(interrupt, data, S_IWUSR | S_IRUSR);
  1745. DEBUGFS_ADD_FILE(qos, data, S_IRUSR);
  1746. DEBUGFS_ADD_FILE(led, data, S_IRUSR);
  1747. DEBUGFS_ADD_FILE(sleep_level_override, data, S_IWUSR | S_IRUSR);
  1748. DEBUGFS_ADD_FILE(current_sleep_command, data, S_IRUSR);
  1749. DEBUGFS_ADD_FILE(thermal_throttling, data, S_IRUSR);
  1750. DEBUGFS_ADD_FILE(disable_ht40, data, S_IWUSR | S_IRUSR);
  1751. DEBUGFS_ADD_FILE(rx_statistics, debug, S_IRUSR);
  1752. DEBUGFS_ADD_FILE(tx_statistics, debug, S_IRUSR);
  1753. DEBUGFS_ADD_FILE(traffic_log, debug, S_IWUSR | S_IRUSR);
  1754. DEBUGFS_ADD_FILE(rx_queue, debug, S_IRUSR);
  1755. DEBUGFS_ADD_FILE(tx_queue, debug, S_IRUSR);
  1756. DEBUGFS_ADD_FILE(tx_power, debug, S_IRUSR);
  1757. DEBUGFS_ADD_FILE(power_save_status, debug, S_IRUSR);
  1758. DEBUGFS_ADD_FILE(clear_ucode_statistics, debug, S_IWUSR);
  1759. DEBUGFS_ADD_FILE(clear_traffic_statistics, debug, S_IWUSR);
  1760. DEBUGFS_ADD_FILE(csr, debug, S_IWUSR);
  1761. if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) {
  1762. DEBUGFS_ADD_FILE(ucode_rx_stats, debug, S_IRUSR);
  1763. DEBUGFS_ADD_FILE(ucode_tx_stats, debug, S_IRUSR);
  1764. DEBUGFS_ADD_FILE(ucode_general_stats, debug, S_IRUSR);
  1765. DEBUGFS_ADD_FILE(sensitivity, debug, S_IRUSR);
  1766. DEBUGFS_ADD_FILE(chain_noise, debug, S_IRUSR);
  1767. }
  1768. DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
  1769. DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
  1770. &priv->disable_chain_noise_cal);
  1771. if (((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) ||
  1772. ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_3945))
  1773. DEBUGFS_ADD_BOOL(disable_tx_power, rf,
  1774. &priv->disable_tx_power_cal);
  1775. return 0;
  1776. err:
  1777. IWL_ERR(priv, "Can't open the debugfs directory\n");
  1778. iwl_dbgfs_unregister(priv);
  1779. return ret;
  1780. }
  1781. EXPORT_SYMBOL(iwl_dbgfs_register);
  1782. /**
  1783. * Remove the debugfs files and directories
  1784. *
  1785. */
  1786. void iwl_dbgfs_unregister(struct iwl_priv *priv)
  1787. {
  1788. if (!priv->dbgfs)
  1789. return;
  1790. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sleep_level_override);
  1791. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_current_sleep_command);
  1792. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_nvm);
  1793. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
  1794. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_log_event);
  1795. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
  1796. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_channels);
  1797. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_status);
  1798. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_interrupt);
  1799. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_qos);
  1800. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_led);
  1801. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_thermal_throttling);
  1802. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_disable_ht40);
  1803. DEBUGFS_REMOVE(priv->dbgfs->dir_data);
  1804. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_rx_statistics);
  1805. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_statistics);
  1806. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_traffic_log);
  1807. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_rx_queue);
  1808. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_queue);
  1809. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_power);
  1810. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_power_save_status);
  1811. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1812. file_clear_ucode_statistics);
  1813. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1814. file_clear_traffic_statistics);
  1815. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_csr);
  1816. if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) {
  1817. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1818. file_ucode_rx_stats);
  1819. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1820. file_ucode_tx_stats);
  1821. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1822. file_ucode_general_stats);
  1823. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1824. file_sensitivity);
  1825. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1826. file_chain_noise);
  1827. }
  1828. DEBUGFS_REMOVE(priv->dbgfs->dir_debug);
  1829. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
  1830. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
  1831. if (((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) ||
  1832. ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_3945))
  1833. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_tx_power);
  1834. DEBUGFS_REMOVE(priv->dbgfs->dir_rf);
  1835. DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
  1836. kfree(priv->dbgfs);
  1837. priv->dbgfs = NULL;
  1838. }
  1839. EXPORT_SYMBOL(iwl_dbgfs_unregister);