iwl-op-mode.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
  2. /*
  3. * Copyright (C) 2005-2014, 2018-2021 Intel Corporation
  4. * Copyright (C) 2013-2014 Intel Mobile Communications GmbH
  5. * Copyright (C) 2015 Intel Deutschland GmbH
  6. */
  7. #ifndef __iwl_op_mode_h__
  8. #define __iwl_op_mode_h__
  9. #include <linux/netdevice.h>
  10. #include <linux/debugfs.h>
  11. #include "iwl-dbg-tlv.h"
  12. struct iwl_op_mode;
  13. struct iwl_trans;
  14. struct sk_buff;
  15. struct iwl_device_cmd;
  16. struct iwl_rx_cmd_buffer;
  17. struct iwl_fw;
  18. struct iwl_cfg;
  19. /**
  20. * DOC: Operational mode - what is it ?
  21. *
  22. * The operational mode (a.k.a. op_mode) is the layer that implements
  23. * mac80211's handlers. It knows two APIs: mac80211's and the fw's. It uses
  24. * the transport API to access the HW. The op_mode doesn't need to know how the
  25. * underlying HW works, since the transport layer takes care of that.
  26. *
  27. * There can be several op_mode: i.e. different fw APIs will require two
  28. * different op_modes. This is why the op_mode is virtualized.
  29. */
  30. /**
  31. * DOC: Life cycle of the Operational mode
  32. *
  33. * The operational mode has a very simple life cycle.
  34. *
  35. * 1) The driver layer (iwl-drv.c) chooses the op_mode based on the
  36. * capabilities advertised by the fw file (in TLV format).
  37. * 2) The driver layer starts the op_mode (ops->start)
  38. * 3) The op_mode registers mac80211
  39. * 4) The op_mode is governed by mac80211
  40. * 5) The driver layer stops the op_mode
  41. */
  42. /**
  43. * struct iwl_op_mode_ops - op_mode specific operations
  44. *
  45. * The op_mode exports its ops so that external components can start it and
  46. * interact with it. The driver layer typically calls the start and stop
  47. * handlers, the transport layer calls the others.
  48. *
  49. * All the handlers MUST be implemented, except @rx_rss which can be left
  50. * out *iff* the opmode will never run on hardware with multi-queue capability.
  51. *
  52. * @start: start the op_mode. The transport layer is already allocated.
  53. * May sleep
  54. * @stop: stop the op_mode. Must free all the memory allocated.
  55. * May sleep
  56. * @rx: Rx notification to the op_mode. rxb is the Rx buffer itself. Cmd is the
  57. * HCMD this Rx responds to. Can't sleep.
  58. * @rx_rss: data queue RX notification to the op_mode, for (data) notifications
  59. * received on the RSS queue(s). The queue parameter indicates which of the
  60. * RSS queues received this frame; it will always be non-zero.
  61. * This method must not sleep.
  62. * @async_cb: called when an ASYNC command with CMD_WANT_ASYNC_CALLBACK set
  63. * completes. Must be atomic.
  64. * @queue_full: notifies that a HW queue is full.
  65. * Must be atomic and called with BH disabled.
  66. * @queue_not_full: notifies that a HW queue is not full any more.
  67. * Must be atomic and called with BH disabled.
  68. * @hw_rf_kill:notifies of a change in the HW rf kill switch. True means that
  69. * the radio is killed. Return %true if the device should be stopped by
  70. * the transport immediately after the call. May sleep.
  71. * @free_skb: allows the transport layer to free skbs that haven't been
  72. * reclaimed by the op_mode. This can happen when the driver is freed and
  73. * there are Tx packets pending in the transport layer.
  74. * Must be atomic
  75. * @nic_error: error notification. Must be atomic and must be called with BH
  76. * disabled, unless the sync parameter is true.
  77. * @cmd_queue_full: Called when the command queue gets full. Must be atomic and
  78. * called with BH disabled.
  79. * @nic_config: configure NIC, called before firmware is started.
  80. * May sleep
  81. * @wimax_active: invoked when WiMax becomes active. May sleep
  82. * @time_point: called when transport layer wants to collect debug data
  83. */
  84. struct iwl_op_mode_ops {
  85. struct iwl_op_mode *(*start)(struct iwl_trans *trans,
  86. const struct iwl_cfg *cfg,
  87. const struct iwl_fw *fw,
  88. struct dentry *dbgfs_dir);
  89. void (*stop)(struct iwl_op_mode *op_mode);
  90. void (*rx)(struct iwl_op_mode *op_mode, struct napi_struct *napi,
  91. struct iwl_rx_cmd_buffer *rxb);
  92. void (*rx_rss)(struct iwl_op_mode *op_mode, struct napi_struct *napi,
  93. struct iwl_rx_cmd_buffer *rxb, unsigned int queue);
  94. void (*async_cb)(struct iwl_op_mode *op_mode,
  95. const struct iwl_device_cmd *cmd);
  96. void (*queue_full)(struct iwl_op_mode *op_mode, int queue);
  97. void (*queue_not_full)(struct iwl_op_mode *op_mode, int queue);
  98. bool (*hw_rf_kill)(struct iwl_op_mode *op_mode, bool state);
  99. void (*free_skb)(struct iwl_op_mode *op_mode, struct sk_buff *skb);
  100. void (*nic_error)(struct iwl_op_mode *op_mode, bool sync);
  101. void (*cmd_queue_full)(struct iwl_op_mode *op_mode);
  102. void (*nic_config)(struct iwl_op_mode *op_mode);
  103. void (*wimax_active)(struct iwl_op_mode *op_mode);
  104. void (*time_point)(struct iwl_op_mode *op_mode,
  105. enum iwl_fw_ini_time_point tp_id,
  106. union iwl_dbg_tlv_tp_data *tp_data);
  107. };
  108. int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops);
  109. void iwl_opmode_deregister(const char *name);
  110. /**
  111. * struct iwl_op_mode - operational mode
  112. * @ops: pointer to its own ops
  113. *
  114. * This holds an implementation of the mac80211 / fw API.
  115. */
  116. struct iwl_op_mode {
  117. const struct iwl_op_mode_ops *ops;
  118. char op_mode_specific[] __aligned(sizeof(void *));
  119. };
  120. static inline void iwl_op_mode_stop(struct iwl_op_mode *op_mode)
  121. {
  122. might_sleep();
  123. op_mode->ops->stop(op_mode);
  124. }
  125. static inline void iwl_op_mode_rx(struct iwl_op_mode *op_mode,
  126. struct napi_struct *napi,
  127. struct iwl_rx_cmd_buffer *rxb)
  128. {
  129. return op_mode->ops->rx(op_mode, napi, rxb);
  130. }
  131. static inline void iwl_op_mode_rx_rss(struct iwl_op_mode *op_mode,
  132. struct napi_struct *napi,
  133. struct iwl_rx_cmd_buffer *rxb,
  134. unsigned int queue)
  135. {
  136. op_mode->ops->rx_rss(op_mode, napi, rxb, queue);
  137. }
  138. static inline void iwl_op_mode_async_cb(struct iwl_op_mode *op_mode,
  139. const struct iwl_device_cmd *cmd)
  140. {
  141. if (op_mode->ops->async_cb)
  142. op_mode->ops->async_cb(op_mode, cmd);
  143. }
  144. static inline void iwl_op_mode_queue_full(struct iwl_op_mode *op_mode,
  145. int queue)
  146. {
  147. op_mode->ops->queue_full(op_mode, queue);
  148. }
  149. static inline void iwl_op_mode_queue_not_full(struct iwl_op_mode *op_mode,
  150. int queue)
  151. {
  152. op_mode->ops->queue_not_full(op_mode, queue);
  153. }
  154. static inline bool __must_check
  155. iwl_op_mode_hw_rf_kill(struct iwl_op_mode *op_mode, bool state)
  156. {
  157. might_sleep();
  158. return op_mode->ops->hw_rf_kill(op_mode, state);
  159. }
  160. static inline void iwl_op_mode_free_skb(struct iwl_op_mode *op_mode,
  161. struct sk_buff *skb)
  162. {
  163. if (WARN_ON_ONCE(!op_mode))
  164. return;
  165. op_mode->ops->free_skb(op_mode, skb);
  166. }
  167. static inline void iwl_op_mode_nic_error(struct iwl_op_mode *op_mode, bool sync)
  168. {
  169. op_mode->ops->nic_error(op_mode, sync);
  170. }
  171. static inline void iwl_op_mode_cmd_queue_full(struct iwl_op_mode *op_mode)
  172. {
  173. op_mode->ops->cmd_queue_full(op_mode);
  174. }
  175. static inline void iwl_op_mode_nic_config(struct iwl_op_mode *op_mode)
  176. {
  177. might_sleep();
  178. op_mode->ops->nic_config(op_mode);
  179. }
  180. static inline void iwl_op_mode_wimax_active(struct iwl_op_mode *op_mode)
  181. {
  182. might_sleep();
  183. op_mode->ops->wimax_active(op_mode);
  184. }
  185. static inline void iwl_op_mode_time_point(struct iwl_op_mode *op_mode,
  186. enum iwl_fw_ini_time_point tp_id,
  187. union iwl_dbg_tlv_tp_data *tp_data)
  188. {
  189. if (!op_mode || !op_mode->ops || !op_mode->ops->time_point)
  190. return;
  191. op_mode->ops->time_point(op_mode, tp_id, tp_data);
  192. }
  193. #endif /* __iwl_op_mode_h__ */