Ignore:
Timestamp:
Dec 14, 2010, 9:35:35 PM (15 years ago)
Author:
markus
Message:

fixed ata_cmd to FIS mapping (LBA-28); removed sector mapping test code

File:
1 edited

Legend:

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

    r55 r57  
    3333
    3434
    35 /* #define LBATEST
    36  * uncomment to perform sector mapping test of first drive */
    37 
    38 #define LBATEST_SECTORS_PER_READ     64
    39 #define LBATEST_SECTOR_SIZE         512
    40 
    41 
    4235/* ------------------------ typedefs and structures ------------------------ */
    4336
     
    4639static void ahci_setup_device     (AD_INFO *ai, int p, int d, u16 *id_buf);
    4740static void _cdecl _far timeout_callback (ULONG timer_handle, ULONG p1, ULONG p2);
    48 
    49 #ifdef LBATEST
    50 static void lba_test              (AD_INFO *ai, int p, int d, u16 *id_buf);
    51 #endif
    5241
    5342/* ------------------------ global/static variables ------------------------ */
     
    15171506  }
    15181507
    1519 #ifdef LBATEST
    1520   /* if LBATEST is defined, we perform a sector mapping test
    1521    * for the first HD attached to the first adapter.
    1522    * The purose of this test is to determine if the sector
    1523    * mapping is correct throughout the entire disk.
    1524    */
    1525   if (total_dev_cnt == 1) {
    1526     lba_test(ai, p, 0, id_buf);
    1527   }
    1528 #endif
    1529 
    15301508
    15311509}
     
    15741552
    15751553
    1576 /*******************************************************************************
    1577  * Perform LBA to CHS mapping test.
    1578  * The purpose of this test is to find out if the driver's CHS to LBA mapping
    1579  * is correct throughout the entire physical hard disk.
    1580  *
    1581  * To perform the test, attach the test HD to a Linux box and run lbatest
    1582  * to write each sector's LBA to its first 4 bytes, then compile/install
    1583  * the driver with LBATEST defined.
    1584  */
    1585 #ifdef LBATEST
    1586 static void lba_test(AD_INFO *ai, int p, int d, u16 *id_buf)
    1587 {
    1588   u32 total_sectors = 0;
    1589   u32 sector;
    1590   int i;
    1591   unsigned char _far *buf;
    1592   u32 err_cnt = 0;
    1593   int rc;
    1594   u16 cbt = LBATEST_SECTOR_SIZE * LBATEST_SECTORS_PER_READ;
    1595   u32 phys_addr;
    1596 
    1597   /* determine number of sectors of this HD */
    1598   if (id_buf[ATA_ID_CFS_ENABLE_2] & 0x400) {
    1599     /* 48-bit LBA supported */
    1600     if (ATA_CAPACITY48_H(id_buf) != 0) {
    1601       /* more than 32 bits for number of sectors */
    1602       total_sectors = 0xffffffffUL;
    1603     } else {
    1604       total_sectors = ATA_CAPACITY48_L(id_buf);
    1605     }
    1606   } else {
    1607     /* 28-bit LBA */
    1608     total_sectors = ATA_CAPACITY(id_buf) & 0x0fffffffUL;
    1609   }
    1610 
    1611   /* allocate buffer */
    1612   spin_lock(drv_lock);
    1613   if (DevHelp_AllocPhys(cbt, 1, &phys_addr)) {
    1614     printf("Failed to allocate %ld bytes phys memory for lbatest\n");
    1615     spin_unlock(drv_lock);
    1616     return;
    1617   }
    1618   if (DevHelp_PhysToVirt(phys_addr, (USHORT) cbt, (PVOID) &buf, &i)) {
    1619     printf("Failed to convert phys addr to virt\n");
    1620     DevHelp_FreePhys(phys_addr);
    1621     spin_unlock(drv_lock);
    1622     return;
    1623   }
    1624   spin_unlock(drv_lock);
    1625 
    1626   /* go... */
    1627   memset(buf, 0x00, sizeof(buf));
    1628   for (sector = 0; sector < total_sectors; sector += LBATEST_SECTORS_PER_READ) {
    1629 
    1630     /* write progress to serial terminal */
    1631     if (sector % 1000 == 0) {
    1632       printf("lbatest: read %ldk sectors\n", sector / 1000);
    1633     }
    1634 
    1635     /* read appropriate number of sectors */
    1636     rc = ahci_exec_polled_cmd(ai, p, 0, 500, ATA_CMD_READ_EXT,
    1637                               AP_SECTOR_48, sector, (u16) 0,
    1638                               AP_VADDR, (void _far *) buf, cbt,
    1639                               AP_COUNT, (u16) LBATEST_SECTORS_PER_READ,
    1640                               AP_DEVICE, 0x4000,
    1641                               AP_END);
    1642 
    1643     /* verify lba numbers */
    1644     for (i = 0; i < LBATEST_SECTORS_PER_READ; i++) {
    1645       if (*((u32 _far*)(buf + i * LBATEST_SECTOR_SIZE)) != sector + i) {
    1646         printf("lbatest: read LBA 0x%08lx from sector 0x%08lx\n",
    1647                *((u32 _far*) buf), sector + i);
    1648         err_cnt++;
    1649       }
    1650                
    1651     }
    1652   }
    1653 
    1654   printf("lbatest: passed with %ld errors\n", err_cnt);
    1655    
    1656 cleanup_lbatest:
    1657   DevHelp_FreePhys(phys_addr);
    1658 
    1659   LBA test compiled?
    1660 
    1661 }
    1662 #endif
Note: See TracChangeset for help on using the changeset viewer.