Changeset 157 for trunk/src/os2ahci/ahci.c
- Timestamp:
- May 8, 2013, 5:10:33 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/os2ahci/ahci.c
r156 r157 331 331 332 332 /* spec says "leave reset bit on for at least 1ms"; make it 2ms */ 333 mdelay(2);333 udelay(2000); 334 334 335 335 writel(port_mmio + PORT_SCR_CTL, tmp); … … 341 341 * least hard disks complete the reset within a few milliseonds) 342 342 */ 343 m delay(20);343 msleep(20); 344 344 } 345 345 … … 448 448 return(0); 449 449 } 450 m delay(10);450 msleep(10); 451 451 } 452 452 … … 459 459 { 460 460 u32 tmp; 461 int timeout = 1000;461 TIMER Timer; 462 462 463 463 dprintf("controller reset starting on adapter %d\n", ad_no(ai)); … … 480 480 * the hardware should be considered fried. 481 481 */ 482 while (((tmp = readl(ai->mmio + HOST_CTL)) & HOST_RESET) == HOST_RESET) { 483 mdelay(10); 484 timeout -= 10; 485 if (timeout <= 0) { 486 dprintf("controller reset failed (0x%lx)\n", tmp); 487 return(-1); 488 } 482 timer_init(&Timer, 1000); 483 while (((tmp = readl(ai->mmio + HOST_CTL)) & HOST_RESET) != 0) { 484 if (timer_check_and_block(&Timer)) { 485 dprintf("controller reset failed (0x%lx)\n", tmp); 486 return(-1); 487 } 489 488 } 490 489 … … 497 496 ahci_restore_initial_config(ai); 498 497 499 500 501 502 503 504 505 506 507 508 509 510 498 if (ai->pci->vendor == PCI_VENDOR_ID_INTEL) { 499 u32 tmp16 = 0; 500 501 ddprintf("ahci_reset_controller: intel detected\n"); 502 /* configure PCS */ 503 pci_read_conf(ai->bus, ai->dev_func, 0x92, sizeof(u16), &tmp16); 504 if ((tmp16 & ai->port_map) != ai->port_map) { 505 ddprintf("ahci_reset_controller: updating PCS %x/%x\n", (u16)tmp16, ai->port_map); 506 tmp16 |= ai->port_map; 507 pci_write_conf(ai->bus, ai->dev_func, 0x92, sizeof(u16), tmp16); 508 } 509 } 511 510 512 511 return 0; … … 538 537 int p; 539 538 int i; 539 TIMER Timer; 540 540 541 541 if ((id_buf = malloc(ATA_ID_WORDS * sizeof(u16))) == NULL) { … … 561 561 ddprintf("ahci_scan_ports: Wait till not busy on port %d\n", p); 562 562 /* wait until all active commands have completed on this port */ 563 timer_init(&Timer, 250); 563 564 while (ahci_port_busy(ai, p)) { 564 msleep(250);565 if (timer_check_and_block(&Timer)) break; 565 566 } 566 567 … … 718 719 u8 _far *port_mmio = port_base(ai, p); 719 720 u32 tmp; 720 int timeout;721 TIMER Timer; 721 722 722 723 dprintf("ahci_reset_port: resetting port %d.%d\n", ad_no(ai), p); … … 762 763 763 764 /* spec says "leave reset bit on for at least 1ms"; make it 2ms */ 764 mdelay(2);765 udelay(2000); 765 766 766 767 writel(port_mmio + PORT_SCR_CTL, tmp); … … 768 769 769 770 /* wait for communication to be re-established after port reset */ 770 timeout = 5000; 771 dprintf("Wait for communication...\n"); 772 timer_init(&Timer, 500); 771 773 while (((tmp = readl(port_mmio + PORT_SCR_STAT)) & 3) != 3) { 772 mdelay(10); 773 timeout -= 10; 774 if (timeout <= 0) { 775 dprintf("no device present after resetting port #%d " 776 "(PORT_SCR_STAT = 0x%lx)\n", p, tmp); 774 if (timer_check_and_block(&Timer)) { 775 dprintf("no device present after resetting port #%d (PORT_SCR_STAT = 0x%lx)\n", p, tmp); 777 776 return(-1); 778 777 } … … 788 787 789 788 /* wait for device to be ready ((PxTFD & (BSY | DRQ | ERR)) == 0) */ 790 time out = 5000;789 timer_init(&Timer, 1000); 791 790 while (((tmp = readl(port_mmio + PORT_TFDATA)) & 0x89) != 0) { 792 mdelay(10); 793 timeout -= 10; 794 if (timeout <= 0) { 795 dprintf("device not ready on port #%d " 796 "(PORT_TFDATA = 0x%lx)\n", p, tmp); 791 if (timer_check_and_block(&Timer)) { 792 dprintf("device not ready on port #%d (PORT_TFDATA = 0x%lx)\n", p, tmp); 797 793 ahci_stop_port(ai, p); 798 794 return(-1); 799 795 } 800 796 } 801 ddprintf("ahci_reset_port: PORT_TFDATA 797 ddprintf("ahci_reset_port: PORT_TFDATA = 0x%lx\n", readl(port_mmio + PORT_TFDATA)); 802 798 803 799 return(0); … … 949 945 { 950 946 u8 _far *port_mmio = port_base(ai, p); 951 int timeout = 1000;947 TIMER Timer; 952 948 u32 tmp; 949 int status; 953 950 954 951 /* disable FIS reception */ … … 958 955 959 956 /* wait for completion, spec says 500ms, give it 1000ms */ 960 while (timeout > 0 && (readl(port_mmio + PORT_CMD) & PORT_CMD_FIS_ON)) { 961 mdelay(10); 962 timeout -= 10; 963 } 964 965 return((timeout <= 0) ? -1 : 0); 957 status = 0; 958 timer_init(&Timer, 1000); 959 while (readl(port_mmio + PORT_CMD) & PORT_CMD_FIS_ON) { 960 status = timer_check_and_block(&Timer); 961 if (status) break; 962 } 963 964 return(status ? -1 : 0); 966 965 } 967 966 … … 976 975 { 977 976 u8 _far *port_mmio = port_base(ai, p); 978 int timeout = 500; 977 TIMER Timer; 978 int status; 979 979 u32 tmp; 980 980 … … 991 991 992 992 /* wait for engine to stop. This could be as long as 500 msec */ 993 while (timeout > 0 && (readl(port_mmio + PORT_CMD) & PORT_CMD_LIST_ON)) { 994 mdelay(10); 995 timeout -= 10; 996 } 997 998 return((timeout <= 0) ? -1 : 0); 993 status = 0; 994 timer_init(&Timer, 500); 995 while (readl(port_mmio + PORT_CMD) & PORT_CMD_LIST_ON) { 996 status = timer_check_and_block(&Timer); 997 if (status) break; 998 } 999 1000 return(status ? -1 : 0); 999 1001 } 1000 1002 … … 1162 1164 int p = iorb_unit_port(iorb); 1163 1165 u8 _far *port_mmio = port_base(ai, p); 1166 TIMER Timer; 1167 int rc; 1164 1168 1165 1169 /* enable AHCI mode */ … … 1204 1208 ddprintf("executing polled cmd on slot 0..."); 1205 1209 writel(port_mmio + PORT_CMD_ISSUE, 1); 1206 timeout /= 10; 1207 while (timeout > 0 && (readl(port_mmio + PORT_CMD_ISSUE) & 1)) { 1208 mdelay(10); 1209 timeout--; 1210 } 1211 ddprintf(" done (time left = %ld)\n", timeout * 10); 1212 1213 if (timeout == 0) { 1210 timer_init(&Timer, timeout); 1211 while (readl(port_mmio + PORT_CMD_ISSUE) & 1) { 1212 rc = timer_check_and_block(&Timer); 1213 if (rc) break; 1214 } 1215 1216 if (rc) { 1214 1217 dprintf("timeout for IORB %Fp\n", iorb); 1215 1218 iorb_seterr(iorb, IOERR_ADAPTER_TIMEOUT); 1216 1217 1219 } else if (readl(port_mmio + PORT_SCR_ERR) != 0 || 1218 1220 readl(port_mmio + PORT_TFDATA) & 0x89) { … … 1220 1222 iorb_seterr(iorb, IOERR_DEVICE_NONSPECIFIC); 1221 1223 ahci_reset_port(ai, iorb_unit_port(iorb), 0); 1222 1223 1224 } else { 1224 1225 /* successfully executed command */ … … 1259 1260 u32 tmp; 1260 1261 int rc; 1262 TIMER Timer; 1261 1263 1262 1264 /* verify that command slot 0 is idle */ … … 1277 1279 1278 1280 /* wait until command has completed */ 1279 while (timeout > 0 && (readl(port_mmio + PORT_CMD_ISSUE) & 1)) { 1280 mdelay(10); 1281 timeout -= 10; 1282 } 1283 ddprintf(" done (time left = %d)\n", timeout); 1281 timer_init(&Timer, timeout); 1282 rc = 0; 1283 while (readl(port_mmio + PORT_CMD_ISSUE) & 1) { 1284 rc = timer_check_and_block(&Timer); 1285 if (rc) break; 1286 } 1284 1287 1285 1288 /* check error condition */ 1286 1289 if ((tmp = readl(port_mmio + PORT_SCR_ERR)) != 0) { 1287 1290 dprintf("SERR = 0x%08lx\n", tmp); 1288 timeout = 0;1291 rc = 1; 1289 1292 } 1290 1293 if (((tmp = readl(port_mmio + PORT_TFDATA)) & 0x89) != 0) { 1291 1294 dprintf("TFDATA = 0x%08lx\n", tmp); 1292 timeout = 0;1293 } 1294 1295 if ( timeout <= 0) {1295 rc = 1; 1296 } 1297 1298 if (rc) { 1296 1299 ahci_reset_port(ai, p, 0); 1297 1300 return(-1);
Note:
See TracChangeset
for help on using the changeset viewer.