aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-05 22:06:25 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-05 22:06:25 -0500
commit551e4fb2465b87de9d4aa1669b27d624435443bb (patch)
tree316a5816b833a7536071a4ee0913a9b51b4faff8
parentb297d520b9af536d5580ac505dd316be4cf5560c (diff)
parentdfe799364e7a500389559e1dcd331d995cdc18ea (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6: (29 commits) ide-tape: bump minor driver version ide-tape: cleanup the remaining codestyle issues ide-tape: fix syntax error in idetape_identify_device() ide-tape: remove leftover OnStream support warning ide-tape: collect module-related macro calls at the end ide-tape: include proper headers ide-tape: remove unused "length" arg from idetape_create_read_buffer_cmd() ide-tape: remove struct idetape_id_gcw ide-tape: cleanup and fix comments ide-tape: shorten some function names ide-tape: remove idetape_increase_max_pipeline_stages() ide-tape: struct idetape_tape_t: shorten member names v2 ide-tape: struct idetape_tape_t: remove unused members ide-tape: remove typedef idetape_chrdev_direction_t ide-tape: simplify code branching in the interrupt handler ide-tape: remove unreachable code chunk ide-tape: remove struct idetape_read_position_result_t ide-tape: refactor the debug logging facility ide: add ide_read_error() inline helper ide: add ide_read_[alt]status() inline helpers ...
-rw-r--r--Documentation/kernel-parameters.txt3
-rw-r--r--drivers/ide/Kconfig9
-rw-r--r--drivers/ide/arm/Makefile1
-rw-r--r--drivers/ide/arm/icside.c2
-rw-r--r--drivers/ide/arm/palm_bk3710.c395
-rw-r--r--drivers/ide/cris/ide-cris.c33
-rw-r--r--drivers/ide/ide-acpi.c2
-rw-r--r--drivers/ide/ide-cd.c9
-rw-r--r--drivers/ide/ide-dma.c3
-rw-r--r--drivers/ide/ide-floppy.c6
-rw-r--r--drivers/ide/ide-generic.c10
-rw-r--r--drivers/ide/ide-io.c14
-rw-r--r--drivers/ide/ide-iops.c45
-rw-r--r--drivers/ide/ide-lib.c2
-rw-r--r--drivers/ide/ide-probe.c47
-rw-r--r--drivers/ide/ide-proc.c1
-rw-r--r--drivers/ide/ide-tape.c2400
-rw-r--r--drivers/ide/ide-taskfile.c35
-rw-r--r--drivers/ide/ide.c54
-rw-r--r--drivers/ide/legacy/buddha.c72
-rw-r--r--drivers/ide/legacy/falconide.c42
-rw-r--r--drivers/ide/legacy/gayle.c39
-rw-r--r--drivers/ide/legacy/hd.c9
-rw-r--r--drivers/ide/legacy/macide.c57
-rw-r--r--drivers/ide/legacy/q40ide.c9
-rw-r--r--drivers/ide/pci/Makefile3
-rw-r--r--drivers/ide/pci/generic.c13
-rw-r--r--drivers/ide/pci/siimage.c3
-rw-r--r--drivers/macintosh/mediabay.c46
-rw-r--r--drivers/scsi/ide-scsi.c4
-rw-r--r--include/asm-powerpc/mediabay.h8
-rw-r--r--include/linux/ide.h42
32 files changed, 1825 insertions, 1593 deletions
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 9ad4e6fc56fd..8fd5aa40585f 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -780,6 +780,9 @@ and is between 256 and 4096 characters. It is defined in the file
780 loop use the MONITOR/MWAIT idle loop anyways. Performance should be the same 780 loop use the MONITOR/MWAIT idle loop anyways. Performance should be the same
781 as idle=poll. 781 as idle=poll.
782 782
783 ide-pci-generic.all-generic-ide [HW] (E)IDE subsystem
784 Claim all unknown PCI IDE storage controllers.
785
783 ignore_loglevel [KNL] 786 ignore_loglevel [KNL]
784 Ignore loglevel setting - this will print /all/ 787 Ignore loglevel setting - this will print /all/
785 kernel messages to the console. Useful for debugging. 788 kernel messages to the console. Useful for debugging.
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index 45b26ed351cf..ab8fb257528e 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -1009,6 +1009,15 @@ config BLK_DEV_Q40IDE
1009 normally be on; disable it only if you are running a custom hard 1009 normally be on; disable it only if you are running a custom hard
1010 drive subsystem through an expansion card. 1010 drive subsystem through an expansion card.
1011 1011
1012config BLK_DEV_PALMCHIP_BK3710
1013 tristate "Palmchip bk3710 IDE controller support"
1014 depends on ARCH_DAVINCI
1015 select BLK_DEV_IDEDMA_PCI
1016 help
1017 Say Y here if you want to support the onchip IDE controller on the
1018 TI DaVinci SoC
1019
1020
1012config BLK_DEV_MPC8xx_IDE 1021config BLK_DEV_MPC8xx_IDE
1013 tristate "MPC8xx IDE support" 1022 tristate "MPC8xx IDE support"
1014 depends on 8xx && (LWMON || IVMS8 || IVML24 || TQM8xxL) && IDE=y && BLK_DEV_IDE=y && !PPC_MERGE 1023 depends on 8xx && (LWMON || IVMS8 || IVML24 || TQM8xxL) && IDE=y && BLK_DEV_IDE=y && !PPC_MERGE
diff --git a/drivers/ide/arm/Makefile b/drivers/ide/arm/Makefile
index 5f63ad216862..936e7b0237f5 100644
--- a/drivers/ide/arm/Makefile
+++ b/drivers/ide/arm/Makefile
@@ -2,6 +2,7 @@
2obj-$(CONFIG_BLK_DEV_IDE_ICSIDE) += icside.o 2obj-$(CONFIG_BLK_DEV_IDE_ICSIDE) += icside.o
3obj-$(CONFIG_BLK_DEV_IDE_RAPIDE) += rapide.o 3obj-$(CONFIG_BLK_DEV_IDE_RAPIDE) += rapide.o
4obj-$(CONFIG_BLK_DEV_IDE_BAST) += bast-ide.o 4obj-$(CONFIG_BLK_DEV_IDE_BAST) += bast-ide.o
5obj-$(CONFIG_BLK_DEV_PALMCHIP_BK3710) += palm_bk3710.o
5 6
6ifeq ($(CONFIG_IDE_ARM), m) 7ifeq ($(CONFIG_IDE_ARM), m)
7 obj-m += ide_arm.o 8 obj-m += ide_arm.o
diff --git a/drivers/ide/arm/icside.c b/drivers/ide/arm/icside.c
index fb00f3827ecd..e816b0ffcfe6 100644
--- a/drivers/ide/arm/icside.c
+++ b/drivers/ide/arm/icside.c
@@ -365,7 +365,7 @@ static void icside_dma_timeout(ide_drive_t *drive)
365 if (icside_dma_test_irq(drive)) 365 if (icside_dma_test_irq(drive))
366 return; 366 return;
367 367
368 ide_dump_status(drive, "DMA timeout", HWIF(drive)->INB(IDE_STATUS_REG)); 368 ide_dump_status(drive, "DMA timeout", ide_read_status(drive));
369 369
370 icside_dma_end(drive); 370 icside_dma_end(drive);
371} 371}
diff --git a/drivers/ide/arm/palm_bk3710.c b/drivers/ide/arm/palm_bk3710.c
new file mode 100644
index 000000000000..c3069970a012
--- /dev/null
+++ b/drivers/ide/arm/palm_bk3710.c
@@ -0,0 +1,395 @@
1/*
2 * Palmchip bk3710 IDE controller
3 *
4 * Copyright (C) 2006 Texas Instruments.
5 * Copyright (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * ----------------------------------------------------------------------------
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * ----------------------------------------------------------------------------
23 *
24 */
25
26#include <linux/types.h>
27#include <linux/module.h>
28#include <linux/kernel.h>
29#include <linux/ioport.h>
30#include <linux/hdreg.h>
31#include <linux/ide.h>
32#include <linux/delay.h>
33#include <linux/init.h>
34#include <linux/clk.h>
35#include <linux/platform_device.h>
36
37/* Offset of the primary interface registers */
38#define IDE_PALM_ATA_PRI_REG_OFFSET 0x1F0
39
40/* Primary Control Offset */
41#define IDE_PALM_ATA_PRI_CTL_OFFSET 0x3F6
42
43/*
44 * PalmChip 3710 IDE Controller UDMA timing structure Definition
45 */
46struct palm_bk3710_udmatiming {
47 unsigned int rptime; /* Ready to pause time */
48 unsigned int cycletime; /* Cycle Time */
49};
50
51#define BK3710_BMICP 0x00
52#define BK3710_BMISP 0x02
53#define BK3710_BMIDTP 0x04
54#define BK3710_BMICS 0x08
55#define BK3710_BMISS 0x0A
56#define BK3710_BMIDTS 0x0C
57#define BK3710_IDETIMP 0x40
58#define BK3710_IDETIMS 0x42
59#define BK3710_SIDETIM 0x44
60#define BK3710_SLEWCTL 0x45
61#define BK3710_IDESTATUS 0x47
62#define BK3710_UDMACTL 0x48
63#define BK3710_UDMATIM 0x4A
64#define BK3710_MISCCTL 0x50
65#define BK3710_REGSTB 0x54
66#define BK3710_REGRCVR 0x58
67#define BK3710_DATSTB 0x5C
68#define BK3710_DATRCVR 0x60
69#define BK3710_DMASTB 0x64
70#define BK3710_DMARCVR 0x68
71#define BK3710_UDMASTB 0x6C
72#define BK3710_UDMATRP 0x70
73#define BK3710_UDMAENV 0x74
74#define BK3710_IORDYTMP 0x78
75#define BK3710_IORDYTMS 0x7C
76
77#include "../ide-timing.h"
78
79static long ide_palm_clk;
80
81static const struct palm_bk3710_udmatiming palm_bk3710_udmatimings[6] = {
82 {160, 240}, /* UDMA Mode 0 */
83 {125, 160}, /* UDMA Mode 1 */
84 {100, 120}, /* UDMA Mode 2 */
85 {100, 90}, /* UDMA Mode 3 */
86 {85, 60}, /* UDMA Mode 4 */
87};
88
89static struct clk *ideclkp;
90
91static void palm_bk3710_setudmamode(void __iomem *base, unsigned int dev,
92 unsigned int mode)
93{
94 u8 tenv, trp, t0;
95 u32 val32;
96 u16 val16;
97
98 /* DMA Data Setup */
99 t0 = (palm_bk3710_udmatimings[mode].cycletime + ide_palm_clk - 1)
100 / ide_palm_clk - 1;
101 tenv = (20 + ide_palm_clk - 1) / ide_palm_clk - 1;
102 trp = (palm_bk3710_udmatimings[mode].rptime + ide_palm_clk - 1)
103 / ide_palm_clk - 1;
104
105 /* udmatim Register */
106 val16 = readw(base + BK3710_UDMATIM) & (dev ? 0xFF0F : 0xFFF0);
107 val16 |= (mode << (dev ? 4 : 0));
108 writew(val16, base + BK3710_UDMATIM);
109
110 /* udmastb Ultra DMA Access Strobe Width */
111 val32 = readl(base + BK3710_UDMASTB) & (0xFF << (dev ? 0 : 8));
112 val32 |= (t0 << (dev ? 8 : 0));
113 writel(val32, base + BK3710_UDMASTB);
114
115 /* udmatrp Ultra DMA Ready to Pause Time */
116 val32 = readl(base + BK3710_UDMATRP) & (0xFF << (dev ? 0 : 8));
117 val32 |= (trp << (dev ? 8 : 0));
118 writel(val32, base + BK3710_UDMATRP);
119
120 /* udmaenv Ultra DMA envelop Time */
121 val32 = readl(base + BK3710_UDMAENV) & (0xFF << (dev ? 0 : 8));
122 val32 |= (tenv << (dev ? 8 : 0));
123 writel(val32, base + BK3710_UDMAENV);
124
125 /* Enable UDMA for Device */
126 val16 = readw(base + BK3710_UDMACTL) | (1 << dev);
127 writew(val16, base + BK3710_UDMACTL);
128}
129
130static void palm_bk3710_setdmamode(void __iomem *base, unsigned int dev,
131 unsigned short min_cycle,
132 unsigned int mode)
133{
134 u8 td, tkw, t0;
135 u32 val32;
136 u16 val16;
137 struct ide_timing *t;
138 int cycletime;
139
140 t = ide_timing_find_mode(mode);
141 cycletime = max_t(int, t->cycle, min_cycle);
142
143 /* DMA Data Setup */
144 t0 = (cycletime + ide_palm_clk - 1) / ide_palm_clk;
145 td = (t->active + ide_palm_clk - 1) / ide_palm_clk;
146 tkw = t0 - td - 1;
147 td -= 1;
148
149 val32 = readl(base + BK3710_DMASTB) & (0xFF << (dev ? 0 : 8));
150 val32 |= (td << (dev ? 8 : 0));
151 writel(val32, base + BK3710_DMASTB);
152
153 val32 = readl(base + BK3710_DMARCVR) & (0xFF << (dev ? 0 : 8));
154 val32 |= (tkw << (dev ? 8 : 0));
155 writel(val32, base + BK3710_DMARCVR);
156
157 /* Disable UDMA for Device */
158 val16 = readw(base + BK3710_UDMACTL) & ~(1 << dev);
159 writew(val16, base + BK3710_UDMACTL);
160}
161
162static void palm_bk3710_setpiomode(void __iomem *base, ide_drive_t *mate,
163 unsigned int dev, unsigned int cycletime,
164 unsigned int mode)
165{
166 u8 t2, t2i, t0;
167 u32 val32;
168 struct ide_timing *t;
169
170 /* PIO Data Setup */
171 t0 = (cycletime + ide_palm_clk - 1) / ide_palm_clk;
172 t2 = (ide_timing_find_mode(XFER_PIO_0 + mode)->active +
173 ide_palm_clk - 1) / ide_palm_clk;
174
175 t2i = t0 - t2 - 1;
176 t2 -= 1;
177
178 val32 = readl(base + BK3710_DATSTB) & (0xFF << (dev ? 0 : 8));
179 val32 |= (t2 << (dev ? 8 : 0));
180 writel(val32, base + BK3710_DATSTB);
181
182 val32 = readl(base + BK3710_DATRCVR) & (0xFF << (dev ? 0 : 8));
183 val32 |= (t2i << (dev ? 8 : 0));
184 writel(val32, base + BK3710_DATRCVR);
185
186 if (mate && mate->present) {
187 u8 mode2 = ide_get_best_pio_mode(mate, 255, 4);
188
189 if (mode2 < mode)
190 mode = mode2;
191 }
192
193 /* TASKFILE Setup */
194 t = ide_timing_find_mode(XFER_PIO_0 + mode);
195 t0 = (t->cyc8b + ide_palm_clk - 1) / ide_palm_clk;
196 t2 = (t->act8b + ide_palm_clk - 1) / ide_palm_clk;
197
198 t2i = t0 - t2 - 1;
199 t2 -= 1;
200
201 val32 = readl(base + BK3710_REGSTB) & (0xFF << (dev ? 0 : 8));
202 val32 |= (t2 << (dev ? 8 : 0));
203 writel(val32, base + BK3710_REGSTB);
204
205 val32 = readl(base + BK3710_REGRCVR) & (0xFF << (dev ? 0 : 8));
206 val32 |= (t2i << (dev ? 8 : 0));
207 writel(val32, base + BK3710_REGRCVR);
208}
209
210static void palm_bk3710_set_dma_mode(ide_drive_t *drive, u8 xferspeed)
211{
212 int is_slave = drive->dn & 1;
213 void __iomem *base = (void *)drive->hwif->dma_base;
214
215 if (xferspeed >= XFER_UDMA_0) {
216 palm_bk3710_setudmamode(base, is_slave,
217 xferspeed - XFER_UDMA_0);
218 } else {
219 palm_bk3710_setdmamode(base, is_slave, drive->id->eide_dma_min,
220 xferspeed);
221 }
222}
223
224static void palm_bk3710_set_pio_mode(ide_drive_t *drive, u8 pio)
225{
226 unsigned int cycle_time;
227 int is_slave = drive->dn & 1;
228 ide_drive_t *mate;
229 void __iomem *base = (void *)drive->hwif->dma_base;
230
231 /*
232 * Obtain the drive PIO data for tuning the Palm Chip registers
233 */
234 cycle_time = ide_pio_cycle_time(drive, pio);
235 mate = ide_get_paired_drive(drive);
236 palm_bk3710_setpiomode(base, mate, is_slave, cycle_time, pio);
237}
238
239static void __devinit palm_bk3710_chipinit(void __iomem *base)
240{
241 /*
242 * enable the reset_en of ATA controller so that when ata signals
243 * are brought out, by writing into device config. at that
244 * time por_n signal should not be 'Z' and have a stable value.
245 */
246 writel(0x0300, base + BK3710_MISCCTL);
247
248 /* wait for some time and deassert the reset of ATA Device. */
249 mdelay(100);
250
251 /* Deassert the Reset */
252 writel(0x0200, base + BK3710_MISCCTL);
253
254 /*
255 * Program the IDETIMP Register Value based on the following assumptions
256 *
257 * (ATA_IDETIMP_IDEEN , ENABLE ) |
258 * (ATA_IDETIMP_SLVTIMEN , DISABLE) |
259 * (ATA_IDETIMP_RDYSMPL , 70NS) |
260 * (ATA_IDETIMP_RDYRCVRY , 50NS) |
261 * (ATA_IDETIMP_DMAFTIM1 , PIOCOMP) |
262 * (ATA_IDETIMP_PREPOST1 , DISABLE) |
263 * (ATA_IDETIMP_RDYSEN1 , DISABLE) |
264 * (ATA_IDETIMP_PIOFTIM1 , DISABLE) |
265 * (ATA_IDETIMP_DMAFTIM0 , PIOCOMP) |
266 * (ATA_IDETIMP_PREPOST0 , DISABLE) |
267 * (ATA_IDETIMP_RDYSEN0 , DISABLE) |
268 * (ATA_IDETIMP_PIOFTIM0 , DISABLE)
269 */
270 writew(0xB388, base + BK3710_IDETIMP);
271
272 /*
273 * Configure SIDETIM Register
274 * (ATA_SIDETIM_RDYSMPS1 ,120NS ) |
275 * (ATA_SIDETIM_RDYRCYS1 ,120NS )
276 */
277 writeb(0, base + BK3710_SIDETIM);
278
279 /*
280 * UDMACTL Ultra-ATA DMA Control
281 * (ATA_UDMACTL_UDMAP1 , 0 ) |
282 * (ATA_UDMACTL_UDMAP0 , 0 )
283 *
284 */
285 writew(0, base + BK3710_UDMACTL);
286
287 /*
288 * MISCCTL Miscellaneous Conrol Register
289 * (ATA_MISCCTL_RSTMODEP , 1) |
290 * (ATA_MISCCTL_RESETP , 0) |
291 * (ATA_MISCCTL_TIMORIDE , 1)
292 */
293 writel(0x201, base + BK3710_MISCCTL);
294
295 /*
296 * IORDYTMP IORDY Timer for Primary Register
297 * (ATA_IORDYTMP_IORDYTMP , 0xffff )
298 */
299 writel(0xFFFF, base + BK3710_IORDYTMP);
300
301 /*
302 * Configure BMISP Register
303 * (ATA_BMISP_DMAEN1 , DISABLE ) |
304 * (ATA_BMISP_DMAEN0 , DISABLE ) |
305 * (ATA_BMISP_IORDYINT , CLEAR) |
306 * (ATA_BMISP_INTRSTAT , CLEAR) |
307 * (ATA_BMISP_DMAERROR , CLEAR)
308 */
309 writew(0, base + BK3710_BMISP);
310
311 palm_bk3710_setpiomode(base, NULL, 0, 600, 0);
312 palm_bk3710_setpiomode(base, NULL, 1, 600, 0);
313}
314static int __devinit palm_bk3710_probe(struct platform_device *pdev)
315{
316 hw_regs_t ide_ctlr_info;
317 int index = 0;
318 int pribase;
319 struct clk *clkp;
320 struct resource *mem, *irq;
321 ide_hwif_t *hwif;
322 void __iomem *base;
323
324 clkp = clk_get(NULL, "IDECLK");
325 if (IS_ERR(clkp))
326 return -ENODEV;
327
328 ideclkp = clkp;
329 clk_enable(ideclkp);
330 ide_palm_clk = clk_get_rate(ideclkp)/100000;
331 ide_palm_clk = (10000/ide_palm_clk) + 1;
332 /* Register the IDE interface with Linux ATA Interface */
333 memset(&ide_ctlr_info, 0, sizeof(ide_ctlr_info));
334
335 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
336 if (mem == NULL) {
337 printk(KERN_ERR "failed to get memory region resource\n");
338 return -ENODEV;
339 }
340 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
341 if (irq == NULL) {
342 printk(KERN_ERR "failed to get IRQ resource\n");
343 return -ENODEV;
344 }
345
346 base = (void *)mem->start;
347
348 /* Configure the Palm Chip controller */
349 palm_bk3710_chipinit(base);
350
351 pribase = mem->start + IDE_PALM_ATA_PRI_REG_OFFSET;
352 for (index = 0; index < IDE_NR_PORTS - 2; index++)
353 ide_ctlr_info.io_ports[index] = pribase + index;
354 ide_ctlr_info.io_ports[IDE_CONTROL_OFFSET] = mem->start +
355 IDE_PALM_ATA_PRI_CTL_OFFSET;
356 ide_ctlr_info.irq = irq->start;
357 ide_ctlr_info.chipset = ide_palm3710;
358
359 if (ide_register_hw(&ide_ctlr_info, NULL, &hwif) < 0) {
360 printk(KERN_WARNING "Palm Chip BK3710 IDE Register Fail\n");
361 return -ENODEV;
362 }
363
364 hwif->set_pio_mode = &palm_bk3710_set_pio_mode;
365 hwif->set_dma_mode = &palm_bk3710_set_dma_mode;
366 hwif->mmio = 1;
367 default_hwif_mmiops(hwif);
368 hwif->cbl = ATA_CBL_PATA80;
369 hwif->ultra_mask = 0x1f; /* Ultra DMA Mode 4 Max
370 (input clk 99MHz) */
371 hwif->mwdma_mask = 0x7;
372 hwif->drives[0].autotune = 1;
373 hwif->drives[1].autotune = 1;
374
375 ide_setup_dma(hwif, mem->start);
376
377 return 0;
378}
379
380static struct platform_driver platform_bk_driver = {
381 .driver = {
382 .name = "palm_bk3710",
383 },
384 .probe = palm_bk3710_probe,
385 .remove = NULL,
386};
387
388static int __init palm_bk3710_init(void)
389{
390 return platform_driver_register(&platform_bk_driver);
391}
392
393module_init(palm_bk3710_init);
394MODULE_LICENSE("GPL");
395
diff --git a/drivers/ide/cris/ide-cris.c b/drivers/ide/cris/ide-cris.c
index 00587a8c2ba1..e79bf8f9b7db 100644
--- a/drivers/ide/cris/ide-cris.c
+++ b/drivers/ide/cris/ide-cris.c
@@ -753,6 +753,25 @@ static void cris_set_dma_mode(ide_drive_t *drive, const u8 speed)
753 cris_ide_set_speed(TYPE_DMA, 0, strobe, hold); 753 cris_ide_set_speed(TYPE_DMA, 0, strobe, hold);
754} 754}
755 755
756static void __init cris_setup_ports(hw_regs_t *hw, unsigned long base)
757{
758 int i;
759
760 memset(hw, 0, sizeof(*hw));
761
762 for (i = 0; i <= 7; i++)
763 hw->io_ports[i] = base + cris_ide_reg_addr(i, 0, 1);
764
765 /*
766 * the IDE control register is at ATA address 6,
767 * with CS1 active instead of CS0
768 */
769 hw->io_ports[IDE_CONTROL_OFFSET] = base + cris_ide_reg_addr(6, 1, 0);
770
771 hw->irq = ide_default_irq(0);
772 hw->ack_intr = cris_ide_ack_intr;
773}
774
756static const struct ide_port_info cris_port_info __initdata = { 775static const struct ide_port_info cris_port_info __initdata = {
757 .chipset = ide_etrax100, 776 .chipset = ide_etrax100,
758 .host_flags = IDE_HFLAG_NO_ATAPI_DMA | 777 .host_flags = IDE_HFLAG_NO_ATAPI_DMA |
@@ -765,24 +784,16 @@ static const struct ide_port_info cris_port_info __initdata = {
765static int __init init_e100_ide(void) 784static int __init init_e100_ide(void)
766{ 785{
767 hw_regs_t hw; 786 hw_regs_t hw;
768 int ide_offsets[IDE_NR_PORTS], h, i; 787 int h;
769 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; 788 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
770 789
771 printk("ide: ETRAX FS built-in ATA DMA controller\n"); 790 printk("ide: ETRAX FS built-in ATA DMA controller\n");
772 791
773 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
774 ide_offsets[i] = cris_ide_reg_addr(i, 0, 1);
775
776 /* the IDE control register is at ATA address 6, with CS1 active instead of CS0 */
777 ide_offsets[IDE_CONTROL_OFFSET] = cris_ide_reg_addr(6, 1, 0);
778
779 for (h = 0; h < 4; h++) { 792 for (h = 0; h < 4; h++) {
780 ide_hwif_t *hwif = NULL; 793 ide_hwif_t *hwif = NULL;
781 794
782 ide_setup_ports(&hw, cris_ide_base_address(h), 795 cris_setup_ports(&hw, cris_ide_base_address(h));
783 ide_offsets, 796
784 0, 0, cris_ide_ack_intr,
785 ide_default_irq(0));
786 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); 797 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]);
787 if (hwif == NULL) 798 if (hwif == NULL)
788 continue; 799 continue;
diff --git a/drivers/ide/ide-acpi.c b/drivers/ide/ide-acpi.c
index 25aaeae1e830..e07b189f3ec8 100644
--- a/drivers/ide/ide-acpi.c
+++ b/drivers/ide/ide-acpi.c
@@ -171,7 +171,7 @@ err:
171static acpi_handle ide_acpi_hwif_get_handle(ide_hwif_t *hwif) 171static acpi_handle ide_acpi_hwif_get_handle(ide_hwif_t *hwif)
172{ 172{
173 struct device *dev = hwif->gendev.parent; 173 struct device *dev = hwif->gendev.parent;
174 acpi_handle dev_handle; 174 acpi_handle uninitialized_var(dev_handle);
175 acpi_integer pcidevfn; 175 acpi_integer pcidevfn;
176 acpi_handle chan_handle; 176 acpi_handle chan_handle;
177 int err; 177 int err;
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index ee4d458e2bbf..5e42c19a03e3 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -295,7 +295,8 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
295 int stat, err, sense_key; 295 int stat, err, sense_key;
296 296
297 /* Check for errors. */ 297 /* Check for errors. */
298 stat = HWIF(drive)->INB(IDE_STATUS_REG); 298 stat = ide_read_status(drive);
299
299 if (stat_ret) 300 if (stat_ret)
300 *stat_ret = stat; 301 *stat_ret = stat;
301 302
@@ -303,7 +304,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
303 return 0; 304 return 0;
304 305
305 /* Get the IDE error register. */ 306 /* Get the IDE error register. */
306 err = HWIF(drive)->INB(IDE_ERROR_REG); 307 err = ide_read_error(drive);
307 sense_key = err >> 4; 308 sense_key = err >> 4;
308 309
309 if (rq == NULL) { 310 if (rq == NULL) {
@@ -692,7 +693,7 @@ int ide_cd_check_ireason(ide_drive_t *drive, int len, int ireason, int rw)
692 /* Some drives (ASUS) seem to tell us that status 693 /* Some drives (ASUS) seem to tell us that status
693 * info is available. just get it and ignore. 694 * info is available. just get it and ignore.
694 */ 695 */
695 (void) HWIF(drive)->INB(IDE_STATUS_REG); 696 (void)ide_read_status(drive);
696 return 0; 697 return 0;
697 } else { 698 } else {
698 /* Drive wants a command packet, or invalid ireason... */ 699 /* Drive wants a command packet, or invalid ireason... */
@@ -1326,7 +1327,7 @@ ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, sector_t block)
1326 if (blk_fs_request(rq)) { 1327 if (blk_fs_request(rq)) {
1327 if (info->cd_flags & IDE_CD_FLAG_SEEKING) { 1328 if (info->cd_flags & IDE_CD_FLAG_SEEKING) {
1328 unsigned long elapsed = jiffies - info->start_seek; 1329 unsigned long elapsed = jiffies - info->start_seek;
1329 int stat = HWIF(drive)->INB(IDE_STATUS_REG); 1330 int stat = ide_read_status(drive);
1330 1331
1331 if ((stat & SEEK_STAT) != SEEK_STAT) { 1332 if ((stat & SEEK_STAT) != SEEK_STAT) {
1332 if (elapsed < IDECD_SEEK_TIMEOUT) { 1333 if (elapsed < IDECD_SEEK_TIMEOUT) {
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index 3cf59f2c3928..a4bb32883c6b 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -147,7 +147,8 @@ ide_startstop_t ide_dma_intr (ide_drive_t *drive)
147 u8 stat = 0, dma_stat = 0; 147 u8 stat = 0, dma_stat = 0;
148 148
149 dma_stat = HWIF(drive)->ide_dma_end(drive); 149 dma_stat = HWIF(drive)->ide_dma_end(drive);
150 stat = HWIF(drive)->INB(IDE_STATUS_REG); /* get drive status */ 150 stat = ide_read_status(drive);
151
151 if (OK_STAT(stat,DRIVE_READY,drive->bad_wstat|DRQ_STAT)) { 152 if (OK_STAT(stat,DRIVE_READY,drive->bad_wstat|DRQ_STAT)) {
152 if (!dma_stat) { 153 if (!dma_stat) {
153 struct request *rq = HWGROUP(drive)->rq; 154 struct request *rq = HWGROUP(drive)->rq;
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index f8fe6ee128f3..faf22d716f80 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -465,7 +465,7 @@ static void idefloppy_retry_pc(ide_drive_t *drive)
465 idefloppy_pc_t *pc; 465 idefloppy_pc_t *pc;
466 struct request *rq; 466 struct request *rq;
467 467
468 (void)drive->hwif->INB(IDE_ERROR_REG); 468 (void)ide_read_error(drive);
469 pc = idefloppy_next_pc_storage(drive); 469 pc = idefloppy_next_pc_storage(drive);
470 rq = idefloppy_next_rq_storage(drive); 470 rq = idefloppy_next_rq_storage(drive);
471 idefloppy_create_request_sense_cmd(pc); 471 idefloppy_create_request_sense_cmd(pc);
@@ -501,7 +501,7 @@ static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive)
501 } 501 }
502 502
503 /* Clear the interrupt */ 503 /* Clear the interrupt */
504 stat = drive->hwif->INB(IDE_STATUS_REG); 504 stat = ide_read_status(drive);
505 505
506 /* No more interrupts */ 506 /* No more interrupts */
507 if ((stat & DRQ_STAT) == 0) { 507 if ((stat & DRQ_STAT) == 0) {
@@ -1246,7 +1246,7 @@ static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg)
1246 u8 stat; 1246 u8 stat;
1247 1247
1248 local_irq_save(flags); 1248 local_irq_save(flags);
1249 stat = drive->hwif->INB(IDE_STATUS_REG); 1249 stat = ide_read_status(drive);
1250 local_irq_restore(flags); 1250 local_irq_restore(flags);
1251 1251
1252 progress_indication = ((stat & SEEK_STAT) == 0) ? 0 : 0x10000; 1252 progress_indication = ((stat & SEEK_STAT) == 0) ? 0 : 0x10000;
diff --git a/drivers/ide/ide-generic.c b/drivers/ide/ide-generic.c
index be469dbbe8fb..709b9e4d2871 100644
--- a/drivers/ide/ide-generic.c
+++ b/drivers/ide/ide-generic.c
@@ -20,8 +20,14 @@ static int __init ide_generic_init(void)
20 if (ide_hwifs[0].io_ports[IDE_DATA_OFFSET]) 20 if (ide_hwifs[0].io_ports[IDE_DATA_OFFSET])
21 ide_get_lock(NULL, NULL); /* for atari only */ 21 ide_get_lock(NULL, NULL); /* for atari only */
22 22
23 for (i = 0; i < MAX_HWIFS; i++) 23 for (i = 0; i < MAX_HWIFS; i++) {
24 idx[i] = ide_hwifs[i].present ? 0xff : i; 24 ide_hwif_t *hwif = &ide_hwifs[i];
25
26 if (hwif->io_ports[IDE_DATA_OFFSET] && !hwif->present)
27 idx[i] = i;
28 else
29 idx[i] = 0xff;
30 }
25 31
26 ide_device_add_all(idx, NULL); 32 ide_device_add_all(idx, NULL);
27 33
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 4bddef0c0b96..3addbe478d26 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -466,7 +466,7 @@ static ide_startstop_t ide_ata_error(ide_drive_t *drive, struct request *rq, u8
466 return ide_stopped; 466 return ide_stopped;
467 } 467 }
468 468
469 if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT)) 469 if (ide_read_status(drive) & (BUSY_STAT | DRQ_STAT))
470 rq->errors |= ERROR_RESET; 470 rq->errors |= ERROR_RESET;
471 471
472 if ((rq->errors & ERROR_RESET) == ERROR_RESET) { 472 if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
@@ -493,7 +493,7 @@ static ide_startstop_t ide_atapi_error(ide_drive_t *drive, struct request *rq, u
493 /* add decoding error stuff */ 493 /* add decoding error stuff */
494 } 494 }
495 495
496 if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT)) 496 if (ide_read_status(drive) & (BUSY_STAT | DRQ_STAT))
497 /* force an abort */ 497 /* force an abort */
498 hwif->OUTB(WIN_IDLEIMMEDIATE, IDE_COMMAND_REG); 498 hwif->OUTB(WIN_IDLEIMMEDIATE, IDE_COMMAND_REG);
499 499
@@ -821,9 +821,8 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
821#ifdef DEBUG 821#ifdef DEBUG
822 printk("%s: DRIVE_CMD (null)\n", drive->name); 822 printk("%s: DRIVE_CMD (null)\n", drive->name);
823#endif 823#endif
824 ide_end_drive_cmd(drive, 824 ide_end_drive_cmd(drive, ide_read_status(drive), ide_read_error(drive));
825 hwif->INB(IDE_STATUS_REG), 825
826 hwif->INB(IDE_ERROR_REG));
827 return ide_stopped; 826 return ide_stopped;
828} 827}
829 828
@@ -1231,7 +1230,7 @@ static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
1231 printk(KERN_WARNING "%s: DMA timeout error\n", drive->name); 1230 printk(KERN_WARNING "%s: DMA timeout error\n", drive->name);
1232 (void)HWIF(drive)->ide_dma_end(drive); 1231 (void)HWIF(drive)->ide_dma_end(drive);
1233 ret = ide_error(drive, "dma timeout error", 1232 ret = ide_error(drive, "dma timeout error",
1234 hwif->INB(IDE_STATUS_REG)); 1233 ide_read_status(drive));
1235 } else { 1234 } else {
1236 printk(KERN_WARNING "%s: DMA timeout retry\n", drive->name); 1235 printk(KERN_WARNING "%s: DMA timeout retry\n", drive->name);
1237 hwif->dma_timeout(drive); 1236 hwif->dma_timeout(drive);
@@ -1355,7 +1354,8 @@ void ide_timer_expiry (unsigned long data)
1355 startstop = ide_dma_timeout_retry(drive, wait); 1354 startstop = ide_dma_timeout_retry(drive, wait);
1356 } else 1355 } else
1357 startstop = 1356 startstop =
1358 ide_error(drive, "irq timeout", hwif->INB(IDE_STATUS_REG)); 1357 ide_error(drive, "irq timeout",
1358 ide_read_status(drive));
1359 } 1359 }
1360 drive->service_time = jiffies - drive->service_start; 1360 drive->service_time = jiffies - drive->service_start;
1361 spin_lock_irq(&ide_lock); 1361 spin_lock_irq(&ide_lock);
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index a95178f5e1bb..c32e759df208 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -430,10 +430,10 @@ int drive_is_ready (ide_drive_t *drive)
430 * about possible isa-pnp and pci-pnp issues yet. 430 * about possible isa-pnp and pci-pnp issues yet.
431 */ 431 */
432 if (IDE_CONTROL_REG) 432 if (IDE_CONTROL_REG)
433 stat = hwif->INB(IDE_ALTSTATUS_REG); 433 stat = ide_read_altstatus(drive);
434 else 434 else
435 /* Note: this may clear a pending IRQ!! */ 435 /* Note: this may clear a pending IRQ!! */
436 stat = hwif->INB(IDE_STATUS_REG); 436 stat = ide_read_status(drive);
437 437
438 if (stat & BUSY_STAT) 438 if (stat & BUSY_STAT)
439 /* drive busy: definitely not interrupting */ 439 /* drive busy: definitely not interrupting */
@@ -458,23 +458,24 @@ EXPORT_SYMBOL(drive_is_ready);
458 */ 458 */
459static int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad, unsigned long timeout, u8 *rstat) 459static int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad, unsigned long timeout, u8 *rstat)
460{ 460{
461 ide_hwif_t *hwif = drive->hwif;
462 unsigned long flags; 461 unsigned long flags;
463 int i; 462 int i;
464 u8 stat; 463 u8 stat;
465 464
466 udelay(1); /* spec allows drive 400ns to assert "BUSY" */ 465 udelay(1); /* spec allows drive 400ns to assert "BUSY" */
467 if ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) { 466 stat = ide_read_status(drive);
467
468 if (stat & BUSY_STAT) {
468 local_irq_set(flags); 469 local_irq_set(flags);
469 timeout += jiffies; 470 timeout += jiffies;
470 while ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) { 471 while ((stat = ide_read_status(drive)) & BUSY_STAT) {
471 if (time_after(jiffies, timeout)) { 472 if (time_after(jiffies, timeout)) {
472 /* 473 /*
473 * One last read after the timeout in case 474 * One last read after the timeout in case
474 * heavy interrupt load made us not make any 475 * heavy interrupt load made us not make any
475 * progress during the timeout.. 476 * progress during the timeout..
476 */ 477 */
477 stat = hwif->INB(IDE_STATUS_REG); 478 stat = ide_read_status(drive);
478 if (!(stat & BUSY_STAT)) 479 if (!(stat & BUSY_STAT))
479 break; 480 break;
480 481
@@ -494,7 +495,9 @@ static int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad, unsigned long ti
494 */ 495 */
495 for (i = 0; i < 10; i++) { 496 for (i = 0; i < 10; i++) {
496 udelay(1); 497 udelay(1);
497 if (OK_STAT((stat = hwif->INB(IDE_STATUS_REG)), good, bad)) { 498 stat = ide_read_status(drive);
499
500 if (OK_STAT(stat, good, bad)) {
498 *rstat = stat; 501 *rstat = stat;
499 return 0; 502 return 0;
500 } 503 }
@@ -617,6 +620,7 @@ int ide_driveid_update(ide_drive_t *drive)
617 ide_hwif_t *hwif = drive->hwif; 620 ide_hwif_t *hwif = drive->hwif;
618 struct hd_driveid *id; 621 struct hd_driveid *id;
619 unsigned long timeout, flags; 622 unsigned long timeout, flags;
623 u8 stat;
620 624
621 /* 625 /*
622 * Re-read drive->id for possible DMA mode 626 * Re-read drive->id for possible DMA mode
@@ -633,10 +637,15 @@ int ide_driveid_update(ide_drive_t *drive)
633 SELECT_MASK(drive, 0); 637 SELECT_MASK(drive, 0);
634 return 0; /* drive timed-out */ 638 return 0; /* drive timed-out */
635 } 639 }
640
636 msleep(50); /* give drive a breather */ 641 msleep(50); /* give drive a breather */
637 } while (hwif->INB(IDE_ALTSTATUS_REG) & BUSY_STAT); 642 stat = ide_read_altstatus(drive);
643 } while (stat & BUSY_STAT);
644
638 msleep(50); /* wait for IRQ and DRQ_STAT */ 645 msleep(50); /* wait for IRQ and DRQ_STAT */
639 if (!OK_STAT(hwif->INB(IDE_STATUS_REG),DRQ_STAT,BAD_R_STAT)) { 646 stat = ide_read_status(drive);
647
648 if (!OK_STAT(stat, DRQ_STAT, BAD_R_STAT)) {
640 SELECT_MASK(drive, 0); 649 SELECT_MASK(drive, 0);
641 printk("%s: CHECK for good STATUS\n", drive->name); 650 printk("%s: CHECK for good STATUS\n", drive->name);
642 return 0; 651 return 0;
@@ -649,7 +658,7 @@ int ide_driveid_update(ide_drive_t *drive)
649 return 0; 658 return 0;
650 } 659 }
651 ata_input_data(drive, id, SECTOR_WORDS); 660 ata_input_data(drive, id, SECTOR_WORDS);
652 (void) hwif->INB(IDE_STATUS_REG); /* clear drive IRQ */ 661 (void)ide_read_status(drive); /* clear drive IRQ */
653 local_irq_enable(); 662 local_irq_enable();
654 local_irq_restore(flags); 663 local_irq_restore(flags);
655 ide_fix_driveid(id); 664 ide_fix_driveid(id);
@@ -850,17 +859,16 @@ static ide_startstop_t do_reset1 (ide_drive_t *, int);
850static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive) 859static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive)
851{ 860{
852 ide_hwgroup_t *hwgroup = HWGROUP(drive); 861 ide_hwgroup_t *hwgroup = HWGROUP(drive);
853 ide_hwif_t *hwif = HWIF(drive);
854 u8 stat; 862 u8 stat;
855 863
856 SELECT_DRIVE(drive); 864 SELECT_DRIVE(drive);
857 udelay (10); 865 udelay (10);
866 stat = ide_read_status(drive);
858 867
859 if (OK_STAT(stat = hwif->INB(IDE_STATUS_REG), 0, BUSY_STAT)) { 868 if (OK_STAT(stat, 0, BUSY_STAT))
860 printk("%s: ATAPI reset complete\n", drive->name); 869 printk("%s: ATAPI reset complete\n", drive->name);
861 } else { 870 else {
862 if (time_before(jiffies, hwgroup->poll_timeout)) { 871 if (time_before(jiffies, hwgroup->poll_timeout)) {
863 BUG_ON(HWGROUP(drive)->handler != NULL);
864 ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL); 872 ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL);
865 /* continue polling */ 873 /* continue polling */
866 return ide_started; 874 return ide_started;
@@ -898,9 +906,10 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
898 } 906 }
899 } 907 }
900 908
901 if (!OK_STAT(tmp = hwif->INB(IDE_STATUS_REG), 0, BUSY_STAT)) { 909 tmp = ide_read_status(drive);
910
911 if (!OK_STAT(tmp, 0, BUSY_STAT)) {
902 if (time_before(jiffies, hwgroup->poll_timeout)) { 912 if (time_before(jiffies, hwgroup->poll_timeout)) {
903 BUG_ON(HWGROUP(drive)->handler != NULL);
904 ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL); 913 ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL);
905 /* continue polling */ 914 /* continue polling */
906 return ide_started; 915 return ide_started;
@@ -909,7 +918,9 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
909 drive->failures++; 918 drive->failures++;
910 } else { 919 } else {
911 printk("%s: reset: ", hwif->name); 920 printk("%s: reset: ", hwif->name);
912 if ((tmp = hwif->INB(IDE_ERROR_REG)) == 1) { 921 tmp = ide_read_error(drive);
922
923 if (tmp == 1) {
913 printk("success\n"); 924 printk("success\n");
914 drive->failures = 0; 925 drive->failures = 0;
915 } else { 926 } else {
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index b42940d8bf70..1ff676cc6473 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -578,7 +578,7 @@ u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
578 } 578 }
579 printk("}\n"); 579 printk("}\n");
580 if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) { 580 if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) {
581 err = drive->hwif->INB(IDE_ERROR_REG); 581 err = ide_read_error(drive);
582 printk("%s: %s: error=0x%02x ", drive->name, msg, err); 582 printk("%s: %s: error=0x%02x ", drive->name, msg, err);
583 if (drive->media == ide_disk) 583 if (drive->media == ide_disk)
584 ide_dump_ata_error(drive, err); 584 ide_dump_ata_error(drive, err);
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 9c07bdb68d1a..fd0ef8268950 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -264,8 +264,7 @@ err_misc:
264static int actual_try_to_identify (ide_drive_t *drive, u8 cmd) 264static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
265{ 265{
266 ide_hwif_t *hwif = HWIF(drive); 266 ide_hwif_t *hwif = HWIF(drive);
267 int rc; 267 int use_altstatus = 0, rc;
268 unsigned long hd_status;
269 unsigned long timeout; 268 unsigned long timeout;
270 u8 s = 0, a = 0; 269 u8 s = 0, a = 0;
271 270
@@ -273,19 +272,17 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
273 msleep(50); 272 msleep(50);
274 273
275 if (IDE_CONTROL_REG) { 274 if (IDE_CONTROL_REG) {
276 a = hwif->INB(IDE_ALTSTATUS_REG); 275 a = ide_read_altstatus(drive);
277 s = hwif->INB(IDE_STATUS_REG); 276 s = ide_read_status(drive);
278 if ((a ^ s) & ~INDEX_STAT) { 277 if ((a ^ s) & ~INDEX_STAT)
279 printk(KERN_INFO "%s: probing with STATUS(0x%02x) instead of "
280 "ALTSTATUS(0x%02x)\n", drive->name, s, a);
281 /* ancient Seagate drives, broken interfaces */ 278 /* ancient Seagate drives, broken interfaces */
282 hd_status = IDE_STATUS_REG; 279 printk(KERN_INFO "%s: probing with STATUS(0x%02x) "
283 } else { 280 "instead of ALTSTATUS(0x%02x)\n",
281 drive->name, s, a);
282 else
284 /* use non-intrusive polling */ 283 /* use non-intrusive polling */
285 hd_status = IDE_ALTSTATUS_REG; 284 use_altstatus = 1;
286 } 285 }
287 } else
288 hd_status = IDE_STATUS_REG;
289 286
290 /* set features register for atapi 287 /* set features register for atapi
291 * identify command to be sure of reply 288 * identify command to be sure of reply
@@ -306,11 +303,15 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
306 } 303 }
307 /* give drive a breather */ 304 /* give drive a breather */
308 msleep(50); 305 msleep(50);
309 } while ((hwif->INB(hd_status)) & BUSY_STAT); 306 s = use_altstatus ? ide_read_altstatus(drive)
307 : ide_read_status(drive);
308 } while (s & BUSY_STAT);
310 309
311 /* wait for IRQ and DRQ_STAT */ 310 /* wait for IRQ and DRQ_STAT */
312 msleep(50); 311 msleep(50);
313 if (OK_STAT((hwif->INB(IDE_STATUS_REG)), DRQ_STAT, BAD_R_STAT)) { 312 s = ide_read_status(drive);
313
314 if (OK_STAT(s, DRQ_STAT, BAD_R_STAT)) {
314 unsigned long flags; 315 unsigned long flags;
315 316
316 /* local CPU only; some systems need this */ 317 /* local CPU only; some systems need this */
@@ -320,7 +321,7 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
320 /* drive responded with ID */ 321 /* drive responded with ID */
321 rc = 0; 322 rc = 0;
322 /* clear drive IRQ */ 323 /* clear drive IRQ */
323 (void) hwif->INB(IDE_STATUS_REG); 324 (void)ide_read_status(drive);
324 local_irq_restore(flags); 325 local_irq_restore(flags);
325 } else { 326 } else {
326 /* drive refused ID */ 327 /* drive refused ID */
@@ -367,7 +368,7 @@ static int try_to_identify (ide_drive_t *drive, u8 cmd)
367 368
368 ide_set_irq(drive, 0); 369 ide_set_irq(drive, 0);
369 /* clear drive IRQ */ 370 /* clear drive IRQ */
370 (void) hwif->INB(IDE_STATUS_REG); 371 (void)ide_read_status(drive);
371 udelay(5); 372 udelay(5);
372 irq = probe_irq_off(cookie); 373 irq = probe_irq_off(cookie);
373 if (!hwif->irq) { 374 if (!hwif->irq) {
@@ -455,7 +456,9 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
455 return 3; 456 return 3;
456 } 457 }
457 458
458 if (OK_STAT((hwif->INB(IDE_STATUS_REG)), READY_STAT, BUSY_STAT) || 459 stat = ide_read_status(drive);
460
461 if (OK_STAT(stat, READY_STAT, BUSY_STAT) ||
459 drive->present || cmd == WIN_PIDENTIFY) { 462 drive->present || cmd == WIN_PIDENTIFY) {
460 /* send cmd and wait */ 463 /* send cmd and wait */
461 if ((rc = try_to_identify(drive, cmd))) { 464 if ((rc = try_to_identify(drive, cmd))) {
@@ -463,7 +466,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
463 rc = try_to_identify(drive,cmd); 466 rc = try_to_identify(drive,cmd);
464 } 467 }
465 468
466 stat = hwif->INB(IDE_STATUS_REG); 469 stat = ide_read_status(drive);
467 470
468 if (stat == (BUSY_STAT | READY_STAT)) 471 if (stat == (BUSY_STAT | READY_STAT))
469 return 4; 472 return 4;
@@ -482,7 +485,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
482 } 485 }
483 486
484 /* ensure drive IRQ is clear */ 487 /* ensure drive IRQ is clear */
485 stat = hwif->INB(IDE_STATUS_REG); 488 stat = ide_read_status(drive);
486 489
487 if (rc == 1) 490 if (rc == 1)
488 printk(KERN_ERR "%s: no response (status = 0x%02x)\n", 491 printk(KERN_ERR "%s: no response (status = 0x%02x)\n",
@@ -496,7 +499,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
496 SELECT_DRIVE(&hwif->drives[0]); 499 SELECT_DRIVE(&hwif->drives[0]);
497 msleep(50); 500 msleep(50);
498 /* ensure drive irq is clear */ 501 /* ensure drive irq is clear */
499 (void) hwif->INB(IDE_STATUS_REG); 502 (void)ide_read_status(drive);
500 } 503 }
501 return rc; 504 return rc;
502} 505}
@@ -521,7 +524,7 @@ static void enable_nest (ide_drive_t *drive)
521 524
522 msleep(50); 525 msleep(50);
523 526
524 stat = hwif->INB(IDE_STATUS_REG); 527 stat = ide_read_status(drive);
525 528
526 if (!OK_STAT(stat, 0, BAD_STAT)) 529 if (!OK_STAT(stat, 0, BAD_STAT))
527 printk(KERN_CONT "failed (status = 0x%02x)\n", stat); 530 printk(KERN_CONT "failed (status = 0x%02x)\n", stat);
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index 975c0ff0f438..bab88ca7f7ec 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -65,6 +65,7 @@ static int proc_ide_read_imodel
65 case ide_4drives: name = "4drives"; break; 65 case ide_4drives: name = "4drives"; break;
66 case ide_pmac: name = "mac-io"; break; 66 case ide_pmac: name = "mac-io"; break;
67 case ide_au1xxx: name = "au1xxx"; break; 67 case ide_au1xxx: name = "au1xxx"; break;
68 case ide_palm3710: name = "palm3710"; break;
68 case ide_etrax100: name = "etrax100"; break; 69 case ide_etrax100: name = "etrax100"; break;
69 case ide_acorn: name = "acorn"; break; 70 case ide_acorn: name = "acorn"; break;
70 default: name = "(unknown)"; break; 71 default: name = "(unknown)"; break;
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index bf40d8c824ad..49dd2e7bae7a 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -15,7 +15,7 @@
15 * Documentation/ide/ChangeLog.ide-tape.1995-2002 15 * Documentation/ide/ChangeLog.ide-tape.1995-2002
16 */ 16 */
17 17
18#define IDETAPE_VERSION "1.19" 18#define IDETAPE_VERSION "1.20"
19 19
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/types.h> 21#include <linux/types.h>
@@ -39,63 +39,70 @@
39#include <scsi/scsi.h> 39#include <scsi/scsi.h>
40 40
41#include <asm/byteorder.h> 41#include <asm/byteorder.h>
42#include <asm/irq.h> 42#include <linux/irq.h>
43#include <asm/uaccess.h> 43#include <linux/uaccess.h>
44#include <asm/io.h> 44#include <linux/io.h>
45#include <asm/unaligned.h> 45#include <asm/unaligned.h>
46#include <linux/mtio.h> 46#include <linux/mtio.h>
47 47
48enum {
49 /* output errors only */
50 DBG_ERR = (1 << 0),
51 /* output all sense key/asc */
52 DBG_SENSE = (1 << 1),
53 /* info regarding all chrdev-related procedures */
54 DBG_CHRDEV = (1 << 2),
55 /* all remaining procedures */
56 DBG_PROCS = (1 << 3),
57 /* buffer alloc info (pc_stack & rq_stack) */
58 DBG_PCRQ_STACK = (1 << 4),
59};
60
61/* define to see debug info */
62#define IDETAPE_DEBUG_LOG 0
63
64#if IDETAPE_DEBUG_LOG
65#define debug_log(lvl, fmt, args...) \
66{ \
67 if (tape->debug_mask & lvl) \
68 printk(KERN_INFO "ide-tape: " fmt, ## args); \
69}
70#else
71#define debug_log(lvl, fmt, args...) do {} while (0)
72#endif
73
48/**************************** Tunable parameters *****************************/ 74/**************************** Tunable parameters *****************************/
49 75
50 76
51/* 77/*
52 * Pipelined mode parameters. 78 * Pipelined mode parameters.
53 * 79 *
54 * We try to use the minimum number of stages which is enough to 80 * We try to use the minimum number of stages which is enough to keep the tape
55 * keep the tape constantly streaming. To accomplish that, we implement 81 * constantly streaming. To accomplish that, we implement a feedback loop around
56 * a feedback loop around the maximum number of stages: 82 * the maximum number of stages:
57 * 83 *
58 * We start from MIN maximum stages (we will not even use MIN stages 84 * We start from MIN maximum stages (we will not even use MIN stages if we don't
59 * if we don't need them), increment it by RATE*(MAX-MIN) 85 * need them), increment it by RATE*(MAX-MIN) whenever we sense that the
60 * whenever we sense that the pipeline is empty, until we reach 86 * pipeline is empty, until we reach the optimum value or until we reach MAX.
61 * the optimum value or until we reach MAX.
62 * 87 *
63 * Setting the following parameter to 0 is illegal: the pipelined mode 88 * Setting the following parameter to 0 is illegal: the pipelined mode cannot be
64 * cannot be disabled (calculate_speeds() divides by tape->max_stages.) 89 * disabled (idetape_calculate_speeds() divides by tape->max_stages.)
65 */ 90 */
66#define IDETAPE_MIN_PIPELINE_STAGES 1 91#define IDETAPE_MIN_PIPELINE_STAGES 1
67#define IDETAPE_MAX_PIPELINE_STAGES 400 92#define IDETAPE_MAX_PIPELINE_STAGES 400
68#define IDETAPE_INCREASE_STAGES_RATE 20 93#define IDETAPE_INCREASE_STAGES_RATE 20
69 94
70/* 95/*
71 * The following are used to debug the driver: 96 * After each failed packet command we issue a request sense command and retry
72 * 97 * the packet command IDETAPE_MAX_PC_RETRIES times.
73 * Setting IDETAPE_DEBUG_LOG to 1 will log driver flow control.
74 * 98 *
75 * Setting them to 0 will restore normal operation mode: 99 * Setting IDETAPE_MAX_PC_RETRIES to 0 will disable retries.
76 *
77 * 1. Disable logging normal successful operations.
78 * 2. Disable self-sanity checks.
79 * 3. Errors will still be logged, of course.
80 *
81 * All the #if DEBUG code will be removed some day, when the driver
82 * is verified to be stable enough. This will make it much more
83 * esthetic.
84 */
85#define IDETAPE_DEBUG_LOG 0
86
87/*
88 * After each failed packet command we issue a request sense command
89 * and retry the packet command IDETAPE_MAX_PC_RETRIES times.
90 *
91 * Setting IDETAPE_MAX_PC_RETRIES to 0 will disable retries.
92 */ 100 */
93#define IDETAPE_MAX_PC_RETRIES 3 101#define IDETAPE_MAX_PC_RETRIES 3
94 102
95/* 103/*
96 * With each packet command, we allocate a buffer of 104 * With each packet command, we allocate a buffer of IDETAPE_PC_BUFFER_SIZE
97 * IDETAPE_PC_BUFFER_SIZE bytes. This is used for several packet 105 * bytes. This is used for several packet commands (Not for READ/WRITE commands)
98 * commands (Not for READ/WRITE commands).
99 */ 106 */
100#define IDETAPE_PC_BUFFER_SIZE 256 107#define IDETAPE_PC_BUFFER_SIZE 256
101 108
@@ -114,48 +121,39 @@
114#define IDETAPE_WAIT_CMD (900*HZ) 121#define IDETAPE_WAIT_CMD (900*HZ)
115 122
116/* 123/*
117 * The following parameter is used to select the point in the internal 124 * The following parameter is used to select the point in the internal tape fifo
118 * tape fifo in which we will start to refill the buffer. Decreasing 125 * in which we will start to refill the buffer. Decreasing the following
119 * the following parameter will improve the system's latency and 126 * parameter will improve the system's latency and interactive response, while
120 * interactive response, while using a high value might improve system 127 * using a high value might improve system throughput.
121 * throughput.
122 */ 128 */
123#define IDETAPE_FIFO_THRESHOLD 2 129#define IDETAPE_FIFO_THRESHOLD 2
124 130
125/* 131/*
126 * DSC polling parameters. 132 * DSC polling parameters.
127 *
128 * Polling for DSC (a single bit in the status register) is a very
129 * important function in ide-tape. There are two cases in which we
130 * poll for DSC:
131 * 133 *
132 * 1. Before a read/write packet command, to ensure that we 134 * Polling for DSC (a single bit in the status register) is a very important
133 * can transfer data from/to the tape's data buffers, without 135 * function in ide-tape. There are two cases in which we poll for DSC:
134 * causing an actual media access. In case the tape is not
135 * ready yet, we take out our request from the device
136 * request queue, so that ide.c will service requests from
137 * the other device on the same interface meanwhile.
138 * 136 *
139 * 2. After the successful initialization of a "media access 137 * 1. Before a read/write packet command, to ensure that we can transfer data
140 * packet command", which is a command which can take a long 138 * from/to the tape's data buffers, without causing an actual media access.
141 * time to complete (it can be several seconds or even an hour). 139 * In case the tape is not ready yet, we take out our request from the device
140 * request queue, so that ide.c could service requests from the other device
141 * on the same interface in the meantime.
142 * 142 *
143 * Again, we postpone our request in the middle to free the bus 143 * 2. After the successful initialization of a "media access packet command",
144 * for the other device. The polling frequency here should be 144 * which is a command that can take a long time to complete (the interval can
145 * lower than the read/write frequency since those media access 145 * range from several seconds to even an hour). Again, we postpone our request
146 * commands are slow. We start from a "fast" frequency - 146 * in the middle to free the bus for the other device. The polling frequency
147 * IDETAPE_DSC_MA_FAST (one second), and if we don't receive DSC 147 * here should be lower than the read/write frequency since those media access
148 * after IDETAPE_DSC_MA_THRESHOLD (5 minutes), we switch it to a 148 * commands are slow. We start from a "fast" frequency - IDETAPE_DSC_MA_FAST
149 * lower frequency - IDETAPE_DSC_MA_SLOW (1 minute). 149 * (1 second), and if we don't receive DSC after IDETAPE_DSC_MA_THRESHOLD
150 * (5 min), we switch it to a lower frequency - IDETAPE_DSC_MA_SLOW (1 min).
150 * 151 *
151 * We also set a timeout for the timer, in case something goes wrong. 152 * We also set a timeout for the timer, in case something goes wrong. The
152 * The timeout should be longer then the maximum execution time of a 153 * timeout should be longer then the maximum execution time of a tape operation.
153 * tape operation.
154 */
155
156/*
157 * DSC timings.
158 */ 154 */
155
156/* DSC timings. */
159#define IDETAPE_DSC_RW_MIN 5*HZ/100 /* 50 msec */ 157#define IDETAPE_DSC_RW_MIN 5*HZ/100 /* 50 msec */
160#define IDETAPE_DSC_RW_MAX 40*HZ/100 /* 400 msec */ 158#define IDETAPE_DSC_RW_MAX 40*HZ/100 /* 400 msec */
161#define IDETAPE_DSC_RW_TIMEOUT 2*60*HZ /* 2 minutes */ 159#define IDETAPE_DSC_RW_TIMEOUT 2*60*HZ /* 2 minutes */
@@ -166,19 +164,15 @@
166 164
167/*************************** End of tunable parameters ***********************/ 165/*************************** End of tunable parameters ***********************/
168 166
169/* 167/* Read/Write error simulation */
170 * Read/Write error simulation
171 */
172#define SIMULATE_ERRORS 0 168#define SIMULATE_ERRORS 0
173 169
174/* 170/* tape directions */
175 * For general magnetic tape device compatibility. 171enum {
176 */ 172 IDETAPE_DIR_NONE = (1 << 0),
177typedef enum { 173 IDETAPE_DIR_READ = (1 << 1),
178 idetape_direction_none, 174 IDETAPE_DIR_WRITE = (1 << 2),
179 idetape_direction_read, 175};
180 idetape_direction_write
181} idetape_chrdev_direction_t;
182 176
183struct idetape_bh { 177struct idetape_bh {
184 u32 b_size; 178 u32 b_size;
@@ -187,24 +181,32 @@ struct idetape_bh {
187 char *b_data; 181 char *b_data;
188}; 182};
189 183
190/*
191 * Our view of a packet command.
192 */
193typedef struct idetape_packet_command_s { 184typedef struct idetape_packet_command_s {
194 u8 c[12]; /* Actual packet bytes */ 185 /* Actual packet bytes */
195 int retries; /* On each retry, we increment retries */ 186 u8 c[12];
196 int error; /* Error code */ 187 /* On each retry, we increment retries */
197 int request_transfer; /* Bytes to transfer */ 188 int retries;
198 int actually_transferred; /* Bytes actually transferred */ 189 /* Error code */
199 int buffer_size; /* Size of our data buffer */ 190 int error;
191 /* Bytes to transfer */
192 int request_transfer;
193 /* Bytes actually transferred */
194 int actually_transferred;
195 /* Size of our data buffer */
196 int buffer_size;
200 struct idetape_bh *bh; 197 struct idetape_bh *bh;
201 char *b_data; 198 char *b_data;
202 int b_count; 199 int b_count;
203 u8 *buffer; /* Data buffer */ 200 /* Data buffer */
204 u8 *current_position; /* Pointer into the above buffer */ 201 u8 *buffer;
205 ide_startstop_t (*callback) (ide_drive_t *); /* Called when this packet command is completed */ 202 /* Pointer into the above buffer */
206 u8 pc_buffer[IDETAPE_PC_BUFFER_SIZE]; /* Temporary buffer */ 203 u8 *current_position;
207 unsigned long flags; /* Status/Action bit flags: long for set_bit */ 204 /* Called when this packet command is completed */
205 ide_startstop_t (*callback) (ide_drive_t *);
206 /* Temporary buffer */
207 u8 pc_buffer[IDETAPE_PC_BUFFER_SIZE];
208 /* Status/Action bit flags: long for set_bit */
209 unsigned long flags;
208} idetape_pc_t; 210} idetape_pc_t;
209 211
210/* 212/*
@@ -223,9 +225,7 @@ typedef struct idetape_packet_command_s {
223/* Data direction */ 225/* Data direction */
224#define PC_WRITING 5 226#define PC_WRITING 5
225 227
226/* 228/* A pipeline stage. */
227 * A pipeline stage.
228 */
229typedef struct idetape_stage_s { 229typedef struct idetape_stage_s {
230 struct request rq; /* The corresponding request */ 230 struct request rq; /* The corresponding request */
231 struct idetape_bh *bh; /* The data buffers */ 231 struct idetape_bh *bh; /* The data buffers */
@@ -233,9 +233,8 @@ typedef struct idetape_stage_s {
233} idetape_stage_t; 233} idetape_stage_t;
234 234
235/* 235/*
236 * Most of our global data which we need to save even as we leave the 236 * Most of our global data which we need to save even as we leave the driver due
237 * driver due to an interrupt or a timer event is stored in a variable 237 * to an interrupt or a timer event is stored in the struct defined below.
238 * of type idetape_tape_t, defined below.
239 */ 238 */
240typedef struct ide_tape_obj { 239typedef struct ide_tape_obj {
241 ide_drive_t *drive; 240 ide_drive_t *drive;
@@ -271,15 +270,14 @@ typedef struct ide_tape_obj {
271 int rq_stack_index; 270 int rq_stack_index;
272 271
273 /* 272 /*
274 * DSC polling variables. 273 * DSC polling variables.
275 * 274 *
276 * While polling for DSC we use postponed_rq to postpone the 275 * While polling for DSC we use postponed_rq to postpone the current
277 * current request so that ide.c will be able to service 276 * request so that ide.c will be able to service pending requests on the
278 * pending requests on the other device. Note that at most 277 * other device. Note that at most we will have only one DSC (usually
279 * we will have only one DSC (usually data transfer) request 278 * data transfer) request in the device request queue. Additional
280 * in the device request queue. Additional requests can be 279 * requests can be queued in our internal pipeline, but they will be
281 * queued in our internal pipeline, but they will be visible 280 * visible to ide.c only one at a time.
282 * to ide.c only one at a time.
283 */ 281 */
284 struct request *postponed_rq; 282 struct request *postponed_rq;
285 /* The time in which we started polling for DSC */ 283 /* The time in which we started polling for DSC */
@@ -287,73 +285,57 @@ typedef struct ide_tape_obj {
287 /* Timer used to poll for dsc */ 285 /* Timer used to poll for dsc */
288 struct timer_list dsc_timer; 286 struct timer_list dsc_timer;
289 /* Read/Write dsc polling frequency */ 287 /* Read/Write dsc polling frequency */
290 unsigned long best_dsc_rw_frequency; 288 unsigned long best_dsc_rw_freq;
291 /* The current polling frequency */ 289 unsigned long dsc_poll_freq;
292 unsigned long dsc_polling_frequency;
293 /* Maximum waiting time */
294 unsigned long dsc_timeout; 290 unsigned long dsc_timeout;
295 291
296 /* 292 /* Read position information */
297 * Read position information
298 */
299 u8 partition; 293 u8 partition;
300 /* Current block */ 294 /* Current block */
301 unsigned int first_frame_position; 295 unsigned int first_frame;
302 unsigned int last_frame_position;
303 unsigned int blocks_in_buffer;
304 296
305 /* 297 /* Last error information */
306 * Last error information
307 */
308 u8 sense_key, asc, ascq; 298 u8 sense_key, asc, ascq;
309 299
310 /* 300 /* Character device operation */
311 * Character device operation
312 */
313 unsigned int minor; 301 unsigned int minor;
314 /* device name */ 302 /* device name */
315 char name[4]; 303 char name[4];
316 /* Current character device data transfer direction */ 304 /* Current character device data transfer direction */
317 idetape_chrdev_direction_t chrdev_direction; 305 u8 chrdev_dir;
318 306
319 /* 307 /* tape block size, usually 512 or 1024 bytes */
320 * Device information 308 unsigned short blk_size;
321 */
322 /* Usually 512 or 1024 bytes */
323 unsigned short tape_block_size;
324 int user_bs_factor; 309 int user_bs_factor;
325 310
326 /* Copy of the tape's Capabilities and Mechanical Page */ 311 /* Copy of the tape's Capabilities and Mechanical Page */
327 u8 caps[20]; 312 u8 caps[20];
328 313
329 /* 314 /*
330 * Active data transfer request parameters. 315 * Active data transfer request parameters.
331 *
332 * At most, there is only one ide-tape originated data transfer
333 * request in the device request queue. This allows ide.c to
334 * easily service requests from the other device when we
335 * postpone our active request. In the pipelined operation
336 * mode, we use our internal pipeline structure to hold
337 * more data requests.
338 * 316 *
339 * The data buffer size is chosen based on the tape's 317 * At most, there is only one ide-tape originated data transfer request
340 * recommendation. 318 * in the device request queue. This allows ide.c to easily service
319 * requests from the other device when we postpone our active request.
320 * In the pipelined operation mode, we use our internal pipeline
321 * structure to hold more data requests. The data buffer size is chosen
322 * based on the tape's recommendation.
341 */ 323 */
342 /* Pointer to the request which is waiting in the device request queue */ 324 /* ptr to the request which is waiting in the device request queue */
343 struct request *active_data_request; 325 struct request *active_data_rq;
344 /* Data buffer size (chosen based on the tape's recommendation */ 326 /* Data buffer size chosen based on the tape's recommendation */
345 int stage_size; 327 int stage_size;
346 idetape_stage_t *merge_stage; 328 idetape_stage_t *merge_stage;
347 int merge_stage_size; 329 int merge_stage_size;
348 struct idetape_bh *bh; 330 struct idetape_bh *bh;
349 char *b_data; 331 char *b_data;
350 int b_count; 332 int b_count;
351 333
352 /* 334 /*
353 * Pipeline parameters. 335 * Pipeline parameters.
354 * 336 *
355 * To accomplish non-pipelined mode, we simply set the following 337 * To accomplish non-pipelined mode, we simply set the following
356 * variables to zero (or NULL, where appropriate). 338 * variables to zero (or NULL, where appropriate).
357 */ 339 */
358 /* Number of currently used stages */ 340 /* Number of currently used stages */
359 int nr_stages; 341 int nr_stages;
@@ -378,20 +360,13 @@ typedef struct ide_tape_obj {
378 /* Status/Action flags: long for set_bit */ 360 /* Status/Action flags: long for set_bit */
379 unsigned long flags; 361 unsigned long flags;
380 /* protects the ide-tape queue */ 362 /* protects the ide-tape queue */
381 spinlock_t spinlock; 363 spinlock_t lock;
382 364
383 /* 365 /* Measures average tape speed */
384 * Measures average tape speed
385 */
386 unsigned long avg_time; 366 unsigned long avg_time;
387 int avg_size; 367 int avg_size;
388 int avg_speed; 368 int avg_speed;
389 369
390 char vendor_id[10];
391 char product_id[18];
392 char firmware_revision[6];
393 int firmware_revision_num;
394
395 /* the door is currently locked */ 370 /* the door is currently locked */
396 int door_locked; 371 int door_locked;
397 /* the tape hardware is write protected */ 372 /* the tape hardware is write protected */
@@ -400,11 +375,9 @@ typedef struct ide_tape_obj {
400 char write_prot; 375 char write_prot;
401 376
402 /* 377 /*
403 * Limit the number of times a request can 378 * Limit the number of times a request can be postponed, to avoid an
404 * be postponed, to avoid an infinite postpone 379 * infinite postpone deadlock.
405 * deadlock.
406 */ 380 */
407 /* request postpone count limit */
408 int postpone_cnt; 381 int postpone_cnt;
409 382
410 /* 383 /*
@@ -419,30 +392,19 @@ typedef struct ide_tape_obj {
419 int tape_head; 392 int tape_head;
420 int last_tape_head; 393 int last_tape_head;
421 394
422 /* 395 /* Speed control at the tape buffers input/output */
423 * Speed control at the tape buffers input/output
424 */
425 unsigned long insert_time; 396 unsigned long insert_time;
426 int insert_size; 397 int insert_size;
427 int insert_speed; 398 int insert_speed;
428 int max_insert_speed; 399 int max_insert_speed;
429 int measure_insert_time; 400 int measure_insert_time;
430 401
431 /* 402 /* Speed regulation negative feedback loop */
432 * Measure tape still time, in milliseconds
433 */
434 unsigned long tape_still_time_begin;
435 int tape_still_time;
436
437 /*
438 * Speed regulation negative feedback loop
439 */
440 int speed_control; 403 int speed_control;
441 int pipeline_head_speed; 404 int pipeline_head_speed;
442 int controlled_pipeline_head_speed; 405 int controlled_pipeline_head_speed;
443 int uncontrolled_pipeline_head_speed; 406 int uncontrolled_pipeline_head_speed;
444 int controlled_last_pipeline_head; 407 int controlled_last_pipeline_head;
445 int uncontrolled_last_pipeline_head;
446 unsigned long uncontrolled_pipeline_head_time; 408 unsigned long uncontrolled_pipeline_head_time;
447 unsigned long controlled_pipeline_head_time; 409 unsigned long controlled_pipeline_head_time;
448 int controlled_previous_pipeline_head; 410 int controlled_previous_pipeline_head;
@@ -451,18 +413,7 @@ typedef struct ide_tape_obj {
451 unsigned long uncontrolled_previous_head_time; 413 unsigned long uncontrolled_previous_head_time;
452 int restart_speed_control_req; 414 int restart_speed_control_req;
453 415
454 /* 416 u32 debug_mask;
455 * Debug_level determines amount of debugging output;
456 * can be changed using /proc/ide/hdx/settings
457 * 0 : almost no debugging output
458 * 1 : 0+output errors only
459 * 2 : 1+output all sensekey/asc
460 * 3 : 2+follow all chrdev related procedures
461 * 4 : 3+follow all procedures
462 * 5 : 4+include pc_stack rq_stack info
463 * 6 : 5+USE_COUNT updates
464 */
465 int debug_level;
466} idetape_tape_t; 417} idetape_tape_t;
467 418
468static DEFINE_MUTEX(idetape_ref_mutex); 419static DEFINE_MUTEX(idetape_ref_mutex);
@@ -495,9 +446,7 @@ static void ide_tape_put(struct ide_tape_obj *tape)
495 mutex_unlock(&idetape_ref_mutex); 446 mutex_unlock(&idetape_ref_mutex);
496} 447}
497 448
498/* 449/* Tape door status */
499 * Tape door status
500 */
501#define DOOR_UNLOCKED 0 450#define DOOR_UNLOCKED 0
502#define DOOR_LOCKED 1 451#define DOOR_LOCKED 1
503#define DOOR_EXPLICITLY_LOCKED 2 452#define DOOR_EXPLICITLY_LOCKED 2
@@ -517,30 +466,23 @@ static void ide_tape_put(struct ide_tape_obj *tape)
517/* 0 = no tape is loaded, so we don't rewind after ejecting */ 466/* 0 = no tape is loaded, so we don't rewind after ejecting */
518#define IDETAPE_MEDIUM_PRESENT 9 467#define IDETAPE_MEDIUM_PRESENT 9
519 468
520/* 469/* A define for the READ BUFFER command */
521 * Some defines for the READ BUFFER command
522 */
523#define IDETAPE_RETRIEVE_FAULTY_BLOCK 6 470#define IDETAPE_RETRIEVE_FAULTY_BLOCK 6
524 471
525/* 472/* Some defines for the SPACE command */
526 * Some defines for the SPACE command
527 */
528#define IDETAPE_SPACE_OVER_FILEMARK 1 473#define IDETAPE_SPACE_OVER_FILEMARK 1
529#define IDETAPE_SPACE_TO_EOD 3 474#define IDETAPE_SPACE_TO_EOD 3
530 475
531/* 476/* Some defines for the LOAD UNLOAD command */
532 * Some defines for the LOAD UNLOAD command
533 */
534#define IDETAPE_LU_LOAD_MASK 1 477#define IDETAPE_LU_LOAD_MASK 1
535#define IDETAPE_LU_RETENSION_MASK 2 478#define IDETAPE_LU_RETENSION_MASK 2
536#define IDETAPE_LU_EOT_MASK 4 479#define IDETAPE_LU_EOT_MASK 4
537 480
538/* 481/*
539 * Special requests for our block device strategy routine. 482 * Special requests for our block device strategy routine.
540 * 483 *
541 * In order to service a character device command, we add special 484 * In order to service a character device command, we add special requests to
542 * requests to the tail of our block device request queue and wait 485 * the tail of our block device request queue and wait for their completion.
543 * for their completion.
544 */ 486 */
545 487
546enum { 488enum {
@@ -551,55 +493,20 @@ enum {
551 REQ_IDETAPE_READ_BUFFER = (1 << 4), 493 REQ_IDETAPE_READ_BUFFER = (1 << 4),
552}; 494};
553 495
554/* 496/* Error codes returned in rq->errors to the higher part of the driver. */
555 * Error codes which are returned in rq->errors to the higher part
556 * of the driver.
557 */
558#define IDETAPE_ERROR_GENERAL 101 497#define IDETAPE_ERROR_GENERAL 101
559#define IDETAPE_ERROR_FILEMARK 102 498#define IDETAPE_ERROR_FILEMARK 102
560#define IDETAPE_ERROR_EOD 103 499#define IDETAPE_ERROR_EOD 103
561 500
562/*
563 * The following is used to format the general configuration word of
564 * the ATAPI IDENTIFY DEVICE command.
565 */
566struct idetape_id_gcw {
567 unsigned packet_size :2; /* Packet Size */
568 unsigned reserved234 :3; /* Reserved */
569 unsigned drq_type :2; /* Command packet DRQ type */
570 unsigned removable :1; /* Removable media */
571 unsigned device_type :5; /* Device type */
572 unsigned reserved13 :1; /* Reserved */
573 unsigned protocol :2; /* Protocol type */
574};
575
576/*
577 * READ POSITION packet command - Data Format (From Table 6-57)
578 */
579typedef struct {
580 unsigned reserved0_10 :2; /* Reserved */
581 unsigned bpu :1; /* Block Position Unknown */
582 unsigned reserved0_543 :3; /* Reserved */
583 unsigned eop :1; /* End Of Partition */
584 unsigned bop :1; /* Beginning Of Partition */
585 u8 partition; /* Partition Number */
586 u8 reserved2, reserved3; /* Reserved */
587 u32 first_block; /* First Block Location */
588 u32 last_block; /* Last Block Location (Optional) */
589 u8 reserved12; /* Reserved */
590 u8 blocks_in_buffer[3]; /* Blocks In Buffer - (Optional) */
591 u32 bytes_in_buffer; /* Bytes In Buffer (Optional) */
592} idetape_read_position_result_t;
593
594/* Structures related to the SELECT SENSE / MODE SENSE packet commands. */ 501/* Structures related to the SELECT SENSE / MODE SENSE packet commands. */
595#define IDETAPE_BLOCK_DESCRIPTOR 0 502#define IDETAPE_BLOCK_DESCRIPTOR 0
596#define IDETAPE_CAPABILITIES_PAGE 0x2a 503#define IDETAPE_CAPABILITIES_PAGE 0x2a
597 504
598/* 505/*
599 * The variables below are used for the character device interface. 506 * The variables below are used for the character device interface. Additional
600 * Additional state variables are defined in our ide_drive_t structure. 507 * state variables are defined in our ide_drive_t structure.
601 */ 508 */
602static struct ide_tape_obj * idetape_devs[MAX_HWIFS * MAX_DRIVES]; 509static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES];
603 510
604#define ide_tape_f(file) ((file)->private_data) 511#define ide_tape_f(file) ((file)->private_data)
605 512
@@ -616,23 +523,17 @@ static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i)
616} 523}
617 524
618/* 525/*
619 * Function declarations
620 *
621 */
622static int idetape_chrdev_release (struct inode *inode, struct file *filp);
623static void idetape_write_release (ide_drive_t *drive, unsigned int minor);
624
625/*
626 * Too bad. The drive wants to send us data which we are not ready to accept. 526 * Too bad. The drive wants to send us data which we are not ready to accept.
627 * Just throw it away. 527 * Just throw it away.
628 */ 528 */
629static void idetape_discard_data (ide_drive_t *drive, unsigned int bcount) 529static void idetape_discard_data(ide_drive_t *drive, unsigned int bcount)
630{ 530{
631 while (bcount--) 531 while (bcount--)
632 (void) HWIF(drive)->INB(IDE_DATA_REG); 532 (void) HWIF(drive)->INB(IDE_DATA_REG);
633} 533}
634 534
635static void idetape_input_buffers (ide_drive_t *drive, idetape_pc_t *pc, unsigned int bcount) 535static void idetape_input_buffers(ide_drive_t *drive, idetape_pc_t *pc,
536 unsigned int bcount)
636{ 537{
637 struct idetape_bh *bh = pc->bh; 538 struct idetape_bh *bh = pc->bh;
638 int count; 539 int count;
@@ -644,8 +545,11 @@ static void idetape_input_buffers (ide_drive_t *drive, idetape_pc_t *pc, unsigne
644 idetape_discard_data(drive, bcount); 545 idetape_discard_data(drive, bcount);
645 return; 546 return;
646 } 547 }
647 count = min((unsigned int)(bh->b_size - atomic_read(&bh->b_count)), bcount); 548 count = min(
648 HWIF(drive)->atapi_input_bytes(drive, bh->b_data + atomic_read(&bh->b_count), count); 549 (unsigned int)(bh->b_size - atomic_read(&bh->b_count)),
550 bcount);
551 HWIF(drive)->atapi_input_bytes(drive, bh->b_data +
552 atomic_read(&bh->b_count), count);
649 bcount -= count; 553 bcount -= count;
650 atomic_add(count, &bh->b_count); 554 atomic_add(count, &bh->b_count);
651 if (atomic_read(&bh->b_count) == bh->b_size) { 555 if (atomic_read(&bh->b_count) == bh->b_size) {
@@ -657,15 +561,16 @@ static void idetape_input_buffers (ide_drive_t *drive, idetape_pc_t *pc, unsigne
657 pc->bh = bh; 561 pc->bh = bh;
658} 562}
659 563
660static void idetape_output_buffers (ide_drive_t *drive, idetape_pc_t *pc, unsigned int bcount) 564static void idetape_output_buffers(ide_drive_t *drive, idetape_pc_t *pc,
565 unsigned int bcount)
661{ 566{
662 struct idetape_bh *bh = pc->bh; 567 struct idetape_bh *bh = pc->bh;
663 int count; 568 int count;
664 569
665 while (bcount) { 570 while (bcount) {
666 if (bh == NULL) { 571 if (bh == NULL) {
667 printk(KERN_ERR "ide-tape: bh == NULL in " 572 printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
668 "idetape_output_buffers\n"); 573 __func__);
669 return; 574 return;
670 } 575 }
671 count = min((unsigned int)pc->b_count, (unsigned int)bcount); 576 count = min((unsigned int)pc->b_count, (unsigned int)bcount);
@@ -674,7 +579,8 @@ static void idetape_output_buffers (ide_drive_t *drive, idetape_pc_t *pc, unsign
674 pc->b_data += count; 579 pc->b_data += count;
675 pc->b_count -= count; 580 pc->b_count -= count;
676 if (!pc->b_count) { 581 if (!pc->b_count) {
677 pc->bh = bh = bh->b_reqnext; 582 bh = bh->b_reqnext;
583 pc->bh = bh;
678 if (bh) { 584 if (bh) {
679 pc->b_data = bh->b_data; 585 pc->b_data = bh->b_data;
680 pc->b_count = atomic_read(&bh->b_count); 586 pc->b_count = atomic_read(&bh->b_count);
@@ -683,7 +589,7 @@ static void idetape_output_buffers (ide_drive_t *drive, idetape_pc_t *pc, unsign
683 } 589 }
684} 590}
685 591
686static void idetape_update_buffers (idetape_pc_t *pc) 592static void idetape_update_buffers(idetape_pc_t *pc)
687{ 593{
688 struct idetape_bh *bh = pc->bh; 594 struct idetape_bh *bh = pc->bh;
689 int count; 595 int count;
@@ -693,8 +599,8 @@ static void idetape_update_buffers (idetape_pc_t *pc)
693 return; 599 return;
694 while (bcount) { 600 while (bcount) {
695 if (bh == NULL) { 601 if (bh == NULL) {
696 printk(KERN_ERR "ide-tape: bh == NULL in " 602 printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
697 "idetape_update_buffers\n"); 603 __func__);
698 return; 604 return;
699 } 605 }
700 count = min((unsigned int)bh->b_size, (unsigned int)bcount); 606 count = min((unsigned int)bh->b_size, (unsigned int)bcount);
@@ -712,17 +618,14 @@ static void idetape_update_buffers (idetape_pc_t *pc)
712 * driver. A storage space for a maximum of IDETAPE_PC_STACK packet 618 * driver. A storage space for a maximum of IDETAPE_PC_STACK packet
713 * commands is allocated at initialization time. 619 * commands is allocated at initialization time.
714 */ 620 */
715static idetape_pc_t *idetape_next_pc_storage (ide_drive_t *drive) 621static idetape_pc_t *idetape_next_pc_storage(ide_drive_t *drive)
716{ 622{
717 idetape_tape_t *tape = drive->driver_data; 623 idetape_tape_t *tape = drive->driver_data;
718 624
719#if IDETAPE_DEBUG_LOG 625 debug_log(DBG_PCRQ_STACK, "pc_stack_index=%d\n", tape->pc_stack_index);
720 if (tape->debug_level >= 5) 626
721 printk(KERN_INFO "ide-tape: pc_stack_index=%d\n",
722 tape->pc_stack_index);
723#endif /* IDETAPE_DEBUG_LOG */
724 if (tape->pc_stack_index == IDETAPE_PC_STACK) 627 if (tape->pc_stack_index == IDETAPE_PC_STACK)
725 tape->pc_stack_index=0; 628 tape->pc_stack_index = 0;
726 return (&tape->pc_stack[tape->pc_stack_index++]); 629 return (&tape->pc_stack[tape->pc_stack_index++]);
727} 630}
728 631
@@ -731,32 +634,26 @@ static idetape_pc_t *idetape_next_pc_storage (ide_drive_t *drive)
731 * Since we queue packet commands in the request queue, we need to 634 * Since we queue packet commands in the request queue, we need to
732 * allocate a request, along with the allocation of a packet command. 635 * allocate a request, along with the allocation of a packet command.
733 */ 636 */
734 637
735/************************************************************** 638/**************************************************************
736 * * 639 * *
737 * This should get fixed to use kmalloc(.., GFP_ATOMIC) * 640 * This should get fixed to use kmalloc(.., GFP_ATOMIC) *
738 * followed later on by kfree(). -ml * 641 * followed later on by kfree(). -ml *
739 * * 642 * *
740 **************************************************************/ 643 **************************************************************/
741 644
742static struct request *idetape_next_rq_storage (ide_drive_t *drive) 645static struct request *idetape_next_rq_storage(ide_drive_t *drive)
743{ 646{
744 idetape_tape_t *tape = drive->driver_data; 647 idetape_tape_t *tape = drive->driver_data;
745 648
746#if IDETAPE_DEBUG_LOG 649 debug_log(DBG_PCRQ_STACK, "rq_stack_index=%d\n", tape->rq_stack_index);
747 if (tape->debug_level >= 5) 650
748 printk(KERN_INFO "ide-tape: rq_stack_index=%d\n",
749 tape->rq_stack_index);
750#endif /* IDETAPE_DEBUG_LOG */
751 if (tape->rq_stack_index == IDETAPE_PC_STACK) 651 if (tape->rq_stack_index == IDETAPE_PC_STACK)
752 tape->rq_stack_index=0; 652 tape->rq_stack_index = 0;
753 return (&tape->rq_stack[tape->rq_stack_index++]); 653 return (&tape->rq_stack[tape->rq_stack_index++]);
754} 654}
755 655
756/* 656static void idetape_init_pc(idetape_pc_t *pc)
757 * idetape_init_pc initializes a packet command.
758 */
759static void idetape_init_pc (idetape_pc_t *pc)
760{ 657{
761 memset(pc->c, 0, 12); 658 memset(pc->c, 0, 12);
762 pc->retries = 0; 659 pc->retries = 0;
@@ -780,22 +677,14 @@ static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
780 tape->sense_key = sense[2] & 0xF; 677 tape->sense_key = sense[2] & 0xF;
781 tape->asc = sense[12]; 678 tape->asc = sense[12];
782 tape->ascq = sense[13]; 679 tape->ascq = sense[13];
783#if IDETAPE_DEBUG_LOG 680
784 /* 681 debug_log(DBG_ERR, "pc = %x, sense key = %x, asc = %x, ascq = %x\n",
785 * Without debugging, we only log an error if we decided to give up 682 pc->c[0], tape->sense_key, tape->asc, tape->ascq);
786 * retrying.
787 */
788 if (tape->debug_level >= 1)
789 printk(KERN_INFO "ide-tape: pc = %x, sense key = %x, "
790 "asc = %x, ascq = %x\n",
791 pc->c[0], tape->sense_key,
792 tape->asc, tape->ascq);
793#endif /* IDETAPE_DEBUG_LOG */
794 683
795 /* Correct pc->actually_transferred by asking the tape. */ 684 /* Correct pc->actually_transferred by asking the tape. */
796 if (test_bit(PC_DMA_ERROR, &pc->flags)) { 685 if (test_bit(PC_DMA_ERROR, &pc->flags)) {
797 pc->actually_transferred = pc->request_transfer - 686 pc->actually_transferred = pc->request_transfer -
798 tape->tape_block_size * 687 tape->blk_size *
799 be32_to_cpu(get_unaligned((u32 *)&sense[3])); 688 be32_to_cpu(get_unaligned((u32 *)&sense[3]));
800 idetape_update_buffers(pc); 689 idetape_update_buffers(pc);
801 } 690 }
@@ -843,50 +732,24 @@ static void idetape_activate_next_stage(ide_drive_t *drive)
843 idetape_stage_t *stage = tape->next_stage; 732 idetape_stage_t *stage = tape->next_stage;
844 struct request *rq = &stage->rq; 733 struct request *rq = &stage->rq;
845 734
846#if IDETAPE_DEBUG_LOG 735 debug_log(DBG_PROCS, "Enter %s\n", __func__);
847 if (tape->debug_level >= 4) 736
848 printk(KERN_INFO "ide-tape: Reached idetape_active_next_stage\n");
849#endif /* IDETAPE_DEBUG_LOG */
850 if (stage == NULL) { 737 if (stage == NULL) {
851 printk(KERN_ERR "ide-tape: bug: Trying to activate a non existing stage\n"); 738 printk(KERN_ERR "ide-tape: bug: Trying to activate a non"
739 " existing stage\n");
852 return; 740 return;
853 } 741 }
854 742
855 rq->rq_disk = tape->disk; 743 rq->rq_disk = tape->disk;
856 rq->buffer = NULL; 744 rq->buffer = NULL;
857 rq->special = (void *)stage->bh; 745 rq->special = (void *)stage->bh;
858 tape->active_data_request = rq; 746 tape->active_data_rq = rq;
859 tape->active_stage = stage; 747 tape->active_stage = stage;
860 tape->next_stage = stage->next; 748 tape->next_stage = stage->next;
861} 749}
862 750
863/* 751/* Free a stage along with its related buffers completely. */
864 * idetape_increase_max_pipeline_stages is a part of the feedback 752static void __idetape_kfree_stage(idetape_stage_t *stage)
865 * loop which tries to find the optimum number of stages. In the
866 * feedback loop, we are starting from a minimum maximum number of
867 * stages, and if we sense that the pipeline is empty, we try to
868 * increase it, until we reach the user compile time memory limit.
869 */
870static void idetape_increase_max_pipeline_stages (ide_drive_t *drive)
871{
872 idetape_tape_t *tape = drive->driver_data;
873 int increase = (tape->max_pipeline - tape->min_pipeline) / 10;
874
875#if IDETAPE_DEBUG_LOG
876 if (tape->debug_level >= 4)
877 printk (KERN_INFO "ide-tape: Reached idetape_increase_max_pipeline_stages\n");
878#endif /* IDETAPE_DEBUG_LOG */
879
880 tape->max_stages += max(increase, 1);
881 tape->max_stages = max(tape->max_stages, tape->min_pipeline);
882 tape->max_stages = min(tape->max_stages, tape->max_pipeline);
883}
884
885/*
886 * idetape_kfree_stage calls kfree to completely free a stage, along with
887 * its related buffers.
888 */
889static void __idetape_kfree_stage (idetape_stage_t *stage)
890{ 753{
891 struct idetape_bh *prev_bh, *bh = stage->bh; 754 struct idetape_bh *prev_bh, *bh = stage->bh;
892 int size; 755 int size;
@@ -907,30 +770,29 @@ static void __idetape_kfree_stage (idetape_stage_t *stage)
907 kfree(stage); 770 kfree(stage);
908} 771}
909 772
910static void idetape_kfree_stage (idetape_tape_t *tape, idetape_stage_t *stage) 773static void idetape_kfree_stage(idetape_tape_t *tape, idetape_stage_t *stage)
911{ 774{
912 __idetape_kfree_stage(stage); 775 __idetape_kfree_stage(stage);
913} 776}
914 777
915/* 778/*
916 * idetape_remove_stage_head removes tape->first_stage from the pipeline. 779 * Remove tape->first_stage from the pipeline. The caller should avoid race
917 * The caller should avoid race conditions. 780 * conditions.
918 */ 781 */
919static void idetape_remove_stage_head (ide_drive_t *drive) 782static void idetape_remove_stage_head(ide_drive_t *drive)
920{ 783{
921 idetape_tape_t *tape = drive->driver_data; 784 idetape_tape_t *tape = drive->driver_data;
922 idetape_stage_t *stage; 785 idetape_stage_t *stage;
923 786
924#if IDETAPE_DEBUG_LOG 787 debug_log(DBG_PROCS, "Enter %s\n", __func__);
925 if (tape->debug_level >= 4) 788
926 printk(KERN_INFO "ide-tape: Reached idetape_remove_stage_head\n");
927#endif /* IDETAPE_DEBUG_LOG */
928 if (tape->first_stage == NULL) { 789 if (tape->first_stage == NULL) {
929 printk(KERN_ERR "ide-tape: bug: tape->first_stage is NULL\n"); 790 printk(KERN_ERR "ide-tape: bug: tape->first_stage is NULL\n");
930 return; 791 return;
931 } 792 }
932 if (tape->active_stage == tape->first_stage) { 793 if (tape->active_stage == tape->first_stage) {
933 printk(KERN_ERR "ide-tape: bug: Trying to free our active pipeline stage\n"); 794 printk(KERN_ERR "ide-tape: bug: Trying to free our active "
795 "pipeline stage\n");
934 return; 796 return;
935 } 797 }
936 stage = tape->first_stage; 798 stage = tape->first_stage;
@@ -940,9 +802,11 @@ static void idetape_remove_stage_head (ide_drive_t *drive)
940 if (tape->first_stage == NULL) { 802 if (tape->first_stage == NULL) {
941 tape->last_stage = NULL; 803 tape->last_stage = NULL;
942 if (tape->next_stage != NULL) 804 if (tape->next_stage != NULL)
943 printk(KERN_ERR "ide-tape: bug: tape->next_stage != NULL\n"); 805 printk(KERN_ERR "ide-tape: bug: tape->next_stage !="
806 " NULL\n");
944 if (tape->nr_stages) 807 if (tape->nr_stages)
945 printk(KERN_ERR "ide-tape: bug: nr_stages should be 0 now\n"); 808 printk(KERN_ERR "ide-tape: bug: nr_stages should be 0 "
809 "now\n");
946 } 810 }
947} 811}
948 812
@@ -957,10 +821,8 @@ static void idetape_abort_pipeline(ide_drive_t *drive,
957 idetape_stage_t *stage = new_last_stage->next; 821 idetape_stage_t *stage = new_last_stage->next;
958 idetape_stage_t *nstage; 822 idetape_stage_t *nstage;
959 823
960#if IDETAPE_DEBUG_LOG 824 debug_log(DBG_PROCS, "%s: Enter %s\n", tape->name, __func__);
961 if (tape->debug_level >= 4) 825
962 printk(KERN_INFO "ide-tape: %s: idetape_abort_pipeline called\n", tape->name);
963#endif
964 while (stage) { 826 while (stage) {
965 nstage = stage->next; 827 nstage = stage->next;
966 idetape_kfree_stage(tape, stage); 828 idetape_kfree_stage(tape, stage);
@@ -975,8 +837,8 @@ static void idetape_abort_pipeline(ide_drive_t *drive,
975} 837}
976 838
977/* 839/*
978 * idetape_end_request is used to finish servicing a request, and to 840 * Finish servicing a request and insert a pending pipeline request into the
979 * insert a pending pipeline request into the main device queue. 841 * main device queue.
980 */ 842 */
981static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects) 843static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
982{ 844{
@@ -987,15 +849,12 @@ static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
987 int remove_stage = 0; 849 int remove_stage = 0;
988 idetape_stage_t *active_stage; 850 idetape_stage_t *active_stage;
989 851
990#if IDETAPE_DEBUG_LOG 852 debug_log(DBG_PROCS, "Enter %s\n", __func__);
991 if (tape->debug_level >= 4)
992 printk(KERN_INFO "ide-tape: Reached idetape_end_request\n");
993#endif /* IDETAPE_DEBUG_LOG */
994 853
995 switch (uptodate) { 854 switch (uptodate) {
996 case 0: error = IDETAPE_ERROR_GENERAL; break; 855 case 0: error = IDETAPE_ERROR_GENERAL; break;
997 case 1: error = 0; break; 856 case 1: error = 0; break;
998 default: error = uptodate; 857 default: error = uptodate;
999 } 858 }
1000 rq->errors = error; 859 rq->errors = error;
1001 if (error) 860 if (error)
@@ -1006,20 +865,21 @@ static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
1006 return 0; 865 return 0;
1007 } 866 }
1008 867
1009 spin_lock_irqsave(&tape->spinlock, flags); 868 spin_lock_irqsave(&tape->lock, flags);
1010 869
1011 /* The request was a pipelined data transfer request */ 870 /* The request was a pipelined data transfer request */
1012 if (tape->active_data_request == rq) { 871 if (tape->active_data_rq == rq) {
1013 active_stage = tape->active_stage; 872 active_stage = tape->active_stage;
1014 tape->active_stage = NULL; 873 tape->active_stage = NULL;
1015 tape->active_data_request = NULL; 874 tape->active_data_rq = NULL;
1016 tape->nr_pending_stages--; 875 tape->nr_pending_stages--;
1017 if (rq->cmd[0] & REQ_IDETAPE_WRITE) { 876 if (rq->cmd[0] & REQ_IDETAPE_WRITE) {
1018 remove_stage = 1; 877 remove_stage = 1;
1019 if (error) { 878 if (error) {
1020 set_bit(IDETAPE_PIPELINE_ERROR, &tape->flags); 879 set_bit(IDETAPE_PIPELINE_ERROR, &tape->flags);
1021 if (error == IDETAPE_ERROR_EOD) 880 if (error == IDETAPE_ERROR_EOD)
1022 idetape_abort_pipeline(drive, active_stage); 881 idetape_abort_pipeline(drive,
882 active_stage);
1023 } 883 }
1024 } else if (rq->cmd[0] & REQ_IDETAPE_READ) { 884 } else if (rq->cmd[0] & REQ_IDETAPE_READ) {
1025 if (error == IDETAPE_ERROR_EOD) { 885 if (error == IDETAPE_ERROR_EOD) {
@@ -1030,48 +890,57 @@ static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
1030 if (tape->next_stage != NULL) { 890 if (tape->next_stage != NULL) {
1031 idetape_activate_next_stage(drive); 891 idetape_activate_next_stage(drive);
1032 892
893 /* Insert the next request into the request queue. */
894 (void)ide_do_drive_cmd(drive, tape->active_data_rq,
895 ide_end);
896 } else if (!error) {
1033 /* 897 /*
1034 * Insert the next request into the request queue. 898 * This is a part of the feedback loop which tries to
899 * find the optimum number of stages. We are starting
900 * from a minimum maximum number of stages, and if we
901 * sense that the pipeline is empty, we try to increase
902 * it, until we reach the user compile time memory
903 * limit.
1035 */ 904 */
1036 (void) ide_do_drive_cmd(drive, tape->active_data_request, ide_end); 905 int i = (tape->max_pipeline - tape->min_pipeline) / 10;
1037 } else if (!error) { 906
1038 idetape_increase_max_pipeline_stages(drive); 907 tape->max_stages += max(i, 1);
908 tape->max_stages = max(tape->max_stages,
909 tape->min_pipeline);
910 tape->max_stages = min(tape->max_stages,
911 tape->max_pipeline);
1039 } 912 }
1040 } 913 }
1041 ide_end_drive_cmd(drive, 0, 0); 914 ide_end_drive_cmd(drive, 0, 0);
1042// blkdev_dequeue_request(rq);
1043// drive->rq = NULL;
1044// end_that_request_last(rq);
1045 915
1046 if (remove_stage) 916 if (remove_stage)
1047 idetape_remove_stage_head(drive); 917 idetape_remove_stage_head(drive);
1048 if (tape->active_data_request == NULL) 918 if (tape->active_data_rq == NULL)
1049 clear_bit(IDETAPE_PIPELINE_ACTIVE, &tape->flags); 919 clear_bit(IDETAPE_PIPELINE_ACTIVE, &tape->flags);
1050 spin_unlock_irqrestore(&tape->spinlock, flags); 920 spin_unlock_irqrestore(&tape->lock, flags);
1051 return 0; 921 return 0;
1052} 922}
1053 923
1054static ide_startstop_t idetape_request_sense_callback (ide_drive_t *drive) 924static ide_startstop_t idetape_request_sense_callback(ide_drive_t *drive)
1055{ 925{
1056 idetape_tape_t *tape = drive->driver_data; 926 idetape_tape_t *tape = drive->driver_data;
1057 927
1058#if IDETAPE_DEBUG_LOG 928 debug_log(DBG_PROCS, "Enter %s\n", __func__);
1059 if (tape->debug_level >= 4) 929
1060 printk(KERN_INFO "ide-tape: Reached idetape_request_sense_callback\n");
1061#endif /* IDETAPE_DEBUG_LOG */
1062 if (!tape->pc->error) { 930 if (!tape->pc->error) {
1063 idetape_analyze_error(drive, tape->pc->buffer); 931 idetape_analyze_error(drive, tape->pc->buffer);
1064 idetape_end_request(drive, 1, 0); 932 idetape_end_request(drive, 1, 0);
1065 } else { 933 } else {
1066 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE itself - Aborting request!\n"); 934 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE itself - "
935 "Aborting request!\n");
1067 idetape_end_request(drive, 0, 0); 936 idetape_end_request(drive, 0, 0);
1068 } 937 }
1069 return ide_stopped; 938 return ide_stopped;
1070} 939}
1071 940
1072static void idetape_create_request_sense_cmd (idetape_pc_t *pc) 941static void idetape_create_request_sense_cmd(idetape_pc_t *pc)
1073{ 942{
1074 idetape_init_pc(pc); 943 idetape_init_pc(pc);
1075 pc->c[0] = REQUEST_SENSE; 944 pc->c[0] = REQUEST_SENSE;
1076 pc->c[4] = 20; 945 pc->c[4] = 20;
1077 pc->request_transfer = 20; 946 pc->request_transfer = 20;
@@ -1086,25 +955,22 @@ static void idetape_init_rq(struct request *rq, u8 cmd)
1086} 955}
1087 956
1088/* 957/*
1089 * idetape_queue_pc_head generates a new packet command request in front 958 * Generate a new packet command request in front of the request queue, before
1090 * of the request queue, before the current request, so that it will be 959 * the current request, so that it will be processed immediately, on the next
1091 * processed immediately, on the next pass through the driver. 960 * pass through the driver. The function below is called from the request
1092 * 961 * handling part of the driver (the "bottom" part). Safe storage for the request
1093 * idetape_queue_pc_head is called from the request handling part of 962 * should be allocated with ide_tape_next_{pc,rq}_storage() prior to that.
1094 * the driver (the "bottom" part). Safe storage for the request should
1095 * be allocated with idetape_next_pc_storage and idetape_next_rq_storage
1096 * before calling idetape_queue_pc_head.
1097 * 963 *
1098 * Memory for those requests is pre-allocated at initialization time, and 964 * Memory for those requests is pre-allocated at initialization time, and is
1099 * is limited to IDETAPE_PC_STACK requests. We assume that we have enough 965 * limited to IDETAPE_PC_STACK requests. We assume that we have enough space for
1100 * space for the maximum possible number of inter-dependent packet commands. 966 * the maximum possible number of inter-dependent packet commands.
1101 * 967 *
1102 * The higher level of the driver - The ioctl handler and the character 968 * The higher level of the driver - The ioctl handler and the character device
1103 * device handling functions should queue request to the lower level part 969 * handling functions should queue request to the lower level part and wait for
1104 * and wait for their completion using idetape_queue_pc_tail or 970 * their completion using idetape_queue_pc_tail or idetape_queue_rw_tail.
1105 * idetape_queue_rw_tail.
1106 */ 971 */
1107static void idetape_queue_pc_head (ide_drive_t *drive, idetape_pc_t *pc,struct request *rq) 972static void idetape_queue_pc_head(ide_drive_t *drive, idetape_pc_t *pc,
973 struct request *rq)
1108{ 974{
1109 struct ide_tape_obj *tape = drive->driver_data; 975 struct ide_tape_obj *tape = drive->driver_data;
1110 976
@@ -1125,7 +991,7 @@ static ide_startstop_t idetape_retry_pc (ide_drive_t *drive)
1125 idetape_pc_t *pc; 991 idetape_pc_t *pc;
1126 struct request *rq; 992 struct request *rq;
1127 993
1128 (void)drive->hwif->INB(IDE_ERROR_REG); 994 (void)ide_read_error(drive);
1129 pc = idetape_next_pc_storage(drive); 995 pc = idetape_next_pc_storage(drive);
1130 rq = idetape_next_rq_storage(drive); 996 rq = idetape_next_rq_storage(drive);
1131 idetape_create_request_sense_cmd(pc); 997 idetape_create_request_sense_cmd(pc);
@@ -1135,50 +1001,46 @@ static ide_startstop_t idetape_retry_pc (ide_drive_t *drive)
1135} 1001}
1136 1002
1137/* 1003/*
1138 * idetape_postpone_request postpones the current request so that 1004 * Postpone the current request so that ide.c will be able to service requests
1139 * ide.c will be able to service requests from another device on 1005 * from another device on the same hwgroup while we are polling for DSC.
1140 * the same hwgroup while we are polling for DSC.
1141 */ 1006 */
1142static void idetape_postpone_request (ide_drive_t *drive) 1007static void idetape_postpone_request(ide_drive_t *drive)
1143{ 1008{
1144 idetape_tape_t *tape = drive->driver_data; 1009 idetape_tape_t *tape = drive->driver_data;
1145 1010
1146#if IDETAPE_DEBUG_LOG 1011 debug_log(DBG_PROCS, "Enter %s\n", __func__);
1147 if (tape->debug_level >= 4) 1012
1148 printk(KERN_INFO "ide-tape: idetape_postpone_request\n");
1149#endif
1150 tape->postponed_rq = HWGROUP(drive)->rq; 1013 tape->postponed_rq = HWGROUP(drive)->rq;
1151 ide_stall_queue(drive, tape->dsc_polling_frequency); 1014 ide_stall_queue(drive, tape->dsc_poll_freq);
1152} 1015}
1153 1016
1017typedef void idetape_io_buf(ide_drive_t *, idetape_pc_t *, unsigned int);
1018
1154/* 1019/*
1155 * idetape_pc_intr is the usual interrupt handler which will be called 1020 * This is the usual interrupt handler which will be called during a packet
1156 * during a packet command. We will transfer some of the data (as 1021 * command. We will transfer some of the data (as requested by the drive) and
1157 * requested by the drive) and will re-point interrupt handler to us. 1022 * will re-point interrupt handler to us. When data transfer is finished, we
1158 * When data transfer is finished, we will act according to the 1023 * will act according to the algorithm described before
1159 * algorithm described before idetape_issue_packet_command. 1024 * idetape_issue_pc.
1160 *
1161 */ 1025 */
1162static ide_startstop_t idetape_pc_intr (ide_drive_t *drive) 1026static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
1163{ 1027{
1164 ide_hwif_t *hwif = drive->hwif; 1028 ide_hwif_t *hwif = drive->hwif;
1165 idetape_tape_t *tape = drive->driver_data; 1029 idetape_tape_t *tape = drive->driver_data;
1166 idetape_pc_t *pc = tape->pc; 1030 idetape_pc_t *pc = tape->pc;
1031 xfer_func_t *xferfunc;
1032 idetape_io_buf *iobuf;
1167 unsigned int temp; 1033 unsigned int temp;
1168#if SIMULATE_ERRORS 1034#if SIMULATE_ERRORS
1169 static int error_sim_count = 0; 1035 static int error_sim_count;
1170#endif 1036#endif
1171 u16 bcount; 1037 u16 bcount;
1172 u8 stat, ireason; 1038 u8 stat, ireason;
1173 1039
1174#if IDETAPE_DEBUG_LOG 1040 debug_log(DBG_PROCS, "Enter %s - interrupt handler\n", __func__);
1175 if (tape->debug_level >= 4)
1176 printk(KERN_INFO "ide-tape: Reached idetape_pc_intr "
1177 "interrupt handler\n");
1178#endif /* IDETAPE_DEBUG_LOG */
1179 1041
1180 /* Clear the interrupt */ 1042 /* Clear the interrupt */
1181 stat = hwif->INB(IDE_STATUS_REG); 1043 stat = ide_read_status(drive);
1182 1044
1183 if (test_bit(PC_DMA_IN_PROGRESS, &pc->flags)) { 1045 if (test_bit(PC_DMA_IN_PROGRESS, &pc->flags)) {
1184 if (hwif->ide_dma_end(drive) || (stat & ERR_STAT)) { 1046 if (hwif->ide_dma_end(drive) || (stat & ERR_STAT)) {
@@ -1208,20 +1070,16 @@ static ide_startstop_t idetape_pc_intr (ide_drive_t *drive)
1208 pc->actually_transferred = pc->request_transfer; 1070 pc->actually_transferred = pc->request_transfer;
1209 idetape_update_buffers(pc); 1071 idetape_update_buffers(pc);
1210 } 1072 }
1211#if IDETAPE_DEBUG_LOG 1073 debug_log(DBG_PROCS, "DMA finished\n");
1212 if (tape->debug_level >= 4) 1074
1213 printk(KERN_INFO "ide-tape: DMA finished\n");
1214#endif /* IDETAPE_DEBUG_LOG */
1215 } 1075 }
1216 1076
1217 /* No more interrupts */ 1077 /* No more interrupts */
1218 if ((stat & DRQ_STAT) == 0) { 1078 if ((stat & DRQ_STAT) == 0) {
1219#if IDETAPE_DEBUG_LOG 1079 debug_log(DBG_SENSE, "Packet command completed, %d bytes"
1220 if (tape->debug_level >= 2) 1080 " transferred\n", pc->actually_transferred);
1221 printk(KERN_INFO "ide-tape: Packet command completed, %d bytes transferred\n", pc->actually_transferred);
1222#endif /* IDETAPE_DEBUG_LOG */
1223 clear_bit(PC_DMA_IN_PROGRESS, &pc->flags);
1224 1081
1082 clear_bit(PC_DMA_IN_PROGRESS, &pc->flags);
1225 local_irq_enable(); 1083 local_irq_enable();
1226 1084
1227#if SIMULATE_ERRORS 1085#if SIMULATE_ERRORS
@@ -1236,19 +1094,16 @@ static ide_startstop_t idetape_pc_intr (ide_drive_t *drive)
1236 stat &= ~ERR_STAT; 1094 stat &= ~ERR_STAT;
1237 if ((stat & ERR_STAT) || test_bit(PC_DMA_ERROR, &pc->flags)) { 1095 if ((stat & ERR_STAT) || test_bit(PC_DMA_ERROR, &pc->flags)) {
1238 /* Error detected */ 1096 /* Error detected */
1239#if IDETAPE_DEBUG_LOG 1097 debug_log(DBG_ERR, "%s: I/O error\n", tape->name);
1240 if (tape->debug_level >= 1) 1098
1241 printk(KERN_INFO "ide-tape: %s: I/O error\n",
1242 tape->name);
1243#endif /* IDETAPE_DEBUG_LOG */
1244 if (pc->c[0] == REQUEST_SENSE) { 1099 if (pc->c[0] == REQUEST_SENSE) {
1245 printk(KERN_ERR "ide-tape: I/O error in request sense command\n"); 1100 printk(KERN_ERR "ide-tape: I/O error in request"
1101 " sense command\n");
1246 return ide_do_reset(drive); 1102 return ide_do_reset(drive);
1247 } 1103 }
1248#if IDETAPE_DEBUG_LOG 1104 debug_log(DBG_ERR, "[cmd %x]: check condition\n",
1249 if (tape->debug_level >= 1) 1105 pc->c[0]);
1250 printk(KERN_INFO "ide-tape: [cmd %x]: check condition\n", pc->c[0]); 1106
1251#endif
1252 /* Retry operation */ 1107 /* Retry operation */
1253 return idetape_retry_pc(drive); 1108 return idetape_retry_pc(drive);
1254 } 1109 }
@@ -1257,7 +1112,7 @@ static ide_startstop_t idetape_pc_intr (ide_drive_t *drive)
1257 (stat & SEEK_STAT) == 0) { 1112 (stat & SEEK_STAT) == 0) {
1258 /* Media access command */ 1113 /* Media access command */
1259 tape->dsc_polling_start = jiffies; 1114 tape->dsc_polling_start = jiffies;
1260 tape->dsc_polling_frequency = IDETAPE_DSC_MA_FAST; 1115 tape->dsc_poll_freq = IDETAPE_DSC_MA_FAST;
1261 tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT; 1116 tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT;
1262 /* Allow ide.c to handle other requests */ 1117 /* Allow ide.c to handle other requests */
1263 idetape_postpone_request(drive); 1118 idetape_postpone_request(drive);
@@ -1282,7 +1137,7 @@ static ide_startstop_t idetape_pc_intr (ide_drive_t *drive)
1282 ireason = hwif->INB(IDE_IREASON_REG); 1137 ireason = hwif->INB(IDE_IREASON_REG);
1283 1138
1284 if (ireason & CD) { 1139 if (ireason & CD) {
1285 printk(KERN_ERR "ide-tape: CoD != 0 in idetape_pc_intr\n"); 1140 printk(KERN_ERR "ide-tape: CoD != 0 in %s\n", __func__);
1286 return ide_do_reset(drive); 1141 return ide_do_reset(drive);
1287 } 1142 }
1288 if (((ireason & IO) == IO) == test_bit(PC_WRITING, &pc->flags)) { 1143 if (((ireason & IO) == IO) == test_bit(PC_WRITING, &pc->flags)) {
@@ -1298,86 +1153,76 @@ static ide_startstop_t idetape_pc_intr (ide_drive_t *drive)
1298 temp = pc->actually_transferred + bcount; 1153 temp = pc->actually_transferred + bcount;
1299 if (temp > pc->request_transfer) { 1154 if (temp > pc->request_transfer) {
1300 if (temp > pc->buffer_size) { 1155 if (temp > pc->buffer_size) {
1301 printk(KERN_ERR "ide-tape: The tape wants to send us more data than expected - discarding data\n"); 1156 printk(KERN_ERR "ide-tape: The tape wants to "
1157 "send us more data than expected "
1158 "- discarding data\n");
1302 idetape_discard_data(drive, bcount); 1159 idetape_discard_data(drive, bcount);
1303 ide_set_handler(drive, &idetape_pc_intr, IDETAPE_WAIT_CMD, NULL); 1160 ide_set_handler(drive, &idetape_pc_intr,
1161 IDETAPE_WAIT_CMD, NULL);
1304 return ide_started; 1162 return ide_started;
1305 } 1163 }
1306#if IDETAPE_DEBUG_LOG 1164 debug_log(DBG_SENSE, "The tape wants to send us more "
1307 if (tape->debug_level >= 2) 1165 "data than expected - allowing transfer\n");
1308 printk(KERN_NOTICE "ide-tape: The tape wants to send us more data than expected - allowing transfer\n");
1309#endif /* IDETAPE_DEBUG_LOG */
1310 } 1166 }
1311 } 1167 iobuf = &idetape_input_buffers;
1312 if (test_bit(PC_WRITING, &pc->flags)) { 1168 xferfunc = hwif->atapi_input_bytes;
1313 if (pc->bh != NULL)
1314 idetape_output_buffers(drive, pc, bcount);
1315 else
1316 /* Write the current buffer */
1317 hwif->atapi_output_bytes(drive, pc->current_position,
1318 bcount);
1319 } else { 1169 } else {
1320 if (pc->bh != NULL) 1170 iobuf = &idetape_output_buffers;
1321 idetape_input_buffers(drive, pc, bcount); 1171 xferfunc = hwif->atapi_output_bytes;
1322 else
1323 /* Read the current buffer */
1324 hwif->atapi_input_bytes(drive, pc->current_position,
1325 bcount);
1326 } 1172 }
1173
1174 if (pc->bh)
1175 iobuf(drive, pc, bcount);
1176 else
1177 xferfunc(drive, pc->current_position, bcount);
1178
1327 /* Update the current position */ 1179 /* Update the current position */
1328 pc->actually_transferred += bcount; 1180 pc->actually_transferred += bcount;
1329 pc->current_position += bcount; 1181 pc->current_position += bcount;
1330#if IDETAPE_DEBUG_LOG 1182
1331 if (tape->debug_level >= 2) 1183 debug_log(DBG_SENSE, "[cmd %x] transferred %d bytes on that intr.\n",
1332 printk(KERN_INFO "ide-tape: [cmd %x] transferred %d bytes " 1184 pc->c[0], bcount);
1333 "on that interrupt\n", pc->c[0], bcount); 1185
1334#endif
1335 /* And set the interrupt handler again */ 1186 /* And set the interrupt handler again */
1336 ide_set_handler(drive, &idetape_pc_intr, IDETAPE_WAIT_CMD, NULL); 1187 ide_set_handler(drive, &idetape_pc_intr, IDETAPE_WAIT_CMD, NULL);
1337 return ide_started; 1188 return ide_started;
1338} 1189}
1339 1190
1340/* 1191/*
1341 * Packet Command Interface 1192 * Packet Command Interface
1342 *
1343 * The current Packet Command is available in tape->pc, and will not
1344 * change until we finish handling it. Each packet command is associated
1345 * with a callback function that will be called when the command is
1346 * finished.
1347 * 1193 *
1348 * The handling will be done in three stages: 1194 * The current Packet Command is available in tape->pc, and will not change
1195 * until we finish handling it. Each packet command is associated with a
1196 * callback function that will be called when the command is finished.
1349 * 1197 *
1350 * 1. idetape_issue_packet_command will send the packet command to the 1198 * The handling will be done in three stages:
1351 * drive, and will set the interrupt handler to idetape_pc_intr.
1352 * 1199 *
1353 * 2. On each interrupt, idetape_pc_intr will be called. This step 1200 * 1. idetape_issue_pc will send the packet command to the drive, and will set
1354 * will be repeated until the device signals us that no more 1201 * the interrupt handler to idetape_pc_intr.
1355 * interrupts will be issued.
1356 * 1202 *
1357 * 3. ATAPI Tape media access commands have immediate status with a 1203 * 2. On each interrupt, idetape_pc_intr will be called. This step will be
1358 * delayed process. In case of a successful initiation of a 1204 * repeated until the device signals us that no more interrupts will be issued.
1359 * media access packet command, the DSC bit will be set when the
1360 * actual execution of the command is finished.
1361 * Since the tape drive will not issue an interrupt, we have to
1362 * poll for this event. In this case, we define the request as
1363 * "low priority request" by setting rq_status to
1364 * IDETAPE_RQ_POSTPONED, set a timer to poll for DSC and exit
1365 * the driver.
1366 * 1205 *
1367 * ide.c will then give higher priority to requests which 1206 * 3. ATAPI Tape media access commands have immediate status with a delayed
1368 * originate from the other device, until will change rq_status 1207 * process. In case of a successful initiation of a media access packet command,
1369 * to RQ_ACTIVE. 1208 * the DSC bit will be set when the actual execution of the command is finished.
1209 * Since the tape drive will not issue an interrupt, we have to poll for this
1210 * event. In this case, we define the request as "low priority request" by
1211 * setting rq_status to IDETAPE_RQ_POSTPONED, set a timer to poll for DSC and
1212 * exit the driver.
1370 * 1213 *
1371 * 4. When the packet command is finished, it will be checked for errors. 1214 * ide.c will then give higher priority to requests which originate from the
1215 * other device, until will change rq_status to RQ_ACTIVE.
1372 * 1216 *
1373 * 5. In case an error was found, we queue a request sense packet 1217 * 4. When the packet command is finished, it will be checked for errors.
1374 * command in front of the request queue and retry the operation
1375 * up to IDETAPE_MAX_PC_RETRIES times.
1376 * 1218 *
1377 * 6. In case no error was found, or we decided to give up and not 1219 * 5. In case an error was found, we queue a request sense packet command in
1378 * to retry again, the callback function will be called and then 1220 * front of the request queue and retry the operation up to
1379 * we will handle the next request. 1221 * IDETAPE_MAX_PC_RETRIES times.
1380 * 1222 *
1223 * 6. In case no error was found, or we decided to give up and not to retry
1224 * again, the callback function will be called and then we will handle the next
1225 * request.
1381 */ 1226 */
1382static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive) 1227static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive)
1383{ 1228{
@@ -1388,8 +1233,9 @@ static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive)
1388 ide_startstop_t startstop; 1233 ide_startstop_t startstop;
1389 u8 ireason; 1234 u8 ireason;
1390 1235
1391 if (ide_wait_stat(&startstop,drive,DRQ_STAT,BUSY_STAT,WAIT_READY)) { 1236 if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) {
1392 printk(KERN_ERR "ide-tape: Strange, packet command initiated yet DRQ isn't asserted\n"); 1237 printk(KERN_ERR "ide-tape: Strange, packet command initiated "
1238 "yet DRQ isn't asserted\n");
1393 return startstop; 1239 return startstop;
1394 } 1240 }
1395 ireason = hwif->INB(IDE_IREASON_REG); 1241 ireason = hwif->INB(IDE_IREASON_REG);
@@ -1422,7 +1268,7 @@ static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive)
1422 return ide_started; 1268 return ide_started;
1423} 1269}
1424 1270
1425static ide_startstop_t idetape_issue_packet_command (ide_drive_t *drive, idetape_pc_t *pc) 1271static ide_startstop_t idetape_issue_pc(ide_drive_t *drive, idetape_pc_t *pc)
1426{ 1272{
1427 ide_hwif_t *hwif = drive->hwif; 1273 ide_hwif_t *hwif = drive->hwif;
1428 idetape_tape_t *tape = drive->driver_data; 1274 idetape_tape_t *tape = drive->driver_data;
@@ -1443,9 +1289,9 @@ static ide_startstop_t idetape_issue_packet_command (ide_drive_t *drive, idetape
1443 if (pc->retries > IDETAPE_MAX_PC_RETRIES || 1289 if (pc->retries > IDETAPE_MAX_PC_RETRIES ||
1444 test_bit(PC_ABORT, &pc->flags)) { 1290 test_bit(PC_ABORT, &pc->flags)) {
1445 /* 1291 /*
1446 * We will "abort" retrying a packet command in case 1292 * We will "abort" retrying a packet command in case legitimate
1447 * a legitimate error code was received (crossing a 1293 * error code was received (crossing a filemark, or end of the
1448 * filemark, or end of the media, for example). 1294 * media, for example).
1449 */ 1295 */
1450 if (!test_bit(PC_ABORT, &pc->flags)) { 1296 if (!test_bit(PC_ABORT, &pc->flags)) {
1451 if (!(pc->c[0] == TEST_UNIT_READY && 1297 if (!(pc->c[0] == TEST_UNIT_READY &&
@@ -1464,10 +1310,7 @@ static ide_startstop_t idetape_issue_packet_command (ide_drive_t *drive, idetape
1464 tape->failed_pc = NULL; 1310 tape->failed_pc = NULL;
1465 return pc->callback(drive); 1311 return pc->callback(drive);
1466 } 1312 }
1467#if IDETAPE_DEBUG_LOG 1313 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]);
1468 if (tape->debug_level >= 2)
1469 printk(KERN_INFO "ide-tape: Retry number - %d, cmd = %02X\n", pc->retries, pc->c[0]);
1470#endif /* IDETAPE_DEBUG_LOG */
1471 1314
1472 pc->retries++; 1315 pc->retries++;
1473 /* We haven't transferred any data yet */ 1316 /* We haven't transferred any data yet */
@@ -1499,31 +1342,24 @@ static ide_startstop_t idetape_issue_packet_command (ide_drive_t *drive, idetape
1499 } 1342 }
1500} 1343}
1501 1344
1502/* 1345static ide_startstop_t idetape_pc_callback(ide_drive_t *drive)
1503 * General packet command callback function.
1504 */
1505static ide_startstop_t idetape_pc_callback (ide_drive_t *drive)
1506{ 1346{
1507 idetape_tape_t *tape = drive->driver_data; 1347 idetape_tape_t *tape = drive->driver_data;
1508 1348
1509#if IDETAPE_DEBUG_LOG 1349 debug_log(DBG_PROCS, "Enter %s\n", __func__);
1510 if (tape->debug_level >= 4)
1511 printk(KERN_INFO "ide-tape: Reached idetape_pc_callback\n");
1512#endif /* IDETAPE_DEBUG_LOG */
1513 1350
1514 idetape_end_request(drive, tape->pc->error ? 0 : 1, 0); 1351 idetape_end_request(drive, tape->pc->error ? 0 : 1, 0);
1515 return ide_stopped; 1352 return ide_stopped;
1516} 1353}
1517 1354
1518/* 1355/* A mode sense command is used to "sense" tape parameters. */
1519 * A mode sense command is used to "sense" tape parameters. 1356static void idetape_create_mode_sense_cmd(idetape_pc_t *pc, u8 page_code)
1520 */
1521static void idetape_create_mode_sense_cmd (idetape_pc_t *pc, u8 page_code)
1522{ 1357{
1523 idetape_init_pc(pc); 1358 idetape_init_pc(pc);
1524 pc->c[0] = MODE_SENSE; 1359 pc->c[0] = MODE_SENSE;
1525 if (page_code != IDETAPE_BLOCK_DESCRIPTOR) 1360 if (page_code != IDETAPE_BLOCK_DESCRIPTOR)
1526 pc->c[1] = 8; /* DBD = 1 - Don't return block descriptors */ 1361 /* DBD = 1 - Don't return block descriptors */
1362 pc->c[1] = 8;
1527 pc->c[2] = page_code; 1363 pc->c[2] = page_code;
1528 /* 1364 /*
1529 * Changed pc->c[3] to 0 (255 will at best return unused info). 1365 * Changed pc->c[3] to 0 (255 will at best return unused info).
@@ -1533,7 +1369,8 @@ static void idetape_create_mode_sense_cmd (idetape_pc_t *pc, u8 page_code)
1533 * and return an error when 255 is used. 1369 * and return an error when 255 is used.
1534 */ 1370 */
1535 pc->c[3] = 0; 1371 pc->c[3] = 0;
1536 pc->c[4] = 255; /* (We will just discard data in that case) */ 1372 /* We will just discard data in that case */
1373 pc->c[4] = 255;
1537 if (page_code == IDETAPE_BLOCK_DESCRIPTOR) 1374 if (page_code == IDETAPE_BLOCK_DESCRIPTOR)
1538 pc->request_transfer = 12; 1375 pc->request_transfer = 12;
1539 else if (page_code == IDETAPE_CAPABILITIES_PAGE) 1376 else if (page_code == IDETAPE_CAPABILITIES_PAGE)
@@ -1543,62 +1380,77 @@ static void idetape_create_mode_sense_cmd (idetape_pc_t *pc, u8 page_code)
1543 pc->callback = &idetape_pc_callback; 1380 pc->callback = &idetape_pc_callback;
1544} 1381}
1545 1382
1546static void calculate_speeds(ide_drive_t *drive) 1383static void idetape_calculate_speeds(ide_drive_t *drive)
1547{ 1384{
1548 idetape_tape_t *tape = drive->driver_data; 1385 idetape_tape_t *tape = drive->driver_data;
1549 int full = 125, empty = 75;
1550 1386
1551 if (time_after(jiffies, tape->controlled_pipeline_head_time + 120 * HZ)) { 1387 if (time_after(jiffies,
1552 tape->controlled_previous_pipeline_head = tape->controlled_last_pipeline_head; 1388 tape->controlled_pipeline_head_time + 120 * HZ)) {
1553 tape->controlled_previous_head_time = tape->controlled_pipeline_head_time; 1389 tape->controlled_previous_pipeline_head =
1390 tape->controlled_last_pipeline_head;
1391 tape->controlled_previous_head_time =
1392 tape->controlled_pipeline_head_time;
1554 tape->controlled_last_pipeline_head = tape->pipeline_head; 1393 tape->controlled_last_pipeline_head = tape->pipeline_head;
1555 tape->controlled_pipeline_head_time = jiffies; 1394 tape->controlled_pipeline_head_time = jiffies;
1556 } 1395 }
1557 if (time_after(jiffies, tape->controlled_pipeline_head_time + 60 * HZ)) 1396 if (time_after(jiffies, tape->controlled_pipeline_head_time + 60 * HZ))
1558 tape->controlled_pipeline_head_speed = (tape->pipeline_head - tape->controlled_last_pipeline_head) * 32 * HZ / (jiffies - tape->controlled_pipeline_head_time); 1397 tape->controlled_pipeline_head_speed = (tape->pipeline_head -
1398 tape->controlled_last_pipeline_head) * 32 * HZ /
1399 (jiffies - tape->controlled_pipeline_head_time);
1559 else if (time_after(jiffies, tape->controlled_previous_head_time)) 1400 else if (time_after(jiffies, tape->controlled_previous_head_time))
1560 tape->controlled_pipeline_head_speed = (tape->pipeline_head - tape->controlled_previous_pipeline_head) * 32 * HZ / (jiffies - tape->controlled_previous_head_time); 1401 tape->controlled_pipeline_head_speed = (tape->pipeline_head -
1402 tape->controlled_previous_pipeline_head) * 32 *
1403 HZ / (jiffies - tape->controlled_previous_head_time);
1561 1404
1562 if (tape->nr_pending_stages < tape->max_stages /*- 1 */) { 1405 if (tape->nr_pending_stages < tape->max_stages/*- 1 */) {
1563 /* -1 for read mode error recovery */ 1406 /* -1 for read mode error recovery */
1564 if (time_after(jiffies, tape->uncontrolled_previous_head_time + 10 * HZ)) { 1407 if (time_after(jiffies, tape->uncontrolled_previous_head_time +
1408 10 * HZ)) {
1565 tape->uncontrolled_pipeline_head_time = jiffies; 1409 tape->uncontrolled_pipeline_head_time = jiffies;
1566 tape->uncontrolled_pipeline_head_speed = (tape->pipeline_head - tape->uncontrolled_previous_pipeline_head) * 32 * HZ / (jiffies - tape->uncontrolled_previous_head_time); 1410 tape->uncontrolled_pipeline_head_speed =
1411 (tape->pipeline_head -
1412 tape->uncontrolled_previous_pipeline_head) *
1413 32 * HZ / (jiffies -
1414 tape->uncontrolled_previous_head_time);
1567 } 1415 }
1568 } else { 1416 } else {
1569 tape->uncontrolled_previous_head_time = jiffies; 1417 tape->uncontrolled_previous_head_time = jiffies;
1570 tape->uncontrolled_previous_pipeline_head = tape->pipeline_head; 1418 tape->uncontrolled_previous_pipeline_head = tape->pipeline_head;
1571 if (time_after(jiffies, tape->uncontrolled_pipeline_head_time + 30 * HZ)) { 1419 if (time_after(jiffies, tape->uncontrolled_pipeline_head_time +
1420 30 * HZ))
1572 tape->uncontrolled_pipeline_head_time = jiffies; 1421 tape->uncontrolled_pipeline_head_time = jiffies;
1573 } 1422
1574 } 1423 }
1575 tape->pipeline_head_speed = max(tape->uncontrolled_pipeline_head_speed, tape->controlled_pipeline_head_speed); 1424 tape->pipeline_head_speed = max(tape->uncontrolled_pipeline_head_speed,
1576 if (tape->speed_control == 0) { 1425 tape->controlled_pipeline_head_speed);
1577 tape->max_insert_speed = 5000; 1426
1578 } else if (tape->speed_control == 1) { 1427 if (tape->speed_control == 1) {
1579 if (tape->nr_pending_stages >= tape->max_stages / 2) 1428 if (tape->nr_pending_stages >= tape->max_stages / 2)
1580 tape->max_insert_speed = tape->pipeline_head_speed + 1429 tape->max_insert_speed = tape->pipeline_head_speed +
1581 (1100 - tape->pipeline_head_speed) * 2 * (tape->nr_pending_stages - tape->max_stages / 2) / tape->max_stages; 1430 (1100 - tape->pipeline_head_speed) * 2 *
1431 (tape->nr_pending_stages - tape->max_stages / 2)
1432 / tape->max_stages;
1582 else 1433 else
1583 tape->max_insert_speed = 500 + 1434 tape->max_insert_speed = 500 +
1584 (tape->pipeline_head_speed - 500) * 2 * tape->nr_pending_stages / tape->max_stages; 1435 (tape->pipeline_head_speed - 500) * 2 *
1436 tape->nr_pending_stages / tape->max_stages;
1437
1585 if (tape->nr_pending_stages >= tape->max_stages * 99 / 100) 1438 if (tape->nr_pending_stages >= tape->max_stages * 99 / 100)
1586 tape->max_insert_speed = 5000; 1439 tape->max_insert_speed = 5000;
1587 } else if (tape->speed_control == 2) {
1588 tape->max_insert_speed = tape->pipeline_head_speed * empty / 100 +
1589 (tape->pipeline_head_speed * full / 100 - tape->pipeline_head_speed * empty / 100) * tape->nr_pending_stages / tape->max_stages;
1590 } else 1440 } else
1591 tape->max_insert_speed = tape->speed_control; 1441 tape->max_insert_speed = tape->speed_control;
1442
1592 tape->max_insert_speed = max(tape->max_insert_speed, 500); 1443 tape->max_insert_speed = max(tape->max_insert_speed, 500);
1593} 1444}
1594 1445
1595static ide_startstop_t idetape_media_access_finished (ide_drive_t *drive) 1446static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
1596{ 1447{
1597 idetape_tape_t *tape = drive->driver_data; 1448 idetape_tape_t *tape = drive->driver_data;
1598 idetape_pc_t *pc = tape->pc; 1449 idetape_pc_t *pc = tape->pc;
1599 u8 stat; 1450 u8 stat;
1600 1451
1601 stat = drive->hwif->INB(IDE_STATUS_REG); 1452 stat = ide_read_status(drive);
1453
1602 if (stat & SEEK_STAT) { 1454 if (stat & SEEK_STAT) {
1603 if (stat & ERR_STAT) { 1455 if (stat & ERR_STAT) {
1604 /* Error detected */ 1456 /* Error detected */
@@ -1618,14 +1470,14 @@ static ide_startstop_t idetape_media_access_finished (ide_drive_t *drive)
1618 return pc->callback(drive); 1470 return pc->callback(drive);
1619} 1471}
1620 1472
1621static ide_startstop_t idetape_rw_callback (ide_drive_t *drive) 1473static ide_startstop_t idetape_rw_callback(ide_drive_t *drive)
1622{ 1474{
1623 idetape_tape_t *tape = drive->driver_data; 1475 idetape_tape_t *tape = drive->driver_data;
1624 struct request *rq = HWGROUP(drive)->rq; 1476 struct request *rq = HWGROUP(drive)->rq;
1625 int blocks = tape->pc->actually_transferred / tape->tape_block_size; 1477 int blocks = tape->pc->actually_transferred / tape->blk_size;
1626 1478
1627 tape->avg_size += blocks * tape->tape_block_size; 1479 tape->avg_size += blocks * tape->blk_size;
1628 tape->insert_size += blocks * tape->tape_block_size; 1480 tape->insert_size += blocks * tape->blk_size;
1629 if (tape->insert_size > 1024 * 1024) 1481 if (tape->insert_size > 1024 * 1024)
1630 tape->measure_insert_time = 1; 1482 tape->measure_insert_time = 1;
1631 if (tape->measure_insert_time) { 1483 if (tape->measure_insert_time) {
@@ -1634,19 +1486,17 @@ static ide_startstop_t idetape_rw_callback (ide_drive_t *drive)
1634 tape->insert_size = 0; 1486 tape->insert_size = 0;
1635 } 1487 }
1636 if (time_after(jiffies, tape->insert_time)) 1488 if (time_after(jiffies, tape->insert_time))
1637 tape->insert_speed = tape->insert_size / 1024 * HZ / (jiffies - tape->insert_time); 1489 tape->insert_speed = tape->insert_size / 1024 * HZ /
1490 (jiffies - tape->insert_time);
1638 if (time_after_eq(jiffies, tape->avg_time + HZ)) { 1491 if (time_after_eq(jiffies, tape->avg_time + HZ)) {
1639 tape->avg_speed = tape->avg_size * HZ / (jiffies - tape->avg_time) / 1024; 1492 tape->avg_speed = tape->avg_size * HZ /
1493 (jiffies - tape->avg_time) / 1024;
1640 tape->avg_size = 0; 1494 tape->avg_size = 0;
1641 tape->avg_time = jiffies; 1495 tape->avg_time = jiffies;
1642 } 1496 }
1497 debug_log(DBG_PROCS, "Enter %s\n", __func__);
1643 1498
1644#if IDETAPE_DEBUG_LOG 1499 tape->first_frame += blocks;
1645 if (tape->debug_level >= 4)
1646 printk(KERN_INFO "ide-tape: Reached idetape_rw_callback\n");
1647#endif /* IDETAPE_DEBUG_LOG */
1648
1649 tape->first_frame_position += blocks;
1650 rq->current_nr_sectors -= blocks; 1500 rq->current_nr_sectors -= blocks;
1651 1501
1652 if (!tape->pc->error) 1502 if (!tape->pc->error)
@@ -1656,7 +1506,8 @@ static ide_startstop_t idetape_rw_callback (ide_drive_t *drive)
1656 return ide_stopped; 1506 return ide_stopped;
1657} 1507}
1658 1508
1659static void idetape_create_read_cmd(idetape_tape_t *tape, idetape_pc_t *pc, unsigned int length, struct idetape_bh *bh) 1509static void idetape_create_read_cmd(idetape_tape_t *tape, idetape_pc_t *pc,
1510 unsigned int length, struct idetape_bh *bh)
1660{ 1511{
1661 idetape_init_pc(pc); 1512 idetape_init_pc(pc);
1662 pc->c[0] = READ_6; 1513 pc->c[0] = READ_6;
@@ -1666,12 +1517,14 @@ static void idetape_create_read_cmd(idetape_tape_t *tape, idetape_pc_t *pc, unsi
1666 pc->bh = bh; 1517 pc->bh = bh;
1667 atomic_set(&bh->b_count, 0); 1518 atomic_set(&bh->b_count, 0);
1668 pc->buffer = NULL; 1519 pc->buffer = NULL;
1669 pc->request_transfer = pc->buffer_size = length * tape->tape_block_size; 1520 pc->buffer_size = length * tape->blk_size;
1521 pc->request_transfer = pc->buffer_size;
1670 if (pc->request_transfer == tape->stage_size) 1522 if (pc->request_transfer == tape->stage_size)
1671 set_bit(PC_DMA_RECOMMENDED, &pc->flags); 1523 set_bit(PC_DMA_RECOMMENDED, &pc->flags);
1672} 1524}
1673 1525
1674static void idetape_create_read_buffer_cmd(idetape_tape_t *tape, idetape_pc_t *pc, unsigned int length, struct idetape_bh *bh) 1526static void idetape_create_read_buffer_cmd(idetape_tape_t *tape,
1527 idetape_pc_t *pc, struct idetape_bh *bh)
1675{ 1528{
1676 int size = 32768; 1529 int size = 32768;
1677 struct idetape_bh *p = bh; 1530 struct idetape_bh *p = bh;
@@ -1689,10 +1542,12 @@ static void idetape_create_read_buffer_cmd(idetape_tape_t *tape, idetape_pc_t *p
1689 atomic_set(&p->b_count, 0); 1542 atomic_set(&p->b_count, 0);
1690 p = p->b_reqnext; 1543 p = p->b_reqnext;
1691 } 1544 }
1692 pc->request_transfer = pc->buffer_size = size; 1545 pc->request_transfer = size;
1546 pc->buffer_size = size;
1693} 1547}
1694 1548
1695static void idetape_create_write_cmd(idetape_tape_t *tape, idetape_pc_t *pc, unsigned int length, struct idetape_bh *bh) 1549static void idetape_create_write_cmd(idetape_tape_t *tape, idetape_pc_t *pc,
1550 unsigned int length, struct idetape_bh *bh)
1696{ 1551{
1697 idetape_init_pc(pc); 1552 idetape_init_pc(pc);
1698 pc->c[0] = WRITE_6; 1553 pc->c[0] = WRITE_6;
@@ -1704,14 +1559,12 @@ static void idetape_create_write_cmd(idetape_tape_t *tape, idetape_pc_t *pc, uns
1704 pc->b_data = bh->b_data; 1559 pc->b_data = bh->b_data;
1705 pc->b_count = atomic_read(&bh->b_count); 1560 pc->b_count = atomic_read(&bh->b_count);
1706 pc->buffer = NULL; 1561 pc->buffer = NULL;
1707 pc->request_transfer = pc->buffer_size = length * tape->tape_block_size; 1562 pc->buffer_size = length * tape->blk_size;
1563 pc->request_transfer = pc->buffer_size;
1708 if (pc->request_transfer == tape->stage_size) 1564 if (pc->request_transfer == tape->stage_size)
1709 set_bit(PC_DMA_RECOMMENDED, &pc->flags); 1565 set_bit(PC_DMA_RECOMMENDED, &pc->flags);
1710} 1566}
1711 1567
1712/*
1713 * idetape_do_request is our request handling function.
1714 */
1715static ide_startstop_t idetape_do_request(ide_drive_t *drive, 1568static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1716 struct request *rq, sector_t block) 1569 struct request *rq, sector_t block)
1717{ 1570{
@@ -1720,30 +1573,22 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1720 struct request *postponed_rq = tape->postponed_rq; 1573 struct request *postponed_rq = tape->postponed_rq;
1721 u8 stat; 1574 u8 stat;
1722 1575
1723#if IDETAPE_DEBUG_LOG 1576 debug_log(DBG_SENSE, "sector: %ld, nr_sectors: %ld,"
1724 if (tape->debug_level >= 2) 1577 " current_nr_sectors: %d\n",
1725 printk(KERN_INFO "ide-tape: sector: %ld, "
1726 "nr_sectors: %ld, current_nr_sectors: %d\n",
1727 rq->sector, rq->nr_sectors, rq->current_nr_sectors); 1578 rq->sector, rq->nr_sectors, rq->current_nr_sectors);
1728#endif /* IDETAPE_DEBUG_LOG */
1729 1579
1730 if (!blk_special_request(rq)) { 1580 if (!blk_special_request(rq)) {
1731 /* 1581 /* We do not support buffer cache originated requests. */
1732 * We do not support buffer cache originated requests.
1733 */
1734 printk(KERN_NOTICE "ide-tape: %s: Unsupported request in " 1582 printk(KERN_NOTICE "ide-tape: %s: Unsupported request in "
1735 "request queue (%d)\n", drive->name, rq->cmd_type); 1583 "request queue (%d)\n", drive->name, rq->cmd_type);
1736 ide_end_request(drive, 0, 0); 1584 ide_end_request(drive, 0, 0);
1737 return ide_stopped; 1585 return ide_stopped;
1738 } 1586 }
1739 1587
1740 /* 1588 /* Retry a failed packet command */
1741 * Retry a failed packet command 1589 if (tape->failed_pc && tape->pc->c[0] == REQUEST_SENSE)
1742 */ 1590 return idetape_issue_pc(drive, tape->failed_pc);
1743 if (tape->failed_pc != NULL && 1591
1744 tape->pc->c[0] == REQUEST_SENSE) {
1745 return idetape_issue_packet_command(drive, tape->failed_pc);
1746 }
1747 if (postponed_rq != NULL) 1592 if (postponed_rq != NULL)
1748 if (rq != postponed_rq) { 1593 if (rq != postponed_rq) {
1749 printk(KERN_ERR "ide-tape: ide-tape.c bug - " 1594 printk(KERN_ERR "ide-tape: ide-tape.c bug - "
@@ -1758,7 +1603,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1758 * If the tape is still busy, postpone our request and service 1603 * If the tape is still busy, postpone our request and service
1759 * the other device meanwhile. 1604 * the other device meanwhile.
1760 */ 1605 */
1761 stat = drive->hwif->INB(IDE_STATUS_REG); 1606 stat = ide_read_status(drive);
1762 1607
1763 if (!drive->dsc_overlap && !(rq->cmd[0] & REQ_IDETAPE_PC2)) 1608 if (!drive->dsc_overlap && !(rq->cmd[0] & REQ_IDETAPE_PC2))
1764 set_bit(IDETAPE_IGNORE_DSC, &tape->flags); 1609 set_bit(IDETAPE_IGNORE_DSC, &tape->flags);
@@ -1768,16 +1613,15 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1768 drive->post_reset = 0; 1613 drive->post_reset = 0;
1769 } 1614 }
1770 1615
1771 if (tape->tape_still_time > 100 && tape->tape_still_time < 200)
1772 tape->measure_insert_time = 1;
1773 if (time_after(jiffies, tape->insert_time)) 1616 if (time_after(jiffies, tape->insert_time))
1774 tape->insert_speed = tape->insert_size / 1024 * HZ / (jiffies - tape->insert_time); 1617 tape->insert_speed = tape->insert_size / 1024 * HZ /
1775 calculate_speeds(drive); 1618 (jiffies - tape->insert_time);
1619 idetape_calculate_speeds(drive);
1776 if (!test_and_clear_bit(IDETAPE_IGNORE_DSC, &tape->flags) && 1620 if (!test_and_clear_bit(IDETAPE_IGNORE_DSC, &tape->flags) &&
1777 (stat & SEEK_STAT) == 0) { 1621 (stat & SEEK_STAT) == 0) {
1778 if (postponed_rq == NULL) { 1622 if (postponed_rq == NULL) {
1779 tape->dsc_polling_start = jiffies; 1623 tape->dsc_polling_start = jiffies;
1780 tape->dsc_polling_frequency = tape->best_dsc_rw_frequency; 1624 tape->dsc_poll_freq = tape->best_dsc_rw_freq;
1781 tape->dsc_timeout = jiffies + IDETAPE_DSC_RW_TIMEOUT; 1625 tape->dsc_timeout = jiffies + IDETAPE_DSC_RW_TIMEOUT;
1782 } else if (time_after(jiffies, tape->dsc_timeout)) { 1626 } else if (time_after(jiffies, tape->dsc_timeout)) {
1783 printk(KERN_ERR "ide-tape: %s: DSC timeout\n", 1627 printk(KERN_ERR "ide-tape: %s: DSC timeout\n",
@@ -1788,8 +1632,10 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1788 } else { 1632 } else {
1789 return ide_do_reset(drive); 1633 return ide_do_reset(drive);
1790 } 1634 }
1791 } else if (time_after(jiffies, tape->dsc_polling_start + IDETAPE_DSC_MA_THRESHOLD)) 1635 } else if (time_after(jiffies,
1792 tape->dsc_polling_frequency = IDETAPE_DSC_MA_SLOW; 1636 tape->dsc_polling_start +
1637 IDETAPE_DSC_MA_THRESHOLD))
1638 tape->dsc_poll_freq = IDETAPE_DSC_MA_SLOW;
1793 idetape_postpone_request(drive); 1639 idetape_postpone_request(drive);
1794 return ide_stopped; 1640 return ide_stopped;
1795 } 1641 }
@@ -1797,20 +1643,23 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1797 tape->buffer_head++; 1643 tape->buffer_head++;
1798 tape->postpone_cnt = 0; 1644 tape->postpone_cnt = 0;
1799 pc = idetape_next_pc_storage(drive); 1645 pc = idetape_next_pc_storage(drive);
1800 idetape_create_read_cmd(tape, pc, rq->current_nr_sectors, (struct idetape_bh *)rq->special); 1646 idetape_create_read_cmd(tape, pc, rq->current_nr_sectors,
1647 (struct idetape_bh *)rq->special);
1801 goto out; 1648 goto out;
1802 } 1649 }
1803 if (rq->cmd[0] & REQ_IDETAPE_WRITE) { 1650 if (rq->cmd[0] & REQ_IDETAPE_WRITE) {
1804 tape->buffer_head++; 1651 tape->buffer_head++;
1805 tape->postpone_cnt = 0; 1652 tape->postpone_cnt = 0;
1806 pc = idetape_next_pc_storage(drive); 1653 pc = idetape_next_pc_storage(drive);
1807 idetape_create_write_cmd(tape, pc, rq->current_nr_sectors, (struct idetape_bh *)rq->special); 1654 idetape_create_write_cmd(tape, pc, rq->current_nr_sectors,
1655 (struct idetape_bh *)rq->special);
1808 goto out; 1656 goto out;
1809 } 1657 }
1810 if (rq->cmd[0] & REQ_IDETAPE_READ_BUFFER) { 1658 if (rq->cmd[0] & REQ_IDETAPE_READ_BUFFER) {
1811 tape->postpone_cnt = 0; 1659 tape->postpone_cnt = 0;
1812 pc = idetape_next_pc_storage(drive); 1660 pc = idetape_next_pc_storage(drive);
1813 idetape_create_read_buffer_cmd(tape, pc, rq->current_nr_sectors, (struct idetape_bh *)rq->special); 1661 idetape_create_read_buffer_cmd(tape, pc,
1662 (struct idetape_bh *)rq->special);
1814 goto out; 1663 goto out;
1815 } 1664 }
1816 if (rq->cmd[0] & REQ_IDETAPE_PC1) { 1665 if (rq->cmd[0] & REQ_IDETAPE_PC1) {
@@ -1825,49 +1674,51 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1825 } 1674 }
1826 BUG(); 1675 BUG();
1827out: 1676out:
1828 return idetape_issue_packet_command(drive, pc); 1677 return idetape_issue_pc(drive, pc);
1829} 1678}
1830 1679
1831/* 1680/* Pipeline related functions */
1832 * Pipeline related functions 1681static inline int idetape_pipeline_active(idetape_tape_t *tape)
1833 */
1834static inline int idetape_pipeline_active (idetape_tape_t *tape)
1835{ 1682{
1836 int rc1, rc2; 1683 int rc1, rc2;
1837 1684
1838 rc1 = test_bit(IDETAPE_PIPELINE_ACTIVE, &tape->flags); 1685 rc1 = test_bit(IDETAPE_PIPELINE_ACTIVE, &tape->flags);
1839 rc2 = (tape->active_data_request != NULL); 1686 rc2 = (tape->active_data_rq != NULL);
1840 return rc1; 1687 return rc1;
1841} 1688}
1842 1689
1843/* 1690/*
1844 * idetape_kmalloc_stage uses __get_free_page to allocate a pipeline 1691 * The function below uses __get_free_page to allocate a pipeline stage, along
1845 * stage, along with all the necessary small buffers which together make 1692 * with all the necessary small buffers which together make a buffer of size
1846 * a buffer of size tape->stage_size (or a bit more). We attempt to 1693 * tape->stage_size (or a bit more). We attempt to combine sequential pages as
1847 * combine sequential pages as much as possible. 1694 * much as possible.
1848 * 1695 *
1849 * Returns a pointer to the new allocated stage, or NULL if we 1696 * It returns a pointer to the new allocated stage, or NULL if we can't (or
1850 * can't (or don't want to) allocate a stage. 1697 * don't want to) allocate a stage.
1851 * 1698 *
1852 * Pipeline stages are optional and are used to increase performance. 1699 * Pipeline stages are optional and are used to increase performance. If we
1853 * If we can't allocate them, we'll manage without them. 1700 * can't allocate them, we'll manage without them.
1854 */ 1701 */
1855static idetape_stage_t *__idetape_kmalloc_stage (idetape_tape_t *tape, int full, int clear) 1702static idetape_stage_t *__idetape_kmalloc_stage(idetape_tape_t *tape, int full,
1703 int clear)
1856{ 1704{
1857 idetape_stage_t *stage; 1705 idetape_stage_t *stage;
1858 struct idetape_bh *prev_bh, *bh; 1706 struct idetape_bh *prev_bh, *bh;
1859 int pages = tape->pages_per_stage; 1707 int pages = tape->pages_per_stage;
1860 char *b_data = NULL; 1708 char *b_data = NULL;
1861 1709
1862 if ((stage = kmalloc(sizeof (idetape_stage_t),GFP_KERNEL)) == NULL) 1710 stage = kmalloc(sizeof(idetape_stage_t), GFP_KERNEL);
1711 if (!stage)
1863 return NULL; 1712 return NULL;
1864 stage->next = NULL; 1713 stage->next = NULL;
1865 1714
1866 bh = stage->bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL); 1715 stage->bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL);
1716 bh = stage->bh;
1867 if (bh == NULL) 1717 if (bh == NULL)
1868 goto abort; 1718 goto abort;
1869 bh->b_reqnext = NULL; 1719 bh->b_reqnext = NULL;
1870 if ((bh->b_data = (char *) __get_free_page (GFP_KERNEL)) == NULL) 1720 bh->b_data = (char *) __get_free_page(GFP_KERNEL);
1721 if (!bh->b_data)
1871 goto abort; 1722 goto abort;
1872 if (clear) 1723 if (clear)
1873 memset(bh->b_data, 0, PAGE_SIZE); 1724 memset(bh->b_data, 0, PAGE_SIZE);
@@ -1875,7 +1726,8 @@ static idetape_stage_t *__idetape_kmalloc_stage (idetape_tape_t *tape, int full,
1875 atomic_set(&bh->b_count, full ? bh->b_size : 0); 1726 atomic_set(&bh->b_count, full ? bh->b_size : 0);
1876 1727
1877 while (--pages) { 1728 while (--pages) {
1878 if ((b_data = (char *) __get_free_page (GFP_KERNEL)) == NULL) 1729 b_data = (char *) __get_free_page(GFP_KERNEL);
1730 if (!b_data)
1879 goto abort; 1731 goto abort;
1880 if (clear) 1732 if (clear)
1881 memset(b_data, 0, PAGE_SIZE); 1733 memset(b_data, 0, PAGE_SIZE);
@@ -1893,7 +1745,8 @@ static idetape_stage_t *__idetape_kmalloc_stage (idetape_tape_t *tape, int full,
1893 continue; 1745 continue;
1894 } 1746 }
1895 prev_bh = bh; 1747 prev_bh = bh;
1896 if ((bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL)) == NULL) { 1748 bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL);
1749 if (!bh) {
1897 free_page((unsigned long) b_data); 1750 free_page((unsigned long) b_data);
1898 goto abort; 1751 goto abort;
1899 } 1752 }
@@ -1912,14 +1765,11 @@ abort:
1912 return NULL; 1765 return NULL;
1913} 1766}
1914 1767
1915static idetape_stage_t *idetape_kmalloc_stage (idetape_tape_t *tape) 1768static idetape_stage_t *idetape_kmalloc_stage(idetape_tape_t *tape)
1916{ 1769{
1917 idetape_stage_t *cache_stage = tape->cache_stage; 1770 idetape_stage_t *cache_stage = tape->cache_stage;
1918 1771
1919#if IDETAPE_DEBUG_LOG 1772 debug_log(DBG_PROCS, "Enter %s\n", __func__);
1920 if (tape->debug_level >= 4)
1921 printk(KERN_INFO "ide-tape: Reached idetape_kmalloc_stage\n");
1922#endif /* IDETAPE_DEBUG_LOG */
1923 1773
1924 if (tape->nr_stages >= tape->max_stages) 1774 if (tape->nr_stages >= tape->max_stages)
1925 return NULL; 1775 return NULL;
@@ -1930,7 +1780,8 @@ static idetape_stage_t *idetape_kmalloc_stage (idetape_tape_t *tape)
1930 return __idetape_kmalloc_stage(tape, 0, 0); 1780 return __idetape_kmalloc_stage(tape, 0, 0);
1931} 1781}
1932 1782
1933static int idetape_copy_stage_from_user (idetape_tape_t *tape, idetape_stage_t *stage, const char __user *buf, int n) 1783static int idetape_copy_stage_from_user(idetape_tape_t *tape,
1784 idetape_stage_t *stage, const char __user *buf, int n)
1934{ 1785{
1935 struct idetape_bh *bh = tape->bh; 1786 struct idetape_bh *bh = tape->bh;
1936 int count; 1787 int count;
@@ -1938,12 +1789,15 @@ static int idetape_copy_stage_from_user (idetape_tape_t *tape, idetape_stage_t *
1938 1789
1939 while (n) { 1790 while (n) {
1940 if (bh == NULL) { 1791 if (bh == NULL) {
1941 printk(KERN_ERR "ide-tape: bh == NULL in " 1792 printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
1942 "idetape_copy_stage_from_user\n"); 1793 __func__);
1943 return 1; 1794 return 1;
1944 } 1795 }
1945 count = min((unsigned int)(bh->b_size - atomic_read(&bh->b_count)), (unsigned int)n); 1796 count = min((unsigned int)
1946 if (copy_from_user(bh->b_data + atomic_read(&bh->b_count), buf, count)) 1797 (bh->b_size - atomic_read(&bh->b_count)),
1798 (unsigned int)n);
1799 if (copy_from_user(bh->b_data + atomic_read(&bh->b_count), buf,
1800 count))
1947 ret = 1; 1801 ret = 1;
1948 n -= count; 1802 n -= count;
1949 atomic_add(count, &bh->b_count); 1803 atomic_add(count, &bh->b_count);
@@ -1958,7 +1812,8 @@ static int idetape_copy_stage_from_user (idetape_tape_t *tape, idetape_stage_t *
1958 return ret; 1812 return ret;
1959} 1813}
1960 1814
1961static int idetape_copy_stage_to_user (idetape_tape_t *tape, char __user *buf, idetape_stage_t *stage, int n) 1815static int idetape_copy_stage_to_user(idetape_tape_t *tape, char __user *buf,
1816 idetape_stage_t *stage, int n)
1962{ 1817{
1963 struct idetape_bh *bh = tape->bh; 1818 struct idetape_bh *bh = tape->bh;
1964 int count; 1819 int count;
@@ -1966,8 +1821,8 @@ static int idetape_copy_stage_to_user (idetape_tape_t *tape, char __user *buf, i
1966 1821
1967 while (n) { 1822 while (n) {
1968 if (bh == NULL) { 1823 if (bh == NULL) {
1969 printk(KERN_ERR "ide-tape: bh == NULL in " 1824 printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
1970 "idetape_copy_stage_to_user\n"); 1825 __func__);
1971 return 1; 1826 return 1;
1972 } 1827 }
1973 count = min(tape->b_count, n); 1828 count = min(tape->b_count, n);
@@ -1978,7 +1833,8 @@ static int idetape_copy_stage_to_user (idetape_tape_t *tape, char __user *buf, i
1978 tape->b_count -= count; 1833 tape->b_count -= count;
1979 buf += count; 1834 buf += count;
1980 if (!tape->b_count) { 1835 if (!tape->b_count) {
1981 tape->bh = bh = bh->b_reqnext; 1836 bh = bh->b_reqnext;
1837 tape->bh = bh;
1982 if (bh) { 1838 if (bh) {
1983 tape->b_data = bh->b_data; 1839 tape->b_data = bh->b_data;
1984 tape->b_count = atomic_read(&bh->b_count); 1840 tape->b_count = atomic_read(&bh->b_count);
@@ -1988,12 +1844,12 @@ static int idetape_copy_stage_to_user (idetape_tape_t *tape, char __user *buf, i
1988 return ret; 1844 return ret;
1989} 1845}
1990 1846
1991static void idetape_init_merge_stage (idetape_tape_t *tape) 1847static void idetape_init_merge_stage(idetape_tape_t *tape)
1992{ 1848{
1993 struct idetape_bh *bh = tape->merge_stage->bh; 1849 struct idetape_bh *bh = tape->merge_stage->bh;
1994 1850
1995 tape->bh = bh; 1851 tape->bh = bh;
1996 if (tape->chrdev_direction == idetape_direction_write) 1852 if (tape->chrdev_dir == IDETAPE_DIR_WRITE)
1997 atomic_set(&bh->b_count, 0); 1853 atomic_set(&bh->b_count, 0);
1998 else { 1854 else {
1999 tape->b_data = bh->b_data; 1855 tape->b_data = bh->b_data;
@@ -2001,7 +1857,7 @@ static void idetape_init_merge_stage (idetape_tape_t *tape)
2001 } 1857 }
2002} 1858}
2003 1859
2004static void idetape_switch_buffers (idetape_tape_t *tape, idetape_stage_t *stage) 1860static void idetape_switch_buffers(idetape_tape_t *tape, idetape_stage_t *stage)
2005{ 1861{
2006 struct idetape_bh *tmp; 1862 struct idetape_bh *tmp;
2007 1863
@@ -2011,87 +1867,76 @@ static void idetape_switch_buffers (idetape_tape_t *tape, idetape_stage_t *stage
2011 idetape_init_merge_stage(tape); 1867 idetape_init_merge_stage(tape);
2012} 1868}
2013 1869
2014/* 1870/* Add a new stage at the end of the pipeline. */
2015 * idetape_add_stage_tail adds a new stage at the end of the pipeline. 1871static void idetape_add_stage_tail(ide_drive_t *drive, idetape_stage_t *stage)
2016 */
2017static void idetape_add_stage_tail (ide_drive_t *drive,idetape_stage_t *stage)
2018{ 1872{
2019 idetape_tape_t *tape = drive->driver_data; 1873 idetape_tape_t *tape = drive->driver_data;
2020 unsigned long flags; 1874 unsigned long flags;
2021 1875
2022#if IDETAPE_DEBUG_LOG 1876 debug_log(DBG_PROCS, "Enter %s\n", __func__);
2023 if (tape->debug_level >= 4) 1877
2024 printk (KERN_INFO "ide-tape: Reached idetape_add_stage_tail\n"); 1878 spin_lock_irqsave(&tape->lock, flags);
2025#endif /* IDETAPE_DEBUG_LOG */
2026 spin_lock_irqsave(&tape->spinlock, flags);
2027 stage->next = NULL; 1879 stage->next = NULL;
2028 if (tape->last_stage != NULL) 1880 if (tape->last_stage != NULL)
2029 tape->last_stage->next=stage; 1881 tape->last_stage->next = stage;
2030 else 1882 else
2031 tape->first_stage = tape->next_stage=stage; 1883 tape->first_stage = stage;
1884 tape->next_stage = stage;
2032 tape->last_stage = stage; 1885 tape->last_stage = stage;
2033 if (tape->next_stage == NULL) 1886 if (tape->next_stage == NULL)
2034 tape->next_stage = tape->last_stage; 1887 tape->next_stage = tape->last_stage;
2035 tape->nr_stages++; 1888 tape->nr_stages++;
2036 tape->nr_pending_stages++; 1889 tape->nr_pending_stages++;
2037 spin_unlock_irqrestore(&tape->spinlock, flags); 1890 spin_unlock_irqrestore(&tape->lock, flags);
2038} 1891}
2039 1892
2040/* 1893/* Install a completion in a pending request and sleep until it is serviced. The
2041 * idetape_wait_for_request installs a completion in a pending request 1894 * caller should ensure that the request will not be serviced before we install
2042 * and sleeps until it is serviced. 1895 * the completion (usually by disabling interrupts).
2043 *
2044 * The caller should ensure that the request will not be serviced
2045 * before we install the completion (usually by disabling interrupts).
2046 */ 1896 */
2047static void idetape_wait_for_request (ide_drive_t *drive, struct request *rq) 1897static void idetape_wait_for_request(ide_drive_t *drive, struct request *rq)
2048{ 1898{
2049 DECLARE_COMPLETION_ONSTACK(wait); 1899 DECLARE_COMPLETION_ONSTACK(wait);
2050 idetape_tape_t *tape = drive->driver_data; 1900 idetape_tape_t *tape = drive->driver_data;
2051 1901
2052 if (rq == NULL || !blk_special_request(rq)) { 1902 if (rq == NULL || !blk_special_request(rq)) {
2053 printk (KERN_ERR "ide-tape: bug: Trying to sleep on non-valid request\n"); 1903 printk(KERN_ERR "ide-tape: bug: Trying to sleep on non-valid"
1904 " request\n");
2054 return; 1905 return;
2055 } 1906 }
2056 rq->end_io_data = &wait; 1907 rq->end_io_data = &wait;
2057 rq->end_io = blk_end_sync_rq; 1908 rq->end_io = blk_end_sync_rq;
2058 spin_unlock_irq(&tape->spinlock); 1909 spin_unlock_irq(&tape->lock);
2059 wait_for_completion(&wait); 1910 wait_for_completion(&wait);
2060 /* The stage and its struct request have been deallocated */ 1911 /* The stage and its struct request have been deallocated */
2061 spin_lock_irq(&tape->spinlock); 1912 spin_lock_irq(&tape->lock);
2062} 1913}
2063 1914
2064static ide_startstop_t idetape_read_position_callback (ide_drive_t *drive) 1915static ide_startstop_t idetape_read_position_callback(ide_drive_t *drive)
2065{ 1916{
2066 idetape_tape_t *tape = drive->driver_data; 1917 idetape_tape_t *tape = drive->driver_data;
2067 idetape_read_position_result_t *result; 1918 u8 *readpos = tape->pc->buffer;
2068 1919
2069#if IDETAPE_DEBUG_LOG 1920 debug_log(DBG_PROCS, "Enter %s\n", __func__);
2070 if (tape->debug_level >= 4)
2071 printk(KERN_INFO "ide-tape: Reached idetape_read_position_callback\n");
2072#endif /* IDETAPE_DEBUG_LOG */
2073 1921
2074 if (!tape->pc->error) { 1922 if (!tape->pc->error) {
2075 result = (idetape_read_position_result_t *) tape->pc->buffer; 1923 debug_log(DBG_SENSE, "BOP - %s\n",
2076#if IDETAPE_DEBUG_LOG 1924 (readpos[0] & 0x80) ? "Yes" : "No");
2077 if (tape->debug_level >= 2) 1925 debug_log(DBG_SENSE, "EOP - %s\n",
2078 printk(KERN_INFO "ide-tape: BOP - %s\n",result->bop ? "Yes":"No"); 1926 (readpos[0] & 0x40) ? "Yes" : "No");
2079 if (tape->debug_level >= 2) 1927
2080 printk(KERN_INFO "ide-tape: EOP - %s\n",result->eop ? "Yes":"No"); 1928 if (readpos[0] & 0x4) {
2081#endif /* IDETAPE_DEBUG_LOG */ 1929 printk(KERN_INFO "ide-tape: Block location is unknown"
2082 if (result->bpu) { 1930 "to the tape\n");
2083 printk(KERN_INFO "ide-tape: Block location is unknown to the tape\n");
2084 clear_bit(IDETAPE_ADDRESS_VALID, &tape->flags); 1931 clear_bit(IDETAPE_ADDRESS_VALID, &tape->flags);
2085 idetape_end_request(drive, 0, 0); 1932 idetape_end_request(drive, 0, 0);
2086 } else { 1933 } else {
2087#if IDETAPE_DEBUG_LOG 1934 debug_log(DBG_SENSE, "Block Location - %u\n",
2088 if (tape->debug_level >= 2) 1935 be32_to_cpu(*(u32 *)&readpos[4]));
2089 printk(KERN_INFO "ide-tape: Block Location - %u\n", ntohl(result->first_block)); 1936
2090#endif /* IDETAPE_DEBUG_LOG */ 1937 tape->partition = readpos[1];
2091 tape->partition = result->partition; 1938 tape->first_frame =
2092 tape->first_frame_position = ntohl(result->first_block); 1939 be32_to_cpu(*(u32 *)&readpos[4]);
2093 tape->last_frame_position = ntohl(result->last_block);
2094 tape->blocks_in_buffer = result->blocks_in_buffer[2];
2095 set_bit(IDETAPE_ADDRESS_VALID, &tape->flags); 1940 set_bit(IDETAPE_ADDRESS_VALID, &tape->flags);
2096 idetape_end_request(drive, 1, 0); 1941 idetape_end_request(drive, 1, 0);
2097 } 1942 }
@@ -2102,14 +1947,11 @@ static ide_startstop_t idetape_read_position_callback (ide_drive_t *drive)
2102} 1947}
2103 1948
2104/* 1949/*
2105 * idetape_create_write_filemark_cmd will: 1950 * Write a filemark if write_filemark=1. Flush the device buffers without
2106 * 1951 * writing a filemark otherwise.
2107 * 1. Write a filemark if write_filemark=1.
2108 * 2. Flush the device buffers without writing a filemark
2109 * if write_filemark=0.
2110 *
2111 */ 1952 */
2112static void idetape_create_write_filemark_cmd (ide_drive_t *drive, idetape_pc_t *pc,int write_filemark) 1953static void idetape_create_write_filemark_cmd(ide_drive_t *drive,
1954 idetape_pc_t *pc, int write_filemark)
2113{ 1955{
2114 idetape_init_pc(pc); 1956 idetape_init_pc(pc);
2115 pc->c[0] = WRITE_FILEMARKS; 1957 pc->c[0] = WRITE_FILEMARKS;
@@ -2126,26 +1968,19 @@ static void idetape_create_test_unit_ready_cmd(idetape_pc_t *pc)
2126} 1968}
2127 1969
2128/* 1970/*
2129 * idetape_queue_pc_tail is based on the following functions: 1971 * We add a special packet command request to the tail of the request queue, and
2130 * 1972 * wait for it to be serviced. This is not to be called from within the request
2131 * ide_do_drive_cmd from ide.c 1973 * handling part of the driver! We allocate here data on the stack and it is
2132 * cdrom_queue_request and cdrom_queue_packet_command from ide-cd.c 1974 * valid until the request is finished. This is not the case for the bottom part
1975 * of the driver, where we are always leaving the functions to wait for an
1976 * interrupt or a timer event.
2133 * 1977 *
2134 * We add a special packet command request to the tail of the request 1978 * From the bottom part of the driver, we should allocate safe memory using
2135 * queue, and wait for it to be serviced. 1979 * idetape_next_pc_storage() and ide_tape_next_rq_storage(), and add the request
2136 * 1980 * to the request list without waiting for it to be serviced! In that case, we
2137 * This is not to be called from within the request handling part 1981 * usually use idetape_queue_pc_head().
2138 * of the driver ! We allocate here data in the stack, and it is valid
2139 * until the request is finished. This is not the case for the bottom
2140 * part of the driver, where we are always leaving the functions to wait
2141 * for an interrupt or a timer event.
2142 *
2143 * From the bottom part of the driver, we should allocate safe memory
2144 * using idetape_next_pc_storage and idetape_next_rq_storage, and add
2145 * the request to the request list without waiting for it to be serviced !
2146 * In that case, we usually use idetape_queue_pc_head.
2147 */ 1982 */
2148static int __idetape_queue_pc_tail (ide_drive_t *drive, idetape_pc_t *pc) 1983static int __idetape_queue_pc_tail(ide_drive_t *drive, idetape_pc_t *pc)
2149{ 1984{
2150 struct ide_tape_obj *tape = drive->driver_data; 1985 struct ide_tape_obj *tape = drive->driver_data;
2151 struct request rq; 1986 struct request rq;
@@ -2156,7 +1991,8 @@ static int __idetape_queue_pc_tail (ide_drive_t *drive, idetape_pc_t *pc)
2156 return ide_do_drive_cmd(drive, &rq, ide_wait); 1991 return ide_do_drive_cmd(drive, &rq, ide_wait);
2157} 1992}
2158 1993
2159static void idetape_create_load_unload_cmd (ide_drive_t *drive, idetape_pc_t *pc,int cmd) 1994static void idetape_create_load_unload_cmd(ide_drive_t *drive, idetape_pc_t *pc,
1995 int cmd)
2160{ 1996{
2161 idetape_init_pc(pc); 1997 idetape_init_pc(pc);
2162 pc->c[0] = START_STOP; 1998 pc->c[0] = START_STOP;
@@ -2171,9 +2007,7 @@ static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
2171 idetape_pc_t pc; 2007 idetape_pc_t pc;
2172 int load_attempted = 0; 2008 int load_attempted = 0;
2173 2009
2174 /* 2010 /* Wait for the tape to become ready */
2175 * Wait for the tape to become ready
2176 */
2177 set_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags); 2011 set_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags);
2178 timeout += jiffies; 2012 timeout += jiffies;
2179 while (time_before(jiffies, timeout)) { 2013 while (time_before(jiffies, timeout)) {
@@ -2181,10 +2015,12 @@ static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
2181 if (!__idetape_queue_pc_tail(drive, &pc)) 2015 if (!__idetape_queue_pc_tail(drive, &pc))
2182 return 0; 2016 return 0;
2183 if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2) 2017 if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2)
2184 || (tape->asc == 0x3A)) { /* no media */ 2018 || (tape->asc == 0x3A)) {
2019 /* no media */
2185 if (load_attempted) 2020 if (load_attempted)
2186 return -ENOMEDIUM; 2021 return -ENOMEDIUM;
2187 idetape_create_load_unload_cmd(drive, &pc, IDETAPE_LU_LOAD_MASK); 2022 idetape_create_load_unload_cmd(drive, &pc,
2023 IDETAPE_LU_LOAD_MASK);
2188 __idetape_queue_pc_tail(drive, &pc); 2024 __idetape_queue_pc_tail(drive, &pc);
2189 load_attempted = 1; 2025 load_attempted = 1;
2190 /* not about to be ready */ 2026 /* not about to be ready */
@@ -2196,24 +2032,25 @@ static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
2196 return -EIO; 2032 return -EIO;
2197} 2033}
2198 2034
2199static int idetape_queue_pc_tail (ide_drive_t *drive,idetape_pc_t *pc) 2035static int idetape_queue_pc_tail(ide_drive_t *drive, idetape_pc_t *pc)
2200{ 2036{
2201 return __idetape_queue_pc_tail(drive, pc); 2037 return __idetape_queue_pc_tail(drive, pc);
2202} 2038}
2203 2039
2204static int idetape_flush_tape_buffers (ide_drive_t *drive) 2040static int idetape_flush_tape_buffers(ide_drive_t *drive)
2205{ 2041{
2206 idetape_pc_t pc; 2042 idetape_pc_t pc;
2207 int rc; 2043 int rc;
2208 2044
2209 idetape_create_write_filemark_cmd(drive, &pc, 0); 2045 idetape_create_write_filemark_cmd(drive, &pc, 0);
2210 if ((rc = idetape_queue_pc_tail(drive, &pc))) 2046 rc = idetape_queue_pc_tail(drive, &pc);
2047 if (rc)
2211 return rc; 2048 return rc;
2212 idetape_wait_ready(drive, 60 * 5 * HZ); 2049 idetape_wait_ready(drive, 60 * 5 * HZ);
2213 return 0; 2050 return 0;
2214} 2051}
2215 2052
2216static void idetape_create_read_position_cmd (idetape_pc_t *pc) 2053static void idetape_create_read_position_cmd(idetape_pc_t *pc)
2217{ 2054{
2218 idetape_init_pc(pc); 2055 idetape_init_pc(pc);
2219 pc->c[0] = READ_POSITION; 2056 pc->c[0] = READ_POSITION;
@@ -2221,25 +2058,23 @@ static void idetape_create_read_position_cmd (idetape_pc_t *pc)
2221 pc->callback = &idetape_read_position_callback; 2058 pc->callback = &idetape_read_position_callback;
2222} 2059}
2223 2060
2224static int idetape_read_position (ide_drive_t *drive) 2061static int idetape_read_position(ide_drive_t *drive)
2225{ 2062{
2226 idetape_tape_t *tape = drive->driver_data; 2063 idetape_tape_t *tape = drive->driver_data;
2227 idetape_pc_t pc; 2064 idetape_pc_t pc;
2228 int position; 2065 int position;
2229 2066
2230#if IDETAPE_DEBUG_LOG 2067 debug_log(DBG_PROCS, "Enter %s\n", __func__);
2231 if (tape->debug_level >= 4)
2232 printk(KERN_INFO "ide-tape: Reached idetape_read_position\n");
2233#endif /* IDETAPE_DEBUG_LOG */
2234 2068
2235 idetape_create_read_position_cmd(&pc); 2069 idetape_create_read_position_cmd(&pc);
2236 if (idetape_queue_pc_tail(drive, &pc)) 2070 if (idetape_queue_pc_tail(drive, &pc))
2237 return -1; 2071 return -1;
2238 position = tape->first_frame_position; 2072 position = tape->first_frame;
2239 return position; 2073 return position;
2240} 2074}
2241 2075
2242static void idetape_create_locate_cmd (ide_drive_t *drive, idetape_pc_t *pc, unsigned int block, u8 partition, int skip) 2076static void idetape_create_locate_cmd(ide_drive_t *drive, idetape_pc_t *pc,
2077 unsigned int block, u8 partition, int skip)
2243{ 2078{
2244 idetape_init_pc(pc); 2079 idetape_init_pc(pc);
2245 pc->c[0] = POSITION_TO_ELEMENT; 2080 pc->c[0] = POSITION_TO_ELEMENT;
@@ -2250,7 +2085,8 @@ static void idetape_create_locate_cmd (ide_drive_t *drive, idetape_pc_t *pc, uns
2250 pc->callback = &idetape_pc_callback; 2085 pc->callback = &idetape_pc_callback;
2251} 2086}
2252 2087
2253static int idetape_create_prevent_cmd (ide_drive_t *drive, idetape_pc_t *pc, int prevent) 2088static int idetape_create_prevent_cmd(ide_drive_t *drive, idetape_pc_t *pc,
2089 int prevent)
2254{ 2090{
2255 idetape_tape_t *tape = drive->driver_data; 2091 idetape_tape_t *tape = drive->driver_data;
2256 2092
@@ -2265,17 +2101,17 @@ static int idetape_create_prevent_cmd (ide_drive_t *drive, idetape_pc_t *pc, int
2265 return 1; 2101 return 1;
2266} 2102}
2267 2103
2268static int __idetape_discard_read_pipeline (ide_drive_t *drive) 2104static int __idetape_discard_read_pipeline(ide_drive_t *drive)
2269{ 2105{
2270 idetape_tape_t *tape = drive->driver_data; 2106 idetape_tape_t *tape = drive->driver_data;
2271 unsigned long flags; 2107 unsigned long flags;
2272 int cnt; 2108 int cnt;
2273 2109
2274 if (tape->chrdev_direction != idetape_direction_read) 2110 if (tape->chrdev_dir != IDETAPE_DIR_READ)
2275 return 0; 2111 return 0;
2276 2112
2277 /* Remove merge stage. */ 2113 /* Remove merge stage. */
2278 cnt = tape->merge_stage_size / tape->tape_block_size; 2114 cnt = tape->merge_stage_size / tape->blk_size;
2279 if (test_and_clear_bit(IDETAPE_FILEMARK, &tape->flags)) 2115 if (test_and_clear_bit(IDETAPE_FILEMARK, &tape->flags))
2280 ++cnt; /* Filemarks count as 1 sector */ 2116 ++cnt; /* Filemarks count as 1 sector */
2281 tape->merge_stage_size = 0; 2117 tape->merge_stage_size = 0;
@@ -2286,22 +2122,22 @@ static int __idetape_discard_read_pipeline (ide_drive_t *drive)
2286 2122
2287 /* Clear pipeline flags. */ 2123 /* Clear pipeline flags. */
2288 clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags); 2124 clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags);
2289 tape->chrdev_direction = idetape_direction_none; 2125 tape->chrdev_dir = IDETAPE_DIR_NONE;
2290 2126
2291 /* Remove pipeline stages. */ 2127 /* Remove pipeline stages. */
2292 if (tape->first_stage == NULL) 2128 if (tape->first_stage == NULL)
2293 return 0; 2129 return 0;
2294 2130
2295 spin_lock_irqsave(&tape->spinlock, flags); 2131 spin_lock_irqsave(&tape->lock, flags);
2296 tape->next_stage = NULL; 2132 tape->next_stage = NULL;
2297 if (idetape_pipeline_active(tape)) 2133 if (idetape_pipeline_active(tape))
2298 idetape_wait_for_request(drive, tape->active_data_request); 2134 idetape_wait_for_request(drive, tape->active_data_rq);
2299 spin_unlock_irqrestore(&tape->spinlock, flags); 2135 spin_unlock_irqrestore(&tape->lock, flags);
2300 2136
2301 while (tape->first_stage != NULL) { 2137 while (tape->first_stage != NULL) {
2302 struct request *rq_ptr = &tape->first_stage->rq; 2138 struct request *rq_ptr = &tape->first_stage->rq;
2303 2139
2304 cnt += rq_ptr->nr_sectors - rq_ptr->current_nr_sectors; 2140 cnt += rq_ptr->nr_sectors - rq_ptr->current_nr_sectors;
2305 if (rq_ptr->errors == IDETAPE_ERROR_FILEMARK) 2141 if (rq_ptr->errors == IDETAPE_ERROR_FILEMARK)
2306 ++cnt; 2142 ++cnt;
2307 idetape_remove_stage_head(drive); 2143 idetape_remove_stage_head(drive);
@@ -2312,21 +2148,19 @@ static int __idetape_discard_read_pipeline (ide_drive_t *drive)
2312} 2148}
2313 2149
2314/* 2150/*
2315 * idetape_position_tape positions the tape to the requested block 2151 * Position the tape to the requested block using the LOCATE packet command.
2316 * using the LOCATE packet command. A READ POSITION command is then 2152 * A READ POSITION command is then issued to check where we are positioned. Like
2317 * issued to check where we are positioned. 2153 * all higher level operations, we queue the commands at the tail of the request
2318 * 2154 * queue and wait for their completion.
2319 * Like all higher level operations, we queue the commands at the tail
2320 * of the request queue and wait for their completion.
2321 *
2322 */ 2155 */
2323static int idetape_position_tape (ide_drive_t *drive, unsigned int block, u8 partition, int skip) 2156static int idetape_position_tape(ide_drive_t *drive, unsigned int block,
2157 u8 partition, int skip)
2324{ 2158{
2325 idetape_tape_t *tape = drive->driver_data; 2159 idetape_tape_t *tape = drive->driver_data;
2326 int retval; 2160 int retval;
2327 idetape_pc_t pc; 2161 idetape_pc_t pc;
2328 2162
2329 if (tape->chrdev_direction == idetape_direction_read) 2163 if (tape->chrdev_dir == IDETAPE_DIR_READ)
2330 __idetape_discard_read_pipeline(drive); 2164 __idetape_discard_read_pipeline(drive);
2331 idetape_wait_ready(drive, 60 * 5 * HZ); 2165 idetape_wait_ready(drive, 60 * 5 * HZ);
2332 idetape_create_locate_cmd(drive, &pc, block, partition, skip); 2166 idetape_create_locate_cmd(drive, &pc, block, partition, skip);
@@ -2338,7 +2172,8 @@ static int idetape_position_tape (ide_drive_t *drive, unsigned int block, u8 par
2338 return (idetape_queue_pc_tail(drive, &pc)); 2172 return (idetape_queue_pc_tail(drive, &pc));
2339} 2173}
2340 2174
2341static void idetape_discard_read_pipeline (ide_drive_t *drive, int restore_position) 2175static void idetape_discard_read_pipeline(ide_drive_t *drive,
2176 int restore_position)
2342{ 2177{
2343 idetape_tape_t *tape = drive->driver_data; 2178 idetape_tape_t *tape = drive->driver_data;
2344 int cnt; 2179 int cnt;
@@ -2349,35 +2184,37 @@ static void idetape_discard_read_pipeline (ide_drive_t *drive, int restore_posit
2349 position = idetape_read_position(drive); 2184 position = idetape_read_position(drive);
2350 seek = position > cnt ? position - cnt : 0; 2185 seek = position > cnt ? position - cnt : 0;
2351 if (idetape_position_tape(drive, seek, 0, 0)) { 2186 if (idetape_position_tape(drive, seek, 0, 0)) {
2352 printk(KERN_INFO "ide-tape: %s: position_tape failed in discard_pipeline()\n", tape->name); 2187 printk(KERN_INFO "ide-tape: %s: position_tape failed in"
2188 " discard_pipeline()\n", tape->name);
2353 return; 2189 return;
2354 } 2190 }
2355 } 2191 }
2356} 2192}
2357 2193
2358/* 2194/*
2359 * idetape_queue_rw_tail generates a read/write request for the block 2195 * Generate a read/write request for the block device interface and wait for it
2360 * device interface and wait for it to be serviced. 2196 * to be serviced.
2361 */ 2197 */
2362static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks, struct idetape_bh *bh) 2198static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks,
2199 struct idetape_bh *bh)
2363{ 2200{
2364 idetape_tape_t *tape = drive->driver_data; 2201 idetape_tape_t *tape = drive->driver_data;
2365 struct request rq; 2202 struct request rq;
2366 2203
2367#if IDETAPE_DEBUG_LOG 2204 debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd);
2368 if (tape->debug_level >= 2) 2205
2369 printk(KERN_INFO "ide-tape: idetape_queue_rw_tail: cmd=%d\n",cmd);
2370#endif /* IDETAPE_DEBUG_LOG */
2371 if (idetape_pipeline_active(tape)) { 2206 if (idetape_pipeline_active(tape)) {
2372 printk(KERN_ERR "ide-tape: bug: the pipeline is active in idetape_queue_rw_tail\n"); 2207 printk(KERN_ERR "ide-tape: bug: the pipeline is active in %s\n",
2208 __func__);
2373 return (0); 2209 return (0);
2374 } 2210 }
2375 2211
2376 idetape_init_rq(&rq, cmd); 2212 idetape_init_rq(&rq, cmd);
2377 rq.rq_disk = tape->disk; 2213 rq.rq_disk = tape->disk;
2378 rq.special = (void *)bh; 2214 rq.special = (void *)bh;
2379 rq.sector = tape->first_frame_position; 2215 rq.sector = tape->first_frame;
2380 rq.nr_sectors = rq.current_nr_sectors = blocks; 2216 rq.nr_sectors = blocks;
2217 rq.current_nr_sectors = blocks;
2381 (void) ide_do_drive_cmd(drive, &rq, ide_wait); 2218 (void) ide_do_drive_cmd(drive, &rq, ide_wait);
2382 2219
2383 if ((cmd & (REQ_IDETAPE_READ | REQ_IDETAPE_WRITE)) == 0) 2220 if ((cmd & (REQ_IDETAPE_READ | REQ_IDETAPE_WRITE)) == 0)
@@ -2387,14 +2224,11 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks, struct
2387 idetape_init_merge_stage(tape); 2224 idetape_init_merge_stage(tape);
2388 if (rq.errors == IDETAPE_ERROR_GENERAL) 2225 if (rq.errors == IDETAPE_ERROR_GENERAL)
2389 return -EIO; 2226 return -EIO;
2390 return (tape->tape_block_size * (blocks-rq.current_nr_sectors)); 2227 return (tape->blk_size * (blocks-rq.current_nr_sectors));
2391} 2228}
2392 2229
2393/* 2230/* start servicing the pipeline stages, starting from tape->next_stage. */
2394 * idetape_insert_pipeline_into_queue is used to start servicing the 2231static void idetape_plug_pipeline(ide_drive_t *drive)
2395 * pipeline stages, starting from tape->next_stage.
2396 */
2397static void idetape_insert_pipeline_into_queue (ide_drive_t *drive)
2398{ 2232{
2399 idetape_tape_t *tape = drive->driver_data; 2233 idetape_tape_t *tape = drive->driver_data;
2400 2234
@@ -2403,19 +2237,20 @@ static void idetape_insert_pipeline_into_queue (ide_drive_t *drive)
2403 if (!idetape_pipeline_active(tape)) { 2237 if (!idetape_pipeline_active(tape)) {
2404 set_bit(IDETAPE_PIPELINE_ACTIVE, &tape->flags); 2238 set_bit(IDETAPE_PIPELINE_ACTIVE, &tape->flags);
2405 idetape_activate_next_stage(drive); 2239 idetape_activate_next_stage(drive);
2406 (void) ide_do_drive_cmd(drive, tape->active_data_request, ide_end); 2240 (void) ide_do_drive_cmd(drive, tape->active_data_rq, ide_end);
2407 } 2241 }
2408} 2242}
2409 2243
2410static void idetape_create_inquiry_cmd (idetape_pc_t *pc) 2244static void idetape_create_inquiry_cmd(idetape_pc_t *pc)
2411{ 2245{
2412 idetape_init_pc(pc); 2246 idetape_init_pc(pc);
2413 pc->c[0] = INQUIRY; 2247 pc->c[0] = INQUIRY;
2414 pc->c[4] = pc->request_transfer = 254; 2248 pc->c[4] = 254;
2249 pc->request_transfer = 254;
2415 pc->callback = &idetape_pc_callback; 2250 pc->callback = &idetape_pc_callback;
2416} 2251}
2417 2252
2418static void idetape_create_rewind_cmd (ide_drive_t *drive, idetape_pc_t *pc) 2253static void idetape_create_rewind_cmd(ide_drive_t *drive, idetape_pc_t *pc)
2419{ 2254{
2420 idetape_init_pc(pc); 2255 idetape_init_pc(pc);
2421 pc->c[0] = REZERO_UNIT; 2256 pc->c[0] = REZERO_UNIT;
@@ -2423,7 +2258,7 @@ static void idetape_create_rewind_cmd (ide_drive_t *drive, idetape_pc_t *pc)
2423 pc->callback = &idetape_pc_callback; 2258 pc->callback = &idetape_pc_callback;
2424} 2259}
2425 2260
2426static void idetape_create_erase_cmd (idetape_pc_t *pc) 2261static void idetape_create_erase_cmd(idetape_pc_t *pc)
2427{ 2262{
2428 idetape_init_pc(pc); 2263 idetape_init_pc(pc);
2429 pc->c[0] = ERASE; 2264 pc->c[0] = ERASE;
@@ -2432,7 +2267,7 @@ static void idetape_create_erase_cmd (idetape_pc_t *pc)
2432 pc->callback = &idetape_pc_callback; 2267 pc->callback = &idetape_pc_callback;
2433} 2268}
2434 2269
2435static void idetape_create_space_cmd (idetape_pc_t *pc,int count, u8 cmd) 2270static void idetape_create_space_cmd(idetape_pc_t *pc, int count, u8 cmd)
2436{ 2271{
2437 idetape_init_pc(pc); 2272 idetape_init_pc(pc);
2438 pc->c[0] = SPACE; 2273 pc->c[0] = SPACE;
@@ -2442,89 +2277,87 @@ static void idetape_create_space_cmd (idetape_pc_t *pc,int count, u8 cmd)
2442 pc->callback = &idetape_pc_callback; 2277 pc->callback = &idetape_pc_callback;
2443} 2278}
2444 2279
2445static void idetape_wait_first_stage (ide_drive_t *drive) 2280static void idetape_wait_first_stage(ide_drive_t *drive)
2446{ 2281{
2447 idetape_tape_t *tape = drive->driver_data; 2282 idetape_tape_t *tape = drive->driver_data;
2448 unsigned long flags; 2283 unsigned long flags;
2449 2284
2450 if (tape->first_stage == NULL) 2285 if (tape->first_stage == NULL)
2451 return; 2286 return;
2452 spin_lock_irqsave(&tape->spinlock, flags); 2287 spin_lock_irqsave(&tape->lock, flags);
2453 if (tape->active_stage == tape->first_stage) 2288 if (tape->active_stage == tape->first_stage)
2454 idetape_wait_for_request(drive, tape->active_data_request); 2289 idetape_wait_for_request(drive, tape->active_data_rq);
2455 spin_unlock_irqrestore(&tape->spinlock, flags); 2290 spin_unlock_irqrestore(&tape->lock, flags);
2456} 2291}
2457 2292
2458/* 2293/*
2459 * idetape_add_chrdev_write_request tries to add a character device 2294 * Try to add a character device originated write request to our pipeline. In
2460 * originated write request to our pipeline. In case we don't succeed, 2295 * case we don't succeed, we revert to non-pipelined operation mode for this
2461 * we revert to non-pipelined operation mode for this request. 2296 * request. In order to accomplish that, we
2462 * 2297 *
2463 * 1. Try to allocate a new pipeline stage. 2298 * 1. Try to allocate a new pipeline stage.
2464 * 2. If we can't, wait for more and more requests to be serviced 2299 * 2. If we can't, wait for more and more requests to be serviced and try again
2465 * and try again each time. 2300 * each time.
2466 * 3. If we still can't allocate a stage, fallback to 2301 * 3. If we still can't allocate a stage, fallback to non-pipelined operation
2467 * non-pipelined operation mode for this request. 2302 * mode for this request.
2468 */ 2303 */
2469static int idetape_add_chrdev_write_request (ide_drive_t *drive, int blocks) 2304static int idetape_add_chrdev_write_request(ide_drive_t *drive, int blocks)
2470{ 2305{
2471 idetape_tape_t *tape = drive->driver_data; 2306 idetape_tape_t *tape = drive->driver_data;
2472 idetape_stage_t *new_stage; 2307 idetape_stage_t *new_stage;
2473 unsigned long flags; 2308 unsigned long flags;
2474 struct request *rq; 2309 struct request *rq;
2475 2310
2476#if IDETAPE_DEBUG_LOG 2311 debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
2477 if (tape->debug_level >= 3)
2478 printk(KERN_INFO "ide-tape: Reached idetape_add_chrdev_write_request\n");
2479#endif /* IDETAPE_DEBUG_LOG */
2480 2312
2481 /* 2313 /* Attempt to allocate a new stage. Beware possible race conditions. */
2482 * Attempt to allocate a new stage.
2483 * Pay special attention to possible race conditions.
2484 */
2485 while ((new_stage = idetape_kmalloc_stage(tape)) == NULL) { 2314 while ((new_stage = idetape_kmalloc_stage(tape)) == NULL) {
2486 spin_lock_irqsave(&tape->spinlock, flags); 2315 spin_lock_irqsave(&tape->lock, flags);
2487 if (idetape_pipeline_active(tape)) { 2316 if (idetape_pipeline_active(tape)) {
2488 idetape_wait_for_request(drive, tape->active_data_request); 2317 idetape_wait_for_request(drive, tape->active_data_rq);
2489 spin_unlock_irqrestore(&tape->spinlock, flags); 2318 spin_unlock_irqrestore(&tape->lock, flags);
2490 } else { 2319 } else {
2491 spin_unlock_irqrestore(&tape->spinlock, flags); 2320 spin_unlock_irqrestore(&tape->lock, flags);
2492 idetape_insert_pipeline_into_queue(drive); 2321 idetape_plug_pipeline(drive);
2493 if (idetape_pipeline_active(tape)) 2322 if (idetape_pipeline_active(tape))
2494 continue; 2323 continue;
2495 /* 2324 /*
2496 * Linux is short on memory. Fallback to 2325 * The machine is short on memory. Fallback to non-
2497 * non-pipelined operation mode for this request. 2326 * pipelined operation mode for this request.
2498 */ 2327 */
2499 return idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks, tape->merge_stage->bh); 2328 return idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE,
2329 blocks, tape->merge_stage->bh);
2500 } 2330 }
2501 } 2331 }
2502 rq = &new_stage->rq; 2332 rq = &new_stage->rq;
2503 idetape_init_rq(rq, REQ_IDETAPE_WRITE); 2333 idetape_init_rq(rq, REQ_IDETAPE_WRITE);
2504 /* Doesn't actually matter - We always assume sequential access */ 2334 /* Doesn't actually matter - We always assume sequential access */
2505 rq->sector = tape->first_frame_position; 2335 rq->sector = tape->first_frame;
2506 rq->nr_sectors = rq->current_nr_sectors = blocks; 2336 rq->current_nr_sectors = blocks;
2337 rq->nr_sectors = blocks;
2507 2338
2508 idetape_switch_buffers(tape, new_stage); 2339 idetape_switch_buffers(tape, new_stage);
2509 idetape_add_stage_tail(drive, new_stage); 2340 idetape_add_stage_tail(drive, new_stage);
2510 tape->pipeline_head++; 2341 tape->pipeline_head++;
2511 calculate_speeds(drive); 2342 idetape_calculate_speeds(drive);
2512 2343
2513 /* 2344 /*
2514 * Estimate whether the tape has stopped writing by checking 2345 * Estimate whether the tape has stopped writing by checking if our
2515 * if our write pipeline is currently empty. If we are not 2346 * write pipeline is currently empty. If we are not writing anymore,
2516 * writing anymore, wait for the pipeline to be full enough 2347 * wait for the pipeline to be almost completely full (90%) before
2517 * (90%) before starting to service requests, so that we will 2348 * starting to service requests, so that we will be able to keep up with
2518 * be able to keep up with the higher speeds of the tape. 2349 * the higher speeds of the tape.
2519 */ 2350 */
2520 if (!idetape_pipeline_active(tape)) { 2351 if (!idetape_pipeline_active(tape)) {
2521 if (tape->nr_stages >= tape->max_stages * 9 / 10 || 2352 if (tape->nr_stages >= tape->max_stages * 9 / 10 ||
2522 tape->nr_stages >= tape->max_stages - tape->uncontrolled_pipeline_head_speed * 3 * 1024 / tape->tape_block_size) { 2353 tape->nr_stages >= tape->max_stages -
2354 tape->uncontrolled_pipeline_head_speed * 3 * 1024 /
2355 tape->blk_size) {
2523 tape->measure_insert_time = 1; 2356 tape->measure_insert_time = 1;
2524 tape->insert_time = jiffies; 2357 tape->insert_time = jiffies;
2525 tape->insert_size = 0; 2358 tape->insert_size = 0;
2526 tape->insert_speed = 0; 2359 tape->insert_speed = 0;
2527 idetape_insert_pipeline_into_queue(drive); 2360 idetape_plug_pipeline(drive);
2528 } 2361 }
2529 } 2362 }
2530 if (test_and_clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags)) 2363 if (test_and_clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags))
@@ -2534,31 +2367,32 @@ static int idetape_add_chrdev_write_request (ide_drive_t *drive, int blocks)
2534} 2367}
2535 2368
2536/* 2369/*
2537 * idetape_wait_for_pipeline will wait until all pending pipeline 2370 * Wait until all pending pipeline requests are serviced. Typically called on
2538 * requests are serviced. Typically called on device close. 2371 * device close.
2539 */ 2372 */
2540static void idetape_wait_for_pipeline (ide_drive_t *drive) 2373static void idetape_wait_for_pipeline(ide_drive_t *drive)
2541{ 2374{
2542 idetape_tape_t *tape = drive->driver_data; 2375 idetape_tape_t *tape = drive->driver_data;
2543 unsigned long flags; 2376 unsigned long flags;
2544 2377
2545 while (tape->next_stage || idetape_pipeline_active(tape)) { 2378 while (tape->next_stage || idetape_pipeline_active(tape)) {
2546 idetape_insert_pipeline_into_queue(drive); 2379 idetape_plug_pipeline(drive);
2547 spin_lock_irqsave(&tape->spinlock, flags); 2380 spin_lock_irqsave(&tape->lock, flags);
2548 if (idetape_pipeline_active(tape)) 2381 if (idetape_pipeline_active(tape))
2549 idetape_wait_for_request(drive, tape->active_data_request); 2382 idetape_wait_for_request(drive, tape->active_data_rq);
2550 spin_unlock_irqrestore(&tape->spinlock, flags); 2383 spin_unlock_irqrestore(&tape->lock, flags);
2551 } 2384 }
2552} 2385}
2553 2386
2554static void idetape_empty_write_pipeline (ide_drive_t *drive) 2387static void idetape_empty_write_pipeline(ide_drive_t *drive)
2555{ 2388{
2556 idetape_tape_t *tape = drive->driver_data; 2389 idetape_tape_t *tape = drive->driver_data;
2557 int blocks, min; 2390 int blocks, min;
2558 struct idetape_bh *bh; 2391 struct idetape_bh *bh;
2559 2392
2560 if (tape->chrdev_direction != idetape_direction_write) { 2393 if (tape->chrdev_dir != IDETAPE_DIR_WRITE) {
2561 printk(KERN_ERR "ide-tape: bug: Trying to empty write pipeline, but we are not writing.\n"); 2394 printk(KERN_ERR "ide-tape: bug: Trying to empty write pipeline,"
2395 " but we are not writing.\n");
2562 return; 2396 return;
2563 } 2397 }
2564 if (tape->merge_stage_size > tape->stage_size) { 2398 if (tape->merge_stage_size > tape->stage_size) {
@@ -2566,12 +2400,13 @@ static void idetape_empty_write_pipeline (ide_drive_t *drive)
2566 tape->merge_stage_size = tape->stage_size; 2400 tape->merge_stage_size = tape->stage_size;
2567 } 2401 }
2568 if (tape->merge_stage_size) { 2402 if (tape->merge_stage_size) {
2569 blocks = tape->merge_stage_size / tape->tape_block_size; 2403 blocks = tape->merge_stage_size / tape->blk_size;
2570 if (tape->merge_stage_size % tape->tape_block_size) { 2404 if (tape->merge_stage_size % tape->blk_size) {
2571 unsigned int i; 2405 unsigned int i;
2572 2406
2573 blocks++; 2407 blocks++;
2574 i = tape->tape_block_size - tape->merge_stage_size % tape->tape_block_size; 2408 i = tape->blk_size - tape->merge_stage_size %
2409 tape->blk_size;
2575 bh = tape->bh->b_reqnext; 2410 bh = tape->bh->b_reqnext;
2576 while (bh) { 2411 while (bh) {
2577 atomic_set(&bh->b_count, 0); 2412 atomic_set(&bh->b_count, 0);
@@ -2580,12 +2415,14 @@ static void idetape_empty_write_pipeline (ide_drive_t *drive)
2580 bh = tape->bh; 2415 bh = tape->bh;
2581 while (i) { 2416 while (i) {
2582 if (bh == NULL) { 2417 if (bh == NULL) {
2583 2418 printk(KERN_INFO "ide-tape: bug,"
2584 printk(KERN_INFO "ide-tape: bug, bh NULL\n"); 2419 " bh NULL\n");
2585 break; 2420 break;
2586 } 2421 }
2587 min = min(i, (unsigned int)(bh->b_size - atomic_read(&bh->b_count))); 2422 min = min(i, (unsigned int)(bh->b_size -
2588 memset(bh->b_data + atomic_read(&bh->b_count), 0, min); 2423 atomic_read(&bh->b_count)));
2424 memset(bh->b_data + atomic_read(&bh->b_count),
2425 0, min);
2589 atomic_add(min, &bh->b_count); 2426 atomic_add(min, &bh->b_count);
2590 i -= min; 2427 i -= min;
2591 bh = bh->b_reqnext; 2428 bh = bh->b_reqnext;
@@ -2600,13 +2437,13 @@ static void idetape_empty_write_pipeline (ide_drive_t *drive)
2600 tape->merge_stage = NULL; 2437 tape->merge_stage = NULL;
2601 } 2438 }
2602 clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags); 2439 clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags);
2603 tape->chrdev_direction = idetape_direction_none; 2440 tape->chrdev_dir = IDETAPE_DIR_NONE;
2604 2441
2605 /* 2442 /*
2606 * On the next backup, perform the feedback loop again. 2443 * On the next backup, perform the feedback loop again. (I don't want to
2607 * (I don't want to keep sense information between backups, 2444 * keep sense information between backups, as some systems are
2608 * as some systems are constantly on, and the system load 2445 * constantly on, and the system load can be totally different on the
2609 * can be totally different on the next backup). 2446 * next backup).
2610 */ 2447 */
2611 tape->max_stages = tape->min_pipeline; 2448 tape->max_stages = tape->min_pipeline;
2612 if (tape->first_stage != NULL || 2449 if (tape->first_stage != NULL ||
@@ -2621,21 +2458,25 @@ static void idetape_empty_write_pipeline (ide_drive_t *drive)
2621 } 2458 }
2622} 2459}
2623 2460
2624static void idetape_restart_speed_control (ide_drive_t *drive) 2461static void idetape_restart_speed_control(ide_drive_t *drive)
2625{ 2462{
2626 idetape_tape_t *tape = drive->driver_data; 2463 idetape_tape_t *tape = drive->driver_data;
2627 2464
2628 tape->restart_speed_control_req = 0; 2465 tape->restart_speed_control_req = 0;
2629 tape->pipeline_head = 0; 2466 tape->pipeline_head = 0;
2630 tape->controlled_last_pipeline_head = tape->uncontrolled_last_pipeline_head = 0; 2467 tape->controlled_last_pipeline_head = 0;
2631 tape->controlled_previous_pipeline_head = tape->uncontrolled_previous_pipeline_head = 0; 2468 tape->controlled_previous_pipeline_head = 0;
2632 tape->pipeline_head_speed = tape->controlled_pipeline_head_speed = 5000; 2469 tape->uncontrolled_previous_pipeline_head = 0;
2470 tape->controlled_pipeline_head_speed = 5000;
2471 tape->pipeline_head_speed = 5000;
2633 tape->uncontrolled_pipeline_head_speed = 0; 2472 tape->uncontrolled_pipeline_head_speed = 0;
2634 tape->controlled_pipeline_head_time = tape->uncontrolled_pipeline_head_time = jiffies; 2473 tape->controlled_pipeline_head_time =
2635 tape->controlled_previous_head_time = tape->uncontrolled_previous_head_time = jiffies; 2474 tape->uncontrolled_pipeline_head_time = jiffies;
2475 tape->controlled_previous_head_time =
2476 tape->uncontrolled_previous_head_time = jiffies;
2636} 2477}
2637 2478
2638static int idetape_initiate_read (ide_drive_t *drive, int max_stages) 2479static int idetape_init_read(ide_drive_t *drive, int max_stages)
2639{ 2480{
2640 idetape_tape_t *tape = drive->driver_data; 2481 idetape_tape_t *tape = drive->driver_data;
2641 idetape_stage_t *new_stage; 2482 idetape_stage_t *new_stage;
@@ -2644,32 +2485,35 @@ static int idetape_initiate_read (ide_drive_t *drive, int max_stages)
2644 u16 blocks = *(u16 *)&tape->caps[12]; 2485 u16 blocks = *(u16 *)&tape->caps[12];
2645 2486
2646 /* Initialize read operation */ 2487 /* Initialize read operation */
2647 if (tape->chrdev_direction != idetape_direction_read) { 2488 if (tape->chrdev_dir != IDETAPE_DIR_READ) {
2648 if (tape->chrdev_direction == idetape_direction_write) { 2489 if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
2649 idetape_empty_write_pipeline(drive); 2490 idetape_empty_write_pipeline(drive);
2650 idetape_flush_tape_buffers(drive); 2491 idetape_flush_tape_buffers(drive);
2651 } 2492 }
2652 if (tape->merge_stage || tape->merge_stage_size) { 2493 if (tape->merge_stage || tape->merge_stage_size) {
2653 printk (KERN_ERR "ide-tape: merge_stage_size should be 0 now\n"); 2494 printk(KERN_ERR "ide-tape: merge_stage_size should be"
2495 " 0 now\n");
2654 tape->merge_stage_size = 0; 2496 tape->merge_stage_size = 0;
2655 } 2497 }
2656 if ((tape->merge_stage = __idetape_kmalloc_stage(tape, 0, 0)) == NULL) 2498 tape->merge_stage = __idetape_kmalloc_stage(tape, 0, 0);
2499 if (!tape->merge_stage)
2657 return -ENOMEM; 2500 return -ENOMEM;
2658 tape->chrdev_direction = idetape_direction_read; 2501 tape->chrdev_dir = IDETAPE_DIR_READ;
2659 2502
2660 /* 2503 /*
2661 * Issue a read 0 command to ensure that DSC handshake 2504 * Issue a read 0 command to ensure that DSC handshake is
2662 * is switched from completion mode to buffer available 2505 * switched from completion mode to buffer available mode.
2663 * mode. 2506 * No point in issuing this if DSC overlap isn't supported, some
2664 * No point in issuing this if DSC overlap isn't supported, 2507 * drives (Seagate STT3401A) will return an error.
2665 * some drives (Seagate STT3401A) will return an error.
2666 */ 2508 */
2667 if (drive->dsc_overlap) { 2509 if (drive->dsc_overlap) {
2668 bytes_read = idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, 0, tape->merge_stage->bh); 2510 bytes_read = idetape_queue_rw_tail(drive,
2511 REQ_IDETAPE_READ, 0,
2512 tape->merge_stage->bh);
2669 if (bytes_read < 0) { 2513 if (bytes_read < 0) {
2670 __idetape_kfree_stage(tape->merge_stage); 2514 __idetape_kfree_stage(tape->merge_stage);
2671 tape->merge_stage = NULL; 2515 tape->merge_stage = NULL;
2672 tape->chrdev_direction = idetape_direction_none; 2516 tape->chrdev_dir = IDETAPE_DIR_NONE;
2673 return bytes_read; 2517 return bytes_read;
2674 } 2518 }
2675 } 2519 }
@@ -2677,8 +2521,9 @@ static int idetape_initiate_read (ide_drive_t *drive, int max_stages)
2677 if (tape->restart_speed_control_req) 2521 if (tape->restart_speed_control_req)
2678 idetape_restart_speed_control(drive); 2522 idetape_restart_speed_control(drive);
2679 idetape_init_rq(&rq, REQ_IDETAPE_READ); 2523 idetape_init_rq(&rq, REQ_IDETAPE_READ);
2680 rq.sector = tape->first_frame_position; 2524 rq.sector = tape->first_frame;
2681 rq.nr_sectors = rq.current_nr_sectors = blocks; 2525 rq.nr_sectors = blocks;
2526 rq.current_nr_sectors = blocks;
2682 if (!test_bit(IDETAPE_PIPELINE_ERROR, &tape->flags) && 2527 if (!test_bit(IDETAPE_PIPELINE_ERROR, &tape->flags) &&
2683 tape->nr_stages < max_stages) { 2528 tape->nr_stages < max_stages) {
2684 new_stage = idetape_kmalloc_stage(tape); 2529 new_stage = idetape_kmalloc_stage(tape);
@@ -2696,50 +2541,43 @@ static int idetape_initiate_read (ide_drive_t *drive, int max_stages)
2696 tape->insert_time = jiffies; 2541 tape->insert_time = jiffies;
2697 tape->insert_size = 0; 2542 tape->insert_size = 0;
2698 tape->insert_speed = 0; 2543 tape->insert_speed = 0;
2699 idetape_insert_pipeline_into_queue(drive); 2544 idetape_plug_pipeline(drive);
2700 } 2545 }
2701 } 2546 }
2702 return 0; 2547 return 0;
2703} 2548}
2704 2549
2705/* 2550/*
2706 * idetape_add_chrdev_read_request is called from idetape_chrdev_read 2551 * Called from idetape_chrdev_read() to service a character device read request
2707 * to service a character device read request and add read-ahead 2552 * and add read-ahead requests to our pipeline.
2708 * requests to our pipeline.
2709 */ 2553 */
2710static int idetape_add_chrdev_read_request (ide_drive_t *drive,int blocks) 2554static int idetape_add_chrdev_read_request(ide_drive_t *drive, int blocks)
2711{ 2555{
2712 idetape_tape_t *tape = drive->driver_data; 2556 idetape_tape_t *tape = drive->driver_data;
2713 unsigned long flags; 2557 unsigned long flags;
2714 struct request *rq_ptr; 2558 struct request *rq_ptr;
2715 int bytes_read; 2559 int bytes_read;
2716 2560
2717#if IDETAPE_DEBUG_LOG 2561 debug_log(DBG_PROCS, "Enter %s, %d blocks\n", __func__, blocks);
2718 if (tape->debug_level >= 4)
2719 printk(KERN_INFO "ide-tape: Reached idetape_add_chrdev_read_request, %d blocks\n", blocks);
2720#endif /* IDETAPE_DEBUG_LOG */
2721 2562
2722 /* 2563 /* If we are at a filemark, return a read length of 0 */
2723 * If we are at a filemark, return a read length of 0
2724 */
2725 if (test_bit(IDETAPE_FILEMARK, &tape->flags)) 2564 if (test_bit(IDETAPE_FILEMARK, &tape->flags))
2726 return 0; 2565 return 0;
2727 2566
2728 /* 2567 /* Wait for the next block to reach the head of the pipeline. */
2729 * Wait for the next block to be available at the head 2568 idetape_init_read(drive, tape->max_stages);
2730 * of the pipeline
2731 */
2732 idetape_initiate_read(drive, tape->max_stages);
2733 if (tape->first_stage == NULL) { 2569 if (tape->first_stage == NULL) {
2734 if (test_bit(IDETAPE_PIPELINE_ERROR, &tape->flags)) 2570 if (test_bit(IDETAPE_PIPELINE_ERROR, &tape->flags))
2735 return 0; 2571 return 0;
2736 return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, blocks, tape->merge_stage->bh); 2572 return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, blocks,
2573 tape->merge_stage->bh);
2737 } 2574 }
2738 idetape_wait_first_stage(drive); 2575 idetape_wait_first_stage(drive);
2739 rq_ptr = &tape->first_stage->rq; 2576 rq_ptr = &tape->first_stage->rq;
2740 bytes_read = tape->tape_block_size * (rq_ptr->nr_sectors - rq_ptr->current_nr_sectors); 2577 bytes_read = tape->blk_size * (rq_ptr->nr_sectors -
2741 rq_ptr->nr_sectors = rq_ptr->current_nr_sectors = 0; 2578 rq_ptr->current_nr_sectors);
2742 2579 rq_ptr->nr_sectors = 0;
2580 rq_ptr->current_nr_sectors = 0;
2743 2581
2744 if (rq_ptr->errors == IDETAPE_ERROR_EOD) 2582 if (rq_ptr->errors == IDETAPE_ERROR_EOD)
2745 return 0; 2583 return 0;
@@ -2747,43 +2585,46 @@ static int idetape_add_chrdev_read_request (ide_drive_t *drive,int blocks)
2747 idetape_switch_buffers(tape, tape->first_stage); 2585 idetape_switch_buffers(tape, tape->first_stage);
2748 if (rq_ptr->errors == IDETAPE_ERROR_FILEMARK) 2586 if (rq_ptr->errors == IDETAPE_ERROR_FILEMARK)
2749 set_bit(IDETAPE_FILEMARK, &tape->flags); 2587 set_bit(IDETAPE_FILEMARK, &tape->flags);
2750 spin_lock_irqsave(&tape->spinlock, flags); 2588 spin_lock_irqsave(&tape->lock, flags);
2751 idetape_remove_stage_head(drive); 2589 idetape_remove_stage_head(drive);
2752 spin_unlock_irqrestore(&tape->spinlock, flags); 2590 spin_unlock_irqrestore(&tape->lock, flags);
2753 tape->pipeline_head++; 2591 tape->pipeline_head++;
2754 calculate_speeds(drive); 2592 idetape_calculate_speeds(drive);
2755 } 2593 }
2756 if (bytes_read > blocks * tape->tape_block_size) { 2594 if (bytes_read > blocks * tape->blk_size) {
2757 printk(KERN_ERR "ide-tape: bug: trying to return more bytes than requested\n"); 2595 printk(KERN_ERR "ide-tape: bug: trying to return more bytes"
2758 bytes_read = blocks * tape->tape_block_size; 2596 " than requested\n");
2597 bytes_read = blocks * tape->blk_size;
2759 } 2598 }
2760 return (bytes_read); 2599 return (bytes_read);
2761} 2600}
2762 2601
2763static void idetape_pad_zeros (ide_drive_t *drive, int bcount) 2602static void idetape_pad_zeros(ide_drive_t *drive, int bcount)
2764{ 2603{
2765 idetape_tape_t *tape = drive->driver_data; 2604 idetape_tape_t *tape = drive->driver_data;
2766 struct idetape_bh *bh; 2605 struct idetape_bh *bh;
2767 int blocks; 2606 int blocks;
2768 2607
2769 while (bcount) { 2608 while (bcount) {
2770 unsigned int count; 2609 unsigned int count;
2771 2610
2772 bh = tape->merge_stage->bh; 2611 bh = tape->merge_stage->bh;
2773 count = min(tape->stage_size, bcount); 2612 count = min(tape->stage_size, bcount);
2774 bcount -= count; 2613 bcount -= count;
2775 blocks = count / tape->tape_block_size; 2614 blocks = count / tape->blk_size;
2776 while (count) { 2615 while (count) {
2777 atomic_set(&bh->b_count, min(count, (unsigned int)bh->b_size)); 2616 atomic_set(&bh->b_count,
2617 min(count, (unsigned int)bh->b_size));
2778 memset(bh->b_data, 0, atomic_read(&bh->b_count)); 2618 memset(bh->b_data, 0, atomic_read(&bh->b_count));
2779 count -= atomic_read(&bh->b_count); 2619 count -= atomic_read(&bh->b_count);
2780 bh = bh->b_reqnext; 2620 bh = bh->b_reqnext;
2781 } 2621 }
2782 idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks, tape->merge_stage->bh); 2622 idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks,
2623 tape->merge_stage->bh);
2783 } 2624 }
2784} 2625}
2785 2626
2786static int idetape_pipeline_size (ide_drive_t *drive) 2627static int idetape_pipeline_size(ide_drive_t *drive)
2787{ 2628{
2788 idetape_tape_t *tape = drive->driver_data; 2629 idetape_tape_t *tape = drive->driver_data;
2789 idetape_stage_t *stage; 2630 idetape_stage_t *stage;
@@ -2794,9 +2635,10 @@ static int idetape_pipeline_size (ide_drive_t *drive)
2794 stage = tape->first_stage; 2635 stage = tape->first_stage;
2795 while (stage != NULL) { 2636 while (stage != NULL) {
2796 rq = &stage->rq; 2637 rq = &stage->rq;
2797 size += tape->tape_block_size * (rq->nr_sectors-rq->current_nr_sectors); 2638 size += tape->blk_size * (rq->nr_sectors -
2639 rq->current_nr_sectors);
2798 if (rq->errors == IDETAPE_ERROR_FILEMARK) 2640 if (rq->errors == IDETAPE_ERROR_FILEMARK)
2799 size += tape->tape_block_size; 2641 size += tape->blk_size;
2800 stage = stage->next; 2642 stage = stage->next;
2801 } 2643 }
2802 size += tape->merge_stage_size; 2644 size += tape->merge_stage_size;
@@ -2804,20 +2646,18 @@ static int idetape_pipeline_size (ide_drive_t *drive)
2804} 2646}
2805 2647
2806/* 2648/*
2807 * Rewinds the tape to the Beginning Of the current Partition (BOP). 2649 * Rewinds the tape to the Beginning Of the current Partition (BOP). We
2808 * 2650 * currently support only one partition.
2809 * We currently support only one partition. 2651 */
2810 */ 2652static int idetape_rewind_tape(ide_drive_t *drive)
2811static int idetape_rewind_tape (ide_drive_t *drive)
2812{ 2653{
2813 int retval; 2654 int retval;
2814 idetape_pc_t pc; 2655 idetape_pc_t pc;
2815#if IDETAPE_DEBUG_LOG 2656 idetape_tape_t *tape;
2816 idetape_tape_t *tape = drive->driver_data; 2657 tape = drive->driver_data;
2817 if (tape->debug_level >= 2) 2658
2818 printk(KERN_INFO "ide-tape: Reached idetape_rewind_tape\n"); 2659 debug_log(DBG_SENSE, "Enter %s\n", __func__);
2819#endif /* IDETAPE_DEBUG_LOG */ 2660
2820
2821 idetape_create_rewind_cmd(drive, &pc); 2661 idetape_create_rewind_cmd(drive, &pc);
2822 retval = idetape_queue_pc_tail(drive, &pc); 2662 retval = idetape_queue_pc_tail(drive, &pc);
2823 if (retval) 2663 if (retval)
@@ -2830,14 +2670,9 @@ static int idetape_rewind_tape (ide_drive_t *drive)
2830 return 0; 2670 return 0;
2831} 2671}
2832 2672
2833/* 2673/* mtio.h compatible commands should be issued to the chrdev interface. */
2834 * Our special ide-tape ioctl's. 2674static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd,
2835 * 2675 unsigned long arg)
2836 * Currently there aren't any ioctl's.
2837 * mtio.h compatible commands should be issued to the character device
2838 * interface.
2839 */
2840static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd, unsigned long arg)
2841{ 2676{
2842 idetape_tape_t *tape = drive->driver_data; 2677 idetape_tape_t *tape = drive->driver_data;
2843 void __user *argp = (void __user *)arg; 2678 void __user *argp = (void __user *)arg;
@@ -2848,44 +2683,41 @@ static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd, unsigned l
2848 int nr_stages; 2683 int nr_stages;
2849 } config; 2684 } config;
2850 2685
2851#if IDETAPE_DEBUG_LOG 2686 debug_log(DBG_PROCS, "Enter %s\n", __func__);
2852 if (tape->debug_level >= 4) 2687
2853 printk(KERN_INFO "ide-tape: Reached idetape_blkdev_ioctl\n");
2854#endif /* IDETAPE_DEBUG_LOG */
2855 switch (cmd) { 2688 switch (cmd) {
2856 case 0x0340: 2689 case 0x0340:
2857 if (copy_from_user(&config, argp, sizeof(config))) 2690 if (copy_from_user(&config, argp, sizeof(config)))
2858 return -EFAULT; 2691 return -EFAULT;
2859 tape->best_dsc_rw_frequency = config.dsc_rw_frequency; 2692 tape->best_dsc_rw_freq = config.dsc_rw_frequency;
2860 tape->max_stages = config.nr_stages; 2693 tape->max_stages = config.nr_stages;
2861 break; 2694 break;
2862 case 0x0350: 2695 case 0x0350:
2863 config.dsc_rw_frequency = (int) tape->best_dsc_rw_frequency; 2696 config.dsc_rw_frequency = (int) tape->best_dsc_rw_freq;
2864 config.nr_stages = tape->max_stages; 2697 config.nr_stages = tape->max_stages;
2865 if (copy_to_user(argp, &config, sizeof(config))) 2698 if (copy_to_user(argp, &config, sizeof(config)))
2866 return -EFAULT; 2699 return -EFAULT;
2867 break; 2700 break;
2868 default: 2701 default:
2869 return -EIO; 2702 return -EIO;
2870 } 2703 }
2871 return 0; 2704 return 0;
2872} 2705}
2873 2706
2874/* 2707/*
2875 * idetape_space_over_filemarks is now a bit more complicated than just 2708 * The function below is now a bit more complicated than just passing the
2876 * passing the command to the tape since we may have crossed some 2709 * command to the tape since we may have crossed some filemarks during our
2877 * filemarks during our pipelined read-ahead mode. 2710 * pipelined read-ahead mode. As a minor side effect, the pipeline enables us to
2878 * 2711 * support MTFSFM when the filemark is in our internal pipeline even if the tape
2879 * As a minor side effect, the pipeline enables us to support MTFSFM when 2712 * doesn't support spacing over filemarks in the reverse direction.
2880 * the filemark is in our internal pipeline even if the tape doesn't
2881 * support spacing over filemarks in the reverse direction.
2882 */ 2713 */
2883static int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_count) 2714static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
2715 int mt_count)
2884{ 2716{
2885 idetape_tape_t *tape = drive->driver_data; 2717 idetape_tape_t *tape = drive->driver_data;
2886 idetape_pc_t pc; 2718 idetape_pc_t pc;
2887 unsigned long flags; 2719 unsigned long flags;
2888 int retval,count=0; 2720 int retval, count = 0;
2889 int sprev = !!(tape->caps[4] & 0x20); 2721 int sprev = !!(tape->caps[4] & 0x20);
2890 2722
2891 if (mt_count == 0) 2723 if (mt_count == 0)
@@ -2893,14 +2725,11 @@ static int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_c
2893 if (MTBSF == mt_op || MTBSFM == mt_op) { 2725 if (MTBSF == mt_op || MTBSFM == mt_op) {
2894 if (!sprev) 2726 if (!sprev)
2895 return -EIO; 2727 return -EIO;
2896 mt_count = - mt_count; 2728 mt_count = -mt_count;
2897 } 2729 }
2898 2730
2899 if (tape->chrdev_direction == idetape_direction_read) { 2731 if (tape->chrdev_dir == IDETAPE_DIR_READ) {
2900 /* 2732 /* its a read-ahead buffer, scan it for crossed filemarks. */
2901 * We have a read-ahead buffer. Scan it for crossed
2902 * filemarks.
2903 */
2904 tape->merge_stage_size = 0; 2733 tape->merge_stage_size = 0;
2905 if (test_and_clear_bit(IDETAPE_FILEMARK, &tape->flags)) 2734 if (test_and_clear_bit(IDETAPE_FILEMARK, &tape->flags))
2906 ++count; 2735 ++count;
@@ -2910,24 +2739,27 @@ static int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_c
2910 set_bit(IDETAPE_FILEMARK, &tape->flags); 2739 set_bit(IDETAPE_FILEMARK, &tape->flags);
2911 return 0; 2740 return 0;
2912 } 2741 }
2913 spin_lock_irqsave(&tape->spinlock, flags); 2742 spin_lock_irqsave(&tape->lock, flags);
2914 if (tape->first_stage == tape->active_stage) { 2743 if (tape->first_stage == tape->active_stage) {
2915 /* 2744 /*
2916 * We have reached the active stage in the read pipeline. 2745 * We have reached the active stage in the read
2917 * There is no point in allowing the drive to continue 2746 * pipeline. There is no point in allowing the
2918 * reading any farther, so we stop the pipeline. 2747 * drive to continue reading any farther, so we
2748 * stop the pipeline.
2919 * 2749 *
2920 * This section should be moved to a separate subroutine, 2750 * This section should be moved to a separate
2921 * because a similar function is performed in 2751 * subroutine because similar operations are
2922 * __idetape_discard_read_pipeline(), for example. 2752 * done in __idetape_discard_read_pipeline(),
2753 * for example.
2923 */ 2754 */
2924 tape->next_stage = NULL; 2755 tape->next_stage = NULL;
2925 spin_unlock_irqrestore(&tape->spinlock, flags); 2756 spin_unlock_irqrestore(&tape->lock, flags);
2926 idetape_wait_first_stage(drive); 2757 idetape_wait_first_stage(drive);
2927 tape->next_stage = tape->first_stage->next; 2758 tape->next_stage = tape->first_stage->next;
2928 } else 2759 } else
2929 spin_unlock_irqrestore(&tape->spinlock, flags); 2760 spin_unlock_irqrestore(&tape->lock, flags);
2930 if (tape->first_stage->rq.errors == IDETAPE_ERROR_FILEMARK) 2761 if (tape->first_stage->rq.errors ==
2762 IDETAPE_ERROR_FILEMARK)
2931 ++count; 2763 ++count;
2932 idetape_remove_stage_head(drive); 2764 idetape_remove_stage_head(drive);
2933 } 2765 }
@@ -2935,73 +2767,74 @@ static int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_c
2935 } 2767 }
2936 2768
2937 /* 2769 /*
2938 * The filemark was not found in our internal pipeline. 2770 * The filemark was not found in our internal pipeline; now we can issue
2939 * Now we can issue the space command. 2771 * the space command.
2940 */ 2772 */
2941 switch (mt_op) { 2773 switch (mt_op) {
2942 case MTFSF: 2774 case MTFSF:
2943 case MTBSF: 2775 case MTBSF:
2944 idetape_create_space_cmd(&pc,mt_count-count,IDETAPE_SPACE_OVER_FILEMARK); 2776 idetape_create_space_cmd(&pc, mt_count - count,
2945 return (idetape_queue_pc_tail(drive, &pc)); 2777 IDETAPE_SPACE_OVER_FILEMARK);
2946 case MTFSFM: 2778 return idetape_queue_pc_tail(drive, &pc);
2947 case MTBSFM: 2779 case MTFSFM:
2948 if (!sprev) 2780 case MTBSFM:
2949 return (-EIO); 2781 if (!sprev)
2950 retval = idetape_space_over_filemarks(drive, MTFSF, mt_count-count); 2782 return -EIO;
2951 if (retval) return (retval); 2783 retval = idetape_space_over_filemarks(drive, MTFSF,
2952 count = (MTBSFM == mt_op ? 1 : -1); 2784 mt_count - count);
2953 return (idetape_space_over_filemarks(drive, MTFSF, count)); 2785 if (retval)
2954 default: 2786 return retval;
2955 printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n",mt_op); 2787 count = (MTBSFM == mt_op ? 1 : -1);
2956 return (-EIO); 2788 return idetape_space_over_filemarks(drive, MTFSF, count);
2789 default:
2790 printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n",
2791 mt_op);
2792 return -EIO;
2957 } 2793 }
2958} 2794}
2959 2795
2960
2961/* 2796/*
2962 * Our character device read / write functions. 2797 * Our character device read / write functions.
2963 * 2798 *
2964 * The tape is optimized to maximize throughput when it is transferring 2799 * The tape is optimized to maximize throughput when it is transferring an
2965 * an integral number of the "continuous transfer limit", which is 2800 * integral number of the "continuous transfer limit", which is a parameter of
2966 * a parameter of the specific tape (26 KB on my particular tape). 2801 * the specific tape (26kB on my particular tape, 32kB for Onstream).
2967 * (32 kB for Onstream)
2968 * 2802 *
2969 * As of version 1.3 of the driver, the character device provides an 2803 * As of version 1.3 of the driver, the character device provides an abstract
2970 * abstract continuous view of the media - any mix of block sizes (even 1 2804 * continuous view of the media - any mix of block sizes (even 1 byte) on the
2971 * byte) on the same backup/restore procedure is supported. The driver 2805 * same backup/restore procedure is supported. The driver will internally
2972 * will internally convert the requests to the recommended transfer unit, 2806 * convert the requests to the recommended transfer unit, so that an unmatch
2973 * so that an unmatch between the user's block size to the recommended 2807 * between the user's block size to the recommended size will only result in a
2974 * size will only result in a (slightly) increased driver overhead, but 2808 * (slightly) increased driver overhead, but will no longer hit performance.
2975 * will no longer hit performance. 2809 * This is not applicable to Onstream.
2976 * This is not applicable to Onstream.
2977 */ 2810 */
2978static ssize_t idetape_chrdev_read (struct file *file, char __user *buf, 2811static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
2979 size_t count, loff_t *ppos) 2812 size_t count, loff_t *ppos)
2980{ 2813{
2981 struct ide_tape_obj *tape = ide_tape_f(file); 2814 struct ide_tape_obj *tape = ide_tape_f(file);
2982 ide_drive_t *drive = tape->drive; 2815 ide_drive_t *drive = tape->drive;
2983 ssize_t bytes_read,temp, actually_read = 0, rc; 2816 ssize_t bytes_read, temp, actually_read = 0, rc;
2984 ssize_t ret = 0; 2817 ssize_t ret = 0;
2985 u16 ctl = *(u16 *)&tape->caps[12]; 2818 u16 ctl = *(u16 *)&tape->caps[12];
2986 2819
2987#if IDETAPE_DEBUG_LOG 2820 debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count);
2988 if (tape->debug_level >= 3)
2989 printk(KERN_INFO "ide-tape: Reached idetape_chrdev_read, count %Zd\n", count);
2990#endif /* IDETAPE_DEBUG_LOG */
2991 2821
2992 if (tape->chrdev_direction != idetape_direction_read) { 2822 if (tape->chrdev_dir != IDETAPE_DIR_READ) {
2993 if (test_bit(IDETAPE_DETECT_BS, &tape->flags)) 2823 if (test_bit(IDETAPE_DETECT_BS, &tape->flags))
2994 if (count > tape->tape_block_size && 2824 if (count > tape->blk_size &&
2995 (count % tape->tape_block_size) == 0) 2825 (count % tape->blk_size) == 0)
2996 tape->user_bs_factor = count / tape->tape_block_size; 2826 tape->user_bs_factor = count / tape->blk_size;
2997 } 2827 }
2998 if ((rc = idetape_initiate_read(drive, tape->max_stages)) < 0) 2828 rc = idetape_init_read(drive, tape->max_stages);
2829 if (rc < 0)
2999 return rc; 2830 return rc;
3000 if (count == 0) 2831 if (count == 0)
3001 return (0); 2832 return (0);
3002 if (tape->merge_stage_size) { 2833 if (tape->merge_stage_size) {
3003 actually_read = min((unsigned int)(tape->merge_stage_size), (unsigned int)count); 2834 actually_read = min((unsigned int)(tape->merge_stage_size),
3004 if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, actually_read)) 2835 (unsigned int)count);
2836 if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage,
2837 actually_read))
3005 ret = -EFAULT; 2838 ret = -EFAULT;
3006 buf += actually_read; 2839 buf += actually_read;
3007 tape->merge_stage_size -= actually_read; 2840 tape->merge_stage_size -= actually_read;
@@ -3011,7 +2844,8 @@ static ssize_t idetape_chrdev_read (struct file *file, char __user *buf,
3011 bytes_read = idetape_add_chrdev_read_request(drive, ctl); 2844 bytes_read = idetape_add_chrdev_read_request(drive, ctl);
3012 if (bytes_read <= 0) 2845 if (bytes_read <= 0)
3013 goto finish; 2846 goto finish;
3014 if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, bytes_read)) 2847 if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage,
2848 bytes_read))
3015 ret = -EFAULT; 2849 ret = -EFAULT;
3016 buf += bytes_read; 2850 buf += bytes_read;
3017 count -= bytes_read; 2851 count -= bytes_read;
@@ -3022,25 +2856,24 @@ static ssize_t idetape_chrdev_read (struct file *file, char __user *buf,
3022 if (bytes_read <= 0) 2856 if (bytes_read <= 0)
3023 goto finish; 2857 goto finish;
3024 temp = min((unsigned long)count, (unsigned long)bytes_read); 2858 temp = min((unsigned long)count, (unsigned long)bytes_read);
3025 if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, temp)) 2859 if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage,
2860 temp))
3026 ret = -EFAULT; 2861 ret = -EFAULT;
3027 actually_read += temp; 2862 actually_read += temp;
3028 tape->merge_stage_size = bytes_read-temp; 2863 tape->merge_stage_size = bytes_read-temp;
3029 } 2864 }
3030finish: 2865finish:
3031 if (!actually_read && test_bit(IDETAPE_FILEMARK, &tape->flags)) { 2866 if (!actually_read && test_bit(IDETAPE_FILEMARK, &tape->flags)) {
3032#if IDETAPE_DEBUG_LOG 2867 debug_log(DBG_SENSE, "%s: spacing over filemark\n", tape->name);
3033 if (tape->debug_level >= 2) 2868
3034 printk(KERN_INFO "ide-tape: %s: spacing over filemark\n", tape->name);
3035#endif
3036 idetape_space_over_filemarks(drive, MTFSF, 1); 2869 idetape_space_over_filemarks(drive, MTFSF, 1);
3037 return 0; 2870 return 0;
3038 } 2871 }
3039 2872
3040 return (ret) ? ret : actually_read; 2873 return ret ? ret : actually_read;
3041} 2874}
3042 2875
3043static ssize_t idetape_chrdev_write (struct file *file, const char __user *buf, 2876static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
3044 size_t count, loff_t *ppos) 2877 size_t count, loff_t *ppos)
3045{ 2878{
3046 struct ide_tape_obj *tape = ide_tape_f(file); 2879 struct ide_tape_obj *tape = ide_tape_f(file);
@@ -3053,39 +2886,37 @@ static ssize_t idetape_chrdev_write (struct file *file, const char __user *buf,
3053 if (tape->write_prot) 2886 if (tape->write_prot)
3054 return -EACCES; 2887 return -EACCES;
3055 2888
3056#if IDETAPE_DEBUG_LOG 2889 debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count);
3057 if (tape->debug_level >= 3)
3058 printk(KERN_INFO "ide-tape: Reached idetape_chrdev_write, "
3059 "count %Zd\n", count);
3060#endif /* IDETAPE_DEBUG_LOG */
3061 2890
3062 /* Initialize write operation */ 2891 /* Initialize write operation */
3063 if (tape->chrdev_direction != idetape_direction_write) { 2892 if (tape->chrdev_dir != IDETAPE_DIR_WRITE) {
3064 if (tape->chrdev_direction == idetape_direction_read) 2893 if (tape->chrdev_dir == IDETAPE_DIR_READ)
3065 idetape_discard_read_pipeline(drive, 1); 2894 idetape_discard_read_pipeline(drive, 1);
3066 if (tape->merge_stage || tape->merge_stage_size) { 2895 if (tape->merge_stage || tape->merge_stage_size) {
3067 printk(KERN_ERR "ide-tape: merge_stage_size " 2896 printk(KERN_ERR "ide-tape: merge_stage_size "
3068 "should be 0 now\n"); 2897 "should be 0 now\n");
3069 tape->merge_stage_size = 0; 2898 tape->merge_stage_size = 0;
3070 } 2899 }
3071 if ((tape->merge_stage = __idetape_kmalloc_stage(tape, 0, 0)) == NULL) 2900 tape->merge_stage = __idetape_kmalloc_stage(tape, 0, 0);
2901 if (!tape->merge_stage)
3072 return -ENOMEM; 2902 return -ENOMEM;
3073 tape->chrdev_direction = idetape_direction_write; 2903 tape->chrdev_dir = IDETAPE_DIR_WRITE;
3074 idetape_init_merge_stage(tape); 2904 idetape_init_merge_stage(tape);
3075 2905
3076 /* 2906 /*
3077 * Issue a write 0 command to ensure that DSC handshake 2907 * Issue a write 0 command to ensure that DSC handshake is
3078 * is switched from completion mode to buffer available 2908 * switched from completion mode to buffer available mode. No
3079 * mode. 2909 * point in issuing this if DSC overlap isn't supported, some
3080 * No point in issuing this if DSC overlap isn't supported, 2910 * drives (Seagate STT3401A) will return an error.
3081 * some drives (Seagate STT3401A) will return an error.
3082 */ 2911 */
3083 if (drive->dsc_overlap) { 2912 if (drive->dsc_overlap) {
3084 ssize_t retval = idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, 0, tape->merge_stage->bh); 2913 ssize_t retval = idetape_queue_rw_tail(drive,
2914 REQ_IDETAPE_WRITE, 0,
2915 tape->merge_stage->bh);
3085 if (retval < 0) { 2916 if (retval < 0) {
3086 __idetape_kfree_stage(tape->merge_stage); 2917 __idetape_kfree_stage(tape->merge_stage);
3087 tape->merge_stage = NULL; 2918 tape->merge_stage = NULL;
3088 tape->chrdev_direction = idetape_direction_none; 2919 tape->chrdev_dir = IDETAPE_DIR_NONE;
3089 return retval; 2920 return retval;
3090 } 2921 }
3091 } 2922 }
@@ -3096,11 +2927,14 @@ static ssize_t idetape_chrdev_write (struct file *file, const char __user *buf,
3096 idetape_restart_speed_control(drive); 2927 idetape_restart_speed_control(drive);
3097 if (tape->merge_stage_size) { 2928 if (tape->merge_stage_size) {
3098 if (tape->merge_stage_size >= tape->stage_size) { 2929 if (tape->merge_stage_size >= tape->stage_size) {
3099 printk(KERN_ERR "ide-tape: bug: merge buffer too big\n"); 2930 printk(KERN_ERR "ide-tape: bug: merge buf too big\n");
3100 tape->merge_stage_size = 0; 2931 tape->merge_stage_size = 0;
3101 } 2932 }
3102 actually_written = min((unsigned int)(tape->stage_size - tape->merge_stage_size), (unsigned int)count); 2933 actually_written = min((unsigned int)
3103 if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf, actually_written)) 2934 (tape->stage_size - tape->merge_stage_size),
2935 (unsigned int)count);
2936 if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf,
2937 actually_written))
3104 ret = -EFAULT; 2938 ret = -EFAULT;
3105 buf += actually_written; 2939 buf += actually_written;
3106 tape->merge_stage_size += actually_written; 2940 tape->merge_stage_size += actually_written;
@@ -3116,7 +2950,8 @@ static ssize_t idetape_chrdev_write (struct file *file, const char __user *buf,
3116 } 2950 }
3117 while (count >= tape->stage_size) { 2951 while (count >= tape->stage_size) {
3118 ssize_t retval; 2952 ssize_t retval;
3119 if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf, tape->stage_size)) 2953 if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf,
2954 tape->stage_size))
3120 ret = -EFAULT; 2955 ret = -EFAULT;
3121 buf += tape->stage_size; 2956 buf += tape->stage_size;
3122 count -= tape->stage_size; 2957 count -= tape->stage_size;
@@ -3127,14 +2962,15 @@ static ssize_t idetape_chrdev_write (struct file *file, const char __user *buf,
3127 } 2962 }
3128 if (count) { 2963 if (count) {
3129 actually_written += count; 2964 actually_written += count;
3130 if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf, count)) 2965 if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf,
2966 count))
3131 ret = -EFAULT; 2967 ret = -EFAULT;
3132 tape->merge_stage_size += count; 2968 tape->merge_stage_size += count;
3133 } 2969 }
3134 return (ret) ? ret : actually_written; 2970 return ret ? ret : actually_written;
3135} 2971}
3136 2972
3137static int idetape_write_filemark (ide_drive_t *drive) 2973static int idetape_write_filemark(ide_drive_t *drive)
3138{ 2974{
3139 idetape_pc_t pc; 2975 idetape_pc_t pc;
3140 2976
@@ -3165,113 +3001,117 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
3165{ 3001{
3166 idetape_tape_t *tape = drive->driver_data; 3002 idetape_tape_t *tape = drive->driver_data;
3167 idetape_pc_t pc; 3003 idetape_pc_t pc;
3168 int i,retval; 3004 int i, retval;
3169 3005
3170#if IDETAPE_DEBUG_LOG 3006 debug_log(DBG_ERR, "Handling MTIOCTOP ioctl: mt_op=%d, mt_count=%d\n",
3171 if (tape->debug_level >= 1) 3007 mt_op, mt_count);
3172 printk(KERN_INFO "ide-tape: Handling MTIOCTOP ioctl: " 3008
3173 "mt_op=%d, mt_count=%d\n", mt_op, mt_count); 3009 /* Commands which need our pipelined read-ahead stages. */
3174#endif /* IDETAPE_DEBUG_LOG */
3175 /*
3176 * Commands which need our pipelined read-ahead stages.
3177 */
3178 switch (mt_op) { 3010 switch (mt_op) {
3179 case MTFSF: 3011 case MTFSF:
3180 case MTFSFM: 3012 case MTFSFM:
3181 case MTBSF: 3013 case MTBSF:
3182 case MTBSFM: 3014 case MTBSFM:
3183 if (!mt_count) 3015 if (!mt_count)
3184 return (0); 3016 return 0;
3185 return (idetape_space_over_filemarks(drive,mt_op,mt_count)); 3017 return idetape_space_over_filemarks(drive, mt_op, mt_count);
3186 default: 3018 default:
3187 break; 3019 break;
3188 } 3020 }
3021
3189 switch (mt_op) { 3022 switch (mt_op) {
3190 case MTWEOF: 3023 case MTWEOF:
3191 if (tape->write_prot) 3024 if (tape->write_prot)
3192 return -EACCES; 3025 return -EACCES;
3193 idetape_discard_read_pipeline(drive, 1); 3026 idetape_discard_read_pipeline(drive, 1);
3194 for (i = 0; i < mt_count; i++) { 3027 for (i = 0; i < mt_count; i++) {
3195 retval = idetape_write_filemark(drive); 3028 retval = idetape_write_filemark(drive);
3196 if (retval) 3029 if (retval)
3197 return retval; 3030 return retval;
3198 } 3031 }
3199 return (0); 3032 return 0;
3200 case MTREW: 3033 case MTREW:
3201 idetape_discard_read_pipeline(drive, 0); 3034 idetape_discard_read_pipeline(drive, 0);
3202 if (idetape_rewind_tape(drive)) 3035 if (idetape_rewind_tape(drive))
3036 return -EIO;
3037 return 0;
3038 case MTLOAD:
3039 idetape_discard_read_pipeline(drive, 0);
3040 idetape_create_load_unload_cmd(drive, &pc,
3041 IDETAPE_LU_LOAD_MASK);
3042 return idetape_queue_pc_tail(drive, &pc);
3043 case MTUNLOAD:
3044 case MTOFFL:
3045 /*
3046 * If door is locked, attempt to unlock before
3047 * attempting to eject.
3048 */
3049 if (tape->door_locked) {
3050 if (idetape_create_prevent_cmd(drive, &pc, 0))
3051 if (!idetape_queue_pc_tail(drive, &pc))
3052 tape->door_locked = DOOR_UNLOCKED;
3053 }
3054 idetape_discard_read_pipeline(drive, 0);
3055 idetape_create_load_unload_cmd(drive, &pc,
3056 !IDETAPE_LU_LOAD_MASK);
3057 retval = idetape_queue_pc_tail(drive, &pc);
3058 if (!retval)
3059 clear_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags);
3060 return retval;
3061 case MTNOP:
3062 idetape_discard_read_pipeline(drive, 0);
3063 return idetape_flush_tape_buffers(drive);
3064 case MTRETEN:
3065 idetape_discard_read_pipeline(drive, 0);
3066 idetape_create_load_unload_cmd(drive, &pc,
3067 IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK);
3068 return idetape_queue_pc_tail(drive, &pc);
3069 case MTEOM:
3070 idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD);
3071 return idetape_queue_pc_tail(drive, &pc);
3072 case MTERASE:
3073 (void)idetape_rewind_tape(drive);
3074 idetape_create_erase_cmd(&pc);
3075 return idetape_queue_pc_tail(drive, &pc);
3076 case MTSETBLK:
3077 if (mt_count) {
3078 if (mt_count < tape->blk_size ||
3079 mt_count % tape->blk_size)
3203 return -EIO; 3080 return -EIO;
3081 tape->user_bs_factor = mt_count / tape->blk_size;
3082 clear_bit(IDETAPE_DETECT_BS, &tape->flags);
3083 } else
3084 set_bit(IDETAPE_DETECT_BS, &tape->flags);
3085 return 0;
3086 case MTSEEK:
3087 idetape_discard_read_pipeline(drive, 0);
3088 return idetape_position_tape(drive,
3089 mt_count * tape->user_bs_factor, tape->partition, 0);
3090 case MTSETPART:
3091 idetape_discard_read_pipeline(drive, 0);
3092 return idetape_position_tape(drive, 0, mt_count, 0);
3093 case MTFSR:
3094 case MTBSR:
3095 case MTLOCK:
3096 if (!idetape_create_prevent_cmd(drive, &pc, 1))
3204 return 0; 3097 return 0;
3205 case MTLOAD: 3098 retval = idetape_queue_pc_tail(drive, &pc);
3206 idetape_discard_read_pipeline(drive, 0); 3099 if (retval)
3207 idetape_create_load_unload_cmd(drive, &pc, IDETAPE_LU_LOAD_MASK);
3208 return (idetape_queue_pc_tail(drive, &pc));
3209 case MTUNLOAD:
3210 case MTOFFL:
3211 /*
3212 * If door is locked, attempt to unlock before
3213 * attempting to eject.
3214 */
3215 if (tape->door_locked) {
3216 if (idetape_create_prevent_cmd(drive, &pc, 0))
3217 if (!idetape_queue_pc_tail(drive, &pc))
3218 tape->door_locked = DOOR_UNLOCKED;
3219 }
3220 idetape_discard_read_pipeline(drive, 0);
3221 idetape_create_load_unload_cmd(drive, &pc,!IDETAPE_LU_LOAD_MASK);
3222 retval = idetape_queue_pc_tail(drive, &pc);
3223 if (!retval)
3224 clear_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags);
3225 return retval; 3100 return retval;
3226 case MTNOP: 3101 tape->door_locked = DOOR_EXPLICITLY_LOCKED;
3227 idetape_discard_read_pipeline(drive, 0); 3102 return 0;
3228 return (idetape_flush_tape_buffers(drive)); 3103 case MTUNLOCK:
3229 case MTRETEN: 3104 if (!idetape_create_prevent_cmd(drive, &pc, 0))
3230 idetape_discard_read_pipeline(drive, 0);
3231 idetape_create_load_unload_cmd(drive, &pc,IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK);
3232 return (idetape_queue_pc_tail(drive, &pc));
3233 case MTEOM:
3234 idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD);
3235 return (idetape_queue_pc_tail(drive, &pc));
3236 case MTERASE:
3237 (void) idetape_rewind_tape(drive);
3238 idetape_create_erase_cmd(&pc);
3239 return (idetape_queue_pc_tail(drive, &pc));
3240 case MTSETBLK:
3241 if (mt_count) {
3242 if (mt_count < tape->tape_block_size || mt_count % tape->tape_block_size)
3243 return -EIO;
3244 tape->user_bs_factor = mt_count / tape->tape_block_size;
3245 clear_bit(IDETAPE_DETECT_BS, &tape->flags);
3246 } else
3247 set_bit(IDETAPE_DETECT_BS, &tape->flags);
3248 return 0;
3249 case MTSEEK:
3250 idetape_discard_read_pipeline(drive, 0);
3251 return idetape_position_tape(drive, mt_count * tape->user_bs_factor, tape->partition, 0);
3252 case MTSETPART:
3253 idetape_discard_read_pipeline(drive, 0);
3254 return (idetape_position_tape(drive, 0, mt_count, 0));
3255 case MTFSR:
3256 case MTBSR:
3257 case MTLOCK:
3258 if (!idetape_create_prevent_cmd(drive, &pc, 1))
3259 return 0;
3260 retval = idetape_queue_pc_tail(drive, &pc);
3261 if (retval) return retval;
3262 tape->door_locked = DOOR_EXPLICITLY_LOCKED;
3263 return 0;
3264 case MTUNLOCK:
3265 if (!idetape_create_prevent_cmd(drive, &pc, 0))
3266 return 0;
3267 retval = idetape_queue_pc_tail(drive, &pc);
3268 if (retval) return retval;
3269 tape->door_locked = DOOR_UNLOCKED;
3270 return 0; 3105 return 0;
3271 default: 3106 retval = idetape_queue_pc_tail(drive, &pc);
3272 printk(KERN_ERR "ide-tape: MTIO operation %d not " 3107 if (retval)
3273 "supported\n", mt_op); 3108 return retval;
3274 return (-EIO); 3109 tape->door_locked = DOOR_UNLOCKED;
3110 return 0;
3111 default:
3112 printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n",
3113 mt_op);
3114 return -EIO;
3275 } 3115 }
3276} 3116}
3277 3117
@@ -3288,50 +3128,51 @@ static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
3288 struct mtop mtop; 3128 struct mtop mtop;
3289 struct mtget mtget; 3129 struct mtget mtget;
3290 struct mtpos mtpos; 3130 struct mtpos mtpos;
3291 int block_offset = 0, position = tape->first_frame_position; 3131 int block_offset = 0, position = tape->first_frame;
3292 void __user *argp = (void __user *)arg; 3132 void __user *argp = (void __user *)arg;
3293 3133
3294#if IDETAPE_DEBUG_LOG 3134 debug_log(DBG_CHRDEV, "Enter %s, cmd=%u\n", __func__, cmd);
3295 if (tape->debug_level >= 3)
3296 printk(KERN_INFO "ide-tape: Reached idetape_chrdev_ioctl, "
3297 "cmd=%u\n", cmd);
3298#endif /* IDETAPE_DEBUG_LOG */
3299 3135
3300 tape->restart_speed_control_req = 1; 3136 tape->restart_speed_control_req = 1;
3301 if (tape->chrdev_direction == idetape_direction_write) { 3137 if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
3302 idetape_empty_write_pipeline(drive); 3138 idetape_empty_write_pipeline(drive);
3303 idetape_flush_tape_buffers(drive); 3139 idetape_flush_tape_buffers(drive);
3304 } 3140 }
3305 if (cmd == MTIOCGET || cmd == MTIOCPOS) { 3141 if (cmd == MTIOCGET || cmd == MTIOCPOS) {
3306 block_offset = idetape_pipeline_size(drive) / (tape->tape_block_size * tape->user_bs_factor); 3142 block_offset = idetape_pipeline_size(drive) /
3307 if ((position = idetape_read_position(drive)) < 0) 3143 (tape->blk_size * tape->user_bs_factor);
3144 position = idetape_read_position(drive);
3145 if (position < 0)
3308 return -EIO; 3146 return -EIO;
3309 } 3147 }
3310 switch (cmd) { 3148 switch (cmd) {
3311 case MTIOCTOP: 3149 case MTIOCTOP:
3312 if (copy_from_user(&mtop, argp, sizeof (struct mtop))) 3150 if (copy_from_user(&mtop, argp, sizeof(struct mtop)))
3313 return -EFAULT; 3151 return -EFAULT;
3314 return (idetape_mtioctop(drive,mtop.mt_op,mtop.mt_count)); 3152 return idetape_mtioctop(drive, mtop.mt_op, mtop.mt_count);
3315 case MTIOCGET: 3153 case MTIOCGET:
3316 memset(&mtget, 0, sizeof (struct mtget)); 3154 memset(&mtget, 0, sizeof(struct mtget));
3317 mtget.mt_type = MT_ISSCSI2; 3155 mtget.mt_type = MT_ISSCSI2;
3318 mtget.mt_blkno = position / tape->user_bs_factor - block_offset; 3156 mtget.mt_blkno = position / tape->user_bs_factor - block_offset;
3319 mtget.mt_dsreg = ((tape->tape_block_size * tape->user_bs_factor) << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK; 3157 mtget.mt_dsreg =
3320 if (tape->drv_write_prot) { 3158 ((tape->blk_size * tape->user_bs_factor)
3321 mtget.mt_gstat |= GMT_WR_PROT(0xffffffff); 3159 << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK;
3322 } 3160
3323 if (copy_to_user(argp, &mtget, sizeof(struct mtget))) 3161 if (tape->drv_write_prot)
3324 return -EFAULT; 3162 mtget.mt_gstat |= GMT_WR_PROT(0xffffffff);
3325 return 0; 3163
3326 case MTIOCPOS: 3164 if (copy_to_user(argp, &mtget, sizeof(struct mtget)))
3327 mtpos.mt_blkno = position / tape->user_bs_factor - block_offset; 3165 return -EFAULT;
3328 if (copy_to_user(argp, &mtpos, sizeof(struct mtpos))) 3166 return 0;
3329 return -EFAULT; 3167 case MTIOCPOS:
3330 return 0; 3168 mtpos.mt_blkno = position / tape->user_bs_factor - block_offset;
3331 default: 3169 if (copy_to_user(argp, &mtpos, sizeof(struct mtpos)))
3332 if (tape->chrdev_direction == idetape_direction_read) 3170 return -EFAULT;
3333 idetape_discard_read_pipeline(drive, 1); 3171 return 0;
3334 return idetape_blkdev_ioctl(drive, cmd, arg); 3172 default:
3173 if (tape->chrdev_dir == IDETAPE_DIR_READ)
3174 idetape_discard_read_pipeline(drive, 1);
3175 return idetape_blkdev_ioctl(drive, cmd, arg);
3335 } 3176 }
3336} 3177}
3337 3178
@@ -3347,23 +3188,20 @@ static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive)
3347 idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR); 3188 idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR);
3348 if (idetape_queue_pc_tail(drive, &pc)) { 3189 if (idetape_queue_pc_tail(drive, &pc)) {
3349 printk(KERN_ERR "ide-tape: Can't get block descriptor\n"); 3190 printk(KERN_ERR "ide-tape: Can't get block descriptor\n");
3350 if (tape->tape_block_size == 0) { 3191 if (tape->blk_size == 0) {
3351 printk(KERN_WARNING "ide-tape: Cannot deal with zero " 3192 printk(KERN_WARNING "ide-tape: Cannot deal with zero "
3352 "block size, assuming 32k\n"); 3193 "block size, assuming 32k\n");
3353 tape->tape_block_size = 32768; 3194 tape->blk_size = 32768;
3354 } 3195 }
3355 return; 3196 return;
3356 } 3197 }
3357 tape->tape_block_size = (pc.buffer[4 + 5] << 16) + 3198 tape->blk_size = (pc.buffer[4 + 5] << 16) +
3358 (pc.buffer[4 + 6] << 8) + 3199 (pc.buffer[4 + 6] << 8) +
3359 pc.buffer[4 + 7]; 3200 pc.buffer[4 + 7];
3360 tape->drv_write_prot = (pc.buffer[2] & 0x80) >> 7; 3201 tape->drv_write_prot = (pc.buffer[2] & 0x80) >> 7;
3361} 3202}
3362 3203
3363/* 3204static int idetape_chrdev_open(struct inode *inode, struct file *filp)
3364 * Our character device open function.
3365 */
3366static int idetape_chrdev_open (struct inode *inode, struct file *filp)
3367{ 3205{
3368 unsigned int minor = iminor(inode), i = minor & ~0xc0; 3206 unsigned int minor = iminor(inode), i = minor & ~0xc0;
3369 ide_drive_t *drive; 3207 ide_drive_t *drive;
@@ -3371,6 +3209,15 @@ static int idetape_chrdev_open (struct inode *inode, struct file *filp)
3371 idetape_pc_t pc; 3209 idetape_pc_t pc;
3372 int retval; 3210 int retval;
3373 3211
3212 if (i >= MAX_HWIFS * MAX_DRIVES)
3213 return -ENXIO;
3214
3215 tape = ide_tape_chrdev_get(i);
3216 if (!tape)
3217 return -ENXIO;
3218
3219 debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
3220
3374 /* 3221 /*
3375 * We really want to do nonseekable_open(inode, filp); here, but some 3222 * We really want to do nonseekable_open(inode, filp); here, but some
3376 * versions of tar incorrectly call lseek on tapes and bail out if that 3223 * versions of tar incorrectly call lseek on tapes and bail out if that
@@ -3378,16 +3225,6 @@ static int idetape_chrdev_open (struct inode *inode, struct file *filp)
3378 */ 3225 */
3379 filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE); 3226 filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE);
3380 3227
3381#if IDETAPE_DEBUG_LOG
3382 printk(KERN_INFO "ide-tape: Reached idetape_chrdev_open\n");
3383#endif /* IDETAPE_DEBUG_LOG */
3384
3385 if (i >= MAX_HWIFS * MAX_DRIVES)
3386 return -ENXIO;
3387
3388 if (!(tape = ide_tape_chrdev_get(i)))
3389 return -ENXIO;
3390
3391 drive = tape->drive; 3228 drive = tape->drive;
3392 3229
3393 filp->private_data = tape; 3230 filp->private_data = tape;
@@ -3408,7 +3245,7 @@ static int idetape_chrdev_open (struct inode *inode, struct file *filp)
3408 if (!test_bit(IDETAPE_ADDRESS_VALID, &tape->flags)) 3245 if (!test_bit(IDETAPE_ADDRESS_VALID, &tape->flags))
3409 (void)idetape_rewind_tape(drive); 3246 (void)idetape_rewind_tape(drive);
3410 3247
3411 if (tape->chrdev_direction != idetape_direction_read) 3248 if (tape->chrdev_dir != IDETAPE_DIR_READ)
3412 clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags); 3249 clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags);
3413 3250
3414 /* Read block size and write protect status from drive. */ 3251 /* Read block size and write protect status from drive. */
@@ -3430,10 +3267,8 @@ static int idetape_chrdev_open (struct inode *inode, struct file *filp)
3430 } 3267 }
3431 } 3268 }
3432 3269
3433 /* 3270 /* Lock the tape drive door so user can't eject. */
3434 * Lock the tape drive door so user can't eject. 3271 if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
3435 */
3436 if (tape->chrdev_direction == idetape_direction_none) {
3437 if (idetape_create_prevent_cmd(drive, &pc, 1)) { 3272 if (idetape_create_prevent_cmd(drive, &pc, 1)) {
3438 if (!idetape_queue_pc_tail(drive, &pc)) { 3273 if (!idetape_queue_pc_tail(drive, &pc)) {
3439 if (tape->door_locked != DOOR_EXPLICITLY_LOCKED) 3274 if (tape->door_locked != DOOR_EXPLICITLY_LOCKED)
@@ -3450,14 +3285,15 @@ out_put_tape:
3450 return retval; 3285 return retval;
3451} 3286}
3452 3287
3453static void idetape_write_release (ide_drive_t *drive, unsigned int minor) 3288static void idetape_write_release(ide_drive_t *drive, unsigned int minor)
3454{ 3289{
3455 idetape_tape_t *tape = drive->driver_data; 3290 idetape_tape_t *tape = drive->driver_data;
3456 3291
3457 idetape_empty_write_pipeline(drive); 3292 idetape_empty_write_pipeline(drive);
3458 tape->merge_stage = __idetape_kmalloc_stage(tape, 1, 0); 3293 tape->merge_stage = __idetape_kmalloc_stage(tape, 1, 0);
3459 if (tape->merge_stage != NULL) { 3294 if (tape->merge_stage != NULL) {
3460 idetape_pad_zeros(drive, tape->tape_block_size * (tape->user_bs_factor - 1)); 3295 idetape_pad_zeros(drive, tape->blk_size *
3296 (tape->user_bs_factor - 1));
3461 __idetape_kfree_stage(tape->merge_stage); 3297 __idetape_kfree_stage(tape->merge_stage);
3462 tape->merge_stage = NULL; 3298 tape->merge_stage = NULL;
3463 } 3299 }
@@ -3466,10 +3302,7 @@ static void idetape_write_release (ide_drive_t *drive, unsigned int minor)
3466 idetape_flush_tape_buffers(drive); 3302 idetape_flush_tape_buffers(drive);
3467} 3303}
3468 3304
3469/* 3305static int idetape_chrdev_release(struct inode *inode, struct file *filp)
3470 * Our character device release function.
3471 */
3472static int idetape_chrdev_release (struct inode *inode, struct file *filp)
3473{ 3306{
3474 struct ide_tape_obj *tape = ide_tape_f(filp); 3307 struct ide_tape_obj *tape = ide_tape_f(filp);
3475 ide_drive_t *drive = tape->drive; 3308 ide_drive_t *drive = tape->drive;
@@ -3478,14 +3311,12 @@ static int idetape_chrdev_release (struct inode *inode, struct file *filp)
3478 3311
3479 lock_kernel(); 3312 lock_kernel();
3480 tape = drive->driver_data; 3313 tape = drive->driver_data;
3481#if IDETAPE_DEBUG_LOG
3482 if (tape->debug_level >= 3)
3483 printk(KERN_INFO "ide-tape: Reached idetape_chrdev_release\n");
3484#endif /* IDETAPE_DEBUG_LOG */
3485 3314
3486 if (tape->chrdev_direction == idetape_direction_write) 3315 debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
3316
3317 if (tape->chrdev_dir == IDETAPE_DIR_WRITE)
3487 idetape_write_release(drive, minor); 3318 idetape_write_release(drive, minor);
3488 if (tape->chrdev_direction == idetape_direction_read) { 3319 if (tape->chrdev_dir == IDETAPE_DIR_READ) {
3489 if (minor < 128) 3320 if (minor < 128)
3490 idetape_discard_read_pipeline(drive, 1); 3321 idetape_discard_read_pipeline(drive, 1);
3491 else 3322 else
@@ -3497,7 +3328,7 @@ static int idetape_chrdev_release (struct inode *inode, struct file *filp)
3497 } 3328 }
3498 if (minor < 128 && test_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags)) 3329 if (minor < 128 && test_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags))
3499 (void) idetape_rewind_tape(drive); 3330 (void) idetape_rewind_tape(drive);
3500 if (tape->chrdev_direction == idetape_direction_none) { 3331 if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
3501 if (tape->door_locked == DOOR_LOCKED) { 3332 if (tape->door_locked == DOOR_LOCKED) {
3502 if (idetape_create_prevent_cmd(drive, &pc, 0)) { 3333 if (idetape_create_prevent_cmd(drive, &pc, 0)) {
3503 if (!idetape_queue_pc_tail(drive, &pc)) 3334 if (!idetape_queue_pc_tail(drive, &pc))
@@ -3512,37 +3343,39 @@ static int idetape_chrdev_release (struct inode *inode, struct file *filp)
3512} 3343}
3513 3344
3514/* 3345/*
3515 * idetape_identify_device is called to check the contents of the 3346 * check the contents of the ATAPI IDENTIFY command results. We return:
3516 * ATAPI IDENTIFY command results. We return:
3517 * 3347 *
3518 * 1 If the tape can be supported by us, based on the information 3348 * 1 - If the tape can be supported by us, based on the information we have so
3519 * we have so far. 3349 * far.
3520 * 3350 *
3521 * 0 If this tape driver is not currently supported by us. 3351 * 0 - If this tape driver is not currently supported by us.
3522 */ 3352 */
3523static int idetape_identify_device (ide_drive_t *drive) 3353static int idetape_identify_device(ide_drive_t *drive)
3524{ 3354{
3525 struct idetape_id_gcw gcw; 3355 u8 gcw[2], protocol, device_type, removable, packet_size;
3526 struct hd_driveid *id = drive->id;
3527 3356
3528 if (drive->id_read == 0) 3357 if (drive->id_read == 0)
3529 return 1; 3358 return 1;
3530 3359
3531 *((unsigned short *) &gcw) = id->config; 3360 *((unsigned short *) &gcw) = drive->id->config;
3361
3362 protocol = (gcw[1] & 0xC0) >> 6;
3363 device_type = gcw[1] & 0x1F;
3364 removable = !!(gcw[0] & 0x80);
3365 packet_size = gcw[0] & 0x3;
3532 3366
3533 /* Check that we can support this device */ 3367 /* Check that we can support this device */
3534 3368 if (protocol != 2)
3535 if (gcw.protocol != 2)
3536 printk(KERN_ERR "ide-tape: Protocol (0x%02x) is not ATAPI\n", 3369 printk(KERN_ERR "ide-tape: Protocol (0x%02x) is not ATAPI\n",
3537 gcw.protocol); 3370 protocol);
3538 else if (gcw.device_type != 1) 3371 else if (device_type != 1)
3539 printk(KERN_ERR "ide-tape: Device type (0x%02x) is not set " 3372 printk(KERN_ERR "ide-tape: Device type (0x%02x) is not set "
3540 "to tape\n", gcw.device_type); 3373 "to tape\n", device_type);
3541 else if (!gcw.removable) 3374 else if (!removable)
3542 printk(KERN_ERR "ide-tape: The removable flag is not set\n"); 3375 printk(KERN_ERR "ide-tape: The removable flag is not set\n");
3543 else if (gcw.packet_size != 0) { 3376 else if (packet_size != 0) {
3544 printk(KERN_ERR "ide-tape: Packet size (0x%02x) is not 12 " 3377 printk(KERN_ERR "ide-tape: Packet size (0x%02x) is not 12"
3545 "bytes long\n", gcw.packet_size); 3378 " bytes\n", packet_size);
3546 } else 3379 } else
3547 return 1; 3380 return 1;
3548 return 0; 3381 return 0;
@@ -3550,9 +3383,9 @@ static int idetape_identify_device (ide_drive_t *drive)
3550 3383
3551static void idetape_get_inquiry_results(ide_drive_t *drive) 3384static void idetape_get_inquiry_results(ide_drive_t *drive)
3552{ 3385{
3553 char *r;
3554 idetape_tape_t *tape = drive->driver_data; 3386 idetape_tape_t *tape = drive->driver_data;
3555 idetape_pc_t pc; 3387 idetape_pc_t pc;
3388 char fw_rev[6], vendor_id[10], product_id[18];
3556 3389
3557 idetape_create_inquiry_cmd(&pc); 3390 idetape_create_inquiry_cmd(&pc);
3558 if (idetape_queue_pc_tail(drive, &pc)) { 3391 if (idetape_queue_pc_tail(drive, &pc)) {
@@ -3560,27 +3393,23 @@ static void idetape_get_inquiry_results(ide_drive_t *drive)
3560 tape->name); 3393 tape->name);
3561 return; 3394 return;
3562 } 3395 }
3563 memcpy(tape->vendor_id, &pc.buffer[8], 8); 3396 memcpy(vendor_id, &pc.buffer[8], 8);
3564 memcpy(tape->product_id, &pc.buffer[16], 16); 3397 memcpy(product_id, &pc.buffer[16], 16);
3565 memcpy(tape->firmware_revision, &pc.buffer[32], 4); 3398 memcpy(fw_rev, &pc.buffer[32], 4);
3566 3399
3567 ide_fixstring(tape->vendor_id, 10, 0); 3400 ide_fixstring(vendor_id, 10, 0);
3568 ide_fixstring(tape->product_id, 18, 0); 3401 ide_fixstring(product_id, 18, 0);
3569 ide_fixstring(tape->firmware_revision, 6, 0); 3402 ide_fixstring(fw_rev, 6, 0);
3570 r = tape->firmware_revision; 3403
3571 if (*(r + 1) == '.')
3572 tape->firmware_revision_num = (*r - '0') * 100 +
3573 (*(r + 2) - '0') * 10 + *(r + 3) - '0';
3574 printk(KERN_INFO "ide-tape: %s <-> %s: %s %s rev %s\n", 3404 printk(KERN_INFO "ide-tape: %s <-> %s: %s %s rev %s\n",
3575 drive->name, tape->name, tape->vendor_id, 3405 drive->name, tape->name, vendor_id, product_id, fw_rev);
3576 tape->product_id, tape->firmware_revision);
3577} 3406}
3578 3407
3579/* 3408/*
3580 * Ask the tape about its various parameters. In particular, we will adjust our 3409 * Ask the tape about its various parameters. In particular, we will adjust our
3581 * data transfer buffer size to the recommended value as returned by the tape. 3410 * data transfer buffer size to the recommended value as returned by the tape.
3582 */ 3411 */
3583static void idetape_get_mode_sense_results (ide_drive_t *drive) 3412static void idetape_get_mode_sense_results(ide_drive_t *drive)
3584{ 3413{
3585 idetape_tape_t *tape = drive->driver_data; 3414 idetape_tape_t *tape = drive->driver_data;
3586 idetape_pc_t pc; 3415 idetape_pc_t pc;
@@ -3591,7 +3420,7 @@ static void idetape_get_mode_sense_results (ide_drive_t *drive)
3591 if (idetape_queue_pc_tail(drive, &pc)) { 3420 if (idetape_queue_pc_tail(drive, &pc)) {
3592 printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming" 3421 printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming"
3593 " some default values\n"); 3422 " some default values\n");
3594 tape->tape_block_size = 512; 3423 tape->blk_size = 512;
3595 put_unaligned(52, (u16 *)&tape->caps[12]); 3424 put_unaligned(52, (u16 *)&tape->caps[12]);
3596 put_unaligned(540, (u16 *)&tape->caps[14]); 3425 put_unaligned(540, (u16 *)&tape->caps[14]);
3597 put_unaligned(6*52, (u16 *)&tape->caps[16]); 3426 put_unaligned(6*52, (u16 *)&tape->caps[16]);
@@ -3621,62 +3450,75 @@ static void idetape_get_mode_sense_results (ide_drive_t *drive)
3621 3450
3622 memcpy(&tape->caps, caps, 20); 3451 memcpy(&tape->caps, caps, 20);
3623 if (caps[7] & 0x02) 3452 if (caps[7] & 0x02)
3624 tape->tape_block_size = 512; 3453 tape->blk_size = 512;
3625 else if (caps[7] & 0x04) 3454 else if (caps[7] & 0x04)
3626 tape->tape_block_size = 1024; 3455 tape->blk_size = 1024;
3627} 3456}
3628 3457
3629#ifdef CONFIG_IDE_PROC_FS 3458#ifdef CONFIG_IDE_PROC_FS
3630static void idetape_add_settings (ide_drive_t *drive) 3459static void idetape_add_settings(ide_drive_t *drive)
3631{ 3460{
3632 idetape_tape_t *tape = drive->driver_data; 3461 idetape_tape_t *tape = drive->driver_data;
3633 3462
3634/*
3635 * drive setting name read/write data type min max mul_factor div_factor data pointer set function
3636 */
3637 ide_add_setting(drive, "buffer", SETTING_READ, TYPE_SHORT, 0, 0xffff, 3463 ide_add_setting(drive, "buffer", SETTING_READ, TYPE_SHORT, 0, 0xffff,
3638 1, 2, (u16 *)&tape->caps[16], NULL); 3464 1, 2, (u16 *)&tape->caps[16], NULL);
3639 ide_add_setting(drive, "pipeline_min", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->min_pipeline, NULL); 3465 ide_add_setting(drive, "pipeline_min", SETTING_RW, TYPE_INT, 1, 0xffff,
3640 ide_add_setting(drive, "pipeline", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->max_stages, NULL); 3466 tape->stage_size / 1024, 1, &tape->min_pipeline, NULL);
3641 ide_add_setting(drive, "pipeline_max", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->max_pipeline, NULL); 3467 ide_add_setting(drive, "pipeline", SETTING_RW, TYPE_INT, 1, 0xffff,
3642 ide_add_setting(drive, "pipeline_used", SETTING_READ, TYPE_INT, 0, 0xffff, tape->stage_size / 1024, 1, &tape->nr_stages, NULL); 3468 tape->stage_size / 1024, 1, &tape->max_stages, NULL);
3643 ide_add_setting(drive, "pipeline_pending", SETTING_READ, TYPE_INT, 0, 0xffff, tape->stage_size / 1024, 1, &tape->nr_pending_stages, NULL); 3469 ide_add_setting(drive, "pipeline_max", SETTING_RW, TYPE_INT, 1, 0xffff,
3470 tape->stage_size / 1024, 1, &tape->max_pipeline, NULL);
3471 ide_add_setting(drive, "pipeline_used", SETTING_READ, TYPE_INT, 0,
3472 0xffff, tape->stage_size / 1024, 1, &tape->nr_stages,
3473 NULL);
3474 ide_add_setting(drive, "pipeline_pending", SETTING_READ, TYPE_INT, 0,
3475 0xffff, tape->stage_size / 1024, 1,
3476 &tape->nr_pending_stages, NULL);
3644 ide_add_setting(drive, "speed", SETTING_READ, TYPE_SHORT, 0, 0xffff, 3477 ide_add_setting(drive, "speed", SETTING_READ, TYPE_SHORT, 0, 0xffff,
3645 1, 1, (u16 *)&tape->caps[14], NULL); 3478 1, 1, (u16 *)&tape->caps[14], NULL);
3646 ide_add_setting(drive, "stage", SETTING_READ, TYPE_INT, 0, 0xffff, 1, 1024, &tape->stage_size, NULL); 3479 ide_add_setting(drive, "stage", SETTING_READ, TYPE_INT, 0, 0xffff, 1,
3647 ide_add_setting(drive, "tdsc", SETTING_RW, TYPE_INT, IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX, 1000, HZ, &tape->best_dsc_rw_frequency, NULL); 3480 1024, &tape->stage_size, NULL);
3648 ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->dsc_overlap, NULL); 3481 ide_add_setting(drive, "tdsc", SETTING_RW, TYPE_INT, IDETAPE_DSC_RW_MIN,
3649 ide_add_setting(drive, "pipeline_head_speed_c",SETTING_READ, TYPE_INT, 0, 0xffff, 1, 1, &tape->controlled_pipeline_head_speed, NULL); 3482 IDETAPE_DSC_RW_MAX, 1000, HZ, &tape->best_dsc_rw_freq,
3650 ide_add_setting(drive, "pipeline_head_speed_u",SETTING_READ, TYPE_INT, 0, 0xffff, 1, 1, &tape->uncontrolled_pipeline_head_speed,NULL); 3483 NULL);
3651 ide_add_setting(drive, "avg_speed", SETTING_READ, TYPE_INT, 0, 0xffff, 1, 1, &tape->avg_speed, NULL); 3484 ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1,
3652 ide_add_setting(drive, "debug_level", SETTING_RW, TYPE_INT, 0, 0xffff, 1, 1, &tape->debug_level, NULL); 3485 1, &drive->dsc_overlap, NULL);
3486 ide_add_setting(drive, "pipeline_head_speed_c", SETTING_READ, TYPE_INT,
3487 0, 0xffff, 1, 1, &tape->controlled_pipeline_head_speed,
3488 NULL);
3489 ide_add_setting(drive, "pipeline_head_speed_u", SETTING_READ, TYPE_INT,
3490 0, 0xffff, 1, 1,
3491 &tape->uncontrolled_pipeline_head_speed, NULL);
3492 ide_add_setting(drive, "avg_speed", SETTING_READ, TYPE_INT, 0, 0xffff,
3493 1, 1, &tape->avg_speed, NULL);
3494 ide_add_setting(drive, "debug_mask", SETTING_RW, TYPE_INT, 0, 0xffff, 1,
3495 1, &tape->debug_mask, NULL);
3653} 3496}
3654#else 3497#else
3655static inline void idetape_add_settings(ide_drive_t *drive) { ; } 3498static inline void idetape_add_settings(ide_drive_t *drive) { ; }
3656#endif 3499#endif
3657 3500
3658/* 3501/*
3659 * ide_setup is called to: 3502 * The function below is called to:
3660 * 3503 *
3661 * 1. Initialize our various state variables. 3504 * 1. Initialize our various state variables.
3662 * 2. Ask the tape for its capabilities. 3505 * 2. Ask the tape for its capabilities.
3663 * 3. Allocate a buffer which will be used for data 3506 * 3. Allocate a buffer which will be used for data transfer. The buffer size
3664 * transfer. The buffer size is chosen based on 3507 * is chosen based on the recommendation which we received in step 2.
3665 * the recommendation which we received in step (2).
3666 * 3508 *
3667 * Note that at this point ide.c already assigned us an irq, so that 3509 * Note that at this point ide.c already assigned us an irq, so that we can
3668 * we can queue requests here and wait for their completion. 3510 * queue requests here and wait for their completion.
3669 */ 3511 */
3670static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor) 3512static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
3671{ 3513{
3672 unsigned long t1, tmid, tn, t; 3514 unsigned long t1, tmid, tn, t;
3673 int speed; 3515 int speed;
3674 struct idetape_id_gcw gcw;
3675 int stage_size; 3516 int stage_size;
3517 u8 gcw[2];
3676 struct sysinfo si; 3518 struct sysinfo si;
3677 u16 *ctl = (u16 *)&tape->caps[12]; 3519 u16 *ctl = (u16 *)&tape->caps[12];
3678 3520
3679 spin_lock_init(&tape->spinlock); 3521 spin_lock_init(&tape->lock);
3680 drive->dsc_overlap = 1; 3522 drive->dsc_overlap = 1;
3681 if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) { 3523 if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) {
3682 printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n", 3524 printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n",
@@ -3690,25 +3532,29 @@ static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor)
3690 tape->name[0] = 'h'; 3532 tape->name[0] = 'h';
3691 tape->name[1] = 't'; 3533 tape->name[1] = 't';
3692 tape->name[2] = '0' + minor; 3534 tape->name[2] = '0' + minor;
3693 tape->chrdev_direction = idetape_direction_none; 3535 tape->chrdev_dir = IDETAPE_DIR_NONE;
3694 tape->pc = tape->pc_stack; 3536 tape->pc = tape->pc_stack;
3695 tape->max_insert_speed = 10000; 3537 tape->max_insert_speed = 10000;
3696 tape->speed_control = 1; 3538 tape->speed_control = 1;
3697 *((unsigned short *) &gcw) = drive->id->config; 3539 *((unsigned short *) &gcw) = drive->id->config;
3698 if (gcw.drq_type == 1) 3540
3541 /* Command packet DRQ type */
3542 if (((gcw[0] & 0x60) >> 5) == 1)
3699 set_bit(IDETAPE_DRQ_INTERRUPT, &tape->flags); 3543 set_bit(IDETAPE_DRQ_INTERRUPT, &tape->flags);
3700 3544
3701 tape->min_pipeline = tape->max_pipeline = tape->max_stages = 10; 3545 tape->min_pipeline = 10;
3702 3546 tape->max_pipeline = 10;
3547 tape->max_stages = 10;
3548
3703 idetape_get_inquiry_results(drive); 3549 idetape_get_inquiry_results(drive);
3704 idetape_get_mode_sense_results(drive); 3550 idetape_get_mode_sense_results(drive);
3705 ide_tape_get_bsize_from_bdesc(drive); 3551 ide_tape_get_bsize_from_bdesc(drive);
3706 tape->user_bs_factor = 1; 3552 tape->user_bs_factor = 1;
3707 tape->stage_size = *ctl * tape->tape_block_size; 3553 tape->stage_size = *ctl * tape->blk_size;
3708 while (tape->stage_size > 0xffff) { 3554 while (tape->stage_size > 0xffff) {
3709 printk(KERN_NOTICE "ide-tape: decreasing stage size\n"); 3555 printk(KERN_NOTICE "ide-tape: decreasing stage size\n");
3710 *ctl /= 2; 3556 *ctl /= 2;
3711 tape->stage_size = *ctl * tape->tape_block_size; 3557 tape->stage_size = *ctl * tape->blk_size;
3712 } 3558 }
3713 stage_size = tape->stage_size; 3559 stage_size = tape->stage_size;
3714 tape->pages_per_stage = stage_size / PAGE_SIZE; 3560 tape->pages_per_stage = stage_size / PAGE_SIZE;
@@ -3722,17 +3568,22 @@ static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor)
3722 3568
3723 tape->max_stages = speed * 1000 * 10 / tape->stage_size; 3569 tape->max_stages = speed * 1000 * 10 / tape->stage_size;
3724 3570
3725 /* 3571 /* Limit memory use for pipeline to 10% of physical memory */
3726 * Limit memory use for pipeline to 10% of physical memory
3727 */
3728 si_meminfo(&si); 3572 si_meminfo(&si);
3729 if (tape->max_stages * tape->stage_size > si.totalram * si.mem_unit / 10) 3573 if (tape->max_stages * tape->stage_size >
3730 tape->max_stages = si.totalram * si.mem_unit / (10 * tape->stage_size); 3574 si.totalram * si.mem_unit / 10)
3575 tape->max_stages =
3576 si.totalram * si.mem_unit / (10 * tape->stage_size);
3577
3731 tape->max_stages = min(tape->max_stages, IDETAPE_MAX_PIPELINE_STAGES); 3578 tape->max_stages = min(tape->max_stages, IDETAPE_MAX_PIPELINE_STAGES);
3732 tape->min_pipeline = min(tape->max_stages, IDETAPE_MIN_PIPELINE_STAGES); 3579 tape->min_pipeline = min(tape->max_stages, IDETAPE_MIN_PIPELINE_STAGES);
3733 tape->max_pipeline = min(tape->max_stages * 2, IDETAPE_MAX_PIPELINE_STAGES); 3580 tape->max_pipeline =
3734 if (tape->max_stages == 0) 3581 min(tape->max_stages * 2, IDETAPE_MAX_PIPELINE_STAGES);
3735 tape->max_stages = tape->min_pipeline = tape->max_pipeline = 1; 3582 if (tape->max_stages == 0) {
3583 tape->max_stages = 1;
3584 tape->min_pipeline = 1;
3585 tape->max_pipeline = 1;
3586 }
3736 3587
3737 t1 = (tape->stage_size * HZ) / (speed * 1000); 3588 t1 = (tape->stage_size * HZ) / (speed * 1000);
3738 tmid = (*(u16 *)&tape->caps[16] * 32 * HZ) / (speed * 125); 3589 tmid = (*(u16 *)&tape->caps[16] * 32 * HZ) / (speed * 125);
@@ -3744,17 +3595,19 @@ static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor)
3744 t = t1; 3595 t = t1;
3745 3596
3746 /* 3597 /*
3747 * Ensure that the number we got makes sense; limit 3598 * Ensure that the number we got makes sense; limit it within
3748 * it within IDETAPE_DSC_RW_MIN and IDETAPE_DSC_RW_MAX. 3599 * IDETAPE_DSC_RW_MIN and IDETAPE_DSC_RW_MAX.
3749 */ 3600 */
3750 tape->best_dsc_rw_frequency = max_t(unsigned long, min_t(unsigned long, t, IDETAPE_DSC_RW_MAX), IDETAPE_DSC_RW_MIN); 3601 tape->best_dsc_rw_freq = max_t(unsigned long,
3602 min_t(unsigned long, t, IDETAPE_DSC_RW_MAX),
3603 IDETAPE_DSC_RW_MIN);
3751 printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, " 3604 printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, "
3752 "%dkB pipeline, %lums tDSC%s\n", 3605 "%dkB pipeline, %lums tDSC%s\n",
3753 drive->name, tape->name, *(u16 *)&tape->caps[14], 3606 drive->name, tape->name, *(u16 *)&tape->caps[14],
3754 (*(u16 *)&tape->caps[16] * 512) / tape->stage_size, 3607 (*(u16 *)&tape->caps[16] * 512) / tape->stage_size,
3755 tape->stage_size / 1024, 3608 tape->stage_size / 1024,
3756 tape->max_stages * tape->stage_size / 1024, 3609 tape->max_stages * tape->stage_size / 1024,
3757 tape->best_dsc_rw_frequency * 1000 / HZ, 3610 tape->best_dsc_rw_freq * 1000 / HZ,
3758 drive->using_dma ? ", DMA":""); 3611 drive->using_dma ? ", DMA":"");
3759 3612
3760 idetape_add_settings(drive); 3613 idetape_add_settings(drive);
@@ -3782,7 +3635,8 @@ static void ide_tape_release(struct kref *kref)
3782 drive->dsc_overlap = 0; 3635 drive->dsc_overlap = 0;
3783 drive->driver_data = NULL; 3636 drive->driver_data = NULL;
3784 device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor)); 3637 device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor));
3785 device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor + 128)); 3638 device_destroy(idetape_sysfs_class,
3639 MKDEV(IDETAPE_MAJOR, tape->minor + 128));
3786 idetape_devs[tape->minor] = NULL; 3640 idetape_devs[tape->minor] = NULL;
3787 g->private_data = NULL; 3641 g->private_data = NULL;
3788 put_disk(g); 3642 put_disk(g);
@@ -3831,9 +3685,7 @@ static ide_driver_t idetape_driver = {
3831#endif 3685#endif
3832}; 3686};
3833 3687
3834/* 3688/* Our character device supporting functions, passed to register_chrdev. */
3835 * Our character device supporting functions, passed to register_chrdev.
3836 */
3837static const struct file_operations idetape_fops = { 3689static const struct file_operations idetape_fops = {
3838 .owner = THIS_MODULE, 3690 .owner = THIS_MODULE,
3839 .read = idetape_chrdev_read, 3691 .read = idetape_chrdev_read,
@@ -3848,7 +3700,8 @@ static int idetape_open(struct inode *inode, struct file *filp)
3848 struct gendisk *disk = inode->i_bdev->bd_disk; 3700 struct gendisk *disk = inode->i_bdev->bd_disk;
3849 struct ide_tape_obj *tape; 3701 struct ide_tape_obj *tape;
3850 3702
3851 if (!(tape = ide_tape_get(disk))) 3703 tape = ide_tape_get(disk);
3704 if (!tape)
3852 return -ENXIO; 3705 return -ENXIO;
3853 3706
3854 return 0; 3707 return 0;
@@ -3895,21 +3748,20 @@ static int ide_tape_probe(ide_drive_t *drive)
3895 goto failed; 3748 goto failed;
3896 if (drive->media != ide_tape) 3749 if (drive->media != ide_tape)
3897 goto failed; 3750 goto failed;
3898 if (!idetape_identify_device (drive)) { 3751 if (!idetape_identify_device(drive)) {
3899 printk(KERN_ERR "ide-tape: %s: not supported by this version of ide-tape\n", drive->name); 3752 printk(KERN_ERR "ide-tape: %s: not supported by this version of"
3753 " the driver\n", drive->name);
3900 goto failed; 3754 goto failed;
3901 } 3755 }
3902 if (drive->scsi) { 3756 if (drive->scsi) {
3903 printk("ide-tape: passing drive %s to ide-scsi emulation.\n", drive->name); 3757 printk(KERN_INFO "ide-tape: passing drive %s to ide-scsi"
3758 " emulation.\n", drive->name);
3904 goto failed; 3759 goto failed;
3905 } 3760 }
3906 if (strstr(drive->id->model, "OnStream DI-")) { 3761 tape = kzalloc(sizeof(idetape_tape_t), GFP_KERNEL);
3907 printk(KERN_WARNING "ide-tape: Use drive %s with ide-scsi emulation and osst.\n", drive->name);
3908 printk(KERN_WARNING "ide-tape: OnStream support will be removed soon from ide-tape!\n");
3909 }
3910 tape = kzalloc(sizeof (idetape_tape_t), GFP_KERNEL);
3911 if (tape == NULL) { 3762 if (tape == NULL) {
3912 printk(KERN_ERR "ide-tape: %s: Can't allocate a tape structure\n", drive->name); 3763 printk(KERN_ERR "ide-tape: %s: Can't allocate a tape struct\n",
3764 drive->name);
3913 goto failed; 3765 goto failed;
3914 } 3766 }
3915 3767
@@ -3955,10 +3807,7 @@ failed:
3955 return -ENODEV; 3807 return -ENODEV;
3956} 3808}
3957 3809
3958MODULE_DESCRIPTION("ATAPI Streaming TAPE Driver"); 3810static void __exit idetape_exit(void)
3959MODULE_LICENSE("GPL");
3960
3961static void __exit idetape_exit (void)
3962{ 3811{
3963 driver_unregister(&idetape_driver.gen_driver); 3812 driver_unregister(&idetape_driver.gen_driver);
3964 class_destroy(idetape_sysfs_class); 3813 class_destroy(idetape_sysfs_class);
@@ -3977,7 +3826,8 @@ static int __init idetape_init(void)
3977 } 3826 }
3978 3827
3979 if (register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) { 3828 if (register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) {
3980 printk(KERN_ERR "ide-tape: Failed to register character device interface\n"); 3829 printk(KERN_ERR "ide-tape: Failed to register chrdev"
3830 " interface\n");
3981 error = -EBUSY; 3831 error = -EBUSY;
3982 goto out_free_class; 3832 goto out_free_class;
3983 } 3833 }
@@ -4000,3 +3850,5 @@ MODULE_ALIAS("ide:*m-tape*");
4000module_init(idetape_init); 3850module_init(idetape_init);
4001module_exit(idetape_exit); 3851module_exit(idetape_exit);
4002MODULE_ALIAS_CHARDEV_MAJOR(IDETAPE_MAJOR); 3852MODULE_ALIAS_CHARDEV_MAJOR(IDETAPE_MAJOR);
3853MODULE_DESCRIPTION("ATAPI Streaming TAPE Driver");
3854MODULE_LICENSE("GPL");
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 4e1da1c78cb5..0518a2e948cf 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -189,12 +189,11 @@ EXPORT_SYMBOL_GPL(do_rw_taskfile);
189 */ 189 */
190static ide_startstop_t set_multmode_intr(ide_drive_t *drive) 190static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
191{ 191{
192 ide_hwif_t *hwif = HWIF(drive); 192 u8 stat = ide_read_status(drive);
193 u8 stat;
194 193
195 if (OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) { 194 if (OK_STAT(stat, READY_STAT, BAD_STAT))
196 drive->mult_count = drive->mult_req; 195 drive->mult_count = drive->mult_req;
197 } else { 196 else {
198 drive->mult_req = drive->mult_count = 0; 197 drive->mult_req = drive->mult_count = 0;
199 drive->special.b.recalibrate = 1; 198 drive->special.b.recalibrate = 1;
200 (void) ide_dump_status(drive, "set_multmode", stat); 199 (void) ide_dump_status(drive, "set_multmode", stat);
@@ -207,11 +206,10 @@ static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
207 */ 206 */
208static ide_startstop_t set_geometry_intr(ide_drive_t *drive) 207static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
209{ 208{
210 ide_hwif_t *hwif = HWIF(drive);
211 int retries = 5; 209 int retries = 5;
212 u8 stat; 210 u8 stat;
213 211
214 while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--) 212 while (((stat = ide_read_status(drive)) & BUSY_STAT) && retries--)
215 udelay(10); 213 udelay(10);
216 214
217 if (OK_STAT(stat, READY_STAT, BAD_STAT)) 215 if (OK_STAT(stat, READY_STAT, BAD_STAT))
@@ -230,10 +228,9 @@ static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
230 */ 228 */
231static ide_startstop_t recal_intr(ide_drive_t *drive) 229static ide_startstop_t recal_intr(ide_drive_t *drive)
232{ 230{
233 ide_hwif_t *hwif = HWIF(drive); 231 u8 stat = ide_read_status(drive);
234 u8 stat;
235 232
236 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT)) 233 if (!OK_STAT(stat, READY_STAT, BAD_STAT))
237 return ide_error(drive, "recal_intr", stat); 234 return ide_error(drive, "recal_intr", stat);
238 return ide_stopped; 235 return ide_stopped;
239} 236}
@@ -244,23 +241,23 @@ static ide_startstop_t recal_intr(ide_drive_t *drive)
244static ide_startstop_t task_no_data_intr(ide_drive_t *drive) 241static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
245{ 242{
246 ide_task_t *args = HWGROUP(drive)->rq->special; 243 ide_task_t *args = HWGROUP(drive)->rq->special;
247 ide_hwif_t *hwif = HWIF(drive);
248 u8 stat; 244 u8 stat;
249 245
250 local_irq_enable_in_hardirq(); 246 local_irq_enable_in_hardirq();
251 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) { 247 stat = ide_read_status(drive);
248
249 if (!OK_STAT(stat, READY_STAT, BAD_STAT))
252 return ide_error(drive, "task_no_data_intr", stat); 250 return ide_error(drive, "task_no_data_intr", stat);
253 /* calls ide_end_drive_cmd */ 251 /* calls ide_end_drive_cmd */
254 } 252
255 if (args) 253 if (args)
256 ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG)); 254 ide_end_drive_cmd(drive, stat, ide_read_error(drive));
257 255
258 return ide_stopped; 256 return ide_stopped;
259} 257}
260 258
261static u8 wait_drive_not_busy(ide_drive_t *drive) 259static u8 wait_drive_not_busy(ide_drive_t *drive)
262{ 260{
263 ide_hwif_t *hwif = HWIF(drive);
264 int retries; 261 int retries;
265 u8 stat; 262 u8 stat;
266 263
@@ -269,7 +266,9 @@ static u8 wait_drive_not_busy(ide_drive_t *drive)
269 * This can take up to 10 usec, but we will wait max 1 ms. 266 * This can take up to 10 usec, but we will wait max 1 ms.
270 */ 267 */
271 for (retries = 0; retries < 100; retries++) { 268 for (retries = 0; retries < 100; retries++) {
272 if ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) 269 stat = ide_read_status(drive);
270
271 if (stat & BUSY_STAT)
273 udelay(10); 272 udelay(10);
274 else 273 else
275 break; 274 break;
@@ -408,7 +407,7 @@ static ide_startstop_t task_error(ide_drive_t *drive, struct request *rq,
408void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat) 407void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat)
409{ 408{
410 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) { 409 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
411 u8 err = drive->hwif->INB(IDE_ERROR_REG); 410 u8 err = ide_read_error(drive);
412 411
413 ide_end_drive_cmd(drive, stat, err); 412 ide_end_drive_cmd(drive, stat, err);
414 return; 413 return;
@@ -430,7 +429,7 @@ static ide_startstop_t task_in_intr(ide_drive_t *drive)
430{ 429{
431 ide_hwif_t *hwif = drive->hwif; 430 ide_hwif_t *hwif = drive->hwif;
432 struct request *rq = HWGROUP(drive)->rq; 431 struct request *rq = HWGROUP(drive)->rq;
433 u8 stat = hwif->INB(IDE_STATUS_REG); 432 u8 stat = ide_read_status(drive);
434 433
435 /* new way for dealing with premature shared PCI interrupts */ 434 /* new way for dealing with premature shared PCI interrupts */
436 if (!OK_STAT(stat, DRQ_STAT, BAD_R_STAT)) { 435 if (!OK_STAT(stat, DRQ_STAT, BAD_R_STAT)) {
@@ -465,7 +464,7 @@ static ide_startstop_t task_out_intr (ide_drive_t *drive)
465{ 464{
466 ide_hwif_t *hwif = drive->hwif; 465 ide_hwif_t *hwif = drive->hwif;
467 struct request *rq = HWGROUP(drive)->rq; 466 struct request *rq = HWGROUP(drive)->rq;
468 u8 stat = hwif->INB(IDE_STATUS_REG); 467 u8 stat = ide_read_status(drive);
469 468
470 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat)) 469 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat))
471 return task_error(drive, rq, __FUNCTION__, stat); 470 return task_error(drive, rq, __FUNCTION__, stat);
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index ac6136001615..ad0e9955f73c 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -618,60 +618,6 @@ abort:
618 618
619EXPORT_SYMBOL(ide_unregister); 619EXPORT_SYMBOL(ide_unregister);
620 620
621
622/**
623 * ide_setup_ports - set up IDE interface ports
624 * @hw: register descriptions
625 * @base: base register
626 * @offsets: table of register offsets
627 * @ctrl: control register
628 * @ack_irq: IRQ ack
629 * @irq: interrupt lie
630 *
631 * Setup hw_regs_t structure described by parameters. You
632 * may set up the hw structure yourself OR use this routine to
633 * do it for you. This is basically a helper
634 *
635 */
636
637void ide_setup_ports ( hw_regs_t *hw,
638 unsigned long base, int *offsets,
639 unsigned long ctrl, unsigned long intr,
640 ide_ack_intr_t *ack_intr,
641/*
642 * ide_io_ops_t *iops,
643 */
644 int irq)
645{
646 int i;
647
648 memset(hw, 0, sizeof(hw_regs_t));
649 for (i = 0; i < IDE_NR_PORTS; i++) {
650 if (offsets[i] == -1) {
651 switch(i) {
652 case IDE_CONTROL_OFFSET:
653 hw->io_ports[i] = ctrl;
654 break;
655#if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
656 case IDE_IRQ_OFFSET:
657 hw->io_ports[i] = intr;
658 break;
659#endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
660 default:
661 hw->io_ports[i] = 0;
662 break;
663 }
664 } else {
665 hw->io_ports[i] = base + offsets[i];
666 }
667 }
668 hw->irq = irq;
669 hw->ack_intr = ack_intr;
670/*
671 * hw->iops = iops;
672 */
673}
674
675void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw) 621void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
676{ 622{
677 memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports)); 623 memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports));
diff --git a/drivers/ide/legacy/buddha.c b/drivers/ide/legacy/buddha.c
index 8bdb79da17e8..50ffa871d5e9 100644
--- a/drivers/ide/legacy/buddha.c
+++ b/drivers/ide/legacy/buddha.c
@@ -56,31 +56,11 @@ static u_int xsurf_bases[XSURF_NUM_HWIFS] __initdata = {
56 XSURF_BASE1, XSURF_BASE2 56 XSURF_BASE1, XSURF_BASE2
57}; 57};
58 58
59
60 /* 59 /*
61 * Offsets from one of the above bases 60 * Offsets from one of the above bases
62 */ 61 */
63 62
64#define BUDDHA_DATA 0x00
65#define BUDDHA_ERROR 0x06 /* see err-bits */
66#define BUDDHA_NSECTOR 0x0a /* nr of sectors to read/write */
67#define BUDDHA_SECTOR 0x0e /* starting sector */
68#define BUDDHA_LCYL 0x12 /* starting cylinder */
69#define BUDDHA_HCYL 0x16 /* high byte of starting cyl */
70#define BUDDHA_SELECT 0x1a /* 101dhhhh , d=drive, hhhh=head */
71#define BUDDHA_STATUS 0x1e /* see status-bits */
72#define BUDDHA_CONTROL 0x11a 63#define BUDDHA_CONTROL 0x11a
73#define XSURF_CONTROL -1 /* X-Surf has no CS1* (Control/AltStat) */
74
75static int buddha_offsets[IDE_NR_PORTS] __initdata = {
76 BUDDHA_DATA, BUDDHA_ERROR, BUDDHA_NSECTOR, BUDDHA_SECTOR, BUDDHA_LCYL,
77 BUDDHA_HCYL, BUDDHA_SELECT, BUDDHA_STATUS, BUDDHA_CONTROL, -1
78};
79
80static int xsurf_offsets[IDE_NR_PORTS] __initdata = {
81 BUDDHA_DATA, BUDDHA_ERROR, BUDDHA_NSECTOR, BUDDHA_SECTOR, BUDDHA_LCYL,
82 BUDDHA_HCYL, BUDDHA_SELECT, BUDDHA_STATUS, XSURF_CONTROL, -1
83};
84 64
85 /* 65 /*
86 * Other registers 66 * Other registers
@@ -140,6 +120,26 @@ static int xsurf_ack_intr(ide_hwif_t *hwif)
140 return 1; 120 return 1;
141} 121}
142 122
123static void __init buddha_setup_ports(hw_regs_t *hw, unsigned long base,
124 unsigned long ctl, unsigned long irq_port,
125 ide_ack_intr_t *ack_intr)
126{
127 int i;
128
129 memset(hw, 0, sizeof(*hw));
130
131 hw->io_ports[IDE_DATA_OFFSET] = base;
132
133 for (i = 1; i < 8; i++)
134 hw->io_ports[i] = base + 2 + i * 4;
135
136 hw->io_ports[IDE_CONTROL_OFFSET] = ctl;
137 hw->io_ports[IDE_IRQ_OFFSET] = irq_port;
138
139 hw->irq = IRQ_AMIGA_PORTS;
140 hw->ack_intr = ack_intr;
141}
142
143 /* 143 /*
144 * Probe for a Buddha or Catweasel IDE interface 144 * Probe for a Buddha or Catweasel IDE interface
145 */ 145 */
@@ -202,22 +202,24 @@ fail_base2:
202 printk(KERN_INFO "ide: %s IDE controller\n", 202 printk(KERN_INFO "ide: %s IDE controller\n",
203 buddha_board_name[type]); 203 buddha_board_name[type]);
204 204
205 for(i=0;i<buddha_num_hwifs;i++) { 205 for (i = 0; i < buddha_num_hwifs; i++) {
206 if(type != BOARD_XSURF) { 206 unsigned long base, ctl, irq_port;
207 ide_setup_ports(&hw, (buddha_board+buddha_bases[i]), 207 ide_ack_intr_t *ack_intr;
208 buddha_offsets, 0, 208
209 (buddha_board+buddha_irqports[i]), 209 if (type != BOARD_XSURF) {
210 buddha_ack_intr, 210 base = buddha_board + buddha_bases[i];
211// budda_iops, 211 ctl = base + BUDDHA_CONTROL;
212 IRQ_AMIGA_PORTS); 212 irq_port = buddha_board + buddha_irqports[i];
213 ack_intr = buddha_ack_intr;
213 } else { 214 } else {
214 ide_setup_ports(&hw, (buddha_board+xsurf_bases[i]), 215 base = buddha_board + xsurf_bases[i];
215 xsurf_offsets, 0, 216 /* X-Surf has no CS1* (Control/AltStat) */
216 (buddha_board+xsurf_irqports[i]), 217 ctl = 0;
217 xsurf_ack_intr, 218 irq_port = buddha_board + xsurf_irqports[i];
218// xsurf_iops, 219 ack_intr = xsurf_ack_intr;
219 IRQ_AMIGA_PORTS); 220 }
220 } 221
222 buddha_setup_ports(&hw, base, ctl, irq_port, ack_intr);
221 223
222 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); 224 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]);
223 if (hwif) { 225 if (hwif) {
diff --git a/drivers/ide/legacy/falconide.c b/drivers/ide/legacy/falconide.c
index 85b69a82825f..f044048903b3 100644
--- a/drivers/ide/legacy/falconide.c
+++ b/drivers/ide/legacy/falconide.c
@@ -33,22 +33,8 @@
33 * Offsets from the above base 33 * Offsets from the above base
34 */ 34 */
35 35
36#define ATA_HD_DATA 0x00
37#define ATA_HD_ERROR 0x05 /* see err-bits */
38#define ATA_HD_NSECTOR 0x09 /* nr of sectors to read/write */
39#define ATA_HD_SECTOR 0x0d /* starting sector */
40#define ATA_HD_LCYL 0x11 /* starting cylinder */
41#define ATA_HD_HCYL 0x15 /* high byte of starting cyl */
42#define ATA_HD_SELECT 0x19 /* 101dhhhh , d=drive, hhhh=head */
43#define ATA_HD_STATUS 0x1d /* see status-bits */
44#define ATA_HD_CONTROL 0x39 36#define ATA_HD_CONTROL 0x39
45 37
46static int falconide_offsets[IDE_NR_PORTS] __initdata = {
47 ATA_HD_DATA, ATA_HD_ERROR, ATA_HD_NSECTOR, ATA_HD_SECTOR, ATA_HD_LCYL,
48 ATA_HD_HCYL, ATA_HD_SELECT, ATA_HD_STATUS, ATA_HD_CONTROL, -1
49};
50
51
52 /* 38 /*
53 * falconide_intr_lock is used to obtain access to the IDE interrupt, 39 * falconide_intr_lock is used to obtain access to the IDE interrupt,
54 * which is shared between several drivers. 40 * which is shared between several drivers.
@@ -57,6 +43,22 @@ static int falconide_offsets[IDE_NR_PORTS] __initdata = {
57int falconide_intr_lock; 43int falconide_intr_lock;
58EXPORT_SYMBOL(falconide_intr_lock); 44EXPORT_SYMBOL(falconide_intr_lock);
59 45
46static void __init falconide_setup_ports(hw_regs_t *hw)
47{
48 int i;
49
50 memset(hw, 0, sizeof(*hw));
51
52 hw->io_ports[IDE_DATA_OFFSET] = ATA_HD_BASE;
53
54 for (i = 1; i < 8; i++)
55 hw->io_ports[i] = ATA_HD_BASE + 1 + i * 4;
56
57 hw->io_ports[IDE_CONTROL_OFFSET] = ATA_HD_CONTROL;
58
59 hw->irq = IRQ_MFP_IDE;
60 hw->ack_intr = NULL;
61}
60 62
61 /* 63 /*
62 * Probe for a Falcon IDE interface 64 * Probe for a Falcon IDE interface
@@ -64,16 +66,15 @@ EXPORT_SYMBOL(falconide_intr_lock);
64 66
65static int __init falconide_init(void) 67static int __init falconide_init(void)
66{ 68{
67 if (MACH_IS_ATARI && ATARIHW_PRESENT(IDE)) {
68 hw_regs_t hw; 69 hw_regs_t hw;
69 ide_hwif_t *hwif; 70 ide_hwif_t *hwif;
70 71
72 if (!MACH_IS_ATARI || !ATARIHW_PRESENT(IDE))
73 return 0;
74
71 printk(KERN_INFO "ide: Falcon IDE controller\n"); 75 printk(KERN_INFO "ide: Falcon IDE controller\n");
72 76
73 ide_setup_ports(&hw, ATA_HD_BASE, falconide_offsets, 77 falconide_setup_ports(&hw);
74 0, 0, NULL,
75// falconide_iops,
76 IRQ_MFP_IDE);
77 78
78 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); 79 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]);
79 if (hwif) { 80 if (hwif) {
@@ -85,9 +86,8 @@ static int __init falconide_init(void)
85 86
86 ide_device_add(idx, NULL); 87 ide_device_add(idx, NULL);
87 } 88 }
88 }
89 89
90 return 0; 90 return 0;
91} 91}
92 92
93module_init(falconide_init); 93module_init(falconide_init);
diff --git a/drivers/ide/legacy/gayle.c b/drivers/ide/legacy/gayle.c
index fc29ce75aff1..9d3851d27677 100644
--- a/drivers/ide/legacy/gayle.c
+++ b/drivers/ide/legacy/gayle.c
@@ -34,22 +34,8 @@
34 * Offsets from one of the above bases 34 * Offsets from one of the above bases
35 */ 35 */
36 36
37#define GAYLE_DATA 0x00
38#define GAYLE_ERROR 0x06 /* see err-bits */
39#define GAYLE_NSECTOR 0x0a /* nr of sectors to read/write */
40#define GAYLE_SECTOR 0x0e /* starting sector */
41#define GAYLE_LCYL 0x12 /* starting cylinder */
42#define GAYLE_HCYL 0x16 /* high byte of starting cyl */
43#define GAYLE_SELECT 0x1a /* 101dhhhh , d=drive, hhhh=head */
44#define GAYLE_STATUS 0x1e /* see status-bits */
45#define GAYLE_CONTROL 0x101a 37#define GAYLE_CONTROL 0x101a
46 38
47static int gayle_offsets[IDE_NR_PORTS] __initdata = {
48 GAYLE_DATA, GAYLE_ERROR, GAYLE_NSECTOR, GAYLE_SECTOR, GAYLE_LCYL,
49 GAYLE_HCYL, GAYLE_SELECT, GAYLE_STATUS, -1, -1
50};
51
52
53 /* 39 /*
54 * These are at different offsets from the base 40 * These are at different offsets from the base
55 */ 41 */
@@ -106,6 +92,26 @@ static int gayle_ack_intr_a1200(ide_hwif_t *hwif)
106 return 1; 92 return 1;
107} 93}
108 94
95static void __init gayle_setup_ports(hw_regs_t *hw, unsigned long base,
96 unsigned long ctl, unsigned long irq_port,
97 ide_ack_intr_t *ack_intr);
98{
99 int i;
100
101 memset(hw, 0, sizeof(*hw));
102
103 hw->io_ports[IDE_DATA_OFFSET] = base;
104
105 for (i = 1; i < 8; i++)
106 hw->io_ports[i] = base + 2 + i * 4;
107
108 hw->io_ports[IDE_CONTROL_OFFSET] = ctl;
109 hw->io_ports[IDE_IRQ_OFFSET] = irq_port;
110
111 hw->irq = IRQ_AMIGA_PORTS;
112 hw->ack_intr = ack_intr;
113}
114
109 /* 115 /*
110 * Probe for a Gayle IDE interface (and optionally for an IDE doubler) 116 * Probe for a Gayle IDE interface (and optionally for an IDE doubler)
111 */ 117 */
@@ -167,10 +173,7 @@ found:
167 base = (unsigned long)ZTWO_VADDR(phys_base); 173 base = (unsigned long)ZTWO_VADDR(phys_base);
168 ctrlport = GAYLE_HAS_CONTROL_REG ? (base + GAYLE_CONTROL) : 0; 174 ctrlport = GAYLE_HAS_CONTROL_REG ? (base + GAYLE_CONTROL) : 0;
169 175
170 ide_setup_ports(&hw, base, gayle_offsets, 176 gayle_setup_ports(&hw, base, ctrlport, irqport, ack_intr);
171 ctrlport, irqport, ack_intr,
172// &gayle_iops,
173 IRQ_AMIGA_PORTS);
174 177
175 hwif = ide_find_port(base); 178 hwif = ide_find_port(base);
176 if (hwif) { 179 if (hwif) {
diff --git a/drivers/ide/legacy/hd.c b/drivers/ide/legacy/hd.c
index 8e05d88e81ba..0b0d86731927 100644
--- a/drivers/ide/legacy/hd.c
+++ b/drivers/ide/legacy/hd.c
@@ -421,11 +421,14 @@ static void bad_rw_intr(void)
421 421
422static inline int wait_DRQ(void) 422static inline int wait_DRQ(void)
423{ 423{
424 int retries = 100000, stat; 424 int retries;
425 int stat;
425 426
426 while (--retries > 0) 427 for (retries = 0; retries < 100000; retries++) {
427 if ((stat = inb_p(HD_STATUS)) & DRQ_STAT) 428 stat = inb_p(HD_STATUS);
429 if (stat & DRQ_STAT)
428 return 0; 430 return 0;
431 }
429 dump_status("wait_DRQ", stat); 432 dump_status("wait_DRQ", stat);
430 return -1; 433 return -1;
431} 434}
diff --git a/drivers/ide/legacy/macide.c b/drivers/ide/legacy/macide.c
index 06df8df857a3..a61e60737dc7 100644
--- a/drivers/ide/legacy/macide.c
+++ b/drivers/ide/legacy/macide.c
@@ -31,14 +31,6 @@
31 * These match MkLinux so they should be correct. 31 * These match MkLinux so they should be correct.
32 */ 32 */
33 33
34#define IDE_DATA 0x00
35#define IDE_ERROR 0x04 /* see err-bits */
36#define IDE_NSECTOR 0x08 /* nr of sectors to read/write */
37#define IDE_SECTOR 0x0c /* starting sector */
38#define IDE_LCYL 0x10 /* starting cylinder */
39#define IDE_HCYL 0x14 /* high byte of starting cyl */
40#define IDE_SELECT 0x18 /* 101dhhhh , d=drive, hhhh=head */
41#define IDE_STATUS 0x1c /* see status-bits */
42#define IDE_CONTROL 0x38 /* control/altstatus */ 34#define IDE_CONTROL 0x38 /* control/altstatus */
43 35
44/* 36/*
@@ -63,11 +55,6 @@
63 55
64volatile unsigned char *ide_ifr = (unsigned char *) (IDE_BASE + IDE_IFR); 56volatile unsigned char *ide_ifr = (unsigned char *) (IDE_BASE + IDE_IFR);
65 57
66static int macide_offsets[IDE_NR_PORTS] = {
67 IDE_DATA, IDE_ERROR, IDE_NSECTOR, IDE_SECTOR, IDE_LCYL,
68 IDE_HCYL, IDE_SELECT, IDE_STATUS, IDE_CONTROL
69};
70
71int macide_ack_intr(ide_hwif_t* hwif) 58int macide_ack_intr(ide_hwif_t* hwif)
72{ 59{
73 if (*ide_ifr & 0x20) { 60 if (*ide_ifr & 0x20) {
@@ -77,6 +64,22 @@ int macide_ack_intr(ide_hwif_t* hwif)
77 return 0; 64 return 0;
78} 65}
79 66
67static void __init macide_setup_ports(hw_regs_t *hw, unsigned long base,
68 int irq, ide_ack_intr_t *ack_intr)
69{
70 int i;
71
72 memset(hw, 0, sizeof(*hw));
73
74 for (i = 0; i < 8; i++)
75 hw->io_ports[i] = base + i * 4;
76
77 hw->io_ports[IDE_CONTROL_OFFSET] = IDE_CONTROL;
78
79 hw->irq = irq;
80 hw->ack_intr = ack_intr;
81}
82
80static const char *mac_ide_name[] = 83static const char *mac_ide_name[] =
81 { "Quadra", "Powerbook", "Powerbook Baboon" }; 84 { "Quadra", "Powerbook", "Powerbook Baboon" };
82 85
@@ -86,27 +89,27 @@ static const char *mac_ide_name[] =
86 89
87static int __init macide_init(void) 90static int __init macide_init(void)
88{ 91{
89 hw_regs_t hw;
90 ide_hwif_t *hwif; 92 ide_hwif_t *hwif;
93 ide_ack_intr_t *ack_intr;
94 unsigned long base;
95 int irq;
96 hw_regs_t hw;
91 97
92 switch (macintosh_config->ide_type) { 98 switch (macintosh_config->ide_type) {
93 case MAC_IDE_QUADRA: 99 case MAC_IDE_QUADRA:
94 ide_setup_ports(&hw, IDE_BASE, macide_offsets, 100 base = IDE_BASE;
95 0, 0, macide_ack_intr, 101 ack_intr = macide_ack_intr;
96// quadra_ide_iops, 102 irq = IRQ_NUBUS_F;
97 IRQ_NUBUS_F);
98 break; 103 break;
99 case MAC_IDE_PB: 104 case MAC_IDE_PB:
100 ide_setup_ports(&hw, IDE_BASE, macide_offsets, 105 base = IDE_BASE;
101 0, 0, macide_ack_intr, 106 ack_intr = macide_ack_intr;
102// macide_pb_iops, 107 irq = IRQ_NUBUS_C;
103 IRQ_NUBUS_C);
104 break; 108 break;
105 case MAC_IDE_BABOON: 109 case MAC_IDE_BABOON:
106 ide_setup_ports(&hw, BABOON_BASE, macide_offsets, 110 base = BABOON_BASE;
107 0, 0, NULL, 111 ack_intr = NULL;
108// macide_baboon_iops, 112 irq = IRQ_BABOON_1;
109 IRQ_BABOON_1);
110 break; 113 break;
111 default: 114 default:
112 return -ENODEV; 115 return -ENODEV;
@@ -115,6 +118,8 @@ static int __init macide_init(void)
115 printk(KERN_INFO "ide: Macintosh %s IDE controller\n", 118 printk(KERN_INFO "ide: Macintosh %s IDE controller\n",
116 mac_ide_name[macintosh_config->ide_type - 1]); 119 mac_ide_name[macintosh_config->ide_type - 1]);
117 120
121 macide_setup_ports(&hw, base, irq, ack_intr);
122
118 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]); 123 hwif = ide_find_port(hw.io_ports[IDE_DATA_OFFSET]);
119 if (hwif) { 124 if (hwif) {
120 u8 index = hwif->index; 125 u8 index = hwif->index;
diff --git a/drivers/ide/legacy/q40ide.c b/drivers/ide/legacy/q40ide.c
index 2f0b34d892a1..1381b91bc316 100644
--- a/drivers/ide/legacy/q40ide.c
+++ b/drivers/ide/legacy/q40ide.c
@@ -66,16 +66,12 @@ static int q40ide_default_irq(unsigned long base)
66 66
67 67
68/* 68/*
69 * This is very similar to ide_setup_ports except that addresses 69 * Addresses are pretranslated for Q40 ISA access.
70 * are pretranslated for q40 ISA access
71 */ 70 */
72void q40_ide_setup_ports ( hw_regs_t *hw, 71void q40_ide_setup_ports ( hw_regs_t *hw,
73 unsigned long base, int *offsets, 72 unsigned long base, int *offsets,
74 unsigned long ctrl, unsigned long intr, 73 unsigned long ctrl, unsigned long intr,
75 ide_ack_intr_t *ack_intr, 74 ide_ack_intr_t *ack_intr,
76/*
77 * ide_io_ops_t *iops,
78 */
79 int irq) 75 int irq)
80{ 76{
81 int i; 77 int i;
@@ -92,9 +88,6 @@ void q40_ide_setup_ports ( hw_regs_t *hw,
92 88
93 hw->irq = irq; 89 hw->irq = irq;
94 hw->ack_intr = ack_intr; 90 hw->ack_intr = ack_intr;
95/*
96 * hw->iops = iops;
97 */
98} 91}
99 92
100 93
diff --git a/drivers/ide/pci/Makefile b/drivers/ide/pci/Makefile
index 94803253e8af..02e6ee7d751d 100644
--- a/drivers/ide/pci/Makefile
+++ b/drivers/ide/pci/Makefile
@@ -34,7 +34,8 @@ obj-$(CONFIG_BLK_DEV_TRM290) += trm290.o
34obj-$(CONFIG_BLK_DEV_VIA82CXXX) += via82cxxx.o 34obj-$(CONFIG_BLK_DEV_VIA82CXXX) += via82cxxx.o
35 35
36# Must appear at the end of the block 36# Must appear at the end of the block
37obj-$(CONFIG_BLK_DEV_GENERIC) += generic.o 37obj-$(CONFIG_BLK_DEV_GENERIC) += ide-pci-generic.o
38ide-pci-generic-y += generic.o
38 39
39ifeq ($(CONFIG_BLK_DEV_CMD640), m) 40ifeq ($(CONFIG_BLK_DEV_CMD640), m)
40 obj-m += cmd640.o 41 obj-m += cmd640.o
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c
index 9262a9174b4e..7fd83a9d4dee 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/pci/generic.c
@@ -29,19 +29,6 @@
29 29
30static int ide_generic_all; /* Set to claim all devices */ 30static int ide_generic_all; /* Set to claim all devices */
31 31
32/*
33 * the module_param_named() was added for the modular case
34 * the __setup() is left as compatibility for existing setups
35 */
36#ifndef MODULE
37static int __init ide_generic_all_on(char *unused)
38{
39 ide_generic_all = 1;
40 printk(KERN_INFO "IDE generic will claim all unknown PCI IDE storage controllers.\n");
41 return 1;
42}
43const __setup("all-generic-ide", ide_generic_all_on);
44#endif
45module_param_named(all_generic_ide, ide_generic_all, bool, 0444); 32module_param_named(all_generic_ide, ide_generic_all, bool, 0444);
46MODULE_PARM_DESC(all_generic_ide, "IDE generic will claim all unknown PCI IDE storage controllers."); 33MODULE_PARM_DESC(all_generic_ide, "IDE generic will claim all unknown PCI IDE storage controllers.");
47 34
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index ef5b39fa042b..cc4be9621bc0 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -704,9 +704,6 @@ static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif)
704 hwif->sata_scr[SATA_STATUS_OFFSET] = base + 0x104; 704 hwif->sata_scr[SATA_STATUS_OFFSET] = base + 0x104;
705 hwif->sata_scr[SATA_ERROR_OFFSET] = base + 0x108; 705 hwif->sata_scr[SATA_ERROR_OFFSET] = base + 0x108;
706 hwif->sata_scr[SATA_CONTROL_OFFSET] = base + 0x100; 706 hwif->sata_scr[SATA_CONTROL_OFFSET] = base + 0x100;
707 hwif->sata_misc[SATA_MISC_OFFSET] = base + 0x140;
708 hwif->sata_misc[SATA_PHY_OFFSET] = base + 0x144;
709 hwif->sata_misc[SATA_IEN_OFFSET] = base + 0x148;
710 } 707 }
711 708
712 memcpy(hwif->io_ports, hw.io_ports, sizeof(hwif->io_ports)); 709 memcpy(hwif->io_ports, hw.io_ports, sizeof(hwif->io_ports));
diff --git a/drivers/macintosh/mediabay.c b/drivers/macintosh/mediabay.c
index de9ebbfbf122..936788272a5f 100644
--- a/drivers/macintosh/mediabay.c
+++ b/drivers/macintosh/mediabay.c
@@ -78,12 +78,14 @@ struct media_bay_info {
78 int cached_gpio; 78 int cached_gpio;
79 int sleeping; 79 int sleeping;
80 struct semaphore lock; 80 struct semaphore lock;
81#ifdef CONFIG_BLK_DEV_IDE 81#ifdef CONFIG_BLK_DEV_IDE_PMAC
82 void __iomem *cd_base; 82 void __iomem *cd_base;
83 int cd_index;
84 int cd_irq; 83 int cd_irq;
85 int cd_retry; 84 int cd_retry;
86#endif 85#endif
86#if defined(CONFIG_BLK_DEV_IDE_PMAC) || defined(CONFIG_MAC_FLOPPY)
87 int cd_index;
88#endif
87}; 89};
88 90
89#define MAX_BAYS 2 91#define MAX_BAYS 2
@@ -91,7 +93,7 @@ struct media_bay_info {
91static struct media_bay_info media_bays[MAX_BAYS]; 93static struct media_bay_info media_bays[MAX_BAYS];
92int media_bay_count = 0; 94int media_bay_count = 0;
93 95
94#ifdef CONFIG_BLK_DEV_IDE 96#ifdef CONFIG_BLK_DEV_IDE_PMAC
95/* check the busy bit in the media-bay ide interface 97/* check the busy bit in the media-bay ide interface
96 (assumes the media-bay contains an ide device) */ 98 (assumes the media-bay contains an ide device) */
97#define MB_IDE_READY(i) ((readb(media_bays[i].cd_base + 0x70) & 0x80) == 0) 99#define MB_IDE_READY(i) ((readb(media_bays[i].cd_base + 0x70) & 0x80) == 0)
@@ -401,7 +403,7 @@ static void poll_media_bay(struct media_bay_info* bay)
401 set_mb_power(bay, id != MB_NO); 403 set_mb_power(bay, id != MB_NO);
402 bay->content_id = id; 404 bay->content_id = id;
403 if (id == MB_NO) { 405 if (id == MB_NO) {
404#ifdef CONFIG_BLK_DEV_IDE 406#ifdef CONFIG_BLK_DEV_IDE_PMAC
405 bay->cd_retry = 0; 407 bay->cd_retry = 0;
406#endif 408#endif
407 printk(KERN_INFO "media bay %d is empty\n", bay->index); 409 printk(KERN_INFO "media bay %d is empty\n", bay->index);
@@ -414,9 +416,9 @@ static void poll_media_bay(struct media_bay_info* bay)
414 } 416 }
415} 417}
416 418
419#ifdef CONFIG_MAC_FLOPPY
417int check_media_bay(struct device_node *which_bay, int what) 420int check_media_bay(struct device_node *which_bay, int what)
418{ 421{
419#ifdef CONFIG_BLK_DEV_IDE
420 int i; 422 int i;
421 423
422 for (i=0; i<media_bay_count; i++) 424 for (i=0; i<media_bay_count; i++)
@@ -426,14 +428,14 @@ int check_media_bay(struct device_node *which_bay, int what)
426 media_bays[i].cd_index = -1; 428 media_bays[i].cd_index = -1;
427 return -EINVAL; 429 return -EINVAL;
428 } 430 }
429#endif /* CONFIG_BLK_DEV_IDE */
430 return -ENODEV; 431 return -ENODEV;
431} 432}
432EXPORT_SYMBOL(check_media_bay); 433EXPORT_SYMBOL(check_media_bay);
434#endif /* CONFIG_MAC_FLOPPY */
433 435
436#ifdef CONFIG_BLK_DEV_IDE_PMAC
434int check_media_bay_by_base(unsigned long base, int what) 437int check_media_bay_by_base(unsigned long base, int what)
435{ 438{
436#ifdef CONFIG_BLK_DEV_IDE
437 int i; 439 int i;
438 440
439 for (i=0; i<media_bay_count; i++) 441 for (i=0; i<media_bay_count; i++)
@@ -443,15 +445,13 @@ int check_media_bay_by_base(unsigned long base, int what)
443 media_bays[i].cd_index = -1; 445 media_bays[i].cd_index = -1;
444 return -EINVAL; 446 return -EINVAL;
445 } 447 }
446#endif 448
447
448 return -ENODEV; 449 return -ENODEV;
449} 450}
450 451
451int media_bay_set_ide_infos(struct device_node* which_bay, unsigned long base, 452int media_bay_set_ide_infos(struct device_node* which_bay, unsigned long base,
452 int irq, int index) 453 int irq, int index)
453{ 454{
454#ifdef CONFIG_BLK_DEV_IDE
455 int i; 455 int i;
456 456
457 for (i=0; i<media_bay_count; i++) { 457 for (i=0; i<media_bay_count; i++) {
@@ -483,10 +483,10 @@ int media_bay_set_ide_infos(struct device_node* which_bay, unsigned long base,
483 return -ENODEV; 483 return -ENODEV;
484 } 484 }
485 } 485 }
486#endif /* CONFIG_BLK_DEV_IDE */ 486
487
488 return -ENODEV; 487 return -ENODEV;
489} 488}
489#endif /* CONFIG_BLK_DEV_IDE_PMAC */
490 490
491static void media_bay_step(int i) 491static void media_bay_step(int i)
492{ 492{
@@ -521,14 +521,13 @@ static void media_bay_step(int i)
521 bay->state = mb_resetting; 521 bay->state = mb_resetting;
522 MBDBG("mediabay%d: waiting reset (kind:%d)\n", i, bay->content_id); 522 MBDBG("mediabay%d: waiting reset (kind:%d)\n", i, bay->content_id);
523 break; 523 break;
524
525 case mb_resetting: 524 case mb_resetting:
526 if (bay->content_id != MB_CD) { 525 if (bay->content_id != MB_CD) {
527 MBDBG("mediabay%d: bay is up (kind:%d)\n", i, bay->content_id); 526 MBDBG("mediabay%d: bay is up (kind:%d)\n", i, bay->content_id);
528 bay->state = mb_up; 527 bay->state = mb_up;
529 break; 528 break;
530 } 529 }
531#ifdef CONFIG_BLK_DEV_IDE 530#ifdef CONFIG_BLK_DEV_IDE_PMAC
532 MBDBG("mediabay%d: waiting IDE reset (kind:%d)\n", i, bay->content_id); 531 MBDBG("mediabay%d: waiting IDE reset (kind:%d)\n", i, bay->content_id);
533 bay->ops->un_reset_ide(bay); 532 bay->ops->un_reset_ide(bay);
534 bay->timer = msecs_to_jiffies(MB_IDE_WAIT); 533 bay->timer = msecs_to_jiffies(MB_IDE_WAIT);
@@ -536,16 +535,14 @@ static void media_bay_step(int i)
536#else 535#else
537 printk(KERN_DEBUG "media-bay %d is ide (not compiled in kernel)\n", i); 536 printk(KERN_DEBUG "media-bay %d is ide (not compiled in kernel)\n", i);
538 set_mb_power(bay, 0); 537 set_mb_power(bay, 0);
539#endif /* CONFIG_BLK_DEV_IDE */ 538#endif /* CONFIG_BLK_DEV_IDE_PMAC */
540 break; 539 break;
541 540#ifdef CONFIG_BLK_DEV_IDE_PMAC
542#ifdef CONFIG_BLK_DEV_IDE
543 case mb_ide_resetting: 541 case mb_ide_resetting:
544 bay->timer = msecs_to_jiffies(MB_IDE_TIMEOUT); 542 bay->timer = msecs_to_jiffies(MB_IDE_TIMEOUT);
545 bay->state = mb_ide_waiting; 543 bay->state = mb_ide_waiting;
546 MBDBG("mediabay%d: waiting IDE ready (kind:%d)\n", i, bay->content_id); 544 MBDBG("mediabay%d: waiting IDE ready (kind:%d)\n", i, bay->content_id);
547 break; 545 break;
548
549 case mb_ide_waiting: 546 case mb_ide_waiting:
550 if (bay->cd_base == NULL) { 547 if (bay->cd_base == NULL) {
551 bay->timer = 0; 548 bay->timer = 0;
@@ -587,11 +584,10 @@ static void media_bay_step(int i)
587 bay->timer = 0; 584 bay->timer = 0;
588 } 585 }
589 break; 586 break;
590#endif /* CONFIG_BLK_DEV_IDE */ 587#endif /* CONFIG_BLK_DEV_IDE_PMAC */
591
592 case mb_powering_down: 588 case mb_powering_down:
593 bay->state = mb_empty; 589 bay->state = mb_empty;
594#ifdef CONFIG_BLK_DEV_IDE 590#ifdef CONFIG_BLK_DEV_IDE_PMAC
595 if (bay->cd_index >= 0) { 591 if (bay->cd_index >= 0) {
596 printk(KERN_DEBUG "Unregistering mb %d ide, index:%d\n", i, 592 printk(KERN_DEBUG "Unregistering mb %d ide, index:%d\n", i,
597 bay->cd_index); 593 bay->cd_index);
@@ -607,7 +603,7 @@ static void media_bay_step(int i)
607 bay->content_id = MB_NO; 603 bay->content_id = MB_NO;
608 } 604 }
609 } 605 }
610#endif /* CONFIG_BLK_DEV_IDE */ 606#endif /* CONFIG_BLK_DEV_IDE_PMAC */
611 MBDBG("mediabay%d: end of power down\n", i); 607 MBDBG("mediabay%d: end of power down\n", i);
612 break; 608 break;
613 } 609 }
@@ -739,7 +735,7 @@ static int media_bay_resume(struct macio_dev *mdev)
739 bay->last_value = bay->content_id; 735 bay->last_value = bay->content_id;
740 bay->value_count = msecs_to_jiffies(MB_STABLE_DELAY); 736 bay->value_count = msecs_to_jiffies(MB_STABLE_DELAY);
741 bay->timer = msecs_to_jiffies(MB_POWER_DELAY); 737 bay->timer = msecs_to_jiffies(MB_POWER_DELAY);
742#ifdef CONFIG_BLK_DEV_IDE 738#ifdef CONFIG_BLK_DEV_IDE_PMAC
743 bay->cd_retry = 0; 739 bay->cd_retry = 0;
744#endif 740#endif
745 do { 741 do {
@@ -829,7 +825,7 @@ static int __init media_bay_init(void)
829 for (i=0; i<MAX_BAYS; i++) { 825 for (i=0; i<MAX_BAYS; i++) {
830 memset((char *)&media_bays[i], 0, sizeof(struct media_bay_info)); 826 memset((char *)&media_bays[i], 0, sizeof(struct media_bay_info));
831 media_bays[i].content_id = -1; 827 media_bays[i].content_id = -1;
832#ifdef CONFIG_BLK_DEV_IDE 828#ifdef CONFIG_BLK_DEV_IDE_PMAC
833 media_bays[i].cd_index = -1; 829 media_bays[i].cd_index = -1;
834#endif 830#endif
835 } 831 }
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index 6c4f0f081785..68e5c632c5d5 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -287,7 +287,7 @@ static int idescsi_end_request(ide_drive_t *, int, int);
287static ide_startstop_t 287static ide_startstop_t
288idescsi_atapi_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err) 288idescsi_atapi_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
289{ 289{
290 if (HWIF(drive)->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT)) 290 if (ide_read_status(drive) & (BUSY_STAT | DRQ_STAT))
291 /* force an abort */ 291 /* force an abort */
292 HWIF(drive)->OUTB(WIN_IDLEIMMEDIATE,IDE_COMMAND_REG); 292 HWIF(drive)->OUTB(WIN_IDLEIMMEDIATE,IDE_COMMAND_REG);
293 293
@@ -423,7 +423,7 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
423 } 423 }
424 424
425 /* Clear the interrupt */ 425 /* Clear the interrupt */
426 stat = drive->hwif->INB(IDE_STATUS_REG); 426 stat = ide_read_status(drive);
427 427
428 if ((stat & DRQ_STAT) == 0) { 428 if ((stat & DRQ_STAT) == 0) {
429 /* No more interrupts */ 429 /* No more interrupts */
diff --git a/include/asm-powerpc/mediabay.h b/include/asm-powerpc/mediabay.h
index 9daa3252d7b6..de83fe196309 100644
--- a/include/asm-powerpc/mediabay.h
+++ b/include/asm-powerpc/mediabay.h
@@ -18,14 +18,14 @@
18#define MB_NO 7 /* media bay contains nothing */ 18#define MB_NO 7 /* media bay contains nothing */
19 19
20int check_media_bay(struct device_node *which_bay, int what); 20int check_media_bay(struct device_node *which_bay, int what);
21int check_media_bay_by_base(unsigned long base, int what);
22 21
23/* Number of bays in the machine or 0 */ 22/* Number of bays in the machine or 0 */
24extern int media_bay_count; 23extern int media_bay_count;
25 24
26/* called by pmac-ide.c to register IDE controller for media bay */ 25int check_media_bay_by_base(unsigned long base, int what);
27extern int media_bay_set_ide_infos(struct device_node* which_bay, 26/* called by IDE PMAC host driver to register IDE controller for media bay */
28 unsigned long base, int irq, int index); 27int media_bay_set_ide_infos(struct device_node *which_bay, unsigned long base,
28 int irq, int index);
29 29
30#endif /* __KERNEL__ */ 30#endif /* __KERNEL__ */
31#endif /* _PPC_MEDIABAY_H */ 31#endif /* _PPC_MEDIABAY_H */
diff --git a/include/linux/ide.h b/include/linux/ide.h
index 367c17084a28..acec99da832d 100644
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -115,10 +115,6 @@ typedef unsigned char byte; /* used everywhere */
115#define SATA_ERROR_OFFSET (1) 115#define SATA_ERROR_OFFSET (1)
116#define SATA_CONTROL_OFFSET (2) 116#define SATA_CONTROL_OFFSET (2)
117 117
118#define SATA_MISC_OFFSET (0)
119#define SATA_PHY_OFFSET (1)
120#define SATA_IEN_OFFSET (2)
121
122/* 118/*
123 * Our Physical Region Descriptor (PRD) table should be large enough 119 * Our Physical Region Descriptor (PRD) table should be large enough
124 * to handle the biggest I/O request we are likely to see. Since requests 120 * to handle the biggest I/O request we are likely to see. Since requests
@@ -173,7 +169,7 @@ enum { ide_unknown, ide_generic, ide_pci,
173 ide_rz1000, ide_trm290, 169 ide_rz1000, ide_trm290,
174 ide_cmd646, ide_cy82c693, ide_4drives, 170 ide_cmd646, ide_cy82c693, ide_4drives,
175 ide_pmac, ide_etrax100, ide_acorn, 171 ide_pmac, ide_etrax100, ide_acorn,
176 ide_au1xxx, ide_forced 172 ide_au1xxx, ide_palm3710, ide_forced
177}; 173};
178 174
179typedef u8 hwif_chipset_t; 175typedef u8 hwif_chipset_t;
@@ -198,17 +194,6 @@ struct ide_drive_s;
198int ide_register_hw(hw_regs_t *, void (*)(struct ide_drive_s *), 194int ide_register_hw(hw_regs_t *, void (*)(struct ide_drive_s *),
199 struct hwif_s **); 195 struct hwif_s **);
200 196
201void ide_setup_ports( hw_regs_t *hw,
202 unsigned long base,
203 int *offsets,
204 unsigned long ctrl,
205 unsigned long intr,
206 ide_ack_intr_t *ack_intr,
207#if 0
208 ide_io_ops_t *iops,
209#endif
210 int irq);
211
212static inline void ide_std_init_ports(hw_regs_t *hw, 197static inline void ide_std_init_ports(hw_regs_t *hw,
213 unsigned long io_addr, 198 unsigned long io_addr,
214 unsigned long ctl_addr) 199 unsigned long ctl_addr)
@@ -473,7 +458,6 @@ typedef struct hwif_s {
473 /* task file registers for pata and sata */ 458 /* task file registers for pata and sata */
474 unsigned long io_ports[IDE_NR_PORTS]; 459 unsigned long io_ports[IDE_NR_PORTS];
475 unsigned long sata_scr[SATA_NR_PORTS]; 460 unsigned long sata_scr[SATA_NR_PORTS];
476 unsigned long sata_misc[SATA_NR_PORTS];
477 461
478 ide_drive_t drives[MAX_DRIVES]; /* drive info */ 462 ide_drive_t drives[MAX_DRIVES]; /* drive info */
479 463
@@ -1014,7 +998,8 @@ extern int __ide_pci_register_driver(struct pci_driver *driver, struct module *o
1014void ide_pci_setup_ports(struct pci_dev *, const struct ide_port_info *, int, u8 *); 998void ide_pci_setup_ports(struct pci_dev *, const struct ide_port_info *, int, u8 *);
1015void ide_setup_pci_noise(struct pci_dev *, const struct ide_port_info *); 999void ide_setup_pci_noise(struct pci_dev *, const struct ide_port_info *);
1016 1000
1017#ifdef CONFIG_BLK_DEV_IDEDMA_PCI 1001/* FIXME: palm_bk3710 uses BLK_DEV_IDEDMA_PCI without BLK_DEV_IDEPCI! */
1002#if defined(CONFIG_BLK_DEV_IDEPCI) && defined(CONFIG_BLK_DEV_IDEDMA_PCI)
1018void ide_hwif_setup_dma(ide_hwif_t *, const struct ide_port_info *); 1003void ide_hwif_setup_dma(ide_hwif_t *, const struct ide_port_info *);
1019#else 1004#else
1020static inline void ide_hwif_setup_dma(ide_hwif_t *hwif, 1005static inline void ide_hwif_setup_dma(ide_hwif_t *hwif,
@@ -1324,4 +1309,25 @@ static inline void ide_set_irq(ide_drive_t *drive, int on)
1324 drive->hwif->OUTB(drive->ctl | (on ? 0 : 2), IDE_CONTROL_REG); 1309 drive->hwif->OUTB(drive->ctl | (on ? 0 : 2), IDE_CONTROL_REG);
1325} 1310}
1326 1311
1312static inline u8 ide_read_status(ide_drive_t *drive)
1313{
1314 ide_hwif_t *hwif = drive->hwif;
1315
1316 return hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]);
1317}
1318
1319static inline u8 ide_read_altstatus(ide_drive_t *drive)
1320{
1321 ide_hwif_t *hwif = drive->hwif;
1322
1323 return hwif->INB(hwif->io_ports[IDE_CONTROL_OFFSET]);
1324}
1325
1326static inline u8 ide_read_error(ide_drive_t *drive)
1327{
1328 ide_hwif_t *hwif = drive->hwif;
1329
1330 return hwif->INB(hwif->io_ports[IDE_ERROR_OFFSET]);
1331}
1332
1327#endif /* _IDE_H */ 1333#endif /* _IDE_H */