Ignore:
Timestamp:
May 8, 2013, 5:10:33 PM (12 years ago)
Author:
David Azarewicz
Message:

Fixed up timer functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/os2ahci/ahci.c

    r156 r157  
    331331
    332332        /* spec says "leave reset bit on for at least 1ms"; make it 2ms */
    333         mdelay(2);
     333        udelay(2000);
    334334
    335335        writel(port_mmio + PORT_SCR_CTL, tmp);
     
    341341     * least hard disks complete the reset within a few milliseonds)
    342342     */
    343     mdelay(20);
     343    msleep(20);
    344344  }
    345345
     
    448448      return(0);
    449449    }
    450     mdelay(10);
     450    msleep(10);
    451451  }
    452452
     
    459459{
    460460    u32 tmp;
    461     int timeout = 1000;
     461    TIMER Timer;
    462462
    463463    dprintf("controller reset starting on adapter %d\n", ad_no(ai));
     
    480480     * the hardware should be considered fried.
    481481     */
    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      }
    489488    }
    490489
     
    497496    ahci_restore_initial_config(ai);
    498497
    499         if (ai->pci->vendor == PCI_VENDOR_ID_INTEL) {
    500                 u32 tmp16 = 0;
    501 
    502         ddprintf("ahci_reset_controller: intel detected\n");
    503                 /* configure PCS */
    504                 pci_read_conf(ai->bus, ai->dev_func, 0x92, sizeof(u16), &tmp16);
    505                 if ((tmp16 & ai->port_map) != ai->port_map) {
    506             ddprintf("ahci_reset_controller: updating PCS %x/%x\n", (u16)tmp16, ai->port_map);
    507                         tmp16 |= ai->port_map;
    508                         pci_write_conf(ai->bus, ai->dev_func, 0x92, sizeof(u16), tmp16);
    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    }
    511510
    512511    return 0;
     
    538537  int p;
    539538  int i;
     539  TIMER Timer;
    540540
    541541  if ((id_buf = malloc(ATA_ID_WORDS * sizeof(u16))) == NULL) {
     
    561561      ddprintf("ahci_scan_ports: Wait till not busy on port %d\n", p);
    562562      /* wait until all active commands have completed on this port */
     563      timer_init(&Timer, 250);
    563564      while (ahci_port_busy(ai, p)) {
    564         msleep(250);
     565        if (timer_check_and_block(&Timer)) break;
    565566      }
    566567
     
    718719  u8 _far *port_mmio = port_base(ai, p);
    719720  u32 tmp;
    720   int timeout;
     721  TIMER Timer;
    721722
    722723  dprintf("ahci_reset_port: resetting port %d.%d\n", ad_no(ai), p);
     
    762763
    763764  /* spec says "leave reset bit on for at least 1ms"; make it 2ms */
    764   mdelay(2);
     765  udelay(2000);
    765766
    766767  writel(port_mmio + PORT_SCR_CTL, tmp);
     
    768769
    769770  /* wait for communication to be re-established after port reset */
    770   timeout = 5000;
     771  dprintf("Wait for communication...\n");
     772  timer_init(&Timer, 500);
    771773  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);
    777776      return(-1);
    778777    }
     
    788787
    789788  /* wait for device to be ready ((PxTFD & (BSY | DRQ | ERR)) == 0) */
    790   timeout = 5000;
     789  timer_init(&Timer, 1000);
    791790  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);
    797793      ahci_stop_port(ai, p);
    798794      return(-1);
    799795    }
    800796  }
    801   ddprintf("ahci_reset_port: PORT_TFDATA   = 0x%lx\n", readl(port_mmio + PORT_TFDATA));
     797  ddprintf("ahci_reset_port: PORT_TFDATA = 0x%lx\n", readl(port_mmio + PORT_TFDATA));
    802798
    803799  return(0);
     
    949945{
    950946  u8 _far *port_mmio = port_base(ai, p);
    951   int timeout = 1000;
     947  TIMER Timer;
    952948  u32 tmp;
     949  int status;
    953950
    954951  /* disable FIS reception */
     
    958955
    959956  /* 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);
    966965}
    967966
     
    976975{
    977976  u8 _far *port_mmio = port_base(ai, p);
    978   int timeout = 500;
     977  TIMER Timer;
     978  int status;
    979979  u32 tmp;
    980980
     
    991991
    992992  /* 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);
    9991001}
    10001002
     
    11621164  int p = iorb_unit_port(iorb);
    11631165  u8 _far *port_mmio = port_base(ai, p);
     1166  TIMER Timer;
     1167  int rc;
    11641168
    11651169  /* enable AHCI mode */
     
    12041208    ddprintf("executing polled cmd on slot 0...");
    12051209    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) {
    12141217      dprintf("timeout for IORB %Fp\n", iorb);
    12151218      iorb_seterr(iorb, IOERR_ADAPTER_TIMEOUT);
    1216 
    12171219    } else if (readl(port_mmio + PORT_SCR_ERR) != 0 ||
    12181220               readl(port_mmio + PORT_TFDATA) & 0x89) {
     
    12201222      iorb_seterr(iorb, IOERR_DEVICE_NONSPECIFIC);
    12211223      ahci_reset_port(ai, iorb_unit_port(iorb), 0);
    1222 
    12231224    } else {
    12241225      /* successfully executed command */
     
    12591260  u32 tmp;
    12601261  int rc;
     1262  TIMER Timer;
    12611263
    12621264  /* verify that command slot 0 is idle */
     
    12771279
    12781280  /* 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  }
    12841287
    12851288  /* check error condition */
    12861289  if ((tmp = readl(port_mmio + PORT_SCR_ERR)) != 0) {
    12871290    dprintf("SERR = 0x%08lx\n", tmp);
    1288     timeout = 0;
     1291    rc = 1;
    12891292  }
    12901293  if (((tmp = readl(port_mmio + PORT_TFDATA)) & 0x89) != 0) {
    12911294    dprintf("TFDATA = 0x%08lx\n", tmp);
    1292     timeout = 0;
    1293   }
    1294 
    1295   if (timeout <= 0) {
     1295    rc = 1;
     1296  }
     1297
     1298  if (rc) {
    12961299    ahci_reset_port(ai, p, 0);
    12971300    return(-1);
Note: See TracChangeset for help on using the changeset viewer.