2 * Wireless Host Controller (WHC) WUSB operations.
4 * Copyright (C) 2007 Cambridge Silicon Radio Ltd.
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.
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.
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/>.
18 #include <linux/version.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/uwb/umc.h>
23 #include <linux/uwb/debug.h>
25 #include "../../wusbcore/wusbhc.h"
30 static void dump_di(struct whc *whc, int idx)
32 struct di_buf_entry *di = &whc->di_buf[idx];
33 struct device *dev = &whc->umc->dev;
36 bitmap_scnprintf(buf, sizeof(buf), (unsigned long *)di->availability_info, UWB_NUM_MAS);
38 d_printf(1, dev, "DI[%d]\n", idx);
39 d_printf(1, dev, " availability: %s\n", buf);
40 d_printf(1, dev, " %c%c key idx: %d dev addr: %d\n",
41 (di->addr_sec_info & WHC_DI_SECURE) ? 'S' : ' ',
42 (di->addr_sec_info & WHC_DI_DISABLE) ? 'D' : ' ',
43 (di->addr_sec_info & WHC_DI_KEY_IDX_MASK) >> 8,
44 (di->addr_sec_info & WHC_DI_DEV_ADDR_MASK));
47 static inline void dump_di(struct whc *whc, int idx)
52 static int whc_update_di(struct whc *whc, int idx)
54 int offset = idx / 32;
55 u32 bit = 1 << (idx % 32);
59 le_writel(bit, whc->base + WUSBDIBUPDATED + offset);
61 return whci_wait_for(&whc->umc->dev,
62 whc->base + WUSBDIBUPDATED + offset, bit, 0,
67 * WHCI starts MMCs based on there being a valid GTK so these need
68 * only start/stop the asynchronous and periodic schedules and send a
69 * channel stop command.
72 int whc_wusbhc_start(struct wusbhc *wusbhc)
74 struct whc *whc = wusbhc_to_whc(wusbhc);
82 void whc_wusbhc_stop(struct wusbhc *wusbhc, int delay)
84 struct whc *whc = wusbhc_to_whc(wusbhc);
85 u32 stop_time, now_time;
91 now_time = le_readl(whc->base + WUSBTIME) & WUSBTIME_CHANNEL_TIME_MASK;
92 stop_time = (now_time + ((delay * 8) << 7)) & 0x00ffffff;
93 ret = whc_do_gencmd(whc, WUSBGENCMDSTS_CHAN_STOP, stop_time, NULL, 0);
98 int whc_mmcie_add(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt,
99 u8 handle, struct wuie_hdr *wuie)
101 struct whc *whc = wusbhc_to_whc(wusbhc);
104 params = (interval << 24)
106 | (wuie->bLength << 8)
109 return whc_do_gencmd(whc, WUSBGENCMDSTS_MMCIE_ADD, params, wuie, wuie->bLength);
112 int whc_mmcie_rm(struct wusbhc *wusbhc, u8 handle)
114 struct whc *whc = wusbhc_to_whc(wusbhc);
119 return whc_do_gencmd(whc, WUSBGENCMDSTS_MMCIE_RM, params, NULL, 0);
122 int whc_bwa_set(struct wusbhc *wusbhc, s8 stream_index, const struct uwb_mas_bm *mas_bm)
124 struct whc *whc = wusbhc_to_whc(wusbhc);
126 if (stream_index >= 0)
127 whc_write_wusbcmd(whc, WUSBCMD_WUSBSI_MASK, WUSBCMD_WUSBSI(stream_index));
129 return whc_do_gencmd(whc, WUSBGENCMDSTS_SET_MAS, 0, (void *)mas_bm, sizeof(*mas_bm));
132 int whc_dev_info_set(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
134 struct whc *whc = wusbhc_to_whc(wusbhc);
135 int idx = wusb_dev->port_idx;
136 struct di_buf_entry *di = &whc->di_buf[idx];
139 mutex_lock(&whc->mutex);
141 uwb_mas_bm_copy_le(di->availability_info, &wusb_dev->availability);
142 di->addr_sec_info &= ~(WHC_DI_DISABLE | WHC_DI_DEV_ADDR_MASK);
143 di->addr_sec_info |= WHC_DI_DEV_ADDR(wusb_dev->addr);
145 ret = whc_update_di(whc, idx);
147 mutex_unlock(&whc->mutex);
153 * Set the number of Device Notification Time Slots (DNTS) and enable
154 * device notifications.
156 int whc_set_num_dnts(struct wusbhc *wusbhc, u8 interval, u8 slots)
158 struct whc *whc = wusbhc_to_whc(wusbhc);
161 dntsctrl = WUSBDNTSCTRL_ACTIVE
162 | WUSBDNTSCTRL_INTERVAL(interval)
163 | WUSBDNTSCTRL_SLOTS(slots);
165 le_writel(dntsctrl, whc->base + WUSBDNTSCTRL);
170 static int whc_set_key(struct whc *whc, u8 key_index, uint32_t tkid,
171 const void *key, size_t key_size, bool is_gtk)
178 memcpy(seckey, key, key_size);
179 setkeycmd = WUSBSETSECKEYCMD_SET | WUSBSETSECKEYCMD_IDX(key_index);
181 setkeycmd |= WUSBSETSECKEYCMD_GTK;
183 le_writel(tkid, whc->base + WUSBTKID);
184 for (i = 0; i < 4; i++)
185 le_writel(seckey[i], whc->base + WUSBSECKEY + 4*i);
186 le_writel(setkeycmd, whc->base + WUSBSETSECKEYCMD);
188 ret = whci_wait_for(&whc->umc->dev, whc->base + WUSBSETSECKEYCMD,
189 WUSBSETSECKEYCMD_SET, 0, 100, "set key");
195 * whc_set_ptk - set the PTK to use for a device.
197 * The index into the key table for this PTK is the same as the
198 * device's port index.
200 int whc_set_ptk(struct wusbhc *wusbhc, u8 port_idx, u32 tkid,
201 const void *ptk, size_t key_size)
203 struct whc *whc = wusbhc_to_whc(wusbhc);
204 struct di_buf_entry *di = &whc->di_buf[port_idx];
207 mutex_lock(&whc->mutex);
210 ret = whc_set_key(whc, port_idx, tkid, ptk, key_size, false);
214 di->addr_sec_info &= ~WHC_DI_KEY_IDX_MASK;
215 di->addr_sec_info |= WHC_DI_SECURE | WHC_DI_KEY_IDX(port_idx);
217 di->addr_sec_info &= ~WHC_DI_SECURE;
219 ret = whc_update_di(whc, port_idx);
221 mutex_unlock(&whc->mutex);
226 * whc_set_gtk - set the GTK for subsequent broadcast packets
228 * The GTK is stored in the last entry in the key table (the previous
229 * N_DEVICES entries are for the per-device PTKs).
231 int whc_set_gtk(struct wusbhc *wusbhc, u32 tkid,
232 const void *gtk, size_t key_size)
234 struct whc *whc = wusbhc_to_whc(wusbhc);
237 mutex_lock(&whc->mutex);
239 ret = whc_set_key(whc, whc->n_devices, tkid, gtk, key_size, true);
241 mutex_unlock(&whc->mutex);
246 int whc_set_cluster_id(struct whc *whc, u8 bcid)
248 whc_write_wusbcmd(whc, WUSBCMD_BCID_MASK, WUSBCMD_BCID(bcid));