Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * WUSB cluster reservation management |
| 3 | * |
| 4 | * Copyright (C) 2007 Cambridge Silicon Radio Ltd. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License version |
| 8 | * 2 as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/uwb.h> |
| 20 | |
| 21 | #include "wusbhc.h" |
| 22 | |
| 23 | /* |
| 24 | * WUSB cluster reservations are multicast reservations with the |
| 25 | * broadcast cluster ID (BCID) as the target DevAddr. |
| 26 | * |
| 27 | * FIXME: consider adjusting the reservation depending on what devices |
| 28 | * are attached. |
| 29 | */ |
| 30 | |
| 31 | static int wusbhc_bwa_set(struct wusbhc *wusbhc, u8 stream, |
| 32 | const struct uwb_mas_bm *mas) |
| 33 | { |
| 34 | if (mas == NULL) |
| 35 | mas = &uwb_mas_bm_zero; |
| 36 | return wusbhc->bwa_set(wusbhc, stream, mas); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * wusbhc_rsv_complete_cb - WUSB HC reservation complete callback |
| 41 | * @rsv: the reservation |
| 42 | * |
| 43 | * Either set or clear the HC's view of the reservation. |
| 44 | * |
| 45 | * FIXME: when a reservation is denied the HC should be stopped. |
| 46 | */ |
| 47 | static void wusbhc_rsv_complete_cb(struct uwb_rsv *rsv) |
| 48 | { |
| 49 | struct wusbhc *wusbhc = rsv->pal_priv; |
| 50 | struct device *dev = wusbhc->dev; |
Stefano Panella | 5b37717 | 2008-12-12 13:00:06 +0000 | [diff] [blame] | 51 | struct uwb_mas_bm mas; |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 52 | char buf[72]; |
| 53 | |
Thomas Pugliese | b4a9dfb | 2013-12-20 11:45:02 -0600 | [diff] [blame] | 54 | dev_dbg(dev, "%s: state = %d\n", __func__, rsv->state); |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 55 | switch (rsv->state) { |
| 56 | case UWB_RSV_STATE_O_ESTABLISHED: |
Stefano Panella | 5b37717 | 2008-12-12 13:00:06 +0000 | [diff] [blame] | 57 | uwb_rsv_get_usable_mas(rsv, &mas); |
| 58 | bitmap_scnprintf(buf, sizeof(buf), mas.bm, UWB_NUM_MAS); |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 59 | dev_dbg(dev, "established reservation: %s\n", buf); |
Stefano Panella | 5b37717 | 2008-12-12 13:00:06 +0000 | [diff] [blame] | 60 | wusbhc_bwa_set(wusbhc, rsv->stream, &mas); |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 61 | break; |
| 62 | case UWB_RSV_STATE_NONE: |
| 63 | dev_dbg(dev, "removed reservation\n"); |
| 64 | wusbhc_bwa_set(wusbhc, 0, NULL); |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 65 | break; |
| 66 | default: |
| 67 | dev_dbg(dev, "unexpected reservation state: %d\n", rsv->state); |
| 68 | break; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | |
| 73 | /** |
| 74 | * wusbhc_rsv_establish - establish a reservation for the cluster |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 75 | * @wusbhc: the WUSB HC requesting a bandwidth reservation |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 76 | */ |
| 77 | int wusbhc_rsv_establish(struct wusbhc *wusbhc) |
| 78 | { |
| 79 | struct uwb_rc *rc = wusbhc->uwb_rc; |
| 80 | struct uwb_rsv *rsv; |
| 81 | struct uwb_dev_addr bcid; |
| 82 | int ret; |
| 83 | |
Thomas Pugliese | a899575 | 2013-06-24 14:26:35 -0500 | [diff] [blame] | 84 | if (rc == NULL) |
| 85 | return -ENODEV; |
| 86 | |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 87 | rsv = uwb_rsv_create(rc, wusbhc_rsv_complete_cb, wusbhc); |
| 88 | if (rsv == NULL) |
| 89 | return -ENOMEM; |
| 90 | |
| 91 | bcid.data[0] = wusbhc->cluster_id; |
| 92 | bcid.data[1] = 0; |
| 93 | |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 94 | rsv->target.type = UWB_RSV_TARGET_DEVADDR; |
| 95 | rsv->target.devaddr = bcid; |
| 96 | rsv->type = UWB_DRP_TYPE_PRIVATE; |
Stefano Panella | 5b37717 | 2008-12-12 13:00:06 +0000 | [diff] [blame] | 97 | rsv->max_mas = 256; /* try to get as much as possible */ |
| 98 | rsv->min_mas = 15; /* one MAS per zone */ |
| 99 | rsv->max_interval = 1; /* max latency is one zone */ |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 100 | rsv->is_multicast = true; |
| 101 | |
| 102 | ret = uwb_rsv_establish(rsv); |
| 103 | if (ret == 0) |
| 104 | wusbhc->rsv = rsv; |
| 105 | else |
| 106 | uwb_rsv_destroy(rsv); |
| 107 | return ret; |
| 108 | } |
| 109 | |
| 110 | |
| 111 | /** |
David Vrabel | cae1c11 | 2008-10-27 15:22:46 +0000 | [diff] [blame] | 112 | * wusbhc_rsv_terminate - terminate the cluster reservation |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 113 | * @wusbhc: the WUSB host whose reservation is to be terminated |
| 114 | */ |
| 115 | void wusbhc_rsv_terminate(struct wusbhc *wusbhc) |
| 116 | { |
David Vrabel | fe6e87a | 2008-12-12 13:25:21 +0000 | [diff] [blame] | 117 | if (wusbhc->rsv) { |
| 118 | uwb_rsv_terminate(wusbhc->rsv); |
| 119 | uwb_rsv_destroy(wusbhc->rsv); |
| 120 | wusbhc->rsv = NULL; |
| 121 | } |
Inaky Perez-Gonzalez | 90ff96f | 2008-09-17 16:34:23 +0100 | [diff] [blame] | 122 | } |