xref: /wlan-driver/qcacld-3.0/os_if/sync/inc/osif_vdev_sync.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2018-2019, 2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef __OSIF_VDEV_SYNC_H
21 #define __OSIF_VDEV_SYNC_H
22 
23 #include "linux/device.h"
24 #include "linux/netdevice.h"
25 #include "qdf_types.h"
26 
27 /**
28  * struct osif_vdev_sync - vdev synchronization context
29  * @net_dev: the net_device used as a lookup key
30  * @dsc_vdev: the dsc_vdev used for synchronization
31  * @in_use: indicates if the context is being used
32  */
33 struct osif_vdev_sync {
34 	struct net_device *net_dev;
35 	struct dsc_vdev *dsc_vdev;
36 	bool in_use;
37 };
38 
39 /**
40  * osif_vdev_sync_create() - create a vdev synchronization context
41  * @dev: parent device to the vdev
42  * @out_vdev_sync: out parameter for the new synchronization context
43  *
44  * Return: Errno
45  */
46 qdf_must_check int
47 osif_vdev_sync_create(struct device *dev,
48 		      struct osif_vdev_sync **out_vdev_sync);
49 
50 /**
51  * osif_vdev_sync_create_and_trans() - create a vdev synchronization context
52  * @dev: parent device to the vdev
53  * @out_vdev_sync: out parameter for the new synchronization context
54  *
55  * For protecting the net_device creation process.
56  *
57  * Return: Errno
58  */
59 #define osif_vdev_sync_create_and_trans(dev, out_vdev_sync) \
60 	__osif_vdev_sync_create_and_trans(dev, out_vdev_sync, __func__)
61 
62 qdf_must_check int
63 __osif_vdev_sync_create_and_trans(struct device *dev,
64 				  struct osif_vdev_sync **out_vdev_sync,
65 				  const char *desc);
66 
67 /**
68  * osif_vdev_sync_destroy() - destroy a vdev synchronization context
69  * @vdev_sync: the context to destroy
70  *
71  * Return: none
72  */
73 void osif_vdev_sync_destroy(struct osif_vdev_sync *vdev_sync);
74 
75 /**
76  * osif_vdev_sync_register() - register a vdev for operations/transitions
77  * @net_dev: the net_device to use as the operation/transition lookup key
78  * @vdev_sync: the vdev synchronization context to register
79  *
80  * Return: none
81  */
82 void osif_vdev_sync_register(struct net_device *net_dev,
83 			     struct osif_vdev_sync *vdev_sync);
84 
85 /**
86  * osif_vdev_sync_unregister() - unregister a vdev for operations/transitions
87  * @net_dev: the net_device originally used to register the vdev_sync context
88  *
89  * Return: the vdev synchronization context that was registered for @net_dev
90  */
91 struct osif_vdev_sync *osif_vdev_sync_unregister(struct net_device *net_dev);
92 
93 /**
94  * osif_vdev_sync_trans_start() - attempt to start a transition on @net_dev
95  * @net_dev: the net_device to transition
96  * @out_vdev_sync: out parameter for the synchronization context registered with
97  *	@net_dev, populated on success
98  *
99  * Return: Errno
100  */
101 #define osif_vdev_sync_trans_start(net_dev, out_vdev_sync) \
102 	__osif_vdev_sync_trans_start(net_dev, out_vdev_sync, __func__)
103 
104 qdf_must_check int
105 __osif_vdev_sync_trans_start(struct net_device *net_dev,
106 			     struct osif_vdev_sync **out_vdev_sync,
107 			     const char *desc);
108 
109 /**
110  * osif_vdev_sync_trans_start_wait() - attempt to start a transition on
111  *	@net_dev, blocking if a conflicting transition is in flight
112  * @net_dev: the net_device to transition
113  * @out_vdev_sync: out parameter for the synchronization context registered with
114  *	@net_dev, populated on success
115  *
116  * Return: Errno
117  */
118 #define osif_vdev_sync_trans_start_wait(net_dev, out_vdev_sync) \
119 	__osif_vdev_sync_trans_start_wait(net_dev, out_vdev_sync, __func__)
120 
121 qdf_must_check int
122 __osif_vdev_sync_trans_start_wait(struct net_device *net_dev,
123 				  struct osif_vdev_sync **out_vdev_sync,
124 				  const char *desc);
125 
126 /**
127  * osif_vdev_sync_trans_stop() - stop a transition associated with @vdev_sync
128  * @vdev_sync: the synchronization context tracking the transition
129  *
130  * Return: none
131  */
132 void osif_vdev_sync_trans_stop(struct osif_vdev_sync *vdev_sync);
133 
134 /**
135  * osif_vdev_sync_assert_trans_protected() - assert that @net_dev is currently
136  *	protected by a transition
137  * @net_dev: the net_device to check
138  *
139  * Return: none
140  */
141 void osif_vdev_sync_assert_trans_protected(struct net_device *net_dev);
142 
143 /**
144  * osif_vdev_sync_op_start() - attempt to start an operation on @net_dev
145  * @net_dev: the net_device to operate against
146  * @out_vdev_sync: out parameter for the synchronization context registered with
147  *	@net_dev, populated on success
148  *
149  * Return: Errno
150  */
151 #define osif_vdev_sync_op_start(net_dev, out_vdev_sync) \
152 	__osif_vdev_sync_op_start(net_dev, out_vdev_sync, __func__)
153 
154 qdf_must_check int
155 __osif_vdev_sync_op_start(struct net_device *net_dev,
156 			  struct osif_vdev_sync **out_vdev_sync,
157 			  const char *func);
158 
159 /**
160  * osif_vdev_sync_op_stop() - stop an operation associated with @vdev_sync
161  * @vdev_sync: the synchronization context tracking the operation
162  *
163  * Return: none
164  */
165 #define osif_vdev_sync_op_stop(vdev_sync) \
166 	__osif_vdev_sync_op_stop(vdev_sync, __func__)
167 
168 void __osif_vdev_sync_op_stop(struct osif_vdev_sync *vdev_sync,
169 			      const char *func);
170 
171 /**
172  * osif_vdev_sync_wait_for_ops() - wait until all @vdev_sync operations complete
173  * @vdev_sync: the synchronization context tracking the operations
174  *
175  * Return: None
176  */
177 void osif_vdev_sync_wait_for_ops(struct osif_vdev_sync *vdev_sync);
178 
179 /**
180  * osif_vdev_get_cached_cmd() - Get north bound cmd cached during SSR
181  * @vdev_sync: osif vdev sync corresponding to the network interface
182  *
183  * This api will be invoked after completion of SSR re-initialization to get
184  * the last north bound command received during SSR
185  *
186  * Return: North bound command ID
187  */
188 uint8_t osif_vdev_get_cached_cmd(struct osif_vdev_sync *vdev_sync);
189 
190 /**
191  * osif_vdev_cache_command() - Cache north bound command during SSR
192  * @vdev_sync: osif vdev sync corresponding to the network interface
193  * @cmd_id: North bound command ID
194  *
195  * This api will be invoked when a north bound command is received during SSR
196  * and it should be handled after SSR re-initialization.
197  *
198  * Return: None
199  */
200 void osif_vdev_cache_command(struct osif_vdev_sync *vdev_sync, uint8_t cmd_id);
201 
202 /**
203  * osif_get_vdev_sync_arr() - Get vdev sync array base pointer
204  *
205  * Return: Base pointer to the vdev sync array
206  */
207 struct osif_vdev_sync *osif_get_vdev_sync_arr(void);
208 
209 #endif /* __OSIF_VDEV_SYNC_H */
210 
211