Greg Kroah-Hartman | 5fd54ac | 2017-11-03 11:28:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 2 | /* |
| 3 | * WUSB cluster reservation management |
| 4 | * |
| 5 | * Copyright (C) 2007 Cambridge Silicon Radio Ltd. |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 6 | */ |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/uwb.h> |
| 9 | |
| 10 | #include "wusbhc.h" |
| 11 | |
| 12 | /* |
| 13 | * WUSB cluster reservations are multicast reservations with the |
| 14 | * broadcast cluster ID (BCID) as the target DevAddr. |
| 15 | * |
| 16 | * FIXME: consider adjusting the reservation depending on what devices |
| 17 | * are attached. |
| 18 | */ |
| 19 | |
| 20 | static int wusbhc_bwa_set(struct wusbhc *wusbhc, u8 stream, |
| 21 | const struct uwb_mas_bm *mas) |
| 22 | { |
| 23 | if (mas == NULL) |
| 24 | mas = &uwb_mas_bm_zero; |
| 25 | return wusbhc->bwa_set(wusbhc, stream, mas); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * wusbhc_rsv_complete_cb - WUSB HC reservation complete callback |
| 30 | * @rsv: the reservation |
| 31 | * |
| 32 | * Either set or clear the HC's view of the reservation. |
| 33 | * |
| 34 | * FIXME: when a reservation is denied the HC should be stopped. |
| 35 | */ |
| 36 | static void wusbhc_rsv_complete_cb(struct uwb_rsv *rsv) |
| 37 | { |
| 38 | struct wusbhc *wusbhc = rsv->pal_priv; |
| 39 | struct device *dev = wusbhc->dev; |
Stefano Panella | 5b37717 | 2008-12-12 13:00:06 +0000 | [diff] [blame] | 40 | struct uwb_mas_bm mas; |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 41 | |
Thomas Pugliese | b4a9dfb | 2013-12-20 11:45:02 -0600 | [diff] [blame] | 42 | dev_dbg(dev, "%s: state = %d\n", __func__, rsv->state); |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 43 | switch (rsv->state) { |
| 44 | case UWB_RSV_STATE_O_ESTABLISHED: |
Stefano Panella | 5b37717 | 2008-12-12 13:00:06 +0000 | [diff] [blame] | 45 | uwb_rsv_get_usable_mas(rsv, &mas); |
Tejun Heo | 125918d | 2015-02-13 14:37:53 -0800 | [diff] [blame] | 46 | dev_dbg(dev, "established reservation: %*pb\n", |
| 47 | UWB_NUM_MAS, mas.bm); |
Stefano Panella | 5b37717 | 2008-12-12 13:00:06 +0000 | [diff] [blame] | 48 | wusbhc_bwa_set(wusbhc, rsv->stream, &mas); |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 49 | break; |
| 50 | case UWB_RSV_STATE_NONE: |
| 51 | dev_dbg(dev, "removed reservation\n"); |
| 52 | wusbhc_bwa_set(wusbhc, 0, NULL); |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 53 | break; |
| 54 | default: |
| 55 | dev_dbg(dev, "unexpected reservation state: %d\n", rsv->state); |
| 56 | break; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | |
| 61 | /** |
| 62 | * wusbhc_rsv_establish - establish a reservation for the cluster |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 63 | * @wusbhc: the WUSB HC requesting a bandwidth reservation |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 64 | */ |
| 65 | int wusbhc_rsv_establish(struct wusbhc *wusbhc) |
| 66 | { |
| 67 | struct uwb_rc *rc = wusbhc->uwb_rc; |
| 68 | struct uwb_rsv *rsv; |
| 69 | struct uwb_dev_addr bcid; |
| 70 | int ret; |
| 71 | |
Thomas Pugliese | a899575 | 2013-06-24 14:26:35 -0500 | [diff] [blame] | 72 | if (rc == NULL) |
| 73 | return -ENODEV; |
| 74 | |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 75 | rsv = uwb_rsv_create(rc, wusbhc_rsv_complete_cb, wusbhc); |
| 76 | if (rsv == NULL) |
| 77 | return -ENOMEM; |
| 78 | |
| 79 | bcid.data[0] = wusbhc->cluster_id; |
| 80 | bcid.data[1] = 0; |
| 81 | |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 82 | rsv->target.type = UWB_RSV_TARGET_DEVADDR; |
| 83 | rsv->target.devaddr = bcid; |
| 84 | rsv->type = UWB_DRP_TYPE_PRIVATE; |
Stefano Panella | 5b37717 | 2008-12-12 13:00:06 +0000 | [diff] [blame] | 85 | rsv->max_mas = 256; /* try to get as much as possible */ |
| 86 | rsv->min_mas = 15; /* one MAS per zone */ |
| 87 | rsv->max_interval = 1; /* max latency is one zone */ |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 88 | rsv->is_multicast = true; |
| 89 | |
| 90 | ret = uwb_rsv_establish(rsv); |
| 91 | if (ret == 0) |
| 92 | wusbhc->rsv = rsv; |
| 93 | else |
| 94 | uwb_rsv_destroy(rsv); |
| 95 | return ret; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | /** |
David Vrabel | cae1c11 | 2008-10-27 15:22:46 +0000 | [diff] [blame] | 100 | * wusbhc_rsv_terminate - terminate the cluster reservation |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 101 | * @wusbhc: the WUSB host whose reservation is to be terminated |
| 102 | */ |
| 103 | void wusbhc_rsv_terminate(struct wusbhc *wusbhc) |
| 104 | { |
David Vrabel | fe6e87a | 2008-12-12 13:25:21 +0000 | [diff] [blame] | 105 | if (wusbhc->rsv) { |
| 106 | uwb_rsv_terminate(wusbhc->rsv); |
| 107 | uwb_rsv_destroy(wusbhc->rsv); |
| 108 | wusbhc->rsv = NULL; |
| 109 | } |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 110 | } |