xref: /wlan-driver/qcacld-3.0/core/dp/txrx/ol_txrx_event.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2012-2020 The Linux Foundation. All rights reserved.
3*5113495bSYour Name  *
4*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for
5*5113495bSYour Name  * any purpose with or without fee is hereby granted, provided that the
6*5113495bSYour Name  * above copyright notice and this permission notice appear in all
7*5113495bSYour Name  * copies.
8*5113495bSYour Name  *
9*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10*5113495bSYour Name  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11*5113495bSYour Name  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12*5113495bSYour Name  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13*5113495bSYour Name  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14*5113495bSYour Name  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15*5113495bSYour Name  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16*5113495bSYour Name  * PERFORMANCE OF THIS SOFTWARE.
17*5113495bSYour Name  */
18*5113495bSYour Name 
19*5113495bSYour Name #include "ol_txrx_types.h"
20*5113495bSYour Name #include "ol_txrx.h"
21*5113495bSYour Name 
wdi_event_next_sub(wdi_event_subscribe * wdi_sub)22*5113495bSYour Name static inline wdi_event_subscribe *wdi_event_next_sub(wdi_event_subscribe *
23*5113495bSYour Name 						      wdi_sub)
24*5113495bSYour Name {
25*5113495bSYour Name 	if (!wdi_sub) {
26*5113495bSYour Name 		QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
27*5113495bSYour Name 			  "Invalid subscriber in %s\n", __func__);
28*5113495bSYour Name 		return NULL;
29*5113495bSYour Name 	}
30*5113495bSYour Name 	return wdi_sub->priv.next;
31*5113495bSYour Name }
32*5113495bSYour Name 
33*5113495bSYour Name static inline void
wdi_event_del_subs(wdi_event_subscribe * wdi_sub,int event_index)34*5113495bSYour Name wdi_event_del_subs(wdi_event_subscribe *wdi_sub, int event_index)
35*5113495bSYour Name {
36*5113495bSYour Name 	wdi_event_notify deallocate_sub;
37*5113495bSYour Name 
38*5113495bSYour Name 	while (wdi_sub) {
39*5113495bSYour Name 		wdi_event_subscribe *next = wdi_event_next_sub(wdi_sub);
40*5113495bSYour Name 		/*
41*5113495bSYour Name 		 *  Context is NULL for static allocation of subs
42*5113495bSYour Name 		 *  In dynamic allocation case notify the user
43*5113495bSYour Name 		 */
44*5113495bSYour Name 		if (wdi_sub->context) {
45*5113495bSYour Name 			deallocate_sub = wdi_sub->context;
46*5113495bSYour Name 			deallocate_sub(WDI_EVENT_SUB_DEALLOCATE,
47*5113495bSYour Name 				       WDI_EVENT_BASE + event_index);
48*5113495bSYour Name 		}
49*5113495bSYour Name 		wdi_sub = next;
50*5113495bSYour Name 	}
51*5113495bSYour Name 	/* qdf_mem_free(wdi_sub); */
52*5113495bSYour Name }
53*5113495bSYour Name 
54*5113495bSYour Name static inline void
wdi_event_iter_sub(struct ol_txrx_pdev_t * pdev,uint32_t event_index,wdi_event_subscribe * wdi_sub,void * data)55*5113495bSYour Name wdi_event_iter_sub(struct ol_txrx_pdev_t *pdev,
56*5113495bSYour Name 		   uint32_t event_index,
57*5113495bSYour Name 		   wdi_event_subscribe *wdi_sub, void *data)
58*5113495bSYour Name {
59*5113495bSYour Name 	enum WDI_EVENT event = event_index + WDI_EVENT_BASE;
60*5113495bSYour Name 
61*5113495bSYour Name 	if (wdi_sub) {
62*5113495bSYour Name 		do {
63*5113495bSYour Name 			wdi_sub->callback(pdev, event, data, 0, 0);
64*5113495bSYour Name 		} while ((wdi_sub = wdi_event_next_sub(wdi_sub)));
65*5113495bSYour Name 	}
66*5113495bSYour Name }
67*5113495bSYour Name 
68*5113495bSYour Name void
wdi_event_handler(enum WDI_EVENT event,uint8_t pdev_id,void * data)69*5113495bSYour Name wdi_event_handler(enum WDI_EVENT event,
70*5113495bSYour Name 		  uint8_t pdev_id, void *data)
71*5113495bSYour Name {
72*5113495bSYour Name 	uint32_t event_index;
73*5113495bSYour Name 	wdi_event_subscribe *wdi_sub;
74*5113495bSYour Name 	struct ol_txrx_soc_t *soc = cds_get_context(QDF_MODULE_ID_SOC);
75*5113495bSYour Name 	ol_txrx_pdev_handle txrx_pdev;
76*5113495bSYour Name 
77*5113495bSYour Name 	/*
78*5113495bSYour Name 	 * Input validation
79*5113495bSYour Name 	 */
80*5113495bSYour Name 	if (!event) {
81*5113495bSYour Name 		ol_txrx_err("Invalid WDI event");
82*5113495bSYour Name 		return;
83*5113495bSYour Name 	}
84*5113495bSYour Name 	if (!soc)
85*5113495bSYour Name 		return;
86*5113495bSYour Name 
87*5113495bSYour Name 	txrx_pdev = ol_txrx_get_pdev_from_pdev_id(soc, pdev_id);
88*5113495bSYour Name 	if (!txrx_pdev) {
89*5113495bSYour Name 		ol_txrx_err("Invalid pdev");
90*5113495bSYour Name 		return;
91*5113495bSYour Name 	}
92*5113495bSYour Name 	/*
93*5113495bSYour Name 	 *  There can be NULL data, so no validation for the data
94*5113495bSYour Name 	 *  Subscribers must do the sanity based on the requirements
95*5113495bSYour Name 	 */
96*5113495bSYour Name 	event_index = event - WDI_EVENT_BASE;
97*5113495bSYour Name 
98*5113495bSYour Name 	wdi_sub = txrx_pdev->wdi_event_list[event_index];
99*5113495bSYour Name 
100*5113495bSYour Name 	/* Find the subscriber */
101*5113495bSYour Name 	wdi_event_iter_sub(txrx_pdev, event_index, wdi_sub, data);
102*5113495bSYour Name }
103*5113495bSYour Name 
104*5113495bSYour Name int
wdi_event_sub(struct cdp_soc_t * soc_hdl,uint8_t pdev_id,wdi_event_subscribe * pevent_cb_sub,uint32_t event)105*5113495bSYour Name wdi_event_sub(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
106*5113495bSYour Name 	      wdi_event_subscribe *pevent_cb_sub, uint32_t event)
107*5113495bSYour Name {
108*5113495bSYour Name 	uint32_t event_index;
109*5113495bSYour Name 	wdi_event_subscribe *wdi_sub;
110*5113495bSYour Name 	struct ol_txrx_soc_t *soc = cdp_soc_t_to_ol_txrx_soc_t(soc_hdl);
111*5113495bSYour Name 	ol_txrx_pdev_handle txrx_pdev = ol_txrx_get_pdev_from_pdev_id(soc,
112*5113495bSYour Name 								      pdev_id);
113*5113495bSYour Name 	wdi_event_subscribe *event_cb_sub = pevent_cb_sub;
114*5113495bSYour Name 
115*5113495bSYour Name 	/* Input validation */
116*5113495bSYour Name 	if (!txrx_pdev || !txrx_pdev->wdi_event_list) {
117*5113495bSYour Name 		QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
118*5113495bSYour Name 			  "Invalid txrx_pdev or wdi_event_list in %s",
119*5113495bSYour Name 			  __func__);
120*5113495bSYour Name 		return -EINVAL;
121*5113495bSYour Name 	}
122*5113495bSYour Name 	if (!event_cb_sub) {
123*5113495bSYour Name 		QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
124*5113495bSYour Name 			  "Invalid callback in %s", __func__);
125*5113495bSYour Name 		return -EINVAL;
126*5113495bSYour Name 	}
127*5113495bSYour Name 	if ((!event) || (event >= WDI_EVENT_LAST) || (event < WDI_EVENT_BASE)) {
128*5113495bSYour Name 		QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
129*5113495bSYour Name 			  "Invalid event in %s", __func__);
130*5113495bSYour Name 		return -EINVAL;
131*5113495bSYour Name 	}
132*5113495bSYour Name 	/* Input validation */
133*5113495bSYour Name 	event_index = event - WDI_EVENT_BASE;
134*5113495bSYour Name 
135*5113495bSYour Name 	wdi_sub = txrx_pdev->wdi_event_list[event_index];
136*5113495bSYour Name 	/*
137*5113495bSYour Name 	 *  Check if it is the first subscriber of the event
138*5113495bSYour Name 	 */
139*5113495bSYour Name 	if (!wdi_sub) {
140*5113495bSYour Name 		wdi_sub = event_cb_sub;
141*5113495bSYour Name 		wdi_sub->priv.next = NULL;
142*5113495bSYour Name 		wdi_sub->priv.prev = NULL;
143*5113495bSYour Name 		txrx_pdev->wdi_event_list[event_index] = wdi_sub;
144*5113495bSYour Name 		return 0;
145*5113495bSYour Name 	}
146*5113495bSYour Name 	event_cb_sub->priv.next = wdi_sub;
147*5113495bSYour Name 	event_cb_sub->priv.prev = NULL;
148*5113495bSYour Name 	wdi_sub->priv.prev = event_cb_sub;
149*5113495bSYour Name 	txrx_pdev->wdi_event_list[event_index] = event_cb_sub;
150*5113495bSYour Name 
151*5113495bSYour Name 	return 0;
152*5113495bSYour Name }
153*5113495bSYour Name 
154*5113495bSYour Name int
wdi_event_unsub(struct cdp_soc_t * soc_hdl,uint8_t pdev_id,wdi_event_subscribe * pevent_cb_sub,uint32_t event)155*5113495bSYour Name wdi_event_unsub(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
156*5113495bSYour Name 		wdi_event_subscribe *pevent_cb_sub, uint32_t event)
157*5113495bSYour Name {
158*5113495bSYour Name 	uint32_t event_index = event - WDI_EVENT_BASE;
159*5113495bSYour Name 	struct ol_txrx_soc_t *soc = cdp_soc_t_to_ol_txrx_soc_t(soc_hdl);
160*5113495bSYour Name 	ol_txrx_pdev_handle txrx_pdev = ol_txrx_get_pdev_from_pdev_id(soc,
161*5113495bSYour Name 								      pdev_id);
162*5113495bSYour Name 
163*5113495bSYour Name 	wdi_event_subscribe *event_cb_sub = pevent_cb_sub;
164*5113495bSYour Name 
165*5113495bSYour Name 	/* Input validation */
166*5113495bSYour Name 	if (!txrx_pdev) {
167*5113495bSYour Name 		QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
168*5113495bSYour Name 			  "Invalid txrx_pdev in %s", __func__);
169*5113495bSYour Name 		return -EINVAL;
170*5113495bSYour Name 	}
171*5113495bSYour Name 
172*5113495bSYour Name 	/* Input validation */
173*5113495bSYour Name 	if (!event_cb_sub) {
174*5113495bSYour Name 		QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
175*5113495bSYour Name 			  "Invalid callback in %s", __func__);
176*5113495bSYour Name 		return -EINVAL;
177*5113495bSYour Name 	}
178*5113495bSYour Name 	if (!event_cb_sub->priv.prev) {
179*5113495bSYour Name 		txrx_pdev->wdi_event_list[event_index] =
180*5113495bSYour Name 			event_cb_sub->priv.next;
181*5113495bSYour Name 	} else {
182*5113495bSYour Name 		event_cb_sub->priv.prev->priv.next = event_cb_sub->priv.next;
183*5113495bSYour Name 	}
184*5113495bSYour Name 	if (event_cb_sub->priv.next)
185*5113495bSYour Name 		event_cb_sub->priv.next->priv.prev = event_cb_sub->priv.prev;
186*5113495bSYour Name 
187*5113495bSYour Name 	/* qdf_mem_free(event_cb_sub); */
188*5113495bSYour Name 
189*5113495bSYour Name 	return 0;
190*5113495bSYour Name }
191*5113495bSYour Name 
wdi_event_attach(struct ol_txrx_pdev_t * txrx_pdev)192*5113495bSYour Name A_STATUS wdi_event_attach(struct ol_txrx_pdev_t *txrx_pdev)
193*5113495bSYour Name {
194*5113495bSYour Name 	/* Input validation */
195*5113495bSYour Name 	if (!txrx_pdev) {
196*5113495bSYour Name 		QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
197*5113495bSYour Name 			  "Invalid device in %s\nWDI event attach failed",
198*5113495bSYour Name 			  __func__);
199*5113495bSYour Name 		return A_ERROR;
200*5113495bSYour Name 	}
201*5113495bSYour Name 	/* Separate subscriber list for each event */
202*5113495bSYour Name 	txrx_pdev->wdi_event_list = (wdi_event_subscribe **)
203*5113495bSYour Name 				    qdf_mem_malloc(
204*5113495bSYour Name 					    sizeof(wdi_event_subscribe *) *
205*5113495bSYour Name 					    WDI_NUM_EVENTS);
206*5113495bSYour Name 	if (!txrx_pdev->wdi_event_list)
207*5113495bSYour Name 		return A_NO_MEMORY;
208*5113495bSYour Name 
209*5113495bSYour Name 	return A_OK;
210*5113495bSYour Name }
211*5113495bSYour Name 
wdi_event_detach(struct ol_txrx_pdev_t * txrx_pdev)212*5113495bSYour Name A_STATUS wdi_event_detach(struct ol_txrx_pdev_t *txrx_pdev)
213*5113495bSYour Name {
214*5113495bSYour Name 	int i;
215*5113495bSYour Name 	wdi_event_subscribe *wdi_sub;
216*5113495bSYour Name 
217*5113495bSYour Name 	if (!txrx_pdev) {
218*5113495bSYour Name 		QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
219*5113495bSYour Name 			  "Invalid device in %s\nWDI detach failed",
220*5113495bSYour Name 			  __func__);
221*5113495bSYour Name 		return A_ERROR;
222*5113495bSYour Name 	}
223*5113495bSYour Name 	if (!txrx_pdev->wdi_event_list) {
224*5113495bSYour Name 		QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
225*5113495bSYour Name 			  "%s: wdi_event_list is NULL", __func__);
226*5113495bSYour Name 		return A_ERROR;
227*5113495bSYour Name 	}
228*5113495bSYour Name 
229*5113495bSYour Name 	for (i = 0; i < WDI_NUM_EVENTS; i++) {
230*5113495bSYour Name 		wdi_sub = txrx_pdev->wdi_event_list[i];
231*5113495bSYour Name 		if (wdi_sub) {
232*5113495bSYour Name 			/* Delete all the subscribers */
233*5113495bSYour Name 			wdi_event_del_subs(wdi_sub, i);
234*5113495bSYour Name 		}
235*5113495bSYour Name 	}
236*5113495bSYour Name 	/* txrx_pdev->wdi_event_list would be non-null */
237*5113495bSYour Name 	qdf_mem_free(txrx_pdev->wdi_event_list);
238*5113495bSYour Name 	txrx_pdev->wdi_event_list = NULL;
239*5113495bSYour Name 	return A_OK;
240*5113495bSYour Name }
241