blob: 1674dba43f83bac68f1a47e71386f9f00a43cc3e [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090072#include <linux/slab.h>
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -080073
74#define D_SUBMODULE driver
75#include "debug-levels.h"
76
77
78int i2400m_idle_mode_disabled; /* 0 (idle mode enabled) by default */
79module_param_named(idle_mode_disabled, i2400m_idle_mode_disabled, int, 0644);
80MODULE_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.");
83
Inaky Perez-Gonzalezc7475832009-02-28 23:42:54 +000084int i2400m_rx_reorder_disabled; /* 0 (rx reorder enabled) by default */
85module_param_named(rx_reorder_disabled, i2400m_rx_reorder_disabled, int, 0644);
86MODULE_PARM_DESC(rx_reorder_disabled,
87 "If true, RX reordering will be disabled.");
88
Inaky Perez-Gonzalezfb101672009-05-07 10:27:42 -070089int i2400m_power_save_disabled; /* 0 (power saving enabled) by default */
90module_param_named(power_save_disabled, i2400m_power_save_disabled, int, 0644);
91MODULE_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 "
95 "saving).");
96
Inaky Perez-Gonzalez4c2b1a12009-09-02 15:36:05 -070097static char i2400m_debug_params[128];
98module_param_string(debug, i2400m_debug_params, sizeof(i2400m_debug_params),
99 0644);
100MODULE_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.");
104
Inaky Perez-Gonzalezaba3792a2009-09-03 15:14:29 -0700105static char i2400m_barkers_params[128];
106module_param_string(barkers, i2400m_barkers_params,
107 sizeof(i2400m_barkers_params), 0644);
108MODULE_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.");
113
Inaky Perez-Gonzalezb0fbcb22009-09-14 13:29:32 -0700114static
115struct 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)
118{
119 struct i2400m_work *iw;
120
121 iw = kzalloc(sizeof(*iw) + pl_size, gfp_flags);
122 if (iw == NULL)
123 return NULL;
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);
128 return iw;
129}
130
131
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800132/*
133 * Schedule i2400m's specific work on the system's queue.
134 *
135 * Used for a few cases where we really need it; otherwise, identical
136 * to i2400m_queue_work().
137 *
138 * Returns < 0 errno code on error, 1 if ok.
139 *
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.
143 */
144int i2400m_schedule_work(struct i2400m *i2400m,
Inaky Perez-Gonzalezb0fbcb22009-09-14 13:29:32 -0700145 void (*fn)(struct work_struct *), gfp_t gfp_flags,
146 const void *pl, size_t pl_size)
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800147{
148 int result;
149 struct i2400m_work *iw;
150
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800151 result = -ENOMEM;
Inaky Perez-Gonzalezb0fbcb22009-09-14 13:29:32 -0700152 iw = __i2400m_work_setup(i2400m, fn, gfp_flags, pl, pl_size);
153 if (iw != NULL) {
154 result = schedule_work(&iw->ws);
155 if (WARN_ON(result == 0))
156 result = -ENXIO;
157 }
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800158 return result;
159}
160
161
162/*
163 * WiMAX stack operation: relay a message from user space
164 *
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
170 *
171 * The WiMAX stack will call this function when a message was received
172 * from user space.
173 *
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.
178 *
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.
182 *
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.
188 *
189 * Note that asynchronous events from the device are processed and
190 * sent to user space in rx.c.
191 */
192static
193int 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)
197{
198 int result;
199 struct i2400m *i2400m = wimax_dev_to_i2400m(wimax_dev);
200 struct device *dev = i2400m_dev(i2400m);
201 struct sk_buff *ack_skb;
202
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);
208 if (IS_ERR(ack_skb))
209 goto error_msg_to_dev;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800210 result = wimax_msg_send(&i2400m->wimax_dev, ack_skb);
211error_msg_to_dev:
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,
214 genl_info, result);
215 return result;
216}
217
218
219/*
220 * Context to wait for a reset to finalize
221 */
222struct i2400m_reset_ctx {
223 struct completion completion;
224 int result;
225};
226
227
228/*
229 * WiMAX stack operation: reset a device
230 *
231 * @wimax_dev: device descriptor
232 *
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.
236 *
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.
240 *
241 * The bus-driver implementation of reset takes care of falling back
242 * to cold reset if warm fails.
243 */
244static
245int i2400m_op_reset(struct wimax_dev *wimax_dev)
246{
247 int result;
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),
252 .result = 0,
253 };
254
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);
Inaky Perez-Gonzalezc931cee2009-10-19 16:24:56 +0900259 result = i2400m_reset(i2400m, I2400M_RT_WARM);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800260 if (result < 0)
261 goto out;
262 result = wait_for_completion_timeout(&ctx.completion, 4*HZ);
263 if (result == 0)
264 result = -ETIMEDOUT;
265 else if (result > 0)
266 result = ctx.result;
267 /* if result < 0, pass it on */
268 mutex_lock(&i2400m->init_mutex);
269 i2400m->reset_ctx = NULL;
270 mutex_unlock(&i2400m->init_mutex);
271out:
272 d_fnend(4, dev, "(wimax_dev %p) = %d\n", wimax_dev, result);
273 return result;
274}
275
276
277/*
278 * Check the MAC address we got from boot mode is ok
279 *
280 * @i2400m: device descriptor
281 *
282 * Returns: 0 if ok, < 0 errno code on error.
283 */
284static
285int i2400m_check_mac_addr(struct i2400m *i2400m)
286{
287 int result;
288 struct device *dev = i2400m_dev(i2400m);
289 struct sk_buff *skb;
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 };
293
294 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
295 skb = i2400m_get_device_info(i2400m);
296 if (IS_ERR(skb)) {
297 result = PTR_ERR(skb);
298 dev_err(dev, "Cannot verify MAC address, error reading: %d\n",
299 result);
300 goto error;
301 }
302 /* Extract MAC addresss */
303 ddi = (void *) skb->data;
304 BUILD_BUG_ON(ETH_ALEN != sizeof(ddi->mac_address));
hartleys4754b3d2010-01-05 07:00:57 +0000305 d_printf(2, dev, "GET DEVICE INFO: mac addr %pM\n",
306 ddi->mac_address);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800307 if (!memcmp(net_dev->perm_addr, ddi->mac_address,
308 sizeof(ddi->mac_address)))
309 goto ok;
310 dev_warn(dev, "warning: device reports a different MAC address "
311 "to that of boot mode's\n");
hartleys4754b3d2010-01-05 07:00:57 +0000312 dev_warn(dev, "device reports %pM\n", ddi->mac_address);
313 dev_warn(dev, "boot mode reported %pM\n", net_dev->perm_addr);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800314 if (!memcmp(zeromac, ddi->mac_address, sizeof(zeromac)))
315 dev_err(dev, "device reports an invalid MAC address, "
316 "not updating\n");
317 else {
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);
322 }
323ok:
324 result = 0;
325 kfree_skb(skb);
326error:
327 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
328 return result;
329}
330
331
332/**
333 * __i2400m_dev_start - Bring up driver communication with the device
334 *
335 * @i2400m: device descriptor
336 * @flags: boot mode flags
337 *
338 * Returns: 0 if ok, < 0 errno code on error.
339 *
340 * Uploads firmware and brings up all the resources needed to be able
341 * to communicate with the device.
342 *
Inaky Perez-Gonzaleze9a6b452009-05-08 13:02:41 -0700343 * 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.
347 *
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800348 * TX needs to be setup before the bus-specific code (otherwise on
349 * shutdown, the bus-tx code could try to access it).
350 */
351static
352int __i2400m_dev_start(struct i2400m *i2400m, enum i2400m_bri flags)
353{
354 int result;
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);
Inaky Perez-Gonzalezecddfd52009-06-03 16:13:14 +0800358 int times = i2400m->bus_bm_retries;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800359
360 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
361retry:
362 result = i2400m_dev_bootstrap(i2400m, flags);
363 if (result < 0) {
364 dev_err(dev, "cannot bootstrap device: %d\n", result);
365 goto error_bootstrap;
366 }
367 result = i2400m_tx_setup(i2400m);
368 if (result < 0)
369 goto error_tx_setup;
Inaky Perez-Gonzalezc7475832009-02-28 23:42:54 +0000370 result = i2400m_rx_setup(i2400m);
371 if (result < 0)
372 goto error_rx_setup;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800373 i2400m->work_queue = create_singlethread_workqueue(wimax_dev->name);
374 if (i2400m->work_queue == NULL) {
375 result = -ENOMEM;
376 dev_err(dev, "cannot create workqueue\n");
377 goto error_create_workqueue;
378 }
Inaky Perez-Gonzalez097acbe2009-10-08 12:33:50 +0900379 if (i2400m->bus_dev_start) {
380 result = i2400m->bus_dev_start(i2400m);
381 if (result < 0)
382 goto error_bus_dev_start;
383 }
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700384 i2400m->ready = 1;
385 wmb(); /* see i2400m->ready's documentation */
Inaky Perez-Gonzaleza0beba22009-10-07 21:43:10 +0900386 /* process pending reports from the device */
387 queue_work(i2400m->work_queue, &i2400m->rx_report_ws);
Inaky Perez-Gonzalez6a0f7ab2009-02-28 23:42:49 +0000388 result = i2400m_firmware_check(i2400m); /* fw versions ok? */
389 if (result < 0)
390 goto error_fw_check;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800391 /* At this point is ok to send commands to the device */
392 result = i2400m_check_mac_addr(i2400m);
393 if (result < 0)
394 goto error_check_mac_addr;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800395 result = i2400m_dev_initialize(i2400m);
396 if (result < 0)
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);
402 return result;
403
404error_dev_initialize:
405error_check_mac_addr:
Cindy H Kao49d72df2010-03-30 19:19:37 -0700406error_fw_check:
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700407 i2400m->ready = 0;
408 wmb(); /* see i2400m->ready's documentation */
409 flush_workqueue(i2400m->work_queue);
Inaky Perez-Gonzalez097acbe2009-10-08 12:33:50 +0900410 if (i2400m->bus_dev_stop)
411 i2400m->bus_dev_stop(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800412error_bus_dev_start:
Inaky Perez-Gonzaleze9a6b452009-05-08 13:02:41 -0700413 destroy_workqueue(i2400m->work_queue);
414error_create_workqueue:
Inaky Perez-Gonzalezc7475832009-02-28 23:42:54 +0000415 i2400m_rx_release(i2400m);
416error_rx_setup:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800417 i2400m_tx_release(i2400m);
418error_tx_setup:
419error_bootstrap:
Cindy H Kao0bcfc5e2009-06-10 17:06:19 -0700420 if (result == -EL3RST && times-- > 0) {
Cindy H Kao8b5b30ee2009-06-10 16:52:10 -0700421 flags = I2400M_BRI_SOFT|I2400M_BRI_MAC_REINIT;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800422 goto retry;
423 }
424 d_fnend(3, dev, "(net_dev %p [i2400m %p]) = %d\n",
425 net_dev, i2400m, result);
426 return result;
427}
428
429
430static
431int i2400m_dev_start(struct i2400m *i2400m, enum i2400m_bri bm_flags)
432{
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700433 int result = 0;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800434 mutex_lock(&i2400m->init_mutex); /* Well, start the device */
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700435 if (i2400m->updown == 0) {
436 result = __i2400m_dev_start(i2400m, bm_flags);
437 if (result >= 0) {
438 i2400m->updown = 1;
Cindy H Kaof4e41342010-04-07 19:42:42 -0700439 i2400m->alive = 1;
440 wmb();/* see i2400m->updown and i2400m->alive's doc */
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700441 }
442 }
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800443 mutex_unlock(&i2400m->init_mutex);
444 return result;
445}
446
447
448/**
449 * i2400m_dev_stop - Tear down driver communication with the device
450 *
451 * @i2400m: device descriptor
452 *
453 * Returns: 0 if ok, < 0 errno code on error.
454 *
Inaky Perez-Gonzaleze9a6b452009-05-08 13:02:41 -0700455 * Releases all the resources allocated to communicate with the
456 * device. Note we cannot destroy the workqueue earlier as until RX is
457 * fully destroyed, it could still try to schedule jobs.
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800458 */
459static
460void __i2400m_dev_stop(struct i2400m *i2400m)
461{
462 struct wimax_dev *wimax_dev = &i2400m->wimax_dev;
463 struct device *dev = i2400m_dev(i2400m);
464
465 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
466 wimax_state_change(wimax_dev, __WIMAX_ST_QUIESCING);
Inaky Perez-Gonzalez5eeae352009-10-07 12:20:15 +0900467 i2400m_msg_to_dev_cancel_wait(i2400m, -EL3RST);
468 complete(&i2400m->msg_completion);
Inaky Perez-Gonzalezac53aed2009-09-16 16:30:39 -0700469 i2400m_net_wake_stop(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800470 i2400m_dev_shutdown(i2400m);
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700471 /*
472 * Make sure no report hooks are running *before* we stop the
473 * communication infrastructure with the device.
474 */
475 i2400m->ready = 0; /* nobody can queue work anymore */
476 wmb(); /* see i2400m->ready's documentation */
477 flush_workqueue(i2400m->work_queue);
478
Inaky Perez-Gonzalez097acbe2009-10-08 12:33:50 +0900479 if (i2400m->bus_dev_stop)
480 i2400m->bus_dev_stop(i2400m);
Inaky Perez-Gonzaleze9a6b452009-05-08 13:02:41 -0700481 destroy_workqueue(i2400m->work_queue);
Inaky Perez-Gonzalezc7475832009-02-28 23:42:54 +0000482 i2400m_rx_release(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800483 i2400m_tx_release(i2400m);
484 wimax_state_change(wimax_dev, WIMAX_ST_DOWN);
485 d_fnend(3, dev, "(i2400m %p) = 0\n", i2400m);
486}
487
488
489/*
490 * Watch out -- we only need to stop if there is a need for it. The
491 * device could have reset itself and failed to come up again (see
492 * _i2400m_dev_reset_handle()).
493 */
494static
495void i2400m_dev_stop(struct i2400m *i2400m)
496{
497 mutex_lock(&i2400m->init_mutex);
498 if (i2400m->updown) {
499 __i2400m_dev_stop(i2400m);
500 i2400m->updown = 0;
Cindy H Kaof4e41342010-04-07 19:42:42 -0700501 i2400m->alive = 0;
502 wmb(); /* see i2400m->updown and i2400m->alive's doc */
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800503 }
504 mutex_unlock(&i2400m->init_mutex);
505}
506
507
508/*
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -0700509 * Listen to PM events to cache the firmware before suspend/hibernation
510 *
511 * When the device comes out of suspend, it might go into reset and
512 * firmware has to be uploaded again. At resume, most of the times, we
513 * can't load firmware images from disk, so we need to cache it.
514 *
515 * i2400m_fw_cache() will allocate a kobject and attach the firmware
516 * to it; that way we don't have to worry too much about the fw loader
517 * hitting a race condition.
518 *
519 * Note: modus operandi stolen from the Orinoco driver; thx.
520 */
521static
522int i2400m_pm_notifier(struct notifier_block *notifier,
523 unsigned long pm_event,
524 void *unused)
525{
526 struct i2400m *i2400m =
527 container_of(notifier, struct i2400m, pm_notifier);
528 struct device *dev = i2400m_dev(i2400m);
529
530 d_fnstart(3, dev, "(i2400m %p pm_event %lx)\n", i2400m, pm_event);
531 switch (pm_event) {
532 case PM_HIBERNATION_PREPARE:
533 case PM_SUSPEND_PREPARE:
534 i2400m_fw_cache(i2400m);
535 break;
536 case PM_POST_RESTORE:
537 /* Restore from hibernation failed. We need to clean
538 * up in exactly the same way, so fall through. */
539 case PM_POST_HIBERNATION:
540 case PM_POST_SUSPEND:
541 i2400m_fw_uncache(i2400m);
542 break;
543
544 case PM_RESTORE_PREPARE:
545 default:
546 break;
547 }
548 d_fnend(3, dev, "(i2400m %p pm_event %lx) = void\n", i2400m, pm_event);
549 return NOTIFY_DONE;
550}
551
552
553/*
Inaky Perez-Gonzalez3725d8c2009-09-17 15:20:45 -0700554 * pre-reset is called before a device is going on reset
555 *
556 * This has to be followed by a call to i2400m_post_reset(), otherwise
557 * bad things might happen.
558 */
559int i2400m_pre_reset(struct i2400m *i2400m)
560{
561 int result;
562 struct device *dev = i2400m_dev(i2400m);
563
564 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
565 d_printf(1, dev, "pre-reset shut down\n");
566
567 result = 0;
568 mutex_lock(&i2400m->init_mutex);
569 if (i2400m->updown) {
570 netif_tx_disable(i2400m->wimax_dev.net_dev);
571 __i2400m_dev_stop(i2400m);
572 result = 0;
573 /* down't set updown to zero -- this way
574 * post_reset can restore properly */
575 }
576 mutex_unlock(&i2400m->init_mutex);
577 if (i2400m->bus_release)
578 i2400m->bus_release(i2400m);
579 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
580 return result;
581}
582EXPORT_SYMBOL_GPL(i2400m_pre_reset);
583
584
585/*
586 * Restore device state after a reset
587 *
588 * Do the work needed after a device reset to bring it up to the same
589 * state as it was before the reset.
590 *
591 * NOTE: this requires i2400m->init_mutex taken
592 */
593int i2400m_post_reset(struct i2400m *i2400m)
594{
595 int result = 0;
596 struct device *dev = i2400m_dev(i2400m);
597
598 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
599 d_printf(1, dev, "post-reset start\n");
600 if (i2400m->bus_setup) {
601 result = i2400m->bus_setup(i2400m);
602 if (result < 0) {
603 dev_err(dev, "bus-specific setup failed: %d\n",
604 result);
605 goto error_bus_setup;
606 }
607 }
608 mutex_lock(&i2400m->init_mutex);
609 if (i2400m->updown) {
610 result = __i2400m_dev_start(
611 i2400m, I2400M_BRI_SOFT | I2400M_BRI_MAC_REINIT);
612 if (result < 0)
613 goto error_dev_start;
614 }
615 mutex_unlock(&i2400m->init_mutex);
616 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
617 return result;
618
619error_dev_start:
620 if (i2400m->bus_release)
621 i2400m->bus_release(i2400m);
622error_bus_setup:
623 /* even if the device was up, it could not be recovered, so we
624 * mark it as down. */
625 i2400m->updown = 0;
626 wmb(); /* see i2400m->updown's documentation */
627 mutex_unlock(&i2400m->init_mutex);
628 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
629 return result;
630}
631EXPORT_SYMBOL_GPL(i2400m_post_reset);
632
633
634/*
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800635 * The device has rebooted; fix up the device and the driver
636 *
637 * Tear down the driver communication with the device, reload the
638 * firmware and reinitialize the communication with the device.
639 *
640 * If someone calls a reset when the device's firmware is down, in
641 * theory we won't see it because we are not listening. However, just
642 * in case, leave the code to handle it.
643 *
644 * If there is a reset context, use it; this means someone is waiting
645 * for us to tell him when the reset operation is complete and the
646 * device is ready to rock again.
647 *
648 * NOTE: if we are in the process of bringing up or down the
649 * communication with the device [running i2400m_dev_start() or
650 * _stop()], don't do anything, let it fail and handle it.
651 *
652 * This function is ran always in a thread context
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700653 *
654 * This function gets passed, as payload to i2400m_work() a 'const
655 * char *' ptr with a "reason" why the reset happened (for messages).
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800656 */
657static
658void __i2400m_dev_reset_handle(struct work_struct *ws)
659{
660 int result;
661 struct i2400m_work *iw = container_of(ws, struct i2400m_work, ws);
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700662 const char *reason;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800663 struct i2400m *i2400m = iw->i2400m;
664 struct device *dev = i2400m_dev(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800665 struct i2400m_reset_ctx *ctx = i2400m->reset_ctx;
666
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700667 if (WARN_ON(iw->pl_size != sizeof(reason)))
668 reason = "SW BUG: reason n/a";
669 else
670 memcpy(&reason, iw->pl, sizeof(reason));
671
672 d_fnstart(3, dev, "(ws %p i2400m %p reason %s)\n", ws, i2400m, reason);
673
Cindy H Kaof4e41342010-04-07 19:42:42 -0700674 i2400m->boot_mode = 1;
675 wmb(); /* Make sure i2400m_msg_to_dev() sees boot_mode */
676
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800677 result = 0;
678 if (mutex_trylock(&i2400m->init_mutex) == 0) {
679 /* We are still in i2400m_dev_start() [let it fail] or
680 * i2400m_dev_stop() [we are shutting down anyway, so
681 * ignore it] or we are resetting somewhere else. */
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700682 dev_err(dev, "device rebooted somewhere else?\n");
Cindy H Kao0bcfc5e2009-06-10 17:06:19 -0700683 i2400m_msg_to_dev_cancel_wait(i2400m, -EL3RST);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800684 complete(&i2400m->msg_completion);
685 goto out;
686 }
Cindy H Kaof4e41342010-04-07 19:42:42 -0700687
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700688 dev_err(dev, "%s: reinitializing driver\n", reason);
Cindy H Kaof4e41342010-04-07 19:42:42 -0700689 rmb();
690 if (i2400m->updown) {
691 __i2400m_dev_stop(i2400m);
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700692 i2400m->updown = 0;
693 wmb(); /* see i2400m->updown's documentation */
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700694 }
Cindy H Kaof4e41342010-04-07 19:42:42 -0700695
696 if (i2400m->alive) {
697 result = __i2400m_dev_start(i2400m,
698 I2400M_BRI_SOFT | I2400M_BRI_MAC_REINIT);
699 if (result < 0) {
700 dev_err(dev, "%s: cannot start the device: %d\n",
701 reason, result);
702 result = -EUCLEAN;
703 if (atomic_read(&i2400m->bus_reset_retries)
704 >= I2400M_BUS_RESET_RETRIES) {
705 result = -ENODEV;
706 dev_err(dev, "tried too many times to "
707 "reset the device, giving up\n");
708 }
709 }
710 }
711
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800712 if (i2400m->reset_ctx) {
713 ctx->result = result;
714 complete(&ctx->completion);
715 }
716 mutex_unlock(&i2400m->init_mutex);
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900717 if (result == -EUCLEAN) {
Cindy H Kaof4e41342010-04-07 19:42:42 -0700718 /*
719 * We come here because the reset during operational mode
720 * wasn't successully done and need to proceed to a bus
721 * reset. For the dev_reset_handle() to be able to handle
722 * the reset event later properly, we restore boot_mode back
723 * to the state before previous reset. ie: just like we are
724 * issuing the bus reset for the first time
725 */
726 i2400m->boot_mode = 0;
727 wmb();
728
729 atomic_inc(&i2400m->bus_reset_retries);
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900730 /* ops, need to clean up [w/ init_mutex not held] */
Inaky Perez-Gonzalezc931cee2009-10-19 16:24:56 +0900731 result = i2400m_reset(i2400m, I2400M_RT_BUS);
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900732 if (result >= 0)
733 result = -ENODEV;
Cindy H Kaof4e41342010-04-07 19:42:42 -0700734 } else {
735 rmb();
736 if (i2400m->alive) {
737 /* great, we expect the device state up and
738 * dev_start() actually brings the device state up */
739 i2400m->updown = 1;
740 wmb();
741 atomic_set(&i2400m->bus_reset_retries, 0);
742 }
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900743 }
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800744out:
745 i2400m_put(i2400m);
746 kfree(iw);
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700747 d_fnend(3, dev, "(ws %p i2400m %p reason %s) = void\n",
748 ws, i2400m, reason);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800749 return;
750}
751
752
753/**
754 * i2400m_dev_reset_handle - Handle a device's reset in a thread context
755 *
756 * Schedule a device reset handling out on a thread context, so it
757 * is safe to call from atomic context. We can't use the i2400m's
758 * queue as we are going to destroy it and reinitialize it as part of
759 * the driver bringup/bringup process.
760 *
761 * See __i2400m_dev_reset_handle() for details; that takes care of
762 * reinitializing the driver to handle the reset, calling into the
763 * bus-specific functions ops as needed.
764 */
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700765int i2400m_dev_reset_handle(struct i2400m *i2400m, const char *reason)
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800766{
767 return i2400m_schedule_work(i2400m, __i2400m_dev_reset_handle,
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700768 GFP_ATOMIC, &reason, sizeof(reason));
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800769}
770EXPORT_SYMBOL_GPL(i2400m_dev_reset_handle);
771
772
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700773/*
774 * Alloc the command and ack buffers for boot mode
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700775 *
776 * Get the buffers needed to deal with boot mode messages. These
777 * buffers need to be allocated before the sdio recieve irq is setup.
778 */
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700779static
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700780int i2400m_bm_buf_alloc(struct i2400m *i2400m)
781{
782 int result;
783
784 result = -ENOMEM;
785 i2400m->bm_cmd_buf = kzalloc(I2400M_BM_CMD_BUF_SIZE, GFP_KERNEL);
786 if (i2400m->bm_cmd_buf == NULL)
787 goto error_bm_cmd_kzalloc;
788 i2400m->bm_ack_buf = kzalloc(I2400M_BM_ACK_BUF_SIZE, GFP_KERNEL);
789 if (i2400m->bm_ack_buf == NULL)
790 goto error_bm_ack_buf_kzalloc;
791 return 0;
792
793error_bm_ack_buf_kzalloc:
794 kfree(i2400m->bm_cmd_buf);
795error_bm_cmd_kzalloc:
796 return result;
797}
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700798
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700799
800/*
801 * Free boot mode command and ack buffers.
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700802 */
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700803static
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700804void i2400m_bm_buf_free(struct i2400m *i2400m)
805{
806 kfree(i2400m->bm_ack_buf);
807 kfree(i2400m->bm_cmd_buf);
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700808}
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700809
810
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700811/**
Inaky Perez-Gonzalezaf77dfa2009-10-07 21:37:53 +0900812 * i2400m_init - Initialize a 'struct i2400m' from all zeroes
813 *
814 * This is a bus-generic API call.
815 */
816void i2400m_init(struct i2400m *i2400m)
817{
818 wimax_dev_init(&i2400m->wimax_dev);
819
820 i2400m->boot_mode = 1;
821 i2400m->rx_reorder = 1;
822 init_waitqueue_head(&i2400m->state_wq);
823
824 spin_lock_init(&i2400m->tx_lock);
825 i2400m->tx_pl_min = UINT_MAX;
826 i2400m->tx_size_min = UINT_MAX;
827
828 spin_lock_init(&i2400m->rx_lock);
829 i2400m->rx_pl_min = UINT_MAX;
830 i2400m->rx_size_min = UINT_MAX;
Inaky Perez-Gonzaleza0beba22009-10-07 21:43:10 +0900831 INIT_LIST_HEAD(&i2400m->rx_reports);
832 INIT_WORK(&i2400m->rx_report_ws, i2400m_report_hook_work);
Inaky Perez-Gonzalezaf77dfa2009-10-07 21:37:53 +0900833
834 mutex_init(&i2400m->msg_mutex);
835 init_completion(&i2400m->msg_completion);
836
837 mutex_init(&i2400m->init_mutex);
838 /* wake_tx_ws is initialized in i2400m_tx_setup() */
Cindy H Kaof4e41342010-04-07 19:42:42 -0700839 atomic_set(&i2400m->bus_reset_retries, 0);
840
841 i2400m->alive = 0;
Inaky Perez-Gonzalezaf77dfa2009-10-07 21:37:53 +0900842}
843EXPORT_SYMBOL_GPL(i2400m_init);
844
845
Inaky Perez-Gonzalezc931cee2009-10-19 16:24:56 +0900846int i2400m_reset(struct i2400m *i2400m, enum i2400m_reset_type rt)
847{
848 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
849
850 /*
851 * Make sure we stop TXs and down the carrier before
852 * resetting; this is needed to avoid things like
853 * i2400m_wake_tx() scheduling stuff in parallel.
854 */
855 if (net_dev->reg_state == NETREG_REGISTERED) {
856 netif_tx_disable(net_dev);
857 netif_carrier_off(net_dev);
858 }
859 return i2400m->bus_reset(i2400m, rt);
860}
861EXPORT_SYMBOL_GPL(i2400m_reset);
862
863
Inaky Perez-Gonzalezaf77dfa2009-10-07 21:37:53 +0900864/**
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800865 * i2400m_setup - bus-generic setup function for the i2400m device
866 *
867 * @i2400m: device descriptor (bus-specific parts have been initialized)
868 *
869 * Returns: 0 if ok, < 0 errno code on error.
870 *
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700871 * Sets up basic device comunication infrastructure, boots the ROM to
872 * read the MAC address, registers with the WiMAX and network stacks
873 * and then brings up the device.
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800874 */
875int i2400m_setup(struct i2400m *i2400m, enum i2400m_bri bm_flags)
876{
877 int result = -ENODEV;
878 struct device *dev = i2400m_dev(i2400m);
879 struct wimax_dev *wimax_dev = &i2400m->wimax_dev;
880 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
881
882 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
883
884 snprintf(wimax_dev->name, sizeof(wimax_dev->name),
Kay Sievers347707b2009-02-28 23:42:51 +0000885 "i2400m-%s:%s", dev->bus->name, dev_name(dev));
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800886
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700887 result = i2400m_bm_buf_alloc(i2400m);
888 if (result < 0) {
889 dev_err(dev, "cannot allocate bootmode scratch buffers\n");
890 goto error_bm_buf_alloc;
891 }
892
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700893 if (i2400m->bus_setup) {
894 result = i2400m->bus_setup(i2400m);
895 if (result < 0) {
896 dev_err(dev, "bus-specific setup failed: %d\n",
897 result);
898 goto error_bus_setup;
899 }
900 }
901
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800902 result = i2400m_bootrom_init(i2400m, bm_flags);
903 if (result < 0) {
904 dev_err(dev, "read mac addr: bootrom init "
905 "failed: %d\n", result);
906 goto error_bootrom_init;
907 }
908 result = i2400m_read_mac_addr(i2400m);
909 if (result < 0)
910 goto error_read_mac_addr;
Inaky Perez-Gonzalezfe442682009-04-22 16:53:08 -0700911 random_ether_addr(i2400m->src_mac_addr);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800912
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -0700913 i2400m->pm_notifier.notifier_call = i2400m_pm_notifier;
914 register_pm_notifier(&i2400m->pm_notifier);
915
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800916 result = register_netdev(net_dev); /* Okey dokey, bring it up */
917 if (result < 0) {
918 dev_err(dev, "cannot register i2400m network device: %d\n",
919 result);
920 goto error_register_netdev;
921 }
922 netif_carrier_off(net_dev);
923
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800924 i2400m->wimax_dev.op_msg_from_user = i2400m_op_msg_from_user;
925 i2400m->wimax_dev.op_rfkill_sw_toggle = i2400m_op_rfkill_sw_toggle;
926 i2400m->wimax_dev.op_reset = i2400m_op_reset;
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700927
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800928 result = wimax_dev_add(&i2400m->wimax_dev, net_dev);
929 if (result < 0)
930 goto error_wimax_dev_add;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800931
932 /* Now setup all that requires a registered net and wimax device. */
Inaky Perez-Gonzalez89876912009-02-28 23:42:50 +0000933 result = sysfs_create_group(&net_dev->dev.kobj, &i2400m_dev_attr_group);
934 if (result < 0) {
935 dev_err(dev, "cannot setup i2400m's sysfs: %d\n", result);
936 goto error_sysfs_setup;
937 }
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700938
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800939 result = i2400m_debugfs_add(i2400m);
940 if (result < 0) {
941 dev_err(dev, "cannot setup i2400m's debugfs: %d\n", result);
942 goto error_debugfs_setup;
943 }
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700944
945 result = i2400m_dev_start(i2400m, bm_flags);
946 if (result < 0)
947 goto error_dev_start;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800948 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
949 return result;
950
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700951error_dev_start:
952 i2400m_debugfs_rm(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800953error_debugfs_setup:
Inaky Perez-Gonzalez89876912009-02-28 23:42:50 +0000954 sysfs_remove_group(&i2400m->wimax_dev.net_dev->dev.kobj,
955 &i2400m_dev_attr_group);
956error_sysfs_setup:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800957 wimax_dev_rm(&i2400m->wimax_dev);
958error_wimax_dev_add:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800959 unregister_netdev(net_dev);
960error_register_netdev:
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -0700961 unregister_pm_notifier(&i2400m->pm_notifier);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800962error_read_mac_addr:
963error_bootrom_init:
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700964 if (i2400m->bus_release)
965 i2400m->bus_release(i2400m);
966error_bus_setup:
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700967 i2400m_bm_buf_free(i2400m);
968error_bm_buf_alloc:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800969 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
970 return result;
971}
972EXPORT_SYMBOL_GPL(i2400m_setup);
973
974
975/**
976 * i2400m_release - release the bus-generic driver resources
977 *
978 * Sends a disconnect message and undoes any setup done by i2400m_setup()
979 */
980void i2400m_release(struct i2400m *i2400m)
981{
982 struct device *dev = i2400m_dev(i2400m);
983
984 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
985 netif_stop_queue(i2400m->wimax_dev.net_dev);
986
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700987 i2400m_dev_stop(i2400m);
988
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800989 i2400m_debugfs_rm(i2400m);
Inaky Perez-Gonzalez89876912009-02-28 23:42:50 +0000990 sysfs_remove_group(&i2400m->wimax_dev.net_dev->dev.kobj,
991 &i2400m_dev_attr_group);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800992 wimax_dev_rm(&i2400m->wimax_dev);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800993 unregister_netdev(i2400m->wimax_dev.net_dev);
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -0700994 unregister_pm_notifier(&i2400m->pm_notifier);
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700995 if (i2400m->bus_release)
996 i2400m->bus_release(i2400m);
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700997 i2400m_bm_buf_free(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800998 d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
999}
1000EXPORT_SYMBOL_GPL(i2400m_release);
1001
1002
Inaky Perez-Gonzalez1af7ad52009-01-29 17:18:31 -08001003/*
1004 * Debug levels control; see debug.h
1005 */
1006struct d_level D_LEVEL[] = {
1007 D_SUBMODULE_DEFINE(control),
1008 D_SUBMODULE_DEFINE(driver),
1009 D_SUBMODULE_DEFINE(debugfs),
1010 D_SUBMODULE_DEFINE(fw),
1011 D_SUBMODULE_DEFINE(netdev),
1012 D_SUBMODULE_DEFINE(rfkill),
1013 D_SUBMODULE_DEFINE(rx),
Inaky Perez-Gonzalez4dc1bf02009-09-02 15:31:48 -07001014 D_SUBMODULE_DEFINE(sysfs),
Inaky Perez-Gonzalez1af7ad52009-01-29 17:18:31 -08001015 D_SUBMODULE_DEFINE(tx),
1016};
1017size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL);
1018
1019
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001020static
1021int __init i2400m_driver_init(void)
1022{
Inaky Perez-Gonzalez4c2b1a12009-09-02 15:36:05 -07001023 d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400m_debug_params,
1024 "i2400m.debug");
Inaky Perez-Gonzalezaba3792a2009-09-03 15:14:29 -07001025 return i2400m_barker_db_init(i2400m_barkers_params);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001026}
1027module_init(i2400m_driver_init);
1028
1029static
1030void __exit i2400m_driver_exit(void)
1031{
1032 /* for scheds i2400m_dev_reset_handle() */
1033 flush_scheduled_work();
Inaky Perez-Gonzalezaba3792a2009-09-03 15:14:29 -07001034 i2400m_barker_db_exit();
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001035 return;
1036}
1037module_exit(i2400m_driver_exit);
1038
1039MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>");
1040MODULE_DESCRIPTION("Intel 2400M WiMAX networking bus-generic driver");
1041MODULE_LICENSE("GPL");