iwl-debugfs.c 88 KB

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