debug.c 39 KB

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