ata.h
来自「linux 内核源代码」· C头文件 代码 · 共 617 行 · 第 1/2 页
H
617 行
SERR_10B_8B_ERR = (1 << 19), /* 10b to 8b decode error */ SERR_DISPARITY = (1 << 20), /* Disparity */ SERR_CRC = (1 << 21), /* CRC error */ SERR_HANDSHAKE = (1 << 22), /* Handshake error */ SERR_LINK_SEQ_ERR = (1 << 23), /* Link sequence error */ SERR_TRANS_ST_ERROR = (1 << 24), /* Transport state trans. error */ SERR_UNRECOG_FIS = (1 << 25), /* Unrecognized FIS */ SERR_DEV_XCHG = (1 << 26), /* device exchanged */ /* struct ata_taskfile flags */ ATA_TFLAG_LBA48 = (1 << 0), /* enable 48-bit LBA and "HOB" */ ATA_TFLAG_ISADDR = (1 << 1), /* enable r/w to nsect/lba regs */ ATA_TFLAG_DEVICE = (1 << 2), /* enable r/w to device reg */ ATA_TFLAG_WRITE = (1 << 3), /* data dir: host->dev==1 (write) */ ATA_TFLAG_LBA = (1 << 4), /* enable LBA */ ATA_TFLAG_FUA = (1 << 5), /* enable FUA */ ATA_TFLAG_POLLING = (1 << 6), /* set nIEN to 1 and use polling */};enum ata_tf_protocols { /* ATA taskfile protocols */ ATA_PROT_UNKNOWN, /* unknown/invalid */ ATA_PROT_NODATA, /* no data */ ATA_PROT_PIO, /* PIO data xfer */ ATA_PROT_DMA, /* DMA */ ATA_PROT_NCQ, /* NCQ */ ATA_PROT_ATAPI, /* packet command, PIO data xfer*/ ATA_PROT_ATAPI_NODATA, /* packet command, no data */ ATA_PROT_ATAPI_DMA, /* packet command with special DMA sauce */};enum ata_ioctls { ATA_IOC_GET_IO32 = 0x309, ATA_IOC_SET_IO32 = 0x324,};/* core structures */struct ata_prd { u32 addr; u32 flags_len;};struct ata_taskfile { unsigned long flags; /* ATA_TFLAG_xxx */ u8 protocol; /* ATA_PROT_xxx */ u8 ctl; /* control reg */ u8 hob_feature; /* additional data */ u8 hob_nsect; /* to support LBA48 */ u8 hob_lbal; u8 hob_lbam; u8 hob_lbah; u8 feature; u8 nsect; u8 lbal; u8 lbam; u8 lbah; u8 device; u8 command; /* IO operation */};#define ata_id_is_ata(id) (((id)[0] & (1 << 15)) == 0)#define ata_id_has_lba(id) ((id)[49] & (1 << 9))#define ata_id_has_dma(id) ((id)[49] & (1 << 8))#define ata_id_has_ncq(id) ((id)[76] & (1 << 8))#define ata_id_queue_depth(id) (((id)[75] & 0x1f) + 1)#define ata_id_removeable(id) ((id)[0] & (1 << 7))#define ata_id_has_dword_io(id) ((id)[48] & (1 << 0))#define ata_id_has_atapi_AN(id) \ ( (((id)[76] != 0x0000) && ((id)[76] != 0xffff)) && \ ((id)[78] & (1 << 5)) )#define ata_id_iordy_disable(id) ((id)[49] & (1 << 10))#define ata_id_has_iordy(id) ((id)[49] & (1 << 11))#define ata_id_u32(id,n) \ (((u32) (id)[(n) + 1] << 16) | ((u32) (id)[(n)]))#define ata_id_u64(id,n) \ ( ((u64) (id)[(n) + 3] << 48) | \ ((u64) (id)[(n) + 2] << 32) | \ ((u64) (id)[(n) + 1] << 16) | \ ((u64) (id)[(n) + 0]) )#define ata_id_cdb_intr(id) (((id)[0] & 0x60) == 0x20)static inline bool ata_id_has_hipm(const u16 *id){ u16 val = id[76]; if (val == 0 || val == 0xffff) return false; return val & (1 << 9);}static inline bool ata_id_has_dipm(const u16 *id){ u16 val = id[78]; if (val == 0 || val == 0xffff) return false; return val & (1 << 3);}static inline int ata_id_has_fua(const u16 *id){ if ((id[84] & 0xC000) != 0x4000) return 0; return id[84] & (1 << 6);}static inline int ata_id_has_flush(const u16 *id){ if ((id[83] & 0xC000) != 0x4000) return 0; return id[83] & (1 << 12);}static inline int ata_id_has_flush_ext(const u16 *id){ if ((id[83] & 0xC000) != 0x4000) return 0; return id[83] & (1 << 13);}static inline int ata_id_has_lba48(const u16 *id){ if ((id[83] & 0xC000) != 0x4000) return 0; if (!ata_id_u64(id, 100)) return 0; return id[83] & (1 << 10);}static inline int ata_id_hpa_enabled(const u16 *id){ /* Yes children, word 83 valid bits cover word 82 data */ if ((id[83] & 0xC000) != 0x4000) return 0; /* And 87 covers 85-87 */ if ((id[87] & 0xC000) != 0x4000) return 0; /* Check command sets enabled as well as supported */ if ((id[85] & ( 1 << 10)) == 0) return 0; return id[82] & (1 << 10);}static inline int ata_id_has_wcache(const u16 *id){ /* Yes children, word 83 valid bits cover word 82 data */ if ((id[83] & 0xC000) != 0x4000) return 0; return id[82] & (1 << 5);}static inline int ata_id_has_pm(const u16 *id){ if ((id[83] & 0xC000) != 0x4000) return 0; return id[82] & (1 << 3);}static inline int ata_id_rahead_enabled(const u16 *id){ if ((id[87] & 0xC000) != 0x4000) return 0; return id[85] & (1 << 6);}static inline int ata_id_wcache_enabled(const u16 *id){ if ((id[87] & 0xC000) != 0x4000) return 0; return id[85] & (1 << 5);}/** * ata_id_major_version - get ATA level of drive * @id: Identify data * * Caveats: * ATA-1 considers identify optional * ATA-2 introduces mandatory identify * ATA-3 introduces word 80 and accurate reporting * * The practical impact of this is that ata_id_major_version cannot * reliably report on drives below ATA3. */static inline unsigned int ata_id_major_version(const u16 *id){ unsigned int mver; if (id[ATA_ID_MAJOR_VER] == 0xFFFF) return 0; for (mver = 14; mver >= 1; mver--) if (id[ATA_ID_MAJOR_VER] & (1 << mver)) break; return mver;}static inline int ata_id_is_sata(const u16 *id){ return ata_id_major_version(id) >= 5 && id[93] == 0;}static inline int ata_id_current_chs_valid(const u16 *id){ /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command has not been issued to the device then the values of id[54] to id[56] are vendor specific. */ return (id[53] & 0x01) && /* Current translation valid */ id[54] && /* cylinders in current translation */ id[55] && /* heads in current translation */ id[55] <= 16 && id[56]; /* sectors in current translation */}static inline int ata_id_is_cfa(const u16 *id){ u16 v = id[0]; if (v == 0x848A) /* Standard CF */ return 1; /* Could be CF hiding as standard ATA */ if (ata_id_major_version(id) >= 3 && id[82] != 0xFFFF && (id[82] & ( 1 << 2))) return 1; return 0;}static inline int ata_drive_40wire(const u16 *dev_id){ if (ata_id_is_sata(dev_id)) return 0; /* SATA */ if ((dev_id[93] & 0xE000) == 0x6000) return 0; /* 80 wire */ return 1;}static inline int ata_drive_40wire_relaxed(const u16 *dev_id){ if ((dev_id[93] & 0x2000) == 0x2000) return 0; /* 80 wire */ return 1;}static inline int atapi_cdb_len(const u16 *dev_id){ u16 tmp = dev_id[0] & 0x3; switch (tmp) { case 0: return 12; case 1: return 16; default: return -1; }}static inline int atapi_command_packet_set(const u16 *dev_id){ return (dev_id[0] >> 8) & 0x1f;}static inline int is_atapi_taskfile(const struct ata_taskfile *tf){ return (tf->protocol == ATA_PROT_ATAPI) || (tf->protocol == ATA_PROT_ATAPI_NODATA) || (tf->protocol == ATA_PROT_ATAPI_DMA);}static inline int is_multi_taskfile(struct ata_taskfile *tf){ return (tf->command == ATA_CMD_READ_MULTI) || (tf->command == ATA_CMD_WRITE_MULTI) || (tf->command == ATA_CMD_READ_MULTI_EXT) || (tf->command == ATA_CMD_WRITE_MULTI_EXT) || (tf->command == ATA_CMD_WRITE_MULTI_FUA_EXT);}static inline int ata_ok(u8 status){ return ((status & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ | ATA_ERR)) == ATA_DRDY);}static inline int lba_28_ok(u64 block, u32 n_block){ /* check the ending block number */ return ((block + n_block - 1) < ((u64)1 << 28)) && (n_block <= 256);}static inline int lba_48_ok(u64 block, u32 n_block){ /* check the ending block number */ return ((block + n_block - 1) < ((u64)1 << 48)) && (n_block <= 65536);}#define sata_pmp_gscr_vendor(gscr) ((gscr)[SATA_PMP_GSCR_PROD_ID] & 0xffff)#define sata_pmp_gscr_devid(gscr) ((gscr)[SATA_PMP_GSCR_PROD_ID] >> 16)#define sata_pmp_gscr_rev(gscr) (((gscr)[SATA_PMP_GSCR_REV] >> 8) & 0xff)#define sata_pmp_gscr_ports(gscr) ((gscr)[SATA_PMP_GSCR_PORT_INFO] & 0xf)#endif /* __LINUX_ATA_H__ */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?