]>
Commit | Line | Data |
---|---|---|
f398e424 IPG |
1 | /* |
2 | * Intel Wireless WiMAX Connection 2400m | |
3 | * Linux driver model glue for USB device, reset & fw upload | |
4 | * | |
5 | * | |
6 | * Copyright (C) 2007-2008 Intel Corporation <linux-wimax@intel.com> | |
7 | * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> | |
8 | * Yanir Lubetkin <yanirx.lubetkin@intel.com> | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or | |
11 | * modify it under the terms of the GNU General Public License version | |
12 | * 2 as published by the Free Software Foundation. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
22 | * 02110-1301, USA. | |
23 | * | |
24 | * | |
25 | * See i2400m-usb.h for a general description of this driver. | |
26 | * | |
27 | * This file implements driver model glue, and hook ups for the | |
28 | * generic driver to implement the bus-specific functions (device | |
29 | * communication setup/tear down, firmware upload and resetting). | |
30 | * | |
31 | * ROADMAP | |
32 | * | |
33 | * i2400mu_probe() | |
34 | * alloc_netdev()... | |
35 | * i2400mu_netdev_setup() | |
36 | * i2400mu_init() | |
37 | * i2400m_netdev_setup() | |
38 | * i2400m_setup()... | |
39 | * | |
40 | * i2400mu_disconnect | |
41 | * i2400m_release() | |
42 | * free_netdev() | |
43 | * | |
44 | * i2400mu_suspend() | |
45 | * i2400m_cmd_enter_powersave() | |
46 | * i2400mu_notification_release() | |
47 | * | |
48 | * i2400mu_resume() | |
49 | * i2400mu_notification_setup() | |
50 | * | |
51 | * i2400mu_bus_dev_start() Called by i2400m_dev_start() [who is | |
52 | * i2400mu_tx_setup() called by i2400m_setup()] | |
53 | * i2400mu_rx_setup() | |
54 | * i2400mu_notification_setup() | |
55 | * | |
56 | * i2400mu_bus_dev_stop() Called by i2400m_dev_stop() [who is | |
57 | * i2400mu_notification_release() called by i2400m_release()] | |
58 | * i2400mu_rx_release() | |
59 | * i2400mu_tx_release() | |
60 | * | |
c931ceeb | 61 | * i2400mu_bus_reset() Called by i2400m_reset |
f398e424 IPG |
62 | * __i2400mu_reset() |
63 | * __i2400mu_send_barker() | |
64 | * usb_reset_device() | |
65 | */ | |
66 | #include "i2400m-usb.h" | |
67 | #include <linux/wimax/i2400m.h> | |
68 | #include <linux/debugfs.h> | |
5a0e3ad6 | 69 | #include <linux/slab.h> |
f398e424 IPG |
70 | |
71 | ||
72 | #define D_SUBMODULE usb | |
73 | #include "usb-debug-levels.h" | |
74 | ||
4c2b1a11 IPG |
75 | static char i2400mu_debug_params[128]; |
76 | module_param_string(debug, i2400mu_debug_params, sizeof(i2400mu_debug_params), | |
77 | 0644); | |
78 | MODULE_PARM_DESC(debug, | |
79 | "String of space-separated NAME:VALUE pairs, where NAMEs " | |
80 | "are the different debug submodules and VALUE are the " | |
81 | "initial debug value to set."); | |
f398e424 IPG |
82 | |
83 | /* Our firmware file name */ | |
7329012e | 84 | static const char *i2400mu_bus_fw_names_5x50[] = { |
1039abbc IPG |
85 | #define I2400MU_FW_FILE_NAME_v1_4 "i2400m-fw-usb-1.4.sbcf" |
86 | I2400MU_FW_FILE_NAME_v1_4, | |
7329012e DB |
87 | NULL, |
88 | }; | |
89 | ||
90 | ||
91 | static const char *i2400mu_bus_fw_names_6050[] = { | |
92 | #define I6050U_FW_FILE_NAME_v1_5 "i6050-fw-usb-1.5.sbcf" | |
93 | I6050U_FW_FILE_NAME_v1_5, | |
1039abbc IPG |
94 | NULL, |
95 | }; | |
96 | ||
f398e424 IPG |
97 | |
98 | static | |
99 | int i2400mu_bus_dev_start(struct i2400m *i2400m) | |
100 | { | |
101 | int result; | |
102 | struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m); | |
103 | struct device *dev = &i2400mu->usb_iface->dev; | |
104 | ||
105 | d_fnstart(3, dev, "(i2400m %p)\n", i2400m); | |
106 | result = i2400mu_tx_setup(i2400mu); | |
107 | if (result < 0) | |
108 | goto error_usb_tx_setup; | |
109 | result = i2400mu_rx_setup(i2400mu); | |
110 | if (result < 0) | |
111 | goto error_usb_rx_setup; | |
112 | result = i2400mu_notification_setup(i2400mu); | |
113 | if (result < 0) | |
114 | goto error_notif_setup; | |
115 | d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result); | |
116 | return result; | |
117 | ||
118 | error_notif_setup: | |
119 | i2400mu_rx_release(i2400mu); | |
120 | error_usb_rx_setup: | |
121 | i2400mu_tx_release(i2400mu); | |
122 | error_usb_tx_setup: | |
123 | d_fnend(3, dev, "(i2400m %p) = void\n", i2400m); | |
124 | return result; | |
125 | } | |
126 | ||
127 | ||
128 | static | |
129 | void i2400mu_bus_dev_stop(struct i2400m *i2400m) | |
130 | { | |
131 | struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m); | |
132 | struct device *dev = &i2400mu->usb_iface->dev; | |
133 | ||
134 | d_fnstart(3, dev, "(i2400m %p)\n", i2400m); | |
135 | i2400mu_notification_release(i2400mu); | |
136 | i2400mu_rx_release(i2400mu); | |
137 | i2400mu_tx_release(i2400mu); | |
138 | d_fnend(3, dev, "(i2400m %p) = void\n", i2400m); | |
139 | } | |
140 | ||
141 | ||
142 | /* | |
143 | * Sends a barker buffer to the device | |
144 | * | |
145 | * This helper will allocate a kmalloced buffer and use it to transmit | |
146 | * (then free it). Reason for this is that other arches cannot use | |
147 | * stack/vmalloc/text areas for DMA transfers. | |
148 | * | |
149 | * Error recovery here is simpler: anything is considered a hard error | |
150 | * and will move the reset code to use a last-resort bus-based reset. | |
151 | */ | |
152 | static | |
153 | int __i2400mu_send_barker(struct i2400mu *i2400mu, | |
154 | const __le32 *barker, | |
155 | size_t barker_size, | |
156 | unsigned endpoint) | |
157 | { | |
158 | struct usb_endpoint_descriptor *epd = NULL; | |
159 | int pipe, actual_len, ret; | |
160 | struct device *dev = &i2400mu->usb_iface->dev; | |
161 | void *buffer; | |
162 | int do_autopm = 1; | |
163 | ||
164 | ret = usb_autopm_get_interface(i2400mu->usb_iface); | |
165 | if (ret < 0) { | |
166 | dev_err(dev, "RESET: can't get autopm: %d\n", ret); | |
167 | do_autopm = 0; | |
168 | } | |
169 | ret = -ENOMEM; | |
170 | buffer = kmalloc(barker_size, GFP_KERNEL); | |
171 | if (buffer == NULL) | |
172 | goto error_kzalloc; | |
173 | epd = usb_get_epd(i2400mu->usb_iface, endpoint); | |
174 | pipe = usb_sndbulkpipe(i2400mu->usb_dev, epd->bEndpointAddress); | |
175 | memcpy(buffer, barker, barker_size); | |
faf57162 | 176 | retry: |
f398e424 | 177 | ret = usb_bulk_msg(i2400mu->usb_dev, pipe, buffer, barker_size, |
296bd4bd | 178 | &actual_len, 200); |
faf57162 IPG |
179 | switch (ret) { |
180 | case 0: | |
181 | if (actual_len != barker_size) { /* Too short? drop it */ | |
182 | dev_err(dev, "E: %s: short write (%d B vs %zu " | |
183 | "expected)\n", | |
184 | __func__, actual_len, barker_size); | |
185 | ret = -EIO; | |
186 | } | |
187 | break; | |
188 | case -EPIPE: | |
189 | /* | |
190 | * Stall -- maybe the device is choking with our | |
191 | * requests. Clear it and give it some time. If they | |
192 | * happen to often, it might be another symptom, so we | |
193 | * reset. | |
194 | * | |
195 | * No error handling for usb_clear_halt(0; if it | |
196 | * works, the retry works; if it fails, this switch | |
197 | * does the error handling for us. | |
198 | */ | |
199 | if (edc_inc(&i2400mu->urb_edc, | |
200 | 10 * EDC_MAX_ERRORS, EDC_ERROR_TIMEFRAME)) { | |
201 | dev_err(dev, "E: %s: too many stalls in " | |
202 | "URB; resetting device\n", __func__); | |
203 | usb_queue_reset_device(i2400mu->usb_iface); | |
204 | /* fallthrough */ | |
205 | } else { | |
206 | usb_clear_halt(i2400mu->usb_dev, pipe); | |
207 | msleep(10); /* give the device some time */ | |
208 | goto retry; | |
209 | } | |
210 | case -EINVAL: /* while removing driver */ | |
211 | case -ENODEV: /* dev disconnect ... */ | |
212 | case -ENOENT: /* just ignore it */ | |
213 | case -ESHUTDOWN: /* and exit */ | |
214 | case -ECONNRESET: | |
215 | ret = -ESHUTDOWN; | |
216 | break; | |
217 | default: /* Some error? */ | |
218 | if (edc_inc(&i2400mu->urb_edc, | |
219 | EDC_MAX_ERRORS, EDC_ERROR_TIMEFRAME)) { | |
220 | dev_err(dev, "E: %s: maximum errors in URB " | |
221 | "exceeded; resetting device\n", | |
222 | __func__); | |
223 | usb_queue_reset_device(i2400mu->usb_iface); | |
224 | } else { | |
225 | dev_warn(dev, "W: %s: cannot send URB: %d\n", | |
226 | __func__, ret); | |
227 | goto retry; | |
228 | } | |
f398e424 IPG |
229 | } |
230 | kfree(buffer); | |
231 | error_kzalloc: | |
232 | if (do_autopm) | |
233 | usb_autopm_put_interface(i2400mu->usb_iface); | |
234 | return ret; | |
235 | } | |
236 | ||
237 | ||
238 | /* | |
239 | * Reset a device at different levels (warm, cold or bus) | |
240 | * | |
241 | * @i2400m: device descriptor | |
242 | * @reset_type: soft, warm or bus reset (I2400M_RT_WARM/SOFT/BUS) | |
243 | * | |
244 | * Warm and cold resets get a USB reset if they fail. | |
245 | * | |
246 | * Warm reset: | |
247 | * | |
248 | * The device will be fully reset internally, but won't be | |
249 | * disconnected from the USB bus (so no reenumeration will | |
3ad2f3fb | 250 | * happen). Firmware upload will be necessary. |
f398e424 IPG |
251 | * |
252 | * The device will send a reboot barker in the notification endpoint | |
253 | * that will trigger the driver to reinitialize the state | |
254 | * automatically from notif.c:i2400m_notification_grok() into | |
255 | * i2400m_dev_bootstrap_delayed(). | |
256 | * | |
257 | * Cold and bus (USB) reset: | |
258 | * | |
259 | * The device will be fully reset internally, disconnected from the | |
260 | * USB bus an a reenumeration will happen. Firmware upload will be | |
3ad2f3fb | 261 | * necessary. Thus, we don't do any locking or struct |
f398e424 IPG |
262 | * reinitialization, as we are going to be fully disconnected and |
263 | * reenumerated. | |
264 | * | |
265 | * Note we need to return -ENODEV if a warm reset was requested and we | |
266 | * had to resort to a bus reset. See i2400m_op_reset(), wimax_reset() | |
267 | * and wimax_dev->op_reset. | |
268 | * | |
269 | * WARNING: no driver state saved/fixed | |
270 | */ | |
271 | static | |
272 | int i2400mu_bus_reset(struct i2400m *i2400m, enum i2400m_reset_type rt) | |
273 | { | |
274 | int result; | |
275 | struct i2400mu *i2400mu = | |
276 | container_of(i2400m, struct i2400mu, i2400m); | |
277 | struct device *dev = i2400m_dev(i2400m); | |
278 | static const __le32 i2400m_WARM_BOOT_BARKER[4] = { | |
ee437770 HH |
279 | cpu_to_le32(I2400M_WARM_RESET_BARKER), |
280 | cpu_to_le32(I2400M_WARM_RESET_BARKER), | |
281 | cpu_to_le32(I2400M_WARM_RESET_BARKER), | |
282 | cpu_to_le32(I2400M_WARM_RESET_BARKER), | |
f398e424 IPG |
283 | }; |
284 | static const __le32 i2400m_COLD_BOOT_BARKER[4] = { | |
ee437770 HH |
285 | cpu_to_le32(I2400M_COLD_RESET_BARKER), |
286 | cpu_to_le32(I2400M_COLD_RESET_BARKER), | |
287 | cpu_to_le32(I2400M_COLD_RESET_BARKER), | |
288 | cpu_to_le32(I2400M_COLD_RESET_BARKER), | |
f398e424 IPG |
289 | }; |
290 | ||
291 | d_fnstart(3, dev, "(i2400m %p rt %u)\n", i2400m, rt); | |
292 | if (rt == I2400M_RT_WARM) | |
2093586d DB |
293 | result = __i2400mu_send_barker( |
294 | i2400mu, i2400m_WARM_BOOT_BARKER, | |
295 | sizeof(i2400m_WARM_BOOT_BARKER), | |
296 | i2400mu->endpoint_cfg.bulk_out); | |
f398e424 | 297 | else if (rt == I2400M_RT_COLD) |
2093586d DB |
298 | result = __i2400mu_send_barker( |
299 | i2400mu, i2400m_COLD_BOOT_BARKER, | |
300 | sizeof(i2400m_COLD_BOOT_BARKER), | |
301 | i2400mu->endpoint_cfg.reset_cold); | |
f398e424 | 302 | else if (rt == I2400M_RT_BUS) { |
f398e424 IPG |
303 | result = usb_reset_device(i2400mu->usb_dev); |
304 | switch (result) { | |
305 | case 0: | |
306 | case -EINVAL: /* device is gone */ | |
307 | case -ENODEV: | |
308 | case -ENOENT: | |
309 | case -ESHUTDOWN: | |
b9ee9501 | 310 | result = 0; |
f398e424 IPG |
311 | break; /* We assume the device is disconnected */ |
312 | default: | |
313 | dev_err(dev, "USB reset failed (%d), giving up!\n", | |
314 | result); | |
315 | } | |
98eb0f53 IPG |
316 | } else { |
317 | result = -EINVAL; /* shut gcc up in certain arches */ | |
f398e424 | 318 | BUG(); |
98eb0f53 | 319 | } |
f398e424 IPG |
320 | if (result < 0 |
321 | && result != -EINVAL /* device is gone */ | |
322 | && rt != I2400M_RT_BUS) { | |
b9ee9501 IPG |
323 | /* |
324 | * Things failed -- resort to lower level reset, that | |
325 | * we queue in another context; the reason for this is | |
326 | * that the pre and post reset functionality requires | |
327 | * the i2400m->init_mutex; RT_WARM and RT_COLD can | |
328 | * come from areas where i2400m->init_mutex is taken. | |
329 | */ | |
f398e424 IPG |
330 | dev_err(dev, "%s reset failed (%d); trying USB reset\n", |
331 | rt == I2400M_RT_WARM ? "warm" : "cold", result); | |
b9ee9501 IPG |
332 | usb_queue_reset_device(i2400mu->usb_iface); |
333 | result = -ENODEV; | |
f398e424 IPG |
334 | } |
335 | d_fnend(3, dev, "(i2400m %p rt %u) = %d\n", i2400m, rt, result); | |
336 | return result; | |
337 | } | |
338 | ||
339 | ||
340 | static | |
341 | void i2400mu_netdev_setup(struct net_device *net_dev) | |
342 | { | |
343 | struct i2400m *i2400m = net_dev_to_i2400m(net_dev); | |
344 | struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m); | |
345 | i2400mu_init(i2400mu); | |
346 | i2400m_netdev_setup(net_dev); | |
347 | } | |
348 | ||
349 | ||
350 | /* | |
351 | * Debug levels control; see debug.h | |
352 | */ | |
353 | struct d_level D_LEVEL[] = { | |
354 | D_SUBMODULE_DEFINE(usb), | |
355 | D_SUBMODULE_DEFINE(fw), | |
356 | D_SUBMODULE_DEFINE(notif), | |
357 | D_SUBMODULE_DEFINE(rx), | |
358 | D_SUBMODULE_DEFINE(tx), | |
359 | }; | |
360 | size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL); | |
361 | ||
362 | ||
363 | #define __debugfs_register(prefix, name, parent) \ | |
364 | do { \ | |
365 | result = d_level_register_debugfs(prefix, name, parent); \ | |
366 | if (result < 0) \ | |
367 | goto error; \ | |
368 | } while (0) | |
369 | ||
370 | ||
371 | static | |
372 | int i2400mu_debugfs_add(struct i2400mu *i2400mu) | |
373 | { | |
374 | int result; | |
375 | struct device *dev = &i2400mu->usb_iface->dev; | |
376 | struct dentry *dentry = i2400mu->i2400m.wimax_dev.debugfs_dentry; | |
377 | struct dentry *fd; | |
378 | ||
379 | dentry = debugfs_create_dir("i2400m-usb", dentry); | |
380 | result = PTR_ERR(dentry); | |
381 | if (IS_ERR(dentry)) { | |
382 | if (result == -ENODEV) | |
383 | result = 0; /* No debugfs support */ | |
384 | goto error; | |
385 | } | |
386 | i2400mu->debugfs_dentry = dentry; | |
387 | __debugfs_register("dl_", usb, dentry); | |
388 | __debugfs_register("dl_", fw, dentry); | |
389 | __debugfs_register("dl_", notif, dentry); | |
390 | __debugfs_register("dl_", rx, dentry); | |
391 | __debugfs_register("dl_", tx, dentry); | |
392 | ||
393 | /* Don't touch these if you don't know what you are doing */ | |
394 | fd = debugfs_create_u8("rx_size_auto_shrink", 0600, dentry, | |
395 | &i2400mu->rx_size_auto_shrink); | |
396 | result = PTR_ERR(fd); | |
397 | if (IS_ERR(fd) && result != -ENODEV) { | |
398 | dev_err(dev, "Can't create debugfs entry " | |
399 | "rx_size_auto_shrink: %d\n", result); | |
400 | goto error; | |
401 | } | |
402 | ||
403 | fd = debugfs_create_size_t("rx_size", 0600, dentry, | |
404 | &i2400mu->rx_size); | |
405 | result = PTR_ERR(fd); | |
406 | if (IS_ERR(fd) && result != -ENODEV) { | |
407 | dev_err(dev, "Can't create debugfs entry " | |
408 | "rx_size: %d\n", result); | |
409 | goto error; | |
410 | } | |
411 | ||
412 | return 0; | |
413 | ||
414 | error: | |
415 | debugfs_remove_recursive(i2400mu->debugfs_dentry); | |
416 | return result; | |
417 | } | |
418 | ||
419 | ||
384912ed MH |
420 | static struct device_type i2400mu_type = { |
421 | .name = "wimax", | |
422 | }; | |
423 | ||
f398e424 IPG |
424 | /* |
425 | * Probe a i2400m interface and register it | |
426 | * | |
427 | * @iface: USB interface to link to | |
428 | * @id: USB class/subclass/protocol id | |
429 | * @returns: 0 if ok, < 0 errno code on error. | |
430 | * | |
431 | * Alloc a net device, initialize the bus-specific details and then | |
432 | * calls the bus-generic initialization routine. That will register | |
433 | * the wimax and netdev devices, upload the firmware [using | |
434 | * _bus_bm_*()], call _bus_dev_start() to finalize the setup of the | |
435 | * communication with the device and then will start to talk to it to | |
436 | * finnish setting it up. | |
437 | */ | |
438 | static | |
439 | int i2400mu_probe(struct usb_interface *iface, | |
440 | const struct usb_device_id *id) | |
441 | { | |
442 | int result; | |
443 | struct net_device *net_dev; | |
444 | struct device *dev = &iface->dev; | |
445 | struct i2400m *i2400m; | |
446 | struct i2400mu *i2400mu; | |
447 | struct usb_device *usb_dev = interface_to_usbdev(iface); | |
448 | ||
449 | if (usb_dev->speed != USB_SPEED_HIGH) | |
450 | dev_err(dev, "device not connected as high speed\n"); | |
451 | ||
452 | /* Allocate instance [calls i2400m_netdev_setup() on it]. */ | |
453 | result = -ENOMEM; | |
454 | net_dev = alloc_netdev(sizeof(*i2400mu), "wmx%d", | |
455 | i2400mu_netdev_setup); | |
456 | if (net_dev == NULL) { | |
457 | dev_err(dev, "no memory for network device instance\n"); | |
458 | goto error_alloc_netdev; | |
459 | } | |
460 | SET_NETDEV_DEV(net_dev, dev); | |
384912ed | 461 | SET_NETDEV_DEVTYPE(net_dev, &i2400mu_type); |
f398e424 IPG |
462 | i2400m = net_dev_to_i2400m(net_dev); |
463 | i2400mu = container_of(i2400m, struct i2400mu, i2400m); | |
464 | i2400m->wimax_dev.net_dev = net_dev; | |
465 | i2400mu->usb_dev = usb_get_dev(usb_dev); | |
466 | i2400mu->usb_iface = iface; | |
467 | usb_set_intfdata(iface, i2400mu); | |
468 | ||
469 | i2400m->bus_tx_block_size = I2400MU_BLK_SIZE; | |
470 | i2400m->bus_pl_size_max = I2400MU_PL_SIZE_MAX; | |
0856ccf2 | 471 | i2400m->bus_setup = NULL; |
f398e424 IPG |
472 | i2400m->bus_dev_start = i2400mu_bus_dev_start; |
473 | i2400m->bus_dev_stop = i2400mu_bus_dev_stop; | |
0856ccf2 | 474 | i2400m->bus_release = NULL; |
f398e424 IPG |
475 | i2400m->bus_tx_kick = i2400mu_bus_tx_kick; |
476 | i2400m->bus_reset = i2400mu_bus_reset; | |
c3083658 | 477 | i2400m->bus_bm_retries = I2400M_USB_BOOT_RETRIES; |
f398e424 IPG |
478 | i2400m->bus_bm_cmd_send = i2400mu_bus_bm_cmd_send; |
479 | i2400m->bus_bm_wait_for_ack = i2400mu_bus_bm_wait_for_ack; | |
f398e424 IPG |
480 | i2400m->bus_bm_mac_addr_impaired = 0; |
481 | ||
b8112469 IPG |
482 | switch (id->idProduct) { |
483 | case USB_DEVICE_ID_I6050: | |
484 | case USB_DEVICE_ID_I6050_2: | |
485 | i2400mu->i6050 = 1; | |
486 | break; | |
487 | default: | |
488 | break; | |
489 | } | |
490 | ||
491 | if (i2400mu->i6050) { | |
7329012e DB |
492 | i2400m->bus_fw_names = i2400mu_bus_fw_names_6050; |
493 | i2400mu->endpoint_cfg.bulk_out = 0; | |
494 | i2400mu->endpoint_cfg.notification = 3; | |
495 | i2400mu->endpoint_cfg.reset_cold = 2; | |
496 | i2400mu->endpoint_cfg.bulk_in = 1; | |
497 | } else { | |
498 | i2400m->bus_fw_names = i2400mu_bus_fw_names_5x50; | |
2093586d DB |
499 | i2400mu->endpoint_cfg.bulk_out = 0; |
500 | i2400mu->endpoint_cfg.notification = 1; | |
501 | i2400mu->endpoint_cfg.reset_cold = 2; | |
502 | i2400mu->endpoint_cfg.bulk_in = 3; | |
503 | } | |
9fd7a1d9 | 504 | #ifdef CONFIG_PM |
f398e424 IPG |
505 | iface->needs_remote_wakeup = 1; /* autosuspend (15s delay) */ |
506 | device_init_wakeup(dev, 1); | |
f398e424 IPG |
507 | usb_dev->autosuspend_delay = 15 * HZ; |
508 | usb_dev->autosuspend_disabled = 0; | |
9fd7a1d9 | 509 | #endif |
f398e424 IPG |
510 | |
511 | result = i2400m_setup(i2400m, I2400M_BRI_MAC_REINIT); | |
512 | if (result < 0) { | |
513 | dev_err(dev, "cannot setup device: %d\n", result); | |
514 | goto error_setup; | |
515 | } | |
516 | result = i2400mu_debugfs_add(i2400mu); | |
517 | if (result < 0) { | |
518 | dev_err(dev, "Can't register i2400mu's debugfs: %d\n", result); | |
519 | goto error_debugfs_add; | |
520 | } | |
521 | return 0; | |
522 | ||
523 | error_debugfs_add: | |
524 | i2400m_release(i2400m); | |
525 | error_setup: | |
526 | usb_set_intfdata(iface, NULL); | |
527 | usb_put_dev(i2400mu->usb_dev); | |
528 | free_netdev(net_dev); | |
529 | error_alloc_netdev: | |
530 | return result; | |
531 | } | |
532 | ||
533 | ||
534 | /* | |
535 | * Disconect a i2400m from the system. | |
536 | * | |
537 | * i2400m_stop() has been called before, so al the rx and tx contexts | |
538 | * have been taken down already. Make sure the queue is stopped, | |
539 | * unregister netdev and i2400m, free and kill. | |
540 | */ | |
541 | static | |
542 | void i2400mu_disconnect(struct usb_interface *iface) | |
543 | { | |
544 | struct i2400mu *i2400mu = usb_get_intfdata(iface); | |
545 | struct i2400m *i2400m = &i2400mu->i2400m; | |
546 | struct net_device *net_dev = i2400m->wimax_dev.net_dev; | |
547 | struct device *dev = &iface->dev; | |
548 | ||
549 | d_fnstart(3, dev, "(iface %p i2400m %p)\n", iface, i2400m); | |
550 | ||
551 | debugfs_remove_recursive(i2400mu->debugfs_dentry); | |
552 | i2400m_release(i2400m); | |
553 | usb_set_intfdata(iface, NULL); | |
554 | usb_put_dev(i2400mu->usb_dev); | |
555 | free_netdev(net_dev); | |
556 | d_fnend(3, dev, "(iface %p i2400m %p) = void\n", iface, i2400m); | |
557 | } | |
558 | ||
559 | ||
560 | /* | |
561 | * Get the device ready for USB port or system standby and hibernation | |
562 | * | |
563 | * USB port and system standby are handled the same. | |
564 | * | |
565 | * When the system hibernates, the USB device is powered down and then | |
566 | * up, so we don't really have to do much here, as it will be seen as | |
567 | * a reconnect. Still for simplicity we consider this case the same as | |
568 | * suspend, so that the device has a chance to do notify the base | |
569 | * station (if connected). | |
570 | * | |
571 | * So at the end, the three cases require common handling. | |
572 | * | |
573 | * If at the time of this call the device's firmware is not loaded, | |
c2315b4e IPG |
574 | * nothing has to be done. Note we can be "loose" about not reading |
575 | * i2400m->updown under i2400m->init_mutex. If it happens to change | |
576 | * inmediately, other parts of the call flow will fail and effectively | |
577 | * catch it. | |
f398e424 IPG |
578 | * |
579 | * If the firmware is loaded, we need to: | |
580 | * | |
581 | * - tell the device to go into host interface power save mode, wait | |
582 | * for it to ack | |
583 | * | |
584 | * This is quite more interesting than it is; we need to execute a | |
585 | * command, but this time, we don't want the code in usb-{tx,rx}.c | |
586 | * to call the usb_autopm_get/put_interface() barriers as it'd | |
587 | * deadlock, so we need to decrement i2400mu->do_autopm, that acts | |
588 | * as a poor man's semaphore. Ugly, but it works. | |
589 | * | |
590 | * As well, the device might refuse going to sleep for whichever | |
591 | * reason. In this case we just fail. For system suspend/hibernate, | |
fb34d537 | 592 | * we *can't* fail. We check PM_EVENT_AUTO to see if the |
f398e424 IPG |
593 | * suspend call comes from the USB stack or from the system and act |
594 | * in consequence. | |
595 | * | |
596 | * - stop the notification endpoint polling | |
597 | */ | |
598 | static | |
599 | int i2400mu_suspend(struct usb_interface *iface, pm_message_t pm_msg) | |
600 | { | |
601 | int result = 0; | |
602 | struct device *dev = &iface->dev; | |
603 | struct i2400mu *i2400mu = usb_get_intfdata(iface); | |
2618ab77 | 604 | unsigned is_autosuspend = 0; |
f398e424 IPG |
605 | struct i2400m *i2400m = &i2400mu->i2400m; |
606 | ||
2618ab77 | 607 | #ifdef CONFIG_PM |
fb34d537 | 608 | if (pm_msg.event & PM_EVENT_AUTO) |
2618ab77 IPG |
609 | is_autosuspend = 1; |
610 | #endif | |
611 | ||
f398e424 | 612 | d_fnstart(3, dev, "(iface %p pm_msg %u)\n", iface, pm_msg.event); |
c2315b4e | 613 | rmb(); /* see i2400m->updown's documentation */ |
f398e424 IPG |
614 | if (i2400m->updown == 0) |
615 | goto no_firmware; | |
2618ab77 IPG |
616 | if (i2400m->state == I2400M_SS_DATA_PATH_CONNECTED && is_autosuspend) { |
617 | /* ugh -- the device is connected and this suspend | |
618 | * request is an autosuspend one (not a system standby | |
619 | * / hibernate). | |
620 | * | |
621 | * The only way the device can go to standby is if the | |
622 | * link with the base station is in IDLE mode; that | |
623 | * were the case, we'd be in status | |
624 | * I2400M_SS_CONNECTED_IDLE. But we are not. | |
625 | * | |
626 | * If we *tell* him to go power save now, it'll reset | |
627 | * as a precautionary measure, so if this is an | |
628 | * autosuspend thing, say no and it'll come back | |
629 | * later, when the link is IDLE | |
630 | */ | |
631 | result = -EBADF; | |
632 | d_printf(1, dev, "fw up, link up, not-idle, autosuspend: " | |
633 | "not entering powersave\n"); | |
634 | goto error_not_now; | |
635 | } | |
636 | d_printf(1, dev, "fw up: entering powersave\n"); | |
f398e424 IPG |
637 | atomic_dec(&i2400mu->do_autopm); |
638 | result = i2400m_cmd_enter_powersave(i2400m); | |
639 | atomic_inc(&i2400mu->do_autopm); | |
2618ab77 | 640 | if (result < 0 && !is_autosuspend) { |
f398e424 IPG |
641 | /* System suspend, can't fail */ |
642 | dev_err(dev, "failed to suspend, will reset on resume\n"); | |
643 | result = 0; | |
644 | } | |
645 | if (result < 0) | |
646 | goto error_enter_powersave; | |
647 | i2400mu_notification_release(i2400mu); | |
2618ab77 | 648 | d_printf(1, dev, "powersave requested\n"); |
f398e424 | 649 | error_enter_powersave: |
2618ab77 | 650 | error_not_now: |
f398e424 IPG |
651 | no_firmware: |
652 | d_fnend(3, dev, "(iface %p pm_msg %u) = %d\n", | |
653 | iface, pm_msg.event, result); | |
654 | return result; | |
655 | } | |
656 | ||
657 | ||
658 | static | |
659 | int i2400mu_resume(struct usb_interface *iface) | |
660 | { | |
661 | int ret = 0; | |
662 | struct device *dev = &iface->dev; | |
663 | struct i2400mu *i2400mu = usb_get_intfdata(iface); | |
664 | struct i2400m *i2400m = &i2400mu->i2400m; | |
665 | ||
666 | d_fnstart(3, dev, "(iface %p)\n", iface); | |
c2315b4e | 667 | rmb(); /* see i2400m->updown's documentation */ |
f398e424 IPG |
668 | if (i2400m->updown == 0) { |
669 | d_printf(1, dev, "fw was down, no resume neeed\n"); | |
670 | goto out; | |
671 | } | |
672 | d_printf(1, dev, "fw was up, resuming\n"); | |
673 | i2400mu_notification_setup(i2400mu); | |
674 | /* USB has flow control, so we don't need to give it time to | |
675 | * come back; otherwise, we'd use something like a get-state | |
676 | * command... */ | |
677 | out: | |
678 | d_fnend(3, dev, "(iface %p) = %d\n", iface, ret); | |
679 | return ret; | |
680 | } | |
681 | ||
682 | ||
1a5a73c0 IPG |
683 | static |
684 | int i2400mu_reset_resume(struct usb_interface *iface) | |
685 | { | |
686 | int result; | |
687 | struct device *dev = &iface->dev; | |
688 | struct i2400mu *i2400mu = usb_get_intfdata(iface); | |
689 | struct i2400m *i2400m = &i2400mu->i2400m; | |
690 | ||
691 | d_fnstart(3, dev, "(iface %p)\n", iface); | |
692 | result = i2400m_dev_reset_handle(i2400m, "device reset on resume"); | |
693 | d_fnend(3, dev, "(iface %p) = %d\n", iface, result); | |
694 | return result < 0 ? result : 0; | |
695 | } | |
696 | ||
697 | ||
3725d8c9 IPG |
698 | /* |
699 | * Another driver or user space is triggering a reset on the device | |
700 | * which contains the interface passed as an argument. Cease IO and | |
701 | * save any device state you need to restore. | |
702 | * | |
703 | * If you need to allocate memory here, use GFP_NOIO or GFP_ATOMIC, if | |
704 | * you are in atomic context. | |
705 | */ | |
706 | static | |
707 | int i2400mu_pre_reset(struct usb_interface *iface) | |
708 | { | |
709 | struct i2400mu *i2400mu = usb_get_intfdata(iface); | |
710 | return i2400m_pre_reset(&i2400mu->i2400m); | |
711 | } | |
712 | ||
713 | ||
714 | /* | |
715 | * The reset has completed. Restore any saved device state and begin | |
716 | * using the device again. | |
717 | * | |
718 | * If you need to allocate memory here, use GFP_NOIO or GFP_ATOMIC, if | |
719 | * you are in atomic context. | |
720 | */ | |
721 | static | |
722 | int i2400mu_post_reset(struct usb_interface *iface) | |
723 | { | |
724 | struct i2400mu *i2400mu = usb_get_intfdata(iface); | |
725 | return i2400m_post_reset(&i2400mu->i2400m); | |
726 | } | |
727 | ||
728 | ||
f398e424 IPG |
729 | static |
730 | struct usb_device_id i2400mu_id_table[] = { | |
7329012e | 731 | { USB_DEVICE(0x8086, USB_DEVICE_ID_I6050) }, |
b8112469 | 732 | { USB_DEVICE(0x8086, USB_DEVICE_ID_I6050_2) }, |
f398e424 IPG |
733 | { USB_DEVICE(0x8086, 0x0181) }, |
734 | { USB_DEVICE(0x8086, 0x1403) }, | |
735 | { USB_DEVICE(0x8086, 0x1405) }, | |
736 | { USB_DEVICE(0x8086, 0x0180) }, | |
737 | { USB_DEVICE(0x8086, 0x0182) }, | |
738 | { USB_DEVICE(0x8086, 0x1406) }, | |
739 | { USB_DEVICE(0x8086, 0x1403) }, | |
740 | { }, | |
741 | }; | |
742 | MODULE_DEVICE_TABLE(usb, i2400mu_id_table); | |
743 | ||
744 | ||
745 | static | |
746 | struct usb_driver i2400mu_driver = { | |
747 | .name = KBUILD_MODNAME, | |
748 | .suspend = i2400mu_suspend, | |
749 | .resume = i2400mu_resume, | |
1a5a73c0 | 750 | .reset_resume = i2400mu_reset_resume, |
f398e424 IPG |
751 | .probe = i2400mu_probe, |
752 | .disconnect = i2400mu_disconnect, | |
3725d8c9 IPG |
753 | .pre_reset = i2400mu_pre_reset, |
754 | .post_reset = i2400mu_post_reset, | |
f398e424 IPG |
755 | .id_table = i2400mu_id_table, |
756 | .supports_autosuspend = 1, | |
757 | }; | |
758 | ||
759 | static | |
760 | int __init i2400mu_driver_init(void) | |
761 | { | |
4c2b1a11 IPG |
762 | d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400mu_debug_params, |
763 | "i2400m_usb.debug"); | |
f398e424 IPG |
764 | return usb_register(&i2400mu_driver); |
765 | } | |
766 | module_init(i2400mu_driver_init); | |
767 | ||
768 | ||
769 | static | |
770 | void __exit i2400mu_driver_exit(void) | |
771 | { | |
772 | flush_scheduled_work(); /* for the stuff we schedule from sysfs.c */ | |
773 | usb_deregister(&i2400mu_driver); | |
774 | } | |
775 | module_exit(i2400mu_driver_exit); | |
776 | ||
777 | MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>"); | |
7329012e DB |
778 | MODULE_DESCRIPTION("Driver for USB based Intel Wireless WiMAX Connection 2400M " |
779 | "(5x50 & 6050)"); | |
f398e424 | 780 | MODULE_LICENSE("GPL"); |
1039abbc | 781 | MODULE_FIRMWARE(I2400MU_FW_FILE_NAME_v1_4); |