2 * Intel Wireless WiMAX Connection 2400m
3 * Generic probe/disconnect, reset and message passing
6 * Copyright (C) 2007-2008 Intel Corporation <linux-wimax@intel.com>
7 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
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.
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.
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
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()].
31 * i2400m_op_msg_from_user()
33 * wimax_msg_to_user_send()
38 * i2400m_dev_reset_handle()
39 * __i2400m_dev_reset_handle()
41 * __i2400m_dev_start()
45 * i2400m_bootrom_init()
49 * __i2400m_dev_start()
50 * i2400m_dev_bootstrap()
52 * i2400m->bus_dev_start()
53 * i2400m_firmware_check()
54 * i2400m_check_mac_addr()
59 * i2400m_dev_shutdown()
60 * i2400m->bus_dev_stop()
62 * i2400m->bus_release()
67 #include <linux/etherdevice.h>
68 #include <linux/wimax/i2400m.h>
69 #include <linux/module.h>
70 #include <linux/moduleparam.h>
71 #include <linux/suspend.h>
72 #include <linux/slab.h>
74 #define D_SUBMODULE driver
75 #include "debug-levels.h"
78 int i2400m_idle_mode_disabled; /* 0 (idle mode enabled) by default */
79 module_param_named(idle_mode_disabled, i2400m_idle_mode_disabled, int, 0644);
80 MODULE_PARM_DESC(idle_mode_disabled,
81 "If true, the device will not enable idle mode negotiation "
82 "with the base station (when connected) to save power.");
84 int i2400m_rx_reorder_disabled; /* 0 (rx reorder enabled) by default */
85 module_param_named(rx_reorder_disabled, i2400m_rx_reorder_disabled, int, 0644);
86 MODULE_PARM_DESC(rx_reorder_disabled,
87 "If true, RX reordering will be disabled.");
89 int i2400m_power_save_disabled; /* 0 (power saving enabled) by default */
90 module_param_named(power_save_disabled, i2400m_power_save_disabled, int, 0644);
91 MODULE_PARM_DESC(power_save_disabled,
92 "If true, the driver will not tell the device to enter "
93 "power saving mode when it reports it is ready for it. "
94 "False by default (so the device is told to do power "
97 static char i2400m_debug_params[128];
98 module_param_string(debug, i2400m_debug_params, sizeof(i2400m_debug_params),
100 MODULE_PARM_DESC(debug,
101 "String of space-separated NAME:VALUE pairs, where NAMEs "
102 "are the different debug submodules and VALUE are the "
103 "initial debug value to set.");
105 static char i2400m_barkers_params[128];
106 module_param_string(barkers, i2400m_barkers_params,
107 sizeof(i2400m_barkers_params), 0644);
108 MODULE_PARM_DESC(barkers,
109 "String of comma-separated 32-bit values; each is "
110 "recognized as the value the device sends as a reboot "
111 "signal; values are appended to a list--setting one value "
112 "as zero cleans the existing list and starts a new one.");
115 struct i2400m_work *__i2400m_work_setup(
116 struct i2400m *i2400m, void (*fn)(struct work_struct *),
117 gfp_t gfp_flags, const void *pl, size_t pl_size)
119 struct i2400m_work *iw;
121 iw = kzalloc(sizeof(*iw) + pl_size, gfp_flags);
124 iw->i2400m = i2400m_get(i2400m);
125 iw->pl_size = pl_size;
126 memcpy(iw->pl, pl, pl_size);
127 INIT_WORK(&iw->ws, fn);
133 * Schedule i2400m's specific work on the system's queue.
135 * Used for a few cases where we really need it; otherwise, identical
136 * to i2400m_queue_work().
138 * Returns < 0 errno code on error, 1 if ok.
140 * If it returns zero, something really bad happened, as it means the
141 * works struct was already queued, but we have just allocated it, so
142 * it should not happen.
144 int i2400m_schedule_work(struct i2400m *i2400m,
145 void (*fn)(struct work_struct *), gfp_t gfp_flags,
146 const void *pl, size_t pl_size)
149 struct i2400m_work *iw;
152 iw = __i2400m_work_setup(i2400m, fn, gfp_flags, pl, pl_size);
154 result = schedule_work(&iw->ws);
155 if (WARN_ON(result == 0))
163 * WiMAX stack operation: relay a message from user space
165 * @wimax_dev: device descriptor
166 * @pipe_name: named pipe the message is for
167 * @msg_buf: pointer to the message bytes
168 * @msg_len: length of the buffer
169 * @genl_info: passed by the generic netlink layer
171 * The WiMAX stack will call this function when a message was received
174 * For the i2400m, this is an L3L4 message, as specified in
175 * include/linux/wimax/i2400m.h, and thus prefixed with a 'struct
176 * i2400m_l3l4_hdr'. Driver (and device) expect the messages to be
177 * coded in Little Endian.
179 * This function just verifies that the header declaration and the
180 * payload are consistent and then deals with it, either forwarding it
181 * to the device or procesing it locally.
183 * In the i2400m, messages are basically commands that will carry an
184 * ack, so we use i2400m_msg_to_dev() and then deliver the ack back to
185 * user space. The rx.c code might intercept the response and use it
186 * to update the driver's state, but then it will pass it on so it can
187 * be relayed back to user space.
189 * Note that asynchronous events from the device are processed and
190 * sent to user space in rx.c.
193 int i2400m_op_msg_from_user(struct wimax_dev *wimax_dev,
194 const char *pipe_name,
195 const void *msg_buf, size_t msg_len,
196 const struct genl_info *genl_info)
199 struct i2400m *i2400m = wimax_dev_to_i2400m(wimax_dev);
200 struct device *dev = i2400m_dev(i2400m);
201 struct sk_buff *ack_skb;
203 d_fnstart(4, dev, "(wimax_dev %p [i2400m %p] msg_buf %p "
204 "msg_len %zu genl_info %p)\n", wimax_dev, i2400m,
205 msg_buf, msg_len, genl_info);
206 ack_skb = i2400m_msg_to_dev(i2400m, msg_buf, msg_len);
207 result = PTR_ERR(ack_skb);
209 goto error_msg_to_dev;
210 result = wimax_msg_send(&i2400m->wimax_dev, ack_skb);
212 d_fnend(4, dev, "(wimax_dev %p [i2400m %p] msg_buf %p msg_len %zu "
213 "genl_info %p) = %d\n", wimax_dev, i2400m, msg_buf, msg_len,
220 * Context to wait for a reset to finalize
222 struct i2400m_reset_ctx {
223 struct completion completion;
229 * WiMAX stack operation: reset a device
231 * @wimax_dev: device descriptor
233 * See the documentation for wimax_reset() and wimax_dev->op_reset for
234 * the requirements of this function. The WiMAX stack guarantees
235 * serialization on calls to this function.
237 * Do a warm reset on the device; if it fails, resort to a cold reset
238 * and return -ENODEV. On successful warm reset, we need to block
239 * until it is complete.
241 * The bus-driver implementation of reset takes care of falling back
242 * to cold reset if warm fails.
245 int i2400m_op_reset(struct wimax_dev *wimax_dev)
248 struct i2400m *i2400m = wimax_dev_to_i2400m(wimax_dev);
249 struct device *dev = i2400m_dev(i2400m);
250 struct i2400m_reset_ctx ctx = {
251 .completion = COMPLETION_INITIALIZER_ONSTACK(ctx.completion),
255 d_fnstart(4, dev, "(wimax_dev %p)\n", wimax_dev);
256 mutex_lock(&i2400m->init_mutex);
257 i2400m->reset_ctx = &ctx;
258 mutex_unlock(&i2400m->init_mutex);
259 result = i2400m_reset(i2400m, I2400M_RT_WARM);
262 result = wait_for_completion_timeout(&ctx.completion, 4*HZ);
267 /* if result < 0, pass it on */
268 mutex_lock(&i2400m->init_mutex);
269 i2400m->reset_ctx = NULL;
270 mutex_unlock(&i2400m->init_mutex);
272 d_fnend(4, dev, "(wimax_dev %p) = %d\n", wimax_dev, result);
278 * Check the MAC address we got from boot mode is ok
280 * @i2400m: device descriptor
282 * Returns: 0 if ok, < 0 errno code on error.
285 int i2400m_check_mac_addr(struct i2400m *i2400m)
288 struct device *dev = i2400m_dev(i2400m);
290 const struct i2400m_tlv_detailed_device_info *ddi;
291 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
292 const unsigned char zeromac[ETH_ALEN] = { 0 };
294 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
295 skb = i2400m_get_device_info(i2400m);
297 result = PTR_ERR(skb);
298 dev_err(dev, "Cannot verify MAC address, error reading: %d\n",
302 /* Extract MAC addresss */
303 ddi = (void *) skb->data;
304 BUILD_BUG_ON(ETH_ALEN != sizeof(ddi->mac_address));
305 d_printf(2, dev, "GET DEVICE INFO: mac addr %pM\n",
307 if (!memcmp(net_dev->perm_addr, ddi->mac_address,
308 sizeof(ddi->mac_address)))
310 dev_warn(dev, "warning: device reports a different MAC address "
311 "to that of boot mode's\n");
312 dev_warn(dev, "device reports %pM\n", ddi->mac_address);
313 dev_warn(dev, "boot mode reported %pM\n", net_dev->perm_addr);
314 if (!memcmp(zeromac, ddi->mac_address, sizeof(zeromac)))
315 dev_err(dev, "device reports an invalid MAC address, "
318 dev_warn(dev, "updating MAC address\n");
319 net_dev->addr_len = ETH_ALEN;
320 memcpy(net_dev->perm_addr, ddi->mac_address, ETH_ALEN);
321 memcpy(net_dev->dev_addr, ddi->mac_address, ETH_ALEN);
327 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
333 * __i2400m_dev_start - Bring up driver communication with the device
335 * @i2400m: device descriptor
336 * @flags: boot mode flags
338 * Returns: 0 if ok, < 0 errno code on error.
340 * Uploads firmware and brings up all the resources needed to be able
341 * to communicate with the device.
343 * The workqueue has to be setup early, at least before RX handling
344 * (it's only real user for now) so it can process reports as they
345 * arrive. We also want to destroy it if we retry, to make sure it is
346 * flushed...easier like this.
348 * TX needs to be setup before the bus-specific code (otherwise on
349 * shutdown, the bus-tx code could try to access it).
352 int __i2400m_dev_start(struct i2400m *i2400m, enum i2400m_bri flags)
355 struct wimax_dev *wimax_dev = &i2400m->wimax_dev;
356 struct net_device *net_dev = wimax_dev->net_dev;
357 struct device *dev = i2400m_dev(i2400m);
358 int times = i2400m->bus_bm_retries;
360 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
362 result = i2400m_dev_bootstrap(i2400m, flags);
364 dev_err(dev, "cannot bootstrap device: %d\n", result);
365 goto error_bootstrap;
367 result = i2400m_tx_setup(i2400m);
370 result = i2400m_rx_setup(i2400m);
373 i2400m->work_queue = create_singlethread_workqueue(wimax_dev->name);
374 if (i2400m->work_queue == NULL) {
376 dev_err(dev, "cannot create workqueue\n");
377 goto error_create_workqueue;
379 if (i2400m->bus_dev_start) {
380 result = i2400m->bus_dev_start(i2400m);
382 goto error_bus_dev_start;
385 wmb(); /* see i2400m->ready's documentation */
386 /* process pending reports from the device */
387 queue_work(i2400m->work_queue, &i2400m->rx_report_ws);
388 result = i2400m_firmware_check(i2400m); /* fw versions ok? */
391 /* At this point is ok to send commands to the device */
392 result = i2400m_check_mac_addr(i2400m);
394 goto error_check_mac_addr;
395 result = i2400m_dev_initialize(i2400m);
397 goto error_dev_initialize;
398 /* At this point, reports will come for the device and set it
399 * to the right state if it is different than UNINITIALIZED */
400 d_fnend(3, dev, "(net_dev %p [i2400m %p]) = %d\n",
401 net_dev, i2400m, result);
404 error_dev_initialize:
405 error_check_mac_addr:
407 wmb(); /* see i2400m->ready's documentation */
408 flush_workqueue(i2400m->work_queue);
410 if (i2400m->bus_dev_stop)
411 i2400m->bus_dev_stop(i2400m);
413 destroy_workqueue(i2400m->work_queue);
414 error_create_workqueue:
415 i2400m_rx_release(i2400m);
417 i2400m_tx_release(i2400m);
420 if (result == -EL3RST && times-- > 0) {
421 flags = I2400M_BRI_SOFT|I2400M_BRI_MAC_REINIT;
424 d_fnend(3, dev, "(net_dev %p [i2400m %p]) = %d\n",
425 net_dev, i2400m, result);
431 int i2400m_dev_start(struct i2400m *i2400m, enum i2400m_bri bm_flags)
434 mutex_lock(&i2400m->init_mutex); /* Well, start the device */
435 if (i2400m->updown == 0) {
436 result = __i2400m_dev_start(i2400m, bm_flags);
439 wmb(); /* see i2400m->updown's documentation */
442 mutex_unlock(&i2400m->init_mutex);
448 * i2400m_dev_stop - Tear down driver communication with the device
450 * @i2400m: device descriptor
452 * Returns: 0 if ok, < 0 errno code on error.
454 * Releases all the resources allocated to communicate with the
455 * device. Note we cannot destroy the workqueue earlier as until RX is
456 * fully destroyed, it could still try to schedule jobs.
459 void __i2400m_dev_stop(struct i2400m *i2400m)
461 struct wimax_dev *wimax_dev = &i2400m->wimax_dev;
462 struct device *dev = i2400m_dev(i2400m);
464 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
465 wimax_state_change(wimax_dev, __WIMAX_ST_QUIESCING);
466 i2400m_msg_to_dev_cancel_wait(i2400m, -EL3RST);
467 complete(&i2400m->msg_completion);
468 i2400m_net_wake_stop(i2400m);
469 i2400m_dev_shutdown(i2400m);
471 * Make sure no report hooks are running *before* we stop the
472 * communication infrastructure with the device.
474 i2400m->ready = 0; /* nobody can queue work anymore */
475 wmb(); /* see i2400m->ready's documentation */
476 flush_workqueue(i2400m->work_queue);
478 if (i2400m->bus_dev_stop)
479 i2400m->bus_dev_stop(i2400m);
480 destroy_workqueue(i2400m->work_queue);
481 i2400m_rx_release(i2400m);
482 i2400m_tx_release(i2400m);
483 wimax_state_change(wimax_dev, WIMAX_ST_DOWN);
484 d_fnend(3, dev, "(i2400m %p) = 0\n", i2400m);
489 * Watch out -- we only need to stop if there is a need for it. The
490 * device could have reset itself and failed to come up again (see
491 * _i2400m_dev_reset_handle()).
494 void i2400m_dev_stop(struct i2400m *i2400m)
496 mutex_lock(&i2400m->init_mutex);
497 if (i2400m->updown) {
498 __i2400m_dev_stop(i2400m);
500 wmb(); /* see i2400m->updown's documentation */
502 mutex_unlock(&i2400m->init_mutex);
507 * Listen to PM events to cache the firmware before suspend/hibernation
509 * When the device comes out of suspend, it might go into reset and
510 * firmware has to be uploaded again. At resume, most of the times, we
511 * can't load firmware images from disk, so we need to cache it.
513 * i2400m_fw_cache() will allocate a kobject and attach the firmware
514 * to it; that way we don't have to worry too much about the fw loader
515 * hitting a race condition.
517 * Note: modus operandi stolen from the Orinoco driver; thx.
520 int i2400m_pm_notifier(struct notifier_block *notifier,
521 unsigned long pm_event,
524 struct i2400m *i2400m =
525 container_of(notifier, struct i2400m, pm_notifier);
526 struct device *dev = i2400m_dev(i2400m);
528 d_fnstart(3, dev, "(i2400m %p pm_event %lx)\n", i2400m, pm_event);
530 case PM_HIBERNATION_PREPARE:
531 case PM_SUSPEND_PREPARE:
532 i2400m_fw_cache(i2400m);
534 case PM_POST_RESTORE:
535 /* Restore from hibernation failed. We need to clean
536 * up in exactly the same way, so fall through. */
537 case PM_POST_HIBERNATION:
538 case PM_POST_SUSPEND:
539 i2400m_fw_uncache(i2400m);
542 case PM_RESTORE_PREPARE:
546 d_fnend(3, dev, "(i2400m %p pm_event %lx) = void\n", i2400m, pm_event);
552 * pre-reset is called before a device is going on reset
554 * This has to be followed by a call to i2400m_post_reset(), otherwise
555 * bad things might happen.
557 int i2400m_pre_reset(struct i2400m *i2400m)
560 struct device *dev = i2400m_dev(i2400m);
562 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
563 d_printf(1, dev, "pre-reset shut down\n");
566 mutex_lock(&i2400m->init_mutex);
567 if (i2400m->updown) {
568 netif_tx_disable(i2400m->wimax_dev.net_dev);
569 __i2400m_dev_stop(i2400m);
571 /* down't set updown to zero -- this way
572 * post_reset can restore properly */
574 mutex_unlock(&i2400m->init_mutex);
575 if (i2400m->bus_release)
576 i2400m->bus_release(i2400m);
577 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
580 EXPORT_SYMBOL_GPL(i2400m_pre_reset);
584 * Restore device state after a reset
586 * Do the work needed after a device reset to bring it up to the same
587 * state as it was before the reset.
589 * NOTE: this requires i2400m->init_mutex taken
591 int i2400m_post_reset(struct i2400m *i2400m)
594 struct device *dev = i2400m_dev(i2400m);
596 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
597 d_printf(1, dev, "post-reset start\n");
598 if (i2400m->bus_setup) {
599 result = i2400m->bus_setup(i2400m);
601 dev_err(dev, "bus-specific setup failed: %d\n",
603 goto error_bus_setup;
606 mutex_lock(&i2400m->init_mutex);
607 if (i2400m->updown) {
608 result = __i2400m_dev_start(
609 i2400m, I2400M_BRI_SOFT | I2400M_BRI_MAC_REINIT);
611 goto error_dev_start;
613 mutex_unlock(&i2400m->init_mutex);
614 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
618 if (i2400m->bus_release)
619 i2400m->bus_release(i2400m);
621 /* even if the device was up, it could not be recovered, so we
622 * mark it as down. */
624 wmb(); /* see i2400m->updown's documentation */
625 mutex_unlock(&i2400m->init_mutex);
626 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
629 EXPORT_SYMBOL_GPL(i2400m_post_reset);
633 * The device has rebooted; fix up the device and the driver
635 * Tear down the driver communication with the device, reload the
636 * firmware and reinitialize the communication with the device.
638 * If someone calls a reset when the device's firmware is down, in
639 * theory we won't see it because we are not listening. However, just
640 * in case, leave the code to handle it.
642 * If there is a reset context, use it; this means someone is waiting
643 * for us to tell him when the reset operation is complete and the
644 * device is ready to rock again.
646 * NOTE: if we are in the process of bringing up or down the
647 * communication with the device [running i2400m_dev_start() or
648 * _stop()], don't do anything, let it fail and handle it.
650 * This function is ran always in a thread context
652 * This function gets passed, as payload to i2400m_work() a 'const
653 * char *' ptr with a "reason" why the reset happened (for messages).
656 void __i2400m_dev_reset_handle(struct work_struct *ws)
659 struct i2400m_work *iw = container_of(ws, struct i2400m_work, ws);
661 struct i2400m *i2400m = iw->i2400m;
662 struct device *dev = i2400m_dev(i2400m);
663 struct i2400m_reset_ctx *ctx = i2400m->reset_ctx;
665 if (WARN_ON(iw->pl_size != sizeof(reason)))
666 reason = "SW BUG: reason n/a";
668 memcpy(&reason, iw->pl, sizeof(reason));
670 d_fnstart(3, dev, "(ws %p i2400m %p reason %s)\n", ws, i2400m, reason);
673 if (mutex_trylock(&i2400m->init_mutex) == 0) {
674 /* We are still in i2400m_dev_start() [let it fail] or
675 * i2400m_dev_stop() [we are shutting down anyway, so
676 * ignore it] or we are resetting somewhere else. */
677 dev_err(dev, "device rebooted somewhere else?\n");
678 i2400m_msg_to_dev_cancel_wait(i2400m, -EL3RST);
679 complete(&i2400m->msg_completion);
682 if (i2400m->updown == 0) {
683 dev_info(dev, "%s: device is down, doing nothing\n", reason);
686 dev_err(dev, "%s: reinitializing driver\n", reason);
687 __i2400m_dev_stop(i2400m);
688 result = __i2400m_dev_start(i2400m,
689 I2400M_BRI_SOFT | I2400M_BRI_MAC_REINIT);
692 wmb(); /* see i2400m->updown's documentation */
693 dev_err(dev, "%s: cannot start the device: %d\n",
698 if (i2400m->reset_ctx) {
699 ctx->result = result;
700 complete(&ctx->completion);
702 mutex_unlock(&i2400m->init_mutex);
703 if (result == -EUCLEAN) {
704 /* ops, need to clean up [w/ init_mutex not held] */
705 result = i2400m_reset(i2400m, I2400M_RT_BUS);
712 d_fnend(3, dev, "(ws %p i2400m %p reason %s) = void\n",
718 * i2400m_dev_reset_handle - Handle a device's reset in a thread context
720 * Schedule a device reset handling out on a thread context, so it
721 * is safe to call from atomic context. We can't use the i2400m's
722 * queue as we are going to destroy it and reinitialize it as part of
723 * the driver bringup/bringup process.
725 * See __i2400m_dev_reset_handle() for details; that takes care of
726 * reinitializing the driver to handle the reset, calling into the
727 * bus-specific functions ops as needed.
729 int i2400m_dev_reset_handle(struct i2400m *i2400m, const char *reason)
731 i2400m->boot_mode = 1;
732 wmb(); /* Make sure i2400m_msg_to_dev() sees boot_mode */
733 return i2400m_schedule_work(i2400m, __i2400m_dev_reset_handle,
734 GFP_ATOMIC, &reason, sizeof(reason));
736 EXPORT_SYMBOL_GPL(i2400m_dev_reset_handle);
740 * Alloc the command and ack buffers for boot mode
742 * Get the buffers needed to deal with boot mode messages. These
743 * buffers need to be allocated before the sdio recieve irq is setup.
746 int i2400m_bm_buf_alloc(struct i2400m *i2400m)
751 i2400m->bm_cmd_buf = kzalloc(I2400M_BM_CMD_BUF_SIZE, GFP_KERNEL);
752 if (i2400m->bm_cmd_buf == NULL)
753 goto error_bm_cmd_kzalloc;
754 i2400m->bm_ack_buf = kzalloc(I2400M_BM_ACK_BUF_SIZE, GFP_KERNEL);
755 if (i2400m->bm_ack_buf == NULL)
756 goto error_bm_ack_buf_kzalloc;
759 error_bm_ack_buf_kzalloc:
760 kfree(i2400m->bm_cmd_buf);
761 error_bm_cmd_kzalloc:
767 * Free boot mode command and ack buffers.
770 void i2400m_bm_buf_free(struct i2400m *i2400m)
772 kfree(i2400m->bm_ack_buf);
773 kfree(i2400m->bm_cmd_buf);
778 * i2400m_init - Initialize a 'struct i2400m' from all zeroes
780 * This is a bus-generic API call.
782 void i2400m_init(struct i2400m *i2400m)
784 wimax_dev_init(&i2400m->wimax_dev);
786 i2400m->boot_mode = 1;
787 i2400m->rx_reorder = 1;
788 init_waitqueue_head(&i2400m->state_wq);
790 spin_lock_init(&i2400m->tx_lock);
791 i2400m->tx_pl_min = UINT_MAX;
792 i2400m->tx_size_min = UINT_MAX;
794 spin_lock_init(&i2400m->rx_lock);
795 i2400m->rx_pl_min = UINT_MAX;
796 i2400m->rx_size_min = UINT_MAX;
797 INIT_LIST_HEAD(&i2400m->rx_reports);
798 INIT_WORK(&i2400m->rx_report_ws, i2400m_report_hook_work);
800 mutex_init(&i2400m->msg_mutex);
801 init_completion(&i2400m->msg_completion);
803 mutex_init(&i2400m->init_mutex);
804 /* wake_tx_ws is initialized in i2400m_tx_setup() */
806 EXPORT_SYMBOL_GPL(i2400m_init);
809 int i2400m_reset(struct i2400m *i2400m, enum i2400m_reset_type rt)
811 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
814 * Make sure we stop TXs and down the carrier before
815 * resetting; this is needed to avoid things like
816 * i2400m_wake_tx() scheduling stuff in parallel.
818 if (net_dev->reg_state == NETREG_REGISTERED) {
819 netif_tx_disable(net_dev);
820 netif_carrier_off(net_dev);
822 return i2400m->bus_reset(i2400m, rt);
824 EXPORT_SYMBOL_GPL(i2400m_reset);
828 * i2400m_setup - bus-generic setup function for the i2400m device
830 * @i2400m: device descriptor (bus-specific parts have been initialized)
832 * Returns: 0 if ok, < 0 errno code on error.
834 * Sets up basic device comunication infrastructure, boots the ROM to
835 * read the MAC address, registers with the WiMAX and network stacks
836 * and then brings up the device.
838 int i2400m_setup(struct i2400m *i2400m, enum i2400m_bri bm_flags)
840 int result = -ENODEV;
841 struct device *dev = i2400m_dev(i2400m);
842 struct wimax_dev *wimax_dev = &i2400m->wimax_dev;
843 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
845 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
847 snprintf(wimax_dev->name, sizeof(wimax_dev->name),
848 "i2400m-%s:%s", dev->bus->name, dev_name(dev));
850 result = i2400m_bm_buf_alloc(i2400m);
852 dev_err(dev, "cannot allocate bootmode scratch buffers\n");
853 goto error_bm_buf_alloc;
856 if (i2400m->bus_setup) {
857 result = i2400m->bus_setup(i2400m);
859 dev_err(dev, "bus-specific setup failed: %d\n",
861 goto error_bus_setup;
865 result = i2400m_bootrom_init(i2400m, bm_flags);
867 dev_err(dev, "read mac addr: bootrom init "
868 "failed: %d\n", result);
869 goto error_bootrom_init;
871 result = i2400m_read_mac_addr(i2400m);
873 goto error_read_mac_addr;
874 random_ether_addr(i2400m->src_mac_addr);
876 i2400m->pm_notifier.notifier_call = i2400m_pm_notifier;
877 register_pm_notifier(&i2400m->pm_notifier);
879 result = register_netdev(net_dev); /* Okey dokey, bring it up */
881 dev_err(dev, "cannot register i2400m network device: %d\n",
883 goto error_register_netdev;
885 netif_carrier_off(net_dev);
887 i2400m->wimax_dev.op_msg_from_user = i2400m_op_msg_from_user;
888 i2400m->wimax_dev.op_rfkill_sw_toggle = i2400m_op_rfkill_sw_toggle;
889 i2400m->wimax_dev.op_reset = i2400m_op_reset;
891 result = wimax_dev_add(&i2400m->wimax_dev, net_dev);
893 goto error_wimax_dev_add;
895 /* Now setup all that requires a registered net and wimax device. */
896 result = sysfs_create_group(&net_dev->dev.kobj, &i2400m_dev_attr_group);
898 dev_err(dev, "cannot setup i2400m's sysfs: %d\n", result);
899 goto error_sysfs_setup;
902 result = i2400m_debugfs_add(i2400m);
904 dev_err(dev, "cannot setup i2400m's debugfs: %d\n", result);
905 goto error_debugfs_setup;
908 result = i2400m_dev_start(i2400m, bm_flags);
910 goto error_dev_start;
911 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
915 i2400m_debugfs_rm(i2400m);
917 sysfs_remove_group(&i2400m->wimax_dev.net_dev->dev.kobj,
918 &i2400m_dev_attr_group);
920 wimax_dev_rm(&i2400m->wimax_dev);
922 unregister_netdev(net_dev);
923 error_register_netdev:
924 unregister_pm_notifier(&i2400m->pm_notifier);
927 if (i2400m->bus_release)
928 i2400m->bus_release(i2400m);
930 i2400m_bm_buf_free(i2400m);
932 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
935 EXPORT_SYMBOL_GPL(i2400m_setup);
939 * i2400m_release - release the bus-generic driver resources
941 * Sends a disconnect message and undoes any setup done by i2400m_setup()
943 void i2400m_release(struct i2400m *i2400m)
945 struct device *dev = i2400m_dev(i2400m);
947 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
948 netif_stop_queue(i2400m->wimax_dev.net_dev);
950 i2400m_dev_stop(i2400m);
952 i2400m_debugfs_rm(i2400m);
953 sysfs_remove_group(&i2400m->wimax_dev.net_dev->dev.kobj,
954 &i2400m_dev_attr_group);
955 wimax_dev_rm(&i2400m->wimax_dev);
956 unregister_netdev(i2400m->wimax_dev.net_dev);
957 unregister_pm_notifier(&i2400m->pm_notifier);
958 if (i2400m->bus_release)
959 i2400m->bus_release(i2400m);
960 i2400m_bm_buf_free(i2400m);
961 d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
963 EXPORT_SYMBOL_GPL(i2400m_release);
967 * Debug levels control; see debug.h
969 struct d_level D_LEVEL[] = {
970 D_SUBMODULE_DEFINE(control),
971 D_SUBMODULE_DEFINE(driver),
972 D_SUBMODULE_DEFINE(debugfs),
973 D_SUBMODULE_DEFINE(fw),
974 D_SUBMODULE_DEFINE(netdev),
975 D_SUBMODULE_DEFINE(rfkill),
976 D_SUBMODULE_DEFINE(rx),
977 D_SUBMODULE_DEFINE(sysfs),
978 D_SUBMODULE_DEFINE(tx),
980 size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL);
984 int __init i2400m_driver_init(void)
986 d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400m_debug_params,
988 return i2400m_barker_db_init(i2400m_barkers_params);
990 module_init(i2400m_driver_init);
993 void __exit i2400m_driver_exit(void)
995 /* for scheds i2400m_dev_reset_handle() */
996 flush_scheduled_work();
997 i2400m_barker_db_exit();
999 module_exit(i2400m_driver_exit);
1001 MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>");
1002 MODULE_DESCRIPTION("Intel 2400M WiMAX networking bus-generic driver");
1003 MODULE_LICENSE("GPL");