This source file includes following definitions.
- i2400mu_bus_dev_start
- i2400mu_bus_dev_stop
- __i2400mu_send_barker
- i2400mu_bus_reset
- i2400mu_get_drvinfo
- i2400mu_netdev_setup
- i2400mu_debugfs_add
- i2400mu_probe
- i2400mu_disconnect
- i2400mu_suspend
- i2400mu_resume
- i2400mu_reset_resume
- i2400mu_pre_reset
- i2400mu_post_reset
- i2400mu_driver_init
- i2400mu_driver_exit
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 "i2400m-usb.h"
52 #include <linux/wimax/i2400m.h>
53 #include <linux/debugfs.h>
54 #include <linux/slab.h>
55 #include <linux/module.h>
56
57
58 #define D_SUBMODULE usb
59 #include "usb-debug-levels.h"
60
61 static char i2400mu_debug_params[128];
62 module_param_string(debug, i2400mu_debug_params, sizeof(i2400mu_debug_params),
63 0644);
64 MODULE_PARM_DESC(debug,
65 "String of space-separated NAME:VALUE pairs, where NAMEs "
66 "are the different debug submodules and VALUE are the "
67 "initial debug value to set.");
68
69
70 static const char *i2400mu_bus_fw_names_5x50[] = {
71 #define I2400MU_FW_FILE_NAME_v1_5 "i2400m-fw-usb-1.5.sbcf"
72 I2400MU_FW_FILE_NAME_v1_5,
73 #define I2400MU_FW_FILE_NAME_v1_4 "i2400m-fw-usb-1.4.sbcf"
74 I2400MU_FW_FILE_NAME_v1_4,
75 NULL,
76 };
77
78
79 static const char *i2400mu_bus_fw_names_6050[] = {
80 #define I6050U_FW_FILE_NAME_v1_5 "i6050-fw-usb-1.5.sbcf"
81 I6050U_FW_FILE_NAME_v1_5,
82 NULL,
83 };
84
85
86 static
87 int i2400mu_bus_dev_start(struct i2400m *i2400m)
88 {
89 int result;
90 struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
91 struct device *dev = &i2400mu->usb_iface->dev;
92
93 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
94 result = i2400mu_tx_setup(i2400mu);
95 if (result < 0)
96 goto error_usb_tx_setup;
97 result = i2400mu_rx_setup(i2400mu);
98 if (result < 0)
99 goto error_usb_rx_setup;
100 result = i2400mu_notification_setup(i2400mu);
101 if (result < 0)
102 goto error_notif_setup;
103 d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
104 return result;
105
106 error_notif_setup:
107 i2400mu_rx_release(i2400mu);
108 error_usb_rx_setup:
109 i2400mu_tx_release(i2400mu);
110 error_usb_tx_setup:
111 d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
112 return result;
113 }
114
115
116 static
117 void i2400mu_bus_dev_stop(struct i2400m *i2400m)
118 {
119 struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
120 struct device *dev = &i2400mu->usb_iface->dev;
121
122 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
123 i2400mu_notification_release(i2400mu);
124 i2400mu_rx_release(i2400mu);
125 i2400mu_tx_release(i2400mu);
126 d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
127 }
128
129
130
131
132
133
134
135
136
137
138
139
140 static
141 int __i2400mu_send_barker(struct i2400mu *i2400mu,
142 const __le32 *barker,
143 size_t barker_size,
144 unsigned endpoint)
145 {
146 struct usb_endpoint_descriptor *epd = NULL;
147 int pipe, actual_len, ret;
148 struct device *dev = &i2400mu->usb_iface->dev;
149 void *buffer;
150 int do_autopm = 1;
151
152 ret = usb_autopm_get_interface(i2400mu->usb_iface);
153 if (ret < 0) {
154 dev_err(dev, "RESET: can't get autopm: %d\n", ret);
155 do_autopm = 0;
156 }
157 ret = -ENOMEM;
158 buffer = kmalloc(barker_size, GFP_KERNEL);
159 if (buffer == NULL)
160 goto error_kzalloc;
161 epd = usb_get_epd(i2400mu->usb_iface, endpoint);
162 pipe = usb_sndbulkpipe(i2400mu->usb_dev, epd->bEndpointAddress);
163 memcpy(buffer, barker, barker_size);
164 retry:
165 ret = usb_bulk_msg(i2400mu->usb_dev, pipe, buffer, barker_size,
166 &actual_len, 200);
167 switch (ret) {
168 case 0:
169 if (actual_len != barker_size) {
170 dev_err(dev, "E: %s: short write (%d B vs %zu "
171 "expected)\n",
172 __func__, actual_len, barker_size);
173 ret = -EIO;
174 }
175 break;
176 case -EPIPE:
177
178
179
180
181
182
183
184
185
186
187 if (edc_inc(&i2400mu->urb_edc,
188 10 * EDC_MAX_ERRORS, EDC_ERROR_TIMEFRAME)) {
189 dev_err(dev, "E: %s: too many stalls in "
190 "URB; resetting device\n", __func__);
191 usb_queue_reset_device(i2400mu->usb_iface);
192
193 } else {
194 usb_clear_halt(i2400mu->usb_dev, pipe);
195 msleep(10);
196 goto retry;
197 }
198
199 case -EINVAL:
200 case -ENODEV:
201 case -ENOENT:
202 case -ESHUTDOWN:
203 case -ECONNRESET:
204 ret = -ESHUTDOWN;
205 break;
206 default:
207 if (edc_inc(&i2400mu->urb_edc,
208 EDC_MAX_ERRORS, EDC_ERROR_TIMEFRAME)) {
209 dev_err(dev, "E: %s: maximum errors in URB "
210 "exceeded; resetting device\n",
211 __func__);
212 usb_queue_reset_device(i2400mu->usb_iface);
213 } else {
214 dev_warn(dev, "W: %s: cannot send URB: %d\n",
215 __func__, ret);
216 goto retry;
217 }
218 }
219 kfree(buffer);
220 error_kzalloc:
221 if (do_autopm)
222 usb_autopm_put_interface(i2400mu->usb_iface);
223 return ret;
224 }
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260 static
261 int i2400mu_bus_reset(struct i2400m *i2400m, enum i2400m_reset_type rt)
262 {
263 int result;
264 struct i2400mu *i2400mu =
265 container_of(i2400m, struct i2400mu, i2400m);
266 struct device *dev = i2400m_dev(i2400m);
267 static const __le32 i2400m_WARM_BOOT_BARKER[4] = {
268 cpu_to_le32(I2400M_WARM_RESET_BARKER),
269 cpu_to_le32(I2400M_WARM_RESET_BARKER),
270 cpu_to_le32(I2400M_WARM_RESET_BARKER),
271 cpu_to_le32(I2400M_WARM_RESET_BARKER),
272 };
273 static const __le32 i2400m_COLD_BOOT_BARKER[4] = {
274 cpu_to_le32(I2400M_COLD_RESET_BARKER),
275 cpu_to_le32(I2400M_COLD_RESET_BARKER),
276 cpu_to_le32(I2400M_COLD_RESET_BARKER),
277 cpu_to_le32(I2400M_COLD_RESET_BARKER),
278 };
279
280 d_fnstart(3, dev, "(i2400m %p rt %u)\n", i2400m, rt);
281 if (rt == I2400M_RT_WARM)
282 result = __i2400mu_send_barker(
283 i2400mu, i2400m_WARM_BOOT_BARKER,
284 sizeof(i2400m_WARM_BOOT_BARKER),
285 i2400mu->endpoint_cfg.bulk_out);
286 else if (rt == I2400M_RT_COLD)
287 result = __i2400mu_send_barker(
288 i2400mu, i2400m_COLD_BOOT_BARKER,
289 sizeof(i2400m_COLD_BOOT_BARKER),
290 i2400mu->endpoint_cfg.reset_cold);
291 else if (rt == I2400M_RT_BUS) {
292 result = usb_reset_device(i2400mu->usb_dev);
293 switch (result) {
294 case 0:
295 case -EINVAL:
296 case -ENODEV:
297 case -ENOENT:
298 case -ESHUTDOWN:
299 result = 0;
300 break;
301 default:
302 dev_err(dev, "USB reset failed (%d), giving up!\n",
303 result);
304 }
305 } else {
306 result = -EINVAL;
307 BUG();
308 }
309 if (result < 0
310 && result != -EINVAL
311 && rt != I2400M_RT_BUS) {
312
313
314
315
316
317
318
319 dev_err(dev, "%s reset failed (%d); trying USB reset\n",
320 rt == I2400M_RT_WARM ? "warm" : "cold", result);
321 usb_queue_reset_device(i2400mu->usb_iface);
322 result = -ENODEV;
323 }
324 d_fnend(3, dev, "(i2400m %p rt %u) = %d\n", i2400m, rt, result);
325 return result;
326 }
327
328 static void i2400mu_get_drvinfo(struct net_device *net_dev,
329 struct ethtool_drvinfo *info)
330 {
331 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
332 struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
333 struct usb_device *udev = i2400mu->usb_dev;
334
335 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
336 strlcpy(info->fw_version, i2400m->fw_name ? : "",
337 sizeof(info->fw_version));
338 usb_make_path(udev, info->bus_info, sizeof(info->bus_info));
339 }
340
341 static const struct ethtool_ops i2400mu_ethtool_ops = {
342 .get_drvinfo = i2400mu_get_drvinfo,
343 .get_link = ethtool_op_get_link,
344 };
345
346 static
347 void i2400mu_netdev_setup(struct net_device *net_dev)
348 {
349 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
350 struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
351 i2400mu_init(i2400mu);
352 i2400m_netdev_setup(net_dev);
353 net_dev->ethtool_ops = &i2400mu_ethtool_ops;
354 }
355
356
357
358
359
360 struct d_level D_LEVEL[] = {
361 D_SUBMODULE_DEFINE(usb),
362 D_SUBMODULE_DEFINE(fw),
363 D_SUBMODULE_DEFINE(notif),
364 D_SUBMODULE_DEFINE(rx),
365 D_SUBMODULE_DEFINE(tx),
366 };
367 size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL);
368
369 static
370 void i2400mu_debugfs_add(struct i2400mu *i2400mu)
371 {
372 struct dentry *dentry = i2400mu->i2400m.wimax_dev.debugfs_dentry;
373
374 dentry = debugfs_create_dir("i2400m-usb", dentry);
375 i2400mu->debugfs_dentry = dentry;
376
377 d_level_register_debugfs("dl_", usb, dentry);
378 d_level_register_debugfs("dl_", fw, dentry);
379 d_level_register_debugfs("dl_", notif, dentry);
380 d_level_register_debugfs("dl_", rx, dentry);
381 d_level_register_debugfs("dl_", tx, dentry);
382
383
384 debugfs_create_u8("rx_size_auto_shrink", 0600, dentry,
385 &i2400mu->rx_size_auto_shrink);
386
387 debugfs_create_size_t("rx_size", 0600, dentry, &i2400mu->rx_size);
388 }
389
390
391 static struct device_type i2400mu_type = {
392 .name = "wimax",
393 };
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409 static
410 int i2400mu_probe(struct usb_interface *iface,
411 const struct usb_device_id *id)
412 {
413 int result;
414 struct net_device *net_dev;
415 struct device *dev = &iface->dev;
416 struct i2400m *i2400m;
417 struct i2400mu *i2400mu;
418 struct usb_device *usb_dev = interface_to_usbdev(iface);
419
420 if (iface->cur_altsetting->desc.bNumEndpoints < 4)
421 return -ENODEV;
422
423 if (usb_dev->speed != USB_SPEED_HIGH)
424 dev_err(dev, "device not connected as high speed\n");
425
426
427 result = -ENOMEM;
428 net_dev = alloc_netdev(sizeof(*i2400mu), "wmx%d", NET_NAME_UNKNOWN,
429 i2400mu_netdev_setup);
430 if (net_dev == NULL) {
431 dev_err(dev, "no memory for network device instance\n");
432 goto error_alloc_netdev;
433 }
434 SET_NETDEV_DEV(net_dev, dev);
435 SET_NETDEV_DEVTYPE(net_dev, &i2400mu_type);
436 i2400m = net_dev_to_i2400m(net_dev);
437 i2400mu = container_of(i2400m, struct i2400mu, i2400m);
438 i2400m->wimax_dev.net_dev = net_dev;
439 i2400mu->usb_dev = usb_get_dev(usb_dev);
440 i2400mu->usb_iface = iface;
441 usb_set_intfdata(iface, i2400mu);
442
443 i2400m->bus_tx_block_size = I2400MU_BLK_SIZE;
444
445
446
447
448
449
450 i2400m->bus_tx_room_min = I2400MU_BLK_SIZE;
451 i2400m->bus_pl_size_max = I2400MU_PL_SIZE_MAX;
452 i2400m->bus_setup = NULL;
453 i2400m->bus_dev_start = i2400mu_bus_dev_start;
454 i2400m->bus_dev_stop = i2400mu_bus_dev_stop;
455 i2400m->bus_release = NULL;
456 i2400m->bus_tx_kick = i2400mu_bus_tx_kick;
457 i2400m->bus_reset = i2400mu_bus_reset;
458 i2400m->bus_bm_retries = I2400M_USB_BOOT_RETRIES;
459 i2400m->bus_bm_cmd_send = i2400mu_bus_bm_cmd_send;
460 i2400m->bus_bm_wait_for_ack = i2400mu_bus_bm_wait_for_ack;
461 i2400m->bus_bm_mac_addr_impaired = 0;
462
463 switch (id->idProduct) {
464 case USB_DEVICE_ID_I6050:
465 case USB_DEVICE_ID_I6050_2:
466 case USB_DEVICE_ID_I6150:
467 case USB_DEVICE_ID_I6150_2:
468 case USB_DEVICE_ID_I6150_3:
469 case USB_DEVICE_ID_I6250:
470 i2400mu->i6050 = 1;
471 break;
472 default:
473 break;
474 }
475
476 if (i2400mu->i6050) {
477 i2400m->bus_fw_names = i2400mu_bus_fw_names_6050;
478 i2400mu->endpoint_cfg.bulk_out = 0;
479 i2400mu->endpoint_cfg.notification = 3;
480 i2400mu->endpoint_cfg.reset_cold = 2;
481 i2400mu->endpoint_cfg.bulk_in = 1;
482 } else {
483 i2400m->bus_fw_names = i2400mu_bus_fw_names_5x50;
484 i2400mu->endpoint_cfg.bulk_out = 0;
485 i2400mu->endpoint_cfg.notification = 1;
486 i2400mu->endpoint_cfg.reset_cold = 2;
487 i2400mu->endpoint_cfg.bulk_in = 3;
488 }
489 #ifdef CONFIG_PM
490 iface->needs_remote_wakeup = 1;
491 device_init_wakeup(dev, 1);
492 pm_runtime_set_autosuspend_delay(&usb_dev->dev, 15000);
493 usb_enable_autosuspend(usb_dev);
494 #endif
495
496 result = i2400m_setup(i2400m, I2400M_BRI_MAC_REINIT);
497 if (result < 0) {
498 dev_err(dev, "cannot setup device: %d\n", result);
499 goto error_setup;
500 }
501 i2400mu_debugfs_add(i2400mu);
502 return 0;
503
504 error_setup:
505 usb_set_intfdata(iface, NULL);
506 usb_put_dev(i2400mu->usb_dev);
507 free_netdev(net_dev);
508 error_alloc_netdev:
509 return result;
510 }
511
512
513
514
515
516
517
518
519
520 static
521 void i2400mu_disconnect(struct usb_interface *iface)
522 {
523 struct i2400mu *i2400mu = usb_get_intfdata(iface);
524 struct i2400m *i2400m = &i2400mu->i2400m;
525 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
526 struct device *dev = &iface->dev;
527
528 d_fnstart(3, dev, "(iface %p i2400m %p)\n", iface, i2400m);
529
530 debugfs_remove_recursive(i2400mu->debugfs_dentry);
531 i2400m_release(i2400m);
532 usb_set_intfdata(iface, NULL);
533 usb_put_dev(i2400mu->usb_dev);
534 free_netdev(net_dev);
535 d_fnend(3, dev, "(iface %p i2400m %p) = void\n", iface, i2400m);
536 }
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577 static
578 int i2400mu_suspend(struct usb_interface *iface, pm_message_t pm_msg)
579 {
580 int result = 0;
581 struct device *dev = &iface->dev;
582 struct i2400mu *i2400mu = usb_get_intfdata(iface);
583 unsigned is_autosuspend = 0;
584 struct i2400m *i2400m = &i2400mu->i2400m;
585
586 #ifdef CONFIG_PM
587 if (PMSG_IS_AUTO(pm_msg))
588 is_autosuspend = 1;
589 #endif
590
591 d_fnstart(3, dev, "(iface %p pm_msg %u)\n", iface, pm_msg.event);
592 rmb();
593 if (i2400m->updown == 0)
594 goto no_firmware;
595 if (i2400m->state == I2400M_SS_DATA_PATH_CONNECTED && is_autosuspend) {
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610 result = -EBADF;
611 d_printf(1, dev, "fw up, link up, not-idle, autosuspend: "
612 "not entering powersave\n");
613 goto error_not_now;
614 }
615 d_printf(1, dev, "fw up: entering powersave\n");
616 atomic_dec(&i2400mu->do_autopm);
617 result = i2400m_cmd_enter_powersave(i2400m);
618 atomic_inc(&i2400mu->do_autopm);
619 if (result < 0 && !is_autosuspend) {
620
621 dev_err(dev, "failed to suspend, will reset on resume\n");
622 result = 0;
623 }
624 if (result < 0)
625 goto error_enter_powersave;
626 i2400mu_notification_release(i2400mu);
627 d_printf(1, dev, "powersave requested\n");
628 error_enter_powersave:
629 error_not_now:
630 no_firmware:
631 d_fnend(3, dev, "(iface %p pm_msg %u) = %d\n",
632 iface, pm_msg.event, result);
633 return result;
634 }
635
636
637 static
638 int i2400mu_resume(struct usb_interface *iface)
639 {
640 int ret = 0;
641 struct device *dev = &iface->dev;
642 struct i2400mu *i2400mu = usb_get_intfdata(iface);
643 struct i2400m *i2400m = &i2400mu->i2400m;
644
645 d_fnstart(3, dev, "(iface %p)\n", iface);
646 rmb();
647 if (i2400m->updown == 0) {
648 d_printf(1, dev, "fw was down, no resume needed\n");
649 goto out;
650 }
651 d_printf(1, dev, "fw was up, resuming\n");
652 i2400mu_notification_setup(i2400mu);
653
654
655
656 out:
657 d_fnend(3, dev, "(iface %p) = %d\n", iface, ret);
658 return ret;
659 }
660
661
662 static
663 int i2400mu_reset_resume(struct usb_interface *iface)
664 {
665 int result;
666 struct device *dev = &iface->dev;
667 struct i2400mu *i2400mu = usb_get_intfdata(iface);
668 struct i2400m *i2400m = &i2400mu->i2400m;
669
670 d_fnstart(3, dev, "(iface %p)\n", iface);
671 result = i2400m_dev_reset_handle(i2400m, "device reset on resume");
672 d_fnend(3, dev, "(iface %p) = %d\n", iface, result);
673 return result < 0 ? result : 0;
674 }
675
676
677
678
679
680
681
682
683
684
685 static
686 int i2400mu_pre_reset(struct usb_interface *iface)
687 {
688 struct i2400mu *i2400mu = usb_get_intfdata(iface);
689 return i2400m_pre_reset(&i2400mu->i2400m);
690 }
691
692
693
694
695
696
697
698
699
700 static
701 int i2400mu_post_reset(struct usb_interface *iface)
702 {
703 struct i2400mu *i2400mu = usb_get_intfdata(iface);
704 return i2400m_post_reset(&i2400mu->i2400m);
705 }
706
707
708 static
709 struct usb_device_id i2400mu_id_table[] = {
710 { USB_DEVICE(0x8086, USB_DEVICE_ID_I6050) },
711 { USB_DEVICE(0x8086, USB_DEVICE_ID_I6050_2) },
712 { USB_DEVICE(0x8087, USB_DEVICE_ID_I6150) },
713 { USB_DEVICE(0x8087, USB_DEVICE_ID_I6150_2) },
714 { USB_DEVICE(0x8087, USB_DEVICE_ID_I6150_3) },
715 { USB_DEVICE(0x8086, USB_DEVICE_ID_I6250) },
716 { USB_DEVICE(0x8086, 0x0181) },
717 { USB_DEVICE(0x8086, 0x1403) },
718 { USB_DEVICE(0x8086, 0x1405) },
719 { USB_DEVICE(0x8086, 0x0180) },
720 { USB_DEVICE(0x8086, 0x0182) },
721 { USB_DEVICE(0x8086, 0x1406) },
722 { USB_DEVICE(0x8086, 0x1403) },
723 { },
724 };
725 MODULE_DEVICE_TABLE(usb, i2400mu_id_table);
726
727
728 static
729 struct usb_driver i2400mu_driver = {
730 .name = KBUILD_MODNAME,
731 .suspend = i2400mu_suspend,
732 .resume = i2400mu_resume,
733 .reset_resume = i2400mu_reset_resume,
734 .probe = i2400mu_probe,
735 .disconnect = i2400mu_disconnect,
736 .pre_reset = i2400mu_pre_reset,
737 .post_reset = i2400mu_post_reset,
738 .id_table = i2400mu_id_table,
739 .supports_autosuspend = 1,
740 };
741
742 static
743 int __init i2400mu_driver_init(void)
744 {
745 d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400mu_debug_params,
746 "i2400m_usb.debug");
747 return usb_register(&i2400mu_driver);
748 }
749 module_init(i2400mu_driver_init);
750
751
752 static
753 void __exit i2400mu_driver_exit(void)
754 {
755 usb_deregister(&i2400mu_driver);
756 }
757 module_exit(i2400mu_driver_exit);
758
759 MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>");
760 MODULE_DESCRIPTION("Driver for USB based Intel Wireless WiMAX Connection 2400M "
761 "(5x50 & 6050)");
762 MODULE_LICENSE("GPL");
763 MODULE_FIRMWARE(I2400MU_FW_FILE_NAME_v1_5);
764 MODULE_FIRMWARE(I6050U_FW_FILE_NAME_v1_5);