libata.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Copyright (C) 2008 Freescale Semiconductor, Inc.
  3. * Dave Liu <daveliu@freescale.com>
  4. * port from the libata of linux kernel
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. * MA 02111-1307 USA
  20. *
  21. */
  22. #include <libata.h>
  23. u64 ata_id_n_sectors(u16 *id)
  24. {
  25. if (ata_id_has_lba(id)) {
  26. if (ata_id_has_lba48(id))
  27. return ata_id_u64(id, ATA_ID_LBA48_SECTORS);
  28. else
  29. return ata_id_u32(id, ATA_ID_LBA_SECTORS);
  30. } else {
  31. return 0;
  32. }
  33. }
  34. u32 ata_dev_classify(u32 sig)
  35. {
  36. u8 lbam, lbah;
  37. lbam = (sig >> 16) & 0xff;
  38. lbah = (sig >> 24) & 0xff;
  39. if (((lbam == 0) && (lbah == 0)) ||
  40. ((lbam == 0x3c) && (lbah == 0xc3)))
  41. return ATA_DEV_ATA;
  42. if ((lbam == 0x14) && (lbah == 0xeb))
  43. return ATA_DEV_ATAPI;
  44. if ((lbam == 0x69) && (lbah == 0x96))
  45. return ATA_DEV_PMP;
  46. return ATA_DEV_UNKNOWN;
  47. }
  48. static void ata_id_string(const u16 *id, unsigned char *s,
  49. unsigned int ofs, unsigned int len)
  50. {
  51. unsigned int c;
  52. while (len > 0) {
  53. c = id[ofs] >> 8;
  54. *s = c;
  55. s++;
  56. c = id[ofs] & 0xff;
  57. *s = c;
  58. s++;
  59. ofs++;
  60. len -= 2;
  61. }
  62. }
  63. void ata_id_c_string(const u16 *id, unsigned char *s,
  64. unsigned int ofs, unsigned int len)
  65. {
  66. unsigned char *p;
  67. ata_id_string(id, s, ofs, len - 1);
  68. p = s + strnlen((char *)s, len - 1);
  69. while (p > s && p[-1] == ' ')
  70. p--;
  71. *p = '\0';
  72. }
  73. void ata_dump_id(u16 *id)
  74. {
  75. unsigned char serial[ATA_ID_SERNO_LEN + 1];
  76. unsigned char firmware[ATA_ID_FW_REV_LEN + 1];
  77. unsigned char product[ATA_ID_PROD_LEN + 1];
  78. u64 n_sectors;
  79. /* Serial number */
  80. ata_id_c_string(id, serial, ATA_ID_SERNO, sizeof(serial));
  81. printf("S/N: %s\n\r", serial);
  82. /* Firmware version */
  83. ata_id_c_string(id, firmware, ATA_ID_FW_REV, sizeof(firmware));
  84. printf("Firmware version: %s\n\r", firmware);
  85. /* Product model */
  86. ata_id_c_string(id, product, ATA_ID_PROD, sizeof(product));
  87. printf("Product model number: %s\n\r", product);
  88. /* Total sectors of device */
  89. n_sectors = ata_id_n_sectors(id);
  90. printf("Capablity: %lld sectors\n\r", n_sectors);
  91. printf ("id[49]: capabilities = 0x%04x\n"
  92. "id[53]: field valid = 0x%04x\n"
  93. "id[63]: mwdma = 0x%04x\n"
  94. "id[64]: pio = 0x%04x\n"
  95. "id[75]: queue depth = 0x%04x\n",
  96. id[49],
  97. id[53],
  98. id[63],
  99. id[64],
  100. id[75]);
  101. printf ("id[76]: sata capablity = 0x%04x\n"
  102. "id[78]: sata features supported = 0x%04x\n"
  103. "id[79]: sata features enable = 0x%04x\n",
  104. id[76],
  105. id[78],
  106. id[79]);
  107. printf ("id[80]: major version = 0x%04x\n"
  108. "id[81]: minor version = 0x%04x\n"
  109. "id[82]: command set supported 1 = 0x%04x\n"
  110. "id[83]: command set supported 2 = 0x%04x\n"
  111. "id[84]: command set extension = 0x%04x\n",
  112. id[80],
  113. id[81],
  114. id[82],
  115. id[83],
  116. id[84]);
  117. printf ("id[85]: command set enable 1 = 0x%04x\n"
  118. "id[86]: command set enable 2 = 0x%04x\n"
  119. "id[87]: command set default = 0x%04x\n"
  120. "id[88]: udma = 0x%04x\n"
  121. "id[93]: hardware reset result = 0x%04x\n",
  122. id[85],
  123. id[86],
  124. id[87],
  125. id[88],
  126. id[93]);
  127. }
  128. void ata_swap_buf_le16(u16 *buf, unsigned int buf_words)
  129. {
  130. unsigned int i;
  131. for (i = 0; i < buf_words; i++)
  132. buf[i] = le16_to_cpu(buf[i]);
  133. }