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