iwl-debugfs.c 83 KB

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