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