aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/scsi/st.c202
1 files changed, 66 insertions, 136 deletions
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index fe4c20259bca..ddf2630b3479 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 const char *verstr = "20080504"; 20static const char *verstr = "20081215";
21 21
22#include <linux/module.h> 22#include <linux/module.h>
23 23
@@ -491,10 +491,13 @@ static int st_scsi_execute(struct st_request *SRpnt, const unsigned char *cmd,
491 491
492 mdata->null_mapped = 1; 492 mdata->null_mapped = 1;
493 493
494 err = blk_rq_map_user(req->q, req, mdata, NULL, bufflen, GFP_KERNEL); 494 if (bufflen) {
495 if (err) { 495 err = blk_rq_map_user(req->q, req, mdata, NULL, bufflen,
496 blk_put_request(req); 496 GFP_KERNEL);
497 return DRIVER_ERROR << 24; 497 if (err) {
498 blk_put_request(req);
499 return DRIVER_ERROR << 24;
500 }
498 } 501 }
499 502
500 SRpnt->bio = req->bio; 503 SRpnt->bio = req->bio;
@@ -577,28 +580,6 @@ st_do_scsi(struct st_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd
577 return SRpnt; 580 return SRpnt;
578} 581}
579 582
580static int st_scsi_kern_execute(struct st_request *streq,
581 const unsigned char *cmd, int data_direction,
582 void *buffer, unsigned bufflen, int timeout,
583 int retries)
584{
585 struct scsi_tape *stp = streq->stp;
586 int ret, resid;
587
588 stp->buffer->cmdstat.have_sense = 0;
589 memcpy(streq->cmd, cmd, sizeof(streq->cmd));
590
591 ret = scsi_execute(stp->device, cmd, data_direction, buffer, bufflen,
592 streq->sense, timeout, retries, 0, &resid);
593 if (driver_byte(ret) & DRIVER_ERROR)
594 return -EBUSY;
595
596 stp->buffer->cmdstat.midlevel_result = streq->result = ret;
597 stp->buffer->cmdstat.residual = resid;
598 stp->buffer->syscall_result = st_chk_result(stp, streq);
599
600 return 0;
601}
602 583
603/* Handle the write-behind checking (waits for completion). Returns -ENOSPC if 584/* Handle the write-behind checking (waits for completion). Returns -ENOSPC if
604 write has been correct but EOM early warning reached, -EIO if write ended in 585 write has been correct but EOM early warning reached, -EIO if write ended in
@@ -671,7 +652,6 @@ static int cross_eof(struct scsi_tape * STp, int forward)
671{ 652{
672 struct st_request *SRpnt; 653 struct st_request *SRpnt;
673 unsigned char cmd[MAX_COMMAND_SIZE]; 654 unsigned char cmd[MAX_COMMAND_SIZE];
674 int ret;
675 655
676 cmd[0] = SPACE; 656 cmd[0] = SPACE;
677 cmd[1] = 0x01; /* Space FileMarks */ 657 cmd[1] = 0x01; /* Space FileMarks */
@@ -685,26 +665,20 @@ static int cross_eof(struct scsi_tape * STp, int forward)
685 DEBC(printk(ST_DEB_MSG "%s: Stepping over filemark %s.\n", 665 DEBC(printk(ST_DEB_MSG "%s: Stepping over filemark %s.\n",
686 tape_name(STp), forward ? "forward" : "backward")); 666 tape_name(STp), forward ? "forward" : "backward"));
687 667
688 SRpnt = st_allocate_request(STp); 668 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
669 STp->device->request_queue->rq_timeout,
670 MAX_RETRIES, 1);
689 if (!SRpnt) 671 if (!SRpnt)
690 return STp->buffer->syscall_result; 672 return (STp->buffer)->syscall_result;
691
692 ret = st_scsi_kern_execute(SRpnt, cmd, DMA_NONE, NULL, 0,
693 STp->device->request_queue->rq_timeout,
694 MAX_RETRIES);
695 if (ret)
696 goto out;
697 673
698 ret = STp->buffer->syscall_result; 674 st_release_request(SRpnt);
675 SRpnt = NULL;
699 676
700 if ((STp->buffer)->cmdstat.midlevel_result != 0) 677 if ((STp->buffer)->cmdstat.midlevel_result != 0)
701 printk(KERN_ERR "%s: Stepping over filemark %s failed.\n", 678 printk(KERN_ERR "%s: Stepping over filemark %s failed.\n",
702 tape_name(STp), forward ? "forward" : "backward"); 679 tape_name(STp), forward ? "forward" : "backward");
703 680
704out: 681 return (STp->buffer)->syscall_result;
705 st_release_request(SRpnt);
706
707 return ret;
708} 682}
709 683
710 684
@@ -925,24 +899,21 @@ static int test_ready(struct scsi_tape *STp, int do_wait)
925 int attentions, waits, max_wait, scode; 899 int attentions, waits, max_wait, scode;
926 int retval = CHKRES_READY, new_session = 0; 900 int retval = CHKRES_READY, new_session = 0;
927 unsigned char cmd[MAX_COMMAND_SIZE]; 901 unsigned char cmd[MAX_COMMAND_SIZE];
928 struct st_request *SRpnt; 902 struct st_request *SRpnt = NULL;
929 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; 903 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
930 904
931 SRpnt = st_allocate_request(STp);
932 if (!SRpnt)
933 return STp->buffer->syscall_result;
934
935 max_wait = do_wait ? ST_BLOCK_SECONDS : 0; 905 max_wait = do_wait ? ST_BLOCK_SECONDS : 0;
936 906
937 for (attentions=waits=0; ; ) { 907 for (attentions=waits=0; ; ) {
938 memset((void *) &cmd[0], 0, MAX_COMMAND_SIZE); 908 memset((void *) &cmd[0], 0, MAX_COMMAND_SIZE);
939 cmd[0] = TEST_UNIT_READY; 909 cmd[0] = TEST_UNIT_READY;
910 SRpnt = st_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE,
911 STp->long_timeout, MAX_READY_RETRIES, 1);
940 912
941 retval = st_scsi_kern_execute(SRpnt, cmd, DMA_NONE, NULL, 0, 913 if (!SRpnt) {
942 STp->long_timeout, 914 retval = (STp->buffer)->syscall_result;
943 MAX_READY_RETRIES);
944 if (retval)
945 break; 915 break;
916 }
946 917
947 if (cmdstatp->have_sense) { 918 if (cmdstatp->have_sense) {
948 919
@@ -986,8 +957,8 @@ static int test_ready(struct scsi_tape *STp, int do_wait)
986 break; 957 break;
987 } 958 }
988 959
989 st_release_request(SRpnt); 960 if (SRpnt != NULL)
990 961 st_release_request(SRpnt);
991 return retval; 962 return retval;
992} 963}
993 964
@@ -1064,24 +1035,17 @@ static int check_tape(struct scsi_tape *STp, struct file *filp)
1064 } 1035 }
1065 } 1036 }
1066 1037
1067 SRpnt = st_allocate_request(STp);
1068 if (!SRpnt) {
1069 retval = STp->buffer->syscall_result;
1070 goto err_out;
1071 }
1072
1073 if (STp->omit_blklims) 1038 if (STp->omit_blklims)
1074 STp->min_block = STp->max_block = (-1); 1039 STp->min_block = STp->max_block = (-1);
1075 else { 1040 else {
1076 memset((void *) &cmd[0], 0, MAX_COMMAND_SIZE); 1041 memset((void *) &cmd[0], 0, MAX_COMMAND_SIZE);
1077 cmd[0] = READ_BLOCK_LIMITS; 1042 cmd[0] = READ_BLOCK_LIMITS;
1078 1043
1079 retval = st_scsi_kern_execute(SRpnt, cmd, DMA_FROM_DEVICE, 1044 SRpnt = st_do_scsi(SRpnt, STp, cmd, 6, DMA_FROM_DEVICE,
1080 STp->buffer->b_data, 6, 1045 STp->device->request_queue->rq_timeout,
1081 STp->device->request_queue->rq_timeout, 1046 MAX_READY_RETRIES, 1);
1082 MAX_READY_RETRIES); 1047 if (!SRpnt) {
1083 if (retval) { 1048 retval = (STp->buffer)->syscall_result;
1084 st_release_request(SRpnt);
1085 goto err_out; 1049 goto err_out;
1086 } 1050 }
1087 1051
@@ -1105,12 +1069,11 @@ static int check_tape(struct scsi_tape *STp, struct file *filp)
1105 cmd[0] = MODE_SENSE; 1069 cmd[0] = MODE_SENSE;
1106 cmd[4] = 12; 1070 cmd[4] = 12;
1107 1071
1108 retval = st_scsi_kern_execute(SRpnt, cmd, DMA_FROM_DEVICE, 1072 SRpnt = st_do_scsi(SRpnt, STp, cmd, 12, DMA_FROM_DEVICE,
1109 STp->buffer->b_data, 12, 1073 STp->device->request_queue->rq_timeout,
1110 STp->device->request_queue->rq_timeout, 1074 MAX_READY_RETRIES, 1);
1111 MAX_READY_RETRIES); 1075 if (!SRpnt) {
1112 if (retval) { 1076 retval = (STp->buffer)->syscall_result;
1113 st_release_request(SRpnt);
1114 goto err_out; 1077 goto err_out;
1115 } 1078 }
1116 1079
@@ -1340,17 +1303,11 @@ static int st_flush(struct file *filp, fl_owner_t id)
1340 cmd[0] = WRITE_FILEMARKS; 1303 cmd[0] = WRITE_FILEMARKS;
1341 cmd[4] = 1 + STp->two_fm; 1304 cmd[4] = 1 + STp->two_fm;
1342 1305
1343 SRpnt = st_allocate_request(STp); 1306 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
1307 STp->device->request_queue->rq_timeout,
1308 MAX_WRITE_RETRIES, 1);
1344 if (!SRpnt) { 1309 if (!SRpnt) {
1345 result = STp->buffer->syscall_result; 1310 result = (STp->buffer)->syscall_result;
1346 goto out;
1347 }
1348
1349 result = st_scsi_kern_execute(SRpnt, cmd, DMA_NONE, NULL, 0,
1350 STp->device->request_queue->rq_timeout,
1351 MAX_WRITE_RETRIES);
1352 if (result) {
1353 st_release_request(SRpnt);
1354 goto out; 1311 goto out;
1355 } 1312 }
1356 1313
@@ -2415,7 +2372,6 @@ static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs)
2415{ 2372{
2416 unsigned char cmd[MAX_COMMAND_SIZE]; 2373 unsigned char cmd[MAX_COMMAND_SIZE];
2417 struct st_request *SRpnt; 2374 struct st_request *SRpnt;
2418 int ret;
2419 2375
2420 memset(cmd, 0, MAX_COMMAND_SIZE); 2376 memset(cmd, 0, MAX_COMMAND_SIZE);
2421 cmd[0] = MODE_SENSE; 2377 cmd[0] = MODE_SENSE;
@@ -2424,17 +2380,14 @@ static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs)
2424 cmd[2] = page; 2380 cmd[2] = page;
2425 cmd[4] = 255; 2381 cmd[4] = 255;
2426 2382
2427 SRpnt = st_allocate_request(STp); 2383 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_FROM_DEVICE,
2428 if (!SRpnt) 2384 STp->device->request_queue->rq_timeout, 0, 1);
2429 return STp->buffer->syscall_result; 2385 if (SRpnt == NULL)
2386 return (STp->buffer)->syscall_result;
2430 2387
2431 ret = st_scsi_kern_execute(SRpnt, cmd, DMA_FROM_DEVICE,
2432 STp->buffer->b_data, cmd[4],
2433 STp->device->request_queue->rq_timeout,
2434 MAX_RETRIES);
2435 st_release_request(SRpnt); 2388 st_release_request(SRpnt);
2436 2389
2437 return ret ? : STp->buffer->syscall_result; 2390 return STp->buffer->syscall_result;
2438} 2391}
2439 2392
2440 2393
@@ -2442,9 +2395,10 @@ static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs)
2442 in the buffer is correctly formatted. The long timeout is used if slow is non-zero. */ 2395 in the buffer is correctly formatted. The long timeout is used if slow is non-zero. */
2443static int write_mode_page(struct scsi_tape *STp, int page, int slow) 2396static int write_mode_page(struct scsi_tape *STp, int page, int slow)
2444{ 2397{
2445 int pgo, timeout, ret = 0; 2398 int pgo;
2446 unsigned char cmd[MAX_COMMAND_SIZE]; 2399 unsigned char cmd[MAX_COMMAND_SIZE];
2447 struct st_request *SRpnt; 2400 struct st_request *SRpnt;
2401 int timeout;
2448 2402
2449 memset(cmd, 0, MAX_COMMAND_SIZE); 2403 memset(cmd, 0, MAX_COMMAND_SIZE);
2450 cmd[0] = MODE_SELECT; 2404 cmd[0] = MODE_SELECT;
@@ -2458,21 +2412,16 @@ static int write_mode_page(struct scsi_tape *STp, int page, int slow)
2458 (STp->buffer)->b_data[MH_OFF_DEV_SPECIFIC] &= ~MH_BIT_WP; 2412 (STp->buffer)->b_data[MH_OFF_DEV_SPECIFIC] &= ~MH_BIT_WP;
2459 (STp->buffer)->b_data[pgo + MP_OFF_PAGE_NBR] &= MP_MSK_PAGE_NBR; 2413 (STp->buffer)->b_data[pgo + MP_OFF_PAGE_NBR] &= MP_MSK_PAGE_NBR;
2460 2414
2461 SRpnt = st_allocate_request(STp); 2415 timeout = slow ?
2462 if (!SRpnt) 2416 STp->long_timeout : STp->device->request_queue->rq_timeout;
2463 return ret; 2417 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_TO_DEVICE,
2464 2418 timeout, 0, 1);
2465 timeout = slow ? STp->long_timeout : 2419 if (SRpnt == NULL)
2466 STp->device->request_queue->rq_timeout; 2420 return (STp->buffer)->syscall_result;
2467
2468 ret = st_scsi_kern_execute(SRpnt, cmd, DMA_TO_DEVICE,
2469 STp->buffer->b_data, cmd[4], timeout, 0);
2470 if (!ret)
2471 ret = STp->buffer->syscall_result;
2472 2421
2473 st_release_request(SRpnt); 2422 st_release_request(SRpnt);
2474 2423
2475 return ret; 2424 return STp->buffer->syscall_result;
2476} 2425}
2477 2426
2478 2427
@@ -2590,16 +2539,13 @@ static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_cod
2590 printk(ST_DEB_MSG "%s: Loading tape.\n", name); 2539 printk(ST_DEB_MSG "%s: Loading tape.\n", name);
2591 ); 2540 );
2592 2541
2593 SRpnt = st_allocate_request(STp); 2542 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
2543 timeout, MAX_RETRIES, 1);
2594 if (!SRpnt) 2544 if (!SRpnt)
2595 return STp->buffer->syscall_result; 2545 return (STp->buffer)->syscall_result;
2596
2597 retval = st_scsi_kern_execute(SRpnt, cmd, DMA_NONE, NULL, 0, timeout,
2598 MAX_RETRIES);
2599 if (retval)
2600 goto out;
2601 2546
2602 retval = (STp->buffer)->syscall_result; 2547 retval = (STp->buffer)->syscall_result;
2548 st_release_request(SRpnt);
2603 2549
2604 if (!retval) { /* SCSI command successful */ 2550 if (!retval) { /* SCSI command successful */
2605 2551
@@ -2618,8 +2564,6 @@ static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_cod
2618 STps = &(STp->ps[STp->partition]); 2564 STps = &(STp->ps[STp->partition]);
2619 STps->drv_file = STps->drv_block = (-1); 2565 STps->drv_file = STps->drv_block = (-1);
2620 } 2566 }
2621out:
2622 st_release_request(SRpnt);
2623 2567
2624 return retval; 2568 return retval;
2625} 2569}
@@ -2895,15 +2839,12 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
2895 return (-ENOSYS); 2839 return (-ENOSYS);
2896 } 2840 }
2897 2841
2898 SRpnt = st_allocate_request(STp); 2842 SRpnt = st_do_scsi(NULL, STp, cmd, datalen, direction,
2843 timeout, MAX_RETRIES, 1);
2899 if (!SRpnt) 2844 if (!SRpnt)
2900 return (STp->buffer)->syscall_result; 2845 return (STp->buffer)->syscall_result;
2901 2846
2902 ioctl_result = st_scsi_kern_execute(SRpnt, cmd, direction, 2847 ioctl_result = (STp->buffer)->syscall_result;
2903 STp->buffer->b_data, datalen,
2904 timeout, MAX_RETRIES);
2905 if (!ioctl_result)
2906 ioctl_result = (STp->buffer)->syscall_result;
2907 2848
2908 if (!ioctl_result) { /* SCSI command successful */ 2849 if (!ioctl_result) { /* SCSI command successful */
2909 st_release_request(SRpnt); 2850 st_release_request(SRpnt);
@@ -3065,17 +3006,11 @@ static int get_location(struct scsi_tape *STp, unsigned int *block, int *partiti
3065 if (!logical && !STp->scsi2_logical) 3006 if (!logical && !STp->scsi2_logical)
3066 scmd[1] = 1; 3007 scmd[1] = 1;
3067 } 3008 }
3068 3009 SRpnt = st_do_scsi(NULL, STp, scmd, 20, DMA_FROM_DEVICE,
3069 SRpnt = st_allocate_request(STp); 3010 STp->device->request_queue->rq_timeout,
3011 MAX_READY_RETRIES, 1);
3070 if (!SRpnt) 3012 if (!SRpnt)
3071 return STp->buffer->syscall_result; 3013 return (STp->buffer)->syscall_result;
3072
3073 result = st_scsi_kern_execute(SRpnt, scmd, DMA_FROM_DEVICE,
3074 STp->buffer->b_data, 20,
3075 STp->device->request_queue->rq_timeout,
3076 MAX_READY_RETRIES);
3077 if (result)
3078 goto out;
3079 3014
3080 if ((STp->buffer)->syscall_result != 0 || 3015 if ((STp->buffer)->syscall_result != 0 ||
3081 (STp->device->scsi_level >= SCSI_2 && 3016 (STp->device->scsi_level >= SCSI_2 &&
@@ -3103,7 +3038,6 @@ static int get_location(struct scsi_tape *STp, unsigned int *block, int *partiti
3103 DEBC(printk(ST_DEB_MSG "%s: Got tape pos. blk %d part %d.\n", name, 3038 DEBC(printk(ST_DEB_MSG "%s: Got tape pos. blk %d part %d.\n", name,
3104 *block, *partition)); 3039 *block, *partition));
3105 } 3040 }
3106out:
3107 st_release_request(SRpnt); 3041 st_release_request(SRpnt);
3108 SRpnt = NULL; 3042 SRpnt = NULL;
3109 3043
@@ -3178,14 +3112,10 @@ static int set_location(struct scsi_tape *STp, unsigned int block, int partition
3178 timeout = STp->device->request_queue->rq_timeout; 3112 timeout = STp->device->request_queue->rq_timeout;
3179 } 3113 }
3180 3114
3181 SRpnt = st_allocate_request(STp); 3115 SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE,
3116 timeout, MAX_READY_RETRIES, 1);
3182 if (!SRpnt) 3117 if (!SRpnt)
3183 return STp->buffer->syscall_result; 3118 return (STp->buffer)->syscall_result;
3184
3185 result = st_scsi_kern_execute(SRpnt, scmd, DMA_NONE, NULL, 0,
3186 timeout, MAX_READY_RETRIES);
3187 if (result)
3188 goto out;
3189 3119
3190 STps->drv_block = STps->drv_file = (-1); 3120 STps->drv_block = STps->drv_file = (-1);
3191 STps->eof = ST_NOEOF; 3121 STps->eof = ST_NOEOF;
@@ -3210,7 +3140,7 @@ static int set_location(struct scsi_tape *STp, unsigned int block, int partition
3210 STps->drv_block = STps->drv_file = 0; 3140 STps->drv_block = STps->drv_file = 0;
3211 result = 0; 3141 result = 0;
3212 } 3142 }
3213out: 3143
3214 st_release_request(SRpnt); 3144 st_release_request(SRpnt);
3215 SRpnt = NULL; 3145 SRpnt = NULL;
3216 3146