uwb-internal.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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/kernel.h>
  30. #include <linux/device.h>
  31. #include <linux/uwb.h>
  32. #include <linux/mutex.h>
  33. struct uwb_beca_e;
  34. /* General device API */
  35. extern void uwb_dev_init(struct uwb_dev *uwb_dev);
  36. extern int __uwb_dev_offair(struct uwb_dev *, struct uwb_rc *);
  37. extern int uwb_dev_add(struct uwb_dev *uwb_dev, struct device *parent_dev,
  38. struct uwb_rc *parent_rc);
  39. extern void uwb_dev_rm(struct uwb_dev *uwb_dev);
  40. extern void uwbd_dev_onair(struct uwb_rc *, struct uwb_beca_e *);
  41. extern void uwbd_dev_offair(struct uwb_beca_e *);
  42. void uwb_notify(struct uwb_rc *rc, struct uwb_dev *uwb_dev, enum uwb_notifs event);
  43. /* General UWB Radio Controller Internal API */
  44. extern struct uwb_rc *__uwb_rc_try_get(struct uwb_rc *);
  45. static inline struct uwb_rc *__uwb_rc_get(struct uwb_rc *rc)
  46. {
  47. uwb_dev_get(&rc->uwb_dev);
  48. return rc;
  49. }
  50. static inline void __uwb_rc_put(struct uwb_rc *rc)
  51. {
  52. if (rc)
  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. void uwb_rc_ie_init(struct uwb_rc *);
  63. int uwb_rc_ie_setup(struct uwb_rc *);
  64. void uwb_rc_ie_release(struct uwb_rc *);
  65. int uwb_ie_dump_hex(const struct uwb_ie_hdr *ies, size_t len,
  66. char *buf, size_t size);
  67. int uwb_rc_set_ie(struct uwb_rc *, struct uwb_rc_cmd_set_ie *);
  68. extern const char *uwb_rc_strerror(unsigned code);
  69. /*
  70. * Time to wait for a response to an RC command.
  71. *
  72. * Some commands can take a long time to response. e.g., START_BEACON
  73. * may scan for several superframes before joining an existing beacon
  74. * group and this can take around 600 ms.
  75. */
  76. #define UWB_RC_CMD_TIMEOUT_MS 1000 /* ms */
  77. /*
  78. * Notification/Event Handlers
  79. */
  80. struct uwb_rc_neh;
  81. extern int uwb_rc_cmd_async(struct uwb_rc *rc, const char *cmd_name,
  82. struct uwb_rccb *cmd, size_t cmd_size,
  83. u8 expected_type, u16 expected_event,
  84. uwb_rc_cmd_cb_f cb, void *arg);
  85. void uwb_rc_neh_create(struct uwb_rc *rc);
  86. void uwb_rc_neh_destroy(struct uwb_rc *rc);
  87. struct uwb_rc_neh *uwb_rc_neh_add(struct uwb_rc *rc, struct uwb_rccb *cmd,
  88. u8 expected_type, u16 expected_event,
  89. uwb_rc_cmd_cb_f cb, void *arg);
  90. void uwb_rc_neh_rm(struct uwb_rc *rc, struct uwb_rc_neh *neh);
  91. void uwb_rc_neh_arm(struct uwb_rc *rc, struct uwb_rc_neh *neh);
  92. void uwb_rc_neh_put(struct uwb_rc_neh *neh);
  93. /* Event size tables */
  94. extern int uwb_est_create(void);
  95. extern void uwb_est_destroy(void);
  96. /*
  97. * UWB conflicting alien reservations
  98. */
  99. struct uwb_cnflt_alien {
  100. struct uwb_rc *rc;
  101. struct list_head rc_node;
  102. struct uwb_mas_bm mas;
  103. struct timer_list timer;
  104. struct work_struct cnflt_update_work;
  105. };
  106. enum uwb_uwb_rsv_alloc_result {
  107. UWB_RSV_ALLOC_FOUND = 0,
  108. UWB_RSV_ALLOC_NOT_FOUND,
  109. };
  110. enum uwb_rsv_mas_status {
  111. UWB_RSV_MAS_NOT_AVAIL = 1,
  112. UWB_RSV_MAS_SAFE,
  113. UWB_RSV_MAS_UNSAFE,
  114. };
  115. struct uwb_rsv_col_set_info {
  116. unsigned char start_col;
  117. unsigned char interval;
  118. unsigned char safe_mas_per_col;
  119. unsigned char unsafe_mas_per_col;
  120. };
  121. struct uwb_rsv_col_info {
  122. unsigned char max_avail_safe;
  123. unsigned char max_avail_unsafe;
  124. unsigned char highest_mas[UWB_MAS_PER_ZONE];
  125. struct uwb_rsv_col_set_info csi;
  126. };
  127. struct uwb_rsv_row_info {
  128. unsigned char avail[UWB_MAS_PER_ZONE];
  129. unsigned char free_rows;
  130. unsigned char used_rows;
  131. };
  132. /*
  133. * UWB find allocation
  134. */
  135. struct uwb_rsv_alloc_info {
  136. unsigned char bm[UWB_MAS_PER_ZONE * UWB_NUM_ZONES];
  137. struct uwb_rsv_col_info ci[UWB_NUM_ZONES];
  138. struct uwb_rsv_row_info ri;
  139. struct uwb_mas_bm *not_available;
  140. struct uwb_mas_bm *result;
  141. int min_mas;
  142. int max_mas;
  143. int max_interval;
  144. int total_allocated_mases;
  145. int safe_allocated_mases;
  146. int unsafe_allocated_mases;
  147. int interval;
  148. };
  149. int uwb_rsv_find_best_allocation(struct uwb_rsv *rsv,
  150. struct uwb_mas_bm *available,
  151. struct uwb_mas_bm *result);
  152. void uwb_rsv_handle_drp_avail_change(struct uwb_rc *rc);
  153. /*
  154. * UWB Events & management daemon
  155. */
  156. /**
  157. * enum uwb_event_type - types of UWB management daemon events
  158. *
  159. * The UWB management daemon (uwbd) can receive two types of events:
  160. * UWB_EVT_TYPE_NOTIF - notification from the radio controller.
  161. * UWB_EVT_TYPE_MSG - a simple message.
  162. */
  163. enum uwb_event_type {
  164. UWB_EVT_TYPE_NOTIF,
  165. UWB_EVT_TYPE_MSG,
  166. };
  167. /**
  168. * struct uwb_event_notif - an event for a radio controller notification
  169. * @size: Size of the buffer (ie: Guaranteed to contain at least
  170. * a full 'struct uwb_rceb')
  171. * @rceb: Pointer to a kmalloced() event payload
  172. */
  173. struct uwb_event_notif {
  174. size_t size;
  175. struct uwb_rceb *rceb;
  176. };
  177. /**
  178. * enum uwb_event_message - an event for a message for asynchronous processing
  179. *
  180. * UWB_EVT_MSG_RESET - reset the radio controller and all PAL hardware.
  181. */
  182. enum uwb_event_message {
  183. UWB_EVT_MSG_RESET,
  184. };
  185. /**
  186. * UWB Event
  187. * @rc: Radio controller that emitted the event (referenced)
  188. * @ts_jiffies: Timestamp, when was it received
  189. * @type: This event's type.
  190. */
  191. struct uwb_event {
  192. struct list_head list_node;
  193. struct uwb_rc *rc;
  194. unsigned long ts_jiffies;
  195. enum uwb_event_type type;
  196. union {
  197. struct uwb_event_notif notif;
  198. enum uwb_event_message message;
  199. };
  200. };
  201. extern void uwbd_start(struct uwb_rc *rc);
  202. extern void uwbd_stop(struct uwb_rc *rc);
  203. extern struct uwb_event *uwb_event_alloc(size_t, gfp_t gfp_mask);
  204. extern void uwbd_event_queue(struct uwb_event *);
  205. void uwbd_flush(struct uwb_rc *rc);
  206. /* UWB event handlers */
  207. extern int uwbd_evt_handle_rc_ie_rcv(struct uwb_event *);
  208. extern int uwbd_evt_handle_rc_beacon(struct uwb_event *);
  209. extern int uwbd_evt_handle_rc_beacon_size(struct uwb_event *);
  210. extern int uwbd_evt_handle_rc_bpoie_change(struct uwb_event *);
  211. extern int uwbd_evt_handle_rc_bp_slot_change(struct uwb_event *);
  212. extern int uwbd_evt_handle_rc_drp(struct uwb_event *);
  213. extern int uwbd_evt_handle_rc_drp_avail(struct uwb_event *);
  214. int uwbd_msg_handle_reset(struct uwb_event *evt);
  215. /*
  216. * Address management
  217. */
  218. int uwb_rc_dev_addr_assign(struct uwb_rc *rc);
  219. int uwbd_evt_handle_rc_dev_addr_conflict(struct uwb_event *evt);
  220. /*
  221. * UWB Beacon Cache
  222. *
  223. * Each beacon we received is kept in a cache--when we receive that
  224. * beacon consistently, that means there is a new device that we have
  225. * to add to the system.
  226. */
  227. extern unsigned long beacon_timeout_ms;
  228. /**
  229. * Beacon cache entry
  230. *
  231. * @jiffies_refresh: last time a beacon was received that refreshed
  232. * this cache entry.
  233. * @uwb_dev: device connected to this beacon. This pointer is not
  234. * safe, you need to get it with uwb_dev_try_get()
  235. *
  236. * @hits: how many time we have seen this beacon since last time we
  237. * cleared it
  238. */
  239. struct uwb_beca_e {
  240. struct mutex mutex;
  241. struct kref refcnt;
  242. struct list_head node;
  243. struct uwb_mac_addr *mac_addr;
  244. struct uwb_dev_addr dev_addr;
  245. u8 hits;
  246. unsigned long ts_jiffies;
  247. struct uwb_dev *uwb_dev;
  248. struct uwb_rc_evt_beacon *be;
  249. struct stats lqe_stats, rssi_stats; /* radio statistics */
  250. };
  251. struct uwb_beacon_frame;
  252. extern ssize_t uwb_bce_print_IEs(struct uwb_dev *, struct uwb_beca_e *,
  253. char *, size_t);
  254. extern void uwb_bce_kfree(struct kref *_bce);
  255. static inline void uwb_bce_get(struct uwb_beca_e *bce)
  256. {
  257. kref_get(&bce->refcnt);
  258. }
  259. static inline void uwb_bce_put(struct uwb_beca_e *bce)
  260. {
  261. kref_put(&bce->refcnt, uwb_bce_kfree);
  262. }
  263. extern void uwb_beca_purge(struct uwb_rc *rc);
  264. extern void uwb_beca_release(struct uwb_rc *rc);
  265. struct uwb_dev *uwb_dev_get_by_devaddr(struct uwb_rc *rc,
  266. const struct uwb_dev_addr *devaddr);
  267. struct uwb_dev *uwb_dev_get_by_macaddr(struct uwb_rc *rc,
  268. const struct uwb_mac_addr *macaddr);
  269. int uwb_radio_setup(struct uwb_rc *rc);
  270. void uwb_radio_reset_state(struct uwb_rc *rc);
  271. void uwb_radio_shutdown(struct uwb_rc *rc);
  272. int uwb_radio_force_channel(struct uwb_rc *rc, int channel);
  273. /* -- UWB Sysfs representation */
  274. extern struct class uwb_rc_class;
  275. extern struct bus_type uwb_bus_type;
  276. extern struct device_attribute dev_attr_mac_address;
  277. extern struct device_attribute dev_attr_beacon;
  278. extern struct device_attribute dev_attr_scan;
  279. /* -- DRP Bandwidth allocator: bandwidth allocations, reservations, DRP */
  280. void uwb_rsv_init(struct uwb_rc *rc);
  281. int uwb_rsv_setup(struct uwb_rc *rc);
  282. void uwb_rsv_cleanup(struct uwb_rc *rc);
  283. void uwb_rsv_remove_all(struct uwb_rc *rc);
  284. void uwb_rsv_get(struct uwb_rsv *rsv);
  285. void uwb_rsv_put(struct uwb_rsv *rsv);
  286. bool uwb_rsv_has_two_drp_ies(struct uwb_rsv *rsv);
  287. void uwb_rsv_dump(char *text, struct uwb_rsv *rsv);
  288. int uwb_rsv_try_move(struct uwb_rsv *rsv, struct uwb_mas_bm *available);
  289. void uwb_rsv_backoff_win_timer(unsigned long arg);
  290. void uwb_rsv_backoff_win_increment(struct uwb_rc *rc);
  291. int uwb_rsv_status(struct uwb_rsv *rsv);
  292. int uwb_rsv_companion_status(struct uwb_rsv *rsv);
  293. void uwb_rsv_set_state(struct uwb_rsv *rsv, enum uwb_rsv_state new_state);
  294. void uwb_rsv_remove(struct uwb_rsv *rsv);
  295. struct uwb_rsv *uwb_rsv_find(struct uwb_rc *rc, struct uwb_dev *src,
  296. struct uwb_ie_drp *drp_ie);
  297. void uwb_rsv_sched_update(struct uwb_rc *rc);
  298. void uwb_rsv_queue_update(struct uwb_rc *rc);
  299. int uwb_drp_ie_update(struct uwb_rsv *rsv);
  300. void uwb_drp_ie_to_bm(struct uwb_mas_bm *bm, const struct uwb_ie_drp *drp_ie);
  301. void uwb_drp_avail_init(struct uwb_rc *rc);
  302. void uwb_drp_available(struct uwb_rc *rc, struct uwb_mas_bm *avail);
  303. int uwb_drp_avail_reserve_pending(struct uwb_rc *rc, struct uwb_mas_bm *mas);
  304. void uwb_drp_avail_reserve(struct uwb_rc *rc, struct uwb_mas_bm *mas);
  305. void uwb_drp_avail_release(struct uwb_rc *rc, struct uwb_mas_bm *mas);
  306. void uwb_drp_avail_ie_update(struct uwb_rc *rc);
  307. /* -- PAL support */
  308. void uwb_rc_pal_init(struct uwb_rc *rc);
  309. /* -- Misc */
  310. extern ssize_t uwb_mac_frame_hdr_print(char *, size_t,
  311. const struct uwb_mac_frame_hdr *);
  312. /* -- Debug interface */
  313. void uwb_dbg_init(void);
  314. void uwb_dbg_exit(void);
  315. void uwb_dbg_add_rc(struct uwb_rc *rc);
  316. void uwb_dbg_del_rc(struct uwb_rc *rc);
  317. struct dentry *uwb_dbg_create_pal_dir(struct uwb_pal *pal);
  318. static inline void uwb_dev_lock(struct uwb_dev *uwb_dev)
  319. {
  320. device_lock(&uwb_dev->dev);
  321. }
  322. static inline void uwb_dev_unlock(struct uwb_dev *uwb_dev)
  323. {
  324. device_unlock(&uwb_dev->dev);
  325. }
  326. #endif /* #ifndef __UWB_INTERNAL_H__ */