1 /* 2 * Copyright (c) 1992 OMRON Corporation. 3 * Copyright (c) 1992, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * OMRON Corporation. 8 * 9 * %sccs.include.redist.c% 10 * 11 * @(#)scsi.c 8.1 (Berkeley) 06/10/93 12 */ 13 14 /* 15 * scsi.c -- front end of SCSI test commands 16 * by A.Fujita, FEB-09-1992 17 */ 18 19 #include <sys/param.h> 20 #include <luna68k/dev/scsireg.h> 21 #include <luna68k/stand/status.h> 22 23 24 int scsi_device = 6; 25 26 #define SENSBUFF 8 /* 06/10/93P%$%98.1i%$%P$G%;%s%9%G!<%? */ 27 /* $ND9$5$r#8/usr/home/csrg/sccs/sys/luna68k/stand/SCCS/s.scsi.c$%H0JFb$K8GDj$7$F */ 28 u_char sensbuff[SENSBUFF]; /* #80J>e$OL50UL#$G$"$k!# */ 29 30 static struct scsi_inquiry inquirybuf; 31 static struct scsi_fmt_cdb inquiry = { 32 6, 33 CMD_INQUIRY, 0, 0, 0, sizeof(inquirybuf), 0 34 }; 35 36 static u_long capacitybuf[2]; 37 struct scsi_fmt_cdb capacity = { 38 10, 39 CMD_READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0 40 }; 41 42 43 int 44 scsi(argc, argv) 45 int argc; 46 char *argv[]; 47 { 48 register char *p; 49 register int i, status; 50 51 if (argc < 2) { 52 printf("This command is required subcommand !!\n"); 53 return(ST_ERROR); 54 } 55 56 if (!strcmp(argv[1], "device")) { 57 if (argc > 2) { 58 i = 0; 59 for (p = argv[2]; *p != NULL; p++) { 60 i = i * 10 + *p - '0'; 61 } 62 if ( i < 8 && i >= 0) { 63 scsi_device = i; 64 } 65 } 66 printf("Current Device ID: %d\n", scsi_device); 67 } else if (!strcmp(argv[1], "test_unit_rdy")) { 68 /* CTLR SLAVE LUN */ 69 scsi_test_unit_rdy( 0, scsi_device, 0); 70 } else if (!strcmp(argv[1], "request_sense")) { 71 /* CTLR SLAVE LUN */ 72 scsi_request_sense( 0, scsi_device, 0, sensbuff, SENSBUFF); 73 } else if (!strcmp(argv[1], "inquiry")) { 74 if (scsi_immed_command( 0, scsi_device, 0, &inquiry, 75 (u_char *) &inquirybuf, sizeof(inquirybuf)) == 0) { 76 printf("Type:\t0x%x\n", inquirybuf.type); 77 printf("Qualifier:\t0x%x\n", inquirybuf.qual); 78 printf("Version:\t0x%x\n", inquirybuf.version); 79 printf("RDF:\t0x%x\n", inquirybuf.rsvd); 80 81 printf("Vender ID:\t"); 82 for (i = 0; i < 8; i++) 83 printf("%c", inquirybuf.vendor_id[i]); 84 printf("\n"); 85 86 printf("Product ID:\t"); 87 for (i = 0; i < 16; i++) 88 printf("%c", inquirybuf.product_id[i]); 89 printf("\n"); 90 91 printf("Revision:\t"); 92 for (i = 0; i < 4; i++) 93 printf("%c", inquirybuf.rev[i]); 94 printf("\n"); 95 } 96 } else if (!strcmp(argv[1], "read_capacity")) { 97 if (scsi_immed_command( 0, scsi_device, 0, &capacity, 98 (u_char *) &capacitybuf, sizeof(capacitybuf)) == 0) { 99 printf("Logical Block Address:\t%d (0x%x)\n", 100 capacitybuf[0], capacitybuf[0]); 101 printf("Block Length:\t\t%d (0x%x)\n", 102 capacitybuf[1], capacitybuf[1]); 103 } 104 } else if (!strcmp(argv[1], "trace")) { 105 for (i = 0; i < 7; i++) { 106 printf("SCSI ID %d .... ", i); 107 status = scsi_test_unit_rdy( 0, i, 0); 108 if (status >= 0) 109 printf("found.\n"); 110 else 111 printf("no.\n"); 112 } 113 } else if (!strcmp(argv[1], "format_unit")) { 114 i = 0; 115 while (i == 0) { 116 printf("Do you really want to format SCSI %d device ? [y/n]: ", 117 scsi_device); 118 i = cngetc(); 119 printf("\n"); 120 if ((i != 'y') && (i != 'Y') && (i != 'n') && (i != 'N')) 121 i = 0; 122 } 123 124 if ((i == 'y') || (i == 'Y')) 125 status = scsi_format_unit( 0, scsi_device, 0); 126 } 127 128 return(ST_NORMAL); 129 } 130 131 static struct scsi_fmt_cdb scsi_cdb = { 132 10, 133 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 134 }; 135 136 int 137 scsi_read_raw(target, blk, nblk, buff, len) 138 u_int target; 139 u_int blk; 140 u_int nblk; 141 u_char *buff; 142 u_int len; 143 { 144 register struct scsi_fmt_cdb *cdb = &scsi_cdb; 145 146 cdb->cdb[0] = CMD_READ_EXT; 147 148 cdb->cdb[2] = (blk & 0xff000000) >> 24; 149 cdb->cdb[3] = (blk & 0x00ff0000) >> 16; 150 cdb->cdb[4] = (blk & 0x0000ff00) >> 8; 151 cdb->cdb[5] = (blk & 0x000000ff); 152 153 cdb->cdb[7] = (nblk & 0xff00) >> 8; 154 cdb->cdb[8] = (nblk & 0x00ff); 155 156 if (scsi_immed_command(0, target, 0, cdb, buff, len) == 0) 157 return(1); 158 else 159 return(0); 160 } 161 162 int 163 scsi_read(blk, buff, len) 164 u_int blk; 165 u_char *buff; 166 u_int len; 167 { 168 u_int nblk = len >> DEV_BSHIFT; 169 170 return(scsi_read_raw(scsi_device, blk, nblk, buff, len)); 171 } 172 173 int 174 scsi_write(blk, buff, len) 175 u_int blk; 176 u_char *buff; 177 u_int len; 178 { 179 register struct scsi_fmt_cdb *cdb = &scsi_cdb; 180 181 cdb->cdb[0] = CMD_WRITE_EXT; 182 183 cdb->cdb[2] = (blk & 0xff000000) >> 24; 184 cdb->cdb[3] = (blk & 0x00ff0000) >> 16; 185 cdb->cdb[4] = (blk & 0x0000ff00) >> 8; 186 cdb->cdb[5] = (blk & 0x000000ff); 187 188 cdb->cdb[7] = ((len >> DEV_BSHIFT) & 0xff00) >> 8; 189 cdb->cdb[8] = ((len >> DEV_BSHIFT) & 0x00ff); 190 191 if (scsi_immed_command(0, scsi_device, 0, cdb, buff, len) == 0) 192 return(1); 193 else 194 return(0); 195 } 196