iwl-debugfs.c 83 KB

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