Blame view
drivers/ide/ide-dma-sff.c
8.91 KB
457c89965 treewide: Add SPD... |
1 |
// SPDX-License-Identifier: GPL-2.0-only |
2dbe7e919 ide: move SFF DMA... |
2 3 |
#include <linux/types.h> #include <linux/kernel.h> |
38789fda2 ide/ata: Add expo... |
4 |
#include <linux/export.h> |
2dbe7e919 ide: move SFF DMA... |
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#include <linux/ide.h> #include <linux/scatterlist.h> #include <linux/dma-mapping.h> #include <linux/io.h> /** * config_drive_for_dma - attempt to activate IDE DMA * @drive: the drive to place in DMA mode * * If the drive supports at least mode 2 DMA or UDMA of any kind * then attempt to place it into DMA mode. Drives that are known to * support DMA but predate the DMA properties or that are known * to have DMA handling bugs are also set up appropriately based * on the good/bad drive lists. */ int config_drive_for_dma(ide_drive_t *drive) { ide_hwif_t *hwif = drive->hwif; u16 *id = drive->id; if (drive->media != ide_disk) { if (hwif->host_flags & IDE_HFLAG_NO_ATAPI_DMA) return 0; } /* * Enable DMA on any drive that has * UltraDMA (mode 0/1/2/3/4/5/6) enabled */ if ((id[ATA_ID_FIELD_VALID] & 4) && ((id[ATA_ID_UDMA_MODES] >> 8) & 0x7f)) return 1; /* * Enable DMA on any drive that has mode2 DMA * (multi or single) enabled */ |
8d64fcd93 ide: identify dat... |
43 44 45 |
if ((id[ATA_ID_MWDMA_MODES] & 0x404) == 0x404 || (id[ATA_ID_SWDMA_MODES] & 0x404) == 0x404) return 1; |
2dbe7e919 ide: move SFF DMA... |
46 47 48 49 50 51 52 |
/* Consult the list of known "good" drives */ if (ide_dma_good_drive(drive)) return 1; return 0; } |
592b53152 ide: move read_sf... |
53 54 55 56 57 58 59 60 61 62 |
u8 ide_dma_sff_read_status(ide_hwif_t *hwif) { unsigned long addr = hwif->dma_base + ATA_DMA_STATUS; if (hwif->host_flags & IDE_HFLAG_MMIO) return readb((void __iomem *)addr); else return inb(addr); } EXPORT_SYMBOL_GPL(ide_dma_sff_read_status); |
05789634e ide-dma-sff: fact... |
63 64 65 66 67 68 69 70 71 |
static void ide_dma_sff_write_status(ide_hwif_t *hwif, u8 val) { unsigned long addr = hwif->dma_base + ATA_DMA_STATUS; if (hwif->host_flags & IDE_HFLAG_MMIO) writeb(val, (void __iomem *)addr); else outb(val, addr); } |
2dbe7e919 ide: move SFF DMA... |
72 73 74 75 76 77 78 79 80 81 82 83 |
/** * ide_dma_host_set - Enable/disable DMA on a host * @drive: drive to control * * Enable/disable DMA on an IDE controller following generic * bus-mastering IDE controller behaviour. */ void ide_dma_host_set(ide_drive_t *drive, int on) { ide_hwif_t *hwif = drive->hwif; u8 unit = drive->dn & 1; |
592b53152 ide: move read_sf... |
84 |
u8 dma_stat = hwif->dma_ops->dma_sff_read_status(hwif); |
2dbe7e919 ide: move SFF DMA... |
85 86 87 88 89 |
if (on) dma_stat |= (1 << (5 + unit)); else dma_stat &= ~(1 << (5 + unit)); |
05789634e ide-dma-sff: fact... |
90 |
ide_dma_sff_write_status(hwif, dma_stat); |
2dbe7e919 ide: move SFF DMA... |
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
} EXPORT_SYMBOL_GPL(ide_dma_host_set); /** * ide_build_dmatable - build IDE DMA table * * ide_build_dmatable() prepares a dma request. We map the command * to get the pci bus addresses of the buffers and then build up * the PRD table that the IDE layer wants to be fed. * * Most chipsets correctly interpret a length of 0x0000 as 64KB, * but at least one (e.g. CS5530) misinterprets it as zero (!). * So we break the 64KB entry into two 32KB entries instead. * * Returns the number of built PRD entries if all went okay, * returns 0 otherwise. * * May also be invoked from trm290.c */ |
229816941 ide: pass command... |
110 |
int ide_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd) |
2dbe7e919 ide: move SFF DMA... |
111 112 113 |
{ ide_hwif_t *hwif = drive->hwif; __le32 *table = (__le32 *)hwif->dmatable_cpu; |
2dbe7e919 ide: move SFF DMA... |
114 115 116 |
unsigned int count = 0; int i; struct scatterlist *sg; |
1f66019bd trm290: add IDE_H... |
117 |
u8 is_trm290 = !!(hwif->host_flags & IDE_HFLAG_TRM290); |
2dbe7e919 ide: move SFF DMA... |
118 |
|
229816941 ide: pass command... |
119 |
for_each_sg(hwif->sg_table, sg, cmd->sg_nents, i) { |
2dbe7e919 ide: move SFF DMA... |
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
u32 cur_addr, cur_len, xcount, bcount; cur_addr = sg_dma_address(sg); cur_len = sg_dma_len(sg); /* * Fill in the dma table, without crossing any 64kB boundaries. * Most hardware requires 16-bit alignment of all blocks, * but the trm290 requires 32-bit alignment. */ while (cur_len) { if (count++ >= PRD_ENTRIES) goto use_pio_instead; bcount = 0x10000 - (cur_addr & 0xffff); if (bcount > cur_len) bcount = cur_len; *table++ = cpu_to_le32(cur_addr); xcount = bcount & 0xffff; if (is_trm290) xcount = ((xcount >> 2) - 1) << 16; |
769b49ce6 ide: re-add TRM29... |
142 |
else if (xcount == 0x0000) { |
2dbe7e919 ide: move SFF DMA... |
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
if (count++ >= PRD_ENTRIES) goto use_pio_instead; *table++ = cpu_to_le32(0x8000); *table++ = cpu_to_le32(cur_addr + 0x8000); xcount = 0x8000; } *table++ = cpu_to_le32(xcount); cur_addr += bcount; cur_len -= bcount; } } if (count) { if (!is_trm290) *--table |= cpu_to_le32(0x80000000); return count; } use_pio_instead: printk(KERN_ERR "%s: %s ", drive->name, count ? "DMA table too small" : "empty DMA table?"); |
2dbe7e919 ide: move SFF DMA... |
165 166 167 168 169 170 171 |
return 0; /* revert to PIO for this request */ } EXPORT_SYMBOL_GPL(ide_build_dmatable); /** * ide_dma_setup - begin a DMA phase * @drive: target device |
229816941 ide: pass command... |
172 |
* @cmd: command |
2dbe7e919 ide: move SFF DMA... |
173 174 175 176 177 178 179 180 181 |
* * Build an IDE DMA PRD (IDE speak for scatter gather table) * and then set up the DMA transfer registers for a device * that follows generic IDE PCI DMA behaviour. Controllers can * override this function if they need to * * Returns 0 on success. If a PIO fallback is required then 1 * is returned. */ |
229816941 ide: pass command... |
182 |
int ide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd) |
2dbe7e919 ide: move SFF DMA... |
183 184 |
{ ide_hwif_t *hwif = drive->hwif; |
2dbe7e919 ide: move SFF DMA... |
185 |
u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; |
229816941 ide: pass command... |
186 |
u8 rw = (cmd->tf_flags & IDE_TFLAG_WRITE) ? 0 : ATA_DMA_WR; |
2dbe7e919 ide: move SFF DMA... |
187 |
u8 dma_stat; |
2dbe7e919 ide: move SFF DMA... |
188 |
/* fall back to pio! */ |
229816941 ide: pass command... |
189 190 |
if (ide_build_dmatable(drive, cmd) == 0) { ide_map_sg(drive, cmd); |
2dbe7e919 ide: move SFF DMA... |
191 192 193 194 |
return 1; } /* PRD table */ |
05789634e ide-dma-sff: fact... |
195 |
if (mmio) |
2dbe7e919 ide: move SFF DMA... |
196 197 198 199 200 201 202 |
writel(hwif->dmatable_dma, (void __iomem *)(hwif->dma_base + ATA_DMA_TABLE_OFS)); else outl(hwif->dmatable_dma, hwif->dma_base + ATA_DMA_TABLE_OFS); /* specify r/w */ if (mmio) |
229816941 ide: pass command... |
203 |
writeb(rw, (void __iomem *)(hwif->dma_base + ATA_DMA_CMD)); |
2dbe7e919 ide: move SFF DMA... |
204 |
else |
229816941 ide: pass command... |
205 |
outb(rw, hwif->dma_base + ATA_DMA_CMD); |
2dbe7e919 ide: move SFF DMA... |
206 207 |
/* read DMA status for INTR & ERROR flags */ |
592b53152 ide: move read_sf... |
208 |
dma_stat = hwif->dma_ops->dma_sff_read_status(hwif); |
2dbe7e919 ide: move SFF DMA... |
209 210 |
/* clear INTR & ERROR flags */ |
05789634e ide-dma-sff: fact... |
211 |
ide_dma_sff_write_status(hwif, dma_stat | ATA_DMA_ERR | ATA_DMA_INTR); |
2dbe7e919 ide: move SFF DMA... |
212 |
|
2dbe7e919 ide: move SFF DMA... |
213 214 215 216 217 |
return 0; } EXPORT_SYMBOL_GPL(ide_dma_setup); /** |
22117d6ea ide: add ->dma_ti... |
218 |
* ide_dma_sff_timer_expiry - handle a DMA timeout |
2dbe7e919 ide: move SFF DMA... |
219 220 221 222 223 224 225 226 227 228 229 |
* @drive: Drive that timed out * * An IDE DMA transfer timed out. In the event of an error we ask * the driver to resolve the problem, if a DMA transfer is still * in progress we continue to wait (arguably we need to add a * secondary 'I don't care what the drive thinks' timeout here) * Finally if we have an interrupt we let it complete the I/O. * But only one time - we clear expiry and if it's still not * completed after WAIT_CMD, we error and retry in PIO. * This can occur if an interrupt is lost or due to hang or bugs. */ |
22117d6ea ide: add ->dma_ti... |
230 |
int ide_dma_sff_timer_expiry(ide_drive_t *drive) |
2dbe7e919 ide: move SFF DMA... |
231 232 |
{ ide_hwif_t *hwif = drive->hwif; |
592b53152 ide: move read_sf... |
233 |
u8 dma_stat = hwif->dma_ops->dma_sff_read_status(hwif); |
2dbe7e919 ide: move SFF DMA... |
234 235 236 237 238 239 240 |
printk(KERN_WARNING "%s: %s: DMA status (0x%02x) ", drive->name, __func__, dma_stat); if ((dma_stat & 0x18) == 0x18) /* BUSY Stupid Early Timer !! */ return WAIT_CMD; |
b65fac32c ide: merge ide_hw... |
241 |
hwif->expiry = NULL; /* one free ride for now */ |
2dbe7e919 ide: move SFF DMA... |
242 |
|
1d35364ac ide: use ATA_DMA_... |
243 |
if (dma_stat & ATA_DMA_ERR) /* ERROR */ |
2dbe7e919 ide: move SFF DMA... |
244 |
return -1; |
1d35364ac ide: use ATA_DMA_... |
245 |
if (dma_stat & ATA_DMA_ACTIVE) /* DMAing */ |
2dbe7e919 ide: move SFF DMA... |
246 |
return WAIT_CMD; |
1d35364ac ide: use ATA_DMA_... |
247 |
if (dma_stat & ATA_DMA_INTR) /* Got an Interrupt */ |
2dbe7e919 ide: move SFF DMA... |
248 249 250 251 |
return WAIT_CMD; return 0; /* Status is unknown -- reset the bus */ } |
22117d6ea ide: add ->dma_ti... |
252 |
EXPORT_SYMBOL_GPL(ide_dma_sff_timer_expiry); |
2dbe7e919 ide: move SFF DMA... |
253 254 255 256 257 258 259 260 261 262 263 264 265 |
void ide_dma_start(ide_drive_t *drive) { ide_hwif_t *hwif = drive->hwif; u8 dma_cmd; /* Note that this is done *after* the cmd has * been issued to the drive, as per the BM-IDE spec. * The Promise Ultra33 doesn't work correctly when * we do this part before issuing the drive cmd. */ if (hwif->host_flags & IDE_HFLAG_MMIO) { dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD)); |
1d35364ac ide: use ATA_DMA_... |
266 |
writeb(dma_cmd | ATA_DMA_START, |
2dbe7e919 ide: move SFF DMA... |
267 268 269 |
(void __iomem *)(hwif->dma_base + ATA_DMA_CMD)); } else { dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD); |
1d35364ac ide: use ATA_DMA_... |
270 |
outb(dma_cmd | ATA_DMA_START, hwif->dma_base + ATA_DMA_CMD); |
2dbe7e919 ide: move SFF DMA... |
271 |
} |
2dbe7e919 ide: move SFF DMA... |
272 273 274 275 276 277 278 |
} EXPORT_SYMBOL_GPL(ide_dma_start); /* returns 1 on error, 0 otherwise */ int ide_dma_end(ide_drive_t *drive) { ide_hwif_t *hwif = drive->hwif; |
edafcf73d ide: remove wmb()... |
279 |
u8 dma_stat = 0, dma_cmd = 0; |
2dbe7e919 ide: move SFF DMA... |
280 |
|
1d35364ac ide: use ATA_DMA_... |
281 |
/* stop DMA */ |
05789634e ide-dma-sff: fact... |
282 |
if (hwif->host_flags & IDE_HFLAG_MMIO) { |
2dbe7e919 ide: move SFF DMA... |
283 |
dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD)); |
1d35364ac ide: use ATA_DMA_... |
284 |
writeb(dma_cmd & ~ATA_DMA_START, |
2dbe7e919 ide: move SFF DMA... |
285 286 287 |
(void __iomem *)(hwif->dma_base + ATA_DMA_CMD)); } else { dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD); |
1d35364ac ide: use ATA_DMA_... |
288 |
outb(dma_cmd & ~ATA_DMA_START, hwif->dma_base + ATA_DMA_CMD); |
2dbe7e919 ide: move SFF DMA... |
289 290 291 |
} /* get DMA status */ |
592b53152 ide: move read_sf... |
292 |
dma_stat = hwif->dma_ops->dma_sff_read_status(hwif); |
2dbe7e919 ide: move SFF DMA... |
293 |
|
05789634e ide-dma-sff: fact... |
294 295 |
/* clear INTR & ERROR bits */ ide_dma_sff_write_status(hwif, dma_stat | ATA_DMA_ERR | ATA_DMA_INTR); |
2dbe7e919 ide: move SFF DMA... |
296 |
|
edafcf73d ide: remove wmb()... |
297 |
#define CHECK_DMA_MASK (ATA_DMA_ACTIVE | ATA_DMA_ERR | ATA_DMA_INTR) |
1d35364ac ide: use ATA_DMA_... |
298 299 |
/* verify good DMA status */ |
edafcf73d ide: remove wmb()... |
300 |
if ((dma_stat & CHECK_DMA_MASK) != ATA_DMA_INTR) |
1d35364ac ide: use ATA_DMA_... |
301 302 |
return 0x10 | dma_stat; return 0; |
2dbe7e919 ide: move SFF DMA... |
303 304 305 306 307 308 309 |
} EXPORT_SYMBOL_GPL(ide_dma_end); /* returns 1 if dma irq issued, 0 otherwise */ int ide_dma_test_irq(ide_drive_t *drive) { ide_hwif_t *hwif = drive->hwif; |
592b53152 ide: move read_sf... |
310 |
u8 dma_stat = hwif->dma_ops->dma_sff_read_status(hwif); |
2dbe7e919 ide: move SFF DMA... |
311 |
|
1d35364ac ide: use ATA_DMA_... |
312 |
return (dma_stat & ATA_DMA_INTR) ? 1 : 0; |
2dbe7e919 ide: move SFF DMA... |
313 314 315 316 317 318 |
} EXPORT_SYMBOL_GPL(ide_dma_test_irq); const struct ide_dma_ops sff_dma_ops = { .dma_host_set = ide_dma_host_set, .dma_setup = ide_dma_setup, |
2dbe7e919 ide: move SFF DMA... |
319 320 321 |
.dma_start = ide_dma_start, .dma_end = ide_dma_end, .dma_test_irq = ide_dma_test_irq, |
2dbe7e919 ide: move SFF DMA... |
322 |
.dma_lost_irq = ide_dma_lost_irq, |
35c9b4daf ide: add ->dma_cl... |
323 |
.dma_timer_expiry = ide_dma_sff_timer_expiry, |
592b53152 ide: move read_sf... |
324 |
.dma_sff_read_status = ide_dma_sff_read_status, |
2dbe7e919 ide: move SFF DMA... |
325 326 |
}; EXPORT_SYMBOL_GPL(sff_dma_ops); |