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