xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/intel/iwlwifi/iwl-op-mode.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /******************************************************************************
2*4882a593Smuzhiyun  *
3*4882a593Smuzhiyun  * This file is provided under a dual BSD/GPLv2 license.  When using or
4*4882a593Smuzhiyun  * redistributing this file, you may do so under either license.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * GPL LICENSE SUMMARY
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved.
9*4882a593Smuzhiyun  * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
10*4882a593Smuzhiyun  * Copyright(c) 2015        Intel Deutschland GmbH
11*4882a593Smuzhiyun  * Copyright(c) 2018 - 2019 Intel Corporation
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or modify
14*4882a593Smuzhiyun  * it under the terms of version 2 of the GNU General Public License as
15*4882a593Smuzhiyun  * published by the Free Software Foundation.
16*4882a593Smuzhiyun  *
17*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful, but
18*4882a593Smuzhiyun  * WITHOUT ANY WARRANTY; without even the implied warranty of
19*4882a593Smuzhiyun  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20*4882a593Smuzhiyun  * General Public License for more details.
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  * The full GNU General Public License is included in this distribution
23*4882a593Smuzhiyun  * in the file called COPYING.
24*4882a593Smuzhiyun  *
25*4882a593Smuzhiyun  * Contact Information:
26*4882a593Smuzhiyun  *  Intel Linux Wireless <linuxwifi@intel.com>
27*4882a593Smuzhiyun  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  * BSD LICENSE
30*4882a593Smuzhiyun  *
31*4882a593Smuzhiyun  * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
32*4882a593Smuzhiyun  * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
33*4882a593Smuzhiyun  * Copyright(c) 2015        Intel Deutschland GmbH
34*4882a593Smuzhiyun  * Copyright(c) 2018 - 2019 Intel Corporation
35*4882a593Smuzhiyun  * All rights reserved.
36*4882a593Smuzhiyun  *
37*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
38*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions
39*4882a593Smuzhiyun  * are met:
40*4882a593Smuzhiyun  *
41*4882a593Smuzhiyun  *  * Redistributions of source code must retain the above copyright
42*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer.
43*4882a593Smuzhiyun  *  * Redistributions in binary form must reproduce the above copyright
44*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer in
45*4882a593Smuzhiyun  *    the documentation and/or other materials provided with the
46*4882a593Smuzhiyun  *    distribution.
47*4882a593Smuzhiyun  *  * Neither the name Intel Corporation nor the names of its
48*4882a593Smuzhiyun  *    contributors may be used to endorse or promote products derived
49*4882a593Smuzhiyun  *    from this software without specific prior written permission.
50*4882a593Smuzhiyun  *
51*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52*4882a593Smuzhiyun  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53*4882a593Smuzhiyun  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54*4882a593Smuzhiyun  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55*4882a593Smuzhiyun  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56*4882a593Smuzhiyun  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57*4882a593Smuzhiyun  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58*4882a593Smuzhiyun  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59*4882a593Smuzhiyun  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60*4882a593Smuzhiyun  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61*4882a593Smuzhiyun  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62*4882a593Smuzhiyun  *
63*4882a593Smuzhiyun  *****************************************************************************/
64*4882a593Smuzhiyun #ifndef __iwl_op_mode_h__
65*4882a593Smuzhiyun #define __iwl_op_mode_h__
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun #include <linux/netdevice.h>
68*4882a593Smuzhiyun #include <linux/debugfs.h>
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun struct iwl_op_mode;
71*4882a593Smuzhiyun struct iwl_trans;
72*4882a593Smuzhiyun struct sk_buff;
73*4882a593Smuzhiyun struct iwl_device_cmd;
74*4882a593Smuzhiyun struct iwl_rx_cmd_buffer;
75*4882a593Smuzhiyun struct iwl_fw;
76*4882a593Smuzhiyun struct iwl_cfg;
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun /**
79*4882a593Smuzhiyun  * DOC: Operational mode - what is it ?
80*4882a593Smuzhiyun  *
81*4882a593Smuzhiyun  * The operational mode (a.k.a. op_mode) is the layer that implements
82*4882a593Smuzhiyun  * mac80211's handlers. It knows two APIs: mac80211's and the fw's. It uses
83*4882a593Smuzhiyun  * the transport API to access the HW. The op_mode doesn't need to know how the
84*4882a593Smuzhiyun  * underlying HW works, since the transport layer takes care of that.
85*4882a593Smuzhiyun  *
86*4882a593Smuzhiyun  * There can be several op_mode: i.e. different fw APIs will require two
87*4882a593Smuzhiyun  * different op_modes. This is why the op_mode is virtualized.
88*4882a593Smuzhiyun  */
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun /**
91*4882a593Smuzhiyun  * DOC: Life cycle of the Operational mode
92*4882a593Smuzhiyun  *
93*4882a593Smuzhiyun  * The operational mode has a very simple life cycle.
94*4882a593Smuzhiyun  *
95*4882a593Smuzhiyun  *	1) The driver layer (iwl-drv.c) chooses the op_mode based on the
96*4882a593Smuzhiyun  *	   capabilities advertised by the fw file (in TLV format).
97*4882a593Smuzhiyun  *	2) The driver layer starts the op_mode (ops->start)
98*4882a593Smuzhiyun  *	3) The op_mode registers mac80211
99*4882a593Smuzhiyun  *	4) The op_mode is governed by mac80211
100*4882a593Smuzhiyun  *	5) The driver layer stops the op_mode
101*4882a593Smuzhiyun  */
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun /**
104*4882a593Smuzhiyun  * struct iwl_op_mode_ops - op_mode specific operations
105*4882a593Smuzhiyun  *
106*4882a593Smuzhiyun  * The op_mode exports its ops so that external components can start it and
107*4882a593Smuzhiyun  * interact with it. The driver layer typically calls the start and stop
108*4882a593Smuzhiyun  * handlers, the transport layer calls the others.
109*4882a593Smuzhiyun  *
110*4882a593Smuzhiyun  * All the handlers MUST be implemented, except @rx_rss which can be left
111*4882a593Smuzhiyun  * out *iff* the opmode will never run on hardware with multi-queue capability.
112*4882a593Smuzhiyun  *
113*4882a593Smuzhiyun  * @start: start the op_mode. The transport layer is already allocated.
114*4882a593Smuzhiyun  *	May sleep
115*4882a593Smuzhiyun  * @stop: stop the op_mode. Must free all the memory allocated.
116*4882a593Smuzhiyun  *	May sleep
117*4882a593Smuzhiyun  * @rx: Rx notification to the op_mode. rxb is the Rx buffer itself. Cmd is the
118*4882a593Smuzhiyun  *	HCMD this Rx responds to. Can't sleep.
119*4882a593Smuzhiyun  * @rx_rss: data queue RX notification to the op_mode, for (data) notifications
120*4882a593Smuzhiyun  *	received on the RSS queue(s). The queue parameter indicates which of the
121*4882a593Smuzhiyun  *	RSS queues received this frame; it will always be non-zero.
122*4882a593Smuzhiyun  *	This method must not sleep.
123*4882a593Smuzhiyun  * @async_cb: called when an ASYNC command with CMD_WANT_ASYNC_CALLBACK set
124*4882a593Smuzhiyun  *	completes. Must be atomic.
125*4882a593Smuzhiyun  * @queue_full: notifies that a HW queue is full.
126*4882a593Smuzhiyun  *	Must be atomic and called with BH disabled.
127*4882a593Smuzhiyun  * @queue_not_full: notifies that a HW queue is not full any more.
128*4882a593Smuzhiyun  *	Must be atomic and called with BH disabled.
129*4882a593Smuzhiyun  * @hw_rf_kill:notifies of a change in the HW rf kill switch. True means that
130*4882a593Smuzhiyun  *	the radio is killed. Return %true if the device should be stopped by
131*4882a593Smuzhiyun  *	the transport immediately after the call. May sleep.
132*4882a593Smuzhiyun  * @free_skb: allows the transport layer to free skbs that haven't been
133*4882a593Smuzhiyun  *	reclaimed by the op_mode. This can happen when the driver is freed and
134*4882a593Smuzhiyun  *	there are Tx packets pending in the transport layer.
135*4882a593Smuzhiyun  *	Must be atomic
136*4882a593Smuzhiyun  * @nic_error: error notification. Must be atomic and must be called with BH
137*4882a593Smuzhiyun  *	disabled.
138*4882a593Smuzhiyun  * @cmd_queue_full: Called when the command queue gets full. Must be atomic and
139*4882a593Smuzhiyun  *	called with BH disabled.
140*4882a593Smuzhiyun  * @nic_config: configure NIC, called before firmware is started.
141*4882a593Smuzhiyun  *	May sleep
142*4882a593Smuzhiyun  * @wimax_active: invoked when WiMax becomes active. May sleep
143*4882a593Smuzhiyun  */
144*4882a593Smuzhiyun struct iwl_op_mode_ops {
145*4882a593Smuzhiyun 	struct iwl_op_mode *(*start)(struct iwl_trans *trans,
146*4882a593Smuzhiyun 				     const struct iwl_cfg *cfg,
147*4882a593Smuzhiyun 				     const struct iwl_fw *fw,
148*4882a593Smuzhiyun 				     struct dentry *dbgfs_dir);
149*4882a593Smuzhiyun 	void (*stop)(struct iwl_op_mode *op_mode);
150*4882a593Smuzhiyun 	void (*rx)(struct iwl_op_mode *op_mode, struct napi_struct *napi,
151*4882a593Smuzhiyun 		   struct iwl_rx_cmd_buffer *rxb);
152*4882a593Smuzhiyun 	void (*rx_rss)(struct iwl_op_mode *op_mode, struct napi_struct *napi,
153*4882a593Smuzhiyun 		       struct iwl_rx_cmd_buffer *rxb, unsigned int queue);
154*4882a593Smuzhiyun 	void (*async_cb)(struct iwl_op_mode *op_mode,
155*4882a593Smuzhiyun 			 const struct iwl_device_cmd *cmd);
156*4882a593Smuzhiyun 	void (*queue_full)(struct iwl_op_mode *op_mode, int queue);
157*4882a593Smuzhiyun 	void (*queue_not_full)(struct iwl_op_mode *op_mode, int queue);
158*4882a593Smuzhiyun 	bool (*hw_rf_kill)(struct iwl_op_mode *op_mode, bool state);
159*4882a593Smuzhiyun 	void (*free_skb)(struct iwl_op_mode *op_mode, struct sk_buff *skb);
160*4882a593Smuzhiyun 	void (*nic_error)(struct iwl_op_mode *op_mode);
161*4882a593Smuzhiyun 	void (*cmd_queue_full)(struct iwl_op_mode *op_mode);
162*4882a593Smuzhiyun 	void (*nic_config)(struct iwl_op_mode *op_mode);
163*4882a593Smuzhiyun 	void (*wimax_active)(struct iwl_op_mode *op_mode);
164*4882a593Smuzhiyun };
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops);
167*4882a593Smuzhiyun void iwl_opmode_deregister(const char *name);
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun /**
170*4882a593Smuzhiyun  * struct iwl_op_mode - operational mode
171*4882a593Smuzhiyun  * @ops: pointer to its own ops
172*4882a593Smuzhiyun  *
173*4882a593Smuzhiyun  * This holds an implementation of the mac80211 / fw API.
174*4882a593Smuzhiyun  */
175*4882a593Smuzhiyun struct iwl_op_mode {
176*4882a593Smuzhiyun 	const struct iwl_op_mode_ops *ops;
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun 	char op_mode_specific[] __aligned(sizeof(void *));
179*4882a593Smuzhiyun };
180*4882a593Smuzhiyun 
iwl_op_mode_stop(struct iwl_op_mode * op_mode)181*4882a593Smuzhiyun static inline void iwl_op_mode_stop(struct iwl_op_mode *op_mode)
182*4882a593Smuzhiyun {
183*4882a593Smuzhiyun 	might_sleep();
184*4882a593Smuzhiyun 	op_mode->ops->stop(op_mode);
185*4882a593Smuzhiyun }
186*4882a593Smuzhiyun 
iwl_op_mode_rx(struct iwl_op_mode * op_mode,struct napi_struct * napi,struct iwl_rx_cmd_buffer * rxb)187*4882a593Smuzhiyun static inline void iwl_op_mode_rx(struct iwl_op_mode *op_mode,
188*4882a593Smuzhiyun 				  struct napi_struct *napi,
189*4882a593Smuzhiyun 				  struct iwl_rx_cmd_buffer *rxb)
190*4882a593Smuzhiyun {
191*4882a593Smuzhiyun 	return op_mode->ops->rx(op_mode, napi, rxb);
192*4882a593Smuzhiyun }
193*4882a593Smuzhiyun 
iwl_op_mode_rx_rss(struct iwl_op_mode * op_mode,struct napi_struct * napi,struct iwl_rx_cmd_buffer * rxb,unsigned int queue)194*4882a593Smuzhiyun static inline void iwl_op_mode_rx_rss(struct iwl_op_mode *op_mode,
195*4882a593Smuzhiyun 				      struct napi_struct *napi,
196*4882a593Smuzhiyun 				      struct iwl_rx_cmd_buffer *rxb,
197*4882a593Smuzhiyun 				      unsigned int queue)
198*4882a593Smuzhiyun {
199*4882a593Smuzhiyun 	op_mode->ops->rx_rss(op_mode, napi, rxb, queue);
200*4882a593Smuzhiyun }
201*4882a593Smuzhiyun 
iwl_op_mode_async_cb(struct iwl_op_mode * op_mode,const struct iwl_device_cmd * cmd)202*4882a593Smuzhiyun static inline void iwl_op_mode_async_cb(struct iwl_op_mode *op_mode,
203*4882a593Smuzhiyun 					const struct iwl_device_cmd *cmd)
204*4882a593Smuzhiyun {
205*4882a593Smuzhiyun 	if (op_mode->ops->async_cb)
206*4882a593Smuzhiyun 		op_mode->ops->async_cb(op_mode, cmd);
207*4882a593Smuzhiyun }
208*4882a593Smuzhiyun 
iwl_op_mode_queue_full(struct iwl_op_mode * op_mode,int queue)209*4882a593Smuzhiyun static inline void iwl_op_mode_queue_full(struct iwl_op_mode *op_mode,
210*4882a593Smuzhiyun 					  int queue)
211*4882a593Smuzhiyun {
212*4882a593Smuzhiyun 	op_mode->ops->queue_full(op_mode, queue);
213*4882a593Smuzhiyun }
214*4882a593Smuzhiyun 
iwl_op_mode_queue_not_full(struct iwl_op_mode * op_mode,int queue)215*4882a593Smuzhiyun static inline void iwl_op_mode_queue_not_full(struct iwl_op_mode *op_mode,
216*4882a593Smuzhiyun 					      int queue)
217*4882a593Smuzhiyun {
218*4882a593Smuzhiyun 	op_mode->ops->queue_not_full(op_mode, queue);
219*4882a593Smuzhiyun }
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun static inline bool __must_check
iwl_op_mode_hw_rf_kill(struct iwl_op_mode * op_mode,bool state)222*4882a593Smuzhiyun iwl_op_mode_hw_rf_kill(struct iwl_op_mode *op_mode, bool state)
223*4882a593Smuzhiyun {
224*4882a593Smuzhiyun 	might_sleep();
225*4882a593Smuzhiyun 	return op_mode->ops->hw_rf_kill(op_mode, state);
226*4882a593Smuzhiyun }
227*4882a593Smuzhiyun 
iwl_op_mode_free_skb(struct iwl_op_mode * op_mode,struct sk_buff * skb)228*4882a593Smuzhiyun static inline void iwl_op_mode_free_skb(struct iwl_op_mode *op_mode,
229*4882a593Smuzhiyun 					struct sk_buff *skb)
230*4882a593Smuzhiyun {
231*4882a593Smuzhiyun 	op_mode->ops->free_skb(op_mode, skb);
232*4882a593Smuzhiyun }
233*4882a593Smuzhiyun 
iwl_op_mode_nic_error(struct iwl_op_mode * op_mode)234*4882a593Smuzhiyun static inline void iwl_op_mode_nic_error(struct iwl_op_mode *op_mode)
235*4882a593Smuzhiyun {
236*4882a593Smuzhiyun 	op_mode->ops->nic_error(op_mode);
237*4882a593Smuzhiyun }
238*4882a593Smuzhiyun 
iwl_op_mode_cmd_queue_full(struct iwl_op_mode * op_mode)239*4882a593Smuzhiyun static inline void iwl_op_mode_cmd_queue_full(struct iwl_op_mode *op_mode)
240*4882a593Smuzhiyun {
241*4882a593Smuzhiyun 	op_mode->ops->cmd_queue_full(op_mode);
242*4882a593Smuzhiyun }
243*4882a593Smuzhiyun 
iwl_op_mode_nic_config(struct iwl_op_mode * op_mode)244*4882a593Smuzhiyun static inline void iwl_op_mode_nic_config(struct iwl_op_mode *op_mode)
245*4882a593Smuzhiyun {
246*4882a593Smuzhiyun 	might_sleep();
247*4882a593Smuzhiyun 	op_mode->ops->nic_config(op_mode);
248*4882a593Smuzhiyun }
249*4882a593Smuzhiyun 
iwl_op_mode_wimax_active(struct iwl_op_mode * op_mode)250*4882a593Smuzhiyun static inline void iwl_op_mode_wimax_active(struct iwl_op_mode *op_mode)
251*4882a593Smuzhiyun {
252*4882a593Smuzhiyun 	might_sleep();
253*4882a593Smuzhiyun 	op_mode->ops->wimax_active(op_mode);
254*4882a593Smuzhiyun }
255*4882a593Smuzhiyun 
256*4882a593Smuzhiyun #endif /* __iwl_op_mode_h__ */
257