ide-atapi.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /*
  2. * ATAPI support.
  3. */
  4. #include <linux/kernel.h>
  5. #include <linux/cdrom.h>
  6. #include <linux/delay.h>
  7. #include <linux/ide.h>
  8. #include <linux/scatterlist.h>
  9. #include <scsi/scsi.h>
  10. #ifdef DEBUG
  11. #define debug_log(fmt, args...) \
  12. printk(KERN_INFO "ide: " fmt, ## args)
  13. #else
  14. #define debug_log(fmt, args...) do {} while (0)
  15. #endif
  16. #define ATAPI_MIN_CDB_BYTES 12
  17. static inline int dev_is_idecd(ide_drive_t *drive)
  18. {
  19. return drive->media == ide_cdrom || drive->media == ide_optical;
  20. }
  21. /*
  22. * Check whether we can support a device,
  23. * based on the ATAPI IDENTIFY command results.
  24. */
  25. int ide_check_atapi_device(ide_drive_t *drive, const char *s)
  26. {
  27. u16 *id = drive->id;
  28. u8 gcw[2], protocol, device_type, removable, drq_type, packet_size;
  29. *((u16 *)&gcw) = id[ATA_ID_CONFIG];
  30. protocol = (gcw[1] & 0xC0) >> 6;
  31. device_type = gcw[1] & 0x1F;
  32. removable = (gcw[0] & 0x80) >> 7;
  33. drq_type = (gcw[0] & 0x60) >> 5;
  34. packet_size = gcw[0] & 0x03;
  35. #ifdef CONFIG_PPC
  36. /* kludge for Apple PowerBook internal zip */
  37. if (drive->media == ide_floppy && device_type == 5 &&
  38. !strstr((char *)&id[ATA_ID_PROD], "CD-ROM") &&
  39. strstr((char *)&id[ATA_ID_PROD], "ZIP"))
  40. device_type = 0;
  41. #endif
  42. if (protocol != 2)
  43. printk(KERN_ERR "%s: %s: protocol (0x%02x) is not ATAPI\n",
  44. s, drive->name, protocol);
  45. else if ((drive->media == ide_floppy && device_type != 0) ||
  46. (drive->media == ide_tape && device_type != 1))
  47. printk(KERN_ERR "%s: %s: invalid device type (0x%02x)\n",
  48. s, drive->name, device_type);
  49. else if (removable == 0)
  50. printk(KERN_ERR "%s: %s: the removable flag is not set\n",
  51. s, drive->name);
  52. else if (drive->media == ide_floppy && drq_type == 3)
  53. printk(KERN_ERR "%s: %s: sorry, DRQ type (0x%02x) not "
  54. "supported\n", s, drive->name, drq_type);
  55. else if (packet_size != 0)
  56. printk(KERN_ERR "%s: %s: packet size (0x%02x) is not 12 "
  57. "bytes\n", s, drive->name, packet_size);
  58. else
  59. return 1;
  60. return 0;
  61. }
  62. EXPORT_SYMBOL_GPL(ide_check_atapi_device);
  63. void ide_init_pc(struct ide_atapi_pc *pc)
  64. {
  65. memset(pc, 0, sizeof(*pc));
  66. pc->buf = pc->pc_buf;
  67. pc->buf_size = IDE_PC_BUFFER_SIZE;
  68. }
  69. EXPORT_SYMBOL_GPL(ide_init_pc);
  70. /*
  71. * Generate a new packet command request in front of the request queue, before
  72. * the current request, so that it will be processed immediately, on the next
  73. * pass through the driver.
  74. */
  75. static void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
  76. struct ide_atapi_pc *pc, struct request *rq)
  77. {
  78. blk_rq_init(NULL, rq);
  79. rq->cmd_type = REQ_TYPE_SPECIAL;
  80. rq->cmd_flags |= REQ_PREEMPT;
  81. rq->buffer = (char *)pc;
  82. rq->rq_disk = disk;
  83. if (pc->req_xfer) {
  84. rq->data = pc->buf;
  85. rq->data_len = pc->req_xfer;
  86. }
  87. memcpy(rq->cmd, pc->c, 12);
  88. if (drive->media == ide_tape)
  89. rq->cmd[13] = REQ_IDETAPE_PC1;
  90. drive->hwif->rq = NULL;
  91. elv_add_request(drive->queue, rq, ELEVATOR_INSERT_FRONT, 0);
  92. }
  93. /*
  94. * Add a special packet command request to the tail of the request queue,
  95. * and wait for it to be serviced.
  96. */
  97. int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk,
  98. struct ide_atapi_pc *pc)
  99. {
  100. struct request *rq;
  101. int error;
  102. rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
  103. rq->cmd_type = REQ_TYPE_SPECIAL;
  104. rq->buffer = (char *)pc;
  105. if (pc->req_xfer) {
  106. rq->data = pc->buf;
  107. rq->data_len = pc->req_xfer;
  108. }
  109. memcpy(rq->cmd, pc->c, 12);
  110. if (drive->media == ide_tape)
  111. rq->cmd[13] = REQ_IDETAPE_PC1;
  112. error = blk_execute_rq(drive->queue, disk, rq, 0);
  113. blk_put_request(rq);
  114. return error;
  115. }
  116. EXPORT_SYMBOL_GPL(ide_queue_pc_tail);
  117. int ide_do_test_unit_ready(ide_drive_t *drive, struct gendisk *disk)
  118. {
  119. struct ide_atapi_pc pc;
  120. ide_init_pc(&pc);
  121. pc.c[0] = TEST_UNIT_READY;
  122. return ide_queue_pc_tail(drive, disk, &pc);
  123. }
  124. EXPORT_SYMBOL_GPL(ide_do_test_unit_ready);
  125. int ide_do_start_stop(ide_drive_t *drive, struct gendisk *disk, int start)
  126. {
  127. struct ide_atapi_pc pc;
  128. ide_init_pc(&pc);
  129. pc.c[0] = START_STOP;
  130. pc.c[4] = start;
  131. if (drive->media == ide_tape)
  132. pc.flags |= PC_FLAG_WAIT_FOR_DSC;
  133. return ide_queue_pc_tail(drive, disk, &pc);
  134. }
  135. EXPORT_SYMBOL_GPL(ide_do_start_stop);
  136. int ide_set_media_lock(ide_drive_t *drive, struct gendisk *disk, int on)
  137. {
  138. struct ide_atapi_pc pc;
  139. if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0)
  140. return 0;
  141. ide_init_pc(&pc);
  142. pc.c[0] = ALLOW_MEDIUM_REMOVAL;
  143. pc.c[4] = on;
  144. return ide_queue_pc_tail(drive, disk, &pc);
  145. }
  146. EXPORT_SYMBOL_GPL(ide_set_media_lock);
  147. void ide_create_request_sense_cmd(ide_drive_t *drive, struct ide_atapi_pc *pc)
  148. {
  149. ide_init_pc(pc);
  150. pc->c[0] = REQUEST_SENSE;
  151. if (drive->media == ide_floppy) {
  152. pc->c[4] = 255;
  153. pc->req_xfer = 18;
  154. } else {
  155. pc->c[4] = 20;
  156. pc->req_xfer = 20;
  157. }
  158. }
  159. EXPORT_SYMBOL_GPL(ide_create_request_sense_cmd);
  160. /*
  161. * Called when an error was detected during the last packet command.
  162. * We queue a request sense packet command in the head of the request list.
  163. */
  164. void ide_retry_pc(ide_drive_t *drive, struct gendisk *disk)
  165. {
  166. struct request *rq = &drive->request_sense_rq;
  167. struct ide_atapi_pc *pc = &drive->request_sense_pc;
  168. (void)ide_read_error(drive);
  169. ide_create_request_sense_cmd(drive, pc);
  170. if (drive->media == ide_tape)
  171. set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
  172. ide_queue_pc_head(drive, disk, pc, rq);
  173. }
  174. EXPORT_SYMBOL_GPL(ide_retry_pc);
  175. int ide_cd_expiry(ide_drive_t *drive)
  176. {
  177. struct request *rq = drive->hwif->rq;
  178. unsigned long wait = 0;
  179. debug_log("%s: rq->cmd[0]: 0x%x\n", __func__, rq->cmd[0]);
  180. /*
  181. * Some commands are *slow* and normally take a long time to complete.
  182. * Usually we can use the ATAPI "disconnect" to bypass this, but not all
  183. * commands/drives support that. Let ide_timer_expiry keep polling us
  184. * for these.
  185. */
  186. switch (rq->cmd[0]) {
  187. case GPCMD_BLANK:
  188. case GPCMD_FORMAT_UNIT:
  189. case GPCMD_RESERVE_RZONE_TRACK:
  190. case GPCMD_CLOSE_TRACK:
  191. case GPCMD_FLUSH_CACHE:
  192. wait = ATAPI_WAIT_PC;
  193. break;
  194. default:
  195. if (!(rq->cmd_flags & REQ_QUIET))
  196. printk(KERN_INFO "cmd 0x%x timed out\n",
  197. rq->cmd[0]);
  198. wait = 0;
  199. break;
  200. }
  201. return wait;
  202. }
  203. EXPORT_SYMBOL_GPL(ide_cd_expiry);
  204. int ide_cd_get_xferlen(struct request *rq)
  205. {
  206. if (blk_fs_request(rq))
  207. return 32768;
  208. else if (blk_sense_request(rq) || blk_pc_request(rq) ||
  209. rq->cmd_type == REQ_TYPE_ATA_PC)
  210. return rq->data_len;
  211. else
  212. return 0;
  213. }
  214. EXPORT_SYMBOL_GPL(ide_cd_get_xferlen);
  215. void ide_read_bcount_and_ireason(ide_drive_t *drive, u16 *bcount, u8 *ireason)
  216. {
  217. struct ide_taskfile tf;
  218. drive->hwif->tp_ops->tf_read(drive, &tf, IDE_VALID_NSECT |
  219. IDE_VALID_LBAM | IDE_VALID_LBAH);
  220. *bcount = (tf.lbah << 8) | tf.lbam;
  221. *ireason = tf.nsect & 3;
  222. }
  223. EXPORT_SYMBOL_GPL(ide_read_bcount_and_ireason);
  224. /*
  225. * This is the usual interrupt handler which will be called during a packet
  226. * command. We will transfer some of the data (as requested by the drive)
  227. * and will re-point interrupt handler to us.
  228. */
  229. static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
  230. {
  231. struct ide_atapi_pc *pc = drive->pc;
  232. ide_hwif_t *hwif = drive->hwif;
  233. struct ide_cmd *cmd = &hwif->cmd;
  234. struct request *rq = hwif->rq;
  235. const struct ide_tp_ops *tp_ops = hwif->tp_ops;
  236. xfer_func_t *xferfunc;
  237. unsigned int timeout, done;
  238. u16 bcount;
  239. u8 stat, ireason, dsc = 0;
  240. u8 write = !!(pc->flags & PC_FLAG_WRITING);
  241. debug_log("Enter %s - interrupt handler\n", __func__);
  242. timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
  243. : WAIT_TAPE_CMD;
  244. /* Clear the interrupt */
  245. stat = tp_ops->read_status(hwif);
  246. if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
  247. int rc;
  248. drive->waiting_for_dma = 0;
  249. rc = hwif->dma_ops->dma_end(drive);
  250. ide_dma_unmap_sg(drive, cmd);
  251. if (rc || (drive->media == ide_tape && (stat & ATA_ERR))) {
  252. if (drive->media == ide_floppy)
  253. printk(KERN_ERR "%s: DMA %s error\n",
  254. drive->name, rq_data_dir(pc->rq)
  255. ? "write" : "read");
  256. pc->flags |= PC_FLAG_DMA_ERROR;
  257. } else {
  258. pc->xferred = pc->req_xfer;
  259. if (drive->pc_update_buffers)
  260. drive->pc_update_buffers(drive, pc);
  261. }
  262. debug_log("%s: DMA finished\n", drive->name);
  263. }
  264. /* No more interrupts */
  265. if ((stat & ATA_DRQ) == 0) {
  266. int uptodate, error;
  267. unsigned int done;
  268. debug_log("Packet command completed, %d bytes transferred\n",
  269. pc->xferred);
  270. pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
  271. local_irq_enable_in_hardirq();
  272. if (drive->media == ide_tape &&
  273. (stat & ATA_ERR) && rq->cmd[0] == REQUEST_SENSE)
  274. stat &= ~ATA_ERR;
  275. if ((stat & ATA_ERR) || (pc->flags & PC_FLAG_DMA_ERROR)) {
  276. /* Error detected */
  277. debug_log("%s: I/O error\n", drive->name);
  278. if (drive->media != ide_tape)
  279. pc->rq->errors++;
  280. if (rq->cmd[0] == REQUEST_SENSE) {
  281. printk(KERN_ERR "%s: I/O error in request sense"
  282. " command\n", drive->name);
  283. return ide_do_reset(drive);
  284. }
  285. debug_log("[cmd %x]: check condition\n", rq->cmd[0]);
  286. /* Retry operation */
  287. ide_retry_pc(drive, rq->rq_disk);
  288. /* queued, but not started */
  289. return ide_stopped;
  290. }
  291. pc->error = 0;
  292. if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0)
  293. dsc = 1;
  294. /* Command finished - Call the callback function */
  295. uptodate = drive->pc_callback(drive, dsc);
  296. if (uptodate == 0)
  297. drive->failed_pc = NULL;
  298. if (blk_special_request(rq)) {
  299. rq->errors = 0;
  300. done = blk_rq_bytes(rq);
  301. error = 0;
  302. } else {
  303. if (blk_fs_request(rq) == 0 && uptodate <= 0) {
  304. if (rq->errors == 0)
  305. rq->errors = -EIO;
  306. }
  307. if (drive->media == ide_tape)
  308. done = ide_rq_bytes(rq); /* FIXME */
  309. else
  310. done = blk_rq_bytes(rq);
  311. error = uptodate ? 0 : -EIO;
  312. }
  313. ide_complete_rq(drive, error, done);
  314. return ide_stopped;
  315. }
  316. if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
  317. pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
  318. printk(KERN_ERR "%s: The device wants to issue more interrupts "
  319. "in DMA mode\n", drive->name);
  320. ide_dma_off(drive);
  321. return ide_do_reset(drive);
  322. }
  323. /* Get the number of bytes to transfer on this interrupt. */
  324. ide_read_bcount_and_ireason(drive, &bcount, &ireason);
  325. if (ireason & ATAPI_COD) {
  326. printk(KERN_ERR "%s: CoD != 0 in %s\n", drive->name, __func__);
  327. return ide_do_reset(drive);
  328. }
  329. if (((ireason & ATAPI_IO) == ATAPI_IO) == write) {
  330. /* Hopefully, we will never get here */
  331. printk(KERN_ERR "%s: We wanted to %s, but the device wants us "
  332. "to %s!\n", drive->name,
  333. (ireason & ATAPI_IO) ? "Write" : "Read",
  334. (ireason & ATAPI_IO) ? "Read" : "Write");
  335. return ide_do_reset(drive);
  336. }
  337. xferfunc = write ? tp_ops->output_data : tp_ops->input_data;
  338. if (drive->media == ide_floppy && pc->buf == NULL) {
  339. done = min_t(unsigned int, bcount, cmd->nleft);
  340. ide_pio_bytes(drive, cmd, write, done);
  341. } else if (drive->media == ide_tape && pc->bh) {
  342. done = drive->pc_io_buffers(drive, pc, bcount, write);
  343. } else {
  344. done = min_t(unsigned int, bcount, pc->req_xfer - pc->xferred);
  345. xferfunc(drive, NULL, pc->cur_pos, done);
  346. }
  347. /* Update the current position */
  348. pc->xferred += done;
  349. pc->cur_pos += done;
  350. bcount -= done;
  351. if (bcount)
  352. ide_pad_transfer(drive, write, bcount);
  353. debug_log("[cmd %x] transferred %d bytes, padded %d bytes\n",
  354. rq->cmd[0], done, bcount);
  355. /* And set the interrupt handler again */
  356. ide_set_handler(drive, ide_pc_intr, timeout);
  357. return ide_started;
  358. }
  359. static void ide_init_packet_cmd(struct ide_cmd *cmd, u8 valid_tf,
  360. u16 bcount, u8 dma)
  361. {
  362. cmd->protocol = dma ? ATAPI_PROT_DMA : ATAPI_PROT_PIO;
  363. cmd->valid.out.tf = IDE_VALID_LBAH | IDE_VALID_LBAM |
  364. IDE_VALID_FEATURE | valid_tf;
  365. cmd->tf.command = ATA_CMD_PACKET;
  366. cmd->tf.feature = dma; /* Use PIO/DMA */
  367. cmd->tf.lbam = bcount & 0xff;
  368. cmd->tf.lbah = (bcount >> 8) & 0xff;
  369. }
  370. static u8 ide_read_ireason(ide_drive_t *drive)
  371. {
  372. struct ide_taskfile tf;
  373. drive->hwif->tp_ops->tf_read(drive, &tf, IDE_VALID_NSECT);
  374. return tf.nsect & 3;
  375. }
  376. static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason)
  377. {
  378. int retries = 100;
  379. while (retries-- && ((ireason & ATAPI_COD) == 0 ||
  380. (ireason & ATAPI_IO))) {
  381. printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing "
  382. "a packet command, retrying\n", drive->name);
  383. udelay(100);
  384. ireason = ide_read_ireason(drive);
  385. if (retries == 0) {
  386. printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing "
  387. "a packet command, ignoring\n",
  388. drive->name);
  389. ireason |= ATAPI_COD;
  390. ireason &= ~ATAPI_IO;
  391. }
  392. }
  393. return ireason;
  394. }
  395. static int ide_delayed_transfer_pc(ide_drive_t *drive)
  396. {
  397. /* Send the actual packet */
  398. drive->hwif->tp_ops->output_data(drive, NULL, drive->pc->c, 12);
  399. /* Timeout for the packet command */
  400. return WAIT_FLOPPY_CMD;
  401. }
  402. static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
  403. {
  404. struct ide_atapi_pc *uninitialized_var(pc);
  405. ide_hwif_t *hwif = drive->hwif;
  406. struct request *rq = hwif->rq;
  407. ide_expiry_t *expiry;
  408. unsigned int timeout;
  409. int cmd_len;
  410. ide_startstop_t startstop;
  411. u8 ireason;
  412. if (ide_wait_stat(&startstop, drive, ATA_DRQ, ATA_BUSY, WAIT_READY)) {
  413. printk(KERN_ERR "%s: Strange, packet command initiated yet "
  414. "DRQ isn't asserted\n", drive->name);
  415. return startstop;
  416. }
  417. if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
  418. if (drive->dma)
  419. drive->waiting_for_dma = 1;
  420. }
  421. if (dev_is_idecd(drive)) {
  422. /* ATAPI commands get padded out to 12 bytes minimum */
  423. cmd_len = COMMAND_SIZE(rq->cmd[0]);
  424. if (cmd_len < ATAPI_MIN_CDB_BYTES)
  425. cmd_len = ATAPI_MIN_CDB_BYTES;
  426. timeout = rq->timeout;
  427. expiry = ide_cd_expiry;
  428. } else {
  429. pc = drive->pc;
  430. cmd_len = ATAPI_MIN_CDB_BYTES;
  431. /*
  432. * If necessary schedule the packet transfer to occur 'timeout'
  433. * miliseconds later in ide_delayed_transfer_pc() after the
  434. * device says it's ready for a packet.
  435. */
  436. if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) {
  437. timeout = drive->pc_delay;
  438. expiry = &ide_delayed_transfer_pc;
  439. } else {
  440. timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
  441. : WAIT_TAPE_CMD;
  442. expiry = NULL;
  443. }
  444. ireason = ide_read_ireason(drive);
  445. if (drive->media == ide_tape)
  446. ireason = ide_wait_ireason(drive, ireason);
  447. if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) {
  448. printk(KERN_ERR "%s: (IO,CoD) != (0,1) while issuing "
  449. "a packet command\n", drive->name);
  450. return ide_do_reset(drive);
  451. }
  452. }
  453. hwif->expiry = expiry;
  454. /* Set the interrupt routine */
  455. ide_set_handler(drive,
  456. (dev_is_idecd(drive) ? drive->irq_handler
  457. : ide_pc_intr),
  458. timeout);
  459. /* Send the actual packet */
  460. if ((drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) == 0)
  461. hwif->tp_ops->output_data(drive, NULL, rq->cmd, cmd_len);
  462. /* Begin DMA, if necessary */
  463. if (dev_is_idecd(drive)) {
  464. if (drive->dma)
  465. hwif->dma_ops->dma_start(drive);
  466. } else {
  467. if (pc->flags & PC_FLAG_DMA_OK) {
  468. pc->flags |= PC_FLAG_DMA_IN_PROGRESS;
  469. hwif->dma_ops->dma_start(drive);
  470. }
  471. }
  472. return ide_started;
  473. }
  474. ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_cmd *cmd)
  475. {
  476. struct ide_atapi_pc *pc;
  477. ide_hwif_t *hwif = drive->hwif;
  478. ide_expiry_t *expiry = NULL;
  479. struct request *rq = hwif->rq;
  480. unsigned int timeout;
  481. u16 bcount;
  482. u8 valid_tf;
  483. u8 drq_int = !!(drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT);
  484. if (dev_is_idecd(drive)) {
  485. valid_tf = IDE_VALID_NSECT | IDE_VALID_LBAL;
  486. bcount = ide_cd_get_xferlen(rq);
  487. expiry = ide_cd_expiry;
  488. timeout = ATAPI_WAIT_PC;
  489. if (drive->dma)
  490. drive->dma = !ide_dma_prepare(drive, cmd);
  491. } else {
  492. pc = drive->pc;
  493. /* We haven't transferred any data yet */
  494. pc->xferred = 0;
  495. pc->cur_pos = pc->buf;
  496. valid_tf = IDE_VALID_DEVICE;
  497. bcount = ((drive->media == ide_tape) ?
  498. pc->req_xfer :
  499. min(pc->req_xfer, 63 * 1024));
  500. if (pc->flags & PC_FLAG_DMA_ERROR) {
  501. pc->flags &= ~PC_FLAG_DMA_ERROR;
  502. ide_dma_off(drive);
  503. }
  504. if (pc->flags & PC_FLAG_DMA_OK)
  505. drive->dma = !ide_dma_prepare(drive, cmd);
  506. if (!drive->dma)
  507. pc->flags &= ~PC_FLAG_DMA_OK;
  508. timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
  509. : WAIT_TAPE_CMD;
  510. }
  511. ide_init_packet_cmd(cmd, valid_tf, bcount, drive->dma);
  512. (void)do_rw_taskfile(drive, cmd);
  513. if (drq_int) {
  514. if (drive->dma)
  515. drive->waiting_for_dma = 0;
  516. hwif->expiry = expiry;
  517. }
  518. ide_execute_command(drive, cmd, ide_transfer_pc, timeout);
  519. return drq_int ? ide_started : ide_transfer_pc(drive);
  520. }
  521. EXPORT_SYMBOL_GPL(ide_issue_pc);