~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to xen/drivers/scsi/scsi_scan.c

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  scsi_scan.c Copyright (C) 2000 Eric Youngdale
3
 
 *
4
 
 *  Bus scan logic.
5
 
 *
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
 
 */
10
 
 
11
 
#define __NO_VERSION__
12
 
#include <xeno/config.h>
13
 
#include <xeno/module.h>
14
 
#include <xeno/init.h>
15
 
 
16
 
#include <xeno/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
 
 * Flags for irregular SCSI devices that need special treatment 
28
 
 */
29
 
#define BLIST_NOLUN             0x001   /* Don't scan for LUNs */
30
 
#define BLIST_FORCELUN          0x002   /* Known to have LUNs, force sanning */
31
 
#define BLIST_BORKEN            0x004   /* Flag for broken handshaking */
32
 
#define BLIST_KEY               0x008   /* Needs to be unlocked by special command */
33
 
#define BLIST_SINGLELUN         0x010   /* LUNs should better not be used in parallel */
34
 
#define BLIST_NOTQ              0x020   /* Buggy Tagged Command Queuing */
35
 
#define BLIST_SPARSELUN         0x040   /* Non consecutive LUN numbering */
36
 
#define BLIST_MAX5LUN           0x080   /* Avoid LUNS >= 5 */
37
 
#define BLIST_ISDISK            0x100   /* Treat as (removable) disk */
38
 
#define BLIST_ISROM             0x200   /* Treat as (removable) CD-ROM */
39
 
#define BLIST_LARGELUN          0x400   /* LUNs larger than 7 despite reporting as SCSI 2 */
40
 
 
41
 
static void print_inquiry(unsigned char *data);
42
 
static int scan_scsis_single(unsigned int channel, unsigned int dev,
43
 
                unsigned int lun, int lun0_scsi_level, 
44
 
                unsigned int *max_scsi_dev, unsigned int *sparse_lun, 
45
 
                Scsi_Device ** SDpnt, struct Scsi_Host *shpnt, 
46
 
                char *scsi_result);
47
 
static int find_lun0_scsi_level(unsigned int channel, unsigned int dev,
48
 
                                struct Scsi_Host *shpnt);
49
 
 
50
 
struct dev_info {
51
 
        const char *vendor;
52
 
        const char *model;
53
 
        const char *revision;   /* Latest revision known to be bad.  Not used yet */
54
 
        unsigned flags;
55
 
};
56
 
 
57
 
/*
58
 
 * This is what was previously known as the blacklist.  The concept
59
 
 * has been expanded so that we can specify other types of things we
60
 
 * need to be aware of.
61
 
 */
62
 
static struct dev_info device_list[] =
63
 
{
64
 
/* The following devices are known not to tolerate a lun != 0 scan for
65
 
 * one reason or another.  Some will respond to all luns, others will
66
 
 * lock up.
67
 
 */
68
 
        {"Aashima", "IMAGERY 2400SP", "1.03", BLIST_NOLUN},     /* Locks up if polled for lun != 0 */
69
 
        {"CHINON", "CD-ROM CDS-431", "H42", BLIST_NOLUN},       /* Locks up if polled for lun != 0 */
70
 
        {"CHINON", "CD-ROM CDS-535", "Q14", BLIST_NOLUN},       /* Locks up if polled for lun != 0 */
71
 
        {"DENON", "DRD-25X", "V", BLIST_NOLUN},                 /* Locks up if probed for lun != 0 */
72
 
        {"HITACHI", "DK312C", "CM81", BLIST_NOLUN},             /* Responds to all lun - dtg */
73
 
        {"HITACHI", "DK314C", "CR21", BLIST_NOLUN},             /* responds to all lun */
74
 
        {"IMS", "CDD521/10", "2.06", BLIST_NOLUN},              /* Locks-up when LUN>0 polled. */
75
 
        {"MAXTOR", "XT-3280", "PR02", BLIST_NOLUN},             /* Locks-up when LUN>0 polled. */
76
 
        {"MAXTOR", "XT-4380S", "B3C", BLIST_NOLUN},             /* Locks-up when LUN>0 polled. */
77
 
        {"MAXTOR", "MXT-1240S", "I1.2", BLIST_NOLUN},           /* Locks up when LUN>0 polled */
78
 
        {"MAXTOR", "XT-4170S", "B5A", BLIST_NOLUN},             /* Locks-up sometimes when LUN>0 polled. */
79
 
        {"MAXTOR", "XT-8760S", "B7B", BLIST_NOLUN},             /* guess what? */
80
 
        {"MEDIAVIS", "RENO CD-ROMX2A", "2.03", BLIST_NOLUN},    /*Responds to all lun */
81
 
        {"NEC", "CD-ROM DRIVE:841", "1.0", BLIST_NOLUN},        /* Locks-up when LUN>0 polled. */
82
 
        {"PHILIPS", "PCA80SC", "V4-2", BLIST_NOLUN},            /* Responds to all lun */
83
 
        {"RODIME", "RO3000S", "2.33", BLIST_NOLUN},             /* Locks up if polled for lun != 0 */
84
 
        {"SANYO", "CRD-250S", "1.20", BLIST_NOLUN},             /* causes failed REQUEST SENSE on lun 1
85
 
                                                                 * for aha152x controller, which causes
86
 
                                                                 * SCSI code to reset bus.*/
87
 
        {"SEAGATE", "ST157N", "\004|j", BLIST_NOLUN},           /* causes failed REQUEST SENSE on lun 1
88
 
                                                                 * for aha152x controller, which causes
89
 
                                                                 * SCSI code to reset bus.*/
90
 
        {"SEAGATE", "ST296", "921", BLIST_NOLUN},               /* Responds to all lun */
91
 
        {"SEAGATE", "ST1581", "6538", BLIST_NOLUN},             /* Responds to all lun */
92
 
        {"SONY", "CD-ROM CDU-541", "4.3d", BLIST_NOLUN},        
93
 
        {"SONY", "CD-ROM CDU-55S", "1.0i", BLIST_NOLUN},
94
 
        {"SONY", "CD-ROM CDU-561", "1.7x", BLIST_NOLUN},
95
 
        {"SONY", "CD-ROM CDU-8012", "*", BLIST_NOLUN},
96
 
        {"TANDBERG", "TDC 3600", "U07", BLIST_NOLUN},           /* Locks up if polled for lun != 0 */
97
 
        {"TEAC", "CD-R55S", "1.0H", BLIST_NOLUN},               /* Locks up if polled for lun != 0 */
98
 
        {"TEAC", "CD-ROM", "1.06", BLIST_NOLUN},                /* causes failed REQUEST SENSE on lun 1
99
 
                                                                 * for seagate controller, which causes
100
 
                                                                 * SCSI code to reset bus.*/
101
 
        {"TEAC", "MT-2ST/45S2-27", "RV M", BLIST_NOLUN},        /* Responds to all lun */
102
 
        {"TEXEL", "CD-ROM", "1.06", BLIST_NOLUN},               /* causes failed REQUEST SENSE on lun 1
103
 
                                                                 * for seagate controller, which causes
104
 
                                                                 * SCSI code to reset bus.*/
105
 
        {"QUANTUM", "LPS525S", "3110", BLIST_NOLUN},            /* Locks sometimes if polled for lun != 0 */
106
 
        {"QUANTUM", "PD1225S", "3110", BLIST_NOLUN},            /* Locks sometimes if polled for lun != 0 */
107
 
        {"QUANTUM", "FIREBALL ST4.3S", "0F0C", BLIST_NOLUN},    /* Locks up when polled for lun != 0 */
108
 
        {"MEDIAVIS", "CDR-H93MV", "1.31", BLIST_NOLUN},         /* Locks up if polled for lun != 0 */
109
 
        {"SANKYO", "CP525", "6.64", BLIST_NOLUN},               /* causes failed REQ SENSE, extra reset */
110
 
        {"HP", "C1750A", "3226", BLIST_NOLUN},                  /* scanjet iic */
111
 
        {"HP", "C1790A", "", BLIST_NOLUN},                      /* scanjet iip */
112
 
        {"HP", "C2500A", "", BLIST_NOLUN},                      /* scanjet iicx */
113
 
        {"HP", "A6188A", "*", BLIST_SPARSELUN},                 /* HP Va7100 Array */
114
 
        {"HP", "A6189A", "*", BLIST_SPARSELUN},                 /* HP Va7400 Array */
115
 
        {"HP", "A6189B", "*", BLIST_SPARSELUN},                 /* HP Va7410 Array */
116
 
        {"HP", "OPEN-", "*", BLIST_SPARSELUN},                  /* HP XP Arrays */
117
 
        {"YAMAHA", "CDR100", "1.00", BLIST_NOLUN},              /* Locks up if polled for lun != 0 */
118
 
        {"YAMAHA", "CDR102", "1.00", BLIST_NOLUN},              /* Locks up if polled for lun != 0  
119
 
                                                                 * extra reset */
120
 
        {"YAMAHA", "CRW8424S", "1.0", BLIST_NOLUN},             /* Locks up if polled for lun != 0 */
121
 
        {"YAMAHA", "CRW6416S", "1.0c", BLIST_NOLUN},            /* Locks up if polled for lun != 0 */
122
 
        {"MITSUMI", "CD-R CR-2201CS", "6119", BLIST_NOLUN},     /* Locks up if polled for lun != 0 */
123
 
        {"RELISYS", "Scorpio", "*", BLIST_NOLUN},               /* responds to all LUN */
124
 
        {"RELISYS", "VM3530+", "*", BLIST_NOLUN},               /* responds to all LUN */
125
 
        {"ACROSS", "", "*", BLIST_NOLUN},                       /* responds to all LUN */
126
 
        {"MICROTEK", "ScanMaker II", "5.61", BLIST_NOLUN},      /* responds to all LUN */
127
 
 
128
 
/*
129
 
 * Other types of devices that have special flags.
130
 
 */
131
 
        {"SONY", "CD-ROM CDU-8001", "*", BLIST_BORKEN},
132
 
        {"TEXEL", "CD-ROM", "1.06", BLIST_BORKEN},
133
 
        {"IOMEGA", "Io20S         *F", "*", BLIST_KEY},
134
 
        {"INSITE", "Floptical   F*8I", "*", BLIST_KEY},
135
 
        {"INSITE", "I325VM", "*", BLIST_KEY},
136
 
        {"LASOUND","CDX7405","3.10", BLIST_MAX5LUN | BLIST_SINGLELUN},
137
 
        {"MICROP", "4110", "*", BLIST_NOTQ},                    /* Buggy Tagged Queuing */
138
 
        {"NRC", "MBR-7", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
139
 
        {"NRC", "MBR-7.4", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
140
 
        {"REGAL", "CDC-4X", "*", BLIST_MAX5LUN | BLIST_SINGLELUN},
141
 
        {"NAKAMICH", "MJ-4.8S", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
142
 
        {"NAKAMICH", "MJ-5.16S", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
143
 
        {"PIONEER", "CD-ROM DRM-600", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
144
 
        {"PIONEER", "CD-ROM DRM-602X", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
145
 
        {"PIONEER", "CD-ROM DRM-604X", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
146
 
        {"EMULEX", "MD21/S2     ESDI", "*", BLIST_SINGLELUN},
147
 
        {"CANON", "IPUBJD", "*", BLIST_SPARSELUN},
148
 
        {"nCipher", "Fastness Crypto", "*", BLIST_FORCELUN},
149
 
        {"DEC","HSG80","*", BLIST_FORCELUN},
150
 
        {"COMPAQ","LOGICAL VOLUME","*", BLIST_FORCELUN},
151
 
        {"COMPAQ","CR3500","*", BLIST_FORCELUN},
152
 
        {"NEC", "PD-1 ODX654P", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
153
 
        {"MATSHITA", "PD-1", "*", BLIST_FORCELUN | BLIST_SINGLELUN},
154
 
        {"iomega", "jaz 1GB", "J.86", BLIST_NOTQ | BLIST_NOLUN},
155
 
        {"TOSHIBA","CDROM","*", BLIST_ISROM},
156
 
        {"TOSHIBA","CD-ROM","*", BLIST_ISROM},
157
 
        {"MegaRAID", "LD", "*", BLIST_FORCELUN},
158
 
        {"DGC",  "RAID",      "*", BLIST_SPARSELUN | BLIST_LARGELUN}, // Dell PV 650F (tgt @ LUN 0)
159
 
        {"DGC",  "DISK",      "*", BLIST_SPARSELUN | BLIST_LARGELUN}, // Dell PV 650F (no tgt @ LUN 0) 
160
 
        {"DELL", "PV660F",   "*", BLIST_SPARSELUN | BLIST_LARGELUN},
161
 
        {"DELL", "PV660F   PSEUDO",   "*", BLIST_SPARSELUN | BLIST_LARGELUN},
162
 
        {"DELL", "PSEUDO DEVICE .",   "*", BLIST_SPARSELUN | BLIST_LARGELUN}, // Dell PV 530F
163
 
        {"DELL", "PV530F",    "*", BLIST_SPARSELUN | BLIST_LARGELUN}, // Dell PV 530F
164
 
        {"EMC", "SYMMETRIX", "*", BLIST_SPARSELUN | BLIST_LARGELUN | BLIST_FORCELUN},
165
 
        {"HP", "A6189A", "*", BLIST_SPARSELUN |  BLIST_LARGELUN}, // HP VA7400, by Alar Aun
166
 
        {"CMD", "CRA-7280", "*", BLIST_SPARSELUN | BLIST_LARGELUN},   // CMD RAID Controller
167
 
        {"CNSI", "G7324", "*", BLIST_SPARSELUN | BLIST_LARGELUN},     // Chaparral G7324 RAID
168
 
        {"CNSi", "G8324", "*", BLIST_SPARSELUN},     // Chaparral G8324 RAID
169
 
        {"Zzyzx", "RocketStor 500S", "*", BLIST_SPARSELUN},
170
 
        {"Zzyzx", "RocketStor 2000", "*", BLIST_SPARSELUN},
171
 
        {"SONY", "TSL",       "*", BLIST_FORCELUN},  // DDS3 & DDS4 autoloaders
172
 
        {"DELL", "PERCRAID", "*", BLIST_FORCELUN},
173
 
        {"HP", "NetRAID-4M", "*", BLIST_FORCELUN},
174
 
        {"ADAPTEC", "AACRAID", "*", BLIST_FORCELUN},
175
 
        {"ADAPTEC", "Adaptec 5400S", "*", BLIST_FORCELUN},
176
 
        {"COMPAQ", "MSA1000", "*", BLIST_FORCELUN},
177
 
        {"HP", "C1557A", "*", BLIST_FORCELUN},
178
 
        {"IBM", "AuSaV1S2", "*", BLIST_FORCELUN},
179
 
        {"FSC", "CentricStor", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
180
 
        {"DDN", "SAN DataDirector", "*", BLIST_SPARSELUN},
181
 
        {"HITACHI", "DF400", "*", BLIST_SPARSELUN},
182
 
        {"HITACHI", "DF500", "*", BLIST_SPARSELUN},
183
 
        {"HITACHI", "DF600", "*", BLIST_SPARSELUN},
184
 
 
185
 
        /*
186
 
         * Must be at end of list...
187
 
         */
188
 
        {NULL, NULL, NULL}
189
 
};
190
 
 
191
 
#define MAX_SCSI_LUNS 0xFFFFFFFF
192
 
 
193
 
#ifdef CONFIG_SCSI_MULTI_LUN
194
 
static unsigned int max_scsi_luns = MAX_SCSI_LUNS;
195
 
#else
196
 
static unsigned int max_scsi_luns = 1;
197
 
#endif
198
 
 
199
 
#ifdef MODULE
200
 
 
201
 
MODULE_PARM(max_scsi_luns, "i");
202
 
MODULE_PARM_DESC(max_scsi_luns, "last scsi LUN (should be between 1 and 2^32-1)");
203
 
 
204
 
#else
205
 
 
206
 
static int __init scsi_luns_setup(char *str)
207
 
{
208
 
#if 0
209
 
        unsigned int tmp;
210
 
 
211
 
        if (get_option(&str, &tmp) == 1) {
212
 
                max_scsi_luns = tmp;
213
 
                return 1;
214
 
        } else {
215
 
                printk("scsi_luns_setup : usage max_scsi_luns=n "
216
 
                       "(n should be between 1 and 2^32-1)\n");
217
 
                return 0;
218
 
        }
219
 
#else
220
 
        return 0;
221
 
#endif
222
 
}
223
 
 
224
 
__setup("max_scsi_luns=", scsi_luns_setup);
225
 
 
226
 
#endif
227
 
 
228
 
static void print_inquiry(unsigned char *data)
229
 
{
230
 
        int i;
231
 
 
232
 
        printk("  Vendor: ");
233
 
        for (i = 8; i < 16; i++) {
234
 
                if (data[i] >= 0x20 && i < data[4] + 5)
235
 
                        printk("%c", data[i]);
236
 
                else
237
 
                        printk(" ");
238
 
        }
239
 
 
240
 
        printk("  Model: ");
241
 
        for (i = 16; i < 32; i++) {
242
 
                if (data[i] >= 0x20 && i < data[4] + 5)
243
 
                        printk("%c", data[i]);
244
 
                else
245
 
                        printk(" ");
246
 
        }
247
 
 
248
 
        printk("  Rev: ");
249
 
        for (i = 32; i < 36; i++) {
250
 
                if (data[i] >= 0x20 && i < data[4] + 5)
251
 
                        printk("%c", data[i]);
252
 
                else
253
 
                        printk(" ");
254
 
        }
255
 
 
256
 
        printk("\n");
257
 
 
258
 
        i = data[0] & 0x1f;
259
 
 
260
 
        printk("  Type:   %s ",
261
 
               i < MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] : "Unknown          ");
262
 
        printk("                 ANSI SCSI revision: %02x", data[2] & 0x07);
263
 
        if ((data[2] & 0x07) == 1 && (data[3] & 0x0f) == 1)
264
 
                printk(" CCS\n");
265
 
        else
266
 
                printk("\n");
267
 
}
268
 
 
269
 
static int get_device_flags(unsigned char *response_data)
270
 
{
271
 
        int i = 0;
272
 
        unsigned char *pnt;
273
 
        for (i = 0; 1; i++) {
274
 
                if (device_list[i].vendor == NULL)
275
 
                        return 0;
276
 
                pnt = &response_data[8];
277
 
                while (*pnt && *pnt == ' ')
278
 
                        pnt++;
279
 
                if (memcmp(device_list[i].vendor, pnt,
280
 
                           strlen(device_list[i].vendor)))
281
 
                        continue;
282
 
                pnt = &response_data[16];
283
 
                while (*pnt && *pnt == ' ')
284
 
                        pnt++;
285
 
                if (memcmp(device_list[i].model, pnt,
286
 
                           strlen(device_list[i].model)))
287
 
                        continue;
288
 
                return device_list[i].flags;
289
 
        }
290
 
        return 0;
291
 
}
292
 
 
293
 
/*
294
 
 *  Detecting SCSI devices :
295
 
 *  We scan all present host adapter's busses,  from ID 0 to ID (max_id).
296
 
 *  We use the INQUIRY command, determine device type, and pass the ID /
297
 
 *  lun address of all sequential devices to the tape driver, all random
298
 
 *  devices to the disk driver.
299
 
 */
300
 
void scan_scsis(struct Scsi_Host *shpnt,
301
 
                       uint hardcoded,
302
 
                       uint hchannel,
303
 
                       uint hid,
304
 
                       uint hlun)
305
 
{
306
 
        uint channel;
307
 
        unsigned int dev;
308
 
        unsigned int lun;
309
 
        unsigned int max_dev_lun;
310
 
        unsigned char *scsi_result;
311
 
        unsigned char scsi_result0[256];
312
 
        Scsi_Device *SDpnt;
313
 
        Scsi_Device *SDtail;
314
 
        unsigned int sparse_lun;
315
 
        int lun0_sl;
316
 
 
317
 
        scsi_result = NULL;
318
 
 
319
 
        SDpnt = (Scsi_Device *) kmalloc(sizeof(Scsi_Device),
320
 
                                        GFP_ATOMIC);
321
 
        if (SDpnt) {
322
 
                memset(SDpnt, 0, sizeof(Scsi_Device));
323
 
                /*
324
 
                 * Register the queue for the device.  All I/O requests will
325
 
                 * come in through here.  We also need to register a pointer to
326
 
                 * ourselves, since the queue handler won't know what device
327
 
                 * the queue actually represents.   We could look it up, but it
328
 
                 * is pointless work.
329
 
                 */
330
 
                scsi_initialize_queue(SDpnt, shpnt);
331
 
                SDpnt->request_queue.queuedata = (void *) SDpnt;
332
 
                /* Make sure we have something that is valid for DMA purposes */
333
 
                scsi_result = ((!shpnt->unchecked_isa_dma)
334
 
                               ? &scsi_result0[0] : kmalloc(512, GFP_DMA));
335
 
        }
336
 
 
337
 
        if (scsi_result == NULL) {
338
 
                printk("Unable to obtain scsi_result buffer\n");
339
 
                goto leave;
340
 
        }
341
 
        /*
342
 
         * We must chain ourself in the host_queue, so commands can time out 
343
 
         */
344
 
        SDpnt->queue_depth = 1;
345
 
        SDpnt->host = shpnt;
346
 
        SDpnt->online = TRUE;
347
 
 
348
 
        initialize_merge_fn(SDpnt);
349
 
 
350
 
#if 0
351
 
        /*
352
 
         * Initialize the object that we will use to wait for command blocks.
353
 
         */
354
 
        init_waitqueue_head(&SDpnt->scpnt_wait);
355
 
#endif
356
 
 
357
 
        /*
358
 
         * Next, hook the device to the host in question.
359
 
         */
360
 
        SDpnt->prev = NULL;
361
 
        SDpnt->next = NULL;
362
 
        if (shpnt->host_queue != NULL) {
363
 
                SDtail = shpnt->host_queue;
364
 
                while (SDtail->next != NULL)
365
 
                        SDtail = SDtail->next;
366
 
 
367
 
                SDtail->next = SDpnt;
368
 
                SDpnt->prev = SDtail;
369
 
        } else {
370
 
                shpnt->host_queue = SDpnt;
371
 
        }
372
 
 
373
 
        /*
374
 
         * We need to increment the counter for this one device so we can track
375
 
         * when things are quiet.
376
 
         */
377
 
        if (hardcoded == 1) {
378
 
                Scsi_Device *oldSDpnt = SDpnt;
379
 
                struct Scsi_Device_Template *sdtpnt;
380
 
                channel = hchannel;
381
 
                if (channel > shpnt->max_channel)
382
 
                        goto leave;
383
 
                dev = hid;
384
 
                if (dev >= shpnt->max_id)
385
 
                        goto leave;
386
 
                lun = hlun;
387
 
                if (lun >= shpnt->max_lun)
388
 
                        goto leave;
389
 
                if ((0 == lun) || (lun > 7))
390
 
                        lun0_sl = SCSI_3; /* actually don't care for 0 == lun */
391
 
                else
392
 
                        lun0_sl = find_lun0_scsi_level(channel, dev, shpnt);
393
 
                scan_scsis_single(channel, dev, lun, lun0_sl, &max_dev_lun, 
394
 
                                  &sparse_lun, &SDpnt, shpnt, scsi_result);
395
 
                if (SDpnt != oldSDpnt) {
396
 
 
397
 
                        /* it could happen the blockdevice hasn't yet been inited */
398
 
                        /* queue_depth() moved from scsi_proc_info() so that
399
 
                           it is called before scsi_build_commandblocks() */
400
 
                        if (shpnt->select_queue_depths != NULL)
401
 
                                (shpnt->select_queue_depths)(shpnt,
402
 
                                                             shpnt->host_queue);
403
 
 
404
 
                        for (sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
405
 
                                if (sdtpnt->init && sdtpnt->dev_noticed)
406
 
                                        (*sdtpnt->init) ();
407
 
 
408
 
                        for (sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next) {
409
 
                                if (sdtpnt->attach) {
410
 
                                        (*sdtpnt->attach) (oldSDpnt);
411
 
                                        if (oldSDpnt->attached) {
412
 
                                                scsi_build_commandblocks(oldSDpnt);
413
 
                                                if (0 == oldSDpnt->has_cmdblocks) {
414
 
                                                        printk("scan_scsis: DANGER, no command blocks\n");
415
 
                                                        /* What to do now ?? */
416
 
                                                }
417
 
                                        }
418
 
                                }
419
 
                        }
420
 
                        scsi_resize_dma_pool();
421
 
 
422
 
                        for (sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next) {
423
 
                                if (sdtpnt->finish && sdtpnt->nr_dev) {
424
 
                                        (*sdtpnt->finish) ();
425
 
                                }
426
 
                        }
427
 
                }
428
 
        } else {
429
 
                /* Actual LUN. PC ordering is 0->n IBM/spec ordering is n->0 */
430
 
                int order_dev;
431
 
 
432
 
                for (channel = 0; channel <= shpnt->max_channel; channel++) {
433
 
                        for (dev = 0; dev < shpnt->max_id; ++dev) {
434
 
                                if (shpnt->reverse_ordering)
435
 
                                        /* Shift to scanning 15,14,13... or 7,6,5,4, */
436
 
                                        order_dev = shpnt->max_id - dev - 1;
437
 
                                else
438
 
                                        order_dev = dev;
439
 
 
440
 
                                if (shpnt->this_id != order_dev) {
441
 
 
442
 
                                        /*
443
 
                                         * We need the for so our continue, etc. work fine. We put this in
444
 
                                         * a variable so that we can override it during the scan if we
445
 
                                         * detect a device *KNOWN* to have multiple logical units.
446
 
                                         */
447
 
                                        max_dev_lun = (max_scsi_luns < shpnt->max_lun ?
448
 
                                         max_scsi_luns : shpnt->max_lun);
449
 
                                        sparse_lun = 0;
450
 
                                        for (lun = 0, lun0_sl = SCSI_2; lun < max_dev_lun; ++lun) {
451
 
                                                /* don't probe further for luns > 7 for targets <= SCSI_2 */
452
 
                                                if ((lun0_sl < SCSI_3) && (lun > 7))
453
 
                                                        break;
454
 
 
455
 
                                                if (!scan_scsis_single(channel, order_dev, lun, lun0_sl,
456
 
                                                                       &max_dev_lun, &sparse_lun, &SDpnt, shpnt,
457
 
                                                                       scsi_result)
458
 
                                                    && !sparse_lun)
459
 
                                                        break;  /* break means don't probe further for luns!=0 */
460
 
                                                if (SDpnt && (0 == lun)) {
461
 
                                                        int bflags = get_device_flags (scsi_result);
462
 
                                                        if (bflags & BLIST_LARGELUN)
463
 
                                                                lun0_sl = SCSI_3; /* treat as SCSI 3 */
464
 
                                                        else
465
 
                                                                lun0_sl = SDpnt->scsi_level;
466
 
                                                }
467
 
                                        }       /* for lun ends */
468
 
                                }       /* if this_id != id ends */
469
 
                        }       /* for dev ends */
470
 
                }               /* for channel ends */
471
 
        }                       /* if/else hardcoded */
472
 
 
473
 
      leave:
474
 
 
475
 
        {                       /* Unchain SRpnt from host_queue */
476
 
                Scsi_Device *prev, *next;
477
 
                Scsi_Device *dqptr;
478
 
 
479
 
                for (dqptr = shpnt->host_queue; dqptr != SDpnt; dqptr = dqptr->next)
480
 
                        continue;
481
 
                if (dqptr) {
482
 
                        prev = dqptr->prev;
483
 
                        next = dqptr->next;
484
 
                        if (prev)
485
 
                                prev->next = next;
486
 
                        else
487
 
                                shpnt->host_queue = next;
488
 
                        if (next)
489
 
                                next->prev = prev;
490
 
                }
491
 
        }
492
 
 
493
 
        /* Last device block does not exist.  Free memory. */
494
 
        if (SDpnt != NULL) {
495
 
                blk_cleanup_queue(&SDpnt->request_queue);
496
 
                kfree((char *) SDpnt);
497
 
        }
498
 
 
499
 
        /* If we allocated a buffer so we could do DMA, free it now */
500
 
        if (scsi_result != &scsi_result0[0] && scsi_result != NULL) {
501
 
                kfree(scsi_result);
502
 
        } {
503
 
                Scsi_Device *sdev;
504
 
                Scsi_Cmnd *scmd;
505
 
 
506
 
                SCSI_LOG_SCAN_BUS(4, printk("Host status for host %p:\n", shpnt));
507
 
                for (sdev = shpnt->host_queue; sdev; sdev = sdev->next) {
508
 
                        SCSI_LOG_SCAN_BUS(4, printk("Device %d %p: ", sdev->id, sdev));
509
 
                        for (scmd = sdev->device_queue; scmd; scmd = scmd->next) {
510
 
                                SCSI_LOG_SCAN_BUS(4, printk("%p ", scmd));
511
 
                        }
512
 
                        SCSI_LOG_SCAN_BUS(4, printk("\n"));
513
 
                }
514
 
        }
515
 
}
516
 
 
517
 
/*
518
 
 * The worker for scan_scsis.
519
 
 * Returning 0 means Please don't ask further for lun!=0, 1 means OK go on.
520
 
 * Global variables used : scsi_devices(linked list)
521
 
 */
522
 
static int scan_scsis_single(unsigned int channel, unsigned int dev,
523
 
                unsigned int lun, int lun0_scsi_level,
524
 
                unsigned int *max_dev_lun, unsigned int *sparse_lun, 
525
 
                Scsi_Device ** SDpnt2, struct Scsi_Host *shpnt, 
526
 
                char *scsi_result)
527
 
{
528
 
        char devname[64];
529
 
        unsigned char scsi_cmd[MAX_COMMAND_SIZE];
530
 
        struct Scsi_Device_Template *sdtpnt;
531
 
        Scsi_Device *SDtail, *SDpnt = *SDpnt2;
532
 
        Scsi_Request * SRpnt;
533
 
        int bflags, type = -1;
534
 
#ifdef DEVFS_MUST_DIE
535
 
        extern devfs_handle_t scsi_devfs_handle;
536
 
#endif
537
 
        int scsi_level;
538
 
 
539
 
        SDpnt->host = shpnt;
540
 
        SDpnt->id = dev;
541
 
        SDpnt->lun = lun;
542
 
        SDpnt->channel = channel;
543
 
        SDpnt->online = TRUE;
544
 
 
545
 
        scsi_build_commandblocks(SDpnt);
546
 
 
547
 
        /* Some low level driver could use device->type (DB) */
548
 
        SDpnt->type = -1;
549
 
 
550
 
        /*
551
 
         * Assume that the device will have handshaking problems, and then fix
552
 
         * this field later if it turns out it doesn't
553
 
         */
554
 
        SDpnt->borken = 1;
555
 
        SDpnt->was_reset = 0;
556
 
        SDpnt->expecting_cc_ua = 0;
557
 
        SDpnt->starved = 0;
558
 
 
559
 
        if (NULL == (SRpnt = scsi_allocate_request(SDpnt))) {
560
 
                printk("scan_scsis_single: no memory\n");
561
 
                return 0;
562
 
        }
563
 
 
564
 
        /*
565
 
         * We used to do a TEST_UNIT_READY before the INQUIRY but that was 
566
 
         * not really necessary.  Spec recommends using INQUIRY to scan for
567
 
         * devices (and TEST_UNIT_READY to poll for media change). - Paul G.
568
 
         */
569
 
 
570
 
        SCSI_LOG_SCAN_BUS(3, printk("scsi: performing INQUIRY\n"));
571
 
        /*
572
 
         * Build an INQUIRY command block.
573
 
         */
574
 
        scsi_cmd[0] = INQUIRY;
575
 
        if ((lun > 0) && (lun0_scsi_level <= SCSI_2))
576
 
                scsi_cmd[1] = (lun << 5) & 0xe0;
577
 
        else    
578
 
                scsi_cmd[1] = 0;        /* SCSI_3 and higher, don't touch */
579
 
        scsi_cmd[2] = 0;
580
 
        scsi_cmd[3] = 0;
581
 
        scsi_cmd[4] = 255;
582
 
        scsi_cmd[5] = 0;
583
 
        SRpnt->sr_cmd_len = 0;
584
 
        SRpnt->sr_data_direction = SCSI_DATA_READ;
585
 
 
586
 
        scsi_wait_req (SRpnt, (void *) scsi_cmd,
587
 
                  (void *) scsi_result,
588
 
                  256, SCSI_TIMEOUT+4*HZ, 3);
589
 
 
590
 
        SCSI_LOG_SCAN_BUS(3, printk("scsi: INQUIRY %s with code 0x%x\n",
591
 
                SRpnt->sr_result ? "failed" : "successful", SRpnt->sr_result));
592
 
 
593
 
        /*
594
 
         * Now that we don't do TEST_UNIT_READY anymore, we must be prepared
595
 
         * for media change conditions here, so cannot require zero result.
596
 
         */
597
 
        if (SRpnt->sr_result) {
598
 
                if ((driver_byte(SRpnt->sr_result) & DRIVER_SENSE) != 0 &&
599
 
                    (SRpnt->sr_sense_buffer[2] & 0xf) == UNIT_ATTENTION &&
600
 
                    SRpnt->sr_sense_buffer[12] == 0x28 &&
601
 
                    SRpnt->sr_sense_buffer[13] == 0) {
602
 
                        /* not-ready to ready transition - good */
603
 
                } else {
604
 
                        /* assume no peripheral if any other sort of error */
605
 
                        scsi_release_request(SRpnt);
606
 
                        return 0;
607
 
                }
608
 
        }
609
 
 
610
 
        /*
611
 
         * Check for SPARSELUN before checking the peripheral qualifier,
612
 
         * so sparse lun devices are completely scanned.
613
 
         */
614
 
 
615
 
        /*
616
 
         * Get any flags for this device.  
617
 
         */
618
 
        bflags = get_device_flags (scsi_result);
619
 
 
620
 
        if (bflags & BLIST_SPARSELUN) {
621
 
          *sparse_lun = 1;
622
 
        }
623
 
        /*
624
 
         * Check the peripheral qualifier field - this tells us whether LUNS
625
 
         * are supported here or not.
626
 
         */
627
 
        if ((scsi_result[0] >> 5) == 3) {
628
 
                scsi_release_request(SRpnt);
629
 
                return 0;       /* assume no peripheral if any sort of error */
630
 
        }
631
 
         /*   The Toshiba ROM was "gender-changed" here as an inline hack.
632
 
              This is now much more generic.
633
 
              This is a mess: What we really want is to leave the scsi_result
634
 
              alone, and just change the SDpnt structure. And the SDpnt is what
635
 
              we want print_inquiry to print.  -- REW
636
 
         */
637
 
        if (bflags & BLIST_ISDISK) {
638
 
                scsi_result[0] = TYPE_DISK;                                                
639
 
                scsi_result[1] |= 0x80;     /* removable */
640
 
        }
641
 
 
642
 
        if (bflags & BLIST_ISROM) {
643
 
                scsi_result[0] = TYPE_ROM;
644
 
                scsi_result[1] |= 0x80;     /* removable */
645
 
        }
646
 
    
647
 
        memcpy(SDpnt->vendor, scsi_result + 8, 8);
648
 
        memcpy(SDpnt->model, scsi_result + 16, 16);
649
 
        memcpy(SDpnt->rev, scsi_result + 32, 4);
650
 
 
651
 
        SDpnt->removable = (0x80 & scsi_result[1]) >> 7;
652
 
        /* Use the peripheral qualifier field to determine online/offline */
653
 
        if (((scsi_result[0] >> 5) & 7) == 1)   SDpnt->online = FALSE;
654
 
        else SDpnt->online = TRUE;
655
 
        SDpnt->lockable = SDpnt->removable;
656
 
        SDpnt->changed = 0;
657
 
        SDpnt->access_count = 0;
658
 
        SDpnt->busy = 0;
659
 
        SDpnt->has_cmdblocks = 0;
660
 
        /*
661
 
         * Currently, all sequential devices are assumed to be tapes, all random
662
 
         * devices disk, with the appropriate read only flags set for ROM / WORM
663
 
         * treated as RO.
664
 
         */
665
 
        switch (type = (scsi_result[0] & 0x1f)) {
666
 
        case TYPE_TAPE:
667
 
        case TYPE_DISK:
668
 
        case TYPE_PRINTER:
669
 
        case TYPE_MOD:
670
 
        case TYPE_PROCESSOR:
671
 
        case TYPE_SCANNER:
672
 
        case TYPE_MEDIUM_CHANGER:
673
 
        case TYPE_ENCLOSURE:
674
 
        case TYPE_COMM:
675
 
                SDpnt->writeable = 1;
676
 
                break;
677
 
        case TYPE_WORM:
678
 
        case TYPE_ROM:
679
 
                SDpnt->writeable = 0;
680
 
                break;
681
 
        default:
682
 
                printk("scsi: unknown type %d\n", type);
683
 
        }
684
 
 
685
 
        SDpnt->device_blocked = FALSE;
686
 
        SDpnt->device_busy = 0;
687
 
        SDpnt->single_lun = 0;
688
 
        SDpnt->soft_reset =
689
 
            (scsi_result[7] & 1) && ((scsi_result[3] & 7) == 2);
690
 
        SDpnt->random = (type == TYPE_TAPE) ? 0 : 1;
691
 
        SDpnt->type = (type & 0x1f);
692
 
 
693
 
        print_inquiry(scsi_result);
694
 
 
695
 
        sprintf (devname, "host%d/bus%d/target%d/lun%d",
696
 
                 SDpnt->host->host_no, SDpnt->channel, SDpnt->id, SDpnt->lun);
697
 
#ifdef DEVFS_MUST_DIE
698
 
        if (SDpnt->de) printk ("DEBUG: dir: \"%s\" already exists\n", devname);
699
 
        else SDpnt->de = devfs_mk_dir (scsi_devfs_handle, devname, NULL);
700
 
#endif
701
 
 
702
 
        for (sdtpnt = scsi_devicelist; sdtpnt;
703
 
             sdtpnt = sdtpnt->next)
704
 
                if (sdtpnt->detect)
705
 
                        SDpnt->attached +=
706
 
                            (*sdtpnt->detect) (SDpnt);
707
 
 
708
 
        SDpnt->scsi_level = scsi_result[2] & 0x07;
709
 
        if (SDpnt->scsi_level >= 2 ||
710
 
            (SDpnt->scsi_level == 1 &&
711
 
             (scsi_result[3] & 0x0f) == 1))
712
 
                SDpnt->scsi_level++;
713
 
        scsi_level = SDpnt->scsi_level;
714
 
 
715
 
        /*
716
 
         * Accommodate drivers that want to sleep when they should be in a polling
717
 
         * loop.
718
 
         */
719
 
        SDpnt->disconnect = 0;
720
 
 
721
 
 
722
 
        /*
723
 
         * Set the tagged_queue flag for SCSI-II devices that purport to support
724
 
         * tagged queuing in the INQUIRY data.
725
 
         */
726
 
        SDpnt->tagged_queue = 0;
727
 
        if ((SDpnt->scsi_level >= SCSI_2) &&
728
 
            (scsi_result[7] & 2) &&
729
 
            !(bflags & BLIST_NOTQ)) {
730
 
                SDpnt->tagged_supported = 1;
731
 
                SDpnt->current_tag = 0;
732
 
        }
733
 
        /*
734
 
         * Some revisions of the Texel CD ROM drives have handshaking problems when
735
 
         * used with the Seagate controllers.  Before we know what type of device
736
 
         * we're talking to, we assume it's borken and then change it here if it
737
 
         * turns out that it isn't a TEXEL drive.
738
 
         */
739
 
        if ((bflags & BLIST_BORKEN) == 0)
740
 
                SDpnt->borken = 0;
741
 
 
742
 
        /*
743
 
         * If we want to only allow I/O to one of the luns attached to this device
744
 
         * at a time, then we set this flag.
745
 
         */
746
 
        if (bflags & BLIST_SINGLELUN)
747
 
                SDpnt->single_lun = 1;
748
 
 
749
 
        /*
750
 
         * These devices need this "key" to unlock the devices so we can use it
751
 
         */
752
 
        if ((bflags & BLIST_KEY) != 0) {
753
 
                printk("Unlocked floptical drive.\n");
754
 
                SDpnt->lockable = 0;
755
 
                scsi_cmd[0] = MODE_SENSE;
756
 
                if (shpnt->max_lun <= 8)
757
 
                        scsi_cmd[1] = (lun << 5) & 0xe0;
758
 
                else    scsi_cmd[1] = 0;        /* any other idea? */
759
 
                scsi_cmd[2] = 0x2e;
760
 
                scsi_cmd[3] = 0;
761
 
                scsi_cmd[4] = 0x2a;
762
 
                scsi_cmd[5] = 0;
763
 
                SRpnt->sr_cmd_len = 0;
764
 
                SRpnt->sr_data_direction = SCSI_DATA_READ;
765
 
                scsi_wait_req (SRpnt, (void *) scsi_cmd,
766
 
                        (void *) scsi_result, 0x2a,
767
 
                        SCSI_TIMEOUT, 3);
768
 
        }
769
 
 
770
 
        scsi_release_request(SRpnt);
771
 
        SRpnt = NULL;
772
 
 
773
 
        scsi_release_commandblocks(SDpnt);
774
 
 
775
 
        /*
776
 
         * This device was already hooked up to the host in question,
777
 
         * so at this point we just let go of it and it should be fine.  We do need to
778
 
         * allocate a new one and attach it to the host so that we can further scan the bus.
779
 
         */
780
 
        SDpnt = (Scsi_Device *) kmalloc(sizeof(Scsi_Device), GFP_ATOMIC);
781
 
        if (!SDpnt) {
782
 
                printk("scsi: scan_scsis_single: Cannot malloc\n");
783
 
                return 0;
784
 
        }
785
 
        memset(SDpnt, 0, sizeof(Scsi_Device));
786
 
 
787
 
        *SDpnt2 = SDpnt;
788
 
        SDpnt->queue_depth = 1;
789
 
        SDpnt->host = shpnt;
790
 
        SDpnt->online = TRUE;
791
 
        SDpnt->scsi_level = scsi_level;
792
 
 
793
 
        /*
794
 
         * Register the queue for the device.  All I/O requests will come
795
 
         * in through here.  We also need to register a pointer to
796
 
         * ourselves, since the queue handler won't know what device
797
 
         * the queue actually represents.   We could look it up, but it
798
 
         * is pointless work.
799
 
         */
800
 
        scsi_initialize_queue(SDpnt, shpnt);
801
 
        SDpnt->host = shpnt;
802
 
        initialize_merge_fn(SDpnt);
803
 
 
804
 
        /*
805
 
         * Mark this device as online, or otherwise we won't be able to do much with it.
806
 
         */
807
 
        SDpnt->online = TRUE;
808
 
 
809
 
#if 0
810
 
        /*
811
 
         * Initialize the object that we will use to wait for command blocks.
812
 
         */
813
 
        init_waitqueue_head(&SDpnt->scpnt_wait);
814
 
#endif
815
 
 
816
 
        /*
817
 
         * Since we just found one device, there had damn well better be one in the list
818
 
         * already.
819
 
         */
820
 
        if (shpnt->host_queue == NULL)
821
 
                panic("scan_scsis_single: Host queue == NULL\n");
822
 
 
823
 
        SDtail = shpnt->host_queue;
824
 
        while (SDtail->next) {
825
 
                SDtail = SDtail->next;
826
 
        }
827
 
 
828
 
        /* Add this device to the linked list at the end */
829
 
        SDtail->next = SDpnt;
830
 
        SDpnt->prev = SDtail;
831
 
        SDpnt->next = NULL;
832
 
 
833
 
        /*
834
 
         * Some scsi devices cannot be polled for lun != 0 due to firmware bugs
835
 
         */
836
 
        if (bflags & BLIST_NOLUN)
837
 
                return 0;       /* break; */
838
 
 
839
 
        /*
840
 
         * If this device is known to support sparse multiple units, override the
841
 
         * other settings, and scan all of them.
842
 
         */
843
 
        if (bflags & BLIST_SPARSELUN) {
844
 
                *max_dev_lun = shpnt->max_lun;
845
 
                *sparse_lun = 1;
846
 
                return 1;
847
 
        }
848
 
        /*
849
 
         * If this device is known to support multiple units, override the other
850
 
         * settings, and scan all of them.
851
 
         */
852
 
        if (bflags & BLIST_FORCELUN) {
853
 
                /* 
854
 
                 * Scanning MAX_SCSI_LUNS units would be a bad idea.
855
 
                 * Any better idea?
856
 
                 * I think we need REPORT LUNS in future to avoid scanning
857
 
                 * of unused LUNs. But, that is another item.
858
 
                 */
859
 
                if (*max_dev_lun < shpnt->max_lun)
860
 
                        *max_dev_lun = shpnt->max_lun;
861
 
                else    if ((max_scsi_luns >> 1) >= *max_dev_lun)
862
 
                                *max_dev_lun += shpnt->max_lun;
863
 
                        else    *max_dev_lun = max_scsi_luns;
864
 
                return 1;
865
 
        }
866
 
        /*
867
 
         * REGAL CDC-4X: avoid hang after LUN 4
868
 
         */
869
 
        if (bflags & BLIST_MAX5LUN) {
870
 
                *max_dev_lun = 5;
871
 
                return 1;
872
 
        }
873
 
 
874
 
        /*
875
 
         * We assume the device can't handle lun!=0 if: - it reports scsi-0
876
 
         * (ANSI SCSI Revision 0) (old drives like MAXTOR XT-3280) or - it
877
 
         * reports scsi-1 (ANSI SCSI Revision 1) and Response Data Format 0
878
 
         */
879
 
        if (((scsi_result[2] & 0x07) == 0)
880
 
            ||
881
 
            ((scsi_result[2] & 0x07) == 1 &&
882
 
             (scsi_result[3] & 0x0f) == 0))
883
 
                return 0;
884
 
        return 1;
885
 
}
886
 
 
887
 
/*
888
 
 * The worker for scan_scsis.
889
 
 * Returns the scsi_level of lun0 on this host, channel and dev (if already
890
 
 * known), otherwise returns SCSI_2.
891
 
 */
892
 
static int find_lun0_scsi_level(unsigned int channel, unsigned int dev,
893
 
                                struct Scsi_Host *shpnt)
894
 
{
895
 
        int res = SCSI_2;
896
 
        Scsi_Device *SDpnt;
897
 
 
898
 
        for (SDpnt = shpnt->host_queue; SDpnt; SDpnt = SDpnt->next)
899
 
        {
900
 
                if ((0 == SDpnt->lun) && (dev == SDpnt->id) &&
901
 
                    (channel == SDpnt->channel))
902
 
                        return (int)SDpnt->scsi_level;
903
 
        }
904
 
        /* haven't found lun0, should send INQUIRY but take easy route */
905
 
        return res;
906
 
}