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