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