iwl-debugfs.c 38 KB

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