iwl-debugfs.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760
  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) do { \
  45. dbgfs->dbgfs_##parent##_files.file_##name = \
  46. debugfs_create_file(#name, S_IWUSR | S_IRUSR, \
  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 + sizeof(char) * 24 * (MANAGEMENT_MAX + CONTROL_MAX);
  114. buf = kzalloc(bufsz, GFP_KERNEL);
  115. if (!buf)
  116. return -ENOMEM;
  117. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  118. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  119. pos += scnprintf(buf + pos, bufsz - pos,
  120. "\t%s\t\t: %u\n",
  121. get_mgmt_string(cnt),
  122. priv->tx_stats.mgmt[cnt]);
  123. }
  124. pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
  125. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  126. pos += scnprintf(buf + pos, bufsz - pos,
  127. "\t%s\t\t: %u\n",
  128. get_ctrl_string(cnt),
  129. priv->tx_stats.ctrl[cnt]);
  130. }
  131. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  132. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  133. priv->tx_stats.data_cnt);
  134. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  135. priv->tx_stats.data_bytes);
  136. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  137. kfree(buf);
  138. return ret;
  139. }
  140. static ssize_t iwl_dbgfs_tx_statistics_write(struct file *file,
  141. const char __user *user_buf,
  142. size_t count, loff_t *ppos)
  143. {
  144. struct iwl_priv *priv = file->private_data;
  145. u32 clear_flag;
  146. char buf[8];
  147. int buf_size;
  148. memset(buf, 0, sizeof(buf));
  149. buf_size = min(count, sizeof(buf) - 1);
  150. if (copy_from_user(buf, user_buf, buf_size))
  151. return -EFAULT;
  152. if (sscanf(buf, "%x", &clear_flag) != 1)
  153. return -EFAULT;
  154. if (clear_flag == 1)
  155. iwl_clear_tx_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) * 24 * (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%s\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%s\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. static ssize_t iwl_dbgfs_rx_statistics_write(struct file *file,
  195. const char __user *user_buf,
  196. size_t count, loff_t *ppos)
  197. {
  198. struct iwl_priv *priv = file->private_data;
  199. u32 clear_flag;
  200. char buf[8];
  201. int buf_size;
  202. memset(buf, 0, sizeof(buf));
  203. buf_size = min(count, sizeof(buf) - 1);
  204. if (copy_from_user(buf, user_buf, buf_size))
  205. return -EFAULT;
  206. if (sscanf(buf, "%x", &clear_flag) != 1)
  207. return -EFAULT;
  208. if (clear_flag == 1)
  209. iwl_clear_rx_stats(priv);
  210. return count;
  211. }
  212. #define BYTE1_MASK 0x000000ff;
  213. #define BYTE2_MASK 0x0000ffff;
  214. #define BYTE3_MASK 0x00ffffff;
  215. static ssize_t iwl_dbgfs_sram_read(struct file *file,
  216. char __user *user_buf,
  217. size_t count, loff_t *ppos)
  218. {
  219. u32 val;
  220. char buf[1024];
  221. ssize_t ret;
  222. int i;
  223. int pos = 0;
  224. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  225. const size_t bufsz = sizeof(buf);
  226. for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
  227. val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
  228. priv->dbgfs->sram_len - i);
  229. if (i < 4) {
  230. switch (i) {
  231. case 1:
  232. val &= BYTE1_MASK;
  233. break;
  234. case 2:
  235. val &= BYTE2_MASK;
  236. break;
  237. case 3:
  238. val &= BYTE3_MASK;
  239. break;
  240. }
  241. }
  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. return ret;
  247. }
  248. static ssize_t iwl_dbgfs_sram_write(struct file *file,
  249. const char __user *user_buf,
  250. size_t count, loff_t *ppos)
  251. {
  252. struct iwl_priv *priv = file->private_data;
  253. char buf[64];
  254. int buf_size;
  255. u32 offset, len;
  256. memset(buf, 0, sizeof(buf));
  257. buf_size = min(count, sizeof(buf) - 1);
  258. if (copy_from_user(buf, user_buf, buf_size))
  259. return -EFAULT;
  260. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  261. priv->dbgfs->sram_offset = offset;
  262. priv->dbgfs->sram_len = len;
  263. } else {
  264. priv->dbgfs->sram_offset = 0;
  265. priv->dbgfs->sram_len = 0;
  266. }
  267. return count;
  268. }
  269. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  270. size_t count, loff_t *ppos)
  271. {
  272. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  273. struct iwl_station_entry *station;
  274. int max_sta = priv->hw_params.max_stations;
  275. char *buf;
  276. int i, j, pos = 0;
  277. ssize_t ret;
  278. /* Add 30 for initial string */
  279. const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
  280. buf = kmalloc(bufsz, GFP_KERNEL);
  281. if (!buf)
  282. return -ENOMEM;
  283. pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
  284. priv->num_stations);
  285. for (i = 0; i < max_sta; i++) {
  286. station = &priv->stations[i];
  287. if (station->used) {
  288. pos += scnprintf(buf + pos, bufsz - pos,
  289. "station %d:\ngeneral data:\n", i+1);
  290. pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
  291. station->sta.sta.sta_id);
  292. pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
  293. station->sta.mode);
  294. pos += scnprintf(buf + pos, bufsz - pos,
  295. "flags: 0x%x\n",
  296. station->sta.station_flags_msk);
  297. pos += scnprintf(buf + pos, bufsz - pos,
  298. "ps_status: %u\n", station->ps_status);
  299. pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
  300. pos += scnprintf(buf + pos, bufsz - pos,
  301. "seq_num\t\ttxq_id");
  302. pos += scnprintf(buf + pos, bufsz - pos,
  303. "\tframe_count\twait_for_ba\t");
  304. pos += scnprintf(buf + pos, bufsz - pos,
  305. "start_idx\tbitmap0\t");
  306. pos += scnprintf(buf + pos, bufsz - pos,
  307. "bitmap1\trate_n_flags");
  308. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  309. for (j = 0; j < MAX_TID_COUNT; j++) {
  310. pos += scnprintf(buf + pos, bufsz - pos,
  311. "[%d]:\t\t%u", j,
  312. station->tid[j].seq_number);
  313. pos += scnprintf(buf + pos, bufsz - pos,
  314. "\t%u\t\t%u\t\t%u\t\t",
  315. station->tid[j].agg.txq_id,
  316. station->tid[j].agg.frame_count,
  317. station->tid[j].agg.wait_for_ba);
  318. pos += scnprintf(buf + pos, bufsz - pos,
  319. "%u\t%llu\t%u",
  320. station->tid[j].agg.start_idx,
  321. (unsigned long long)station->tid[j].agg.bitmap,
  322. station->tid[j].agg.rate_n_flags);
  323. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  324. }
  325. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  326. }
  327. }
  328. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  329. kfree(buf);
  330. return ret;
  331. }
  332. static ssize_t iwl_dbgfs_nvm_read(struct file *file,
  333. char __user *user_buf,
  334. size_t count,
  335. loff_t *ppos)
  336. {
  337. ssize_t ret;
  338. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  339. int pos = 0, ofs = 0, buf_size = 0;
  340. const u8 *ptr;
  341. char *buf;
  342. u16 eeprom_ver;
  343. size_t eeprom_len = priv->cfg->eeprom_size;
  344. buf_size = 4 * eeprom_len + 256;
  345. if (eeprom_len % 16) {
  346. IWL_ERR(priv, "NVM size is not multiple of 16.\n");
  347. return -ENODATA;
  348. }
  349. ptr = priv->eeprom;
  350. if (!ptr) {
  351. IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
  352. return -ENOMEM;
  353. }
  354. /* 4 characters for byte 0xYY */
  355. buf = kzalloc(buf_size, GFP_KERNEL);
  356. if (!buf) {
  357. IWL_ERR(priv, "Can not allocate Buffer\n");
  358. return -ENOMEM;
  359. }
  360. eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
  361. pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
  362. "version: 0x%x\n",
  363. (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
  364. ? "OTP" : "EEPROM", eeprom_ver);
  365. for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
  366. pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
  367. hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
  368. buf_size - pos, 0);
  369. pos += strlen(buf + pos);
  370. if (buf_size - pos > 0)
  371. buf[pos++] = '\n';
  372. }
  373. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  374. kfree(buf);
  375. return ret;
  376. }
  377. static ssize_t iwl_dbgfs_log_event_write(struct file *file,
  378. const char __user *user_buf,
  379. size_t count, loff_t *ppos)
  380. {
  381. struct iwl_priv *priv = file->private_data;
  382. u32 event_log_flag;
  383. char buf[8];
  384. int buf_size;
  385. memset(buf, 0, sizeof(buf));
  386. buf_size = min(count, sizeof(buf) - 1);
  387. if (copy_from_user(buf, user_buf, buf_size))
  388. return -EFAULT;
  389. if (sscanf(buf, "%d", &event_log_flag) != 1)
  390. return -EFAULT;
  391. if (event_log_flag == 1)
  392. priv->cfg->ops->lib->dump_nic_event_log(priv);
  393. return count;
  394. }
  395. static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
  396. size_t count, loff_t *ppos)
  397. {
  398. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  399. struct ieee80211_channel *channels = NULL;
  400. const struct ieee80211_supported_band *supp_band = NULL;
  401. int pos = 0, i, bufsz = PAGE_SIZE;
  402. char *buf;
  403. ssize_t ret;
  404. if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
  405. return -EAGAIN;
  406. buf = kzalloc(bufsz, GFP_KERNEL);
  407. if (!buf) {
  408. IWL_ERR(priv, "Can not allocate Buffer\n");
  409. return -ENOMEM;
  410. }
  411. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
  412. if (supp_band) {
  413. channels = supp_band->channels;
  414. pos += scnprintf(buf + pos, bufsz - pos,
  415. "Displaying %d channels in 2.4GHz band 802.11bg):\n",
  416. supp_band->n_channels);
  417. for (i = 0; i < supp_band->n_channels; i++)
  418. pos += scnprintf(buf + pos, bufsz - pos,
  419. "%d: %ddBm: BSS%s%s, %s.\n",
  420. ieee80211_frequency_to_channel(
  421. channels[i].center_freq),
  422. channels[i].max_power,
  423. channels[i].flags & IEEE80211_CHAN_RADAR ?
  424. " (IEEE 802.11h required)" : "",
  425. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  426. || (channels[i].flags &
  427. IEEE80211_CHAN_RADAR)) ? "" :
  428. ", IBSS",
  429. channels[i].flags &
  430. IEEE80211_CHAN_PASSIVE_SCAN ?
  431. "passive only" : "active/passive");
  432. }
  433. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
  434. if (supp_band) {
  435. channels = supp_band->channels;
  436. pos += scnprintf(buf + pos, bufsz - pos,
  437. "Displaying %d channels in 5.2GHz band (802.11a)\n",
  438. supp_band->n_channels);
  439. for (i = 0; i < supp_band->n_channels; i++)
  440. pos += scnprintf(buf + pos, bufsz - pos,
  441. "%d: %ddBm: BSS%s%s, %s.\n",
  442. ieee80211_frequency_to_channel(
  443. channels[i].center_freq),
  444. channels[i].max_power,
  445. channels[i].flags & IEEE80211_CHAN_RADAR ?
  446. " (IEEE 802.11h required)" : "",
  447. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  448. || (channels[i].flags &
  449. IEEE80211_CHAN_RADAR)) ? "" :
  450. ", IBSS",
  451. channels[i].flags &
  452. IEEE80211_CHAN_PASSIVE_SCAN ?
  453. "passive only" : "active/passive");
  454. }
  455. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  456. kfree(buf);
  457. return ret;
  458. }
  459. static ssize_t iwl_dbgfs_status_read(struct file *file,
  460. char __user *user_buf,
  461. size_t count, loff_t *ppos) {
  462. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  463. char buf[512];
  464. int pos = 0;
  465. const size_t bufsz = sizeof(buf);
  466. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
  467. test_bit(STATUS_HCMD_ACTIVE, &priv->status));
  468. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
  469. test_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status));
  470. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
  471. test_bit(STATUS_INT_ENABLED, &priv->status));
  472. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
  473. test_bit(STATUS_RF_KILL_HW, &priv->status));
  474. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
  475. test_bit(STATUS_INIT, &priv->status));
  476. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
  477. test_bit(STATUS_ALIVE, &priv->status));
  478. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
  479. test_bit(STATUS_READY, &priv->status));
  480. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
  481. test_bit(STATUS_TEMPERATURE, &priv->status));
  482. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
  483. test_bit(STATUS_GEO_CONFIGURED, &priv->status));
  484. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
  485. test_bit(STATUS_EXIT_PENDING, &priv->status));
  486. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
  487. test_bit(STATUS_STATISTICS, &priv->status));
  488. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
  489. test_bit(STATUS_SCANNING, &priv->status));
  490. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
  491. test_bit(STATUS_SCAN_ABORTING, &priv->status));
  492. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
  493. test_bit(STATUS_SCAN_HW, &priv->status));
  494. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
  495. test_bit(STATUS_POWER_PMI, &priv->status));
  496. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
  497. test_bit(STATUS_FW_ERROR, &priv->status));
  498. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_MODE_PENDING:\t %d\n",
  499. test_bit(STATUS_MODE_PENDING, &priv->status));
  500. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  501. }
  502. static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
  503. char __user *user_buf,
  504. size_t count, loff_t *ppos) {
  505. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  506. int pos = 0;
  507. int cnt = 0;
  508. char *buf;
  509. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  510. ssize_t ret;
  511. buf = kzalloc(bufsz, GFP_KERNEL);
  512. if (!buf) {
  513. IWL_ERR(priv, "Can not allocate Buffer\n");
  514. return -ENOMEM;
  515. }
  516. pos += scnprintf(buf + pos, bufsz - pos,
  517. "Interrupt Statistics Report:\n");
  518. pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
  519. priv->isr_stats.hw);
  520. pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
  521. priv->isr_stats.sw);
  522. if (priv->isr_stats.sw > 0) {
  523. pos += scnprintf(buf + pos, bufsz - pos,
  524. "\tLast Restarting Code: 0x%X\n",
  525. priv->isr_stats.sw_err);
  526. }
  527. #ifdef CONFIG_IWLWIFI_DEBUG
  528. pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
  529. priv->isr_stats.sch);
  530. pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
  531. priv->isr_stats.alive);
  532. #endif
  533. pos += scnprintf(buf + pos, bufsz - pos,
  534. "HW RF KILL switch toggled:\t %u\n",
  535. priv->isr_stats.rfkill);
  536. pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
  537. priv->isr_stats.ctkill);
  538. pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
  539. priv->isr_stats.wakeup);
  540. pos += scnprintf(buf + pos, bufsz - pos,
  541. "Rx command responses:\t\t %u\n",
  542. priv->isr_stats.rx);
  543. for (cnt = 0; cnt < REPLY_MAX; cnt++) {
  544. if (priv->isr_stats.rx_handlers[cnt] > 0)
  545. pos += scnprintf(buf + pos, bufsz - pos,
  546. "\tRx handler[%36s]:\t\t %u\n",
  547. get_cmd_string(cnt),
  548. priv->isr_stats.rx_handlers[cnt]);
  549. }
  550. pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
  551. priv->isr_stats.tx);
  552. pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
  553. priv->isr_stats.unhandled);
  554. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  555. kfree(buf);
  556. return ret;
  557. }
  558. static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
  559. const char __user *user_buf,
  560. size_t count, loff_t *ppos)
  561. {
  562. struct iwl_priv *priv = file->private_data;
  563. char buf[8];
  564. int buf_size;
  565. u32 reset_flag;
  566. memset(buf, 0, sizeof(buf));
  567. buf_size = min(count, sizeof(buf) - 1);
  568. if (copy_from_user(buf, user_buf, buf_size))
  569. return -EFAULT;
  570. if (sscanf(buf, "%x", &reset_flag) != 1)
  571. return -EFAULT;
  572. if (reset_flag == 0)
  573. iwl_clear_isr_stats(priv);
  574. return count;
  575. }
  576. static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
  577. size_t count, loff_t *ppos)
  578. {
  579. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  580. int pos = 0, i;
  581. char buf[256];
  582. const size_t bufsz = sizeof(buf);
  583. ssize_t ret;
  584. for (i = 0; i < AC_NUM; i++) {
  585. pos += scnprintf(buf + pos, bufsz - pos,
  586. "\tcw_min\tcw_max\taifsn\ttxop\n");
  587. pos += scnprintf(buf + pos, bufsz - pos,
  588. "AC[%d]\t%u\t%u\t%u\t%u\n", i,
  589. priv->qos_data.def_qos_parm.ac[i].cw_min,
  590. priv->qos_data.def_qos_parm.ac[i].cw_max,
  591. priv->qos_data.def_qos_parm.ac[i].aifsn,
  592. priv->qos_data.def_qos_parm.ac[i].edca_txop);
  593. }
  594. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  595. return ret;
  596. }
  597. #ifdef CONFIG_IWLWIFI_LEDS
  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. #endif
  621. static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
  622. char __user *user_buf,
  623. size_t count, loff_t *ppos)
  624. {
  625. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  626. struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
  627. struct iwl_tt_restriction *restriction;
  628. char buf[100];
  629. int pos = 0;
  630. const size_t bufsz = sizeof(buf);
  631. ssize_t ret;
  632. pos += scnprintf(buf + pos, bufsz - pos,
  633. "Thermal Throttling Mode: %s\n",
  634. tt->advanced_tt ? "Advance" : "Legacy");
  635. pos += scnprintf(buf + pos, bufsz - pos,
  636. "Thermal Throttling State: %d\n",
  637. tt->state);
  638. if (tt->advanced_tt) {
  639. restriction = tt->restriction + tt->state;
  640. pos += scnprintf(buf + pos, bufsz - pos,
  641. "Tx mode: %d\n",
  642. restriction->tx_stream);
  643. pos += scnprintf(buf + pos, bufsz - pos,
  644. "Rx mode: %d\n",
  645. restriction->rx_stream);
  646. pos += scnprintf(buf + pos, bufsz - pos,
  647. "HT mode: %d\n",
  648. restriction->is_ht);
  649. }
  650. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  651. return ret;
  652. }
  653. static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
  654. const char __user *user_buf,
  655. size_t count, loff_t *ppos)
  656. {
  657. struct iwl_priv *priv = file->private_data;
  658. char buf[8];
  659. int buf_size;
  660. int ht40;
  661. memset(buf, 0, sizeof(buf));
  662. buf_size = min(count, sizeof(buf) - 1);
  663. if (copy_from_user(buf, user_buf, buf_size))
  664. return -EFAULT;
  665. if (sscanf(buf, "%d", &ht40) != 1)
  666. return -EFAULT;
  667. if (!iwl_is_associated(priv))
  668. priv->disable_ht40 = ht40 ? true : false;
  669. else {
  670. IWL_ERR(priv, "Sta associated with AP - "
  671. "Change to 40MHz channel support is not allowed\n");
  672. return -EINVAL;
  673. }
  674. return count;
  675. }
  676. static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
  677. char __user *user_buf,
  678. size_t count, loff_t *ppos)
  679. {
  680. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  681. char buf[100];
  682. int pos = 0;
  683. const size_t bufsz = sizeof(buf);
  684. ssize_t ret;
  685. pos += scnprintf(buf + pos, bufsz - pos,
  686. "11n 40MHz Mode: %s\n",
  687. priv->disable_ht40 ? "Disabled" : "Enabled");
  688. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  689. return ret;
  690. }
  691. static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
  692. const char __user *user_buf,
  693. size_t count, loff_t *ppos)
  694. {
  695. struct iwl_priv *priv = file->private_data;
  696. char buf[8];
  697. int buf_size;
  698. int value;
  699. memset(buf, 0, sizeof(buf));
  700. buf_size = min(count, sizeof(buf) - 1);
  701. if (copy_from_user(buf, user_buf, buf_size))
  702. return -EFAULT;
  703. if (sscanf(buf, "%d", &value) != 1)
  704. return -EINVAL;
  705. /*
  706. * Our users expect 0 to be "CAM", but 0 isn't actually
  707. * valid here. However, let's not confuse them and present
  708. * IWL_POWER_INDEX_1 as "1", not "0".
  709. */
  710. if (value > 0)
  711. value -= 1;
  712. if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
  713. return -EINVAL;
  714. priv->power_data.debug_sleep_level_override = value;
  715. iwl_power_update_mode(priv, false);
  716. return count;
  717. }
  718. static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
  719. char __user *user_buf,
  720. size_t count, loff_t *ppos)
  721. {
  722. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  723. char buf[10];
  724. int pos, value;
  725. const size_t bufsz = sizeof(buf);
  726. /* see the write function */
  727. value = priv->power_data.debug_sleep_level_override;
  728. if (value >= 0)
  729. value += 1;
  730. pos = scnprintf(buf, bufsz, "%d\n", value);
  731. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  732. }
  733. static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
  734. char __user *user_buf,
  735. size_t count, loff_t *ppos)
  736. {
  737. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  738. char buf[200];
  739. int pos = 0, i;
  740. const size_t bufsz = sizeof(buf);
  741. struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
  742. pos += scnprintf(buf + pos, bufsz - pos,
  743. "flags: %#.2x\n", le16_to_cpu(cmd->flags));
  744. pos += scnprintf(buf + pos, bufsz - pos,
  745. "RX/TX timeout: %d/%d usec\n",
  746. le32_to_cpu(cmd->rx_data_timeout),
  747. le32_to_cpu(cmd->tx_data_timeout));
  748. for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
  749. pos += scnprintf(buf + pos, bufsz - pos,
  750. "sleep_interval[%d]: %d\n", i,
  751. le32_to_cpu(cmd->sleep_interval[i]));
  752. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  753. }
  754. DEBUGFS_READ_WRITE_FILE_OPS(sram);
  755. DEBUGFS_WRITE_FILE_OPS(log_event);
  756. DEBUGFS_READ_FILE_OPS(nvm);
  757. DEBUGFS_READ_FILE_OPS(stations);
  758. DEBUGFS_READ_FILE_OPS(channels);
  759. DEBUGFS_READ_FILE_OPS(status);
  760. DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
  761. DEBUGFS_READ_FILE_OPS(qos);
  762. #ifdef CONFIG_IWLWIFI_LEDS
  763. DEBUGFS_READ_FILE_OPS(led);
  764. #endif
  765. DEBUGFS_READ_FILE_OPS(thermal_throttling);
  766. DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
  767. DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
  768. DEBUGFS_READ_FILE_OPS(current_sleep_command);
  769. static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
  770. char __user *user_buf,
  771. size_t count, loff_t *ppos)
  772. {
  773. struct iwl_priv *priv = file->private_data;
  774. int pos = 0, ofs = 0;
  775. int cnt = 0, entry;
  776. struct iwl_tx_queue *txq;
  777. struct iwl_queue *q;
  778. struct iwl_rx_queue *rxq = &priv->rxq;
  779. char *buf;
  780. int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
  781. (IWL_MAX_NUM_QUEUES * 32 * 8) + 400;
  782. const u8 *ptr;
  783. ssize_t ret;
  784. buf = kzalloc(bufsz, GFP_KERNEL);
  785. if (!buf) {
  786. IWL_ERR(priv, "Can not allocate buffer\n");
  787. return -ENOMEM;
  788. }
  789. pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
  790. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  791. txq = &priv->txq[cnt];
  792. q = &txq->q;
  793. pos += scnprintf(buf + pos, bufsz - pos,
  794. "q[%d]: read_ptr: %u, write_ptr: %u\n",
  795. cnt, q->read_ptr, q->write_ptr);
  796. }
  797. if (priv->tx_traffic && (iwl_debug_level & IWL_DL_TX)) {
  798. ptr = priv->tx_traffic;
  799. pos += scnprintf(buf + pos, bufsz - pos,
  800. "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
  801. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  802. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  803. entry++, ofs += 16) {
  804. pos += scnprintf(buf + pos, bufsz - pos,
  805. "0x%.4x ", ofs);
  806. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  807. buf + pos, bufsz - pos, 0);
  808. pos += strlen(buf + pos);
  809. if (bufsz - pos > 0)
  810. buf[pos++] = '\n';
  811. }
  812. }
  813. }
  814. pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
  815. pos += scnprintf(buf + pos, bufsz - pos,
  816. "read: %u, write: %u\n",
  817. rxq->read, rxq->write);
  818. if (priv->rx_traffic && (iwl_debug_level & IWL_DL_RX)) {
  819. ptr = priv->rx_traffic;
  820. pos += scnprintf(buf + pos, bufsz - pos,
  821. "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
  822. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  823. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  824. entry++, ofs += 16) {
  825. pos += scnprintf(buf + pos, bufsz - pos,
  826. "0x%.4x ", ofs);
  827. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  828. buf + pos, bufsz - pos, 0);
  829. pos += strlen(buf + pos);
  830. if (bufsz - pos > 0)
  831. buf[pos++] = '\n';
  832. }
  833. }
  834. }
  835. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  836. kfree(buf);
  837. return ret;
  838. }
  839. static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
  840. const char __user *user_buf,
  841. size_t count, loff_t *ppos)
  842. {
  843. struct iwl_priv *priv = file->private_data;
  844. char buf[8];
  845. int buf_size;
  846. int traffic_log;
  847. memset(buf, 0, sizeof(buf));
  848. buf_size = min(count, sizeof(buf) - 1);
  849. if (copy_from_user(buf, user_buf, buf_size))
  850. return -EFAULT;
  851. if (sscanf(buf, "%d", &traffic_log) != 1)
  852. return -EFAULT;
  853. if (traffic_log == 0)
  854. iwl_reset_traffic_log(priv);
  855. return count;
  856. }
  857. static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
  858. char __user *user_buf,
  859. size_t count, loff_t *ppos) {
  860. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  861. struct iwl_tx_queue *txq;
  862. struct iwl_queue *q;
  863. char *buf;
  864. int pos = 0;
  865. int cnt;
  866. int ret;
  867. const size_t bufsz = sizeof(char) * 60 * IWL_MAX_NUM_QUEUES;
  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,
  880. txq->swq_id & 0x80 ? txq->swq_id & 3 :
  881. txq->swq_id,
  882. txq->swq_id & 0x80 ? (txq->swq_id >> 2) &
  883. 0x1f : txq->swq_id);
  884. if (cnt >= 4)
  885. continue;
  886. /* for the ACs, display the stop count too */
  887. pos += scnprintf(buf + pos, bufsz - pos,
  888. " stop-count: %d\n",
  889. atomic_read(&priv->queue_stop_count[cnt]));
  890. }
  891. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  892. kfree(buf);
  893. return ret;
  894. }
  895. static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
  896. char __user *user_buf,
  897. size_t count, loff_t *ppos) {
  898. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  899. struct iwl_rx_queue *rxq = &priv->rxq;
  900. char buf[256];
  901. int pos = 0;
  902. const size_t bufsz = sizeof(buf);
  903. pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
  904. rxq->read);
  905. pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
  906. rxq->write);
  907. pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
  908. rxq->free_count);
  909. pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
  910. le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
  911. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  912. }
  913. #define UCODE_STATISTICS_CLEAR_MSK (0x1 << 0)
  914. #define UCODE_STATISTICS_FREQUENCY_MSK (0x1 << 1)
  915. #define UCODE_STATISTICS_NARROW_BAND_MSK (0x1 << 2)
  916. static int iwl_dbgfs_statistics_flag(struct iwl_priv *priv, char *buf,
  917. int bufsz)
  918. {
  919. int p = 0;
  920. p += scnprintf(buf + p, bufsz - p,
  921. "Statistics Flag(0x%X):\n",
  922. le32_to_cpu(priv->statistics.flag));
  923. if (le32_to_cpu(priv->statistics.flag) & UCODE_STATISTICS_CLEAR_MSK)
  924. p += scnprintf(buf + p, bufsz - p,
  925. "\tStatistics have been cleared\n");
  926. p += scnprintf(buf + p, bufsz - p,
  927. "\tOperational Frequency: %s\n",
  928. (le32_to_cpu(priv->statistics.flag) &
  929. UCODE_STATISTICS_FREQUENCY_MSK)
  930. ? "2.4 GHz" : "5.2 GHz");
  931. p += scnprintf(buf + p, bufsz - p,
  932. "\tTGj Narrow Band: %s\n",
  933. (le32_to_cpu(priv->statistics.flag) &
  934. UCODE_STATISTICS_NARROW_BAND_MSK)
  935. ? "enabled" : "disabled");
  936. return p;
  937. }
  938. static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
  939. char __user *user_buf,
  940. size_t count, loff_t *ppos)
  941. {
  942. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  943. int pos = 0;
  944. char *buf;
  945. int bufsz = sizeof(struct statistics_rx_phy) * 20 +
  946. sizeof(struct statistics_rx_non_phy) * 20 +
  947. sizeof(struct statistics_rx_ht_phy) * 20 + 400;
  948. ssize_t ret;
  949. struct statistics_rx_phy *ofdm;
  950. struct statistics_rx_phy *cck;
  951. struct statistics_rx_non_phy *general;
  952. struct statistics_rx_ht_phy *ht;
  953. if (!iwl_is_alive(priv))
  954. return -EAGAIN;
  955. /* make request to uCode to retrieve statistics information */
  956. mutex_lock(&priv->mutex);
  957. ret = iwl_send_statistics_request(priv, 0);
  958. mutex_unlock(&priv->mutex);
  959. if (ret) {
  960. IWL_ERR(priv,
  961. "Error sending statistics request: %zd\n", ret);
  962. return -EAGAIN;
  963. }
  964. buf = kzalloc(bufsz, GFP_KERNEL);
  965. if (!buf) {
  966. IWL_ERR(priv, "Can not allocate Buffer\n");
  967. return -ENOMEM;
  968. }
  969. /* the statistic information display here is based on
  970. * the last statistics notification from uCode
  971. * might not reflect the current uCode activity
  972. */
  973. ofdm = &priv->statistics.rx.ofdm;
  974. cck = &priv->statistics.rx.cck;
  975. general = &priv->statistics.rx.general;
  976. ht = &priv->statistics.rx.ofdm_ht;
  977. pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
  978. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - OFDM:\n");
  979. pos += scnprintf(buf + pos, bufsz - pos, "ina_cnt: %u\n",
  980. le32_to_cpu(ofdm->ina_cnt));
  981. pos += scnprintf(buf + pos, bufsz - pos, "fina_cnt: %u\n",
  982. le32_to_cpu(ofdm->fina_cnt));
  983. pos += scnprintf(buf + pos, bufsz - pos, "plcp_err: %u\n",
  984. le32_to_cpu(ofdm->plcp_err));
  985. pos += scnprintf(buf + pos, bufsz - pos, "crc32_err: %u\n",
  986. le32_to_cpu(ofdm->crc32_err));
  987. pos += scnprintf(buf + pos, bufsz - pos, "overrun_err: %u\n",
  988. le32_to_cpu(ofdm->overrun_err));
  989. pos += scnprintf(buf + pos, bufsz - pos, "early_overrun_err: %u\n",
  990. le32_to_cpu(ofdm->early_overrun_err));
  991. pos += scnprintf(buf + pos, bufsz - pos, "crc32_good: %u\n",
  992. le32_to_cpu(ofdm->crc32_good));
  993. pos += scnprintf(buf + pos, bufsz - pos, "false_alarm_cnt: %u\n",
  994. le32_to_cpu(ofdm->false_alarm_cnt));
  995. pos += scnprintf(buf + pos, bufsz - pos, "fina_sync_err_cnt: %u\n",
  996. le32_to_cpu(ofdm->fina_sync_err_cnt));
  997. pos += scnprintf(buf + pos, bufsz - pos, "sfd_timeout: %u\n",
  998. le32_to_cpu(ofdm->sfd_timeout));
  999. pos += scnprintf(buf + pos, bufsz - pos, "fina_timeout: %u\n",
  1000. le32_to_cpu(ofdm->fina_timeout));
  1001. pos += scnprintf(buf + pos, bufsz - pos, "unresponded_rts: %u\n",
  1002. le32_to_cpu(ofdm->unresponded_rts));
  1003. pos += scnprintf(buf + pos, bufsz - pos,
  1004. "rxe_frame_limit_overrun: %u\n",
  1005. le32_to_cpu(ofdm->rxe_frame_limit_overrun));
  1006. pos += scnprintf(buf + pos, bufsz - pos, "sent_ack_cnt: %u\n",
  1007. le32_to_cpu(ofdm->sent_ack_cnt));
  1008. pos += scnprintf(buf + pos, bufsz - pos, "sent_cts_cnt: %u\n",
  1009. le32_to_cpu(ofdm->sent_cts_cnt));
  1010. pos += scnprintf(buf + pos, bufsz - pos, "sent_ba_rsp_cnt: %u\n",
  1011. le32_to_cpu(ofdm->sent_ba_rsp_cnt));
  1012. pos += scnprintf(buf + pos, bufsz - pos, "dsp_self_kill: %u\n",
  1013. le32_to_cpu(ofdm->dsp_self_kill));
  1014. pos += scnprintf(buf + pos, bufsz - pos, "mh_format_err: %u\n",
  1015. le32_to_cpu(ofdm->mh_format_err));
  1016. pos += scnprintf(buf + pos, bufsz - pos, "re_acq_main_rssi_sum: %u\n",
  1017. le32_to_cpu(ofdm->re_acq_main_rssi_sum));
  1018. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - CCK:\n");
  1019. pos += scnprintf(buf + pos, bufsz - pos, "ina_cnt: %u\n",
  1020. le32_to_cpu(cck->ina_cnt));
  1021. pos += scnprintf(buf + pos, bufsz - pos, "fina_cnt: %u\n",
  1022. le32_to_cpu(cck->fina_cnt));
  1023. pos += scnprintf(buf + pos, bufsz - pos, "plcp_err: %u\n",
  1024. le32_to_cpu(cck->plcp_err));
  1025. pos += scnprintf(buf + pos, bufsz - pos, "crc32_err: %u\n",
  1026. le32_to_cpu(cck->crc32_err));
  1027. pos += scnprintf(buf + pos, bufsz - pos, "overrun_err: %u\n",
  1028. le32_to_cpu(cck->overrun_err));
  1029. pos += scnprintf(buf + pos, bufsz - pos, "early_overrun_err: %u\n",
  1030. le32_to_cpu(cck->early_overrun_err));
  1031. pos += scnprintf(buf + pos, bufsz - pos, "crc32_good: %u\n",
  1032. le32_to_cpu(cck->crc32_good));
  1033. pos += scnprintf(buf + pos, bufsz - pos, "false_alarm_cnt: %u\n",
  1034. le32_to_cpu(cck->false_alarm_cnt));
  1035. pos += scnprintf(buf + pos, bufsz - pos, "fina_sync_err_cnt: %u\n",
  1036. le32_to_cpu(cck->fina_sync_err_cnt));
  1037. pos += scnprintf(buf + pos, bufsz - pos, "sfd_timeout: %u\n",
  1038. le32_to_cpu(cck->sfd_timeout));
  1039. pos += scnprintf(buf + pos, bufsz - pos, "fina_timeout: %u\n",
  1040. le32_to_cpu(cck->fina_timeout));
  1041. pos += scnprintf(buf + pos, bufsz - pos, "unresponded_rts: %u\n",
  1042. le32_to_cpu(cck->unresponded_rts));
  1043. pos += scnprintf(buf + pos, bufsz - pos,
  1044. "rxe_frame_limit_overrun: %u\n",
  1045. le32_to_cpu(cck->rxe_frame_limit_overrun));
  1046. pos += scnprintf(buf + pos, bufsz - pos, "sent_ack_cnt: %u\n",
  1047. le32_to_cpu(cck->sent_ack_cnt));
  1048. pos += scnprintf(buf + pos, bufsz - pos, "sent_cts_cnt: %u\n",
  1049. le32_to_cpu(cck->sent_cts_cnt));
  1050. pos += scnprintf(buf + pos, bufsz - pos, "sent_ba_rsp_cnt: %u\n",
  1051. le32_to_cpu(cck->sent_ba_rsp_cnt));
  1052. pos += scnprintf(buf + pos, bufsz - pos, "dsp_self_kill: %u\n",
  1053. le32_to_cpu(cck->dsp_self_kill));
  1054. pos += scnprintf(buf + pos, bufsz - pos, "mh_format_err: %u\n",
  1055. le32_to_cpu(cck->mh_format_err));
  1056. pos += scnprintf(buf + pos, bufsz - pos, "re_acq_main_rssi_sum: %u\n",
  1057. le32_to_cpu(cck->re_acq_main_rssi_sum));
  1058. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - GENERAL:\n");
  1059. pos += scnprintf(buf + pos, bufsz - pos, "bogus_cts: %u\n",
  1060. le32_to_cpu(general->bogus_cts));
  1061. pos += scnprintf(buf + pos, bufsz - pos, "bogus_ack: %u\n",
  1062. le32_to_cpu(general->bogus_ack));
  1063. pos += scnprintf(buf + pos, bufsz - pos, "non_bssid_frames: %u\n",
  1064. le32_to_cpu(general->non_bssid_frames));
  1065. pos += scnprintf(buf + pos, bufsz - pos, "filtered_frames: %u\n",
  1066. le32_to_cpu(general->filtered_frames));
  1067. pos += scnprintf(buf + pos, bufsz - pos, "non_channel_beacons: %u\n",
  1068. le32_to_cpu(general->non_channel_beacons));
  1069. pos += scnprintf(buf + pos, bufsz - pos, "channel_beacons: %u\n",
  1070. le32_to_cpu(general->channel_beacons));
  1071. pos += scnprintf(buf + pos, bufsz - pos, "num_missed_bcon: %u\n",
  1072. le32_to_cpu(general->num_missed_bcon));
  1073. pos += scnprintf(buf + pos, bufsz - pos,
  1074. "adc_rx_saturation_time: %u\n",
  1075. le32_to_cpu(general->adc_rx_saturation_time));
  1076. pos += scnprintf(buf + pos, bufsz - pos,
  1077. "ina_detection_search_time: %u\n",
  1078. le32_to_cpu(general->ina_detection_search_time));
  1079. pos += scnprintf(buf + pos, bufsz - pos, "beacon_silence_rssi_a: %u\n",
  1080. le32_to_cpu(general->beacon_silence_rssi_a));
  1081. pos += scnprintf(buf + pos, bufsz - pos, "beacon_silence_rssi_b: %u\n",
  1082. le32_to_cpu(general->beacon_silence_rssi_b));
  1083. pos += scnprintf(buf + pos, bufsz - pos, "beacon_silence_rssi_c: %u\n",
  1084. le32_to_cpu(general->beacon_silence_rssi_c));
  1085. pos += scnprintf(buf + pos, bufsz - pos,
  1086. "interference_data_flag: %u\n",
  1087. le32_to_cpu(general->interference_data_flag));
  1088. pos += scnprintf(buf + pos, bufsz - pos, "channel_load: %u\n",
  1089. le32_to_cpu(general->channel_load));
  1090. pos += scnprintf(buf + pos, bufsz - pos, "dsp_false_alarms: %u\n",
  1091. le32_to_cpu(general->dsp_false_alarms));
  1092. pos += scnprintf(buf + pos, bufsz - pos, "beacon_rssi_a: %u\n",
  1093. le32_to_cpu(general->beacon_rssi_a));
  1094. pos += scnprintf(buf + pos, bufsz - pos, "beacon_rssi_b: %u\n",
  1095. le32_to_cpu(general->beacon_rssi_b));
  1096. pos += scnprintf(buf + pos, bufsz - pos, "beacon_rssi_c: %u\n",
  1097. le32_to_cpu(general->beacon_rssi_c));
  1098. pos += scnprintf(buf + pos, bufsz - pos, "beacon_energy_a: %u\n",
  1099. le32_to_cpu(general->beacon_energy_a));
  1100. pos += scnprintf(buf + pos, bufsz - pos, "beacon_energy_b: %u\n",
  1101. le32_to_cpu(general->beacon_energy_b));
  1102. pos += scnprintf(buf + pos, bufsz - pos, "beacon_energy_c: %u\n",
  1103. le32_to_cpu(general->beacon_energy_c));
  1104. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - OFDM_HT:\n");
  1105. pos += scnprintf(buf + pos, bufsz - pos, "plcp_err: %u\n",
  1106. le32_to_cpu(ht->plcp_err));
  1107. pos += scnprintf(buf + pos, bufsz - pos, "overrun_err: %u\n",
  1108. le32_to_cpu(ht->overrun_err));
  1109. pos += scnprintf(buf + pos, bufsz - pos, "early_overrun_err: %u\n",
  1110. le32_to_cpu(ht->early_overrun_err));
  1111. pos += scnprintf(buf + pos, bufsz - pos, "crc32_good: %u\n",
  1112. le32_to_cpu(ht->crc32_good));
  1113. pos += scnprintf(buf + pos, bufsz - pos, "crc32_err: %u\n",
  1114. le32_to_cpu(ht->crc32_err));
  1115. pos += scnprintf(buf + pos, bufsz - pos, "mh_format_err: %u\n",
  1116. le32_to_cpu(ht->mh_format_err));
  1117. pos += scnprintf(buf + pos, bufsz - pos, "agg_crc32_good: %u\n",
  1118. le32_to_cpu(ht->agg_crc32_good));
  1119. pos += scnprintf(buf + pos, bufsz - pos, "agg_mpdu_cnt: %u\n",
  1120. le32_to_cpu(ht->agg_mpdu_cnt));
  1121. pos += scnprintf(buf + pos, bufsz - pos, "agg_cnt: %u\n",
  1122. le32_to_cpu(ht->agg_cnt));
  1123. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1124. kfree(buf);
  1125. return ret;
  1126. }
  1127. static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
  1128. char __user *user_buf,
  1129. size_t count, loff_t *ppos)
  1130. {
  1131. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1132. int pos = 0;
  1133. char *buf;
  1134. int bufsz = (sizeof(struct statistics_tx) * 24) + 250;
  1135. ssize_t ret;
  1136. struct statistics_tx *tx;
  1137. if (!iwl_is_alive(priv))
  1138. return -EAGAIN;
  1139. /* make request to uCode to retrieve statistics information */
  1140. mutex_lock(&priv->mutex);
  1141. ret = iwl_send_statistics_request(priv, 0);
  1142. mutex_unlock(&priv->mutex);
  1143. if (ret) {
  1144. IWL_ERR(priv,
  1145. "Error sending statistics request: %zd\n", ret);
  1146. return -EAGAIN;
  1147. }
  1148. buf = kzalloc(bufsz, GFP_KERNEL);
  1149. if (!buf) {
  1150. IWL_ERR(priv, "Can not allocate Buffer\n");
  1151. return -ENOMEM;
  1152. }
  1153. /* the statistic information display here is based on
  1154. * the last statistics notification from uCode
  1155. * might not reflect the current uCode activity
  1156. */
  1157. tx = &priv->statistics.tx;
  1158. pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
  1159. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Tx:\n");
  1160. pos += scnprintf(buf + pos, bufsz - pos, "preamble: %u\n",
  1161. le32_to_cpu(tx->preamble_cnt));
  1162. pos += scnprintf(buf + pos, bufsz - pos, "rx_detected_cnt: %u\n",
  1163. le32_to_cpu(tx->rx_detected_cnt));
  1164. pos += scnprintf(buf + pos, bufsz - pos, "bt_prio_defer_cnt: %u\n",
  1165. le32_to_cpu(tx->bt_prio_defer_cnt));
  1166. pos += scnprintf(buf + pos, bufsz - pos, "bt_prio_kill_cnt: %u\n",
  1167. le32_to_cpu(tx->bt_prio_kill_cnt));
  1168. pos += scnprintf(buf + pos, bufsz - pos, "few_bytes_cnt: %u\n",
  1169. le32_to_cpu(tx->few_bytes_cnt));
  1170. pos += scnprintf(buf + pos, bufsz - pos, "cts_timeout: %u\n",
  1171. le32_to_cpu(tx->cts_timeout));
  1172. pos += scnprintf(buf + pos, bufsz - pos, "ack_timeout: %u\n",
  1173. le32_to_cpu(tx->ack_timeout));
  1174. pos += scnprintf(buf + pos, bufsz - pos, "expected_ack_cnt: %u\n",
  1175. le32_to_cpu(tx->expected_ack_cnt));
  1176. pos += scnprintf(buf + pos, bufsz - pos, "actual_ack_cnt: %u\n",
  1177. le32_to_cpu(tx->actual_ack_cnt));
  1178. pos += scnprintf(buf + pos, bufsz - pos, "dump_msdu_cnt: %u\n",
  1179. le32_to_cpu(tx->dump_msdu_cnt));
  1180. pos += scnprintf(buf + pos, bufsz - pos,
  1181. "burst_abort_next_frame_mismatch_cnt: %u\n",
  1182. le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt));
  1183. pos += scnprintf(buf + pos, bufsz - pos,
  1184. "burst_abort_missing_next_frame_cnt: %u\n",
  1185. le32_to_cpu(tx->burst_abort_missing_next_frame_cnt));
  1186. pos += scnprintf(buf + pos, bufsz - pos, "cts_timeout_collision: %u\n",
  1187. le32_to_cpu(tx->cts_timeout_collision));
  1188. pos += scnprintf(buf + pos, bufsz - pos,
  1189. "ack_or_ba_timeout_collision: %u\n",
  1190. le32_to_cpu(tx->ack_or_ba_timeout_collision));
  1191. pos += scnprintf(buf + pos, bufsz - pos, "agg ba_timeout: %u\n",
  1192. le32_to_cpu(tx->agg.ba_timeout));
  1193. pos += scnprintf(buf + pos, bufsz - pos,
  1194. "agg ba_reschedule_frames: %u\n",
  1195. le32_to_cpu(tx->agg.ba_reschedule_frames));
  1196. pos += scnprintf(buf + pos, bufsz - pos,
  1197. "agg scd_query_agg_frame_cnt: %u\n",
  1198. le32_to_cpu(tx->agg.scd_query_agg_frame_cnt));
  1199. pos += scnprintf(buf + pos, bufsz - pos, "agg scd_query_no_agg: %u\n",
  1200. le32_to_cpu(tx->agg.scd_query_no_agg));
  1201. pos += scnprintf(buf + pos, bufsz - pos, "agg scd_query_agg: %u\n",
  1202. le32_to_cpu(tx->agg.scd_query_agg));
  1203. pos += scnprintf(buf + pos, bufsz - pos,
  1204. "agg scd_query_mismatch: %u\n",
  1205. le32_to_cpu(tx->agg.scd_query_mismatch));
  1206. pos += scnprintf(buf + pos, bufsz - pos, "agg frame_not_ready: %u\n",
  1207. le32_to_cpu(tx->agg.frame_not_ready));
  1208. pos += scnprintf(buf + pos, bufsz - pos, "agg underrun: %u\n",
  1209. le32_to_cpu(tx->agg.underrun));
  1210. pos += scnprintf(buf + pos, bufsz - pos, "agg bt_prio_kill: %u\n",
  1211. le32_to_cpu(tx->agg.bt_prio_kill));
  1212. pos += scnprintf(buf + pos, bufsz - pos, "agg rx_ba_rsp_cnt: %u\n",
  1213. le32_to_cpu(tx->agg.rx_ba_rsp_cnt));
  1214. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1215. kfree(buf);
  1216. return ret;
  1217. }
  1218. static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
  1219. char __user *user_buf,
  1220. size_t count, loff_t *ppos)
  1221. {
  1222. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1223. int pos = 0;
  1224. char *buf;
  1225. int bufsz = sizeof(struct statistics_general) * 4 + 250;
  1226. ssize_t ret;
  1227. struct statistics_general *general;
  1228. struct statistics_dbg *dbg;
  1229. struct statistics_div *div;
  1230. if (!iwl_is_alive(priv))
  1231. return -EAGAIN;
  1232. /* make request to uCode to retrieve statistics information */
  1233. mutex_lock(&priv->mutex);
  1234. ret = iwl_send_statistics_request(priv, 0);
  1235. mutex_unlock(&priv->mutex);
  1236. if (ret) {
  1237. IWL_ERR(priv,
  1238. "Error sending statistics request: %zd\n", ret);
  1239. return -EAGAIN;
  1240. }
  1241. buf = kzalloc(bufsz, GFP_KERNEL);
  1242. if (!buf) {
  1243. IWL_ERR(priv, "Can not allocate Buffer\n");
  1244. return -ENOMEM;
  1245. }
  1246. /* the statistic information display here is based on
  1247. * the last statistics notification from uCode
  1248. * might not reflect the current uCode activity
  1249. */
  1250. general = &priv->statistics.general;
  1251. dbg = &priv->statistics.general.dbg;
  1252. div = &priv->statistics.general.div;
  1253. pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
  1254. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_General:\n");
  1255. pos += scnprintf(buf + pos, bufsz - pos, "temperature: %u\n",
  1256. le32_to_cpu(general->temperature));
  1257. pos += scnprintf(buf + pos, bufsz - pos, "temperature_m: %u\n",
  1258. le32_to_cpu(general->temperature_m));
  1259. pos += scnprintf(buf + pos, bufsz - pos, "burst_check: %u\n",
  1260. le32_to_cpu(dbg->burst_check));
  1261. pos += scnprintf(buf + pos, bufsz - pos, "burst_count: %u\n",
  1262. le32_to_cpu(dbg->burst_count));
  1263. pos += scnprintf(buf + pos, bufsz - pos, "sleep_time: %u\n",
  1264. le32_to_cpu(general->sleep_time));
  1265. pos += scnprintf(buf + pos, bufsz - pos, "slots_out: %u\n",
  1266. le32_to_cpu(general->slots_out));
  1267. pos += scnprintf(buf + pos, bufsz - pos, "slots_idle: %u\n",
  1268. le32_to_cpu(general->slots_idle));
  1269. pos += scnprintf(buf + pos, bufsz - pos, "ttl_timestamp: %u\n",
  1270. le32_to_cpu(general->ttl_timestamp));
  1271. pos += scnprintf(buf + pos, bufsz - pos, "tx_on_a: %u\n",
  1272. le32_to_cpu(div->tx_on_a));
  1273. pos += scnprintf(buf + pos, bufsz - pos, "tx_on_b: %u\n",
  1274. le32_to_cpu(div->tx_on_b));
  1275. pos += scnprintf(buf + pos, bufsz - pos, "exec_time: %u\n",
  1276. le32_to_cpu(div->exec_time));
  1277. pos += scnprintf(buf + pos, bufsz - pos, "probe_time: %u\n",
  1278. le32_to_cpu(div->probe_time));
  1279. pos += scnprintf(buf + pos, bufsz - pos, "rx_enable_counter: %u\n",
  1280. le32_to_cpu(general->rx_enable_counter));
  1281. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1282. kfree(buf);
  1283. return ret;
  1284. }
  1285. static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
  1286. char __user *user_buf,
  1287. size_t count, loff_t *ppos) {
  1288. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1289. int pos = 0;
  1290. int cnt = 0;
  1291. char *buf;
  1292. int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
  1293. ssize_t ret;
  1294. struct iwl_sensitivity_data *data;
  1295. data = &priv->sensitivity_data;
  1296. buf = kzalloc(bufsz, GFP_KERNEL);
  1297. if (!buf) {
  1298. IWL_ERR(priv, "Can not allocate Buffer\n");
  1299. return -ENOMEM;
  1300. }
  1301. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
  1302. data->auto_corr_ofdm);
  1303. pos += scnprintf(buf + pos, bufsz - pos,
  1304. "auto_corr_ofdm_mrc:\t\t %u\n",
  1305. data->auto_corr_ofdm_mrc);
  1306. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
  1307. data->auto_corr_ofdm_x1);
  1308. pos += scnprintf(buf + pos, bufsz - pos,
  1309. "auto_corr_ofdm_mrc_x1:\t\t %u\n",
  1310. data->auto_corr_ofdm_mrc_x1);
  1311. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
  1312. data->auto_corr_cck);
  1313. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
  1314. data->auto_corr_cck_mrc);
  1315. pos += scnprintf(buf + pos, bufsz - pos,
  1316. "last_bad_plcp_cnt_ofdm:\t\t %u\n",
  1317. data->last_bad_plcp_cnt_ofdm);
  1318. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
  1319. data->last_fa_cnt_ofdm);
  1320. pos += scnprintf(buf + pos, bufsz - pos,
  1321. "last_bad_plcp_cnt_cck:\t\t %u\n",
  1322. data->last_bad_plcp_cnt_cck);
  1323. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
  1324. data->last_fa_cnt_cck);
  1325. pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
  1326. data->nrg_curr_state);
  1327. pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
  1328. data->nrg_prev_state);
  1329. pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
  1330. for (cnt = 0; cnt < 10; cnt++) {
  1331. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1332. data->nrg_value[cnt]);
  1333. }
  1334. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1335. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
  1336. for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
  1337. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1338. data->nrg_silence_rssi[cnt]);
  1339. }
  1340. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1341. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
  1342. data->nrg_silence_ref);
  1343. pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
  1344. data->nrg_energy_idx);
  1345. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
  1346. data->nrg_silence_idx);
  1347. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
  1348. data->nrg_th_cck);
  1349. pos += scnprintf(buf + pos, bufsz - pos,
  1350. "nrg_auto_corr_silence_diff:\t %u\n",
  1351. data->nrg_auto_corr_silence_diff);
  1352. pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
  1353. data->num_in_cck_no_fa);
  1354. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
  1355. data->nrg_th_ofdm);
  1356. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1357. kfree(buf);
  1358. return ret;
  1359. }
  1360. static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
  1361. char __user *user_buf,
  1362. size_t count, loff_t *ppos) {
  1363. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1364. int pos = 0;
  1365. int cnt = 0;
  1366. char *buf;
  1367. int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
  1368. ssize_t ret;
  1369. struct iwl_chain_noise_data *data;
  1370. data = &priv->chain_noise_data;
  1371. buf = kzalloc(bufsz, GFP_KERNEL);
  1372. if (!buf) {
  1373. IWL_ERR(priv, "Can not allocate Buffer\n");
  1374. return -ENOMEM;
  1375. }
  1376. pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
  1377. data->active_chains);
  1378. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
  1379. data->chain_noise_a);
  1380. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
  1381. data->chain_noise_b);
  1382. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
  1383. data->chain_noise_c);
  1384. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
  1385. data->chain_signal_a);
  1386. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
  1387. data->chain_signal_b);
  1388. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
  1389. data->chain_signal_c);
  1390. pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
  1391. data->beacon_count);
  1392. pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
  1393. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1394. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1395. data->disconn_array[cnt]);
  1396. }
  1397. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1398. pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
  1399. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1400. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1401. data->delta_gain_code[cnt]);
  1402. }
  1403. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1404. pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
  1405. data->radio_write);
  1406. pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
  1407. data->state);
  1408. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1409. kfree(buf);
  1410. return ret;
  1411. }
  1412. static ssize_t iwl_dbgfs_tx_power_read(struct file *file,
  1413. char __user *user_buf,
  1414. size_t count, loff_t *ppos) {
  1415. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1416. char buf[128];
  1417. int pos = 0;
  1418. ssize_t ret;
  1419. const size_t bufsz = sizeof(buf);
  1420. struct statistics_tx *tx;
  1421. if (!iwl_is_alive(priv))
  1422. pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
  1423. else {
  1424. /* make request to uCode to retrieve statistics information */
  1425. mutex_lock(&priv->mutex);
  1426. ret = iwl_send_statistics_request(priv, 0);
  1427. mutex_unlock(&priv->mutex);
  1428. if (ret) {
  1429. IWL_ERR(priv, "Error sending statistics request: %zd\n",
  1430. ret);
  1431. return -EAGAIN;
  1432. }
  1433. tx = &priv->statistics.tx;
  1434. if (tx->tx_power.ant_a ||
  1435. tx->tx_power.ant_b ||
  1436. tx->tx_power.ant_c) {
  1437. pos += scnprintf(buf + pos, bufsz - pos,
  1438. "tx power: (1/2 dB step)\n");
  1439. if ((priv->cfg->valid_tx_ant & ANT_A) &&
  1440. tx->tx_power.ant_a)
  1441. pos += scnprintf(buf + pos, bufsz - pos,
  1442. "\tantenna A: 0x%X\n",
  1443. tx->tx_power.ant_a);
  1444. if ((priv->cfg->valid_tx_ant & ANT_B) &&
  1445. tx->tx_power.ant_b)
  1446. pos += scnprintf(buf + pos, bufsz - pos,
  1447. "\tantenna B: 0x%X\n",
  1448. tx->tx_power.ant_b);
  1449. if ((priv->cfg->valid_tx_ant & ANT_C) &&
  1450. tx->tx_power.ant_c)
  1451. pos += scnprintf(buf + pos, bufsz - pos,
  1452. "\tantenna C: 0x%X\n",
  1453. tx->tx_power.ant_c);
  1454. } else
  1455. pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
  1456. }
  1457. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1458. }
  1459. DEBUGFS_READ_WRITE_FILE_OPS(rx_statistics);
  1460. DEBUGFS_READ_WRITE_FILE_OPS(tx_statistics);
  1461. DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
  1462. DEBUGFS_READ_FILE_OPS(rx_queue);
  1463. DEBUGFS_READ_FILE_OPS(tx_queue);
  1464. DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
  1465. DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
  1466. DEBUGFS_READ_FILE_OPS(ucode_general_stats);
  1467. DEBUGFS_READ_FILE_OPS(sensitivity);
  1468. DEBUGFS_READ_FILE_OPS(chain_noise);
  1469. DEBUGFS_READ_FILE_OPS(tx_power);
  1470. /*
  1471. * Create the debugfs files and directories
  1472. *
  1473. */
  1474. int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
  1475. {
  1476. struct iwl_debugfs *dbgfs;
  1477. struct dentry *phyd = priv->hw->wiphy->debugfsdir;
  1478. int ret = 0;
  1479. dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
  1480. if (!dbgfs) {
  1481. ret = -ENOMEM;
  1482. goto err;
  1483. }
  1484. priv->dbgfs = dbgfs;
  1485. dbgfs->name = name;
  1486. dbgfs->dir_drv = debugfs_create_dir(name, phyd);
  1487. if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)) {
  1488. ret = -ENOENT;
  1489. goto err;
  1490. }
  1491. DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
  1492. DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv);
  1493. DEBUGFS_ADD_DIR(debug, dbgfs->dir_drv);
  1494. DEBUGFS_ADD_FILE(nvm, data);
  1495. DEBUGFS_ADD_FILE(sram, data);
  1496. DEBUGFS_ADD_FILE(log_event, data);
  1497. DEBUGFS_ADD_FILE(stations, data);
  1498. DEBUGFS_ADD_FILE(channels, data);
  1499. DEBUGFS_ADD_FILE(status, data);
  1500. DEBUGFS_ADD_FILE(interrupt, data);
  1501. DEBUGFS_ADD_FILE(qos, data);
  1502. #ifdef CONFIG_IWLWIFI_LEDS
  1503. DEBUGFS_ADD_FILE(led, data);
  1504. #endif
  1505. DEBUGFS_ADD_FILE(sleep_level_override, data);
  1506. DEBUGFS_ADD_FILE(current_sleep_command, data);
  1507. DEBUGFS_ADD_FILE(thermal_throttling, data);
  1508. DEBUGFS_ADD_FILE(disable_ht40, data);
  1509. DEBUGFS_ADD_FILE(rx_statistics, debug);
  1510. DEBUGFS_ADD_FILE(tx_statistics, debug);
  1511. DEBUGFS_ADD_FILE(traffic_log, debug);
  1512. DEBUGFS_ADD_FILE(rx_queue, debug);
  1513. DEBUGFS_ADD_FILE(tx_queue, debug);
  1514. DEBUGFS_ADD_FILE(tx_power, debug);
  1515. if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) {
  1516. DEBUGFS_ADD_FILE(ucode_rx_stats, debug);
  1517. DEBUGFS_ADD_FILE(ucode_tx_stats, debug);
  1518. DEBUGFS_ADD_FILE(ucode_general_stats, debug);
  1519. DEBUGFS_ADD_FILE(sensitivity, debug);
  1520. DEBUGFS_ADD_FILE(chain_noise, debug);
  1521. }
  1522. DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
  1523. DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
  1524. &priv->disable_chain_noise_cal);
  1525. if (((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) ||
  1526. ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_3945))
  1527. DEBUGFS_ADD_BOOL(disable_tx_power, rf,
  1528. &priv->disable_tx_power_cal);
  1529. return 0;
  1530. err:
  1531. IWL_ERR(priv, "Can't open the debugfs directory\n");
  1532. iwl_dbgfs_unregister(priv);
  1533. return ret;
  1534. }
  1535. EXPORT_SYMBOL(iwl_dbgfs_register);
  1536. /**
  1537. * Remove the debugfs files and directories
  1538. *
  1539. */
  1540. void iwl_dbgfs_unregister(struct iwl_priv *priv)
  1541. {
  1542. if (!priv->dbgfs)
  1543. return;
  1544. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sleep_level_override);
  1545. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_current_sleep_command);
  1546. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_nvm);
  1547. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
  1548. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_log_event);
  1549. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
  1550. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_channels);
  1551. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_status);
  1552. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_interrupt);
  1553. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_qos);
  1554. #ifdef CONFIG_IWLWIFI_LEDS
  1555. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_led);
  1556. #endif
  1557. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_thermal_throttling);
  1558. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_disable_ht40);
  1559. DEBUGFS_REMOVE(priv->dbgfs->dir_data);
  1560. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_rx_statistics);
  1561. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_statistics);
  1562. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_traffic_log);
  1563. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_rx_queue);
  1564. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_queue);
  1565. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_power);
  1566. if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) {
  1567. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1568. file_ucode_rx_stats);
  1569. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1570. file_ucode_tx_stats);
  1571. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1572. file_ucode_general_stats);
  1573. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1574. file_sensitivity);
  1575. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
  1576. file_chain_noise);
  1577. }
  1578. DEBUGFS_REMOVE(priv->dbgfs->dir_debug);
  1579. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
  1580. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
  1581. if (((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) ||
  1582. ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_3945))
  1583. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_tx_power);
  1584. DEBUGFS_REMOVE(priv->dbgfs->dir_rf);
  1585. DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
  1586. kfree(priv->dbgfs);
  1587. priv->dbgfs = NULL;
  1588. }
  1589. EXPORT_SYMBOL(iwl_dbgfs_unregister);