blob: 063422290a43b65fd0a314ba58b24a03ae5b2cef [file] [log] [blame]
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -08001/*
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->bus_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
70
71#define D_SUBMODULE usb
72#include "usb-debug-levels.h"
73
Inaky Perez-Gonzalez4c2b1a12009-09-02 15:36:05 -070074static 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.");
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -080081
82/* Our firmware file name */
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +000083static const char *i2400mu_bus_fw_names[] = {
84#define I2400MU_FW_FILE_NAME_v1_4 "i2400m-fw-usb-1.4.sbcf"
85 I2400MU_FW_FILE_NAME_v1_4,
86#define I2400MU_FW_FILE_NAME_v1_3 "i2400m-fw-usb-1.3.sbcf"
87 I2400MU_FW_FILE_NAME_v1_3,
88 NULL,
89};
90
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -080091
92static
93int i2400mu_bus_dev_start(struct i2400m *i2400m)
94{
95 int result;
96 struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
97 struct device *dev = &i2400mu->usb_iface->dev;
98
99 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
100 result = i2400mu_tx_setup(i2400mu);
101 if (result < 0)
102 goto error_usb_tx_setup;
103 result = i2400mu_rx_setup(i2400mu);
104 if (result < 0)
105 goto error_usb_rx_setup;
106 result = i2400mu_notification_setup(i2400mu);
107 if (result < 0)
108 goto error_notif_setup;
109 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
110 return result;
111
112error_notif_setup:
113 i2400mu_rx_release(i2400mu);
114error_usb_rx_setup:
115 i2400mu_tx_release(i2400mu);
116error_usb_tx_setup:
117 d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
118 return result;
119}
120
121
122static
123void i2400mu_bus_dev_stop(struct i2400m *i2400m)
124{
125 struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
126 struct device *dev = &i2400mu->usb_iface->dev;
127
128 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
129 i2400mu_notification_release(i2400mu);
130 i2400mu_rx_release(i2400mu);
131 i2400mu_tx_release(i2400mu);
132 d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
133}
134
135
136/*
137 * Sends a barker buffer to the device
138 *
139 * This helper will allocate a kmalloced buffer and use it to transmit
140 * (then free it). Reason for this is that other arches cannot use
141 * stack/vmalloc/text areas for DMA transfers.
142 *
143 * Error recovery here is simpler: anything is considered a hard error
144 * and will move the reset code to use a last-resort bus-based reset.
145 */
146static
147int __i2400mu_send_barker(struct i2400mu *i2400mu,
148 const __le32 *barker,
149 size_t barker_size,
150 unsigned endpoint)
151{
152 struct usb_endpoint_descriptor *epd = NULL;
153 int pipe, actual_len, ret;
154 struct device *dev = &i2400mu->usb_iface->dev;
155 void *buffer;
156 int do_autopm = 1;
157
158 ret = usb_autopm_get_interface(i2400mu->usb_iface);
159 if (ret < 0) {
160 dev_err(dev, "RESET: can't get autopm: %d\n", ret);
161 do_autopm = 0;
162 }
163 ret = -ENOMEM;
164 buffer = kmalloc(barker_size, GFP_KERNEL);
165 if (buffer == NULL)
166 goto error_kzalloc;
167 epd = usb_get_epd(i2400mu->usb_iface, endpoint);
168 pipe = usb_sndbulkpipe(i2400mu->usb_dev, epd->bEndpointAddress);
169 memcpy(buffer, barker, barker_size);
170 ret = usb_bulk_msg(i2400mu->usb_dev, pipe, buffer, barker_size,
171 &actual_len, HZ);
172 if (ret < 0) {
173 if (ret != -EINVAL)
174 dev_err(dev, "E: barker error: %d\n", ret);
175 } else if (actual_len != barker_size) {
176 dev_err(dev, "E: only %d bytes transmitted\n", actual_len);
177 ret = -EIO;
178 }
179 kfree(buffer);
180error_kzalloc:
181 if (do_autopm)
182 usb_autopm_put_interface(i2400mu->usb_iface);
183 return ret;
184}
185
186
187/*
188 * Reset a device at different levels (warm, cold or bus)
189 *
190 * @i2400m: device descriptor
191 * @reset_type: soft, warm or bus reset (I2400M_RT_WARM/SOFT/BUS)
192 *
193 * Warm and cold resets get a USB reset if they fail.
194 *
195 * Warm reset:
196 *
197 * The device will be fully reset internally, but won't be
198 * disconnected from the USB bus (so no reenumeration will
199 * happen). Firmware upload will be neccessary.
200 *
201 * The device will send a reboot barker in the notification endpoint
202 * that will trigger the driver to reinitialize the state
203 * automatically from notif.c:i2400m_notification_grok() into
204 * i2400m_dev_bootstrap_delayed().
205 *
206 * Cold and bus (USB) reset:
207 *
208 * The device will be fully reset internally, disconnected from the
209 * USB bus an a reenumeration will happen. Firmware upload will be
210 * neccessary. Thus, we don't do any locking or struct
211 * reinitialization, as we are going to be fully disconnected and
212 * reenumerated.
213 *
214 * Note we need to return -ENODEV if a warm reset was requested and we
215 * had to resort to a bus reset. See i2400m_op_reset(), wimax_reset()
216 * and wimax_dev->op_reset.
217 *
218 * WARNING: no driver state saved/fixed
219 */
220static
221int i2400mu_bus_reset(struct i2400m *i2400m, enum i2400m_reset_type rt)
222{
223 int result;
224 struct i2400mu *i2400mu =
225 container_of(i2400m, struct i2400mu, i2400m);
226 struct device *dev = i2400m_dev(i2400m);
227 static const __le32 i2400m_WARM_BOOT_BARKER[4] = {
Harvey Harrisonee437772009-02-01 00:43:54 -0800228 cpu_to_le32(I2400M_WARM_RESET_BARKER),
229 cpu_to_le32(I2400M_WARM_RESET_BARKER),
230 cpu_to_le32(I2400M_WARM_RESET_BARKER),
231 cpu_to_le32(I2400M_WARM_RESET_BARKER),
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800232 };
233 static const __le32 i2400m_COLD_BOOT_BARKER[4] = {
Harvey Harrisonee437772009-02-01 00:43:54 -0800234 cpu_to_le32(I2400M_COLD_RESET_BARKER),
235 cpu_to_le32(I2400M_COLD_RESET_BARKER),
236 cpu_to_le32(I2400M_COLD_RESET_BARKER),
237 cpu_to_le32(I2400M_COLD_RESET_BARKER),
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800238 };
239
240 d_fnstart(3, dev, "(i2400m %p rt %u)\n", i2400m, rt);
241 if (rt == I2400M_RT_WARM)
Dirk Brandewie20935862009-08-12 11:29:46 -0700242 result = __i2400mu_send_barker(
243 i2400mu, i2400m_WARM_BOOT_BARKER,
244 sizeof(i2400m_WARM_BOOT_BARKER),
245 i2400mu->endpoint_cfg.bulk_out);
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800246 else if (rt == I2400M_RT_COLD)
Dirk Brandewie20935862009-08-12 11:29:46 -0700247 result = __i2400mu_send_barker(
248 i2400mu, i2400m_COLD_BOOT_BARKER,
249 sizeof(i2400m_COLD_BOOT_BARKER),
250 i2400mu->endpoint_cfg.reset_cold);
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800251 else if (rt == I2400M_RT_BUS) {
252do_bus_reset:
253 result = usb_reset_device(i2400mu->usb_dev);
254 switch (result) {
255 case 0:
256 case -EINVAL: /* device is gone */
257 case -ENODEV:
258 case -ENOENT:
259 case -ESHUTDOWN:
260 result = rt == I2400M_RT_WARM ? -ENODEV : 0;
261 break; /* We assume the device is disconnected */
262 default:
263 dev_err(dev, "USB reset failed (%d), giving up!\n",
264 result);
265 }
Inaky Perez-Gonzalez98eb0f52009-06-11 11:13:41 -0700266 } else {
267 result = -EINVAL; /* shut gcc up in certain arches */
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800268 BUG();
Inaky Perez-Gonzalez98eb0f52009-06-11 11:13:41 -0700269 }
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800270 if (result < 0
271 && result != -EINVAL /* device is gone */
272 && rt != I2400M_RT_BUS) {
273 dev_err(dev, "%s reset failed (%d); trying USB reset\n",
274 rt == I2400M_RT_WARM ? "warm" : "cold", result);
275 rt = I2400M_RT_BUS;
276 goto do_bus_reset;
277 }
278 d_fnend(3, dev, "(i2400m %p rt %u) = %d\n", i2400m, rt, result);
279 return result;
280}
281
282
283static
284void i2400mu_netdev_setup(struct net_device *net_dev)
285{
286 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
287 struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
288 i2400mu_init(i2400mu);
289 i2400m_netdev_setup(net_dev);
290}
291
292
293/*
294 * Debug levels control; see debug.h
295 */
296struct d_level D_LEVEL[] = {
297 D_SUBMODULE_DEFINE(usb),
298 D_SUBMODULE_DEFINE(fw),
299 D_SUBMODULE_DEFINE(notif),
300 D_SUBMODULE_DEFINE(rx),
301 D_SUBMODULE_DEFINE(tx),
302};
303size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL);
304
305
306#define __debugfs_register(prefix, name, parent) \
307do { \
308 result = d_level_register_debugfs(prefix, name, parent); \
309 if (result < 0) \
310 goto error; \
311} while (0)
312
313
314static
315int i2400mu_debugfs_add(struct i2400mu *i2400mu)
316{
317 int result;
318 struct device *dev = &i2400mu->usb_iface->dev;
319 struct dentry *dentry = i2400mu->i2400m.wimax_dev.debugfs_dentry;
320 struct dentry *fd;
321
322 dentry = debugfs_create_dir("i2400m-usb", dentry);
323 result = PTR_ERR(dentry);
324 if (IS_ERR(dentry)) {
325 if (result == -ENODEV)
326 result = 0; /* No debugfs support */
327 goto error;
328 }
329 i2400mu->debugfs_dentry = dentry;
330 __debugfs_register("dl_", usb, dentry);
331 __debugfs_register("dl_", fw, dentry);
332 __debugfs_register("dl_", notif, dentry);
333 __debugfs_register("dl_", rx, dentry);
334 __debugfs_register("dl_", tx, dentry);
335
336 /* Don't touch these if you don't know what you are doing */
337 fd = debugfs_create_u8("rx_size_auto_shrink", 0600, dentry,
338 &i2400mu->rx_size_auto_shrink);
339 result = PTR_ERR(fd);
340 if (IS_ERR(fd) && result != -ENODEV) {
341 dev_err(dev, "Can't create debugfs entry "
342 "rx_size_auto_shrink: %d\n", result);
343 goto error;
344 }
345
346 fd = debugfs_create_size_t("rx_size", 0600, dentry,
347 &i2400mu->rx_size);
348 result = PTR_ERR(fd);
349 if (IS_ERR(fd) && result != -ENODEV) {
350 dev_err(dev, "Can't create debugfs entry "
351 "rx_size: %d\n", result);
352 goto error;
353 }
354
355 return 0;
356
357error:
358 debugfs_remove_recursive(i2400mu->debugfs_dentry);
359 return result;
360}
361
362
Marcel Holtmann384912e2009-08-31 21:08:19 +0000363static struct device_type i2400mu_type = {
364 .name = "wimax",
365};
366
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800367/*
368 * Probe a i2400m interface and register it
369 *
370 * @iface: USB interface to link to
371 * @id: USB class/subclass/protocol id
372 * @returns: 0 if ok, < 0 errno code on error.
373 *
374 * Alloc a net device, initialize the bus-specific details and then
375 * calls the bus-generic initialization routine. That will register
376 * the wimax and netdev devices, upload the firmware [using
377 * _bus_bm_*()], call _bus_dev_start() to finalize the setup of the
378 * communication with the device and then will start to talk to it to
379 * finnish setting it up.
380 */
381static
382int i2400mu_probe(struct usb_interface *iface,
383 const struct usb_device_id *id)
384{
385 int result;
386 struct net_device *net_dev;
387 struct device *dev = &iface->dev;
388 struct i2400m *i2400m;
389 struct i2400mu *i2400mu;
390 struct usb_device *usb_dev = interface_to_usbdev(iface);
391
392 if (usb_dev->speed != USB_SPEED_HIGH)
393 dev_err(dev, "device not connected as high speed\n");
394
395 /* Allocate instance [calls i2400m_netdev_setup() on it]. */
396 result = -ENOMEM;
397 net_dev = alloc_netdev(sizeof(*i2400mu), "wmx%d",
398 i2400mu_netdev_setup);
399 if (net_dev == NULL) {
400 dev_err(dev, "no memory for network device instance\n");
401 goto error_alloc_netdev;
402 }
403 SET_NETDEV_DEV(net_dev, dev);
Marcel Holtmann384912e2009-08-31 21:08:19 +0000404 SET_NETDEV_DEVTYPE(net_dev, &i2400mu_type);
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800405 i2400m = net_dev_to_i2400m(net_dev);
406 i2400mu = container_of(i2400m, struct i2400mu, i2400m);
407 i2400m->wimax_dev.net_dev = net_dev;
408 i2400mu->usb_dev = usb_get_dev(usb_dev);
409 i2400mu->usb_iface = iface;
410 usb_set_intfdata(iface, i2400mu);
411
412 i2400m->bus_tx_block_size = I2400MU_BLK_SIZE;
413 i2400m->bus_pl_size_max = I2400MU_PL_SIZE_MAX;
414 i2400m->bus_dev_start = i2400mu_bus_dev_start;
415 i2400m->bus_dev_stop = i2400mu_bus_dev_stop;
416 i2400m->bus_tx_kick = i2400mu_bus_tx_kick;
417 i2400m->bus_reset = i2400mu_bus_reset;
Dirk Brandewiec3083652009-08-13 13:48:29 -0700418 i2400m->bus_bm_retries = I2400M_USB_BOOT_RETRIES;
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800419 i2400m->bus_bm_cmd_send = i2400mu_bus_bm_cmd_send;
420 i2400m->bus_bm_wait_for_ack = i2400mu_bus_bm_wait_for_ack;
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +0000421 i2400m->bus_fw_names = i2400mu_bus_fw_names;
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800422 i2400m->bus_bm_mac_addr_impaired = 0;
423
Dirk Brandewie20935862009-08-12 11:29:46 -0700424 {
425 i2400mu->endpoint_cfg.bulk_out = 0;
426 i2400mu->endpoint_cfg.notification = 1;
427 i2400mu->endpoint_cfg.reset_cold = 2;
428 i2400mu->endpoint_cfg.bulk_in = 3;
429 }
Inaky Perez-Gonzalez9fd7a1d2009-01-08 11:08:25 -0800430#ifdef CONFIG_PM
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800431 iface->needs_remote_wakeup = 1; /* autosuspend (15s delay) */
432 device_init_wakeup(dev, 1);
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800433 usb_dev->autosuspend_delay = 15 * HZ;
434 usb_dev->autosuspend_disabled = 0;
Inaky Perez-Gonzalez9fd7a1d2009-01-08 11:08:25 -0800435#endif
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800436
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700437 result = i2400m_bm_buf_alloc(i2400m);
438 if (result < 0) {
439 dev_err(dev, "cannot allocate USB bootmode buffer\n");
440 goto error_bm_buf_alloc;
441 }
442
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800443 result = i2400m_setup(i2400m, I2400M_BRI_MAC_REINIT);
444 if (result < 0) {
445 dev_err(dev, "cannot setup device: %d\n", result);
446 goto error_setup;
447 }
448 result = i2400mu_debugfs_add(i2400mu);
449 if (result < 0) {
450 dev_err(dev, "Can't register i2400mu's debugfs: %d\n", result);
451 goto error_debugfs_add;
452 }
453 return 0;
454
455error_debugfs_add:
456 i2400m_release(i2400m);
457error_setup:
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700458 i2400m_bm_buf_free(i2400m);
459error_bm_buf_alloc:
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800460 usb_set_intfdata(iface, NULL);
461 usb_put_dev(i2400mu->usb_dev);
462 free_netdev(net_dev);
463error_alloc_netdev:
464 return result;
465}
466
467
468/*
469 * Disconect a i2400m from the system.
470 *
471 * i2400m_stop() has been called before, so al the rx and tx contexts
472 * have been taken down already. Make sure the queue is stopped,
473 * unregister netdev and i2400m, free and kill.
474 */
475static
476void i2400mu_disconnect(struct usb_interface *iface)
477{
478 struct i2400mu *i2400mu = usb_get_intfdata(iface);
479 struct i2400m *i2400m = &i2400mu->i2400m;
480 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
481 struct device *dev = &iface->dev;
482
483 d_fnstart(3, dev, "(iface %p i2400m %p)\n", iface, i2400m);
484
485 debugfs_remove_recursive(i2400mu->debugfs_dentry);
486 i2400m_release(i2400m);
487 usb_set_intfdata(iface, NULL);
488 usb_put_dev(i2400mu->usb_dev);
489 free_netdev(net_dev);
490 d_fnend(3, dev, "(iface %p i2400m %p) = void\n", iface, i2400m);
491}
492
493
494/*
495 * Get the device ready for USB port or system standby and hibernation
496 *
497 * USB port and system standby are handled the same.
498 *
499 * When the system hibernates, the USB device is powered down and then
500 * up, so we don't really have to do much here, as it will be seen as
501 * a reconnect. Still for simplicity we consider this case the same as
502 * suspend, so that the device has a chance to do notify the base
503 * station (if connected).
504 *
505 * So at the end, the three cases require common handling.
506 *
507 * If at the time of this call the device's firmware is not loaded,
508 * nothing has to be done.
509 *
510 * If the firmware is loaded, we need to:
511 *
512 * - tell the device to go into host interface power save mode, wait
513 * for it to ack
514 *
515 * This is quite more interesting than it is; we need to execute a
516 * command, but this time, we don't want the code in usb-{tx,rx}.c
517 * to call the usb_autopm_get/put_interface() barriers as it'd
518 * deadlock, so we need to decrement i2400mu->do_autopm, that acts
519 * as a poor man's semaphore. Ugly, but it works.
520 *
521 * As well, the device might refuse going to sleep for whichever
522 * reason. In this case we just fail. For system suspend/hibernate,
523 * we *can't* fail. We look at usb_dev->auto_pm to see if the
524 * suspend call comes from the USB stack or from the system and act
525 * in consequence.
526 *
527 * - stop the notification endpoint polling
528 */
529static
530int i2400mu_suspend(struct usb_interface *iface, pm_message_t pm_msg)
531{
532 int result = 0;
533 struct device *dev = &iface->dev;
534 struct i2400mu *i2400mu = usb_get_intfdata(iface);
Inaky Perez-Gonzalez9fd7a1d2009-01-08 11:08:25 -0800535#ifdef CONFIG_PM
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800536 struct usb_device *usb_dev = i2400mu->usb_dev;
Inaky Perez-Gonzalez9fd7a1d2009-01-08 11:08:25 -0800537#endif
Inaky Perez-Gonzalez2618ab72009-05-08 15:51:44 -0700538 unsigned is_autosuspend = 0;
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800539 struct i2400m *i2400m = &i2400mu->i2400m;
540
Inaky Perez-Gonzalez2618ab72009-05-08 15:51:44 -0700541#ifdef CONFIG_PM
542 if (usb_dev->auto_pm > 0)
543 is_autosuspend = 1;
544#endif
545
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800546 d_fnstart(3, dev, "(iface %p pm_msg %u)\n", iface, pm_msg.event);
547 if (i2400m->updown == 0)
548 goto no_firmware;
Inaky Perez-Gonzalez2618ab72009-05-08 15:51:44 -0700549 if (i2400m->state == I2400M_SS_DATA_PATH_CONNECTED && is_autosuspend) {
550 /* ugh -- the device is connected and this suspend
551 * request is an autosuspend one (not a system standby
552 * / hibernate).
553 *
554 * The only way the device can go to standby is if the
555 * link with the base station is in IDLE mode; that
556 * were the case, we'd be in status
557 * I2400M_SS_CONNECTED_IDLE. But we are not.
558 *
559 * If we *tell* him to go power save now, it'll reset
560 * as a precautionary measure, so if this is an
561 * autosuspend thing, say no and it'll come back
562 * later, when the link is IDLE
563 */
564 result = -EBADF;
565 d_printf(1, dev, "fw up, link up, not-idle, autosuspend: "
566 "not entering powersave\n");
567 goto error_not_now;
568 }
569 d_printf(1, dev, "fw up: entering powersave\n");
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800570 atomic_dec(&i2400mu->do_autopm);
571 result = i2400m_cmd_enter_powersave(i2400m);
572 atomic_inc(&i2400mu->do_autopm);
Inaky Perez-Gonzalez2618ab72009-05-08 15:51:44 -0700573 if (result < 0 && !is_autosuspend) {
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800574 /* System suspend, can't fail */
575 dev_err(dev, "failed to suspend, will reset on resume\n");
576 result = 0;
577 }
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800578 if (result < 0)
579 goto error_enter_powersave;
580 i2400mu_notification_release(i2400mu);
Inaky Perez-Gonzalez2618ab72009-05-08 15:51:44 -0700581 d_printf(1, dev, "powersave requested\n");
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800582error_enter_powersave:
Inaky Perez-Gonzalez2618ab72009-05-08 15:51:44 -0700583error_not_now:
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800584no_firmware:
585 d_fnend(3, dev, "(iface %p pm_msg %u) = %d\n",
586 iface, pm_msg.event, result);
587 return result;
588}
589
590
591static
592int i2400mu_resume(struct usb_interface *iface)
593{
594 int ret = 0;
595 struct device *dev = &iface->dev;
596 struct i2400mu *i2400mu = usb_get_intfdata(iface);
597 struct i2400m *i2400m = &i2400mu->i2400m;
598
599 d_fnstart(3, dev, "(iface %p)\n", iface);
600 if (i2400m->updown == 0) {
601 d_printf(1, dev, "fw was down, no resume neeed\n");
602 goto out;
603 }
604 d_printf(1, dev, "fw was up, resuming\n");
605 i2400mu_notification_setup(i2400mu);
606 /* USB has flow control, so we don't need to give it time to
607 * come back; otherwise, we'd use something like a get-state
608 * command... */
609out:
610 d_fnend(3, dev, "(iface %p) = %d\n", iface, ret);
611 return ret;
612}
613
614
615static
616struct usb_device_id i2400mu_id_table[] = {
617 { USB_DEVICE(0x8086, 0x0181) },
618 { USB_DEVICE(0x8086, 0x1403) },
619 { USB_DEVICE(0x8086, 0x1405) },
620 { USB_DEVICE(0x8086, 0x0180) },
621 { USB_DEVICE(0x8086, 0x0182) },
622 { USB_DEVICE(0x8086, 0x1406) },
623 { USB_DEVICE(0x8086, 0x1403) },
624 { },
625};
626MODULE_DEVICE_TABLE(usb, i2400mu_id_table);
627
628
629static
630struct usb_driver i2400mu_driver = {
631 .name = KBUILD_MODNAME,
632 .suspend = i2400mu_suspend,
633 .resume = i2400mu_resume,
634 .probe = i2400mu_probe,
635 .disconnect = i2400mu_disconnect,
636 .id_table = i2400mu_id_table,
637 .supports_autosuspend = 1,
638};
639
640static
641int __init i2400mu_driver_init(void)
642{
Inaky Perez-Gonzalez4c2b1a12009-09-02 15:36:05 -0700643 d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400mu_debug_params,
644 "i2400m_usb.debug");
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800645 return usb_register(&i2400mu_driver);
646}
647module_init(i2400mu_driver_init);
648
649
650static
651void __exit i2400mu_driver_exit(void)
652{
653 flush_scheduled_work(); /* for the stuff we schedule from sysfs.c */
654 usb_deregister(&i2400mu_driver);
655}
656module_exit(i2400mu_driver_exit);
657
658MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>");
659MODULE_DESCRIPTION("Intel 2400M WiMAX networking for USB");
660MODULE_LICENSE("GPL");
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +0000661MODULE_FIRMWARE(I2400MU_FW_FILE_NAME_v1_4);
662MODULE_FIRMWARE(I2400MU_FW_FILE_NAME_v1_3);