iwl-debugfs.c 88 KB

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