iwl-debugfs.c 53 KB

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