Changeset 53


Ignore:
Timestamp:
Dec 5, 2010, 6:09:04 PM (15 years ago)
Author:
markus
Message:

version with lba mapping (read) test

File:
1 edited

Legend:

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

    r42 r53  
    3232                              ? atapi_##func : ata_##func
    3333
     34#define LBATEST_SECTORS_PER_READ     64
     35#define LBATEST_SECTOR_SIZE         512
     36
     37#define LBATEST
    3438
    3539/* ------------------------ typedefs and structures ------------------------ */
     
    3943static void ahci_setup_device     (AD_INFO *ai, int p, int d, u16 *id_buf);
    4044static void _cdecl _far timeout_callback (ULONG timer_handle, ULONG p1, ULONG p2);
     45
     46#ifdef LBATEST
     47static void lba_test              (AD_INFO *ai, int p, int d, u16 *id_buf);
     48#endif
    4149
    4250/* ------------------------ global/static variables ------------------------ */
     
    470478        ddphex(id_buf, 512, "ATA_IDENTIFY(_PACKET) results:\n");
    471479        ahci_setup_device(ai, p, 0, id_buf);
    472 
    473480      } else {
    474481        /* no device attached to this port */
     
    15061513    pci_hack_virtualbox();
    15071514  }
     1515
     1516#ifdef LBATEST
     1517  /* if LBATEST is defined, we perform a sector mapping test
     1518   * for the first HD attached to the first adapter.
     1519   * The purose of this test is to determine if the sector
     1520   * mapping is correct throughout the entire disk.
     1521   */
     1522  if (total_dev_cnt == 1) {
     1523    lba_test(ai, p, 0, id_buf);
     1524  }
     1525#endif
     1526
     1527
    15081528}
    15091529
     
    15501570}
    15511571
     1572
     1573/*******************************************************************************
     1574 * Perform LBA to CHS mapping test.
     1575 * The purpose of this test is to find out if the driver's CHS to LBA mapping
     1576 * is correct throughout the entire physical hard disk.
     1577 *
     1578 * To perform the test, attach the test HD to a Linux box and run lbatest
     1579 * to write each sector's LBA to its first 4 bytes, then compile/install
     1580 * the driver with LBATEST defined.
     1581 */
     1582#ifdef LBATEST
     1583static void lba_test(AD_INFO *ai, int p, int d, u16 *id_buf)
     1584{
     1585  u32 total_sectors = 0;
     1586  u32 sector;
     1587  int i;
     1588  unsigned char _far *buf;
     1589  u32 err_cnt = 0;
     1590  int rc;
     1591  u16 cbt = LBATEST_SECTOR_SIZE * LBATEST_SECTORS_PER_READ;
     1592  u32 phys_addr;
     1593
     1594  /* determine number of sectors of this HD */
     1595  if (id_buf[ATA_ID_CFS_ENABLE_2] & 0x400) {
     1596    /* 48-bit LBA supported */
     1597    if (ATA_CAPACITY48_H(id_buf) != 0) {
     1598      /* more than 32 bits for number of sectors */
     1599      total_sectors = 0xffffffffUL;
     1600    } else {
     1601      total_sectors = ATA_CAPACITY48_L(id_buf);
     1602    }
     1603  } else {
     1604    /* 28-bit LBA */
     1605    total_sectors = ATA_CAPACITY(id_buf) & 0x0fffffffUL;
     1606  }
     1607
     1608  /* allocate buffer */
     1609  spin_lock(drv_lock);
     1610  if (DevHelp_AllocPhys(cbt, 1, &phys_addr)) {
     1611    printf("Failed to allocate %ld bytes phys memory for lbatest\n");
     1612    spin_unlock(drv_lock);
     1613    return;
     1614  }
     1615  if (DevHelp_PhysToVirt(phys_addr, (USHORT) cbt, (PVOID) &buf, &i)) {
     1616    printf("Failed to convert phys addr to virt\n");
     1617    DevHelp_FreePhys(phys_addr);
     1618    spin_unlock(drv_lock);
     1619    return;
     1620  }
     1621  spin_unlock(drv_lock);
     1622
     1623  /* go... */
     1624  memset(buf, 0x00, sizeof(buf));
     1625  for (sector = 0; sector < total_sectors; sector += LBATEST_SECTORS_PER_READ) {
     1626
     1627    /* write progress to serial terminal */
     1628    if (sector % 1000 == 0) {
     1629      printf("lbatest: read %ldk sectors\n", sector / 1000);
     1630    }
     1631
     1632    /* read appropriate number of sectors */
     1633    rc = ahci_exec_polled_cmd(ai, p, 0, 500, ATA_CMD_READ_EXT,
     1634                              AP_SECTOR_48, sector, (u16) 0,
     1635                              AP_VADDR, (void _far *) buf, cbt,
     1636                              AP_COUNT, (u16) LBATEST_SECTORS_PER_READ,
     1637                              AP_DEVICE, 0x4000,
     1638                              AP_END);
     1639
     1640    /* verify lba numbers */
     1641    for (i = 0; i < LBATEST_SECTORS_PER_READ; i++) {
     1642      if (*((u32 _far*)(buf + i * LBATEST_SECTOR_SIZE)) != sector + i) {
     1643        printf("lbatest: read LBA 0x%08lx from sector 0x%08lx\n",
     1644               *((u32 _far*) buf), sector + i);
     1645        err_cnt++;
     1646      }
     1647               
     1648    }
     1649  }
     1650
     1651  printf("lbatest: passed with %ld errors\n", err_cnt);
     1652   
     1653cleanup_lbatest:
     1654  DevHelp_FreePhys(phys_addr);
     1655
     1656}
     1657#endif
Note: See TracChangeset for help on using the changeset viewer.