blob: 5e079408f16e279633d28617cb776bb4c345854e [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 *
Inaky Perez-Gonzalezc931cee2009-10-19 16:24:56 +090061 * i2400mu_bus_reset() Called by i2400m_reset
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -080062 * __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 */
Dirk Brandewie73290122009-08-12 11:29:46 -070083static const char *i2400mu_bus_fw_names_5x50[] = {
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +000084#define I2400MU_FW_FILE_NAME_v1_4 "i2400m-fw-usb-1.4.sbcf"
85 I2400MU_FW_FILE_NAME_v1_4,
Dirk Brandewie73290122009-08-12 11:29:46 -070086 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,
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +000093 NULL,
94};
95
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -080096
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);
175 ret = usb_bulk_msg(i2400mu->usb_dev, pipe, buffer, barker_size,
176 &actual_len, HZ);
177 if (ret < 0) {
178 if (ret != -EINVAL)
179 dev_err(dev, "E: barker error: %d\n", ret);
180 } else if (actual_len != barker_size) {
181 dev_err(dev, "E: only %d bytes transmitted\n", actual_len);
182 ret = -EIO;
183 }
184 kfree(buffer);
185error_kzalloc:
186 if (do_autopm)
187 usb_autopm_put_interface(i2400mu->usb_iface);
188 return ret;
189}
190
191
192/*
193 * Reset a device at different levels (warm, cold or bus)
194 *
195 * @i2400m: device descriptor
196 * @reset_type: soft, warm or bus reset (I2400M_RT_WARM/SOFT/BUS)
197 *
198 * Warm and cold resets get a USB reset if they fail.
199 *
200 * Warm reset:
201 *
202 * The device will be fully reset internally, but won't be
203 * disconnected from the USB bus (so no reenumeration will
204 * happen). Firmware upload will be neccessary.
205 *
206 * The device will send a reboot barker in the notification endpoint
207 * that will trigger the driver to reinitialize the state
208 * automatically from notif.c:i2400m_notification_grok() into
209 * i2400m_dev_bootstrap_delayed().
210 *
211 * Cold and bus (USB) reset:
212 *
213 * The device will be fully reset internally, disconnected from the
214 * USB bus an a reenumeration will happen. Firmware upload will be
215 * neccessary. Thus, we don't do any locking or struct
216 * reinitialization, as we are going to be fully disconnected and
217 * reenumerated.
218 *
219 * Note we need to return -ENODEV if a warm reset was requested and we
220 * had to resort to a bus reset. See i2400m_op_reset(), wimax_reset()
221 * and wimax_dev->op_reset.
222 *
223 * WARNING: no driver state saved/fixed
224 */
225static
226int i2400mu_bus_reset(struct i2400m *i2400m, enum i2400m_reset_type rt)
227{
228 int result;
229 struct i2400mu *i2400mu =
230 container_of(i2400m, struct i2400mu, i2400m);
231 struct device *dev = i2400m_dev(i2400m);
232 static const __le32 i2400m_WARM_BOOT_BARKER[4] = {
Harvey Harrisonee437772009-02-01 00:43:54 -0800233 cpu_to_le32(I2400M_WARM_RESET_BARKER),
234 cpu_to_le32(I2400M_WARM_RESET_BARKER),
235 cpu_to_le32(I2400M_WARM_RESET_BARKER),
236 cpu_to_le32(I2400M_WARM_RESET_BARKER),
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800237 };
238 static const __le32 i2400m_COLD_BOOT_BARKER[4] = {
Harvey Harrisonee437772009-02-01 00:43:54 -0800239 cpu_to_le32(I2400M_COLD_RESET_BARKER),
240 cpu_to_le32(I2400M_COLD_RESET_BARKER),
241 cpu_to_le32(I2400M_COLD_RESET_BARKER),
242 cpu_to_le32(I2400M_COLD_RESET_BARKER),
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800243 };
244
245 d_fnstart(3, dev, "(i2400m %p rt %u)\n", i2400m, rt);
246 if (rt == I2400M_RT_WARM)
Dirk Brandewie20935862009-08-12 11:29:46 -0700247 result = __i2400mu_send_barker(
248 i2400mu, i2400m_WARM_BOOT_BARKER,
249 sizeof(i2400m_WARM_BOOT_BARKER),
250 i2400mu->endpoint_cfg.bulk_out);
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800251 else if (rt == I2400M_RT_COLD)
Dirk Brandewie20935862009-08-12 11:29:46 -0700252 result = __i2400mu_send_barker(
253 i2400mu, i2400m_COLD_BOOT_BARKER,
254 sizeof(i2400m_COLD_BOOT_BARKER),
255 i2400mu->endpoint_cfg.reset_cold);
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800256 else if (rt == I2400M_RT_BUS) {
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800257 result = usb_reset_device(i2400mu->usb_dev);
258 switch (result) {
259 case 0:
260 case -EINVAL: /* device is gone */
261 case -ENODEV:
262 case -ENOENT:
263 case -ESHUTDOWN:
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900264 result = 0;
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800265 break; /* We assume the device is disconnected */
266 default:
267 dev_err(dev, "USB reset failed (%d), giving up!\n",
268 result);
269 }
Inaky Perez-Gonzalez98eb0f52009-06-11 11:13:41 -0700270 } else {
271 result = -EINVAL; /* shut gcc up in certain arches */
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800272 BUG();
Inaky Perez-Gonzalez98eb0f52009-06-11 11:13:41 -0700273 }
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800274 if (result < 0
275 && result != -EINVAL /* device is gone */
276 && rt != I2400M_RT_BUS) {
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900277 /*
278 * Things failed -- resort to lower level reset, that
279 * we queue in another context; the reason for this is
280 * that the pre and post reset functionality requires
281 * the i2400m->init_mutex; RT_WARM and RT_COLD can
282 * come from areas where i2400m->init_mutex is taken.
283 */
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800284 dev_err(dev, "%s reset failed (%d); trying USB reset\n",
285 rt == I2400M_RT_WARM ? "warm" : "cold", result);
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900286 usb_queue_reset_device(i2400mu->usb_iface);
287 result = -ENODEV;
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800288 }
289 d_fnend(3, dev, "(i2400m %p rt %u) = %d\n", i2400m, rt, result);
290 return result;
291}
292
293
294static
295void i2400mu_netdev_setup(struct net_device *net_dev)
296{
297 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
298 struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
299 i2400mu_init(i2400mu);
300 i2400m_netdev_setup(net_dev);
301}
302
303
304/*
305 * Debug levels control; see debug.h
306 */
307struct d_level D_LEVEL[] = {
308 D_SUBMODULE_DEFINE(usb),
309 D_SUBMODULE_DEFINE(fw),
310 D_SUBMODULE_DEFINE(notif),
311 D_SUBMODULE_DEFINE(rx),
312 D_SUBMODULE_DEFINE(tx),
313};
314size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL);
315
316
317#define __debugfs_register(prefix, name, parent) \
318do { \
319 result = d_level_register_debugfs(prefix, name, parent); \
320 if (result < 0) \
321 goto error; \
322} while (0)
323
324
325static
326int i2400mu_debugfs_add(struct i2400mu *i2400mu)
327{
328 int result;
329 struct device *dev = &i2400mu->usb_iface->dev;
330 struct dentry *dentry = i2400mu->i2400m.wimax_dev.debugfs_dentry;
331 struct dentry *fd;
332
333 dentry = debugfs_create_dir("i2400m-usb", dentry);
334 result = PTR_ERR(dentry);
335 if (IS_ERR(dentry)) {
336 if (result == -ENODEV)
337 result = 0; /* No debugfs support */
338 goto error;
339 }
340 i2400mu->debugfs_dentry = dentry;
341 __debugfs_register("dl_", usb, dentry);
342 __debugfs_register("dl_", fw, dentry);
343 __debugfs_register("dl_", notif, dentry);
344 __debugfs_register("dl_", rx, dentry);
345 __debugfs_register("dl_", tx, dentry);
346
347 /* Don't touch these if you don't know what you are doing */
348 fd = debugfs_create_u8("rx_size_auto_shrink", 0600, dentry,
349 &i2400mu->rx_size_auto_shrink);
350 result = PTR_ERR(fd);
351 if (IS_ERR(fd) && result != -ENODEV) {
352 dev_err(dev, "Can't create debugfs entry "
353 "rx_size_auto_shrink: %d\n", result);
354 goto error;
355 }
356
357 fd = debugfs_create_size_t("rx_size", 0600, dentry,
358 &i2400mu->rx_size);
359 result = PTR_ERR(fd);
360 if (IS_ERR(fd) && result != -ENODEV) {
361 dev_err(dev, "Can't create debugfs entry "
362 "rx_size: %d\n", result);
363 goto error;
364 }
365
366 return 0;
367
368error:
369 debugfs_remove_recursive(i2400mu->debugfs_dentry);
370 return result;
371}
372
373
Marcel Holtmann384912e2009-08-31 21:08:19 +0000374static struct device_type i2400mu_type = {
375 .name = "wimax",
376};
377
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800378/*
379 * Probe a i2400m interface and register it
380 *
381 * @iface: USB interface to link to
382 * @id: USB class/subclass/protocol id
383 * @returns: 0 if ok, < 0 errno code on error.
384 *
385 * Alloc a net device, initialize the bus-specific details and then
386 * calls the bus-generic initialization routine. That will register
387 * the wimax and netdev devices, upload the firmware [using
388 * _bus_bm_*()], call _bus_dev_start() to finalize the setup of the
389 * communication with the device and then will start to talk to it to
390 * finnish setting it up.
391 */
392static
393int i2400mu_probe(struct usb_interface *iface,
394 const struct usb_device_id *id)
395{
396 int result;
397 struct net_device *net_dev;
398 struct device *dev = &iface->dev;
399 struct i2400m *i2400m;
400 struct i2400mu *i2400mu;
401 struct usb_device *usb_dev = interface_to_usbdev(iface);
402
403 if (usb_dev->speed != USB_SPEED_HIGH)
404 dev_err(dev, "device not connected as high speed\n");
405
406 /* Allocate instance [calls i2400m_netdev_setup() on it]. */
407 result = -ENOMEM;
408 net_dev = alloc_netdev(sizeof(*i2400mu), "wmx%d",
409 i2400mu_netdev_setup);
410 if (net_dev == NULL) {
411 dev_err(dev, "no memory for network device instance\n");
412 goto error_alloc_netdev;
413 }
414 SET_NETDEV_DEV(net_dev, dev);
Marcel Holtmann384912e2009-08-31 21:08:19 +0000415 SET_NETDEV_DEVTYPE(net_dev, &i2400mu_type);
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800416 i2400m = net_dev_to_i2400m(net_dev);
417 i2400mu = container_of(i2400m, struct i2400mu, i2400m);
418 i2400m->wimax_dev.net_dev = net_dev;
419 i2400mu->usb_dev = usb_get_dev(usb_dev);
420 i2400mu->usb_iface = iface;
421 usb_set_intfdata(iface, i2400mu);
422
423 i2400m->bus_tx_block_size = I2400MU_BLK_SIZE;
424 i2400m->bus_pl_size_max = I2400MU_PL_SIZE_MAX;
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700425 i2400m->bus_setup = NULL;
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800426 i2400m->bus_dev_start = i2400mu_bus_dev_start;
427 i2400m->bus_dev_stop = i2400mu_bus_dev_stop;
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700428 i2400m->bus_release = NULL;
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800429 i2400m->bus_tx_kick = i2400mu_bus_tx_kick;
430 i2400m->bus_reset = i2400mu_bus_reset;
Dirk Brandewiec3083652009-08-13 13:48:29 -0700431 i2400m->bus_bm_retries = I2400M_USB_BOOT_RETRIES;
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800432 i2400m->bus_bm_cmd_send = i2400mu_bus_bm_cmd_send;
433 i2400m->bus_bm_wait_for_ack = i2400mu_bus_bm_wait_for_ack;
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800434 i2400m->bus_bm_mac_addr_impaired = 0;
435
Dirk Brandewie73290122009-08-12 11:29:46 -0700436 if (id->idProduct == USB_DEVICE_ID_I6050) {
437 i2400m->bus_fw_names = i2400mu_bus_fw_names_6050;
438 i2400mu->endpoint_cfg.bulk_out = 0;
439 i2400mu->endpoint_cfg.notification = 3;
440 i2400mu->endpoint_cfg.reset_cold = 2;
441 i2400mu->endpoint_cfg.bulk_in = 1;
442 } else {
443 i2400m->bus_fw_names = i2400mu_bus_fw_names_5x50;
Dirk Brandewie20935862009-08-12 11:29:46 -0700444 i2400mu->endpoint_cfg.bulk_out = 0;
445 i2400mu->endpoint_cfg.notification = 1;
446 i2400mu->endpoint_cfg.reset_cold = 2;
447 i2400mu->endpoint_cfg.bulk_in = 3;
448 }
Inaky Perez-Gonzalez9fd7a1d2009-01-08 11:08:25 -0800449#ifdef CONFIG_PM
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800450 iface->needs_remote_wakeup = 1; /* autosuspend (15s delay) */
451 device_init_wakeup(dev, 1);
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800452 usb_dev->autosuspend_delay = 15 * HZ;
453 usb_dev->autosuspend_disabled = 0;
Inaky Perez-Gonzalez9fd7a1d2009-01-08 11:08:25 -0800454#endif
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800455
456 result = i2400m_setup(i2400m, I2400M_BRI_MAC_REINIT);
457 if (result < 0) {
458 dev_err(dev, "cannot setup device: %d\n", result);
459 goto error_setup;
460 }
461 result = i2400mu_debugfs_add(i2400mu);
462 if (result < 0) {
463 dev_err(dev, "Can't register i2400mu's debugfs: %d\n", result);
464 goto error_debugfs_add;
465 }
466 return 0;
467
468error_debugfs_add:
469 i2400m_release(i2400m);
470error_setup:
471 usb_set_intfdata(iface, NULL);
472 usb_put_dev(i2400mu->usb_dev);
473 free_netdev(net_dev);
474error_alloc_netdev:
475 return result;
476}
477
478
479/*
480 * Disconect a i2400m from the system.
481 *
482 * i2400m_stop() has been called before, so al the rx and tx contexts
483 * have been taken down already. Make sure the queue is stopped,
484 * unregister netdev and i2400m, free and kill.
485 */
486static
487void i2400mu_disconnect(struct usb_interface *iface)
488{
489 struct i2400mu *i2400mu = usb_get_intfdata(iface);
490 struct i2400m *i2400m = &i2400mu->i2400m;
491 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
492 struct device *dev = &iface->dev;
493
494 d_fnstart(3, dev, "(iface %p i2400m %p)\n", iface, i2400m);
495
496 debugfs_remove_recursive(i2400mu->debugfs_dentry);
497 i2400m_release(i2400m);
498 usb_set_intfdata(iface, NULL);
499 usb_put_dev(i2400mu->usb_dev);
500 free_netdev(net_dev);
501 d_fnend(3, dev, "(iface %p i2400m %p) = void\n", iface, i2400m);
502}
503
504
505/*
506 * Get the device ready for USB port or system standby and hibernation
507 *
508 * USB port and system standby are handled the same.
509 *
510 * When the system hibernates, the USB device is powered down and then
511 * up, so we don't really have to do much here, as it will be seen as
512 * a reconnect. Still for simplicity we consider this case the same as
513 * suspend, so that the device has a chance to do notify the base
514 * station (if connected).
515 *
516 * So at the end, the three cases require common handling.
517 *
518 * If at the time of this call the device's firmware is not loaded,
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700519 * nothing has to be done. Note we can be "loose" about not reading
520 * i2400m->updown under i2400m->init_mutex. If it happens to change
521 * inmediately, other parts of the call flow will fail and effectively
522 * catch it.
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800523 *
524 * If the firmware is loaded, we need to:
525 *
526 * - tell the device to go into host interface power save mode, wait
527 * for it to ack
528 *
529 * This is quite more interesting than it is; we need to execute a
530 * command, but this time, we don't want the code in usb-{tx,rx}.c
531 * to call the usb_autopm_get/put_interface() barriers as it'd
532 * deadlock, so we need to decrement i2400mu->do_autopm, that acts
533 * as a poor man's semaphore. Ugly, but it works.
534 *
535 * As well, the device might refuse going to sleep for whichever
536 * reason. In this case we just fail. For system suspend/hibernate,
537 * we *can't* fail. We look at usb_dev->auto_pm to see if the
538 * suspend call comes from the USB stack or from the system and act
539 * in consequence.
540 *
541 * - stop the notification endpoint polling
542 */
543static
544int i2400mu_suspend(struct usb_interface *iface, pm_message_t pm_msg)
545{
546 int result = 0;
547 struct device *dev = &iface->dev;
548 struct i2400mu *i2400mu = usb_get_intfdata(iface);
Inaky Perez-Gonzalez9fd7a1d2009-01-08 11:08:25 -0800549#ifdef CONFIG_PM
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800550 struct usb_device *usb_dev = i2400mu->usb_dev;
Inaky Perez-Gonzalez9fd7a1d2009-01-08 11:08:25 -0800551#endif
Inaky Perez-Gonzalez2618ab72009-05-08 15:51:44 -0700552 unsigned is_autosuspend = 0;
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800553 struct i2400m *i2400m = &i2400mu->i2400m;
554
Inaky Perez-Gonzalez2618ab72009-05-08 15:51:44 -0700555#ifdef CONFIG_PM
556 if (usb_dev->auto_pm > 0)
557 is_autosuspend = 1;
558#endif
559
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800560 d_fnstart(3, dev, "(iface %p pm_msg %u)\n", iface, pm_msg.event);
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700561 rmb(); /* see i2400m->updown's documentation */
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800562 if (i2400m->updown == 0)
563 goto no_firmware;
Inaky Perez-Gonzalez2618ab72009-05-08 15:51:44 -0700564 if (i2400m->state == I2400M_SS_DATA_PATH_CONNECTED && is_autosuspend) {
565 /* ugh -- the device is connected and this suspend
566 * request is an autosuspend one (not a system standby
567 * / hibernate).
568 *
569 * The only way the device can go to standby is if the
570 * link with the base station is in IDLE mode; that
571 * were the case, we'd be in status
572 * I2400M_SS_CONNECTED_IDLE. But we are not.
573 *
574 * If we *tell* him to go power save now, it'll reset
575 * as a precautionary measure, so if this is an
576 * autosuspend thing, say no and it'll come back
577 * later, when the link is IDLE
578 */
579 result = -EBADF;
580 d_printf(1, dev, "fw up, link up, not-idle, autosuspend: "
581 "not entering powersave\n");
582 goto error_not_now;
583 }
584 d_printf(1, dev, "fw up: entering powersave\n");
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800585 atomic_dec(&i2400mu->do_autopm);
586 result = i2400m_cmd_enter_powersave(i2400m);
587 atomic_inc(&i2400mu->do_autopm);
Inaky Perez-Gonzalez2618ab72009-05-08 15:51:44 -0700588 if (result < 0 && !is_autosuspend) {
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800589 /* System suspend, can't fail */
590 dev_err(dev, "failed to suspend, will reset on resume\n");
591 result = 0;
592 }
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800593 if (result < 0)
594 goto error_enter_powersave;
595 i2400mu_notification_release(i2400mu);
Inaky Perez-Gonzalez2618ab72009-05-08 15:51:44 -0700596 d_printf(1, dev, "powersave requested\n");
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800597error_enter_powersave:
Inaky Perez-Gonzalez2618ab72009-05-08 15:51:44 -0700598error_not_now:
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800599no_firmware:
600 d_fnend(3, dev, "(iface %p pm_msg %u) = %d\n",
601 iface, pm_msg.event, result);
602 return result;
603}
604
605
606static
607int i2400mu_resume(struct usb_interface *iface)
608{
609 int ret = 0;
610 struct device *dev = &iface->dev;
611 struct i2400mu *i2400mu = usb_get_intfdata(iface);
612 struct i2400m *i2400m = &i2400mu->i2400m;
613
614 d_fnstart(3, dev, "(iface %p)\n", iface);
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700615 rmb(); /* see i2400m->updown's documentation */
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800616 if (i2400m->updown == 0) {
617 d_printf(1, dev, "fw was down, no resume neeed\n");
618 goto out;
619 }
620 d_printf(1, dev, "fw was up, resuming\n");
621 i2400mu_notification_setup(i2400mu);
622 /* USB has flow control, so we don't need to give it time to
623 * come back; otherwise, we'd use something like a get-state
624 * command... */
625out:
626 d_fnend(3, dev, "(iface %p) = %d\n", iface, ret);
627 return ret;
628}
629
630
631static
Inaky Perez-Gonzalez1a5a73c2009-09-14 15:28:14 -0700632int i2400mu_reset_resume(struct usb_interface *iface)
633{
634 int result;
635 struct device *dev = &iface->dev;
636 struct i2400mu *i2400mu = usb_get_intfdata(iface);
637 struct i2400m *i2400m = &i2400mu->i2400m;
638
639 d_fnstart(3, dev, "(iface %p)\n", iface);
640 result = i2400m_dev_reset_handle(i2400m, "device reset on resume");
641 d_fnend(3, dev, "(iface %p) = %d\n", iface, result);
642 return result < 0 ? result : 0;
643}
644
645
Inaky Perez-Gonzalez3725d8c2009-09-17 15:20:45 -0700646/*
647 * Another driver or user space is triggering a reset on the device
648 * which contains the interface passed as an argument. Cease IO and
649 * save any device state you need to restore.
650 *
651 * If you need to allocate memory here, use GFP_NOIO or GFP_ATOMIC, if
652 * you are in atomic context.
653 */
654static
655int i2400mu_pre_reset(struct usb_interface *iface)
656{
657 struct i2400mu *i2400mu = usb_get_intfdata(iface);
658 return i2400m_pre_reset(&i2400mu->i2400m);
659}
660
661
662/*
663 * The reset has completed. Restore any saved device state and begin
664 * using the device again.
665 *
666 * If you need to allocate memory here, use GFP_NOIO or GFP_ATOMIC, if
667 * you are in atomic context.
668 */
669static
670int i2400mu_post_reset(struct usb_interface *iface)
671{
672 struct i2400mu *i2400mu = usb_get_intfdata(iface);
673 return i2400m_post_reset(&i2400mu->i2400m);
674}
675
676
Inaky Perez-Gonzalez1a5a73c2009-09-14 15:28:14 -0700677static
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800678struct usb_device_id i2400mu_id_table[] = {
Dirk Brandewie73290122009-08-12 11:29:46 -0700679 { USB_DEVICE(0x8086, USB_DEVICE_ID_I6050) },
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800680 { USB_DEVICE(0x8086, 0x0181) },
681 { USB_DEVICE(0x8086, 0x1403) },
682 { USB_DEVICE(0x8086, 0x1405) },
683 { USB_DEVICE(0x8086, 0x0180) },
684 { USB_DEVICE(0x8086, 0x0182) },
685 { USB_DEVICE(0x8086, 0x1406) },
686 { USB_DEVICE(0x8086, 0x1403) },
687 { },
688};
689MODULE_DEVICE_TABLE(usb, i2400mu_id_table);
690
691
692static
693struct usb_driver i2400mu_driver = {
694 .name = KBUILD_MODNAME,
695 .suspend = i2400mu_suspend,
696 .resume = i2400mu_resume,
Inaky Perez-Gonzalez1a5a73c2009-09-14 15:28:14 -0700697 .reset_resume = i2400mu_reset_resume,
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800698 .probe = i2400mu_probe,
699 .disconnect = i2400mu_disconnect,
Inaky Perez-Gonzalez3725d8c2009-09-17 15:20:45 -0700700 .pre_reset = i2400mu_pre_reset,
701 .post_reset = i2400mu_post_reset,
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800702 .id_table = i2400mu_id_table,
703 .supports_autosuspend = 1,
704};
705
706static
707int __init i2400mu_driver_init(void)
708{
Inaky Perez-Gonzalez4c2b1a12009-09-02 15:36:05 -0700709 d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400mu_debug_params,
710 "i2400m_usb.debug");
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800711 return usb_register(&i2400mu_driver);
712}
713module_init(i2400mu_driver_init);
714
715
716static
717void __exit i2400mu_driver_exit(void)
718{
719 flush_scheduled_work(); /* for the stuff we schedule from sysfs.c */
720 usb_deregister(&i2400mu_driver);
721}
722module_exit(i2400mu_driver_exit);
723
724MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>");
Dirk Brandewie73290122009-08-12 11:29:46 -0700725MODULE_DESCRIPTION("Driver for USB based Intel Wireless WiMAX Connection 2400M "
726 "(5x50 & 6050)");
Inaky Perez-Gonzalezf398e422008-12-20 16:57:51 -0800727MODULE_LICENSE("GPL");
Inaky Perez-Gonzalez1039abb2009-02-28 23:42:47 +0000728MODULE_FIRMWARE(I2400MU_FW_FILE_NAME_v1_4);