iwl-debugfs.c 65 KB

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