iwl-debugfs.c 52 KB

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