debug.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  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/ieee80211.h>
  29. #include <linux/export.h>
  30. #include <net/mac80211.h>
  31. #include "common.h"
  32. /* create and remove of files */
  33. #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
  34. if (!debugfs_create_file(#name, mode, parent, il, \
  35. &il_dbgfs_##name##_ops)) \
  36. goto err; \
  37. } while (0)
  38. #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
  39. struct dentry *__tmp; \
  40. __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
  41. parent, ptr); \
  42. if (IS_ERR(__tmp) || !__tmp) \
  43. goto err; \
  44. } while (0)
  45. #define DEBUGFS_ADD_X32(name, parent, ptr) do { \
  46. struct dentry *__tmp; \
  47. __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
  48. parent, ptr); \
  49. if (IS_ERR(__tmp) || !__tmp) \
  50. goto err; \
  51. } while (0)
  52. /* file operation */
  53. #define DEBUGFS_READ_FUNC(name) \
  54. static ssize_t il_dbgfs_##name##_read(struct file *file, \
  55. char __user *user_buf, \
  56. size_t count, loff_t *ppos);
  57. #define DEBUGFS_WRITE_FUNC(name) \
  58. static ssize_t il_dbgfs_##name##_write(struct file *file, \
  59. const char __user *user_buf, \
  60. size_t count, loff_t *ppos);
  61. static int
  62. il_dbgfs_open_file_generic(struct inode *inode, struct file *file)
  63. {
  64. file->private_data = inode->i_private;
  65. return 0;
  66. }
  67. #define DEBUGFS_READ_FILE_OPS(name) \
  68. DEBUGFS_READ_FUNC(name); \
  69. static const struct file_operations il_dbgfs_##name##_ops = { \
  70. .read = il_dbgfs_##name##_read, \
  71. .open = il_dbgfs_open_file_generic, \
  72. .llseek = generic_file_llseek, \
  73. };
  74. #define DEBUGFS_WRITE_FILE_OPS(name) \
  75. DEBUGFS_WRITE_FUNC(name); \
  76. static const struct file_operations il_dbgfs_##name##_ops = { \
  77. .write = il_dbgfs_##name##_write, \
  78. .open = il_dbgfs_open_file_generic, \
  79. .llseek = generic_file_llseek, \
  80. };
  81. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  82. DEBUGFS_READ_FUNC(name); \
  83. DEBUGFS_WRITE_FUNC(name); \
  84. static const struct file_operations il_dbgfs_##name##_ops = { \
  85. .write = il_dbgfs_##name##_write, \
  86. .read = il_dbgfs_##name##_read, \
  87. .open = il_dbgfs_open_file_generic, \
  88. .llseek = generic_file_llseek, \
  89. };
  90. static ssize_t
  91. il_dbgfs_tx_stats_read(struct file *file, char __user *user_buf, size_t count,
  92. loff_t *ppos)
  93. {
  94. struct il_priv *il = file->private_data;
  95. char *buf;
  96. int pos = 0;
  97. int cnt;
  98. ssize_t ret;
  99. const size_t bufsz =
  100. 100 + sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  101. buf = kzalloc(bufsz, GFP_KERNEL);
  102. if (!buf)
  103. return -ENOMEM;
  104. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  105. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  106. pos +=
  107. scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
  108. il_get_mgmt_string(cnt), il->tx_stats.mgmt[cnt]);
  109. }
  110. pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
  111. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  112. pos +=
  113. scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
  114. il_get_ctrl_string(cnt), il->tx_stats.ctrl[cnt]);
  115. }
  116. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  117. pos +=
  118. scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  119. il->tx_stats.data_cnt);
  120. pos +=
  121. scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  122. il->tx_stats.data_bytes);
  123. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  124. kfree(buf);
  125. return ret;
  126. }
  127. static ssize_t
  128. il_dbgfs_clear_traffic_stats_write(struct file *file,
  129. const char __user *user_buf, size_t count,
  130. loff_t *ppos)
  131. {
  132. struct il_priv *il = file->private_data;
  133. u32 clear_flag;
  134. char buf[8];
  135. int buf_size;
  136. memset(buf, 0, sizeof(buf));
  137. buf_size = min(count, sizeof(buf) - 1);
  138. if (copy_from_user(buf, user_buf, buf_size))
  139. return -EFAULT;
  140. if (sscanf(buf, "%x", &clear_flag) != 1)
  141. return -EFAULT;
  142. il_clear_traffic_stats(il);
  143. return count;
  144. }
  145. static ssize_t
  146. il_dbgfs_rx_stats_read(struct file *file, char __user *user_buf, size_t count,
  147. loff_t *ppos)
  148. {
  149. struct il_priv *il = file->private_data;
  150. char *buf;
  151. int pos = 0;
  152. int cnt;
  153. ssize_t ret;
  154. const size_t bufsz =
  155. 100 + sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  156. buf = kzalloc(bufsz, GFP_KERNEL);
  157. if (!buf)
  158. return -ENOMEM;
  159. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  160. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  161. pos +=
  162. scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
  163. il_get_mgmt_string(cnt), il->rx_stats.mgmt[cnt]);
  164. }
  165. pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
  166. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  167. pos +=
  168. scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
  169. il_get_ctrl_string(cnt), il->rx_stats.ctrl[cnt]);
  170. }
  171. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  172. pos +=
  173. scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  174. il->rx_stats.data_cnt);
  175. pos +=
  176. scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  177. il->rx_stats.data_bytes);
  178. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  179. kfree(buf);
  180. return ret;
  181. }
  182. #define BYTE1_MASK 0x000000ff;
  183. #define BYTE2_MASK 0x0000ffff;
  184. #define BYTE3_MASK 0x00ffffff;
  185. static ssize_t
  186. il_dbgfs_sram_read(struct file *file, char __user *user_buf, size_t count,
  187. loff_t *ppos)
  188. {
  189. u32 val;
  190. char *buf;
  191. ssize_t ret;
  192. int i;
  193. int pos = 0;
  194. struct il_priv *il = file->private_data;
  195. size_t bufsz;
  196. /* default is to dump the entire data segment */
  197. if (!il->dbgfs_sram_offset && !il->dbgfs_sram_len) {
  198. il->dbgfs_sram_offset = 0x800000;
  199. if (il->ucode_type == UCODE_INIT)
  200. il->dbgfs_sram_len = il->ucode_init_data.len;
  201. else
  202. il->dbgfs_sram_len = il->ucode_data.len;
  203. }
  204. bufsz = 30 + il->dbgfs_sram_len * sizeof(char) * 10;
  205. buf = kmalloc(bufsz, GFP_KERNEL);
  206. if (!buf)
  207. return -ENOMEM;
  208. pos +=
  209. scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
  210. il->dbgfs_sram_len);
  211. pos +=
  212. scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
  213. il->dbgfs_sram_offset);
  214. for (i = il->dbgfs_sram_len; i > 0; i -= 4) {
  215. val =
  216. il_read_targ_mem(il,
  217. il->dbgfs_sram_offset +
  218. il->dbgfs_sram_len - i);
  219. if (i < 4) {
  220. switch (i) {
  221. case 1:
  222. val &= BYTE1_MASK;
  223. break;
  224. case 2:
  225. val &= BYTE2_MASK;
  226. break;
  227. case 3:
  228. val &= BYTE3_MASK;
  229. break;
  230. }
  231. }
  232. if (!(i % 16))
  233. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  234. pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
  235. }
  236. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  237. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  238. kfree(buf);
  239. return ret;
  240. }
  241. static ssize_t
  242. il_dbgfs_sram_write(struct file *file, const char __user *user_buf,
  243. size_t count, loff_t *ppos)
  244. {
  245. struct il_priv *il = file->private_data;
  246. char buf[64];
  247. int buf_size;
  248. u32 offset, len;
  249. memset(buf, 0, sizeof(buf));
  250. buf_size = min(count, sizeof(buf) - 1);
  251. if (copy_from_user(buf, user_buf, buf_size))
  252. return -EFAULT;
  253. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  254. il->dbgfs_sram_offset = offset;
  255. il->dbgfs_sram_len = len;
  256. } else {
  257. il->dbgfs_sram_offset = 0;
  258. il->dbgfs_sram_len = 0;
  259. }
  260. return count;
  261. }
  262. static ssize_t
  263. il_dbgfs_stations_read(struct file *file, char __user *user_buf, size_t count,
  264. loff_t *ppos)
  265. {
  266. struct il_priv *il = file->private_data;
  267. struct il_station_entry *station;
  268. int max_sta = il->hw_params.max_stations;
  269. char *buf;
  270. int i, j, pos = 0;
  271. ssize_t ret;
  272. /* Add 30 for initial string */
  273. const size_t bufsz = 30 + sizeof(char) * 500 * (il->num_stations);
  274. buf = kmalloc(bufsz, GFP_KERNEL);
  275. if (!buf)
  276. return -ENOMEM;
  277. pos +=
  278. scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
  279. il->num_stations);
  280. for (i = 0; i < max_sta; i++) {
  281. station = &il->stations[i];
  282. if (!station->used)
  283. continue;
  284. pos +=
  285. scnprintf(buf + pos, bufsz - pos,
  286. "station %d - addr: %pM, flags: %#x\n", i,
  287. station->sta.sta.addr,
  288. station->sta.station_flags_msk);
  289. pos +=
  290. scnprintf(buf + pos, bufsz - pos,
  291. "TID\tseq_num\ttxq_id\tframes\ttfds\t");
  292. pos +=
  293. scnprintf(buf + pos, bufsz - pos,
  294. "start_idx\tbitmap\t\t\trate_n_flags\n");
  295. for (j = 0; j < MAX_TID_COUNT; j++) {
  296. pos +=
  297. scnprintf(buf + pos, bufsz - pos,
  298. "%d:\t%#x\t%#x\t%u\t%u\t%u\t\t%#.16llx\t%#x",
  299. j, station->tid[j].seq_number,
  300. station->tid[j].agg.txq_id,
  301. station->tid[j].agg.frame_count,
  302. station->tid[j].tfds_in_queue,
  303. station->tid[j].agg.start_idx,
  304. station->tid[j].agg.bitmap,
  305. station->tid[j].agg.rate_n_flags);
  306. if (station->tid[j].agg.wait_for_ba)
  307. pos +=
  308. scnprintf(buf + pos, bufsz - pos,
  309. " - waitforba");
  310. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  311. }
  312. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  313. }
  314. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  315. kfree(buf);
  316. return ret;
  317. }
  318. static ssize_t
  319. il_dbgfs_nvm_read(struct file *file, char __user *user_buf, size_t count,
  320. loff_t *ppos)
  321. {
  322. ssize_t ret;
  323. struct il_priv *il = file->private_data;
  324. int pos = 0, ofs = 0, buf_size = 0;
  325. const u8 *ptr;
  326. char *buf;
  327. u16 eeprom_ver;
  328. size_t eeprom_len = il->cfg->base_params->eeprom_size;
  329. buf_size = 4 * eeprom_len + 256;
  330. if (eeprom_len % 16) {
  331. IL_ERR("NVM size is not multiple of 16.\n");
  332. return -ENODATA;
  333. }
  334. ptr = il->eeprom;
  335. if (!ptr) {
  336. IL_ERR("Invalid EEPROM memory\n");
  337. return -ENOMEM;
  338. }
  339. /* 4 characters for byte 0xYY */
  340. buf = kzalloc(buf_size, GFP_KERNEL);
  341. if (!buf) {
  342. IL_ERR("Can not allocate Buffer\n");
  343. return -ENOMEM;
  344. }
  345. eeprom_ver = il_eeprom_query16(il, EEPROM_VERSION);
  346. pos +=
  347. scnprintf(buf + pos, buf_size - pos, "EEPROM " "version: 0x%x\n",
  348. eeprom_ver);
  349. for (ofs = 0; ofs < eeprom_len; ofs += 16) {
  350. pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
  351. hex_dump_to_buffer(ptr + ofs, 16, 16, 2, buf + pos,
  352. buf_size - pos, 0);
  353. pos += strlen(buf + pos);
  354. if (buf_size - pos > 0)
  355. buf[pos++] = '\n';
  356. }
  357. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  358. kfree(buf);
  359. return ret;
  360. }
  361. static ssize_t
  362. il_dbgfs_channels_read(struct file *file, char __user *user_buf, size_t count,
  363. loff_t *ppos)
  364. {
  365. struct il_priv *il = file->private_data;
  366. struct ieee80211_channel *channels = NULL;
  367. const struct ieee80211_supported_band *supp_band = NULL;
  368. int pos = 0, i, bufsz = PAGE_SIZE;
  369. char *buf;
  370. ssize_t ret;
  371. if (!test_bit(S_GEO_CONFIGURED, &il->status))
  372. return -EAGAIN;
  373. buf = kzalloc(bufsz, GFP_KERNEL);
  374. if (!buf) {
  375. IL_ERR("Can not allocate Buffer\n");
  376. return -ENOMEM;
  377. }
  378. supp_band = il_get_hw_mode(il, IEEE80211_BAND_2GHZ);
  379. if (supp_band) {
  380. channels = supp_band->channels;
  381. pos +=
  382. scnprintf(buf + pos, bufsz - pos,
  383. "Displaying %d channels in 2.4GHz band 802.11bg):\n",
  384. supp_band->n_channels);
  385. for (i = 0; i < supp_band->n_channels; i++)
  386. pos +=
  387. scnprintf(buf + pos, bufsz - pos,
  388. "%d: %ddBm: BSS%s%s, %s.\n",
  389. channels[i].hw_value,
  390. channels[i].max_power,
  391. channels[i].
  392. flags & IEEE80211_CHAN_RADAR ?
  393. " (IEEE 802.11h required)" : "",
  394. ((channels[i].
  395. flags & IEEE80211_CHAN_NO_IBSS) ||
  396. (channels[i].
  397. flags & IEEE80211_CHAN_RADAR)) ? "" :
  398. ", IBSS",
  399. channels[i].
  400. flags & IEEE80211_CHAN_PASSIVE_SCAN ?
  401. "passive only" : "active/passive");
  402. }
  403. supp_band = il_get_hw_mode(il, IEEE80211_BAND_5GHZ);
  404. if (supp_band) {
  405. channels = supp_band->channels;
  406. pos +=
  407. scnprintf(buf + pos, bufsz - pos,
  408. "Displaying %d channels in 5.2GHz band (802.11a)\n",
  409. supp_band->n_channels);
  410. for (i = 0; i < supp_band->n_channels; i++)
  411. pos +=
  412. scnprintf(buf + pos, bufsz - pos,
  413. "%d: %ddBm: BSS%s%s, %s.\n",
  414. channels[i].hw_value,
  415. channels[i].max_power,
  416. channels[i].
  417. flags & IEEE80211_CHAN_RADAR ?
  418. " (IEEE 802.11h required)" : "",
  419. ((channels[i].
  420. flags & IEEE80211_CHAN_NO_IBSS) ||
  421. (channels[i].
  422. flags & IEEE80211_CHAN_RADAR)) ? "" :
  423. ", IBSS",
  424. channels[i].
  425. flags & IEEE80211_CHAN_PASSIVE_SCAN ?
  426. "passive only" : "active/passive");
  427. }
  428. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  429. kfree(buf);
  430. return ret;
  431. }
  432. static ssize_t
  433. il_dbgfs_status_read(struct file *file, char __user *user_buf, size_t count,
  434. loff_t *ppos)
  435. {
  436. struct il_priv *il = file->private_data;
  437. char buf[512];
  438. int pos = 0;
  439. const size_t bufsz = sizeof(buf);
  440. pos +=
  441. scnprintf(buf + pos, bufsz - pos, "S_HCMD_ACTIVE:\t %d\n",
  442. test_bit(S_HCMD_ACTIVE, &il->status));
  443. pos +=
  444. scnprintf(buf + pos, bufsz - pos, "S_INT_ENABLED:\t %d\n",
  445. test_bit(S_INT_ENABLED, &il->status));
  446. pos +=
  447. scnprintf(buf + pos, bufsz - pos, "S_RF_KILL_HW:\t %d\n",
  448. test_bit(S_RF_KILL_HW, &il->status));
  449. pos +=
  450. scnprintf(buf + pos, bufsz - pos, "S_CT_KILL:\t\t %d\n",
  451. test_bit(S_CT_KILL, &il->status));
  452. pos +=
  453. scnprintf(buf + pos, bufsz - pos, "S_INIT:\t\t %d\n",
  454. test_bit(S_INIT, &il->status));
  455. pos +=
  456. scnprintf(buf + pos, bufsz - pos, "S_ALIVE:\t\t %d\n",
  457. test_bit(S_ALIVE, &il->status));
  458. pos +=
  459. scnprintf(buf + pos, bufsz - pos, "S_READY:\t\t %d\n",
  460. test_bit(S_READY, &il->status));
  461. pos +=
  462. scnprintf(buf + pos, bufsz - pos, "S_TEMPERATURE:\t %d\n",
  463. test_bit(S_TEMPERATURE, &il->status));
  464. pos +=
  465. scnprintf(buf + pos, bufsz - pos, "S_GEO_CONFIGURED:\t %d\n",
  466. test_bit(S_GEO_CONFIGURED, &il->status));
  467. pos +=
  468. scnprintf(buf + pos, bufsz - pos, "S_EXIT_PENDING:\t %d\n",
  469. test_bit(S_EXIT_PENDING, &il->status));
  470. pos +=
  471. scnprintf(buf + pos, bufsz - pos, "S_STATS:\t %d\n",
  472. test_bit(S_STATS, &il->status));
  473. pos +=
  474. scnprintf(buf + pos, bufsz - pos, "S_SCANNING:\t %d\n",
  475. test_bit(S_SCANNING, &il->status));
  476. pos +=
  477. scnprintf(buf + pos, bufsz - pos, "S_SCAN_ABORTING:\t %d\n",
  478. test_bit(S_SCAN_ABORTING, &il->status));
  479. pos +=
  480. scnprintf(buf + pos, bufsz - pos, "S_SCAN_HW:\t\t %d\n",
  481. test_bit(S_SCAN_HW, &il->status));
  482. pos +=
  483. scnprintf(buf + pos, bufsz - pos, "S_POWER_PMI:\t %d\n",
  484. test_bit(S_POWER_PMI, &il->status));
  485. pos +=
  486. scnprintf(buf + pos, bufsz - pos, "S_FW_ERROR:\t %d\n",
  487. test_bit(S_FW_ERROR, &il->status));
  488. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  489. }
  490. static ssize_t
  491. il_dbgfs_interrupt_read(struct file *file, char __user *user_buf, size_t count,
  492. loff_t *ppos)
  493. {
  494. struct il_priv *il = file->private_data;
  495. int pos = 0;
  496. int cnt = 0;
  497. char *buf;
  498. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  499. ssize_t ret;
  500. buf = kzalloc(bufsz, GFP_KERNEL);
  501. if (!buf) {
  502. IL_ERR("Can not allocate Buffer\n");
  503. return -ENOMEM;
  504. }
  505. pos +=
  506. scnprintf(buf + pos, bufsz - pos, "Interrupt Statistics Report:\n");
  507. pos +=
  508. scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
  509. il->isr_stats.hw);
  510. pos +=
  511. scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
  512. il->isr_stats.sw);
  513. if (il->isr_stats.sw || il->isr_stats.hw) {
  514. pos +=
  515. scnprintf(buf + pos, bufsz - pos,
  516. "\tLast Restarting Code: 0x%X\n",
  517. il->isr_stats.err_code);
  518. }
  519. #ifdef CONFIG_IWLEGACY_DEBUG
  520. pos +=
  521. scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
  522. il->isr_stats.sch);
  523. pos +=
  524. scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
  525. il->isr_stats.alive);
  526. #endif
  527. pos +=
  528. scnprintf(buf + pos, bufsz - pos,
  529. "HW RF KILL switch toggled:\t %u\n",
  530. il->isr_stats.rfkill);
  531. pos +=
  532. scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
  533. il->isr_stats.ctkill);
  534. pos +=
  535. scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
  536. il->isr_stats.wakeup);
  537. pos +=
  538. scnprintf(buf + pos, bufsz - pos, "Rx command responses:\t\t %u\n",
  539. il->isr_stats.rx);
  540. for (cnt = 0; cnt < IL_CN_MAX; cnt++) {
  541. if (il->isr_stats.handlers[cnt] > 0)
  542. pos +=
  543. scnprintf(buf + pos, bufsz - pos,
  544. "\tRx handler[%36s]:\t\t %u\n",
  545. il_get_cmd_string(cnt),
  546. il->isr_stats.handlers[cnt]);
  547. }
  548. pos +=
  549. scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
  550. il->isr_stats.tx);
  551. pos +=
  552. scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
  553. il->isr_stats.unhandled);
  554. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  555. kfree(buf);
  556. return ret;
  557. }
  558. static ssize_t
  559. il_dbgfs_interrupt_write(struct file *file, const char __user *user_buf,
  560. size_t count, loff_t *ppos)
  561. {
  562. struct il_priv *il = file->private_data;
  563. char buf[8];
  564. int buf_size;
  565. u32 reset_flag;
  566. memset(buf, 0, sizeof(buf));
  567. buf_size = min(count, sizeof(buf) - 1);
  568. if (copy_from_user(buf, user_buf, buf_size))
  569. return -EFAULT;
  570. if (sscanf(buf, "%x", &reset_flag) != 1)
  571. return -EFAULT;
  572. if (reset_flag == 0)
  573. il_clear_isr_stats(il);
  574. return count;
  575. }
  576. static ssize_t
  577. il_dbgfs_qos_read(struct file *file, char __user *user_buf, size_t count,
  578. loff_t *ppos)
  579. {
  580. struct il_priv *il = file->private_data;
  581. struct il_rxon_context *ctx = &il->ctx;
  582. int pos = 0, i;
  583. char buf[256];
  584. const size_t bufsz = sizeof(buf);
  585. pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n", ctx->ctxid);
  586. for (i = 0; i < AC_NUM; i++) {
  587. pos +=
  588. scnprintf(buf + pos, bufsz - pos,
  589. "\tcw_min\tcw_max\taifsn\ttxop\n");
  590. pos +=
  591. scnprintf(buf + pos, bufsz - pos,
  592. "AC[%d]\t%u\t%u\t%u\t%u\n", i,
  593. ctx->qos_data.def_qos_parm.ac[i].cw_min,
  594. ctx->qos_data.def_qos_parm.ac[i].cw_max,
  595. ctx->qos_data.def_qos_parm.ac[i].aifsn,
  596. ctx->qos_data.def_qos_parm.ac[i].edca_txop);
  597. }
  598. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  599. }
  600. static ssize_t
  601. il_dbgfs_disable_ht40_write(struct file *file, const char __user *user_buf,
  602. size_t count, loff_t *ppos)
  603. {
  604. struct il_priv *il = file->private_data;
  605. char buf[8];
  606. int buf_size;
  607. int ht40;
  608. memset(buf, 0, sizeof(buf));
  609. buf_size = min(count, sizeof(buf) - 1);
  610. if (copy_from_user(buf, user_buf, buf_size))
  611. return -EFAULT;
  612. if (sscanf(buf, "%d", &ht40) != 1)
  613. return -EFAULT;
  614. if (!il_is_any_associated(il))
  615. il->disable_ht40 = ht40 ? true : false;
  616. else {
  617. IL_ERR("Sta associated with AP - "
  618. "Change to 40MHz channel support is not allowed\n");
  619. return -EINVAL;
  620. }
  621. return count;
  622. }
  623. static ssize_t
  624. il_dbgfs_disable_ht40_read(struct file *file, char __user *user_buf,
  625. size_t count, loff_t *ppos)
  626. {
  627. struct il_priv *il = file->private_data;
  628. char buf[100];
  629. int pos = 0;
  630. const size_t bufsz = sizeof(buf);
  631. pos +=
  632. scnprintf(buf + pos, bufsz - pos, "11n 40MHz Mode: %s\n",
  633. il->disable_ht40 ? "Disabled" : "Enabled");
  634. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  635. }
  636. DEBUGFS_READ_WRITE_FILE_OPS(sram);
  637. DEBUGFS_READ_FILE_OPS(nvm);
  638. DEBUGFS_READ_FILE_OPS(stations);
  639. DEBUGFS_READ_FILE_OPS(channels);
  640. DEBUGFS_READ_FILE_OPS(status);
  641. DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
  642. DEBUGFS_READ_FILE_OPS(qos);
  643. DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
  644. static ssize_t
  645. il_dbgfs_traffic_log_read(struct file *file, char __user *user_buf,
  646. size_t count, loff_t *ppos)
  647. {
  648. struct il_priv *il = file->private_data;
  649. int pos = 0, ofs = 0;
  650. int cnt = 0, entry;
  651. struct il_tx_queue *txq;
  652. struct il_queue *q;
  653. struct il_rx_queue *rxq = &il->rxq;
  654. char *buf;
  655. int bufsz =
  656. ((IL_TRAFFIC_ENTRIES * IL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
  657. (il->cfg->base_params->num_of_queues * 32 * 8) + 400;
  658. const u8 *ptr;
  659. ssize_t ret;
  660. if (!il->txq) {
  661. IL_ERR("txq not ready\n");
  662. return -EAGAIN;
  663. }
  664. buf = kzalloc(bufsz, GFP_KERNEL);
  665. if (!buf) {
  666. IL_ERR("Can not allocate buffer\n");
  667. return -ENOMEM;
  668. }
  669. pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
  670. for (cnt = 0; cnt < il->hw_params.max_txq_num; cnt++) {
  671. txq = &il->txq[cnt];
  672. q = &txq->q;
  673. pos +=
  674. scnprintf(buf + pos, bufsz - pos,
  675. "q[%d]: read_ptr: %u, write_ptr: %u\n", cnt,
  676. q->read_ptr, q->write_ptr);
  677. }
  678. if (il->tx_traffic && (il_debug_level & IL_DL_TX)) {
  679. ptr = il->tx_traffic;
  680. pos +=
  681. scnprintf(buf + pos, bufsz - pos, "Tx Traffic idx: %u\n",
  682. il->tx_traffic_idx);
  683. for (cnt = 0, ofs = 0; cnt < IL_TRAFFIC_ENTRIES; cnt++) {
  684. for (entry = 0; entry < IL_TRAFFIC_ENTRY_SIZE / 16;
  685. entry++, ofs += 16) {
  686. pos +=
  687. scnprintf(buf + pos, bufsz - pos, "0x%.4x ",
  688. ofs);
  689. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  690. buf + pos, bufsz - pos, 0);
  691. pos += strlen(buf + pos);
  692. if (bufsz - pos > 0)
  693. buf[pos++] = '\n';
  694. }
  695. }
  696. }
  697. pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
  698. pos +=
  699. scnprintf(buf + pos, bufsz - pos, "read: %u, write: %u\n",
  700. rxq->read, rxq->write);
  701. if (il->rx_traffic && (il_debug_level & IL_DL_RX)) {
  702. ptr = il->rx_traffic;
  703. pos +=
  704. scnprintf(buf + pos, bufsz - pos, "Rx Traffic idx: %u\n",
  705. il->rx_traffic_idx);
  706. for (cnt = 0, ofs = 0; cnt < IL_TRAFFIC_ENTRIES; cnt++) {
  707. for (entry = 0; entry < IL_TRAFFIC_ENTRY_SIZE / 16;
  708. entry++, ofs += 16) {
  709. pos +=
  710. scnprintf(buf + pos, bufsz - pos, "0x%.4x ",
  711. ofs);
  712. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  713. buf + pos, bufsz - pos, 0);
  714. pos += strlen(buf + pos);
  715. if (bufsz - pos > 0)
  716. buf[pos++] = '\n';
  717. }
  718. }
  719. }
  720. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  721. kfree(buf);
  722. return ret;
  723. }
  724. static ssize_t
  725. il_dbgfs_traffic_log_write(struct file *file, const char __user *user_buf,
  726. size_t count, loff_t *ppos)
  727. {
  728. struct il_priv *il = file->private_data;
  729. char buf[8];
  730. int buf_size;
  731. int traffic_log;
  732. memset(buf, 0, sizeof(buf));
  733. buf_size = min(count, sizeof(buf) - 1);
  734. if (copy_from_user(buf, user_buf, buf_size))
  735. return -EFAULT;
  736. if (sscanf(buf, "%d", &traffic_log) != 1)
  737. return -EFAULT;
  738. if (traffic_log == 0)
  739. il_reset_traffic_log(il);
  740. return count;
  741. }
  742. static ssize_t
  743. il_dbgfs_tx_queue_read(struct file *file, char __user *user_buf, size_t count,
  744. loff_t *ppos)
  745. {
  746. struct il_priv *il = file->private_data;
  747. struct il_tx_queue *txq;
  748. struct il_queue *q;
  749. char *buf;
  750. int pos = 0;
  751. int cnt;
  752. int ret;
  753. const size_t bufsz =
  754. sizeof(char) * 64 * il->cfg->base_params->num_of_queues;
  755. if (!il->txq) {
  756. IL_ERR("txq not ready\n");
  757. return -EAGAIN;
  758. }
  759. buf = kzalloc(bufsz, GFP_KERNEL);
  760. if (!buf)
  761. return -ENOMEM;
  762. for (cnt = 0; cnt < il->hw_params.max_txq_num; cnt++) {
  763. txq = &il->txq[cnt];
  764. q = &txq->q;
  765. pos +=
  766. scnprintf(buf + pos, bufsz - pos,
  767. "hwq %.2d: read=%u write=%u stop=%d"
  768. " swq_id=%#.2x (ac %d/hwq %d)\n", cnt,
  769. q->read_ptr, q->write_ptr,
  770. !!test_bit(cnt, il->queue_stopped),
  771. txq->swq_id, txq->swq_id & 3,
  772. (txq->swq_id >> 2) & 0x1f);
  773. if (cnt >= 4)
  774. continue;
  775. /* for the ACs, display the stop count too */
  776. pos +=
  777. scnprintf(buf + pos, bufsz - pos,
  778. " stop-count: %d\n",
  779. atomic_read(&il->queue_stop_count[cnt]));
  780. }
  781. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  782. kfree(buf);
  783. return ret;
  784. }
  785. static ssize_t
  786. il_dbgfs_rx_queue_read(struct file *file, char __user *user_buf, size_t count,
  787. loff_t *ppos)
  788. {
  789. struct il_priv *il = file->private_data;
  790. struct il_rx_queue *rxq = &il->rxq;
  791. char buf[256];
  792. int pos = 0;
  793. const size_t bufsz = sizeof(buf);
  794. pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n", rxq->read);
  795. pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n", rxq->write);
  796. pos +=
  797. scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
  798. rxq->free_count);
  799. if (rxq->rb_stts) {
  800. pos +=
  801. scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
  802. le16_to_cpu(rxq->rb_stts->
  803. closed_rb_num) & 0x0FFF);
  804. } else {
  805. pos +=
  806. scnprintf(buf + pos, bufsz - pos,
  807. "closed_rb_num: Not Allocated\n");
  808. }
  809. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  810. }
  811. static ssize_t
  812. il_dbgfs_ucode_rx_stats_read(struct file *file, char __user *user_buf,
  813. size_t count, loff_t *ppos)
  814. {
  815. struct il_priv *il = file->private_data;
  816. return il->cfg->ops->lib->debugfs_ops.rx_stats_read(file, user_buf,
  817. count, ppos);
  818. }
  819. static ssize_t
  820. il_dbgfs_ucode_tx_stats_read(struct file *file, char __user *user_buf,
  821. size_t count, loff_t *ppos)
  822. {
  823. struct il_priv *il = file->private_data;
  824. return il->cfg->ops->lib->debugfs_ops.tx_stats_read(file, user_buf,
  825. count, ppos);
  826. }
  827. static ssize_t
  828. il_dbgfs_ucode_general_stats_read(struct file *file, char __user *user_buf,
  829. size_t count, loff_t *ppos)
  830. {
  831. struct il_priv *il = file->private_data;
  832. return il->cfg->ops->lib->debugfs_ops.general_stats_read(file, user_buf,
  833. count, ppos);
  834. }
  835. static ssize_t
  836. il_dbgfs_sensitivity_read(struct file *file, char __user *user_buf,
  837. size_t count, loff_t *ppos)
  838. {
  839. struct il_priv *il = file->private_data;
  840. int pos = 0;
  841. int cnt = 0;
  842. char *buf;
  843. int bufsz = sizeof(struct il_sensitivity_data) * 4 + 100;
  844. ssize_t ret;
  845. struct il_sensitivity_data *data;
  846. data = &il->sensitivity_data;
  847. buf = kzalloc(bufsz, GFP_KERNEL);
  848. if (!buf) {
  849. IL_ERR("Can not allocate Buffer\n");
  850. return -ENOMEM;
  851. }
  852. pos +=
  853. scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
  854. data->auto_corr_ofdm);
  855. pos +=
  856. scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_mrc:\t\t %u\n",
  857. data->auto_corr_ofdm_mrc);
  858. pos +=
  859. scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
  860. data->auto_corr_ofdm_x1);
  861. pos +=
  862. scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_mrc_x1:\t\t %u\n",
  863. data->auto_corr_ofdm_mrc_x1);
  864. pos +=
  865. scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
  866. data->auto_corr_cck);
  867. pos +=
  868. scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
  869. data->auto_corr_cck_mrc);
  870. pos +=
  871. scnprintf(buf + pos, bufsz - pos,
  872. "last_bad_plcp_cnt_ofdm:\t\t %u\n",
  873. data->last_bad_plcp_cnt_ofdm);
  874. pos +=
  875. scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
  876. data->last_fa_cnt_ofdm);
  877. pos +=
  878. scnprintf(buf + pos, bufsz - pos, "last_bad_plcp_cnt_cck:\t\t %u\n",
  879. data->last_bad_plcp_cnt_cck);
  880. pos +=
  881. scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
  882. data->last_fa_cnt_cck);
  883. pos +=
  884. scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
  885. data->nrg_curr_state);
  886. pos +=
  887. scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
  888. data->nrg_prev_state);
  889. pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
  890. for (cnt = 0; cnt < 10; cnt++) {
  891. pos +=
  892. scnprintf(buf + pos, bufsz - pos, " %u",
  893. data->nrg_value[cnt]);
  894. }
  895. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  896. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
  897. for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
  898. pos +=
  899. scnprintf(buf + pos, bufsz - pos, " %u",
  900. data->nrg_silence_rssi[cnt]);
  901. }
  902. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  903. pos +=
  904. scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
  905. data->nrg_silence_ref);
  906. pos +=
  907. scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
  908. data->nrg_energy_idx);
  909. pos +=
  910. scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
  911. data->nrg_silence_idx);
  912. pos +=
  913. scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
  914. data->nrg_th_cck);
  915. pos +=
  916. scnprintf(buf + pos, bufsz - pos,
  917. "nrg_auto_corr_silence_diff:\t %u\n",
  918. data->nrg_auto_corr_silence_diff);
  919. pos +=
  920. scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
  921. data->num_in_cck_no_fa);
  922. pos +=
  923. scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
  924. data->nrg_th_ofdm);
  925. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  926. kfree(buf);
  927. return ret;
  928. }
  929. static ssize_t
  930. il_dbgfs_chain_noise_read(struct file *file, char __user *user_buf,
  931. size_t count, loff_t *ppos)
  932. {
  933. struct il_priv *il = file->private_data;
  934. int pos = 0;
  935. int cnt = 0;
  936. char *buf;
  937. int bufsz = sizeof(struct il_chain_noise_data) * 4 + 100;
  938. ssize_t ret;
  939. struct il_chain_noise_data *data;
  940. data = &il->chain_noise_data;
  941. buf = kzalloc(bufsz, GFP_KERNEL);
  942. if (!buf) {
  943. IL_ERR("Can not allocate Buffer\n");
  944. return -ENOMEM;
  945. }
  946. pos +=
  947. scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
  948. data->active_chains);
  949. pos +=
  950. scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
  951. data->chain_noise_a);
  952. pos +=
  953. scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
  954. data->chain_noise_b);
  955. pos +=
  956. scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
  957. data->chain_noise_c);
  958. pos +=
  959. scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
  960. data->chain_signal_a);
  961. pos +=
  962. scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
  963. data->chain_signal_b);
  964. pos +=
  965. scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
  966. data->chain_signal_c);
  967. pos +=
  968. scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
  969. data->beacon_count);
  970. pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
  971. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  972. pos +=
  973. scnprintf(buf + pos, bufsz - pos, " %u",
  974. data->disconn_array[cnt]);
  975. }
  976. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  977. pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
  978. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  979. pos +=
  980. scnprintf(buf + pos, bufsz - pos, " %u",
  981. data->delta_gain_code[cnt]);
  982. }
  983. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  984. pos +=
  985. scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
  986. data->radio_write);
  987. pos +=
  988. scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
  989. data->state);
  990. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  991. kfree(buf);
  992. return ret;
  993. }
  994. static ssize_t
  995. il_dbgfs_power_save_status_read(struct file *file, char __user *user_buf,
  996. size_t count, loff_t *ppos)
  997. {
  998. struct il_priv *il = file->private_data;
  999. char buf[60];
  1000. int pos = 0;
  1001. const size_t bufsz = sizeof(buf);
  1002. u32 pwrsave_status;
  1003. pwrsave_status =
  1004. _il_rd(il, CSR_GP_CNTRL) & CSR_GP_REG_POWER_SAVE_STATUS_MSK;
  1005. pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
  1006. pos +=
  1007. scnprintf(buf + pos, bufsz - pos, "%s\n",
  1008. (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
  1009. (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
  1010. (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
  1011. "error");
  1012. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1013. }
  1014. static ssize_t
  1015. il_dbgfs_clear_ucode_stats_write(struct file *file,
  1016. const char __user *user_buf, size_t count,
  1017. loff_t *ppos)
  1018. {
  1019. struct il_priv *il = file->private_data;
  1020. char buf[8];
  1021. int buf_size;
  1022. int clear;
  1023. memset(buf, 0, sizeof(buf));
  1024. buf_size = min(count, sizeof(buf) - 1);
  1025. if (copy_from_user(buf, user_buf, buf_size))
  1026. return -EFAULT;
  1027. if (sscanf(buf, "%d", &clear) != 1)
  1028. return -EFAULT;
  1029. /* make request to uCode to retrieve stats information */
  1030. mutex_lock(&il->mutex);
  1031. il_send_stats_request(il, CMD_SYNC, true);
  1032. mutex_unlock(&il->mutex);
  1033. return count;
  1034. }
  1035. static ssize_t
  1036. il_dbgfs_rxon_flags_read(struct file *file, char __user *user_buf,
  1037. size_t count, loff_t *ppos)
  1038. {
  1039. struct il_priv *il = file->private_data;
  1040. int len = 0;
  1041. char buf[20];
  1042. len = sprintf(buf, "0x%04X\n", le32_to_cpu(il->ctx.active.flags));
  1043. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1044. }
  1045. static ssize_t
  1046. il_dbgfs_rxon_filter_flags_read(struct file *file, char __user *user_buf,
  1047. size_t count, loff_t *ppos)
  1048. {
  1049. struct il_priv *il = file->private_data;
  1050. int len = 0;
  1051. char buf[20];
  1052. len =
  1053. sprintf(buf, "0x%04X\n", le32_to_cpu(il->ctx.active.filter_flags));
  1054. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1055. }
  1056. static ssize_t
  1057. il_dbgfs_fh_reg_read(struct file *file, char __user *user_buf, size_t count,
  1058. loff_t *ppos)
  1059. {
  1060. struct il_priv *il = file->private_data;
  1061. char *buf;
  1062. int pos = 0;
  1063. ssize_t ret = -EFAULT;
  1064. if (il->cfg->ops->lib->dump_fh) {
  1065. ret = pos = il->cfg->ops->lib->dump_fh(il, &buf, true);
  1066. if (buf) {
  1067. ret =
  1068. simple_read_from_buffer(user_buf, count, ppos, buf,
  1069. pos);
  1070. kfree(buf);
  1071. }
  1072. }
  1073. return ret;
  1074. }
  1075. static ssize_t
  1076. il_dbgfs_missed_beacon_read(struct file *file, char __user *user_buf,
  1077. size_t count, loff_t *ppos)
  1078. {
  1079. struct il_priv *il = file->private_data;
  1080. int pos = 0;
  1081. char buf[12];
  1082. const size_t bufsz = sizeof(buf);
  1083. pos +=
  1084. scnprintf(buf + pos, bufsz - pos, "%d\n",
  1085. il->missed_beacon_threshold);
  1086. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1087. }
  1088. static ssize_t
  1089. il_dbgfs_missed_beacon_write(struct file *file, const char __user *user_buf,
  1090. size_t count, loff_t *ppos)
  1091. {
  1092. struct il_priv *il = file->private_data;
  1093. char buf[8];
  1094. int buf_size;
  1095. int missed;
  1096. memset(buf, 0, sizeof(buf));
  1097. buf_size = min(count, sizeof(buf) - 1);
  1098. if (copy_from_user(buf, user_buf, buf_size))
  1099. return -EFAULT;
  1100. if (sscanf(buf, "%d", &missed) != 1)
  1101. return -EINVAL;
  1102. if (missed < IL_MISSED_BEACON_THRESHOLD_MIN ||
  1103. missed > IL_MISSED_BEACON_THRESHOLD_MAX)
  1104. il->missed_beacon_threshold = IL_MISSED_BEACON_THRESHOLD_DEF;
  1105. else
  1106. il->missed_beacon_threshold = missed;
  1107. return count;
  1108. }
  1109. static ssize_t
  1110. il_dbgfs_force_reset_read(struct file *file, char __user *user_buf,
  1111. size_t count, loff_t *ppos)
  1112. {
  1113. struct il_priv *il = file->private_data;
  1114. int pos = 0;
  1115. char buf[300];
  1116. const size_t bufsz = sizeof(buf);
  1117. struct il_force_reset *force_reset;
  1118. force_reset = &il->force_reset;
  1119. pos +=
  1120. scnprintf(buf + pos, bufsz - pos, "\tnumber of reset request: %d\n",
  1121. force_reset->reset_request_count);
  1122. pos +=
  1123. scnprintf(buf + pos, bufsz - pos,
  1124. "\tnumber of reset request success: %d\n",
  1125. force_reset->reset_success_count);
  1126. pos +=
  1127. scnprintf(buf + pos, bufsz - pos,
  1128. "\tnumber of reset request reject: %d\n",
  1129. force_reset->reset_reject_count);
  1130. pos +=
  1131. scnprintf(buf + pos, bufsz - pos, "\treset duration: %lu\n",
  1132. force_reset->reset_duration);
  1133. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1134. }
  1135. static ssize_t
  1136. il_dbgfs_force_reset_write(struct file *file, const char __user *user_buf,
  1137. size_t count, loff_t *ppos)
  1138. {
  1139. int ret;
  1140. struct il_priv *il = file->private_data;
  1141. ret = il_force_reset(il, true);
  1142. return ret ? ret : count;
  1143. }
  1144. static ssize_t
  1145. il_dbgfs_wd_timeout_write(struct file *file, const char __user *user_buf,
  1146. size_t count, loff_t *ppos)
  1147. {
  1148. struct il_priv *il = file->private_data;
  1149. char buf[8];
  1150. int buf_size;
  1151. int timeout;
  1152. memset(buf, 0, sizeof(buf));
  1153. buf_size = min(count, sizeof(buf) - 1);
  1154. if (copy_from_user(buf, user_buf, buf_size))
  1155. return -EFAULT;
  1156. if (sscanf(buf, "%d", &timeout) != 1)
  1157. return -EINVAL;
  1158. if (timeout < 0 || timeout > IL_MAX_WD_TIMEOUT)
  1159. timeout = IL_DEF_WD_TIMEOUT;
  1160. il->cfg->base_params->wd_timeout = timeout;
  1161. il_setup_watchdog(il);
  1162. return count;
  1163. }
  1164. DEBUGFS_READ_FILE_OPS(rx_stats);
  1165. DEBUGFS_READ_FILE_OPS(tx_stats);
  1166. DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
  1167. DEBUGFS_READ_FILE_OPS(rx_queue);
  1168. DEBUGFS_READ_FILE_OPS(tx_queue);
  1169. DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
  1170. DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
  1171. DEBUGFS_READ_FILE_OPS(ucode_general_stats);
  1172. DEBUGFS_READ_FILE_OPS(sensitivity);
  1173. DEBUGFS_READ_FILE_OPS(chain_noise);
  1174. DEBUGFS_READ_FILE_OPS(power_save_status);
  1175. DEBUGFS_WRITE_FILE_OPS(clear_ucode_stats);
  1176. DEBUGFS_WRITE_FILE_OPS(clear_traffic_stats);
  1177. DEBUGFS_READ_FILE_OPS(fh_reg);
  1178. DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
  1179. DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
  1180. DEBUGFS_READ_FILE_OPS(rxon_flags);
  1181. DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
  1182. DEBUGFS_WRITE_FILE_OPS(wd_timeout);
  1183. /*
  1184. * Create the debugfs files and directories
  1185. *
  1186. */
  1187. int
  1188. il_dbgfs_register(struct il_priv *il, const char *name)
  1189. {
  1190. struct dentry *phyd = il->hw->wiphy->debugfsdir;
  1191. struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
  1192. dir_drv = debugfs_create_dir(name, phyd);
  1193. if (!dir_drv)
  1194. return -ENOMEM;
  1195. il->debugfs_dir = dir_drv;
  1196. dir_data = debugfs_create_dir("data", dir_drv);
  1197. if (!dir_data)
  1198. goto err;
  1199. dir_rf = debugfs_create_dir("rf", dir_drv);
  1200. if (!dir_rf)
  1201. goto err;
  1202. dir_debug = debugfs_create_dir("debug", dir_drv);
  1203. if (!dir_debug)
  1204. goto err;
  1205. DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
  1206. DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
  1207. DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
  1208. DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
  1209. DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
  1210. DEBUGFS_ADD_FILE(interrupt, dir_data, S_IWUSR | S_IRUSR);
  1211. DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
  1212. DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
  1213. DEBUGFS_ADD_FILE(rx_stats, dir_debug, S_IRUSR);
  1214. DEBUGFS_ADD_FILE(tx_stats, dir_debug, S_IRUSR);
  1215. DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
  1216. DEBUGFS_ADD_FILE(rx_queue, dir_debug, S_IRUSR);
  1217. DEBUGFS_ADD_FILE(tx_queue, dir_debug, S_IRUSR);
  1218. DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
  1219. DEBUGFS_ADD_FILE(clear_ucode_stats, dir_debug, S_IWUSR);
  1220. DEBUGFS_ADD_FILE(clear_traffic_stats, dir_debug, S_IWUSR);
  1221. DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR);
  1222. DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
  1223. DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
  1224. DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
  1225. DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
  1226. DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
  1227. if (il->cfg->base_params->sensitivity_calib_by_driver)
  1228. DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
  1229. if (il->cfg->base_params->chain_noise_calib_by_driver)
  1230. DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
  1231. DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
  1232. DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
  1233. DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
  1234. if (il->cfg->base_params->sensitivity_calib_by_driver)
  1235. DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
  1236. &il->disable_sens_cal);
  1237. if (il->cfg->base_params->chain_noise_calib_by_driver)
  1238. DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
  1239. &il->disable_chain_noise_cal);
  1240. DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf, &il->disable_tx_power_cal);
  1241. return 0;
  1242. err:
  1243. IL_ERR("Can't create the debugfs directory\n");
  1244. il_dbgfs_unregister(il);
  1245. return -ENOMEM;
  1246. }
  1247. EXPORT_SYMBOL(il_dbgfs_register);
  1248. /**
  1249. * Remove the debugfs files and directories
  1250. *
  1251. */
  1252. void
  1253. il_dbgfs_unregister(struct il_priv *il)
  1254. {
  1255. if (!il->debugfs_dir)
  1256. return;
  1257. debugfs_remove_recursive(il->debugfs_dir);
  1258. il->debugfs_dir = NULL;
  1259. }
  1260. EXPORT_SYMBOL(il_dbgfs_unregister);