scsi_devinfo.c 28.8 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7 8

#include <linux/blkdev.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
9
#include <linux/slab.h>
Linus Torvalds's avatar
Linus Torvalds committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

#include <scsi/scsi_device.h>
#include <scsi/scsi_devinfo.h>

#include "scsi_priv.h"


/*
 * scsi_dev_info_list: structure to hold black/white listed devices.
 */
struct scsi_dev_info_list {
	struct list_head dev_info_list;
	char vendor[8];
	char model[16];
	unsigned flags;
	unsigned compatible; /* for use with scsi_static_device_list entries */
};

28 29 30 31 32 33 34
struct scsi_dev_info_list_table {
	struct list_head node;	/* our node for being on the master list */
	struct list_head scsi_dev_info_list; /* head of dev info list */
	const char *name;	/* name of list for /proc (NULL for global) */
	int key;		/* unique numeric identifier */
};

Linus Torvalds's avatar
Linus Torvalds committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

static unsigned scsi_default_dev_flags;
static LIST_HEAD(scsi_dev_info_list);
static char scsi_dev_flags[256];

/*
 * scsi_static_device_list: deprecated list of devices that require
 * settings that differ from the default, includes black-listed (broken)
 * devices. The entries here are added to the tail of scsi_dev_info_list
 * via scsi_dev_info_list_init.
 *
 * Do not add to this list, use the command line or proc interface to add
 * to the scsi_dev_info_list. This table will eventually go away.
 */
static struct {
	char *vendor;
	char *model;
	char *revision;	/* revision known to be bad, unused */
	unsigned flags;
} scsi_static_device_list[] __initdata = {
	/*
	 * The following devices are known not to tolerate a lun != 0 scan
	 * for one reason or another. Some will respond to all luns,
	 * others will lock up.
	 */
	{"Aashima", "IMAGERY 2400SP", "1.03", BLIST_NOLUN},	/* locks up */
	{"CHINON", "CD-ROM CDS-431", "H42", BLIST_NOLUN},	/* locks up */
	{"CHINON", "CD-ROM CDS-535", "Q14", BLIST_NOLUN},	/* locks up */
	{"DENON", "DRD-25X", "V", BLIST_NOLUN},			/* locks up */
	{"HITACHI", "DK312C", "CM81", BLIST_NOLUN},	/* responds to all lun */
	{"HITACHI", "DK314C", "CR21", BLIST_NOLUN},	/* responds to all lun */
66 67
	{"IBM", "2104-DU3", NULL, BLIST_NOLUN},		/* locks up */
	{"IBM", "2104-TU3", NULL, BLIST_NOLUN},		/* locks up */
Linus Torvalds's avatar
Linus Torvalds committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
	{"IMS", "CDD521/10", "2.06", BLIST_NOLUN},	/* locks up */
	{"MAXTOR", "XT-3280", "PR02", BLIST_NOLUN},	/* locks up */
	{"MAXTOR", "XT-4380S", "B3C", BLIST_NOLUN},	/* locks up */
	{"MAXTOR", "MXT-1240S", "I1.2", BLIST_NOLUN},	/* locks up */
	{"MAXTOR", "XT-4170S", "B5A", BLIST_NOLUN},	/* locks up */
	{"MAXTOR", "XT-8760S", "B7B", BLIST_NOLUN},	/* locks up */
	{"MEDIAVIS", "RENO CD-ROMX2A", "2.03", BLIST_NOLUN},	/* responds to all lun */
	{"MICROTEK", "ScanMakerIII", "2.30", BLIST_NOLUN},	/* responds to all lun */
	{"NEC", "CD-ROM DRIVE:841", "1.0", BLIST_NOLUN},/* locks up */
	{"PHILIPS", "PCA80SC", "V4-2", BLIST_NOLUN},	/* responds to all lun */
	{"RODIME", "RO3000S", "2.33", BLIST_NOLUN},	/* locks up */
	{"SUN", "SENA", NULL, BLIST_NOLUN},		/* responds to all luns */
	/*
	 * The following causes a failed REQUEST SENSE on lun 1 for
	 * aha152x controller, which causes SCSI code to reset bus.
	 */
	{"SANYO", "CRD-250S", "1.20", BLIST_NOLUN},
	/*
	 * The following causes a failed REQUEST SENSE on lun 1 for
	 * aha152x controller, which causes SCSI code to reset bus.
	 */
	{"SEAGATE", "ST157N", "\004|j", BLIST_NOLUN},
	{"SEAGATE", "ST296", "921", BLIST_NOLUN},	/* responds to all lun */
	{"SEAGATE", "ST1581", "6538", BLIST_NOLUN},	/* responds to all lun */
	{"SONY", "CD-ROM CDU-541", "4.3d", BLIST_NOLUN},
	{"SONY", "CD-ROM CDU-55S", "1.0i", BLIST_NOLUN},
	{"SONY", "CD-ROM CDU-561", "1.7x", BLIST_NOLUN},
	{"SONY", "CD-ROM CDU-8012", NULL, BLIST_NOLUN},
	{"SONY", "SDT-5000", "3.17", BLIST_SELECT_NO_ATN},
	{"TANDBERG", "TDC 3600", "U07", BLIST_NOLUN},	/* locks up */
	{"TEAC", "CD-R55S", "1.0H", BLIST_NOLUN},	/* locks up */
	/*
	 * The following causes a failed REQUEST SENSE on lun 1 for
	 * seagate controller, which causes SCSI code to reset bus.
	 */
	{"TEAC", "CD-ROM", "1.06", BLIST_NOLUN},
	{"TEAC", "MT-2ST/45S2-27", "RV M", BLIST_NOLUN},	/* responds to all lun */
	/*
	 * The following causes a failed REQUEST SENSE on lun 1 for
	 * seagate controller, which causes SCSI code to reset bus.
	 */
	{"HP", "C1750A", "3226", BLIST_NOLUN},		/* scanjet iic */
	{"HP", "C1790A", "", BLIST_NOLUN},		/* scanjet iip */
	{"HP", "C2500A", "", BLIST_NOLUN},		/* scanjet iicx */
	{"MEDIAVIS", "CDR-H93MV", "1.31", BLIST_NOLUN},	/* locks up */
	{"MICROTEK", "ScanMaker II", "5.61", BLIST_NOLUN},	/* responds to all lun */
	{"MITSUMI", "CD-R CR-2201CS", "6119", BLIST_NOLUN},	/* locks up */
	{"NEC", "D3856", "0009", BLIST_NOLUN},
	{"QUANTUM", "LPS525S", "3110", BLIST_NOLUN},	/* locks up */
	{"QUANTUM", "PD1225S", "3110", BLIST_NOLUN},	/* locks up */
	{"QUANTUM", "FIREBALL ST4.3S", "0F0C", BLIST_NOLUN},	/* locks up */
	{"RELISYS", "Scorpio", NULL, BLIST_NOLUN},	/* responds to all lun */
	{"SANKYO", "CP525", "6.64", BLIST_NOLUN},	/* causes failed REQ SENSE, extra reset */
	{"TEXEL", "CD-ROM", "1.06", BLIST_NOLUN},
122
	{"transtec", "T5008", "0001", BLIST_NOREPORTLUN },
Linus Torvalds's avatar
Linus Torvalds committed
123 124 125 126
	{"YAMAHA", "CDR100", "1.00", BLIST_NOLUN},	/* locks up */
	{"YAMAHA", "CDR102", "1.00", BLIST_NOLUN},	/* locks up */
	{"YAMAHA", "CRW8424S", "1.0", BLIST_NOLUN},	/* locks up */
	{"YAMAHA", "CRW6416S", "1.0c", BLIST_NOLUN},	/* locks up */
Dave Jones's avatar
Dave Jones committed
127
	{"", "Scanner", "1.80", BLIST_NOLUN},	/* responds to all lun */
Linus Torvalds's avatar
Linus Torvalds committed
128 129 130 131 132 133 134 135 136 137

	/*
	 * Other types of devices that have special flags.
	 * Note that all USB devices should have the BLIST_INQUIRY_36 flag.
	 */
	{"3PARdata", "VV", NULL, BLIST_REPORTLUN2},
	{"ADAPTEC", "AACRAID", NULL, BLIST_FORCELUN},
	{"ADAPTEC", "Adaptec 5400S", NULL, BLIST_FORCELUN},
	{"AFT PRO", "-IX CF", "0.0>", BLIST_FORCELUN},
	{"BELKIN", "USB 2 HS-CF", "1.95",  BLIST_FORCELUN | BLIST_INQUIRY_36},
138
	{"BROWNIE", "1200U3P", NULL, BLIST_NOREPORTLUN},
139
	{"BROWNIE", "1600U3P", NULL, BLIST_NOREPORTLUN},
Linus Torvalds's avatar
Linus Torvalds committed
140 141 142 143 144
	{"CANON", "IPUBJD", NULL, BLIST_SPARSELUN},
	{"CBOX3", "USB Storage-SMC", "300A", BLIST_FORCELUN | BLIST_INQUIRY_36},
	{"CMD", "CRA-7280", NULL, BLIST_SPARSELUN},	/* CMD RAID Controller */
	{"CNSI", "G7324", NULL, BLIST_SPARSELUN},	/* Chaparral G7324 RAID */
	{"CNSi", "G8324", NULL, BLIST_SPARSELUN},	/* Chaparral G8324 RAID */
145 146 147
	{"COMPAQ", "ARRAY CONTROLLER", NULL, BLIST_SPARSELUN | BLIST_LARGELUN |
		BLIST_MAX_512 | BLIST_REPORTLUN2},	/* Compaq RA4x00 */
	{"COMPAQ", "LOGICAL VOLUME", NULL, BLIST_FORCELUN | BLIST_MAX_512}, /* Compaq RA4x00 */
Linus Torvalds's avatar
Linus Torvalds committed
148 149 150 151 152
	{"COMPAQ", "CR3500", NULL, BLIST_FORCELUN},
	{"COMPAQ", "MSA1000", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD},
	{"COMPAQ", "MSA1000 VOLUME", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD},
	{"COMPAQ", "HSV110", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
	{"DDN", "SAN DataDirector", "*", BLIST_SPARSELUN},
153
	{"DEC", "HSG80", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
Linus Torvalds's avatar
Linus Torvalds committed
154 155 156 157 158 159 160
	{"DELL", "PV660F", NULL, BLIST_SPARSELUN},
	{"DELL", "PV660F   PSEUDO", NULL, BLIST_SPARSELUN},
	{"DELL", "PSEUDO DEVICE .", NULL, BLIST_SPARSELUN},	/* Dell PV 530F */
	{"DELL", "PV530F", NULL, BLIST_SPARSELUN},
	{"DELL", "PERCRAID", NULL, BLIST_FORCELUN},
	{"DGC", "RAID", NULL, BLIST_SPARSELUN},	/* Dell PV 650F, storage on LUN 0 */
	{"DGC", "DISK", NULL, BLIST_SPARSELUN},	/* Dell PV 650F, no storage on LUN 0 */
161
	{"EMC",  "Invista", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
162
	{"EMC", "SYMMETRIX", NULL, BLIST_SPARSELUN | BLIST_LARGELUN | BLIST_REPORTLUN2},
Linus Torvalds's avatar
Linus Torvalds committed
163
	{"EMULEX", "MD21/S2     ESDI", NULL, BLIST_SINGLELUN},
164 165 166
	{"easyRAID", "16P", NULL, BLIST_NOREPORTLUN},
	{"easyRAID", "X6P", NULL, BLIST_NOREPORTLUN},
	{"easyRAID", "F8", NULL, BLIST_NOREPORTLUN},
Linus Torvalds's avatar
Linus Torvalds committed
167 168 169 170
	{"FSC", "CentricStor", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
	{"Generic", "USB SD Reader", "1.00", BLIST_FORCELUN | BLIST_INQUIRY_36},
	{"Generic", "USB Storage-SMC", "0180", BLIST_FORCELUN | BLIST_INQUIRY_36},
	{"Generic", "USB Storage-SMC", "0207", BLIST_FORCELUN | BLIST_INQUIRY_36},
171 172 173
	{"HITACHI", "DF400", "*", BLIST_REPORTLUN2},
	{"HITACHI", "DF500", "*", BLIST_REPORTLUN2},
	{"HITACHI", "DISK-SUBSYSTEM", "*", BLIST_REPORTLUN2},
174
	{"HITACHI", "HUS1530", "*", BLIST_NO_DIF},
175
	{"HITACHI", "OPEN-", "*", BLIST_REPORTLUN2},
176 177 178 179 180
	{"HITACHI", "OP-C-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
	{"HITACHI", "3380-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
	{"HITACHI", "3390-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
	{"HITACHI", "6586-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
	{"HITACHI", "6588-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
Linus Torvalds's avatar
Linus Torvalds committed
181
	{"HP", "A6189A", NULL, BLIST_SPARSELUN | BLIST_LARGELUN},	/* HP VA7400 */
182
	{"HP", "OPEN-", "*", BLIST_REPORTLUN2 | BLIST_TRY_VPD_PAGES}, /* HP XP Arrays */
Linus Torvalds's avatar
Linus Torvalds committed
183 184 185 186
	{"HP", "NetRAID-4M", NULL, BLIST_FORCELUN},
	{"HP", "HSV100", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
	{"HP", "C1557A", NULL, BLIST_FORCELUN},
	{"HP", "C3323-300", "4269", BLIST_NOTQ},
187
	{"HP", "C5713A", NULL, BLIST_NOREPORTLUN},
188 189 190 191 192 193 194 195
	{"HP", "DF400", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
	{"HP", "DF500", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
	{"HP", "DF600", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
	{"HP", "OP-C-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
	{"HP", "3380-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
	{"HP", "3390-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
	{"HP", "6586-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
	{"HP", "6588-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
Linus Torvalds's avatar
Linus Torvalds committed
196 197 198 199
	{"IBM", "AuSaV1S2", NULL, BLIST_FORCELUN},
	{"IBM", "ProFibre 4000R", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
	{"IBM", "2105", NULL, BLIST_RETRY_HWERROR},
	{"iomega", "jaz 1GB", "J.86", BLIST_NOTQ | BLIST_NOLUN},
200
	{"IOMEGA", "ZIP", NULL, BLIST_NOTQ | BLIST_NOLUN},
Linus Torvalds's avatar
Linus Torvalds committed
201 202 203
	{"IOMEGA", "Io20S         *F", NULL, BLIST_KEY},
	{"INSITE", "Floptical   F*8I", NULL, BLIST_KEY},
	{"INSITE", "I325VM", NULL, BLIST_KEY},
204
	{"Intel", "Multi-Flex", NULL, BLIST_NO_RSOC},
Linus Torvalds's avatar
Linus Torvalds committed
205 206
	{"iRiver", "iFP Mass Driver", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
	{"LASOUND", "CDX7405", "3.10", BLIST_MAX5LUN | BLIST_SINGLELUN},
207
	{"Marvell", "Console", NULL, BLIST_SKIP_VPD_PAGES},
208
	{"Marvell", "91xx Config", "1.01", BLIST_SKIP_VPD_PAGES},
Linus Torvalds's avatar
Linus Torvalds committed
209 210 211 212 213 214
	{"MATSHITA", "PD-1", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
	{"MATSHITA", "DMC-LC5", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
	{"MATSHITA", "DMC-LC40", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
	{"Medion", "Flash XL  MMC/SD", "2.6D", BLIST_FORCELUN},
	{"MegaRAID", "LD", NULL, BLIST_FORCELUN},
	{"MICROP", "4110", NULL, BLIST_NOTQ},
215
	{"MSFT", "Virtual HD", NULL, BLIST_NO_RSOC},
Linus Torvalds's avatar
Linus Torvalds committed
216 217 218 219 220
	{"MYLEX", "DACARMRB", "*", BLIST_REPORTLUN2},
	{"nCipher", "Fastness Crypto", NULL, BLIST_FORCELUN},
	{"NAKAMICH", "MJ-4.8S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
	{"NAKAMICH", "MJ-5.16S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
	{"NEC", "PD-1 ODX654P", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
221
	{"NEC", "iStorage", NULL, BLIST_REPORTLUN2},
222 223
	{"NETAPP", "LUN C-Mode", NULL, BLIST_SYNC_ALUA},
	{"NETAPP", "INF-01-00", NULL, BLIST_SYNC_ALUA},
Linus Torvalds's avatar
Linus Torvalds committed
224 225 226 227 228
	{"NRC", "MBR-7", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
	{"NRC", "MBR-7.4", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
	{"PIONEER", "CD-ROM DRM-600", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
	{"PIONEER", "CD-ROM DRM-602X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
	{"PIONEER", "CD-ROM DRM-604X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
229
	{"PIONEER", "CD-ROM DRM-624X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
230
	{"Promise", "VTrak E610f", NULL, BLIST_SPARSELUN | BLIST_NO_RSOC},
Ed Lin's avatar
Ed Lin committed
231
	{"Promise", "", NULL, BLIST_SPARSELUN},
232
	{"QEMU", "QEMU CD-ROM", NULL, BLIST_SKIP_VPD_PAGES},
233
	{"QNAP", "iSCSI Storage", NULL, BLIST_MAX_1024},
234
	{"SYNOLOGY", "iSCSI Storage", NULL, BLIST_MAX_1024},
235
	{"QUANTUM", "XP34301", "1071", BLIST_NOTQ},
Linus Torvalds's avatar
Linus Torvalds committed
236 237 238 239
	{"REGAL", "CDC-4X", NULL, BLIST_MAX5LUN | BLIST_SINGLELUN},
	{"SanDisk", "ImageMate CF-SD1", NULL, BLIST_FORCELUN},
	{"SEAGATE", "ST34555N", "0930", BLIST_NOTQ},	/* Chokes on tagged INQUIRY */
	{"SEAGATE", "ST3390N", "9546", BLIST_NOTQ},
240
	{"SEAGATE", "ST900MM0006", NULL, BLIST_SKIP_VPD_PAGES},
Linus Torvalds's avatar
Linus Torvalds committed
241 242 243 244
	{"SGI", "RAID3", "*", BLIST_SPARSELUN},
	{"SGI", "RAID5", "*", BLIST_SPARSELUN},
	{"SGI", "TP9100", "*", BLIST_REPORTLUN2},
	{"SGI", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
245
	{"IBM", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
246
	{"SUN", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
247
	{"DELL", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
248 249 250 251
	{"STK", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
	{"NETAPP", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
	{"LSI", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
	{"ENGENIO", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
252
	{"LENOVO", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
Linus Torvalds's avatar
Linus Torvalds committed
253 254 255 256 257 258 259
	{"SMSC", "USB 2 HS-CF", NULL, BLIST_SPARSELUN | BLIST_INQUIRY_36},
	{"SONY", "CD-ROM CDU-8001", NULL, BLIST_BORKEN},
	{"SONY", "TSL", NULL, BLIST_FORCELUN},		/* DDS3 & DDS4 autoloaders */
	{"ST650211", "CF", NULL, BLIST_RETRY_HWERROR},
	{"SUN", "T300", "*", BLIST_SPARSELUN},
	{"SUN", "T4", "*", BLIST_SPARSELUN},
	{"TEXEL", "CD-ROM", "1.06", BLIST_BORKEN},
260
	{"Tornado-", "F4", "*", BLIST_NOREPORTLUN},
Linus Torvalds's avatar
Linus Torvalds committed
261 262
	{"TOSHIBA", "CDROM", NULL, BLIST_ISROM},
	{"TOSHIBA", "CD-ROM", NULL, BLIST_ISROM},
263
	{"Traxdata", "CDR4120", NULL, BLIST_NOLUN},	/* locks up */
Linus Torvalds's avatar
Linus Torvalds committed
264 265 266 267 268 269 270 271 272 273 274
	{"USB2.0", "SMARTMEDIA/XD", NULL, BLIST_FORCELUN | BLIST_INQUIRY_36},
	{"WangDAT", "Model 2600", "01.7", BLIST_SELECT_NO_ATN},
	{"WangDAT", "Model 3200", "02.2", BLIST_SELECT_NO_ATN},
	{"WangDAT", "Model 1300", "02.4", BLIST_SELECT_NO_ATN},
	{"WDC WD25", "00JB-00FUA0", NULL, BLIST_NOREPORTLUN},
	{"XYRATEX", "RS", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
	{"Zzyzx", "RocketStor 500S", NULL, BLIST_SPARSELUN},
	{"Zzyzx", "RocketStor 2000", NULL, BLIST_SPARSELUN},
	{ NULL, NULL, NULL, 0 },
};

275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
static struct scsi_dev_info_list_table *scsi_devinfo_lookup_by_key(int key)
{
	struct scsi_dev_info_list_table *devinfo_table;
	int found = 0;

	list_for_each_entry(devinfo_table, &scsi_dev_info_list, node)
		if (devinfo_table->key == key) {
			found = 1;
			break;
		}
	if (!found)
		return ERR_PTR(-EINVAL);

	return devinfo_table;
}

Linus Torvalds's avatar
Linus Torvalds committed
291 292 293 294 295 296 297 298 299 300
/*
 * scsi_strcpy_devinfo: called from scsi_dev_info_list_add to copy into
 * devinfo vendor and model strings.
 */
static void scsi_strcpy_devinfo(char *name, char *to, size_t to_length,
				char *from, int compatible)
{
	size_t from_length;

	from_length = strlen(from);
301 302 303 304 305 306 307
	/* this zero-pads the destination */
	strncpy(to, from, to_length);
	if (from_length < to_length && !compatible) {
		/*
		 * space pad the string if it is short.
		 */
		memset(&to[from_length], ' ', to_length - from_length);
Linus Torvalds's avatar
Linus Torvalds committed
308 309 310
	}
	if (from_length > to_length)
		 printk(KERN_WARNING "%s: %s string '%s' is too long\n",
311
			__func__, name, from);
Linus Torvalds's avatar
Linus Torvalds committed
312 313 314
}

/**
315 316
 * scsi_dev_info_list_add - add one dev_info list entry.
 * @compatible: if true, null terminate short strings.  Otherwise space pad.
Linus Torvalds's avatar
Linus Torvalds committed
317 318 319
 * @vendor:	vendor string
 * @model:	model (product) string
 * @strflags:	integer string
320
 * @flags:	if strflags NULL, use this flag value
Linus Torvalds's avatar
Linus Torvalds committed
321 322 323 324 325 326 327 328 329 330 331
 *
 * Description:
 * 	Create and add one dev_info entry for @vendor, @model, @strflags or
 * 	@flag. If @compatible, add to the tail of the list, do not space
 * 	pad, and set devinfo->compatible. The scsi_static_device_list entries
 * 	are added with @compatible 1 and @clfags NULL.
 *
 * Returns: 0 OK, -error on failure.
 **/
static int scsi_dev_info_list_add(int compatible, char *vendor, char *model,
			    char *strflags, int flags)
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
{
	return scsi_dev_info_list_add_keyed(compatible, vendor, model,
					    strflags, flags,
					    SCSI_DEVINFO_GLOBAL);
}

/**
 * scsi_dev_info_list_add_keyed - add one dev_info list entry.
 * @compatible: if true, null terminate short strings.  Otherwise space pad.
 * @vendor:	vendor string
 * @model:	model (product) string
 * @strflags:	integer string
 * @flags:	if strflags NULL, use this flag value
 * @key:	specify list to use
 *
 * Description:
 * 	Create and add one dev_info entry for @vendor, @model,
 * 	@strflags or @flag in list specified by @key. If @compatible,
 * 	add to the tail of the list, do not space pad, and set
 * 	devinfo->compatible. The scsi_static_device_list entries are
 * 	added with @compatible 1 and @clfags NULL.
 *
 * Returns: 0 OK, -error on failure.
 **/
int scsi_dev_info_list_add_keyed(int compatible, char *vendor, char *model,
				 char *strflags, int flags, int key)
Linus Torvalds's avatar
Linus Torvalds committed
358 359
{
	struct scsi_dev_info_list *devinfo;
360 361 362 363 364
	struct scsi_dev_info_list_table *devinfo_table =
		scsi_devinfo_lookup_by_key(key);

	if (IS_ERR(devinfo_table))
		return PTR_ERR(devinfo_table);
Linus Torvalds's avatar
Linus Torvalds committed
365 366 367

	devinfo = kmalloc(sizeof(*devinfo), GFP_KERNEL);
	if (!devinfo) {
368
		printk(KERN_ERR "%s: no memory\n", __func__);
Linus Torvalds's avatar
Linus Torvalds committed
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
		return -ENOMEM;
	}

	scsi_strcpy_devinfo("vendor", devinfo->vendor, sizeof(devinfo->vendor),
			    vendor, compatible);
	scsi_strcpy_devinfo("model", devinfo->model, sizeof(devinfo->model),
			    model, compatible);

	if (strflags)
		devinfo->flags = simple_strtoul(strflags, NULL, 0);
	else
		devinfo->flags = flags;

	devinfo->compatible = compatible;

	if (compatible)
385 386
		list_add_tail(&devinfo->dev_info_list,
			      &devinfo_table->scsi_dev_info_list);
Linus Torvalds's avatar
Linus Torvalds committed
387
	else
388 389
		list_add(&devinfo->dev_info_list,
			 &devinfo_table->scsi_dev_info_list);
Linus Torvalds's avatar
Linus Torvalds committed
390 391 392

	return 0;
}
393
EXPORT_SYMBOL(scsi_dev_info_list_add_keyed);
Linus Torvalds's avatar
Linus Torvalds committed
394

395
/**
396
 * scsi_dev_info_list_find - find a matching dev_info list entry.
397 398
 * @vendor:	full vendor string
 * @model:	full model (product) string
399 400 401
 * @key:	specify list to use
 *
 * Description:
402
 *	Finds the first dev_info entry matching @vendor, @model
403 404
 * 	in list specified by @key.
 *
405
 * Returns: pointer to matching entry, or ERR_PTR on failure.
406
 **/
407 408
static struct scsi_dev_info_list *scsi_dev_info_list_find(const char *vendor,
		const char *model, int key)
409
{
410
	struct scsi_dev_info_list *devinfo;
411 412
	struct scsi_dev_info_list_table *devinfo_table =
		scsi_devinfo_lookup_by_key(key);
413
	size_t vmax, mmax, mlen;
414
	const char *vskip, *mskip;
415 416

	if (IS_ERR(devinfo_table))
417
		return (struct scsi_dev_info_list *) devinfo_table;
418

419 420 421 422 423 424 425 426 427 428
	/* Prepare for "compatible" matches */

	/*
	 * XXX why skip leading spaces? If an odd INQUIRY
	 * value, that should have been part of the
	 * scsi_static_device_list[] entry, such as "  FOO"
	 * rather than "FOO". Since this code is already
	 * here, and we don't know what device it is
	 * trying to work with, leave it as-is.
	 */
429
	vmax = sizeof(devinfo->vendor);
430 431 432 433 434 435 436 437 438
	vskip = vendor;
	while (vmax > 0 && *vskip == ' ') {
		vmax--;
		vskip++;
	}
	/* Also skip trailing spaces */
	while (vmax > 0 && vskip[vmax - 1] == ' ')
		--vmax;

439
	mmax = sizeof(devinfo->model);
440 441 442 443 444 445 446 447
	mskip = model;
	while (mmax > 0 && *mskip == ' ') {
		mmax--;
		mskip++;
	}
	while (mmax > 0 && mskip[mmax - 1] == ' ')
		--mmax;

448 449 450 451
	list_for_each_entry(devinfo, &devinfo_table->scsi_dev_info_list,
			    dev_info_list) {
		if (devinfo->compatible) {
			/*
452
			 * vendor strings must be an exact match
453
			 */
454 455
			if (vmax != strnlen(devinfo->vendor,
					    sizeof(devinfo->vendor)) ||
456
			    memcmp(devinfo->vendor, vskip, vmax))
457
				continue;
458 459 460 461 462

			/*
			 * @model specifies the full string, and
			 * must be larger or equal to devinfo->model
			 */
463
			mlen = strnlen(devinfo->model, sizeof(devinfo->model));
464
			if (mmax < mlen || memcmp(devinfo->model, mskip, mlen))
465
				continue;
466
			return devinfo;
467 468 469 470 471
		} else {
			if (!memcmp(devinfo->vendor, vendor,
				     sizeof(devinfo->vendor)) &&
			     !memcmp(devinfo->model, model,
				      sizeof(devinfo->model)))
472
				return devinfo;
473 474 475
		}
	}

476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
	return ERR_PTR(-ENOENT);
}

/**
 * scsi_dev_info_list_del_keyed - remove one dev_info list entry.
 * @vendor:	vendor string
 * @model:	model (product) string
 * @key:	specify list to use
 *
 * Description:
 *	Remove and destroy one dev_info entry for @vendor, @model
 *	in list specified by @key.
 *
 * Returns: 0 OK, -error on failure.
 **/
int scsi_dev_info_list_del_keyed(char *vendor, char *model, int key)
{
	struct scsi_dev_info_list *found;
494

495 496 497 498 499 500 501
	found = scsi_dev_info_list_find(vendor, model, key);
	if (IS_ERR(found))
		return PTR_ERR(found);

	list_del(&found->dev_info_list);
	kfree(found);
	return 0;
502 503 504
}
EXPORT_SYMBOL(scsi_dev_info_list_del_keyed);

Linus Torvalds's avatar
Linus Torvalds committed
505
/**
506
 * scsi_dev_info_list_add_str - parse dev_list and add to the scsi_dev_info_list.
Linus Torvalds's avatar
Linus Torvalds committed
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
 * @dev_list:	string of device flags to add
 *
 * Description:
 * 	Parse dev_list, and add entries to the scsi_dev_info_list.
 * 	dev_list is of the form "vendor:product:flag,vendor:product:flag".
 * 	dev_list is modified via strsep. Can be called for command line
 * 	addition, for proc or mabye a sysfs interface.
 *
 * Returns: 0 if OK, -error on failure.
 **/
static int scsi_dev_info_list_add_str(char *dev_list)
{
	char *vendor, *model, *strflags, *next;
	char *next_check;
	int res = 0;

	next = dev_list;
	if (next && next[0] == '"') {
		/*
		 * Ignore both the leading and trailing quote.
		 */
		next++;
		next_check = ",\"";
	} else {
		next_check = ",";
	}

	/*
	 * For the leading and trailing '"' case, the for loop comes
	 * through the last time with vendor[0] == '\0'.
	 */
	for (vendor = strsep(&next, ":"); vendor && (vendor[0] != '\0')
	     && (res == 0); vendor = strsep(&next, ":")) {
		strflags = NULL;
		model = strsep(&next, ":");
		if (model)
			strflags = strsep(&next, next_check);
		if (!model || !strflags) {
			printk(KERN_ERR "%s: bad dev info string '%s' '%s'"
546
			       " '%s'\n", __func__, vendor, model,
Linus Torvalds's avatar
Linus Torvalds committed
547 548 549 550 551 552 553 554 555 556
			       strflags);
			res = -EINVAL;
		} else
			res = scsi_dev_info_list_add(0 /* compatible */, vendor,
						     model, strflags, 0);
	}
	return res;
}

/**
557 558
 * get_device_flags - get device specific flags from the dynamic device list.
 * @sdev:       &scsi_device to get flags for
Linus Torvalds's avatar
Linus Torvalds committed
559 560 561 562
 * @vendor:	vendor name
 * @model:	model name
 *
 * Description:
563 564 565 566
 *     Search the global scsi_dev_info_list (specified by list zero)
 *     for an entry matching @vendor and @model, if found, return the
 *     matching flags value, else return the host or global default
 *     settings.  Called during scan time.
Linus Torvalds's avatar
Linus Torvalds committed
567
 **/
568 569 570
int scsi_get_device_flags(struct scsi_device *sdev,
			  const unsigned char *vendor,
			  const unsigned char *model)
571 572 573 574 575 576 577
{
	return scsi_get_device_flags_keyed(sdev, vendor, model,
					   SCSI_DEVINFO_GLOBAL);
}


/**
578
 * scsi_get_device_flags_keyed - get device specific flags from the dynamic device list
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
 * @sdev:       &scsi_device to get flags for
 * @vendor:	vendor name
 * @model:	model name
 * @key:	list to look up
 *
 * Description:
 *     Search the scsi_dev_info_list specified by @key for an entry
 *     matching @vendor and @model, if found, return the matching
 *     flags value, else return the host or global default settings.
 *     Called during scan time.
 **/
int scsi_get_device_flags_keyed(struct scsi_device *sdev,
				const unsigned char *vendor,
				const unsigned char *model,
				int key)
Linus Torvalds's avatar
Linus Torvalds committed
594 595
{
	struct scsi_dev_info_list *devinfo;
596

597 598 599
	devinfo = scsi_dev_info_list_find(vendor, model, key);
	if (!IS_ERR(devinfo))
		return devinfo->flags;
Linus Torvalds's avatar
Linus Torvalds committed
600

601
	/* key or device not found: return nothing */
602 603 604 605 606 607 608 609
	if (key != SCSI_DEVINFO_GLOBAL)
		return 0;

	/* except for the global list, where we have an exception */
	if (sdev->sdev_bflags)
		return sdev->sdev_bflags;

	return scsi_default_dev_flags;
Linus Torvalds's avatar
Linus Torvalds committed
610
}
611
EXPORT_SYMBOL(scsi_get_device_flags_keyed);
Linus Torvalds's avatar
Linus Torvalds committed
612 613

#ifdef CONFIG_SCSI_PROC_FS
614 615 616 617 618
struct double_list {
	struct list_head *top;
	struct list_head *bottom;
};

619
static int devinfo_seq_show(struct seq_file *m, void *v)
Linus Torvalds's avatar
Linus Torvalds committed
620
{
621 622 623
	struct double_list *dl = v;
	struct scsi_dev_info_list_table *devinfo_table =
		list_entry(dl->top, struct scsi_dev_info_list_table, node);
624
	struct scsi_dev_info_list *devinfo =
625 626 627 628 629 630
		list_entry(dl->bottom, struct scsi_dev_info_list,
			   dev_info_list);

	if (devinfo_table->scsi_dev_info_list.next == dl->bottom &&
	    devinfo_table->name)
		seq_printf(m, "[%s]:\n", devinfo_table->name);
Linus Torvalds's avatar
Linus Torvalds committed
631

632
	seq_printf(m, "'%.8s' '%.16s' 0x%x\n",
633
		   devinfo->vendor, devinfo->model, devinfo->flags);
634 635 636
	return 0;
}

637
static void *devinfo_seq_start(struct seq_file *m, loff_t *ppos)
638
{
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
	struct double_list *dl = kmalloc(sizeof(*dl), GFP_KERNEL);
	loff_t pos = *ppos;

	if (!dl)
		return NULL;

	list_for_each(dl->top, &scsi_dev_info_list) {
		struct scsi_dev_info_list_table *devinfo_table =
			list_entry(dl->top, struct scsi_dev_info_list_table,
				   node);
		list_for_each(dl->bottom, &devinfo_table->scsi_dev_info_list)
			if (pos-- == 0)
				return dl;
	}

	kfree(dl);
	return NULL;
656
}
Linus Torvalds's avatar
Linus Torvalds committed
657

658
static void *devinfo_seq_next(struct seq_file *m, void *v, loff_t *ppos)
659
{
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
	struct double_list *dl = v;
	struct scsi_dev_info_list_table *devinfo_table =
		list_entry(dl->top, struct scsi_dev_info_list_table, node);

	++*ppos;
	dl->bottom = dl->bottom->next;
	while (&devinfo_table->scsi_dev_info_list == dl->bottom) {
		dl->top = dl->top->next;
		if (dl->top == &scsi_dev_info_list) {
			kfree(dl);
			return NULL;
		}
		devinfo_table = list_entry(dl->top,
					   struct scsi_dev_info_list_table,
					   node);
		dl->bottom = devinfo_table->scsi_dev_info_list.next;
	}

	return dl;
679 680 681 682
}

static void devinfo_seq_stop(struct seq_file *m, void *v)
{
683
	kfree(v);
684 685 686 687 688 689 690 691 692 693 694 695
}

static const struct seq_operations scsi_devinfo_seq_ops = {
	.start	= devinfo_seq_start,
	.next	= devinfo_seq_next,
	.stop	= devinfo_seq_stop,
	.show	= devinfo_seq_show,
};

static int proc_scsi_devinfo_open(struct inode *inode, struct file *file)
{
	return seq_open(file, &scsi_devinfo_seq_ops);
Linus Torvalds's avatar
Linus Torvalds committed
696 697 698
}

/* 
699
 * proc_scsi_dev_info_write - allow additions to scsi_dev_info_list via /proc.
Linus Torvalds's avatar
Linus Torvalds committed
700
 *
701 702 703
 * Description: Adds a black/white list entry for vendor and model with an
 * integer value of flag to the scsi device info list.
 * To use, echo "vendor:model:flag" > /proc/scsi/device_info
Linus Torvalds's avatar
Linus Torvalds committed
704
 */
705 706 707
static ssize_t proc_scsi_devinfo_write(struct file *file,
				       const char __user *buf,
				       size_t length, loff_t *ppos)
Linus Torvalds's avatar
Linus Torvalds committed
708 709
{
	char *buffer;
710
	ssize_t err = length;
Linus Torvalds's avatar
Linus Torvalds committed
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733

	if (!buf || length>PAGE_SIZE)
		return -EINVAL;
	if (!(buffer = (char *) __get_free_page(GFP_KERNEL)))
		return -ENOMEM;
	if (copy_from_user(buffer, buf, length)) {
		err =-EFAULT;
		goto out;
	}

	if (length < PAGE_SIZE)
		buffer[length] = '\0';
	else if (buffer[PAGE_SIZE-1]) {
		err = -EINVAL;
		goto out;
	}

	scsi_dev_info_list_add_str(buffer);

out:
	free_page((unsigned long)buffer);
	return err;
}
734 735 736 737 738 739 740 741 742

static const struct file_operations scsi_devinfo_proc_fops = {
	.owner		= THIS_MODULE,
	.open		= proc_scsi_devinfo_open,
	.read		= seq_read,
	.write		= proc_scsi_devinfo_write,
	.llseek		= seq_lseek,
	.release	= seq_release,
};
Linus Torvalds's avatar
Linus Torvalds committed
743 744 745 746 747 748 749 750 751 752 753 754 755
#endif /* CONFIG_SCSI_PROC_FS */

module_param_string(dev_flags, scsi_dev_flags, sizeof(scsi_dev_flags), 0);
MODULE_PARM_DESC(dev_flags,
	 "Given scsi_dev_flags=vendor:model:flags[,v:m:f] add black/white"
	 " list entries for vendor and model with an integer value of flags"
	 " to the scsi device info list");

module_param_named(default_dev_flags, scsi_default_dev_flags, int, S_IRUGO|S_IWUSR);
MODULE_PARM_DESC(default_dev_flags,
		 "scsi default device flag integer value");

/**
756
 * scsi_exit_devinfo - remove /proc/scsi/device_info & the scsi_dev_info_list
Linus Torvalds's avatar
Linus Torvalds committed
757 758 759 760 761 762 763
 **/
void scsi_exit_devinfo(void)
{
#ifdef CONFIG_SCSI_PROC_FS
	remove_proc_entry("scsi/device_info", NULL);
#endif

764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822
	scsi_dev_info_remove_list(SCSI_DEVINFO_GLOBAL);
}

/**
 * scsi_dev_info_add_list - add a new devinfo list
 * @key:	key of the list to add
 * @name:	Name of the list to add (for /proc/scsi/device_info)
 *
 * Adds the requested list, returns zero on success, -EEXIST if the
 * key is already registered to a list, or other error on failure.
 */
int scsi_dev_info_add_list(int key, const char *name)
{
	struct scsi_dev_info_list_table *devinfo_table =
		scsi_devinfo_lookup_by_key(key);

	if (!IS_ERR(devinfo_table))
		/* list already exists */
		return -EEXIST;

	devinfo_table = kmalloc(sizeof(*devinfo_table), GFP_KERNEL);

	if (!devinfo_table)
		return -ENOMEM;

	INIT_LIST_HEAD(&devinfo_table->node);
	INIT_LIST_HEAD(&devinfo_table->scsi_dev_info_list);
	devinfo_table->name = name;
	devinfo_table->key = key;
	list_add_tail(&devinfo_table->node, &scsi_dev_info_list);

	return 0;
}
EXPORT_SYMBOL(scsi_dev_info_add_list);

/**
 * scsi_dev_info_remove_list - destroy an added devinfo list
 * @key: key of the list to destroy
 *
 * Iterates over the entire list first, freeing all the values, then
 * frees the list itself.  Returns 0 on success or -EINVAL if the key
 * can't be found.
 */
int scsi_dev_info_remove_list(int key)
{
	struct list_head *lh, *lh_next;
	struct scsi_dev_info_list_table *devinfo_table =
		scsi_devinfo_lookup_by_key(key);

	if (IS_ERR(devinfo_table))
		/* no such list */
		return -EINVAL;

	/* remove from the master list */
	list_del(&devinfo_table->node);

	list_for_each_safe(lh, lh_next, &devinfo_table->scsi_dev_info_list) {
		struct scsi_dev_info_list *devinfo;

Linus Torvalds's avatar
Linus Torvalds committed
823 824 825 826
		devinfo = list_entry(lh, struct scsi_dev_info_list,
				     dev_info_list);
		kfree(devinfo);
	}
827 828 829
	kfree(devinfo_table);

	return 0;
Linus Torvalds's avatar
Linus Torvalds committed
830
}
831
EXPORT_SYMBOL(scsi_dev_info_remove_list);
Linus Torvalds's avatar
Linus Torvalds committed
832 833

/**
834
 * scsi_init_devinfo - set up the dynamic device list.
Linus Torvalds's avatar
Linus Torvalds committed
835 836
 *
 * Description:
837
 * 	Add command line entries from scsi_dev_flags, then add
Linus Torvalds's avatar
Linus Torvalds committed
838
 * 	scsi_static_device_list entries to the scsi device info list.
839
 */
Linus Torvalds's avatar
Linus Torvalds committed
840 841 842 843 844 845 846
int __init scsi_init_devinfo(void)
{
#ifdef CONFIG_SCSI_PROC_FS
	struct proc_dir_entry *p;
#endif
	int error, i;

847
	error = scsi_dev_info_add_list(SCSI_DEVINFO_GLOBAL, NULL);
Linus Torvalds's avatar
Linus Torvalds committed
848 849 850
	if (error)
		return error;

851 852 853 854
	error = scsi_dev_info_list_add_str(scsi_dev_flags);
	if (error)
		goto out;

Linus Torvalds's avatar
Linus Torvalds committed
855 856 857 858 859 860 861 862 863 864 865
	for (i = 0; scsi_static_device_list[i].vendor; i++) {
		error = scsi_dev_info_list_add(1 /* compatibile */,
				scsi_static_device_list[i].vendor,
				scsi_static_device_list[i].model,
				NULL,
				scsi_static_device_list[i].flags);
		if (error)
			goto out;
	}

#ifdef CONFIG_SCSI_PROC_FS
866
	p = proc_create("scsi/device_info", 0, NULL, &scsi_devinfo_proc_fops);
Linus Torvalds's avatar
Linus Torvalds committed
867 868 869 870 871 872 873 874 875 876 877
	if (!p) {
		error = -ENOMEM;
		goto out;
	}
#endif /* CONFIG_SCSI_PROC_FS */

 out:
	if (error)
		scsi_exit_devinfo();
	return error;
}