sata_promise.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * sata_promise.h - Promise SATA common definitions and inline funcs
  4. *
  5. * Copyright 2003-2004 Red Hat, Inc.
  6. *
  7. * libata documentation is available via 'make {ps|pdf}docs',
  8. * as Documentation/driver-api/libata.rst
  9. */
  10. #ifndef __SATA_PROMISE_H__
  11. #define __SATA_PROMISE_H__
  12. #include <linux/ata.h>
  13. enum pdc_packet_bits {
  14. PDC_PKT_READ = (1 << 2),
  15. PDC_PKT_NODATA = (1 << 3),
  16. PDC_PKT_SIZEMASK = (1 << 7) | (1 << 6) | (1 << 5),
  17. PDC_PKT_CLEAR_BSY = (1 << 4),
  18. PDC_PKT_WAIT_DRDY = (1 << 3) | (1 << 4),
  19. PDC_LAST_REG = (1 << 3),
  20. PDC_REG_DEVCTL = (1 << 3) | (1 << 2) | (1 << 1),
  21. };
  22. static inline unsigned int pdc_pkt_header(struct ata_taskfile *tf,
  23. dma_addr_t sg_table,
  24. unsigned int devno, u8 *buf)
  25. {
  26. u8 dev_reg;
  27. __le32 *buf32 = (__le32 *) buf;
  28. /* set control bits (byte 0), zero delay seq id (byte 3),
  29. * and seq id (byte 2)
  30. */
  31. switch (tf->protocol) {
  32. case ATA_PROT_DMA:
  33. if (!(tf->flags & ATA_TFLAG_WRITE))
  34. buf32[0] = cpu_to_le32(PDC_PKT_READ);
  35. else
  36. buf32[0] = 0;
  37. break;
  38. case ATA_PROT_NODATA:
  39. buf32[0] = cpu_to_le32(PDC_PKT_NODATA);
  40. break;
  41. default:
  42. BUG();
  43. break;
  44. }
  45. buf32[1] = cpu_to_le32(sg_table); /* S/G table addr */
  46. buf32[2] = 0; /* no next-packet */
  47. if (devno == 0)
  48. dev_reg = ATA_DEVICE_OBS;
  49. else
  50. dev_reg = ATA_DEVICE_OBS | ATA_DEV1;
  51. /* select device */
  52. buf[12] = (1 << 5) | PDC_PKT_CLEAR_BSY | ATA_REG_DEVICE;
  53. buf[13] = dev_reg;
  54. /* device control register */
  55. buf[14] = (1 << 5) | PDC_REG_DEVCTL;
  56. buf[15] = tf->ctl;
  57. return 16; /* offset of next byte */
  58. }
  59. static inline unsigned int pdc_pkt_footer(struct ata_taskfile *tf, u8 *buf,
  60. unsigned int i)
  61. {
  62. if (tf->flags & ATA_TFLAG_DEVICE) {
  63. buf[i++] = (1 << 5) | ATA_REG_DEVICE;
  64. buf[i++] = tf->device;
  65. }
  66. /* and finally the command itself; also includes end-of-pkt marker */
  67. buf[i++] = (1 << 5) | PDC_LAST_REG | ATA_REG_CMD;
  68. buf[i++] = tf->command;
  69. return i;
  70. }
  71. static inline unsigned int pdc_prep_lba28(struct ata_taskfile *tf, u8 *buf, unsigned int i)
  72. {
  73. /* the "(1 << 5)" should be read "(count << 5)" */
  74. /* ATA command block registers */
  75. buf[i++] = (1 << 5) | ATA_REG_FEATURE;
  76. buf[i++] = tf->feature;
  77. buf[i++] = (1 << 5) | ATA_REG_NSECT;
  78. buf[i++] = tf->nsect;
  79. buf[i++] = (1 << 5) | ATA_REG_LBAL;
  80. buf[i++] = tf->lbal;
  81. buf[i++] = (1 << 5) | ATA_REG_LBAM;
  82. buf[i++] = tf->lbam;
  83. buf[i++] = (1 << 5) | ATA_REG_LBAH;
  84. buf[i++] = tf->lbah;
  85. return i;
  86. }
  87. static inline unsigned int pdc_prep_lba48(struct ata_taskfile *tf, u8 *buf, unsigned int i)
  88. {
  89. /* the "(2 << 5)" should be read "(count << 5)" */
  90. /* ATA command block registers */
  91. buf[i++] = (2 << 5) | ATA_REG_FEATURE;
  92. buf[i++] = tf->hob_feature;
  93. buf[i++] = tf->feature;
  94. buf[i++] = (2 << 5) | ATA_REG_NSECT;
  95. buf[i++] = tf->hob_nsect;
  96. buf[i++] = tf->nsect;
  97. buf[i++] = (2 << 5) | ATA_REG_LBAL;
  98. buf[i++] = tf->hob_lbal;
  99. buf[i++] = tf->lbal;
  100. buf[i++] = (2 << 5) | ATA_REG_LBAM;
  101. buf[i++] = tf->hob_lbam;
  102. buf[i++] = tf->lbam;
  103. buf[i++] = (2 << 5) | ATA_REG_LBAH;
  104. buf[i++] = tf->hob_lbah;
  105. buf[i++] = tf->lbah;
  106. return i;
  107. }
  108. #endif /* __SATA_PROMISE_H__ */