3 #ifndef __LINUX__UWB_H__
4 #define __LINUX__UWB_H__
6 #include <linux/limits.h>
7 #include <linux/device.h>
8 #include <linux/mutex.h>
9 #include <linux/timer.h>
10 #include <linux/wait.h>
11 #include <linux/workqueue.h>
12 #include <linux/uwb/spec.h>
21 * struct uwb_dev - a UWB Device
22 * @rc: UWB Radio Controller that discovered the device (kind of its
24 * @bce: a beacon cache entry for this device; or NULL if the device
25 * is a local radio controller.
26 * @mac_addr: the EUI-48 address of this device.
27 * @dev_addr: the current DevAddr used by this device.
28 * @beacon_slot: the slot number the beacon is using.
29 * @streams: bitmap of streams allocated to reservations targeted at
30 * this device. For an RC, this is the streams allocated for
31 * reservations targeted at DevAddrs.
33 * A UWB device may either by a neighbor or part of a local radio
38 struct list_head list_node
;
40 struct uwb_rc
*rc
; /* radio controller */
41 struct uwb_beca_e
*bce
; /* Beacon Cache Entry */
43 struct uwb_mac_addr mac_addr
;
44 struct uwb_dev_addr dev_addr
;
46 DECLARE_BITMAP(streams
, UWB_NUM_STREAMS
);
47 DECLARE_BITMAP(last_availability_bm
, UWB_NUM_MAS
);
49 #define to_uwb_dev(d) container_of(d, struct uwb_dev, dev)
52 * UWB HWA/WHCI Radio Control {Command|Event} Block context IDs
54 * RC[CE]Bs have a 'context ID' field that matches the command with
55 * the event received to confirm it.
57 * Maximum number of context IDs
59 enum { UWB_RC_CTX_MAX
= 256 };
62 /** Notification chain head for UWB generated events to listeners */
63 struct uwb_notifs_chain
{
64 struct list_head list
;
68 /* Beacon cache list */
70 struct list_head list
;
75 /* Event handling thread. */
78 struct task_struct
*task
;
80 struct list_head event_list
;
81 spinlock_t event_list_lock
;
85 * struct uwb_mas_bm - a bitmap of all MAS in a superframe
86 * @bm: a bitmap of length #UWB_NUM_MAS
89 DECLARE_BITMAP(bm
, UWB_NUM_MAS
);
90 DECLARE_BITMAP(unsafe_bm
, UWB_NUM_MAS
);
96 UWB_RSV_STATE_NONE
= 0,
97 UWB_RSV_STATE_O_INITIATED
,
98 UWB_RSV_STATE_O_PENDING
,
99 UWB_RSV_STATE_O_MODIFIED
,
100 UWB_RSV_STATE_O_ESTABLISHED
,
101 UWB_RSV_STATE_O_TO_BE_MOVED
,
102 UWB_RSV_STATE_O_MOVE_EXPANDING
,
103 UWB_RSV_STATE_O_MOVE_COMBINING
,
104 UWB_RSV_STATE_O_MOVE_REDUCING
,
105 UWB_RSV_STATE_T_ACCEPTED
,
106 UWB_RSV_STATE_T_DENIED
,
107 UWB_RSV_STATE_T_CONFLICT
,
108 UWB_RSV_STATE_T_PENDING
,
109 UWB_RSV_STATE_T_EXPANDING_ACCEPTED
,
110 UWB_RSV_STATE_T_EXPANDING_CONFLICT
,
111 UWB_RSV_STATE_T_EXPANDING_PENDING
,
112 UWB_RSV_STATE_T_EXPANDING_DENIED
,
113 UWB_RSV_STATE_T_RESIZED
,
118 enum uwb_rsv_target_type
{
120 UWB_RSV_TARGET_DEVADDR
,
124 * struct uwb_rsv_target - the target of a reservation.
126 * Reservations unicast and targeted at a single device
127 * (UWB_RSV_TARGET_DEV); or (e.g., in the case of WUSB) targeted at a
128 * specific (private) DevAddr (UWB_RSV_TARGET_DEVADDR).
130 struct uwb_rsv_target
{
131 enum uwb_rsv_target_type type
;
134 struct uwb_dev_addr devaddr
;
138 struct uwb_rsv_move
{
139 struct uwb_mas_bm final_mas
;
140 struct uwb_ie_drp
*companion_drp_ie
;
141 struct uwb_mas_bm companion_mas
;
145 * Number of streams reserved for reservations targeted at DevAddrs.
147 #define UWB_NUM_GLOBAL_STREAMS 1
149 typedef void (*uwb_rsv_cb_f
)(struct uwb_rsv
*rsv
);
152 * struct uwb_rsv - a DRP reservation
154 * Data structure management:
156 * @rc: the radio controller this reservation is for
157 * (as target or owner)
158 * @rc_node: a list node for the RC
159 * @pal_node: a list node for the PAL
161 * Owner and target parameters:
163 * @owner: the UWB device owning this reservation
164 * @target: the target UWB device
165 * @type: reservation type
169 * @max_mas: maxiumum number of MAS
170 * @min_mas: minimum number of MAS
171 * @sparsity: owner selected sparsity
172 * @is_multicast: true iff multicast
174 * @callback: callback function when the reservation completes
175 * @pal_priv: private data for the PAL making the reservation
177 * Reservation status:
179 * @status: negotiation status
180 * @stream: stream index allocated for this reservation
181 * @tiebreaker: conflict tiebreaker for this reservation
183 * @drp_ie: the DRP IE
184 * @ie_valid: true iff the DRP IE matches the reservation parameters
186 * DRP reservations are uniquely identified by the owner, target and
187 * stream index. However, when using a DevAddr as a target (e.g., for
188 * a WUSB cluster reservation) the responses may be received from
189 * devices with different DevAddrs. In this case, reservations are
190 * uniquely identified by just the stream index. A number of stream
191 * indexes (UWB_NUM_GLOBAL_STREAMS) are reserved for this.
195 struct list_head rc_node
;
196 struct list_head pal_node
;
199 struct uwb_dev
*owner
;
200 struct uwb_rsv_target target
;
201 enum uwb_drp_type type
;
207 uwb_rsv_cb_f callback
;
210 enum uwb_rsv_state state
;
211 bool needs_release_companion_mas
;
214 struct uwb_mas_bm mas
;
215 struct uwb_ie_drp
*drp_ie
;
216 struct uwb_rsv_move mv
;
218 struct timer_list timer
;
219 struct work_struct handle_timeout_work
;
223 struct uwb_mas_bm uwb_mas_bm_zero
= { .bm
= { 0 } };
225 static inline void uwb_mas_bm_copy_le(void *dst
, const struct uwb_mas_bm
*mas
)
227 bitmap_copy_le(dst
, mas
->bm
, UWB_NUM_MAS
);
231 * struct uwb_drp_avail - a radio controller's view of MAS usage
232 * @global: MAS unused by neighbors (excluding reservations targetted
233 * or owned by the local radio controller) or the beaon period
234 * @local: MAS unused by local established reservations
235 * @pending: MAS unused by local pending reservations
236 * @ie: DRP Availability IE to be included in the beacon
237 * @ie_valid: true iff @ie is valid and does not need to regenerated from
240 * Each radio controller maintains a view of MAS usage or
241 * availability. MAS available for a new reservation are determined
242 * from the intersection of @global, @local, and @pending.
244 * The radio controller must transmit a DRP Availability IE that's the
245 * intersection of @global and @local.
247 * A set bit indicates the MAS is unused and available.
249 * rc->rsvs_mutex should be held before accessing this data structure.
251 * [ECMA-368] section 17.4.3.
253 struct uwb_drp_avail
{
254 DECLARE_BITMAP(global
, UWB_NUM_MAS
);
255 DECLARE_BITMAP(local
, UWB_NUM_MAS
);
256 DECLARE_BITMAP(pending
, UWB_NUM_MAS
);
257 struct uwb_ie_drp_avail ie
;
261 struct uwb_drp_backoff_win
{
265 struct timer_list timer
;
266 bool can_reserve_extra_mases
;
269 const char *uwb_rsv_state_str(enum uwb_rsv_state state
);
270 const char *uwb_rsv_type_str(enum uwb_drp_type type
);
272 struct uwb_rsv
*uwb_rsv_create(struct uwb_rc
*rc
, uwb_rsv_cb_f cb
,
274 void uwb_rsv_destroy(struct uwb_rsv
*rsv
);
276 int uwb_rsv_establish(struct uwb_rsv
*rsv
);
277 int uwb_rsv_modify(struct uwb_rsv
*rsv
,
278 int max_mas
, int min_mas
, int sparsity
);
279 void uwb_rsv_terminate(struct uwb_rsv
*rsv
);
281 void uwb_rsv_accept(struct uwb_rsv
*rsv
, uwb_rsv_cb_f cb
, void *pal_priv
);
283 void uwb_rsv_get_usable_mas(struct uwb_rsv
*orig_rsv
, struct uwb_mas_bm
*mas
);
286 * Radio Control Interface instance
289 * Life cycle rules: those of the UWB Device.
291 * @index: an index number for this radio controller, as used in the
293 * @version: version of protocol supported by this device
294 * @priv: Backend implementation; rw with uwb_dev.dev.sem taken.
295 * @cmd: Backend implementation to execute commands; rw and call
296 * only with uwb_dev.dev.sem taken.
297 * @reset: Hardware reset of radio controller and any PAL controllers.
298 * @filter: Backend implementation to manipulate data to and from device
299 * to be compliant to specification assumed by driver (WHCI
302 * uwb_dev.dev.mutex is used to execute commands and update
303 * the corresponding structures; can't use a spinlock
304 * because rc->cmd() can sleep.
305 * @ies: This is a dynamically allocated array cacheing the
306 * IEs (settable by the host) that the beacon of this
307 * radio controller is currently sending.
309 * In reality, we store here the full command we set to
310 * the radio controller (which is basically a command
311 * prefix followed by all the IEs the beacon currently
312 * contains). This way we don't have to realloc and
313 * memcpy when setting it.
315 * We set this up in uwb_rc_ie_setup(), where we alloc
316 * this struct, call get_ie() [so we know which IEs are
317 * currently being sent, if any].
319 * @ies_capacity:Amount of space (in bytes) allocated in @ies. The
320 * amount used is given by sizeof(*ies) plus ies->wIELength
321 * (which is a little endian quantity all the time).
322 * @ies_mutex: protect the IE cache
323 * @dbg: information for the debug interface
326 struct uwb_dev uwb_dev
;
330 struct module
*owner
;
332 int (*start
)(struct uwb_rc
*rc
);
333 void (*stop
)(struct uwb_rc
*rc
);
334 int (*cmd
)(struct uwb_rc
*, const struct uwb_rccb
*, size_t);
335 int (*reset
)(struct uwb_rc
*rc
);
336 int (*filter_cmd
)(struct uwb_rc
*, struct uwb_rccb
**, size_t *);
337 int (*filter_event
)(struct uwb_rc
*, struct uwb_rceb
**, const size_t,
340 spinlock_t neh_lock
; /* protects neh_* and ctx_* */
341 struct list_head neh_list
; /* Open NE handles */
342 unsigned long ctx_bm
[UWB_RC_CTX_MAX
/ 8 / sizeof(unsigned long)];
345 int beaconing
; /* Beaconing state [channel number] */
346 int beaconing_forced
;
348 enum uwb_scan_type scan_type
:3;
350 struct uwb_notifs_chain notifs_chain
;
351 struct uwb_beca uwb_beca
;
355 struct uwb_drp_backoff_win bow
;
356 struct uwb_drp_avail drp_avail
;
357 struct list_head reservations
;
358 struct list_head cnflt_alien_list
;
359 struct uwb_mas_bm cnflt_alien_bitmap
;
360 struct mutex rsvs_mutex
;
361 spinlock_t rsvs_lock
;
362 struct workqueue_struct
*rsv_workq
;
364 struct delayed_work rsv_update_work
;
365 struct delayed_work rsv_alien_bp_work
;
366 int set_drp_ie_pending
;
367 struct mutex ies_mutex
;
368 struct uwb_rc_cmd_set_ie
*ies
;
371 struct list_head pals
;
379 * struct uwb_pal - a UWB PAL
380 * @name: descriptive name for this PAL (wusbhc, wlp, etc.).
381 * @device: a device for the PAL. Used to link the PAL and the radio
382 * controller in sysfs.
383 * @rc: the radio controller the PAL uses.
384 * @channel_changed: called when the channel used by the radio changes.
385 * A channel of -1 means the channel has been stopped.
386 * @new_rsv: called when a peer requests a reservation (may be NULL if
387 * the PAL cannot accept reservation requests).
388 * @channel: channel being used by the PAL; 0 if the PAL isn't using
389 * the radio; -1 if the PAL wishes to use the radio but
391 * @debugfs_dir: a debugfs directory which the PAL can use for its own
394 * A Protocol Adaptation Layer (PAL) is a user of the WiMedia UWB
395 * radio platform (e.g., WUSB, WLP or Bluetooth UWB AMP).
397 * The PALs using a radio controller must register themselves to
398 * permit the UWB stack to coordinate usage of the radio between the
399 * various PALs or to allow PALs to response to certain requests from
402 * A struct uwb_pal should be embedded in a containing structure
403 * belonging to the PAL and initialized with uwb_pal_init()). Fields
404 * should be set appropriately by the PAL before registering the PAL
405 * with uwb_pal_register().
408 struct list_head node
;
410 struct device
*device
;
413 void (*channel_changed
)(struct uwb_pal
*pal
, int channel
);
414 void (*new_rsv
)(struct uwb_pal
*pal
, struct uwb_rsv
*rsv
);
417 struct dentry
*debugfs_dir
;
420 void uwb_pal_init(struct uwb_pal
*pal
);
421 int uwb_pal_register(struct uwb_pal
*pal
);
422 void uwb_pal_unregister(struct uwb_pal
*pal
);
424 int uwb_radio_start(struct uwb_pal
*pal
);
425 void uwb_radio_stop(struct uwb_pal
*pal
);
430 * This API can be used by UWB device drivers or by those implementing
431 * UWB Radio Controllers
433 struct uwb_dev
*uwb_dev_get_by_devaddr(struct uwb_rc
*rc
,
434 const struct uwb_dev_addr
*devaddr
);
435 struct uwb_dev
*uwb_dev_get_by_rc(struct uwb_dev
*, struct uwb_rc
*);
436 static inline void uwb_dev_get(struct uwb_dev
*uwb_dev
)
438 get_device(&uwb_dev
->dev
);
440 static inline void uwb_dev_put(struct uwb_dev
*uwb_dev
)
442 put_device(&uwb_dev
->dev
);
444 struct uwb_dev
*uwb_dev_try_get(struct uwb_rc
*rc
, struct uwb_dev
*uwb_dev
);
447 * Callback function for 'uwb_{dev,rc}_foreach()'.
449 * @dev: Linux device instance
450 * 'uwb_dev = container_of(dev, struct uwb_dev, dev)'
451 * @priv: Data passed by the caller to 'uwb_{dev,rc}_foreach()'.
453 * @returns: 0 to continue the iterations, any other val to stop
454 * iterating and return the value to the caller of
457 typedef int (*uwb_dev_for_each_f
)(struct device
*dev
, void *priv
);
458 int uwb_dev_for_each(struct uwb_rc
*rc
, uwb_dev_for_each_f func
, void *priv
);
460 struct uwb_rc
*uwb_rc_alloc(void);
461 struct uwb_rc
*uwb_rc_get_by_dev(const struct uwb_dev_addr
*);
462 struct uwb_rc
*uwb_rc_get_by_grandpa(const struct device
*);
463 void uwb_rc_put(struct uwb_rc
*rc
);
465 typedef void (*uwb_rc_cmd_cb_f
)(struct uwb_rc
*rc
, void *arg
,
466 struct uwb_rceb
*reply
, ssize_t reply_size
);
468 int uwb_rc_cmd_async(struct uwb_rc
*rc
, const char *cmd_name
,
469 struct uwb_rccb
*cmd
, size_t cmd_size
,
470 u8 expected_type
, u16 expected_event
,
471 uwb_rc_cmd_cb_f cb
, void *arg
);
472 ssize_t
uwb_rc_cmd(struct uwb_rc
*rc
, const char *cmd_name
,
473 struct uwb_rccb
*cmd
, size_t cmd_size
,
474 struct uwb_rceb
*reply
, size_t reply_size
);
475 ssize_t
uwb_rc_vcmd(struct uwb_rc
*rc
, const char *cmd_name
,
476 struct uwb_rccb
*cmd
, size_t cmd_size
,
477 u8 expected_type
, u16 expected_event
,
478 struct uwb_rceb
**preply
);
480 size_t __uwb_addr_print(char *, size_t, const unsigned char *, int);
482 int uwb_rc_dev_addr_set(struct uwb_rc
*, const struct uwb_dev_addr
*);
483 int uwb_rc_dev_addr_get(struct uwb_rc
*, struct uwb_dev_addr
*);
484 int uwb_rc_mac_addr_set(struct uwb_rc
*, const struct uwb_mac_addr
*);
485 int uwb_rc_mac_addr_get(struct uwb_rc
*, struct uwb_mac_addr
*);
486 int __uwb_mac_addr_assigned_check(struct device
*, void *);
487 int __uwb_dev_addr_assigned_check(struct device
*, void *);
489 /* Print in @buf a pretty repr of @addr */
490 static inline size_t uwb_dev_addr_print(char *buf
, size_t buf_size
,
491 const struct uwb_dev_addr
*addr
)
493 return __uwb_addr_print(buf
, buf_size
, addr
->data
, 0);
496 /* Print in @buf a pretty repr of @addr */
497 static inline size_t uwb_mac_addr_print(char *buf
, size_t buf_size
,
498 const struct uwb_mac_addr
*addr
)
500 return __uwb_addr_print(buf
, buf_size
, addr
->data
, 1);
503 /* @returns 0 if device addresses @addr2 and @addr1 are equal */
504 static inline int uwb_dev_addr_cmp(const struct uwb_dev_addr
*addr1
,
505 const struct uwb_dev_addr
*addr2
)
507 return memcmp(addr1
, addr2
, sizeof(*addr1
));
510 /* @returns 0 if MAC addresses @addr2 and @addr1 are equal */
511 static inline int uwb_mac_addr_cmp(const struct uwb_mac_addr
*addr1
,
512 const struct uwb_mac_addr
*addr2
)
514 return memcmp(addr1
, addr2
, sizeof(*addr1
));
517 /* @returns !0 if a MAC @addr is a broadcast address */
518 static inline int uwb_mac_addr_bcast(const struct uwb_mac_addr
*addr
)
520 struct uwb_mac_addr bcast
= {
521 .data
= { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
523 return !uwb_mac_addr_cmp(addr
, &bcast
);
526 /* @returns !0 if a MAC @addr is all zeroes*/
527 static inline int uwb_mac_addr_unset(const struct uwb_mac_addr
*addr
)
529 struct uwb_mac_addr unset
= {
530 .data
= { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
532 return !uwb_mac_addr_cmp(addr
, &unset
);
535 /* @returns !0 if the address is in use. */
536 static inline unsigned __uwb_dev_addr_assigned(struct uwb_rc
*rc
,
537 struct uwb_dev_addr
*addr
)
539 return uwb_dev_for_each(rc
, __uwb_dev_addr_assigned_check
, addr
);
543 * UWB Radio Controller API
545 * This API is used (in addition to the general API) to implement UWB
548 void uwb_rc_init(struct uwb_rc
*);
549 int uwb_rc_add(struct uwb_rc
*, struct device
*dev
, void *rc_priv
);
550 void uwb_rc_rm(struct uwb_rc
*);
551 void uwb_rc_neh_grok(struct uwb_rc
*, void *, size_t);
552 void uwb_rc_neh_error(struct uwb_rc
*, int);
553 void uwb_rc_reset_all(struct uwb_rc
*rc
);
554 void uwb_rc_pre_reset(struct uwb_rc
*rc
);
555 int uwb_rc_post_reset(struct uwb_rc
*rc
);
558 * uwb_rsv_is_owner - is the owner of this reservation the RC?
559 * @rsv: the reservation
561 static inline bool uwb_rsv_is_owner(struct uwb_rsv
*rsv
)
563 return rsv
->owner
== &rsv
->rc
->uwb_dev
;
567 * enum uwb_notifs - UWB events that can be passed to any listeners
568 * @UWB_NOTIF_ONAIR: a new neighbour has joined the beacon group.
569 * @UWB_NOTIF_OFFAIR: a neighbour has left the beacon group.
571 * Higher layers can register callback functions with the radio
572 * controller using uwb_notifs_register(). The radio controller
573 * maintains a list of all registered handlers and will notify all
574 * nodes when an event occurs.
581 /* Callback function registered with UWB */
582 struct uwb_notifs_handler
{
583 struct list_head list_node
;
584 void (*cb
)(void *, struct uwb_dev
*, enum uwb_notifs
);
588 int uwb_notifs_register(struct uwb_rc
*, struct uwb_notifs_handler
*);
589 int uwb_notifs_deregister(struct uwb_rc
*, struct uwb_notifs_handler
*);
593 * UWB radio controller Event Size Entry (for creating entry tables)
595 * WUSB and WHCI define events and notifications, and they might have
596 * fixed or variable size.
598 * Each event/notification has a size which is not necessarily known
599 * in advance based on the event code. As well, vendor specific
600 * events/notifications will have a size impossible to determine
601 * unless we know about the device's specific details.
603 * It was way too smart of the spec writers not to think that it would
604 * be impossible for a generic driver to skip over vendor specific
605 * events/notifications if there are no LENGTH fields in the HEADER of
606 * each message...the transaction size cannot be counted on as the
607 * spec does not forbid to pack more than one event in a single
610 * Thus, we guess sizes with tables (or for events, when you know the
611 * size ahead of time you can use uwb_rc_neh_extra_size*()). We
612 * register tables with the known events and their sizes, and then we
613 * traverse those tables. For those with variable length, we provide a
614 * way to lookup the size inside the event/notification's
615 * payload. This allows device-specific event size tables to be
618 * @size: Size of the payload
620 * @offset: if != 0, at offset @offset-1 starts a field with a length
621 * that has to be added to @size. The format of the field is
624 * @type: Type and length of the offset field. Most common is LE 16
625 * bits (that's why that is zero); others are there mostly to
626 * cover for bugs and weirdos.
628 struct uwb_est_entry
{
631 enum { UWB_EST_16
= 0, UWB_EST_8
= 1 } type
;
634 int uwb_est_register(u8 type
, u8 code_high
, u16 vendor
, u16 product
,
635 const struct uwb_est_entry
*, size_t entries
);
636 int uwb_est_unregister(u8 type
, u8 code_high
, u16 vendor
, u16 product
,
637 const struct uwb_est_entry
*, size_t entries
);
638 ssize_t
uwb_est_find_size(struct uwb_rc
*rc
, const struct uwb_rceb
*rceb
,
645 EDC_ERROR_TIMEFRAME
= HZ
,
648 /* error density counter */
650 unsigned long timestart
;
655 void edc_init(struct edc
*edc
)
657 edc
->timestart
= jiffies
;
660 /* Called when an error occured.
661 * This is way to determine if the number of acceptable errors per time
662 * period has been exceeded. It is not accurate as there are cases in which
663 * this scheme will not work, for example if there are periodic occurences
664 * of errors that straddle updates to the start time. This scheme is
665 * sufficient for our usage.
667 * @returns 1 if maximum acceptable errors per timeframe has been exceeded.
669 static inline int edc_inc(struct edc
*err_hist
, u16 max_err
, u16 timeframe
)
674 if (now
- err_hist
->timestart
> timeframe
) {
675 err_hist
->errorcount
= 1;
676 err_hist
->timestart
= now
;
677 } else if (++err_hist
->errorcount
> max_err
) {
678 err_hist
->errorcount
= 0;
679 err_hist
->timestart
= now
;
686 /* Information Element handling */
688 struct uwb_ie_hdr
*uwb_ie_next(void **ptr
, size_t *len
);
689 int uwb_rc_ie_add(struct uwb_rc
*uwb_rc
, const struct uwb_ie_hdr
*ies
, size_t size
);
690 int uwb_rc_ie_rm(struct uwb_rc
*uwb_rc
, enum uwb_ie element_id
);
699 void stats_init(struct stats
*stats
)
701 atomic_set(&stats
->samples
, 0);
706 void stats_add_sample(struct stats
*stats
, s8 sample
)
710 unsigned samples
= atomic_read(&stats
->samples
);
711 if (samples
== 0) { /* it was zero before, so we initialize */
718 sigma
= stats
->sigma
;
721 if (sample
< min
) /* compute new values */
723 else if (sample
> max
)
727 stats
->min
= min
; /* commit */
729 stats
->sigma
= sigma
;
730 if (atomic_add_return(1, &stats
->samples
) > 255) {
731 /* wrapped around! reset */
732 stats
->sigma
= sigma
/ 256;
733 atomic_set(&stats
->samples
, 1);
737 static inline ssize_t
stats_show(struct stats
*stats
, char *buf
)
740 int samples
= atomic_read(&stats
->samples
);
746 avg
= stats
->sigma
/ samples
;
748 return scnprintf(buf
, PAGE_SIZE
, "%d %d %d\n", min
, max
, avg
);
751 static inline ssize_t
stats_store(struct stats
*stats
, const char *buf
,
758 #endif /* #ifndef __LINUX__UWB_H__ */