aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ide')
-rw-r--r--drivers/ide/alim15x3.c10
-rw-r--r--drivers/ide/icside.c2
-rw-r--r--drivers/ide/ide-atapi.c183
-rw-r--r--drivers/ide/ide-cd.c152
-rw-r--r--drivers/ide/ide-cd.h4
-rw-r--r--drivers/ide/ide-disk.c11
-rw-r--r--drivers/ide/ide-dma.c22
-rw-r--r--drivers/ide/ide-floppy.c32
-rw-r--r--drivers/ide/ide-io.c61
-rw-r--r--drivers/ide/ide-ioctls.c1
-rw-r--r--drivers/ide/ide-iops.c21
-rw-r--r--drivers/ide/ide-lib.c29
-rw-r--r--drivers/ide/ide-park.c7
-rw-r--r--drivers/ide/ide-pci-generic.c11
-rw-r--r--drivers/ide/ide-pm.c38
-rw-r--r--drivers/ide/ide-probe.c9
-rw-r--r--drivers/ide/ide-tape.c742
-rw-r--r--drivers/ide/ide-taskfile.c20
-rw-r--r--drivers/ide/pdc202xx_old.c24
-rw-r--r--drivers/ide/piix.c1
-rw-r--r--drivers/ide/tc86c001.c2
-rw-r--r--drivers/ide/tx4939ide.c2
-rw-r--r--drivers/ide/via82cxxx.c2
23 files changed, 481 insertions, 905 deletions
diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
index 537da1cde16d..e59b6dee9ae2 100644
--- a/drivers/ide/alim15x3.c
+++ b/drivers/ide/alim15x3.c
@@ -402,27 +402,23 @@ static u8 ali_cable_detect(ide_hwif_t *hwif)
402 return cbl; 402 return cbl;
403} 403}
404 404
405#if !defined(CONFIG_SPARC64) && !defined(CONFIG_PPC) 405#ifndef CONFIG_SPARC64
406/** 406/**
407 * init_hwif_ali15x3 - Initialize the ALI IDE x86 stuff 407 * init_hwif_ali15x3 - Initialize the ALI IDE x86 stuff
408 * @hwif: interface to configure 408 * @hwif: interface to configure
409 * 409 *
410 * Obtain the IRQ tables for an ALi based IDE solution on the PC 410 * Obtain the IRQ tables for an ALi based IDE solution on the PC
411 * class platforms. This part of the code isn't applicable to the 411 * class platforms. This part of the code isn't applicable to the
412 * Sparc and PowerPC systems. 412 * Sparc systems.
413 */ 413 */
414 414
415static void __devinit init_hwif_ali15x3 (ide_hwif_t *hwif) 415static void __devinit init_hwif_ali15x3 (ide_hwif_t *hwif)
416{ 416{
417 struct pci_dev *dev = to_pci_dev(hwif->dev);
418 u8 ideic, inmir; 417 u8 ideic, inmir;
419 s8 irq_routing_table[] = { -1, 9, 3, 10, 4, 5, 7, 6, 418 s8 irq_routing_table[] = { -1, 9, 3, 10, 4, 5, 7, 6,
420 1, 11, 0, 12, 0, 14, 0, 15 }; 419 1, 11, 0, 12, 0, 14, 0, 15 };
421 int irq = -1; 420 int irq = -1;
422 421
423 if (dev->device == PCI_DEVICE_ID_AL_M5229)
424 hwif->irq = hwif->channel ? 15 : 14;
425
426 if (isa_dev) { 422 if (isa_dev) {
427 /* 423 /*
428 * read IDE interface control 424 * read IDE interface control
@@ -455,7 +451,7 @@ static void __devinit init_hwif_ali15x3 (ide_hwif_t *hwif)
455} 451}
456#else 452#else
457#define init_hwif_ali15x3 NULL 453#define init_hwif_ali15x3 NULL
458#endif /* !defined(CONFIG_SPARC64) && !defined(CONFIG_PPC) */ 454#endif /* CONFIG_SPARC64 */
459 455
460/** 456/**
461 * init_dma_ali15x3 - set up DMA on ALi15x3 457 * init_dma_ali15x3 - set up DMA on ALi15x3
diff --git a/drivers/ide/icside.c b/drivers/ide/icside.c
index 4e16ce68b063..36da913cc553 100644
--- a/drivers/ide/icside.c
+++ b/drivers/ide/icside.c
@@ -466,7 +466,7 @@ icside_register_v6(struct icside_state *state, struct expansion_card *ec)
466 struct ide_host *host; 466 struct ide_host *host;
467 unsigned int sel = 0; 467 unsigned int sel = 0;
468 int ret; 468 int ret;
469 hw_regs_t hw[2], *hws[] = { &hw[0], NULL, NULL, NULL }; 469 hw_regs_t hw[2], *hws[] = { &hw[0], &hw[1], NULL, NULL };
470 struct ide_port_info d = icside_v6_port_info; 470 struct ide_port_info d = icside_v6_port_info;
471 471
472 ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0); 472 ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c
index 7201b176d75b..757e5956b132 100644
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -80,34 +80,6 @@ void ide_init_pc(struct ide_atapi_pc *pc)
80EXPORT_SYMBOL_GPL(ide_init_pc); 80EXPORT_SYMBOL_GPL(ide_init_pc);
81 81
82/* 82/*
83 * Generate a new packet command request in front of the request queue, before
84 * the current request, so that it will be processed immediately, on the next
85 * pass through the driver.
86 */
87static void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
88 struct ide_atapi_pc *pc, struct request *rq)
89{
90 blk_rq_init(NULL, rq);
91 rq->cmd_type = REQ_TYPE_SPECIAL;
92 rq->cmd_flags |= REQ_PREEMPT;
93 rq->buffer = (char *)pc;
94 rq->rq_disk = disk;
95
96 if (pc->req_xfer) {
97 rq->data = pc->buf;
98 rq->data_len = pc->req_xfer;
99 }
100
101 memcpy(rq->cmd, pc->c, 12);
102 if (drive->media == ide_tape)
103 rq->cmd[13] = REQ_IDETAPE_PC1;
104
105 drive->hwif->rq = NULL;
106
107 elv_add_request(drive->queue, rq, ELEVATOR_INSERT_FRONT, 0);
108}
109
110/*
111 * Add a special packet command request to the tail of the request queue, 83 * Add a special packet command request to the tail of the request queue,
112 * and wait for it to be serviced. 84 * and wait for it to be serviced.
113 */ 85 */
@@ -119,19 +91,21 @@ int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk,
119 91
120 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 92 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
121 rq->cmd_type = REQ_TYPE_SPECIAL; 93 rq->cmd_type = REQ_TYPE_SPECIAL;
122 rq->buffer = (char *)pc; 94 rq->special = (char *)pc;
123 95
124 if (pc->req_xfer) { 96 if (pc->req_xfer) {
125 rq->data = pc->buf; 97 error = blk_rq_map_kern(drive->queue, rq, pc->buf, pc->req_xfer,
126 rq->data_len = pc->req_xfer; 98 GFP_NOIO);
99 if (error)
100 goto put_req;
127 } 101 }
128 102
129 memcpy(rq->cmd, pc->c, 12); 103 memcpy(rq->cmd, pc->c, 12);
130 if (drive->media == ide_tape) 104 if (drive->media == ide_tape)
131 rq->cmd[13] = REQ_IDETAPE_PC1; 105 rq->cmd[13] = REQ_IDETAPE_PC1;
132 error = blk_execute_rq(drive->queue, disk, rq, 0); 106 error = blk_execute_rq(drive->queue, disk, rq, 0);
107put_req:
133 blk_put_request(rq); 108 blk_put_request(rq);
134
135 return error; 109 return error;
136} 110}
137EXPORT_SYMBOL_GPL(ide_queue_pc_tail); 111EXPORT_SYMBOL_GPL(ide_queue_pc_tail);
@@ -191,20 +165,113 @@ void ide_create_request_sense_cmd(ide_drive_t *drive, struct ide_atapi_pc *pc)
191} 165}
192EXPORT_SYMBOL_GPL(ide_create_request_sense_cmd); 166EXPORT_SYMBOL_GPL(ide_create_request_sense_cmd);
193 167
168void ide_prep_sense(ide_drive_t *drive, struct request *rq)
169{
170 struct request_sense *sense = &drive->sense_data;
171 struct request *sense_rq = &drive->sense_rq;
172 unsigned int cmd_len, sense_len;
173 int err;
174
175 debug_log("%s: enter\n", __func__);
176
177 switch (drive->media) {
178 case ide_floppy:
179 cmd_len = 255;
180 sense_len = 18;
181 break;
182 case ide_tape:
183 cmd_len = 20;
184 sense_len = 20;
185 break;
186 default:
187 cmd_len = 18;
188 sense_len = 18;
189 }
190
191 BUG_ON(sense_len > sizeof(*sense));
192
193 if (blk_sense_request(rq) || drive->sense_rq_armed)
194 return;
195
196 memset(sense, 0, sizeof(*sense));
197
198 blk_rq_init(rq->q, sense_rq);
199
200 err = blk_rq_map_kern(drive->queue, sense_rq, sense, sense_len,
201 GFP_NOIO);
202 if (unlikely(err)) {
203 if (printk_ratelimit())
204 printk(KERN_WARNING "%s: failed to map sense buffer\n",
205 drive->name);
206 return;
207 }
208
209 sense_rq->rq_disk = rq->rq_disk;
210 sense_rq->cmd[0] = GPCMD_REQUEST_SENSE;
211 sense_rq->cmd[4] = cmd_len;
212 sense_rq->cmd_type = REQ_TYPE_SENSE;
213 sense_rq->cmd_flags |= REQ_PREEMPT;
214
215 if (drive->media == ide_tape)
216 sense_rq->cmd[13] = REQ_IDETAPE_PC1;
217
218 drive->sense_rq_armed = true;
219}
220EXPORT_SYMBOL_GPL(ide_prep_sense);
221
222int ide_queue_sense_rq(ide_drive_t *drive, void *special)
223{
224 /* deferred failure from ide_prep_sense() */
225 if (!drive->sense_rq_armed) {
226 printk(KERN_WARNING "%s: failed queue sense request\n",
227 drive->name);
228 return -ENOMEM;
229 }
230
231 drive->sense_rq.special = special;
232 drive->sense_rq_armed = false;
233
234 drive->hwif->rq = NULL;
235
236 elv_add_request(drive->queue, &drive->sense_rq,
237 ELEVATOR_INSERT_FRONT, 0);
238 return 0;
239}
240EXPORT_SYMBOL_GPL(ide_queue_sense_rq);
241
194/* 242/*
195 * Called when an error was detected during the last packet command. 243 * Called when an error was detected during the last packet command.
196 * We queue a request sense packet command in the head of the request list. 244 * We queue a request sense packet command at the head of the request
245 * queue.
197 */ 246 */
198void ide_retry_pc(ide_drive_t *drive, struct gendisk *disk) 247void ide_retry_pc(ide_drive_t *drive)
199{ 248{
200 struct request *rq = &drive->request_sense_rq; 249 struct request *failed_rq = drive->hwif->rq;
250 struct request *sense_rq = &drive->sense_rq;
201 struct ide_atapi_pc *pc = &drive->request_sense_pc; 251 struct ide_atapi_pc *pc = &drive->request_sense_pc;
202 252
203 (void)ide_read_error(drive); 253 (void)ide_read_error(drive);
204 ide_create_request_sense_cmd(drive, pc); 254
255 /* init pc from sense_rq */
256 ide_init_pc(pc);
257 memcpy(pc->c, sense_rq->cmd, 12);
258 pc->buf = bio_data(sense_rq->bio); /* pointer to mapped address */
259 pc->req_xfer = blk_rq_bytes(sense_rq);
260
205 if (drive->media == ide_tape) 261 if (drive->media == ide_tape)
206 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags); 262 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
207 ide_queue_pc_head(drive, disk, pc, rq); 263
264 /*
265 * Push back the failed request and put request sense on top
266 * of it. The failed command will be retried after sense data
267 * is acquired.
268 */
269 blk_requeue_request(failed_rq->q, failed_rq);
270 drive->hwif->rq = NULL;
271 if (ide_queue_sense_rq(drive, pc)) {
272 blk_start_request(failed_rq);
273 ide_complete_rq(drive, -EIO, blk_rq_bytes(failed_rq));
274 }
208} 275}
209EXPORT_SYMBOL_GPL(ide_retry_pc); 276EXPORT_SYMBOL_GPL(ide_retry_pc);
210 277
@@ -246,7 +313,7 @@ int ide_cd_get_xferlen(struct request *rq)
246 return 32768; 313 return 32768;
247 else if (blk_sense_request(rq) || blk_pc_request(rq) || 314 else if (blk_sense_request(rq) || blk_pc_request(rq) ||
248 rq->cmd_type == REQ_TYPE_ATA_PC) 315 rq->cmd_type == REQ_TYPE_ATA_PC)
249 return rq->data_len; 316 return blk_rq_bytes(rq);
250 else 317 else
251 return 0; 318 return 0;
252} 319}
@@ -276,7 +343,6 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
276 struct ide_cmd *cmd = &hwif->cmd; 343 struct ide_cmd *cmd = &hwif->cmd;
277 struct request *rq = hwif->rq; 344 struct request *rq = hwif->rq;
278 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 345 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
279 xfer_func_t *xferfunc;
280 unsigned int timeout, done; 346 unsigned int timeout, done;
281 u16 bcount; 347 u16 bcount;
282 u8 stat, ireason, dsc = 0; 348 u8 stat, ireason, dsc = 0;
@@ -303,18 +369,14 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
303 drive->name, rq_data_dir(pc->rq) 369 drive->name, rq_data_dir(pc->rq)
304 ? "write" : "read"); 370 ? "write" : "read");
305 pc->flags |= PC_FLAG_DMA_ERROR; 371 pc->flags |= PC_FLAG_DMA_ERROR;
306 } else { 372 } else
307 pc->xferred = pc->req_xfer; 373 pc->xferred = pc->req_xfer;
308 if (drive->pc_update_buffers)
309 drive->pc_update_buffers(drive, pc);
310 }
311 debug_log("%s: DMA finished\n", drive->name); 374 debug_log("%s: DMA finished\n", drive->name);
312 } 375 }
313 376
314 /* No more interrupts */ 377 /* No more interrupts */
315 if ((stat & ATA_DRQ) == 0) { 378 if ((stat & ATA_DRQ) == 0) {
316 int uptodate, error; 379 int uptodate, error;
317 unsigned int done;
318 380
319 debug_log("Packet command completed, %d bytes transferred\n", 381 debug_log("Packet command completed, %d bytes transferred\n",
320 pc->xferred); 382 pc->xferred);
@@ -343,7 +405,7 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
343 debug_log("[cmd %x]: check condition\n", rq->cmd[0]); 405 debug_log("[cmd %x]: check condition\n", rq->cmd[0]);
344 406
345 /* Retry operation */ 407 /* Retry operation */
346 ide_retry_pc(drive, rq->rq_disk); 408 ide_retry_pc(drive);
347 409
348 /* queued, but not started */ 410 /* queued, but not started */
349 return ide_stopped; 411 return ide_stopped;
@@ -353,6 +415,12 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
353 if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0) 415 if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0)
354 dsc = 1; 416 dsc = 1;
355 417
418 /*
419 * ->pc_callback() might change rq->data_len for
420 * residual count, cache total length.
421 */
422 done = blk_rq_bytes(rq);
423
356 /* Command finished - Call the callback function */ 424 /* Command finished - Call the callback function */
357 uptodate = drive->pc_callback(drive, dsc); 425 uptodate = drive->pc_callback(drive, dsc);
358 426
@@ -361,7 +429,6 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
361 429
362 if (blk_special_request(rq)) { 430 if (blk_special_request(rq)) {
363 rq->errors = 0; 431 rq->errors = 0;
364 done = blk_rq_bytes(rq);
365 error = 0; 432 error = 0;
366 } else { 433 } else {
367 434
@@ -370,15 +437,10 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
370 rq->errors = -EIO; 437 rq->errors = -EIO;
371 } 438 }
372 439
373 if (drive->media == ide_tape)
374 done = ide_rq_bytes(rq); /* FIXME */
375 else
376 done = blk_rq_bytes(rq);
377
378 error = uptodate ? 0 : -EIO; 440 error = uptodate ? 0 : -EIO;
379 } 441 }
380 442
381 ide_complete_rq(drive, error, done); 443 ide_complete_rq(drive, error, blk_rq_bytes(rq));
382 return ide_stopped; 444 return ide_stopped;
383 } 445 }
384 446
@@ -407,21 +469,11 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
407 return ide_do_reset(drive); 469 return ide_do_reset(drive);
408 } 470 }
409 471
410 xferfunc = write ? tp_ops->output_data : tp_ops->input_data; 472 done = min_t(unsigned int, bcount, cmd->nleft);
411 473 ide_pio_bytes(drive, cmd, write, done);
412 if (drive->media == ide_floppy && pc->buf == NULL) {
413 done = min_t(unsigned int, bcount, cmd->nleft);
414 ide_pio_bytes(drive, cmd, write, done);
415 } else if (drive->media == ide_tape && pc->bh) {
416 done = drive->pc_io_buffers(drive, pc, bcount, write);
417 } else {
418 done = min_t(unsigned int, bcount, pc->req_xfer - pc->xferred);
419 xferfunc(drive, NULL, pc->cur_pos, done);
420 }
421 474
422 /* Update the current position */ 475 /* Update transferred byte count */
423 pc->xferred += done; 476 pc->xferred += done;
424 pc->cur_pos += done;
425 477
426 bcount -= done; 478 bcount -= done;
427 479
@@ -599,7 +651,6 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_cmd *cmd)
599 651
600 /* We haven't transferred any data yet */ 652 /* We haven't transferred any data yet */
601 pc->xferred = 0; 653 pc->xferred = 0;
602 pc->cur_pos = pc->buf;
603 654
604 valid_tf = IDE_VALID_DEVICE; 655 valid_tf = IDE_VALID_DEVICE;
605 bcount = ((drive->media == ide_tape) ? 656 bcount = ((drive->media == ide_tape) ?
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 925eb9e245d1..424140c6c400 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -182,7 +182,7 @@ static void cdrom_analyze_sense_data(ide_drive_t *drive,
182 (sense->information[2] << 8) | 182 (sense->information[2] << 8) |
183 (sense->information[3]); 183 (sense->information[3]);
184 184
185 if (drive->queue->hardsect_size == 2048) 185 if (queue_logical_block_size(drive->queue) == 2048)
186 /* device sector size is 2K */ 186 /* device sector size is 2K */
187 sector <<= 2; 187 sector <<= 2;
188 188
@@ -206,54 +206,25 @@ static void cdrom_analyze_sense_data(ide_drive_t *drive,
206 ide_cd_log_error(drive->name, failed_command, sense); 206 ide_cd_log_error(drive->name, failed_command, sense);
207} 207}
208 208
209static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
210 struct request *failed_command)
211{
212 struct cdrom_info *info = drive->driver_data;
213 struct request *rq = &drive->request_sense_rq;
214
215 ide_debug_log(IDE_DBG_SENSE, "enter");
216
217 if (sense == NULL)
218 sense = &info->sense_data;
219
220 /* stuff the sense request in front of our current request */
221 blk_rq_init(NULL, rq);
222 rq->cmd_type = REQ_TYPE_ATA_PC;
223 rq->rq_disk = info->disk;
224
225 rq->data = sense;
226 rq->cmd[0] = GPCMD_REQUEST_SENSE;
227 rq->cmd[4] = 18;
228 rq->data_len = 18;
229
230 rq->cmd_type = REQ_TYPE_SENSE;
231 rq->cmd_flags |= REQ_PREEMPT;
232
233 /* NOTE! Save the failed command in "rq->buffer" */
234 rq->buffer = (void *) failed_command;
235
236 if (failed_command)
237 ide_debug_log(IDE_DBG_SENSE, "failed_cmd: 0x%x",
238 failed_command->cmd[0]);
239
240 drive->hwif->rq = NULL;
241
242 elv_add_request(drive->queue, rq, ELEVATOR_INSERT_FRONT, 0);
243}
244
245static void ide_cd_complete_failed_rq(ide_drive_t *drive, struct request *rq) 209static void ide_cd_complete_failed_rq(ide_drive_t *drive, struct request *rq)
246{ 210{
247 /* 211 /*
248 * For REQ_TYPE_SENSE, "rq->buffer" points to the original 212 * For REQ_TYPE_SENSE, "rq->special" points to the original
249 * failed request 213 * failed request. Also, the sense data should be read
214 * directly from rq which might be different from the original
215 * sense buffer if it got copied during mapping.
250 */ 216 */
251 struct request *failed = (struct request *)rq->buffer; 217 struct request *failed = (struct request *)rq->special;
252 struct cdrom_info *info = drive->driver_data; 218 void *sense = bio_data(rq->bio);
253 void *sense = &info->sense_data;
254 219
255 if (failed) { 220 if (failed) {
256 if (failed->sense) { 221 if (failed->sense) {
222 /*
223 * Sense is always read into drive->sense_data.
224 * Copy back if the failed request has its
225 * sense pointer set.
226 */
227 memcpy(failed->sense, sense, 18);
257 sense = failed->sense; 228 sense = failed->sense;
258 failed->sense_len = rq->sense_len; 229 failed->sense_len = rq->sense_len;
259 } 230 }
@@ -428,22 +399,13 @@ static int cdrom_decode_status(ide_drive_t *drive, u8 stat)
428 399
429 /* if we got a CHECK_CONDITION status, queue a request sense command */ 400 /* if we got a CHECK_CONDITION status, queue a request sense command */
430 if (stat & ATA_ERR) 401 if (stat & ATA_ERR)
431 cdrom_queue_request_sense(drive, NULL, NULL); 402 return ide_queue_sense_rq(drive, NULL) ? 2 : 1;
432 return 1; 403 return 1;
433 404
434end_request: 405end_request:
435 if (stat & ATA_ERR) { 406 if (stat & ATA_ERR) {
436 struct request_queue *q = drive->queue;
437 unsigned long flags;
438
439 spin_lock_irqsave(q->queue_lock, flags);
440 blkdev_dequeue_request(rq);
441 spin_unlock_irqrestore(q->queue_lock, flags);
442
443 hwif->rq = NULL; 407 hwif->rq = NULL;
444 408 return ide_queue_sense_rq(drive, rq) ? 2 : 1;
445 cdrom_queue_request_sense(drive, rq->sense, rq);
446 return 1;
447 } else 409 } else
448 return 2; 410 return 2;
449} 411}
@@ -503,14 +465,8 @@ static void ide_cd_request_sense_fixup(ide_drive_t *drive, struct ide_cmd *cmd)
503 * and some drives don't send them. Sigh. 465 * and some drives don't send them. Sigh.
504 */ 466 */
505 if (rq->cmd[0] == GPCMD_REQUEST_SENSE && 467 if (rq->cmd[0] == GPCMD_REQUEST_SENSE &&
506 cmd->nleft > 0 && cmd->nleft <= 5) { 468 cmd->nleft > 0 && cmd->nleft <= 5)
507 unsigned int ofs = cmd->nbytes - cmd->nleft; 469 cmd->nleft = 0;
508
509 while (cmd->nleft > 0) {
510 *((u8 *)rq->data + ofs++) = 0;
511 cmd->nleft--;
512 }
513 }
514} 470}
515 471
516int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd, 472int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd,
@@ -543,14 +499,18 @@ int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd,
543 rq->cmd_flags |= cmd_flags; 499 rq->cmd_flags |= cmd_flags;
544 rq->timeout = timeout; 500 rq->timeout = timeout;
545 if (buffer) { 501 if (buffer) {
546 rq->data = buffer; 502 error = blk_rq_map_kern(drive->queue, rq, buffer,
547 rq->data_len = *bufflen; 503 *bufflen, GFP_NOIO);
504 if (error) {
505 blk_put_request(rq);
506 return error;
507 }
548 } 508 }
549 509
550 error = blk_execute_rq(drive->queue, info->disk, rq, 0); 510 error = blk_execute_rq(drive->queue, info->disk, rq, 0);
551 511
552 if (buffer) 512 if (buffer)
553 *bufflen = rq->data_len; 513 *bufflen = rq->resid_len;
554 514
555 flags = rq->cmd_flags; 515 flags = rq->cmd_flags;
556 blk_put_request(rq); 516 blk_put_request(rq);
@@ -608,7 +568,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
608 struct request *rq = hwif->rq; 568 struct request *rq = hwif->rq;
609 ide_expiry_t *expiry = NULL; 569 ide_expiry_t *expiry = NULL;
610 int dma_error = 0, dma, thislen, uptodate = 0; 570 int dma_error = 0, dma, thislen, uptodate = 0;
611 int write = (rq_data_dir(rq) == WRITE) ? 1 : 0, rc = 0, nsectors; 571 int write = (rq_data_dir(rq) == WRITE) ? 1 : 0, rc = 0;
612 int sense = blk_sense_request(rq); 572 int sense = blk_sense_request(rq);
613 unsigned int timeout; 573 unsigned int timeout;
614 u16 len; 574 u16 len;
@@ -738,13 +698,8 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
738 698
739out_end: 699out_end:
740 if (blk_pc_request(rq) && rc == 0) { 700 if (blk_pc_request(rq) && rc == 0) {
741 unsigned int dlen = rq->data_len; 701 rq->resid_len = 0;
742 702 blk_end_request_all(rq, 0);
743 rq->data_len = 0;
744
745 if (blk_end_request(rq, 0, dlen))
746 BUG();
747
748 hwif->rq = NULL; 703 hwif->rq = NULL;
749 } else { 704 } else {
750 if (sense && uptodate) 705 if (sense && uptodate)
@@ -762,21 +717,13 @@ out_end:
762 ide_cd_error_cmd(drive, cmd); 717 ide_cd_error_cmd(drive, cmd);
763 718
764 /* make sure it's fully ended */ 719 /* make sure it's fully ended */
765 if (blk_pc_request(rq))
766 nsectors = (rq->data_len + 511) >> 9;
767 else
768 nsectors = rq->hard_nr_sectors;
769
770 if (nsectors == 0)
771 nsectors = 1;
772
773 if (blk_fs_request(rq) == 0) { 720 if (blk_fs_request(rq) == 0) {
774 rq->data_len -= (cmd->nbytes - cmd->nleft); 721 rq->resid_len -= cmd->nbytes - cmd->nleft;
775 if (uptodate == 0 && (cmd->tf_flags & IDE_TFLAG_WRITE)) 722 if (uptodate == 0 && (cmd->tf_flags & IDE_TFLAG_WRITE))
776 rq->data_len += cmd->last_xfer_len; 723 rq->resid_len += cmd->last_xfer_len;
777 } 724 }
778 725
779 ide_complete_rq(drive, uptodate ? 0 : -EIO, nsectors << 9); 726 ide_complete_rq(drive, uptodate ? 0 : -EIO, blk_rq_bytes(rq));
780 727
781 if (sense && rc == 2) 728 if (sense && rc == 2)
782 ide_error(drive, "request sense failure", stat); 729 ide_error(drive, "request sense failure", stat);
@@ -790,7 +737,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
790 struct request_queue *q = drive->queue; 737 struct request_queue *q = drive->queue;
791 int write = rq_data_dir(rq) == WRITE; 738 int write = rq_data_dir(rq) == WRITE;
792 unsigned short sectors_per_frame = 739 unsigned short sectors_per_frame =
793 queue_hardsect_size(q) >> SECTOR_BITS; 740 queue_logical_block_size(q) >> SECTOR_BITS;
794 741
795 ide_debug_log(IDE_DBG_RQ, "rq->cmd[0]: 0x%x, rq->cmd_flags: 0x%x, " 742 ide_debug_log(IDE_DBG_RQ, "rq->cmd[0]: 0x%x, rq->cmd_flags: 0x%x, "
796 "secs_per_frame: %u", 743 "secs_per_frame: %u",
@@ -809,8 +756,8 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
809 } 756 }
810 757
811 /* fs requests *must* be hardware frame aligned */ 758 /* fs requests *must* be hardware frame aligned */
812 if ((rq->nr_sectors & (sectors_per_frame - 1)) || 759 if ((blk_rq_sectors(rq) & (sectors_per_frame - 1)) ||
813 (rq->sector & (sectors_per_frame - 1))) 760 (blk_rq_pos(rq) & (sectors_per_frame - 1)))
814 return ide_stopped; 761 return ide_stopped;
815 762
816 /* use DMA, if possible */ 763 /* use DMA, if possible */
@@ -838,15 +785,10 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
838 drive->dma = 0; 785 drive->dma = 0;
839 786
840 /* sg request */ 787 /* sg request */
841 if (rq->bio || ((rq->cmd_type == REQ_TYPE_ATA_PC) && rq->data_len)) { 788 if (rq->bio) {
842 struct request_queue *q = drive->queue; 789 struct request_queue *q = drive->queue;
790 char *buf = bio_data(rq->bio);
843 unsigned int alignment; 791 unsigned int alignment;
844 char *buf;
845
846 if (rq->bio)
847 buf = bio_data(rq->bio);
848 else
849 buf = rq->data;
850 792
851 drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA); 793 drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
852 794
@@ -858,7 +800,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
858 */ 800 */
859 alignment = queue_dma_alignment(q) | q->dma_pad_mask; 801 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
860 if ((unsigned long)buf & alignment 802 if ((unsigned long)buf & alignment
861 || rq->data_len & q->dma_pad_mask 803 || blk_rq_bytes(rq) & q->dma_pad_mask
862 || object_is_on_stack(buf)) 804 || object_is_on_stack(buf))
863 drive->dma = 0; 805 drive->dma = 0;
864 } 806 }
@@ -896,6 +838,9 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
896 goto out_end; 838 goto out_end;
897 } 839 }
898 840
841 /* prepare sense request for this command */
842 ide_prep_sense(drive, rq);
843
899 memset(&cmd, 0, sizeof(cmd)); 844 memset(&cmd, 0, sizeof(cmd));
900 845
901 if (rq_data_dir(rq)) 846 if (rq_data_dir(rq))
@@ -903,15 +848,14 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
903 848
904 cmd.rq = rq; 849 cmd.rq = rq;
905 850
906 if (blk_fs_request(rq) || rq->data_len) { 851 if (blk_fs_request(rq) || blk_rq_bytes(rq)) {
907 ide_init_sg_cmd(&cmd, blk_fs_request(rq) ? (rq->nr_sectors << 9) 852 ide_init_sg_cmd(&cmd, blk_rq_bytes(rq));
908 : rq->data_len);
909 ide_map_sg(drive, &cmd); 853 ide_map_sg(drive, &cmd);
910 } 854 }
911 855
912 return ide_issue_pc(drive, &cmd); 856 return ide_issue_pc(drive, &cmd);
913out_end: 857out_end:
914 nsectors = rq->hard_nr_sectors; 858 nsectors = blk_rq_sectors(rq);
915 859
916 if (nsectors == 0) 860 if (nsectors == 0)
917 nsectors = 1; 861 nsectors = 1;
@@ -1077,8 +1021,8 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
1077 /* save a private copy of the TOC capacity for error handling */ 1021 /* save a private copy of the TOC capacity for error handling */
1078 drive->probed_capacity = toc->capacity * sectors_per_frame; 1022 drive->probed_capacity = toc->capacity * sectors_per_frame;
1079 1023
1080 blk_queue_hardsect_size(drive->queue, 1024 blk_queue_logical_block_size(drive->queue,
1081 sectors_per_frame << SECTOR_BITS); 1025 sectors_per_frame << SECTOR_BITS);
1082 1026
1083 /* first read just the header, so we know how long the TOC is */ 1027 /* first read just the header, so we know how long the TOC is */
1084 stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr, 1028 stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr,
@@ -1394,9 +1338,9 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1394/* standard prep_rq_fn that builds 10 byte cmds */ 1338/* standard prep_rq_fn that builds 10 byte cmds */
1395static int ide_cdrom_prep_fs(struct request_queue *q, struct request *rq) 1339static int ide_cdrom_prep_fs(struct request_queue *q, struct request *rq)
1396{ 1340{
1397 int hard_sect = queue_hardsect_size(q); 1341 int hard_sect = queue_logical_block_size(q);
1398 long block = (long)rq->hard_sector / (hard_sect >> 9); 1342 long block = (long)blk_rq_pos(rq) / (hard_sect >> 9);
1399 unsigned long blocks = rq->hard_nr_sectors / (hard_sect >> 9); 1343 unsigned long blocks = blk_rq_sectors(rq) / (hard_sect >> 9);
1400 1344
1401 memset(rq->cmd, 0, BLK_MAX_CDB); 1345 memset(rq->cmd, 0, BLK_MAX_CDB);
1402 1346
@@ -1599,7 +1543,7 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1599 1543
1600 nslots = ide_cdrom_probe_capabilities(drive); 1544 nslots = ide_cdrom_probe_capabilities(drive);
1601 1545
1602 blk_queue_hardsect_size(q, CD_FRAMESIZE); 1546 blk_queue_logical_block_size(q, CD_FRAMESIZE);
1603 1547
1604 if (ide_cdrom_register(drive, nslots)) { 1548 if (ide_cdrom_register(drive, nslots)) {
1605 printk(KERN_ERR PFX "%s: %s failed to register device with the" 1549 printk(KERN_ERR PFX "%s: %s failed to register device with the"
diff --git a/drivers/ide/ide-cd.h b/drivers/ide/ide-cd.h
index 1d97101099ce..93a3cf1b0f3f 100644
--- a/drivers/ide/ide-cd.h
+++ b/drivers/ide/ide-cd.h
@@ -87,10 +87,6 @@ struct cdrom_info {
87 87
88 struct atapi_toc *toc; 88 struct atapi_toc *toc;
89 89
90 /* The result of the last successful request sense command
91 on this device. */
92 struct request_sense sense_data;
93
94 u8 max_speed; /* Max speed of the drive. */ 90 u8 max_speed; /* Max speed of the drive. */
95 u8 current_speed; /* Current speed of the drive. */ 91 u8 current_speed; /* Current speed of the drive. */
96 92
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index a9fbe2c31210..c6f7fcfb9d67 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -82,7 +82,7 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
82 sector_t block) 82 sector_t block)
83{ 83{
84 ide_hwif_t *hwif = drive->hwif; 84 ide_hwif_t *hwif = drive->hwif;
85 u16 nsectors = (u16)rq->nr_sectors; 85 u16 nsectors = (u16)blk_rq_sectors(rq);
86 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48); 86 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
87 u8 dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA); 87 u8 dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
88 struct ide_cmd cmd; 88 struct ide_cmd cmd;
@@ -90,7 +90,7 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
90 ide_startstop_t rc; 90 ide_startstop_t rc;
91 91
92 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && lba48 && dma) { 92 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && lba48 && dma) {
93 if (block + rq->nr_sectors > 1ULL << 28) 93 if (block + blk_rq_sectors(rq) > 1ULL << 28)
94 dma = 0; 94 dma = 0;
95 else 95 else
96 lba48 = 0; 96 lba48 = 0;
@@ -195,9 +195,9 @@ static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
195 195
196 ledtrig_ide_activity(); 196 ledtrig_ide_activity();
197 197
198 pr_debug("%s: %sing: block=%llu, sectors=%lu, buffer=0x%08lx\n", 198 pr_debug("%s: %sing: block=%llu, sectors=%u, buffer=0x%08lx\n",
199 drive->name, rq_data_dir(rq) == READ ? "read" : "writ", 199 drive->name, rq_data_dir(rq) == READ ? "read" : "writ",
200 (unsigned long long)block, rq->nr_sectors, 200 (unsigned long long)block, blk_rq_sectors(rq),
201 (unsigned long)rq->buffer); 201 (unsigned long)rq->buffer);
202 202
203 if (hwif->rw_disk) 203 if (hwif->rw_disk)
@@ -411,7 +411,6 @@ static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
411 cmd->protocol = ATA_PROT_NODATA; 411 cmd->protocol = ATA_PROT_NODATA;
412 412
413 rq->cmd_type = REQ_TYPE_ATA_TASKFILE; 413 rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
414 rq->cmd_flags |= REQ_SOFTBARRIER;
415 rq->special = cmd; 414 rq->special = cmd;
416} 415}
417 416
@@ -640,7 +639,7 @@ static void ide_disk_setup(ide_drive_t *drive)
640 } 639 }
641 640
642 printk(KERN_INFO "%s: max request size: %dKiB\n", drive->name, 641 printk(KERN_INFO "%s: max request size: %dKiB\n", drive->name,
643 q->max_sectors / 2); 642 queue_max_sectors(q) / 2);
644 643
645 if (ata_id_is_ssd(id)) 644 if (ata_id_is_ssd(id))
646 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q); 645 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index a0b8cab1d9a6..001f68f0bb28 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -103,7 +103,7 @@ ide_startstop_t ide_dma_intr(ide_drive_t *drive)
103 ide_finish_cmd(drive, cmd, stat); 103 ide_finish_cmd(drive, cmd, stat);
104 else 104 else
105 ide_complete_rq(drive, 0, 105 ide_complete_rq(drive, 0,
106 cmd->rq->nr_sectors << 9); 106 blk_rq_sectors(cmd->rq) << 9);
107 return ide_stopped; 107 return ide_stopped;
108 } 108 }
109 printk(KERN_ERR "%s: %s: bad DMA status (0x%02x)\n", 109 printk(KERN_ERR "%s: %s: bad DMA status (0x%02x)\n",
@@ -510,23 +510,11 @@ ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
510 /* 510 /*
511 * un-busy drive etc and make sure request is sane 511 * un-busy drive etc and make sure request is sane
512 */ 512 */
513
514 rq = hwif->rq; 513 rq = hwif->rq;
515 if (!rq) 514 if (rq) {
516 goto out; 515 hwif->rq = NULL;
517 516 rq->errors = 0;
518 hwif->rq = NULL; 517 }
519
520 rq->errors = 0;
521
522 if (!rq->bio)
523 goto out;
524
525 rq->sector = rq->bio->bi_sector;
526 rq->current_nr_sectors = bio_iovec(rq->bio)->bv_len >> 9;
527 rq->hard_cur_sectors = rq->current_nr_sectors;
528 rq->buffer = bio_data(rq->bio);
529out:
530 return ret; 518 return ret;
531} 519}
532 520
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index 2b4868d95f8b..650981758f15 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -134,13 +134,17 @@ static ide_startstop_t ide_floppy_issue_pc(ide_drive_t *drive,
134 drive->pc = pc; 134 drive->pc = pc;
135 135
136 if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) { 136 if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) {
137 unsigned int done = blk_rq_bytes(drive->hwif->rq);
138
137 if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR)) 139 if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR))
138 ide_floppy_report_error(floppy, pc); 140 ide_floppy_report_error(floppy, pc);
141
139 /* Giving up */ 142 /* Giving up */
140 pc->error = IDE_DRV_ERROR_GENERAL; 143 pc->error = IDE_DRV_ERROR_GENERAL;
141 144
142 drive->failed_pc = NULL; 145 drive->failed_pc = NULL;
143 drive->pc_callback(drive, 0); 146 drive->pc_callback(drive, 0);
147 ide_complete_rq(drive, -EIO, done);
144 return ide_stopped; 148 return ide_stopped;
145 } 149 }
146 150
@@ -190,7 +194,7 @@ static void idefloppy_create_rw_cmd(ide_drive_t *drive,
190{ 194{
191 struct ide_disk_obj *floppy = drive->driver_data; 195 struct ide_disk_obj *floppy = drive->driver_data;
192 int block = sector / floppy->bs_factor; 196 int block = sector / floppy->bs_factor;
193 int blocks = rq->nr_sectors / floppy->bs_factor; 197 int blocks = blk_rq_sectors(rq) / floppy->bs_factor;
194 int cmd = rq_data_dir(rq); 198 int cmd = rq_data_dir(rq);
195 199
196 ide_debug_log(IDE_DBG_FUNC, "block: %d, blocks: %d", block, blocks); 200 ide_debug_log(IDE_DBG_FUNC, "block: %d, blocks: %d", block, blocks);
@@ -216,16 +220,14 @@ static void idefloppy_blockpc_cmd(struct ide_disk_obj *floppy,
216 ide_init_pc(pc); 220 ide_init_pc(pc);
217 memcpy(pc->c, rq->cmd, sizeof(pc->c)); 221 memcpy(pc->c, rq->cmd, sizeof(pc->c));
218 pc->rq = rq; 222 pc->rq = rq;
219 if (rq->data_len && rq_data_dir(rq) == WRITE) 223 if (blk_rq_bytes(rq)) {
220 pc->flags |= PC_FLAG_WRITING;
221 pc->buf = rq->data;
222 if (rq->bio)
223 pc->flags |= PC_FLAG_DMA_OK; 224 pc->flags |= PC_FLAG_DMA_OK;
224 /* 225 if (rq_data_dir(rq) == WRITE)
225 * possibly problematic, doesn't look like ide-floppy correctly 226 pc->flags |= PC_FLAG_WRITING;
226 * handled scattered requests if dma fails... 227 }
227 */ 228 /* pio will be performed by ide_pio_bytes() which handles sg fine */
228 pc->req_xfer = pc->buf_size = rq->data_len; 229 pc->buf = NULL;
230 pc->req_xfer = pc->buf_size = blk_rq_bytes(rq);
229} 231}
230 232
231static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive, 233static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
@@ -257,16 +259,16 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
257 goto out_end; 259 goto out_end;
258 } 260 }
259 if (blk_fs_request(rq)) { 261 if (blk_fs_request(rq)) {
260 if (((long)rq->sector % floppy->bs_factor) || 262 if (((long)blk_rq_pos(rq) % floppy->bs_factor) ||
261 (rq->nr_sectors % floppy->bs_factor)) { 263 (blk_rq_sectors(rq) % floppy->bs_factor)) {
262 printk(KERN_ERR PFX "%s: unsupported r/w rq size\n", 264 printk(KERN_ERR PFX "%s: unsupported r/w rq size\n",
263 drive->name); 265 drive->name);
264 goto out_end; 266 goto out_end;
265 } 267 }
266 pc = &floppy->queued_pc; 268 pc = &floppy->queued_pc;
267 idefloppy_create_rw_cmd(drive, pc, rq, (unsigned long)block); 269 idefloppy_create_rw_cmd(drive, pc, rq, (unsigned long)block);
268 } else if (blk_special_request(rq)) { 270 } else if (blk_special_request(rq) || blk_sense_request(rq)) {
269 pc = (struct ide_atapi_pc *) rq->buffer; 271 pc = (struct ide_atapi_pc *)rq->special;
270 } else if (blk_pc_request(rq)) { 272 } else if (blk_pc_request(rq)) {
271 pc = &floppy->queued_pc; 273 pc = &floppy->queued_pc;
272 idefloppy_blockpc_cmd(floppy, pc, rq); 274 idefloppy_blockpc_cmd(floppy, pc, rq);
@@ -275,6 +277,8 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
275 goto out_end; 277 goto out_end;
276 } 278 }
277 279
280 ide_prep_sense(drive, rq);
281
278 memset(&cmd, 0, sizeof(cmd)); 282 memset(&cmd, 0, sizeof(cmd));
279 283
280 if (rq_data_dir(rq)) 284 if (rq_data_dir(rq))
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 35dc38d3b2c5..bba4297f2f03 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -116,9 +116,9 @@ void ide_complete_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat, u8 err)
116unsigned int ide_rq_bytes(struct request *rq) 116unsigned int ide_rq_bytes(struct request *rq)
117{ 117{
118 if (blk_pc_request(rq)) 118 if (blk_pc_request(rq))
119 return rq->data_len; 119 return blk_rq_bytes(rq);
120 else 120 else
121 return rq->hard_cur_sectors << 9; 121 return blk_rq_cur_sectors(rq) << 9;
122} 122}
123EXPORT_SYMBOL_GPL(ide_rq_bytes); 123EXPORT_SYMBOL_GPL(ide_rq_bytes);
124 124
@@ -133,7 +133,7 @@ int ide_complete_rq(ide_drive_t *drive, int error, unsigned int nr_bytes)
133 * and complete the whole request right now 133 * and complete the whole request right now
134 */ 134 */
135 if (blk_noretry_request(rq) && error <= 0) 135 if (blk_noretry_request(rq) && error <= 0)
136 nr_bytes = rq->hard_nr_sectors << 9; 136 nr_bytes = blk_rq_sectors(rq) << 9;
137 137
138 rc = ide_end_rq(drive, rq, error, nr_bytes); 138 rc = ide_end_rq(drive, rq, error, nr_bytes);
139 if (rc == 0) 139 if (rc == 0)
@@ -248,14 +248,7 @@ void ide_map_sg(ide_drive_t *drive, struct ide_cmd *cmd)
248 struct scatterlist *sg = hwif->sg_table; 248 struct scatterlist *sg = hwif->sg_table;
249 struct request *rq = cmd->rq; 249 struct request *rq = cmd->rq;
250 250
251 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) { 251 cmd->sg_nents = blk_rq_map_sg(drive->queue, rq, sg);
252 sg_init_one(sg, rq->buffer, rq->nr_sectors * SECTOR_SIZE);
253 cmd->sg_nents = 1;
254 } else if (!rq->bio) {
255 sg_init_one(sg, rq->data, rq->data_len);
256 cmd->sg_nents = 1;
257 } else
258 cmd->sg_nents = blk_rq_map_sg(drive->queue, rq, sg);
259} 252}
260EXPORT_SYMBOL_GPL(ide_map_sg); 253EXPORT_SYMBOL_GPL(ide_map_sg);
261 254
@@ -286,7 +279,7 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
286 279
287 if (cmd) { 280 if (cmd) {
288 if (cmd->protocol == ATA_PROT_PIO) { 281 if (cmd->protocol == ATA_PROT_PIO) {
289 ide_init_sg_cmd(cmd, rq->nr_sectors << 9); 282 ide_init_sg_cmd(cmd, blk_rq_sectors(rq) << 9);
290 ide_map_sg(drive, cmd); 283 ide_map_sg(drive, cmd);
291 } 284 }
292 285
@@ -371,7 +364,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
371 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) 364 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
372 return execute_drive_cmd(drive, rq); 365 return execute_drive_cmd(drive, rq);
373 else if (blk_pm_request(rq)) { 366 else if (blk_pm_request(rq)) {
374 struct request_pm_state *pm = rq->data; 367 struct request_pm_state *pm = rq->special;
375#ifdef DEBUG_PM 368#ifdef DEBUG_PM
376 printk("%s: start_power_step(step: %d)\n", 369 printk("%s: start_power_step(step: %d)\n",
377 drive->name, pm->pm_step); 370 drive->name, pm->pm_step);
@@ -394,7 +387,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
394 387
395 drv = *(struct ide_driver **)rq->rq_disk->private_data; 388 drv = *(struct ide_driver **)rq->rq_disk->private_data;
396 389
397 return drv->do_request(drive, rq, rq->sector); 390 return drv->do_request(drive, rq, blk_rq_pos(rq));
398 } 391 }
399 return do_special(drive); 392 return do_special(drive);
400kill_rq: 393kill_rq:
@@ -484,6 +477,9 @@ void do_ide_request(struct request_queue *q)
484 477
485 spin_unlock_irq(q->queue_lock); 478 spin_unlock_irq(q->queue_lock);
486 479
480 /* HLD do_request() callback might sleep, make sure it's okay */
481 might_sleep();
482
487 if (ide_lock_host(host, hwif)) 483 if (ide_lock_host(host, hwif))
488 goto plug_device_2; 484 goto plug_device_2;
489 485
@@ -491,10 +487,10 @@ void do_ide_request(struct request_queue *q)
491 487
492 if (!ide_lock_port(hwif)) { 488 if (!ide_lock_port(hwif)) {
493 ide_hwif_t *prev_port; 489 ide_hwif_t *prev_port;
490
491 WARN_ON_ONCE(hwif->rq);
494repeat: 492repeat:
495 prev_port = hwif->host->cur_port; 493 prev_port = hwif->host->cur_port;
496 hwif->rq = NULL;
497
498 if (drive->dev_flags & IDE_DFLAG_SLEEPING && 494 if (drive->dev_flags & IDE_DFLAG_SLEEPING &&
499 time_after(drive->sleep, jiffies)) { 495 time_after(drive->sleep, jiffies)) {
500 ide_unlock_port(hwif); 496 ide_unlock_port(hwif);
@@ -523,7 +519,9 @@ repeat:
523 * we know that the queue isn't empty, but this can happen 519 * we know that the queue isn't empty, but this can happen
524 * if the q->prep_rq_fn() decides to kill a request 520 * if the q->prep_rq_fn() decides to kill a request
525 */ 521 */
526 rq = elv_next_request(drive->queue); 522 if (!rq)
523 rq = blk_fetch_request(drive->queue);
524
527 spin_unlock_irq(q->queue_lock); 525 spin_unlock_irq(q->queue_lock);
528 spin_lock_irq(&hwif->lock); 526 spin_lock_irq(&hwif->lock);
529 527
@@ -535,7 +533,7 @@ repeat:
535 /* 533 /*
536 * Sanity: don't accept a request that isn't a PM request 534 * Sanity: don't accept a request that isn't a PM request
537 * if we are currently power managed. This is very important as 535 * if we are currently power managed. This is very important as
538 * blk_stop_queue() doesn't prevent the elv_next_request() 536 * blk_stop_queue() doesn't prevent the blk_fetch_request()
539 * above to return us whatever is in the queue. Since we call 537 * above to return us whatever is in the queue. Since we call
540 * ide_do_request() ourselves, we end up taking requests while 538 * ide_do_request() ourselves, we end up taking requests while
541 * the queue is blocked... 539 * the queue is blocked...
@@ -559,8 +557,11 @@ repeat:
559 startstop = start_request(drive, rq); 557 startstop = start_request(drive, rq);
560 spin_lock_irq(&hwif->lock); 558 spin_lock_irq(&hwif->lock);
561 559
562 if (startstop == ide_stopped) 560 if (startstop == ide_stopped) {
561 rq = hwif->rq;
562 hwif->rq = NULL;
563 goto repeat; 563 goto repeat;
564 }
564 } else 565 } else
565 goto plug_device; 566 goto plug_device;
566out: 567out:
@@ -576,18 +577,24 @@ plug_device:
576plug_device_2: 577plug_device_2:
577 spin_lock_irq(q->queue_lock); 578 spin_lock_irq(q->queue_lock);
578 579
580 if (rq)
581 blk_requeue_request(q, rq);
579 if (!elv_queue_empty(q)) 582 if (!elv_queue_empty(q))
580 blk_plug_device(q); 583 blk_plug_device(q);
581} 584}
582 585
583static void ide_plug_device(ide_drive_t *drive) 586static void ide_requeue_and_plug(ide_drive_t *drive, struct request *rq)
584{ 587{
585 struct request_queue *q = drive->queue; 588 struct request_queue *q = drive->queue;
586 unsigned long flags; 589 unsigned long flags;
587 590
588 spin_lock_irqsave(q->queue_lock, flags); 591 spin_lock_irqsave(q->queue_lock, flags);
592
593 if (rq)
594 blk_requeue_request(q, rq);
589 if (!elv_queue_empty(q)) 595 if (!elv_queue_empty(q))
590 blk_plug_device(q); 596 blk_plug_device(q);
597
591 spin_unlock_irqrestore(q->queue_lock, flags); 598 spin_unlock_irqrestore(q->queue_lock, flags);
592} 599}
593 600
@@ -636,6 +643,7 @@ void ide_timer_expiry (unsigned long data)
636 unsigned long flags; 643 unsigned long flags;
637 int wait = -1; 644 int wait = -1;
638 int plug_device = 0; 645 int plug_device = 0;
646 struct request *uninitialized_var(rq_in_flight);
639 647
640 spin_lock_irqsave(&hwif->lock, flags); 648 spin_lock_irqsave(&hwif->lock, flags);
641 649
@@ -696,7 +704,9 @@ void ide_timer_expiry (unsigned long data)
696 } 704 }
697 spin_lock_irq(&hwif->lock); 705 spin_lock_irq(&hwif->lock);
698 enable_irq(hwif->irq); 706 enable_irq(hwif->irq);
699 if (startstop == ide_stopped) { 707 if (startstop == ide_stopped && hwif->polling == 0) {
708 rq_in_flight = hwif->rq;
709 hwif->rq = NULL;
700 ide_unlock_port(hwif); 710 ide_unlock_port(hwif);
701 plug_device = 1; 711 plug_device = 1;
702 } 712 }
@@ -705,7 +715,7 @@ void ide_timer_expiry (unsigned long data)
705 715
706 if (plug_device) { 716 if (plug_device) {
707 ide_unlock_host(hwif->host); 717 ide_unlock_host(hwif->host);
708 ide_plug_device(drive); 718 ide_requeue_and_plug(drive, rq_in_flight);
709 } 719 }
710} 720}
711 721
@@ -791,6 +801,7 @@ irqreturn_t ide_intr (int irq, void *dev_id)
791 ide_startstop_t startstop; 801 ide_startstop_t startstop;
792 irqreturn_t irq_ret = IRQ_NONE; 802 irqreturn_t irq_ret = IRQ_NONE;
793 int plug_device = 0; 803 int plug_device = 0;
804 struct request *uninitialized_var(rq_in_flight);
794 805
795 if (host->host_flags & IDE_HFLAG_SERIALIZE) { 806 if (host->host_flags & IDE_HFLAG_SERIALIZE) {
796 if (hwif != host->cur_port) 807 if (hwif != host->cur_port)
@@ -868,8 +879,10 @@ irqreturn_t ide_intr (int irq, void *dev_id)
868 * same irq as is currently being serviced here, and Linux 879 * same irq as is currently being serviced here, and Linux
869 * won't allow another of the same (on any CPU) until we return. 880 * won't allow another of the same (on any CPU) until we return.
870 */ 881 */
871 if (startstop == ide_stopped) { 882 if (startstop == ide_stopped && hwif->polling == 0) {
872 BUG_ON(hwif->handler); 883 BUG_ON(hwif->handler);
884 rq_in_flight = hwif->rq;
885 hwif->rq = NULL;
873 ide_unlock_port(hwif); 886 ide_unlock_port(hwif);
874 plug_device = 1; 887 plug_device = 1;
875 } 888 }
@@ -879,7 +892,7 @@ out:
879out_early: 892out_early:
880 if (plug_device) { 893 if (plug_device) {
881 ide_unlock_host(hwif->host); 894 ide_unlock_host(hwif->host);
882 ide_plug_device(drive); 895 ide_requeue_and_plug(drive, rq_in_flight);
883 } 896 }
884 897
885 return irq_ret; 898 return irq_ret;
diff --git a/drivers/ide/ide-ioctls.c b/drivers/ide/ide-ioctls.c
index c1c25ebbaa1f..5991b23793f2 100644
--- a/drivers/ide/ide-ioctls.c
+++ b/drivers/ide/ide-ioctls.c
@@ -231,7 +231,6 @@ static int generic_drive_reset(ide_drive_t *drive)
231 rq->cmd_type = REQ_TYPE_SPECIAL; 231 rq->cmd_type = REQ_TYPE_SPECIAL;
232 rq->cmd_len = 1; 232 rq->cmd_len = 1;
233 rq->cmd[0] = REQ_DRIVE_RESET; 233 rq->cmd[0] = REQ_DRIVE_RESET;
234 rq->cmd_flags |= REQ_SOFTBARRIER;
235 if (blk_execute_rq(drive->queue, NULL, rq, 1)) 234 if (blk_execute_rq(drive->queue, NULL, rq, 1))
236 ret = rq->errors; 235 ret = rq->errors;
237 blk_put_request(rq); 236 blk_put_request(rq);
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index c19a221b1e18..06fe002116ec 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -206,8 +206,6 @@ EXPORT_SYMBOL_GPL(ide_in_drive_list);
206 206
207/* 207/*
208 * Early UDMA66 devices don't set bit14 to 1, only bit13 is valid. 208 * Early UDMA66 devices don't set bit14 to 1, only bit13 is valid.
209 * We list them here and depend on the device side cable detection for them.
210 *
211 * Some optical devices with the buggy firmwares have the same problem. 209 * Some optical devices with the buggy firmwares have the same problem.
212 */ 210 */
213static const struct drive_list_entry ivb_list[] = { 211static const struct drive_list_entry ivb_list[] = {
@@ -251,10 +249,25 @@ u8 eighty_ninty_three(ide_drive_t *drive)
251 * - force bit13 (80c cable present) check also for !ivb devices 249 * - force bit13 (80c cable present) check also for !ivb devices
252 * (unless the slave device is pre-ATA3) 250 * (unless the slave device is pre-ATA3)
253 */ 251 */
254 if ((id[ATA_ID_HW_CONFIG] & 0x4000) || 252 if (id[ATA_ID_HW_CONFIG] & 0x4000)
255 (ivb && (id[ATA_ID_HW_CONFIG] & 0x2000)))
256 return 1; 253 return 1;
257 254
255 if (ivb) {
256 const char *model = (char *)&id[ATA_ID_PROD];
257
258 if (strstr(model, "TSSTcorp CDDVDW SH-S202")) {
259 /*
260 * These ATAPI devices always report 80c cable
261 * so we have to depend on the host in this case.
262 */
263 if (hwif->cbl == ATA_CBL_PATA80)
264 return 1;
265 } else {
266 /* Depend on the device side cable detection. */
267 if (id[ATA_ID_HW_CONFIG] & 0x2000)
268 return 1;
269 }
270 }
258no_80w: 271no_80w:
259 if (drive->dev_flags & IDE_DFLAG_UDMA33_WARNED) 272 if (drive->dev_flags & IDE_DFLAG_UDMA33_WARNED)
260 return 0; 273 return 0;
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index 56ff8c46c7d1..e386a32dc9ba 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -31,24 +31,6 @@ void ide_toggle_bounce(ide_drive_t *drive, int on)
31 blk_queue_bounce_limit(drive->queue, addr); 31 blk_queue_bounce_limit(drive->queue, addr);
32} 32}
33 33
34static void ide_dump_opcode(ide_drive_t *drive)
35{
36 struct request *rq = drive->hwif->rq;
37 struct ide_cmd *cmd = NULL;
38
39 if (!rq)
40 return;
41
42 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
43 cmd = rq->special;
44
45 printk(KERN_ERR "ide: failed opcode was: ");
46 if (cmd == NULL)
47 printk(KERN_CONT "unknown\n");
48 else
49 printk(KERN_CONT "0x%02x\n", cmd->tf.command);
50}
51
52u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48) 34u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48)
53{ 35{
54 struct ide_taskfile *tf = &cmd->tf; 36 struct ide_taskfile *tf = &cmd->tf;
@@ -91,7 +73,7 @@ static void ide_dump_sector(ide_drive_t *drive)
91 73
92static void ide_dump_ata_error(ide_drive_t *drive, u8 err) 74static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
93{ 75{
94 printk(KERN_ERR "{ "); 76 printk(KERN_CONT "{ ");
95 if (err & ATA_ABORTED) 77 if (err & ATA_ABORTED)
96 printk(KERN_CONT "DriveStatusError "); 78 printk(KERN_CONT "DriveStatusError ");
97 if (err & ATA_ICRC) 79 if (err & ATA_ICRC)
@@ -114,14 +96,14 @@ static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
114 96
115 if (rq) 97 if (rq)
116 printk(KERN_CONT ", sector=%llu", 98 printk(KERN_CONT ", sector=%llu",
117 (unsigned long long)rq->sector); 99 (unsigned long long)blk_rq_pos(rq));
118 } 100 }
119 printk(KERN_CONT "\n"); 101 printk(KERN_CONT "\n");
120} 102}
121 103
122static void ide_dump_atapi_error(ide_drive_t *drive, u8 err) 104static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
123{ 105{
124 printk(KERN_ERR "{ "); 106 printk(KERN_CONT "{ ");
125 if (err & ATAPI_ILI) 107 if (err & ATAPI_ILI)
126 printk(KERN_CONT "IllegalLengthIndication "); 108 printk(KERN_CONT "IllegalLengthIndication ");
127 if (err & ATAPI_EOM) 109 if (err & ATAPI_EOM)
@@ -179,7 +161,10 @@ u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
179 else 161 else
180 ide_dump_atapi_error(drive, err); 162 ide_dump_atapi_error(drive, err);
181 } 163 }
182 ide_dump_opcode(drive); 164
165 printk(KERN_ERR "%s: possibly failed opcode: 0x%02x\n",
166 drive->name, drive->hwif->cmd.tf.command);
167
183 return err; 168 return err;
184} 169}
185EXPORT_SYMBOL(ide_dump_status); 170EXPORT_SYMBOL(ide_dump_status);
diff --git a/drivers/ide/ide-park.c b/drivers/ide/ide-park.c
index 310d03f2b5b7..a914023d6d03 100644
--- a/drivers/ide/ide-park.c
+++ b/drivers/ide/ide-park.c
@@ -24,11 +24,8 @@ static void issue_park_cmd(ide_drive_t *drive, unsigned long timeout)
24 start_queue = 1; 24 start_queue = 1;
25 spin_unlock_irq(&hwif->lock); 25 spin_unlock_irq(&hwif->lock);
26 26
27 if (start_queue) { 27 if (start_queue)
28 spin_lock_irq(q->queue_lock); 28 blk_run_queue(q);
29 blk_start_queueing(q);
30 spin_unlock_irq(q->queue_lock);
31 }
32 return; 29 return;
33 } 30 }
34 spin_unlock_irq(&hwif->lock); 31 spin_unlock_irq(&hwif->lock);
diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
index 61111fd27130..39d4e01f5c9c 100644
--- a/drivers/ide/ide-pci-generic.c
+++ b/drivers/ide/ide-pci-generic.c
@@ -33,6 +33,16 @@ static int ide_generic_all; /* Set to claim all devices */
33module_param_named(all_generic_ide, ide_generic_all, bool, 0444); 33module_param_named(all_generic_ide, ide_generic_all, bool, 0444);
34MODULE_PARM_DESC(all_generic_ide, "IDE generic will claim all unknown PCI IDE storage controllers."); 34MODULE_PARM_DESC(all_generic_ide, "IDE generic will claim all unknown PCI IDE storage controllers.");
35 35
36static void netcell_quirkproc(ide_drive_t *drive)
37{
38 /* mark words 85-87 as valid */
39 drive->id[ATA_ID_CSF_DEFAULT] |= 0x4000;
40}
41
42static const struct ide_port_ops netcell_port_ops = {
43 .quirkproc = netcell_quirkproc,
44};
45
36#define DECLARE_GENERIC_PCI_DEV(extra_flags) \ 46#define DECLARE_GENERIC_PCI_DEV(extra_flags) \
37 { \ 47 { \
38 .name = DRV_NAME, \ 48 .name = DRV_NAME, \
@@ -74,6 +84,7 @@ static const struct ide_port_info generic_chipsets[] __devinitdata = {
74 84
75 { /* 6: Revolution */ 85 { /* 6: Revolution */
76 .name = DRV_NAME, 86 .name = DRV_NAME,
87 .port_ops = &netcell_port_ops,
77 .host_flags = IDE_HFLAG_CLEAR_SIMPLEX | 88 .host_flags = IDE_HFLAG_CLEAR_SIMPLEX |
78 IDE_HFLAG_TRUST_BIOS_FOR_DMA | 89 IDE_HFLAG_TRUST_BIOS_FOR_DMA |
79 IDE_HFLAG_OFF_BOARD, 90 IDE_HFLAG_OFF_BOARD,
diff --git a/drivers/ide/ide-pm.c b/drivers/ide/ide-pm.c
index 0d8a151c0a01..ba1488bd8430 100644
--- a/drivers/ide/ide-pm.c
+++ b/drivers/ide/ide-pm.c
@@ -7,7 +7,6 @@ int generic_ide_suspend(struct device *dev, pm_message_t mesg)
7 ide_hwif_t *hwif = drive->hwif; 7 ide_hwif_t *hwif = drive->hwif;
8 struct request *rq; 8 struct request *rq;
9 struct request_pm_state rqpm; 9 struct request_pm_state rqpm;
10 struct ide_cmd cmd;
11 int ret; 10 int ret;
12 11
13 /* call ACPI _GTM only once */ 12 /* call ACPI _GTM only once */
@@ -15,11 +14,9 @@ int generic_ide_suspend(struct device *dev, pm_message_t mesg)
15 ide_acpi_get_timing(hwif); 14 ide_acpi_get_timing(hwif);
16 15
17 memset(&rqpm, 0, sizeof(rqpm)); 16 memset(&rqpm, 0, sizeof(rqpm));
18 memset(&cmd, 0, sizeof(cmd));
19 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 17 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
20 rq->cmd_type = REQ_TYPE_PM_SUSPEND; 18 rq->cmd_type = REQ_TYPE_PM_SUSPEND;
21 rq->special = &cmd; 19 rq->special = &rqpm;
22 rq->data = &rqpm;
23 rqpm.pm_step = IDE_PM_START_SUSPEND; 20 rqpm.pm_step = IDE_PM_START_SUSPEND;
24 if (mesg.event == PM_EVENT_PRETHAW) 21 if (mesg.event == PM_EVENT_PRETHAW)
25 mesg.event = PM_EVENT_FREEZE; 22 mesg.event = PM_EVENT_FREEZE;
@@ -41,7 +38,6 @@ int generic_ide_resume(struct device *dev)
41 ide_hwif_t *hwif = drive->hwif; 38 ide_hwif_t *hwif = drive->hwif;
42 struct request *rq; 39 struct request *rq;
43 struct request_pm_state rqpm; 40 struct request_pm_state rqpm;
44 struct ide_cmd cmd;
45 int err; 41 int err;
46 42
47 /* call ACPI _PS0 / _STM only once */ 43 /* call ACPI _PS0 / _STM only once */
@@ -53,12 +49,10 @@ int generic_ide_resume(struct device *dev)
53 ide_acpi_exec_tfs(drive); 49 ide_acpi_exec_tfs(drive);
54 50
55 memset(&rqpm, 0, sizeof(rqpm)); 51 memset(&rqpm, 0, sizeof(rqpm));
56 memset(&cmd, 0, sizeof(cmd));
57 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 52 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
58 rq->cmd_type = REQ_TYPE_PM_RESUME; 53 rq->cmd_type = REQ_TYPE_PM_RESUME;
59 rq->cmd_flags |= REQ_PREEMPT; 54 rq->cmd_flags |= REQ_PREEMPT;
60 rq->special = &cmd; 55 rq->special = &rqpm;
61 rq->data = &rqpm;
62 rqpm.pm_step = IDE_PM_START_RESUME; 56 rqpm.pm_step = IDE_PM_START_RESUME;
63 rqpm.pm_state = PM_EVENT_ON; 57 rqpm.pm_state = PM_EVENT_ON;
64 58
@@ -77,7 +71,7 @@ int generic_ide_resume(struct device *dev)
77 71
78void ide_complete_power_step(ide_drive_t *drive, struct request *rq) 72void ide_complete_power_step(ide_drive_t *drive, struct request *rq)
79{ 73{
80 struct request_pm_state *pm = rq->data; 74 struct request_pm_state *pm = rq->special;
81 75
82#ifdef DEBUG_PM 76#ifdef DEBUG_PM
83 printk(KERN_INFO "%s: complete_power_step(step: %d)\n", 77 printk(KERN_INFO "%s: complete_power_step(step: %d)\n",
@@ -107,10 +101,8 @@ void ide_complete_power_step(ide_drive_t *drive, struct request *rq)
107 101
108ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq) 102ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
109{ 103{
110 struct request_pm_state *pm = rq->data; 104 struct request_pm_state *pm = rq->special;
111 struct ide_cmd *cmd = rq->special; 105 struct ide_cmd cmd = { };
112
113 memset(cmd, 0, sizeof(*cmd));
114 106
115 switch (pm->pm_step) { 107 switch (pm->pm_step) {
116 case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */ 108 case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */
@@ -123,12 +115,12 @@ ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
123 return ide_stopped; 115 return ide_stopped;
124 } 116 }
125 if (ata_id_flush_ext_enabled(drive->id)) 117 if (ata_id_flush_ext_enabled(drive->id))
126 cmd->tf.command = ATA_CMD_FLUSH_EXT; 118 cmd.tf.command = ATA_CMD_FLUSH_EXT;
127 else 119 else
128 cmd->tf.command = ATA_CMD_FLUSH; 120 cmd.tf.command = ATA_CMD_FLUSH;
129 goto out_do_tf; 121 goto out_do_tf;
130 case IDE_PM_STANDBY: /* Suspend step 2 (standby) */ 122 case IDE_PM_STANDBY: /* Suspend step 2 (standby) */
131 cmd->tf.command = ATA_CMD_STANDBYNOW1; 123 cmd.tf.command = ATA_CMD_STANDBYNOW1;
132 goto out_do_tf; 124 goto out_do_tf;
133 case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */ 125 case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */
134 ide_set_max_pio(drive); 126 ide_set_max_pio(drive);
@@ -141,7 +133,7 @@ ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
141 ide_complete_power_step(drive, rq); 133 ide_complete_power_step(drive, rq);
142 return ide_stopped; 134 return ide_stopped;
143 case IDE_PM_IDLE: /* Resume step 2 (idle) */ 135 case IDE_PM_IDLE: /* Resume step 2 (idle) */
144 cmd->tf.command = ATA_CMD_IDLEIMMEDIATE; 136 cmd.tf.command = ATA_CMD_IDLEIMMEDIATE;
145 goto out_do_tf; 137 goto out_do_tf;
146 case IDE_PM_RESTORE_DMA: /* Resume step 3 (restore DMA) */ 138 case IDE_PM_RESTORE_DMA: /* Resume step 3 (restore DMA) */
147 /* 139 /*
@@ -163,11 +155,11 @@ ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
163 return ide_stopped; 155 return ide_stopped;
164 156
165out_do_tf: 157out_do_tf:
166 cmd->valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE; 158 cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
167 cmd->valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE; 159 cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE;
168 cmd->protocol = ATA_PROT_NODATA; 160 cmd.protocol = ATA_PROT_NODATA;
169 161
170 return do_rw_taskfile(drive, cmd); 162 return do_rw_taskfile(drive, &cmd);
171} 163}
172 164
173/** 165/**
@@ -181,7 +173,7 @@ out_do_tf:
181void ide_complete_pm_rq(ide_drive_t *drive, struct request *rq) 173void ide_complete_pm_rq(ide_drive_t *drive, struct request *rq)
182{ 174{
183 struct request_queue *q = drive->queue; 175 struct request_queue *q = drive->queue;
184 struct request_pm_state *pm = rq->data; 176 struct request_pm_state *pm = rq->special;
185 unsigned long flags; 177 unsigned long flags;
186 178
187 ide_complete_power_step(drive, rq); 179 ide_complete_power_step(drive, rq);
@@ -207,7 +199,7 @@ void ide_complete_pm_rq(ide_drive_t *drive, struct request *rq)
207 199
208void ide_check_pm_state(ide_drive_t *drive, struct request *rq) 200void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
209{ 201{
210 struct request_pm_state *pm = rq->data; 202 struct request_pm_state *pm = rq->special;
211 203
212 if (blk_pm_suspend_request(rq) && 204 if (blk_pm_suspend_request(rq) &&
213 pm->pm_step == IDE_PM_START_SUSPEND) 205 pm->pm_step == IDE_PM_START_SUSPEND)
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 7f264ed1141b..c895ed52b2e8 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -295,7 +295,7 @@ int ide_dev_read_id(ide_drive_t *drive, u8 cmd, u16 *id)
295 295
296 timeout = ((cmd == ATA_CMD_ID_ATA) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2; 296 timeout = ((cmd == ATA_CMD_ID_ATA) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2;
297 297
298 if (ide_busy_sleep(hwif, timeout, use_altstatus)) 298 if (ide_busy_sleep(drive, timeout, use_altstatus))
299 return 1; 299 return 1;
300 300
301 /* wait for IRQ and ATA_DRQ */ 301 /* wait for IRQ and ATA_DRQ */
@@ -316,8 +316,9 @@ int ide_dev_read_id(ide_drive_t *drive, u8 cmd, u16 *id)
316 return rc; 316 return rc;
317} 317}
318 318
319int ide_busy_sleep(ide_hwif_t *hwif, unsigned long timeout, int altstatus) 319int ide_busy_sleep(ide_drive_t *drive, unsigned long timeout, int altstatus)
320{ 320{
321 ide_hwif_t *hwif = drive->hwif;
321 u8 stat; 322 u8 stat;
322 323
323 timeout += jiffies; 324 timeout += jiffies;
@@ -330,6 +331,8 @@ int ide_busy_sleep(ide_hwif_t *hwif, unsigned long timeout, int altstatus)
330 return 0; 331 return 0;
331 } while (time_before(jiffies, timeout)); 332 } while (time_before(jiffies, timeout));
332 333
334 printk(KERN_ERR "%s: timeout in %s\n", drive->name, __func__);
335
333 return 1; /* drive timed-out */ 336 return 1; /* drive timed-out */
334} 337}
335 338
@@ -420,7 +423,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
420 tp_ops->dev_select(drive); 423 tp_ops->dev_select(drive);
421 msleep(50); 424 msleep(50);
422 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET); 425 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
423 (void)ide_busy_sleep(hwif, WAIT_WORSTCASE, 0); 426 (void)ide_busy_sleep(drive, WAIT_WORSTCASE, 0);
424 rc = ide_dev_read_id(drive, cmd, id); 427 rc = ide_dev_read_id(drive, cmd, id);
425 } 428 }
426 429
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index cb942a9b580f..d9764f0bc82f 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -131,13 +131,6 @@ enum {
131 IDETAPE_DIR_WRITE = (1 << 2), 131 IDETAPE_DIR_WRITE = (1 << 2),
132}; 132};
133 133
134struct idetape_bh {
135 u32 b_size;
136 atomic_t b_count;
137 struct idetape_bh *b_reqnext;
138 char *b_data;
139};
140
141/* Tape door status */ 134/* Tape door status */
142#define DOOR_UNLOCKED 0 135#define DOOR_UNLOCKED 0
143#define DOOR_LOCKED 1 136#define DOOR_LOCKED 1
@@ -219,18 +212,12 @@ typedef struct ide_tape_obj {
219 212
220 /* Data buffer size chosen based on the tape's recommendation */ 213 /* Data buffer size chosen based on the tape's recommendation */
221 int buffer_size; 214 int buffer_size;
222 /* merge buffer */ 215 /* Staging buffer of buffer_size bytes */
223 struct idetape_bh *merge_bh; 216 void *buf;
224 /* size of the merge buffer */ 217 /* The read/write cursor */
225 int merge_bh_size; 218 void *cur;
226 /* pointer to current buffer head within the merge buffer */ 219 /* The number of valid bytes in buf */
227 struct idetape_bh *bh; 220 size_t valid;
228 char *b_data;
229 int b_count;
230
231 int pages_per_buffer;
232 /* Wasted space in each stage */
233 int excess_bh_size;
234 221
235 /* Measures average tape speed */ 222 /* Measures average tape speed */
236 unsigned long avg_time; 223 unsigned long avg_time;
@@ -297,84 +284,6 @@ static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i)
297 return tape; 284 return tape;
298} 285}
299 286
300static int idetape_input_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
301 unsigned int bcount)
302{
303 struct idetape_bh *bh = pc->bh;
304 int count;
305
306 while (bcount) {
307 if (bh == NULL)
308 break;
309 count = min(
310 (unsigned int)(bh->b_size - atomic_read(&bh->b_count)),
311 bcount);
312 drive->hwif->tp_ops->input_data(drive, NULL, bh->b_data +
313 atomic_read(&bh->b_count), count);
314 bcount -= count;
315 atomic_add(count, &bh->b_count);
316 if (atomic_read(&bh->b_count) == bh->b_size) {
317 bh = bh->b_reqnext;
318 if (bh)
319 atomic_set(&bh->b_count, 0);
320 }
321 }
322
323 pc->bh = bh;
324
325 return bcount;
326}
327
328static int idetape_output_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
329 unsigned int bcount)
330{
331 struct idetape_bh *bh = pc->bh;
332 int count;
333
334 while (bcount) {
335 if (bh == NULL)
336 break;
337 count = min((unsigned int)pc->b_count, (unsigned int)bcount);
338 drive->hwif->tp_ops->output_data(drive, NULL, pc->b_data, count);
339 bcount -= count;
340 pc->b_data += count;
341 pc->b_count -= count;
342 if (!pc->b_count) {
343 bh = bh->b_reqnext;
344 pc->bh = bh;
345 if (bh) {
346 pc->b_data = bh->b_data;
347 pc->b_count = atomic_read(&bh->b_count);
348 }
349 }
350 }
351
352 return bcount;
353}
354
355static void idetape_update_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc)
356{
357 struct idetape_bh *bh = pc->bh;
358 int count;
359 unsigned int bcount = pc->xferred;
360
361 if (pc->flags & PC_FLAG_WRITING)
362 return;
363 while (bcount) {
364 if (bh == NULL) {
365 printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
366 __func__);
367 return;
368 }
369 count = min((unsigned int)bh->b_size, (unsigned int)bcount);
370 atomic_set(&bh->b_count, count);
371 if (atomic_read(&bh->b_count) == bh->b_size)
372 bh = bh->b_reqnext;
373 bcount -= count;
374 }
375 pc->bh = bh;
376}
377
378/* 287/*
379 * called on each failed packet command retry to analyze the request sense. We 288 * called on each failed packet command retry to analyze the request sense. We
380 * currently do not utilize this information. 289 * currently do not utilize this information.
@@ -392,12 +301,10 @@ static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
392 pc->c[0], tape->sense_key, tape->asc, tape->ascq); 301 pc->c[0], tape->sense_key, tape->asc, tape->ascq);
393 302
394 /* Correct pc->xferred by asking the tape. */ 303 /* Correct pc->xferred by asking the tape. */
395 if (pc->flags & PC_FLAG_DMA_ERROR) { 304 if (pc->flags & PC_FLAG_DMA_ERROR)
396 pc->xferred = pc->req_xfer - 305 pc->xferred = pc->req_xfer -
397 tape->blk_size * 306 tape->blk_size *
398 get_unaligned_be32(&sense[3]); 307 get_unaligned_be32(&sense[3]);
399 idetape_update_buffers(drive, pc);
400 }
401 308
402 /* 309 /*
403 * If error was the result of a zero-length read or write command, 310 * If error was the result of a zero-length read or write command,
@@ -436,29 +343,6 @@ static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
436 } 343 }
437} 344}
438 345
439/* Free data buffers completely. */
440static void ide_tape_kfree_buffer(idetape_tape_t *tape)
441{
442 struct idetape_bh *prev_bh, *bh = tape->merge_bh;
443
444 while (bh) {
445 u32 size = bh->b_size;
446
447 while (size) {
448 unsigned int order = fls(size >> PAGE_SHIFT)-1;
449
450 if (bh->b_data)
451 free_pages((unsigned long)bh->b_data, order);
452
453 size &= (order-1);
454 bh->b_data += (1 << order) * PAGE_SIZE;
455 }
456 prev_bh = bh;
457 bh = bh->b_reqnext;
458 kfree(prev_bh);
459 }
460}
461
462static void ide_tape_handle_dsc(ide_drive_t *); 346static void ide_tape_handle_dsc(ide_drive_t *);
463 347
464static int ide_tape_callback(ide_drive_t *drive, int dsc) 348static int ide_tape_callback(ide_drive_t *drive, int dsc)
@@ -496,7 +380,7 @@ static int ide_tape_callback(ide_drive_t *drive, int dsc)
496 } 380 }
497 381
498 tape->first_frame += blocks; 382 tape->first_frame += blocks;
499 rq->current_nr_sectors -= blocks; 383 rq->resid_len -= blocks * tape->blk_size;
500 384
501 if (pc->error) { 385 if (pc->error) {
502 uptodate = 0; 386 uptodate = 0;
@@ -558,19 +442,6 @@ static void ide_tape_handle_dsc(ide_drive_t *drive)
558 idetape_postpone_request(drive); 442 idetape_postpone_request(drive);
559} 443}
560 444
561static int ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
562 unsigned int bcount, int write)
563{
564 unsigned int bleft;
565
566 if (write)
567 bleft = idetape_output_buffers(drive, pc, bcount);
568 else
569 bleft = idetape_input_buffers(drive, pc, bcount);
570
571 return bcount - bleft;
572}
573
574/* 445/*
575 * Packet Command Interface 446 * Packet Command Interface
576 * 447 *
@@ -614,12 +485,6 @@ static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive,
614{ 485{
615 idetape_tape_t *tape = drive->driver_data; 486 idetape_tape_t *tape = drive->driver_data;
616 487
617 if (drive->pc->c[0] == REQUEST_SENSE &&
618 pc->c[0] == REQUEST_SENSE) {
619 printk(KERN_ERR "ide-tape: possible ide-tape.c bug - "
620 "Two request sense in serial were issued\n");
621 }
622
623 if (drive->failed_pc == NULL && pc->c[0] != REQUEST_SENSE) 488 if (drive->failed_pc == NULL && pc->c[0] != REQUEST_SENSE)
624 drive->failed_pc = pc; 489 drive->failed_pc = pc;
625 490
@@ -628,6 +493,8 @@ static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive,
628 493
629 if (pc->retries > IDETAPE_MAX_PC_RETRIES || 494 if (pc->retries > IDETAPE_MAX_PC_RETRIES ||
630 (pc->flags & PC_FLAG_ABORT)) { 495 (pc->flags & PC_FLAG_ABORT)) {
496 unsigned int done = blk_rq_bytes(drive->hwif->rq);
497
631 /* 498 /*
632 * We will "abort" retrying a packet command in case legitimate 499 * We will "abort" retrying a packet command in case legitimate
633 * error code was received (crossing a filemark, or end of the 500 * error code was received (crossing a filemark, or end of the
@@ -647,8 +514,10 @@ static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive,
647 /* Giving up */ 514 /* Giving up */
648 pc->error = IDE_DRV_ERROR_GENERAL; 515 pc->error = IDE_DRV_ERROR_GENERAL;
649 } 516 }
517
650 drive->failed_pc = NULL; 518 drive->failed_pc = NULL;
651 drive->pc_callback(drive, 0); 519 drive->pc_callback(drive, 0);
520 ide_complete_rq(drive, -EIO, done);
652 return ide_stopped; 521 return ide_stopped;
653 } 522 }
654 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]); 523 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]);
@@ -701,7 +570,7 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
701 printk(KERN_ERR "ide-tape: %s: I/O error, ", 570 printk(KERN_ERR "ide-tape: %s: I/O error, ",
702 tape->name); 571 tape->name);
703 /* Retry operation */ 572 /* Retry operation */
704 ide_retry_pc(drive, tape->disk); 573 ide_retry_pc(drive);
705 return ide_stopped; 574 return ide_stopped;
706 } 575 }
707 pc->error = 0; 576 pc->error = 0;
@@ -717,27 +586,22 @@ static void ide_tape_create_rw_cmd(idetape_tape_t *tape,
717 struct ide_atapi_pc *pc, struct request *rq, 586 struct ide_atapi_pc *pc, struct request *rq,
718 u8 opcode) 587 u8 opcode)
719{ 588{
720 struct idetape_bh *bh = (struct idetape_bh *)rq->special; 589 unsigned int length = blk_rq_sectors(rq);
721 unsigned int length = rq->current_nr_sectors;
722 590
723 ide_init_pc(pc); 591 ide_init_pc(pc);
724 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]); 592 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
725 pc->c[1] = 1; 593 pc->c[1] = 1;
726 pc->bh = bh;
727 pc->buf = NULL; 594 pc->buf = NULL;
728 pc->buf_size = length * tape->blk_size; 595 pc->buf_size = length * tape->blk_size;
729 pc->req_xfer = pc->buf_size; 596 pc->req_xfer = pc->buf_size;
730 if (pc->req_xfer == tape->buffer_size) 597 if (pc->req_xfer == tape->buffer_size)
731 pc->flags |= PC_FLAG_DMA_OK; 598 pc->flags |= PC_FLAG_DMA_OK;
732 599
733 if (opcode == READ_6) { 600 if (opcode == READ_6)
734 pc->c[0] = READ_6; 601 pc->c[0] = READ_6;
735 atomic_set(&bh->b_count, 0); 602 else if (opcode == WRITE_6) {
736 } else if (opcode == WRITE_6) {
737 pc->c[0] = WRITE_6; 603 pc->c[0] = WRITE_6;
738 pc->flags |= PC_FLAG_WRITING; 604 pc->flags |= PC_FLAG_WRITING;
739 pc->b_data = bh->b_data;
740 pc->b_count = atomic_read(&bh->b_count);
741 } 605 }
742 606
743 memcpy(rq->cmd, pc->c, 12); 607 memcpy(rq->cmd, pc->c, 12);
@@ -753,12 +617,10 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
753 struct ide_cmd cmd; 617 struct ide_cmd cmd;
754 u8 stat; 618 u8 stat;
755 619
756 debug_log(DBG_SENSE, "sector: %llu, nr_sectors: %lu," 620 debug_log(DBG_SENSE, "sector: %llu, nr_sectors: %u\n"
757 " current_nr_sectors: %u\n", 621 (unsigned long long)blk_rq_pos(rq), blk_rq_sectors(rq));
758 (unsigned long long)rq->sector, rq->nr_sectors,
759 rq->current_nr_sectors);
760 622
761 if (!blk_special_request(rq)) { 623 if (!(blk_special_request(rq) || blk_sense_request(rq))) {
762 /* We do not support buffer cache originated requests. */ 624 /* We do not support buffer cache originated requests. */
763 printk(KERN_NOTICE "ide-tape: %s: Unsupported request in " 625 printk(KERN_NOTICE "ide-tape: %s: Unsupported request in "
764 "request queue (%d)\n", drive->name, rq->cmd_type); 626 "request queue (%d)\n", drive->name, rq->cmd_type);
@@ -834,7 +696,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
834 goto out; 696 goto out;
835 } 697 }
836 if (rq->cmd[13] & REQ_IDETAPE_PC1) { 698 if (rq->cmd[13] & REQ_IDETAPE_PC1) {
837 pc = (struct ide_atapi_pc *) rq->buffer; 699 pc = (struct ide_atapi_pc *)rq->special;
838 rq->cmd[13] &= ~(REQ_IDETAPE_PC1); 700 rq->cmd[13] &= ~(REQ_IDETAPE_PC1);
839 rq->cmd[13] |= REQ_IDETAPE_PC2; 701 rq->cmd[13] |= REQ_IDETAPE_PC2;
840 goto out; 702 goto out;
@@ -846,6 +708,9 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
846 BUG(); 708 BUG();
847 709
848out: 710out:
711 /* prepare sense request for this command */
712 ide_prep_sense(drive, rq);
713
849 memset(&cmd, 0, sizeof(cmd)); 714 memset(&cmd, 0, sizeof(cmd));
850 715
851 if (rq_data_dir(rq)) 716 if (rq_data_dir(rq))
@@ -853,167 +718,10 @@ out:
853 718
854 cmd.rq = rq; 719 cmd.rq = rq;
855 720
856 return ide_tape_issue_pc(drive, &cmd, pc); 721 ide_init_sg_cmd(&cmd, pc->req_xfer);
857} 722 ide_map_sg(drive, &cmd);
858
859/*
860 * The function below uses __get_free_pages to allocate a data buffer of size
861 * tape->buffer_size (or a bit more). We attempt to combine sequential pages as
862 * much as possible.
863 *
864 * It returns a pointer to the newly allocated buffer, or NULL in case of
865 * failure.
866 */
867static struct idetape_bh *ide_tape_kmalloc_buffer(idetape_tape_t *tape,
868 int full, int clear)
869{
870 struct idetape_bh *prev_bh, *bh, *merge_bh;
871 int pages = tape->pages_per_buffer;
872 unsigned int order, b_allocd;
873 char *b_data = NULL;
874
875 merge_bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL);
876 bh = merge_bh;
877 if (bh == NULL)
878 goto abort;
879
880 order = fls(pages) - 1;
881 bh->b_data = (char *) __get_free_pages(GFP_KERNEL, order);
882 if (!bh->b_data)
883 goto abort;
884 b_allocd = (1 << order) * PAGE_SIZE;
885 pages &= (order-1);
886
887 if (clear)
888 memset(bh->b_data, 0, b_allocd);
889 bh->b_reqnext = NULL;
890 bh->b_size = b_allocd;
891 atomic_set(&bh->b_count, full ? bh->b_size : 0);
892
893 while (pages) {
894 order = fls(pages) - 1;
895 b_data = (char *) __get_free_pages(GFP_KERNEL, order);
896 if (!b_data)
897 goto abort;
898 b_allocd = (1 << order) * PAGE_SIZE;
899
900 if (clear)
901 memset(b_data, 0, b_allocd);
902
903 /* newly allocated page frames below buffer header or ...*/
904 if (bh->b_data == b_data + b_allocd) {
905 bh->b_size += b_allocd;
906 bh->b_data -= b_allocd;
907 if (full)
908 atomic_add(b_allocd, &bh->b_count);
909 continue;
910 }
911 /* they are above the header */
912 if (b_data == bh->b_data + bh->b_size) {
913 bh->b_size += b_allocd;
914 if (full)
915 atomic_add(b_allocd, &bh->b_count);
916 continue;
917 }
918 prev_bh = bh;
919 bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL);
920 if (!bh) {
921 free_pages((unsigned long) b_data, order);
922 goto abort;
923 }
924 bh->b_reqnext = NULL;
925 bh->b_data = b_data;
926 bh->b_size = b_allocd;
927 atomic_set(&bh->b_count, full ? bh->b_size : 0);
928 prev_bh->b_reqnext = bh;
929
930 pages &= (order-1);
931 }
932 723
933 bh->b_size -= tape->excess_bh_size; 724 return ide_tape_issue_pc(drive, &cmd, pc);
934 if (full)
935 atomic_sub(tape->excess_bh_size, &bh->b_count);
936 return merge_bh;
937abort:
938 ide_tape_kfree_buffer(tape);
939 return NULL;
940}
941
942static int idetape_copy_stage_from_user(idetape_tape_t *tape,
943 const char __user *buf, int n)
944{
945 struct idetape_bh *bh = tape->bh;
946 int count;
947 int ret = 0;
948
949 while (n) {
950 if (bh == NULL) {
951 printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
952 __func__);
953 return 1;
954 }
955 count = min((unsigned int)
956 (bh->b_size - atomic_read(&bh->b_count)),
957 (unsigned int)n);
958 if (copy_from_user(bh->b_data + atomic_read(&bh->b_count), buf,
959 count))
960 ret = 1;
961 n -= count;
962 atomic_add(count, &bh->b_count);
963 buf += count;
964 if (atomic_read(&bh->b_count) == bh->b_size) {
965 bh = bh->b_reqnext;
966 if (bh)
967 atomic_set(&bh->b_count, 0);
968 }
969 }
970 tape->bh = bh;
971 return ret;
972}
973
974static int idetape_copy_stage_to_user(idetape_tape_t *tape, char __user *buf,
975 int n)
976{
977 struct idetape_bh *bh = tape->bh;
978 int count;
979 int ret = 0;
980
981 while (n) {
982 if (bh == NULL) {
983 printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
984 __func__);
985 return 1;
986 }
987 count = min(tape->b_count, n);
988 if (copy_to_user(buf, tape->b_data, count))
989 ret = 1;
990 n -= count;
991 tape->b_data += count;
992 tape->b_count -= count;
993 buf += count;
994 if (!tape->b_count) {
995 bh = bh->b_reqnext;
996 tape->bh = bh;
997 if (bh) {
998 tape->b_data = bh->b_data;
999 tape->b_count = atomic_read(&bh->b_count);
1000 }
1001 }
1002 }
1003 return ret;
1004}
1005
1006static void idetape_init_merge_buffer(idetape_tape_t *tape)
1007{
1008 struct idetape_bh *bh = tape->merge_bh;
1009 tape->bh = tape->merge_bh;
1010
1011 if (tape->chrdev_dir == IDETAPE_DIR_WRITE)
1012 atomic_set(&bh->b_count, 0);
1013 else {
1014 tape->b_data = bh->b_data;
1015 tape->b_count = atomic_read(&bh->b_count);
1016 }
1017} 725}
1018 726
1019/* 727/*
@@ -1113,10 +821,10 @@ static void __ide_tape_discard_merge_buffer(ide_drive_t *drive)
1113 return; 821 return;
1114 822
1115 clear_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags); 823 clear_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags);
1116 tape->merge_bh_size = 0; 824 tape->valid = 0;
1117 if (tape->merge_bh != NULL) { 825 if (tape->buf != NULL) {
1118 ide_tape_kfree_buffer(tape); 826 kfree(tape->buf);
1119 tape->merge_bh = NULL; 827 tape->buf = NULL;
1120 } 828 }
1121 829
1122 tape->chrdev_dir = IDETAPE_DIR_NONE; 830 tape->chrdev_dir = IDETAPE_DIR_NONE;
@@ -1170,36 +878,44 @@ static void ide_tape_discard_merge_buffer(ide_drive_t *drive,
1170 * Generate a read/write request for the block device interface and wait for it 878 * Generate a read/write request for the block device interface and wait for it
1171 * to be serviced. 879 * to be serviced.
1172 */ 880 */
1173static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks, 881static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int size)
1174 struct idetape_bh *bh)
1175{ 882{
1176 idetape_tape_t *tape = drive->driver_data; 883 idetape_tape_t *tape = drive->driver_data;
1177 struct request *rq; 884 struct request *rq;
1178 int ret, errors; 885 int ret;
1179 886
1180 debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd); 887 debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd);
888 BUG_ON(cmd != REQ_IDETAPE_READ && cmd != REQ_IDETAPE_WRITE);
889 BUG_ON(size < 0 || size % tape->blk_size);
1181 890
1182 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 891 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
1183 rq->cmd_type = REQ_TYPE_SPECIAL; 892 rq->cmd_type = REQ_TYPE_SPECIAL;
1184 rq->cmd[13] = cmd; 893 rq->cmd[13] = cmd;
1185 rq->rq_disk = tape->disk; 894 rq->rq_disk = tape->disk;
1186 rq->special = (void *)bh; 895 rq->__sector = tape->first_frame;
1187 rq->sector = tape->first_frame;
1188 rq->nr_sectors = blocks;
1189 rq->current_nr_sectors = blocks;
1190 blk_execute_rq(drive->queue, tape->disk, rq, 0);
1191 896
1192 errors = rq->errors; 897 if (size) {
1193 ret = tape->blk_size * (blocks - rq->current_nr_sectors); 898 ret = blk_rq_map_kern(drive->queue, rq, tape->buf, size,
1194 blk_put_request(rq); 899 __GFP_WAIT);
900 if (ret)
901 goto out_put;
902 }
1195 903
1196 if ((cmd & (REQ_IDETAPE_READ | REQ_IDETAPE_WRITE)) == 0) 904 blk_execute_rq(drive->queue, tape->disk, rq, 0);
1197 return 0;
1198 905
1199 if (tape->merge_bh) 906 /* calculate the number of transferred bytes and update buffer state */
1200 idetape_init_merge_buffer(tape); 907 size -= rq->resid_len;
1201 if (errors == IDE_DRV_ERROR_GENERAL) 908 tape->cur = tape->buf;
1202 return -EIO; 909 if (cmd == REQ_IDETAPE_READ)
910 tape->valid = size;
911 else
912 tape->valid = 0;
913
914 ret = size;
915 if (rq->errors == IDE_DRV_ERROR_GENERAL)
916 ret = -EIO;
917out_put:
918 blk_put_request(rq);
1203 return ret; 919 return ret;
1204} 920}
1205 921
@@ -1236,153 +952,87 @@ static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd)
1236 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 952 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1237} 953}
1238 954
1239/* Queue up a character device originated write request. */
1240static int idetape_add_chrdev_write_request(ide_drive_t *drive, int blocks)
1241{
1242 idetape_tape_t *tape = drive->driver_data;
1243
1244 debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
1245
1246 return idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE,
1247 blocks, tape->merge_bh);
1248}
1249
1250static void ide_tape_flush_merge_buffer(ide_drive_t *drive) 955static void ide_tape_flush_merge_buffer(ide_drive_t *drive)
1251{ 956{
1252 idetape_tape_t *tape = drive->driver_data; 957 idetape_tape_t *tape = drive->driver_data;
1253 int blocks, min;
1254 struct idetape_bh *bh;
1255 958
1256 if (tape->chrdev_dir != IDETAPE_DIR_WRITE) { 959 if (tape->chrdev_dir != IDETAPE_DIR_WRITE) {
1257 printk(KERN_ERR "ide-tape: bug: Trying to empty merge buffer" 960 printk(KERN_ERR "ide-tape: bug: Trying to empty merge buffer"
1258 " but we are not writing.\n"); 961 " but we are not writing.\n");
1259 return; 962 return;
1260 } 963 }
1261 if (tape->merge_bh_size > tape->buffer_size) { 964 if (tape->buf) {
1262 printk(KERN_ERR "ide-tape: bug: merge_buffer too big\n"); 965 size_t aligned = roundup(tape->valid, tape->blk_size);
1263 tape->merge_bh_size = tape->buffer_size; 966
1264 } 967 memset(tape->cur, 0, aligned - tape->valid);
1265 if (tape->merge_bh_size) { 968 idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, aligned);
1266 blocks = tape->merge_bh_size / tape->blk_size; 969 kfree(tape->buf);
1267 if (tape->merge_bh_size % tape->blk_size) { 970 tape->buf = NULL;
1268 unsigned int i;
1269
1270 blocks++;
1271 i = tape->blk_size - tape->merge_bh_size %
1272 tape->blk_size;
1273 bh = tape->bh->b_reqnext;
1274 while (bh) {
1275 atomic_set(&bh->b_count, 0);
1276 bh = bh->b_reqnext;
1277 }
1278 bh = tape->bh;
1279 while (i) {
1280 if (bh == NULL) {
1281 printk(KERN_INFO "ide-tape: bug,"
1282 " bh NULL\n");
1283 break;
1284 }
1285 min = min(i, (unsigned int)(bh->b_size -
1286 atomic_read(&bh->b_count)));
1287 memset(bh->b_data + atomic_read(&bh->b_count),
1288 0, min);
1289 atomic_add(min, &bh->b_count);
1290 i -= min;
1291 bh = bh->b_reqnext;
1292 }
1293 }
1294 (void) idetape_add_chrdev_write_request(drive, blocks);
1295 tape->merge_bh_size = 0;
1296 }
1297 if (tape->merge_bh != NULL) {
1298 ide_tape_kfree_buffer(tape);
1299 tape->merge_bh = NULL;
1300 } 971 }
1301 tape->chrdev_dir = IDETAPE_DIR_NONE; 972 tape->chrdev_dir = IDETAPE_DIR_NONE;
1302} 973}
1303 974
1304static int idetape_init_read(ide_drive_t *drive) 975static int idetape_init_rw(ide_drive_t *drive, int dir)
1305{ 976{
1306 idetape_tape_t *tape = drive->driver_data; 977 idetape_tape_t *tape = drive->driver_data;
1307 int bytes_read; 978 int rc;
1308
1309 /* Initialize read operation */
1310 if (tape->chrdev_dir != IDETAPE_DIR_READ) {
1311 if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
1312 ide_tape_flush_merge_buffer(drive);
1313 idetape_flush_tape_buffers(drive);
1314 }
1315 if (tape->merge_bh || tape->merge_bh_size) {
1316 printk(KERN_ERR "ide-tape: merge_bh_size should be"
1317 " 0 now\n");
1318 tape->merge_bh_size = 0;
1319 }
1320 tape->merge_bh = ide_tape_kmalloc_buffer(tape, 0, 0);
1321 if (!tape->merge_bh)
1322 return -ENOMEM;
1323 tape->chrdev_dir = IDETAPE_DIR_READ;
1324 979
1325 /* 980 BUG_ON(dir != IDETAPE_DIR_READ && dir != IDETAPE_DIR_WRITE);
1326 * Issue a read 0 command to ensure that DSC handshake is
1327 * switched from completion mode to buffer available mode.
1328 * No point in issuing this if DSC overlap isn't supported, some
1329 * drives (Seagate STT3401A) will return an error.
1330 */
1331 if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
1332 bytes_read = idetape_queue_rw_tail(drive,
1333 REQ_IDETAPE_READ, 0,
1334 tape->merge_bh);
1335 if (bytes_read < 0) {
1336 ide_tape_kfree_buffer(tape);
1337 tape->merge_bh = NULL;
1338 tape->chrdev_dir = IDETAPE_DIR_NONE;
1339 return bytes_read;
1340 }
1341 }
1342 }
1343 981
1344 return 0; 982 if (tape->chrdev_dir == dir)
1345} 983 return 0;
1346 984
1347/* called from idetape_chrdev_read() to service a chrdev read request. */ 985 if (tape->chrdev_dir == IDETAPE_DIR_READ)
1348static int idetape_add_chrdev_read_request(ide_drive_t *drive, int blocks) 986 ide_tape_discard_merge_buffer(drive, 1);
1349{ 987 else if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
1350 idetape_tape_t *tape = drive->driver_data; 988 ide_tape_flush_merge_buffer(drive);
989 idetape_flush_tape_buffers(drive);
990 }
1351 991
1352 debug_log(DBG_PROCS, "Enter %s, %d blocks\n", __func__, blocks); 992 if (tape->buf || tape->valid) {
993 printk(KERN_ERR "ide-tape: valid should be 0 now\n");
994 tape->valid = 0;
995 }
1353 996
1354 /* If we are at a filemark, return a read length of 0 */ 997 tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL);
1355 if (test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags)) 998 if (!tape->buf)
1356 return 0; 999 return -ENOMEM;
1000 tape->chrdev_dir = dir;
1001 tape->cur = tape->buf;
1357 1002
1358 idetape_init_read(drive); 1003 /*
1004 * Issue a 0 rw command to ensure that DSC handshake is
1005 * switched from completion mode to buffer available mode. No
1006 * point in issuing this if DSC overlap isn't supported, some
1007 * drives (Seagate STT3401A) will return an error.
1008 */
1009 if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
1010 int cmd = dir == IDETAPE_DIR_READ ? REQ_IDETAPE_READ
1011 : REQ_IDETAPE_WRITE;
1012
1013 rc = idetape_queue_rw_tail(drive, cmd, 0);
1014 if (rc < 0) {
1015 kfree(tape->buf);
1016 tape->buf = NULL;
1017 tape->chrdev_dir = IDETAPE_DIR_NONE;
1018 return rc;
1019 }
1020 }
1359 1021
1360 return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, blocks, 1022 return 0;
1361 tape->merge_bh);
1362} 1023}
1363 1024
1364static void idetape_pad_zeros(ide_drive_t *drive, int bcount) 1025static void idetape_pad_zeros(ide_drive_t *drive, int bcount)
1365{ 1026{
1366 idetape_tape_t *tape = drive->driver_data; 1027 idetape_tape_t *tape = drive->driver_data;
1367 struct idetape_bh *bh; 1028
1368 int blocks; 1029 memset(tape->buf, 0, tape->buffer_size);
1369 1030
1370 while (bcount) { 1031 while (bcount) {
1371 unsigned int count; 1032 unsigned int count = min(tape->buffer_size, bcount);
1372 1033
1373 bh = tape->merge_bh; 1034 idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, count);
1374 count = min(tape->buffer_size, bcount);
1375 bcount -= count; 1035 bcount -= count;
1376 blocks = count / tape->blk_size;
1377 while (count) {
1378 atomic_set(&bh->b_count,
1379 min(count, (unsigned int)bh->b_size));
1380 memset(bh->b_data, 0, atomic_read(&bh->b_count));
1381 count -= atomic_read(&bh->b_count);
1382 bh = bh->b_reqnext;
1383 }
1384 idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks,
1385 tape->merge_bh);
1386 } 1036 }
1387} 1037}
1388 1038
@@ -1462,7 +1112,7 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
1462 } 1112 }
1463 1113
1464 if (tape->chrdev_dir == IDETAPE_DIR_READ) { 1114 if (tape->chrdev_dir == IDETAPE_DIR_READ) {
1465 tape->merge_bh_size = 0; 1115 tape->valid = 0;
1466 if (test_and_clear_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags)) 1116 if (test_and_clear_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags))
1467 ++count; 1117 ++count;
1468 ide_tape_discard_merge_buffer(drive, 0); 1118 ide_tape_discard_merge_buffer(drive, 0);
@@ -1511,9 +1161,9 @@ static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
1511{ 1161{
1512 struct ide_tape_obj *tape = file->private_data; 1162 struct ide_tape_obj *tape = file->private_data;
1513 ide_drive_t *drive = tape->drive; 1163 ide_drive_t *drive = tape->drive;
1514 ssize_t bytes_read, temp, actually_read = 0, rc; 1164 size_t done = 0;
1515 ssize_t ret = 0; 1165 ssize_t ret = 0;
1516 u16 ctl = *(u16 *)&tape->caps[12]; 1166 int rc;
1517 1167
1518 debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count); 1168 debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count);
1519 1169
@@ -1523,49 +1173,43 @@ static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
1523 (count % tape->blk_size) == 0) 1173 (count % tape->blk_size) == 0)
1524 tape->user_bs_factor = count / tape->blk_size; 1174 tape->user_bs_factor = count / tape->blk_size;
1525 } 1175 }
1526 rc = idetape_init_read(drive); 1176
1177 rc = idetape_init_rw(drive, IDETAPE_DIR_READ);
1527 if (rc < 0) 1178 if (rc < 0)
1528 return rc; 1179 return rc;
1529 if (count == 0) 1180
1530 return (0); 1181 while (done < count) {
1531 if (tape->merge_bh_size) { 1182 size_t todo;
1532 actually_read = min((unsigned int)(tape->merge_bh_size), 1183
1533 (unsigned int)count); 1184 /* refill if staging buffer is empty */
1534 if (idetape_copy_stage_to_user(tape, buf, actually_read)) 1185 if (!tape->valid) {
1535 ret = -EFAULT; 1186 /* If we are at a filemark, nothing more to read */
1536 buf += actually_read; 1187 if (test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags))
1537 tape->merge_bh_size -= actually_read; 1188 break;
1538 count -= actually_read; 1189 /* read */
1539 } 1190 if (idetape_queue_rw_tail(drive, REQ_IDETAPE_READ,
1540 while (count >= tape->buffer_size) { 1191 tape->buffer_size) <= 0)
1541 bytes_read = idetape_add_chrdev_read_request(drive, ctl); 1192 break;
1542 if (bytes_read <= 0) 1193 }
1543 goto finish; 1194
1544 if (idetape_copy_stage_to_user(tape, buf, bytes_read)) 1195 /* copy out */
1545 ret = -EFAULT; 1196 todo = min_t(size_t, count - done, tape->valid);
1546 buf += bytes_read; 1197 if (copy_to_user(buf + done, tape->cur, todo))
1547 count -= bytes_read;
1548 actually_read += bytes_read;
1549 }
1550 if (count) {
1551 bytes_read = idetape_add_chrdev_read_request(drive, ctl);
1552 if (bytes_read <= 0)
1553 goto finish;
1554 temp = min((unsigned long)count, (unsigned long)bytes_read);
1555 if (idetape_copy_stage_to_user(tape, buf, temp))
1556 ret = -EFAULT; 1198 ret = -EFAULT;
1557 actually_read += temp; 1199
1558 tape->merge_bh_size = bytes_read-temp; 1200 tape->cur += todo;
1201 tape->valid -= todo;
1202 done += todo;
1559 } 1203 }
1560finish: 1204
1561 if (!actually_read && test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags)) { 1205 if (!done && test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags)) {
1562 debug_log(DBG_SENSE, "%s: spacing over filemark\n", tape->name); 1206 debug_log(DBG_SENSE, "%s: spacing over filemark\n", tape->name);
1563 1207
1564 idetape_space_over_filemarks(drive, MTFSF, 1); 1208 idetape_space_over_filemarks(drive, MTFSF, 1);
1565 return 0; 1209 return 0;
1566 } 1210 }
1567 1211
1568 return ret ? ret : actually_read; 1212 return ret ? ret : done;
1569} 1213}
1570 1214
1571static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf, 1215static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
@@ -1573,9 +1217,9 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
1573{ 1217{
1574 struct ide_tape_obj *tape = file->private_data; 1218 struct ide_tape_obj *tape = file->private_data;
1575 ide_drive_t *drive = tape->drive; 1219 ide_drive_t *drive = tape->drive;
1576 ssize_t actually_written = 0; 1220 size_t done = 0;
1577 ssize_t ret = 0; 1221 ssize_t ret = 0;
1578 u16 ctl = *(u16 *)&tape->caps[12]; 1222 int rc;
1579 1223
1580 /* The drive is write protected. */ 1224 /* The drive is write protected. */
1581 if (tape->write_prot) 1225 if (tape->write_prot)
@@ -1584,80 +1228,31 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
1584 debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count); 1228 debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count);
1585 1229
1586 /* Initialize write operation */ 1230 /* Initialize write operation */
1587 if (tape->chrdev_dir != IDETAPE_DIR_WRITE) { 1231 rc = idetape_init_rw(drive, IDETAPE_DIR_WRITE);
1588 if (tape->chrdev_dir == IDETAPE_DIR_READ) 1232 if (rc < 0)
1589 ide_tape_discard_merge_buffer(drive, 1); 1233 return rc;
1590 if (tape->merge_bh || tape->merge_bh_size) {
1591 printk(KERN_ERR "ide-tape: merge_bh_size "
1592 "should be 0 now\n");
1593 tape->merge_bh_size = 0;
1594 }
1595 tape->merge_bh = ide_tape_kmalloc_buffer(tape, 0, 0);
1596 if (!tape->merge_bh)
1597 return -ENOMEM;
1598 tape->chrdev_dir = IDETAPE_DIR_WRITE;
1599 idetape_init_merge_buffer(tape);
1600 1234
1601 /* 1235 while (done < count) {
1602 * Issue a write 0 command to ensure that DSC handshake is 1236 size_t todo;
1603 * switched from completion mode to buffer available mode. No 1237
1604 * point in issuing this if DSC overlap isn't supported, some 1238 /* flush if staging buffer is full */
1605 * drives (Seagate STT3401A) will return an error. 1239 if (tape->valid == tape->buffer_size &&
1606 */ 1240 idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE,
1607 if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) { 1241 tape->buffer_size) <= 0)
1608 ssize_t retval = idetape_queue_rw_tail(drive, 1242 return rc;
1609 REQ_IDETAPE_WRITE, 0, 1243
1610 tape->merge_bh); 1244 /* copy in */
1611 if (retval < 0) { 1245 todo = min_t(size_t, count - done,
1612 ide_tape_kfree_buffer(tape); 1246 tape->buffer_size - tape->valid);
1613 tape->merge_bh = NULL; 1247 if (copy_from_user(tape->cur, buf + done, todo))
1614 tape->chrdev_dir = IDETAPE_DIR_NONE;
1615 return retval;
1616 }
1617 }
1618 }
1619 if (count == 0)
1620 return (0);
1621 if (tape->merge_bh_size) {
1622 if (tape->merge_bh_size >= tape->buffer_size) {
1623 printk(KERN_ERR "ide-tape: bug: merge buf too big\n");
1624 tape->merge_bh_size = 0;
1625 }
1626 actually_written = min((unsigned int)
1627 (tape->buffer_size - tape->merge_bh_size),
1628 (unsigned int)count);
1629 if (idetape_copy_stage_from_user(tape, buf, actually_written))
1630 ret = -EFAULT;
1631 buf += actually_written;
1632 tape->merge_bh_size += actually_written;
1633 count -= actually_written;
1634
1635 if (tape->merge_bh_size == tape->buffer_size) {
1636 ssize_t retval;
1637 tape->merge_bh_size = 0;
1638 retval = idetape_add_chrdev_write_request(drive, ctl);
1639 if (retval <= 0)
1640 return (retval);
1641 }
1642 }
1643 while (count >= tape->buffer_size) {
1644 ssize_t retval;
1645 if (idetape_copy_stage_from_user(tape, buf, tape->buffer_size))
1646 ret = -EFAULT;
1647 buf += tape->buffer_size;
1648 count -= tape->buffer_size;
1649 retval = idetape_add_chrdev_write_request(drive, ctl);
1650 actually_written += tape->buffer_size;
1651 if (retval <= 0)
1652 return (retval);
1653 }
1654 if (count) {
1655 actually_written += count;
1656 if (idetape_copy_stage_from_user(tape, buf, count))
1657 ret = -EFAULT; 1248 ret = -EFAULT;
1658 tape->merge_bh_size += count; 1249
1250 tape->cur += todo;
1251 tape->valid += todo;
1252 done += todo;
1659 } 1253 }
1660 return ret ? ret : actually_written; 1254
1255 return ret ? ret : done;
1661} 1256}
1662 1257
1663static int idetape_write_filemark(ide_drive_t *drive) 1258static int idetape_write_filemark(ide_drive_t *drive)
@@ -1818,7 +1413,7 @@ static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
1818 idetape_flush_tape_buffers(drive); 1413 idetape_flush_tape_buffers(drive);
1819 } 1414 }
1820 if (cmd == MTIOCGET || cmd == MTIOCPOS) { 1415 if (cmd == MTIOCGET || cmd == MTIOCPOS) {
1821 block_offset = tape->merge_bh_size / 1416 block_offset = tape->valid /
1822 (tape->blk_size * tape->user_bs_factor); 1417 (tape->blk_size * tape->user_bs_factor);
1823 position = idetape_read_position(drive); 1418 position = idetape_read_position(drive);
1824 if (position < 0) 1419 if (position < 0)
@@ -1966,12 +1561,12 @@ static void idetape_write_release(ide_drive_t *drive, unsigned int minor)
1966 idetape_tape_t *tape = drive->driver_data; 1561 idetape_tape_t *tape = drive->driver_data;
1967 1562
1968 ide_tape_flush_merge_buffer(drive); 1563 ide_tape_flush_merge_buffer(drive);
1969 tape->merge_bh = ide_tape_kmalloc_buffer(tape, 1, 0); 1564 tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL);
1970 if (tape->merge_bh != NULL) { 1565 if (tape->buf != NULL) {
1971 idetape_pad_zeros(drive, tape->blk_size * 1566 idetape_pad_zeros(drive, tape->blk_size *
1972 (tape->user_bs_factor - 1)); 1567 (tape->user_bs_factor - 1));
1973 ide_tape_kfree_buffer(tape); 1568 kfree(tape->buf);
1974 tape->merge_bh = NULL; 1569 tape->buf = NULL;
1975 } 1570 }
1976 idetape_write_filemark(drive); 1571 idetape_write_filemark(drive);
1977 idetape_flush_tape_buffers(drive); 1572 idetape_flush_tape_buffers(drive);
@@ -2165,8 +1760,6 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2165 u16 *ctl = (u16 *)&tape->caps[12]; 1760 u16 *ctl = (u16 *)&tape->caps[12];
2166 1761
2167 drive->pc_callback = ide_tape_callback; 1762 drive->pc_callback = ide_tape_callback;
2168 drive->pc_update_buffers = idetape_update_buffers;
2169 drive->pc_io_buffers = ide_tape_io_buffers;
2170 1763
2171 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP; 1764 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
2172 1765
@@ -2197,11 +1790,6 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2197 tape->buffer_size = *ctl * tape->blk_size; 1790 tape->buffer_size = *ctl * tape->blk_size;
2198 } 1791 }
2199 buffer_size = tape->buffer_size; 1792 buffer_size = tape->buffer_size;
2200 tape->pages_per_buffer = buffer_size / PAGE_SIZE;
2201 if (buffer_size % PAGE_SIZE) {
2202 tape->pages_per_buffer++;
2203 tape->excess_bh_size = PAGE_SIZE - buffer_size % PAGE_SIZE;
2204 }
2205 1793
2206 /* select the "best" DSC read/write polling freq */ 1794 /* select the "best" DSC read/write polling freq */
2207 speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]); 1795 speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]);
@@ -2244,7 +1832,7 @@ static void ide_tape_release(struct device *dev)
2244 ide_drive_t *drive = tape->drive; 1832 ide_drive_t *drive = tape->drive;
2245 struct gendisk *g = tape->disk; 1833 struct gendisk *g = tape->disk;
2246 1834
2247 BUG_ON(tape->merge_bh_size); 1835 BUG_ON(tape->valid);
2248 1836
2249 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP; 1837 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
2250 drive->driver_data = NULL; 1838 drive->driver_data = NULL;
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 4aa6223c11be..a0c3e1b2f73c 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -385,7 +385,7 @@ out_end:
385 if ((cmd->tf_flags & IDE_TFLAG_FS) == 0) 385 if ((cmd->tf_flags & IDE_TFLAG_FS) == 0)
386 ide_finish_cmd(drive, cmd, stat); 386 ide_finish_cmd(drive, cmd, stat);
387 else 387 else
388 ide_complete_rq(drive, 0, cmd->rq->nr_sectors << 9); 388 ide_complete_rq(drive, 0, blk_rq_sectors(cmd->rq) << 9);
389 return ide_stopped; 389 return ide_stopped;
390out_err: 390out_err:
391 ide_error_cmd(drive, cmd); 391 ide_error_cmd(drive, cmd);
@@ -424,7 +424,9 @@ int ide_raw_taskfile(ide_drive_t *drive, struct ide_cmd *cmd, u8 *buf,
424 424
425 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 425 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
426 rq->cmd_type = REQ_TYPE_ATA_TASKFILE; 426 rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
427 rq->buffer = buf; 427
428 if (cmd->tf_flags & IDE_TFLAG_WRITE)
429 rq->cmd_flags |= REQ_RW;
428 430
429 /* 431 /*
430 * (ks) We transfer currently only whole sectors. 432 * (ks) We transfer currently only whole sectors.
@@ -432,18 +434,20 @@ int ide_raw_taskfile(ide_drive_t *drive, struct ide_cmd *cmd, u8 *buf,
432 * if we would find a solution to transfer any size. 434 * if we would find a solution to transfer any size.
433 * To support special commands like READ LONG. 435 * To support special commands like READ LONG.
434 */ 436 */
435 rq->hard_nr_sectors = rq->nr_sectors = nsect; 437 if (nsect) {
436 rq->hard_cur_sectors = rq->current_nr_sectors = nsect; 438 error = blk_rq_map_kern(drive->queue, rq, buf,
437 439 nsect * SECTOR_SIZE, __GFP_WAIT);
438 if (cmd->tf_flags & IDE_TFLAG_WRITE) 440 if (error)
439 rq->cmd_flags |= REQ_RW; 441 goto put_req;
442 }
440 443
441 rq->special = cmd; 444 rq->special = cmd;
442 cmd->rq = rq; 445 cmd->rq = rq;
443 446
444 error = blk_execute_rq(drive->queue, NULL, rq, 0); 447 error = blk_execute_rq(drive->queue, NULL, rq, 0);
445 blk_put_request(rq);
446 448
449put_req:
450 blk_put_request(rq);
447 return error; 451 return error;
448} 452}
449 453
diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
index 248a54bd2386..e24ecc87a9b1 100644
--- a/drivers/ide/pdc202xx_old.c
+++ b/drivers/ide/pdc202xx_old.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org> 2 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>
3 * Copyright (C) 2006-2007 MontaVista Software, Inc. 3 * Copyright (C) 2006-2007, 2009 MontaVista Software, Inc.
4 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz 4 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
5 * 5 *
6 * Portions Copyright (C) 1999 Promise Technology, Inc. 6 * Portions Copyright (C) 1999 Promise Technology, Inc.
@@ -177,7 +177,7 @@ static void pdc202xx_dma_start(ide_drive_t *drive)
177 u8 clock = inb(high_16 + 0x11); 177 u8 clock = inb(high_16 + 0x11);
178 178
179 outb(clock | (hwif->channel ? 0x08 : 0x02), high_16 + 0x11); 179 outb(clock | (hwif->channel ? 0x08 : 0x02), high_16 + 0x11);
180 word_count = (rq->nr_sectors << 8); 180 word_count = (blk_rq_sectors(rq) << 8);
181 word_count = (rq_data_dir(rq) == READ) ? 181 word_count = (rq_data_dir(rq) == READ) ?
182 word_count | 0x05000000 : 182 word_count | 0x05000000 :
183 word_count | 0x06000000; 183 word_count | 0x06000000;
@@ -227,28 +227,19 @@ somebody_else:
227 return (dma_stat & 4) == 4; /* return 1 if INTR asserted */ 227 return (dma_stat & 4) == 4; /* return 1 if INTR asserted */
228} 228}
229 229
230static void pdc202xx_reset_host (ide_hwif_t *hwif) 230static void pdc202xx_reset(ide_drive_t *drive)
231{ 231{
232 ide_hwif_t *hwif = drive->hwif;
232 unsigned long high_16 = hwif->extra_base - 16; 233 unsigned long high_16 = hwif->extra_base - 16;
233 u8 udma_speed_flag = inb(high_16 | 0x001f); 234 u8 udma_speed_flag = inb(high_16 | 0x001f);
234 235
236 printk(KERN_WARNING "PDC202xx: software reset...\n");
237
235 outb(udma_speed_flag | 0x10, high_16 | 0x001f); 238 outb(udma_speed_flag | 0x10, high_16 | 0x001f);
236 mdelay(100); 239 mdelay(100);
237 outb(udma_speed_flag & ~0x10, high_16 | 0x001f); 240 outb(udma_speed_flag & ~0x10, high_16 | 0x001f);
238 mdelay(2000); /* 2 seconds ?! */ 241 mdelay(2000); /* 2 seconds ?! */
239 242
240 printk(KERN_WARNING "PDC202XX: %s channel reset.\n",
241 hwif->channel ? "Secondary" : "Primary");
242}
243
244static void pdc202xx_reset (ide_drive_t *drive)
245{
246 ide_hwif_t *hwif = drive->hwif;
247 ide_hwif_t *mate = hwif->mate;
248
249 pdc202xx_reset_host(hwif);
250 pdc202xx_reset_host(mate);
251
252 ide_set_max_pio(drive); 243 ide_set_max_pio(drive);
253} 244}
254 245
@@ -328,9 +319,8 @@ static const struct ide_dma_ops pdc20246_dma_ops = {
328 .dma_start = ide_dma_start, 319 .dma_start = ide_dma_start,
329 .dma_end = ide_dma_end, 320 .dma_end = ide_dma_end,
330 .dma_test_irq = pdc202xx_dma_test_irq, 321 .dma_test_irq = pdc202xx_dma_test_irq,
331 .dma_lost_irq = pdc202xx_dma_lost_irq, 322 .dma_lost_irq = ide_dma_lost_irq,
332 .dma_timer_expiry = ide_dma_sff_timer_expiry, 323 .dma_timer_expiry = ide_dma_sff_timer_expiry,
333 .dma_clear = pdc202xx_reset,
334 .dma_sff_read_status = ide_dma_sff_read_status, 324 .dma_sff_read_status = ide_dma_sff_read_status,
335}; 325};
336 326
diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
index 2aa699933064..69860dea3820 100644
--- a/drivers/ide/piix.c
+++ b/drivers/ide/piix.c
@@ -263,6 +263,7 @@ static const struct ich_laptop ich_laptop[] = {
263 { 0x24CA, 0x1025, 0x003d }, /* ICH4 on ACER TM290 */ 263 { 0x24CA, 0x1025, 0x003d }, /* ICH4 on ACER TM290 */
264 { 0x266F, 0x1025, 0x0066 }, /* ICH6 on ACER Aspire 1694WLMi */ 264 { 0x266F, 0x1025, 0x0066 }, /* ICH6 on ACER Aspire 1694WLMi */
265 { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */ 265 { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */
266 { 0x27df, 0x104d, 0x900e }, /* ICH7 on Sony TZ-90 */
266 /* end marker */ 267 /* end marker */
267 { 0, } 268 { 0, }
268}; 269};
diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
index b4cf42dc8a6f..05a93d6baecc 100644
--- a/drivers/ide/tc86c001.c
+++ b/drivers/ide/tc86c001.c
@@ -112,7 +112,7 @@ static void tc86c001_dma_start(ide_drive_t *drive)
112 ide_hwif_t *hwif = drive->hwif; 112 ide_hwif_t *hwif = drive->hwif;
113 unsigned long sc_base = hwif->config_data; 113 unsigned long sc_base = hwif->config_data;
114 unsigned long twcr_port = sc_base + (drive->dn ? 0x06 : 0x04); 114 unsigned long twcr_port = sc_base + (drive->dn ? 0x06 : 0x04);
115 unsigned long nsectors = hwif->rq->nr_sectors; 115 unsigned long nsectors = blk_rq_sectors(hwif->rq);
116 116
117 /* 117 /*
118 * We have to manually load the sector count and size into 118 * We have to manually load the sector count and size into
diff --git a/drivers/ide/tx4939ide.c b/drivers/ide/tx4939ide.c
index 564422d23976..5ca76224f6d1 100644
--- a/drivers/ide/tx4939ide.c
+++ b/drivers/ide/tx4939ide.c
@@ -307,7 +307,7 @@ static int tx4939ide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
307 tx4939ide_writew(SECTOR_SIZE / 2, base, drive->dn ? 307 tx4939ide_writew(SECTOR_SIZE / 2, base, drive->dn ?
308 TX4939IDE_Xfer_Cnt_2 : TX4939IDE_Xfer_Cnt_1); 308 TX4939IDE_Xfer_Cnt_2 : TX4939IDE_Xfer_Cnt_1);
309 309
310 tx4939ide_writew(cmd->rq->nr_sectors, base, TX4939IDE_Sec_Cnt); 310 tx4939ide_writew(blk_rq_sectors(cmd->rq), base, TX4939IDE_Sec_Cnt);
311 311
312 return 0; 312 return 0;
313} 313}
diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
index 3ff7231e4858..028de26a25fe 100644
--- a/drivers/ide/via82cxxx.c
+++ b/drivers/ide/via82cxxx.c
@@ -67,6 +67,7 @@ static struct via_isa_bridge {
67 u8 udma_mask; 67 u8 udma_mask;
68 u8 flags; 68 u8 flags;
69} via_isa_bridges[] = { 69} via_isa_bridges[] = {
70 { "vx855", PCI_DEVICE_ID_VIA_VX855, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
70 { "vx800", PCI_DEVICE_ID_VIA_VX800, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, 71 { "vx800", PCI_DEVICE_ID_VIA_VX800, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
71 { "cx700", PCI_DEVICE_ID_VIA_CX700, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, 72 { "cx700", PCI_DEVICE_ID_VIA_CX700, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
72 { "vt8237s", PCI_DEVICE_ID_VIA_8237S, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, 73 { "vt8237s", PCI_DEVICE_ID_VIA_8237S, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
@@ -474,6 +475,7 @@ static const struct pci_device_id via_pci_tbl[] = {
474 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C576_1), 0 }, 475 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C576_1), 0 },
475 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C586_1), 0 }, 476 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C586_1), 0 },
476 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_CX700_IDE), 0 }, 477 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_CX700_IDE), 0 },
478 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_VX855_IDE), 0 },
477 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_6410), 1 }, 479 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_6410), 1 },
478 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_SATA_EIDE), 1 }, 480 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_SATA_EIDE), 1 },
479 { 0, }, 481 { 0, },