blob: a7494bf100815279be8420f435786e6d513651fc [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{
58 uwb_dev_put(&rc->uwb_dev);
59}
60
61extern int uwb_rc_reset(struct uwb_rc *rc);
62extern int uwb_rc_beacon(struct uwb_rc *rc,
63 int channel, unsigned bpst_offset);
64extern int uwb_rc_scan(struct uwb_rc *rc,
65 unsigned channel, enum uwb_scan_type type,
66 unsigned bpst_offset);
67extern int uwb_rc_send_all_drp_ie(struct uwb_rc *rc);
David Vrabel1cde7f62008-10-27 16:48:09 +000068
69void uwb_rc_ie_init(struct uwb_rc *);
70int uwb_rc_ie_setup(struct uwb_rc *);
71void uwb_rc_ie_release(struct uwb_rc *);
72int uwb_ie_dump_hex(const struct uwb_ie_hdr *ies, size_t len,
73 char *buf, size_t size);
74int uwb_rc_set_ie(struct uwb_rc *, struct uwb_rc_cmd_set_ie *);
75
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +010076
77extern const char *uwb_rc_strerror(unsigned code);
78
79/*
80 * Time to wait for a response to an RC command.
81 *
82 * Some commands can take a long time to response. e.g., START_BEACON
83 * may scan for several superframes before joining an existing beacon
84 * group and this can take around 600 ms.
85 */
86#define UWB_RC_CMD_TIMEOUT_MS 1000 /* ms */
87
88/*
89 * Notification/Event Handlers
90 */
91
92struct uwb_rc_neh;
93
Stefano Panella5b377172008-12-12 13:00:06 +000094extern int uwb_rc_cmd_async(struct uwb_rc *rc, const char *cmd_name,
95 struct uwb_rccb *cmd, size_t cmd_size,
96 u8 expected_type, u16 expected_event,
97 uwb_rc_cmd_cb_f cb, void *arg);
98
99
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100100void uwb_rc_neh_create(struct uwb_rc *rc);
101void uwb_rc_neh_destroy(struct uwb_rc *rc);
102
103struct uwb_rc_neh *uwb_rc_neh_add(struct uwb_rc *rc, struct uwb_rccb *cmd,
104 u8 expected_type, u16 expected_event,
105 uwb_rc_cmd_cb_f cb, void *arg);
106void uwb_rc_neh_rm(struct uwb_rc *rc, struct uwb_rc_neh *neh);
107void uwb_rc_neh_arm(struct uwb_rc *rc, struct uwb_rc_neh *neh);
108void uwb_rc_neh_put(struct uwb_rc_neh *neh);
109
110/* Event size tables */
111extern int uwb_est_create(void);
112extern void uwb_est_destroy(void);
113
Stefano Panella5b377172008-12-12 13:00:06 +0000114/*
115 * UWB conflicting alien reservations
116 */
117struct uwb_cnflt_alien {
118 struct uwb_rc *rc;
119 struct list_head rc_node;
120 struct uwb_mas_bm mas;
121 struct timer_list timer;
122 struct work_struct cnflt_update_work;
123};
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100124
Stefano Panella5b377172008-12-12 13:00:06 +0000125enum uwb_uwb_rsv_alloc_result {
126 UWB_RSV_ALLOC_FOUND = 0,
127 UWB_RSV_ALLOC_NOT_FOUND,
128};
129
130enum uwb_rsv_mas_status {
131 UWB_RSV_MAS_NOT_AVAIL = 1,
132 UWB_RSV_MAS_SAFE,
133 UWB_RSV_MAS_UNSAFE,
134};
135
136struct uwb_rsv_col_set_info {
137 unsigned char start_col;
138 unsigned char interval;
139 unsigned char safe_mas_per_col;
140 unsigned char unsafe_mas_per_col;
141};
142
143struct uwb_rsv_col_info {
144 unsigned char max_avail_safe;
145 unsigned char max_avail_unsafe;
146 unsigned char highest_mas[UWB_MAS_PER_ZONE];
147 struct uwb_rsv_col_set_info csi;
148};
149
150struct uwb_rsv_row_info {
151 unsigned char avail[UWB_MAS_PER_ZONE];
152 unsigned char free_rows;
153 unsigned char used_rows;
154};
155
156/*
157 * UWB find allocation
158 */
159struct uwb_rsv_alloc_info {
160 unsigned char bm[UWB_MAS_PER_ZONE * UWB_NUM_ZONES];
161 struct uwb_rsv_col_info ci[UWB_NUM_ZONES];
162 struct uwb_rsv_row_info ri;
163 struct uwb_mas_bm *not_available;
164 struct uwb_mas_bm *result;
165 int min_mas;
166 int max_mas;
167 int max_interval;
168 int total_allocated_mases;
169 int safe_allocated_mases;
170 int unsafe_allocated_mases;
171 int interval;
172};
173
174int uwb_rsv_find_best_allocation(struct uwb_rsv *rsv, struct uwb_mas_bm *available,
175 struct uwb_mas_bm *result);
176void uwb_rsv_handle_drp_avail_change(struct uwb_rc *rc);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100177/*
178 * UWB Events & management daemon
179 */
180
181/**
182 * enum uwb_event_type - types of UWB management daemon events
183 *
184 * The UWB management daemon (uwbd) can receive two types of events:
185 * UWB_EVT_TYPE_NOTIF - notification from the radio controller.
186 * UWB_EVT_TYPE_MSG - a simple message.
187 */
188enum uwb_event_type {
189 UWB_EVT_TYPE_NOTIF,
190 UWB_EVT_TYPE_MSG,
191};
192
193/**
194 * struct uwb_event_notif - an event for a radio controller notification
195 * @size: Size of the buffer (ie: Guaranteed to contain at least
196 * a full 'struct uwb_rceb')
197 * @rceb: Pointer to a kmalloced() event payload
198 */
199struct uwb_event_notif {
200 size_t size;
201 struct uwb_rceb *rceb;
202};
203
204/**
205 * enum uwb_event_message - an event for a message for asynchronous processing
206 *
207 * UWB_EVT_MSG_RESET - reset the radio controller and all PAL hardware.
208 */
209enum uwb_event_message {
210 UWB_EVT_MSG_RESET,
211};
212
213/**
214 * UWB Event
215 * @rc: Radio controller that emitted the event (referenced)
216 * @ts_jiffies: Timestamp, when was it received
217 * @type: This event's type.
218 */
219struct uwb_event {
220 struct list_head list_node;
221 struct uwb_rc *rc;
222 unsigned long ts_jiffies;
223 enum uwb_event_type type;
224 union {
225 struct uwb_event_notif notif;
226 enum uwb_event_message message;
227 };
228};
229
Stefano Panellafec1a592008-11-04 15:39:08 +0000230extern void uwbd_start(struct uwb_rc *rc);
231extern void uwbd_stop(struct uwb_rc *rc);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100232extern struct uwb_event *uwb_event_alloc(size_t, gfp_t gfp_mask);
233extern void uwbd_event_queue(struct uwb_event *);
234void uwbd_flush(struct uwb_rc *rc);
235
236/* UWB event handlers */
Stefano Panellac5995bd2008-11-04 14:06:31 +0000237extern int uwbd_evt_handle_rc_ie_rcv(struct uwb_event *);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100238extern int uwbd_evt_handle_rc_beacon(struct uwb_event *);
239extern int uwbd_evt_handle_rc_beacon_size(struct uwb_event *);
240extern int uwbd_evt_handle_rc_bpoie_change(struct uwb_event *);
241extern int uwbd_evt_handle_rc_bp_slot_change(struct uwb_event *);
242extern int uwbd_evt_handle_rc_drp(struct uwb_event *);
243extern int uwbd_evt_handle_rc_drp_avail(struct uwb_event *);
244
245int uwbd_msg_handle_reset(struct uwb_event *evt);
246
247
248/*
249 * Address management
250 */
251int uwb_rc_dev_addr_assign(struct uwb_rc *rc);
252int uwbd_evt_handle_rc_dev_addr_conflict(struct uwb_event *evt);
253
254/*
255 * UWB Beacon Cache
256 *
257 * Each beacon we received is kept in a cache--when we receive that
258 * beacon consistently, that means there is a new device that we have
259 * to add to the system.
260 */
261
262extern unsigned long beacon_timeout_ms;
263
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100264/**
265 * Beacon cache entry
266 *
267 * @jiffies_refresh: last time a beacon was received that refreshed
268 * this cache entry.
269 * @uwb_dev: device connected to this beacon. This pointer is not
270 * safe, you need to get it with uwb_dev_try_get()
271 *
272 * @hits: how many time we have seen this beacon since last time we
273 * cleared it
274 */
275struct uwb_beca_e {
276 struct mutex mutex;
277 struct kref refcnt;
278 struct list_head node;
279 struct uwb_mac_addr *mac_addr;
280 struct uwb_dev_addr dev_addr;
281 u8 hits;
282 unsigned long ts_jiffies;
283 struct uwb_dev *uwb_dev;
284 struct uwb_rc_evt_beacon *be;
285 struct stats lqe_stats, rssi_stats; /* radio statistics */
286};
287struct uwb_beacon_frame;
288extern ssize_t uwb_bce_print_IEs(struct uwb_dev *, struct uwb_beca_e *,
289 char *, size_t);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100290
291extern void uwb_bce_kfree(struct kref *_bce);
292static inline void uwb_bce_get(struct uwb_beca_e *bce)
293{
294 kref_get(&bce->refcnt);
295}
296static inline void uwb_bce_put(struct uwb_beca_e *bce)
297{
298 kref_put(&bce->refcnt, uwb_bce_kfree);
299}
Stefano Panellafec1a592008-11-04 15:39:08 +0000300extern void uwb_beca_purge(struct uwb_rc *rc);
301extern void uwb_beca_release(struct uwb_rc *rc);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100302
303struct uwb_dev *uwb_dev_get_by_devaddr(struct uwb_rc *rc,
304 const struct uwb_dev_addr *devaddr);
305struct uwb_dev *uwb_dev_get_by_macaddr(struct uwb_rc *rc,
306 const struct uwb_mac_addr *macaddr);
307
David Vrabel6fae35f2008-11-17 15:53:42 +0000308int uwb_radio_setup(struct uwb_rc *rc);
309void uwb_radio_reset_state(struct uwb_rc *rc);
310void uwb_radio_shutdown(struct uwb_rc *rc);
311int uwb_radio_force_channel(struct uwb_rc *rc, int channel);
312
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100313/* -- UWB Sysfs representation */
314extern struct class uwb_rc_class;
315extern struct device_attribute dev_attr_mac_address;
316extern struct device_attribute dev_attr_beacon;
317extern struct device_attribute dev_attr_scan;
318
319/* -- DRP Bandwidth allocator: bandwidth allocations, reservations, DRP */
320void uwb_rsv_init(struct uwb_rc *rc);
321int uwb_rsv_setup(struct uwb_rc *rc);
322void uwb_rsv_cleanup(struct uwb_rc *rc);
David Vrabel307ba6d2008-11-07 17:37:33 +0000323void uwb_rsv_remove_all(struct uwb_rc *rc);
Stefano Panella5b377172008-12-12 13:00:06 +0000324void uwb_rsv_get(struct uwb_rsv *rsv);
325void uwb_rsv_put(struct uwb_rsv *rsv);
326bool uwb_rsv_has_two_drp_ies(struct uwb_rsv *rsv);
327void uwb_rsv_dump(char *text, struct uwb_rsv *rsv);
328int uwb_rsv_try_move(struct uwb_rsv *rsv, struct uwb_mas_bm *available);
329void uwb_rsv_backoff_win_timer(unsigned long arg);
330void uwb_rsv_backoff_win_increment(struct uwb_rc *rc);
331int uwb_rsv_status(struct uwb_rsv *rsv);
332int uwb_rsv_companion_status(struct uwb_rsv *rsv);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100333
334void uwb_rsv_set_state(struct uwb_rsv *rsv, enum uwb_rsv_state new_state);
335void uwb_rsv_remove(struct uwb_rsv *rsv);
336struct uwb_rsv *uwb_rsv_find(struct uwb_rc *rc, struct uwb_dev *src,
337 struct uwb_ie_drp *drp_ie);
338void uwb_rsv_sched_update(struct uwb_rc *rc);
Stefano Panella5b377172008-12-12 13:00:06 +0000339void uwb_rsv_queue_update(struct uwb_rc *rc);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100340
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100341int uwb_drp_ie_update(struct uwb_rsv *rsv);
342void uwb_drp_ie_to_bm(struct uwb_mas_bm *bm, const struct uwb_ie_drp *drp_ie);
343
344void uwb_drp_avail_init(struct uwb_rc *rc);
Stefano Panella5b377172008-12-12 13:00:06 +0000345void uwb_drp_available(struct uwb_rc *rc, struct uwb_mas_bm *avail);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100346int uwb_drp_avail_reserve_pending(struct uwb_rc *rc, struct uwb_mas_bm *mas);
347void uwb_drp_avail_reserve(struct uwb_rc *rc, struct uwb_mas_bm *mas);
348void uwb_drp_avail_release(struct uwb_rc *rc, struct uwb_mas_bm *mas);
349void uwb_drp_avail_ie_update(struct uwb_rc *rc);
350
351/* -- PAL support */
352void uwb_rc_pal_init(struct uwb_rc *rc);
353
354/* -- Misc */
355
356extern ssize_t uwb_mac_frame_hdr_print(char *, size_t,
357 const struct uwb_mac_frame_hdr *);
358
359/* -- Debug interface */
360void uwb_dbg_init(void);
361void uwb_dbg_exit(void);
362void uwb_dbg_add_rc(struct uwb_rc *rc);
363void uwb_dbg_del_rc(struct uwb_rc *rc);
David Vrabeldcc74612008-11-26 13:36:59 +0000364struct dentry *uwb_dbg_create_pal_dir(struct uwb_pal *pal);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100365
366static inline void uwb_dev_lock(struct uwb_dev *uwb_dev)
367{
Greg Kroah-Hartman8e9394c2010-02-17 10:57:05 -0800368 device_lock(&uwb_dev->dev);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100369}
370
371static inline void uwb_dev_unlock(struct uwb_dev *uwb_dev)
372{
Greg Kroah-Hartman8e9394c2010-02-17 10:57:05 -0800373 device_unlock(&uwb_dev->dev);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100374}
375
376#endif /* #ifndef __UWB_INTERNAL_H__ */