iwl-debugfs.c 85 KB

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