iwl-debugfs.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2009 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/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/debugfs.h>
  31. #include <linux/ieee80211.h>
  32. #include <net/mac80211.h>
  33. #include "iwl-dev.h"
  34. #include "iwl-debug.h"
  35. #include "iwl-core.h"
  36. #include "iwl-io.h"
  37. #include "iwl-calib.h"
  38. /* create and remove of files */
  39. #define DEBUGFS_ADD_DIR(name, parent) do { \
  40. dbgfs->dir_##name = debugfs_create_dir(#name, parent); \
  41. if (!(dbgfs->dir_##name)) \
  42. goto err; \
  43. } while (0)
  44. #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
  45. dbgfs->dbgfs_##parent##_files.file_##name = \
  46. debugfs_create_file(#name, mode, \
  47. dbgfs->dir_##parent, priv, \
  48. &iwl_dbgfs_##name##_ops); \
  49. if (!(dbgfs->dbgfs_##parent##_files.file_##name)) \
  50. goto err; \
  51. } while (0)
  52. #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
  53. dbgfs->dbgfs_##parent##_files.file_##name = \
  54. debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
  55. dbgfs->dir_##parent, ptr); \
  56. if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
  57. || !dbgfs->dbgfs_##parent##_files.file_##name) \
  58. goto err; \
  59. } while (0)
  60. #define DEBUGFS_ADD_X32(name, parent, ptr) do { \
  61. dbgfs->dbgfs_##parent##_files.file_##name = \
  62. debugfs_create_x32(#name, S_IRUSR, dbgfs->dir_##parent, ptr); \
  63. if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
  64. || !dbgfs->dbgfs_##parent##_files.file_##name) \
  65. goto err; \
  66. } while (0)
  67. #define DEBUGFS_REMOVE(name) do { \
  68. debugfs_remove(name); \
  69. name = NULL; \
  70. } while (0);
  71. /* file operation */
  72. #define DEBUGFS_READ_FUNC(name) \
  73. static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
  74. char __user *user_buf, \
  75. size_t count, loff_t *ppos);
  76. #define DEBUGFS_WRITE_FUNC(name) \
  77. static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
  78. const char __user *user_buf, \
  79. size_t count, loff_t *ppos);
  80. static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
  81. {
  82. file->private_data = inode->i_private;
  83. return 0;
  84. }
  85. #define DEBUGFS_READ_FILE_OPS(name) \
  86. DEBUGFS_READ_FUNC(name); \
  87. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  88. .read = iwl_dbgfs_##name##_read, \
  89. .open = iwl_dbgfs_open_file_generic, \
  90. };
  91. #define DEBUGFS_WRITE_FILE_OPS(name) \
  92. DEBUGFS_WRITE_FUNC(name); \
  93. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  94. .write = iwl_dbgfs_##name##_write, \
  95. .open = iwl_dbgfs_open_file_generic, \
  96. };
  97. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  98. DEBUGFS_READ_FUNC(name); \
  99. DEBUGFS_WRITE_FUNC(name); \
  100. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  101. .write = iwl_dbgfs_##name##_write, \
  102. .read = iwl_dbgfs_##name##_read, \
  103. .open = iwl_dbgfs_open_file_generic, \
  104. };
  105. static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
  106. char __user *user_buf,
  107. size_t count, loff_t *ppos) {
  108. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  109. char *buf;
  110. int pos = 0;
  111. int cnt;
  112. ssize_t ret;
  113. const size_t bufsz = 100 +
  114. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  115. buf = kzalloc(bufsz, GFP_KERNEL);
  116. if (!buf)
  117. return -ENOMEM;
  118. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  119. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  120. pos += scnprintf(buf + pos, bufsz - pos,
  121. "\t%25s\t\t: %u\n",
  122. get_mgmt_string(cnt),
  123. priv->tx_stats.mgmt[cnt]);
  124. }
  125. pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
  126. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  127. pos += scnprintf(buf + pos, bufsz - pos,
  128. "\t%25s\t\t: %u\n",
  129. get_ctrl_string(cnt),
  130. priv->tx_stats.ctrl[cnt]);
  131. }
  132. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  133. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  134. priv->tx_stats.data_cnt);
  135. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  136. priv->tx_stats.data_bytes);
  137. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  138. kfree(buf);
  139. return ret;
  140. }
  141. static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
  142. const char __user *user_buf,
  143. size_t count, loff_t *ppos)
  144. {
  145. struct iwl_priv *priv = file->private_data;
  146. u32 clear_flag;
  147. char buf[8];
  148. int buf_size;
  149. memset(buf, 0, sizeof(buf));
  150. buf_size = min(count, sizeof(buf) - 1);
  151. if (copy_from_user(buf, user_buf, buf_size))
  152. return -EFAULT;
  153. if (sscanf(buf, "%x", &clear_flag) != 1)
  154. return -EFAULT;
  155. iwl_clear_traffic_stats(priv);
  156. return count;
  157. }
  158. static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
  159. char __user *user_buf,
  160. size_t count, loff_t *ppos) {
  161. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  162. char *buf;
  163. int pos = 0;
  164. int cnt;
  165. ssize_t ret;
  166. const size_t bufsz = 100 +
  167. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  168. buf = kzalloc(bufsz, GFP_KERNEL);
  169. if (!buf)
  170. return -ENOMEM;
  171. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  172. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  173. pos += scnprintf(buf + pos, bufsz - pos,
  174. "\t%25s\t\t: %u\n",
  175. get_mgmt_string(cnt),
  176. priv->rx_stats.mgmt[cnt]);
  177. }
  178. pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
  179. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  180. pos += scnprintf(buf + pos, bufsz - pos,
  181. "\t%25s\t\t: %u\n",
  182. get_ctrl_string(cnt),
  183. priv->rx_stats.ctrl[cnt]);
  184. }
  185. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  186. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  187. priv->rx_stats.data_cnt);
  188. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  189. priv->rx_stats.data_bytes);
  190. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  191. kfree(buf);
  192. return ret;
  193. }
  194. #define BYTE1_MASK 0x000000ff;
  195. #define BYTE2_MASK 0x0000ffff;
  196. #define BYTE3_MASK 0x00ffffff;
  197. static ssize_t iwl_dbgfs_sram_read(struct file *file,
  198. char __user *user_buf,
  199. size_t count, loff_t *ppos)
  200. {
  201. u32 val;
  202. char *buf;
  203. ssize_t ret;
  204. int i;
  205. int pos = 0;
  206. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  207. size_t bufsz;
  208. /* default is to dump the entire data segment */
  209. if (!priv->dbgfs->sram_offset && !priv->dbgfs->sram_len) {
  210. priv->dbgfs->sram_offset = 0x800000;
  211. if (priv->ucode_type == UCODE_INIT)
  212. priv->dbgfs->sram_len = priv->ucode_init_data.len;
  213. else
  214. priv->dbgfs->sram_len = priv->ucode_data.len;
  215. }
  216. bufsz = 30 + priv->dbgfs->sram_len * sizeof(char) * 10;
  217. buf = kmalloc(bufsz, GFP_KERNEL);
  218. if (!buf)
  219. return -ENOMEM;
  220. pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
  221. priv->dbgfs->sram_len);
  222. pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
  223. priv->dbgfs->sram_offset);
  224. for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
  225. val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
  226. priv->dbgfs->sram_len - i);
  227. if (i < 4) {
  228. switch (i) {
  229. case 1:
  230. val &= BYTE1_MASK;
  231. break;
  232. case 2:
  233. val &= BYTE2_MASK;
  234. break;
  235. case 3:
  236. val &= BYTE3_MASK;
  237. break;
  238. }
  239. }
  240. if (!(i % 16))
  241. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  242. pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
  243. }
  244. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  245. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  246. kfree(buf);
  247. return ret;
  248. }
  249. static ssize_t iwl_dbgfs_sram_write(struct file *file,
  250. const char __user *user_buf,
  251. size_t count, loff_t *ppos)
  252. {
  253. struct iwl_priv *priv = file->private_data;
  254. char buf[64];
  255. int buf_size;
  256. u32 offset, len;
  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,%x", &offset, &len) == 2) {
  262. priv->dbgfs->sram_offset = offset;
  263. priv->dbgfs->sram_len = len;
  264. } else {
  265. priv->dbgfs->sram_offset = 0;
  266. priv->dbgfs->sram_len = 0;
  267. }
  268. return count;
  269. }
  270. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  271. size_t count, loff_t *ppos)
  272. {
  273. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  274. struct iwl_station_entry *station;
  275. int max_sta = priv->hw_params.max_stations;
  276. char *buf;
  277. int i, j, pos = 0;
  278. ssize_t ret;
  279. /* Add 30 for initial string */
  280. const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
  281. buf = kmalloc(bufsz, GFP_KERNEL);
  282. if (!buf)
  283. return -ENOMEM;
  284. pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
  285. priv->num_stations);
  286. for (i = 0; i < max_sta; i++) {
  287. station = &priv->stations[i];
  288. if (station->used) {
  289. pos += scnprintf(buf + pos, bufsz - pos,
  290. "station %d:\ngeneral data:\n", i+1);
  291. pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
  292. station->sta.sta.sta_id);
  293. pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
  294. station->sta.mode);
  295. pos += scnprintf(buf + pos, bufsz - pos,
  296. "flags: 0x%x\n",
  297. station->sta.station_flags_msk);
  298. pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
  299. pos += scnprintf(buf + pos, bufsz - pos,
  300. "seq_num\t\ttxq_id");
  301. pos += scnprintf(buf + pos, bufsz - pos,
  302. "\tframe_count\twait_for_ba\t");
  303. pos += scnprintf(buf + pos, bufsz - pos,
  304. "start_idx\tbitmap0\t");
  305. pos += scnprintf(buf + pos, bufsz - pos,
  306. "bitmap1\trate_n_flags");
  307. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  308. for (j = 0; j < MAX_TID_COUNT; j++) {
  309. pos += scnprintf(buf + pos, bufsz - pos,
  310. "[%d]:\t\t%u", j,
  311. station->tid[j].seq_number);
  312. pos += scnprintf(buf + pos, bufsz - pos,
  313. "\t%u\t\t%u\t\t%u\t\t",
  314. station->tid[j].agg.txq_id,
  315. station->tid[j].agg.frame_count,
  316. station->tid[j].agg.wait_for_ba);
  317. pos += scnprintf(buf + pos, bufsz - pos,
  318. "%u\t%llu\t%u",
  319. station->tid[j].agg.start_idx,
  320. (unsigned long long)station->tid[j].agg.bitmap,
  321. station->tid[j].agg.rate_n_flags);
  322. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  323. }
  324. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  325. }
  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 = (struct iwl_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->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_write(struct file *file,
  377. const char __user *user_buf,
  378. size_t count, loff_t *ppos)
  379. {
  380. struct iwl_priv *priv = file->private_data;
  381. u32 event_log_flag;
  382. char buf[8];
  383. int buf_size;
  384. memset(buf, 0, sizeof(buf));
  385. buf_size = min(count, sizeof(buf) - 1);
  386. if (copy_from_user(buf, user_buf, buf_size))
  387. return -EFAULT;
  388. if (sscanf(buf, "%d", &event_log_flag) != 1)
  389. return -EFAULT;
  390. if (event_log_flag == 1)
  391. priv->cfg->ops->lib->dump_nic_event_log(priv, true);
  392. return count;
  393. }
  394. static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
  395. size_t count, loff_t *ppos)
  396. {
  397. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  398. struct ieee80211_channel *channels = NULL;
  399. const struct ieee80211_supported_band *supp_band = NULL;
  400. int pos = 0, i, bufsz = PAGE_SIZE;
  401. char *buf;
  402. ssize_t ret;
  403. if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
  404. return -EAGAIN;
  405. buf = kzalloc(bufsz, GFP_KERNEL);
  406. if (!buf) {
  407. IWL_ERR(priv, "Can not allocate Buffer\n");
  408. return -ENOMEM;
  409. }
  410. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
  411. if (supp_band) {
  412. channels = supp_band->channels;
  413. pos += scnprintf(buf + pos, bufsz - pos,
  414. "Displaying %d channels in 2.4GHz band 802.11bg):\n",
  415. supp_band->n_channels);
  416. for (i = 0; i < supp_band->n_channels; i++)
  417. pos += scnprintf(buf + pos, bufsz - pos,
  418. "%d: %ddBm: BSS%s%s, %s.\n",
  419. ieee80211_frequency_to_channel(
  420. channels[i].center_freq),
  421. channels[i].max_power,
  422. channels[i].flags & IEEE80211_CHAN_RADAR ?
  423. " (IEEE 802.11h required)" : "",
  424. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  425. || (channels[i].flags &
  426. IEEE80211_CHAN_RADAR)) ? "" :
  427. ", IBSS",
  428. channels[i].flags &
  429. IEEE80211_CHAN_PASSIVE_SCAN ?
  430. "passive only" : "active/passive");
  431. }
  432. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
  433. if (supp_band) {
  434. channels = supp_band->channels;
  435. pos += scnprintf(buf + pos, bufsz - pos,
  436. "Displaying %d channels in 5.2GHz band (802.11a)\n",
  437. supp_band->n_channels);
  438. for (i = 0; i < supp_band->n_channels; i++)
  439. pos += scnprintf(buf + pos, bufsz - pos,
  440. "%d: %ddBm: BSS%s%s, %s.\n",
  441. ieee80211_frequency_to_channel(
  442. channels[i].center_freq),
  443. channels[i].max_power,
  444. channels[i].flags & IEEE80211_CHAN_RADAR ?
  445. " (IEEE 802.11h required)" : "",
  446. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  447. || (channels[i].flags &
  448. IEEE80211_CHAN_RADAR)) ? "" :
  449. ", IBSS",
  450. channels[i].flags &
  451. IEEE80211_CHAN_PASSIVE_SCAN ?
  452. "passive only" : "active/passive");
  453. }
  454. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  455. kfree(buf);
  456. return ret;
  457. }
  458. static ssize_t iwl_dbgfs_status_read(struct file *file,
  459. char __user *user_buf,
  460. size_t count, loff_t *ppos) {
  461. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  462. char buf[512];
  463. int pos = 0;
  464. const size_t bufsz = sizeof(buf);
  465. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
  466. test_bit(STATUS_HCMD_ACTIVE, &priv->status));
  467. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
  468. test_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status));
  469. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
  470. test_bit(STATUS_INT_ENABLED, &priv->status));
  471. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
  472. test_bit(STATUS_RF_KILL_HW, &priv->status));
  473. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
  474. test_bit(STATUS_CT_KILL, &priv->status));
  475. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
  476. test_bit(STATUS_INIT, &priv->status));
  477. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
  478. test_bit(STATUS_ALIVE, &priv->status));
  479. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
  480. test_bit(STATUS_READY, &priv->status));
  481. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
  482. test_bit(STATUS_TEMPERATURE, &priv->status));
  483. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
  484. test_bit(STATUS_GEO_CONFIGURED, &priv->status));
  485. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
  486. test_bit(STATUS_EXIT_PENDING, &priv->status));
  487. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
  488. test_bit(STATUS_STATISTICS, &priv->status));
  489. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
  490. test_bit(STATUS_SCANNING, &priv->status));
  491. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
  492. test_bit(STATUS_SCAN_ABORTING, &priv->status));
  493. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
  494. test_bit(STATUS_SCAN_HW, &priv->status));
  495. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
  496. test_bit(STATUS_POWER_PMI, &priv->status));
  497. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
  498. test_bit(STATUS_FW_ERROR, &priv->status));
  499. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_MODE_PENDING:\t %d\n",
  500. test_bit(STATUS_MODE_PENDING, &priv->status));
  501. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  502. }
  503. static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
  504. char __user *user_buf,
  505. size_t count, loff_t *ppos) {
  506. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  507. int pos = 0;
  508. int cnt = 0;
  509. char *buf;
  510. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  511. ssize_t ret;
  512. buf = kzalloc(bufsz, GFP_KERNEL);
  513. if (!buf) {
  514. IWL_ERR(priv, "Can not allocate Buffer\n");
  515. return -ENOMEM;
  516. }
  517. pos += scnprintf(buf + pos, bufsz - pos,
  518. "Interrupt Statistics Report:\n");
  519. pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
  520. priv->isr_stats.hw);
  521. pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
  522. priv->isr_stats.sw);
  523. if (priv->isr_stats.sw > 0) {
  524. pos += scnprintf(buf + pos, bufsz - pos,
  525. "\tLast Restarting Code: 0x%X\n",
  526. priv->isr_stats.sw_err);
  527. }
  528. #ifdef CONFIG_IWLWIFI_DEBUG
  529. pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
  530. priv->isr_stats.sch);
  531. pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
  532. priv->isr_stats.alive);
  533. #endif
  534. pos += scnprintf(buf + pos, bufsz - pos,
  535. "HW RF KILL switch toggled:\t %u\n",
  536. priv->isr_stats.rfkill);
  537. pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
  538. priv->isr_stats.ctkill);
  539. pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
  540. priv->isr_stats.wakeup);
  541. pos += scnprintf(buf + pos, bufsz - pos,
  542. "Rx command responses:\t\t %u\n",
  543. priv->isr_stats.rx);
  544. for (cnt = 0; cnt < REPLY_MAX; cnt++) {
  545. if (priv->isr_stats.rx_handlers[cnt] > 0)
  546. pos += scnprintf(buf + pos, bufsz - pos,
  547. "\tRx handler[%36s]:\t\t %u\n",
  548. get_cmd_string(cnt),
  549. priv->isr_stats.rx_handlers[cnt]);
  550. }
  551. pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
  552. priv->isr_stats.tx);
  553. pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
  554. priv->isr_stats.unhandled);
  555. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  556. kfree(buf);
  557. return ret;
  558. }
  559. static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
  560. const char __user *user_buf,
  561. size_t count, loff_t *ppos)
  562. {
  563. struct iwl_priv *priv = file->private_data;
  564. char buf[8];
  565. int buf_size;
  566. u32 reset_flag;
  567. memset(buf, 0, sizeof(buf));
  568. buf_size = min(count, sizeof(buf) - 1);
  569. if (copy_from_user(buf, user_buf, buf_size))
  570. return -EFAULT;
  571. if (sscanf(buf, "%x", &reset_flag) != 1)
  572. return -EFAULT;
  573. if (reset_flag == 0)
  574. iwl_clear_isr_stats(priv);
  575. return count;
  576. }
  577. static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
  578. size_t count, loff_t *ppos)
  579. {
  580. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  581. int pos = 0, i;
  582. char buf[256];
  583. const size_t bufsz = sizeof(buf);
  584. ssize_t ret;
  585. for (i = 0; i < AC_NUM; i++) {
  586. pos += scnprintf(buf + pos, bufsz - pos,
  587. "\tcw_min\tcw_max\taifsn\ttxop\n");
  588. pos += scnprintf(buf + pos, bufsz - pos,
  589. "AC[%d]\t%u\t%u\t%u\t%u\n", i,
  590. priv->qos_data.def_qos_parm.ac[i].cw_min,
  591. priv->qos_data.def_qos_parm.ac[i].cw_max,
  592. priv->qos_data.def_qos_parm.ac[i].aifsn,
  593. priv->qos_data.def_qos_parm.ac[i].edca_txop);
  594. }
  595. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  596. return ret;
  597. }
  598. static ssize_t iwl_dbgfs_led_read(struct file *file, char __user *user_buf,
  599. size_t count, loff_t *ppos)
  600. {
  601. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  602. int pos = 0;
  603. char buf[256];
  604. const size_t bufsz = sizeof(buf);
  605. ssize_t ret;
  606. pos += scnprintf(buf + pos, bufsz - pos,
  607. "allow blinking: %s\n",
  608. (priv->allow_blinking) ? "True" : "False");
  609. if (priv->allow_blinking) {
  610. pos += scnprintf(buf + pos, bufsz - pos,
  611. "Led blinking rate: %u\n",
  612. priv->last_blink_rate);
  613. pos += scnprintf(buf + pos, bufsz - pos,
  614. "Last blink time: %lu\n",
  615. priv->last_blink_time);
  616. }
  617. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  618. return ret;
  619. }
  620. static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
  621. char __user *user_buf,
  622. size_t count, loff_t *ppos)
  623. {
  624. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  625. struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
  626. struct iwl_tt_restriction *restriction;
  627. char buf[100];
  628. int pos = 0;
  629. const size_t bufsz = sizeof(buf);
  630. ssize_t ret;
  631. pos += scnprintf(buf + pos, bufsz - pos,
  632. "Thermal Throttling Mode: %s\n",
  633. tt->advanced_tt ? "Advance" : "Legacy");
  634. pos += scnprintf(buf + pos, bufsz - pos,
  635. "Thermal Throttling State: %d\n",
  636. tt->state);
  637. if (tt->advanced_tt) {
  638. restriction = tt->restriction + tt->state;
  639. pos += scnprintf(buf + pos, bufsz - pos,
  640. "Tx mode: %d\n",
  641. restriction->tx_stream);
  642. pos += scnprintf(buf + pos, bufsz - pos,
  643. "Rx mode: %d\n",
  644. restriction->rx_stream);
  645. pos += scnprintf(buf + pos, bufsz - pos,
  646. "HT mode: %d\n",
  647. restriction->is_ht);
  648. }
  649. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  650. return ret;
  651. }
  652. static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
  653. const char __user *user_buf,
  654. size_t count, loff_t *ppos)
  655. {
  656. struct iwl_priv *priv = file->private_data;
  657. char buf[8];
  658. int buf_size;
  659. int ht40;
  660. memset(buf, 0, sizeof(buf));
  661. buf_size = min(count, sizeof(buf) - 1);
  662. if (copy_from_user(buf, user_buf, buf_size))
  663. return -EFAULT;
  664. if (sscanf(buf, "%d", &ht40) != 1)
  665. return -EFAULT;
  666. if (!iwl_is_associated(priv))
  667. priv->disable_ht40 = ht40 ? true : false;
  668. else {
  669. IWL_ERR(priv, "Sta associated with AP - "
  670. "Change to 40MHz channel support is not allowed\n");
  671. return -EINVAL;
  672. }
  673. return count;
  674. }
  675. static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
  676. char __user *user_buf,
  677. size_t count, loff_t *ppos)
  678. {
  679. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  680. char buf[100];
  681. int pos = 0;
  682. const size_t bufsz = sizeof(buf);
  683. ssize_t ret;
  684. pos += scnprintf(buf + pos, bufsz - pos,
  685. "11n 40MHz Mode: %s\n",
  686. priv->disable_ht40 ? "Disabled" : "Enabled");
  687. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  688. return ret;
  689. }
  690. static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
  691. const char __user *user_buf,
  692. size_t count, loff_t *ppos)
  693. {
  694. struct iwl_priv *priv = file->private_data;
  695. char buf[8];
  696. int buf_size;
  697. int value;
  698. memset(buf, 0, sizeof(buf));
  699. buf_size = min(count, sizeof(buf) - 1);
  700. if (copy_from_user(buf, user_buf, buf_size))
  701. return -EFAULT;
  702. if (sscanf(buf, "%d", &value) != 1)
  703. return -EINVAL;
  704. /*
  705. * Our users expect 0 to be "CAM", but 0 isn't actually
  706. * valid here. However, let's not confuse them and present
  707. * IWL_POWER_INDEX_1 as "1", not "0".
  708. */
  709. if (value == 0)
  710. return -EINVAL;
  711. else if (value > 0)
  712. value -= 1;
  713. if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
  714. return -EINVAL;
  715. if (!iwl_is_ready_rf(priv))
  716. return -EAGAIN;
  717. priv->power_data.debug_sleep_level_override = value;
  718. iwl_power_update_mode(priv, true);
  719. return count;
  720. }
  721. static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
  722. char __user *user_buf,
  723. size_t count, loff_t *ppos)
  724. {
  725. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  726. char buf[10];
  727. int pos, value;
  728. const size_t bufsz = sizeof(buf);
  729. /* see the write function */
  730. value = priv->power_data.debug_sleep_level_override;
  731. if (value >= 0)
  732. value += 1;
  733. pos = scnprintf(buf, bufsz, "%d\n", value);
  734. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  735. }
  736. static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
  737. char __user *user_buf,
  738. size_t count, loff_t *ppos)
  739. {
  740. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  741. char buf[200];
  742. int pos = 0, i;
  743. const size_t bufsz = sizeof(buf);
  744. struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
  745. pos += scnprintf(buf + pos, bufsz - pos,
  746. "flags: %#.2x\n", le16_to_cpu(cmd->flags));
  747. pos += scnprintf(buf + pos, bufsz - pos,
  748. "RX/TX timeout: %d/%d usec\n",
  749. le32_to_cpu(cmd->rx_data_timeout),
  750. le32_to_cpu(cmd->tx_data_timeout));
  751. for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
  752. pos += scnprintf(buf + pos, bufsz - pos,
  753. "sleep_interval[%d]: %d\n", i,
  754. le32_to_cpu(cmd->sleep_interval[i]));
  755. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  756. }
  757. DEBUGFS_READ_WRITE_FILE_OPS(sram);
  758. DEBUGFS_WRITE_FILE_OPS(log_event);
  759. DEBUGFS_READ_FILE_OPS(nvm);
  760. DEBUGFS_READ_FILE_OPS(stations);
  761. DEBUGFS_READ_FILE_OPS(channels);
  762. DEBUGFS_READ_FILE_OPS(status);
  763. DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
  764. DEBUGFS_READ_FILE_OPS(qos);
  765. DEBUGFS_READ_FILE_OPS(led);
  766. DEBUGFS_READ_FILE_OPS(thermal_throttling);
  767. DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
  768. DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
  769. DEBUGFS_READ_FILE_OPS(current_sleep_command);
  770. static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
  771. char __user *user_buf,
  772. size_t count, loff_t *ppos)
  773. {
  774. struct iwl_priv *priv = file->private_data;
  775. int pos = 0, ofs = 0;
  776. int cnt = 0, entry;
  777. struct iwl_tx_queue *txq;
  778. struct iwl_queue *q;
  779. struct iwl_rx_queue *rxq = &priv->rxq;
  780. char *buf;
  781. int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
  782. (priv->cfg->num_of_queues * 32 * 8) + 400;
  783. const u8 *ptr;
  784. ssize_t ret;
  785. if (!priv->txq) {
  786. IWL_ERR(priv, "txq not ready\n");
  787. return -EAGAIN;
  788. }
  789. buf = kzalloc(bufsz, GFP_KERNEL);
  790. if (!buf) {
  791. IWL_ERR(priv, "Can not allocate buffer\n");
  792. return -ENOMEM;
  793. }
  794. pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
  795. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  796. txq = &priv->txq[cnt];
  797. q = &txq->q;
  798. pos += scnprintf(buf + pos, bufsz - pos,
  799. "q[%d]: read_ptr: %u, write_ptr: %u\n",
  800. cnt, q->read_ptr, q->write_ptr);
  801. }
  802. if (priv->tx_traffic && (iwl_debug_level & IWL_DL_TX)) {
  803. ptr = priv->tx_traffic;
  804. pos += scnprintf(buf + pos, bufsz - pos,
  805. "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
  806. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  807. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  808. entry++, ofs += 16) {
  809. pos += scnprintf(buf + pos, bufsz - pos,
  810. "0x%.4x ", ofs);
  811. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  812. buf + pos, bufsz - pos, 0);
  813. pos += strlen(buf + pos);
  814. if (bufsz - pos > 0)
  815. buf[pos++] = '\n';
  816. }
  817. }
  818. }
  819. pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
  820. pos += scnprintf(buf + pos, bufsz - pos,
  821. "read: %u, write: %u\n",
  822. rxq->read, rxq->write);
  823. if (priv->rx_traffic && (iwl_debug_level & IWL_DL_RX)) {
  824. ptr = priv->rx_traffic;
  825. pos += scnprintf(buf + pos, bufsz - pos,
  826. "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
  827. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  828. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  829. entry++, ofs += 16) {
  830. pos += scnprintf(buf + pos, bufsz - pos,
  831. "0x%.4x ", ofs);
  832. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  833. buf + pos, bufsz - pos, 0);
  834. pos += strlen(buf + pos);
  835. if (bufsz - pos > 0)
  836. buf[pos++] = '\n';
  837. }
  838. }
  839. }
  840. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  841. kfree(buf);
  842. return ret;
  843. }
  844. static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
  845. const char __user *user_buf,
  846. size_t count, loff_t *ppos)
  847. {
  848. struct iwl_priv *priv = file->private_data;
  849. char buf[8];
  850. int buf_size;
  851. int traffic_log;
  852. memset(buf, 0, sizeof(buf));
  853. buf_size = min(count, sizeof(buf) - 1);
  854. if (copy_from_user(buf, user_buf, buf_size))
  855. return -EFAULT;
  856. if (sscanf(buf, "%d", &traffic_log) != 1)
  857. return -EFAULT;
  858. if (traffic_log == 0)
  859. iwl_reset_traffic_log(priv);
  860. return count;
  861. }
  862. static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
  863. char __user *user_buf,
  864. size_t count, loff_t *ppos) {
  865. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  866. struct iwl_tx_queue *txq;
  867. struct iwl_queue *q;
  868. char *buf;
  869. int pos = 0;
  870. int cnt;
  871. int ret;
  872. const size_t bufsz = sizeof(char) * 64 * priv->cfg->num_of_queues;
  873. if (!priv->txq) {
  874. IWL_ERR(priv, "txq not ready\n");
  875. return -EAGAIN;
  876. }
  877. buf = kzalloc(bufsz, GFP_KERNEL);
  878. if (!buf)
  879. return -ENOMEM;
  880. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  881. txq = &priv->txq[cnt];
  882. q = &txq->q;
  883. pos += scnprintf(buf + pos, bufsz - pos,
  884. "hwq %.2d: read=%u write=%u stop=%d"
  885. " swq_id=%#.2x (ac %d/hwq %d)\n",
  886. cnt, q->read_ptr, q->write_ptr,
  887. !!test_bit(cnt, priv->queue_stopped),
  888. txq->swq_id,
  889. txq->swq_id & 0x80 ? txq->swq_id & 3 :
  890. txq->swq_id,
  891. txq->swq_id & 0x80 ? (txq->swq_id >> 2) &
  892. 0x1f : txq->swq_id);
  893. if (cnt >= 4)
  894. continue;
  895. /* for the ACs, display the stop count too */
  896. pos += scnprintf(buf + pos, bufsz - pos,
  897. " stop-count: %d\n",
  898. atomic_read(&priv->queue_stop_count[cnt]));
  899. }
  900. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  901. kfree(buf);
  902. return ret;
  903. }
  904. static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
  905. char __user *user_buf,
  906. size_t count, loff_t *ppos) {
  907. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  908. struct iwl_rx_queue *rxq = &priv->rxq;
  909. char buf[256];
  910. int pos = 0;
  911. const size_t bufsz = sizeof(buf);
  912. pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
  913. rxq->read);
  914. pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
  915. rxq->write);
  916. pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
  917. rxq->free_count);
  918. pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
  919. le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
  920. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  921. }
  922. static int iwl_dbgfs_statistics_flag(struct iwl_priv *priv, char *buf,
  923. int bufsz)
  924. {
  925. int p = 0;
  926. p += scnprintf(buf + p, bufsz - p,
  927. "Statistics Flag(0x%X):\n",
  928. le32_to_cpu(priv->statistics.flag));
  929. if (le32_to_cpu(priv->statistics.flag) & UCODE_STATISTICS_CLEAR_MSK)
  930. p += scnprintf(buf + p, bufsz - p,
  931. "\tStatistics have been cleared\n");
  932. p += scnprintf(buf + p, bufsz - p,
  933. "\tOperational Frequency: %s\n",
  934. (le32_to_cpu(priv->statistics.flag) &
  935. UCODE_STATISTICS_FREQUENCY_MSK)
  936. ? "2.4 GHz" : "5.2 GHz");
  937. p += scnprintf(buf + p, bufsz - p,
  938. "\tTGj Narrow Band: %s\n",
  939. (le32_to_cpu(priv->statistics.flag) &
  940. UCODE_STATISTICS_NARROW_BAND_MSK)
  941. ? "enabled" : "disabled");
  942. return p;
  943. }
  944. static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
  945. char __user *user_buf,
  946. size_t count, loff_t *ppos)
  947. {
  948. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  949. int pos = 0;
  950. char *buf;
  951. int bufsz = sizeof(struct statistics_rx_phy) * 20 +
  952. sizeof(struct statistics_rx_non_phy) * 20 +
  953. sizeof(struct statistics_rx_ht_phy) * 20 + 400;
  954. ssize_t ret;
  955. struct statistics_rx_phy *ofdm, *accum_ofdm;
  956. struct statistics_rx_phy *cck, *accum_cck;
  957. struct statistics_rx_non_phy *general, *accum_general;
  958. struct statistics_rx_ht_phy *ht, *accum_ht;
  959. if (!iwl_is_alive(priv))
  960. return -EAGAIN;
  961. /* make request to uCode to retrieve statistics information */
  962. mutex_lock(&priv->mutex);
  963. ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
  964. mutex_unlock(&priv->mutex);
  965. if (ret) {
  966. IWL_ERR(priv,
  967. "Error sending statistics request: %zd\n", ret);
  968. return -EAGAIN;
  969. }
  970. buf = kzalloc(bufsz, GFP_KERNEL);
  971. if (!buf) {
  972. IWL_ERR(priv, "Can not allocate Buffer\n");
  973. return -ENOMEM;
  974. }
  975. /* the statistic information display here is based on
  976. * the last statistics notification from uCode
  977. * might not reflect the current uCode activity
  978. */
  979. ofdm = &priv->statistics.rx.ofdm;
  980. cck = &priv->statistics.rx.cck;
  981. general = &priv->statistics.rx.general;
  982. ht = &priv->statistics.rx.ofdm_ht;
  983. accum_ofdm = &priv->accum_statistics.rx.ofdm;
  984. accum_cck = &priv->accum_statistics.rx.cck;
  985. accum_general = &priv->accum_statistics.rx.general;
  986. accum_ht = &priv->accum_statistics.rx.ofdm_ht;
  987. pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
  988. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - OFDM:\n");
  989. pos += scnprintf(buf + pos, bufsz - pos,
  990. "\t\t\tcurrent\t\t\taccumulative\n");
  991. pos += scnprintf(buf + pos, bufsz - pos, "ina_cnt:\t\t%u\t\t\t%u\n",
  992. le32_to_cpu(ofdm->ina_cnt), accum_ofdm->ina_cnt);
  993. pos += scnprintf(buf + pos, bufsz - pos, "fina_cnt:\t\t%u\t\t\t%u\n",
  994. le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt);
  995. pos += scnprintf(buf + pos, bufsz - pos, "plcp_err:\t\t%u\t\t\t%u\n",
  996. le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err);
  997. pos += scnprintf(buf + pos, bufsz - pos, "crc32_err:\t\t%u\t\t\t%u\n",
  998. le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err);
  999. pos += scnprintf(buf + pos, bufsz - pos,
  1000. "overrun_err:\t\t%u\t\t\t%u\n",
  1001. le32_to_cpu(ofdm->overrun_err),
  1002. accum_ofdm->overrun_err);
  1003. pos += scnprintf(buf + pos, bufsz - pos,
  1004. "early_overrun_err:\t%u\t\t\t%u\n",
  1005. le32_to_cpu(ofdm->early_overrun_err),
  1006. accum_ofdm->early_overrun_err);
  1007. pos += scnprintf(buf + pos, bufsz - pos, "crc32_good:\t\t%u\t\t\t%u\n",
  1008. le32_to_cpu(ofdm->crc32_good),
  1009. accum_ofdm->crc32_good);
  1010. pos += scnprintf(buf + pos, bufsz - pos,
  1011. "false_alarm_cnt:\t%u\t\t\t%u\n",
  1012. le32_to_cpu(ofdm->false_alarm_cnt),
  1013. accum_ofdm->false_alarm_cnt);
  1014. pos += scnprintf(buf + pos, bufsz - pos,
  1015. "fina_sync_err_cnt:\t%u\t\t\t%u\n",
  1016. le32_to_cpu(ofdm->fina_sync_err_cnt),
  1017. accum_ofdm->fina_sync_err_cnt);
  1018. pos += scnprintf(buf + pos, bufsz - pos,
  1019. "sfd_timeout:\t\t%u\t\t\t%u\n",
  1020. le32_to_cpu(ofdm->sfd_timeout),
  1021. accum_ofdm->sfd_timeout);
  1022. pos += scnprintf(buf + pos, bufsz - pos,
  1023. "fina_timeout:\t\t%u\t\t\t%u\n",
  1024. le32_to_cpu(ofdm->fina_timeout),
  1025. accum_ofdm->fina_timeout);
  1026. pos += scnprintf(buf + pos, bufsz - pos,
  1027. "unresponded_rts:\t%u\t\t\t%u\n",
  1028. le32_to_cpu(ofdm->unresponded_rts),
  1029. accum_ofdm->unresponded_rts);
  1030. pos += scnprintf(buf + pos, bufsz - pos,
  1031. "rxe_frame_lmt_ovrun:\t%u\t\t\t%u\n",
  1032. le32_to_cpu(ofdm->rxe_frame_limit_overrun),
  1033. accum_ofdm->rxe_frame_limit_overrun);
  1034. pos += scnprintf(buf + pos, bufsz - pos,
  1035. "sent_ack_cnt:\t\t%u\t\t\t%u\n",
  1036. le32_to_cpu(ofdm->sent_ack_cnt),
  1037. accum_ofdm->sent_ack_cnt);
  1038. pos += scnprintf(buf + pos, bufsz - pos,
  1039. "sent_cts_cnt:\t\t%u\t\t\t%u\n",
  1040. le32_to_cpu(ofdm->sent_cts_cnt),
  1041. accum_ofdm->sent_cts_cnt);
  1042. pos += scnprintf(buf + pos, bufsz - pos,
  1043. "sent_ba_rsp_cnt:\t%u\t\t\t%u\n",
  1044. le32_to_cpu(ofdm->sent_ba_rsp_cnt),
  1045. accum_ofdm->sent_ba_rsp_cnt);
  1046. pos += scnprintf(buf + pos, bufsz - pos,
  1047. "dsp_self_kill:\t\t%u\t\t\t%u\n",
  1048. le32_to_cpu(ofdm->dsp_self_kill),
  1049. accum_ofdm->dsp_self_kill);
  1050. pos += scnprintf(buf + pos, bufsz - pos,
  1051. "mh_format_err:\t\t%u\t\t\t%u\n",
  1052. le32_to_cpu(ofdm->mh_format_err),
  1053. accum_ofdm->mh_format_err);
  1054. pos += scnprintf(buf + pos, bufsz - pos,
  1055. "re_acq_main_rssi_sum:\t%u\t\t\t%u\n",
  1056. le32_to_cpu(ofdm->re_acq_main_rssi_sum),
  1057. accum_ofdm->re_acq_main_rssi_sum);
  1058. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - CCK:\n");
  1059. pos += scnprintf(buf + pos, bufsz - pos,
  1060. "\t\t\tcurrent\t\t\taccumulative\n");
  1061. pos += scnprintf(buf + pos, bufsz - pos, "ina_cnt:\t\t%u\t\t\t%u\n",
  1062. le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt);
  1063. pos += scnprintf(buf + pos, bufsz - pos, "fina_cnt:\t\t%u\t\t\t%u\n",
  1064. le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt);
  1065. pos += scnprintf(buf + pos, bufsz - pos, "plcp_err:\t\t%u\t\t\t%u\n",
  1066. le32_to_cpu(cck->plcp_err), accum_cck->plcp_err);
  1067. pos += scnprintf(buf + pos, bufsz - pos, "crc32_err:\t\t%u\t\t\t%u\n",
  1068. le32_to_cpu(cck->crc32_err), accum_cck->crc32_err);
  1069. pos += scnprintf(buf + pos, bufsz - pos,
  1070. "overrun_err:\t\t%u\t\t\t%u\n",
  1071. le32_to_cpu(cck->overrun_err),
  1072. accum_cck->overrun_err);
  1073. pos += scnprintf(buf + pos, bufsz - pos,
  1074. "early_overrun_err:\t%u\t\t\t%u\n",
  1075. le32_to_cpu(cck->early_overrun_err),
  1076. accum_cck->early_overrun_err);
  1077. pos += scnprintf(buf + pos, bufsz - pos, "crc32_good:\t\t%u\t\t\t%u\n",
  1078. le32_to_cpu(cck->crc32_good), accum_cck->crc32_good);
  1079. pos += scnprintf(buf + pos, bufsz - pos,
  1080. "false_alarm_cnt:\t%u\t\t\t%u\n",
  1081. le32_to_cpu(cck->false_alarm_cnt),
  1082. accum_cck->false_alarm_cnt);
  1083. pos += scnprintf(buf + pos, bufsz - pos,
  1084. "fina_sync_err_cnt:\t%u\t\t\t%u\n",
  1085. le32_to_cpu(cck->fina_sync_err_cnt),
  1086. accum_cck->fina_sync_err_cnt);
  1087. pos += scnprintf(buf + pos, bufsz - pos,
  1088. "sfd_timeout:\t\t%u\t\t\t%u\n",
  1089. le32_to_cpu(cck->sfd_timeout),
  1090. accum_cck->sfd_timeout);
  1091. pos += scnprintf(buf + pos, bufsz - pos,
  1092. "fina_timeout:\t\t%u\t\t\t%u\n",
  1093. le32_to_cpu(cck->fina_timeout),
  1094. accum_cck->fina_timeout);
  1095. pos += scnprintf(buf + pos, bufsz - pos,
  1096. "unresponded_rts:\t%u\t\t\t%u\n",
  1097. le32_to_cpu(cck->unresponded_rts),
  1098. accum_cck->unresponded_rts);
  1099. pos += scnprintf(buf + pos, bufsz - pos,
  1100. "rxe_frame_lmt_ovrun:\t%u\t\t\t%u\n",
  1101. le32_to_cpu(cck->rxe_frame_limit_overrun),
  1102. accum_cck->rxe_frame_limit_overrun);
  1103. pos += scnprintf(buf + pos, bufsz - pos,
  1104. "sent_ack_cnt:\t\t%u\t\t\t%u\n",
  1105. le32_to_cpu(cck->sent_ack_cnt),
  1106. accum_cck->sent_ack_cnt);
  1107. pos += scnprintf(buf + pos, bufsz - pos,
  1108. "sent_cts_cnt:\t\t%u\t\t\t%u\n",
  1109. le32_to_cpu(cck->sent_cts_cnt),
  1110. accum_cck->sent_cts_cnt);
  1111. pos += scnprintf(buf + pos, bufsz - pos,
  1112. "sent_ba_rsp_cnt:\t%u\t\t\t%u\n",
  1113. le32_to_cpu(cck->sent_ba_rsp_cnt),
  1114. accum_cck->sent_ba_rsp_cnt);
  1115. pos += scnprintf(buf + pos, bufsz - pos,
  1116. "dsp_self_kill:\t\t%u\t\t\t%u\n",
  1117. le32_to_cpu(cck->dsp_self_kill),
  1118. accum_cck->dsp_self_kill);
  1119. pos += scnprintf(buf + pos, bufsz - pos,
  1120. "mh_format_err:\t\t%u\t\t\t%u\n",
  1121. le32_to_cpu(cck->mh_format_err),
  1122. accum_cck->mh_format_err);
  1123. pos += scnprintf(buf + pos, bufsz - pos,
  1124. "re_acq_main_rssi_sum:\t%u\t\t\t%u\n",
  1125. le32_to_cpu(cck->re_acq_main_rssi_sum),
  1126. accum_cck->re_acq_main_rssi_sum);
  1127. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - GENERAL:\n");
  1128. pos += scnprintf(buf + pos, bufsz - pos,
  1129. "\t\t\tcurrent\t\t\taccumulative\n");
  1130. pos += scnprintf(buf + pos, bufsz - pos, "bogus_cts:\t\t%u\t\t\t%u\n",
  1131. le32_to_cpu(general->bogus_cts),
  1132. accum_general->bogus_cts);
  1133. pos += scnprintf(buf + pos, bufsz - pos, "bogus_ack:\t\t%u\t\t\t%u\n",
  1134. le32_to_cpu(general->bogus_ack),
  1135. accum_general->bogus_ack);
  1136. pos += scnprintf(buf + pos, bufsz - pos,
  1137. "non_bssid_frames:\t%u\t\t\t%u\n",
  1138. le32_to_cpu(general->non_bssid_frames),
  1139. accum_general->non_bssid_frames);
  1140. pos += scnprintf(buf + pos, bufsz - pos,
  1141. "filtered_frames:\t%u\t\t\t%u\n",
  1142. le32_to_cpu(general->filtered_frames),
  1143. accum_general->filtered_frames);
  1144. pos += scnprintf(buf + pos, bufsz - pos,
  1145. "non_channel_beacons:\t%u\t\t\t%u\n",
  1146. le32_to_cpu(general->non_channel_beacons),
  1147. accum_general->non_channel_beacons);
  1148. pos += scnprintf(buf + pos, bufsz - pos,
  1149. "channel_beacons:\t%u\t\t\t%u\n",
  1150. le32_to_cpu(general->channel_beacons),
  1151. accum_general->channel_beacons);
  1152. pos += scnprintf(buf + pos, bufsz - pos,
  1153. "num_missed_bcon:\t%u\t\t\t%u\n",
  1154. le32_to_cpu(general->num_missed_bcon),
  1155. accum_general->num_missed_bcon);
  1156. pos += scnprintf(buf + pos, bufsz - pos,
  1157. "adc_rx_saturation_time:\t%u\t\t\t%u\n",
  1158. le32_to_cpu(general->adc_rx_saturation_time),
  1159. accum_general->adc_rx_saturation_time);
  1160. pos += scnprintf(buf + pos, bufsz - pos,
  1161. "ina_detect_search_tm:\t%u\t\t\t%u\n",
  1162. le32_to_cpu(general->ina_detection_search_time),
  1163. accum_general->ina_detection_search_time);
  1164. pos += scnprintf(buf + pos, bufsz - pos,
  1165. "beacon_silence_rssi_a:\t%u\t\t\t%u\n",
  1166. le32_to_cpu(general->beacon_silence_rssi_a),
  1167. accum_general->beacon_silence_rssi_a);
  1168. pos += scnprintf(buf + pos, bufsz - pos,
  1169. "beacon_silence_rssi_b:\t%u\t\t\t%u\n",
  1170. le32_to_cpu(general->beacon_silence_rssi_b),
  1171. accum_general->beacon_silence_rssi_b);
  1172. pos += scnprintf(buf + pos, bufsz - pos,
  1173. "beacon_silence_rssi_c:\t%u\t\t\t%u\n",
  1174. le32_to_cpu(general->beacon_silence_rssi_c),
  1175. accum_general->beacon_silence_rssi_c);
  1176. pos += scnprintf(buf + pos, bufsz - pos,
  1177. "interference_data_flag:\t%u\t\t\t%u\n",
  1178. le32_to_cpu(general->interference_data_flag),
  1179. accum_general->interference_data_flag);
  1180. pos += scnprintf(buf + pos, bufsz - pos,
  1181. "channel_load:\t\t%u\t\t\t%u\n",
  1182. le32_to_cpu(general->channel_load),
  1183. accum_general->channel_load);
  1184. pos += scnprintf(buf + pos, bufsz - pos,
  1185. "dsp_false_alarms:\t%u\t\t\t%u\n",
  1186. le32_to_cpu(general->dsp_false_alarms),
  1187. accum_general->dsp_false_alarms);
  1188. pos += scnprintf(buf + pos, bufsz - pos,
  1189. "beacon_rssi_a:\t\t%u\t\t\t%u\n",
  1190. le32_to_cpu(general->beacon_rssi_a),
  1191. accum_general->beacon_rssi_a);
  1192. pos += scnprintf(buf + pos, bufsz - pos,
  1193. "beacon_rssi_b:\t\t%u\t\t\t%u\n",
  1194. le32_to_cpu(general->beacon_rssi_b),
  1195. accum_general->beacon_rssi_b);
  1196. pos += scnprintf(buf + pos, bufsz - pos,
  1197. "beacon_rssi_c:\t\t%u\t\t\t%u\n",
  1198. le32_to_cpu(general->beacon_rssi_c),
  1199. accum_general->beacon_rssi_c);
  1200. pos += scnprintf(buf + pos, bufsz - pos,
  1201. "beacon_energy_a:\t%u\t\t\t%u\n",
  1202. le32_to_cpu(general->beacon_energy_a),
  1203. accum_general->beacon_energy_a);
  1204. pos += scnprintf(buf + pos, bufsz - pos,
  1205. "beacon_energy_b:\t%u\t\t\t%u\n",
  1206. le32_to_cpu(general->beacon_energy_b),
  1207. accum_general->beacon_energy_b);
  1208. pos += scnprintf(buf + pos, bufsz - pos,
  1209. "beacon_energy_c:\t%u\t\t\t%u\n",
  1210. le32_to_cpu(general->beacon_energy_c),
  1211. accum_general->beacon_energy_c);
  1212. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - OFDM_HT:\n");
  1213. pos += scnprintf(buf + pos, bufsz - pos,
  1214. "\t\t\tcurrent\t\t\taccumulative\n");
  1215. pos += scnprintf(buf + pos, bufsz - pos, "plcp_err:\t\t%u\t\t\t%u\n",
  1216. le32_to_cpu(ht->plcp_err), accum_ht->plcp_err);
  1217. pos += scnprintf(buf + pos, bufsz - pos,
  1218. "overrun_err:\t\t%u\t\t\t%u\n",
  1219. le32_to_cpu(ht->overrun_err), accum_ht->overrun_err);
  1220. pos += scnprintf(buf + pos, bufsz - pos,
  1221. "early_overrun_err:\t%u\t\t\t%u\n",
  1222. le32_to_cpu(ht->early_overrun_err),
  1223. accum_ht->early_overrun_err);
  1224. pos += scnprintf(buf + pos, bufsz - pos, "crc32_good:\t\t%u\t\t\t%u\n",
  1225. le32_to_cpu(ht->crc32_good), accum_ht->crc32_good);
  1226. pos += scnprintf(buf + pos, bufsz - pos, "crc32_err:\t\t%u\t\t\t%u\n",
  1227. le32_to_cpu(ht->crc32_err), accum_ht->crc32_err);
  1228. pos += scnprintf(buf + pos, bufsz - pos,
  1229. "mh_format_err:\t\t%u\t\t\t%u\n",
  1230. le32_to_cpu(ht->mh_format_err),
  1231. accum_ht->mh_format_err);
  1232. pos += scnprintf(buf + pos, bufsz - pos,
  1233. "agg_crc32_good:\t\t%u\t\t\t%u\n",
  1234. le32_to_cpu(ht->agg_crc32_good),
  1235. accum_ht->agg_crc32_good);
  1236. pos += scnprintf(buf + pos, bufsz - pos,
  1237. "agg_mpdu_cnt:\t\t%u\t\t\t%u\n",
  1238. le32_to_cpu(ht->agg_mpdu_cnt),
  1239. accum_ht->agg_mpdu_cnt);
  1240. pos += scnprintf(buf + pos, bufsz - pos, "agg_cnt:\t\t%u\t\t\t%u\n",
  1241. le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt);
  1242. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1243. kfree(buf);
  1244. return ret;
  1245. }
  1246. static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
  1247. char __user *user_buf,
  1248. size_t count, loff_t *ppos)
  1249. {
  1250. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1251. int pos = 0;
  1252. char *buf;
  1253. int bufsz = (sizeof(struct statistics_tx) * 24) + 250;
  1254. ssize_t ret;
  1255. struct statistics_tx *tx, *accum_tx;
  1256. if (!iwl_is_alive(priv))
  1257. return -EAGAIN;
  1258. /* make request to uCode to retrieve statistics information */
  1259. mutex_lock(&priv->mutex);
  1260. ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
  1261. mutex_unlock(&priv->mutex);
  1262. if (ret) {
  1263. IWL_ERR(priv,
  1264. "Error sending statistics request: %zd\n", ret);
  1265. return -EAGAIN;
  1266. }
  1267. buf = kzalloc(bufsz, GFP_KERNEL);
  1268. if (!buf) {
  1269. IWL_ERR(priv, "Can not allocate Buffer\n");
  1270. return -ENOMEM;
  1271. }
  1272. /* the statistic information display here is based on
  1273. * the last statistics notification from uCode
  1274. * might not reflect the current uCode activity
  1275. */
  1276. tx = &priv->statistics.tx;
  1277. accum_tx = &priv->accum_statistics.tx;
  1278. pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
  1279. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Tx:\n");
  1280. pos += scnprintf(buf + pos, bufsz - pos,
  1281. "\t\t\tcurrent\t\t\taccumulative\n");
  1282. pos += scnprintf(buf + pos, bufsz - pos, "preamble:\t\t\t%u\t\t\t%u\n",
  1283. le32_to_cpu(tx->preamble_cnt),
  1284. accum_tx->preamble_cnt);
  1285. pos += scnprintf(buf + pos, bufsz - pos,
  1286. "rx_detected_cnt:\t\t%u\t\t\t%u\n",
  1287. le32_to_cpu(tx->rx_detected_cnt),
  1288. accum_tx->rx_detected_cnt);
  1289. pos += scnprintf(buf + pos, bufsz - pos,
  1290. "bt_prio_defer_cnt:\t\t%u\t\t\t%u\n",
  1291. le32_to_cpu(tx->bt_prio_defer_cnt),
  1292. accum_tx->bt_prio_defer_cnt);
  1293. pos += scnprintf(buf + pos, bufsz - pos,
  1294. "bt_prio_kill_cnt:\t\t%u\t\t\t%u\n",
  1295. le32_to_cpu(tx->bt_prio_kill_cnt),
  1296. accum_tx->bt_prio_kill_cnt);
  1297. pos += scnprintf(buf + pos, bufsz - pos,
  1298. "few_bytes_cnt:\t\t\t%u\t\t\t%u\n",
  1299. le32_to_cpu(tx->few_bytes_cnt),
  1300. accum_tx->few_bytes_cnt);
  1301. pos += scnprintf(buf + pos, bufsz - pos,
  1302. "cts_timeout:\t\t\t%u\t\t\t%u\n",
  1303. le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout);
  1304. pos += scnprintf(buf + pos, bufsz - pos,
  1305. "ack_timeout:\t\t\t%u\t\t\t%u\n",
  1306. le32_to_cpu(tx->ack_timeout),
  1307. accum_tx->ack_timeout);
  1308. pos += scnprintf(buf + pos, bufsz - pos,
  1309. "expected_ack_cnt:\t\t%u\t\t\t%u\n",
  1310. le32_to_cpu(tx->expected_ack_cnt),
  1311. accum_tx->expected_ack_cnt);
  1312. pos += scnprintf(buf + pos, bufsz - pos,
  1313. "actual_ack_cnt:\t\t\t%u\t\t\t%u\n",
  1314. le32_to_cpu(tx->actual_ack_cnt),
  1315. accum_tx->actual_ack_cnt);
  1316. pos += scnprintf(buf + pos, bufsz - pos,
  1317. "dump_msdu_cnt:\t\t\t%u\t\t\t%u\n",
  1318. le32_to_cpu(tx->dump_msdu_cnt),
  1319. accum_tx->dump_msdu_cnt);
  1320. pos += scnprintf(buf + pos, bufsz - pos,
  1321. "abort_nxt_frame_mismatch:"
  1322. "\t%u\t\t\t%u\n",
  1323. le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
  1324. accum_tx->burst_abort_next_frame_mismatch_cnt);
  1325. pos += scnprintf(buf + pos, bufsz - pos,
  1326. "abort_missing_nxt_frame:"
  1327. "\t%u\t\t\t%u\n",
  1328. le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
  1329. accum_tx->burst_abort_missing_next_frame_cnt);
  1330. pos += scnprintf(buf + pos, bufsz - pos,
  1331. "cts_timeout_collision:\t\t%u\t\t\t%u\n",
  1332. le32_to_cpu(tx->cts_timeout_collision),
  1333. accum_tx->cts_timeout_collision);
  1334. pos += scnprintf(buf + pos, bufsz - pos,
  1335. "ack_ba_timeout_collision:\t%u\t\t\t%u\n",
  1336. le32_to_cpu(tx->ack_or_ba_timeout_collision),
  1337. accum_tx->ack_or_ba_timeout_collision);
  1338. pos += scnprintf(buf + pos, bufsz - pos,
  1339. "agg ba_timeout:\t\t\t%u\t\t\t%u\n",
  1340. le32_to_cpu(tx->agg.ba_timeout),
  1341. accum_tx->agg.ba_timeout);
  1342. pos += scnprintf(buf + pos, bufsz - pos,
  1343. "agg ba_resched_frames:\t\t%u\t\t\t%u\n",
  1344. le32_to_cpu(tx->agg.ba_reschedule_frames),
  1345. accum_tx->agg.ba_reschedule_frames);
  1346. pos += scnprintf(buf + pos, bufsz - pos,
  1347. "agg scd_query_agg_frame:\t%u\t\t\t%u\n",
  1348. le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
  1349. accum_tx->agg.scd_query_agg_frame_cnt);
  1350. pos += scnprintf(buf + pos, bufsz - pos,
  1351. "agg scd_query_no_agg:\t\t%u\t\t\t%u\n",
  1352. le32_to_cpu(tx->agg.scd_query_no_agg),
  1353. accum_tx->agg.scd_query_no_agg);
  1354. pos += scnprintf(buf + pos, bufsz - pos,
  1355. "agg scd_query_agg:\t\t%u\t\t\t%u\n",
  1356. le32_to_cpu(tx->agg.scd_query_agg),
  1357. accum_tx->agg.scd_query_agg);
  1358. pos += scnprintf(buf + pos, bufsz - pos,
  1359. "agg scd_query_mismatch:\t\t%u\t\t\t%u\n",
  1360. le32_to_cpu(tx->agg.scd_query_mismatch),
  1361. accum_tx->agg.scd_query_mismatch);
  1362. pos += scnprintf(buf + pos, bufsz - pos,
  1363. "agg frame_not_ready:\t\t%u\t\t\t%u\n",
  1364. le32_to_cpu(tx->agg.frame_not_ready),
  1365. accum_tx->agg.frame_not_ready);
  1366. pos += scnprintf(buf + pos, bufsz - pos,
  1367. "agg underrun:\t\t\t%u\t\t\t%u\n",
  1368. le32_to_cpu(tx->agg.underrun),
  1369. accum_tx->agg.underrun);
  1370. pos += scnprintf(buf + pos, bufsz - pos,
  1371. "agg bt_prio_kill:\t\t%u\t\t\t%u\n",
  1372. le32_to_cpu(tx->agg.bt_prio_kill),
  1373. accum_tx->agg.bt_prio_kill);
  1374. pos += scnprintf(buf + pos, bufsz - pos,
  1375. "agg rx_ba_rsp_cnt:\t\t%u\t\t\t%u\n",
  1376. le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
  1377. accum_tx->agg.rx_ba_rsp_cnt);
  1378. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1379. kfree(buf);
  1380. return ret;
  1381. }
  1382. static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
  1383. char __user *user_buf,
  1384. size_t count, loff_t *ppos)
  1385. {
  1386. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1387. int pos = 0;
  1388. char *buf;
  1389. int bufsz = sizeof(struct statistics_general) * 4 + 250;
  1390. ssize_t ret;
  1391. struct statistics_general *general, *accum_general;
  1392. struct statistics_dbg *dbg, *accum_dbg;
  1393. struct statistics_div *div, *accum_div;
  1394. if (!iwl_is_alive(priv))
  1395. return -EAGAIN;
  1396. /* make request to uCode to retrieve statistics information */
  1397. mutex_lock(&priv->mutex);
  1398. ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
  1399. mutex_unlock(&priv->mutex);
  1400. if (ret) {
  1401. IWL_ERR(priv,
  1402. "Error sending statistics request: %zd\n", ret);
  1403. return -EAGAIN;
  1404. }
  1405. buf = kzalloc(bufsz, GFP_KERNEL);
  1406. if (!buf) {
  1407. IWL_ERR(priv, "Can not allocate Buffer\n");
  1408. return -ENOMEM;
  1409. }
  1410. /* the statistic information display here is based on
  1411. * the last statistics notification from uCode
  1412. * might not reflect the current uCode activity
  1413. */
  1414. general = &priv->statistics.general;
  1415. dbg = &priv->statistics.general.dbg;
  1416. div = &priv->statistics.general.div;
  1417. accum_general = &priv->accum_statistics.general;
  1418. accum_dbg = &priv->accum_statistics.general.dbg;
  1419. accum_div = &priv->accum_statistics.general.div;
  1420. pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
  1421. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_General:\n");
  1422. pos += scnprintf(buf + pos, bufsz - pos,
  1423. "\t\t\tcurrent\t\t\taccumulative\n");
  1424. pos += scnprintf(buf + pos, bufsz - pos, "temperature:\t\t\t%u\n",
  1425. le32_to_cpu(general->temperature));
  1426. pos += scnprintf(buf + pos, bufsz - pos, "temperature_m:\t\t\t%u\n",
  1427. le32_to_cpu(general->temperature_m));
  1428. pos += scnprintf(buf + pos, bufsz - pos,
  1429. "burst_check:\t\t\t%u\t\t\t%u\n",
  1430. le32_to_cpu(dbg->burst_check),
  1431. accum_dbg->burst_check);
  1432. pos += scnprintf(buf + pos, bufsz - pos,
  1433. "burst_count:\t\t\t%u\t\t\t%u\n",
  1434. le32_to_cpu(dbg->burst_count),
  1435. accum_dbg->burst_count);
  1436. pos += scnprintf(buf + pos, bufsz - pos,
  1437. "sleep_time:\t\t\t%u\t\t\t%u\n",
  1438. le32_to_cpu(general->sleep_time),
  1439. accum_general->sleep_time);
  1440. pos += scnprintf(buf + pos, bufsz - pos,
  1441. "slots_out:\t\t\t%u\t\t\t%u\n",
  1442. le32_to_cpu(general->slots_out),
  1443. accum_general->slots_out);
  1444. pos += scnprintf(buf + pos, bufsz - pos,
  1445. "slots_idle:\t\t\t%u\t\t\t%u\n",
  1446. le32_to_cpu(general->slots_idle),
  1447. accum_general->slots_idle);
  1448. pos += scnprintf(buf + pos, bufsz - pos, "ttl_timestamp:\t\t\t%u\n",
  1449. le32_to_cpu(general->ttl_timestamp));
  1450. pos += scnprintf(buf + pos, bufsz - pos, "tx_on_a:\t\t\t%u\t\t\t%u\n",
  1451. le32_to_cpu(div->tx_on_a), accum_div->tx_on_a);
  1452. pos += scnprintf(buf + pos, bufsz - pos, "tx_on_b:\t\t\t%u\t\t\t%u\n",
  1453. le32_to_cpu(div->tx_on_b), accum_div->tx_on_b);
  1454. pos += scnprintf(buf + pos, bufsz - pos,
  1455. "exec_time:\t\t\t%u\t\t\t%u\n",
  1456. le32_to_cpu(div->exec_time), accum_div->exec_time);
  1457. pos += scnprintf(buf + pos, bufsz - pos,
  1458. "probe_time:\t\t\t%u\t\t\t%u\n",
  1459. le32_to_cpu(div->probe_time), accum_div->probe_time);
  1460. pos += scnprintf(buf + pos, bufsz - pos,
  1461. "rx_enable_counter:\t\t%u\t\t\t%u\n",
  1462. le32_to_cpu(general->rx_enable_counter),
  1463. accum_general->rx_enable_counter);
  1464. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1465. kfree(buf);
  1466. return ret;
  1467. }
  1468. static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
  1469. char __user *user_buf,
  1470. size_t count, loff_t *ppos) {
  1471. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1472. int pos = 0;
  1473. int cnt = 0;
  1474. char *buf;
  1475. int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
  1476. ssize_t ret;
  1477. struct iwl_sensitivity_data *data;
  1478. data = &priv->sensitivity_data;
  1479. buf = kzalloc(bufsz, GFP_KERNEL);
  1480. if (!buf) {
  1481. IWL_ERR(priv, "Can not allocate Buffer\n");
  1482. return -ENOMEM;
  1483. }
  1484. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
  1485. data->auto_corr_ofdm);
  1486. pos += scnprintf(buf + pos, bufsz - pos,
  1487. "auto_corr_ofdm_mrc:\t\t %u\n",
  1488. data->auto_corr_ofdm_mrc);
  1489. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
  1490. data->auto_corr_ofdm_x1);
  1491. pos += scnprintf(buf + pos, bufsz - pos,
  1492. "auto_corr_ofdm_mrc_x1:\t\t %u\n",
  1493. data->auto_corr_ofdm_mrc_x1);
  1494. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
  1495. data->auto_corr_cck);
  1496. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
  1497. data->auto_corr_cck_mrc);
  1498. pos += scnprintf(buf + pos, bufsz - pos,
  1499. "last_bad_plcp_cnt_ofdm:\t\t %u\n",
  1500. data->last_bad_plcp_cnt_ofdm);
  1501. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
  1502. data->last_fa_cnt_ofdm);
  1503. pos += scnprintf(buf + pos, bufsz - pos,
  1504. "last_bad_plcp_cnt_cck:\t\t %u\n",
  1505. data->last_bad_plcp_cnt_cck);
  1506. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
  1507. data->last_fa_cnt_cck);
  1508. pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
  1509. data->nrg_curr_state);
  1510. pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
  1511. data->nrg_prev_state);
  1512. pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
  1513. for (cnt = 0; cnt < 10; cnt++) {
  1514. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1515. data->nrg_value[cnt]);
  1516. }
  1517. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1518. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
  1519. for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
  1520. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1521. data->nrg_silence_rssi[cnt]);
  1522. }
  1523. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1524. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
  1525. data->nrg_silence_ref);
  1526. pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
  1527. data->nrg_energy_idx);
  1528. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
  1529. data->nrg_silence_idx);
  1530. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
  1531. data->nrg_th_cck);
  1532. pos += scnprintf(buf + pos, bufsz - pos,
  1533. "nrg_auto_corr_silence_diff:\t %u\n",
  1534. data->nrg_auto_corr_silence_diff);
  1535. pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
  1536. data->num_in_cck_no_fa);
  1537. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
  1538. data->nrg_th_ofdm);
  1539. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1540. kfree(buf);
  1541. return ret;
  1542. }
  1543. static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
  1544. char __user *user_buf,
  1545. size_t count, loff_t *ppos) {
  1546. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1547. int pos = 0;
  1548. int cnt = 0;
  1549. char *buf;
  1550. int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
  1551. ssize_t ret;
  1552. struct iwl_chain_noise_data *data;
  1553. data = &priv->chain_noise_data;
  1554. buf = kzalloc(bufsz, GFP_KERNEL);
  1555. if (!buf) {
  1556. IWL_ERR(priv, "Can not allocate Buffer\n");
  1557. return -ENOMEM;
  1558. }
  1559. pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
  1560. data->active_chains);
  1561. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
  1562. data->chain_noise_a);
  1563. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
  1564. data->chain_noise_b);
  1565. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
  1566. data->chain_noise_c);
  1567. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
  1568. data->chain_signal_a);
  1569. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
  1570. data->chain_signal_b);
  1571. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
  1572. data->chain_signal_c);
  1573. pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
  1574. data->beacon_count);
  1575. pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
  1576. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1577. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1578. data->disconn_array[cnt]);
  1579. }
  1580. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1581. pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
  1582. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1583. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1584. data->delta_gain_code[cnt]);
  1585. }
  1586. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1587. pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
  1588. data->radio_write);
  1589. pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
  1590. data->state);
  1591. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1592. kfree(buf);
  1593. return ret;
  1594. }
  1595. static ssize_t iwl_dbgfs_tx_power_read(struct file *file,
  1596. char __user *user_buf,
  1597. size_t count, loff_t *ppos) {
  1598. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1599. char buf[128];
  1600. int pos = 0;
  1601. ssize_t ret;
  1602. const size_t bufsz = sizeof(buf);
  1603. struct statistics_tx *tx;
  1604. if (!iwl_is_alive(priv))
  1605. pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
  1606. else {
  1607. /* make request to uCode to retrieve statistics information */
  1608. mutex_lock(&priv->mutex);
  1609. ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
  1610. mutex_unlock(&priv->mutex);
  1611. if (ret) {
  1612. IWL_ERR(priv, "Error sending statistics request: %zd\n",
  1613. ret);
  1614. return -EAGAIN;
  1615. }
  1616. tx = &priv->statistics.tx;
  1617. if (tx->tx_power.ant_a ||
  1618. tx->tx_power.ant_b ||
  1619. tx->tx_power.ant_c) {
  1620. pos += scnprintf(buf + pos, bufsz - pos,
  1621. "tx power: (1/2 dB step)\n");
  1622. if ((priv->cfg->valid_tx_ant & ANT_A) &&
  1623. tx->tx_power.ant_a)
  1624. pos += scnprintf(buf + pos, bufsz - pos,
  1625. "\tantenna A: 0x%X\n",
  1626. tx->tx_power.ant_a);
  1627. if ((priv->cfg->valid_tx_ant & ANT_B) &&
  1628. tx->tx_power.ant_b)
  1629. pos += scnprintf(buf + pos, bufsz - pos,
  1630. "\tantenna B: 0x%X\n",
  1631. tx->tx_power.ant_b);
  1632. if ((priv->cfg->valid_tx_ant & ANT_C) &&
  1633. tx->tx_power.ant_c)
  1634. pos += scnprintf(buf + pos, bufsz - pos,
  1635. "\tantenna C: 0x%X\n",
  1636. tx->tx_power.ant_c);
  1637. } else
  1638. pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
  1639. }
  1640. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1641. }
  1642. static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
  1643. char __user *user_buf,
  1644. size_t count, loff_t *ppos)
  1645. {
  1646. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1647. char buf[60];
  1648. int pos = 0;
  1649. const size_t bufsz = sizeof(buf);
  1650. u32 pwrsave_status;
  1651. pwrsave_status = iwl_read32(priv, CSR_GP_CNTRL) &
  1652. CSR_GP_REG_POWER_SAVE_STATUS_MSK;
  1653. pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
  1654. pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
  1655. (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
  1656. (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
  1657. (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
  1658. "error");
  1659. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1660. }
  1661. static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
  1662. const char __user *user_buf,
  1663. size_t count, loff_t *ppos)
  1664. {
  1665. struct iwl_priv *priv = file->private_data;
  1666. char buf[8];
  1667. int buf_size;
  1668. int clear;
  1669. memset(buf, 0, sizeof(buf));
  1670. buf_size = min(count, sizeof(buf) - 1);
  1671. if (copy_from_user(buf, user_buf, buf_size))
  1672. return -EFAULT;
  1673. if (sscanf(buf, "%d", &clear) != 1)
  1674. return -EFAULT;
  1675. /* make request to uCode to retrieve statistics information */
  1676. mutex_lock(&priv->mutex);
  1677. iwl_send_statistics_request(priv, CMD_SYNC, true);
  1678. mutex_unlock(&priv->mutex);
  1679. return count;
  1680. }
  1681. DEBUGFS_READ_FILE_OPS(rx_statistics);
  1682. DEBUGFS_READ_FILE_OPS(tx_statistics);
  1683. DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
  1684. DEBUGFS_READ_FILE_OPS(rx_queue);
  1685. DEBUGFS_READ_FILE_OPS(tx_queue);
  1686. DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
  1687. DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
  1688. DEBUGFS_READ_FILE_OPS(ucode_general_stats);
  1689. DEBUGFS_READ_FILE_OPS(sensitivity);
  1690. DEBUGFS_READ_FILE_OPS(chain_noise);
  1691. DEBUGFS_READ_FILE_OPS(tx_power);
  1692. DEBUGFS_READ_FILE_OPS(power_save_status);
  1693. DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
  1694. DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
  1695. /*
  1696. * Create the debugfs files and directories
  1697. *
  1698. */
  1699. int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
  1700. {
  1701. struct iwl_debugfs *dbgfs;
  1702. struct dentry *phyd = priv->hw->wiphy->debugfsdir;
  1703. int ret = 0;
  1704. dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
  1705. if (!dbgfs) {
  1706. ret = -ENOMEM;
  1707. goto err;
  1708. }
  1709. priv->dbgfs = dbgfs;
  1710. dbgfs->name = name;
  1711. dbgfs->dir_drv = debugfs_create_dir(name, phyd);
  1712. if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)) {
  1713. ret = -ENOENT;
  1714. goto err;
  1715. }
  1716. DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
  1717. DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv);
  1718. DEBUGFS_ADD_DIR(debug, dbgfs->dir_drv);
  1719. DEBUGFS_ADD_FILE(nvm, data, S_IRUSR);
  1720. DEBUGFS_ADD_FILE(sram, data, S_IWUSR | S_IRUSR);
  1721. DEBUGFS_ADD_FILE(log_event, data, S_IWUSR);
  1722. DEBUGFS_ADD_FILE(stations, data, S_IRUSR);
  1723. DEBUGFS_ADD_FILE(channels, data, S_IRUSR);
  1724. DEBUGFS_ADD_FILE(status, data, S_IRUSR);
  1725. DEBUGFS_ADD_FILE(interrupt, data, S_IWUSR | S_IRUSR);
  1726. DEBUGFS_ADD_FILE(qos, data, S_IRUSR);
  1727. DEBUGFS_ADD_FILE(led, data, S_IRUSR);
  1728. DEBUGFS_ADD_FILE(sleep_level_override, data, S_IWUSR | S_IRUSR);
  1729. DEBUGFS_ADD_FILE(current_sleep_command, data, S_IRUSR);
  1730. DEBUGFS_ADD_FILE(thermal_throttling, data, S_IRUSR);
  1731. DEBUGFS_ADD_FILE(disable_ht40, data, S_IWUSR | S_IRUSR);
  1732. DEBUGFS_ADD_FILE(rx_statistics, debug, S_IRUSR);
  1733. DEBUGFS_ADD_FILE(tx_statistics, debug, S_IRUSR);
  1734. DEBUGFS_ADD_FILE(traffic_log, debug, S_IWUSR | S_IRUSR);
  1735. DEBUGFS_ADD_FILE(rx_queue, debug, S_IRUSR);
  1736. DEBUGFS_ADD_FILE(tx_queue, debug, S_IRUSR);
  1737. DEBUGFS_ADD_FILE(tx_power, debug, S_IRUSR);
  1738. DEBUGFS_ADD_FILE(power_save_status, debug, S_IRUSR);
  1739. DEBUGFS_ADD_FILE(clear_ucode_statistics, debug, S_IWUSR);
  1740. DEBUGFS_ADD_FILE(clear_traffic_statistics, debug, S_IWUSR);
  1741. if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) {
  1742. DEBUGFS_ADD_FILE(ucode_rx_stats, debug, S_IRUSR);
  1743. DEBUGFS_ADD_FILE(ucode_tx_stats, debug, S_IRUSR);
  1744. DEBUGFS_ADD_FILE(ucode_general_stats, debug, S_IRUSR);
  1745. DEBUGFS_ADD_FILE(sensitivity, debug, S_IRUSR);
  1746. DEBUGFS_ADD_FILE(chain_noise, debug, S_IRUSR);
  1747. }
  1748. DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
  1749. DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
  1750. &priv->disable_chain_noise_cal);
  1751. if (((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) ||
  1752. ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_3945))
  1753. DEBUGFS_ADD_BOOL(disable_tx_power, rf,
  1754. &priv->disable_tx_power_cal);
  1755. return 0;
  1756. err:
  1757. IWL_ERR(priv, "Can't open the debugfs directory\n");
  1758. iwl_dbgfs_unregister(priv);
  1759. return ret;
  1760. }
  1761. EXPORT_SYMBOL(iwl_dbgfs_register);
  1762. /**
  1763. * Remove the debugfs files and directories
  1764. *
  1765. */
  1766. void iwl_dbgfs_unregister(struct iwl_priv *priv)
  1767. {
  1768. if (!priv->dbgfs)
  1769. return;
  1770. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sleep_level_override);
  1771. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_current_sleep_command);
  1772. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_nvm);
  1773. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
  1774. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_log_event);
  1775. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
  1776. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_channels);
  1777. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_status);
  1778. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_interrupt);
  1779. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_qos);
  1780. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_led);
  1781. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_thermal_throttling);
  1782. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_disable_ht40);
  1783. DEBUGFS_REMOVE(priv->dbgfs->dir_data);
  1784. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_rx_statistics);
  1785. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_statistics);
  1786. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_traffic_log);
  1787. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_rx_queue);
  1788. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_queue);
  1789. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_power);
  1790. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_power_save_status);
  1791. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1792. file_clear_ucode_statistics);
  1793. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1794. file_clear_traffic_statistics);
  1795. if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) {
  1796. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1797. file_ucode_rx_stats);
  1798. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1799. file_ucode_tx_stats);
  1800. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1801. file_ucode_general_stats);
  1802. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1803. file_sensitivity);
  1804. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1805. file_chain_noise);
  1806. }
  1807. DEBUGFS_REMOVE(priv->dbgfs->dir_debug);
  1808. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
  1809. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
  1810. if (((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) ||
  1811. ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_3945))
  1812. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_tx_power);
  1813. DEBUGFS_REMOVE(priv->dbgfs->dir_rf);
  1814. DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
  1815. kfree(priv->dbgfs);
  1816. priv->dbgfs = NULL;
  1817. }
  1818. EXPORT_SYMBOL(iwl_dbgfs_unregister);