debug.c 38 KB

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