debug.c 39 KB

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