blob: 10673af5a7f0f0f0b951ba635f474878e8023bf5 [file] [log] [blame]
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001/*
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-Gonzalez0856ccf2009-09-16 18:23:27 -070044 * i2400m->bus_setup()
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -080045 * i2400m_bootrom_init()
46 * register_netdev()
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -070047 * wimax_dev_add()
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -080048 * i2400m_dev_start()
49 * __i2400m_dev_start()
50 * i2400m_dev_bootstrap()
51 * i2400m_tx_setup()
52 * i2400m->bus_dev_start()
Inaky Perez-Gonzalez6a0f7ab2009-02-28 23:42:49 +000053 * i2400m_firmware_check()
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -080054 * i2400m_check_mac_addr()
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -080055 *
56 * i2400m_release()
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -080057 * i2400m_dev_stop()
58 * __i2400m_dev_stop()
59 * i2400m_dev_shutdown()
60 * i2400m->bus_dev_stop()
61 * i2400m_tx_release()
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -070062 * i2400m->bus_release()
63 * wimax_dev_rm()
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -080064 * unregister_netdev()
65 */
66#include "i2400m.h"
Inaky Perez-Gonzalezfe442682009-04-22 16:53:08 -070067#include <linux/etherdevice.h>
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -080068#include <linux/wimax/i2400m.h>
69#include <linux/module.h>
70#include <linux/moduleparam.h>
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -070071#include <linux/suspend.h>
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -080072
73#define D_SUBMODULE driver
74#include "debug-levels.h"
75
76
77int i2400m_idle_mode_disabled; /* 0 (idle mode enabled) by default */
78module_param_named(idle_mode_disabled, i2400m_idle_mode_disabled, int, 0644);
79MODULE_PARM_DESC(idle_mode_disabled,
80 "If true, the device will not enable idle mode negotiation "
81 "with the base station (when connected) to save power.");
82
Inaky Perez-Gonzalezc7475832009-02-28 23:42:54 +000083int i2400m_rx_reorder_disabled; /* 0 (rx reorder enabled) by default */
84module_param_named(rx_reorder_disabled, i2400m_rx_reorder_disabled, int, 0644);
85MODULE_PARM_DESC(rx_reorder_disabled,
86 "If true, RX reordering will be disabled.");
87
Inaky Perez-Gonzalezfb101672009-05-07 10:27:42 -070088int i2400m_power_save_disabled; /* 0 (power saving enabled) by default */
89module_param_named(power_save_disabled, i2400m_power_save_disabled, int, 0644);
90MODULE_PARM_DESC(power_save_disabled,
91 "If true, the driver will not tell the device to enter "
92 "power saving mode when it reports it is ready for it. "
93 "False by default (so the device is told to do power "
94 "saving).");
95
Inaky Perez-Gonzalez4c2b1a12009-09-02 15:36:05 -070096static char i2400m_debug_params[128];
97module_param_string(debug, i2400m_debug_params, sizeof(i2400m_debug_params),
98 0644);
99MODULE_PARM_DESC(debug,
100 "String of space-separated NAME:VALUE pairs, where NAMEs "
101 "are the different debug submodules and VALUE are the "
102 "initial debug value to set.");
103
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -0700104static char i2400m_barkers_params[128];
105module_param_string(barkers, i2400m_barkers_params,
106 sizeof(i2400m_barkers_params), 0644);
107MODULE_PARM_DESC(barkers,
108 "String of comma-separated 32-bit values; each is "
109 "recognized as the value the device sends as a reboot "
110 "signal; values are appended to a list--setting one value "
111 "as zero cleans the existing list and starts a new one.");
112
Inaky Perez-Gonzalezb0fbcb22009-09-14 13:29:32 -0700113static
114struct i2400m_work *__i2400m_work_setup(
115 struct i2400m *i2400m, void (*fn)(struct work_struct *),
116 gfp_t gfp_flags, const void *pl, size_t pl_size)
117{
118 struct i2400m_work *iw;
119
120 iw = kzalloc(sizeof(*iw) + pl_size, gfp_flags);
121 if (iw == NULL)
122 return NULL;
123 iw->i2400m = i2400m_get(i2400m);
124 iw->pl_size = pl_size;
125 memcpy(iw->pl, pl, pl_size);
126 INIT_WORK(&iw->ws, fn);
127 return iw;
128}
129
130
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800131/**
132 * i2400m_queue_work - schedule work on a i2400m's queue
133 *
134 * @i2400m: device descriptor
135 *
136 * @fn: function to run to execute work. It gets passed a 'struct
137 * work_struct' that is wrapped in a 'struct i2400m_work'. Once
138 * done, you have to (1) i2400m_put(i2400m_work->i2400m) and then
139 * (2) kfree(i2400m_work).
140 *
141 * @gfp_flags: GFP flags for memory allocation.
142 *
143 * @pl: pointer to a payload buffer that you want to pass to the _work
144 * function. Use this to pack (for example) a struct with extra
145 * arguments.
146 *
147 * @pl_size: size of the payload buffer.
148 *
149 * We do this quite often, so this just saves typing; allocate a
150 * wrapper for a i2400m, get a ref to it, pack arguments and launch
151 * the work.
152 *
153 * A usual workflow is:
154 *
155 * struct my_work_args {
156 * void *something;
157 * int whatever;
158 * };
159 * ...
160 *
161 * struct my_work_args my_args = {
162 * .something = FOO,
163 * .whaetever = BLAH
164 * };
165 * i2400m_queue_work(i2400m, 1, my_work_function, GFP_KERNEL,
166 * &args, sizeof(args))
167 *
168 * And now the work function can unpack the arguments and call the
169 * real function (or do the job itself):
170 *
171 * static
172 * void my_work_fn((struct work_struct *ws)
173 * {
174 * struct i2400m_work *iw =
175 * container_of(ws, struct i2400m_work, ws);
176 * struct my_work_args *my_args = (void *) iw->pl;
177 *
178 * my_work(iw->i2400m, my_args->something, my_args->whatevert);
179 * }
180 */
181int i2400m_queue_work(struct i2400m *i2400m,
182 void (*fn)(struct work_struct *), gfp_t gfp_flags,
183 const void *pl, size_t pl_size)
184{
185 int result;
186 struct i2400m_work *iw;
187
188 BUG_ON(i2400m->work_queue == NULL);
189 result = -ENOMEM;
Inaky Perez-Gonzalezb0fbcb22009-09-14 13:29:32 -0700190 iw = __i2400m_work_setup(i2400m, fn, gfp_flags, pl, pl_size);
191 if (iw != NULL) {
192 result = queue_work(i2400m->work_queue, &iw->ws);
193 if (WARN_ON(result == 0))
194 result = -ENXIO;
195 }
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800196 return result;
197}
198EXPORT_SYMBOL_GPL(i2400m_queue_work);
199
200
201/*
202 * Schedule i2400m's specific work on the system's queue.
203 *
204 * Used for a few cases where we really need it; otherwise, identical
205 * to i2400m_queue_work().
206 *
207 * Returns < 0 errno code on error, 1 if ok.
208 *
209 * If it returns zero, something really bad happened, as it means the
210 * works struct was already queued, but we have just allocated it, so
211 * it should not happen.
212 */
213int i2400m_schedule_work(struct i2400m *i2400m,
Inaky Perez-Gonzalezb0fbcb22009-09-14 13:29:32 -0700214 void (*fn)(struct work_struct *), gfp_t gfp_flags,
215 const void *pl, size_t pl_size)
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800216{
217 int result;
218 struct i2400m_work *iw;
219
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800220 result = -ENOMEM;
Inaky Perez-Gonzalezb0fbcb22009-09-14 13:29:32 -0700221 iw = __i2400m_work_setup(i2400m, fn, gfp_flags, pl, pl_size);
222 if (iw != NULL) {
223 result = schedule_work(&iw->ws);
224 if (WARN_ON(result == 0))
225 result = -ENXIO;
226 }
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800227 return result;
228}
229
230
231/*
232 * WiMAX stack operation: relay a message from user space
233 *
234 * @wimax_dev: device descriptor
235 * @pipe_name: named pipe the message is for
236 * @msg_buf: pointer to the message bytes
237 * @msg_len: length of the buffer
238 * @genl_info: passed by the generic netlink layer
239 *
240 * The WiMAX stack will call this function when a message was received
241 * from user space.
242 *
243 * For the i2400m, this is an L3L4 message, as specified in
244 * include/linux/wimax/i2400m.h, and thus prefixed with a 'struct
245 * i2400m_l3l4_hdr'. Driver (and device) expect the messages to be
246 * coded in Little Endian.
247 *
248 * This function just verifies that the header declaration and the
249 * payload are consistent and then deals with it, either forwarding it
250 * to the device or procesing it locally.
251 *
252 * In the i2400m, messages are basically commands that will carry an
253 * ack, so we use i2400m_msg_to_dev() and then deliver the ack back to
254 * user space. The rx.c code might intercept the response and use it
255 * to update the driver's state, but then it will pass it on so it can
256 * be relayed back to user space.
257 *
258 * Note that asynchronous events from the device are processed and
259 * sent to user space in rx.c.
260 */
261static
262int i2400m_op_msg_from_user(struct wimax_dev *wimax_dev,
263 const char *pipe_name,
264 const void *msg_buf, size_t msg_len,
265 const struct genl_info *genl_info)
266{
267 int result;
268 struct i2400m *i2400m = wimax_dev_to_i2400m(wimax_dev);
269 struct device *dev = i2400m_dev(i2400m);
270 struct sk_buff *ack_skb;
271
272 d_fnstart(4, dev, "(wimax_dev %p [i2400m %p] msg_buf %p "
273 "msg_len %zu genl_info %p)\n", wimax_dev, i2400m,
274 msg_buf, msg_len, genl_info);
275 ack_skb = i2400m_msg_to_dev(i2400m, msg_buf, msg_len);
276 result = PTR_ERR(ack_skb);
277 if (IS_ERR(ack_skb))
278 goto error_msg_to_dev;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800279 result = wimax_msg_send(&i2400m->wimax_dev, ack_skb);
280error_msg_to_dev:
281 d_fnend(4, dev, "(wimax_dev %p [i2400m %p] msg_buf %p msg_len %zu "
282 "genl_info %p) = %d\n", wimax_dev, i2400m, msg_buf, msg_len,
283 genl_info, result);
284 return result;
285}
286
287
288/*
289 * Context to wait for a reset to finalize
290 */
291struct i2400m_reset_ctx {
292 struct completion completion;
293 int result;
294};
295
296
297/*
298 * WiMAX stack operation: reset a device
299 *
300 * @wimax_dev: device descriptor
301 *
302 * See the documentation for wimax_reset() and wimax_dev->op_reset for
303 * the requirements of this function. The WiMAX stack guarantees
304 * serialization on calls to this function.
305 *
306 * Do a warm reset on the device; if it fails, resort to a cold reset
307 * and return -ENODEV. On successful warm reset, we need to block
308 * until it is complete.
309 *
310 * The bus-driver implementation of reset takes care of falling back
311 * to cold reset if warm fails.
312 */
313static
314int i2400m_op_reset(struct wimax_dev *wimax_dev)
315{
316 int result;
317 struct i2400m *i2400m = wimax_dev_to_i2400m(wimax_dev);
318 struct device *dev = i2400m_dev(i2400m);
319 struct i2400m_reset_ctx ctx = {
320 .completion = COMPLETION_INITIALIZER_ONSTACK(ctx.completion),
321 .result = 0,
322 };
323
324 d_fnstart(4, dev, "(wimax_dev %p)\n", wimax_dev);
325 mutex_lock(&i2400m->init_mutex);
326 i2400m->reset_ctx = &ctx;
327 mutex_unlock(&i2400m->init_mutex);
328 result = i2400m->bus_reset(i2400m, I2400M_RT_WARM);
329 if (result < 0)
330 goto out;
331 result = wait_for_completion_timeout(&ctx.completion, 4*HZ);
332 if (result == 0)
333 result = -ETIMEDOUT;
334 else if (result > 0)
335 result = ctx.result;
336 /* if result < 0, pass it on */
337 mutex_lock(&i2400m->init_mutex);
338 i2400m->reset_ctx = NULL;
339 mutex_unlock(&i2400m->init_mutex);
340out:
341 d_fnend(4, dev, "(wimax_dev %p) = %d\n", wimax_dev, result);
342 return result;
343}
344
345
346/*
347 * Check the MAC address we got from boot mode is ok
348 *
349 * @i2400m: device descriptor
350 *
351 * Returns: 0 if ok, < 0 errno code on error.
352 */
353static
354int i2400m_check_mac_addr(struct i2400m *i2400m)
355{
356 int result;
357 struct device *dev = i2400m_dev(i2400m);
358 struct sk_buff *skb;
359 const struct i2400m_tlv_detailed_device_info *ddi;
360 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
361 const unsigned char zeromac[ETH_ALEN] = { 0 };
362
363 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
364 skb = i2400m_get_device_info(i2400m);
365 if (IS_ERR(skb)) {
366 result = PTR_ERR(skb);
367 dev_err(dev, "Cannot verify MAC address, error reading: %d\n",
368 result);
369 goto error;
370 }
371 /* Extract MAC addresss */
372 ddi = (void *) skb->data;
373 BUILD_BUG_ON(ETH_ALEN != sizeof(ddi->mac_address));
374 d_printf(2, dev, "GET DEVICE INFO: mac addr "
375 "%02x:%02x:%02x:%02x:%02x:%02x\n",
376 ddi->mac_address[0], ddi->mac_address[1],
377 ddi->mac_address[2], ddi->mac_address[3],
378 ddi->mac_address[4], ddi->mac_address[5]);
379 if (!memcmp(net_dev->perm_addr, ddi->mac_address,
380 sizeof(ddi->mac_address)))
381 goto ok;
382 dev_warn(dev, "warning: device reports a different MAC address "
383 "to that of boot mode's\n");
384 dev_warn(dev, "device reports %02x:%02x:%02x:%02x:%02x:%02x\n",
385 ddi->mac_address[0], ddi->mac_address[1],
386 ddi->mac_address[2], ddi->mac_address[3],
387 ddi->mac_address[4], ddi->mac_address[5]);
388 dev_warn(dev, "boot mode reported %02x:%02x:%02x:%02x:%02x:%02x\n",
389 net_dev->perm_addr[0], net_dev->perm_addr[1],
390 net_dev->perm_addr[2], net_dev->perm_addr[3],
391 net_dev->perm_addr[4], net_dev->perm_addr[5]);
392 if (!memcmp(zeromac, ddi->mac_address, sizeof(zeromac)))
393 dev_err(dev, "device reports an invalid MAC address, "
394 "not updating\n");
395 else {
396 dev_warn(dev, "updating MAC address\n");
397 net_dev->addr_len = ETH_ALEN;
398 memcpy(net_dev->perm_addr, ddi->mac_address, ETH_ALEN);
399 memcpy(net_dev->dev_addr, ddi->mac_address, ETH_ALEN);
400 }
401ok:
402 result = 0;
403 kfree_skb(skb);
404error:
405 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
406 return result;
407}
408
409
410/**
411 * __i2400m_dev_start - Bring up driver communication with the device
412 *
413 * @i2400m: device descriptor
414 * @flags: boot mode flags
415 *
416 * Returns: 0 if ok, < 0 errno code on error.
417 *
418 * Uploads firmware and brings up all the resources needed to be able
419 * to communicate with the device.
420 *
Inaky Perez-Gonzaleze9a6b452009-05-08 13:02:41 -0700421 * The workqueue has to be setup early, at least before RX handling
422 * (it's only real user for now) so it can process reports as they
423 * arrive. We also want to destroy it if we retry, to make sure it is
424 * flushed...easier like this.
425 *
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800426 * TX needs to be setup before the bus-specific code (otherwise on
427 * shutdown, the bus-tx code could try to access it).
428 */
429static
430int __i2400m_dev_start(struct i2400m *i2400m, enum i2400m_bri flags)
431{
432 int result;
433 struct wimax_dev *wimax_dev = &i2400m->wimax_dev;
434 struct net_device *net_dev = wimax_dev->net_dev;
435 struct device *dev = i2400m_dev(i2400m);
Inaky Perez-Gonzalezecddfd52009-06-03 16:13:14 +0800436 int times = i2400m->bus_bm_retries;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800437
438 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
439retry:
440 result = i2400m_dev_bootstrap(i2400m, flags);
441 if (result < 0) {
442 dev_err(dev, "cannot bootstrap device: %d\n", result);
443 goto error_bootstrap;
444 }
445 result = i2400m_tx_setup(i2400m);
446 if (result < 0)
447 goto error_tx_setup;
Inaky Perez-Gonzalezc7475832009-02-28 23:42:54 +0000448 result = i2400m_rx_setup(i2400m);
449 if (result < 0)
450 goto error_rx_setup;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800451 i2400m->work_queue = create_singlethread_workqueue(wimax_dev->name);
452 if (i2400m->work_queue == NULL) {
453 result = -ENOMEM;
454 dev_err(dev, "cannot create workqueue\n");
455 goto error_create_workqueue;
456 }
Inaky Perez-Gonzaleze9a6b452009-05-08 13:02:41 -0700457 result = i2400m->bus_dev_start(i2400m);
458 if (result < 0)
459 goto error_bus_dev_start;
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700460 i2400m->ready = 1;
461 wmb(); /* see i2400m->ready's documentation */
Inaky Perez-Gonzalez6a0f7ab2009-02-28 23:42:49 +0000462 result = i2400m_firmware_check(i2400m); /* fw versions ok? */
463 if (result < 0)
464 goto error_fw_check;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800465 /* At this point is ok to send commands to the device */
466 result = i2400m_check_mac_addr(i2400m);
467 if (result < 0)
468 goto error_check_mac_addr;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800469 wimax_state_change(wimax_dev, WIMAX_ST_UNINITIALIZED);
470 result = i2400m_dev_initialize(i2400m);
471 if (result < 0)
472 goto error_dev_initialize;
473 /* At this point, reports will come for the device and set it
474 * to the right state if it is different than UNINITIALIZED */
475 d_fnend(3, dev, "(net_dev %p [i2400m %p]) = %d\n",
476 net_dev, i2400m, result);
477 return result;
478
479error_dev_initialize:
480error_check_mac_addr:
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700481 i2400m->ready = 0;
482 wmb(); /* see i2400m->ready's documentation */
483 flush_workqueue(i2400m->work_queue);
Inaky Perez-Gonzalez6a0f7ab2009-02-28 23:42:49 +0000484error_fw_check:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800485 i2400m->bus_dev_stop(i2400m);
486error_bus_dev_start:
Inaky Perez-Gonzaleze9a6b452009-05-08 13:02:41 -0700487 destroy_workqueue(i2400m->work_queue);
488error_create_workqueue:
Inaky Perez-Gonzalezc7475832009-02-28 23:42:54 +0000489 i2400m_rx_release(i2400m);
490error_rx_setup:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800491 i2400m_tx_release(i2400m);
492error_tx_setup:
493error_bootstrap:
Cindy H Kao0bcfc5e2009-06-10 17:06:19 -0700494 if (result == -EL3RST && times-- > 0) {
Cindy H Kao8b5b30e2009-06-10 16:52:10 -0700495 flags = I2400M_BRI_SOFT|I2400M_BRI_MAC_REINIT;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800496 goto retry;
497 }
498 d_fnend(3, dev, "(net_dev %p [i2400m %p]) = %d\n",
499 net_dev, i2400m, result);
500 return result;
501}
502
503
504static
505int i2400m_dev_start(struct i2400m *i2400m, enum i2400m_bri bm_flags)
506{
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700507 int result = 0;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800508 mutex_lock(&i2400m->init_mutex); /* Well, start the device */
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700509 if (i2400m->updown == 0) {
510 result = __i2400m_dev_start(i2400m, bm_flags);
511 if (result >= 0) {
512 i2400m->updown = 1;
513 wmb(); /* see i2400m->updown's documentation */
514 }
515 }
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800516 mutex_unlock(&i2400m->init_mutex);
517 return result;
518}
519
520
521/**
522 * i2400m_dev_stop - Tear down driver communication with the device
523 *
524 * @i2400m: device descriptor
525 *
526 * Returns: 0 if ok, < 0 errno code on error.
527 *
Inaky Perez-Gonzaleze9a6b452009-05-08 13:02:41 -0700528 * Releases all the resources allocated to communicate with the
529 * device. Note we cannot destroy the workqueue earlier as until RX is
530 * fully destroyed, it could still try to schedule jobs.
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800531 */
532static
533void __i2400m_dev_stop(struct i2400m *i2400m)
534{
535 struct wimax_dev *wimax_dev = &i2400m->wimax_dev;
536 struct device *dev = i2400m_dev(i2400m);
537
538 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
539 wimax_state_change(wimax_dev, __WIMAX_ST_QUIESCING);
Inaky Perez-Gonzalez5eeae352009-10-07 12:20:15 +0900540 i2400m_msg_to_dev_cancel_wait(i2400m, -EL3RST);
541 complete(&i2400m->msg_completion);
Inaky Perez-Gonzalezac53aed2009-09-16 16:30:39 -0700542 i2400m_net_wake_stop(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800543 i2400m_dev_shutdown(i2400m);
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700544 /*
545 * Make sure no report hooks are running *before* we stop the
546 * communication infrastructure with the device.
547 */
548 i2400m->ready = 0; /* nobody can queue work anymore */
549 wmb(); /* see i2400m->ready's documentation */
550 flush_workqueue(i2400m->work_queue);
551
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800552 i2400m->bus_dev_stop(i2400m);
Inaky Perez-Gonzaleze9a6b452009-05-08 13:02:41 -0700553 destroy_workqueue(i2400m->work_queue);
Inaky Perez-Gonzalezc7475832009-02-28 23:42:54 +0000554 i2400m_rx_release(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800555 i2400m_tx_release(i2400m);
556 wimax_state_change(wimax_dev, WIMAX_ST_DOWN);
557 d_fnend(3, dev, "(i2400m %p) = 0\n", i2400m);
558}
559
560
561/*
562 * Watch out -- we only need to stop if there is a need for it. The
563 * device could have reset itself and failed to come up again (see
564 * _i2400m_dev_reset_handle()).
565 */
566static
567void i2400m_dev_stop(struct i2400m *i2400m)
568{
569 mutex_lock(&i2400m->init_mutex);
570 if (i2400m->updown) {
571 __i2400m_dev_stop(i2400m);
572 i2400m->updown = 0;
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700573 wmb(); /* see i2400m->updown's documentation */
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800574 }
575 mutex_unlock(&i2400m->init_mutex);
576}
577
578
579/*
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -0700580 * Listen to PM events to cache the firmware before suspend/hibernation
581 *
582 * When the device comes out of suspend, it might go into reset and
583 * firmware has to be uploaded again. At resume, most of the times, we
584 * can't load firmware images from disk, so we need to cache it.
585 *
586 * i2400m_fw_cache() will allocate a kobject and attach the firmware
587 * to it; that way we don't have to worry too much about the fw loader
588 * hitting a race condition.
589 *
590 * Note: modus operandi stolen from the Orinoco driver; thx.
591 */
592static
593int i2400m_pm_notifier(struct notifier_block *notifier,
594 unsigned long pm_event,
595 void *unused)
596{
597 struct i2400m *i2400m =
598 container_of(notifier, struct i2400m, pm_notifier);
599 struct device *dev = i2400m_dev(i2400m);
600
601 d_fnstart(3, dev, "(i2400m %p pm_event %lx)\n", i2400m, pm_event);
602 switch (pm_event) {
603 case PM_HIBERNATION_PREPARE:
604 case PM_SUSPEND_PREPARE:
605 i2400m_fw_cache(i2400m);
606 break;
607 case PM_POST_RESTORE:
608 /* Restore from hibernation failed. We need to clean
609 * up in exactly the same way, so fall through. */
610 case PM_POST_HIBERNATION:
611 case PM_POST_SUSPEND:
612 i2400m_fw_uncache(i2400m);
613 break;
614
615 case PM_RESTORE_PREPARE:
616 default:
617 break;
618 }
619 d_fnend(3, dev, "(i2400m %p pm_event %lx) = void\n", i2400m, pm_event);
620 return NOTIFY_DONE;
621}
622
623
624/*
Inaky Perez-Gonzalez3725d8c2009-09-17 15:20:45 -0700625 * pre-reset is called before a device is going on reset
626 *
627 * This has to be followed by a call to i2400m_post_reset(), otherwise
628 * bad things might happen.
629 */
630int i2400m_pre_reset(struct i2400m *i2400m)
631{
632 int result;
633 struct device *dev = i2400m_dev(i2400m);
634
635 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
636 d_printf(1, dev, "pre-reset shut down\n");
637
638 result = 0;
639 mutex_lock(&i2400m->init_mutex);
640 if (i2400m->updown) {
641 netif_tx_disable(i2400m->wimax_dev.net_dev);
642 __i2400m_dev_stop(i2400m);
643 result = 0;
644 /* down't set updown to zero -- this way
645 * post_reset can restore properly */
646 }
647 mutex_unlock(&i2400m->init_mutex);
648 if (i2400m->bus_release)
649 i2400m->bus_release(i2400m);
650 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
651 return result;
652}
653EXPORT_SYMBOL_GPL(i2400m_pre_reset);
654
655
656/*
657 * Restore device state after a reset
658 *
659 * Do the work needed after a device reset to bring it up to the same
660 * state as it was before the reset.
661 *
662 * NOTE: this requires i2400m->init_mutex taken
663 */
664int i2400m_post_reset(struct i2400m *i2400m)
665{
666 int result = 0;
667 struct device *dev = i2400m_dev(i2400m);
668
669 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
670 d_printf(1, dev, "post-reset start\n");
671 if (i2400m->bus_setup) {
672 result = i2400m->bus_setup(i2400m);
673 if (result < 0) {
674 dev_err(dev, "bus-specific setup failed: %d\n",
675 result);
676 goto error_bus_setup;
677 }
678 }
679 mutex_lock(&i2400m->init_mutex);
680 if (i2400m->updown) {
681 result = __i2400m_dev_start(
682 i2400m, I2400M_BRI_SOFT | I2400M_BRI_MAC_REINIT);
683 if (result < 0)
684 goto error_dev_start;
685 }
686 mutex_unlock(&i2400m->init_mutex);
687 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
688 return result;
689
690error_dev_start:
691 if (i2400m->bus_release)
692 i2400m->bus_release(i2400m);
693error_bus_setup:
694 /* even if the device was up, it could not be recovered, so we
695 * mark it as down. */
696 i2400m->updown = 0;
697 wmb(); /* see i2400m->updown's documentation */
698 mutex_unlock(&i2400m->init_mutex);
699 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
700 return result;
701}
702EXPORT_SYMBOL_GPL(i2400m_post_reset);
703
704
705/*
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800706 * The device has rebooted; fix up the device and the driver
707 *
708 * Tear down the driver communication with the device, reload the
709 * firmware and reinitialize the communication with the device.
710 *
711 * If someone calls a reset when the device's firmware is down, in
712 * theory we won't see it because we are not listening. However, just
713 * in case, leave the code to handle it.
714 *
715 * If there is a reset context, use it; this means someone is waiting
716 * for us to tell him when the reset operation is complete and the
717 * device is ready to rock again.
718 *
719 * NOTE: if we are in the process of bringing up or down the
720 * communication with the device [running i2400m_dev_start() or
721 * _stop()], don't do anything, let it fail and handle it.
722 *
723 * This function is ran always in a thread context
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700724 *
725 * This function gets passed, as payload to i2400m_work() a 'const
726 * char *' ptr with a "reason" why the reset happened (for messages).
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800727 */
728static
729void __i2400m_dev_reset_handle(struct work_struct *ws)
730{
731 int result;
732 struct i2400m_work *iw = container_of(ws, struct i2400m_work, ws);
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700733 const char *reason;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800734 struct i2400m *i2400m = iw->i2400m;
735 struct device *dev = i2400m_dev(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800736 struct i2400m_reset_ctx *ctx = i2400m->reset_ctx;
737
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700738 if (WARN_ON(iw->pl_size != sizeof(reason)))
739 reason = "SW BUG: reason n/a";
740 else
741 memcpy(&reason, iw->pl, sizeof(reason));
742
743 d_fnstart(3, dev, "(ws %p i2400m %p reason %s)\n", ws, i2400m, reason);
744
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800745 result = 0;
746 if (mutex_trylock(&i2400m->init_mutex) == 0) {
747 /* We are still in i2400m_dev_start() [let it fail] or
748 * i2400m_dev_stop() [we are shutting down anyway, so
749 * ignore it] or we are resetting somewhere else. */
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700750 dev_err(dev, "device rebooted somewhere else?\n");
Cindy H Kao0bcfc5e2009-06-10 17:06:19 -0700751 i2400m_msg_to_dev_cancel_wait(i2400m, -EL3RST);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800752 complete(&i2400m->msg_completion);
753 goto out;
754 }
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700755 if (i2400m->updown == 0) {
756 dev_info(dev, "%s: device is down, doing nothing\n", reason);
757 goto out_unlock;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800758 }
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700759 dev_err(dev, "%s: reinitializing driver\n", reason);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800760 __i2400m_dev_stop(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800761 result = __i2400m_dev_start(i2400m,
762 I2400M_BRI_SOFT | I2400M_BRI_MAC_REINIT);
763 if (result < 0) {
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700764 i2400m->updown = 0;
765 wmb(); /* see i2400m->updown's documentation */
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700766 dev_err(dev, "%s: cannot start the device: %d\n",
767 reason, result);
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900768 result = -EUCLEAN;
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700769 }
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800770out_unlock:
771 if (i2400m->reset_ctx) {
772 ctx->result = result;
773 complete(&ctx->completion);
774 }
775 mutex_unlock(&i2400m->init_mutex);
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900776 if (result == -EUCLEAN) {
777 /* ops, need to clean up [w/ init_mutex not held] */
778 result = i2400m->bus_reset(i2400m, I2400M_RT_BUS);
779 if (result >= 0)
780 result = -ENODEV;
781 }
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800782out:
783 i2400m_put(i2400m);
784 kfree(iw);
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700785 d_fnend(3, dev, "(ws %p i2400m %p reason %s) = void\n",
786 ws, i2400m, reason);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800787 return;
788}
789
790
791/**
792 * i2400m_dev_reset_handle - Handle a device's reset in a thread context
793 *
794 * Schedule a device reset handling out on a thread context, so it
795 * is safe to call from atomic context. We can't use the i2400m's
796 * queue as we are going to destroy it and reinitialize it as part of
797 * the driver bringup/bringup process.
798 *
799 * See __i2400m_dev_reset_handle() for details; that takes care of
800 * reinitializing the driver to handle the reset, calling into the
801 * bus-specific functions ops as needed.
802 */
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700803int i2400m_dev_reset_handle(struct i2400m *i2400m, const char *reason)
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800804{
Inaky Perez-Gonzalezb4013f92009-06-03 09:45:55 +0800805 i2400m->boot_mode = 1;
806 wmb(); /* Make sure i2400m_msg_to_dev() sees boot_mode */
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800807 return i2400m_schedule_work(i2400m, __i2400m_dev_reset_handle,
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700808 GFP_ATOMIC, &reason, sizeof(reason));
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800809}
810EXPORT_SYMBOL_GPL(i2400m_dev_reset_handle);
811
812
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700813/*
814 * Alloc the command and ack buffers for boot mode
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700815 *
816 * Get the buffers needed to deal with boot mode messages. These
817 * buffers need to be allocated before the sdio recieve irq is setup.
818 */
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700819static
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700820int i2400m_bm_buf_alloc(struct i2400m *i2400m)
821{
822 int result;
823
824 result = -ENOMEM;
825 i2400m->bm_cmd_buf = kzalloc(I2400M_BM_CMD_BUF_SIZE, GFP_KERNEL);
826 if (i2400m->bm_cmd_buf == NULL)
827 goto error_bm_cmd_kzalloc;
828 i2400m->bm_ack_buf = kzalloc(I2400M_BM_ACK_BUF_SIZE, GFP_KERNEL);
829 if (i2400m->bm_ack_buf == NULL)
830 goto error_bm_ack_buf_kzalloc;
831 return 0;
832
833error_bm_ack_buf_kzalloc:
834 kfree(i2400m->bm_cmd_buf);
835error_bm_cmd_kzalloc:
836 return result;
837}
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700838
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700839
840/*
841 * Free boot mode command and ack buffers.
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700842 */
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700843static
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700844void i2400m_bm_buf_free(struct i2400m *i2400m)
845{
846 kfree(i2400m->bm_ack_buf);
847 kfree(i2400m->bm_cmd_buf);
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700848}
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700849
850
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700851/**
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800852 * i2400m_setup - bus-generic setup function for the i2400m device
853 *
854 * @i2400m: device descriptor (bus-specific parts have been initialized)
855 *
856 * Returns: 0 if ok, < 0 errno code on error.
857 *
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700858 * Sets up basic device comunication infrastructure, boots the ROM to
859 * read the MAC address, registers with the WiMAX and network stacks
860 * and then brings up the device.
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800861 */
862int i2400m_setup(struct i2400m *i2400m, enum i2400m_bri bm_flags)
863{
864 int result = -ENODEV;
865 struct device *dev = i2400m_dev(i2400m);
866 struct wimax_dev *wimax_dev = &i2400m->wimax_dev;
867 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
868
869 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
870
871 snprintf(wimax_dev->name, sizeof(wimax_dev->name),
Kay Sievers347707b2009-02-28 23:42:51 +0000872 "i2400m-%s:%s", dev->bus->name, dev_name(dev));
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800873
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700874 result = i2400m_bm_buf_alloc(i2400m);
875 if (result < 0) {
876 dev_err(dev, "cannot allocate bootmode scratch buffers\n");
877 goto error_bm_buf_alloc;
878 }
879
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700880 if (i2400m->bus_setup) {
881 result = i2400m->bus_setup(i2400m);
882 if (result < 0) {
883 dev_err(dev, "bus-specific setup failed: %d\n",
884 result);
885 goto error_bus_setup;
886 }
887 }
888
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800889 result = i2400m_bootrom_init(i2400m, bm_flags);
890 if (result < 0) {
891 dev_err(dev, "read mac addr: bootrom init "
892 "failed: %d\n", result);
893 goto error_bootrom_init;
894 }
895 result = i2400m_read_mac_addr(i2400m);
896 if (result < 0)
897 goto error_read_mac_addr;
Inaky Perez-Gonzalezfe442682009-04-22 16:53:08 -0700898 random_ether_addr(i2400m->src_mac_addr);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800899
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -0700900 i2400m->pm_notifier.notifier_call = i2400m_pm_notifier;
901 register_pm_notifier(&i2400m->pm_notifier);
902
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800903 result = register_netdev(net_dev); /* Okey dokey, bring it up */
904 if (result < 0) {
905 dev_err(dev, "cannot register i2400m network device: %d\n",
906 result);
907 goto error_register_netdev;
908 }
909 netif_carrier_off(net_dev);
910
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800911 i2400m->wimax_dev.op_msg_from_user = i2400m_op_msg_from_user;
912 i2400m->wimax_dev.op_rfkill_sw_toggle = i2400m_op_rfkill_sw_toggle;
913 i2400m->wimax_dev.op_reset = i2400m_op_reset;
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700914
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800915 result = wimax_dev_add(&i2400m->wimax_dev, net_dev);
916 if (result < 0)
917 goto error_wimax_dev_add;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800918
919 /* Now setup all that requires a registered net and wimax device. */
Inaky Perez-Gonzalez89876912009-02-28 23:42:50 +0000920 result = sysfs_create_group(&net_dev->dev.kobj, &i2400m_dev_attr_group);
921 if (result < 0) {
922 dev_err(dev, "cannot setup i2400m's sysfs: %d\n", result);
923 goto error_sysfs_setup;
924 }
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700925
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800926 result = i2400m_debugfs_add(i2400m);
927 if (result < 0) {
928 dev_err(dev, "cannot setup i2400m's debugfs: %d\n", result);
929 goto error_debugfs_setup;
930 }
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700931
932 result = i2400m_dev_start(i2400m, bm_flags);
933 if (result < 0)
934 goto error_dev_start;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800935 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
936 return result;
937
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700938error_dev_start:
939 i2400m_debugfs_rm(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800940error_debugfs_setup:
Inaky Perez-Gonzalez89876912009-02-28 23:42:50 +0000941 sysfs_remove_group(&i2400m->wimax_dev.net_dev->dev.kobj,
942 &i2400m_dev_attr_group);
943error_sysfs_setup:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800944 wimax_dev_rm(&i2400m->wimax_dev);
945error_wimax_dev_add:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800946 unregister_netdev(net_dev);
947error_register_netdev:
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -0700948 unregister_pm_notifier(&i2400m->pm_notifier);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800949error_read_mac_addr:
950error_bootrom_init:
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700951 if (i2400m->bus_release)
952 i2400m->bus_release(i2400m);
953error_bus_setup:
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700954 i2400m_bm_buf_free(i2400m);
955error_bm_buf_alloc:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800956 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
957 return result;
958}
959EXPORT_SYMBOL_GPL(i2400m_setup);
960
961
962/**
963 * i2400m_release - release the bus-generic driver resources
964 *
965 * Sends a disconnect message and undoes any setup done by i2400m_setup()
966 */
967void i2400m_release(struct i2400m *i2400m)
968{
969 struct device *dev = i2400m_dev(i2400m);
970
971 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
972 netif_stop_queue(i2400m->wimax_dev.net_dev);
973
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700974 i2400m_dev_stop(i2400m);
975
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800976 i2400m_debugfs_rm(i2400m);
Inaky Perez-Gonzalez89876912009-02-28 23:42:50 +0000977 sysfs_remove_group(&i2400m->wimax_dev.net_dev->dev.kobj,
978 &i2400m_dev_attr_group);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800979 wimax_dev_rm(&i2400m->wimax_dev);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800980 unregister_netdev(i2400m->wimax_dev.net_dev);
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -0700981 unregister_pm_notifier(&i2400m->pm_notifier);
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700982 if (i2400m->bus_release)
983 i2400m->bus_release(i2400m);
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700984 i2400m_bm_buf_free(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800985 d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
986}
987EXPORT_SYMBOL_GPL(i2400m_release);
988
989
Inaky Perez-Gonzalez1af7ad52009-01-29 17:18:31 -0800990/*
991 * Debug levels control; see debug.h
992 */
993struct d_level D_LEVEL[] = {
994 D_SUBMODULE_DEFINE(control),
995 D_SUBMODULE_DEFINE(driver),
996 D_SUBMODULE_DEFINE(debugfs),
997 D_SUBMODULE_DEFINE(fw),
998 D_SUBMODULE_DEFINE(netdev),
999 D_SUBMODULE_DEFINE(rfkill),
1000 D_SUBMODULE_DEFINE(rx),
Inaky Perez-Gonzalez4dc1bf02009-09-02 15:31:48 -07001001 D_SUBMODULE_DEFINE(sysfs),
Inaky Perez-Gonzalez1af7ad52009-01-29 17:18:31 -08001002 D_SUBMODULE_DEFINE(tx),
1003};
1004size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL);
1005
1006
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001007static
1008int __init i2400m_driver_init(void)
1009{
Inaky Perez-Gonzalez4c2b1a12009-09-02 15:36:05 -07001010 d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400m_debug_params,
1011 "i2400m.debug");
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -07001012 return i2400m_barker_db_init(i2400m_barkers_params);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001013}
1014module_init(i2400m_driver_init);
1015
1016static
1017void __exit i2400m_driver_exit(void)
1018{
1019 /* for scheds i2400m_dev_reset_handle() */
1020 flush_scheduled_work();
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -07001021 i2400m_barker_db_exit();
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001022 return;
1023}
1024module_exit(i2400m_driver_exit);
1025
1026MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>");
1027MODULE_DESCRIPTION("Intel 2400M WiMAX networking bus-generic driver");
1028MODULE_LICENSE("GPL");