aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ide/at91_ide.c2
-rw-r--r--drivers/ide/ide-cd.c32
-rw-r--r--drivers/ide/ide-disk_proc.c129
-rw-r--r--drivers/ide/ide-floppy_proc.c30
-rw-r--r--drivers/ide/ide-ioctls.c8
-rw-r--r--drivers/ide/ide-iops.c17
-rw-r--r--drivers/ide/ide-probe.c31
-rw-r--r--drivers/ide/ide-proc.c340
-rw-r--r--drivers/ide/ide-tape.c160
-rw-r--r--drivers/ide/ide-taskfile.c126
-rw-r--r--drivers/ide/palm_bk3710.c2
11 files changed, 515 insertions, 362 deletions
diff --git a/drivers/ide/at91_ide.c b/drivers/ide/at91_ide.c
index dbfeda42b940..248219a89a68 100644
--- a/drivers/ide/at91_ide.c
+++ b/drivers/ide/at91_ide.c
@@ -29,9 +29,7 @@
29 29
30#include <mach/board.h> 30#include <mach/board.h>
31#include <mach/gpio.h> 31#include <mach/gpio.h>
32#include <mach/at91sam9263.h>
33#include <mach/at91sam9_smc.h> 32#include <mach/at91sam9_smc.h>
34#include <mach/at91sam9263_matrix.h>
35 33
36#define DRV_NAME "at91_ide" 34#define DRV_NAME "at91_ide"
37 35
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 6a9a769bffc1..b79ca419d8d9 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -30,6 +30,7 @@
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/timer.h> 32#include <linux/timer.h>
33#include <linux/seq_file.h>
33#include <linux/slab.h> 34#include <linux/slab.h>
34#include <linux/interrupt.h> 35#include <linux/interrupt.h>
35#include <linux/errno.h> 36#include <linux/errno.h>
@@ -1146,8 +1147,8 @@ void ide_cdrom_update_speed(ide_drive_t *drive, u8 *buf)
1146 ide_debug_log(IDE_DBG_PROBE, "curspeed: %u, maxspeed: %u", 1147 ide_debug_log(IDE_DBG_PROBE, "curspeed: %u, maxspeed: %u",
1147 curspeed, maxspeed); 1148 curspeed, maxspeed);
1148 1149
1149 cd->current_speed = (curspeed + (176/2)) / 176; 1150 cd->current_speed = DIV_ROUND_CLOSEST(curspeed, 176);
1150 cd->max_speed = (maxspeed + (176/2)) / 176; 1151 cd->max_speed = DIV_ROUND_CLOSEST(maxspeed, 176);
1151} 1152}
1152 1153
1153#define IDE_CD_CAPABILITIES \ 1154#define IDE_CD_CAPABILITIES \
@@ -1389,19 +1390,30 @@ static sector_t ide_cdrom_capacity(ide_drive_t *drive)
1389 return capacity * sectors_per_frame; 1390 return capacity * sectors_per_frame;
1390} 1391}
1391 1392
1392static int proc_idecd_read_capacity(char *page, char **start, off_t off, 1393static int idecd_capacity_proc_show(struct seq_file *m, void *v)
1393 int count, int *eof, void *data)
1394{ 1394{
1395 ide_drive_t *drive = data; 1395 ide_drive_t *drive = m->private;
1396 int len;
1397 1396
1398 len = sprintf(page, "%llu\n", (long long)ide_cdrom_capacity(drive)); 1397 seq_printf(m, "%llu\n", (long long)ide_cdrom_capacity(drive));
1399 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 1398 return 0;
1399}
1400
1401static int idecd_capacity_proc_open(struct inode *inode, struct file *file)
1402{
1403 return single_open(file, idecd_capacity_proc_show, PDE(inode)->data);
1400} 1404}
1401 1405
1406static const struct file_operations idecd_capacity_proc_fops = {
1407 .owner = THIS_MODULE,
1408 .open = idecd_capacity_proc_open,
1409 .read = seq_read,
1410 .llseek = seq_lseek,
1411 .release = single_release,
1412};
1413
1402static ide_proc_entry_t idecd_proc[] = { 1414static ide_proc_entry_t idecd_proc[] = {
1403 { "capacity", S_IFREG|S_IRUGO, proc_idecd_read_capacity, NULL }, 1415 { "capacity", S_IFREG|S_IRUGO, &idecd_capacity_proc_fops },
1404 { NULL, 0, NULL, NULL } 1416 {}
1405}; 1417};
1406 1418
1407static ide_proc_entry_t *ide_cd_proc_entries(ide_drive_t *drive) 1419static ide_proc_entry_t *ide_cd_proc_entries(ide_drive_t *drive)
diff --git a/drivers/ide/ide-disk_proc.c b/drivers/ide/ide-disk_proc.c
index 19f263bf0a9e..60b0590ccc9c 100644
--- a/drivers/ide/ide-disk_proc.c
+++ b/drivers/ide/ide-disk_proc.c
@@ -1,5 +1,6 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/ide.h> 2#include <linux/ide.h>
3#include <linux/seq_file.h>
3 4
4#include "ide-disk.h" 5#include "ide-disk.h"
5 6
@@ -37,77 +38,117 @@ static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
37 return ide_raw_taskfile(drive, &cmd, buf, 1); 38 return ide_raw_taskfile(drive, &cmd, buf, 1);
38} 39}
39 40
40static int proc_idedisk_read_cache 41static int idedisk_cache_proc_show(struct seq_file *m, void *v)
41 (char *page, char **start, off_t off, int count, int *eof, void *data)
42{ 42{
43 ide_drive_t *drive = (ide_drive_t *) data; 43 ide_drive_t *drive = (ide_drive_t *) m->private;
44 char *out = page;
45 int len;
46 44
47 if (drive->dev_flags & IDE_DFLAG_ID_READ) 45 if (drive->dev_flags & IDE_DFLAG_ID_READ)
48 len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2); 46 seq_printf(m, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
49 else 47 else
50 len = sprintf(out, "(none)\n"); 48 seq_printf(m, "(none)\n");
49 return 0;
50}
51 51
52 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 52static int idedisk_cache_proc_open(struct inode *inode, struct file *file)
53{
54 return single_open(file, idedisk_cache_proc_show, PDE(inode)->data);
53} 55}
54 56
55static int proc_idedisk_read_capacity 57static const struct file_operations idedisk_cache_proc_fops = {
56 (char *page, char **start, off_t off, int count, int *eof, void *data) 58 .owner = THIS_MODULE,
59 .open = idedisk_cache_proc_open,
60 .read = seq_read,
61 .llseek = seq_lseek,
62 .release = single_release,
63};
64
65static int idedisk_capacity_proc_show(struct seq_file *m, void *v)
57{ 66{
58 ide_drive_t*drive = (ide_drive_t *)data; 67 ide_drive_t*drive = (ide_drive_t *)m->private;
59 int len;
60 68
61 len = sprintf(page, "%llu\n", (long long)ide_gd_capacity(drive)); 69 seq_printf(m, "%llu\n", (long long)ide_gd_capacity(drive));
70 return 0;
71}
62 72
63 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 73static int idedisk_capacity_proc_open(struct inode *inode, struct file *file)
74{
75 return single_open(file, idedisk_capacity_proc_show, PDE(inode)->data);
64} 76}
65 77
66static int proc_idedisk_read_smart(char *page, char **start, off_t off, 78static const struct file_operations idedisk_capacity_proc_fops = {
67 int count, int *eof, void *data, u8 sub_cmd) 79 .owner = THIS_MODULE,
80 .open = idedisk_capacity_proc_open,
81 .read = seq_read,
82 .llseek = seq_lseek,
83 .release = single_release,
84};
85
86static int __idedisk_proc_show(struct seq_file *m, ide_drive_t *drive, u8 sub_cmd)
68{ 87{
69 ide_drive_t *drive = (ide_drive_t *)data; 88 u8 *buf;
70 int len = 0, i = 0; 89
90 buf = kmalloc(SECTOR_SIZE, GFP_KERNEL);
91 if (!buf)
92 return -ENOMEM;
71 93
72 (void)smart_enable(drive); 94 (void)smart_enable(drive);
73 95
74 if (get_smart_data(drive, page, sub_cmd) == 0) { 96 if (get_smart_data(drive, buf, sub_cmd) == 0) {
75 unsigned short *val = (unsigned short *) page; 97 __le16 *val = (__le16 *)buf;
76 char *out = (char *)val + SECTOR_SIZE; 98 int i;
77 99
78 page = out; 100 for (i = 0; i < SECTOR_SIZE / 2; i++) {
79 do { 101 seq_printf(m, "%04x%c", le16_to_cpu(val[i]),
80 out += sprintf(out, "%04x%c", le16_to_cpu(*val), 102 (i % 8) == 7 ? '\n' : ' ');
81 (++i & 7) ? ' ' : '\n'); 103 }
82 val += 1;
83 } while (i < SECTOR_SIZE / 2);
84 len = out - page;
85 } 104 }
105 kfree(buf);
106 return 0;
107}
86 108
87 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 109static int idedisk_sv_proc_show(struct seq_file *m, void *v)
110{
111 return __idedisk_proc_show(m, m->private, ATA_SMART_READ_VALUES);
88} 112}
89 113
90static int proc_idedisk_read_sv 114static int idedisk_sv_proc_open(struct inode *inode, struct file *file)
91 (char *page, char **start, off_t off, int count, int *eof, void *data)
92{ 115{
93 return proc_idedisk_read_smart(page, start, off, count, eof, data, 116 return single_open(file, idedisk_sv_proc_show, PDE(inode)->data);
94 ATA_SMART_READ_VALUES);
95} 117}
96 118
97static int proc_idedisk_read_st 119static const struct file_operations idedisk_sv_proc_fops = {
98 (char *page, char **start, off_t off, int count, int *eof, void *data) 120 .owner = THIS_MODULE,
121 .open = idedisk_sv_proc_open,
122 .read = seq_read,
123 .llseek = seq_lseek,
124 .release = single_release,
125};
126
127static int idedisk_st_proc_show(struct seq_file *m, void *v)
99{ 128{
100 return proc_idedisk_read_smart(page, start, off, count, eof, data, 129 return __idedisk_proc_show(m, m->private, ATA_SMART_READ_THRESHOLDS);
101 ATA_SMART_READ_THRESHOLDS);
102} 130}
103 131
132static int idedisk_st_proc_open(struct inode *inode, struct file *file)
133{
134 return single_open(file, idedisk_st_proc_show, PDE(inode)->data);
135}
136
137static const struct file_operations idedisk_st_proc_fops = {
138 .owner = THIS_MODULE,
139 .open = idedisk_st_proc_open,
140 .read = seq_read,
141 .llseek = seq_lseek,
142 .release = single_release,
143};
144
104ide_proc_entry_t ide_disk_proc[] = { 145ide_proc_entry_t ide_disk_proc[] = {
105 { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL }, 146 { "cache", S_IFREG|S_IRUGO, &idedisk_cache_proc_fops },
106 { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL }, 147 { "capacity", S_IFREG|S_IRUGO, &idedisk_capacity_proc_fops },
107 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, 148 { "geometry", S_IFREG|S_IRUGO, &ide_geometry_proc_fops },
108 { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv, NULL }, 149 { "smart_values", S_IFREG|S_IRUSR, &idedisk_sv_proc_fops },
109 { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st, NULL }, 150 { "smart_thresholds", S_IFREG|S_IRUSR, &idedisk_st_proc_fops },
110 { NULL, 0, NULL, NULL } 151 {}
111}; 152};
112 153
113ide_devset_rw_field(bios_cyl, bios_cyl); 154ide_devset_rw_field(bios_cyl, bios_cyl);
diff --git a/drivers/ide/ide-floppy_proc.c b/drivers/ide/ide-floppy_proc.c
index fcd4d8153df5..d711d9b883de 100644
--- a/drivers/ide/ide-floppy_proc.c
+++ b/drivers/ide/ide-floppy_proc.c
@@ -1,22 +1,34 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/ide.h> 2#include <linux/ide.h>
3#include <linux/seq_file.h>
3 4
4#include "ide-floppy.h" 5#include "ide-floppy.h"
5 6
6static int proc_idefloppy_read_capacity(char *page, char **start, off_t off, 7static int idefloppy_capacity_proc_show(struct seq_file *m, void *v)
7 int count, int *eof, void *data)
8{ 8{
9 ide_drive_t*drive = (ide_drive_t *)data; 9 ide_drive_t*drive = (ide_drive_t *)m->private;
10 int len;
11 10
12 len = sprintf(page, "%llu\n", (long long)ide_gd_capacity(drive)); 11 seq_printf(m, "%llu\n", (long long)ide_gd_capacity(drive));
13 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 12 return 0;
14} 13}
15 14
15static int idefloppy_capacity_proc_open(struct inode *inode, struct file *file)
16{
17 return single_open(file, idefloppy_capacity_proc_show, PDE(inode)->data);
18}
19
20static const struct file_operations idefloppy_capacity_proc_fops = {
21 .owner = THIS_MODULE,
22 .open = idefloppy_capacity_proc_open,
23 .read = seq_read,
24 .llseek = seq_lseek,
25 .release = single_release,
26};
27
16ide_proc_entry_t ide_floppy_proc[] = { 28ide_proc_entry_t ide_floppy_proc[] = {
17 { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL }, 29 { "capacity", S_IFREG|S_IRUGO, &idefloppy_capacity_proc_fops },
18 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, 30 { "geometry", S_IFREG|S_IRUGO, &ide_geometry_proc_fops },
19 { NULL, 0, NULL, NULL } 31 {}
20}; 32};
21 33
22ide_devset_rw_field(bios_cyl, bios_cyl); 34ide_devset_rw_field(bios_cyl, bios_cyl);
diff --git a/drivers/ide/ide-ioctls.c b/drivers/ide/ide-ioctls.c
index e246d3d3fbcc..d3440b5010a5 100644
--- a/drivers/ide/ide-ioctls.c
+++ b/drivers/ide/ide-ioctls.c
@@ -167,6 +167,8 @@ static int ide_cmd_ioctl(ide_drive_t *drive, unsigned long arg)
167 err = -EINVAL; 167 err = -EINVAL;
168 goto abort; 168 goto abort;
169 } 169 }
170
171 cmd.tf_flags |= IDE_TFLAG_SET_XFER;
170 } 172 }
171 173
172 err = ide_raw_taskfile(drive, &cmd, buf, args[3]); 174 err = ide_raw_taskfile(drive, &cmd, buf, args[3]);
@@ -174,12 +176,6 @@ static int ide_cmd_ioctl(ide_drive_t *drive, unsigned long arg)
174 args[0] = tf->status; 176 args[0] = tf->status;
175 args[1] = tf->error; 177 args[1] = tf->error;
176 args[2] = tf->nsect; 178 args[2] = tf->nsect;
177
178 if (!err && xfer_rate) {
179 /* active-retuning-calls future */
180 ide_set_xfer_rate(drive, xfer_rate);
181 ide_driveid_update(drive);
182 }
183abort: 179abort:
184 if (copy_to_user((void __user *)arg, &args, 4)) 180 if (copy_to_user((void __user *)arg, &args, 4))
185 err = -EFAULT; 181 err = -EFAULT;
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index 2892b242bbe1..222c1ef65fb9 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -102,8 +102,8 @@ EXPORT_SYMBOL(ide_fixstring);
102 * setting a timer to wake up at half second intervals thereafter, 102 * setting a timer to wake up at half second intervals thereafter,
103 * until timeout is achieved, before timing out. 103 * until timeout is achieved, before timing out.
104 */ 104 */
105static int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad, 105int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad,
106 unsigned long timeout, u8 *rstat) 106 unsigned long timeout, u8 *rstat)
107{ 107{
108 ide_hwif_t *hwif = drive->hwif; 108 ide_hwif_t *hwif = drive->hwif;
109 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 109 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
@@ -292,6 +292,7 @@ static const char *nien_quirk_list[] = {
292 "QUANTUM FIREBALLP KX27.3", 292 "QUANTUM FIREBALLP KX27.3",
293 "QUANTUM FIREBALLP LM20.4", 293 "QUANTUM FIREBALLP LM20.4",
294 "QUANTUM FIREBALLP LM20.5", 294 "QUANTUM FIREBALLP LM20.5",
295 "FUJITSU MHZ2160BH G2",
295 NULL 296 NULL
296}; 297};
297 298
@@ -316,7 +317,7 @@ int ide_driveid_update(ide_drive_t *drive)
316 return 0; 317 return 0;
317 318
318 SELECT_MASK(drive, 1); 319 SELECT_MASK(drive, 1);
319 rc = ide_dev_read_id(drive, ATA_CMD_ID_ATA, id); 320 rc = ide_dev_read_id(drive, ATA_CMD_ID_ATA, id, 1);
320 SELECT_MASK(drive, 0); 321 SELECT_MASK(drive, 0);
321 322
322 if (rc) 323 if (rc)
@@ -363,14 +364,6 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
363 * this point (lost interrupt). 364 * this point (lost interrupt).
364 */ 365 */
365 366
366 /*
367 * FIXME: we race against the running IRQ here if
368 * this is called from non IRQ context. If we use
369 * disable_irq() we hang on the error path. Work
370 * is needed.
371 */
372 disable_irq_nosync(hwif->irq);
373
374 udelay(1); 367 udelay(1);
375 tp_ops->dev_select(drive); 368 tp_ops->dev_select(drive);
376 SELECT_MASK(drive, 1); 369 SELECT_MASK(drive, 1);
@@ -394,8 +387,6 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
394 387
395 SELECT_MASK(drive, 0); 388 SELECT_MASK(drive, 0);
396 389
397 enable_irq(hwif->irq);
398
399 if (error) { 390 if (error) {
400 (void) ide_dump_status(drive, "set_drive_speed_status", stat); 391 (void) ide_dump_status(drive, "set_drive_speed_status", stat);
401 return error; 392 return error;
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 1bb106f6221a..8de442cbee94 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -238,6 +238,7 @@ static void do_identify(ide_drive_t *drive, u8 cmd, u16 *id)
238 * @drive: drive to identify 238 * @drive: drive to identify
239 * @cmd: command to use 239 * @cmd: command to use
240 * @id: buffer for IDENTIFY data 240 * @id: buffer for IDENTIFY data
241 * @irq_ctx: flag set when called from the IRQ context
241 * 242 *
242 * Sends an ATA(PI) IDENTIFY request to a drive and waits for a response. 243 * Sends an ATA(PI) IDENTIFY request to a drive and waits for a response.
243 * 244 *
@@ -246,7 +247,7 @@ static void do_identify(ide_drive_t *drive, u8 cmd, u16 *id)
246 * 2 device aborted the command (refused to identify itself) 247 * 2 device aborted the command (refused to identify itself)
247 */ 248 */
248 249
249int ide_dev_read_id(ide_drive_t *drive, u8 cmd, u16 *id) 250int ide_dev_read_id(ide_drive_t *drive, u8 cmd, u16 *id, int irq_ctx)
250{ 251{
251 ide_hwif_t *hwif = drive->hwif; 252 ide_hwif_t *hwif = drive->hwif;
252 struct ide_io_ports *io_ports = &hwif->io_ports; 253 struct ide_io_ports *io_ports = &hwif->io_ports;
@@ -263,7 +264,10 @@ int ide_dev_read_id(ide_drive_t *drive, u8 cmd, u16 *id)
263 tp_ops->write_devctl(hwif, ATA_NIEN | ATA_DEVCTL_OBS); 264 tp_ops->write_devctl(hwif, ATA_NIEN | ATA_DEVCTL_OBS);
264 265
265 /* take a deep breath */ 266 /* take a deep breath */
266 msleep(50); 267 if (irq_ctx)
268 mdelay(50);
269 else
270 msleep(50);
267 271
268 if (io_ports->ctl_addr && 272 if (io_ports->ctl_addr &&
269 (hwif->host_flags & IDE_HFLAG_BROKEN_ALTSTATUS) == 0) { 273 (hwif->host_flags & IDE_HFLAG_BROKEN_ALTSTATUS) == 0) {
@@ -295,12 +299,19 @@ int ide_dev_read_id(ide_drive_t *drive, u8 cmd, u16 *id)
295 299
296 timeout = ((cmd == ATA_CMD_ID_ATA) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2; 300 timeout = ((cmd == ATA_CMD_ID_ATA) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2;
297 301
298 if (ide_busy_sleep(drive, timeout, use_altstatus))
299 return 1;
300
301 /* wait for IRQ and ATA_DRQ */ 302 /* wait for IRQ and ATA_DRQ */
302 msleep(50); 303 if (irq_ctx) {
303 s = tp_ops->read_status(hwif); 304 rc = __ide_wait_stat(drive, ATA_DRQ, BAD_R_STAT, timeout, &s);
305 if (rc)
306 return 1;
307 } else {
308 rc = ide_busy_sleep(drive, timeout, use_altstatus);
309 if (rc)
310 return 1;
311
312 msleep(50);
313 s = tp_ops->read_status(hwif);
314 }
304 315
305 if (OK_STAT(s, ATA_DRQ, BAD_R_STAT)) { 316 if (OK_STAT(s, ATA_DRQ, BAD_R_STAT)) {
306 /* drive returned ID */ 317 /* drive returned ID */
@@ -406,10 +417,10 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
406 417
407 if (OK_STAT(stat, ATA_DRDY, ATA_BUSY) || 418 if (OK_STAT(stat, ATA_DRDY, ATA_BUSY) ||
408 present || cmd == ATA_CMD_ID_ATAPI) { 419 present || cmd == ATA_CMD_ID_ATAPI) {
409 rc = ide_dev_read_id(drive, cmd, id); 420 rc = ide_dev_read_id(drive, cmd, id, 0);
410 if (rc) 421 if (rc)
411 /* failed: try again */ 422 /* failed: try again */
412 rc = ide_dev_read_id(drive, cmd, id); 423 rc = ide_dev_read_id(drive, cmd, id, 0);
413 424
414 stat = tp_ops->read_status(hwif); 425 stat = tp_ops->read_status(hwif);
415 426
@@ -424,7 +435,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
424 msleep(50); 435 msleep(50);
425 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET); 436 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
426 (void)ide_busy_sleep(drive, WAIT_WORSTCASE, 0); 437 (void)ide_busy_sleep(drive, WAIT_WORSTCASE, 0);
427 rc = ide_dev_read_id(drive, cmd, id); 438 rc = ide_dev_read_id(drive, cmd, id, 0);
428 } 439 }
429 440
430 /* ensure drive IRQ is clear */ 441 /* ensure drive IRQ is clear */
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index 3242698832a4..28d09a5d8450 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -30,11 +30,9 @@
30 30
31static struct proc_dir_entry *proc_ide_root; 31static struct proc_dir_entry *proc_ide_root;
32 32
33static int proc_ide_read_imodel 33static int ide_imodel_proc_show(struct seq_file *m, void *v)
34 (char *page, char **start, off_t off, int count, int *eof, void *data)
35{ 34{
36 ide_hwif_t *hwif = (ide_hwif_t *) data; 35 ide_hwif_t *hwif = (ide_hwif_t *) m->private;
37 int len;
38 const char *name; 36 const char *name;
39 37
40 switch (hwif->chipset) { 38 switch (hwif->chipset) {
@@ -53,63 +51,108 @@ static int proc_ide_read_imodel
53 case ide_acorn: name = "acorn"; break; 51 case ide_acorn: name = "acorn"; break;
54 default: name = "(unknown)"; break; 52 default: name = "(unknown)"; break;
55 } 53 }
56 len = sprintf(page, "%s\n", name); 54 seq_printf(m, "%s\n", name);
57 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 55 return 0;
58} 56}
59 57
60static int proc_ide_read_mate 58static int ide_imodel_proc_open(struct inode *inode, struct file *file)
61 (char *page, char **start, off_t off, int count, int *eof, void *data)
62{ 59{
63 ide_hwif_t *hwif = (ide_hwif_t *) data; 60 return single_open(file, ide_imodel_proc_show, PDE(inode)->data);
64 int len; 61}
62
63static const struct file_operations ide_imodel_proc_fops = {
64 .owner = THIS_MODULE,
65 .open = ide_imodel_proc_open,
66 .read = seq_read,
67 .llseek = seq_lseek,
68 .release = single_release,
69};
70
71static int ide_mate_proc_show(struct seq_file *m, void *v)
72{
73 ide_hwif_t *hwif = (ide_hwif_t *) m->private;
65 74
66 if (hwif && hwif->mate) 75 if (hwif && hwif->mate)
67 len = sprintf(page, "%s\n", hwif->mate->name); 76 seq_printf(m, "%s\n", hwif->mate->name);
68 else 77 else
69 len = sprintf(page, "(none)\n"); 78 seq_printf(m, "(none)\n");
70 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 79 return 0;
80}
81
82static int ide_mate_proc_open(struct inode *inode, struct file *file)
83{
84 return single_open(file, ide_mate_proc_show, PDE(inode)->data);
71} 85}
72 86
73static int proc_ide_read_channel 87static const struct file_operations ide_mate_proc_fops = {
74 (char *page, char **start, off_t off, int count, int *eof, void *data) 88 .owner = THIS_MODULE,
89 .open = ide_mate_proc_open,
90 .read = seq_read,
91 .llseek = seq_lseek,
92 .release = single_release,
93};
94
95static int ide_channel_proc_show(struct seq_file *m, void *v)
75{ 96{
76 ide_hwif_t *hwif = (ide_hwif_t *) data; 97 ide_hwif_t *hwif = (ide_hwif_t *) m->private;
77 int len;
78 98
79 page[0] = hwif->channel ? '1' : '0'; 99 seq_printf(m, "%c\n", hwif->channel ? '1' : '0');
80 page[1] = '\n'; 100 return 0;
81 len = 2;
82 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
83} 101}
84 102
85static int proc_ide_read_identify 103static int ide_channel_proc_open(struct inode *inode, struct file *file)
86 (char *page, char **start, off_t off, int count, int *eof, void *data)
87{ 104{
88 ide_drive_t *drive = (ide_drive_t *)data; 105 return single_open(file, ide_channel_proc_show, PDE(inode)->data);
89 int len = 0, i = 0; 106}
90 int err = 0; 107
108static const struct file_operations ide_channel_proc_fops = {
109 .owner = THIS_MODULE,
110 .open = ide_channel_proc_open,
111 .read = seq_read,
112 .llseek = seq_lseek,
113 .release = single_release,
114};
91 115
92 len = sprintf(page, "\n"); 116static int ide_identify_proc_show(struct seq_file *m, void *v)
117{
118 ide_drive_t *drive = (ide_drive_t *)m->private;
119 u8 *buf;
93 120
94 if (drive) { 121 if (!drive) {
95 __le16 *val = (__le16 *)page; 122 seq_putc(m, '\n');
123 return 0;
124 }
96 125
97 err = taskfile_lib_get_identify(drive, page); 126 buf = kmalloc(SECTOR_SIZE, GFP_KERNEL);
98 if (!err) { 127 if (!buf)
99 char *out = (char *)page + SECTOR_SIZE; 128 return -ENOMEM;
129 if (taskfile_lib_get_identify(drive, buf) == 0) {
130 __le16 *val = (__le16 *)buf;
131 int i;
100 132
101 page = out; 133 for (i = 0; i < SECTOR_SIZE / 2; i++) {
102 do { 134 seq_printf(m, "%04x%c", le16_to_cpu(val[i]),
103 out += sprintf(out, "%04x%c", 135 (i % 8) == 7 ? '\n' : ' ');
104 le16_to_cpup(val), (++i & 7) ? ' ' : '\n');
105 val += 1;
106 } while (i < SECTOR_SIZE / 2);
107 len = out - page;
108 } 136 }
109 } 137 } else
110 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 138 seq_putc(m, buf[0]);
139 kfree(buf);
140 return 0;
141}
142
143static int ide_identify_proc_open(struct inode *inode, struct file *file)
144{
145 return single_open(file, ide_identify_proc_show, PDE(inode)->data);
111} 146}
112 147
148static const struct file_operations ide_identify_proc_fops = {
149 .owner = THIS_MODULE,
150 .open = ide_identify_proc_open,
151 .read = seq_read,
152 .llseek = seq_lseek,
153 .release = single_release,
154};
155
113/** 156/**
114 * ide_find_setting - find a specific setting 157 * ide_find_setting - find a specific setting
115 * @st: setting table pointer 158 * @st: setting table pointer
@@ -195,7 +238,6 @@ ide_devset_get(xfer_rate, current_speed);
195static int set_xfer_rate (ide_drive_t *drive, int arg) 238static int set_xfer_rate (ide_drive_t *drive, int arg)
196{ 239{
197 struct ide_cmd cmd; 240 struct ide_cmd cmd;
198 int err;
199 241
200 if (arg < XFER_PIO_0 || arg > XFER_UDMA_6) 242 if (arg < XFER_PIO_0 || arg > XFER_UDMA_6)
201 return -EINVAL; 243 return -EINVAL;
@@ -206,14 +248,9 @@ static int set_xfer_rate (ide_drive_t *drive, int arg)
206 cmd.tf.nsect = (u8)arg; 248 cmd.tf.nsect = (u8)arg;
207 cmd.valid.out.tf = IDE_VALID_FEATURE | IDE_VALID_NSECT; 249 cmd.valid.out.tf = IDE_VALID_FEATURE | IDE_VALID_NSECT;
208 cmd.valid.in.tf = IDE_VALID_NSECT; 250 cmd.valid.in.tf = IDE_VALID_NSECT;
251 cmd.tf_flags = IDE_TFLAG_SET_XFER;
209 252
210 err = ide_no_data_taskfile(drive, &cmd); 253 return ide_no_data_taskfile(drive, &cmd);
211
212 if (!err) {
213 ide_set_xfer_rate(drive, (u8) arg);
214 ide_driveid_update(drive);
215 }
216 return err;
217} 254}
218 255
219ide_devset_rw(current_speed, xfer_rate); 256ide_devset_rw(current_speed, xfer_rate);
@@ -246,22 +283,20 @@ static void proc_ide_settings_warn(void)
246 warned = 1; 283 warned = 1;
247} 284}
248 285
249static int proc_ide_read_settings 286static int ide_settings_proc_show(struct seq_file *m, void *v)
250 (char *page, char **start, off_t off, int count, int *eof, void *data)
251{ 287{
252 const struct ide_proc_devset *setting, *g, *d; 288 const struct ide_proc_devset *setting, *g, *d;
253 const struct ide_devset *ds; 289 const struct ide_devset *ds;
254 ide_drive_t *drive = (ide_drive_t *) data; 290 ide_drive_t *drive = (ide_drive_t *) m->private;
255 char *out = page; 291 int rc, mul_factor, div_factor;
256 int len, rc, mul_factor, div_factor;
257 292
258 proc_ide_settings_warn(); 293 proc_ide_settings_warn();
259 294
260 mutex_lock(&ide_setting_mtx); 295 mutex_lock(&ide_setting_mtx);
261 g = ide_generic_settings; 296 g = ide_generic_settings;
262 d = drive->settings; 297 d = drive->settings;
263 out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n"); 298 seq_printf(m, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
264 out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n"); 299 seq_printf(m, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
265 while (g->name || (d && d->name)) { 300 while (g->name || (d && d->name)) {
266 /* read settings in the alphabetical order */ 301 /* read settings in the alphabetical order */
267 if (g->name && d && d->name) { 302 if (g->name && d && d->name) {
@@ -275,31 +310,35 @@ static int proc_ide_read_settings
275 setting = g++; 310 setting = g++;
276 mul_factor = setting->mulf ? setting->mulf(drive) : 1; 311 mul_factor = setting->mulf ? setting->mulf(drive) : 1;
277 div_factor = setting->divf ? setting->divf(drive) : 1; 312 div_factor = setting->divf ? setting->divf(drive) : 1;
278 out += sprintf(out, "%-24s", setting->name); 313 seq_printf(m, "%-24s", setting->name);
279 rc = ide_read_setting(drive, setting); 314 rc = ide_read_setting(drive, setting);
280 if (rc >= 0) 315 if (rc >= 0)
281 out += sprintf(out, "%-16d", rc * mul_factor / div_factor); 316 seq_printf(m, "%-16d", rc * mul_factor / div_factor);
282 else 317 else
283 out += sprintf(out, "%-16s", "write-only"); 318 seq_printf(m, "%-16s", "write-only");
284 out += sprintf(out, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor); 319 seq_printf(m, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor);
285 ds = setting->setting; 320 ds = setting->setting;
286 if (ds->get) 321 if (ds->get)
287 out += sprintf(out, "r"); 322 seq_printf(m, "r");
288 if (ds->set) 323 if (ds->set)
289 out += sprintf(out, "w"); 324 seq_printf(m, "w");
290 out += sprintf(out, "\n"); 325 seq_printf(m, "\n");
291 } 326 }
292 len = out - page;
293 mutex_unlock(&ide_setting_mtx); 327 mutex_unlock(&ide_setting_mtx);
294 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 328 return 0;
329}
330
331static int ide_settings_proc_open(struct inode *inode, struct file *file)
332{
333 return single_open(file, ide_settings_proc_show, PDE(inode)->data);
295} 334}
296 335
297#define MAX_LEN 30 336#define MAX_LEN 30
298 337
299static int proc_ide_write_settings(struct file *file, const char __user *buffer, 338static ssize_t ide_settings_proc_write(struct file *file, const char __user *buffer,
300 unsigned long count, void *data) 339 size_t count, loff_t *pos)
301{ 340{
302 ide_drive_t *drive = (ide_drive_t *) data; 341 ide_drive_t *drive = (ide_drive_t *) PDE(file->f_path.dentry->d_inode)->data;
303 char name[MAX_LEN + 1]; 342 char name[MAX_LEN + 1];
304 int for_real = 0, mul_factor, div_factor; 343 int for_real = 0, mul_factor, div_factor;
305 unsigned long n; 344 unsigned long n;
@@ -394,63 +433,104 @@ static int proc_ide_write_settings(struct file *file, const char __user *buffer,
394 return count; 433 return count;
395parse_error: 434parse_error:
396 free_page((unsigned long)buf); 435 free_page((unsigned long)buf);
397 printk("proc_ide_write_settings(): parse error\n"); 436 printk("%s(): parse error\n", __func__);
398 return -EINVAL; 437 return -EINVAL;
399} 438}
400 439
401int proc_ide_read_capacity 440static const struct file_operations ide_settings_proc_fops = {
402 (char *page, char **start, off_t off, int count, int *eof, void *data) 441 .owner = THIS_MODULE,
442 .open = ide_settings_proc_open,
443 .read = seq_read,
444 .llseek = seq_lseek,
445 .release = single_release,
446 .write = ide_settings_proc_write,
447};
448
449static int ide_capacity_proc_show(struct seq_file *m, void *v)
450{
451 seq_printf(m, "%llu\n", (long long)0x7fffffff);
452 return 0;
453}
454
455static int ide_capacity_proc_open(struct inode *inode, struct file *file)
403{ 456{
404 int len = sprintf(page, "%llu\n", (long long)0x7fffffff); 457 return single_open(file, ide_capacity_proc_show, NULL);
405 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
406} 458}
407 459
408EXPORT_SYMBOL_GPL(proc_ide_read_capacity); 460const struct file_operations ide_capacity_proc_fops = {
461 .owner = THIS_MODULE,
462 .open = ide_capacity_proc_open,
463 .read = seq_read,
464 .llseek = seq_lseek,
465 .release = single_release,
466};
467EXPORT_SYMBOL_GPL(ide_capacity_proc_fops);
409 468
410int proc_ide_read_geometry 469static int ide_geometry_proc_show(struct seq_file *m, void *v)
411 (char *page, char **start, off_t off, int count, int *eof, void *data)
412{ 470{
413 ide_drive_t *drive = (ide_drive_t *) data; 471 ide_drive_t *drive = (ide_drive_t *) m->private;
414 char *out = page;
415 int len;
416 472
417 out += sprintf(out, "physical %d/%d/%d\n", 473 seq_printf(m, "physical %d/%d/%d\n",
418 drive->cyl, drive->head, drive->sect); 474 drive->cyl, drive->head, drive->sect);
419 out += sprintf(out, "logical %d/%d/%d\n", 475 seq_printf(m, "logical %d/%d/%d\n",
420 drive->bios_cyl, drive->bios_head, drive->bios_sect); 476 drive->bios_cyl, drive->bios_head, drive->bios_sect);
477 return 0;
478}
421 479
422 len = out - page; 480static int ide_geometry_proc_open(struct inode *inode, struct file *file)
423 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 481{
482 return single_open(file, ide_geometry_proc_show, PDE(inode)->data);
424} 483}
425 484
426EXPORT_SYMBOL(proc_ide_read_geometry); 485const struct file_operations ide_geometry_proc_fops = {
486 .owner = THIS_MODULE,
487 .open = ide_geometry_proc_open,
488 .read = seq_read,
489 .llseek = seq_lseek,
490 .release = single_release,
491};
492EXPORT_SYMBOL(ide_geometry_proc_fops);
427 493
428static int proc_ide_read_dmodel 494static int ide_dmodel_proc_show(struct seq_file *seq, void *v)
429 (char *page, char **start, off_t off, int count, int *eof, void *data)
430{ 495{
431 ide_drive_t *drive = (ide_drive_t *) data; 496 ide_drive_t *drive = (ide_drive_t *) seq->private;
432 char *m = (char *)&drive->id[ATA_ID_PROD]; 497 char *m = (char *)&drive->id[ATA_ID_PROD];
433 int len;
434 498
435 len = sprintf(page, "%.40s\n", m[0] ? m : "(none)"); 499 seq_printf(seq, "%.40s\n", m[0] ? m : "(none)");
436 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 500 return 0;
501}
502
503static int ide_dmodel_proc_open(struct inode *inode, struct file *file)
504{
505 return single_open(file, ide_dmodel_proc_show, PDE(inode)->data);
437} 506}
438 507
439static int proc_ide_read_driver 508static const struct file_operations ide_dmodel_proc_fops = {
440 (char *page, char **start, off_t off, int count, int *eof, void *data) 509 .owner = THIS_MODULE,
510 .open = ide_dmodel_proc_open,
511 .read = seq_read,
512 .llseek = seq_lseek,
513 .release = single_release,
514};
515
516static int ide_driver_proc_show(struct seq_file *m, void *v)
441{ 517{
442 ide_drive_t *drive = (ide_drive_t *)data; 518 ide_drive_t *drive = (ide_drive_t *)m->private;
443 struct device *dev = &drive->gendev; 519 struct device *dev = &drive->gendev;
444 struct ide_driver *ide_drv; 520 struct ide_driver *ide_drv;
445 int len;
446 521
447 if (dev->driver) { 522 if (dev->driver) {
448 ide_drv = to_ide_driver(dev->driver); 523 ide_drv = to_ide_driver(dev->driver);
449 len = sprintf(page, "%s version %s\n", 524 seq_printf(m, "%s version %s\n",
450 dev->driver->name, ide_drv->version); 525 dev->driver->name, ide_drv->version);
451 } else 526 } else
452 len = sprintf(page, "ide-default version 0.9.newide\n"); 527 seq_printf(m, "ide-default version 0.9.newide\n");
453 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 528 return 0;
529}
530
531static int ide_driver_proc_open(struct inode *inode, struct file *file)
532{
533 return single_open(file, ide_driver_proc_show, PDE(inode)->data);
454} 534}
455 535
456static int ide_replace_subdriver(ide_drive_t *drive, const char *driver) 536static int ide_replace_subdriver(ide_drive_t *drive, const char *driver)
@@ -480,10 +560,10 @@ static int ide_replace_subdriver(ide_drive_t *drive, const char *driver)
480 return ret; 560 return ret;
481} 561}
482 562
483static int proc_ide_write_driver 563static ssize_t ide_driver_proc_write(struct file *file, const char __user *buffer,
484 (struct file *file, const char __user *buffer, unsigned long count, void *data) 564 size_t count, loff_t *pos)
485{ 565{
486 ide_drive_t *drive = (ide_drive_t *) data; 566 ide_drive_t *drive = (ide_drive_t *) PDE(file->f_path.dentry->d_inode)->data;
487 char name[32]; 567 char name[32];
488 568
489 if (!capable(CAP_SYS_ADMIN)) 569 if (!capable(CAP_SYS_ADMIN))
@@ -498,12 +578,19 @@ static int proc_ide_write_driver
498 return count; 578 return count;
499} 579}
500 580
501static int proc_ide_read_media 581static const struct file_operations ide_driver_proc_fops = {
502 (char *page, char **start, off_t off, int count, int *eof, void *data) 582 .owner = THIS_MODULE,
583 .open = ide_driver_proc_open,
584 .read = seq_read,
585 .llseek = seq_lseek,
586 .release = single_release,
587 .write = ide_driver_proc_write,
588};
589
590static int ide_media_proc_show(struct seq_file *m, void *v)
503{ 591{
504 ide_drive_t *drive = (ide_drive_t *) data; 592 ide_drive_t *drive = (ide_drive_t *) m->private;
505 const char *media; 593 const char *media;
506 int len;
507 594
508 switch (drive->media) { 595 switch (drive->media) {
509 case ide_disk: media = "disk\n"; break; 596 case ide_disk: media = "disk\n"; break;
@@ -513,20 +600,30 @@ static int proc_ide_read_media
513 case ide_optical: media = "optical\n"; break; 600 case ide_optical: media = "optical\n"; break;
514 default: media = "UNKNOWN\n"; break; 601 default: media = "UNKNOWN\n"; break;
515 } 602 }
516 strcpy(page, media); 603 seq_puts(m, media);
517 len = strlen(media); 604 return 0;
518 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 605}
606
607static int ide_media_proc_open(struct inode *inode, struct file *file)
608{
609 return single_open(file, ide_media_proc_show, PDE(inode)->data);
519} 610}
520 611
612static const struct file_operations ide_media_proc_fops = {
613 .owner = THIS_MODULE,
614 .open = ide_media_proc_open,
615 .read = seq_read,
616 .llseek = seq_lseek,
617 .release = single_release,
618};
619
521static ide_proc_entry_t generic_drive_entries[] = { 620static ide_proc_entry_t generic_drive_entries[] = {
522 { "driver", S_IFREG|S_IRUGO, proc_ide_read_driver, 621 { "driver", S_IFREG|S_IRUGO, &ide_driver_proc_fops },
523 proc_ide_write_driver }, 622 { "identify", S_IFREG|S_IRUSR, &ide_identify_proc_fops},
524 { "identify", S_IFREG|S_IRUSR, proc_ide_read_identify, NULL }, 623 { "media", S_IFREG|S_IRUGO, &ide_media_proc_fops },
525 { "media", S_IFREG|S_IRUGO, proc_ide_read_media, NULL }, 624 { "model", S_IFREG|S_IRUGO, &ide_dmodel_proc_fops },
526 { "model", S_IFREG|S_IRUGO, proc_ide_read_dmodel, NULL }, 625 { "settings", S_IFREG|S_IRUSR|S_IWUSR, &ide_settings_proc_fops},
527 { "settings", S_IFREG|S_IRUSR|S_IWUSR, proc_ide_read_settings, 626 {}
528 proc_ide_write_settings },
529 { NULL, 0, NULL, NULL }
530}; 627};
531 628
532static void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data) 629static void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data)
@@ -536,11 +633,8 @@ static void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p
536 if (!dir || !p) 633 if (!dir || !p)
537 return; 634 return;
538 while (p->name != NULL) { 635 while (p->name != NULL) {
539 ent = create_proc_entry(p->name, p->mode, dir); 636 ent = proc_create_data(p->name, p->mode, dir, p->proc_fops, data);
540 if (!ent) return; 637 if (!ent) return;
541 ent->data = data;
542 ent->read_proc = p->read_proc;
543 ent->write_proc = p->write_proc;
544 p++; 638 p++;
545 } 639 }
546} 640}
@@ -623,10 +717,10 @@ void ide_proc_unregister_device(ide_drive_t *drive)
623} 717}
624 718
625static ide_proc_entry_t hwif_entries[] = { 719static ide_proc_entry_t hwif_entries[] = {
626 { "channel", S_IFREG|S_IRUGO, proc_ide_read_channel, NULL }, 720 { "channel", S_IFREG|S_IRUGO, &ide_channel_proc_fops },
627 { "mate", S_IFREG|S_IRUGO, proc_ide_read_mate, NULL }, 721 { "mate", S_IFREG|S_IRUGO, &ide_mate_proc_fops },
628 { "model", S_IFREG|S_IRUGO, proc_ide_read_imodel, NULL }, 722 { "model", S_IFREG|S_IRUGO, &ide_imodel_proc_fops },
629 { NULL, 0, NULL, NULL } 723 {}
630}; 724};
631 725
632void ide_proc_register_port(ide_hwif_t *hwif) 726void ide_proc_register_port(ide_hwif_t *hwif)
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index bc5fb12b913c..9d6f62baac27 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -31,6 +31,7 @@
31#include <linux/major.h> 31#include <linux/major.h>
32#include <linux/errno.h> 32#include <linux/errno.h>
33#include <linux/genhd.h> 33#include <linux/genhd.h>
34#include <linux/seq_file.h>
34#include <linux/slab.h> 35#include <linux/slab.h>
35#include <linux/pci.h> 36#include <linux/pci.h>
36#include <linux/ide.h> 37#include <linux/ide.h>
@@ -47,28 +48,13 @@
47#include <asm/unaligned.h> 48#include <asm/unaligned.h>
48#include <linux/mtio.h> 49#include <linux/mtio.h>
49 50
50enum {
51 /* output errors only */
52 DBG_ERR = (1 << 0),
53 /* output all sense key/asc */
54 DBG_SENSE = (1 << 1),
55 /* info regarding all chrdev-related procedures */
56 DBG_CHRDEV = (1 << 2),
57 /* all remaining procedures */
58 DBG_PROCS = (1 << 3),
59};
60
61/* define to see debug info */ 51/* define to see debug info */
62#define IDETAPE_DEBUG_LOG 0 52#undef IDETAPE_DEBUG_LOG
63 53
64#if IDETAPE_DEBUG_LOG 54#ifdef IDETAPE_DEBUG_LOG
65#define debug_log(lvl, fmt, args...) \ 55#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, ## args)
66{ \
67 if (tape->debug_mask & lvl) \
68 printk(KERN_INFO "ide-tape: " fmt, ## args); \
69}
70#else 56#else
71#define debug_log(lvl, fmt, args...) do {} while (0) 57#define ide_debug_log(lvl, fmt, args...) do {} while (0)
72#endif 58#endif
73 59
74/**************************** Tunable parameters *****************************/ 60/**************************** Tunable parameters *****************************/
@@ -170,7 +156,8 @@ typedef struct ide_tape_obj {
170 * other device. Note that at most we will have only one DSC (usually 156 * other device. Note that at most we will have only one DSC (usually
171 * data transfer) request in the device request queue. 157 * data transfer) request in the device request queue.
172 */ 158 */
173 struct request *postponed_rq; 159 bool postponed_rq;
160
174 /* The time in which we started polling for DSC */ 161 /* The time in which we started polling for DSC */
175 unsigned long dsc_polling_start; 162 unsigned long dsc_polling_start;
176 /* Timer used to poll for dsc */ 163 /* Timer used to poll for dsc */
@@ -230,8 +217,6 @@ typedef struct ide_tape_obj {
230 char drv_write_prot; 217 char drv_write_prot;
231 /* the tape is write protected (hardware or opened as read-only) */ 218 /* the tape is write protected (hardware or opened as read-only) */
232 char write_prot; 219 char write_prot;
233
234 u32 debug_mask;
235} idetape_tape_t; 220} idetape_tape_t;
236 221
237static DEFINE_MUTEX(idetape_ref_mutex); 222static DEFINE_MUTEX(idetape_ref_mutex);
@@ -290,8 +275,9 @@ static void idetape_analyze_error(ide_drive_t *drive)
290 tape->asc = sense[12]; 275 tape->asc = sense[12];
291 tape->ascq = sense[13]; 276 tape->ascq = sense[13];
292 277
293 debug_log(DBG_ERR, "pc = %x, sense key = %x, asc = %x, ascq = %x\n", 278 ide_debug_log(IDE_DBG_FUNC,
294 pc->c[0], tape->sense_key, tape->asc, tape->ascq); 279 "cmd: 0x%x, sense key = %x, asc = %x, ascq = %x",
280 rq->cmd[0], tape->sense_key, tape->asc, tape->ascq);
295 281
296 /* correct remaining bytes to transfer */ 282 /* correct remaining bytes to transfer */
297 if (pc->flags & PC_FLAG_DMA_ERROR) 283 if (pc->flags & PC_FLAG_DMA_ERROR)
@@ -344,7 +330,8 @@ static int ide_tape_callback(ide_drive_t *drive, int dsc)
344 int uptodate = pc->error ? 0 : 1; 330 int uptodate = pc->error ? 0 : 1;
345 int err = uptodate ? 0 : IDE_DRV_ERROR_GENERAL; 331 int err = uptodate ? 0 : IDE_DRV_ERROR_GENERAL;
346 332
347 debug_log(DBG_PROCS, "Enter %s\n", __func__); 333 ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x, dsc: %d, err: %d", rq->cmd[0],
334 dsc, err);
348 335
349 if (dsc) 336 if (dsc)
350 ide_tape_handle_dsc(drive); 337 ide_tape_handle_dsc(drive);
@@ -387,13 +374,14 @@ static int ide_tape_callback(ide_drive_t *drive, int dsc)
387 * Postpone the current request so that ide.c will be able to service requests 374 * Postpone the current request so that ide.c will be able to service requests
388 * from another device on the same port while we are polling for DSC. 375 * from another device on the same port while we are polling for DSC.
389 */ 376 */
390static void idetape_postpone_request(ide_drive_t *drive) 377static void ide_tape_stall_queue(ide_drive_t *drive)
391{ 378{
392 idetape_tape_t *tape = drive->driver_data; 379 idetape_tape_t *tape = drive->driver_data;
393 380
394 debug_log(DBG_PROCS, "Enter %s\n", __func__); 381 ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x, dsc_poll_freq: %lu",
382 drive->hwif->rq->cmd[0], tape->dsc_poll_freq);
395 383
396 tape->postponed_rq = drive->hwif->rq; 384 tape->postponed_rq = true;
397 385
398 ide_stall_queue(drive, tape->dsc_poll_freq); 386 ide_stall_queue(drive, tape->dsc_poll_freq);
399} 387}
@@ -407,7 +395,7 @@ static void ide_tape_handle_dsc(ide_drive_t *drive)
407 tape->dsc_poll_freq = IDETAPE_DSC_MA_FAST; 395 tape->dsc_poll_freq = IDETAPE_DSC_MA_FAST;
408 tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT; 396 tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT;
409 /* Allow ide.c to handle other requests */ 397 /* Allow ide.c to handle other requests */
410 idetape_postpone_request(drive); 398 ide_tape_stall_queue(drive);
411} 399}
412 400
413/* 401/*
@@ -488,7 +476,8 @@ static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive,
488 ide_complete_rq(drive, -EIO, blk_rq_bytes(rq)); 476 ide_complete_rq(drive, -EIO, blk_rq_bytes(rq));
489 return ide_stopped; 477 return ide_stopped;
490 } 478 }
491 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]); 479 ide_debug_log(IDE_DBG_SENSE, "retry #%d, cmd: 0x%02x", pc->retries,
480 pc->c[0]);
492 481
493 pc->retries++; 482 pc->retries++;
494 483
@@ -579,12 +568,12 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
579 ide_hwif_t *hwif = drive->hwif; 568 ide_hwif_t *hwif = drive->hwif;
580 idetape_tape_t *tape = drive->driver_data; 569 idetape_tape_t *tape = drive->driver_data;
581 struct ide_atapi_pc *pc = NULL; 570 struct ide_atapi_pc *pc = NULL;
582 struct request *postponed_rq = tape->postponed_rq;
583 struct ide_cmd cmd; 571 struct ide_cmd cmd;
584 u8 stat; 572 u8 stat;
585 573
586 debug_log(DBG_SENSE, "sector: %llu, nr_sectors: %u\n" 574 ide_debug_log(IDE_DBG_RQ, "cmd: 0x%x, sector: %llu, nr_sectors: %u",
587 (unsigned long long)blk_rq_pos(rq), blk_rq_sectors(rq)); 575 rq->cmd[0], (unsigned long long)blk_rq_pos(rq),
576 blk_rq_sectors(rq));
588 577
589 BUG_ON(!(blk_special_request(rq) || blk_sense_request(rq))); 578 BUG_ON(!(blk_special_request(rq) || blk_sense_request(rq)));
590 579
@@ -594,18 +583,6 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
594 goto out; 583 goto out;
595 } 584 }
596 585
597 if (postponed_rq != NULL)
598 if (rq != postponed_rq) {
599 printk(KERN_ERR "ide-tape: ide-tape.c bug - "
600 "Two DSC requests were queued\n");
601 drive->failed_pc = NULL;
602 rq->errors = 0;
603 ide_complete_rq(drive, 0, blk_rq_bytes(rq));
604 return ide_stopped;
605 }
606
607 tape->postponed_rq = NULL;
608
609 /* 586 /*
610 * If the tape is still busy, postpone our request and service 587 * If the tape is still busy, postpone our request and service
611 * the other device meanwhile. 588 * the other device meanwhile.
@@ -623,7 +600,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
623 600
624 if (!(drive->atapi_flags & IDE_AFLAG_IGNORE_DSC) && 601 if (!(drive->atapi_flags & IDE_AFLAG_IGNORE_DSC) &&
625 !(stat & ATA_DSC)) { 602 !(stat & ATA_DSC)) {
626 if (postponed_rq == NULL) { 603 if (!tape->postponed_rq) {
627 tape->dsc_polling_start = jiffies; 604 tape->dsc_polling_start = jiffies;
628 tape->dsc_poll_freq = tape->best_dsc_rw_freq; 605 tape->dsc_poll_freq = tape->best_dsc_rw_freq;
629 tape->dsc_timeout = jiffies + IDETAPE_DSC_RW_TIMEOUT; 606 tape->dsc_timeout = jiffies + IDETAPE_DSC_RW_TIMEOUT;
@@ -640,10 +617,12 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
640 tape->dsc_polling_start + 617 tape->dsc_polling_start +
641 IDETAPE_DSC_MA_THRESHOLD)) 618 IDETAPE_DSC_MA_THRESHOLD))
642 tape->dsc_poll_freq = IDETAPE_DSC_MA_SLOW; 619 tape->dsc_poll_freq = IDETAPE_DSC_MA_SLOW;
643 idetape_postpone_request(drive); 620 ide_tape_stall_queue(drive);
644 return ide_stopped; 621 return ide_stopped;
645 } else 622 } else {
646 drive->atapi_flags &= ~IDE_AFLAG_IGNORE_DSC; 623 drive->atapi_flags &= ~IDE_AFLAG_IGNORE_DSC;
624 tape->postponed_rq = false;
625 }
647 626
648 if (rq->cmd[13] & REQ_IDETAPE_READ) { 627 if (rq->cmd[13] & REQ_IDETAPE_READ) {
649 pc = &tape->queued_pc; 628 pc = &tape->queued_pc;
@@ -745,7 +724,7 @@ static int ide_tape_read_position(ide_drive_t *drive)
745 struct ide_atapi_pc pc; 724 struct ide_atapi_pc pc;
746 u8 buf[20]; 725 u8 buf[20];
747 726
748 debug_log(DBG_PROCS, "Enter %s\n", __func__); 727 ide_debug_log(IDE_DBG_FUNC, "enter");
749 728
750 /* prep cmd */ 729 /* prep cmd */
751 ide_init_pc(&pc); 730 ide_init_pc(&pc);
@@ -756,9 +735,9 @@ static int ide_tape_read_position(ide_drive_t *drive)
756 return -1; 735 return -1;
757 736
758 if (!pc.error) { 737 if (!pc.error) {
759 debug_log(DBG_SENSE, "BOP - %s\n", 738 ide_debug_log(IDE_DBG_FUNC, "BOP - %s",
760 (buf[0] & 0x80) ? "Yes" : "No"); 739 (buf[0] & 0x80) ? "Yes" : "No");
761 debug_log(DBG_SENSE, "EOP - %s\n", 740 ide_debug_log(IDE_DBG_FUNC, "EOP - %s",
762 (buf[0] & 0x40) ? "Yes" : "No"); 741 (buf[0] & 0x40) ? "Yes" : "No");
763 742
764 if (buf[0] & 0x4) { 743 if (buf[0] & 0x4) {
@@ -768,8 +747,8 @@ static int ide_tape_read_position(ide_drive_t *drive)
768 &drive->atapi_flags); 747 &drive->atapi_flags);
769 return -1; 748 return -1;
770 } else { 749 } else {
771 debug_log(DBG_SENSE, "Block Location - %u\n", 750 ide_debug_log(IDE_DBG_FUNC, "Block Location: %u",
772 be32_to_cpup((__be32 *)&buf[4])); 751 be32_to_cpup((__be32 *)&buf[4]));
773 752
774 tape->partition = buf[1]; 753 tape->partition = buf[1];
775 tape->first_frame = be32_to_cpup((__be32 *)&buf[4]); 754 tape->first_frame = be32_to_cpup((__be32 *)&buf[4]);
@@ -866,7 +845,8 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int size)
866 struct request *rq; 845 struct request *rq;
867 int ret; 846 int ret;
868 847
869 debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd); 848 ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x, size: %d", cmd, size);
849
870 BUG_ON(cmd != REQ_IDETAPE_READ && cmd != REQ_IDETAPE_WRITE); 850 BUG_ON(cmd != REQ_IDETAPE_READ && cmd != REQ_IDETAPE_WRITE);
871 BUG_ON(size < 0 || size % tape->blk_size); 851 BUG_ON(size < 0 || size % tape->blk_size);
872 852
@@ -1029,7 +1009,7 @@ static int idetape_rewind_tape(ide_drive_t *drive)
1029 struct ide_atapi_pc pc; 1009 struct ide_atapi_pc pc;
1030 int ret; 1010 int ret;
1031 1011
1032 debug_log(DBG_SENSE, "Enter %s\n", __func__); 1012 ide_debug_log(IDE_DBG_FUNC, "enter");
1033 1013
1034 idetape_create_rewind_cmd(drive, &pc); 1014 idetape_create_rewind_cmd(drive, &pc);
1035 ret = ide_queue_pc_tail(drive, disk, &pc, NULL, 0); 1015 ret = ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
@@ -1055,7 +1035,7 @@ static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd,
1055 int nr_stages; 1035 int nr_stages;
1056 } config; 1036 } config;
1057 1037
1058 debug_log(DBG_PROCS, "Enter %s\n", __func__); 1038 ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%04x", cmd);
1059 1039
1060 switch (cmd) { 1040 switch (cmd) {
1061 case 0x0340: 1041 case 0x0340:
@@ -1085,6 +1065,9 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
1085 int retval, count = 0; 1065 int retval, count = 0;
1086 int sprev = !!(tape->caps[4] & 0x20); 1066 int sprev = !!(tape->caps[4] & 0x20);
1087 1067
1068
1069 ide_debug_log(IDE_DBG_FUNC, "mt_op: %d, mt_count: %d", mt_op, mt_count);
1070
1088 if (mt_count == 0) 1071 if (mt_count == 0)
1089 return 0; 1072 return 0;
1090 if (MTBSF == mt_op || MTBSFM == mt_op) { 1073 if (MTBSF == mt_op || MTBSFM == mt_op) {
@@ -1148,7 +1131,7 @@ static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
1148 ssize_t ret = 0; 1131 ssize_t ret = 0;
1149 int rc; 1132 int rc;
1150 1133
1151 debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count); 1134 ide_debug_log(IDE_DBG_FUNC, "count %Zd", count);
1152 1135
1153 if (tape->chrdev_dir != IDETAPE_DIR_READ) { 1136 if (tape->chrdev_dir != IDETAPE_DIR_READ) {
1154 if (test_bit(ilog2(IDE_AFLAG_DETECT_BS), &drive->atapi_flags)) 1137 if (test_bit(ilog2(IDE_AFLAG_DETECT_BS), &drive->atapi_flags))
@@ -1187,8 +1170,6 @@ static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
1187 } 1170 }
1188 1171
1189 if (!done && test_bit(ilog2(IDE_AFLAG_FILEMARK), &drive->atapi_flags)) { 1172 if (!done && test_bit(ilog2(IDE_AFLAG_FILEMARK), &drive->atapi_flags)) {
1190 debug_log(DBG_SENSE, "%s: spacing over filemark\n", tape->name);
1191
1192 idetape_space_over_filemarks(drive, MTFSF, 1); 1173 idetape_space_over_filemarks(drive, MTFSF, 1);
1193 return 0; 1174 return 0;
1194 } 1175 }
@@ -1209,7 +1190,7 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
1209 if (tape->write_prot) 1190 if (tape->write_prot)
1210 return -EACCES; 1191 return -EACCES;
1211 1192
1212 debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count); 1193 ide_debug_log(IDE_DBG_FUNC, "count %Zd", count);
1213 1194
1214 /* Initialize write operation */ 1195 /* Initialize write operation */
1215 rc = idetape_init_rw(drive, IDETAPE_DIR_WRITE); 1196 rc = idetape_init_rw(drive, IDETAPE_DIR_WRITE);
@@ -1273,8 +1254,8 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
1273 struct ide_atapi_pc pc; 1254 struct ide_atapi_pc pc;
1274 int i, retval; 1255 int i, retval;
1275 1256
1276 debug_log(DBG_ERR, "Handling MTIOCTOP ioctl: mt_op=%d, mt_count=%d\n", 1257 ide_debug_log(IDE_DBG_FUNC, "MTIOCTOP ioctl: mt_op: %d, mt_count: %d",
1277 mt_op, mt_count); 1258 mt_op, mt_count);
1278 1259
1279 switch (mt_op) { 1260 switch (mt_op) {
1280 case MTFSF: 1261 case MTFSF:
@@ -1393,7 +1374,7 @@ static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
1393 int block_offset = 0, position = tape->first_frame; 1374 int block_offset = 0, position = tape->first_frame;
1394 void __user *argp = (void __user *)arg; 1375 void __user *argp = (void __user *)arg;
1395 1376
1396 debug_log(DBG_CHRDEV, "Enter %s, cmd=%u\n", __func__, cmd); 1377 ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x", cmd);
1397 1378
1398 if (tape->chrdev_dir == IDETAPE_DIR_WRITE) { 1379 if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
1399 ide_tape_flush_merge_buffer(drive); 1380 ide_tape_flush_merge_buffer(drive);
@@ -1461,6 +1442,9 @@ static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive)
1461 (buf[4 + 6] << 8) + 1442 (buf[4 + 6] << 8) +
1462 buf[4 + 7]; 1443 buf[4 + 7];
1463 tape->drv_write_prot = (buf[2] & 0x80) >> 7; 1444 tape->drv_write_prot = (buf[2] & 0x80) >> 7;
1445
1446 ide_debug_log(IDE_DBG_FUNC, "blk_size: %d, write_prot: %d",
1447 tape->blk_size, tape->drv_write_prot);
1464} 1448}
1465 1449
1466static int idetape_chrdev_open(struct inode *inode, struct file *filp) 1450static int idetape_chrdev_open(struct inode *inode, struct file *filp)
@@ -1480,7 +1464,10 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
1480 return -ENXIO; 1464 return -ENXIO;
1481 } 1465 }
1482 1466
1483 debug_log(DBG_CHRDEV, "Enter %s\n", __func__); 1467 drive = tape->drive;
1468 filp->private_data = tape;
1469
1470 ide_debug_log(IDE_DBG_FUNC, "enter");
1484 1471
1485 /* 1472 /*
1486 * We really want to do nonseekable_open(inode, filp); here, but some 1473 * We really want to do nonseekable_open(inode, filp); here, but some
@@ -1489,9 +1476,6 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
1489 */ 1476 */
1490 filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE); 1477 filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE);
1491 1478
1492 drive = tape->drive;
1493
1494 filp->private_data = tape;
1495 1479
1496 if (test_and_set_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags)) { 1480 if (test_and_set_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags)) {
1497 retval = -EBUSY; 1481 retval = -EBUSY;
@@ -1570,7 +1554,7 @@ static int idetape_chrdev_release(struct inode *inode, struct file *filp)
1570 lock_kernel(); 1554 lock_kernel();
1571 tape = drive->driver_data; 1555 tape = drive->driver_data;
1572 1556
1573 debug_log(DBG_CHRDEV, "Enter %s\n", __func__); 1557 ide_debug_log(IDE_DBG_FUNC, "enter");
1574 1558
1575 if (tape->chrdev_dir == IDETAPE_DIR_WRITE) 1559 if (tape->chrdev_dir == IDETAPE_DIR_WRITE)
1576 idetape_write_release(drive, minor); 1560 idetape_write_release(drive, minor);
@@ -1707,7 +1691,6 @@ static int divf_buffer_size(ide_drive_t *drive) { return 1024; }
1707 1691
1708ide_devset_rw_flag(dsc_overlap, IDE_DFLAG_DSC_OVERLAP); 1692ide_devset_rw_flag(dsc_overlap, IDE_DFLAG_DSC_OVERLAP);
1709 1693
1710ide_tape_devset_rw_field(debug_mask, debug_mask);
1711ide_tape_devset_rw_field(tdsc, best_dsc_rw_freq); 1694ide_tape_devset_rw_field(tdsc, best_dsc_rw_freq);
1712 1695
1713ide_tape_devset_r_field(avg_speed, avg_speed); 1696ide_tape_devset_r_field(avg_speed, avg_speed);
@@ -1719,7 +1702,6 @@ static const struct ide_proc_devset idetape_settings[] = {
1719 __IDE_PROC_DEVSET(avg_speed, 0, 0xffff, NULL, NULL), 1702 __IDE_PROC_DEVSET(avg_speed, 0, 0xffff, NULL, NULL),
1720 __IDE_PROC_DEVSET(buffer, 0, 0xffff, NULL, divf_buffer), 1703 __IDE_PROC_DEVSET(buffer, 0, 0xffff, NULL, divf_buffer),
1721 __IDE_PROC_DEVSET(buffer_size, 0, 0xffff, NULL, divf_buffer_size), 1704 __IDE_PROC_DEVSET(buffer_size, 0, 0xffff, NULL, divf_buffer_size),
1722 __IDE_PROC_DEVSET(debug_mask, 0, 0xffff, NULL, NULL),
1723 __IDE_PROC_DEVSET(dsc_overlap, 0, 1, NULL, NULL), 1705 __IDE_PROC_DEVSET(dsc_overlap, 0, 1, NULL, NULL),
1724 __IDE_PROC_DEVSET(speed, 0, 0xffff, NULL, NULL), 1706 __IDE_PROC_DEVSET(speed, 0, 0xffff, NULL, NULL),
1725 __IDE_PROC_DEVSET(tdsc, IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX, 1707 __IDE_PROC_DEVSET(tdsc, IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX,
@@ -1746,7 +1728,9 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
1746 int buffer_size; 1728 int buffer_size;
1747 u16 *ctl = (u16 *)&tape->caps[12]; 1729 u16 *ctl = (u16 *)&tape->caps[12];
1748 1730
1749 drive->pc_callback = ide_tape_callback; 1731 ide_debug_log(IDE_DBG_FUNC, "minor: %d", minor);
1732
1733 drive->pc_callback = ide_tape_callback;
1750 1734
1751 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP; 1735 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
1752 1736
@@ -1833,22 +1817,32 @@ static void ide_tape_release(struct device *dev)
1833} 1817}
1834 1818
1835#ifdef CONFIG_IDE_PROC_FS 1819#ifdef CONFIG_IDE_PROC_FS
1836static int proc_idetape_read_name 1820static int idetape_name_proc_show(struct seq_file *m, void *v)
1837 (char *page, char **start, off_t off, int count, int *eof, void *data)
1838{ 1821{
1839 ide_drive_t *drive = (ide_drive_t *) data; 1822 ide_drive_t *drive = (ide_drive_t *) m->private;
1840 idetape_tape_t *tape = drive->driver_data; 1823 idetape_tape_t *tape = drive->driver_data;
1841 char *out = page;
1842 int len;
1843 1824
1844 len = sprintf(out, "%s\n", tape->name); 1825 seq_printf(m, "%s\n", tape->name);
1845 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 1826 return 0;
1827}
1828
1829static int idetape_name_proc_open(struct inode *inode, struct file *file)
1830{
1831 return single_open(file, idetape_name_proc_show, PDE(inode)->data);
1846} 1832}
1847 1833
1834static const struct file_operations idetape_name_proc_fops = {
1835 .owner = THIS_MODULE,
1836 .open = idetape_name_proc_open,
1837 .read = seq_read,
1838 .llseek = seq_lseek,
1839 .release = single_release,
1840};
1841
1848static ide_proc_entry_t idetape_proc[] = { 1842static ide_proc_entry_t idetape_proc[] = {
1849 { "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL }, 1843 { "capacity", S_IFREG|S_IRUGO, &ide_capacity_proc_fops },
1850 { "name", S_IFREG|S_IRUGO, proc_idetape_read_name, NULL }, 1844 { "name", S_IFREG|S_IRUGO, &idetape_name_proc_fops },
1851 { NULL, 0, NULL, NULL } 1845 {}
1852}; 1846};
1853 1847
1854static ide_proc_entry_t *ide_tape_proc_entries(ide_drive_t *drive) 1848static ide_proc_entry_t *ide_tape_proc_entries(ide_drive_t *drive)
@@ -1932,7 +1926,9 @@ static int ide_tape_probe(ide_drive_t *drive)
1932 struct gendisk *g; 1926 struct gendisk *g;
1933 int minor; 1927 int minor;
1934 1928
1935 if (!strstr("ide-tape", drive->driver_req)) 1929 ide_debug_log(IDE_DBG_FUNC, "enter");
1930
1931 if (!strstr(DRV_NAME, drive->driver_req))
1936 goto failed; 1932 goto failed;
1937 1933
1938 if (drive->media != ide_tape) 1934 if (drive->media != ide_tape)
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 75b85a8cd2d4..cc8633cbe133 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -19,8 +19,8 @@
19#include <linux/hdreg.h> 19#include <linux/hdreg.h>
20#include <linux/ide.h> 20#include <linux/ide.h>
21#include <linux/scatterlist.h> 21#include <linux/scatterlist.h>
22#include <linux/uaccess.h>
22 23
23#include <asm/uaccess.h>
24#include <asm/io.h> 24#include <asm/io.h>
25 25
26void ide_tf_readback(ide_drive_t *drive, struct ide_cmd *cmd) 26void ide_tf_readback(ide_drive_t *drive, struct ide_cmd *cmd)
@@ -53,7 +53,7 @@ void ide_tf_dump(const char *s, struct ide_cmd *cmd)
53#endif 53#endif
54} 54}
55 55
56int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf) 56int taskfile_lib_get_identify(ide_drive_t *drive, u8 *buf)
57{ 57{
58 struct ide_cmd cmd; 58 struct ide_cmd cmd;
59 59
@@ -86,7 +86,7 @@ ide_startstop_t do_rw_taskfile(ide_drive_t *drive, struct ide_cmd *orig_cmd)
86 if (orig_cmd->protocol == ATA_PROT_PIO && 86 if (orig_cmd->protocol == ATA_PROT_PIO &&
87 (orig_cmd->tf_flags & IDE_TFLAG_MULTI_PIO) && 87 (orig_cmd->tf_flags & IDE_TFLAG_MULTI_PIO) &&
88 drive->mult_count == 0) { 88 drive->mult_count == 0) {
89 printk(KERN_ERR "%s: multimode not set!\n", drive->name); 89 pr_err("%s: multimode not set!\n", drive->name);
90 return ide_stopped; 90 return ide_stopped;
91 } 91 }
92 92
@@ -214,7 +214,7 @@ static u8 wait_drive_not_busy(ide_drive_t *drive)
214 } 214 }
215 215
216 if (stat & ATA_BUSY) 216 if (stat & ATA_BUSY)
217 printk(KERN_ERR "%s: drive still BUSY!\n", drive->name); 217 pr_err("%s: drive still BUSY!\n", drive->name);
218 218
219 return stat; 219 return stat;
220} 220}
@@ -225,8 +225,8 @@ void ide_pio_bytes(ide_drive_t *drive, struct ide_cmd *cmd,
225 ide_hwif_t *hwif = drive->hwif; 225 ide_hwif_t *hwif = drive->hwif;
226 struct scatterlist *sg = hwif->sg_table; 226 struct scatterlist *sg = hwif->sg_table;
227 struct scatterlist *cursg = cmd->cursg; 227 struct scatterlist *cursg = cmd->cursg;
228 unsigned long uninitialized_var(flags);
228 struct page *page; 229 struct page *page;
229 unsigned long flags;
230 unsigned int offset; 230 unsigned int offset;
231 u8 *buf; 231 u8 *buf;
232 232
@@ -236,6 +236,7 @@ void ide_pio_bytes(ide_drive_t *drive, struct ide_cmd *cmd,
236 236
237 while (len) { 237 while (len) {
238 unsigned nr_bytes = min(len, cursg->length - cmd->cursg_ofs); 238 unsigned nr_bytes = min(len, cursg->length - cmd->cursg_ofs);
239 int page_is_high;
239 240
240 if (nr_bytes > PAGE_SIZE) 241 if (nr_bytes > PAGE_SIZE)
241 nr_bytes = PAGE_SIZE; 242 nr_bytes = PAGE_SIZE;
@@ -247,7 +248,8 @@ void ide_pio_bytes(ide_drive_t *drive, struct ide_cmd *cmd,
247 page = nth_page(page, (offset >> PAGE_SHIFT)); 248 page = nth_page(page, (offset >> PAGE_SHIFT));
248 offset %= PAGE_SIZE; 249 offset %= PAGE_SIZE;
249 250
250 if (PageHighMem(page)) 251 page_is_high = PageHighMem(page);
252 if (page_is_high)
251 local_irq_save(flags); 253 local_irq_save(flags);
252 254
253 buf = kmap_atomic(page, KM_BIO_SRC_IRQ) + offset; 255 buf = kmap_atomic(page, KM_BIO_SRC_IRQ) + offset;
@@ -268,7 +270,7 @@ void ide_pio_bytes(ide_drive_t *drive, struct ide_cmd *cmd,
268 270
269 kunmap_atomic(buf, KM_BIO_SRC_IRQ); 271 kunmap_atomic(buf, KM_BIO_SRC_IRQ);
270 272
271 if (PageHighMem(page)) 273 if (page_is_high)
272 local_irq_restore(flags); 274 local_irq_restore(flags);
273 275
274 len -= nr_bytes; 276 len -= nr_bytes;
@@ -322,10 +324,17 @@ static void ide_error_cmd(ide_drive_t *drive, struct ide_cmd *cmd)
322void ide_finish_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat) 324void ide_finish_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat)
323{ 325{
324 struct request *rq = drive->hwif->rq; 326 struct request *rq = drive->hwif->rq;
325 u8 err = ide_read_error(drive); 327 u8 err = ide_read_error(drive), nsect = cmd->tf.nsect;
328 u8 set_xfer = !!(cmd->tf_flags & IDE_TFLAG_SET_XFER);
326 329
327 ide_complete_cmd(drive, cmd, stat, err); 330 ide_complete_cmd(drive, cmd, stat, err);
328 rq->errors = err; 331 rq->errors = err;
332
333 if (err == 0 && set_xfer) {
334 ide_set_xfer_rate(drive, nsect);
335 ide_driveid_update(drive);
336 }
337
329 ide_complete_rq(drive, err ? -EIO : 0, blk_rq_bytes(rq)); 338 ide_complete_rq(drive, err ? -EIO : 0, blk_rq_bytes(rq));
330} 339}
331 340
@@ -398,8 +407,7 @@ static ide_startstop_t pre_task_out_intr(ide_drive_t *drive,
398 407
399 if (ide_wait_stat(&startstop, drive, ATA_DRQ, 408 if (ide_wait_stat(&startstop, drive, ATA_DRQ,
400 drive->bad_wstat, WAIT_DRQ)) { 409 drive->bad_wstat, WAIT_DRQ)) {
401 printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n", 410 pr_err("%s: no DRQ after issuing %sWRITE%s\n", drive->name,
402 drive->name,
403 (cmd->tf_flags & IDE_TFLAG_MULTI_PIO) ? "MULT" : "", 411 (cmd->tf_flags & IDE_TFLAG_MULTI_PIO) ? "MULT" : "",
404 (drive->dev_flags & IDE_DFLAG_LBA48) ? "_EXT" : ""); 412 (drive->dev_flags & IDE_DFLAG_LBA48) ? "_EXT" : "");
405 return startstop; 413 return startstop;
@@ -449,7 +457,6 @@ put_req:
449 blk_put_request(rq); 457 blk_put_request(rq);
450 return error; 458 return error;
451} 459}
452
453EXPORT_SYMBOL(ide_raw_taskfile); 460EXPORT_SYMBOL(ide_raw_taskfile);
454 461
455int ide_no_data_taskfile(ide_drive_t *drive, struct ide_cmd *cmd) 462int ide_no_data_taskfile(ide_drive_t *drive, struct ide_cmd *cmd)
@@ -475,10 +482,9 @@ int ide_taskfile_ioctl(ide_drive_t *drive, unsigned long arg)
475 u16 nsect = 0; 482 u16 nsect = 0;
476 char __user *buf = (char __user *)arg; 483 char __user *buf = (char __user *)arg;
477 484
478// printk("IDE Taskfile ...\n");
479
480 req_task = kzalloc(tasksize, GFP_KERNEL); 485 req_task = kzalloc(tasksize, GFP_KERNEL);
481 if (req_task == NULL) return -ENOMEM; 486 if (req_task == NULL)
487 return -ENOMEM;
482 if (copy_from_user(req_task, buf, tasksize)) { 488 if (copy_from_user(req_task, buf, tasksize)) {
483 kfree(req_task); 489 kfree(req_task);
484 return -EFAULT; 490 return -EFAULT;
@@ -486,7 +492,7 @@ int ide_taskfile_ioctl(ide_drive_t *drive, unsigned long arg)
486 492
487 taskout = req_task->out_size; 493 taskout = req_task->out_size;
488 taskin = req_task->in_size; 494 taskin = req_task->in_size;
489 495
490 if (taskin > 65536 || taskout > 65536) { 496 if (taskin > 65536 || taskout > 65536) {
491 err = -EINVAL; 497 err = -EINVAL;
492 goto abort; 498 goto abort;
@@ -576,51 +582,49 @@ int ide_taskfile_ioctl(ide_drive_t *drive, unsigned long arg)
576 cmd.protocol = ATA_PROT_DMA; 582 cmd.protocol = ATA_PROT_DMA;
577 583
578 switch (req_task->data_phase) { 584 switch (req_task->data_phase) {
579 case TASKFILE_MULTI_OUT: 585 case TASKFILE_MULTI_OUT:
580 if (!drive->mult_count) { 586 if (!drive->mult_count) {
581 /* (hs): give up if multcount is not set */ 587 /* (hs): give up if multcount is not set */
582 printk(KERN_ERR "%s: %s Multimode Write " \ 588 pr_err("%s: %s Multimode Write multcount is not set\n",
583 "multcount is not set\n", 589 drive->name, __func__);
584 drive->name, __func__); 590 err = -EPERM;
585 err = -EPERM; 591 goto abort;
586 goto abort; 592 }
587 } 593 cmd.tf_flags |= IDE_TFLAG_MULTI_PIO;
588 cmd.tf_flags |= IDE_TFLAG_MULTI_PIO; 594 /* fall through */
589 /* fall through */ 595 case TASKFILE_OUT:
590 case TASKFILE_OUT: 596 cmd.protocol = ATA_PROT_PIO;
591 cmd.protocol = ATA_PROT_PIO; 597 /* fall through */
592 /* fall through */ 598 case TASKFILE_OUT_DMAQ:
593 case TASKFILE_OUT_DMAQ: 599 case TASKFILE_OUT_DMA:
594 case TASKFILE_OUT_DMA: 600 cmd.tf_flags |= IDE_TFLAG_WRITE;
595 cmd.tf_flags |= IDE_TFLAG_WRITE; 601 nsect = taskout / SECTOR_SIZE;
596 nsect = taskout / SECTOR_SIZE; 602 data_buf = outbuf;
597 data_buf = outbuf; 603 break;
598 break; 604 case TASKFILE_MULTI_IN:
599 case TASKFILE_MULTI_IN: 605 if (!drive->mult_count) {
600 if (!drive->mult_count) { 606 /* (hs): give up if multcount is not set */
601 /* (hs): give up if multcount is not set */ 607 pr_err("%s: %s Multimode Read multcount is not set\n",
602 printk(KERN_ERR "%s: %s Multimode Read failure " \ 608 drive->name, __func__);
603 "multcount is not set\n", 609 err = -EPERM;
604 drive->name, __func__);
605 err = -EPERM;
606 goto abort;
607 }
608 cmd.tf_flags |= IDE_TFLAG_MULTI_PIO;
609 /* fall through */
610 case TASKFILE_IN:
611 cmd.protocol = ATA_PROT_PIO;
612 /* fall through */
613 case TASKFILE_IN_DMAQ:
614 case TASKFILE_IN_DMA:
615 nsect = taskin / SECTOR_SIZE;
616 data_buf = inbuf;
617 break;
618 case TASKFILE_NO_DATA:
619 cmd.protocol = ATA_PROT_NODATA;
620 break;
621 default:
622 err = -EFAULT;
623 goto abort; 610 goto abort;
611 }
612 cmd.tf_flags |= IDE_TFLAG_MULTI_PIO;
613 /* fall through */
614 case TASKFILE_IN:
615 cmd.protocol = ATA_PROT_PIO;
616 /* fall through */
617 case TASKFILE_IN_DMAQ:
618 case TASKFILE_IN_DMA:
619 nsect = taskin / SECTOR_SIZE;
620 data_buf = inbuf;
621 break;
622 case TASKFILE_NO_DATA:
623 cmd.protocol = ATA_PROT_NODATA;
624 break;
625 default:
626 err = -EFAULT;
627 goto abort;
624 } 628 }
625 629
626 if (req_task->req_cmd == IDE_DRIVE_TASK_NO_DATA) 630 if (req_task->req_cmd == IDE_DRIVE_TASK_NO_DATA)
@@ -629,7 +633,7 @@ int ide_taskfile_ioctl(ide_drive_t *drive, unsigned long arg)
629 nsect = (cmd.hob.nsect << 8) | cmd.tf.nsect; 633 nsect = (cmd.hob.nsect << 8) | cmd.tf.nsect;
630 634
631 if (!nsect) { 635 if (!nsect) {
632 printk(KERN_ERR "%s: in/out command without data\n", 636 pr_err("%s: in/out command without data\n",
633 drive->name); 637 drive->name);
634 err = -EFAULT; 638 err = -EFAULT;
635 goto abort; 639 goto abort;
@@ -671,8 +675,6 @@ abort:
671 kfree(outbuf); 675 kfree(outbuf);
672 kfree(inbuf); 676 kfree(inbuf);
673 677
674// printk("IDE Taskfile ioctl ended. rc = %i\n", err);
675
676 return err; 678 return err;
677} 679}
678#endif 680#endif
diff --git a/drivers/ide/palm_bk3710.c b/drivers/ide/palm_bk3710.c
index 3c1dc0152153..f8eddf05ecb8 100644
--- a/drivers/ide/palm_bk3710.c
+++ b/drivers/ide/palm_bk3710.c
@@ -318,7 +318,7 @@ static int __init palm_bk3710_probe(struct platform_device *pdev)
318 int i, rc; 318 int i, rc;
319 struct ide_hw hw, *hws[] = { &hw }; 319 struct ide_hw hw, *hws[] = { &hw };
320 320
321 clk = clk_get(&pdev->dev, "IDECLK"); 321 clk = clk_get(&pdev->dev, NULL);
322 if (IS_ERR(clk)) 322 if (IS_ERR(clk))
323 return -ENODEV; 323 return -ENODEV;
324 324