debug.c 39 KB

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