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