uwb-internal.h 9.1 KB

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