blob: 39cf96a90d7a9674130f876555a653640aad7db7 [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;
Cindy H Kao599e5952010-04-07 20:07:47 -0700398
399 /* We don't want any additional unwanted error recovery triggered
400 * from any other context so if anything went wrong before we come
401 * here, let's keep i2400m->error_recovery untouched and leave it to
402 * dev_reset_handle(). See dev_reset_handle(). */
403
404 atomic_dec(&i2400m->error_recovery);
405 /* Every thing works so far, ok, now we are ready to
406 * take error recovery if it's required. */
407
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800408 /* At this point, reports will come for the device and set it
409 * to the right state if it is different than UNINITIALIZED */
410 d_fnend(3, dev, "(net_dev %p [i2400m %p]) = %d\n",
411 net_dev, i2400m, result);
412 return result;
413
414error_dev_initialize:
415error_check_mac_addr:
Cindy H Kao49d72df2010-03-30 19:19:37 -0700416error_fw_check:
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700417 i2400m->ready = 0;
418 wmb(); /* see i2400m->ready's documentation */
419 flush_workqueue(i2400m->work_queue);
Inaky Perez-Gonzalez097acbe2009-10-08 12:33:50 +0900420 if (i2400m->bus_dev_stop)
421 i2400m->bus_dev_stop(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800422error_bus_dev_start:
Inaky Perez-Gonzaleze9a6b452009-05-08 13:02:41 -0700423 destroy_workqueue(i2400m->work_queue);
424error_create_workqueue:
Inaky Perez-Gonzalezc7475832009-02-28 23:42:54 +0000425 i2400m_rx_release(i2400m);
426error_rx_setup:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800427 i2400m_tx_release(i2400m);
428error_tx_setup:
429error_bootstrap:
Cindy H Kao0bcfc5e2009-06-10 17:06:19 -0700430 if (result == -EL3RST && times-- > 0) {
Cindy H Kao8b5b30ee2009-06-10 16:52:10 -0700431 flags = I2400M_BRI_SOFT|I2400M_BRI_MAC_REINIT;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800432 goto retry;
433 }
434 d_fnend(3, dev, "(net_dev %p [i2400m %p]) = %d\n",
435 net_dev, i2400m, result);
436 return result;
437}
438
439
440static
441int i2400m_dev_start(struct i2400m *i2400m, enum i2400m_bri bm_flags)
442{
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700443 int result = 0;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800444 mutex_lock(&i2400m->init_mutex); /* Well, start the device */
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700445 if (i2400m->updown == 0) {
446 result = __i2400m_dev_start(i2400m, bm_flags);
447 if (result >= 0) {
448 i2400m->updown = 1;
Cindy H Kaof4e41342010-04-07 19:42:42 -0700449 i2400m->alive = 1;
450 wmb();/* see i2400m->updown and i2400m->alive's doc */
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700451 }
452 }
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800453 mutex_unlock(&i2400m->init_mutex);
454 return result;
455}
456
457
458/**
459 * i2400m_dev_stop - Tear down driver communication with the device
460 *
461 * @i2400m: device descriptor
462 *
463 * Returns: 0 if ok, < 0 errno code on error.
464 *
Inaky Perez-Gonzaleze9a6b452009-05-08 13:02:41 -0700465 * Releases all the resources allocated to communicate with the
466 * device. Note we cannot destroy the workqueue earlier as until RX is
467 * fully destroyed, it could still try to schedule jobs.
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800468 */
469static
470void __i2400m_dev_stop(struct i2400m *i2400m)
471{
472 struct wimax_dev *wimax_dev = &i2400m->wimax_dev;
473 struct device *dev = i2400m_dev(i2400m);
474
475 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
476 wimax_state_change(wimax_dev, __WIMAX_ST_QUIESCING);
Inaky Perez-Gonzalez5eeae352009-10-07 12:20:15 +0900477 i2400m_msg_to_dev_cancel_wait(i2400m, -EL3RST);
478 complete(&i2400m->msg_completion);
Inaky Perez-Gonzalezac53aed2009-09-16 16:30:39 -0700479 i2400m_net_wake_stop(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800480 i2400m_dev_shutdown(i2400m);
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700481 /*
482 * Make sure no report hooks are running *before* we stop the
483 * communication infrastructure with the device.
484 */
485 i2400m->ready = 0; /* nobody can queue work anymore */
486 wmb(); /* see i2400m->ready's documentation */
487 flush_workqueue(i2400m->work_queue);
488
Inaky Perez-Gonzalez097acbe2009-10-08 12:33:50 +0900489 if (i2400m->bus_dev_stop)
490 i2400m->bus_dev_stop(i2400m);
Inaky Perez-Gonzaleze9a6b452009-05-08 13:02:41 -0700491 destroy_workqueue(i2400m->work_queue);
Inaky Perez-Gonzalezc7475832009-02-28 23:42:54 +0000492 i2400m_rx_release(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800493 i2400m_tx_release(i2400m);
494 wimax_state_change(wimax_dev, WIMAX_ST_DOWN);
495 d_fnend(3, dev, "(i2400m %p) = 0\n", i2400m);
496}
497
498
499/*
500 * Watch out -- we only need to stop if there is a need for it. The
501 * device could have reset itself and failed to come up again (see
502 * _i2400m_dev_reset_handle()).
503 */
504static
505void i2400m_dev_stop(struct i2400m *i2400m)
506{
507 mutex_lock(&i2400m->init_mutex);
508 if (i2400m->updown) {
509 __i2400m_dev_stop(i2400m);
510 i2400m->updown = 0;
Cindy H Kaof4e41342010-04-07 19:42:42 -0700511 i2400m->alive = 0;
512 wmb(); /* see i2400m->updown and i2400m->alive's doc */
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800513 }
514 mutex_unlock(&i2400m->init_mutex);
515}
516
517
518/*
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -0700519 * Listen to PM events to cache the firmware before suspend/hibernation
520 *
521 * When the device comes out of suspend, it might go into reset and
522 * firmware has to be uploaded again. At resume, most of the times, we
523 * can't load firmware images from disk, so we need to cache it.
524 *
525 * i2400m_fw_cache() will allocate a kobject and attach the firmware
526 * to it; that way we don't have to worry too much about the fw loader
527 * hitting a race condition.
528 *
529 * Note: modus operandi stolen from the Orinoco driver; thx.
530 */
531static
532int i2400m_pm_notifier(struct notifier_block *notifier,
533 unsigned long pm_event,
534 void *unused)
535{
536 struct i2400m *i2400m =
537 container_of(notifier, struct i2400m, pm_notifier);
538 struct device *dev = i2400m_dev(i2400m);
539
540 d_fnstart(3, dev, "(i2400m %p pm_event %lx)\n", i2400m, pm_event);
541 switch (pm_event) {
542 case PM_HIBERNATION_PREPARE:
543 case PM_SUSPEND_PREPARE:
544 i2400m_fw_cache(i2400m);
545 break;
546 case PM_POST_RESTORE:
547 /* Restore from hibernation failed. We need to clean
548 * up in exactly the same way, so fall through. */
549 case PM_POST_HIBERNATION:
550 case PM_POST_SUSPEND:
551 i2400m_fw_uncache(i2400m);
552 break;
553
554 case PM_RESTORE_PREPARE:
555 default:
556 break;
557 }
558 d_fnend(3, dev, "(i2400m %p pm_event %lx) = void\n", i2400m, pm_event);
559 return NOTIFY_DONE;
560}
561
562
563/*
Inaky Perez-Gonzalez3725d8c2009-09-17 15:20:45 -0700564 * pre-reset is called before a device is going on reset
565 *
566 * This has to be followed by a call to i2400m_post_reset(), otherwise
567 * bad things might happen.
568 */
569int i2400m_pre_reset(struct i2400m *i2400m)
570{
571 int result;
572 struct device *dev = i2400m_dev(i2400m);
573
574 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
575 d_printf(1, dev, "pre-reset shut down\n");
576
577 result = 0;
578 mutex_lock(&i2400m->init_mutex);
579 if (i2400m->updown) {
580 netif_tx_disable(i2400m->wimax_dev.net_dev);
581 __i2400m_dev_stop(i2400m);
582 result = 0;
583 /* down't set updown to zero -- this way
584 * post_reset can restore properly */
585 }
586 mutex_unlock(&i2400m->init_mutex);
587 if (i2400m->bus_release)
588 i2400m->bus_release(i2400m);
589 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
590 return result;
591}
592EXPORT_SYMBOL_GPL(i2400m_pre_reset);
593
594
595/*
596 * Restore device state after a reset
597 *
598 * Do the work needed after a device reset to bring it up to the same
599 * state as it was before the reset.
600 *
601 * NOTE: this requires i2400m->init_mutex taken
602 */
603int i2400m_post_reset(struct i2400m *i2400m)
604{
605 int result = 0;
606 struct device *dev = i2400m_dev(i2400m);
607
608 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
609 d_printf(1, dev, "post-reset start\n");
610 if (i2400m->bus_setup) {
611 result = i2400m->bus_setup(i2400m);
612 if (result < 0) {
613 dev_err(dev, "bus-specific setup failed: %d\n",
614 result);
615 goto error_bus_setup;
616 }
617 }
618 mutex_lock(&i2400m->init_mutex);
619 if (i2400m->updown) {
620 result = __i2400m_dev_start(
621 i2400m, I2400M_BRI_SOFT | I2400M_BRI_MAC_REINIT);
622 if (result < 0)
623 goto error_dev_start;
624 }
625 mutex_unlock(&i2400m->init_mutex);
626 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
627 return result;
628
629error_dev_start:
630 if (i2400m->bus_release)
631 i2400m->bus_release(i2400m);
Inaky Perez-Gonzalez3725d8c2009-09-17 15:20:45 -0700632 /* even if the device was up, it could not be recovered, so we
633 * mark it as down. */
634 i2400m->updown = 0;
635 wmb(); /* see i2400m->updown's documentation */
636 mutex_unlock(&i2400m->init_mutex);
Cindy H Kao23541612010-04-08 16:03:12 -0700637error_bus_setup:
Inaky Perez-Gonzalez3725d8c2009-09-17 15:20:45 -0700638 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
639 return result;
640}
641EXPORT_SYMBOL_GPL(i2400m_post_reset);
642
643
644/*
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800645 * The device has rebooted; fix up the device and the driver
646 *
647 * Tear down the driver communication with the device, reload the
648 * firmware and reinitialize the communication with the device.
649 *
650 * If someone calls a reset when the device's firmware is down, in
651 * theory we won't see it because we are not listening. However, just
652 * in case, leave the code to handle it.
653 *
654 * If there is a reset context, use it; this means someone is waiting
655 * for us to tell him when the reset operation is complete and the
656 * device is ready to rock again.
657 *
658 * NOTE: if we are in the process of bringing up or down the
659 * communication with the device [running i2400m_dev_start() or
660 * _stop()], don't do anything, let it fail and handle it.
661 *
662 * This function is ran always in a thread context
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700663 *
664 * This function gets passed, as payload to i2400m_work() a 'const
665 * char *' ptr with a "reason" why the reset happened (for messages).
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800666 */
667static
668void __i2400m_dev_reset_handle(struct work_struct *ws)
669{
670 int result;
671 struct i2400m_work *iw = container_of(ws, struct i2400m_work, ws);
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700672 const char *reason;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800673 struct i2400m *i2400m = iw->i2400m;
674 struct device *dev = i2400m_dev(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800675 struct i2400m_reset_ctx *ctx = i2400m->reset_ctx;
676
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700677 if (WARN_ON(iw->pl_size != sizeof(reason)))
678 reason = "SW BUG: reason n/a";
679 else
680 memcpy(&reason, iw->pl, sizeof(reason));
681
682 d_fnstart(3, dev, "(ws %p i2400m %p reason %s)\n", ws, i2400m, reason);
683
Cindy H Kaof4e41342010-04-07 19:42:42 -0700684 i2400m->boot_mode = 1;
685 wmb(); /* Make sure i2400m_msg_to_dev() sees boot_mode */
686
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800687 result = 0;
688 if (mutex_trylock(&i2400m->init_mutex) == 0) {
689 /* We are still in i2400m_dev_start() [let it fail] or
690 * i2400m_dev_stop() [we are shutting down anyway, so
691 * ignore it] or we are resetting somewhere else. */
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700692 dev_err(dev, "device rebooted somewhere else?\n");
Cindy H Kao0bcfc5e2009-06-10 17:06:19 -0700693 i2400m_msg_to_dev_cancel_wait(i2400m, -EL3RST);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800694 complete(&i2400m->msg_completion);
695 goto out;
696 }
Cindy H Kaof4e41342010-04-07 19:42:42 -0700697
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700698 dev_err(dev, "%s: reinitializing driver\n", reason);
Cindy H Kaof4e41342010-04-07 19:42:42 -0700699 rmb();
700 if (i2400m->updown) {
701 __i2400m_dev_stop(i2400m);
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700702 i2400m->updown = 0;
703 wmb(); /* see i2400m->updown's documentation */
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700704 }
Cindy H Kaof4e41342010-04-07 19:42:42 -0700705
706 if (i2400m->alive) {
707 result = __i2400m_dev_start(i2400m,
708 I2400M_BRI_SOFT | I2400M_BRI_MAC_REINIT);
709 if (result < 0) {
710 dev_err(dev, "%s: cannot start the device: %d\n",
711 reason, result);
712 result = -EUCLEAN;
713 if (atomic_read(&i2400m->bus_reset_retries)
714 >= I2400M_BUS_RESET_RETRIES) {
715 result = -ENODEV;
716 dev_err(dev, "tried too many times to "
717 "reset the device, giving up\n");
718 }
719 }
720 }
721
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800722 if (i2400m->reset_ctx) {
723 ctx->result = result;
724 complete(&ctx->completion);
725 }
726 mutex_unlock(&i2400m->init_mutex);
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900727 if (result == -EUCLEAN) {
Cindy H Kaof4e41342010-04-07 19:42:42 -0700728 /*
729 * We come here because the reset during operational mode
730 * wasn't successully done and need to proceed to a bus
731 * reset. For the dev_reset_handle() to be able to handle
732 * the reset event later properly, we restore boot_mode back
733 * to the state before previous reset. ie: just like we are
734 * issuing the bus reset for the first time
735 */
736 i2400m->boot_mode = 0;
737 wmb();
738
739 atomic_inc(&i2400m->bus_reset_retries);
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900740 /* ops, need to clean up [w/ init_mutex not held] */
Inaky Perez-Gonzalezc931cee2009-10-19 16:24:56 +0900741 result = i2400m_reset(i2400m, I2400M_RT_BUS);
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900742 if (result >= 0)
743 result = -ENODEV;
Cindy H Kaof4e41342010-04-07 19:42:42 -0700744 } else {
745 rmb();
746 if (i2400m->alive) {
747 /* great, we expect the device state up and
748 * dev_start() actually brings the device state up */
749 i2400m->updown = 1;
750 wmb();
751 atomic_set(&i2400m->bus_reset_retries, 0);
752 }
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900753 }
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800754out:
755 i2400m_put(i2400m);
756 kfree(iw);
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700757 d_fnend(3, dev, "(ws %p i2400m %p reason %s) = void\n",
758 ws, i2400m, reason);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800759 return;
760}
761
762
763/**
764 * i2400m_dev_reset_handle - Handle a device's reset in a thread context
765 *
766 * Schedule a device reset handling out on a thread context, so it
767 * is safe to call from atomic context. We can't use the i2400m's
768 * queue as we are going to destroy it and reinitialize it as part of
769 * the driver bringup/bringup process.
770 *
771 * See __i2400m_dev_reset_handle() for details; that takes care of
772 * reinitializing the driver to handle the reset, calling into the
773 * bus-specific functions ops as needed.
774 */
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700775int i2400m_dev_reset_handle(struct i2400m *i2400m, const char *reason)
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800776{
777 return i2400m_schedule_work(i2400m, __i2400m_dev_reset_handle,
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700778 GFP_ATOMIC, &reason, sizeof(reason));
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800779}
780EXPORT_SYMBOL_GPL(i2400m_dev_reset_handle);
781
782
Cindy H Kao599e5952010-04-07 20:07:47 -0700783 /*
784 * The actual work of error recovery.
785 *
786 * The current implementation of error recovery is to trigger a bus reset.
787 */
788static
789void __i2400m_error_recovery(struct work_struct *ws)
790{
791 struct i2400m_work *iw = container_of(ws, struct i2400m_work, ws);
792 struct i2400m *i2400m = iw->i2400m;
793
794 i2400m_reset(i2400m, I2400M_RT_BUS);
795
796 i2400m_put(i2400m);
797 kfree(iw);
798 return;
799}
800
801/*
802 * Schedule a work struct for error recovery.
803 *
804 * The intention of error recovery is to bring back the device to some
805 * known state whenever TX sees -110 (-ETIMEOUT) on copying the data to
806 * the device. The TX failure could mean a device bus stuck, so the current
807 * error recovery implementation is to trigger a bus reset to the device
808 * and hopefully it can bring back the device.
809 *
810 * The actual work of error recovery has to be in a thread context because
811 * it is kicked off in the TX thread (i2400ms->tx_workqueue) which is to be
812 * destroyed by the error recovery mechanism (currently a bus reset).
813 *
814 * Also, there may be already a queue of TX works that all hit
815 * the -ETIMEOUT error condition because the device is stuck already.
816 * Since bus reset is used as the error recovery mechanism and we don't
817 * want consecutive bus resets simply because the multiple TX works
818 * in the queue all hit the same device erratum, the flag "error_recovery"
819 * is introduced for preventing unwanted consecutive bus resets.
820 *
821 * Error recovery shall only be invoked again if previous one was completed.
822 * The flag error_recovery is set when error recovery mechanism is scheduled,
823 * and is checked when we need to schedule another error recovery. If it is
824 * in place already, then we shouldn't schedule another one.
825 */
826void i2400m_error_recovery(struct i2400m *i2400m)
827{
828 struct device *dev = i2400m_dev(i2400m);
829
830 if (atomic_add_return(1, &i2400m->error_recovery) == 1) {
831 if (i2400m_schedule_work(i2400m, __i2400m_error_recovery,
832 GFP_ATOMIC, NULL, 0) < 0) {
833 dev_err(dev, "run out of memory for "
834 "scheduling an error recovery ?\n");
835 atomic_dec(&i2400m->error_recovery);
836 }
837 } else
838 atomic_dec(&i2400m->error_recovery);
839 return;
840}
841EXPORT_SYMBOL_GPL(i2400m_error_recovery);
842
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700843/*
844 * Alloc the command and ack buffers for boot mode
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700845 *
846 * Get the buffers needed to deal with boot mode messages. These
847 * buffers need to be allocated before the sdio recieve irq is setup.
848 */
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700849static
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700850int i2400m_bm_buf_alloc(struct i2400m *i2400m)
851{
852 int result;
853
854 result = -ENOMEM;
855 i2400m->bm_cmd_buf = kzalloc(I2400M_BM_CMD_BUF_SIZE, GFP_KERNEL);
856 if (i2400m->bm_cmd_buf == NULL)
857 goto error_bm_cmd_kzalloc;
858 i2400m->bm_ack_buf = kzalloc(I2400M_BM_ACK_BUF_SIZE, GFP_KERNEL);
859 if (i2400m->bm_ack_buf == NULL)
860 goto error_bm_ack_buf_kzalloc;
861 return 0;
862
863error_bm_ack_buf_kzalloc:
864 kfree(i2400m->bm_cmd_buf);
865error_bm_cmd_kzalloc:
866 return result;
867}
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700868
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700869
870/*
871 * Free boot mode command and ack buffers.
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700872 */
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700873static
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700874void i2400m_bm_buf_free(struct i2400m *i2400m)
875{
876 kfree(i2400m->bm_ack_buf);
877 kfree(i2400m->bm_cmd_buf);
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700878}
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700879
880
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700881/**
Inaky Perez-Gonzalezaf77dfa2009-10-07 21:37:53 +0900882 * i2400m_init - Initialize a 'struct i2400m' from all zeroes
883 *
884 * This is a bus-generic API call.
885 */
886void i2400m_init(struct i2400m *i2400m)
887{
888 wimax_dev_init(&i2400m->wimax_dev);
889
890 i2400m->boot_mode = 1;
891 i2400m->rx_reorder = 1;
892 init_waitqueue_head(&i2400m->state_wq);
893
894 spin_lock_init(&i2400m->tx_lock);
895 i2400m->tx_pl_min = UINT_MAX;
896 i2400m->tx_size_min = UINT_MAX;
897
898 spin_lock_init(&i2400m->rx_lock);
899 i2400m->rx_pl_min = UINT_MAX;
900 i2400m->rx_size_min = UINT_MAX;
Inaky Perez-Gonzaleza0beba22009-10-07 21:43:10 +0900901 INIT_LIST_HEAD(&i2400m->rx_reports);
902 INIT_WORK(&i2400m->rx_report_ws, i2400m_report_hook_work);
Inaky Perez-Gonzalezaf77dfa2009-10-07 21:37:53 +0900903
904 mutex_init(&i2400m->msg_mutex);
905 init_completion(&i2400m->msg_completion);
906
907 mutex_init(&i2400m->init_mutex);
908 /* wake_tx_ws is initialized in i2400m_tx_setup() */
Cindy H Kaof4e41342010-04-07 19:42:42 -0700909 atomic_set(&i2400m->bus_reset_retries, 0);
910
911 i2400m->alive = 0;
Cindy H Kao599e5952010-04-07 20:07:47 -0700912
913 /* initialize error_recovery to 1 for denoting we
914 * are not yet ready to take any error recovery */
915 atomic_set(&i2400m->error_recovery, 1);
Inaky Perez-Gonzalezaf77dfa2009-10-07 21:37:53 +0900916}
917EXPORT_SYMBOL_GPL(i2400m_init);
918
919
Inaky Perez-Gonzalezc931cee2009-10-19 16:24:56 +0900920int i2400m_reset(struct i2400m *i2400m, enum i2400m_reset_type rt)
921{
922 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
923
924 /*
925 * Make sure we stop TXs and down the carrier before
926 * resetting; this is needed to avoid things like
927 * i2400m_wake_tx() scheduling stuff in parallel.
928 */
929 if (net_dev->reg_state == NETREG_REGISTERED) {
930 netif_tx_disable(net_dev);
931 netif_carrier_off(net_dev);
932 }
933 return i2400m->bus_reset(i2400m, rt);
934}
935EXPORT_SYMBOL_GPL(i2400m_reset);
936
937
Inaky Perez-Gonzalezaf77dfa2009-10-07 21:37:53 +0900938/**
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800939 * i2400m_setup - bus-generic setup function for the i2400m device
940 *
941 * @i2400m: device descriptor (bus-specific parts have been initialized)
942 *
943 * Returns: 0 if ok, < 0 errno code on error.
944 *
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700945 * Sets up basic device comunication infrastructure, boots the ROM to
946 * read the MAC address, registers with the WiMAX and network stacks
947 * and then brings up the device.
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800948 */
949int i2400m_setup(struct i2400m *i2400m, enum i2400m_bri bm_flags)
950{
951 int result = -ENODEV;
952 struct device *dev = i2400m_dev(i2400m);
953 struct wimax_dev *wimax_dev = &i2400m->wimax_dev;
954 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
955
956 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
957
958 snprintf(wimax_dev->name, sizeof(wimax_dev->name),
Kay Sievers347707b2009-02-28 23:42:51 +0000959 "i2400m-%s:%s", dev->bus->name, dev_name(dev));
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800960
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700961 result = i2400m_bm_buf_alloc(i2400m);
962 if (result < 0) {
963 dev_err(dev, "cannot allocate bootmode scratch buffers\n");
964 goto error_bm_buf_alloc;
965 }
966
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700967 if (i2400m->bus_setup) {
968 result = i2400m->bus_setup(i2400m);
969 if (result < 0) {
970 dev_err(dev, "bus-specific setup failed: %d\n",
971 result);
972 goto error_bus_setup;
973 }
974 }
975
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800976 result = i2400m_bootrom_init(i2400m, bm_flags);
977 if (result < 0) {
978 dev_err(dev, "read mac addr: bootrom init "
979 "failed: %d\n", result);
980 goto error_bootrom_init;
981 }
982 result = i2400m_read_mac_addr(i2400m);
983 if (result < 0)
984 goto error_read_mac_addr;
Inaky Perez-Gonzalezfe442682009-04-22 16:53:08 -0700985 random_ether_addr(i2400m->src_mac_addr);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800986
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -0700987 i2400m->pm_notifier.notifier_call = i2400m_pm_notifier;
988 register_pm_notifier(&i2400m->pm_notifier);
989
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800990 result = register_netdev(net_dev); /* Okey dokey, bring it up */
991 if (result < 0) {
992 dev_err(dev, "cannot register i2400m network device: %d\n",
993 result);
994 goto error_register_netdev;
995 }
996 netif_carrier_off(net_dev);
997
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800998 i2400m->wimax_dev.op_msg_from_user = i2400m_op_msg_from_user;
999 i2400m->wimax_dev.op_rfkill_sw_toggle = i2400m_op_rfkill_sw_toggle;
1000 i2400m->wimax_dev.op_reset = i2400m_op_reset;
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -07001001
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001002 result = wimax_dev_add(&i2400m->wimax_dev, net_dev);
1003 if (result < 0)
1004 goto error_wimax_dev_add;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001005
1006 /* Now setup all that requires a registered net and wimax device. */
Inaky Perez-Gonzalez89876912009-02-28 23:42:50 +00001007 result = sysfs_create_group(&net_dev->dev.kobj, &i2400m_dev_attr_group);
1008 if (result < 0) {
1009 dev_err(dev, "cannot setup i2400m's sysfs: %d\n", result);
1010 goto error_sysfs_setup;
1011 }
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -07001012
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001013 result = i2400m_debugfs_add(i2400m);
1014 if (result < 0) {
1015 dev_err(dev, "cannot setup i2400m's debugfs: %d\n", result);
1016 goto error_debugfs_setup;
1017 }
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -07001018
1019 result = i2400m_dev_start(i2400m, bm_flags);
1020 if (result < 0)
1021 goto error_dev_start;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001022 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
1023 return result;
1024
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -07001025error_dev_start:
1026 i2400m_debugfs_rm(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001027error_debugfs_setup:
Inaky Perez-Gonzalez89876912009-02-28 23:42:50 +00001028 sysfs_remove_group(&i2400m->wimax_dev.net_dev->dev.kobj,
1029 &i2400m_dev_attr_group);
1030error_sysfs_setup:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001031 wimax_dev_rm(&i2400m->wimax_dev);
1032error_wimax_dev_add:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001033 unregister_netdev(net_dev);
1034error_register_netdev:
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -07001035 unregister_pm_notifier(&i2400m->pm_notifier);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001036error_read_mac_addr:
1037error_bootrom_init:
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -07001038 if (i2400m->bus_release)
1039 i2400m->bus_release(i2400m);
1040error_bus_setup:
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -07001041 i2400m_bm_buf_free(i2400m);
1042error_bm_buf_alloc:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001043 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
1044 return result;
1045}
1046EXPORT_SYMBOL_GPL(i2400m_setup);
1047
1048
1049/**
1050 * i2400m_release - release the bus-generic driver resources
1051 *
1052 * Sends a disconnect message and undoes any setup done by i2400m_setup()
1053 */
1054void i2400m_release(struct i2400m *i2400m)
1055{
1056 struct device *dev = i2400m_dev(i2400m);
1057
1058 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
1059 netif_stop_queue(i2400m->wimax_dev.net_dev);
1060
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -07001061 i2400m_dev_stop(i2400m);
1062
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001063 i2400m_debugfs_rm(i2400m);
Inaky Perez-Gonzalez89876912009-02-28 23:42:50 +00001064 sysfs_remove_group(&i2400m->wimax_dev.net_dev->dev.kobj,
1065 &i2400m_dev_attr_group);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001066 wimax_dev_rm(&i2400m->wimax_dev);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001067 unregister_netdev(i2400m->wimax_dev.net_dev);
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -07001068 unregister_pm_notifier(&i2400m->pm_notifier);
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -07001069 if (i2400m->bus_release)
1070 i2400m->bus_release(i2400m);
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -07001071 i2400m_bm_buf_free(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001072 d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
1073}
1074EXPORT_SYMBOL_GPL(i2400m_release);
1075
1076
Inaky Perez-Gonzalez1af7ad52009-01-29 17:18:31 -08001077/*
1078 * Debug levels control; see debug.h
1079 */
1080struct d_level D_LEVEL[] = {
1081 D_SUBMODULE_DEFINE(control),
1082 D_SUBMODULE_DEFINE(driver),
1083 D_SUBMODULE_DEFINE(debugfs),
1084 D_SUBMODULE_DEFINE(fw),
1085 D_SUBMODULE_DEFINE(netdev),
1086 D_SUBMODULE_DEFINE(rfkill),
1087 D_SUBMODULE_DEFINE(rx),
Inaky Perez-Gonzalez4dc1bf02009-09-02 15:31:48 -07001088 D_SUBMODULE_DEFINE(sysfs),
Inaky Perez-Gonzalez1af7ad52009-01-29 17:18:31 -08001089 D_SUBMODULE_DEFINE(tx),
1090};
1091size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL);
1092
1093
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001094static
1095int __init i2400m_driver_init(void)
1096{
Inaky Perez-Gonzalez4c2b1a12009-09-02 15:36:05 -07001097 d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400m_debug_params,
1098 "i2400m.debug");
Inaky Perez-Gonzalezaba3792a2009-09-03 15:14:29 -07001099 return i2400m_barker_db_init(i2400m_barkers_params);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001100}
1101module_init(i2400m_driver_init);
1102
1103static
1104void __exit i2400m_driver_exit(void)
1105{
1106 /* for scheds i2400m_dev_reset_handle() */
1107 flush_scheduled_work();
Inaky Perez-Gonzalezaba3792a2009-09-03 15:14:29 -07001108 i2400m_barker_db_exit();
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001109 return;
1110}
1111module_exit(i2400m_driver_exit);
1112
1113MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>");
1114MODULE_DESCRIPTION("Intel 2400M WiMAX networking bus-generic driver");
1115MODULE_LICENSE("GPL");