ide-lib.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. static void ide_dump_opcode(ide_drive_t *drive)
  29. {
  30. struct request *rq = drive->hwif->rq;
  31. struct ide_cmd *cmd = NULL;
  32. if (!rq)
  33. return;
  34. if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
  35. cmd = rq->special;
  36. printk(KERN_ERR "ide: failed opcode was: ");
  37. if (cmd == NULL)
  38. printk(KERN_CONT "unknown\n");
  39. else
  40. printk(KERN_CONT "0x%02x\n", cmd->tf.command);
  41. }
  42. u64 ide_get_lba_addr(struct ide_taskfile *tf, int lba48)
  43. {
  44. u32 high, low;
  45. if (lba48)
  46. high = (tf->hob_lbah << 16) | (tf->hob_lbam << 8) |
  47. tf->hob_lbal;
  48. else
  49. high = tf->device & 0xf;
  50. low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
  51. return ((u64)high << 24) | low;
  52. }
  53. EXPORT_SYMBOL_GPL(ide_get_lba_addr);
  54. static void ide_dump_sector(ide_drive_t *drive)
  55. {
  56. struct ide_cmd cmd;
  57. struct ide_taskfile *tf = &cmd.tf;
  58. u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
  59. memset(&cmd, 0, sizeof(cmd));
  60. if (lba48)
  61. cmd.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_HOB_LBA |
  62. IDE_TFLAG_LBA48;
  63. else
  64. cmd.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_DEVICE;
  65. drive->hwif->tp_ops->tf_read(drive, &cmd);
  66. if (lba48 || (tf->device & ATA_LBA))
  67. printk(KERN_CONT ", LBAsect=%llu",
  68. (unsigned long long)ide_get_lba_addr(tf, lba48));
  69. else
  70. printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam,
  71. tf->device & 0xf, tf->lbal);
  72. }
  73. static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
  74. {
  75. printk(KERN_ERR "{ ");
  76. if (err & ATA_ABORTED)
  77. printk(KERN_CONT "DriveStatusError ");
  78. if (err & ATA_ICRC)
  79. printk(KERN_CONT "%s",
  80. (err & ATA_ABORTED) ? "BadCRC " : "BadSector ");
  81. if (err & ATA_UNC)
  82. printk(KERN_CONT "UncorrectableError ");
  83. if (err & ATA_IDNF)
  84. printk(KERN_CONT "SectorIdNotFound ");
  85. if (err & ATA_TRK0NF)
  86. printk(KERN_CONT "TrackZeroNotFound ");
  87. if (err & ATA_AMNF)
  88. printk(KERN_CONT "AddrMarkNotFound ");
  89. printk(KERN_CONT "}");
  90. if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
  91. (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
  92. struct request *rq = drive->hwif->rq;
  93. ide_dump_sector(drive);
  94. if (rq)
  95. printk(KERN_CONT ", sector=%llu",
  96. (unsigned long long)rq->sector);
  97. }
  98. printk(KERN_CONT "\n");
  99. }
  100. static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
  101. {
  102. printk(KERN_ERR "{ ");
  103. if (err & ATAPI_ILI)
  104. printk(KERN_CONT "IllegalLengthIndication ");
  105. if (err & ATAPI_EOM)
  106. printk(KERN_CONT "EndOfMedia ");
  107. if (err & ATA_ABORTED)
  108. printk(KERN_CONT "AbortedCommand ");
  109. if (err & ATA_MCR)
  110. printk(KERN_CONT "MediaChangeRequested ");
  111. if (err & ATAPI_LFS)
  112. printk(KERN_CONT "LastFailedSense=0x%02x ",
  113. (err & ATAPI_LFS) >> 4);
  114. printk(KERN_CONT "}\n");
  115. }
  116. /**
  117. * ide_dump_status - translate ATA/ATAPI error
  118. * @drive: drive that status applies to
  119. * @msg: text message to print
  120. * @stat: status byte to decode
  121. *
  122. * Error reporting, in human readable form (luxurious, but a memory hog).
  123. * Combines the drive name, message and status byte to provide a
  124. * user understandable explanation of the device error.
  125. */
  126. u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
  127. {
  128. u8 err = 0;
  129. printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat);
  130. if (stat & ATA_BUSY)
  131. printk(KERN_CONT "Busy ");
  132. else {
  133. if (stat & ATA_DRDY)
  134. printk(KERN_CONT "DriveReady ");
  135. if (stat & ATA_DF)
  136. printk(KERN_CONT "DeviceFault ");
  137. if (stat & ATA_DSC)
  138. printk(KERN_CONT "SeekComplete ");
  139. if (stat & ATA_DRQ)
  140. printk(KERN_CONT "DataRequest ");
  141. if (stat & ATA_CORR)
  142. printk(KERN_CONT "CorrectedError ");
  143. if (stat & ATA_IDX)
  144. printk(KERN_CONT "Index ");
  145. if (stat & ATA_ERR)
  146. printk(KERN_CONT "Error ");
  147. }
  148. printk(KERN_CONT "}\n");
  149. if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) {
  150. err = ide_read_error(drive);
  151. printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err);
  152. if (drive->media == ide_disk)
  153. ide_dump_ata_error(drive, err);
  154. else
  155. ide_dump_atapi_error(drive, err);
  156. }
  157. ide_dump_opcode(drive);
  158. return err;
  159. }
  160. EXPORT_SYMBOL(ide_dump_status);