Import 2.3.47pre1
[davej-history.git] / drivers / scsi / scsi_scan.c
blob6f22c402244655d50d757cb5d2009e0d2b176a80
1 /*
2 * scsi_scan.c Copyright (C) 2000 Eric Youngdale
4 * Bus scan logic.
6 * This used to live in scsi.c, but that file was just a laundry basket
7 * full of misc stuff. This got separated out in order to make things
8 * clearer.
9 */
11 #define __NO_VERSION__
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
16 #include <linux/blk.h>
18 #include "scsi.h"
19 #include "hosts.h"
20 #include "constants.h"
22 #ifdef CONFIG_KMOD
23 #include <linux/kmod.h>
24 #endif
26 /* The following devices are known not to tolerate a lun != 0 scan for
27 * one reason or another. Some will respond to all luns, others will
28 * lock up.
31 #define BLIST_NOLUN 0x001
32 #define BLIST_FORCELUN 0x002
33 #define BLIST_BORKEN 0x004
34 #define BLIST_KEY 0x008
35 #define BLIST_SINGLELUN 0x010
36 #define BLIST_NOTQ 0x020
37 #define BLIST_SPARSELUN 0x040
38 #define BLIST_MAX5LUN 0x080
39 #define BLIST_ISDISK 0x100
40 #define BLIST_ISROM 0x200
41 #define BLIST_GHOST 0x400
43 static void print_inquiry(unsigned char *data);
44 static int scan_scsis_single(int channel, int dev, int lun, int *max_scsi_dev,
45 int *sparse_lun, Scsi_Device ** SDpnt,
46 struct Scsi_Host *shpnt, char *scsi_result);
48 struct dev_info {
49 const char *vendor;
50 const char *model;
51 const char *revision; /* Latest revision known to be bad. Not used yet */
52 unsigned flags;
56 * This is what was previously known as the blacklist. The concept
57 * has been expanded so that we can specify other types of things we
58 * need to be aware of.
60 static struct dev_info device_list[] =
62 {"Aashima", "IMAGERY 2400SP", "1.03", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
63 {"CHINON", "CD-ROM CDS-431", "H42", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
64 {"CHINON", "CD-ROM CDS-535", "Q14", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
65 {"DENON", "DRD-25X", "V", BLIST_NOLUN}, /* Locks up if probed for lun != 0 */
66 {"HITACHI", "DK312C", "CM81", BLIST_NOLUN}, /* Responds to all lun - dtg */
67 {"HITACHI", "DK314C", "CR21", BLIST_NOLUN}, /* responds to all lun */
68 {"IMS", "CDD521/10", "2.06", BLIST_NOLUN}, /* Locks-up when LUN>0 polled. */
69 {"MAXTOR", "XT-3280", "PR02", BLIST_NOLUN}, /* Locks-up when LUN>0 polled. */
70 {"MAXTOR", "XT-4380S", "B3C", BLIST_NOLUN}, /* Locks-up when LUN>0 polled. */
71 {"MAXTOR", "MXT-1240S", "I1.2", BLIST_NOLUN}, /* Locks up when LUN>0 polled */
72 {"MAXTOR", "XT-4170S", "B5A", BLIST_NOLUN}, /* Locks-up sometimes when LUN>0 polled. */
73 {"MAXTOR", "XT-8760S", "B7B", BLIST_NOLUN}, /* guess what? */
74 {"MEDIAVIS", "RENO CD-ROMX2A", "2.03", BLIST_NOLUN}, /*Responds to all lun */
75 {"MICROP", "4110", "*", BLIST_NOTQ}, /* Buggy Tagged Queuing */
76 {"NEC", "CD-ROM DRIVE:841", "1.0", BLIST_NOLUN}, /* Locks-up when LUN>0 polled. */
77 {"PHILIPS", "PCA80SC", "V4-2", BLIST_NOLUN}, /* Responds to all lun */
78 {"RODIME", "RO3000S", "2.33", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
79 {"SANYO", "CRD-250S", "1.20", BLIST_NOLUN}, /* causes failed REQUEST SENSE on lun 1
80 * for aha152x controller, which causes
81 * SCSI code to reset bus.*/
82 {"SEAGATE", "ST157N", "\004|j", BLIST_NOLUN}, /* causes failed REQUEST SENSE on lun 1
83 * for aha152x controller, which causes
84 * SCSI code to reset bus.*/
85 {"SEAGATE", "ST296", "921", BLIST_NOLUN}, /* Responds to all lun */
86 {"SEAGATE", "ST1581", "6538", BLIST_NOLUN}, /* Responds to all lun */
87 {"SONY", "CD-ROM CDU-541", "4.3d", BLIST_NOLUN},
88 {"SONY", "CD-ROM CDU-55S", "1.0i", BLIST_NOLUN},
89 {"SONY", "CD-ROM CDU-561", "1.7x", BLIST_NOLUN},
90 {"SONY", "CD-ROM CDU-8012", "*", BLIST_NOLUN},
91 {"TANDBERG", "TDC 3600", "U07", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
92 {"TEAC", "CD-R55S", "1.0H", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
93 {"TEAC", "CD-ROM", "1.06", BLIST_NOLUN}, /* causes failed REQUEST SENSE on lun 1
94 * for seagate controller, which causes
95 * SCSI code to reset bus.*/
96 {"TEAC", "MT-2ST/45S2-27", "RV M", BLIST_NOLUN}, /* Responds to all lun */
97 {"TEXEL", "CD-ROM", "1.06", BLIST_NOLUN}, /* causes failed REQUEST SENSE on lun 1
98 * for seagate controller, which causes
99 * SCSI code to reset bus.*/
100 {"QUANTUM", "LPS525S", "3110", BLIST_NOLUN}, /* Locks sometimes if polled for lun != 0 */
101 {"QUANTUM", "PD1225S", "3110", BLIST_NOLUN}, /* Locks sometimes if polled for lun != 0 */
102 {"QUANTUM", "FIREBALL ST4.3S", "0F0C", BLIST_NOLUN}, /* Locks up when polled for lun != 0 */
103 {"MEDIAVIS", "CDR-H93MV", "1.31", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
104 {"SANKYO", "CP525", "6.64", BLIST_NOLUN}, /* causes failed REQ SENSE, extra reset */
105 {"HP", "C1750A", "3226", BLIST_NOLUN}, /* scanjet iic */
106 {"HP", "C1790A", "", BLIST_NOLUN}, /* scanjet iip */
107 {"HP", "C2500A", "", BLIST_NOLUN}, /* scanjet iicx */
108 {"YAMAHA", "CDR100", "1.00", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
109 {"YAMAHA", "CDR102", "1.00", BLIST_NOLUN}, /* Locks up if polled for lun != 0
110 * extra reset */
111 {"RELISYS", "Scorpio", "*", BLIST_NOLUN}, /* responds to all LUN */
112 {"MICROTEK", "ScanMaker II", "5.61", BLIST_NOLUN}, /* responds to all LUN */
115 * Other types of devices that have special flags.
117 {"SONY", "CD-ROM CDU-8001", "*", BLIST_BORKEN},
118 {"TEXEL", "CD-ROM", "1.06", BLIST_BORKEN},
119 {"IOMEGA", "Io20S *F", "*", BLIST_KEY},
120 {"INSITE", "Floptical F*8I", "*", BLIST_KEY},
121 {"INSITE", "I325VM", "*", BLIST_KEY},
122 {"LASOUND","CDX7405","3.10", BLIST_MAX5LUN | BLIST_SINGLELUN},
123 {"NRC", "MBR-7", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
124 {"NRC", "MBR-7.4", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
125 {"REGAL", "CDC-4X", "*", BLIST_MAX5LUN | BLIST_SINGLELUN},
126 {"NAKAMICH", "MJ-4.8S", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
127 {"NAKAMICH", "MJ-5.16S", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
128 {"PIONEER", "CD-ROM DRM-600", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
129 {"PIONEER", "CD-ROM DRM-602X", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
130 {"PIONEER", "CD-ROM DRM-604X", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
131 {"EMULEX", "MD21/S2 ESDI", "*", BLIST_SINGLELUN},
132 {"CANON", "IPUBJD", "*", BLIST_SPARSELUN},
133 {"nCipher", "Fastness Crypto", "*", BLIST_FORCELUN},
134 {"NEC", "PD-1 ODX654P", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
135 {"MATSHITA", "PD-1", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
136 {"iomega", "jaz 1GB", "J.86", BLIST_NOTQ | BLIST_NOLUN},
137 {"CREATIVE","DVD-RAM RAM","*", BLIST_GHOST},
138 {"MATSHITA","PD-2 LF-D100","*", BLIST_GHOST},
139 {"HITACHI", "GF-1050","*", BLIST_GHOST}, /* Hitachi SCSI DVD-RAM */
140 {"TOSHIBA","CDROM","*", BLIST_ISROM},
141 {"TOSHIBA","DVD-RAM SD-W1101","*", BLIST_GHOST},
142 {"TOSHIBA","DVD-RAM SD-W1111","*", BLIST_GHOST},
145 * Must be at end of list...
147 {NULL, NULL, NULL}
150 #ifdef CONFIG_SCSI_MULTI_LUN
151 static int max_scsi_luns = 8;
152 #else
153 static int max_scsi_luns = 1;
154 #endif
156 #ifdef MODULE
158 MODULE_PARM(max_scsi_luns, "i");
159 MODULE_PARM_DESC(max_scsi_luns, "last scsi LUN (should be between 1 and 8)");
161 #else
163 static int __init scsi_luns_setup(char *str)
165 int tmp;
167 if (get_option(&str, &tmp) == 1) {
168 max_scsi_luns = tmp;
169 return 1;
170 } else {
171 printk("scsi_luns_setup : usage max_scsi_luns=n "
172 "(n should be between 1 and 8)\n");
173 return 0;
177 __setup("max_scsi_luns=", scsi_luns_setup);
179 #endif
181 static void print_inquiry(unsigned char *data)
183 int i;
185 printk(" Vendor: ");
186 for (i = 8; i < 16; i++) {
187 if (data[i] >= 0x20 && i < data[4] + 5)
188 printk("%c", data[i]);
189 else
190 printk(" ");
193 printk(" Model: ");
194 for (i = 16; i < 32; i++) {
195 if (data[i] >= 0x20 && i < data[4] + 5)
196 printk("%c", data[i]);
197 else
198 printk(" ");
201 printk(" Rev: ");
202 for (i = 32; i < 36; i++) {
203 if (data[i] >= 0x20 && i < data[4] + 5)
204 printk("%c", data[i]);
205 else
206 printk(" ");
209 printk("\n");
211 i = data[0] & 0x1f;
213 printk(" Type: %s ",
214 i < MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] : "Unknown ");
215 printk(" ANSI SCSI revision: %02x", data[2] & 0x07);
216 if ((data[2] & 0x07) == 1 && (data[3] & 0x0f) == 1)
217 printk(" CCS\n");
218 else
219 printk("\n");
222 static int get_device_flags(unsigned char *response_data)
224 int i = 0;
225 unsigned char *pnt;
226 for (i = 0; 1; i++) {
227 if (device_list[i].vendor == NULL)
228 return 0;
229 pnt = &response_data[8];
230 while (*pnt && *pnt == ' ')
231 pnt++;
232 if (memcmp(device_list[i].vendor, pnt,
233 strlen(device_list[i].vendor)))
234 continue;
235 pnt = &response_data[16];
236 while (*pnt && *pnt == ' ')
237 pnt++;
238 if (memcmp(device_list[i].model, pnt,
239 strlen(device_list[i].model)))
240 continue;
241 return device_list[i].flags;
243 return 0;
247 * Detecting SCSI devices :
248 * We scan all present host adapter's busses, from ID 0 to ID (max_id).
249 * We use the INQUIRY command, determine device type, and pass the ID /
250 * lun address of all sequential devices to the tape driver, all random
251 * devices to the disk driver.
253 void scan_scsis(struct Scsi_Host *shpnt,
254 unchar hardcoded,
255 unchar hchannel,
256 unchar hid,
257 unchar hlun)
259 int channel;
260 int dev;
261 int lun;
262 int max_dev_lun;
263 unsigned char *scsi_result;
264 unsigned char scsi_result0[256];
265 Scsi_Device *SDpnt;
266 Scsi_Device *SDtail;
267 int sparse_lun;
269 scsi_result = NULL;
271 SDpnt = (Scsi_Device *) kmalloc(sizeof(Scsi_Device),
272 GFP_ATOMIC);
273 if (SDpnt) {
274 memset(SDpnt, 0, sizeof(Scsi_Device));
276 * Register the queue for the device. All I/O requests will come
277 * in through here. We also need to register a pointer to
278 * ourselves, since the queue handler won't know what device
279 * the queue actually represents. We could look it up, but it
280 * is pointless work.
282 scsi_initialize_queue(SDpnt, shpnt);
283 blk_queue_headactive(&SDpnt->request_queue, 0);
284 SDpnt->request_queue.queuedata = (void *) SDpnt;
285 /* Make sure we have something that is valid for DMA purposes */
286 scsi_result = ((!shpnt->unchecked_isa_dma)
287 ? &scsi_result0[0] : kmalloc(512, GFP_DMA));
290 if (scsi_result == NULL) {
291 printk("Unable to obtain scsi_result buffer\n");
292 goto leave;
295 * We must chain ourself in the host_queue, so commands can time out
297 SDpnt->queue_depth = 1;
298 SDpnt->host = shpnt;
299 SDpnt->online = TRUE;
301 scsi_build_commandblocks(SDpnt);
303 initialize_merge_fn(SDpnt);
306 * Initialize the object that we will use to wait for command blocks.
308 init_waitqueue_head(&SDpnt->scpnt_wait);
311 * Next, hook the device to the host in question.
313 SDpnt->prev = NULL;
314 SDpnt->next = NULL;
315 if (shpnt->host_queue != NULL) {
316 SDtail = shpnt->host_queue;
317 while (SDtail->next != NULL)
318 SDtail = SDtail->next;
320 SDtail->next = SDpnt;
321 SDpnt->prev = SDtail;
322 } else {
323 shpnt->host_queue = SDpnt;
327 * We need to increment the counter for this one device so we can track when
328 * things are quiet.
330 if (hardcoded == 1) {
331 Scsi_Device *oldSDpnt = SDpnt;
332 struct Scsi_Device_Template *sdtpnt;
333 channel = hchannel;
334 if (channel > shpnt->max_channel)
335 goto leave;
336 dev = hid;
337 if (dev >= shpnt->max_id)
338 goto leave;
339 lun = hlun;
340 if (lun >= shpnt->max_lun)
341 goto leave;
342 scan_scsis_single(channel, dev, lun, &max_dev_lun, &sparse_lun,
343 &SDpnt, shpnt, scsi_result);
344 if (SDpnt != oldSDpnt) {
346 /* it could happen the blockdevice hasn't yet been inited */
347 for (sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
348 if (sdtpnt->init && sdtpnt->dev_noticed)
349 (*sdtpnt->init) ();
351 for (sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next) {
352 if (sdtpnt->attach) {
353 (*sdtpnt->attach) (oldSDpnt);
354 if (oldSDpnt->attached) {
355 scsi_build_commandblocks(oldSDpnt);
356 if (0 == oldSDpnt->has_cmdblocks) {
357 printk("scan_scsis: DANGER, no command blocks\n");
358 /* What to do now ?? */
363 scsi_resize_dma_pool();
365 for (sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next) {
366 if (sdtpnt->finish && sdtpnt->nr_dev) {
367 (*sdtpnt->finish) ();
371 } else {
372 /* Actual LUN. PC ordering is 0->n IBM/spec ordering is n->0 */
373 int order_dev;
375 for (channel = 0; channel <= shpnt->max_channel; channel++) {
376 for (dev = 0; dev < shpnt->max_id; ++dev) {
377 if (shpnt->reverse_ordering)
378 /* Shift to scanning 15,14,13... or 7,6,5,4, */
379 order_dev = shpnt->max_id - dev - 1;
380 else
381 order_dev = dev;
383 if (shpnt->this_id != order_dev) {
386 * We need the for so our continue, etc. work fine. We put this in
387 * a variable so that we can override it during the scan if we
388 * detect a device *KNOWN* to have multiple logical units.
390 max_dev_lun = (max_scsi_luns < shpnt->max_lun ?
391 max_scsi_luns : shpnt->max_lun);
392 sparse_lun = 0;
393 for (lun = 0; lun < max_dev_lun; ++lun) {
394 if (!scan_scsis_single(channel, order_dev, lun, &max_dev_lun,
395 &sparse_lun, &SDpnt, shpnt,
396 scsi_result)
397 && !sparse_lun)
398 break; /* break means don't probe further for luns!=0 */
399 } /* for lun ends */
400 } /* if this_id != id ends */
401 } /* for dev ends */
402 } /* for channel ends */
403 } /* if/else hardcoded */
405 leave:
407 { /* Unchain SCpnt from host_queue */
408 Scsi_Device *prev, *next;
409 Scsi_Device *dqptr;
411 for (dqptr = shpnt->host_queue; dqptr != SDpnt; dqptr = dqptr->next)
412 continue;
413 if (dqptr) {
414 prev = dqptr->prev;
415 next = dqptr->next;
416 if (prev)
417 prev->next = next;
418 else
419 shpnt->host_queue = next;
420 if (next)
421 next->prev = prev;
425 scsi_release_commandblocks(SDpnt);
427 /* Last device block does not exist. Free memory. */
428 if (SDpnt != NULL)
429 kfree((char *) SDpnt);
431 /* If we allocated a buffer so we could do DMA, free it now */
432 if (scsi_result != &scsi_result0[0] && scsi_result != NULL) {
433 kfree(scsi_result);
435 Scsi_Device *sdev;
436 Scsi_Cmnd *scmd;
438 SCSI_LOG_SCAN_BUS(4, printk("Host status for host %p:\n", shpnt));
439 for (sdev = shpnt->host_queue; sdev; sdev = sdev->next) {
440 SCSI_LOG_SCAN_BUS(4, printk("Device %d %p: ", sdev->id, sdev));
441 for (scmd = sdev->device_queue; scmd; scmd = scmd->next) {
442 SCSI_LOG_SCAN_BUS(4, printk("%p ", scmd));
444 SCSI_LOG_SCAN_BUS(4, printk("\n"));
450 * The worker for scan_scsis.
451 * Returning 0 means Please don't ask further for lun!=0, 1 means OK go on.
452 * Global variables used : scsi_devices(linked list)
454 static int scan_scsis_single(int channel, int dev, int lun, int *max_dev_lun,
455 int *sparse_lun, Scsi_Device ** SDpnt2,
456 struct Scsi_Host *shpnt, char *scsi_result)
458 char devname[64];
459 unsigned char scsi_cmd[MAX_COMMAND_SIZE];
460 struct Scsi_Device_Template *sdtpnt;
461 Scsi_Device *SDtail, *SDpnt = *SDpnt2;
462 Scsi_Cmnd * SCpnt;
463 int bflags, type = -1;
464 static int ghost_channel=-1, ghost_dev=-1;
465 int org_lun = lun;
466 extern devfs_handle_t scsi_devfs_handle;
468 SDpnt->host = shpnt;
469 SDpnt->id = dev;
470 SDpnt->lun = lun;
471 SDpnt->channel = channel;
472 SDpnt->online = TRUE;
475 if ((channel == ghost_channel) && (dev == ghost_dev) && (lun == 1)) {
476 SDpnt->lun = 0;
477 } else {
478 ghost_channel = ghost_dev = -1;
482 /* Some low level driver could use device->type (DB) */
483 SDpnt->type = -1;
486 * Assume that the device will have handshaking problems, and then fix this
487 * field later if it turns out it doesn't
489 SDpnt->borken = 1;
490 SDpnt->was_reset = 0;
491 SDpnt->expecting_cc_ua = 0;
492 SDpnt->starved = 0;
494 scsi_cmd[0] = TEST_UNIT_READY;
495 scsi_cmd[1] = lun << 5;
496 scsi_cmd[2] = scsi_cmd[3] = scsi_cmd[4] = scsi_cmd[5] = 0;
498 SCpnt = scsi_allocate_device(SDpnt, 0, 0);
500 SCpnt->host = SDpnt->host;
501 SCpnt->device = SDpnt;
502 SCpnt->target = SDpnt->id;
503 SCpnt->lun = SDpnt->lun;
504 SCpnt->channel = SDpnt->channel;
505 SCpnt->sc_data_direction = SCSI_DATA_NONE;
507 scsi_wait_cmd (SCpnt, (void *) scsi_cmd,
508 (void *) NULL,
509 0, SCSI_TIMEOUT + 4 * HZ, 5);
511 SCSI_LOG_SCAN_BUS(3, printk("scsi: scan_scsis_single id %d lun %d. Return code 0x%08x\n",
512 dev, lun, SCpnt->result));
513 SCSI_LOG_SCAN_BUS(3, print_driverbyte(SCpnt->result));
514 SCSI_LOG_SCAN_BUS(3, print_hostbyte(SCpnt->result));
515 SCSI_LOG_SCAN_BUS(3, printk("\n"));
517 if (SCpnt->result) {
518 if (((driver_byte(SCpnt->result) & DRIVER_SENSE) ||
519 (status_byte(SCpnt->result) & CHECK_CONDITION)) &&
520 ((SCpnt->sense_buffer[0] & 0x70) >> 4) == 7) {
521 if (((SCpnt->sense_buffer[2] & 0xf) != NOT_READY) &&
522 ((SCpnt->sense_buffer[2] & 0xf) != UNIT_ATTENTION) &&
523 ((SCpnt->sense_buffer[2] & 0xf) != ILLEGAL_REQUEST || lun > 0)) {
524 scsi_release_command(SCpnt);
525 return 1;
527 } else {
528 scsi_release_command(SCpnt);
529 return 0;
532 SCSI_LOG_SCAN_BUS(3, printk("scsi: performing INQUIRY\n"));
534 * Build an INQUIRY command block.
536 scsi_cmd[0] = INQUIRY;
537 scsi_cmd[1] = (lun << 5) & 0xe0;
538 scsi_cmd[2] = 0;
539 scsi_cmd[3] = 0;
540 scsi_cmd[4] = 255;
541 scsi_cmd[5] = 0;
542 SCpnt->cmd_len = 0;
543 SCpnt->sc_data_direction = SCSI_DATA_READ;
545 scsi_wait_cmd (SCpnt, (void *) scsi_cmd,
546 (void *) scsi_result,
547 256, SCSI_TIMEOUT, 3);
549 SCSI_LOG_SCAN_BUS(3, printk("scsi: INQUIRY %s with code 0x%x\n",
550 SCpnt->result ? "failed" : "successful", SCpnt->result));
552 if (SCpnt->result) {
553 scsi_release_command(SCpnt);
554 return 0; /* assume no peripheral if any sort of error */
558 * Check the peripheral qualifier field - this tells us whether LUNS
559 * are supported here or not.
561 if ((scsi_result[0] >> 5) == 3) {
562 scsi_release_command(SCpnt);
563 return 0; /* assume no peripheral if any sort of error */
567 * Get any flags for this device.
569 bflags = get_device_flags (scsi_result);
572 /* The Toshiba ROM was "gender-changed" here as an inline hack.
573 This is now much more generic.
574 This is a mess: What we really want is to leave the scsi_result
575 alone, and just change the SDpnt structure. And the SDpnt is what
576 we want print_inquiry to print. -- REW
578 if (bflags & BLIST_ISDISK) {
579 scsi_result[0] = TYPE_DISK;
580 scsi_result[1] |= 0x80; /* removable */
583 if (bflags & BLIST_ISROM) {
584 scsi_result[0] = TYPE_ROM;
585 scsi_result[1] |= 0x80; /* removable */
588 if (bflags & BLIST_GHOST) {
589 if ((ghost_channel == channel) && (ghost_dev == dev) && (org_lun == 1)) {
590 lun=1;
591 } else {
592 ghost_channel = channel;
593 ghost_dev = dev;
594 scsi_result[0] = TYPE_MOD;
595 scsi_result[1] |= 0x80; /* removable */
600 memcpy(SDpnt->vendor, scsi_result + 8, 8);
601 memcpy(SDpnt->model, scsi_result + 16, 16);
602 memcpy(SDpnt->rev, scsi_result + 32, 4);
604 SDpnt->removable = (0x80 & scsi_result[1]) >> 7;
605 SDpnt->online = TRUE;
606 SDpnt->lockable = SDpnt->removable;
607 SDpnt->changed = 0;
608 SDpnt->access_count = 0;
609 SDpnt->busy = 0;
610 SDpnt->has_cmdblocks = 0;
612 * Currently, all sequential devices are assumed to be tapes, all random
613 * devices disk, with the appropriate read only flags set for ROM / WORM
614 * treated as RO.
616 switch (type = (scsi_result[0] & 0x1f)) {
617 case TYPE_TAPE:
618 case TYPE_DISK:
619 case TYPE_MOD:
620 case TYPE_PROCESSOR:
621 case TYPE_SCANNER:
622 case TYPE_MEDIUM_CHANGER:
623 case TYPE_ENCLOSURE:
624 SDpnt->writeable = 1;
625 break;
626 case TYPE_WORM:
627 case TYPE_ROM:
628 SDpnt->writeable = 0;
629 break;
630 default:
631 printk("scsi: unknown type %d\n", type);
634 SDpnt->device_blocked = FALSE;
635 SDpnt->device_busy = 0;
636 SDpnt->single_lun = 0;
637 SDpnt->soft_reset =
638 (scsi_result[7] & 1) && ((scsi_result[3] & 7) == 2);
639 SDpnt->random = (type == TYPE_TAPE) ? 0 : 1;
640 SDpnt->type = (type & 0x1f);
642 print_inquiry(scsi_result);
644 sprintf (devname, "host%d/bus%d/target%d/lun%d",
645 SDpnt->host->host_no, SDpnt->channel, SDpnt->id, SDpnt->lun);
646 if (SDpnt->de) printk ("DEBUG: dir: \"%s\" already exists\n", devname);
647 else SDpnt->de = devfs_mk_dir (scsi_devfs_handle, devname, 0, NULL);
649 for (sdtpnt = scsi_devicelist; sdtpnt;
650 sdtpnt = sdtpnt->next)
651 if (sdtpnt->detect)
652 SDpnt->attached +=
653 (*sdtpnt->detect) (SDpnt);
655 SDpnt->scsi_level = scsi_result[2] & 0x07;
656 if (SDpnt->scsi_level >= 2 ||
657 (SDpnt->scsi_level == 1 &&
658 (scsi_result[3] & 0x0f) == 1))
659 SDpnt->scsi_level++;
662 * Accommodate drivers that want to sleep when they should be in a polling
663 * loop.
665 SDpnt->disconnect = 0;
669 * Set the tagged_queue flag for SCSI-II devices that purport to support
670 * tagged queuing in the INQUIRY data.
672 SDpnt->tagged_queue = 0;
673 if ((SDpnt->scsi_level >= SCSI_2) &&
674 (scsi_result[7] & 2) &&
675 !(bflags & BLIST_NOTQ)) {
676 SDpnt->tagged_supported = 1;
677 SDpnt->current_tag = 0;
680 * Some revisions of the Texel CD ROM drives have handshaking problems when
681 * used with the Seagate controllers. Before we know what type of device
682 * we're talking to, we assume it's borken and then change it here if it
683 * turns out that it isn't a TEXEL drive.
685 if ((bflags & BLIST_BORKEN) == 0)
686 SDpnt->borken = 0;
689 * If we want to only allow I/O to one of the luns attached to this device
690 * at a time, then we set this flag.
692 if (bflags & BLIST_SINGLELUN)
693 SDpnt->single_lun = 1;
696 * These devices need this "key" to unlock the devices so we can use it
698 if ((bflags & BLIST_KEY) != 0) {
699 printk("Unlocked floptical drive.\n");
700 SDpnt->lockable = 0;
701 scsi_cmd[0] = MODE_SENSE;
702 scsi_cmd[1] = (lun << 5) & 0xe0;
703 scsi_cmd[2] = 0x2e;
704 scsi_cmd[3] = 0;
705 scsi_cmd[4] = 0x2a;
706 scsi_cmd[5] = 0;
707 SCpnt->cmd_len = 0;
708 SCpnt->sc_data_direction = SCSI_DATA_NONE;
709 scsi_wait_cmd (SCpnt, (void *) scsi_cmd,
710 (void *) scsi_result, 0x2a,
711 SCSI_TIMEOUT, 3);
714 scsi_release_command(SCpnt);
715 SCpnt = NULL;
717 scsi_release_commandblocks(SDpnt);
720 * This device was already hooked up to the host in question,
721 * so at this point we just let go of it and it should be fine. We do need to
722 * allocate a new one and attach it to the host so that we can further scan the bus.
724 SDpnt = (Scsi_Device *) kmalloc(sizeof(Scsi_Device), GFP_ATOMIC);
725 if (!SDpnt) {
726 printk("scsi: scan_scsis_single: Cannot malloc\n");
727 return 0;
729 memset(SDpnt, 0, sizeof(Scsi_Device));
731 *SDpnt2 = SDpnt;
732 SDpnt->queue_depth = 1;
733 SDpnt->host = shpnt;
734 SDpnt->online = TRUE;
736 scsi_build_commandblocks(SDpnt);
739 * Register the queue for the device. All I/O requests will come
740 * in through here. We also need to register a pointer to
741 * ourselves, since the queue handler won't know what device
742 * the queue actually represents. We could look it up, but it
743 * is pointless work.
745 scsi_initialize_queue(SDpnt, shpnt);
746 blk_queue_headactive(&SDpnt->request_queue, 0);
747 SDpnt->request_queue.queuedata = (void *) SDpnt;
748 SDpnt->host = shpnt;
749 initialize_merge_fn(SDpnt);
752 * Mark this device as online, or otherwise we won't be able to do much with it.
754 SDpnt->online = TRUE;
757 * Initialize the object that we will use to wait for command blocks.
759 init_waitqueue_head(&SDpnt->scpnt_wait);
762 * Since we just found one device, there had damn well better be one in the list
763 * already.
765 if (shpnt->host_queue == NULL)
766 panic("scan_scsis_single: Host queue == NULL\n");
768 SDtail = shpnt->host_queue;
769 while (SDtail->next) {
770 SDtail = SDtail->next;
773 /* Add this device to the linked list at the end */
774 SDtail->next = SDpnt;
775 SDpnt->prev = SDtail;
776 SDpnt->next = NULL;
779 * Some scsi devices cannot be polled for lun != 0 due to firmware bugs
781 if (bflags & BLIST_NOLUN)
782 return 0; /* break; */
785 * If this device is known to support sparse multiple units, override the
786 * other settings, and scan all of them.
788 if (bflags & BLIST_SPARSELUN) {
789 *max_dev_lun = 8;
790 *sparse_lun = 1;
791 return 1;
794 * If this device is known to support multiple units, override the other
795 * settings, and scan all of them.
797 if (bflags & BLIST_FORCELUN) {
798 *max_dev_lun = 8;
799 return 1;
802 * REGAL CDC-4X: avoid hang after LUN 4
804 if (bflags & BLIST_MAX5LUN) {
805 *max_dev_lun = 5;
806 return 1;
810 * If this device is Ghosted, scan upto two luns. (It physically only
811 * has one). -- REW
813 if (bflags & BLIST_GHOST) {
814 *max_dev_lun = 2;
815 return 1;
820 * We assume the device can't handle lun!=0 if: - it reports scsi-0 (ANSI
821 * SCSI Revision 0) (old drives like MAXTOR XT-3280) or - it reports scsi-1
822 * (ANSI SCSI Revision 1) and Response Data Format 0
824 if (((scsi_result[2] & 0x07) == 0)
826 ((scsi_result[2] & 0x07) == 1 &&
827 (scsi_result[3] & 0x0f) == 0))
828 return 0;
829 return 1;