diff options
Diffstat (limited to 'drivers/uwb')
-rw-r--r-- | drivers/uwb/Kconfig | 12 | ||||
-rw-r--r-- | drivers/uwb/Makefile | 1 | ||||
-rw-r--r-- | drivers/uwb/i1480/Makefile | 1 | ||||
-rw-r--r-- | drivers/uwb/i1480/dfu/Makefile | 9 | ||||
-rw-r--r-- | drivers/uwb/i1480/dfu/dfu.c | 281 | ||||
-rw-r--r-- | drivers/uwb/i1480/dfu/i1480-dfu.h | 263 | ||||
-rw-r--r-- | drivers/uwb/i1480/dfu/mac.c | 529 | ||||
-rw-r--r-- | drivers/uwb/i1480/dfu/phy.c | 203 | ||||
-rw-r--r-- | drivers/uwb/i1480/dfu/usb.c | 500 | ||||
-rw-r--r-- | drivers/uwb/i1480/i1480-est.c | 99 |
10 files changed, 1898 insertions, 0 deletions
diff --git a/drivers/uwb/Kconfig b/drivers/uwb/Kconfig index 41f8984d1984..59acb5b001d1 100644 --- a/drivers/uwb/Kconfig +++ b/drivers/uwb/Kconfig | |||
@@ -64,4 +64,16 @@ config UWB_WLP | |||
64 | This is a common library for drivers that implement | 64 | This is a common library for drivers that implement |
65 | networking over UWB. | 65 | networking over UWB. |
66 | 66 | ||
67 | config UWB_I1480U | ||
68 | tristate "Support for Intel Wireless UWB Link 1480 HWA" | ||
69 | depends on UWB_HWA | ||
70 | select FW_LOADER | ||
71 | help | ||
72 | This driver enables support for the i1480 when connected via | ||
73 | USB. It consists of a firmware uploader that will enable it | ||
74 | to behave as an HWA device. | ||
75 | |||
76 | To compile this driver select Y (built in) or M (module). It | ||
77 | is safe to select any even if you do not have the hardware. | ||
78 | |||
67 | endif # UWB | 79 | endif # UWB |
diff --git a/drivers/uwb/Makefile b/drivers/uwb/Makefile index 79f48e3d4ec6..257e6908304c 100644 --- a/drivers/uwb/Makefile +++ b/drivers/uwb/Makefile | |||
@@ -2,6 +2,7 @@ obj-$(CONFIG_UWB) += uwb.o | |||
2 | obj-$(CONFIG_UWB_WLP) += wlp/ | 2 | obj-$(CONFIG_UWB_WLP) += wlp/ |
3 | obj-$(CONFIG_UWB_WHCI) += umc.o whci.o whc-rc.o | 3 | obj-$(CONFIG_UWB_WHCI) += umc.o whci.o whc-rc.o |
4 | obj-$(CONFIG_UWB_HWA) += hwa-rc.o | 4 | obj-$(CONFIG_UWB_HWA) += hwa-rc.o |
5 | obj-$(CONFIG_UWB_I1480U) += i1480/ | ||
5 | 6 | ||
6 | uwb-objs := \ | 7 | uwb-objs := \ |
7 | address.o \ | 8 | address.o \ |
diff --git a/drivers/uwb/i1480/Makefile b/drivers/uwb/i1480/Makefile new file mode 100644 index 000000000000..d69da1684cfb --- /dev/null +++ b/drivers/uwb/i1480/Makefile | |||
@@ -0,0 +1 @@ | |||
obj-$(CONFIG_UWB_I1480U) += dfu/ i1480-est.o | |||
diff --git a/drivers/uwb/i1480/dfu/Makefile b/drivers/uwb/i1480/dfu/Makefile new file mode 100644 index 000000000000..bd1b9f25424c --- /dev/null +++ b/drivers/uwb/i1480/dfu/Makefile | |||
@@ -0,0 +1,9 @@ | |||
1 | obj-$(CONFIG_UWB_I1480U) += i1480-dfu-usb.o | ||
2 | |||
3 | i1480-dfu-usb-objs := \ | ||
4 | dfu.o \ | ||
5 | mac.o \ | ||
6 | phy.o \ | ||
7 | usb.o | ||
8 | |||
9 | |||
diff --git a/drivers/uwb/i1480/dfu/dfu.c b/drivers/uwb/i1480/dfu/dfu.c new file mode 100644 index 000000000000..ebffaf542153 --- /dev/null +++ b/drivers/uwb/i1480/dfu/dfu.c | |||
@@ -0,0 +1,281 @@ | |||
1 | /* | ||
2 | * Intel Wireless UWB Link 1480 | ||
3 | * Main driver | ||
4 | * | ||
5 | * Copyright (C) 2005-2006 Intel Corporation | ||
6 | * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License version | ||
10 | * 2 as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
20 | * 02110-1301, USA. | ||
21 | * | ||
22 | * | ||
23 | * Common code for firmware upload used by the USB and PCI version; | ||
24 | * i1480_fw_upload() takes a device descriptor and uses the function | ||
25 | * pointers it provides to upload firmware and prepare the PHY. | ||
26 | * | ||
27 | * As well, provides common functions used by the rest of the code. | ||
28 | */ | ||
29 | #include "i1480-dfu.h" | ||
30 | #include <linux/errno.h> | ||
31 | #include <linux/delay.h> | ||
32 | #include <linux/pci.h> | ||
33 | #include <linux/device.h> | ||
34 | #include <linux/uwb.h> | ||
35 | #include <linux/random.h> | ||
36 | |||
37 | #define D_LOCAL 0 | ||
38 | #include <linux/uwb/debug.h> | ||
39 | |||
40 | /** @return 0 if If @evt is a valid reply event; otherwise complain */ | ||
41 | int i1480_rceb_check(const struct i1480 *i1480, const struct uwb_rceb *rceb, | ||
42 | const char *cmd, u8 context, | ||
43 | unsigned expected_type, unsigned expected_event) | ||
44 | { | ||
45 | int result = 0; | ||
46 | struct device *dev = i1480->dev; | ||
47 | if (rceb->bEventContext != context) { | ||
48 | dev_err(dev, "%s: " | ||
49 | "unexpected context id 0x%02x (expected 0x%02x)\n", | ||
50 | cmd, rceb->bEventContext, context); | ||
51 | result = -EINVAL; | ||
52 | } | ||
53 | if (rceb->bEventType != expected_type) { | ||
54 | dev_err(dev, "%s: " | ||
55 | "unexpected event type 0x%02x (expected 0x%02x)\n", | ||
56 | cmd, rceb->bEventType, expected_type); | ||
57 | result = -EINVAL; | ||
58 | } | ||
59 | if (le16_to_cpu(rceb->wEvent) != expected_event) { | ||
60 | dev_err(dev, "%s: " | ||
61 | "unexpected event 0x%04x (expected 0x%04x)\n", | ||
62 | cmd, le16_to_cpu(rceb->wEvent), expected_event); | ||
63 | result = -EINVAL; | ||
64 | } | ||
65 | return result; | ||
66 | } | ||
67 | EXPORT_SYMBOL_GPL(i1480_rceb_check); | ||
68 | |||
69 | |||
70 | /** | ||
71 | * Execute a Radio Control Command | ||
72 | * | ||
73 | * Command data has to be in i1480->cmd_buf. | ||
74 | * | ||
75 | * @returns size of the reply data filled in i1480->evt_buf or < 0 errno | ||
76 | * code on error. | ||
77 | */ | ||
78 | ssize_t i1480_cmd(struct i1480 *i1480, const char *cmd_name, size_t cmd_size, | ||
79 | size_t reply_size) | ||
80 | { | ||
81 | ssize_t result; | ||
82 | struct uwb_rceb *reply = i1480->evt_buf; | ||
83 | struct uwb_rccb *cmd = i1480->cmd_buf; | ||
84 | u16 expected_event = reply->wEvent; | ||
85 | u8 expected_type = reply->bEventType; | ||
86 | u8 context; | ||
87 | |||
88 | d_fnstart(3, i1480->dev, "(%p, %s, %zu)\n", i1480, cmd_name, cmd_size); | ||
89 | init_completion(&i1480->evt_complete); | ||
90 | i1480->evt_result = -EINPROGRESS; | ||
91 | do { | ||
92 | get_random_bytes(&context, 1); | ||
93 | } while (context == 0x00 || context == 0xff); | ||
94 | cmd->bCommandContext = context; | ||
95 | result = i1480->cmd(i1480, cmd_name, cmd_size); | ||
96 | if (result < 0) | ||
97 | goto error; | ||
98 | /* wait for the callback to report a event was received */ | ||
99 | result = wait_for_completion_interruptible_timeout( | ||
100 | &i1480->evt_complete, HZ); | ||
101 | if (result == 0) { | ||
102 | result = -ETIMEDOUT; | ||
103 | goto error; | ||
104 | } | ||
105 | if (result < 0) | ||
106 | goto error; | ||
107 | result = i1480->evt_result; | ||
108 | if (result < 0) { | ||
109 | dev_err(i1480->dev, "%s: command reply reception failed: %zd\n", | ||
110 | cmd_name, result); | ||
111 | goto error; | ||
112 | } | ||
113 | if (result != reply_size) { | ||
114 | dev_err(i1480->dev, "%s returned only %zu bytes, %zu expected\n", | ||
115 | cmd_name, result, reply_size); | ||
116 | result = -EINVAL; | ||
117 | goto error; | ||
118 | } | ||
119 | /* Verify we got the right event in response */ | ||
120 | result = i1480_rceb_check(i1480, i1480->evt_buf, cmd_name, context, | ||
121 | expected_type, expected_event); | ||
122 | error: | ||
123 | d_fnend(3, i1480->dev, "(%p, %s, %zu) = %zd\n", | ||
124 | i1480, cmd_name, cmd_size, result); | ||
125 | return result; | ||
126 | } | ||
127 | EXPORT_SYMBOL_GPL(i1480_cmd); | ||
128 | |||
129 | |||
130 | /** | ||
131 | * Get information about the MAC and PHY | ||
132 | * | ||
133 | * @wa: Wired adaptor | ||
134 | * @neh: Notification/event handler | ||
135 | * @reply: Pointer to the reply event buffer | ||
136 | * @returns: 0 if ok, < 0 errno code on error. | ||
137 | */ | ||
138 | static | ||
139 | int i1480_cmd_get_mac_phy_info(struct i1480 *i1480) | ||
140 | { | ||
141 | int result; | ||
142 | struct uwb_rccb *cmd = i1480->cmd_buf; | ||
143 | struct i1480_evt_confirm_GMPI *reply = i1480->evt_buf; | ||
144 | |||
145 | cmd->bCommandType = i1480_CET_VS1; | ||
146 | cmd->wCommand = cpu_to_le16(i1480_CMD_GET_MAC_PHY_INFO); | ||
147 | reply->rceb.bEventType = i1480_CET_VS1; | ||
148 | reply->rceb.wEvent = i1480_EVT_GET_MAC_PHY_INFO; | ||
149 | result = i1480_cmd(i1480, "GET_MAC_PHY_INFO", sizeof(*cmd), | ||
150 | sizeof(*reply)); | ||
151 | if (result < 0) | ||
152 | goto out; | ||
153 | if (le16_to_cpu(reply->status) != 0x00) { | ||
154 | dev_err(i1480->dev, | ||
155 | "GET_MAC_PHY_INFO: command execution failed: %d\n", | ||
156 | reply->status); | ||
157 | result = -EIO; | ||
158 | } | ||
159 | out: | ||
160 | return result; | ||
161 | } | ||
162 | |||
163 | |||
164 | /** | ||
165 | * Get i1480's info and print it | ||
166 | * | ||
167 | * @wa: Wire Adapter | ||
168 | * @neh: Notification/event handler | ||
169 | * @returns: 0 if ok, < 0 errno code on error. | ||
170 | */ | ||
171 | static | ||
172 | int i1480_check_info(struct i1480 *i1480) | ||
173 | { | ||
174 | struct i1480_evt_confirm_GMPI *reply = i1480->evt_buf; | ||
175 | int result; | ||
176 | unsigned mac_fw_rev; | ||
177 | #if i1480_FW <= 0x00000302 | ||
178 | unsigned phy_fw_rev; | ||
179 | #endif | ||
180 | if (i1480->quirk_no_check_info) { | ||
181 | dev_err(i1480->dev, "firmware info check disabled\n"); | ||
182 | return 0; | ||
183 | } | ||
184 | |||
185 | result = i1480_cmd_get_mac_phy_info(i1480); | ||
186 | if (result < 0) { | ||
187 | dev_err(i1480->dev, "Cannot get MAC & PHY information: %d\n", | ||
188 | result); | ||
189 | goto out; | ||
190 | } | ||
191 | mac_fw_rev = le16_to_cpu(reply->mac_fw_rev); | ||
192 | #if i1480_FW > 0x00000302 | ||
193 | dev_info(i1480->dev, | ||
194 | "HW v%02hx " | ||
195 | "MAC FW v%02hx.%02hx caps %04hx " | ||
196 | "PHY type %02hx v%02hx caps %02hx %02hx %02hx\n", | ||
197 | reply->hw_rev, mac_fw_rev >> 8, mac_fw_rev & 0xff, | ||
198 | le16_to_cpu(reply->mac_caps), | ||
199 | reply->phy_vendor, reply->phy_rev, | ||
200 | reply->phy_caps[0], reply->phy_caps[1], reply->phy_caps[2]); | ||
201 | #else | ||
202 | phy_fw_rev = le16_to_cpu(reply->phy_fw_rev); | ||
203 | dev_info(i1480->dev, "MAC FW v%02hx.%02hx caps %04hx " | ||
204 | " PHY FW v%02hx.%02hx caps %04hx\n", | ||
205 | mac_fw_rev >> 8, mac_fw_rev & 0xff, | ||
206 | le16_to_cpu(reply->mac_caps), | ||
207 | phy_fw_rev >> 8, phy_fw_rev & 0xff, | ||
208 | le16_to_cpu(reply->phy_caps)); | ||
209 | #endif | ||
210 | dev_dbg(i1480->dev, | ||
211 | "key-stores:%hu mcast-addr-stores:%hu sec-modes:%hu\n", | ||
212 | (unsigned short) reply->key_stores, | ||
213 | le16_to_cpu(reply->mcast_addr_stores), | ||
214 | (unsigned short) reply->sec_mode_supported); | ||
215 | /* FIXME: complain if fw version too low -- pending for | ||
216 | * numbering to stabilize */ | ||
217 | out: | ||
218 | return result; | ||
219 | } | ||
220 | |||
221 | |||
222 | static | ||
223 | int i1480_print_state(struct i1480 *i1480) | ||
224 | { | ||
225 | int result; | ||
226 | u32 *buf = (u32 *) i1480->cmd_buf; | ||
227 | |||
228 | result = i1480->read(i1480, 0x80080000, 2 * sizeof(*buf)); | ||
229 | if (result < 0) { | ||
230 | dev_err(i1480->dev, "cannot read U & L states: %d\n", result); | ||
231 | goto error; | ||
232 | } | ||
233 | dev_info(i1480->dev, "state U 0x%08x, L 0x%08x\n", buf[0], buf[1]); | ||
234 | error: | ||
235 | return result; | ||
236 | } | ||
237 | |||
238 | |||
239 | /* | ||
240 | * PCI probe, firmware uploader | ||
241 | * | ||
242 | * _mac_fw_upload() will call rc_setup(), which needs an rc_release(). | ||
243 | */ | ||
244 | int i1480_fw_upload(struct i1480 *i1480) | ||
245 | { | ||
246 | int result; | ||
247 | |||
248 | result = i1480_pre_fw_upload(i1480); /* PHY pre fw */ | ||
249 | if (result < 0 && result != -ENOENT) { | ||
250 | i1480_print_state(i1480); | ||
251 | goto error; | ||
252 | } | ||
253 | result = i1480_mac_fw_upload(i1480); /* MAC fw */ | ||
254 | if (result < 0) { | ||
255 | if (result == -ENOENT) | ||
256 | dev_err(i1480->dev, "Cannot locate MAC FW file '%s'\n", | ||
257 | i1480->mac_fw_name); | ||
258 | else | ||
259 | i1480_print_state(i1480); | ||
260 | goto error; | ||
261 | } | ||
262 | result = i1480_phy_fw_upload(i1480); /* PHY fw */ | ||
263 | if (result < 0 && result != -ENOENT) { | ||
264 | i1480_print_state(i1480); | ||
265 | goto error_rc_release; | ||
266 | } | ||
267 | result = i1480_check_info(i1480); | ||
268 | if (result < 0) { | ||
269 | dev_warn(i1480->dev, "Warning! Cannot check firmware info: %d\n", | ||
270 | result); | ||
271 | result = 0; | ||
272 | } | ||
273 | dev_info(i1480->dev, "firmware uploaded successfully\n"); | ||
274 | error_rc_release: | ||
275 | if (i1480->rc_release) | ||
276 | i1480->rc_release(i1480); | ||
277 | result = 0; | ||
278 | error: | ||
279 | return result; | ||
280 | } | ||
281 | EXPORT_SYMBOL_GPL(i1480_fw_upload); | ||
diff --git a/drivers/uwb/i1480/dfu/i1480-dfu.h b/drivers/uwb/i1480/dfu/i1480-dfu.h new file mode 100644 index 000000000000..4103b287ac71 --- /dev/null +++ b/drivers/uwb/i1480/dfu/i1480-dfu.h | |||
@@ -0,0 +1,263 @@ | |||
1 | /* | ||
2 | * i1480 Device Firmware Upload | ||
3 | * | ||
4 | * Copyright (C) 2005-2006 Intel Corporation | ||
5 | * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License version | ||
9 | * 2 as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
19 | * 02110-1301, USA. | ||
20 | * | ||
21 | * | ||
22 | * This driver is the firmware uploader for the Intel Wireless UWB | ||
23 | * Link 1480 device (both in the USB and PCI incarnations). | ||
24 | * | ||
25 | * The process is quite simple: we stop the device, write the firmware | ||
26 | * to its memory and then restart it. Wait for the device to let us | ||
27 | * know it is done booting firmware. Ready. | ||
28 | * | ||
29 | * We might have to upload before or after a phy firmware (which might | ||
30 | * be done in two methods, using a normal firmware image or through | ||
31 | * the MPI port). | ||
32 | * | ||
33 | * Because USB and PCI use common methods, we just make ops out of the | ||
34 | * common operations (read, write, wait_init_done and cmd) and | ||
35 | * implement them in usb.c and pci.c. | ||
36 | * | ||
37 | * The flow is (some parts omitted): | ||
38 | * | ||
39 | * i1480_{usb,pci}_probe() On enumerate/discovery | ||
40 | * i1480_fw_upload() | ||
41 | * i1480_pre_fw_upload() | ||
42 | * __mac_fw_upload() | ||
43 | * fw_hdrs_load() | ||
44 | * mac_fw_hdrs_push() | ||
45 | * i1480->write() [i1480_{usb,pci}_write()] | ||
46 | * i1480_fw_cmp() | ||
47 | * i1480->read() [i1480_{usb,pci}_read()] | ||
48 | * i1480_mac_fw_upload() | ||
49 | * __mac_fw_upload() | ||
50 | * i1480->setup(() | ||
51 | * i1480->wait_init_done() | ||
52 | * i1480_cmd_reset() | ||
53 | * i1480->cmd() [i1480_{usb,pci}_cmd()] | ||
54 | * ... | ||
55 | * i1480_phy_fw_upload() | ||
56 | * request_firmware() | ||
57 | * i1480_mpi_write() | ||
58 | * i1480->cmd() [i1480_{usb,pci}_cmd()] | ||
59 | * i1480_check_info() | ||
60 | * | ||
61 | * Once the probe function enumerates the device and uploads the | ||
62 | * firmware, we just exit with -ENODEV, as we don't really want to | ||
63 | * attach to the device. | ||
64 | */ | ||
65 | #ifndef __i1480_DFU_H__ | ||
66 | #define __i1480_DFU_H__ | ||
67 | |||
68 | #include <linux/uwb/spec.h> | ||
69 | #include <linux/types.h> | ||
70 | #include <linux/completion.h> | ||
71 | |||
72 | #define i1480_FW_UPLOAD_MODE_MASK (cpu_to_le32(0x00000018)) | ||
73 | |||
74 | #if i1480_FW > 0x00000302 | ||
75 | #define i1480_RCEB_EXTENDED | ||
76 | #endif | ||
77 | |||
78 | struct uwb_rccb; | ||
79 | struct uwb_rceb; | ||
80 | |||
81 | /* | ||
82 | * Common firmware upload handlers | ||
83 | * | ||
84 | * Normally you embed this struct in another one specific to your hw. | ||
85 | * | ||
86 | * @write Write to device's memory from buffer. | ||
87 | * @read Read from device's memory to i1480->evt_buf. | ||
88 | * @setup Setup device after basic firmware is uploaded | ||
89 | * @wait_init_done | ||
90 | * Wait for the device to send a notification saying init | ||
91 | * is done. | ||
92 | * @cmd FOP for issuing the command to the hardware. The | ||
93 | * command data is contained in i1480->cmd_buf and the size | ||
94 | * is supplied as an argument. The command replied is put | ||
95 | * in i1480->evt_buf and the size in i1480->evt_result (or if | ||
96 | * an error, a < 0 errno code). | ||
97 | * | ||
98 | * @cmd_buf Memory buffer used to send commands to the device. | ||
99 | * Allocated by the upper layers i1480_fw_upload(). | ||
100 | * Size has to be @buf_size. | ||
101 | * @evt_buf Memory buffer used to place the async notifications | ||
102 | * received by the hw. Allocated by the upper layers | ||
103 | * i1480_fw_upload(). | ||
104 | * Size has to be @buf_size. | ||
105 | * @cmd_complete | ||
106 | * Low level driver uses this to notify code waiting afor | ||
107 | * an event that the event has arrived and data is in | ||
108 | * i1480->evt_buf (and size/result in i1480->evt_result). | ||
109 | * @hw_rev | ||
110 | * Use this value to activate dfu code to support new revisions | ||
111 | * of hardware. i1480_init() sets this to a default value. | ||
112 | * It should be updated by the USB and PCI code. | ||
113 | */ | ||
114 | struct i1480 { | ||
115 | struct device *dev; | ||
116 | |||
117 | int (*write)(struct i1480 *, u32 addr, const void *, size_t); | ||
118 | int (*read)(struct i1480 *, u32 addr, size_t); | ||
119 | int (*rc_setup)(struct i1480 *); | ||
120 | void (*rc_release)(struct i1480 *); | ||
121 | int (*wait_init_done)(struct i1480 *); | ||
122 | int (*cmd)(struct i1480 *, const char *cmd_name, size_t cmd_size); | ||
123 | const char *pre_fw_name; | ||
124 | const char *mac_fw_name; | ||
125 | const char *mac_fw_name_deprecate; /* FIXME: Will go away */ | ||
126 | const char *phy_fw_name; | ||
127 | u8 hw_rev; | ||
128 | |||
129 | size_t buf_size; /* size of both evt_buf and cmd_buf */ | ||
130 | void *evt_buf, *cmd_buf; | ||
131 | ssize_t evt_result; | ||
132 | struct completion evt_complete; | ||
133 | |||
134 | u8 quirk_no_check_info:1; | ||
135 | }; | ||
136 | |||
137 | static inline | ||
138 | void i1480_init(struct i1480 *i1480) | ||
139 | { | ||
140 | i1480->hw_rev = 1; | ||
141 | init_completion(&i1480->evt_complete); | ||
142 | } | ||
143 | |||
144 | extern int i1480_fw_upload(struct i1480 *); | ||
145 | extern int i1480_pre_fw_upload(struct i1480 *); | ||
146 | extern int i1480_mac_fw_upload(struct i1480 *); | ||
147 | extern int i1480_phy_fw_upload(struct i1480 *); | ||
148 | extern ssize_t i1480_cmd(struct i1480 *, const char *, size_t, size_t); | ||
149 | extern int i1480_rceb_check(const struct i1480 *, | ||
150 | const struct uwb_rceb *, const char *, u8, | ||
151 | unsigned, unsigned); | ||
152 | |||
153 | enum { | ||
154 | /* Vendor specific command type */ | ||
155 | i1480_CET_VS1 = 0xfd, | ||
156 | /* i1480 commands */ | ||
157 | i1480_CMD_SET_IP_MAS = 0x000e, | ||
158 | i1480_CMD_GET_MAC_PHY_INFO = 0x0003, | ||
159 | i1480_CMD_MPI_WRITE = 0x000f, | ||
160 | i1480_CMD_MPI_READ = 0x0010, | ||
161 | /* i1480 events */ | ||
162 | #if i1480_FW > 0x00000302 | ||
163 | i1480_EVT_CONFIRM = 0x0002, | ||
164 | i1480_EVT_RM_INIT_DONE = 0x0101, | ||
165 | i1480_EVT_DEV_ADD = 0x0103, | ||
166 | i1480_EVT_DEV_RM = 0x0104, | ||
167 | i1480_EVT_DEV_ID_CHANGE = 0x0105, | ||
168 | i1480_EVT_GET_MAC_PHY_INFO = i1480_CMD_GET_MAC_PHY_INFO, | ||
169 | #else | ||
170 | i1480_EVT_CONFIRM = 0x0002, | ||
171 | i1480_EVT_RM_INIT_DONE = 0x0101, | ||
172 | i1480_EVT_DEV_ADD = 0x0103, | ||
173 | i1480_EVT_DEV_RM = 0x0104, | ||
174 | i1480_EVT_DEV_ID_CHANGE = 0x0105, | ||
175 | i1480_EVT_GET_MAC_PHY_INFO = i1480_EVT_CONFIRM, | ||
176 | #endif | ||
177 | }; | ||
178 | |||
179 | |||
180 | struct i1480_evt_confirm { | ||
181 | struct uwb_rceb rceb; | ||
182 | #ifdef i1480_RCEB_EXTENDED | ||
183 | __le16 wParamLength; | ||
184 | #endif | ||
185 | u8 bResultCode; | ||
186 | } __attribute__((packed)); | ||
187 | |||
188 | |||
189 | struct i1480_rceb { | ||
190 | struct uwb_rceb rceb; | ||
191 | #ifdef i1480_RCEB_EXTENDED | ||
192 | __le16 wParamLength; | ||
193 | #endif | ||
194 | } __attribute__((packed)); | ||
195 | |||
196 | |||
197 | /** | ||
198 | * Get MAC & PHY Information confirm event structure | ||
199 | * | ||
200 | * Confirm event returned by the command. | ||
201 | */ | ||
202 | struct i1480_evt_confirm_GMPI { | ||
203 | #if i1480_FW > 0x00000302 | ||
204 | struct uwb_rceb rceb; | ||
205 | __le16 wParamLength; | ||
206 | __le16 status; | ||
207 | u8 mac_addr[6]; /* EUI-64 bit IEEE address [still 8 bytes?] */ | ||
208 | u8 dev_addr[2]; | ||
209 | __le16 mac_fw_rev; /* major = v >> 8; minor = v & 0xff */ | ||
210 | u8 hw_rev; | ||
211 | u8 phy_vendor; | ||
212 | u8 phy_rev; /* major v = >> 8; minor = v & 0xff */ | ||
213 | __le16 mac_caps; | ||
214 | u8 phy_caps[3]; | ||
215 | u8 key_stores; | ||
216 | __le16 mcast_addr_stores; | ||
217 | u8 sec_mode_supported; | ||
218 | #else | ||
219 | struct uwb_rceb rceb; | ||
220 | u8 status; | ||
221 | u8 mac_addr[8]; /* EUI-64 bit IEEE address [still 8 bytes?] */ | ||
222 | u8 dev_addr[2]; | ||
223 | __le16 mac_fw_rev; /* major = v >> 8; minor = v & 0xff */ | ||
224 | __le16 phy_fw_rev; /* major v = >> 8; minor = v & 0xff */ | ||
225 | __le16 mac_caps; | ||
226 | u8 phy_caps; | ||
227 | u8 key_stores; | ||
228 | __le16 mcast_addr_stores; | ||
229 | u8 sec_mode_supported; | ||
230 | #endif | ||
231 | } __attribute__((packed)); | ||
232 | |||
233 | |||
234 | struct i1480_cmd_mpi_write { | ||
235 | struct uwb_rccb rccb; | ||
236 | __le16 size; | ||
237 | u8 data[]; | ||
238 | }; | ||
239 | |||
240 | |||
241 | struct i1480_cmd_mpi_read { | ||
242 | struct uwb_rccb rccb; | ||
243 | __le16 size; | ||
244 | struct { | ||
245 | u8 page, offset; | ||
246 | } __attribute__((packed)) data[]; | ||
247 | } __attribute__((packed)); | ||
248 | |||
249 | |||
250 | struct i1480_evt_mpi_read { | ||
251 | struct uwb_rceb rceb; | ||
252 | #ifdef i1480_RCEB_EXTENDED | ||
253 | __le16 wParamLength; | ||
254 | #endif | ||
255 | u8 bResultCode; | ||
256 | __le16 size; | ||
257 | struct { | ||
258 | u8 page, offset, value; | ||
259 | } __attribute__((packed)) data[]; | ||
260 | } __attribute__((packed)); | ||
261 | |||
262 | |||
263 | #endif /* #ifndef __i1480_DFU_H__ */ | ||
diff --git a/drivers/uwb/i1480/dfu/mac.c b/drivers/uwb/i1480/dfu/mac.c new file mode 100644 index 000000000000..3d445541e8e9 --- /dev/null +++ b/drivers/uwb/i1480/dfu/mac.c | |||
@@ -0,0 +1,529 @@ | |||
1 | /* | ||
2 | * Intel Wireless UWB Link 1480 | ||
3 | * MAC Firmware upload implementation | ||
4 | * | ||
5 | * Copyright (C) 2005-2006 Intel Corporation | ||
6 | * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License version | ||
10 | * 2 as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
20 | * 02110-1301, USA. | ||
21 | * | ||
22 | * | ||
23 | * Implementation of the code for parsing the firmware file (extract | ||
24 | * the headers and binary code chunks) in the fw_*() functions. The | ||
25 | * code to upload pre and mac firmwares is the same, so it uses a | ||
26 | * common entry point in __mac_fw_upload(), which uses the i1480 | ||
27 | * function pointers to push the firmware to the device. | ||
28 | */ | ||
29 | #include <linux/delay.h> | ||
30 | #include <linux/firmware.h> | ||
31 | #include <linux/uwb.h> | ||
32 | #include "i1480-dfu.h" | ||
33 | |||
34 | #define D_LOCAL 0 | ||
35 | #include <linux/uwb/debug.h> | ||
36 | |||
37 | /* | ||
38 | * Descriptor for a continuous segment of MAC fw data | ||
39 | */ | ||
40 | struct fw_hdr { | ||
41 | unsigned long address; | ||
42 | size_t length; | ||
43 | const u32 *bin; | ||
44 | struct fw_hdr *next; | ||
45 | }; | ||
46 | |||
47 | |||
48 | /* Free a chain of firmware headers */ | ||
49 | static | ||
50 | void fw_hdrs_free(struct fw_hdr *hdr) | ||
51 | { | ||
52 | struct fw_hdr *next; | ||
53 | |||
54 | while (hdr) { | ||
55 | next = hdr->next; | ||
56 | kfree(hdr); | ||
57 | hdr = next; | ||
58 | } | ||
59 | } | ||
60 | |||
61 | |||
62 | /* Fill a firmware header descriptor from a memory buffer */ | ||
63 | static | ||
64 | int fw_hdr_load(struct i1480 *i1480, struct fw_hdr *hdr, unsigned hdr_cnt, | ||
65 | const char *_data, const u32 *data_itr, const u32 *data_top) | ||
66 | { | ||
67 | size_t hdr_offset = (const char *) data_itr - _data; | ||
68 | size_t remaining_size = (void *) data_top - (void *) data_itr; | ||
69 | if (data_itr + 2 > data_top) { | ||
70 | dev_err(i1480->dev, "fw hdr #%u/%zu: EOF reached in header at " | ||
71 | "offset %zu, limit %zu\n", | ||
72 | hdr_cnt, hdr_offset, | ||
73 | (const char *) data_itr + 2 - _data, | ||
74 | (const char *) data_top - _data); | ||
75 | return -EINVAL; | ||
76 | } | ||
77 | hdr->next = NULL; | ||
78 | hdr->address = le32_to_cpu(*data_itr++); | ||
79 | hdr->length = le32_to_cpu(*data_itr++); | ||
80 | hdr->bin = data_itr; | ||
81 | if (hdr->length > remaining_size) { | ||
82 | dev_err(i1480->dev, "fw hdr #%u/%zu: EOF reached in data; " | ||
83 | "chunk too long (%zu bytes), only %zu left\n", | ||
84 | hdr_cnt, hdr_offset, hdr->length, remaining_size); | ||
85 | return -EINVAL; | ||
86 | } | ||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | |||
91 | /** | ||
92 | * Get a buffer where the firmware is supposed to be and create a | ||
93 | * chain of headers linking them together. | ||
94 | * | ||
95 | * @phdr: where to place the pointer to the first header (headers link | ||
96 | * to the next via the @hdr->next ptr); need to free the whole | ||
97 | * chain when done. | ||
98 | * | ||
99 | * @_data: Pointer to the data buffer. | ||
100 | * | ||
101 | * @_data_size: Size of the data buffer (bytes); data size has to be a | ||
102 | * multiple of 4. Function will fail if not. | ||
103 | * | ||
104 | * Goes over the whole binary blob; reads the first chunk and creates | ||
105 | * a fw hdr from it (which points to where the data is in @_data and | ||
106 | * the length of the chunk); then goes on to the next chunk until | ||
107 | * done. Each header is linked to the next. | ||
108 | */ | ||
109 | static | ||
110 | int fw_hdrs_load(struct i1480 *i1480, struct fw_hdr **phdr, | ||
111 | const char *_data, size_t data_size) | ||
112 | { | ||
113 | int result; | ||
114 | unsigned hdr_cnt = 0; | ||
115 | u32 *data = (u32 *) _data, *data_itr, *data_top; | ||
116 | struct fw_hdr *hdr, **prev_hdr = phdr; | ||
117 | |||
118 | result = -EINVAL; | ||
119 | /* Check size is ok and pointer is aligned */ | ||
120 | if (data_size % sizeof(u32) != 0) | ||
121 | goto error; | ||
122 | if ((unsigned long) _data % sizeof(u16) != 0) | ||
123 | goto error; | ||
124 | *phdr = NULL; | ||
125 | data_itr = data; | ||
126 | data_top = (u32 *) (_data + data_size); | ||
127 | while (data_itr < data_top) { | ||
128 | result = -ENOMEM; | ||
129 | hdr = kmalloc(sizeof(*hdr), GFP_KERNEL); | ||
130 | if (hdr == NULL) { | ||
131 | dev_err(i1480->dev, "Cannot allocate fw header " | ||
132 | "for chunk #%u\n", hdr_cnt); | ||
133 | goto error_alloc; | ||
134 | } | ||
135 | result = fw_hdr_load(i1480, hdr, hdr_cnt, | ||
136 | _data, data_itr, data_top); | ||
137 | if (result < 0) | ||
138 | goto error_load; | ||
139 | data_itr += 2 + hdr->length; | ||
140 | *prev_hdr = hdr; | ||
141 | prev_hdr = &hdr->next; | ||
142 | hdr_cnt++; | ||
143 | }; | ||
144 | *prev_hdr = NULL; | ||
145 | return 0; | ||
146 | |||
147 | error_load: | ||
148 | kfree(hdr); | ||
149 | error_alloc: | ||
150 | fw_hdrs_free(*phdr); | ||
151 | error: | ||
152 | return result; | ||
153 | } | ||
154 | |||
155 | |||
156 | /** | ||
157 | * Compares a chunk of fw with one in the devices's memory | ||
158 | * | ||
159 | * @i1480: Device instance | ||
160 | * @hdr: Pointer to the firmware chunk | ||
161 | * @returns: 0 if equal, < 0 errno on error. If > 0, it is the offset | ||
162 | * where the difference was found (plus one). | ||
163 | * | ||
164 | * Kind of dirty and simplistic, but does the trick in both the PCI | ||
165 | * and USB version. We do a quick[er] memcmp(), and if it fails, we do | ||
166 | * a byte-by-byte to find the offset. | ||
167 | */ | ||
168 | static | ||
169 | ssize_t i1480_fw_cmp(struct i1480 *i1480, struct fw_hdr *hdr) | ||
170 | { | ||
171 | ssize_t result = 0; | ||
172 | u32 src_itr = 0, cnt; | ||
173 | size_t size = hdr->length*sizeof(hdr->bin[0]); | ||
174 | size_t chunk_size; | ||
175 | u8 *bin = (u8 *) hdr->bin; | ||
176 | |||
177 | while (size > 0) { | ||
178 | chunk_size = size < i1480->buf_size ? size : i1480->buf_size; | ||
179 | result = i1480->read(i1480, hdr->address + src_itr, chunk_size); | ||
180 | if (result < 0) { | ||
181 | dev_err(i1480->dev, "error reading for verification: " | ||
182 | "%zd\n", result); | ||
183 | goto error; | ||
184 | } | ||
185 | if (memcmp(i1480->cmd_buf, bin + src_itr, result)) { | ||
186 | u8 *buf = i1480->cmd_buf; | ||
187 | d_printf(2, i1480->dev, | ||
188 | "original data @ %p + %u, %zu bytes\n", | ||
189 | bin, src_itr, result); | ||
190 | d_dump(4, i1480->dev, bin + src_itr, result); | ||
191 | for (cnt = 0; cnt < result; cnt++) | ||
192 | if (bin[src_itr + cnt] != buf[cnt]) { | ||
193 | dev_err(i1480->dev, "byte failed at " | ||
194 | "src_itr %u cnt %u [0x%02x " | ||
195 | "vs 0x%02x]\n", src_itr, cnt, | ||
196 | bin[src_itr + cnt], buf[cnt]); | ||
197 | result = src_itr + cnt + 1; | ||
198 | goto cmp_failed; | ||
199 | } | ||
200 | } | ||
201 | src_itr += result; | ||
202 | size -= result; | ||
203 | } | ||
204 | result = 0; | ||
205 | error: | ||
206 | cmp_failed: | ||
207 | return result; | ||
208 | } | ||
209 | |||
210 | |||
211 | /** | ||
212 | * Writes firmware headers to the device. | ||
213 | * | ||
214 | * @prd: PRD instance | ||
215 | * @hdr: Processed firmware | ||
216 | * @returns: 0 if ok, < 0 errno on error. | ||
217 | */ | ||
218 | static | ||
219 | int mac_fw_hdrs_push(struct i1480 *i1480, struct fw_hdr *hdr, | ||
220 | const char *fw_name, const char *fw_tag) | ||
221 | { | ||
222 | struct device *dev = i1480->dev; | ||
223 | ssize_t result = 0; | ||
224 | struct fw_hdr *hdr_itr; | ||
225 | int verif_retry_count; | ||
226 | |||
227 | d_fnstart(3, dev, "(%p, %p)\n", i1480, hdr); | ||
228 | /* Now, header by header, push them to the hw */ | ||
229 | for (hdr_itr = hdr; hdr_itr != NULL; hdr_itr = hdr_itr->next) { | ||
230 | verif_retry_count = 0; | ||
231 | retry: | ||
232 | dev_dbg(dev, "fw chunk (%zu @ 0x%08lx)\n", | ||
233 | hdr_itr->length * sizeof(hdr_itr->bin[0]), | ||
234 | hdr_itr->address); | ||
235 | result = i1480->write(i1480, hdr_itr->address, hdr_itr->bin, | ||
236 | hdr_itr->length*sizeof(hdr_itr->bin[0])); | ||
237 | if (result < 0) { | ||
238 | dev_err(dev, "%s fw '%s': write failed (%zuB @ 0x%lx):" | ||
239 | " %zd\n", fw_tag, fw_name, | ||
240 | hdr_itr->length * sizeof(hdr_itr->bin[0]), | ||
241 | hdr_itr->address, result); | ||
242 | break; | ||
243 | } | ||
244 | result = i1480_fw_cmp(i1480, hdr_itr); | ||
245 | if (result < 0) { | ||
246 | dev_err(dev, "%s fw '%s': verification read " | ||
247 | "failed (%zuB @ 0x%lx): %zd\n", | ||
248 | fw_tag, fw_name, | ||
249 | hdr_itr->length * sizeof(hdr_itr->bin[0]), | ||
250 | hdr_itr->address, result); | ||
251 | break; | ||
252 | } | ||
253 | if (result > 0) { /* Offset where it failed + 1 */ | ||
254 | result--; | ||
255 | dev_err(dev, "%s fw '%s': WARNING: verification " | ||
256 | "failed at 0x%lx: retrying\n", | ||
257 | fw_tag, fw_name, hdr_itr->address + result); | ||
258 | if (++verif_retry_count < 3) | ||
259 | goto retry; /* write this block again! */ | ||
260 | dev_err(dev, "%s fw '%s': verification failed at 0x%lx: " | ||
261 | "tried %d times\n", fw_tag, fw_name, | ||
262 | hdr_itr->address + result, verif_retry_count); | ||
263 | result = -EINVAL; | ||
264 | break; | ||
265 | } | ||
266 | } | ||
267 | d_fnend(3, dev, "(%zd)\n", result); | ||
268 | return result; | ||
269 | } | ||
270 | |||
271 | |||
272 | /** Puts the device in firmware upload mode.*/ | ||
273 | static | ||
274 | int mac_fw_upload_enable(struct i1480 *i1480) | ||
275 | { | ||
276 | int result; | ||
277 | u32 reg = 0x800000c0; | ||
278 | u32 *buffer = (u32 *)i1480->cmd_buf; | ||
279 | |||
280 | if (i1480->hw_rev > 1) | ||
281 | reg = 0x8000d0d4; | ||
282 | result = i1480->read(i1480, reg, sizeof(u32)); | ||
283 | if (result < 0) | ||
284 | goto error_cmd; | ||
285 | *buffer &= ~i1480_FW_UPLOAD_MODE_MASK; | ||
286 | result = i1480->write(i1480, reg, buffer, sizeof(u32)); | ||
287 | if (result < 0) | ||
288 | goto error_cmd; | ||
289 | return 0; | ||
290 | error_cmd: | ||
291 | dev_err(i1480->dev, "can't enable fw upload mode: %d\n", result); | ||
292 | return result; | ||
293 | } | ||
294 | |||
295 | |||
296 | /** Gets the device out of firmware upload mode. */ | ||
297 | static | ||
298 | int mac_fw_upload_disable(struct i1480 *i1480) | ||
299 | { | ||
300 | int result; | ||
301 | u32 reg = 0x800000c0; | ||
302 | u32 *buffer = (u32 *)i1480->cmd_buf; | ||
303 | |||
304 | if (i1480->hw_rev > 1) | ||
305 | reg = 0x8000d0d4; | ||
306 | result = i1480->read(i1480, reg, sizeof(u32)); | ||
307 | if (result < 0) | ||
308 | goto error_cmd; | ||
309 | *buffer |= i1480_FW_UPLOAD_MODE_MASK; | ||
310 | result = i1480->write(i1480, reg, buffer, sizeof(u32)); | ||
311 | if (result < 0) | ||
312 | goto error_cmd; | ||
313 | return 0; | ||
314 | error_cmd: | ||
315 | dev_err(i1480->dev, "can't disable fw upload mode: %d\n", result); | ||
316 | return result; | ||
317 | } | ||
318 | |||
319 | |||
320 | |||
321 | /** | ||
322 | * Generic function for uploading a MAC firmware. | ||
323 | * | ||
324 | * @i1480: Device instance | ||
325 | * @fw_name: Name of firmware file to upload. | ||
326 | * @fw_tag: Name of the firmware type (for messages) | ||
327 | * [eg: MAC, PRE] | ||
328 | * @do_wait: Wait for device to emit initialization done message (0 | ||
329 | * for PRE fws, 1 for MAC fws). | ||
330 | * @returns: 0 if ok, < 0 errno on error. | ||
331 | */ | ||
332 | static | ||
333 | int __mac_fw_upload(struct i1480 *i1480, const char *fw_name, | ||
334 | const char *fw_tag) | ||
335 | { | ||
336 | int result; | ||
337 | const struct firmware *fw; | ||
338 | struct fw_hdr *fw_hdrs; | ||
339 | |||
340 | d_fnstart(3, i1480->dev, "(%p, %s, %s)\n", i1480, fw_name, fw_tag); | ||
341 | result = request_firmware(&fw, fw_name, i1480->dev); | ||
342 | if (result < 0) /* Up to caller to complain on -ENOENT */ | ||
343 | goto out; | ||
344 | d_printf(3, i1480->dev, "%s fw '%s': uploading\n", fw_tag, fw_name); | ||
345 | result = fw_hdrs_load(i1480, &fw_hdrs, fw->data, fw->size); | ||
346 | if (result < 0) { | ||
347 | dev_err(i1480->dev, "%s fw '%s': failed to parse firmware " | ||
348 | "file: %d\n", fw_tag, fw_name, result); | ||
349 | goto out_release; | ||
350 | } | ||
351 | result = mac_fw_upload_enable(i1480); | ||
352 | if (result < 0) | ||
353 | goto out_hdrs_release; | ||
354 | result = mac_fw_hdrs_push(i1480, fw_hdrs, fw_name, fw_tag); | ||
355 | mac_fw_upload_disable(i1480); | ||
356 | out_hdrs_release: | ||
357 | if (result >= 0) | ||
358 | dev_info(i1480->dev, "%s fw '%s': uploaded\n", fw_tag, fw_name); | ||
359 | else | ||
360 | dev_err(i1480->dev, "%s fw '%s': failed to upload (%d), " | ||
361 | "power cycle device\n", fw_tag, fw_name, result); | ||
362 | fw_hdrs_free(fw_hdrs); | ||
363 | out_release: | ||
364 | release_firmware(fw); | ||
365 | out: | ||
366 | d_fnend(3, i1480->dev, "(%p, %s, %s) = %d\n", i1480, fw_name, fw_tag, | ||
367 | result); | ||
368 | return result; | ||
369 | } | ||
370 | |||
371 | |||
372 | /** | ||
373 | * Upload a pre-PHY firmware | ||
374 | * | ||
375 | */ | ||
376 | int i1480_pre_fw_upload(struct i1480 *i1480) | ||
377 | { | ||
378 | int result; | ||
379 | result = __mac_fw_upload(i1480, i1480->pre_fw_name, "PRE"); | ||
380 | if (result == 0) | ||
381 | msleep(400); | ||
382 | return result; | ||
383 | } | ||
384 | |||
385 | |||
386 | /** | ||
387 | * Reset a the MAC and PHY | ||
388 | * | ||
389 | * @i1480: Device's instance | ||
390 | * @returns: 0 if ok, < 0 errno code on error | ||
391 | * | ||
392 | * We put the command on kmalloc'ed memory as some arches cannot do | ||
393 | * USB from the stack. The reply event is copied from an stage buffer, | ||
394 | * so it can be in the stack. See WUSB1.0[8.6.2.4] for more details. | ||
395 | * | ||
396 | * We issue the reset to make sure the UWB controller reinits the PHY; | ||
397 | * this way we can now if the PHY init went ok. | ||
398 | */ | ||
399 | static | ||
400 | int i1480_cmd_reset(struct i1480 *i1480) | ||
401 | { | ||
402 | int result; | ||
403 | struct uwb_rccb *cmd = (void *) i1480->cmd_buf; | ||
404 | struct i1480_evt_reset { | ||
405 | struct uwb_rceb rceb; | ||
406 | u8 bResultCode; | ||
407 | } __attribute__((packed)) *reply = (void *) i1480->evt_buf; | ||
408 | |||
409 | result = -ENOMEM; | ||
410 | cmd->bCommandType = UWB_RC_CET_GENERAL; | ||
411 | cmd->wCommand = cpu_to_le16(UWB_RC_CMD_RESET); | ||
412 | reply->rceb.bEventType = UWB_RC_CET_GENERAL; | ||
413 | reply->rceb.wEvent = UWB_RC_CMD_RESET; | ||
414 | result = i1480_cmd(i1480, "RESET", sizeof(*cmd), sizeof(*reply)); | ||
415 | if (result < 0) | ||
416 | goto out; | ||
417 | if (reply->bResultCode != UWB_RC_RES_SUCCESS) { | ||
418 | dev_err(i1480->dev, "RESET: command execution failed: %u\n", | ||
419 | reply->bResultCode); | ||
420 | result = -EIO; | ||
421 | } | ||
422 | out: | ||
423 | return result; | ||
424 | |||
425 | } | ||
426 | |||
427 | |||
428 | /** Wait for the MAC FW to start running */ | ||
429 | static | ||
430 | int i1480_fw_is_running_q(struct i1480 *i1480) | ||
431 | { | ||
432 | int cnt = 0; | ||
433 | int result; | ||
434 | u32 *val = (u32 *) i1480->cmd_buf; | ||
435 | |||
436 | d_fnstart(3, i1480->dev, "(i1480 %p)\n", i1480); | ||
437 | for (cnt = 0; cnt < 10; cnt++) { | ||
438 | msleep(100); | ||
439 | result = i1480->read(i1480, 0x80080000, 4); | ||
440 | if (result < 0) { | ||
441 | dev_err(i1480->dev, "Can't read 0x8008000: %d\n", result); | ||
442 | goto out; | ||
443 | } | ||
444 | if (*val == 0x55555555UL) /* fw running? cool */ | ||
445 | goto out; | ||
446 | if (printk_ratelimit()) | ||
447 | d_printf(5, i1480->dev, "read #%d: 0x%08x\n", cnt, *val); | ||
448 | } | ||
449 | dev_err(i1480->dev, "Timed out waiting for fw to start\n"); | ||
450 | result = -ETIMEDOUT; | ||
451 | out: | ||
452 | d_fnend(3, i1480->dev, "(i1480 %p) = %d\n", i1480, result); | ||
453 | return result; | ||
454 | |||
455 | } | ||
456 | |||
457 | |||
458 | /** | ||
459 | * Upload MAC firmware, wait for it to start | ||
460 | * | ||
461 | * @i1480: Device instance | ||
462 | * @fw_name: Name of the file that contains the firmware | ||
463 | * | ||
464 | * This has to be called after the pre fw has been uploaded (if | ||
465 | * there is any). | ||
466 | */ | ||
467 | int i1480_mac_fw_upload(struct i1480 *i1480) | ||
468 | { | ||
469 | int result = 0, deprecated_name = 0; | ||
470 | struct i1480_rceb *rcebe = (void *) i1480->evt_buf; | ||
471 | |||
472 | d_fnstart(3, i1480->dev, "(%p)\n", i1480); | ||
473 | result = __mac_fw_upload(i1480, i1480->mac_fw_name, "MAC"); | ||
474 | if (result == -ENOENT) { | ||
475 | result = __mac_fw_upload(i1480, i1480->mac_fw_name_deprecate, | ||
476 | "MAC"); | ||
477 | deprecated_name = 1; | ||
478 | } | ||
479 | if (result < 0) | ||
480 | return result; | ||
481 | if (deprecated_name == 1) | ||
482 | dev_warn(i1480->dev, | ||
483 | "WARNING: firmware file name %s is deprecated, " | ||
484 | "please rename to %s\n", | ||
485 | i1480->mac_fw_name_deprecate, i1480->mac_fw_name); | ||
486 | result = i1480_fw_is_running_q(i1480); | ||
487 | if (result < 0) | ||
488 | goto error_fw_not_running; | ||
489 | result = i1480->rc_setup ? i1480->rc_setup(i1480) : 0; | ||
490 | if (result < 0) { | ||
491 | dev_err(i1480->dev, "Cannot setup after MAC fw upload: %d\n", | ||
492 | result); | ||
493 | goto error_setup; | ||
494 | } | ||
495 | result = i1480->wait_init_done(i1480); /* wait init'on */ | ||
496 | if (result < 0) { | ||
497 | dev_err(i1480->dev, "MAC fw '%s': Initialization timed out " | ||
498 | "(%d)\n", i1480->mac_fw_name, result); | ||
499 | goto error_init_timeout; | ||
500 | } | ||
501 | /* verify we got the right initialization done event */ | ||
502 | if (i1480->evt_result != sizeof(*rcebe)) { | ||
503 | dev_err(i1480->dev, "MAC fw '%s': initialization event returns " | ||
504 | "wrong size (%zu bytes vs %zu needed)\n", | ||
505 | i1480->mac_fw_name, i1480->evt_result, sizeof(*rcebe)); | ||
506 | dump_bytes(i1480->dev, rcebe, min(i1480->evt_result, (ssize_t)32)); | ||
507 | goto error_size; | ||
508 | } | ||
509 | result = -EIO; | ||
510 | if (rcebe->rceb.bEventType != i1480_CET_VS1 | ||
511 | || le16_to_cpu(rcebe->rceb.wEvent) != i1480_EVT_RM_INIT_DONE) { | ||
512 | dev_err(i1480->dev, "wrong initialization event 0x%02x/%04x/%02x " | ||
513 | "received; expected 0x%02x/%04x/00\n", | ||
514 | rcebe->rceb.bEventType, le16_to_cpu(rcebe->rceb.wEvent), | ||
515 | rcebe->rceb.bEventContext, i1480_CET_VS1, | ||
516 | i1480_EVT_RM_INIT_DONE); | ||
517 | goto error_init_timeout; | ||
518 | } | ||
519 | result = i1480_cmd_reset(i1480); | ||
520 | if (result < 0) | ||
521 | dev_err(i1480->dev, "MAC fw '%s': MBOA reset failed (%d)\n", | ||
522 | i1480->mac_fw_name, result); | ||
523 | error_fw_not_running: | ||
524 | error_init_timeout: | ||
525 | error_size: | ||
526 | error_setup: | ||
527 | d_fnend(3, i1480->dev, "(i1480 %p) = %d\n", i1480, result); | ||
528 | return result; | ||
529 | } | ||
diff --git a/drivers/uwb/i1480/dfu/phy.c b/drivers/uwb/i1480/dfu/phy.c new file mode 100644 index 000000000000..3b1a87de8e63 --- /dev/null +++ b/drivers/uwb/i1480/dfu/phy.c | |||
@@ -0,0 +1,203 @@ | |||
1 | /* | ||
2 | * Intel Wireless UWB Link 1480 | ||
3 | * PHY parameters upload | ||
4 | * | ||
5 | * Copyright (C) 2005-2006 Intel Corporation | ||
6 | * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License version | ||
10 | * 2 as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
20 | * 02110-1301, USA. | ||
21 | * | ||
22 | * | ||
23 | * Code for uploading the PHY parameters to the PHY through the UWB | ||
24 | * Radio Control interface. | ||
25 | * | ||
26 | * We just send the data through the MPI interface using HWA-like | ||
27 | * commands and then reset the PHY to make sure it is ok. | ||
28 | */ | ||
29 | #include <linux/delay.h> | ||
30 | #include <linux/device.h> | ||
31 | #include <linux/firmware.h> | ||
32 | #include <linux/usb/wusb.h> | ||
33 | #include "i1480-dfu.h" | ||
34 | |||
35 | |||
36 | /** | ||
37 | * Write a value array to an address of the MPI interface | ||
38 | * | ||
39 | * @i1480: Device descriptor | ||
40 | * @data: Data array to write | ||
41 | * @size: Size of the data array | ||
42 | * @returns: 0 if ok, < 0 errno code on error. | ||
43 | * | ||
44 | * The data array is organized into pairs: | ||
45 | * | ||
46 | * ADDRESS VALUE | ||
47 | * | ||
48 | * ADDRESS is BE 16 bit unsigned, VALUE 8 bit unsigned. Size thus has | ||
49 | * to be a multiple of three. | ||
50 | */ | ||
51 | static | ||
52 | int i1480_mpi_write(struct i1480 *i1480, const void *data, size_t size) | ||
53 | { | ||
54 | int result; | ||
55 | struct i1480_cmd_mpi_write *cmd = i1480->cmd_buf; | ||
56 | struct i1480_evt_confirm *reply = i1480->evt_buf; | ||
57 | |||
58 | BUG_ON(size > 480); | ||
59 | result = -ENOMEM; | ||
60 | cmd->rccb.bCommandType = i1480_CET_VS1; | ||
61 | cmd->rccb.wCommand = cpu_to_le16(i1480_CMD_MPI_WRITE); | ||
62 | cmd->size = cpu_to_le16(size); | ||
63 | memcpy(cmd->data, data, size); | ||
64 | reply->rceb.bEventType = i1480_CET_VS1; | ||
65 | reply->rceb.wEvent = i1480_CMD_MPI_WRITE; | ||
66 | result = i1480_cmd(i1480, "MPI-WRITE", sizeof(*cmd) + size, sizeof(*reply)); | ||
67 | if (result < 0) | ||
68 | goto out; | ||
69 | if (reply->bResultCode != UWB_RC_RES_SUCCESS) { | ||
70 | dev_err(i1480->dev, "MPI-WRITE: command execution failed: %d\n", | ||
71 | reply->bResultCode); | ||
72 | result = -EIO; | ||
73 | } | ||
74 | out: | ||
75 | return result; | ||
76 | } | ||
77 | |||
78 | |||
79 | /** | ||
80 | * Read a value array to from an address of the MPI interface | ||
81 | * | ||
82 | * @i1480: Device descriptor | ||
83 | * @data: where to place the read array | ||
84 | * @srcaddr: Where to read from | ||
85 | * @size: Size of the data read array | ||
86 | * @returns: 0 if ok, < 0 errno code on error. | ||
87 | * | ||
88 | * The command data array is organized into pairs ADDR0 ADDR1..., and | ||
89 | * the returned data in ADDR0 VALUE0 ADDR1 VALUE1... | ||
90 | * | ||
91 | * We generate the command array to be a sequential read and then | ||
92 | * rearrange the result. | ||
93 | * | ||
94 | * We use the i1480->cmd_buf for the command, i1480->evt_buf for the reply. | ||
95 | * | ||
96 | * As the reply has to fit in 512 bytes (i1480->evt_buffer), the max amount | ||
97 | * of values we can read is (512 - sizeof(*reply)) / 3 | ||
98 | */ | ||
99 | static | ||
100 | int i1480_mpi_read(struct i1480 *i1480, u8 *data, u16 srcaddr, size_t size) | ||
101 | { | ||
102 | int result; | ||
103 | struct i1480_cmd_mpi_read *cmd = i1480->cmd_buf; | ||
104 | struct i1480_evt_mpi_read *reply = i1480->evt_buf; | ||
105 | unsigned cnt; | ||
106 | |||
107 | memset(i1480->cmd_buf, 0x69, 512); | ||
108 | memset(i1480->evt_buf, 0x69, 512); | ||
109 | |||
110 | BUG_ON(size > (i1480->buf_size - sizeof(*reply)) / 3); | ||
111 | result = -ENOMEM; | ||
112 | cmd->rccb.bCommandType = i1480_CET_VS1; | ||
113 | cmd->rccb.wCommand = cpu_to_le16(i1480_CMD_MPI_READ); | ||
114 | cmd->size = cpu_to_le16(3*size); | ||
115 | for (cnt = 0; cnt < size; cnt++) { | ||
116 | cmd->data[cnt].page = (srcaddr + cnt) >> 8; | ||
117 | cmd->data[cnt].offset = (srcaddr + cnt) & 0xff; | ||
118 | } | ||
119 | reply->rceb.bEventType = i1480_CET_VS1; | ||
120 | reply->rceb.wEvent = i1480_CMD_MPI_READ; | ||
121 | result = i1480_cmd(i1480, "MPI-READ", sizeof(*cmd) + 2*size, | ||
122 | sizeof(*reply) + 3*size); | ||
123 | if (result < 0) | ||
124 | goto out; | ||
125 | if (reply->bResultCode != UWB_RC_RES_SUCCESS) { | ||
126 | dev_err(i1480->dev, "MPI-READ: command execution failed: %d\n", | ||
127 | reply->bResultCode); | ||
128 | result = -EIO; | ||
129 | } | ||
130 | for (cnt = 0; cnt < size; cnt++) { | ||
131 | if (reply->data[cnt].page != (srcaddr + cnt) >> 8) | ||
132 | dev_err(i1480->dev, "MPI-READ: page inconsistency at " | ||
133 | "index %u: expected 0x%02x, got 0x%02x\n", cnt, | ||
134 | (srcaddr + cnt) >> 8, reply->data[cnt].page); | ||
135 | if (reply->data[cnt].offset != ((srcaddr + cnt) & 0x00ff)) | ||
136 | dev_err(i1480->dev, "MPI-READ: offset inconsistency at " | ||
137 | "index %u: expected 0x%02x, got 0x%02x\n", cnt, | ||
138 | (srcaddr + cnt) & 0x00ff, | ||
139 | reply->data[cnt].offset); | ||
140 | data[cnt] = reply->data[cnt].value; | ||
141 | } | ||
142 | result = 0; | ||
143 | out: | ||
144 | return result; | ||
145 | } | ||
146 | |||
147 | |||
148 | /** | ||
149 | * Upload a PHY firmware, wait for it to start | ||
150 | * | ||
151 | * @i1480: Device instance | ||
152 | * @fw_name: Name of the file that contains the firmware | ||
153 | * | ||
154 | * We assume the MAC fw is up and running. This means we can use the | ||
155 | * MPI interface to write the PHY firmware. Once done, we issue an | ||
156 | * MBOA Reset, which will force the MAC to reset and reinitialize the | ||
157 | * PHY. If that works, we are ready to go. | ||
158 | * | ||
159 | * Max packet size for the MPI write is 512, so the max buffer is 480 | ||
160 | * (which gives us 160 byte triads of MSB, LSB and VAL for the data). | ||
161 | */ | ||
162 | int i1480_phy_fw_upload(struct i1480 *i1480) | ||
163 | { | ||
164 | int result; | ||
165 | const struct firmware *fw; | ||
166 | const char *data_itr, *data_top; | ||
167 | const size_t MAX_BLK_SIZE = 480; /* 160 triads */ | ||
168 | size_t data_size; | ||
169 | u8 phy_stat; | ||
170 | |||
171 | result = request_firmware(&fw, i1480->phy_fw_name, i1480->dev); | ||
172 | if (result < 0) | ||
173 | goto out; | ||
174 | /* Loop writing data in chunks as big as possible until done. */ | ||
175 | for (data_itr = fw->data, data_top = data_itr + fw->size; | ||
176 | data_itr < data_top; data_itr += MAX_BLK_SIZE) { | ||
177 | data_size = min(MAX_BLK_SIZE, (size_t) (data_top - data_itr)); | ||
178 | result = i1480_mpi_write(i1480, data_itr, data_size); | ||
179 | if (result < 0) | ||
180 | goto error_mpi_write; | ||
181 | } | ||
182 | /* Read MPI page 0, offset 6; if 0, PHY was initialized correctly. */ | ||
183 | result = i1480_mpi_read(i1480, &phy_stat, 0x0006, 1); | ||
184 | if (result < 0) { | ||
185 | dev_err(i1480->dev, "PHY: can't get status: %d\n", result); | ||
186 | goto error_mpi_status; | ||
187 | } | ||
188 | if (phy_stat != 0) { | ||
189 | result = -ENODEV; | ||
190 | dev_info(i1480->dev, "error, PHY not ready: %u\n", phy_stat); | ||
191 | goto error_phy_status; | ||
192 | } | ||
193 | dev_info(i1480->dev, "PHY fw '%s': uploaded\n", i1480->phy_fw_name); | ||
194 | error_phy_status: | ||
195 | error_mpi_status: | ||
196 | error_mpi_write: | ||
197 | release_firmware(fw); | ||
198 | if (result < 0) | ||
199 | dev_err(i1480->dev, "PHY fw '%s': failed to upload (%d), " | ||
200 | "power cycle device\n", i1480->phy_fw_name, result); | ||
201 | out: | ||
202 | return result; | ||
203 | } | ||
diff --git a/drivers/uwb/i1480/dfu/usb.c b/drivers/uwb/i1480/dfu/usb.c new file mode 100644 index 000000000000..98eeeff051aa --- /dev/null +++ b/drivers/uwb/i1480/dfu/usb.c | |||
@@ -0,0 +1,500 @@ | |||
1 | /* | ||
2 | * Intel Wireless UWB Link 1480 | ||
3 | * USB SKU firmware upload implementation | ||
4 | * | ||
5 | * Copyright (C) 2005-2006 Intel Corporation | ||
6 | * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License version | ||
10 | * 2 as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
20 | * 02110-1301, USA. | ||
21 | * | ||
22 | * | ||
23 | * This driver will prepare the i1480 device to behave as a real | ||
24 | * Wireless USB HWA adaptor by uploading the firmware. | ||
25 | * | ||
26 | * When the device is connected or driver is loaded, i1480_usb_probe() | ||
27 | * is called--this will allocate and initialize the device structure, | ||
28 | * fill in the pointers to the common functions (read, write, | ||
29 | * wait_init_done and cmd for HWA command execution) and once that is | ||
30 | * done, call the common firmware uploading routine. Then clean up and | ||
31 | * return -ENODEV, as we don't attach to the device. | ||
32 | * | ||
33 | * The rest are the basic ops we implement that the fw upload code | ||
34 | * uses to do its job. All the ops in the common code are i1480->NAME, | ||
35 | * the functions are i1480_usb_NAME(). | ||
36 | */ | ||
37 | #include <linux/module.h> | ||
38 | #include <linux/version.h> | ||
39 | #include <linux/usb.h> | ||
40 | #include <linux/interrupt.h> | ||
41 | #include <linux/delay.h> | ||
42 | #include <linux/uwb.h> | ||
43 | #include <linux/usb/wusb.h> | ||
44 | #include <linux/usb/wusb-wa.h> | ||
45 | #include "i1480-dfu.h" | ||
46 | |||
47 | #define D_LOCAL 0 | ||
48 | #include <linux/uwb/debug.h> | ||
49 | |||
50 | |||
51 | struct i1480_usb { | ||
52 | struct i1480 i1480; | ||
53 | struct usb_device *usb_dev; | ||
54 | struct usb_interface *usb_iface; | ||
55 | struct urb *neep_urb; /* URB for reading from EP1 */ | ||
56 | }; | ||
57 | |||
58 | |||
59 | static | ||
60 | void i1480_usb_init(struct i1480_usb *i1480_usb) | ||
61 | { | ||
62 | i1480_init(&i1480_usb->i1480); | ||
63 | } | ||
64 | |||
65 | |||
66 | static | ||
67 | int i1480_usb_create(struct i1480_usb *i1480_usb, struct usb_interface *iface) | ||
68 | { | ||
69 | struct usb_device *usb_dev = interface_to_usbdev(iface); | ||
70 | int result = -ENOMEM; | ||
71 | |||
72 | i1480_usb->usb_dev = usb_get_dev(usb_dev); /* bind the USB device */ | ||
73 | i1480_usb->usb_iface = usb_get_intf(iface); | ||
74 | usb_set_intfdata(iface, i1480_usb); /* Bind the driver to iface0 */ | ||
75 | i1480_usb->neep_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
76 | if (i1480_usb->neep_urb == NULL) | ||
77 | goto error; | ||
78 | return 0; | ||
79 | |||
80 | error: | ||
81 | usb_set_intfdata(iface, NULL); | ||
82 | usb_put_intf(iface); | ||
83 | usb_put_dev(usb_dev); | ||
84 | return result; | ||
85 | } | ||
86 | |||
87 | |||
88 | static | ||
89 | void i1480_usb_destroy(struct i1480_usb *i1480_usb) | ||
90 | { | ||
91 | usb_kill_urb(i1480_usb->neep_urb); | ||
92 | usb_free_urb(i1480_usb->neep_urb); | ||
93 | usb_set_intfdata(i1480_usb->usb_iface, NULL); | ||
94 | usb_put_intf(i1480_usb->usb_iface); | ||
95 | usb_put_dev(i1480_usb->usb_dev); | ||
96 | } | ||
97 | |||
98 | |||
99 | /** | ||
100 | * Write a buffer to a memory address in the i1480 device | ||
101 | * | ||
102 | * @i1480: i1480 instance | ||
103 | * @memory_address: | ||
104 | * Address where to write the data buffer to. | ||
105 | * @buffer: Buffer to the data | ||
106 | * @size: Size of the buffer [has to be < 512]. | ||
107 | * @returns: 0 if ok, < 0 errno code on error. | ||
108 | * | ||
109 | * Data buffers to USB cannot be on the stack or in vmalloc'ed areas, | ||
110 | * so we copy it to the local i1480 buffer before proceeding. In any | ||
111 | * case, we have a max size we can send, soooo. | ||
112 | */ | ||
113 | static | ||
114 | int i1480_usb_write(struct i1480 *i1480, u32 memory_address, | ||
115 | const void *buffer, size_t size) | ||
116 | { | ||
117 | int result = 0; | ||
118 | struct i1480_usb *i1480_usb = container_of(i1480, struct i1480_usb, i1480); | ||
119 | size_t buffer_size, itr = 0; | ||
120 | |||
121 | d_fnstart(3, i1480->dev, "(%p, 0x%08x, %p, %zu)\n", | ||
122 | i1480, memory_address, buffer, size); | ||
123 | BUG_ON(size & 0x3); /* Needs to be a multiple of 4 */ | ||
124 | while (size > 0) { | ||
125 | buffer_size = size < i1480->buf_size ? size : i1480->buf_size; | ||
126 | memcpy(i1480->cmd_buf, buffer + itr, buffer_size); | ||
127 | result = usb_control_msg( | ||
128 | i1480_usb->usb_dev, usb_sndctrlpipe(i1480_usb->usb_dev, 0), | ||
129 | 0xf0, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
130 | cpu_to_le16(memory_address & 0xffff), | ||
131 | cpu_to_le16((memory_address >> 16) & 0xffff), | ||
132 | i1480->cmd_buf, buffer_size, 100 /* FIXME: arbitrary */); | ||
133 | if (result < 0) | ||
134 | break; | ||
135 | d_printf(3, i1480->dev, | ||
136 | "wrote @ 0x%08x %u bytes (of %zu bytes requested)\n", | ||
137 | memory_address, result, buffer_size); | ||
138 | d_dump(4, i1480->dev, i1480->cmd_buf, result); | ||
139 | itr += result; | ||
140 | memory_address += result; | ||
141 | size -= result; | ||
142 | } | ||
143 | d_fnend(3, i1480->dev, "(%p, 0x%08x, %p, %zu) = %d\n", | ||
144 | i1480, memory_address, buffer, size, result); | ||
145 | return result; | ||
146 | } | ||
147 | |||
148 | |||
149 | /** | ||
150 | * Read a block [max size 512] of the device's memory to @i1480's buffer. | ||
151 | * | ||
152 | * @i1480: i1480 instance | ||
153 | * @memory_address: | ||
154 | * Address where to read from. | ||
155 | * @size: Size to read. Smaller than or equal to 512. | ||
156 | * @returns: >= 0 number of bytes written if ok, < 0 errno code on error. | ||
157 | * | ||
158 | * NOTE: if the memory address or block is incorrect, you might get a | ||
159 | * stall or a different memory read. Caller has to verify the | ||
160 | * memory address and size passed back in the @neh structure. | ||
161 | */ | ||
162 | static | ||
163 | int i1480_usb_read(struct i1480 *i1480, u32 addr, size_t size) | ||
164 | { | ||
165 | ssize_t result = 0, bytes = 0; | ||
166 | size_t itr, read_size = i1480->buf_size; | ||
167 | struct i1480_usb *i1480_usb = container_of(i1480, struct i1480_usb, i1480); | ||
168 | |||
169 | d_fnstart(3, i1480->dev, "(%p, 0x%08x, %zu)\n", | ||
170 | i1480, addr, size); | ||
171 | BUG_ON(size > i1480->buf_size); | ||
172 | BUG_ON(size & 0x3); /* Needs to be a multiple of 4 */ | ||
173 | BUG_ON(read_size > 512); | ||
174 | |||
175 | if (addr >= 0x8000d200 && addr < 0x8000d400) /* Yeah, HW quirk */ | ||
176 | read_size = 4; | ||
177 | |||
178 | for (itr = 0; itr < size; itr += read_size) { | ||
179 | size_t itr_addr = addr + itr; | ||
180 | size_t itr_size = min(read_size, size - itr); | ||
181 | result = usb_control_msg( | ||
182 | i1480_usb->usb_dev, usb_rcvctrlpipe(i1480_usb->usb_dev, 0), | ||
183 | 0xf0, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
184 | cpu_to_le16(itr_addr & 0xffff), | ||
185 | cpu_to_le16((itr_addr >> 16) & 0xffff), | ||
186 | i1480->cmd_buf + itr, itr_size, | ||
187 | 100 /* FIXME: arbitrary */); | ||
188 | if (result < 0) { | ||
189 | dev_err(i1480->dev, "%s: USB read error: %zd\n", | ||
190 | __func__, result); | ||
191 | goto out; | ||
192 | } | ||
193 | if (result != itr_size) { | ||
194 | result = -EIO; | ||
195 | dev_err(i1480->dev, | ||
196 | "%s: partial read got only %zu bytes vs %zu expected\n", | ||
197 | __func__, result, itr_size); | ||
198 | goto out; | ||
199 | } | ||
200 | bytes += result; | ||
201 | } | ||
202 | result = bytes; | ||
203 | out: | ||
204 | d_fnend(3, i1480->dev, "(%p, 0x%08x, %zu) = %zd\n", | ||
205 | i1480, addr, size, result); | ||
206 | if (result > 0) | ||
207 | d_dump(4, i1480->dev, i1480->cmd_buf, result); | ||
208 | return result; | ||
209 | } | ||
210 | |||
211 | |||
212 | /** | ||
213 | * Callback for reads on the notification/event endpoint | ||
214 | * | ||
215 | * Just enables the completion read handler. | ||
216 | */ | ||
217 | static | ||
218 | void i1480_usb_neep_cb(struct urb *urb) | ||
219 | { | ||
220 | struct i1480 *i1480 = urb->context; | ||
221 | struct device *dev = i1480->dev; | ||
222 | |||
223 | switch (urb->status) { | ||
224 | case 0: | ||
225 | break; | ||
226 | case -ECONNRESET: /* Not an error, but a controlled situation; */ | ||
227 | case -ENOENT: /* (we killed the URB)...so, no broadcast */ | ||
228 | dev_dbg(dev, "NEEP: reset/noent %d\n", urb->status); | ||
229 | break; | ||
230 | case -ESHUTDOWN: /* going away! */ | ||
231 | dev_dbg(dev, "NEEP: down %d\n", urb->status); | ||
232 | break; | ||
233 | default: | ||
234 | dev_err(dev, "NEEP: unknown status %d\n", urb->status); | ||
235 | break; | ||
236 | } | ||
237 | i1480->evt_result = urb->actual_length; | ||
238 | complete(&i1480->evt_complete); | ||
239 | return; | ||
240 | } | ||
241 | |||
242 | |||
243 | /** | ||
244 | * Wait for the MAC FW to initialize | ||
245 | * | ||
246 | * MAC FW sends a 0xfd/0101/00 notification to EP1 when done | ||
247 | * initializing. Get that notification into i1480->evt_buf; upper layer | ||
248 | * will verify it. | ||
249 | * | ||
250 | * Set i1480->evt_result with the result of getting the event or its | ||
251 | * size (if succesful). | ||
252 | * | ||
253 | * Delivers the data directly to i1480->evt_buf | ||
254 | */ | ||
255 | static | ||
256 | int i1480_usb_wait_init_done(struct i1480 *i1480) | ||
257 | { | ||
258 | int result; | ||
259 | struct device *dev = i1480->dev; | ||
260 | struct i1480_usb *i1480_usb = container_of(i1480, struct i1480_usb, i1480); | ||
261 | struct usb_endpoint_descriptor *epd; | ||
262 | |||
263 | d_fnstart(3, dev, "(%p)\n", i1480); | ||
264 | init_completion(&i1480->evt_complete); | ||
265 | i1480->evt_result = -EINPROGRESS; | ||
266 | epd = &i1480_usb->usb_iface->cur_altsetting->endpoint[0].desc; | ||
267 | usb_fill_int_urb(i1480_usb->neep_urb, i1480_usb->usb_dev, | ||
268 | usb_rcvintpipe(i1480_usb->usb_dev, epd->bEndpointAddress), | ||
269 | i1480->evt_buf, i1480->buf_size, | ||
270 | i1480_usb_neep_cb, i1480, epd->bInterval); | ||
271 | result = usb_submit_urb(i1480_usb->neep_urb, GFP_KERNEL); | ||
272 | if (result < 0) { | ||
273 | dev_err(dev, "init done: cannot submit NEEP read: %d\n", | ||
274 | result); | ||
275 | goto error_submit; | ||
276 | } | ||
277 | /* Wait for the USB callback to get the data */ | ||
278 | result = wait_for_completion_interruptible_timeout( | ||
279 | &i1480->evt_complete, HZ); | ||
280 | if (result <= 0) { | ||
281 | result = result == 0 ? -ETIMEDOUT : result; | ||
282 | goto error_wait; | ||
283 | } | ||
284 | usb_kill_urb(i1480_usb->neep_urb); | ||
285 | d_fnend(3, dev, "(%p) = 0\n", i1480); | ||
286 | return 0; | ||
287 | |||
288 | error_wait: | ||
289 | usb_kill_urb(i1480_usb->neep_urb); | ||
290 | error_submit: | ||
291 | i1480->evt_result = result; | ||
292 | d_fnend(3, dev, "(%p) = %d\n", i1480, result); | ||
293 | return result; | ||
294 | } | ||
295 | |||
296 | |||
297 | /** | ||
298 | * Generic function for issuing commands to the i1480 | ||
299 | * | ||
300 | * @i1480: i1480 instance | ||
301 | * @cmd_name: Name of the command (for error messages) | ||
302 | * @cmd: Pointer to command buffer | ||
303 | * @cmd_size: Size of the command buffer | ||
304 | * @reply: Buffer for the reply event | ||
305 | * @reply_size: Expected size back (including RCEB); the reply buffer | ||
306 | * is assumed to be as big as this. | ||
307 | * @returns: >= 0 size of the returned event data if ok, | ||
308 | * < 0 errno code on error. | ||
309 | * | ||
310 | * Arms the NE handle, issues the command to the device and checks the | ||
311 | * basics of the reply event. | ||
312 | */ | ||
313 | static | ||
314 | int i1480_usb_cmd(struct i1480 *i1480, const char *cmd_name, size_t cmd_size) | ||
315 | { | ||
316 | int result; | ||
317 | struct device *dev = i1480->dev; | ||
318 | struct i1480_usb *i1480_usb = container_of(i1480, struct i1480_usb, i1480); | ||
319 | struct usb_endpoint_descriptor *epd; | ||
320 | struct uwb_rccb *cmd = i1480->cmd_buf; | ||
321 | u8 iface_no; | ||
322 | |||
323 | d_fnstart(3, dev, "(%p, %s, %zu)\n", i1480, cmd_name, cmd_size); | ||
324 | /* Post a read on the notification & event endpoint */ | ||
325 | iface_no = i1480_usb->usb_iface->cur_altsetting->desc.bInterfaceNumber; | ||
326 | epd = &i1480_usb->usb_iface->cur_altsetting->endpoint[0].desc; | ||
327 | usb_fill_int_urb( | ||
328 | i1480_usb->neep_urb, i1480_usb->usb_dev, | ||
329 | usb_rcvintpipe(i1480_usb->usb_dev, epd->bEndpointAddress), | ||
330 | i1480->evt_buf, i1480->buf_size, | ||
331 | i1480_usb_neep_cb, i1480, epd->bInterval); | ||
332 | result = usb_submit_urb(i1480_usb->neep_urb, GFP_KERNEL); | ||
333 | if (result < 0) { | ||
334 | dev_err(dev, "%s: cannot submit NEEP read: %d\n", | ||
335 | cmd_name, result); | ||
336 | goto error_submit_ep1; | ||
337 | } | ||
338 | /* Now post the command on EP0 */ | ||
339 | result = usb_control_msg( | ||
340 | i1480_usb->usb_dev, usb_sndctrlpipe(i1480_usb->usb_dev, 0), | ||
341 | WA_EXEC_RC_CMD, | ||
342 | USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS, | ||
343 | 0, iface_no, | ||
344 | cmd, cmd_size, | ||
345 | 100 /* FIXME: this is totally arbitrary */); | ||
346 | if (result < 0) { | ||
347 | dev_err(dev, "%s: control request failed: %d\n", | ||
348 | cmd_name, result); | ||
349 | goto error_submit_ep0; | ||
350 | } | ||
351 | d_fnend(3, dev, "(%p, %s, %zu) = %d\n", | ||
352 | i1480, cmd_name, cmd_size, result); | ||
353 | return result; | ||
354 | |||
355 | error_submit_ep0: | ||
356 | usb_kill_urb(i1480_usb->neep_urb); | ||
357 | error_submit_ep1: | ||
358 | d_fnend(3, dev, "(%p, %s, %zu) = %d\n", | ||
359 | i1480, cmd_name, cmd_size, result); | ||
360 | return result; | ||
361 | } | ||
362 | |||
363 | |||
364 | /* | ||
365 | * Probe a i1480 device for uploading firmware. | ||
366 | * | ||
367 | * We attach only to interface #0, which is the radio control interface. | ||
368 | */ | ||
369 | static | ||
370 | int i1480_usb_probe(struct usb_interface *iface, const struct usb_device_id *id) | ||
371 | { | ||
372 | struct i1480_usb *i1480_usb; | ||
373 | struct i1480 *i1480; | ||
374 | struct device *dev = &iface->dev; | ||
375 | int result; | ||
376 | |||
377 | result = -ENODEV; | ||
378 | if (iface->cur_altsetting->desc.bInterfaceNumber != 0) { | ||
379 | dev_dbg(dev, "not attaching to iface %d\n", | ||
380 | iface->cur_altsetting->desc.bInterfaceNumber); | ||
381 | goto error; | ||
382 | } | ||
383 | if (iface->num_altsetting > 1 | ||
384 | && interface_to_usbdev(iface)->descriptor.idProduct == 0xbabe) { | ||
385 | /* Need altsetting #1 [HW QUIRK] or EP1 won't work */ | ||
386 | result = usb_set_interface(interface_to_usbdev(iface), 0, 1); | ||
387 | if (result < 0) | ||
388 | dev_warn(dev, | ||
389 | "can't set altsetting 1 on iface 0: %d\n", | ||
390 | result); | ||
391 | } | ||
392 | |||
393 | result = -ENOMEM; | ||
394 | i1480_usb = kzalloc(sizeof(*i1480_usb), GFP_KERNEL); | ||
395 | if (i1480_usb == NULL) { | ||
396 | dev_err(dev, "Unable to allocate instance\n"); | ||
397 | goto error; | ||
398 | } | ||
399 | i1480_usb_init(i1480_usb); | ||
400 | |||
401 | i1480 = &i1480_usb->i1480; | ||
402 | i1480->buf_size = 512; | ||
403 | i1480->cmd_buf = kmalloc(2 * i1480->buf_size, GFP_KERNEL); | ||
404 | if (i1480->cmd_buf == NULL) { | ||
405 | dev_err(dev, "Cannot allocate transfer buffers\n"); | ||
406 | result = -ENOMEM; | ||
407 | goto error_buf_alloc; | ||
408 | } | ||
409 | i1480->evt_buf = i1480->cmd_buf + i1480->buf_size; | ||
410 | |||
411 | result = i1480_usb_create(i1480_usb, iface); | ||
412 | if (result < 0) { | ||
413 | dev_err(dev, "Cannot create instance: %d\n", result); | ||
414 | goto error_create; | ||
415 | } | ||
416 | |||
417 | /* setup the fops and upload the firmare */ | ||
418 | i1480->pre_fw_name = "i1480-pre-phy-0.0.bin"; | ||
419 | i1480->mac_fw_name = "i1480-usb-0.0.bin"; | ||
420 | i1480->mac_fw_name_deprecate = "ptc-0.0.bin"; | ||
421 | i1480->phy_fw_name = "i1480-phy-0.0.bin"; | ||
422 | i1480->dev = &iface->dev; | ||
423 | i1480->write = i1480_usb_write; | ||
424 | i1480->read = i1480_usb_read; | ||
425 | i1480->rc_setup = NULL; | ||
426 | i1480->wait_init_done = i1480_usb_wait_init_done; | ||
427 | i1480->cmd = i1480_usb_cmd; | ||
428 | |||
429 | result = i1480_fw_upload(&i1480_usb->i1480); /* the real thing */ | ||
430 | if (result >= 0) { | ||
431 | usb_reset_device(i1480_usb->usb_dev); | ||
432 | result = -ENODEV; /* we don't want to bind to the iface */ | ||
433 | } | ||
434 | i1480_usb_destroy(i1480_usb); | ||
435 | error_create: | ||
436 | kfree(i1480->cmd_buf); | ||
437 | error_buf_alloc: | ||
438 | kfree(i1480_usb); | ||
439 | error: | ||
440 | return result; | ||
441 | } | ||
442 | |||
443 | #define i1480_USB_DEV(v, p) \ | ||
444 | { \ | ||
445 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE \ | ||
446 | | USB_DEVICE_ID_MATCH_DEV_INFO \ | ||
447 | | USB_DEVICE_ID_MATCH_INT_INFO, \ | ||
448 | .idVendor = (v), \ | ||
449 | .idProduct = (p), \ | ||
450 | .bDeviceClass = 0xff, \ | ||
451 | .bDeviceSubClass = 0xff, \ | ||
452 | .bDeviceProtocol = 0xff, \ | ||
453 | .bInterfaceClass = 0xff, \ | ||
454 | .bInterfaceSubClass = 0xff, \ | ||
455 | .bInterfaceProtocol = 0xff, \ | ||
456 | } | ||
457 | |||
458 | |||
459 | /** USB device ID's that we handle */ | ||
460 | static struct usb_device_id i1480_usb_id_table[] = { | ||
461 | i1480_USB_DEV(0x8086, 0xdf3b), | ||
462 | i1480_USB_DEV(0x15a9, 0x0005), | ||
463 | i1480_USB_DEV(0x07d1, 0x3802), | ||
464 | i1480_USB_DEV(0x050d, 0x305a), | ||
465 | i1480_USB_DEV(0x3495, 0x3007), | ||
466 | {}, | ||
467 | }; | ||
468 | MODULE_DEVICE_TABLE(usb, i1480_usb_id_table); | ||
469 | |||
470 | |||
471 | static struct usb_driver i1480_dfu_driver = { | ||
472 | .name = "i1480-dfu-usb", | ||
473 | .id_table = i1480_usb_id_table, | ||
474 | .probe = i1480_usb_probe, | ||
475 | .disconnect = NULL, | ||
476 | }; | ||
477 | |||
478 | |||
479 | /* | ||
480 | * Initialize the i1480 DFU driver. | ||
481 | * | ||
482 | * We also need to register our function for guessing event sizes. | ||
483 | */ | ||
484 | static int __init i1480_dfu_driver_init(void) | ||
485 | { | ||
486 | return usb_register(&i1480_dfu_driver); | ||
487 | } | ||
488 | module_init(i1480_dfu_driver_init); | ||
489 | |||
490 | |||
491 | static void __exit i1480_dfu_driver_exit(void) | ||
492 | { | ||
493 | usb_deregister(&i1480_dfu_driver); | ||
494 | } | ||
495 | module_exit(i1480_dfu_driver_exit); | ||
496 | |||
497 | |||
498 | MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>"); | ||
499 | MODULE_DESCRIPTION("Intel Wireless UWB Link 1480 firmware uploader for USB"); | ||
500 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/uwb/i1480/i1480-est.c b/drivers/uwb/i1480/i1480-est.c new file mode 100644 index 000000000000..7bf8c6febae7 --- /dev/null +++ b/drivers/uwb/i1480/i1480-est.c | |||
@@ -0,0 +1,99 @@ | |||
1 | /* | ||
2 | * Intel Wireless UWB Link 1480 | ||
3 | * Event Size tables for Wired Adaptors | ||
4 | * | ||
5 | * Copyright (C) 2005-2006 Intel Corporation | ||
6 | * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License version | ||
10 | * 2 as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
20 | * 02110-1301, USA. | ||
21 | * | ||
22 | * | ||
23 | * FIXME: docs | ||
24 | */ | ||
25 | |||
26 | #include <linux/init.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/usb.h> | ||
29 | #include <linux/uwb.h> | ||
30 | #include "dfu/i1480-dfu.h" | ||
31 | |||
32 | |||
33 | /** Event size table for wEvents 0x00XX */ | ||
34 | static struct uwb_est_entry i1480_est_fd00[] = { | ||
35 | /* Anybody expecting this response has to use | ||
36 | * neh->extra_size to specify the real size that will | ||
37 | * come back. */ | ||
38 | [i1480_EVT_CONFIRM] = { .size = sizeof(struct i1480_evt_confirm) }, | ||
39 | [i1480_CMD_SET_IP_MAS] = { .size = sizeof(struct i1480_evt_confirm) }, | ||
40 | #ifdef i1480_RCEB_EXTENDED | ||
41 | [0x09] = { | ||
42 | .size = sizeof(struct i1480_rceb), | ||
43 | .offset = 1 + offsetof(struct i1480_rceb, wParamLength), | ||
44 | }, | ||
45 | #endif | ||
46 | }; | ||
47 | |||
48 | /** Event size table for wEvents 0x01XX */ | ||
49 | static struct uwb_est_entry i1480_est_fd01[] = { | ||
50 | [0xff & i1480_EVT_RM_INIT_DONE] = { .size = sizeof(struct i1480_rceb) }, | ||
51 | [0xff & i1480_EVT_DEV_ADD] = { .size = sizeof(struct i1480_rceb) + 9 }, | ||
52 | [0xff & i1480_EVT_DEV_RM] = { .size = sizeof(struct i1480_rceb) + 9 }, | ||
53 | [0xff & i1480_EVT_DEV_ID_CHANGE] = { | ||
54 | .size = sizeof(struct i1480_rceb) + 2 }, | ||
55 | }; | ||
56 | |||
57 | static int i1480_est_init(void) | ||
58 | { | ||
59 | int result = uwb_est_register(i1480_CET_VS1, 0x00, 0x8086, 0x0c3b, | ||
60 | i1480_est_fd00, | ||
61 | ARRAY_SIZE(i1480_est_fd00)); | ||
62 | if (result < 0) { | ||
63 | printk(KERN_ERR "Can't register EST table fd00: %d\n", result); | ||
64 | return result; | ||
65 | } | ||
66 | result = uwb_est_register(i1480_CET_VS1, 0x01, 0x8086, 0x0c3b, | ||
67 | i1480_est_fd01, ARRAY_SIZE(i1480_est_fd01)); | ||
68 | if (result < 0) { | ||
69 | printk(KERN_ERR "Can't register EST table fd01: %d\n", result); | ||
70 | return result; | ||
71 | } | ||
72 | return 0; | ||
73 | } | ||
74 | module_init(i1480_est_init); | ||
75 | |||
76 | static void i1480_est_exit(void) | ||
77 | { | ||
78 | uwb_est_unregister(i1480_CET_VS1, 0x00, 0x8086, 0x0c3b, | ||
79 | i1480_est_fd00, ARRAY_SIZE(i1480_est_fd00)); | ||
80 | uwb_est_unregister(i1480_CET_VS1, 0x01, 0x8086, 0x0c3b, | ||
81 | i1480_est_fd01, ARRAY_SIZE(i1480_est_fd01)); | ||
82 | } | ||
83 | module_exit(i1480_est_exit); | ||
84 | |||
85 | MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>"); | ||
86 | MODULE_DESCRIPTION("i1480's Vendor Specific Event Size Tables"); | ||
87 | MODULE_LICENSE("GPL"); | ||
88 | |||
89 | /** | ||
90 | * USB device ID's that we handle | ||
91 | * | ||
92 | * [so we are loaded when this kind device is connected] | ||
93 | */ | ||
94 | static struct usb_device_id i1480_est_id_table[] = { | ||
95 | { USB_DEVICE(0x8086, 0xdf3b), }, | ||
96 | { USB_DEVICE(0x8086, 0x0c3b), }, | ||
97 | { }, | ||
98 | }; | ||
99 | MODULE_DEVICE_TABLE(usb, i1480_est_id_table); | ||