Linux Audio

Check our new training course

Loading...
v3.1
 
  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
 31static 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 */
 47static void wusbhc_rsv_complete_cb(struct uwb_rsv *rsv)
 48{
 49	struct wusbhc *wusbhc = rsv->pal_priv;
 50	struct device *dev = wusbhc->dev;
 51	struct uwb_mas_bm mas;
 52	char buf[72];
 53
 
 54	switch (rsv->state) {
 55	case UWB_RSV_STATE_O_ESTABLISHED:
 56		uwb_rsv_get_usable_mas(rsv, &mas);
 57		bitmap_scnprintf(buf, sizeof(buf), mas.bm, UWB_NUM_MAS);
 58		dev_dbg(dev, "established reservation: %s\n", buf);
 59		wusbhc_bwa_set(wusbhc, rsv->stream, &mas);
 60		break;
 61	case UWB_RSV_STATE_NONE:
 62		dev_dbg(dev, "removed reservation\n");
 63		wusbhc_bwa_set(wusbhc, 0, NULL);
 64		break;
 65	default:
 66		dev_dbg(dev, "unexpected reservation state: %d\n", rsv->state);
 67		break;
 68	}
 69}
 70
 71
 72/**
 73 * wusbhc_rsv_establish - establish a reservation for the cluster
 74 * @wusbhc: the WUSB HC requesting a bandwidth reservation
 75 */
 76int wusbhc_rsv_establish(struct wusbhc *wusbhc)
 77{
 78	struct uwb_rc *rc = wusbhc->uwb_rc;
 79	struct uwb_rsv *rsv;
 80	struct uwb_dev_addr bcid;
 81	int ret;
 
 
 
 82
 83	rsv = uwb_rsv_create(rc, wusbhc_rsv_complete_cb, wusbhc);
 84	if (rsv == NULL)
 85		return -ENOMEM;
 86
 87	bcid.data[0] = wusbhc->cluster_id;
 88	bcid.data[1] = 0;
 89
 90	rsv->target.type = UWB_RSV_TARGET_DEVADDR;
 91	rsv->target.devaddr = bcid;
 92	rsv->type = UWB_DRP_TYPE_PRIVATE;
 93	rsv->max_mas = 256; /* try to get as much as possible */
 94	rsv->min_mas = 15;  /* one MAS per zone */
 95	rsv->max_interval = 1; /* max latency is one zone */
 96	rsv->is_multicast = true;
 97
 98	ret = uwb_rsv_establish(rsv);
 99	if (ret == 0)
100		wusbhc->rsv = rsv;
101	else
102		uwb_rsv_destroy(rsv);
103	return ret;
104}
105
106
107/**
108 * wusbhc_rsv_terminate - terminate the cluster reservation
109 * @wusbhc: the WUSB host whose reservation is to be terminated
110 */
111void wusbhc_rsv_terminate(struct wusbhc *wusbhc)
112{
113	if (wusbhc->rsv) {
114		uwb_rsv_terminate(wusbhc->rsv);
115		uwb_rsv_destroy(wusbhc->rsv);
116		wusbhc->rsv = NULL;
117	}
118}
v4.17
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * WUSB cluster reservation management
  4 *
  5 * Copyright (C) 2007 Cambridge Silicon Radio Ltd.
 
 
 
 
 
 
 
 
 
 
 
 
  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
 20static 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 */
 36static void wusbhc_rsv_complete_cb(struct uwb_rsv *rsv)
 37{
 38	struct wusbhc *wusbhc = rsv->pal_priv;
 39	struct device *dev = wusbhc->dev;
 40	struct uwb_mas_bm mas;
 
 41
 42	dev_dbg(dev, "%s: state = %d\n", __func__, rsv->state);
 43	switch (rsv->state) {
 44	case UWB_RSV_STATE_O_ESTABLISHED:
 45		uwb_rsv_get_usable_mas(rsv, &mas);
 46		dev_dbg(dev, "established reservation: %*pb\n",
 47			UWB_NUM_MAS, mas.bm);
 48		wusbhc_bwa_set(wusbhc, rsv->stream, &mas);
 49		break;
 50	case UWB_RSV_STATE_NONE:
 51		dev_dbg(dev, "removed reservation\n");
 52		wusbhc_bwa_set(wusbhc, 0, NULL);
 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
 63 * @wusbhc: the WUSB HC requesting a bandwidth reservation
 64 */
 65int 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
 72	if (rc == NULL)
 73		return -ENODEV;
 74
 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
 82	rsv->target.type = UWB_RSV_TARGET_DEVADDR;
 83	rsv->target.devaddr = bcid;
 84	rsv->type = UWB_DRP_TYPE_PRIVATE;
 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 */
 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/**
100 * wusbhc_rsv_terminate - terminate the cluster reservation
101 * @wusbhc: the WUSB host whose reservation is to be terminated
102 */
103void wusbhc_rsv_terminate(struct wusbhc *wusbhc)
104{
105	if (wusbhc->rsv) {
106		uwb_rsv_terminate(wusbhc->rsv);
107		uwb_rsv_destroy(wusbhc->rsv);
108		wusbhc->rsv = NULL;
109	}
110}