Lines Matching +full:drive +full:- +full:mode
2 * IDE DMA support (including IDE PCI BM-DMA).
4 * Copyright (C) 1995-1998 Mark Lord
5 * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org>
21 * Thanks to "Benoit Poulot-Cazajous" <poulot@chorus.fr> for testing
25 * at generic DMA -- his patches were referred to when preparing this code.
28 * for supplying a Promise UDMA board & WD UDMA drive for this work!
37 #include <linux/dma-mapping.h>
42 { "CONNER CTT8000-A" , NULL },
55 { "Compaq CRD-8241B" , NULL },
56 { "CRD-8400B" , NULL },
57 { "CRD-8480B", NULL },
58 { "CRD-8482B", NULL },
59 { "CRD-84" , NULL },
61 { "SanDisk SDP3B-64" , NULL },
62 { "SANYO CD-ROM CRD" , NULL },
63 { "HITACHI CDR-8" , NULL },
64 { "HITACHI CDR-8335" , NULL },
65 { "HITACHI CDR-8435" , NULL },
66 { "Toshiba CD-ROM XM-6202B" , NULL },
67 { "TOSHIBA CD-ROM XM-1702BC", NULL },
68 { "CD-532E-A" , NULL },
69 { "E-IDE CD-ROM CR-840", NULL },
70 { "CD-ROM Drive/F5A", NULL },
71 { "WPI CDD-820", NULL },
72 { "SAMSUNG CD-ROM SC-148C", NULL },
73 { "SAMSUNG CD-ROM SC", NULL },
74 { "ATAPI CD-ROM DRIVE 40X MAXIMUM", NULL },
76 { "SAMSUNG CD-ROM SN-124", "N001" },
78 { "CD-ROM CDR_U200", "1.09" },
84 * ide_dma_intr - IDE DMA interrupt handler
85 * @drive: the drive the interrupt is for
91 ide_startstop_t ide_dma_intr(ide_drive_t *drive) in ide_dma_intr() argument
93 ide_hwif_t *hwif = drive->hwif; in ide_dma_intr()
94 struct ide_cmd *cmd = &hwif->cmd; in ide_dma_intr()
97 drive->waiting_for_dma = 0; in ide_dma_intr()
98 dma_stat = hwif->dma_ops->dma_end(drive); in ide_dma_intr()
99 ide_dma_unmap_sg(drive, cmd); in ide_dma_intr()
100 stat = hwif->tp_ops->read_status(hwif); in ide_dma_intr()
102 if (OK_STAT(stat, DRIVE_READY, drive->bad_wstat | ATA_DRQ)) { in ide_dma_intr()
104 if ((cmd->tf_flags & IDE_TFLAG_FS) == 0) in ide_dma_intr()
105 ide_finish_cmd(drive, cmd, stat); in ide_dma_intr()
107 ide_complete_rq(drive, BLK_STS_OK, in ide_dma_intr()
108 blk_rq_sectors(cmd->rq) << 9); in ide_dma_intr()
112 drive->name, __func__, dma_stat); in ide_dma_intr()
114 return ide_error(drive, "dma_intr", stat); in ide_dma_intr()
117 int ide_dma_good_drive(ide_drive_t *drive) in ide_dma_good_drive() argument
119 return ide_in_drive_list(drive->id, drive_whitelist); in ide_dma_good_drive()
123 * ide_dma_map_sg - map IDE scatter gather for DMA I/O
124 * @drive: the drive to map the DMA table for
133 static int ide_dma_map_sg(ide_drive_t *drive, struct ide_cmd *cmd) in ide_dma_map_sg() argument
135 ide_hwif_t *hwif = drive->hwif; in ide_dma_map_sg()
136 struct scatterlist *sg = hwif->sg_table; in ide_dma_map_sg()
139 if (cmd->tf_flags & IDE_TFLAG_WRITE) in ide_dma_map_sg()
140 cmd->sg_dma_direction = DMA_TO_DEVICE; in ide_dma_map_sg()
142 cmd->sg_dma_direction = DMA_FROM_DEVICE; in ide_dma_map_sg()
144 i = dma_map_sg(hwif->dev, sg, cmd->sg_nents, cmd->sg_dma_direction); in ide_dma_map_sg()
146 cmd->orig_sg_nents = cmd->sg_nents; in ide_dma_map_sg()
147 cmd->sg_nents = i; in ide_dma_map_sg()
154 * ide_dma_unmap_sg - clean up DMA mapping
155 * @drive: The drive to unmap
164 void ide_dma_unmap_sg(ide_drive_t *drive, struct ide_cmd *cmd) in ide_dma_unmap_sg() argument
166 ide_hwif_t *hwif = drive->hwif; in ide_dma_unmap_sg()
168 dma_unmap_sg(hwif->dev, hwif->sg_table, cmd->orig_sg_nents, in ide_dma_unmap_sg()
169 cmd->sg_dma_direction); in ide_dma_unmap_sg()
174 * ide_dma_off_quietly - Generic DMA kill
175 * @drive: drive to control
180 void ide_dma_off_quietly(ide_drive_t *drive) in ide_dma_off_quietly() argument
182 drive->dev_flags &= ~IDE_DFLAG_USING_DMA; in ide_dma_off_quietly()
184 drive->hwif->dma_ops->dma_host_set(drive, 0); in ide_dma_off_quietly()
189 * ide_dma_off - disable DMA on a device
190 * @drive: drive to disable DMA on
196 void ide_dma_off(ide_drive_t *drive) in ide_dma_off() argument
198 printk(KERN_INFO "%s: DMA disabled\n", drive->name); in ide_dma_off()
199 ide_dma_off_quietly(drive); in ide_dma_off()
204 * ide_dma_on - Enable DMA on a device
205 * @drive: drive to enable DMA on
210 void ide_dma_on(ide_drive_t *drive) in ide_dma_on() argument
212 drive->dev_flags |= IDE_DFLAG_USING_DMA; in ide_dma_on()
214 drive->hwif->dma_ops->dma_host_set(drive, 1); in ide_dma_on()
217 int __ide_dma_bad_drive(ide_drive_t *drive) in __ide_dma_bad_drive() argument
219 u16 *id = drive->id; in __ide_dma_bad_drive()
224 drive->name, (char *)&id[ATA_ID_PROD]); in __ide_dma_bad_drive()
237 static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base, u8 req_mode) in ide_get_mode_mask() argument
239 u16 *id = drive->id; in ide_get_mode_mask()
240 ide_hwif_t *hwif = drive->hwif; in ide_get_mode_mask()
241 const struct ide_port_ops *port_ops = hwif->port_ops; in ide_get_mode_mask()
249 if (port_ops && port_ops->udma_filter) in ide_get_mode_mask()
250 mask &= port_ops->udma_filter(drive); in ide_get_mode_mask()
252 mask &= hwif->ultra_mask; in ide_get_mode_mask()
258 if ((mask & 0x78) && (eighty_ninty_three(drive) == 0)) in ide_get_mode_mask()
267 u8 mode = ((id[ATA_ID_CFA_MODES] & 0x38) >> 3) - 1; in ide_get_mode_mask() local
269 mask |= ((2 << mode) - 1) << 3; in ide_get_mode_mask()
272 if (port_ops && port_ops->mdma_filter) in ide_get_mode_mask()
273 mask &= port_ops->mdma_filter(drive); in ide_get_mode_mask()
275 mask &= hwif->mwdma_mask; in ide_get_mode_mask()
280 u8 mode = id[ATA_ID_OLD_DMA_MODES] >> 8; in ide_get_mode_mask() local
283 * if the mode is valid convert it to the mask in ide_get_mode_mask()
284 * (the maximum allowed mode is XFER_SW_DMA_2) in ide_get_mode_mask()
286 if (mode <= 2) in ide_get_mode_mask()
287 mask = (2 << mode) - 1; in ide_get_mode_mask()
289 mask &= hwif->swdma_mask; in ide_get_mode_mask()
300 * ide_find_dma_mode - compute DMA speed
301 * @drive: IDE device
302 * @req_mode: requested mode
304 * Checks the drive/host capabilities and finds the speed to use for
305 * the DMA transfer. The speed is then limited by the requested mode.
307 * Returns 0 if the drive/host combination is incapable of DMA transfers
308 * or if the requested mode is not a DMA mode.
311 u8 ide_find_dma_mode(ide_drive_t *drive, u8 req_mode) in ide_find_dma_mode() argument
313 ide_hwif_t *hwif = drive->hwif; in ide_find_dma_mode()
316 u8 mode = 0; in ide_find_dma_mode() local
318 if (drive->media != ide_disk) { in ide_find_dma_mode()
319 if (hwif->host_flags & IDE_HFLAG_NO_ATAPI_DMA) in ide_find_dma_mode()
326 mask = ide_get_mode_mask(drive, xfer_mode_bases[i], req_mode); in ide_find_dma_mode()
327 x = fls(mask) - 1; in ide_find_dma_mode()
329 mode = xfer_mode_bases[i] + x; in ide_find_dma_mode()
334 if (hwif->chipset == ide_acorn && mode == 0) { in ide_find_dma_mode()
338 if (ide_dma_good_drive(drive) && in ide_find_dma_mode()
339 drive->id[ATA_ID_EIDE_DMA_TIME] < 150) in ide_find_dma_mode()
340 mode = XFER_MW_DMA_1; in ide_find_dma_mode()
343 mode = min(mode, req_mode); in ide_find_dma_mode()
345 printk(KERN_INFO "%s: %s mode selected\n", drive->name, in ide_find_dma_mode()
346 mode ? ide_xfer_verbose(mode) : "no DMA"); in ide_find_dma_mode()
348 return mode; in ide_find_dma_mode()
351 static int ide_tune_dma(ide_drive_t *drive) in ide_tune_dma() argument
353 ide_hwif_t *hwif = drive->hwif; in ide_tune_dma()
356 if (ata_id_has_dma(drive->id) == 0 || in ide_tune_dma()
357 (drive->dev_flags & IDE_DFLAG_NODMA)) in ide_tune_dma()
361 if (__ide_dma_bad_drive(drive)) in ide_tune_dma()
364 if (hwif->host_flags & IDE_HFLAG_TRUST_BIOS_FOR_DMA) in ide_tune_dma()
365 return config_drive_for_dma(drive); in ide_tune_dma()
367 speed = ide_max_dma_mode(drive); in ide_tune_dma()
372 if (ide_set_dma_mode(drive, speed)) in ide_tune_dma()
378 static int ide_dma_check(ide_drive_t *drive) in ide_dma_check() argument
380 ide_hwif_t *hwif = drive->hwif; in ide_dma_check()
382 if (ide_tune_dma(drive)) in ide_dma_check()
386 if (hwif->host_flags & IDE_HFLAG_TRUST_BIOS_FOR_DMA) in ide_dma_check()
387 return -1; in ide_dma_check()
389 ide_set_max_pio(drive); in ide_dma_check()
391 return -1; in ide_dma_check()
394 int ide_set_dma(ide_drive_t *drive) in ide_set_dma() argument
404 ide_dma_off_quietly(drive); in ide_set_dma()
406 rc = ide_dma_check(drive); in ide_set_dma()
410 ide_dma_on(drive); in ide_set_dma()
415 void ide_check_dma_crc(ide_drive_t *drive) in ide_check_dma_crc() argument
417 u8 mode; in ide_check_dma_crc() local
419 ide_dma_off_quietly(drive); in ide_check_dma_crc()
420 drive->crc_count = 0; in ide_check_dma_crc()
421 mode = drive->current_speed; in ide_check_dma_crc()
423 * Don't try non Ultra-DMA modes without iCRC's. Force the in ide_check_dma_crc()
426 if (mode > XFER_UDMA_0 && mode <= XFER_UDMA_7) in ide_check_dma_crc()
427 mode--; in ide_check_dma_crc()
429 mode = XFER_PIO_4; in ide_check_dma_crc()
430 ide_set_xfer_rate(drive, mode); in ide_check_dma_crc()
431 if (drive->current_speed >= XFER_SW_DMA_0) in ide_check_dma_crc()
432 ide_dma_on(drive); in ide_check_dma_crc()
435 void ide_dma_lost_irq(ide_drive_t *drive) in ide_dma_lost_irq() argument
437 printk(KERN_ERR "%s: DMA interrupt recovery\n", drive->name); in ide_dma_lost_irq()
442 * un-busy the port etc, and clear any pending DMA status. we want to
443 * retry the current request in pio mode instead of risking tossing it
446 ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error) in ide_dma_timeout_retry() argument
448 ide_hwif_t *hwif = drive->hwif; in ide_dma_timeout_retry()
449 const struct ide_dma_ops *dma_ops = hwif->dma_ops; in ide_dma_timeout_retry()
450 struct ide_cmd *cmd = &hwif->cmd; in ide_dma_timeout_retry()
458 printk(KERN_WARNING "%s: DMA timeout error\n", drive->name); in ide_dma_timeout_retry()
459 drive->waiting_for_dma = 0; in ide_dma_timeout_retry()
460 (void)dma_ops->dma_end(drive); in ide_dma_timeout_retry()
461 ide_dma_unmap_sg(drive, cmd); in ide_dma_timeout_retry()
462 ret = ide_error(drive, "dma timeout error", in ide_dma_timeout_retry()
463 hwif->tp_ops->read_status(hwif)); in ide_dma_timeout_retry()
465 printk(KERN_WARNING "%s: DMA timeout retry\n", drive->name); in ide_dma_timeout_retry()
466 if (dma_ops->dma_clear) in ide_dma_timeout_retry()
467 dma_ops->dma_clear(drive); in ide_dma_timeout_retry()
468 printk(KERN_ERR "%s: timeout waiting for DMA\n", drive->name); in ide_dma_timeout_retry()
469 if (dma_ops->dma_test_irq(drive) == 0) { in ide_dma_timeout_retry()
470 ide_dump_status(drive, "DMA timeout", in ide_dma_timeout_retry()
471 hwif->tp_ops->read_status(hwif)); in ide_dma_timeout_retry()
472 drive->waiting_for_dma = 0; in ide_dma_timeout_retry()
473 (void)dma_ops->dma_end(drive); in ide_dma_timeout_retry()
474 ide_dma_unmap_sg(drive, cmd); in ide_dma_timeout_retry()
480 * a timeout -- we'll reenable after we finish this next request in ide_dma_timeout_retry()
483 drive->dev_flags |= IDE_DFLAG_DMA_PIO_RETRY; in ide_dma_timeout_retry()
484 drive->retry_pio++; in ide_dma_timeout_retry()
485 ide_dma_off_quietly(drive); in ide_dma_timeout_retry()
490 if (hwif->rq) in ide_dma_timeout_retry()
491 scsi_req(hwif->rq)->result = 0; in ide_dma_timeout_retry()
497 if (hwif->dmatable_cpu) { in ide_release_dma_engine()
498 int prd_size = hwif->prd_max_nents * hwif->prd_ent_size; in ide_release_dma_engine()
500 dma_free_coherent(hwif->dev, prd_size, in ide_release_dma_engine()
501 hwif->dmatable_cpu, hwif->dmatable_dma); in ide_release_dma_engine()
502 hwif->dmatable_cpu = NULL; in ide_release_dma_engine()
511 if (hwif->prd_max_nents == 0) in ide_allocate_dma_engine()
512 hwif->prd_max_nents = PRD_ENTRIES; in ide_allocate_dma_engine()
513 if (hwif->prd_ent_size == 0) in ide_allocate_dma_engine()
514 hwif->prd_ent_size = PRD_BYTES; in ide_allocate_dma_engine()
516 prd_size = hwif->prd_max_nents * hwif->prd_ent_size; in ide_allocate_dma_engine()
518 hwif->dmatable_cpu = dma_alloc_coherent(hwif->dev, prd_size, in ide_allocate_dma_engine()
519 &hwif->dmatable_dma, in ide_allocate_dma_engine()
521 if (hwif->dmatable_cpu == NULL) { in ide_allocate_dma_engine()
523 hwif->name); in ide_allocate_dma_engine()
524 return -ENOMEM; in ide_allocate_dma_engine()
531 int ide_dma_prepare(ide_drive_t *drive, struct ide_cmd *cmd) in ide_dma_prepare() argument
533 const struct ide_dma_ops *dma_ops = drive->hwif->dma_ops; in ide_dma_prepare()
535 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0 || in ide_dma_prepare()
536 (dma_ops->dma_check && dma_ops->dma_check(drive, cmd))) in ide_dma_prepare()
538 ide_map_sg(drive, cmd); in ide_dma_prepare()
539 if (ide_dma_map_sg(drive, cmd) == 0) in ide_dma_prepare()
541 if (dma_ops->dma_setup(drive, cmd)) in ide_dma_prepare()
543 drive->waiting_for_dma = 1; in ide_dma_prepare()
546 ide_dma_unmap_sg(drive, cmd); in ide_dma_prepare()
548 ide_map_sg(drive, cmd); in ide_dma_prepare()