Linux Audio

Check our new training course

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