This source file includes following definitions.
- uwb_mas_bm_copy_le
- uwb_dev_get
- uwb_dev_put
- uwb_dev_addr_print
- uwb_mac_addr_print
- uwb_dev_addr_cmp
- uwb_mac_addr_cmp
- uwb_mac_addr_bcast
- uwb_mac_addr_unset
- __uwb_dev_addr_assigned
- uwb_rsv_is_owner
- edc_init
- edc_inc
- stats_init
- stats_add_sample
- stats_show
- stats_store
1
2
3
4
5
6
7
8
9
10
11
12 #ifndef __LINUX__UWB_H__
13 #define __LINUX__UWB_H__
14
15 #include <linux/limits.h>
16 #include <linux/device.h>
17 #include <linux/mutex.h>
18 #include <linux/timer.h>
19 #include <linux/wait.h>
20 #include <linux/workqueue.h>
21 #include <asm/page.h>
22 #include "include/spec.h"
23
24 struct uwb_dev;
25 struct uwb_beca_e;
26 struct uwb_rc;
27 struct uwb_rsv;
28 struct uwb_dbg;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 struct uwb_dev {
47 struct mutex mutex;
48 struct list_head list_node;
49 struct device dev;
50 struct uwb_rc *rc;
51 struct uwb_beca_e *bce;
52
53 struct uwb_mac_addr mac_addr;
54 struct uwb_dev_addr dev_addr;
55 int beacon_slot;
56 DECLARE_BITMAP(streams, UWB_NUM_STREAMS);
57 DECLARE_BITMAP(last_availability_bm, UWB_NUM_MAS);
58 };
59 #define to_uwb_dev(d) container_of(d, struct uwb_dev, dev)
60
61
62
63
64
65
66
67
68
69 enum { UWB_RC_CTX_MAX = 256 };
70
71
72
73 struct uwb_notifs_chain {
74 struct list_head list;
75 struct mutex mutex;
76 };
77
78
79 struct uwb_beca {
80 struct list_head list;
81 size_t entries;
82 struct mutex mutex;
83 };
84
85
86 struct uwbd {
87 int pid;
88 struct task_struct *task;
89 wait_queue_head_t wq;
90 struct list_head event_list;
91 spinlock_t event_list_lock;
92 };
93
94
95
96
97
98 struct uwb_mas_bm {
99 DECLARE_BITMAP(bm, UWB_NUM_MAS);
100 DECLARE_BITMAP(unsafe_bm, UWB_NUM_MAS);
101 int safe;
102 int unsafe;
103 };
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127 enum uwb_rsv_state {
128 UWB_RSV_STATE_NONE = 0,
129 UWB_RSV_STATE_O_INITIATED,
130 UWB_RSV_STATE_O_PENDING,
131 UWB_RSV_STATE_O_MODIFIED,
132 UWB_RSV_STATE_O_ESTABLISHED,
133 UWB_RSV_STATE_O_TO_BE_MOVED,
134 UWB_RSV_STATE_O_MOVE_EXPANDING,
135 UWB_RSV_STATE_O_MOVE_COMBINING,
136 UWB_RSV_STATE_O_MOVE_REDUCING,
137 UWB_RSV_STATE_T_ACCEPTED,
138 UWB_RSV_STATE_T_DENIED,
139 UWB_RSV_STATE_T_CONFLICT,
140 UWB_RSV_STATE_T_PENDING,
141 UWB_RSV_STATE_T_EXPANDING_ACCEPTED,
142 UWB_RSV_STATE_T_EXPANDING_CONFLICT,
143 UWB_RSV_STATE_T_EXPANDING_PENDING,
144 UWB_RSV_STATE_T_EXPANDING_DENIED,
145 UWB_RSV_STATE_T_RESIZED,
146
147 UWB_RSV_STATE_LAST,
148 };
149
150 enum uwb_rsv_target_type {
151 UWB_RSV_TARGET_DEV,
152 UWB_RSV_TARGET_DEVADDR,
153 };
154
155
156
157
158
159
160
161
162 struct uwb_rsv_target {
163 enum uwb_rsv_target_type type;
164 union {
165 struct uwb_dev *dev;
166 struct uwb_dev_addr devaddr;
167 };
168 };
169
170 struct uwb_rsv_move {
171 struct uwb_mas_bm final_mas;
172 struct uwb_ie_drp *companion_drp_ie;
173 struct uwb_mas_bm companion_mas;
174 };
175
176
177
178
179 #define UWB_NUM_GLOBAL_STREAMS 1
180
181 typedef void (*uwb_rsv_cb_f)(struct uwb_rsv *rsv);
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225 struct uwb_rsv {
226 struct uwb_rc *rc;
227 struct list_head rc_node;
228 struct list_head pal_node;
229 struct kref kref;
230
231 struct uwb_dev *owner;
232 struct uwb_rsv_target target;
233 enum uwb_drp_type type;
234 int max_mas;
235 int min_mas;
236 int max_interval;
237 bool is_multicast;
238
239 uwb_rsv_cb_f callback;
240 void *pal_priv;
241
242 enum uwb_rsv_state state;
243 bool needs_release_companion_mas;
244 u8 stream;
245 u8 tiebreaker;
246 struct uwb_mas_bm mas;
247 struct uwb_ie_drp *drp_ie;
248 struct uwb_rsv_move mv;
249 bool ie_valid;
250 struct timer_list timer;
251 struct work_struct handle_timeout_work;
252 };
253
254 static const
255 struct uwb_mas_bm uwb_mas_bm_zero = { .bm = { 0 } };
256
257 static inline void uwb_mas_bm_copy_le(void *dst, const struct uwb_mas_bm *mas)
258 {
259 bitmap_copy_le(dst, mas->bm, UWB_NUM_MAS);
260 }
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285 struct uwb_drp_avail {
286 DECLARE_BITMAP(global, UWB_NUM_MAS);
287 DECLARE_BITMAP(local, UWB_NUM_MAS);
288 DECLARE_BITMAP(pending, UWB_NUM_MAS);
289 struct uwb_ie_drp_avail ie;
290 bool ie_valid;
291 };
292
293 struct uwb_drp_backoff_win {
294 u8 window;
295 u8 n;
296 int total_expired;
297 struct timer_list timer;
298 bool can_reserve_extra_mases;
299 };
300
301 const char *uwb_rsv_state_str(enum uwb_rsv_state state);
302 const char *uwb_rsv_type_str(enum uwb_drp_type type);
303
304 struct uwb_rsv *uwb_rsv_create(struct uwb_rc *rc, uwb_rsv_cb_f cb,
305 void *pal_priv);
306 void uwb_rsv_destroy(struct uwb_rsv *rsv);
307
308 int uwb_rsv_establish(struct uwb_rsv *rsv);
309 int uwb_rsv_modify(struct uwb_rsv *rsv,
310 int max_mas, int min_mas, int sparsity);
311 void uwb_rsv_terminate(struct uwb_rsv *rsv);
312
313 void uwb_rsv_accept(struct uwb_rsv *rsv, uwb_rsv_cb_f cb, void *pal_priv);
314
315 void uwb_rsv_get_usable_mas(struct uwb_rsv *orig_rsv, struct uwb_mas_bm *mas);
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357 struct uwb_rc {
358 struct uwb_dev uwb_dev;
359 int index;
360 u16 version;
361
362 struct module *owner;
363 void *priv;
364 int (*start)(struct uwb_rc *rc);
365 void (*stop)(struct uwb_rc *rc);
366 int (*cmd)(struct uwb_rc *, const struct uwb_rccb *, size_t);
367 int (*reset)(struct uwb_rc *rc);
368 int (*filter_cmd)(struct uwb_rc *, struct uwb_rccb **, size_t *);
369 int (*filter_event)(struct uwb_rc *, struct uwb_rceb **, const size_t,
370 size_t *, size_t *);
371
372 spinlock_t neh_lock;
373 struct list_head neh_list;
374 unsigned long ctx_bm[UWB_RC_CTX_MAX / 8 / sizeof(unsigned long)];
375 u8 ctx_roll;
376
377 int beaconing;
378 int beaconing_forced;
379 int scanning;
380 enum uwb_scan_type scan_type:3;
381 unsigned ready:1;
382 struct uwb_notifs_chain notifs_chain;
383 struct uwb_beca uwb_beca;
384
385 struct uwbd uwbd;
386
387 struct uwb_drp_backoff_win bow;
388 struct uwb_drp_avail drp_avail;
389 struct list_head reservations;
390 struct list_head cnflt_alien_list;
391 struct uwb_mas_bm cnflt_alien_bitmap;
392 struct mutex rsvs_mutex;
393 spinlock_t rsvs_lock;
394 struct workqueue_struct *rsv_workq;
395
396 struct delayed_work rsv_update_work;
397 struct delayed_work rsv_alien_bp_work;
398 int set_drp_ie_pending;
399 struct mutex ies_mutex;
400 struct uwb_rc_cmd_set_ie *ies;
401 size_t ies_capacity;
402
403 struct list_head pals;
404 int active_pals;
405
406 struct uwb_dbg *dbg;
407 };
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439 struct uwb_pal {
440 struct list_head node;
441 const char *name;
442 struct device *device;
443 struct uwb_rc *rc;
444
445 void (*channel_changed)(struct uwb_pal *pal, int channel);
446 void (*new_rsv)(struct uwb_pal *pal, struct uwb_rsv *rsv);
447
448 int channel;
449 struct dentry *debugfs_dir;
450 };
451
452 void uwb_pal_init(struct uwb_pal *pal);
453 int uwb_pal_register(struct uwb_pal *pal);
454 void uwb_pal_unregister(struct uwb_pal *pal);
455
456 int uwb_radio_start(struct uwb_pal *pal);
457 void uwb_radio_stop(struct uwb_pal *pal);
458
459
460
461
462
463
464
465 struct uwb_dev *uwb_dev_get_by_devaddr(struct uwb_rc *rc,
466 const struct uwb_dev_addr *devaddr);
467 struct uwb_dev *uwb_dev_get_by_rc(struct uwb_dev *, struct uwb_rc *);
468 static inline void uwb_dev_get(struct uwb_dev *uwb_dev)
469 {
470 get_device(&uwb_dev->dev);
471 }
472 static inline void uwb_dev_put(struct uwb_dev *uwb_dev)
473 {
474 put_device(&uwb_dev->dev);
475 }
476 struct uwb_dev *uwb_dev_try_get(struct uwb_rc *rc, struct uwb_dev *uwb_dev);
477
478
479
480
481
482
483
484
485
486
487
488
489 typedef int (*uwb_dev_for_each_f)(struct device *dev, void *priv);
490 int uwb_dev_for_each(struct uwb_rc *rc, uwb_dev_for_each_f func, void *priv);
491
492 struct uwb_rc *uwb_rc_alloc(void);
493 struct uwb_rc *uwb_rc_get_by_dev(const struct uwb_dev_addr *);
494 struct uwb_rc *uwb_rc_get_by_grandpa(const struct device *);
495 void uwb_rc_put(struct uwb_rc *rc);
496
497 typedef void (*uwb_rc_cmd_cb_f)(struct uwb_rc *rc, void *arg,
498 struct uwb_rceb *reply, ssize_t reply_size);
499
500 int uwb_rc_cmd_async(struct uwb_rc *rc, const char *cmd_name,
501 struct uwb_rccb *cmd, size_t cmd_size,
502 u8 expected_type, u16 expected_event,
503 uwb_rc_cmd_cb_f cb, void *arg);
504 ssize_t uwb_rc_cmd(struct uwb_rc *rc, const char *cmd_name,
505 struct uwb_rccb *cmd, size_t cmd_size,
506 struct uwb_rceb *reply, size_t reply_size);
507 ssize_t uwb_rc_vcmd(struct uwb_rc *rc, const char *cmd_name,
508 struct uwb_rccb *cmd, size_t cmd_size,
509 u8 expected_type, u16 expected_event,
510 struct uwb_rceb **preply);
511
512 size_t __uwb_addr_print(char *, size_t, const unsigned char *, int);
513
514 int uwb_rc_dev_addr_set(struct uwb_rc *, const struct uwb_dev_addr *);
515 int uwb_rc_dev_addr_get(struct uwb_rc *, struct uwb_dev_addr *);
516 int uwb_rc_mac_addr_set(struct uwb_rc *, const struct uwb_mac_addr *);
517 int uwb_rc_mac_addr_get(struct uwb_rc *, struct uwb_mac_addr *);
518 int __uwb_mac_addr_assigned_check(struct device *, void *);
519 int __uwb_dev_addr_assigned_check(struct device *, void *);
520
521
522 static inline size_t uwb_dev_addr_print(char *buf, size_t buf_size,
523 const struct uwb_dev_addr *addr)
524 {
525 return __uwb_addr_print(buf, buf_size, addr->data, 0);
526 }
527
528
529 static inline size_t uwb_mac_addr_print(char *buf, size_t buf_size,
530 const struct uwb_mac_addr *addr)
531 {
532 return __uwb_addr_print(buf, buf_size, addr->data, 1);
533 }
534
535
536 static inline int uwb_dev_addr_cmp(const struct uwb_dev_addr *addr1,
537 const struct uwb_dev_addr *addr2)
538 {
539 return memcmp(addr1, addr2, sizeof(*addr1));
540 }
541
542
543 static inline int uwb_mac_addr_cmp(const struct uwb_mac_addr *addr1,
544 const struct uwb_mac_addr *addr2)
545 {
546 return memcmp(addr1, addr2, sizeof(*addr1));
547 }
548
549
550 static inline int uwb_mac_addr_bcast(const struct uwb_mac_addr *addr)
551 {
552 struct uwb_mac_addr bcast = {
553 .data = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
554 };
555 return !uwb_mac_addr_cmp(addr, &bcast);
556 }
557
558
559 static inline int uwb_mac_addr_unset(const struct uwb_mac_addr *addr)
560 {
561 struct uwb_mac_addr unset = {
562 .data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
563 };
564 return !uwb_mac_addr_cmp(addr, &unset);
565 }
566
567
568 static inline unsigned __uwb_dev_addr_assigned(struct uwb_rc *rc,
569 struct uwb_dev_addr *addr)
570 {
571 return uwb_dev_for_each(rc, __uwb_dev_addr_assigned_check, addr);
572 }
573
574
575
576
577
578
579
580 void uwb_rc_init(struct uwb_rc *);
581 int uwb_rc_add(struct uwb_rc *, struct device *dev, void *rc_priv);
582 void uwb_rc_rm(struct uwb_rc *);
583 void uwb_rc_neh_grok(struct uwb_rc *, void *, size_t);
584 void uwb_rc_neh_error(struct uwb_rc *, int);
585 void uwb_rc_reset_all(struct uwb_rc *rc);
586 void uwb_rc_pre_reset(struct uwb_rc *rc);
587 int uwb_rc_post_reset(struct uwb_rc *rc);
588
589
590
591
592
593 static inline bool uwb_rsv_is_owner(struct uwb_rsv *rsv)
594 {
595 return rsv->owner == &rsv->rc->uwb_dev;
596 }
597
598
599
600
601
602
603
604
605
606
607
608 enum uwb_notifs {
609 UWB_NOTIF_ONAIR,
610 UWB_NOTIF_OFFAIR,
611 };
612
613
614 struct uwb_notifs_handler {
615 struct list_head list_node;
616 void (*cb)(void *, struct uwb_dev *, enum uwb_notifs);
617 void *data;
618 };
619
620 int uwb_notifs_register(struct uwb_rc *, struct uwb_notifs_handler *);
621 int uwb_notifs_deregister(struct uwb_rc *, struct uwb_notifs_handler *);
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660 struct uwb_est_entry {
661 size_t size;
662 unsigned offset;
663 enum { UWB_EST_16 = 0, UWB_EST_8 = 1 } type;
664 };
665
666 int uwb_est_register(u8 type, u8 code_high, u16 vendor, u16 product,
667 const struct uwb_est_entry *, size_t entries);
668 int uwb_est_unregister(u8 type, u8 code_high, u16 vendor, u16 product,
669 const struct uwb_est_entry *, size_t entries);
670 ssize_t uwb_est_find_size(struct uwb_rc *rc, const struct uwb_rceb *rceb,
671 size_t len);
672
673
674
675 enum {
676 EDC_MAX_ERRORS = 10,
677 EDC_ERROR_TIMEFRAME = HZ,
678 };
679
680
681 struct edc {
682 unsigned long timestart;
683 u16 errorcount;
684 };
685
686 static inline
687 void edc_init(struct edc *edc)
688 {
689 edc->timestart = jiffies;
690 }
691
692
693
694
695
696
697
698
699
700
701 static inline int edc_inc(struct edc *err_hist, u16 max_err, u16 timeframe)
702 {
703 unsigned long now;
704
705 now = jiffies;
706 if (now - err_hist->timestart > timeframe) {
707 err_hist->errorcount = 1;
708 err_hist->timestart = now;
709 } else if (++err_hist->errorcount > max_err) {
710 err_hist->errorcount = 0;
711 err_hist->timestart = now;
712 return 1;
713 }
714 return 0;
715 }
716
717
718
719
720 struct uwb_ie_hdr *uwb_ie_next(void **ptr, size_t *len);
721 int uwb_rc_ie_add(struct uwb_rc *uwb_rc, const struct uwb_ie_hdr *ies, size_t size);
722 int uwb_rc_ie_rm(struct uwb_rc *uwb_rc, enum uwb_ie element_id);
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751 struct stats {
752 s8 min, max;
753 s16 sigma;
754 atomic_t samples;
755 };
756
757 static inline
758 void stats_init(struct stats *stats)
759 {
760 atomic_set(&stats->samples, 0);
761 wmb();
762 }
763
764 static inline
765 void stats_add_sample(struct stats *stats, s8 sample)
766 {
767 s8 min, max;
768 s16 sigma;
769 unsigned samples = atomic_read(&stats->samples);
770 if (samples == 0) {
771 min = 127;
772 max = -128;
773 sigma = 0;
774 } else {
775 min = stats->min;
776 max = stats->max;
777 sigma = stats->sigma;
778 }
779
780 if (sample < min)
781 min = sample;
782 else if (sample > max)
783 max = sample;
784 sigma += sample;
785
786 stats->min = min;
787 stats->max = max;
788 stats->sigma = sigma;
789 if (atomic_add_return(1, &stats->samples) > 255) {
790
791 stats->sigma = sigma / 256;
792 atomic_set(&stats->samples, 1);
793 }
794 }
795
796 static inline ssize_t stats_show(struct stats *stats, char *buf)
797 {
798 int min, max, avg;
799 int samples = atomic_read(&stats->samples);
800 if (samples == 0)
801 min = max = avg = 0;
802 else {
803 min = stats->min;
804 max = stats->max;
805 avg = stats->sigma / samples;
806 }
807 return scnprintf(buf, PAGE_SIZE, "%d %d %d\n", min, max, avg);
808 }
809
810 static inline ssize_t stats_store(struct stats *stats, const char *buf,
811 size_t size)
812 {
813 stats_init(stats);
814 return size;
815 }
816
817 #endif