wlan_logging_sock_svc.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434
  1. /*
  2. * Copyright (c) 2014-2017 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted, provided that the
  9. * above copyright notice and this permission notice appear in all
  10. * copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  15. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  16. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  17. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19. * PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. /*
  22. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. /******************************************************************************
  27. * wlan_logging_sock_svc.c
  28. *
  29. ******************************************************************************/
  30. #ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
  31. #include <vmalloc.h>
  32. #ifdef CONFIG_MCL
  33. #include <cds_api.h>
  34. #include <host_diag_core_event.h>
  35. #include "cds_utils.h"
  36. #include "csr_api.h"
  37. #include "wlan_hdd_main.h"
  38. #include "wma.h"
  39. #include "ol_txrx_api.h"
  40. #include "pktlog_ac.h"
  41. #endif
  42. #include <wlan_logging_sock_svc.h>
  43. #include <kthread.h>
  44. #include <qdf_time.h>
  45. #include <qdf_trace.h>
  46. #include <qdf_mc_timer.h>
  47. #include <wlan_ptt_sock_svc.h>
  48. #include <host_diag_core_event.h>
  49. #include "host_diag_core_log.h"
  50. #ifdef CNSS_GENL
  51. #include <net/cnss_nl.h>
  52. #endif
  53. #define MAX_NUM_PKT_LOG 32
  54. /**
  55. * struct tx_status - tx status
  56. * @tx_status_ok: successfully sent + acked
  57. * @tx_status_discard: discard - not sent (congestion control)
  58. * @tx_status_no_ack: no_ack - sent, but no ack
  59. * @tx_status_download_fail: download_fail -
  60. * the host could not deliver the tx frame to the target
  61. * @tx_status_peer_del: peer_del - tx completion for
  62. * alreay deleted peer used for HL case
  63. *
  64. * This enum has tx status types
  65. */
  66. enum tx_status {
  67. tx_status_ok,
  68. tx_status_discard,
  69. tx_status_no_ack,
  70. tx_status_download_fail,
  71. tx_status_peer_del,
  72. };
  73. #ifdef CONFIG_MCL
  74. static uint8_t gtx_count;
  75. static uint8_t grx_count;
  76. #endif
  77. #define LOGGING_TRACE(level, args ...) \
  78. QDF_TRACE(QDF_MODULE_ID_HDD, level, ## args)
  79. /* Global variables */
  80. #define ANI_NL_MSG_LOG_TYPE 89
  81. #define ANI_NL_MSG_READY_IND_TYPE 90
  82. #define MAX_LOGMSG_LENGTH 2048
  83. #define MAX_SKBMSG_LENGTH 4096
  84. #define MAX_PKTSTATS_LENGTH 2048
  85. #define MAX_PKTSTATS_BUFF 16
  86. #define HOST_LOG_DRIVER_MSG 0x001
  87. #define HOST_LOG_PER_PKT_STATS 0x002
  88. #define HOST_LOG_FW_FLUSH_COMPLETE 0x003
  89. #define DIAG_TYPE_LOGS 1
  90. #define PTT_MSG_DIAG_CMDS_TYPE 0x5050
  91. struct log_msg {
  92. struct list_head node;
  93. unsigned int radio;
  94. unsigned int index;
  95. /* indicates the current filled log length in logbuf */
  96. unsigned int filled_length;
  97. /*
  98. * Buf to hold the log msg
  99. * tAniHdr + log
  100. */
  101. char logbuf[MAX_LOGMSG_LENGTH];
  102. };
  103. /**
  104. * struct packet_dump - This data structure contains the
  105. * Tx/Rx packet stats
  106. * @status: Status
  107. * @type: Type
  108. * @driver_ts: driver timestamp
  109. * @fw_ts: fw timestamp
  110. */
  111. struct packet_dump {
  112. unsigned char status;
  113. unsigned char type;
  114. uint32_t driver_ts;
  115. uint16_t fw_ts;
  116. } __attribute__((__packed__));
  117. /**
  118. * struct pkt_stats_msg - This data structure contains the
  119. * pkt stats node for link list
  120. * @node: LinkList node
  121. * @node: Pointer to skb
  122. */
  123. struct pkt_stats_msg {
  124. struct list_head node;
  125. struct sk_buff *skb;
  126. };
  127. struct wlan_logging {
  128. /* Log Fatal and ERROR to console */
  129. bool log_to_console;
  130. /* Number of buffers to be used for logging */
  131. int num_buf;
  132. /* Lock to synchronize access to shared logging resource */
  133. spinlock_t spin_lock;
  134. /* Holds the free node which can be used for filling logs */
  135. struct list_head free_list;
  136. /* Holds the filled nodes which needs to be indicated to APP */
  137. struct list_head filled_list;
  138. /* Wait queue for Logger thread */
  139. wait_queue_head_t wait_queue;
  140. /* Logger thread */
  141. struct task_struct *thread;
  142. /* Logging thread sets this variable on exit */
  143. struct completion shutdown_comp;
  144. /* Indicates to logger thread to exit */
  145. bool exit;
  146. /* Holds number of dropped logs */
  147. unsigned int drop_count;
  148. /* current logbuf to which the log will be filled to */
  149. struct log_msg *pcur_node;
  150. /* Event flag used for wakeup and post indication*/
  151. unsigned long eventFlag;
  152. /* Indicates logger thread is activated */
  153. bool is_active;
  154. /* Flush completion check */
  155. bool is_flush_complete;
  156. /* paramaters for pkt stats */
  157. struct list_head pkt_stat_free_list;
  158. struct list_head pkt_stat_filled_list;
  159. struct pkt_stats_msg *pkt_stats_pcur_node;
  160. unsigned int pkt_stat_drop_cnt;
  161. spinlock_t pkt_stats_lock;
  162. unsigned int pkt_stats_msg_idx;
  163. };
  164. static struct wlan_logging gwlan_logging;
  165. static struct log_msg *gplog_msg;
  166. static struct pkt_stats_msg *gpkt_stats_buffers;
  167. /* Need to call this with spin_lock acquired */
  168. static int wlan_queue_logmsg_for_app(void)
  169. {
  170. char *ptr;
  171. int ret = 0;
  172. ptr = &gwlan_logging.pcur_node->logbuf[sizeof(tAniHdr)];
  173. ptr[gwlan_logging.pcur_node->filled_length] = '\0';
  174. *(unsigned short *)(gwlan_logging.pcur_node->logbuf) =
  175. ANI_NL_MSG_LOG_TYPE;
  176. *(unsigned short *)(gwlan_logging.pcur_node->logbuf + 2) =
  177. gwlan_logging.pcur_node->filled_length;
  178. list_add_tail(&gwlan_logging.pcur_node->node,
  179. &gwlan_logging.filled_list);
  180. if (!list_empty(&gwlan_logging.free_list)) {
  181. /* Get buffer from free list */
  182. gwlan_logging.pcur_node =
  183. (struct log_msg *)(gwlan_logging.free_list.next);
  184. list_del_init(gwlan_logging.free_list.next);
  185. } else if (!list_empty(&gwlan_logging.filled_list)) {
  186. /* Get buffer from filled list */
  187. /* This condition will drop the packet from being
  188. * indicated to app
  189. */
  190. gwlan_logging.pcur_node =
  191. (struct log_msg *)(gwlan_logging.filled_list.next);
  192. ++gwlan_logging.drop_count;
  193. list_del_init(gwlan_logging.filled_list.next);
  194. ret = 1;
  195. }
  196. /* Reset the current node values */
  197. gwlan_logging.pcur_node->filled_length = 0;
  198. return ret;
  199. }
  200. #ifdef QCA_WIFI_3_0_ADRASTEA
  201. /**
  202. * wlan_add_user_log_radio_time_stamp() - add radio, firmware timestamp and
  203. * time stamp in log buffer
  204. * @tbuf: Pointer to time stamp buffer
  205. * @tbuf_sz: Time buffer size
  206. * @ts: Time stamp value
  207. * @radoi: the radio index
  208. *
  209. * For adrastea time stamp is QTIMER raw tick which will be used by cnss_diag
  210. * to convert it into user visible time stamp. In adrstea FW also uses QTIMER
  211. * raw ticks which is needed to synchronize host and fw log time stamps
  212. *
  213. * Also add logcat timestamp so that driver logs and
  214. * logcat logs can be co-related
  215. *
  216. * For discrete solution e.g rome use system tick and convert it into
  217. * seconds.milli seconds
  218. *
  219. * Return: number of characters written in target buffer not including
  220. * trailing '/0'
  221. */
  222. static int wlan_add_user_log_radio_time_stamp(char *tbuf, size_t tbuf_sz,
  223. uint64_t ts, int radio)
  224. {
  225. int tlen;
  226. char time_buf[20];
  227. qdf_get_time_of_the_day_in_hr_min_sec_usec(time_buf, sizeof(time_buf));
  228. tlen = scnprintf(tbuf, tbuf_sz, "R%d: [%.16s][%llu] %s ", radio,
  229. ((in_irq() ? "irq" : in_softirq() ? "soft_irq" :
  230. current->comm)),
  231. ts, time_buf);
  232. return tlen;
  233. }
  234. #else
  235. /**
  236. * wlan_add_user_log_radio_time_stamp() - add radio, firmware timestamp and
  237. * logcat timestamp in log buffer
  238. * @tbuf: Pointer to time stamp buffer
  239. * @tbuf_sz: Time buffer size
  240. * @ts: Time stamp value
  241. * @radio: the radio index
  242. *
  243. * For adrastea time stamp QTIMER raw tick which will be used by cnss_diag
  244. * to convert it into user visible time stamp
  245. *
  246. * Also add logcat timestamp so that driver logs and
  247. * logcat logs can be co-related
  248. *
  249. * For discrete solution e.g rome use system tick and convert it into
  250. * seconds.milli seconds
  251. *
  252. * Return: number of characters written in target buffer not including
  253. * trailing '/0'
  254. */
  255. static int wlan_add_user_log_radio_time_stamp(char *tbuf, size_t tbuf_sz,
  256. uint64_t ts, int radio)
  257. {
  258. int tlen;
  259. uint32_t rem;
  260. char time_buf[20];
  261. qdf_get_time_of_the_day_in_hr_min_sec_usec(time_buf, sizeof(time_buf));
  262. rem = do_div(ts, QDF_MC_TIMER_TO_SEC_UNIT);
  263. tlen = scnprintf(tbuf, tbuf_sz, "R%d: [%.16s][%lu.%06lu] %s ", radio,
  264. ((in_irq() ? "irq" : in_softirq() ? "soft_irq" :
  265. current->comm)),
  266. (unsigned long) ts,
  267. (unsigned long)rem, time_buf);
  268. return tlen;
  269. }
  270. #endif
  271. #ifdef CONFIG_MCL
  272. static inline void print_to_console(char *tbuf, char *to_be_sent)
  273. {
  274. pr_info("%s %s\n", tbuf, to_be_sent);
  275. }
  276. #else
  277. #define print_to_console(str1, str2)
  278. #endif
  279. int wlan_log_to_user(QDF_TRACE_LEVEL log_level, char *to_be_sent, int length)
  280. {
  281. /* Add the current time stamp */
  282. char *ptr;
  283. char tbuf[60];
  284. int tlen;
  285. int total_log_len;
  286. unsigned int *pfilled_length;
  287. bool wake_up_thread = false;
  288. unsigned long flags;
  289. uint64_t ts;
  290. int radio = 0;
  291. bool log_overflow = false;
  292. #ifdef CONFIG_MCL
  293. radio = cds_get_radio_index();
  294. #endif
  295. if (
  296. #ifdef CONFIG_MCL
  297. !cds_is_multicast_logging() ||
  298. #endif
  299. (radio == -EINVAL) ||
  300. (!gwlan_logging.is_active)) {
  301. /*
  302. * This is to make sure that we print the logs to kmsg console
  303. * when no logger app is running. This is also needed to
  304. * log the initial messages during loading of driver where even
  305. * if app is running it will not be able to
  306. * register with driver immediately and start logging all the
  307. * messages.
  308. */
  309. /*
  310. * R%d: if the radio index is invalid, just post the message
  311. * to console.
  312. * Also the radio index shouldn't happen to be EINVAL, but if
  313. * that happen just print it, so that the logging would be
  314. * aware the cnss_logger is somehow failed.
  315. */
  316. pr_info("R%d: %s\n", radio, to_be_sent);
  317. return 0;
  318. }
  319. ts = qdf_get_log_timestamp();
  320. tlen = wlan_add_user_log_radio_time_stamp(tbuf, sizeof(tbuf), ts,
  321. radio);
  322. /* 1+1 indicate '\n'+'\0' */
  323. total_log_len = length + tlen + 1 + 1;
  324. spin_lock_irqsave(&gwlan_logging.spin_lock, flags);
  325. /* wlan logging svc resources are not yet initialized */
  326. if (!gwlan_logging.pcur_node) {
  327. spin_unlock_irqrestore(&gwlan_logging.spin_lock, flags);
  328. return -EIO;
  329. }
  330. pfilled_length = &gwlan_logging.pcur_node->filled_length;
  331. /* Check if we can accomodate more log into current node/buffer */
  332. if ((MAX_LOGMSG_LENGTH <= (*pfilled_length +
  333. sizeof(tAniNlHdr))) ||
  334. ((MAX_LOGMSG_LENGTH - (*pfilled_length +
  335. sizeof(tAniNlHdr))) < total_log_len)) {
  336. wake_up_thread = true;
  337. wlan_queue_logmsg_for_app();
  338. pfilled_length = &gwlan_logging.pcur_node->filled_length;
  339. }
  340. ptr = &gwlan_logging.pcur_node->logbuf[sizeof(tAniHdr)];
  341. /* Assumption here is that we receive logs which is always less than
  342. * MAX_LOGMSG_LENGTH, where we can accomodate the
  343. * tAniNlHdr + [context][timestamp] + log
  344. *
  345. * Continue and copy logs to the available length and discard the rest.
  346. */
  347. if (MAX_LOGMSG_LENGTH < (sizeof(tAniNlHdr) + total_log_len)) {
  348. log_overflow = true;
  349. total_log_len = MAX_LOGMSG_LENGTH - sizeof(tAniNlHdr) - 2;
  350. }
  351. memcpy(&ptr[*pfilled_length], tbuf, tlen);
  352. memcpy(&ptr[*pfilled_length + tlen], to_be_sent,
  353. min(length, (total_log_len - tlen)));
  354. *pfilled_length += tlen + min(length, total_log_len - tlen);
  355. ptr[*pfilled_length] = '\n';
  356. *pfilled_length += 1;
  357. spin_unlock_irqrestore(&gwlan_logging.spin_lock, flags);
  358. /*
  359. * QDF_ASSERT if complete log was not accomodated into
  360. * the available buffer.
  361. */
  362. QDF_ASSERT(!log_overflow);
  363. /* Wakeup logger thread */
  364. if ((true == wake_up_thread)) {
  365. set_bit(HOST_LOG_DRIVER_MSG, &gwlan_logging.eventFlag);
  366. wake_up_interruptible(&gwlan_logging.wait_queue);
  367. }
  368. if (gwlan_logging.log_to_console
  369. && ((QDF_TRACE_LEVEL_FATAL == log_level)
  370. || (QDF_TRACE_LEVEL_ERROR == log_level))) {
  371. print_to_console(tbuf, to_be_sent);
  372. }
  373. return 0;
  374. }
  375. /**
  376. * pkt_stats_fill_headers() - This function adds headers to skb
  377. * @skb: skb to which headers need to be added
  378. *
  379. * Return: 0 on success or Errno on failure
  380. */
  381. static int pkt_stats_fill_headers(struct sk_buff *skb)
  382. {
  383. struct host_log_pktlog_info cds_pktlog;
  384. int cds_pkt_size = sizeof(struct host_log_pktlog_info);
  385. tAniNlHdr msg_header;
  386. int extra_header_len, nl_payload_len;
  387. static int nlmsg_seq;
  388. int diag_type;
  389. qdf_mem_zero(&cds_pktlog, cds_pkt_size);
  390. cds_pktlog.version = VERSION_LOG_WLAN_PKT_LOG_INFO_C;
  391. cds_pktlog.buf_len = skb->len;
  392. cds_pktlog.seq_no = gwlan_logging.pkt_stats_msg_idx++;
  393. #ifdef CONFIG_MCL
  394. host_diag_log_set_code(&cds_pktlog, LOG_WLAN_PKT_LOG_INFO_C);
  395. host_diag_log_set_length(&cds_pktlog.log_hdr, skb->len +
  396. cds_pkt_size);
  397. #endif
  398. if (unlikely(skb_headroom(skb) < cds_pkt_size)) {
  399. pr_err("VPKT [%d]: Insufficient headroom, head[%p], data[%p], req[%zu]",
  400. __LINE__, skb->head, skb->data, sizeof(msg_header));
  401. return -EIO;
  402. }
  403. qdf_mem_copy(skb_push(skb, cds_pkt_size),
  404. &cds_pktlog, cds_pkt_size);
  405. if (unlikely(skb_headroom(skb) < sizeof(int))) {
  406. pr_err("VPKT [%d]: Insufficient headroom, head[%p], data[%p], req[%zu]",
  407. __LINE__, skb->head, skb->data, sizeof(int));
  408. return -EIO;
  409. }
  410. diag_type = DIAG_TYPE_LOGS;
  411. qdf_mem_copy(skb_push(skb, sizeof(int)), &diag_type, sizeof(int));
  412. extra_header_len = sizeof(msg_header.radio) + sizeof(tAniHdr) +
  413. sizeof(struct nlmsghdr);
  414. nl_payload_len = extra_header_len + skb->len;
  415. msg_header.nlh.nlmsg_type = ANI_NL_MSG_PUMAC;
  416. msg_header.nlh.nlmsg_len = nl_payload_len;
  417. msg_header.nlh.nlmsg_flags = NLM_F_REQUEST;
  418. msg_header.nlh.nlmsg_pid = 0;
  419. msg_header.nlh.nlmsg_seq = nlmsg_seq++;
  420. msg_header.radio = 0;
  421. msg_header.wmsg.type = PTT_MSG_DIAG_CMDS_TYPE;
  422. msg_header.wmsg.length = cpu_to_be16(skb->len);
  423. if (unlikely(skb_headroom(skb) < sizeof(msg_header))) {
  424. pr_err("VPKT [%d]: Insufficient headroom, head[%p], data[%p], req[%zu]",
  425. __LINE__, skb->head, skb->data, sizeof(msg_header));
  426. return -EIO;
  427. }
  428. qdf_mem_copy(skb_push(skb, sizeof(msg_header)), &msg_header,
  429. sizeof(msg_header));
  430. return 0;
  431. }
  432. /**
  433. * nl_srv_bcast_diag() - Wrapper to send bcast msgs to diag events mcast grp
  434. * @skb: sk buffer pointer
  435. *
  436. * Sends the bcast message to diag events multicast group with generic nl socket
  437. * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
  438. *
  439. * Return: zero on success, error code otherwise
  440. */
  441. static int nl_srv_bcast_diag(struct sk_buff *skb)
  442. {
  443. #ifdef CNSS_GENL
  444. return nl_srv_bcast(skb, CLD80211_MCGRP_DIAG_EVENTS, ANI_NL_MSG_PUMAC);
  445. #else
  446. return nl_srv_bcast(skb);
  447. #endif
  448. }
  449. /**
  450. * nl_srv_bcast_host_logs() - Wrapper to send bcast msgs to host logs mcast grp
  451. * @skb: sk buffer pointer
  452. *
  453. * Sends the bcast message to host logs multicast group with generic nl socket
  454. * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
  455. *
  456. * Return: zero on success, error code otherwise
  457. */
  458. static int nl_srv_bcast_host_logs(struct sk_buff *skb)
  459. {
  460. #ifdef CNSS_GENL
  461. return nl_srv_bcast(skb, CLD80211_MCGRP_HOST_LOGS, ANI_NL_MSG_LOG);
  462. #else
  463. return nl_srv_bcast(skb);
  464. #endif
  465. }
  466. /**
  467. * pktlog_send_per_pkt_stats_to_user() - This function is used to send the per
  468. * packet statistics to the user
  469. *
  470. * This function is used to send the per packet statistics to the user
  471. *
  472. * Return: Success if the message is posted to user
  473. */
  474. int pktlog_send_per_pkt_stats_to_user(void)
  475. {
  476. int ret = -1;
  477. struct pkt_stats_msg *pstats_msg;
  478. unsigned long flags;
  479. struct sk_buff *skb_new = NULL;
  480. static int rate_limit;
  481. bool free_old_skb = false;
  482. while (!list_empty(&gwlan_logging.pkt_stat_filled_list)
  483. && !gwlan_logging.exit) {
  484. skb_new = dev_alloc_skb(MAX_SKBMSG_LENGTH);
  485. if (skb_new == NULL) {
  486. if (!rate_limit) {
  487. pr_err("%s: dev_alloc_skb() failed for msg size[%d] drop count = %u\n",
  488. __func__, MAX_SKBMSG_LENGTH,
  489. gwlan_logging.drop_count);
  490. }
  491. rate_limit = 1;
  492. ret = -ENOMEM;
  493. break;
  494. }
  495. spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, flags);
  496. pstats_msg = (struct pkt_stats_msg *)
  497. (gwlan_logging.pkt_stat_filled_list.next);
  498. list_del_init(gwlan_logging.pkt_stat_filled_list.next);
  499. spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, flags);
  500. ret = pkt_stats_fill_headers(pstats_msg->skb);
  501. if (ret < 0) {
  502. pr_err("%s failed to fill headers %d\n", __func__, ret);
  503. free_old_skb = true;
  504. goto err;
  505. }
  506. ret = nl_srv_bcast_diag(pstats_msg->skb);
  507. if (ret < 0) {
  508. pr_info("%s: Send Failed %d drop_count = %u\n",
  509. __func__, ret,
  510. ++gwlan_logging.pkt_stat_drop_cnt);
  511. } else {
  512. ret = 0;
  513. }
  514. err:
  515. /*
  516. * Free old skb in case or error before assigning new skb
  517. * to the free list.
  518. */
  519. if (free_old_skb)
  520. dev_kfree_skb(pstats_msg->skb);
  521. spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, flags);
  522. pstats_msg->skb = skb_new;
  523. list_add_tail(&pstats_msg->node,
  524. &gwlan_logging.pkt_stat_free_list);
  525. spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, flags);
  526. ret = 0;
  527. }
  528. return ret;
  529. }
  530. static int send_filled_buffers_to_user(void)
  531. {
  532. int ret = -1;
  533. struct log_msg *plog_msg;
  534. int payload_len;
  535. int tot_msg_len;
  536. tAniNlHdr *wnl;
  537. struct sk_buff *skb = NULL;
  538. struct nlmsghdr *nlh;
  539. static int nlmsg_seq;
  540. unsigned long flags;
  541. static int rate_limit;
  542. while (!list_empty(&gwlan_logging.filled_list)
  543. && !gwlan_logging.exit) {
  544. skb = dev_alloc_skb(MAX_LOGMSG_LENGTH);
  545. if (skb == NULL) {
  546. if (!rate_limit) {
  547. pr_err
  548. ("%s: dev_alloc_skb() failed for msg size[%d] drop count = %u\n",
  549. __func__, MAX_LOGMSG_LENGTH,
  550. gwlan_logging.drop_count);
  551. }
  552. rate_limit = 1;
  553. ret = -ENOMEM;
  554. break;
  555. }
  556. rate_limit = 0;
  557. spin_lock_irqsave(&gwlan_logging.spin_lock, flags);
  558. plog_msg = (struct log_msg *)
  559. (gwlan_logging.filled_list.next);
  560. list_del_init(gwlan_logging.filled_list.next);
  561. spin_unlock_irqrestore(&gwlan_logging.spin_lock, flags);
  562. /* 4 extra bytes for the radio idx */
  563. payload_len = plog_msg->filled_length +
  564. sizeof(wnl->radio) + sizeof(tAniHdr);
  565. tot_msg_len = NLMSG_SPACE(payload_len);
  566. nlh = nlmsg_put(skb, 0, nlmsg_seq++,
  567. ANI_NL_MSG_LOG, payload_len, NLM_F_REQUEST);
  568. if (NULL == nlh) {
  569. spin_lock_irqsave(&gwlan_logging.spin_lock, flags);
  570. list_add_tail(&plog_msg->node,
  571. &gwlan_logging.free_list);
  572. spin_unlock_irqrestore(&gwlan_logging.spin_lock, flags);
  573. pr_err("%s: drop_count = %u\n", __func__,
  574. ++gwlan_logging.drop_count);
  575. pr_err("%s: nlmsg_put() failed for msg size[%d]\n",
  576. __func__, tot_msg_len);
  577. dev_kfree_skb(skb);
  578. skb = NULL;
  579. ret = -EINVAL;
  580. continue;
  581. }
  582. wnl = (tAniNlHdr *) nlh;
  583. wnl->radio = plog_msg->radio;
  584. memcpy(&wnl->wmsg, plog_msg->logbuf,
  585. plog_msg->filled_length + sizeof(tAniHdr));
  586. spin_lock_irqsave(&gwlan_logging.spin_lock, flags);
  587. list_add_tail(&plog_msg->node, &gwlan_logging.free_list);
  588. spin_unlock_irqrestore(&gwlan_logging.spin_lock, flags);
  589. ret = nl_srv_bcast_host_logs(skb);
  590. /* print every 64th drop count */
  591. if (ret < 0 && (!(gwlan_logging.drop_count % 0x40))) {
  592. pr_err("%s: Send Failed %d drop_count = %u\n",
  593. __func__, ret, ++gwlan_logging.drop_count);
  594. }
  595. }
  596. return ret;
  597. }
  598. #ifdef FEATURE_WLAN_DIAG_SUPPORT
  599. /**
  600. * wlan_report_log_completion() - Report bug report completion to userspace
  601. * @is_fatal: Type of event, fatal or not
  602. * @indicator: Source of bug report, framework/host/firmware
  603. * @reason_code: Reason for triggering bug report
  604. *
  605. * This function is used to report the bug report completion to userspace
  606. *
  607. * Return: None
  608. */
  609. void wlan_report_log_completion(uint32_t is_fatal,
  610. uint32_t indicator,
  611. uint32_t reason_code)
  612. {
  613. WLAN_HOST_DIAG_EVENT_DEF(wlan_diag_event,
  614. struct host_event_wlan_log_complete);
  615. wlan_diag_event.is_fatal = is_fatal;
  616. wlan_diag_event.indicator = indicator;
  617. wlan_diag_event.reason_code = reason_code;
  618. wlan_diag_event.reserved = 0;
  619. WLAN_HOST_DIAG_EVENT_REPORT(&wlan_diag_event, EVENT_WLAN_LOG_COMPLETE);
  620. }
  621. #endif
  622. #ifdef CONFIG_MCL
  623. /**
  624. * send_flush_completion_to_user() - Indicate flush completion to the user
  625. *
  626. * This function is used to send the flush completion message to user space
  627. *
  628. * Return: None
  629. */
  630. static void send_flush_completion_to_user(void)
  631. {
  632. uint32_t is_fatal, indicator, reason_code;
  633. bool recovery_needed;
  634. cds_get_and_reset_log_completion(&is_fatal,
  635. &indicator, &reason_code, &recovery_needed);
  636. /* Error on purpose, so that it will get logged in the kmsg */
  637. LOGGING_TRACE(QDF_TRACE_LEVEL_ERROR,
  638. "%s: Sending flush done to userspace", __func__);
  639. wlan_report_log_completion(is_fatal, indicator, reason_code);
  640. if (recovery_needed)
  641. cds_trigger_recovery(false);
  642. }
  643. #endif
  644. /**
  645. * wlan_logging_thread() - The WLAN Logger thread
  646. * @Arg - pointer to the HDD context
  647. *
  648. * This thread logs log message to App registered for the logs.
  649. */
  650. static int wlan_logging_thread(void *Arg)
  651. {
  652. int ret_wait_status = 0;
  653. int ret = 0;
  654. unsigned long flags;
  655. while (!gwlan_logging.exit) {
  656. ret_wait_status =
  657. wait_event_interruptible(gwlan_logging.wait_queue,
  658. (!list_empty
  659. (&gwlan_logging.filled_list)
  660. || test_bit(
  661. HOST_LOG_DRIVER_MSG,
  662. &gwlan_logging.eventFlag)
  663. || test_bit(
  664. HOST_LOG_PER_PKT_STATS,
  665. &gwlan_logging.eventFlag)
  666. || test_bit(
  667. HOST_LOG_FW_FLUSH_COMPLETE,
  668. &gwlan_logging.eventFlag)
  669. || gwlan_logging.exit));
  670. if (ret_wait_status == -ERESTARTSYS) {
  671. pr_err
  672. ("%s: wait_event_interruptible returned -ERESTARTSYS",
  673. __func__);
  674. break;
  675. }
  676. if (gwlan_logging.exit)
  677. break;
  678. if (test_and_clear_bit(HOST_LOG_DRIVER_MSG,
  679. &gwlan_logging.eventFlag)) {
  680. ret = send_filled_buffers_to_user();
  681. if (-ENOMEM == ret)
  682. msleep(200);
  683. #ifdef CONFIG_MCL
  684. if (WLAN_LOG_INDICATOR_HOST_ONLY ==
  685. cds_get_log_indicator()) {
  686. send_flush_completion_to_user();
  687. }
  688. #endif
  689. }
  690. if (test_and_clear_bit(HOST_LOG_PER_PKT_STATS,
  691. &gwlan_logging.eventFlag)) {
  692. ret = pktlog_send_per_pkt_stats_to_user();
  693. if (-ENOMEM == ret)
  694. msleep(200);
  695. }
  696. if (test_and_clear_bit(HOST_LOG_FW_FLUSH_COMPLETE,
  697. &gwlan_logging.eventFlag)) {
  698. /* Flush bit could have been set while we were mid
  699. * way in the logging thread. So, need to check other
  700. * buffers like log messages, per packet stats again
  701. * to flush any residual data in them
  702. */
  703. if (gwlan_logging.is_flush_complete == true) {
  704. gwlan_logging.is_flush_complete = false;
  705. #ifdef CONFIG_MCL
  706. send_flush_completion_to_user();
  707. #endif
  708. } else {
  709. gwlan_logging.is_flush_complete = true;
  710. /* Flush all current host logs*/
  711. spin_lock_irqsave(&gwlan_logging.spin_lock,
  712. flags);
  713. wlan_queue_logmsg_for_app();
  714. spin_unlock_irqrestore(&gwlan_logging.spin_lock,
  715. flags);
  716. set_bit(HOST_LOG_DRIVER_MSG,
  717. &gwlan_logging.eventFlag);
  718. set_bit(HOST_LOG_PER_PKT_STATS,
  719. &gwlan_logging.eventFlag);
  720. set_bit(HOST_LOG_FW_FLUSH_COMPLETE,
  721. &gwlan_logging.eventFlag);
  722. wake_up_interruptible(
  723. &gwlan_logging.wait_queue);
  724. }
  725. }
  726. }
  727. complete_and_exit(&gwlan_logging.shutdown_comp, 0);
  728. return 0;
  729. }
  730. int wlan_logging_sock_activate_svc(int log_to_console, int num_buf)
  731. {
  732. int i = 0, j, pkt_stats_size;
  733. unsigned long irq_flag;
  734. gplog_msg = (struct log_msg *)vmalloc(num_buf * sizeof(struct log_msg));
  735. if (!gplog_msg) {
  736. pr_err("%s: Could not allocate memory\n", __func__);
  737. return -ENOMEM;
  738. }
  739. qdf_mem_zero(gplog_msg, (num_buf * sizeof(struct log_msg)));
  740. gwlan_logging.log_to_console = !!log_to_console;
  741. gwlan_logging.num_buf = num_buf;
  742. spin_lock_irqsave(&gwlan_logging.spin_lock, irq_flag);
  743. INIT_LIST_HEAD(&gwlan_logging.free_list);
  744. INIT_LIST_HEAD(&gwlan_logging.filled_list);
  745. for (i = 0; i < num_buf; i++) {
  746. list_add(&gplog_msg[i].node, &gwlan_logging.free_list);
  747. gplog_msg[i].index = i;
  748. }
  749. gwlan_logging.pcur_node = (struct log_msg *)
  750. (gwlan_logging.free_list.next);
  751. list_del_init(gwlan_logging.free_list.next);
  752. spin_unlock_irqrestore(&gwlan_logging.spin_lock, irq_flag);
  753. /* Initialize the pktStats data structure here */
  754. pkt_stats_size = sizeof(struct pkt_stats_msg);
  755. gpkt_stats_buffers = vmalloc(MAX_PKTSTATS_BUFF * pkt_stats_size);
  756. if (!gpkt_stats_buffers) {
  757. pr_err("%s: Could not allocate memory for Pkt stats\n",
  758. __func__);
  759. goto err1;
  760. }
  761. qdf_mem_zero(gpkt_stats_buffers,
  762. MAX_PKTSTATS_BUFF * pkt_stats_size);
  763. spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, irq_flag);
  764. gwlan_logging.pkt_stats_msg_idx = 0;
  765. INIT_LIST_HEAD(&gwlan_logging.pkt_stat_free_list);
  766. INIT_LIST_HEAD(&gwlan_logging.pkt_stat_filled_list);
  767. spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, irq_flag);
  768. for (i = 0; i < MAX_PKTSTATS_BUFF; i++) {
  769. gpkt_stats_buffers[i].skb = dev_alloc_skb(MAX_PKTSTATS_LENGTH);
  770. if (gpkt_stats_buffers[i].skb == NULL) {
  771. pr_err("%s: Memory alloc failed for skb", __func__);
  772. /* free previously allocated skb and return */
  773. for (j = 0; j < i ; j++)
  774. dev_kfree_skb(gpkt_stats_buffers[j].skb);
  775. goto err2;
  776. }
  777. spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, irq_flag);
  778. list_add(&gpkt_stats_buffers[i].node,
  779. &gwlan_logging.pkt_stat_free_list);
  780. spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, irq_flag);
  781. }
  782. spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, irq_flag);
  783. gwlan_logging.pkt_stats_pcur_node = (struct pkt_stats_msg *)
  784. (gwlan_logging.pkt_stat_free_list.next);
  785. list_del_init(gwlan_logging.pkt_stat_free_list.next);
  786. spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, irq_flag);
  787. /* Pkt Stats intialization done */
  788. init_waitqueue_head(&gwlan_logging.wait_queue);
  789. gwlan_logging.exit = false;
  790. clear_bit(HOST_LOG_DRIVER_MSG, &gwlan_logging.eventFlag);
  791. clear_bit(HOST_LOG_PER_PKT_STATS, &gwlan_logging.eventFlag);
  792. clear_bit(HOST_LOG_FW_FLUSH_COMPLETE, &gwlan_logging.eventFlag);
  793. init_completion(&gwlan_logging.shutdown_comp);
  794. gwlan_logging.thread = kthread_create(wlan_logging_thread, NULL,
  795. "wlan_logging_thread");
  796. if (IS_ERR(gwlan_logging.thread)) {
  797. pr_err("%s: Could not Create LogMsg Thread Controller",
  798. __func__);
  799. goto err3;
  800. }
  801. wake_up_process(gwlan_logging.thread);
  802. gwlan_logging.is_active = true;
  803. gwlan_logging.is_flush_complete = false;
  804. return 0;
  805. err3:
  806. for (i = 0; i < MAX_PKTSTATS_BUFF; i++) {
  807. if (gpkt_stats_buffers[i].skb)
  808. dev_kfree_skb(gpkt_stats_buffers[i].skb);
  809. }
  810. err2:
  811. spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, irq_flag);
  812. gwlan_logging.pkt_stats_pcur_node = NULL;
  813. spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, irq_flag);
  814. vfree(gpkt_stats_buffers);
  815. gpkt_stats_buffers = NULL;
  816. err1:
  817. spin_lock_irqsave(&gwlan_logging.spin_lock, irq_flag);
  818. gwlan_logging.pcur_node = NULL;
  819. spin_unlock_irqrestore(&gwlan_logging.spin_lock, irq_flag);
  820. vfree(gplog_msg);
  821. gplog_msg = NULL;
  822. return -ENOMEM;
  823. }
  824. int wlan_logging_sock_deactivate_svc(void)
  825. {
  826. unsigned long irq_flag;
  827. int i = 0;
  828. if (!gplog_msg)
  829. return 0;
  830. #ifdef CONFIG_MCL
  831. INIT_COMPLETION(gwlan_logging.shutdown_comp);
  832. #endif
  833. gwlan_logging.exit = true;
  834. gwlan_logging.is_active = false;
  835. #ifdef CONFIG_MCL
  836. cds_set_multicast_logging(0);
  837. #endif
  838. gwlan_logging.is_flush_complete = false;
  839. clear_bit(HOST_LOG_DRIVER_MSG, &gwlan_logging.eventFlag);
  840. clear_bit(HOST_LOG_PER_PKT_STATS, &gwlan_logging.eventFlag);
  841. clear_bit(HOST_LOG_FW_FLUSH_COMPLETE, &gwlan_logging.eventFlag);
  842. wake_up_interruptible(&gwlan_logging.wait_queue);
  843. wait_for_completion(&gwlan_logging.shutdown_comp);
  844. spin_lock_irqsave(&gwlan_logging.spin_lock, irq_flag);
  845. gwlan_logging.pcur_node = NULL;
  846. spin_unlock_irqrestore(&gwlan_logging.spin_lock, irq_flag);
  847. vfree(gplog_msg);
  848. gplog_msg = NULL;
  849. spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, irq_flag);
  850. gwlan_logging.pkt_stats_pcur_node = NULL;
  851. gwlan_logging.pkt_stats_msg_idx = 0;
  852. gwlan_logging.pkt_stat_drop_cnt = 0;
  853. for (i = 0; i < MAX_PKTSTATS_BUFF; i++) {
  854. if (gpkt_stats_buffers[i].skb)
  855. dev_kfree_skb(gpkt_stats_buffers[i].skb);
  856. }
  857. spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, irq_flag);
  858. vfree(gpkt_stats_buffers);
  859. gpkt_stats_buffers = NULL;
  860. return 0;
  861. }
  862. int wlan_logging_sock_init_svc(void)
  863. {
  864. spin_lock_init(&gwlan_logging.spin_lock);
  865. spin_lock_init(&gwlan_logging.pkt_stats_lock);
  866. gwlan_logging.pcur_node = NULL;
  867. gwlan_logging.pkt_stats_pcur_node = NULL;
  868. return 0;
  869. }
  870. int wlan_logging_sock_deinit_svc(void)
  871. {
  872. gwlan_logging.pcur_node = NULL;
  873. gwlan_logging.pkt_stats_pcur_node = NULL;
  874. return 0;
  875. }
  876. /**
  877. * wlan_logging_set_per_pkt_stats() - This function triggers per packet logging
  878. *
  879. * This function is used to send signal to the logger thread for logging per
  880. * packet stats
  881. *
  882. * Return: None
  883. *
  884. */
  885. void wlan_logging_set_per_pkt_stats(void)
  886. {
  887. if (gwlan_logging.is_active == false)
  888. return;
  889. set_bit(HOST_LOG_PER_PKT_STATS, &gwlan_logging.eventFlag);
  890. wake_up_interruptible(&gwlan_logging.wait_queue);
  891. }
  892. /*
  893. * wlan_logging_set_fw_flush_complete() - FW log flush completion
  894. *
  895. * This function is used to send signal to the logger thread to indicate
  896. * that the flushing of FW logs is complete by the FW
  897. *
  898. * Return: None
  899. *
  900. */
  901. void wlan_logging_set_fw_flush_complete(void)
  902. {
  903. if (gwlan_logging.is_active == false
  904. #ifdef CONFIG_MCL
  905. || !cds_is_fatal_event_enabled()
  906. #endif
  907. )
  908. return;
  909. set_bit(HOST_LOG_FW_FLUSH_COMPLETE, &gwlan_logging.eventFlag);
  910. wake_up_interruptible(&gwlan_logging.wait_queue);
  911. }
  912. /**
  913. * wlan_flush_host_logs_for_fatal() - Flush host logs
  914. *
  915. * This function is used to send signal to the logger thread to
  916. * Flush the host logs
  917. *
  918. * Return: None
  919. */
  920. void wlan_flush_host_logs_for_fatal(void)
  921. {
  922. unsigned long flags;
  923. #ifdef CONFIG_MCL
  924. if (cds_is_log_report_in_progress()) {
  925. #endif
  926. pr_info("%s:flush all host logs Setting HOST_LOG_POST_MASK\n",
  927. __func__);
  928. spin_lock_irqsave(&gwlan_logging.spin_lock, flags);
  929. wlan_queue_logmsg_for_app();
  930. spin_unlock_irqrestore(&gwlan_logging.spin_lock, flags);
  931. set_bit(HOST_LOG_DRIVER_MSG, &gwlan_logging.eventFlag);
  932. wake_up_interruptible(&gwlan_logging.wait_queue);
  933. #ifdef CONFIG_MCL
  934. }
  935. #endif
  936. }
  937. /**
  938. * wlan_get_pkt_stats_free_node() - Get the free node for pkt stats
  939. *
  940. * This function is used to get the free node for pkt stats from
  941. * free list/filles list
  942. *
  943. * Return: int
  944. *
  945. */
  946. static int wlan_get_pkt_stats_free_node(void)
  947. {
  948. int ret = 0;
  949. list_add_tail(&gwlan_logging.pkt_stats_pcur_node->node,
  950. &gwlan_logging.pkt_stat_filled_list);
  951. if (!list_empty(&gwlan_logging.pkt_stat_free_list)) {
  952. /* Get buffer from free list */
  953. gwlan_logging.pkt_stats_pcur_node =
  954. (struct pkt_stats_msg *)(gwlan_logging.pkt_stat_free_list.next);
  955. list_del_init(gwlan_logging.pkt_stat_free_list.next);
  956. } else if (!list_empty(&gwlan_logging.pkt_stat_filled_list)) {
  957. /* Get buffer from filled list. This condition will drop the
  958. * packet from being indicated to app
  959. */
  960. gwlan_logging.pkt_stats_pcur_node =
  961. (struct pkt_stats_msg *)
  962. (gwlan_logging.pkt_stat_filled_list.next);
  963. ++gwlan_logging.pkt_stat_drop_cnt;
  964. /* print every 64th drop count */
  965. if (
  966. #ifdef CONFIG_MCL
  967. cds_is_multicast_logging() &&
  968. #endif
  969. (!(gwlan_logging.pkt_stat_drop_cnt % 0x40))) {
  970. pr_err("%s: drop_count = %u\n",
  971. __func__, gwlan_logging.pkt_stat_drop_cnt);
  972. }
  973. list_del_init(gwlan_logging.pkt_stat_filled_list.next);
  974. ret = 1;
  975. }
  976. /* Reset the skb values, essential if dequeued from filled list */
  977. skb_trim(gwlan_logging.pkt_stats_pcur_node->skb, 0);
  978. return ret;
  979. }
  980. /**
  981. * wlan_pkt_stats_to_logger_thread() - Add the pkt stats to SKB
  982. * @pl_hdr: Pointer to pl_hdr
  983. * @pkt_dump: Pointer to pkt_dump
  984. * @data: Pointer to data
  985. *
  986. * This function adds the pktstats hdr and data to current
  987. * skb node of free list.
  988. *
  989. * Return: None
  990. */
  991. void wlan_pkt_stats_to_logger_thread(void *pl_hdr, void *pkt_dump, void *data)
  992. {
  993. #ifdef CONFIG_MCL
  994. struct ath_pktlog_hdr *pktlog_hdr;
  995. struct packet_dump *pkt_stats_dump;
  996. int total_stats_len = 0;
  997. bool wake_up_thread = false;
  998. unsigned long flags;
  999. struct sk_buff *ptr;
  1000. int hdr_size;
  1001. pktlog_hdr = (struct ath_pktlog_hdr *)pl_hdr;
  1002. if (pktlog_hdr == NULL) {
  1003. pr_err("%s : Invalid pkt_stats_header\n", __func__);
  1004. return;
  1005. }
  1006. pkt_stats_dump = (struct packet_dump *)pkt_dump;
  1007. total_stats_len = sizeof(struct ath_pktlog_hdr) +
  1008. pktlog_hdr->size;
  1009. spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, flags);
  1010. if (!gwlan_logging.pkt_stats_pcur_node || (NULL == pkt_stats_dump)) {
  1011. spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, flags);
  1012. return;
  1013. }
  1014. /* Check if we can accommodate more log into current node/buffer */
  1015. hdr_size = sizeof(struct host_log_pktlog_info) +
  1016. sizeof(tAniNlHdr);
  1017. if ((total_stats_len + hdr_size) >=
  1018. skb_tailroom(gwlan_logging.pkt_stats_pcur_node->skb)) {
  1019. wake_up_thread = true;
  1020. wlan_get_pkt_stats_free_node();
  1021. }
  1022. ptr = gwlan_logging.pkt_stats_pcur_node->skb;
  1023. qdf_mem_copy(skb_put(ptr,
  1024. sizeof(struct ath_pktlog_hdr)),
  1025. pktlog_hdr,
  1026. sizeof(struct ath_pktlog_hdr));
  1027. if (pkt_stats_dump) {
  1028. qdf_mem_copy(skb_put(ptr,
  1029. sizeof(struct packet_dump)),
  1030. pkt_stats_dump,
  1031. sizeof(struct packet_dump));
  1032. pktlog_hdr->size -= sizeof(struct packet_dump);
  1033. }
  1034. if (data)
  1035. qdf_mem_copy(skb_put(ptr,
  1036. pktlog_hdr->size),
  1037. data, pktlog_hdr->size);
  1038. if (pkt_stats_dump->type == STOP_MONITOR) {
  1039. wake_up_thread = true;
  1040. wlan_get_pkt_stats_free_node();
  1041. }
  1042. spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, flags);
  1043. /* Wakeup logger thread */
  1044. if (true == wake_up_thread) {
  1045. set_bit(HOST_LOG_PER_PKT_STATS, &gwlan_logging.eventFlag);
  1046. wake_up_interruptible(&gwlan_logging.wait_queue);
  1047. }
  1048. #endif
  1049. }
  1050. #ifdef CONFIG_MCL
  1051. /**
  1052. * driver_hal_status_map() - maps driver to hal
  1053. * status
  1054. * @status: status to be mapped
  1055. *
  1056. * This function is used to map driver to hal status
  1057. *
  1058. * Return: None
  1059. *
  1060. */
  1061. static void driver_hal_status_map(uint8_t *status)
  1062. {
  1063. switch (*status) {
  1064. case tx_status_ok:
  1065. *status = TX_PKT_FATE_ACKED;
  1066. break;
  1067. case tx_status_discard:
  1068. *status = TX_PKT_FATE_DRV_DROP_OTHER;
  1069. break;
  1070. case tx_status_no_ack:
  1071. *status = TX_PKT_FATE_SENT;
  1072. break;
  1073. case tx_status_download_fail:
  1074. *status = TX_PKT_FATE_FW_QUEUED;
  1075. break;
  1076. default:
  1077. *status = TX_PKT_FATE_DRV_DROP_OTHER;
  1078. break;
  1079. }
  1080. }
  1081. /*
  1082. * send_packetdump() - send packet dump
  1083. * @netbuf: netbuf
  1084. * @status: status of tx packet
  1085. * @vdev_id: virtual device id
  1086. * @type: type of packet
  1087. *
  1088. * This function is used to send packet dump to HAL layer
  1089. * using wlan_pkt_stats_to_logger_thread
  1090. *
  1091. * Return: None
  1092. *
  1093. */
  1094. static void send_packetdump(qdf_nbuf_t netbuf, uint8_t status,
  1095. uint8_t vdev_id, uint8_t type)
  1096. {
  1097. struct ath_pktlog_hdr pktlog_hdr = {0};
  1098. struct packet_dump pd_hdr = {0};
  1099. hdd_context_t *hdd_ctx;
  1100. hdd_adapter_t *adapter;
  1101. v_CONTEXT_t vos_ctx;
  1102. vos_ctx = cds_get_global_context();
  1103. if (!vos_ctx)
  1104. return;
  1105. hdd_ctx = (hdd_context_t *)cds_get_context(QDF_MODULE_ID_HDD);
  1106. if (!hdd_ctx)
  1107. return;
  1108. adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
  1109. if (!adapter)
  1110. return;
  1111. /* Send packet dump only for STA interface */
  1112. if (adapter->device_mode != QDF_STA_MODE)
  1113. return;
  1114. #if defined(HELIUMPLUS)
  1115. pktlog_hdr.flags |= PKTLOG_HDR_SIZE_16;
  1116. #endif
  1117. pktlog_hdr.log_type = PKTLOG_TYPE_PKT_DUMP;
  1118. pktlog_hdr.size = sizeof(pd_hdr) + netbuf->len;
  1119. pd_hdr.status = status;
  1120. pd_hdr.type = type;
  1121. pd_hdr.driver_ts = qdf_get_monotonic_boottime();
  1122. if ((type == TX_MGMT_PKT) || (type == TX_DATA_PKT))
  1123. gtx_count++;
  1124. else if ((type == RX_MGMT_PKT) || (type == RX_DATA_PKT))
  1125. grx_count++;
  1126. wlan_pkt_stats_to_logger_thread(&pktlog_hdr, &pd_hdr, netbuf->data);
  1127. }
  1128. /*
  1129. * send_packetdump_monitor() - sends start/stop packet dump indication
  1130. * @type: type of packet
  1131. *
  1132. * This function is used to indicate HAL layer to start/stop monitoring
  1133. * of packets
  1134. *
  1135. * Return: None
  1136. *
  1137. */
  1138. static void send_packetdump_monitor(uint8_t type)
  1139. {
  1140. struct ath_pktlog_hdr pktlog_hdr = {0};
  1141. struct packet_dump pd_hdr = {0};
  1142. #if defined(HELIUMPLUS)
  1143. pktlog_hdr.flags |= PKTLOG_HDR_SIZE_16;
  1144. #endif
  1145. pktlog_hdr.log_type = PKTLOG_TYPE_PKT_DUMP;
  1146. pktlog_hdr.size = sizeof(pd_hdr);
  1147. pd_hdr.type = type;
  1148. LOGGING_TRACE(QDF_TRACE_LEVEL_INFO,
  1149. "fate Tx-Rx %s: type: %d", __func__, type);
  1150. wlan_pkt_stats_to_logger_thread(&pktlog_hdr, &pd_hdr, NULL);
  1151. }
  1152. /**
  1153. * wlan_deregister_txrx_packetdump() - tx/rx packet dump
  1154. * deregistration
  1155. *
  1156. * This function is used to deregister tx/rx packet dump callbacks
  1157. * with ol, pe and htt layers
  1158. *
  1159. * Return: None
  1160. *
  1161. */
  1162. void wlan_deregister_txrx_packetdump(void)
  1163. {
  1164. if (gtx_count || grx_count) {
  1165. ol_deregister_packetdump_callback();
  1166. wma_deregister_packetdump_callback();
  1167. send_packetdump_monitor(STOP_MONITOR);
  1168. csr_packetdump_timer_stop();
  1169. gtx_count = 0;
  1170. grx_count = 0;
  1171. } else
  1172. LOGGING_TRACE(QDF_TRACE_LEVEL_INFO,
  1173. "%s: deregistered packetdump already", __func__);
  1174. }
  1175. /*
  1176. * check_txrx_packetdump_count() - function to check
  1177. * tx/rx packet dump global counts
  1178. *
  1179. * This function is used to check global counts of tx/rx
  1180. * packet dump functionality.
  1181. *
  1182. * Return: 1 if either gtx_count or grx_count reached 32
  1183. * 0 otherwise
  1184. *
  1185. */
  1186. static bool check_txrx_packetdump_count(void)
  1187. {
  1188. if (gtx_count == MAX_NUM_PKT_LOG ||
  1189. grx_count == MAX_NUM_PKT_LOG) {
  1190. LOGGING_TRACE(QDF_TRACE_LEVEL_INFO,
  1191. "%s gtx_count: %d grx_count: %d deregister packetdump",
  1192. __func__, gtx_count, grx_count);
  1193. wlan_deregister_txrx_packetdump();
  1194. return 1;
  1195. }
  1196. return 0;
  1197. }
  1198. /*
  1199. * tx_packetdump_cb() - tx packet dump callback
  1200. * @netbuf: netbuf
  1201. * @status: status of tx packet
  1202. * @vdev_id: virtual device id
  1203. * @type: packet type
  1204. *
  1205. * This function is used to send tx packet dump to HAL layer
  1206. * and deregister packet dump callbacks
  1207. *
  1208. * Return: None
  1209. *
  1210. */
  1211. static void tx_packetdump_cb(qdf_nbuf_t netbuf, uint8_t status,
  1212. uint8_t vdev_id, uint8_t type)
  1213. {
  1214. bool temp;
  1215. temp = check_txrx_packetdump_count();
  1216. if (temp)
  1217. return;
  1218. driver_hal_status_map(&status);
  1219. send_packetdump(netbuf, status, vdev_id, type);
  1220. }
  1221. /*
  1222. * rx_packetdump_cb() - rx packet dump callback
  1223. * @netbuf: netbuf
  1224. * @status: status of rx packet
  1225. * @vdev_id: virtual device id
  1226. * @type: packet type
  1227. *
  1228. * This function is used to send rx packet dump to HAL layer
  1229. * and deregister packet dump callbacks
  1230. *
  1231. * Return: None
  1232. *
  1233. */
  1234. static void rx_packetdump_cb(qdf_nbuf_t netbuf, uint8_t status,
  1235. uint8_t vdev_id, uint8_t type)
  1236. {
  1237. bool temp;
  1238. temp = check_txrx_packetdump_count();
  1239. if (temp)
  1240. return;
  1241. send_packetdump(netbuf, status, vdev_id, type);
  1242. }
  1243. /**
  1244. * wlan_register_txrx_packetdump() - tx/rx packet dump
  1245. * registration
  1246. *
  1247. * This function is used to register tx/rx packet dump callbacks
  1248. * with ol, pe and htt layers
  1249. *
  1250. * Return: None
  1251. *
  1252. */
  1253. void wlan_register_txrx_packetdump(void)
  1254. {
  1255. ol_register_packetdump_callback(tx_packetdump_cb,
  1256. rx_packetdump_cb);
  1257. wma_register_packetdump_callback(tx_packetdump_cb,
  1258. rx_packetdump_cb);
  1259. send_packetdump_monitor(START_MONITOR);
  1260. gtx_count = 0;
  1261. grx_count = 0;
  1262. }
  1263. #endif
  1264. #endif /* WLAN_LOGGING_SOCK_SVC_ENABLE */