iwl-debugfs.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2011 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/slab.h>
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/debugfs.h>
  32. #include <linux/ieee80211.h>
  33. #include <net/mac80211.h>
  34. #include "iwl-dev.h"
  35. #include "iwl-debug.h"
  36. #include "iwl-core.h"
  37. #include "iwl-io.h"
  38. /* create and remove of files */
  39. #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
  40. if (!debugfs_create_file(#name, mode, parent, priv, \
  41. &iwl_dbgfs_##name##_ops)) \
  42. goto err; \
  43. } while (0)
  44. #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
  45. struct dentry *__tmp; \
  46. __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
  47. parent, ptr); \
  48. if (IS_ERR(__tmp) || !__tmp) \
  49. goto err; \
  50. } while (0)
  51. #define DEBUGFS_ADD_X32(name, parent, ptr) do { \
  52. struct dentry *__tmp; \
  53. __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
  54. parent, ptr); \
  55. if (IS_ERR(__tmp) || !__tmp) \
  56. goto err; \
  57. } while (0)
  58. /* file operation */
  59. #define DEBUGFS_READ_FUNC(name) \
  60. static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
  61. char __user *user_buf, \
  62. size_t count, loff_t *ppos);
  63. #define DEBUGFS_WRITE_FUNC(name) \
  64. static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
  65. const char __user *user_buf, \
  66. size_t count, loff_t *ppos);
  67. static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
  68. {
  69. file->private_data = inode->i_private;
  70. return 0;
  71. }
  72. #define DEBUGFS_READ_FILE_OPS(name) \
  73. DEBUGFS_READ_FUNC(name); \
  74. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  75. .read = iwl_dbgfs_##name##_read, \
  76. .open = iwl_dbgfs_open_file_generic, \
  77. .llseek = generic_file_llseek, \
  78. };
  79. #define DEBUGFS_WRITE_FILE_OPS(name) \
  80. DEBUGFS_WRITE_FUNC(name); \
  81. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  82. .write = iwl_dbgfs_##name##_write, \
  83. .open = iwl_dbgfs_open_file_generic, \
  84. .llseek = generic_file_llseek, \
  85. };
  86. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  87. DEBUGFS_READ_FUNC(name); \
  88. DEBUGFS_WRITE_FUNC(name); \
  89. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  90. .write = iwl_dbgfs_##name##_write, \
  91. .read = iwl_dbgfs_##name##_read, \
  92. .open = iwl_dbgfs_open_file_generic, \
  93. .llseek = generic_file_llseek, \
  94. };
  95. static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
  96. char __user *user_buf,
  97. size_t count, loff_t *ppos) {
  98. struct iwl_priv *priv = file->private_data;
  99. char *buf;
  100. int pos = 0;
  101. int cnt;
  102. ssize_t ret;
  103. const size_t bufsz = 100 +
  104. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  105. buf = kzalloc(bufsz, GFP_KERNEL);
  106. if (!buf)
  107. return -ENOMEM;
  108. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  109. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  110. pos += scnprintf(buf + pos, bufsz - pos,
  111. "\t%25s\t\t: %u\n",
  112. get_mgmt_string(cnt),
  113. priv->tx_stats.mgmt[cnt]);
  114. }
  115. pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
  116. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  117. pos += scnprintf(buf + pos, bufsz - pos,
  118. "\t%25s\t\t: %u\n",
  119. get_ctrl_string(cnt),
  120. priv->tx_stats.ctrl[cnt]);
  121. }
  122. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  123. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  124. priv->tx_stats.data_cnt);
  125. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  126. priv->tx_stats.data_bytes);
  127. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  128. kfree(buf);
  129. return ret;
  130. }
  131. static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
  132. const char __user *user_buf,
  133. size_t count, loff_t *ppos)
  134. {
  135. struct iwl_priv *priv = file->private_data;
  136. u32 clear_flag;
  137. char buf[8];
  138. int buf_size;
  139. memset(buf, 0, sizeof(buf));
  140. buf_size = min(count, sizeof(buf) - 1);
  141. if (copy_from_user(buf, user_buf, buf_size))
  142. return -EFAULT;
  143. if (sscanf(buf, "%x", &clear_flag) != 1)
  144. return -EFAULT;
  145. iwl_clear_traffic_stats(priv);
  146. return count;
  147. }
  148. static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
  149. char __user *user_buf,
  150. size_t count, loff_t *ppos) {
  151. struct iwl_priv *priv = file->private_data;
  152. char *buf;
  153. int pos = 0;
  154. int cnt;
  155. ssize_t ret;
  156. const size_t bufsz = 100 +
  157. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  158. buf = kzalloc(bufsz, GFP_KERNEL);
  159. if (!buf)
  160. return -ENOMEM;
  161. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  162. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  163. pos += scnprintf(buf + pos, bufsz - pos,
  164. "\t%25s\t\t: %u\n",
  165. get_mgmt_string(cnt),
  166. priv->rx_stats.mgmt[cnt]);
  167. }
  168. pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
  169. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  170. pos += scnprintf(buf + pos, bufsz - pos,
  171. "\t%25s\t\t: %u\n",
  172. get_ctrl_string(cnt),
  173. priv->rx_stats.ctrl[cnt]);
  174. }
  175. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  176. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  177. priv->rx_stats.data_cnt);
  178. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  179. priv->rx_stats.data_bytes);
  180. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  181. kfree(buf);
  182. return ret;
  183. }
  184. static ssize_t iwl_dbgfs_sram_read(struct file *file,
  185. char __user *user_buf,
  186. size_t count, loff_t *ppos)
  187. {
  188. u32 val = 0;
  189. char *buf;
  190. ssize_t ret;
  191. int i = 0;
  192. bool device_format = false;
  193. int offset = 0;
  194. int len = 0;
  195. int pos = 0;
  196. int sram;
  197. struct iwl_priv *priv = file->private_data;
  198. size_t bufsz;
  199. /* default is to dump the entire data segment */
  200. if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
  201. priv->dbgfs_sram_offset = 0x800000;
  202. if (priv->ucode_type == UCODE_SUBTYPE_INIT)
  203. priv->dbgfs_sram_len = priv->ucode_init.data.len;
  204. else
  205. priv->dbgfs_sram_len = priv->ucode_rt.data.len;
  206. }
  207. len = priv->dbgfs_sram_len;
  208. if (len == -4) {
  209. device_format = true;
  210. len = 4;
  211. }
  212. bufsz = 50 + len * 4;
  213. buf = kmalloc(bufsz, GFP_KERNEL);
  214. if (!buf)
  215. return -ENOMEM;
  216. pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
  217. len);
  218. pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
  219. priv->dbgfs_sram_offset);
  220. /* adjust sram address since reads are only on even u32 boundaries */
  221. offset = priv->dbgfs_sram_offset & 0x3;
  222. sram = priv->dbgfs_sram_offset & ~0x3;
  223. /* read the first u32 from sram */
  224. val = iwl_read_targ_mem(priv, sram);
  225. for (; len; len--) {
  226. /* put the address at the start of every line */
  227. if (i == 0)
  228. pos += scnprintf(buf + pos, bufsz - pos,
  229. "%08X: ", sram + offset);
  230. if (device_format)
  231. pos += scnprintf(buf + pos, bufsz - pos,
  232. "%02x", (val >> (8 * (3 - offset))) & 0xff);
  233. else
  234. pos += scnprintf(buf + pos, bufsz - pos,
  235. "%02x ", (val >> (8 * offset)) & 0xff);
  236. /* if all bytes processed, read the next u32 from sram */
  237. if (++offset == 4) {
  238. sram += 4;
  239. offset = 0;
  240. val = iwl_read_targ_mem(priv, sram);
  241. }
  242. /* put in extra spaces and split lines for human readability */
  243. if (++i == 16) {
  244. i = 0;
  245. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  246. } else if (!(i & 7)) {
  247. pos += scnprintf(buf + pos, bufsz - pos, " ");
  248. } else if (!(i & 3)) {
  249. pos += scnprintf(buf + pos, bufsz - pos, " ");
  250. }
  251. }
  252. if (i)
  253. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  254. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  255. kfree(buf);
  256. return ret;
  257. }
  258. static ssize_t iwl_dbgfs_sram_write(struct file *file,
  259. const char __user *user_buf,
  260. size_t count, loff_t *ppos)
  261. {
  262. struct iwl_priv *priv = file->private_data;
  263. char buf[64];
  264. int buf_size;
  265. u32 offset, len;
  266. memset(buf, 0, sizeof(buf));
  267. buf_size = min(count, sizeof(buf) - 1);
  268. if (copy_from_user(buf, user_buf, buf_size))
  269. return -EFAULT;
  270. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  271. priv->dbgfs_sram_offset = offset;
  272. priv->dbgfs_sram_len = len;
  273. } else if (sscanf(buf, "%x", &offset) == 1) {
  274. priv->dbgfs_sram_offset = offset;
  275. priv->dbgfs_sram_len = -4;
  276. } else {
  277. priv->dbgfs_sram_offset = 0;
  278. priv->dbgfs_sram_len = 0;
  279. }
  280. return count;
  281. }
  282. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  283. size_t count, loff_t *ppos)
  284. {
  285. struct iwl_priv *priv = file->private_data;
  286. struct iwl_station_entry *station;
  287. int max_sta = priv->hw_params.max_stations;
  288. char *buf;
  289. int i, j, pos = 0;
  290. ssize_t ret;
  291. /* Add 30 for initial string */
  292. const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
  293. buf = kmalloc(bufsz, GFP_KERNEL);
  294. if (!buf)
  295. return -ENOMEM;
  296. pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
  297. priv->num_stations);
  298. for (i = 0; i < max_sta; i++) {
  299. station = &priv->stations[i];
  300. if (!station->used)
  301. continue;
  302. pos += scnprintf(buf + pos, bufsz - pos,
  303. "station %d - addr: %pM, flags: %#x\n",
  304. i, station->sta.sta.addr,
  305. station->sta.station_flags_msk);
  306. pos += scnprintf(buf + pos, bufsz - pos,
  307. "TID\tseq_num\ttxq_id\tframes\ttfds\t");
  308. pos += scnprintf(buf + pos, bufsz - pos,
  309. "start_idx\tbitmap\t\t\trate_n_flags\n");
  310. for (j = 0; j < MAX_TID_COUNT; j++) {
  311. pos += scnprintf(buf + pos, bufsz - pos,
  312. "%d:\t%#x\t%#x\t%u\t%u\t%u\t\t%#.16llx\t%#x",
  313. j, station->tid[j].seq_number,
  314. station->tid[j].agg.txq_id,
  315. station->tid[j].agg.frame_count,
  316. station->tid[j].tfds_in_queue,
  317. station->tid[j].agg.start_idx,
  318. station->tid[j].agg.bitmap,
  319. station->tid[j].agg.rate_n_flags);
  320. if (station->tid[j].agg.wait_for_ba)
  321. pos += scnprintf(buf + pos, bufsz - pos,
  322. " - waitforba");
  323. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  324. }
  325. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  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 = 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->base_params->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_read(struct file *file,
  377. char __user *user_buf,
  378. size_t count, loff_t *ppos)
  379. {
  380. struct iwl_priv *priv = file->private_data;
  381. char *buf;
  382. int pos = 0;
  383. ssize_t ret = -ENOMEM;
  384. ret = pos = iwl_dump_nic_event_log(priv, true, &buf, true);
  385. if (buf) {
  386. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  387. kfree(buf);
  388. }
  389. return ret;
  390. }
  391. static ssize_t iwl_dbgfs_log_event_write(struct file *file,
  392. const char __user *user_buf,
  393. size_t count, loff_t *ppos)
  394. {
  395. struct iwl_priv *priv = file->private_data;
  396. u32 event_log_flag;
  397. char buf[8];
  398. int buf_size;
  399. memset(buf, 0, sizeof(buf));
  400. buf_size = min(count, sizeof(buf) - 1);
  401. if (copy_from_user(buf, user_buf, buf_size))
  402. return -EFAULT;
  403. if (sscanf(buf, "%d", &event_log_flag) != 1)
  404. return -EFAULT;
  405. if (event_log_flag == 1)
  406. iwl_dump_nic_event_log(priv, true, NULL, false);
  407. return count;
  408. }
  409. static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
  410. size_t count, loff_t *ppos)
  411. {
  412. struct iwl_priv *priv = file->private_data;
  413. struct ieee80211_channel *channels = NULL;
  414. const struct ieee80211_supported_band *supp_band = NULL;
  415. int pos = 0, i, bufsz = PAGE_SIZE;
  416. char *buf;
  417. ssize_t ret;
  418. if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
  419. return -EAGAIN;
  420. buf = kzalloc(bufsz, GFP_KERNEL);
  421. if (!buf) {
  422. IWL_ERR(priv, "Can not allocate Buffer\n");
  423. return -ENOMEM;
  424. }
  425. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
  426. if (supp_band) {
  427. channels = supp_band->channels;
  428. pos += scnprintf(buf + pos, bufsz - pos,
  429. "Displaying %d channels in 2.4GHz band 802.11bg):\n",
  430. supp_band->n_channels);
  431. for (i = 0; i < supp_band->n_channels; i++)
  432. pos += scnprintf(buf + pos, bufsz - pos,
  433. "%d: %ddBm: BSS%s%s, %s.\n",
  434. channels[i].hw_value,
  435. channels[i].max_power,
  436. channels[i].flags & IEEE80211_CHAN_RADAR ?
  437. " (IEEE 802.11h required)" : "",
  438. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  439. || (channels[i].flags &
  440. IEEE80211_CHAN_RADAR)) ? "" :
  441. ", IBSS",
  442. channels[i].flags &
  443. IEEE80211_CHAN_PASSIVE_SCAN ?
  444. "passive only" : "active/passive");
  445. }
  446. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
  447. if (supp_band) {
  448. channels = supp_band->channels;
  449. pos += scnprintf(buf + pos, bufsz - pos,
  450. "Displaying %d channels in 5.2GHz band (802.11a)\n",
  451. supp_band->n_channels);
  452. for (i = 0; i < supp_band->n_channels; i++)
  453. pos += scnprintf(buf + pos, bufsz - pos,
  454. "%d: %ddBm: BSS%s%s, %s.\n",
  455. channels[i].hw_value,
  456. channels[i].max_power,
  457. channels[i].flags & IEEE80211_CHAN_RADAR ?
  458. " (IEEE 802.11h required)" : "",
  459. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  460. || (channels[i].flags &
  461. IEEE80211_CHAN_RADAR)) ? "" :
  462. ", IBSS",
  463. channels[i].flags &
  464. IEEE80211_CHAN_PASSIVE_SCAN ?
  465. "passive only" : "active/passive");
  466. }
  467. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  468. kfree(buf);
  469. return ret;
  470. }
  471. static ssize_t iwl_dbgfs_status_read(struct file *file,
  472. char __user *user_buf,
  473. size_t count, loff_t *ppos) {
  474. struct iwl_priv *priv = file->private_data;
  475. char buf[512];
  476. int pos = 0;
  477. const size_t bufsz = sizeof(buf);
  478. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
  479. test_bit(STATUS_HCMD_ACTIVE, &priv->status));
  480. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
  481. test_bit(STATUS_INT_ENABLED, &priv->status));
  482. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
  483. test_bit(STATUS_RF_KILL_HW, &priv->status));
  484. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
  485. test_bit(STATUS_CT_KILL, &priv->status));
  486. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
  487. test_bit(STATUS_INIT, &priv->status));
  488. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
  489. test_bit(STATUS_ALIVE, &priv->status));
  490. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
  491. test_bit(STATUS_READY, &priv->status));
  492. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
  493. test_bit(STATUS_TEMPERATURE, &priv->status));
  494. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
  495. test_bit(STATUS_GEO_CONFIGURED, &priv->status));
  496. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
  497. test_bit(STATUS_EXIT_PENDING, &priv->status));
  498. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
  499. test_bit(STATUS_STATISTICS, &priv->status));
  500. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
  501. test_bit(STATUS_SCANNING, &priv->status));
  502. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
  503. test_bit(STATUS_SCAN_ABORTING, &priv->status));
  504. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
  505. test_bit(STATUS_SCAN_HW, &priv->status));
  506. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
  507. test_bit(STATUS_POWER_PMI, &priv->status));
  508. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
  509. test_bit(STATUS_FW_ERROR, &priv->status));
  510. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  511. }
  512. static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
  513. char __user *user_buf,
  514. size_t count, loff_t *ppos) {
  515. struct iwl_priv *priv = file->private_data;
  516. int pos = 0;
  517. int cnt = 0;
  518. char *buf;
  519. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  520. ssize_t ret;
  521. buf = kzalloc(bufsz, GFP_KERNEL);
  522. if (!buf) {
  523. IWL_ERR(priv, "Can not allocate Buffer\n");
  524. return -ENOMEM;
  525. }
  526. pos += scnprintf(buf + pos, bufsz - pos,
  527. "Interrupt Statistics Report:\n");
  528. pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
  529. priv->isr_stats.hw);
  530. pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
  531. priv->isr_stats.sw);
  532. if (priv->isr_stats.sw || priv->isr_stats.hw) {
  533. pos += scnprintf(buf + pos, bufsz - pos,
  534. "\tLast Restarting Code: 0x%X\n",
  535. priv->isr_stats.err_code);
  536. }
  537. #ifdef CONFIG_IWLWIFI_DEBUG
  538. pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
  539. priv->isr_stats.sch);
  540. pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
  541. priv->isr_stats.alive);
  542. #endif
  543. pos += scnprintf(buf + pos, bufsz - pos,
  544. "HW RF KILL switch toggled:\t %u\n",
  545. priv->isr_stats.rfkill);
  546. pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
  547. priv->isr_stats.ctkill);
  548. pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
  549. priv->isr_stats.wakeup);
  550. pos += scnprintf(buf + pos, bufsz - pos,
  551. "Rx command responses:\t\t %u\n",
  552. priv->isr_stats.rx);
  553. for (cnt = 0; cnt < REPLY_MAX; cnt++) {
  554. if (priv->isr_stats.rx_handlers[cnt] > 0)
  555. pos += scnprintf(buf + pos, bufsz - pos,
  556. "\tRx handler[%36s]:\t\t %u\n",
  557. get_cmd_string(cnt),
  558. priv->isr_stats.rx_handlers[cnt]);
  559. }
  560. pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
  561. priv->isr_stats.tx);
  562. pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
  563. priv->isr_stats.unhandled);
  564. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  565. kfree(buf);
  566. return ret;
  567. }
  568. static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
  569. const char __user *user_buf,
  570. size_t count, loff_t *ppos)
  571. {
  572. struct iwl_priv *priv = file->private_data;
  573. char buf[8];
  574. int buf_size;
  575. u32 reset_flag;
  576. memset(buf, 0, sizeof(buf));
  577. buf_size = min(count, sizeof(buf) - 1);
  578. if (copy_from_user(buf, user_buf, buf_size))
  579. return -EFAULT;
  580. if (sscanf(buf, "%x", &reset_flag) != 1)
  581. return -EFAULT;
  582. if (reset_flag == 0)
  583. iwl_clear_isr_stats(priv);
  584. return count;
  585. }
  586. static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
  587. size_t count, loff_t *ppos)
  588. {
  589. struct iwl_priv *priv = file->private_data;
  590. struct iwl_rxon_context *ctx;
  591. int pos = 0, i;
  592. char buf[256 * NUM_IWL_RXON_CTX];
  593. const size_t bufsz = sizeof(buf);
  594. for_each_context(priv, ctx) {
  595. pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
  596. ctx->ctxid);
  597. for (i = 0; i < AC_NUM; i++) {
  598. pos += scnprintf(buf + pos, bufsz - pos,
  599. "\tcw_min\tcw_max\taifsn\ttxop\n");
  600. pos += scnprintf(buf + pos, bufsz - pos,
  601. "AC[%d]\t%u\t%u\t%u\t%u\n", i,
  602. ctx->qos_data.def_qos_parm.ac[i].cw_min,
  603. ctx->qos_data.def_qos_parm.ac[i].cw_max,
  604. ctx->qos_data.def_qos_parm.ac[i].aifsn,
  605. ctx->qos_data.def_qos_parm.ac[i].edca_txop);
  606. }
  607. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  608. }
  609. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  610. }
  611. static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
  612. char __user *user_buf,
  613. size_t count, loff_t *ppos)
  614. {
  615. struct iwl_priv *priv = file->private_data;
  616. struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
  617. struct iwl_tt_restriction *restriction;
  618. char buf[100];
  619. int pos = 0;
  620. const size_t bufsz = sizeof(buf);
  621. pos += scnprintf(buf + pos, bufsz - pos,
  622. "Thermal Throttling Mode: %s\n",
  623. tt->advanced_tt ? "Advance" : "Legacy");
  624. pos += scnprintf(buf + pos, bufsz - pos,
  625. "Thermal Throttling State: %d\n",
  626. tt->state);
  627. if (tt->advanced_tt) {
  628. restriction = tt->restriction + tt->state;
  629. pos += scnprintf(buf + pos, bufsz - pos,
  630. "Tx mode: %d\n",
  631. restriction->tx_stream);
  632. pos += scnprintf(buf + pos, bufsz - pos,
  633. "Rx mode: %d\n",
  634. restriction->rx_stream);
  635. pos += scnprintf(buf + pos, bufsz - pos,
  636. "HT mode: %d\n",
  637. restriction->is_ht);
  638. }
  639. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  640. }
  641. static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
  642. const char __user *user_buf,
  643. size_t count, loff_t *ppos)
  644. {
  645. struct iwl_priv *priv = file->private_data;
  646. char buf[8];
  647. int buf_size;
  648. int ht40;
  649. memset(buf, 0, sizeof(buf));
  650. buf_size = min(count, sizeof(buf) - 1);
  651. if (copy_from_user(buf, user_buf, buf_size))
  652. return -EFAULT;
  653. if (sscanf(buf, "%d", &ht40) != 1)
  654. return -EFAULT;
  655. if (!iwl_is_any_associated(priv))
  656. priv->disable_ht40 = ht40 ? true : false;
  657. else {
  658. IWL_ERR(priv, "Sta associated with AP - "
  659. "Change to 40MHz channel support is not allowed\n");
  660. return -EINVAL;
  661. }
  662. return count;
  663. }
  664. static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
  665. char __user *user_buf,
  666. size_t count, loff_t *ppos)
  667. {
  668. struct iwl_priv *priv = file->private_data;
  669. char buf[100];
  670. int pos = 0;
  671. const size_t bufsz = sizeof(buf);
  672. pos += scnprintf(buf + pos, bufsz - pos,
  673. "11n 40MHz Mode: %s\n",
  674. priv->disable_ht40 ? "Disabled" : "Enabled");
  675. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  676. }
  677. static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
  678. const char __user *user_buf,
  679. size_t count, loff_t *ppos)
  680. {
  681. struct iwl_priv *priv = file->private_data;
  682. char buf[8];
  683. int buf_size;
  684. int value;
  685. memset(buf, 0, sizeof(buf));
  686. buf_size = min(count, sizeof(buf) - 1);
  687. if (copy_from_user(buf, user_buf, buf_size))
  688. return -EFAULT;
  689. if (sscanf(buf, "%d", &value) != 1)
  690. return -EINVAL;
  691. /*
  692. * Our users expect 0 to be "CAM", but 0 isn't actually
  693. * valid here. However, let's not confuse them and present
  694. * IWL_POWER_INDEX_1 as "1", not "0".
  695. */
  696. if (value == 0)
  697. return -EINVAL;
  698. else if (value > 0)
  699. value -= 1;
  700. if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
  701. return -EINVAL;
  702. if (!iwl_is_ready_rf(priv))
  703. return -EAGAIN;
  704. priv->power_data.debug_sleep_level_override = value;
  705. mutex_lock(&priv->mutex);
  706. iwl_power_update_mode(priv, true);
  707. mutex_unlock(&priv->mutex);
  708. return count;
  709. }
  710. static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
  711. char __user *user_buf,
  712. size_t count, loff_t *ppos)
  713. {
  714. struct iwl_priv *priv = file->private_data;
  715. char buf[10];
  716. int pos, value;
  717. const size_t bufsz = sizeof(buf);
  718. /* see the write function */
  719. value = priv->power_data.debug_sleep_level_override;
  720. if (value >= 0)
  721. value += 1;
  722. pos = scnprintf(buf, bufsz, "%d\n", value);
  723. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  724. }
  725. static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
  726. char __user *user_buf,
  727. size_t count, loff_t *ppos)
  728. {
  729. struct iwl_priv *priv = file->private_data;
  730. char buf[200];
  731. int pos = 0, i;
  732. const size_t bufsz = sizeof(buf);
  733. struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
  734. pos += scnprintf(buf + pos, bufsz - pos,
  735. "flags: %#.2x\n", le16_to_cpu(cmd->flags));
  736. pos += scnprintf(buf + pos, bufsz - pos,
  737. "RX/TX timeout: %d/%d usec\n",
  738. le32_to_cpu(cmd->rx_data_timeout),
  739. le32_to_cpu(cmd->tx_data_timeout));
  740. for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
  741. pos += scnprintf(buf + pos, bufsz - pos,
  742. "sleep_interval[%d]: %d\n", i,
  743. le32_to_cpu(cmd->sleep_interval[i]));
  744. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  745. }
  746. DEBUGFS_READ_WRITE_FILE_OPS(sram);
  747. DEBUGFS_READ_WRITE_FILE_OPS(log_event);
  748. DEBUGFS_READ_FILE_OPS(nvm);
  749. DEBUGFS_READ_FILE_OPS(stations);
  750. DEBUGFS_READ_FILE_OPS(channels);
  751. DEBUGFS_READ_FILE_OPS(status);
  752. DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
  753. DEBUGFS_READ_FILE_OPS(qos);
  754. DEBUGFS_READ_FILE_OPS(thermal_throttling);
  755. DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
  756. DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
  757. DEBUGFS_READ_FILE_OPS(current_sleep_command);
  758. static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
  759. char __user *user_buf,
  760. size_t count, loff_t *ppos)
  761. {
  762. struct iwl_priv *priv = file->private_data;
  763. int pos = 0, ofs = 0;
  764. int cnt = 0, entry;
  765. struct iwl_tx_queue *txq;
  766. struct iwl_queue *q;
  767. struct iwl_rx_queue *rxq = &priv->rxq;
  768. char *buf;
  769. int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
  770. (priv->cfg->base_params->num_of_queues * 32 * 8) + 400;
  771. const u8 *ptr;
  772. ssize_t ret;
  773. if (!priv->txq) {
  774. IWL_ERR(priv, "txq not ready\n");
  775. return -EAGAIN;
  776. }
  777. buf = kzalloc(bufsz, GFP_KERNEL);
  778. if (!buf) {
  779. IWL_ERR(priv, "Can not allocate buffer\n");
  780. return -ENOMEM;
  781. }
  782. pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
  783. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  784. txq = &priv->txq[cnt];
  785. q = &txq->q;
  786. pos += scnprintf(buf + pos, bufsz - pos,
  787. "q[%d]: read_ptr: %u, write_ptr: %u\n",
  788. cnt, q->read_ptr, q->write_ptr);
  789. }
  790. if (priv->tx_traffic && (iwl_debug_level & IWL_DL_TX)) {
  791. ptr = priv->tx_traffic;
  792. pos += scnprintf(buf + pos, bufsz - pos,
  793. "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
  794. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  795. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  796. entry++, ofs += 16) {
  797. pos += scnprintf(buf + pos, bufsz - pos,
  798. "0x%.4x ", ofs);
  799. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  800. buf + pos, bufsz - pos, 0);
  801. pos += strlen(buf + pos);
  802. if (bufsz - pos > 0)
  803. buf[pos++] = '\n';
  804. }
  805. }
  806. }
  807. pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
  808. pos += scnprintf(buf + pos, bufsz - pos,
  809. "read: %u, write: %u\n",
  810. rxq->read, rxq->write);
  811. if (priv->rx_traffic && (iwl_debug_level & IWL_DL_RX)) {
  812. ptr = priv->rx_traffic;
  813. pos += scnprintf(buf + pos, bufsz - pos,
  814. "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
  815. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  816. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  817. entry++, ofs += 16) {
  818. pos += scnprintf(buf + pos, bufsz - pos,
  819. "0x%.4x ", ofs);
  820. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  821. buf + pos, bufsz - pos, 0);
  822. pos += strlen(buf + pos);
  823. if (bufsz - pos > 0)
  824. buf[pos++] = '\n';
  825. }
  826. }
  827. }
  828. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  829. kfree(buf);
  830. return ret;
  831. }
  832. static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
  833. const char __user *user_buf,
  834. size_t count, loff_t *ppos)
  835. {
  836. struct iwl_priv *priv = file->private_data;
  837. char buf[8];
  838. int buf_size;
  839. int traffic_log;
  840. memset(buf, 0, sizeof(buf));
  841. buf_size = min(count, sizeof(buf) - 1);
  842. if (copy_from_user(buf, user_buf, buf_size))
  843. return -EFAULT;
  844. if (sscanf(buf, "%d", &traffic_log) != 1)
  845. return -EFAULT;
  846. if (traffic_log == 0)
  847. iwl_reset_traffic_log(priv);
  848. return count;
  849. }
  850. static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
  851. char __user *user_buf,
  852. size_t count, loff_t *ppos) {
  853. struct iwl_priv *priv = file->private_data;
  854. struct iwl_tx_queue *txq;
  855. struct iwl_queue *q;
  856. char *buf;
  857. int pos = 0;
  858. int cnt;
  859. int ret;
  860. const size_t bufsz = sizeof(char) * 64 *
  861. priv->cfg->base_params->num_of_queues;
  862. if (!priv->txq) {
  863. IWL_ERR(priv, "txq not ready\n");
  864. return -EAGAIN;
  865. }
  866. buf = kzalloc(bufsz, GFP_KERNEL);
  867. if (!buf)
  868. return -ENOMEM;
  869. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  870. txq = &priv->txq[cnt];
  871. q = &txq->q;
  872. pos += scnprintf(buf + pos, bufsz - pos,
  873. "hwq %.2d: read=%u write=%u stop=%d"
  874. " swq_id=%#.2x (ac %d/hwq %d)\n",
  875. cnt, q->read_ptr, q->write_ptr,
  876. !!test_bit(cnt, priv->queue_stopped),
  877. txq->swq_id, txq->swq_id & 3,
  878. (txq->swq_id >> 2) & 0x1f);
  879. if (cnt >= 4)
  880. continue;
  881. /* for the ACs, display the stop count too */
  882. pos += scnprintf(buf + pos, bufsz - pos,
  883. " stop-count: %d\n",
  884. atomic_read(&priv->queue_stop_count[cnt]));
  885. }
  886. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  887. kfree(buf);
  888. return ret;
  889. }
  890. static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
  891. char __user *user_buf,
  892. size_t count, loff_t *ppos) {
  893. struct iwl_priv *priv = file->private_data;
  894. struct iwl_rx_queue *rxq = &priv->rxq;
  895. char buf[256];
  896. int pos = 0;
  897. const size_t bufsz = sizeof(buf);
  898. pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
  899. rxq->read);
  900. pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
  901. rxq->write);
  902. pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
  903. rxq->free_count);
  904. if (rxq->rb_stts) {
  905. pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
  906. le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
  907. } else {
  908. pos += scnprintf(buf + pos, bufsz - pos,
  909. "closed_rb_num: Not Allocated\n");
  910. }
  911. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  912. }
  913. static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
  914. char __user *user_buf,
  915. size_t count, loff_t *ppos)
  916. {
  917. struct iwl_priv *priv = file->private_data;
  918. return priv->cfg->ops->lib->debugfs_ops.rx_stats_read(file,
  919. user_buf, count, ppos);
  920. }
  921. static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
  922. char __user *user_buf,
  923. size_t count, loff_t *ppos)
  924. {
  925. struct iwl_priv *priv = file->private_data;
  926. return priv->cfg->ops->lib->debugfs_ops.tx_stats_read(file,
  927. user_buf, count, ppos);
  928. }
  929. static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
  930. char __user *user_buf,
  931. size_t count, loff_t *ppos)
  932. {
  933. struct iwl_priv *priv = file->private_data;
  934. return priv->cfg->ops->lib->debugfs_ops.general_stats_read(file,
  935. user_buf, count, ppos);
  936. }
  937. static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
  938. char __user *user_buf,
  939. size_t count, loff_t *ppos) {
  940. struct iwl_priv *priv = file->private_data;
  941. int pos = 0;
  942. int cnt = 0;
  943. char *buf;
  944. int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
  945. ssize_t ret;
  946. struct iwl_sensitivity_data *data;
  947. data = &priv->sensitivity_data;
  948. buf = kzalloc(bufsz, GFP_KERNEL);
  949. if (!buf) {
  950. IWL_ERR(priv, "Can not allocate Buffer\n");
  951. return -ENOMEM;
  952. }
  953. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
  954. data->auto_corr_ofdm);
  955. pos += scnprintf(buf + pos, bufsz - pos,
  956. "auto_corr_ofdm_mrc:\t\t %u\n",
  957. data->auto_corr_ofdm_mrc);
  958. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
  959. data->auto_corr_ofdm_x1);
  960. pos += scnprintf(buf + pos, bufsz - pos,
  961. "auto_corr_ofdm_mrc_x1:\t\t %u\n",
  962. data->auto_corr_ofdm_mrc_x1);
  963. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
  964. data->auto_corr_cck);
  965. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
  966. data->auto_corr_cck_mrc);
  967. pos += scnprintf(buf + pos, bufsz - pos,
  968. "last_bad_plcp_cnt_ofdm:\t\t %u\n",
  969. data->last_bad_plcp_cnt_ofdm);
  970. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
  971. data->last_fa_cnt_ofdm);
  972. pos += scnprintf(buf + pos, bufsz - pos,
  973. "last_bad_plcp_cnt_cck:\t\t %u\n",
  974. data->last_bad_plcp_cnt_cck);
  975. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
  976. data->last_fa_cnt_cck);
  977. pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
  978. data->nrg_curr_state);
  979. pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
  980. data->nrg_prev_state);
  981. pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
  982. for (cnt = 0; cnt < 10; cnt++) {
  983. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  984. data->nrg_value[cnt]);
  985. }
  986. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  987. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
  988. for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
  989. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  990. data->nrg_silence_rssi[cnt]);
  991. }
  992. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  993. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
  994. data->nrg_silence_ref);
  995. pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
  996. data->nrg_energy_idx);
  997. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
  998. data->nrg_silence_idx);
  999. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
  1000. data->nrg_th_cck);
  1001. pos += scnprintf(buf + pos, bufsz - pos,
  1002. "nrg_auto_corr_silence_diff:\t %u\n",
  1003. data->nrg_auto_corr_silence_diff);
  1004. pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
  1005. data->num_in_cck_no_fa);
  1006. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
  1007. data->nrg_th_ofdm);
  1008. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1009. kfree(buf);
  1010. return ret;
  1011. }
  1012. static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
  1013. char __user *user_buf,
  1014. size_t count, loff_t *ppos) {
  1015. struct iwl_priv *priv = file->private_data;
  1016. int pos = 0;
  1017. int cnt = 0;
  1018. char *buf;
  1019. int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
  1020. ssize_t ret;
  1021. struct iwl_chain_noise_data *data;
  1022. data = &priv->chain_noise_data;
  1023. buf = kzalloc(bufsz, GFP_KERNEL);
  1024. if (!buf) {
  1025. IWL_ERR(priv, "Can not allocate Buffer\n");
  1026. return -ENOMEM;
  1027. }
  1028. pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
  1029. data->active_chains);
  1030. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
  1031. data->chain_noise_a);
  1032. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
  1033. data->chain_noise_b);
  1034. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
  1035. data->chain_noise_c);
  1036. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
  1037. data->chain_signal_a);
  1038. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
  1039. data->chain_signal_b);
  1040. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
  1041. data->chain_signal_c);
  1042. pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
  1043. data->beacon_count);
  1044. pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
  1045. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1046. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1047. data->disconn_array[cnt]);
  1048. }
  1049. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1050. pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
  1051. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1052. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1053. data->delta_gain_code[cnt]);
  1054. }
  1055. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1056. pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
  1057. data->radio_write);
  1058. pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
  1059. data->state);
  1060. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1061. kfree(buf);
  1062. return ret;
  1063. }
  1064. static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
  1065. char __user *user_buf,
  1066. size_t count, loff_t *ppos)
  1067. {
  1068. struct iwl_priv *priv = file->private_data;
  1069. char buf[60];
  1070. int pos = 0;
  1071. const size_t bufsz = sizeof(buf);
  1072. u32 pwrsave_status;
  1073. pwrsave_status = iwl_read32(priv, CSR_GP_CNTRL) &
  1074. CSR_GP_REG_POWER_SAVE_STATUS_MSK;
  1075. pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
  1076. pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
  1077. (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
  1078. (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
  1079. (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
  1080. "error");
  1081. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1082. }
  1083. static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
  1084. const char __user *user_buf,
  1085. size_t count, loff_t *ppos)
  1086. {
  1087. struct iwl_priv *priv = file->private_data;
  1088. char buf[8];
  1089. int buf_size;
  1090. int clear;
  1091. memset(buf, 0, sizeof(buf));
  1092. buf_size = min(count, sizeof(buf) - 1);
  1093. if (copy_from_user(buf, user_buf, buf_size))
  1094. return -EFAULT;
  1095. if (sscanf(buf, "%d", &clear) != 1)
  1096. return -EFAULT;
  1097. /* make request to uCode to retrieve statistics information */
  1098. mutex_lock(&priv->mutex);
  1099. iwl_send_statistics_request(priv, CMD_SYNC, true);
  1100. mutex_unlock(&priv->mutex);
  1101. return count;
  1102. }
  1103. static ssize_t iwl_dbgfs_csr_write(struct file *file,
  1104. const char __user *user_buf,
  1105. size_t count, loff_t *ppos)
  1106. {
  1107. struct iwl_priv *priv = file->private_data;
  1108. char buf[8];
  1109. int buf_size;
  1110. int csr;
  1111. memset(buf, 0, sizeof(buf));
  1112. buf_size = min(count, sizeof(buf) - 1);
  1113. if (copy_from_user(buf, user_buf, buf_size))
  1114. return -EFAULT;
  1115. if (sscanf(buf, "%d", &csr) != 1)
  1116. return -EFAULT;
  1117. iwl_dump_csr(priv);
  1118. return count;
  1119. }
  1120. static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
  1121. char __user *user_buf,
  1122. size_t count, loff_t *ppos) {
  1123. struct iwl_priv *priv = file->private_data;
  1124. int pos = 0;
  1125. char buf[128];
  1126. const size_t bufsz = sizeof(buf);
  1127. pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
  1128. priv->event_log.ucode_trace ? "On" : "Off");
  1129. pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
  1130. priv->event_log.non_wraps_count);
  1131. pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
  1132. priv->event_log.wraps_once_count);
  1133. pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
  1134. priv->event_log.wraps_more_count);
  1135. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1136. }
  1137. static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
  1138. const char __user *user_buf,
  1139. size_t count, loff_t *ppos)
  1140. {
  1141. struct iwl_priv *priv = file->private_data;
  1142. char buf[8];
  1143. int buf_size;
  1144. int trace;
  1145. memset(buf, 0, sizeof(buf));
  1146. buf_size = min(count, sizeof(buf) - 1);
  1147. if (copy_from_user(buf, user_buf, buf_size))
  1148. return -EFAULT;
  1149. if (sscanf(buf, "%d", &trace) != 1)
  1150. return -EFAULT;
  1151. if (trace) {
  1152. priv->event_log.ucode_trace = true;
  1153. /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
  1154. mod_timer(&priv->ucode_trace,
  1155. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  1156. } else {
  1157. priv->event_log.ucode_trace = false;
  1158. del_timer_sync(&priv->ucode_trace);
  1159. }
  1160. return count;
  1161. }
  1162. static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
  1163. char __user *user_buf,
  1164. size_t count, loff_t *ppos) {
  1165. struct iwl_priv *priv = file->private_data;
  1166. int len = 0;
  1167. char buf[20];
  1168. len = sprintf(buf, "0x%04X\n",
  1169. le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
  1170. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1171. }
  1172. static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
  1173. char __user *user_buf,
  1174. size_t count, loff_t *ppos) {
  1175. struct iwl_priv *priv = file->private_data;
  1176. int len = 0;
  1177. char buf[20];
  1178. len = sprintf(buf, "0x%04X\n",
  1179. le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
  1180. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1181. }
  1182. static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
  1183. char __user *user_buf,
  1184. size_t count, loff_t *ppos)
  1185. {
  1186. struct iwl_priv *priv = file->private_data;
  1187. char *buf;
  1188. int pos = 0;
  1189. ssize_t ret = -EFAULT;
  1190. ret = pos = iwl_dump_fh(priv, &buf, true);
  1191. if (buf) {
  1192. ret = simple_read_from_buffer(user_buf,
  1193. count, ppos, buf, pos);
  1194. kfree(buf);
  1195. }
  1196. return ret;
  1197. }
  1198. static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
  1199. char __user *user_buf,
  1200. size_t count, loff_t *ppos) {
  1201. struct iwl_priv *priv = file->private_data;
  1202. int pos = 0;
  1203. char buf[12];
  1204. const size_t bufsz = sizeof(buf);
  1205. pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
  1206. priv->missed_beacon_threshold);
  1207. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1208. }
  1209. static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
  1210. const char __user *user_buf,
  1211. size_t count, loff_t *ppos)
  1212. {
  1213. struct iwl_priv *priv = file->private_data;
  1214. char buf[8];
  1215. int buf_size;
  1216. int missed;
  1217. memset(buf, 0, sizeof(buf));
  1218. buf_size = min(count, sizeof(buf) - 1);
  1219. if (copy_from_user(buf, user_buf, buf_size))
  1220. return -EFAULT;
  1221. if (sscanf(buf, "%d", &missed) != 1)
  1222. return -EINVAL;
  1223. if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
  1224. missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
  1225. priv->missed_beacon_threshold =
  1226. IWL_MISSED_BEACON_THRESHOLD_DEF;
  1227. else
  1228. priv->missed_beacon_threshold = missed;
  1229. return count;
  1230. }
  1231. static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
  1232. char __user *user_buf,
  1233. size_t count, loff_t *ppos) {
  1234. struct iwl_priv *priv = file->private_data;
  1235. int pos = 0;
  1236. char buf[12];
  1237. const size_t bufsz = sizeof(buf);
  1238. pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
  1239. priv->cfg->base_params->plcp_delta_threshold);
  1240. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1241. }
  1242. static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
  1243. const char __user *user_buf,
  1244. size_t count, loff_t *ppos) {
  1245. struct iwl_priv *priv = file->private_data;
  1246. char buf[8];
  1247. int buf_size;
  1248. int plcp;
  1249. memset(buf, 0, sizeof(buf));
  1250. buf_size = min(count, sizeof(buf) - 1);
  1251. if (copy_from_user(buf, user_buf, buf_size))
  1252. return -EFAULT;
  1253. if (sscanf(buf, "%d", &plcp) != 1)
  1254. return -EINVAL;
  1255. if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
  1256. (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
  1257. priv->cfg->base_params->plcp_delta_threshold =
  1258. IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
  1259. else
  1260. priv->cfg->base_params->plcp_delta_threshold = plcp;
  1261. return count;
  1262. }
  1263. static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
  1264. char __user *user_buf,
  1265. size_t count, loff_t *ppos) {
  1266. struct iwl_priv *priv = file->private_data;
  1267. int i, pos = 0;
  1268. char buf[300];
  1269. const size_t bufsz = sizeof(buf);
  1270. struct iwl_force_reset *force_reset;
  1271. for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
  1272. force_reset = &priv->force_reset[i];
  1273. pos += scnprintf(buf + pos, bufsz - pos,
  1274. "Force reset method %d\n", i);
  1275. pos += scnprintf(buf + pos, bufsz - pos,
  1276. "\tnumber of reset request: %d\n",
  1277. force_reset->reset_request_count);
  1278. pos += scnprintf(buf + pos, bufsz - pos,
  1279. "\tnumber of reset request success: %d\n",
  1280. force_reset->reset_success_count);
  1281. pos += scnprintf(buf + pos, bufsz - pos,
  1282. "\tnumber of reset request reject: %d\n",
  1283. force_reset->reset_reject_count);
  1284. pos += scnprintf(buf + pos, bufsz - pos,
  1285. "\treset duration: %lu\n",
  1286. force_reset->reset_duration);
  1287. }
  1288. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1289. }
  1290. static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
  1291. const char __user *user_buf,
  1292. size_t count, loff_t *ppos) {
  1293. struct iwl_priv *priv = file->private_data;
  1294. char buf[8];
  1295. int buf_size;
  1296. int reset, ret;
  1297. memset(buf, 0, sizeof(buf));
  1298. buf_size = min(count, sizeof(buf) - 1);
  1299. if (copy_from_user(buf, user_buf, buf_size))
  1300. return -EFAULT;
  1301. if (sscanf(buf, "%d", &reset) != 1)
  1302. return -EINVAL;
  1303. switch (reset) {
  1304. case IWL_RF_RESET:
  1305. case IWL_FW_RESET:
  1306. ret = iwl_force_reset(priv, reset, true);
  1307. break;
  1308. default:
  1309. return -EINVAL;
  1310. }
  1311. return ret ? ret : count;
  1312. }
  1313. static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
  1314. const char __user *user_buf,
  1315. size_t count, loff_t *ppos) {
  1316. struct iwl_priv *priv = file->private_data;
  1317. char buf[8];
  1318. int buf_size;
  1319. int flush;
  1320. memset(buf, 0, sizeof(buf));
  1321. buf_size = min(count, sizeof(buf) - 1);
  1322. if (copy_from_user(buf, user_buf, buf_size))
  1323. return -EFAULT;
  1324. if (sscanf(buf, "%d", &flush) != 1)
  1325. return -EINVAL;
  1326. if (iwl_is_rfkill(priv))
  1327. return -EFAULT;
  1328. priv->cfg->ops->lib->dev_txfifo_flush(priv, IWL_DROP_ALL);
  1329. return count;
  1330. }
  1331. static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
  1332. char __user *user_buf,
  1333. size_t count, loff_t *ppos)
  1334. {
  1335. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1336. return priv->cfg->ops->lib->debugfs_ops.bt_stats_read(file,
  1337. user_buf, count, ppos);
  1338. }
  1339. static ssize_t iwl_dbgfs_wd_timeout_write(struct file *file,
  1340. const char __user *user_buf,
  1341. size_t count, loff_t *ppos) {
  1342. struct iwl_priv *priv = file->private_data;
  1343. char buf[8];
  1344. int buf_size;
  1345. int timeout;
  1346. memset(buf, 0, sizeof(buf));
  1347. buf_size = min(count, sizeof(buf) - 1);
  1348. if (copy_from_user(buf, user_buf, buf_size))
  1349. return -EFAULT;
  1350. if (sscanf(buf, "%d", &timeout) != 1)
  1351. return -EINVAL;
  1352. if (timeout < 0 || timeout > IWL_MAX_WD_TIMEOUT)
  1353. timeout = IWL_DEF_WD_TIMEOUT;
  1354. priv->cfg->base_params->wd_timeout = timeout;
  1355. iwl_setup_watchdog(priv);
  1356. return count;
  1357. }
  1358. static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
  1359. char __user *user_buf,
  1360. size_t count, loff_t *ppos) {
  1361. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1362. int pos = 0;
  1363. char buf[200];
  1364. const size_t bufsz = sizeof(buf);
  1365. if (!priv->bt_enable_flag) {
  1366. pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n");
  1367. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1368. }
  1369. pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n",
  1370. priv->bt_enable_flag);
  1371. pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
  1372. priv->bt_full_concurrent ? "full concurrency" : "3-wire");
  1373. pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
  1374. "last traffic notif: %d\n",
  1375. priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load);
  1376. pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
  1377. "kill_ack_mask: %x, kill_cts_mask: %x\n",
  1378. priv->bt_ch_announce, priv->kill_ack_mask,
  1379. priv->kill_cts_mask);
  1380. pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
  1381. switch (priv->bt_traffic_load) {
  1382. case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
  1383. pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
  1384. break;
  1385. case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
  1386. pos += scnprintf(buf + pos, bufsz - pos, "High\n");
  1387. break;
  1388. case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
  1389. pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
  1390. break;
  1391. case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
  1392. default:
  1393. pos += scnprintf(buf + pos, bufsz - pos, "None\n");
  1394. break;
  1395. }
  1396. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1397. }
  1398. static ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
  1399. char __user *user_buf,
  1400. size_t count, loff_t *ppos)
  1401. {
  1402. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1403. int pos = 0;
  1404. char buf[40];
  1405. const size_t bufsz = sizeof(buf);
  1406. if (priv->cfg->ht_params)
  1407. pos += scnprintf(buf + pos, bufsz - pos,
  1408. "use %s for aggregation\n",
  1409. (priv->cfg->ht_params->use_rts_for_aggregation) ?
  1410. "rts/cts" : "cts-to-self");
  1411. else
  1412. pos += scnprintf(buf + pos, bufsz - pos, "N/A");
  1413. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1414. }
  1415. static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
  1416. const char __user *user_buf,
  1417. size_t count, loff_t *ppos) {
  1418. struct iwl_priv *priv = file->private_data;
  1419. char buf[8];
  1420. int buf_size;
  1421. int rts;
  1422. if (!priv->cfg->ht_params)
  1423. return -EINVAL;
  1424. memset(buf, 0, sizeof(buf));
  1425. buf_size = min(count, sizeof(buf) - 1);
  1426. if (copy_from_user(buf, user_buf, buf_size))
  1427. return -EFAULT;
  1428. if (sscanf(buf, "%d", &rts) != 1)
  1429. return -EINVAL;
  1430. if (rts)
  1431. priv->cfg->ht_params->use_rts_for_aggregation = true;
  1432. else
  1433. priv->cfg->ht_params->use_rts_for_aggregation = false;
  1434. return count;
  1435. }
  1436. static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
  1437. char __user *user_buf,
  1438. size_t count, loff_t *ppos)
  1439. {
  1440. struct iwl_priv *priv = file->private_data;
  1441. if (priv->cfg->ops->lib->debugfs_ops.reply_tx_error)
  1442. return priv->cfg->ops->lib->debugfs_ops.reply_tx_error(
  1443. file, user_buf, count, ppos);
  1444. else
  1445. return -ENODATA;
  1446. }
  1447. DEBUGFS_READ_FILE_OPS(rx_statistics);
  1448. DEBUGFS_READ_FILE_OPS(tx_statistics);
  1449. DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
  1450. DEBUGFS_READ_FILE_OPS(rx_queue);
  1451. DEBUGFS_READ_FILE_OPS(tx_queue);
  1452. DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
  1453. DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
  1454. DEBUGFS_READ_FILE_OPS(ucode_general_stats);
  1455. DEBUGFS_READ_FILE_OPS(sensitivity);
  1456. DEBUGFS_READ_FILE_OPS(chain_noise);
  1457. DEBUGFS_READ_FILE_OPS(power_save_status);
  1458. DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
  1459. DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
  1460. DEBUGFS_WRITE_FILE_OPS(csr);
  1461. DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
  1462. DEBUGFS_READ_FILE_OPS(fh_reg);
  1463. DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
  1464. DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
  1465. DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
  1466. DEBUGFS_READ_FILE_OPS(rxon_flags);
  1467. DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
  1468. DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
  1469. DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
  1470. DEBUGFS_WRITE_FILE_OPS(wd_timeout);
  1471. DEBUGFS_READ_FILE_OPS(bt_traffic);
  1472. DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
  1473. DEBUGFS_READ_FILE_OPS(reply_tx_error);
  1474. /*
  1475. * Create the debugfs files and directories
  1476. *
  1477. */
  1478. int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
  1479. {
  1480. struct dentry *phyd = priv->hw->wiphy->debugfsdir;
  1481. struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
  1482. dir_drv = debugfs_create_dir(name, phyd);
  1483. if (!dir_drv)
  1484. return -ENOMEM;
  1485. priv->debugfs_dir = dir_drv;
  1486. dir_data = debugfs_create_dir("data", dir_drv);
  1487. if (!dir_data)
  1488. goto err;
  1489. dir_rf = debugfs_create_dir("rf", dir_drv);
  1490. if (!dir_rf)
  1491. goto err;
  1492. dir_debug = debugfs_create_dir("debug", dir_drv);
  1493. if (!dir_debug)
  1494. goto err;
  1495. DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
  1496. DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
  1497. DEBUGFS_ADD_FILE(log_event, dir_data, S_IWUSR | S_IRUSR);
  1498. DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
  1499. DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
  1500. DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
  1501. DEBUGFS_ADD_FILE(interrupt, dir_data, S_IWUSR | S_IRUSR);
  1502. DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
  1503. DEBUGFS_ADD_FILE(sleep_level_override, dir_data, S_IWUSR | S_IRUSR);
  1504. DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
  1505. DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
  1506. DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
  1507. DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
  1508. DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
  1509. DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
  1510. DEBUGFS_ADD_FILE(rx_queue, dir_debug, S_IRUSR);
  1511. DEBUGFS_ADD_FILE(tx_queue, dir_debug, S_IRUSR);
  1512. DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
  1513. DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
  1514. DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
  1515. DEBUGFS_ADD_FILE(csr, dir_debug, S_IWUSR);
  1516. DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR);
  1517. DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
  1518. DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
  1519. DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
  1520. DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
  1521. DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
  1522. DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
  1523. if (priv->cfg->ops->lib->dev_txfifo_flush)
  1524. DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR);
  1525. DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR);
  1526. DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
  1527. DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
  1528. DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
  1529. DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR);
  1530. DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR);
  1531. DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
  1532. DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
  1533. DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
  1534. if (iwl_advanced_bt_coexist(priv))
  1535. DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR);
  1536. DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
  1537. &priv->disable_sens_cal);
  1538. DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
  1539. &priv->disable_chain_noise_cal);
  1540. return 0;
  1541. err:
  1542. IWL_ERR(priv, "Can't create the debugfs directory\n");
  1543. iwl_dbgfs_unregister(priv);
  1544. return -ENOMEM;
  1545. }
  1546. /**
  1547. * Remove the debugfs files and directories
  1548. *
  1549. */
  1550. void iwl_dbgfs_unregister(struct iwl_priv *priv)
  1551. {
  1552. if (!priv->debugfs_dir)
  1553. return;
  1554. debugfs_remove_recursive(priv->debugfs_dir);
  1555. priv->debugfs_dir = NULL;
  1556. }