iwl-debugfs.c 84 KB

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