|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: /* ! 25: * sctest - test of SCSIController object. Linked with libSCSIController.o. ! 26: */ ! 27: ! 28: #define FAKE_HARDWARE 1 ! 29: ! 30: #import <bsd/sys/types.h> ! 31: #import <bsd/libc.h> ! 32: #import <SCSIController/SCSIController.h> ! 33: #import <SCSIController/SCSIControllerPrivate.h> ! 34: #import <architecture/nrw/SCSI_channel.h> ! 35: #import <driverkit/return.h> ! 36: #import <driverkit/align.h> ! 37: ! 38: /* ! 39: * prototypes for private functions. ! 40: */ ! 41: static void usage(char **argv); ! 42: static void print_menu(); ! 43: static void setupScsiReq(scsiReq_t *scsiReq); ! 44: void dump_buf(u_char *buf, int size); ! 45: ! 46: /* ! 47: * Menu stuff. ! 48: */ ! 49: struct menu_entry { ! 50: char menu_c; ! 51: char *name; ! 52: void (*men_fcn)(); ! 53: }; ! 54: ! 55: static void scReset(); ! 56: static void cdbRead(); ! 57: static void cdbWrite(); ! 58: static void setTarget(); ! 59: static void setLun(); ! 60: static void quit(); ! 61: static void setupCDB(); ! 62: static void setDmaMax(); ! 63: static void setDmaDir(); ! 64: static void dumpBuf(); ! 65: ! 66: struct menu_entry me_array[] = { ! 67: ! 68: {'t', "Reset" , scReset }, ! 69: {'r', "cdbRead" , cdbRead }, ! 70: {'w', "cdbWrite" , cdbWrite }, ! 71: {'T', "Set Target" , setTarget }, ! 72: {'L', "Set lun" , setLun }, ! 73: {'c', "Setup CDB" , setupCDB }, ! 74: {'d', "Set DMA Size" , setDmaMax }, ! 75: {'D', "Set DMA Dir" , setDmaDir }, ! 76: {'b', "Dump r/w buf" , dumpBuf }, ! 77: {'h', "Help" , print_menu }, ! 78: {'x', "Exit" , quit }, ! 79: {'q', NULL , quit }, ! 80: {0, NULL , NULL } ! 81: }; ! 82: ! 83: #define MAX_DMA_SIZE (8 * 512) ! 84: ! 85: /* ! 86: * Static variables. ! 87: */ ! 88: int ioTimeout = 10; ! 89: int target = 0; ! 90: int lun = 0; ! 91: id controllerId; ! 92: u_char cdb_bytes[12]; ! 93: u_int dmaMax = MAX_DMA_SIZE; ! 94: SCSIDmaDir_t dmaDir = SCSI_DMA_READ; ! 95: char *rwbuf; ! 96: char *rwbuf_unalign; ! 97: ! 98: /* ! 99: * User-specified variables. ! 100: */ ! 101: int verbose = 0; /* used by libIODevice */ ! 102: int ioStub = 0; ! 103: ! 104: int main(int argc, char **argv) ! 105: { ! 106: int arg; ! 107: char instr[80]; ! 108: struct menu_entry *mep; ! 109: int ok; ! 110: ! 111: if(argc < 1) ! 112: usage(argv); ! 113: for(arg=1; arg<argc; arg++) { ! 114: switch(argv[arg][0]) { ! 115: case 'v': ! 116: verbose++; ! 117: break; ! 118: case 's': ! 119: ioStub++; ! 120: break; ! 121: default: ! 122: usage(argv); ! 123: } ! 124: } ! 125: ! 126: rwbuf_unalign = malloc(MAX_DMA_SIZE + 2 * SCSI_BUFSIZE); ! 127: rwbuf = IOAlign(char *, rwbuf_unalign, SCSI_BUFSIZE); ! 128: ! 129: IOInitGeneralFuncs(); ! 130: #ifdef DDM_DEBUG ! 131: IOInitDDM(200, "scxpr"); ! 132: #endif DDM_DEBUG ! 133: ! 134: /* ! 135: * Instantiate and init the controller object. ! 136: */ ! 137: controllerId = [SCSIController probe:0 deviceMaster:PORT_NULL]; ! 138: if(controllerId == nil) { ! 139: printf("SCSIController probe FAILED\n"); ! 140: exit(-1); ! 141: } ! 142: ! 143: print_menu(); ! 144: while(1) { ! 145: printf("Enter Selection: "); ! 146: gets(instr); ! 147: mep = me_array; ! 148: ok = 0; ! 149: while(mep->menu_c) { ! 150: if(mep->menu_c == instr[0]) { ! 151: ok = 1; ! 152: (*mep->men_fcn)(); ! 153: break; ! 154: } ! 155: else ! 156: mep++; ! 157: } ! 158: if(!ok) ! 159: printf("***Illegal Selection\n"); ! 160: } ! 161: return(0); ! 162: } ! 163: ! 164: static void usage(char **argv) ! 165: { ! 166: printf("usage: %s [options]\n", argv[0]); ! 167: printf("Options:\n"); ! 168: printf("\tv verbose mode\n"); ! 169: printf("\ts Use I/O stub\n"); ! 170: exit(1); ! 171: } ! 172: ! 173: static void print_menu() { ! 174: ! 175: struct menu_entry *mep; ! 176: ! 177: printf("\n"); ! 178: mep = me_array; ! 179: while(mep->menu_c) { ! 180: if(mep->name) ! 181: printf(" %c: %s\n", mep->menu_c, mep->name); ! 182: mep++; ! 183: } ! 184: printf("\n"); ! 185: } /* print_menu() */ ! 186: ! 187: static void scReset() ! 188: { ! 189: scStatus rtn; ! 190: ! 191: rtn = [controllerId scsiReset]; ! 192: if(rtn) { ! 193: printf("...scsiReset returned %d\n", rtn); ! 194: } ! 195: } ! 196: ! 197: static void cdbRead() ! 198: { ! 199: scsiReq_t scsiReq; ! 200: scStatus rtn; ! 201: ! 202: setupScsiReq(&scsiReq); ! 203: rtn = [controllerId executeCdbRead:&scsiReq buffer:rwbuf]; ! 204: if(rtn) { ! 205: printf("...executeCdbRead returned %s\n", ! 206: IOFindNameForValue(rtn, scStatusValues)); ! 207: printf(" ioStatus = %s\n", ! 208: IOFindNameForValue(scsiReq.ioStatus, scStatusValues)); ! 209: } ! 210: else if(scsiReq.ioStatus) { ! 211: printf("...executeCdbRead: ioStatus = %d\n", ! 212: IOFindNameForValue(scsiReq.ioStatus, scStatusValues)); ! 213: } ! 214: else if(scsiReq.dmaXfr) ! 215: printf("dmaXfr = %d\n", scsiReq.dmaXfr); ! 216: else ! 217: printf("...OK\n"); ! 218: } ! 219: ! 220: static void cdbWrite() ! 221: { ! 222: scsiReq_t scsiReq; ! 223: scStatus rtn; ! 224: ! 225: setupScsiReq(&scsiReq); ! 226: rtn = [controllerId executeCdbWrite:&scsiReq buffer:rwbuf]; ! 227: if(rtn) { ! 228: printf("...executeCdbWrite returned %s\n", ! 229: IOFindNameForValue(rtn, scStatusValues)); ! 230: printf(" ioStatus = %s\n", ! 231: IOFindNameForValue(scsiReq.ioStatus, scStatusValues)); ! 232: } ! 233: else if(scsiReq.ioStatus) { ! 234: printf("...executeCdbWrite: ioStatus = %d\n", ! 235: IOFindNameForValue(scsiReq.ioStatus, scStatusValues)); ! 236: } ! 237: else if(scsiReq.dmaXfr) ! 238: printf("dmaXfr = %d\n", scsiReq.dmaXfr); ! 239: else ! 240: printf("...OK\n"); ! 241: } ! 242: ! 243: static void setTarget() ! 244: { ! 245: char instr[100]; ! 246: ! 247: printf("Enter new target (CR = %d): ", target); ! 248: gets(instr); ! 249: if(instr[0]) ! 250: target = atoi(instr); ! 251: } ! 252: ! 253: static void setLun() ! 254: { ! 255: char instr[100]; ! 256: ! 257: printf("Enter new lun (CR = %d): ", lun); ! 258: gets(instr); ! 259: if(instr[0]) ! 260: lun = atoi(instr); ! 261: } ! 262: ! 263: static void setDmaMax() ! 264: { ! 265: char instr[100]; ! 266: int ok; ! 267: ! 268: do { ! 269: printf("Enter new dmaMax (CR = %d): ", dmaMax); ! 270: gets(instr); ! 271: if(instr[0]) ! 272: dmaMax = atoi(instr); ! 273: if(dmaMax > MAX_DMA_SIZE) { ! 274: printf("Maximum DMA size is %d\n", MAX_DMA_SIZE); ! 275: ok = 0; ! 276: } ! 277: else { ! 278: ok = 1; ! 279: } ! 280: } while(!ok); ! 281: } ! 282: ! 283: static void setDmaDir() ! 284: { ! 285: char instr[100]; ! 286: ! 287: printf("Enter new dmaDir (r/w, CR = %s): ", ! 288: dmaDir == SCSI_DMA_READ ? "Read" : "Write"); ! 289: gets(instr); ! 290: switch(instr[0]) { ! 291: case 'r': ! 292: dmaDir = SCSI_DMA_READ; ! 293: break; ! 294: case 'w': ! 295: dmaDir = SCSI_DMA_WRITE; ! 296: break; ! 297: default: ! 298: break; ! 299: } ! 300: } ! 301: ! 302: ! 303: static void setupCDB() ! 304: { ! 305: int i; ! 306: char instr[20]; ! 307: ! 308: printf("Enter <ESC> at any prompt to quit\n"); ! 309: for(i=0; i<12; i++) { ! 310: printf(" CDB byte %d (CR = 0x%02x): ", i, cdb_bytes[i]); ! 311: gets(instr); ! 312: switch(instr[0]) { ! 313: case '\0': ! 314: break; /* take current value */ ! 315: case 0x1b: /* Escape */ ! 316: goto outOfHere; ! 317: default: ! 318: cdb_bytes[i] = atoh(instr); ! 319: break; ! 320: } ! 321: } ! 322: outOfHere: ! 323: printf("CDB bytes: "); ! 324: for(i=0; i<12; i++) ! 325: printf("0x%02x ", cdb_bytes[i]); ! 326: printf("\n"); ! 327: } ! 328: ! 329: static void setupScsiReq(scsiReq_t *scsiReq) ! 330: { ! 331: bzero(scsiReq, sizeof(scsiReq_t)); ! 332: scsiReq->target = target; ! 333: scsiReq->lun = lun; ! 334: bcopy(cdb_bytes, &scsiReq->cdb, 12); ! 335: scsiReq->dmaDir = dmaDir; ! 336: scsiReq->dmaMax = dmaMax; ! 337: scsiReq->ioTimeout = ioTimeout; ! 338: } ! 339: ! 340: static void dumpBuf() ! 341: { ! 342: dump_buf((u_char *)rwbuf, MAX_DMA_SIZE); ! 343: } ! 344: ! 345: static void quit() ! 346: { ! 347: exit(0); ! 348: } ! 349: ! 350: #ifdef notdef ! 351: void dump_buf(u_char *buf, int size) { ! 352: ! 353: int i; ! 354: char c[100]; ! 355: ! 356: printf("\n"); ! 357: for(i=0; i<size; i++) { ! 358: if((i>0) && (i%0x100 == 0)) { ! 359: printf("\n...More? (y/anything) "); ! 360: gets(c); ! 361: if(c[0] != 'y') ! 362: return; ! 363: } ! 364: if(i%0x10 == 0) ! 365: printf("\n %03X: ",i); ! 366: else if(i%8 == 0) ! 367: printf(" "); ! 368: printf("%02X ",buf[i]); ! 369: } ! 370: printf("\n"); ! 371: } /* dump_buf() */ ! 372: #endif notdef
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.