| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Intel Wireless WiMAX Connection 2400m | 
|  | 3 | * Generic probe/disconnect, reset and message passing | 
|  | 4 | * | 
|  | 5 | * | 
|  | 6 | * Copyright (C) 2007-2008 Intel Corporation <linux-wimax@intel.com> | 
|  | 7 | * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> | 
|  | 8 | * | 
|  | 9 | * This program is free software; you can redistribute it and/or | 
|  | 10 | * modify it under the terms of the GNU General Public License version | 
|  | 11 | * 2 as published by the Free Software Foundation. | 
|  | 12 | * | 
|  | 13 | * This program is distributed in the hope that it will be useful, | 
|  | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 16 | * GNU General Public License for more details. | 
|  | 17 | * | 
|  | 18 | * You should have received a copy of the GNU General Public License | 
|  | 19 | * along with this program; if not, write to the Free Software | 
|  | 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 
|  | 21 | * 02110-1301, USA. | 
|  | 22 | * | 
|  | 23 | * | 
|  | 24 | * See i2400m.h for driver documentation. This contains helpers for | 
|  | 25 | * the driver model glue [_setup()/_release()], handling device resets | 
|  | 26 | * [_dev_reset_handle()], and the backends for the WiMAX stack ops | 
|  | 27 | * reset [_op_reset()] and message from user [_op_msg_from_user()]. | 
|  | 28 | * | 
|  | 29 | * ROADMAP: | 
|  | 30 | * | 
|  | 31 | * i2400m_op_msg_from_user() | 
|  | 32 | *   i2400m_msg_to_dev() | 
|  | 33 | *   wimax_msg_to_user_send() | 
|  | 34 | * | 
|  | 35 | * i2400m_op_reset() | 
|  | 36 | *   i240m->bus_reset() | 
|  | 37 | * | 
|  | 38 | * i2400m_dev_reset_handle() | 
|  | 39 | *   __i2400m_dev_reset_handle() | 
|  | 40 | *     __i2400m_dev_stop() | 
|  | 41 | *     __i2400m_dev_start() | 
|  | 42 | * | 
|  | 43 | * i2400m_setup() | 
| Inaky Perez-Gonzalez | 0856ccf | 2009-09-16 18:23:27 -0700 | [diff] [blame] | 44 | *   i2400m->bus_setup() | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 45 | *   i2400m_bootrom_init() | 
|  | 46 | *   register_netdev() | 
| Inaky Perez-Gonzalez | 0856ccf | 2009-09-16 18:23:27 -0700 | [diff] [blame] | 47 | *   wimax_dev_add() | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 48 | *   i2400m_dev_start() | 
|  | 49 | *     __i2400m_dev_start() | 
|  | 50 | *       i2400m_dev_bootstrap() | 
|  | 51 | *       i2400m_tx_setup() | 
|  | 52 | *       i2400m->bus_dev_start() | 
| Inaky Perez-Gonzalez | 6a0f7ab | 2009-02-28 23:42:49 +0000 | [diff] [blame] | 53 | *       i2400m_firmware_check() | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 54 | *       i2400m_check_mac_addr() | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 55 | * | 
|  | 56 | * i2400m_release() | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 57 | *   i2400m_dev_stop() | 
|  | 58 | *     __i2400m_dev_stop() | 
|  | 59 | *       i2400m_dev_shutdown() | 
|  | 60 | *       i2400m->bus_dev_stop() | 
|  | 61 | *       i2400m_tx_release() | 
| Inaky Perez-Gonzalez | 0856ccf | 2009-09-16 18:23:27 -0700 | [diff] [blame] | 62 | *   i2400m->bus_release() | 
|  | 63 | *   wimax_dev_rm() | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 64 | *   unregister_netdev() | 
|  | 65 | */ | 
|  | 66 | #include "i2400m.h" | 
| Inaky Perez-Gonzalez | fe44268 | 2009-04-22 16:53:08 -0700 | [diff] [blame] | 67 | #include <linux/etherdevice.h> | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 68 | #include <linux/wimax/i2400m.h> | 
|  | 69 | #include <linux/module.h> | 
|  | 70 | #include <linux/moduleparam.h> | 
| Inaky Perez-Gonzalez | 7b43ca7 | 2009-09-14 14:10:16 -0700 | [diff] [blame] | 71 | #include <linux/suspend.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 72 | #include <linux/slab.h> | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 73 |  | 
|  | 74 | #define D_SUBMODULE driver | 
|  | 75 | #include "debug-levels.h" | 
|  | 76 |  | 
|  | 77 |  | 
| Inaky Perez-Gonzalez | 4c2b1a1 | 2009-09-02 15:36:05 -0700 | [diff] [blame] | 78 | static char i2400m_debug_params[128]; | 
|  | 79 | module_param_string(debug, i2400m_debug_params, sizeof(i2400m_debug_params), | 
|  | 80 | 0644); | 
|  | 81 | MODULE_PARM_DESC(debug, | 
|  | 82 | "String of space-separated NAME:VALUE pairs, where NAMEs " | 
|  | 83 | "are the different debug submodules and VALUE are the " | 
|  | 84 | "initial debug value to set."); | 
|  | 85 |  | 
| Inaky Perez-Gonzalez | aba3792 | 2009-09-03 15:14:29 -0700 | [diff] [blame] | 86 | static char i2400m_barkers_params[128]; | 
|  | 87 | module_param_string(barkers, i2400m_barkers_params, | 
|  | 88 | sizeof(i2400m_barkers_params), 0644); | 
|  | 89 | MODULE_PARM_DESC(barkers, | 
|  | 90 | "String of comma-separated 32-bit values; each is " | 
|  | 91 | "recognized as the value the device sends as a reboot " | 
|  | 92 | "signal; values are appended to a list--setting one value " | 
|  | 93 | "as zero cleans the existing list and starts a new one."); | 
|  | 94 |  | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 95 | /* | 
|  | 96 | * WiMAX stack operation: relay a message from user space | 
|  | 97 | * | 
|  | 98 | * @wimax_dev: device descriptor | 
|  | 99 | * @pipe_name: named pipe the message is for | 
|  | 100 | * @msg_buf: pointer to the message bytes | 
|  | 101 | * @msg_len: length of the buffer | 
|  | 102 | * @genl_info: passed by the generic netlink layer | 
|  | 103 | * | 
|  | 104 | * The WiMAX stack will call this function when a message was received | 
|  | 105 | * from user space. | 
|  | 106 | * | 
|  | 107 | * For the i2400m, this is an L3L4 message, as specified in | 
|  | 108 | * include/linux/wimax/i2400m.h, and thus prefixed with a 'struct | 
|  | 109 | * i2400m_l3l4_hdr'. Driver (and device) expect the messages to be | 
|  | 110 | * coded in Little Endian. | 
|  | 111 | * | 
|  | 112 | * This function just verifies that the header declaration and the | 
|  | 113 | * payload are consistent and then deals with it, either forwarding it | 
|  | 114 | * to the device or procesing it locally. | 
|  | 115 | * | 
|  | 116 | * In the i2400m, messages are basically commands that will carry an | 
|  | 117 | * ack, so we use i2400m_msg_to_dev() and then deliver the ack back to | 
|  | 118 | * user space. The rx.c code might intercept the response and use it | 
|  | 119 | * to update the driver's state, but then it will pass it on so it can | 
|  | 120 | * be relayed back to user space. | 
|  | 121 | * | 
|  | 122 | * Note that asynchronous events from the device are processed and | 
|  | 123 | * sent to user space in rx.c. | 
|  | 124 | */ | 
|  | 125 | static | 
|  | 126 | int i2400m_op_msg_from_user(struct wimax_dev *wimax_dev, | 
|  | 127 | const char *pipe_name, | 
|  | 128 | const void *msg_buf, size_t msg_len, | 
|  | 129 | const struct genl_info *genl_info) | 
|  | 130 | { | 
|  | 131 | int result; | 
|  | 132 | struct i2400m *i2400m = wimax_dev_to_i2400m(wimax_dev); | 
|  | 133 | struct device *dev = i2400m_dev(i2400m); | 
|  | 134 | struct sk_buff *ack_skb; | 
|  | 135 |  | 
|  | 136 | d_fnstart(4, dev, "(wimax_dev %p [i2400m %p] msg_buf %p " | 
|  | 137 | "msg_len %zu genl_info %p)\n", wimax_dev, i2400m, | 
|  | 138 | msg_buf, msg_len, genl_info); | 
|  | 139 | ack_skb = i2400m_msg_to_dev(i2400m, msg_buf, msg_len); | 
|  | 140 | result = PTR_ERR(ack_skb); | 
|  | 141 | if (IS_ERR(ack_skb)) | 
|  | 142 | goto error_msg_to_dev; | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 143 | result = wimax_msg_send(&i2400m->wimax_dev, ack_skb); | 
|  | 144 | error_msg_to_dev: | 
|  | 145 | d_fnend(4, dev, "(wimax_dev %p [i2400m %p] msg_buf %p msg_len %zu " | 
|  | 146 | "genl_info %p) = %d\n", wimax_dev, i2400m, msg_buf, msg_len, | 
|  | 147 | genl_info, result); | 
|  | 148 | return result; | 
|  | 149 | } | 
|  | 150 |  | 
|  | 151 |  | 
|  | 152 | /* | 
|  | 153 | * Context to wait for a reset to finalize | 
|  | 154 | */ | 
|  | 155 | struct i2400m_reset_ctx { | 
|  | 156 | struct completion completion; | 
|  | 157 | int result; | 
|  | 158 | }; | 
|  | 159 |  | 
|  | 160 |  | 
|  | 161 | /* | 
|  | 162 | * WiMAX stack operation: reset a device | 
|  | 163 | * | 
|  | 164 | * @wimax_dev: device descriptor | 
|  | 165 | * | 
|  | 166 | * See the documentation for wimax_reset() and wimax_dev->op_reset for | 
|  | 167 | * the requirements of this function. The WiMAX stack guarantees | 
|  | 168 | * serialization on calls to this function. | 
|  | 169 | * | 
|  | 170 | * Do a warm reset on the device; if it fails, resort to a cold reset | 
|  | 171 | * and return -ENODEV. On successful warm reset, we need to block | 
|  | 172 | * until it is complete. | 
|  | 173 | * | 
|  | 174 | * The bus-driver implementation of reset takes care of falling back | 
|  | 175 | * to cold reset if warm fails. | 
|  | 176 | */ | 
|  | 177 | static | 
|  | 178 | int i2400m_op_reset(struct wimax_dev *wimax_dev) | 
|  | 179 | { | 
|  | 180 | int result; | 
|  | 181 | struct i2400m *i2400m = wimax_dev_to_i2400m(wimax_dev); | 
|  | 182 | struct device *dev = i2400m_dev(i2400m); | 
|  | 183 | struct i2400m_reset_ctx ctx = { | 
|  | 184 | .completion = COMPLETION_INITIALIZER_ONSTACK(ctx.completion), | 
|  | 185 | .result = 0, | 
|  | 186 | }; | 
|  | 187 |  | 
|  | 188 | d_fnstart(4, dev, "(wimax_dev %p)\n", wimax_dev); | 
|  | 189 | mutex_lock(&i2400m->init_mutex); | 
|  | 190 | i2400m->reset_ctx = &ctx; | 
|  | 191 | mutex_unlock(&i2400m->init_mutex); | 
| Inaky Perez-Gonzalez | c931cee | 2009-10-19 16:24:56 +0900 | [diff] [blame] | 192 | result = i2400m_reset(i2400m, I2400M_RT_WARM); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 193 | if (result < 0) | 
|  | 194 | goto out; | 
|  | 195 | result = wait_for_completion_timeout(&ctx.completion, 4*HZ); | 
|  | 196 | if (result == 0) | 
|  | 197 | result = -ETIMEDOUT; | 
|  | 198 | else if (result > 0) | 
|  | 199 | result = ctx.result; | 
|  | 200 | /* if result < 0, pass it on */ | 
|  | 201 | mutex_lock(&i2400m->init_mutex); | 
|  | 202 | i2400m->reset_ctx = NULL; | 
|  | 203 | mutex_unlock(&i2400m->init_mutex); | 
|  | 204 | out: | 
|  | 205 | d_fnend(4, dev, "(wimax_dev %p) = %d\n", wimax_dev, result); | 
|  | 206 | return result; | 
|  | 207 | } | 
|  | 208 |  | 
|  | 209 |  | 
|  | 210 | /* | 
|  | 211 | * Check the MAC address we got from boot mode is ok | 
|  | 212 | * | 
|  | 213 | * @i2400m: device descriptor | 
|  | 214 | * | 
|  | 215 | * Returns: 0 if ok, < 0 errno code on error. | 
|  | 216 | */ | 
|  | 217 | static | 
|  | 218 | int i2400m_check_mac_addr(struct i2400m *i2400m) | 
|  | 219 | { | 
|  | 220 | int result; | 
|  | 221 | struct device *dev = i2400m_dev(i2400m); | 
|  | 222 | struct sk_buff *skb; | 
|  | 223 | const struct i2400m_tlv_detailed_device_info *ddi; | 
|  | 224 | struct net_device *net_dev = i2400m->wimax_dev.net_dev; | 
|  | 225 | const unsigned char zeromac[ETH_ALEN] = { 0 }; | 
|  | 226 |  | 
|  | 227 | d_fnstart(3, dev, "(i2400m %p)\n", i2400m); | 
|  | 228 | skb = i2400m_get_device_info(i2400m); | 
|  | 229 | if (IS_ERR(skb)) { | 
|  | 230 | result = PTR_ERR(skb); | 
|  | 231 | dev_err(dev, "Cannot verify MAC address, error reading: %d\n", | 
|  | 232 | result); | 
|  | 233 | goto error; | 
|  | 234 | } | 
| Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 235 | /* Extract MAC address */ | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 236 | ddi = (void *) skb->data; | 
|  | 237 | BUILD_BUG_ON(ETH_ALEN != sizeof(ddi->mac_address)); | 
| hartleys | 4754b3d | 2010-01-05 07:00:57 +0000 | [diff] [blame] | 238 | d_printf(2, dev, "GET DEVICE INFO: mac addr %pM\n", | 
|  | 239 | ddi->mac_address); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 240 | if (!memcmp(net_dev->perm_addr, ddi->mac_address, | 
|  | 241 | sizeof(ddi->mac_address))) | 
|  | 242 | goto ok; | 
|  | 243 | dev_warn(dev, "warning: device reports a different MAC address " | 
|  | 244 | "to that of boot mode's\n"); | 
| hartleys | 4754b3d | 2010-01-05 07:00:57 +0000 | [diff] [blame] | 245 | dev_warn(dev, "device reports     %pM\n", ddi->mac_address); | 
|  | 246 | dev_warn(dev, "boot mode reported %pM\n", net_dev->perm_addr); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 247 | if (!memcmp(zeromac, ddi->mac_address, sizeof(zeromac))) | 
|  | 248 | dev_err(dev, "device reports an invalid MAC address, " | 
|  | 249 | "not updating\n"); | 
|  | 250 | else { | 
|  | 251 | dev_warn(dev, "updating MAC address\n"); | 
|  | 252 | net_dev->addr_len = ETH_ALEN; | 
|  | 253 | memcpy(net_dev->perm_addr, ddi->mac_address, ETH_ALEN); | 
|  | 254 | memcpy(net_dev->dev_addr, ddi->mac_address, ETH_ALEN); | 
|  | 255 | } | 
|  | 256 | ok: | 
|  | 257 | result = 0; | 
|  | 258 | kfree_skb(skb); | 
|  | 259 | error: | 
|  | 260 | d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result); | 
|  | 261 | return result; | 
|  | 262 | } | 
|  | 263 |  | 
|  | 264 |  | 
|  | 265 | /** | 
|  | 266 | * __i2400m_dev_start - Bring up driver communication with the device | 
|  | 267 | * | 
|  | 268 | * @i2400m: device descriptor | 
|  | 269 | * @flags: boot mode flags | 
|  | 270 | * | 
|  | 271 | * Returns: 0 if ok, < 0 errno code on error. | 
|  | 272 | * | 
|  | 273 | * Uploads firmware and brings up all the resources needed to be able | 
|  | 274 | * to communicate with the device. | 
|  | 275 | * | 
| Inaky Perez-Gonzalez | e9a6b45 | 2009-05-08 13:02:41 -0700 | [diff] [blame] | 276 | * The workqueue has to be setup early, at least before RX handling | 
|  | 277 | * (it's only real user for now) so it can process reports as they | 
|  | 278 | * arrive. We also want to destroy it if we retry, to make sure it is | 
|  | 279 | * flushed...easier like this. | 
|  | 280 | * | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 281 | * TX needs to be setup before the bus-specific code (otherwise on | 
|  | 282 | * shutdown, the bus-tx code could try to access it). | 
|  | 283 | */ | 
|  | 284 | static | 
|  | 285 | int __i2400m_dev_start(struct i2400m *i2400m, enum i2400m_bri flags) | 
|  | 286 | { | 
|  | 287 | int result; | 
|  | 288 | struct wimax_dev *wimax_dev = &i2400m->wimax_dev; | 
|  | 289 | struct net_device *net_dev = wimax_dev->net_dev; | 
|  | 290 | struct device *dev = i2400m_dev(i2400m); | 
| Inaky Perez-Gonzalez | ecddfd5 | 2009-06-03 16:13:14 +0800 | [diff] [blame] | 291 | int times = i2400m->bus_bm_retries; | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 292 |  | 
|  | 293 | d_fnstart(3, dev, "(i2400m %p)\n", i2400m); | 
|  | 294 | retry: | 
|  | 295 | result = i2400m_dev_bootstrap(i2400m, flags); | 
|  | 296 | if (result < 0) { | 
|  | 297 | dev_err(dev, "cannot bootstrap device: %d\n", result); | 
|  | 298 | goto error_bootstrap; | 
|  | 299 | } | 
|  | 300 | result = i2400m_tx_setup(i2400m); | 
|  | 301 | if (result < 0) | 
|  | 302 | goto error_tx_setup; | 
| Inaky Perez-Gonzalez | c747583 | 2009-02-28 23:42:54 +0000 | [diff] [blame] | 303 | result = i2400m_rx_setup(i2400m); | 
|  | 304 | if (result < 0) | 
|  | 305 | goto error_rx_setup; | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 306 | i2400m->work_queue = create_singlethread_workqueue(wimax_dev->name); | 
|  | 307 | if (i2400m->work_queue == NULL) { | 
|  | 308 | result = -ENOMEM; | 
|  | 309 | dev_err(dev, "cannot create workqueue\n"); | 
|  | 310 | goto error_create_workqueue; | 
|  | 311 | } | 
| Inaky Perez-Gonzalez | 097acbe | 2009-10-08 12:33:50 +0900 | [diff] [blame] | 312 | if (i2400m->bus_dev_start) { | 
|  | 313 | result = i2400m->bus_dev_start(i2400m); | 
|  | 314 | if (result < 0) | 
|  | 315 | goto error_bus_dev_start; | 
|  | 316 | } | 
| Inaky Perez-Gonzalez | c2315b4 | 2009-09-16 17:10:55 -0700 | [diff] [blame] | 317 | i2400m->ready = 1; | 
|  | 318 | wmb();		/* see i2400m->ready's documentation  */ | 
| Inaky Perez-Gonzalez | a0beba2 | 2009-10-07 21:43:10 +0900 | [diff] [blame] | 319 | /* process pending reports from the device */ | 
|  | 320 | queue_work(i2400m->work_queue, &i2400m->rx_report_ws); | 
| Inaky Perez-Gonzalez | 6a0f7ab | 2009-02-28 23:42:49 +0000 | [diff] [blame] | 321 | result = i2400m_firmware_check(i2400m);	/* fw versions ok? */ | 
|  | 322 | if (result < 0) | 
|  | 323 | goto error_fw_check; | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 324 | /* At this point is ok to send commands to the device */ | 
|  | 325 | result = i2400m_check_mac_addr(i2400m); | 
|  | 326 | if (result < 0) | 
|  | 327 | goto error_check_mac_addr; | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 328 | result = i2400m_dev_initialize(i2400m); | 
|  | 329 | if (result < 0) | 
|  | 330 | goto error_dev_initialize; | 
| Cindy H Kao | 599e595 | 2010-04-07 20:07:47 -0700 | [diff] [blame] | 331 |  | 
|  | 332 | /* We don't want any additional unwanted error recovery triggered | 
|  | 333 | * from any other context so if anything went wrong before we come | 
|  | 334 | * here, let's keep i2400m->error_recovery untouched and leave it to | 
|  | 335 | * dev_reset_handle(). See dev_reset_handle(). */ | 
|  | 336 |  | 
|  | 337 | atomic_dec(&i2400m->error_recovery); | 
|  | 338 | /* Every thing works so far, ok, now we are ready to | 
|  | 339 | * take error recovery if it's required. */ | 
|  | 340 |  | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 341 | /* At this point, reports will come for the device and set it | 
|  | 342 | * to the right state if it is different than UNINITIALIZED */ | 
|  | 343 | d_fnend(3, dev, "(net_dev %p [i2400m %p]) = %d\n", | 
|  | 344 | net_dev, i2400m, result); | 
|  | 345 | return result; | 
|  | 346 |  | 
|  | 347 | error_dev_initialize: | 
|  | 348 | error_check_mac_addr: | 
| Cindy H Kao | 49d72df | 2010-03-30 19:19:37 -0700 | [diff] [blame] | 349 | error_fw_check: | 
| Inaky Perez-Gonzalez | c2315b4 | 2009-09-16 17:10:55 -0700 | [diff] [blame] | 350 | i2400m->ready = 0; | 
|  | 351 | wmb();		/* see i2400m->ready's documentation  */ | 
|  | 352 | flush_workqueue(i2400m->work_queue); | 
| Inaky Perez-Gonzalez | 097acbe | 2009-10-08 12:33:50 +0900 | [diff] [blame] | 353 | if (i2400m->bus_dev_stop) | 
|  | 354 | i2400m->bus_dev_stop(i2400m); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 355 | error_bus_dev_start: | 
| Inaky Perez-Gonzalez | e9a6b45 | 2009-05-08 13:02:41 -0700 | [diff] [blame] | 356 | destroy_workqueue(i2400m->work_queue); | 
|  | 357 | error_create_workqueue: | 
| Inaky Perez-Gonzalez | c747583 | 2009-02-28 23:42:54 +0000 | [diff] [blame] | 358 | i2400m_rx_release(i2400m); | 
|  | 359 | error_rx_setup: | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 360 | i2400m_tx_release(i2400m); | 
|  | 361 | error_tx_setup: | 
|  | 362 | error_bootstrap: | 
| Cindy H Kao | 0bcfc5e | 2009-06-10 17:06:19 -0700 | [diff] [blame] | 363 | if (result == -EL3RST && times-- > 0) { | 
| Cindy H Kao | 8b5b30e | 2009-06-10 16:52:10 -0700 | [diff] [blame] | 364 | flags = I2400M_BRI_SOFT|I2400M_BRI_MAC_REINIT; | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 365 | goto retry; | 
|  | 366 | } | 
|  | 367 | d_fnend(3, dev, "(net_dev %p [i2400m %p]) = %d\n", | 
|  | 368 | net_dev, i2400m, result); | 
|  | 369 | return result; | 
|  | 370 | } | 
|  | 371 |  | 
|  | 372 |  | 
|  | 373 | static | 
|  | 374 | int i2400m_dev_start(struct i2400m *i2400m, enum i2400m_bri bm_flags) | 
|  | 375 | { | 
| Inaky Perez-Gonzalez | c2315b4 | 2009-09-16 17:10:55 -0700 | [diff] [blame] | 376 | int result = 0; | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 377 | mutex_lock(&i2400m->init_mutex);	/* Well, start the device */ | 
| Inaky Perez-Gonzalez | c2315b4 | 2009-09-16 17:10:55 -0700 | [diff] [blame] | 378 | if (i2400m->updown == 0) { | 
|  | 379 | result = __i2400m_dev_start(i2400m, bm_flags); | 
|  | 380 | if (result >= 0) { | 
|  | 381 | i2400m->updown = 1; | 
| Cindy H Kao | f4e4134 | 2010-04-07 19:42:42 -0700 | [diff] [blame] | 382 | i2400m->alive = 1; | 
|  | 383 | wmb();/* see i2400m->updown and i2400m->alive's doc */ | 
| Inaky Perez-Gonzalez | c2315b4 | 2009-09-16 17:10:55 -0700 | [diff] [blame] | 384 | } | 
|  | 385 | } | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 386 | mutex_unlock(&i2400m->init_mutex); | 
|  | 387 | return result; | 
|  | 388 | } | 
|  | 389 |  | 
|  | 390 |  | 
|  | 391 | /** | 
|  | 392 | * i2400m_dev_stop - Tear down driver communication with the device | 
|  | 393 | * | 
|  | 394 | * @i2400m: device descriptor | 
|  | 395 | * | 
|  | 396 | * Returns: 0 if ok, < 0 errno code on error. | 
|  | 397 | * | 
| Inaky Perez-Gonzalez | e9a6b45 | 2009-05-08 13:02:41 -0700 | [diff] [blame] | 398 | * Releases all the resources allocated to communicate with the | 
|  | 399 | * device. Note we cannot destroy the workqueue earlier as until RX is | 
|  | 400 | * fully destroyed, it could still try to schedule jobs. | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 401 | */ | 
|  | 402 | static | 
|  | 403 | void __i2400m_dev_stop(struct i2400m *i2400m) | 
|  | 404 | { | 
|  | 405 | struct wimax_dev *wimax_dev = &i2400m->wimax_dev; | 
|  | 406 | struct device *dev = i2400m_dev(i2400m); | 
|  | 407 |  | 
|  | 408 | d_fnstart(3, dev, "(i2400m %p)\n", i2400m); | 
|  | 409 | wimax_state_change(wimax_dev, __WIMAX_ST_QUIESCING); | 
| Inaky Perez-Gonzalez | 5eeae35 | 2009-10-07 12:20:15 +0900 | [diff] [blame] | 410 | i2400m_msg_to_dev_cancel_wait(i2400m, -EL3RST); | 
|  | 411 | complete(&i2400m->msg_completion); | 
| Inaky Perez-Gonzalez | ac53aed | 2009-09-16 16:30:39 -0700 | [diff] [blame] | 412 | i2400m_net_wake_stop(i2400m); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 413 | i2400m_dev_shutdown(i2400m); | 
| Inaky Perez-Gonzalez | c2315b4 | 2009-09-16 17:10:55 -0700 | [diff] [blame] | 414 | /* | 
|  | 415 | * Make sure no report hooks are running *before* we stop the | 
|  | 416 | * communication infrastructure with the device. | 
|  | 417 | */ | 
|  | 418 | i2400m->ready = 0;	/* nobody can queue work anymore */ | 
|  | 419 | wmb();		/* see i2400m->ready's documentation  */ | 
|  | 420 | flush_workqueue(i2400m->work_queue); | 
|  | 421 |  | 
| Inaky Perez-Gonzalez | 097acbe | 2009-10-08 12:33:50 +0900 | [diff] [blame] | 422 | if (i2400m->bus_dev_stop) | 
|  | 423 | i2400m->bus_dev_stop(i2400m); | 
| Inaky Perez-Gonzalez | e9a6b45 | 2009-05-08 13:02:41 -0700 | [diff] [blame] | 424 | destroy_workqueue(i2400m->work_queue); | 
| Inaky Perez-Gonzalez | c747583 | 2009-02-28 23:42:54 +0000 | [diff] [blame] | 425 | i2400m_rx_release(i2400m); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 426 | i2400m_tx_release(i2400m); | 
|  | 427 | wimax_state_change(wimax_dev, WIMAX_ST_DOWN); | 
|  | 428 | d_fnend(3, dev, "(i2400m %p) = 0\n", i2400m); | 
|  | 429 | } | 
|  | 430 |  | 
|  | 431 |  | 
|  | 432 | /* | 
|  | 433 | * Watch out -- we only need to stop if there is a need for it. The | 
|  | 434 | * device could have reset itself and failed to come up again (see | 
|  | 435 | * _i2400m_dev_reset_handle()). | 
|  | 436 | */ | 
|  | 437 | static | 
|  | 438 | void i2400m_dev_stop(struct i2400m *i2400m) | 
|  | 439 | { | 
|  | 440 | mutex_lock(&i2400m->init_mutex); | 
|  | 441 | if (i2400m->updown) { | 
|  | 442 | __i2400m_dev_stop(i2400m); | 
|  | 443 | i2400m->updown = 0; | 
| Cindy H Kao | f4e4134 | 2010-04-07 19:42:42 -0700 | [diff] [blame] | 444 | i2400m->alive = 0; | 
|  | 445 | wmb();	/* see i2400m->updown and i2400m->alive's doc */ | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 446 | } | 
|  | 447 | mutex_unlock(&i2400m->init_mutex); | 
|  | 448 | } | 
|  | 449 |  | 
|  | 450 |  | 
|  | 451 | /* | 
| Inaky Perez-Gonzalez | 7b43ca7 | 2009-09-14 14:10:16 -0700 | [diff] [blame] | 452 | * Listen to PM events to cache the firmware before suspend/hibernation | 
|  | 453 | * | 
|  | 454 | * When the device comes out of suspend, it might go into reset and | 
|  | 455 | * firmware has to be uploaded again. At resume, most of the times, we | 
|  | 456 | * can't load firmware images from disk, so we need to cache it. | 
|  | 457 | * | 
|  | 458 | * i2400m_fw_cache() will allocate a kobject and attach the firmware | 
|  | 459 | * to it; that way we don't have to worry too much about the fw loader | 
|  | 460 | * hitting a race condition. | 
|  | 461 | * | 
|  | 462 | * Note: modus operandi stolen from the Orinoco driver; thx. | 
|  | 463 | */ | 
|  | 464 | static | 
|  | 465 | int i2400m_pm_notifier(struct notifier_block *notifier, | 
|  | 466 | unsigned long pm_event, | 
|  | 467 | void *unused) | 
|  | 468 | { | 
|  | 469 | struct i2400m *i2400m = | 
|  | 470 | container_of(notifier, struct i2400m, pm_notifier); | 
|  | 471 | struct device *dev = i2400m_dev(i2400m); | 
|  | 472 |  | 
|  | 473 | d_fnstart(3, dev, "(i2400m %p pm_event %lx)\n", i2400m, pm_event); | 
|  | 474 | switch (pm_event) { | 
|  | 475 | case PM_HIBERNATION_PREPARE: | 
|  | 476 | case PM_SUSPEND_PREPARE: | 
|  | 477 | i2400m_fw_cache(i2400m); | 
|  | 478 | break; | 
|  | 479 | case PM_POST_RESTORE: | 
|  | 480 | /* Restore from hibernation failed. We need to clean | 
|  | 481 | * up in exactly the same way, so fall through. */ | 
|  | 482 | case PM_POST_HIBERNATION: | 
|  | 483 | case PM_POST_SUSPEND: | 
|  | 484 | i2400m_fw_uncache(i2400m); | 
|  | 485 | break; | 
|  | 486 |  | 
|  | 487 | case PM_RESTORE_PREPARE: | 
|  | 488 | default: | 
|  | 489 | break; | 
|  | 490 | } | 
|  | 491 | d_fnend(3, dev, "(i2400m %p pm_event %lx) = void\n", i2400m, pm_event); | 
|  | 492 | return NOTIFY_DONE; | 
|  | 493 | } | 
|  | 494 |  | 
|  | 495 |  | 
|  | 496 | /* | 
| Inaky Perez-Gonzalez | 3725d8c | 2009-09-17 15:20:45 -0700 | [diff] [blame] | 497 | * pre-reset is called before a device is going on reset | 
|  | 498 | * | 
|  | 499 | * This has to be followed by a call to i2400m_post_reset(), otherwise | 
|  | 500 | * bad things might happen. | 
|  | 501 | */ | 
|  | 502 | int i2400m_pre_reset(struct i2400m *i2400m) | 
|  | 503 | { | 
|  | 504 | int result; | 
|  | 505 | struct device *dev = i2400m_dev(i2400m); | 
|  | 506 |  | 
|  | 507 | d_fnstart(3, dev, "(i2400m %p)\n", i2400m); | 
|  | 508 | d_printf(1, dev, "pre-reset shut down\n"); | 
|  | 509 |  | 
|  | 510 | result = 0; | 
|  | 511 | mutex_lock(&i2400m->init_mutex); | 
|  | 512 | if (i2400m->updown) { | 
|  | 513 | netif_tx_disable(i2400m->wimax_dev.net_dev); | 
|  | 514 | __i2400m_dev_stop(i2400m); | 
|  | 515 | result = 0; | 
|  | 516 | /* down't set updown to zero -- this way | 
|  | 517 | * post_reset can restore properly */ | 
|  | 518 | } | 
|  | 519 | mutex_unlock(&i2400m->init_mutex); | 
|  | 520 | if (i2400m->bus_release) | 
|  | 521 | i2400m->bus_release(i2400m); | 
|  | 522 | d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result); | 
|  | 523 | return result; | 
|  | 524 | } | 
|  | 525 | EXPORT_SYMBOL_GPL(i2400m_pre_reset); | 
|  | 526 |  | 
|  | 527 |  | 
|  | 528 | /* | 
|  | 529 | * Restore device state after a reset | 
|  | 530 | * | 
|  | 531 | * Do the work needed after a device reset to bring it up to the same | 
|  | 532 | * state as it was before the reset. | 
|  | 533 | * | 
|  | 534 | * NOTE: this requires i2400m->init_mutex taken | 
|  | 535 | */ | 
|  | 536 | int i2400m_post_reset(struct i2400m *i2400m) | 
|  | 537 | { | 
|  | 538 | int result = 0; | 
|  | 539 | struct device *dev = i2400m_dev(i2400m); | 
|  | 540 |  | 
|  | 541 | d_fnstart(3, dev, "(i2400m %p)\n", i2400m); | 
|  | 542 | d_printf(1, dev, "post-reset start\n"); | 
|  | 543 | if (i2400m->bus_setup) { | 
|  | 544 | result = i2400m->bus_setup(i2400m); | 
|  | 545 | if (result < 0) { | 
|  | 546 | dev_err(dev, "bus-specific setup failed: %d\n", | 
|  | 547 | result); | 
|  | 548 | goto error_bus_setup; | 
|  | 549 | } | 
|  | 550 | } | 
|  | 551 | mutex_lock(&i2400m->init_mutex); | 
|  | 552 | if (i2400m->updown) { | 
|  | 553 | result = __i2400m_dev_start( | 
|  | 554 | i2400m, I2400M_BRI_SOFT | I2400M_BRI_MAC_REINIT); | 
|  | 555 | if (result < 0) | 
|  | 556 | goto error_dev_start; | 
|  | 557 | } | 
|  | 558 | mutex_unlock(&i2400m->init_mutex); | 
|  | 559 | d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result); | 
|  | 560 | return result; | 
|  | 561 |  | 
|  | 562 | error_dev_start: | 
|  | 563 | if (i2400m->bus_release) | 
|  | 564 | i2400m->bus_release(i2400m); | 
| Inaky Perez-Gonzalez | 3725d8c | 2009-09-17 15:20:45 -0700 | [diff] [blame] | 565 | /* even if the device was up, it could not be recovered, so we | 
|  | 566 | * mark it as down. */ | 
|  | 567 | i2400m->updown = 0; | 
|  | 568 | wmb();		/* see i2400m->updown's documentation  */ | 
|  | 569 | mutex_unlock(&i2400m->init_mutex); | 
| Cindy H Kao | 2354161 | 2010-04-08 16:03:12 -0700 | [diff] [blame] | 570 | error_bus_setup: | 
| Inaky Perez-Gonzalez | 3725d8c | 2009-09-17 15:20:45 -0700 | [diff] [blame] | 571 | d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result); | 
|  | 572 | return result; | 
|  | 573 | } | 
|  | 574 | EXPORT_SYMBOL_GPL(i2400m_post_reset); | 
|  | 575 |  | 
|  | 576 |  | 
|  | 577 | /* | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 578 | * The device has rebooted; fix up the device and the driver | 
|  | 579 | * | 
|  | 580 | * Tear down the driver communication with the device, reload the | 
|  | 581 | * firmware and reinitialize the communication with the device. | 
|  | 582 | * | 
|  | 583 | * If someone calls a reset when the device's firmware is down, in | 
|  | 584 | * theory we won't see it because we are not listening. However, just | 
|  | 585 | * in case, leave the code to handle it. | 
|  | 586 | * | 
|  | 587 | * If there is a reset context, use it; this means someone is waiting | 
|  | 588 | * for us to tell him when the reset operation is complete and the | 
|  | 589 | * device is ready to rock again. | 
|  | 590 | * | 
|  | 591 | * NOTE: if we are in the process of bringing up or down the | 
|  | 592 | *       communication with the device [running i2400m_dev_start() or | 
|  | 593 | *       _stop()], don't do anything, let it fail and handle it. | 
|  | 594 | * | 
|  | 595 | * This function is ran always in a thread context | 
| Inaky Perez-Gonzalez | 3ef6129 | 2009-09-14 14:05:19 -0700 | [diff] [blame] | 596 | * | 
|  | 597 | * This function gets passed, as payload to i2400m_work() a 'const | 
|  | 598 | * char *' ptr with a "reason" why the reset happened (for messages). | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 599 | */ | 
|  | 600 | static | 
|  | 601 | void __i2400m_dev_reset_handle(struct work_struct *ws) | 
|  | 602 | { | 
| Tejun Heo | 781ba45 | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 603 | struct i2400m *i2400m = container_of(ws, struct i2400m, reset_ws); | 
|  | 604 | const char *reason = i2400m->reset_reason; | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 605 | struct device *dev = i2400m_dev(i2400m); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 606 | struct i2400m_reset_ctx *ctx = i2400m->reset_ctx; | 
| Tejun Heo | 781ba45 | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 607 | int result; | 
| Inaky Perez-Gonzalez | 3ef6129 | 2009-09-14 14:05:19 -0700 | [diff] [blame] | 608 |  | 
|  | 609 | d_fnstart(3, dev, "(ws %p i2400m %p reason %s)\n", ws, i2400m, reason); | 
|  | 610 |  | 
| Cindy H Kao | f4e4134 | 2010-04-07 19:42:42 -0700 | [diff] [blame] | 611 | i2400m->boot_mode = 1; | 
|  | 612 | wmb();		/* Make sure i2400m_msg_to_dev() sees boot_mode */ | 
|  | 613 |  | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 614 | result = 0; | 
|  | 615 | if (mutex_trylock(&i2400m->init_mutex) == 0) { | 
|  | 616 | /* We are still in i2400m_dev_start() [let it fail] or | 
|  | 617 | * i2400m_dev_stop() [we are shutting down anyway, so | 
|  | 618 | * ignore it] or we are resetting somewhere else. */ | 
| Inaky Perez-Gonzalez | c2315b4 | 2009-09-16 17:10:55 -0700 | [diff] [blame] | 619 | dev_err(dev, "device rebooted somewhere else?\n"); | 
| Cindy H Kao | 0bcfc5e | 2009-06-10 17:06:19 -0700 | [diff] [blame] | 620 | i2400m_msg_to_dev_cancel_wait(i2400m, -EL3RST); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 621 | complete(&i2400m->msg_completion); | 
|  | 622 | goto out; | 
|  | 623 | } | 
| Cindy H Kao | f4e4134 | 2010-04-07 19:42:42 -0700 | [diff] [blame] | 624 |  | 
| Inaky Perez-Gonzalez | 3ef6129 | 2009-09-14 14:05:19 -0700 | [diff] [blame] | 625 | dev_err(dev, "%s: reinitializing driver\n", reason); | 
| Cindy H Kao | f4e4134 | 2010-04-07 19:42:42 -0700 | [diff] [blame] | 626 | rmb(); | 
|  | 627 | if (i2400m->updown) { | 
|  | 628 | __i2400m_dev_stop(i2400m); | 
| Inaky Perez-Gonzalez | c2315b4 | 2009-09-16 17:10:55 -0700 | [diff] [blame] | 629 | i2400m->updown = 0; | 
|  | 630 | wmb();		/* see i2400m->updown's documentation  */ | 
| Inaky Perez-Gonzalez | c2315b4 | 2009-09-16 17:10:55 -0700 | [diff] [blame] | 631 | } | 
| Cindy H Kao | f4e4134 | 2010-04-07 19:42:42 -0700 | [diff] [blame] | 632 |  | 
|  | 633 | if (i2400m->alive) { | 
|  | 634 | result = __i2400m_dev_start(i2400m, | 
|  | 635 | I2400M_BRI_SOFT | I2400M_BRI_MAC_REINIT); | 
|  | 636 | if (result < 0) { | 
|  | 637 | dev_err(dev, "%s: cannot start the device: %d\n", | 
|  | 638 | reason, result); | 
|  | 639 | result = -EUCLEAN; | 
|  | 640 | if (atomic_read(&i2400m->bus_reset_retries) | 
|  | 641 | >= I2400M_BUS_RESET_RETRIES) { | 
|  | 642 | result = -ENODEV; | 
|  | 643 | dev_err(dev, "tried too many times to " | 
|  | 644 | "reset the device, giving up\n"); | 
|  | 645 | } | 
|  | 646 | } | 
|  | 647 | } | 
|  | 648 |  | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 649 | if (i2400m->reset_ctx) { | 
|  | 650 | ctx->result = result; | 
|  | 651 | complete(&ctx->completion); | 
|  | 652 | } | 
|  | 653 | mutex_unlock(&i2400m->init_mutex); | 
| Inaky Perez-Gonzalez | b9ee950 | 2009-10-07 12:34:13 +0900 | [diff] [blame] | 654 | if (result == -EUCLEAN) { | 
| Cindy H Kao | f4e4134 | 2010-04-07 19:42:42 -0700 | [diff] [blame] | 655 | /* | 
|  | 656 | * We come here because the reset during operational mode | 
| Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 657 | * wasn't successfully done and need to proceed to a bus | 
| Cindy H Kao | f4e4134 | 2010-04-07 19:42:42 -0700 | [diff] [blame] | 658 | * reset. For the dev_reset_handle() to be able to handle | 
|  | 659 | * the reset event later properly, we restore boot_mode back | 
|  | 660 | * to the state before previous reset. ie: just like we are | 
|  | 661 | * issuing the bus reset for the first time | 
|  | 662 | */ | 
|  | 663 | i2400m->boot_mode = 0; | 
|  | 664 | wmb(); | 
|  | 665 |  | 
|  | 666 | atomic_inc(&i2400m->bus_reset_retries); | 
| Inaky Perez-Gonzalez | b9ee950 | 2009-10-07 12:34:13 +0900 | [diff] [blame] | 667 | /* ops, need to clean up [w/ init_mutex not held] */ | 
| Inaky Perez-Gonzalez | c931cee | 2009-10-19 16:24:56 +0900 | [diff] [blame] | 668 | result = i2400m_reset(i2400m, I2400M_RT_BUS); | 
| Inaky Perez-Gonzalez | b9ee950 | 2009-10-07 12:34:13 +0900 | [diff] [blame] | 669 | if (result >= 0) | 
|  | 670 | result = -ENODEV; | 
| Cindy H Kao | f4e4134 | 2010-04-07 19:42:42 -0700 | [diff] [blame] | 671 | } else { | 
|  | 672 | rmb(); | 
|  | 673 | if (i2400m->alive) { | 
|  | 674 | /* great, we expect the device state up and | 
|  | 675 | * dev_start() actually brings the device state up */ | 
|  | 676 | i2400m->updown = 1; | 
|  | 677 | wmb(); | 
|  | 678 | atomic_set(&i2400m->bus_reset_retries, 0); | 
|  | 679 | } | 
| Inaky Perez-Gonzalez | b9ee950 | 2009-10-07 12:34:13 +0900 | [diff] [blame] | 680 | } | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 681 | out: | 
| Inaky Perez-Gonzalez | 3ef6129 | 2009-09-14 14:05:19 -0700 | [diff] [blame] | 682 | d_fnend(3, dev, "(ws %p i2400m %p reason %s) = void\n", | 
|  | 683 | ws, i2400m, reason); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 684 | } | 
|  | 685 |  | 
|  | 686 |  | 
|  | 687 | /** | 
|  | 688 | * i2400m_dev_reset_handle - Handle a device's reset in a thread context | 
|  | 689 | * | 
|  | 690 | * Schedule a device reset handling out on a thread context, so it | 
|  | 691 | * is safe to call from atomic context. We can't use the i2400m's | 
|  | 692 | * queue as we are going to destroy it and reinitialize it as part of | 
|  | 693 | * the driver bringup/bringup process. | 
|  | 694 | * | 
|  | 695 | * See __i2400m_dev_reset_handle() for details; that takes care of | 
|  | 696 | * reinitializing the driver to handle the reset, calling into the | 
|  | 697 | * bus-specific functions ops as needed. | 
|  | 698 | */ | 
| Inaky Perez-Gonzalez | 3ef6129 | 2009-09-14 14:05:19 -0700 | [diff] [blame] | 699 | int i2400m_dev_reset_handle(struct i2400m *i2400m, const char *reason) | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 700 | { | 
| Tejun Heo | 781ba45 | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 701 | i2400m->reset_reason = reason; | 
|  | 702 | return schedule_work(&i2400m->reset_ws); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 703 | } | 
|  | 704 | EXPORT_SYMBOL_GPL(i2400m_dev_reset_handle); | 
|  | 705 |  | 
|  | 706 |  | 
| Cindy H Kao | 599e595 | 2010-04-07 20:07:47 -0700 | [diff] [blame] | 707 | /* | 
|  | 708 | * The actual work of error recovery. | 
|  | 709 | * | 
|  | 710 | * The current implementation of error recovery is to trigger a bus reset. | 
|  | 711 | */ | 
|  | 712 | static | 
|  | 713 | void __i2400m_error_recovery(struct work_struct *ws) | 
|  | 714 | { | 
| Tejun Heo | 781ba45 | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 715 | struct i2400m *i2400m = container_of(ws, struct i2400m, recovery_ws); | 
| Cindy H Kao | 599e595 | 2010-04-07 20:07:47 -0700 | [diff] [blame] | 716 |  | 
|  | 717 | i2400m_reset(i2400m, I2400M_RT_BUS); | 
| Cindy H Kao | 599e595 | 2010-04-07 20:07:47 -0700 | [diff] [blame] | 718 | } | 
|  | 719 |  | 
|  | 720 | /* | 
|  | 721 | * Schedule a work struct for error recovery. | 
|  | 722 | * | 
|  | 723 | * The intention of error recovery is to bring back the device to some | 
|  | 724 | * known state whenever TX sees -110 (-ETIMEOUT) on copying the data to | 
|  | 725 | * the device. The TX failure could mean a device bus stuck, so the current | 
|  | 726 | * error recovery implementation is to trigger a bus reset to the device | 
|  | 727 | * and hopefully it can bring back the device. | 
|  | 728 | * | 
|  | 729 | * The actual work of error recovery has to be in a thread context because | 
|  | 730 | * it is kicked off in the TX thread (i2400ms->tx_workqueue) which is to be | 
|  | 731 | * destroyed by the error recovery mechanism (currently a bus reset). | 
|  | 732 | * | 
|  | 733 | * Also, there may be already a queue of TX works that all hit | 
|  | 734 | * the -ETIMEOUT error condition because the device is stuck already. | 
|  | 735 | * Since bus reset is used as the error recovery mechanism and we don't | 
|  | 736 | * want consecutive bus resets simply because the multiple TX works | 
|  | 737 | * in the queue all hit the same device erratum, the flag "error_recovery" | 
|  | 738 | * is introduced for preventing unwanted consecutive bus resets. | 
|  | 739 | * | 
|  | 740 | * Error recovery shall only be invoked again if previous one was completed. | 
|  | 741 | * The flag error_recovery is set when error recovery mechanism is scheduled, | 
|  | 742 | * and is checked when we need to schedule another error recovery. If it is | 
|  | 743 | * in place already, then we shouldn't schedule another one. | 
|  | 744 | */ | 
|  | 745 | void i2400m_error_recovery(struct i2400m *i2400m) | 
|  | 746 | { | 
| Tejun Heo | 781ba45 | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 747 | if (atomic_add_return(1, &i2400m->error_recovery) == 1) | 
|  | 748 | schedule_work(&i2400m->recovery_ws); | 
|  | 749 | else | 
| Cindy H Kao | 599e595 | 2010-04-07 20:07:47 -0700 | [diff] [blame] | 750 | atomic_dec(&i2400m->error_recovery); | 
| Cindy H Kao | 599e595 | 2010-04-07 20:07:47 -0700 | [diff] [blame] | 751 | } | 
|  | 752 | EXPORT_SYMBOL_GPL(i2400m_error_recovery); | 
|  | 753 |  | 
| Inaky Perez-Gonzalez | 2869da8 | 2009-09-16 18:33:26 -0700 | [diff] [blame] | 754 | /* | 
|  | 755 | * Alloc the command and ack buffers for boot mode | 
| Dirk Brandewie | a134fd6 | 2009-08-18 08:51:52 -0700 | [diff] [blame] | 756 | * | 
|  | 757 | * Get the buffers needed to deal with boot mode messages.  These | 
| Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 758 | * buffers need to be allocated before the sdio receive irq is setup. | 
| Dirk Brandewie | a134fd6 | 2009-08-18 08:51:52 -0700 | [diff] [blame] | 759 | */ | 
| Inaky Perez-Gonzalez | 2869da8 | 2009-09-16 18:33:26 -0700 | [diff] [blame] | 760 | static | 
| Dirk Brandewie | a134fd6 | 2009-08-18 08:51:52 -0700 | [diff] [blame] | 761 | int i2400m_bm_buf_alloc(struct i2400m *i2400m) | 
|  | 762 | { | 
|  | 763 | int result; | 
|  | 764 |  | 
|  | 765 | result = -ENOMEM; | 
|  | 766 | i2400m->bm_cmd_buf = kzalloc(I2400M_BM_CMD_BUF_SIZE, GFP_KERNEL); | 
|  | 767 | if (i2400m->bm_cmd_buf == NULL) | 
|  | 768 | goto error_bm_cmd_kzalloc; | 
|  | 769 | i2400m->bm_ack_buf = kzalloc(I2400M_BM_ACK_BUF_SIZE, GFP_KERNEL); | 
|  | 770 | if (i2400m->bm_ack_buf == NULL) | 
|  | 771 | goto error_bm_ack_buf_kzalloc; | 
|  | 772 | return 0; | 
|  | 773 |  | 
|  | 774 | error_bm_ack_buf_kzalloc: | 
|  | 775 | kfree(i2400m->bm_cmd_buf); | 
|  | 776 | error_bm_cmd_kzalloc: | 
|  | 777 | return result; | 
|  | 778 | } | 
| Dirk Brandewie | a134fd6 | 2009-08-18 08:51:52 -0700 | [diff] [blame] | 779 |  | 
| Inaky Perez-Gonzalez | 2869da8 | 2009-09-16 18:33:26 -0700 | [diff] [blame] | 780 |  | 
|  | 781 | /* | 
|  | 782 | * Free boot mode command and ack buffers. | 
| Dirk Brandewie | a134fd6 | 2009-08-18 08:51:52 -0700 | [diff] [blame] | 783 | */ | 
| Inaky Perez-Gonzalez | 2869da8 | 2009-09-16 18:33:26 -0700 | [diff] [blame] | 784 | static | 
| Dirk Brandewie | a134fd6 | 2009-08-18 08:51:52 -0700 | [diff] [blame] | 785 | void i2400m_bm_buf_free(struct i2400m *i2400m) | 
|  | 786 | { | 
|  | 787 | kfree(i2400m->bm_ack_buf); | 
|  | 788 | kfree(i2400m->bm_cmd_buf); | 
| Dirk Brandewie | a134fd6 | 2009-08-18 08:51:52 -0700 | [diff] [blame] | 789 | } | 
| Inaky Perez-Gonzalez | 2869da8 | 2009-09-16 18:33:26 -0700 | [diff] [blame] | 790 |  | 
|  | 791 |  | 
| Dirk Brandewie | a134fd6 | 2009-08-18 08:51:52 -0700 | [diff] [blame] | 792 | /** | 
| Inaky Perez-Gonzalez | af77dfa | 2009-10-07 21:37:53 +0900 | [diff] [blame] | 793 | * i2400m_init - Initialize a 'struct i2400m' from all zeroes | 
|  | 794 | * | 
|  | 795 | * This is a bus-generic API call. | 
|  | 796 | */ | 
|  | 797 | void i2400m_init(struct i2400m *i2400m) | 
|  | 798 | { | 
|  | 799 | wimax_dev_init(&i2400m->wimax_dev); | 
|  | 800 |  | 
|  | 801 | i2400m->boot_mode = 1; | 
|  | 802 | i2400m->rx_reorder = 1; | 
|  | 803 | init_waitqueue_head(&i2400m->state_wq); | 
|  | 804 |  | 
|  | 805 | spin_lock_init(&i2400m->tx_lock); | 
|  | 806 | i2400m->tx_pl_min = UINT_MAX; | 
|  | 807 | i2400m->tx_size_min = UINT_MAX; | 
|  | 808 |  | 
|  | 809 | spin_lock_init(&i2400m->rx_lock); | 
|  | 810 | i2400m->rx_pl_min = UINT_MAX; | 
|  | 811 | i2400m->rx_size_min = UINT_MAX; | 
| Inaky Perez-Gonzalez | a0beba2 | 2009-10-07 21:43:10 +0900 | [diff] [blame] | 812 | INIT_LIST_HEAD(&i2400m->rx_reports); | 
|  | 813 | INIT_WORK(&i2400m->rx_report_ws, i2400m_report_hook_work); | 
| Inaky Perez-Gonzalez | af77dfa | 2009-10-07 21:37:53 +0900 | [diff] [blame] | 814 |  | 
|  | 815 | mutex_init(&i2400m->msg_mutex); | 
|  | 816 | init_completion(&i2400m->msg_completion); | 
|  | 817 |  | 
|  | 818 | mutex_init(&i2400m->init_mutex); | 
|  | 819 | /* wake_tx_ws is initialized in i2400m_tx_setup() */ | 
| Tejun Heo | 781ba45 | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 820 |  | 
|  | 821 | INIT_WORK(&i2400m->reset_ws, __i2400m_dev_reset_handle); | 
|  | 822 | INIT_WORK(&i2400m->recovery_ws, __i2400m_error_recovery); | 
|  | 823 |  | 
| Cindy H Kao | f4e4134 | 2010-04-07 19:42:42 -0700 | [diff] [blame] | 824 | atomic_set(&i2400m->bus_reset_retries, 0); | 
|  | 825 |  | 
|  | 826 | i2400m->alive = 0; | 
| Cindy H Kao | 599e595 | 2010-04-07 20:07:47 -0700 | [diff] [blame] | 827 |  | 
|  | 828 | /* initialize error_recovery to 1 for denoting we | 
|  | 829 | * are not yet ready to take any error recovery */ | 
|  | 830 | atomic_set(&i2400m->error_recovery, 1); | 
| Inaky Perez-Gonzalez | af77dfa | 2009-10-07 21:37:53 +0900 | [diff] [blame] | 831 | } | 
|  | 832 | EXPORT_SYMBOL_GPL(i2400m_init); | 
|  | 833 |  | 
|  | 834 |  | 
| Inaky Perez-Gonzalez | c931cee | 2009-10-19 16:24:56 +0900 | [diff] [blame] | 835 | int i2400m_reset(struct i2400m *i2400m, enum i2400m_reset_type rt) | 
|  | 836 | { | 
|  | 837 | struct net_device *net_dev = i2400m->wimax_dev.net_dev; | 
|  | 838 |  | 
|  | 839 | /* | 
|  | 840 | * Make sure we stop TXs and down the carrier before | 
|  | 841 | * resetting; this is needed to avoid things like | 
|  | 842 | * i2400m_wake_tx() scheduling stuff in parallel. | 
|  | 843 | */ | 
|  | 844 | if (net_dev->reg_state == NETREG_REGISTERED) { | 
|  | 845 | netif_tx_disable(net_dev); | 
|  | 846 | netif_carrier_off(net_dev); | 
|  | 847 | } | 
|  | 848 | return i2400m->bus_reset(i2400m, rt); | 
|  | 849 | } | 
|  | 850 | EXPORT_SYMBOL_GPL(i2400m_reset); | 
|  | 851 |  | 
|  | 852 |  | 
| Inaky Perez-Gonzalez | af77dfa | 2009-10-07 21:37:53 +0900 | [diff] [blame] | 853 | /** | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 854 | * i2400m_setup - bus-generic setup function for the i2400m device | 
|  | 855 | * | 
|  | 856 | * @i2400m: device descriptor (bus-specific parts have been initialized) | 
|  | 857 | * | 
|  | 858 | * Returns: 0 if ok, < 0 errno code on error. | 
|  | 859 | * | 
| Inaky Perez-Gonzalez | 8f90f3e | 2009-09-16 17:53:57 -0700 | [diff] [blame] | 860 | * Sets up basic device comunication infrastructure, boots the ROM to | 
|  | 861 | * read the MAC address, registers with the WiMAX and network stacks | 
|  | 862 | * and then brings up the device. | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 863 | */ | 
|  | 864 | int i2400m_setup(struct i2400m *i2400m, enum i2400m_bri bm_flags) | 
|  | 865 | { | 
|  | 866 | int result = -ENODEV; | 
|  | 867 | struct device *dev = i2400m_dev(i2400m); | 
|  | 868 | struct wimax_dev *wimax_dev = &i2400m->wimax_dev; | 
|  | 869 | struct net_device *net_dev = i2400m->wimax_dev.net_dev; | 
|  | 870 |  | 
|  | 871 | d_fnstart(3, dev, "(i2400m %p)\n", i2400m); | 
|  | 872 |  | 
|  | 873 | snprintf(wimax_dev->name, sizeof(wimax_dev->name), | 
| Kay Sievers | 347707b | 2009-02-28 23:42:51 +0000 | [diff] [blame] | 874 | "i2400m-%s:%s", dev->bus->name, dev_name(dev)); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 875 |  | 
| Inaky Perez-Gonzalez | 2869da8 | 2009-09-16 18:33:26 -0700 | [diff] [blame] | 876 | result = i2400m_bm_buf_alloc(i2400m); | 
|  | 877 | if (result < 0) { | 
|  | 878 | dev_err(dev, "cannot allocate bootmode scratch buffers\n"); | 
|  | 879 | goto error_bm_buf_alloc; | 
|  | 880 | } | 
|  | 881 |  | 
| Inaky Perez-Gonzalez | 0856ccf | 2009-09-16 18:23:27 -0700 | [diff] [blame] | 882 | if (i2400m->bus_setup) { | 
|  | 883 | result = i2400m->bus_setup(i2400m); | 
|  | 884 | if (result < 0) { | 
|  | 885 | dev_err(dev, "bus-specific setup failed: %d\n", | 
|  | 886 | result); | 
|  | 887 | goto error_bus_setup; | 
|  | 888 | } | 
|  | 889 | } | 
|  | 890 |  | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 891 | result = i2400m_bootrom_init(i2400m, bm_flags); | 
|  | 892 | if (result < 0) { | 
|  | 893 | dev_err(dev, "read mac addr: bootrom init " | 
|  | 894 | "failed: %d\n", result); | 
|  | 895 | goto error_bootrom_init; | 
|  | 896 | } | 
|  | 897 | result = i2400m_read_mac_addr(i2400m); | 
|  | 898 | if (result < 0) | 
|  | 899 | goto error_read_mac_addr; | 
| Inaky Perez-Gonzalez | fe44268 | 2009-04-22 16:53:08 -0700 | [diff] [blame] | 900 | random_ether_addr(i2400m->src_mac_addr); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 901 |  | 
| Inaky Perez-Gonzalez | 7b43ca7 | 2009-09-14 14:10:16 -0700 | [diff] [blame] | 902 | i2400m->pm_notifier.notifier_call = i2400m_pm_notifier; | 
|  | 903 | register_pm_notifier(&i2400m->pm_notifier); | 
|  | 904 |  | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 905 | result = register_netdev(net_dev);	/* Okey dokey, bring it up */ | 
|  | 906 | if (result < 0) { | 
|  | 907 | dev_err(dev, "cannot register i2400m network device: %d\n", | 
|  | 908 | result); | 
|  | 909 | goto error_register_netdev; | 
|  | 910 | } | 
|  | 911 | netif_carrier_off(net_dev); | 
|  | 912 |  | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 913 | i2400m->wimax_dev.op_msg_from_user = i2400m_op_msg_from_user; | 
|  | 914 | i2400m->wimax_dev.op_rfkill_sw_toggle = i2400m_op_rfkill_sw_toggle; | 
|  | 915 | i2400m->wimax_dev.op_reset = i2400m_op_reset; | 
| Inaky Perez-Gonzalez | 8f90f3e | 2009-09-16 17:53:57 -0700 | [diff] [blame] | 916 |  | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 917 | result = wimax_dev_add(&i2400m->wimax_dev, net_dev); | 
|  | 918 | if (result < 0) | 
|  | 919 | goto error_wimax_dev_add; | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 920 |  | 
|  | 921 | /* Now setup all that requires a registered net and wimax device. */ | 
| Inaky Perez-Gonzalez | 8987691 | 2009-02-28 23:42:50 +0000 | [diff] [blame] | 922 | result = sysfs_create_group(&net_dev->dev.kobj, &i2400m_dev_attr_group); | 
|  | 923 | if (result < 0) { | 
|  | 924 | dev_err(dev, "cannot setup i2400m's sysfs: %d\n", result); | 
|  | 925 | goto error_sysfs_setup; | 
|  | 926 | } | 
| Inaky Perez-Gonzalez | 8f90f3e | 2009-09-16 17:53:57 -0700 | [diff] [blame] | 927 |  | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 928 | result = i2400m_debugfs_add(i2400m); | 
|  | 929 | if (result < 0) { | 
|  | 930 | dev_err(dev, "cannot setup i2400m's debugfs: %d\n", result); | 
|  | 931 | goto error_debugfs_setup; | 
|  | 932 | } | 
| Inaky Perez-Gonzalez | 8f90f3e | 2009-09-16 17:53:57 -0700 | [diff] [blame] | 933 |  | 
|  | 934 | result = i2400m_dev_start(i2400m, bm_flags); | 
|  | 935 | if (result < 0) | 
|  | 936 | goto error_dev_start; | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 937 | d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result); | 
|  | 938 | return result; | 
|  | 939 |  | 
| Inaky Perez-Gonzalez | 8f90f3e | 2009-09-16 17:53:57 -0700 | [diff] [blame] | 940 | error_dev_start: | 
|  | 941 | i2400m_debugfs_rm(i2400m); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 942 | error_debugfs_setup: | 
| Inaky Perez-Gonzalez | 8987691 | 2009-02-28 23:42:50 +0000 | [diff] [blame] | 943 | sysfs_remove_group(&i2400m->wimax_dev.net_dev->dev.kobj, | 
|  | 944 | &i2400m_dev_attr_group); | 
|  | 945 | error_sysfs_setup: | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 946 | wimax_dev_rm(&i2400m->wimax_dev); | 
|  | 947 | error_wimax_dev_add: | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 948 | unregister_netdev(net_dev); | 
|  | 949 | error_register_netdev: | 
| Inaky Perez-Gonzalez | 7b43ca7 | 2009-09-14 14:10:16 -0700 | [diff] [blame] | 950 | unregister_pm_notifier(&i2400m->pm_notifier); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 951 | error_read_mac_addr: | 
|  | 952 | error_bootrom_init: | 
| Inaky Perez-Gonzalez | 0856ccf | 2009-09-16 18:23:27 -0700 | [diff] [blame] | 953 | if (i2400m->bus_release) | 
|  | 954 | i2400m->bus_release(i2400m); | 
|  | 955 | error_bus_setup: | 
| Inaky Perez-Gonzalez | 2869da8 | 2009-09-16 18:33:26 -0700 | [diff] [blame] | 956 | i2400m_bm_buf_free(i2400m); | 
|  | 957 | error_bm_buf_alloc: | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 958 | d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result); | 
|  | 959 | return result; | 
|  | 960 | } | 
|  | 961 | EXPORT_SYMBOL_GPL(i2400m_setup); | 
|  | 962 |  | 
|  | 963 |  | 
|  | 964 | /** | 
|  | 965 | * i2400m_release - release the bus-generic driver resources | 
|  | 966 | * | 
|  | 967 | * Sends a disconnect message and undoes any setup done by i2400m_setup() | 
|  | 968 | */ | 
|  | 969 | void i2400m_release(struct i2400m *i2400m) | 
|  | 970 | { | 
|  | 971 | struct device *dev = i2400m_dev(i2400m); | 
|  | 972 |  | 
|  | 973 | d_fnstart(3, dev, "(i2400m %p)\n", i2400m); | 
|  | 974 | netif_stop_queue(i2400m->wimax_dev.net_dev); | 
|  | 975 |  | 
| Inaky Perez-Gonzalez | 8f90f3e | 2009-09-16 17:53:57 -0700 | [diff] [blame] | 976 | i2400m_dev_stop(i2400m); | 
|  | 977 |  | 
| Tejun Heo | 781ba45 | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 978 | cancel_work_sync(&i2400m->reset_ws); | 
|  | 979 | cancel_work_sync(&i2400m->recovery_ws); | 
|  | 980 |  | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 981 | i2400m_debugfs_rm(i2400m); | 
| Inaky Perez-Gonzalez | 8987691 | 2009-02-28 23:42:50 +0000 | [diff] [blame] | 982 | sysfs_remove_group(&i2400m->wimax_dev.net_dev->dev.kobj, | 
|  | 983 | &i2400m_dev_attr_group); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 984 | wimax_dev_rm(&i2400m->wimax_dev); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 985 | unregister_netdev(i2400m->wimax_dev.net_dev); | 
| Inaky Perez-Gonzalez | 7b43ca7 | 2009-09-14 14:10:16 -0700 | [diff] [blame] | 986 | unregister_pm_notifier(&i2400m->pm_notifier); | 
| Inaky Perez-Gonzalez | 0856ccf | 2009-09-16 18:23:27 -0700 | [diff] [blame] | 987 | if (i2400m->bus_release) | 
|  | 988 | i2400m->bus_release(i2400m); | 
| Inaky Perez-Gonzalez | 8f90f3e | 2009-09-16 17:53:57 -0700 | [diff] [blame] | 989 | i2400m_bm_buf_free(i2400m); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 990 | d_fnend(3, dev, "(i2400m %p) = void\n", i2400m); | 
|  | 991 | } | 
|  | 992 | EXPORT_SYMBOL_GPL(i2400m_release); | 
|  | 993 |  | 
|  | 994 |  | 
| Inaky Perez-Gonzalez | 1af7ad5 | 2009-01-29 17:18:31 -0800 | [diff] [blame] | 995 | /* | 
|  | 996 | * Debug levels control; see debug.h | 
|  | 997 | */ | 
|  | 998 | struct d_level D_LEVEL[] = { | 
|  | 999 | D_SUBMODULE_DEFINE(control), | 
|  | 1000 | D_SUBMODULE_DEFINE(driver), | 
|  | 1001 | D_SUBMODULE_DEFINE(debugfs), | 
|  | 1002 | D_SUBMODULE_DEFINE(fw), | 
|  | 1003 | D_SUBMODULE_DEFINE(netdev), | 
|  | 1004 | D_SUBMODULE_DEFINE(rfkill), | 
|  | 1005 | D_SUBMODULE_DEFINE(rx), | 
| Inaky Perez-Gonzalez | 4dc1bf0 | 2009-09-02 15:31:48 -0700 | [diff] [blame] | 1006 | D_SUBMODULE_DEFINE(sysfs), | 
| Inaky Perez-Gonzalez | 1af7ad5 | 2009-01-29 17:18:31 -0800 | [diff] [blame] | 1007 | D_SUBMODULE_DEFINE(tx), | 
|  | 1008 | }; | 
|  | 1009 | size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL); | 
|  | 1010 |  | 
|  | 1011 |  | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 1012 | static | 
|  | 1013 | int __init i2400m_driver_init(void) | 
|  | 1014 | { | 
| Inaky Perez-Gonzalez | 4c2b1a1 | 2009-09-02 15:36:05 -0700 | [diff] [blame] | 1015 | d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400m_debug_params, | 
|  | 1016 | "i2400m.debug"); | 
| Inaky Perez-Gonzalez | aba3792 | 2009-09-03 15:14:29 -0700 | [diff] [blame] | 1017 | return i2400m_barker_db_init(i2400m_barkers_params); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 1018 | } | 
|  | 1019 | module_init(i2400m_driver_init); | 
|  | 1020 |  | 
|  | 1021 | static | 
|  | 1022 | void __exit i2400m_driver_exit(void) | 
|  | 1023 | { | 
| Inaky Perez-Gonzalez | aba3792 | 2009-09-03 15:14:29 -0700 | [diff] [blame] | 1024 | i2400m_barker_db_exit(); | 
| Inaky Perez-Gonzalez | 024f7f3 | 2008-12-20 16:57:44 -0800 | [diff] [blame] | 1025 | } | 
|  | 1026 | module_exit(i2400m_driver_exit); | 
|  | 1027 |  | 
|  | 1028 | MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>"); | 
|  | 1029 | MODULE_DESCRIPTION("Intel 2400M WiMAX networking bus-generic driver"); | 
|  | 1030 | MODULE_LICENSE("GPL"); |