I'm trying to execute ATA TRIM command on my SSD. It's Samsung SATA3 SSD but I use it in IDE legacy mode for compatability and simplicity so I control it via legacy I/O port 1F0h. I already had written a simple ATA driver so I can execute various ATA commands, read/write sectors etc. But I have a problem with TRIM command. I studied the description in ACS-2 and ACS-4 and I have some doubts if I set all parameters correctly, e.g. data register and features.
I already did a simple test:
ide_exec_command: I/O=1F0h, drv=0-W, cmd=06h, data=00h, feat=01h, LBA=0, scnt=1
rangelist[0] = 0001000000000003 (LBA start=3, sectors=1)
(rest of range 512B list sector was zeroed)
Code: Select all
outportb(io_base+IDE_CMR_DATA, 0); // set data reg.
outportb(io_base+IDE_CMR_FEAT_ERR, 0x01); // set features reg.
outportb(io_base+IDE_CMR_SECCNT, 1); // set sector count reg.
outportb(io_base+IDE_CMR_SECNUM, 0); // set sector number reg.
outportb(io_base+IDE_CMR_CYLLO, 0); // set cylinder low reg.
outportb(io_base+IDE_CMR_CYLHI, 0); // set cylinder high reg.
outportb(io_base+IDE_CMR_DRVSEL_HD, 0|(0<<4)|0xA0|0x40); // bit3:0 = head=0, bit4 = drive=0, bit5 = sect. size (1=512B), bit6 LBA/CHS (1=LBA), bit7 = 1
outportb(io_base+IDE_CMR_CMD_STAT, 0x06); // send IDE command (will be performed immediatelly)
ERROR: CMD_ABORT
STATUS: ERROR SEEK_DONE DRV_READY
RETURN: LBA=00000000h, scnt=00h, err=04h
The SSD ended in a bad state (wait busy timeout) where disk activity LED was lighting and I have to restart PC. When I looked at test LBA sector 3 with disk editor the content remained unchanged. Please can someone tell me what I'm doing wrong?
My SSD reports to support TRIM, DRAT, RZAT in device identify data and it works fine under Linux (fstrim).