18 #include <linux/kernel.h>
20 #include <linux/slab.h>
21 #include <linux/random.h>
22 #include <linux/export.h>
26 static void uwb_rsv_timer(
unsigned long arg);
28 static const char *rsv_states[] = {
49 static const char *rsv_types[] = {
59 static const bool has_two_drp_ies[] = {
79 return has_two_drp_ies[rsv->
state];
90 return rsv_states[
state];
102 return rsv_types[
type];
112 uwb_dev_addr_print(owner,
sizeof(owner), &rsv->
owner->dev_addr);
114 devaddr = rsv->
target.dev->dev_addr;
116 devaddr = rsv->
target.devaddr;
117 uwb_dev_addr_print(target,
sizeof(target), &devaddr);
119 dev_dbg(dev,
"rsv %s %s -> %s: %s\n",
123 static void uwb_rsv_release(
struct kref *
kref)
132 kref_get(&rsv->
kref);
137 kref_put(&rsv->
kref, uwb_rsv_release);
147 static int uwb_rsv_get_stream(
struct uwb_rsv *
rsv)
151 unsigned long *streams_bm;
154 switch (rsv->
target.type) {
156 streams_bm = rsv->
target.dev->streams;
159 streams_bm = rc->
uwb_dev.streams;
177 static void uwb_rsv_put_stream(
struct uwb_rsv *rsv)
181 unsigned long *streams_bm;
183 switch (rsv->
target.type) {
185 streams_bm = rsv->
target.dev->streams;
188 streams_bm = rc->
uwb_dev.streams;
226 dev_dbg(dev,
"backoff_win_increment: window=%d\n", bow->
window);
243 static void uwb_rsv_stroke_timer(
struct uwb_rsv *rsv)
278 static void uwb_rsv_state_update(
struct uwb_rsv *rsv,
286 uwb_rsv_stroke_timer(rsv);
290 static void uwb_rsv_callback(
struct uwb_rsv *rsv)
300 if (rsv->
state == new_state) {
301 switch (rsv->
state) {
310 uwb_rsv_stroke_timer(rsv);
325 uwb_rsv_callback(rsv);
346 uwb_rsv_callback(rsv);
374 uwb_rsv_callback(rsv);
391 dev_err(&rsv->
rc->uwb_dev.dev,
"unhandled state: %s (%d)\n",
406 switch (rsv->
state) {
465 kref_init(&rsv->
kref);
467 rsv->
timer.function = uwb_rsv_timer;
493 rsv = uwb_rsv_alloc(rc);
515 if (uwb_rsv_is_owner(rsv))
516 uwb_rsv_put_stream(rsv);
518 uwb_dev_put(rsv->
owner);
520 uwb_dev_put(rsv->
target.dev);
556 ret = uwb_rsv_get_stream(rsv);
567 uwb_rsv_put_stream(rsv);
573 uwb_rsv_put_stream(rsv);
580 uwb_dev_get(rsv->
owner);
629 dev_dbg(dev,
"new allocation not found\n");
712 stream = uwb_ie_drp_stream_index(drp_ie);
714 if (rsv->
stream != stream)
717 switch (rsv->
target.type) {
719 return rsv->
stream == stream;
721 if (uwb_ie_drp_owner(drp_ie))
722 rsv_src = &rsv->
owner->dev_addr;
724 rsv_src = &rsv->
target.dev->dev_addr;
725 return uwb_dev_addr_cmp(&src->
dev_addr, rsv_src) == 0;
738 rsv = uwb_rsv_alloc(rc);
744 uwb_dev_get(rsv->
owner);
748 rsv->
type = uwb_ie_drp_type(drp_ie);
749 rsv->
stream = uwb_ie_drp_stream_index(drp_ie);
792 bitmap_andnot(mas->bm, rsv->
mas.bm, rsv->
rc->cnflt_alien_bitmap.bm,
UWB_NUM_MAS);
812 if (uwb_rsv_match(rsv, src, drp_ie))
816 if (uwb_ie_drp_owner(drp_ie))
817 return uwb_rsv_new_target(rc, src, drp_ie);
829 static bool uwb_rsv_update_all(
struct uwb_rc *rc)
832 bool ie_updated =
false;
891 static void uwb_rsv_update_work(
struct work_struct *work)
899 ie_updated = uwb_rsv_update_all(rc);
912 static void uwb_rsv_alien_bp_work(
struct work_struct *work)
929 static void uwb_rsv_timer(
unsigned long arg)
974 rc->
bow.can_reserve_extra_mases =
true;
975 rc->
bow.total_expired = 0;