aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/st.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/st.c')
-rw-r--r--drivers/scsi/st.c279
1 files changed, 126 insertions, 153 deletions
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index dd592f6a2529..c4aade8f5345 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -17,7 +17,7 @@
17 Last modified: 18-JAN-1998 Richard Gooch <rgooch@atnf.csiro.au> Devfs support 17 Last modified: 18-JAN-1998 Richard Gooch <rgooch@atnf.csiro.au> Devfs support
18 */ 18 */
19 19
20static char *verstr = "20050830"; 20static const char *verstr = "20050830";
21 21
22#include <linux/module.h> 22#include <linux/module.h>
23 23
@@ -50,7 +50,6 @@ static char *verstr = "20050830";
50#include <scsi/scsi_eh.h> 50#include <scsi/scsi_eh.h>
51#include <scsi/scsi_host.h> 51#include <scsi/scsi_host.h>
52#include <scsi/scsi_ioctl.h> 52#include <scsi/scsi_ioctl.h>
53#include <scsi/scsi_request.h>
54#include <scsi/sg.h> 53#include <scsi/sg.h>
55 54
56 55
@@ -134,7 +133,7 @@ static struct st_dev_parm {
134#endif 133#endif
135/* Bit reversed order to get same names for same minors with all 134/* Bit reversed order to get same names for same minors with all
136 mode counts */ 135 mode counts */
137static char *st_formats[] = { 136static const char *st_formats[] = {
138 "", "r", "k", "s", "l", "t", "o", "u", 137 "", "r", "k", "s", "l", "t", "o", "u",
139 "m", "v", "p", "x", "a", "y", "q", "z"}; 138 "m", "v", "p", "x", "a", "y", "q", "z"};
140 139
@@ -188,8 +187,6 @@ static int from_buffer(struct st_buffer *, char __user *, int);
188static void move_buffer_data(struct st_buffer *, int); 187static void move_buffer_data(struct st_buffer *, int);
189static void buf_to_sg(struct st_buffer *, unsigned int); 188static void buf_to_sg(struct st_buffer *, unsigned int);
190 189
191static int st_map_user_pages(struct scatterlist *, const unsigned int,
192 unsigned long, size_t, int, unsigned long);
193static int sgl_map_user_pages(struct scatterlist *, const unsigned int, 190static int sgl_map_user_pages(struct scatterlist *, const unsigned int,
194 unsigned long, size_t, int); 191 unsigned long, size_t, int);
195static int sgl_unmap_user_pages(struct scatterlist *, const unsigned int, int); 192static int sgl_unmap_user_pages(struct scatterlist *, const unsigned int, int);
@@ -313,12 +310,13 @@ static inline char *tape_name(struct scsi_tape *tape)
313} 310}
314 311
315 312
316static void st_analyze_sense(struct scsi_request *SRpnt, struct st_cmdstatus *s) 313static void st_analyze_sense(struct st_request *SRpnt, struct st_cmdstatus *s)
317{ 314{
318 const u8 *ucp; 315 const u8 *ucp;
319 const u8 *sense = SRpnt->sr_sense_buffer; 316 const u8 *sense = SRpnt->sense;
320 317
321 s->have_sense = scsi_request_normalize_sense(SRpnt, &s->sense_hdr); 318 s->have_sense = scsi_normalize_sense(SRpnt->sense,
319 SCSI_SENSE_BUFFERSIZE, &s->sense_hdr);
322 s->flags = 0; 320 s->flags = 0;
323 321
324 if (s->have_sense) { 322 if (s->have_sense) {
@@ -345,9 +343,9 @@ static void st_analyze_sense(struct scsi_request *SRpnt, struct st_cmdstatus *s)
345 343
346 344
347/* Convert the result to success code */ 345/* Convert the result to success code */
348static int st_chk_result(struct scsi_tape *STp, struct scsi_request * SRpnt) 346static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt)
349{ 347{
350 int result = SRpnt->sr_result; 348 int result = SRpnt->result;
351 u8 scode; 349 u8 scode;
352 DEB(const char *stp;) 350 DEB(const char *stp;)
353 char *name = tape_name(STp); 351 char *name = tape_name(STp);
@@ -366,13 +364,12 @@ static int st_chk_result(struct scsi_tape *STp, struct scsi_request * SRpnt)
366 364
367 DEB( 365 DEB(
368 if (debugging) { 366 if (debugging) {
369 printk(ST_DEB_MSG "%s: Error: %x, cmd: %x %x %x %x %x %x Len: %d\n", 367 printk(ST_DEB_MSG "%s: Error: %x, cmd: %x %x %x %x %x %x\n",
370 name, result, 368 name, result,
371 SRpnt->sr_cmnd[0], SRpnt->sr_cmnd[1], SRpnt->sr_cmnd[2], 369 SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2],
372 SRpnt->sr_cmnd[3], SRpnt->sr_cmnd[4], SRpnt->sr_cmnd[5], 370 SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]);
373 SRpnt->sr_bufflen);
374 if (cmdstatp->have_sense) 371 if (cmdstatp->have_sense)
375 scsi_print_req_sense("st", SRpnt); 372 __scsi_print_sense("st", SRpnt->sense, SCSI_SENSE_BUFFERSIZE);
376 } ) /* end DEB */ 373 } ) /* end DEB */
377 if (!debugging) { /* Abnormal conditions for tape */ 374 if (!debugging) { /* Abnormal conditions for tape */
378 if (!cmdstatp->have_sense) 375 if (!cmdstatp->have_sense)
@@ -386,20 +383,21 @@ static int st_chk_result(struct scsi_tape *STp, struct scsi_request * SRpnt)
386 /* scode != UNIT_ATTENTION && */ 383 /* scode != UNIT_ATTENTION && */
387 scode != BLANK_CHECK && 384 scode != BLANK_CHECK &&
388 scode != VOLUME_OVERFLOW && 385 scode != VOLUME_OVERFLOW &&
389 SRpnt->sr_cmnd[0] != MODE_SENSE && 386 SRpnt->cmd[0] != MODE_SENSE &&
390 SRpnt->sr_cmnd[0] != TEST_UNIT_READY) { 387 SRpnt->cmd[0] != TEST_UNIT_READY) {
391 printk(KERN_WARNING "%s: Error with sense data: ", name); 388 printk(KERN_WARNING "%s: Error with sense data: ", name);
392 scsi_print_req_sense("st", SRpnt); 389 __scsi_print_sense("st", SRpnt->sense,
390 SCSI_SENSE_BUFFERSIZE);
393 } 391 }
394 } 392 }
395 393
396 if (cmdstatp->fixed_format && 394 if (cmdstatp->fixed_format &&
397 STp->cln_mode >= EXTENDED_SENSE_START) { /* Only fixed format sense */ 395 STp->cln_mode >= EXTENDED_SENSE_START) { /* Only fixed format sense */
398 if (STp->cln_sense_value) 396 if (STp->cln_sense_value)
399 STp->cleaning_req |= ((SRpnt->sr_sense_buffer[STp->cln_mode] & 397 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] &
400 STp->cln_sense_mask) == STp->cln_sense_value); 398 STp->cln_sense_mask) == STp->cln_sense_value);
401 else 399 else
402 STp->cleaning_req |= ((SRpnt->sr_sense_buffer[STp->cln_mode] & 400 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] &
403 STp->cln_sense_mask) != 0); 401 STp->cln_sense_mask) != 0);
404 } 402 }
405 if (cmdstatp->have_sense && 403 if (cmdstatp->have_sense &&
@@ -411,8 +409,8 @@ static int st_chk_result(struct scsi_tape *STp, struct scsi_request * SRpnt)
411 if (cmdstatp->have_sense && 409 if (cmdstatp->have_sense &&
412 scode == RECOVERED_ERROR 410 scode == RECOVERED_ERROR
413#if ST_RECOVERED_WRITE_FATAL 411#if ST_RECOVERED_WRITE_FATAL
414 && SRpnt->sr_cmnd[0] != WRITE_6 412 && SRpnt->cmd[0] != WRITE_6
415 && SRpnt->sr_cmnd[0] != WRITE_FILEMARKS 413 && SRpnt->cmd[0] != WRITE_FILEMARKS
416#endif 414#endif
417 ) { 415 ) {
418 STp->recover_count++; 416 STp->recover_count++;
@@ -420,9 +418,9 @@ static int st_chk_result(struct scsi_tape *STp, struct scsi_request * SRpnt)
420 418
421 DEB( 419 DEB(
422 if (debugging) { 420 if (debugging) {
423 if (SRpnt->sr_cmnd[0] == READ_6) 421 if (SRpnt->cmd[0] == READ_6)
424 stp = "read"; 422 stp = "read";
425 else if (SRpnt->sr_cmnd[0] == WRITE_6) 423 else if (SRpnt->cmd[0] == WRITE_6)
426 stp = "write"; 424 stp = "write";
427 else 425 else
428 stp = "ioctl"; 426 stp = "ioctl";
@@ -438,28 +436,37 @@ static int st_chk_result(struct scsi_tape *STp, struct scsi_request * SRpnt)
438 436
439 437
440/* Wakeup from interrupt */ 438/* Wakeup from interrupt */
441static void st_sleep_done(struct scsi_cmnd * SCpnt) 439static void st_sleep_done(void *data, char *sense, int result, int resid)
442{ 440{
443 struct scsi_tape *STp = container_of(SCpnt->request->rq_disk->private_data, 441 struct st_request *SRpnt = data;
444 struct scsi_tape, driver); 442 struct scsi_tape *STp = SRpnt->stp;
445 443
446 (STp->buffer)->cmdstat.midlevel_result = SCpnt->result; 444 memcpy(SRpnt->sense, sense, SCSI_SENSE_BUFFERSIZE);
447 SCpnt->request->rq_status = RQ_SCSI_DONE; 445 (STp->buffer)->cmdstat.midlevel_result = SRpnt->result = result;
448 DEB( STp->write_pending = 0; ) 446 DEB( STp->write_pending = 0; )
449 447
450 if (SCpnt->request->waiting) 448 if (SRpnt->waiting)
451 complete(SCpnt->request->waiting); 449 complete(SRpnt->waiting);
450}
451
452static struct st_request *st_allocate_request(void)
453{
454 return kzalloc(sizeof(struct st_request), GFP_KERNEL);
455}
456
457static void st_release_request(struct st_request *streq)
458{
459 kfree(streq);
452} 460}
453 461
454/* Do the scsi command. Waits until command performed if do_wait is true. 462/* Do the scsi command. Waits until command performed if do_wait is true.
455 Otherwise write_behind_check() is used to check that the command 463 Otherwise write_behind_check() is used to check that the command
456 has finished. */ 464 has finished. */
457static struct scsi_request * 465static struct st_request *
458st_do_scsi(struct scsi_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd, 466st_do_scsi(struct st_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd,
459 int bytes, int direction, int timeout, int retries, int do_wait) 467 int bytes, int direction, int timeout, int retries, int do_wait)
460{ 468{
461 struct completion *waiting; 469 struct completion *waiting;
462 unsigned char *bp;
463 470
464 /* if async, make sure there's no command outstanding */ 471 /* if async, make sure there's no command outstanding */
465 if (!do_wait && ((STp->buffer)->last_SRpnt)) { 472 if (!do_wait && ((STp->buffer)->last_SRpnt)) {
@@ -473,7 +480,7 @@ st_do_scsi(struct scsi_request * SRpnt, struct scsi_tape * STp, unsigned char *c
473 } 480 }
474 481
475 if (SRpnt == NULL) { 482 if (SRpnt == NULL) {
476 SRpnt = scsi_allocate_request(STp->device, GFP_ATOMIC); 483 SRpnt = st_allocate_request();
477 if (SRpnt == NULL) { 484 if (SRpnt == NULL) {
478 DEBC( printk(KERN_ERR "%s: Can't get SCSI request.\n", 485 DEBC( printk(KERN_ERR "%s: Can't get SCSI request.\n",
479 tape_name(STp)); ); 486 tape_name(STp)); );
@@ -483,6 +490,7 @@ st_do_scsi(struct scsi_request * SRpnt, struct scsi_tape * STp, unsigned char *c
483 (STp->buffer)->syscall_result = (-EBUSY); 490 (STp->buffer)->syscall_result = (-EBUSY);
484 return NULL; 491 return NULL;
485 } 492 }
493 SRpnt->stp = STp;
486 } 494 }
487 495
488 /* If async IO, set last_SRpnt. This ptr tells write_behind_check 496 /* If async IO, set last_SRpnt. This ptr tells write_behind_check
@@ -492,32 +500,28 @@ st_do_scsi(struct scsi_request * SRpnt, struct scsi_tape * STp, unsigned char *c
492 500
493 waiting = &STp->wait; 501 waiting = &STp->wait;
494 init_completion(waiting); 502 init_completion(waiting);
495 SRpnt->sr_use_sg = STp->buffer->do_dio || (bytes > (STp->buffer)->frp[0].length); 503 SRpnt->waiting = waiting;
496 if (SRpnt->sr_use_sg) {
497 if (!STp->buffer->do_dio)
498 buf_to_sg(STp->buffer, bytes);
499 SRpnt->sr_use_sg = (STp->buffer)->sg_segs;
500 bp = (char *) &((STp->buffer)->sg[0]);
501 } else
502 bp = (STp->buffer)->b_data;
503 SRpnt->sr_data_direction = direction;
504 SRpnt->sr_cmd_len = 0;
505 SRpnt->sr_request->waiting = waiting;
506 SRpnt->sr_request->rq_status = RQ_SCSI_BUSY;
507 SRpnt->sr_request->rq_disk = STp->disk;
508 SRpnt->sr_request->end_io = blk_end_sync_rq;
509 STp->buffer->cmdstat.have_sense = 0;
510 504
511 scsi_do_req(SRpnt, (void *) cmd, bp, bytes, 505 if (!STp->buffer->do_dio)
512 st_sleep_done, timeout, retries); 506 buf_to_sg(STp->buffer, bytes);
513 507
514 if (do_wait) { 508 memcpy(SRpnt->cmd, cmd, sizeof(SRpnt->cmd));
509 STp->buffer->cmdstat.have_sense = 0;
510 STp->buffer->syscall_result = 0;
511
512 if (scsi_execute_async(STp->device, cmd, direction,
513 &((STp->buffer)->sg[0]), bytes, (STp->buffer)->sg_segs,
514 timeout, retries, SRpnt, st_sleep_done, GFP_KERNEL)) {
515 /* could not allocate the buffer or request was too large */
516 (STp->buffer)->syscall_result = (-EBUSY);
517 (STp->buffer)->last_SRpnt = NULL;
518 }
519 else if (do_wait) {
515 wait_for_completion(waiting); 520 wait_for_completion(waiting);
516 SRpnt->sr_request->waiting = NULL; 521 SRpnt->waiting = NULL;
517 if (SRpnt->sr_request->rq_status != RQ_SCSI_DONE)
518 SRpnt->sr_result |= (DRIVER_ERROR << 24);
519 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); 522 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt);
520 } 523 }
524
521 return SRpnt; 525 return SRpnt;
522} 526}
523 527
@@ -532,7 +536,7 @@ static int write_behind_check(struct scsi_tape * STp)
532 struct st_buffer *STbuffer; 536 struct st_buffer *STbuffer;
533 struct st_partstat *STps; 537 struct st_partstat *STps;
534 struct st_cmdstatus *cmdstatp; 538 struct st_cmdstatus *cmdstatp;
535 struct scsi_request *SRpnt; 539 struct st_request *SRpnt;
536 540
537 STbuffer = STp->buffer; 541 STbuffer = STp->buffer;
538 if (!STbuffer->writing) 542 if (!STbuffer->writing)
@@ -548,12 +552,10 @@ static int write_behind_check(struct scsi_tape * STp)
548 wait_for_completion(&(STp->wait)); 552 wait_for_completion(&(STp->wait));
549 SRpnt = STbuffer->last_SRpnt; 553 SRpnt = STbuffer->last_SRpnt;
550 STbuffer->last_SRpnt = NULL; 554 STbuffer->last_SRpnt = NULL;
551 SRpnt->sr_request->waiting = NULL; 555 SRpnt->waiting = NULL;
552 if (SRpnt->sr_request->rq_status != RQ_SCSI_DONE)
553 SRpnt->sr_result |= (DRIVER_ERROR << 24);
554 556
555 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); 557 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt);
556 scsi_release_request(SRpnt); 558 st_release_request(SRpnt);
557 559
558 STbuffer->buffer_bytes -= STbuffer->writing; 560 STbuffer->buffer_bytes -= STbuffer->writing;
559 STps = &(STp->ps[STp->partition]); 561 STps = &(STp->ps[STp->partition]);
@@ -593,7 +595,7 @@ static int write_behind_check(struct scsi_tape * STp)
593 it messes up the block number). */ 595 it messes up the block number). */
594static int cross_eof(struct scsi_tape * STp, int forward) 596static int cross_eof(struct scsi_tape * STp, int forward)
595{ 597{
596 struct scsi_request *SRpnt; 598 struct st_request *SRpnt;
597 unsigned char cmd[MAX_COMMAND_SIZE]; 599 unsigned char cmd[MAX_COMMAND_SIZE];
598 600
599 cmd[0] = SPACE; 601 cmd[0] = SPACE;
@@ -613,7 +615,7 @@ static int cross_eof(struct scsi_tape * STp, int forward)
613 if (!SRpnt) 615 if (!SRpnt)
614 return (STp->buffer)->syscall_result; 616 return (STp->buffer)->syscall_result;
615 617
616 scsi_release_request(SRpnt); 618 st_release_request(SRpnt);
617 SRpnt = NULL; 619 SRpnt = NULL;
618 620
619 if ((STp->buffer)->cmdstat.midlevel_result != 0) 621 if ((STp->buffer)->cmdstat.midlevel_result != 0)
@@ -630,7 +632,7 @@ static int flush_write_buffer(struct scsi_tape * STp)
630 int offset, transfer, blks; 632 int offset, transfer, blks;
631 int result; 633 int result;
632 unsigned char cmd[MAX_COMMAND_SIZE]; 634 unsigned char cmd[MAX_COMMAND_SIZE];
633 struct scsi_request *SRpnt; 635 struct st_request *SRpnt;
634 struct st_partstat *STps; 636 struct st_partstat *STps;
635 637
636 result = write_behind_check(STp); 638 result = write_behind_check(STp);
@@ -688,7 +690,7 @@ static int flush_write_buffer(struct scsi_tape * STp)
688 STp->dirty = 0; 690 STp->dirty = 0;
689 (STp->buffer)->buffer_bytes = 0; 691 (STp->buffer)->buffer_bytes = 0;
690 } 692 }
691 scsi_release_request(SRpnt); 693 st_release_request(SRpnt);
692 SRpnt = NULL; 694 SRpnt = NULL;
693 } 695 }
694 return result; 696 return result;
@@ -785,7 +787,7 @@ static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm)
785} 787}
786 788
787 789
788/* Lock or unlock the drive door. Don't use when scsi_request allocated. */ 790/* Lock or unlock the drive door. Don't use when st_request allocated. */
789static int do_door_lock(struct scsi_tape * STp, int do_lock) 791static int do_door_lock(struct scsi_tape * STp, int do_lock)
790{ 792{
791 int retval, cmd; 793 int retval, cmd;
@@ -844,7 +846,7 @@ static int test_ready(struct scsi_tape *STp, int do_wait)
844 int attentions, waits, max_wait, scode; 846 int attentions, waits, max_wait, scode;
845 int retval = CHKRES_READY, new_session = 0; 847 int retval = CHKRES_READY, new_session = 0;
846 unsigned char cmd[MAX_COMMAND_SIZE]; 848 unsigned char cmd[MAX_COMMAND_SIZE];
847 struct scsi_request *SRpnt = NULL; 849 struct st_request *SRpnt = NULL;
848 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; 850 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
849 851
850 max_wait = do_wait ? ST_BLOCK_SECONDS : 0; 852 max_wait = do_wait ? ST_BLOCK_SECONDS : 0;
@@ -903,7 +905,7 @@ static int test_ready(struct scsi_tape *STp, int do_wait)
903 } 905 }
904 906
905 if (SRpnt != NULL) 907 if (SRpnt != NULL)
906 scsi_release_request(SRpnt); 908 st_release_request(SRpnt);
907 return retval; 909 return retval;
908} 910}
909 911
@@ -918,7 +920,7 @@ static int check_tape(struct scsi_tape *STp, struct file *filp)
918 int i, retval, new_session = 0, do_wait; 920 int i, retval, new_session = 0, do_wait;
919 unsigned char cmd[MAX_COMMAND_SIZE], saved_cleaning; 921 unsigned char cmd[MAX_COMMAND_SIZE], saved_cleaning;
920 unsigned short st_flags = filp->f_flags; 922 unsigned short st_flags = filp->f_flags;
921 struct scsi_request *SRpnt = NULL; 923 struct st_request *SRpnt = NULL;
922 struct st_modedef *STm; 924 struct st_modedef *STm;
923 struct st_partstat *STps; 925 struct st_partstat *STps;
924 char *name = tape_name(STp); 926 char *name = tape_name(STp);
@@ -993,7 +995,7 @@ static int check_tape(struct scsi_tape *STp, struct file *filp)
993 goto err_out; 995 goto err_out;
994 } 996 }
995 997
996 if (!SRpnt->sr_result && !STp->buffer->cmdstat.have_sense) { 998 if (!SRpnt->result && !STp->buffer->cmdstat.have_sense) {
997 STp->max_block = ((STp->buffer)->b_data[1] << 16) | 999 STp->max_block = ((STp->buffer)->b_data[1] << 16) |
998 ((STp->buffer)->b_data[2] << 8) | (STp->buffer)->b_data[3]; 1000 ((STp->buffer)->b_data[2] << 8) | (STp->buffer)->b_data[3];
999 STp->min_block = ((STp->buffer)->b_data[4] << 8) | 1001 STp->min_block = ((STp->buffer)->b_data[4] << 8) |
@@ -1045,7 +1047,7 @@ static int check_tape(struct scsi_tape *STp, struct file *filp)
1045 } 1047 }
1046 STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0; 1048 STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0;
1047 } 1049 }
1048 scsi_release_request(SRpnt); 1050 st_release_request(SRpnt);
1049 SRpnt = NULL; 1051 SRpnt = NULL;
1050 STp->inited = 1; 1052 STp->inited = 1;
1051 1053
@@ -1196,7 +1198,7 @@ static int st_flush(struct file *filp)
1196{ 1198{
1197 int result = 0, result2; 1199 int result = 0, result2;
1198 unsigned char cmd[MAX_COMMAND_SIZE]; 1200 unsigned char cmd[MAX_COMMAND_SIZE];
1199 struct scsi_request *SRpnt; 1201 struct st_request *SRpnt;
1200 struct scsi_tape *STp = filp->private_data; 1202 struct scsi_tape *STp = filp->private_data;
1201 struct st_modedef *STm = &(STp->modes[STp->current_mode]); 1203 struct st_modedef *STm = &(STp->modes[STp->current_mode]);
1202 struct st_partstat *STps = &(STp->ps[STp->partition]); 1204 struct st_partstat *STps = &(STp->ps[STp->partition]);
@@ -1249,7 +1251,7 @@ static int st_flush(struct file *filp)
1249 cmdstatp->sense_hdr.sense_key == RECOVERED_ERROR) && 1251 cmdstatp->sense_hdr.sense_key == RECOVERED_ERROR) &&
1250 (!cmdstatp->remainder_valid || cmdstatp->uremainder64 == 0))) { 1252 (!cmdstatp->remainder_valid || cmdstatp->uremainder64 == 0))) {
1251 /* Write successful at EOM */ 1253 /* Write successful at EOM */
1252 scsi_release_request(SRpnt); 1254 st_release_request(SRpnt);
1253 SRpnt = NULL; 1255 SRpnt = NULL;
1254 if (STps->drv_file >= 0) 1256 if (STps->drv_file >= 0)
1255 STps->drv_file++; 1257 STps->drv_file++;
@@ -1259,7 +1261,7 @@ static int st_flush(struct file *filp)
1259 STps->eof = ST_FM; 1261 STps->eof = ST_FM;
1260 } 1262 }
1261 else { /* Write error */ 1263 else { /* Write error */
1262 scsi_release_request(SRpnt); 1264 st_release_request(SRpnt);
1263 SRpnt = NULL; 1265 SRpnt = NULL;
1264 printk(KERN_ERR "%s: Error on write filemark.\n", name); 1266 printk(KERN_ERR "%s: Error on write filemark.\n", name);
1265 if (result == 0) 1267 if (result == 0)
@@ -1400,11 +1402,11 @@ static int setup_buffering(struct scsi_tape *STp, const char __user *buf,
1400 i = STp->try_dio && try_rdio; 1402 i = STp->try_dio && try_rdio;
1401 else 1403 else
1402 i = STp->try_dio && try_wdio; 1404 i = STp->try_dio && try_wdio;
1405
1403 if (i && ((unsigned long)buf & queue_dma_alignment( 1406 if (i && ((unsigned long)buf & queue_dma_alignment(
1404 STp->device->request_queue)) == 0) { 1407 STp->device->request_queue)) == 0) {
1405 i = st_map_user_pages(&(STbp->sg[0]), STbp->use_sg, 1408 i = sgl_map_user_pages(&(STbp->sg[0]), STbp->use_sg,
1406 (unsigned long)buf, count, (is_read ? READ : WRITE), 1409 (unsigned long)buf, count, (is_read ? READ : WRITE));
1407 STp->max_pfn);
1408 if (i > 0) { 1410 if (i > 0) {
1409 STbp->do_dio = i; 1411 STbp->do_dio = i;
1410 STbp->buffer_bytes = 0; /* can be used as transfer counter */ 1412 STbp->buffer_bytes = 0; /* can be used as transfer counter */
@@ -1449,14 +1451,15 @@ static int setup_buffering(struct scsi_tape *STp, const char __user *buf,
1449 1451
1450 1452
1451/* Can be called more than once after each setup_buffer() */ 1453/* Can be called more than once after each setup_buffer() */
1452static void release_buffering(struct scsi_tape *STp) 1454static void release_buffering(struct scsi_tape *STp, int is_read)
1453{ 1455{
1454 struct st_buffer *STbp; 1456 struct st_buffer *STbp;
1455 1457
1456 STbp = STp->buffer; 1458 STbp = STp->buffer;
1457 if (STbp->do_dio) { 1459 if (STbp->do_dio) {
1458 sgl_unmap_user_pages(&(STbp->sg[0]), STbp->do_dio, 0); 1460 sgl_unmap_user_pages(&(STbp->sg[0]), STbp->do_dio, is_read);
1459 STbp->do_dio = 0; 1461 STbp->do_dio = 0;
1462 STbp->sg_segs = 0;
1460 } 1463 }
1461} 1464}
1462 1465
@@ -1472,7 +1475,7 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
1472 int async_write; 1475 int async_write;
1473 unsigned char cmd[MAX_COMMAND_SIZE]; 1476 unsigned char cmd[MAX_COMMAND_SIZE];
1474 const char __user *b_point; 1477 const char __user *b_point;
1475 struct scsi_request *SRpnt = NULL; 1478 struct st_request *SRpnt = NULL;
1476 struct scsi_tape *STp = filp->private_data; 1479 struct scsi_tape *STp = filp->private_data;
1477 struct st_modedef *STm; 1480 struct st_modedef *STm;
1478 struct st_partstat *STps; 1481 struct st_partstat *STps;
@@ -1624,7 +1627,7 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
1624 retval = STbp->syscall_result; 1627 retval = STbp->syscall_result;
1625 goto out; 1628 goto out;
1626 } 1629 }
1627 if (async_write) { 1630 if (async_write && !STbp->syscall_result) {
1628 STbp->writing = transfer; 1631 STbp->writing = transfer;
1629 STp->dirty = !(STbp->writing == 1632 STp->dirty = !(STbp->writing ==
1630 STbp->buffer_bytes); 1633 STbp->buffer_bytes);
@@ -1698,7 +1701,7 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
1698 } else { 1701 } else {
1699 count += do_count; 1702 count += do_count;
1700 STps->drv_block = (-1); /* Too cautious? */ 1703 STps->drv_block = (-1); /* Too cautious? */
1701 retval = (-EIO); 1704 retval = STbp->syscall_result;
1702 } 1705 }
1703 1706
1704 } 1707 }
@@ -1728,8 +1731,8 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
1728 1731
1729 out: 1732 out:
1730 if (SRpnt != NULL) 1733 if (SRpnt != NULL)
1731 scsi_release_request(SRpnt); 1734 st_release_request(SRpnt);
1732 release_buffering(STp); 1735 release_buffering(STp, 0);
1733 up(&STp->lock); 1736 up(&STp->lock);
1734 1737
1735 return retval; 1738 return retval;
@@ -1742,11 +1745,11 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
1742 Does release user buffer mapping if it is set. 1745 Does release user buffer mapping if it is set.
1743*/ 1746*/
1744static long read_tape(struct scsi_tape *STp, long count, 1747static long read_tape(struct scsi_tape *STp, long count,
1745 struct scsi_request ** aSRpnt) 1748 struct st_request ** aSRpnt)
1746{ 1749{
1747 int transfer, blks, bytes; 1750 int transfer, blks, bytes;
1748 unsigned char cmd[MAX_COMMAND_SIZE]; 1751 unsigned char cmd[MAX_COMMAND_SIZE];
1749 struct scsi_request *SRpnt; 1752 struct st_request *SRpnt;
1750 struct st_modedef *STm; 1753 struct st_modedef *STm;
1751 struct st_partstat *STps; 1754 struct st_partstat *STps;
1752 struct st_buffer *STbp; 1755 struct st_buffer *STbp;
@@ -1787,7 +1790,7 @@ static long read_tape(struct scsi_tape *STp, long count,
1787 SRpnt = *aSRpnt; 1790 SRpnt = *aSRpnt;
1788 SRpnt = st_do_scsi(SRpnt, STp, cmd, bytes, DMA_FROM_DEVICE, 1791 SRpnt = st_do_scsi(SRpnt, STp, cmd, bytes, DMA_FROM_DEVICE,
1789 STp->device->timeout, MAX_RETRIES, 1); 1792 STp->device->timeout, MAX_RETRIES, 1);
1790 release_buffering(STp); 1793 release_buffering(STp, 1);
1791 *aSRpnt = SRpnt; 1794 *aSRpnt = SRpnt;
1792 if (!SRpnt) 1795 if (!SRpnt)
1793 return STbp->syscall_result; 1796 return STbp->syscall_result;
@@ -1802,10 +1805,10 @@ static long read_tape(struct scsi_tape *STp, long count,
1802 retval = 1; 1805 retval = 1;
1803 DEBC(printk(ST_DEB_MSG "%s: Sense: %2x %2x %2x %2x %2x %2x %2x %2x\n", 1806 DEBC(printk(ST_DEB_MSG "%s: Sense: %2x %2x %2x %2x %2x %2x %2x %2x\n",
1804 name, 1807 name,
1805 SRpnt->sr_sense_buffer[0], SRpnt->sr_sense_buffer[1], 1808 SRpnt->sense[0], SRpnt->sense[1],
1806 SRpnt->sr_sense_buffer[2], SRpnt->sr_sense_buffer[3], 1809 SRpnt->sense[2], SRpnt->sense[3],
1807 SRpnt->sr_sense_buffer[4], SRpnt->sr_sense_buffer[5], 1810 SRpnt->sense[4], SRpnt->sense[5],
1808 SRpnt->sr_sense_buffer[6], SRpnt->sr_sense_buffer[7])); 1811 SRpnt->sense[6], SRpnt->sense[7]));
1809 if (cmdstatp->have_sense) { 1812 if (cmdstatp->have_sense) {
1810 1813
1811 if (cmdstatp->sense_hdr.sense_key == BLANK_CHECK) 1814 if (cmdstatp->sense_hdr.sense_key == BLANK_CHECK)
@@ -1835,7 +1838,7 @@ static long read_tape(struct scsi_tape *STp, long count,
1835 } 1838 }
1836 STbp->buffer_bytes = bytes - transfer; 1839 STbp->buffer_bytes = bytes - transfer;
1837 } else { 1840 } else {
1838 scsi_release_request(SRpnt); 1841 st_release_request(SRpnt);
1839 SRpnt = *aSRpnt = NULL; 1842 SRpnt = *aSRpnt = NULL;
1840 if (transfer == blks) { /* We did not get anything, error */ 1843 if (transfer == blks) { /* We did not get anything, error */
1841 printk(KERN_NOTICE "%s: Incorrect block size.\n", name); 1844 printk(KERN_NOTICE "%s: Incorrect block size.\n", name);
@@ -1929,7 +1932,7 @@ st_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos)
1929 ssize_t retval = 0; 1932 ssize_t retval = 0;
1930 ssize_t i, transfer; 1933 ssize_t i, transfer;
1931 int special, do_dio = 0; 1934 int special, do_dio = 0;
1932 struct scsi_request *SRpnt = NULL; 1935 struct st_request *SRpnt = NULL;
1933 struct scsi_tape *STp = filp->private_data; 1936 struct scsi_tape *STp = filp->private_data;
1934 struct st_modedef *STm; 1937 struct st_modedef *STm;
1935 struct st_partstat *STps; 1938 struct st_partstat *STps;
@@ -2054,11 +2057,11 @@ st_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos)
2054 2057
2055 out: 2058 out:
2056 if (SRpnt != NULL) { 2059 if (SRpnt != NULL) {
2057 scsi_release_request(SRpnt); 2060 st_release_request(SRpnt);
2058 SRpnt = NULL; 2061 SRpnt = NULL;
2059 } 2062 }
2060 if (do_dio) { 2063 if (do_dio) {
2061 release_buffering(STp); 2064 release_buffering(STp, 1);
2062 STbp->buffer_bytes = 0; 2065 STbp->buffer_bytes = 0;
2063 } 2066 }
2064 up(&STp->lock); 2067 up(&STp->lock);
@@ -2284,7 +2287,7 @@ static int st_set_options(struct scsi_tape *STp, long options)
2284static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs) 2287static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs)
2285{ 2288{
2286 unsigned char cmd[MAX_COMMAND_SIZE]; 2289 unsigned char cmd[MAX_COMMAND_SIZE];
2287 struct scsi_request *SRpnt = NULL; 2290 struct st_request *SRpnt = NULL;
2288 2291
2289 memset(cmd, 0, MAX_COMMAND_SIZE); 2292 memset(cmd, 0, MAX_COMMAND_SIZE);
2290 cmd[0] = MODE_SENSE; 2293 cmd[0] = MODE_SENSE;
@@ -2298,7 +2301,7 @@ static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs)
2298 if (SRpnt == NULL) 2301 if (SRpnt == NULL)
2299 return (STp->buffer)->syscall_result; 2302 return (STp->buffer)->syscall_result;
2300 2303
2301 scsi_release_request(SRpnt); 2304 st_release_request(SRpnt);
2302 2305
2303 return (STp->buffer)->syscall_result; 2306 return (STp->buffer)->syscall_result;
2304} 2307}
@@ -2310,7 +2313,7 @@ static int write_mode_page(struct scsi_tape *STp, int page, int slow)
2310{ 2313{
2311 int pgo; 2314 int pgo;
2312 unsigned char cmd[MAX_COMMAND_SIZE]; 2315 unsigned char cmd[MAX_COMMAND_SIZE];
2313 struct scsi_request *SRpnt = NULL; 2316 struct st_request *SRpnt = NULL;
2314 2317
2315 memset(cmd, 0, MAX_COMMAND_SIZE); 2318 memset(cmd, 0, MAX_COMMAND_SIZE);
2316 cmd[0] = MODE_SELECT; 2319 cmd[0] = MODE_SELECT;
@@ -2329,7 +2332,7 @@ static int write_mode_page(struct scsi_tape *STp, int page, int slow)
2329 if (SRpnt == NULL) 2332 if (SRpnt == NULL)
2330 return (STp->buffer)->syscall_result; 2333 return (STp->buffer)->syscall_result;
2331 2334
2332 scsi_release_request(SRpnt); 2335 st_release_request(SRpnt);
2333 2336
2334 return (STp->buffer)->syscall_result; 2337 return (STp->buffer)->syscall_result;
2335} 2338}
@@ -2412,7 +2415,7 @@ static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_cod
2412 DEB( char *name = tape_name(STp); ) 2415 DEB( char *name = tape_name(STp); )
2413 unsigned char cmd[MAX_COMMAND_SIZE]; 2416 unsigned char cmd[MAX_COMMAND_SIZE];
2414 struct st_partstat *STps; 2417 struct st_partstat *STps;
2415 struct scsi_request *SRpnt; 2418 struct st_request *SRpnt;
2416 2419
2417 if (STp->ready != ST_READY && !load_code) { 2420 if (STp->ready != ST_READY && !load_code) {
2418 if (STp->ready == ST_NO_TAPE) 2421 if (STp->ready == ST_NO_TAPE)
@@ -2455,7 +2458,7 @@ static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_cod
2455 return (STp->buffer)->syscall_result; 2458 return (STp->buffer)->syscall_result;
2456 2459
2457 retval = (STp->buffer)->syscall_result; 2460 retval = (STp->buffer)->syscall_result;
2458 scsi_release_request(SRpnt); 2461 st_release_request(SRpnt);
2459 2462
2460 if (!retval) { /* SCSI command successful */ 2463 if (!retval) { /* SCSI command successful */
2461 2464
@@ -2503,7 +2506,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
2503 int ioctl_result; 2506 int ioctl_result;
2504 int chg_eof = 1; 2507 int chg_eof = 1;
2505 unsigned char cmd[MAX_COMMAND_SIZE]; 2508 unsigned char cmd[MAX_COMMAND_SIZE];
2506 struct scsi_request *SRpnt; 2509 struct st_request *SRpnt;
2507 struct st_partstat *STps; 2510 struct st_partstat *STps;
2508 int fileno, blkno, at_sm, undone; 2511 int fileno, blkno, at_sm, undone;
2509 int datalen = 0, direction = DMA_NONE; 2512 int datalen = 0, direction = DMA_NONE;
@@ -2757,7 +2760,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
2757 ioctl_result = (STp->buffer)->syscall_result; 2760 ioctl_result = (STp->buffer)->syscall_result;
2758 2761
2759 if (!ioctl_result) { /* SCSI command successful */ 2762 if (!ioctl_result) { /* SCSI command successful */
2760 scsi_release_request(SRpnt); 2763 st_release_request(SRpnt);
2761 SRpnt = NULL; 2764 SRpnt = NULL;
2762 STps->drv_block = blkno; 2765 STps->drv_block = blkno;
2763 STps->drv_file = fileno; 2766 STps->drv_file = fileno;
@@ -2872,7 +2875,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
2872 /* Try the other possible state of Page Format if not 2875 /* Try the other possible state of Page Format if not
2873 already tried */ 2876 already tried */
2874 STp->use_pf = !STp->use_pf | PF_TESTED; 2877 STp->use_pf = !STp->use_pf | PF_TESTED;
2875 scsi_release_request(SRpnt); 2878 st_release_request(SRpnt);
2876 SRpnt = NULL; 2879 SRpnt = NULL;
2877 return st_int_ioctl(STp, cmd_in, arg); 2880 return st_int_ioctl(STp, cmd_in, arg);
2878 } 2881 }
@@ -2882,7 +2885,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
2882 if (cmdstatp->sense_hdr.sense_key == BLANK_CHECK) 2885 if (cmdstatp->sense_hdr.sense_key == BLANK_CHECK)
2883 STps->eof = ST_EOD; 2886 STps->eof = ST_EOD;
2884 2887
2885 scsi_release_request(SRpnt); 2888 st_release_request(SRpnt);
2886 SRpnt = NULL; 2889 SRpnt = NULL;
2887 } 2890 }
2888 2891
@@ -2898,7 +2901,7 @@ static int get_location(struct scsi_tape *STp, unsigned int *block, int *partiti
2898{ 2901{
2899 int result; 2902 int result;
2900 unsigned char scmd[MAX_COMMAND_SIZE]; 2903 unsigned char scmd[MAX_COMMAND_SIZE];
2901 struct scsi_request *SRpnt; 2904 struct st_request *SRpnt;
2902 DEB( char *name = tape_name(STp); ) 2905 DEB( char *name = tape_name(STp); )
2903 2906
2904 if (STp->ready != ST_READY) 2907 if (STp->ready != ST_READY)
@@ -2944,7 +2947,7 @@ static int get_location(struct scsi_tape *STp, unsigned int *block, int *partiti
2944 DEBC(printk(ST_DEB_MSG "%s: Got tape pos. blk %d part %d.\n", name, 2947 DEBC(printk(ST_DEB_MSG "%s: Got tape pos. blk %d part %d.\n", name,
2945 *block, *partition)); 2948 *block, *partition));
2946 } 2949 }
2947 scsi_release_request(SRpnt); 2950 st_release_request(SRpnt);
2948 SRpnt = NULL; 2951 SRpnt = NULL;
2949 2952
2950 return result; 2953 return result;
@@ -2961,7 +2964,7 @@ static int set_location(struct scsi_tape *STp, unsigned int block, int partition
2961 unsigned int blk; 2964 unsigned int blk;
2962 int timeout; 2965 int timeout;
2963 unsigned char scmd[MAX_COMMAND_SIZE]; 2966 unsigned char scmd[MAX_COMMAND_SIZE];
2964 struct scsi_request *SRpnt; 2967 struct st_request *SRpnt;
2965 DEB( char *name = tape_name(STp); ) 2968 DEB( char *name = tape_name(STp); )
2966 2969
2967 if (STp->ready != ST_READY) 2970 if (STp->ready != ST_READY)
@@ -3047,7 +3050,7 @@ static int set_location(struct scsi_tape *STp, unsigned int block, int partition
3047 result = 0; 3050 result = 0;
3048 } 3051 }
3049 3052
3050 scsi_release_request(SRpnt); 3053 st_release_request(SRpnt);
3051 SRpnt = NULL; 3054 SRpnt = NULL;
3052 3055
3053 return result; 3056 return result;
@@ -3577,7 +3580,7 @@ static long st_compat_ioctl(struct file *file, unsigned int cmd, unsigned long a
3577static struct st_buffer * 3580static struct st_buffer *
3578 new_tape_buffer(int from_initialization, int need_dma, int max_sg) 3581 new_tape_buffer(int from_initialization, int need_dma, int max_sg)
3579{ 3582{
3580 int i, got = 0, segs = 0; 3583 int i, got = 0;
3581 gfp_t priority; 3584 gfp_t priority;
3582 struct st_buffer *tb; 3585 struct st_buffer *tb;
3583 3586
@@ -3594,10 +3597,8 @@ static struct st_buffer *
3594 return NULL; 3597 return NULL;
3595 } 3598 }
3596 memset(tb, 0, i); 3599 memset(tb, 0, i);
3597 tb->frp_segs = tb->orig_frp_segs = segs; 3600 tb->frp_segs = tb->orig_frp_segs = 0;
3598 tb->use_sg = max_sg; 3601 tb->use_sg = max_sg;
3599 if (segs > 0)
3600 tb->b_data = page_address(tb->sg[0].page);
3601 tb->frp = (struct st_buf_fragment *)(&(tb->sg[0]) + max_sg); 3602 tb->frp = (struct st_buf_fragment *)(&(tb->sg[0]) + max_sg);
3602 3603
3603 tb->in_use = 1; 3604 tb->in_use = 1;
@@ -3628,7 +3629,7 @@ static int enlarge_buffer(struct st_buffer * STbuffer, int new_size, int need_dm
3628 priority = GFP_KERNEL | __GFP_NOWARN; 3629 priority = GFP_KERNEL | __GFP_NOWARN;
3629 if (need_dma) 3630 if (need_dma)
3630 priority |= GFP_DMA; 3631 priority |= GFP_DMA;
3631 for (b_size = PAGE_SIZE, order=0; 3632 for (b_size = PAGE_SIZE, order=0; order <= 6 &&
3632 b_size < new_size - STbuffer->buffer_size; 3633 b_size < new_size - STbuffer->buffer_size;
3633 order++, b_size *= 2) 3634 order++, b_size *= 2)
3634 ; /* empty */ 3635 ; /* empty */
@@ -3670,6 +3671,7 @@ static void normalize_buffer(struct st_buffer * STbuffer)
3670 } 3671 }
3671 STbuffer->frp_segs = STbuffer->orig_frp_segs; 3672 STbuffer->frp_segs = STbuffer->orig_frp_segs;
3672 STbuffer->frp_sg_current = 0; 3673 STbuffer->frp_sg_current = 0;
3674 STbuffer->sg_segs = 0;
3673} 3675}
3674 3676
3675 3677
@@ -3882,7 +3884,6 @@ static int st_probe(struct device *dev)
3882 struct st_buffer *buffer; 3884 struct st_buffer *buffer;
3883 int i, j, mode, dev_num, error; 3885 int i, j, mode, dev_num, error;
3884 char *stp; 3886 char *stp;
3885 u64 bounce_limit;
3886 3887
3887 if (SDp->type != TYPE_TAPE) 3888 if (SDp->type != TYPE_TAPE)
3888 return -ENODEV; 3889 return -ENODEV;
@@ -3892,7 +3893,8 @@ static int st_probe(struct device *dev)
3892 return -ENODEV; 3893 return -ENODEV;
3893 } 3894 }
3894 3895
3895 i = SDp->host->sg_tablesize; 3896 i = min(SDp->request_queue->max_hw_segments,
3897 SDp->request_queue->max_phys_segments);
3896 if (st_max_sg_segs < i) 3898 if (st_max_sg_segs < i)
3897 i = st_max_sg_segs; 3899 i = st_max_sg_segs;
3898 buffer = new_tape_buffer(1, (SDp->host)->unchecked_isa_dma, i); 3900 buffer = new_tape_buffer(1, (SDp->host)->unchecked_isa_dma, i);
@@ -3994,11 +3996,6 @@ static int st_probe(struct device *dev)
3994 tpnt->long_timeout = ST_LONG_TIMEOUT; 3996 tpnt->long_timeout = ST_LONG_TIMEOUT;
3995 tpnt->try_dio = try_direct_io && !SDp->host->unchecked_isa_dma; 3997 tpnt->try_dio = try_direct_io && !SDp->host->unchecked_isa_dma;
3996 3998
3997 bounce_limit = scsi_calculate_bounce_limit(SDp->host) >> PAGE_SHIFT;
3998 if (bounce_limit > ULONG_MAX)
3999 bounce_limit = ULONG_MAX;
4000 tpnt->max_pfn = bounce_limit;
4001
4002 for (i = 0; i < ST_NBR_MODES; i++) { 3999 for (i = 0; i < ST_NBR_MODES; i++) {
4003 STm = &(tpnt->modes[i]); 4000 STm = &(tpnt->modes[i]);
4004 STm->defined = 0; 4001 STm->defined = 0;
@@ -4077,9 +4074,9 @@ static int st_probe(struct device *dev)
4077 4074
4078 sdev_printk(KERN_WARNING, SDp, 4075 sdev_printk(KERN_WARNING, SDp,
4079 "Attached scsi tape %s", tape_name(tpnt)); 4076 "Attached scsi tape %s", tape_name(tpnt));
4080 printk(KERN_WARNING "%s: try direct i/o: %s (alignment %d B), max page reachable by HBA %lu\n", 4077 printk(KERN_WARNING "%s: try direct i/o: %s (alignment %d B)\n",
4081 tape_name(tpnt), tpnt->try_dio ? "yes" : "no", 4078 tape_name(tpnt), tpnt->try_dio ? "yes" : "no",
4082 queue_dma_alignment(SDp->request_queue) + 1, tpnt->max_pfn); 4079 queue_dma_alignment(SDp->request_queue) + 1);
4083 4080
4084 return 0; 4081 return 0;
4085 4082
@@ -4185,7 +4182,11 @@ static void scsi_tape_release(struct kref *kref)
4185 4182
4186static void st_intr(struct scsi_cmnd *SCpnt) 4183static void st_intr(struct scsi_cmnd *SCpnt)
4187{ 4184{
4188 scsi_io_completion(SCpnt, (SCpnt->result ? 0: SCpnt->bufflen), 1); 4185 /*
4186 * The caller should be checking the request's errors
4187 * value.
4188 */
4189 scsi_io_completion(SCpnt, SCpnt->bufflen, 0);
4189} 4190}
4190 4191
4191/* 4192/*
@@ -4197,7 +4198,7 @@ static int st_init_command(struct scsi_cmnd *SCpnt)
4197 if (!(SCpnt->request->flags & REQ_BLOCK_PC)) 4198 if (!(SCpnt->request->flags & REQ_BLOCK_PC))
4198 return 0; 4199 return 0;
4199 4200
4200 scsi_setup_blk_pc_cmnd(SCpnt, 0); 4201 scsi_setup_blk_pc_cmnd(SCpnt);
4201 SCpnt->done = st_intr; 4202 SCpnt->done = st_intr;
4202 return 1; 4203 return 1;
4203} 4204}
@@ -4390,34 +4391,6 @@ static void do_create_class_files(struct scsi_tape *STp, int dev_num, int mode)
4390 return; 4391 return;
4391} 4392}
4392 4393
4393
4394/* Pin down user pages and put them into a scatter gather list. Returns <= 0 if
4395 - mapping of all pages not successful
4396 - any page is above max_pfn
4397 (i.e., either completely successful or fails)
4398*/
4399static int st_map_user_pages(struct scatterlist *sgl, const unsigned int max_pages,
4400 unsigned long uaddr, size_t count, int rw,
4401 unsigned long max_pfn)
4402{
4403 int i, nr_pages;
4404
4405 nr_pages = sgl_map_user_pages(sgl, max_pages, uaddr, count, rw);
4406 if (nr_pages <= 0)
4407 return nr_pages;
4408
4409 for (i=0; i < nr_pages; i++) {
4410 if (page_to_pfn(sgl[i].page) > max_pfn)
4411 goto out_unmap;
4412 }
4413 return nr_pages;
4414
4415 out_unmap:
4416 sgl_unmap_user_pages(sgl, nr_pages, 0);
4417 return 0;
4418}
4419
4420
4421/* The following functions may be useful for a larger audience. */ 4394/* The following functions may be useful for a larger audience. */
4422static int sgl_map_user_pages(struct scatterlist *sgl, const unsigned int max_pages, 4395static int sgl_map_user_pages(struct scatterlist *sgl, const unsigned int max_pages,
4423 unsigned long uaddr, size_t count, int rw) 4396 unsigned long uaddr, size_t count, int rw)