Changeset 166 for trunk/src/os2ahci/ahci.c
- Timestamp:
- Aug 1, 2013, 5:11:07 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/os2ahci/ahci.c
r165 r166 598 598 dprintf("ahci_scan_ports: scanning ports on adapter %d\n", ad_no(ai)); 599 599 for (p = 0; p < AHCI_MAX_PORTS; p++) { 600 if (ai->port_map & (1UL << p)) { 601 602 ddprintf("ahci_scan_ports: Wait till not busy on port %d\n", p); 603 /* wait until all active commands have completed on this port */ 604 timer_init(&Timer, 250); 605 while (ahci_port_busy(ai, p)) { 606 if (timer_check_and_block(&Timer)) break; 600 if (!(ai->port_map & (1UL << p))) continue; 601 if (port_ignore[ad_no(ai)][p]) continue; 602 603 ddprintf("ahci_scan_ports: Wait till not busy on port %d\n", p); 604 /* wait until all active commands have completed on this port */ 605 timer_init(&Timer, 250); 606 while (ahci_port_busy(ai, p)) { 607 if (timer_check_and_block(&Timer)) break; 608 } 609 610 if (!init_complete) { 611 if ((pc = ahci_save_port_config(ai, p)) == NULL) { 612 goto exit_port_scan; 607 613 } 608 609 if (!init_complete) { 610 if ((pc = ahci_save_port_config(ai, p)) == NULL) { 611 goto exit_port_scan; 612 } 614 } 615 616 /* start/reset port; if no device is attached, this is expected to fail */ 617 if (init_reset) { 618 rc = ahci_reset_port(ai, p, 0); 619 } else { 620 ddprintf("ahci_scan_ports: (re)starting port %d\n", p); 621 ahci_stop_port(ai, p); 622 rc = ahci_start_port(ai, p, 0); 623 } 624 if (rc) { 625 /* no device attached to this port */ 626 ai->port_map &= ~(1UL << p); 627 goto restore_port_config; 628 } 629 630 /* this port seems to have a device attached and ready for commands */ 631 ddprintf("ahci_scan_ports: port %d seems to be attached to a device; probing...\n", p); 632 633 /* Get ATA(PI) identity. The so-called signature gives us a hint whether 634 * this is an ATA or an ATAPI device but we'll try both in either case; 635 * the signature will merely determine whether we're going to probe for 636 * an ATA or ATAPI device, first, in order to reduce the chance of sending 637 * the wrong command (which would result in a port reset given the way 638 * ahci_exec_polled_cmd() was implemented). 639 */ 640 is_ata = readl(port_base(ai, p) + PORT_SIG) == 0x00000101UL; 641 for (i = 0; i < 2; i++) { 642 rc = ahci_exec_polled_cmd(ai, p, 0, 500, 643 (is_ata) ? ATA_CMD_ID_ATA : ATA_CMD_ID_ATAPI, 644 AP_VADDR, (void _far *) id_buf, 512, 645 AP_END); 646 if (rc == 0) { 647 break; 613 648 } 614 649 615 /* start/reset port; if no device is attached, this is expected to fail */ 616 if (init_reset) { 617 rc = ahci_reset_port(ai, p, 0); 618 } else { 619 ddprintf("ahci_scan_ports: (re)starting port %d\n", p); 620 ahci_stop_port(ai, p); 621 rc = ahci_start_port(ai, p, 0); 622 } 623 if (rc) { 624 /* no device attached to this port */ 625 ai->port_map &= ~(1UL << p); 626 goto restore_port_config; 627 } 628 629 /* this port seems to have a device attached and ready for commands */ 630 ddprintf("ahci_scan_ports: port %d seems to be attached to a device; probing...\n", p); 631 632 /* Get ATA(PI) identity. The so-called signature gives us a hint whether 633 * this is an ATA or an ATAPI device but we'll try both in either case; 634 * the signature will merely determine whether we're going to probe for 635 * an ATA or ATAPI device, first, in order to reduce the chance of sending 636 * the wrong command (which would result in a port reset given the way 637 * ahci_exec_polled_cmd() was implemented). 638 */ 639 is_ata = readl(port_base(ai, p) + PORT_SIG) == 0x00000101UL; 640 for (i = 0; i < 2; i++) { 641 rc = ahci_exec_polled_cmd(ai, p, 0, 500, 642 (is_ata) ? ATA_CMD_ID_ATA : ATA_CMD_ID_ATAPI, 643 AP_VADDR, (void _far *) id_buf, 512, 644 AP_END); 645 if (rc == 0) { 646 break; 647 } 648 649 /* try again with ATA/ATAPI swapped */ 650 is_ata = !is_ata; 651 } 652 653 if (rc == 0) { 654 /* we have a valid IDENTIFY or IDENTIFY_PACKET response */ 655 ddphex(id_buf, 512, "ATA_IDENTIFY%s results:\n", (is_ata) ? "" : "_PACKET"); 656 ahci_setup_device(ai, p, 0, id_buf); 657 } else { 658 /* no device attached to this port */ 659 ai->port_map &= ~(1UL << p); 660 } 661 662 restore_port_config: 663 if (pc != NULL) { 664 ahci_restore_port_config(ai, p, pc); 665 } 650 /* try again with ATA/ATAPI swapped */ 651 is_ata = !is_ata; 652 } 653 654 if (rc == 0) { 655 /* we have a valid IDENTIFY or IDENTIFY_PACKET response */ 656 ddphex(id_buf, 512, "ATA_IDENTIFY%s results:\n", (is_ata) ? "" : "_PACKET"); 657 ahci_setup_device(ai, p, 0, id_buf); 658 } else { 659 /* no device attached to this port */ 660 ai->port_map &= ~(1UL << p); 661 } 662 663 restore_port_config: 664 if (pc != NULL) { 665 ahci_restore_port_config(ai, p, pc); 666 666 } 667 667 }
Note:
See TracChangeset
for help on using the changeset viewer.