iwl-debugfs.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2010 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/slab.h>
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/debugfs.h>
  32. #include <linux/ieee80211.h>
  33. #include <net/mac80211.h>
  34. #include "iwl-dev.h"
  35. #include "iwl-debug.h"
  36. #include "iwl-core.h"
  37. #include "iwl-io.h"
  38. /* create and remove of files */
  39. #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
  40. if (!debugfs_create_file(#name, mode, parent, priv, \
  41. &iwl_dbgfs_##name##_ops)) \
  42. goto err; \
  43. } while (0)
  44. #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
  45. struct dentry *__tmp; \
  46. __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
  47. parent, ptr); \
  48. if (IS_ERR(__tmp) || !__tmp) \
  49. goto err; \
  50. } while (0)
  51. #define DEBUGFS_ADD_X32(name, parent, ptr) do { \
  52. struct dentry *__tmp; \
  53. __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
  54. parent, ptr); \
  55. if (IS_ERR(__tmp) || !__tmp) \
  56. goto err; \
  57. } while (0)
  58. /* file operation */
  59. #define DEBUGFS_READ_FUNC(name) \
  60. static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
  61. char __user *user_buf, \
  62. size_t count, loff_t *ppos);
  63. #define DEBUGFS_WRITE_FUNC(name) \
  64. static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
  65. const char __user *user_buf, \
  66. size_t count, loff_t *ppos);
  67. static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
  68. {
  69. file->private_data = inode->i_private;
  70. return 0;
  71. }
  72. #define DEBUGFS_READ_FILE_OPS(name) \
  73. DEBUGFS_READ_FUNC(name); \
  74. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  75. .read = iwl_dbgfs_##name##_read, \
  76. .open = iwl_dbgfs_open_file_generic, \
  77. .llseek = generic_file_llseek, \
  78. };
  79. #define DEBUGFS_WRITE_FILE_OPS(name) \
  80. DEBUGFS_WRITE_FUNC(name); \
  81. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  82. .write = iwl_dbgfs_##name##_write, \
  83. .open = iwl_dbgfs_open_file_generic, \
  84. .llseek = generic_file_llseek, \
  85. };
  86. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  87. DEBUGFS_READ_FUNC(name); \
  88. DEBUGFS_WRITE_FUNC(name); \
  89. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  90. .write = iwl_dbgfs_##name##_write, \
  91. .read = iwl_dbgfs_##name##_read, \
  92. .open = iwl_dbgfs_open_file_generic, \
  93. .llseek = generic_file_llseek, \
  94. };
  95. static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
  96. char __user *user_buf,
  97. size_t count, loff_t *ppos) {
  98. struct iwl_priv *priv = file->private_data;
  99. char *buf;
  100. int pos = 0;
  101. int cnt;
  102. ssize_t ret;
  103. const size_t bufsz = 100 +
  104. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  105. buf = kzalloc(bufsz, GFP_KERNEL);
  106. if (!buf)
  107. return -ENOMEM;
  108. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  109. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  110. pos += scnprintf(buf + pos, bufsz - pos,
  111. "\t%25s\t\t: %u\n",
  112. get_mgmt_string(cnt),
  113. priv->tx_stats.mgmt[cnt]);
  114. }
  115. pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
  116. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  117. pos += scnprintf(buf + pos, bufsz - pos,
  118. "\t%25s\t\t: %u\n",
  119. get_ctrl_string(cnt),
  120. priv->tx_stats.ctrl[cnt]);
  121. }
  122. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  123. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  124. priv->tx_stats.data_cnt);
  125. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  126. priv->tx_stats.data_bytes);
  127. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  128. kfree(buf);
  129. return ret;
  130. }
  131. static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
  132. const char __user *user_buf,
  133. size_t count, loff_t *ppos)
  134. {
  135. struct iwl_priv *priv = file->private_data;
  136. u32 clear_flag;
  137. char buf[8];
  138. int buf_size;
  139. memset(buf, 0, sizeof(buf));
  140. buf_size = min(count, sizeof(buf) - 1);
  141. if (copy_from_user(buf, user_buf, buf_size))
  142. return -EFAULT;
  143. if (sscanf(buf, "%x", &clear_flag) != 1)
  144. return -EFAULT;
  145. iwl_clear_traffic_stats(priv);
  146. return count;
  147. }
  148. static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
  149. char __user *user_buf,
  150. size_t count, loff_t *ppos) {
  151. struct iwl_priv *priv = file->private_data;
  152. char *buf;
  153. int pos = 0;
  154. int cnt;
  155. ssize_t ret;
  156. const size_t bufsz = 100 +
  157. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  158. buf = kzalloc(bufsz, GFP_KERNEL);
  159. if (!buf)
  160. return -ENOMEM;
  161. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  162. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  163. pos += scnprintf(buf + pos, bufsz - pos,
  164. "\t%25s\t\t: %u\n",
  165. get_mgmt_string(cnt),
  166. priv->rx_stats.mgmt[cnt]);
  167. }
  168. pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
  169. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  170. pos += scnprintf(buf + pos, bufsz - pos,
  171. "\t%25s\t\t: %u\n",
  172. get_ctrl_string(cnt),
  173. priv->rx_stats.ctrl[cnt]);
  174. }
  175. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  176. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  177. priv->rx_stats.data_cnt);
  178. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  179. priv->rx_stats.data_bytes);
  180. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  181. kfree(buf);
  182. return ret;
  183. }
  184. static ssize_t iwl_dbgfs_sram_read(struct file *file,
  185. char __user *user_buf,
  186. size_t count, loff_t *ppos)
  187. {
  188. u32 val = 0;
  189. char *buf;
  190. ssize_t ret;
  191. int i = 0;
  192. bool device_format = false;
  193. int offset = 0;
  194. int len = 0;
  195. int pos = 0;
  196. int sram;
  197. struct iwl_priv *priv = file->private_data;
  198. size_t bufsz;
  199. /* default is to dump the entire data segment */
  200. if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
  201. priv->dbgfs_sram_offset = 0x800000;
  202. if (priv->ucode_type == UCODE_INIT)
  203. priv->dbgfs_sram_len = priv->ucode_init_data.len;
  204. else
  205. priv->dbgfs_sram_len = priv->ucode_data.len;
  206. }
  207. len = priv->dbgfs_sram_len;
  208. if (len == -4) {
  209. device_format = true;
  210. len = 4;
  211. }
  212. bufsz = 50 + len * 4;
  213. buf = kmalloc(bufsz, GFP_KERNEL);
  214. if (!buf)
  215. return -ENOMEM;
  216. pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
  217. len);
  218. pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
  219. priv->dbgfs_sram_offset);
  220. /* adjust sram address since reads are only on even u32 boundaries */
  221. offset = priv->dbgfs_sram_offset & 0x3;
  222. sram = priv->dbgfs_sram_offset & ~0x3;
  223. /* read the first u32 from sram */
  224. val = iwl_read_targ_mem(priv, sram);
  225. for (; len; len--) {
  226. /* put the address at the start of every line */
  227. if (i == 0)
  228. pos += scnprintf(buf + pos, bufsz - pos,
  229. "%08X: ", sram + offset);
  230. if (device_format)
  231. pos += scnprintf(buf + pos, bufsz - pos,
  232. "%02x", (val >> (8 * (3 - offset))) & 0xff);
  233. else
  234. pos += scnprintf(buf + pos, bufsz - pos,
  235. "%02x ", (val >> (8 * offset)) & 0xff);
  236. /* if all bytes processed, read the next u32 from sram */
  237. if (++offset == 4) {
  238. sram += 4;
  239. offset = 0;
  240. val = iwl_read_targ_mem(priv, sram);
  241. }
  242. /* put in extra spaces and split lines for human readability */
  243. if (++i == 16) {
  244. i = 0;
  245. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  246. } else if (!(i & 7)) {
  247. pos += scnprintf(buf + pos, bufsz - pos, " ");
  248. } else if (!(i & 3)) {
  249. pos += scnprintf(buf + pos, bufsz - pos, " ");
  250. }
  251. }
  252. if (i)
  253. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  254. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  255. kfree(buf);
  256. return ret;
  257. }
  258. static ssize_t iwl_dbgfs_sram_write(struct file *file,
  259. const char __user *user_buf,
  260. size_t count, loff_t *ppos)
  261. {
  262. struct iwl_priv *priv = file->private_data;
  263. char buf[64];
  264. int buf_size;
  265. u32 offset, len;
  266. memset(buf, 0, sizeof(buf));
  267. buf_size = min(count, sizeof(buf) - 1);
  268. if (copy_from_user(buf, user_buf, buf_size))
  269. return -EFAULT;
  270. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  271. priv->dbgfs_sram_offset = offset;
  272. priv->dbgfs_sram_len = len;
  273. } else if (sscanf(buf, "%x", &offset) == 1) {
  274. priv->dbgfs_sram_offset = offset;
  275. priv->dbgfs_sram_len = -4;
  276. } else {
  277. priv->dbgfs_sram_offset = 0;
  278. priv->dbgfs_sram_len = 0;
  279. }
  280. return count;
  281. }
  282. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  283. size_t count, loff_t *ppos)
  284. {
  285. struct iwl_priv *priv = file->private_data;
  286. struct iwl_station_entry *station;
  287. int max_sta = priv->hw_params.max_stations;
  288. char *buf;
  289. int i, j, pos = 0;
  290. ssize_t ret;
  291. /* Add 30 for initial string */
  292. const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
  293. buf = kmalloc(bufsz, GFP_KERNEL);
  294. if (!buf)
  295. return -ENOMEM;
  296. pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
  297. priv->num_stations);
  298. for (i = 0; i < max_sta; i++) {
  299. station = &priv->stations[i];
  300. if (!station->used)
  301. continue;
  302. pos += scnprintf(buf + pos, bufsz - pos,
  303. "station %d - addr: %pM, flags: %#x\n",
  304. i, station->sta.sta.addr,
  305. station->sta.station_flags_msk);
  306. pos += scnprintf(buf + pos, bufsz - pos,
  307. "TID\tseq_num\ttxq_id\tframes\ttfds\t");
  308. pos += scnprintf(buf + pos, bufsz - pos,
  309. "start_idx\tbitmap\t\t\trate_n_flags\n");
  310. for (j = 0; j < MAX_TID_COUNT; j++) {
  311. pos += scnprintf(buf + pos, bufsz - pos,
  312. "%d:\t%#x\t%#x\t%u\t%u\t%u\t\t%#.16llx\t%#x",
  313. j, station->tid[j].seq_number,
  314. station->tid[j].agg.txq_id,
  315. station->tid[j].agg.frame_count,
  316. station->tid[j].tfds_in_queue,
  317. station->tid[j].agg.start_idx,
  318. station->tid[j].agg.bitmap,
  319. station->tid[j].agg.rate_n_flags);
  320. if (station->tid[j].agg.wait_for_ba)
  321. pos += scnprintf(buf + pos, bufsz - pos,
  322. " - waitforba");
  323. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  324. }
  325. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  326. }
  327. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  328. kfree(buf);
  329. return ret;
  330. }
  331. static ssize_t iwl_dbgfs_nvm_read(struct file *file,
  332. char __user *user_buf,
  333. size_t count,
  334. loff_t *ppos)
  335. {
  336. ssize_t ret;
  337. struct iwl_priv *priv = file->private_data;
  338. int pos = 0, ofs = 0, buf_size = 0;
  339. const u8 *ptr;
  340. char *buf;
  341. u16 eeprom_ver;
  342. size_t eeprom_len = priv->cfg->base_params->eeprom_size;
  343. buf_size = 4 * eeprom_len + 256;
  344. if (eeprom_len % 16) {
  345. IWL_ERR(priv, "NVM size is not multiple of 16.\n");
  346. return -ENODATA;
  347. }
  348. ptr = priv->eeprom;
  349. if (!ptr) {
  350. IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
  351. return -ENOMEM;
  352. }
  353. /* 4 characters for byte 0xYY */
  354. buf = kzalloc(buf_size, GFP_KERNEL);
  355. if (!buf) {
  356. IWL_ERR(priv, "Can not allocate Buffer\n");
  357. return -ENOMEM;
  358. }
  359. eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
  360. pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
  361. "version: 0x%x\n",
  362. (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
  363. ? "OTP" : "EEPROM", eeprom_ver);
  364. for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
  365. pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
  366. hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
  367. buf_size - pos, 0);
  368. pos += strlen(buf + pos);
  369. if (buf_size - pos > 0)
  370. buf[pos++] = '\n';
  371. }
  372. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  373. kfree(buf);
  374. return ret;
  375. }
  376. static ssize_t iwl_dbgfs_log_event_read(struct file *file,
  377. char __user *user_buf,
  378. size_t count, loff_t *ppos)
  379. {
  380. struct iwl_priv *priv = file->private_data;
  381. char *buf;
  382. int pos = 0;
  383. ssize_t ret = -ENOMEM;
  384. ret = pos = priv->cfg->ops->lib->dump_nic_event_log(
  385. priv, true, &buf, true);
  386. if (buf) {
  387. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  388. kfree(buf);
  389. }
  390. return ret;
  391. }
  392. static ssize_t iwl_dbgfs_log_event_write(struct file *file,
  393. const char __user *user_buf,
  394. size_t count, loff_t *ppos)
  395. {
  396. struct iwl_priv *priv = file->private_data;
  397. u32 event_log_flag;
  398. char buf[8];
  399. int buf_size;
  400. memset(buf, 0, sizeof(buf));
  401. buf_size = min(count, sizeof(buf) - 1);
  402. if (copy_from_user(buf, user_buf, buf_size))
  403. return -EFAULT;
  404. if (sscanf(buf, "%d", &event_log_flag) != 1)
  405. return -EFAULT;
  406. if (event_log_flag == 1)
  407. priv->cfg->ops->lib->dump_nic_event_log(priv, true,
  408. NULL, false);
  409. return count;
  410. }
  411. static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
  412. size_t count, loff_t *ppos)
  413. {
  414. struct iwl_priv *priv = file->private_data;
  415. struct ieee80211_channel *channels = NULL;
  416. const struct ieee80211_supported_band *supp_band = NULL;
  417. int pos = 0, i, bufsz = PAGE_SIZE;
  418. char *buf;
  419. ssize_t ret;
  420. if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
  421. return -EAGAIN;
  422. buf = kzalloc(bufsz, GFP_KERNEL);
  423. if (!buf) {
  424. IWL_ERR(priv, "Can not allocate Buffer\n");
  425. return -ENOMEM;
  426. }
  427. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
  428. if (supp_band) {
  429. channels = supp_band->channels;
  430. pos += scnprintf(buf + pos, bufsz - pos,
  431. "Displaying %d channels in 2.4GHz band 802.11bg):\n",
  432. supp_band->n_channels);
  433. for (i = 0; i < supp_band->n_channels; i++)
  434. pos += scnprintf(buf + pos, bufsz - pos,
  435. "%d: %ddBm: BSS%s%s, %s.\n",
  436. channels[i].hw_value,
  437. channels[i].max_power,
  438. channels[i].flags & IEEE80211_CHAN_RADAR ?
  439. " (IEEE 802.11h required)" : "",
  440. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  441. || (channels[i].flags &
  442. IEEE80211_CHAN_RADAR)) ? "" :
  443. ", IBSS",
  444. channels[i].flags &
  445. IEEE80211_CHAN_PASSIVE_SCAN ?
  446. "passive only" : "active/passive");
  447. }
  448. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
  449. if (supp_band) {
  450. channels = supp_band->channels;
  451. pos += scnprintf(buf + pos, bufsz - pos,
  452. "Displaying %d channels in 5.2GHz band (802.11a)\n",
  453. supp_band->n_channels);
  454. for (i = 0; i < supp_band->n_channels; i++)
  455. pos += scnprintf(buf + pos, bufsz - pos,
  456. "%d: %ddBm: BSS%s%s, %s.\n",
  457. channels[i].hw_value,
  458. channels[i].max_power,
  459. channels[i].flags & IEEE80211_CHAN_RADAR ?
  460. " (IEEE 802.11h required)" : "",
  461. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  462. || (channels[i].flags &
  463. IEEE80211_CHAN_RADAR)) ? "" :
  464. ", IBSS",
  465. channels[i].flags &
  466. IEEE80211_CHAN_PASSIVE_SCAN ?
  467. "passive only" : "active/passive");
  468. }
  469. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  470. kfree(buf);
  471. return ret;
  472. }
  473. static ssize_t iwl_dbgfs_status_read(struct file *file,
  474. char __user *user_buf,
  475. size_t count, loff_t *ppos) {
  476. struct iwl_priv *priv = file->private_data;
  477. char buf[512];
  478. int pos = 0;
  479. const size_t bufsz = sizeof(buf);
  480. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
  481. test_bit(STATUS_HCMD_ACTIVE, &priv->status));
  482. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
  483. test_bit(STATUS_INT_ENABLED, &priv->status));
  484. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
  485. test_bit(STATUS_RF_KILL_HW, &priv->status));
  486. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
  487. test_bit(STATUS_CT_KILL, &priv->status));
  488. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
  489. test_bit(STATUS_INIT, &priv->status));
  490. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
  491. test_bit(STATUS_ALIVE, &priv->status));
  492. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
  493. test_bit(STATUS_READY, &priv->status));
  494. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
  495. test_bit(STATUS_TEMPERATURE, &priv->status));
  496. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
  497. test_bit(STATUS_GEO_CONFIGURED, &priv->status));
  498. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
  499. test_bit(STATUS_EXIT_PENDING, &priv->status));
  500. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
  501. test_bit(STATUS_STATISTICS, &priv->status));
  502. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
  503. test_bit(STATUS_SCANNING, &priv->status));
  504. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
  505. test_bit(STATUS_SCAN_ABORTING, &priv->status));
  506. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
  507. test_bit(STATUS_SCAN_HW, &priv->status));
  508. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
  509. test_bit(STATUS_POWER_PMI, &priv->status));
  510. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
  511. test_bit(STATUS_FW_ERROR, &priv->status));
  512. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  513. }
  514. static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
  515. char __user *user_buf,
  516. size_t count, loff_t *ppos) {
  517. struct iwl_priv *priv = file->private_data;
  518. int pos = 0;
  519. int cnt = 0;
  520. char *buf;
  521. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  522. ssize_t ret;
  523. buf = kzalloc(bufsz, GFP_KERNEL);
  524. if (!buf) {
  525. IWL_ERR(priv, "Can not allocate Buffer\n");
  526. return -ENOMEM;
  527. }
  528. pos += scnprintf(buf + pos, bufsz - pos,
  529. "Interrupt Statistics Report:\n");
  530. pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
  531. priv->isr_stats.hw);
  532. pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
  533. priv->isr_stats.sw);
  534. if (priv->isr_stats.sw || priv->isr_stats.hw) {
  535. pos += scnprintf(buf + pos, bufsz - pos,
  536. "\tLast Restarting Code: 0x%X\n",
  537. priv->isr_stats.err_code);
  538. }
  539. #ifdef CONFIG_IWLWIFI_DEBUG
  540. pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
  541. priv->isr_stats.sch);
  542. pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
  543. priv->isr_stats.alive);
  544. #endif
  545. pos += scnprintf(buf + pos, bufsz - pos,
  546. "HW RF KILL switch toggled:\t %u\n",
  547. priv->isr_stats.rfkill);
  548. pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
  549. priv->isr_stats.ctkill);
  550. pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
  551. priv->isr_stats.wakeup);
  552. pos += scnprintf(buf + pos, bufsz - pos,
  553. "Rx command responses:\t\t %u\n",
  554. priv->isr_stats.rx);
  555. for (cnt = 0; cnt < REPLY_MAX; cnt++) {
  556. if (priv->isr_stats.rx_handlers[cnt] > 0)
  557. pos += scnprintf(buf + pos, bufsz - pos,
  558. "\tRx handler[%36s]:\t\t %u\n",
  559. get_cmd_string(cnt),
  560. priv->isr_stats.rx_handlers[cnt]);
  561. }
  562. pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
  563. priv->isr_stats.tx);
  564. pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
  565. priv->isr_stats.unhandled);
  566. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  567. kfree(buf);
  568. return ret;
  569. }
  570. static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
  571. const char __user *user_buf,
  572. size_t count, loff_t *ppos)
  573. {
  574. struct iwl_priv *priv = file->private_data;
  575. char buf[8];
  576. int buf_size;
  577. u32 reset_flag;
  578. memset(buf, 0, sizeof(buf));
  579. buf_size = min(count, sizeof(buf) - 1);
  580. if (copy_from_user(buf, user_buf, buf_size))
  581. return -EFAULT;
  582. if (sscanf(buf, "%x", &reset_flag) != 1)
  583. return -EFAULT;
  584. if (reset_flag == 0)
  585. iwl_clear_isr_stats(priv);
  586. return count;
  587. }
  588. static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
  589. size_t count, loff_t *ppos)
  590. {
  591. struct iwl_priv *priv = file->private_data;
  592. struct iwl_rxon_context *ctx;
  593. int pos = 0, i;
  594. char buf[256 * NUM_IWL_RXON_CTX];
  595. const size_t bufsz = sizeof(buf);
  596. for_each_context(priv, ctx) {
  597. pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
  598. ctx->ctxid);
  599. for (i = 0; i < AC_NUM; i++) {
  600. pos += scnprintf(buf + pos, bufsz - pos,
  601. "\tcw_min\tcw_max\taifsn\ttxop\n");
  602. pos += scnprintf(buf + pos, bufsz - pos,
  603. "AC[%d]\t%u\t%u\t%u\t%u\n", i,
  604. ctx->qos_data.def_qos_parm.ac[i].cw_min,
  605. ctx->qos_data.def_qos_parm.ac[i].cw_max,
  606. ctx->qos_data.def_qos_parm.ac[i].aifsn,
  607. ctx->qos_data.def_qos_parm.ac[i].edca_txop);
  608. }
  609. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  610. }
  611. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  612. }
  613. static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
  614. char __user *user_buf,
  615. size_t count, loff_t *ppos)
  616. {
  617. struct iwl_priv *priv = file->private_data;
  618. struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
  619. struct iwl_tt_restriction *restriction;
  620. char buf[100];
  621. int pos = 0;
  622. const size_t bufsz = sizeof(buf);
  623. pos += scnprintf(buf + pos, bufsz - pos,
  624. "Thermal Throttling Mode: %s\n",
  625. tt->advanced_tt ? "Advance" : "Legacy");
  626. pos += scnprintf(buf + pos, bufsz - pos,
  627. "Thermal Throttling State: %d\n",
  628. tt->state);
  629. if (tt->advanced_tt) {
  630. restriction = tt->restriction + tt->state;
  631. pos += scnprintf(buf + pos, bufsz - pos,
  632. "Tx mode: %d\n",
  633. restriction->tx_stream);
  634. pos += scnprintf(buf + pos, bufsz - pos,
  635. "Rx mode: %d\n",
  636. restriction->rx_stream);
  637. pos += scnprintf(buf + pos, bufsz - pos,
  638. "HT mode: %d\n",
  639. restriction->is_ht);
  640. }
  641. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  642. }
  643. static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
  644. const char __user *user_buf,
  645. size_t count, loff_t *ppos)
  646. {
  647. struct iwl_priv *priv = file->private_data;
  648. char buf[8];
  649. int buf_size;
  650. int ht40;
  651. memset(buf, 0, sizeof(buf));
  652. buf_size = min(count, sizeof(buf) - 1);
  653. if (copy_from_user(buf, user_buf, buf_size))
  654. return -EFAULT;
  655. if (sscanf(buf, "%d", &ht40) != 1)
  656. return -EFAULT;
  657. if (!iwl_is_any_associated(priv))
  658. priv->disable_ht40 = ht40 ? true : false;
  659. else {
  660. IWL_ERR(priv, "Sta associated with AP - "
  661. "Change to 40MHz channel support is not allowed\n");
  662. return -EINVAL;
  663. }
  664. return count;
  665. }
  666. static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
  667. char __user *user_buf,
  668. size_t count, loff_t *ppos)
  669. {
  670. struct iwl_priv *priv = file->private_data;
  671. char buf[100];
  672. int pos = 0;
  673. const size_t bufsz = sizeof(buf);
  674. pos += scnprintf(buf + pos, bufsz - pos,
  675. "11n 40MHz Mode: %s\n",
  676. priv->disable_ht40 ? "Disabled" : "Enabled");
  677. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  678. }
  679. static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
  680. const char __user *user_buf,
  681. size_t count, loff_t *ppos)
  682. {
  683. struct iwl_priv *priv = file->private_data;
  684. char buf[8];
  685. int buf_size;
  686. int value;
  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, "%d", &value) != 1)
  692. return -EINVAL;
  693. /*
  694. * Our users expect 0 to be "CAM", but 0 isn't actually
  695. * valid here. However, let's not confuse them and present
  696. * IWL_POWER_INDEX_1 as "1", not "0".
  697. */
  698. if (value == 0)
  699. return -EINVAL;
  700. else if (value > 0)
  701. value -= 1;
  702. if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
  703. return -EINVAL;
  704. if (!iwl_is_ready_rf(priv))
  705. return -EAGAIN;
  706. priv->power_data.debug_sleep_level_override = value;
  707. mutex_lock(&priv->mutex);
  708. iwl_power_update_mode(priv, true);
  709. mutex_unlock(&priv->mutex);
  710. return count;
  711. }
  712. static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
  713. char __user *user_buf,
  714. size_t count, loff_t *ppos)
  715. {
  716. struct iwl_priv *priv = file->private_data;
  717. char buf[10];
  718. int pos, value;
  719. const size_t bufsz = sizeof(buf);
  720. /* see the write function */
  721. value = priv->power_data.debug_sleep_level_override;
  722. if (value >= 0)
  723. value += 1;
  724. pos = scnprintf(buf, bufsz, "%d\n", value);
  725. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  726. }
  727. static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
  728. char __user *user_buf,
  729. size_t count, loff_t *ppos)
  730. {
  731. struct iwl_priv *priv = file->private_data;
  732. char buf[200];
  733. int pos = 0, i;
  734. const size_t bufsz = sizeof(buf);
  735. struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
  736. pos += scnprintf(buf + pos, bufsz - pos,
  737. "flags: %#.2x\n", le16_to_cpu(cmd->flags));
  738. pos += scnprintf(buf + pos, bufsz - pos,
  739. "RX/TX timeout: %d/%d usec\n",
  740. le32_to_cpu(cmd->rx_data_timeout),
  741. le32_to_cpu(cmd->tx_data_timeout));
  742. for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
  743. pos += scnprintf(buf + pos, bufsz - pos,
  744. "sleep_interval[%d]: %d\n", i,
  745. le32_to_cpu(cmd->sleep_interval[i]));
  746. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  747. }
  748. DEBUGFS_READ_WRITE_FILE_OPS(sram);
  749. DEBUGFS_READ_WRITE_FILE_OPS(log_event);
  750. DEBUGFS_READ_FILE_OPS(nvm);
  751. DEBUGFS_READ_FILE_OPS(stations);
  752. DEBUGFS_READ_FILE_OPS(channels);
  753. DEBUGFS_READ_FILE_OPS(status);
  754. DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
  755. DEBUGFS_READ_FILE_OPS(qos);
  756. DEBUGFS_READ_FILE_OPS(thermal_throttling);
  757. DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
  758. DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
  759. DEBUGFS_READ_FILE_OPS(current_sleep_command);
  760. static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
  761. char __user *user_buf,
  762. size_t count, loff_t *ppos)
  763. {
  764. struct iwl_priv *priv = file->private_data;
  765. int pos = 0, ofs = 0;
  766. int cnt = 0, entry;
  767. struct iwl_tx_queue *txq;
  768. struct iwl_queue *q;
  769. struct iwl_rx_queue *rxq = &priv->rxq;
  770. char *buf;
  771. int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
  772. (priv->cfg->base_params->num_of_queues * 32 * 8) + 400;
  773. const u8 *ptr;
  774. ssize_t ret;
  775. if (!priv->txq) {
  776. IWL_ERR(priv, "txq not ready\n");
  777. return -EAGAIN;
  778. }
  779. buf = kzalloc(bufsz, GFP_KERNEL);
  780. if (!buf) {
  781. IWL_ERR(priv, "Can not allocate buffer\n");
  782. return -ENOMEM;
  783. }
  784. pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
  785. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  786. txq = &priv->txq[cnt];
  787. q = &txq->q;
  788. pos += scnprintf(buf + pos, bufsz - pos,
  789. "q[%d]: read_ptr: %u, write_ptr: %u\n",
  790. cnt, q->read_ptr, q->write_ptr);
  791. }
  792. if (priv->tx_traffic && (iwl_debug_level & IWL_DL_TX)) {
  793. ptr = priv->tx_traffic;
  794. pos += scnprintf(buf + pos, bufsz - pos,
  795. "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
  796. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  797. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  798. entry++, ofs += 16) {
  799. pos += scnprintf(buf + pos, bufsz - pos,
  800. "0x%.4x ", ofs);
  801. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  802. buf + pos, bufsz - pos, 0);
  803. pos += strlen(buf + pos);
  804. if (bufsz - pos > 0)
  805. buf[pos++] = '\n';
  806. }
  807. }
  808. }
  809. pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
  810. pos += scnprintf(buf + pos, bufsz - pos,
  811. "read: %u, write: %u\n",
  812. rxq->read, rxq->write);
  813. if (priv->rx_traffic && (iwl_debug_level & IWL_DL_RX)) {
  814. ptr = priv->rx_traffic;
  815. pos += scnprintf(buf + pos, bufsz - pos,
  816. "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
  817. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  818. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  819. entry++, ofs += 16) {
  820. pos += scnprintf(buf + pos, bufsz - pos,
  821. "0x%.4x ", ofs);
  822. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  823. buf + pos, bufsz - pos, 0);
  824. pos += strlen(buf + pos);
  825. if (bufsz - pos > 0)
  826. buf[pos++] = '\n';
  827. }
  828. }
  829. }
  830. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  831. kfree(buf);
  832. return ret;
  833. }
  834. static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
  835. const char __user *user_buf,
  836. size_t count, loff_t *ppos)
  837. {
  838. struct iwl_priv *priv = file->private_data;
  839. char buf[8];
  840. int buf_size;
  841. int traffic_log;
  842. memset(buf, 0, sizeof(buf));
  843. buf_size = min(count, sizeof(buf) - 1);
  844. if (copy_from_user(buf, user_buf, buf_size))
  845. return -EFAULT;
  846. if (sscanf(buf, "%d", &traffic_log) != 1)
  847. return -EFAULT;
  848. if (traffic_log == 0)
  849. iwl_reset_traffic_log(priv);
  850. return count;
  851. }
  852. static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
  853. char __user *user_buf,
  854. size_t count, loff_t *ppos) {
  855. struct iwl_priv *priv = file->private_data;
  856. struct iwl_tx_queue *txq;
  857. struct iwl_queue *q;
  858. char *buf;
  859. int pos = 0;
  860. int cnt;
  861. int ret;
  862. const size_t bufsz = sizeof(char) * 64 *
  863. priv->cfg->base_params->num_of_queues;
  864. if (!priv->txq) {
  865. IWL_ERR(priv, "txq not ready\n");
  866. return -EAGAIN;
  867. }
  868. buf = kzalloc(bufsz, GFP_KERNEL);
  869. if (!buf)
  870. return -ENOMEM;
  871. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  872. txq = &priv->txq[cnt];
  873. q = &txq->q;
  874. pos += scnprintf(buf + pos, bufsz - pos,
  875. "hwq %.2d: read=%u write=%u stop=%d"
  876. " swq_id=%#.2x (ac %d/hwq %d)\n",
  877. cnt, q->read_ptr, q->write_ptr,
  878. !!test_bit(cnt, priv->queue_stopped),
  879. txq->swq_id, txq->swq_id & 3,
  880. (txq->swq_id >> 2) & 0x1f);
  881. if (cnt >= 4)
  882. continue;
  883. /* for the ACs, display the stop count too */
  884. pos += scnprintf(buf + pos, bufsz - pos,
  885. " stop-count: %d\n",
  886. atomic_read(&priv->queue_stop_count[cnt]));
  887. }
  888. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  889. kfree(buf);
  890. return ret;
  891. }
  892. static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
  893. char __user *user_buf,
  894. size_t count, loff_t *ppos) {
  895. struct iwl_priv *priv = file->private_data;
  896. struct iwl_rx_queue *rxq = &priv->rxq;
  897. char buf[256];
  898. int pos = 0;
  899. const size_t bufsz = sizeof(buf);
  900. pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
  901. rxq->read);
  902. pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
  903. rxq->write);
  904. pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
  905. rxq->free_count);
  906. if (rxq->rb_stts) {
  907. pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
  908. le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
  909. } else {
  910. pos += scnprintf(buf + pos, bufsz - pos,
  911. "closed_rb_num: Not Allocated\n");
  912. }
  913. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  914. }
  915. static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
  916. char __user *user_buf,
  917. size_t count, loff_t *ppos)
  918. {
  919. struct iwl_priv *priv = file->private_data;
  920. return priv->cfg->ops->lib->debugfs_ops.rx_stats_read(file,
  921. user_buf, count, ppos);
  922. }
  923. static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
  924. char __user *user_buf,
  925. size_t count, loff_t *ppos)
  926. {
  927. struct iwl_priv *priv = file->private_data;
  928. return priv->cfg->ops->lib->debugfs_ops.tx_stats_read(file,
  929. user_buf, count, ppos);
  930. }
  931. static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
  932. char __user *user_buf,
  933. size_t count, loff_t *ppos)
  934. {
  935. struct iwl_priv *priv = file->private_data;
  936. return priv->cfg->ops->lib->debugfs_ops.general_stats_read(file,
  937. user_buf, count, ppos);
  938. }
  939. static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
  940. char __user *user_buf,
  941. size_t count, loff_t *ppos) {
  942. struct iwl_priv *priv = file->private_data;
  943. int pos = 0;
  944. int cnt = 0;
  945. char *buf;
  946. int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
  947. ssize_t ret;
  948. struct iwl_sensitivity_data *data;
  949. data = &priv->sensitivity_data;
  950. buf = kzalloc(bufsz, GFP_KERNEL);
  951. if (!buf) {
  952. IWL_ERR(priv, "Can not allocate Buffer\n");
  953. return -ENOMEM;
  954. }
  955. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
  956. data->auto_corr_ofdm);
  957. pos += scnprintf(buf + pos, bufsz - pos,
  958. "auto_corr_ofdm_mrc:\t\t %u\n",
  959. data->auto_corr_ofdm_mrc);
  960. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
  961. data->auto_corr_ofdm_x1);
  962. pos += scnprintf(buf + pos, bufsz - pos,
  963. "auto_corr_ofdm_mrc_x1:\t\t %u\n",
  964. data->auto_corr_ofdm_mrc_x1);
  965. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
  966. data->auto_corr_cck);
  967. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
  968. data->auto_corr_cck_mrc);
  969. pos += scnprintf(buf + pos, bufsz - pos,
  970. "last_bad_plcp_cnt_ofdm:\t\t %u\n",
  971. data->last_bad_plcp_cnt_ofdm);
  972. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
  973. data->last_fa_cnt_ofdm);
  974. pos += scnprintf(buf + pos, bufsz - pos,
  975. "last_bad_plcp_cnt_cck:\t\t %u\n",
  976. data->last_bad_plcp_cnt_cck);
  977. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
  978. data->last_fa_cnt_cck);
  979. pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
  980. data->nrg_curr_state);
  981. pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
  982. data->nrg_prev_state);
  983. pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
  984. for (cnt = 0; cnt < 10; cnt++) {
  985. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  986. data->nrg_value[cnt]);
  987. }
  988. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  989. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
  990. for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
  991. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  992. data->nrg_silence_rssi[cnt]);
  993. }
  994. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  995. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
  996. data->nrg_silence_ref);
  997. pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
  998. data->nrg_energy_idx);
  999. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
  1000. data->nrg_silence_idx);
  1001. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
  1002. data->nrg_th_cck);
  1003. pos += scnprintf(buf + pos, bufsz - pos,
  1004. "nrg_auto_corr_silence_diff:\t %u\n",
  1005. data->nrg_auto_corr_silence_diff);
  1006. pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
  1007. data->num_in_cck_no_fa);
  1008. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
  1009. data->nrg_th_ofdm);
  1010. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1011. kfree(buf);
  1012. return ret;
  1013. }
  1014. static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
  1015. char __user *user_buf,
  1016. size_t count, loff_t *ppos) {
  1017. struct iwl_priv *priv = file->private_data;
  1018. int pos = 0;
  1019. int cnt = 0;
  1020. char *buf;
  1021. int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
  1022. ssize_t ret;
  1023. struct iwl_chain_noise_data *data;
  1024. data = &priv->chain_noise_data;
  1025. buf = kzalloc(bufsz, GFP_KERNEL);
  1026. if (!buf) {
  1027. IWL_ERR(priv, "Can not allocate Buffer\n");
  1028. return -ENOMEM;
  1029. }
  1030. pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
  1031. data->active_chains);
  1032. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
  1033. data->chain_noise_a);
  1034. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
  1035. data->chain_noise_b);
  1036. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
  1037. data->chain_noise_c);
  1038. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
  1039. data->chain_signal_a);
  1040. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
  1041. data->chain_signal_b);
  1042. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
  1043. data->chain_signal_c);
  1044. pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
  1045. data->beacon_count);
  1046. pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
  1047. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1048. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1049. data->disconn_array[cnt]);
  1050. }
  1051. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1052. pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
  1053. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1054. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1055. data->delta_gain_code[cnt]);
  1056. }
  1057. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1058. pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
  1059. data->radio_write);
  1060. pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
  1061. data->state);
  1062. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1063. kfree(buf);
  1064. return ret;
  1065. }
  1066. static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
  1067. char __user *user_buf,
  1068. size_t count, loff_t *ppos)
  1069. {
  1070. struct iwl_priv *priv = file->private_data;
  1071. char buf[60];
  1072. int pos = 0;
  1073. const size_t bufsz = sizeof(buf);
  1074. u32 pwrsave_status;
  1075. pwrsave_status = iwl_read32(priv, CSR_GP_CNTRL) &
  1076. CSR_GP_REG_POWER_SAVE_STATUS_MSK;
  1077. pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
  1078. pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
  1079. (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
  1080. (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
  1081. (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
  1082. "error");
  1083. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1084. }
  1085. static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
  1086. const char __user *user_buf,
  1087. size_t count, loff_t *ppos)
  1088. {
  1089. struct iwl_priv *priv = file->private_data;
  1090. char buf[8];
  1091. int buf_size;
  1092. int clear;
  1093. memset(buf, 0, sizeof(buf));
  1094. buf_size = min(count, sizeof(buf) - 1);
  1095. if (copy_from_user(buf, user_buf, buf_size))
  1096. return -EFAULT;
  1097. if (sscanf(buf, "%d", &clear) != 1)
  1098. return -EFAULT;
  1099. /* make request to uCode to retrieve statistics information */
  1100. mutex_lock(&priv->mutex);
  1101. iwl_send_statistics_request(priv, CMD_SYNC, true);
  1102. mutex_unlock(&priv->mutex);
  1103. return count;
  1104. }
  1105. static ssize_t iwl_dbgfs_csr_write(struct file *file,
  1106. const char __user *user_buf,
  1107. size_t count, loff_t *ppos)
  1108. {
  1109. struct iwl_priv *priv = file->private_data;
  1110. char buf[8];
  1111. int buf_size;
  1112. int csr;
  1113. memset(buf, 0, sizeof(buf));
  1114. buf_size = min(count, sizeof(buf) - 1);
  1115. if (copy_from_user(buf, user_buf, buf_size))
  1116. return -EFAULT;
  1117. if (sscanf(buf, "%d", &csr) != 1)
  1118. return -EFAULT;
  1119. if (priv->cfg->ops->lib->dump_csr)
  1120. priv->cfg->ops->lib->dump_csr(priv);
  1121. return count;
  1122. }
  1123. static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
  1124. char __user *user_buf,
  1125. size_t count, loff_t *ppos) {
  1126. struct iwl_priv *priv = file->private_data;
  1127. int pos = 0;
  1128. char buf[128];
  1129. const size_t bufsz = sizeof(buf);
  1130. pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
  1131. priv->event_log.ucode_trace ? "On" : "Off");
  1132. pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
  1133. priv->event_log.non_wraps_count);
  1134. pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
  1135. priv->event_log.wraps_once_count);
  1136. pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
  1137. priv->event_log.wraps_more_count);
  1138. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1139. }
  1140. static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
  1141. const char __user *user_buf,
  1142. size_t count, loff_t *ppos)
  1143. {
  1144. struct iwl_priv *priv = file->private_data;
  1145. char buf[8];
  1146. int buf_size;
  1147. int trace;
  1148. memset(buf, 0, sizeof(buf));
  1149. buf_size = min(count, sizeof(buf) - 1);
  1150. if (copy_from_user(buf, user_buf, buf_size))
  1151. return -EFAULT;
  1152. if (sscanf(buf, "%d", &trace) != 1)
  1153. return -EFAULT;
  1154. if (trace) {
  1155. priv->event_log.ucode_trace = true;
  1156. /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
  1157. mod_timer(&priv->ucode_trace,
  1158. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  1159. } else {
  1160. priv->event_log.ucode_trace = false;
  1161. del_timer_sync(&priv->ucode_trace);
  1162. }
  1163. return count;
  1164. }
  1165. static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
  1166. char __user *user_buf,
  1167. size_t count, loff_t *ppos) {
  1168. struct iwl_priv *priv = file->private_data;
  1169. int len = 0;
  1170. char buf[20];
  1171. len = sprintf(buf, "0x%04X\n",
  1172. le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
  1173. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1174. }
  1175. static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
  1176. char __user *user_buf,
  1177. size_t count, loff_t *ppos) {
  1178. struct iwl_priv *priv = file->private_data;
  1179. int len = 0;
  1180. char buf[20];
  1181. len = sprintf(buf, "0x%04X\n",
  1182. le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
  1183. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1184. }
  1185. static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
  1186. char __user *user_buf,
  1187. size_t count, loff_t *ppos)
  1188. {
  1189. struct iwl_priv *priv = file->private_data;
  1190. char *buf;
  1191. int pos = 0;
  1192. ssize_t ret = -EFAULT;
  1193. if (priv->cfg->ops->lib->dump_fh) {
  1194. ret = pos = priv->cfg->ops->lib->dump_fh(priv, &buf, true);
  1195. if (buf) {
  1196. ret = simple_read_from_buffer(user_buf,
  1197. count, ppos, buf, pos);
  1198. kfree(buf);
  1199. }
  1200. }
  1201. return ret;
  1202. }
  1203. static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
  1204. char __user *user_buf,
  1205. size_t count, loff_t *ppos) {
  1206. struct iwl_priv *priv = file->private_data;
  1207. int pos = 0;
  1208. char buf[12];
  1209. const size_t bufsz = sizeof(buf);
  1210. pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
  1211. priv->missed_beacon_threshold);
  1212. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1213. }
  1214. static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
  1215. const char __user *user_buf,
  1216. size_t count, loff_t *ppos)
  1217. {
  1218. struct iwl_priv *priv = file->private_data;
  1219. char buf[8];
  1220. int buf_size;
  1221. int missed;
  1222. memset(buf, 0, sizeof(buf));
  1223. buf_size = min(count, sizeof(buf) - 1);
  1224. if (copy_from_user(buf, user_buf, buf_size))
  1225. return -EFAULT;
  1226. if (sscanf(buf, "%d", &missed) != 1)
  1227. return -EINVAL;
  1228. if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
  1229. missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
  1230. priv->missed_beacon_threshold =
  1231. IWL_MISSED_BEACON_THRESHOLD_DEF;
  1232. else
  1233. priv->missed_beacon_threshold = missed;
  1234. return count;
  1235. }
  1236. static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
  1237. char __user *user_buf,
  1238. size_t count, loff_t *ppos) {
  1239. struct iwl_priv *priv = file->private_data;
  1240. int pos = 0;
  1241. char buf[12];
  1242. const size_t bufsz = sizeof(buf);
  1243. pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
  1244. priv->cfg->base_params->plcp_delta_threshold);
  1245. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1246. }
  1247. static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
  1248. const char __user *user_buf,
  1249. size_t count, loff_t *ppos) {
  1250. struct iwl_priv *priv = file->private_data;
  1251. char buf[8];
  1252. int buf_size;
  1253. int plcp;
  1254. memset(buf, 0, sizeof(buf));
  1255. buf_size = min(count, sizeof(buf) - 1);
  1256. if (copy_from_user(buf, user_buf, buf_size))
  1257. return -EFAULT;
  1258. if (sscanf(buf, "%d", &plcp) != 1)
  1259. return -EINVAL;
  1260. if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
  1261. (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
  1262. priv->cfg->base_params->plcp_delta_threshold =
  1263. IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
  1264. else
  1265. priv->cfg->base_params->plcp_delta_threshold = plcp;
  1266. return count;
  1267. }
  1268. static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
  1269. char __user *user_buf,
  1270. size_t count, loff_t *ppos) {
  1271. struct iwl_priv *priv = file->private_data;
  1272. int i, pos = 0;
  1273. char buf[300];
  1274. const size_t bufsz = sizeof(buf);
  1275. struct iwl_force_reset *force_reset;
  1276. for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
  1277. force_reset = &priv->force_reset[i];
  1278. pos += scnprintf(buf + pos, bufsz - pos,
  1279. "Force reset method %d\n", i);
  1280. pos += scnprintf(buf + pos, bufsz - pos,
  1281. "\tnumber of reset request: %d\n",
  1282. force_reset->reset_request_count);
  1283. pos += scnprintf(buf + pos, bufsz - pos,
  1284. "\tnumber of reset request success: %d\n",
  1285. force_reset->reset_success_count);
  1286. pos += scnprintf(buf + pos, bufsz - pos,
  1287. "\tnumber of reset request reject: %d\n",
  1288. force_reset->reset_reject_count);
  1289. pos += scnprintf(buf + pos, bufsz - pos,
  1290. "\treset duration: %lu\n",
  1291. force_reset->reset_duration);
  1292. }
  1293. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1294. }
  1295. static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
  1296. const char __user *user_buf,
  1297. size_t count, loff_t *ppos) {
  1298. struct iwl_priv *priv = file->private_data;
  1299. char buf[8];
  1300. int buf_size;
  1301. int reset, ret;
  1302. memset(buf, 0, sizeof(buf));
  1303. buf_size = min(count, sizeof(buf) - 1);
  1304. if (copy_from_user(buf, user_buf, buf_size))
  1305. return -EFAULT;
  1306. if (sscanf(buf, "%d", &reset) != 1)
  1307. return -EINVAL;
  1308. switch (reset) {
  1309. case IWL_RF_RESET:
  1310. case IWL_FW_RESET:
  1311. ret = iwl_force_reset(priv, reset, true);
  1312. break;
  1313. default:
  1314. return -EINVAL;
  1315. }
  1316. return ret ? ret : count;
  1317. }
  1318. static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
  1319. const char __user *user_buf,
  1320. size_t count, loff_t *ppos) {
  1321. struct iwl_priv *priv = file->private_data;
  1322. char buf[8];
  1323. int buf_size;
  1324. int flush;
  1325. memset(buf, 0, sizeof(buf));
  1326. buf_size = min(count, sizeof(buf) - 1);
  1327. if (copy_from_user(buf, user_buf, buf_size))
  1328. return -EFAULT;
  1329. if (sscanf(buf, "%d", &flush) != 1)
  1330. return -EINVAL;
  1331. if (iwl_is_rfkill(priv))
  1332. return -EFAULT;
  1333. priv->cfg->ops->lib->dev_txfifo_flush(priv, IWL_DROP_ALL);
  1334. return count;
  1335. }
  1336. static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
  1337. char __user *user_buf,
  1338. size_t count, loff_t *ppos)
  1339. {
  1340. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1341. return priv->cfg->ops->lib->debugfs_ops.bt_stats_read(file,
  1342. user_buf, count, ppos);
  1343. }
  1344. static ssize_t iwl_dbgfs_wd_timeout_write(struct file *file,
  1345. const char __user *user_buf,
  1346. size_t count, loff_t *ppos) {
  1347. struct iwl_priv *priv = file->private_data;
  1348. char buf[8];
  1349. int buf_size;
  1350. int timeout;
  1351. memset(buf, 0, sizeof(buf));
  1352. buf_size = min(count, sizeof(buf) - 1);
  1353. if (copy_from_user(buf, user_buf, buf_size))
  1354. return -EFAULT;
  1355. if (sscanf(buf, "%d", &timeout) != 1)
  1356. return -EINVAL;
  1357. if (timeout < 0 || timeout > IWL_MAX_WD_TIMEOUT)
  1358. timeout = IWL_DEF_WD_TIMEOUT;
  1359. priv->cfg->base_params->wd_timeout = timeout;
  1360. iwl_setup_watchdog(priv);
  1361. return count;
  1362. }
  1363. static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
  1364. char __user *user_buf,
  1365. size_t count, loff_t *ppos) {
  1366. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1367. int pos = 0;
  1368. char buf[200];
  1369. const size_t bufsz = sizeof(buf);
  1370. ssize_t ret;
  1371. if (!priv->bt_enable_flag) {
  1372. pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n");
  1373. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1374. return ret;
  1375. }
  1376. pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n",
  1377. priv->bt_enable_flag);
  1378. pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
  1379. priv->bt_full_concurrent ? "full concurrency" : "3-wire");
  1380. pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
  1381. "last traffic notif: %d\n",
  1382. priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load);
  1383. pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
  1384. "kill_ack_mask: %x, kill_cts_mask: %x\n",
  1385. priv->bt_ch_announce, priv->kill_ack_mask,
  1386. priv->kill_cts_mask);
  1387. pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
  1388. switch (priv->bt_traffic_load) {
  1389. case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
  1390. pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
  1391. break;
  1392. case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
  1393. pos += scnprintf(buf + pos, bufsz - pos, "High\n");
  1394. break;
  1395. case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
  1396. pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
  1397. break;
  1398. case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
  1399. default:
  1400. pos += scnprintf(buf + pos, bufsz - pos, "None\n");
  1401. break;
  1402. }
  1403. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1404. return ret;
  1405. }
  1406. static ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
  1407. char __user *user_buf,
  1408. size_t count, loff_t *ppos)
  1409. {
  1410. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1411. int pos = 0;
  1412. char buf[40];
  1413. const size_t bufsz = sizeof(buf);
  1414. if (priv->cfg->ht_params)
  1415. pos += scnprintf(buf + pos, bufsz - pos,
  1416. "use %s for aggregation\n",
  1417. (priv->cfg->ht_params->use_rts_for_aggregation) ?
  1418. "rts/cts" : "cts-to-self");
  1419. else
  1420. pos += scnprintf(buf + pos, bufsz - pos, "N/A");
  1421. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1422. }
  1423. static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
  1424. const char __user *user_buf,
  1425. size_t count, loff_t *ppos) {
  1426. struct iwl_priv *priv = file->private_data;
  1427. char buf[8];
  1428. int buf_size;
  1429. int rts;
  1430. if (!priv->cfg->ht_params)
  1431. return -EINVAL;
  1432. memset(buf, 0, sizeof(buf));
  1433. buf_size = min(count, sizeof(buf) - 1);
  1434. if (copy_from_user(buf, user_buf, buf_size))
  1435. return -EFAULT;
  1436. if (sscanf(buf, "%d", &rts) != 1)
  1437. return -EINVAL;
  1438. if (rts)
  1439. priv->cfg->ht_params->use_rts_for_aggregation = true;
  1440. else
  1441. priv->cfg->ht_params->use_rts_for_aggregation = false;
  1442. return count;
  1443. }
  1444. static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
  1445. char __user *user_buf,
  1446. size_t count, loff_t *ppos)
  1447. {
  1448. struct iwl_priv *priv = file->private_data;
  1449. if (priv->cfg->ops->lib->debugfs_ops.reply_tx_error)
  1450. return priv->cfg->ops->lib->debugfs_ops.reply_tx_error(
  1451. file, user_buf, count, ppos);
  1452. else
  1453. return -ENODATA;
  1454. }
  1455. DEBUGFS_READ_FILE_OPS(rx_statistics);
  1456. DEBUGFS_READ_FILE_OPS(tx_statistics);
  1457. DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
  1458. DEBUGFS_READ_FILE_OPS(rx_queue);
  1459. DEBUGFS_READ_FILE_OPS(tx_queue);
  1460. DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
  1461. DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
  1462. DEBUGFS_READ_FILE_OPS(ucode_general_stats);
  1463. DEBUGFS_READ_FILE_OPS(sensitivity);
  1464. DEBUGFS_READ_FILE_OPS(chain_noise);
  1465. DEBUGFS_READ_FILE_OPS(power_save_status);
  1466. DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
  1467. DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
  1468. DEBUGFS_WRITE_FILE_OPS(csr);
  1469. DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
  1470. DEBUGFS_READ_FILE_OPS(fh_reg);
  1471. DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
  1472. DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
  1473. DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
  1474. DEBUGFS_READ_FILE_OPS(rxon_flags);
  1475. DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
  1476. DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
  1477. DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
  1478. DEBUGFS_WRITE_FILE_OPS(wd_timeout);
  1479. DEBUGFS_READ_FILE_OPS(bt_traffic);
  1480. DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
  1481. DEBUGFS_READ_FILE_OPS(reply_tx_error);
  1482. /*
  1483. * Create the debugfs files and directories
  1484. *
  1485. */
  1486. int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
  1487. {
  1488. struct dentry *phyd = priv->hw->wiphy->debugfsdir;
  1489. struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
  1490. dir_drv = debugfs_create_dir(name, phyd);
  1491. if (!dir_drv)
  1492. return -ENOMEM;
  1493. priv->debugfs_dir = dir_drv;
  1494. dir_data = debugfs_create_dir("data", dir_drv);
  1495. if (!dir_data)
  1496. goto err;
  1497. dir_rf = debugfs_create_dir("rf", dir_drv);
  1498. if (!dir_rf)
  1499. goto err;
  1500. dir_debug = debugfs_create_dir("debug", dir_drv);
  1501. if (!dir_debug)
  1502. goto err;
  1503. DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
  1504. DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
  1505. DEBUGFS_ADD_FILE(log_event, dir_data, S_IWUSR | S_IRUSR);
  1506. DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
  1507. DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
  1508. DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
  1509. DEBUGFS_ADD_FILE(interrupt, dir_data, S_IWUSR | S_IRUSR);
  1510. DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
  1511. if (!priv->cfg->base_params->broken_powersave) {
  1512. DEBUGFS_ADD_FILE(sleep_level_override, dir_data,
  1513. S_IWUSR | S_IRUSR);
  1514. DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
  1515. }
  1516. DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
  1517. DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
  1518. DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
  1519. DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
  1520. DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
  1521. DEBUGFS_ADD_FILE(rx_queue, dir_debug, S_IRUSR);
  1522. DEBUGFS_ADD_FILE(tx_queue, dir_debug, S_IRUSR);
  1523. DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
  1524. DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
  1525. DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
  1526. DEBUGFS_ADD_FILE(csr, dir_debug, S_IWUSR);
  1527. DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR);
  1528. DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
  1529. DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
  1530. DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
  1531. DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
  1532. DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
  1533. DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
  1534. if (priv->cfg->ops->lib->dev_txfifo_flush)
  1535. DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR);
  1536. DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR);
  1537. if (priv->cfg->base_params->sensitivity_calib_by_driver)
  1538. DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
  1539. if (priv->cfg->base_params->chain_noise_calib_by_driver)
  1540. DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
  1541. if (priv->cfg->base_params->ucode_tracing)
  1542. DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
  1543. if (iwl_bt_statistics(priv))
  1544. DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR);
  1545. DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR);
  1546. DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
  1547. DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
  1548. DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
  1549. if (iwl_advanced_bt_coexist(priv))
  1550. DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR);
  1551. if (priv->cfg->base_params->sensitivity_calib_by_driver)
  1552. DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
  1553. &priv->disable_sens_cal);
  1554. if (priv->cfg->base_params->chain_noise_calib_by_driver)
  1555. DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
  1556. &priv->disable_chain_noise_cal);
  1557. if (priv->cfg->base_params->tx_power_by_driver)
  1558. DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf,
  1559. &priv->disable_tx_power_cal);
  1560. return 0;
  1561. err:
  1562. IWL_ERR(priv, "Can't create the debugfs directory\n");
  1563. iwl_dbgfs_unregister(priv);
  1564. return -ENOMEM;
  1565. }
  1566. /**
  1567. * Remove the debugfs files and directories
  1568. *
  1569. */
  1570. void iwl_dbgfs_unregister(struct iwl_priv *priv)
  1571. {
  1572. if (!priv->debugfs_dir)
  1573. return;
  1574. debugfs_remove_recursive(priv->debugfs_dir);
  1575. priv->debugfs_dir = NULL;
  1576. }