Commit | Line | Data |
---|---|---|
04672fe6 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
183b9b59 IPG |
2 | /* |
3 | * Ultra Wide Band | |
4 | * UWB internal API | |
5 | * | |
6 | * Copyright (C) 2005-2006 Intel Corporation | |
7 | * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> | |
8 | * | |
183b9b59 IPG |
9 | * This contains most of the internal API for UWB. This is stuff used |
10 | * across the stack that of course, is of no interest to the rest. | |
11 | * | |
12 | * Some parts might end up going public (like uwb_rc_*())... | |
13 | */ | |
14 | ||
15 | #ifndef __UWB_INTERNAL_H__ | |
16 | #define __UWB_INTERNAL_H__ | |
17 | ||
183b9b59 IPG |
18 | #include <linux/kernel.h> |
19 | #include <linux/device.h> | |
20 | #include <linux/uwb.h> | |
21 | #include <linux/mutex.h> | |
22 | ||
23 | struct uwb_beca_e; | |
24 | ||
25 | /* General device API */ | |
26 | extern void uwb_dev_init(struct uwb_dev *uwb_dev); | |
27 | extern int __uwb_dev_offair(struct uwb_dev *, struct uwb_rc *); | |
28 | extern int uwb_dev_add(struct uwb_dev *uwb_dev, struct device *parent_dev, | |
29 | struct uwb_rc *parent_rc); | |
30 | extern void uwb_dev_rm(struct uwb_dev *uwb_dev); | |
31 | extern void uwbd_dev_onair(struct uwb_rc *, struct uwb_beca_e *); | |
32 | extern void uwbd_dev_offair(struct uwb_beca_e *); | |
33 | void uwb_notify(struct uwb_rc *rc, struct uwb_dev *uwb_dev, enum uwb_notifs event); | |
34 | ||
35 | /* General UWB Radio Controller Internal API */ | |
36 | extern struct uwb_rc *__uwb_rc_try_get(struct uwb_rc *); | |
37 | static inline struct uwb_rc *__uwb_rc_get(struct uwb_rc *rc) | |
38 | { | |
39 | uwb_dev_get(&rc->uwb_dev); | |
40 | return rc; | |
41 | } | |
42 | ||
43 | static inline void __uwb_rc_put(struct uwb_rc *rc) | |
44 | { | |
a8995751 TP |
45 | if (rc) |
46 | uwb_dev_put(&rc->uwb_dev); | |
183b9b59 IPG |
47 | } |
48 | ||
49 | extern int uwb_rc_reset(struct uwb_rc *rc); | |
50 | extern int uwb_rc_beacon(struct uwb_rc *rc, | |
51 | int channel, unsigned bpst_offset); | |
52 | extern int uwb_rc_scan(struct uwb_rc *rc, | |
53 | unsigned channel, enum uwb_scan_type type, | |
54 | unsigned bpst_offset); | |
55 | extern int uwb_rc_send_all_drp_ie(struct uwb_rc *rc); | |
1cde7f68 DV |
56 | |
57 | void uwb_rc_ie_init(struct uwb_rc *); | |
58 | int uwb_rc_ie_setup(struct uwb_rc *); | |
59 | void uwb_rc_ie_release(struct uwb_rc *); | |
60 | int uwb_ie_dump_hex(const struct uwb_ie_hdr *ies, size_t len, | |
61 | char *buf, size_t size); | |
62 | int uwb_rc_set_ie(struct uwb_rc *, struct uwb_rc_cmd_set_ie *); | |
63 | ||
183b9b59 IPG |
64 | |
65 | extern const char *uwb_rc_strerror(unsigned code); | |
66 | ||
67 | /* | |
68 | * Time to wait for a response to an RC command. | |
69 | * | |
70 | * Some commands can take a long time to response. e.g., START_BEACON | |
71 | * may scan for several superframes before joining an existing beacon | |
72 | * group and this can take around 600 ms. | |
73 | */ | |
74 | #define UWB_RC_CMD_TIMEOUT_MS 1000 /* ms */ | |
75 | ||
76 | /* | |
77 | * Notification/Event Handlers | |
78 | */ | |
79 | ||
80 | struct uwb_rc_neh; | |
81 | ||
5b37717a SP |
82 | extern int uwb_rc_cmd_async(struct uwb_rc *rc, const char *cmd_name, |
83 | struct uwb_rccb *cmd, size_t cmd_size, | |
84 | u8 expected_type, u16 expected_event, | |
85 | uwb_rc_cmd_cb_f cb, void *arg); | |
86 | ||
87 | ||
183b9b59 IPG |
88 | void uwb_rc_neh_create(struct uwb_rc *rc); |
89 | void uwb_rc_neh_destroy(struct uwb_rc *rc); | |
90 | ||
91 | struct uwb_rc_neh *uwb_rc_neh_add(struct uwb_rc *rc, struct uwb_rccb *cmd, | |
92 | u8 expected_type, u16 expected_event, | |
93 | uwb_rc_cmd_cb_f cb, void *arg); | |
94 | void uwb_rc_neh_rm(struct uwb_rc *rc, struct uwb_rc_neh *neh); | |
95 | void uwb_rc_neh_arm(struct uwb_rc *rc, struct uwb_rc_neh *neh); | |
96 | void uwb_rc_neh_put(struct uwb_rc_neh *neh); | |
97 | ||
98 | /* Event size tables */ | |
99 | extern int uwb_est_create(void); | |
100 | extern void uwb_est_destroy(void); | |
101 | ||
5b37717a SP |
102 | /* |
103 | * UWB conflicting alien reservations | |
104 | */ | |
105 | struct uwb_cnflt_alien { | |
106 | struct uwb_rc *rc; | |
107 | struct list_head rc_node; | |
108 | struct uwb_mas_bm mas; | |
109 | struct timer_list timer; | |
110 | struct work_struct cnflt_update_work; | |
111 | }; | |
112 | ||
113 | enum uwb_uwb_rsv_alloc_result { | |
114 | UWB_RSV_ALLOC_FOUND = 0, | |
115 | UWB_RSV_ALLOC_NOT_FOUND, | |
116 | }; | |
117 | ||
118 | enum uwb_rsv_mas_status { | |
119 | UWB_RSV_MAS_NOT_AVAIL = 1, | |
120 | UWB_RSV_MAS_SAFE, | |
121 | UWB_RSV_MAS_UNSAFE, | |
122 | }; | |
123 | ||
124 | struct uwb_rsv_col_set_info { | |
125 | unsigned char start_col; | |
126 | unsigned char interval; | |
127 | unsigned char safe_mas_per_col; | |
128 | unsigned char unsafe_mas_per_col; | |
129 | }; | |
130 | ||
131 | struct uwb_rsv_col_info { | |
132 | unsigned char max_avail_safe; | |
133 | unsigned char max_avail_unsafe; | |
134 | unsigned char highest_mas[UWB_MAS_PER_ZONE]; | |
135 | struct uwb_rsv_col_set_info csi; | |
136 | }; | |
137 | ||
138 | struct uwb_rsv_row_info { | |
139 | unsigned char avail[UWB_MAS_PER_ZONE]; | |
140 | unsigned char free_rows; | |
141 | unsigned char used_rows; | |
142 | }; | |
143 | ||
144 | /* | |
145 | * UWB find allocation | |
146 | */ | |
147 | struct uwb_rsv_alloc_info { | |
148 | unsigned char bm[UWB_MAS_PER_ZONE * UWB_NUM_ZONES]; | |
149 | struct uwb_rsv_col_info ci[UWB_NUM_ZONES]; | |
150 | struct uwb_rsv_row_info ri; | |
151 | struct uwb_mas_bm *not_available; | |
152 | struct uwb_mas_bm *result; | |
153 | int min_mas; | |
154 | int max_mas; | |
155 | int max_interval; | |
156 | int total_allocated_mases; | |
157 | int safe_allocated_mases; | |
158 | int unsafe_allocated_mases; | |
159 | int interval; | |
160 | }; | |
183b9b59 | 161 | |
92825020 TP |
162 | int uwb_rsv_find_best_allocation(struct uwb_rsv *rsv, |
163 | struct uwb_mas_bm *available, | |
5b37717a SP |
164 | struct uwb_mas_bm *result); |
165 | void uwb_rsv_handle_drp_avail_change(struct uwb_rc *rc); | |
183b9b59 IPG |
166 | /* |
167 | * UWB Events & management daemon | |
168 | */ | |
169 | ||
170 | /** | |
171 | * enum uwb_event_type - types of UWB management daemon events | |
172 | * | |
173 | * The UWB management daemon (uwbd) can receive two types of events: | |
174 | * UWB_EVT_TYPE_NOTIF - notification from the radio controller. | |
175 | * UWB_EVT_TYPE_MSG - a simple message. | |
176 | */ | |
177 | enum uwb_event_type { | |
178 | UWB_EVT_TYPE_NOTIF, | |
179 | UWB_EVT_TYPE_MSG, | |
180 | }; | |
181 | ||
182 | /** | |
183 | * struct uwb_event_notif - an event for a radio controller notification | |
184 | * @size: Size of the buffer (ie: Guaranteed to contain at least | |
185 | * a full 'struct uwb_rceb') | |
186 | * @rceb: Pointer to a kmalloced() event payload | |
187 | */ | |
188 | struct uwb_event_notif { | |
189 | size_t size; | |
190 | struct uwb_rceb *rceb; | |
191 | }; | |
192 | ||
193 | /** | |
194 | * enum uwb_event_message - an event for a message for asynchronous processing | |
195 | * | |
196 | * UWB_EVT_MSG_RESET - reset the radio controller and all PAL hardware. | |
197 | */ | |
198 | enum uwb_event_message { | |
199 | UWB_EVT_MSG_RESET, | |
200 | }; | |
201 | ||
202 | /** | |
203 | * UWB Event | |
204 | * @rc: Radio controller that emitted the event (referenced) | |
205 | * @ts_jiffies: Timestamp, when was it received | |
206 | * @type: This event's type. | |
207 | */ | |
208 | struct uwb_event { | |
209 | struct list_head list_node; | |
210 | struct uwb_rc *rc; | |
211 | unsigned long ts_jiffies; | |
212 | enum uwb_event_type type; | |
213 | union { | |
214 | struct uwb_event_notif notif; | |
215 | enum uwb_event_message message; | |
216 | }; | |
217 | }; | |
218 | ||
fec1a593 SP |
219 | extern void uwbd_start(struct uwb_rc *rc); |
220 | extern void uwbd_stop(struct uwb_rc *rc); | |
183b9b59 IPG |
221 | extern struct uwb_event *uwb_event_alloc(size_t, gfp_t gfp_mask); |
222 | extern void uwbd_event_queue(struct uwb_event *); | |
223 | void uwbd_flush(struct uwb_rc *rc); | |
224 | ||
225 | /* UWB event handlers */ | |
c5995bd2 | 226 | extern int uwbd_evt_handle_rc_ie_rcv(struct uwb_event *); |
183b9b59 IPG |
227 | extern int uwbd_evt_handle_rc_beacon(struct uwb_event *); |
228 | extern int uwbd_evt_handle_rc_beacon_size(struct uwb_event *); | |
229 | extern int uwbd_evt_handle_rc_bpoie_change(struct uwb_event *); | |
230 | extern int uwbd_evt_handle_rc_bp_slot_change(struct uwb_event *); | |
231 | extern int uwbd_evt_handle_rc_drp(struct uwb_event *); | |
232 | extern int uwbd_evt_handle_rc_drp_avail(struct uwb_event *); | |
233 | ||
234 | int uwbd_msg_handle_reset(struct uwb_event *evt); | |
235 | ||
236 | ||
237 | /* | |
238 | * Address management | |
239 | */ | |
240 | int uwb_rc_dev_addr_assign(struct uwb_rc *rc); | |
241 | int uwbd_evt_handle_rc_dev_addr_conflict(struct uwb_event *evt); | |
242 | ||
243 | /* | |
244 | * UWB Beacon Cache | |
245 | * | |
246 | * Each beacon we received is kept in a cache--when we receive that | |
247 | * beacon consistently, that means there is a new device that we have | |
248 | * to add to the system. | |
249 | */ | |
250 | ||
251 | extern unsigned long beacon_timeout_ms; | |
252 | ||
183b9b59 IPG |
253 | /** |
254 | * Beacon cache entry | |
255 | * | |
256 | * @jiffies_refresh: last time a beacon was received that refreshed | |
257 | * this cache entry. | |
258 | * @uwb_dev: device connected to this beacon. This pointer is not | |
259 | * safe, you need to get it with uwb_dev_try_get() | |
260 | * | |
261 | * @hits: how many time we have seen this beacon since last time we | |
262 | * cleared it | |
263 | */ | |
264 | struct uwb_beca_e { | |
265 | struct mutex mutex; | |
266 | struct kref refcnt; | |
267 | struct list_head node; | |
268 | struct uwb_mac_addr *mac_addr; | |
269 | struct uwb_dev_addr dev_addr; | |
270 | u8 hits; | |
271 | unsigned long ts_jiffies; | |
272 | struct uwb_dev *uwb_dev; | |
273 | struct uwb_rc_evt_beacon *be; | |
274 | struct stats lqe_stats, rssi_stats; /* radio statistics */ | |
275 | }; | |
276 | struct uwb_beacon_frame; | |
277 | extern ssize_t uwb_bce_print_IEs(struct uwb_dev *, struct uwb_beca_e *, | |
278 | char *, size_t); | |
183b9b59 IPG |
279 | |
280 | extern void uwb_bce_kfree(struct kref *_bce); | |
281 | static inline void uwb_bce_get(struct uwb_beca_e *bce) | |
282 | { | |
283 | kref_get(&bce->refcnt); | |
284 | } | |
285 | static inline void uwb_bce_put(struct uwb_beca_e *bce) | |
286 | { | |
287 | kref_put(&bce->refcnt, uwb_bce_kfree); | |
288 | } | |
fec1a593 SP |
289 | extern void uwb_beca_purge(struct uwb_rc *rc); |
290 | extern void uwb_beca_release(struct uwb_rc *rc); | |
183b9b59 IPG |
291 | |
292 | struct uwb_dev *uwb_dev_get_by_devaddr(struct uwb_rc *rc, | |
293 | const struct uwb_dev_addr *devaddr); | |
294 | struct uwb_dev *uwb_dev_get_by_macaddr(struct uwb_rc *rc, | |
295 | const struct uwb_mac_addr *macaddr); | |
296 | ||
6fae35f9 DV |
297 | int uwb_radio_setup(struct uwb_rc *rc); |
298 | void uwb_radio_reset_state(struct uwb_rc *rc); | |
299 | void uwb_radio_shutdown(struct uwb_rc *rc); | |
300 | int uwb_radio_force_channel(struct uwb_rc *rc, int channel); | |
301 | ||
183b9b59 IPG |
302 | /* -- UWB Sysfs representation */ |
303 | extern struct class uwb_rc_class; | |
84887934 | 304 | extern struct bus_type uwb_bus_type; |
183b9b59 IPG |
305 | extern struct device_attribute dev_attr_mac_address; |
306 | extern struct device_attribute dev_attr_beacon; | |
307 | extern struct device_attribute dev_attr_scan; | |
308 | ||
309 | /* -- DRP Bandwidth allocator: bandwidth allocations, reservations, DRP */ | |
310 | void uwb_rsv_init(struct uwb_rc *rc); | |
311 | int uwb_rsv_setup(struct uwb_rc *rc); | |
312 | void uwb_rsv_cleanup(struct uwb_rc *rc); | |
307ba6dd | 313 | void uwb_rsv_remove_all(struct uwb_rc *rc); |
5b37717a SP |
314 | void uwb_rsv_get(struct uwb_rsv *rsv); |
315 | void uwb_rsv_put(struct uwb_rsv *rsv); | |
316 | bool uwb_rsv_has_two_drp_ies(struct uwb_rsv *rsv); | |
317 | void uwb_rsv_dump(char *text, struct uwb_rsv *rsv); | |
318 | int uwb_rsv_try_move(struct uwb_rsv *rsv, struct uwb_mas_bm *available); | |
e99e88a9 | 319 | void uwb_rsv_backoff_win_timer(struct timer_list *t); |
5b37717a SP |
320 | void uwb_rsv_backoff_win_increment(struct uwb_rc *rc); |
321 | int uwb_rsv_status(struct uwb_rsv *rsv); | |
322 | int uwb_rsv_companion_status(struct uwb_rsv *rsv); | |
183b9b59 IPG |
323 | |
324 | void uwb_rsv_set_state(struct uwb_rsv *rsv, enum uwb_rsv_state new_state); | |
325 | void uwb_rsv_remove(struct uwb_rsv *rsv); | |
326 | struct uwb_rsv *uwb_rsv_find(struct uwb_rc *rc, struct uwb_dev *src, | |
327 | struct uwb_ie_drp *drp_ie); | |
328 | void uwb_rsv_sched_update(struct uwb_rc *rc); | |
5b37717a | 329 | void uwb_rsv_queue_update(struct uwb_rc *rc); |
183b9b59 | 330 | |
183b9b59 IPG |
331 | int uwb_drp_ie_update(struct uwb_rsv *rsv); |
332 | void uwb_drp_ie_to_bm(struct uwb_mas_bm *bm, const struct uwb_ie_drp *drp_ie); | |
333 | ||
334 | void uwb_drp_avail_init(struct uwb_rc *rc); | |
5b37717a | 335 | void uwb_drp_available(struct uwb_rc *rc, struct uwb_mas_bm *avail); |
183b9b59 IPG |
336 | int uwb_drp_avail_reserve_pending(struct uwb_rc *rc, struct uwb_mas_bm *mas); |
337 | void uwb_drp_avail_reserve(struct uwb_rc *rc, struct uwb_mas_bm *mas); | |
338 | void uwb_drp_avail_release(struct uwb_rc *rc, struct uwb_mas_bm *mas); | |
339 | void uwb_drp_avail_ie_update(struct uwb_rc *rc); | |
340 | ||
341 | /* -- PAL support */ | |
342 | void uwb_rc_pal_init(struct uwb_rc *rc); | |
343 | ||
344 | /* -- Misc */ | |
345 | ||
346 | extern ssize_t uwb_mac_frame_hdr_print(char *, size_t, | |
347 | const struct uwb_mac_frame_hdr *); | |
348 | ||
349 | /* -- Debug interface */ | |
350 | void uwb_dbg_init(void); | |
351 | void uwb_dbg_exit(void); | |
352 | void uwb_dbg_add_rc(struct uwb_rc *rc); | |
353 | void uwb_dbg_del_rc(struct uwb_rc *rc); | |
dcc7461e | 354 | struct dentry *uwb_dbg_create_pal_dir(struct uwb_pal *pal); |
183b9b59 IPG |
355 | |
356 | static inline void uwb_dev_lock(struct uwb_dev *uwb_dev) | |
357 | { | |
8e9394ce | 358 | device_lock(&uwb_dev->dev); |
183b9b59 IPG |
359 | } |
360 | ||
361 | static inline void uwb_dev_unlock(struct uwb_dev *uwb_dev) | |
362 | { | |
8e9394ce | 363 | device_unlock(&uwb_dev->dev); |
183b9b59 IPG |
364 | } |
365 | ||
366 | #endif /* #ifndef __UWB_INTERNAL_H__ */ |