ide-atapi.c 16 KB

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