2 * Copyright (c) 2010 Broadcom Corporation
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.
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 ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <linux/kernel.h>
26 #include <wl_export.h>
27 #include <wlc_event.h>
31 #include <wlc_mac80211.h>
36 /* Local prototypes */
37 static void wlc_timer_cb(void *arg);
39 /* Private data structures */
48 struct wl_timer *timer;
50 uint8 event_inds_mask[ROUNDUP(WLC_E_LAST, NBBY) / NBBY];
56 wlc_eventq_t *BCMATTACHFN(wlc_eventq_attach) (wlc_pub_t *pub,
57 struct wlc_info *wlc, void *wl,
61 eq = (wlc_eventq_t *) MALLOC(pub->osh, sizeof(wlc_eventq_t));
65 bzero(eq, sizeof(wlc_eventq_t));
72 eq->timer = wl_init_timer(eq->wl, wlc_timer_cb, eq, "eventq");
74 WL_ERROR(("wl%d: wlc_eventq_attach: timer failed\n",
76 MFREE(eq->pub->osh, eq, sizeof(wlc_eventq_t));
83 int BCMATTACHFN(wlc_eventq_detach) (wlc_eventq_t *eq)
85 /* Clean up pending events */
90 wl_del_timer(eq->wl, eq->timer);
93 wl_free_timer(eq->wl, eq->timer);
97 ASSERT(wlc_eventq_avail(eq) == FALSE);
98 MFREE(eq->pub->osh, eq, sizeof(wlc_eventq_t));
102 int BCMUNINITFN(wlc_eventq_down) (wlc_eventq_t *eq)
105 if (eq->tpending && !eq->workpending) {
106 if (!wl_del_timer(eq->wl, eq->timer))
109 ASSERT(wlc_eventq_avail(eq) == TRUE);
110 ASSERT(eq->workpending == FALSE);
111 eq->workpending = TRUE;
115 ASSERT(eq->workpending == TRUE);
116 eq->workpending = FALSE;
117 eq->tpending = FALSE;
119 ASSERT(eq->workpending || wlc_eventq_avail(eq) == FALSE);
124 wlc_event_t *wlc_event_alloc(wlc_eventq_t *eq)
128 e = MALLOC(eq->pub->osh, sizeof(wlc_event_t));
133 bzero(e, sizeof(wlc_event_t));
137 void wlc_event_free(wlc_eventq_t *eq, wlc_event_t *e)
139 ASSERT(e->data == NULL);
140 ASSERT(e->next == NULL);
141 MFREE(eq->pub->osh, e, sizeof(wlc_event_t));
144 void wlc_eventq_enq(wlc_eventq_t *eq, wlc_event_t *e)
146 ASSERT(e->next == NULL);
153 eq->head = eq->tail = e;
157 /* Use a zero-delay timer to trigger
158 * delayed processing of the event.
160 wl_add_timer(eq->wl, eq->timer, 0, 0);
164 wlc_event_t *wlc_eventq_deq(wlc_eventq_t *eq)
173 if (eq->head == NULL)
179 wlc_event_t *wlc_eventq_next(wlc_eventq_t *eq, wlc_event_t *e)
184 for (etmp = eq->head; etmp; etmp = etmp->next) {
188 ASSERT(etmp != NULL);
194 int wlc_eventq_cnt(wlc_eventq_t *eq)
199 for (etmp = eq->head; etmp; etmp = etmp->next)
205 bool wlc_eventq_avail(wlc_eventq_t *eq)
207 return (eq->head != NULL);
213 static void wlc_timer_cb(void *arg)
215 struct wlc_eventq *eq = (struct wlc_eventq *)arg;
217 ASSERT(eq->tpending == TRUE);
218 ASSERT(wlc_eventq_avail(eq) == TRUE);
219 ASSERT(eq->workpending == FALSE);
220 eq->workpending = TRUE;
225 ASSERT(wlc_eventq_avail(eq) == FALSE);
226 ASSERT(eq->tpending == TRUE);
227 eq->workpending = FALSE;
228 eq->tpending = FALSE;