Skip to content

Commit e6830a8

Browse files
committed
ide: call ide_build_sglist() prior to ->dma_setup (v2)
* Re-map sg table if needed in ide_build_sglist(). * Move ide_build_sglist() call from ->dma_setup to its users. * Un-export ide_build_sglist(). v2: * Build fix for CONFIG_BLK_DEV_IDEDMA=n (noticed by Randy Dunlap). There should be no functional changes caused by this patch. Cc: Randy Dunlap <randy.dunlap@oracle.com> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
1 parent b109f52 commit e6830a8

10 files changed

Lines changed: 24 additions & 41 deletions

File tree

‎drivers/ide/au1xxx-ide.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,16 @@ static void auide_set_dma_mode(ide_drive_t *drive, const u8 speed)
211211
#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
212212
static int auide_build_dmatable(ide_drive_t *drive)
213213
{
214-
int i, iswrite, count = 0;
215214
ide_hwif_t *hwif = drive->hwif;
216215
struct request *rq = hwif->rq;
217216
_auide_hwif *ahwif = &auide_hwif;
218217
struct scatterlist *sg;
218+
int i = hwif->sg_nents, iswrite, count = 0;
219219

220220
iswrite = (rq_data_dir(rq) == WRITE);
221221
/* Save for interrupt context */
222222
ahwif->drive = drive;
223223

224-
hwif->sg_nents = i = ide_build_sglist(drive, rq);
225-
226-
if (!i)
227-
return 0;
228-
229224
/* fill the descriptors */
230225
sg = hwif->sg_table;
231226
while (i && sg_dma_len(sg)) {

‎drivers/ide/icside.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,6 @@ static int icside_dma_setup(ide_drive_t *drive)
325325
*/
326326
BUG_ON(dma_channel_active(ec->dma));
327327

328-
hwif->sg_nents = ide_build_sglist(drive, rq);
329-
if (hwif->sg_nents == 0) {
330-
ide_map_sg(drive, rq);
331-
return 1;
332-
}
333-
334328
/*
335329
* Ensure that we have the right interrupt routed.
336330
*/

‎drivers/ide/ide-atapi.c‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,18 +631,23 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive)
631631
struct ide_atapi_pc *pc;
632632
ide_hwif_t *hwif = drive->hwif;
633633
ide_expiry_t *expiry = NULL;
634+
struct request *rq = hwif->rq;
634635
unsigned int timeout;
635636
u32 tf_flags;
636637
u16 bcount;
637638

638639
if (dev_is_idecd(drive)) {
639640
tf_flags = IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL;
640-
bcount = ide_cd_get_xferlen(hwif->rq);
641+
bcount = ide_cd_get_xferlen(rq);
641642
expiry = ide_cd_expiry;
642643
timeout = ATAPI_WAIT_PC;
643644

644-
if (drive->dma)
645-
drive->dma = !hwif->dma_ops->dma_setup(drive);
645+
if (drive->dma) {
646+
if (ide_build_sglist(drive, rq))
647+
drive->dma = !hwif->dma_ops->dma_setup(drive);
648+
else
649+
drive->dma = 0;
650+
}
646651
} else {
647652
pc = drive->pc;
648653

@@ -661,8 +666,12 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive)
661666
}
662667

663668
if ((pc->flags & PC_FLAG_DMA_OK) &&
664-
(drive->dev_flags & IDE_DFLAG_USING_DMA))
665-
drive->dma = !hwif->dma_ops->dma_setup(drive);
669+
(drive->dev_flags & IDE_DFLAG_USING_DMA)) {
670+
if (ide_build_sglist(drive, rq))
671+
drive->dma = !hwif->dma_ops->dma_setup(drive);
672+
else
673+
drive->dma = 0;
674+
}
666675

667676
if (!drive->dma)
668677
pc->flags &= ~PC_FLAG_DMA_OK;

‎drivers/ide/ide-dma-sff.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ int ide_build_dmatable(ide_drive_t *drive, struct request *rq)
120120
struct scatterlist *sg;
121121
u8 is_trm290 = !!(hwif->host_flags & IDE_HFLAG_TRM290);
122122

123-
hwif->sg_nents = ide_build_sglist(drive, rq);
124-
if (hwif->sg_nents == 0)
125-
return 0;
126-
127123
for_each_sg(hwif->sg_table, sg, hwif->sg_nents, i) {
128124
u32 cur_addr, cur_len, xcount, bcount;
129125

‎drivers/ide/ide-dma.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,15 @@ int ide_build_sglist(ide_drive_t *drive, struct request *rq)
138138
hwif->sg_dma_direction = DMA_TO_DEVICE;
139139

140140
i = dma_map_sg(hwif->dev, sg, hwif->sg_nents, hwif->sg_dma_direction);
141-
if (i) {
141+
if (i == 0)
142+
ide_map_sg(drive, rq);
143+
else {
142144
hwif->orig_sg_nents = hwif->sg_nents;
143145
hwif->sg_nents = i;
144146
}
145147

146148
return i;
147149
}
148-
EXPORT_SYMBOL_GPL(ide_build_sglist);
149150

150151
/**
151152
* ide_destroy_dmatable - clean up DMA mapping

‎drivers/ide/ide-taskfile.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
103103
return ide_started;
104104
default:
105105
if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0 ||
106+
ide_build_sglist(drive, hwif->rq) == 0 ||
106107
dma_ops->dma_setup(drive))
107108
return ide_stopped;
108109
dma_ops->dma_exec_cmd(drive, tf->command);

‎drivers/ide/pmac.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,10 +1429,10 @@ pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq)
14291429
pmac_ide_hwif_t *pmif =
14301430
(pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
14311431
struct dbdma_cmd *table;
1432-
int i, count = 0;
14331432
volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
14341433
struct scatterlist *sg;
14351434
int wr = (rq_data_dir(rq) == WRITE);
1435+
int i = hwif->sg_nents, count = 0;
14361436

14371437
/* DMA table is already aligned */
14381438
table = (struct dbdma_cmd *) pmif->dma_table_cpu;
@@ -1442,11 +1442,6 @@ pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq)
14421442
while (readl(&dma->status) & RUN)
14431443
udelay(1);
14441444

1445-
hwif->sg_nents = i = ide_build_sglist(drive, rq);
1446-
1447-
if (!i)
1448-
return 0;
1449-
14501445
/* Build DBDMA commands list */
14511446
sg = hwif->sg_table;
14521447
while (i && sg_dma_len(sg)) {

‎drivers/ide/sgiioc4.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,9 @@ sgiioc4_build_dma_table(ide_drive_t * drive, struct request *rq, int ddir)
429429
{
430430
ide_hwif_t *hwif = drive->hwif;
431431
unsigned int *table = hwif->dmatable_cpu;
432-
unsigned int count = 0, i = 1;
433-
struct scatterlist *sg;
432+
unsigned int count = 0, i = hwif->sg_nents;
433+
struct scatterlist *sg = hwif->sg_table;
434434

435-
hwif->sg_nents = i = ide_build_sglist(drive, rq);
436-
437-
if (!i)
438-
return 0; /* sglist of length Zero */
439-
440-
sg = hwif->sg_table;
441435
while (i && sg_dma_len(sg)) {
442436
dma_addr_t cur_addr;
443437
int cur_len;

‎drivers/ide/tx4939ide.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,6 @@ static int tx4939ide_build_dmatable(ide_drive_t *drive, struct request *rq)
240240
int i;
241241
struct scatterlist *sg;
242242

243-
hwif->sg_nents = ide_build_sglist(drive, rq);
244-
if (hwif->sg_nents == 0)
245-
return 0;
246-
247243
for_each_sg(hwif->sg_table, sg, hwif->sg_nents, i) {
248244
u32 cur_addr, cur_len, bcount;
249245

‎include/linux/ide.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,8 @@ static inline int ide_set_dma(ide_drive_t *drive) { return 1; }
14771477
static inline void ide_check_dma_crc(ide_drive_t *drive) { ; }
14781478
static inline ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error) { return ide_stopped; }
14791479
static inline void ide_release_dma_engine(ide_hwif_t *hwif) { ; }
1480+
static inline int ide_build_sglist(ide_drive_t *drive,
1481+
struct request *rq) { return 0; }
14801482
#endif /* CONFIG_BLK_DEV_IDEDMA */
14811483

14821484
#ifdef CONFIG_BLK_DEV_IDEACPI

0 commit comments

Comments
 (0)