1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51#include <linux/slab.h>
52#include <linux/debugfs.h>
53#include <linux/mmc/sdio_ids.h>
54#include <linux/mmc/sdio.h>
55#include <linux/mmc/sdio_func.h>
56#include "i2400m-sdio.h"
57#include <linux/wimax/i2400m.h>
58
59#define D_SUBMODULE main
60#include "sdio-debug-levels.h"
61
62
63static int ioe_timeout = 2;
64module_param(ioe_timeout, int, 0);
65
66static char i2400ms_debug_params[128];
67module_param_string(debug, i2400ms_debug_params, sizeof(i2400ms_debug_params),
68 0644);
69MODULE_PARM_DESC(debug,
70 "String of space-separated NAME:VALUE pairs, where NAMEs "
71 "are the different debug submodules and VALUE are the "
72 "initial debug value to set.");
73
74
75static const char *i2400ms_bus_fw_names[] = {
76#define I2400MS_FW_FILE_NAME "i2400m-fw-sdio-1.3.sbcf"
77 I2400MS_FW_FILE_NAME,
78 NULL
79};
80
81
82static const struct i2400m_poke_table i2400ms_pokes[] = {
83 I2400M_FW_POKE(0x6BE260, 0x00000088),
84 I2400M_FW_POKE(0x080550, 0x00000005),
85 I2400M_FW_POKE(0xAE0000, 0x00000000),
86 I2400M_FW_POKE(0x000000, 0x00000000),
87
88};
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108static
109int i2400ms_enable_function(struct i2400ms *i2400ms, unsigned maxtries)
110{
111 struct sdio_func *func = i2400ms->func;
112 u64 timeout;
113 int err;
114 struct device *dev = &func->dev;
115 unsigned tries = 0;
116
117 d_fnstart(3, dev, "(func %p)\n", func);
118
119
120
121 timeout = get_jiffies_64() + ioe_timeout * HZ;
122 err = -ENODEV;
123 while (err != 0 && time_before64(get_jiffies_64(), timeout)) {
124 sdio_claim_host(func);
125
126
127
128
129
130
131 if (i2400ms->iwmc3200)
132 func->enable_timeout = IWMC3200_IOR_TIMEOUT;
133 err = sdio_enable_func(func);
134 if (0 == err) {
135 sdio_release_host(func);
136 d_printf(2, dev, "SDIO function enabled\n");
137 goto function_enabled;
138 }
139 d_printf(2, dev, "SDIO function failed to enable: %d\n", err);
140 sdio_release_host(func);
141 if (maxtries > 0 && ++tries >= maxtries) {
142 err = -ETIME;
143 break;
144 }
145 msleep(I2400MS_INIT_SLEEP_INTERVAL);
146 }
147
148
149 if (err == -ETIME) {
150 dev_err(dev, "Can't enable WiMAX function; "
151 " has the function been enabled?\n");
152 err = -ENODEV;
153 }
154function_enabled:
155 d_fnend(3, dev, "(func %p) = %d\n", func, err);
156 return err;
157}
158
159
160
161
162
163
164
165
166
167
168static
169int i2400ms_bus_setup(struct i2400m *i2400m)
170{
171 int result;
172 struct i2400ms *i2400ms =
173 container_of(i2400m, struct i2400ms, i2400m);
174 struct device *dev = i2400m_dev(i2400m);
175 struct sdio_func *func = i2400ms->func;
176 int retries;
177
178 sdio_claim_host(func);
179 result = sdio_set_block_size(func, I2400MS_BLK_SIZE);
180 sdio_release_host(func);
181 if (result < 0) {
182 dev_err(dev, "Failed to set block size: %d\n", result);
183 goto error_set_blk_size;
184 }
185
186 if (i2400ms->iwmc3200 && i2400ms->debugfs_dentry == NULL)
187 retries = 1;
188 else
189 retries = 0;
190 result = i2400ms_enable_function(i2400ms, retries);
191 if (result < 0) {
192 dev_err(dev, "Cannot enable SDIO function: %d\n", result);
193 goto error_func_enable;
194 }
195
196 result = i2400ms_tx_setup(i2400ms);
197 if (result < 0)
198 goto error_tx_setup;
199 result = i2400ms_rx_setup(i2400ms);
200 if (result < 0)
201 goto error_rx_setup;
202 return 0;
203
204error_rx_setup:
205 i2400ms_tx_release(i2400ms);
206error_tx_setup:
207 sdio_claim_host(func);
208 sdio_disable_func(func);
209 sdio_release_host(func);
210error_func_enable:
211error_set_blk_size:
212 return result;
213}
214
215
216
217
218
219
220static
221void i2400ms_bus_release(struct i2400m *i2400m)
222{
223 struct i2400ms *i2400ms =
224 container_of(i2400m, struct i2400ms, i2400m);
225 struct sdio_func *func = i2400ms->func;
226
227 i2400ms_rx_release(i2400ms);
228 i2400ms_tx_release(i2400ms);
229 sdio_claim_host(func);
230 sdio_disable_func(func);
231 sdio_release_host(func);
232}
233
234
235
236
237
238
239
240
241
242
243static
244int i2400ms_bus_dev_start(struct i2400m *i2400m)
245{
246 struct i2400ms *i2400ms = container_of(i2400m, struct i2400ms, i2400m);
247 struct sdio_func *func = i2400ms->func;
248 struct device *dev = &func->dev;
249
250 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
251 msleep(200);
252 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, 0);
253 return 0;
254}
255
256
257
258
259
260
261
262
263
264
265
266static
267int __i2400ms_send_barker(struct i2400ms *i2400ms,
268 const __le32 *barker, size_t barker_size)
269{
270 int ret;
271 struct sdio_func *func = i2400ms->func;
272 struct device *dev = &func->dev;
273 void *buffer;
274
275 ret = -ENOMEM;
276 buffer = kmalloc(I2400MS_BLK_SIZE, GFP_KERNEL);
277 if (buffer == NULL)
278 goto error_kzalloc;
279
280 memcpy(buffer, barker, barker_size);
281 sdio_claim_host(func);
282 ret = sdio_memcpy_toio(func, 0, buffer, I2400MS_BLK_SIZE);
283 sdio_release_host(func);
284
285 if (ret < 0)
286 d_printf(0, dev, "E: barker error: %d\n", ret);
287
288 kfree(buffer);
289error_kzalloc:
290 return ret;
291}
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328static
329int i2400ms_bus_reset(struct i2400m *i2400m, enum i2400m_reset_type rt)
330{
331 int result = 0;
332 struct i2400ms *i2400ms =
333 container_of(i2400m, struct i2400ms, i2400m);
334 struct device *dev = i2400m_dev(i2400m);
335 static const __le32 i2400m_WARM_BOOT_BARKER[4] = {
336 cpu_to_le32(I2400M_WARM_RESET_BARKER),
337 cpu_to_le32(I2400M_WARM_RESET_BARKER),
338 cpu_to_le32(I2400M_WARM_RESET_BARKER),
339 cpu_to_le32(I2400M_WARM_RESET_BARKER),
340 };
341 static const __le32 i2400m_COLD_BOOT_BARKER[4] = {
342 cpu_to_le32(I2400M_COLD_RESET_BARKER),
343 cpu_to_le32(I2400M_COLD_RESET_BARKER),
344 cpu_to_le32(I2400M_COLD_RESET_BARKER),
345 cpu_to_le32(I2400M_COLD_RESET_BARKER),
346 };
347
348 if (rt == I2400M_RT_WARM)
349 result = __i2400ms_send_barker(i2400ms, i2400m_WARM_BOOT_BARKER,
350 sizeof(i2400m_WARM_BOOT_BARKER));
351 else if (rt == I2400M_RT_COLD)
352 result = __i2400ms_send_barker(i2400ms, i2400m_COLD_BOOT_BARKER,
353 sizeof(i2400m_COLD_BOOT_BARKER));
354 else if (rt == I2400M_RT_BUS) {
355do_bus_reset:
356
357 i2400ms_bus_release(i2400m);
358
359
360 msleep(40);
361
362 result = i2400ms_bus_setup(i2400m);
363 } else
364 BUG();
365 if (result < 0 && rt != I2400M_RT_BUS) {
366 dev_err(dev, "%s reset failed (%d); trying SDIO reset\n",
367 rt == I2400M_RT_WARM ? "warm" : "cold", result);
368 rt = I2400M_RT_BUS;
369 goto do_bus_reset;
370 }
371 return result;
372}
373
374
375static
376void i2400ms_netdev_setup(struct net_device *net_dev)
377{
378 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
379 struct i2400ms *i2400ms = container_of(i2400m, struct i2400ms, i2400m);
380 i2400ms_init(i2400ms);
381 i2400m_netdev_setup(net_dev);
382}
383
384
385
386
387
388struct d_level D_LEVEL[] = {
389 D_SUBMODULE_DEFINE(main),
390 D_SUBMODULE_DEFINE(tx),
391 D_SUBMODULE_DEFINE(rx),
392 D_SUBMODULE_DEFINE(fw),
393};
394size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL);
395
396
397#define __debugfs_register(prefix, name, parent) \
398do { \
399 result = d_level_register_debugfs(prefix, name, parent); \
400 if (result < 0) \
401 goto error; \
402} while (0)
403
404
405static
406int i2400ms_debugfs_add(struct i2400ms *i2400ms)
407{
408 int result;
409 struct dentry *dentry = i2400ms->i2400m.wimax_dev.debugfs_dentry;
410
411 dentry = debugfs_create_dir("i2400m-sdio", dentry);
412 result = PTR_ERR(dentry);
413 if (IS_ERR(dentry)) {
414 if (result == -ENODEV)
415 result = 0;
416 goto error;
417 }
418 i2400ms->debugfs_dentry = dentry;
419 __debugfs_register("dl_", main, dentry);
420 __debugfs_register("dl_", tx, dentry);
421 __debugfs_register("dl_", rx, dentry);
422 __debugfs_register("dl_", fw, dentry);
423
424 return 0;
425
426error:
427 debugfs_remove_recursive(i2400ms->debugfs_dentry);
428 i2400ms->debugfs_dentry = NULL;
429 return result;
430}
431
432
433static struct device_type i2400ms_type = {
434 .name = "wimax",
435};
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459static
460int i2400ms_probe(struct sdio_func *func,
461 const struct sdio_device_id *id)
462{
463 int result;
464 struct net_device *net_dev;
465 struct device *dev = &func->dev;
466 struct i2400m *i2400m;
467 struct i2400ms *i2400ms;
468
469
470 result = -ENOMEM;
471 net_dev = alloc_netdev(sizeof(*i2400ms), "wmx%d",
472 i2400ms_netdev_setup);
473 if (net_dev == NULL) {
474 dev_err(dev, "no memory for network device instance\n");
475 goto error_alloc_netdev;
476 }
477 SET_NETDEV_DEV(net_dev, dev);
478 SET_NETDEV_DEVTYPE(net_dev, &i2400ms_type);
479 i2400m = net_dev_to_i2400m(net_dev);
480 i2400ms = container_of(i2400m, struct i2400ms, i2400m);
481 i2400m->wimax_dev.net_dev = net_dev;
482 i2400ms->func = func;
483 sdio_set_drvdata(func, i2400ms);
484
485 i2400m->bus_tx_block_size = I2400MS_BLK_SIZE;
486
487
488
489
490
491
492 i2400m->bus_tx_room_min = I2400MS_BLK_SIZE - I2400M_PL_ALIGN * 2;
493 i2400m->bus_pl_size_max = I2400MS_PL_SIZE_MAX;
494 i2400m->bus_setup = i2400ms_bus_setup;
495 i2400m->bus_dev_start = i2400ms_bus_dev_start;
496 i2400m->bus_dev_stop = NULL;
497 i2400m->bus_release = i2400ms_bus_release;
498 i2400m->bus_tx_kick = i2400ms_bus_tx_kick;
499 i2400m->bus_reset = i2400ms_bus_reset;
500
501
502 i2400m->bus_bm_retries = I2400M_SDIO_BOOT_RETRIES;
503 i2400m->bus_bm_cmd_send = i2400ms_bus_bm_cmd_send;
504 i2400m->bus_bm_wait_for_ack = i2400ms_bus_bm_wait_for_ack;
505 i2400m->bus_fw_names = i2400ms_bus_fw_names;
506 i2400m->bus_bm_mac_addr_impaired = 1;
507 i2400m->bus_bm_pokes_table = &i2400ms_pokes[0];
508
509 switch (func->device) {
510 case SDIO_DEVICE_ID_INTEL_IWMC3200WIMAX:
511 case SDIO_DEVICE_ID_INTEL_IWMC3200WIMAX_2G5:
512 i2400ms->iwmc3200 = 1;
513 break;
514 default:
515 i2400ms->iwmc3200 = 0;
516 }
517
518 result = i2400m_setup(i2400m, I2400M_BRI_NO_REBOOT);
519 if (result < 0) {
520 dev_err(dev, "cannot setup device: %d\n", result);
521 goto error_setup;
522 }
523
524 result = i2400ms_debugfs_add(i2400ms);
525 if (result < 0) {
526 dev_err(dev, "cannot create SDIO debugfs: %d\n",
527 result);
528 goto error_debugfs_add;
529 }
530 return 0;
531
532error_debugfs_add:
533 i2400m_release(i2400m);
534error_setup:
535 sdio_set_drvdata(func, NULL);
536 free_netdev(net_dev);
537error_alloc_netdev:
538 return result;
539}
540
541
542static
543void i2400ms_remove(struct sdio_func *func)
544{
545 struct device *dev = &func->dev;
546 struct i2400ms *i2400ms = sdio_get_drvdata(func);
547 struct i2400m *i2400m = &i2400ms->i2400m;
548 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
549
550 d_fnstart(3, dev, "SDIO func %p\n", func);
551 debugfs_remove_recursive(i2400ms->debugfs_dentry);
552 i2400ms->debugfs_dentry = NULL;
553 i2400m_release(i2400m);
554 sdio_set_drvdata(func, NULL);
555 free_netdev(net_dev);
556 d_fnend(3, dev, "SDIO func %p\n", func);
557}
558
559static
560const struct sdio_device_id i2400ms_sdio_ids[] = {
561
562 { SDIO_DEVICE(SDIO_VENDOR_ID_INTEL,
563 SDIO_DEVICE_ID_INTEL_IWMC3200WIMAX) },
564 { SDIO_DEVICE(SDIO_VENDOR_ID_INTEL,
565 SDIO_DEVICE_ID_INTEL_IWMC3200WIMAX_2G5) },
566 { },
567};
568MODULE_DEVICE_TABLE(sdio, i2400ms_sdio_ids);
569
570
571static
572struct sdio_driver i2400m_sdio_driver = {
573 .name = KBUILD_MODNAME,
574 .probe = i2400ms_probe,
575 .remove = i2400ms_remove,
576 .id_table = i2400ms_sdio_ids,
577};
578
579
580static
581int __init i2400ms_driver_init(void)
582{
583 d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400ms_debug_params,
584 "i2400m_sdio.debug");
585 return sdio_register_driver(&i2400m_sdio_driver);
586}
587module_init(i2400ms_driver_init);
588
589
590static
591void __exit i2400ms_driver_exit(void)
592{
593 sdio_unregister_driver(&i2400m_sdio_driver);
594}
595module_exit(i2400ms_driver_exit);
596
597
598MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>");
599MODULE_DESCRIPTION("Intel 2400M WiMAX networking for SDIO");
600MODULE_LICENSE("GPL");
601MODULE_FIRMWARE(I2400MS_FW_FILE_NAME);
602