aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/ata.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/ata.h')
-rw-r--r--include/linux/ata.h110
1 files changed, 94 insertions, 16 deletions
diff --git a/include/linux/ata.h b/include/linux/ata.h
index e672e80202a8..78bbacaed8c4 100644
--- a/include/linux/ata.h
+++ b/include/linux/ata.h
@@ -286,9 +286,10 @@ enum {
286 ATA_CBL_NONE = 0, 286 ATA_CBL_NONE = 0,
287 ATA_CBL_PATA40 = 1, 287 ATA_CBL_PATA40 = 1,
288 ATA_CBL_PATA80 = 2, 288 ATA_CBL_PATA80 = 2,
289 ATA_CBL_PATA40_SHORT = 3, /* 40 wire cable to high UDMA spec */ 289 ATA_CBL_PATA40_SHORT = 3, /* 40 wire cable to high UDMA spec */
290 ATA_CBL_PATA_UNK = 4, 290 ATA_CBL_PATA_UNK = 4, /* don't know, maybe 80c? */
291 ATA_CBL_SATA = 5, 291 ATA_CBL_PATA_IGN = 5, /* don't know, ignore cable handling */
292 ATA_CBL_SATA = 6,
292 293
293 /* SATA Status and Control Registers */ 294 /* SATA Status and Control Registers */
294 SCR_STATUS = 0, 295 SCR_STATUS = 0,
@@ -324,6 +325,13 @@ enum {
324 ATA_TFLAG_LBA = (1 << 4), /* enable LBA */ 325 ATA_TFLAG_LBA = (1 << 4), /* enable LBA */
325 ATA_TFLAG_FUA = (1 << 5), /* enable FUA */ 326 ATA_TFLAG_FUA = (1 << 5), /* enable FUA */
326 ATA_TFLAG_POLLING = (1 << 6), /* set nIEN to 1 and use polling */ 327 ATA_TFLAG_POLLING = (1 << 6), /* set nIEN to 1 and use polling */
328
329 /* protocol flags */
330 ATA_PROT_FLAG_PIO = (1 << 0), /* is PIO */
331 ATA_PROT_FLAG_DMA = (1 << 1), /* is DMA */
332 ATA_PROT_FLAG_DATA = ATA_PROT_FLAG_PIO | ATA_PROT_FLAG_DMA,
333 ATA_PROT_FLAG_NCQ = (1 << 2), /* is NCQ */
334 ATA_PROT_FLAG_ATAPI = (1 << 3), /* is ATAPI */
327}; 335};
328 336
329enum ata_tf_protocols { 337enum ata_tf_protocols {
@@ -333,9 +341,9 @@ enum ata_tf_protocols {
333 ATA_PROT_PIO, /* PIO data xfer */ 341 ATA_PROT_PIO, /* PIO data xfer */
334 ATA_PROT_DMA, /* DMA */ 342 ATA_PROT_DMA, /* DMA */
335 ATA_PROT_NCQ, /* NCQ */ 343 ATA_PROT_NCQ, /* NCQ */
336 ATA_PROT_ATAPI, /* packet command, PIO data xfer*/ 344 ATAPI_PROT_NODATA, /* packet command, no data */
337 ATA_PROT_ATAPI_NODATA, /* packet command, no data */ 345 ATAPI_PROT_PIO, /* packet command, PIO data xfer*/
338 ATA_PROT_ATAPI_DMA, /* packet command with special DMA sauce */ 346 ATAPI_PROT_DMA, /* packet command with special DMA sauce */
339}; 347};
340 348
341enum ata_ioctls { 349enum ata_ioctls {
@@ -346,8 +354,8 @@ enum ata_ioctls {
346/* core structures */ 354/* core structures */
347 355
348struct ata_prd { 356struct ata_prd {
349 u32 addr; 357 __le32 addr;
350 u32 flags_len; 358 __le32 flags_len;
351}; 359};
352 360
353struct ata_taskfile { 361struct ata_taskfile {
@@ -373,13 +381,69 @@ struct ata_taskfile {
373 u8 command; /* IO operation */ 381 u8 command; /* IO operation */
374}; 382};
375 383
384/*
385 * protocol tests
386 */
387static inline unsigned int ata_prot_flags(u8 prot)
388{
389 switch (prot) {
390 case ATA_PROT_NODATA:
391 return 0;
392 case ATA_PROT_PIO:
393 return ATA_PROT_FLAG_PIO;
394 case ATA_PROT_DMA:
395 return ATA_PROT_FLAG_DMA;
396 case ATA_PROT_NCQ:
397 return ATA_PROT_FLAG_DMA | ATA_PROT_FLAG_NCQ;
398 case ATAPI_PROT_NODATA:
399 return ATA_PROT_FLAG_ATAPI;
400 case ATAPI_PROT_PIO:
401 return ATA_PROT_FLAG_ATAPI | ATA_PROT_FLAG_PIO;
402 case ATAPI_PROT_DMA:
403 return ATA_PROT_FLAG_ATAPI | ATA_PROT_FLAG_DMA;
404 }
405 return 0;
406}
407
408static inline int ata_is_atapi(u8 prot)
409{
410 return ata_prot_flags(prot) & ATA_PROT_FLAG_ATAPI;
411}
412
413static inline int ata_is_nodata(u8 prot)
414{
415 return !(ata_prot_flags(prot) & ATA_PROT_FLAG_DATA);
416}
417
418static inline int ata_is_pio(u8 prot)
419{
420 return ata_prot_flags(prot) & ATA_PROT_FLAG_PIO;
421}
422
423static inline int ata_is_dma(u8 prot)
424{
425 return ata_prot_flags(prot) & ATA_PROT_FLAG_DMA;
426}
427
428static inline int ata_is_ncq(u8 prot)
429{
430 return ata_prot_flags(prot) & ATA_PROT_FLAG_NCQ;
431}
432
433static inline int ata_is_data(u8 prot)
434{
435 return ata_prot_flags(prot) & ATA_PROT_FLAG_DATA;
436}
437
438/*
439 * id tests
440 */
376#define ata_id_is_ata(id) (((id)[0] & (1 << 15)) == 0) 441#define ata_id_is_ata(id) (((id)[0] & (1 << 15)) == 0)
377#define ata_id_has_lba(id) ((id)[49] & (1 << 9)) 442#define ata_id_has_lba(id) ((id)[49] & (1 << 9))
378#define ata_id_has_dma(id) ((id)[49] & (1 << 8)) 443#define ata_id_has_dma(id) ((id)[49] & (1 << 8))
379#define ata_id_has_ncq(id) ((id)[76] & (1 << 8)) 444#define ata_id_has_ncq(id) ((id)[76] & (1 << 8))
380#define ata_id_queue_depth(id) (((id)[75] & 0x1f) + 1) 445#define ata_id_queue_depth(id) (((id)[75] & 0x1f) + 1)
381#define ata_id_removeable(id) ((id)[0] & (1 << 7)) 446#define ata_id_removeable(id) ((id)[0] & (1 << 7))
382#define ata_id_has_dword_io(id) ((id)[48] & (1 << 0))
383#define ata_id_has_atapi_AN(id) \ 447#define ata_id_has_atapi_AN(id) \
384 ( (((id)[76] != 0x0000) && ((id)[76] != 0xffff)) && \ 448 ( (((id)[76] != 0x0000) && ((id)[76] != 0xffff)) && \
385 ((id)[78] & (1 << 5)) ) 449 ((id)[78] & (1 << 5)) )
@@ -415,6 +479,7 @@ static inline bool ata_id_has_dipm(const u16 *id)
415 return val & (1 << 3); 479 return val & (1 << 3);
416} 480}
417 481
482
418static inline int ata_id_has_fua(const u16 *id) 483static inline int ata_id_has_fua(const u16 *id)
419{ 484{
420 if ((id[84] & 0xC000) != 0x4000) 485 if ((id[84] & 0xC000) != 0x4000)
@@ -519,6 +584,26 @@ static inline int ata_id_is_sata(const u16 *id)
519 return ata_id_major_version(id) >= 5 && id[93] == 0; 584 return ata_id_major_version(id) >= 5 && id[93] == 0;
520} 585}
521 586
587static inline int ata_id_has_tpm(const u16 *id)
588{
589 /* The TPM bits are only valid on ATA8 */
590 if (ata_id_major_version(id) < 8)
591 return 0;
592 if ((id[48] & 0xC000) != 0x4000)
593 return 0;
594 return id[48] & (1 << 0);
595}
596
597static inline int ata_id_has_dword_io(const u16 *id)
598{
599 /* ATA 8 reuses this flag for "trusted" computing */
600 if (ata_id_major_version(id) > 7)
601 return 0;
602 if (id[48] & (1 << 0))
603 return 1;
604 return 0;
605}
606
522static inline int ata_id_current_chs_valid(const u16 *id) 607static inline int ata_id_current_chs_valid(const u16 *id)
523{ 608{
524 /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command 609 /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command
@@ -574,13 +659,6 @@ static inline int atapi_command_packet_set(const u16 *dev_id)
574 return (dev_id[0] >> 8) & 0x1f; 659 return (dev_id[0] >> 8) & 0x1f;
575} 660}
576 661
577static inline int is_atapi_taskfile(const struct ata_taskfile *tf)
578{
579 return (tf->protocol == ATA_PROT_ATAPI) ||
580 (tf->protocol == ATA_PROT_ATAPI_NODATA) ||
581 (tf->protocol == ATA_PROT_ATAPI_DMA);
582}
583
584static inline int is_multi_taskfile(struct ata_taskfile *tf) 662static inline int is_multi_taskfile(struct ata_taskfile *tf)
585{ 663{
586 return (tf->command == ATA_CMD_READ_MULTI) || 664 return (tf->command == ATA_CMD_READ_MULTI) ||