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 | |
Inaky Perez-Gonzalez | 4c2b1a1 | 2009-09-02 15:36:05 -0700 | [diff] [blame] | 74 | static char i2400mu_debug_params[128]; |
| 75 | module_param_string(debug, i2400mu_debug_params, sizeof(i2400mu_debug_params), |
| 76 | 0644); |
| 77 | MODULE_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-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 81 | |
| 82 | /* Our firmware file name */ |
Dirk Brandewie | 7329012 | 2009-08-12 11:29:46 -0700 | [diff] [blame^] | 83 | static const char *i2400mu_bus_fw_names_5x50[] = { |
Inaky Perez-Gonzalez | 1039abb | 2009-02-28 23:42:47 +0000 | [diff] [blame] | 84 | #define I2400MU_FW_FILE_NAME_v1_4 "i2400m-fw-usb-1.4.sbcf" |
| 85 | I2400MU_FW_FILE_NAME_v1_4, |
Dirk Brandewie | 7329012 | 2009-08-12 11:29:46 -0700 | [diff] [blame^] | 86 | NULL, |
| 87 | }; |
| 88 | |
| 89 | |
| 90 | static 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-Gonzalez | 1039abb | 2009-02-28 23:42:47 +0000 | [diff] [blame] | 93 | NULL, |
| 94 | }; |
| 95 | |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 96 | |
| 97 | static |
| 98 | int 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 | |
| 117 | error_notif_setup: |
| 118 | i2400mu_rx_release(i2400mu); |
| 119 | error_usb_rx_setup: |
| 120 | i2400mu_tx_release(i2400mu); |
| 121 | error_usb_tx_setup: |
| 122 | d_fnend(3, dev, "(i2400m %p) = void\n", i2400m); |
| 123 | return result; |
| 124 | } |
| 125 | |
| 126 | |
| 127 | static |
| 128 | void 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 | */ |
| 151 | static |
| 152 | int __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); |
| 185 | error_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 | */ |
| 225 | static |
| 226 | int 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 Harrison | ee43777 | 2009-02-01 00:43:54 -0800 | [diff] [blame] | 233 | 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-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 237 | }; |
| 238 | static const __le32 i2400m_COLD_BOOT_BARKER[4] = { |
Harvey Harrison | ee43777 | 2009-02-01 00:43:54 -0800 | [diff] [blame] | 239 | 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-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 243 | }; |
| 244 | |
| 245 | d_fnstart(3, dev, "(i2400m %p rt %u)\n", i2400m, rt); |
| 246 | if (rt == I2400M_RT_WARM) |
Dirk Brandewie | 2093586 | 2009-08-12 11:29:46 -0700 | [diff] [blame] | 247 | result = __i2400mu_send_barker( |
| 248 | i2400mu, i2400m_WARM_BOOT_BARKER, |
| 249 | sizeof(i2400m_WARM_BOOT_BARKER), |
| 250 | i2400mu->endpoint_cfg.bulk_out); |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 251 | else if (rt == I2400M_RT_COLD) |
Dirk Brandewie | 2093586 | 2009-08-12 11:29:46 -0700 | [diff] [blame] | 252 | result = __i2400mu_send_barker( |
| 253 | i2400mu, i2400m_COLD_BOOT_BARKER, |
| 254 | sizeof(i2400m_COLD_BOOT_BARKER), |
| 255 | i2400mu->endpoint_cfg.reset_cold); |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 256 | else if (rt == I2400M_RT_BUS) { |
| 257 | do_bus_reset: |
| 258 | result = usb_reset_device(i2400mu->usb_dev); |
| 259 | switch (result) { |
| 260 | case 0: |
| 261 | case -EINVAL: /* device is gone */ |
| 262 | case -ENODEV: |
| 263 | case -ENOENT: |
| 264 | case -ESHUTDOWN: |
| 265 | result = rt == I2400M_RT_WARM ? -ENODEV : 0; |
| 266 | break; /* We assume the device is disconnected */ |
| 267 | default: |
| 268 | dev_err(dev, "USB reset failed (%d), giving up!\n", |
| 269 | result); |
| 270 | } |
Inaky Perez-Gonzalez | 98eb0f5 | 2009-06-11 11:13:41 -0700 | [diff] [blame] | 271 | } else { |
| 272 | result = -EINVAL; /* shut gcc up in certain arches */ |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 273 | BUG(); |
Inaky Perez-Gonzalez | 98eb0f5 | 2009-06-11 11:13:41 -0700 | [diff] [blame] | 274 | } |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 275 | if (result < 0 |
| 276 | && result != -EINVAL /* device is gone */ |
| 277 | && rt != I2400M_RT_BUS) { |
| 278 | dev_err(dev, "%s reset failed (%d); trying USB reset\n", |
| 279 | rt == I2400M_RT_WARM ? "warm" : "cold", result); |
| 280 | rt = I2400M_RT_BUS; |
| 281 | goto do_bus_reset; |
| 282 | } |
| 283 | d_fnend(3, dev, "(i2400m %p rt %u) = %d\n", i2400m, rt, result); |
| 284 | return result; |
| 285 | } |
| 286 | |
| 287 | |
| 288 | static |
| 289 | void i2400mu_netdev_setup(struct net_device *net_dev) |
| 290 | { |
| 291 | struct i2400m *i2400m = net_dev_to_i2400m(net_dev); |
| 292 | struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m); |
| 293 | i2400mu_init(i2400mu); |
| 294 | i2400m_netdev_setup(net_dev); |
| 295 | } |
| 296 | |
| 297 | |
| 298 | /* |
| 299 | * Debug levels control; see debug.h |
| 300 | */ |
| 301 | struct d_level D_LEVEL[] = { |
| 302 | D_SUBMODULE_DEFINE(usb), |
| 303 | D_SUBMODULE_DEFINE(fw), |
| 304 | D_SUBMODULE_DEFINE(notif), |
| 305 | D_SUBMODULE_DEFINE(rx), |
| 306 | D_SUBMODULE_DEFINE(tx), |
| 307 | }; |
| 308 | size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL); |
| 309 | |
| 310 | |
| 311 | #define __debugfs_register(prefix, name, parent) \ |
| 312 | do { \ |
| 313 | result = d_level_register_debugfs(prefix, name, parent); \ |
| 314 | if (result < 0) \ |
| 315 | goto error; \ |
| 316 | } while (0) |
| 317 | |
| 318 | |
| 319 | static |
| 320 | int i2400mu_debugfs_add(struct i2400mu *i2400mu) |
| 321 | { |
| 322 | int result; |
| 323 | struct device *dev = &i2400mu->usb_iface->dev; |
| 324 | struct dentry *dentry = i2400mu->i2400m.wimax_dev.debugfs_dentry; |
| 325 | struct dentry *fd; |
| 326 | |
| 327 | dentry = debugfs_create_dir("i2400m-usb", dentry); |
| 328 | result = PTR_ERR(dentry); |
| 329 | if (IS_ERR(dentry)) { |
| 330 | if (result == -ENODEV) |
| 331 | result = 0; /* No debugfs support */ |
| 332 | goto error; |
| 333 | } |
| 334 | i2400mu->debugfs_dentry = dentry; |
| 335 | __debugfs_register("dl_", usb, dentry); |
| 336 | __debugfs_register("dl_", fw, dentry); |
| 337 | __debugfs_register("dl_", notif, dentry); |
| 338 | __debugfs_register("dl_", rx, dentry); |
| 339 | __debugfs_register("dl_", tx, dentry); |
| 340 | |
| 341 | /* Don't touch these if you don't know what you are doing */ |
| 342 | fd = debugfs_create_u8("rx_size_auto_shrink", 0600, dentry, |
| 343 | &i2400mu->rx_size_auto_shrink); |
| 344 | result = PTR_ERR(fd); |
| 345 | if (IS_ERR(fd) && result != -ENODEV) { |
| 346 | dev_err(dev, "Can't create debugfs entry " |
| 347 | "rx_size_auto_shrink: %d\n", result); |
| 348 | goto error; |
| 349 | } |
| 350 | |
| 351 | fd = debugfs_create_size_t("rx_size", 0600, dentry, |
| 352 | &i2400mu->rx_size); |
| 353 | result = PTR_ERR(fd); |
| 354 | if (IS_ERR(fd) && result != -ENODEV) { |
| 355 | dev_err(dev, "Can't create debugfs entry " |
| 356 | "rx_size: %d\n", result); |
| 357 | goto error; |
| 358 | } |
| 359 | |
| 360 | return 0; |
| 361 | |
| 362 | error: |
| 363 | debugfs_remove_recursive(i2400mu->debugfs_dentry); |
| 364 | return result; |
| 365 | } |
| 366 | |
| 367 | |
Marcel Holtmann | 384912e | 2009-08-31 21:08:19 +0000 | [diff] [blame] | 368 | static struct device_type i2400mu_type = { |
| 369 | .name = "wimax", |
| 370 | }; |
| 371 | |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 372 | /* |
| 373 | * Probe a i2400m interface and register it |
| 374 | * |
| 375 | * @iface: USB interface to link to |
| 376 | * @id: USB class/subclass/protocol id |
| 377 | * @returns: 0 if ok, < 0 errno code on error. |
| 378 | * |
| 379 | * Alloc a net device, initialize the bus-specific details and then |
| 380 | * calls the bus-generic initialization routine. That will register |
| 381 | * the wimax and netdev devices, upload the firmware [using |
| 382 | * _bus_bm_*()], call _bus_dev_start() to finalize the setup of the |
| 383 | * communication with the device and then will start to talk to it to |
| 384 | * finnish setting it up. |
| 385 | */ |
| 386 | static |
| 387 | int i2400mu_probe(struct usb_interface *iface, |
| 388 | const struct usb_device_id *id) |
| 389 | { |
| 390 | int result; |
| 391 | struct net_device *net_dev; |
| 392 | struct device *dev = &iface->dev; |
| 393 | struct i2400m *i2400m; |
| 394 | struct i2400mu *i2400mu; |
| 395 | struct usb_device *usb_dev = interface_to_usbdev(iface); |
| 396 | |
| 397 | if (usb_dev->speed != USB_SPEED_HIGH) |
| 398 | dev_err(dev, "device not connected as high speed\n"); |
| 399 | |
| 400 | /* Allocate instance [calls i2400m_netdev_setup() on it]. */ |
| 401 | result = -ENOMEM; |
| 402 | net_dev = alloc_netdev(sizeof(*i2400mu), "wmx%d", |
| 403 | i2400mu_netdev_setup); |
| 404 | if (net_dev == NULL) { |
| 405 | dev_err(dev, "no memory for network device instance\n"); |
| 406 | goto error_alloc_netdev; |
| 407 | } |
| 408 | SET_NETDEV_DEV(net_dev, dev); |
Marcel Holtmann | 384912e | 2009-08-31 21:08:19 +0000 | [diff] [blame] | 409 | SET_NETDEV_DEVTYPE(net_dev, &i2400mu_type); |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 410 | i2400m = net_dev_to_i2400m(net_dev); |
| 411 | i2400mu = container_of(i2400m, struct i2400mu, i2400m); |
| 412 | i2400m->wimax_dev.net_dev = net_dev; |
| 413 | i2400mu->usb_dev = usb_get_dev(usb_dev); |
| 414 | i2400mu->usb_iface = iface; |
| 415 | usb_set_intfdata(iface, i2400mu); |
| 416 | |
| 417 | i2400m->bus_tx_block_size = I2400MU_BLK_SIZE; |
| 418 | i2400m->bus_pl_size_max = I2400MU_PL_SIZE_MAX; |
| 419 | i2400m->bus_dev_start = i2400mu_bus_dev_start; |
| 420 | i2400m->bus_dev_stop = i2400mu_bus_dev_stop; |
| 421 | i2400m->bus_tx_kick = i2400mu_bus_tx_kick; |
| 422 | i2400m->bus_reset = i2400mu_bus_reset; |
Dirk Brandewie | c308365 | 2009-08-13 13:48:29 -0700 | [diff] [blame] | 423 | i2400m->bus_bm_retries = I2400M_USB_BOOT_RETRIES; |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 424 | i2400m->bus_bm_cmd_send = i2400mu_bus_bm_cmd_send; |
| 425 | i2400m->bus_bm_wait_for_ack = i2400mu_bus_bm_wait_for_ack; |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 426 | i2400m->bus_bm_mac_addr_impaired = 0; |
| 427 | |
Dirk Brandewie | 7329012 | 2009-08-12 11:29:46 -0700 | [diff] [blame^] | 428 | if (id->idProduct == USB_DEVICE_ID_I6050) { |
| 429 | i2400m->bus_fw_names = i2400mu_bus_fw_names_6050; |
| 430 | i2400mu->endpoint_cfg.bulk_out = 0; |
| 431 | i2400mu->endpoint_cfg.notification = 3; |
| 432 | i2400mu->endpoint_cfg.reset_cold = 2; |
| 433 | i2400mu->endpoint_cfg.bulk_in = 1; |
| 434 | } else { |
| 435 | i2400m->bus_fw_names = i2400mu_bus_fw_names_5x50; |
Dirk Brandewie | 2093586 | 2009-08-12 11:29:46 -0700 | [diff] [blame] | 436 | i2400mu->endpoint_cfg.bulk_out = 0; |
| 437 | i2400mu->endpoint_cfg.notification = 1; |
| 438 | i2400mu->endpoint_cfg.reset_cold = 2; |
| 439 | i2400mu->endpoint_cfg.bulk_in = 3; |
| 440 | } |
Inaky Perez-Gonzalez | 9fd7a1d | 2009-01-08 11:08:25 -0800 | [diff] [blame] | 441 | #ifdef CONFIG_PM |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 442 | iface->needs_remote_wakeup = 1; /* autosuspend (15s delay) */ |
| 443 | device_init_wakeup(dev, 1); |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 444 | usb_dev->autosuspend_delay = 15 * HZ; |
| 445 | usb_dev->autosuspend_disabled = 0; |
Inaky Perez-Gonzalez | 9fd7a1d | 2009-01-08 11:08:25 -0800 | [diff] [blame] | 446 | #endif |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 447 | |
Dirk Brandewie | a134fd6 | 2009-08-18 08:51:52 -0700 | [diff] [blame] | 448 | result = i2400m_bm_buf_alloc(i2400m); |
| 449 | if (result < 0) { |
| 450 | dev_err(dev, "cannot allocate USB bootmode buffer\n"); |
| 451 | goto error_bm_buf_alloc; |
| 452 | } |
| 453 | |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 454 | result = i2400m_setup(i2400m, I2400M_BRI_MAC_REINIT); |
| 455 | if (result < 0) { |
| 456 | dev_err(dev, "cannot setup device: %d\n", result); |
| 457 | goto error_setup; |
| 458 | } |
| 459 | result = i2400mu_debugfs_add(i2400mu); |
| 460 | if (result < 0) { |
| 461 | dev_err(dev, "Can't register i2400mu's debugfs: %d\n", result); |
| 462 | goto error_debugfs_add; |
| 463 | } |
| 464 | return 0; |
| 465 | |
| 466 | error_debugfs_add: |
| 467 | i2400m_release(i2400m); |
| 468 | error_setup: |
Dirk Brandewie | a134fd6 | 2009-08-18 08:51:52 -0700 | [diff] [blame] | 469 | i2400m_bm_buf_free(i2400m); |
| 470 | error_bm_buf_alloc: |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 471 | usb_set_intfdata(iface, NULL); |
| 472 | usb_put_dev(i2400mu->usb_dev); |
| 473 | free_netdev(net_dev); |
| 474 | error_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 | */ |
| 486 | static |
| 487 | void 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, |
| 519 | * nothing has to be done. |
| 520 | * |
| 521 | * If the firmware is loaded, we need to: |
| 522 | * |
| 523 | * - tell the device to go into host interface power save mode, wait |
| 524 | * for it to ack |
| 525 | * |
| 526 | * This is quite more interesting than it is; we need to execute a |
| 527 | * command, but this time, we don't want the code in usb-{tx,rx}.c |
| 528 | * to call the usb_autopm_get/put_interface() barriers as it'd |
| 529 | * deadlock, so we need to decrement i2400mu->do_autopm, that acts |
| 530 | * as a poor man's semaphore. Ugly, but it works. |
| 531 | * |
| 532 | * As well, the device might refuse going to sleep for whichever |
| 533 | * reason. In this case we just fail. For system suspend/hibernate, |
| 534 | * we *can't* fail. We look at usb_dev->auto_pm to see if the |
| 535 | * suspend call comes from the USB stack or from the system and act |
| 536 | * in consequence. |
| 537 | * |
| 538 | * - stop the notification endpoint polling |
| 539 | */ |
| 540 | static |
| 541 | int i2400mu_suspend(struct usb_interface *iface, pm_message_t pm_msg) |
| 542 | { |
| 543 | int result = 0; |
| 544 | struct device *dev = &iface->dev; |
| 545 | struct i2400mu *i2400mu = usb_get_intfdata(iface); |
Inaky Perez-Gonzalez | 9fd7a1d | 2009-01-08 11:08:25 -0800 | [diff] [blame] | 546 | #ifdef CONFIG_PM |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 547 | struct usb_device *usb_dev = i2400mu->usb_dev; |
Inaky Perez-Gonzalez | 9fd7a1d | 2009-01-08 11:08:25 -0800 | [diff] [blame] | 548 | #endif |
Inaky Perez-Gonzalez | 2618ab7 | 2009-05-08 15:51:44 -0700 | [diff] [blame] | 549 | unsigned is_autosuspend = 0; |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 550 | struct i2400m *i2400m = &i2400mu->i2400m; |
| 551 | |
Inaky Perez-Gonzalez | 2618ab7 | 2009-05-08 15:51:44 -0700 | [diff] [blame] | 552 | #ifdef CONFIG_PM |
| 553 | if (usb_dev->auto_pm > 0) |
| 554 | is_autosuspend = 1; |
| 555 | #endif |
| 556 | |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 557 | d_fnstart(3, dev, "(iface %p pm_msg %u)\n", iface, pm_msg.event); |
| 558 | if (i2400m->updown == 0) |
| 559 | goto no_firmware; |
Inaky Perez-Gonzalez | 2618ab7 | 2009-05-08 15:51:44 -0700 | [diff] [blame] | 560 | if (i2400m->state == I2400M_SS_DATA_PATH_CONNECTED && is_autosuspend) { |
| 561 | /* ugh -- the device is connected and this suspend |
| 562 | * request is an autosuspend one (not a system standby |
| 563 | * / hibernate). |
| 564 | * |
| 565 | * The only way the device can go to standby is if the |
| 566 | * link with the base station is in IDLE mode; that |
| 567 | * were the case, we'd be in status |
| 568 | * I2400M_SS_CONNECTED_IDLE. But we are not. |
| 569 | * |
| 570 | * If we *tell* him to go power save now, it'll reset |
| 571 | * as a precautionary measure, so if this is an |
| 572 | * autosuspend thing, say no and it'll come back |
| 573 | * later, when the link is IDLE |
| 574 | */ |
| 575 | result = -EBADF; |
| 576 | d_printf(1, dev, "fw up, link up, not-idle, autosuspend: " |
| 577 | "not entering powersave\n"); |
| 578 | goto error_not_now; |
| 579 | } |
| 580 | d_printf(1, dev, "fw up: entering powersave\n"); |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 581 | atomic_dec(&i2400mu->do_autopm); |
| 582 | result = i2400m_cmd_enter_powersave(i2400m); |
| 583 | atomic_inc(&i2400mu->do_autopm); |
Inaky Perez-Gonzalez | 2618ab7 | 2009-05-08 15:51:44 -0700 | [diff] [blame] | 584 | if (result < 0 && !is_autosuspend) { |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 585 | /* System suspend, can't fail */ |
| 586 | dev_err(dev, "failed to suspend, will reset on resume\n"); |
| 587 | result = 0; |
| 588 | } |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 589 | if (result < 0) |
| 590 | goto error_enter_powersave; |
| 591 | i2400mu_notification_release(i2400mu); |
Inaky Perez-Gonzalez | 2618ab7 | 2009-05-08 15:51:44 -0700 | [diff] [blame] | 592 | d_printf(1, dev, "powersave requested\n"); |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 593 | error_enter_powersave: |
Inaky Perez-Gonzalez | 2618ab7 | 2009-05-08 15:51:44 -0700 | [diff] [blame] | 594 | error_not_now: |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 595 | no_firmware: |
| 596 | d_fnend(3, dev, "(iface %p pm_msg %u) = %d\n", |
| 597 | iface, pm_msg.event, result); |
| 598 | return result; |
| 599 | } |
| 600 | |
| 601 | |
| 602 | static |
| 603 | int i2400mu_resume(struct usb_interface *iface) |
| 604 | { |
| 605 | int ret = 0; |
| 606 | struct device *dev = &iface->dev; |
| 607 | struct i2400mu *i2400mu = usb_get_intfdata(iface); |
| 608 | struct i2400m *i2400m = &i2400mu->i2400m; |
| 609 | |
| 610 | d_fnstart(3, dev, "(iface %p)\n", iface); |
| 611 | if (i2400m->updown == 0) { |
| 612 | d_printf(1, dev, "fw was down, no resume neeed\n"); |
| 613 | goto out; |
| 614 | } |
| 615 | d_printf(1, dev, "fw was up, resuming\n"); |
| 616 | i2400mu_notification_setup(i2400mu); |
| 617 | /* USB has flow control, so we don't need to give it time to |
| 618 | * come back; otherwise, we'd use something like a get-state |
| 619 | * command... */ |
| 620 | out: |
| 621 | d_fnend(3, dev, "(iface %p) = %d\n", iface, ret); |
| 622 | return ret; |
| 623 | } |
| 624 | |
| 625 | |
| 626 | static |
| 627 | struct usb_device_id i2400mu_id_table[] = { |
Dirk Brandewie | 7329012 | 2009-08-12 11:29:46 -0700 | [diff] [blame^] | 628 | { USB_DEVICE(0x8086, USB_DEVICE_ID_I6050) }, |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 629 | { USB_DEVICE(0x8086, 0x0181) }, |
| 630 | { USB_DEVICE(0x8086, 0x1403) }, |
| 631 | { USB_DEVICE(0x8086, 0x1405) }, |
| 632 | { USB_DEVICE(0x8086, 0x0180) }, |
| 633 | { USB_DEVICE(0x8086, 0x0182) }, |
| 634 | { USB_DEVICE(0x8086, 0x1406) }, |
| 635 | { USB_DEVICE(0x8086, 0x1403) }, |
| 636 | { }, |
| 637 | }; |
| 638 | MODULE_DEVICE_TABLE(usb, i2400mu_id_table); |
| 639 | |
| 640 | |
| 641 | static |
| 642 | struct usb_driver i2400mu_driver = { |
| 643 | .name = KBUILD_MODNAME, |
| 644 | .suspend = i2400mu_suspend, |
| 645 | .resume = i2400mu_resume, |
| 646 | .probe = i2400mu_probe, |
| 647 | .disconnect = i2400mu_disconnect, |
| 648 | .id_table = i2400mu_id_table, |
| 649 | .supports_autosuspend = 1, |
| 650 | }; |
| 651 | |
| 652 | static |
| 653 | int __init i2400mu_driver_init(void) |
| 654 | { |
Inaky Perez-Gonzalez | 4c2b1a1 | 2009-09-02 15:36:05 -0700 | [diff] [blame] | 655 | d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400mu_debug_params, |
| 656 | "i2400m_usb.debug"); |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 657 | return usb_register(&i2400mu_driver); |
| 658 | } |
| 659 | module_init(i2400mu_driver_init); |
| 660 | |
| 661 | |
| 662 | static |
| 663 | void __exit i2400mu_driver_exit(void) |
| 664 | { |
| 665 | flush_scheduled_work(); /* for the stuff we schedule from sysfs.c */ |
| 666 | usb_deregister(&i2400mu_driver); |
| 667 | } |
| 668 | module_exit(i2400mu_driver_exit); |
| 669 | |
| 670 | MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>"); |
Dirk Brandewie | 7329012 | 2009-08-12 11:29:46 -0700 | [diff] [blame^] | 671 | MODULE_DESCRIPTION("Driver for USB based Intel Wireless WiMAX Connection 2400M " |
| 672 | "(5x50 & 6050)"); |
Inaky Perez-Gonzalez | f398e42 | 2008-12-20 16:57:51 -0800 | [diff] [blame] | 673 | MODULE_LICENSE("GPL"); |
Inaky Perez-Gonzalez | 1039abb | 2009-02-28 23:42:47 +0000 | [diff] [blame] | 674 | MODULE_FIRMWARE(I2400MU_FW_FILE_NAME_v1_4); |