iwl-debugfs.c 85 KB

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