xref: /freebsd/sys/dev/iwm/if_iwm_notif_wait.h (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
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 
70 #ifndef __IF_IWN_NOTIF_WAIT_H__
71 #define __IF_IWN_NOTIF_WAIT_H__
72 
73 #include <sys/queue.h>
74 
75 #define IWM_MAX_NOTIF_CMDS	5
76 
77 struct iwm_rx_packet;
78 struct iwm_softc;
79 
80 /**
81  * struct iwm_notification_wait - notification wait entry
82  * @entry: link for global list
83  * @fn: Function called with the notification. If the function
84  *      returns true, the wait is over, if it returns false then
85  *      the waiter stays blocked. If no function is given, any
86  *      of the listed commands will unblock the waiter.
87  * @cmds: command IDs
88  * @n_cmds: number of command IDs
89  * @triggered: waiter should be woken up
90  * @aborted: wait was aborted
91  *
92  * This structure is not used directly, to wait for a
93  * notification declare it on the stack, and call
94  * iwm_init_notification_wait() with appropriate
95  * parameters. Then do whatever will cause the ucode
96  * to notify the driver, and to wait for that then
97  * call iwm_wait_notification().
98  *
99  * Each notification is one-shot. If at some point we
100  * need to support multi-shot notifications (which
101  * can't be allocated on the stack) we need to modify
102  * the code for them.
103  */
104 struct iwm_notification_wait {
105 	STAILQ_ENTRY(iwm_notification_wait) entry;
106 
107 	int (*fn)(struct iwm_softc *sc, struct iwm_rx_packet *pkt, void *data);
108 	void *fn_data;
109 
110 	uint16_t cmds[IWM_MAX_NOTIF_CMDS];
111 	uint8_t n_cmds;
112 	int triggered, aborted;
113 };
114 
115 /* caller functions */
116 extern	struct iwm_notif_wait_data *iwm_notification_wait_init(
117 		struct iwm_softc *sc);
118 extern	void iwm_notification_wait_free(struct iwm_notif_wait_data *notif_data);
119 extern	void iwm_notification_wait_notify(
120 		struct iwm_notif_wait_data *notif_data, uint16_t cmd,
121 		struct iwm_rx_packet *pkt);
122 extern	void iwm_abort_notification_waits(
123 		struct iwm_notif_wait_data *notif_data);
124 
125 /* user functions */
126 extern	void iwm_init_notification_wait(struct iwm_notif_wait_data *notif_data,
127 		struct iwm_notification_wait *wait_entry,
128 		const uint16_t *cmds, int n_cmds,
129 		int (*fn)(struct iwm_softc *sc,
130 			  struct iwm_rx_packet *pkt, void *data),
131 		void *fn_data);
132 extern	int iwm_wait_notification(struct iwm_notif_wait_data *notif_data,
133 		struct iwm_notification_wait *wait_entry, int timeout);
134 extern	void iwm_remove_notification(struct iwm_notif_wait_data *notif_data,
135 		struct iwm_notification_wait *wait_entry);
136 
137 #endif  /* __IF_IWN_NOTIF_WAIT_H__ */
138