Module Name: src Committed By: jdolecek Date: Wed Apr 19 21:42:39 UTC 2017
Modified Files: src/sys/dev/ata [jdolecek-ncq]: ata.c atareg.h atavar.h wd.c Log Message: add ATA FUA support To generate a diff of this commit: cvs rdiff -u -r1.132.8.5 -r1.132.8.6 src/sys/dev/ata/ata.c cvs rdiff -u -r1.43 -r1.43.18.1 src/sys/dev/ata/atareg.h cvs rdiff -u -r1.92.8.5 -r1.92.8.6 src/sys/dev/ata/atavar.h cvs rdiff -u -r1.428.2.8 -r1.428.2.9 src/sys/dev/ata/wd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/ata/ata.c diff -u src/sys/dev/ata/ata.c:1.132.8.5 src/sys/dev/ata/ata.c:1.132.8.6 --- src/sys/dev/ata/ata.c:1.132.8.5 Wed Apr 19 20:49:17 2017 +++ src/sys/dev/ata/ata.c Wed Apr 19 21:42:39 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: ata.c,v 1.132.8.5 2017/04/19 20:49:17 jdolecek Exp $ */ +/* $NetBSD: ata.c,v 1.132.8.6 2017/04/19 21:42:39 jdolecek Exp $ */ /* * Copyright (c) 1998, 2001 Manuel Bouyer. All rights reserved. @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.132.8.5 2017/04/19 20:49:17 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.132.8.6 2017/04/19 21:42:39 jdolecek Exp $"); #include "opt_ata.h" @@ -1980,8 +1980,14 @@ void atacmd_toncq(struct ata_xfer *xfer, uint8_t *cmd, uint16_t *count, uint16_t *features, uint8_t *device) { - if ((xfer->c_flags & C_NCQ) == 0) + if ((xfer->c_flags & C_NCQ) == 0) { + /* FUA handling for non-NCQ drives */ + if (xfer->c_bio.flags & ATA_FUA + && *cmd == WDCC_WRITEDMA_EXT) + *cmd = WDCC_WRITEDMA_FUA_EXT; + return; + } *cmd = (xfer->c_bio.flags & ATA_READ) ? WDCC_READ_FPDMA_QUEUED : WDCC_WRITE_FPDMA_QUEUED; @@ -1993,5 +1999,6 @@ atacmd_toncq(struct ata_xfer *xfer, uint *count = (xfer->c_slot << 3); /* other device flags */ - /* XXX FUA handling */ + if (xfer->c_bio.flags & ATA_FUA) + *device |= WDSD_FUA; } Index: src/sys/dev/ata/atareg.h diff -u src/sys/dev/ata/atareg.h:1.43 src/sys/dev/ata/atareg.h:1.43.18.1 --- src/sys/dev/ata/atareg.h:1.43 Wed Oct 30 15:37:49 2013 +++ src/sys/dev/ata/atareg.h Wed Apr 19 21:42:39 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: atareg.h,v 1.43 2013/10/30 15:37:49 drochner Exp $ */ +/* $NetBSD: atareg.h,v 1.43.18.1 2017/04/19 21:42:39 jdolecek Exp $ */ /* * Copyright (c) 1998, 2001 Manuel Bouyer. @@ -144,6 +144,7 @@ #define WDCC_READDMA_EXT 0x25 /* read 48-bit addressing with DMA */ #define WDCC_WRITEDMA_EXT 0x35 /* write 48-bit addressing with DMA */ +#define WDCC_WRITEDMA_FUA_EXT 0x3d /* write 48-bit addr with DMA & FUA */ #if defined(_KERNEL) || defined(_STANDALONE) #include <dev/ata/ataconf.h> @@ -248,6 +249,7 @@ atacmd_tostatq(int cmd32) #define WDSD_IBM 0xa0 /* forced to 512 byte sector, ecc */ #define WDSD_CHS 0x00 /* cylinder/head/sector addressing */ #define WDSD_LBA 0x40 /* logical block addressing */ +#define WDSD_FUA 0x80 /* Forced Unit Access (FUA) */ /* Commands for ATAPI devices */ #define ATAPI_CHECK_POWER_MODE 0xe5 Index: src/sys/dev/ata/atavar.h diff -u src/sys/dev/ata/atavar.h:1.92.8.5 src/sys/dev/ata/atavar.h:1.92.8.6 --- src/sys/dev/ata/atavar.h:1.92.8.5 Wed Apr 19 20:49:17 2017 +++ src/sys/dev/ata/atavar.h Wed Apr 19 21:42:39 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: atavar.h,v 1.92.8.5 2017/04/19 20:49:17 jdolecek Exp $ */ +/* $NetBSD: atavar.h,v 1.92.8.6 2017/04/19 21:42:39 jdolecek Exp $ */ /* * Copyright (c) 1998, 2001 Manuel Bouyer. @@ -49,6 +49,7 @@ struct ata_bio { #define ATA_READ 0x0020 /* transfer is a read (otherwise a write) */ #define ATA_CORR 0x0040 /* transfer had a corrected error */ #define ATA_LBA48 0x0080 /* transfer uses 48-bit LBA addressing */ +#define ATA_FUA 0x0100 /* transfer uses FUA */ daddr_t blkno; /* block addr */ daddr_t blkdone;/* number of blks transferred */ daddr_t nblks; /* number of block currently transferring */ Index: src/sys/dev/ata/wd.c diff -u src/sys/dev/ata/wd.c:1.428.2.8 src/sys/dev/ata/wd.c:1.428.2.9 --- src/sys/dev/ata/wd.c:1.428.2.8 Wed Apr 19 21:02:43 2017 +++ src/sys/dev/ata/wd.c Wed Apr 19 21:42:39 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: wd.c,v 1.428.2.8 2017/04/19 21:02:43 jdolecek Exp $ */ +/* $NetBSD: wd.c,v 1.428.2.9 2017/04/19 21:42:39 jdolecek Exp $ */ /* * Copyright (c) 1998, 2001 Manuel Bouyer. All rights reserved. @@ -54,7 +54,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.428.2.8 2017/04/19 21:02:43 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.428.2.9 2017/04/19 21:42:39 jdolecek Exp $"); #include "opt_ata.h" @@ -809,6 +809,14 @@ fail: xfer->c_bio.flags |= ATA_LBA; if (bp->b_flags & B_READ) xfer->c_bio.flags |= ATA_READ; + if (bp->b_flags & B_MEDIA_FUA) { + /* If not using NCQ, the command WRITE DMA FUA EXT is LBA48 */ + KASSERT((wd->sc_flags & WDF_LBA48) != 0); + if ((xfer->c_flags & C_NCQ) == 0) + xfer->c_bio.flags |= ATA_LBA48; + + xfer->c_bio.flags |= ATA_FUA; + } /* Instrumentation. */ disk_busy(&wd->sc_dk); @@ -982,7 +990,7 @@ wdminphys(struct buf *bp) /* * The limit is actually 65536 for LBA48 and 256 for non-LBA48, - * but that requires to pass set the count for the ATA command + * but that requires to set the count for the ATA command * to 0, which is somewhat error prone, so better stay safe. */ if (wd->sc_flags & WDF_LBA48) @@ -1900,6 +1908,9 @@ wd_getcache(struct wd_softc *wd, int *bi if (params.atap_cmd1_en & WDC_CMD1_CACHE) *bitsp |= DKCACHE_WRITE; + if (wd->drvp->drive_flags & (ATA_DRIVE_NCQ|ATA_DRIVE_WFUA)) + *bitsp |= DKCACHE_FUA; + return 0; }