• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6/drivers/usb/wusbcore/
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
24static int wusbhc_bwa_set(struct wusbhc *wusbhc, u8 stream,
25	const struct uwb_mas_bm *mas)
26{
27	if (mas == NULL)
28		mas = &uwb_mas_bm_zero;
29	return wusbhc->bwa_set(wusbhc, stream, mas);
30}
31
32static void wusbhc_rsv_complete_cb(struct uwb_rsv *rsv)
33{
34	struct wusbhc *wusbhc = rsv->pal_priv;
35	struct device *dev = wusbhc->dev;
36	struct uwb_mas_bm mas;
37	char buf[72];
38
39	switch (rsv->state) {
40	case UWB_RSV_STATE_O_ESTABLISHED:
41		uwb_rsv_get_usable_mas(rsv, &mas);
42		bitmap_scnprintf(buf, sizeof(buf), mas.bm, UWB_NUM_MAS);
43		dev_dbg(dev, "established reservation: %s\n", buf);
44		wusbhc_bwa_set(wusbhc, rsv->stream, &mas);
45		break;
46	case UWB_RSV_STATE_NONE:
47		dev_dbg(dev, "removed reservation\n");
48		wusbhc_bwa_set(wusbhc, 0, NULL);
49		break;
50	default:
51		dev_dbg(dev, "unexpected reservation state: %d\n", rsv->state);
52		break;
53	}
54}
55
56
57/**
58 * wusbhc_rsv_establish - establish a reservation for the cluster
59 * @wusbhc: the WUSB HC requesting a bandwith reservation
60 */
61int wusbhc_rsv_establish(struct wusbhc *wusbhc)
62{
63	struct uwb_rc *rc = wusbhc->uwb_rc;
64	struct uwb_rsv *rsv;
65	struct uwb_dev_addr bcid;
66	int ret;
67
68	rsv = uwb_rsv_create(rc, wusbhc_rsv_complete_cb, wusbhc);
69	if (rsv == NULL)
70		return -ENOMEM;
71
72	bcid.data[0] = wusbhc->cluster_id;
73	bcid.data[1] = 0;
74
75	rsv->target.type = UWB_RSV_TARGET_DEVADDR;
76	rsv->target.devaddr = bcid;
77	rsv->type = UWB_DRP_TYPE_PRIVATE;
78	rsv->max_mas = 256; /* try to get as much as possible */
79	rsv->min_mas = 15;  /* one MAS per zone */
80	rsv->max_interval = 1; /* max latency is one zone */
81	rsv->is_multicast = true;
82
83	ret = uwb_rsv_establish(rsv);
84	if (ret == 0)
85		wusbhc->rsv = rsv;
86	else
87		uwb_rsv_destroy(rsv);
88	return ret;
89}
90
91
92/**
93 * wusbhc_rsv_terminate - terminate the cluster reservation
94 * @wusbhc: the WUSB host whose reservation is to be terminated
95 */
96void wusbhc_rsv_terminate(struct wusbhc *wusbhc)
97{
98	if (wusbhc->rsv) {
99		uwb_rsv_terminate(wusbhc->rsv);
100		uwb_rsv_destroy(wusbhc->rsv);
101		wusbhc->rsv = NULL;
102	}
103}
104