blob: 91326ce093a78fd43572f6c6ad39581c24bb241c [file] [log] [blame]
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +01001/*
2 * Ultra Wide Band
3 * UWB internal API
4 *
5 * Copyright (C) 2005-2006 Intel Corporation
6 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 *
22 * This contains most of the internal API for UWB. This is stuff used
23 * across the stack that of course, is of no interest to the rest.
24 *
25 * Some parts might end up going public (like uwb_rc_*())...
26 */
27
28#ifndef __UWB_INTERNAL_H__
29#define __UWB_INTERNAL_H__
30
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +010031#include <linux/kernel.h>
32#include <linux/device.h>
33#include <linux/uwb.h>
34#include <linux/mutex.h>
35
36struct uwb_beca_e;
37
38/* General device API */
39extern void uwb_dev_init(struct uwb_dev *uwb_dev);
40extern int __uwb_dev_offair(struct uwb_dev *, struct uwb_rc *);
41extern int uwb_dev_add(struct uwb_dev *uwb_dev, struct device *parent_dev,
42 struct uwb_rc *parent_rc);
43extern void uwb_dev_rm(struct uwb_dev *uwb_dev);
44extern void uwbd_dev_onair(struct uwb_rc *, struct uwb_beca_e *);
45extern void uwbd_dev_offair(struct uwb_beca_e *);
46void uwb_notify(struct uwb_rc *rc, struct uwb_dev *uwb_dev, enum uwb_notifs event);
47
48/* General UWB Radio Controller Internal API */
49extern struct uwb_rc *__uwb_rc_try_get(struct uwb_rc *);
50static inline struct uwb_rc *__uwb_rc_get(struct uwb_rc *rc)
51{
52 uwb_dev_get(&rc->uwb_dev);
53 return rc;
54}
55
56static inline void __uwb_rc_put(struct uwb_rc *rc)
57{
Thomas Pugliesea8995752013-06-24 14:26:35 -050058 if (rc)
59 uwb_dev_put(&rc->uwb_dev);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +010060}
61
62extern int uwb_rc_reset(struct uwb_rc *rc);
63extern int uwb_rc_beacon(struct uwb_rc *rc,
64 int channel, unsigned bpst_offset);
65extern int uwb_rc_scan(struct uwb_rc *rc,
66 unsigned channel, enum uwb_scan_type type,
67 unsigned bpst_offset);
68extern int uwb_rc_send_all_drp_ie(struct uwb_rc *rc);
David Vrabel1cde7f62008-10-27 16:48:09 +000069
70void uwb_rc_ie_init(struct uwb_rc *);
71int uwb_rc_ie_setup(struct uwb_rc *);
72void uwb_rc_ie_release(struct uwb_rc *);
73int uwb_ie_dump_hex(const struct uwb_ie_hdr *ies, size_t len,
74 char *buf, size_t size);
75int uwb_rc_set_ie(struct uwb_rc *, struct uwb_rc_cmd_set_ie *);
76
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +010077
78extern const char *uwb_rc_strerror(unsigned code);
79
80/*
81 * Time to wait for a response to an RC command.
82 *
83 * Some commands can take a long time to response. e.g., START_BEACON
84 * may scan for several superframes before joining an existing beacon
85 * group and this can take around 600 ms.
86 */
87#define UWB_RC_CMD_TIMEOUT_MS 1000 /* ms */
88
89/*
90 * Notification/Event Handlers
91 */
92
93struct uwb_rc_neh;
94
Stefano Panella5b377172008-12-12 13:00:06 +000095extern int uwb_rc_cmd_async(struct uwb_rc *rc, const char *cmd_name,
96 struct uwb_rccb *cmd, size_t cmd_size,
97 u8 expected_type, u16 expected_event,
98 uwb_rc_cmd_cb_f cb, void *arg);
99
100
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100101void uwb_rc_neh_create(struct uwb_rc *rc);
102void uwb_rc_neh_destroy(struct uwb_rc *rc);
103
104struct uwb_rc_neh *uwb_rc_neh_add(struct uwb_rc *rc, struct uwb_rccb *cmd,
105 u8 expected_type, u16 expected_event,
106 uwb_rc_cmd_cb_f cb, void *arg);
107void uwb_rc_neh_rm(struct uwb_rc *rc, struct uwb_rc_neh *neh);
108void uwb_rc_neh_arm(struct uwb_rc *rc, struct uwb_rc_neh *neh);
109void uwb_rc_neh_put(struct uwb_rc_neh *neh);
110
111/* Event size tables */
112extern int uwb_est_create(void);
113extern void uwb_est_destroy(void);
114
Stefano Panella5b377172008-12-12 13:00:06 +0000115/*
116 * UWB conflicting alien reservations
117 */
118struct uwb_cnflt_alien {
119 struct uwb_rc *rc;
120 struct list_head rc_node;
121 struct uwb_mas_bm mas;
122 struct timer_list timer;
123 struct work_struct cnflt_update_work;
124};
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100125
Stefano Panella5b377172008-12-12 13:00:06 +0000126enum uwb_uwb_rsv_alloc_result {
127 UWB_RSV_ALLOC_FOUND = 0,
128 UWB_RSV_ALLOC_NOT_FOUND,
129};
130
131enum uwb_rsv_mas_status {
132 UWB_RSV_MAS_NOT_AVAIL = 1,
133 UWB_RSV_MAS_SAFE,
134 UWB_RSV_MAS_UNSAFE,
135};
136
137struct uwb_rsv_col_set_info {
138 unsigned char start_col;
139 unsigned char interval;
140 unsigned char safe_mas_per_col;
141 unsigned char unsafe_mas_per_col;
142};
143
144struct uwb_rsv_col_info {
145 unsigned char max_avail_safe;
146 unsigned char max_avail_unsafe;
147 unsigned char highest_mas[UWB_MAS_PER_ZONE];
148 struct uwb_rsv_col_set_info csi;
149};
150
151struct uwb_rsv_row_info {
152 unsigned char avail[UWB_MAS_PER_ZONE];
153 unsigned char free_rows;
154 unsigned char used_rows;
155};
156
157/*
158 * UWB find allocation
159 */
160struct uwb_rsv_alloc_info {
161 unsigned char bm[UWB_MAS_PER_ZONE * UWB_NUM_ZONES];
162 struct uwb_rsv_col_info ci[UWB_NUM_ZONES];
163 struct uwb_rsv_row_info ri;
164 struct uwb_mas_bm *not_available;
165 struct uwb_mas_bm *result;
166 int min_mas;
167 int max_mas;
168 int max_interval;
169 int total_allocated_mases;
170 int safe_allocated_mases;
171 int unsafe_allocated_mases;
172 int interval;
173};
174
Thomas Pugliese92825022014-09-16 15:40:02 -0500175int uwb_rsv_find_best_allocation(struct uwb_rsv *rsv,
176 struct uwb_mas_bm *available,
Stefano Panella5b377172008-12-12 13:00:06 +0000177 struct uwb_mas_bm *result);
178void uwb_rsv_handle_drp_avail_change(struct uwb_rc *rc);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100179/*
180 * UWB Events & management daemon
181 */
182
183/**
184 * enum uwb_event_type - types of UWB management daemon events
185 *
186 * The UWB management daemon (uwbd) can receive two types of events:
187 * UWB_EVT_TYPE_NOTIF - notification from the radio controller.
188 * UWB_EVT_TYPE_MSG - a simple message.
189 */
190enum uwb_event_type {
191 UWB_EVT_TYPE_NOTIF,
192 UWB_EVT_TYPE_MSG,
193};
194
195/**
196 * struct uwb_event_notif - an event for a radio controller notification
197 * @size: Size of the buffer (ie: Guaranteed to contain at least
198 * a full 'struct uwb_rceb')
199 * @rceb: Pointer to a kmalloced() event payload
200 */
201struct uwb_event_notif {
202 size_t size;
203 struct uwb_rceb *rceb;
204};
205
206/**
207 * enum uwb_event_message - an event for a message for asynchronous processing
208 *
209 * UWB_EVT_MSG_RESET - reset the radio controller and all PAL hardware.
210 */
211enum uwb_event_message {
212 UWB_EVT_MSG_RESET,
213};
214
215/**
216 * UWB Event
217 * @rc: Radio controller that emitted the event (referenced)
218 * @ts_jiffies: Timestamp, when was it received
219 * @type: This event's type.
220 */
221struct uwb_event {
222 struct list_head list_node;
223 struct uwb_rc *rc;
224 unsigned long ts_jiffies;
225 enum uwb_event_type type;
226 union {
227 struct uwb_event_notif notif;
228 enum uwb_event_message message;
229 };
230};
231
Stefano Panellafec1a592008-11-04 15:39:08 +0000232extern void uwbd_start(struct uwb_rc *rc);
233extern void uwbd_stop(struct uwb_rc *rc);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100234extern struct uwb_event *uwb_event_alloc(size_t, gfp_t gfp_mask);
235extern void uwbd_event_queue(struct uwb_event *);
236void uwbd_flush(struct uwb_rc *rc);
237
238/* UWB event handlers */
Stefano Panellac5995bd2008-11-04 14:06:31 +0000239extern int uwbd_evt_handle_rc_ie_rcv(struct uwb_event *);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100240extern int uwbd_evt_handle_rc_beacon(struct uwb_event *);
241extern int uwbd_evt_handle_rc_beacon_size(struct uwb_event *);
242extern int uwbd_evt_handle_rc_bpoie_change(struct uwb_event *);
243extern int uwbd_evt_handle_rc_bp_slot_change(struct uwb_event *);
244extern int uwbd_evt_handle_rc_drp(struct uwb_event *);
245extern int uwbd_evt_handle_rc_drp_avail(struct uwb_event *);
246
247int uwbd_msg_handle_reset(struct uwb_event *evt);
248
249
250/*
251 * Address management
252 */
253int uwb_rc_dev_addr_assign(struct uwb_rc *rc);
254int uwbd_evt_handle_rc_dev_addr_conflict(struct uwb_event *evt);
255
256/*
257 * UWB Beacon Cache
258 *
259 * Each beacon we received is kept in a cache--when we receive that
260 * beacon consistently, that means there is a new device that we have
261 * to add to the system.
262 */
263
264extern unsigned long beacon_timeout_ms;
265
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100266/**
267 * Beacon cache entry
268 *
269 * @jiffies_refresh: last time a beacon was received that refreshed
270 * this cache entry.
271 * @uwb_dev: device connected to this beacon. This pointer is not
272 * safe, you need to get it with uwb_dev_try_get()
273 *
274 * @hits: how many time we have seen this beacon since last time we
275 * cleared it
276 */
277struct uwb_beca_e {
278 struct mutex mutex;
279 struct kref refcnt;
280 struct list_head node;
281 struct uwb_mac_addr *mac_addr;
282 struct uwb_dev_addr dev_addr;
283 u8 hits;
284 unsigned long ts_jiffies;
285 struct uwb_dev *uwb_dev;
286 struct uwb_rc_evt_beacon *be;
287 struct stats lqe_stats, rssi_stats; /* radio statistics */
288};
289struct uwb_beacon_frame;
290extern ssize_t uwb_bce_print_IEs(struct uwb_dev *, struct uwb_beca_e *,
291 char *, size_t);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100292
293extern void uwb_bce_kfree(struct kref *_bce);
294static inline void uwb_bce_get(struct uwb_beca_e *bce)
295{
296 kref_get(&bce->refcnt);
297}
298static inline void uwb_bce_put(struct uwb_beca_e *bce)
299{
300 kref_put(&bce->refcnt, uwb_bce_kfree);
301}
Stefano Panellafec1a592008-11-04 15:39:08 +0000302extern void uwb_beca_purge(struct uwb_rc *rc);
303extern void uwb_beca_release(struct uwb_rc *rc);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100304
305struct uwb_dev *uwb_dev_get_by_devaddr(struct uwb_rc *rc,
306 const struct uwb_dev_addr *devaddr);
307struct uwb_dev *uwb_dev_get_by_macaddr(struct uwb_rc *rc,
308 const struct uwb_mac_addr *macaddr);
309
David Vrabel6fae35f2008-11-17 15:53:42 +0000310int uwb_radio_setup(struct uwb_rc *rc);
311void uwb_radio_reset_state(struct uwb_rc *rc);
312void uwb_radio_shutdown(struct uwb_rc *rc);
313int uwb_radio_force_channel(struct uwb_rc *rc, int channel);
314
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100315/* -- UWB Sysfs representation */
316extern struct class uwb_rc_class;
Thomas Pugliese84887932014-09-16 15:53:08 -0500317extern struct bus_type uwb_bus_type;
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100318extern struct device_attribute dev_attr_mac_address;
319extern struct device_attribute dev_attr_beacon;
320extern struct device_attribute dev_attr_scan;
321
322/* -- DRP Bandwidth allocator: bandwidth allocations, reservations, DRP */
323void uwb_rsv_init(struct uwb_rc *rc);
324int uwb_rsv_setup(struct uwb_rc *rc);
325void uwb_rsv_cleanup(struct uwb_rc *rc);
David Vrabel307ba6d2008-11-07 17:37:33 +0000326void uwb_rsv_remove_all(struct uwb_rc *rc);
Stefano Panella5b377172008-12-12 13:00:06 +0000327void uwb_rsv_get(struct uwb_rsv *rsv);
328void uwb_rsv_put(struct uwb_rsv *rsv);
329bool uwb_rsv_has_two_drp_ies(struct uwb_rsv *rsv);
330void uwb_rsv_dump(char *text, struct uwb_rsv *rsv);
331int uwb_rsv_try_move(struct uwb_rsv *rsv, struct uwb_mas_bm *available);
Kees Cooke99e88a2017-10-16 14:43:17 -0700332void uwb_rsv_backoff_win_timer(struct timer_list *t);
Stefano Panella5b377172008-12-12 13:00:06 +0000333void uwb_rsv_backoff_win_increment(struct uwb_rc *rc);
334int uwb_rsv_status(struct uwb_rsv *rsv);
335int uwb_rsv_companion_status(struct uwb_rsv *rsv);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100336
337void uwb_rsv_set_state(struct uwb_rsv *rsv, enum uwb_rsv_state new_state);
338void uwb_rsv_remove(struct uwb_rsv *rsv);
339struct uwb_rsv *uwb_rsv_find(struct uwb_rc *rc, struct uwb_dev *src,
340 struct uwb_ie_drp *drp_ie);
341void uwb_rsv_sched_update(struct uwb_rc *rc);
Stefano Panella5b377172008-12-12 13:00:06 +0000342void uwb_rsv_queue_update(struct uwb_rc *rc);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100343
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100344int uwb_drp_ie_update(struct uwb_rsv *rsv);
345void uwb_drp_ie_to_bm(struct uwb_mas_bm *bm, const struct uwb_ie_drp *drp_ie);
346
347void uwb_drp_avail_init(struct uwb_rc *rc);
Stefano Panella5b377172008-12-12 13:00:06 +0000348void uwb_drp_available(struct uwb_rc *rc, struct uwb_mas_bm *avail);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100349int uwb_drp_avail_reserve_pending(struct uwb_rc *rc, struct uwb_mas_bm *mas);
350void uwb_drp_avail_reserve(struct uwb_rc *rc, struct uwb_mas_bm *mas);
351void uwb_drp_avail_release(struct uwb_rc *rc, struct uwb_mas_bm *mas);
352void uwb_drp_avail_ie_update(struct uwb_rc *rc);
353
354/* -- PAL support */
355void uwb_rc_pal_init(struct uwb_rc *rc);
356
357/* -- Misc */
358
359extern ssize_t uwb_mac_frame_hdr_print(char *, size_t,
360 const struct uwb_mac_frame_hdr *);
361
362/* -- Debug interface */
363void uwb_dbg_init(void);
364void uwb_dbg_exit(void);
365void uwb_dbg_add_rc(struct uwb_rc *rc);
366void uwb_dbg_del_rc(struct uwb_rc *rc);
David Vrabeldcc74612008-11-26 13:36:59 +0000367struct dentry *uwb_dbg_create_pal_dir(struct uwb_pal *pal);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100368
369static inline void uwb_dev_lock(struct uwb_dev *uwb_dev)
370{
Greg Kroah-Hartman8e9394c2010-02-17 10:57:05 -0800371 device_lock(&uwb_dev->dev);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100372}
373
374static inline void uwb_dev_unlock(struct uwb_dev *uwb_dev)
375{
Greg Kroah-Hartman8e9394c2010-02-17 10:57:05 -0800376 device_unlock(&uwb_dev->dev);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100377}
378
379#endif /* #ifndef __UWB_INTERNAL_H__ */