sata_promise.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * sata_promise.h - Promise SATA common definitions and inline funcs
  3. *
  4. * Copyright 2003-2004 Red Hat, Inc.
  5. *
  6. * The contents of this file are subject to the Open
  7. * Software License version 1.1 that can be found at
  8. * http://www.opensource.org/licenses/osl-1.1.txt and is included herein
  9. * by reference.
  10. *
  11. * Alternatively, the contents of this file may be used under the terms
  12. * of the GNU General Public License version 2 (the "GPL") as distributed
  13. * in the kernel source COPYING file, in which case the provisions of
  14. * the GPL are applicable instead of the above. If you wish to allow
  15. * the use of your version of this file only under the terms of the
  16. * GPL and not to allow others to use your version of this file under
  17. * the OSL, indicate your decision by deleting the provisions above and
  18. * replace them with the notice and other provisions required by the GPL.
  19. * If you do not delete the provisions above, a recipient may use your
  20. * version of this file under either the OSL or the GPL.
  21. *
  22. */
  23. #ifndef __SATA_PROMISE_H__
  24. #define __SATA_PROMISE_H__
  25. #include <linux/ata.h>
  26. enum pdc_packet_bits {
  27. PDC_PKT_READ = (1 << 2),
  28. PDC_PKT_NODATA = (1 << 3),
  29. PDC_PKT_SIZEMASK = (1 << 7) | (1 << 6) | (1 << 5),
  30. PDC_PKT_CLEAR_BSY = (1 << 4),
  31. PDC_PKT_WAIT_DRDY = (1 << 3) | (1 << 4),
  32. PDC_LAST_REG = (1 << 3),
  33. PDC_REG_DEVCTL = (1 << 3) | (1 << 2) | (1 << 1),
  34. };
  35. static inline unsigned int pdc_pkt_header(struct ata_taskfile *tf,
  36. dma_addr_t sg_table,
  37. unsigned int devno, u8 *buf)
  38. {
  39. u8 dev_reg;
  40. u32 *buf32 = (u32 *) buf;
  41. /* set control bits (byte 0), zero delay seq id (byte 3),
  42. * and seq id (byte 2)
  43. */
  44. switch (tf->protocol) {
  45. case ATA_PROT_DMA:
  46. if (!(tf->flags & ATA_TFLAG_WRITE))
  47. buf32[0] = cpu_to_le32(PDC_PKT_READ);
  48. else
  49. buf32[0] = 0;
  50. break;
  51. case ATA_PROT_NODATA:
  52. buf32[0] = cpu_to_le32(PDC_PKT_NODATA);
  53. break;
  54. default:
  55. BUG();
  56. break;
  57. }
  58. buf32[1] = cpu_to_le32(sg_table); /* S/G table addr */
  59. buf32[2] = 0; /* no next-packet */
  60. if (devno == 0)
  61. dev_reg = ATA_DEVICE_OBS;
  62. else
  63. dev_reg = ATA_DEVICE_OBS | ATA_DEV1;
  64. /* select device */
  65. buf[12] = (1 << 5) | PDC_PKT_CLEAR_BSY | ATA_REG_DEVICE;
  66. buf[13] = dev_reg;
  67. /* device control register */
  68. buf[14] = (1 << 5) | PDC_REG_DEVCTL;
  69. buf[15] = tf->ctl;
  70. return 16; /* offset of next byte */
  71. }
  72. static inline unsigned int pdc_pkt_footer(struct ata_taskfile *tf, u8 *buf,
  73. unsigned int i)
  74. {
  75. if (tf->flags & ATA_TFLAG_DEVICE) {
  76. buf[i++] = (1 << 5) | ATA_REG_DEVICE;
  77. buf[i++] = tf->device;
  78. }
  79. /* and finally the command itself; also includes end-of-pkt marker */
  80. buf[i++] = (1 << 5) | PDC_LAST_REG | ATA_REG_CMD;
  81. buf[i++] = tf->command;
  82. return i;
  83. }
  84. static inline unsigned int pdc_prep_lba28(struct ata_taskfile *tf, u8 *buf, unsigned int i)
  85. {
  86. /* the "(1 << 5)" should be read "(count << 5)" */
  87. /* ATA command block registers */
  88. buf[i++] = (1 << 5) | ATA_REG_FEATURE;
  89. buf[i++] = tf->feature;
  90. buf[i++] = (1 << 5) | ATA_REG_NSECT;
  91. buf[i++] = tf->nsect;
  92. buf[i++] = (1 << 5) | ATA_REG_LBAL;
  93. buf[i++] = tf->lbal;
  94. buf[i++] = (1 << 5) | ATA_REG_LBAM;
  95. buf[i++] = tf->lbam;
  96. buf[i++] = (1 << 5) | ATA_REG_LBAH;
  97. buf[i++] = tf->lbah;
  98. return i;
  99. }
  100. static inline unsigned int pdc_prep_lba48(struct ata_taskfile *tf, u8 *buf, unsigned int i)
  101. {
  102. /* the "(2 << 5)" should be read "(count << 5)" */
  103. /* ATA command block registers */
  104. buf[i++] = (2 << 5) | ATA_REG_FEATURE;
  105. buf[i++] = tf->hob_feature;
  106. buf[i++] = tf->feature;
  107. buf[i++] = (2 << 5) | ATA_REG_NSECT;
  108. buf[i++] = tf->hob_nsect;
  109. buf[i++] = tf->nsect;
  110. buf[i++] = (2 << 5) | ATA_REG_LBAL;
  111. buf[i++] = tf->hob_lbal;
  112. buf[i++] = tf->lbal;
  113. buf[i++] = (2 << 5) | ATA_REG_LBAM;
  114. buf[i++] = tf->hob_lbam;
  115. buf[i++] = tf->lbam;
  116. buf[i++] = (2 << 5) | ATA_REG_LBAH;
  117. buf[i++] = tf->hob_lbah;
  118. buf[i++] = tf->lbah;
  119. return i;
  120. }
  121. #endif /* __SATA_PROMISE_H__ */