blob: 9c34d2fccfac61508705a4021f436e9a9024e936 [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
Inaky Perez-Gonzalez4c2b1a12009-09-02 15:36:05 -070078static char i2400m_debug_params[128];
79module_param_string(debug, i2400m_debug_params, sizeof(i2400m_debug_params),
80 0644);
81MODULE_PARM_DESC(debug,
82 "String of space-separated NAME:VALUE pairs, where NAMEs "
83 "are the different debug submodules and VALUE are the "
84 "initial debug value to set.");
85
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -070086static char i2400m_barkers_params[128];
87module_param_string(barkers, i2400m_barkers_params,
88 sizeof(i2400m_barkers_params), 0644);
89MODULE_PARM_DESC(barkers,
90 "String of comma-separated 32-bit values; each is "
91 "recognized as the value the device sends as a reboot "
92 "signal; values are appended to a list--setting one value "
93 "as zero cleans the existing list and starts a new one.");
94
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -080095/*
96 * WiMAX stack operation: relay a message from user space
97 *
98 * @wimax_dev: device descriptor
99 * @pipe_name: named pipe the message is for
100 * @msg_buf: pointer to the message bytes
101 * @msg_len: length of the buffer
102 * @genl_info: passed by the generic netlink layer
103 *
104 * The WiMAX stack will call this function when a message was received
105 * from user space.
106 *
107 * For the i2400m, this is an L3L4 message, as specified in
108 * include/linux/wimax/i2400m.h, and thus prefixed with a 'struct
109 * i2400m_l3l4_hdr'. Driver (and device) expect the messages to be
110 * coded in Little Endian.
111 *
112 * This function just verifies that the header declaration and the
113 * payload are consistent and then deals with it, either forwarding it
114 * to the device or procesing it locally.
115 *
116 * In the i2400m, messages are basically commands that will carry an
117 * ack, so we use i2400m_msg_to_dev() and then deliver the ack back to
118 * user space. The rx.c code might intercept the response and use it
119 * to update the driver's state, but then it will pass it on so it can
120 * be relayed back to user space.
121 *
122 * Note that asynchronous events from the device are processed and
123 * sent to user space in rx.c.
124 */
125static
126int i2400m_op_msg_from_user(struct wimax_dev *wimax_dev,
127 const char *pipe_name,
128 const void *msg_buf, size_t msg_len,
129 const struct genl_info *genl_info)
130{
131 int result;
132 struct i2400m *i2400m = wimax_dev_to_i2400m(wimax_dev);
133 struct device *dev = i2400m_dev(i2400m);
134 struct sk_buff *ack_skb;
135
136 d_fnstart(4, dev, "(wimax_dev %p [i2400m %p] msg_buf %p "
137 "msg_len %zu genl_info %p)\n", wimax_dev, i2400m,
138 msg_buf, msg_len, genl_info);
139 ack_skb = i2400m_msg_to_dev(i2400m, msg_buf, msg_len);
140 result = PTR_ERR(ack_skb);
141 if (IS_ERR(ack_skb))
142 goto error_msg_to_dev;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800143 result = wimax_msg_send(&i2400m->wimax_dev, ack_skb);
144error_msg_to_dev:
145 d_fnend(4, dev, "(wimax_dev %p [i2400m %p] msg_buf %p msg_len %zu "
146 "genl_info %p) = %d\n", wimax_dev, i2400m, msg_buf, msg_len,
147 genl_info, result);
148 return result;
149}
150
151
152/*
153 * Context to wait for a reset to finalize
154 */
155struct i2400m_reset_ctx {
156 struct completion completion;
157 int result;
158};
159
160
161/*
162 * WiMAX stack operation: reset a device
163 *
164 * @wimax_dev: device descriptor
165 *
166 * See the documentation for wimax_reset() and wimax_dev->op_reset for
167 * the requirements of this function. The WiMAX stack guarantees
168 * serialization on calls to this function.
169 *
170 * Do a warm reset on the device; if it fails, resort to a cold reset
171 * and return -ENODEV. On successful warm reset, we need to block
172 * until it is complete.
173 *
174 * The bus-driver implementation of reset takes care of falling back
175 * to cold reset if warm fails.
176 */
177static
178int i2400m_op_reset(struct wimax_dev *wimax_dev)
179{
180 int result;
181 struct i2400m *i2400m = wimax_dev_to_i2400m(wimax_dev);
182 struct device *dev = i2400m_dev(i2400m);
183 struct i2400m_reset_ctx ctx = {
184 .completion = COMPLETION_INITIALIZER_ONSTACK(ctx.completion),
185 .result = 0,
186 };
187
188 d_fnstart(4, dev, "(wimax_dev %p)\n", wimax_dev);
189 mutex_lock(&i2400m->init_mutex);
190 i2400m->reset_ctx = &ctx;
191 mutex_unlock(&i2400m->init_mutex);
Inaky Perez-Gonzalezc931cee2009-10-19 16:24:56 +0900192 result = i2400m_reset(i2400m, I2400M_RT_WARM);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800193 if (result < 0)
194 goto out;
195 result = wait_for_completion_timeout(&ctx.completion, 4*HZ);
196 if (result == 0)
197 result = -ETIMEDOUT;
198 else if (result > 0)
199 result = ctx.result;
200 /* if result < 0, pass it on */
201 mutex_lock(&i2400m->init_mutex);
202 i2400m->reset_ctx = NULL;
203 mutex_unlock(&i2400m->init_mutex);
204out:
205 d_fnend(4, dev, "(wimax_dev %p) = %d\n", wimax_dev, result);
206 return result;
207}
208
209
210/*
211 * Check the MAC address we got from boot mode is ok
212 *
213 * @i2400m: device descriptor
214 *
215 * Returns: 0 if ok, < 0 errno code on error.
216 */
217static
218int i2400m_check_mac_addr(struct i2400m *i2400m)
219{
220 int result;
221 struct device *dev = i2400m_dev(i2400m);
222 struct sk_buff *skb;
223 const struct i2400m_tlv_detailed_device_info *ddi;
224 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800225
226 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
227 skb = i2400m_get_device_info(i2400m);
228 if (IS_ERR(skb)) {
229 result = PTR_ERR(skb);
230 dev_err(dev, "Cannot verify MAC address, error reading: %d\n",
231 result);
232 goto error;
233 }
Uwe Kleine-Königb5950762010-11-01 15:38:34 -0400234 /* Extract MAC address */
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800235 ddi = (void *) skb->data;
236 BUILD_BUG_ON(ETH_ALEN != sizeof(ddi->mac_address));
hartleys4754b3d2010-01-05 07:00:57 +0000237 d_printf(2, dev, "GET DEVICE INFO: mac addr %pM\n",
238 ddi->mac_address);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800239 if (!memcmp(net_dev->perm_addr, ddi->mac_address,
240 sizeof(ddi->mac_address)))
241 goto ok;
242 dev_warn(dev, "warning: device reports a different MAC address "
243 "to that of boot mode's\n");
hartleys4754b3d2010-01-05 07:00:57 +0000244 dev_warn(dev, "device reports %pM\n", ddi->mac_address);
245 dev_warn(dev, "boot mode reported %pM\n", net_dev->perm_addr);
Wei Yongjun9213bb82012-08-22 20:49:33 +0000246 if (is_zero_ether_addr(ddi->mac_address))
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800247 dev_err(dev, "device reports an invalid MAC address, "
248 "not updating\n");
249 else {
250 dev_warn(dev, "updating MAC address\n");
251 net_dev->addr_len = ETH_ALEN;
252 memcpy(net_dev->perm_addr, ddi->mac_address, ETH_ALEN);
253 memcpy(net_dev->dev_addr, ddi->mac_address, ETH_ALEN);
254 }
255ok:
256 result = 0;
257 kfree_skb(skb);
258error:
259 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
260 return result;
261}
262
263
264/**
265 * __i2400m_dev_start - Bring up driver communication with the device
266 *
267 * @i2400m: device descriptor
268 * @flags: boot mode flags
269 *
270 * Returns: 0 if ok, < 0 errno code on error.
271 *
272 * Uploads firmware and brings up all the resources needed to be able
273 * to communicate with the device.
274 *
Inaky Perez-Gonzaleze9a6b452009-05-08 13:02:41 -0700275 * The workqueue has to be setup early, at least before RX handling
276 * (it's only real user for now) so it can process reports as they
277 * arrive. We also want to destroy it if we retry, to make sure it is
278 * flushed...easier like this.
279 *
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800280 * TX needs to be setup before the bus-specific code (otherwise on
281 * shutdown, the bus-tx code could try to access it).
282 */
283static
284int __i2400m_dev_start(struct i2400m *i2400m, enum i2400m_bri flags)
285{
286 int result;
287 struct wimax_dev *wimax_dev = &i2400m->wimax_dev;
288 struct net_device *net_dev = wimax_dev->net_dev;
289 struct device *dev = i2400m_dev(i2400m);
Inaky Perez-Gonzalezecddfd52009-06-03 16:13:14 +0800290 int times = i2400m->bus_bm_retries;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800291
292 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
293retry:
294 result = i2400m_dev_bootstrap(i2400m, flags);
295 if (result < 0) {
296 dev_err(dev, "cannot bootstrap device: %d\n", result);
297 goto error_bootstrap;
298 }
299 result = i2400m_tx_setup(i2400m);
300 if (result < 0)
301 goto error_tx_setup;
Inaky Perez-Gonzalezc7475832009-02-28 23:42:54 +0000302 result = i2400m_rx_setup(i2400m);
303 if (result < 0)
304 goto error_rx_setup;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800305 i2400m->work_queue = create_singlethread_workqueue(wimax_dev->name);
306 if (i2400m->work_queue == NULL) {
307 result = -ENOMEM;
308 dev_err(dev, "cannot create workqueue\n");
309 goto error_create_workqueue;
310 }
Inaky Perez-Gonzalez097acbe2009-10-08 12:33:50 +0900311 if (i2400m->bus_dev_start) {
312 result = i2400m->bus_dev_start(i2400m);
313 if (result < 0)
314 goto error_bus_dev_start;
315 }
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700316 i2400m->ready = 1;
317 wmb(); /* see i2400m->ready's documentation */
Inaky Perez-Gonzaleza0beba22009-10-07 21:43:10 +0900318 /* process pending reports from the device */
319 queue_work(i2400m->work_queue, &i2400m->rx_report_ws);
Inaky Perez-Gonzalez6a0f7ab2009-02-28 23:42:49 +0000320 result = i2400m_firmware_check(i2400m); /* fw versions ok? */
321 if (result < 0)
322 goto error_fw_check;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800323 /* At this point is ok to send commands to the device */
324 result = i2400m_check_mac_addr(i2400m);
325 if (result < 0)
326 goto error_check_mac_addr;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800327 result = i2400m_dev_initialize(i2400m);
328 if (result < 0)
329 goto error_dev_initialize;
Cindy H Kao599e5952010-04-07 20:07:47 -0700330
331 /* We don't want any additional unwanted error recovery triggered
332 * from any other context so if anything went wrong before we come
333 * here, let's keep i2400m->error_recovery untouched and leave it to
334 * dev_reset_handle(). See dev_reset_handle(). */
335
336 atomic_dec(&i2400m->error_recovery);
337 /* Every thing works so far, ok, now we are ready to
338 * take error recovery if it's required. */
339
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800340 /* At this point, reports will come for the device and set it
341 * to the right state if it is different than UNINITIALIZED */
342 d_fnend(3, dev, "(net_dev %p [i2400m %p]) = %d\n",
343 net_dev, i2400m, result);
344 return result;
345
346error_dev_initialize:
347error_check_mac_addr:
Cindy H Kao49d72df32010-03-30 19:19:37 -0700348error_fw_check:
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700349 i2400m->ready = 0;
350 wmb(); /* see i2400m->ready's documentation */
351 flush_workqueue(i2400m->work_queue);
Inaky Perez-Gonzalez097acbe2009-10-08 12:33:50 +0900352 if (i2400m->bus_dev_stop)
353 i2400m->bus_dev_stop(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800354error_bus_dev_start:
Inaky Perez-Gonzaleze9a6b452009-05-08 13:02:41 -0700355 destroy_workqueue(i2400m->work_queue);
356error_create_workqueue:
Inaky Perez-Gonzalezc7475832009-02-28 23:42:54 +0000357 i2400m_rx_release(i2400m);
358error_rx_setup:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800359 i2400m_tx_release(i2400m);
360error_tx_setup:
361error_bootstrap:
Cindy H Kao0bcfc5e2009-06-10 17:06:19 -0700362 if (result == -EL3RST && times-- > 0) {
Cindy H Kao8b5b30ee2009-06-10 16:52:10 -0700363 flags = I2400M_BRI_SOFT|I2400M_BRI_MAC_REINIT;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800364 goto retry;
365 }
366 d_fnend(3, dev, "(net_dev %p [i2400m %p]) = %d\n",
367 net_dev, i2400m, result);
368 return result;
369}
370
371
372static
373int i2400m_dev_start(struct i2400m *i2400m, enum i2400m_bri bm_flags)
374{
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700375 int result = 0;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800376 mutex_lock(&i2400m->init_mutex); /* Well, start the device */
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700377 if (i2400m->updown == 0) {
378 result = __i2400m_dev_start(i2400m, bm_flags);
379 if (result >= 0) {
380 i2400m->updown = 1;
Cindy H Kaof4e41342010-04-07 19:42:42 -0700381 i2400m->alive = 1;
382 wmb();/* see i2400m->updown and i2400m->alive's doc */
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700383 }
384 }
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800385 mutex_unlock(&i2400m->init_mutex);
386 return result;
387}
388
389
390/**
391 * i2400m_dev_stop - Tear down driver communication with the device
392 *
393 * @i2400m: device descriptor
394 *
395 * Returns: 0 if ok, < 0 errno code on error.
396 *
Inaky Perez-Gonzaleze9a6b452009-05-08 13:02:41 -0700397 * Releases all the resources allocated to communicate with the
398 * device. Note we cannot destroy the workqueue earlier as until RX is
399 * fully destroyed, it could still try to schedule jobs.
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800400 */
401static
402void __i2400m_dev_stop(struct i2400m *i2400m)
403{
404 struct wimax_dev *wimax_dev = &i2400m->wimax_dev;
405 struct device *dev = i2400m_dev(i2400m);
406
407 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
408 wimax_state_change(wimax_dev, __WIMAX_ST_QUIESCING);
Inaky Perez-Gonzalez5eeae352009-10-07 12:20:15 +0900409 i2400m_msg_to_dev_cancel_wait(i2400m, -EL3RST);
410 complete(&i2400m->msg_completion);
Inaky Perez-Gonzalezac53aed2009-09-16 16:30:39 -0700411 i2400m_net_wake_stop(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800412 i2400m_dev_shutdown(i2400m);
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700413 /*
414 * Make sure no report hooks are running *before* we stop the
415 * communication infrastructure with the device.
416 */
417 i2400m->ready = 0; /* nobody can queue work anymore */
418 wmb(); /* see i2400m->ready's documentation */
419 flush_workqueue(i2400m->work_queue);
420
Inaky Perez-Gonzalez097acbe2009-10-08 12:33:50 +0900421 if (i2400m->bus_dev_stop)
422 i2400m->bus_dev_stop(i2400m);
Inaky Perez-Gonzaleze9a6b452009-05-08 13:02:41 -0700423 destroy_workqueue(i2400m->work_queue);
Inaky Perez-Gonzalezc7475832009-02-28 23:42:54 +0000424 i2400m_rx_release(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800425 i2400m_tx_release(i2400m);
426 wimax_state_change(wimax_dev, WIMAX_ST_DOWN);
427 d_fnend(3, dev, "(i2400m %p) = 0\n", i2400m);
428}
429
430
431/*
432 * Watch out -- we only need to stop if there is a need for it. The
433 * device could have reset itself and failed to come up again (see
434 * _i2400m_dev_reset_handle()).
435 */
436static
437void i2400m_dev_stop(struct i2400m *i2400m)
438{
439 mutex_lock(&i2400m->init_mutex);
440 if (i2400m->updown) {
441 __i2400m_dev_stop(i2400m);
442 i2400m->updown = 0;
Cindy H Kaof4e41342010-04-07 19:42:42 -0700443 i2400m->alive = 0;
444 wmb(); /* see i2400m->updown and i2400m->alive's doc */
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800445 }
446 mutex_unlock(&i2400m->init_mutex);
447}
448
449
450/*
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -0700451 * Listen to PM events to cache the firmware before suspend/hibernation
452 *
453 * When the device comes out of suspend, it might go into reset and
454 * firmware has to be uploaded again. At resume, most of the times, we
455 * can't load firmware images from disk, so we need to cache it.
456 *
457 * i2400m_fw_cache() will allocate a kobject and attach the firmware
458 * to it; that way we don't have to worry too much about the fw loader
459 * hitting a race condition.
460 *
461 * Note: modus operandi stolen from the Orinoco driver; thx.
462 */
463static
464int i2400m_pm_notifier(struct notifier_block *notifier,
465 unsigned long pm_event,
466 void *unused)
467{
468 struct i2400m *i2400m =
469 container_of(notifier, struct i2400m, pm_notifier);
470 struct device *dev = i2400m_dev(i2400m);
471
472 d_fnstart(3, dev, "(i2400m %p pm_event %lx)\n", i2400m, pm_event);
473 switch (pm_event) {
474 case PM_HIBERNATION_PREPARE:
475 case PM_SUSPEND_PREPARE:
476 i2400m_fw_cache(i2400m);
477 break;
478 case PM_POST_RESTORE:
479 /* Restore from hibernation failed. We need to clean
480 * up in exactly the same way, so fall through. */
481 case PM_POST_HIBERNATION:
482 case PM_POST_SUSPEND:
483 i2400m_fw_uncache(i2400m);
484 break;
485
486 case PM_RESTORE_PREPARE:
487 default:
488 break;
489 }
490 d_fnend(3, dev, "(i2400m %p pm_event %lx) = void\n", i2400m, pm_event);
491 return NOTIFY_DONE;
492}
493
494
495/*
Inaky Perez-Gonzalez3725d8c2009-09-17 15:20:45 -0700496 * pre-reset is called before a device is going on reset
497 *
498 * This has to be followed by a call to i2400m_post_reset(), otherwise
499 * bad things might happen.
500 */
501int i2400m_pre_reset(struct i2400m *i2400m)
502{
503 int result;
504 struct device *dev = i2400m_dev(i2400m);
505
506 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
507 d_printf(1, dev, "pre-reset shut down\n");
508
509 result = 0;
510 mutex_lock(&i2400m->init_mutex);
511 if (i2400m->updown) {
512 netif_tx_disable(i2400m->wimax_dev.net_dev);
513 __i2400m_dev_stop(i2400m);
514 result = 0;
515 /* down't set updown to zero -- this way
516 * post_reset can restore properly */
517 }
518 mutex_unlock(&i2400m->init_mutex);
519 if (i2400m->bus_release)
520 i2400m->bus_release(i2400m);
521 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
522 return result;
523}
524EXPORT_SYMBOL_GPL(i2400m_pre_reset);
525
526
527/*
528 * Restore device state after a reset
529 *
530 * Do the work needed after a device reset to bring it up to the same
531 * state as it was before the reset.
532 *
533 * NOTE: this requires i2400m->init_mutex taken
534 */
535int i2400m_post_reset(struct i2400m *i2400m)
536{
537 int result = 0;
538 struct device *dev = i2400m_dev(i2400m);
539
540 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
541 d_printf(1, dev, "post-reset start\n");
542 if (i2400m->bus_setup) {
543 result = i2400m->bus_setup(i2400m);
544 if (result < 0) {
545 dev_err(dev, "bus-specific setup failed: %d\n",
546 result);
547 goto error_bus_setup;
548 }
549 }
550 mutex_lock(&i2400m->init_mutex);
551 if (i2400m->updown) {
552 result = __i2400m_dev_start(
553 i2400m, I2400M_BRI_SOFT | I2400M_BRI_MAC_REINIT);
554 if (result < 0)
555 goto error_dev_start;
556 }
557 mutex_unlock(&i2400m->init_mutex);
558 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
559 return result;
560
561error_dev_start:
562 if (i2400m->bus_release)
563 i2400m->bus_release(i2400m);
Inaky Perez-Gonzalez3725d8c2009-09-17 15:20:45 -0700564 /* even if the device was up, it could not be recovered, so we
565 * mark it as down. */
566 i2400m->updown = 0;
567 wmb(); /* see i2400m->updown's documentation */
568 mutex_unlock(&i2400m->init_mutex);
Cindy H Kao23541612010-04-08 16:03:12 -0700569error_bus_setup:
Inaky Perez-Gonzalez3725d8c2009-09-17 15:20:45 -0700570 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
571 return result;
572}
573EXPORT_SYMBOL_GPL(i2400m_post_reset);
574
575
576/*
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800577 * The device has rebooted; fix up the device and the driver
578 *
579 * Tear down the driver communication with the device, reload the
580 * firmware and reinitialize the communication with the device.
581 *
582 * If someone calls a reset when the device's firmware is down, in
583 * theory we won't see it because we are not listening. However, just
584 * in case, leave the code to handle it.
585 *
586 * If there is a reset context, use it; this means someone is waiting
587 * for us to tell him when the reset operation is complete and the
588 * device is ready to rock again.
589 *
590 * NOTE: if we are in the process of bringing up or down the
591 * communication with the device [running i2400m_dev_start() or
592 * _stop()], don't do anything, let it fail and handle it.
593 *
594 * This function is ran always in a thread context
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700595 *
596 * This function gets passed, as payload to i2400m_work() a 'const
597 * char *' ptr with a "reason" why the reset happened (for messages).
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800598 */
599static
600void __i2400m_dev_reset_handle(struct work_struct *ws)
601{
Tejun Heo781ba452010-12-12 16:45:14 +0100602 struct i2400m *i2400m = container_of(ws, struct i2400m, reset_ws);
603 const char *reason = i2400m->reset_reason;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800604 struct device *dev = i2400m_dev(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800605 struct i2400m_reset_ctx *ctx = i2400m->reset_ctx;
Tejun Heo781ba452010-12-12 16:45:14 +0100606 int result;
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700607
608 d_fnstart(3, dev, "(ws %p i2400m %p reason %s)\n", ws, i2400m, reason);
609
Cindy H Kaof4e41342010-04-07 19:42:42 -0700610 i2400m->boot_mode = 1;
611 wmb(); /* Make sure i2400m_msg_to_dev() sees boot_mode */
612
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800613 result = 0;
614 if (mutex_trylock(&i2400m->init_mutex) == 0) {
615 /* We are still in i2400m_dev_start() [let it fail] or
616 * i2400m_dev_stop() [we are shutting down anyway, so
617 * ignore it] or we are resetting somewhere else. */
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700618 dev_err(dev, "device rebooted somewhere else?\n");
Cindy H Kao0bcfc5e2009-06-10 17:06:19 -0700619 i2400m_msg_to_dev_cancel_wait(i2400m, -EL3RST);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800620 complete(&i2400m->msg_completion);
621 goto out;
622 }
Cindy H Kaof4e41342010-04-07 19:42:42 -0700623
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700624 dev_err(dev, "%s: reinitializing driver\n", reason);
Cindy H Kaof4e41342010-04-07 19:42:42 -0700625 rmb();
626 if (i2400m->updown) {
627 __i2400m_dev_stop(i2400m);
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700628 i2400m->updown = 0;
629 wmb(); /* see i2400m->updown's documentation */
Inaky Perez-Gonzalezc2315b42009-09-16 17:10:55 -0700630 }
Cindy H Kaof4e41342010-04-07 19:42:42 -0700631
632 if (i2400m->alive) {
633 result = __i2400m_dev_start(i2400m,
634 I2400M_BRI_SOFT | I2400M_BRI_MAC_REINIT);
635 if (result < 0) {
636 dev_err(dev, "%s: cannot start the device: %d\n",
637 reason, result);
638 result = -EUCLEAN;
639 if (atomic_read(&i2400m->bus_reset_retries)
640 >= I2400M_BUS_RESET_RETRIES) {
641 result = -ENODEV;
642 dev_err(dev, "tried too many times to "
643 "reset the device, giving up\n");
644 }
645 }
646 }
647
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800648 if (i2400m->reset_ctx) {
649 ctx->result = result;
650 complete(&ctx->completion);
651 }
652 mutex_unlock(&i2400m->init_mutex);
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900653 if (result == -EUCLEAN) {
Cindy H Kaof4e41342010-04-07 19:42:42 -0700654 /*
655 * We come here because the reset during operational mode
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300656 * wasn't successfully done and need to proceed to a bus
Cindy H Kaof4e41342010-04-07 19:42:42 -0700657 * reset. For the dev_reset_handle() to be able to handle
658 * the reset event later properly, we restore boot_mode back
659 * to the state before previous reset. ie: just like we are
660 * issuing the bus reset for the first time
661 */
662 i2400m->boot_mode = 0;
663 wmb();
664
665 atomic_inc(&i2400m->bus_reset_retries);
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900666 /* ops, need to clean up [w/ init_mutex not held] */
Inaky Perez-Gonzalezc931cee2009-10-19 16:24:56 +0900667 result = i2400m_reset(i2400m, I2400M_RT_BUS);
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900668 if (result >= 0)
669 result = -ENODEV;
Cindy H Kaof4e41342010-04-07 19:42:42 -0700670 } else {
671 rmb();
672 if (i2400m->alive) {
673 /* great, we expect the device state up and
674 * dev_start() actually brings the device state up */
675 i2400m->updown = 1;
676 wmb();
677 atomic_set(&i2400m->bus_reset_retries, 0);
678 }
Inaky Perez-Gonzalezb9ee9502009-10-07 12:34:13 +0900679 }
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800680out:
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700681 d_fnend(3, dev, "(ws %p i2400m %p reason %s) = void\n",
682 ws, i2400m, reason);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800683}
684
685
686/**
687 * i2400m_dev_reset_handle - Handle a device's reset in a thread context
688 *
689 * Schedule a device reset handling out on a thread context, so it
690 * is safe to call from atomic context. We can't use the i2400m's
691 * queue as we are going to destroy it and reinitialize it as part of
692 * the driver bringup/bringup process.
693 *
694 * See __i2400m_dev_reset_handle() for details; that takes care of
695 * reinitializing the driver to handle the reset, calling into the
696 * bus-specific functions ops as needed.
697 */
Inaky Perez-Gonzalez3ef61292009-09-14 14:05:19 -0700698int i2400m_dev_reset_handle(struct i2400m *i2400m, const char *reason)
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800699{
Tejun Heo781ba452010-12-12 16:45:14 +0100700 i2400m->reset_reason = reason;
701 return schedule_work(&i2400m->reset_ws);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800702}
703EXPORT_SYMBOL_GPL(i2400m_dev_reset_handle);
704
705
Cindy H Kao599e5952010-04-07 20:07:47 -0700706 /*
707 * The actual work of error recovery.
708 *
709 * The current implementation of error recovery is to trigger a bus reset.
710 */
711static
712void __i2400m_error_recovery(struct work_struct *ws)
713{
Tejun Heo781ba452010-12-12 16:45:14 +0100714 struct i2400m *i2400m = container_of(ws, struct i2400m, recovery_ws);
Cindy H Kao599e5952010-04-07 20:07:47 -0700715
716 i2400m_reset(i2400m, I2400M_RT_BUS);
Cindy H Kao599e5952010-04-07 20:07:47 -0700717}
718
719/*
720 * Schedule a work struct for error recovery.
721 *
722 * The intention of error recovery is to bring back the device to some
723 * known state whenever TX sees -110 (-ETIMEOUT) on copying the data to
724 * the device. The TX failure could mean a device bus stuck, so the current
725 * error recovery implementation is to trigger a bus reset to the device
726 * and hopefully it can bring back the device.
727 *
728 * The actual work of error recovery has to be in a thread context because
729 * it is kicked off in the TX thread (i2400ms->tx_workqueue) which is to be
730 * destroyed by the error recovery mechanism (currently a bus reset).
731 *
732 * Also, there may be already a queue of TX works that all hit
733 * the -ETIMEOUT error condition because the device is stuck already.
734 * Since bus reset is used as the error recovery mechanism and we don't
735 * want consecutive bus resets simply because the multiple TX works
736 * in the queue all hit the same device erratum, the flag "error_recovery"
737 * is introduced for preventing unwanted consecutive bus resets.
738 *
739 * Error recovery shall only be invoked again if previous one was completed.
740 * The flag error_recovery is set when error recovery mechanism is scheduled,
741 * and is checked when we need to schedule another error recovery. If it is
742 * in place already, then we shouldn't schedule another one.
743 */
744void i2400m_error_recovery(struct i2400m *i2400m)
745{
Tejun Heo781ba452010-12-12 16:45:14 +0100746 if (atomic_add_return(1, &i2400m->error_recovery) == 1)
747 schedule_work(&i2400m->recovery_ws);
748 else
Cindy H Kao599e5952010-04-07 20:07:47 -0700749 atomic_dec(&i2400m->error_recovery);
Cindy H Kao599e5952010-04-07 20:07:47 -0700750}
751EXPORT_SYMBOL_GPL(i2400m_error_recovery);
752
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700753/*
754 * Alloc the command and ack buffers for boot mode
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700755 *
John W. Linville5da7b2e2012-07-10 16:27:28 -0400756 * Get the buffers needed to deal with boot mode messages.
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700757 */
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700758static
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700759int i2400m_bm_buf_alloc(struct i2400m *i2400m)
760{
761 int result;
762
763 result = -ENOMEM;
764 i2400m->bm_cmd_buf = kzalloc(I2400M_BM_CMD_BUF_SIZE, GFP_KERNEL);
765 if (i2400m->bm_cmd_buf == NULL)
766 goto error_bm_cmd_kzalloc;
767 i2400m->bm_ack_buf = kzalloc(I2400M_BM_ACK_BUF_SIZE, GFP_KERNEL);
768 if (i2400m->bm_ack_buf == NULL)
769 goto error_bm_ack_buf_kzalloc;
770 return 0;
771
772error_bm_ack_buf_kzalloc:
773 kfree(i2400m->bm_cmd_buf);
774error_bm_cmd_kzalloc:
775 return result;
776}
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700777
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700778
779/*
780 * Free boot mode command and ack buffers.
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700781 */
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700782static
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700783void i2400m_bm_buf_free(struct i2400m *i2400m)
784{
785 kfree(i2400m->bm_ack_buf);
786 kfree(i2400m->bm_cmd_buf);
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700787}
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700788
789
Dirk Brandewiea134fd62009-08-18 08:51:52 -0700790/**
Inaky Perez-Gonzalezaf77dfa2009-10-07 21:37:53 +0900791 * i2400m_init - Initialize a 'struct i2400m' from all zeroes
792 *
793 * This is a bus-generic API call.
794 */
795void i2400m_init(struct i2400m *i2400m)
796{
797 wimax_dev_init(&i2400m->wimax_dev);
798
799 i2400m->boot_mode = 1;
800 i2400m->rx_reorder = 1;
801 init_waitqueue_head(&i2400m->state_wq);
802
803 spin_lock_init(&i2400m->tx_lock);
804 i2400m->tx_pl_min = UINT_MAX;
805 i2400m->tx_size_min = UINT_MAX;
806
807 spin_lock_init(&i2400m->rx_lock);
808 i2400m->rx_pl_min = UINT_MAX;
809 i2400m->rx_size_min = UINT_MAX;
Inaky Perez-Gonzaleza0beba22009-10-07 21:43:10 +0900810 INIT_LIST_HEAD(&i2400m->rx_reports);
811 INIT_WORK(&i2400m->rx_report_ws, i2400m_report_hook_work);
Inaky Perez-Gonzalezaf77dfa2009-10-07 21:37:53 +0900812
813 mutex_init(&i2400m->msg_mutex);
814 init_completion(&i2400m->msg_completion);
815
816 mutex_init(&i2400m->init_mutex);
817 /* wake_tx_ws is initialized in i2400m_tx_setup() */
Tejun Heo781ba452010-12-12 16:45:14 +0100818
819 INIT_WORK(&i2400m->reset_ws, __i2400m_dev_reset_handle);
820 INIT_WORK(&i2400m->recovery_ws, __i2400m_error_recovery);
821
Cindy H Kaof4e41342010-04-07 19:42:42 -0700822 atomic_set(&i2400m->bus_reset_retries, 0);
823
824 i2400m->alive = 0;
Cindy H Kao599e5952010-04-07 20:07:47 -0700825
826 /* initialize error_recovery to 1 for denoting we
827 * are not yet ready to take any error recovery */
828 atomic_set(&i2400m->error_recovery, 1);
Inaky Perez-Gonzalezaf77dfa2009-10-07 21:37:53 +0900829}
830EXPORT_SYMBOL_GPL(i2400m_init);
831
832
Inaky Perez-Gonzalezc931cee2009-10-19 16:24:56 +0900833int i2400m_reset(struct i2400m *i2400m, enum i2400m_reset_type rt)
834{
835 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
836
837 /*
838 * Make sure we stop TXs and down the carrier before
839 * resetting; this is needed to avoid things like
840 * i2400m_wake_tx() scheduling stuff in parallel.
841 */
842 if (net_dev->reg_state == NETREG_REGISTERED) {
843 netif_tx_disable(net_dev);
844 netif_carrier_off(net_dev);
845 }
846 return i2400m->bus_reset(i2400m, rt);
847}
848EXPORT_SYMBOL_GPL(i2400m_reset);
849
850
Inaky Perez-Gonzalezaf77dfa2009-10-07 21:37:53 +0900851/**
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800852 * i2400m_setup - bus-generic setup function for the i2400m device
853 *
854 * @i2400m: device descriptor (bus-specific parts have been initialized)
855 *
856 * Returns: 0 if ok, < 0 errno code on error.
857 *
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700858 * Sets up basic device comunication infrastructure, boots the ROM to
859 * read the MAC address, registers with the WiMAX and network stacks
860 * and then brings up the device.
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800861 */
862int i2400m_setup(struct i2400m *i2400m, enum i2400m_bri bm_flags)
863{
864 int result = -ENODEV;
865 struct device *dev = i2400m_dev(i2400m);
866 struct wimax_dev *wimax_dev = &i2400m->wimax_dev;
867 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
868
869 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
870
871 snprintf(wimax_dev->name, sizeof(wimax_dev->name),
Kay Sievers347707b2009-02-28 23:42:51 +0000872 "i2400m-%s:%s", dev->bus->name, dev_name(dev));
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800873
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700874 result = i2400m_bm_buf_alloc(i2400m);
875 if (result < 0) {
876 dev_err(dev, "cannot allocate bootmode scratch buffers\n");
877 goto error_bm_buf_alloc;
878 }
879
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700880 if (i2400m->bus_setup) {
881 result = i2400m->bus_setup(i2400m);
882 if (result < 0) {
883 dev_err(dev, "bus-specific setup failed: %d\n",
884 result);
885 goto error_bus_setup;
886 }
887 }
888
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800889 result = i2400m_bootrom_init(i2400m, bm_flags);
890 if (result < 0) {
891 dev_err(dev, "read mac addr: bootrom init "
892 "failed: %d\n", result);
893 goto error_bootrom_init;
894 }
895 result = i2400m_read_mac_addr(i2400m);
896 if (result < 0)
897 goto error_read_mac_addr;
Joe Perches344dc8e2012-07-12 19:33:09 +0000898 eth_random_addr(i2400m->src_mac_addr);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800899
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -0700900 i2400m->pm_notifier.notifier_call = i2400m_pm_notifier;
901 register_pm_notifier(&i2400m->pm_notifier);
902
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800903 result = register_netdev(net_dev); /* Okey dokey, bring it up */
904 if (result < 0) {
905 dev_err(dev, "cannot register i2400m network device: %d\n",
906 result);
907 goto error_register_netdev;
908 }
909 netif_carrier_off(net_dev);
910
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800911 i2400m->wimax_dev.op_msg_from_user = i2400m_op_msg_from_user;
912 i2400m->wimax_dev.op_rfkill_sw_toggle = i2400m_op_rfkill_sw_toggle;
913 i2400m->wimax_dev.op_reset = i2400m_op_reset;
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700914
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800915 result = wimax_dev_add(&i2400m->wimax_dev, net_dev);
916 if (result < 0)
917 goto error_wimax_dev_add;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800918
919 /* Now setup all that requires a registered net and wimax device. */
Inaky Perez-Gonzalez89876912009-02-28 23:42:50 +0000920 result = sysfs_create_group(&net_dev->dev.kobj, &i2400m_dev_attr_group);
921 if (result < 0) {
922 dev_err(dev, "cannot setup i2400m's sysfs: %d\n", result);
923 goto error_sysfs_setup;
924 }
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700925
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800926 result = i2400m_debugfs_add(i2400m);
927 if (result < 0) {
928 dev_err(dev, "cannot setup i2400m's debugfs: %d\n", result);
929 goto error_debugfs_setup;
930 }
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700931
932 result = i2400m_dev_start(i2400m, bm_flags);
933 if (result < 0)
934 goto error_dev_start;
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800935 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
936 return result;
937
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700938error_dev_start:
939 i2400m_debugfs_rm(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800940error_debugfs_setup:
Inaky Perez-Gonzalez89876912009-02-28 23:42:50 +0000941 sysfs_remove_group(&i2400m->wimax_dev.net_dev->dev.kobj,
942 &i2400m_dev_attr_group);
943error_sysfs_setup:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800944 wimax_dev_rm(&i2400m->wimax_dev);
945error_wimax_dev_add:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800946 unregister_netdev(net_dev);
947error_register_netdev:
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -0700948 unregister_pm_notifier(&i2400m->pm_notifier);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800949error_read_mac_addr:
950error_bootrom_init:
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700951 if (i2400m->bus_release)
952 i2400m->bus_release(i2400m);
953error_bus_setup:
Inaky Perez-Gonzalez2869da82009-09-16 18:33:26 -0700954 i2400m_bm_buf_free(i2400m);
955error_bm_buf_alloc:
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800956 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
957 return result;
958}
959EXPORT_SYMBOL_GPL(i2400m_setup);
960
961
962/**
963 * i2400m_release - release the bus-generic driver resources
964 *
965 * Sends a disconnect message and undoes any setup done by i2400m_setup()
966 */
967void i2400m_release(struct i2400m *i2400m)
968{
969 struct device *dev = i2400m_dev(i2400m);
970
971 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
972 netif_stop_queue(i2400m->wimax_dev.net_dev);
973
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700974 i2400m_dev_stop(i2400m);
975
Tejun Heo781ba452010-12-12 16:45:14 +0100976 cancel_work_sync(&i2400m->reset_ws);
977 cancel_work_sync(&i2400m->recovery_ws);
978
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800979 i2400m_debugfs_rm(i2400m);
Inaky Perez-Gonzalez89876912009-02-28 23:42:50 +0000980 sysfs_remove_group(&i2400m->wimax_dev.net_dev->dev.kobj,
981 &i2400m_dev_attr_group);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800982 wimax_dev_rm(&i2400m->wimax_dev);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800983 unregister_netdev(i2400m->wimax_dev.net_dev);
Inaky Perez-Gonzalez7b43ca72009-09-14 14:10:16 -0700984 unregister_pm_notifier(&i2400m->pm_notifier);
Inaky Perez-Gonzalez0856ccf2009-09-16 18:23:27 -0700985 if (i2400m->bus_release)
986 i2400m->bus_release(i2400m);
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700987 i2400m_bm_buf_free(i2400m);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -0800988 d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
989}
990EXPORT_SYMBOL_GPL(i2400m_release);
991
992
Inaky Perez-Gonzalez1af7ad52009-01-29 17:18:31 -0800993/*
994 * Debug levels control; see debug.h
995 */
996struct d_level D_LEVEL[] = {
997 D_SUBMODULE_DEFINE(control),
998 D_SUBMODULE_DEFINE(driver),
999 D_SUBMODULE_DEFINE(debugfs),
1000 D_SUBMODULE_DEFINE(fw),
1001 D_SUBMODULE_DEFINE(netdev),
1002 D_SUBMODULE_DEFINE(rfkill),
1003 D_SUBMODULE_DEFINE(rx),
Inaky Perez-Gonzalez4dc1bf02009-09-02 15:31:48 -07001004 D_SUBMODULE_DEFINE(sysfs),
Inaky Perez-Gonzalez1af7ad52009-01-29 17:18:31 -08001005 D_SUBMODULE_DEFINE(tx),
1006};
1007size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL);
1008
1009
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001010static
1011int __init i2400m_driver_init(void)
1012{
Inaky Perez-Gonzalez4c2b1a12009-09-02 15:36:05 -07001013 d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400m_debug_params,
1014 "i2400m.debug");
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -07001015 return i2400m_barker_db_init(i2400m_barkers_params);
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001016}
1017module_init(i2400m_driver_init);
1018
1019static
1020void __exit i2400m_driver_exit(void)
1021{
Inaky Perez-Gonzalezaba37922009-09-03 15:14:29 -07001022 i2400m_barker_db_exit();
Inaky Perez-Gonzalez024f7f32008-12-20 16:57:44 -08001023}
1024module_exit(i2400m_driver_exit);
1025
1026MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>");
1027MODULE_DESCRIPTION("Intel 2400M WiMAX networking bus-generic driver");
1028MODULE_LICENSE("GPL");