Commit 8b05b773b6030de5b1bab1cbb0bf1ff8c34cdbe0

Authored by Mike Christie
Committed by James Bottomley
1 parent d6b10348f9

[SCSI] convert st to use scsi_execute_async

convert st to always send scatterlists and kill scsi_request
usage.

This is the same as last time as it was posted, but with Kai's patches
merged and we now pass the bytes value to scsi_execute_async.

TODO:

- move DIO code to common place or make block layers usable for ULDs.
- move buffer allocation code to common place for all ULDs to use. And
make buffer allocation code handle all queue limits so we can find
out about problems before calling scsi_execute_async.
- move indirect (copy_to/from_user) paths commone place or make block
layers usable for ULDs.

Signed-off-by: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>

Showing 2 changed files with 123 additions and 145 deletions Side-by-side Diff

... ... @@ -50,7 +50,6 @@
50 50 #include <scsi/scsi_eh.h>
51 51 #include <scsi/scsi_host.h>
52 52 #include <scsi/scsi_ioctl.h>
53   -#include <scsi/scsi_request.h>
54 53 #include <scsi/sg.h>
55 54  
56 55  
... ... @@ -188,8 +187,6 @@
188 187 static void move_buffer_data(struct st_buffer *, int);
189 188 static void buf_to_sg(struct st_buffer *, unsigned int);
190 189  
191   -static int st_map_user_pages(struct scatterlist *, const unsigned int,
192   - unsigned long, size_t, int, unsigned long);
193 190 static int sgl_map_user_pages(struct scatterlist *, const unsigned int,
194 191 unsigned long, size_t, int);
195 192 static int sgl_unmap_user_pages(struct scatterlist *, const unsigned int, int);
196 193  
197 194  
... ... @@ -313,12 +310,13 @@
313 310 }
314 311  
315 312  
316   -static void st_analyze_sense(struct scsi_request *SRpnt, struct st_cmdstatus *s)
  313 +static void st_analyze_sense(struct st_request *SRpnt, struct st_cmdstatus *s)
317 314 {
318 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 320 s->flags = 0;
323 321  
324 322 if (s->have_sense) {
325 323  
... ... @@ -345,9 +343,9 @@
345 343  
346 344  
347 345 /* Convert the result to success code */
348   -static int st_chk_result(struct scsi_tape *STp, struct scsi_request * SRpnt)
  346 +static 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 349 u8 scode;
352 350 DEB(const char *stp;)
353 351 char *name = tape_name(STp);
354 352  
355 353  
... ... @@ -366,13 +364,12 @@
366 364  
367 365 DEB(
368 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 368 name, result,
371   - SRpnt->sr_cmnd[0], SRpnt->sr_cmnd[1], SRpnt->sr_cmnd[2],
372   - SRpnt->sr_cmnd[3], SRpnt->sr_cmnd[4], SRpnt->sr_cmnd[5],
373   - SRpnt->sr_bufflen);
  369 + SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2],
  370 + SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]);
374 371 if (cmdstatp->have_sense)
375   - scsi_print_req_sense("st", SRpnt);
  372 + __scsi_print_sense("st", SRpnt->sense, SCSI_SENSE_BUFFERSIZE);
376 373 } ) /* end DEB */
377 374 if (!debugging) { /* Abnormal conditions for tape */
378 375 if (!cmdstatp->have_sense)
379 376  
380 377  
381 378  
... ... @@ -386,20 +383,21 @@
386 383 /* scode != UNIT_ATTENTION && */
387 384 scode != BLANK_CHECK &&
388 385 scode != VOLUME_OVERFLOW &&
389   - SRpnt->sr_cmnd[0] != MODE_SENSE &&
390   - SRpnt->sr_cmnd[0] != TEST_UNIT_READY) {
  386 + SRpnt->cmd[0] != MODE_SENSE &&
  387 + SRpnt->cmd[0] != TEST_UNIT_READY) {
391 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 394 if (cmdstatp->fixed_format &&
397 395 STp->cln_mode >= EXTENDED_SENSE_START) { /* Only fixed format sense */
398 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 398 STp->cln_sense_mask) == STp->cln_sense_value);
401 399 else
402   - STp->cleaning_req |= ((SRpnt->sr_sense_buffer[STp->cln_mode] &
  400 + STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] &
403 401 STp->cln_sense_mask) != 0);
404 402 }
405 403 if (cmdstatp->have_sense &&
... ... @@ -411,8 +409,8 @@
411 409 if (cmdstatp->have_sense &&
412 410 scode == RECOVERED_ERROR
413 411 #if ST_RECOVERED_WRITE_FATAL
414   - && SRpnt->sr_cmnd[0] != WRITE_6
415   - && SRpnt->sr_cmnd[0] != WRITE_FILEMARKS
  412 + && SRpnt->cmd[0] != WRITE_6
  413 + && SRpnt->cmd[0] != WRITE_FILEMARKS
416 414 #endif
417 415 ) {
418 416 STp->recover_count++;
419 417  
... ... @@ -420,9 +418,9 @@
420 418  
421 419 DEB(
422 420 if (debugging) {
423   - if (SRpnt->sr_cmnd[0] == READ_6)
  421 + if (SRpnt->cmd[0] == READ_6)
424 422 stp = "read";
425   - else if (SRpnt->sr_cmnd[0] == WRITE_6)
  423 + else if (SRpnt->cmd[0] == WRITE_6)
426 424 stp = "write";
427 425 else
428 426 stp = "ioctl";
429 427  
430 428  
431 429  
432 430  
433 431  
434 432  
... ... @@ -438,28 +436,37 @@
438 436  
439 437  
440 438 /* Wakeup from interrupt */
441   -static void st_sleep_done(struct scsi_cmnd * SCpnt)
  439 +static 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,
444   - struct scsi_tape, driver);
  441 + struct st_request *SRpnt = data;
  442 + struct scsi_tape *STp = SRpnt->stp;
445 443  
446   - (STp->buffer)->cmdstat.midlevel_result = SCpnt->result;
447   - SCpnt->request->rq_status = RQ_SCSI_DONE;
  444 + memcpy(SRpnt->sense, sense, SCSI_SENSE_BUFFERSIZE);
  445 + (STp->buffer)->cmdstat.midlevel_result = SRpnt->result = result;
448 446 DEB( STp->write_pending = 0; )
449 447  
450   - if (SCpnt->request->waiting)
451   - complete(SCpnt->request->waiting);
  448 + if (SRpnt->waiting)
  449 + complete(SRpnt->waiting);
452 450 }
453 451  
  452 +static struct st_request *st_allocate_request(void)
  453 +{
  454 + return kzalloc(sizeof(struct st_request), GFP_KERNEL);
  455 +}
  456 +
  457 +static void st_release_request(struct st_request *streq)
  458 +{
  459 + kfree(streq);
  460 +}
  461 +
454 462 /* Do the scsi command. Waits until command performed if do_wait is true.
455 463 Otherwise write_behind_check() is used to check that the command
456 464 has finished. */
457   -static struct scsi_request *
458   -st_do_scsi(struct scsi_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd,
  465 +static struct st_request *
  466 +st_do_scsi(struct st_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd,
459 467 int bytes, int direction, int timeout, int retries, int do_wait)
460 468 {
461 469 struct completion *waiting;
462   - unsigned char *bp;
463 470  
464 471 /* if async, make sure there's no command outstanding */
465 472 if (!do_wait && ((STp->buffer)->last_SRpnt)) {
... ... @@ -473,7 +480,7 @@
473 480 }
474 481  
475 482 if (SRpnt == NULL) {
476   - SRpnt = scsi_allocate_request(STp->device, GFP_ATOMIC);
  483 + SRpnt = st_allocate_request();
477 484 if (SRpnt == NULL) {
478 485 DEBC( printk(KERN_ERR "%s: Can't get SCSI request.\n",
479 486 tape_name(STp)); );
... ... @@ -483,6 +490,7 @@
483 490 (STp->buffer)->syscall_result = (-EBUSY);
484 491 return NULL;
485 492 }
  493 + SRpnt->stp = STp;
486 494 }
487 495  
488 496 /* If async IO, set last_SRpnt. This ptr tells write_behind_check
489 497  
490 498  
491 499  
492 500  
... ... @@ -492,32 +500,26 @@
492 500  
493 501 waiting = &STp->wait;
494 502 init_completion(waiting);
495   - SRpnt->sr_use_sg = STp->buffer->do_dio || (bytes > (STp->buffer)->frp[0].length);
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;
  503 + SRpnt->waiting = waiting;
510 504  
511   - scsi_do_req(SRpnt, (void *) cmd, bp, bytes,
512   - st_sleep_done, timeout, retries);
  505 + if (!STp->buffer->do_dio)
  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 + else if (do_wait) {
515 518 wait_for_completion(waiting);
516   - SRpnt->sr_request->waiting = NULL;
517   - if (SRpnt->sr_request->rq_status != RQ_SCSI_DONE)
518   - SRpnt->sr_result |= (DRIVER_ERROR << 24);
  519 + SRpnt->waiting = NULL;
519 520 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt);
520 521 }
  522 +
521 523 return SRpnt;
522 524 }
523 525  
... ... @@ -532,7 +534,7 @@
532 534 struct st_buffer *STbuffer;
533 535 struct st_partstat *STps;
534 536 struct st_cmdstatus *cmdstatp;
535   - struct scsi_request *SRpnt;
  537 + struct st_request *SRpnt;
536 538  
537 539 STbuffer = STp->buffer;
538 540 if (!STbuffer->writing)
539 541  
... ... @@ -548,12 +550,10 @@
548 550 wait_for_completion(&(STp->wait));
549 551 SRpnt = STbuffer->last_SRpnt;
550 552 STbuffer->last_SRpnt = NULL;
551   - SRpnt->sr_request->waiting = NULL;
552   - if (SRpnt->sr_request->rq_status != RQ_SCSI_DONE)
553   - SRpnt->sr_result |= (DRIVER_ERROR << 24);
  553 + SRpnt->waiting = NULL;
554 554  
555 555 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt);
556   - scsi_release_request(SRpnt);
  556 + st_release_request(SRpnt);
557 557  
558 558 STbuffer->buffer_bytes -= STbuffer->writing;
559 559 STps = &(STp->ps[STp->partition]);
... ... @@ -593,7 +593,7 @@
593 593 it messes up the block number). */
594 594 static int cross_eof(struct scsi_tape * STp, int forward)
595 595 {
596   - struct scsi_request *SRpnt;
  596 + struct st_request *SRpnt;
597 597 unsigned char cmd[MAX_COMMAND_SIZE];
598 598  
599 599 cmd[0] = SPACE;
... ... @@ -613,7 +613,7 @@
613 613 if (!SRpnt)
614 614 return (STp->buffer)->syscall_result;
615 615  
616   - scsi_release_request(SRpnt);
  616 + st_release_request(SRpnt);
617 617 SRpnt = NULL;
618 618  
619 619 if ((STp->buffer)->cmdstat.midlevel_result != 0)
... ... @@ -630,7 +630,7 @@
630 630 int offset, transfer, blks;
631 631 int result;
632 632 unsigned char cmd[MAX_COMMAND_SIZE];
633   - struct scsi_request *SRpnt;
  633 + struct st_request *SRpnt;
634 634 struct st_partstat *STps;
635 635  
636 636 result = write_behind_check(STp);
... ... @@ -688,7 +688,7 @@
688 688 STp->dirty = 0;
689 689 (STp->buffer)->buffer_bytes = 0;
690 690 }
691   - scsi_release_request(SRpnt);
  691 + st_release_request(SRpnt);
692 692 SRpnt = NULL;
693 693 }
694 694 return result;
... ... @@ -785,7 +785,7 @@
785 785 }
786 786  
787 787  
788   -/* Lock or unlock the drive door. Don't use when scsi_request allocated. */
  788 +/* Lock or unlock the drive door. Don't use when st_request allocated. */
789 789 static int do_door_lock(struct scsi_tape * STp, int do_lock)
790 790 {
791 791 int retval, cmd;
... ... @@ -844,7 +844,7 @@
844 844 int attentions, waits, max_wait, scode;
845 845 int retval = CHKRES_READY, new_session = 0;
846 846 unsigned char cmd[MAX_COMMAND_SIZE];
847   - struct scsi_request *SRpnt = NULL;
  847 + struct st_request *SRpnt = NULL;
848 848 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
849 849  
850 850 max_wait = do_wait ? ST_BLOCK_SECONDS : 0;
... ... @@ -903,7 +903,7 @@
903 903 }
904 904  
905 905 if (SRpnt != NULL)
906   - scsi_release_request(SRpnt);
  906 + st_release_request(SRpnt);
907 907 return retval;
908 908 }
909 909  
... ... @@ -918,7 +918,7 @@
918 918 int i, retval, new_session = 0, do_wait;
919 919 unsigned char cmd[MAX_COMMAND_SIZE], saved_cleaning;
920 920 unsigned short st_flags = filp->f_flags;
921   - struct scsi_request *SRpnt = NULL;
  921 + struct st_request *SRpnt = NULL;
922 922 struct st_modedef *STm;
923 923 struct st_partstat *STps;
924 924 char *name = tape_name(STp);
... ... @@ -993,7 +993,7 @@
993 993 goto err_out;
994 994 }
995 995  
996   - if (!SRpnt->sr_result && !STp->buffer->cmdstat.have_sense) {
  996 + if (!SRpnt->result && !STp->buffer->cmdstat.have_sense) {
997 997 STp->max_block = ((STp->buffer)->b_data[1] << 16) |
998 998 ((STp->buffer)->b_data[2] << 8) | (STp->buffer)->b_data[3];
999 999 STp->min_block = ((STp->buffer)->b_data[4] << 8) |
... ... @@ -1045,7 +1045,7 @@
1045 1045 }
1046 1046 STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0;
1047 1047 }
1048   - scsi_release_request(SRpnt);
  1048 + st_release_request(SRpnt);
1049 1049 SRpnt = NULL;
1050 1050 STp->inited = 1;
1051 1051  
... ... @@ -1196,7 +1196,7 @@
1196 1196 {
1197 1197 int result = 0, result2;
1198 1198 unsigned char cmd[MAX_COMMAND_SIZE];
1199   - struct scsi_request *SRpnt;
  1199 + struct st_request *SRpnt;
1200 1200 struct scsi_tape *STp = filp->private_data;
1201 1201 struct st_modedef *STm = &(STp->modes[STp->current_mode]);
1202 1202 struct st_partstat *STps = &(STp->ps[STp->partition]);
... ... @@ -1249,7 +1249,7 @@
1249 1249 cmdstatp->sense_hdr.sense_key == RECOVERED_ERROR) &&
1250 1250 (!cmdstatp->remainder_valid || cmdstatp->uremainder64 == 0))) {
1251 1251 /* Write successful at EOM */
1252   - scsi_release_request(SRpnt);
  1252 + st_release_request(SRpnt);
1253 1253 SRpnt = NULL;
1254 1254 if (STps->drv_file >= 0)
1255 1255 STps->drv_file++;
... ... @@ -1259,7 +1259,7 @@
1259 1259 STps->eof = ST_FM;
1260 1260 }
1261 1261 else { /* Write error */
1262   - scsi_release_request(SRpnt);
  1262 + st_release_request(SRpnt);
1263 1263 SRpnt = NULL;
1264 1264 printk(KERN_ERR "%s: Error on write filemark.\n", name);
1265 1265 if (result == 0)
1266 1266  
... ... @@ -1400,11 +1400,11 @@
1400 1400 i = STp->try_dio && try_rdio;
1401 1401 else
1402 1402 i = STp->try_dio && try_wdio;
  1403 +
1403 1404 if (i && ((unsigned long)buf & queue_dma_alignment(
1404 1405 STp->device->request_queue)) == 0) {
1405   - i = st_map_user_pages(&(STbp->sg[0]), STbp->use_sg,
1406   - (unsigned long)buf, count, (is_read ? READ : WRITE),
1407   - STp->max_pfn);
  1406 + i = sgl_map_user_pages(&(STbp->sg[0]), STbp->use_sg,
  1407 + (unsigned long)buf, count, (is_read ? READ : WRITE));
1408 1408 if (i > 0) {
1409 1409 STbp->do_dio = i;
1410 1410 STbp->buffer_bytes = 0; /* can be used as transfer counter */
... ... @@ -1472,7 +1472,7 @@
1472 1472 int async_write;
1473 1473 unsigned char cmd[MAX_COMMAND_SIZE];
1474 1474 const char __user *b_point;
1475   - struct scsi_request *SRpnt = NULL;
  1475 + struct st_request *SRpnt = NULL;
1476 1476 struct scsi_tape *STp = filp->private_data;
1477 1477 struct st_modedef *STm;
1478 1478 struct st_partstat *STps;
... ... @@ -1624,7 +1624,7 @@
1624 1624 retval = STbp->syscall_result;
1625 1625 goto out;
1626 1626 }
1627   - if (async_write) {
  1627 + if (async_write && !STbp->syscall_result) {
1628 1628 STbp->writing = transfer;
1629 1629 STp->dirty = !(STbp->writing ==
1630 1630 STbp->buffer_bytes);
... ... @@ -1698,7 +1698,7 @@
1698 1698 } else {
1699 1699 count += do_count;
1700 1700 STps->drv_block = (-1); /* Too cautious? */
1701   - retval = (-EIO);
  1701 + retval = STbp->syscall_result;
1702 1702 }
1703 1703  
1704 1704 }
... ... @@ -1728,7 +1728,7 @@
1728 1728  
1729 1729 out:
1730 1730 if (SRpnt != NULL)
1731   - scsi_release_request(SRpnt);
  1731 + st_release_request(SRpnt);
1732 1732 release_buffering(STp);
1733 1733 up(&STp->lock);
1734 1734  
1735 1735  
... ... @@ -1742,11 +1742,11 @@
1742 1742 Does release user buffer mapping if it is set.
1743 1743 */
1744 1744 static long read_tape(struct scsi_tape *STp, long count,
1745   - struct scsi_request ** aSRpnt)
  1745 + struct st_request ** aSRpnt)
1746 1746 {
1747 1747 int transfer, blks, bytes;
1748 1748 unsigned char cmd[MAX_COMMAND_SIZE];
1749   - struct scsi_request *SRpnt;
  1749 + struct st_request *SRpnt;
1750 1750 struct st_modedef *STm;
1751 1751 struct st_partstat *STps;
1752 1752 struct st_buffer *STbp;
... ... @@ -1802,10 +1802,10 @@
1802 1802 retval = 1;
1803 1803 DEBC(printk(ST_DEB_MSG "%s: Sense: %2x %2x %2x %2x %2x %2x %2x %2x\n",
1804 1804 name,
1805   - SRpnt->sr_sense_buffer[0], SRpnt->sr_sense_buffer[1],
1806   - SRpnt->sr_sense_buffer[2], SRpnt->sr_sense_buffer[3],
1807   - SRpnt->sr_sense_buffer[4], SRpnt->sr_sense_buffer[5],
1808   - SRpnt->sr_sense_buffer[6], SRpnt->sr_sense_buffer[7]));
  1805 + SRpnt->sense[0], SRpnt->sense[1],
  1806 + SRpnt->sense[2], SRpnt->sense[3],
  1807 + SRpnt->sense[4], SRpnt->sense[5],
  1808 + SRpnt->sense[6], SRpnt->sense[7]));
1809 1809 if (cmdstatp->have_sense) {
1810 1810  
1811 1811 if (cmdstatp->sense_hdr.sense_key == BLANK_CHECK)
... ... @@ -1835,7 +1835,7 @@
1835 1835 }
1836 1836 STbp->buffer_bytes = bytes - transfer;
1837 1837 } else {
1838   - scsi_release_request(SRpnt);
  1838 + st_release_request(SRpnt);
1839 1839 SRpnt = *aSRpnt = NULL;
1840 1840 if (transfer == blks) { /* We did not get anything, error */
1841 1841 printk(KERN_NOTICE "%s: Incorrect block size.\n", name);
... ... @@ -1929,7 +1929,7 @@
1929 1929 ssize_t retval = 0;
1930 1930 ssize_t i, transfer;
1931 1931 int special, do_dio = 0;
1932   - struct scsi_request *SRpnt = NULL;
  1932 + struct st_request *SRpnt = NULL;
1933 1933 struct scsi_tape *STp = filp->private_data;
1934 1934 struct st_modedef *STm;
1935 1935 struct st_partstat *STps;
... ... @@ -2054,7 +2054,7 @@
2054 2054  
2055 2055 out:
2056 2056 if (SRpnt != NULL) {
2057   - scsi_release_request(SRpnt);
  2057 + st_release_request(SRpnt);
2058 2058 SRpnt = NULL;
2059 2059 }
2060 2060 if (do_dio) {
... ... @@ -2284,7 +2284,7 @@
2284 2284 static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs)
2285 2285 {
2286 2286 unsigned char cmd[MAX_COMMAND_SIZE];
2287   - struct scsi_request *SRpnt = NULL;
  2287 + struct st_request *SRpnt = NULL;
2288 2288  
2289 2289 memset(cmd, 0, MAX_COMMAND_SIZE);
2290 2290 cmd[0] = MODE_SENSE;
... ... @@ -2298,7 +2298,7 @@
2298 2298 if (SRpnt == NULL)
2299 2299 return (STp->buffer)->syscall_result;
2300 2300  
2301   - scsi_release_request(SRpnt);
  2301 + st_release_request(SRpnt);
2302 2302  
2303 2303 return (STp->buffer)->syscall_result;
2304 2304 }
... ... @@ -2310,7 +2310,7 @@
2310 2310 {
2311 2311 int pgo;
2312 2312 unsigned char cmd[MAX_COMMAND_SIZE];
2313   - struct scsi_request *SRpnt = NULL;
  2313 + struct st_request *SRpnt = NULL;
2314 2314  
2315 2315 memset(cmd, 0, MAX_COMMAND_SIZE);
2316 2316 cmd[0] = MODE_SELECT;
... ... @@ -2329,7 +2329,7 @@
2329 2329 if (SRpnt == NULL)
2330 2330 return (STp->buffer)->syscall_result;
2331 2331  
2332   - scsi_release_request(SRpnt);
  2332 + st_release_request(SRpnt);
2333 2333  
2334 2334 return (STp->buffer)->syscall_result;
2335 2335 }
... ... @@ -2412,7 +2412,7 @@
2412 2412 DEB( char *name = tape_name(STp); )
2413 2413 unsigned char cmd[MAX_COMMAND_SIZE];
2414 2414 struct st_partstat *STps;
2415   - struct scsi_request *SRpnt;
  2415 + struct st_request *SRpnt;
2416 2416  
2417 2417 if (STp->ready != ST_READY && !load_code) {
2418 2418 if (STp->ready == ST_NO_TAPE)
... ... @@ -2455,7 +2455,7 @@
2455 2455 return (STp->buffer)->syscall_result;
2456 2456  
2457 2457 retval = (STp->buffer)->syscall_result;
2458   - scsi_release_request(SRpnt);
  2458 + st_release_request(SRpnt);
2459 2459  
2460 2460 if (!retval) { /* SCSI command successful */
2461 2461  
... ... @@ -2503,7 +2503,7 @@
2503 2503 int ioctl_result;
2504 2504 int chg_eof = 1;
2505 2505 unsigned char cmd[MAX_COMMAND_SIZE];
2506   - struct scsi_request *SRpnt;
  2506 + struct st_request *SRpnt;
2507 2507 struct st_partstat *STps;
2508 2508 int fileno, blkno, at_sm, undone;
2509 2509 int datalen = 0, direction = DMA_NONE;
... ... @@ -2757,7 +2757,7 @@
2757 2757 ioctl_result = (STp->buffer)->syscall_result;
2758 2758  
2759 2759 if (!ioctl_result) { /* SCSI command successful */
2760   - scsi_release_request(SRpnt);
  2760 + st_release_request(SRpnt);
2761 2761 SRpnt = NULL;
2762 2762 STps->drv_block = blkno;
2763 2763 STps->drv_file = fileno;
... ... @@ -2872,7 +2872,7 @@
2872 2872 /* Try the other possible state of Page Format if not
2873 2873 already tried */
2874 2874 STp->use_pf = !STp->use_pf | PF_TESTED;
2875   - scsi_release_request(SRpnt);
  2875 + st_release_request(SRpnt);
2876 2876 SRpnt = NULL;
2877 2877 return st_int_ioctl(STp, cmd_in, arg);
2878 2878 }
... ... @@ -2882,7 +2882,7 @@
2882 2882 if (cmdstatp->sense_hdr.sense_key == BLANK_CHECK)
2883 2883 STps->eof = ST_EOD;
2884 2884  
2885   - scsi_release_request(SRpnt);
  2885 + st_release_request(SRpnt);
2886 2886 SRpnt = NULL;
2887 2887 }
2888 2888  
... ... @@ -2898,7 +2898,7 @@
2898 2898 {
2899 2899 int result;
2900 2900 unsigned char scmd[MAX_COMMAND_SIZE];
2901   - struct scsi_request *SRpnt;
  2901 + struct st_request *SRpnt;
2902 2902 DEB( char *name = tape_name(STp); )
2903 2903  
2904 2904 if (STp->ready != ST_READY)
... ... @@ -2944,7 +2944,7 @@
2944 2944 DEBC(printk(ST_DEB_MSG "%s: Got tape pos. blk %d part %d.\n", name,
2945 2945 *block, *partition));
2946 2946 }
2947   - scsi_release_request(SRpnt);
  2947 + st_release_request(SRpnt);
2948 2948 SRpnt = NULL;
2949 2949  
2950 2950 return result;
... ... @@ -2961,7 +2961,7 @@
2961 2961 unsigned int blk;
2962 2962 int timeout;
2963 2963 unsigned char scmd[MAX_COMMAND_SIZE];
2964   - struct scsi_request *SRpnt;
  2964 + struct st_request *SRpnt;
2965 2965 DEB( char *name = tape_name(STp); )
2966 2966  
2967 2967 if (STp->ready != ST_READY)
... ... @@ -3047,7 +3047,7 @@
3047 3047 result = 0;
3048 3048 }
3049 3049  
3050   - scsi_release_request(SRpnt);
  3050 + st_release_request(SRpnt);
3051 3051 SRpnt = NULL;
3052 3052  
3053 3053 return result;
... ... @@ -3577,7 +3577,7 @@
3577 3577 static struct st_buffer *
3578 3578 new_tape_buffer(int from_initialization, int need_dma, int max_sg)
3579 3579 {
3580   - int i, got = 0, segs = 0;
  3580 + int i, got = 0;
3581 3581 gfp_t priority;
3582 3582 struct st_buffer *tb;
3583 3583  
3584 3584  
... ... @@ -3594,10 +3594,8 @@
3594 3594 return NULL;
3595 3595 }
3596 3596 memset(tb, 0, i);
3597   - tb->frp_segs = tb->orig_frp_segs = segs;
  3597 + tb->frp_segs = tb->orig_frp_segs = 0;
3598 3598 tb->use_sg = max_sg;
3599   - if (segs > 0)
3600   - tb->b_data = page_address(tb->sg[0].page);
3601 3599 tb->frp = (struct st_buf_fragment *)(&(tb->sg[0]) + max_sg);
3602 3600  
3603 3601 tb->in_use = 1;
... ... @@ -3628,7 +3626,7 @@
3628 3626 priority = GFP_KERNEL | __GFP_NOWARN;
3629 3627 if (need_dma)
3630 3628 priority |= GFP_DMA;
3631   - for (b_size = PAGE_SIZE, order=0;
  3629 + for (b_size = PAGE_SIZE, order=0; order <= 6 &&
3632 3630 b_size < new_size - STbuffer->buffer_size;
3633 3631 order++, b_size *= 2)
3634 3632 ; /* empty */
... ... @@ -3670,6 +3668,7 @@
3670 3668 }
3671 3669 STbuffer->frp_segs = STbuffer->orig_frp_segs;
3672 3670 STbuffer->frp_sg_current = 0;
  3671 + STbuffer->sg_segs = 0;
3673 3672 }
3674 3673  
3675 3674  
... ... @@ -3882,7 +3881,6 @@
3882 3881 struct st_buffer *buffer;
3883 3882 int i, j, mode, dev_num, error;
3884 3883 char *stp;
3885   - u64 bounce_limit;
3886 3884  
3887 3885 if (SDp->type != TYPE_TAPE)
3888 3886 return -ENODEV;
... ... @@ -3892,7 +3890,8 @@
3892 3890 return -ENODEV;
3893 3891 }
3894 3892  
3895   - i = SDp->host->sg_tablesize;
  3893 + i = min(SDp->request_queue->max_hw_segments,
  3894 + SDp->request_queue->max_phys_segments);
3896 3895 if (st_max_sg_segs < i)
3897 3896 i = st_max_sg_segs;
3898 3897 buffer = new_tape_buffer(1, (SDp->host)->unchecked_isa_dma, i);
... ... @@ -3994,11 +3993,6 @@
3994 3993 tpnt->long_timeout = ST_LONG_TIMEOUT;
3995 3994 tpnt->try_dio = try_direct_io && !SDp->host->unchecked_isa_dma;
3996 3995  
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 3996 for (i = 0; i < ST_NBR_MODES; i++) {
4003 3997 STm = &(tpnt->modes[i]);
4004 3998 STm->defined = 0;
4005 3999  
... ... @@ -4077,9 +4071,9 @@
4077 4071  
4078 4072 sdev_printk(KERN_WARNING, SDp,
4079 4073 "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",
  4074 + printk(KERN_WARNING "%s: try direct i/o: %s (alignment %d B)\n",
4081 4075 tape_name(tpnt), tpnt->try_dio ? "yes" : "no",
4082   - queue_dma_alignment(SDp->request_queue) + 1, tpnt->max_pfn);
  4076 + queue_dma_alignment(SDp->request_queue) + 1);
4083 4077  
4084 4078 return 0;
4085 4079  
... ... @@ -4410,34 +4404,6 @@
4410 4404 out:
4411 4405 return;
4412 4406 }
4413   -
4414   -
4415   -/* Pin down user pages and put them into a scatter gather list. Returns <= 0 if
4416   - - mapping of all pages not successful
4417   - - any page is above max_pfn
4418   - (i.e., either completely successful or fails)
4419   -*/
4420   -static int st_map_user_pages(struct scatterlist *sgl, const unsigned int max_pages,
4421   - unsigned long uaddr, size_t count, int rw,
4422   - unsigned long max_pfn)
4423   -{
4424   - int i, nr_pages;
4425   -
4426   - nr_pages = sgl_map_user_pages(sgl, max_pages, uaddr, count, rw);
4427   - if (nr_pages <= 0)
4428   - return nr_pages;
4429   -
4430   - for (i=0; i < nr_pages; i++) {
4431   - if (page_to_pfn(sgl[i].page) > max_pfn)
4432   - goto out_unmap;
4433   - }
4434   - return nr_pages;
4435   -
4436   - out_unmap:
4437   - sgl_unmap_user_pages(sgl, nr_pages, 0);
4438   - return 0;
4439   -}
4440   -
4441 4407  
4442 4408 /* The following functions may be useful for a larger audience. */
4443 4409 static int sgl_map_user_pages(struct scatterlist *sgl, const unsigned int max_pages,
... ... @@ -4,6 +4,7 @@
4 4  
5 5 #include <linux/completion.h>
6 6 #include <linux/kref.h>
  7 +#include <scsi/scsi_cmnd.h>
7 8  
8 9 /* Descriptor for analyzed sense data */
9 10 struct st_cmdstatus {
... ... @@ -17,6 +18,17 @@
17 18 u8 deferred;
18 19 };
19 20  
  21 +struct scsi_tape;
  22 +
  23 +/* scsi tape command */
  24 +struct st_request {
  25 + unsigned char cmd[MAX_COMMAND_SIZE];
  26 + unsigned char sense[SCSI_SENSE_BUFFERSIZE];
  27 + int result;
  28 + struct scsi_tape *stp;
  29 + struct completion *waiting;
  30 +};
  31 +
20 32 /* The tape buffer descriptor. */
21 33 struct st_buffer {
22 34 unsigned char in_use;
... ... @@ -28,7 +40,7 @@
28 40 int read_pointer;
29 41 int writing;
30 42 int syscall_result;
31   - struct scsi_request *last_SRpnt;
  43 + struct st_request *last_SRpnt;
32 44 struct st_cmdstatus cmdstat;
33 45 unsigned char *b_data;
34 46 unsigned short use_sg; /* zero or max number of s/g segments for this adapter */