iwl-debugfs.c 85 KB

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