debug.c 39 KB

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