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