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