Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[SCSI] Improve inquiry printing

- Replace scsi_device_types array API with scsi_device_type function API.
Gets rid of a lot of common code, as well as being easier to use.
- Add the new device types in SPC4 r05a, and rename some of the older ones.
- Reformat the printing of inquiry data; now fits on one line and
includes PQ.

I think I've addressed all the feedback from the previous versions. My
current test box prints:

scsi 2:0:1:0: Direct access HP 18.2G ATLAS10K3_18_SCA HP05 PQ: 0 ANSI: 2

Signed-off-by: Matthew Wilcox <matthew@wil.cx>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>

authored by

Matthew Wilcox and committed by
James Bottomley
4ff36718 008cd5bb

+46 -94
+5 -9
drivers/block/cciss_scsi.c
··· 251 251 stk->pool = NULL; 252 252 } 253 253 254 - /* scsi_device_types comes from scsi.h */ 255 - #define DEVICETYPE(n) (n<0 || n>MAX_SCSI_DEVICE_CODE) ? \ 256 - "Unknown" : scsi_device_types[n] 257 - 258 254 #if 0 259 255 static int xmargin=8; 260 256 static int amargin=60; ··· 385 389 time anyway (the scsi layer's inquiries will show that info) */ 386 390 if (hostno != -1) 387 391 printk("cciss%d: %s device c%db%dt%dl%d added.\n", 388 - ctlr, DEVICETYPE(sd->devtype), hostno, 392 + ctlr, scsi_device_type(sd->devtype), hostno, 389 393 sd->bus, sd->target, sd->lun); 390 394 return 0; 391 395 } ··· 403 407 ccissscsi[ctlr].dev[i] = ccissscsi[ctlr].dev[i+1]; 404 408 ccissscsi[ctlr].ndevices--; 405 409 printk("cciss%d: %s device c%db%dt%dl%d removed.\n", 406 - ctlr, DEVICETYPE(sd.devtype), hostno, 410 + ctlr, scsi_device_type(sd.devtype), hostno, 407 411 sd.bus, sd.target, sd.lun); 408 412 } 409 413 ··· 454 458 if (found == 0) { /* device no longer present. */ 455 459 changes++; 456 460 /* printk("cciss%d: %s device c%db%dt%dl%d removed.\n", 457 - ctlr, DEVICETYPE(csd->devtype), hostno, 461 + ctlr, scsi_device_type(csd->devtype), hostno, 458 462 csd->bus, csd->target, csd->lun); */ 459 463 cciss_scsi_remove_entry(ctlr, hostno, i); 460 464 /* note, i not incremented */ ··· 464 468 printk("cciss%d: device c%db%dt%dl%d type changed " 465 469 "(device type now %s).\n", 466 470 ctlr, hostno, csd->bus, csd->target, csd->lun, 467 - DEVICETYPE(csd->devtype)); 471 + scsi_device_type(csd->devtype)); 468 472 csd->devtype = sd[j].devtype; 469 473 i++; /* so just move along. */ 470 474 } else /* device is same as it ever was, */ ··· 1094 1098 if (ncurrent >= CCISS_MAX_SCSI_DEVS_PER_HBA) { 1095 1099 printk(KERN_INFO "cciss%d: %s ignored, " 1096 1100 "too many devices.\n", cntl_num, 1097 - DEVICETYPE(devtype)); 1101 + scsi_device_type(devtype)); 1098 1102 break; 1099 1103 } 1100 1104 memcpy(&currentsd[ncurrent].scsi3addr[0],
+1 -2
drivers/scsi/fcal.c
··· 248 248 if (scd->id == target) { 249 249 SPRINTF (" [AL-PA: %02x, Id: %02d, Port WWN: %08x%08x, Node WWN: %08x%08x] ", 250 250 alpa, target, u1[0], u1[1], u2[0], u2[1]); 251 - SPRINTF ("%s ", (scd->type < MAX_SCSI_DEVICE_CODE) ? 252 - scsi_device_types[(short) scd->type] : "Unknown device"); 251 + SPRINTF ("%s ", scsi_device_type(scd->type)); 253 252 254 253 for (j = 0; (j < 8) && (scd->vendor[j] >= 0x20); j++) 255 254 SPRINTF ("%c", scd->vendor[j]);
+1 -2
drivers/scsi/g_NCR5380.c
··· 811 811 struct NCR5380_hostdata *hostdata; 812 812 #ifdef NCR5380_STATS 813 813 struct scsi_device *dev; 814 - extern const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE]; 815 814 #endif 816 815 817 816 NCR5380_setup(scsi_ptr); ··· 850 851 long tr = hostdata->time_read[dev->id] / HZ; 851 852 long tw = hostdata->time_write[dev->id] / HZ; 852 853 853 - PRINTP(" T:%d %s " ANDP dev->id ANDP(dev->type < MAX_SCSI_DEVICE_CODE) ? scsi_device_types[(int) dev->type] : "Unknown"); 854 + PRINTP(" T:%d %s " ANDP dev->id ANDP scsi_device_type(dev->type)); 854 855 for (i = 0; i < 8; i++) 855 856 if (dev->vendor[i] >= 0x20) 856 857 *(buffer + (len++)) = dev->vendor[i];
+1 -3
drivers/scsi/megaraid.c
··· 2822 2822 2823 2823 i = scsi_inq[0] & 0x1f; 2824 2824 2825 - len += sprintf(page+len, " Type: %s ", 2826 - i < MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] : 2827 - "Unknown "); 2825 + len += sprintf(page+len, " Type: %s ", scsi_device_type(i)); 2828 2826 2829 2827 len += sprintf(page+len, 2830 2828 " ANSI SCSI revision: %02x", scsi_inq[2] & 0x07);
+26 -10
drivers/scsi/scsi.c
··· 96 96 EXPORT_SYMBOL(scsi_logging_level); 97 97 #endif 98 98 99 - const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE] = { 100 - "Direct-Access ", 101 - "Sequential-Access", 99 + static const char *const scsi_device_types[] = { 100 + "Direct access ", 101 + "Sequential access", 102 102 "Printer ", 103 103 "Processor ", 104 104 "WORM ", 105 - "CD-ROM ", 105 + "CD/DVD ", 106 106 "Scanner ", 107 - "Optical Device ", 108 - "Medium Changer ", 107 + "Optical memory ", 108 + "Media changer ", 109 109 "Communications ", 110 - "Unknown ", 111 - "Unknown ", 110 + "ASC IT8 ", 111 + "ASC IT8 ", 112 112 "RAID ", 113 113 "Enclosure ", 114 - "Direct-Access-RBC", 114 + "Direct access RBC", 115 + "Optical card ", 116 + "Bridge controller", 117 + "Object storage ", 118 + "Automation/Drive ", 115 119 }; 116 - EXPORT_SYMBOL(scsi_device_types); 120 + 121 + const char * scsi_device_type(unsigned type) 122 + { 123 + if (type == 0x1e) 124 + return "Well-known LUN "; 125 + if (type == 0x1f) 126 + return "No Device "; 127 + if (type > ARRAY_SIZE(scsi_device_types)) 128 + return "Unknown "; 129 + return scsi_device_types[type]; 130 + } 131 + 132 + EXPORT_SYMBOL(scsi_device_type); 117 133 118 134 struct scsi_host_cmd_pool { 119 135 kmem_cache_t *slab;
+1 -3
drivers/scsi/scsi_proc.c
··· 178 178 179 179 seq_printf(s, "\n"); 180 180 181 - seq_printf(s, " Type: %s ", 182 - sdev->type < MAX_SCSI_DEVICE_CODE ? 183 - scsi_device_types[(int) sdev->type] : "Unknown "); 181 + seq_printf(s, " Type: %s ", scsi_device_type(sdev->type)); 184 182 seq_printf(s, " ANSI" 185 183 " SCSI revision: %02x", (sdev->scsi_level - 1) ? 186 184 sdev->scsi_level - 1 : 1);
+8 -58
drivers/scsi/scsi_scan.c
··· 134 134 } 135 135 136 136 /** 137 - * print_inquiry - printk the inquiry information 138 - * @inq_result: printk this SCSI INQUIRY 139 - * 140 - * Description: 141 - * printk the vendor, model, and other information found in the 142 - * INQUIRY data in @inq_result. 143 - * 144 - * Notes: 145 - * Remove this, and replace with a hotplug event that logs any 146 - * relevant information. 147 - **/ 148 - static void print_inquiry(unsigned char *inq_result) 149 - { 150 - int i; 151 - 152 - printk(KERN_NOTICE " Vendor: "); 153 - for (i = 8; i < 16; i++) 154 - if (inq_result[i] >= 0x20 && i < inq_result[4] + 5) 155 - printk("%c", inq_result[i]); 156 - else 157 - printk(" "); 158 - 159 - printk(" Model: "); 160 - for (i = 16; i < 32; i++) 161 - if (inq_result[i] >= 0x20 && i < inq_result[4] + 5) 162 - printk("%c", inq_result[i]); 163 - else 164 - printk(" "); 165 - 166 - printk(" Rev: "); 167 - for (i = 32; i < 36; i++) 168 - if (inq_result[i] >= 0x20 && i < inq_result[4] + 5) 169 - printk("%c", inq_result[i]); 170 - else 171 - printk(" "); 172 - 173 - printk("\n"); 174 - 175 - i = inq_result[0] & 0x1f; 176 - 177 - printk(KERN_NOTICE " Type: %s ", 178 - i < 179 - MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] : 180 - "Unknown "); 181 - printk(" ANSI SCSI revision: %02x", 182 - inq_result[2] & 0x07); 183 - if ((inq_result[2] & 0x07) == 1 && (inq_result[3] & 0x0f) == 1) 184 - printk(" CCS\n"); 185 - else 186 - printk("\n"); 187 - } 188 - 189 - /** 190 137 * scsi_alloc_sdev - allocate and setup a scsi_Device 191 138 * 192 139 * Description: ··· 600 653 if (*bflags & BLIST_ISROM) { 601 654 /* 602 655 * It would be better to modify sdev->type, and set 603 - * sdev->removable, but then the print_inquiry() output 604 - * would not show TYPE_ROM; if print_inquiry() is removed 605 - * the issue goes away. 656 + * sdev->removable; this can now be done since 657 + * print_inquiry has gone away. 606 658 */ 607 659 inq_result[0] = TYPE_ROM; 608 660 inq_result[1] |= 0x80; /* removable */ ··· 629 683 default: 630 684 printk(KERN_INFO "scsi: unknown device type %d\n", sdev->type); 631 685 } 632 - 633 - print_inquiry(inq_result); 634 686 635 687 /* 636 688 * For a peripheral qualifier (PQ) value of 1 (001b), the SCSI ··· 658 714 sdev->wdtr = 1; 659 715 if (inq_result[7] & 0x10) 660 716 sdev->sdtr = 1; 717 + 718 + sdev_printk(KERN_NOTICE "scsi", sdev, "%s %.8s %.16s %.4s PQ: %d " 719 + "ANSI: %d%s\n", scsi_device_type(sdev->type), 720 + sdev->vendor, sdev->model, sdev->rev, 721 + sdev->inq_periph_qual, inq_result[2] & 0x07, 722 + (inq_result[3] & 0x0f) == 1 ? " CCS" : ""); 661 723 662 724 /* 663 725 * End sysfs code.
+3 -7
include/scsi/scsi.h
··· 25 25 #define COMMAND_SIZE(opcode) scsi_command_size[((opcode) >> 5) & 7] 26 26 27 27 /* 28 - * SCSI device types 29 - */ 30 - 31 - #define MAX_SCSI_DEVICE_CODE 15 32 - extern const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE]; 33 - 34 - /* 35 28 * Special value for scanning to specify scanning or rescanning of all 36 29 * possible channels, (target) ids, or luns on a given shost. 37 30 */ ··· 217 224 #define TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */ 218 225 #define TYPE_RBC 0x0e 219 226 #define TYPE_NO_LUN 0x7f 227 + 228 + /* Returns a human-readable name for the device */ 229 + extern const char * scsi_device_type(unsigned type); 220 230 221 231 /* 222 232 * standard mode-select header prepended to all mode-select commands