1
2
3
4
5
6
7
8
9
10
11#define __NO_VERSION__
12#include <linux/config.h>
13#include <linux/module.h>
14#include <linux/init.h>
15
16#include <linux/blk.h>
17
18#include "scsi.h"
19#include "hosts.h"
20#include "constants.h"
21
22#ifdef CONFIG_KMOD
23#include <linux/kmod.h>
24#endif
25
26
27
28
29#define BLIST_NOLUN 0x001
30#define BLIST_FORCELUN 0x002
31#define BLIST_BORKEN 0x004
32#define BLIST_KEY 0x008
33#define BLIST_SINGLELUN 0x010
34#define BLIST_NOTQ 0x020
35#define BLIST_SPARSELUN 0x040
36#define BLIST_MAX5LUN 0x080
37#define BLIST_ISDISK 0x100
38#define BLIST_ISROM 0x200
39#define BLIST_LARGELUN 0x400
40#define BLIST_NOSTARTONADD 0x1000
41
42
43static void print_inquiry(unsigned char *data);
44static int scan_scsis_single(unsigned int channel, unsigned int dev,
45 unsigned int lun, int lun0_scsi_level,
46 unsigned int *max_scsi_dev, unsigned int *sparse_lun,
47 Scsi_Device ** SDpnt, struct Scsi_Host *shpnt,
48 char *scsi_result);
49static int find_lun0_scsi_level(unsigned int channel, unsigned int dev,
50 struct Scsi_Host *shpnt);
51
52struct dev_info {
53 const char *vendor;
54 const char *model;
55 const char *revision;
56 unsigned flags;
57};
58
59
60
61
62
63
64static struct dev_info device_list[] =
65{
66
67
68
69
70 {"Aashima", "IMAGERY 2400SP", "1.03", BLIST_NOLUN},
71 {"CHINON", "CD-ROM CDS-431", "H42", BLIST_NOLUN},
72 {"CHINON", "CD-ROM CDS-535", "Q14", BLIST_NOLUN},
73 {"DENON", "DRD-25X", "V", BLIST_NOLUN},
74 {"HITACHI", "DK312C", "CM81", BLIST_NOLUN},
75 {"HITACHI", "DK314C", "CR21", BLIST_NOLUN},
76 {"IMS", "CDD521/10", "2.06", BLIST_NOLUN},
77 {"MAXTOR", "XT-3280", "PR02", BLIST_NOLUN},
78 {"MAXTOR", "XT-4380S", "B3C", BLIST_NOLUN},
79 {"MAXTOR", "MXT-1240S", "I1.2", BLIST_NOLUN},
80 {"MAXTOR", "XT-4170S", "B5A", BLIST_NOLUN},
81 {"MAXTOR", "XT-8760S", "B7B", BLIST_NOLUN},
82 {"MEDIAVIS", "RENO CD-ROMX2A", "2.03", BLIST_NOLUN},
83 {"NEC", "CD-ROM DRIVE:841", "1.0", BLIST_NOLUN},
84 {"PHILIPS", "PCA80SC", "V4-2", BLIST_NOLUN},
85 {"RODIME", "RO3000S", "2.33", BLIST_NOLUN},
86 {"SANYO", "CRD-250S", "1.20", BLIST_NOLUN},
87
88
89 {"SEAGATE", "ST157N", "\004|j", BLIST_NOLUN},
90
91
92 {"SEAGATE", "ST296", "921", BLIST_NOLUN},
93 {"SEAGATE", "ST1581", "6538", BLIST_NOLUN},
94 {"SONY", "CD-ROM CDU-541", "4.3d", BLIST_NOLUN},
95 {"SONY", "CD-ROM CDU-55S", "1.0i", BLIST_NOLUN},
96 {"SONY", "CD-ROM CDU-561", "1.7x", BLIST_NOLUN},
97 {"SONY", "CD-ROM CDU-8012", "*", BLIST_NOLUN},
98 {"TANDBERG", "TDC 3600", "U07", BLIST_NOLUN},
99 {"TEAC", "CD-R55S", "1.0H", BLIST_NOLUN},
100 {"TEAC", "CD-ROM", "1.06", BLIST_NOLUN},
101
102
103 {"TEAC", "MT-2ST/45S2-27", "RV M", BLIST_NOLUN},
104 {"TEXEL", "CD-ROM", "1.06", BLIST_NOLUN},
105
106
107 {"QUANTUM", "LPS525S", "3110", BLIST_NOLUN},
108 {"QUANTUM", "PD1225S", "3110", BLIST_NOLUN},
109 {"QUANTUM", "FIREBALL ST4.3S", "0F0C", BLIST_NOLUN},
110 {"MEDIAVIS", "CDR-H93MV", "1.31", BLIST_NOLUN},
111 {"SANKYO", "CP525", "6.64", BLIST_NOLUN},
112 {"HP", "C1750A", "3226", BLIST_NOLUN},
113 {"HP", "C1790A", "", BLIST_NOLUN},
114 {"HP", "C2500A", "", BLIST_NOLUN},
115 {"HP", "A6188A", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
116 {"HP", "A6189A", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
117 {"HP", "A6189B", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
118 {"HP", "A6218A", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
119 {"YAMAHA", "CDR100", "1.00", BLIST_NOLUN},
120 {"YAMAHA", "CDR102", "1.00", BLIST_NOLUN},
121
122 {"YAMAHA", "CRW8424S", "1.0", BLIST_NOLUN},
123 {"YAMAHA", "CRW6416S", "1.0c", BLIST_NOLUN},
124 {"MITSUMI", "CD-R CR-2201CS", "6119", BLIST_NOLUN},
125 {"RELISYS", "Scorpio", "*", BLIST_NOLUN},
126 {"RELISYS", "VM3530+", "*", BLIST_NOLUN},
127 {"ACROSS", "", "*", BLIST_NOLUN},
128 {"MICROTEK", "ScanMaker II", "5.61", BLIST_NOLUN},
129
130
131
132
133 {"SONY", "CD-ROM CDU-8001", "*", BLIST_BORKEN},
134 {"TEXEL", "CD-ROM", "1.06", BLIST_BORKEN},
135 {"IOMEGA", "Io20S *F", "*", BLIST_KEY},
136 {"INSITE", "Floptical F*8I", "*", BLIST_KEY},
137 {"INSITE", "I325VM", "*", BLIST_KEY},
138 {"LASOUND","CDX7405","3.10", BLIST_MAX5LUN | BLIST_SINGLELUN},
139 {"MICROP", "4110", "*", BLIST_NOTQ},
140 {"NRC", "MBR-7", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
141 {"NRC", "MBR-7.4", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
142 {"REGAL", "CDC-4X", "*", BLIST_MAX5LUN | BLIST_SINGLELUN},
143 {"NAKAMICH", "MJ-4.8S", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
144 {"NAKAMICH", "MJ-5.16S", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
145 {"PIONEER", "CD-ROM DRM-600", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
146 {"PIONEER", "CD-ROM DRM-602X", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
147 {"PIONEER", "CD-ROM DRM-604X", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
148 {"EMULEX", "MD21/S2 ESDI", "*", BLIST_SINGLELUN},
149 {"CANON", "IPUBJD", "*", BLIST_SPARSELUN},
150 {"nCipher", "Fastness Crypto", "*", BLIST_FORCELUN},
151 {"DEC","HSG80","*", BLIST_FORCELUN | BLIST_NOSTARTONADD},
152 {"COMPAQ","LOGICAL VOLUME","*", BLIST_FORCELUN},
153 {"COMPAQ","CR3500","*", BLIST_FORCELUN},
154 {"NEC", "PD-1 ODX654P", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
155 {"MATSHITA", "PD-1", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
156 {"iomega", "jaz 1GB", "J.86", BLIST_NOTQ | BLIST_NOLUN},
157 {"TOSHIBA","CDROM","*", BLIST_ISROM},
158 {"TOSHIBA","CD-ROM","*", BLIST_ISROM},
159 {"MegaRAID", "LD", "*", BLIST_FORCELUN},
160 {"DGC", "RAID", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
161 {"DGC", "DISK", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
162 {"DELL", "PV660F", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
163 {"DELL", "PV660F PSEUDO", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
164 {"DELL", "PSEUDO DEVICE .", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
165 {"DELL", "PV530F", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
166 {"EMC", "SYMMETRIX", "*", BLIST_SPARSELUN | BLIST_LARGELUN | BLIST_FORCELUN},
167 {"HP", "A6189A", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
168 {"HP", "OPEN-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
169 {"CMD", "CRA-7280", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
170 {"CNSI", "G7324", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
171 {"CNSi", "G8324", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
172 {"Zzyzx", "RocketStor 500S", "*", BLIST_SPARSELUN},
173 {"Zzyzx", "RocketStor 2000", "*", BLIST_SPARSELUN},
174 {"SONY", "TSL", "*", BLIST_FORCELUN},
175 {"DELL", "PERCRAID", "*", BLIST_FORCELUN},
176 {"HP", "NetRAID-4M", "*", BLIST_FORCELUN},
177 {"ADAPTEC", "AACRAID", "*", BLIST_FORCELUN},
178 {"ADAPTEC", "Adaptec 5400S", "*", BLIST_FORCELUN},
179 {"APPLE", "Xserve", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
180 {"COMPAQ", "MSA1000", "*", BLIST_SPARSELUN | BLIST_LARGELUN | BLIST_NOSTARTONADD},
181 {"COMPAQ", "MSA1000 VOLUME", "*", BLIST_SPARSELUN | BLIST_LARGELUN | BLIST_NOSTARTONADD},
182 {"COMPAQ", "HSV110", "*", BLIST_SPARSELUN | BLIST_LARGELUN | BLIST_NOSTARTONADD},
183 {"HP", "HSV100", "*", BLIST_SPARSELUN | BLIST_LARGELUN | BLIST_NOSTARTONADD},
184 {"HP", "C1557A", "*", BLIST_FORCELUN},
185 {"IBM", "AuSaV1S2", "*", BLIST_FORCELUN},
186 {"FSC", "CentricStor", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
187 {"DDN", "SAN DataDirector", "*", BLIST_SPARSELUN},
188 {"HITACHI", "DF400", "*", BLIST_SPARSELUN},
189 {"HITACHI", "DF500", "*", BLIST_SPARSELUN},
190 {"HITACHI", "DF600", "*", BLIST_SPARSELUN},
191 {"IBM", "ProFibre 4000R", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
192 {"HITACHI", "OPEN-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
193 {"HITACHI", "DISK-SUBSYSTEM", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
194 {"WINSYS","FLASHDISK G6", "*", BLIST_SPARSELUN},
195 {"DotHill","SANnet RAID X300", "*", BLIST_SPARSELUN},
196 {"SUN", "T300", "*", BLIST_SPARSELUN},
197 {"SUN", "T4", "*", BLIST_SPARSELUN},
198 {"SGI", "RAID3", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
199 {"SGI", "RAID5", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
200 {"SGI", "TP9100", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
201 {"SGI", "TP9300", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
202 {"SGI", "TP9400", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
203 {"SGI", "TP9500", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
204 {"MYLEX", "DACARMRB", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
205 {"PLATYPUS", "CX5", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
206 {"Raidtec", "FCR", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
207 {"HP", "C7200", "*", BLIST_SPARSELUN},
208 {"SMSC", "USB 2 HS", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
209 {"XYRATEX", "RS", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
210 {"NEC", "iStorage", "*", BLIST_SPARSELUN | BLIST_LARGELUN | BLIST_FORCELUN},
211
212
213
214
215 {NULL, NULL, NULL}
216};
217
218#define MAX_SCSI_LUNS 0xFFFFFFFF
219
220#ifdef CONFIG_SCSI_MULTI_LUN
221static unsigned int max_scsi_luns = MAX_SCSI_LUNS;
222#else
223static unsigned int max_scsi_luns = 1;
224#endif
225
226static unsigned int scsi_allow_ghost_devices = 0;
227
228#ifdef MODULE
229
230MODULE_PARM(max_scsi_luns, "i");
231MODULE_PARM_DESC(max_scsi_luns, "last scsi LUN (should be between 1 and 2^32-1)");
232MODULE_PARM(scsi_allow_ghost_devices, "i");
233MODULE_PARM_DESC(scsi_allow_ghost_devices, "allow devices marked as being offline to be accessed anyway (0 = off, else allow ghosts on lun 0 through scsi_allow_ghost_devices - 1");
234
235#else
236
237static int __init scsi_luns_setup(char *str)
238{
239 unsigned int tmp;
240
241 if (get_option(&str, &tmp) == 1) {
242 max_scsi_luns = tmp;
243 return 1;
244 } else {
245 printk("scsi_luns_setup : usage max_scsi_luns=n "
246 "(n should be between 1 and 2^32-1)\n");
247 return 0;
248 }
249}
250
251__setup("max_scsi_luns=", scsi_luns_setup);
252
253static int __init scsi_allow_ghost_devices_setup(char *str)
254{
255 unsigned int tmp;
256
257 if (get_option(&str, &tmp) == 1) {
258 scsi_allow_ghost_devices = tmp;
259 return 1;
260 } else {
261 printk("scsi_allow_ghost_devices_setup: usage scsi_allow_ghost_devices=n (0: off else\nallow ghost devices (ghost devices are devices that report themselves as\nbeing offline but which we allow access to anyway) on lun 0 through n - 1.\n");
262 return 0;
263 }
264}
265
266__setup("scsi_allow_ghost_devices=", scsi_allow_ghost_devices_setup);
267
268#endif
269
270static void print_inquiry(unsigned char *data)
271{
272 int i;
273
274 printk(" Vendor: ");
275 for (i = 8; i < 16; i++) {
276 if (data[i] >= 0x20 && i < data[4] + 5)
277 printk("%c", data[i]);
278 else
279 printk(" ");
280 }
281
282 printk(" Model: ");
283 for (i = 16; i < 32; i++) {
284 if (data[i] >= 0x20 && i < data[4] + 5)
285 printk("%c", data[i]);
286 else
287 printk(" ");
288 }
289
290 printk(" Rev: ");
291 for (i = 32; i < 36; i++) {
292 if (data[i] >= 0x20 && i < data[4] + 5)
293 printk("%c", data[i]);
294 else
295 printk(" ");
296 }
297
298 printk("\n");
299
300 i = data[0] & 0x1f;
301
302 printk(" Type: %s ",
303 i < MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] : "Unknown ");
304 printk(" ANSI SCSI revision: %02x", data[2] & 0x07);
305 if ((data[2] & 0x07) == 1 && (data[3] & 0x0f) == 1)
306 printk(" CCS\n");
307 else
308 printk("\n");
309}
310
311static int get_device_flags(unsigned char *response_data)
312{
313 int i = 0;
314 unsigned char *pnt;
315 for (i = 0; 1; i++) {
316 if (device_list[i].vendor == NULL)
317 return 0;
318 pnt = &response_data[8];
319 while (*pnt && *pnt == ' ')
320 pnt++;
321 if (memcmp(device_list[i].vendor, pnt,
322 strlen(device_list[i].vendor)))
323 continue;
324 pnt = &response_data[16];
325 while (*pnt && *pnt == ' ')
326 pnt++;
327 if (memcmp(device_list[i].model, pnt,
328 strlen(device_list[i].model)))
329 continue;
330 return device_list[i].flags;
331 }
332 return 0;
333}
334
335
336
337
338
339
340
341
342void scan_scsis(struct Scsi_Host *shpnt,
343 uint hardcoded,
344 uint hchannel,
345 uint hid,
346 uint hlun)
347{
348 uint channel;
349 unsigned int dev;
350 unsigned int lun;
351 unsigned int max_dev_lun;
352 unsigned char *scsi_result;
353 unsigned char scsi_result0[256];
354 Scsi_Device *SDpnt;
355 Scsi_Device *SDtail;
356 unsigned int sparse_lun;
357 int lun0_sl;
358
359 scsi_result = NULL;
360
361 SDpnt = (Scsi_Device *) kmalloc(sizeof(Scsi_Device),
362 GFP_ATOMIC);
363 if (SDpnt) {
364 memset(SDpnt, 0, sizeof(Scsi_Device));
365
366
367
368
369
370
371
372 scsi_initialize_queue(SDpnt, shpnt);
373 SDpnt->request_queue.queuedata = (void *) SDpnt;
374
375 scsi_result = ((!shpnt->unchecked_isa_dma)
376 ? &scsi_result0[0] : kmalloc(512, GFP_DMA));
377 }
378
379 if (scsi_result == NULL) {
380 printk("Unable to obtain scsi_result buffer\n");
381 goto leave;
382 }
383
384
385
386 SDpnt->queue_depth = 1;
387 SDpnt->host = shpnt;
388 SDpnt->online = TRUE;
389
390 initialize_merge_fn(SDpnt);
391
392
393
394
395 init_waitqueue_head(&SDpnt->scpnt_wait);
396
397
398
399
400 SDpnt->prev = NULL;
401 SDpnt->next = NULL;
402 if (shpnt->host_queue != NULL) {
403 SDtail = shpnt->host_queue;
404 while (SDtail->next != NULL)
405 SDtail = SDtail->next;
406
407 SDtail->next = SDpnt;
408 SDpnt->prev = SDtail;
409 } else {
410 shpnt->host_queue = SDpnt;
411 }
412
413
414
415
416
417 if (hardcoded == 1) {
418 Scsi_Device *oldSDpnt = SDpnt;
419 struct Scsi_Device_Template *sdtpnt;
420 channel = hchannel;
421 if (channel > shpnt->max_channel)
422 goto leave;
423 dev = hid;
424 if (dev >= shpnt->max_id)
425 goto leave;
426 lun = hlun;
427 if (lun >= shpnt->max_lun)
428 goto leave;
429 if ((0 == lun) || (lun > 7))
430 lun0_sl = SCSI_3;
431 else
432 lun0_sl = find_lun0_scsi_level(channel, dev, shpnt);
433 scan_scsis_single(channel, dev, lun, lun0_sl, &max_dev_lun,
434 &sparse_lun, &SDpnt, shpnt, scsi_result);
435 if (SDpnt != oldSDpnt) {
436
437
438
439
440 if (shpnt->select_queue_depths != NULL)
441 (shpnt->select_queue_depths)(shpnt,
442 shpnt->host_queue);
443
444 for (sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
445 if (sdtpnt->init && sdtpnt->dev_noticed)
446 (*sdtpnt->init) ();
447
448 for (sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next) {
449 if (sdtpnt->attach) {
450 (*sdtpnt->attach) (oldSDpnt);
451 if (oldSDpnt->attached) {
452 scsi_build_commandblocks(oldSDpnt);
453 if (0 == oldSDpnt->has_cmdblocks) {
454 printk("scan_scsis: DANGER, no command blocks\n");
455
456 }
457 }
458 }
459 }
460 scsi_resize_dma_pool();
461
462 for (sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next) {
463 if (sdtpnt->finish && sdtpnt->nr_dev) {
464 (*sdtpnt->finish) ();
465 }
466 }
467 }
468 } else {
469
470 int order_dev;
471
472 for (channel = 0; channel <= shpnt->max_channel; channel++) {
473 for (dev = 0; dev < shpnt->max_id; ++dev) {
474 if (shpnt->reverse_ordering)
475
476 order_dev = shpnt->max_id - dev - 1;
477 else
478 order_dev = dev;
479
480 if (shpnt->this_id != order_dev) {
481
482
483
484
485
486
487 max_dev_lun = (max_scsi_luns < shpnt->max_lun ?
488 max_scsi_luns : shpnt->max_lun);
489 sparse_lun = 0;
490 for (lun = 0, lun0_sl = SCSI_2; lun < max_dev_lun; ++lun) {
491
492 if ((lun0_sl < SCSI_3) && (lun > 7))
493 break;
494
495 if (!scan_scsis_single(channel, order_dev, lun, lun0_sl,
496 &max_dev_lun, &sparse_lun, &SDpnt, shpnt,
497 scsi_result)
498 && !sparse_lun)
499 break;
500 if (SDpnt && (0 == lun)) {
501 int bflags = get_device_flags (scsi_result);
502 if (bflags & BLIST_LARGELUN)
503 lun0_sl = SCSI_3;
504 else
505 lun0_sl = SDpnt->scsi_level;
506 }
507 }
508 }
509 }
510 }
511 }
512
513 leave:
514
515 {
516 Scsi_Device *prev, *next;
517 Scsi_Device *dqptr;
518
519 for (dqptr = shpnt->host_queue; dqptr != SDpnt; dqptr = dqptr->next)
520 continue;
521 if (dqptr) {
522 prev = dqptr->prev;
523 next = dqptr->next;
524 if (prev)
525 prev->next = next;
526 else
527 shpnt->host_queue = next;
528 if (next)
529 next->prev = prev;
530 }
531 }
532
533
534 if (SDpnt != NULL) {
535 blk_cleanup_queue(&SDpnt->request_queue);
536 kfree((char *) SDpnt);
537 }
538
539
540 if (scsi_result != &scsi_result0[0] && scsi_result != NULL) {
541 kfree(scsi_result);
542 } {
543 Scsi_Device *sdev;
544 Scsi_Cmnd *scmd;
545
546 SCSI_LOG_SCAN_BUS(4, printk("Host status for host %p:\n", shpnt));
547 for (sdev = shpnt->host_queue; sdev; sdev = sdev->next) {
548 SCSI_LOG_SCAN_BUS(4, printk("Device %d %p: ", sdev->id, sdev));
549 for (scmd = sdev->device_queue; scmd; scmd = scmd->next) {
550 SCSI_LOG_SCAN_BUS(4, printk("%p ", scmd));
551 }
552 SCSI_LOG_SCAN_BUS(4, printk("\n"));
553 }
554 }
555}
556
557
558
559
560
561
562static int scan_scsis_single(unsigned int channel, unsigned int dev,
563 unsigned int lun, int lun0_scsi_level,
564 unsigned int *max_dev_lun, unsigned int *sparse_lun,
565 Scsi_Device ** SDpnt2, struct Scsi_Host *shpnt,
566 char *scsi_result)
567{
568 char devname[64];
569 unsigned char scsi_cmd[MAX_COMMAND_SIZE];
570 struct Scsi_Device_Template *sdtpnt;
571 Scsi_Device *SDtail, *SDpnt = *SDpnt2;
572 Scsi_Request * SRpnt;
573 int bflags, type = -1;
574 extern devfs_handle_t scsi_devfs_handle;
575 int scsi_level;
576
577 SDpnt->host = shpnt;
578 SDpnt->id = dev;
579 SDpnt->lun = lun;
580 SDpnt->channel = channel;
581 SDpnt->online = TRUE;
582
583 scsi_build_commandblocks(SDpnt);
584
585
586 SDpnt->type = -1;
587
588
589
590
591
592 SDpnt->borken = 1;
593 SDpnt->was_reset = 0;
594 SDpnt->expecting_cc_ua = 0;
595 SDpnt->starved = 0;
596
597 if (NULL == (SRpnt = scsi_allocate_request(SDpnt))) {
598 printk("scan_scsis_single: no memory\n");
599 return 0;
600 }
601
602
603
604
605
606
607
608 SCSI_LOG_SCAN_BUS(3, printk("scsi: performing INQUIRY\n"));
609
610
611
612 scsi_cmd[0] = INQUIRY;
613 if ((lun > 0) && (lun0_scsi_level <= SCSI_2))
614 scsi_cmd[1] = (lun << 5) & 0xe0;
615 else
616 scsi_cmd[1] = 0;
617 scsi_cmd[2] = 0;
618 scsi_cmd[3] = 0;
619 scsi_cmd[4] = 255;
620 scsi_cmd[5] = 0;
621 SRpnt->sr_cmd_len = 0;
622 SRpnt->sr_data_direction = SCSI_DATA_READ;
623
624 scsi_wait_req (SRpnt, (void *) scsi_cmd,
625 (void *) scsi_result,
626 256, SCSI_TIMEOUT+4*HZ, 3);
627
628 SCSI_LOG_SCAN_BUS(3, printk("scsi: INQUIRY %s with code 0x%x\n",
629 SRpnt->sr_result ? "failed" : "successful", SRpnt->sr_result));
630
631
632
633
634
635 if (SRpnt->sr_result) {
636 if ((driver_byte(SRpnt->sr_result) & DRIVER_SENSE) != 0 &&
637 (SRpnt->sr_sense_buffer[2] & 0xf) == UNIT_ATTENTION &&
638 SRpnt->sr_sense_buffer[12] == 0x28 &&
639 SRpnt->sr_sense_buffer[13] == 0) {
640
641 } else {
642
643 scsi_release_request(SRpnt);
644 scsi_release_commandblocks(SDpnt);
645 return 0;
646 }
647 }
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666 if (lun != 0 && (scsi_result[0] >> 5) == 1) {
667 scsi_release_request(SRpnt);
668 scsi_release_commandblocks(SDpnt);
669 return 0;
670 }
671
672
673
674
675 bflags = get_device_flags (scsi_result);
676
677 if (bflags & BLIST_SPARSELUN) {
678 *sparse_lun = 1;
679 }
680
681
682
683
684 if ((scsi_result[0] >> 5) == 3) {
685 scsi_release_request(SRpnt);
686 return 0;
687 }
688
689
690
691
692
693
694 if (bflags & BLIST_ISDISK) {
695 scsi_result[0] = TYPE_DISK;
696 scsi_result[1] |= 0x80;
697 }
698
699 if (bflags & BLIST_ISROM) {
700 scsi_result[0] = TYPE_ROM;
701 scsi_result[1] |= 0x80;
702 }
703
704 memcpy(SDpnt->vendor, scsi_result + 8, 8);
705 memcpy(SDpnt->model, scsi_result + 16, 16);
706 memcpy(SDpnt->rev, scsi_result + 32, 4);
707
708 SDpnt->removable = (0x80 & scsi_result[1]) >> 7;
709
710 if ((((scsi_result[0] >> 5) & 7) == 1) &&
711 (lun >= scsi_allow_ghost_devices))
712 SDpnt->online = FALSE;
713 else
714 SDpnt->online = TRUE;
715 SDpnt->lockable = SDpnt->removable;
716 SDpnt->changed = 0;
717 SDpnt->access_count = 0;
718 SDpnt->busy = 0;
719 SDpnt->has_cmdblocks = 0;
720
721
722
723
724
725 switch (type = (scsi_result[0] & 0x1f)) {
726 case TYPE_TAPE:
727 case TYPE_DISK:
728 case TYPE_PRINTER:
729 case TYPE_MOD:
730 case TYPE_PROCESSOR:
731 case TYPE_SCANNER:
732 case TYPE_MEDIUM_CHANGER:
733 case TYPE_ENCLOSURE:
734 case TYPE_COMM:
735 SDpnt->writeable = 1;
736 break;
737 case TYPE_WORM:
738 case TYPE_ROM:
739 SDpnt->writeable = 0;
740 break;
741 default:
742 printk("scsi: unknown type %d\n", type);
743 }
744
745 SDpnt->device_blocked = FALSE;
746 SDpnt->device_busy = 0;
747 SDpnt->single_lun = 0;
748 SDpnt->soft_reset =
749 (scsi_result[7] & 1) && ((scsi_result[3] & 7) == 2);
750 SDpnt->random = (type == TYPE_TAPE) ? 0 : 1;
751 SDpnt->type = (type & 0x1f);
752
753 print_inquiry(scsi_result);
754
755 sprintf (devname, "host%d/bus%d/target%d/lun%d",
756 SDpnt->host->host_no, SDpnt->channel, SDpnt->id, SDpnt->lun);
757 if (SDpnt->de) printk ("DEBUG: dir: \"%s\" already exists\n", devname);
758 else SDpnt->de = devfs_mk_dir (scsi_devfs_handle, devname, NULL);
759
760 for (sdtpnt = scsi_devicelist; sdtpnt;
761 sdtpnt = sdtpnt->next)
762 if (sdtpnt->detect)
763 SDpnt->attached +=
764 (*sdtpnt->detect) (SDpnt);
765
766 SDpnt->scsi_level = scsi_result[2] & 0x07;
767 if (SDpnt->scsi_level >= 2 ||
768 (SDpnt->scsi_level == 1 &&
769 (scsi_result[3] & 0x0f) == 1))
770 SDpnt->scsi_level++;
771 scsi_level = SDpnt->scsi_level;
772
773
774
775
776
777 SDpnt->disconnect = 0;
778
779
780
781
782
783
784 SDpnt->tagged_queue = 0;
785 if ((SDpnt->scsi_level >= SCSI_2) &&
786 (scsi_result[7] & 2) &&
787 !(bflags & BLIST_NOTQ)) {
788 SDpnt->tagged_supported = 1;
789 SDpnt->current_tag = 0;
790 }
791
792
793
794
795
796
797 if ((bflags & BLIST_BORKEN) == 0)
798 SDpnt->borken = 0;
799
800
801
802
803
804 if (bflags & BLIST_NOSTARTONADD)
805 SDpnt->no_start_on_add = 1;
806
807
808
809
810
811 if (bflags & BLIST_SINGLELUN)
812 SDpnt->single_lun = 1;
813
814
815
816
817 if ((bflags & BLIST_KEY) != 0) {
818 printk("Unlocked floptical drive.\n");
819 SDpnt->lockable = 0;
820 scsi_cmd[0] = MODE_SENSE;
821 if (shpnt->max_lun <= 8)
822 scsi_cmd[1] = (lun << 5) & 0xe0;
823 else scsi_cmd[1] = 0;
824 scsi_cmd[2] = 0x2e;
825 scsi_cmd[3] = 0;
826 scsi_cmd[4] = 0x2a;
827 scsi_cmd[5] = 0;
828 SRpnt->sr_cmd_len = 0;
829 SRpnt->sr_data_direction = SCSI_DATA_READ;
830 scsi_wait_req (SRpnt, (void *) scsi_cmd,
831 (void *) scsi_result, 0x2a,
832 SCSI_TIMEOUT, 3);
833 }
834
835 scsi_release_request(SRpnt);
836 SRpnt = NULL;
837
838 scsi_release_commandblocks(SDpnt);
839
840
841
842
843
844
845 SDpnt = (Scsi_Device *) kmalloc(sizeof(Scsi_Device), GFP_ATOMIC);
846 if (!SDpnt) {
847 printk("scsi: scan_scsis_single: Cannot malloc\n");
848 return 0;
849 }
850 memset(SDpnt, 0, sizeof(Scsi_Device));
851
852 *SDpnt2 = SDpnt;
853 SDpnt->queue_depth = 1;
854 SDpnt->host = shpnt;
855 SDpnt->online = TRUE;
856 SDpnt->scsi_level = scsi_level;
857
858
859
860
861
862
863
864
865 scsi_initialize_queue(SDpnt, shpnt);
866 SDpnt->host = shpnt;
867 initialize_merge_fn(SDpnt);
868
869
870
871
872 SDpnt->online = TRUE;
873
874
875
876
877 init_waitqueue_head(&SDpnt->scpnt_wait);
878
879
880
881
882
883 if (shpnt->host_queue == NULL)
884 panic("scan_scsis_single: Host queue == NULL\n");
885
886 SDtail = shpnt->host_queue;
887 while (SDtail->next) {
888 SDtail = SDtail->next;
889 }
890
891
892 SDtail->next = SDpnt;
893 SDpnt->prev = SDtail;
894 SDpnt->next = NULL;
895
896
897
898
899 if (bflags & BLIST_NOLUN)
900 return 0;
901
902
903
904
905
906 if (bflags & BLIST_SPARSELUN) {
907 *max_dev_lun = shpnt->max_lun;
908 *sparse_lun = 1;
909 return 1;
910 }
911
912
913
914
915 if (bflags & BLIST_FORCELUN) {
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941 *max_dev_lun = shpnt->max_lun;
942 return 1;
943 }
944
945
946
947 if (bflags & BLIST_MAX5LUN) {
948 *max_dev_lun = 5;
949 return 1;
950 }
951
952
953
954
955
956
957 if (((scsi_result[2] & 0x07) == 0)
958 ||
959 ((scsi_result[2] & 0x07) == 1 &&
960 (scsi_result[3] & 0x0f) == 0))
961 return 0;
962 return 1;
963}
964
965
966
967
968
969
970static int find_lun0_scsi_level(unsigned int channel, unsigned int dev,
971 struct Scsi_Host *shpnt)
972{
973 int res = SCSI_2;
974 Scsi_Device *SDpnt;
975
976 for (SDpnt = shpnt->host_queue; SDpnt; SDpnt = SDpnt->next)
977 {
978 if ((0 == SDpnt->lun) && (dev == SDpnt->id) &&
979 (channel == SDpnt->channel))
980 return (int)SDpnt->scsi_level;
981 }
982
983 return res;
984}
985