constants.c

来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 1,197 行 · 第 1/3 页

C
1,197
字号
	{0x6E00, "Command to logical unit failed"},	{0x6F00, "Copy protection key exchange failure - authentication "	 "failure"},	{0x6F01, "Copy protection key exchange failure - key not present"},	{0x6F02, "Copy protection key exchange failure - key not established"},	{0x6F03, "Read of scrambled sector without authentication"},	{0x6F04, "Media region code is mismatched to logical unit region"},	{0x6F05, "Drive region must be permanent/region reset count error"},#if 0	{0x70NN, "Decompression exception short algorithm id of nn"},#endif	{0x7100, "Decompression exception long algorithm id"},	{0x7200, "Session fixation error"},	{0x7201, "Session fixation error writing lead-in"},	{0x7202, "Session fixation error writing lead-out"},	{0x7203, "Session fixation error - incomplete track in session"},	{0x7204, "Empty or partially written reserved track"},	{0x7205, "No more track reservations allowed"},	{0x7300, "Cd control error"},	{0x7301, "Power calibration area almost full"},	{0x7302, "Power calibration area is full"},	{0x7303, "Power calibration area error"},	{0x7304, "Program memory area update failure"},	{0x7305, "Program memory area is full"},	{0x7306, "RMA/PMA is almost full"},	{0, NULL}};struct error_info2 {	unsigned char code1, code2_min, code2_max;	const char * fmt;};static struct error_info2 additional2[] ={	{0x40,0x00,0x7f,"Ram failure (%x)"},	{0x40,0x80,0xff,"Diagnostic failure on component (%x)"},	{0x41,0x00,0xff,"Data path failure (%x)"},	{0x42,0x00,0xff,"Power-on or self-test failure (%x)"},	{0x4D,0x00,0xff,"Tagged overlapped commands (queue tag %x)"},	{0x70,0x00,0xff,"Decompression exception short algorithm id of %x"},	{0, 0, 0, NULL}};#endif#if (CONSTANTS & CONST_SENSE)/* description of the sense key values */static const char *snstext[] = {	"No Sense",	    /* 0: There is no sense information */	"Recovered Error",  /* 1: The last command completed successfully				  but used error correction */	"Not Ready",	    /* 2: The addressed target is not ready */	"Medium Error",	    /* 3: Data error detected on the medium */	"Hardware Error",   /* 4: Controller or device failure */	"Illegal Request",  /* 5: Error in request */	"Unit Attention",   /* 6: Removable medium was changed, or				  the target has been reset */	"Data Protect",	    /* 7: Access to the data is blocked */	"Blank Check",	    /* 8: Reached unexpected written or unwritten				  region of the medium */	"Vendor Specific",  /* 9: Vendor specific */	"Copy Aborted",	    /* A: COPY or COMPARE was aborted */	"Aborted Command",  /* B: The target aborted the command */	"Equal",	    /* C: A SEARCH DATA command found data equal */	"Volume Overflow",  /* D: Medium full with still data to be written */	"Miscompare",	    /* E: Source data and data on the medium				  do not agree */};#endif/* Get sense key string or NULL if not available */const char *scsi_sense_key_string(unsigned char key) {#if (CONSTANTS & CONST_SENSE)	if (key <= 0xE)		return snstext[key];#endif	return NULL;}/* * Get extended sense key string or NULL if not available. * This string may contain a %x and must be printed with ascq as arg. */const char *scsi_extd_sense_format(unsigned char asc, unsigned char ascq) {#if (CONSTANTS & CONST_XSENSE)	int i;	unsigned short code = ((asc << 8) | ascq);	for (i=0; additional[i].text; i++)		if (additional[i].code12 == code)			return additional[i].text;	for (i=0; additional2[i].fmt; i++)		if (additional2[i].code1 == asc &&		    additional2[i].code2_min >= ascq &&		    additional2[i].code2_max <= ascq)			return additional2[i].fmt;#endif	return NULL;}/* Print extended sense information */static voidscsi_show_extd_sense(unsigned char asc, unsigned char ascq) {	const char *extd_sense_fmt = scsi_extd_sense_format(asc, ascq);	if (extd_sense_fmt) {		printk("Additional sense: ");		printk(extd_sense_fmt, ascq);		printk("\n");	} else {		printk("ASC=%2x ASCQ=%2x\n", asc, ascq);	}}/* Print sense information */static voidprint_sense_internal(const char *devclass, 		     const unsigned char *sense_buffer,		     struct request *req){	int s, sense_class, valid, code, info;	const char *error = NULL;	unsigned char asc, ascq;	const char *sense_txt;	const char *name = req->rq_disk ? req->rq_disk->disk_name : devclass;    	sense_class = (sense_buffer[0] >> 4) & 0x07;	code = sense_buffer[0] & 0xf;	valid = sense_buffer[0] & 0x80;    	if (sense_class == 7) {	/* extended sense data */		s = sense_buffer[7] + 8;		if (s > SCSI_SENSE_BUFFERSIZE)			s = SCSI_SENSE_BUFFERSIZE;			info = ((sense_buffer[3] << 24) | (sense_buffer[4] << 16) |			(sense_buffer[5] << 8) | sense_buffer[6]);		if (info || valid) {			printk("Info fld=0x%x", info);			if (!valid)	/* info data not according to standard */				printk(" (nonstd)");			printk(", ");		}		if (sense_buffer[2] & 0x80)			printk( "FMK ");	/* current command has read a filemark */		if (sense_buffer[2] & 0x40)			printk( "EOM ");	/* end-of-medium condition exists */		if (sense_buffer[2] & 0x20)			printk( "ILI ");	/* incorrect block length requested */			switch (code) {		case 0x0:			error = "Current";	/* error concerns current command */			break;		case 0x1:			error = "Deferred";	/* error concerns some earlier command */			/* e.g., an earlier write to disk cache succeeded, but			   now the disk discovers that it cannot write the data */			break;		default:			error = "Invalid";		}		printk("%s ", error);		sense_txt = scsi_sense_key_string(sense_buffer[2]);		if (sense_txt)			printk("%s: sense key %s\n", name, sense_txt);		else			printk("%s: sense = %2x %2x\n", name,			       sense_buffer[0], sense_buffer[2]);		asc = ascq = 0;		if (sense_buffer[7] + 7 >= 13) {			asc = sense_buffer[12];			ascq = sense_buffer[13];		}		if (asc || ascq)			scsi_show_extd_sense(asc, ascq);	} else {	/* non-extended sense data */		/*		 * Standard says:		 *    sense_buffer[0] & 0200 : address valid		 *    sense_buffer[0] & 0177 : vendor-specific error code		 *    sense_buffer[1] & 0340 : vendor-specific		 *    sense_buffer[1..3] : 21-bit logical block address		 */		sense_txt = scsi_sense_key_string(sense_buffer[0]);		if (sense_txt)			printk("%s: old sense key %s\n", name, sense_txt);		else			printk("%s: sense = %2x %2x\n", name,			       sense_buffer[0], sense_buffer[2]);		printk("Non-extended sense class %d code 0x%0x\n",		       sense_class, code);		s = 4;	}    #if !(CONSTANTS & CONST_SENSE)	{		int i;	printk("Raw sense data:");	for (i = 0; i < s; ++i) 		printk("0x%02x ", sense_buffer[i]);	printk("\n");	}#endif}void scsi_print_sense(const char *devclass, struct scsi_cmnd *cmd){	print_sense_internal(devclass, cmd->sense_buffer, cmd->request);}void scsi_print_req_sense(const char *devclass, struct scsi_request *sreq){	print_sense_internal(devclass, sreq->sr_sense_buffer, sreq->sr_request);}#if (CONSTANTS & CONST_MSG) static const char *one_byte_msgs[] = {/* 0x00 */ "Command Complete", NULL, "Save Pointers",/* 0x03 */ "Restore Pointers", "Disconnect", "Initiator Error", /* 0x06 */ "Abort", "Message Reject", "Nop", "Message Parity Error",/* 0x0a */ "Linked Command Complete", "Linked Command Complete w/flag",/* 0x0c */ "Bus device reset", "Abort Tag", "Clear Queue", /* 0x0f */ "Initiate Recovery", "Release Recovery"};#define NO_ONE_BYTE_MSGS (sizeof(one_byte_msgs)  / sizeof (const char *))static const char *two_byte_msgs[] = {/* 0x20 */ "Simple Queue Tag", "Head of Queue Tag", "Ordered Queue Tag"/* 0x23 */ "Ignore Wide Residue"};#define NO_TWO_BYTE_MSGS (sizeof(two_byte_msgs)  / sizeof (const char *))static const char *extended_msgs[] = {/* 0x00 */ "Modify Data Pointer", "Synchronous Data Transfer Request",/* 0x02 */ "SCSI-I Extended Identify", "Wide Data Transfer Request"};#define NO_EXTENDED_MSGS (sizeof(two_byte_msgs)  / sizeof (const char *))#endif /* (CONSTANTS & CONST_MSG) */int scsi_print_msg (const unsigned char *msg) {    int len = 0, i;    if (msg[0] == EXTENDED_MESSAGE) {	len = 3 + msg[1];#if (CONSTANTS & CONST_MSG)	if (msg[2] < NO_EXTENDED_MSGS)	    printk ("%s ", extended_msgs[msg[2]]); 	else 	    printk ("Extended Message, reserved code (0x%02x) ", (int) msg[2]);	switch (msg[2]) {	case EXTENDED_MODIFY_DATA_POINTER:	    printk("pointer = %d", (int) (msg[3] << 24) | (msg[4] << 16) | 		   (msg[5] << 8) | msg[6]);	    break;	case EXTENDED_SDTR:	    printk("period = %d ns, offset = %d", (int) msg[3] * 4, (int) 		   msg[4]);	    break;	case EXTENDED_WDTR:	    printk("width = 2^%d bytes", msg[3]);	    break;	default:	    for (i = 2; i < len; ++i) 		printk("%02x ", msg[i]);	}#else	for (i = 0; i < len; ++i)	    printk("%02x ", msg[i]);#endif	/* Identify */    } else if (msg[0] & 0x80) {#if (CONSTANTS & CONST_MSG)	printk("Identify disconnect %sallowed %s %d ",	       (msg[0] & 0x40) ? "" : "not ",	       (msg[0] & 0x20) ? "target routine" : "lun",	       msg[0] & 0x7);#else	printk("%02x ", msg[0]);#endif	len = 1;	/* Normal One byte */    } else if (msg[0] < 0x1f) {#if (CONSTANTS & CONST_MSG)	if (msg[0] < NO_ONE_BYTE_MSGS)	    printk(one_byte_msgs[msg[0]]);	else	    printk("reserved (%02x) ", msg[0]);#else	printk("%02x ", msg[0]);#endif	len = 1;	/* Two byte */    } else if (msg[0] <= 0x2f) {#if (CONSTANTS & CONST_MSG)	if ((msg[0] - 0x20) < NO_TWO_BYTE_MSGS)	    printk("%s %02x ", two_byte_msgs[msg[0] - 0x20], 		   msg[1]);	else 	    printk("reserved two byte (%02x %02x) ", 		   msg[0], msg[1]);#else	printk("%02x %02x", msg[0], msg[1]);#endif	len = 2;    } else #if (CONSTANTS & CONST_MSG)	printk(reserved);#else    printk("%02x ", msg[0]);#endif    return len;}void scsi_print_command(struct scsi_cmnd *cmd) {    printk("scsi%d : destination target %d, lun %d\n", 	   cmd->device->host->host_no, 	   cmd->device->id, 	   cmd->device->lun);    printk("        command = ");    __scsi_print_command(cmd->cmnd);}#if (CONSTANTS & CONST_HOST)static const char * hostbyte_table[]={"DID_OK", "DID_NO_CONNECT", "DID_BUS_BUSY", "DID_TIME_OUT", "DID_BAD_TARGET", "DID_ABORT", "DID_PARITY", "DID_ERROR", "DID_RESET", "DID_BAD_INTR","DID_PASSTHROUGH", "DID_SOFT_ERROR", "DID_IMM_RETRY", NULL};void scsi_print_hostbyte(int scsiresult){   static int maxcode=0;    int i;       if(!maxcode) {	for(i=0;hostbyte_table[i];i++) ;	maxcode=i-1;    }    printk("Hostbyte=0x%02x",host_byte(scsiresult));    if(host_byte(scsiresult)>maxcode) {	printk("is invalid "); 	return;    }    printk("(%s) ",hostbyte_table[host_byte(scsiresult)]);}#elsevoid scsi_print_hostbyte(int scsiresult){   printk("Hostbyte=0x%02x ",host_byte(scsiresult));}#endif#if (CONSTANTS & CONST_DRIVER)static const char * driverbyte_table[]={"DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT",  "DRIVER_MEDIA", "DRIVER_ERROR", "DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD",NULL };static const char * driversuggest_table[]={"SUGGEST_OK","SUGGEST_RETRY", "SUGGEST_ABORT", "SUGGEST_REMAP", "SUGGEST_DIE",unknown,unknown,unknown, "SUGGEST_SENSE",NULL};void scsi_print_driverbyte(int scsiresult){   static int driver_max=0,suggest_max=0;    int i,dr=driver_byte(scsiresult)&DRIVER_MASK, 	su=(driver_byte(scsiresult)&SUGGEST_MASK)>>4;    if(!driver_max) {        for(i=0;driverbyte_table[i];i++) ;        driver_max=i;	for(i=0;driversuggest_table[i];i++) ;	suggest_max=i;    }    printk("Driverbyte=0x%02x",driver_byte(scsiresult));    printk("(%s,%s) ",	dr<driver_max  ? driverbyte_table[dr]:"invalid",	su<suggest_max ? driversuggest_table[su]:"invalid");}#elsevoid scsi_print_driverbyte(int scsiresult){   printk("Driverbyte=0x%02x ",driver_byte(scsiresult));}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?