ide-lib.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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.valid.in.tf = IDE_VALID_LBA;
  62. cmd.valid.in.hob = IDE_VALID_LBA;
  63. cmd.tf_flags = IDE_TFLAG_LBA48;
  64. } else
  65. cmd.valid.in.tf = IDE_VALID_LBA | IDE_VALID_DEVICE;
  66. drive->hwif->tp_ops->tf_read(drive, &cmd);
  67. if (lba48 || (tf->device & ATA_LBA))
  68. printk(KERN_CONT ", LBAsect=%llu",
  69. (unsigned long long)ide_get_lba_addr(tf, lba48));
  70. else
  71. printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam,
  72. tf->device & 0xf, tf->lbal);
  73. }
  74. static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
  75. {
  76. printk(KERN_ERR "{ ");
  77. if (err & ATA_ABORTED)
  78. printk(KERN_CONT "DriveStatusError ");
  79. if (err & ATA_ICRC)
  80. printk(KERN_CONT "%s",
  81. (err & ATA_ABORTED) ? "BadCRC " : "BadSector ");
  82. if (err & ATA_UNC)
  83. printk(KERN_CONT "UncorrectableError ");
  84. if (err & ATA_IDNF)
  85. printk(KERN_CONT "SectorIdNotFound ");
  86. if (err & ATA_TRK0NF)
  87. printk(KERN_CONT "TrackZeroNotFound ");
  88. if (err & ATA_AMNF)
  89. printk(KERN_CONT "AddrMarkNotFound ");
  90. printk(KERN_CONT "}");
  91. if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
  92. (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
  93. struct request *rq = drive->hwif->rq;
  94. ide_dump_sector(drive);
  95. if (rq)
  96. printk(KERN_CONT ", sector=%llu",
  97. (unsigned long long)rq->sector);
  98. }
  99. printk(KERN_CONT "\n");
  100. }
  101. static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
  102. {
  103. printk(KERN_ERR "{ ");
  104. if (err & ATAPI_ILI)
  105. printk(KERN_CONT "IllegalLengthIndication ");
  106. if (err & ATAPI_EOM)
  107. printk(KERN_CONT "EndOfMedia ");
  108. if (err & ATA_ABORTED)
  109. printk(KERN_CONT "AbortedCommand ");
  110. if (err & ATA_MCR)
  111. printk(KERN_CONT "MediaChangeRequested ");
  112. if (err & ATAPI_LFS)
  113. printk(KERN_CONT "LastFailedSense=0x%02x ",
  114. (err & ATAPI_LFS) >> 4);
  115. printk(KERN_CONT "}\n");
  116. }
  117. /**
  118. * ide_dump_status - translate ATA/ATAPI error
  119. * @drive: drive that status applies to
  120. * @msg: text message to print
  121. * @stat: status byte to decode
  122. *
  123. * Error reporting, in human readable form (luxurious, but a memory hog).
  124. * Combines the drive name, message and status byte to provide a
  125. * user understandable explanation of the device error.
  126. */
  127. u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
  128. {
  129. u8 err = 0;
  130. printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat);
  131. if (stat & ATA_BUSY)
  132. printk(KERN_CONT "Busy ");
  133. else {
  134. if (stat & ATA_DRDY)
  135. printk(KERN_CONT "DriveReady ");
  136. if (stat & ATA_DF)
  137. printk(KERN_CONT "DeviceFault ");
  138. if (stat & ATA_DSC)
  139. printk(KERN_CONT "SeekComplete ");
  140. if (stat & ATA_DRQ)
  141. printk(KERN_CONT "DataRequest ");
  142. if (stat & ATA_CORR)
  143. printk(KERN_CONT "CorrectedError ");
  144. if (stat & ATA_IDX)
  145. printk(KERN_CONT "Index ");
  146. if (stat & ATA_ERR)
  147. printk(KERN_CONT "Error ");
  148. }
  149. printk(KERN_CONT "}\n");
  150. if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) {
  151. err = ide_read_error(drive);
  152. printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err);
  153. if (drive->media == ide_disk)
  154. ide_dump_ata_error(drive, err);
  155. else
  156. ide_dump_atapi_error(drive, err);
  157. }
  158. ide_dump_opcode(drive);
  159. return err;
  160. }
  161. EXPORT_SYMBOL(ide_dump_status);