iwl-notif-wait.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 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 <ilw@linux.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. * All rights reserved.
  36. *
  37. * Redistribution and use in source and binary forms, with or without
  38. * modification, are permitted provided that the following conditions
  39. * are met:
  40. *
  41. * * Redistributions of source code must retain the above copyright
  42. * notice, this list of conditions and the following disclaimer.
  43. * * Redistributions in binary form must reproduce the above copyright
  44. * notice, this list of conditions and the following disclaimer in
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *
  62. *****************************************************************************/
  63. #ifndef __iwl_notif_wait_h__
  64. #define __iwl_notif_wait_h__
  65. #include <linux/wait.h>
  66. #include "iwl-trans.h"
  67. struct iwl_notif_wait_data {
  68. struct list_head notif_waits;
  69. spinlock_t notif_wait_lock;
  70. wait_queue_head_t notif_waitq;
  71. };
  72. #define MAX_NOTIF_CMDS 5
  73. /**
  74. * struct iwl_notification_wait - notification wait entry
  75. * @list: list head for global list
  76. * @fn: Function called with the notification. If the function
  77. * returns true, the wait is over, if it returns false then
  78. * the waiter stays blocked. If no function is given, any
  79. * of the listed commands will unblock the waiter.
  80. * @cmds: command IDs
  81. * @n_cmds: number of command IDs
  82. * @triggered: waiter should be woken up
  83. * @aborted: wait was aborted
  84. *
  85. * This structure is not used directly, to wait for a
  86. * notification declare it on the stack, and call
  87. * iwlagn_init_notification_wait() with appropriate
  88. * parameters. Then do whatever will cause the ucode
  89. * to notify the driver, and to wait for that then
  90. * call iwlagn_wait_notification().
  91. *
  92. * Each notification is one-shot. If at some point we
  93. * need to support multi-shot notifications (which
  94. * can't be allocated on the stack) we need to modify
  95. * the code for them.
  96. */
  97. struct iwl_notification_wait {
  98. struct list_head list;
  99. bool (*fn)(struct iwl_notif_wait_data *notif_data,
  100. struct iwl_rx_packet *pkt, void *data);
  101. void *fn_data;
  102. u16 cmds[MAX_NOTIF_CMDS];
  103. u8 n_cmds;
  104. bool triggered, aborted;
  105. };
  106. /* caller functions */
  107. void iwl_notification_wait_init(struct iwl_notif_wait_data *notif_data);
  108. void iwl_notification_wait_notify(struct iwl_notif_wait_data *notif_data,
  109. struct iwl_rx_packet *pkt);
  110. void iwl_abort_notification_waits(struct iwl_notif_wait_data *notif_data);
  111. /* user functions */
  112. void __acquires(wait_entry)
  113. iwl_init_notification_wait(struct iwl_notif_wait_data *notif_data,
  114. struct iwl_notification_wait *wait_entry,
  115. const u16 *cmds, int n_cmds,
  116. bool (*fn)(struct iwl_notif_wait_data *notif_data,
  117. struct iwl_rx_packet *pkt, void *data),
  118. void *fn_data);
  119. int __must_check __releases(wait_entry)
  120. iwl_wait_notification(struct iwl_notif_wait_data *notif_data,
  121. struct iwl_notification_wait *wait_entry,
  122. unsigned long timeout);
  123. void __releases(wait_entry)
  124. iwl_remove_notification(struct iwl_notif_wait_data *notif_data,
  125. struct iwl_notification_wait *wait_entry);
  126. #endif /* __iwl_notif_wait_h__ */