ide-lib.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #include <linux/types.h>
  2. #include <linux/string.h>
  3. #include <linux/kernel.h>
  4. #include <linux/interrupt.h>
  5. #include <linux/ide.h>
  6. #include <linux/bitops.h>
  7. /**
  8. * ide_toggle_bounce - handle bounce buffering
  9. * @drive: drive to update
  10. * @on: on/off boolean
  11. *
  12. * Enable or disable bounce buffering for the device. Drives move
  13. * between PIO and DMA and that changes the rules we need.
  14. */
  15. void ide_toggle_bounce(ide_drive_t *drive, int on)
  16. {
  17. u64 addr = BLK_BOUNCE_HIGH; /* dma64_addr_t */
  18. if (!PCI_DMA_BUS_IS_PHYS) {
  19. addr = BLK_BOUNCE_ANY;
  20. } else if (on && drive->media == ide_disk) {
  21. struct device *dev = drive->hwif->dev;
  22. if (dev && dev->dma_mask)
  23. addr = *dev->dma_mask;
  24. }
  25. if (drive->queue)
  26. blk_queue_bounce_limit(drive->queue, addr);
  27. }
  28. u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48)
  29. {
  30. struct ide_taskfile *tf = &cmd->tf;
  31. u32 high, low;
  32. low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
  33. if (lba48) {
  34. tf = &cmd->hob;
  35. high = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
  36. } else
  37. high = tf->device & 0xf;
  38. return ((u64)high << 24) | low;
  39. }
  40. EXPORT_SYMBOL_GPL(ide_get_lba_addr);
  41. static void ide_dump_sector(ide_drive_t *drive)
  42. {
  43. struct ide_cmd cmd;
  44. struct ide_taskfile *tf = &cmd.tf;
  45. u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
  46. memset(&cmd, 0, sizeof(cmd));
  47. if (lba48) {
  48. cmd.valid.in.tf = IDE_VALID_LBA;
  49. cmd.valid.in.hob = IDE_VALID_LBA;
  50. cmd.tf_flags = IDE_TFLAG_LBA48;
  51. } else
  52. cmd.valid.in.tf = IDE_VALID_LBA | IDE_VALID_DEVICE;
  53. ide_tf_readback(drive, &cmd);
  54. if (lba48 || (tf->device & ATA_LBA))
  55. printk(KERN_CONT ", LBAsect=%llu",
  56. (unsigned long long)ide_get_lba_addr(&cmd, lba48));
  57. else
  58. printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam,
  59. tf->device & 0xf, tf->lbal);
  60. }
  61. static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
  62. {
  63. printk(KERN_CONT "{ ");
  64. if (err & ATA_ABORTED)
  65. printk(KERN_CONT "DriveStatusError ");
  66. if (err & ATA_ICRC)
  67. printk(KERN_CONT "%s",
  68. (err & ATA_ABORTED) ? "BadCRC " : "BadSector ");
  69. if (err & ATA_UNC)
  70. printk(KERN_CONT "UncorrectableError ");
  71. if (err & ATA_IDNF)
  72. printk(KERN_CONT "SectorIdNotFound ");
  73. if (err & ATA_TRK0NF)
  74. printk(KERN_CONT "TrackZeroNotFound ");
  75. if (err & ATA_AMNF)
  76. printk(KERN_CONT "AddrMarkNotFound ");
  77. printk(KERN_CONT "}");
  78. if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
  79. (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
  80. struct request *rq = drive->hwif->rq;
  81. ide_dump_sector(drive);
  82. if (rq)
  83. printk(KERN_CONT ", sector=%llu",
  84. (unsigned long long)blk_rq_pos(rq));
  85. }
  86. printk(KERN_CONT "\n");
  87. }
  88. static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
  89. {
  90. printk(KERN_CONT "{ ");
  91. if (err & ATAPI_ILI)
  92. printk(KERN_CONT "IllegalLengthIndication ");
  93. if (err & ATAPI_EOM)
  94. printk(KERN_CONT "EndOfMedia ");
  95. if (err & ATA_ABORTED)
  96. printk(KERN_CONT "AbortedCommand ");
  97. if (err & ATA_MCR)
  98. printk(KERN_CONT "MediaChangeRequested ");
  99. if (err & ATAPI_LFS)
  100. printk(KERN_CONT "LastFailedSense=0x%02x ",
  101. (err & ATAPI_LFS) >> 4);
  102. printk(KERN_CONT "}\n");
  103. }
  104. /**
  105. * ide_dump_status - translate ATA/ATAPI error
  106. * @drive: drive that status applies to
  107. * @msg: text message to print
  108. * @stat: status byte to decode
  109. *
  110. * Error reporting, in human readable form (luxurious, but a memory hog).
  111. * Combines the drive name, message and status byte to provide a
  112. * user understandable explanation of the device error.
  113. */
  114. u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
  115. {
  116. u8 err = 0;
  117. printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat);
  118. if (stat & ATA_BUSY)
  119. printk(KERN_CONT "Busy ");
  120. else {
  121. if (stat & ATA_DRDY)
  122. printk(KERN_CONT "DriveReady ");
  123. if (stat & ATA_DF)
  124. printk(KERN_CONT "DeviceFault ");
  125. if (stat & ATA_DSC)
  126. printk(KERN_CONT "SeekComplete ");
  127. if (stat & ATA_DRQ)
  128. printk(KERN_CONT "DataRequest ");
  129. if (stat & ATA_CORR)
  130. printk(KERN_CONT "CorrectedError ");
  131. if (stat & ATA_IDX)
  132. printk(KERN_CONT "Index ");
  133. if (stat & ATA_ERR)
  134. printk(KERN_CONT "Error ");
  135. }
  136. printk(KERN_CONT "}\n");
  137. if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) {
  138. err = ide_read_error(drive);
  139. printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err);
  140. if (drive->media == ide_disk)
  141. ide_dump_ata_error(drive, err);
  142. else
  143. ide_dump_atapi_error(drive, err);
  144. }
  145. printk(KERN_ERR "%s: possibly failed opcode: 0x%02x\n",
  146. drive->name, drive->hwif->cmd.tf.command);
  147. return err;
  148. }
  149. EXPORT_SYMBOL(ide_dump_status);