Linux Audio

Check our new training course

Loading...
v3.5.6
  1/*
  2 * Wireless Host Controller (WHC) WUSB operations.
  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/init.h>
 20#include <linux/uwb/umc.h>
 21
 22#include "../../wusbcore/wusbhc.h"
 23
 24#include "whcd.h"
 25
 26static int whc_update_di(struct whc *whc, int idx)
 27{
 28	int offset = idx / 32;
 29	u32 bit = 1 << (idx % 32);
 30
 31	le_writel(bit, whc->base + WUSBDIBUPDATED + offset);
 32
 33	return whci_wait_for(&whc->umc->dev,
 34			     whc->base + WUSBDIBUPDATED + offset, bit, 0,
 35			     100, "DI update");
 36}
 37
 38/*
 39 * WHCI starts MMCs based on there being a valid GTK so these need
 40 * only start/stop the asynchronous and periodic schedules and send a
 41 * channel stop command.
 42 */
 43
 44int whc_wusbhc_start(struct wusbhc *wusbhc)
 45{
 46	struct whc *whc = wusbhc_to_whc(wusbhc);
 47
 48	asl_start(whc);
 49	pzl_start(whc);
 50
 51	return 0;
 52}
 53
 54void whc_wusbhc_stop(struct wusbhc *wusbhc, int delay)
 55{
 56	struct whc *whc = wusbhc_to_whc(wusbhc);
 57	u32 stop_time, now_time;
 58	int ret;
 59
 60	pzl_stop(whc);
 61	asl_stop(whc);
 62
 63	now_time = le_readl(whc->base + WUSBTIME) & WUSBTIME_CHANNEL_TIME_MASK;
 64	stop_time = (now_time + ((delay * 8) << 7)) & 0x00ffffff;
 65	ret = whc_do_gencmd(whc, WUSBGENCMDSTS_CHAN_STOP, stop_time, NULL, 0);
 66	if (ret == 0)
 67		msleep(delay);
 68}
 69
 70int whc_mmcie_add(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt,
 71		  u8 handle, struct wuie_hdr *wuie)
 72{
 73	struct whc *whc = wusbhc_to_whc(wusbhc);
 74	u32 params;
 75
 76	params = (interval << 24)
 77		| (repeat_cnt << 16)
 78		| (wuie->bLength << 8)
 79		| handle;
 80
 81	return whc_do_gencmd(whc, WUSBGENCMDSTS_MMCIE_ADD, params, wuie, wuie->bLength);
 82}
 83
 84int whc_mmcie_rm(struct wusbhc *wusbhc, u8 handle)
 85{
 86	struct whc *whc = wusbhc_to_whc(wusbhc);
 87	u32 params;
 88
 89	params = handle;
 90
 91	return whc_do_gencmd(whc, WUSBGENCMDSTS_MMCIE_RM, params, NULL, 0);
 92}
 93
 94int whc_bwa_set(struct wusbhc *wusbhc, s8 stream_index, const struct uwb_mas_bm *mas_bm)
 95{
 96	struct whc *whc = wusbhc_to_whc(wusbhc);
 97
 98	if (stream_index >= 0)
 99		whc_write_wusbcmd(whc, WUSBCMD_WUSBSI_MASK, WUSBCMD_WUSBSI(stream_index));
100
101	return whc_do_gencmd(whc, WUSBGENCMDSTS_SET_MAS, 0, (void *)mas_bm, sizeof(*mas_bm));
102}
103
104int whc_dev_info_set(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
105{
106	struct whc *whc = wusbhc_to_whc(wusbhc);
107	int idx = wusb_dev->port_idx;
108	struct di_buf_entry *di = &whc->di_buf[idx];
109	int ret;
110
111	mutex_lock(&whc->mutex);
112
113	uwb_mas_bm_copy_le(di->availability_info, &wusb_dev->availability);
114	di->addr_sec_info &= ~(WHC_DI_DISABLE | WHC_DI_DEV_ADDR_MASK);
115	di->addr_sec_info |= WHC_DI_DEV_ADDR(wusb_dev->addr);
116
117	ret = whc_update_di(whc, idx);
118
119	mutex_unlock(&whc->mutex);
120
121	return ret;
122}
123
124/*
125 * Set the number of Device Notification Time Slots (DNTS) and enable
126 * device notifications.
127 */
128int whc_set_num_dnts(struct wusbhc *wusbhc, u8 interval, u8 slots)
129{
130	struct whc *whc = wusbhc_to_whc(wusbhc);
131	u32 dntsctrl;
132
133	dntsctrl = WUSBDNTSCTRL_ACTIVE
134		| WUSBDNTSCTRL_INTERVAL(interval)
135		| WUSBDNTSCTRL_SLOTS(slots);
136
137	le_writel(dntsctrl, whc->base + WUSBDNTSCTRL);
138
139	return 0;
140}
141
142static int whc_set_key(struct whc *whc, u8 key_index, uint32_t tkid,
143		       const void *key, size_t key_size, bool is_gtk)
144{
145	uint32_t setkeycmd;
146	uint32_t seckey[4];
147	int i;
148	int ret;
149
150	memcpy(seckey, key, key_size);
151	setkeycmd = WUSBSETSECKEYCMD_SET | WUSBSETSECKEYCMD_IDX(key_index);
152	if (is_gtk)
153		setkeycmd |= WUSBSETSECKEYCMD_GTK;
154
155	le_writel(tkid, whc->base + WUSBTKID);
156	for (i = 0; i < 4; i++)
157		le_writel(seckey[i], whc->base + WUSBSECKEY + 4*i);
158	le_writel(setkeycmd, whc->base + WUSBSETSECKEYCMD);
159
160	ret = whci_wait_for(&whc->umc->dev, whc->base + WUSBSETSECKEYCMD,
161			    WUSBSETSECKEYCMD_SET, 0, 100, "set key");
162
163	return ret;
164}
165
166/**
167 * whc_set_ptk - set the PTK to use for a device.
168 *
169 * The index into the key table for this PTK is the same as the
170 * device's port index.
171 */
172int whc_set_ptk(struct wusbhc *wusbhc, u8 port_idx, u32 tkid,
173		const void *ptk, size_t key_size)
174{
175	struct whc *whc = wusbhc_to_whc(wusbhc);
176	struct di_buf_entry *di = &whc->di_buf[port_idx];
177	int ret;
178
179	mutex_lock(&whc->mutex);
180
181	if (ptk) {
182		ret = whc_set_key(whc, port_idx, tkid, ptk, key_size, false);
183		if (ret)
184			goto out;
185
186		di->addr_sec_info &= ~WHC_DI_KEY_IDX_MASK;
187		di->addr_sec_info |= WHC_DI_SECURE | WHC_DI_KEY_IDX(port_idx);
188	} else
189		di->addr_sec_info &= ~WHC_DI_SECURE;
190
191	ret = whc_update_di(whc, port_idx);
192out:
193	mutex_unlock(&whc->mutex);
194	return ret;
195}
196
197/**
198 * whc_set_gtk - set the GTK for subsequent broadcast packets
199 *
200 * The GTK is stored in the last entry in the key table (the previous
201 * N_DEVICES entries are for the per-device PTKs).
202 */
203int whc_set_gtk(struct wusbhc *wusbhc, u32 tkid,
204		const void *gtk, size_t key_size)
205{
206	struct whc *whc = wusbhc_to_whc(wusbhc);
207	int ret;
208
209	mutex_lock(&whc->mutex);
210
211	ret = whc_set_key(whc, whc->n_devices, tkid, gtk, key_size, true);
212
213	mutex_unlock(&whc->mutex);
214
215	return ret;
216}
217
218int whc_set_cluster_id(struct whc *whc, u8 bcid)
219{
220	whc_write_wusbcmd(whc, WUSBCMD_BCID_MASK, WUSBCMD_BCID(bcid));
221	return 0;
222}
v4.6
  1/*
  2 * Wireless Host Controller (WHC) WUSB operations.
  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/umc.h>
 20
 21#include "../../wusbcore/wusbhc.h"
 22
 23#include "whcd.h"
 24
 25static int whc_update_di(struct whc *whc, int idx)
 26{
 27	int offset = idx / 32;
 28	u32 bit = 1 << (idx % 32);
 29
 30	le_writel(bit, whc->base + WUSBDIBUPDATED + offset);
 31
 32	return whci_wait_for(&whc->umc->dev,
 33			     whc->base + WUSBDIBUPDATED + offset, bit, 0,
 34			     100, "DI update");
 35}
 36
 37/*
 38 * WHCI starts MMCs based on there being a valid GTK so these need
 39 * only start/stop the asynchronous and periodic schedules and send a
 40 * channel stop command.
 41 */
 42
 43int whc_wusbhc_start(struct wusbhc *wusbhc)
 44{
 45	struct whc *whc = wusbhc_to_whc(wusbhc);
 46
 47	asl_start(whc);
 48	pzl_start(whc);
 49
 50	return 0;
 51}
 52
 53void whc_wusbhc_stop(struct wusbhc *wusbhc, int delay)
 54{
 55	struct whc *whc = wusbhc_to_whc(wusbhc);
 56	u32 stop_time, now_time;
 57	int ret;
 58
 59	pzl_stop(whc);
 60	asl_stop(whc);
 61
 62	now_time = le_readl(whc->base + WUSBTIME) & WUSBTIME_CHANNEL_TIME_MASK;
 63	stop_time = (now_time + ((delay * 8) << 7)) & 0x00ffffff;
 64	ret = whc_do_gencmd(whc, WUSBGENCMDSTS_CHAN_STOP, stop_time, NULL, 0);
 65	if (ret == 0)
 66		msleep(delay);
 67}
 68
 69int whc_mmcie_add(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt,
 70		  u8 handle, struct wuie_hdr *wuie)
 71{
 72	struct whc *whc = wusbhc_to_whc(wusbhc);
 73	u32 params;
 74
 75	params = (interval << 24)
 76		| (repeat_cnt << 16)
 77		| (wuie->bLength << 8)
 78		| handle;
 79
 80	return whc_do_gencmd(whc, WUSBGENCMDSTS_MMCIE_ADD, params, wuie, wuie->bLength);
 81}
 82
 83int whc_mmcie_rm(struct wusbhc *wusbhc, u8 handle)
 84{
 85	struct whc *whc = wusbhc_to_whc(wusbhc);
 86	u32 params;
 87
 88	params = handle;
 89
 90	return whc_do_gencmd(whc, WUSBGENCMDSTS_MMCIE_RM, params, NULL, 0);
 91}
 92
 93int whc_bwa_set(struct wusbhc *wusbhc, s8 stream_index, const struct uwb_mas_bm *mas_bm)
 94{
 95	struct whc *whc = wusbhc_to_whc(wusbhc);
 96
 97	if (stream_index >= 0)
 98		whc_write_wusbcmd(whc, WUSBCMD_WUSBSI_MASK, WUSBCMD_WUSBSI(stream_index));
 99
100	return whc_do_gencmd(whc, WUSBGENCMDSTS_SET_MAS, 0, (void *)mas_bm, sizeof(*mas_bm));
101}
102
103int whc_dev_info_set(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
104{
105	struct whc *whc = wusbhc_to_whc(wusbhc);
106	int idx = wusb_dev->port_idx;
107	struct di_buf_entry *di = &whc->di_buf[idx];
108	int ret;
109
110	mutex_lock(&whc->mutex);
111
112	uwb_mas_bm_copy_le(di->availability_info, &wusb_dev->availability);
113	di->addr_sec_info &= ~(WHC_DI_DISABLE | WHC_DI_DEV_ADDR_MASK);
114	di->addr_sec_info |= WHC_DI_DEV_ADDR(wusb_dev->addr);
115
116	ret = whc_update_di(whc, idx);
117
118	mutex_unlock(&whc->mutex);
119
120	return ret;
121}
122
123/*
124 * Set the number of Device Notification Time Slots (DNTS) and enable
125 * device notifications.
126 */
127int whc_set_num_dnts(struct wusbhc *wusbhc, u8 interval, u8 slots)
128{
129	struct whc *whc = wusbhc_to_whc(wusbhc);
130	u32 dntsctrl;
131
132	dntsctrl = WUSBDNTSCTRL_ACTIVE
133		| WUSBDNTSCTRL_INTERVAL(interval)
134		| WUSBDNTSCTRL_SLOTS(slots);
135
136	le_writel(dntsctrl, whc->base + WUSBDNTSCTRL);
137
138	return 0;
139}
140
141static int whc_set_key(struct whc *whc, u8 key_index, uint32_t tkid,
142		       const void *key, size_t key_size, bool is_gtk)
143{
144	uint32_t setkeycmd;
145	uint32_t seckey[4];
146	int i;
147	int ret;
148
149	memcpy(seckey, key, key_size);
150	setkeycmd = WUSBSETSECKEYCMD_SET | WUSBSETSECKEYCMD_IDX(key_index);
151	if (is_gtk)
152		setkeycmd |= WUSBSETSECKEYCMD_GTK;
153
154	le_writel(tkid, whc->base + WUSBTKID);
155	for (i = 0; i < 4; i++)
156		le_writel(seckey[i], whc->base + WUSBSECKEY + 4*i);
157	le_writel(setkeycmd, whc->base + WUSBSETSECKEYCMD);
158
159	ret = whci_wait_for(&whc->umc->dev, whc->base + WUSBSETSECKEYCMD,
160			    WUSBSETSECKEYCMD_SET, 0, 100, "set key");
161
162	return ret;
163}
164
165/**
166 * whc_set_ptk - set the PTK to use for a device.
167 *
168 * The index into the key table for this PTK is the same as the
169 * device's port index.
170 */
171int whc_set_ptk(struct wusbhc *wusbhc, u8 port_idx, u32 tkid,
172		const void *ptk, size_t key_size)
173{
174	struct whc *whc = wusbhc_to_whc(wusbhc);
175	struct di_buf_entry *di = &whc->di_buf[port_idx];
176	int ret;
177
178	mutex_lock(&whc->mutex);
179
180	if (ptk) {
181		ret = whc_set_key(whc, port_idx, tkid, ptk, key_size, false);
182		if (ret)
183			goto out;
184
185		di->addr_sec_info &= ~WHC_DI_KEY_IDX_MASK;
186		di->addr_sec_info |= WHC_DI_SECURE | WHC_DI_KEY_IDX(port_idx);
187	} else
188		di->addr_sec_info &= ~WHC_DI_SECURE;
189
190	ret = whc_update_di(whc, port_idx);
191out:
192	mutex_unlock(&whc->mutex);
193	return ret;
194}
195
196/**
197 * whc_set_gtk - set the GTK for subsequent broadcast packets
198 *
199 * The GTK is stored in the last entry in the key table (the previous
200 * N_DEVICES entries are for the per-device PTKs).
201 */
202int whc_set_gtk(struct wusbhc *wusbhc, u32 tkid,
203		const void *gtk, size_t key_size)
204{
205	struct whc *whc = wusbhc_to_whc(wusbhc);
206	int ret;
207
208	mutex_lock(&whc->mutex);
209
210	ret = whc_set_key(whc, whc->n_devices, tkid, gtk, key_size, true);
211
212	mutex_unlock(&whc->mutex);
213
214	return ret;
215}
216
217int whc_set_cluster_id(struct whc *whc, u8 bcid)
218{
219	whc_write_wusbcmd(whc, WUSBCMD_BCID_MASK, WUSBCMD_BCID(bcid));
220	return 0;
221}