- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / drivers / scsi / scsi_scan.c
blob04ea9fbf13c6e64b54cf454bb976d70fde386151
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
42 static void print_inquiry(unsigned char *data);
43 static int scan_scsis_single(int channel, int dev, int lun, int *max_scsi_dev,
44 int *sparse_lun, Scsi_Device ** SDpnt,
45 struct Scsi_Host *shpnt, char *scsi_result);
47 struct dev_info {
48 const char *vendor;
49 const char *model;
50 const char *revision; /* Latest revision known to be bad. Not used yet */
51 unsigned flags;
55 * This is what was previously known as the blacklist. The concept
56 * has been expanded so that we can specify other types of things we
57 * need to be aware of.
59 static struct dev_info device_list[] =
61 {"Aashima", "IMAGERY 2400SP", "1.03", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
62 {"CHINON", "CD-ROM CDS-431", "H42", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
63 {"CHINON", "CD-ROM CDS-535", "Q14", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
64 {"DENON", "DRD-25X", "V", BLIST_NOLUN}, /* Locks up if probed for lun != 0 */
65 {"HITACHI", "DK312C", "CM81", BLIST_NOLUN}, /* Responds to all lun - dtg */
66 {"HITACHI", "DK314C", "CR21", BLIST_NOLUN}, /* responds to all lun */
67 {"IMS", "CDD521/10", "2.06", BLIST_NOLUN}, /* Locks-up when LUN>0 polled. */
68 {"MAXTOR", "XT-3280", "PR02", BLIST_NOLUN}, /* Locks-up when LUN>0 polled. */
69 {"MAXTOR", "XT-4380S", "B3C", BLIST_NOLUN}, /* Locks-up when LUN>0 polled. */
70 {"MAXTOR", "MXT-1240S", "I1.2", BLIST_NOLUN}, /* Locks up when LUN>0 polled */
71 {"MAXTOR", "XT-4170S", "B5A", BLIST_NOLUN}, /* Locks-up sometimes when LUN>0 polled. */
72 {"MAXTOR", "XT-8760S", "B7B", BLIST_NOLUN}, /* guess what? */
73 {"MEDIAVIS", "RENO CD-ROMX2A", "2.03", BLIST_NOLUN}, /*Responds to all lun */
74 {"MICROP", "4110", "*", BLIST_NOTQ}, /* Buggy Tagged Queuing */
75 {"NEC", "CD-ROM DRIVE:841", "1.0", BLIST_NOLUN}, /* Locks-up when LUN>0 polled. */
76 {"PHILIPS", "PCA80SC", "V4-2", BLIST_NOLUN}, /* Responds to all lun */
77 {"RODIME", "RO3000S", "2.33", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
78 {"SANYO", "CRD-250S", "1.20", BLIST_NOLUN}, /* causes failed REQUEST SENSE on lun 1
79 * for aha152x controller, which causes
80 * SCSI code to reset bus.*/
81 {"SEAGATE", "ST157N", "\004|j", BLIST_NOLUN}, /* causes failed REQUEST SENSE on lun 1
82 * for aha152x controller, which causes
83 * SCSI code to reset bus.*/
84 {"SEAGATE", "ST296", "921", BLIST_NOLUN}, /* Responds to all lun */
85 {"SEAGATE", "ST1581", "6538", BLIST_NOLUN}, /* Responds to all lun */
86 {"SONY", "CD-ROM CDU-541", "4.3d", BLIST_NOLUN},
87 {"SONY", "CD-ROM CDU-55S", "1.0i", BLIST_NOLUN},
88 {"SONY", "CD-ROM CDU-561", "1.7x", BLIST_NOLUN},
89 {"SONY", "CD-ROM CDU-8012", "*", BLIST_NOLUN},
90 {"TANDBERG", "TDC 3600", "U07", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
91 {"TEAC", "CD-R55S", "1.0H", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
92 {"TEAC", "CD-ROM", "1.06", BLIST_NOLUN}, /* causes failed REQUEST SENSE on lun 1
93 * for seagate controller, which causes
94 * SCSI code to reset bus.*/
95 {"TEAC", "MT-2ST/45S2-27", "RV M", BLIST_NOLUN}, /* Responds to all lun */
96 {"TEXEL", "CD-ROM", "1.06", BLIST_NOLUN}, /* causes failed REQUEST SENSE on lun 1
97 * for seagate controller, which causes
98 * SCSI code to reset bus.*/
99 {"QUANTUM", "LPS525S", "3110", BLIST_NOLUN}, /* Locks sometimes if polled for lun != 0 */
100 {"QUANTUM", "PD1225S", "3110", BLIST_NOLUN}, /* Locks sometimes if polled for lun != 0 */
101 {"QUANTUM", "FIREBALL ST4.3S", "0F0C", BLIST_NOLUN}, /* Locks up when polled for lun != 0 */
102 {"MEDIAVIS", "CDR-H93MV", "1.31", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
103 {"SANKYO", "CP525", "6.64", BLIST_NOLUN}, /* causes failed REQ SENSE, extra reset */
104 {"HP", "C1750A", "3226", BLIST_NOLUN}, /* scanjet iic */
105 {"HP", "C1790A", "", BLIST_NOLUN}, /* scanjet iip */
106 {"HP", "C2500A", "", BLIST_NOLUN}, /* scanjet iicx */
107 {"YAMAHA", "CDR100", "1.00", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
108 {"YAMAHA", "CDR102", "1.00", BLIST_NOLUN}, /* Locks up if polled for lun != 0
109 * extra reset */
110 {"YAMAHA", "CRW8424S", "1.0", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
111 {"YAMAHA", "CRW6416S", "1.0c", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
112 {"MITSUMI", "CD-R CR-2201CS", "6119", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
113 {"RELISYS", "Scorpio", "*", BLIST_NOLUN}, /* responds to all LUN */
114 {"MICROTEK", "ScanMaker II", "5.61", BLIST_NOLUN}, /* responds to all LUN */
117 * Other types of devices that have special flags.
119 {"SONY", "CD-ROM CDU-8001", "*", BLIST_BORKEN},
120 {"TEXEL", "CD-ROM", "1.06", BLIST_BORKEN},
121 {"IOMEGA", "Io20S *F", "*", BLIST_KEY},
122 {"INSITE", "Floptical F*8I", "*", BLIST_KEY},
123 {"INSITE", "I325VM", "*", BLIST_KEY},
124 {"LASOUND","CDX7405","3.10", BLIST_MAX5LUN | BLIST_SINGLELUN},
125 {"NRC", "MBR-7", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
126 {"NRC", "MBR-7.4", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
127 {"REGAL", "CDC-4X", "*", BLIST_MAX5LUN | BLIST_SINGLELUN},
128 {"NAKAMICH", "MJ-4.8S", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
129 {"NAKAMICH", "MJ-5.16S", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
130 {"PIONEER", "CD-ROM DRM-600", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
131 {"PIONEER", "CD-ROM DRM-602X", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
132 {"PIONEER", "CD-ROM DRM-604X", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
133 {"EMULEX", "MD21/S2 ESDI", "*", BLIST_SINGLELUN},
134 {"CANON", "IPUBJD", "*", BLIST_SPARSELUN},
135 {"nCipher", "Fastness Crypto", "*", BLIST_FORCELUN},
136 {"DEC","HSG80","*", BLIST_FORCELUN},
137 {"COMPAQ","LOGICAL VOLUME","*", BLIST_FORCELUN},
138 {"NEC", "PD-1 ODX654P", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
139 {"MATSHITA", "PD-1", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
140 {"iomega", "jaz 1GB", "J.86", BLIST_NOTQ | BLIST_NOLUN},
141 {"TOSHIBA","CDROM","*", BLIST_ISROM},
142 {"MegaRAID", "LD", "*", BLIST_FORCELUN},
143 {"DGC", "RAID", "*", BLIST_SPARSELUN}, // Dell PV 650F (tgt @ LUN 0)
144 {"DGC", "DISK", "*", BLIST_SPARSELUN}, // Dell PV 650F (no tgt @ LUN 0)
145 {"DELL", "PV530F", "*", BLIST_SPARSELUN}, // Dell PV 530F
146 {"SONY", "TSL", "*", BLIST_FORCELUN}, // DDS3 & DDS4 autoloaders
147 {"DELL", "PERCRAID", "*", BLIST_FORCELUN},
148 {"HP", "NetRAID-4M", "*", BLIST_FORCELUN},
151 * Must be at end of list...
153 {NULL, NULL, NULL}
156 #ifdef CONFIG_SCSI_MULTI_LUN
157 static int max_scsi_luns = 8;
158 #else
159 static int max_scsi_luns = 1;
160 #endif
162 #ifdef MODULE
164 MODULE_PARM(max_scsi_luns, "i");
165 MODULE_PARM_DESC(max_scsi_luns, "last scsi LUN (should be between 1 and 8)");
167 #else
169 static int __init scsi_luns_setup(char *str)
171 int tmp;
173 if (get_option(&str, &tmp) == 1) {
174 max_scsi_luns = tmp;
175 return 1;
176 } else {
177 printk("scsi_luns_setup : usage max_scsi_luns=n "
178 "(n should be between 1 and 8)\n");
179 return 0;
183 __setup("max_scsi_luns=", scsi_luns_setup);
185 #endif
187 static void print_inquiry(unsigned char *data)
189 int i;
191 printk(" Vendor: ");
192 for (i = 8; i < 16; i++) {
193 if (data[i] >= 0x20 && i < data[4] + 5)
194 printk("%c", data[i]);
195 else
196 printk(" ");
199 printk(" Model: ");
200 for (i = 16; i < 32; i++) {
201 if (data[i] >= 0x20 && i < data[4] + 5)
202 printk("%c", data[i]);
203 else
204 printk(" ");
207 printk(" Rev: ");
208 for (i = 32; i < 36; i++) {
209 if (data[i] >= 0x20 && i < data[4] + 5)
210 printk("%c", data[i]);
211 else
212 printk(" ");
215 printk("\n");
217 i = data[0] & 0x1f;
219 printk(" Type: %s ",
220 i < MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] : "Unknown ");
221 printk(" ANSI SCSI revision: %02x", data[2] & 0x07);
222 if ((data[2] & 0x07) == 1 && (data[3] & 0x0f) == 1)
223 printk(" CCS\n");
224 else
225 printk("\n");
228 static int get_device_flags(unsigned char *response_data)
230 int i = 0;
231 unsigned char *pnt;
232 for (i = 0; 1; i++) {
233 if (device_list[i].vendor == NULL)
234 return 0;
235 pnt = &response_data[8];
236 while (*pnt && *pnt == ' ')
237 pnt++;
238 if (memcmp(device_list[i].vendor, pnt,
239 strlen(device_list[i].vendor)))
240 continue;
241 pnt = &response_data[16];
242 while (*pnt && *pnt == ' ')
243 pnt++;
244 if (memcmp(device_list[i].model, pnt,
245 strlen(device_list[i].model)))
246 continue;
247 return device_list[i].flags;
249 return 0;
253 * Detecting SCSI devices :
254 * We scan all present host adapter's busses, from ID 0 to ID (max_id).
255 * We use the INQUIRY command, determine device type, and pass the ID /
256 * lun address of all sequential devices to the tape driver, all random
257 * devices to the disk driver.
259 void scan_scsis(struct Scsi_Host *shpnt,
260 uint hardcoded,
261 uint hchannel,
262 uint hid,
263 uint hlun)
265 uint channel;
266 int dev;
267 int lun;
268 int max_dev_lun;
269 unsigned char *scsi_result;
270 unsigned char scsi_result0[256];
271 Scsi_Device *SDpnt;
272 Scsi_Device *SDtail;
273 int sparse_lun;
275 scsi_result = NULL;
277 SDpnt = (Scsi_Device *) kmalloc(sizeof(Scsi_Device),
278 GFP_ATOMIC);
279 if (SDpnt) {
280 memset(SDpnt, 0, sizeof(Scsi_Device));
282 * Register the queue for the device. All I/O requests will
283 * come in through here. We also need to register a pointer to
284 * ourselves, since the queue handler won't know what device
285 * the queue actually represents. We could look it up, but it
286 * is pointless work.
288 scsi_initialize_queue(SDpnt, shpnt);
289 SDpnt->request_queue.queuedata = (void *) SDpnt;
290 /* Make sure we have something that is valid for DMA purposes */
291 scsi_result = ((!shpnt->unchecked_isa_dma)
292 ? &scsi_result0[0] : kmalloc(512, GFP_DMA));
295 if (scsi_result == NULL) {
296 printk("Unable to obtain scsi_result buffer\n");
297 goto leave;
300 * We must chain ourself in the host_queue, so commands can time out
302 SDpnt->queue_depth = 1;
303 SDpnt->host = shpnt;
304 SDpnt->online = TRUE;
306 initialize_merge_fn(SDpnt);
309 * Initialize the object that we will use to wait for command blocks.
311 init_waitqueue_head(&SDpnt->scpnt_wait);
314 * Next, hook the device to the host in question.
316 SDpnt->prev = NULL;
317 SDpnt->next = NULL;
318 if (shpnt->host_queue != NULL) {
319 SDtail = shpnt->host_queue;
320 while (SDtail->next != NULL)
321 SDtail = SDtail->next;
323 SDtail->next = SDpnt;
324 SDpnt->prev = SDtail;
325 } else {
326 shpnt->host_queue = SDpnt;
330 * We need to increment the counter for this one device so we can track when
331 * things are quiet.
333 if (hardcoded == 1) {
334 Scsi_Device *oldSDpnt = SDpnt;
335 struct Scsi_Device_Template *sdtpnt;
336 channel = hchannel;
337 if (channel > shpnt->max_channel)
338 goto leave;
339 dev = hid;
340 if (dev >= shpnt->max_id)
341 goto leave;
342 lun = hlun;
343 if (lun >= shpnt->max_lun)
344 goto leave;
345 scan_scsis_single(channel, dev, lun, &max_dev_lun, &sparse_lun,
346 &SDpnt, shpnt, scsi_result);
347 if (SDpnt != oldSDpnt) {
349 /* it could happen the blockdevice hasn't yet been inited */
350 /* queue_depth() moved from scsi_proc_info() so that
351 it is called before scsi_build_commandblocks() */
352 if (shpnt->select_queue_depths != NULL)
353 (shpnt->select_queue_depths)(shpnt,
354 shpnt->host_queue);
356 for (sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
357 if (sdtpnt->init && sdtpnt->dev_noticed)
358 (*sdtpnt->init) ();
360 for (sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next) {
361 if (sdtpnt->attach) {
362 (*sdtpnt->attach) (oldSDpnt);
363 if (oldSDpnt->attached) {
364 scsi_build_commandblocks(oldSDpnt);
365 if (0 == oldSDpnt->has_cmdblocks) {
366 printk("scan_scsis: DANGER, no command blocks\n");
367 /* What to do now ?? */
372 scsi_resize_dma_pool();
374 for (sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next) {
375 if (sdtpnt->finish && sdtpnt->nr_dev) {
376 (*sdtpnt->finish) ();
380 } else {
381 /* Actual LUN. PC ordering is 0->n IBM/spec ordering is n->0 */
382 int order_dev;
384 for (channel = 0; channel <= shpnt->max_channel; channel++) {
385 for (dev = 0; dev < shpnt->max_id; ++dev) {
386 if (shpnt->reverse_ordering)
387 /* Shift to scanning 15,14,13... or 7,6,5,4, */
388 order_dev = shpnt->max_id - dev - 1;
389 else
390 order_dev = dev;
392 if (shpnt->this_id != order_dev) {
395 * We need the for so our continue, etc. work fine. We put this in
396 * a variable so that we can override it during the scan if we
397 * detect a device *KNOWN* to have multiple logical units.
399 max_dev_lun = (max_scsi_luns < shpnt->max_lun ?
400 max_scsi_luns : shpnt->max_lun);
401 sparse_lun = 0;
402 for (lun = 0; lun < max_dev_lun; ++lun) {
403 if (!scan_scsis_single(channel, order_dev, lun, &max_dev_lun,
404 &sparse_lun, &SDpnt, shpnt,
405 scsi_result)
406 && !sparse_lun)
407 break; /* break means don't probe further for luns!=0 */
408 } /* for lun ends */
409 } /* if this_id != id ends */
410 } /* for dev ends */
411 } /* for channel ends */
412 } /* if/else hardcoded */
414 leave:
416 { /* Unchain SRpnt from host_queue */
417 Scsi_Device *prev, *next;
418 Scsi_Device *dqptr;
420 for (dqptr = shpnt->host_queue; dqptr != SDpnt; dqptr = dqptr->next)
421 continue;
422 if (dqptr) {
423 prev = dqptr->prev;
424 next = dqptr->next;
425 if (prev)
426 prev->next = next;
427 else
428 shpnt->host_queue = next;
429 if (next)
430 next->prev = prev;
434 /* Last device block does not exist. Free memory. */
435 if (SDpnt != NULL) {
436 blk_cleanup_queue(&SDpnt->request_queue);
437 kfree((char *) SDpnt);
440 /* If we allocated a buffer so we could do DMA, free it now */
441 if (scsi_result != &scsi_result0[0] && scsi_result != NULL) {
442 kfree(scsi_result);
444 Scsi_Device *sdev;
445 Scsi_Cmnd *scmd;
447 SCSI_LOG_SCAN_BUS(4, printk("Host status for host %p:\n", shpnt));
448 for (sdev = shpnt->host_queue; sdev; sdev = sdev->next) {
449 SCSI_LOG_SCAN_BUS(4, printk("Device %d %p: ", sdev->id, sdev));
450 for (scmd = sdev->device_queue; scmd; scmd = scmd->next) {
451 SCSI_LOG_SCAN_BUS(4, printk("%p ", scmd));
453 SCSI_LOG_SCAN_BUS(4, printk("\n"));
459 * The worker for scan_scsis.
460 * Returning 0 means Please don't ask further for lun!=0, 1 means OK go on.
461 * Global variables used : scsi_devices(linked list)
463 static int scan_scsis_single(int channel, int dev, int lun, int *max_dev_lun,
464 int *sparse_lun, Scsi_Device ** SDpnt2,
465 struct Scsi_Host *shpnt, char *scsi_result)
467 char devname[64];
468 unsigned char scsi_cmd[MAX_COMMAND_SIZE];
469 struct Scsi_Device_Template *sdtpnt;
470 Scsi_Device *SDtail, *SDpnt = *SDpnt2;
471 Scsi_Request * SRpnt;
472 int bflags, type = -1;
473 extern devfs_handle_t scsi_devfs_handle;
475 SDpnt->host = shpnt;
476 SDpnt->id = dev;
477 SDpnt->lun = lun;
478 SDpnt->channel = channel;
479 SDpnt->online = TRUE;
481 scsi_build_commandblocks(SDpnt);
483 /* Some low level driver could use device->type (DB) */
484 SDpnt->type = -1;
487 * Assume that the device will have handshaking problems, and then fix this
488 * field later if it turns out it doesn't
490 SDpnt->borken = 1;
491 SDpnt->was_reset = 0;
492 SDpnt->expecting_cc_ua = 0;
493 SDpnt->starved = 0;
495 SRpnt = scsi_allocate_request(SDpnt);
498 * We used to do a TEST_UNIT_READY before the INQUIRY but that was
499 * not really necessary. Spec recommends using INQUIRY to scan for
500 * devices (and TEST_UNIT_READY to poll for media change). - Paul G.
503 SCSI_LOG_SCAN_BUS(3, printk("scsi: performing INQUIRY\n"));
505 * Build an INQUIRY command block.
507 scsi_cmd[0] = INQUIRY;
508 scsi_cmd[1] = (lun << 5) & 0xe0;
509 scsi_cmd[2] = 0;
510 scsi_cmd[3] = 0;
511 scsi_cmd[4] = 255;
512 scsi_cmd[5] = 0;
513 SRpnt->sr_cmd_len = 0;
514 SRpnt->sr_data_direction = SCSI_DATA_READ;
516 scsi_wait_req (SRpnt, (void *) scsi_cmd,
517 (void *) scsi_result,
518 256, SCSI_TIMEOUT+4*HZ, 3);
520 SCSI_LOG_SCAN_BUS(3, printk("scsi: INQUIRY %s with code 0x%x\n",
521 SRpnt->sr_result ? "failed" : "successful", SRpnt->sr_result));
523 if (SRpnt->sr_result) {
524 scsi_release_request(SRpnt);
525 return 0; /* assume no peripheral if any sort of error */
529 * Check the peripheral qualifier field - this tells us whether LUNS
530 * are supported here or not.
532 if ((scsi_result[0] >> 5) == 3) {
533 scsi_release_request(SRpnt);
534 return 0; /* assume no peripheral if any sort of error */
538 * Get any flags for this device.
540 bflags = get_device_flags (scsi_result);
543 /* The Toshiba ROM was "gender-changed" here as an inline hack.
544 This is now much more generic.
545 This is a mess: What we really want is to leave the scsi_result
546 alone, and just change the SDpnt structure. And the SDpnt is what
547 we want print_inquiry to print. -- REW
549 if (bflags & BLIST_ISDISK) {
550 scsi_result[0] = TYPE_DISK;
551 scsi_result[1] |= 0x80; /* removable */
554 if (bflags & BLIST_ISROM) {
555 scsi_result[0] = TYPE_ROM;
556 scsi_result[1] |= 0x80; /* removable */
559 memcpy(SDpnt->vendor, scsi_result + 8, 8);
560 memcpy(SDpnt->model, scsi_result + 16, 16);
561 memcpy(SDpnt->rev, scsi_result + 32, 4);
563 SDpnt->removable = (0x80 & scsi_result[1]) >> 7;
564 /* Use the peripheral qualifier field to determine online/offline */
565 if (((scsi_result[0] >> 5) & 7) == 1) SDpnt->online = FALSE;
566 else SDpnt->online = TRUE;
567 SDpnt->lockable = SDpnt->removable;
568 SDpnt->changed = 0;
569 SDpnt->access_count = 0;
570 SDpnt->busy = 0;
571 SDpnt->has_cmdblocks = 0;
573 * Currently, all sequential devices are assumed to be tapes, all random
574 * devices disk, with the appropriate read only flags set for ROM / WORM
575 * treated as RO.
577 switch (type = (scsi_result[0] & 0x1f)) {
578 case TYPE_TAPE:
579 case TYPE_DISK:
580 case TYPE_MOD:
581 case TYPE_PROCESSOR:
582 case TYPE_SCANNER:
583 case TYPE_MEDIUM_CHANGER:
584 case TYPE_ENCLOSURE:
585 case TYPE_COMM:
586 SDpnt->writeable = 1;
587 break;
588 case TYPE_WORM:
589 case TYPE_ROM:
590 SDpnt->writeable = 0;
591 break;
592 default:
593 printk("scsi: unknown type %d\n", type);
596 SDpnt->device_blocked = FALSE;
597 SDpnt->device_busy = 0;
598 SDpnt->single_lun = 0;
599 SDpnt->soft_reset =
600 (scsi_result[7] & 1) && ((scsi_result[3] & 7) == 2);
601 SDpnt->random = (type == TYPE_TAPE) ? 0 : 1;
602 SDpnt->type = (type & 0x1f);
604 print_inquiry(scsi_result);
606 sprintf (devname, "host%d/bus%d/target%d/lun%d",
607 SDpnt->host->host_no, SDpnt->channel, SDpnt->id, SDpnt->lun);
608 if (SDpnt->de) printk ("DEBUG: dir: \"%s\" already exists\n", devname);
609 else SDpnt->de = devfs_mk_dir (scsi_devfs_handle, devname, NULL);
611 for (sdtpnt = scsi_devicelist; sdtpnt;
612 sdtpnt = sdtpnt->next)
613 if (sdtpnt->detect)
614 SDpnt->attached +=
615 (*sdtpnt->detect) (SDpnt);
617 SDpnt->scsi_level = scsi_result[2] & 0x07;
618 if (SDpnt->scsi_level >= 2 ||
619 (SDpnt->scsi_level == 1 &&
620 (scsi_result[3] & 0x0f) == 1))
621 SDpnt->scsi_level++;
624 * Accommodate drivers that want to sleep when they should be in a polling
625 * loop.
627 SDpnt->disconnect = 0;
631 * Set the tagged_queue flag for SCSI-II devices that purport to support
632 * tagged queuing in the INQUIRY data.
634 SDpnt->tagged_queue = 0;
635 if ((SDpnt->scsi_level >= SCSI_2) &&
636 (scsi_result[7] & 2) &&
637 !(bflags & BLIST_NOTQ)) {
638 SDpnt->tagged_supported = 1;
639 SDpnt->current_tag = 0;
642 * Some revisions of the Texel CD ROM drives have handshaking problems when
643 * used with the Seagate controllers. Before we know what type of device
644 * we're talking to, we assume it's borken and then change it here if it
645 * turns out that it isn't a TEXEL drive.
647 if ((bflags & BLIST_BORKEN) == 0)
648 SDpnt->borken = 0;
651 * If we want to only allow I/O to one of the luns attached to this device
652 * at a time, then we set this flag.
654 if (bflags & BLIST_SINGLELUN)
655 SDpnt->single_lun = 1;
658 * These devices need this "key" to unlock the devices so we can use it
660 if ((bflags & BLIST_KEY) != 0) {
661 printk("Unlocked floptical drive.\n");
662 SDpnt->lockable = 0;
663 scsi_cmd[0] = MODE_SENSE;
664 scsi_cmd[1] = (lun << 5) & 0xe0;
665 scsi_cmd[2] = 0x2e;
666 scsi_cmd[3] = 0;
667 scsi_cmd[4] = 0x2a;
668 scsi_cmd[5] = 0;
669 SRpnt->sr_cmd_len = 0;
670 SRpnt->sr_data_direction = SCSI_DATA_READ;
671 scsi_wait_req (SRpnt, (void *) scsi_cmd,
672 (void *) scsi_result, 0x2a,
673 SCSI_TIMEOUT, 3);
676 scsi_release_request(SRpnt);
677 SRpnt = NULL;
679 scsi_release_commandblocks(SDpnt);
682 * This device was already hooked up to the host in question,
683 * so at this point we just let go of it and it should be fine. We do need to
684 * allocate a new one and attach it to the host so that we can further scan the bus.
686 SDpnt = (Scsi_Device *) kmalloc(sizeof(Scsi_Device), GFP_ATOMIC);
687 if (!SDpnt) {
688 printk("scsi: scan_scsis_single: Cannot malloc\n");
689 return 0;
691 memset(SDpnt, 0, sizeof(Scsi_Device));
693 *SDpnt2 = SDpnt;
694 SDpnt->queue_depth = 1;
695 SDpnt->host = shpnt;
696 SDpnt->online = TRUE;
699 * Register the queue for the device. All I/O requests will come
700 * in through here. We also need to register a pointer to
701 * ourselves, since the queue handler won't know what device
702 * the queue actually represents. We could look it up, but it
703 * is pointless work.
705 scsi_initialize_queue(SDpnt, shpnt);
706 SDpnt->host = shpnt;
707 initialize_merge_fn(SDpnt);
710 * Mark this device as online, or otherwise we won't be able to do much with it.
712 SDpnt->online = TRUE;
715 * Initialize the object that we will use to wait for command blocks.
717 init_waitqueue_head(&SDpnt->scpnt_wait);
720 * Since we just found one device, there had damn well better be one in the list
721 * already.
723 if (shpnt->host_queue == NULL)
724 panic("scan_scsis_single: Host queue == NULL\n");
726 SDtail = shpnt->host_queue;
727 while (SDtail->next) {
728 SDtail = SDtail->next;
731 /* Add this device to the linked list at the end */
732 SDtail->next = SDpnt;
733 SDpnt->prev = SDtail;
734 SDpnt->next = NULL;
737 * Some scsi devices cannot be polled for lun != 0 due to firmware bugs
739 if (bflags & BLIST_NOLUN)
740 return 0; /* break; */
743 * If this device is known to support sparse multiple units, override the
744 * other settings, and scan all of them.
746 if (bflags & BLIST_SPARSELUN) {
747 *max_dev_lun = 8;
748 *sparse_lun = 1;
749 return 1;
752 * If this device is known to support multiple units, override the other
753 * settings, and scan all of them.
755 if (bflags & BLIST_FORCELUN) {
756 *max_dev_lun = 8;
757 return 1;
760 * REGAL CDC-4X: avoid hang after LUN 4
762 if (bflags & BLIST_MAX5LUN) {
763 *max_dev_lun = 5;
764 return 1;
768 * We assume the device can't handle lun!=0 if: - it reports scsi-0
769 * (ANSI SCSI Revision 0) (old drives like MAXTOR XT-3280) or - it
770 * reports scsi-1 (ANSI SCSI Revision 1) and Response Data Format 0
772 if (((scsi_result[2] & 0x07) == 0)
774 ((scsi_result[2] & 0x07) == 1 &&
775 (scsi_result[3] & 0x0f) == 0))
776 return 0;
777 return 1;