wlan_logging_sock_svc.c 37 KB

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