iwl-debugfs.c 88 KB

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