1 /*-
2  * Based on BSD-licensed source modules in the Linux iwlwifi driver,
3  * which were used as the reference documentation for this implementation.
4  *
5  ******************************************************************************
6  *
7  * This file is provided under a dual BSD/GPLv2 license.  When using or
8  * redistributing this file, you may do so under either license.
9  *
10  * GPL LICENSE SUMMARY
11  *
12  * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved.
13  * Copyright(c) 2015 Intel Deutschland GmbH
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of version 2 of the GNU General Public License as
17  * published by the Free Software Foundation.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22  * General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
27  * USA
28  *
29  * The full GNU General Public License is included in this distribution
30  * in the file called COPYING.
31  *
32  * Contact Information:
33  *  Intel Linux Wireless <linuxwifi@intel.com>
34  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
35  *
36  * BSD LICENSE
37  *
38  * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
39  * All rights reserved.
40  *
41  * Redistribution and use in source and binary forms, with or without
42  * modification, are permitted provided that the following conditions
43  * are met:
44  *
45  *  * Redistributions of source code must retain the above copyright
46  *    notice, this list of conditions and the following disclaimer.
47  *  * Redistributions in binary form must reproduce the above copyright
48  *    notice, this list of conditions and the following disclaimer in
49  *    the documentation and/or other materials provided with the
50  *    distribution.
51  *  * Neither the name Intel Corporation nor the names of its
52  *    contributors may be used to endorse or promote products derived
53  *    from this software without specific prior written permission.
54  *
55  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
56  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
57  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
58  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
59  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
61  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
62  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
63  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
64  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
65  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66  *
67  *****************************************************************************/
68 
69 /* $FreeBSD$ */
70 
71 #ifndef __IF_IWN_NOTIF_WAIT_H__
72 #define __IF_IWN_NOTIF_WAIT_H__
73 
74 #include <sys/queue.h>
75 
76 #define IWM_MAX_NOTIF_CMDS	5
77 
78 struct iwm_rx_packet;
79 struct iwm_softc;
80 
81 /**
82  * struct iwm_notification_wait - notification wait entry
83  * @entry: link for global list
84  * @fn: Function called with the notification. If the function
85  *      returns true, the wait is over, if it returns false then
86  *      the waiter stays blocked. If no function is given, any
87  *      of the listed commands will unblock the waiter.
88  * @cmds: command IDs
89  * @n_cmds: number of command IDs
90  * @triggered: waiter should be woken up
91  * @aborted: wait was aborted
92  *
93  * This structure is not used directly, to wait for a
94  * notification declare it on the stack, and call
95  * iwm_init_notification_wait() with appropriate
96  * parameters. Then do whatever will cause the ucode
97  * to notify the driver, and to wait for that then
98  * call iwm_wait_notification().
99  *
100  * Each notification is one-shot. If at some point we
101  * need to support multi-shot notifications (which
102  * can't be allocated on the stack) we need to modify
103  * the code for them.
104  */
105 struct iwm_notification_wait {
106 	STAILQ_ENTRY(iwm_notification_wait) entry;
107 
108 	int (*fn)(struct iwm_softc *sc, struct iwm_rx_packet *pkt, void *data);
109 	void *fn_data;
110 
111 	uint16_t cmds[IWM_MAX_NOTIF_CMDS];
112 	uint8_t n_cmds;
113 	int triggered, aborted;
114 };
115 
116 /* caller functions */
117 extern	struct iwm_notif_wait_data *iwm_notification_wait_init(
118 		struct iwm_softc *sc);
119 extern	void iwm_notification_wait_free(struct iwm_notif_wait_data *notif_data);
120 extern	void iwm_notification_wait_notify(
121 		struct iwm_notif_wait_data *notif_data, uint16_t cmd,
122 		struct iwm_rx_packet *pkt);
123 extern	void iwm_abort_notification_waits(
124 		struct iwm_notif_wait_data *notif_data);
125 
126 /* user functions */
127 extern	void iwm_init_notification_wait(struct iwm_notif_wait_data *notif_data,
128 		struct iwm_notification_wait *wait_entry,
129 		const uint16_t *cmds, int n_cmds,
130 		int (*fn)(struct iwm_softc *sc,
131 			  struct iwm_rx_packet *pkt, void *data),
132 		void *fn_data);
133 extern	int iwm_wait_notification(struct iwm_notif_wait_data *notif_data,
134 		struct iwm_notification_wait *wait_entry, int timeout);
135 extern	void iwm_remove_notification(struct iwm_notif_wait_data *notif_data,
136 		struct iwm_notification_wait *wait_entry);
137 
138 #endif  /* __IF_IWN_NOTIF_WAIT_H__ */
139