]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blob - drivers/uwb/uwb-internal.h
uwb: add the UWB stack (core files)
[mirror_ubuntu-kernels.git] / drivers / uwb / uwb-internal.h
1 /*
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
37 struct uwb_beca_e;
38
39 /* General device API */
40 extern void uwb_dev_init(struct uwb_dev *uwb_dev);
41 extern int __uwb_dev_offair(struct uwb_dev *, struct uwb_rc *);
42 extern int uwb_dev_add(struct uwb_dev *uwb_dev, struct device *parent_dev,
43 struct uwb_rc *parent_rc);
44 extern void uwb_dev_rm(struct uwb_dev *uwb_dev);
45 extern void uwbd_dev_onair(struct uwb_rc *, struct uwb_beca_e *);
46 extern void uwbd_dev_offair(struct uwb_beca_e *);
47 void uwb_notify(struct uwb_rc *rc, struct uwb_dev *uwb_dev, enum uwb_notifs event);
48
49 /* General UWB Radio Controller Internal API */
50 extern struct uwb_rc *__uwb_rc_try_get(struct uwb_rc *);
51 static inline struct uwb_rc *__uwb_rc_get(struct uwb_rc *rc)
52 {
53 uwb_dev_get(&rc->uwb_dev);
54 return rc;
55 }
56
57 static inline void __uwb_rc_put(struct uwb_rc *rc)
58 {
59 uwb_dev_put(&rc->uwb_dev);
60 }
61
62 extern int uwb_rc_reset(struct uwb_rc *rc);
63 extern int uwb_rc_beacon(struct uwb_rc *rc,
64 int channel, unsigned bpst_offset);
65 extern int uwb_rc_scan(struct uwb_rc *rc,
66 unsigned channel, enum uwb_scan_type type,
67 unsigned bpst_offset);
68 extern int uwb_rc_send_all_drp_ie(struct uwb_rc *rc);
69 extern ssize_t uwb_rc_print_IEs(struct uwb_rc *rc, char *, size_t);
70 extern void uwb_rc_ie_init(struct uwb_rc *);
71 extern void uwb_rc_ie_init(struct uwb_rc *);
72 extern ssize_t uwb_rc_ie_setup(struct uwb_rc *);
73 extern void uwb_rc_ie_release(struct uwb_rc *);
74 extern int uwb_rc_ie_add(struct uwb_rc *,
75 const struct uwb_ie_hdr *, size_t);
76 extern int uwb_rc_ie_rm(struct uwb_rc *, enum uwb_ie);
77 extern int uwb_rc_set_identification_ie(struct uwb_rc *);
78
79 extern const char *uwb_rc_strerror(unsigned code);
80
81 /*
82 * Time to wait for a response to an RC command.
83 *
84 * Some commands can take a long time to response. e.g., START_BEACON
85 * may scan for several superframes before joining an existing beacon
86 * group and this can take around 600 ms.
87 */
88 #define UWB_RC_CMD_TIMEOUT_MS 1000 /* ms */
89
90 /*
91 * Notification/Event Handlers
92 */
93
94 struct uwb_rc_neh;
95
96 void uwb_rc_neh_create(struct uwb_rc *rc);
97 void uwb_rc_neh_destroy(struct uwb_rc *rc);
98
99 struct uwb_rc_neh *uwb_rc_neh_add(struct uwb_rc *rc, struct uwb_rccb *cmd,
100 u8 expected_type, u16 expected_event,
101 uwb_rc_cmd_cb_f cb, void *arg);
102 void uwb_rc_neh_rm(struct uwb_rc *rc, struct uwb_rc_neh *neh);
103 void uwb_rc_neh_arm(struct uwb_rc *rc, struct uwb_rc_neh *neh);
104 void uwb_rc_neh_put(struct uwb_rc_neh *neh);
105
106 /* Event size tables */
107 extern int uwb_est_create(void);
108 extern void uwb_est_destroy(void);
109
110
111 /*
112 * UWB Events & management daemon
113 */
114
115 /**
116 * enum uwb_event_type - types of UWB management daemon events
117 *
118 * The UWB management daemon (uwbd) can receive two types of events:
119 * UWB_EVT_TYPE_NOTIF - notification from the radio controller.
120 * UWB_EVT_TYPE_MSG - a simple message.
121 */
122 enum uwb_event_type {
123 UWB_EVT_TYPE_NOTIF,
124 UWB_EVT_TYPE_MSG,
125 };
126
127 /**
128 * struct uwb_event_notif - an event for a radio controller notification
129 * @size: Size of the buffer (ie: Guaranteed to contain at least
130 * a full 'struct uwb_rceb')
131 * @rceb: Pointer to a kmalloced() event payload
132 */
133 struct uwb_event_notif {
134 size_t size;
135 struct uwb_rceb *rceb;
136 };
137
138 /**
139 * enum uwb_event_message - an event for a message for asynchronous processing
140 *
141 * UWB_EVT_MSG_RESET - reset the radio controller and all PAL hardware.
142 */
143 enum uwb_event_message {
144 UWB_EVT_MSG_RESET,
145 };
146
147 /**
148 * UWB Event
149 * @rc: Radio controller that emitted the event (referenced)
150 * @ts_jiffies: Timestamp, when was it received
151 * @type: This event's type.
152 */
153 struct uwb_event {
154 struct list_head list_node;
155 struct uwb_rc *rc;
156 unsigned long ts_jiffies;
157 enum uwb_event_type type;
158 union {
159 struct uwb_event_notif notif;
160 enum uwb_event_message message;
161 };
162 };
163
164 extern void uwbd_start(void);
165 extern void uwbd_stop(void);
166 extern struct uwb_event *uwb_event_alloc(size_t, gfp_t gfp_mask);
167 extern void uwbd_event_queue(struct uwb_event *);
168 void uwbd_flush(struct uwb_rc *rc);
169
170 /* UWB event handlers */
171 extern int uwbd_evt_handle_rc_beacon(struct uwb_event *);
172 extern int uwbd_evt_handle_rc_beacon_size(struct uwb_event *);
173 extern int uwbd_evt_handle_rc_bpoie_change(struct uwb_event *);
174 extern int uwbd_evt_handle_rc_bp_slot_change(struct uwb_event *);
175 extern int uwbd_evt_handle_rc_drp(struct uwb_event *);
176 extern int uwbd_evt_handle_rc_drp_avail(struct uwb_event *);
177
178 int uwbd_msg_handle_reset(struct uwb_event *evt);
179
180
181 /*
182 * Address management
183 */
184 int uwb_rc_dev_addr_assign(struct uwb_rc *rc);
185 int 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
195 extern unsigned long beacon_timeout_ms;
196
197 /** Beacon cache list */
198 struct uwb_beca {
199 struct list_head list;
200 size_t entries;
201 struct mutex mutex;
202 };
203
204 extern struct uwb_beca uwb_beca;
205
206 /**
207 * Beacon cache entry
208 *
209 * @jiffies_refresh: last time a beacon was received that refreshed
210 * this cache entry.
211 * @uwb_dev: device connected to this beacon. This pointer is not
212 * safe, you need to get it with uwb_dev_try_get()
213 *
214 * @hits: how many time we have seen this beacon since last time we
215 * cleared it
216 */
217 struct uwb_beca_e {
218 struct mutex mutex;
219 struct kref refcnt;
220 struct list_head node;
221 struct uwb_mac_addr *mac_addr;
222 struct uwb_dev_addr dev_addr;
223 u8 hits;
224 unsigned long ts_jiffies;
225 struct uwb_dev *uwb_dev;
226 struct uwb_rc_evt_beacon *be;
227 struct stats lqe_stats, rssi_stats; /* radio statistics */
228 };
229 struct uwb_beacon_frame;
230 extern ssize_t uwb_bce_print_IEs(struct uwb_dev *, struct uwb_beca_e *,
231 char *, size_t);
232 extern struct uwb_beca_e *__uwb_beca_add(struct uwb_rc_evt_beacon *,
233 struct uwb_beacon_frame *,
234 unsigned long);
235
236 extern void uwb_bce_kfree(struct kref *_bce);
237 static inline void uwb_bce_get(struct uwb_beca_e *bce)
238 {
239 kref_get(&bce->refcnt);
240 }
241 static inline void uwb_bce_put(struct uwb_beca_e *bce)
242 {
243 kref_put(&bce->refcnt, uwb_bce_kfree);
244 }
245 extern void uwb_beca_purge(void);
246 extern void uwb_beca_release(void);
247
248 struct uwb_dev *uwb_dev_get_by_devaddr(struct uwb_rc *rc,
249 const struct uwb_dev_addr *devaddr);
250 struct uwb_dev *uwb_dev_get_by_macaddr(struct uwb_rc *rc,
251 const struct uwb_mac_addr *macaddr);
252
253 /* -- UWB Sysfs representation */
254 extern struct class uwb_rc_class;
255 extern struct device_attribute dev_attr_mac_address;
256 extern struct device_attribute dev_attr_beacon;
257 extern struct device_attribute dev_attr_scan;
258
259 /* -- DRP Bandwidth allocator: bandwidth allocations, reservations, DRP */
260 void uwb_rsv_init(struct uwb_rc *rc);
261 int uwb_rsv_setup(struct uwb_rc *rc);
262 void uwb_rsv_cleanup(struct uwb_rc *rc);
263
264 void uwb_rsv_set_state(struct uwb_rsv *rsv, enum uwb_rsv_state new_state);
265 void uwb_rsv_remove(struct uwb_rsv *rsv);
266 struct uwb_rsv *uwb_rsv_find(struct uwb_rc *rc, struct uwb_dev *src,
267 struct uwb_ie_drp *drp_ie);
268 void uwb_rsv_sched_update(struct uwb_rc *rc);
269
270 void uwb_drp_handle_timeout(struct uwb_rsv *rsv);
271 int uwb_drp_ie_update(struct uwb_rsv *rsv);
272 void uwb_drp_ie_to_bm(struct uwb_mas_bm *bm, const struct uwb_ie_drp *drp_ie);
273
274 void uwb_drp_avail_init(struct uwb_rc *rc);
275 int uwb_drp_avail_reserve_pending(struct uwb_rc *rc, struct uwb_mas_bm *mas);
276 void uwb_drp_avail_reserve(struct uwb_rc *rc, struct uwb_mas_bm *mas);
277 void uwb_drp_avail_release(struct uwb_rc *rc, struct uwb_mas_bm *mas);
278 void uwb_drp_avail_ie_update(struct uwb_rc *rc);
279
280 /* -- PAL support */
281 void uwb_rc_pal_init(struct uwb_rc *rc);
282
283 /* -- Misc */
284
285 extern ssize_t uwb_mac_frame_hdr_print(char *, size_t,
286 const struct uwb_mac_frame_hdr *);
287
288 /* -- Debug interface */
289 void uwb_dbg_init(void);
290 void uwb_dbg_exit(void);
291 void uwb_dbg_add_rc(struct uwb_rc *rc);
292 void uwb_dbg_del_rc(struct uwb_rc *rc);
293
294 /* Workarounds for version specific stuff */
295
296 static inline void uwb_dev_lock(struct uwb_dev *uwb_dev)
297 {
298 down(&uwb_dev->dev.sem);
299 }
300
301 static inline void uwb_dev_unlock(struct uwb_dev *uwb_dev)
302 {
303 up(&uwb_dev->dev.sem);
304 }
305
306 #endif /* #ifndef __UWB_INTERNAL_H__ */