1 /* SPDX-License-Identifier: GPL-2.0-only */
6 * Copyright (C) 2005-2006 Intel Corporation
7 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
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.
12 * Some parts might end up going public (like uwb_rc_*())...
15 #ifndef __UWB_INTERNAL_H__
16 #define __UWB_INTERNAL_H__
18 #include <linux/kernel.h>
19 #include <linux/device.h>
20 #include <linux/mutex.h>
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
);
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
)
39 uwb_dev_get(&rc
->uwb_dev
);
43 static inline void __uwb_rc_put(struct uwb_rc
*rc
)
46 uwb_dev_put(&rc
->uwb_dev
);
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
);
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
*);
65 extern const char *uwb_rc_strerror(unsigned code
);
68 * Time to wait for a response to an RC command.
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.
74 #define UWB_RC_CMD_TIMEOUT_MS 1000 /* ms */
77 * Notification/Event Handlers
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
);
88 void uwb_rc_neh_create(struct uwb_rc
*rc
);
89 void uwb_rc_neh_destroy(struct uwb_rc
*rc
);
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
);
98 /* Event size tables */
99 extern int uwb_est_create(void);
100 extern void uwb_est_destroy(void);
103 * UWB conflicting alien reservations
105 struct uwb_cnflt_alien
{
107 struct list_head rc_node
;
108 struct uwb_mas_bm mas
;
109 struct timer_list timer
;
110 struct work_struct cnflt_update_work
;
113 enum uwb_uwb_rsv_alloc_result
{
114 UWB_RSV_ALLOC_FOUND
= 0,
115 UWB_RSV_ALLOC_NOT_FOUND
,
118 enum uwb_rsv_mas_status
{
119 UWB_RSV_MAS_NOT_AVAIL
= 1,
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
;
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
;
138 struct uwb_rsv_row_info
{
139 unsigned char avail
[UWB_MAS_PER_ZONE
];
140 unsigned char free_rows
;
141 unsigned char used_rows
;
145 * UWB find allocation
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
;
156 int total_allocated_mases
;
157 int safe_allocated_mases
;
158 int unsafe_allocated_mases
;
162 int uwb_rsv_find_best_allocation(struct uwb_rsv
*rsv
,
163 struct uwb_mas_bm
*available
,
164 struct uwb_mas_bm
*result
);
165 void uwb_rsv_handle_drp_avail_change(struct uwb_rc
*rc
);
167 * UWB Events & management daemon
171 * enum uwb_event_type - types of UWB management daemon events
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.
177 enum uwb_event_type
{
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
188 struct uwb_event_notif
{
190 struct uwb_rceb
*rceb
;
194 * enum uwb_event_message - an event for a message for asynchronous processing
196 * UWB_EVT_MSG_RESET - reset the radio controller and all PAL hardware.
198 enum uwb_event_message
{
204 * @rc: Radio controller that emitted the event (referenced)
205 * @ts_jiffies: Timestamp, when was it received
206 * @type: This event's type.
209 struct list_head list_node
;
211 unsigned long ts_jiffies
;
212 enum uwb_event_type type
;
214 struct uwb_event_notif notif
;
215 enum uwb_event_message message
;
219 extern void uwbd_start(struct uwb_rc
*rc
);
220 extern void uwbd_stop(struct uwb_rc
*rc
);
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
);
225 /* UWB event handlers */
226 extern int uwbd_evt_handle_rc_ie_rcv(struct uwb_event
*);
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
*);
234 int uwbd_msg_handle_reset(struct uwb_event
*evt
);
240 int uwb_rc_dev_addr_assign(struct uwb_rc
*rc
);
241 int uwbd_evt_handle_rc_dev_addr_conflict(struct uwb_event
*evt
);
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.
251 extern unsigned long beacon_timeout_ms
;
256 * @jiffies_refresh: last time a beacon was received that refreshed
258 * @uwb_dev: device connected to this beacon. This pointer is not
259 * safe, you need to get it with uwb_dev_try_get()
261 * @hits: how many time we have seen this beacon since last time we
267 struct list_head node
;
268 struct uwb_mac_addr
*mac_addr
;
269 struct uwb_dev_addr dev_addr
;
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 */
276 struct uwb_beacon_frame
;
277 extern ssize_t
uwb_bce_print_IEs(struct uwb_dev
*, struct uwb_beca_e
*,
280 extern void uwb_bce_kfree(struct kref
*_bce
);
281 static inline void uwb_bce_get(struct uwb_beca_e
*bce
)
283 kref_get(&bce
->refcnt
);
285 static inline void uwb_bce_put(struct uwb_beca_e
*bce
)
287 kref_put(&bce
->refcnt
, uwb_bce_kfree
);
289 extern void uwb_beca_purge(struct uwb_rc
*rc
);
290 extern void uwb_beca_release(struct uwb_rc
*rc
);
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
);
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
);
302 /* -- UWB Sysfs representation */
303 extern struct class uwb_rc_class
;
304 extern struct bus_type uwb_bus_type
;
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
;
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
);
313 void uwb_rsv_remove_all(struct uwb_rc
*rc
);
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
);
319 void uwb_rsv_backoff_win_timer(struct timer_list
*t
);
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
);
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
);
329 void uwb_rsv_queue_update(struct uwb_rc
*rc
);
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
);
334 void uwb_drp_avail_init(struct uwb_rc
*rc
);
335 void uwb_drp_available(struct uwb_rc
*rc
, struct uwb_mas_bm
*avail
);
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
);
342 void uwb_rc_pal_init(struct uwb_rc
*rc
);
346 extern ssize_t
uwb_mac_frame_hdr_print(char *, size_t,
347 const struct uwb_mac_frame_hdr
*);
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
);
354 struct dentry
*uwb_dbg_create_pal_dir(struct uwb_pal
*pal
);
356 static inline void uwb_dev_lock(struct uwb_dev
*uwb_dev
)
358 device_lock(&uwb_dev
->dev
);
361 static inline void uwb_dev_unlock(struct uwb_dev
*uwb_dev
)
363 device_unlock(&uwb_dev
->dev
);
366 #endif /* #ifndef __UWB_INTERNAL_H__ */