18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci/*
48c2ecf20Sopenharmony_ci *  Copyright 2003-2004 Red Hat, Inc.  All rights reserved.
58c2ecf20Sopenharmony_ci *  Copyright 2003-2004 Jeff Garzik
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *  libata documentation is available via 'make {ps|pdf}docs',
88c2ecf20Sopenharmony_ci *  as Documentation/driver-api/libata.rst
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci *  Hardware documentation available from http://www.t13.org/
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#ifndef __LINUX_ATA_H__
148c2ecf20Sopenharmony_ci#define __LINUX_ATA_H__
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <linux/kernel.h>
178c2ecf20Sopenharmony_ci#include <linux/string.h>
188c2ecf20Sopenharmony_ci#include <linux/types.h>
198c2ecf20Sopenharmony_ci#include <asm/byteorder.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/* defines only for the constants which don't work well as enums */
228c2ecf20Sopenharmony_ci#define ATA_DMA_BOUNDARY	0xffffUL
238c2ecf20Sopenharmony_ci#define ATA_DMA_MASK		0xffffffffULL
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cienum {
268c2ecf20Sopenharmony_ci	/* various global constants */
278c2ecf20Sopenharmony_ci	ATA_MAX_DEVICES		= 2,	/* per bus/port */
288c2ecf20Sopenharmony_ci	ATA_MAX_PRD		= 256,	/* we could make these 256/256 */
298c2ecf20Sopenharmony_ci	ATA_SECT_SIZE		= 512,
308c2ecf20Sopenharmony_ci	ATA_MAX_SECTORS_128	= 128,
318c2ecf20Sopenharmony_ci	ATA_MAX_SECTORS		= 256,
328c2ecf20Sopenharmony_ci	ATA_MAX_SECTORS_1024    = 1024,
338c2ecf20Sopenharmony_ci	ATA_MAX_SECTORS_LBA48	= 65535,/* avoid count to be 0000h */
348c2ecf20Sopenharmony_ci	ATA_MAX_SECTORS_TAPE	= 65535,
358c2ecf20Sopenharmony_ci	ATA_MAX_TRIM_RNUM	= 64,	/* 512-byte payload / (6-byte LBA + 2-byte range per entry) */
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	ATA_ID_WORDS		= 256,
388c2ecf20Sopenharmony_ci	ATA_ID_CONFIG		= 0,
398c2ecf20Sopenharmony_ci	ATA_ID_CYLS		= 1,
408c2ecf20Sopenharmony_ci	ATA_ID_HEADS		= 3,
418c2ecf20Sopenharmony_ci	ATA_ID_SECTORS		= 6,
428c2ecf20Sopenharmony_ci	ATA_ID_SERNO		= 10,
438c2ecf20Sopenharmony_ci	ATA_ID_BUF_SIZE		= 21,
448c2ecf20Sopenharmony_ci	ATA_ID_FW_REV		= 23,
458c2ecf20Sopenharmony_ci	ATA_ID_PROD		= 27,
468c2ecf20Sopenharmony_ci	ATA_ID_MAX_MULTSECT	= 47,
478c2ecf20Sopenharmony_ci	ATA_ID_DWORD_IO		= 48,	/* before ATA-8 */
488c2ecf20Sopenharmony_ci	ATA_ID_TRUSTED		= 48,	/* ATA-8 and later */
498c2ecf20Sopenharmony_ci	ATA_ID_CAPABILITY	= 49,
508c2ecf20Sopenharmony_ci	ATA_ID_OLD_PIO_MODES	= 51,
518c2ecf20Sopenharmony_ci	ATA_ID_OLD_DMA_MODES	= 52,
528c2ecf20Sopenharmony_ci	ATA_ID_FIELD_VALID	= 53,
538c2ecf20Sopenharmony_ci	ATA_ID_CUR_CYLS		= 54,
548c2ecf20Sopenharmony_ci	ATA_ID_CUR_HEADS	= 55,
558c2ecf20Sopenharmony_ci	ATA_ID_CUR_SECTORS	= 56,
568c2ecf20Sopenharmony_ci	ATA_ID_MULTSECT		= 59,
578c2ecf20Sopenharmony_ci	ATA_ID_LBA_CAPACITY	= 60,
588c2ecf20Sopenharmony_ci	ATA_ID_SWDMA_MODES	= 62,
598c2ecf20Sopenharmony_ci	ATA_ID_MWDMA_MODES	= 63,
608c2ecf20Sopenharmony_ci	ATA_ID_PIO_MODES	= 64,
618c2ecf20Sopenharmony_ci	ATA_ID_EIDE_DMA_MIN	= 65,
628c2ecf20Sopenharmony_ci	ATA_ID_EIDE_DMA_TIME	= 66,
638c2ecf20Sopenharmony_ci	ATA_ID_EIDE_PIO		= 67,
648c2ecf20Sopenharmony_ci	ATA_ID_EIDE_PIO_IORDY	= 68,
658c2ecf20Sopenharmony_ci	ATA_ID_ADDITIONAL_SUPP	= 69,
668c2ecf20Sopenharmony_ci	ATA_ID_QUEUE_DEPTH	= 75,
678c2ecf20Sopenharmony_ci	ATA_ID_SATA_CAPABILITY	= 76,
688c2ecf20Sopenharmony_ci	ATA_ID_SATA_CAPABILITY_2	= 77,
698c2ecf20Sopenharmony_ci	ATA_ID_FEATURE_SUPP	= 78,
708c2ecf20Sopenharmony_ci	ATA_ID_MAJOR_VER	= 80,
718c2ecf20Sopenharmony_ci	ATA_ID_COMMAND_SET_1	= 82,
728c2ecf20Sopenharmony_ci	ATA_ID_COMMAND_SET_2	= 83,
738c2ecf20Sopenharmony_ci	ATA_ID_CFSSE		= 84,
748c2ecf20Sopenharmony_ci	ATA_ID_CFS_ENABLE_1	= 85,
758c2ecf20Sopenharmony_ci	ATA_ID_CFS_ENABLE_2	= 86,
768c2ecf20Sopenharmony_ci	ATA_ID_CSF_DEFAULT	= 87,
778c2ecf20Sopenharmony_ci	ATA_ID_UDMA_MODES	= 88,
788c2ecf20Sopenharmony_ci	ATA_ID_HW_CONFIG	= 93,
798c2ecf20Sopenharmony_ci	ATA_ID_SPG		= 98,
808c2ecf20Sopenharmony_ci	ATA_ID_LBA_CAPACITY_2	= 100,
818c2ecf20Sopenharmony_ci	ATA_ID_SECTOR_SIZE	= 106,
828c2ecf20Sopenharmony_ci	ATA_ID_WWN		= 108,
838c2ecf20Sopenharmony_ci	ATA_ID_LOGICAL_SECTOR_SIZE	= 117,	/* and 118 */
848c2ecf20Sopenharmony_ci	ATA_ID_COMMAND_SET_3	= 119,
858c2ecf20Sopenharmony_ci	ATA_ID_COMMAND_SET_4	= 120,
868c2ecf20Sopenharmony_ci	ATA_ID_LAST_LUN		= 126,
878c2ecf20Sopenharmony_ci	ATA_ID_DLF		= 128,
888c2ecf20Sopenharmony_ci	ATA_ID_CSFO		= 129,
898c2ecf20Sopenharmony_ci	ATA_ID_CFA_POWER	= 160,
908c2ecf20Sopenharmony_ci	ATA_ID_CFA_KEY_MGMT	= 162,
918c2ecf20Sopenharmony_ci	ATA_ID_CFA_MODES	= 163,
928c2ecf20Sopenharmony_ci	ATA_ID_DATA_SET_MGMT	= 169,
938c2ecf20Sopenharmony_ci	ATA_ID_SCT_CMD_XPORT	= 206,
948c2ecf20Sopenharmony_ci	ATA_ID_ROT_SPEED	= 217,
958c2ecf20Sopenharmony_ci	ATA_ID_PIO4		= (1 << 1),
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	ATA_ID_SERNO_LEN	= 20,
988c2ecf20Sopenharmony_ci	ATA_ID_FW_REV_LEN	= 8,
998c2ecf20Sopenharmony_ci	ATA_ID_PROD_LEN		= 40,
1008c2ecf20Sopenharmony_ci	ATA_ID_WWN_LEN		= 8,
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci	ATA_PCI_CTL_OFS		= 2,
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	ATA_PIO0		= (1 << 0),
1058c2ecf20Sopenharmony_ci	ATA_PIO1		= ATA_PIO0 | (1 << 1),
1068c2ecf20Sopenharmony_ci	ATA_PIO2		= ATA_PIO1 | (1 << 2),
1078c2ecf20Sopenharmony_ci	ATA_PIO3		= ATA_PIO2 | (1 << 3),
1088c2ecf20Sopenharmony_ci	ATA_PIO4		= ATA_PIO3 | (1 << 4),
1098c2ecf20Sopenharmony_ci	ATA_PIO5		= ATA_PIO4 | (1 << 5),
1108c2ecf20Sopenharmony_ci	ATA_PIO6		= ATA_PIO5 | (1 << 6),
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci	ATA_PIO4_ONLY		= (1 << 4),
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci	ATA_SWDMA0		= (1 << 0),
1158c2ecf20Sopenharmony_ci	ATA_SWDMA1		= ATA_SWDMA0 | (1 << 1),
1168c2ecf20Sopenharmony_ci	ATA_SWDMA2		= ATA_SWDMA1 | (1 << 2),
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	ATA_SWDMA2_ONLY		= (1 << 2),
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	ATA_MWDMA0		= (1 << 0),
1218c2ecf20Sopenharmony_ci	ATA_MWDMA1		= ATA_MWDMA0 | (1 << 1),
1228c2ecf20Sopenharmony_ci	ATA_MWDMA2		= ATA_MWDMA1 | (1 << 2),
1238c2ecf20Sopenharmony_ci	ATA_MWDMA3		= ATA_MWDMA2 | (1 << 3),
1248c2ecf20Sopenharmony_ci	ATA_MWDMA4		= ATA_MWDMA3 | (1 << 4),
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	ATA_MWDMA12_ONLY	= (1 << 1) | (1 << 2),
1278c2ecf20Sopenharmony_ci	ATA_MWDMA2_ONLY		= (1 << 2),
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	ATA_UDMA0		= (1 << 0),
1308c2ecf20Sopenharmony_ci	ATA_UDMA1		= ATA_UDMA0 | (1 << 1),
1318c2ecf20Sopenharmony_ci	ATA_UDMA2		= ATA_UDMA1 | (1 << 2),
1328c2ecf20Sopenharmony_ci	ATA_UDMA3		= ATA_UDMA2 | (1 << 3),
1338c2ecf20Sopenharmony_ci	ATA_UDMA4		= ATA_UDMA3 | (1 << 4),
1348c2ecf20Sopenharmony_ci	ATA_UDMA5		= ATA_UDMA4 | (1 << 5),
1358c2ecf20Sopenharmony_ci	ATA_UDMA6		= ATA_UDMA5 | (1 << 6),
1368c2ecf20Sopenharmony_ci	ATA_UDMA7		= ATA_UDMA6 | (1 << 7),
1378c2ecf20Sopenharmony_ci	/* ATA_UDMA7 is just for completeness... doesn't exist (yet?).  */
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci	ATA_UDMA24_ONLY		= (1 << 2) | (1 << 4),
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	ATA_UDMA_MASK_40C	= ATA_UDMA2,	/* udma0-2 */
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci	/* DMA-related */
1448c2ecf20Sopenharmony_ci	ATA_PRD_SZ		= 8,
1458c2ecf20Sopenharmony_ci	ATA_PRD_TBL_SZ		= (ATA_MAX_PRD * ATA_PRD_SZ),
1468c2ecf20Sopenharmony_ci	ATA_PRD_EOT		= (1 << 31),	/* end-of-table flag */
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	ATA_DMA_TABLE_OFS	= 4,
1498c2ecf20Sopenharmony_ci	ATA_DMA_STATUS		= 2,
1508c2ecf20Sopenharmony_ci	ATA_DMA_CMD		= 0,
1518c2ecf20Sopenharmony_ci	ATA_DMA_WR		= (1 << 3),
1528c2ecf20Sopenharmony_ci	ATA_DMA_START		= (1 << 0),
1538c2ecf20Sopenharmony_ci	ATA_DMA_INTR		= (1 << 2),
1548c2ecf20Sopenharmony_ci	ATA_DMA_ERR		= (1 << 1),
1558c2ecf20Sopenharmony_ci	ATA_DMA_ACTIVE		= (1 << 0),
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	/* bits in ATA command block registers */
1588c2ecf20Sopenharmony_ci	ATA_HOB			= (1 << 7),	/* LBA48 selector */
1598c2ecf20Sopenharmony_ci	ATA_NIEN		= (1 << 1),	/* disable-irq flag */
1608c2ecf20Sopenharmony_ci	ATA_LBA			= (1 << 6),	/* LBA28 selector */
1618c2ecf20Sopenharmony_ci	ATA_DEV1		= (1 << 4),	/* Select Device 1 (slave) */
1628c2ecf20Sopenharmony_ci	ATA_DEVICE_OBS		= (1 << 7) | (1 << 5), /* obs bits in dev reg */
1638c2ecf20Sopenharmony_ci	ATA_DEVCTL_OBS		= (1 << 3),	/* obsolete bit in devctl reg */
1648c2ecf20Sopenharmony_ci	ATA_BUSY		= (1 << 7),	/* BSY status bit */
1658c2ecf20Sopenharmony_ci	ATA_DRDY		= (1 << 6),	/* device ready */
1668c2ecf20Sopenharmony_ci	ATA_DF			= (1 << 5),	/* device fault */
1678c2ecf20Sopenharmony_ci	ATA_DSC			= (1 << 4),	/* drive seek complete */
1688c2ecf20Sopenharmony_ci	ATA_DRQ			= (1 << 3),	/* data request i/o */
1698c2ecf20Sopenharmony_ci	ATA_CORR		= (1 << 2),	/* corrected data error */
1708c2ecf20Sopenharmony_ci	ATA_SENSE		= (1 << 1),	/* sense code available */
1718c2ecf20Sopenharmony_ci	ATA_ERR			= (1 << 0),	/* have an error */
1728c2ecf20Sopenharmony_ci	ATA_SRST		= (1 << 2),	/* software reset */
1738c2ecf20Sopenharmony_ci	ATA_ICRC		= (1 << 7),	/* interface CRC error */
1748c2ecf20Sopenharmony_ci	ATA_BBK			= ATA_ICRC,	/* pre-EIDE: block marked bad */
1758c2ecf20Sopenharmony_ci	ATA_UNC			= (1 << 6),	/* uncorrectable media error */
1768c2ecf20Sopenharmony_ci	ATA_MC			= (1 << 5),	/* media changed */
1778c2ecf20Sopenharmony_ci	ATA_IDNF		= (1 << 4),	/* ID not found */
1788c2ecf20Sopenharmony_ci	ATA_MCR			= (1 << 3),	/* media change requested */
1798c2ecf20Sopenharmony_ci	ATA_ABORTED		= (1 << 2),	/* command aborted */
1808c2ecf20Sopenharmony_ci	ATA_TRK0NF		= (1 << 1),	/* track 0 not found */
1818c2ecf20Sopenharmony_ci	ATA_AMNF		= (1 << 0),	/* address mark not found */
1828c2ecf20Sopenharmony_ci	ATAPI_LFS		= 0xF0,		/* last failed sense */
1838c2ecf20Sopenharmony_ci	ATAPI_EOM		= ATA_TRK0NF,	/* end of media */
1848c2ecf20Sopenharmony_ci	ATAPI_ILI		= ATA_AMNF,	/* illegal length indication */
1858c2ecf20Sopenharmony_ci	ATAPI_IO		= (1 << 1),
1868c2ecf20Sopenharmony_ci	ATAPI_COD		= (1 << 0),
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	/* ATA command block registers */
1898c2ecf20Sopenharmony_ci	ATA_REG_DATA		= 0x00,
1908c2ecf20Sopenharmony_ci	ATA_REG_ERR		= 0x01,
1918c2ecf20Sopenharmony_ci	ATA_REG_NSECT		= 0x02,
1928c2ecf20Sopenharmony_ci	ATA_REG_LBAL		= 0x03,
1938c2ecf20Sopenharmony_ci	ATA_REG_LBAM		= 0x04,
1948c2ecf20Sopenharmony_ci	ATA_REG_LBAH		= 0x05,
1958c2ecf20Sopenharmony_ci	ATA_REG_DEVICE		= 0x06,
1968c2ecf20Sopenharmony_ci	ATA_REG_STATUS		= 0x07,
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci	ATA_REG_FEATURE		= ATA_REG_ERR, /* and their aliases */
1998c2ecf20Sopenharmony_ci	ATA_REG_CMD		= ATA_REG_STATUS,
2008c2ecf20Sopenharmony_ci	ATA_REG_BYTEL		= ATA_REG_LBAM,
2018c2ecf20Sopenharmony_ci	ATA_REG_BYTEH		= ATA_REG_LBAH,
2028c2ecf20Sopenharmony_ci	ATA_REG_DEVSEL		= ATA_REG_DEVICE,
2038c2ecf20Sopenharmony_ci	ATA_REG_IRQ		= ATA_REG_NSECT,
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	/* ATA device commands */
2068c2ecf20Sopenharmony_ci	ATA_CMD_DEV_RESET	= 0x08, /* ATAPI device reset */
2078c2ecf20Sopenharmony_ci	ATA_CMD_CHK_POWER	= 0xE5, /* check power mode */
2088c2ecf20Sopenharmony_ci	ATA_CMD_STANDBY		= 0xE2, /* place in standby power mode */
2098c2ecf20Sopenharmony_ci	ATA_CMD_IDLE		= 0xE3, /* place in idle power mode */
2108c2ecf20Sopenharmony_ci	ATA_CMD_EDD		= 0x90,	/* execute device diagnostic */
2118c2ecf20Sopenharmony_ci	ATA_CMD_DOWNLOAD_MICRO  = 0x92,
2128c2ecf20Sopenharmony_ci	ATA_CMD_DOWNLOAD_MICRO_DMA = 0x93,
2138c2ecf20Sopenharmony_ci	ATA_CMD_NOP		= 0x00,
2148c2ecf20Sopenharmony_ci	ATA_CMD_FLUSH		= 0xE7,
2158c2ecf20Sopenharmony_ci	ATA_CMD_FLUSH_EXT	= 0xEA,
2168c2ecf20Sopenharmony_ci	ATA_CMD_ID_ATA		= 0xEC,
2178c2ecf20Sopenharmony_ci	ATA_CMD_ID_ATAPI	= 0xA1,
2188c2ecf20Sopenharmony_ci	ATA_CMD_SERVICE		= 0xA2,
2198c2ecf20Sopenharmony_ci	ATA_CMD_READ		= 0xC8,
2208c2ecf20Sopenharmony_ci	ATA_CMD_READ_EXT	= 0x25,
2218c2ecf20Sopenharmony_ci	ATA_CMD_READ_QUEUED	= 0x26,
2228c2ecf20Sopenharmony_ci	ATA_CMD_READ_STREAM_EXT	= 0x2B,
2238c2ecf20Sopenharmony_ci	ATA_CMD_READ_STREAM_DMA_EXT = 0x2A,
2248c2ecf20Sopenharmony_ci	ATA_CMD_WRITE		= 0xCA,
2258c2ecf20Sopenharmony_ci	ATA_CMD_WRITE_EXT	= 0x35,
2268c2ecf20Sopenharmony_ci	ATA_CMD_WRITE_QUEUED	= 0x36,
2278c2ecf20Sopenharmony_ci	ATA_CMD_WRITE_STREAM_EXT = 0x3B,
2288c2ecf20Sopenharmony_ci	ATA_CMD_WRITE_STREAM_DMA_EXT = 0x3A,
2298c2ecf20Sopenharmony_ci	ATA_CMD_WRITE_FUA_EXT	= 0x3D,
2308c2ecf20Sopenharmony_ci	ATA_CMD_WRITE_QUEUED_FUA_EXT = 0x3E,
2318c2ecf20Sopenharmony_ci	ATA_CMD_FPDMA_READ	= 0x60,
2328c2ecf20Sopenharmony_ci	ATA_CMD_FPDMA_WRITE	= 0x61,
2338c2ecf20Sopenharmony_ci	ATA_CMD_NCQ_NON_DATA	= 0x63,
2348c2ecf20Sopenharmony_ci	ATA_CMD_FPDMA_SEND	= 0x64,
2358c2ecf20Sopenharmony_ci	ATA_CMD_FPDMA_RECV	= 0x65,
2368c2ecf20Sopenharmony_ci	ATA_CMD_PIO_READ	= 0x20,
2378c2ecf20Sopenharmony_ci	ATA_CMD_PIO_READ_EXT	= 0x24,
2388c2ecf20Sopenharmony_ci	ATA_CMD_PIO_WRITE	= 0x30,
2398c2ecf20Sopenharmony_ci	ATA_CMD_PIO_WRITE_EXT	= 0x34,
2408c2ecf20Sopenharmony_ci	ATA_CMD_READ_MULTI	= 0xC4,
2418c2ecf20Sopenharmony_ci	ATA_CMD_READ_MULTI_EXT	= 0x29,
2428c2ecf20Sopenharmony_ci	ATA_CMD_WRITE_MULTI	= 0xC5,
2438c2ecf20Sopenharmony_ci	ATA_CMD_WRITE_MULTI_EXT	= 0x39,
2448c2ecf20Sopenharmony_ci	ATA_CMD_WRITE_MULTI_FUA_EXT = 0xCE,
2458c2ecf20Sopenharmony_ci	ATA_CMD_SET_FEATURES	= 0xEF,
2468c2ecf20Sopenharmony_ci	ATA_CMD_SET_MULTI	= 0xC6,
2478c2ecf20Sopenharmony_ci	ATA_CMD_PACKET		= 0xA0,
2488c2ecf20Sopenharmony_ci	ATA_CMD_VERIFY		= 0x40,
2498c2ecf20Sopenharmony_ci	ATA_CMD_VERIFY_EXT	= 0x42,
2508c2ecf20Sopenharmony_ci	ATA_CMD_WRITE_UNCORR_EXT = 0x45,
2518c2ecf20Sopenharmony_ci	ATA_CMD_STANDBYNOW1	= 0xE0,
2528c2ecf20Sopenharmony_ci	ATA_CMD_IDLEIMMEDIATE	= 0xE1,
2538c2ecf20Sopenharmony_ci	ATA_CMD_SLEEP		= 0xE6,
2548c2ecf20Sopenharmony_ci	ATA_CMD_INIT_DEV_PARAMS	= 0x91,
2558c2ecf20Sopenharmony_ci	ATA_CMD_READ_NATIVE_MAX	= 0xF8,
2568c2ecf20Sopenharmony_ci	ATA_CMD_READ_NATIVE_MAX_EXT = 0x27,
2578c2ecf20Sopenharmony_ci	ATA_CMD_SET_MAX		= 0xF9,
2588c2ecf20Sopenharmony_ci	ATA_CMD_SET_MAX_EXT	= 0x37,
2598c2ecf20Sopenharmony_ci	ATA_CMD_READ_LOG_EXT	= 0x2F,
2608c2ecf20Sopenharmony_ci	ATA_CMD_WRITE_LOG_EXT	= 0x3F,
2618c2ecf20Sopenharmony_ci	ATA_CMD_READ_LOG_DMA_EXT = 0x47,
2628c2ecf20Sopenharmony_ci	ATA_CMD_WRITE_LOG_DMA_EXT = 0x57,
2638c2ecf20Sopenharmony_ci	ATA_CMD_TRUSTED_NONDATA	= 0x5B,
2648c2ecf20Sopenharmony_ci	ATA_CMD_TRUSTED_RCV	= 0x5C,
2658c2ecf20Sopenharmony_ci	ATA_CMD_TRUSTED_RCV_DMA = 0x5D,
2668c2ecf20Sopenharmony_ci	ATA_CMD_TRUSTED_SND	= 0x5E,
2678c2ecf20Sopenharmony_ci	ATA_CMD_TRUSTED_SND_DMA = 0x5F,
2688c2ecf20Sopenharmony_ci	ATA_CMD_PMP_READ	= 0xE4,
2698c2ecf20Sopenharmony_ci	ATA_CMD_PMP_READ_DMA	= 0xE9,
2708c2ecf20Sopenharmony_ci	ATA_CMD_PMP_WRITE	= 0xE8,
2718c2ecf20Sopenharmony_ci	ATA_CMD_PMP_WRITE_DMA	= 0xEB,
2728c2ecf20Sopenharmony_ci	ATA_CMD_CONF_OVERLAY	= 0xB1,
2738c2ecf20Sopenharmony_ci	ATA_CMD_SEC_SET_PASS	= 0xF1,
2748c2ecf20Sopenharmony_ci	ATA_CMD_SEC_UNLOCK	= 0xF2,
2758c2ecf20Sopenharmony_ci	ATA_CMD_SEC_ERASE_PREP	= 0xF3,
2768c2ecf20Sopenharmony_ci	ATA_CMD_SEC_ERASE_UNIT	= 0xF4,
2778c2ecf20Sopenharmony_ci	ATA_CMD_SEC_FREEZE_LOCK	= 0xF5,
2788c2ecf20Sopenharmony_ci	ATA_CMD_SEC_DISABLE_PASS = 0xF6,
2798c2ecf20Sopenharmony_ci	ATA_CMD_CONFIG_STREAM	= 0x51,
2808c2ecf20Sopenharmony_ci	ATA_CMD_SMART		= 0xB0,
2818c2ecf20Sopenharmony_ci	ATA_CMD_MEDIA_LOCK	= 0xDE,
2828c2ecf20Sopenharmony_ci	ATA_CMD_MEDIA_UNLOCK	= 0xDF,
2838c2ecf20Sopenharmony_ci	ATA_CMD_DSM		= 0x06,
2848c2ecf20Sopenharmony_ci	ATA_CMD_CHK_MED_CRD_TYP = 0xD1,
2858c2ecf20Sopenharmony_ci	ATA_CMD_CFA_REQ_EXT_ERR = 0x03,
2868c2ecf20Sopenharmony_ci	ATA_CMD_CFA_WRITE_NE	= 0x38,
2878c2ecf20Sopenharmony_ci	ATA_CMD_CFA_TRANS_SECT	= 0x87,
2888c2ecf20Sopenharmony_ci	ATA_CMD_CFA_ERASE	= 0xC0,
2898c2ecf20Sopenharmony_ci	ATA_CMD_CFA_WRITE_MULT_NE = 0xCD,
2908c2ecf20Sopenharmony_ci	ATA_CMD_REQ_SENSE_DATA  = 0x0B,
2918c2ecf20Sopenharmony_ci	ATA_CMD_SANITIZE_DEVICE = 0xB4,
2928c2ecf20Sopenharmony_ci	ATA_CMD_ZAC_MGMT_IN	= 0x4A,
2938c2ecf20Sopenharmony_ci	ATA_CMD_ZAC_MGMT_OUT	= 0x9F,
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci	/* marked obsolete in the ATA/ATAPI-7 spec */
2968c2ecf20Sopenharmony_ci	ATA_CMD_RESTORE		= 0x10,
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci	/* Subcmds for ATA_CMD_FPDMA_RECV */
2998c2ecf20Sopenharmony_ci	ATA_SUBCMD_FPDMA_RECV_RD_LOG_DMA_EXT = 0x01,
3008c2ecf20Sopenharmony_ci	ATA_SUBCMD_FPDMA_RECV_ZAC_MGMT_IN    = 0x02,
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci	/* Subcmds for ATA_CMD_FPDMA_SEND */
3038c2ecf20Sopenharmony_ci	ATA_SUBCMD_FPDMA_SEND_DSM            = 0x00,
3048c2ecf20Sopenharmony_ci	ATA_SUBCMD_FPDMA_SEND_WR_LOG_DMA_EXT = 0x02,
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci	/* Subcmds for ATA_CMD_NCQ_NON_DATA */
3078c2ecf20Sopenharmony_ci	ATA_SUBCMD_NCQ_NON_DATA_ABORT_QUEUE  = 0x00,
3088c2ecf20Sopenharmony_ci	ATA_SUBCMD_NCQ_NON_DATA_SET_FEATURES = 0x05,
3098c2ecf20Sopenharmony_ci	ATA_SUBCMD_NCQ_NON_DATA_ZERO_EXT     = 0x06,
3108c2ecf20Sopenharmony_ci	ATA_SUBCMD_NCQ_NON_DATA_ZAC_MGMT_OUT = 0x07,
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci	/* Subcmds for ATA_CMD_ZAC_MGMT_IN */
3138c2ecf20Sopenharmony_ci	ATA_SUBCMD_ZAC_MGMT_IN_REPORT_ZONES = 0x00,
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci	/* Subcmds for ATA_CMD_ZAC_MGMT_OUT */
3168c2ecf20Sopenharmony_ci	ATA_SUBCMD_ZAC_MGMT_OUT_CLOSE_ZONE = 0x01,
3178c2ecf20Sopenharmony_ci	ATA_SUBCMD_ZAC_MGMT_OUT_FINISH_ZONE = 0x02,
3188c2ecf20Sopenharmony_ci	ATA_SUBCMD_ZAC_MGMT_OUT_OPEN_ZONE = 0x03,
3198c2ecf20Sopenharmony_ci	ATA_SUBCMD_ZAC_MGMT_OUT_RESET_WRITE_POINTER = 0x04,
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci	/* READ_LOG_EXT pages */
3228c2ecf20Sopenharmony_ci	ATA_LOG_DIRECTORY	= 0x0,
3238c2ecf20Sopenharmony_ci	ATA_LOG_SATA_NCQ	= 0x10,
3248c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_NON_DATA	= 0x12,
3258c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_SEND_RECV	= 0x13,
3268c2ecf20Sopenharmony_ci	ATA_LOG_IDENTIFY_DEVICE	= 0x30,
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci	/* Identify device log pages: */
3298c2ecf20Sopenharmony_ci	ATA_LOG_SECURITY	  = 0x06,
3308c2ecf20Sopenharmony_ci	ATA_LOG_SATA_SETTINGS	  = 0x08,
3318c2ecf20Sopenharmony_ci	ATA_LOG_ZONED_INFORMATION = 0x09,
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci	/* Identify device SATA settings log:*/
3348c2ecf20Sopenharmony_ci	ATA_LOG_DEVSLP_OFFSET	  = 0x30,
3358c2ecf20Sopenharmony_ci	ATA_LOG_DEVSLP_SIZE	  = 0x08,
3368c2ecf20Sopenharmony_ci	ATA_LOG_DEVSLP_MDAT	  = 0x00,
3378c2ecf20Sopenharmony_ci	ATA_LOG_DEVSLP_MDAT_MASK  = 0x1F,
3388c2ecf20Sopenharmony_ci	ATA_LOG_DEVSLP_DETO	  = 0x01,
3398c2ecf20Sopenharmony_ci	ATA_LOG_DEVSLP_VALID	  = 0x07,
3408c2ecf20Sopenharmony_ci	ATA_LOG_DEVSLP_VALID_MASK = 0x80,
3418c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_PRIO_OFFSET   = 0x09,
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	/* NCQ send and receive log */
3448c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_SEND_RECV_SUBCMDS_OFFSET	= 0x00,
3458c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_SEND_RECV_SUBCMDS_DSM	= (1 << 0),
3468c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_SEND_RECV_DSM_OFFSET	= 0x04,
3478c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_SEND_RECV_DSM_TRIM		= (1 << 0),
3488c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_SEND_RECV_RD_LOG_OFFSET	= 0x08,
3498c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_SEND_RECV_RD_LOG_SUPPORTED  = (1 << 0),
3508c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_SEND_RECV_WR_LOG_OFFSET	= 0x0C,
3518c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_SEND_RECV_WR_LOG_SUPPORTED  = (1 << 0),
3528c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_OFFSET	= 0x10,
3538c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_OUT_SUPPORTED = (1 << 0),
3548c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_IN_SUPPORTED = (1 << 1),
3558c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_SEND_RECV_SIZE		= 0x14,
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci	/* NCQ Non-Data log */
3588c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_NON_DATA_SUBCMDS_OFFSET	= 0x00,
3598c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_NON_DATA_ABORT_OFFSET	= 0x00,
3608c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_NON_DATA_ABORT_NCQ		= (1 << 0),
3618c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_NON_DATA_ABORT_ALL		= (1 << 1),
3628c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_NON_DATA_ABORT_STREAMING	= (1 << 2),
3638c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_NON_DATA_ABORT_NON_STREAMING = (1 << 3),
3648c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_NON_DATA_ABORT_SELECTED	= (1 << 4),
3658c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_NON_DATA_ZAC_MGMT_OFFSET	= 0x1C,
3668c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_NON_DATA_ZAC_MGMT_OUT	= (1 << 0),
3678c2ecf20Sopenharmony_ci	ATA_LOG_NCQ_NON_DATA_SIZE		= 0x40,
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci	/* READ/WRITE LONG (obsolete) */
3708c2ecf20Sopenharmony_ci	ATA_CMD_READ_LONG	= 0x22,
3718c2ecf20Sopenharmony_ci	ATA_CMD_READ_LONG_ONCE	= 0x23,
3728c2ecf20Sopenharmony_ci	ATA_CMD_WRITE_LONG	= 0x32,
3738c2ecf20Sopenharmony_ci	ATA_CMD_WRITE_LONG_ONCE	= 0x33,
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	/* SETFEATURES stuff */
3768c2ecf20Sopenharmony_ci	SETFEATURES_XFER	= 0x03,
3778c2ecf20Sopenharmony_ci	XFER_UDMA_7		= 0x47,
3788c2ecf20Sopenharmony_ci	XFER_UDMA_6		= 0x46,
3798c2ecf20Sopenharmony_ci	XFER_UDMA_5		= 0x45,
3808c2ecf20Sopenharmony_ci	XFER_UDMA_4		= 0x44,
3818c2ecf20Sopenharmony_ci	XFER_UDMA_3		= 0x43,
3828c2ecf20Sopenharmony_ci	XFER_UDMA_2		= 0x42,
3838c2ecf20Sopenharmony_ci	XFER_UDMA_1		= 0x41,
3848c2ecf20Sopenharmony_ci	XFER_UDMA_0		= 0x40,
3858c2ecf20Sopenharmony_ci	XFER_MW_DMA_4		= 0x24,	/* CFA only */
3868c2ecf20Sopenharmony_ci	XFER_MW_DMA_3		= 0x23,	/* CFA only */
3878c2ecf20Sopenharmony_ci	XFER_MW_DMA_2		= 0x22,
3888c2ecf20Sopenharmony_ci	XFER_MW_DMA_1		= 0x21,
3898c2ecf20Sopenharmony_ci	XFER_MW_DMA_0		= 0x20,
3908c2ecf20Sopenharmony_ci	XFER_SW_DMA_2		= 0x12,
3918c2ecf20Sopenharmony_ci	XFER_SW_DMA_1		= 0x11,
3928c2ecf20Sopenharmony_ci	XFER_SW_DMA_0		= 0x10,
3938c2ecf20Sopenharmony_ci	XFER_PIO_6		= 0x0E,	/* CFA only */
3948c2ecf20Sopenharmony_ci	XFER_PIO_5		= 0x0D,	/* CFA only */
3958c2ecf20Sopenharmony_ci	XFER_PIO_4		= 0x0C,
3968c2ecf20Sopenharmony_ci	XFER_PIO_3		= 0x0B,
3978c2ecf20Sopenharmony_ci	XFER_PIO_2		= 0x0A,
3988c2ecf20Sopenharmony_ci	XFER_PIO_1		= 0x09,
3998c2ecf20Sopenharmony_ci	XFER_PIO_0		= 0x08,
4008c2ecf20Sopenharmony_ci	XFER_PIO_SLOW		= 0x00,
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ci	SETFEATURES_WC_ON	= 0x02, /* Enable write cache */
4038c2ecf20Sopenharmony_ci	SETFEATURES_WC_OFF	= 0x82, /* Disable write cache */
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	SETFEATURES_RA_ON	= 0xaa, /* Enable read look-ahead */
4068c2ecf20Sopenharmony_ci	SETFEATURES_RA_OFF	= 0x55, /* Disable read look-ahead */
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci	/* Enable/Disable Automatic Acoustic Management */
4098c2ecf20Sopenharmony_ci	SETFEATURES_AAM_ON	= 0x42,
4108c2ecf20Sopenharmony_ci	SETFEATURES_AAM_OFF	= 0xC2,
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci	SETFEATURES_SPINUP		= 0x07, /* Spin-up drive */
4138c2ecf20Sopenharmony_ci	SETFEATURES_SPINUP_TIMEOUT	= 30000, /* 30s timeout for drive spin-up from PUIS */
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci	SETFEATURES_SATA_ENABLE = 0x10, /* Enable use of SATA feature */
4168c2ecf20Sopenharmony_ci	SETFEATURES_SATA_DISABLE = 0x90, /* Disable use of SATA feature */
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci	/* SETFEATURE Sector counts for SATA features */
4198c2ecf20Sopenharmony_ci	SATA_FPDMA_OFFSET	= 0x01,	/* FPDMA non-zero buffer offsets */
4208c2ecf20Sopenharmony_ci	SATA_FPDMA_AA		= 0x02, /* FPDMA Setup FIS Auto-Activate */
4218c2ecf20Sopenharmony_ci	SATA_DIPM		= 0x03,	/* Device Initiated Power Management */
4228c2ecf20Sopenharmony_ci	SATA_FPDMA_IN_ORDER	= 0x04,	/* FPDMA in-order data delivery */
4238c2ecf20Sopenharmony_ci	SATA_AN			= 0x05,	/* Asynchronous Notification */
4248c2ecf20Sopenharmony_ci	SATA_SSP		= 0x06,	/* Software Settings Preservation */
4258c2ecf20Sopenharmony_ci	SATA_DEVSLP		= 0x09,	/* Device Sleep */
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_ci	SETFEATURE_SENSE_DATA	= 0xC3, /* Sense Data Reporting feature */
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ci	/* feature values for SET_MAX */
4308c2ecf20Sopenharmony_ci	ATA_SET_MAX_ADDR	= 0x00,
4318c2ecf20Sopenharmony_ci	ATA_SET_MAX_PASSWD	= 0x01,
4328c2ecf20Sopenharmony_ci	ATA_SET_MAX_LOCK	= 0x02,
4338c2ecf20Sopenharmony_ci	ATA_SET_MAX_UNLOCK	= 0x03,
4348c2ecf20Sopenharmony_ci	ATA_SET_MAX_FREEZE_LOCK	= 0x04,
4358c2ecf20Sopenharmony_ci	ATA_SET_MAX_PASSWD_DMA	= 0x05,
4368c2ecf20Sopenharmony_ci	ATA_SET_MAX_UNLOCK_DMA	= 0x06,
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci	/* feature values for DEVICE CONFIGURATION OVERLAY */
4398c2ecf20Sopenharmony_ci	ATA_DCO_RESTORE		= 0xC0,
4408c2ecf20Sopenharmony_ci	ATA_DCO_FREEZE_LOCK	= 0xC1,
4418c2ecf20Sopenharmony_ci	ATA_DCO_IDENTIFY	= 0xC2,
4428c2ecf20Sopenharmony_ci	ATA_DCO_SET		= 0xC3,
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci	/* feature values for SMART */
4458c2ecf20Sopenharmony_ci	ATA_SMART_ENABLE	= 0xD8,
4468c2ecf20Sopenharmony_ci	ATA_SMART_READ_VALUES	= 0xD0,
4478c2ecf20Sopenharmony_ci	ATA_SMART_READ_THRESHOLDS = 0xD1,
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci	/* feature values for Data Set Management */
4508c2ecf20Sopenharmony_ci	ATA_DSM_TRIM		= 0x01,
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ci	/* password used in LBA Mid / LBA High for executing SMART commands */
4538c2ecf20Sopenharmony_ci	ATA_SMART_LBAM_PASS	= 0x4F,
4548c2ecf20Sopenharmony_ci	ATA_SMART_LBAH_PASS	= 0xC2,
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci	/* ATAPI stuff */
4578c2ecf20Sopenharmony_ci	ATAPI_PKT_DMA		= (1 << 0),
4588c2ecf20Sopenharmony_ci	ATAPI_DMADIR		= (1 << 2),	/* ATAPI data dir:
4598c2ecf20Sopenharmony_ci						   0=to device, 1=to host */
4608c2ecf20Sopenharmony_ci	ATAPI_CDB_LEN		= 16,
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci	/* PMP stuff */
4638c2ecf20Sopenharmony_ci	SATA_PMP_MAX_PORTS	= 15,
4648c2ecf20Sopenharmony_ci	SATA_PMP_CTRL_PORT	= 15,
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_ci	SATA_PMP_GSCR_DWORDS	= 128,
4678c2ecf20Sopenharmony_ci	SATA_PMP_GSCR_PROD_ID	= 0,
4688c2ecf20Sopenharmony_ci	SATA_PMP_GSCR_REV	= 1,
4698c2ecf20Sopenharmony_ci	SATA_PMP_GSCR_PORT_INFO	= 2,
4708c2ecf20Sopenharmony_ci	SATA_PMP_GSCR_ERROR	= 32,
4718c2ecf20Sopenharmony_ci	SATA_PMP_GSCR_ERROR_EN	= 33,
4728c2ecf20Sopenharmony_ci	SATA_PMP_GSCR_FEAT	= 64,
4738c2ecf20Sopenharmony_ci	SATA_PMP_GSCR_FEAT_EN	= 96,
4748c2ecf20Sopenharmony_ci
4758c2ecf20Sopenharmony_ci	SATA_PMP_PSCR_STATUS	= 0,
4768c2ecf20Sopenharmony_ci	SATA_PMP_PSCR_ERROR	= 1,
4778c2ecf20Sopenharmony_ci	SATA_PMP_PSCR_CONTROL	= 2,
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_ci	SATA_PMP_FEAT_BIST	= (1 << 0),
4808c2ecf20Sopenharmony_ci	SATA_PMP_FEAT_PMREQ	= (1 << 1),
4818c2ecf20Sopenharmony_ci	SATA_PMP_FEAT_DYNSSC	= (1 << 2),
4828c2ecf20Sopenharmony_ci	SATA_PMP_FEAT_NOTIFY	= (1 << 3),
4838c2ecf20Sopenharmony_ci
4848c2ecf20Sopenharmony_ci	/* cable types */
4858c2ecf20Sopenharmony_ci	ATA_CBL_NONE		= 0,
4868c2ecf20Sopenharmony_ci	ATA_CBL_PATA40		= 1,
4878c2ecf20Sopenharmony_ci	ATA_CBL_PATA80		= 2,
4888c2ecf20Sopenharmony_ci	ATA_CBL_PATA40_SHORT	= 3,	/* 40 wire cable to high UDMA spec */
4898c2ecf20Sopenharmony_ci	ATA_CBL_PATA_UNK	= 4,	/* don't know, maybe 80c? */
4908c2ecf20Sopenharmony_ci	ATA_CBL_PATA_IGN	= 5,	/* don't know, ignore cable handling */
4918c2ecf20Sopenharmony_ci	ATA_CBL_SATA		= 6,
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci	/* SATA Status and Control Registers */
4948c2ecf20Sopenharmony_ci	SCR_STATUS		= 0,
4958c2ecf20Sopenharmony_ci	SCR_ERROR		= 1,
4968c2ecf20Sopenharmony_ci	SCR_CONTROL		= 2,
4978c2ecf20Sopenharmony_ci	SCR_ACTIVE		= 3,
4988c2ecf20Sopenharmony_ci	SCR_NOTIFICATION	= 4,
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ci	/* SError bits */
5018c2ecf20Sopenharmony_ci	SERR_DATA_RECOVERED	= (1 << 0), /* recovered data error */
5028c2ecf20Sopenharmony_ci	SERR_COMM_RECOVERED	= (1 << 1), /* recovered comm failure */
5038c2ecf20Sopenharmony_ci	SERR_DATA		= (1 << 8), /* unrecovered data error */
5048c2ecf20Sopenharmony_ci	SERR_PERSISTENT		= (1 << 9), /* persistent data/comm error */
5058c2ecf20Sopenharmony_ci	SERR_PROTOCOL		= (1 << 10), /* protocol violation */
5068c2ecf20Sopenharmony_ci	SERR_INTERNAL		= (1 << 11), /* host internal error */
5078c2ecf20Sopenharmony_ci	SERR_PHYRDY_CHG		= (1 << 16), /* PHY RDY changed */
5088c2ecf20Sopenharmony_ci	SERR_PHY_INT_ERR	= (1 << 17), /* PHY internal error */
5098c2ecf20Sopenharmony_ci	SERR_COMM_WAKE		= (1 << 18), /* Comm wake */
5108c2ecf20Sopenharmony_ci	SERR_10B_8B_ERR		= (1 << 19), /* 10b to 8b decode error */
5118c2ecf20Sopenharmony_ci	SERR_DISPARITY		= (1 << 20), /* Disparity */
5128c2ecf20Sopenharmony_ci	SERR_CRC		= (1 << 21), /* CRC error */
5138c2ecf20Sopenharmony_ci	SERR_HANDSHAKE		= (1 << 22), /* Handshake error */
5148c2ecf20Sopenharmony_ci	SERR_LINK_SEQ_ERR	= (1 << 23), /* Link sequence error */
5158c2ecf20Sopenharmony_ci	SERR_TRANS_ST_ERROR	= (1 << 24), /* Transport state trans. error */
5168c2ecf20Sopenharmony_ci	SERR_UNRECOG_FIS	= (1 << 25), /* Unrecognized FIS */
5178c2ecf20Sopenharmony_ci	SERR_DEV_XCHG		= (1 << 26), /* device exchanged */
5188c2ecf20Sopenharmony_ci};
5198c2ecf20Sopenharmony_ci
5208c2ecf20Sopenharmony_cienum ata_prot_flags {
5218c2ecf20Sopenharmony_ci	/* protocol flags */
5228c2ecf20Sopenharmony_ci	ATA_PROT_FLAG_PIO	= (1 << 0), /* is PIO */
5238c2ecf20Sopenharmony_ci	ATA_PROT_FLAG_DMA	= (1 << 1), /* is DMA */
5248c2ecf20Sopenharmony_ci	ATA_PROT_FLAG_NCQ	= (1 << 2), /* is NCQ */
5258c2ecf20Sopenharmony_ci	ATA_PROT_FLAG_ATAPI	= (1 << 3), /* is ATAPI */
5268c2ecf20Sopenharmony_ci
5278c2ecf20Sopenharmony_ci	/* taskfile protocols */
5288c2ecf20Sopenharmony_ci	ATA_PROT_UNKNOWN	= (u8)-1,
5298c2ecf20Sopenharmony_ci	ATA_PROT_NODATA		= 0,
5308c2ecf20Sopenharmony_ci	ATA_PROT_PIO		= ATA_PROT_FLAG_PIO,
5318c2ecf20Sopenharmony_ci	ATA_PROT_DMA		= ATA_PROT_FLAG_DMA,
5328c2ecf20Sopenharmony_ci	ATA_PROT_NCQ_NODATA	= ATA_PROT_FLAG_NCQ,
5338c2ecf20Sopenharmony_ci	ATA_PROT_NCQ		= ATA_PROT_FLAG_DMA | ATA_PROT_FLAG_NCQ,
5348c2ecf20Sopenharmony_ci	ATAPI_PROT_NODATA	= ATA_PROT_FLAG_ATAPI,
5358c2ecf20Sopenharmony_ci	ATAPI_PROT_PIO		= ATA_PROT_FLAG_ATAPI | ATA_PROT_FLAG_PIO,
5368c2ecf20Sopenharmony_ci	ATAPI_PROT_DMA		= ATA_PROT_FLAG_ATAPI | ATA_PROT_FLAG_DMA,
5378c2ecf20Sopenharmony_ci};
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_cienum ata_ioctls {
5408c2ecf20Sopenharmony_ci	ATA_IOC_GET_IO32	= 0x309, /* HDIO_GET_32BIT */
5418c2ecf20Sopenharmony_ci	ATA_IOC_SET_IO32	= 0x324, /* HDIO_SET_32BIT */
5428c2ecf20Sopenharmony_ci};
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_ci/* core structures */
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_cistruct ata_bmdma_prd {
5478c2ecf20Sopenharmony_ci	__le32			addr;
5488c2ecf20Sopenharmony_ci	__le32			flags_len;
5498c2ecf20Sopenharmony_ci};
5508c2ecf20Sopenharmony_ci
5518c2ecf20Sopenharmony_ci/*
5528c2ecf20Sopenharmony_ci * id tests
5538c2ecf20Sopenharmony_ci */
5548c2ecf20Sopenharmony_ci#define ata_id_is_ata(id)	(((id)[ATA_ID_CONFIG] & (1 << 15)) == 0)
5558c2ecf20Sopenharmony_ci#define ata_id_has_lba(id)	((id)[ATA_ID_CAPABILITY] & (1 << 9))
5568c2ecf20Sopenharmony_ci#define ata_id_has_dma(id)	((id)[ATA_ID_CAPABILITY] & (1 << 8))
5578c2ecf20Sopenharmony_ci#define ata_id_has_ncq(id)	((id)[ATA_ID_SATA_CAPABILITY] & (1 << 8))
5588c2ecf20Sopenharmony_ci#define ata_id_queue_depth(id)	(((id)[ATA_ID_QUEUE_DEPTH] & 0x1f) + 1)
5598c2ecf20Sopenharmony_ci#define ata_id_removable(id)	((id)[ATA_ID_CONFIG] & (1 << 7))
5608c2ecf20Sopenharmony_ci#define ata_id_has_atapi_AN(id)	\
5618c2ecf20Sopenharmony_ci	((((id)[ATA_ID_SATA_CAPABILITY] != 0x0000) && \
5628c2ecf20Sopenharmony_ci	  ((id)[ATA_ID_SATA_CAPABILITY] != 0xffff)) && \
5638c2ecf20Sopenharmony_ci	 ((id)[ATA_ID_FEATURE_SUPP] & (1 << 5)))
5648c2ecf20Sopenharmony_ci#define ata_id_has_fpdma_aa(id)	\
5658c2ecf20Sopenharmony_ci	((((id)[ATA_ID_SATA_CAPABILITY] != 0x0000) && \
5668c2ecf20Sopenharmony_ci	  ((id)[ATA_ID_SATA_CAPABILITY] != 0xffff)) && \
5678c2ecf20Sopenharmony_ci	 ((id)[ATA_ID_FEATURE_SUPP] & (1 << 2)))
5688c2ecf20Sopenharmony_ci#define ata_id_has_devslp(id)	\
5698c2ecf20Sopenharmony_ci	((((id)[ATA_ID_SATA_CAPABILITY] != 0x0000) && \
5708c2ecf20Sopenharmony_ci	  ((id)[ATA_ID_SATA_CAPABILITY] != 0xffff)) && \
5718c2ecf20Sopenharmony_ci	 ((id)[ATA_ID_FEATURE_SUPP] & (1 << 8)))
5728c2ecf20Sopenharmony_ci#define ata_id_has_ncq_autosense(id) \
5738c2ecf20Sopenharmony_ci	((((id)[ATA_ID_SATA_CAPABILITY] != 0x0000) && \
5748c2ecf20Sopenharmony_ci	  ((id)[ATA_ID_SATA_CAPABILITY] != 0xffff)) && \
5758c2ecf20Sopenharmony_ci	 ((id)[ATA_ID_FEATURE_SUPP] & (1 << 7)))
5768c2ecf20Sopenharmony_ci#define ata_id_has_dipm(id)	\
5778c2ecf20Sopenharmony_ci	((((id)[ATA_ID_SATA_CAPABILITY] != 0x0000) && \
5788c2ecf20Sopenharmony_ci	  ((id)[ATA_ID_SATA_CAPABILITY] != 0xffff)) && \
5798c2ecf20Sopenharmony_ci	 ((id)[ATA_ID_FEATURE_SUPP] & (1 << 3)))
5808c2ecf20Sopenharmony_ci#define ata_id_iordy_disable(id) ((id)[ATA_ID_CAPABILITY] & (1 << 10))
5818c2ecf20Sopenharmony_ci#define ata_id_has_iordy(id) ((id)[ATA_ID_CAPABILITY] & (1 << 11))
5828c2ecf20Sopenharmony_ci#define ata_id_u32(id,n)	\
5838c2ecf20Sopenharmony_ci	(((u32) (id)[(n) + 1] << 16) | ((u32) (id)[(n)]))
5848c2ecf20Sopenharmony_ci#define ata_id_u64(id,n)	\
5858c2ecf20Sopenharmony_ci	( ((u64) (id)[(n) + 3] << 48) |	\
5868c2ecf20Sopenharmony_ci	  ((u64) (id)[(n) + 2] << 32) |	\
5878c2ecf20Sopenharmony_ci	  ((u64) (id)[(n) + 1] << 16) |	\
5888c2ecf20Sopenharmony_ci	  ((u64) (id)[(n) + 0]) )
5898c2ecf20Sopenharmony_ci
5908c2ecf20Sopenharmony_ci#define ata_id_cdb_intr(id)	(((id)[ATA_ID_CONFIG] & 0x60) == 0x20)
5918c2ecf20Sopenharmony_ci#define ata_id_has_da(id)	((id)[ATA_ID_SATA_CAPABILITY_2] & (1 << 4))
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_cistatic inline bool ata_id_has_hipm(const u16 *id)
5948c2ecf20Sopenharmony_ci{
5958c2ecf20Sopenharmony_ci	u16 val = id[ATA_ID_SATA_CAPABILITY];
5968c2ecf20Sopenharmony_ci
5978c2ecf20Sopenharmony_ci	if (val == 0 || val == 0xffff)
5988c2ecf20Sopenharmony_ci		return false;
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ci	return val & (1 << 9);
6018c2ecf20Sopenharmony_ci}
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_cistatic inline bool ata_id_has_fua(const u16 *id)
6048c2ecf20Sopenharmony_ci{
6058c2ecf20Sopenharmony_ci	if ((id[ATA_ID_CFSSE] & 0xC000) != 0x4000)
6068c2ecf20Sopenharmony_ci		return false;
6078c2ecf20Sopenharmony_ci	return id[ATA_ID_CFSSE] & (1 << 6);
6088c2ecf20Sopenharmony_ci}
6098c2ecf20Sopenharmony_ci
6108c2ecf20Sopenharmony_cistatic inline bool ata_id_has_flush(const u16 *id)
6118c2ecf20Sopenharmony_ci{
6128c2ecf20Sopenharmony_ci	if ((id[ATA_ID_COMMAND_SET_2] & 0xC000) != 0x4000)
6138c2ecf20Sopenharmony_ci		return false;
6148c2ecf20Sopenharmony_ci	return id[ATA_ID_COMMAND_SET_2] & (1 << 12);
6158c2ecf20Sopenharmony_ci}
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_cistatic inline bool ata_id_flush_enabled(const u16 *id)
6188c2ecf20Sopenharmony_ci{
6198c2ecf20Sopenharmony_ci	if (ata_id_has_flush(id) == 0)
6208c2ecf20Sopenharmony_ci		return false;
6218c2ecf20Sopenharmony_ci	if ((id[ATA_ID_CSF_DEFAULT] & 0xC000) != 0x4000)
6228c2ecf20Sopenharmony_ci		return false;
6238c2ecf20Sopenharmony_ci	return id[ATA_ID_CFS_ENABLE_2] & (1 << 12);
6248c2ecf20Sopenharmony_ci}
6258c2ecf20Sopenharmony_ci
6268c2ecf20Sopenharmony_cistatic inline bool ata_id_has_flush_ext(const u16 *id)
6278c2ecf20Sopenharmony_ci{
6288c2ecf20Sopenharmony_ci	if ((id[ATA_ID_COMMAND_SET_2] & 0xC000) != 0x4000)
6298c2ecf20Sopenharmony_ci		return false;
6308c2ecf20Sopenharmony_ci	return id[ATA_ID_COMMAND_SET_2] & (1 << 13);
6318c2ecf20Sopenharmony_ci}
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_cistatic inline bool ata_id_flush_ext_enabled(const u16 *id)
6348c2ecf20Sopenharmony_ci{
6358c2ecf20Sopenharmony_ci	if (ata_id_has_flush_ext(id) == 0)
6368c2ecf20Sopenharmony_ci		return false;
6378c2ecf20Sopenharmony_ci	if ((id[ATA_ID_CSF_DEFAULT] & 0xC000) != 0x4000)
6388c2ecf20Sopenharmony_ci		return false;
6398c2ecf20Sopenharmony_ci	/*
6408c2ecf20Sopenharmony_ci	 * some Maxtor disks have bit 13 defined incorrectly
6418c2ecf20Sopenharmony_ci	 * so check bit 10 too
6428c2ecf20Sopenharmony_ci	 */
6438c2ecf20Sopenharmony_ci	return (id[ATA_ID_CFS_ENABLE_2] & 0x2400) == 0x2400;
6448c2ecf20Sopenharmony_ci}
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_cistatic inline u32 ata_id_logical_sector_size(const u16 *id)
6478c2ecf20Sopenharmony_ci{
6488c2ecf20Sopenharmony_ci	/* T13/1699-D Revision 6a, Sep 6, 2008. Page 128.
6498c2ecf20Sopenharmony_ci	 * IDENTIFY DEVICE data, word 117-118.
6508c2ecf20Sopenharmony_ci	 * 0xd000 ignores bit 13 (logical:physical > 1)
6518c2ecf20Sopenharmony_ci	 */
6528c2ecf20Sopenharmony_ci	if ((id[ATA_ID_SECTOR_SIZE] & 0xd000) == 0x5000)
6538c2ecf20Sopenharmony_ci		return (((id[ATA_ID_LOGICAL_SECTOR_SIZE+1] << 16)
6548c2ecf20Sopenharmony_ci			 + id[ATA_ID_LOGICAL_SECTOR_SIZE]) * sizeof(u16)) ;
6558c2ecf20Sopenharmony_ci	return ATA_SECT_SIZE;
6568c2ecf20Sopenharmony_ci}
6578c2ecf20Sopenharmony_ci
6588c2ecf20Sopenharmony_cistatic inline u8 ata_id_log2_per_physical_sector(const u16 *id)
6598c2ecf20Sopenharmony_ci{
6608c2ecf20Sopenharmony_ci	/* T13/1699-D Revision 6a, Sep 6, 2008. Page 128.
6618c2ecf20Sopenharmony_ci	 * IDENTIFY DEVICE data, word 106.
6628c2ecf20Sopenharmony_ci	 * 0xe000 ignores bit 12 (logical sector > 512 bytes)
6638c2ecf20Sopenharmony_ci	 */
6648c2ecf20Sopenharmony_ci	if ((id[ATA_ID_SECTOR_SIZE] & 0xe000) == 0x6000)
6658c2ecf20Sopenharmony_ci		return (id[ATA_ID_SECTOR_SIZE] & 0xf);
6668c2ecf20Sopenharmony_ci	return 0;
6678c2ecf20Sopenharmony_ci}
6688c2ecf20Sopenharmony_ci
6698c2ecf20Sopenharmony_ci/* Offset of logical sectors relative to physical sectors.
6708c2ecf20Sopenharmony_ci *
6718c2ecf20Sopenharmony_ci * If device has more than one logical sector per physical sector
6728c2ecf20Sopenharmony_ci * (aka 512 byte emulation), vendors might offset the "sector 0" address
6738c2ecf20Sopenharmony_ci * so sector 63 is "naturally aligned" - e.g. FAT partition table.
6748c2ecf20Sopenharmony_ci * This avoids Read/Mod/Write penalties when using FAT partition table
6758c2ecf20Sopenharmony_ci * and updating "well aligned" (FS perspective) physical sectors on every
6768c2ecf20Sopenharmony_ci * transaction.
6778c2ecf20Sopenharmony_ci */
6788c2ecf20Sopenharmony_cistatic inline u16 ata_id_logical_sector_offset(const u16 *id,
6798c2ecf20Sopenharmony_ci	 u8 log2_per_phys)
6808c2ecf20Sopenharmony_ci{
6818c2ecf20Sopenharmony_ci	u16 word_209 = id[209];
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_ci	if ((log2_per_phys > 1) && (word_209 & 0xc000) == 0x4000) {
6848c2ecf20Sopenharmony_ci		u16 first = word_209 & 0x3fff;
6858c2ecf20Sopenharmony_ci		if (first > 0)
6868c2ecf20Sopenharmony_ci			return (1 << log2_per_phys) - first;
6878c2ecf20Sopenharmony_ci	}
6888c2ecf20Sopenharmony_ci	return 0;
6898c2ecf20Sopenharmony_ci}
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_cistatic inline bool ata_id_has_lba48(const u16 *id)
6928c2ecf20Sopenharmony_ci{
6938c2ecf20Sopenharmony_ci	if ((id[ATA_ID_COMMAND_SET_2] & 0xC000) != 0x4000)
6948c2ecf20Sopenharmony_ci		return false;
6958c2ecf20Sopenharmony_ci	if (!ata_id_u64(id, ATA_ID_LBA_CAPACITY_2))
6968c2ecf20Sopenharmony_ci		return false;
6978c2ecf20Sopenharmony_ci	return id[ATA_ID_COMMAND_SET_2] & (1 << 10);
6988c2ecf20Sopenharmony_ci}
6998c2ecf20Sopenharmony_ci
7008c2ecf20Sopenharmony_cistatic inline bool ata_id_lba48_enabled(const u16 *id)
7018c2ecf20Sopenharmony_ci{
7028c2ecf20Sopenharmony_ci	if (ata_id_has_lba48(id) == 0)
7038c2ecf20Sopenharmony_ci		return false;
7048c2ecf20Sopenharmony_ci	if ((id[ATA_ID_CSF_DEFAULT] & 0xC000) != 0x4000)
7058c2ecf20Sopenharmony_ci		return false;
7068c2ecf20Sopenharmony_ci	return id[ATA_ID_CFS_ENABLE_2] & (1 << 10);
7078c2ecf20Sopenharmony_ci}
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_cistatic inline bool ata_id_hpa_enabled(const u16 *id)
7108c2ecf20Sopenharmony_ci{
7118c2ecf20Sopenharmony_ci	/* Yes children, word 83 valid bits cover word 82 data */
7128c2ecf20Sopenharmony_ci	if ((id[ATA_ID_COMMAND_SET_2] & 0xC000) != 0x4000)
7138c2ecf20Sopenharmony_ci		return false;
7148c2ecf20Sopenharmony_ci	/* And 87 covers 85-87 */
7158c2ecf20Sopenharmony_ci	if ((id[ATA_ID_CSF_DEFAULT] & 0xC000) != 0x4000)
7168c2ecf20Sopenharmony_ci		return false;
7178c2ecf20Sopenharmony_ci	/* Check command sets enabled as well as supported */
7188c2ecf20Sopenharmony_ci	if ((id[ATA_ID_CFS_ENABLE_1] & (1 << 10)) == 0)
7198c2ecf20Sopenharmony_ci		return false;
7208c2ecf20Sopenharmony_ci	return id[ATA_ID_COMMAND_SET_1] & (1 << 10);
7218c2ecf20Sopenharmony_ci}
7228c2ecf20Sopenharmony_ci
7238c2ecf20Sopenharmony_cistatic inline bool ata_id_has_wcache(const u16 *id)
7248c2ecf20Sopenharmony_ci{
7258c2ecf20Sopenharmony_ci	/* Yes children, word 83 valid bits cover word 82 data */
7268c2ecf20Sopenharmony_ci	if ((id[ATA_ID_COMMAND_SET_2] & 0xC000) != 0x4000)
7278c2ecf20Sopenharmony_ci		return false;
7288c2ecf20Sopenharmony_ci	return id[ATA_ID_COMMAND_SET_1] & (1 << 5);
7298c2ecf20Sopenharmony_ci}
7308c2ecf20Sopenharmony_ci
7318c2ecf20Sopenharmony_cistatic inline bool ata_id_has_pm(const u16 *id)
7328c2ecf20Sopenharmony_ci{
7338c2ecf20Sopenharmony_ci	if ((id[ATA_ID_COMMAND_SET_2] & 0xC000) != 0x4000)
7348c2ecf20Sopenharmony_ci		return false;
7358c2ecf20Sopenharmony_ci	return id[ATA_ID_COMMAND_SET_1] & (1 << 3);
7368c2ecf20Sopenharmony_ci}
7378c2ecf20Sopenharmony_ci
7388c2ecf20Sopenharmony_cistatic inline bool ata_id_rahead_enabled(const u16 *id)
7398c2ecf20Sopenharmony_ci{
7408c2ecf20Sopenharmony_ci	if ((id[ATA_ID_CSF_DEFAULT] & 0xC000) != 0x4000)
7418c2ecf20Sopenharmony_ci		return false;
7428c2ecf20Sopenharmony_ci	return id[ATA_ID_CFS_ENABLE_1] & (1 << 6);
7438c2ecf20Sopenharmony_ci}
7448c2ecf20Sopenharmony_ci
7458c2ecf20Sopenharmony_cistatic inline bool ata_id_wcache_enabled(const u16 *id)
7468c2ecf20Sopenharmony_ci{
7478c2ecf20Sopenharmony_ci	if ((id[ATA_ID_CSF_DEFAULT] & 0xC000) != 0x4000)
7488c2ecf20Sopenharmony_ci		return false;
7498c2ecf20Sopenharmony_ci	return id[ATA_ID_CFS_ENABLE_1] & (1 << 5);
7508c2ecf20Sopenharmony_ci}
7518c2ecf20Sopenharmony_ci
7528c2ecf20Sopenharmony_cistatic inline bool ata_id_has_read_log_dma_ext(const u16 *id)
7538c2ecf20Sopenharmony_ci{
7548c2ecf20Sopenharmony_ci	/* Word 86 must have bit 15 set */
7558c2ecf20Sopenharmony_ci	if (!(id[ATA_ID_CFS_ENABLE_2] & (1 << 15)))
7568c2ecf20Sopenharmony_ci		return false;
7578c2ecf20Sopenharmony_ci
7588c2ecf20Sopenharmony_ci	/* READ LOG DMA EXT support can be signaled either from word 119
7598c2ecf20Sopenharmony_ci	 * or from word 120. The format is the same for both words: Bit
7608c2ecf20Sopenharmony_ci	 * 15 must be cleared, bit 14 set and bit 3 set.
7618c2ecf20Sopenharmony_ci	 */
7628c2ecf20Sopenharmony_ci	if ((id[ATA_ID_COMMAND_SET_3] & 0xC008) == 0x4008 ||
7638c2ecf20Sopenharmony_ci	    (id[ATA_ID_COMMAND_SET_4] & 0xC008) == 0x4008)
7648c2ecf20Sopenharmony_ci		return true;
7658c2ecf20Sopenharmony_ci
7668c2ecf20Sopenharmony_ci	return false;
7678c2ecf20Sopenharmony_ci}
7688c2ecf20Sopenharmony_ci
7698c2ecf20Sopenharmony_cistatic inline bool ata_id_has_sense_reporting(const u16 *id)
7708c2ecf20Sopenharmony_ci{
7718c2ecf20Sopenharmony_ci	if (!(id[ATA_ID_CFS_ENABLE_2] & BIT(15)))
7728c2ecf20Sopenharmony_ci		return false;
7738c2ecf20Sopenharmony_ci	if ((id[ATA_ID_COMMAND_SET_3] & (BIT(15) | BIT(14))) != BIT(14))
7748c2ecf20Sopenharmony_ci		return false;
7758c2ecf20Sopenharmony_ci	return id[ATA_ID_COMMAND_SET_3] & BIT(6);
7768c2ecf20Sopenharmony_ci}
7778c2ecf20Sopenharmony_ci
7788c2ecf20Sopenharmony_cistatic inline bool ata_id_sense_reporting_enabled(const u16 *id)
7798c2ecf20Sopenharmony_ci{
7808c2ecf20Sopenharmony_ci	if (!ata_id_has_sense_reporting(id))
7818c2ecf20Sopenharmony_ci		return false;
7828c2ecf20Sopenharmony_ci	/* ata_id_has_sense_reporting() == true, word 86 must have bit 15 set */
7838c2ecf20Sopenharmony_ci	if ((id[ATA_ID_COMMAND_SET_4] & (BIT(15) | BIT(14))) != BIT(14))
7848c2ecf20Sopenharmony_ci		return false;
7858c2ecf20Sopenharmony_ci	return id[ATA_ID_COMMAND_SET_4] & BIT(6);
7868c2ecf20Sopenharmony_ci}
7878c2ecf20Sopenharmony_ci
7888c2ecf20Sopenharmony_ci/**
7898c2ecf20Sopenharmony_ci *
7908c2ecf20Sopenharmony_ci * Word: 206 - SCT Command Transport
7918c2ecf20Sopenharmony_ci *    15:12 - Vendor Specific
7928c2ecf20Sopenharmony_ci *     11:6 - Reserved
7938c2ecf20Sopenharmony_ci *        5 - SCT Command Transport Data Tables supported
7948c2ecf20Sopenharmony_ci *        4 - SCT Command Transport Features Control supported
7958c2ecf20Sopenharmony_ci *        3 - SCT Command Transport Error Recovery Control supported
7968c2ecf20Sopenharmony_ci *        2 - SCT Command Transport Write Same supported
7978c2ecf20Sopenharmony_ci *        1 - SCT Command Transport Long Sector Access supported
7988c2ecf20Sopenharmony_ci *        0 - SCT Command Transport supported
7998c2ecf20Sopenharmony_ci */
8008c2ecf20Sopenharmony_cistatic inline bool ata_id_sct_data_tables(const u16 *id)
8018c2ecf20Sopenharmony_ci{
8028c2ecf20Sopenharmony_ci	return id[ATA_ID_SCT_CMD_XPORT] & (1 << 5) ? true : false;
8038c2ecf20Sopenharmony_ci}
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_cistatic inline bool ata_id_sct_features_ctrl(const u16 *id)
8068c2ecf20Sopenharmony_ci{
8078c2ecf20Sopenharmony_ci	return id[ATA_ID_SCT_CMD_XPORT] & (1 << 4) ? true : false;
8088c2ecf20Sopenharmony_ci}
8098c2ecf20Sopenharmony_ci
8108c2ecf20Sopenharmony_cistatic inline bool ata_id_sct_error_recovery_ctrl(const u16 *id)
8118c2ecf20Sopenharmony_ci{
8128c2ecf20Sopenharmony_ci	return id[ATA_ID_SCT_CMD_XPORT] & (1 << 3) ? true : false;
8138c2ecf20Sopenharmony_ci}
8148c2ecf20Sopenharmony_ci
8158c2ecf20Sopenharmony_cistatic inline bool ata_id_sct_long_sector_access(const u16 *id)
8168c2ecf20Sopenharmony_ci{
8178c2ecf20Sopenharmony_ci	return id[ATA_ID_SCT_CMD_XPORT] & (1 << 1) ? true : false;
8188c2ecf20Sopenharmony_ci}
8198c2ecf20Sopenharmony_ci
8208c2ecf20Sopenharmony_cistatic inline bool ata_id_sct_supported(const u16 *id)
8218c2ecf20Sopenharmony_ci{
8228c2ecf20Sopenharmony_ci	return id[ATA_ID_SCT_CMD_XPORT] & (1 << 0) ? true : false;
8238c2ecf20Sopenharmony_ci}
8248c2ecf20Sopenharmony_ci
8258c2ecf20Sopenharmony_ci/**
8268c2ecf20Sopenharmony_ci *	ata_id_major_version	-	get ATA level of drive
8278c2ecf20Sopenharmony_ci *	@id: Identify data
8288c2ecf20Sopenharmony_ci *
8298c2ecf20Sopenharmony_ci *	Caveats:
8308c2ecf20Sopenharmony_ci *		ATA-1 considers identify optional
8318c2ecf20Sopenharmony_ci *		ATA-2 introduces mandatory identify
8328c2ecf20Sopenharmony_ci *		ATA-3 introduces word 80 and accurate reporting
8338c2ecf20Sopenharmony_ci *
8348c2ecf20Sopenharmony_ci *	The practical impact of this is that ata_id_major_version cannot
8358c2ecf20Sopenharmony_ci *	reliably report on drives below ATA3.
8368c2ecf20Sopenharmony_ci */
8378c2ecf20Sopenharmony_ci
8388c2ecf20Sopenharmony_cistatic inline unsigned int ata_id_major_version(const u16 *id)
8398c2ecf20Sopenharmony_ci{
8408c2ecf20Sopenharmony_ci	unsigned int mver;
8418c2ecf20Sopenharmony_ci
8428c2ecf20Sopenharmony_ci	if (id[ATA_ID_MAJOR_VER] == 0xFFFF)
8438c2ecf20Sopenharmony_ci		return 0;
8448c2ecf20Sopenharmony_ci
8458c2ecf20Sopenharmony_ci	for (mver = 14; mver >= 1; mver--)
8468c2ecf20Sopenharmony_ci		if (id[ATA_ID_MAJOR_VER] & (1 << mver))
8478c2ecf20Sopenharmony_ci			break;
8488c2ecf20Sopenharmony_ci	return mver;
8498c2ecf20Sopenharmony_ci}
8508c2ecf20Sopenharmony_ci
8518c2ecf20Sopenharmony_cistatic inline bool ata_id_is_sata(const u16 *id)
8528c2ecf20Sopenharmony_ci{
8538c2ecf20Sopenharmony_ci	/*
8548c2ecf20Sopenharmony_ci	 * See if word 93 is 0 AND drive is at least ATA-5 compatible
8558c2ecf20Sopenharmony_ci	 * verifying that word 80 by casting it to a signed type --
8568c2ecf20Sopenharmony_ci	 * this trick allows us to filter out the reserved values of
8578c2ecf20Sopenharmony_ci	 * 0x0000 and 0xffff along with the earlier ATA revisions...
8588c2ecf20Sopenharmony_ci	 */
8598c2ecf20Sopenharmony_ci	if (id[ATA_ID_HW_CONFIG] == 0 && (short)id[ATA_ID_MAJOR_VER] >= 0x0020)
8608c2ecf20Sopenharmony_ci		return true;
8618c2ecf20Sopenharmony_ci	return false;
8628c2ecf20Sopenharmony_ci}
8638c2ecf20Sopenharmony_ci
8648c2ecf20Sopenharmony_cistatic inline bool ata_id_has_tpm(const u16 *id)
8658c2ecf20Sopenharmony_ci{
8668c2ecf20Sopenharmony_ci	/* The TPM bits are only valid on ATA8 */
8678c2ecf20Sopenharmony_ci	if (ata_id_major_version(id) < 8)
8688c2ecf20Sopenharmony_ci		return false;
8698c2ecf20Sopenharmony_ci	if ((id[48] & 0xC000) != 0x4000)
8708c2ecf20Sopenharmony_ci		return false;
8718c2ecf20Sopenharmony_ci	return id[48] & (1 << 0);
8728c2ecf20Sopenharmony_ci}
8738c2ecf20Sopenharmony_ci
8748c2ecf20Sopenharmony_cistatic inline bool ata_id_has_dword_io(const u16 *id)
8758c2ecf20Sopenharmony_ci{
8768c2ecf20Sopenharmony_ci	/* ATA 8 reuses this flag for "trusted" computing */
8778c2ecf20Sopenharmony_ci	if (ata_id_major_version(id) > 7)
8788c2ecf20Sopenharmony_ci		return false;
8798c2ecf20Sopenharmony_ci	return id[ATA_ID_DWORD_IO] & (1 << 0);
8808c2ecf20Sopenharmony_ci}
8818c2ecf20Sopenharmony_ci
8828c2ecf20Sopenharmony_cistatic inline bool ata_id_has_trusted(const u16 *id)
8838c2ecf20Sopenharmony_ci{
8848c2ecf20Sopenharmony_ci	if (ata_id_major_version(id) <= 7)
8858c2ecf20Sopenharmony_ci		return false;
8868c2ecf20Sopenharmony_ci	return id[ATA_ID_TRUSTED] & (1 << 0);
8878c2ecf20Sopenharmony_ci}
8888c2ecf20Sopenharmony_ci
8898c2ecf20Sopenharmony_cistatic inline bool ata_id_has_unload(const u16 *id)
8908c2ecf20Sopenharmony_ci{
8918c2ecf20Sopenharmony_ci	if (ata_id_major_version(id) >= 7 &&
8928c2ecf20Sopenharmony_ci	    (id[ATA_ID_CFSSE] & 0xC000) == 0x4000 &&
8938c2ecf20Sopenharmony_ci	    id[ATA_ID_CFSSE] & (1 << 13))
8948c2ecf20Sopenharmony_ci		return true;
8958c2ecf20Sopenharmony_ci	return false;
8968c2ecf20Sopenharmony_ci}
8978c2ecf20Sopenharmony_ci
8988c2ecf20Sopenharmony_cistatic inline bool ata_id_has_wwn(const u16 *id)
8998c2ecf20Sopenharmony_ci{
9008c2ecf20Sopenharmony_ci	return (id[ATA_ID_CSF_DEFAULT] & 0xC100) == 0x4100;
9018c2ecf20Sopenharmony_ci}
9028c2ecf20Sopenharmony_ci
9038c2ecf20Sopenharmony_cistatic inline int ata_id_form_factor(const u16 *id)
9048c2ecf20Sopenharmony_ci{
9058c2ecf20Sopenharmony_ci	u16 val = id[168];
9068c2ecf20Sopenharmony_ci
9078c2ecf20Sopenharmony_ci	if (ata_id_major_version(id) < 7 || val == 0 || val == 0xffff)
9088c2ecf20Sopenharmony_ci		return 0;
9098c2ecf20Sopenharmony_ci
9108c2ecf20Sopenharmony_ci	val &= 0xf;
9118c2ecf20Sopenharmony_ci
9128c2ecf20Sopenharmony_ci	if (val > 5)
9138c2ecf20Sopenharmony_ci		return 0;
9148c2ecf20Sopenharmony_ci
9158c2ecf20Sopenharmony_ci	return val;
9168c2ecf20Sopenharmony_ci}
9178c2ecf20Sopenharmony_ci
9188c2ecf20Sopenharmony_cistatic inline int ata_id_rotation_rate(const u16 *id)
9198c2ecf20Sopenharmony_ci{
9208c2ecf20Sopenharmony_ci	u16 val = id[217];
9218c2ecf20Sopenharmony_ci
9228c2ecf20Sopenharmony_ci	if (ata_id_major_version(id) < 7 || val == 0 || val == 0xffff)
9238c2ecf20Sopenharmony_ci		return 0;
9248c2ecf20Sopenharmony_ci
9258c2ecf20Sopenharmony_ci	if (val > 1 && val < 0x401)
9268c2ecf20Sopenharmony_ci		return 0;
9278c2ecf20Sopenharmony_ci
9288c2ecf20Sopenharmony_ci	return val;
9298c2ecf20Sopenharmony_ci}
9308c2ecf20Sopenharmony_ci
9318c2ecf20Sopenharmony_cistatic inline bool ata_id_has_ncq_send_and_recv(const u16 *id)
9328c2ecf20Sopenharmony_ci{
9338c2ecf20Sopenharmony_ci	return id[ATA_ID_SATA_CAPABILITY_2] & BIT(6);
9348c2ecf20Sopenharmony_ci}
9358c2ecf20Sopenharmony_ci
9368c2ecf20Sopenharmony_cistatic inline bool ata_id_has_ncq_non_data(const u16 *id)
9378c2ecf20Sopenharmony_ci{
9388c2ecf20Sopenharmony_ci	return id[ATA_ID_SATA_CAPABILITY_2] & BIT(5);
9398c2ecf20Sopenharmony_ci}
9408c2ecf20Sopenharmony_ci
9418c2ecf20Sopenharmony_cistatic inline bool ata_id_has_ncq_prio(const u16 *id)
9428c2ecf20Sopenharmony_ci{
9438c2ecf20Sopenharmony_ci	return id[ATA_ID_SATA_CAPABILITY] & BIT(12);
9448c2ecf20Sopenharmony_ci}
9458c2ecf20Sopenharmony_ci
9468c2ecf20Sopenharmony_cistatic inline bool ata_id_has_trim(const u16 *id)
9478c2ecf20Sopenharmony_ci{
9488c2ecf20Sopenharmony_ci	if (ata_id_major_version(id) >= 7 &&
9498c2ecf20Sopenharmony_ci	    (id[ATA_ID_DATA_SET_MGMT] & 1))
9508c2ecf20Sopenharmony_ci		return true;
9518c2ecf20Sopenharmony_ci	return false;
9528c2ecf20Sopenharmony_ci}
9538c2ecf20Sopenharmony_ci
9548c2ecf20Sopenharmony_cistatic inline bool ata_id_has_zero_after_trim(const u16 *id)
9558c2ecf20Sopenharmony_ci{
9568c2ecf20Sopenharmony_ci	/* DSM supported, deterministic read, and read zero after trim set */
9578c2ecf20Sopenharmony_ci	if (ata_id_has_trim(id) &&
9588c2ecf20Sopenharmony_ci	    (id[ATA_ID_ADDITIONAL_SUPP] & 0x4020) == 0x4020)
9598c2ecf20Sopenharmony_ci		return true;
9608c2ecf20Sopenharmony_ci
9618c2ecf20Sopenharmony_ci	return false;
9628c2ecf20Sopenharmony_ci}
9638c2ecf20Sopenharmony_ci
9648c2ecf20Sopenharmony_cistatic inline bool ata_id_current_chs_valid(const u16 *id)
9658c2ecf20Sopenharmony_ci{
9668c2ecf20Sopenharmony_ci	/* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command
9678c2ecf20Sopenharmony_ci	   has not been issued to the device then the values of
9688c2ecf20Sopenharmony_ci	   id[ATA_ID_CUR_CYLS] to id[ATA_ID_CUR_SECTORS] are vendor specific. */
9698c2ecf20Sopenharmony_ci	return (id[ATA_ID_FIELD_VALID] & 1) && /* Current translation valid */
9708c2ecf20Sopenharmony_ci		id[ATA_ID_CUR_CYLS] &&  /* cylinders in current translation */
9718c2ecf20Sopenharmony_ci		id[ATA_ID_CUR_HEADS] &&  /* heads in current translation */
9728c2ecf20Sopenharmony_ci		id[ATA_ID_CUR_HEADS] <= 16 &&
9738c2ecf20Sopenharmony_ci		id[ATA_ID_CUR_SECTORS];    /* sectors in current translation */
9748c2ecf20Sopenharmony_ci}
9758c2ecf20Sopenharmony_ci
9768c2ecf20Sopenharmony_cistatic inline bool ata_id_is_cfa(const u16 *id)
9778c2ecf20Sopenharmony_ci{
9788c2ecf20Sopenharmony_ci	if ((id[ATA_ID_CONFIG] == 0x848A) ||	/* Traditional CF */
9798c2ecf20Sopenharmony_ci	    (id[ATA_ID_CONFIG] == 0x844A))	/* Delkin Devices CF */
9808c2ecf20Sopenharmony_ci		return true;
9818c2ecf20Sopenharmony_ci	/*
9828c2ecf20Sopenharmony_ci	 * CF specs don't require specific value in the word 0 anymore and yet
9838c2ecf20Sopenharmony_ci	 * they forbid to report the ATA version in the word 80 and require the
9848c2ecf20Sopenharmony_ci	 * CFA feature set support to be indicated in the word 83 in this case.
9858c2ecf20Sopenharmony_ci	 * Unfortunately, some cards only follow either of this requirements,
9868c2ecf20Sopenharmony_ci	 * and while those that don't indicate CFA feature support need some
9878c2ecf20Sopenharmony_ci	 * sort of quirk list, it seems impractical for the ones that do...
9888c2ecf20Sopenharmony_ci	 */
9898c2ecf20Sopenharmony_ci	return (id[ATA_ID_COMMAND_SET_2] & 0xC004) == 0x4004;
9908c2ecf20Sopenharmony_ci}
9918c2ecf20Sopenharmony_ci
9928c2ecf20Sopenharmony_cistatic inline bool ata_id_is_ssd(const u16 *id)
9938c2ecf20Sopenharmony_ci{
9948c2ecf20Sopenharmony_ci	return id[ATA_ID_ROT_SPEED] == 0x01;
9958c2ecf20Sopenharmony_ci}
9968c2ecf20Sopenharmony_ci
9978c2ecf20Sopenharmony_cistatic inline u8 ata_id_zoned_cap(const u16 *id)
9988c2ecf20Sopenharmony_ci{
9998c2ecf20Sopenharmony_ci	return (id[ATA_ID_ADDITIONAL_SUPP] & 0x3);
10008c2ecf20Sopenharmony_ci}
10018c2ecf20Sopenharmony_ci
10028c2ecf20Sopenharmony_cistatic inline bool ata_id_pio_need_iordy(const u16 *id, const u8 pio)
10038c2ecf20Sopenharmony_ci{
10048c2ecf20Sopenharmony_ci	/* CF spec. r4.1 Table 22 says no IORDY on PIO5 and PIO6. */
10058c2ecf20Sopenharmony_ci	if (pio > 4 && ata_id_is_cfa(id))
10068c2ecf20Sopenharmony_ci		return false;
10078c2ecf20Sopenharmony_ci	/* For PIO3 and higher it is mandatory. */
10088c2ecf20Sopenharmony_ci	if (pio > 2)
10098c2ecf20Sopenharmony_ci		return true;
10108c2ecf20Sopenharmony_ci	/* Turn it on when possible. */
10118c2ecf20Sopenharmony_ci	return ata_id_has_iordy(id);
10128c2ecf20Sopenharmony_ci}
10138c2ecf20Sopenharmony_ci
10148c2ecf20Sopenharmony_cistatic inline bool ata_drive_40wire(const u16 *dev_id)
10158c2ecf20Sopenharmony_ci{
10168c2ecf20Sopenharmony_ci	if (ata_id_is_sata(dev_id))
10178c2ecf20Sopenharmony_ci		return false;	/* SATA */
10188c2ecf20Sopenharmony_ci	if ((dev_id[ATA_ID_HW_CONFIG] & 0xE000) == 0x6000)
10198c2ecf20Sopenharmony_ci		return false;	/* 80 wire */
10208c2ecf20Sopenharmony_ci	return true;
10218c2ecf20Sopenharmony_ci}
10228c2ecf20Sopenharmony_ci
10238c2ecf20Sopenharmony_cistatic inline bool ata_drive_40wire_relaxed(const u16 *dev_id)
10248c2ecf20Sopenharmony_ci{
10258c2ecf20Sopenharmony_ci	if ((dev_id[ATA_ID_HW_CONFIG] & 0x2000) == 0x2000)
10268c2ecf20Sopenharmony_ci		return false;	/* 80 wire */
10278c2ecf20Sopenharmony_ci	return true;
10288c2ecf20Sopenharmony_ci}
10298c2ecf20Sopenharmony_ci
10308c2ecf20Sopenharmony_cistatic inline int atapi_cdb_len(const u16 *dev_id)
10318c2ecf20Sopenharmony_ci{
10328c2ecf20Sopenharmony_ci	u16 tmp = dev_id[ATA_ID_CONFIG] & 0x3;
10338c2ecf20Sopenharmony_ci	switch (tmp) {
10348c2ecf20Sopenharmony_ci	case 0:		return 12;
10358c2ecf20Sopenharmony_ci	case 1:		return 16;
10368c2ecf20Sopenharmony_ci	default:	return -1;
10378c2ecf20Sopenharmony_ci	}
10388c2ecf20Sopenharmony_ci}
10398c2ecf20Sopenharmony_ci
10408c2ecf20Sopenharmony_cistatic inline int atapi_command_packet_set(const u16 *dev_id)
10418c2ecf20Sopenharmony_ci{
10428c2ecf20Sopenharmony_ci	return (dev_id[ATA_ID_CONFIG] >> 8) & 0x1f;
10438c2ecf20Sopenharmony_ci}
10448c2ecf20Sopenharmony_ci
10458c2ecf20Sopenharmony_cistatic inline bool atapi_id_dmadir(const u16 *dev_id)
10468c2ecf20Sopenharmony_ci{
10478c2ecf20Sopenharmony_ci	return ata_id_major_version(dev_id) >= 7 && (dev_id[62] & 0x8000);
10488c2ecf20Sopenharmony_ci}
10498c2ecf20Sopenharmony_ci
10508c2ecf20Sopenharmony_ci/*
10518c2ecf20Sopenharmony_ci * ata_id_is_lba_capacity_ok() performs a sanity check on
10528c2ecf20Sopenharmony_ci * the claimed LBA capacity value for the device.
10538c2ecf20Sopenharmony_ci *
10548c2ecf20Sopenharmony_ci * Returns 1 if LBA capacity looks sensible, 0 otherwise.
10558c2ecf20Sopenharmony_ci *
10568c2ecf20Sopenharmony_ci * It is called only once for each device.
10578c2ecf20Sopenharmony_ci */
10588c2ecf20Sopenharmony_cistatic inline bool ata_id_is_lba_capacity_ok(u16 *id)
10598c2ecf20Sopenharmony_ci{
10608c2ecf20Sopenharmony_ci	unsigned long lba_sects, chs_sects, head, tail;
10618c2ecf20Sopenharmony_ci
10628c2ecf20Sopenharmony_ci	/* No non-LBA info .. so valid! */
10638c2ecf20Sopenharmony_ci	if (id[ATA_ID_CYLS] == 0)
10648c2ecf20Sopenharmony_ci		return true;
10658c2ecf20Sopenharmony_ci
10668c2ecf20Sopenharmony_ci	lba_sects = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
10678c2ecf20Sopenharmony_ci
10688c2ecf20Sopenharmony_ci	/*
10698c2ecf20Sopenharmony_ci	 * The ATA spec tells large drives to return
10708c2ecf20Sopenharmony_ci	 * C/H/S = 16383/16/63 independent of their size.
10718c2ecf20Sopenharmony_ci	 * Some drives can be jumpered to use 15 heads instead of 16.
10728c2ecf20Sopenharmony_ci	 * Some drives can be jumpered to use 4092 cyls instead of 16383.
10738c2ecf20Sopenharmony_ci	 */
10748c2ecf20Sopenharmony_ci	if ((id[ATA_ID_CYLS] == 16383 ||
10758c2ecf20Sopenharmony_ci	     (id[ATA_ID_CYLS] == 4092 && id[ATA_ID_CUR_CYLS] == 16383)) &&
10768c2ecf20Sopenharmony_ci	    id[ATA_ID_SECTORS] == 63 &&
10778c2ecf20Sopenharmony_ci	    (id[ATA_ID_HEADS] == 15 || id[ATA_ID_HEADS] == 16) &&
10788c2ecf20Sopenharmony_ci	    (lba_sects >= 16383 * 63 * id[ATA_ID_HEADS]))
10798c2ecf20Sopenharmony_ci		return true;
10808c2ecf20Sopenharmony_ci
10818c2ecf20Sopenharmony_ci	chs_sects = id[ATA_ID_CYLS] * id[ATA_ID_HEADS] * id[ATA_ID_SECTORS];
10828c2ecf20Sopenharmony_ci
10838c2ecf20Sopenharmony_ci	/* perform a rough sanity check on lba_sects: within 10% is OK */
10848c2ecf20Sopenharmony_ci	if (lba_sects - chs_sects < chs_sects/10)
10858c2ecf20Sopenharmony_ci		return true;
10868c2ecf20Sopenharmony_ci
10878c2ecf20Sopenharmony_ci	/* some drives have the word order reversed */
10888c2ecf20Sopenharmony_ci	head = (lba_sects >> 16) & 0xffff;
10898c2ecf20Sopenharmony_ci	tail = lba_sects & 0xffff;
10908c2ecf20Sopenharmony_ci	lba_sects = head | (tail << 16);
10918c2ecf20Sopenharmony_ci
10928c2ecf20Sopenharmony_ci	if (lba_sects - chs_sects < chs_sects/10) {
10938c2ecf20Sopenharmony_ci		*(__le32 *)&id[ATA_ID_LBA_CAPACITY] = __cpu_to_le32(lba_sects);
10948c2ecf20Sopenharmony_ci		return true;	/* LBA capacity is (now) good */
10958c2ecf20Sopenharmony_ci	}
10968c2ecf20Sopenharmony_ci
10978c2ecf20Sopenharmony_ci	return false;	/* LBA capacity value may be bad */
10988c2ecf20Sopenharmony_ci}
10998c2ecf20Sopenharmony_ci
11008c2ecf20Sopenharmony_cistatic inline void ata_id_to_hd_driveid(u16 *id)
11018c2ecf20Sopenharmony_ci{
11028c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN
11038c2ecf20Sopenharmony_ci	/* accessed in struct hd_driveid as 8-bit values */
11048c2ecf20Sopenharmony_ci	id[ATA_ID_MAX_MULTSECT]	 = __cpu_to_le16(id[ATA_ID_MAX_MULTSECT]);
11058c2ecf20Sopenharmony_ci	id[ATA_ID_CAPABILITY]	 = __cpu_to_le16(id[ATA_ID_CAPABILITY]);
11068c2ecf20Sopenharmony_ci	id[ATA_ID_OLD_PIO_MODES] = __cpu_to_le16(id[ATA_ID_OLD_PIO_MODES]);
11078c2ecf20Sopenharmony_ci	id[ATA_ID_OLD_DMA_MODES] = __cpu_to_le16(id[ATA_ID_OLD_DMA_MODES]);
11088c2ecf20Sopenharmony_ci	id[ATA_ID_MULTSECT]	 = __cpu_to_le16(id[ATA_ID_MULTSECT]);
11098c2ecf20Sopenharmony_ci
11108c2ecf20Sopenharmony_ci	/* as 32-bit values */
11118c2ecf20Sopenharmony_ci	*(u32 *)&id[ATA_ID_LBA_CAPACITY] = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
11128c2ecf20Sopenharmony_ci	*(u32 *)&id[ATA_ID_SPG]		 = ata_id_u32(id, ATA_ID_SPG);
11138c2ecf20Sopenharmony_ci
11148c2ecf20Sopenharmony_ci	/* as 64-bit value */
11158c2ecf20Sopenharmony_ci	*(u64 *)&id[ATA_ID_LBA_CAPACITY_2] =
11168c2ecf20Sopenharmony_ci		ata_id_u64(id, ATA_ID_LBA_CAPACITY_2);
11178c2ecf20Sopenharmony_ci#endif
11188c2ecf20Sopenharmony_ci}
11198c2ecf20Sopenharmony_ci
11208c2ecf20Sopenharmony_cistatic inline bool ata_ok(u8 status)
11218c2ecf20Sopenharmony_ci{
11228c2ecf20Sopenharmony_ci	return ((status & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ | ATA_ERR))
11238c2ecf20Sopenharmony_ci			== ATA_DRDY);
11248c2ecf20Sopenharmony_ci}
11258c2ecf20Sopenharmony_ci
11268c2ecf20Sopenharmony_cistatic inline bool lba_28_ok(u64 block, u32 n_block)
11278c2ecf20Sopenharmony_ci{
11288c2ecf20Sopenharmony_ci	/* check the ending block number: must be LESS THAN 0x0fffffff */
11298c2ecf20Sopenharmony_ci	return ((block + n_block) < ((1 << 28) - 1)) && (n_block <= ATA_MAX_SECTORS);
11308c2ecf20Sopenharmony_ci}
11318c2ecf20Sopenharmony_ci
11328c2ecf20Sopenharmony_cistatic inline bool lba_48_ok(u64 block, u32 n_block)
11338c2ecf20Sopenharmony_ci{
11348c2ecf20Sopenharmony_ci	/* check the ending block number */
11358c2ecf20Sopenharmony_ci	return ((block + n_block - 1) < ((u64)1 << 48)) && (n_block <= ATA_MAX_SECTORS_LBA48);
11368c2ecf20Sopenharmony_ci}
11378c2ecf20Sopenharmony_ci
11388c2ecf20Sopenharmony_ci#define sata_pmp_gscr_vendor(gscr)	((gscr)[SATA_PMP_GSCR_PROD_ID] & 0xffff)
11398c2ecf20Sopenharmony_ci#define sata_pmp_gscr_devid(gscr)	((gscr)[SATA_PMP_GSCR_PROD_ID] >> 16)
11408c2ecf20Sopenharmony_ci#define sata_pmp_gscr_rev(gscr)		(((gscr)[SATA_PMP_GSCR_REV] >> 8) & 0xff)
11418c2ecf20Sopenharmony_ci#define sata_pmp_gscr_ports(gscr)	((gscr)[SATA_PMP_GSCR_PORT_INFO] & 0xf)
11428c2ecf20Sopenharmony_ci
11438c2ecf20Sopenharmony_ci#endif /* __LINUX_ATA_H__ */
1144