ide-lib.c 4.6 KB

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