1 /**
2  * Copyright (c) 2013-2020, The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 /* WIFI3 - Refers to platforms - 6290/6390/6490 */
18 #include "pktlog_wifi3.h"
19 
20 #ifndef REMOVE_PKT_LOG
21 A_STATUS
process_offload_pktlog_wifi3(struct cdp_pdev * pdev,void * data)22 process_offload_pktlog_wifi3(struct cdp_pdev *pdev, void *data)
23 {
24 	struct pktlog_dev_t *pl_dev = get_pktlog_handle();
25 	struct ath_pktlog_info *pl_info;
26 	struct ath_pktlog_hdr pl_hdr;
27 	uint32_t *pl_tgt_hdr;
28 	void *txdesc_hdr_ctl = NULL;
29 	size_t log_size = 0;
30 
31 	if (!pl_dev) {
32 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
33 			  "Invalid context in %s\n", __func__);
34 		return A_ERROR;
35 	}
36 
37 	if (!data) {
38 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
39 			  "Invalid data in %s\n", __func__);
40 		return A_ERROR;
41 	}
42 
43 	pl_tgt_hdr = (uint32_t *)data;
44 
45 	pl_hdr.flags = (*(pl_tgt_hdr + ATH_PKTLOG_HDR_FLAGS_OFFSET) &
46 			ATH_PKTLOG_HDR_FLAGS_MASK) >>
47 				ATH_PKTLOG_HDR_FLAGS_SHIFT;
48 	pl_hdr.missed_cnt =  (*(pl_tgt_hdr + ATH_PKTLOG_HDR_MISSED_CNT_OFFSET) &
49 			ATH_PKTLOG_HDR_MISSED_CNT_MASK) >>
50 				ATH_PKTLOG_HDR_MISSED_CNT_SHIFT;
51 	pl_hdr.log_type =  (*(pl_tgt_hdr + ATH_PKTLOG_HDR_LOG_TYPE_OFFSET) &
52 			ATH_PKTLOG_HDR_LOG_TYPE_MASK) >>
53 				ATH_PKTLOG_HDR_LOG_TYPE_SHIFT;
54 	pl_hdr.size =  (*(pl_tgt_hdr + ATH_PKTLOG_HDR_SIZE_OFFSET) &
55 			ATH_PKTLOG_HDR_SIZE_MASK) >> ATH_PKTLOG_HDR_SIZE_SHIFT;
56 	pl_hdr.timestamp = *(pl_tgt_hdr + ATH_PKTLOG_HDR_TIMESTAMP_OFFSET);
57 
58 	pktlog_hdr_set_specific_data(&pl_hdr,
59 				     *(pl_tgt_hdr +
60 				     ATH_PKTLOG_HDR_TYPE_SPECIFIC_DATA_OFFSET));
61 	if (pl_hdr.size > MAX_PKTLOG_RECV_BUF_SIZE) {
62 		pl_dev->invalid_packets++;
63 		return A_ERROR;
64 	}
65 
66 	/*
67 	 *  Must include to process different types
68 	 *  TX_CTL, TX_STATUS, TX_MSDU_ID, TX_FRM_HDR
69 	 */
70 	pl_info = pl_dev->pl_info;
71 	log_size = pl_hdr.size;
72 	txdesc_hdr_ctl =
73 		(void *)pktlog_getbuf(pl_dev, pl_info, log_size, &pl_hdr);
74 	if (!txdesc_hdr_ctl) {
75 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
76 			  "Failed to allocate pktlog descriptor");
77 		return A_NO_MEMORY;
78 	}
79 	qdf_assert(txdesc_hdr_ctl);
80 	qdf_assert(pl_hdr->size < PKTLOG_MAX_TX_WORDS * sizeof(u_int32_t));
81 	qdf_mem_copy(txdesc_hdr_ctl,
82 		     ((void *)data + sizeof(struct ath_pktlog_hdr)),
83 		     pl_hdr.size);
84 	cds_pkt_stats_to_logger_thread(&pl_hdr, NULL, txdesc_hdr_ctl);
85 
86 	return A_OK;
87 }
88 
process_rx_desc_remote_wifi3(void * pdev,void * data)89 int process_rx_desc_remote_wifi3(void *pdev, void *data)
90 {
91 	struct pktlog_dev_t *pl_dev = get_pktlog_handle();
92 	struct ath_pktlog_hdr pl_hdr;
93 	struct ath_pktlog_rx_info rxstat_log;
94 	size_t log_size;
95 	struct ath_pktlog_info *pl_info;
96 	qdf_nbuf_t log_nbuf = (qdf_nbuf_t)data;
97 
98 	if (!pl_dev) {
99 		qdf_err("Pktlog handle is NULL");
100 		return -EINVAL;
101 	}
102 
103 	pl_info = pl_dev->pl_info;
104 	qdf_mem_zero(&pl_hdr, sizeof(pl_hdr));
105 	pl_hdr.flags = (1 << PKTLOG_FLG_FRM_TYPE_REMOTE_S);
106 	pl_hdr.missed_cnt = 0;
107 	pl_hdr.log_type = PKTLOG_TYPE_RX_STATBUF;
108 	pl_hdr.size = qdf_nbuf_len(log_nbuf);
109 	pl_hdr.timestamp = 0;
110 	log_size = pl_hdr.size;
111 	rxstat_log.rx_desc = (void *)pktlog_getbuf(pl_dev, pl_info,
112 						  log_size, &pl_hdr);
113 
114 	if (!rxstat_log.rx_desc) {
115 		QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_DEBUG,
116 			  "%s: Rx descriptor is NULL", __func__);
117 		return -EINVAL;
118 	}
119 
120 	qdf_mem_copy(rxstat_log.rx_desc, qdf_nbuf_data(log_nbuf), pl_hdr.size);
121 	cds_pkt_stats_to_logger_thread(&pl_hdr, NULL,
122 				       rxstat_log.rx_desc);
123 	return 0;
124 }
125 
126 int
process_pktlog_lite_wifi3(void * context,void * log_data,uint16_t log_type)127 process_pktlog_lite_wifi3(void *context, void *log_data,
128 			  uint16_t log_type)
129 {
130 	struct pktlog_dev_t *pl_dev = get_pktlog_handle();
131 	struct ath_pktlog_info *pl_info;
132 	struct ath_pktlog_hdr pl_hdr;
133 	struct ath_pktlog_rx_info rxstat_log;
134 	size_t log_size;
135 	qdf_nbuf_t log_nbuf = (qdf_nbuf_t)log_data;
136 
137 	if (!pl_dev) {
138 		qdf_err("Pktlog handle is NULL");
139 		return -EINVAL;
140 	}
141 
142 	pl_info = pl_dev->pl_info;
143 	qdf_mem_zero(&pl_hdr, sizeof(pl_hdr));
144 	pl_hdr.flags = (1 << PKTLOG_FLG_FRM_TYPE_REMOTE_S);
145 	pl_hdr.missed_cnt = 0;
146 	pl_hdr.log_type = log_type;
147 	pl_hdr.size = qdf_nbuf_len(log_nbuf);
148 	pl_hdr.timestamp = 0;
149 	log_size = pl_hdr.size;
150 	rxstat_log.rx_desc = (void *)pktlog_getbuf(pl_dev, pl_info,
151 						   log_size, &pl_hdr);
152 	if (!rxstat_log.rx_desc) {
153 		QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_DEBUG,
154 			  "%s: Rx descriptor is NULL", __func__);
155 		return -EINVAL;
156 	}
157 
158 	qdf_mem_copy(rxstat_log.rx_desc, qdf_nbuf_data(log_nbuf), pl_hdr.size);
159 
160 	cds_pkt_stats_to_logger_thread(&pl_hdr, NULL, rxstat_log.rx_desc);
161 	return 0;
162 }
163 #endif /* REMOVE_PKT_LOG */
164