debug.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2011 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/ieee80211.h>
  29. #include <net/mac80211.h>
  30. #include "common.h"
  31. /* create and remove of files */
  32. #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
  33. if (!debugfs_create_file(#name, mode, parent, il, \
  34. &il_dbgfs_##name##_ops)) \
  35. goto err; \
  36. } while (0)
  37. #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
  38. struct dentry *__tmp; \
  39. __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
  40. parent, ptr); \
  41. if (IS_ERR(__tmp) || !__tmp) \
  42. goto err; \
  43. } while (0)
  44. #define DEBUGFS_ADD_X32(name, parent, ptr) do { \
  45. struct dentry *__tmp; \
  46. __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
  47. parent, ptr); \
  48. if (IS_ERR(__tmp) || !__tmp) \
  49. goto err; \
  50. } while (0)
  51. /* file operation */
  52. #define DEBUGFS_READ_FUNC(name) \
  53. static ssize_t il_dbgfs_##name##_read(struct file *file, \
  54. char __user *user_buf, \
  55. size_t count, loff_t *ppos);
  56. #define DEBUGFS_WRITE_FUNC(name) \
  57. static ssize_t il_dbgfs_##name##_write(struct file *file, \
  58. const char __user *user_buf, \
  59. size_t count, loff_t *ppos);
  60. static int
  61. il_dbgfs_open_file_generic(struct inode *inode, struct file *file)
  62. {
  63. file->private_data = inode->i_private;
  64. return 0;
  65. }
  66. #define DEBUGFS_READ_FILE_OPS(name) \
  67. DEBUGFS_READ_FUNC(name); \
  68. static const struct file_operations il_dbgfs_##name##_ops = { \
  69. .read = il_dbgfs_##name##_read, \
  70. .open = il_dbgfs_open_file_generic, \
  71. .llseek = generic_file_llseek, \
  72. };
  73. #define DEBUGFS_WRITE_FILE_OPS(name) \
  74. DEBUGFS_WRITE_FUNC(name); \
  75. static const struct file_operations il_dbgfs_##name##_ops = { \
  76. .write = il_dbgfs_##name##_write, \
  77. .open = il_dbgfs_open_file_generic, \
  78. .llseek = generic_file_llseek, \
  79. };
  80. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  81. DEBUGFS_READ_FUNC(name); \
  82. DEBUGFS_WRITE_FUNC(name); \
  83. static const struct file_operations il_dbgfs_##name##_ops = { \
  84. .write = il_dbgfs_##name##_write, \
  85. .read = il_dbgfs_##name##_read, \
  86. .open = il_dbgfs_open_file_generic, \
  87. .llseek = generic_file_llseek, \
  88. };
  89. static ssize_t il_dbgfs_tx_stats_read(struct file *file,
  90. char __user *user_buf,
  91. size_t count, loff_t *ppos) {
  92. struct il_priv *il = file->private_data;
  93. char *buf;
  94. int pos = 0;
  95. int cnt;
  96. ssize_t ret;
  97. const size_t bufsz = 100 +
  98. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  99. buf = kzalloc(bufsz, GFP_KERNEL);
  100. if (!buf)
  101. return -ENOMEM;
  102. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  103. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  104. pos += scnprintf(buf + pos, bufsz - pos,
  105. "\t%25s\t\t: %u\n",
  106. il_get_mgmt_string(cnt),
  107. il->tx_stats.mgmt[cnt]);
  108. }
  109. pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
  110. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  111. pos += scnprintf(buf + pos, bufsz - pos,
  112. "\t%25s\t\t: %u\n",
  113. il_get_ctrl_string(cnt),
  114. il->tx_stats.ctrl[cnt]);
  115. }
  116. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  117. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  118. il->tx_stats.data_cnt);
  119. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  120. il->tx_stats.data_bytes);
  121. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  122. kfree(buf);
  123. return ret;
  124. }
  125. static ssize_t
  126. il_dbgfs_clear_traffic_stats_write(struct file *file,
  127. const char __user *user_buf,
  128. size_t count, loff_t *ppos)
  129. {
  130. struct il_priv *il = file->private_data;
  131. u32 clear_flag;
  132. char buf[8];
  133. int buf_size;
  134. memset(buf, 0, sizeof(buf));
  135. buf_size = min(count, sizeof(buf) - 1);
  136. if (copy_from_user(buf, user_buf, buf_size))
  137. return -EFAULT;
  138. if (sscanf(buf, "%x", &clear_flag) != 1)
  139. return -EFAULT;
  140. il_clear_traffic_stats(il);
  141. return count;
  142. }
  143. static ssize_t il_dbgfs_rx_stats_read(struct file *file,
  144. char __user *user_buf,
  145. size_t count, loff_t *ppos) {
  146. struct il_priv *il = file->private_data;
  147. char *buf;
  148. int pos = 0;
  149. int cnt;
  150. ssize_t ret;
  151. const size_t bufsz = 100 +
  152. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  153. buf = kzalloc(bufsz, GFP_KERNEL);
  154. if (!buf)
  155. return -ENOMEM;
  156. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  157. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  158. pos += scnprintf(buf + pos, bufsz - pos,
  159. "\t%25s\t\t: %u\n",
  160. il_get_mgmt_string(cnt),
  161. il->rx_stats.mgmt[cnt]);
  162. }
  163. pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
  164. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  165. pos += scnprintf(buf + pos, bufsz - pos,
  166. "\t%25s\t\t: %u\n",
  167. il_get_ctrl_string(cnt),
  168. il->rx_stats.ctrl[cnt]);
  169. }
  170. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  171. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  172. il->rx_stats.data_cnt);
  173. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  174. il->rx_stats.data_bytes);
  175. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  176. kfree(buf);
  177. return ret;
  178. }
  179. #define BYTE1_MASK 0x000000ff;
  180. #define BYTE2_MASK 0x0000ffff;
  181. #define BYTE3_MASK 0x00ffffff;
  182. static ssize_t il_dbgfs_sram_read(struct file *file,
  183. char __user *user_buf,
  184. size_t count, loff_t *ppos)
  185. {
  186. u32 val;
  187. char *buf;
  188. ssize_t ret;
  189. int i;
  190. int pos = 0;
  191. struct il_priv *il = file->private_data;
  192. size_t bufsz;
  193. /* default is to dump the entire data segment */
  194. if (!il->dbgfs_sram_offset && !il->dbgfs_sram_len) {
  195. il->dbgfs_sram_offset = 0x800000;
  196. if (il->ucode_type == UCODE_INIT)
  197. il->dbgfs_sram_len = il->ucode_init_data.len;
  198. else
  199. il->dbgfs_sram_len = il->ucode_data.len;
  200. }
  201. bufsz = 30 + il->dbgfs_sram_len * sizeof(char) * 10;
  202. buf = kmalloc(bufsz, GFP_KERNEL);
  203. if (!buf)
  204. return -ENOMEM;
  205. pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
  206. il->dbgfs_sram_len);
  207. pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
  208. il->dbgfs_sram_offset);
  209. for (i = il->dbgfs_sram_len; i > 0; i -= 4) {
  210. val = il_read_targ_mem(il, il->dbgfs_sram_offset + \
  211. il->dbgfs_sram_len - i);
  212. if (i < 4) {
  213. switch (i) {
  214. case 1:
  215. val &= BYTE1_MASK;
  216. break;
  217. case 2:
  218. val &= BYTE2_MASK;
  219. break;
  220. case 3:
  221. val &= BYTE3_MASK;
  222. break;
  223. }
  224. }
  225. if (!(i % 16))
  226. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  227. pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
  228. }
  229. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  230. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  231. kfree(buf);
  232. return ret;
  233. }
  234. static ssize_t il_dbgfs_sram_write(struct file *file,
  235. const char __user *user_buf,
  236. size_t count, loff_t *ppos)
  237. {
  238. struct il_priv *il = file->private_data;
  239. char buf[64];
  240. int buf_size;
  241. u32 offset, len;
  242. memset(buf, 0, sizeof(buf));
  243. buf_size = min(count, sizeof(buf) - 1);
  244. if (copy_from_user(buf, user_buf, buf_size))
  245. return -EFAULT;
  246. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  247. il->dbgfs_sram_offset = offset;
  248. il->dbgfs_sram_len = len;
  249. } else {
  250. il->dbgfs_sram_offset = 0;
  251. il->dbgfs_sram_len = 0;
  252. }
  253. return count;
  254. }
  255. static ssize_t
  256. il_dbgfs_stations_read(struct file *file, char __user *user_buf,
  257. size_t count, loff_t *ppos)
  258. {
  259. struct il_priv *il = file->private_data;
  260. struct il_station_entry *station;
  261. int max_sta = il->hw_params.max_stations;
  262. char *buf;
  263. int i, j, pos = 0;
  264. ssize_t ret;
  265. /* Add 30 for initial string */
  266. const size_t bufsz = 30 + sizeof(char) * 500 * (il->num_stations);
  267. buf = kmalloc(bufsz, GFP_KERNEL);
  268. if (!buf)
  269. return -ENOMEM;
  270. pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
  271. il->num_stations);
  272. for (i = 0; i < max_sta; i++) {
  273. station = &il->stations[i];
  274. if (!station->used)
  275. continue;
  276. pos += scnprintf(buf + pos, bufsz - pos,
  277. "station %d - addr: %pM, flags: %#x\n",
  278. i, station->sta.sta.addr,
  279. station->sta.station_flags_msk);
  280. pos += scnprintf(buf + pos, bufsz - pos,
  281. "TID\tseq_num\ttxq_id\tframes\ttfds\t");
  282. pos += scnprintf(buf + pos, bufsz - pos,
  283. "start_idx\tbitmap\t\t\trate_n_flags\n");
  284. for (j = 0; j < MAX_TID_COUNT; j++) {
  285. pos += scnprintf(buf + pos, bufsz - pos,
  286. "%d:\t%#x\t%#x\t%u\t%u\t%u\t\t%#.16llx\t%#x",
  287. j, station->tid[j].seq_number,
  288. station->tid[j].agg.txq_id,
  289. station->tid[j].agg.frame_count,
  290. station->tid[j].tfds_in_queue,
  291. station->tid[j].agg.start_idx,
  292. station->tid[j].agg.bitmap,
  293. station->tid[j].agg.rate_n_flags);
  294. if (station->tid[j].agg.wait_for_ba)
  295. pos += scnprintf(buf + pos, bufsz - pos,
  296. " - waitforba");
  297. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  298. }
  299. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  300. }
  301. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  302. kfree(buf);
  303. return ret;
  304. }
  305. static ssize_t il_dbgfs_nvm_read(struct file *file,
  306. char __user *user_buf,
  307. size_t count,
  308. loff_t *ppos)
  309. {
  310. ssize_t ret;
  311. struct il_priv *il = file->private_data;
  312. int pos = 0, ofs = 0, buf_size = 0;
  313. const u8 *ptr;
  314. char *buf;
  315. u16 eeprom_ver;
  316. size_t eeprom_len = il->cfg->base_params->eeprom_size;
  317. buf_size = 4 * eeprom_len + 256;
  318. if (eeprom_len % 16) {
  319. IL_ERR("NVM size is not multiple of 16.\n");
  320. return -ENODATA;
  321. }
  322. ptr = il->eeprom;
  323. if (!ptr) {
  324. IL_ERR("Invalid EEPROM memory\n");
  325. return -ENOMEM;
  326. }
  327. /* 4 characters for byte 0xYY */
  328. buf = kzalloc(buf_size, GFP_KERNEL);
  329. if (!buf) {
  330. IL_ERR("Can not allocate Buffer\n");
  331. return -ENOMEM;
  332. }
  333. eeprom_ver = il_eeprom_query16(il, EEPROM_VERSION);
  334. pos += scnprintf(buf + pos, buf_size - pos, "EEPROM "
  335. "version: 0x%x\n", eeprom_ver);
  336. for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
  337. pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
  338. hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
  339. buf_size - pos, 0);
  340. pos += strlen(buf + pos);
  341. if (buf_size - pos > 0)
  342. buf[pos++] = '\n';
  343. }
  344. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  345. kfree(buf);
  346. return ret;
  347. }
  348. static ssize_t
  349. il_dbgfs_channels_read(struct file *file, char __user *user_buf,
  350. size_t count, loff_t *ppos)
  351. {
  352. struct il_priv *il = file->private_data;
  353. struct ieee80211_channel *channels = NULL;
  354. const struct ieee80211_supported_band *supp_band = NULL;
  355. int pos = 0, i, bufsz = PAGE_SIZE;
  356. char *buf;
  357. ssize_t ret;
  358. if (!test_bit(S_GEO_CONFIGURED, &il->status))
  359. return -EAGAIN;
  360. buf = kzalloc(bufsz, GFP_KERNEL);
  361. if (!buf) {
  362. IL_ERR("Can not allocate Buffer\n");
  363. return -ENOMEM;
  364. }
  365. supp_band = il_get_hw_mode(il, IEEE80211_BAND_2GHZ);
  366. if (supp_band) {
  367. channels = supp_band->channels;
  368. pos += scnprintf(buf + pos, bufsz - pos,
  369. "Displaying %d channels in 2.4GHz band 802.11bg):\n",
  370. supp_band->n_channels);
  371. for (i = 0; i < supp_band->n_channels; i++)
  372. pos += scnprintf(buf + pos, bufsz - pos,
  373. "%d: %ddBm: BSS%s%s, %s.\n",
  374. channels[i].hw_value,
  375. channels[i].max_power,
  376. channels[i].flags & IEEE80211_CHAN_RADAR ?
  377. " (IEEE 802.11h required)" : "",
  378. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  379. || (channels[i].flags &
  380. IEEE80211_CHAN_RADAR)) ? "" :
  381. ", IBSS",
  382. channels[i].flags &
  383. IEEE80211_CHAN_PASSIVE_SCAN ?
  384. "passive only" : "active/passive");
  385. }
  386. supp_band = il_get_hw_mode(il, IEEE80211_BAND_5GHZ);
  387. if (supp_band) {
  388. channels = supp_band->channels;
  389. pos += scnprintf(buf + pos, bufsz - pos,
  390. "Displaying %d channels in 5.2GHz band (802.11a)\n",
  391. supp_band->n_channels);
  392. for (i = 0; i < supp_band->n_channels; i++)
  393. pos += scnprintf(buf + pos, bufsz - pos,
  394. "%d: %ddBm: BSS%s%s, %s.\n",
  395. channels[i].hw_value,
  396. channels[i].max_power,
  397. channels[i].flags & IEEE80211_CHAN_RADAR ?
  398. " (IEEE 802.11h required)" : "",
  399. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  400. || (channels[i].flags &
  401. IEEE80211_CHAN_RADAR)) ? "" :
  402. ", IBSS",
  403. channels[i].flags &
  404. IEEE80211_CHAN_PASSIVE_SCAN ?
  405. "passive only" : "active/passive");
  406. }
  407. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  408. kfree(buf);
  409. return ret;
  410. }
  411. static ssize_t il_dbgfs_status_read(struct file *file,
  412. char __user *user_buf,
  413. size_t count, loff_t *ppos) {
  414. struct il_priv *il = file->private_data;
  415. char buf[512];
  416. int pos = 0;
  417. const size_t bufsz = sizeof(buf);
  418. pos += scnprintf(buf + pos, bufsz - pos, "S_HCMD_ACTIVE:\t %d\n",
  419. test_bit(S_HCMD_ACTIVE, &il->status));
  420. pos += scnprintf(buf + pos, bufsz - pos, "S_INT_ENABLED:\t %d\n",
  421. test_bit(S_INT_ENABLED, &il->status));
  422. pos += scnprintf(buf + pos, bufsz - pos, "S_RF_KILL_HW:\t %d\n",
  423. test_bit(S_RF_KILL_HW, &il->status));
  424. pos += scnprintf(buf + pos, bufsz - pos, "S_CT_KILL:\t\t %d\n",
  425. test_bit(S_CT_KILL, &il->status));
  426. pos += scnprintf(buf + pos, bufsz - pos, "S_INIT:\t\t %d\n",
  427. test_bit(S_INIT, &il->status));
  428. pos += scnprintf(buf + pos, bufsz - pos, "S_ALIVE:\t\t %d\n",
  429. test_bit(S_ALIVE, &il->status));
  430. pos += scnprintf(buf + pos, bufsz - pos, "S_READY:\t\t %d\n",
  431. test_bit(S_READY, &il->status));
  432. pos += scnprintf(buf + pos, bufsz - pos, "S_TEMPERATURE:\t %d\n",
  433. test_bit(S_TEMPERATURE, &il->status));
  434. pos += scnprintf(buf + pos, bufsz - pos, "S_GEO_CONFIGURED:\t %d\n",
  435. test_bit(S_GEO_CONFIGURED, &il->status));
  436. pos += scnprintf(buf + pos, bufsz - pos, "S_EXIT_PENDING:\t %d\n",
  437. test_bit(S_EXIT_PENDING, &il->status));
  438. pos += scnprintf(buf + pos, bufsz - pos, "S_STATS:\t %d\n",
  439. test_bit(S_STATS, &il->status));
  440. pos += scnprintf(buf + pos, bufsz - pos, "S_SCANNING:\t %d\n",
  441. test_bit(S_SCANNING, &il->status));
  442. pos += scnprintf(buf + pos, bufsz - pos, "S_SCAN_ABORTING:\t %d\n",
  443. test_bit(S_SCAN_ABORTING, &il->status));
  444. pos += scnprintf(buf + pos, bufsz - pos, "S_SCAN_HW:\t\t %d\n",
  445. test_bit(S_SCAN_HW, &il->status));
  446. pos += scnprintf(buf + pos, bufsz - pos, "S_POWER_PMI:\t %d\n",
  447. test_bit(S_POWER_PMI, &il->status));
  448. pos += scnprintf(buf + pos, bufsz - pos, "S_FW_ERROR:\t %d\n",
  449. test_bit(S_FW_ERROR, &il->status));
  450. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  451. }
  452. static ssize_t il_dbgfs_interrupt_read(struct file *file,
  453. char __user *user_buf,
  454. size_t count, loff_t *ppos) {
  455. struct il_priv *il = file->private_data;
  456. int pos = 0;
  457. int cnt = 0;
  458. char *buf;
  459. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  460. ssize_t ret;
  461. buf = kzalloc(bufsz, GFP_KERNEL);
  462. if (!buf) {
  463. IL_ERR("Can not allocate Buffer\n");
  464. return -ENOMEM;
  465. }
  466. pos += scnprintf(buf + pos, bufsz - pos,
  467. "Interrupt Statistics Report:\n");
  468. pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
  469. il->isr_stats.hw);
  470. pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
  471. il->isr_stats.sw);
  472. if (il->isr_stats.sw || il->isr_stats.hw) {
  473. pos += scnprintf(buf + pos, bufsz - pos,
  474. "\tLast Restarting Code: 0x%X\n",
  475. il->isr_stats.err_code);
  476. }
  477. #ifdef CONFIG_IWLEGACY_DEBUG
  478. pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
  479. il->isr_stats.sch);
  480. pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
  481. il->isr_stats.alive);
  482. #endif
  483. pos += scnprintf(buf + pos, bufsz - pos,
  484. "HW RF KILL switch toggled:\t %u\n",
  485. il->isr_stats.rfkill);
  486. pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
  487. il->isr_stats.ctkill);
  488. pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
  489. il->isr_stats.wakeup);
  490. pos += scnprintf(buf + pos, bufsz - pos,
  491. "Rx command responses:\t\t %u\n",
  492. il->isr_stats.rx);
  493. for (cnt = 0; cnt < IL_CN_MAX; cnt++) {
  494. if (il->isr_stats.handlers[cnt] > 0)
  495. pos += scnprintf(buf + pos, bufsz - pos,
  496. "\tRx handler[%36s]:\t\t %u\n",
  497. il_get_cmd_string(cnt),
  498. il->isr_stats.handlers[cnt]);
  499. }
  500. pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
  501. il->isr_stats.tx);
  502. pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
  503. il->isr_stats.unhandled);
  504. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  505. kfree(buf);
  506. return ret;
  507. }
  508. static ssize_t il_dbgfs_interrupt_write(struct file *file,
  509. const char __user *user_buf,
  510. size_t count, loff_t *ppos)
  511. {
  512. struct il_priv *il = file->private_data;
  513. char buf[8];
  514. int buf_size;
  515. u32 reset_flag;
  516. memset(buf, 0, sizeof(buf));
  517. buf_size = min(count, sizeof(buf) - 1);
  518. if (copy_from_user(buf, user_buf, buf_size))
  519. return -EFAULT;
  520. if (sscanf(buf, "%x", &reset_flag) != 1)
  521. return -EFAULT;
  522. if (reset_flag == 0)
  523. il_clear_isr_stats(il);
  524. return count;
  525. }
  526. static ssize_t
  527. il_dbgfs_qos_read(struct file *file, char __user *user_buf,
  528. size_t count, loff_t *ppos)
  529. {
  530. struct il_priv *il = file->private_data;
  531. struct il_rxon_context *ctx = &il->ctx;
  532. int pos = 0, i;
  533. char buf[256];
  534. const size_t bufsz = sizeof(buf);
  535. pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
  536. ctx->ctxid);
  537. for (i = 0; i < AC_NUM; i++) {
  538. pos += scnprintf(buf + pos, bufsz - pos,
  539. "\tcw_min\tcw_max\taifsn\ttxop\n");
  540. pos += scnprintf(buf + pos, bufsz - pos,
  541. "AC[%d]\t%u\t%u\t%u\t%u\n", i,
  542. ctx->qos_data.def_qos_parm.ac[i].cw_min,
  543. ctx->qos_data.def_qos_parm.ac[i].cw_max,
  544. ctx->qos_data.def_qos_parm.ac[i].aifsn,
  545. ctx->qos_data.def_qos_parm.ac[i].edca_txop);
  546. }
  547. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  548. }
  549. static ssize_t il_dbgfs_disable_ht40_write(struct file *file,
  550. const char __user *user_buf,
  551. size_t count, loff_t *ppos)
  552. {
  553. struct il_priv *il = file->private_data;
  554. char buf[8];
  555. int buf_size;
  556. int ht40;
  557. memset(buf, 0, sizeof(buf));
  558. buf_size = min(count, sizeof(buf) - 1);
  559. if (copy_from_user(buf, user_buf, buf_size))
  560. return -EFAULT;
  561. if (sscanf(buf, "%d", &ht40) != 1)
  562. return -EFAULT;
  563. if (!il_is_any_associated(il))
  564. il->disable_ht40 = ht40 ? true : false;
  565. else {
  566. IL_ERR("Sta associated with AP - "
  567. "Change to 40MHz channel support is not allowed\n");
  568. return -EINVAL;
  569. }
  570. return count;
  571. }
  572. static ssize_t il_dbgfs_disable_ht40_read(struct file *file,
  573. char __user *user_buf,
  574. size_t count, loff_t *ppos)
  575. {
  576. struct il_priv *il = file->private_data;
  577. char buf[100];
  578. int pos = 0;
  579. const size_t bufsz = sizeof(buf);
  580. pos += scnprintf(buf + pos, bufsz - pos,
  581. "11n 40MHz Mode: %s\n",
  582. il->disable_ht40 ? "Disabled" : "Enabled");
  583. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  584. }
  585. DEBUGFS_READ_WRITE_FILE_OPS(sram);
  586. DEBUGFS_READ_FILE_OPS(nvm);
  587. DEBUGFS_READ_FILE_OPS(stations);
  588. DEBUGFS_READ_FILE_OPS(channels);
  589. DEBUGFS_READ_FILE_OPS(status);
  590. DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
  591. DEBUGFS_READ_FILE_OPS(qos);
  592. DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
  593. static ssize_t il_dbgfs_traffic_log_read(struct file *file,
  594. char __user *user_buf,
  595. size_t count, loff_t *ppos)
  596. {
  597. struct il_priv *il = file->private_data;
  598. int pos = 0, ofs = 0;
  599. int cnt = 0, entry;
  600. struct il_tx_queue *txq;
  601. struct il_queue *q;
  602. struct il_rx_queue *rxq = &il->rxq;
  603. char *buf;
  604. int bufsz = ((IL_TRAFFIC_ENTRIES * IL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
  605. (il->cfg->base_params->num_of_queues * 32 * 8) + 400;
  606. const u8 *ptr;
  607. ssize_t ret;
  608. if (!il->txq) {
  609. IL_ERR("txq not ready\n");
  610. return -EAGAIN;
  611. }
  612. buf = kzalloc(bufsz, GFP_KERNEL);
  613. if (!buf) {
  614. IL_ERR("Can not allocate buffer\n");
  615. return -ENOMEM;
  616. }
  617. pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
  618. for (cnt = 0; cnt < il->hw_params.max_txq_num; cnt++) {
  619. txq = &il->txq[cnt];
  620. q = &txq->q;
  621. pos += scnprintf(buf + pos, bufsz - pos,
  622. "q[%d]: read_ptr: %u, write_ptr: %u\n",
  623. cnt, q->read_ptr, q->write_ptr);
  624. }
  625. if (il->tx_traffic && (il_debug_level & IL_DL_TX)) {
  626. ptr = il->tx_traffic;
  627. pos += scnprintf(buf + pos, bufsz - pos,
  628. "Tx Traffic idx: %u\n", il->tx_traffic_idx);
  629. for (cnt = 0, ofs = 0; cnt < IL_TRAFFIC_ENTRIES; cnt++) {
  630. for (entry = 0; entry < IL_TRAFFIC_ENTRY_SIZE / 16;
  631. entry++, ofs += 16) {
  632. pos += scnprintf(buf + pos, bufsz - pos,
  633. "0x%.4x ", ofs);
  634. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  635. buf + pos, bufsz - pos, 0);
  636. pos += strlen(buf + pos);
  637. if (bufsz - pos > 0)
  638. buf[pos++] = '\n';
  639. }
  640. }
  641. }
  642. pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
  643. pos += scnprintf(buf + pos, bufsz - pos,
  644. "read: %u, write: %u\n",
  645. rxq->read, rxq->write);
  646. if (il->rx_traffic && (il_debug_level & IL_DL_RX)) {
  647. ptr = il->rx_traffic;
  648. pos += scnprintf(buf + pos, bufsz - pos,
  649. "Rx Traffic idx: %u\n", il->rx_traffic_idx);
  650. for (cnt = 0, ofs = 0; cnt < IL_TRAFFIC_ENTRIES; cnt++) {
  651. for (entry = 0; entry < IL_TRAFFIC_ENTRY_SIZE / 16;
  652. entry++, ofs += 16) {
  653. pos += scnprintf(buf + pos, bufsz - pos,
  654. "0x%.4x ", ofs);
  655. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  656. buf + pos, bufsz - pos, 0);
  657. pos += strlen(buf + pos);
  658. if (bufsz - pos > 0)
  659. buf[pos++] = '\n';
  660. }
  661. }
  662. }
  663. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  664. kfree(buf);
  665. return ret;
  666. }
  667. static ssize_t il_dbgfs_traffic_log_write(struct file *file,
  668. const char __user *user_buf,
  669. size_t count, loff_t *ppos)
  670. {
  671. struct il_priv *il = file->private_data;
  672. char buf[8];
  673. int buf_size;
  674. int traffic_log;
  675. memset(buf, 0, sizeof(buf));
  676. buf_size = min(count, sizeof(buf) - 1);
  677. if (copy_from_user(buf, user_buf, buf_size))
  678. return -EFAULT;
  679. if (sscanf(buf, "%d", &traffic_log) != 1)
  680. return -EFAULT;
  681. if (traffic_log == 0)
  682. il_reset_traffic_log(il);
  683. return count;
  684. }
  685. static ssize_t il_dbgfs_tx_queue_read(struct file *file,
  686. char __user *user_buf,
  687. size_t count, loff_t *ppos) {
  688. struct il_priv *il = file->private_data;
  689. struct il_tx_queue *txq;
  690. struct il_queue *q;
  691. char *buf;
  692. int pos = 0;
  693. int cnt;
  694. int ret;
  695. const size_t bufsz = sizeof(char) * 64 *
  696. il->cfg->base_params->num_of_queues;
  697. if (!il->txq) {
  698. IL_ERR("txq not ready\n");
  699. return -EAGAIN;
  700. }
  701. buf = kzalloc(bufsz, GFP_KERNEL);
  702. if (!buf)
  703. return -ENOMEM;
  704. for (cnt = 0; cnt < il->hw_params.max_txq_num; cnt++) {
  705. txq = &il->txq[cnt];
  706. q = &txq->q;
  707. pos += scnprintf(buf + pos, bufsz - pos,
  708. "hwq %.2d: read=%u write=%u stop=%d"
  709. " swq_id=%#.2x (ac %d/hwq %d)\n",
  710. cnt, q->read_ptr, q->write_ptr,
  711. !!test_bit(cnt, il->queue_stopped),
  712. txq->swq_id, txq->swq_id & 3,
  713. (txq->swq_id >> 2) & 0x1f);
  714. if (cnt >= 4)
  715. continue;
  716. /* for the ACs, display the stop count too */
  717. pos += scnprintf(buf + pos, bufsz - pos,
  718. " stop-count: %d\n",
  719. atomic_read(&il->queue_stop_count[cnt]));
  720. }
  721. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  722. kfree(buf);
  723. return ret;
  724. }
  725. static ssize_t il_dbgfs_rx_queue_read(struct file *file,
  726. char __user *user_buf,
  727. size_t count, loff_t *ppos) {
  728. struct il_priv *il = file->private_data;
  729. struct il_rx_queue *rxq = &il->rxq;
  730. char buf[256];
  731. int pos = 0;
  732. const size_t bufsz = sizeof(buf);
  733. pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
  734. rxq->read);
  735. pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
  736. rxq->write);
  737. pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
  738. rxq->free_count);
  739. if (rxq->rb_stts) {
  740. pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
  741. le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
  742. } else {
  743. pos += scnprintf(buf + pos, bufsz - pos,
  744. "closed_rb_num: Not Allocated\n");
  745. }
  746. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  747. }
  748. static ssize_t il_dbgfs_ucode_rx_stats_read(struct file *file,
  749. char __user *user_buf,
  750. size_t count, loff_t *ppos)
  751. {
  752. struct il_priv *il = file->private_data;
  753. return il->cfg->ops->lib->debugfs_ops.rx_stats_read(file,
  754. user_buf, count, ppos);
  755. }
  756. static ssize_t il_dbgfs_ucode_tx_stats_read(struct file *file,
  757. char __user *user_buf,
  758. size_t count, loff_t *ppos)
  759. {
  760. struct il_priv *il = file->private_data;
  761. return il->cfg->ops->lib->debugfs_ops.tx_stats_read(file,
  762. user_buf, count, ppos);
  763. }
  764. static ssize_t il_dbgfs_ucode_general_stats_read(struct file *file,
  765. char __user *user_buf,
  766. size_t count, loff_t *ppos)
  767. {
  768. struct il_priv *il = file->private_data;
  769. return il->cfg->ops->lib->debugfs_ops.general_stats_read(file,
  770. user_buf, count, ppos);
  771. }
  772. static ssize_t il_dbgfs_sensitivity_read(struct file *file,
  773. char __user *user_buf,
  774. size_t count, loff_t *ppos) {
  775. struct il_priv *il = file->private_data;
  776. int pos = 0;
  777. int cnt = 0;
  778. char *buf;
  779. int bufsz = sizeof(struct il_sensitivity_data) * 4 + 100;
  780. ssize_t ret;
  781. struct il_sensitivity_data *data;
  782. data = &il->sensitivity_data;
  783. buf = kzalloc(bufsz, GFP_KERNEL);
  784. if (!buf) {
  785. IL_ERR("Can not allocate Buffer\n");
  786. return -ENOMEM;
  787. }
  788. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
  789. data->auto_corr_ofdm);
  790. pos += scnprintf(buf + pos, bufsz - pos,
  791. "auto_corr_ofdm_mrc:\t\t %u\n",
  792. data->auto_corr_ofdm_mrc);
  793. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
  794. data->auto_corr_ofdm_x1);
  795. pos += scnprintf(buf + pos, bufsz - pos,
  796. "auto_corr_ofdm_mrc_x1:\t\t %u\n",
  797. data->auto_corr_ofdm_mrc_x1);
  798. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
  799. data->auto_corr_cck);
  800. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
  801. data->auto_corr_cck_mrc);
  802. pos += scnprintf(buf + pos, bufsz - pos,
  803. "last_bad_plcp_cnt_ofdm:\t\t %u\n",
  804. data->last_bad_plcp_cnt_ofdm);
  805. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
  806. data->last_fa_cnt_ofdm);
  807. pos += scnprintf(buf + pos, bufsz - pos,
  808. "last_bad_plcp_cnt_cck:\t\t %u\n",
  809. data->last_bad_plcp_cnt_cck);
  810. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
  811. data->last_fa_cnt_cck);
  812. pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
  813. data->nrg_curr_state);
  814. pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
  815. data->nrg_prev_state);
  816. pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
  817. for (cnt = 0; cnt < 10; cnt++) {
  818. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  819. data->nrg_value[cnt]);
  820. }
  821. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  822. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
  823. for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
  824. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  825. data->nrg_silence_rssi[cnt]);
  826. }
  827. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  828. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
  829. data->nrg_silence_ref);
  830. pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
  831. data->nrg_energy_idx);
  832. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
  833. data->nrg_silence_idx);
  834. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
  835. data->nrg_th_cck);
  836. pos += scnprintf(buf + pos, bufsz - pos,
  837. "nrg_auto_corr_silence_diff:\t %u\n",
  838. data->nrg_auto_corr_silence_diff);
  839. pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
  840. data->num_in_cck_no_fa);
  841. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
  842. data->nrg_th_ofdm);
  843. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  844. kfree(buf);
  845. return ret;
  846. }
  847. static ssize_t il_dbgfs_chain_noise_read(struct file *file,
  848. char __user *user_buf,
  849. size_t count, loff_t *ppos) {
  850. struct il_priv *il = file->private_data;
  851. int pos = 0;
  852. int cnt = 0;
  853. char *buf;
  854. int bufsz = sizeof(struct il_chain_noise_data) * 4 + 100;
  855. ssize_t ret;
  856. struct il_chain_noise_data *data;
  857. data = &il->chain_noise_data;
  858. buf = kzalloc(bufsz, GFP_KERNEL);
  859. if (!buf) {
  860. IL_ERR("Can not allocate Buffer\n");
  861. return -ENOMEM;
  862. }
  863. pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
  864. data->active_chains);
  865. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
  866. data->chain_noise_a);
  867. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
  868. data->chain_noise_b);
  869. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
  870. data->chain_noise_c);
  871. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
  872. data->chain_signal_a);
  873. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
  874. data->chain_signal_b);
  875. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
  876. data->chain_signal_c);
  877. pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
  878. data->beacon_count);
  879. pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
  880. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  881. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  882. data->disconn_array[cnt]);
  883. }
  884. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  885. pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
  886. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  887. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  888. data->delta_gain_code[cnt]);
  889. }
  890. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  891. pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
  892. data->radio_write);
  893. pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
  894. data->state);
  895. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  896. kfree(buf);
  897. return ret;
  898. }
  899. static ssize_t il_dbgfs_power_save_status_read(struct file *file,
  900. char __user *user_buf,
  901. size_t count, loff_t *ppos)
  902. {
  903. struct il_priv *il = file->private_data;
  904. char buf[60];
  905. int pos = 0;
  906. const size_t bufsz = sizeof(buf);
  907. u32 pwrsave_status;
  908. pwrsave_status = _il_rd(il, CSR_GP_CNTRL) &
  909. CSR_GP_REG_POWER_SAVE_STATUS_MSK;
  910. pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
  911. pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
  912. (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
  913. (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
  914. (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
  915. "error");
  916. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  917. }
  918. static ssize_t il_dbgfs_clear_ucode_stats_write(struct file *file,
  919. const char __user *user_buf,
  920. size_t count, loff_t *ppos)
  921. {
  922. struct il_priv *il = file->private_data;
  923. char buf[8];
  924. int buf_size;
  925. int clear;
  926. memset(buf, 0, sizeof(buf));
  927. buf_size = min(count, sizeof(buf) - 1);
  928. if (copy_from_user(buf, user_buf, buf_size))
  929. return -EFAULT;
  930. if (sscanf(buf, "%d", &clear) != 1)
  931. return -EFAULT;
  932. /* make request to uCode to retrieve stats information */
  933. mutex_lock(&il->mutex);
  934. il_send_stats_request(il, CMD_SYNC, true);
  935. mutex_unlock(&il->mutex);
  936. return count;
  937. }
  938. static ssize_t il_dbgfs_rxon_flags_read(struct file *file,
  939. char __user *user_buf,
  940. size_t count, loff_t *ppos) {
  941. struct il_priv *il = file->private_data;
  942. int len = 0;
  943. char buf[20];
  944. len = sprintf(buf, "0x%04X\n",
  945. le32_to_cpu(il->ctx.active.flags));
  946. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  947. }
  948. static ssize_t il_dbgfs_rxon_filter_flags_read(struct file *file,
  949. char __user *user_buf,
  950. size_t count, loff_t *ppos) {
  951. struct il_priv *il = file->private_data;
  952. int len = 0;
  953. char buf[20];
  954. len = sprintf(buf, "0x%04X\n",
  955. le32_to_cpu(il->ctx.active.filter_flags));
  956. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  957. }
  958. static ssize_t il_dbgfs_fh_reg_read(struct file *file,
  959. char __user *user_buf,
  960. size_t count, loff_t *ppos)
  961. {
  962. struct il_priv *il = file->private_data;
  963. char *buf;
  964. int pos = 0;
  965. ssize_t ret = -EFAULT;
  966. if (il->cfg->ops->lib->dump_fh) {
  967. ret = pos = il->cfg->ops->lib->dump_fh(il, &buf, true);
  968. if (buf) {
  969. ret = simple_read_from_buffer(user_buf,
  970. count, ppos, buf, pos);
  971. kfree(buf);
  972. }
  973. }
  974. return ret;
  975. }
  976. static ssize_t il_dbgfs_missed_beacon_read(struct file *file,
  977. char __user *user_buf,
  978. size_t count, loff_t *ppos) {
  979. struct il_priv *il = file->private_data;
  980. int pos = 0;
  981. char buf[12];
  982. const size_t bufsz = sizeof(buf);
  983. pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
  984. il->missed_beacon_threshold);
  985. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  986. }
  987. static ssize_t il_dbgfs_missed_beacon_write(struct file *file,
  988. const char __user *user_buf,
  989. size_t count, loff_t *ppos)
  990. {
  991. struct il_priv *il = file->private_data;
  992. char buf[8];
  993. int buf_size;
  994. int missed;
  995. memset(buf, 0, sizeof(buf));
  996. buf_size = min(count, sizeof(buf) - 1);
  997. if (copy_from_user(buf, user_buf, buf_size))
  998. return -EFAULT;
  999. if (sscanf(buf, "%d", &missed) != 1)
  1000. return -EINVAL;
  1001. if (missed < IL_MISSED_BEACON_THRESHOLD_MIN ||
  1002. missed > IL_MISSED_BEACON_THRESHOLD_MAX)
  1003. il->missed_beacon_threshold =
  1004. IL_MISSED_BEACON_THRESHOLD_DEF;
  1005. else
  1006. il->missed_beacon_threshold = missed;
  1007. return count;
  1008. }
  1009. static ssize_t il_dbgfs_force_reset_read(struct file *file,
  1010. char __user *user_buf,
  1011. size_t count, loff_t *ppos) {
  1012. struct il_priv *il = file->private_data;
  1013. int pos = 0;
  1014. char buf[300];
  1015. const size_t bufsz = sizeof(buf);
  1016. struct il_force_reset *force_reset;
  1017. force_reset = &il->force_reset;
  1018. pos += scnprintf(buf + pos, bufsz - pos,
  1019. "\tnumber of reset request: %d\n",
  1020. force_reset->reset_request_count);
  1021. pos += scnprintf(buf + pos, bufsz - pos,
  1022. "\tnumber of reset request success: %d\n",
  1023. force_reset->reset_success_count);
  1024. pos += scnprintf(buf + pos, bufsz - pos,
  1025. "\tnumber of reset request reject: %d\n",
  1026. force_reset->reset_reject_count);
  1027. pos += scnprintf(buf + pos, bufsz - pos,
  1028. "\treset duration: %lu\n",
  1029. force_reset->reset_duration);
  1030. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1031. }
  1032. static ssize_t il_dbgfs_force_reset_write(struct file *file,
  1033. const char __user *user_buf,
  1034. size_t count, loff_t *ppos) {
  1035. int ret;
  1036. struct il_priv *il = file->private_data;
  1037. ret = il_force_reset(il, true);
  1038. return ret ? ret : count;
  1039. }
  1040. static ssize_t il_dbgfs_wd_timeout_write(struct file *file,
  1041. const char __user *user_buf,
  1042. size_t count, loff_t *ppos) {
  1043. struct il_priv *il = file->private_data;
  1044. char buf[8];
  1045. int buf_size;
  1046. int timeout;
  1047. memset(buf, 0, sizeof(buf));
  1048. buf_size = min(count, sizeof(buf) - 1);
  1049. if (copy_from_user(buf, user_buf, buf_size))
  1050. return -EFAULT;
  1051. if (sscanf(buf, "%d", &timeout) != 1)
  1052. return -EINVAL;
  1053. if (timeout < 0 || timeout > IL_MAX_WD_TIMEOUT)
  1054. timeout = IL_DEF_WD_TIMEOUT;
  1055. il->cfg->base_params->wd_timeout = timeout;
  1056. il_setup_watchdog(il);
  1057. return count;
  1058. }
  1059. DEBUGFS_READ_FILE_OPS(rx_stats);
  1060. DEBUGFS_READ_FILE_OPS(tx_stats);
  1061. DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
  1062. DEBUGFS_READ_FILE_OPS(rx_queue);
  1063. DEBUGFS_READ_FILE_OPS(tx_queue);
  1064. DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
  1065. DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
  1066. DEBUGFS_READ_FILE_OPS(ucode_general_stats);
  1067. DEBUGFS_READ_FILE_OPS(sensitivity);
  1068. DEBUGFS_READ_FILE_OPS(chain_noise);
  1069. DEBUGFS_READ_FILE_OPS(power_save_status);
  1070. DEBUGFS_WRITE_FILE_OPS(clear_ucode_stats);
  1071. DEBUGFS_WRITE_FILE_OPS(clear_traffic_stats);
  1072. DEBUGFS_READ_FILE_OPS(fh_reg);
  1073. DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
  1074. DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
  1075. DEBUGFS_READ_FILE_OPS(rxon_flags);
  1076. DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
  1077. DEBUGFS_WRITE_FILE_OPS(wd_timeout);
  1078. /*
  1079. * Create the debugfs files and directories
  1080. *
  1081. */
  1082. int il_dbgfs_register(struct il_priv *il, const char *name)
  1083. {
  1084. struct dentry *phyd = il->hw->wiphy->debugfsdir;
  1085. struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
  1086. dir_drv = debugfs_create_dir(name, phyd);
  1087. if (!dir_drv)
  1088. return -ENOMEM;
  1089. il->debugfs_dir = dir_drv;
  1090. dir_data = debugfs_create_dir("data", dir_drv);
  1091. if (!dir_data)
  1092. goto err;
  1093. dir_rf = debugfs_create_dir("rf", dir_drv);
  1094. if (!dir_rf)
  1095. goto err;
  1096. dir_debug = debugfs_create_dir("debug", dir_drv);
  1097. if (!dir_debug)
  1098. goto err;
  1099. DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
  1100. DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
  1101. DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
  1102. DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
  1103. DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
  1104. DEBUGFS_ADD_FILE(interrupt, dir_data, S_IWUSR | S_IRUSR);
  1105. DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
  1106. DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
  1107. DEBUGFS_ADD_FILE(rx_stats, dir_debug, S_IRUSR);
  1108. DEBUGFS_ADD_FILE(tx_stats, dir_debug, S_IRUSR);
  1109. DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
  1110. DEBUGFS_ADD_FILE(rx_queue, dir_debug, S_IRUSR);
  1111. DEBUGFS_ADD_FILE(tx_queue, dir_debug, S_IRUSR);
  1112. DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
  1113. DEBUGFS_ADD_FILE(clear_ucode_stats, dir_debug, S_IWUSR);
  1114. DEBUGFS_ADD_FILE(clear_traffic_stats, dir_debug, S_IWUSR);
  1115. DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR);
  1116. DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
  1117. DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
  1118. DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
  1119. DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
  1120. DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
  1121. if (il->cfg->base_params->sensitivity_calib_by_driver)
  1122. DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
  1123. if (il->cfg->base_params->chain_noise_calib_by_driver)
  1124. DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
  1125. DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
  1126. DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
  1127. DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
  1128. if (il->cfg->base_params->sensitivity_calib_by_driver)
  1129. DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
  1130. &il->disable_sens_cal);
  1131. if (il->cfg->base_params->chain_noise_calib_by_driver)
  1132. DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
  1133. &il->disable_chain_noise_cal);
  1134. DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf,
  1135. &il->disable_tx_power_cal);
  1136. return 0;
  1137. err:
  1138. IL_ERR("Can't create the debugfs directory\n");
  1139. il_dbgfs_unregister(il);
  1140. return -ENOMEM;
  1141. }
  1142. EXPORT_SYMBOL(il_dbgfs_register);
  1143. /**
  1144. * Remove the debugfs files and directories
  1145. *
  1146. */
  1147. void il_dbgfs_unregister(struct il_priv *il)
  1148. {
  1149. if (!il->debugfs_dir)
  1150. return;
  1151. debugfs_remove_recursive(il->debugfs_dir);
  1152. il->debugfs_dir = NULL;
  1153. }
  1154. EXPORT_SYMBOL(il_dbgfs_unregister);