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