Skip to content

Commit 4ff3671

Browse files
Matthew WilcoxJames Bottomley
authored andcommitted
[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>
1 parent 008cd5b commit 4ff3671

8 files changed

Lines changed: 46 additions & 94 deletions

File tree

‎drivers/block/cciss_scsi.c‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,6 @@ scsi_cmd_stack_free(int ctlr)
251251
stk->pool = NULL;
252252
}
253253

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-
258254
#if 0
259255
static int xmargin=8;
260256
static int amargin=60;
@@ -389,7 +385,7 @@ cciss_scsi_add_entry(int ctlr, int hostno,
389385
time anyway (the scsi layer's inquiries will show that info) */
390386
if (hostno != -1)
391387
printk("cciss%d: %s device c%db%dt%dl%d added.\n",
392-
ctlr, DEVICETYPE(sd->devtype), hostno,
388+
ctlr, scsi_device_type(sd->devtype), hostno,
393389
sd->bus, sd->target, sd->lun);
394390
return 0;
395391
}
@@ -407,7 +403,7 @@ cciss_scsi_remove_entry(int ctlr, int hostno, int entry)
407403
ccissscsi[ctlr].dev[i] = ccissscsi[ctlr].dev[i+1];
408404
ccissscsi[ctlr].ndevices--;
409405
printk("cciss%d: %s device c%db%dt%dl%d removed.\n",
410-
ctlr, DEVICETYPE(sd.devtype), hostno,
406+
ctlr, scsi_device_type(sd.devtype), hostno,
411407
sd.bus, sd.target, sd.lun);
412408
}
413409

@@ -458,7 +454,7 @@ adjust_cciss_scsi_table(int ctlr, int hostno,
458454
if (found == 0) { /* device no longer present. */
459455
changes++;
460456
/* printk("cciss%d: %s device c%db%dt%dl%d removed.\n",
461-
ctlr, DEVICETYPE(csd->devtype), hostno,
457+
ctlr, scsi_device_type(csd->devtype), hostno,
462458
csd->bus, csd->target, csd->lun); */
463459
cciss_scsi_remove_entry(ctlr, hostno, i);
464460
/* note, i not incremented */
@@ -468,7 +464,7 @@ adjust_cciss_scsi_table(int ctlr, int hostno,
468464
printk("cciss%d: device c%db%dt%dl%d type changed "
469465
"(device type now %s).\n",
470466
ctlr, hostno, csd->bus, csd->target, csd->lun,
471-
DEVICETYPE(csd->devtype));
467+
scsi_device_type(csd->devtype));
472468
csd->devtype = sd[j].devtype;
473469
i++; /* so just move along. */
474470
} else /* device is same as it ever was, */
@@ -1098,7 +1094,7 @@ cciss_update_non_disk_devices(int cntl_num, int hostno)
10981094
if (ncurrent >= CCISS_MAX_SCSI_DEVS_PER_HBA) {
10991095
printk(KERN_INFO "cciss%d: %s ignored, "
11001096
"too many devices.\n", cntl_num,
1101-
DEVICETYPE(devtype));
1097+
scsi_device_type(devtype));
11021098
break;
11031099
}
11041100
memcpy(&currentsd[ncurrent].scsi3addr[0],

‎drivers/scsi/fcal.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,7 @@ int fcal_proc_info (struct Scsi_Host *host, char *buffer, char **start, off_t of
248248
if (scd->id == target) {
249249
SPRINTF (" [AL-PA: %02x, Id: %02d, Port WWN: %08x%08x, Node WWN: %08x%08x] ",
250250
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));
253252

254253
for (j = 0; (j < 8) && (scd->vendor[j] >= 0x20); j++)
255254
SPRINTF ("%c", scd->vendor[j]);

‎drivers/scsi/g_NCR5380.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,6 @@ static int generic_NCR5380_proc_info(struct Scsi_Host *scsi_ptr, char *buffer, c
811811
struct NCR5380_hostdata *hostdata;
812812
#ifdef NCR5380_STATS
813813
struct scsi_device *dev;
814-
extern const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE];
815814
#endif
816815

817816
NCR5380_setup(scsi_ptr);
@@ -851,7 +850,7 @@ static int generic_NCR5380_proc_info(struct Scsi_Host *scsi_ptr, char *buffer, c
851850
long tr = hostdata->time_read[dev->id] / HZ;
852851
long tw = hostdata->time_write[dev->id] / HZ;
853852

854-
PRINTP(" T:%d %s " ANDP dev->id ANDP(dev->type < MAX_SCSI_DEVICE_CODE) ? scsi_device_types[(int) dev->type] : "Unknown");
853+
PRINTP(" T:%d %s " ANDP dev->id ANDP scsi_device_type(dev->type));
855854
for (i = 0; i < 8; i++)
856855
if (dev->vendor[i] >= 0x20)
857856
*(buffer + (len++)) = dev->vendor[i];

‎drivers/scsi/megaraid.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,9 +2822,7 @@ mega_print_inquiry(char *page, char *scsi_inq)
28222822

28232823
i = scsi_inq[0] & 0x1f;
28242824

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));
28282826

28292827
len += sprintf(page+len,
28302828
" ANSI SCSI revision: %02x", scsi_inq[2] & 0x07);

‎drivers/scsi/scsi.c‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,24 +96,40 @@ unsigned int scsi_logging_level;
9696
EXPORT_SYMBOL(scsi_logging_level);
9797
#endif
9898

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",
102102
"Printer ",
103103
"Processor ",
104104
"WORM ",
105-
"CD-ROM ",
105+
"CD/DVD ",
106106
"Scanner ",
107-
"Optical Device ",
108-
"Medium Changer ",
107+
"Optical memory ",
108+
"Media changer ",
109109
"Communications ",
110-
"Unknown ",
111-
"Unknown ",
110+
"ASC IT8 ",
111+
"ASC IT8 ",
112112
"RAID ",
113113
"Enclosure ",
114-
"Direct-Access-RBC",
114+
"Direct access RBC",
115+
"Optical card ",
116+
"Bridge controller",
117+
"Object storage ",
118+
"Automation/Drive ",
115119
};
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);
117133

118134
struct scsi_host_cmd_pool {
119135
kmem_cache_t *slab;

‎drivers/scsi/scsi_proc.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ static int proc_print_scsidevice(struct device *dev, void *data)
178178

179179
seq_printf(s, "\n");
180180

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));
184182
seq_printf(s, " ANSI"
185183
" SCSI revision: %02x", (sdev->scsi_level - 1) ?
186184
sdev->scsi_level - 1 : 1);

‎drivers/scsi/scsi_scan.c‎

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -133,59 +133,6 @@ static void scsi_unlock_floptical(struct scsi_device *sdev,
133133
SCSI_TIMEOUT, 3);
134134
}
135135

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-
189136
/**
190137
* scsi_alloc_sdev - allocate and setup a scsi_Device
191138
*
@@ -653,9 +600,8 @@ static int scsi_add_lun(struct scsi_device *sdev, char *inq_result, int *bflags)
653600
if (*bflags & BLIST_ISROM) {
654601
/*
655602
* It would be better to modify sdev->type, and set
656-
* sdev->removable, but then the print_inquiry() output
657-
* would not show TYPE_ROM; if print_inquiry() is removed
658-
* the issue goes away.
603+
* sdev->removable; this can now be done since
604+
* print_inquiry has gone away.
659605
*/
660606
inq_result[0] = TYPE_ROM;
661607
inq_result[1] |= 0x80; /* removable */
@@ -684,8 +630,6 @@ static int scsi_add_lun(struct scsi_device *sdev, char *inq_result, int *bflags)
684630
printk(KERN_INFO "scsi: unknown device type %d\n", sdev->type);
685631
}
686632

687-
print_inquiry(inq_result);
688-
689633
/*
690634
* For a peripheral qualifier (PQ) value of 1 (001b), the SCSI
691635
* spec says: The device server is capable of supporting the
@@ -715,6 +659,12 @@ static int scsi_add_lun(struct scsi_device *sdev, char *inq_result, int *bflags)
715659
if (inq_result[7] & 0x10)
716660
sdev->sdtr = 1;
717661

662+
sdev_printk(KERN_NOTICE "scsi", sdev, "%s %.8s %.16s %.4s PQ: %d "
663+
"ANSI: %d%s\n", scsi_device_type(sdev->type),
664+
sdev->vendor, sdev->model, sdev->rev,
665+
sdev->inq_periph_qual, inq_result[2] & 0x07,
666+
(inq_result[3] & 0x0f) == 1 ? " CCS" : "");
667+
718668
/*
719669
* End sysfs code.
720670
*/

‎include/scsi/scsi.h‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@
2424
extern const unsigned char scsi_command_size[8];
2525
#define COMMAND_SIZE(opcode) scsi_command_size[((opcode) >> 5) & 7]
2626

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-
3427
/*
3528
* Special value for scanning to specify scanning or rescanning of all
3629
* possible channels, (target) ids, or luns on a given shost.
@@ -225,6 +218,9 @@ static inline int scsi_status_is_good(int status)
225218
#define TYPE_RBC 0x0e
226219
#define TYPE_NO_LUN 0x7f
227220

221+
/* Returns a human-readable name for the device */
222+
extern const char * scsi_device_type(unsigned type);
223+
228224
/*
229225
* standard mode-select header prepended to all mode-select commands
230226
*/

0 commit comments

Comments
 (0)