aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/sd.c
diff options
context:
space:
mode:
authorMartin K. Petersen <martin.petersen@oracle.com>2007-02-27 22:40:55 -0500
committerJames Bottomley <jejb@mulgrave.il.steeleye.com>2007-03-11 12:20:17 -0400
commite73aec8247032ee730b5f38edf48922c4f72522e (patch)
treed585067900bb676abbaa779402818c19d1d63d88 /drivers/scsi/sd.c
parenta4d04a4cd9881e89fdc62107b6b57053438f2b30 (diff)
[SCSI] sd: make printing use a common prefix
Make SCSI disk printing more consistent: - Define sd_printk(), sd_print_sense_hdr() and sd_print_result() - Move relevant header bits into sd.h - Remove all the legacy disk_name passing and use scsi_disk pointers where possible - Switch printk() lines to the new sd_ functions so that output is consistent Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/scsi/sd.c')
-rw-r--r--drivers/scsi/sd.c253
1 files changed, 95 insertions, 158 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 5a8f55fea5ff..b5562b851e78 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -58,16 +58,10 @@
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
71MODULE_AUTHOR("Eric Youngdale"); 65MODULE_AUTHOR("Eric Youngdale");
72MODULE_DESCRIPTION("SCSI disk (sd) driver"); 66MODULE_DESCRIPTION("SCSI disk (sd) driver");
73MODULE_LICENSE("GPL"); 67MODULE_LICENSE("GPL");
@@ -89,45 +83,6 @@ MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_DISK13_MAJOR);
89MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_DISK14_MAJOR); 83MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_DISK14_MAJOR);
90MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_DISK15_MAJOR); 84MODULE_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
115struct 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
131static DEFINE_IDR(sd_index_idr); 86static DEFINE_IDR(sd_index_idr);
132static DEFINE_SPINLOCK(sd_index_lock); 87static DEFINE_SPINLOCK(sd_index_lock);
133 88
@@ -136,20 +91,6 @@ static DEFINE_SPINLOCK(sd_index_lock);
136 * object after last put) */ 91 * object after last put) */
137static DEFINE_MUTEX(sd_ref_mutex); 92static DEFINE_MUTEX(sd_ref_mutex);
138 93
139static int sd_revalidate_disk(struct gendisk *disk);
140static void sd_rw_intr(struct scsi_cmnd * SCpnt);
141
142static int sd_probe(struct device *);
143static int sd_remove(struct device *);
144static void sd_shutdown(struct device *dev);
145static void sd_rescan(struct device *);
146static int sd_init_command(struct scsi_cmnd *);
147static int sd_issue_flush(struct device *, sector_t *);
148static void sd_prepare_flush(request_queue_t *, struct request *);
149static void sd_read_capacity(struct scsi_disk *sdkp, char *diskname,
150 unsigned char *buffer);
151static void scsi_disk_release(struct class_device *cdev);
152
153static const char *sd_cache_types[] = { 94static 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)"
@@ -199,7 +140,7 @@ static ssize_t sd_store_cache_type(struct class_device *cdev, const char *buf,
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);
@@ -407,7 +348,8 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
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;
@@ -416,7 +358,8 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
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;
@@ -425,7 +368,8 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
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;
@@ -442,7 +386,7 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
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
@@ -490,7 +434,8 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
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
@@ -786,9 +731,10 @@ not_present:
786 return 1; 731 return 1;
787} 732}
788 733
789static int sd_sync_cache(struct scsi_device *sdp) 734static 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))
@@ -809,12 +755,10 @@ static int sd_sync_cache(struct scsi_device *sdp)
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;
@@ -823,14 +767,13 @@ static int sd_sync_cache(struct scsi_device *sdp)
823static int sd_issue_flush(struct device *dev, sector_t *error_sector) 767static 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}
@@ -1025,7 +968,7 @@ static int media_not_present(struct scsi_disk *sdkp,
1025 * spinup disk - called only in sd_revalidate_disk() 968 * spinup disk - called only in sd_revalidate_disk()
1026 */ 969 */
1027static void 970static void
1028sd_spinup_disk(struct scsi_disk *sdkp, char *diskname) 971sd_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;
@@ -1069,9 +1012,10 @@ sd_spinup_disk(struct scsi_disk *sdkp, char *diskname)
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
@@ -1096,8 +1040,7 @@ sd_spinup_disk(struct scsi_disk *sdkp, char *diskname)
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);
@@ -1130,9 +1073,8 @@ sd_spinup_disk(struct scsi_disk *sdkp, char *diskname)
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 }
@@ -1151,8 +1093,7 @@ sd_spinup_disk(struct scsi_disk *sdkp, char *diskname)
1151 * read disk capacity 1093 * read disk capacity
1152 */ 1094 */
1153static void 1095static void
1154sd_read_capacity(struct scsi_disk *sdkp, char *diskname, 1096sd_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;
@@ -1191,18 +1132,12 @@ repeat:
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. */
@@ -1218,16 +1153,10 @@ repeat:
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 }
@@ -1238,14 +1167,14 @@ repeat:
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 }
@@ -1284,8 +1213,8 @@ repeat:
1284got_data: 1213got_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 &&
@@ -1293,8 +1222,8 @@ got_data:
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
@@ -1327,10 +1256,10 @@ got_data:
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 */
@@ -1362,8 +1291,7 @@ sd_do_mode_sense(struct scsi_device *sdp, int dbd, int modepage,
1362 * called with buffer of length SD_BUF_SIZE 1291 * called with buffer of length SD_BUF_SIZE
1363 */ 1292 */
1364static void 1293static void
1365sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname, 1294sd_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;
@@ -1371,7 +1299,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname,
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
@@ -1403,15 +1331,16 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname,
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
@@ -1420,8 +1349,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname,
1420 * called with buffer of length SD_BUF_SIZE 1349 * called with buffer of length SD_BUF_SIZE
1421 */ 1350 */
1422static void 1351static void
1423sd_read_cache_type(struct scsi_disk *sdkp, char *diskname, 1352sd_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;
@@ -1450,8 +1378,7 @@ sd_read_cache_type(struct scsi_disk *sdkp, char *diskname,
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 */
@@ -1478,13 +1405,12 @@ sd_read_cache_type(struct scsi_disk *sdkp, char *diskname,
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
@@ -1498,14 +1424,13 @@ sd_read_cache_type(struct scsi_disk *sdkp, char *diskname,
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"
@@ -1518,15 +1443,13 @@ bad_sense:
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
1527defaults: 1451defaults:
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;
@@ -1555,8 +1478,8 @@ static int sd_revalidate_disk(struct gendisk *disk)
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
@@ -1568,16 +1491,16 @@ static int sd_revalidate_disk(struct gendisk *disk)
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 /*
@@ -1709,8 +1632,8 @@ static int sd_probe(struct device *dev)
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
@@ -1781,16 +1704,14 @@ static void scsi_disk_release(struct class_device *cdev)
1781 */ 1704 */
1782static void sd_shutdown(struct device *dev) 1705static 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}
@@ -1852,3 +1773,19 @@ static void __exit exit_sd(void)
1852 1773
1853module_init(init_sd); 1774module_init(init_sd);
1854module_exit(exit_sd); 1775module_exit(exit_sd);
1776
1777static 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
1786static void sd_print_result(struct scsi_disk *sdkp, int result)
1787{
1788 sd_printk(KERN_INFO, sdkp, "");
1789 scsi_show_result(result);
1790}
1791