Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 174373
Collapse All | Expand All

(-)a/drivers/scsi/constants.c (-122 / +145 lines)
Lines 202-232 static const char * get_sa_name(const struct value_name_pair * arr, Link Here
202
}
202
}
203
203
204
/* attempt to guess cdb length if cdb_len==0 . No trailing linefeed. */
204
/* attempt to guess cdb length if cdb_len==0 . No trailing linefeed. */
205
static void print_opcode_name(unsigned char * cdbp, int cdb_len,
205
static void print_opcode_name(unsigned char * cdbp, int cdb_len)
206
			      int start_of_line)
207
{
206
{
208
	int sa, len, cdb0;
207
	int sa, len, cdb0;
209
	const char * name;
208
	const char * name;
210
	const char * leadin = start_of_line ? KERN_INFO : "";
211
209
212
	cdb0 = cdbp[0];
210
	cdb0 = cdbp[0];
213
	switch(cdb0) {
211
	switch(cdb0) {
214
	case VARIABLE_LENGTH_CMD:
212
	case VARIABLE_LENGTH_CMD:
215
		len = cdbp[7] + 8;
213
		len = cdbp[7] + 8;
216
		if (len < 10) {
214
		if (len < 10) {
217
			printk("%sshort variable length command, "
215
			printk("short variable length command, "
218
			       "len=%d ext_len=%d", leadin, len, cdb_len);
216
			       "len=%d ext_len=%d", len, cdb_len);
219
			break;
217
			break;
220
		}
218
		}
221
		sa = (cdbp[8] << 8) + cdbp[9];
219
		sa = (cdbp[8] << 8) + cdbp[9];
222
		name = get_sa_name(maint_in_arr, MAINT_IN_SZ, sa);
220
		name = get_sa_name(maint_in_arr, MAINT_IN_SZ, sa);
223
		if (name) {
221
		if (name) {
224
			printk("%s%s", leadin, name);
222
			printk("%s", name);
225
			if ((cdb_len > 0) && (len != cdb_len))
223
			if ((cdb_len > 0) && (len != cdb_len))
226
				printk(", in_cdb_len=%d, ext_len=%d",
224
				printk(", in_cdb_len=%d, ext_len=%d",
227
				       len, cdb_len);
225
				       len, cdb_len);
228
		} else {
226
		} else {
229
			printk("%scdb[0]=0x%x, sa=0x%x", leadin, cdb0, sa);
227
			printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
230
			if ((cdb_len > 0) && (len != cdb_len))
228
			if ((cdb_len > 0) && (len != cdb_len))
231
				printk(", in_cdb_len=%d, ext_len=%d",
229
				printk(", in_cdb_len=%d, ext_len=%d",
232
				       len, cdb_len);
230
				       len, cdb_len);
Lines 236-318 static void print_opcode_name(unsigned char * cdbp, int cdb_len, Link Here
236
		sa = cdbp[1] & 0x1f;
234
		sa = cdbp[1] & 0x1f;
237
		name = get_sa_name(maint_in_arr, MAINT_IN_SZ, sa);
235
		name = get_sa_name(maint_in_arr, MAINT_IN_SZ, sa);
238
		if (name)
236
		if (name)
239
			printk("%s%s", leadin, name);
237
			printk("%s", name);
240
		else
238
		else
241
			printk("%scdb[0]=0x%x, sa=0x%x", leadin, cdb0, sa);
239
			printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
242
		break;
240
		break;
243
	case MAINTENANCE_OUT:
241
	case MAINTENANCE_OUT:
244
		sa = cdbp[1] & 0x1f;
242
		sa = cdbp[1] & 0x1f;
245
		name = get_sa_name(maint_out_arr, MAINT_OUT_SZ, sa);
243
		name = get_sa_name(maint_out_arr, MAINT_OUT_SZ, sa);
246
		if (name)
244
		if (name)
247
			printk("%s%s", leadin, name);
245
			printk("%s", name);
248
		else
246
		else
249
			printk("%scdb[0]=0x%x, sa=0x%x", leadin, cdb0, sa);
247
			printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
250
		break;
248
		break;
251
	case SERVICE_ACTION_IN_12:
249
	case SERVICE_ACTION_IN_12:
252
		sa = cdbp[1] & 0x1f;
250
		sa = cdbp[1] & 0x1f;
253
		name = get_sa_name(serv_in12_arr, SERV_IN12_SZ, sa);
251
		name = get_sa_name(serv_in12_arr, SERV_IN12_SZ, sa);
254
		if (name)
252
		if (name)
255
			printk("%s%s", leadin, name);
253
			printk("%s", name);
256
		else
254
		else
257
			printk("%scdb[0]=0x%x, sa=0x%x", leadin, cdb0, sa);
255
			printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
258
		break;
256
		break;
259
	case SERVICE_ACTION_OUT_12:
257
	case SERVICE_ACTION_OUT_12:
260
		sa = cdbp[1] & 0x1f;
258
		sa = cdbp[1] & 0x1f;
261
		name = get_sa_name(serv_out12_arr, SERV_OUT12_SZ, sa);
259
		name = get_sa_name(serv_out12_arr, SERV_OUT12_SZ, sa);
262
		if (name)
260
		if (name)
263
			printk("%s%s", leadin, name);
261
			printk("%s", name);
264
		else
262
		else
265
			printk("%scdb[0]=0x%x, sa=0x%x", leadin, cdb0, sa);
263
			printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
266
		break;
264
		break;
267
	case SERVICE_ACTION_IN_16:
265
	case SERVICE_ACTION_IN_16:
268
		sa = cdbp[1] & 0x1f;
266
		sa = cdbp[1] & 0x1f;
269
		name = get_sa_name(serv_in16_arr, SERV_IN16_SZ, sa);
267
		name = get_sa_name(serv_in16_arr, SERV_IN16_SZ, sa);
270
		if (name)
268
		if (name)
271
			printk("%s%s", leadin, name);
269
			printk("%s", name);
272
		else
270
		else
273
			printk("%scdb[0]=0x%x, sa=0x%x", leadin, cdb0, sa);
271
			printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
274
		break;
272
		break;
275
	case SERVICE_ACTION_OUT_16:
273
	case SERVICE_ACTION_OUT_16:
276
		sa = cdbp[1] & 0x1f;
274
		sa = cdbp[1] & 0x1f;
277
		name = get_sa_name(serv_out16_arr, SERV_OUT16_SZ, sa);
275
		name = get_sa_name(serv_out16_arr, SERV_OUT16_SZ, sa);
278
		if (name)
276
		if (name)
279
			printk("%s%s", leadin, name);
277
			printk("%s", name);
280
		else
278
		else
281
			printk("%scdb[0]=0x%x, sa=0x%x", leadin, cdb0, sa);
279
			printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
282
		break;
280
		break;
283
	default:
281
	default:
284
		if (cdb0 < 0xc0) {
282
		if (cdb0 < 0xc0) {
285
			name = cdb_byte0_names[cdb0];
283
			name = cdb_byte0_names[cdb0];
286
			if (name)
284
			if (name)
287
				printk("%s%s", leadin, name);
285
				printk("%s", name);
288
			else
286
			else
289
				printk("%scdb[0]=0x%x (reserved)",
287
				printk("cdb[0]=0x%x (reserved)", cdb0);
290
				       leadin, cdb0);
291
		} else
288
		} else
292
			printk("%scdb[0]=0x%x (vendor)", leadin, cdb0);
289
			printk("cdb[0]=0x%x (vendor)", cdb0);
293
		break;
290
		break;
294
	}
291
	}
295
}
292
}
296
293
297
#else /* ifndef CONFIG_SCSI_CONSTANTS */
294
#else /* ifndef CONFIG_SCSI_CONSTANTS */
298
295
299
static void print_opcode_name(unsigned char * cdbp, int cdb_len,
296
static void print_opcode_name(unsigned char * cdbp, int cdb_len)
300
			      int start_of_line)
301
{
297
{
302
	int sa, len, cdb0;
298
	int sa, len, cdb0;
303
	const char * leadin = start_of_line ? KERN_INFO : "";
304
299
305
	cdb0 = cdbp[0];
300
	cdb0 = cdbp[0];
306
	switch(cdb0) {
301
	switch(cdb0) {
307
	case VARIABLE_LENGTH_CMD:
302
	case VARIABLE_LENGTH_CMD:
308
		len = cdbp[7] + 8;
303
		len = cdbp[7] + 8;
309
		if (len < 10) {
304
		if (len < 10) {
310
			printk("%sshort opcode=0x%x command, len=%d "
305
			printk("short opcode=0x%x command, len=%d "
311
			       "ext_len=%d", leadin, cdb0, len, cdb_len);
306
			       "ext_len=%d", cdb0, len, cdb_len);
312
			break;
307
			break;
313
		}
308
		}
314
		sa = (cdbp[8] << 8) + cdbp[9];
309
		sa = (cdbp[8] << 8) + cdbp[9];
315
		printk("%scdb[0]=0x%x, sa=0x%x", leadin, cdb0, sa);
310
		printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
316
		if (len != cdb_len)
311
		if (len != cdb_len)
317
			printk(", in_cdb_len=%d, ext_len=%d", len, cdb_len);
312
			printk(", in_cdb_len=%d, ext_len=%d", len, cdb_len);
318
		break;
313
		break;
Lines 323-371 static void print_opcode_name(unsigned char * cdbp, int cdb_len, Link Here
323
	case SERVICE_ACTION_IN_16:
318
	case SERVICE_ACTION_IN_16:
324
	case SERVICE_ACTION_OUT_16:
319
	case SERVICE_ACTION_OUT_16:
325
		sa = cdbp[1] & 0x1f;
320
		sa = cdbp[1] & 0x1f;
326
		printk("%scdb[0]=0x%x, sa=0x%x", leadin, cdb0, sa);
321
		printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
327
		break;
322
		break;
328
	default:
323
	default:
329
		if (cdb0 < 0xc0)
324
		if (cdb0 < 0xc0)
330
			printk("%scdb[0]=0x%x", leadin, cdb0);
325
			printk("cdb[0]=0x%x", cdb0);
331
		else
326
		else
332
			printk("%scdb[0]=0x%x (vendor)", leadin, cdb0);
327
			printk("cdb[0]=0x%x (vendor)", cdb0);
333
		break;
328
		break;
334
	}
329
	}
335
}
330
}
336
#endif  
331
#endif  
337
332
338
void __scsi_print_command(unsigned char *command)
333
void __scsi_print_command(unsigned char *cdb)
339
{
334
{
340
	int k, len;
335
	int k, len;
341
336
342
	print_opcode_name(command, 0, 1);
337
	print_opcode_name(cdb, 0);
343
	if (VARIABLE_LENGTH_CMD == command[0])
338
	if (VARIABLE_LENGTH_CMD == cdb[0])
344
		len = command[7] + 8;
339
		len = cdb[7] + 8;
345
	else
340
	else
346
		len = COMMAND_SIZE(command[0]);
341
		len = COMMAND_SIZE(cdb[0]);
347
	/* print out all bytes in cdb */
342
	/* print out all bytes in cdb */
348
	for (k = 0; k < len; ++k) 
343
	for (k = 0; k < len; ++k) 
349
		printk(" %02x", command[k]);
344
		printk(" %02x", cdb[k]);
350
	printk("\n");
345
	printk("\n");
351
}
346
}
352
EXPORT_SYMBOL(__scsi_print_command);
347
EXPORT_SYMBOL(__scsi_print_command);
353
348
354
/* This function (perhaps with the addition of peripheral device type)
349
void scsi_print_command(struct scsi_cmnd *cmd)
355
 * is more approriate than __scsi_print_command(). Perhaps that static
356
 * can be dropped later if it replaces the __scsi_print_command version.
357
 */
358
static void scsi_print_cdb(unsigned char *cdb, int cdb_len, int start_of_line)
359
{
350
{
360
	int k;
351
	int k;
361
352
362
	print_opcode_name(cdb, cdb_len, start_of_line);
353
	scmd_printk(KERN_INFO, cmd, "CDB: ");
354
	print_opcode_name(cmd->cmnd, cmd->cmd_len);
355
363
	/* print out all bytes in cdb */
356
	/* print out all bytes in cdb */
364
	printk(":");
357
	printk(":");
365
	for (k = 0; k < cdb_len; ++k) 
358
	for (k = 0; k < cmd->cmd_len; ++k)
366
		printk(" %02x", cdb[k]);
359
		printk(" %02x", cmd->cmnd[k]);
367
	printk("\n");
360
	printk("\n");
368
}
361
}
362
EXPORT_SYMBOL(scsi_print_command);
369
363
370
/**
364
/**
371
 *
365
 *
Lines 1176-1242 scsi_extd_sense_format(unsigned char asc, unsigned char ascq) { Link Here
1176
}
1170
}
1177
EXPORT_SYMBOL(scsi_extd_sense_format);
1171
EXPORT_SYMBOL(scsi_extd_sense_format);
1178
1172
1179
/* Print extended sense information; no leadin, no linefeed */
1173
void
1180
static void
1181
scsi_show_extd_sense(unsigned char asc, unsigned char ascq)
1174
scsi_show_extd_sense(unsigned char asc, unsigned char ascq)
1182
{
1175
{
1183
	const char *extd_sense_fmt = scsi_extd_sense_format(asc, ascq);
1176
        const char *extd_sense_fmt = scsi_extd_sense_format(asc, ascq);
1184
1177
1185
	if (extd_sense_fmt) {
1178
	if (extd_sense_fmt) {
1186
		if (strstr(extd_sense_fmt, "%x")) {
1179
		if (strstr(extd_sense_fmt, "%x")) {
1187
			printk("Additional sense: ");
1180
			printk("Add. Sense: ");
1188
			printk(extd_sense_fmt, ascq);
1181
			printk(extd_sense_fmt, ascq);
1189
		} else
1182
		} else
1190
			printk("Additional sense: %s", extd_sense_fmt);
1183
			printk("Add. Sense: %s", extd_sense_fmt);
1191
	} else {
1184
	} else {
1192
		if (asc >= 0x80)
1185
		if (asc >= 0x80)
1193
			printk("<<vendor>> ASC=0x%x ASCQ=0x%x", asc, ascq);
1186
			printk("<<vendor>> ASC=0x%x ASCQ=0x%x", asc,
1187
			       ascq);
1194
		if (ascq >= 0x80)
1188
		if (ascq >= 0x80)
1195
			printk("ASC=0x%x <<vendor>> ASCQ=0x%x", asc, ascq);
1189
			printk("ASC=0x%x <<vendor>> ASCQ=0x%x", asc,
1190
			       ascq);
1196
		else
1191
		else
1197
			printk("ASC=0x%x ASCQ=0x%x", asc, ascq);
1192
			printk("ASC=0x%x ASCQ=0x%x", asc, ascq);
1198
	}
1193
	}
1194
1195
	printk("\n");
1199
}
1196
}
1197
EXPORT_SYMBOL(scsi_show_extd_sense);
1200
1198
1201
void
1199
void
1202
scsi_print_sense_hdr(const char *name, struct scsi_sense_hdr *sshdr)
1200
scsi_show_sense_hdr(struct scsi_sense_hdr *sshdr)
1203
{
1201
{
1204
	const char *sense_txt;
1202
	const char *sense_txt;
1205
	/* An example of deferred is when an earlier write to disk cache
1206
	 * succeeded, but now the disk discovers that it cannot write the
1207
	 * data to the magnetic media.
1208
	 */
1209
	const char *error = scsi_sense_is_deferred(sshdr) ? 
1210
		"<<DEFERRED>>" : "Current";
1211
	printk(KERN_INFO "%s: %s", name, error);
1212
	if (sshdr->response_code >= 0x72)
1213
		printk(" [descriptor]");
1214
1203
1215
	sense_txt = scsi_sense_key_string(sshdr->sense_key);
1204
	sense_txt = scsi_sense_key_string(sshdr->sense_key);
1216
	if (sense_txt)
1205
	if (sense_txt)
1217
		printk(": sense key: %s\n", sense_txt);
1206
		printk("Sense Key : %s ", sense_txt);
1218
	else
1207
	else
1219
		printk(": sense key=0x%x\n", sshdr->sense_key);
1208
		printk("Sense Key : 0x%x ", sshdr->sense_key);
1220
	printk(KERN_INFO "    ");
1209
1221
	scsi_show_extd_sense(sshdr->asc, sshdr->ascq);
1210
	printk("%s", scsi_sense_is_deferred(sshdr) ? "[deferred] " :
1211
	       "[current] ");
1212
1213
	if (sshdr->response_code >= 0x72)
1214
		printk("[descriptor]");
1215
1222
	printk("\n");
1216
	printk("\n");
1223
}
1217
}
1218
EXPORT_SYMBOL(scsi_show_sense_hdr);
1219
1220
/*
1221
 * Print normalized SCSI sense header with a prefix.
1222
 */
1223
void
1224
scsi_print_sense_hdr(const char *name, struct scsi_sense_hdr *sshdr)
1225
{
1226
	printk(KERN_INFO "%s: ", name);
1227
	scsi_show_sense_hdr(sshdr);
1228
	printk(KERN_INFO "%s: ", name);
1229
	scsi_show_extd_sense(sshdr->asc, sshdr->ascq);
1230
}
1224
EXPORT_SYMBOL(scsi_print_sense_hdr);
1231
EXPORT_SYMBOL(scsi_print_sense_hdr);
1225
1232
1226
/* Print sense information */
1227
void
1233
void
1228
__scsi_print_sense(const char *name, const unsigned char *sense_buffer,
1234
scsi_decode_sense_buffer(const unsigned char *sense_buffer, int sense_len,
1229
		   int sense_len)
1235
		       struct scsi_sense_hdr *sshdr)
1230
{
1236
{
1231
	int k, num, res;
1237
	int k, num, res;
1232
	unsigned int info;
1233
	struct scsi_sense_hdr ssh;
1234
    
1238
    
1235
	res = scsi_normalize_sense(sense_buffer, sense_len, &ssh);
1239
	res = scsi_normalize_sense(sense_buffer, sense_len, sshdr);
1236
	if (0 == res) {
1240
	if (0 == res) {
1237
		/* this may be SCSI-1 sense data */
1241
		/* this may be SCSI-1 sense data */
1238
		num = (sense_len < 32) ? sense_len : 32;
1242
		num = (sense_len < 32) ? sense_len : 32;
1239
		printk(KERN_INFO "Unrecognized sense data (in hex):");
1243
		printk("Unrecognized sense data (in hex):");
1240
		for (k = 0; k < num; ++k) {
1244
		for (k = 0; k < num; ++k) {
1241
			if (0 == (k % 16)) {
1245
			if (0 == (k % 16)) {
1242
				printk("\n");
1246
				printk("\n");
Lines 1247-1257 __scsi_print_sense(const char *name, const unsigned char *sense_buffer, Link Here
1247
		printk("\n");
1251
		printk("\n");
1248
		return;
1252
		return;
1249
	}
1253
	}
1250
	scsi_print_sense_hdr(name, &ssh);
1254
}
1251
	if (ssh.response_code < 0x72) {
1255
1256
void
1257
scsi_decode_sense_extras(const unsigned char *sense_buffer, int sense_len,
1258
			 struct scsi_sense_hdr *sshdr)
1259
{
1260
	int k, num, res;
1261
1262
	if (sshdr->response_code < 0x72)
1263
	{
1252
		/* only decode extras for "fixed" format now */
1264
		/* only decode extras for "fixed" format now */
1253
		char buff[80];
1265
		char buff[80];
1254
		int blen, fixed_valid;
1266
		int blen, fixed_valid;
1267
		unsigned int info;
1255
1268
1256
		fixed_valid = sense_buffer[0] & 0x80;
1269
		fixed_valid = sense_buffer[0] & 0x80;
1257
		info = ((sense_buffer[3] << 24) | (sense_buffer[4] << 16) |
1270
		info = ((sense_buffer[3] << 24) | (sense_buffer[4] << 16) |
Lines 1281-1293 __scsi_print_sense(const char *name, const unsigned char *sense_buffer, Link Here
1281
			res += snprintf(buff + res, blen - res, "ILI");
1294
			res += snprintf(buff + res, blen - res, "ILI");
1282
		}
1295
		}
1283
		if (res > 0)
1296
		if (res > 0)
1284
			printk(KERN_INFO "%s\n", buff);
1297
			printk("%s\n", buff);
1285
	} else if (ssh.additional_length > 0) {
1298
	} else if (sshdr->additional_length > 0) {
1286
		/* descriptor format with sense descriptors */
1299
		/* descriptor format with sense descriptors */
1287
		num = 8 + ssh.additional_length;
1300
		num = 8 + sshdr->additional_length;
1288
		num = (sense_len < num) ? sense_len : num;
1301
		num = (sense_len < num) ? sense_len : num;
1289
		printk(KERN_INFO "Descriptor sense data with sense "
1302
		printk("Descriptor sense data with sense descriptors "
1290
		       "descriptors (in hex):");
1303
		       "(in hex):");
1291
		for (k = 0; k < num; ++k) {
1304
		for (k = 0; k < num; ++k) {
1292
			if (0 == (k % 16)) {
1305
			if (0 == (k % 16)) {
1293
				printk("\n");
1306
				printk("\n");
Lines 1295-1323 __scsi_print_sense(const char *name, const unsigned char *sense_buffer, Link Here
1295
			}
1308
			}
1296
			printk("%02x ", sense_buffer[k]);
1309
			printk("%02x ", sense_buffer[k]);
1297
		}
1310
		}
1311
1298
		printk("\n");
1312
		printk("\n");
1299
	}
1313
	}
1314
1300
}
1315
}
1301
EXPORT_SYMBOL(__scsi_print_sense);
1302
1316
1303
void scsi_print_sense(const char *devclass, struct scsi_cmnd *cmd)
1317
/* Normalize and print sense buffer with name prefix */
1318
void __scsi_print_sense(const char *name, const unsigned char *sense_buffer,
1319
			int sense_len)
1304
{
1320
{
1305
	const char *name = devclass;
1321
	struct scsi_sense_hdr sshdr;
1306
1322
1307
	if (cmd->request->rq_disk)
1323
	printk(KERN_INFO "%s: ", name);
1308
		name = cmd->request->rq_disk->disk_name;
1324
	scsi_decode_sense_buffer(sense_buffer, sense_len, &sshdr);
1309
	__scsi_print_sense(name, cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE);
1325
	scsi_show_sense_hdr(&sshdr);
1326
	scsi_decode_sense_extras(sense_buffer, sense_len, &sshdr);
1327
	printk(KERN_INFO "%s: ", name);
1328
	scsi_show_extd_sense(sshdr.asc, sshdr.ascq);
1310
}
1329
}
1311
EXPORT_SYMBOL(scsi_print_sense);
1330
EXPORT_SYMBOL(__scsi_print_sense);
1312
1331
1313
void scsi_print_command(struct scsi_cmnd *cmd)
1332
/* Normalize and print sense buffer in SCSI command */
1333
void scsi_print_sense(char *name, struct scsi_cmnd *cmd)
1314
{
1334
{
1315
	/* Assume appended output (i.e. not at start of line) */
1335
	struct scsi_sense_hdr sshdr;
1316
	sdev_printk("", cmd->device, "\n");
1336
1317
	printk(KERN_INFO "        command: ");
1337
	scmd_printk(KERN_INFO, cmd, "");
1318
	scsi_print_cdb(cmd->cmnd, cmd->cmd_len, 0);
1338
	scsi_decode_sense_buffer(cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE,
1339
				 &sshdr);
1340
	scsi_show_sense_hdr(&sshdr);
1341
	scsi_decode_sense_extras(cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE,
1342
				 &sshdr);
1343
	scmd_printk(KERN_INFO, cmd, "");
1344
	scsi_show_extd_sense(sshdr.asc, sshdr.ascq);
1319
}
1345
}
1320
EXPORT_SYMBOL(scsi_print_command);
1346
EXPORT_SYMBOL(scsi_print_sense);
1321
1347
1322
#ifdef CONFIG_SCSI_CONSTANTS
1348
#ifdef CONFIG_SCSI_CONSTANTS
1323
1349
Lines 1327-1351 static const char * const hostbyte_table[]={ Link Here
1327
"DID_PASSTHROUGH", "DID_SOFT_ERROR", "DID_IMM_RETRY"};
1353
"DID_PASSTHROUGH", "DID_SOFT_ERROR", "DID_IMM_RETRY"};
1328
#define NUM_HOSTBYTE_STRS ARRAY_SIZE(hostbyte_table)
1354
#define NUM_HOSTBYTE_STRS ARRAY_SIZE(hostbyte_table)
1329
1355
1330
void scsi_print_hostbyte(int scsiresult)
1331
{
1332
	int hb = host_byte(scsiresult);
1333
1334
	printk("Hostbyte=0x%02x", hb);
1335
	if (hb < NUM_HOSTBYTE_STRS)
1336
		printk("(%s) ", hostbyte_table[hb]);
1337
	else
1338
		printk("is invalid ");
1339
}
1340
#else
1341
void scsi_print_hostbyte(int scsiresult)
1342
{
1343
	printk("Hostbyte=0x%02x ", host_byte(scsiresult));
1344
}
1345
#endif
1346
1347
#ifdef CONFIG_SCSI_CONSTANTS
1348
1349
static const char * const driverbyte_table[]={
1356
static const char * const driverbyte_table[]={
1350
"DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT",  "DRIVER_MEDIA", "DRIVER_ERROR",
1357
"DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT",  "DRIVER_MEDIA", "DRIVER_ERROR",
1351
"DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE"};
1358
"DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE"};
Lines 1356-1374 static const char * const driversuggest_table[]={"SUGGEST_OK", Link Here
1356
"SUGGEST_5", "SUGGEST_6", "SUGGEST_7", "SUGGEST_SENSE"};
1363
"SUGGEST_5", "SUGGEST_6", "SUGGEST_7", "SUGGEST_SENSE"};
1357
#define NUM_SUGGEST_STRS ARRAY_SIZE(driversuggest_table)
1364
#define NUM_SUGGEST_STRS ARRAY_SIZE(driversuggest_table)
1358
1365
1359
void scsi_print_driverbyte(int scsiresult)
1366
void scsi_show_result(int result)
1360
{
1367
{
1361
	int dr = (driver_byte(scsiresult) & DRIVER_MASK);
1368
	int hb = host_byte(result);
1362
	int su = ((driver_byte(scsiresult) & SUGGEST_MASK) >> 4);
1369
	int db = (driver_byte(result) & DRIVER_MASK);
1370
	int su = ((driver_byte(result) & SUGGEST_MASK) >> 4);
1363
1371
1364
	printk("Driverbyte=0x%02x ", driver_byte(scsiresult));
1372
	printk("Result: hostbyte=%s driverbyte=%s,%s\n",
1365
	printk("(%s,%s) ",
1373
	       (hb < NUM_HOSTBYTE_STRS ? hostbyte_table[hb]     : "invalid"),
1366
	       (dr < NUM_DRIVERBYTE_STRS ? driverbyte_table[dr] : "invalid"),
1374
	       (db < NUM_DRIVERBYTE_STRS ? driverbyte_table[db] : "invalid"),
1367
	       (su < NUM_SUGGEST_STRS ? driversuggest_table[su] : "invalid"));
1375
	       (su < NUM_SUGGEST_STRS ? driversuggest_table[su] : "invalid"));
1368
}
1376
}
1377
1369
#else
1378
#else
1370
void scsi_print_driverbyte(int scsiresult)
1379
1380
void scsi_show_result(int result)
1371
{
1381
{
1372
	printk("Driverbyte=0x%02x ", driver_byte(scsiresult));
1382
	printk("Result: hostbyte=0x%02x driverbyte=0x%02x\n",
1383
	       host_byte(result), driver_byte(result));
1373
}
1384
}
1385
1374
#endif
1386
#endif
1387
EXPORT_SYMBOL(scsi_show_result);
1388
1389
1390
void scsi_print_result(struct scsi_cmnd *cmd)
1391
{
1392
	scmd_printk(KERN_INFO, cmd, "");
1393
	scsi_show_result(cmd->result);
1394
}
1395
EXPORT_SYMBOL(scsi_print_result);
1396
1397
(-)a/include/scsi/scsi_dbg.h (-5 / +6 lines)
Lines 5-18 struct scsi_cmnd; Link Here
5
struct scsi_sense_hdr;
5
struct scsi_sense_hdr;
6
6
7
extern void scsi_print_command(struct scsi_cmnd *);
7
extern void scsi_print_command(struct scsi_cmnd *);
8
extern void scsi_print_sense_hdr(const char *, struct scsi_sense_hdr *);
9
extern void __scsi_print_command(unsigned char *);
8
extern void __scsi_print_command(unsigned char *);
10
extern void scsi_print_sense(const char *, struct scsi_cmnd *);
9
extern void scsi_show_extd_sense(unsigned char, unsigned char);
10
extern void scsi_show_sense_hdr(struct scsi_sense_hdr *);
11
extern void scsi_print_sense_hdr(const char *, struct scsi_sense_hdr *);
12
extern void scsi_print_sense(char *, struct scsi_cmnd *);
11
extern void __scsi_print_sense(const char *name,
13
extern void __scsi_print_sense(const char *name,
12
			       const unsigned char *sense_buffer,
14
			       const unsigned char *sense_buffer,
13
			       int sense_len);
15
			       int sense_len);
14
extern void scsi_print_driverbyte(int);
16
extern void scsi_show_result(int);
15
extern void scsi_print_hostbyte(int);
17
extern void scsi_print_result(struct scsi_cmnd *);
16
extern void scsi_print_status(unsigned char);
18
extern void scsi_print_status(unsigned char);
17
extern const char *scsi_sense_key_string(unsigned char);
19
extern const char *scsi_sense_key_string(unsigned char);
18
extern const char *scsi_extd_sense_format(unsigned char, unsigned char);
20
extern const char *scsi_extd_sense_format(unsigned char, unsigned char);
19
- Define sd_printk(), sd_print_sense_hdr() and sd_print_result()
21
- Define sd_printk(), sd_print_sense_hdr() and sd_print_result()
20
- Move relevant header bits into sd.h
22
- Move relevant header bits into sd.h
21
- Remove all the legacy disk_name passing and use scsi_disk pointers
23
- Remove all the legacy disk_name passing and use scsi_disk pointers
22
  where possible
24
  where possible
23
- Switch printk() lines to the new sd_ functions so that output is
25
- Switch printk() lines to the new sd_ functions so that output is
24
  consistent
26
  consistent
25
--
(-)a/drivers/scsi/sd.c (-158 / +95 lines)
Lines 58-73 Link Here
58
#include <scsi/scsi_host.h>
58
#include <scsi/scsi_host.h>
59
#include <scsi/scsi_ioctl.h>
59
#include <scsi/scsi_ioctl.h>
60
#include <scsi/scsicam.h>
60
#include <scsi/scsicam.h>
61
#include <scsi/sd.h>
61
62
62
#include "scsi_logging.h"
63
#include "scsi_logging.h"
63
64
64
/*
65
 * More than enough for everybody ;)  The huge number of majors
66
 * is a leftover from 16bit dev_t days, we don't really need that
67
 * much numberspace.
68
 */
69
#define SD_MAJORS	16
70
71
MODULE_AUTHOR("Eric Youngdale");
65
MODULE_AUTHOR("Eric Youngdale");
72
MODULE_DESCRIPTION("SCSI disk (sd) driver");
66
MODULE_DESCRIPTION("SCSI disk (sd) driver");
73
MODULE_LICENSE("GPL");
67
MODULE_LICENSE("GPL");
Lines 89-133 MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_DISK13_MAJOR); Link Here
89
MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_DISK14_MAJOR);
83
MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_DISK14_MAJOR);
90
MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_DISK15_MAJOR);
84
MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_DISK15_MAJOR);
91
85
92
/*
93
 * This is limited by the naming scheme enforced in sd_probe,
94
 * add another character to it if you really need more disks.
95
 */
96
#define SD_MAX_DISKS	(((26 * 26) + 26 + 1) * 26)
97
98
/*
99
 * Time out in seconds for disks and Magneto-opticals (which are slower).
100
 */
101
#define SD_TIMEOUT		(30 * HZ)
102
#define SD_MOD_TIMEOUT		(75 * HZ)
103
104
/*
105
 * Number of allowed retries
106
 */
107
#define SD_MAX_RETRIES		5
108
#define SD_PASSTHROUGH_RETRIES	1
109
110
/*
111
 * Size of the initial data buffer for mode and read capacity data
112
 */
113
#define SD_BUF_SIZE		512
114
115
struct scsi_disk {
116
	struct scsi_driver *driver;	/* always &sd_template */
117
	struct scsi_device *device;
118
	struct class_device cdev;
119
	struct gendisk	*disk;
120
	unsigned int	openers;	/* protected by BKL for now, yuck */
121
	sector_t	capacity;	/* size in 512-byte sectors */
122
	u32		index;
123
	u8		media_present;
124
	u8		write_prot;
125
	unsigned	WCE : 1;	/* state of disk WCE bit */
126
	unsigned	RCD : 1;	/* state of disk RCD bit, unused */
127
	unsigned	DPOFUA : 1;	/* state of disk DPOFUA bit */
128
};
129
#define to_scsi_disk(obj) container_of(obj,struct scsi_disk,cdev)
130
131
static DEFINE_IDR(sd_index_idr);
86
static DEFINE_IDR(sd_index_idr);
132
static DEFINE_SPINLOCK(sd_index_lock);
87
static DEFINE_SPINLOCK(sd_index_lock);
133
88
Lines 136-155 static DEFINE_SPINLOCK(sd_index_lock); Link Here
136
 * object after last put) */
91
 * object after last put) */
137
static DEFINE_MUTEX(sd_ref_mutex);
92
static DEFINE_MUTEX(sd_ref_mutex);
138
93
139
static int sd_revalidate_disk(struct gendisk *disk);
140
static void sd_rw_intr(struct scsi_cmnd * SCpnt);
141
142
static int sd_probe(struct device *);
143
static int sd_remove(struct device *);
144
static void sd_shutdown(struct device *dev);
145
static void sd_rescan(struct device *);
146
static int sd_init_command(struct scsi_cmnd *);
147
static int sd_issue_flush(struct device *, sector_t *);
148
static void sd_prepare_flush(request_queue_t *, struct request *);
149
static void sd_read_capacity(struct scsi_disk *sdkp, char *diskname,
150
			     unsigned char *buffer);
151
static void scsi_disk_release(struct class_device *cdev);
152
153
static const char *sd_cache_types[] = {
94
static const char *sd_cache_types[] = {
154
	"write through", "none", "write back",
95
	"write through", "none", "write back",
155
	"write back, no read (daft)"
96
	"write back, no read (daft)"
Lines 199-205 static ssize_t sd_store_cache_type(struct class_device *cdev, const char *buf, Link Here
199
	if (scsi_mode_select(sdp, 1, sp, 8, buffer_data, len, SD_TIMEOUT,
140
	if (scsi_mode_select(sdp, 1, sp, 8, buffer_data, len, SD_TIMEOUT,
200
			     SD_MAX_RETRIES, &data, &sshdr)) {
141
			     SD_MAX_RETRIES, &data, &sshdr)) {
201
		if (scsi_sense_valid(&sshdr))
142
		if (scsi_sense_valid(&sshdr))
202
			scsi_print_sense_hdr(sdkp->disk->disk_name, &sshdr);
143
			sd_print_sense_hdr(sdkp, &sshdr);
203
		return -EINVAL;
144
		return -EINVAL;
204
	}
145
	}
205
	sd_revalidate_disk(sdkp->disk);
146
	sd_revalidate_disk(sdkp->disk);
Lines 407-413 static int sd_init_command(struct scsi_cmnd * SCpnt) Link Here
407
	 */
348
	 */
408
	if (sdp->sector_size == 1024) {
349
	if (sdp->sector_size == 1024) {
409
		if ((block & 1) || (rq->nr_sectors & 1)) {
350
		if ((block & 1) || (rq->nr_sectors & 1)) {
410
			printk(KERN_ERR "sd: Bad block number requested");
351
			scmd_printk(KERN_ERR, SCpnt,
352
				    "Bad block number requested\n");
411
			return 0;
353
			return 0;
412
		} else {
354
		} else {
413
			block = block >> 1;
355
			block = block >> 1;
Lines 416-422 static int sd_init_command(struct scsi_cmnd * SCpnt) Link Here
416
	}
358
	}
417
	if (sdp->sector_size == 2048) {
359
	if (sdp->sector_size == 2048) {
418
		if ((block & 3) || (rq->nr_sectors & 3)) {
360
		if ((block & 3) || (rq->nr_sectors & 3)) {
419
			printk(KERN_ERR "sd: Bad block number requested");
361
			scmd_printk(KERN_ERR, SCpnt,
362
				    "Bad block number requested\n");
420
			return 0;
363
			return 0;
421
		} else {
364
		} else {
422
			block = block >> 2;
365
			block = block >> 2;
Lines 425-431 static int sd_init_command(struct scsi_cmnd * SCpnt) Link Here
425
	}
368
	}
426
	if (sdp->sector_size == 4096) {
369
	if (sdp->sector_size == 4096) {
427
		if ((block & 7) || (rq->nr_sectors & 7)) {
370
		if ((block & 7) || (rq->nr_sectors & 7)) {
428
			printk(KERN_ERR "sd: Bad block number requested");
371
			scmd_printk(KERN_ERR, SCpnt,
372
				    "Bad block number requested\n");
429
			return 0;
373
			return 0;
430
		} else {
374
		} else {
431
			block = block >> 3;
375
			block = block >> 3;
Lines 442-448 static int sd_init_command(struct scsi_cmnd * SCpnt) Link Here
442
		SCpnt->cmnd[0] = READ_6;
386
		SCpnt->cmnd[0] = READ_6;
443
		SCpnt->sc_data_direction = DMA_FROM_DEVICE;
387
		SCpnt->sc_data_direction = DMA_FROM_DEVICE;
444
	} else {
388
	} else {
445
		printk(KERN_ERR "sd: Unknown command %x\n", rq->cmd_flags);
389
		scmd_printk(KERN_ERR, SCpnt, "Unknown command %x\n", rq->cmd_flags);
446
		return 0;
390
		return 0;
447
	}
391
	}
448
392
Lines 490-496 static int sd_init_command(struct scsi_cmnd * SCpnt) Link Here
490
			 * during operation and thus turned off
434
			 * during operation and thus turned off
491
			 * use_10_for_rw.
435
			 * use_10_for_rw.
492
			 */
436
			 */
493
			printk(KERN_ERR "sd: FUA write on READ/WRITE(6) drive\n");
437
			scmd_printk(KERN_ERR, SCpnt,
438
				    "FUA write on READ/WRITE(6) drive\n");
494
			return 0;
439
			return 0;
495
		}
440
		}
496
441
Lines 786-794 not_present: Link Here
786
	return 1;
731
	return 1;
787
}
732
}
788
733
789
static int sd_sync_cache(struct scsi_device *sdp)
734
static int sd_sync_cache(struct scsi_disk *sdkp)
790
{
735
{
791
	int retries, res;
736
	int retries, res;
737
	struct scsi_device *sdp = sdkp->device;
792
	struct scsi_sense_hdr sshdr;
738
	struct scsi_sense_hdr sshdr;
793
739
794
	if (!scsi_device_online(sdp))
740
	if (!scsi_device_online(sdp))
Lines 809-820 static int sd_sync_cache(struct scsi_device *sdp) Link Here
809
			break;
755
			break;
810
	}
756
	}
811
757
812
	if (res) {		printk(KERN_WARNING "FAILED\n  status = %x, message = %02x, "
758
	if (res) {
813
				    "host = %d, driver = %02x\n  ",
759
		sd_print_result(sdkp, res);
814
				    status_byte(res), msg_byte(res),
760
		if (driver_byte(res) & DRIVER_SENSE)
815
				    host_byte(res), driver_byte(res));
761
			sd_print_sense_hdr(sdkp, &sshdr);
816
			if (driver_byte(res) & DRIVER_SENSE)
817
				scsi_print_sense_hdr("sd", &sshdr);
818
	}
762
	}
819
763
820
	return res;
764
	return res;
Lines 823-836 static int sd_sync_cache(struct scsi_device *sdp) Link Here
823
static int sd_issue_flush(struct device *dev, sector_t *error_sector)
767
static int sd_issue_flush(struct device *dev, sector_t *error_sector)
824
{
768
{
825
	int ret = 0;
769
	int ret = 0;
826
	struct scsi_device *sdp = to_scsi_device(dev);
827
	struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev);
770
	struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev);
828
771
829
	if (!sdkp)
772
	if (!sdkp)
830
               return -ENODEV;
773
               return -ENODEV;
831
774
832
	if (sdkp->WCE)
775
	if (sdkp->WCE)
833
		ret = sd_sync_cache(sdp);
776
		ret = sd_sync_cache(sdkp);
834
	scsi_disk_put(sdkp);
777
	scsi_disk_put(sdkp);
835
	return ret;
778
	return ret;
836
}
779
}
Lines 1025-1031 static int media_not_present(struct scsi_disk *sdkp, Link Here
1025
 * spinup disk - called only in sd_revalidate_disk()
968
 * spinup disk - called only in sd_revalidate_disk()
1026
 */
969
 */
1027
static void
970
static void
1028
sd_spinup_disk(struct scsi_disk *sdkp, char *diskname)
971
sd_spinup_disk(struct scsi_disk *sdkp)
1029
{
972
{
1030
	unsigned char cmd[10];
973
	unsigned char cmd[10];
1031
	unsigned long spintime_expire = 0;
974
	unsigned long spintime_expire = 0;
Lines 1069-1077 sd_spinup_disk(struct scsi_disk *sdkp, char *diskname) Link Here
1069
		if ((driver_byte(the_result) & DRIVER_SENSE) == 0) {
1012
		if ((driver_byte(the_result) & DRIVER_SENSE) == 0) {
1070
			/* no sense, TUR either succeeded or failed
1013
			/* no sense, TUR either succeeded or failed
1071
			 * with a status error */
1014
			 * with a status error */
1072
			if(!spintime && !scsi_status_is_good(the_result))
1015
			if(!spintime && !scsi_status_is_good(the_result)) {
1073
				printk(KERN_NOTICE "%s: Unit Not Ready, "
1016
				sd_printk(KERN_NOTICE, sdkp, "Unit Not Ready\n");
1074
				       "error = 0x%x\n", diskname, the_result);
1017
				sd_print_result(sdkp, the_result);
1018
			}
1075
			break;
1019
			break;
1076
		}
1020
		}
1077
					
1021
					
Lines 1096-1103 sd_spinup_disk(struct scsi_disk *sdkp, char *diskname) Link Here
1096
		 */
1040
		 */
1097
		} else if (sense_valid && sshdr.sense_key == NOT_READY) {
1041
		} else if (sense_valid && sshdr.sense_key == NOT_READY) {
1098
			if (!spintime) {
1042
			if (!spintime) {
1099
				printk(KERN_NOTICE "%s: Spinning up disk...",
1043
				sd_printk(KERN_NOTICE, sdkp, "Spinning up disk...");
1100
				       diskname);
1101
				cmd[0] = START_STOP;
1044
				cmd[0] = START_STOP;
1102
				cmd[1] = 1;	/* Return immediately */
1045
				cmd[1] = 1;	/* Return immediately */
1103
				memset((void *) &cmd[2], 0, 8);
1046
				memset((void *) &cmd[2], 0, 8);
Lines 1130-1138 sd_spinup_disk(struct scsi_disk *sdkp, char *diskname) Link Here
1130
			/* we don't understand the sense code, so it's
1073
			/* we don't understand the sense code, so it's
1131
			 * probably pointless to loop */
1074
			 * probably pointless to loop */
1132
			if(!spintime) {
1075
			if(!spintime) {
1133
				printk(KERN_NOTICE "%s: Unit Not Ready, "
1076
				sd_printk(KERN_NOTICE, sdkp, "Unit Not Ready\n");
1134
					"sense:\n", diskname);
1077
				sd_print_sense_hdr(sdkp, &sshdr);
1135
				scsi_print_sense_hdr("", &sshdr);
1136
			}
1078
			}
1137
			break;
1079
			break;
1138
		}
1080
		}
Lines 1151-1158 sd_spinup_disk(struct scsi_disk *sdkp, char *diskname) Link Here
1151
 * read disk capacity
1093
 * read disk capacity
1152
 */
1094
 */
1153
static void
1095
static void
1154
sd_read_capacity(struct scsi_disk *sdkp, char *diskname,
1096
sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer)
1155
		 unsigned char *buffer)
1156
{
1097
{
1157
	unsigned char cmd[16];
1098
	unsigned char cmd[16];
1158
	int the_result, retries;
1099
	int the_result, retries;
Lines 1191-1208 repeat: Link Here
1191
	} while (the_result && retries);
1132
	} while (the_result && retries);
1192
1133
1193
	if (the_result && !longrc) {
1134
	if (the_result && !longrc) {
1194
		printk(KERN_NOTICE "%s : READ CAPACITY failed.\n"
1135
		sd_printk(KERN_NOTICE, sdkp, "READ CAPACITY failed\n");
1195
		       "%s : status=%x, message=%02x, host=%d, driver=%02x \n",
1136
		sd_print_result(sdkp, the_result);
1196
		       diskname, diskname,
1197
		       status_byte(the_result),
1198
		       msg_byte(the_result),
1199
		       host_byte(the_result),
1200
		       driver_byte(the_result));
1201
1202
		if (driver_byte(the_result) & DRIVER_SENSE)
1137
		if (driver_byte(the_result) & DRIVER_SENSE)
1203
			scsi_print_sense_hdr("sd", &sshdr);
1138
			sd_print_sense_hdr(sdkp, &sshdr);
1204
		else
1139
		else
1205
			printk("%s : sense not available. \n", diskname);
1140
			sd_printk(KERN_NOTICE, sdkp, "Sense not available.\n");
1206
1141
1207
		/* Set dirty bit for removable devices if not ready -
1142
		/* Set dirty bit for removable devices if not ready -
1208
		 * sometimes drives will not report this properly. */
1143
		 * sometimes drives will not report this properly. */
Lines 1218-1233 repeat: Link Here
1218
		return;
1153
		return;
1219
	} else if (the_result && longrc) {
1154
	} else if (the_result && longrc) {
1220
		/* READ CAPACITY(16) has been failed */
1155
		/* READ CAPACITY(16) has been failed */
1221
		printk(KERN_NOTICE "%s : READ CAPACITY(16) failed.\n"
1156
		sd_printk(KERN_NOTICE, sdkp, "READ CAPACITY(16) failed\n");
1222
		       "%s : status=%x, message=%02x, host=%d, driver=%02x \n",
1157
		sd_print_result(sdkp, the_result);
1223
		       diskname, diskname,
1158
		sd_printk(KERN_NOTICE, sdkp, "Use 0xffffffff as device size\n");
1224
		       status_byte(the_result),
1159
1225
		       msg_byte(the_result),
1226
		       host_byte(the_result),
1227
		       driver_byte(the_result));
1228
		printk(KERN_NOTICE "%s : use 0xffffffff as device size\n",
1229
		       diskname);
1230
		
1231
		sdkp->capacity = 1 + (sector_t) 0xffffffff;		
1160
		sdkp->capacity = 1 + (sector_t) 0xffffffff;		
1232
		goto got_data;
1161
		goto got_data;
1233
	}	
1162
	}	
Lines 1238-1251 repeat: Link Here
1238
		if (buffer[0] == 0xff && buffer[1] == 0xff &&
1167
		if (buffer[0] == 0xff && buffer[1] == 0xff &&
1239
		    buffer[2] == 0xff && buffer[3] == 0xff) {
1168
		    buffer[2] == 0xff && buffer[3] == 0xff) {
1240
			if(sizeof(sdkp->capacity) > 4) {
1169
			if(sizeof(sdkp->capacity) > 4) {
1241
				printk(KERN_NOTICE "%s : very big device. try to use"
1170
				sd_printk(KERN_NOTICE, sdkp, "Very big device. "
1242
				       " READ CAPACITY(16).\n", diskname);
1171
					  "Trying to use READ CAPACITY(16).\n");
1243
				longrc = 1;
1172
				longrc = 1;
1244
				goto repeat;
1173
				goto repeat;
1245
			}
1174
			}
1246
			printk(KERN_ERR "%s: too big for this kernel.  Use a "
1175
			sd_printk(KERN_ERR, sdkp, "Too big for this kernel. Use "
1247
			       "kernel compiled with support for large block "
1176
				  "a kernel compiled with support for large "
1248
			       "devices.\n", diskname);
1177
				  "block devices.\n");
1249
			sdkp->capacity = 0;
1178
			sdkp->capacity = 0;
1250
			goto got_data;
1179
			goto got_data;
1251
		}
1180
		}
Lines 1284-1291 repeat: Link Here
1284
got_data:
1213
got_data:
1285
	if (sector_size == 0) {
1214
	if (sector_size == 0) {
1286
		sector_size = 512;
1215
		sector_size = 512;
1287
		printk(KERN_NOTICE "%s : sector size 0 reported, "
1216
		sd_printk(KERN_NOTICE, sdkp, "Sector size 0 reported, "
1288
		       "assuming 512.\n", diskname);
1217
			  "assuming 512.\n");
1289
	}
1218
	}
1290
1219
1291
	if (sector_size != 512 &&
1220
	if (sector_size != 512 &&
Lines 1293-1300 got_data: Link Here
1293
	    sector_size != 2048 &&
1222
	    sector_size != 2048 &&
1294
	    sector_size != 4096 &&
1223
	    sector_size != 4096 &&
1295
	    sector_size != 256) {
1224
	    sector_size != 256) {
1296
		printk(KERN_NOTICE "%s : unsupported sector size "
1225
		sd_printk(KERN_NOTICE, sdkp, "Unsupported sector size %d.\n",
1297
		       "%d.\n", diskname, sector_size);
1226
			  sector_size);
1298
		/*
1227
		/*
1299
		 * The user might want to re-format the drive with
1228
		 * The user might want to re-format the drive with
1300
		 * a supported sectorsize.  Once this happens, it
1229
		 * a supported sectorsize.  Once this happens, it
Lines 1327-1336 got_data: Link Here
1327
		mb -= sz - 974;
1256
		mb -= sz - 974;
1328
		sector_div(mb, 1950);
1257
		sector_div(mb, 1950);
1329
1258
1330
		printk(KERN_NOTICE "SCSI device %s: "
1259
		sd_printk(KERN_NOTICE, sdkp,
1331
		       "%llu %d-byte hdwr sectors (%llu MB)\n",
1260
			  "%llu %d-byte hardware sectors (%llu MB)\n",
1332
		       diskname, (unsigned long long)sdkp->capacity,
1261
			  (unsigned long long)sdkp->capacity,
1333
		       hard_sector, (unsigned long long)mb);
1262
			  hard_sector, (unsigned long long)mb);
1334
	}
1263
	}
1335
1264
1336
	/* Rescale capacity to 512-byte units */
1265
	/* Rescale capacity to 512-byte units */
Lines 1362-1369 sd_do_mode_sense(struct scsi_device *sdp, int dbd, int modepage, Link Here
1362
 * called with buffer of length SD_BUF_SIZE
1291
 * called with buffer of length SD_BUF_SIZE
1363
 */
1292
 */
1364
static void
1293
static void
1365
sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname,
1294
sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer)
1366
			   unsigned char *buffer)
1367
{
1295
{
1368
	int res;
1296
	int res;
1369
	struct scsi_device *sdp = sdkp->device;
1297
	struct scsi_device *sdp = sdkp->device;
Lines 1371-1377 sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname, Link Here
1371
1299
1372
	set_disk_ro(sdkp->disk, 0);
1300
	set_disk_ro(sdkp->disk, 0);
1373
	if (sdp->skip_ms_page_3f) {
1301
	if (sdp->skip_ms_page_3f) {
1374
		printk(KERN_NOTICE "%s: assuming Write Enabled\n", diskname);
1302
		sd_printk(KERN_NOTICE, sdkp, "Assuming Write Enabled\n");
1375
		return;
1303
		return;
1376
	}
1304
	}
1377
1305
Lines 1403-1417 sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname, Link Here
1403
	}
1331
	}
1404
1332
1405
	if (!scsi_status_is_good(res)) {
1333
	if (!scsi_status_is_good(res)) {
1406
		printk(KERN_WARNING
1334
		sd_printk(KERN_WARNING, sdkp,
1407
		       "%s: test WP failed, assume Write Enabled\n", diskname);
1335
			  "Test WP failed, assume Write Enabled\n");
1408
	} else {
1336
	} else {
1409
		sdkp->write_prot = ((data.device_specific & 0x80) != 0);
1337
		sdkp->write_prot = ((data.device_specific & 0x80) != 0);
1410
		set_disk_ro(sdkp->disk, sdkp->write_prot);
1338
		set_disk_ro(sdkp->disk, sdkp->write_prot);
1411
		printk(KERN_NOTICE "%s: Write Protect is %s\n", diskname,
1339
		sd_printk(KERN_NOTICE, sdkp, "Write Protect is %s\n",
1412
		       sdkp->write_prot ? "on" : "off");
1340
			  sdkp->write_prot ? "on" : "off");
1413
		printk(KERN_DEBUG "%s: Mode Sense: %02x %02x %02x %02x\n",
1341
		sd_printk(KERN_DEBUG, sdkp,
1414
		       diskname, buffer[0], buffer[1], buffer[2], buffer[3]);
1342
			  "Mode Sense: %02x %02x %02x %02x\n",
1343
			  buffer[0], buffer[1], buffer[2], buffer[3]);
1415
	}
1344
	}
1416
}
1345
}
1417
1346
Lines 1420-1427 sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname, Link Here
1420
 * called with buffer of length SD_BUF_SIZE
1349
 * called with buffer of length SD_BUF_SIZE
1421
 */
1350
 */
1422
static void
1351
static void
1423
sd_read_cache_type(struct scsi_disk *sdkp, char *diskname,
1352
sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
1424
		   unsigned char *buffer)
1425
{
1353
{
1426
	int len = 0, res;
1354
	int len = 0, res;
1427
	struct scsi_device *sdp = sdkp->device;
1355
	struct scsi_device *sdp = sdkp->device;
Lines 1450-1457 sd_read_cache_type(struct scsi_disk *sdkp, char *diskname, Link Here
1450
1378
1451
	if (!data.header_length) {
1379
	if (!data.header_length) {
1452
		modepage = 6;
1380
		modepage = 6;
1453
		printk(KERN_ERR "%s: missing header in MODE_SENSE response\n",
1381
		sd_printk(KERN_ERR, sdkp, "Missing header in MODE_SENSE response\n");
1454
		       diskname);
1455
	}
1382
	}
1456
1383
1457
	/* that went OK, now ask for the proper length */
1384
	/* that went OK, now ask for the proper length */
Lines 1478-1490 sd_read_cache_type(struct scsi_disk *sdkp, char *diskname, Link Here
1478
		int offset = data.header_length + data.block_descriptor_length;
1405
		int offset = data.header_length + data.block_descriptor_length;
1479
1406
1480
		if (offset >= SD_BUF_SIZE - 2) {
1407
		if (offset >= SD_BUF_SIZE - 2) {
1481
			printk(KERN_ERR "%s: malformed MODE SENSE response",
1408
			sd_printk(KERN_ERR, sdkp, "Malformed MODE SENSE response\n");
1482
				diskname);
1483
			goto defaults;
1409
			goto defaults;
1484
		}
1410
		}
1485
1411
1486
		if ((buffer[offset] & 0x3f) != modepage) {
1412
		if ((buffer[offset] & 0x3f) != modepage) {
1487
			printk(KERN_ERR "%s: got wrong page\n", diskname);
1413
			sd_printk(KERN_ERR, sdkp, "Got wrong page\n");
1488
			goto defaults;
1414
			goto defaults;
1489
		}
1415
		}
1490
1416
Lines 1498-1511 sd_read_cache_type(struct scsi_disk *sdkp, char *diskname, Link Here
1498
1424
1499
		sdkp->DPOFUA = (data.device_specific & 0x10) != 0;
1425
		sdkp->DPOFUA = (data.device_specific & 0x10) != 0;
1500
		if (sdkp->DPOFUA && !sdkp->device->use_10_for_rw) {
1426
		if (sdkp->DPOFUA && !sdkp->device->use_10_for_rw) {
1501
			printk(KERN_NOTICE "SCSI device %s: uses "
1427
			sd_printk(KERN_NOTICE, sdkp,
1502
			       "READ/WRITE(6), disabling FUA\n", diskname);
1428
				  "Uses READ/WRITE(6), disabling FUA\n");
1503
			sdkp->DPOFUA = 0;
1429
			sdkp->DPOFUA = 0;
1504
		}
1430
		}
1505
1431
1506
		printk(KERN_NOTICE "SCSI device %s: "
1432
		sd_printk(KERN_NOTICE, sdkp,
1507
		       "write cache: %s, read cache: %s, %s\n",
1433
		       "Write cache: %s, read cache: %s, %s\n",
1508
		       diskname,
1509
		       sdkp->WCE ? "enabled" : "disabled",
1434
		       sdkp->WCE ? "enabled" : "disabled",
1510
		       sdkp->RCD ? "disabled" : "enabled",
1435
		       sdkp->RCD ? "disabled" : "enabled",
1511
		       sdkp->DPOFUA ? "supports DPO and FUA"
1436
		       sdkp->DPOFUA ? "supports DPO and FUA"
Lines 1518-1532 bad_sense: Link Here
1518
	if (scsi_sense_valid(&sshdr) &&
1443
	if (scsi_sense_valid(&sshdr) &&
1519
	    sshdr.sense_key == ILLEGAL_REQUEST &&
1444
	    sshdr.sense_key == ILLEGAL_REQUEST &&
1520
	    sshdr.asc == 0x24 && sshdr.ascq == 0x0)
1445
	    sshdr.asc == 0x24 && sshdr.ascq == 0x0)
1521
		printk(KERN_NOTICE "%s: cache data unavailable\n",
1446
		/* Invalid field in CDB */
1522
		       diskname);	/* Invalid field in CDB */
1447
		sd_printk(KERN_NOTICE, sdkp, "Cache data unavailable\n");
1523
	else
1448
	else
1524
		printk(KERN_ERR "%s: asking for cache data failed\n",
1449
		sd_printk(KERN_ERR, sdkp, "Asking for cache data failed\n");
1525
		       diskname);
1526
1450
1527
defaults:
1451
defaults:
1528
	printk(KERN_ERR "%s: assuming drive cache: write through\n",
1452
	sd_printk(KERN_ERR, sdkp, "Assuming drive cache: write through\n");
1529
	       diskname);
1530
	sdkp->WCE = 0;
1453
	sdkp->WCE = 0;
1531
	sdkp->RCD = 0;
1454
	sdkp->RCD = 0;
1532
	sdkp->DPOFUA = 0;
1455
	sdkp->DPOFUA = 0;
Lines 1555-1562 static int sd_revalidate_disk(struct gendisk *disk) Link Here
1555
1478
1556
	buffer = kmalloc(SD_BUF_SIZE, GFP_KERNEL | __GFP_DMA);
1479
	buffer = kmalloc(SD_BUF_SIZE, GFP_KERNEL | __GFP_DMA);
1557
	if (!buffer) {
1480
	if (!buffer) {
1558
		printk(KERN_WARNING "(sd_revalidate_disk:) Memory allocation "
1481
		sd_printk(KERN_WARNING, sdkp, "sd_revalidate_disk: Memory "
1559
		       "failure.\n");
1482
			  "allocation failure.\n");
1560
		goto out;
1483
		goto out;
1561
	}
1484
	}
1562
1485
Lines 1568-1583 static int sd_revalidate_disk(struct gendisk *disk) Link Here
1568
	sdkp->WCE = 0;
1491
	sdkp->WCE = 0;
1569
	sdkp->RCD = 0;
1492
	sdkp->RCD = 0;
1570
1493
1571
	sd_spinup_disk(sdkp, disk->disk_name);
1494
	sd_spinup_disk(sdkp);
1572
1495
1573
	/*
1496
	/*
1574
	 * Without media there is no reason to ask; moreover, some devices
1497
	 * Without media there is no reason to ask; moreover, some devices
1575
	 * react badly if we do.
1498
	 * react badly if we do.
1576
	 */
1499
	 */
1577
	if (sdkp->media_present) {
1500
	if (sdkp->media_present) {
1578
		sd_read_capacity(sdkp, disk->disk_name, buffer);
1501
		sd_read_capacity(sdkp, buffer);
1579
		sd_read_write_protect_flag(sdkp, disk->disk_name, buffer);
1502
		sd_read_write_protect_flag(sdkp, buffer);
1580
		sd_read_cache_type(sdkp, disk->disk_name, buffer);
1503
		sd_read_cache_type(sdkp, buffer);
1581
	}
1504
	}
1582
1505
1583
	/*
1506
	/*
Lines 1709-1716 static int sd_probe(struct device *dev) Link Here
1709
	dev_set_drvdata(dev, sdkp);
1632
	dev_set_drvdata(dev, sdkp);
1710
	add_disk(gd);
1633
	add_disk(gd);
1711
1634
1712
	sdev_printk(KERN_NOTICE, sdp, "Attached scsi %sdisk %s\n",
1635
	sd_printk(KERN_NOTICE, sdkp, "Attached SCSI %sdisk\n",
1713
		    sdp->removable ? "removable " : "", gd->disk_name);
1636
		  sdp->removable ? "removable " : "");
1714
1637
1715
	return 0;
1638
	return 0;
1716
1639
Lines 1781-1796 static void scsi_disk_release(struct class_device *cdev) Link Here
1781
 */
1704
 */
1782
static void sd_shutdown(struct device *dev)
1705
static void sd_shutdown(struct device *dev)
1783
{
1706
{
1784
	struct scsi_device *sdp = to_scsi_device(dev);
1785
	struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev);
1707
	struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev);
1786
1708
1787
	if (!sdkp)
1709
	if (!sdkp)
1788
		return;         /* this can happen */
1710
		return;         /* this can happen */
1789
1711
1790
	if (sdkp->WCE) {
1712
	if (sdkp->WCE) {
1791
		printk(KERN_NOTICE "Synchronizing SCSI cache for disk %s: \n",
1713
		sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n");
1792
				sdkp->disk->disk_name);
1714
		sd_sync_cache(sdkp);
1793
		sd_sync_cache(sdp);
1794
	}
1715
	}
1795
	scsi_disk_put(sdkp);
1716
	scsi_disk_put(sdkp);
1796
}
1717
}
Lines 1852-1854 static void __exit exit_sd(void) Link Here
1852
1773
1853
module_init(init_sd);
1774
module_init(init_sd);
1854
module_exit(exit_sd);
1775
module_exit(exit_sd);
1776
1777
static void sd_print_sense_hdr(struct scsi_disk *sdkp,
1778
			       struct scsi_sense_hdr *sshdr)
1779
{
1780
	sd_printk(KERN_INFO, sdkp, "");
1781
	scsi_show_sense_hdr(sshdr);
1782
	sd_printk(KERN_INFO, sdkp, "");
1783
	scsi_show_extd_sense(sshdr->asc, sshdr->ascq);
1784
}
1785
1786
static void sd_print_result(struct scsi_disk *sdkp, int result)
1787
{
1788
	sd_printk(KERN_INFO, sdkp, "");
1789
	scsi_show_result(result);
1790
}
1791
(-)a/include/scsi/sd.h (-1 / +70 lines)
Line 0 Link Here
0
--
1
#ifndef _SCSI_DISK_H
2
#define _SCSI_DISK_H
3
4
/*
5
 * More than enough for everybody ;)  The huge number of majors
6
 * is a leftover from 16bit dev_t days, we don't really need that
7
 * much numberspace.
8
 */
9
#define SD_MAJORS	16
10
11
/*
12
 * This is limited by the naming scheme enforced in sd_probe,
13
 * add another character to it if you really need more disks.
14
 */
15
#define SD_MAX_DISKS	(((26 * 26) + 26 + 1) * 26)
16
17
/*
18
 * Time out in seconds for disks and Magneto-opticals (which are slower).
19
 */
20
#define SD_TIMEOUT		(30 * HZ)
21
#define SD_MOD_TIMEOUT		(75 * HZ)
22
23
/*
24
 * Number of allowed retries
25
 */
26
#define SD_MAX_RETRIES		5
27
#define SD_PASSTHROUGH_RETRIES	1
28
29
/*
30
 * Size of the initial data buffer for mode and read capacity data
31
 */
32
#define SD_BUF_SIZE		512
33
34
struct scsi_disk {
35
	struct scsi_driver *driver;	/* always &sd_template */
36
	struct scsi_device *device;
37
	struct class_device cdev;
38
	struct gendisk	*disk;
39
	unsigned int	openers;	/* protected by BKL for now, yuck */
40
	sector_t	capacity;	/* size in 512-byte sectors */
41
	u32		index;
42
	u8		media_present;
43
	u8		write_prot;
44
	unsigned	WCE : 1;	/* state of disk WCE bit */
45
	unsigned	RCD : 1;	/* state of disk RCD bit, unused */
46
	unsigned	DPOFUA : 1;	/* state of disk DPOFUA bit */
47
};
48
#define to_scsi_disk(obj) container_of(obj,struct scsi_disk,cdev)
49
50
static int  sd_revalidate_disk(struct gendisk *disk);
51
static void sd_rw_intr(struct scsi_cmnd * SCpnt);
52
static int  sd_probe(struct device *);
53
static int  sd_remove(struct device *);
54
static void sd_shutdown(struct device *dev);
55
static void sd_rescan(struct device *);
56
static int  sd_init_command(struct scsi_cmnd *);
57
static int  sd_issue_flush(struct device *, sector_t *);
58
static void sd_prepare_flush(request_queue_t *, struct request *);
59
static void sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer);
60
static void scsi_disk_release(struct class_device *cdev);
61
static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *);
62
static void sd_print_result(struct scsi_disk *, int);
63
64
#define sd_printk(prefix, sdsk, fmt, a...)				\
65
        (sdsk)->disk ?							\
66
	sdev_printk(prefix, (sdsk)->device, "[%s] " fmt,		\
67
		    (sdsk)->disk->disk_name, ##a) :			\
68
	sdev_printk(prefix, (sdsk)->device, fmt, ##a)
69
70
#endif /* _SCSI_DISK_H */
(-)a/drivers/scsi/sd.c (-2 / +3 lines)
Lines 766-772 static int sd_sync_cache(struct scsi_disk *sdkp) Link Here
766
			sd_print_sense_hdr(sdkp, &sshdr);
766
			sd_print_sense_hdr(sdkp, &sshdr);
767
	}
767
	}
768
768
769
	return res;
769
	if (res)
770
		return -EIO;
771
	return 0;
770
}
772
}
771
773
772
static int sd_issue_flush(struct device *dev, sector_t *error_sector)
774
static int sd_issue_flush(struct device *dev, sector_t *error_sector)
773
--
(-)a/drivers/scsi/scsi_sysfs.c (-4 / +27 lines)
Lines 278-283 static int scsi_bus_match(struct device *dev, struct device_driver *gendrv) Link Here
278
278
279
static int scsi_bus_suspend(struct device * dev, pm_message_t state)
279
static int scsi_bus_suspend(struct device * dev, pm_message_t state)
280
{
280
{
281
	struct device_driver *drv = dev->driver;
281
	struct scsi_device *sdev = to_scsi_device(dev);
282
	struct scsi_device *sdev = to_scsi_device(dev);
282
	struct scsi_host_template *sht = sdev->host->hostt;
283
	struct scsi_host_template *sht = sdev->host->hostt;
283
	int err;
284
	int err;
Lines 286-308 static int scsi_bus_suspend(struct device * dev, pm_message_t state) Link Here
286
	if (err)
287
	if (err)
287
		return err;
288
		return err;
288
289
289
	if (sht->suspend)
290
	/* call HLD suspend first */
291
	if (drv && drv->suspend) {
292
		err = drv->suspend(dev, state);
293
		if (err)
294
			return err;
295
	}
296
297
	/* then, call host suspend */
298
	if (sht->suspend) {
290
		err = sht->suspend(sdev, state);
299
		err = sht->suspend(sdev, state);
300
		if (err) {
301
			if (drv && drv->resume)
302
				drv->resume(dev);
303
			return err;
304
		}
305
	}
291
306
292
	return err;
307
	return 0;
293
}
308
}
294
309
295
static int scsi_bus_resume(struct device * dev)
310
static int scsi_bus_resume(struct device * dev)
296
{
311
{
312
	struct device_driver *drv = dev->driver;
297
	struct scsi_device *sdev = to_scsi_device(dev);
313
	struct scsi_device *sdev = to_scsi_device(dev);
298
	struct scsi_host_template *sht = sdev->host->hostt;
314
	struct scsi_host_template *sht = sdev->host->hostt;
299
	int err = 0;
315
	int err = 0, err2 = 0;
300
316
317
	/* call host resume first */
301
	if (sht->resume)
318
	if (sht->resume)
302
		err = sht->resume(sdev);
319
		err = sht->resume(sdev);
303
320
321
	/* then, call HLD resume */
322
	if (drv && drv->resume)
323
		err2 = drv->resume(dev);
324
304
	scsi_device_resume(sdev);
325
	scsi_device_resume(sdev);
305
	return err;
326
327
	/* favor LLD failure */
328
	return err ? err : err2;;
306
}
329
}
307
330
308
struct bus_type scsi_bus_type = {
331
struct bus_type scsi_bus_type = {
(-)a/drivers/scsi/sd.c (+101 lines)
Lines 147-152 static ssize_t sd_store_cache_type(struct class_device *cdev, const char *buf, Link Here
147
	return count;
147
	return count;
148
}
148
}
149
149
150
static ssize_t sd_store_manage_start_stop(struct class_device *cdev,
151
					  const char *buf, size_t count)
152
{
153
	struct scsi_disk *sdkp = to_scsi_disk(cdev);
154
	struct scsi_device *sdp = sdkp->device;
155
156
	if (!capable(CAP_SYS_ADMIN))
157
		return -EACCES;
158
159
	sdp->manage_start_stop = simple_strtoul(buf, NULL, 10);
160
161
	return count;
162
}
163
150
static ssize_t sd_store_allow_restart(struct class_device *cdev, const char *buf,
164
static ssize_t sd_store_allow_restart(struct class_device *cdev, const char *buf,
151
				      size_t count)
165
				      size_t count)
152
{
166
{
Lines 179-184 static ssize_t sd_show_fua(struct class_device *cdev, char *buf) Link Here
179
	return snprintf(buf, 20, "%u\n", sdkp->DPOFUA);
193
	return snprintf(buf, 20, "%u\n", sdkp->DPOFUA);
180
}
194
}
181
195
196
static ssize_t sd_show_manage_start_stop(struct class_device *cdev, char *buf)
197
{
198
	struct scsi_disk *sdkp = to_scsi_disk(cdev);
199
	struct scsi_device *sdp = sdkp->device;
200
201
	return snprintf(buf, 20, "%u\n", sdp->manage_start_stop);
202
}
203
182
static ssize_t sd_show_allow_restart(struct class_device *cdev, char *buf)
204
static ssize_t sd_show_allow_restart(struct class_device *cdev, char *buf)
183
{
205
{
184
	struct scsi_disk *sdkp = to_scsi_disk(cdev);
206
	struct scsi_disk *sdkp = to_scsi_disk(cdev);
Lines 192-197 static struct class_device_attribute sd_disk_attrs[] = { Link Here
192
	__ATTR(FUA, S_IRUGO, sd_show_fua, NULL),
214
	__ATTR(FUA, S_IRUGO, sd_show_fua, NULL),
193
	__ATTR(allow_restart, S_IRUGO|S_IWUSR, sd_show_allow_restart,
215
	__ATTR(allow_restart, S_IRUGO|S_IWUSR, sd_show_allow_restart,
194
	       sd_store_allow_restart),
216
	       sd_store_allow_restart),
217
	__ATTR(manage_start_stop, S_IRUGO|S_IWUSR, sd_show_manage_start_stop,
218
	       sd_store_manage_start_stop),
195
	__ATTR_NULL,
219
	__ATTR_NULL,
196
};
220
};
197
221
Lines 208-213 static struct scsi_driver sd_template = { Link Here
208
		.name		= "sd",
232
		.name		= "sd",
209
		.probe		= sd_probe,
233
		.probe		= sd_probe,
210
		.remove		= sd_remove,
234
		.remove		= sd_remove,
235
		.suspend	= sd_suspend,
236
		.resume		= sd_resume,
211
		.shutdown	= sd_shutdown,
237
		.shutdown	= sd_shutdown,
212
	},
238
	},
213
	.rescan			= sd_rescan,
239
	.rescan			= sd_rescan,
Lines 1707-1712 static void scsi_disk_release(struct class_device *cdev) Link Here
1707
	kfree(sdkp);
1733
	kfree(sdkp);
1708
}
1734
}
1709
1735
1736
static int sd_start_stop_device(struct scsi_device *sdp, int start)
1737
{
1738
	unsigned char cmd[6] = { START_STOP };	/* START_VALID */
1739
	struct scsi_sense_hdr sshdr;
1740
	int res;
1741
1742
	if (start)
1743
		cmd[4] |= 1;	/* START */
1744
1745
	if (!scsi_device_online(sdp))
1746
		return -ENODEV;
1747
1748
	res = scsi_execute_req(sdp, cmd, DMA_NONE, NULL, 0, &sshdr,
1749
			       SD_TIMEOUT, SD_MAX_RETRIES);
1750
	if (res) {
1751
		printk(KERN_WARNING "FAILED\n  status = %x, message = %02x, "
1752
		       "host = %d, driver = %02x\n  ",
1753
		       status_byte(res), msg_byte(res),
1754
		       host_byte(res), driver_byte(res));
1755
		if (driver_byte(res) & DRIVER_SENSE)
1756
			scsi_print_sense_hdr("sd", &sshdr);
1757
	}
1758
1759
	return res;
1760
}
1761
1710
/*
1762
/*
1711
 * Send a SYNCHRONIZE CACHE instruction down to the device through
1763
 * Send a SYNCHRONIZE CACHE instruction down to the device through
1712
 * the normal SCSI command structure.  Wait for the command to
1764
 * the normal SCSI command structure.  Wait for the command to
Lines 1714-1719 static void scsi_disk_release(struct class_device *cdev) Link Here
1714
 */
1766
 */
1715
static void sd_shutdown(struct device *dev)
1767
static void sd_shutdown(struct device *dev)
1716
{
1768
{
1769
	struct scsi_device *sdp = to_scsi_device(dev);
1717
	struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev);
1770
	struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev);
1718
1771
1719
	if (!sdkp)
1772
	if (!sdkp)
Lines 1723-1731 static void sd_shutdown(struct device *dev) Link Here
1723
		sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n");
1776
		sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n");
1724
		sd_sync_cache(sdkp);
1777
		sd_sync_cache(sdkp);
1725
	}
1778
	}
1779
1780
	if (system_state != SYSTEM_RESTART && sdp->manage_start_stop) {
1781
		printk(KERN_NOTICE "Stopping disk %s: \n",
1782
		       sdkp->disk->disk_name);
1783
		sd_start_stop_device(sdp, 0);
1784
	}
1785
1726
	scsi_disk_put(sdkp);
1786
	scsi_disk_put(sdkp);
1727
}
1787
}
1728
1788
1789
static int sd_suspend(struct device *dev, pm_message_t mesg)
1790
{
1791
	struct scsi_device *sdp = to_scsi_device(dev);
1792
	struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev);
1793
	int ret;
1794
1795
	if (!sdkp)
1796
		return 0;	/* this can happen */
1797
1798
	if (sdkp->WCE) {
1799
		printk(KERN_NOTICE "Synchronizing SCSI cache for disk %s: \n",
1800
				sdkp->disk->disk_name);
1801
		ret = sd_sync_cache(sdkp);
1802
		if (ret)
1803
			return ret;
1804
	}
1805
1806
	if (mesg.event == PM_EVENT_SUSPEND && sdp->manage_start_stop) {
1807
		printk(KERN_NOTICE "Stopping disk %s: \n",
1808
		       sdkp->disk->disk_name);
1809
		ret = sd_start_stop_device(sdp, 0);
1810
		if (ret)
1811
			return ret;
1812
	}
1813
1814
	return 0;
1815
}
1816
1817
static int sd_resume(struct device *dev)
1818
{
1819
	struct scsi_device *sdp = to_scsi_device(dev);
1820
	struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev);
1821
1822
	if (!sdp->manage_start_stop)
1823
		return 0;
1824
1825
	printk(KERN_NOTICE "Starting disk %s: \n", sdkp->disk->disk_name);
1826
1827
	return sd_start_stop_device(sdp, 1);
1828
}
1829
1729
/**
1830
/**
1730
 *	init_sd - entry point for this driver (both when built in or when
1831
 *	init_sd - entry point for this driver (both when built in or when
1731
 *	a module).
1832
 *	a module).
(-)a/include/scsi/scsi_device.h (+1 lines)
Lines 120-125 struct scsi_device { Link Here
120
	unsigned use_192_bytes_for_3f:1; /* ask for 192 bytes from page 0x3f */
120
	unsigned use_192_bytes_for_3f:1; /* ask for 192 bytes from page 0x3f */
121
	unsigned no_start_on_add:1;	/* do not issue start on add */
121
	unsigned no_start_on_add:1;	/* do not issue start on add */
122
	unsigned allow_restart:1; /* issue START_UNIT in error handler */
122
	unsigned allow_restart:1; /* issue START_UNIT in error handler */
123
	unsigned manage_start_stop:1;	/* Let HLD (sd) manage start/stop */
123
	unsigned no_uld_attach:1; /* disable connecting to upper level drivers */
124
	unsigned no_uld_attach:1; /* disable connecting to upper level drivers */
124
	unsigned select_no_atn:1;
125
	unsigned select_no_atn:1;
125
	unsigned fix_capacity:1;	/* READ_CAPACITY is too high by 1 */
126
	unsigned fix_capacity:1;	/* READ_CAPACITY is too high by 1 */
(-)a/include/scsi/sd.h (-1 / +2 lines)
Lines 52-57 static void sd_rw_intr(struct scsi_cmnd * SCpnt); Link Here
52
static int  sd_probe(struct device *);
52
static int  sd_probe(struct device *);
53
static int  sd_remove(struct device *);
53
static int  sd_remove(struct device *);
54
static void sd_shutdown(struct device *dev);
54
static void sd_shutdown(struct device *dev);
55
static int sd_suspend(struct device *dev, pm_message_t state);
56
static int sd_resume(struct device *dev);
55
static void sd_rescan(struct device *);
57
static void sd_rescan(struct device *);
56
static int  sd_init_command(struct scsi_cmnd *);
58
static int  sd_init_command(struct scsi_cmnd *);
57
static int  sd_issue_flush(struct device *, sector_t *);
59
static int  sd_issue_flush(struct device *, sector_t *);
58
 code is simplified a lot.
60
 code is simplified a lot.
59
 status is port-wide now.
61
 status is port-wide now.
60
 couldn't find easy way out as libata is in EH waiting for the
62
 couldn't find easy way out as libata is in EH waiting for the
61
 disk to be ready and sd is waiting for EH to complete to issue
63
 disk to be ready and sd is waiting for EH to complete to issue
62
 START_STOP.
64
 START_STOP.
63
 This fixes spindown on shutdown and suspend-to-disk.
65
 This fixes spindown on shutdown and suspend-to-disk.
64
--
65
drivers/ata/ahci.c              |    4 -
66
drivers/ata/ahci.c              |    4 -
66
drivers/ata/ata_generic.c       |    6 +-
67
drivers/ata/ata_generic.c       |    6 +-
67
drivers/ata/ata_piix.c          |    4 -
68
drivers/ata/ata_piix.c          |    4 -
68
drivers/ata/libata-core.c       |   39 +------
69
drivers/ata/libata-core.c       |   39 +------
69
drivers/ata/libata-eh.c         |  237 +--------------------------------------
70
drivers/ata/libata-eh.c         |  237 +--------------------------------------
70
drivers/ata/libata-scsi.c       |  129 +---------------------
71
drivers/ata/libata-scsi.c       |  129 +---------------------
71
drivers/ata/pata_ali.c          |    4 -
72
drivers/ata/pata_ali.c          |    4 -
72
drivers/ata/pata_amd.c          |    4 -
73
drivers/ata/pata_amd.c          |    4 -
73
drivers/ata/pata_atiixp.c       |    4 -
74
drivers/ata/pata_atiixp.c       |    4 -
74
drivers/ata/pata_cmd64x.c       |    4 -
75
drivers/ata/pata_cmd64x.c       |    4 -
75
drivers/ata/pata_cs5520.c       |    4 -
76
drivers/ata/pata_cs5520.c       |    4 -
76
drivers/ata/pata_cs5530.c       |    4 -
77
drivers/ata/pata_cs5530.c       |    4 -
77
drivers/ata/pata_cs5535.c       |    4 -
78
drivers/ata/pata_cs5535.c       |    4 -
78
drivers/ata/pata_cypress.c      |    4 -
79
drivers/ata/pata_cypress.c      |    4 -
79
drivers/ata/pata_efar.c         |    4 -
80
drivers/ata/pata_efar.c         |    4 -
80
drivers/ata/pata_hpt366.c       |    4 -
81
drivers/ata/pata_hpt366.c       |    4 -
81
drivers/ata/pata_hpt3x3.c       |    4 -
82
drivers/ata/pata_hpt3x3.c       |    4 -
82
drivers/ata/pata_it8213.c       |    4 -
83
drivers/ata/pata_it8213.c       |    4 -
83
drivers/ata/pata_it821x.c       |    4 -
84
drivers/ata/pata_it821x.c       |    4 -
84
drivers/ata/pata_ixp4xx_cf.c    |    2 +-
85
drivers/ata/pata_ixp4xx_cf.c    |    2 +-
85
drivers/ata/pata_jmicron.c      |    4 -
86
drivers/ata/pata_jmicron.c      |    4 -
86
drivers/ata/pata_marvell.c      |    4 -
87
drivers/ata/pata_marvell.c      |    4 -
87
drivers/ata/pata_mpc52xx.c      |    4 -
88
drivers/ata/pata_mpc52xx.c      |    4 -
88
drivers/ata/pata_mpiix.c        |    4 -
89
drivers/ata/pata_mpiix.c        |    4 -
89
drivers/ata/pata_netcell.c      |    4 -
90
drivers/ata/pata_netcell.c      |    4 -
90
drivers/ata/pata_ns87410.c      |    4 -
91
drivers/ata/pata_ns87410.c      |    4 -
91
drivers/ata/pata_oldpiix.c      |    4 -
92
drivers/ata/pata_oldpiix.c      |    4 -
92
drivers/ata/pata_opti.c         |    4 -
93
drivers/ata/pata_opti.c         |    4 -
93
drivers/ata/pata_optidma.c      |    4 -
94
drivers/ata/pata_optidma.c      |    4 -
94
drivers/ata/pata_pdc202xx_old.c |    4 -
95
drivers/ata/pata_pdc202xx_old.c |    4 -
95
drivers/ata/pata_radisys.c      |    4 -
96
drivers/ata/pata_radisys.c      |    4 -
96
drivers/ata/pata_rz1000.c       |    6 +-
97
drivers/ata/pata_rz1000.c       |    6 +-
97
drivers/ata/pata_sc1200.c       |    4 -
98
drivers/ata/pata_sc1200.c       |    4 -
98
drivers/ata/pata_scc.c          |    4 -
99
drivers/ata/pata_scc.c          |    4 -
99
drivers/ata/pata_serverworks.c  |    4 -
100
drivers/ata/pata_serverworks.c  |    4 -
100
drivers/ata/pata_sil680.c       |    4 -
101
drivers/ata/pata_sil680.c       |    4 -
101
drivers/ata/pata_sis.c          |    4 -
102
drivers/ata/pata_sis.c          |    4 -
102
drivers/ata/pata_triflex.c      |    4 -
103
drivers/ata/pata_triflex.c      |    4 -
103
drivers/ata/pata_via.c          |    4 -
104
drivers/ata/pata_via.c          |    4 -
104
drivers/ata/sata_inic162x.c     |    4 -
105
drivers/ata/sata_inic162x.c     |    4 -
105
drivers/ata/sata_nv.c           |    8 --
106
drivers/ata/sata_nv.c           |    8 --
106
drivers/ata/sata_sil.c          |    4 -
107
drivers/ata/sata_sil.c          |    4 -
107
drivers/ata/sata_sil24.c        |    4 -
108
drivers/ata/sata_sil24.c        |    4 -
108
include/linux/libata.h          |   14 +--
109
include/linux/libata.h          |   14 +--
109
44 files changed, 14 insertions(+), 571 deletions(-)
110
44 files changed, 14 insertions(+), 571 deletions(-)
(-)a/drivers/ata/ahci.c (-4 lines)
Lines 250-259 static struct scsi_host_template ahci_sh Link Here
250
	.slave_configure	= ata_scsi_slave_config,
250
	.slave_configure	= ata_scsi_slave_config,
251
	.slave_destroy		= ata_scsi_slave_destroy,
251
	.slave_destroy		= ata_scsi_slave_destroy,
252
	.bios_param		= ata_std_bios_param,
252
	.bios_param		= ata_std_bios_param,
253
#ifdef CONFIG_PM
254
	.suspend		= ata_scsi_device_suspend,
255
	.resume			= ata_scsi_device_resume,
256
#endif
257
};
253
};
258
254
259
static const struct ata_port_operations ahci_ops = {
255
static const struct ata_port_operations ahci_ops = {
(-)a/drivers/ata/ata_generic.c (-5 / +1 lines)
Lines 54-60 static int generic_set_mode(struct ata_p Link Here
54
54
55
	for (i = 0; i < ATA_MAX_DEVICES; i++) {
55
	for (i = 0; i < ATA_MAX_DEVICES; i++) {
56
		struct ata_device *dev = &ap->device[i];
56
		struct ata_device *dev = &ap->device[i];
57
		if (ata_dev_ready(dev)) {
57
		if (ata_dev_enabled(dev)) {
58
			/* We don't really care */
58
			/* We don't really care */
59
			dev->pio_mode = XFER_PIO_0;
59
			dev->pio_mode = XFER_PIO_0;
60
			dev->dma_mode = XFER_MW_DMA_0;
60
			dev->dma_mode = XFER_MW_DMA_0;
Lines 90-99 static struct scsi_host_template generic Link Here
90
	.slave_configure	= ata_scsi_slave_config,
90
	.slave_configure	= ata_scsi_slave_config,
91
	.slave_destroy		= ata_scsi_slave_destroy,
91
	.slave_destroy		= ata_scsi_slave_destroy,
92
	.bios_param		= ata_std_bios_param,
92
	.bios_param		= ata_std_bios_param,
93
#ifdef CONFIG_PM
94
	.resume			= ata_scsi_device_resume,
95
	.suspend		= ata_scsi_device_suspend,
96
#endif
97
};
93
};
98
94
99
static struct ata_port_operations generic_port_ops = {
95
static struct ata_port_operations generic_port_ops = {
(-)a/drivers/ata/ata_piix.c (-4 lines)
Lines 275-284 static struct scsi_host_template piix_sh Link Here
275
	.slave_configure	= ata_scsi_slave_config,
275
	.slave_configure	= ata_scsi_slave_config,
276
	.slave_destroy		= ata_scsi_slave_destroy,
276
	.slave_destroy		= ata_scsi_slave_destroy,
277
	.bios_param		= ata_std_bios_param,
277
	.bios_param		= ata_std_bios_param,
278
#ifdef CONFIG_PM
279
	.resume			= ata_scsi_device_resume,
280
	.suspend		= ata_scsi_device_suspend,
281
#endif
282
};
278
};
283
279
284
static const struct ata_port_operations piix_pata_ops = {
280
static const struct ata_port_operations piix_pata_ops = {
(-)a/drivers/ata/libata-core.c (-35 / +4 lines)
Lines 2858-2864 int ata_do_set_mode(struct ata_port *ap, Link Here
2858
		dev = &ap->device[i];
2858
		dev = &ap->device[i];
2859
2859
2860
		/* don't update suspended devices' xfer mode */
2860
		/* don't update suspended devices' xfer mode */
2861
		if (!ata_dev_ready(dev))
2861
		if (!ata_dev_enabled(dev))
2862
			continue;
2862
			continue;
2863
2863
2864
		rc = ata_dev_set_mode(dev);
2864
		rc = ata_dev_set_mode(dev);
Lines 5793-5829 static int ata_host_request_pm(struct at Link Here
5793
 */
5793
 */
5794
int ata_host_suspend(struct ata_host *host, pm_message_t mesg)
5794
int ata_host_suspend(struct ata_host *host, pm_message_t mesg)
5795
{
5795
{
5796
	int i, j, rc;
5796
	int rc;
5797
5797
5798
	rc = ata_host_request_pm(host, mesg, 0, ATA_EHI_QUIET, 1);
5798
	rc = ata_host_request_pm(host, mesg, 0, ATA_EHI_QUIET, 1);
5799
	if (rc)
5799
	if (rc == 0)
5800
		goto fail;
5800
		host->dev->power.power_state = mesg;
5801
5802
	/* EH is quiescent now.  Fail if we have any ready device.
5803
	 * This happens if hotplug occurs between completion of device
5804
	 * suspension and here.
5805
	 */
5806
	for (i = 0; i < host->n_ports; i++) {
5807
		struct ata_port *ap = host->ports[i];
5808
5809
		for (j = 0; j < ATA_MAX_DEVICES; j++) {
5810
			struct ata_device *dev = &ap->device[j];
5811
5812
			if (ata_dev_ready(dev)) {
5813
				ata_port_printk(ap, KERN_WARNING,
5814
						"suspend failed, device %d "
5815
						"still active\n", dev->devno);
5816
				rc = -EBUSY;
5817
				goto fail;
5818
			}
5819
		}
5820
	}
5821
5822
	host->dev->power.power_state = mesg;
5823
	return 0;
5824
5825
 fail:
5826
	ata_host_resume(host);
5827
	return rc;
5801
	return rc;
5828
}
5802
}
5829
5803
Lines 6836-6846 EXPORT_SYMBOL_GPL(ata_pci_default_filter Link Here
6836
EXPORT_SYMBOL_GPL(ata_pci_clear_simplex);
6810
EXPORT_SYMBOL_GPL(ata_pci_clear_simplex);
6837
#endif /* CONFIG_PCI */
6811
#endif /* CONFIG_PCI */
6838
6812
6839
#ifdef CONFIG_PM
6840
EXPORT_SYMBOL_GPL(ata_scsi_device_suspend);
6841
EXPORT_SYMBOL_GPL(ata_scsi_device_resume);
6842
#endif /* CONFIG_PM */
6843
6844
EXPORT_SYMBOL_GPL(ata_eng_timeout);
6813
EXPORT_SYMBOL_GPL(ata_eng_timeout);
6845
EXPORT_SYMBOL_GPL(ata_port_schedule_eh);
6814
EXPORT_SYMBOL_GPL(ata_port_schedule_eh);
6846
EXPORT_SYMBOL_GPL(ata_port_abort);
6815
EXPORT_SYMBOL_GPL(ata_port_abort);
(-)a/drivers/ata/libata-eh.c (-233 / +4 lines)
Lines 55-83 static void ata_eh_finish(struct ata_por Link Here
55
#ifdef CONFIG_PM
55
#ifdef CONFIG_PM
56
static void ata_eh_handle_port_suspend(struct ata_port *ap);
56
static void ata_eh_handle_port_suspend(struct ata_port *ap);
57
static void ata_eh_handle_port_resume(struct ata_port *ap);
57
static void ata_eh_handle_port_resume(struct ata_port *ap);
58
static int ata_eh_suspend(struct ata_port *ap,
59
			  struct ata_device **r_failed_dev);
60
static void ata_eh_prep_resume(struct ata_port *ap);
61
static int ata_eh_resume(struct ata_port *ap, struct ata_device **r_failed_dev);
62
#else /* CONFIG_PM */
58
#else /* CONFIG_PM */
63
static void ata_eh_handle_port_suspend(struct ata_port *ap)
59
static void ata_eh_handle_port_suspend(struct ata_port *ap)
64
{ }
60
{ }
65
61
66
static void ata_eh_handle_port_resume(struct ata_port *ap)
62
static void ata_eh_handle_port_resume(struct ata_port *ap)
67
{ }
63
{ }
68
69
static int ata_eh_suspend(struct ata_port *ap, struct ata_device **r_failed_dev)
70
{
71
	return 0;
72
}
73
74
static void ata_eh_prep_resume(struct ata_port *ap)
75
{ }
76
77
static int ata_eh_resume(struct ata_port *ap, struct ata_device **r_failed_dev)
78
{
79
	return 0;
80
}
81
#endif /* CONFIG_PM */
64
#endif /* CONFIG_PM */
82
65
83
static void ata_ering_record(struct ata_ering *ering, int is_io,
66
static void ata_ering_record(struct ata_ering *ering, int is_io,
Lines 1767-1773 static int ata_eh_revalidate_and_attach( Link Here
1767
		if (ehc->i.flags & ATA_EHI_DID_RESET)
1750
		if (ehc->i.flags & ATA_EHI_DID_RESET)
1768
			readid_flags |= ATA_READID_POSTRESET;
1751
			readid_flags |= ATA_READID_POSTRESET;
1769
1752
1770
		if (action & ATA_EH_REVALIDATE && ata_dev_ready(dev)) {
1753
		if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) {
1771
			if (ata_port_offline(ap)) {
1754
			if (ata_port_offline(ap)) {
1772
				rc = -EIO;
1755
				rc = -EIO;
1773
				goto err;
1756
				goto err;
Lines 1848-2013 static int ata_eh_revalidate_and_attach( Link Here
1848
	return rc;
1831
	return rc;
1849
}
1832
}
1850
1833
1851
#ifdef CONFIG_PM
1852
/**
1853
 *	ata_eh_suspend - handle suspend EH action
1854
 *	@ap: target host port
1855
 *	@r_failed_dev: result parameter to indicate failing device
1856
 *
1857
 *	Handle suspend EH action.  Disk devices are spinned down and
1858
 *	other types of devices are just marked suspended.  Once
1859
 *	suspended, no EH action to the device is allowed until it is
1860
 *	resumed.
1861
 *
1862
 *	LOCKING:
1863
 *	Kernel thread context (may sleep).
1864
 *
1865
 *	RETURNS:
1866
 *	0 on success, -errno otherwise
1867
 */
1868
static int ata_eh_suspend(struct ata_port *ap, struct ata_device **r_failed_dev)
1869
{
1870
	struct ata_device *dev;
1871
	int i, rc = 0;
1872
1873
	DPRINTK("ENTER\n");
1874
1875
	for (i = 0; i < ATA_MAX_DEVICES; i++) {
1876
		unsigned long flags;
1877
		unsigned int action, err_mask;
1878
1879
		dev = &ap->device[i];
1880
		action = ata_eh_dev_action(dev);
1881
1882
		if (!ata_dev_enabled(dev) || !(action & ATA_EH_SUSPEND))
1883
			continue;
1884
1885
		WARN_ON(dev->flags & ATA_DFLAG_SUSPENDED);
1886
1887
		ata_eh_about_to_do(ap, dev, ATA_EH_SUSPEND);
1888
1889
		if (dev->class == ATA_DEV_ATA && !(action & ATA_EH_PM_FREEZE)) {
1890
			/* flush cache */
1891
			rc = ata_flush_cache(dev);
1892
			if (rc)
1893
				break;
1894
1895
			/* spin down */
1896
			err_mask = ata_do_simple_cmd(dev, ATA_CMD_STANDBYNOW1);
1897
			if (err_mask) {
1898
				ata_dev_printk(dev, KERN_ERR, "failed to "
1899
					       "spin down (err_mask=0x%x)\n",
1900
					       err_mask);
1901
				rc = -EIO;
1902
				break;
1903
			}
1904
		}
1905
1906
		spin_lock_irqsave(ap->lock, flags);
1907
		dev->flags |= ATA_DFLAG_SUSPENDED;
1908
		spin_unlock_irqrestore(ap->lock, flags);
1909
1910
		ata_eh_done(ap, dev, ATA_EH_SUSPEND);
1911
	}
1912
1913
	if (rc)
1914
		*r_failed_dev = dev;
1915
1916
	DPRINTK("EXIT\n");
1917
	return rc;
1918
}
1919
1920
/**
1921
 *	ata_eh_prep_resume - prep for resume EH action
1922
 *	@ap: target host port
1923
 *
1924
 *	Clear SUSPENDED in preparation for scheduled resume actions.
1925
 *	This allows other parts of EH to access the devices being
1926
 *	resumed.
1927
 *
1928
 *	LOCKING:
1929
 *	Kernel thread context (may sleep).
1930
 */
1931
static void ata_eh_prep_resume(struct ata_port *ap)
1932
{
1933
	struct ata_device *dev;
1934
	unsigned long flags;
1935
	int i;
1936
1937
	DPRINTK("ENTER\n");
1938
1939
	for (i = 0; i < ATA_MAX_DEVICES; i++) {
1940
		unsigned int action;
1941
1942
		dev = &ap->device[i];
1943
		action = ata_eh_dev_action(dev);
1944
1945
		if (!ata_dev_enabled(dev) || !(action & ATA_EH_RESUME))
1946
			continue;
1947
1948
		spin_lock_irqsave(ap->lock, flags);
1949
		dev->flags &= ~ATA_DFLAG_SUSPENDED;
1950
		spin_unlock_irqrestore(ap->lock, flags);
1951
	}
1952
1953
	DPRINTK("EXIT\n");
1954
}
1955
1956
/**
1957
 *	ata_eh_resume - handle resume EH action
1958
 *	@ap: target host port
1959
 *	@r_failed_dev: result parameter to indicate failing device
1960
 *
1961
 *	Handle resume EH action.  Target devices are already reset and
1962
 *	revalidated.  Spinning up is the only operation left.
1963
 *
1964
 *	LOCKING:
1965
 *	Kernel thread context (may sleep).
1966
 *
1967
 *	RETURNS:
1968
 *	0 on success, -errno otherwise
1969
 */
1970
static int ata_eh_resume(struct ata_port *ap, struct ata_device **r_failed_dev)
1971
{
1972
	struct ata_device *dev;
1973
	int i, rc = 0;
1974
1975
	DPRINTK("ENTER\n");
1976
1977
	for (i = 0; i < ATA_MAX_DEVICES; i++) {
1978
		unsigned int action, err_mask;
1979
1980
		dev = &ap->device[i];
1981
		action = ata_eh_dev_action(dev);
1982
1983
		if (!ata_dev_enabled(dev) || !(action & ATA_EH_RESUME))
1984
			continue;
1985
1986
		ata_eh_about_to_do(ap, dev, ATA_EH_RESUME);
1987
1988
		if (dev->class == ATA_DEV_ATA && !(action & ATA_EH_PM_FREEZE)) {
1989
			err_mask = ata_do_simple_cmd(dev,
1990
						     ATA_CMD_IDLEIMMEDIATE);
1991
			if (err_mask) {
1992
				ata_dev_printk(dev, KERN_ERR, "failed to "
1993
					       "spin up (err_mask=0x%x)\n",
1994
					       err_mask);
1995
				rc = -EIO;
1996
				break;
1997
			}
1998
		}
1999
2000
		ata_eh_done(ap, dev, ATA_EH_RESUME);
2001
	}
2002
2003
	if (rc)
2004
		*r_failed_dev = dev;
2005
2006
	DPRINTK("EXIT\n");
2007
	return 0;
2008
}
2009
#endif /* CONFIG_PM */
2010
2011
static int ata_port_nr_enabled(struct ata_port *ap)
1834
static int ata_port_nr_enabled(struct ata_port *ap)
2012
{
1835
{
2013
	int i, cnt = 0;
1836
	int i, cnt = 0;
Lines 2033-2049 static int ata_eh_skip_recovery(struct a Link Here
2033
	struct ata_eh_context *ehc = &ap->eh_context;
1856
	struct ata_eh_context *ehc = &ap->eh_context;
2034
	int i;
1857
	int i;
2035
1858
2036
	/* skip if all possible devices are suspended */
2037
	for (i = 0; i < ata_port_max_devices(ap); i++) {
2038
		struct ata_device *dev = &ap->device[i];
2039
2040
		if (!(dev->flags & ATA_DFLAG_SUSPENDED))
2041
			break;
2042
	}
2043
2044
	if (i == ata_port_max_devices(ap))
2045
		return 1;
2046
2047
	/* thaw frozen port, resume link and recover failed devices */
1859
	/* thaw frozen port, resume link and recover failed devices */
2048
	if ((ap->pflags & ATA_PFLAG_FROZEN) ||
1860
	if ((ap->pflags & ATA_PFLAG_FROZEN) ||
2049
	    (ehc->i.flags & ATA_EHI_RESUME_LINK) || ata_port_nr_enabled(ap))
1861
	    (ehc->i.flags & ATA_EHI_RESUME_LINK) || ata_port_nr_enabled(ap))
Lines 2123-2131 static int ata_eh_recover(struct ata_por Link Here
2123
	if (ap->pflags & ATA_PFLAG_UNLOADING)
1935
	if (ap->pflags & ATA_PFLAG_UNLOADING)
2124
		goto out;
1936
		goto out;
2125
1937
2126
	/* prep for resume */
2127
	ata_eh_prep_resume(ap);
2128
2129
	/* skip EH if possible. */
1938
	/* skip EH if possible. */
2130
	if (ata_eh_skip_recovery(ap))
1939
	if (ata_eh_skip_recovery(ap))
2131
		ehc->i.action = 0;
1940
		ehc->i.action = 0;
Lines 2153-2163 static int ata_eh_recover(struct ata_por Link Here
2153
	if (rc)
1962
	if (rc)
2154
		goto dev_fail;
1963
		goto dev_fail;
2155
1964
2156
	/* resume devices */
2157
	rc = ata_eh_resume(ap, &dev);
2158
	if (rc)
2159
		goto dev_fail;
2160
2161
	/* configure transfer mode if necessary */
1965
	/* configure transfer mode if necessary */
2162
	if (ehc->i.flags & ATA_EHI_SETMODE) {
1966
	if (ehc->i.flags & ATA_EHI_SETMODE) {
2163
		rc = ata_set_mode(ap, &dev);
1967
		rc = ata_set_mode(ap, &dev);
Lines 2166-2176 static int ata_eh_recover(struct ata_por Link Here
2166
		ehc->i.flags &= ~ATA_EHI_SETMODE;
1970
		ehc->i.flags &= ~ATA_EHI_SETMODE;
2167
	}
1971
	}
2168
1972
2169
	/* suspend devices */
2170
	rc = ata_eh_suspend(ap, &dev);
2171
	if (rc)
2172
		goto dev_fail;
2173
2174
	goto out;
1973
	goto out;
2175
1974
2176
 dev_fail:
1975
 dev_fail:
Lines 2366-2387 static void ata_eh_handle_port_suspend(s Link Here
2366
 *
2165
 *
2367
 *	Resume @ap.
2166
 *	Resume @ap.
2368
 *
2167
 *
2369
 *	This function also waits upto one second until all devices
2370
 *	hanging off this port requests resume EH action.  This is to
2371
 *	prevent invoking EH and thus reset multiple times on resume.
2372
 *
2373
 *	On DPM resume, where some of devices might not be resumed
2374
 *	together, this may delay port resume upto one second, but such
2375
 *	DPM resumes are rare and 1 sec delay isn't too bad.
2376
 *
2377
 *	LOCKING:
2168
 *	LOCKING:
2378
 *	Kernel thread context (may sleep).
2169
 *	Kernel thread context (may sleep).
2379
 */
2170
 */
2380
static void ata_eh_handle_port_resume(struct ata_port *ap)
2171
static void ata_eh_handle_port_resume(struct ata_port *ap)
2381
{
2172
{
2382
	unsigned long timeout;
2383
	unsigned long flags;
2173
	unsigned long flags;
2384
	int i, rc = 0;
2174
	int rc = 0;
2385
2175
2386
	/* are we resuming? */
2176
	/* are we resuming? */
2387
	spin_lock_irqsave(ap->lock, flags);
2177
	spin_lock_irqsave(ap->lock, flags);
Lines 2392-2422 static void ata_eh_handle_port_resume(st Link Here
2392
	}
2182
	}
2393
	spin_unlock_irqrestore(ap->lock, flags);
2183
	spin_unlock_irqrestore(ap->lock, flags);
2394
2184
2395
	/* spurious? */
2185
	WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
2396
	if (!(ap->pflags & ATA_PFLAG_SUSPENDED))
2397
		goto done;
2398
2186
2399
	if (ap->ops->port_resume)
2187
	if (ap->ops->port_resume)
2400
		rc = ap->ops->port_resume(ap);
2188
		rc = ap->ops->port_resume(ap);
2401
2189
2402
	/* give devices time to request EH */
2190
	/* report result */
2403
	timeout = jiffies + HZ; /* 1s max */
2404
	while (1) {
2405
		for (i = 0; i < ATA_MAX_DEVICES; i++) {
2406
			struct ata_device *dev = &ap->device[i];
2407
			unsigned int action = ata_eh_dev_action(dev);
2408
2409
			if ((dev->flags & ATA_DFLAG_SUSPENDED) &&
2410
			    !(action & ATA_EH_RESUME))
2411
				break;
2412
		}
2413
2414
		if (i == ATA_MAX_DEVICES || time_after(jiffies, timeout))
2415
			break;
2416
		msleep(10);
2417
	}
2418
2419
 done:
2420
	spin_lock_irqsave(ap->lock, flags);
2191
	spin_lock_irqsave(ap->lock, flags);
2421
	ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED);
2192
	ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED);
2422
	if (ap->pm_result) {
2193
	if (ap->pm_result) {
(-)a/drivers/ata/libata-scsi.c (-127 / +2 lines)
Lines 510-642 static void ata_dump_status(unsigned id, Link Here
510
	}
510
	}
511
}
511
}
512
512
513
#ifdef CONFIG_PM
514
/**
515
 *	ata_scsi_device_suspend - suspend ATA device associated with sdev
516
 *	@sdev: the SCSI device to suspend
517
 *	@mesg: target power management message
518
 *
519
 *	Request suspend EH action on the ATA device associated with
520
 *	@sdev and wait for the operation to complete.
521
 *
522
 *	LOCKING:
523
 *	Kernel thread context (may sleep).
524
 *
525
 *	RETURNS:
526
 *	0 on success, -errno otherwise.
527
 */
528
int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t mesg)
529
{
530
	struct ata_port *ap = ata_shost_to_port(sdev->host);
531
	struct ata_device *dev = ata_scsi_find_dev(ap, sdev);
532
	unsigned long flags;
533
	unsigned int action;
534
	int rc = 0;
535
536
	if (!dev)
537
		goto out;
538
539
	spin_lock_irqsave(ap->lock, flags);
540
541
	/* wait for the previous resume to complete */
542
	while (dev->flags & ATA_DFLAG_SUSPENDED) {
543
		spin_unlock_irqrestore(ap->lock, flags);
544
		ata_port_wait_eh(ap);
545
		spin_lock_irqsave(ap->lock, flags);
546
	}
547
548
	/* if @sdev is already detached, nothing to do */
549
	if (sdev->sdev_state == SDEV_OFFLINE ||
550
	    sdev->sdev_state == SDEV_CANCEL || sdev->sdev_state == SDEV_DEL)
551
		goto out_unlock;
552
553
	/* request suspend */
554
	action = ATA_EH_SUSPEND;
555
	if (mesg.event != PM_EVENT_SUSPEND)
556
		action |= ATA_EH_PM_FREEZE;
557
	ap->eh_info.dev_action[dev->devno] |= action;
558
	ap->eh_info.flags |= ATA_EHI_QUIET;
559
	ata_port_schedule_eh(ap);
560
561
	spin_unlock_irqrestore(ap->lock, flags);
562
563
	/* wait for EH to do the job */
564
	ata_port_wait_eh(ap);
565
566
	spin_lock_irqsave(ap->lock, flags);
567
568
	/* If @sdev is still attached but the associated ATA device
569
	 * isn't suspended, the operation failed.
570
	 */
571
	if (sdev->sdev_state != SDEV_OFFLINE &&
572
	    sdev->sdev_state != SDEV_CANCEL && sdev->sdev_state != SDEV_DEL &&
573
	    !(dev->flags & ATA_DFLAG_SUSPENDED))
574
		rc = -EIO;
575
576
 out_unlock:
577
	spin_unlock_irqrestore(ap->lock, flags);
578
 out:
579
	if (rc == 0)
580
		sdev->sdev_gendev.power.power_state = mesg;
581
	return rc;
582
}
583
584
/**
585
 *	ata_scsi_device_resume - resume ATA device associated with sdev
586
 *	@sdev: the SCSI device to resume
587
 *
588
 *	Request resume EH action on the ATA device associated with
589
 *	@sdev and return immediately.  This enables parallel
590
 *	wakeup/spinup of devices.
591
 *
592
 *	LOCKING:
593
 *	Kernel thread context (may sleep).
594
 *
595
 *	RETURNS:
596
 *	0.
597
 */
598
int ata_scsi_device_resume(struct scsi_device *sdev)
599
{
600
	struct ata_port *ap = ata_shost_to_port(sdev->host);
601
	struct ata_device *dev = ata_scsi_find_dev(ap, sdev);
602
	struct ata_eh_info *ehi = &ap->eh_info;
603
	unsigned long flags;
604
	unsigned int action;
605
606
	if (!dev)
607
		goto out;
608
609
	spin_lock_irqsave(ap->lock, flags);
610
611
	/* if @sdev is already detached, nothing to do */
612
	if (sdev->sdev_state == SDEV_OFFLINE ||
613
	    sdev->sdev_state == SDEV_CANCEL || sdev->sdev_state == SDEV_DEL)
614
		goto out_unlock;
615
616
	/* request resume */
617
	action = ATA_EH_RESUME;
618
	if (sdev->sdev_gendev.power.power_state.event == PM_EVENT_SUSPEND)
619
		__ata_ehi_hotplugged(ehi);
620
	else
621
		action |= ATA_EH_PM_FREEZE | ATA_EH_SOFTRESET;
622
	ehi->dev_action[dev->devno] |= action;
623
624
	/* We don't want autopsy and verbose EH messages.  Disable
625
	 * those if we're the only device on this link.
626
	 */
627
	if (ata_port_max_devices(ap) == 1)
628
		ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET;
629
630
	ata_port_schedule_eh(ap);
631
632
 out_unlock:
633
	spin_unlock_irqrestore(ap->lock, flags);
634
 out:
635
	sdev->sdev_gendev.power.power_state = PMSG_ON;
636
	return 0;
637
}
638
#endif /* CONFIG_PM */
639
640
/**
513
/**
641
 *	ata_to_sense_error - convert ATA error to SCSI error
514
 *	ata_to_sense_error - convert ATA error to SCSI error
642
 *	@id: ATA device number
515
 *	@id: ATA device number
Lines 929-934 int ata_scsi_slave_config(struct scsi_de Link Here
929
802
930
	blk_queue_max_phys_segments(sdev->request_queue, LIBATA_MAX_PRD);
803
	blk_queue_max_phys_segments(sdev->request_queue, LIBATA_MAX_PRD);
931
804
805
	sdev->manage_start_stop = 1;
806
932
	if (dev)
807
	if (dev)
933
		ata_scsi_dev_config(sdev, dev);
808
		ata_scsi_dev_config(sdev, dev);
934
809
(-)a/drivers/ata/pata_ali.c (-4 lines)
Lines 291-300 static struct scsi_host_template ali_sht Link Here
291
	.slave_configure	= ata_scsi_slave_config,
291
	.slave_configure	= ata_scsi_slave_config,
292
	.slave_destroy		= ata_scsi_slave_destroy,
292
	.slave_destroy		= ata_scsi_slave_destroy,
293
	.bios_param		= ata_std_bios_param,
293
	.bios_param		= ata_std_bios_param,
294
#ifdef CONFIG_PM
295
	.resume			= ata_scsi_device_resume,
296
	.suspend		= ata_scsi_device_suspend,
297
#endif
298
};
294
};
299
295
300
/*
296
/*
(-)a/drivers/ata/pata_amd.c (-4 lines)
Lines 323-332 static struct scsi_host_template amd_sht Link Here
323
	.slave_configure	= ata_scsi_slave_config,
323
	.slave_configure	= ata_scsi_slave_config,
324
	.slave_destroy		= ata_scsi_slave_destroy,
324
	.slave_destroy		= ata_scsi_slave_destroy,
325
	.bios_param		= ata_std_bios_param,
325
	.bios_param		= ata_std_bios_param,
326
#ifdef CONFIG_PM
327
	.resume			= ata_scsi_device_resume,
328
	.suspend		= ata_scsi_device_suspend,
329
#endif
330
};
326
};
331
327
332
static struct ata_port_operations amd33_port_ops = {
328
static struct ata_port_operations amd33_port_ops = {
(-)a/drivers/ata/pata_atiixp.c (-4 lines)
Lines 229-238 static struct scsi_host_template atiixp_ Link Here
229
	.slave_configure	= ata_scsi_slave_config,
229
	.slave_configure	= ata_scsi_slave_config,
230
	.slave_destroy		= ata_scsi_slave_destroy,
230
	.slave_destroy		= ata_scsi_slave_destroy,
231
	.bios_param		= ata_std_bios_param,
231
	.bios_param		= ata_std_bios_param,
232
#ifdef CONFIG_PM
233
	.resume			= ata_scsi_device_resume,
234
	.suspend		= ata_scsi_device_suspend,
235
#endif
236
};
232
};
237
233
238
static struct ata_port_operations atiixp_port_ops = {
234
static struct ata_port_operations atiixp_port_ops = {
(-)a/drivers/ata/pata_cmd64x.c (-4 lines)
Lines 266-275 static struct scsi_host_template cmd64x_ Link Here
266
	.slave_configure	= ata_scsi_slave_config,
266
	.slave_configure	= ata_scsi_slave_config,
267
	.slave_destroy		= ata_scsi_slave_destroy,
267
	.slave_destroy		= ata_scsi_slave_destroy,
268
	.bios_param		= ata_std_bios_param,
268
	.bios_param		= ata_std_bios_param,
269
#ifdef CONFIG_PM
270
	.resume			= ata_scsi_device_resume,
271
	.suspend		= ata_scsi_device_suspend,
272
#endif
273
};
269
};
274
270
275
static struct ata_port_operations cmd64x_port_ops = {
271
static struct ata_port_operations cmd64x_port_ops = {
(-)a/drivers/ata/pata_cs5520.c (-4 lines)
Lines 155-164 static struct scsi_host_template cs5520_ Link Here
155
	.slave_configure	= ata_scsi_slave_config,
155
	.slave_configure	= ata_scsi_slave_config,
156
	.slave_destroy		= ata_scsi_slave_destroy,
156
	.slave_destroy		= ata_scsi_slave_destroy,
157
	.bios_param		= ata_std_bios_param,
157
	.bios_param		= ata_std_bios_param,
158
#ifdef CONFIG_PM
159
	.resume			= ata_scsi_device_resume,
160
	.suspend		= ata_scsi_device_suspend,
161
#endif
162
};
158
};
163
159
164
static struct ata_port_operations cs5520_port_ops = {
160
static struct ata_port_operations cs5520_port_ops = {
(-)a/drivers/ata/pata_cs5530.c (-4 lines)
Lines 176-185 static struct scsi_host_template cs5530_ Link Here
176
	.slave_configure	= ata_scsi_slave_config,
176
	.slave_configure	= ata_scsi_slave_config,
177
	.slave_destroy		= ata_scsi_slave_destroy,
177
	.slave_destroy		= ata_scsi_slave_destroy,
178
	.bios_param		= ata_std_bios_param,
178
	.bios_param		= ata_std_bios_param,
179
#ifdef CONFIG_PM
180
	.resume			= ata_scsi_device_resume,
181
	.suspend		= ata_scsi_device_suspend,
182
#endif
183
};
179
};
184
180
185
static struct ata_port_operations cs5530_port_ops = {
181
static struct ata_port_operations cs5530_port_ops = {
(-)a/drivers/ata/pata_cs5535.c (-4 lines)
Lines 172-181 static struct scsi_host_template cs5535_ Link Here
172
	.slave_configure	= ata_scsi_slave_config,
172
	.slave_configure	= ata_scsi_slave_config,
173
	.slave_destroy		= ata_scsi_slave_destroy,
173
	.slave_destroy		= ata_scsi_slave_destroy,
174
	.bios_param		= ata_std_bios_param,
174
	.bios_param		= ata_std_bios_param,
175
#ifdef CONFIG_PM
176
	.resume			= ata_scsi_device_resume,
177
	.suspend		= ata_scsi_device_suspend,
178
#endif
179
};
175
};
180
176
181
static struct ata_port_operations cs5535_port_ops = {
177
static struct ata_port_operations cs5535_port_ops = {
(-)a/drivers/ata/pata_cypress.c (-4 lines)
Lines 125-134 static struct scsi_host_template cy82c69 Link Here
125
	.slave_configure	= ata_scsi_slave_config,
125
	.slave_configure	= ata_scsi_slave_config,
126
	.slave_destroy		= ata_scsi_slave_destroy,
126
	.slave_destroy		= ata_scsi_slave_destroy,
127
	.bios_param		= ata_std_bios_param,
127
	.bios_param		= ata_std_bios_param,
128
#ifdef CONFIG_PM
129
	.resume			= ata_scsi_device_resume,
130
	.suspend		= ata_scsi_device_suspend,
131
#endif
132
};
128
};
133
129
134
static struct ata_port_operations cy82c693_port_ops = {
130
static struct ata_port_operations cy82c693_port_ops = {
(-)a/drivers/ata/pata_efar.c (-4 lines)
Lines 246-255 static struct scsi_host_template efar_sh Link Here
246
	.slave_configure	= ata_scsi_slave_config,
246
	.slave_configure	= ata_scsi_slave_config,
247
	.slave_destroy		= ata_scsi_slave_destroy,
247
	.slave_destroy		= ata_scsi_slave_destroy,
248
	.bios_param		= ata_std_bios_param,
248
	.bios_param		= ata_std_bios_param,
249
#ifdef CONFIG_PM
250
	.resume			= ata_scsi_device_resume,
251
	.suspend		= ata_scsi_device_suspend,
252
#endif
253
};
249
};
254
250
255
static const struct ata_port_operations efar_ops = {
251
static const struct ata_port_operations efar_ops = {
(-)a/drivers/ata/pata_hpt366.c (-4 lines)
Lines 331-340 static struct scsi_host_template hpt36x_ Link Here
331
	.slave_configure	= ata_scsi_slave_config,
331
	.slave_configure	= ata_scsi_slave_config,
332
	.slave_destroy		= ata_scsi_slave_destroy,
332
	.slave_destroy		= ata_scsi_slave_destroy,
333
	.bios_param		= ata_std_bios_param,
333
	.bios_param		= ata_std_bios_param,
334
#ifdef CONFIG_PM
335
	.resume			= ata_scsi_device_resume,
336
	.suspend		= ata_scsi_device_suspend,
337
#endif
338
};
334
};
339
335
340
/*
336
/*
(-)a/drivers/ata/pata_hpt3x3.c (-4 lines)
Lines 100-109 static struct scsi_host_template hpt3x3_ Link Here
100
	.slave_configure	= ata_scsi_slave_config,
100
	.slave_configure	= ata_scsi_slave_config,
101
	.slave_destroy		= ata_scsi_slave_destroy,
101
	.slave_destroy		= ata_scsi_slave_destroy,
102
	.bios_param		= ata_std_bios_param,
102
	.bios_param		= ata_std_bios_param,
103
#ifdef CONFIG_PM
104
	.resume			= ata_scsi_device_resume,
105
	.suspend		= ata_scsi_device_suspend,
106
#endif
107
};
103
};
108
104
109
static struct ata_port_operations hpt3x3_port_ops = {
105
static struct ata_port_operations hpt3x3_port_ops = {
(-)a/drivers/ata/pata_it8213.c (-4 lines)
Lines 255-264 static struct scsi_host_template it8213_ Link Here
255
	.dma_boundary		= ATA_DMA_BOUNDARY,
255
	.dma_boundary		= ATA_DMA_BOUNDARY,
256
	.slave_configure	= ata_scsi_slave_config,
256
	.slave_configure	= ata_scsi_slave_config,
257
	.bios_param		= ata_std_bios_param,
257
	.bios_param		= ata_std_bios_param,
258
#ifdef CONFIG_PM
259
	.resume			= ata_scsi_device_resume,
260
	.suspend		= ata_scsi_device_suspend,
261
#endif
262
};
258
};
263
259
264
static const struct ata_port_operations it8213_ops = {
260
static const struct ata_port_operations it8213_ops = {
(-)a/drivers/ata/pata_it821x.c (-4 lines)
Lines 620-629 static struct scsi_host_template it821x_ Link Here
620
	.slave_configure	= ata_scsi_slave_config,
620
	.slave_configure	= ata_scsi_slave_config,
621
	.slave_destroy		= ata_scsi_slave_destroy,
621
	.slave_destroy		= ata_scsi_slave_destroy,
622
	.bios_param		= ata_std_bios_param,
622
	.bios_param		= ata_std_bios_param,
623
#ifdef CONFIG_PM
624
	.resume			= ata_scsi_device_resume,
625
	.suspend		= ata_scsi_device_suspend,
626
#endif
627
};
623
};
628
624
629
static struct ata_port_operations it821x_smart_port_ops = {
625
static struct ata_port_operations it821x_smart_port_ops = {
(-)a/drivers/ata/pata_ixp4xx_cf.c (-1 / +1 lines)
Lines 31-37 static int ixp4xx_set_mode(struct ata_po Link Here
31
31
32
	for (i = 0; i < ATA_MAX_DEVICES; i++) {
32
	for (i = 0; i < ATA_MAX_DEVICES; i++) {
33
		struct ata_device *dev = &ap->device[i];
33
		struct ata_device *dev = &ap->device[i];
34
		if (ata_dev_ready(dev)) {
34
		if (ata_dev_enabled(dev)) {
35
			ata_dev_printk(dev, KERN_INFO, "configured for PIO0\n");
35
			ata_dev_printk(dev, KERN_INFO, "configured for PIO0\n");
36
			dev->pio_mode = XFER_PIO_0;
36
			dev->pio_mode = XFER_PIO_0;
37
			dev->xfer_mode = XFER_PIO_0;
37
			dev->xfer_mode = XFER_PIO_0;
(-)a/drivers/ata/pata_jmicron.c (-4 lines)
Lines 137-146 static struct scsi_host_template jmicron Link Here
137
	.slave_destroy		= ata_scsi_slave_destroy,
137
	.slave_destroy		= ata_scsi_slave_destroy,
138
	/* Use standard CHS mapping rules */
138
	/* Use standard CHS mapping rules */
139
	.bios_param		= ata_std_bios_param,
139
	.bios_param		= ata_std_bios_param,
140
#ifdef CONFIG_PM
141
	.suspend		= ata_scsi_device_suspend,
142
	.resume			= ata_scsi_device_resume,
143
#endif
144
};
140
};
145
141
146
static const struct ata_port_operations jmicron_ops = {
142
static const struct ata_port_operations jmicron_ops = {
(-)a/drivers/ata/pata_marvell.c (-4 lines)
Lines 104-113 static struct scsi_host_template marvell Link Here
104
	.slave_destroy		= ata_scsi_slave_destroy,
104
	.slave_destroy		= ata_scsi_slave_destroy,
105
	/* Use standard CHS mapping rules */
105
	/* Use standard CHS mapping rules */
106
	.bios_param		= ata_std_bios_param,
106
	.bios_param		= ata_std_bios_param,
107
#ifdef CONFIG_PM
108
	.resume			= ata_scsi_device_resume,
109
	.suspend		= ata_scsi_device_suspend,
110
#endif
111
};
107
};
112
108
113
static const struct ata_port_operations marvell_ops = {
109
static const struct ata_port_operations marvell_ops = {
(-)a/drivers/ata/pata_mpc52xx.c (-4 lines)
Lines 280-289 static struct scsi_host_template mpc52xx Link Here
280
	.dma_boundary		= ATA_DMA_BOUNDARY,
280
	.dma_boundary		= ATA_DMA_BOUNDARY,
281
	.slave_configure	= ata_scsi_slave_config,
281
	.slave_configure	= ata_scsi_slave_config,
282
	.bios_param		= ata_std_bios_param,
282
	.bios_param		= ata_std_bios_param,
283
#ifdef CONFIG_PM
284
	.suspend		= ata_scsi_device_suspend,
285
	.resume			= ata_scsi_device_resume,
286
#endif
287
};
283
};
288
284
289
static struct ata_port_operations mpc52xx_ata_port_ops = {
285
static struct ata_port_operations mpc52xx_ata_port_ops = {
(-)a/drivers/ata/pata_mpiix.c (-4 lines)
Lines 164-173 static struct scsi_host_template mpiix_s Link Here
164
	.slave_configure	= ata_scsi_slave_config,
164
	.slave_configure	= ata_scsi_slave_config,
165
	.slave_destroy		= ata_scsi_slave_destroy,
165
	.slave_destroy		= ata_scsi_slave_destroy,
166
	.bios_param		= ata_std_bios_param,
166
	.bios_param		= ata_std_bios_param,
167
#ifdef CONFIG_PM
168
	.resume			= ata_scsi_device_resume,
169
	.suspend		= ata_scsi_device_suspend,
170
#endif
171
};
167
};
172
168
173
static struct ata_port_operations mpiix_port_ops = {
169
static struct ata_port_operations mpiix_port_ops = {
(-)a/drivers/ata/pata_netcell.c (-4 lines)
Lines 37-46 static struct scsi_host_template netcell Link Here
37
	.slave_destroy		= ata_scsi_slave_destroy,
37
	.slave_destroy		= ata_scsi_slave_destroy,
38
	/* Use standard CHS mapping rules */
38
	/* Use standard CHS mapping rules */
39
	.bios_param		= ata_std_bios_param,
39
	.bios_param		= ata_std_bios_param,
40
#ifdef CONFIG_PM
41
	.resume			= ata_scsi_device_resume,
42
	.suspend		= ata_scsi_device_suspend,
43
#endif
44
};
40
};
45
41
46
static const struct ata_port_operations netcell_ops = {
42
static const struct ata_port_operations netcell_ops = {
(-)a/drivers/ata/pata_ns87410.c (-4 lines)
Lines 156-165 static struct scsi_host_template ns87410 Link Here
156
	.slave_configure	= ata_scsi_slave_config,
156
	.slave_configure	= ata_scsi_slave_config,
157
	.slave_destroy		= ata_scsi_slave_destroy,
157
	.slave_destroy		= ata_scsi_slave_destroy,
158
	.bios_param		= ata_std_bios_param,
158
	.bios_param		= ata_std_bios_param,
159
#ifdef CONFIG_PM
160
	.resume			= ata_scsi_device_resume,
161
	.suspend		= ata_scsi_device_suspend,
162
#endif
163
};
159
};
164
160
165
static struct ata_port_operations ns87410_port_ops = {
161
static struct ata_port_operations ns87410_port_ops = {
(-)a/drivers/ata/pata_oldpiix.c (-4 lines)
Lines 232-241 static struct scsi_host_template oldpiix Link Here
232
	.slave_configure	= ata_scsi_slave_config,
232
	.slave_configure	= ata_scsi_slave_config,
233
	.slave_destroy		= ata_scsi_slave_destroy,
233
	.slave_destroy		= ata_scsi_slave_destroy,
234
	.bios_param		= ata_std_bios_param,
234
	.bios_param		= ata_std_bios_param,
235
#ifdef CONFIG_PM
236
	.resume			= ata_scsi_device_resume,
237
	.suspend		= ata_scsi_device_suspend,
238
#endif
239
};
235
};
240
236
241
static const struct ata_port_operations oldpiix_pata_ops = {
237
static const struct ata_port_operations oldpiix_pata_ops = {
(-)a/drivers/ata/pata_opti.c (-4 lines)
Lines 177-186 static struct scsi_host_template opti_sh Link Here
177
	.slave_configure	= ata_scsi_slave_config,
177
	.slave_configure	= ata_scsi_slave_config,
178
	.slave_destroy		= ata_scsi_slave_destroy,
178
	.slave_destroy		= ata_scsi_slave_destroy,
179
	.bios_param		= ata_std_bios_param,
179
	.bios_param		= ata_std_bios_param,
180
#ifdef CONFIG_PM
181
	.resume			= ata_scsi_device_resume,
182
	.suspend		= ata_scsi_device_suspend,
183
#endif
184
};
180
};
185
181
186
static struct ata_port_operations opti_port_ops = {
182
static struct ata_port_operations opti_port_ops = {
(-)a/drivers/ata/pata_optidma.c (-4 lines)
Lines 362-371 static struct scsi_host_template optidma Link Here
362
	.slave_configure	= ata_scsi_slave_config,
362
	.slave_configure	= ata_scsi_slave_config,
363
	.slave_destroy		= ata_scsi_slave_destroy,
363
	.slave_destroy		= ata_scsi_slave_destroy,
364
	.bios_param		= ata_std_bios_param,
364
	.bios_param		= ata_std_bios_param,
365
#ifdef CONFIG_PM
366
	.resume			= ata_scsi_device_resume,
367
	.suspend		= ata_scsi_device_suspend,
368
#endif
369
};
365
};
370
366
371
static struct ata_port_operations optidma_port_ops = {
367
static struct ata_port_operations optidma_port_ops = {
(-)a/drivers/ata/pata_pdc202xx_old.c (-4 lines)
Lines 244-253 static struct scsi_host_template pdc202x Link Here
244
	.slave_configure	= ata_scsi_slave_config,
244
	.slave_configure	= ata_scsi_slave_config,
245
	.slave_destroy		= ata_scsi_slave_destroy,
245
	.slave_destroy		= ata_scsi_slave_destroy,
246
	.bios_param		= ata_std_bios_param,
246
	.bios_param		= ata_std_bios_param,
247
#ifdef CONFIG_PM
248
	.resume			= ata_scsi_device_resume,
249
	.suspend		= ata_scsi_device_suspend,
250
#endif
251
};
247
};
252
248
253
static struct ata_port_operations pdc2024x_port_ops = {
249
static struct ata_port_operations pdc2024x_port_ops = {
(-)a/drivers/ata/pata_radisys.c (-4 lines)
Lines 200-209 static struct scsi_host_template radisys Link Here
200
	.slave_configure	= ata_scsi_slave_config,
200
	.slave_configure	= ata_scsi_slave_config,
201
	.slave_destroy		= ata_scsi_slave_destroy,
201
	.slave_destroy		= ata_scsi_slave_destroy,
202
	.bios_param		= ata_std_bios_param,
202
	.bios_param		= ata_std_bios_param,
203
#ifdef CONFIG_PM
204
	.resume			= ata_scsi_device_resume,
205
	.suspend		= ata_scsi_device_suspend,
206
#endif
207
};
203
};
208
204
209
static const struct ata_port_operations radisys_pata_ops = {
205
static const struct ata_port_operations radisys_pata_ops = {
(-)a/drivers/ata/pata_rz1000.c (-5 / +1 lines)
Lines 40-46 static int rz1000_set_mode(struct ata_po Link Here
40
40
41
	for (i = 0; i < ATA_MAX_DEVICES; i++) {
41
	for (i = 0; i < ATA_MAX_DEVICES; i++) {
42
		struct ata_device *dev = &ap->device[i];
42
		struct ata_device *dev = &ap->device[i];
43
		if (ata_dev_ready(dev)) {
43
		if (ata_dev_enabled(dev)) {
44
			/* We don't really care */
44
			/* We don't really care */
45
			dev->pio_mode = XFER_PIO_0;
45
			dev->pio_mode = XFER_PIO_0;
46
			dev->xfer_mode = XFER_PIO_0;
46
			dev->xfer_mode = XFER_PIO_0;
Lines 69-78 static struct scsi_host_template rz1000_ Link Here
69
	.slave_configure	= ata_scsi_slave_config,
69
	.slave_configure	= ata_scsi_slave_config,
70
	.slave_destroy		= ata_scsi_slave_destroy,
70
	.slave_destroy		= ata_scsi_slave_destroy,
71
	.bios_param		= ata_std_bios_param,
71
	.bios_param		= ata_std_bios_param,
72
#ifdef CONFIG_PM
73
	.resume			= ata_scsi_device_resume,
74
	.suspend		= ata_scsi_device_suspend,
75
#endif
76
};
72
};
77
73
78
static struct ata_port_operations rz1000_port_ops = {
74
static struct ata_port_operations rz1000_port_ops = {
(-)a/drivers/ata/pata_sc1200.c (-4 lines)
Lines 194-203 static struct scsi_host_template sc1200_ Link Here
194
	.slave_configure	= ata_scsi_slave_config,
194
	.slave_configure	= ata_scsi_slave_config,
195
	.slave_destroy		= ata_scsi_slave_destroy,
195
	.slave_destroy		= ata_scsi_slave_destroy,
196
	.bios_param		= ata_std_bios_param,
196
	.bios_param		= ata_std_bios_param,
197
#ifdef CONFIG_PM
198
	.resume			= ata_scsi_device_resume,
199
	.suspend		= ata_scsi_device_suspend,
200
#endif
201
};
197
};
202
198
203
static struct ata_port_operations sc1200_port_ops = {
199
static struct ata_port_operations sc1200_port_ops = {
(-)a/drivers/ata/pata_scc.c (-4 lines)
Lines 984-993 static struct scsi_host_template scc_sht Link Here
984
	.slave_configure	= ata_scsi_slave_config,
984
	.slave_configure	= ata_scsi_slave_config,
985
	.slave_destroy		= ata_scsi_slave_destroy,
985
	.slave_destroy		= ata_scsi_slave_destroy,
986
	.bios_param		= ata_std_bios_param,
986
	.bios_param		= ata_std_bios_param,
987
#ifdef CONFIG_PM
988
	.resume			= ata_scsi_device_resume,
989
	.suspend		= ata_scsi_device_suspend,
990
#endif
991
};
987
};
992
988
993
static const struct ata_port_operations scc_pata_ops = {
989
static const struct ata_port_operations scc_pata_ops = {
(-)a/drivers/ata/pata_serverworks.c (-4 lines)
Lines 313-322 static struct scsi_host_template serverw Link Here
313
	.slave_configure	= ata_scsi_slave_config,
313
	.slave_configure	= ata_scsi_slave_config,
314
	.slave_destroy		= ata_scsi_slave_destroy,
314
	.slave_destroy		= ata_scsi_slave_destroy,
315
	.bios_param		= ata_std_bios_param,
315
	.bios_param		= ata_std_bios_param,
316
#ifdef CONFIG_PM
317
	.resume			= ata_scsi_device_resume,
318
	.suspend		= ata_scsi_device_suspend,
319
#endif
320
};
316
};
321
317
322
static struct ata_port_operations serverworks_osb4_port_ops = {
318
static struct ata_port_operations serverworks_osb4_port_ops = {
(-)a/drivers/ata/pata_sil680.c (-4 lines)
Lines 230-239 static struct scsi_host_template sil680_ Link Here
230
	.slave_configure	= ata_scsi_slave_config,
230
	.slave_configure	= ata_scsi_slave_config,
231
	.slave_destroy		= ata_scsi_slave_destroy,
231
	.slave_destroy		= ata_scsi_slave_destroy,
232
	.bios_param		= ata_std_bios_param,
232
	.bios_param		= ata_std_bios_param,
233
#ifdef CONFIG_PM
234
	.suspend		= ata_scsi_device_suspend,
235
	.resume			= ata_scsi_device_resume,
236
#endif
237
};
233
};
238
234
239
static struct ata_port_operations sil680_port_ops = {
235
static struct ata_port_operations sil680_port_ops = {
(-)a/drivers/ata/pata_sis.c (-4 lines)
Lines 520-529 static struct scsi_host_template sis_sht Link Here
520
	.slave_configure	= ata_scsi_slave_config,
520
	.slave_configure	= ata_scsi_slave_config,
521
	.slave_destroy		= ata_scsi_slave_destroy,
521
	.slave_destroy		= ata_scsi_slave_destroy,
522
	.bios_param		= ata_std_bios_param,
522
	.bios_param		= ata_std_bios_param,
523
#ifdef CONFIG_PM
524
	.resume			= ata_scsi_device_resume,
525
	.suspend		= ata_scsi_device_suspend,
526
#endif
527
};
523
};
528
524
529
static const struct ata_port_operations sis_133_ops = {
525
static const struct ata_port_operations sis_133_ops = {
(-)a/drivers/ata/pata_triflex.c (-4 lines)
Lines 192-201 static struct scsi_host_template triflex Link Here
192
	.slave_configure	= ata_scsi_slave_config,
192
	.slave_configure	= ata_scsi_slave_config,
193
	.slave_destroy		= ata_scsi_slave_destroy,
193
	.slave_destroy		= ata_scsi_slave_destroy,
194
	.bios_param		= ata_std_bios_param,
194
	.bios_param		= ata_std_bios_param,
195
#ifdef CONFIG_PM
196
	.resume			= ata_scsi_device_resume,
197
	.suspend		= ata_scsi_device_suspend,
198
#endif
199
};
195
};
200
196
201
static struct ata_port_operations triflex_port_ops = {
197
static struct ata_port_operations triflex_port_ops = {
(-)a/drivers/ata/pata_via.c (-4 lines)
Lines 300-309 static struct scsi_host_template via_sht Link Here
300
	.slave_configure	= ata_scsi_slave_config,
300
	.slave_configure	= ata_scsi_slave_config,
301
	.slave_destroy		= ata_scsi_slave_destroy,
301
	.slave_destroy		= ata_scsi_slave_destroy,
302
	.bios_param		= ata_std_bios_param,
302
	.bios_param		= ata_std_bios_param,
303
#ifdef CONFIG_PM
304
	.resume			= ata_scsi_device_resume,
305
	.suspend		= ata_scsi_device_suspend,
306
#endif
307
};
303
};
308
304
309
static struct ata_port_operations via_port_ops = {
305
static struct ata_port_operations via_port_ops = {
(-)a/drivers/ata/sata_inic162x.c (-4 lines)
Lines 135-144 static struct scsi_host_template inic_sh Link Here
135
	.slave_configure	= inic_slave_config,
135
	.slave_configure	= inic_slave_config,
136
	.slave_destroy		= ata_scsi_slave_destroy,
136
	.slave_destroy		= ata_scsi_slave_destroy,
137
	.bios_param		= ata_std_bios_param,
137
	.bios_param		= ata_std_bios_param,
138
#ifdef CONFIG_PM
139
	.suspend		= ata_scsi_device_suspend,
140
	.resume			= ata_scsi_device_resume,
141
#endif
142
};
138
};
143
139
144
static const int scr_map[] = {
140
static const int scr_map[] = {
(-)a/drivers/ata/sata_nv.c (-8 lines)
Lines 323-332 static struct scsi_host_template nv_sht Link Here
323
	.slave_configure	= ata_scsi_slave_config,
323
	.slave_configure	= ata_scsi_slave_config,
324
	.slave_destroy		= ata_scsi_slave_destroy,
324
	.slave_destroy		= ata_scsi_slave_destroy,
325
	.bios_param		= ata_std_bios_param,
325
	.bios_param		= ata_std_bios_param,
326
#ifdef CONFIG_PM
327
	.suspend		= ata_scsi_device_suspend,
328
	.resume			= ata_scsi_device_resume,
329
#endif
330
};
326
};
331
327
332
static struct scsi_host_template nv_adma_sht = {
328
static struct scsi_host_template nv_adma_sht = {
Lines 345-354 static struct scsi_host_template nv_adma Link Here
345
	.slave_configure	= nv_adma_slave_config,
341
	.slave_configure	= nv_adma_slave_config,
346
	.slave_destroy		= ata_scsi_slave_destroy,
342
	.slave_destroy		= ata_scsi_slave_destroy,
347
	.bios_param		= ata_std_bios_param,
343
	.bios_param		= ata_std_bios_param,
348
#ifdef CONFIG_PM
349
	.suspend		= ata_scsi_device_suspend,
350
	.resume			= ata_scsi_device_resume,
351
#endif
352
};
344
};
353
345
354
static const struct ata_port_operations nv_generic_ops = {
346
static const struct ata_port_operations nv_generic_ops = {
(-)a/drivers/ata/sata_sil.c (-4 lines)
Lines 182-191 static struct scsi_host_template sil_sht Link Here
182
	.slave_configure	= ata_scsi_slave_config,
182
	.slave_configure	= ata_scsi_slave_config,
183
	.slave_destroy		= ata_scsi_slave_destroy,
183
	.slave_destroy		= ata_scsi_slave_destroy,
184
	.bios_param		= ata_std_bios_param,
184
	.bios_param		= ata_std_bios_param,
185
#ifdef CONFIG_PM
186
	.suspend		= ata_scsi_device_suspend,
187
	.resume			= ata_scsi_device_resume,
188
#endif
189
};
185
};
190
186
191
static const struct ata_port_operations sil_ops = {
187
static const struct ata_port_operations sil_ops = {
(-)a/drivers/ata/sata_sil24.c (-4 lines)
Lines 380-389 static struct scsi_host_template sil24_s Link Here
380
	.slave_configure	= ata_scsi_slave_config,
380
	.slave_configure	= ata_scsi_slave_config,
381
	.slave_destroy		= ata_scsi_slave_destroy,
381
	.slave_destroy		= ata_scsi_slave_destroy,
382
	.bios_param		= ata_std_bios_param,
382
	.bios_param		= ata_std_bios_param,
383
#ifdef CONFIG_PM
384
	.suspend		= ata_scsi_device_suspend,
385
	.resume			= ata_scsi_device_resume,
386
#endif
387
};
383
};
388
384
389
static const struct ata_port_operations sil24_ops = {
385
static const struct ata_port_operations sil24_ops = {
(-)a/include/linux/libata.h (-14 / +1 lines)
Lines 140-146 enum { Link Here
140
140
141
	ATA_DFLAG_PIO		= (1 << 8), /* device limited to PIO mode */
141
	ATA_DFLAG_PIO		= (1 << 8), /* device limited to PIO mode */
142
	ATA_DFLAG_NCQ_OFF	= (1 << 9), /* device limited to non-NCQ mode */
142
	ATA_DFLAG_NCQ_OFF	= (1 << 9), /* device limited to non-NCQ mode */
143
	ATA_DFLAG_SUSPENDED	= (1 << 10), /* device suspended */
144
	ATA_DFLAG_INIT_MASK	= (1 << 16) - 1,
143
	ATA_DFLAG_INIT_MASK	= (1 << 16) - 1,
145
144
146
	ATA_DFLAG_DETACH	= (1 << 16),
145
	ATA_DFLAG_DETACH	= (1 << 16),
Lines 268-280 enum { Link Here
268
	ATA_EH_REVALIDATE	= (1 << 0),
267
	ATA_EH_REVALIDATE	= (1 << 0),
269
	ATA_EH_SOFTRESET	= (1 << 1),
268
	ATA_EH_SOFTRESET	= (1 << 1),
270
	ATA_EH_HARDRESET	= (1 << 2),
269
	ATA_EH_HARDRESET	= (1 << 2),
271
	ATA_EH_SUSPEND		= (1 << 3),
272
	ATA_EH_RESUME		= (1 << 4),
273
	ATA_EH_PM_FREEZE	= (1 << 5),
274
270
275
	ATA_EH_RESET_MASK	= ATA_EH_SOFTRESET | ATA_EH_HARDRESET,
271
	ATA_EH_RESET_MASK	= ATA_EH_SOFTRESET | ATA_EH_HARDRESET,
276
	ATA_EH_PERDEV_MASK	= ATA_EH_REVALIDATE | ATA_EH_SUSPEND |
272
	ATA_EH_PERDEV_MASK	= ATA_EH_REVALIDATE,
277
				  ATA_EH_RESUME | ATA_EH_PM_FREEZE,
278
273
279
	/* ata_eh_info->flags */
274
	/* ata_eh_info->flags */
280
	ATA_EHI_HOTPLUGGED	= (1 << 0),  /* could have been hotplugged */
275
	ATA_EHI_HOTPLUGGED	= (1 << 0),  /* could have been hotplugged */
Lines 742-749 extern int sata_scr_write_flush(struct a Link Here
742
extern int ata_port_online(struct ata_port *ap);
737
extern int ata_port_online(struct ata_port *ap);
743
extern int ata_port_offline(struct ata_port *ap);
738
extern int ata_port_offline(struct ata_port *ap);
744
#ifdef CONFIG_PM
739
#ifdef CONFIG_PM
745
extern int ata_scsi_device_resume(struct scsi_device *);
746
extern int ata_scsi_device_suspend(struct scsi_device *, pm_message_t mesg);
747
extern int ata_host_suspend(struct ata_host *host, pm_message_t mesg);
740
extern int ata_host_suspend(struct ata_host *host, pm_message_t mesg);
748
extern void ata_host_resume(struct ata_host *host);
741
extern void ata_host_resume(struct ata_host *host);
749
#endif
742
#endif
Lines 1018-1028 static inline unsigned int ata_dev_absen Link Here
1018
	return ata_class_absent(dev->class);
1011
	return ata_class_absent(dev->class);
1019
}
1012
}
1020
1013
1021
static inline unsigned int ata_dev_ready(const struct ata_device *dev)
1022
{
1023
	return ata_dev_enabled(dev) && !(dev->flags & ATA_DFLAG_SUSPENDED);
1024
}
1025
1026
/*
1014
/*
1027
 * port helpers
1015
 * port helpers
1028
 */
1016
 */
1029
 * Check whether /sys/modules/libata/parameters/spindown_compat
1017
 * Check whether /sys/modules/libata/parameters/spindown_compat
1030
   exists.  If it does, write 0 to it.
1018
   exists.  If it does, write 0 to it.
1031
 * For each libata harddisk {
1019
 * For each libata harddisk {
1032
 }
1020
 }
1033
--
1034
Documentation/feature-removal-schedule.txt |   19 +++++++++++++++++++
1021
Documentation/feature-removal-schedule.txt |   19 +++++++++++++++++++
1035
drivers/ata/libata-core.c                  |    6 ++++++
1022
drivers/ata/libata-core.c                  |    6 ++++++
1036
drivers/ata/libata-scsi.c                  |   28 +++++++++++++++++++++++++++-
1023
drivers/ata/libata-scsi.c                  |   28 +++++++++++++++++++++++++++-
1037
drivers/ata/libata.h                       |    1 +
1024
drivers/ata/libata.h                       |    1 +
1038
4 files changed, 53 insertions(+), 1 deletions(-)
1025
4 files changed, 53 insertions(+), 1 deletions(-)
(-)a/Documentation/feature-removal-schedule.txt (+19 lines)
Lines 314-316 Why: Code was merged, then submitter imm Link Here
314
Who:	David S. Miller <davem@davemloft.net>
314
Who:	David S. Miller <davem@davemloft.net>
315
315
316
---------------------------
316
---------------------------
317
318
What:	libata.spindown_compat module parameter
319
When:	Dec 2008
320
Why:	halt(8) synchronizes caches for and spins down libata disks
321
	because libata didn't use to spin down disk on system halt
322
	(only synchronized caches).
323
	Spin down on system halt is now implemented and can be tested
324
	using sysfs node /sys/class/scsi_disk/h:c:i:l/manage_start_stop.
325
	Because issuing spin down command to an already spun down disk
326
	makes some disks spin up just to spin down again, the old
327
	behavior needs to be maintained till userspace tool is updated
328
	to check the sysfs node and not to spin down disks with the
329
	node set to one.
330
	This module parameter is to give userspace tool the time to
331
	get updated and should be removed after userspace is
332
	reasonably updated.
333
Who:	Tejun Heo <htejun@gmail.com>
334
335
---------------------------
(-)a/drivers/ata/libata-core.c (+6 lines)
Lines 101-106 int libata_noacpi = 1; Link Here
101
module_param_named(noacpi, libata_noacpi, int, 0444);
101
module_param_named(noacpi, libata_noacpi, int, 0444);
102
MODULE_PARM_DESC(noacpi, "Disables the use of ACPI in suspend/resume when set");
102
MODULE_PARM_DESC(noacpi, "Disables the use of ACPI in suspend/resume when set");
103
103
104
int ata_spindown_compat = 1;
105
module_param_named(spindown_compat, ata_spindown_compat, int, 0644);
106
MODULE_PARM_DESC(spindown_compat, "Enable backward compatible spindown "
107
		 "behavior.  Will be removed.  More info can be found in "
108
		 "Documentation/feature-removal-schedule.txt\n");
109
104
MODULE_AUTHOR("Jeff Garzik");
110
MODULE_AUTHOR("Jeff Garzik");
105
MODULE_DESCRIPTION("Library module for ATA devices");
111
MODULE_DESCRIPTION("Library module for ATA devices");
106
MODULE_LICENSE("GPL");
112
MODULE_LICENSE("GPL");
(-)a/drivers/ata/libata-scsi.c (-1 / +27 lines)
Lines 944-952 static unsigned int ata_scsi_start_stop_ Link Here
944
		}
944
		}
945
945
946
		tf->command = ATA_CMD_VERIFY;	/* READ VERIFY */
946
		tf->command = ATA_CMD_VERIFY;	/* READ VERIFY */
947
	} else
947
	} else {
948
		/* XXX: This is for backward compatibility, will be
949
		 * removed.  Read Documentation/feature-removal-schedule.txt
950
		 * for more info.
951
		 */
952
		if (ata_spindown_compat &&
953
		    (system_state == SYSTEM_HALT ||
954
		     system_state == SYSTEM_POWER_OFF)) {
955
			static int warned = 0;
956
957
			if (!warned) {
958
				spin_unlock_irq(qc->ap->lock);
959
				ata_dev_printk(qc->dev, KERN_WARNING,
960
					"DISK MIGHT NOT BE SPUN DOWN PROPERLY. "
961
					"UPDATE SHUTDOWN UTILITY\n");
962
				ata_dev_printk(qc->dev, KERN_WARNING,
963
					"For more info, visit "
964
					"http://linux-ata.org/shutdown.html\n");
965
				warned = 1;
966
				ssleep(5);
967
				spin_lock_irq(qc->ap->lock);
968
			}
969
			scmd->result = SAM_STAT_GOOD;
970
			return 1;
971
		}
972
948
		/* Issue ATA STANDBY IMMEDIATE command */
973
		/* Issue ATA STANDBY IMMEDIATE command */
949
		tf->command = ATA_CMD_STANDBYNOW1;
974
		tf->command = ATA_CMD_STANDBYNOW1;
975
	}
950
976
951
	/*
977
	/*
952
	 * Standby and Idle condition timers could be implemented but that
978
	 * Standby and Idle condition timers could be implemented but that
(-)a/drivers/ata/libata.h (+1 lines)
Lines 58-63 extern int atapi_enabled; Link Here
58
extern int atapi_dmadir;
58
extern int atapi_dmadir;
59
extern int libata_fua;
59
extern int libata_fua;
60
extern int libata_noacpi;
60
extern int libata_noacpi;
61
extern int ata_spindown_compat;
61
extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev);
62
extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev);
62
extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
63
extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
63
			   u64 block, u32 n_block, unsigned int tf_flags,
64
			   u64 block, u32 n_block, unsigned int tf_flags,

Return to bug 174373