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