sata_promise.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * sata_promise.h - Promise SATA common definitions and inline funcs
  3. *
  4. * Copyright 2003-2004 Red Hat, Inc.
  5. *
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; see the file COPYING. If not, write to
  19. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20. *
  21. *
  22. * libata documentation is available via 'make {ps|pdf}docs',
  23. * as Documentation/DocBook/libata.*
  24. *
  25. */
  26. #ifndef __SATA_PROMISE_H__
  27. #define __SATA_PROMISE_H__
  28. #include <linux/ata.h>
  29. enum pdc_packet_bits {
  30. PDC_PKT_READ = (1 << 2),
  31. PDC_PKT_NODATA = (1 << 3),
  32. PDC_PKT_SIZEMASK = (1 << 7) | (1 << 6) | (1 << 5),
  33. PDC_PKT_CLEAR_BSY = (1 << 4),
  34. PDC_PKT_WAIT_DRDY = (1 << 3) | (1 << 4),
  35. PDC_LAST_REG = (1 << 3),
  36. PDC_REG_DEVCTL = (1 << 3) | (1 << 2) | (1 << 1),
  37. };
  38. static inline unsigned int pdc_pkt_header(struct ata_taskfile *tf,
  39. dma_addr_t sg_table,
  40. unsigned int devno, u8 *buf)
  41. {
  42. u8 dev_reg;
  43. __le32 *buf32 = (__le32 *) buf;
  44. /* set control bits (byte 0), zero delay seq id (byte 3),
  45. * and seq id (byte 2)
  46. */
  47. switch (tf->protocol) {
  48. case ATA_PROT_DMA:
  49. if (!(tf->flags & ATA_TFLAG_WRITE))
  50. buf32[0] = cpu_to_le32(PDC_PKT_READ);
  51. else
  52. buf32[0] = 0;
  53. break;
  54. case ATA_PROT_NODATA:
  55. buf32[0] = cpu_to_le32(PDC_PKT_NODATA);
  56. break;
  57. default:
  58. BUG();
  59. break;
  60. }
  61. buf32[1] = cpu_to_le32(sg_table); /* S/G table addr */
  62. buf32[2] = 0; /* no next-packet */
  63. if (devno == 0)
  64. dev_reg = ATA_DEVICE_OBS;
  65. else
  66. dev_reg = ATA_DEVICE_OBS | ATA_DEV1;
  67. /* select device */
  68. buf[12] = (1 << 5) | PDC_PKT_CLEAR_BSY | ATA_REG_DEVICE;
  69. buf[13] = dev_reg;
  70. /* device control register */
  71. buf[14] = (1 << 5) | PDC_REG_DEVCTL;
  72. buf[15] = tf->ctl;
  73. return 16; /* offset of next byte */
  74. }
  75. static inline unsigned int pdc_pkt_footer(struct ata_taskfile *tf, u8 *buf,
  76. unsigned int i)
  77. {
  78. if (tf->flags & ATA_TFLAG_DEVICE) {
  79. buf[i++] = (1 << 5) | ATA_REG_DEVICE;
  80. buf[i++] = tf->device;
  81. }
  82. /* and finally the command itself; also includes end-of-pkt marker */
  83. buf[i++] = (1 << 5) | PDC_LAST_REG | ATA_REG_CMD;
  84. buf[i++] = tf->command;
  85. return i;
  86. }
  87. static inline unsigned int pdc_prep_lba28(struct ata_taskfile *tf, u8 *buf, unsigned int i)
  88. {
  89. /* the "(1 << 5)" should be read "(count << 5)" */
  90. /* ATA command block registers */
  91. buf[i++] = (1 << 5) | ATA_REG_FEATURE;
  92. buf[i++] = tf->feature;
  93. buf[i++] = (1 << 5) | ATA_REG_NSECT;
  94. buf[i++] = tf->nsect;
  95. buf[i++] = (1 << 5) | ATA_REG_LBAL;
  96. buf[i++] = tf->lbal;
  97. buf[i++] = (1 << 5) | ATA_REG_LBAM;
  98. buf[i++] = tf->lbam;
  99. buf[i++] = (1 << 5) | ATA_REG_LBAH;
  100. buf[i++] = tf->lbah;
  101. return i;
  102. }
  103. static inline unsigned int pdc_prep_lba48(struct ata_taskfile *tf, u8 *buf, unsigned int i)
  104. {
  105. /* the "(2 << 5)" should be read "(count << 5)" */
  106. /* ATA command block registers */
  107. buf[i++] = (2 << 5) | ATA_REG_FEATURE;
  108. buf[i++] = tf->hob_feature;
  109. buf[i++] = tf->feature;
  110. buf[i++] = (2 << 5) | ATA_REG_NSECT;
  111. buf[i++] = tf->hob_nsect;
  112. buf[i++] = tf->nsect;
  113. buf[i++] = (2 << 5) | ATA_REG_LBAL;
  114. buf[i++] = tf->hob_lbal;
  115. buf[i++] = tf->lbal;
  116. buf[i++] = (2 << 5) | ATA_REG_LBAM;
  117. buf[i++] = tf->hob_lbam;
  118. buf[i++] = tf->lbam;
  119. buf[i++] = (2 << 5) | ATA_REG_LBAH;
  120. buf[i++] = tf->hob_lbah;
  121. buf[i++] = tf->lbah;
  122. return i;
  123. }
  124. #endif /* __SATA_PROMISE_H__ */