blob: f0f21f406bf0039bade335d1810e4e9a43fcd1fe [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
31#include <linux/version.h>
32#include <linux/kernel.h>
33#include <linux/device.h>
34#include <linux/uwb.h>
35#include <linux/mutex.h>
36
37struct uwb_beca_e;
38
39/* General device API */
40extern void uwb_dev_init(struct uwb_dev *uwb_dev);
41extern int __uwb_dev_offair(struct uwb_dev *, struct uwb_rc *);
42extern int uwb_dev_add(struct uwb_dev *uwb_dev, struct device *parent_dev,
43 struct uwb_rc *parent_rc);
44extern void uwb_dev_rm(struct uwb_dev *uwb_dev);
45extern void uwbd_dev_onair(struct uwb_rc *, struct uwb_beca_e *);
46extern void uwbd_dev_offair(struct uwb_beca_e *);
47void uwb_notify(struct uwb_rc *rc, struct uwb_dev *uwb_dev, enum uwb_notifs event);
48
49/* General UWB Radio Controller Internal API */
50extern struct uwb_rc *__uwb_rc_try_get(struct uwb_rc *);
51static inline struct uwb_rc *__uwb_rc_get(struct uwb_rc *rc)
52{
53 uwb_dev_get(&rc->uwb_dev);
54 return rc;
55}
56
57static inline void __uwb_rc_put(struct uwb_rc *rc)
58{
59 uwb_dev_put(&rc->uwb_dev);
60}
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
95void uwb_rc_neh_create(struct uwb_rc *rc);
96void uwb_rc_neh_destroy(struct uwb_rc *rc);
97
98struct uwb_rc_neh *uwb_rc_neh_add(struct uwb_rc *rc, struct uwb_rccb *cmd,
99 u8 expected_type, u16 expected_event,
100 uwb_rc_cmd_cb_f cb, void *arg);
101void uwb_rc_neh_rm(struct uwb_rc *rc, struct uwb_rc_neh *neh);
102void uwb_rc_neh_arm(struct uwb_rc *rc, struct uwb_rc_neh *neh);
103void uwb_rc_neh_put(struct uwb_rc_neh *neh);
104
105/* Event size tables */
106extern int uwb_est_create(void);
107extern void uwb_est_destroy(void);
108
109
110/*
111 * UWB Events & management daemon
112 */
113
114/**
115 * enum uwb_event_type - types of UWB management daemon events
116 *
117 * The UWB management daemon (uwbd) can receive two types of events:
118 * UWB_EVT_TYPE_NOTIF - notification from the radio controller.
119 * UWB_EVT_TYPE_MSG - a simple message.
120 */
121enum uwb_event_type {
122 UWB_EVT_TYPE_NOTIF,
123 UWB_EVT_TYPE_MSG,
124};
125
126/**
127 * struct uwb_event_notif - an event for a radio controller notification
128 * @size: Size of the buffer (ie: Guaranteed to contain at least
129 * a full 'struct uwb_rceb')
130 * @rceb: Pointer to a kmalloced() event payload
131 */
132struct uwb_event_notif {
133 size_t size;
134 struct uwb_rceb *rceb;
135};
136
137/**
138 * enum uwb_event_message - an event for a message for asynchronous processing
139 *
140 * UWB_EVT_MSG_RESET - reset the radio controller and all PAL hardware.
141 */
142enum uwb_event_message {
143 UWB_EVT_MSG_RESET,
144};
145
146/**
147 * UWB Event
148 * @rc: Radio controller that emitted the event (referenced)
149 * @ts_jiffies: Timestamp, when was it received
150 * @type: This event's type.
151 */
152struct uwb_event {
153 struct list_head list_node;
154 struct uwb_rc *rc;
155 unsigned long ts_jiffies;
156 enum uwb_event_type type;
157 union {
158 struct uwb_event_notif notif;
159 enum uwb_event_message message;
160 };
161};
162
Stefano Panellafec1a592008-11-04 15:39:08 +0000163extern void uwbd_start(struct uwb_rc *rc);
164extern void uwbd_stop(struct uwb_rc *rc);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100165extern struct uwb_event *uwb_event_alloc(size_t, gfp_t gfp_mask);
166extern void uwbd_event_queue(struct uwb_event *);
167void uwbd_flush(struct uwb_rc *rc);
168
169/* UWB event handlers */
Stefano Panellac5995bd2008-11-04 14:06:31 +0000170extern int uwbd_evt_handle_rc_ie_rcv(struct uwb_event *);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100171extern int uwbd_evt_handle_rc_beacon(struct uwb_event *);
172extern int uwbd_evt_handle_rc_beacon_size(struct uwb_event *);
173extern int uwbd_evt_handle_rc_bpoie_change(struct uwb_event *);
174extern int uwbd_evt_handle_rc_bp_slot_change(struct uwb_event *);
175extern int uwbd_evt_handle_rc_drp(struct uwb_event *);
176extern int uwbd_evt_handle_rc_drp_avail(struct uwb_event *);
177
178int uwbd_msg_handle_reset(struct uwb_event *evt);
179
180
181/*
182 * Address management
183 */
184int uwb_rc_dev_addr_assign(struct uwb_rc *rc);
185int uwbd_evt_handle_rc_dev_addr_conflict(struct uwb_event *evt);
186
187/*
188 * UWB Beacon Cache
189 *
190 * Each beacon we received is kept in a cache--when we receive that
191 * beacon consistently, that means there is a new device that we have
192 * to add to the system.
193 */
194
195extern unsigned long beacon_timeout_ms;
196
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100197/**
198 * Beacon cache entry
199 *
200 * @jiffies_refresh: last time a beacon was received that refreshed
201 * this cache entry.
202 * @uwb_dev: device connected to this beacon. This pointer is not
203 * safe, you need to get it with uwb_dev_try_get()
204 *
205 * @hits: how many time we have seen this beacon since last time we
206 * cleared it
207 */
208struct uwb_beca_e {
209 struct mutex mutex;
210 struct kref refcnt;
211 struct list_head node;
212 struct uwb_mac_addr *mac_addr;
213 struct uwb_dev_addr dev_addr;
214 u8 hits;
215 unsigned long ts_jiffies;
216 struct uwb_dev *uwb_dev;
217 struct uwb_rc_evt_beacon *be;
218 struct stats lqe_stats, rssi_stats; /* radio statistics */
219};
220struct uwb_beacon_frame;
221extern ssize_t uwb_bce_print_IEs(struct uwb_dev *, struct uwb_beca_e *,
222 char *, size_t);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100223
224extern void uwb_bce_kfree(struct kref *_bce);
225static inline void uwb_bce_get(struct uwb_beca_e *bce)
226{
227 kref_get(&bce->refcnt);
228}
229static inline void uwb_bce_put(struct uwb_beca_e *bce)
230{
231 kref_put(&bce->refcnt, uwb_bce_kfree);
232}
Stefano Panellafec1a592008-11-04 15:39:08 +0000233extern void uwb_beca_purge(struct uwb_rc *rc);
234extern void uwb_beca_release(struct uwb_rc *rc);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100235
236struct uwb_dev *uwb_dev_get_by_devaddr(struct uwb_rc *rc,
237 const struct uwb_dev_addr *devaddr);
238struct uwb_dev *uwb_dev_get_by_macaddr(struct uwb_rc *rc,
239 const struct uwb_mac_addr *macaddr);
240
David Vrabel6fae35f2008-11-17 15:53:42 +0000241int uwb_radio_setup(struct uwb_rc *rc);
242void uwb_radio_reset_state(struct uwb_rc *rc);
243void uwb_radio_shutdown(struct uwb_rc *rc);
244int uwb_radio_force_channel(struct uwb_rc *rc, int channel);
245
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100246/* -- UWB Sysfs representation */
247extern struct class uwb_rc_class;
248extern struct device_attribute dev_attr_mac_address;
249extern struct device_attribute dev_attr_beacon;
250extern struct device_attribute dev_attr_scan;
251
252/* -- DRP Bandwidth allocator: bandwidth allocations, reservations, DRP */
253void uwb_rsv_init(struct uwb_rc *rc);
254int uwb_rsv_setup(struct uwb_rc *rc);
255void uwb_rsv_cleanup(struct uwb_rc *rc);
David Vrabel307ba6d2008-11-07 17:37:33 +0000256void uwb_rsv_remove_all(struct uwb_rc *rc);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100257
258void uwb_rsv_set_state(struct uwb_rsv *rsv, enum uwb_rsv_state new_state);
259void uwb_rsv_remove(struct uwb_rsv *rsv);
260struct uwb_rsv *uwb_rsv_find(struct uwb_rc *rc, struct uwb_dev *src,
261 struct uwb_ie_drp *drp_ie);
262void uwb_rsv_sched_update(struct uwb_rc *rc);
263
264void uwb_drp_handle_timeout(struct uwb_rsv *rsv);
265int uwb_drp_ie_update(struct uwb_rsv *rsv);
266void uwb_drp_ie_to_bm(struct uwb_mas_bm *bm, const struct uwb_ie_drp *drp_ie);
267
268void uwb_drp_avail_init(struct uwb_rc *rc);
269int uwb_drp_avail_reserve_pending(struct uwb_rc *rc, struct uwb_mas_bm *mas);
270void uwb_drp_avail_reserve(struct uwb_rc *rc, struct uwb_mas_bm *mas);
271void uwb_drp_avail_release(struct uwb_rc *rc, struct uwb_mas_bm *mas);
272void uwb_drp_avail_ie_update(struct uwb_rc *rc);
273
274/* -- PAL support */
275void uwb_rc_pal_init(struct uwb_rc *rc);
276
277/* -- Misc */
278
279extern ssize_t uwb_mac_frame_hdr_print(char *, size_t,
280 const struct uwb_mac_frame_hdr *);
281
282/* -- Debug interface */
283void uwb_dbg_init(void);
284void uwb_dbg_exit(void);
285void uwb_dbg_add_rc(struct uwb_rc *rc);
286void uwb_dbg_del_rc(struct uwb_rc *rc);
David Vrabeldcc74612008-11-26 13:36:59 +0000287struct dentry *uwb_dbg_create_pal_dir(struct uwb_pal *pal);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +0100288
289static inline void uwb_dev_lock(struct uwb_dev *uwb_dev)
290{
291 down(&uwb_dev->dev.sem);
292}
293
294static inline void uwb_dev_unlock(struct uwb_dev *uwb_dev)
295{
296 up(&uwb_dev->dev.sem);
297}
298
299#endif /* #ifndef __UWB_INTERNAL_H__ */