xref: /openbmc/linux/drivers/net/wireless/intel/iwlwifi/fw/notif-wait.h (revision cdd38c5f1ce4398ec58fec95904b75824daab7b5)
1*8e99ea8dSJohannes Berg /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2*8e99ea8dSJohannes Berg /*
3*8e99ea8dSJohannes Berg  * Copyright (C) 2005-2014 Intel Corporation
4*8e99ea8dSJohannes Berg  * Copyright (C) 2015-2017 Intel Deutschland GmbH
5*8e99ea8dSJohannes Berg  */
69fca9d5cSJohannes Berg #ifndef __iwl_notif_wait_h__
79fca9d5cSJohannes Berg #define __iwl_notif_wait_h__
89fca9d5cSJohannes Berg 
99fca9d5cSJohannes Berg #include <linux/wait.h>
109fca9d5cSJohannes Berg 
119fca9d5cSJohannes Berg #include "iwl-trans.h"
129fca9d5cSJohannes Berg 
139fca9d5cSJohannes Berg struct iwl_notif_wait_data {
149fca9d5cSJohannes Berg 	struct list_head notif_waits;
159fca9d5cSJohannes Berg 	spinlock_t notif_wait_lock;
169fca9d5cSJohannes Berg 	wait_queue_head_t notif_waitq;
179fca9d5cSJohannes Berg };
189fca9d5cSJohannes Berg 
199fca9d5cSJohannes Berg #define MAX_NOTIF_CMDS	5
209fca9d5cSJohannes Berg 
219fca9d5cSJohannes Berg /**
229fca9d5cSJohannes Berg  * struct iwl_notification_wait - notification wait entry
239fca9d5cSJohannes Berg  * @list: list head for global list
249fca9d5cSJohannes Berg  * @fn: Function called with the notification. If the function
259fca9d5cSJohannes Berg  *	returns true, the wait is over, if it returns false then
269fca9d5cSJohannes Berg  *	the waiter stays blocked. If no function is given, any
279fca9d5cSJohannes Berg  *	of the listed commands will unblock the waiter.
289fca9d5cSJohannes Berg  * @cmds: command IDs
299fca9d5cSJohannes Berg  * @n_cmds: number of command IDs
309fca9d5cSJohannes Berg  * @triggered: waiter should be woken up
319fca9d5cSJohannes Berg  * @aborted: wait was aborted
329fca9d5cSJohannes Berg  *
339fca9d5cSJohannes Berg  * This structure is not used directly, to wait for a
349fca9d5cSJohannes Berg  * notification declare it on the stack, and call
359fca9d5cSJohannes Berg  * iwl_init_notification_wait() with appropriate
369fca9d5cSJohannes Berg  * parameters. Then do whatever will cause the ucode
379fca9d5cSJohannes Berg  * to notify the driver, and to wait for that then
389fca9d5cSJohannes Berg  * call iwl_wait_notification().
399fca9d5cSJohannes Berg  *
409fca9d5cSJohannes Berg  * Each notification is one-shot. If at some point we
419fca9d5cSJohannes Berg  * need to support multi-shot notifications (which
429fca9d5cSJohannes Berg  * can't be allocated on the stack) we need to modify
439fca9d5cSJohannes Berg  * the code for them.
449fca9d5cSJohannes Berg  */
459fca9d5cSJohannes Berg struct iwl_notification_wait {
469fca9d5cSJohannes Berg 	struct list_head list;
479fca9d5cSJohannes Berg 
489fca9d5cSJohannes Berg 	bool (*fn)(struct iwl_notif_wait_data *notif_data,
499fca9d5cSJohannes Berg 		   struct iwl_rx_packet *pkt, void *data);
509fca9d5cSJohannes Berg 	void *fn_data;
519fca9d5cSJohannes Berg 
529fca9d5cSJohannes Berg 	u16 cmds[MAX_NOTIF_CMDS];
539fca9d5cSJohannes Berg 	u8 n_cmds;
549fca9d5cSJohannes Berg 	bool triggered, aborted;
559fca9d5cSJohannes Berg };
569fca9d5cSJohannes Berg 
579fca9d5cSJohannes Berg 
589fca9d5cSJohannes Berg /* caller functions */
599fca9d5cSJohannes Berg void iwl_notification_wait_init(struct iwl_notif_wait_data *notif_data);
609fca9d5cSJohannes Berg bool iwl_notification_wait(struct iwl_notif_wait_data *notif_data,
619fca9d5cSJohannes Berg 			   struct iwl_rx_packet *pkt);
629fca9d5cSJohannes Berg void iwl_abort_notification_waits(struct iwl_notif_wait_data *notif_data);
639fca9d5cSJohannes Berg 
649fca9d5cSJohannes Berg static inline void
iwl_notification_notify(struct iwl_notif_wait_data * notif_data)659fca9d5cSJohannes Berg iwl_notification_notify(struct iwl_notif_wait_data *notif_data)
669fca9d5cSJohannes Berg {
679fca9d5cSJohannes Berg 	wake_up_all(&notif_data->notif_waitq);
689fca9d5cSJohannes Berg }
699fca9d5cSJohannes Berg 
709fca9d5cSJohannes Berg static inline void
iwl_notification_wait_notify(struct iwl_notif_wait_data * notif_data,struct iwl_rx_packet * pkt)719fca9d5cSJohannes Berg iwl_notification_wait_notify(struct iwl_notif_wait_data *notif_data,
729fca9d5cSJohannes Berg 			     struct iwl_rx_packet *pkt)
739fca9d5cSJohannes Berg {
749fca9d5cSJohannes Berg 	if (iwl_notification_wait(notif_data, pkt))
759fca9d5cSJohannes Berg 		iwl_notification_notify(notif_data);
769fca9d5cSJohannes Berg }
779fca9d5cSJohannes Berg 
789fca9d5cSJohannes Berg /* user functions */
799fca9d5cSJohannes Berg void __acquires(wait_entry)
809fca9d5cSJohannes Berg iwl_init_notification_wait(struct iwl_notif_wait_data *notif_data,
819fca9d5cSJohannes Berg 			   struct iwl_notification_wait *wait_entry,
829fca9d5cSJohannes Berg 			   const u16 *cmds, int n_cmds,
839fca9d5cSJohannes Berg 			   bool (*fn)(struct iwl_notif_wait_data *notif_data,
849fca9d5cSJohannes Berg 				      struct iwl_rx_packet *pkt, void *data),
859fca9d5cSJohannes Berg 			   void *fn_data);
869fca9d5cSJohannes Berg 
879fca9d5cSJohannes Berg int __must_check __releases(wait_entry)
889fca9d5cSJohannes Berg iwl_wait_notification(struct iwl_notif_wait_data *notif_data,
899fca9d5cSJohannes Berg 		      struct iwl_notification_wait *wait_entry,
909fca9d5cSJohannes Berg 		      unsigned long timeout);
919fca9d5cSJohannes Berg 
929fca9d5cSJohannes Berg void __releases(wait_entry)
939fca9d5cSJohannes Berg iwl_remove_notification(struct iwl_notif_wait_data *notif_data,
949fca9d5cSJohannes Berg 			struct iwl_notification_wait *wait_entry);
959fca9d5cSJohannes Berg 
969fca9d5cSJohannes Berg #endif /* __iwl_notif_wait_h__ */
97