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.
17 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/pci.h>
30 #include <wl_export.h>
31 #include <wlc_event.h>
35 #include <wlc_mac80211.h>
41 /* Local prototypes */
42 static void wlc_timer_cb(void *arg);
44 /* Private data structures */
53 struct wl_timer *timer;
55 u8 event_inds_mask[broken_roundup(WLC_E_LAST, NBBY) / NBBY];
61 wlc_eventq_t *wlc_eventq_attach(struct wlc_pub *pub, struct wlc_info *wlc,
67 eq = kzalloc(sizeof(wlc_eventq_t), GFP_ATOMIC);
76 eq->timer = wl_init_timer(eq->wl, wlc_timer_cb, eq, "eventq");
78 WL_ERROR("wl%d: wlc_eventq_attach: timer failed\n",
87 int wlc_eventq_detach(wlc_eventq_t *eq)
89 /* Clean up pending events */
94 wl_del_timer(eq->wl, eq->timer);
97 wl_free_timer(eq->wl, eq->timer);
101 ASSERT(wlc_eventq_avail(eq) == false);
106 int wlc_eventq_down(wlc_eventq_t *eq)
109 if (eq->tpending && !eq->workpending) {
110 if (!wl_del_timer(eq->wl, eq->timer))
113 ASSERT(wlc_eventq_avail(eq) == true);
114 ASSERT(eq->workpending == false);
115 eq->workpending = true;
119 ASSERT(eq->workpending == true);
120 eq->workpending = false;
121 eq->tpending = false;
123 ASSERT(eq->workpending || wlc_eventq_avail(eq) == false);
128 wlc_event_t *wlc_event_alloc(wlc_eventq_t *eq)
132 e = kzalloc(sizeof(wlc_event_t), GFP_ATOMIC);
140 void wlc_event_free(wlc_eventq_t *eq, wlc_event_t *e)
142 ASSERT(e->data == NULL);
143 ASSERT(e->next == NULL);
147 void wlc_eventq_enq(wlc_eventq_t *eq, wlc_event_t *e)
149 ASSERT(e->next == NULL);
156 eq->head = eq->tail = e;
160 /* Use a zero-delay timer to trigger
161 * delayed processing of the event.
163 wl_add_timer(eq->wl, eq->timer, 0, 0);
167 wlc_event_t *wlc_eventq_deq(wlc_eventq_t *eq)
176 if (eq->head == NULL)
182 wlc_event_t *wlc_eventq_next(wlc_eventq_t *eq, wlc_event_t *e)
187 for (etmp = eq->head; etmp; etmp = etmp->next) {
191 ASSERT(etmp != NULL);
197 int wlc_eventq_cnt(wlc_eventq_t *eq)
202 for (etmp = eq->head; etmp; etmp = etmp->next)
208 bool wlc_eventq_avail(wlc_eventq_t *eq)
210 return (eq->head != NULL);
216 static void wlc_timer_cb(void *arg)
218 struct wlc_eventq *eq = (struct wlc_eventq *)arg;
220 ASSERT(eq->tpending == true);
221 ASSERT(wlc_eventq_avail(eq) == true);
222 ASSERT(eq->workpending == false);
223 eq->workpending = true;
228 ASSERT(wlc_eventq_avail(eq) == false);
229 ASSERT(eq->tpending == true);
230 eq->workpending = false;
231 eq->tpending = false;