iwl-debugfs.c 40 KB

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