aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/atm
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@samba.org>2006-02-06 18:43:36 -0500
committerPaul Mackerras <paulus@samba.org>2006-02-06 18:43:36 -0500
commit6cb6524d90b6e5497e79a1474bdb2f26755d1c02 (patch)
treefd475ac8f57a6bd39c976056324d1bc79d11b4c9 /drivers/usb/atm
parent837e9594fc3cb9a06bddd7ecf66151334a2e13d2 (diff)
parent410c05427a69f53851637ccb85c2212131409fbd (diff)
Merge ../linux-2.6
Diffstat (limited to 'drivers/usb/atm')
-rw-r--r--drivers/usb/atm/cxacru.c92
-rw-r--r--drivers/usb/atm/speedtch.c167
-rw-r--r--drivers/usb/atm/ueagle-atm.c96
-rw-r--r--drivers/usb/atm/usbatm.c574
-rw-r--r--drivers/usb/atm/usbatm.h59
-rw-r--r--drivers/usb/atm/xusbatm.c137
6 files changed, 713 insertions, 412 deletions
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
index af0a41e7870e..04631dcbabbc 100644
--- a/drivers/usb/atm/cxacru.c
+++ b/drivers/usb/atm/cxacru.c
@@ -36,6 +36,7 @@
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/device.h> /* FIXME: linux/firmware.h should include it itself */ 37#include <linux/device.h> /* FIXME: linux/firmware.h should include it itself */
38#include <linux/firmware.h> 38#include <linux/firmware.h>
39#include <linux/mutex.h>
39 40
40#include "usbatm.h" 41#include "usbatm.h"
41 42
@@ -160,7 +161,7 @@ struct cxacru_data {
160 struct work_struct poll_work; 161 struct work_struct poll_work;
161 162
162 /* contol handles */ 163 /* contol handles */
163 struct semaphore cm_serialize; 164 struct mutex cm_serialize;
164 u8 *rcv_buf; 165 u8 *rcv_buf;
165 u8 *snd_buf; 166 u8 *snd_buf;
166 struct urb *rcv_urb; 167 struct urb *rcv_urb;
@@ -219,7 +220,7 @@ static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm,
219 goto fail; 220 goto fail;
220 } 221 }
221 222
222 down(&instance->cm_serialize); 223 mutex_lock(&instance->cm_serialize);
223 224
224 /* submit reading urb before the writing one */ 225 /* submit reading urb before the writing one */
225 init_completion(&instance->rcv_done); 226 init_completion(&instance->rcv_done);
@@ -288,7 +289,7 @@ static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm,
288 ret = offd; 289 ret = offd;
289 dbg("cm %#x", cm); 290 dbg("cm %#x", cm);
290fail: 291fail:
291 up(&instance->cm_serialize); 292 mutex_unlock(&instance->cm_serialize);
292 return ret; 293 return ret;
293} 294}
294 295
@@ -352,7 +353,6 @@ static int cxacru_atm_start(struct usbatm_data *usbatm_instance,
352 struct atm_dev *atm_dev) 353 struct atm_dev *atm_dev)
353{ 354{
354 struct cxacru_data *instance = usbatm_instance->driver_data; 355 struct cxacru_data *instance = usbatm_instance->driver_data;
355 struct device *dev = &usbatm_instance->usb_intf->dev;
356 /* 356 /*
357 struct atm_dev *atm_dev = usbatm_instance->atm_dev; 357 struct atm_dev *atm_dev = usbatm_instance->atm_dev;
358 */ 358 */
@@ -364,14 +364,14 @@ static int cxacru_atm_start(struct usbatm_data *usbatm_instance,
364 ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_MAC_ADDRESS, NULL, 0, 364 ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_MAC_ADDRESS, NULL, 0,
365 atm_dev->esi, sizeof(atm_dev->esi)); 365 atm_dev->esi, sizeof(atm_dev->esi));
366 if (ret < 0) { 366 if (ret < 0) {
367 dev_err(dev, "cxacru_atm_start: CARD_GET_MAC_ADDRESS returned %d\n", ret); 367 atm_err(usbatm_instance, "cxacru_atm_start: CARD_GET_MAC_ADDRESS returned %d\n", ret);
368 return ret; 368 return ret;
369 } 369 }
370 370
371 /* start ADSL */ 371 /* start ADSL */
372 ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0); 372 ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0);
373 if (ret < 0) { 373 if (ret < 0) {
374 dev_err(dev, "cxacru_atm_start: CHIP_ADSL_LINE_START returned %d\n", ret); 374 atm_err(usbatm_instance, "cxacru_atm_start: CHIP_ADSL_LINE_START returned %d\n", ret);
375 return ret; 375 return ret;
376 } 376 }
377 377
@@ -383,13 +383,13 @@ static int cxacru_atm_start(struct usbatm_data *usbatm_instance,
383static void cxacru_poll_status(struct cxacru_data *instance) 383static void cxacru_poll_status(struct cxacru_data *instance)
384{ 384{
385 u32 buf[CXINF_MAX] = {}; 385 u32 buf[CXINF_MAX] = {};
386 struct device *dev = &instance->usbatm->usb_intf->dev; 386 struct usbatm_data *usbatm = instance->usbatm;
387 struct atm_dev *atm_dev = instance->usbatm->atm_dev; 387 struct atm_dev *atm_dev = usbatm->atm_dev;
388 int ret; 388 int ret;
389 389
390 ret = cxacru_cm_get_array(instance, CM_REQUEST_CARD_INFO_GET, buf, CXINF_MAX); 390 ret = cxacru_cm_get_array(instance, CM_REQUEST_CARD_INFO_GET, buf, CXINF_MAX);
391 if (ret < 0) { 391 if (ret < 0) {
392 dev_warn(dev, "poll status: error %d\n", ret); 392 atm_warn(usbatm, "poll status: error %d\n", ret);
393 goto reschedule; 393 goto reschedule;
394 } 394 }
395 395
@@ -400,50 +400,50 @@ static void cxacru_poll_status(struct cxacru_data *instance)
400 switch (instance->line_status) { 400 switch (instance->line_status) {
401 case 0: 401 case 0:
402 atm_dev->signal = ATM_PHY_SIG_LOST; 402 atm_dev->signal = ATM_PHY_SIG_LOST;
403 dev_info(dev, "ADSL line: down\n"); 403 atm_info(usbatm, "ADSL line: down\n");
404 break; 404 break;
405 405
406 case 1: 406 case 1:
407 atm_dev->signal = ATM_PHY_SIG_LOST; 407 atm_dev->signal = ATM_PHY_SIG_LOST;
408 dev_info(dev, "ADSL line: attemtping to activate\n"); 408 atm_info(usbatm, "ADSL line: attempting to activate\n");
409 break; 409 break;
410 410
411 case 2: 411 case 2:
412 atm_dev->signal = ATM_PHY_SIG_LOST; 412 atm_dev->signal = ATM_PHY_SIG_LOST;
413 dev_info(dev, "ADSL line: training\n"); 413 atm_info(usbatm, "ADSL line: training\n");
414 break; 414 break;
415 415
416 case 3: 416 case 3:
417 atm_dev->signal = ATM_PHY_SIG_LOST; 417 atm_dev->signal = ATM_PHY_SIG_LOST;
418 dev_info(dev, "ADSL line: channel analysis\n"); 418 atm_info(usbatm, "ADSL line: channel analysis\n");
419 break; 419 break;
420 420
421 case 4: 421 case 4:
422 atm_dev->signal = ATM_PHY_SIG_LOST; 422 atm_dev->signal = ATM_PHY_SIG_LOST;
423 dev_info(dev, "ADSL line: exchange\n"); 423 atm_info(usbatm, "ADSL line: exchange\n");
424 break; 424 break;
425 425
426 case 5: 426 case 5:
427 atm_dev->link_rate = buf[CXINF_DOWNSTREAM_RATE] * 1000 / 424; 427 atm_dev->link_rate = buf[CXINF_DOWNSTREAM_RATE] * 1000 / 424;
428 atm_dev->signal = ATM_PHY_SIG_FOUND; 428 atm_dev->signal = ATM_PHY_SIG_FOUND;
429 429
430 dev_info(dev, "ADSL line: up (%d kb/s down | %d kb/s up)\n", 430 atm_info(usbatm, "ADSL line: up (%d kb/s down | %d kb/s up)\n",
431 buf[CXINF_DOWNSTREAM_RATE], buf[CXINF_UPSTREAM_RATE]); 431 buf[CXINF_DOWNSTREAM_RATE], buf[CXINF_UPSTREAM_RATE]);
432 break; 432 break;
433 433
434 case 6: 434 case 6:
435 atm_dev->signal = ATM_PHY_SIG_LOST; 435 atm_dev->signal = ATM_PHY_SIG_LOST;
436 dev_info(dev, "ADSL line: waiting\n"); 436 atm_info(usbatm, "ADSL line: waiting\n");
437 break; 437 break;
438 438
439 case 7: 439 case 7:
440 atm_dev->signal = ATM_PHY_SIG_LOST; 440 atm_dev->signal = ATM_PHY_SIG_LOST;
441 dev_info(dev, "ADSL line: initializing\n"); 441 atm_info(usbatm, "ADSL line: initializing\n");
442 break; 442 break;
443 443
444 default: 444 default:
445 atm_dev->signal = ATM_PHY_SIG_UNKNOWN; 445 atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
446 dev_info(dev, "Unknown line state %02x\n", instance->line_status); 446 atm_info(usbatm, "Unknown line state %02x\n", instance->line_status);
447 break; 447 break;
448 } 448 }
449reschedule: 449reschedule:
@@ -504,8 +504,8 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
504{ 504{
505 int ret; 505 int ret;
506 int off; 506 int off;
507 struct usb_device *usb_dev = instance->usbatm->usb_dev; 507 struct usbatm_data *usbatm = instance->usbatm;
508 struct device *dev = &instance->usbatm->usb_intf->dev; 508 struct usb_device *usb_dev = usbatm->usb_dev;
509 u16 signature[] = { usb_dev->descriptor.idVendor, usb_dev->descriptor.idProduct }; 509 u16 signature[] = { usb_dev->descriptor.idVendor, usb_dev->descriptor.idProduct };
510 u32 val; 510 u32 val;
511 511
@@ -515,7 +515,7 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
515 val = cpu_to_le32(instance->modem_type->pll_f_clk); 515 val = cpu_to_le32(instance->modem_type->pll_f_clk);
516 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLFCLK_ADDR, (u8 *) &val, 4); 516 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLFCLK_ADDR, (u8 *) &val, 4);
517 if (ret) { 517 if (ret) {
518 dev_err(dev, "FirmwarePllFClkValue failed: %d\n", ret); 518 usb_err(usbatm, "FirmwarePllFClkValue failed: %d\n", ret);
519 return; 519 return;
520 } 520 }
521 521
@@ -523,7 +523,7 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
523 val = cpu_to_le32(instance->modem_type->pll_b_clk); 523 val = cpu_to_le32(instance->modem_type->pll_b_clk);
524 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLBCLK_ADDR, (u8 *) &val, 4); 524 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLBCLK_ADDR, (u8 *) &val, 4);
525 if (ret) { 525 if (ret) {
526 dev_err(dev, "FirmwarePllBClkValue failed: %d\n", ret); 526 usb_err(usbatm, "FirmwarePllBClkValue failed: %d\n", ret);
527 return; 527 return;
528 } 528 }
529 529
@@ -531,14 +531,14 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
531 val = cpu_to_le32(SDRAM_ENA); 531 val = cpu_to_le32(SDRAM_ENA);
532 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SDRAMEN_ADDR, (u8 *) &val, 4); 532 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SDRAMEN_ADDR, (u8 *) &val, 4);
533 if (ret) { 533 if (ret) {
534 dev_err(dev, "Enable SDRAM failed: %d\n", ret); 534 usb_err(usbatm, "Enable SDRAM failed: %d\n", ret);
535 return; 535 return;
536 } 536 }
537 537
538 /* Firmware */ 538 /* Firmware */
539 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, FW_ADDR, fw->data, fw->size); 539 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, FW_ADDR, fw->data, fw->size);
540 if (ret) { 540 if (ret) {
541 dev_err(dev, "Firmware upload failed: %d\n", ret); 541 usb_err(usbatm, "Firmware upload failed: %d\n", ret);
542 return; 542 return;
543 } 543 }
544 544
@@ -546,7 +546,7 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
546 if (instance->modem_type->boot_rom_patch) { 546 if (instance->modem_type->boot_rom_patch) {
547 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_ADDR, bp->data, bp->size); 547 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_ADDR, bp->data, bp->size);
548 if (ret) { 548 if (ret) {
549 dev_err(dev, "Boot ROM patching failed: %d\n", ret); 549 usb_err(usbatm, "Boot ROM patching failed: %d\n", ret);
550 return; 550 return;
551 } 551 }
552 } 552 }
@@ -554,7 +554,7 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
554 /* Signature */ 554 /* Signature */
555 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SIG_ADDR, (u8 *) signature, 4); 555 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SIG_ADDR, (u8 *) signature, 4);
556 if (ret) { 556 if (ret) {
557 dev_err(dev, "Signature storing failed: %d\n", ret); 557 usb_err(usbatm, "Signature storing failed: %d\n", ret);
558 return; 558 return;
559 } 559 }
560 560
@@ -566,7 +566,7 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
566 ret = cxacru_fw(usb_dev, FW_GOTO_MEM, 0x0, 0x0, FW_ADDR, NULL, 0); 566 ret = cxacru_fw(usb_dev, FW_GOTO_MEM, 0x0, 0x0, FW_ADDR, NULL, 0);
567 } 567 }
568 if (ret) { 568 if (ret) {
569 dev_err(dev, "Passing control to firmware failed: %d\n", ret); 569 usb_err(usbatm, "Passing control to firmware failed: %d\n", ret);
570 return; 570 return;
571 } 571 }
572 572
@@ -580,7 +580,7 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
580 580
581 ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0); 581 ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
582 if (ret < 0) { 582 if (ret < 0) {
583 dev_err(dev, "modem failed to initialize: %d\n", ret); 583 usb_err(usbatm, "modem failed to initialize: %d\n", ret);
584 return; 584 return;
585 } 585 }
586 586
@@ -597,7 +597,7 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
597 ret = cxacru_cm(instance, CM_REQUEST_CARD_DATA_SET, 597 ret = cxacru_cm(instance, CM_REQUEST_CARD_DATA_SET,
598 (u8 *) buf, len, NULL, 0); 598 (u8 *) buf, len, NULL, 0);
599 if (ret < 0) { 599 if (ret < 0) {
600 dev_err(dev, "load config data failed: %d\n", ret); 600 usb_err(usbatm, "load config data failed: %d\n", ret);
601 return; 601 return;
602 } 602 }
603 } 603 }
@@ -608,18 +608,19 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
608static int cxacru_find_firmware(struct cxacru_data *instance, 608static int cxacru_find_firmware(struct cxacru_data *instance,
609 char* phase, const struct firmware **fw_p) 609 char* phase, const struct firmware **fw_p)
610{ 610{
611 struct device *dev = &instance->usbatm->usb_intf->dev; 611 struct usbatm_data *usbatm = instance->usbatm;
612 struct device *dev = &usbatm->usb_intf->dev;
612 char buf[16]; 613 char buf[16];
613 614
614 sprintf(buf, "cxacru-%s.bin", phase); 615 sprintf(buf, "cxacru-%s.bin", phase);
615 dbg("cxacru_find_firmware: looking for %s", buf); 616 dbg("cxacru_find_firmware: looking for %s", buf);
616 617
617 if (request_firmware(fw_p, buf, dev)) { 618 if (request_firmware(fw_p, buf, dev)) {
618 dev_dbg(dev, "no stage %s firmware found\n", phase); 619 usb_dbg(usbatm, "no stage %s firmware found\n", phase);
619 return -ENOENT; 620 return -ENOENT;
620 } 621 }
621 622
622 dev_info(dev, "found firmware %s\n", buf); 623 usb_info(usbatm, "found firmware %s\n", buf);
623 624
624 return 0; 625 return 0;
625} 626}
@@ -627,20 +628,19 @@ static int cxacru_find_firmware(struct cxacru_data *instance,
627static int cxacru_heavy_init(struct usbatm_data *usbatm_instance, 628static int cxacru_heavy_init(struct usbatm_data *usbatm_instance,
628 struct usb_interface *usb_intf) 629 struct usb_interface *usb_intf)
629{ 630{
630 struct device *dev = &usbatm_instance->usb_intf->dev;
631 const struct firmware *fw, *bp, *cf; 631 const struct firmware *fw, *bp, *cf;
632 struct cxacru_data *instance = usbatm_instance->driver_data; 632 struct cxacru_data *instance = usbatm_instance->driver_data;
633 633
634 int ret = cxacru_find_firmware(instance, "fw", &fw); 634 int ret = cxacru_find_firmware(instance, "fw", &fw);
635 if (ret) { 635 if (ret) {
636 dev_warn(dev, "firmware (cxacru-fw.bin) unavailable (hotplug misconfiguration?)\n"); 636 usb_warn(usbatm_instance, "firmware (cxacru-fw.bin) unavailable (system misconfigured?)\n");
637 return ret; 637 return ret;
638 } 638 }
639 639
640 if (instance->modem_type->boot_rom_patch) { 640 if (instance->modem_type->boot_rom_patch) {
641 ret = cxacru_find_firmware(instance, "bp", &bp); 641 ret = cxacru_find_firmware(instance, "bp", &bp);
642 if (ret) { 642 if (ret) {
643 dev_warn(dev, "boot ROM patch (cxacru-bp.bin) unavailable (hotplug misconfiguration?)\n"); 643 usb_warn(usbatm_instance, "boot ROM patch (cxacru-bp.bin) unavailable (system misconfigured?)\n");
644 release_firmware(fw); 644 release_firmware(fw);
645 return ret; 645 return ret;
646 } 646 }
@@ -667,22 +667,19 @@ static int cxacru_heavy_init(struct usbatm_data *usbatm_instance,
667} 667}
668 668
669static int cxacru_bind(struct usbatm_data *usbatm_instance, 669static int cxacru_bind(struct usbatm_data *usbatm_instance,
670 struct usb_interface *intf, const struct usb_device_id *id, 670 struct usb_interface *intf, const struct usb_device_id *id)
671 int *need_heavy_init)
672{ 671{
673 struct cxacru_data *instance; 672 struct cxacru_data *instance;
674 struct usb_device *usb_dev = interface_to_usbdev(intf); 673 struct usb_device *usb_dev = interface_to_usbdev(intf);
675 int ret; 674 int ret;
676 675
677 /* instance init */ 676 /* instance init */
678 instance = kmalloc(sizeof(*instance), GFP_KERNEL); 677 instance = kzalloc(sizeof(*instance), GFP_KERNEL);
679 if (!instance) { 678 if (!instance) {
680 dbg("cxacru_bind: no memory for instance data"); 679 dbg("cxacru_bind: no memory for instance data");
681 return -ENOMEM; 680 return -ENOMEM;
682 } 681 }
683 682
684 memset(instance, 0, sizeof(*instance));
685
686 instance->usbatm = usbatm_instance; 683 instance->usbatm = usbatm_instance;
687 instance->modem_type = (struct cxacru_modem_type *) id->driver_info; 684 instance->modem_type = (struct cxacru_modem_type *) id->driver_info;
688 685
@@ -721,13 +718,13 @@ static int cxacru_bind(struct usbatm_data *usbatm_instance,
721 instance->snd_buf, PAGE_SIZE, 718 instance->snd_buf, PAGE_SIZE,
722 cxacru_blocking_completion, &instance->snd_done, 4); 719 cxacru_blocking_completion, &instance->snd_done, 4);
723 720
724 init_MUTEX(&instance->cm_serialize); 721 mutex_init(&instance->cm_serialize);
725 722
726 INIT_WORK(&instance->poll_work, (void *)cxacru_poll_status, instance); 723 INIT_WORK(&instance->poll_work, (void *)cxacru_poll_status, instance);
727 724
728 usbatm_instance->driver_data = instance; 725 usbatm_instance->driver_data = instance;
729 726
730 *need_heavy_init = cxacru_card_status(instance); 727 usbatm_instance->flags = (cxacru_card_status(instance) ? 0 : UDSL_SKIP_HEAVY_INIT);
731 728
732 return 0; 729 return 0;
733 730
@@ -787,12 +784,12 @@ static const struct usb_device_id cxacru_usb_ids[] = {
787 { /* V = Conexant P = ADSL modem (Hasbani project) */ 784 { /* V = Conexant P = ADSL modem (Hasbani project) */
788 USB_DEVICE(0x0572, 0xcb00), .driver_info = (unsigned long) &cxacru_cb00 785 USB_DEVICE(0x0572, 0xcb00), .driver_info = (unsigned long) &cxacru_cb00
789 }, 786 },
790 { /* V = Conexant P = ADSL modem (Well PTI-800 */
791 USB_DEVICE(0x0572, 0xcb02), .driver_info = (unsigned long) &cxacru_cb00
792 },
793 { /* V = Conexant P = ADSL modem */ 787 { /* V = Conexant P = ADSL modem */
794 USB_DEVICE(0x0572, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00 788 USB_DEVICE(0x0572, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00
795 }, 789 },
790 { /* V = Conexant P = ADSL modem (Well PTI-800) */
791 USB_DEVICE(0x0572, 0xcb02), .driver_info = (unsigned long) &cxacru_cb00
792 },
796 { /* V = Conexant P = ADSL modem */ 793 { /* V = Conexant P = ADSL modem */
797 USB_DEVICE(0x0572, 0xcb06), .driver_info = (unsigned long) &cxacru_cb00 794 USB_DEVICE(0x0572, 0xcb06), .driver_info = (unsigned long) &cxacru_cb00
798 }, 795 },
@@ -835,14 +832,13 @@ static const struct usb_device_id cxacru_usb_ids[] = {
835MODULE_DEVICE_TABLE(usb, cxacru_usb_ids); 832MODULE_DEVICE_TABLE(usb, cxacru_usb_ids);
836 833
837static struct usbatm_driver cxacru_driver = { 834static struct usbatm_driver cxacru_driver = {
838 .owner = THIS_MODULE,
839 .driver_name = cxacru_driver_name, 835 .driver_name = cxacru_driver_name,
840 .bind = cxacru_bind, 836 .bind = cxacru_bind,
841 .heavy_init = cxacru_heavy_init, 837 .heavy_init = cxacru_heavy_init,
842 .unbind = cxacru_unbind, 838 .unbind = cxacru_unbind,
843 .atm_start = cxacru_atm_start, 839 .atm_start = cxacru_atm_start,
844 .in = CXACRU_EP_DATA, 840 .bulk_in = CXACRU_EP_DATA,
845 .out = CXACRU_EP_DATA, 841 .bulk_out = CXACRU_EP_DATA,
846 .rx_padding = 3, 842 .rx_padding = 3,
847 .tx_padding = 11, 843 .tx_padding = 11,
848}; 844};
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c
index c1b47d74e206..7860c8a5800d 100644
--- a/drivers/usb/atm/speedtch.c
+++ b/drivers/usb/atm/speedtch.c
@@ -35,12 +35,14 @@
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/stat.h> 36#include <linux/stat.h>
37#include <linux/timer.h> 37#include <linux/timer.h>
38#include <linux/types.h>
39#include <linux/usb_ch9.h>
38#include <linux/workqueue.h> 40#include <linux/workqueue.h>
39 41
40#include "usbatm.h" 42#include "usbatm.h"
41 43
42#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>" 44#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>"
43#define DRIVER_VERSION "1.9" 45#define DRIVER_VERSION "1.10"
44#define DRIVER_DESC "Alcatel SpeedTouch USB driver version " DRIVER_VERSION 46#define DRIVER_DESC "Alcatel SpeedTouch USB driver version " DRIVER_VERSION
45 47
46static const char speedtch_driver_name[] = "speedtch"; 48static const char speedtch_driver_name[] = "speedtch";
@@ -66,31 +68,42 @@ static const char speedtch_driver_name[] = "speedtch";
66 68
67#define RESUBMIT_DELAY 1000 /* milliseconds */ 69#define RESUBMIT_DELAY 1000 /* milliseconds */
68 70
69#define DEFAULT_ALTSETTING 1 71#define DEFAULT_BULK_ALTSETTING 1
72#define DEFAULT_ISOC_ALTSETTING 2
70#define DEFAULT_DL_512_FIRST 0 73#define DEFAULT_DL_512_FIRST 0
74#define DEFAULT_ENABLE_ISOC 0
71#define DEFAULT_SW_BUFFERING 0 75#define DEFAULT_SW_BUFFERING 0
72 76
73static int altsetting = DEFAULT_ALTSETTING; 77static unsigned int altsetting = 0; /* zero means: use the default */
74static int dl_512_first = DEFAULT_DL_512_FIRST; 78static int dl_512_first = DEFAULT_DL_512_FIRST;
79static int enable_isoc = DEFAULT_ENABLE_ISOC;
75static int sw_buffering = DEFAULT_SW_BUFFERING; 80static int sw_buffering = DEFAULT_SW_BUFFERING;
76 81
77module_param(altsetting, int, S_IRUGO | S_IWUSR); 82module_param(altsetting, uint, S_IRUGO | S_IWUSR);
78MODULE_PARM_DESC(altsetting, 83MODULE_PARM_DESC(altsetting,
79 "Alternative setting for data interface (default: " 84 "Alternative setting for data interface (bulk_default: "
80 __MODULE_STRING(DEFAULT_ALTSETTING) ")"); 85 __MODULE_STRING(DEFAULT_BULK_ALTSETTING) "; isoc_default: "
86 __MODULE_STRING(DEFAULT_ISOC_ALTSETTING) ")");
81 87
82module_param(dl_512_first, bool, S_IRUGO | S_IWUSR); 88module_param(dl_512_first, bool, S_IRUGO | S_IWUSR);
83MODULE_PARM_DESC(dl_512_first, 89MODULE_PARM_DESC(dl_512_first,
84 "Read 512 bytes before sending firmware (default: " 90 "Read 512 bytes before sending firmware (default: "
85 __MODULE_STRING(DEFAULT_DL_512_FIRST) ")"); 91 __MODULE_STRING(DEFAULT_DL_512_FIRST) ")");
86 92
93module_param(enable_isoc, bool, S_IRUGO | S_IWUSR);
94MODULE_PARM_DESC(enable_isoc,
95 "Use isochronous transfers if available (default: "
96 __MODULE_STRING(DEFAULT_ENABLE_ISOC) ")");
97
87module_param(sw_buffering, bool, S_IRUGO | S_IWUSR); 98module_param(sw_buffering, bool, S_IRUGO | S_IWUSR);
88MODULE_PARM_DESC(sw_buffering, 99MODULE_PARM_DESC(sw_buffering,
89 "Enable software buffering (default: " 100 "Enable software buffering (default: "
90 __MODULE_STRING(DEFAULT_SW_BUFFERING) ")"); 101 __MODULE_STRING(DEFAULT_SW_BUFFERING) ")");
91 102
103#define INTERFACE_DATA 1
92#define ENDPOINT_INT 0x81 104#define ENDPOINT_INT 0x81
93#define ENDPOINT_DATA 0x07 105#define ENDPOINT_BULK_DATA 0x07
106#define ENDPOINT_ISOC_DATA 0x07
94#define ENDPOINT_FIRMWARE 0x05 107#define ENDPOINT_FIRMWARE 0x05
95 108
96#define hex2int(c) ( (c >= '0') && (c <= '9') ? (c - '0') : ((c & 0xf) + 9) ) 109#define hex2int(c) ( (c >= '0') && (c <= '9') ? (c - '0') : ((c & 0xf) + 9) )
@@ -98,6 +111,8 @@ MODULE_PARM_DESC(sw_buffering,
98struct speedtch_instance_data { 111struct speedtch_instance_data {
99 struct usbatm_data *usbatm; 112 struct usbatm_data *usbatm;
100 113
114 unsigned int altsetting;
115
101 struct work_struct status_checker; 116 struct work_struct status_checker;
102 117
103 unsigned char last_status; 118 unsigned char last_status;
@@ -205,7 +220,7 @@ static int speedtch_upload_firmware(struct speedtch_instance_data *instance,
205 buffer, 0x200, &actual_length, 2000); 220 buffer, 0x200, &actual_length, 2000);
206 221
207 if (ret < 0 && ret != -ETIMEDOUT) 222 if (ret < 0 && ret != -ETIMEDOUT)
208 usb_dbg(usbatm, "%s: read BLOCK0 from modem failed (%d)!\n", __func__, ret); 223 usb_warn(usbatm, "%s: read BLOCK0 from modem failed (%d)!\n", __func__, ret);
209 else 224 else
210 usb_dbg(usbatm, "%s: BLOCK0 downloaded (%d bytes)\n", __func__, ret); 225 usb_dbg(usbatm, "%s: BLOCK0 downloaded (%d bytes)\n", __func__, ret);
211 } 226 }
@@ -219,7 +234,7 @@ static int speedtch_upload_firmware(struct speedtch_instance_data *instance,
219 buffer, thislen, &actual_length, DATA_TIMEOUT); 234 buffer, thislen, &actual_length, DATA_TIMEOUT);
220 235
221 if (ret < 0) { 236 if (ret < 0) {
222 usb_dbg(usbatm, "%s: write BLOCK1 to modem failed (%d)!\n", __func__, ret); 237 usb_err(usbatm, "%s: write BLOCK1 to modem failed (%d)!\n", __func__, ret);
223 goto out_free; 238 goto out_free;
224 } 239 }
225 usb_dbg(usbatm, "%s: BLOCK1 uploaded (%zu bytes)\n", __func__, fw1->size); 240 usb_dbg(usbatm, "%s: BLOCK1 uploaded (%zu bytes)\n", __func__, fw1->size);
@@ -232,7 +247,7 @@ static int speedtch_upload_firmware(struct speedtch_instance_data *instance,
232 buffer, 0x200, &actual_length, DATA_TIMEOUT); 247 buffer, 0x200, &actual_length, DATA_TIMEOUT);
233 248
234 if (ret < 0) { 249 if (ret < 0) {
235 usb_dbg(usbatm, "%s: read BLOCK2 from modem failed (%d)!\n", __func__, ret); 250 usb_err(usbatm, "%s: read BLOCK2 from modem failed (%d)!\n", __func__, ret);
236 goto out_free; 251 goto out_free;
237 } 252 }
238 usb_dbg(usbatm, "%s: BLOCK2 downloaded (%d bytes)\n", __func__, actual_length); 253 usb_dbg(usbatm, "%s: BLOCK2 downloaded (%d bytes)\n", __func__, actual_length);
@@ -246,7 +261,7 @@ static int speedtch_upload_firmware(struct speedtch_instance_data *instance,
246 buffer, thislen, &actual_length, DATA_TIMEOUT); 261 buffer, thislen, &actual_length, DATA_TIMEOUT);
247 262
248 if (ret < 0) { 263 if (ret < 0) {
249 usb_dbg(usbatm, "%s: write BLOCK3 to modem failed (%d)!\n", __func__, ret); 264 usb_err(usbatm, "%s: write BLOCK3 to modem failed (%d)!\n", __func__, ret);
250 goto out_free; 265 goto out_free;
251 } 266 }
252 } 267 }
@@ -259,7 +274,7 @@ static int speedtch_upload_firmware(struct speedtch_instance_data *instance,
259 buffer, 0x200, &actual_length, DATA_TIMEOUT); 274 buffer, 0x200, &actual_length, DATA_TIMEOUT);
260 275
261 if (ret < 0) { 276 if (ret < 0) {
262 usb_dbg(usbatm, "%s: read BLOCK4 from modem failed (%d)!\n", __func__, ret); 277 usb_err(usbatm, "%s: read BLOCK4 from modem failed (%d)!\n", __func__, ret);
263 goto out_free; 278 goto out_free;
264 } 279 }
265 280
@@ -270,6 +285,11 @@ static int speedtch_upload_firmware(struct speedtch_instance_data *instance,
270 because we're in our own kernel thread anyway. */ 285 because we're in our own kernel thread anyway. */
271 msleep_interruptible(1000); 286 msleep_interruptible(1000);
272 287
288 if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, instance->altsetting)) < 0) {
289 usb_err(usbatm, "%s: setting interface to %d failed (%d)!\n", __func__, instance->altsetting, ret);
290 goto out_free;
291 }
292
273 /* Enable software buffering, if requested */ 293 /* Enable software buffering, if requested */
274 if (sw_buffering) 294 if (sw_buffering)
275 speedtch_set_swbuff(instance, 1); 295 speedtch_set_swbuff(instance, 1);
@@ -285,8 +305,8 @@ out:
285 return ret; 305 return ret;
286} 306}
287 307
288static int speedtch_find_firmware(struct usb_interface *intf, int phase, 308static int speedtch_find_firmware(struct usbatm_data *usbatm, struct usb_interface *intf,
289 const struct firmware **fw_p) 309 int phase, const struct firmware **fw_p)
290{ 310{
291 struct device *dev = &intf->dev; 311 struct device *dev = &intf->dev;
292 const u16 bcdDevice = le16_to_cpu(interface_to_usbdev(intf)->descriptor.bcdDevice); 312 const u16 bcdDevice = le16_to_cpu(interface_to_usbdev(intf)->descriptor.bcdDevice);
@@ -295,24 +315,24 @@ static int speedtch_find_firmware(struct usb_interface *intf, int phase,
295 char buf[24]; 315 char buf[24];
296 316
297 sprintf(buf, "speedtch-%d.bin.%x.%02x", phase, major_revision, minor_revision); 317 sprintf(buf, "speedtch-%d.bin.%x.%02x", phase, major_revision, minor_revision);
298 dev_dbg(dev, "%s: looking for %s\n", __func__, buf); 318 usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf);
299 319
300 if (request_firmware(fw_p, buf, dev)) { 320 if (request_firmware(fw_p, buf, dev)) {
301 sprintf(buf, "speedtch-%d.bin.%x", phase, major_revision); 321 sprintf(buf, "speedtch-%d.bin.%x", phase, major_revision);
302 dev_dbg(dev, "%s: looking for %s\n", __func__, buf); 322 usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf);
303 323
304 if (request_firmware(fw_p, buf, dev)) { 324 if (request_firmware(fw_p, buf, dev)) {
305 sprintf(buf, "speedtch-%d.bin", phase); 325 sprintf(buf, "speedtch-%d.bin", phase);
306 dev_dbg(dev, "%s: looking for %s\n", __func__, buf); 326 usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf);
307 327
308 if (request_firmware(fw_p, buf, dev)) { 328 if (request_firmware(fw_p, buf, dev)) {
309 dev_warn(dev, "no stage %d firmware found!\n", phase); 329 usb_err(usbatm, "%s: no stage %d firmware found!\n", __func__, phase);
310 return -ENOENT; 330 return -ENOENT;
311 } 331 }
312 } 332 }
313 } 333 }
314 334
315 dev_info(dev, "found stage %d firmware %s\n", phase, buf); 335 usb_info(usbatm, "found stage %d firmware %s\n", phase, buf);
316 336
317 return 0; 337 return 0;
318} 338}
@@ -323,15 +343,16 @@ static int speedtch_heavy_init(struct usbatm_data *usbatm, struct usb_interface
323 struct speedtch_instance_data *instance = usbatm->driver_data; 343 struct speedtch_instance_data *instance = usbatm->driver_data;
324 int ret; 344 int ret;
325 345
326 if ((ret = speedtch_find_firmware(intf, 1, &fw1)) < 0) 346 if ((ret = speedtch_find_firmware(usbatm, intf, 1, &fw1)) < 0)
327 return ret; 347 return ret;
328 348
329 if ((ret = speedtch_find_firmware(intf, 2, &fw2)) < 0) { 349 if ((ret = speedtch_find_firmware(usbatm, intf, 2, &fw2)) < 0) {
330 release_firmware(fw1); 350 release_firmware(fw1);
331 return ret; 351 return ret;
332 } 352 }
333 353
334 ret = speedtch_upload_firmware(instance, fw1, fw2); 354 if ((ret = speedtch_upload_firmware(instance, fw1, fw2)) < 0)
355 usb_err(usbatm, "%s: firmware upload failed (%d)!\n", __func__, ret);
335 356
336 release_firmware(fw2); 357 release_firmware(fw2);
337 release_firmware(fw1); 358 release_firmware(fw1);
@@ -428,7 +449,9 @@ static void speedtch_check_status(struct speedtch_instance_data *instance)
428 int down_speed, up_speed, ret; 449 int down_speed, up_speed, ret;
429 unsigned char status; 450 unsigned char status;
430 451
452#ifdef VERBOSE_DEBUG
431 atm_dbg(usbatm, "%s entered\n", __func__); 453 atm_dbg(usbatm, "%s entered\n", __func__);
454#endif
432 455
433 ret = speedtch_read_status(instance); 456 ret = speedtch_read_status(instance);
434 if (ret < 0) { 457 if (ret < 0) {
@@ -441,9 +464,9 @@ static void speedtch_check_status(struct speedtch_instance_data *instance)
441 464
442 status = buf[OFFSET_7]; 465 status = buf[OFFSET_7];
443 466
444 atm_dbg(usbatm, "%s: line state %02x\n", __func__, status);
445
446 if ((status != instance->last_status) || !status) { 467 if ((status != instance->last_status) || !status) {
468 atm_dbg(usbatm, "%s: line state 0x%02x\n", __func__, status);
469
447 switch (status) { 470 switch (status) {
448 case 0: 471 case 0:
449 atm_dev->signal = ATM_PHY_SIG_LOST; 472 atm_dev->signal = ATM_PHY_SIG_LOST;
@@ -484,7 +507,7 @@ static void speedtch_check_status(struct speedtch_instance_data *instance)
484 507
485 default: 508 default:
486 atm_dev->signal = ATM_PHY_SIG_UNKNOWN; 509 atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
487 atm_info(usbatm, "Unknown line state %02x\n", status); 510 atm_info(usbatm, "unknown line state %02x\n", status);
488 break; 511 break;
489 } 512 }
490 513
@@ -583,11 +606,6 @@ static int speedtch_atm_start(struct usbatm_data *usbatm, struct atm_dev *atm_de
583 606
584 atm_dbg(usbatm, "%s entered\n", __func__); 607 atm_dbg(usbatm, "%s entered\n", __func__);
585 608
586 if ((ret = usb_set_interface(usb_dev, 1, altsetting)) < 0) {
587 atm_dbg(usbatm, "%s: usb_set_interface returned %d!\n", __func__, ret);
588 return ret;
589 }
590
591 /* Set MAC address, it is stored in the serial number */ 609 /* Set MAC address, it is stored in the serial number */
592 memset(atm_dev->esi, 0, sizeof(atm_dev->esi)); 610 memset(atm_dev->esi, 0, sizeof(atm_dev->esi));
593 if (usb_string(usb_dev, usb_dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) { 611 if (usb_string(usb_dev, usb_dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) {
@@ -678,20 +696,27 @@ static void speedtch_release_interfaces(struct usb_device *usb_dev, int num_inte
678 696
679static int speedtch_bind(struct usbatm_data *usbatm, 697static int speedtch_bind(struct usbatm_data *usbatm,
680 struct usb_interface *intf, 698 struct usb_interface *intf,
681 const struct usb_device_id *id, 699 const struct usb_device_id *id)
682 int *need_heavy_init)
683{ 700{
684 struct usb_device *usb_dev = interface_to_usbdev(intf); 701 struct usb_device *usb_dev = interface_to_usbdev(intf);
685 struct usb_interface *cur_intf; 702 struct usb_interface *cur_intf, *data_intf;
686 struct speedtch_instance_data *instance; 703 struct speedtch_instance_data *instance;
687 int ifnum = intf->altsetting->desc.bInterfaceNumber; 704 int ifnum = intf->altsetting->desc.bInterfaceNumber;
688 int num_interfaces = usb_dev->actconfig->desc.bNumInterfaces; 705 int num_interfaces = usb_dev->actconfig->desc.bNumInterfaces;
689 int i, ret; 706 int i, ret;
707 int use_isoc;
690 708
691 usb_dbg(usbatm, "%s entered\n", __func__); 709 usb_dbg(usbatm, "%s entered\n", __func__);
692 710
711 /* sanity checks */
712
693 if (usb_dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) { 713 if (usb_dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) {
694 usb_dbg(usbatm, "%s: wrong device class %d\n", __func__, usb_dev->descriptor.bDeviceClass); 714 usb_err(usbatm, "%s: wrong device class %d\n", __func__, usb_dev->descriptor.bDeviceClass);
715 return -ENODEV;
716 }
717
718 if (!(data_intf = usb_ifnum_to_if(usb_dev, INTERFACE_DATA))) {
719 usb_err(usbatm, "%s: data interface not found!\n", __func__);
695 return -ENODEV; 720 return -ENODEV;
696 } 721 }
697 722
@@ -704,25 +729,71 @@ static int speedtch_bind(struct usbatm_data *usbatm,
704 ret = usb_driver_claim_interface(&speedtch_usb_driver, cur_intf, usbatm); 729 ret = usb_driver_claim_interface(&speedtch_usb_driver, cur_intf, usbatm);
705 730
706 if (ret < 0) { 731 if (ret < 0) {
707 usb_dbg(usbatm, "%s: failed to claim interface %d (%d)\n", __func__, i, ret); 732 usb_err(usbatm, "%s: failed to claim interface %2d (%d)!\n", __func__, i, ret);
708 speedtch_release_interfaces(usb_dev, i); 733 speedtch_release_interfaces(usb_dev, i);
709 return ret; 734 return ret;
710 } 735 }
711 } 736 }
712 } 737 }
713 738
714 instance = kmalloc(sizeof(*instance), GFP_KERNEL); 739 instance = kzalloc(sizeof(*instance), GFP_KERNEL);
715 740
716 if (!instance) { 741 if (!instance) {
717 usb_dbg(usbatm, "%s: no memory for instance data!\n", __func__); 742 usb_err(usbatm, "%s: no memory for instance data!\n", __func__);
718 ret = -ENOMEM; 743 ret = -ENOMEM;
719 goto fail_release; 744 goto fail_release;
720 } 745 }
721 746
722 memset(instance, 0, sizeof(struct speedtch_instance_data));
723
724 instance->usbatm = usbatm; 747 instance->usbatm = usbatm;
725 748
749 /* altsetting and enable_isoc may change at any moment, so take a snapshot */
750 instance->altsetting = altsetting;
751 use_isoc = enable_isoc;
752
753 if (instance->altsetting)
754 if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, instance->altsetting)) < 0) {
755 usb_err(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, instance->altsetting, ret);
756 instance->altsetting = 0; /* fall back to default */
757 }
758
759 if (!instance->altsetting && use_isoc)
760 if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, DEFAULT_ISOC_ALTSETTING)) < 0) {
761 usb_dbg(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, DEFAULT_ISOC_ALTSETTING, ret);
762 use_isoc = 0; /* fall back to bulk */
763 }
764
765 if (use_isoc) {
766 const struct usb_host_interface *desc = data_intf->cur_altsetting;
767 const __u8 target_address = USB_DIR_IN | usbatm->driver->isoc_in;
768 int i;
769
770 use_isoc = 0; /* fall back to bulk if endpoint not found */
771
772 for (i=0; i<desc->desc.bNumEndpoints; i++) {
773 const struct usb_endpoint_descriptor *endpoint_desc = &desc->endpoint[i].desc;
774
775 if ((endpoint_desc->bEndpointAddress == target_address)) {
776 use_isoc = (endpoint_desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
777 USB_ENDPOINT_XFER_ISOC;
778 break;
779 }
780 }
781
782 if (!use_isoc)
783 usb_info(usbatm, "isochronous transfer not supported - using bulk\n");
784 }
785
786 if (!use_isoc && !instance->altsetting)
787 if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, DEFAULT_BULK_ALTSETTING)) < 0) {
788 usb_err(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, DEFAULT_BULK_ALTSETTING, ret);
789 goto fail_free;
790 }
791
792 if (!instance->altsetting)
793 instance->altsetting = use_isoc ? DEFAULT_ISOC_ALTSETTING : DEFAULT_BULK_ALTSETTING;
794
795 usbatm->flags |= (use_isoc ? UDSL_USE_ISOC : 0);
796
726 INIT_WORK(&instance->status_checker, (void *)speedtch_check_status, instance); 797 INIT_WORK(&instance->status_checker, (void *)speedtch_check_status, instance);
727 798
728 instance->status_checker.timer.function = speedtch_status_poll; 799 instance->status_checker.timer.function = speedtch_status_poll;
@@ -749,13 +820,15 @@ static int speedtch_bind(struct usbatm_data *usbatm,
749 0x12, 0xc0, 0x07, 0x00, 820 0x12, 0xc0, 0x07, 0x00,
750 instance->scratch_buffer + OFFSET_7, SIZE_7, 500); 821 instance->scratch_buffer + OFFSET_7, SIZE_7, 500);
751 822
752 *need_heavy_init = (ret != SIZE_7); 823 usbatm->flags |= (ret == SIZE_7 ? UDSL_SKIP_HEAVY_INIT : 0);
753 824
754 usb_dbg(usbatm, "%s: firmware %s loaded\n", __func__, need_heavy_init ? "not" : "already"); 825 usb_dbg(usbatm, "%s: firmware %s loaded\n", __func__, usbatm->flags & UDSL_SKIP_HEAVY_INIT ? "already" : "not");
755 826
756 if (*need_heavy_init) 827 if (!(usbatm->flags & UDSL_SKIP_HEAVY_INIT))
757 if ((ret = usb_reset_device(usb_dev)) < 0) 828 if ((ret = usb_reset_device(usb_dev)) < 0) {
829 usb_err(usbatm, "%s: device reset failed (%d)!\n", __func__, ret);
758 goto fail_free; 830 goto fail_free;
831 }
759 832
760 usbatm->driver_data = instance; 833 usbatm->driver_data = instance;
761 834
@@ -787,15 +860,15 @@ static void speedtch_unbind(struct usbatm_data *usbatm, struct usb_interface *in
787***********/ 860***********/
788 861
789static struct usbatm_driver speedtch_usbatm_driver = { 862static struct usbatm_driver speedtch_usbatm_driver = {
790 .owner = THIS_MODULE,
791 .driver_name = speedtch_driver_name, 863 .driver_name = speedtch_driver_name,
792 .bind = speedtch_bind, 864 .bind = speedtch_bind,
793 .heavy_init = speedtch_heavy_init, 865 .heavy_init = speedtch_heavy_init,
794 .unbind = speedtch_unbind, 866 .unbind = speedtch_unbind,
795 .atm_start = speedtch_atm_start, 867 .atm_start = speedtch_atm_start,
796 .atm_stop = speedtch_atm_stop, 868 .atm_stop = speedtch_atm_stop,
797 .in = ENDPOINT_DATA, 869 .bulk_in = ENDPOINT_BULK_DATA,
798 .out = ENDPOINT_DATA 870 .bulk_out = ENDPOINT_BULK_DATA,
871 .isoc_in = ENDPOINT_ISOC_DATA
799}; 872};
800 873
801static int speedtch_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) 874static int speedtch_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index 7d2a679989ed..830d2c982670 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -63,11 +63,12 @@
63#include <linux/ctype.h> 63#include <linux/ctype.h>
64#include <linux/kthread.h> 64#include <linux/kthread.h>
65#include <linux/version.h> 65#include <linux/version.h>
66#include <linux/mutex.h>
66#include <asm/unaligned.h> 67#include <asm/unaligned.h>
67 68
68#include "usbatm.h" 69#include "usbatm.h"
69 70
70#define EAGLEUSBVERSION "ueagle 1.1" 71#define EAGLEUSBVERSION "ueagle 1.2"
71 72
72 73
73/* 74/*
@@ -358,16 +359,19 @@ struct intr_pkt {
358#define INTR_PKT_SIZE 28 359#define INTR_PKT_SIZE 28
359 360
360static struct usb_driver uea_driver; 361static struct usb_driver uea_driver;
361static DECLARE_MUTEX(uea_semaphore); 362static DEFINE_MUTEX(uea_mutex);
362static const char *chip_name[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III"}; 363static const char *chip_name[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III"};
363 364
364static int modem_index; 365static int modem_index;
365static unsigned int debug; 366static unsigned int debug;
367static int use_iso[NB_MODEM] = {[0 ... (NB_MODEM - 1)] = 1};
366static int sync_wait[NB_MODEM]; 368static int sync_wait[NB_MODEM];
367static char *cmv_file[NB_MODEM]; 369static char *cmv_file[NB_MODEM];
368 370
369module_param(debug, uint, 0644); 371module_param(debug, uint, 0644);
370MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)"); 372MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)");
373module_param_array(use_iso, bool, NULL, 0644);
374MODULE_PARM_DESC(use_iso, "use isochronous usb pipe for incoming traffic");
371module_param_array(sync_wait, bool, NULL, 0644); 375module_param_array(sync_wait, bool, NULL, 0644);
372MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM"); 376MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM");
373module_param_array(cmv_file, charp, NULL, 0644); 377module_param_array(cmv_file, charp, NULL, 0644);
@@ -628,8 +632,7 @@ static int request_dsp(struct uea_softc *sc)
628 dsp_name = FW_DIR "DSPep.bin"; 632 dsp_name = FW_DIR "DSPep.bin";
629 } 633 }
630 634
631 ret = request_firmware(&sc->dsp_firm, 635 ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev);
632 dsp_name, &sc->usb_dev->dev);
633 if (ret < 0) { 636 if (ret < 0) {
634 uea_err(INS_TO_USBDEV(sc), 637 uea_err(INS_TO_USBDEV(sc),
635 "requesting firmware %s failed with error %d\n", 638 "requesting firmware %s failed with error %d\n",
@@ -744,7 +747,6 @@ static inline int wait_cmv_ack(struct uea_softc *sc)
744 return ret; 747 return ret;
745 748
746 return (ret == 0) ? -ETIMEDOUT : 0; 749 return (ret == 0) ? -ETIMEDOUT : 0;
747
748} 750}
749 751
750#define UCDC_SEND_ENCAPSULATED_COMMAND 0x00 752#define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
@@ -935,6 +937,7 @@ static int uea_stat(struct uea_softc *sc)
935 * ADI930 don't support it (-EPIPE error). 937 * ADI930 don't support it (-EPIPE error).
936 */ 938 */
937 if (UEA_CHIP_VERSION(sc) != ADI930 939 if (UEA_CHIP_VERSION(sc) != ADI930
940 && !use_iso[sc->modem_index]
938 && sc->stats.phy.dsrate != (data >> 16) * 32) { 941 && sc->stats.phy.dsrate != (data >> 16) * 32) {
939 /* Original timming from ADI(used in windows driver) 942 /* Original timming from ADI(used in windows driver)
940 * 0x20ffff>>16 * 32 = 32 * 32 = 1Mbits 943 * 0x20ffff>>16 * 32 = 32 * 32 = 1Mbits
@@ -1010,7 +1013,7 @@ static int request_cmvs(struct uea_softc *sc,
1010 int ret, size; 1013 int ret, size;
1011 u8 *data; 1014 u8 *data;
1012 char *file; 1015 char *file;
1013 static char cmv_name[256] = FW_DIR; 1016 char cmv_name[FIRMWARE_NAME_MAX]; /* 30 bytes stack variable */
1014 1017
1015 if (cmv_file[sc->modem_index] == NULL) { 1018 if (cmv_file[sc->modem_index] == NULL) {
1016 if (UEA_CHIP_VERSION(sc) == ADI930) 1019 if (UEA_CHIP_VERSION(sc) == ADI930)
@@ -1184,8 +1187,7 @@ static int load_XILINX_firmware(struct uea_softc *sc)
1184 } 1187 }
1185 } 1188 }
1186 1189
1187 /* finish to send the fpga 1190 /* finish to send the fpga */
1188 */
1189 ret = uea_request(sc, 0xe, 1, 0, NULL); 1191 ret = uea_request(sc, 0xe, 1, 0, NULL);
1190 if (ret < 0) { 1192 if (ret < 0) {
1191 uea_err(INS_TO_USBDEV(sc), 1193 uea_err(INS_TO_USBDEV(sc),
@@ -1193,9 +1195,7 @@ static int load_XILINX_firmware(struct uea_softc *sc)
1193 goto err1; 1195 goto err1;
1194 } 1196 }
1195 1197
1196 /* 1198 /* Tell the modem we finish : de-assert reset */
1197 * Tell the modem we finish : de-assert reset
1198 */
1199 value = 0; 1199 value = 0;
1200 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value); 1200 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1201 if (ret < 0) 1201 if (ret < 0)
@@ -1209,6 +1209,7 @@ err0:
1209 return ret; 1209 return ret;
1210} 1210}
1211 1211
1212/* The modem send us an ack. First with check if it right */
1212static void uea_dispatch_cmv(struct uea_softc *sc, struct cmv* cmv) 1213static void uea_dispatch_cmv(struct uea_softc *sc, struct cmv* cmv)
1213{ 1214{
1214 uea_enters(INS_TO_USBDEV(sc)); 1215 uea_enters(INS_TO_USBDEV(sc));
@@ -1268,23 +1269,19 @@ bad1:
1268 */ 1269 */
1269static void uea_intr(struct urb *urb, struct pt_regs *regs) 1270static void uea_intr(struct urb *urb, struct pt_regs *regs)
1270{ 1271{
1271 struct uea_softc *sc = (struct uea_softc *)urb->context; 1272 struct uea_softc *sc = urb->context;
1272 struct intr_pkt *intr; 1273 struct intr_pkt *intr = urb->transfer_buffer;
1273 uea_enters(INS_TO_USBDEV(sc)); 1274 uea_enters(INS_TO_USBDEV(sc));
1274 1275
1275 if (urb->status < 0) { 1276 if (unlikely(urb->status < 0)) {
1276 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n", 1277 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
1277 urb->status); 1278 urb->status);
1278 return; 1279 return;
1279 } 1280 }
1280 1281
1281 intr = (struct intr_pkt *) urb->transfer_buffer;
1282
1283 /* device-to-host interrupt */ 1282 /* device-to-host interrupt */
1284 if (intr->bType != 0x08 || sc->booting) { 1283 if (intr->bType != 0x08 || sc->booting) {
1285 uea_err(INS_TO_USBDEV(sc), "wrong intr\n"); 1284 uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n");
1286 // rebooting ?
1287 // sc->reset = 1;
1288 goto resubmit; 1285 goto resubmit;
1289 } 1286 }
1290 1287
@@ -1300,7 +1297,7 @@ static void uea_intr(struct urb *urb, struct pt_regs *regs)
1300 break; 1297 break;
1301 1298
1302 default: 1299 default:
1303 uea_err(INS_TO_USBDEV(sc), "unknown intr %u\n", 1300 uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n",
1304 le16_to_cpu(intr->wInterrupt)); 1301 le16_to_cpu(intr->wInterrupt));
1305 } 1302 }
1306 1303
@@ -1379,7 +1376,7 @@ static void uea_stop(struct uea_softc *sc)
1379 int ret; 1376 int ret;
1380 uea_enters(INS_TO_USBDEV(sc)); 1377 uea_enters(INS_TO_USBDEV(sc));
1381 ret = kthread_stop(sc->kthread); 1378 ret = kthread_stop(sc->kthread);
1382 uea_info(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret); 1379 uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
1383 1380
1384 /* stop any pending boot process */ 1381 /* stop any pending boot process */
1385 flush_scheduled_work(); 1382 flush_scheduled_work();
@@ -1418,13 +1415,13 @@ static ssize_t read_status(struct device *dev, struct device_attribute *attr,
1418 int ret = -ENODEV; 1415 int ret = -ENODEV;
1419 struct uea_softc *sc; 1416 struct uea_softc *sc;
1420 1417
1421 down(&uea_semaphore); 1418 mutex_lock(&uea_mutex);
1422 sc = dev_to_uea(dev); 1419 sc = dev_to_uea(dev);
1423 if (!sc) 1420 if (!sc)
1424 goto out; 1421 goto out;
1425 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state); 1422 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
1426out: 1423out:
1427 up(&uea_semaphore); 1424 mutex_unlock(&uea_mutex);
1428 return ret; 1425 return ret;
1429} 1426}
1430 1427
@@ -1434,14 +1431,14 @@ static ssize_t reboot(struct device *dev, struct device_attribute *attr,
1434 int ret = -ENODEV; 1431 int ret = -ENODEV;
1435 struct uea_softc *sc; 1432 struct uea_softc *sc;
1436 1433
1437 down(&uea_semaphore); 1434 mutex_lock(&uea_mutex);
1438 sc = dev_to_uea(dev); 1435 sc = dev_to_uea(dev);
1439 if (!sc) 1436 if (!sc)
1440 goto out; 1437 goto out;
1441 sc->reset = 1; 1438 sc->reset = 1;
1442 ret = count; 1439 ret = count;
1443out: 1440out:
1444 up(&uea_semaphore); 1441 mutex_unlock(&uea_mutex);
1445 return ret; 1442 return ret;
1446} 1443}
1447 1444
@@ -1453,7 +1450,7 @@ static ssize_t read_human_status(struct device *dev, struct device_attribute *at
1453 int ret = -ENODEV; 1450 int ret = -ENODEV;
1454 struct uea_softc *sc; 1451 struct uea_softc *sc;
1455 1452
1456 down(&uea_semaphore); 1453 mutex_lock(&uea_mutex);
1457 sc = dev_to_uea(dev); 1454 sc = dev_to_uea(dev);
1458 if (!sc) 1455 if (!sc)
1459 goto out; 1456 goto out;
@@ -1473,7 +1470,7 @@ static ssize_t read_human_status(struct device *dev, struct device_attribute *at
1473 break; 1470 break;
1474 } 1471 }
1475out: 1472out:
1476 up(&uea_semaphore); 1473 mutex_unlock(&uea_mutex);
1477 return ret; 1474 return ret;
1478} 1475}
1479 1476
@@ -1485,7 +1482,7 @@ static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
1485 int ret = -ENODEV; 1482 int ret = -ENODEV;
1486 struct uea_softc *sc; 1483 struct uea_softc *sc;
1487 1484
1488 down(&uea_semaphore); 1485 mutex_lock(&uea_mutex);
1489 sc = dev_to_uea(dev); 1486 sc = dev_to_uea(dev);
1490 if (!sc) 1487 if (!sc)
1491 goto out; 1488 goto out;
@@ -1497,7 +1494,7 @@ static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
1497 else 1494 else
1498 ret = sprintf(buf, "GOOD\n"); 1495 ret = sprintf(buf, "GOOD\n");
1499out: 1496out:
1500 up(&uea_semaphore); 1497 mutex_unlock(&uea_mutex);
1501 return ret; 1498 return ret;
1502} 1499}
1503 1500
@@ -1511,7 +1508,7 @@ static ssize_t read_##name(struct device *dev, \
1511 int ret = -ENODEV; \ 1508 int ret = -ENODEV; \
1512 struct uea_softc *sc; \ 1509 struct uea_softc *sc; \
1513 \ 1510 \
1514 down(&uea_semaphore); \ 1511 mutex_lock(&uea_mutex); \
1515 sc = dev_to_uea(dev); \ 1512 sc = dev_to_uea(dev); \
1516 if (!sc) \ 1513 if (!sc) \
1517 goto out; \ 1514 goto out; \
@@ -1519,7 +1516,7 @@ static ssize_t read_##name(struct device *dev, \
1519 if (reset) \ 1516 if (reset) \
1520 sc->stats.phy.name = 0; \ 1517 sc->stats.phy.name = 0; \
1521out: \ 1518out: \
1522 up(&uea_semaphore); \ 1519 mutex_unlock(&uea_mutex); \
1523 return ret; \ 1520 return ret; \
1524} \ 1521} \
1525 \ 1522 \
@@ -1617,7 +1614,7 @@ static void create_fs_entries(struct uea_softc *sc, struct usb_interface *intf)
1617} 1614}
1618 1615
1619static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf, 1616static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
1620 const struct usb_device_id *id, int *heavy) 1617 const struct usb_device_id *id)
1621{ 1618{
1622 struct usb_device *usb = interface_to_usbdev(intf); 1619 struct usb_device *usb = interface_to_usbdev(intf);
1623 struct uea_softc *sc; 1620 struct uea_softc *sc;
@@ -1629,16 +1626,14 @@ static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
1629 if (ifnum != UEA_INTR_IFACE_NO) 1626 if (ifnum != UEA_INTR_IFACE_NO)
1630 return -ENODEV; 1627 return -ENODEV;
1631 1628
1632 *heavy = sync_wait[modem_index]; 1629 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
1633 1630
1634 /* interface 1 is for outbound traffic */ 1631 /* interface 1 is for outbound traffic */
1635 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO); 1632 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
1636 if (ret < 0) 1633 if (ret < 0)
1637 return ret; 1634 return ret;
1638 1635
1639 /* ADI930 has only 2 interfaces and inbound traffic 1636 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
1640 * is on interface 1
1641 */
1642 if (UEA_CHIP_VERSION(id) != ADI930) { 1637 if (UEA_CHIP_VERSION(id) != ADI930) {
1643 /* interface 2 is for inbound traffic */ 1638 /* interface 2 is for inbound traffic */
1644 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO); 1639 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
@@ -1658,6 +1653,25 @@ static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
1658 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0; 1653 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
1659 sc->driver_info = id->driver_info; 1654 sc->driver_info = id->driver_info;
1660 1655
1656 /* ADI930 don't support iso */
1657 if (UEA_CHIP_VERSION(id) != ADI930 && use_iso[sc->modem_index]) {
1658 int i;
1659
1660 /* try set fastest alternate for inbound traffic interface */
1661 for (i = FASTEST_ISO_INTF; i > 0; i--)
1662 if (usb_set_interface(usb, UEA_DS_IFACE_NO, i) == 0)
1663 break;
1664
1665 if (i > 0) {
1666 uea_dbg(usb, "set alternate %d for 2 interface\n", i);
1667 uea_info(usb, "using iso mode\n");
1668 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
1669 } else {
1670 uea_err(usb, "setting any alternate failed for "
1671 "2 interface, using bulk mode\n");
1672 }
1673 }
1674
1661 ret = uea_boot(sc); 1675 ret = uea_boot(sc);
1662 if (ret < 0) { 1676 if (ret < 0) {
1663 kfree(sc); 1677 kfree(sc);
@@ -1701,13 +1715,13 @@ static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
1701 1715
1702static struct usbatm_driver uea_usbatm_driver = { 1716static struct usbatm_driver uea_usbatm_driver = {
1703 .driver_name = "ueagle-atm", 1717 .driver_name = "ueagle-atm",
1704 .owner = THIS_MODULE,
1705 .bind = uea_bind, 1718 .bind = uea_bind,
1706 .atm_start = uea_atm_open, 1719 .atm_start = uea_atm_open,
1707 .unbind = uea_unbind, 1720 .unbind = uea_unbind,
1708 .heavy_init = uea_heavy, 1721 .heavy_init = uea_heavy,
1709 .in = UEA_BULK_DATA_PIPE, 1722 .bulk_in = UEA_BULK_DATA_PIPE,
1710 .out = UEA_BULK_DATA_PIPE, 1723 .bulk_out = UEA_BULK_DATA_PIPE,
1724 .isoc_in = UEA_ISO_DATA_PIPE,
1711}; 1725};
1712 1726
1713static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id) 1727static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
@@ -1738,9 +1752,9 @@ static void uea_disconnect(struct usb_interface *intf)
1738 * Pre-firmware device has one interface 1752 * Pre-firmware device has one interface
1739 */ 1753 */
1740 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) { 1754 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
1741 down(&uea_semaphore); 1755 mutex_lock(&uea_mutex);
1742 usbatm_usb_disconnect(intf); 1756 usbatm_usb_disconnect(intf);
1743 up(&uea_semaphore); 1757 mutex_unlock(&uea_mutex);
1744 uea_info(usb, "ADSL device removed\n"); 1758 uea_info(usb, "ADSL device removed\n");
1745 } 1759 }
1746 1760
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index 7af1883d4bf9..c1211fc037d9 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -72,6 +72,7 @@
72#include <linux/kernel.h> 72#include <linux/kernel.h>
73#include <linux/module.h> 73#include <linux/module.h>
74#include <linux/moduleparam.h> 74#include <linux/moduleparam.h>
75#include <linux/netdevice.h>
75#include <linux/proc_fs.h> 76#include <linux/proc_fs.h>
76#include <linux/sched.h> 77#include <linux/sched.h>
77#include <linux/signal.h> 78#include <linux/signal.h>
@@ -91,19 +92,18 @@ static int usbatm_print_packet(const unsigned char *data, int len);
91#endif 92#endif
92 93
93#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>" 94#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>"
94#define DRIVER_VERSION "1.9" 95#define DRIVER_VERSION "1.10"
95#define DRIVER_DESC "Generic USB ATM/DSL I/O, version " DRIVER_VERSION 96#define DRIVER_DESC "Generic USB ATM/DSL I/O, version " DRIVER_VERSION
96 97
97static const char usbatm_driver_name[] = "usbatm"; 98static const char usbatm_driver_name[] = "usbatm";
98 99
99#define UDSL_MAX_RCV_URBS 16 100#define UDSL_MAX_RCV_URBS 16
100#define UDSL_MAX_SND_URBS 16 101#define UDSL_MAX_SND_URBS 16
101#define UDSL_MAX_RCV_BUF_SIZE 1024 /* ATM cells */ 102#define UDSL_MAX_BUF_SIZE 64 * 1024 /* bytes */
102#define UDSL_MAX_SND_BUF_SIZE 1024 /* ATM cells */
103#define UDSL_DEFAULT_RCV_URBS 4 103#define UDSL_DEFAULT_RCV_URBS 4
104#define UDSL_DEFAULT_SND_URBS 4 104#define UDSL_DEFAULT_SND_URBS 4
105#define UDSL_DEFAULT_RCV_BUF_SIZE 64 /* ATM cells */ 105#define UDSL_DEFAULT_RCV_BUF_SIZE 64 * ATM_CELL_SIZE /* bytes */
106#define UDSL_DEFAULT_SND_BUF_SIZE 64 /* ATM cells */ 106#define UDSL_DEFAULT_SND_BUF_SIZE 64 * ATM_CELL_SIZE /* bytes */
107 107
108#define ATM_CELL_HEADER (ATM_CELL_SIZE - ATM_CELL_PAYLOAD) 108#define ATM_CELL_HEADER (ATM_CELL_SIZE - ATM_CELL_PAYLOAD)
109 109
@@ -111,8 +111,8 @@ static const char usbatm_driver_name[] = "usbatm";
111 111
112static unsigned int num_rcv_urbs = UDSL_DEFAULT_RCV_URBS; 112static unsigned int num_rcv_urbs = UDSL_DEFAULT_RCV_URBS;
113static unsigned int num_snd_urbs = UDSL_DEFAULT_SND_URBS; 113static unsigned int num_snd_urbs = UDSL_DEFAULT_SND_URBS;
114static unsigned int rcv_buf_size = UDSL_DEFAULT_RCV_BUF_SIZE; 114static unsigned int rcv_buf_bytes = UDSL_DEFAULT_RCV_BUF_SIZE;
115static unsigned int snd_buf_size = UDSL_DEFAULT_SND_BUF_SIZE; 115static unsigned int snd_buf_bytes = UDSL_DEFAULT_SND_BUF_SIZE;
116 116
117module_param(num_rcv_urbs, uint, S_IRUGO); 117module_param(num_rcv_urbs, uint, S_IRUGO);
118MODULE_PARM_DESC(num_rcv_urbs, 118MODULE_PARM_DESC(num_rcv_urbs,
@@ -126,15 +126,15 @@ MODULE_PARM_DESC(num_snd_urbs,
126 __MODULE_STRING(UDSL_MAX_SND_URBS) ", default: " 126 __MODULE_STRING(UDSL_MAX_SND_URBS) ", default: "
127 __MODULE_STRING(UDSL_DEFAULT_SND_URBS) ")"); 127 __MODULE_STRING(UDSL_DEFAULT_SND_URBS) ")");
128 128
129module_param(rcv_buf_size, uint, S_IRUGO); 129module_param(rcv_buf_bytes, uint, S_IRUGO);
130MODULE_PARM_DESC(rcv_buf_size, 130MODULE_PARM_DESC(rcv_buf_bytes,
131 "Size of the buffers used for reception in ATM cells (range: 1-" 131 "Size of the buffers used for reception, in bytes (range: 1-"
132 __MODULE_STRING(UDSL_MAX_RCV_BUF_SIZE) ", default: " 132 __MODULE_STRING(UDSL_MAX_BUF_SIZE) ", default: "
133 __MODULE_STRING(UDSL_DEFAULT_RCV_BUF_SIZE) ")"); 133 __MODULE_STRING(UDSL_DEFAULT_RCV_BUF_SIZE) ")");
134 134
135module_param(snd_buf_size, uint, S_IRUGO); 135module_param(snd_buf_bytes, uint, S_IRUGO);
136MODULE_PARM_DESC(snd_buf_size, 136MODULE_PARM_DESC(snd_buf_bytes,
137 "Size of the buffers used for transmission in ATM cells (range: 1-" 137 "Size of the buffers used for transmission, in bytes (range: 1-"
138 __MODULE_STRING(UDSL_MAX_SND_BUF_SIZE) ", default: " 138 __MODULE_STRING(UDSL_MAX_SND_BUF_SIZE) ", default: "
139 __MODULE_STRING(UDSL_DEFAULT_SND_BUF_SIZE) ")"); 139 __MODULE_STRING(UDSL_DEFAULT_SND_BUF_SIZE) ")");
140 140
@@ -166,10 +166,10 @@ struct usbatm_control {
166 166
167/* ATM */ 167/* ATM */
168 168
169static void usbatm_atm_dev_close(struct atm_dev *dev); 169static void usbatm_atm_dev_close(struct atm_dev *atm_dev);
170static int usbatm_atm_open(struct atm_vcc *vcc); 170static int usbatm_atm_open(struct atm_vcc *vcc);
171static void usbatm_atm_close(struct atm_vcc *vcc); 171static void usbatm_atm_close(struct atm_vcc *vcc);
172static int usbatm_atm_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg); 172static int usbatm_atm_ioctl(struct atm_dev *atm_dev, unsigned int cmd, void __user * arg);
173static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb); 173static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb);
174static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page); 174static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page);
175 175
@@ -199,7 +199,7 @@ static inline void usbatm_pop(struct atm_vcc *vcc, struct sk_buff *skb)
199 if (vcc->pop) 199 if (vcc->pop)
200 vcc->pop(vcc, skb); 200 vcc->pop(vcc, skb);
201 else 201 else
202 dev_kfree_skb(skb); 202 dev_kfree_skb_any(skb);
203} 203}
204 204
205 205
@@ -234,8 +234,9 @@ static int usbatm_submit_urb(struct urb *urb)
234 234
235 ret = usb_submit_urb(urb, GFP_ATOMIC); 235 ret = usb_submit_urb(urb, GFP_ATOMIC);
236 if (ret) { 236 if (ret) {
237 atm_dbg(channel->usbatm, "%s: urb 0x%p submission failed (%d)!\n", 237 if (printk_ratelimit())
238 __func__, urb, ret); 238 atm_warn(channel->usbatm, "%s: urb 0x%p submission failed (%d)!\n",
239 __func__, urb, ret);
239 240
240 /* consider all errors transient and return the buffer back to the queue */ 241 /* consider all errors transient and return the buffer back to the queue */
241 urb->status = -EAGAIN; 242 urb->status = -EAGAIN;
@@ -269,10 +270,16 @@ static void usbatm_complete(struct urb *urb, struct pt_regs *regs)
269 270
270 spin_unlock_irqrestore(&channel->lock, flags); 271 spin_unlock_irqrestore(&channel->lock, flags);
271 272
272 if (unlikely(urb->status)) 273 if (unlikely(urb->status) &&
274 (!(channel->usbatm->flags & UDSL_IGNORE_EILSEQ) ||
275 urb->status != -EILSEQ ))
276 {
277 if (printk_ratelimit())
278 atm_warn(channel->usbatm, "%s: urb 0x%p failed (%d)!\n",
279 __func__, urb, urb->status);
273 /* throttle processing in case of an error */ 280 /* throttle processing in case of an error */
274 mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS)); 281 mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS));
275 else 282 } else
276 tasklet_schedule(&channel->tasklet); 283 tasklet_schedule(&channel->tasklet);
277} 284}
278 285
@@ -284,129 +291,167 @@ static void usbatm_complete(struct urb *urb, struct pt_regs *regs)
284static inline struct usbatm_vcc_data *usbatm_find_vcc(struct usbatm_data *instance, 291static inline struct usbatm_vcc_data *usbatm_find_vcc(struct usbatm_data *instance,
285 short vpi, int vci) 292 short vpi, int vci)
286{ 293{
287 struct usbatm_vcc_data *vcc; 294 struct usbatm_vcc_data *vcc_data;
288 295
289 list_for_each_entry(vcc, &instance->vcc_list, list) 296 list_for_each_entry(vcc_data, &instance->vcc_list, list)
290 if ((vcc->vci == vci) && (vcc->vpi == vpi)) 297 if ((vcc_data->vci == vci) && (vcc_data->vpi == vpi))
291 return vcc; 298 return vcc_data;
292 return NULL; 299 return NULL;
293} 300}
294 301
295static void usbatm_extract_cells(struct usbatm_data *instance, 302static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char *source)
296 unsigned char *source, unsigned int avail_data)
297{ 303{
298 struct usbatm_vcc_data *cached_vcc = NULL;
299 struct atm_vcc *vcc; 304 struct atm_vcc *vcc;
300 struct sk_buff *sarb; 305 struct sk_buff *sarb;
301 unsigned int stride = instance->rx_channel.stride; 306 short vpi = ((source[0] & 0x0f) << 4) | (source[1] >> 4);
302 int vci, cached_vci = 0; 307 int vci = ((source[1] & 0x0f) << 12) | (source[2] << 4) | (source[3] >> 4);
303 short vpi, cached_vpi = 0; 308 u8 pti = ((source[3] & 0xe) >> 1);
304 u8 pti;
305 309
306 for (; avail_data >= stride; avail_data -= stride, source += stride) { 310 vdbg("%s: vpi %hd, vci %d, pti %d", __func__, vpi, vci, pti);
307 vpi = ((source[0] & 0x0f) << 4) | (source[1] >> 4);
308 vci = ((source[1] & 0x0f) << 12) | (source[2] << 4) | (source[3] >> 4);
309 pti = ((source[3] & 0xe) >> 1);
310 311
311 vdbg("%s: vpi %hd, vci %d, pti %d", __func__, vpi, vci, pti); 312 if ((vci != instance->cached_vci) || (vpi != instance->cached_vpi)) {
313 instance->cached_vpi = vpi;
314 instance->cached_vci = vci;
312 315
313 if ((vci != cached_vci) || (vpi != cached_vpi)) { 316 instance->cached_vcc = usbatm_find_vcc(instance, vpi, vci);
314 cached_vpi = vpi;
315 cached_vci = vci;
316 317
317 cached_vcc = usbatm_find_vcc(instance, vpi, vci); 318 if (!instance->cached_vcc)
319 atm_rldbg(instance, "%s: unknown vpi/vci (%hd/%d)!\n", __func__, vpi, vci);
320 }
318 321
319 if (!cached_vcc) 322 if (!instance->cached_vcc)
320 atm_dbg(instance, "%s: unknown vpi/vci (%hd/%d)!\n", __func__, vpi, vci); 323 return;
321 }
322 324
323 if (!cached_vcc) 325 vcc = instance->cached_vcc->vcc;
324 continue;
325 326
326 vcc = cached_vcc->vcc; 327 /* OAM F5 end-to-end */
328 if (pti == ATM_PTI_E2EF5) {
329 if (printk_ratelimit())
330 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
331 __func__, vpi, vci);
332 atomic_inc(&vcc->stats->rx_err);
333 return;
334 }
327 335
328 /* OAM F5 end-to-end */ 336 sarb = instance->cached_vcc->sarb;
329 if (pti == ATM_PTI_E2EF5) {
330 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n", __func__, vpi, vci);
331 atomic_inc(&vcc->stats->rx_err);
332 continue;
333 }
334 337
335 sarb = cached_vcc->sarb; 338 if (sarb->tail + ATM_CELL_PAYLOAD > sarb->end) {
339 atm_rldbg(instance, "%s: buffer overrun (sarb->len %u, vcc: 0x%p)!\n",
340 __func__, sarb->len, vcc);
341 /* discard cells already received */
342 skb_trim(sarb, 0);
343 UDSL_ASSERT(sarb->tail + ATM_CELL_PAYLOAD <= sarb->end);
344 }
336 345
337 if (sarb->tail + ATM_CELL_PAYLOAD > sarb->end) { 346 memcpy(sarb->tail, source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD);
338 atm_dbg(instance, "%s: buffer overrun (sarb->len %u, vcc: 0x%p)!\n", 347 __skb_put(sarb, ATM_CELL_PAYLOAD);
339 __func__, sarb->len, vcc);
340 /* discard cells already received */
341 skb_trim(sarb, 0);
342 UDSL_ASSERT(sarb->tail + ATM_CELL_PAYLOAD <= sarb->end);
343 }
344 348
345 memcpy(sarb->tail, source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD); 349 if (pti & 1) {
346 __skb_put(sarb, ATM_CELL_PAYLOAD); 350 struct sk_buff *skb;
351 unsigned int length;
352 unsigned int pdu_length;
347 353
348 if (pti & 1) { 354 length = (source[ATM_CELL_SIZE - 6] << 8) + source[ATM_CELL_SIZE - 5];
349 struct sk_buff *skb;
350 unsigned int length;
351 unsigned int pdu_length;
352 355
353 length = (source[ATM_CELL_SIZE - 6] << 8) + source[ATM_CELL_SIZE - 5]; 356 /* guard against overflow */
357 if (length > ATM_MAX_AAL5_PDU) {
358 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
359 __func__, length, vcc);
360 atomic_inc(&vcc->stats->rx_err);
361 goto out;
362 }
354 363
355 /* guard against overflow */ 364 pdu_length = usbatm_pdu_length(length);
356 if (length > ATM_MAX_AAL5_PDU) {
357 atm_dbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
358 __func__, length, vcc);
359 atomic_inc(&vcc->stats->rx_err);
360 goto out;
361 }
362 365
363 pdu_length = usbatm_pdu_length(length); 366 if (sarb->len < pdu_length) {
367 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
368 __func__, pdu_length, sarb->len, vcc);
369 atomic_inc(&vcc->stats->rx_err);
370 goto out;
371 }
364 372
365 if (sarb->len < pdu_length) { 373 if (crc32_be(~0, sarb->tail - pdu_length, pdu_length) != 0xc704dd7b) {
366 atm_dbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n", 374 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
367 __func__, pdu_length, sarb->len, vcc); 375 __func__, vcc);
368 atomic_inc(&vcc->stats->rx_err); 376 atomic_inc(&vcc->stats->rx_err);
369 goto out; 377 goto out;
370 } 378 }
371 379
372 if (crc32_be(~0, sarb->tail - pdu_length, pdu_length) != 0xc704dd7b) { 380 vdbg("%s: got packet (length: %u, pdu_length: %u, vcc: 0x%p)", __func__, length, pdu_length, vcc);
373 atm_dbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
374 __func__, vcc);
375 atomic_inc(&vcc->stats->rx_err);
376 goto out;
377 }
378 381
379 vdbg("%s: got packet (length: %u, pdu_length: %u, vcc: 0x%p)", __func__, length, pdu_length, vcc); 382 if (!(skb = dev_alloc_skb(length))) {
383 if (printk_ratelimit())
384 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
385 __func__, length);
386 atomic_inc(&vcc->stats->rx_drop);
387 goto out;
388 }
380 389
381 if (!(skb = dev_alloc_skb(length))) { 390 vdbg("%s: allocated new sk_buff (skb: 0x%p, skb->truesize: %u)", __func__, skb, skb->truesize);
382 atm_dbg(instance, "%s: no memory for skb (length: %u)!\n", __func__, length);
383 atomic_inc(&vcc->stats->rx_drop);
384 goto out;
385 }
386 391
387 vdbg("%s: allocated new sk_buff (skb: 0x%p, skb->truesize: %u)", __func__, skb, skb->truesize); 392 if (!atm_charge(vcc, skb->truesize)) {
393 atm_rldbg(instance, "%s: failed atm_charge (skb->truesize: %u)!\n",
394 __func__, skb->truesize);
395 dev_kfree_skb_any(skb);
396 goto out; /* atm_charge increments rx_drop */
397 }
388 398
389 if (!atm_charge(vcc, skb->truesize)) { 399 memcpy(skb->data, sarb->tail - pdu_length, length);
390 atm_dbg(instance, "%s: failed atm_charge (skb->truesize: %u)!\n", __func__, skb->truesize); 400 __skb_put(skb, length);
391 dev_kfree_skb(skb);
392 goto out; /* atm_charge increments rx_drop */
393 }
394 401
395 memcpy(skb->data, sarb->tail - pdu_length, length); 402 vdbg("%s: sending skb 0x%p, skb->len %u, skb->truesize %u",
396 __skb_put(skb, length); 403 __func__, skb, skb->len, skb->truesize);
397 404
398 vdbg("%s: sending skb 0x%p, skb->len %u, skb->truesize %u", 405 PACKETDEBUG(skb->data, skb->len);
399 __func__, skb, skb->len, skb->truesize);
400 406
401 PACKETDEBUG(skb->data, skb->len); 407 vcc->push(vcc, skb);
402 408
403 vcc->push(vcc, skb); 409 atomic_inc(&vcc->stats->rx);
410 out:
411 skb_trim(sarb, 0);
412 }
413}
404 414
405 atomic_inc(&vcc->stats->rx); 415static void usbatm_extract_cells(struct usbatm_data *instance,
406 out: 416 unsigned char *source, unsigned int avail_data)
407 skb_trim(sarb, 0); 417{
418 unsigned int stride = instance->rx_channel.stride;
419 unsigned int buf_usage = instance->buf_usage;
420
421 /* extract cells from incoming data, taking into account that
422 * the length of avail data may not be a multiple of stride */
423
424 if (buf_usage > 0) {
425 /* we have a partially received atm cell */
426 unsigned char *cell_buf = instance->cell_buf;
427 unsigned int space_left = stride - buf_usage;
428
429 UDSL_ASSERT(buf_usage <= stride);
430
431 if (avail_data >= space_left) {
432 /* add new data and process cell */
433 memcpy(cell_buf + buf_usage, source, space_left);
434 source += space_left;
435 avail_data -= space_left;
436 usbatm_extract_one_cell(instance, cell_buf);
437 instance->buf_usage = 0;
438 } else {
439 /* not enough data to fill the cell */
440 memcpy(cell_buf + buf_usage, source, avail_data);
441 instance->buf_usage = buf_usage + avail_data;
442 return;
408 } 443 }
409 } 444 }
445
446 for (; avail_data >= stride; avail_data -= stride, source += stride)
447 usbatm_extract_one_cell(instance, source);
448
449 if (avail_data > 0) {
450 /* length was not a multiple of stride -
451 * save remaining data for next call */
452 memcpy(instance->cell_buf, source, avail_data);
453 instance->buf_usage = avail_data;
454 }
410} 455}
411 456
412 457
@@ -420,14 +465,14 @@ static unsigned int usbatm_write_cells(struct usbatm_data *instance,
420{ 465{
421 struct usbatm_control *ctrl = UDSL_SKB(skb); 466 struct usbatm_control *ctrl = UDSL_SKB(skb);
422 struct atm_vcc *vcc = ctrl->atm.vcc; 467 struct atm_vcc *vcc = ctrl->atm.vcc;
423 unsigned int num_written; 468 unsigned int bytes_written;
424 unsigned int stride = instance->tx_channel.stride; 469 unsigned int stride = instance->tx_channel.stride;
425 470
426 vdbg("%s: skb->len=%d, avail_space=%u", __func__, skb->len, avail_space); 471 vdbg("%s: skb->len=%d, avail_space=%u", __func__, skb->len, avail_space);
427 UDSL_ASSERT(!(avail_space % stride)); 472 UDSL_ASSERT(!(avail_space % stride));
428 473
429 for (num_written = 0; num_written < avail_space && ctrl->len; 474 for (bytes_written = 0; bytes_written < avail_space && ctrl->len;
430 num_written += stride, target += stride) { 475 bytes_written += stride, target += stride) {
431 unsigned int data_len = min_t(unsigned int, skb->len, ATM_CELL_PAYLOAD); 476 unsigned int data_len = min_t(unsigned int, skb->len, ATM_CELL_PAYLOAD);
432 unsigned int left = ATM_CELL_PAYLOAD - data_len; 477 unsigned int left = ATM_CELL_PAYLOAD - data_len;
433 u8 *ptr = target; 478 u8 *ptr = target;
@@ -470,7 +515,7 @@ static unsigned int usbatm_write_cells(struct usbatm_data *instance,
470 ctrl->crc = crc32_be(ctrl->crc, ptr, left); 515 ctrl->crc = crc32_be(ctrl->crc, ptr, left);
471 } 516 }
472 517
473 return num_written; 518 return bytes_written;
474} 519}
475 520
476 521
@@ -487,16 +532,40 @@ static void usbatm_rx_process(unsigned long data)
487 vdbg("%s: processing urb 0x%p", __func__, urb); 532 vdbg("%s: processing urb 0x%p", __func__, urb);
488 533
489 if (usb_pipeisoc(urb->pipe)) { 534 if (usb_pipeisoc(urb->pipe)) {
535 unsigned char *merge_start = NULL;
536 unsigned int merge_length = 0;
537 const unsigned int packet_size = instance->rx_channel.packet_size;
490 int i; 538 int i;
491 for (i = 0; i < urb->number_of_packets; i++) 539
492 if (!urb->iso_frame_desc[i].status) 540 for (i = 0; i < urb->number_of_packets; i++) {
493 usbatm_extract_cells(instance, 541 if (!urb->iso_frame_desc[i].status) {
494 (u8 *)urb->transfer_buffer + urb->iso_frame_desc[i].offset, 542 unsigned int actual_length = urb->iso_frame_desc[i].actual_length;
495 urb->iso_frame_desc[i].actual_length); 543
496 } 544 UDSL_ASSERT(actual_length <= packet_size);
497 else 545
546 if (!merge_length)
547 merge_start = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset;
548 merge_length += actual_length;
549 if (merge_length && (actual_length < packet_size)) {
550 usbatm_extract_cells(instance, merge_start, merge_length);
551 merge_length = 0;
552 }
553 } else {
554 atm_rldbg(instance, "%s: status %d in frame %d!\n", __func__, urb->status, i);
555 if (merge_length)
556 usbatm_extract_cells(instance, merge_start, merge_length);
557 merge_length = 0;
558 instance->buf_usage = 0;
559 }
560 }
561
562 if (merge_length)
563 usbatm_extract_cells(instance, merge_start, merge_length);
564 } else
498 if (!urb->status) 565 if (!urb->status)
499 usbatm_extract_cells(instance, urb->transfer_buffer, urb->actual_length); 566 usbatm_extract_cells(instance, urb->transfer_buffer, urb->actual_length);
567 else
568 instance->buf_usage = 0;
500 569
501 if (usbatm_submit_urb(urb)) 570 if (usbatm_submit_urb(urb))
502 return; 571 return;
@@ -514,7 +583,7 @@ static void usbatm_tx_process(unsigned long data)
514 struct sk_buff *skb = instance->current_skb; 583 struct sk_buff *skb = instance->current_skb;
515 struct urb *urb = NULL; 584 struct urb *urb = NULL;
516 const unsigned int buf_size = instance->tx_channel.buf_size; 585 const unsigned int buf_size = instance->tx_channel.buf_size;
517 unsigned int num_written = 0; 586 unsigned int bytes_written = 0;
518 u8 *buffer = NULL; 587 u8 *buffer = NULL;
519 588
520 if (!skb) 589 if (!skb)
@@ -526,16 +595,16 @@ static void usbatm_tx_process(unsigned long data)
526 if (!urb) 595 if (!urb)
527 break; /* no more senders */ 596 break; /* no more senders */
528 buffer = urb->transfer_buffer; 597 buffer = urb->transfer_buffer;
529 num_written = (urb->status == -EAGAIN) ? 598 bytes_written = (urb->status == -EAGAIN) ?
530 urb->transfer_buffer_length : 0; 599 urb->transfer_buffer_length : 0;
531 } 600 }
532 601
533 num_written += usbatm_write_cells(instance, skb, 602 bytes_written += usbatm_write_cells(instance, skb,
534 buffer + num_written, 603 buffer + bytes_written,
535 buf_size - num_written); 604 buf_size - bytes_written);
536 605
537 vdbg("%s: wrote %u bytes from skb 0x%p to urb 0x%p", 606 vdbg("%s: wrote %u bytes from skb 0x%p to urb 0x%p",
538 __func__, num_written, skb, urb); 607 __func__, bytes_written, skb, urb);
539 608
540 if (!UDSL_SKB(skb)->len) { 609 if (!UDSL_SKB(skb)->len) {
541 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc; 610 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
@@ -546,8 +615,8 @@ static void usbatm_tx_process(unsigned long data)
546 skb = skb_dequeue(&instance->sndqueue); 615 skb = skb_dequeue(&instance->sndqueue);
547 } 616 }
548 617
549 if (num_written == buf_size || (!skb && num_written)) { 618 if (bytes_written == buf_size || (!skb && bytes_written)) {
550 urb->transfer_buffer_length = num_written; 619 urb->transfer_buffer_length = bytes_written;
551 620
552 if (usbatm_submit_urb(urb)) 621 if (usbatm_submit_urb(urb))
553 break; 622 break;
@@ -593,20 +662,24 @@ static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
593 662
594 vdbg("%s called (skb 0x%p, len %u)", __func__, skb, skb->len); 663 vdbg("%s called (skb 0x%p, len %u)", __func__, skb, skb->len);
595 664
596 if (!instance) { 665 /* racy disconnection check - fine */
597 dbg("%s: NULL data!", __func__); 666 if (!instance || instance->disconnected) {
667#ifdef DEBUG
668 if (printk_ratelimit())
669 printk(KERN_DEBUG "%s: %s!\n", __func__, instance ? "disconnected" : "NULL instance");
670#endif
598 err = -ENODEV; 671 err = -ENODEV;
599 goto fail; 672 goto fail;
600 } 673 }
601 674
602 if (vcc->qos.aal != ATM_AAL5) { 675 if (vcc->qos.aal != ATM_AAL5) {
603 atm_dbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal); 676 atm_rldbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal);
604 err = -EINVAL; 677 err = -EINVAL;
605 goto fail; 678 goto fail;
606 } 679 }
607 680
608 if (skb->len > ATM_MAX_AAL5_PDU) { 681 if (skb->len > ATM_MAX_AAL5_PDU) {
609 atm_dbg(instance, "%s: packet too long (%d vs %d)!\n", 682 atm_rldbg(instance, "%s: packet too long (%d vs %d)!\n",
610 __func__, skb->len, ATM_MAX_AAL5_PDU); 683 __func__, skb->len, ATM_MAX_AAL5_PDU);
611 err = -EINVAL; 684 err = -EINVAL;
612 goto fail; 685 goto fail;
@@ -665,16 +738,16 @@ static void usbatm_put_instance(struct usbatm_data *instance)
665** ATM ** 738** ATM **
666**********/ 739**********/
667 740
668static void usbatm_atm_dev_close(struct atm_dev *dev) 741static void usbatm_atm_dev_close(struct atm_dev *atm_dev)
669{ 742{
670 struct usbatm_data *instance = dev->dev_data; 743 struct usbatm_data *instance = atm_dev->dev_data;
671 744
672 dbg("%s", __func__); 745 dbg("%s", __func__);
673 746
674 if (!instance) 747 if (!instance)
675 return; 748 return;
676 749
677 dev->dev_data = NULL; 750 atm_dev->dev_data = NULL; /* catch bugs */
678 usbatm_put_instance(instance); /* taken in usbatm_atm_init */ 751 usbatm_put_instance(instance); /* taken in usbatm_atm_init */
679} 752}
680 753
@@ -706,15 +779,19 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
706 atomic_read(&atm_dev->stats.aal5.rx_err), 779 atomic_read(&atm_dev->stats.aal5.rx_err),
707 atomic_read(&atm_dev->stats.aal5.rx_drop)); 780 atomic_read(&atm_dev->stats.aal5.rx_drop));
708 781
709 if (!left--) 782 if (!left--) {
710 switch (atm_dev->signal) { 783 if (instance->disconnected)
711 case ATM_PHY_SIG_FOUND: 784 return sprintf(page, "Disconnected\n");
712 return sprintf(page, "Line up\n"); 785 else
713 case ATM_PHY_SIG_LOST: 786 switch (atm_dev->signal) {
714 return sprintf(page, "Line down\n"); 787 case ATM_PHY_SIG_FOUND:
715 default: 788 return sprintf(page, "Line up\n");
716 return sprintf(page, "Line state unknown\n"); 789 case ATM_PHY_SIG_LOST:
717 } 790 return sprintf(page, "Line down\n");
791 default:
792 return sprintf(page, "Line state unknown\n");
793 }
794 }
718 795
719 return 0; 796 return 0;
720} 797}
@@ -735,13 +812,24 @@ static int usbatm_atm_open(struct atm_vcc *vcc)
735 atm_dbg(instance, "%s: vpi %hd, vci %d\n", __func__, vpi, vci); 812 atm_dbg(instance, "%s: vpi %hd, vci %d\n", __func__, vpi, vci);
736 813
737 /* only support AAL5 */ 814 /* only support AAL5 */
738 if ((vcc->qos.aal != ATM_AAL5) || (vcc->qos.rxtp.max_sdu < 0) 815 if ((vcc->qos.aal != ATM_AAL5)) {
739 || (vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU)) { 816 atm_warn(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal);
740 atm_dbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal); 817 return -EINVAL;
818 }
819
820 /* sanity checks */
821 if ((vcc->qos.rxtp.max_sdu < 0) || (vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU)) {
822 atm_dbg(instance, "%s: max_sdu %d out of range!\n", __func__, vcc->qos.rxtp.max_sdu);
741 return -EINVAL; 823 return -EINVAL;
742 } 824 }
743 825
744 down(&instance->serialize); /* vs self, usbatm_atm_close */ 826 mutex_lock(&instance->serialize); /* vs self, usbatm_atm_close, usbatm_usb_disconnect */
827
828 if (instance->disconnected) {
829 atm_dbg(instance, "%s: disconnected!\n", __func__);
830 ret = -ENODEV;
831 goto fail;
832 }
745 833
746 if (usbatm_find_vcc(instance, vpi, vci)) { 834 if (usbatm_find_vcc(instance, vpi, vci)) {
747 atm_dbg(instance, "%s: %hd/%d already in use!\n", __func__, vpi, vci); 835 atm_dbg(instance, "%s: %hd/%d already in use!\n", __func__, vpi, vci);
@@ -749,20 +837,19 @@ static int usbatm_atm_open(struct atm_vcc *vcc)
749 goto fail; 837 goto fail;
750 } 838 }
751 839
752 if (!(new = kmalloc(sizeof(struct usbatm_vcc_data), GFP_KERNEL))) { 840 if (!(new = kzalloc(sizeof(struct usbatm_vcc_data), GFP_KERNEL))) {
753 atm_dbg(instance, "%s: no memory for vcc_data!\n", __func__); 841 atm_err(instance, "%s: no memory for vcc_data!\n", __func__);
754 ret = -ENOMEM; 842 ret = -ENOMEM;
755 goto fail; 843 goto fail;
756 } 844 }
757 845
758 memset(new, 0, sizeof(struct usbatm_vcc_data));
759 new->vcc = vcc; 846 new->vcc = vcc;
760 new->vpi = vpi; 847 new->vpi = vpi;
761 new->vci = vci; 848 new->vci = vci;
762 849
763 new->sarb = alloc_skb(usbatm_pdu_length(vcc->qos.rxtp.max_sdu), GFP_KERNEL); 850 new->sarb = alloc_skb(usbatm_pdu_length(vcc->qos.rxtp.max_sdu), GFP_KERNEL);
764 if (!new->sarb) { 851 if (!new->sarb) {
765 atm_dbg(instance, "%s: no memory for SAR buffer!\n", __func__); 852 atm_err(instance, "%s: no memory for SAR buffer!\n", __func__);
766 ret = -ENOMEM; 853 ret = -ENOMEM;
767 goto fail; 854 goto fail;
768 } 855 }
@@ -770,6 +857,9 @@ static int usbatm_atm_open(struct atm_vcc *vcc)
770 vcc->dev_data = new; 857 vcc->dev_data = new;
771 858
772 tasklet_disable(&instance->rx_channel.tasklet); 859 tasklet_disable(&instance->rx_channel.tasklet);
860 instance->cached_vcc = new;
861 instance->cached_vpi = vpi;
862 instance->cached_vci = vci;
773 list_add(&new->list, &instance->vcc_list); 863 list_add(&new->list, &instance->vcc_list);
774 tasklet_enable(&instance->rx_channel.tasklet); 864 tasklet_enable(&instance->rx_channel.tasklet);
775 865
@@ -777,7 +867,7 @@ static int usbatm_atm_open(struct atm_vcc *vcc)
777 set_bit(ATM_VF_PARTIAL, &vcc->flags); 867 set_bit(ATM_VF_PARTIAL, &vcc->flags);
778 set_bit(ATM_VF_READY, &vcc->flags); 868 set_bit(ATM_VF_READY, &vcc->flags);
779 869
780 up(&instance->serialize); 870 mutex_unlock(&instance->serialize);
781 871
782 atm_dbg(instance, "%s: allocated vcc data 0x%p\n", __func__, new); 872 atm_dbg(instance, "%s: allocated vcc data 0x%p\n", __func__, new);
783 873
@@ -785,7 +875,7 @@ static int usbatm_atm_open(struct atm_vcc *vcc)
785 875
786fail: 876fail:
787 kfree(new); 877 kfree(new);
788 up(&instance->serialize); 878 mutex_unlock(&instance->serialize);
789 return ret; 879 return ret;
790} 880}
791 881
@@ -806,9 +896,14 @@ static void usbatm_atm_close(struct atm_vcc *vcc)
806 896
807 usbatm_cancel_send(instance, vcc); 897 usbatm_cancel_send(instance, vcc);
808 898
809 down(&instance->serialize); /* vs self, usbatm_atm_open */ 899 mutex_lock(&instance->serialize); /* vs self, usbatm_atm_open, usbatm_usb_disconnect */
810 900
811 tasklet_disable(&instance->rx_channel.tasklet); 901 tasklet_disable(&instance->rx_channel.tasklet);
902 if (instance->cached_vcc == vcc_data) {
903 instance->cached_vcc = NULL;
904 instance->cached_vpi = ATM_VPI_UNSPEC;
905 instance->cached_vci = ATM_VCI_UNSPEC;
906 }
812 list_del(&vcc_data->list); 907 list_del(&vcc_data->list);
813 tasklet_enable(&instance->rx_channel.tasklet); 908 tasklet_enable(&instance->rx_channel.tasklet);
814 909
@@ -824,14 +919,21 @@ static void usbatm_atm_close(struct atm_vcc *vcc)
824 clear_bit(ATM_VF_PARTIAL, &vcc->flags); 919 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
825 clear_bit(ATM_VF_ADDR, &vcc->flags); 920 clear_bit(ATM_VF_ADDR, &vcc->flags);
826 921
827 up(&instance->serialize); 922 mutex_unlock(&instance->serialize);
828 923
829 atm_dbg(instance, "%s successful\n", __func__); 924 atm_dbg(instance, "%s successful\n", __func__);
830} 925}
831 926
832static int usbatm_atm_ioctl(struct atm_dev *dev, unsigned int cmd, 927static int usbatm_atm_ioctl(struct atm_dev *atm_dev, unsigned int cmd,
833 void __user * arg) 928 void __user * arg)
834{ 929{
930 struct usbatm_data *instance = atm_dev->dev_data;
931
932 if (!instance || instance->disconnected) {
933 dbg("%s: %s!", __func__, instance ? "disconnected" : "NULL instance");
934 return -ENODEV;
935 }
936
835 switch (cmd) { 937 switch (cmd) {
836 case ATM_QUERYLOOP: 938 case ATM_QUERYLOOP:
837 return put_user(ATM_LM_NONE, (int __user *)arg) ? -EFAULT : 0; 939 return put_user(ATM_LM_NONE, (int __user *)arg) ? -EFAULT : 0;
@@ -845,10 +947,13 @@ static int usbatm_atm_init(struct usbatm_data *instance)
845 struct atm_dev *atm_dev; 947 struct atm_dev *atm_dev;
846 int ret, i; 948 int ret, i;
847 949
848 /* ATM init */ 950 /* ATM init. The ATM initialization scheme suffers from an intrinsic race
951 * condition: callbacks we register can be executed at once, before we have
952 * initialized the struct atm_dev. To protect against this, all callbacks
953 * abort if atm_dev->dev_data is NULL. */
849 atm_dev = atm_dev_register(instance->driver_name, &usbatm_atm_devops, -1, NULL); 954 atm_dev = atm_dev_register(instance->driver_name, &usbatm_atm_devops, -1, NULL);
850 if (!atm_dev) { 955 if (!atm_dev) {
851 usb_dbg(instance, "%s: failed to register ATM device!\n", __func__); 956 usb_err(instance, "%s: failed to register ATM device!\n", __func__);
852 return -1; 957 return -1;
853 } 958 }
854 959
@@ -862,12 +967,13 @@ static int usbatm_atm_init(struct usbatm_data *instance)
862 atm_dev->link_rate = 128 * 1000 / 424; 967 atm_dev->link_rate = 128 * 1000 / 424;
863 968
864 if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) { 969 if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) {
865 atm_dbg(instance, "%s: atm_start failed: %d!\n", __func__, ret); 970 atm_err(instance, "%s: atm_start failed: %d!\n", __func__, ret);
866 goto fail; 971 goto fail;
867 } 972 }
868 973
869 /* ready for ATM callbacks */
870 usbatm_get_instance(instance); /* dropped in usbatm_atm_dev_close */ 974 usbatm_get_instance(instance); /* dropped in usbatm_atm_dev_close */
975
976 /* ready for ATM callbacks */
871 mb(); 977 mb();
872 atm_dev->dev_data = instance; 978 atm_dev->dev_data = instance;
873 979
@@ -903,9 +1009,9 @@ static int usbatm_do_heavy_init(void *arg)
903 if (!ret) 1009 if (!ret)
904 ret = usbatm_atm_init(instance); 1010 ret = usbatm_atm_init(instance);
905 1011
906 down(&instance->serialize); 1012 mutex_lock(&instance->serialize);
907 instance->thread_pid = -1; 1013 instance->thread_pid = -1;
908 up(&instance->serialize); 1014 mutex_unlock(&instance->serialize);
909 1015
910 complete_and_exit(&instance->thread_exited, ret); 1016 complete_and_exit(&instance->thread_exited, ret);
911} 1017}
@@ -915,13 +1021,13 @@ static int usbatm_heavy_init(struct usbatm_data *instance)
915 int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_KERNEL); 1021 int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_KERNEL);
916 1022
917 if (ret < 0) { 1023 if (ret < 0) {
918 usb_dbg(instance, "%s: failed to create kernel_thread (%d)!\n", __func__, ret); 1024 usb_err(instance, "%s: failed to create kernel_thread (%d)!\n", __func__, ret);
919 return ret; 1025 return ret;
920 } 1026 }
921 1027
922 down(&instance->serialize); 1028 mutex_lock(&instance->serialize);
923 instance->thread_pid = ret; 1029 instance->thread_pid = ret;
924 up(&instance->serialize); 1030 mutex_unlock(&instance->serialize);
925 1031
926 wait_for_completion(&instance->thread_started); 1032 wait_for_completion(&instance->thread_started);
927 1033
@@ -951,9 +1057,9 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
951 char *buf; 1057 char *buf;
952 int error = -ENOMEM; 1058 int error = -ENOMEM;
953 int i, length; 1059 int i, length;
954 int need_heavy; 1060 unsigned int maxpacket, num_packets;
955 1061
956 dev_dbg(dev, "%s: trying driver %s with vendor=0x%x, product=0x%x, ifnum %d\n", 1062 dev_dbg(dev, "%s: trying driver %s with vendor=%04x, product=%04x, ifnum %2d\n",
957 __func__, driver->driver_name, 1063 __func__, driver->driver_name,
958 le16_to_cpu(usb_dev->descriptor.idVendor), 1064 le16_to_cpu(usb_dev->descriptor.idVendor),
959 le16_to_cpu(usb_dev->descriptor.idProduct), 1065 le16_to_cpu(usb_dev->descriptor.idProduct),
@@ -962,7 +1068,7 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
962 /* instance init */ 1068 /* instance init */
963 instance = kzalloc(sizeof(*instance) + sizeof(struct urb *) * (num_rcv_urbs + num_snd_urbs), GFP_KERNEL); 1069 instance = kzalloc(sizeof(*instance) + sizeof(struct urb *) * (num_rcv_urbs + num_snd_urbs), GFP_KERNEL);
964 if (!instance) { 1070 if (!instance) {
965 dev_dbg(dev, "%s: no memory for instance data!\n", __func__); 1071 dev_err(dev, "%s: no memory for instance data!\n", __func__);
966 return -ENOMEM; 1072 return -ENOMEM;
967 } 1073 }
968 1074
@@ -996,66 +1102,96 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
996 snprintf(buf, length, ")"); 1102 snprintf(buf, length, ")");
997 1103
998 bind: 1104 bind:
999 need_heavy = 1; 1105 if (driver->bind && (error = driver->bind(instance, intf, id)) < 0) {
1000 if (driver->bind && (error = driver->bind(instance, intf, id, &need_heavy)) < 0) { 1106 dev_err(dev, "%s: bind failed: %d!\n", __func__, error);
1001 dev_dbg(dev, "%s: bind failed: %d!\n", __func__, error);
1002 goto fail_free; 1107 goto fail_free;
1003 } 1108 }
1004 1109
1005 /* private fields */ 1110 /* private fields */
1006 1111
1007 kref_init(&instance->refcount); /* dropped in usbatm_usb_disconnect */ 1112 kref_init(&instance->refcount); /* dropped in usbatm_usb_disconnect */
1008 init_MUTEX(&instance->serialize); 1113 mutex_init(&instance->serialize);
1009 1114
1010 instance->thread_pid = -1; 1115 instance->thread_pid = -1;
1011 init_completion(&instance->thread_started); 1116 init_completion(&instance->thread_started);
1012 init_completion(&instance->thread_exited); 1117 init_completion(&instance->thread_exited);
1013 1118
1014 INIT_LIST_HEAD(&instance->vcc_list); 1119 INIT_LIST_HEAD(&instance->vcc_list);
1120 skb_queue_head_init(&instance->sndqueue);
1015 1121
1016 usbatm_init_channel(&instance->rx_channel); 1122 usbatm_init_channel(&instance->rx_channel);
1017 usbatm_init_channel(&instance->tx_channel); 1123 usbatm_init_channel(&instance->tx_channel);
1018 tasklet_init(&instance->rx_channel.tasklet, usbatm_rx_process, (unsigned long)instance); 1124 tasklet_init(&instance->rx_channel.tasklet, usbatm_rx_process, (unsigned long)instance);
1019 tasklet_init(&instance->tx_channel.tasklet, usbatm_tx_process, (unsigned long)instance); 1125 tasklet_init(&instance->tx_channel.tasklet, usbatm_tx_process, (unsigned long)instance);
1020 instance->rx_channel.endpoint = usb_rcvbulkpipe(usb_dev, driver->in);
1021 instance->tx_channel.endpoint = usb_sndbulkpipe(usb_dev, driver->out);
1022 instance->rx_channel.stride = ATM_CELL_SIZE + driver->rx_padding; 1126 instance->rx_channel.stride = ATM_CELL_SIZE + driver->rx_padding;
1023 instance->tx_channel.stride = ATM_CELL_SIZE + driver->tx_padding; 1127 instance->tx_channel.stride = ATM_CELL_SIZE + driver->tx_padding;
1024 instance->rx_channel.buf_size = rcv_buf_size * instance->rx_channel.stride;
1025 instance->tx_channel.buf_size = snd_buf_size * instance->tx_channel.stride;
1026 instance->rx_channel.usbatm = instance->tx_channel.usbatm = instance; 1128 instance->rx_channel.usbatm = instance->tx_channel.usbatm = instance;
1027 1129
1028 skb_queue_head_init(&instance->sndqueue); 1130 if ((instance->flags & UDSL_USE_ISOC) && driver->isoc_in)
1131 instance->rx_channel.endpoint = usb_rcvisocpipe(usb_dev, driver->isoc_in);
1132 else
1133 instance->rx_channel.endpoint = usb_rcvbulkpipe(usb_dev, driver->bulk_in);
1134
1135 instance->tx_channel.endpoint = usb_sndbulkpipe(usb_dev, driver->bulk_out);
1136
1137 /* tx buffer size must be a positive multiple of the stride */
1138 instance->tx_channel.buf_size = max (instance->tx_channel.stride,
1139 snd_buf_bytes - (snd_buf_bytes % instance->tx_channel.stride));
1140
1141 /* rx buffer size must be a positive multiple of the endpoint maxpacket */
1142 maxpacket = usb_maxpacket(usb_dev, instance->rx_channel.endpoint, 0);
1143
1144 if ((maxpacket < 1) || (maxpacket > UDSL_MAX_BUF_SIZE)) {
1145 dev_err(dev, "%s: invalid endpoint %02x!\n", __func__,
1146 usb_pipeendpoint(instance->rx_channel.endpoint));
1147 error = -EINVAL;
1148 goto fail_unbind;
1149 }
1150
1151 num_packets = max (1U, (rcv_buf_bytes + maxpacket / 2) / maxpacket); /* round */
1152
1153 if (num_packets * maxpacket > UDSL_MAX_BUF_SIZE)
1154 num_packets--;
1155
1156 instance->rx_channel.buf_size = num_packets * maxpacket;
1157 instance->rx_channel.packet_size = maxpacket;
1158
1159#ifdef DEBUG
1160 for (i = 0; i < 2; i++) {
1161 struct usbatm_channel *channel = i ?
1162 &instance->tx_channel : &instance->rx_channel;
1163
1164 dev_dbg(dev, "%s: using %d byte buffer for %s channel 0x%p\n", __func__, channel->buf_size, i ? "tx" : "rx", channel);
1165 }
1166#endif
1167
1168 /* initialize urbs */
1029 1169
1030 for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) { 1170 for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) {
1031 struct urb *urb;
1032 u8 *buffer; 1171 u8 *buffer;
1033 unsigned int iso_packets = 0, iso_size = 0;
1034 struct usbatm_channel *channel = i < num_rcv_urbs ? 1172 struct usbatm_channel *channel = i < num_rcv_urbs ?
1035 &instance->rx_channel : &instance->tx_channel; 1173 &instance->rx_channel : &instance->tx_channel;
1174 struct urb *urb;
1175 unsigned int iso_packets = usb_pipeisoc(channel->endpoint) ? channel->buf_size / channel->packet_size : 0;
1036 1176
1037 if (usb_pipeisoc(channel->endpoint)) { 1177 UDSL_ASSERT(!usb_pipeisoc(channel->endpoint) || usb_pipein(channel->endpoint));
1038 /* don't expect iso out endpoints */
1039 iso_size = usb_maxpacket(instance->usb_dev, channel->endpoint, 0);
1040 iso_size -= iso_size % channel->stride; /* alignment */
1041 BUG_ON(!iso_size);
1042 iso_packets = (channel->buf_size - 1) / iso_size + 1;
1043 }
1044 1178
1045 urb = usb_alloc_urb(iso_packets, GFP_KERNEL); 1179 urb = usb_alloc_urb(iso_packets, GFP_KERNEL);
1046 if (!urb) { 1180 if (!urb) {
1047 dev_dbg(dev, "%s: no memory for urb %d!\n", __func__, i); 1181 dev_err(dev, "%s: no memory for urb %d!\n", __func__, i);
1182 error = -ENOMEM;
1048 goto fail_unbind; 1183 goto fail_unbind;
1049 } 1184 }
1050 1185
1051 instance->urbs[i] = urb; 1186 instance->urbs[i] = urb;
1052 1187
1053 buffer = kmalloc(channel->buf_size, GFP_KERNEL); 1188 /* zero the tx padding to avoid leaking information */
1189 buffer = kzalloc(channel->buf_size, GFP_KERNEL);
1054 if (!buffer) { 1190 if (!buffer) {
1055 dev_dbg(dev, "%s: no memory for buffer %d!\n", __func__, i); 1191 dev_err(dev, "%s: no memory for buffer %d!\n", __func__, i);
1192 error = -ENOMEM;
1056 goto fail_unbind; 1193 goto fail_unbind;
1057 } 1194 }
1058 memset(buffer, 0, channel->buf_size);
1059 1195
1060 usb_fill_bulk_urb(urb, instance->usb_dev, channel->endpoint, 1196 usb_fill_bulk_urb(urb, instance->usb_dev, channel->endpoint,
1061 buffer, channel->buf_size, usbatm_complete, channel); 1197 buffer, channel->buf_size, usbatm_complete, channel);
@@ -1065,9 +1201,8 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
1065 urb->transfer_flags = URB_ISO_ASAP; 1201 urb->transfer_flags = URB_ISO_ASAP;
1066 urb->number_of_packets = iso_packets; 1202 urb->number_of_packets = iso_packets;
1067 for (j = 0; j < iso_packets; j++) { 1203 for (j = 0; j < iso_packets; j++) {
1068 urb->iso_frame_desc[j].offset = iso_size * j; 1204 urb->iso_frame_desc[j].offset = channel->packet_size * j;
1069 urb->iso_frame_desc[j].length = min_t(int, iso_size, 1205 urb->iso_frame_desc[j].length = channel->packet_size;
1070 channel->buf_size - urb->iso_frame_desc[j].offset);
1071 } 1206 }
1072 } 1207 }
1073 1208
@@ -1079,7 +1214,17 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
1079 __func__, urb->transfer_buffer, urb->transfer_buffer_length, urb); 1214 __func__, urb->transfer_buffer, urb->transfer_buffer_length, urb);
1080 } 1215 }
1081 1216
1082 if (need_heavy && driver->heavy_init) { 1217 instance->cached_vpi = ATM_VPI_UNSPEC;
1218 instance->cached_vci = ATM_VCI_UNSPEC;
1219 instance->cell_buf = kmalloc(instance->rx_channel.stride, GFP_KERNEL);
1220
1221 if (!instance->cell_buf) {
1222 dev_err(dev, "%s: no memory for cell buffer!\n", __func__);
1223 error = -ENOMEM;
1224 goto fail_unbind;
1225 }
1226
1227 if (!(instance->flags & UDSL_SKIP_HEAVY_INIT) && driver->heavy_init) {
1083 error = usbatm_heavy_init(instance); 1228 error = usbatm_heavy_init(instance);
1084 } else { 1229 } else {
1085 complete(&instance->thread_exited); /* pretend that heavy_init was run */ 1230 complete(&instance->thread_exited); /* pretend that heavy_init was run */
@@ -1098,6 +1243,8 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
1098 if (instance->driver->unbind) 1243 if (instance->driver->unbind)
1099 instance->driver->unbind(instance, intf); 1244 instance->driver->unbind(instance, intf);
1100 fail_free: 1245 fail_free:
1246 kfree(instance->cell_buf);
1247
1101 for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) { 1248 for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) {
1102 if (instance->urbs[i]) 1249 if (instance->urbs[i])
1103 kfree(instance->urbs[i]->transfer_buffer); 1250 kfree(instance->urbs[i]->transfer_buffer);
@@ -1114,6 +1261,7 @@ void usbatm_usb_disconnect(struct usb_interface *intf)
1114{ 1261{
1115 struct device *dev = &intf->dev; 1262 struct device *dev = &intf->dev;
1116 struct usbatm_data *instance = usb_get_intfdata(intf); 1263 struct usbatm_data *instance = usb_get_intfdata(intf);
1264 struct usbatm_vcc_data *vcc_data;
1117 int i; 1265 int i;
1118 1266
1119 dev_dbg(dev, "%s entered\n", __func__); 1267 dev_dbg(dev, "%s entered\n", __func__);
@@ -1125,13 +1273,19 @@ void usbatm_usb_disconnect(struct usb_interface *intf)
1125 1273
1126 usb_set_intfdata(intf, NULL); 1274 usb_set_intfdata(intf, NULL);
1127 1275
1128 down(&instance->serialize); 1276 mutex_lock(&instance->serialize);
1277 instance->disconnected = 1;
1129 if (instance->thread_pid >= 0) 1278 if (instance->thread_pid >= 0)
1130 kill_proc(instance->thread_pid, SIGTERM, 1); 1279 kill_proc(instance->thread_pid, SIGTERM, 1);
1131 up(&instance->serialize); 1280 mutex_unlock(&instance->serialize);
1132 1281
1133 wait_for_completion(&instance->thread_exited); 1282 wait_for_completion(&instance->thread_exited);
1134 1283
1284 mutex_lock(&instance->serialize);
1285 list_for_each_entry(vcc_data, &instance->vcc_list, list)
1286 vcc_release_async(vcc_data->vcc, -EPIPE);
1287 mutex_unlock(&instance->serialize);
1288
1135 tasklet_disable(&instance->rx_channel.tasklet); 1289 tasklet_disable(&instance->rx_channel.tasklet);
1136 tasklet_disable(&instance->tx_channel.tasklet); 1290 tasklet_disable(&instance->tx_channel.tasklet);
1137 1291
@@ -1141,6 +1295,14 @@ void usbatm_usb_disconnect(struct usb_interface *intf)
1141 del_timer_sync(&instance->rx_channel.delay); 1295 del_timer_sync(&instance->rx_channel.delay);
1142 del_timer_sync(&instance->tx_channel.delay); 1296 del_timer_sync(&instance->tx_channel.delay);
1143 1297
1298 /* turn usbatm_[rt]x_process into something close to a no-op */
1299 /* no need to take the spinlock */
1300 INIT_LIST_HEAD(&instance->rx_channel.list);
1301 INIT_LIST_HEAD(&instance->tx_channel.list);
1302
1303 tasklet_enable(&instance->rx_channel.tasklet);
1304 tasklet_enable(&instance->tx_channel.tasklet);
1305
1144 if (instance->atm_dev && instance->driver->atm_stop) 1306 if (instance->atm_dev && instance->driver->atm_stop)
1145 instance->driver->atm_stop(instance, instance->atm_dev); 1307 instance->driver->atm_stop(instance, instance->atm_dev);
1146 1308
@@ -1149,19 +1311,13 @@ void usbatm_usb_disconnect(struct usb_interface *intf)
1149 1311
1150 instance->driver_data = NULL; 1312 instance->driver_data = NULL;
1151 1313
1152 /* turn usbatm_[rt]x_process into noop */
1153 /* no need to take the spinlock */
1154 INIT_LIST_HEAD(&instance->rx_channel.list);
1155 INIT_LIST_HEAD(&instance->tx_channel.list);
1156
1157 tasklet_enable(&instance->rx_channel.tasklet);
1158 tasklet_enable(&instance->tx_channel.tasklet);
1159
1160 for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) { 1314 for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) {
1161 kfree(instance->urbs[i]->transfer_buffer); 1315 kfree(instance->urbs[i]->transfer_buffer);
1162 usb_free_urb(instance->urbs[i]); 1316 usb_free_urb(instance->urbs[i]);
1163 } 1317 }
1164 1318
1319 kfree(instance->cell_buf);
1320
1165 /* ATM finalize */ 1321 /* ATM finalize */
1166 if (instance->atm_dev) 1322 if (instance->atm_dev)
1167 atm_dev_deregister(instance->atm_dev); 1323 atm_dev_deregister(instance->atm_dev);
@@ -1186,10 +1342,10 @@ static int __init usbatm_usb_init(void)
1186 1342
1187 if ((num_rcv_urbs > UDSL_MAX_RCV_URBS) 1343 if ((num_rcv_urbs > UDSL_MAX_RCV_URBS)
1188 || (num_snd_urbs > UDSL_MAX_SND_URBS) 1344 || (num_snd_urbs > UDSL_MAX_SND_URBS)
1189 || (rcv_buf_size < 1) 1345 || (rcv_buf_bytes < 1)
1190 || (rcv_buf_size > UDSL_MAX_RCV_BUF_SIZE) 1346 || (rcv_buf_bytes > UDSL_MAX_BUF_SIZE)
1191 || (snd_buf_size < 1) 1347 || (snd_buf_bytes < 1)
1192 || (snd_buf_size > UDSL_MAX_SND_BUF_SIZE)) 1348 || (snd_buf_bytes > UDSL_MAX_BUF_SIZE))
1193 return -EINVAL; 1349 return -EINVAL;
1194 1350
1195 return 0; 1351 return 0;
diff --git a/drivers/usb/atm/usbatm.h b/drivers/usb/atm/usbatm.h
index 1adacd60d713..ff8551e93372 100644
--- a/drivers/usb/atm/usbatm.h
+++ b/drivers/usb/atm/usbatm.h
@@ -24,21 +24,21 @@
24#ifndef _USBATM_H_ 24#ifndef _USBATM_H_
25#define _USBATM_H_ 25#define _USBATM_H_
26 26
27#include <linux/config.h>
28
29/*
30#define VERBOSE_DEBUG
31*/
32
33#include <asm/semaphore.h> 27#include <asm/semaphore.h>
34#include <linux/atm.h> 28#include <linux/atm.h>
35#include <linux/atmdev.h> 29#include <linux/atmdev.h>
36#include <linux/completion.h> 30#include <linux/completion.h>
37#include <linux/device.h> 31#include <linux/device.h>
32#include <linux/kernel.h>
38#include <linux/kref.h> 33#include <linux/kref.h>
39#include <linux/list.h> 34#include <linux/list.h>
40#include <linux/stringify.h> 35#include <linux/stringify.h>
41#include <linux/usb.h> 36#include <linux/usb.h>
37#include <linux/mutex.h>
38
39/*
40#define VERBOSE_DEBUG
41*/
42 42
43#ifdef DEBUG 43#ifdef DEBUG
44#define UDSL_ASSERT(x) BUG_ON(!(x)) 44#define UDSL_ASSERT(x) BUG_ON(!(x))
@@ -52,8 +52,13 @@
52 dev_info(&(instance)->usb_intf->dev , format , ## arg) 52 dev_info(&(instance)->usb_intf->dev , format , ## arg)
53#define usb_warn(instance, format, arg...) \ 53#define usb_warn(instance, format, arg...) \
54 dev_warn(&(instance)->usb_intf->dev , format , ## arg) 54 dev_warn(&(instance)->usb_intf->dev , format , ## arg)
55#ifdef DEBUG
55#define usb_dbg(instance, format, arg...) \ 56#define usb_dbg(instance, format, arg...) \
56 dev_dbg(&(instance)->usb_intf->dev , format , ## arg) 57 dev_printk(KERN_DEBUG , &(instance)->usb_intf->dev , format , ## arg)
58#else
59#define usb_dbg(instance, format, arg...) \
60 do {} while (0)
61#endif
57 62
58/* FIXME: move to dev_* once ATM is driver model aware */ 63/* FIXME: move to dev_* once ATM is driver model aware */
59#define atm_printk(level, instance, format, arg...) \ 64#define atm_printk(level, instance, format, arg...) \
@@ -69,12 +74,24 @@
69#ifdef DEBUG 74#ifdef DEBUG
70#define atm_dbg(instance, format, arg...) \ 75#define atm_dbg(instance, format, arg...) \
71 atm_printk(KERN_DEBUG, instance , format , ## arg) 76 atm_printk(KERN_DEBUG, instance , format , ## arg)
77#define atm_rldbg(instance, format, arg...) \
78 if (printk_ratelimit()) \
79 atm_printk(KERN_DEBUG, instance , format , ## arg)
72#else 80#else
73#define atm_dbg(instance, format, arg...) \ 81#define atm_dbg(instance, format, arg...) \
74 do {} while (0) 82 do {} while (0)
83#define atm_rldbg(instance, format, arg...) \
84 do {} while (0)
75#endif 85#endif
76 86
77 87
88/* flags, set by mini-driver in bind() */
89
90#define UDSL_SKIP_HEAVY_INIT (1<<0)
91#define UDSL_USE_ISOC (1<<1)
92#define UDSL_IGNORE_EILSEQ (1<<2)
93
94
78/* mini driver */ 95/* mini driver */
79 96
80struct usbatm_data; 97struct usbatm_data;
@@ -86,16 +103,11 @@ struct usbatm_data;
86*/ 103*/
87 104
88struct usbatm_driver { 105struct usbatm_driver {
89 struct module *owner;
90
91 const char *driver_name; 106 const char *driver_name;
92 107
93 /* 108 /* init device ... can sleep, or cause probe() failure */
94 * init device ... can sleep, or cause probe() failure. Drivers with a heavy_init
95 * method can avoid having it called by setting need_heavy_init to zero.
96 */
97 int (*bind) (struct usbatm_data *, struct usb_interface *, 109 int (*bind) (struct usbatm_data *, struct usb_interface *,
98 const struct usb_device_id *id, int *need_heavy_init); 110 const struct usb_device_id *id);
99 111
100 /* additional device initialization that is too slow to be done in probe() */ 112 /* additional device initialization that is too slow to be done in probe() */
101 int (*heavy_init) (struct usbatm_data *, struct usb_interface *); 113 int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
@@ -109,8 +121,9 @@ struct usbatm_driver {
109 /* cleanup ATM device ... can sleep, but can't fail */ 121 /* cleanup ATM device ... can sleep, but can't fail */
110 void (*atm_stop) (struct usbatm_data *, struct atm_dev *); 122 void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
111 123
112 int in; /* rx endpoint */ 124 int bulk_in; /* bulk rx endpoint */
113 int out; /* tx endpoint */ 125 int isoc_in; /* isochronous rx endpoint */
126 int bulk_out; /* bulk tx endpoint */
114 127
115 unsigned rx_padding; 128 unsigned rx_padding;
116 unsigned tx_padding; 129 unsigned tx_padding;
@@ -125,6 +138,7 @@ struct usbatm_channel {
125 int endpoint; /* usb pipe */ 138 int endpoint; /* usb pipe */
126 unsigned int stride; /* ATM cell size + padding */ 139 unsigned int stride; /* ATM cell size + padding */
127 unsigned int buf_size; /* urb buffer size */ 140 unsigned int buf_size; /* urb buffer size */
141 unsigned int packet_size; /* endpoint maxpacket */
128 spinlock_t lock; 142 spinlock_t lock;
129 struct list_head list; 143 struct list_head list;
130 struct tasklet_struct tasklet; 144 struct tasklet_struct tasklet;
@@ -143,6 +157,7 @@ struct usbatm_data {
143 struct usbatm_driver *driver; 157 struct usbatm_driver *driver;
144 void *driver_data; 158 void *driver_data;
145 char driver_name[16]; 159 char driver_name[16];
160 unsigned int flags; /* set by mini-driver in bind() */
146 161
147 /* USB device */ 162 /* USB device */
148 struct usb_device *usb_dev; 163 struct usb_device *usb_dev;
@@ -157,7 +172,8 @@ struct usbatm_data {
157 ********************************/ 172 ********************************/
158 173
159 struct kref refcount; 174 struct kref refcount;
160 struct semaphore serialize; 175 struct mutex serialize;
176 int disconnected;
161 177
162 /* heavy init */ 178 /* heavy init */
163 int thread_pid; 179 int thread_pid;
@@ -171,7 +187,14 @@ struct usbatm_data {
171 struct usbatm_channel tx_channel; 187 struct usbatm_channel tx_channel;
172 188
173 struct sk_buff_head sndqueue; 189 struct sk_buff_head sndqueue;
174 struct sk_buff *current_skb; /* being emptied */ 190 struct sk_buff *current_skb; /* being emptied */
191
192 struct usbatm_vcc_data *cached_vcc;
193 int cached_vci;
194 short cached_vpi;
195
196 unsigned char *cell_buf; /* holds partial rx cell */
197 unsigned int buf_usage;
175 198
176 struct urb *urbs[0]; 199 struct urb *urbs[0];
177}; 200};
diff --git a/drivers/usb/atm/xusbatm.c b/drivers/usb/atm/xusbatm.c
index 5c76e3aaaa5e..42d6823b82b3 100644
--- a/drivers/usb/atm/xusbatm.c
+++ b/drivers/usb/atm/xusbatm.c
@@ -41,6 +41,8 @@ XUSBATM_PARM(rx_endpoint, unsigned char, byte, "rx endpoint number");
41XUSBATM_PARM(tx_endpoint, unsigned char, byte, "tx endpoint number"); 41XUSBATM_PARM(tx_endpoint, unsigned char, byte, "tx endpoint number");
42XUSBATM_PARM(rx_padding, unsigned char, byte, "rx padding (default 0)"); 42XUSBATM_PARM(rx_padding, unsigned char, byte, "rx padding (default 0)");
43XUSBATM_PARM(tx_padding, unsigned char, byte, "tx padding (default 0)"); 43XUSBATM_PARM(tx_padding, unsigned char, byte, "tx padding (default 0)");
44XUSBATM_PARM(rx_altsetting, unsigned char, byte, "rx altsetting (default 0)");
45XUSBATM_PARM(tx_altsetting, unsigned char, byte, "rx altsetting (default 0)");
44 46
45static const char xusbatm_driver_name[] = "xusbatm"; 47static const char xusbatm_driver_name[] = "xusbatm";
46 48
@@ -48,82 +50,118 @@ static struct usbatm_driver xusbatm_drivers[XUSBATM_DRIVERS_MAX];
48static struct usb_device_id xusbatm_usb_ids[XUSBATM_DRIVERS_MAX + 1]; 50static struct usb_device_id xusbatm_usb_ids[XUSBATM_DRIVERS_MAX + 1];
49static struct usb_driver xusbatm_usb_driver; 51static struct usb_driver xusbatm_usb_driver;
50 52
51static int usb_intf_has_ep(const struct usb_interface *intf, u8 ep) 53static struct usb_interface *xusbatm_find_intf (struct usb_device *usb_dev, int altsetting, u8 ep)
52{ 54{
55 struct usb_host_interface *alt;
56 struct usb_interface *intf;
53 int i, j; 57 int i, j;
54 58
55 for (i = 0; i < intf->num_altsetting; i++) { 59 for(i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++)
56 struct usb_host_interface *alt = intf->altsetting; 60 if ((intf = usb_dev->actconfig->interface[i]) && (alt = usb_altnum_to_altsetting(intf, altsetting)))
57 for (j = 0; j < alt->desc.bNumEndpoints; j++) 61 for (j = 0; j < alt->desc.bNumEndpoints; j++)
58 if ((alt->endpoint[i].desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) == ep) 62 if (alt->endpoint[j].desc.bEndpointAddress == ep)
59 return 1; 63 return intf;
64 return NULL;
65}
66
67static int xusbatm_capture_intf (struct usbatm_data *usbatm, struct usb_device *usb_dev,
68 struct usb_interface *intf, int altsetting, int claim)
69{
70 int ifnum = intf->altsetting->desc.bInterfaceNumber;
71 int ret;
72
73 if (claim && (ret = usb_driver_claim_interface(&xusbatm_usb_driver, intf, usbatm))) {
74 usb_err(usbatm, "%s: failed to claim interface %2d (%d)!\n", __func__, ifnum, ret);
75 return ret;
76 }
77 if ((ret = usb_set_interface(usb_dev, ifnum, altsetting))) {
78 usb_err(usbatm, "%s: altsetting %2d for interface %2d failed (%d)!\n", __func__, altsetting, ifnum, ret);
79 return ret;
60 } 80 }
61 return 0; 81 return 0;
62} 82}
63 83
64static int xusbatm_bind(struct usbatm_data *usbatm_instance, 84static void xusbatm_release_intf (struct usb_device *usb_dev, struct usb_interface *intf, int claimed)
65 struct usb_interface *intf, const struct usb_device_id *id, 85{
66 int *need_heavy_init) 86 if (claimed) {
87 usb_set_intfdata(intf, NULL);
88 usb_driver_release_interface(&xusbatm_usb_driver, intf);
89 }
90}
91
92static int xusbatm_bind(struct usbatm_data *usbatm,
93 struct usb_interface *intf, const struct usb_device_id *id)
67{ 94{
68 struct usb_device *usb_dev = interface_to_usbdev(intf); 95 struct usb_device *usb_dev = interface_to_usbdev(intf);
69 int drv_ix = id - xusbatm_usb_ids; 96 int drv_ix = id - xusbatm_usb_ids;
70 int rx_ep_present = usb_intf_has_ep(intf, rx_endpoint[drv_ix]); 97 int rx_alt = rx_altsetting[drv_ix];
71 int tx_ep_present = usb_intf_has_ep(intf, tx_endpoint[drv_ix]); 98 int tx_alt = tx_altsetting[drv_ix];
72 u8 searched_ep = rx_ep_present ? tx_endpoint[drv_ix] : rx_endpoint[drv_ix]; 99 struct usb_interface *rx_intf = xusbatm_find_intf(usb_dev, rx_alt, rx_endpoint[drv_ix]);
73 int i, ret; 100 struct usb_interface *tx_intf = xusbatm_find_intf(usb_dev, tx_alt, tx_endpoint[drv_ix]);
74 101 int ret;
75 usb_dbg(usbatm_instance, "%s: binding driver %d: vendor %#x product %#x" 102
76 " rx: ep %#x padd %d tx: ep %#x padd %d\n", 103 usb_dbg(usbatm, "%s: binding driver %d: vendor %04x product %04x"
104 " rx: ep %02x padd %d alt %2d tx: ep %02x padd %d alt %2d\n",
77 __func__, drv_ix, vendor[drv_ix], product[drv_ix], 105 __func__, drv_ix, vendor[drv_ix], product[drv_ix],
78 rx_endpoint[drv_ix], rx_padding[drv_ix], 106 rx_endpoint[drv_ix], rx_padding[drv_ix], rx_alt,
79 tx_endpoint[drv_ix], tx_padding[drv_ix]); 107 tx_endpoint[drv_ix], tx_padding[drv_ix], tx_alt);
108
109 if (!rx_intf || !tx_intf) {
110 if (!rx_intf)
111 usb_dbg(usbatm, "%s: no interface contains endpoint %02x in altsetting %2d\n",
112 __func__, rx_endpoint[drv_ix], rx_alt);
113 if (!tx_intf)
114 usb_dbg(usbatm, "%s: no interface contains endpoint %02x in altsetting %2d\n",
115 __func__, tx_endpoint[drv_ix], tx_alt);
116 return -ENODEV;
117 }
80 118
81 if (!rx_ep_present && !tx_ep_present) { 119 if ((rx_intf != intf) && (tx_intf != intf))
82 usb_dbg(usbatm_instance, "%s: intf #%d has neither rx (%#x) nor tx (%#x) endpoint\n",
83 __func__, intf->altsetting->desc.bInterfaceNumber,
84 rx_endpoint[drv_ix], tx_endpoint[drv_ix]);
85 return -ENODEV; 120 return -ENODEV;
121
122 if ((rx_intf == tx_intf) && (rx_alt != tx_alt)) {
123 usb_err(usbatm, "%s: altsettings clash on interface %2d (%2d vs %2d)!\n", __func__,
124 rx_intf->altsetting->desc.bInterfaceNumber, rx_alt, tx_alt);
125 return -EINVAL;
86 } 126 }
87 127
88 if (rx_ep_present && tx_ep_present) 128 usb_dbg(usbatm, "%s: rx If#=%2d; tx If#=%2d\n", __func__,
89 return 0; 129 rx_intf->altsetting->desc.bInterfaceNumber,
130 tx_intf->altsetting->desc.bInterfaceNumber);
90 131
91 for(i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++) { 132 if ((ret = xusbatm_capture_intf(usbatm, usb_dev, rx_intf, rx_alt, rx_intf != intf)))
92 struct usb_interface *cur_if = usb_dev->actconfig->interface[i]; 133 return ret;
93 134
94 if (cur_if != intf && usb_intf_has_ep(cur_if, searched_ep)) { 135 if ((tx_intf != rx_intf) && (ret = xusbatm_capture_intf(usbatm, usb_dev, tx_intf, tx_alt, tx_intf != intf))) {
95 ret = usb_driver_claim_interface(&xusbatm_usb_driver, 136 xusbatm_release_intf(usb_dev, rx_intf, rx_intf != intf);
96 cur_if, usbatm_instance); 137 return ret;
97 if (!ret)
98 usb_err(usbatm_instance, "%s: failed to claim interface #%d (%d)\n",
99 __func__, cur_if->altsetting->desc.bInterfaceNumber, ret);
100 return ret;
101 }
102 } 138 }
103 139
104 usb_err(usbatm_instance, "%s: no interface has endpoint %#x\n", 140 return 0;
105 __func__, searched_ep);
106 return -ENODEV;
107} 141}
108 142
109static void xusbatm_unbind(struct usbatm_data *usbatm_instance, 143static void xusbatm_unbind(struct usbatm_data *usbatm,
110 struct usb_interface *intf) 144 struct usb_interface *intf)
111{ 145{
112 struct usb_device *usb_dev = interface_to_usbdev(intf); 146 struct usb_device *usb_dev = interface_to_usbdev(intf);
113 int i; 147 int i;
114 usb_dbg(usbatm_instance, "%s entered\n", __func__); 148
149 usb_dbg(usbatm, "%s entered\n", __func__);
115 150
116 for(i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++) { 151 for(i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++) {
117 struct usb_interface *cur_if = usb_dev->actconfig->interface[i]; 152 struct usb_interface *cur_intf = usb_dev->actconfig->interface[i];
118 usb_set_intfdata(cur_if, NULL); 153
119 usb_driver_release_interface(&xusbatm_usb_driver, cur_if); 154 if (cur_intf && (usb_get_intfdata(cur_intf) == usbatm)) {
155 usb_set_intfdata(cur_intf, NULL);
156 usb_driver_release_interface(&xusbatm_usb_driver, cur_intf);
157 }
120 } 158 }
121} 159}
122 160
123static int xusbatm_atm_start(struct usbatm_data *usbatm_instance, 161static int xusbatm_atm_start(struct usbatm_data *usbatm,
124 struct atm_dev *atm_dev) 162 struct atm_dev *atm_dev)
125{ 163{
126 atm_dbg(usbatm_instance, "%s entered\n", __func__); 164 atm_dbg(usbatm, "%s entered\n", __func__);
127 165
128 /* use random MAC as we've no way to get it from the device */ 166 /* use random MAC as we've no way to get it from the device */
129 random_ether_addr(atm_dev->esi); 167 random_ether_addr(atm_dev->esi);
@@ -161,18 +199,19 @@ static int __init xusbatm_init(void)
161 } 199 }
162 200
163 for (i = 0; i < num_vendor; i++) { 201 for (i = 0; i < num_vendor; i++) {
202 rx_endpoint[i] |= USB_DIR_IN;
203 tx_endpoint[i] &= USB_ENDPOINT_NUMBER_MASK;
204
164 xusbatm_usb_ids[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE; 205 xusbatm_usb_ids[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
165 xusbatm_usb_ids[i].idVendor = vendor[i]; 206 xusbatm_usb_ids[i].idVendor = vendor[i];
166 xusbatm_usb_ids[i].idProduct = product[i]; 207 xusbatm_usb_ids[i].idProduct = product[i];
167 208
168
169 xusbatm_drivers[i].owner = THIS_MODULE;
170 xusbatm_drivers[i].driver_name = xusbatm_driver_name; 209 xusbatm_drivers[i].driver_name = xusbatm_driver_name;
171 xusbatm_drivers[i].bind = xusbatm_bind; 210 xusbatm_drivers[i].bind = xusbatm_bind;
172 xusbatm_drivers[i].unbind = xusbatm_unbind; 211 xusbatm_drivers[i].unbind = xusbatm_unbind;
173 xusbatm_drivers[i].atm_start = xusbatm_atm_start; 212 xusbatm_drivers[i].atm_start = xusbatm_atm_start;
174 xusbatm_drivers[i].in = rx_endpoint[i]; 213 xusbatm_drivers[i].bulk_in = rx_endpoint[i];
175 xusbatm_drivers[i].out = tx_endpoint[i]; 214 xusbatm_drivers[i].bulk_out = tx_endpoint[i];
176 xusbatm_drivers[i].rx_padding = rx_padding[i]; 215 xusbatm_drivers[i].rx_padding = rx_padding[i];
177 xusbatm_drivers[i].tx_padding = tx_padding[i]; 216 xusbatm_drivers[i].tx_padding = tx_padding[i];
178 } 217 }