iwl-debugfs.c 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539
  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/slab.h>
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/debugfs.h>
  32. #include <linux/ieee80211.h>
  33. #include <net/mac80211.h>
  34. #include "iwl-dev.h"
  35. #include "iwl-debug.h"
  36. #include "iwl-core.h"
  37. #include "iwl-io.h"
  38. #include "iwl-agn.h"
  39. /* create and remove of files */
  40. #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
  41. if (!debugfs_create_file(#name, mode, parent, priv, \
  42. &iwl_dbgfs_##name##_ops)) \
  43. goto err; \
  44. } while (0)
  45. #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
  46. struct dentry *__tmp; \
  47. __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
  48. parent, ptr); \
  49. if (IS_ERR(__tmp) || !__tmp) \
  50. goto err; \
  51. } while (0)
  52. #define DEBUGFS_ADD_X32(name, parent, ptr) do { \
  53. struct dentry *__tmp; \
  54. __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
  55. parent, ptr); \
  56. if (IS_ERR(__tmp) || !__tmp) \
  57. goto err; \
  58. } while (0)
  59. /* file operation */
  60. #define DEBUGFS_READ_FUNC(name) \
  61. static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
  62. char __user *user_buf, \
  63. size_t count, loff_t *ppos);
  64. #define DEBUGFS_WRITE_FUNC(name) \
  65. static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
  66. const char __user *user_buf, \
  67. size_t count, loff_t *ppos);
  68. static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
  69. {
  70. file->private_data = inode->i_private;
  71. return 0;
  72. }
  73. #define DEBUGFS_READ_FILE_OPS(name) \
  74. DEBUGFS_READ_FUNC(name); \
  75. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  76. .read = iwl_dbgfs_##name##_read, \
  77. .open = iwl_dbgfs_open_file_generic, \
  78. .llseek = generic_file_llseek, \
  79. };
  80. #define DEBUGFS_WRITE_FILE_OPS(name) \
  81. DEBUGFS_WRITE_FUNC(name); \
  82. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  83. .write = iwl_dbgfs_##name##_write, \
  84. .open = iwl_dbgfs_open_file_generic, \
  85. .llseek = generic_file_llseek, \
  86. };
  87. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  88. DEBUGFS_READ_FUNC(name); \
  89. DEBUGFS_WRITE_FUNC(name); \
  90. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  91. .write = iwl_dbgfs_##name##_write, \
  92. .read = iwl_dbgfs_##name##_read, \
  93. .open = iwl_dbgfs_open_file_generic, \
  94. .llseek = generic_file_llseek, \
  95. };
  96. static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
  97. char __user *user_buf,
  98. size_t count, loff_t *ppos) {
  99. struct iwl_priv *priv = file->private_data;
  100. char *buf;
  101. int pos = 0;
  102. int cnt;
  103. ssize_t ret;
  104. const size_t bufsz = 100 +
  105. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  106. buf = kzalloc(bufsz, GFP_KERNEL);
  107. if (!buf)
  108. return -ENOMEM;
  109. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  110. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  111. pos += scnprintf(buf + pos, bufsz - pos,
  112. "\t%25s\t\t: %u\n",
  113. get_mgmt_string(cnt),
  114. priv->tx_stats.mgmt[cnt]);
  115. }
  116. pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
  117. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  118. pos += scnprintf(buf + pos, bufsz - pos,
  119. "\t%25s\t\t: %u\n",
  120. get_ctrl_string(cnt),
  121. priv->tx_stats.ctrl[cnt]);
  122. }
  123. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  124. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  125. priv->tx_stats.data_cnt);
  126. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  127. priv->tx_stats.data_bytes);
  128. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  129. kfree(buf);
  130. return ret;
  131. }
  132. static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
  133. const char __user *user_buf,
  134. size_t count, loff_t *ppos)
  135. {
  136. struct iwl_priv *priv = file->private_data;
  137. u32 clear_flag;
  138. char buf[8];
  139. int buf_size;
  140. memset(buf, 0, sizeof(buf));
  141. buf_size = min(count, sizeof(buf) - 1);
  142. if (copy_from_user(buf, user_buf, buf_size))
  143. return -EFAULT;
  144. if (sscanf(buf, "%x", &clear_flag) != 1)
  145. return -EFAULT;
  146. iwl_clear_traffic_stats(priv);
  147. return count;
  148. }
  149. static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
  150. char __user *user_buf,
  151. size_t count, loff_t *ppos) {
  152. struct iwl_priv *priv = file->private_data;
  153. char *buf;
  154. int pos = 0;
  155. int cnt;
  156. ssize_t ret;
  157. const size_t bufsz = 100 +
  158. sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
  159. buf = kzalloc(bufsz, GFP_KERNEL);
  160. if (!buf)
  161. return -ENOMEM;
  162. pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
  163. for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
  164. pos += scnprintf(buf + pos, bufsz - pos,
  165. "\t%25s\t\t: %u\n",
  166. get_mgmt_string(cnt),
  167. priv->rx_stats.mgmt[cnt]);
  168. }
  169. pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
  170. for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
  171. pos += scnprintf(buf + pos, bufsz - pos,
  172. "\t%25s\t\t: %u\n",
  173. get_ctrl_string(cnt),
  174. priv->rx_stats.ctrl[cnt]);
  175. }
  176. pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
  177. pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
  178. priv->rx_stats.data_cnt);
  179. pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
  180. priv->rx_stats.data_bytes);
  181. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  182. kfree(buf);
  183. return ret;
  184. }
  185. static ssize_t iwl_dbgfs_sram_read(struct file *file,
  186. char __user *user_buf,
  187. size_t count, loff_t *ppos)
  188. {
  189. u32 val = 0;
  190. char *buf;
  191. ssize_t ret;
  192. int i = 0;
  193. bool device_format = false;
  194. int offset = 0;
  195. int len = 0;
  196. int pos = 0;
  197. int sram;
  198. struct iwl_priv *priv = file->private_data;
  199. size_t bufsz;
  200. /* default is to dump the entire data segment */
  201. if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
  202. priv->dbgfs_sram_offset = 0x800000;
  203. if (priv->ucode_type == IWL_UCODE_INIT)
  204. priv->dbgfs_sram_len = priv->ucode_init.data.len;
  205. else
  206. priv->dbgfs_sram_len = priv->ucode_rt.data.len;
  207. }
  208. len = priv->dbgfs_sram_len;
  209. if (len == -4) {
  210. device_format = true;
  211. len = 4;
  212. }
  213. bufsz = 50 + len * 4;
  214. buf = kmalloc(bufsz, GFP_KERNEL);
  215. if (!buf)
  216. return -ENOMEM;
  217. pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
  218. len);
  219. pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
  220. priv->dbgfs_sram_offset);
  221. /* adjust sram address since reads are only on even u32 boundaries */
  222. offset = priv->dbgfs_sram_offset & 0x3;
  223. sram = priv->dbgfs_sram_offset & ~0x3;
  224. /* read the first u32 from sram */
  225. val = iwl_read_targ_mem(bus(priv), sram);
  226. for (; len; len--) {
  227. /* put the address at the start of every line */
  228. if (i == 0)
  229. pos += scnprintf(buf + pos, bufsz - pos,
  230. "%08X: ", sram + offset);
  231. if (device_format)
  232. pos += scnprintf(buf + pos, bufsz - pos,
  233. "%02x", (val >> (8 * (3 - offset))) & 0xff);
  234. else
  235. pos += scnprintf(buf + pos, bufsz - pos,
  236. "%02x ", (val >> (8 * offset)) & 0xff);
  237. /* if all bytes processed, read the next u32 from sram */
  238. if (++offset == 4) {
  239. sram += 4;
  240. offset = 0;
  241. val = iwl_read_targ_mem(bus(priv), sram);
  242. }
  243. /* put in extra spaces and split lines for human readability */
  244. if (++i == 16) {
  245. i = 0;
  246. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  247. } else if (!(i & 7)) {
  248. pos += scnprintf(buf + pos, bufsz - pos, " ");
  249. } else if (!(i & 3)) {
  250. pos += scnprintf(buf + pos, bufsz - pos, " ");
  251. }
  252. }
  253. if (i)
  254. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  255. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  256. kfree(buf);
  257. return ret;
  258. }
  259. static ssize_t iwl_dbgfs_sram_write(struct file *file,
  260. const char __user *user_buf,
  261. size_t count, loff_t *ppos)
  262. {
  263. struct iwl_priv *priv = file->private_data;
  264. char buf[64];
  265. int buf_size;
  266. u32 offset, len;
  267. memset(buf, 0, sizeof(buf));
  268. buf_size = min(count, sizeof(buf) - 1);
  269. if (copy_from_user(buf, user_buf, buf_size))
  270. return -EFAULT;
  271. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  272. priv->dbgfs_sram_offset = offset;
  273. priv->dbgfs_sram_len = len;
  274. } else if (sscanf(buf, "%x", &offset) == 1) {
  275. priv->dbgfs_sram_offset = offset;
  276. priv->dbgfs_sram_len = -4;
  277. } else {
  278. priv->dbgfs_sram_offset = 0;
  279. priv->dbgfs_sram_len = 0;
  280. }
  281. return count;
  282. }
  283. static ssize_t iwl_dbgfs_wowlan_sram_read(struct file *file,
  284. char __user *user_buf,
  285. size_t count, loff_t *ppos)
  286. {
  287. struct iwl_priv *priv = file->private_data;
  288. if (!priv->wowlan_sram)
  289. return -ENODATA;
  290. return simple_read_from_buffer(user_buf, count, ppos,
  291. priv->wowlan_sram,
  292. priv->ucode_wowlan.data.len);
  293. }
  294. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  295. size_t count, loff_t *ppos)
  296. {
  297. struct iwl_priv *priv = file->private_data;
  298. struct iwl_station_entry *station;
  299. struct iwl_tid_data *tid_data;
  300. int max_sta = hw_params(priv).max_stations;
  301. char *buf;
  302. int i, j, pos = 0;
  303. ssize_t ret;
  304. /* Add 30 for initial string */
  305. const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
  306. buf = kmalloc(bufsz, GFP_KERNEL);
  307. if (!buf)
  308. return -ENOMEM;
  309. pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
  310. priv->num_stations);
  311. for (i = 0; i < max_sta; i++) {
  312. station = &priv->stations[i];
  313. if (!station->used)
  314. continue;
  315. pos += scnprintf(buf + pos, bufsz - pos,
  316. "station %d - addr: %pM, flags: %#x\n",
  317. i, station->sta.sta.addr,
  318. station->sta.station_flags_msk);
  319. pos += scnprintf(buf + pos, bufsz - pos,
  320. "TID\tseq_num\ttxq_id\ttfds\trate_n_flags\n");
  321. for (j = 0; j < IWL_MAX_TID_COUNT; j++) {
  322. tid_data = &priv->shrd->tid_data[i][j];
  323. pos += scnprintf(buf + pos, bufsz - pos,
  324. "%d:\t%#x\t%#x\t%u\t%#x",
  325. j, tid_data->seq_number,
  326. tid_data->agg.txq_id,
  327. tid_data->tfds_in_queue,
  328. tid_data->agg.rate_n_flags);
  329. if (tid_data->agg.wait_for_ba)
  330. pos += scnprintf(buf + pos, bufsz - pos,
  331. " - waitforba");
  332. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  333. }
  334. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  335. }
  336. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  337. kfree(buf);
  338. return ret;
  339. }
  340. static ssize_t iwl_dbgfs_nvm_read(struct file *file,
  341. char __user *user_buf,
  342. size_t count,
  343. loff_t *ppos)
  344. {
  345. ssize_t ret;
  346. struct iwl_priv *priv = file->private_data;
  347. int pos = 0, ofs = 0, buf_size = 0;
  348. const u8 *ptr;
  349. char *buf;
  350. u16 eeprom_ver;
  351. size_t eeprom_len = priv->cfg->base_params->eeprom_size;
  352. buf_size = 4 * eeprom_len + 256;
  353. if (eeprom_len % 16) {
  354. IWL_ERR(priv, "NVM size is not multiple of 16.\n");
  355. return -ENODATA;
  356. }
  357. ptr = priv->eeprom;
  358. if (!ptr) {
  359. IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
  360. return -ENOMEM;
  361. }
  362. /* 4 characters for byte 0xYY */
  363. buf = kzalloc(buf_size, GFP_KERNEL);
  364. if (!buf) {
  365. IWL_ERR(priv, "Can not allocate Buffer\n");
  366. return -ENOMEM;
  367. }
  368. eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
  369. pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
  370. "version: 0x%x\n",
  371. (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
  372. ? "OTP" : "EEPROM", eeprom_ver);
  373. for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
  374. pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
  375. hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
  376. buf_size - pos, 0);
  377. pos += strlen(buf + pos);
  378. if (buf_size - pos > 0)
  379. buf[pos++] = '\n';
  380. }
  381. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  382. kfree(buf);
  383. return ret;
  384. }
  385. static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
  386. size_t count, loff_t *ppos)
  387. {
  388. struct iwl_priv *priv = file->private_data;
  389. struct ieee80211_channel *channels = NULL;
  390. const struct ieee80211_supported_band *supp_band = NULL;
  391. int pos = 0, i, bufsz = PAGE_SIZE;
  392. char *buf;
  393. ssize_t ret;
  394. if (!test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status))
  395. return -EAGAIN;
  396. buf = kzalloc(bufsz, GFP_KERNEL);
  397. if (!buf) {
  398. IWL_ERR(priv, "Can not allocate Buffer\n");
  399. return -ENOMEM;
  400. }
  401. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
  402. if (supp_band) {
  403. channels = supp_band->channels;
  404. pos += scnprintf(buf + pos, bufsz - pos,
  405. "Displaying %d channels in 2.4GHz band 802.11bg):\n",
  406. supp_band->n_channels);
  407. for (i = 0; i < supp_band->n_channels; i++)
  408. pos += scnprintf(buf + pos, bufsz - pos,
  409. "%d: %ddBm: BSS%s%s, %s.\n",
  410. channels[i].hw_value,
  411. channels[i].max_power,
  412. channels[i].flags & IEEE80211_CHAN_RADAR ?
  413. " (IEEE 802.11h required)" : "",
  414. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  415. || (channels[i].flags &
  416. IEEE80211_CHAN_RADAR)) ? "" :
  417. ", IBSS",
  418. channels[i].flags &
  419. IEEE80211_CHAN_PASSIVE_SCAN ?
  420. "passive only" : "active/passive");
  421. }
  422. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
  423. if (supp_band) {
  424. channels = supp_band->channels;
  425. pos += scnprintf(buf + pos, bufsz - pos,
  426. "Displaying %d channels in 5.2GHz band (802.11a)\n",
  427. supp_band->n_channels);
  428. for (i = 0; i < supp_band->n_channels; i++)
  429. pos += scnprintf(buf + pos, bufsz - pos,
  430. "%d: %ddBm: BSS%s%s, %s.\n",
  431. channels[i].hw_value,
  432. channels[i].max_power,
  433. channels[i].flags & IEEE80211_CHAN_RADAR ?
  434. " (IEEE 802.11h required)" : "",
  435. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  436. || (channels[i].flags &
  437. IEEE80211_CHAN_RADAR)) ? "" :
  438. ", IBSS",
  439. channels[i].flags &
  440. IEEE80211_CHAN_PASSIVE_SCAN ?
  441. "passive only" : "active/passive");
  442. }
  443. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  444. kfree(buf);
  445. return ret;
  446. }
  447. static ssize_t iwl_dbgfs_status_read(struct file *file,
  448. char __user *user_buf,
  449. size_t count, loff_t *ppos) {
  450. struct iwl_priv *priv = file->private_data;
  451. char buf[512];
  452. int pos = 0;
  453. const size_t bufsz = sizeof(buf);
  454. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
  455. test_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status));
  456. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
  457. test_bit(STATUS_INT_ENABLED, &priv->shrd->status));
  458. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
  459. test_bit(STATUS_RF_KILL_HW, &priv->shrd->status));
  460. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
  461. test_bit(STATUS_CT_KILL, &priv->shrd->status));
  462. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
  463. test_bit(STATUS_INIT, &priv->shrd->status));
  464. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
  465. test_bit(STATUS_ALIVE, &priv->shrd->status));
  466. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
  467. test_bit(STATUS_READY, &priv->shrd->status));
  468. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
  469. test_bit(STATUS_TEMPERATURE, &priv->shrd->status));
  470. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
  471. test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status));
  472. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
  473. test_bit(STATUS_EXIT_PENDING, &priv->shrd->status));
  474. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
  475. test_bit(STATUS_STATISTICS, &priv->shrd->status));
  476. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
  477. test_bit(STATUS_SCANNING, &priv->shrd->status));
  478. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
  479. test_bit(STATUS_SCAN_ABORTING, &priv->shrd->status));
  480. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
  481. test_bit(STATUS_SCAN_HW, &priv->shrd->status));
  482. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
  483. test_bit(STATUS_POWER_PMI, &priv->shrd->status));
  484. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
  485. test_bit(STATUS_FW_ERROR, &priv->shrd->status));
  486. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  487. }
  488. static ssize_t iwl_dbgfs_rx_handlers_read(struct file *file,
  489. char __user *user_buf,
  490. size_t count, loff_t *ppos) {
  491. struct iwl_priv *priv = file->private_data;
  492. int pos = 0;
  493. int cnt = 0;
  494. char *buf;
  495. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  496. ssize_t ret;
  497. buf = kzalloc(bufsz, GFP_KERNEL);
  498. if (!buf) {
  499. IWL_ERR(priv, "Can not allocate Buffer\n");
  500. return -ENOMEM;
  501. }
  502. for (cnt = 0; cnt < REPLY_MAX; cnt++) {
  503. if (priv->rx_handlers_stats[cnt] > 0)
  504. pos += scnprintf(buf + pos, bufsz - pos,
  505. "\tRx handler[%36s]:\t\t %u\n",
  506. get_cmd_string(cnt),
  507. priv->rx_handlers_stats[cnt]);
  508. }
  509. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  510. kfree(buf);
  511. return ret;
  512. }
  513. static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
  514. const char __user *user_buf,
  515. size_t count, loff_t *ppos)
  516. {
  517. struct iwl_priv *priv = file->private_data;
  518. char buf[8];
  519. int buf_size;
  520. u32 reset_flag;
  521. memset(buf, 0, sizeof(buf));
  522. buf_size = min(count, sizeof(buf) - 1);
  523. if (copy_from_user(buf, user_buf, buf_size))
  524. return -EFAULT;
  525. if (sscanf(buf, "%x", &reset_flag) != 1)
  526. return -EFAULT;
  527. if (reset_flag == 0)
  528. memset(&priv->rx_handlers_stats[0], 0,
  529. sizeof(priv->rx_handlers_stats));
  530. return count;
  531. }
  532. static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
  533. size_t count, loff_t *ppos)
  534. {
  535. struct iwl_priv *priv = file->private_data;
  536. struct iwl_rxon_context *ctx;
  537. int pos = 0, i;
  538. char buf[256 * NUM_IWL_RXON_CTX];
  539. const size_t bufsz = sizeof(buf);
  540. for_each_context(priv, ctx) {
  541. pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
  542. ctx->ctxid);
  543. for (i = 0; i < AC_NUM; i++) {
  544. pos += scnprintf(buf + pos, bufsz - pos,
  545. "\tcw_min\tcw_max\taifsn\ttxop\n");
  546. pos += scnprintf(buf + pos, bufsz - pos,
  547. "AC[%d]\t%u\t%u\t%u\t%u\n", i,
  548. ctx->qos_data.def_qos_parm.ac[i].cw_min,
  549. ctx->qos_data.def_qos_parm.ac[i].cw_max,
  550. ctx->qos_data.def_qos_parm.ac[i].aifsn,
  551. ctx->qos_data.def_qos_parm.ac[i].edca_txop);
  552. }
  553. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  554. }
  555. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  556. }
  557. static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
  558. char __user *user_buf,
  559. size_t count, loff_t *ppos)
  560. {
  561. struct iwl_priv *priv = file->private_data;
  562. struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
  563. struct iwl_tt_restriction *restriction;
  564. char buf[100];
  565. int pos = 0;
  566. const size_t bufsz = sizeof(buf);
  567. pos += scnprintf(buf + pos, bufsz - pos,
  568. "Thermal Throttling Mode: %s\n",
  569. tt->advanced_tt ? "Advance" : "Legacy");
  570. pos += scnprintf(buf + pos, bufsz - pos,
  571. "Thermal Throttling State: %d\n",
  572. tt->state);
  573. if (tt->advanced_tt) {
  574. restriction = tt->restriction + tt->state;
  575. pos += scnprintf(buf + pos, bufsz - pos,
  576. "Tx mode: %d\n",
  577. restriction->tx_stream);
  578. pos += scnprintf(buf + pos, bufsz - pos,
  579. "Rx mode: %d\n",
  580. restriction->rx_stream);
  581. pos += scnprintf(buf + pos, bufsz - pos,
  582. "HT mode: %d\n",
  583. restriction->is_ht);
  584. }
  585. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  586. }
  587. static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
  588. const char __user *user_buf,
  589. size_t count, loff_t *ppos)
  590. {
  591. struct iwl_priv *priv = file->private_data;
  592. char buf[8];
  593. int buf_size;
  594. int ht40;
  595. memset(buf, 0, sizeof(buf));
  596. buf_size = min(count, sizeof(buf) - 1);
  597. if (copy_from_user(buf, user_buf, buf_size))
  598. return -EFAULT;
  599. if (sscanf(buf, "%d", &ht40) != 1)
  600. return -EFAULT;
  601. if (!iwl_is_any_associated(priv))
  602. priv->disable_ht40 = ht40 ? true : false;
  603. else {
  604. IWL_ERR(priv, "Sta associated with AP - "
  605. "Change to 40MHz channel support is not allowed\n");
  606. return -EINVAL;
  607. }
  608. return count;
  609. }
  610. static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
  611. char __user *user_buf,
  612. size_t count, loff_t *ppos)
  613. {
  614. struct iwl_priv *priv = file->private_data;
  615. char buf[100];
  616. int pos = 0;
  617. const size_t bufsz = sizeof(buf);
  618. pos += scnprintf(buf + pos, bufsz - pos,
  619. "11n 40MHz Mode: %s\n",
  620. priv->disable_ht40 ? "Disabled" : "Enabled");
  621. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  622. }
  623. static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
  624. const char __user *user_buf,
  625. size_t count, loff_t *ppos)
  626. {
  627. struct iwl_priv *priv = file->private_data;
  628. char buf[8];
  629. int buf_size;
  630. int value;
  631. memset(buf, 0, sizeof(buf));
  632. buf_size = min(count, sizeof(buf) - 1);
  633. if (copy_from_user(buf, user_buf, buf_size))
  634. return -EFAULT;
  635. if (sscanf(buf, "%d", &value) != 1)
  636. return -EINVAL;
  637. /*
  638. * Our users expect 0 to be "CAM", but 0 isn't actually
  639. * valid here. However, let's not confuse them and present
  640. * IWL_POWER_INDEX_1 as "1", not "0".
  641. */
  642. if (value == 0)
  643. return -EINVAL;
  644. else if (value > 0)
  645. value -= 1;
  646. if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
  647. return -EINVAL;
  648. if (!iwl_is_ready_rf(priv->shrd))
  649. return -EAGAIN;
  650. priv->power_data.debug_sleep_level_override = value;
  651. mutex_lock(&priv->shrd->mutex);
  652. iwl_power_update_mode(priv, true);
  653. mutex_unlock(&priv->shrd->mutex);
  654. return count;
  655. }
  656. static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
  657. char __user *user_buf,
  658. size_t count, loff_t *ppos)
  659. {
  660. struct iwl_priv *priv = file->private_data;
  661. char buf[10];
  662. int pos, value;
  663. const size_t bufsz = sizeof(buf);
  664. /* see the write function */
  665. value = priv->power_data.debug_sleep_level_override;
  666. if (value >= 0)
  667. value += 1;
  668. pos = scnprintf(buf, bufsz, "%d\n", value);
  669. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  670. }
  671. static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
  672. char __user *user_buf,
  673. size_t count, loff_t *ppos)
  674. {
  675. struct iwl_priv *priv = file->private_data;
  676. char buf[200];
  677. int pos = 0, i;
  678. const size_t bufsz = sizeof(buf);
  679. struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
  680. pos += scnprintf(buf + pos, bufsz - pos,
  681. "flags: %#.2x\n", le16_to_cpu(cmd->flags));
  682. pos += scnprintf(buf + pos, bufsz - pos,
  683. "RX/TX timeout: %d/%d usec\n",
  684. le32_to_cpu(cmd->rx_data_timeout),
  685. le32_to_cpu(cmd->tx_data_timeout));
  686. for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
  687. pos += scnprintf(buf + pos, bufsz - pos,
  688. "sleep_interval[%d]: %d\n", i,
  689. le32_to_cpu(cmd->sleep_interval[i]));
  690. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  691. }
  692. DEBUGFS_READ_WRITE_FILE_OPS(sram);
  693. DEBUGFS_READ_FILE_OPS(wowlan_sram);
  694. DEBUGFS_READ_FILE_OPS(nvm);
  695. DEBUGFS_READ_FILE_OPS(stations);
  696. DEBUGFS_READ_FILE_OPS(channels);
  697. DEBUGFS_READ_FILE_OPS(status);
  698. DEBUGFS_READ_WRITE_FILE_OPS(rx_handlers);
  699. DEBUGFS_READ_FILE_OPS(qos);
  700. DEBUGFS_READ_FILE_OPS(thermal_throttling);
  701. DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
  702. DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
  703. DEBUGFS_READ_FILE_OPS(current_sleep_command);
  704. static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
  705. char __user *user_buf,
  706. size_t count, loff_t *ppos)
  707. {
  708. struct iwl_priv *priv = file->private_data;
  709. int pos = 0, ofs = 0;
  710. int cnt = 0, entry;
  711. char *buf;
  712. int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
  713. (hw_params(priv).max_txq_num * 32 * 8) + 400;
  714. const u8 *ptr;
  715. ssize_t ret;
  716. buf = kzalloc(bufsz, GFP_KERNEL);
  717. if (!buf) {
  718. IWL_ERR(priv, "Can not allocate buffer\n");
  719. return -ENOMEM;
  720. }
  721. if (priv->tx_traffic &&
  722. (iwl_get_debug_level(priv->shrd) & IWL_DL_TX)) {
  723. ptr = priv->tx_traffic;
  724. pos += scnprintf(buf + pos, bufsz - pos,
  725. "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
  726. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  727. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  728. entry++, ofs += 16) {
  729. pos += scnprintf(buf + pos, bufsz - pos,
  730. "0x%.4x ", ofs);
  731. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  732. buf + pos, bufsz - pos, 0);
  733. pos += strlen(buf + pos);
  734. if (bufsz - pos > 0)
  735. buf[pos++] = '\n';
  736. }
  737. }
  738. }
  739. if (priv->rx_traffic &&
  740. (iwl_get_debug_level(priv->shrd) & IWL_DL_RX)) {
  741. ptr = priv->rx_traffic;
  742. pos += scnprintf(buf + pos, bufsz - pos,
  743. "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
  744. for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
  745. for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
  746. entry++, ofs += 16) {
  747. pos += scnprintf(buf + pos, bufsz - pos,
  748. "0x%.4x ", ofs);
  749. hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
  750. buf + pos, bufsz - pos, 0);
  751. pos += strlen(buf + pos);
  752. if (bufsz - pos > 0)
  753. buf[pos++] = '\n';
  754. }
  755. }
  756. }
  757. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  758. kfree(buf);
  759. return ret;
  760. }
  761. static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
  762. const char __user *user_buf,
  763. size_t count, loff_t *ppos)
  764. {
  765. struct iwl_priv *priv = file->private_data;
  766. char buf[8];
  767. int buf_size;
  768. int traffic_log;
  769. memset(buf, 0, sizeof(buf));
  770. buf_size = min(count, sizeof(buf) - 1);
  771. if (copy_from_user(buf, user_buf, buf_size))
  772. return -EFAULT;
  773. if (sscanf(buf, "%d", &traffic_log) != 1)
  774. return -EFAULT;
  775. if (traffic_log == 0)
  776. iwl_reset_traffic_log(priv);
  777. return count;
  778. }
  779. static const char *fmt_value = " %-30s %10u\n";
  780. static const char *fmt_hex = " %-30s 0x%02X\n";
  781. static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
  782. static const char *fmt_header =
  783. "%-32s current cumulative delta max\n";
  784. static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
  785. {
  786. int p = 0;
  787. u32 flag;
  788. flag = le32_to_cpu(priv->statistics.flag);
  789. p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag);
  790. if (flag & UCODE_STATISTICS_CLEAR_MSK)
  791. p += scnprintf(buf + p, bufsz - p,
  792. "\tStatistics have been cleared\n");
  793. p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
  794. (flag & UCODE_STATISTICS_FREQUENCY_MSK)
  795. ? "2.4 GHz" : "5.2 GHz");
  796. p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
  797. (flag & UCODE_STATISTICS_NARROW_BAND_MSK)
  798. ? "enabled" : "disabled");
  799. return p;
  800. }
  801. static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
  802. char __user *user_buf,
  803. size_t count, loff_t *ppos)
  804. {
  805. struct iwl_priv *priv = file->private_data;
  806. int pos = 0;
  807. char *buf;
  808. int bufsz = sizeof(struct statistics_rx_phy) * 40 +
  809. sizeof(struct statistics_rx_non_phy) * 40 +
  810. sizeof(struct statistics_rx_ht_phy) * 40 + 400;
  811. ssize_t ret;
  812. struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm;
  813. struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck;
  814. struct statistics_rx_non_phy *general, *accum_general;
  815. struct statistics_rx_non_phy *delta_general, *max_general;
  816. struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht;
  817. if (!iwl_is_alive(priv->shrd))
  818. return -EAGAIN;
  819. buf = kzalloc(bufsz, GFP_KERNEL);
  820. if (!buf) {
  821. IWL_ERR(priv, "Can not allocate Buffer\n");
  822. return -ENOMEM;
  823. }
  824. /*
  825. * the statistic information display here is based on
  826. * the last statistics notification from uCode
  827. * might not reflect the current uCode activity
  828. */
  829. ofdm = &priv->statistics.rx_ofdm;
  830. cck = &priv->statistics.rx_cck;
  831. general = &priv->statistics.rx_non_phy;
  832. ht = &priv->statistics.rx_ofdm_ht;
  833. accum_ofdm = &priv->accum_stats.rx_ofdm;
  834. accum_cck = &priv->accum_stats.rx_cck;
  835. accum_general = &priv->accum_stats.rx_non_phy;
  836. accum_ht = &priv->accum_stats.rx_ofdm_ht;
  837. delta_ofdm = &priv->delta_stats.rx_ofdm;
  838. delta_cck = &priv->delta_stats.rx_cck;
  839. delta_general = &priv->delta_stats.rx_non_phy;
  840. delta_ht = &priv->delta_stats.rx_ofdm_ht;
  841. max_ofdm = &priv->max_delta_stats.rx_ofdm;
  842. max_cck = &priv->max_delta_stats.rx_cck;
  843. max_general = &priv->max_delta_stats.rx_non_phy;
  844. max_ht = &priv->max_delta_stats.rx_ofdm_ht;
  845. pos += iwl_statistics_flag(priv, buf, bufsz);
  846. pos += scnprintf(buf + pos, bufsz - pos,
  847. fmt_header, "Statistics_Rx - OFDM:");
  848. pos += scnprintf(buf + pos, bufsz - pos,
  849. fmt_table, "ina_cnt:",
  850. le32_to_cpu(ofdm->ina_cnt),
  851. accum_ofdm->ina_cnt,
  852. delta_ofdm->ina_cnt, max_ofdm->ina_cnt);
  853. pos += scnprintf(buf + pos, bufsz - pos,
  854. fmt_table, "fina_cnt:",
  855. le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt,
  856. delta_ofdm->fina_cnt, max_ofdm->fina_cnt);
  857. pos += scnprintf(buf + pos, bufsz - pos,
  858. fmt_table, "plcp_err:",
  859. le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err,
  860. delta_ofdm->plcp_err, max_ofdm->plcp_err);
  861. pos += scnprintf(buf + pos, bufsz - pos,
  862. fmt_table, "crc32_err:",
  863. le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err,
  864. delta_ofdm->crc32_err, max_ofdm->crc32_err);
  865. pos += scnprintf(buf + pos, bufsz - pos,
  866. fmt_table, "overrun_err:",
  867. le32_to_cpu(ofdm->overrun_err),
  868. accum_ofdm->overrun_err, delta_ofdm->overrun_err,
  869. max_ofdm->overrun_err);
  870. pos += scnprintf(buf + pos, bufsz - pos,
  871. fmt_table, "early_overrun_err:",
  872. le32_to_cpu(ofdm->early_overrun_err),
  873. accum_ofdm->early_overrun_err,
  874. delta_ofdm->early_overrun_err,
  875. max_ofdm->early_overrun_err);
  876. pos += scnprintf(buf + pos, bufsz - pos,
  877. fmt_table, "crc32_good:",
  878. le32_to_cpu(ofdm->crc32_good),
  879. accum_ofdm->crc32_good, delta_ofdm->crc32_good,
  880. max_ofdm->crc32_good);
  881. pos += scnprintf(buf + pos, bufsz - pos,
  882. fmt_table, "false_alarm_cnt:",
  883. le32_to_cpu(ofdm->false_alarm_cnt),
  884. accum_ofdm->false_alarm_cnt,
  885. delta_ofdm->false_alarm_cnt,
  886. max_ofdm->false_alarm_cnt);
  887. pos += scnprintf(buf + pos, bufsz - pos,
  888. fmt_table, "fina_sync_err_cnt:",
  889. le32_to_cpu(ofdm->fina_sync_err_cnt),
  890. accum_ofdm->fina_sync_err_cnt,
  891. delta_ofdm->fina_sync_err_cnt,
  892. max_ofdm->fina_sync_err_cnt);
  893. pos += scnprintf(buf + pos, bufsz - pos,
  894. fmt_table, "sfd_timeout:",
  895. le32_to_cpu(ofdm->sfd_timeout),
  896. accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout,
  897. max_ofdm->sfd_timeout);
  898. pos += scnprintf(buf + pos, bufsz - pos,
  899. fmt_table, "fina_timeout:",
  900. le32_to_cpu(ofdm->fina_timeout),
  901. accum_ofdm->fina_timeout, delta_ofdm->fina_timeout,
  902. max_ofdm->fina_timeout);
  903. pos += scnprintf(buf + pos, bufsz - pos,
  904. fmt_table, "unresponded_rts:",
  905. le32_to_cpu(ofdm->unresponded_rts),
  906. accum_ofdm->unresponded_rts,
  907. delta_ofdm->unresponded_rts,
  908. max_ofdm->unresponded_rts);
  909. pos += scnprintf(buf + pos, bufsz - pos,
  910. fmt_table, "rxe_frame_lmt_ovrun:",
  911. le32_to_cpu(ofdm->rxe_frame_limit_overrun),
  912. accum_ofdm->rxe_frame_limit_overrun,
  913. delta_ofdm->rxe_frame_limit_overrun,
  914. max_ofdm->rxe_frame_limit_overrun);
  915. pos += scnprintf(buf + pos, bufsz - pos,
  916. fmt_table, "sent_ack_cnt:",
  917. le32_to_cpu(ofdm->sent_ack_cnt),
  918. accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt,
  919. max_ofdm->sent_ack_cnt);
  920. pos += scnprintf(buf + pos, bufsz - pos,
  921. fmt_table, "sent_cts_cnt:",
  922. le32_to_cpu(ofdm->sent_cts_cnt),
  923. accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt,
  924. max_ofdm->sent_cts_cnt);
  925. pos += scnprintf(buf + pos, bufsz - pos,
  926. fmt_table, "sent_ba_rsp_cnt:",
  927. le32_to_cpu(ofdm->sent_ba_rsp_cnt),
  928. accum_ofdm->sent_ba_rsp_cnt,
  929. delta_ofdm->sent_ba_rsp_cnt,
  930. max_ofdm->sent_ba_rsp_cnt);
  931. pos += scnprintf(buf + pos, bufsz - pos,
  932. fmt_table, "dsp_self_kill:",
  933. le32_to_cpu(ofdm->dsp_self_kill),
  934. accum_ofdm->dsp_self_kill,
  935. delta_ofdm->dsp_self_kill,
  936. max_ofdm->dsp_self_kill);
  937. pos += scnprintf(buf + pos, bufsz - pos,
  938. fmt_table, "mh_format_err:",
  939. le32_to_cpu(ofdm->mh_format_err),
  940. accum_ofdm->mh_format_err,
  941. delta_ofdm->mh_format_err,
  942. max_ofdm->mh_format_err);
  943. pos += scnprintf(buf + pos, bufsz - pos,
  944. fmt_table, "re_acq_main_rssi_sum:",
  945. le32_to_cpu(ofdm->re_acq_main_rssi_sum),
  946. accum_ofdm->re_acq_main_rssi_sum,
  947. delta_ofdm->re_acq_main_rssi_sum,
  948. max_ofdm->re_acq_main_rssi_sum);
  949. pos += scnprintf(buf + pos, bufsz - pos,
  950. fmt_header, "Statistics_Rx - CCK:");
  951. pos += scnprintf(buf + pos, bufsz - pos,
  952. fmt_table, "ina_cnt:",
  953. le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt,
  954. delta_cck->ina_cnt, max_cck->ina_cnt);
  955. pos += scnprintf(buf + pos, bufsz - pos,
  956. fmt_table, "fina_cnt:",
  957. le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt,
  958. delta_cck->fina_cnt, max_cck->fina_cnt);
  959. pos += scnprintf(buf + pos, bufsz - pos,
  960. fmt_table, "plcp_err:",
  961. le32_to_cpu(cck->plcp_err), accum_cck->plcp_err,
  962. delta_cck->plcp_err, max_cck->plcp_err);
  963. pos += scnprintf(buf + pos, bufsz - pos,
  964. fmt_table, "crc32_err:",
  965. le32_to_cpu(cck->crc32_err), accum_cck->crc32_err,
  966. delta_cck->crc32_err, max_cck->crc32_err);
  967. pos += scnprintf(buf + pos, bufsz - pos,
  968. fmt_table, "overrun_err:",
  969. le32_to_cpu(cck->overrun_err),
  970. accum_cck->overrun_err, delta_cck->overrun_err,
  971. max_cck->overrun_err);
  972. pos += scnprintf(buf + pos, bufsz - pos,
  973. fmt_table, "early_overrun_err:",
  974. le32_to_cpu(cck->early_overrun_err),
  975. accum_cck->early_overrun_err,
  976. delta_cck->early_overrun_err,
  977. max_cck->early_overrun_err);
  978. pos += scnprintf(buf + pos, bufsz - pos,
  979. fmt_table, "crc32_good:",
  980. le32_to_cpu(cck->crc32_good), accum_cck->crc32_good,
  981. delta_cck->crc32_good, max_cck->crc32_good);
  982. pos += scnprintf(buf + pos, bufsz - pos,
  983. fmt_table, "false_alarm_cnt:",
  984. le32_to_cpu(cck->false_alarm_cnt),
  985. accum_cck->false_alarm_cnt,
  986. delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt);
  987. pos += scnprintf(buf + pos, bufsz - pos,
  988. fmt_table, "fina_sync_err_cnt:",
  989. le32_to_cpu(cck->fina_sync_err_cnt),
  990. accum_cck->fina_sync_err_cnt,
  991. delta_cck->fina_sync_err_cnt,
  992. max_cck->fina_sync_err_cnt);
  993. pos += scnprintf(buf + pos, bufsz - pos,
  994. fmt_table, "sfd_timeout:",
  995. le32_to_cpu(cck->sfd_timeout),
  996. accum_cck->sfd_timeout, delta_cck->sfd_timeout,
  997. max_cck->sfd_timeout);
  998. pos += scnprintf(buf + pos, bufsz - pos,
  999. fmt_table, "fina_timeout:",
  1000. le32_to_cpu(cck->fina_timeout),
  1001. accum_cck->fina_timeout, delta_cck->fina_timeout,
  1002. max_cck->fina_timeout);
  1003. pos += scnprintf(buf + pos, bufsz - pos,
  1004. fmt_table, "unresponded_rts:",
  1005. le32_to_cpu(cck->unresponded_rts),
  1006. accum_cck->unresponded_rts, delta_cck->unresponded_rts,
  1007. max_cck->unresponded_rts);
  1008. pos += scnprintf(buf + pos, bufsz - pos,
  1009. fmt_table, "rxe_frame_lmt_ovrun:",
  1010. le32_to_cpu(cck->rxe_frame_limit_overrun),
  1011. accum_cck->rxe_frame_limit_overrun,
  1012. delta_cck->rxe_frame_limit_overrun,
  1013. max_cck->rxe_frame_limit_overrun);
  1014. pos += scnprintf(buf + pos, bufsz - pos,
  1015. fmt_table, "sent_ack_cnt:",
  1016. le32_to_cpu(cck->sent_ack_cnt),
  1017. accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt,
  1018. max_cck->sent_ack_cnt);
  1019. pos += scnprintf(buf + pos, bufsz - pos,
  1020. fmt_table, "sent_cts_cnt:",
  1021. le32_to_cpu(cck->sent_cts_cnt),
  1022. accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt,
  1023. max_cck->sent_cts_cnt);
  1024. pos += scnprintf(buf + pos, bufsz - pos,
  1025. fmt_table, "sent_ba_rsp_cnt:",
  1026. le32_to_cpu(cck->sent_ba_rsp_cnt),
  1027. accum_cck->sent_ba_rsp_cnt,
  1028. delta_cck->sent_ba_rsp_cnt,
  1029. max_cck->sent_ba_rsp_cnt);
  1030. pos += scnprintf(buf + pos, bufsz - pos,
  1031. fmt_table, "dsp_self_kill:",
  1032. le32_to_cpu(cck->dsp_self_kill),
  1033. accum_cck->dsp_self_kill, delta_cck->dsp_self_kill,
  1034. max_cck->dsp_self_kill);
  1035. pos += scnprintf(buf + pos, bufsz - pos,
  1036. fmt_table, "mh_format_err:",
  1037. le32_to_cpu(cck->mh_format_err),
  1038. accum_cck->mh_format_err, delta_cck->mh_format_err,
  1039. max_cck->mh_format_err);
  1040. pos += scnprintf(buf + pos, bufsz - pos,
  1041. fmt_table, "re_acq_main_rssi_sum:",
  1042. le32_to_cpu(cck->re_acq_main_rssi_sum),
  1043. accum_cck->re_acq_main_rssi_sum,
  1044. delta_cck->re_acq_main_rssi_sum,
  1045. max_cck->re_acq_main_rssi_sum);
  1046. pos += scnprintf(buf + pos, bufsz - pos,
  1047. fmt_header, "Statistics_Rx - GENERAL:");
  1048. pos += scnprintf(buf + pos, bufsz - pos,
  1049. fmt_table, "bogus_cts:",
  1050. le32_to_cpu(general->bogus_cts),
  1051. accum_general->bogus_cts, delta_general->bogus_cts,
  1052. max_general->bogus_cts);
  1053. pos += scnprintf(buf + pos, bufsz - pos,
  1054. fmt_table, "bogus_ack:",
  1055. le32_to_cpu(general->bogus_ack),
  1056. accum_general->bogus_ack, delta_general->bogus_ack,
  1057. max_general->bogus_ack);
  1058. pos += scnprintf(buf + pos, bufsz - pos,
  1059. fmt_table, "non_bssid_frames:",
  1060. le32_to_cpu(general->non_bssid_frames),
  1061. accum_general->non_bssid_frames,
  1062. delta_general->non_bssid_frames,
  1063. max_general->non_bssid_frames);
  1064. pos += scnprintf(buf + pos, bufsz - pos,
  1065. fmt_table, "filtered_frames:",
  1066. le32_to_cpu(general->filtered_frames),
  1067. accum_general->filtered_frames,
  1068. delta_general->filtered_frames,
  1069. max_general->filtered_frames);
  1070. pos += scnprintf(buf + pos, bufsz - pos,
  1071. fmt_table, "non_channel_beacons:",
  1072. le32_to_cpu(general->non_channel_beacons),
  1073. accum_general->non_channel_beacons,
  1074. delta_general->non_channel_beacons,
  1075. max_general->non_channel_beacons);
  1076. pos += scnprintf(buf + pos, bufsz - pos,
  1077. fmt_table, "channel_beacons:",
  1078. le32_to_cpu(general->channel_beacons),
  1079. accum_general->channel_beacons,
  1080. delta_general->channel_beacons,
  1081. max_general->channel_beacons);
  1082. pos += scnprintf(buf + pos, bufsz - pos,
  1083. fmt_table, "num_missed_bcon:",
  1084. le32_to_cpu(general->num_missed_bcon),
  1085. accum_general->num_missed_bcon,
  1086. delta_general->num_missed_bcon,
  1087. max_general->num_missed_bcon);
  1088. pos += scnprintf(buf + pos, bufsz - pos,
  1089. fmt_table, "adc_rx_saturation_time:",
  1090. le32_to_cpu(general->adc_rx_saturation_time),
  1091. accum_general->adc_rx_saturation_time,
  1092. delta_general->adc_rx_saturation_time,
  1093. max_general->adc_rx_saturation_time);
  1094. pos += scnprintf(buf + pos, bufsz - pos,
  1095. fmt_table, "ina_detect_search_tm:",
  1096. le32_to_cpu(general->ina_detection_search_time),
  1097. accum_general->ina_detection_search_time,
  1098. delta_general->ina_detection_search_time,
  1099. max_general->ina_detection_search_time);
  1100. pos += scnprintf(buf + pos, bufsz - pos,
  1101. fmt_table, "beacon_silence_rssi_a:",
  1102. le32_to_cpu(general->beacon_silence_rssi_a),
  1103. accum_general->beacon_silence_rssi_a,
  1104. delta_general->beacon_silence_rssi_a,
  1105. max_general->beacon_silence_rssi_a);
  1106. pos += scnprintf(buf + pos, bufsz - pos,
  1107. fmt_table, "beacon_silence_rssi_b:",
  1108. le32_to_cpu(general->beacon_silence_rssi_b),
  1109. accum_general->beacon_silence_rssi_b,
  1110. delta_general->beacon_silence_rssi_b,
  1111. max_general->beacon_silence_rssi_b);
  1112. pos += scnprintf(buf + pos, bufsz - pos,
  1113. fmt_table, "beacon_silence_rssi_c:",
  1114. le32_to_cpu(general->beacon_silence_rssi_c),
  1115. accum_general->beacon_silence_rssi_c,
  1116. delta_general->beacon_silence_rssi_c,
  1117. max_general->beacon_silence_rssi_c);
  1118. pos += scnprintf(buf + pos, bufsz - pos,
  1119. fmt_table, "interference_data_flag:",
  1120. le32_to_cpu(general->interference_data_flag),
  1121. accum_general->interference_data_flag,
  1122. delta_general->interference_data_flag,
  1123. max_general->interference_data_flag);
  1124. pos += scnprintf(buf + pos, bufsz - pos,
  1125. fmt_table, "channel_load:",
  1126. le32_to_cpu(general->channel_load),
  1127. accum_general->channel_load,
  1128. delta_general->channel_load,
  1129. max_general->channel_load);
  1130. pos += scnprintf(buf + pos, bufsz - pos,
  1131. fmt_table, "dsp_false_alarms:",
  1132. le32_to_cpu(general->dsp_false_alarms),
  1133. accum_general->dsp_false_alarms,
  1134. delta_general->dsp_false_alarms,
  1135. max_general->dsp_false_alarms);
  1136. pos += scnprintf(buf + pos, bufsz - pos,
  1137. fmt_table, "beacon_rssi_a:",
  1138. le32_to_cpu(general->beacon_rssi_a),
  1139. accum_general->beacon_rssi_a,
  1140. delta_general->beacon_rssi_a,
  1141. max_general->beacon_rssi_a);
  1142. pos += scnprintf(buf + pos, bufsz - pos,
  1143. fmt_table, "beacon_rssi_b:",
  1144. le32_to_cpu(general->beacon_rssi_b),
  1145. accum_general->beacon_rssi_b,
  1146. delta_general->beacon_rssi_b,
  1147. max_general->beacon_rssi_b);
  1148. pos += scnprintf(buf + pos, bufsz - pos,
  1149. fmt_table, "beacon_rssi_c:",
  1150. le32_to_cpu(general->beacon_rssi_c),
  1151. accum_general->beacon_rssi_c,
  1152. delta_general->beacon_rssi_c,
  1153. max_general->beacon_rssi_c);
  1154. pos += scnprintf(buf + pos, bufsz - pos,
  1155. fmt_table, "beacon_energy_a:",
  1156. le32_to_cpu(general->beacon_energy_a),
  1157. accum_general->beacon_energy_a,
  1158. delta_general->beacon_energy_a,
  1159. max_general->beacon_energy_a);
  1160. pos += scnprintf(buf + pos, bufsz - pos,
  1161. fmt_table, "beacon_energy_b:",
  1162. le32_to_cpu(general->beacon_energy_b),
  1163. accum_general->beacon_energy_b,
  1164. delta_general->beacon_energy_b,
  1165. max_general->beacon_energy_b);
  1166. pos += scnprintf(buf + pos, bufsz - pos,
  1167. fmt_table, "beacon_energy_c:",
  1168. le32_to_cpu(general->beacon_energy_c),
  1169. accum_general->beacon_energy_c,
  1170. delta_general->beacon_energy_c,
  1171. max_general->beacon_energy_c);
  1172. pos += scnprintf(buf + pos, bufsz - pos,
  1173. fmt_header, "Statistics_Rx - OFDM_HT:");
  1174. pos += scnprintf(buf + pos, bufsz - pos,
  1175. fmt_table, "plcp_err:",
  1176. le32_to_cpu(ht->plcp_err), accum_ht->plcp_err,
  1177. delta_ht->plcp_err, max_ht->plcp_err);
  1178. pos += scnprintf(buf + pos, bufsz - pos,
  1179. fmt_table, "overrun_err:",
  1180. le32_to_cpu(ht->overrun_err), accum_ht->overrun_err,
  1181. delta_ht->overrun_err, max_ht->overrun_err);
  1182. pos += scnprintf(buf + pos, bufsz - pos,
  1183. fmt_table, "early_overrun_err:",
  1184. le32_to_cpu(ht->early_overrun_err),
  1185. accum_ht->early_overrun_err,
  1186. delta_ht->early_overrun_err,
  1187. max_ht->early_overrun_err);
  1188. pos += scnprintf(buf + pos, bufsz - pos,
  1189. fmt_table, "crc32_good:",
  1190. le32_to_cpu(ht->crc32_good), accum_ht->crc32_good,
  1191. delta_ht->crc32_good, max_ht->crc32_good);
  1192. pos += scnprintf(buf + pos, bufsz - pos,
  1193. fmt_table, "crc32_err:",
  1194. le32_to_cpu(ht->crc32_err), accum_ht->crc32_err,
  1195. delta_ht->crc32_err, max_ht->crc32_err);
  1196. pos += scnprintf(buf + pos, bufsz - pos,
  1197. fmt_table, "mh_format_err:",
  1198. le32_to_cpu(ht->mh_format_err),
  1199. accum_ht->mh_format_err,
  1200. delta_ht->mh_format_err, max_ht->mh_format_err);
  1201. pos += scnprintf(buf + pos, bufsz - pos,
  1202. fmt_table, "agg_crc32_good:",
  1203. le32_to_cpu(ht->agg_crc32_good),
  1204. accum_ht->agg_crc32_good,
  1205. delta_ht->agg_crc32_good, max_ht->agg_crc32_good);
  1206. pos += scnprintf(buf + pos, bufsz - pos,
  1207. fmt_table, "agg_mpdu_cnt:",
  1208. le32_to_cpu(ht->agg_mpdu_cnt),
  1209. accum_ht->agg_mpdu_cnt,
  1210. delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt);
  1211. pos += scnprintf(buf + pos, bufsz - pos,
  1212. fmt_table, "agg_cnt:",
  1213. le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt,
  1214. delta_ht->agg_cnt, max_ht->agg_cnt);
  1215. pos += scnprintf(buf + pos, bufsz - pos,
  1216. fmt_table, "unsupport_mcs:",
  1217. le32_to_cpu(ht->unsupport_mcs),
  1218. accum_ht->unsupport_mcs,
  1219. delta_ht->unsupport_mcs, max_ht->unsupport_mcs);
  1220. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1221. kfree(buf);
  1222. return ret;
  1223. }
  1224. static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
  1225. char __user *user_buf,
  1226. size_t count, loff_t *ppos)
  1227. {
  1228. struct iwl_priv *priv = file->private_data;
  1229. int pos = 0;
  1230. char *buf;
  1231. int bufsz = (sizeof(struct statistics_tx) * 48) + 250;
  1232. ssize_t ret;
  1233. struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx;
  1234. if (!iwl_is_alive(priv->shrd))
  1235. return -EAGAIN;
  1236. buf = kzalloc(bufsz, GFP_KERNEL);
  1237. if (!buf) {
  1238. IWL_ERR(priv, "Can not allocate Buffer\n");
  1239. return -ENOMEM;
  1240. }
  1241. /* the statistic information display here is based on
  1242. * the last statistics notification from uCode
  1243. * might not reflect the current uCode activity
  1244. */
  1245. tx = &priv->statistics.tx;
  1246. accum_tx = &priv->accum_stats.tx;
  1247. delta_tx = &priv->delta_stats.tx;
  1248. max_tx = &priv->max_delta_stats.tx;
  1249. pos += iwl_statistics_flag(priv, buf, bufsz);
  1250. pos += scnprintf(buf + pos, bufsz - pos,
  1251. fmt_header, "Statistics_Tx:");
  1252. pos += scnprintf(buf + pos, bufsz - pos,
  1253. fmt_table, "preamble:",
  1254. le32_to_cpu(tx->preamble_cnt),
  1255. accum_tx->preamble_cnt,
  1256. delta_tx->preamble_cnt, max_tx->preamble_cnt);
  1257. pos += scnprintf(buf + pos, bufsz - pos,
  1258. fmt_table, "rx_detected_cnt:",
  1259. le32_to_cpu(tx->rx_detected_cnt),
  1260. accum_tx->rx_detected_cnt,
  1261. delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt);
  1262. pos += scnprintf(buf + pos, bufsz - pos,
  1263. fmt_table, "bt_prio_defer_cnt:",
  1264. le32_to_cpu(tx->bt_prio_defer_cnt),
  1265. accum_tx->bt_prio_defer_cnt,
  1266. delta_tx->bt_prio_defer_cnt,
  1267. max_tx->bt_prio_defer_cnt);
  1268. pos += scnprintf(buf + pos, bufsz - pos,
  1269. fmt_table, "bt_prio_kill_cnt:",
  1270. le32_to_cpu(tx->bt_prio_kill_cnt),
  1271. accum_tx->bt_prio_kill_cnt,
  1272. delta_tx->bt_prio_kill_cnt,
  1273. max_tx->bt_prio_kill_cnt);
  1274. pos += scnprintf(buf + pos, bufsz - pos,
  1275. fmt_table, "few_bytes_cnt:",
  1276. le32_to_cpu(tx->few_bytes_cnt),
  1277. accum_tx->few_bytes_cnt,
  1278. delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt);
  1279. pos += scnprintf(buf + pos, bufsz - pos,
  1280. fmt_table, "cts_timeout:",
  1281. le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout,
  1282. delta_tx->cts_timeout, max_tx->cts_timeout);
  1283. pos += scnprintf(buf + pos, bufsz - pos,
  1284. fmt_table, "ack_timeout:",
  1285. le32_to_cpu(tx->ack_timeout),
  1286. accum_tx->ack_timeout,
  1287. delta_tx->ack_timeout, max_tx->ack_timeout);
  1288. pos += scnprintf(buf + pos, bufsz - pos,
  1289. fmt_table, "expected_ack_cnt:",
  1290. le32_to_cpu(tx->expected_ack_cnt),
  1291. accum_tx->expected_ack_cnt,
  1292. delta_tx->expected_ack_cnt,
  1293. max_tx->expected_ack_cnt);
  1294. pos += scnprintf(buf + pos, bufsz - pos,
  1295. fmt_table, "actual_ack_cnt:",
  1296. le32_to_cpu(tx->actual_ack_cnt),
  1297. accum_tx->actual_ack_cnt,
  1298. delta_tx->actual_ack_cnt,
  1299. max_tx->actual_ack_cnt);
  1300. pos += scnprintf(buf + pos, bufsz - pos,
  1301. fmt_table, "dump_msdu_cnt:",
  1302. le32_to_cpu(tx->dump_msdu_cnt),
  1303. accum_tx->dump_msdu_cnt,
  1304. delta_tx->dump_msdu_cnt,
  1305. max_tx->dump_msdu_cnt);
  1306. pos += scnprintf(buf + pos, bufsz - pos,
  1307. fmt_table, "abort_nxt_frame_mismatch:",
  1308. le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
  1309. accum_tx->burst_abort_next_frame_mismatch_cnt,
  1310. delta_tx->burst_abort_next_frame_mismatch_cnt,
  1311. max_tx->burst_abort_next_frame_mismatch_cnt);
  1312. pos += scnprintf(buf + pos, bufsz - pos,
  1313. fmt_table, "abort_missing_nxt_frame:",
  1314. le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
  1315. accum_tx->burst_abort_missing_next_frame_cnt,
  1316. delta_tx->burst_abort_missing_next_frame_cnt,
  1317. max_tx->burst_abort_missing_next_frame_cnt);
  1318. pos += scnprintf(buf + pos, bufsz - pos,
  1319. fmt_table, "cts_timeout_collision:",
  1320. le32_to_cpu(tx->cts_timeout_collision),
  1321. accum_tx->cts_timeout_collision,
  1322. delta_tx->cts_timeout_collision,
  1323. max_tx->cts_timeout_collision);
  1324. pos += scnprintf(buf + pos, bufsz - pos,
  1325. fmt_table, "ack_ba_timeout_collision:",
  1326. le32_to_cpu(tx->ack_or_ba_timeout_collision),
  1327. accum_tx->ack_or_ba_timeout_collision,
  1328. delta_tx->ack_or_ba_timeout_collision,
  1329. max_tx->ack_or_ba_timeout_collision);
  1330. pos += scnprintf(buf + pos, bufsz - pos,
  1331. fmt_table, "agg ba_timeout:",
  1332. le32_to_cpu(tx->agg.ba_timeout),
  1333. accum_tx->agg.ba_timeout,
  1334. delta_tx->agg.ba_timeout,
  1335. max_tx->agg.ba_timeout);
  1336. pos += scnprintf(buf + pos, bufsz - pos,
  1337. fmt_table, "agg ba_resched_frames:",
  1338. le32_to_cpu(tx->agg.ba_reschedule_frames),
  1339. accum_tx->agg.ba_reschedule_frames,
  1340. delta_tx->agg.ba_reschedule_frames,
  1341. max_tx->agg.ba_reschedule_frames);
  1342. pos += scnprintf(buf + pos, bufsz - pos,
  1343. fmt_table, "agg scd_query_agg_frame:",
  1344. le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
  1345. accum_tx->agg.scd_query_agg_frame_cnt,
  1346. delta_tx->agg.scd_query_agg_frame_cnt,
  1347. max_tx->agg.scd_query_agg_frame_cnt);
  1348. pos += scnprintf(buf + pos, bufsz - pos,
  1349. fmt_table, "agg scd_query_no_agg:",
  1350. le32_to_cpu(tx->agg.scd_query_no_agg),
  1351. accum_tx->agg.scd_query_no_agg,
  1352. delta_tx->agg.scd_query_no_agg,
  1353. max_tx->agg.scd_query_no_agg);
  1354. pos += scnprintf(buf + pos, bufsz - pos,
  1355. fmt_table, "agg scd_query_agg:",
  1356. le32_to_cpu(tx->agg.scd_query_agg),
  1357. accum_tx->agg.scd_query_agg,
  1358. delta_tx->agg.scd_query_agg,
  1359. max_tx->agg.scd_query_agg);
  1360. pos += scnprintf(buf + pos, bufsz - pos,
  1361. fmt_table, "agg scd_query_mismatch:",
  1362. le32_to_cpu(tx->agg.scd_query_mismatch),
  1363. accum_tx->agg.scd_query_mismatch,
  1364. delta_tx->agg.scd_query_mismatch,
  1365. max_tx->agg.scd_query_mismatch);
  1366. pos += scnprintf(buf + pos, bufsz - pos,
  1367. fmt_table, "agg frame_not_ready:",
  1368. le32_to_cpu(tx->agg.frame_not_ready),
  1369. accum_tx->agg.frame_not_ready,
  1370. delta_tx->agg.frame_not_ready,
  1371. max_tx->agg.frame_not_ready);
  1372. pos += scnprintf(buf + pos, bufsz - pos,
  1373. fmt_table, "agg underrun:",
  1374. le32_to_cpu(tx->agg.underrun),
  1375. accum_tx->agg.underrun,
  1376. delta_tx->agg.underrun, max_tx->agg.underrun);
  1377. pos += scnprintf(buf + pos, bufsz - pos,
  1378. fmt_table, "agg bt_prio_kill:",
  1379. le32_to_cpu(tx->agg.bt_prio_kill),
  1380. accum_tx->agg.bt_prio_kill,
  1381. delta_tx->agg.bt_prio_kill,
  1382. max_tx->agg.bt_prio_kill);
  1383. pos += scnprintf(buf + pos, bufsz - pos,
  1384. fmt_table, "agg rx_ba_rsp_cnt:",
  1385. le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
  1386. accum_tx->agg.rx_ba_rsp_cnt,
  1387. delta_tx->agg.rx_ba_rsp_cnt,
  1388. max_tx->agg.rx_ba_rsp_cnt);
  1389. if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
  1390. pos += scnprintf(buf + pos, bufsz - pos,
  1391. "tx power: (1/2 dB step)\n");
  1392. if ((priv->cfg->valid_tx_ant & ANT_A) && tx->tx_power.ant_a)
  1393. pos += scnprintf(buf + pos, bufsz - pos,
  1394. fmt_hex, "antenna A:",
  1395. tx->tx_power.ant_a);
  1396. if ((priv->cfg->valid_tx_ant & ANT_B) && tx->tx_power.ant_b)
  1397. pos += scnprintf(buf + pos, bufsz - pos,
  1398. fmt_hex, "antenna B:",
  1399. tx->tx_power.ant_b);
  1400. if ((priv->cfg->valid_tx_ant & ANT_C) && tx->tx_power.ant_c)
  1401. pos += scnprintf(buf + pos, bufsz - pos,
  1402. fmt_hex, "antenna C:",
  1403. tx->tx_power.ant_c);
  1404. }
  1405. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1406. kfree(buf);
  1407. return ret;
  1408. }
  1409. static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
  1410. char __user *user_buf,
  1411. size_t count, loff_t *ppos)
  1412. {
  1413. struct iwl_priv *priv = file->private_data;
  1414. int pos = 0;
  1415. char *buf;
  1416. int bufsz = sizeof(struct statistics_general) * 10 + 300;
  1417. ssize_t ret;
  1418. struct statistics_general_common *general, *accum_general;
  1419. struct statistics_general_common *delta_general, *max_general;
  1420. struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg;
  1421. struct statistics_div *div, *accum_div, *delta_div, *max_div;
  1422. if (!iwl_is_alive(priv->shrd))
  1423. return -EAGAIN;
  1424. buf = kzalloc(bufsz, GFP_KERNEL);
  1425. if (!buf) {
  1426. IWL_ERR(priv, "Can not allocate Buffer\n");
  1427. return -ENOMEM;
  1428. }
  1429. /* the statistic information display here is based on
  1430. * the last statistics notification from uCode
  1431. * might not reflect the current uCode activity
  1432. */
  1433. general = &priv->statistics.common;
  1434. dbg = &priv->statistics.common.dbg;
  1435. div = &priv->statistics.common.div;
  1436. accum_general = &priv->accum_stats.common;
  1437. accum_dbg = &priv->accum_stats.common.dbg;
  1438. accum_div = &priv->accum_stats.common.div;
  1439. delta_general = &priv->delta_stats.common;
  1440. max_general = &priv->max_delta_stats.common;
  1441. delta_dbg = &priv->delta_stats.common.dbg;
  1442. max_dbg = &priv->max_delta_stats.common.dbg;
  1443. delta_div = &priv->delta_stats.common.div;
  1444. max_div = &priv->max_delta_stats.common.div;
  1445. pos += iwl_statistics_flag(priv, buf, bufsz);
  1446. pos += scnprintf(buf + pos, bufsz - pos,
  1447. fmt_header, "Statistics_General:");
  1448. pos += scnprintf(buf + pos, bufsz - pos,
  1449. fmt_value, "temperature:",
  1450. le32_to_cpu(general->temperature));
  1451. pos += scnprintf(buf + pos, bufsz - pos,
  1452. fmt_value, "temperature_m:",
  1453. le32_to_cpu(general->temperature_m));
  1454. pos += scnprintf(buf + pos, bufsz - pos,
  1455. fmt_value, "ttl_timestamp:",
  1456. le32_to_cpu(general->ttl_timestamp));
  1457. pos += scnprintf(buf + pos, bufsz - pos,
  1458. fmt_table, "burst_check:",
  1459. le32_to_cpu(dbg->burst_check),
  1460. accum_dbg->burst_check,
  1461. delta_dbg->burst_check, max_dbg->burst_check);
  1462. pos += scnprintf(buf + pos, bufsz - pos,
  1463. fmt_table, "burst_count:",
  1464. le32_to_cpu(dbg->burst_count),
  1465. accum_dbg->burst_count,
  1466. delta_dbg->burst_count, max_dbg->burst_count);
  1467. pos += scnprintf(buf + pos, bufsz - pos,
  1468. fmt_table, "wait_for_silence_timeout_count:",
  1469. le32_to_cpu(dbg->wait_for_silence_timeout_cnt),
  1470. accum_dbg->wait_for_silence_timeout_cnt,
  1471. delta_dbg->wait_for_silence_timeout_cnt,
  1472. max_dbg->wait_for_silence_timeout_cnt);
  1473. pos += scnprintf(buf + pos, bufsz - pos,
  1474. fmt_table, "sleep_time:",
  1475. le32_to_cpu(general->sleep_time),
  1476. accum_general->sleep_time,
  1477. delta_general->sleep_time, max_general->sleep_time);
  1478. pos += scnprintf(buf + pos, bufsz - pos,
  1479. fmt_table, "slots_out:",
  1480. le32_to_cpu(general->slots_out),
  1481. accum_general->slots_out,
  1482. delta_general->slots_out, max_general->slots_out);
  1483. pos += scnprintf(buf + pos, bufsz - pos,
  1484. fmt_table, "slots_idle:",
  1485. le32_to_cpu(general->slots_idle),
  1486. accum_general->slots_idle,
  1487. delta_general->slots_idle, max_general->slots_idle);
  1488. pos += scnprintf(buf + pos, bufsz - pos,
  1489. fmt_table, "tx_on_a:",
  1490. le32_to_cpu(div->tx_on_a), accum_div->tx_on_a,
  1491. delta_div->tx_on_a, max_div->tx_on_a);
  1492. pos += scnprintf(buf + pos, bufsz - pos,
  1493. fmt_table, "tx_on_b:",
  1494. le32_to_cpu(div->tx_on_b), accum_div->tx_on_b,
  1495. delta_div->tx_on_b, max_div->tx_on_b);
  1496. pos += scnprintf(buf + pos, bufsz - pos,
  1497. fmt_table, "exec_time:",
  1498. le32_to_cpu(div->exec_time), accum_div->exec_time,
  1499. delta_div->exec_time, max_div->exec_time);
  1500. pos += scnprintf(buf + pos, bufsz - pos,
  1501. fmt_table, "probe_time:",
  1502. le32_to_cpu(div->probe_time), accum_div->probe_time,
  1503. delta_div->probe_time, max_div->probe_time);
  1504. pos += scnprintf(buf + pos, bufsz - pos,
  1505. fmt_table, "rx_enable_counter:",
  1506. le32_to_cpu(general->rx_enable_counter),
  1507. accum_general->rx_enable_counter,
  1508. delta_general->rx_enable_counter,
  1509. max_general->rx_enable_counter);
  1510. pos += scnprintf(buf + pos, bufsz - pos,
  1511. fmt_table, "num_of_sos_states:",
  1512. le32_to_cpu(general->num_of_sos_states),
  1513. accum_general->num_of_sos_states,
  1514. delta_general->num_of_sos_states,
  1515. max_general->num_of_sos_states);
  1516. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1517. kfree(buf);
  1518. return ret;
  1519. }
  1520. static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
  1521. char __user *user_buf,
  1522. size_t count, loff_t *ppos)
  1523. {
  1524. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1525. int pos = 0;
  1526. char *buf;
  1527. int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200;
  1528. ssize_t ret;
  1529. struct statistics_bt_activity *bt, *accum_bt;
  1530. if (!iwl_is_alive(priv->shrd))
  1531. return -EAGAIN;
  1532. if (!priv->bt_enable_flag)
  1533. return -EINVAL;
  1534. /* make request to uCode to retrieve statistics information */
  1535. mutex_lock(&priv->shrd->mutex);
  1536. ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
  1537. mutex_unlock(&priv->shrd->mutex);
  1538. if (ret) {
  1539. IWL_ERR(priv,
  1540. "Error sending statistics request: %zd\n", ret);
  1541. return -EAGAIN;
  1542. }
  1543. buf = kzalloc(bufsz, GFP_KERNEL);
  1544. if (!buf) {
  1545. IWL_ERR(priv, "Can not allocate Buffer\n");
  1546. return -ENOMEM;
  1547. }
  1548. /*
  1549. * the statistic information display here is based on
  1550. * the last statistics notification from uCode
  1551. * might not reflect the current uCode activity
  1552. */
  1553. bt = &priv->statistics.bt_activity;
  1554. accum_bt = &priv->accum_stats.bt_activity;
  1555. pos += iwl_statistics_flag(priv, buf, bufsz);
  1556. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n");
  1557. pos += scnprintf(buf + pos, bufsz - pos,
  1558. "\t\t\tcurrent\t\t\taccumulative\n");
  1559. pos += scnprintf(buf + pos, bufsz - pos,
  1560. "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
  1561. le32_to_cpu(bt->hi_priority_tx_req_cnt),
  1562. accum_bt->hi_priority_tx_req_cnt);
  1563. pos += scnprintf(buf + pos, bufsz - pos,
  1564. "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
  1565. le32_to_cpu(bt->hi_priority_tx_denied_cnt),
  1566. accum_bt->hi_priority_tx_denied_cnt);
  1567. pos += scnprintf(buf + pos, bufsz - pos,
  1568. "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
  1569. le32_to_cpu(bt->lo_priority_tx_req_cnt),
  1570. accum_bt->lo_priority_tx_req_cnt);
  1571. pos += scnprintf(buf + pos, bufsz - pos,
  1572. "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
  1573. le32_to_cpu(bt->lo_priority_tx_denied_cnt),
  1574. accum_bt->lo_priority_tx_denied_cnt);
  1575. pos += scnprintf(buf + pos, bufsz - pos,
  1576. "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
  1577. le32_to_cpu(bt->hi_priority_rx_req_cnt),
  1578. accum_bt->hi_priority_rx_req_cnt);
  1579. pos += scnprintf(buf + pos, bufsz - pos,
  1580. "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
  1581. le32_to_cpu(bt->hi_priority_rx_denied_cnt),
  1582. accum_bt->hi_priority_rx_denied_cnt);
  1583. pos += scnprintf(buf + pos, bufsz - pos,
  1584. "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
  1585. le32_to_cpu(bt->lo_priority_rx_req_cnt),
  1586. accum_bt->lo_priority_rx_req_cnt);
  1587. pos += scnprintf(buf + pos, bufsz - pos,
  1588. "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
  1589. le32_to_cpu(bt->lo_priority_rx_denied_cnt),
  1590. accum_bt->lo_priority_rx_denied_cnt);
  1591. pos += scnprintf(buf + pos, bufsz - pos,
  1592. "(rx)num_bt_kills:\t\t%u\t\t\t%u\n",
  1593. le32_to_cpu(priv->statistics.num_bt_kills),
  1594. priv->statistics.accum_num_bt_kills);
  1595. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1596. kfree(buf);
  1597. return ret;
  1598. }
  1599. static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
  1600. char __user *user_buf,
  1601. size_t count, loff_t *ppos)
  1602. {
  1603. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  1604. int pos = 0;
  1605. char *buf;
  1606. int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) +
  1607. (sizeof(struct reply_agg_tx_error_statistics) * 24) + 200;
  1608. ssize_t ret;
  1609. if (!iwl_is_alive(priv->shrd))
  1610. return -EAGAIN;
  1611. buf = kzalloc(bufsz, GFP_KERNEL);
  1612. if (!buf) {
  1613. IWL_ERR(priv, "Can not allocate Buffer\n");
  1614. return -ENOMEM;
  1615. }
  1616. pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n");
  1617. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n",
  1618. iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY),
  1619. priv->reply_tx_stats.pp_delay);
  1620. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1621. iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_FEW_BYTES),
  1622. priv->reply_tx_stats.pp_few_bytes);
  1623. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1624. iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_BT_PRIO),
  1625. priv->reply_tx_stats.pp_bt_prio);
  1626. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1627. iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_QUIET_PERIOD),
  1628. priv->reply_tx_stats.pp_quiet_period);
  1629. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1630. iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_CALC_TTAK),
  1631. priv->reply_tx_stats.pp_calc_ttak);
  1632. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1633. iwl_get_tx_fail_reason(
  1634. TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY),
  1635. priv->reply_tx_stats.int_crossed_retry);
  1636. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1637. iwl_get_tx_fail_reason(TX_STATUS_FAIL_SHORT_LIMIT),
  1638. priv->reply_tx_stats.short_limit);
  1639. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1640. iwl_get_tx_fail_reason(TX_STATUS_FAIL_LONG_LIMIT),
  1641. priv->reply_tx_stats.long_limit);
  1642. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1643. iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_UNDERRUN),
  1644. priv->reply_tx_stats.fifo_underrun);
  1645. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1646. iwl_get_tx_fail_reason(TX_STATUS_FAIL_DRAIN_FLOW),
  1647. priv->reply_tx_stats.drain_flow);
  1648. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1649. iwl_get_tx_fail_reason(TX_STATUS_FAIL_RFKILL_FLUSH),
  1650. priv->reply_tx_stats.rfkill_flush);
  1651. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1652. iwl_get_tx_fail_reason(TX_STATUS_FAIL_LIFE_EXPIRE),
  1653. priv->reply_tx_stats.life_expire);
  1654. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1655. iwl_get_tx_fail_reason(TX_STATUS_FAIL_DEST_PS),
  1656. priv->reply_tx_stats.dest_ps);
  1657. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1658. iwl_get_tx_fail_reason(TX_STATUS_FAIL_HOST_ABORTED),
  1659. priv->reply_tx_stats.host_abort);
  1660. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1661. iwl_get_tx_fail_reason(TX_STATUS_FAIL_BT_RETRY),
  1662. priv->reply_tx_stats.pp_delay);
  1663. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1664. iwl_get_tx_fail_reason(TX_STATUS_FAIL_STA_INVALID),
  1665. priv->reply_tx_stats.sta_invalid);
  1666. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1667. iwl_get_tx_fail_reason(TX_STATUS_FAIL_FRAG_DROPPED),
  1668. priv->reply_tx_stats.frag_drop);
  1669. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1670. iwl_get_tx_fail_reason(TX_STATUS_FAIL_TID_DISABLE),
  1671. priv->reply_tx_stats.tid_disable);
  1672. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1673. iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_FLUSHED),
  1674. priv->reply_tx_stats.fifo_flush);
  1675. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1676. iwl_get_tx_fail_reason(
  1677. TX_STATUS_FAIL_INSUFFICIENT_CF_POLL),
  1678. priv->reply_tx_stats.insuff_cf_poll);
  1679. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1680. iwl_get_tx_fail_reason(TX_STATUS_FAIL_PASSIVE_NO_RX),
  1681. priv->reply_tx_stats.fail_hw_drop);
  1682. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1683. iwl_get_tx_fail_reason(
  1684. TX_STATUS_FAIL_NO_BEACON_ON_RADAR),
  1685. priv->reply_tx_stats.sta_color_mismatch);
  1686. pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
  1687. priv->reply_tx_stats.unknown);
  1688. pos += scnprintf(buf + pos, bufsz - pos,
  1689. "\nStatistics_Agg_TX_Error:\n");
  1690. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1691. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK),
  1692. priv->reply_agg_tx_stats.underrun);
  1693. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1694. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK),
  1695. priv->reply_agg_tx_stats.bt_prio);
  1696. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1697. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK),
  1698. priv->reply_agg_tx_stats.few_bytes);
  1699. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1700. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_ABORT_MSK),
  1701. priv->reply_agg_tx_stats.abort);
  1702. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1703. iwl_get_agg_tx_fail_reason(
  1704. AGG_TX_STATE_LAST_SENT_TTL_MSK),
  1705. priv->reply_agg_tx_stats.last_sent_ttl);
  1706. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1707. iwl_get_agg_tx_fail_reason(
  1708. AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK),
  1709. priv->reply_agg_tx_stats.last_sent_try);
  1710. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1711. iwl_get_agg_tx_fail_reason(
  1712. AGG_TX_STATE_LAST_SENT_BT_KILL_MSK),
  1713. priv->reply_agg_tx_stats.last_sent_bt_kill);
  1714. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1715. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_SCD_QUERY_MSK),
  1716. priv->reply_agg_tx_stats.scd_query);
  1717. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
  1718. iwl_get_agg_tx_fail_reason(
  1719. AGG_TX_STATE_TEST_BAD_CRC32_MSK),
  1720. priv->reply_agg_tx_stats.bad_crc32);
  1721. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1722. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_RESPONSE_MSK),
  1723. priv->reply_agg_tx_stats.response);
  1724. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1725. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK),
  1726. priv->reply_agg_tx_stats.dump_tx);
  1727. pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
  1728. iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DELAY_TX_MSK),
  1729. priv->reply_agg_tx_stats.delay_tx);
  1730. pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
  1731. priv->reply_agg_tx_stats.unknown);
  1732. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1733. kfree(buf);
  1734. return ret;
  1735. }
  1736. static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
  1737. char __user *user_buf,
  1738. size_t count, loff_t *ppos) {
  1739. struct iwl_priv *priv = file->private_data;
  1740. int pos = 0;
  1741. int cnt = 0;
  1742. char *buf;
  1743. int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
  1744. ssize_t ret;
  1745. struct iwl_sensitivity_data *data;
  1746. data = &priv->sensitivity_data;
  1747. buf = kzalloc(bufsz, GFP_KERNEL);
  1748. if (!buf) {
  1749. IWL_ERR(priv, "Can not allocate Buffer\n");
  1750. return -ENOMEM;
  1751. }
  1752. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
  1753. data->auto_corr_ofdm);
  1754. pos += scnprintf(buf + pos, bufsz - pos,
  1755. "auto_corr_ofdm_mrc:\t\t %u\n",
  1756. data->auto_corr_ofdm_mrc);
  1757. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
  1758. data->auto_corr_ofdm_x1);
  1759. pos += scnprintf(buf + pos, bufsz - pos,
  1760. "auto_corr_ofdm_mrc_x1:\t\t %u\n",
  1761. data->auto_corr_ofdm_mrc_x1);
  1762. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
  1763. data->auto_corr_cck);
  1764. pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
  1765. data->auto_corr_cck_mrc);
  1766. pos += scnprintf(buf + pos, bufsz - pos,
  1767. "last_bad_plcp_cnt_ofdm:\t\t %u\n",
  1768. data->last_bad_plcp_cnt_ofdm);
  1769. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
  1770. data->last_fa_cnt_ofdm);
  1771. pos += scnprintf(buf + pos, bufsz - pos,
  1772. "last_bad_plcp_cnt_cck:\t\t %u\n",
  1773. data->last_bad_plcp_cnt_cck);
  1774. pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
  1775. data->last_fa_cnt_cck);
  1776. pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
  1777. data->nrg_curr_state);
  1778. pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
  1779. data->nrg_prev_state);
  1780. pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
  1781. for (cnt = 0; cnt < 10; cnt++) {
  1782. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1783. data->nrg_value[cnt]);
  1784. }
  1785. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1786. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
  1787. for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
  1788. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1789. data->nrg_silence_rssi[cnt]);
  1790. }
  1791. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1792. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
  1793. data->nrg_silence_ref);
  1794. pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
  1795. data->nrg_energy_idx);
  1796. pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
  1797. data->nrg_silence_idx);
  1798. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
  1799. data->nrg_th_cck);
  1800. pos += scnprintf(buf + pos, bufsz - pos,
  1801. "nrg_auto_corr_silence_diff:\t %u\n",
  1802. data->nrg_auto_corr_silence_diff);
  1803. pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
  1804. data->num_in_cck_no_fa);
  1805. pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
  1806. data->nrg_th_ofdm);
  1807. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1808. kfree(buf);
  1809. return ret;
  1810. }
  1811. static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
  1812. char __user *user_buf,
  1813. size_t count, loff_t *ppos) {
  1814. struct iwl_priv *priv = file->private_data;
  1815. int pos = 0;
  1816. int cnt = 0;
  1817. char *buf;
  1818. int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
  1819. ssize_t ret;
  1820. struct iwl_chain_noise_data *data;
  1821. data = &priv->chain_noise_data;
  1822. buf = kzalloc(bufsz, GFP_KERNEL);
  1823. if (!buf) {
  1824. IWL_ERR(priv, "Can not allocate Buffer\n");
  1825. return -ENOMEM;
  1826. }
  1827. pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
  1828. data->active_chains);
  1829. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
  1830. data->chain_noise_a);
  1831. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
  1832. data->chain_noise_b);
  1833. pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
  1834. data->chain_noise_c);
  1835. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
  1836. data->chain_signal_a);
  1837. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
  1838. data->chain_signal_b);
  1839. pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
  1840. data->chain_signal_c);
  1841. pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
  1842. data->beacon_count);
  1843. pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
  1844. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1845. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1846. data->disconn_array[cnt]);
  1847. }
  1848. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1849. pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
  1850. for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
  1851. pos += scnprintf(buf + pos, bufsz - pos, " %u",
  1852. data->delta_gain_code[cnt]);
  1853. }
  1854. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  1855. pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
  1856. data->radio_write);
  1857. pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
  1858. data->state);
  1859. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1860. kfree(buf);
  1861. return ret;
  1862. }
  1863. static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
  1864. char __user *user_buf,
  1865. size_t count, loff_t *ppos)
  1866. {
  1867. struct iwl_priv *priv = file->private_data;
  1868. char buf[60];
  1869. int pos = 0;
  1870. const size_t bufsz = sizeof(buf);
  1871. u32 pwrsave_status;
  1872. pwrsave_status = iwl_read32(bus(priv), CSR_GP_CNTRL) &
  1873. CSR_GP_REG_POWER_SAVE_STATUS_MSK;
  1874. pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
  1875. pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
  1876. (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
  1877. (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
  1878. (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
  1879. "error");
  1880. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1881. }
  1882. static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
  1883. const char __user *user_buf,
  1884. size_t count, loff_t *ppos)
  1885. {
  1886. struct iwl_priv *priv = file->private_data;
  1887. char buf[8];
  1888. int buf_size;
  1889. int clear;
  1890. memset(buf, 0, sizeof(buf));
  1891. buf_size = min(count, sizeof(buf) - 1);
  1892. if (copy_from_user(buf, user_buf, buf_size))
  1893. return -EFAULT;
  1894. if (sscanf(buf, "%d", &clear) != 1)
  1895. return -EFAULT;
  1896. /* make request to uCode to retrieve statistics information */
  1897. mutex_lock(&priv->shrd->mutex);
  1898. iwl_send_statistics_request(priv, CMD_SYNC, true);
  1899. mutex_unlock(&priv->shrd->mutex);
  1900. return count;
  1901. }
  1902. static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
  1903. char __user *user_buf,
  1904. size_t count, loff_t *ppos) {
  1905. struct iwl_priv *priv = file->private_data;
  1906. int pos = 0;
  1907. char buf[128];
  1908. const size_t bufsz = sizeof(buf);
  1909. pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
  1910. priv->event_log.ucode_trace ? "On" : "Off");
  1911. pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
  1912. priv->event_log.non_wraps_count);
  1913. pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
  1914. priv->event_log.wraps_once_count);
  1915. pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
  1916. priv->event_log.wraps_more_count);
  1917. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1918. }
  1919. static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
  1920. const char __user *user_buf,
  1921. size_t count, loff_t *ppos)
  1922. {
  1923. struct iwl_priv *priv = file->private_data;
  1924. char buf[8];
  1925. int buf_size;
  1926. int trace;
  1927. memset(buf, 0, sizeof(buf));
  1928. buf_size = min(count, sizeof(buf) - 1);
  1929. if (copy_from_user(buf, user_buf, buf_size))
  1930. return -EFAULT;
  1931. if (sscanf(buf, "%d", &trace) != 1)
  1932. return -EFAULT;
  1933. if (trace) {
  1934. priv->event_log.ucode_trace = true;
  1935. /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
  1936. mod_timer(&priv->ucode_trace,
  1937. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  1938. } else {
  1939. priv->event_log.ucode_trace = false;
  1940. del_timer_sync(&priv->ucode_trace);
  1941. }
  1942. return count;
  1943. }
  1944. static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
  1945. char __user *user_buf,
  1946. size_t count, loff_t *ppos) {
  1947. struct iwl_priv *priv = file->private_data;
  1948. int len = 0;
  1949. char buf[20];
  1950. len = sprintf(buf, "0x%04X\n",
  1951. le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
  1952. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1953. }
  1954. static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
  1955. char __user *user_buf,
  1956. size_t count, loff_t *ppos) {
  1957. struct iwl_priv *priv = file->private_data;
  1958. int len = 0;
  1959. char buf[20];
  1960. len = sprintf(buf, "0x%04X\n",
  1961. le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
  1962. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  1963. }
  1964. static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
  1965. char __user *user_buf,
  1966. size_t count, loff_t *ppos) {
  1967. struct iwl_priv *priv = file->private_data;
  1968. int pos = 0;
  1969. char buf[12];
  1970. const size_t bufsz = sizeof(buf);
  1971. pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
  1972. priv->missed_beacon_threshold);
  1973. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  1974. }
  1975. static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
  1976. const char __user *user_buf,
  1977. size_t count, loff_t *ppos)
  1978. {
  1979. struct iwl_priv *priv = file->private_data;
  1980. char buf[8];
  1981. int buf_size;
  1982. int missed;
  1983. memset(buf, 0, sizeof(buf));
  1984. buf_size = min(count, sizeof(buf) - 1);
  1985. if (copy_from_user(buf, user_buf, buf_size))
  1986. return -EFAULT;
  1987. if (sscanf(buf, "%d", &missed) != 1)
  1988. return -EINVAL;
  1989. if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
  1990. missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
  1991. priv->missed_beacon_threshold =
  1992. IWL_MISSED_BEACON_THRESHOLD_DEF;
  1993. else
  1994. priv->missed_beacon_threshold = missed;
  1995. return count;
  1996. }
  1997. static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
  1998. char __user *user_buf,
  1999. size_t count, loff_t *ppos) {
  2000. struct iwl_priv *priv = file->private_data;
  2001. int pos = 0;
  2002. char buf[12];
  2003. const size_t bufsz = sizeof(buf);
  2004. pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
  2005. priv->cfg->base_params->plcp_delta_threshold);
  2006. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  2007. }
  2008. static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
  2009. const char __user *user_buf,
  2010. size_t count, loff_t *ppos) {
  2011. struct iwl_priv *priv = file->private_data;
  2012. char buf[8];
  2013. int buf_size;
  2014. int plcp;
  2015. memset(buf, 0, sizeof(buf));
  2016. buf_size = min(count, sizeof(buf) - 1);
  2017. if (copy_from_user(buf, user_buf, buf_size))
  2018. return -EFAULT;
  2019. if (sscanf(buf, "%d", &plcp) != 1)
  2020. return -EINVAL;
  2021. if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
  2022. (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
  2023. priv->cfg->base_params->plcp_delta_threshold =
  2024. IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
  2025. else
  2026. priv->cfg->base_params->plcp_delta_threshold = plcp;
  2027. return count;
  2028. }
  2029. static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
  2030. char __user *user_buf,
  2031. size_t count, loff_t *ppos) {
  2032. struct iwl_priv *priv = file->private_data;
  2033. int i, pos = 0;
  2034. char buf[300];
  2035. const size_t bufsz = sizeof(buf);
  2036. struct iwl_force_reset *force_reset;
  2037. for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
  2038. force_reset = &priv->force_reset[i];
  2039. pos += scnprintf(buf + pos, bufsz - pos,
  2040. "Force reset method %d\n", i);
  2041. pos += scnprintf(buf + pos, bufsz - pos,
  2042. "\tnumber of reset request: %d\n",
  2043. force_reset->reset_request_count);
  2044. pos += scnprintf(buf + pos, bufsz - pos,
  2045. "\tnumber of reset request success: %d\n",
  2046. force_reset->reset_success_count);
  2047. pos += scnprintf(buf + pos, bufsz - pos,
  2048. "\tnumber of reset request reject: %d\n",
  2049. force_reset->reset_reject_count);
  2050. pos += scnprintf(buf + pos, bufsz - pos,
  2051. "\treset duration: %lu\n",
  2052. force_reset->reset_duration);
  2053. }
  2054. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  2055. }
  2056. static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
  2057. const char __user *user_buf,
  2058. size_t count, loff_t *ppos) {
  2059. struct iwl_priv *priv = file->private_data;
  2060. char buf[8];
  2061. int buf_size;
  2062. int reset, ret;
  2063. memset(buf, 0, sizeof(buf));
  2064. buf_size = min(count, sizeof(buf) - 1);
  2065. if (copy_from_user(buf, user_buf, buf_size))
  2066. return -EFAULT;
  2067. if (sscanf(buf, "%d", &reset) != 1)
  2068. return -EINVAL;
  2069. switch (reset) {
  2070. case IWL_RF_RESET:
  2071. case IWL_FW_RESET:
  2072. ret = iwl_force_reset(priv, reset, true);
  2073. break;
  2074. default:
  2075. return -EINVAL;
  2076. }
  2077. return ret ? ret : count;
  2078. }
  2079. static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
  2080. const char __user *user_buf,
  2081. size_t count, loff_t *ppos) {
  2082. struct iwl_priv *priv = file->private_data;
  2083. char buf[8];
  2084. int buf_size;
  2085. int flush;
  2086. memset(buf, 0, sizeof(buf));
  2087. buf_size = min(count, sizeof(buf) - 1);
  2088. if (copy_from_user(buf, user_buf, buf_size))
  2089. return -EFAULT;
  2090. if (sscanf(buf, "%d", &flush) != 1)
  2091. return -EINVAL;
  2092. if (iwl_is_rfkill(priv->shrd))
  2093. return -EFAULT;
  2094. iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
  2095. return count;
  2096. }
  2097. static ssize_t iwl_dbgfs_wd_timeout_write(struct file *file,
  2098. const char __user *user_buf,
  2099. size_t count, loff_t *ppos) {
  2100. struct iwl_priv *priv = file->private_data;
  2101. char buf[8];
  2102. int buf_size;
  2103. int timeout;
  2104. memset(buf, 0, sizeof(buf));
  2105. buf_size = min(count, sizeof(buf) - 1);
  2106. if (copy_from_user(buf, user_buf, buf_size))
  2107. return -EFAULT;
  2108. if (sscanf(buf, "%d", &timeout) != 1)
  2109. return -EINVAL;
  2110. if (timeout < 0 || timeout > IWL_MAX_WD_TIMEOUT)
  2111. timeout = IWL_DEF_WD_TIMEOUT;
  2112. priv->cfg->base_params->wd_timeout = timeout;
  2113. iwl_setup_watchdog(priv);
  2114. return count;
  2115. }
  2116. static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
  2117. char __user *user_buf,
  2118. size_t count, loff_t *ppos) {
  2119. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  2120. int pos = 0;
  2121. char buf[200];
  2122. const size_t bufsz = sizeof(buf);
  2123. if (!priv->bt_enable_flag) {
  2124. pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n");
  2125. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  2126. }
  2127. pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n",
  2128. priv->bt_enable_flag);
  2129. pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
  2130. priv->bt_full_concurrent ? "full concurrency" : "3-wire");
  2131. pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
  2132. "last traffic notif: %d\n",
  2133. priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load);
  2134. pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
  2135. "kill_ack_mask: %x, kill_cts_mask: %x\n",
  2136. priv->bt_ch_announce, priv->kill_ack_mask,
  2137. priv->kill_cts_mask);
  2138. pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
  2139. switch (priv->bt_traffic_load) {
  2140. case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
  2141. pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
  2142. break;
  2143. case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
  2144. pos += scnprintf(buf + pos, bufsz - pos, "High\n");
  2145. break;
  2146. case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
  2147. pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
  2148. break;
  2149. case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
  2150. default:
  2151. pos += scnprintf(buf + pos, bufsz - pos, "None\n");
  2152. break;
  2153. }
  2154. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  2155. }
  2156. static ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
  2157. char __user *user_buf,
  2158. size_t count, loff_t *ppos)
  2159. {
  2160. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  2161. int pos = 0;
  2162. char buf[40];
  2163. const size_t bufsz = sizeof(buf);
  2164. if (priv->cfg->ht_params)
  2165. pos += scnprintf(buf + pos, bufsz - pos,
  2166. "use %s for aggregation\n",
  2167. (priv->cfg->ht_params->use_rts_for_aggregation) ?
  2168. "rts/cts" : "cts-to-self");
  2169. else
  2170. pos += scnprintf(buf + pos, bufsz - pos, "N/A");
  2171. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  2172. }
  2173. static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
  2174. const char __user *user_buf,
  2175. size_t count, loff_t *ppos) {
  2176. struct iwl_priv *priv = file->private_data;
  2177. char buf[8];
  2178. int buf_size;
  2179. int rts;
  2180. if (!priv->cfg->ht_params)
  2181. return -EINVAL;
  2182. memset(buf, 0, sizeof(buf));
  2183. buf_size = min(count, sizeof(buf) - 1);
  2184. if (copy_from_user(buf, user_buf, buf_size))
  2185. return -EFAULT;
  2186. if (sscanf(buf, "%d", &rts) != 1)
  2187. return -EINVAL;
  2188. if (rts)
  2189. priv->cfg->ht_params->use_rts_for_aggregation = true;
  2190. else
  2191. priv->cfg->ht_params->use_rts_for_aggregation = false;
  2192. return count;
  2193. }
  2194. DEBUGFS_READ_FILE_OPS(rx_statistics);
  2195. DEBUGFS_READ_FILE_OPS(tx_statistics);
  2196. DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
  2197. DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
  2198. DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
  2199. DEBUGFS_READ_FILE_OPS(ucode_general_stats);
  2200. DEBUGFS_READ_FILE_OPS(sensitivity);
  2201. DEBUGFS_READ_FILE_OPS(chain_noise);
  2202. DEBUGFS_READ_FILE_OPS(power_save_status);
  2203. DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
  2204. DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
  2205. DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
  2206. DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
  2207. DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
  2208. DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
  2209. DEBUGFS_READ_FILE_OPS(rxon_flags);
  2210. DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
  2211. DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
  2212. DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
  2213. DEBUGFS_WRITE_FILE_OPS(wd_timeout);
  2214. DEBUGFS_READ_FILE_OPS(bt_traffic);
  2215. DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
  2216. DEBUGFS_READ_FILE_OPS(reply_tx_error);
  2217. /*
  2218. * Create the debugfs files and directories
  2219. *
  2220. */
  2221. int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
  2222. {
  2223. struct dentry *phyd = priv->hw->wiphy->debugfsdir;
  2224. struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
  2225. dir_drv = debugfs_create_dir(name, phyd);
  2226. if (!dir_drv)
  2227. return -ENOMEM;
  2228. priv->debugfs_dir = dir_drv;
  2229. dir_data = debugfs_create_dir("data", dir_drv);
  2230. if (!dir_data)
  2231. goto err;
  2232. dir_rf = debugfs_create_dir("rf", dir_drv);
  2233. if (!dir_rf)
  2234. goto err;
  2235. dir_debug = debugfs_create_dir("debug", dir_drv);
  2236. if (!dir_debug)
  2237. goto err;
  2238. DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
  2239. DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
  2240. DEBUGFS_ADD_FILE(wowlan_sram, dir_data, S_IRUSR);
  2241. DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
  2242. DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
  2243. DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
  2244. DEBUGFS_ADD_FILE(rx_handlers, dir_data, S_IWUSR | S_IRUSR);
  2245. DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
  2246. DEBUGFS_ADD_FILE(sleep_level_override, dir_data, S_IWUSR | S_IRUSR);
  2247. DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
  2248. DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
  2249. DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
  2250. DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
  2251. DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
  2252. DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
  2253. DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
  2254. DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
  2255. DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
  2256. DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
  2257. DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
  2258. DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
  2259. DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
  2260. DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
  2261. DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
  2262. DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR);
  2263. DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR);
  2264. DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
  2265. DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
  2266. DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
  2267. DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR);
  2268. DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR);
  2269. DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
  2270. DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
  2271. DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
  2272. if (iwl_advanced_bt_coexist(priv))
  2273. DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR);
  2274. DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
  2275. &priv->disable_sens_cal);
  2276. DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
  2277. &priv->disable_chain_noise_cal);
  2278. if (iwl_trans_dbgfs_register(trans(priv), dir_debug))
  2279. goto err;
  2280. return 0;
  2281. err:
  2282. IWL_ERR(priv, "Can't create the debugfs directory\n");
  2283. iwl_dbgfs_unregister(priv);
  2284. return -ENOMEM;
  2285. }
  2286. /**
  2287. * Remove the debugfs files and directories
  2288. *
  2289. */
  2290. void iwl_dbgfs_unregister(struct iwl_priv *priv)
  2291. {
  2292. if (!priv->debugfs_dir)
  2293. return;
  2294. debugfs_remove_recursive(priv->debugfs_dir);
  2295. priv->debugfs_dir = NULL;
  2296. }