debug.c 39 KB

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