aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/DAC960.c10
-rw-r--r--drivers/block/Kconfig6
-rw-r--r--drivers/block/amiflop.c54
-rw-r--r--drivers/block/aoe/aoechr.c7
-rw-r--r--drivers/block/aoe/aoecmd.c7
-rw-r--r--drivers/block/ataflop.c66
-rw-r--r--drivers/block/brd.c7
-rw-r--r--drivers/block/cciss.c928
-rw-r--r--drivers/block/cciss.h34
-rw-r--r--drivers/block/cciss_cmd.h2
-rw-r--r--drivers/block/cciss_scsi.c109
-rw-r--r--drivers/block/cpqarray.c20
-rw-r--r--drivers/block/floppy.c85
-rw-r--r--drivers/block/hd.c116
-rw-r--r--drivers/block/loop.c37
-rw-r--r--drivers/block/mg_disk.c509
-rw-r--r--drivers/block/nbd.c23
-rw-r--r--drivers/block/paride/pcd.c29
-rw-r--r--drivers/block/paride/pd.c22
-rw-r--r--drivers/block/paride/pf.c47
-rw-r--r--drivers/block/pktcdvd.c17
-rw-r--r--drivers/block/ps3disk.c42
-rw-r--r--drivers/block/ps3vram.c168
-rw-r--r--drivers/block/sunvdc.c14
-rw-r--r--drivers/block/swim.c48
-rw-r--r--drivers/block/swim3.c107
-rw-r--r--drivers/block/sx8.c17
-rw-r--r--drivers/block/ub.c54
-rw-r--r--drivers/block/viodasd.c12
-rw-r--r--drivers/block/virtio_blk.c120
-rw-r--r--drivers/block/xd.c41
-rw-r--r--drivers/block/xen-blkfront.c48
-rw-r--r--drivers/block/xsysace.c46
-rw-r--r--drivers/block/z2ram.c19
34 files changed, 1624 insertions, 1247 deletions
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index f22ed6cc69f2..668dc234b8e2 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -3321,7 +3321,7 @@ static int DAC960_process_queue(DAC960_Controller_T *Controller, struct request_
3321 DAC960_Command_T *Command; 3321 DAC960_Command_T *Command;
3322 3322
3323 while(1) { 3323 while(1) {
3324 Request = elv_next_request(req_q); 3324 Request = blk_peek_request(req_q);
3325 if (!Request) 3325 if (!Request)
3326 return 1; 3326 return 1;
3327 3327
@@ -3338,10 +3338,10 @@ static int DAC960_process_queue(DAC960_Controller_T *Controller, struct request_
3338 } 3338 }
3339 Command->Completion = Request->end_io_data; 3339 Command->Completion = Request->end_io_data;
3340 Command->LogicalDriveNumber = (long)Request->rq_disk->private_data; 3340 Command->LogicalDriveNumber = (long)Request->rq_disk->private_data;
3341 Command->BlockNumber = Request->sector; 3341 Command->BlockNumber = blk_rq_pos(Request);
3342 Command->BlockCount = Request->nr_sectors; 3342 Command->BlockCount = blk_rq_sectors(Request);
3343 Command->Request = Request; 3343 Command->Request = Request;
3344 blkdev_dequeue_request(Request); 3344 blk_start_request(Request);
3345 Command->SegmentCount = blk_rq_map_sg(req_q, 3345 Command->SegmentCount = blk_rq_map_sg(req_q,
3346 Command->Request, Command->cmd_sglist); 3346 Command->Request, Command->cmd_sglist);
3347 /* pci_map_sg MAY change the value of SegCount */ 3347 /* pci_map_sg MAY change the value of SegCount */
@@ -3431,7 +3431,7 @@ static void DAC960_queue_partial_rw(DAC960_Command_T *Command)
3431 * successfully as possible. 3431 * successfully as possible.
3432 */ 3432 */
3433 Command->SegmentCount = 1; 3433 Command->SegmentCount = 1;
3434 Command->BlockNumber = Request->sector; 3434 Command->BlockNumber = blk_rq_pos(Request);
3435 Command->BlockCount = 1; 3435 Command->BlockCount = 1;
3436 DAC960_QueueReadWriteCommand(Command); 3436 DAC960_QueueReadWriteCommand(Command);
3437 return; 3437 return;
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index ddea8e485cc9..bb72ada9f074 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -112,7 +112,7 @@ config GDROM
112 with up to 1 GB of data. This drive will also read standard CD ROM 112 with up to 1 GB of data. This drive will also read standard CD ROM
113 disks. Select this option to access any disks in your GD ROM drive. 113 disks. Select this option to access any disks in your GD ROM drive.
114 Most users will want to say "Y" here. 114 Most users will want to say "Y" here.
115 You can also build this as a module which will be called gdrom.ko 115 You can also build this as a module which will be called gdrom.
116 116
117source "drivers/block/paride/Kconfig" 117source "drivers/block/paride/Kconfig"
118 118
@@ -412,7 +412,7 @@ config ATA_OVER_ETH
412 412
413config MG_DISK 413config MG_DISK
414 tristate "mGine mflash, gflash support" 414 tristate "mGine mflash, gflash support"
415 depends on ARM && ATA && GPIOLIB 415 depends on ARM && GPIOLIB
416 help 416 help
417 mGine mFlash(gFlash) block device driver 417 mGine mFlash(gFlash) block device driver
418 418
@@ -438,7 +438,7 @@ source "drivers/s390/block/Kconfig"
438 438
439config XILINX_SYSACE 439config XILINX_SYSACE
440 tristate "Xilinx SystemACE support" 440 tristate "Xilinx SystemACE support"
441 depends on 4xx 441 depends on 4xx || MICROBLAZE
442 help 442 help
443 Include support for the Xilinx SystemACE CompactFlash interface 443 Include support for the Xilinx SystemACE CompactFlash interface
444 444
diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c
index 8df436ff7068..9c6e5b0fe894 100644
--- a/drivers/block/amiflop.c
+++ b/drivers/block/amiflop.c
@@ -112,8 +112,6 @@ module_param(fd_def_df0, ulong, 0);
112MODULE_LICENSE("GPL"); 112MODULE_LICENSE("GPL");
113 113
114static struct request_queue *floppy_queue; 114static struct request_queue *floppy_queue;
115#define QUEUE (floppy_queue)
116#define CURRENT elv_next_request(floppy_queue)
117 115
118/* 116/*
119 * Macros 117 * Macros
@@ -1335,64 +1333,60 @@ static int get_track(int drive, int track)
1335 1333
1336static void redo_fd_request(void) 1334static void redo_fd_request(void)
1337{ 1335{
1336 struct request *rq;
1338 unsigned int cnt, block, track, sector; 1337 unsigned int cnt, block, track, sector;
1339 int drive; 1338 int drive;
1340 struct amiga_floppy_struct *floppy; 1339 struct amiga_floppy_struct *floppy;
1341 char *data; 1340 char *data;
1342 unsigned long flags; 1341 unsigned long flags;
1342 int err;
1343 1343
1344 repeat: 1344next_req:
1345 if (!CURRENT) { 1345 rq = blk_fetch_request(floppy_queue);
1346 if (!rq) {
1346 /* Nothing left to do */ 1347 /* Nothing left to do */
1347 return; 1348 return;
1348 } 1349 }
1349 1350
1350 floppy = CURRENT->rq_disk->private_data; 1351 floppy = rq->rq_disk->private_data;
1351 drive = floppy - unit; 1352 drive = floppy - unit;
1352 1353
1354next_segment:
1353 /* Here someone could investigate to be more efficient */ 1355 /* Here someone could investigate to be more efficient */
1354 for (cnt = 0; cnt < CURRENT->current_nr_sectors; cnt++) { 1356 for (cnt = 0, err = 0; cnt < blk_rq_cur_sectors(rq); cnt++) {
1355#ifdef DEBUG 1357#ifdef DEBUG
1356 printk("fd: sector %ld + %d requested for %s\n", 1358 printk("fd: sector %ld + %d requested for %s\n",
1357 CURRENT->sector,cnt, 1359 blk_rq_pos(rq), cnt,
1358 (rq_data_dir(CURRENT) == READ) ? "read" : "write"); 1360 (rq_data_dir(rq) == READ) ? "read" : "write");
1359#endif 1361#endif
1360 block = CURRENT->sector + cnt; 1362 block = blk_rq_pos(rq) + cnt;
1361 if ((int)block > floppy->blocks) { 1363 if ((int)block > floppy->blocks) {
1362 end_request(CURRENT, 0); 1364 err = -EIO;
1363 goto repeat; 1365 break;
1364 } 1366 }
1365 1367
1366 track = block / (floppy->dtype->sects * floppy->type->sect_mult); 1368 track = block / (floppy->dtype->sects * floppy->type->sect_mult);
1367 sector = block % (floppy->dtype->sects * floppy->type->sect_mult); 1369 sector = block % (floppy->dtype->sects * floppy->type->sect_mult);
1368 data = CURRENT->buffer + 512 * cnt; 1370 data = rq->buffer + 512 * cnt;
1369#ifdef DEBUG 1371#ifdef DEBUG
1370 printk("access to track %d, sector %d, with buffer at " 1372 printk("access to track %d, sector %d, with buffer at "
1371 "0x%08lx\n", track, sector, data); 1373 "0x%08lx\n", track, sector, data);
1372#endif 1374#endif
1373 1375
1374 if ((rq_data_dir(CURRENT) != READ) && (rq_data_dir(CURRENT) != WRITE)) {
1375 printk(KERN_WARNING "do_fd_request: unknown command\n");
1376 end_request(CURRENT, 0);
1377 goto repeat;
1378 }
1379 if (get_track(drive, track) == -1) { 1376 if (get_track(drive, track) == -1) {
1380 end_request(CURRENT, 0); 1377 err = -EIO;
1381 goto repeat; 1378 break;
1382 } 1379 }
1383 1380
1384 switch (rq_data_dir(CURRENT)) { 1381 if (rq_data_dir(rq) == READ) {
1385 case READ:
1386 memcpy(data, floppy->trackbuf + sector * 512, 512); 1382 memcpy(data, floppy->trackbuf + sector * 512, 512);
1387 break; 1383 } else {
1388
1389 case WRITE:
1390 memcpy(floppy->trackbuf + sector * 512, data, 512); 1384 memcpy(floppy->trackbuf + sector * 512, data, 512);
1391 1385
1392 /* keep the drive spinning while writes are scheduled */ 1386 /* keep the drive spinning while writes are scheduled */
1393 if (!fd_motor_on(drive)) { 1387 if (!fd_motor_on(drive)) {
1394 end_request(CURRENT, 0); 1388 err = -EIO;
1395 goto repeat; 1389 break;
1396 } 1390 }
1397 /* 1391 /*
1398 * setup a callback to write the track buffer 1392 * setup a callback to write the track buffer
@@ -1404,14 +1398,12 @@ static void redo_fd_request(void)
1404 /* reset the timer */ 1398 /* reset the timer */
1405 mod_timer (flush_track_timer + drive, jiffies + 1); 1399 mod_timer (flush_track_timer + drive, jiffies + 1);
1406 local_irq_restore(flags); 1400 local_irq_restore(flags);
1407 break;
1408 } 1401 }
1409 } 1402 }
1410 CURRENT->nr_sectors -= CURRENT->current_nr_sectors;
1411 CURRENT->sector += CURRENT->current_nr_sectors;
1412 1403
1413 end_request(CURRENT, 1); 1404 if (__blk_end_request_cur(rq, err))
1414 goto repeat; 1405 goto next_segment;
1406 goto next_req;
1415} 1407}
1416 1408
1417static void do_fd_request(struct request_queue * q) 1409static void do_fd_request(struct request_queue * q)
diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
index 200efc4d2c1e..19888354188f 100644
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -266,6 +266,11 @@ static const struct file_operations aoe_fops = {
266 .owner = THIS_MODULE, 266 .owner = THIS_MODULE,
267}; 267};
268 268
269static char *aoe_nodename(struct device *dev)
270{
271 return kasprintf(GFP_KERNEL, "etherd/%s", dev_name(dev));
272}
273
269int __init 274int __init
270aoechr_init(void) 275aoechr_init(void)
271{ 276{
@@ -283,6 +288,8 @@ aoechr_init(void)
283 unregister_chrdev(AOE_MAJOR, "aoechr"); 288 unregister_chrdev(AOE_MAJOR, "aoechr");
284 return PTR_ERR(aoe_class); 289 return PTR_ERR(aoe_class);
285 } 290 }
291 aoe_class->nodename = aoe_nodename;
292
286 for (i = 0; i < ARRAY_SIZE(chardevs); ++i) 293 for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
287 device_create(aoe_class, NULL, 294 device_create(aoe_class, NULL,
288 MKDEV(AOE_MAJOR, chardevs[i].minor), NULL, 295 MKDEV(AOE_MAJOR, chardevs[i].minor), NULL,
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c
index 31693bc24444..965ece2c7e4d 100644
--- a/drivers/block/aoe/aoecmd.c
+++ b/drivers/block/aoe/aoecmd.c
@@ -34,13 +34,6 @@ new_skb(ulong len)
34 skb_reset_mac_header(skb); 34 skb_reset_mac_header(skb);
35 skb_reset_network_header(skb); 35 skb_reset_network_header(skb);
36 skb->protocol = __constant_htons(ETH_P_AOE); 36 skb->protocol = __constant_htons(ETH_P_AOE);
37 skb->priority = 0;
38 skb->next = skb->prev = NULL;
39
40 /* tell the network layer not to perform IP checksums
41 * or to get the NIC to do it
42 */
43 skb->ip_summed = CHECKSUM_NONE;
44 } 37 }
45 return skb; 38 return skb;
46} 39}
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index 4234c11c1e4c..f5e7180d7f47 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -79,9 +79,7 @@
79#undef DEBUG 79#undef DEBUG
80 80
81static struct request_queue *floppy_queue; 81static struct request_queue *floppy_queue;
82 82static struct request *fd_request;
83#define QUEUE (floppy_queue)
84#define CURRENT elv_next_request(floppy_queue)
85 83
86/* Disk types: DD, HD, ED */ 84/* Disk types: DD, HD, ED */
87static struct atari_disk_type { 85static struct atari_disk_type {
@@ -376,6 +374,12 @@ static DEFINE_TIMER(readtrack_timer, fd_readtrack_check, 0, 0);
376static DEFINE_TIMER(timeout_timer, fd_times_out, 0, 0); 374static DEFINE_TIMER(timeout_timer, fd_times_out, 0, 0);
377static DEFINE_TIMER(fd_timer, check_change, 0, 0); 375static DEFINE_TIMER(fd_timer, check_change, 0, 0);
378 376
377static void fd_end_request_cur(int err)
378{
379 if (!__blk_end_request_cur(fd_request, err))
380 fd_request = NULL;
381}
382
379static inline void start_motor_off_timer(void) 383static inline void start_motor_off_timer(void)
380{ 384{
381 mod_timer(&motor_off_timer, jiffies + FD_MOTOR_OFF_DELAY); 385 mod_timer(&motor_off_timer, jiffies + FD_MOTOR_OFF_DELAY);
@@ -606,15 +610,15 @@ static void fd_error( void )
606 return; 610 return;
607 } 611 }
608 612
609 if (!CURRENT) 613 if (!fd_request)
610 return; 614 return;
611 615
612 CURRENT->errors++; 616 fd_request->errors++;
613 if (CURRENT->errors >= MAX_ERRORS) { 617 if (fd_request->errors >= MAX_ERRORS) {
614 printk(KERN_ERR "fd%d: too many errors.\n", SelectedDrive ); 618 printk(KERN_ERR "fd%d: too many errors.\n", SelectedDrive );
615 end_request(CURRENT, 0); 619 fd_end_request_cur(-EIO);
616 } 620 }
617 else if (CURRENT->errors == RECALIBRATE_ERRORS) { 621 else if (fd_request->errors == RECALIBRATE_ERRORS) {
618 printk(KERN_WARNING "fd%d: recalibrating\n", SelectedDrive ); 622 printk(KERN_WARNING "fd%d: recalibrating\n", SelectedDrive );
619 if (SelectedDrive != -1) 623 if (SelectedDrive != -1)
620 SUD.track = -1; 624 SUD.track = -1;
@@ -725,16 +729,14 @@ static void do_fd_action( int drive )
725 if (IS_BUFFERED( drive, ReqSide, ReqTrack )) { 729 if (IS_BUFFERED( drive, ReqSide, ReqTrack )) {
726 if (ReqCmd == READ) { 730 if (ReqCmd == READ) {
727 copy_buffer( SECTOR_BUFFER(ReqSector), ReqData ); 731 copy_buffer( SECTOR_BUFFER(ReqSector), ReqData );
728 if (++ReqCnt < CURRENT->current_nr_sectors) { 732 if (++ReqCnt < blk_rq_cur_sectors(fd_request)) {
729 /* read next sector */ 733 /* read next sector */
730 setup_req_params( drive ); 734 setup_req_params( drive );
731 goto repeat; 735 goto repeat;
732 } 736 }
733 else { 737 else {
734 /* all sectors finished */ 738 /* all sectors finished */
735 CURRENT->nr_sectors -= CURRENT->current_nr_sectors; 739 fd_end_request_cur(0);
736 CURRENT->sector += CURRENT->current_nr_sectors;
737 end_request(CURRENT, 1);
738 redo_fd_request(); 740 redo_fd_request();
739 return; 741 return;
740 } 742 }
@@ -1132,16 +1134,14 @@ static void fd_rwsec_done1(int status)
1132 } 1134 }
1133 } 1135 }
1134 1136
1135 if (++ReqCnt < CURRENT->current_nr_sectors) { 1137 if (++ReqCnt < blk_rq_cur_sectors(fd_request)) {
1136 /* read next sector */ 1138 /* read next sector */
1137 setup_req_params( SelectedDrive ); 1139 setup_req_params( SelectedDrive );
1138 do_fd_action( SelectedDrive ); 1140 do_fd_action( SelectedDrive );
1139 } 1141 }
1140 else { 1142 else {
1141 /* all sectors finished */ 1143 /* all sectors finished */
1142 CURRENT->nr_sectors -= CURRENT->current_nr_sectors; 1144 fd_end_request_cur(0);
1143 CURRENT->sector += CURRENT->current_nr_sectors;
1144 end_request(CURRENT, 1);
1145 redo_fd_request(); 1145 redo_fd_request();
1146 } 1146 }
1147 return; 1147 return;
@@ -1382,7 +1382,7 @@ static void setup_req_params( int drive )
1382 ReqData = ReqBuffer + 512 * ReqCnt; 1382 ReqData = ReqBuffer + 512 * ReqCnt;
1383 1383
1384 if (UseTrackbuffer) 1384 if (UseTrackbuffer)
1385 read_track = (ReqCmd == READ && CURRENT->errors == 0); 1385 read_track = (ReqCmd == READ && fd_request->errors == 0);
1386 else 1386 else
1387 read_track = 0; 1387 read_track = 0;
1388 1388
@@ -1396,25 +1396,27 @@ static void redo_fd_request(void)
1396 int drive, type; 1396 int drive, type;
1397 struct atari_floppy_struct *floppy; 1397 struct atari_floppy_struct *floppy;
1398 1398
1399 DPRINT(("redo_fd_request: CURRENT=%p dev=%s CURRENT->sector=%ld\n", 1399 DPRINT(("redo_fd_request: fd_request=%p dev=%s fd_request->sector=%ld\n",
1400 CURRENT, CURRENT ? CURRENT->rq_disk->disk_name : "", 1400 fd_request, fd_request ? fd_request->rq_disk->disk_name : "",
1401 CURRENT ? CURRENT->sector : 0 )); 1401 fd_request ? blk_rq_pos(fd_request) : 0 ));
1402 1402
1403 IsFormatting = 0; 1403 IsFormatting = 0;
1404 1404
1405repeat: 1405repeat:
1406 if (!fd_request) {
1407 fd_request = blk_fetch_request(floppy_queue);
1408 if (!fd_request)
1409 goto the_end;
1410 }
1406 1411
1407 if (!CURRENT) 1412 floppy = fd_request->rq_disk->private_data;
1408 goto the_end;
1409
1410 floppy = CURRENT->rq_disk->private_data;
1411 drive = floppy - unit; 1413 drive = floppy - unit;
1412 type = floppy->type; 1414 type = floppy->type;
1413 1415
1414 if (!UD.connected) { 1416 if (!UD.connected) {
1415 /* drive not connected */ 1417 /* drive not connected */
1416 printk(KERN_ERR "Unknown Device: fd%d\n", drive ); 1418 printk(KERN_ERR "Unknown Device: fd%d\n", drive );
1417 end_request(CURRENT, 0); 1419 fd_end_request_cur(-EIO);
1418 goto repeat; 1420 goto repeat;
1419 } 1421 }
1420 1422
@@ -1430,12 +1432,12 @@ repeat:
1430 /* user supplied disk type */ 1432 /* user supplied disk type */
1431 if (--type >= NUM_DISK_MINORS) { 1433 if (--type >= NUM_DISK_MINORS) {
1432 printk(KERN_WARNING "fd%d: invalid disk format", drive ); 1434 printk(KERN_WARNING "fd%d: invalid disk format", drive );
1433 end_request(CURRENT, 0); 1435 fd_end_request_cur(-EIO);
1434 goto repeat; 1436 goto repeat;
1435 } 1437 }
1436 if (minor2disktype[type].drive_types > DriveType) { 1438 if (minor2disktype[type].drive_types > DriveType) {
1437 printk(KERN_WARNING "fd%d: unsupported disk format", drive ); 1439 printk(KERN_WARNING "fd%d: unsupported disk format", drive );
1438 end_request(CURRENT, 0); 1440 fd_end_request_cur(-EIO);
1439 goto repeat; 1441 goto repeat;
1440 } 1442 }
1441 type = minor2disktype[type].index; 1443 type = minor2disktype[type].index;
@@ -1444,8 +1446,8 @@ repeat:
1444 UD.autoprobe = 0; 1446 UD.autoprobe = 0;
1445 } 1447 }
1446 1448
1447 if (CURRENT->sector + 1 > UDT->blocks) { 1449 if (blk_rq_pos(fd_request) + 1 > UDT->blocks) {
1448 end_request(CURRENT, 0); 1450 fd_end_request_cur(-EIO);
1449 goto repeat; 1451 goto repeat;
1450 } 1452 }
1451 1453
@@ -1453,9 +1455,9 @@ repeat:
1453 del_timer( &motor_off_timer ); 1455 del_timer( &motor_off_timer );
1454 1456
1455 ReqCnt = 0; 1457 ReqCnt = 0;
1456 ReqCmd = rq_data_dir(CURRENT); 1458 ReqCmd = rq_data_dir(fd_request);
1457 ReqBlock = CURRENT->sector; 1459 ReqBlock = blk_rq_pos(fd_request);
1458 ReqBuffer = CURRENT->buffer; 1460 ReqBuffer = fd_request->buffer;
1459 setup_req_params( drive ); 1461 setup_req_params( drive );
1460 do_fd_action( drive ); 1462 do_fd_action( drive );
1461 1463
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 5f7e64ba87e5..4bf8705b3ace 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -407,12 +407,7 @@ static int __init ramdisk_size(char *str)
407 rd_size = simple_strtol(str, NULL, 0); 407 rd_size = simple_strtol(str, NULL, 0);
408 return 1; 408 return 1;
409} 409}
410static int __init ramdisk_size2(char *str) 410__setup("ramdisk_size=", ramdisk_size);
411{
412 return ramdisk_size(str);
413}
414__setup("ramdisk=", ramdisk_size);
415__setup("ramdisk_size=", ramdisk_size2);
416#endif 411#endif
417 412
418/* 413/*
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 4d4d5e0d3fa6..c7a527c08a09 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -38,7 +38,6 @@
38#include <linux/hdreg.h> 38#include <linux/hdreg.h>
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <linux/compat.h> 40#include <linux/compat.h>
41#include <linux/blktrace_api.h>
42#include <asm/uaccess.h> 41#include <asm/uaccess.h>
43#include <asm/io.h> 42#include <asm/io.h>
44 43
@@ -180,11 +179,13 @@ static void __devinit cciss_interrupt_mode(ctlr_info_t *, struct pci_dev *,
180 __u32); 179 __u32);
181static void start_io(ctlr_info_t *h); 180static void start_io(ctlr_info_t *h);
182static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size, 181static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size,
183 unsigned int use_unit_num, unsigned int log_unit,
184 __u8 page_code, unsigned char *scsi3addr, int cmd_type); 182 __u8 page_code, unsigned char *scsi3addr, int cmd_type);
185static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size, 183static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size,
186 unsigned int use_unit_num, unsigned int log_unit, 184 __u8 page_code, unsigned char scsi3addr[],
187 __u8 page_code, int cmd_type); 185 int cmd_type);
186static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c,
187 int attempt_retry);
188static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c);
188 189
189static void fail_all_cmds(unsigned long ctlr); 190static void fail_all_cmds(unsigned long ctlr);
190static int scan_thread(void *data); 191static int scan_thread(void *data);
@@ -437,6 +438,194 @@ static void __devinit cciss_procinit(int i)
437} 438}
438#endif /* CONFIG_PROC_FS */ 439#endif /* CONFIG_PROC_FS */
439 440
441#define MAX_PRODUCT_NAME_LEN 19
442
443#define to_hba(n) container_of(n, struct ctlr_info, dev)
444#define to_drv(n) container_of(n, drive_info_struct, dev)
445
446static struct device_type cciss_host_type = {
447 .name = "cciss_host",
448};
449
450static ssize_t dev_show_unique_id(struct device *dev,
451 struct device_attribute *attr,
452 char *buf)
453{
454 drive_info_struct *drv = to_drv(dev);
455 struct ctlr_info *h = to_hba(drv->dev.parent);
456 __u8 sn[16];
457 unsigned long flags;
458 int ret = 0;
459
460 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
461 if (h->busy_configuring)
462 ret = -EBUSY;
463 else
464 memcpy(sn, drv->serial_no, sizeof(sn));
465 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
466
467 if (ret)
468 return ret;
469 else
470 return snprintf(buf, 16 * 2 + 2,
471 "%02X%02X%02X%02X%02X%02X%02X%02X"
472 "%02X%02X%02X%02X%02X%02X%02X%02X\n",
473 sn[0], sn[1], sn[2], sn[3],
474 sn[4], sn[5], sn[6], sn[7],
475 sn[8], sn[9], sn[10], sn[11],
476 sn[12], sn[13], sn[14], sn[15]);
477}
478DEVICE_ATTR(unique_id, S_IRUGO, dev_show_unique_id, NULL);
479
480static ssize_t dev_show_vendor(struct device *dev,
481 struct device_attribute *attr,
482 char *buf)
483{
484 drive_info_struct *drv = to_drv(dev);
485 struct ctlr_info *h = to_hba(drv->dev.parent);
486 char vendor[VENDOR_LEN + 1];
487 unsigned long flags;
488 int ret = 0;
489
490 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
491 if (h->busy_configuring)
492 ret = -EBUSY;
493 else
494 memcpy(vendor, drv->vendor, VENDOR_LEN + 1);
495 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
496
497 if (ret)
498 return ret;
499 else
500 return snprintf(buf, sizeof(vendor) + 1, "%s\n", drv->vendor);
501}
502DEVICE_ATTR(vendor, S_IRUGO, dev_show_vendor, NULL);
503
504static ssize_t dev_show_model(struct device *dev,
505 struct device_attribute *attr,
506 char *buf)
507{
508 drive_info_struct *drv = to_drv(dev);
509 struct ctlr_info *h = to_hba(drv->dev.parent);
510 char model[MODEL_LEN + 1];
511 unsigned long flags;
512 int ret = 0;
513
514 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
515 if (h->busy_configuring)
516 ret = -EBUSY;
517 else
518 memcpy(model, drv->model, MODEL_LEN + 1);
519 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
520
521 if (ret)
522 return ret;
523 else
524 return snprintf(buf, sizeof(model) + 1, "%s\n", drv->model);
525}
526DEVICE_ATTR(model, S_IRUGO, dev_show_model, NULL);
527
528static ssize_t dev_show_rev(struct device *dev,
529 struct device_attribute *attr,
530 char *buf)
531{
532 drive_info_struct *drv = to_drv(dev);
533 struct ctlr_info *h = to_hba(drv->dev.parent);
534 char rev[REV_LEN + 1];
535 unsigned long flags;
536 int ret = 0;
537
538 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
539 if (h->busy_configuring)
540 ret = -EBUSY;
541 else
542 memcpy(rev, drv->rev, REV_LEN + 1);
543 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
544
545 if (ret)
546 return ret;
547 else
548 return snprintf(buf, sizeof(rev) + 1, "%s\n", drv->rev);
549}
550DEVICE_ATTR(rev, S_IRUGO, dev_show_rev, NULL);
551
552static struct attribute *cciss_dev_attrs[] = {
553 &dev_attr_unique_id.attr,
554 &dev_attr_model.attr,
555 &dev_attr_vendor.attr,
556 &dev_attr_rev.attr,
557 NULL
558};
559
560static struct attribute_group cciss_dev_attr_group = {
561 .attrs = cciss_dev_attrs,
562};
563
564static struct attribute_group *cciss_dev_attr_groups[] = {
565 &cciss_dev_attr_group,
566 NULL
567};
568
569static struct device_type cciss_dev_type = {
570 .name = "cciss_device",
571 .groups = cciss_dev_attr_groups,
572};
573
574static struct bus_type cciss_bus_type = {
575 .name = "cciss",
576};
577
578
579/*
580 * Initialize sysfs entry for each controller. This sets up and registers
581 * the 'cciss#' directory for each individual controller under
582 * /sys/bus/pci/devices/<dev>/.
583 */
584static int cciss_create_hba_sysfs_entry(struct ctlr_info *h)
585{
586 device_initialize(&h->dev);
587 h->dev.type = &cciss_host_type;
588 h->dev.bus = &cciss_bus_type;
589 dev_set_name(&h->dev, "%s", h->devname);
590 h->dev.parent = &h->pdev->dev;
591
592 return device_add(&h->dev);
593}
594
595/*
596 * Remove sysfs entries for an hba.
597 */
598static void cciss_destroy_hba_sysfs_entry(struct ctlr_info *h)
599{
600 device_del(&h->dev);
601}
602
603/*
604 * Initialize sysfs for each logical drive. This sets up and registers
605 * the 'c#d#' directory for each individual logical drive under
606 * /sys/bus/pci/devices/<dev/ccis#/. We also create a link from
607 * /sys/block/cciss!c#d# to this entry.
608 */
609static int cciss_create_ld_sysfs_entry(struct ctlr_info *h,
610 drive_info_struct *drv,
611 int drv_index)
612{
613 device_initialize(&drv->dev);
614 drv->dev.type = &cciss_dev_type;
615 drv->dev.bus = &cciss_bus_type;
616 dev_set_name(&drv->dev, "c%dd%d", h->ctlr, drv_index);
617 drv->dev.parent = &h->dev;
618 return device_add(&drv->dev);
619}
620
621/*
622 * Remove sysfs entries for a logical drive.
623 */
624static void cciss_destroy_ld_sysfs_entry(drive_info_struct *drv)
625{
626 device_del(&drv->dev);
627}
628
440/* 629/*
441 * For operations that cannot sleep, a command block is allocated at init, 630 * For operations that cannot sleep, a command block is allocated at init,
442 * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track 631 * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track
@@ -1299,7 +1488,6 @@ static void cciss_softirq_done(struct request *rq)
1299{ 1488{
1300 CommandList_struct *cmd = rq->completion_data; 1489 CommandList_struct *cmd = rq->completion_data;
1301 ctlr_info_t *h = hba[cmd->ctlr]; 1490 ctlr_info_t *h = hba[cmd->ctlr];
1302 unsigned int nr_bytes;
1303 unsigned long flags; 1491 unsigned long flags;
1304 u64bit temp64; 1492 u64bit temp64;
1305 int i, ddir; 1493 int i, ddir;
@@ -1321,15 +1509,11 @@ static void cciss_softirq_done(struct request *rq)
1321 printk("Done with %p\n", rq); 1509 printk("Done with %p\n", rq);
1322#endif /* CCISS_DEBUG */ 1510#endif /* CCISS_DEBUG */
1323 1511
1324 /* 1512 /* set the residual count for pc requests */
1325 * Store the full size and set the residual count for pc requests
1326 */
1327 nr_bytes = blk_rq_bytes(rq);
1328 if (blk_pc_request(rq)) 1513 if (blk_pc_request(rq))
1329 rq->data_len = cmd->err_info->ResidualCnt; 1514 rq->resid_len = cmd->err_info->ResidualCnt;
1330 1515
1331 if (blk_end_request(rq, (rq->errors == 0) ? 0 : -EIO, nr_bytes)) 1516 blk_end_request_all(rq, (rq->errors == 0) ? 0 : -EIO);
1332 BUG();
1333 1517
1334 spin_lock_irqsave(&h->lock, flags); 1518 spin_lock_irqsave(&h->lock, flags);
1335 cmd_free(h, cmd, 1); 1519 cmd_free(h, cmd, 1);
@@ -1337,6 +1521,56 @@ static void cciss_softirq_done(struct request *rq)
1337 spin_unlock_irqrestore(&h->lock, flags); 1521 spin_unlock_irqrestore(&h->lock, flags);
1338} 1522}
1339 1523
1524static void log_unit_to_scsi3addr(ctlr_info_t *h, unsigned char scsi3addr[],
1525 uint32_t log_unit)
1526{
1527 log_unit = h->drv[log_unit].LunID & 0x03fff;
1528 memset(&scsi3addr[4], 0, 4);
1529 memcpy(&scsi3addr[0], &log_unit, 4);
1530 scsi3addr[3] |= 0x40;
1531}
1532
1533/* This function gets the SCSI vendor, model, and revision of a logical drive
1534 * via the inquiry page 0. Model, vendor, and rev are set to empty strings if
1535 * they cannot be read.
1536 */
1537static void cciss_get_device_descr(int ctlr, int logvol, int withirq,
1538 char *vendor, char *model, char *rev)
1539{
1540 int rc;
1541 InquiryData_struct *inq_buf;
1542 unsigned char scsi3addr[8];
1543
1544 *vendor = '\0';
1545 *model = '\0';
1546 *rev = '\0';
1547
1548 inq_buf = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
1549 if (!inq_buf)
1550 return;
1551
1552 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol);
1553 if (withirq)
1554 rc = sendcmd_withirq(CISS_INQUIRY, ctlr, inq_buf,
1555 sizeof(InquiryData_struct), 0,
1556 scsi3addr, TYPE_CMD);
1557 else
1558 rc = sendcmd(CISS_INQUIRY, ctlr, inq_buf,
1559 sizeof(InquiryData_struct), 0,
1560 scsi3addr, TYPE_CMD);
1561 if (rc == IO_OK) {
1562 memcpy(vendor, &inq_buf->data_byte[8], VENDOR_LEN);
1563 vendor[VENDOR_LEN] = '\0';
1564 memcpy(model, &inq_buf->data_byte[16], MODEL_LEN);
1565 model[MODEL_LEN] = '\0';
1566 memcpy(rev, &inq_buf->data_byte[32], REV_LEN);
1567 rev[REV_LEN] = '\0';
1568 }
1569
1570 kfree(inq_buf);
1571 return;
1572}
1573
1340/* This function gets the serial number of a logical drive via 1574/* This function gets the serial number of a logical drive via
1341 * inquiry page 0x83. Serial no. is 16 bytes. If the serial 1575 * inquiry page 0x83. Serial no. is 16 bytes. If the serial
1342 * number cannot be had, for whatever reason, 16 bytes of 0xff 1576 * number cannot be had, for whatever reason, 16 bytes of 0xff
@@ -1348,6 +1582,7 @@ static void cciss_get_serial_no(int ctlr, int logvol, int withirq,
1348#define PAGE_83_INQ_BYTES 64 1582#define PAGE_83_INQ_BYTES 64
1349 int rc; 1583 int rc;
1350 unsigned char *buf; 1584 unsigned char *buf;
1585 unsigned char scsi3addr[8];
1351 1586
1352 if (buflen > 16) 1587 if (buflen > 16)
1353 buflen = 16; 1588 buflen = 16;
@@ -1356,12 +1591,13 @@ static void cciss_get_serial_no(int ctlr, int logvol, int withirq,
1356 if (!buf) 1591 if (!buf)
1357 return; 1592 return;
1358 memset(serial_no, 0, buflen); 1593 memset(serial_no, 0, buflen);
1594 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol);
1359 if (withirq) 1595 if (withirq)
1360 rc = sendcmd_withirq(CISS_INQUIRY, ctlr, buf, 1596 rc = sendcmd_withirq(CISS_INQUIRY, ctlr, buf,
1361 PAGE_83_INQ_BYTES, 1, logvol, 0x83, TYPE_CMD); 1597 PAGE_83_INQ_BYTES, 0x83, scsi3addr, TYPE_CMD);
1362 else 1598 else
1363 rc = sendcmd(CISS_INQUIRY, ctlr, buf, 1599 rc = sendcmd(CISS_INQUIRY, ctlr, buf,
1364 PAGE_83_INQ_BYTES, 1, logvol, 0x83, NULL, TYPE_CMD); 1600 PAGE_83_INQ_BYTES, 0x83, scsi3addr, TYPE_CMD);
1365 if (rc == IO_OK) 1601 if (rc == IO_OK)
1366 memcpy(serial_no, &buf[8], buflen); 1602 memcpy(serial_no, &buf[8], buflen);
1367 kfree(buf); 1603 kfree(buf);
@@ -1377,7 +1613,7 @@ static void cciss_add_disk(ctlr_info_t *h, struct gendisk *disk,
1377 disk->first_minor = drv_index << NWD_SHIFT; 1613 disk->first_minor = drv_index << NWD_SHIFT;
1378 disk->fops = &cciss_fops; 1614 disk->fops = &cciss_fops;
1379 disk->private_data = &h->drv[drv_index]; 1615 disk->private_data = &h->drv[drv_index];
1380 disk->driverfs_dev = &h->pdev->dev; 1616 disk->driverfs_dev = &h->drv[drv_index].dev;
1381 1617
1382 /* Set up queue information */ 1618 /* Set up queue information */
1383 blk_queue_bounce_limit(disk->queue, h->pdev->dma_mask); 1619 blk_queue_bounce_limit(disk->queue, h->pdev->dma_mask);
@@ -1394,8 +1630,8 @@ static void cciss_add_disk(ctlr_info_t *h, struct gendisk *disk,
1394 1630
1395 disk->queue->queuedata = h; 1631 disk->queue->queuedata = h;
1396 1632
1397 blk_queue_hardsect_size(disk->queue, 1633 blk_queue_logical_block_size(disk->queue,
1398 h->drv[drv_index].block_size); 1634 h->drv[drv_index].block_size);
1399 1635
1400 /* Make sure all queue data is written out before */ 1636 /* Make sure all queue data is written out before */
1401 /* setting h->drv[drv_index].queue, as setting this */ 1637 /* setting h->drv[drv_index].queue, as setting this */
@@ -1468,6 +1704,8 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time)
1468 drvinfo->block_size = block_size; 1704 drvinfo->block_size = block_size;
1469 drvinfo->nr_blocks = total_size + 1; 1705 drvinfo->nr_blocks = total_size + 1;
1470 1706
1707 cciss_get_device_descr(ctlr, drv_index, 1, drvinfo->vendor,
1708 drvinfo->model, drvinfo->rev);
1471 cciss_get_serial_no(ctlr, drv_index, 1, drvinfo->serial_no, 1709 cciss_get_serial_no(ctlr, drv_index, 1, drvinfo->serial_no,
1472 sizeof(drvinfo->serial_no)); 1710 sizeof(drvinfo->serial_no));
1473 1711
@@ -1517,6 +1755,9 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time)
1517 h->drv[drv_index].cylinders = drvinfo->cylinders; 1755 h->drv[drv_index].cylinders = drvinfo->cylinders;
1518 h->drv[drv_index].raid_level = drvinfo->raid_level; 1756 h->drv[drv_index].raid_level = drvinfo->raid_level;
1519 memcpy(h->drv[drv_index].serial_no, drvinfo->serial_no, 16); 1757 memcpy(h->drv[drv_index].serial_no, drvinfo->serial_no, 16);
1758 memcpy(h->drv[drv_index].vendor, drvinfo->vendor, VENDOR_LEN + 1);
1759 memcpy(h->drv[drv_index].model, drvinfo->model, MODEL_LEN + 1);
1760 memcpy(h->drv[drv_index].rev, drvinfo->rev, REV_LEN + 1);
1520 1761
1521 ++h->num_luns; 1762 ++h->num_luns;
1522 disk = h->gendisk[drv_index]; 1763 disk = h->gendisk[drv_index];
@@ -1591,6 +1832,8 @@ static int cciss_add_gendisk(ctlr_info_t *h, __u32 lunid, int controller_node)
1591 } 1832 }
1592 } 1833 }
1593 h->drv[drv_index].LunID = lunid; 1834 h->drv[drv_index].LunID = lunid;
1835 if (cciss_create_ld_sysfs_entry(h, &h->drv[drv_index], drv_index))
1836 goto err_free_disk;
1594 1837
1595 /* Don't need to mark this busy because nobody */ 1838 /* Don't need to mark this busy because nobody */
1596 /* else knows about this disk yet to contend */ 1839 /* else knows about this disk yet to contend */
@@ -1598,6 +1841,11 @@ static int cciss_add_gendisk(ctlr_info_t *h, __u32 lunid, int controller_node)
1598 h->drv[drv_index].busy_configuring = 0; 1841 h->drv[drv_index].busy_configuring = 0;
1599 wmb(); 1842 wmb();
1600 return drv_index; 1843 return drv_index;
1844
1845err_free_disk:
1846 put_disk(h->gendisk[drv_index]);
1847 h->gendisk[drv_index] = NULL;
1848 return -1;
1601} 1849}
1602 1850
1603/* This is for the special case of a controller which 1851/* This is for the special case of a controller which
@@ -1668,8 +1916,8 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time)
1668 goto mem_msg; 1916 goto mem_msg;
1669 1917
1670 return_code = sendcmd_withirq(CISS_REPORT_LOG, ctlr, ld_buff, 1918 return_code = sendcmd_withirq(CISS_REPORT_LOG, ctlr, ld_buff,
1671 sizeof(ReportLunData_struct), 0, 1919 sizeof(ReportLunData_struct),
1672 0, 0, TYPE_CMD); 1920 0, CTLR_LUNID, TYPE_CMD);
1673 1921
1674 if (return_code == IO_OK) 1922 if (return_code == IO_OK)
1675 listlength = be32_to_cpu(*(__be32 *) ld_buff->LUNListLength); 1923 listlength = be32_to_cpu(*(__be32 *) ld_buff->LUNListLength);
@@ -1718,6 +1966,7 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time)
1718 h->drv[i].busy_configuring = 1; 1966 h->drv[i].busy_configuring = 1;
1719 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 1967 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
1720 return_code = deregister_disk(h, i, 1); 1968 return_code = deregister_disk(h, i, 1);
1969 cciss_destroy_ld_sysfs_entry(&h->drv[i]);
1721 h->drv[i].busy_configuring = 0; 1970 h->drv[i].busy_configuring = 0;
1722 } 1971 }
1723 } 1972 }
@@ -1877,11 +2126,9 @@ static int deregister_disk(ctlr_info_t *h, int drv_index,
1877 return 0; 2126 return 0;
1878} 2127}
1879 2128
1880static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_t size, unsigned int use_unit_num, /* 0: address the controller, 2129static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff,
1881 1: address logical volume log_unit, 2130 size_t size, __u8 page_code, unsigned char *scsi3addr,
1882 2: periph device address is scsi3addr */ 2131 int cmd_type)
1883 unsigned int log_unit, __u8 page_code,
1884 unsigned char *scsi3addr, int cmd_type)
1885{ 2132{
1886 ctlr_info_t *h = hba[ctlr]; 2133 ctlr_info_t *h = hba[ctlr];
1887 u64bit buff_dma_handle; 2134 u64bit buff_dma_handle;
@@ -1897,27 +2144,12 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1897 c->Header.SGTotal = 0; 2144 c->Header.SGTotal = 0;
1898 } 2145 }
1899 c->Header.Tag.lower = c->busaddr; 2146 c->Header.Tag.lower = c->busaddr;
2147 memcpy(c->Header.LUN.LunAddrBytes, scsi3addr, 8);
1900 2148
1901 c->Request.Type.Type = cmd_type; 2149 c->Request.Type.Type = cmd_type;
1902 if (cmd_type == TYPE_CMD) { 2150 if (cmd_type == TYPE_CMD) {
1903 switch (cmd) { 2151 switch (cmd) {
1904 case CISS_INQUIRY: 2152 case CISS_INQUIRY:
1905 /* If the logical unit number is 0 then, this is going
1906 to controller so It's a physical command
1907 mode = 0 target = 0. So we have nothing to write.
1908 otherwise, if use_unit_num == 1,
1909 mode = 1(volume set addressing) target = LUNID
1910 otherwise, if use_unit_num == 2,
1911 mode = 0(periph dev addr) target = scsi3addr */
1912 if (use_unit_num == 1) {
1913 c->Header.LUN.LogDev.VolId =
1914 h->drv[log_unit].LunID;
1915 c->Header.LUN.LogDev.Mode = 1;
1916 } else if (use_unit_num == 2) {
1917 memcpy(c->Header.LUN.LunAddrBytes, scsi3addr,
1918 8);
1919 c->Header.LUN.LogDev.Mode = 0;
1920 }
1921 /* are we trying to read a vital product page */ 2153 /* are we trying to read a vital product page */
1922 if (page_code != 0) { 2154 if (page_code != 0) {
1923 c->Request.CDB[1] = 0x01; 2155 c->Request.CDB[1] = 0x01;
@@ -1947,8 +2179,6 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1947 break; 2179 break;
1948 2180
1949 case CCISS_READ_CAPACITY: 2181 case CCISS_READ_CAPACITY:
1950 c->Header.LUN.LogDev.VolId = h->drv[log_unit].LunID;
1951 c->Header.LUN.LogDev.Mode = 1;
1952 c->Request.CDBLen = 10; 2182 c->Request.CDBLen = 10;
1953 c->Request.Type.Attribute = ATTR_SIMPLE; 2183 c->Request.Type.Attribute = ATTR_SIMPLE;
1954 c->Request.Type.Direction = XFER_READ; 2184 c->Request.Type.Direction = XFER_READ;
@@ -1956,8 +2186,6 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1956 c->Request.CDB[0] = cmd; 2186 c->Request.CDB[0] = cmd;
1957 break; 2187 break;
1958 case CCISS_READ_CAPACITY_16: 2188 case CCISS_READ_CAPACITY_16:
1959 c->Header.LUN.LogDev.VolId = h->drv[log_unit].LunID;
1960 c->Header.LUN.LogDev.Mode = 1;
1961 c->Request.CDBLen = 16; 2189 c->Request.CDBLen = 16;
1962 c->Request.Type.Attribute = ATTR_SIMPLE; 2190 c->Request.Type.Attribute = ATTR_SIMPLE;
1963 c->Request.Type.Direction = XFER_READ; 2191 c->Request.Type.Direction = XFER_READ;
@@ -1979,6 +2207,12 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1979 c->Request.CDB[0] = BMIC_WRITE; 2207 c->Request.CDB[0] = BMIC_WRITE;
1980 c->Request.CDB[6] = BMIC_CACHE_FLUSH; 2208 c->Request.CDB[6] = BMIC_CACHE_FLUSH;
1981 break; 2209 break;
2210 case TEST_UNIT_READY:
2211 c->Request.CDBLen = 6;
2212 c->Request.Type.Attribute = ATTR_SIMPLE;
2213 c->Request.Type.Direction = XFER_NONE;
2214 c->Request.Timeout = 0;
2215 break;
1982 default: 2216 default:
1983 printk(KERN_WARNING 2217 printk(KERN_WARNING
1984 "cciss%d: Unknown Command 0x%c\n", ctlr, cmd); 2218 "cciss%d: Unknown Command 0x%c\n", ctlr, cmd);
@@ -1997,13 +2231,13 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1997 memcpy(&c->Request.CDB[4], buff, 8); 2231 memcpy(&c->Request.CDB[4], buff, 8);
1998 break; 2232 break;
1999 case 1: /* RESET message */ 2233 case 1: /* RESET message */
2000 c->Request.CDBLen = 12; 2234 c->Request.CDBLen = 16;
2001 c->Request.Type.Attribute = ATTR_SIMPLE; 2235 c->Request.Type.Attribute = ATTR_SIMPLE;
2002 c->Request.Type.Direction = XFER_WRITE; 2236 c->Request.Type.Direction = XFER_NONE;
2003 c->Request.Timeout = 0; 2237 c->Request.Timeout = 0;
2004 memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB)); 2238 memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB));
2005 c->Request.CDB[0] = cmd; /* reset */ 2239 c->Request.CDB[0] = cmd; /* reset */
2006 c->Request.CDB[1] = 0x04; /* reset a LUN */ 2240 c->Request.CDB[1] = 0x03; /* reset a target */
2007 break; 2241 break;
2008 case 3: /* No-Op message */ 2242 case 3: /* No-Op message */
2009 c->Request.CDBLen = 1; 2243 c->Request.CDBLen = 1;
@@ -2035,114 +2269,152 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
2035 return status; 2269 return status;
2036} 2270}
2037 2271
2038static int sendcmd_withirq(__u8 cmd, 2272static int check_target_status(ctlr_info_t *h, CommandList_struct *c)
2039 int ctlr,
2040 void *buff,
2041 size_t size,
2042 unsigned int use_unit_num,
2043 unsigned int log_unit, __u8 page_code, int cmd_type)
2044{ 2273{
2045 ctlr_info_t *h = hba[ctlr]; 2274 switch (c->err_info->ScsiStatus) {
2046 CommandList_struct *c; 2275 case SAM_STAT_GOOD:
2276 return IO_OK;
2277 case SAM_STAT_CHECK_CONDITION:
2278 switch (0xf & c->err_info->SenseInfo[2]) {
2279 case 0: return IO_OK; /* no sense */
2280 case 1: return IO_OK; /* recovered error */
2281 default:
2282 printk(KERN_WARNING "cciss%d: cmd 0x%02x "
2283 "check condition, sense key = 0x%02x\n",
2284 h->ctlr, c->Request.CDB[0],
2285 c->err_info->SenseInfo[2]);
2286 }
2287 break;
2288 default:
2289 printk(KERN_WARNING "cciss%d: cmd 0x%02x"
2290 "scsi status = 0x%02x\n", h->ctlr,
2291 c->Request.CDB[0], c->err_info->ScsiStatus);
2292 break;
2293 }
2294 return IO_ERROR;
2295}
2296
2297static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c)
2298{
2299 int return_status = IO_OK;
2300
2301 if (c->err_info->CommandStatus == CMD_SUCCESS)
2302 return IO_OK;
2303
2304 switch (c->err_info->CommandStatus) {
2305 case CMD_TARGET_STATUS:
2306 return_status = check_target_status(h, c);
2307 break;
2308 case CMD_DATA_UNDERRUN:
2309 case CMD_DATA_OVERRUN:
2310 /* expected for inquiry and report lun commands */
2311 break;
2312 case CMD_INVALID:
2313 printk(KERN_WARNING "cciss: cmd 0x%02x is "
2314 "reported invalid\n", c->Request.CDB[0]);
2315 return_status = IO_ERROR;
2316 break;
2317 case CMD_PROTOCOL_ERR:
2318 printk(KERN_WARNING "cciss: cmd 0x%02x has "
2319 "protocol error \n", c->Request.CDB[0]);
2320 return_status = IO_ERROR;
2321 break;
2322 case CMD_HARDWARE_ERR:
2323 printk(KERN_WARNING "cciss: cmd 0x%02x had "
2324 " hardware error\n", c->Request.CDB[0]);
2325 return_status = IO_ERROR;
2326 break;
2327 case CMD_CONNECTION_LOST:
2328 printk(KERN_WARNING "cciss: cmd 0x%02x had "
2329 "connection lost\n", c->Request.CDB[0]);
2330 return_status = IO_ERROR;
2331 break;
2332 case CMD_ABORTED:
2333 printk(KERN_WARNING "cciss: cmd 0x%02x was "
2334 "aborted\n", c->Request.CDB[0]);
2335 return_status = IO_ERROR;
2336 break;
2337 case CMD_ABORT_FAILED:
2338 printk(KERN_WARNING "cciss: cmd 0x%02x reports "
2339 "abort failed\n", c->Request.CDB[0]);
2340 return_status = IO_ERROR;
2341 break;
2342 case CMD_UNSOLICITED_ABORT:
2343 printk(KERN_WARNING
2344 "cciss%d: unsolicited abort 0x%02x\n", h->ctlr,
2345 c->Request.CDB[0]);
2346 return_status = IO_NEEDS_RETRY;
2347 break;
2348 default:
2349 printk(KERN_WARNING "cciss: cmd 0x%02x returned "
2350 "unknown status %x\n", c->Request.CDB[0],
2351 c->err_info->CommandStatus);
2352 return_status = IO_ERROR;
2353 }
2354 return return_status;
2355}
2356
2357static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c,
2358 int attempt_retry)
2359{
2360 DECLARE_COMPLETION_ONSTACK(wait);
2047 u64bit buff_dma_handle; 2361 u64bit buff_dma_handle;
2048 unsigned long flags; 2362 unsigned long flags;
2049 int return_status; 2363 int return_status = IO_OK;
2050 DECLARE_COMPLETION_ONSTACK(wait);
2051 2364
2052 if ((c = cmd_alloc(h, 0)) == NULL) 2365resend_cmd2:
2053 return -ENOMEM;
2054 return_status = fill_cmd(c, cmd, ctlr, buff, size, use_unit_num,
2055 log_unit, page_code, NULL, cmd_type);
2056 if (return_status != IO_OK) {
2057 cmd_free(h, c, 0);
2058 return return_status;
2059 }
2060 resend_cmd2:
2061 c->waiting = &wait; 2366 c->waiting = &wait;
2062
2063 /* Put the request on the tail of the queue and send it */ 2367 /* Put the request on the tail of the queue and send it */
2064 spin_lock_irqsave(CCISS_LOCK(ctlr), flags); 2368 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
2065 addQ(&h->reqQ, c); 2369 addQ(&h->reqQ, c);
2066 h->Qdepth++; 2370 h->Qdepth++;
2067 start_io(h); 2371 start_io(h);
2068 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); 2372 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
2069 2373
2070 wait_for_completion(&wait); 2374 wait_for_completion(&wait);
2071 2375
2072 if (c->err_info->CommandStatus != 0) { /* an error has occurred */ 2376 if (c->err_info->CommandStatus == 0 || !attempt_retry)
2073 switch (c->err_info->CommandStatus) { 2377 goto command_done;
2074 case CMD_TARGET_STATUS:
2075 printk(KERN_WARNING "cciss: cmd %p has "
2076 " completed with errors\n", c);
2077 if (c->err_info->ScsiStatus) {
2078 printk(KERN_WARNING "cciss: cmd %p "
2079 "has SCSI Status = %x\n",
2080 c, c->err_info->ScsiStatus);
2081 }
2082 2378
2083 break; 2379 return_status = process_sendcmd_error(h, c);
2084 case CMD_DATA_UNDERRUN: 2380
2085 case CMD_DATA_OVERRUN: 2381 if (return_status == IO_NEEDS_RETRY &&
2086 /* expected for inquire and report lun commands */ 2382 c->retry_count < MAX_CMD_RETRIES) {
2087 break; 2383 printk(KERN_WARNING "cciss%d: retrying 0x%02x\n", h->ctlr,
2088 case CMD_INVALID: 2384 c->Request.CDB[0]);
2089 printk(KERN_WARNING "cciss: Cmd %p is " 2385 c->retry_count++;
2090 "reported invalid\n", c); 2386 /* erase the old error information */
2091 return_status = IO_ERROR; 2387 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
2092 break; 2388 return_status = IO_OK;
2093 case CMD_PROTOCOL_ERR: 2389 INIT_COMPLETION(wait);
2094 printk(KERN_WARNING "cciss: cmd %p has " 2390 goto resend_cmd2;
2095 "protocol error \n", c);
2096 return_status = IO_ERROR;
2097 break;
2098 case CMD_HARDWARE_ERR:
2099 printk(KERN_WARNING "cciss: cmd %p had "
2100 " hardware error\n", c);
2101 return_status = IO_ERROR;
2102 break;
2103 case CMD_CONNECTION_LOST:
2104 printk(KERN_WARNING "cciss: cmd %p had "
2105 "connection lost\n", c);
2106 return_status = IO_ERROR;
2107 break;
2108 case CMD_ABORTED:
2109 printk(KERN_WARNING "cciss: cmd %p was "
2110 "aborted\n", c);
2111 return_status = IO_ERROR;
2112 break;
2113 case CMD_ABORT_FAILED:
2114 printk(KERN_WARNING "cciss: cmd %p reports "
2115 "abort failed\n", c);
2116 return_status = IO_ERROR;
2117 break;
2118 case CMD_UNSOLICITED_ABORT:
2119 printk(KERN_WARNING
2120 "cciss%d: unsolicited abort %p\n", ctlr, c);
2121 if (c->retry_count < MAX_CMD_RETRIES) {
2122 printk(KERN_WARNING
2123 "cciss%d: retrying %p\n", ctlr, c);
2124 c->retry_count++;
2125 /* erase the old error information */
2126 memset(c->err_info, 0,
2127 sizeof(ErrorInfo_struct));
2128 return_status = IO_OK;
2129 INIT_COMPLETION(wait);
2130 goto resend_cmd2;
2131 }
2132 return_status = IO_ERROR;
2133 break;
2134 default:
2135 printk(KERN_WARNING "cciss: cmd %p returned "
2136 "unknown status %x\n", c,
2137 c->err_info->CommandStatus);
2138 return_status = IO_ERROR;
2139 }
2140 } 2391 }
2392
2393command_done:
2141 /* unlock the buffers from DMA */ 2394 /* unlock the buffers from DMA */
2142 buff_dma_handle.val32.lower = c->SG[0].Addr.lower; 2395 buff_dma_handle.val32.lower = c->SG[0].Addr.lower;
2143 buff_dma_handle.val32.upper = c->SG[0].Addr.upper; 2396 buff_dma_handle.val32.upper = c->SG[0].Addr.upper;
2144 pci_unmap_single(h->pdev, (dma_addr_t) buff_dma_handle.val, 2397 pci_unmap_single(h->pdev, (dma_addr_t) buff_dma_handle.val,
2145 c->SG[0].Len, PCI_DMA_BIDIRECTIONAL); 2398 c->SG[0].Len, PCI_DMA_BIDIRECTIONAL);
2399 return return_status;
2400}
2401
2402static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size,
2403 __u8 page_code, unsigned char scsi3addr[],
2404 int cmd_type)
2405{
2406 ctlr_info_t *h = hba[ctlr];
2407 CommandList_struct *c;
2408 int return_status;
2409
2410 c = cmd_alloc(h, 0);
2411 if (!c)
2412 return -ENOMEM;
2413 return_status = fill_cmd(c, cmd, ctlr, buff, size, page_code,
2414 scsi3addr, cmd_type);
2415 if (return_status == IO_OK)
2416 return_status = sendcmd_withirq_core(h, c, 1);
2417
2146 cmd_free(h, c, 0); 2418 cmd_free(h, c, 0);
2147 return return_status; 2419 return return_status;
2148} 2420}
@@ -2155,15 +2427,17 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
2155{ 2427{
2156 int return_code; 2428 int return_code;
2157 unsigned long t; 2429 unsigned long t;
2430 unsigned char scsi3addr[8];
2158 2431
2159 memset(inq_buff, 0, sizeof(InquiryData_struct)); 2432 memset(inq_buff, 0, sizeof(InquiryData_struct));
2433 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol);
2160 if (withirq) 2434 if (withirq)
2161 return_code = sendcmd_withirq(CISS_INQUIRY, ctlr, 2435 return_code = sendcmd_withirq(CISS_INQUIRY, ctlr,
2162 inq_buff, sizeof(*inq_buff), 1, 2436 inq_buff, sizeof(*inq_buff),
2163 logvol, 0xC1, TYPE_CMD); 2437 0xC1, scsi3addr, TYPE_CMD);
2164 else 2438 else
2165 return_code = sendcmd(CISS_INQUIRY, ctlr, inq_buff, 2439 return_code = sendcmd(CISS_INQUIRY, ctlr, inq_buff,
2166 sizeof(*inq_buff), 1, logvol, 0xC1, NULL, 2440 sizeof(*inq_buff), 0xC1, scsi3addr,
2167 TYPE_CMD); 2441 TYPE_CMD);
2168 if (return_code == IO_OK) { 2442 if (return_code == IO_OK) {
2169 if (inq_buff->data_byte[8] == 0xFF) { 2443 if (inq_buff->data_byte[8] == 0xFF) {
@@ -2204,6 +2478,7 @@ cciss_read_capacity(int ctlr, int logvol, int withirq, sector_t *total_size,
2204{ 2478{
2205 ReadCapdata_struct *buf; 2479 ReadCapdata_struct *buf;
2206 int return_code; 2480 int return_code;
2481 unsigned char scsi3addr[8];
2207 2482
2208 buf = kzalloc(sizeof(ReadCapdata_struct), GFP_KERNEL); 2483 buf = kzalloc(sizeof(ReadCapdata_struct), GFP_KERNEL);
2209 if (!buf) { 2484 if (!buf) {
@@ -2211,14 +2486,15 @@ cciss_read_capacity(int ctlr, int logvol, int withirq, sector_t *total_size,
2211 return; 2486 return;
2212 } 2487 }
2213 2488
2489 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol);
2214 if (withirq) 2490 if (withirq)
2215 return_code = sendcmd_withirq(CCISS_READ_CAPACITY, 2491 return_code = sendcmd_withirq(CCISS_READ_CAPACITY,
2216 ctlr, buf, sizeof(ReadCapdata_struct), 2492 ctlr, buf, sizeof(ReadCapdata_struct),
2217 1, logvol, 0, TYPE_CMD); 2493 0, scsi3addr, TYPE_CMD);
2218 else 2494 else
2219 return_code = sendcmd(CCISS_READ_CAPACITY, 2495 return_code = sendcmd(CCISS_READ_CAPACITY,
2220 ctlr, buf, sizeof(ReadCapdata_struct), 2496 ctlr, buf, sizeof(ReadCapdata_struct),
2221 1, logvol, 0, NULL, TYPE_CMD); 2497 0, scsi3addr, TYPE_CMD);
2222 if (return_code == IO_OK) { 2498 if (return_code == IO_OK) {
2223 *total_size = be32_to_cpu(*(__be32 *) buf->total_size); 2499 *total_size = be32_to_cpu(*(__be32 *) buf->total_size);
2224 *block_size = be32_to_cpu(*(__be32 *) buf->block_size); 2500 *block_size = be32_to_cpu(*(__be32 *) buf->block_size);
@@ -2238,6 +2514,7 @@ cciss_read_capacity_16(int ctlr, int logvol, int withirq, sector_t *total_size,
2238{ 2514{
2239 ReadCapdata_struct_16 *buf; 2515 ReadCapdata_struct_16 *buf;
2240 int return_code; 2516 int return_code;
2517 unsigned char scsi3addr[8];
2241 2518
2242 buf = kzalloc(sizeof(ReadCapdata_struct_16), GFP_KERNEL); 2519 buf = kzalloc(sizeof(ReadCapdata_struct_16), GFP_KERNEL);
2243 if (!buf) { 2520 if (!buf) {
@@ -2245,15 +2522,16 @@ cciss_read_capacity_16(int ctlr, int logvol, int withirq, sector_t *total_size,
2245 return; 2522 return;
2246 } 2523 }
2247 2524
2525 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol);
2248 if (withirq) { 2526 if (withirq) {
2249 return_code = sendcmd_withirq(CCISS_READ_CAPACITY_16, 2527 return_code = sendcmd_withirq(CCISS_READ_CAPACITY_16,
2250 ctlr, buf, sizeof(ReadCapdata_struct_16), 2528 ctlr, buf, sizeof(ReadCapdata_struct_16),
2251 1, logvol, 0, TYPE_CMD); 2529 0, scsi3addr, TYPE_CMD);
2252 } 2530 }
2253 else { 2531 else {
2254 return_code = sendcmd(CCISS_READ_CAPACITY_16, 2532 return_code = sendcmd(CCISS_READ_CAPACITY_16,
2255 ctlr, buf, sizeof(ReadCapdata_struct_16), 2533 ctlr, buf, sizeof(ReadCapdata_struct_16),
2256 1, logvol, 0, NULL, TYPE_CMD); 2534 0, scsi3addr, TYPE_CMD);
2257 } 2535 }
2258 if (return_code == IO_OK) { 2536 if (return_code == IO_OK) {
2259 *total_size = be64_to_cpu(*(__be64 *) buf->total_size); 2537 *total_size = be64_to_cpu(*(__be64 *) buf->total_size);
@@ -2303,7 +2581,7 @@ static int cciss_revalidate(struct gendisk *disk)
2303 cciss_geometry_inquiry(h->ctlr, logvol, 1, total_size, block_size, 2581 cciss_geometry_inquiry(h->ctlr, logvol, 1, total_size, block_size,
2304 inq_buff, drv); 2582 inq_buff, drv);
2305 2583
2306 blk_queue_hardsect_size(drv->queue, drv->block_size); 2584 blk_queue_logical_block_size(drv->queue, drv->block_size);
2307 set_capacity(disk, drv->nr_blocks); 2585 set_capacity(disk, drv->nr_blocks);
2308 2586
2309 kfree(inq_buff); 2587 kfree(inq_buff);
@@ -2333,86 +2611,21 @@ static unsigned long pollcomplete(int ctlr)
2333 return 1; 2611 return 1;
2334} 2612}
2335 2613
2336static int add_sendcmd_reject(__u8 cmd, int ctlr, unsigned long complete) 2614/* Send command c to controller h and poll for it to complete.
2337{ 2615 * Turns interrupts off on the board. Used at driver init time
2338 /* We get in here if sendcmd() is polling for completions 2616 * and during SCSI error recovery.
2339 and gets some command back that it wasn't expecting --
2340 something other than that which it just sent down.
2341 Ordinarily, that shouldn't happen, but it can happen when
2342 the scsi tape stuff gets into error handling mode, and
2343 starts using sendcmd() to try to abort commands and
2344 reset tape drives. In that case, sendcmd may pick up
2345 completions of commands that were sent to logical drives
2346 through the block i/o system, or cciss ioctls completing, etc.
2347 In that case, we need to save those completions for later
2348 processing by the interrupt handler.
2349 */
2350
2351#ifdef CONFIG_CISS_SCSI_TAPE
2352 struct sendcmd_reject_list *srl = &hba[ctlr]->scsi_rejects;
2353
2354 /* If it's not the scsi tape stuff doing error handling, (abort */
2355 /* or reset) then we don't expect anything weird. */
2356 if (cmd != CCISS_RESET_MSG && cmd != CCISS_ABORT_MSG) {
2357#endif
2358 printk(KERN_WARNING "cciss cciss%d: SendCmd "
2359 "Invalid command list address returned! (%lx)\n",
2360 ctlr, complete);
2361 /* not much we can do. */
2362#ifdef CONFIG_CISS_SCSI_TAPE
2363 return 1;
2364 }
2365
2366 /* We've sent down an abort or reset, but something else
2367 has completed */
2368 if (srl->ncompletions >= (hba[ctlr]->nr_cmds + 2)) {
2369 /* Uh oh. No room to save it for later... */
2370 printk(KERN_WARNING "cciss%d: Sendcmd: Invalid command addr, "
2371 "reject list overflow, command lost!\n", ctlr);
2372 return 1;
2373 }
2374 /* Save it for later */
2375 srl->complete[srl->ncompletions] = complete;
2376 srl->ncompletions++;
2377#endif
2378 return 0;
2379}
2380
2381/*
2382 * Send a command to the controller, and wait for it to complete.
2383 * Only used at init time.
2384 */ 2617 */
2385static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size, unsigned int use_unit_num, /* 0: address the controller, 2618static int sendcmd_core(ctlr_info_t *h, CommandList_struct *c)
2386 1: address logical volume log_unit,
2387 2: periph device address is scsi3addr */
2388 unsigned int log_unit,
2389 __u8 page_code, unsigned char *scsi3addr, int cmd_type)
2390{ 2619{
2391 CommandList_struct *c;
2392 int i; 2620 int i;
2393 unsigned long complete; 2621 unsigned long complete;
2394 ctlr_info_t *info_p = hba[ctlr]; 2622 int status = IO_ERROR;
2395 u64bit buff_dma_handle; 2623 u64bit buff_dma_handle;
2396 int status, done = 0;
2397 2624
2398 if ((c = cmd_alloc(info_p, 1)) == NULL) { 2625resend_cmd1:
2399 printk(KERN_WARNING "cciss: unable to get memory"); 2626
2400 return IO_ERROR; 2627 /* Disable interrupt on the board. */
2401 } 2628 h->access.set_intr_mask(h, CCISS_INTR_OFF);
2402 status = fill_cmd(c, cmd, ctlr, buff, size, use_unit_num,
2403 log_unit, page_code, scsi3addr, cmd_type);
2404 if (status != IO_OK) {
2405 cmd_free(info_p, c, 1);
2406 return status;
2407 }
2408 resend_cmd1:
2409 /*
2410 * Disable interrupt
2411 */
2412#ifdef CCISS_DEBUG
2413 printk(KERN_DEBUG "cciss: turning intr off\n");
2414#endif /* CCISS_DEBUG */
2415 info_p->access.set_intr_mask(info_p, CCISS_INTR_OFF);
2416 2629
2417 /* Make sure there is room in the command FIFO */ 2630 /* Make sure there is room in the command FIFO */
2418 /* Actually it should be completely empty at this time */ 2631 /* Actually it should be completely empty at this time */
@@ -2420,21 +2633,15 @@ static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size, unsigned int use
2420 /* tape side of the driver. */ 2633 /* tape side of the driver. */
2421 for (i = 200000; i > 0; i--) { 2634 for (i = 200000; i > 0; i--) {
2422 /* if fifo isn't full go */ 2635 /* if fifo isn't full go */
2423 if (!(info_p->access.fifo_full(info_p))) { 2636 if (!(h->access.fifo_full(h)))
2424
2425 break; 2637 break;
2426 }
2427 udelay(10); 2638 udelay(10);
2428 printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full," 2639 printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full,"
2429 " waiting!\n", ctlr); 2640 " waiting!\n", h->ctlr);
2430 } 2641 }
2431 /* 2642 h->access.submit_command(h, c); /* Send the cmd */
2432 * Send the cmd
2433 */
2434 info_p->access.submit_command(info_p, c);
2435 done = 0;
2436 do { 2643 do {
2437 complete = pollcomplete(ctlr); 2644 complete = pollcomplete(h->ctlr);
2438 2645
2439#ifdef CCISS_DEBUG 2646#ifdef CCISS_DEBUG
2440 printk(KERN_DEBUG "cciss: command completed\n"); 2647 printk(KERN_DEBUG "cciss: command completed\n");
@@ -2443,97 +2650,102 @@ static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size, unsigned int use
2443 if (complete == 1) { 2650 if (complete == 1) {
2444 printk(KERN_WARNING 2651 printk(KERN_WARNING
2445 "cciss cciss%d: SendCmd Timeout out, " 2652 "cciss cciss%d: SendCmd Timeout out, "
2446 "No command list address returned!\n", ctlr); 2653 "No command list address returned!\n", h->ctlr);
2447 status = IO_ERROR; 2654 status = IO_ERROR;
2448 done = 1;
2449 break; 2655 break;
2450 } 2656 }
2451 2657
2452 /* This will need to change for direct lookup completions */ 2658 /* Make sure it's the command we're expecting. */
2453 if ((complete & CISS_ERROR_BIT) 2659 if ((complete & ~CISS_ERROR_BIT) != c->busaddr) {
2454 && (complete & ~CISS_ERROR_BIT) == c->busaddr) { 2660 printk(KERN_WARNING "cciss%d: Unexpected command "
2455 /* if data overrun or underun on Report command 2661 "completion.\n", h->ctlr);
2456 ignore it 2662 continue;
2457 */ 2663 }
2458 if (((c->Request.CDB[0] == CISS_REPORT_LOG) || 2664
2459 (c->Request.CDB[0] == CISS_REPORT_PHYS) || 2665 /* It is our command. If no error, we're done. */
2460 (c->Request.CDB[0] == CISS_INQUIRY)) && 2666 if (!(complete & CISS_ERROR_BIT)) {
2461 ((c->err_info->CommandStatus == 2667 status = IO_OK;
2462 CMD_DATA_OVERRUN) || 2668 break;
2463 (c->err_info->CommandStatus == CMD_DATA_UNDERRUN)
2464 )) {
2465 complete = c->busaddr;
2466 } else {
2467 if (c->err_info->CommandStatus ==
2468 CMD_UNSOLICITED_ABORT) {
2469 printk(KERN_WARNING "cciss%d: "
2470 "unsolicited abort %p\n",
2471 ctlr, c);
2472 if (c->retry_count < MAX_CMD_RETRIES) {
2473 printk(KERN_WARNING
2474 "cciss%d: retrying %p\n",
2475 ctlr, c);
2476 c->retry_count++;
2477 /* erase the old error */
2478 /* information */
2479 memset(c->err_info, 0,
2480 sizeof
2481 (ErrorInfo_struct));
2482 goto resend_cmd1;
2483 } else {
2484 printk(KERN_WARNING
2485 "cciss%d: retried %p too "
2486 "many times\n", ctlr, c);
2487 status = IO_ERROR;
2488 goto cleanup1;
2489 }
2490 } else if (c->err_info->CommandStatus ==
2491 CMD_UNABORTABLE) {
2492 printk(KERN_WARNING
2493 "cciss%d: command could not be aborted.\n",
2494 ctlr);
2495 status = IO_ERROR;
2496 goto cleanup1;
2497 }
2498 printk(KERN_WARNING "ciss ciss%d: sendcmd"
2499 " Error %x \n", ctlr,
2500 c->err_info->CommandStatus);
2501 printk(KERN_WARNING "ciss ciss%d: sendcmd"
2502 " offensive info\n"
2503 " size %x\n num %x value %x\n",
2504 ctlr,
2505 c->err_info->MoreErrInfo.Invalid_Cmd.
2506 offense_size,
2507 c->err_info->MoreErrInfo.Invalid_Cmd.
2508 offense_num,
2509 c->err_info->MoreErrInfo.Invalid_Cmd.
2510 offense_value);
2511 status = IO_ERROR;
2512 goto cleanup1;
2513 }
2514 } 2669 }
2515 /* This will need changing for direct lookup completions */ 2670
2516 if (complete != c->busaddr) { 2671 /* There is an error... */
2517 if (add_sendcmd_reject(cmd, ctlr, complete) != 0) { 2672
2518 BUG(); /* we are pretty much hosed if we get here. */ 2673 /* if data overrun or underun on Report command ignore it */
2674 if (((c->Request.CDB[0] == CISS_REPORT_LOG) ||
2675 (c->Request.CDB[0] == CISS_REPORT_PHYS) ||
2676 (c->Request.CDB[0] == CISS_INQUIRY)) &&
2677 ((c->err_info->CommandStatus == CMD_DATA_OVERRUN) ||
2678 (c->err_info->CommandStatus == CMD_DATA_UNDERRUN))) {
2679 complete = c->busaddr;
2680 status = IO_OK;
2681 break;
2682 }
2683
2684 if (c->err_info->CommandStatus == CMD_UNSOLICITED_ABORT) {
2685 printk(KERN_WARNING "cciss%d: unsolicited abort %p\n",
2686 h->ctlr, c);
2687 if (c->retry_count < MAX_CMD_RETRIES) {
2688 printk(KERN_WARNING "cciss%d: retrying %p\n",
2689 h->ctlr, c);
2690 c->retry_count++;
2691 /* erase the old error information */
2692 memset(c->err_info, 0, sizeof(c->err_info));
2693 goto resend_cmd1;
2519 } 2694 }
2520 continue; 2695 printk(KERN_WARNING "cciss%d: retried %p too many "
2521 } else 2696 "times\n", h->ctlr, c);
2522 done = 1; 2697 status = IO_ERROR;
2523 } while (!done); 2698 break;
2699 }
2700
2701 if (c->err_info->CommandStatus == CMD_UNABORTABLE) {
2702 printk(KERN_WARNING "cciss%d: command could not be "
2703 "aborted.\n", h->ctlr);
2704 status = IO_ERROR;
2705 break;
2706 }
2707
2708 if (c->err_info->CommandStatus == CMD_TARGET_STATUS) {
2709 status = check_target_status(h, c);
2710 break;
2711 }
2712
2713 printk(KERN_WARNING "cciss%d: sendcmd error\n", h->ctlr);
2714 printk(KERN_WARNING "cmd = 0x%02x, CommandStatus = 0x%02x\n",
2715 c->Request.CDB[0], c->err_info->CommandStatus);
2716 status = IO_ERROR;
2717 break;
2718
2719 } while (1);
2524 2720
2525 cleanup1:
2526 /* unlock the data buffer from DMA */ 2721 /* unlock the data buffer from DMA */
2527 buff_dma_handle.val32.lower = c->SG[0].Addr.lower; 2722 buff_dma_handle.val32.lower = c->SG[0].Addr.lower;
2528 buff_dma_handle.val32.upper = c->SG[0].Addr.upper; 2723 buff_dma_handle.val32.upper = c->SG[0].Addr.upper;
2529 pci_unmap_single(info_p->pdev, (dma_addr_t) buff_dma_handle.val, 2724 pci_unmap_single(h->pdev, (dma_addr_t) buff_dma_handle.val,
2530 c->SG[0].Len, PCI_DMA_BIDIRECTIONAL); 2725 c->SG[0].Len, PCI_DMA_BIDIRECTIONAL);
2531#ifdef CONFIG_CISS_SCSI_TAPE 2726 return status;
2532 /* if we saved some commands for later, process them now. */ 2727}
2533 if (info_p->scsi_rejects.ncompletions > 0) 2728
2534 do_cciss_intr(0, info_p); 2729/*
2535#endif 2730 * Send a command to the controller, and wait for it to complete.
2536 cmd_free(info_p, c, 1); 2731 * Used at init time, and during SCSI error recovery.
2732 */
2733static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size,
2734 __u8 page_code, unsigned char *scsi3addr, int cmd_type)
2735{
2736 CommandList_struct *c;
2737 int status;
2738
2739 c = cmd_alloc(hba[ctlr], 1);
2740 if (!c) {
2741 printk(KERN_WARNING "cciss: unable to get memory");
2742 return IO_ERROR;
2743 }
2744 status = fill_cmd(c, cmd, ctlr, buff, size, page_code,
2745 scsi3addr, cmd_type);
2746 if (status == IO_OK)
2747 status = sendcmd_core(hba[ctlr], c);
2748 cmd_free(hba[ctlr], c, 1);
2537 return status; 2749 return status;
2538} 2750}
2539 2751
@@ -2691,7 +2903,7 @@ static inline void complete_command(ctlr_info_t *h, CommandList_struct *cmd,
2691 printk(KERN_WARNING "cciss: cmd %p has" 2903 printk(KERN_WARNING "cciss: cmd %p has"
2692 " completed with data underrun " 2904 " completed with data underrun "
2693 "reported\n", cmd); 2905 "reported\n", cmd);
2694 cmd->rq->data_len = cmd->err_info->ResidualCnt; 2906 cmd->rq->resid_len = cmd->err_info->ResidualCnt;
2695 } 2907 }
2696 break; 2908 break;
2697 case CMD_DATA_OVERRUN: 2909 case CMD_DATA_OVERRUN:
@@ -2806,7 +3018,7 @@ static void do_cciss_request(struct request_queue *q)
2806 goto startio; 3018 goto startio;
2807 3019
2808 queue: 3020 queue:
2809 creq = elv_next_request(q); 3021 creq = blk_peek_request(q);
2810 if (!creq) 3022 if (!creq)
2811 goto startio; 3023 goto startio;
2812 3024
@@ -2815,7 +3027,7 @@ static void do_cciss_request(struct request_queue *q)
2815 if ((c = cmd_alloc(h, 1)) == NULL) 3027 if ((c = cmd_alloc(h, 1)) == NULL)
2816 goto full; 3028 goto full;
2817 3029
2818 blkdev_dequeue_request(creq); 3030 blk_start_request(creq);
2819 3031
2820 spin_unlock_irq(q->queue_lock); 3032 spin_unlock_irq(q->queue_lock);
2821 3033
@@ -2840,10 +3052,10 @@ static void do_cciss_request(struct request_queue *q)
2840 c->Request.Timeout = 0; // Don't time out 3052 c->Request.Timeout = 0; // Don't time out
2841 c->Request.CDB[0] = 3053 c->Request.CDB[0] =
2842 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write; 3054 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write;
2843 start_blk = creq->sector; 3055 start_blk = blk_rq_pos(creq);
2844#ifdef CCISS_DEBUG 3056#ifdef CCISS_DEBUG
2845 printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n", (int)creq->sector, 3057 printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n",
2846 (int)creq->nr_sectors); 3058 (int)blk_rq_pos(creq), (int)blk_rq_sectors(creq));
2847#endif /* CCISS_DEBUG */ 3059#endif /* CCISS_DEBUG */
2848 3060
2849 sg_init_table(tmp_sg, MAXSGENTRIES); 3061 sg_init_table(tmp_sg, MAXSGENTRIES);
@@ -2869,8 +3081,8 @@ static void do_cciss_request(struct request_queue *q)
2869 h->maxSG = seg; 3081 h->maxSG = seg;
2870 3082
2871#ifdef CCISS_DEBUG 3083#ifdef CCISS_DEBUG
2872 printk(KERN_DEBUG "cciss: Submitting %lu sectors in %d segments\n", 3084 printk(KERN_DEBUG "cciss: Submitting %u sectors in %d segments\n",
2873 creq->nr_sectors, seg); 3085 blk_rq_sectors(creq), seg);
2874#endif /* CCISS_DEBUG */ 3086#endif /* CCISS_DEBUG */
2875 3087
2876 c->Header.SGList = c->Header.SGTotal = seg; 3088 c->Header.SGList = c->Header.SGTotal = seg;
@@ -2882,8 +3094,8 @@ static void do_cciss_request(struct request_queue *q)
2882 c->Request.CDB[4] = (start_blk >> 8) & 0xff; 3094 c->Request.CDB[4] = (start_blk >> 8) & 0xff;
2883 c->Request.CDB[5] = start_blk & 0xff; 3095 c->Request.CDB[5] = start_blk & 0xff;
2884 c->Request.CDB[6] = 0; // (sect >> 24) & 0xff; MSB 3096 c->Request.CDB[6] = 0; // (sect >> 24) & 0xff; MSB
2885 c->Request.CDB[7] = (creq->nr_sectors >> 8) & 0xff; 3097 c->Request.CDB[7] = (blk_rq_sectors(creq) >> 8) & 0xff;
2886 c->Request.CDB[8] = creq->nr_sectors & 0xff; 3098 c->Request.CDB[8] = blk_rq_sectors(creq) & 0xff;
2887 c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0; 3099 c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0;
2888 } else { 3100 } else {
2889 u32 upper32 = upper_32_bits(start_blk); 3101 u32 upper32 = upper_32_bits(start_blk);
@@ -2898,10 +3110,10 @@ static void do_cciss_request(struct request_queue *q)
2898 c->Request.CDB[7]= (start_blk >> 16) & 0xff; 3110 c->Request.CDB[7]= (start_blk >> 16) & 0xff;
2899 c->Request.CDB[8]= (start_blk >> 8) & 0xff; 3111 c->Request.CDB[8]= (start_blk >> 8) & 0xff;
2900 c->Request.CDB[9]= start_blk & 0xff; 3112 c->Request.CDB[9]= start_blk & 0xff;
2901 c->Request.CDB[10]= (creq->nr_sectors >> 24) & 0xff; 3113 c->Request.CDB[10]= (blk_rq_sectors(creq) >> 24) & 0xff;
2902 c->Request.CDB[11]= (creq->nr_sectors >> 16) & 0xff; 3114 c->Request.CDB[11]= (blk_rq_sectors(creq) >> 16) & 0xff;
2903 c->Request.CDB[12]= (creq->nr_sectors >> 8) & 0xff; 3115 c->Request.CDB[12]= (blk_rq_sectors(creq) >> 8) & 0xff;
2904 c->Request.CDB[13]= creq->nr_sectors & 0xff; 3116 c->Request.CDB[13]= blk_rq_sectors(creq) & 0xff;
2905 c->Request.CDB[14] = c->Request.CDB[15] = 0; 3117 c->Request.CDB[14] = c->Request.CDB[15] = 0;
2906 } 3118 }
2907 } else if (blk_pc_request(creq)) { 3119 } else if (blk_pc_request(creq)) {
@@ -2931,44 +3143,18 @@ startio:
2931 3143
2932static inline unsigned long get_next_completion(ctlr_info_t *h) 3144static inline unsigned long get_next_completion(ctlr_info_t *h)
2933{ 3145{
2934#ifdef CONFIG_CISS_SCSI_TAPE
2935 /* Any rejects from sendcmd() lying around? Process them first */
2936 if (h->scsi_rejects.ncompletions == 0)
2937 return h->access.command_completed(h);
2938 else {
2939 struct sendcmd_reject_list *srl;
2940 int n;
2941 srl = &h->scsi_rejects;
2942 n = --srl->ncompletions;
2943 /* printk("cciss%d: processing saved reject\n", h->ctlr); */
2944 printk("p");
2945 return srl->complete[n];
2946 }
2947#else
2948 return h->access.command_completed(h); 3146 return h->access.command_completed(h);
2949#endif
2950} 3147}
2951 3148
2952static inline int interrupt_pending(ctlr_info_t *h) 3149static inline int interrupt_pending(ctlr_info_t *h)
2953{ 3150{
2954#ifdef CONFIG_CISS_SCSI_TAPE
2955 return (h->access.intr_pending(h)
2956 || (h->scsi_rejects.ncompletions > 0));
2957#else
2958 return h->access.intr_pending(h); 3151 return h->access.intr_pending(h);
2959#endif
2960} 3152}
2961 3153
2962static inline long interrupt_not_for_us(ctlr_info_t *h) 3154static inline long interrupt_not_for_us(ctlr_info_t *h)
2963{ 3155{
2964#ifdef CONFIG_CISS_SCSI_TAPE
2965 return (((h->access.intr_pending(h) == 0) ||
2966 (h->interrupts_enabled == 0))
2967 && (h->scsi_rejects.ncompletions == 0));
2968#else
2969 return (((h->access.intr_pending(h) == 0) || 3156 return (((h->access.intr_pending(h) == 0) ||
2970 (h->interrupts_enabled == 0))); 3157 (h->interrupts_enabled == 0)));
2971#endif
2972} 3158}
2973 3159
2974static irqreturn_t do_cciss_intr(int irq, void *dev_id) 3160static irqreturn_t do_cciss_intr(int irq, void *dev_id)
@@ -3723,12 +3909,15 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3723 INIT_HLIST_HEAD(&hba[i]->reqQ); 3909 INIT_HLIST_HEAD(&hba[i]->reqQ);
3724 3910
3725 if (cciss_pci_init(hba[i], pdev) != 0) 3911 if (cciss_pci_init(hba[i], pdev) != 0)
3726 goto clean1; 3912 goto clean0;
3727 3913
3728 sprintf(hba[i]->devname, "cciss%d", i); 3914 sprintf(hba[i]->devname, "cciss%d", i);
3729 hba[i]->ctlr = i; 3915 hba[i]->ctlr = i;
3730 hba[i]->pdev = pdev; 3916 hba[i]->pdev = pdev;
3731 3917
3918 if (cciss_create_hba_sysfs_entry(hba[i]))
3919 goto clean0;
3920
3732 /* configure PCI DMA stuff */ 3921 /* configure PCI DMA stuff */
3733 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) 3922 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)))
3734 dac = 1; 3923 dac = 1;
@@ -3787,15 +3976,6 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3787 printk(KERN_ERR "cciss: out of memory"); 3976 printk(KERN_ERR "cciss: out of memory");
3788 goto clean4; 3977 goto clean4;
3789 } 3978 }
3790#ifdef CONFIG_CISS_SCSI_TAPE
3791 hba[i]->scsi_rejects.complete =
3792 kmalloc(sizeof(hba[i]->scsi_rejects.complete[0]) *
3793 (hba[i]->nr_cmds + 5), GFP_KERNEL);
3794 if (hba[i]->scsi_rejects.complete == NULL) {
3795 printk(KERN_ERR "cciss: out of memory");
3796 goto clean4;
3797 }
3798#endif
3799 spin_lock_init(&hba[i]->lock); 3979 spin_lock_init(&hba[i]->lock);
3800 3980
3801 /* Initialize the pdev driver private data. 3981 /* Initialize the pdev driver private data.
@@ -3828,7 +4008,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3828 } 4008 }
3829 4009
3830 return_code = sendcmd_withirq(CISS_INQUIRY, i, inq_buff, 4010 return_code = sendcmd_withirq(CISS_INQUIRY, i, inq_buff,
3831 sizeof(InquiryData_struct), 0, 0 , 0, TYPE_CMD); 4011 sizeof(InquiryData_struct), 0, CTLR_LUNID, TYPE_CMD);
3832 if (return_code == IO_OK) { 4012 if (return_code == IO_OK) {
3833 hba[i]->firm_ver[0] = inq_buff->data_byte[32]; 4013 hba[i]->firm_ver[0] = inq_buff->data_byte[32];
3834 hba[i]->firm_ver[1] = inq_buff->data_byte[33]; 4014 hba[i]->firm_ver[1] = inq_buff->data_byte[33];
@@ -3855,9 +4035,6 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3855 4035
3856clean4: 4036clean4:
3857 kfree(inq_buff); 4037 kfree(inq_buff);
3858#ifdef CONFIG_CISS_SCSI_TAPE
3859 kfree(hba[i]->scsi_rejects.complete);
3860#endif
3861 kfree(hba[i]->cmd_pool_bits); 4038 kfree(hba[i]->cmd_pool_bits);
3862 if (hba[i]->cmd_pool) 4039 if (hba[i]->cmd_pool)
3863 pci_free_consistent(hba[i]->pdev, 4040 pci_free_consistent(hba[i]->pdev,
@@ -3872,6 +4049,8 @@ clean4:
3872clean2: 4049clean2:
3873 unregister_blkdev(hba[i]->major, hba[i]->devname); 4050 unregister_blkdev(hba[i]->major, hba[i]->devname);
3874clean1: 4051clean1:
4052 cciss_destroy_hba_sysfs_entry(hba[i]);
4053clean0:
3875 hba[i]->busy_initializing = 0; 4054 hba[i]->busy_initializing = 0;
3876 /* cleanup any queues that may have been initialized */ 4055 /* cleanup any queues that may have been initialized */
3877 for (j=0; j <= hba[i]->highest_lun; j++){ 4056 for (j=0; j <= hba[i]->highest_lun; j++){
@@ -3907,8 +4086,8 @@ static void cciss_shutdown(struct pci_dev *pdev)
3907 /* sendcmd will turn off interrupt, and send the flush... 4086 /* sendcmd will turn off interrupt, and send the flush...
3908 * To write all data in the battery backed cache to disks */ 4087 * To write all data in the battery backed cache to disks */
3909 memset(flush_buf, 0, 4); 4088 memset(flush_buf, 0, 4);
3910 return_code = sendcmd(CCISS_CACHE_FLUSH, i, flush_buf, 4, 0, 0, 0, NULL, 4089 return_code = sendcmd(CCISS_CACHE_FLUSH, i, flush_buf, 4, 0,
3911 TYPE_CMD); 4090 CTLR_LUNID, TYPE_CMD);
3912 if (return_code == IO_OK) { 4091 if (return_code == IO_OK) {
3913 printk(KERN_INFO "Completed flushing cache on controller %d\n", i); 4092 printk(KERN_INFO "Completed flushing cache on controller %d\n", i);
3914 } else { 4093 } else {
@@ -3973,15 +4152,13 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev)
3973 pci_free_consistent(hba[i]->pdev, hba[i]->nr_cmds * sizeof(ErrorInfo_struct), 4152 pci_free_consistent(hba[i]->pdev, hba[i]->nr_cmds * sizeof(ErrorInfo_struct),
3974 hba[i]->errinfo_pool, hba[i]->errinfo_pool_dhandle); 4153 hba[i]->errinfo_pool, hba[i]->errinfo_pool_dhandle);
3975 kfree(hba[i]->cmd_pool_bits); 4154 kfree(hba[i]->cmd_pool_bits);
3976#ifdef CONFIG_CISS_SCSI_TAPE
3977 kfree(hba[i]->scsi_rejects.complete);
3978#endif
3979 /* 4155 /*
3980 * Deliberately omit pci_disable_device(): it does something nasty to 4156 * Deliberately omit pci_disable_device(): it does something nasty to
3981 * Smart Array controllers that pci_enable_device does not undo 4157 * Smart Array controllers that pci_enable_device does not undo
3982 */ 4158 */
3983 pci_release_regions(pdev); 4159 pci_release_regions(pdev);
3984 pci_set_drvdata(pdev, NULL); 4160 pci_set_drvdata(pdev, NULL);
4161 cciss_destroy_hba_sysfs_entry(hba[i]);
3985 free_hba(i); 4162 free_hba(i);
3986} 4163}
3987 4164
@@ -3999,6 +4176,8 @@ static struct pci_driver cciss_pci_driver = {
3999 */ 4176 */
4000static int __init cciss_init(void) 4177static int __init cciss_init(void)
4001{ 4178{
4179 int err;
4180
4002 /* 4181 /*
4003 * The hardware requires that commands are aligned on a 64-bit 4182 * The hardware requires that commands are aligned on a 64-bit
4004 * boundary. Given that we use pci_alloc_consistent() to allocate an 4183 * boundary. Given that we use pci_alloc_consistent() to allocate an
@@ -4008,8 +4187,20 @@ static int __init cciss_init(void)
4008 4187
4009 printk(KERN_INFO DRIVER_NAME "\n"); 4188 printk(KERN_INFO DRIVER_NAME "\n");
4010 4189
4190 err = bus_register(&cciss_bus_type);
4191 if (err)
4192 return err;
4193
4011 /* Register for our PCI devices */ 4194 /* Register for our PCI devices */
4012 return pci_register_driver(&cciss_pci_driver); 4195 err = pci_register_driver(&cciss_pci_driver);
4196 if (err)
4197 goto err_bus_register;
4198
4199 return 0;
4200
4201err_bus_register:
4202 bus_unregister(&cciss_bus_type);
4203 return err;
4013} 4204}
4014 4205
4015static void __exit cciss_cleanup(void) 4206static void __exit cciss_cleanup(void)
@@ -4026,6 +4217,7 @@ static void __exit cciss_cleanup(void)
4026 } 4217 }
4027 } 4218 }
4028 remove_proc_entry("driver/cciss", NULL); 4219 remove_proc_entry("driver/cciss", NULL);
4220 bus_unregister(&cciss_bus_type);
4029} 4221}
4030 4222
4031static void fail_all_cmds(unsigned long ctlr) 4223static void fail_all_cmds(unsigned long ctlr)
diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
index 703e08038fb9..06a5db25b298 100644
--- a/drivers/block/cciss.h
+++ b/drivers/block/cciss.h
@@ -11,6 +11,11 @@
11 11
12#define IO_OK 0 12#define IO_OK 0
13#define IO_ERROR 1 13#define IO_ERROR 1
14#define IO_NEEDS_RETRY 3
15
16#define VENDOR_LEN 8
17#define MODEL_LEN 16
18#define REV_LEN 4
14 19
15struct ctlr_info; 20struct ctlr_info;
16typedef struct ctlr_info ctlr_info_t; 21typedef struct ctlr_info ctlr_info_t;
@@ -34,23 +39,20 @@ typedef struct _drive_info_struct
34 int cylinders; 39 int cylinders;
35 int raid_level; /* set to -1 to indicate that 40 int raid_level; /* set to -1 to indicate that
36 * the drive is not in use/configured 41 * the drive is not in use/configured
37 */ 42 */
38 int busy_configuring; /*This is set when the drive is being removed 43 int busy_configuring; /* This is set when a drive is being removed
39 *to prevent it from being opened or it's queue 44 * to prevent it from being opened or it's
40 *from being started. 45 * queue from being started.
41 */ 46 */
42 __u8 serial_no[16]; /* from inquiry page 0x83, */ 47 struct device dev;
43 /* not necc. null terminated. */ 48 __u8 serial_no[16]; /* from inquiry page 0x83,
49 * not necc. null terminated.
50 */
51 char vendor[VENDOR_LEN + 1]; /* SCSI vendor string */
52 char model[MODEL_LEN + 1]; /* SCSI model string */
53 char rev[REV_LEN + 1]; /* SCSI revision string */
44} drive_info_struct; 54} drive_info_struct;
45 55
46#ifdef CONFIG_CISS_SCSI_TAPE
47
48struct sendcmd_reject_list {
49 int ncompletions;
50 unsigned long *complete; /* array of NR_CMDS tags */
51};
52
53#endif
54struct ctlr_info 56struct ctlr_info
55{ 57{
56 int ctlr; 58 int ctlr;
@@ -118,11 +120,11 @@ struct ctlr_info
118 void *scsi_ctlr; /* ptr to structure containing scsi related stuff */ 120 void *scsi_ctlr; /* ptr to structure containing scsi related stuff */
119 /* list of block side commands the scsi error handling sucked up */ 121 /* list of block side commands the scsi error handling sucked up */
120 /* and saved for later processing */ 122 /* and saved for later processing */
121 struct sendcmd_reject_list scsi_rejects;
122#endif 123#endif
123 unsigned char alive; 124 unsigned char alive;
124 struct completion *rescan_wait; 125 struct completion *rescan_wait;
125 struct task_struct *cciss_scan_thread; 126 struct task_struct *cciss_scan_thread;
127 struct device dev;
126}; 128};
127 129
128/* Defining the diffent access_menthods */ 130/* Defining the diffent access_menthods */
diff --git a/drivers/block/cciss_cmd.h b/drivers/block/cciss_cmd.h
index 40b1b92dae7f..cd665b00c7c5 100644
--- a/drivers/block/cciss_cmd.h
+++ b/drivers/block/cciss_cmd.h
@@ -217,6 +217,8 @@ typedef union _LUNAddr_struct {
217 LogDevAddr_struct LogDev; 217 LogDevAddr_struct LogDev;
218} LUNAddr_struct; 218} LUNAddr_struct;
219 219
220#define CTLR_LUNID "\0\0\0\0\0\0\0\0"
221
220typedef struct _CommandListHeader_struct { 222typedef struct _CommandListHeader_struct {
221 BYTE ReplyQueue; 223 BYTE ReplyQueue;
222 BYTE SGList; 224 BYTE SGList;
diff --git a/drivers/block/cciss_scsi.c b/drivers/block/cciss_scsi.c
index a3fd87b41444..3315268b4ec7 100644
--- a/drivers/block/cciss_scsi.c
+++ b/drivers/block/cciss_scsi.c
@@ -44,20 +44,13 @@
44#define CCISS_ABORT_MSG 0x00 44#define CCISS_ABORT_MSG 0x00
45#define CCISS_RESET_MSG 0x01 45#define CCISS_RESET_MSG 0x01
46 46
47/* some prototypes... */ 47static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff,
48static int sendcmd( 48 size_t size,
49 __u8 cmd, 49 __u8 page_code, unsigned char *scsi3addr,
50 int ctlr,
51 void *buff,
52 size_t size,
53 unsigned int use_unit_num, /* 0: address the controller,
54 1: address logical volume log_unit,
55 2: address is in scsi3addr */
56 unsigned int log_unit,
57 __u8 page_code,
58 unsigned char *scsi3addr,
59 int cmd_type); 50 int cmd_type);
60 51
52static CommandList_struct *cmd_alloc(ctlr_info_t *h, int get_from_pool);
53static void cmd_free(ctlr_info_t *h, CommandList_struct *c, int got_from_pool);
61 54
62static int cciss_scsi_proc_info( 55static int cciss_scsi_proc_info(
63 struct Scsi_Host *sh, 56 struct Scsi_Host *sh,
@@ -1575,6 +1568,75 @@ cciss_seq_tape_report(struct seq_file *seq, int ctlr)
1575 CPQ_TAPE_UNLOCK(ctlr, flags); 1568 CPQ_TAPE_UNLOCK(ctlr, flags);
1576} 1569}
1577 1570
1571static int wait_for_device_to_become_ready(ctlr_info_t *h,
1572 unsigned char lunaddr[])
1573{
1574 int rc;
1575 int count = 0;
1576 int waittime = HZ;
1577 CommandList_struct *c;
1578
1579 c = cmd_alloc(h, 1);
1580 if (!c) {
1581 printk(KERN_WARNING "cciss%d: out of memory in "
1582 "wait_for_device_to_become_ready.\n", h->ctlr);
1583 return IO_ERROR;
1584 }
1585
1586 /* Send test unit ready until device ready, or give up. */
1587 while (count < 20) {
1588
1589 /* Wait for a bit. do this first, because if we send
1590 * the TUR right away, the reset will just abort it.
1591 */
1592 schedule_timeout_uninterruptible(waittime);
1593 count++;
1594
1595 /* Increase wait time with each try, up to a point. */
1596 if (waittime < (HZ * 30))
1597 waittime = waittime * 2;
1598
1599 /* Send the Test Unit Ready */
1600 rc = fill_cmd(c, TEST_UNIT_READY, h->ctlr, NULL, 0, 0,
1601 lunaddr, TYPE_CMD);
1602 if (rc == 0)
1603 rc = sendcmd_withirq_core(h, c, 0);
1604
1605 (void) process_sendcmd_error(h, c);
1606
1607 if (rc != 0)
1608 goto retry_tur;
1609
1610 if (c->err_info->CommandStatus == CMD_SUCCESS)
1611 break;
1612
1613 if (c->err_info->CommandStatus == CMD_TARGET_STATUS &&
1614 c->err_info->ScsiStatus == SAM_STAT_CHECK_CONDITION) {
1615 if (c->err_info->SenseInfo[2] == NO_SENSE)
1616 break;
1617 if (c->err_info->SenseInfo[2] == UNIT_ATTENTION) {
1618 unsigned char asc;
1619 asc = c->err_info->SenseInfo[12];
1620 check_for_unit_attention(h, c);
1621 if (asc == POWER_OR_RESET)
1622 break;
1623 }
1624 }
1625retry_tur:
1626 printk(KERN_WARNING "cciss%d: Waiting %d secs "
1627 "for device to become ready.\n",
1628 h->ctlr, waittime / HZ);
1629 rc = 1; /* device not ready. */
1630 }
1631
1632 if (rc)
1633 printk("cciss%d: giving up on device.\n", h->ctlr);
1634 else
1635 printk(KERN_WARNING "cciss%d: device is ready.\n", h->ctlr);
1636
1637 cmd_free(h, c, 1);
1638 return rc;
1639}
1578 1640
1579/* Need at least one of these error handlers to keep ../scsi/hosts.c from 1641/* Need at least one of these error handlers to keep ../scsi/hosts.c from
1580 * complaining. Doing a host- or bus-reset can't do anything good here. 1642 * complaining. Doing a host- or bus-reset can't do anything good here.
@@ -1591,6 +1653,7 @@ static int cciss_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
1591{ 1653{
1592 int rc; 1654 int rc;
1593 CommandList_struct *cmd_in_trouble; 1655 CommandList_struct *cmd_in_trouble;
1656 unsigned char lunaddr[8];
1594 ctlr_info_t **c; 1657 ctlr_info_t **c;
1595 int ctlr; 1658 int ctlr;
1596 1659
@@ -1600,19 +1663,15 @@ static int cciss_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
1600 return FAILED; 1663 return FAILED;
1601 ctlr = (*c)->ctlr; 1664 ctlr = (*c)->ctlr;
1602 printk(KERN_WARNING "cciss%d: resetting tape drive or medium changer.\n", ctlr); 1665 printk(KERN_WARNING "cciss%d: resetting tape drive or medium changer.\n", ctlr);
1603
1604 /* find the command that's giving us trouble */ 1666 /* find the command that's giving us trouble */
1605 cmd_in_trouble = (CommandList_struct *) scsicmd->host_scribble; 1667 cmd_in_trouble = (CommandList_struct *) scsicmd->host_scribble;
1606 if (cmd_in_trouble == NULL) { /* paranoia */ 1668 if (cmd_in_trouble == NULL) /* paranoia */
1607 return FAILED; 1669 return FAILED;
1608 } 1670 memcpy(lunaddr, &cmd_in_trouble->Header.LUN.LunAddrBytes[0], 8);
1609 /* send a reset to the SCSI LUN which the command was sent to */ 1671 /* send a reset to the SCSI LUN which the command was sent to */
1610 rc = sendcmd(CCISS_RESET_MSG, ctlr, NULL, 0, 2, 0, 0, 1672 rc = sendcmd_withirq(CCISS_RESET_MSG, ctlr, NULL, 0, 0, lunaddr,
1611 (unsigned char *) &cmd_in_trouble->Header.LUN.LunAddrBytes[0],
1612 TYPE_MSG); 1673 TYPE_MSG);
1613 /* sendcmd turned off interrupts on the board, turn 'em back on. */ 1674 if (rc == 0 && wait_for_device_to_become_ready(*c, lunaddr) == 0)
1614 (*c)->access.set_intr_mask(*c, CCISS_INTR_ON);
1615 if (rc == 0)
1616 return SUCCESS; 1675 return SUCCESS;
1617 printk(KERN_WARNING "cciss%d: resetting device failed.\n", ctlr); 1676 printk(KERN_WARNING "cciss%d: resetting device failed.\n", ctlr);
1618 return FAILED; 1677 return FAILED;
@@ -1622,6 +1681,7 @@ static int cciss_eh_abort_handler(struct scsi_cmnd *scsicmd)
1622{ 1681{
1623 int rc; 1682 int rc;
1624 CommandList_struct *cmd_to_abort; 1683 CommandList_struct *cmd_to_abort;
1684 unsigned char lunaddr[8];
1625 ctlr_info_t **c; 1685 ctlr_info_t **c;
1626 int ctlr; 1686 int ctlr;
1627 1687
@@ -1636,12 +1696,9 @@ static int cciss_eh_abort_handler(struct scsi_cmnd *scsicmd)
1636 cmd_to_abort = (CommandList_struct *) scsicmd->host_scribble; 1696 cmd_to_abort = (CommandList_struct *) scsicmd->host_scribble;
1637 if (cmd_to_abort == NULL) /* paranoia */ 1697 if (cmd_to_abort == NULL) /* paranoia */
1638 return FAILED; 1698 return FAILED;
1639 rc = sendcmd(CCISS_ABORT_MSG, ctlr, &cmd_to_abort->Header.Tag, 1699 memcpy(lunaddr, &cmd_to_abort->Header.LUN.LunAddrBytes[0], 8);
1640 0, 2, 0, 0, 1700 rc = sendcmd_withirq(CCISS_ABORT_MSG, ctlr, &cmd_to_abort->Header.Tag,
1641 (unsigned char *) &cmd_to_abort->Header.LUN.LunAddrBytes[0], 1701 0, 0, lunaddr, TYPE_MSG);
1642 TYPE_MSG);
1643 /* sendcmd turned off interrupts on the board, turn 'em back on. */
1644 (*c)->access.set_intr_mask(*c, CCISS_INTR_ON);
1645 if (rc == 0) 1702 if (rc == 0)
1646 return SUCCESS; 1703 return SUCCESS;
1647 return FAILED; 1704 return FAILED;
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index ca268ca11159..44fa2018f6b0 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -474,7 +474,7 @@ static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev)
474 disk->fops = &ida_fops; 474 disk->fops = &ida_fops;
475 if (j && !drv->nr_blks) 475 if (j && !drv->nr_blks)
476 continue; 476 continue;
477 blk_queue_hardsect_size(hba[i]->queue, drv->blk_size); 477 blk_queue_logical_block_size(hba[i]->queue, drv->blk_size);
478 set_capacity(disk, drv->nr_blks); 478 set_capacity(disk, drv->nr_blks);
479 disk->queue = hba[i]->queue; 479 disk->queue = hba[i]->queue;
480 disk->private_data = drv; 480 disk->private_data = drv;
@@ -903,7 +903,7 @@ static void do_ida_request(struct request_queue *q)
903 goto startio; 903 goto startio;
904 904
905queue_next: 905queue_next:
906 creq = elv_next_request(q); 906 creq = blk_peek_request(q);
907 if (!creq) 907 if (!creq)
908 goto startio; 908 goto startio;
909 909
@@ -912,17 +912,18 @@ queue_next:
912 if ((c = cmd_alloc(h,1)) == NULL) 912 if ((c = cmd_alloc(h,1)) == NULL)
913 goto startio; 913 goto startio;
914 914
915 blkdev_dequeue_request(creq); 915 blk_start_request(creq);
916 916
917 c->ctlr = h->ctlr; 917 c->ctlr = h->ctlr;
918 c->hdr.unit = (drv_info_t *)(creq->rq_disk->private_data) - h->drv; 918 c->hdr.unit = (drv_info_t *)(creq->rq_disk->private_data) - h->drv;
919 c->hdr.size = sizeof(rblk_t) >> 2; 919 c->hdr.size = sizeof(rblk_t) >> 2;
920 c->size += sizeof(rblk_t); 920 c->size += sizeof(rblk_t);
921 921
922 c->req.hdr.blk = creq->sector; 922 c->req.hdr.blk = blk_rq_pos(creq);
923 c->rq = creq; 923 c->rq = creq;
924DBGPX( 924DBGPX(
925 printk("sector=%d, nr_sectors=%d\n", creq->sector, creq->nr_sectors); 925 printk("sector=%d, nr_sectors=%u\n",
926 blk_rq_pos(creq), blk_rq_sectors(creq));
926); 927);
927 sg_init_table(tmp_sg, SG_MAX); 928 sg_init_table(tmp_sg, SG_MAX);
928 seg = blk_rq_map_sg(q, creq, tmp_sg); 929 seg = blk_rq_map_sg(q, creq, tmp_sg);
@@ -940,9 +941,9 @@ DBGPX(
940 tmp_sg[i].offset, 941 tmp_sg[i].offset,
941 tmp_sg[i].length, dir); 942 tmp_sg[i].length, dir);
942 } 943 }
943DBGPX( printk("Submitting %d sectors in %d segments\n", creq->nr_sectors, seg); ); 944DBGPX( printk("Submitting %u sectors in %d segments\n", blk_rq_sectors(creq), seg); );
944 c->req.hdr.sg_cnt = seg; 945 c->req.hdr.sg_cnt = seg;
945 c->req.hdr.blk_cnt = creq->nr_sectors; 946 c->req.hdr.blk_cnt = blk_rq_sectors(creq);
946 c->req.hdr.cmd = (rq_data_dir(creq) == READ) ? IDA_READ : IDA_WRITE; 947 c->req.hdr.cmd = (rq_data_dir(creq) == READ) ? IDA_READ : IDA_WRITE;
947 c->type = CMD_RWREQ; 948 c->type = CMD_RWREQ;
948 949
@@ -1024,8 +1025,7 @@ static inline void complete_command(cmdlist_t *cmd, int timeout)
1024 cmd->req.sg[i].size, ddir); 1025 cmd->req.sg[i].size, ddir);
1025 1026
1026 DBGPX(printk("Done with %p\n", rq);); 1027 DBGPX(printk("Done with %p\n", rq););
1027 if (__blk_end_request(rq, error, blk_rq_bytes(rq))) 1028 __blk_end_request_all(rq, error);
1028 BUG();
1029} 1029}
1030 1030
1031/* 1031/*
@@ -1546,7 +1546,7 @@ static int revalidate_allvol(ctlr_info_t *host)
1546 drv_info_t *drv = &host->drv[i]; 1546 drv_info_t *drv = &host->drv[i];
1547 if (i && !drv->nr_blks) 1547 if (i && !drv->nr_blks)
1548 continue; 1548 continue;
1549 blk_queue_hardsect_size(host->queue, drv->blk_size); 1549 blk_queue_logical_block_size(host->queue, drv->blk_size);
1550 set_capacity(disk, drv->nr_blks); 1550 set_capacity(disk, drv->nr_blks);
1551 disk->queue = host->queue; 1551 disk->queue = host->queue;
1552 disk->private_data = drv; 1552 disk->private_data = drv;
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 1300df6f1642..862b40c90181 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -931,7 +931,7 @@ static inline void unlock_fdc(void)
931 del_timer(&fd_timeout); 931 del_timer(&fd_timeout);
932 cont = NULL; 932 cont = NULL;
933 clear_bit(0, &fdc_busy); 933 clear_bit(0, &fdc_busy);
934 if (elv_next_request(floppy_queue)) 934 if (current_req || blk_peek_request(floppy_queue))
935 do_fd_request(floppy_queue); 935 do_fd_request(floppy_queue);
936 spin_unlock_irqrestore(&floppy_lock, flags); 936 spin_unlock_irqrestore(&floppy_lock, flags);
937 wake_up(&fdc_wait); 937 wake_up(&fdc_wait);
@@ -2303,7 +2303,7 @@ static void floppy_end_request(struct request *req, int error)
2303 2303
2304 /* current_count_sectors can be zero if transfer failed */ 2304 /* current_count_sectors can be zero if transfer failed */
2305 if (error) 2305 if (error)
2306 nr_sectors = req->current_nr_sectors; 2306 nr_sectors = blk_rq_cur_sectors(req);
2307 if (__blk_end_request(req, error, nr_sectors << 9)) 2307 if (__blk_end_request(req, error, nr_sectors << 9))
2308 return; 2308 return;
2309 2309
@@ -2332,7 +2332,7 @@ static void request_done(int uptodate)
2332 if (uptodate) { 2332 if (uptodate) {
2333 /* maintain values for invalidation on geometry 2333 /* maintain values for invalidation on geometry
2334 * change */ 2334 * change */
2335 block = current_count_sectors + req->sector; 2335 block = current_count_sectors + blk_rq_pos(req);
2336 INFBOUND(DRS->maxblock, block); 2336 INFBOUND(DRS->maxblock, block);
2337 if (block > _floppy->sect) 2337 if (block > _floppy->sect)
2338 DRS->maxtrack = 1; 2338 DRS->maxtrack = 1;
@@ -2346,10 +2346,10 @@ static void request_done(int uptodate)
2346 /* record write error information */ 2346 /* record write error information */
2347 DRWE->write_errors++; 2347 DRWE->write_errors++;
2348 if (DRWE->write_errors == 1) { 2348 if (DRWE->write_errors == 1) {
2349 DRWE->first_error_sector = req->sector; 2349 DRWE->first_error_sector = blk_rq_pos(req);
2350 DRWE->first_error_generation = DRS->generation; 2350 DRWE->first_error_generation = DRS->generation;
2351 } 2351 }
2352 DRWE->last_error_sector = req->sector; 2352 DRWE->last_error_sector = blk_rq_pos(req);
2353 DRWE->last_error_generation = DRS->generation; 2353 DRWE->last_error_generation = DRS->generation;
2354 } 2354 }
2355 spin_lock_irqsave(q->queue_lock, flags); 2355 spin_lock_irqsave(q->queue_lock, flags);
@@ -2503,24 +2503,23 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
2503 2503
2504 max_sector = transfer_size(ssize, 2504 max_sector = transfer_size(ssize,
2505 min(max_sector, max_sector_2), 2505 min(max_sector, max_sector_2),
2506 current_req->nr_sectors); 2506 blk_rq_sectors(current_req));
2507 2507
2508 if (current_count_sectors <= 0 && CT(COMMAND) == FD_WRITE && 2508 if (current_count_sectors <= 0 && CT(COMMAND) == FD_WRITE &&
2509 buffer_max > fsector_t + current_req->nr_sectors) 2509 buffer_max > fsector_t + blk_rq_sectors(current_req))
2510 current_count_sectors = min_t(int, buffer_max - fsector_t, 2510 current_count_sectors = min_t(int, buffer_max - fsector_t,
2511 current_req->nr_sectors); 2511 blk_rq_sectors(current_req));
2512 2512
2513 remaining = current_count_sectors << 9; 2513 remaining = current_count_sectors << 9;
2514#ifdef FLOPPY_SANITY_CHECK 2514#ifdef FLOPPY_SANITY_CHECK
2515 if ((remaining >> 9) > current_req->nr_sectors && 2515 if (remaining > blk_rq_bytes(current_req) && CT(COMMAND) == FD_WRITE) {
2516 CT(COMMAND) == FD_WRITE) {
2517 DPRINT("in copy buffer\n"); 2516 DPRINT("in copy buffer\n");
2518 printk("current_count_sectors=%ld\n", current_count_sectors); 2517 printk("current_count_sectors=%ld\n", current_count_sectors);
2519 printk("remaining=%d\n", remaining >> 9); 2518 printk("remaining=%d\n", remaining >> 9);
2520 printk("current_req->nr_sectors=%ld\n", 2519 printk("current_req->nr_sectors=%u\n",
2521 current_req->nr_sectors); 2520 blk_rq_sectors(current_req));
2522 printk("current_req->current_nr_sectors=%u\n", 2521 printk("current_req->current_nr_sectors=%u\n",
2523 current_req->current_nr_sectors); 2522 blk_rq_cur_sectors(current_req));
2524 printk("max_sector=%d\n", max_sector); 2523 printk("max_sector=%d\n", max_sector);
2525 printk("ssize=%d\n", ssize); 2524 printk("ssize=%d\n", ssize);
2526 } 2525 }
@@ -2530,7 +2529,7 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
2530 2529
2531 dma_buffer = floppy_track_buffer + ((fsector_t - buffer_min) << 9); 2530 dma_buffer = floppy_track_buffer + ((fsector_t - buffer_min) << 9);
2532 2531
2533 size = current_req->current_nr_sectors << 9; 2532 size = blk_rq_cur_bytes(current_req);
2534 2533
2535 rq_for_each_segment(bv, current_req, iter) { 2534 rq_for_each_segment(bv, current_req, iter) {
2536 if (!remaining) 2535 if (!remaining)
@@ -2648,10 +2647,10 @@ static int make_raw_rw_request(void)
2648 2647
2649 max_sector = _floppy->sect * _floppy->head; 2648 max_sector = _floppy->sect * _floppy->head;
2650 2649
2651 TRACK = (int)current_req->sector / max_sector; 2650 TRACK = (int)blk_rq_pos(current_req) / max_sector;
2652 fsector_t = (int)current_req->sector % max_sector; 2651 fsector_t = (int)blk_rq_pos(current_req) % max_sector;
2653 if (_floppy->track && TRACK >= _floppy->track) { 2652 if (_floppy->track && TRACK >= _floppy->track) {
2654 if (current_req->current_nr_sectors & 1) { 2653 if (blk_rq_cur_sectors(current_req) & 1) {
2655 current_count_sectors = 1; 2654 current_count_sectors = 1;
2656 return 1; 2655 return 1;
2657 } else 2656 } else
@@ -2669,7 +2668,7 @@ static int make_raw_rw_request(void)
2669 if (fsector_t >= max_sector) { 2668 if (fsector_t >= max_sector) {
2670 current_count_sectors = 2669 current_count_sectors =
2671 min_t(int, _floppy->sect - fsector_t, 2670 min_t(int, _floppy->sect - fsector_t,
2672 current_req->nr_sectors); 2671 blk_rq_sectors(current_req));
2673 return 1; 2672 return 1;
2674 } 2673 }
2675 SIZECODE = 2; 2674 SIZECODE = 2;
@@ -2720,7 +2719,7 @@ static int make_raw_rw_request(void)
2720 2719
2721 in_sector_offset = (fsector_t % _floppy->sect) % ssize; 2720 in_sector_offset = (fsector_t % _floppy->sect) % ssize;
2722 aligned_sector_t = fsector_t - in_sector_offset; 2721 aligned_sector_t = fsector_t - in_sector_offset;
2723 max_size = current_req->nr_sectors; 2722 max_size = blk_rq_sectors(current_req);
2724 if ((raw_cmd->track == buffer_track) && 2723 if ((raw_cmd->track == buffer_track) &&
2725 (current_drive == buffer_drive) && 2724 (current_drive == buffer_drive) &&
2726 (fsector_t >= buffer_min) && (fsector_t < buffer_max)) { 2725 (fsector_t >= buffer_min) && (fsector_t < buffer_max)) {
@@ -2729,10 +2728,10 @@ static int make_raw_rw_request(void)
2729 copy_buffer(1, max_sector, buffer_max); 2728 copy_buffer(1, max_sector, buffer_max);
2730 return 1; 2729 return 1;
2731 } 2730 }
2732 } else if (in_sector_offset || current_req->nr_sectors < ssize) { 2731 } else if (in_sector_offset || blk_rq_sectors(current_req) < ssize) {
2733 if (CT(COMMAND) == FD_WRITE) { 2732 if (CT(COMMAND) == FD_WRITE) {
2734 if (fsector_t + current_req->nr_sectors > ssize && 2733 if (fsector_t + blk_rq_sectors(current_req) > ssize &&
2735 fsector_t + current_req->nr_sectors < ssize + ssize) 2734 fsector_t + blk_rq_sectors(current_req) < ssize + ssize)
2736 max_size = ssize + ssize; 2735 max_size = ssize + ssize;
2737 else 2736 else
2738 max_size = ssize; 2737 max_size = ssize;
@@ -2776,7 +2775,7 @@ static int make_raw_rw_request(void)
2776 (indirect * 2 > direct * 3 && 2775 (indirect * 2 > direct * 3 &&
2777 *errors < DP->max_errors.read_track && ((!probing 2776 *errors < DP->max_errors.read_track && ((!probing
2778 || (DP->read_track & (1 << DRS->probed_format)))))) { 2777 || (DP->read_track & (1 << DRS->probed_format)))))) {
2779 max_size = current_req->nr_sectors; 2778 max_size = blk_rq_sectors(current_req);
2780 } else { 2779 } else {
2781 raw_cmd->kernel_data = current_req->buffer; 2780 raw_cmd->kernel_data = current_req->buffer;
2782 raw_cmd->length = current_count_sectors << 9; 2781 raw_cmd->length = current_count_sectors << 9;
@@ -2801,7 +2800,7 @@ static int make_raw_rw_request(void)
2801 fsector_t > buffer_max || 2800 fsector_t > buffer_max ||
2802 fsector_t < buffer_min || 2801 fsector_t < buffer_min ||
2803 ((CT(COMMAND) == FD_READ || 2802 ((CT(COMMAND) == FD_READ ||
2804 (!in_sector_offset && current_req->nr_sectors >= ssize)) && 2803 (!in_sector_offset && blk_rq_sectors(current_req) >= ssize)) &&
2805 max_sector > 2 * max_buffer_sectors + buffer_min && 2804 max_sector > 2 * max_buffer_sectors + buffer_min &&
2806 max_size + fsector_t > 2 * max_buffer_sectors + buffer_min) 2805 max_size + fsector_t > 2 * max_buffer_sectors + buffer_min)
2807 /* not enough space */ 2806 /* not enough space */
@@ -2879,8 +2878,8 @@ static int make_raw_rw_request(void)
2879 printk("write\n"); 2878 printk("write\n");
2880 return 0; 2879 return 0;
2881 } 2880 }
2882 } else if (raw_cmd->length > current_req->nr_sectors << 9 || 2881 } else if (raw_cmd->length > blk_rq_bytes(current_req) ||
2883 current_count_sectors > current_req->nr_sectors) { 2882 current_count_sectors > blk_rq_sectors(current_req)) {
2884 DPRINT("buffer overrun in direct transfer\n"); 2883 DPRINT("buffer overrun in direct transfer\n");
2885 return 0; 2884 return 0;
2886 } else if (raw_cmd->length < current_count_sectors << 9) { 2885 } else if (raw_cmd->length < current_count_sectors << 9) {
@@ -2913,7 +2912,7 @@ static void redo_fd_request(void)
2913 struct request *req; 2912 struct request *req;
2914 2913
2915 spin_lock_irq(floppy_queue->queue_lock); 2914 spin_lock_irq(floppy_queue->queue_lock);
2916 req = elv_next_request(floppy_queue); 2915 req = blk_fetch_request(floppy_queue);
2917 spin_unlock_irq(floppy_queue->queue_lock); 2916 spin_unlock_irq(floppy_queue->queue_lock);
2918 if (!req) { 2917 if (!req) {
2919 do_floppy = NULL; 2918 do_floppy = NULL;
@@ -2990,8 +2989,9 @@ static void do_fd_request(struct request_queue * q)
2990 if (usage_count == 0) { 2989 if (usage_count == 0) {
2991 printk("warning: usage count=0, current_req=%p exiting\n", 2990 printk("warning: usage count=0, current_req=%p exiting\n",
2992 current_req); 2991 current_req);
2993 printk("sect=%ld type=%x flags=%x\n", (long)current_req->sector, 2992 printk("sect=%ld type=%x flags=%x\n",
2994 current_req->cmd_type, current_req->cmd_flags); 2993 (long)blk_rq_pos(current_req), current_req->cmd_type,
2994 current_req->cmd_flags);
2995 return; 2995 return;
2996 } 2996 }
2997 if (test_bit(0, &fdc_busy)) { 2997 if (test_bit(0, &fdc_busy)) {
@@ -4148,6 +4148,24 @@ static void floppy_device_release(struct device *dev)
4148{ 4148{
4149} 4149}
4150 4150
4151static int floppy_resume(struct platform_device *dev)
4152{
4153 int fdc;
4154
4155 for (fdc = 0; fdc < N_FDC; fdc++)
4156 if (FDCS->address != -1)
4157 user_reset_fdc(-1, FD_RESET_ALWAYS, 0);
4158
4159 return 0;
4160}
4161
4162static struct platform_driver floppy_driver = {
4163 .resume = floppy_resume,
4164 .driver = {
4165 .name = "floppy",
4166 },
4167};
4168
4151static struct platform_device floppy_device[N_DRIVE]; 4169static struct platform_device floppy_device[N_DRIVE];
4152 4170
4153static struct kobject *floppy_find(dev_t dev, int *part, void *data) 4171static struct kobject *floppy_find(dev_t dev, int *part, void *data)
@@ -4196,10 +4214,14 @@ static int __init floppy_init(void)
4196 if (err) 4214 if (err)
4197 goto out_put_disk; 4215 goto out_put_disk;
4198 4216
4217 err = platform_driver_register(&floppy_driver);
4218 if (err)
4219 goto out_unreg_blkdev;
4220
4199 floppy_queue = blk_init_queue(do_fd_request, &floppy_lock); 4221 floppy_queue = blk_init_queue(do_fd_request, &floppy_lock);
4200 if (!floppy_queue) { 4222 if (!floppy_queue) {
4201 err = -ENOMEM; 4223 err = -ENOMEM;
4202 goto out_unreg_blkdev; 4224 goto out_unreg_driver;
4203 } 4225 }
4204 blk_queue_max_sectors(floppy_queue, 64); 4226 blk_queue_max_sectors(floppy_queue, 64);
4205 4227
@@ -4346,6 +4368,8 @@ out_flush_work:
4346out_unreg_region: 4368out_unreg_region:
4347 blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256); 4369 blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256);
4348 blk_cleanup_queue(floppy_queue); 4370 blk_cleanup_queue(floppy_queue);
4371out_unreg_driver:
4372 platform_driver_unregister(&floppy_driver);
4349out_unreg_blkdev: 4373out_unreg_blkdev:
4350 unregister_blkdev(FLOPPY_MAJOR, "fd"); 4374 unregister_blkdev(FLOPPY_MAJOR, "fd");
4351out_put_disk: 4375out_put_disk:
@@ -4566,6 +4590,7 @@ static void __exit floppy_module_exit(void)
4566 4590
4567 blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256); 4591 blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256);
4568 unregister_blkdev(FLOPPY_MAJOR, "fd"); 4592 unregister_blkdev(FLOPPY_MAJOR, "fd");
4593 platform_driver_unregister(&floppy_driver);
4569 4594
4570 for (drive = 0; drive < N_DRIVE; drive++) { 4595 for (drive = 0; drive < N_DRIVE; drive++) {
4571 del_timer_sync(&motor_off_timer[drive]); 4596 del_timer_sync(&motor_off_timer[drive]);
diff --git a/drivers/block/hd.c b/drivers/block/hd.c
index baaa9e486e50..f9d01608cbe2 100644
--- a/drivers/block/hd.c
+++ b/drivers/block/hd.c
@@ -98,10 +98,7 @@
98 98
99static DEFINE_SPINLOCK(hd_lock); 99static DEFINE_SPINLOCK(hd_lock);
100static struct request_queue *hd_queue; 100static struct request_queue *hd_queue;
101 101static struct request *hd_req;
102#define MAJOR_NR HD_MAJOR
103#define QUEUE (hd_queue)
104#define CURRENT elv_next_request(hd_queue)
105 102
106#define TIMEOUT_VALUE (6*HZ) 103#define TIMEOUT_VALUE (6*HZ)
107#define HD_DELAY 0 104#define HD_DELAY 0
@@ -195,11 +192,24 @@ static void __init hd_setup(char *str, int *ints)
195 NR_HD = hdind+1; 192 NR_HD = hdind+1;
196} 193}
197 194
195static bool hd_end_request(int err, unsigned int bytes)
196{
197 if (__blk_end_request(hd_req, err, bytes))
198 return true;
199 hd_req = NULL;
200 return false;
201}
202
203static bool hd_end_request_cur(int err)
204{
205 return hd_end_request(err, blk_rq_cur_bytes(hd_req));
206}
207
198static void dump_status(const char *msg, unsigned int stat) 208static void dump_status(const char *msg, unsigned int stat)
199{ 209{
200 char *name = "hd?"; 210 char *name = "hd?";
201 if (CURRENT) 211 if (hd_req)
202 name = CURRENT->rq_disk->disk_name; 212 name = hd_req->rq_disk->disk_name;
203 213
204#ifdef VERBOSE_ERRORS 214#ifdef VERBOSE_ERRORS
205 printk("%s: %s: status=0x%02x { ", name, msg, stat & 0xff); 215 printk("%s: %s: status=0x%02x { ", name, msg, stat & 0xff);
@@ -227,8 +237,8 @@ static void dump_status(const char *msg, unsigned int stat)
227 if (hd_error & (BBD_ERR|ECC_ERR|ID_ERR|MARK_ERR)) { 237 if (hd_error & (BBD_ERR|ECC_ERR|ID_ERR|MARK_ERR)) {
228 printk(", CHS=%d/%d/%d", (inb(HD_HCYL)<<8) + inb(HD_LCYL), 238 printk(", CHS=%d/%d/%d", (inb(HD_HCYL)<<8) + inb(HD_LCYL),
229 inb(HD_CURRENT) & 0xf, inb(HD_SECTOR)); 239 inb(HD_CURRENT) & 0xf, inb(HD_SECTOR));
230 if (CURRENT) 240 if (hd_req)
231 printk(", sector=%ld", CURRENT->sector); 241 printk(", sector=%ld", blk_rq_pos(hd_req));
232 } 242 }
233 printk("\n"); 243 printk("\n");
234 } 244 }
@@ -406,11 +416,12 @@ static void unexpected_hd_interrupt(void)
406 */ 416 */
407static void bad_rw_intr(void) 417static void bad_rw_intr(void)
408{ 418{
409 struct request *req = CURRENT; 419 struct request *req = hd_req;
420
410 if (req != NULL) { 421 if (req != NULL) {
411 struct hd_i_struct *disk = req->rq_disk->private_data; 422 struct hd_i_struct *disk = req->rq_disk->private_data;
412 if (++req->errors >= MAX_ERRORS || (hd_error & BBD_ERR)) { 423 if (++req->errors >= MAX_ERRORS || (hd_error & BBD_ERR)) {
413 end_request(req, 0); 424 hd_end_request_cur(-EIO);
414 disk->special_op = disk->recalibrate = 1; 425 disk->special_op = disk->recalibrate = 1;
415 } else if (req->errors % RESET_FREQ == 0) 426 } else if (req->errors % RESET_FREQ == 0)
416 reset = 1; 427 reset = 1;
@@ -452,37 +463,30 @@ static void read_intr(void)
452 bad_rw_intr(); 463 bad_rw_intr();
453 hd_request(); 464 hd_request();
454 return; 465 return;
466
455ok_to_read: 467ok_to_read:
456 req = CURRENT; 468 req = hd_req;
457 insw(HD_DATA, req->buffer, 256); 469 insw(HD_DATA, req->buffer, 256);
458 req->sector++;
459 req->buffer += 512;
460 req->errors = 0;
461 i = --req->nr_sectors;
462 --req->current_nr_sectors;
463#ifdef DEBUG 470#ifdef DEBUG
464 printk("%s: read: sector %ld, remaining = %ld, buffer=%p\n", 471 printk("%s: read: sector %ld, remaining = %u, buffer=%p\n",
465 req->rq_disk->disk_name, req->sector, req->nr_sectors, 472 req->rq_disk->disk_name, blk_rq_pos(req) + 1,
466 req->buffer+512); 473 blk_rq_sectors(req) - 1, req->buffer+512);
467#endif 474#endif
468 if (req->current_nr_sectors <= 0) 475 if (hd_end_request(0, 512)) {
469 end_request(req, 1);
470 if (i > 0) {
471 SET_HANDLER(&read_intr); 476 SET_HANDLER(&read_intr);
472 return; 477 return;
473 } 478 }
479
474 (void) inb_p(HD_STATUS); 480 (void) inb_p(HD_STATUS);
475#if (HD_DELAY > 0) 481#if (HD_DELAY > 0)
476 last_req = read_timer(); 482 last_req = read_timer();
477#endif 483#endif
478 if (elv_next_request(QUEUE)) 484 hd_request();
479 hd_request();
480 return;
481} 485}
482 486
483static void write_intr(void) 487static void write_intr(void)
484{ 488{
485 struct request *req = CURRENT; 489 struct request *req = hd_req;
486 int i; 490 int i;
487 int retries = 100000; 491 int retries = 100000;
488 492
@@ -492,30 +496,25 @@ static void write_intr(void)
492 continue; 496 continue;
493 if (!OK_STATUS(i)) 497 if (!OK_STATUS(i))
494 break; 498 break;
495 if ((req->nr_sectors <= 1) || (i & DRQ_STAT)) 499 if ((blk_rq_sectors(req) <= 1) || (i & DRQ_STAT))
496 goto ok_to_write; 500 goto ok_to_write;
497 } while (--retries > 0); 501 } while (--retries > 0);
498 dump_status("write_intr", i); 502 dump_status("write_intr", i);
499 bad_rw_intr(); 503 bad_rw_intr();
500 hd_request(); 504 hd_request();
501 return; 505 return;
506
502ok_to_write: 507ok_to_write:
503 req->sector++; 508 if (hd_end_request(0, 512)) {
504 i = --req->nr_sectors;
505 --req->current_nr_sectors;
506 req->buffer += 512;
507 if (!i || (req->bio && req->current_nr_sectors <= 0))
508 end_request(req, 1);
509 if (i > 0) {
510 SET_HANDLER(&write_intr); 509 SET_HANDLER(&write_intr);
511 outsw(HD_DATA, req->buffer, 256); 510 outsw(HD_DATA, req->buffer, 256);
512 } else { 511 return;
512 }
513
513#if (HD_DELAY > 0) 514#if (HD_DELAY > 0)
514 last_req = read_timer(); 515 last_req = read_timer();
515#endif 516#endif
516 hd_request(); 517 hd_request();
517 }
518 return;
519} 518}
520 519
521static void recal_intr(void) 520static void recal_intr(void)
@@ -537,18 +536,18 @@ static void hd_times_out(unsigned long dummy)
537 536
538 do_hd = NULL; 537 do_hd = NULL;
539 538
540 if (!CURRENT) 539 if (!hd_req)
541 return; 540 return;
542 541
543 spin_lock_irq(hd_queue->queue_lock); 542 spin_lock_irq(hd_queue->queue_lock);
544 reset = 1; 543 reset = 1;
545 name = CURRENT->rq_disk->disk_name; 544 name = hd_req->rq_disk->disk_name;
546 printk("%s: timeout\n", name); 545 printk("%s: timeout\n", name);
547 if (++CURRENT->errors >= MAX_ERRORS) { 546 if (++hd_req->errors >= MAX_ERRORS) {
548#ifdef DEBUG 547#ifdef DEBUG
549 printk("%s: too many errors\n", name); 548 printk("%s: too many errors\n", name);
550#endif 549#endif
551 end_request(CURRENT, 0); 550 hd_end_request_cur(-EIO);
552 } 551 }
553 hd_request(); 552 hd_request();
554 spin_unlock_irq(hd_queue->queue_lock); 553 spin_unlock_irq(hd_queue->queue_lock);
@@ -563,7 +562,7 @@ static int do_special_op(struct hd_i_struct *disk, struct request *req)
563 } 562 }
564 if (disk->head > 16) { 563 if (disk->head > 16) {
565 printk("%s: cannot handle device with more than 16 heads - giving up\n", req->rq_disk->disk_name); 564 printk("%s: cannot handle device with more than 16 heads - giving up\n", req->rq_disk->disk_name);
566 end_request(req, 0); 565 hd_end_request_cur(-EIO);
567 } 566 }
568 disk->special_op = 0; 567 disk->special_op = 0;
569 return 1; 568 return 1;
@@ -590,24 +589,27 @@ static void hd_request(void)
590repeat: 589repeat:
591 del_timer(&device_timer); 590 del_timer(&device_timer);
592 591
593 req = CURRENT; 592 if (!hd_req) {
594 if (!req) { 593 hd_req = blk_fetch_request(hd_queue);
595 do_hd = NULL; 594 if (!hd_req) {
596 return; 595 do_hd = NULL;
596 return;
597 }
597 } 598 }
599 req = hd_req;
598 600
599 if (reset) { 601 if (reset) {
600 reset_hd(); 602 reset_hd();
601 return; 603 return;
602 } 604 }
603 disk = req->rq_disk->private_data; 605 disk = req->rq_disk->private_data;
604 block = req->sector; 606 block = blk_rq_pos(req);
605 nsect = req->nr_sectors; 607 nsect = blk_rq_sectors(req);
606 if (block >= get_capacity(req->rq_disk) || 608 if (block >= get_capacity(req->rq_disk) ||
607 ((block+nsect) > get_capacity(req->rq_disk))) { 609 ((block+nsect) > get_capacity(req->rq_disk))) {
608 printk("%s: bad access: block=%d, count=%d\n", 610 printk("%s: bad access: block=%d, count=%d\n",
609 req->rq_disk->disk_name, block, nsect); 611 req->rq_disk->disk_name, block, nsect);
610 end_request(req, 0); 612 hd_end_request_cur(-EIO);
611 goto repeat; 613 goto repeat;
612 } 614 }
613 615
@@ -647,7 +649,7 @@ repeat:
647 break; 649 break;
648 default: 650 default:
649 printk("unknown hd-command\n"); 651 printk("unknown hd-command\n");
650 end_request(req, 0); 652 hd_end_request_cur(-EIO);
651 break; 653 break;
652 } 654 }
653 } 655 }
@@ -708,19 +710,19 @@ static int __init hd_init(void)
708{ 710{
709 int drive; 711 int drive;
710 712
711 if (register_blkdev(MAJOR_NR, "hd")) 713 if (register_blkdev(HD_MAJOR, "hd"))
712 return -1; 714 return -1;
713 715
714 hd_queue = blk_init_queue(do_hd_request, &hd_lock); 716 hd_queue = blk_init_queue(do_hd_request, &hd_lock);
715 if (!hd_queue) { 717 if (!hd_queue) {
716 unregister_blkdev(MAJOR_NR, "hd"); 718 unregister_blkdev(HD_MAJOR, "hd");
717 return -ENOMEM; 719 return -ENOMEM;
718 } 720 }
719 721
720 blk_queue_max_sectors(hd_queue, 255); 722 blk_queue_max_sectors(hd_queue, 255);
721 init_timer(&device_timer); 723 init_timer(&device_timer);
722 device_timer.function = hd_times_out; 724 device_timer.function = hd_times_out;
723 blk_queue_hardsect_size(hd_queue, 512); 725 blk_queue_logical_block_size(hd_queue, 512);
724 726
725 if (!NR_HD) { 727 if (!NR_HD) {
726 /* 728 /*
@@ -747,7 +749,7 @@ static int __init hd_init(void)
747 struct hd_i_struct *p = &hd_info[drive]; 749 struct hd_i_struct *p = &hd_info[drive];
748 if (!disk) 750 if (!disk)
749 goto Enomem; 751 goto Enomem;
750 disk->major = MAJOR_NR; 752 disk->major = HD_MAJOR;
751 disk->first_minor = drive << 6; 753 disk->first_minor = drive << 6;
752 disk->fops = &hd_fops; 754 disk->fops = &hd_fops;
753 sprintf(disk->disk_name, "hd%c", 'a'+drive); 755 sprintf(disk->disk_name, "hd%c", 'a'+drive);
@@ -791,7 +793,7 @@ out1:
791 NR_HD = 0; 793 NR_HD = 0;
792out: 794out:
793 del_timer(&device_timer); 795 del_timer(&device_timer);
794 unregister_blkdev(MAJOR_NR, "hd"); 796 unregister_blkdev(HD_MAJOR, "hd");
795 blk_cleanup_queue(hd_queue); 797 blk_cleanup_queue(hd_queue);
796 return -1; 798 return -1;
797Enomem: 799Enomem:
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index ddae80825899..801f4ab83302 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -511,11 +511,7 @@ out:
511 */ 511 */
512static void loop_add_bio(struct loop_device *lo, struct bio *bio) 512static void loop_add_bio(struct loop_device *lo, struct bio *bio)
513{ 513{
514 if (lo->lo_biotail) { 514 bio_list_add(&lo->lo_bio_list, bio);
515 lo->lo_biotail->bi_next = bio;
516 lo->lo_biotail = bio;
517 } else
518 lo->lo_bio = lo->lo_biotail = bio;
519} 515}
520 516
521/* 517/*
@@ -523,16 +519,7 @@ static void loop_add_bio(struct loop_device *lo, struct bio *bio)
523 */ 519 */
524static struct bio *loop_get_bio(struct loop_device *lo) 520static struct bio *loop_get_bio(struct loop_device *lo)
525{ 521{
526 struct bio *bio; 522 return bio_list_pop(&lo->lo_bio_list);
527
528 if ((bio = lo->lo_bio)) {
529 if (bio == lo->lo_biotail)
530 lo->lo_biotail = NULL;
531 lo->lo_bio = bio->bi_next;
532 bio->bi_next = NULL;
533 }
534
535 return bio;
536} 523}
537 524
538static int loop_make_request(struct request_queue *q, struct bio *old_bio) 525static int loop_make_request(struct request_queue *q, struct bio *old_bio)
@@ -609,12 +596,13 @@ static int loop_thread(void *data)
609 596
610 set_user_nice(current, -20); 597 set_user_nice(current, -20);
611 598
612 while (!kthread_should_stop() || lo->lo_bio) { 599 while (!kthread_should_stop() || !bio_list_empty(&lo->lo_bio_list)) {
613 600
614 wait_event_interruptible(lo->lo_event, 601 wait_event_interruptible(lo->lo_event,
615 lo->lo_bio || kthread_should_stop()); 602 !bio_list_empty(&lo->lo_bio_list) ||
603 kthread_should_stop());
616 604
617 if (!lo->lo_bio) 605 if (bio_list_empty(&lo->lo_bio_list))
618 continue; 606 continue;
619 spin_lock_irq(&lo->lo_lock); 607 spin_lock_irq(&lo->lo_lock);
620 bio = loop_get_bio(lo); 608 bio = loop_get_bio(lo);
@@ -721,10 +709,6 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
721 if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode)) 709 if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))
722 goto out_putf; 710 goto out_putf;
723 711
724 /* new backing store needs to support loop (eg splice_read) */
725 if (!inode->i_fop->splice_read)
726 goto out_putf;
727
728 /* size of the new backing store needs to be the same */ 712 /* size of the new backing store needs to be the same */
729 if (get_loop_size(lo, file) != get_loop_size(lo, old_file)) 713 if (get_loop_size(lo, file) != get_loop_size(lo, old_file))
730 goto out_putf; 714 goto out_putf;
@@ -800,12 +784,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
800 error = -EINVAL; 784 error = -EINVAL;
801 if (S_ISREG(inode->i_mode) || S_ISBLK(inode->i_mode)) { 785 if (S_ISREG(inode->i_mode) || S_ISBLK(inode->i_mode)) {
802 const struct address_space_operations *aops = mapping->a_ops; 786 const struct address_space_operations *aops = mapping->a_ops;
803 /* 787
804 * If we can't read - sorry. If we only can't write - well,
805 * it's going to be read-only.
806 */
807 if (!file->f_op->splice_read)
808 goto out_putf;
809 if (aops->write_begin) 788 if (aops->write_begin)
810 lo_flags |= LO_FLAGS_USE_AOPS; 789 lo_flags |= LO_FLAGS_USE_AOPS;
811 if (!(lo_flags & LO_FLAGS_USE_AOPS) && !file->f_op->write) 790 if (!(lo_flags & LO_FLAGS_USE_AOPS) && !file->f_op->write)
@@ -841,7 +820,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
841 lo->old_gfp_mask = mapping_gfp_mask(mapping); 820 lo->old_gfp_mask = mapping_gfp_mask(mapping);
842 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS)); 821 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
843 822
844 lo->lo_bio = lo->lo_biotail = NULL; 823 bio_list_init(&lo->lo_bio_list);
845 824
846 /* 825 /*
847 * set queue make_request_fn, and add limits based on lower level 826 * set queue make_request_fn, and add limits based on lower level
diff --git a/drivers/block/mg_disk.c b/drivers/block/mg_disk.c
index f3898353d0a8..f703f5478246 100644
--- a/drivers/block/mg_disk.c
+++ b/drivers/block/mg_disk.c
@@ -17,7 +17,7 @@
17#include <linux/fs.h> 17#include <linux/fs.h>
18#include <linux/blkdev.h> 18#include <linux/blkdev.h>
19#include <linux/hdreg.h> 19#include <linux/hdreg.h>
20#include <linux/libata.h> 20#include <linux/ata.h>
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
@@ -26,62 +26,185 @@
26 26
27#define MG_RES_SEC (CONFIG_MG_DISK_RES << 1) 27#define MG_RES_SEC (CONFIG_MG_DISK_RES << 1)
28 28
29/* name for block device */
30#define MG_DISK_NAME "mgd"
31
32#define MG_DISK_MAJ 0
33#define MG_DISK_MAX_PART 16
34#define MG_SECTOR_SIZE 512
35#define MG_MAX_SECTS 256
36
37/* Register offsets */
38#define MG_BUFF_OFFSET 0x8000
39#define MG_STORAGE_BUFFER_SIZE 0x200
40#define MG_REG_OFFSET 0xC000
41#define MG_REG_FEATURE (MG_REG_OFFSET + 2) /* write case */
42#define MG_REG_ERROR (MG_REG_OFFSET + 2) /* read case */
43#define MG_REG_SECT_CNT (MG_REG_OFFSET + 4)
44#define MG_REG_SECT_NUM (MG_REG_OFFSET + 6)
45#define MG_REG_CYL_LOW (MG_REG_OFFSET + 8)
46#define MG_REG_CYL_HIGH (MG_REG_OFFSET + 0xA)
47#define MG_REG_DRV_HEAD (MG_REG_OFFSET + 0xC)
48#define MG_REG_COMMAND (MG_REG_OFFSET + 0xE) /* write case */
49#define MG_REG_STATUS (MG_REG_OFFSET + 0xE) /* read case */
50#define MG_REG_DRV_CTRL (MG_REG_OFFSET + 0x10)
51#define MG_REG_BURST_CTRL (MG_REG_OFFSET + 0x12)
52
53/* handy status */
54#define MG_STAT_READY (ATA_DRDY | ATA_DSC)
55#define MG_READY_OK(s) (((s) & (MG_STAT_READY | (ATA_BUSY | ATA_DF | \
56 ATA_ERR))) == MG_STAT_READY)
57
58/* error code for others */
59#define MG_ERR_NONE 0
60#define MG_ERR_TIMEOUT 0x100
61#define MG_ERR_INIT_STAT 0x101
62#define MG_ERR_TRANSLATION 0x102
63#define MG_ERR_CTRL_RST 0x103
64#define MG_ERR_INV_STAT 0x104
65#define MG_ERR_RSTOUT 0x105
66
67#define MG_MAX_ERRORS 6 /* Max read/write errors */
68
69/* command */
70#define MG_CMD_RD 0x20
71#define MG_CMD_WR 0x30
72#define MG_CMD_SLEEP 0x99
73#define MG_CMD_WAKEUP 0xC3
74#define MG_CMD_ID 0xEC
75#define MG_CMD_WR_CONF 0x3C
76#define MG_CMD_RD_CONF 0x40
77
78/* operation mode */
79#define MG_OP_CASCADE (1 << 0)
80#define MG_OP_CASCADE_SYNC_RD (1 << 1)
81#define MG_OP_CASCADE_SYNC_WR (1 << 2)
82#define MG_OP_INTERLEAVE (1 << 3)
83
84/* synchronous */
85#define MG_BURST_LAT_4 (3 << 4)
86#define MG_BURST_LAT_5 (4 << 4)
87#define MG_BURST_LAT_6 (5 << 4)
88#define MG_BURST_LAT_7 (6 << 4)
89#define MG_BURST_LAT_8 (7 << 4)
90#define MG_BURST_LEN_4 (1 << 1)
91#define MG_BURST_LEN_8 (2 << 1)
92#define MG_BURST_LEN_16 (3 << 1)
93#define MG_BURST_LEN_32 (4 << 1)
94#define MG_BURST_LEN_CONT (0 << 1)
95
96/* timeout value (unit: ms) */
97#define MG_TMAX_CONF_TO_CMD 1
98#define MG_TMAX_WAIT_RD_DRQ 10
99#define MG_TMAX_WAIT_WR_DRQ 500
100#define MG_TMAX_RST_TO_BUSY 10
101#define MG_TMAX_HDRST_TO_RDY 500
102#define MG_TMAX_SWRST_TO_RDY 500
103#define MG_TMAX_RSTOUT 3000
104
105#define MG_DEV_MASK (MG_BOOT_DEV | MG_STORAGE_DEV | MG_STORAGE_DEV_SKIP_RST)
106
107/* main structure for mflash driver */
108struct mg_host {
109 struct device *dev;
110
111 struct request_queue *breq;
112 struct request *req;
113 spinlock_t lock;
114 struct gendisk *gd;
115
116 struct timer_list timer;
117 void (*mg_do_intr) (struct mg_host *);
118
119 u16 id[ATA_ID_WORDS];
120
121 u16 cyls;
122 u16 heads;
123 u16 sectors;
124 u32 n_sectors;
125 u32 nres_sectors;
126
127 void __iomem *dev_base;
128 unsigned int irq;
129 unsigned int rst;
130 unsigned int rstout;
131
132 u32 major;
133 u32 error;
134};
135
136/*
137 * Debugging macro and defines
138 */
139#undef DO_MG_DEBUG
140#ifdef DO_MG_DEBUG
141# define MG_DBG(fmt, args...) \
142 printk(KERN_DEBUG "%s:%d "fmt, __func__, __LINE__, ##args)
143#else /* CONFIG_MG_DEBUG */
144# define MG_DBG(fmt, args...) do { } while (0)
145#endif /* CONFIG_MG_DEBUG */
146
29static void mg_request(struct request_queue *); 147static void mg_request(struct request_queue *);
30 148
149static bool mg_end_request(struct mg_host *host, int err, unsigned int nr_bytes)
150{
151 if (__blk_end_request(host->req, err, nr_bytes))
152 return true;
153
154 host->req = NULL;
155 return false;
156}
157
158static bool mg_end_request_cur(struct mg_host *host, int err)
159{
160 return mg_end_request(host, err, blk_rq_cur_bytes(host->req));
161}
162
31static void mg_dump_status(const char *msg, unsigned int stat, 163static void mg_dump_status(const char *msg, unsigned int stat,
32 struct mg_host *host) 164 struct mg_host *host)
33{ 165{
34 char *name = MG_DISK_NAME; 166 char *name = MG_DISK_NAME;
35 struct request *req;
36 167
37 if (host->breq) { 168 if (host->req)
38 req = elv_next_request(host->breq); 169 name = host->req->rq_disk->disk_name;
39 if (req)
40 name = req->rq_disk->disk_name;
41 }
42 170
43 printk(KERN_ERR "%s: %s: status=0x%02x { ", name, msg, stat & 0xff); 171 printk(KERN_ERR "%s: %s: status=0x%02x { ", name, msg, stat & 0xff);
44 if (stat & MG_REG_STATUS_BIT_BUSY) 172 if (stat & ATA_BUSY)
45 printk("Busy "); 173 printk("Busy ");
46 if (stat & MG_REG_STATUS_BIT_READY) 174 if (stat & ATA_DRDY)
47 printk("DriveReady "); 175 printk("DriveReady ");
48 if (stat & MG_REG_STATUS_BIT_WRITE_FAULT) 176 if (stat & ATA_DF)
49 printk("WriteFault "); 177 printk("WriteFault ");
50 if (stat & MG_REG_STATUS_BIT_SEEK_DONE) 178 if (stat & ATA_DSC)
51 printk("SeekComplete "); 179 printk("SeekComplete ");
52 if (stat & MG_REG_STATUS_BIT_DATA_REQ) 180 if (stat & ATA_DRQ)
53 printk("DataRequest "); 181 printk("DataRequest ");
54 if (stat & MG_REG_STATUS_BIT_CORRECTED_ERROR) 182 if (stat & ATA_CORR)
55 printk("CorrectedError "); 183 printk("CorrectedError ");
56 if (stat & MG_REG_STATUS_BIT_ERROR) 184 if (stat & ATA_ERR)
57 printk("Error "); 185 printk("Error ");
58 printk("}\n"); 186 printk("}\n");
59 if ((stat & MG_REG_STATUS_BIT_ERROR) == 0) { 187 if ((stat & ATA_ERR) == 0) {
60 host->error = 0; 188 host->error = 0;
61 } else { 189 } else {
62 host->error = inb((unsigned long)host->dev_base + MG_REG_ERROR); 190 host->error = inb((unsigned long)host->dev_base + MG_REG_ERROR);
63 printk(KERN_ERR "%s: %s: error=0x%02x { ", name, msg, 191 printk(KERN_ERR "%s: %s: error=0x%02x { ", name, msg,
64 host->error & 0xff); 192 host->error & 0xff);
65 if (host->error & MG_REG_ERR_BBK) 193 if (host->error & ATA_BBK)
66 printk("BadSector "); 194 printk("BadSector ");
67 if (host->error & MG_REG_ERR_UNC) 195 if (host->error & ATA_UNC)
68 printk("UncorrectableError "); 196 printk("UncorrectableError ");
69 if (host->error & MG_REG_ERR_IDNF) 197 if (host->error & ATA_IDNF)
70 printk("SectorIdNotFound "); 198 printk("SectorIdNotFound ");
71 if (host->error & MG_REG_ERR_ABRT) 199 if (host->error & ATA_ABORTED)
72 printk("DriveStatusError "); 200 printk("DriveStatusError ");
73 if (host->error & MG_REG_ERR_AMNF) 201 if (host->error & ATA_AMNF)
74 printk("AddrMarkNotFound "); 202 printk("AddrMarkNotFound ");
75 printk("}"); 203 printk("}");
76 if (host->error & 204 if (host->error & (ATA_BBK | ATA_UNC | ATA_IDNF | ATA_AMNF)) {
77 (MG_REG_ERR_BBK | MG_REG_ERR_UNC | 205 if (host->req)
78 MG_REG_ERR_IDNF | MG_REG_ERR_AMNF)) { 206 printk(", sector=%u",
79 if (host->breq) { 207 (unsigned int)blk_rq_pos(host->req));
80 req = elv_next_request(host->breq);
81 if (req)
82 printk(", sector=%u", (u32)req->sector);
83 }
84
85 } 208 }
86 printk("\n"); 209 printk("\n");
87 } 210 }
@@ -100,12 +223,12 @@ static unsigned int mg_wait(struct mg_host *host, u32 expect, u32 msec)
100 223
101 do { 224 do {
102 cur_jiffies = jiffies; 225 cur_jiffies = jiffies;
103 if (status & MG_REG_STATUS_BIT_BUSY) { 226 if (status & ATA_BUSY) {
104 if (expect == MG_REG_STATUS_BIT_BUSY) 227 if (expect == ATA_BUSY)
105 break; 228 break;
106 } else { 229 } else {
107 /* Check the error condition! */ 230 /* Check the error condition! */
108 if (status & MG_REG_STATUS_BIT_ERROR) { 231 if (status & ATA_ERR) {
109 mg_dump_status("mg_wait", status, host); 232 mg_dump_status("mg_wait", status, host);
110 break; 233 break;
111 } 234 }
@@ -114,8 +237,8 @@ static unsigned int mg_wait(struct mg_host *host, u32 expect, u32 msec)
114 if (MG_READY_OK(status)) 237 if (MG_READY_OK(status))
115 break; 238 break;
116 239
117 if (expect == MG_REG_STATUS_BIT_DATA_REQ) 240 if (expect == ATA_DRQ)
118 if (status & MG_REG_STATUS_BIT_DATA_REQ) 241 if (status & ATA_DRQ)
119 break; 242 break;
120 } 243 }
121 if (!msec) { 244 if (!msec) {
@@ -173,6 +296,42 @@ static irqreturn_t mg_irq(int irq, void *dev_id)
173 return IRQ_HANDLED; 296 return IRQ_HANDLED;
174} 297}
175 298
299/* local copy of ata_id_string() */
300static void mg_id_string(const u16 *id, unsigned char *s,
301 unsigned int ofs, unsigned int len)
302{
303 unsigned int c;
304
305 BUG_ON(len & 1);
306
307 while (len > 0) {
308 c = id[ofs] >> 8;
309 *s = c;
310 s++;
311
312 c = id[ofs] & 0xff;
313 *s = c;
314 s++;
315
316 ofs++;
317 len -= 2;
318 }
319}
320
321/* local copy of ata_id_c_string() */
322static void mg_id_c_string(const u16 *id, unsigned char *s,
323 unsigned int ofs, unsigned int len)
324{
325 unsigned char *p;
326
327 mg_id_string(id, s, ofs, len - 1);
328
329 p = s + strnlen(s, len - 1);
330 while (p > s && p[-1] == ' ')
331 p--;
332 *p = '\0';
333}
334
176static int mg_get_disk_id(struct mg_host *host) 335static int mg_get_disk_id(struct mg_host *host)
177{ 336{
178 u32 i; 337 u32 i;
@@ -184,12 +343,10 @@ static int mg_get_disk_id(struct mg_host *host)
184 char serial[ATA_ID_SERNO_LEN + 1]; 343 char serial[ATA_ID_SERNO_LEN + 1];
185 344
186 if (!prv_data->use_polling) 345 if (!prv_data->use_polling)
187 outb(MG_REG_CTRL_INTR_DISABLE, 346 outb(ATA_NIEN, (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
188 (unsigned long)host->dev_base +
189 MG_REG_DRV_CTRL);
190 347
191 outb(MG_CMD_ID, (unsigned long)host->dev_base + MG_REG_COMMAND); 348 outb(MG_CMD_ID, (unsigned long)host->dev_base + MG_REG_COMMAND);
192 err = mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, MG_TMAX_WAIT_RD_DRQ); 349 err = mg_wait(host, ATA_DRQ, MG_TMAX_WAIT_RD_DRQ);
193 if (err) 350 if (err)
194 return err; 351 return err;
195 352
@@ -219,9 +376,9 @@ static int mg_get_disk_id(struct mg_host *host)
219 host->n_sectors -= host->nres_sectors; 376 host->n_sectors -= host->nres_sectors;
220 } 377 }
221 378
222 ata_id_c_string(id, fwrev, ATA_ID_FW_REV, sizeof(fwrev)); 379 mg_id_c_string(id, fwrev, ATA_ID_FW_REV, sizeof(fwrev));
223 ata_id_c_string(id, model, ATA_ID_PROD, sizeof(model)); 380 mg_id_c_string(id, model, ATA_ID_PROD, sizeof(model));
224 ata_id_c_string(id, serial, ATA_ID_SERNO, sizeof(serial)); 381 mg_id_c_string(id, serial, ATA_ID_SERNO, sizeof(serial));
225 printk(KERN_INFO "mg_disk: model: %s\n", model); 382 printk(KERN_INFO "mg_disk: model: %s\n", model);
226 printk(KERN_INFO "mg_disk: firm: %.8s\n", fwrev); 383 printk(KERN_INFO "mg_disk: firm: %.8s\n", fwrev);
227 printk(KERN_INFO "mg_disk: serial: %s\n", serial); 384 printk(KERN_INFO "mg_disk: serial: %s\n", serial);
@@ -229,8 +386,7 @@ static int mg_get_disk_id(struct mg_host *host)
229 host->n_sectors, host->nres_sectors); 386 host->n_sectors, host->nres_sectors);
230 387
231 if (!prv_data->use_polling) 388 if (!prv_data->use_polling)
232 outb(MG_REG_CTRL_INTR_ENABLE, (unsigned long)host->dev_base + 389 outb(0, (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
233 MG_REG_DRV_CTRL);
234 390
235 return err; 391 return err;
236} 392}
@@ -244,7 +400,7 @@ static int mg_disk_init(struct mg_host *host)
244 400
245 /* hdd rst low */ 401 /* hdd rst low */
246 gpio_set_value(host->rst, 0); 402 gpio_set_value(host->rst, 0);
247 err = mg_wait(host, MG_REG_STATUS_BIT_BUSY, MG_TMAX_RST_TO_BUSY); 403 err = mg_wait(host, ATA_BUSY, MG_TMAX_RST_TO_BUSY);
248 if (err) 404 if (err)
249 return err; 405 return err;
250 406
@@ -255,17 +411,14 @@ static int mg_disk_init(struct mg_host *host)
255 return err; 411 return err;
256 412
257 /* soft reset on */ 413 /* soft reset on */
258 outb(MG_REG_CTRL_RESET | 414 outb(ATA_SRST | (prv_data->use_polling ? ATA_NIEN : 0),
259 (prv_data->use_polling ? MG_REG_CTRL_INTR_DISABLE :
260 MG_REG_CTRL_INTR_ENABLE),
261 (unsigned long)host->dev_base + MG_REG_DRV_CTRL); 415 (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
262 err = mg_wait(host, MG_REG_STATUS_BIT_BUSY, MG_TMAX_RST_TO_BUSY); 416 err = mg_wait(host, ATA_BUSY, MG_TMAX_RST_TO_BUSY);
263 if (err) 417 if (err)
264 return err; 418 return err;
265 419
266 /* soft reset off */ 420 /* soft reset off */
267 outb(prv_data->use_polling ? MG_REG_CTRL_INTR_DISABLE : 421 outb(prv_data->use_polling ? ATA_NIEN : 0,
268 MG_REG_CTRL_INTR_ENABLE,
269 (unsigned long)host->dev_base + MG_REG_DRV_CTRL); 422 (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
270 err = mg_wait(host, MG_STAT_READY, MG_TMAX_SWRST_TO_RDY); 423 err = mg_wait(host, MG_STAT_READY, MG_TMAX_SWRST_TO_RDY);
271 if (err) 424 if (err)
@@ -281,11 +434,10 @@ static int mg_disk_init(struct mg_host *host)
281 434
282static void mg_bad_rw_intr(struct mg_host *host) 435static void mg_bad_rw_intr(struct mg_host *host)
283{ 436{
284 struct request *req = elv_next_request(host->breq); 437 if (host->req)
285 if (req != NULL) 438 if (++host->req->errors >= MG_MAX_ERRORS ||
286 if (++req->errors >= MG_MAX_ERRORS || 439 host->error == MG_ERR_TIMEOUT)
287 host->error == MG_ERR_TIMEOUT) 440 mg_end_request_cur(host, -EIO);
288 end_request(req, 0);
289} 441}
290 442
291static unsigned int mg_out(struct mg_host *host, 443static unsigned int mg_out(struct mg_host *host,
@@ -311,7 +463,7 @@ static unsigned int mg_out(struct mg_host *host,
311 MG_REG_CYL_LOW); 463 MG_REG_CYL_LOW);
312 outb((u8)(sect_num >> 16), (unsigned long)host->dev_base + 464 outb((u8)(sect_num >> 16), (unsigned long)host->dev_base +
313 MG_REG_CYL_HIGH); 465 MG_REG_CYL_HIGH);
314 outb((u8)((sect_num >> 24) | MG_REG_HEAD_LBA_MODE), 466 outb((u8)((sect_num >> 24) | ATA_LBA | ATA_DEVICE_OBS),
315 (unsigned long)host->dev_base + MG_REG_DRV_HEAD); 467 (unsigned long)host->dev_base + MG_REG_DRV_HEAD);
316 outb(cmd, (unsigned long)host->dev_base + MG_REG_COMMAND); 468 outb(cmd, (unsigned long)host->dev_base + MG_REG_COMMAND);
317 return MG_ERR_NONE; 469 return MG_ERR_NONE;
@@ -319,105 +471,77 @@ static unsigned int mg_out(struct mg_host *host,
319 471
320static void mg_read(struct request *req) 472static void mg_read(struct request *req)
321{ 473{
322 u32 remains, j; 474 u32 j;
323 struct mg_host *host = req->rq_disk->private_data; 475 struct mg_host *host = req->rq_disk->private_data;
324 476
325 remains = req->nr_sectors; 477 if (mg_out(host, blk_rq_pos(req), blk_rq_sectors(req),
326 478 MG_CMD_RD, NULL) != MG_ERR_NONE)
327 if (mg_out(host, req->sector, req->nr_sectors, MG_CMD_RD, NULL) !=
328 MG_ERR_NONE)
329 mg_bad_rw_intr(host); 479 mg_bad_rw_intr(host);
330 480
331 MG_DBG("requested %d sects (from %ld), buffer=0x%p\n", 481 MG_DBG("requested %d sects (from %ld), buffer=0x%p\n",
332 remains, req->sector, req->buffer); 482 blk_rq_sectors(req), blk_rq_pos(req), req->buffer);
483
484 do {
485 u16 *buff = (u16 *)req->buffer;
333 486
334 while (remains) { 487 if (mg_wait(host, ATA_DRQ,
335 if (mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, 488 MG_TMAX_WAIT_RD_DRQ) != MG_ERR_NONE) {
336 MG_TMAX_WAIT_RD_DRQ) != MG_ERR_NONE) {
337 mg_bad_rw_intr(host); 489 mg_bad_rw_intr(host);
338 return; 490 return;
339 } 491 }
340 for (j = 0; j < MG_SECTOR_SIZE >> 1; j++) { 492 for (j = 0; j < MG_SECTOR_SIZE >> 1; j++)
341 *(u16 *)req->buffer = 493 *buff++ = inw((unsigned long)host->dev_base +
342 inw((unsigned long)host->dev_base + 494 MG_BUFF_OFFSET + (j << 1));
343 MG_BUFF_OFFSET + (j << 1));
344 req->buffer += 2;
345 }
346
347 req->sector++;
348 req->errors = 0;
349 remains = --req->nr_sectors;
350 --req->current_nr_sectors;
351
352 if (req->current_nr_sectors <= 0) {
353 MG_DBG("remain : %d sects\n", remains);
354 end_request(req, 1);
355 if (remains > 0)
356 req = elv_next_request(host->breq);
357 }
358 495
359 outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base + 496 outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base +
360 MG_REG_COMMAND); 497 MG_REG_COMMAND);
361 } 498 } while (mg_end_request(host, 0, MG_SECTOR_SIZE));
362} 499}
363 500
364static void mg_write(struct request *req) 501static void mg_write(struct request *req)
365{ 502{
366 u32 remains, j; 503 u32 j;
367 struct mg_host *host = req->rq_disk->private_data; 504 struct mg_host *host = req->rq_disk->private_data;
368 505
369 remains = req->nr_sectors; 506 if (mg_out(host, blk_rq_pos(req), blk_rq_sectors(req),
370 507 MG_CMD_WR, NULL) != MG_ERR_NONE) {
371 if (mg_out(host, req->sector, req->nr_sectors, MG_CMD_WR, NULL) !=
372 MG_ERR_NONE) {
373 mg_bad_rw_intr(host); 508 mg_bad_rw_intr(host);
374 return; 509 return;
375 } 510 }
376 511
377
378 MG_DBG("requested %d sects (from %ld), buffer=0x%p\n", 512 MG_DBG("requested %d sects (from %ld), buffer=0x%p\n",
379 remains, req->sector, req->buffer); 513 blk_rq_sectors(req), blk_rq_pos(req), req->buffer);
380 while (remains) { 514
381 if (mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, 515 do {
382 MG_TMAX_WAIT_WR_DRQ) != MG_ERR_NONE) { 516 u16 *buff = (u16 *)req->buffer;
517
518 if (mg_wait(host, ATA_DRQ, MG_TMAX_WAIT_WR_DRQ) != MG_ERR_NONE) {
383 mg_bad_rw_intr(host); 519 mg_bad_rw_intr(host);
384 return; 520 return;
385 } 521 }
386 for (j = 0; j < MG_SECTOR_SIZE >> 1; j++) { 522 for (j = 0; j < MG_SECTOR_SIZE >> 1; j++)
387 outw(*(u16 *)req->buffer, 523 outw(*buff++, (unsigned long)host->dev_base +
388 (unsigned long)host->dev_base + 524 MG_BUFF_OFFSET + (j << 1));
389 MG_BUFF_OFFSET + (j << 1));
390 req->buffer += 2;
391 }
392 req->sector++;
393 remains = --req->nr_sectors;
394 --req->current_nr_sectors;
395
396 if (req->current_nr_sectors <= 0) {
397 MG_DBG("remain : %d sects\n", remains);
398 end_request(req, 1);
399 if (remains > 0)
400 req = elv_next_request(host->breq);
401 }
402 525
403 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base + 526 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base +
404 MG_REG_COMMAND); 527 MG_REG_COMMAND);
405 } 528 } while (mg_end_request(host, 0, MG_SECTOR_SIZE));
406} 529}
407 530
408static void mg_read_intr(struct mg_host *host) 531static void mg_read_intr(struct mg_host *host)
409{ 532{
533 struct request *req = host->req;
410 u32 i; 534 u32 i;
411 struct request *req; 535 u16 *buff;
412 536
413 /* check status */ 537 /* check status */
414 do { 538 do {
415 i = inb((unsigned long)host->dev_base + MG_REG_STATUS); 539 i = inb((unsigned long)host->dev_base + MG_REG_STATUS);
416 if (i & MG_REG_STATUS_BIT_BUSY) 540 if (i & ATA_BUSY)
417 break; 541 break;
418 if (!MG_READY_OK(i)) 542 if (!MG_READY_OK(i))
419 break; 543 break;
420 if (i & MG_REG_STATUS_BIT_DATA_REQ) 544 if (i & ATA_DRQ)
421 goto ok_to_read; 545 goto ok_to_read;
422 } while (0); 546 } while (0);
423 mg_dump_status("mg_read_intr", i, host); 547 mg_dump_status("mg_read_intr", i, host);
@@ -427,60 +551,42 @@ static void mg_read_intr(struct mg_host *host)
427 551
428ok_to_read: 552ok_to_read:
429 /* get current segment of request */ 553 /* get current segment of request */
430 req = elv_next_request(host->breq); 554 buff = (u16 *)req->buffer;
431 555
432 /* read 1 sector */ 556 /* read 1 sector */
433 for (i = 0; i < MG_SECTOR_SIZE >> 1; i++) { 557 for (i = 0; i < MG_SECTOR_SIZE >> 1; i++)
434 *(u16 *)req->buffer = 558 *buff++ = inw((unsigned long)host->dev_base + MG_BUFF_OFFSET +
435 inw((unsigned long)host->dev_base + MG_BUFF_OFFSET + 559 (i << 1));
436 (i << 1));
437 req->buffer += 2;
438 }
439 560
440 /* manipulate request */
441 MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n", 561 MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n",
442 req->sector, req->nr_sectors - 1, req->buffer); 562 blk_rq_pos(req), blk_rq_sectors(req) - 1, req->buffer);
443
444 req->sector++;
445 req->errors = 0;
446 i = --req->nr_sectors;
447 --req->current_nr_sectors;
448
449 /* let know if current segment done */
450 if (req->current_nr_sectors <= 0)
451 end_request(req, 1);
452
453 /* set handler if read remains */
454 if (i > 0) {
455 host->mg_do_intr = mg_read_intr;
456 mod_timer(&host->timer, jiffies + 3 * HZ);
457 }
458 563
459 /* send read confirm */ 564 /* send read confirm */
460 outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND); 565 outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND);
461 566
462 /* goto next request */ 567 if (mg_end_request(host, 0, MG_SECTOR_SIZE)) {
463 if (!i) 568 /* set handler if read remains */
569 host->mg_do_intr = mg_read_intr;
570 mod_timer(&host->timer, jiffies + 3 * HZ);
571 } else /* goto next request */
464 mg_request(host->breq); 572 mg_request(host->breq);
465} 573}
466 574
467static void mg_write_intr(struct mg_host *host) 575static void mg_write_intr(struct mg_host *host)
468{ 576{
577 struct request *req = host->req;
469 u32 i, j; 578 u32 i, j;
470 u16 *buff; 579 u16 *buff;
471 struct request *req; 580 bool rem;
472
473 /* get current segment of request */
474 req = elv_next_request(host->breq);
475 581
476 /* check status */ 582 /* check status */
477 do { 583 do {
478 i = inb((unsigned long)host->dev_base + MG_REG_STATUS); 584 i = inb((unsigned long)host->dev_base + MG_REG_STATUS);
479 if (i & MG_REG_STATUS_BIT_BUSY) 585 if (i & ATA_BUSY)
480 break; 586 break;
481 if (!MG_READY_OK(i)) 587 if (!MG_READY_OK(i))
482 break; 588 break;
483 if ((req->nr_sectors <= 1) || (i & MG_REG_STATUS_BIT_DATA_REQ)) 589 if ((blk_rq_sectors(req) <= 1) || (i & ATA_DRQ))
484 goto ok_to_write; 590 goto ok_to_write;
485 } while (0); 591 } while (0);
486 mg_dump_status("mg_write_intr", i, host); 592 mg_dump_status("mg_write_intr", i, host);
@@ -489,18 +595,8 @@ static void mg_write_intr(struct mg_host *host)
489 return; 595 return;
490 596
491ok_to_write: 597ok_to_write:
492 /* manipulate request */ 598 if ((rem = mg_end_request(host, 0, MG_SECTOR_SIZE))) {
493 req->sector++; 599 /* write 1 sector and set handler if remains */
494 i = --req->nr_sectors;
495 --req->current_nr_sectors;
496 req->buffer += MG_SECTOR_SIZE;
497
498 /* let know if current segment or all done */
499 if (!i || (req->bio && req->current_nr_sectors <= 0))
500 end_request(req, 1);
501
502 /* write 1 sector and set handler if remains */
503 if (i > 0) {
504 buff = (u16 *)req->buffer; 600 buff = (u16 *)req->buffer;
505 for (j = 0; j < MG_STORAGE_BUFFER_SIZE >> 1; j++) { 601 for (j = 0; j < MG_STORAGE_BUFFER_SIZE >> 1; j++) {
506 outw(*buff, (unsigned long)host->dev_base + 602 outw(*buff, (unsigned long)host->dev_base +
@@ -508,7 +604,7 @@ ok_to_write:
508 buff++; 604 buff++;
509 } 605 }
510 MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n", 606 MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n",
511 req->sector, req->nr_sectors, req->buffer); 607 blk_rq_pos(req), blk_rq_sectors(req), req->buffer);
512 host->mg_do_intr = mg_write_intr; 608 host->mg_do_intr = mg_write_intr;
513 mod_timer(&host->timer, jiffies + 3 * HZ); 609 mod_timer(&host->timer, jiffies + 3 * HZ);
514 } 610 }
@@ -516,7 +612,7 @@ ok_to_write:
516 /* send write confirm */ 612 /* send write confirm */
517 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND); 613 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND);
518 614
519 if (!i) 615 if (!rem)
520 mg_request(host->breq); 616 mg_request(host->breq);
521} 617}
522 618
@@ -524,49 +620,45 @@ void mg_times_out(unsigned long data)
524{ 620{
525 struct mg_host *host = (struct mg_host *)data; 621 struct mg_host *host = (struct mg_host *)data;
526 char *name; 622 char *name;
527 struct request *req;
528 623
529 spin_lock_irq(&host->lock); 624 spin_lock_irq(&host->lock);
530 625
531 req = elv_next_request(host->breq); 626 if (!host->req)
532 if (!req)
533 goto out_unlock; 627 goto out_unlock;
534 628
535 host->mg_do_intr = NULL; 629 host->mg_do_intr = NULL;
536 630
537 name = req->rq_disk->disk_name; 631 name = host->req->rq_disk->disk_name;
538 printk(KERN_DEBUG "%s: timeout\n", name); 632 printk(KERN_DEBUG "%s: timeout\n", name);
539 633
540 host->error = MG_ERR_TIMEOUT; 634 host->error = MG_ERR_TIMEOUT;
541 mg_bad_rw_intr(host); 635 mg_bad_rw_intr(host);
542 636
543 mg_request(host->breq);
544out_unlock: 637out_unlock:
638 mg_request(host->breq);
545 spin_unlock_irq(&host->lock); 639 spin_unlock_irq(&host->lock);
546} 640}
547 641
548static void mg_request_poll(struct request_queue *q) 642static void mg_request_poll(struct request_queue *q)
549{ 643{
550 struct request *req; 644 struct mg_host *host = q->queuedata;
551 struct mg_host *host;
552 645
553 while ((req = elv_next_request(q)) != NULL) { 646 while (1) {
554 host = req->rq_disk->private_data; 647 if (!host->req) {
555 if (blk_fs_request(req)) { 648 host->req = blk_fetch_request(q);
556 switch (rq_data_dir(req)) { 649 if (!host->req)
557 case READ:
558 mg_read(req);
559 break;
560 case WRITE:
561 mg_write(req);
562 break;
563 default:
564 printk(KERN_WARNING "%s:%d unknown command\n",
565 __func__, __LINE__);
566 end_request(req, 0);
567 break; 650 break;
568 }
569 } 651 }
652
653 if (unlikely(!blk_fs_request(host->req))) {
654 mg_end_request_cur(host, -EIO);
655 continue;
656 }
657
658 if (rq_data_dir(host->req) == READ)
659 mg_read(host->req);
660 else
661 mg_write(host->req);
570 } 662 }
571} 663}
572 664
@@ -588,18 +680,15 @@ static unsigned int mg_issue_req(struct request *req,
588 break; 680 break;
589 case WRITE: 681 case WRITE:
590 /* TODO : handler */ 682 /* TODO : handler */
591 outb(MG_REG_CTRL_INTR_DISABLE, 683 outb(ATA_NIEN, (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
592 (unsigned long)host->dev_base +
593 MG_REG_DRV_CTRL);
594 if (mg_out(host, sect_num, sect_cnt, MG_CMD_WR, &mg_write_intr) 684 if (mg_out(host, sect_num, sect_cnt, MG_CMD_WR, &mg_write_intr)
595 != MG_ERR_NONE) { 685 != MG_ERR_NONE) {
596 mg_bad_rw_intr(host); 686 mg_bad_rw_intr(host);
597 return host->error; 687 return host->error;
598 } 688 }
599 del_timer(&host->timer); 689 del_timer(&host->timer);
600 mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, MG_TMAX_WAIT_WR_DRQ); 690 mg_wait(host, ATA_DRQ, MG_TMAX_WAIT_WR_DRQ);
601 outb(MG_REG_CTRL_INTR_ENABLE, (unsigned long)host->dev_base + 691 outb(0, (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
602 MG_REG_DRV_CTRL);
603 if (host->error) { 692 if (host->error) {
604 mg_bad_rw_intr(host); 693 mg_bad_rw_intr(host);
605 return host->error; 694 return host->error;
@@ -614,11 +703,6 @@ static unsigned int mg_issue_req(struct request *req,
614 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base + 703 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base +
615 MG_REG_COMMAND); 704 MG_REG_COMMAND);
616 break; 705 break;
617 default:
618 printk(KERN_WARNING "%s:%d unknown command\n",
619 __func__, __LINE__);
620 end_request(req, 0);
621 break;
622 } 706 }
623 return MG_ERR_NONE; 707 return MG_ERR_NONE;
624} 708}
@@ -626,16 +710,17 @@ static unsigned int mg_issue_req(struct request *req,
626/* This function also called from IRQ context */ 710/* This function also called from IRQ context */
627static void mg_request(struct request_queue *q) 711static void mg_request(struct request_queue *q)
628{ 712{
713 struct mg_host *host = q->queuedata;
629 struct request *req; 714 struct request *req;
630 struct mg_host *host;
631 u32 sect_num, sect_cnt; 715 u32 sect_num, sect_cnt;
632 716
633 while (1) { 717 while (1) {
634 req = elv_next_request(q); 718 if (!host->req) {
635 if (!req) 719 host->req = blk_fetch_request(q);
636 return; 720 if (!host->req)
637 721 break;
638 host = req->rq_disk->private_data; 722 }
723 req = host->req;
639 724
640 /* check unwanted request call */ 725 /* check unwanted request call */
641 if (host->mg_do_intr) 726 if (host->mg_do_intr)
@@ -643,9 +728,9 @@ static void mg_request(struct request_queue *q)
643 728
644 del_timer(&host->timer); 729 del_timer(&host->timer);
645 730
646 sect_num = req->sector; 731 sect_num = blk_rq_pos(req);
647 /* deal whole segments */ 732 /* deal whole segments */
648 sect_cnt = req->nr_sectors; 733 sect_cnt = blk_rq_sectors(req);
649 734
650 /* sanity check */ 735 /* sanity check */
651 if (sect_num >= get_capacity(req->rq_disk) || 736 if (sect_num >= get_capacity(req->rq_disk) ||
@@ -655,12 +740,14 @@ static void mg_request(struct request_queue *q)
655 "%s: bad access: sector=%d, count=%d\n", 740 "%s: bad access: sector=%d, count=%d\n",
656 req->rq_disk->disk_name, 741 req->rq_disk->disk_name,
657 sect_num, sect_cnt); 742 sect_num, sect_cnt);
658 end_request(req, 0); 743 mg_end_request_cur(host, -EIO);
659 continue; 744 continue;
660 } 745 }
661 746
662 if (!blk_fs_request(req)) 747 if (unlikely(!blk_fs_request(req))) {
663 return; 748 mg_end_request_cur(host, -EIO);
749 continue;
750 }
664 751
665 if (!mg_issue_req(req, host, sect_num, sect_cnt)) 752 if (!mg_issue_req(req, host, sect_num, sect_cnt))
666 return; 753 return;
@@ -690,9 +777,7 @@ static int mg_suspend(struct platform_device *plat_dev, pm_message_t state)
690 return -EIO; 777 return -EIO;
691 778
692 if (!prv_data->use_polling) 779 if (!prv_data->use_polling)
693 outb(MG_REG_CTRL_INTR_DISABLE, 780 outb(ATA_NIEN, (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
694 (unsigned long)host->dev_base +
695 MG_REG_DRV_CTRL);
696 781
697 outb(MG_CMD_SLEEP, (unsigned long)host->dev_base + MG_REG_COMMAND); 782 outb(MG_CMD_SLEEP, (unsigned long)host->dev_base + MG_REG_COMMAND);
698 /* wait until mflash deep sleep */ 783 /* wait until mflash deep sleep */
@@ -700,9 +785,7 @@ static int mg_suspend(struct platform_device *plat_dev, pm_message_t state)
700 785
701 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD)) { 786 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD)) {
702 if (!prv_data->use_polling) 787 if (!prv_data->use_polling)
703 outb(MG_REG_CTRL_INTR_ENABLE, 788 outb(0, (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
704 (unsigned long)host->dev_base +
705 MG_REG_DRV_CTRL);
706 return -EIO; 789 return -EIO;
707 } 790 }
708 791
@@ -725,8 +808,7 @@ static int mg_resume(struct platform_device *plat_dev)
725 return -EIO; 808 return -EIO;
726 809
727 if (!prv_data->use_polling) 810 if (!prv_data->use_polling)
728 outb(MG_REG_CTRL_INTR_ENABLE, (unsigned long)host->dev_base + 811 outb(0, (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
729 MG_REG_DRV_CTRL);
730 812
731 return 0; 813 return 0;
732} 814}
@@ -877,6 +959,7 @@ static int mg_probe(struct platform_device *plat_dev)
877 __func__, __LINE__); 959 __func__, __LINE__);
878 goto probe_err_5; 960 goto probe_err_5;
879 } 961 }
962 host->breq->queuedata = host;
880 963
881 /* mflash is random device, thanx for the noop */ 964 /* mflash is random device, thanx for the noop */
882 elevator_exit(host->breq->elevator); 965 elevator_exit(host->breq->elevator);
@@ -887,7 +970,7 @@ static int mg_probe(struct platform_device *plat_dev)
887 goto probe_err_6; 970 goto probe_err_6;
888 } 971 }
889 blk_queue_max_sectors(host->breq, MG_MAX_SECTS); 972 blk_queue_max_sectors(host->breq, MG_MAX_SECTS);
890 blk_queue_hardsect_size(host->breq, MG_SECTOR_SIZE); 973 blk_queue_logical_block_size(host->breq, MG_SECTOR_SIZE);
891 974
892 init_timer(&host->timer); 975 init_timer(&host->timer);
893 host->timer.function = mg_times_out; 976 host->timer.function = mg_times_out;
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 4d6de4f15ccb..5d23ffad7c77 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -110,7 +110,7 @@ static void nbd_end_request(struct request *req)
110 req, error ? "failed" : "done"); 110 req, error ? "failed" : "done");
111 111
112 spin_lock_irqsave(q->queue_lock, flags); 112 spin_lock_irqsave(q->queue_lock, flags);
113 __blk_end_request(req, error, req->nr_sectors << 9); 113 __blk_end_request_all(req, error);
114 spin_unlock_irqrestore(q->queue_lock, flags); 114 spin_unlock_irqrestore(q->queue_lock, flags);
115} 115}
116 116
@@ -231,19 +231,19 @@ static int nbd_send_req(struct nbd_device *lo, struct request *req)
231{ 231{
232 int result, flags; 232 int result, flags;
233 struct nbd_request request; 233 struct nbd_request request;
234 unsigned long size = req->nr_sectors << 9; 234 unsigned long size = blk_rq_bytes(req);
235 235
236 request.magic = htonl(NBD_REQUEST_MAGIC); 236 request.magic = htonl(NBD_REQUEST_MAGIC);
237 request.type = htonl(nbd_cmd(req)); 237 request.type = htonl(nbd_cmd(req));
238 request.from = cpu_to_be64((u64) req->sector << 9); 238 request.from = cpu_to_be64((u64)blk_rq_pos(req) << 9);
239 request.len = htonl(size); 239 request.len = htonl(size);
240 memcpy(request.handle, &req, sizeof(req)); 240 memcpy(request.handle, &req, sizeof(req));
241 241
242 dprintk(DBG_TX, "%s: request %p: sending control (%s@%llu,%luB)\n", 242 dprintk(DBG_TX, "%s: request %p: sending control (%s@%llu,%uB)\n",
243 lo->disk->disk_name, req, 243 lo->disk->disk_name, req,
244 nbdcmd_to_ascii(nbd_cmd(req)), 244 nbdcmd_to_ascii(nbd_cmd(req)),
245 (unsigned long long)req->sector << 9, 245 (unsigned long long)blk_rq_pos(req) << 9,
246 req->nr_sectors << 9); 246 blk_rq_bytes(req));
247 result = sock_xmit(lo, 1, &request, sizeof(request), 247 result = sock_xmit(lo, 1, &request, sizeof(request),
248 (nbd_cmd(req) == NBD_CMD_WRITE) ? MSG_MORE : 0); 248 (nbd_cmd(req) == NBD_CMD_WRITE) ? MSG_MORE : 0);
249 if (result <= 0) { 249 if (result <= 0) {
@@ -533,11 +533,9 @@ static void do_nbd_request(struct request_queue *q)
533{ 533{
534 struct request *req; 534 struct request *req;
535 535
536 while ((req = elv_next_request(q)) != NULL) { 536 while ((req = blk_fetch_request(q)) != NULL) {
537 struct nbd_device *lo; 537 struct nbd_device *lo;
538 538
539 blkdev_dequeue_request(req);
540
541 spin_unlock_irq(q->queue_lock); 539 spin_unlock_irq(q->queue_lock);
542 540
543 dprintk(DBG_BLKDEV, "%s: request %p: dequeued (flags=%x)\n", 541 dprintk(DBG_BLKDEV, "%s: request %p: dequeued (flags=%x)\n",
@@ -580,13 +578,6 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
580 blk_rq_init(NULL, &sreq); 578 blk_rq_init(NULL, &sreq);
581 sreq.cmd_type = REQ_TYPE_SPECIAL; 579 sreq.cmd_type = REQ_TYPE_SPECIAL;
582 nbd_cmd(&sreq) = NBD_CMD_DISC; 580 nbd_cmd(&sreq) = NBD_CMD_DISC;
583 /*
584 * Set these to sane values in case server implementation
585 * fails to check the request type first and also to keep
586 * debugging output cleaner.
587 */
588 sreq.sector = 0;
589 sreq.nr_sectors = 0;
590 if (!lo->sock) 581 if (!lo->sock)
591 return -EINVAL; 582 return -EINVAL;
592 nbd_send_req(lo, &sreq); 583 nbd_send_req(lo, &sreq);
diff --git a/drivers/block/paride/pcd.c b/drivers/block/paride/pcd.c
index e91d4b4b014f..911dfd98d813 100644
--- a/drivers/block/paride/pcd.c
+++ b/drivers/block/paride/pcd.c
@@ -719,32 +719,37 @@ static void do_pcd_request(struct request_queue * q)
719 if (pcd_busy) 719 if (pcd_busy)
720 return; 720 return;
721 while (1) { 721 while (1) {
722 pcd_req = elv_next_request(q); 722 if (!pcd_req) {
723 if (!pcd_req) 723 pcd_req = blk_fetch_request(q);
724 return; 724 if (!pcd_req)
725 return;
726 }
725 727
726 if (rq_data_dir(pcd_req) == READ) { 728 if (rq_data_dir(pcd_req) == READ) {
727 struct pcd_unit *cd = pcd_req->rq_disk->private_data; 729 struct pcd_unit *cd = pcd_req->rq_disk->private_data;
728 if (cd != pcd_current) 730 if (cd != pcd_current)
729 pcd_bufblk = -1; 731 pcd_bufblk = -1;
730 pcd_current = cd; 732 pcd_current = cd;
731 pcd_sector = pcd_req->sector; 733 pcd_sector = blk_rq_pos(pcd_req);
732 pcd_count = pcd_req->current_nr_sectors; 734 pcd_count = blk_rq_cur_sectors(pcd_req);
733 pcd_buf = pcd_req->buffer; 735 pcd_buf = pcd_req->buffer;
734 pcd_busy = 1; 736 pcd_busy = 1;
735 ps_set_intr(do_pcd_read, NULL, 0, nice); 737 ps_set_intr(do_pcd_read, NULL, 0, nice);
736 return; 738 return;
737 } else 739 } else {
738 end_request(pcd_req, 0); 740 __blk_end_request_all(pcd_req, -EIO);
741 pcd_req = NULL;
742 }
739 } 743 }
740} 744}
741 745
742static inline void next_request(int success) 746static inline void next_request(int err)
743{ 747{
744 unsigned long saved_flags; 748 unsigned long saved_flags;
745 749
746 spin_lock_irqsave(&pcd_lock, saved_flags); 750 spin_lock_irqsave(&pcd_lock, saved_flags);
747 end_request(pcd_req, success); 751 if (!__blk_end_request_cur(pcd_req, err))
752 pcd_req = NULL;
748 pcd_busy = 0; 753 pcd_busy = 0;
749 do_pcd_request(pcd_queue); 754 do_pcd_request(pcd_queue);
750 spin_unlock_irqrestore(&pcd_lock, saved_flags); 755 spin_unlock_irqrestore(&pcd_lock, saved_flags);
@@ -781,7 +786,7 @@ static void pcd_start(void)
781 786
782 if (pcd_command(pcd_current, rd_cmd, 2048, "read block")) { 787 if (pcd_command(pcd_current, rd_cmd, 2048, "read block")) {
783 pcd_bufblk = -1; 788 pcd_bufblk = -1;
784 next_request(0); 789 next_request(-EIO);
785 return; 790 return;
786 } 791 }
787 792
@@ -796,7 +801,7 @@ static void do_pcd_read(void)
796 pcd_retries = 0; 801 pcd_retries = 0;
797 pcd_transfer(); 802 pcd_transfer();
798 if (!pcd_count) { 803 if (!pcd_count) {
799 next_request(1); 804 next_request(0);
800 return; 805 return;
801 } 806 }
802 807
@@ -815,7 +820,7 @@ static void do_pcd_read_drq(void)
815 return; 820 return;
816 } 821 }
817 pcd_bufblk = -1; 822 pcd_bufblk = -1;
818 next_request(0); 823 next_request(-EIO);
819 return; 824 return;
820 } 825 }
821 826
diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c
index 9299455b0af6..bf5955b3d873 100644
--- a/drivers/block/paride/pd.c
+++ b/drivers/block/paride/pd.c
@@ -410,10 +410,12 @@ static void run_fsm(void)
410 pd_claimed = 0; 410 pd_claimed = 0;
411 phase = NULL; 411 phase = NULL;
412 spin_lock_irqsave(&pd_lock, saved_flags); 412 spin_lock_irqsave(&pd_lock, saved_flags);
413 end_request(pd_req, res); 413 if (!__blk_end_request_cur(pd_req,
414 pd_req = elv_next_request(pd_queue); 414 res == Ok ? 0 : -EIO)) {
415 if (!pd_req) 415 pd_req = blk_fetch_request(pd_queue);
416 stop = 1; 416 if (!pd_req)
417 stop = 1;
418 }
417 spin_unlock_irqrestore(&pd_lock, saved_flags); 419 spin_unlock_irqrestore(&pd_lock, saved_flags);
418 if (stop) 420 if (stop)
419 return; 421 return;
@@ -443,11 +445,11 @@ static enum action do_pd_io_start(void)
443 445
444 pd_cmd = rq_data_dir(pd_req); 446 pd_cmd = rq_data_dir(pd_req);
445 if (pd_cmd == READ || pd_cmd == WRITE) { 447 if (pd_cmd == READ || pd_cmd == WRITE) {
446 pd_block = pd_req->sector; 448 pd_block = blk_rq_pos(pd_req);
447 pd_count = pd_req->current_nr_sectors; 449 pd_count = blk_rq_cur_sectors(pd_req);
448 if (pd_block + pd_count > get_capacity(pd_req->rq_disk)) 450 if (pd_block + pd_count > get_capacity(pd_req->rq_disk))
449 return Fail; 451 return Fail;
450 pd_run = pd_req->nr_sectors; 452 pd_run = blk_rq_sectors(pd_req);
451 pd_buf = pd_req->buffer; 453 pd_buf = pd_req->buffer;
452 pd_retries = 0; 454 pd_retries = 0;
453 if (pd_cmd == READ) 455 if (pd_cmd == READ)
@@ -477,8 +479,8 @@ static int pd_next_buf(void)
477 if (pd_count) 479 if (pd_count)
478 return 0; 480 return 0;
479 spin_lock_irqsave(&pd_lock, saved_flags); 481 spin_lock_irqsave(&pd_lock, saved_flags);
480 end_request(pd_req, 1); 482 __blk_end_request_cur(pd_req, 0);
481 pd_count = pd_req->current_nr_sectors; 483 pd_count = blk_rq_cur_sectors(pd_req);
482 pd_buf = pd_req->buffer; 484 pd_buf = pd_req->buffer;
483 spin_unlock_irqrestore(&pd_lock, saved_flags); 485 spin_unlock_irqrestore(&pd_lock, saved_flags);
484 return 0; 486 return 0;
@@ -702,7 +704,7 @@ static void do_pd_request(struct request_queue * q)
702{ 704{
703 if (pd_req) 705 if (pd_req)
704 return; 706 return;
705 pd_req = elv_next_request(q); 707 pd_req = blk_fetch_request(q);
706 if (!pd_req) 708 if (!pd_req)
707 return; 709 return;
708 710
diff --git a/drivers/block/paride/pf.c b/drivers/block/paride/pf.c
index bef3b997ba3e..68a90834e993 100644
--- a/drivers/block/paride/pf.c
+++ b/drivers/block/paride/pf.c
@@ -750,12 +750,10 @@ static int pf_ready(void)
750 750
751static struct request_queue *pf_queue; 751static struct request_queue *pf_queue;
752 752
753static void pf_end_request(int uptodate) 753static void pf_end_request(int err)
754{ 754{
755 if (pf_req) { 755 if (pf_req && !__blk_end_request_cur(pf_req, err))
756 end_request(pf_req, uptodate);
757 pf_req = NULL; 756 pf_req = NULL;
758 }
759} 757}
760 758
761static void do_pf_request(struct request_queue * q) 759static void do_pf_request(struct request_queue * q)
@@ -763,17 +761,19 @@ static void do_pf_request(struct request_queue * q)
763 if (pf_busy) 761 if (pf_busy)
764 return; 762 return;
765repeat: 763repeat:
766 pf_req = elv_next_request(q); 764 if (!pf_req) {
767 if (!pf_req) 765 pf_req = blk_fetch_request(q);
768 return; 766 if (!pf_req)
767 return;
768 }
769 769
770 pf_current = pf_req->rq_disk->private_data; 770 pf_current = pf_req->rq_disk->private_data;
771 pf_block = pf_req->sector; 771 pf_block = blk_rq_pos(pf_req);
772 pf_run = pf_req->nr_sectors; 772 pf_run = blk_rq_sectors(pf_req);
773 pf_count = pf_req->current_nr_sectors; 773 pf_count = blk_rq_cur_sectors(pf_req);
774 774
775 if (pf_block + pf_count > get_capacity(pf_req->rq_disk)) { 775 if (pf_block + pf_count > get_capacity(pf_req->rq_disk)) {
776 pf_end_request(0); 776 pf_end_request(-EIO);
777 goto repeat; 777 goto repeat;
778 } 778 }
779 779
@@ -788,7 +788,7 @@ repeat:
788 pi_do_claimed(pf_current->pi, do_pf_write); 788 pi_do_claimed(pf_current->pi, do_pf_write);
789 else { 789 else {
790 pf_busy = 0; 790 pf_busy = 0;
791 pf_end_request(0); 791 pf_end_request(-EIO);
792 goto repeat; 792 goto repeat;
793 } 793 }
794} 794}
@@ -805,23 +805,22 @@ static int pf_next_buf(void)
805 return 1; 805 return 1;
806 if (!pf_count) { 806 if (!pf_count) {
807 spin_lock_irqsave(&pf_spin_lock, saved_flags); 807 spin_lock_irqsave(&pf_spin_lock, saved_flags);
808 pf_end_request(1); 808 pf_end_request(0);
809 pf_req = elv_next_request(pf_queue);
810 spin_unlock_irqrestore(&pf_spin_lock, saved_flags); 809 spin_unlock_irqrestore(&pf_spin_lock, saved_flags);
811 if (!pf_req) 810 if (!pf_req)
812 return 1; 811 return 1;
813 pf_count = pf_req->current_nr_sectors; 812 pf_count = blk_rq_cur_sectors(pf_req);
814 pf_buf = pf_req->buffer; 813 pf_buf = pf_req->buffer;
815 } 814 }
816 return 0; 815 return 0;
817} 816}
818 817
819static inline void next_request(int success) 818static inline void next_request(int err)
820{ 819{
821 unsigned long saved_flags; 820 unsigned long saved_flags;
822 821
823 spin_lock_irqsave(&pf_spin_lock, saved_flags); 822 spin_lock_irqsave(&pf_spin_lock, saved_flags);
824 pf_end_request(success); 823 pf_end_request(err);
825 pf_busy = 0; 824 pf_busy = 0;
826 do_pf_request(pf_queue); 825 do_pf_request(pf_queue);
827 spin_unlock_irqrestore(&pf_spin_lock, saved_flags); 826 spin_unlock_irqrestore(&pf_spin_lock, saved_flags);
@@ -844,7 +843,7 @@ static void do_pf_read_start(void)
844 pi_do_claimed(pf_current->pi, do_pf_read_start); 843 pi_do_claimed(pf_current->pi, do_pf_read_start);
845 return; 844 return;
846 } 845 }
847 next_request(0); 846 next_request(-EIO);
848 return; 847 return;
849 } 848 }
850 pf_mask = STAT_DRQ; 849 pf_mask = STAT_DRQ;
@@ -863,7 +862,7 @@ static void do_pf_read_drq(void)
863 pi_do_claimed(pf_current->pi, do_pf_read_start); 862 pi_do_claimed(pf_current->pi, do_pf_read_start);
864 return; 863 return;
865 } 864 }
866 next_request(0); 865 next_request(-EIO);
867 return; 866 return;
868 } 867 }
869 pi_read_block(pf_current->pi, pf_buf, 512); 868 pi_read_block(pf_current->pi, pf_buf, 512);
@@ -871,7 +870,7 @@ static void do_pf_read_drq(void)
871 break; 870 break;
872 } 871 }
873 pi_disconnect(pf_current->pi); 872 pi_disconnect(pf_current->pi);
874 next_request(1); 873 next_request(0);
875} 874}
876 875
877static void do_pf_write(void) 876static void do_pf_write(void)
@@ -890,7 +889,7 @@ static void do_pf_write_start(void)
890 pi_do_claimed(pf_current->pi, do_pf_write_start); 889 pi_do_claimed(pf_current->pi, do_pf_write_start);
891 return; 890 return;
892 } 891 }
893 next_request(0); 892 next_request(-EIO);
894 return; 893 return;
895 } 894 }
896 895
@@ -903,7 +902,7 @@ static void do_pf_write_start(void)
903 pi_do_claimed(pf_current->pi, do_pf_write_start); 902 pi_do_claimed(pf_current->pi, do_pf_write_start);
904 return; 903 return;
905 } 904 }
906 next_request(0); 905 next_request(-EIO);
907 return; 906 return;
908 } 907 }
909 pi_write_block(pf_current->pi, pf_buf, 512); 908 pi_write_block(pf_current->pi, pf_buf, 512);
@@ -923,11 +922,11 @@ static void do_pf_write_done(void)
923 pi_do_claimed(pf_current->pi, do_pf_write_start); 922 pi_do_claimed(pf_current->pi, do_pf_write_start);
924 return; 923 return;
925 } 924 }
926 next_request(0); 925 next_request(-EIO);
927 return; 926 return;
928 } 927 }
929 pi_disconnect(pf_current->pi); 928 pi_disconnect(pf_current->pi);
930 next_request(1); 929 next_request(0);
931} 930}
932 931
933static int __init pf_init(void) 932static int __init pf_init(void)
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index dc7a8c352da2..83650e00632d 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -430,7 +430,7 @@ static void pkt_sysfs_cleanup(void)
430/******************************************************************** 430/********************************************************************
431 entries in debugfs 431 entries in debugfs
432 432
433 /debugfs/pktcdvd[0-7]/ 433 /sys/kernel/debug/pktcdvd[0-7]/
434 info 434 info
435 435
436 *******************************************************************/ 436 *******************************************************************/
@@ -991,13 +991,15 @@ static void pkt_iosched_process_queue(struct pktcdvd_device *pd)
991 */ 991 */
992static int pkt_set_segment_merging(struct pktcdvd_device *pd, struct request_queue *q) 992static int pkt_set_segment_merging(struct pktcdvd_device *pd, struct request_queue *q)
993{ 993{
994 if ((pd->settings.size << 9) / CD_FRAMESIZE <= q->max_phys_segments) { 994 if ((pd->settings.size << 9) / CD_FRAMESIZE
995 <= queue_max_phys_segments(q)) {
995 /* 996 /*
996 * The cdrom device can handle one segment/frame 997 * The cdrom device can handle one segment/frame
997 */ 998 */
998 clear_bit(PACKET_MERGE_SEGS, &pd->flags); 999 clear_bit(PACKET_MERGE_SEGS, &pd->flags);
999 return 0; 1000 return 0;
1000 } else if ((pd->settings.size << 9) / PAGE_SIZE <= q->max_phys_segments) { 1001 } else if ((pd->settings.size << 9) / PAGE_SIZE
1002 <= queue_max_phys_segments(q)) {
1001 /* 1003 /*
1002 * We can handle this case at the expense of some extra memory 1004 * We can handle this case at the expense of some extra memory
1003 * copies during write operations 1005 * copies during write operations
@@ -2657,7 +2659,7 @@ static void pkt_init_queue(struct pktcdvd_device *pd)
2657 struct request_queue *q = pd->disk->queue; 2659 struct request_queue *q = pd->disk->queue;
2658 2660
2659 blk_queue_make_request(q, pkt_make_request); 2661 blk_queue_make_request(q, pkt_make_request);
2660 blk_queue_hardsect_size(q, CD_FRAMESIZE); 2662 blk_queue_logical_block_size(q, CD_FRAMESIZE);
2661 blk_queue_max_sectors(q, PACKET_MAX_SECTORS); 2663 blk_queue_max_sectors(q, PACKET_MAX_SECTORS);
2662 blk_queue_merge_bvec(q, pkt_merge_bvec); 2664 blk_queue_merge_bvec(q, pkt_merge_bvec);
2663 q->queuedata = pd; 2665 q->queuedata = pd;
@@ -2853,6 +2855,11 @@ static struct block_device_operations pktcdvd_ops = {
2853 .media_changed = pkt_media_changed, 2855 .media_changed = pkt_media_changed,
2854}; 2856};
2855 2857
2858static char *pktcdvd_nodename(struct gendisk *gd)
2859{
2860 return kasprintf(GFP_KERNEL, "pktcdvd/%s", gd->disk_name);
2861}
2862
2856/* 2863/*
2857 * Set up mapping from pktcdvd device to CD-ROM device. 2864 * Set up mapping from pktcdvd device to CD-ROM device.
2858 */ 2865 */
@@ -2905,6 +2912,7 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev)
2905 disk->fops = &pktcdvd_ops; 2912 disk->fops = &pktcdvd_ops;
2906 disk->flags = GENHD_FL_REMOVABLE; 2913 disk->flags = GENHD_FL_REMOVABLE;
2907 strcpy(disk->disk_name, pd->name); 2914 strcpy(disk->disk_name, pd->name);
2915 disk->nodename = pktcdvd_nodename;
2908 disk->private_data = pd; 2916 disk->private_data = pd;
2909 disk->queue = blk_alloc_queue(GFP_KERNEL); 2917 disk->queue = blk_alloc_queue(GFP_KERNEL);
2910 if (!disk->queue) 2918 if (!disk->queue)
@@ -3060,6 +3068,7 @@ static const struct file_operations pkt_ctl_fops = {
3060static struct miscdevice pkt_misc = { 3068static struct miscdevice pkt_misc = {
3061 .minor = MISC_DYNAMIC_MINOR, 3069 .minor = MISC_DYNAMIC_MINOR,
3062 .name = DRIVER_NAME, 3070 .name = DRIVER_NAME,
3071 .name = "pktcdvd/control",
3063 .fops = &pkt_ctl_fops 3072 .fops = &pkt_ctl_fops
3064}; 3073};
3065 3074
diff --git a/drivers/block/ps3disk.c b/drivers/block/ps3disk.c
index bccc42bb9212..34cbb7f3efa8 100644
--- a/drivers/block/ps3disk.c
+++ b/drivers/block/ps3disk.c
@@ -120,7 +120,7 @@ static void ps3disk_scatter_gather(struct ps3_storage_device *dev,
120static int ps3disk_submit_request_sg(struct ps3_storage_device *dev, 120static int ps3disk_submit_request_sg(struct ps3_storage_device *dev,
121 struct request *req) 121 struct request *req)
122{ 122{
123 struct ps3disk_private *priv = dev->sbd.core.driver_data; 123 struct ps3disk_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
124 int write = rq_data_dir(req), res; 124 int write = rq_data_dir(req), res;
125 const char *op = write ? "write" : "read"; 125 const char *op = write ? "write" : "read";
126 u64 start_sector, sectors; 126 u64 start_sector, sectors;
@@ -134,13 +134,12 @@ static int ps3disk_submit_request_sg(struct ps3_storage_device *dev,
134 rq_for_each_segment(bv, req, iter) 134 rq_for_each_segment(bv, req, iter)
135 n++; 135 n++;
136 dev_dbg(&dev->sbd.core, 136 dev_dbg(&dev->sbd.core,
137 "%s:%u: %s req has %u bvecs for %lu sectors %lu hard sectors\n", 137 "%s:%u: %s req has %u bvecs for %u sectors\n",
138 __func__, __LINE__, op, n, req->nr_sectors, 138 __func__, __LINE__, op, n, blk_rq_sectors(req));
139 req->hard_nr_sectors);
140#endif 139#endif
141 140
142 start_sector = req->sector * priv->blocking_factor; 141 start_sector = blk_rq_pos(req) * priv->blocking_factor;
143 sectors = req->nr_sectors * priv->blocking_factor; 142 sectors = blk_rq_sectors(req) * priv->blocking_factor;
144 dev_dbg(&dev->sbd.core, "%s:%u: %s %llu sectors starting at %llu\n", 143 dev_dbg(&dev->sbd.core, "%s:%u: %s %llu sectors starting at %llu\n",
145 __func__, __LINE__, op, sectors, start_sector); 144 __func__, __LINE__, op, sectors, start_sector);
146 145
@@ -158,7 +157,7 @@ static int ps3disk_submit_request_sg(struct ps3_storage_device *dev,
158 if (res) { 157 if (res) {
159 dev_err(&dev->sbd.core, "%s:%u: %s failed %d\n", __func__, 158 dev_err(&dev->sbd.core, "%s:%u: %s failed %d\n", __func__,
160 __LINE__, op, res); 159 __LINE__, op, res);
161 end_request(req, 0); 160 __blk_end_request_all(req, -EIO);
162 return 0; 161 return 0;
163 } 162 }
164 163
@@ -169,7 +168,7 @@ static int ps3disk_submit_request_sg(struct ps3_storage_device *dev,
169static int ps3disk_submit_flush_request(struct ps3_storage_device *dev, 168static int ps3disk_submit_flush_request(struct ps3_storage_device *dev,
170 struct request *req) 169 struct request *req)
171{ 170{
172 struct ps3disk_private *priv = dev->sbd.core.driver_data; 171 struct ps3disk_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
173 u64 res; 172 u64 res;
174 173
175 dev_dbg(&dev->sbd.core, "%s:%u: flush request\n", __func__, __LINE__); 174 dev_dbg(&dev->sbd.core, "%s:%u: flush request\n", __func__, __LINE__);
@@ -180,7 +179,7 @@ static int ps3disk_submit_flush_request(struct ps3_storage_device *dev,
180 if (res) { 179 if (res) {
181 dev_err(&dev->sbd.core, "%s:%u: sync cache failed 0x%llx\n", 180 dev_err(&dev->sbd.core, "%s:%u: sync cache failed 0x%llx\n",
182 __func__, __LINE__, res); 181 __func__, __LINE__, res);
183 end_request(req, 0); 182 __blk_end_request_all(req, -EIO);
184 return 0; 183 return 0;
185 } 184 }
186 185
@@ -195,7 +194,7 @@ static void ps3disk_do_request(struct ps3_storage_device *dev,
195 194
196 dev_dbg(&dev->sbd.core, "%s:%u\n", __func__, __LINE__); 195 dev_dbg(&dev->sbd.core, "%s:%u\n", __func__, __LINE__);
197 196
198 while ((req = elv_next_request(q))) { 197 while ((req = blk_fetch_request(q))) {
199 if (blk_fs_request(req)) { 198 if (blk_fs_request(req)) {
200 if (ps3disk_submit_request_sg(dev, req)) 199 if (ps3disk_submit_request_sg(dev, req))
201 break; 200 break;
@@ -205,7 +204,7 @@ static void ps3disk_do_request(struct ps3_storage_device *dev,
205 break; 204 break;
206 } else { 205 } else {
207 blk_dump_rq_flags(req, DEVICE_NAME " bad request"); 206 blk_dump_rq_flags(req, DEVICE_NAME " bad request");
208 end_request(req, 0); 207 __blk_end_request_all(req, -EIO);
209 continue; 208 continue;
210 } 209 }
211 } 210 }
@@ -214,7 +213,7 @@ static void ps3disk_do_request(struct ps3_storage_device *dev,
214static void ps3disk_request(struct request_queue *q) 213static void ps3disk_request(struct request_queue *q)
215{ 214{
216 struct ps3_storage_device *dev = q->queuedata; 215 struct ps3_storage_device *dev = q->queuedata;
217 struct ps3disk_private *priv = dev->sbd.core.driver_data; 216 struct ps3disk_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
218 217
219 if (priv->req) { 218 if (priv->req) {
220 dev_dbg(&dev->sbd.core, "%s:%u busy\n", __func__, __LINE__); 219 dev_dbg(&dev->sbd.core, "%s:%u busy\n", __func__, __LINE__);
@@ -231,7 +230,6 @@ static irqreturn_t ps3disk_interrupt(int irq, void *data)
231 struct request *req; 230 struct request *req;
232 int res, read, error; 231 int res, read, error;
233 u64 tag, status; 232 u64 tag, status;
234 unsigned long num_sectors;
235 const char *op; 233 const char *op;
236 234
237 res = lv1_storage_get_async_status(dev->sbd.dev_id, &tag, &status); 235 res = lv1_storage_get_async_status(dev->sbd.dev_id, &tag, &status);
@@ -247,7 +245,7 @@ static irqreturn_t ps3disk_interrupt(int irq, void *data)
247 return IRQ_HANDLED; 245 return IRQ_HANDLED;
248 } 246 }
249 247
250 priv = dev->sbd.core.driver_data; 248 priv = ps3_system_bus_get_drvdata(&dev->sbd);
251 req = priv->req; 249 req = priv->req;
252 if (!req) { 250 if (!req) {
253 dev_dbg(&dev->sbd.core, 251 dev_dbg(&dev->sbd.core,
@@ -261,11 +259,9 @@ static irqreturn_t ps3disk_interrupt(int irq, void *data)
261 if (req->cmd_type == REQ_TYPE_LINUX_BLOCK && 259 if (req->cmd_type == REQ_TYPE_LINUX_BLOCK &&
262 req->cmd[0] == REQ_LB_OP_FLUSH) { 260 req->cmd[0] == REQ_LB_OP_FLUSH) {
263 read = 0; 261 read = 0;
264 num_sectors = req->hard_cur_sectors;
265 op = "flush"; 262 op = "flush";
266 } else { 263 } else {
267 read = !rq_data_dir(req); 264 read = !rq_data_dir(req);
268 num_sectors = req->nr_sectors;
269 op = read ? "read" : "write"; 265 op = read ? "read" : "write";
270 } 266 }
271 if (status) { 267 if (status) {
@@ -281,7 +277,7 @@ static irqreturn_t ps3disk_interrupt(int irq, void *data)
281 } 277 }
282 278
283 spin_lock(&priv->lock); 279 spin_lock(&priv->lock);
284 __blk_end_request(req, error, num_sectors << 9); 280 __blk_end_request_all(req, error);
285 priv->req = NULL; 281 priv->req = NULL;
286 ps3disk_do_request(dev, priv->queue); 282 ps3disk_do_request(dev, priv->queue);
287 spin_unlock(&priv->lock); 283 spin_unlock(&priv->lock);
@@ -368,7 +364,7 @@ static void ata_id_c_string(const u16 *id, unsigned char *s, unsigned int ofs,
368 364
369static int ps3disk_identify(struct ps3_storage_device *dev) 365static int ps3disk_identify(struct ps3_storage_device *dev)
370{ 366{
371 struct ps3disk_private *priv = dev->sbd.core.driver_data; 367 struct ps3disk_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
372 struct lv1_ata_cmnd_block ata_cmnd; 368 struct lv1_ata_cmnd_block ata_cmnd;
373 u16 *id = dev->bounce_buf; 369 u16 *id = dev->bounce_buf;
374 u64 res; 370 u64 res;
@@ -449,7 +445,7 @@ static int __devinit ps3disk_probe(struct ps3_system_bus_device *_dev)
449 goto fail; 445 goto fail;
450 } 446 }
451 447
452 dev->sbd.core.driver_data = priv; 448 ps3_system_bus_set_drvdata(_dev, priv);
453 spin_lock_init(&priv->lock); 449 spin_lock_init(&priv->lock);
454 450
455 dev->bounce_size = BOUNCE_SIZE; 451 dev->bounce_size = BOUNCE_SIZE;
@@ -481,7 +477,7 @@ static int __devinit ps3disk_probe(struct ps3_system_bus_device *_dev)
481 blk_queue_max_sectors(queue, dev->bounce_size >> 9); 477 blk_queue_max_sectors(queue, dev->bounce_size >> 9);
482 blk_queue_segment_boundary(queue, -1UL); 478 blk_queue_segment_boundary(queue, -1UL);
483 blk_queue_dma_alignment(queue, dev->blk_size-1); 479 blk_queue_dma_alignment(queue, dev->blk_size-1);
484 blk_queue_hardsect_size(queue, dev->blk_size); 480 blk_queue_logical_block_size(queue, dev->blk_size);
485 481
486 blk_queue_ordered(queue, QUEUE_ORDERED_DRAIN_FLUSH, 482 blk_queue_ordered(queue, QUEUE_ORDERED_DRAIN_FLUSH,
487 ps3disk_prepare_flush); 483 ps3disk_prepare_flush);
@@ -527,7 +523,7 @@ fail_free_bounce:
527 kfree(dev->bounce_buf); 523 kfree(dev->bounce_buf);
528fail_free_priv: 524fail_free_priv:
529 kfree(priv); 525 kfree(priv);
530 dev->sbd.core.driver_data = NULL; 526 ps3_system_bus_set_drvdata(_dev, NULL);
531fail: 527fail:
532 mutex_lock(&ps3disk_mask_mutex); 528 mutex_lock(&ps3disk_mask_mutex);
533 __clear_bit(devidx, &ps3disk_mask); 529 __clear_bit(devidx, &ps3disk_mask);
@@ -538,7 +534,7 @@ fail:
538static int ps3disk_remove(struct ps3_system_bus_device *_dev) 534static int ps3disk_remove(struct ps3_system_bus_device *_dev)
539{ 535{
540 struct ps3_storage_device *dev = to_ps3_storage_device(&_dev->core); 536 struct ps3_storage_device *dev = to_ps3_storage_device(&_dev->core);
541 struct ps3disk_private *priv = dev->sbd.core.driver_data; 537 struct ps3disk_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
542 538
543 mutex_lock(&ps3disk_mask_mutex); 539 mutex_lock(&ps3disk_mask_mutex);
544 __clear_bit(MINOR(disk_devt(priv->gendisk)) / PS3DISK_MINORS, 540 __clear_bit(MINOR(disk_devt(priv->gendisk)) / PS3DISK_MINORS,
@@ -552,7 +548,7 @@ static int ps3disk_remove(struct ps3_system_bus_device *_dev)
552 ps3stor_teardown(dev); 548 ps3stor_teardown(dev);
553 kfree(dev->bounce_buf); 549 kfree(dev->bounce_buf);
554 kfree(priv); 550 kfree(priv);
555 dev->sbd.core.driver_data = NULL; 551 ps3_system_bus_set_drvdata(_dev, NULL);
556 return 0; 552 return 0;
557} 553}
558 554
diff --git a/drivers/block/ps3vram.c b/drivers/block/ps3vram.c
index 8eddef373a91..095f97e60665 100644
--- a/drivers/block/ps3vram.c
+++ b/drivers/block/ps3vram.c
@@ -14,8 +14,10 @@
14#include <linux/seq_file.h> 14#include <linux/seq_file.h>
15 15
16#include <asm/firmware.h> 16#include <asm/firmware.h>
17#include <asm/iommu.h>
17#include <asm/lv1call.h> 18#include <asm/lv1call.h>
18#include <asm/ps3.h> 19#include <asm/ps3.h>
20#include <asm/ps3gpu.h>
19 21
20 22
21#define DEVICE_NAME "ps3vram" 23#define DEVICE_NAME "ps3vram"
@@ -45,8 +47,6 @@
45#define NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN 0x0000030c 47#define NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN 0x0000030c
46#define NV_MEMORY_TO_MEMORY_FORMAT_NOTIFY 0x00000104 48#define NV_MEMORY_TO_MEMORY_FORMAT_NOTIFY 0x00000104
47 49
48#define L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT 0x601
49
50#define CACHE_PAGE_PRESENT 1 50#define CACHE_PAGE_PRESENT 1
51#define CACHE_PAGE_DIRTY 2 51#define CACHE_PAGE_DIRTY 2
52 52
@@ -72,8 +72,7 @@ struct ps3vram_priv {
72 u64 memory_handle; 72 u64 memory_handle;
73 u64 context_handle; 73 u64 context_handle;
74 u32 *ctrl; 74 u32 *ctrl;
75 u32 *reports; 75 void *reports;
76 u8 __iomem *ddr_base;
77 u8 *xdr_buf; 76 u8 *xdr_buf;
78 77
79 u32 *fifo_base; 78 u32 *fifo_base;
@@ -81,8 +80,8 @@ struct ps3vram_priv {
81 80
82 struct ps3vram_cache cache; 81 struct ps3vram_cache cache;
83 82
84 /* Used to serialize cache/DMA operations */ 83 spinlock_t lock; /* protecting list of bios */
85 struct mutex lock; 84 struct bio_list list;
86}; 85};
87 86
88 87
@@ -103,15 +102,15 @@ static char *size = "256M";
103module_param(size, charp, 0); 102module_param(size, charp, 0);
104MODULE_PARM_DESC(size, "memory size"); 103MODULE_PARM_DESC(size, "memory size");
105 104
106static u32 *ps3vram_get_notifier(u32 *reports, int notifier) 105static u32 *ps3vram_get_notifier(void *reports, int notifier)
107{ 106{
108 return (void *)reports + DMA_NOTIFIER_OFFSET_BASE + 107 return reports + DMA_NOTIFIER_OFFSET_BASE +
109 DMA_NOTIFIER_SIZE * notifier; 108 DMA_NOTIFIER_SIZE * notifier;
110} 109}
111 110
112static void ps3vram_notifier_reset(struct ps3_system_bus_device *dev) 111static void ps3vram_notifier_reset(struct ps3_system_bus_device *dev)
113{ 112{
114 struct ps3vram_priv *priv = dev->core.driver_data; 113 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
115 u32 *notify = ps3vram_get_notifier(priv->reports, NOTIFIER); 114 u32 *notify = ps3vram_get_notifier(priv->reports, NOTIFIER);
116 int i; 115 int i;
117 116
@@ -122,7 +121,7 @@ static void ps3vram_notifier_reset(struct ps3_system_bus_device *dev)
122static int ps3vram_notifier_wait(struct ps3_system_bus_device *dev, 121static int ps3vram_notifier_wait(struct ps3_system_bus_device *dev,
123 unsigned int timeout_ms) 122 unsigned int timeout_ms)
124{ 123{
125 struct ps3vram_priv *priv = dev->core.driver_data; 124 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
126 u32 *notify = ps3vram_get_notifier(priv->reports, NOTIFIER); 125 u32 *notify = ps3vram_get_notifier(priv->reports, NOTIFIER);
127 unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms); 126 unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms);
128 127
@@ -137,7 +136,7 @@ static int ps3vram_notifier_wait(struct ps3_system_bus_device *dev,
137 136
138static void ps3vram_init_ring(struct ps3_system_bus_device *dev) 137static void ps3vram_init_ring(struct ps3_system_bus_device *dev)
139{ 138{
140 struct ps3vram_priv *priv = dev->core.driver_data; 139 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
141 140
142 priv->ctrl[CTRL_PUT] = FIFO_BASE + FIFO_OFFSET; 141 priv->ctrl[CTRL_PUT] = FIFO_BASE + FIFO_OFFSET;
143 priv->ctrl[CTRL_GET] = FIFO_BASE + FIFO_OFFSET; 142 priv->ctrl[CTRL_GET] = FIFO_BASE + FIFO_OFFSET;
@@ -146,7 +145,7 @@ static void ps3vram_init_ring(struct ps3_system_bus_device *dev)
146static int ps3vram_wait_ring(struct ps3_system_bus_device *dev, 145static int ps3vram_wait_ring(struct ps3_system_bus_device *dev,
147 unsigned int timeout_ms) 146 unsigned int timeout_ms)
148{ 147{
149 struct ps3vram_priv *priv = dev->core.driver_data; 148 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
150 unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms); 149 unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms);
151 150
152 do { 151 do {
@@ -175,7 +174,7 @@ static void ps3vram_begin_ring(struct ps3vram_priv *priv, u32 chan, u32 tag,
175 174
176static void ps3vram_rewind_ring(struct ps3_system_bus_device *dev) 175static void ps3vram_rewind_ring(struct ps3_system_bus_device *dev)
177{ 176{
178 struct ps3vram_priv *priv = dev->core.driver_data; 177 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
179 int status; 178 int status;
180 179
181 ps3vram_out_ring(priv, 0x20000000 | (FIFO_BASE + FIFO_OFFSET)); 180 ps3vram_out_ring(priv, 0x20000000 | (FIFO_BASE + FIFO_OFFSET));
@@ -183,20 +182,17 @@ static void ps3vram_rewind_ring(struct ps3_system_bus_device *dev)
183 priv->ctrl[CTRL_PUT] = FIFO_BASE + FIFO_OFFSET; 182 priv->ctrl[CTRL_PUT] = FIFO_BASE + FIFO_OFFSET;
184 183
185 /* asking the HV for a blit will kick the FIFO */ 184 /* asking the HV for a blit will kick the FIFO */
186 status = lv1_gpu_context_attribute(priv->context_handle, 185 status = lv1_gpu_fb_blit(priv->context_handle, 0, 0, 0, 0);
187 L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT, 0,
188 0, 0, 0);
189 if (status) 186 if (status)
190 dev_err(&dev->core, 187 dev_err(&dev->core, "%s: lv1_gpu_fb_blit failed %d\n",
191 "%s: lv1_gpu_context_attribute failed %d\n", __func__, 188 __func__, status);
192 status);
193 189
194 priv->fifo_ptr = priv->fifo_base; 190 priv->fifo_ptr = priv->fifo_base;
195} 191}
196 192
197static void ps3vram_fire_ring(struct ps3_system_bus_device *dev) 193static void ps3vram_fire_ring(struct ps3_system_bus_device *dev)
198{ 194{
199 struct ps3vram_priv *priv = dev->core.driver_data; 195 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
200 int status; 196 int status;
201 197
202 mutex_lock(&ps3_gpu_mutex); 198 mutex_lock(&ps3_gpu_mutex);
@@ -205,13 +201,10 @@ static void ps3vram_fire_ring(struct ps3_system_bus_device *dev)
205 (priv->fifo_ptr - priv->fifo_base) * sizeof(u32); 201 (priv->fifo_ptr - priv->fifo_base) * sizeof(u32);
206 202
207 /* asking the HV for a blit will kick the FIFO */ 203 /* asking the HV for a blit will kick the FIFO */
208 status = lv1_gpu_context_attribute(priv->context_handle, 204 status = lv1_gpu_fb_blit(priv->context_handle, 0, 0, 0, 0);
209 L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT, 0,
210 0, 0, 0);
211 if (status) 205 if (status)
212 dev_err(&dev->core, 206 dev_err(&dev->core, "%s: lv1_gpu_fb_blit failed %d\n",
213 "%s: lv1_gpu_context_attribute failed %d\n", __func__, 207 __func__, status);
214 status);
215 208
216 if ((priv->fifo_ptr - priv->fifo_base) * sizeof(u32) > 209 if ((priv->fifo_ptr - priv->fifo_base) * sizeof(u32) >
217 FIFO_SIZE - 1024) { 210 FIFO_SIZE - 1024) {
@@ -225,7 +218,7 @@ static void ps3vram_fire_ring(struct ps3_system_bus_device *dev)
225 218
226static void ps3vram_bind(struct ps3_system_bus_device *dev) 219static void ps3vram_bind(struct ps3_system_bus_device *dev)
227{ 220{
228 struct ps3vram_priv *priv = dev->core.driver_data; 221 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
229 222
230 ps3vram_begin_ring(priv, UPLOAD_SUBCH, 0, 1); 223 ps3vram_begin_ring(priv, UPLOAD_SUBCH, 0, 1);
231 ps3vram_out_ring(priv, 0x31337303); 224 ps3vram_out_ring(priv, 0x31337303);
@@ -248,7 +241,7 @@ static int ps3vram_upload(struct ps3_system_bus_device *dev,
248 unsigned int src_offset, unsigned int dst_offset, 241 unsigned int src_offset, unsigned int dst_offset,
249 int len, int count) 242 int len, int count)
250{ 243{
251 struct ps3vram_priv *priv = dev->core.driver_data; 244 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
252 245
253 ps3vram_begin_ring(priv, UPLOAD_SUBCH, 246 ps3vram_begin_ring(priv, UPLOAD_SUBCH,
254 NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8); 247 NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8);
@@ -280,7 +273,7 @@ static int ps3vram_download(struct ps3_system_bus_device *dev,
280 unsigned int src_offset, unsigned int dst_offset, 273 unsigned int src_offset, unsigned int dst_offset,
281 int len, int count) 274 int len, int count)
282{ 275{
283 struct ps3vram_priv *priv = dev->core.driver_data; 276 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
284 277
285 ps3vram_begin_ring(priv, DOWNLOAD_SUBCH, 278 ps3vram_begin_ring(priv, DOWNLOAD_SUBCH,
286 NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8); 279 NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8);
@@ -310,7 +303,7 @@ static int ps3vram_download(struct ps3_system_bus_device *dev,
310 303
311static void ps3vram_cache_evict(struct ps3_system_bus_device *dev, int entry) 304static void ps3vram_cache_evict(struct ps3_system_bus_device *dev, int entry)
312{ 305{
313 struct ps3vram_priv *priv = dev->core.driver_data; 306 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
314 struct ps3vram_cache *cache = &priv->cache; 307 struct ps3vram_cache *cache = &priv->cache;
315 308
316 if (!(cache->tags[entry].flags & CACHE_PAGE_DIRTY)) 309 if (!(cache->tags[entry].flags & CACHE_PAGE_DIRTY))
@@ -332,7 +325,7 @@ static void ps3vram_cache_evict(struct ps3_system_bus_device *dev, int entry)
332static void ps3vram_cache_load(struct ps3_system_bus_device *dev, int entry, 325static void ps3vram_cache_load(struct ps3_system_bus_device *dev, int entry,
333 unsigned int address) 326 unsigned int address)
334{ 327{
335 struct ps3vram_priv *priv = dev->core.driver_data; 328 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
336 struct ps3vram_cache *cache = &priv->cache; 329 struct ps3vram_cache *cache = &priv->cache;
337 330
338 dev_dbg(&dev->core, "Fetching %d: 0x%08x\n", entry, address); 331 dev_dbg(&dev->core, "Fetching %d: 0x%08x\n", entry, address);
@@ -352,7 +345,7 @@ static void ps3vram_cache_load(struct ps3_system_bus_device *dev, int entry,
352 345
353static void ps3vram_cache_flush(struct ps3_system_bus_device *dev) 346static void ps3vram_cache_flush(struct ps3_system_bus_device *dev)
354{ 347{
355 struct ps3vram_priv *priv = dev->core.driver_data; 348 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
356 struct ps3vram_cache *cache = &priv->cache; 349 struct ps3vram_cache *cache = &priv->cache;
357 int i; 350 int i;
358 351
@@ -366,7 +359,7 @@ static void ps3vram_cache_flush(struct ps3_system_bus_device *dev)
366static unsigned int ps3vram_cache_match(struct ps3_system_bus_device *dev, 359static unsigned int ps3vram_cache_match(struct ps3_system_bus_device *dev,
367 loff_t address) 360 loff_t address)
368{ 361{
369 struct ps3vram_priv *priv = dev->core.driver_data; 362 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
370 struct ps3vram_cache *cache = &priv->cache; 363 struct ps3vram_cache *cache = &priv->cache;
371 unsigned int base; 364 unsigned int base;
372 unsigned int offset; 365 unsigned int offset;
@@ -400,7 +393,7 @@ static unsigned int ps3vram_cache_match(struct ps3_system_bus_device *dev,
400 393
401static int ps3vram_cache_init(struct ps3_system_bus_device *dev) 394static int ps3vram_cache_init(struct ps3_system_bus_device *dev)
402{ 395{
403 struct ps3vram_priv *priv = dev->core.driver_data; 396 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
404 397
405 priv->cache.page_count = CACHE_PAGE_COUNT; 398 priv->cache.page_count = CACHE_PAGE_COUNT;
406 priv->cache.page_size = CACHE_PAGE_SIZE; 399 priv->cache.page_size = CACHE_PAGE_SIZE;
@@ -419,7 +412,7 @@ static int ps3vram_cache_init(struct ps3_system_bus_device *dev)
419 412
420static void ps3vram_cache_cleanup(struct ps3_system_bus_device *dev) 413static void ps3vram_cache_cleanup(struct ps3_system_bus_device *dev)
421{ 414{
422 struct ps3vram_priv *priv = dev->core.driver_data; 415 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
423 416
424 ps3vram_cache_flush(dev); 417 ps3vram_cache_flush(dev);
425 kfree(priv->cache.tags); 418 kfree(priv->cache.tags);
@@ -428,7 +421,7 @@ static void ps3vram_cache_cleanup(struct ps3_system_bus_device *dev)
428static int ps3vram_read(struct ps3_system_bus_device *dev, loff_t from, 421static int ps3vram_read(struct ps3_system_bus_device *dev, loff_t from,
429 size_t len, size_t *retlen, u_char *buf) 422 size_t len, size_t *retlen, u_char *buf)
430{ 423{
431 struct ps3vram_priv *priv = dev->core.driver_data; 424 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
432 unsigned int cached, count; 425 unsigned int cached, count;
433 426
434 dev_dbg(&dev->core, "%s: from=0x%08x len=0x%zx\n", __func__, 427 dev_dbg(&dev->core, "%s: from=0x%08x len=0x%zx\n", __func__,
@@ -449,8 +442,6 @@ static int ps3vram_read(struct ps3_system_bus_device *dev, loff_t from,
449 offset = (unsigned int) (from & (priv->cache.page_size - 1)); 442 offset = (unsigned int) (from & (priv->cache.page_size - 1));
450 avail = priv->cache.page_size - offset; 443 avail = priv->cache.page_size - offset;
451 444
452 mutex_lock(&priv->lock);
453
454 entry = ps3vram_cache_match(dev, from); 445 entry = ps3vram_cache_match(dev, from);
455 cached = CACHE_OFFSET + entry * priv->cache.page_size + offset; 446 cached = CACHE_OFFSET + entry * priv->cache.page_size + offset;
456 447
@@ -462,8 +453,6 @@ static int ps3vram_read(struct ps3_system_bus_device *dev, loff_t from,
462 avail = count; 453 avail = count;
463 memcpy(buf, priv->xdr_buf + cached, avail); 454 memcpy(buf, priv->xdr_buf + cached, avail);
464 455
465 mutex_unlock(&priv->lock);
466
467 buf += avail; 456 buf += avail;
468 count -= avail; 457 count -= avail;
469 from += avail; 458 from += avail;
@@ -476,7 +465,7 @@ static int ps3vram_read(struct ps3_system_bus_device *dev, loff_t from,
476static int ps3vram_write(struct ps3_system_bus_device *dev, loff_t to, 465static int ps3vram_write(struct ps3_system_bus_device *dev, loff_t to,
477 size_t len, size_t *retlen, const u_char *buf) 466 size_t len, size_t *retlen, const u_char *buf)
478{ 467{
479 struct ps3vram_priv *priv = dev->core.driver_data; 468 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
480 unsigned int cached, count; 469 unsigned int cached, count;
481 470
482 if (to >= priv->size) 471 if (to >= priv->size)
@@ -494,8 +483,6 @@ static int ps3vram_write(struct ps3_system_bus_device *dev, loff_t to,
494 offset = (unsigned int) (to & (priv->cache.page_size - 1)); 483 offset = (unsigned int) (to & (priv->cache.page_size - 1));
495 avail = priv->cache.page_size - offset; 484 avail = priv->cache.page_size - offset;
496 485
497 mutex_lock(&priv->lock);
498
499 entry = ps3vram_cache_match(dev, to); 486 entry = ps3vram_cache_match(dev, to);
500 cached = CACHE_OFFSET + entry * priv->cache.page_size + offset; 487 cached = CACHE_OFFSET + entry * priv->cache.page_size + offset;
501 488
@@ -509,8 +496,6 @@ static int ps3vram_write(struct ps3_system_bus_device *dev, loff_t to,
509 496
510 priv->cache.tags[entry].flags |= CACHE_PAGE_DIRTY; 497 priv->cache.tags[entry].flags |= CACHE_PAGE_DIRTY;
511 498
512 mutex_unlock(&priv->lock);
513
514 buf += avail; 499 buf += avail;
515 count -= avail; 500 count -= avail;
516 to += avail; 501 to += avail;
@@ -543,28 +528,26 @@ static const struct file_operations ps3vram_proc_fops = {
543 528
544static void __devinit ps3vram_proc_init(struct ps3_system_bus_device *dev) 529static void __devinit ps3vram_proc_init(struct ps3_system_bus_device *dev)
545{ 530{
546 struct ps3vram_priv *priv = dev->core.driver_data; 531 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
547 struct proc_dir_entry *pde; 532 struct proc_dir_entry *pde;
548 533
549 pde = proc_create(DEVICE_NAME, 0444, NULL, &ps3vram_proc_fops); 534 pde = proc_create_data(DEVICE_NAME, 0444, NULL, &ps3vram_proc_fops,
550 if (!pde) { 535 priv);
536 if (!pde)
551 dev_warn(&dev->core, "failed to create /proc entry\n"); 537 dev_warn(&dev->core, "failed to create /proc entry\n");
552 return;
553 }
554 pde->data = priv;
555} 538}
556 539
557static int ps3vram_make_request(struct request_queue *q, struct bio *bio) 540static struct bio *ps3vram_do_bio(struct ps3_system_bus_device *dev,
541 struct bio *bio)
558{ 542{
559 struct ps3_system_bus_device *dev = q->queuedata; 543 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
560 int write = bio_data_dir(bio) == WRITE; 544 int write = bio_data_dir(bio) == WRITE;
561 const char *op = write ? "write" : "read"; 545 const char *op = write ? "write" : "read";
562 loff_t offset = bio->bi_sector << 9; 546 loff_t offset = bio->bi_sector << 9;
563 int error = 0; 547 int error = 0;
564 struct bio_vec *bvec; 548 struct bio_vec *bvec;
565 unsigned int i; 549 unsigned int i;
566 550 struct bio *next;
567 dev_dbg(&dev->core, "%s\n", __func__);
568 551
569 bio_for_each_segment(bvec, bio, i) { 552 bio_for_each_segment(bvec, bio, i) {
570 /* PS3 is ppc64, so we don't handle highmem */ 553 /* PS3 is ppc64, so we don't handle highmem */
@@ -585,6 +568,7 @@ static int ps3vram_make_request(struct request_queue *q, struct bio *bio)
585 568
586 if (retlen != len) { 569 if (retlen != len) {
587 dev_err(&dev->core, "Short %s\n", op); 570 dev_err(&dev->core, "Short %s\n", op);
571 error = -EIO;
588 goto out; 572 goto out;
589 } 573 }
590 574
@@ -594,7 +578,35 @@ static int ps3vram_make_request(struct request_queue *q, struct bio *bio)
594 dev_dbg(&dev->core, "%s completed\n", op); 578 dev_dbg(&dev->core, "%s completed\n", op);
595 579
596out: 580out:
581 spin_lock_irq(&priv->lock);
582 bio_list_pop(&priv->list);
583 next = bio_list_peek(&priv->list);
584 spin_unlock_irq(&priv->lock);
585
597 bio_endio(bio, error); 586 bio_endio(bio, error);
587 return next;
588}
589
590static int ps3vram_make_request(struct request_queue *q, struct bio *bio)
591{
592 struct ps3_system_bus_device *dev = q->queuedata;
593 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
594 int busy;
595
596 dev_dbg(&dev->core, "%s\n", __func__);
597
598 spin_lock_irq(&priv->lock);
599 busy = !bio_list_empty(&priv->list);
600 bio_list_add(&priv->list, bio);
601 spin_unlock_irq(&priv->lock);
602
603 if (busy)
604 return 0;
605
606 do {
607 bio = ps3vram_do_bio(dev, bio);
608 } while (bio);
609
598 return 0; 610 return 0;
599} 611}
600 612
@@ -604,8 +616,8 @@ static int __devinit ps3vram_probe(struct ps3_system_bus_device *dev)
604 int error, status; 616 int error, status;
605 struct request_queue *queue; 617 struct request_queue *queue;
606 struct gendisk *gendisk; 618 struct gendisk *gendisk;
607 u64 ddr_lpar, ctrl_lpar, info_lpar, reports_lpar, ddr_size, 619 u64 ddr_size, ddr_lpar, ctrl_lpar, info_lpar, reports_lpar,
608 reports_size; 620 reports_size, xdr_lpar;
609 char *rest; 621 char *rest;
610 622
611 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 623 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
@@ -614,10 +626,9 @@ static int __devinit ps3vram_probe(struct ps3_system_bus_device *dev)
614 goto fail; 626 goto fail;
615 } 627 }
616 628
617 mutex_init(&priv->lock); 629 spin_lock_init(&priv->lock);
618 dev->core.driver_data = priv; 630 bio_list_init(&priv->list);
619 631 ps3_system_bus_set_drvdata(dev, priv);
620 priv = dev->core.driver_data;
621 632
622 /* Allocate XDR buffer (1MiB aligned) */ 633 /* Allocate XDR buffer (1MiB aligned) */
623 priv->xdr_buf = (void *)__get_free_pages(GFP_KERNEL, 634 priv->xdr_buf = (void *)__get_free_pages(GFP_KERNEL,
@@ -636,7 +647,7 @@ static int __devinit ps3vram_probe(struct ps3_system_bus_device *dev)
636 if (ps3_open_hv_device(dev)) { 647 if (ps3_open_hv_device(dev)) {
637 dev_err(&dev->core, "ps3_open_hv_device failed\n"); 648 dev_err(&dev->core, "ps3_open_hv_device failed\n");
638 error = -EAGAIN; 649 error = -EAGAIN;
639 goto out_close_gpu; 650 goto out_free_xdr_buf;
640 } 651 }
641 652
642 /* Request memory */ 653 /* Request memory */
@@ -660,7 +671,7 @@ static int __devinit ps3vram_probe(struct ps3_system_bus_device *dev)
660 dev_err(&dev->core, "lv1_gpu_memory_allocate failed %d\n", 671 dev_err(&dev->core, "lv1_gpu_memory_allocate failed %d\n",
661 status); 672 status);
662 error = -ENOMEM; 673 error = -ENOMEM;
663 goto out_free_xdr_buf; 674 goto out_close_gpu;
664 } 675 }
665 676
666 /* Request context */ 677 /* Request context */
@@ -676,9 +687,11 @@ static int __devinit ps3vram_probe(struct ps3_system_bus_device *dev)
676 } 687 }
677 688
678 /* Map XDR buffer to RSX */ 689 /* Map XDR buffer to RSX */
690 xdr_lpar = ps3_mm_phys_to_lpar(__pa(priv->xdr_buf));
679 status = lv1_gpu_context_iomap(priv->context_handle, XDR_IOIF, 691 status = lv1_gpu_context_iomap(priv->context_handle, XDR_IOIF,
680 ps3_mm_phys_to_lpar(__pa(priv->xdr_buf)), 692 xdr_lpar, XDR_BUF_SIZE,
681 XDR_BUF_SIZE, 0); 693 CBE_IOPTE_PP_W | CBE_IOPTE_PP_R |
694 CBE_IOPTE_M);
682 if (status) { 695 if (status) {
683 dev_err(&dev->core, "lv1_gpu_context_iomap failed %d\n", 696 dev_err(&dev->core, "lv1_gpu_context_iomap failed %d\n",
684 status); 697 status);
@@ -686,19 +699,11 @@ static int __devinit ps3vram_probe(struct ps3_system_bus_device *dev)
686 goto out_free_context; 699 goto out_free_context;
687 } 700 }
688 701
689 priv->ddr_base = ioremap_flags(ddr_lpar, ddr_size, _PAGE_NO_CACHE);
690
691 if (!priv->ddr_base) {
692 dev_err(&dev->core, "ioremap DDR failed\n");
693 error = -ENOMEM;
694 goto out_free_context;
695 }
696
697 priv->ctrl = ioremap(ctrl_lpar, 64 * 1024); 702 priv->ctrl = ioremap(ctrl_lpar, 64 * 1024);
698 if (!priv->ctrl) { 703 if (!priv->ctrl) {
699 dev_err(&dev->core, "ioremap CTRL failed\n"); 704 dev_err(&dev->core, "ioremap CTRL failed\n");
700 error = -ENOMEM; 705 error = -ENOMEM;
701 goto out_unmap_vram; 706 goto out_unmap_context;
702 } 707 }
703 708
704 priv->reports = ioremap(reports_lpar, reports_size); 709 priv->reports = ioremap(reports_lpar, reports_size);
@@ -775,8 +780,9 @@ out_unmap_reports:
775 iounmap(priv->reports); 780 iounmap(priv->reports);
776out_unmap_ctrl: 781out_unmap_ctrl:
777 iounmap(priv->ctrl); 782 iounmap(priv->ctrl);
778out_unmap_vram: 783out_unmap_context:
779 iounmap(priv->ddr_base); 784 lv1_gpu_context_iomap(priv->context_handle, XDR_IOIF, xdr_lpar,
785 XDR_BUF_SIZE, CBE_IOPTE_M);
780out_free_context: 786out_free_context:
781 lv1_gpu_context_free(priv->context_handle); 787 lv1_gpu_context_free(priv->context_handle);
782out_free_memory: 788out_free_memory:
@@ -787,14 +793,14 @@ out_free_xdr_buf:
787 free_pages((unsigned long) priv->xdr_buf, get_order(XDR_BUF_SIZE)); 793 free_pages((unsigned long) priv->xdr_buf, get_order(XDR_BUF_SIZE));
788fail_free_priv: 794fail_free_priv:
789 kfree(priv); 795 kfree(priv);
790 dev->core.driver_data = NULL; 796 ps3_system_bus_set_drvdata(dev, NULL);
791fail: 797fail:
792 return error; 798 return error;
793} 799}
794 800
795static int ps3vram_remove(struct ps3_system_bus_device *dev) 801static int ps3vram_remove(struct ps3_system_bus_device *dev)
796{ 802{
797 struct ps3vram_priv *priv = dev->core.driver_data; 803 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
798 804
799 del_gendisk(priv->gendisk); 805 del_gendisk(priv->gendisk);
800 put_disk(priv->gendisk); 806 put_disk(priv->gendisk);
@@ -803,13 +809,15 @@ static int ps3vram_remove(struct ps3_system_bus_device *dev)
803 ps3vram_cache_cleanup(dev); 809 ps3vram_cache_cleanup(dev);
804 iounmap(priv->reports); 810 iounmap(priv->reports);
805 iounmap(priv->ctrl); 811 iounmap(priv->ctrl);
806 iounmap(priv->ddr_base); 812 lv1_gpu_context_iomap(priv->context_handle, XDR_IOIF,
813 ps3_mm_phys_to_lpar(__pa(priv->xdr_buf)),
814 XDR_BUF_SIZE, CBE_IOPTE_M);
807 lv1_gpu_context_free(priv->context_handle); 815 lv1_gpu_context_free(priv->context_handle);
808 lv1_gpu_memory_free(priv->memory_handle); 816 lv1_gpu_memory_free(priv->memory_handle);
809 ps3_close_hv_device(dev); 817 ps3_close_hv_device(dev);
810 free_pages((unsigned long) priv->xdr_buf, get_order(XDR_BUF_SIZE)); 818 free_pages((unsigned long) priv->xdr_buf, get_order(XDR_BUF_SIZE));
811 kfree(priv); 819 kfree(priv);
812 dev->core.driver_data = NULL; 820 ps3_system_bus_set_drvdata(dev, NULL);
813 return 0; 821 return 0;
814} 822}
815 823
diff --git a/drivers/block/sunvdc.c b/drivers/block/sunvdc.c
index 5861e33efe63..cbfd9c0aef03 100644
--- a/drivers/block/sunvdc.c
+++ b/drivers/block/sunvdc.c
@@ -212,11 +212,6 @@ static void vdc_end_special(struct vdc_port *port, struct vio_disk_desc *desc)
212 vdc_finish(&port->vio, -err, WAITING_FOR_GEN_CMD); 212 vdc_finish(&port->vio, -err, WAITING_FOR_GEN_CMD);
213} 213}
214 214
215static void vdc_end_request(struct request *req, int error, int num_sectors)
216{
217 __blk_end_request(req, error, num_sectors << 9);
218}
219
220static void vdc_end_one(struct vdc_port *port, struct vio_dring_state *dr, 215static void vdc_end_one(struct vdc_port *port, struct vio_dring_state *dr,
221 unsigned int index) 216 unsigned int index)
222{ 217{
@@ -239,7 +234,7 @@ static void vdc_end_one(struct vdc_port *port, struct vio_dring_state *dr,
239 234
240 rqe->req = NULL; 235 rqe->req = NULL;
241 236
242 vdc_end_request(req, (desc->status ? -EIO : 0), desc->size >> 9); 237 __blk_end_request(req, (desc->status ? -EIO : 0), desc->size);
243 238
244 if (blk_queue_stopped(port->disk->queue)) 239 if (blk_queue_stopped(port->disk->queue))
245 blk_start_queue(port->disk->queue); 240 blk_start_queue(port->disk->queue);
@@ -421,7 +416,7 @@ static int __send_request(struct request *req)
421 desc->slice = 0; 416 desc->slice = 0;
422 } 417 }
423 desc->status = ~0; 418 desc->status = ~0;
424 desc->offset = (req->sector << 9) / port->vdisk_block_size; 419 desc->offset = (blk_rq_pos(req) << 9) / port->vdisk_block_size;
425 desc->size = len; 420 desc->size = len;
426 desc->ncookies = err; 421 desc->ncookies = err;
427 422
@@ -446,14 +441,13 @@ out:
446static void do_vdc_request(struct request_queue *q) 441static void do_vdc_request(struct request_queue *q)
447{ 442{
448 while (1) { 443 while (1) {
449 struct request *req = elv_next_request(q); 444 struct request *req = blk_fetch_request(q);
450 445
451 if (!req) 446 if (!req)
452 break; 447 break;
453 448
454 blkdev_dequeue_request(req);
455 if (__send_request(req) < 0) 449 if (__send_request(req) < 0)
456 vdc_end_request(req, -EIO, req->hard_nr_sectors); 450 __blk_end_request_all(req, -EIO);
457 } 451 }
458} 452}
459 453
diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index d22cc3856937..cf7877fb8a7d 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -514,7 +514,7 @@ static int floppy_read_sectors(struct floppy_state *fs,
514 ret = swim_read_sector(fs, side, track, sector, 514 ret = swim_read_sector(fs, side, track, sector,
515 buffer); 515 buffer);
516 if (try-- == 0) 516 if (try-- == 0)
517 return -1; 517 return -EIO;
518 } while (ret != 512); 518 } while (ret != 512);
519 519
520 buffer += ret; 520 buffer += ret;
@@ -528,45 +528,31 @@ static void redo_fd_request(struct request_queue *q)
528 struct request *req; 528 struct request *req;
529 struct floppy_state *fs; 529 struct floppy_state *fs;
530 530
531 while ((req = elv_next_request(q))) { 531 req = blk_fetch_request(q);
532 while (req) {
533 int err = -EIO;
532 534
533 fs = req->rq_disk->private_data; 535 fs = req->rq_disk->private_data;
534 if (req->sector < 0 || req->sector >= fs->total_secs) { 536 if (blk_rq_pos(req) >= fs->total_secs)
535 end_request(req, 0); 537 goto done;
536 continue; 538 if (!fs->disk_in)
537 } 539 goto done;
538 if (req->current_nr_sectors == 0) { 540 if (rq_data_dir(req) == WRITE && fs->write_protected)
539 end_request(req, 1); 541 goto done;
540 continue; 542
541 }
542 if (!fs->disk_in) {
543 end_request(req, 0);
544 continue;
545 }
546 if (rq_data_dir(req) == WRITE) {
547 if (fs->write_protected) {
548 end_request(req, 0);
549 continue;
550 }
551 }
552 switch (rq_data_dir(req)) { 543 switch (rq_data_dir(req)) {
553 case WRITE: 544 case WRITE:
554 /* NOT IMPLEMENTED */ 545 /* NOT IMPLEMENTED */
555 end_request(req, 0);
556 break; 546 break;
557 case READ: 547 case READ:
558 if (floppy_read_sectors(fs, req->sector, 548 err = floppy_read_sectors(fs, blk_rq_pos(req),
559 req->current_nr_sectors, 549 blk_rq_cur_sectors(req),
560 req->buffer)) { 550 req->buffer);
561 end_request(req, 0);
562 continue;
563 }
564 req->nr_sectors -= req->current_nr_sectors;
565 req->sector += req->current_nr_sectors;
566 req->buffer += req->current_nr_sectors * 512;
567 end_request(req, 1);
568 break; 551 break;
569 } 552 }
553 done:
554 if (!__blk_end_request_cur(req, err))
555 req = blk_fetch_request(q);
570 } 556 }
571} 557}
572 558
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index 612965307ba0..80df93e3cdd0 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -251,6 +251,20 @@ static int floppy_release(struct gendisk *disk, fmode_t mode);
251static int floppy_check_change(struct gendisk *disk); 251static int floppy_check_change(struct gendisk *disk);
252static int floppy_revalidate(struct gendisk *disk); 252static int floppy_revalidate(struct gendisk *disk);
253 253
254static bool swim3_end_request(int err, unsigned int nr_bytes)
255{
256 if (__blk_end_request(fd_req, err, nr_bytes))
257 return true;
258
259 fd_req = NULL;
260 return false;
261}
262
263static bool swim3_end_request_cur(int err)
264{
265 return swim3_end_request(err, blk_rq_cur_bytes(fd_req));
266}
267
254static void swim3_select(struct floppy_state *fs, int sel) 268static void swim3_select(struct floppy_state *fs, int sel)
255{ 269{
256 struct swim3 __iomem *sw = fs->swim3; 270 struct swim3 __iomem *sw = fs->swim3;
@@ -310,25 +324,27 @@ static void start_request(struct floppy_state *fs)
310 wake_up(&fs->wait); 324 wake_up(&fs->wait);
311 return; 325 return;
312 } 326 }
313 while (fs->state == idle && (req = elv_next_request(swim3_queue))) { 327 while (fs->state == idle) {
328 if (!fd_req) {
329 fd_req = blk_fetch_request(swim3_queue);
330 if (!fd_req)
331 break;
332 }
333 req = fd_req;
314#if 0 334#if 0
315 printk("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%ld buf=%p\n", 335 printk("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%u buf=%p\n",
316 req->rq_disk->disk_name, req->cmd, 336 req->rq_disk->disk_name, req->cmd,
317 (long)req->sector, req->nr_sectors, req->buffer); 337 (long)blk_rq_pos(req), blk_rq_sectors(req), req->buffer);
318 printk(" errors=%d current_nr_sectors=%ld\n", 338 printk(" errors=%d current_nr_sectors=%u\n",
319 req->errors, req->current_nr_sectors); 339 req->errors, blk_rq_cur_sectors(req));
320#endif 340#endif
321 341
322 if (req->sector < 0 || req->sector >= fs->total_secs) { 342 if (blk_rq_pos(req) >= fs->total_secs) {
323 end_request(req, 0); 343 swim3_end_request_cur(-EIO);
324 continue;
325 }
326 if (req->current_nr_sectors == 0) {
327 end_request(req, 1);
328 continue; 344 continue;
329 } 345 }
330 if (fs->ejected) { 346 if (fs->ejected) {
331 end_request(req, 0); 347 swim3_end_request_cur(-EIO);
332 continue; 348 continue;
333 } 349 }
334 350
@@ -336,18 +352,19 @@ static void start_request(struct floppy_state *fs)
336 if (fs->write_prot < 0) 352 if (fs->write_prot < 0)
337 fs->write_prot = swim3_readbit(fs, WRITE_PROT); 353 fs->write_prot = swim3_readbit(fs, WRITE_PROT);
338 if (fs->write_prot) { 354 if (fs->write_prot) {
339 end_request(req, 0); 355 swim3_end_request_cur(-EIO);
340 continue; 356 continue;
341 } 357 }
342 } 358 }
343 359
344 /* Do not remove the cast. req->sector is now a sector_t and 360 /* Do not remove the cast. blk_rq_pos(req) is now a
345 * can be 64 bits, but it will never go past 32 bits for this 361 * sector_t and can be 64 bits, but it will never go
346 * driver anyway, so we can safely cast it down and not have 362 * past 32 bits for this driver anyway, so we can
347 * to do a 64/32 division 363 * safely cast it down and not have to do a 64/32
364 * division
348 */ 365 */
349 fs->req_cyl = ((long)req->sector) / fs->secpercyl; 366 fs->req_cyl = ((long)blk_rq_pos(req)) / fs->secpercyl;
350 x = ((long)req->sector) % fs->secpercyl; 367 x = ((long)blk_rq_pos(req)) % fs->secpercyl;
351 fs->head = x / fs->secpertrack; 368 fs->head = x / fs->secpertrack;
352 fs->req_sector = x % fs->secpertrack + 1; 369 fs->req_sector = x % fs->secpertrack + 1;
353 fd_req = req; 370 fd_req = req;
@@ -424,7 +441,7 @@ static inline void setup_transfer(struct floppy_state *fs)
424 struct dbdma_cmd *cp = fs->dma_cmd; 441 struct dbdma_cmd *cp = fs->dma_cmd;
425 struct dbdma_regs __iomem *dr = fs->dma; 442 struct dbdma_regs __iomem *dr = fs->dma;
426 443
427 if (fd_req->current_nr_sectors <= 0) { 444 if (blk_rq_cur_sectors(fd_req) <= 0) {
428 printk(KERN_ERR "swim3: transfer 0 sectors?\n"); 445 printk(KERN_ERR "swim3: transfer 0 sectors?\n");
429 return; 446 return;
430 } 447 }
@@ -432,8 +449,8 @@ static inline void setup_transfer(struct floppy_state *fs)
432 n = 1; 449 n = 1;
433 else { 450 else {
434 n = fs->secpertrack - fs->req_sector + 1; 451 n = fs->secpertrack - fs->req_sector + 1;
435 if (n > fd_req->current_nr_sectors) 452 if (n > blk_rq_cur_sectors(fd_req))
436 n = fd_req->current_nr_sectors; 453 n = blk_rq_cur_sectors(fd_req);
437 } 454 }
438 fs->scount = n; 455 fs->scount = n;
439 swim3_select(fs, fs->head? READ_DATA_1: READ_DATA_0); 456 swim3_select(fs, fs->head? READ_DATA_1: READ_DATA_0);
@@ -508,7 +525,7 @@ static void act(struct floppy_state *fs)
508 case do_transfer: 525 case do_transfer:
509 if (fs->cur_cyl != fs->req_cyl) { 526 if (fs->cur_cyl != fs->req_cyl) {
510 if (fs->retries > 5) { 527 if (fs->retries > 5) {
511 end_request(fd_req, 0); 528 swim3_end_request_cur(-EIO);
512 fs->state = idle; 529 fs->state = idle;
513 return; 530 return;
514 } 531 }
@@ -540,7 +557,7 @@ static void scan_timeout(unsigned long data)
540 out_8(&sw->intr_enable, 0); 557 out_8(&sw->intr_enable, 0);
541 fs->cur_cyl = -1; 558 fs->cur_cyl = -1;
542 if (fs->retries > 5) { 559 if (fs->retries > 5) {
543 end_request(fd_req, 0); 560 swim3_end_request_cur(-EIO);
544 fs->state = idle; 561 fs->state = idle;
545 start_request(fs); 562 start_request(fs);
546 } else { 563 } else {
@@ -559,7 +576,7 @@ static void seek_timeout(unsigned long data)
559 out_8(&sw->select, RELAX); 576 out_8(&sw->select, RELAX);
560 out_8(&sw->intr_enable, 0); 577 out_8(&sw->intr_enable, 0);
561 printk(KERN_ERR "swim3: seek timeout\n"); 578 printk(KERN_ERR "swim3: seek timeout\n");
562 end_request(fd_req, 0); 579 swim3_end_request_cur(-EIO);
563 fs->state = idle; 580 fs->state = idle;
564 start_request(fs); 581 start_request(fs);
565} 582}
@@ -583,7 +600,7 @@ static void settle_timeout(unsigned long data)
583 return; 600 return;
584 } 601 }
585 printk(KERN_ERR "swim3: seek settle timeout\n"); 602 printk(KERN_ERR "swim3: seek settle timeout\n");
586 end_request(fd_req, 0); 603 swim3_end_request_cur(-EIO);
587 fs->state = idle; 604 fs->state = idle;
588 start_request(fs); 605 start_request(fs);
589} 606}
@@ -593,8 +610,6 @@ static void xfer_timeout(unsigned long data)
593 struct floppy_state *fs = (struct floppy_state *) data; 610 struct floppy_state *fs = (struct floppy_state *) data;
594 struct swim3 __iomem *sw = fs->swim3; 611 struct swim3 __iomem *sw = fs->swim3;
595 struct dbdma_regs __iomem *dr = fs->dma; 612 struct dbdma_regs __iomem *dr = fs->dma;
596 struct dbdma_cmd *cp = fs->dma_cmd;
597 unsigned long s;
598 int n; 613 int n;
599 614
600 fs->timeout_pending = 0; 615 fs->timeout_pending = 0;
@@ -605,17 +620,10 @@ static void xfer_timeout(unsigned long data)
605 out_8(&sw->intr_enable, 0); 620 out_8(&sw->intr_enable, 0);
606 out_8(&sw->control_bic, WRITE_SECTORS | DO_ACTION); 621 out_8(&sw->control_bic, WRITE_SECTORS | DO_ACTION);
607 out_8(&sw->select, RELAX); 622 out_8(&sw->select, RELAX);
608 if (rq_data_dir(fd_req) == WRITE)
609 ++cp;
610 if (ld_le16(&cp->xfer_status) != 0)
611 s = fs->scount - ((ld_le16(&cp->res_count) + 511) >> 9);
612 else
613 s = 0;
614 fd_req->sector += s;
615 fd_req->current_nr_sectors -= s;
616 printk(KERN_ERR "swim3: timeout %sing sector %ld\n", 623 printk(KERN_ERR "swim3: timeout %sing sector %ld\n",
617 (rq_data_dir(fd_req)==WRITE? "writ": "read"), (long)fd_req->sector); 624 (rq_data_dir(fd_req)==WRITE? "writ": "read"),
618 end_request(fd_req, 0); 625 (long)blk_rq_pos(fd_req));
626 swim3_end_request_cur(-EIO);
619 fs->state = idle; 627 fs->state = idle;
620 start_request(fs); 628 start_request(fs);
621} 629}
@@ -646,7 +654,7 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id)
646 printk(KERN_ERR "swim3: seen sector but cyl=ff?\n"); 654 printk(KERN_ERR "swim3: seen sector but cyl=ff?\n");
647 fs->cur_cyl = -1; 655 fs->cur_cyl = -1;
648 if (fs->retries > 5) { 656 if (fs->retries > 5) {
649 end_request(fd_req, 0); 657 swim3_end_request_cur(-EIO);
650 fs->state = idle; 658 fs->state = idle;
651 start_request(fs); 659 start_request(fs);
652 } else { 660 } else {
@@ -719,9 +727,7 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id)
719 if (intr & ERROR_INTR) { 727 if (intr & ERROR_INTR) {
720 n = fs->scount - 1 - resid / 512; 728 n = fs->scount - 1 - resid / 512;
721 if (n > 0) { 729 if (n > 0) {
722 fd_req->sector += n; 730 blk_update_request(fd_req, 0, n << 9);
723 fd_req->current_nr_sectors -= n;
724 fd_req->buffer += n * 512;
725 fs->req_sector += n; 731 fs->req_sector += n;
726 } 732 }
727 if (fs->retries < 5) { 733 if (fs->retries < 5) {
@@ -730,8 +736,8 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id)
730 } else { 736 } else {
731 printk("swim3: error %sing block %ld (err=%x)\n", 737 printk("swim3: error %sing block %ld (err=%x)\n",
732 rq_data_dir(fd_req) == WRITE? "writ": "read", 738 rq_data_dir(fd_req) == WRITE? "writ": "read",
733 (long)fd_req->sector, err); 739 (long)blk_rq_pos(fd_req), err);
734 end_request(fd_req, 0); 740 swim3_end_request_cur(-EIO);
735 fs->state = idle; 741 fs->state = idle;
736 } 742 }
737 } else { 743 } else {
@@ -740,18 +746,12 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id)
740 printk(KERN_ERR "swim3: fd dma: stat=%x resid=%d\n", stat, resid); 746 printk(KERN_ERR "swim3: fd dma: stat=%x resid=%d\n", stat, resid);
741 printk(KERN_ERR " state=%d, dir=%x, intr=%x, err=%x\n", 747 printk(KERN_ERR " state=%d, dir=%x, intr=%x, err=%x\n",
742 fs->state, rq_data_dir(fd_req), intr, err); 748 fs->state, rq_data_dir(fd_req), intr, err);
743 end_request(fd_req, 0); 749 swim3_end_request_cur(-EIO);
744 fs->state = idle; 750 fs->state = idle;
745 start_request(fs); 751 start_request(fs);
746 break; 752 break;
747 } 753 }
748 fd_req->sector += fs->scount; 754 if (swim3_end_request(0, fs->scount << 9)) {
749 fd_req->current_nr_sectors -= fs->scount;
750 fd_req->buffer += fs->scount * 512;
751 if (fd_req->current_nr_sectors <= 0) {
752 end_request(fd_req, 1);
753 fs->state = idle;
754 } else {
755 fs->req_sector += fs->scount; 755 fs->req_sector += fs->scount;
756 if (fs->req_sector > fs->secpertrack) { 756 if (fs->req_sector > fs->secpertrack) {
757 fs->req_sector -= fs->secpertrack; 757 fs->req_sector -= fs->secpertrack;
@@ -761,7 +761,8 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id)
761 } 761 }
762 } 762 }
763 act(fs); 763 act(fs);
764 } 764 } else
765 fs->state = idle;
765 } 766 }
766 if (fs->state == idle) 767 if (fs->state == idle)
767 start_request(fs); 768 start_request(fs);
diff --git a/drivers/block/sx8.c b/drivers/block/sx8.c
index ff0448e4bf03..da403b6a7f43 100644
--- a/drivers/block/sx8.c
+++ b/drivers/block/sx8.c
@@ -749,8 +749,7 @@ static inline void carm_end_request_queued(struct carm_host *host,
749 struct request *req = crq->rq; 749 struct request *req = crq->rq;
750 int rc; 750 int rc;
751 751
752 rc = __blk_end_request(req, error, blk_rq_bytes(req)); 752 __blk_end_request_all(req, error);
753 assert(rc == 0);
754 753
755 rc = carm_put_request(host, crq); 754 rc = carm_put_request(host, crq);
756 assert(rc == 0); 755 assert(rc == 0);
@@ -811,12 +810,10 @@ static void carm_oob_rq_fn(struct request_queue *q)
811 810
812 while (1) { 811 while (1) {
813 DPRINTK("get req\n"); 812 DPRINTK("get req\n");
814 rq = elv_next_request(q); 813 rq = blk_fetch_request(q);
815 if (!rq) 814 if (!rq)
816 break; 815 break;
817 816
818 blkdev_dequeue_request(rq);
819
820 crq = rq->special; 817 crq = rq->special;
821 assert(crq != NULL); 818 assert(crq != NULL);
822 assert(crq->rq == rq); 819 assert(crq->rq == rq);
@@ -847,7 +844,7 @@ static void carm_rq_fn(struct request_queue *q)
847 844
848queue_one_request: 845queue_one_request:
849 VPRINTK("get req\n"); 846 VPRINTK("get req\n");
850 rq = elv_next_request(q); 847 rq = blk_peek_request(q);
851 if (!rq) 848 if (!rq)
852 return; 849 return;
853 850
@@ -858,7 +855,7 @@ queue_one_request:
858 } 855 }
859 crq->rq = rq; 856 crq->rq = rq;
860 857
861 blkdev_dequeue_request(rq); 858 blk_start_request(rq);
862 859
863 if (rq_data_dir(rq) == WRITE) { 860 if (rq_data_dir(rq) == WRITE) {
864 writing = 1; 861 writing = 1;
@@ -904,10 +901,10 @@ queue_one_request:
904 msg->sg_count = n_elem; 901 msg->sg_count = n_elem;
905 msg->sg_type = SGT_32BIT; 902 msg->sg_type = SGT_32BIT;
906 msg->handle = cpu_to_le32(TAG_ENCODE(crq->tag)); 903 msg->handle = cpu_to_le32(TAG_ENCODE(crq->tag));
907 msg->lba = cpu_to_le32(rq->sector & 0xffffffff); 904 msg->lba = cpu_to_le32(blk_rq_pos(rq) & 0xffffffff);
908 tmp = (rq->sector >> 16) >> 16; 905 tmp = (blk_rq_pos(rq) >> 16) >> 16;
909 msg->lba_high = cpu_to_le16( (u16) tmp ); 906 msg->lba_high = cpu_to_le16( (u16) tmp );
910 msg->lba_count = cpu_to_le16(rq->nr_sectors); 907 msg->lba_count = cpu_to_le16(blk_rq_sectors(rq));
911 908
912 msg_size = sizeof(struct carm_msg_rw) - sizeof(msg->sg); 909 msg_size = sizeof(struct carm_msg_rw) - sizeof(msg->sg);
913 for (i = 0; i < n_elem; i++) { 910 for (i = 0; i < n_elem; i++) {
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index 689cd27ac890..cc54473b8e77 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -360,8 +360,7 @@ static void ub_cmd_build_block(struct ub_dev *sc, struct ub_lun *lun,
360static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun, 360static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
361 struct ub_scsi_cmd *cmd, struct ub_request *urq); 361 struct ub_scsi_cmd *cmd, struct ub_request *urq);
362static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd); 362static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd);
363static void ub_end_rq(struct request *rq, unsigned int status, 363static void ub_end_rq(struct request *rq, unsigned int status);
364 unsigned int cmd_len);
365static int ub_rw_cmd_retry(struct ub_dev *sc, struct ub_lun *lun, 364static int ub_rw_cmd_retry(struct ub_dev *sc, struct ub_lun *lun,
366 struct ub_request *urq, struct ub_scsi_cmd *cmd); 365 struct ub_request *urq, struct ub_scsi_cmd *cmd);
367static int ub_submit_scsi(struct ub_dev *sc, struct ub_scsi_cmd *cmd); 366static int ub_submit_scsi(struct ub_dev *sc, struct ub_scsi_cmd *cmd);
@@ -627,7 +626,7 @@ static void ub_request_fn(struct request_queue *q)
627 struct ub_lun *lun = q->queuedata; 626 struct ub_lun *lun = q->queuedata;
628 struct request *rq; 627 struct request *rq;
629 628
630 while ((rq = elv_next_request(q)) != NULL) { 629 while ((rq = blk_peek_request(q)) != NULL) {
631 if (ub_request_fn_1(lun, rq) != 0) { 630 if (ub_request_fn_1(lun, rq) != 0) {
632 blk_stop_queue(q); 631 blk_stop_queue(q);
633 break; 632 break;
@@ -643,14 +642,14 @@ static int ub_request_fn_1(struct ub_lun *lun, struct request *rq)
643 int n_elem; 642 int n_elem;
644 643
645 if (atomic_read(&sc->poison)) { 644 if (atomic_read(&sc->poison)) {
646 blkdev_dequeue_request(rq); 645 blk_start_request(rq);
647 ub_end_rq(rq, DID_NO_CONNECT << 16, blk_rq_bytes(rq)); 646 ub_end_rq(rq, DID_NO_CONNECT << 16);
648 return 0; 647 return 0;
649 } 648 }
650 649
651 if (lun->changed && !blk_pc_request(rq)) { 650 if (lun->changed && !blk_pc_request(rq)) {
652 blkdev_dequeue_request(rq); 651 blk_start_request(rq);
653 ub_end_rq(rq, SAM_STAT_CHECK_CONDITION, blk_rq_bytes(rq)); 652 ub_end_rq(rq, SAM_STAT_CHECK_CONDITION);
654 return 0; 653 return 0;
655 } 654 }
656 655
@@ -660,7 +659,7 @@ static int ub_request_fn_1(struct ub_lun *lun, struct request *rq)
660 return -1; 659 return -1;
661 memset(cmd, 0, sizeof(struct ub_scsi_cmd)); 660 memset(cmd, 0, sizeof(struct ub_scsi_cmd));
662 661
663 blkdev_dequeue_request(rq); 662 blk_start_request(rq);
664 663
665 urq = &lun->urq; 664 urq = &lun->urq;
666 memset(urq, 0, sizeof(struct ub_request)); 665 memset(urq, 0, sizeof(struct ub_request));
@@ -702,7 +701,7 @@ static int ub_request_fn_1(struct ub_lun *lun, struct request *rq)
702 701
703drop: 702drop:
704 ub_put_cmd(lun, cmd); 703 ub_put_cmd(lun, cmd);
705 ub_end_rq(rq, DID_ERROR << 16, blk_rq_bytes(rq)); 704 ub_end_rq(rq, DID_ERROR << 16);
706 return 0; 705 return 0;
707} 706}
708 707
@@ -723,11 +722,11 @@ static void ub_cmd_build_block(struct ub_dev *sc, struct ub_lun *lun,
723 /* 722 /*
724 * build the command 723 * build the command
725 * 724 *
726 * The call to blk_queue_hardsect_size() guarantees that request 725 * The call to blk_queue_logical_block_size() guarantees that request
727 * is aligned, but it is given in terms of 512 byte units, always. 726 * is aligned, but it is given in terms of 512 byte units, always.
728 */ 727 */
729 block = rq->sector >> lun->capacity.bshift; 728 block = blk_rq_pos(rq) >> lun->capacity.bshift;
730 nblks = rq->nr_sectors >> lun->capacity.bshift; 729 nblks = blk_rq_sectors(rq) >> lun->capacity.bshift;
731 730
732 cmd->cdb[0] = (cmd->dir == UB_DIR_READ)? READ_10: WRITE_10; 731 cmd->cdb[0] = (cmd->dir == UB_DIR_READ)? READ_10: WRITE_10;
733 /* 10-byte uses 4 bytes of LBA: 2147483648KB, 2097152MB, 2048GB */ 732 /* 10-byte uses 4 bytes of LBA: 2147483648KB, 2097152MB, 2048GB */
@@ -739,7 +738,7 @@ static void ub_cmd_build_block(struct ub_dev *sc, struct ub_lun *lun,
739 cmd->cdb[8] = nblks; 738 cmd->cdb[8] = nblks;
740 cmd->cdb_len = 10; 739 cmd->cdb_len = 10;
741 740
742 cmd->len = rq->nr_sectors * 512; 741 cmd->len = blk_rq_bytes(rq);
743} 742}
744 743
745static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun, 744static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
@@ -747,7 +746,7 @@ static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
747{ 746{
748 struct request *rq = urq->rq; 747 struct request *rq = urq->rq;
749 748
750 if (rq->data_len == 0) { 749 if (blk_rq_bytes(rq) == 0) {
751 cmd->dir = UB_DIR_NONE; 750 cmd->dir = UB_DIR_NONE;
752 } else { 751 } else {
753 if (rq_data_dir(rq) == WRITE) 752 if (rq_data_dir(rq) == WRITE)
@@ -762,7 +761,7 @@ static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
762 memcpy(&cmd->cdb, rq->cmd, rq->cmd_len); 761 memcpy(&cmd->cdb, rq->cmd, rq->cmd_len);
763 cmd->cdb_len = rq->cmd_len; 762 cmd->cdb_len = rq->cmd_len;
764 763
765 cmd->len = rq->data_len; 764 cmd->len = blk_rq_bytes(rq);
766 765
767 /* 766 /*
768 * To reapply this to every URB is not as incorrect as it looks. 767 * To reapply this to every URB is not as incorrect as it looks.
@@ -777,16 +776,15 @@ static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
777 struct ub_request *urq = cmd->back; 776 struct ub_request *urq = cmd->back;
778 struct request *rq; 777 struct request *rq;
779 unsigned int scsi_status; 778 unsigned int scsi_status;
780 unsigned int cmd_len;
781 779
782 rq = urq->rq; 780 rq = urq->rq;
783 781
784 if (cmd->error == 0) { 782 if (cmd->error == 0) {
785 if (blk_pc_request(rq)) { 783 if (blk_pc_request(rq)) {
786 if (cmd->act_len >= rq->data_len) 784 if (cmd->act_len >= rq->resid_len)
787 rq->data_len = 0; 785 rq->resid_len = 0;
788 else 786 else
789 rq->data_len -= cmd->act_len; 787 rq->resid_len -= cmd->act_len;
790 scsi_status = 0; 788 scsi_status = 0;
791 } else { 789 } else {
792 if (cmd->act_len != cmd->len) { 790 if (cmd->act_len != cmd->len) {
@@ -818,17 +816,14 @@ static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
818 816
819 urq->rq = NULL; 817 urq->rq = NULL;
820 818
821 cmd_len = cmd->len;
822 ub_put_cmd(lun, cmd); 819 ub_put_cmd(lun, cmd);
823 ub_end_rq(rq, scsi_status, cmd_len); 820 ub_end_rq(rq, scsi_status);
824 blk_start_queue(lun->disk->queue); 821 blk_start_queue(lun->disk->queue);
825} 822}
826 823
827static void ub_end_rq(struct request *rq, unsigned int scsi_status, 824static void ub_end_rq(struct request *rq, unsigned int scsi_status)
828 unsigned int cmd_len)
829{ 825{
830 int error; 826 int error;
831 long rqlen;
832 827
833 if (scsi_status == 0) { 828 if (scsi_status == 0) {
834 error = 0; 829 error = 0;
@@ -836,12 +831,7 @@ static void ub_end_rq(struct request *rq, unsigned int scsi_status,
836 error = -EIO; 831 error = -EIO;
837 rq->errors = scsi_status; 832 rq->errors = scsi_status;
838 } 833 }
839 rqlen = blk_rq_bytes(rq); /* Oddly enough, this is the residue. */ 834 __blk_end_request_all(rq, error);
840 if (__blk_end_request(rq, error, cmd_len)) {
841 printk(KERN_WARNING DRV_NAME
842 ": __blk_end_request blew, %s-cmd total %u rqlen %ld\n",
843 blk_pc_request(rq)? "pc": "fs", cmd_len, rqlen);
844 }
845} 835}
846 836
847static int ub_rw_cmd_retry(struct ub_dev *sc, struct ub_lun *lun, 837static int ub_rw_cmd_retry(struct ub_dev *sc, struct ub_lun *lun,
@@ -1759,7 +1749,7 @@ static int ub_bd_revalidate(struct gendisk *disk)
1759 ub_revalidate(lun->udev, lun); 1749 ub_revalidate(lun->udev, lun);
1760 1750
1761 /* XXX Support sector size switching like in sr.c */ 1751 /* XXX Support sector size switching like in sr.c */
1762 blk_queue_hardsect_size(disk->queue, lun->capacity.bsize); 1752 blk_queue_logical_block_size(disk->queue, lun->capacity.bsize);
1763 set_capacity(disk, lun->capacity.nsec); 1753 set_capacity(disk, lun->capacity.nsec);
1764 // set_disk_ro(sdkp->disk, lun->readonly); 1754 // set_disk_ro(sdkp->disk, lun->readonly);
1765 1755
@@ -2334,7 +2324,7 @@ static int ub_probe_lun(struct ub_dev *sc, int lnum)
2334 blk_queue_max_phys_segments(q, UB_MAX_REQ_SG); 2324 blk_queue_max_phys_segments(q, UB_MAX_REQ_SG);
2335 blk_queue_segment_boundary(q, 0xffffffff); /* Dubious. */ 2325 blk_queue_segment_boundary(q, 0xffffffff); /* Dubious. */
2336 blk_queue_max_sectors(q, UB_MAX_SECTORS); 2326 blk_queue_max_sectors(q, UB_MAX_SECTORS);
2337 blk_queue_hardsect_size(q, lun->capacity.bsize); 2327 blk_queue_logical_block_size(q, lun->capacity.bsize);
2338 2328
2339 lun->disk = disk; 2329 lun->disk = disk;
2340 q->queuedata = lun; 2330 q->queuedata = lun;
diff --git a/drivers/block/viodasd.c b/drivers/block/viodasd.c
index ecccf65dce2f..390d69bb7c48 100644
--- a/drivers/block/viodasd.c
+++ b/drivers/block/viodasd.c
@@ -252,7 +252,7 @@ static int send_request(struct request *req)
252 struct viodasd_device *d; 252 struct viodasd_device *d;
253 unsigned long flags; 253 unsigned long flags;
254 254
255 start = (u64)req->sector << 9; 255 start = (u64)blk_rq_pos(req) << 9;
256 256
257 if (rq_data_dir(req) == READ) { 257 if (rq_data_dir(req) == READ) {
258 direction = DMA_FROM_DEVICE; 258 direction = DMA_FROM_DEVICE;
@@ -361,19 +361,17 @@ static void do_viodasd_request(struct request_queue *q)
361 * back later. 361 * back later.
362 */ 362 */
363 while (num_req_outstanding < VIOMAXREQ) { 363 while (num_req_outstanding < VIOMAXREQ) {
364 req = elv_next_request(q); 364 req = blk_fetch_request(q);
365 if (req == NULL) 365 if (req == NULL)
366 return; 366 return;
367 /* dequeue the current request from the queue */
368 blkdev_dequeue_request(req);
369 /* check that request contains a valid command */ 367 /* check that request contains a valid command */
370 if (!blk_fs_request(req)) { 368 if (!blk_fs_request(req)) {
371 viodasd_end_request(req, -EIO, req->hard_nr_sectors); 369 viodasd_end_request(req, -EIO, blk_rq_sectors(req));
372 continue; 370 continue;
373 } 371 }
374 /* Try sending the request */ 372 /* Try sending the request */
375 if (send_request(req) != 0) 373 if (send_request(req) != 0)
376 viodasd_end_request(req, -EIO, req->hard_nr_sectors); 374 viodasd_end_request(req, -EIO, blk_rq_sectors(req));
377 } 375 }
378} 376}
379 377
@@ -590,7 +588,7 @@ static int viodasd_handle_read_write(struct vioblocklpevent *bevent)
590 err = vio_lookup_rc(viodasd_err_table, bevent->sub_result); 588 err = vio_lookup_rc(viodasd_err_table, bevent->sub_result);
591 printk(VIOD_KERN_WARNING "read/write error %d:0x%04x (%s)\n", 589 printk(VIOD_KERN_WARNING "read/write error %d:0x%04x (%s)\n",
592 event->xRc, bevent->sub_result, err->msg); 590 event->xRc, bevent->sub_result, err->msg);
593 num_sect = req->hard_nr_sectors; 591 num_sect = blk_rq_sectors(req);
594 } 592 }
595 qlock = req->q->queue_lock; 593 qlock = req->q->queue_lock;
596 spin_lock_irqsave(qlock, irq_flags); 594 spin_lock_irqsave(qlock, irq_flags);
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 5d34764c8a87..43db3ea15b54 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -37,6 +37,7 @@ struct virtblk_req
37 struct list_head list; 37 struct list_head list;
38 struct request *req; 38 struct request *req;
39 struct virtio_blk_outhdr out_hdr; 39 struct virtio_blk_outhdr out_hdr;
40 struct virtio_scsi_inhdr in_hdr;
40 u8 status; 41 u8 status;
41}; 42};
42 43
@@ -50,6 +51,7 @@ static void blk_done(struct virtqueue *vq)
50 spin_lock_irqsave(&vblk->lock, flags); 51 spin_lock_irqsave(&vblk->lock, flags);
51 while ((vbr = vblk->vq->vq_ops->get_buf(vblk->vq, &len)) != NULL) { 52 while ((vbr = vblk->vq->vq_ops->get_buf(vblk->vq, &len)) != NULL) {
52 int error; 53 int error;
54
53 switch (vbr->status) { 55 switch (vbr->status) {
54 case VIRTIO_BLK_S_OK: 56 case VIRTIO_BLK_S_OK:
55 error = 0; 57 error = 0;
@@ -62,7 +64,13 @@ static void blk_done(struct virtqueue *vq)
62 break; 64 break;
63 } 65 }
64 66
65 __blk_end_request(vbr->req, error, blk_rq_bytes(vbr->req)); 67 if (blk_pc_request(vbr->req)) {
68 vbr->req->resid_len = vbr->in_hdr.residual;
69 vbr->req->sense_len = vbr->in_hdr.sense_len;
70 vbr->req->errors = vbr->in_hdr.errors;
71 }
72
73 __blk_end_request_all(vbr->req, error);
66 list_del(&vbr->list); 74 list_del(&vbr->list);
67 mempool_free(vbr, vblk->pool); 75 mempool_free(vbr, vblk->pool);
68 } 76 }
@@ -74,7 +82,7 @@ static void blk_done(struct virtqueue *vq)
74static bool do_req(struct request_queue *q, struct virtio_blk *vblk, 82static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
75 struct request *req) 83 struct request *req)
76{ 84{
77 unsigned long num, out, in; 85 unsigned long num, out = 0, in = 0;
78 struct virtblk_req *vbr; 86 struct virtblk_req *vbr;
79 87
80 vbr = mempool_alloc(vblk->pool, GFP_ATOMIC); 88 vbr = mempool_alloc(vblk->pool, GFP_ATOMIC);
@@ -85,7 +93,7 @@ static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
85 vbr->req = req; 93 vbr->req = req;
86 if (blk_fs_request(vbr->req)) { 94 if (blk_fs_request(vbr->req)) {
87 vbr->out_hdr.type = 0; 95 vbr->out_hdr.type = 0;
88 vbr->out_hdr.sector = vbr->req->sector; 96 vbr->out_hdr.sector = blk_rq_pos(vbr->req);
89 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req); 97 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
90 } else if (blk_pc_request(vbr->req)) { 98 } else if (blk_pc_request(vbr->req)) {
91 vbr->out_hdr.type = VIRTIO_BLK_T_SCSI_CMD; 99 vbr->out_hdr.type = VIRTIO_BLK_T_SCSI_CMD;
@@ -99,18 +107,36 @@ static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
99 if (blk_barrier_rq(vbr->req)) 107 if (blk_barrier_rq(vbr->req))
100 vbr->out_hdr.type |= VIRTIO_BLK_T_BARRIER; 108 vbr->out_hdr.type |= VIRTIO_BLK_T_BARRIER;
101 109
102 sg_set_buf(&vblk->sg[0], &vbr->out_hdr, sizeof(vbr->out_hdr)); 110 sg_set_buf(&vblk->sg[out++], &vbr->out_hdr, sizeof(vbr->out_hdr));
103 num = blk_rq_map_sg(q, vbr->req, vblk->sg+1);
104 sg_set_buf(&vblk->sg[num+1], &vbr->status, sizeof(vbr->status));
105 111
106 if (rq_data_dir(vbr->req) == WRITE) { 112 /*
107 vbr->out_hdr.type |= VIRTIO_BLK_T_OUT; 113 * If this is a packet command we need a couple of additional headers.
108 out = 1 + num; 114 * Behind the normal outhdr we put a segment with the scsi command
109 in = 1; 115 * block, and before the normal inhdr we put the sense data and the
110 } else { 116 * inhdr with additional status information before the normal inhdr.
111 vbr->out_hdr.type |= VIRTIO_BLK_T_IN; 117 */
112 out = 1; 118 if (blk_pc_request(vbr->req))
113 in = 1 + num; 119 sg_set_buf(&vblk->sg[out++], vbr->req->cmd, vbr->req->cmd_len);
120
121 num = blk_rq_map_sg(q, vbr->req, vblk->sg + out);
122
123 if (blk_pc_request(vbr->req)) {
124 sg_set_buf(&vblk->sg[num + out + in++], vbr->req->sense, 96);
125 sg_set_buf(&vblk->sg[num + out + in++], &vbr->in_hdr,
126 sizeof(vbr->in_hdr));
127 }
128
129 sg_set_buf(&vblk->sg[num + out + in++], &vbr->status,
130 sizeof(vbr->status));
131
132 if (num) {
133 if (rq_data_dir(vbr->req) == WRITE) {
134 vbr->out_hdr.type |= VIRTIO_BLK_T_OUT;
135 out += num;
136 } else {
137 vbr->out_hdr.type |= VIRTIO_BLK_T_IN;
138 in += num;
139 }
114 } 140 }
115 141
116 if (vblk->vq->vq_ops->add_buf(vblk->vq, vblk->sg, out, in, vbr)) { 142 if (vblk->vq->vq_ops->add_buf(vblk->vq, vblk->sg, out, in, vbr)) {
@@ -124,12 +150,11 @@ static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
124 150
125static void do_virtblk_request(struct request_queue *q) 151static void do_virtblk_request(struct request_queue *q)
126{ 152{
127 struct virtio_blk *vblk = NULL; 153 struct virtio_blk *vblk = q->queuedata;
128 struct request *req; 154 struct request *req;
129 unsigned int issued = 0; 155 unsigned int issued = 0;
130 156
131 while ((req = elv_next_request(q)) != NULL) { 157 while ((req = blk_peek_request(q)) != NULL) {
132 vblk = req->rq_disk->private_data;
133 BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems); 158 BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems);
134 159
135 /* If this request fails, stop queue and wait for something to 160 /* If this request fails, stop queue and wait for something to
@@ -138,7 +163,7 @@ static void do_virtblk_request(struct request_queue *q)
138 blk_stop_queue(q); 163 blk_stop_queue(q);
139 break; 164 break;
140 } 165 }
141 blkdev_dequeue_request(req); 166 blk_start_request(req);
142 issued++; 167 issued++;
143 } 168 }
144 169
@@ -146,12 +171,51 @@ static void do_virtblk_request(struct request_queue *q)
146 vblk->vq->vq_ops->kick(vblk->vq); 171 vblk->vq->vq_ops->kick(vblk->vq);
147} 172}
148 173
174/* return ATA identify data
175 */
176static int virtblk_identify(struct gendisk *disk, void *argp)
177{
178 struct virtio_blk *vblk = disk->private_data;
179 void *opaque;
180 int err = -ENOMEM;
181
182 opaque = kmalloc(VIRTIO_BLK_ID_BYTES, GFP_KERNEL);
183 if (!opaque)
184 goto out;
185
186 err = virtio_config_buf(vblk->vdev, VIRTIO_BLK_F_IDENTIFY,
187 offsetof(struct virtio_blk_config, identify), opaque,
188 VIRTIO_BLK_ID_BYTES);
189
190 if (err)
191 goto out_kfree;
192
193 if (copy_to_user(argp, opaque, VIRTIO_BLK_ID_BYTES))
194 err = -EFAULT;
195
196out_kfree:
197 kfree(opaque);
198out:
199 return err;
200}
201
149static int virtblk_ioctl(struct block_device *bdev, fmode_t mode, 202static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
150 unsigned cmd, unsigned long data) 203 unsigned cmd, unsigned long data)
151{ 204{
152 return scsi_cmd_ioctl(bdev->bd_disk->queue, 205 struct gendisk *disk = bdev->bd_disk;
153 bdev->bd_disk, mode, cmd, 206 struct virtio_blk *vblk = disk->private_data;
154 (void __user *)data); 207 void __user *argp = (void __user *)data;
208
209 if (cmd == HDIO_GET_IDENTITY)
210 return virtblk_identify(disk, argp);
211
212 /*
213 * Only allow the generic SCSI ioctls if the host can support it.
214 */
215 if (!virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_SCSI))
216 return -ENOIOCTLCMD;
217
218 return scsi_cmd_ioctl(disk->queue, disk, mode, cmd, argp);
155} 219}
156 220
157/* We provide getgeo only to please some old bootloader/partitioning tools */ 221/* We provide getgeo only to please some old bootloader/partitioning tools */
@@ -190,7 +254,7 @@ static int index_to_minor(int index)
190 return index << PART_BITS; 254 return index << PART_BITS;
191} 255}
192 256
193static int virtblk_probe(struct virtio_device *vdev) 257static int __devinit virtblk_probe(struct virtio_device *vdev)
194{ 258{
195 struct virtio_blk *vblk; 259 struct virtio_blk *vblk;
196 int err; 260 int err;
@@ -224,7 +288,7 @@ static int virtblk_probe(struct virtio_device *vdev)
224 sg_init_table(vblk->sg, vblk->sg_elems); 288 sg_init_table(vblk->sg, vblk->sg_elems);
225 289
226 /* We expect one virtqueue, for output. */ 290 /* We expect one virtqueue, for output. */
227 vblk->vq = vdev->config->find_vq(vdev, 0, blk_done); 291 vblk->vq = virtio_find_single_vq(vdev, blk_done, "requests");
228 if (IS_ERR(vblk->vq)) { 292 if (IS_ERR(vblk->vq)) {
229 err = PTR_ERR(vblk->vq); 293 err = PTR_ERR(vblk->vq);
230 goto out_free_vblk; 294 goto out_free_vblk;
@@ -249,6 +313,7 @@ static int virtblk_probe(struct virtio_device *vdev)
249 goto out_put_disk; 313 goto out_put_disk;
250 } 314 }
251 315
316 vblk->disk->queue->queuedata = vblk;
252 queue_flag_set_unlocked(QUEUE_FLAG_VIRT, vblk->disk->queue); 317 queue_flag_set_unlocked(QUEUE_FLAG_VIRT, vblk->disk->queue);
253 318
254 if (index < 26) { 319 if (index < 26) {
@@ -313,7 +378,7 @@ static int virtblk_probe(struct virtio_device *vdev)
313 offsetof(struct virtio_blk_config, blk_size), 378 offsetof(struct virtio_blk_config, blk_size),
314 &blk_size); 379 &blk_size);
315 if (!err) 380 if (!err)
316 blk_queue_hardsect_size(vblk->disk->queue, blk_size); 381 blk_queue_logical_block_size(vblk->disk->queue, blk_size);
317 382
318 add_disk(vblk->disk); 383 add_disk(vblk->disk);
319 return 0; 384 return 0;
@@ -323,14 +388,14 @@ out_put_disk:
323out_mempool: 388out_mempool:
324 mempool_destroy(vblk->pool); 389 mempool_destroy(vblk->pool);
325out_free_vq: 390out_free_vq:
326 vdev->config->del_vq(vblk->vq); 391 vdev->config->del_vqs(vdev);
327out_free_vblk: 392out_free_vblk:
328 kfree(vblk); 393 kfree(vblk);
329out: 394out:
330 return err; 395 return err;
331} 396}
332 397
333static void virtblk_remove(struct virtio_device *vdev) 398static void __devexit virtblk_remove(struct virtio_device *vdev)
334{ 399{
335 struct virtio_blk *vblk = vdev->priv; 400 struct virtio_blk *vblk = vdev->priv;
336 401
@@ -344,7 +409,7 @@ static void virtblk_remove(struct virtio_device *vdev)
344 blk_cleanup_queue(vblk->disk->queue); 409 blk_cleanup_queue(vblk->disk->queue);
345 put_disk(vblk->disk); 410 put_disk(vblk->disk);
346 mempool_destroy(vblk->pool); 411 mempool_destroy(vblk->pool);
347 vdev->config->del_vq(vblk->vq); 412 vdev->config->del_vqs(vdev);
348 kfree(vblk); 413 kfree(vblk);
349} 414}
350 415
@@ -356,6 +421,7 @@ static struct virtio_device_id id_table[] = {
356static unsigned int features[] = { 421static unsigned int features[] = {
357 VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX, 422 VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX,
358 VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE, 423 VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE,
424 VIRTIO_BLK_F_SCSI, VIRTIO_BLK_F_IDENTIFY
359}; 425};
360 426
361static struct virtio_driver virtio_blk = { 427static struct virtio_driver virtio_blk = {
diff --git a/drivers/block/xd.c b/drivers/block/xd.c
index 64b496fce98b..ce2429219925 100644
--- a/drivers/block/xd.c
+++ b/drivers/block/xd.c
@@ -305,30 +305,25 @@ static void do_xd_request (struct request_queue * q)
305 if (xdc_busy) 305 if (xdc_busy)
306 return; 306 return;
307 307
308 while ((req = elv_next_request(q)) != NULL) { 308 req = blk_fetch_request(q);
309 unsigned block = req->sector; 309 while (req) {
310 unsigned count = req->nr_sectors; 310 unsigned block = blk_rq_pos(req);
311 int rw = rq_data_dir(req); 311 unsigned count = blk_rq_cur_sectors(req);
312 XD_INFO *disk = req->rq_disk->private_data; 312 XD_INFO *disk = req->rq_disk->private_data;
313 int res = 0; 313 int res = -EIO;
314 int retry; 314 int retry;
315 315
316 if (!blk_fs_request(req)) { 316 if (!blk_fs_request(req))
317 end_request(req, 0); 317 goto done;
318 continue; 318 if (block + count > get_capacity(req->rq_disk))
319 } 319 goto done;
320 if (block + count > get_capacity(req->rq_disk)) {
321 end_request(req, 0);
322 continue;
323 }
324 if (rw != READ && rw != WRITE) {
325 printk("do_xd_request: unknown request\n");
326 end_request(req, 0);
327 continue;
328 }
329 for (retry = 0; (retry < XD_RETRIES) && !res; retry++) 320 for (retry = 0; (retry < XD_RETRIES) && !res; retry++)
330 res = xd_readwrite(rw, disk, req->buffer, block, count); 321 res = xd_readwrite(rq_data_dir(req), disk, req->buffer,
331 end_request(req, res); /* wrap up, 0 = fail, 1 = success */ 322 block, count);
323 done:
324 /* wrap up, 0 = success, -errno = fail */
325 if (!__blk_end_request_cur(req, res))
326 req = blk_fetch_request(q);
332 } 327 }
333} 328}
334 329
@@ -418,7 +413,7 @@ static int xd_readwrite (u_char operation,XD_INFO *p,char *buffer,u_int block,u_
418 printk("xd%c: %s timeout, recalibrating drive\n",'a'+drive,(operation == READ ? "read" : "write")); 413 printk("xd%c: %s timeout, recalibrating drive\n",'a'+drive,(operation == READ ? "read" : "write"));
419 xd_recalibrate(drive); 414 xd_recalibrate(drive);
420 spin_lock_irq(&xd_lock); 415 spin_lock_irq(&xd_lock);
421 return (0); 416 return -EIO;
422 case 2: 417 case 2:
423 if (sense[0] & 0x30) { 418 if (sense[0] & 0x30) {
424 printk("xd%c: %s - ",'a'+drive,(operation == READ ? "reading" : "writing")); 419 printk("xd%c: %s - ",'a'+drive,(operation == READ ? "reading" : "writing"));
@@ -439,7 +434,7 @@ static int xd_readwrite (u_char operation,XD_INFO *p,char *buffer,u_int block,u_
439 else 434 else
440 printk(" - no valid disk address\n"); 435 printk(" - no valid disk address\n");
441 spin_lock_irq(&xd_lock); 436 spin_lock_irq(&xd_lock);
442 return (0); 437 return -EIO;
443 } 438 }
444 if (xd_dma_buffer) 439 if (xd_dma_buffer)
445 for (i=0; i < (temp * 0x200); i++) 440 for (i=0; i < (temp * 0x200); i++)
@@ -448,7 +443,7 @@ static int xd_readwrite (u_char operation,XD_INFO *p,char *buffer,u_int block,u_
448 count -= temp, buffer += temp * 0x200, block += temp; 443 count -= temp, buffer += temp * 0x200, block += temp;
449 } 444 }
450 spin_lock_irq(&xd_lock); 445 spin_lock_irq(&xd_lock);
451 return (1); 446 return 0;
452} 447}
453 448
454/* xd_recalibrate: recalibrate a given drive and reset controller if necessary */ 449/* xd_recalibrate: recalibrate a given drive and reset controller if necessary */
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index a6cbf7b808e6..e53284767f7c 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -122,7 +122,7 @@ static DEFINE_SPINLOCK(blkif_io_lock);
122static int get_id_from_freelist(struct blkfront_info *info) 122static int get_id_from_freelist(struct blkfront_info *info)
123{ 123{
124 unsigned long free = info->shadow_free; 124 unsigned long free = info->shadow_free;
125 BUG_ON(free > BLK_RING_SIZE); 125 BUG_ON(free >= BLK_RING_SIZE);
126 info->shadow_free = info->shadow[free].req.id; 126 info->shadow_free = info->shadow[free].req.id;
127 info->shadow[free].req.id = 0x0fffffee; /* debug */ 127 info->shadow[free].req.id = 0x0fffffee; /* debug */
128 return free; 128 return free;
@@ -231,7 +231,7 @@ static int blkif_queue_request(struct request *req)
231 info->shadow[id].request = (unsigned long)req; 231 info->shadow[id].request = (unsigned long)req;
232 232
233 ring_req->id = id; 233 ring_req->id = id;
234 ring_req->sector_number = (blkif_sector_t)req->sector; 234 ring_req->sector_number = (blkif_sector_t)blk_rq_pos(req);
235 ring_req->handle = info->handle; 235 ring_req->handle = info->handle;
236 236
237 ring_req->operation = rq_data_dir(req) ? 237 ring_req->operation = rq_data_dir(req) ?
@@ -299,25 +299,25 @@ static void do_blkif_request(struct request_queue *rq)
299 299
300 queued = 0; 300 queued = 0;
301 301
302 while ((req = elv_next_request(rq)) != NULL) { 302 while ((req = blk_peek_request(rq)) != NULL) {
303 info = req->rq_disk->private_data; 303 info = req->rq_disk->private_data;
304 if (!blk_fs_request(req)) {
305 end_request(req, 0);
306 continue;
307 }
308 304
309 if (RING_FULL(&info->ring)) 305 if (RING_FULL(&info->ring))
310 goto wait; 306 goto wait;
311 307
312 pr_debug("do_blk_req %p: cmd %p, sec %lx, " 308 blk_start_request(req);
313 "(%u/%li) buffer:%p [%s]\n",
314 req, req->cmd, (unsigned long)req->sector,
315 req->current_nr_sectors,
316 req->nr_sectors, req->buffer,
317 rq_data_dir(req) ? "write" : "read");
318 309
310 if (!blk_fs_request(req)) {
311 __blk_end_request_all(req, -EIO);
312 continue;
313 }
314
315 pr_debug("do_blk_req %p: cmd %p, sec %lx, "
316 "(%u/%u) buffer:%p [%s]\n",
317 req, req->cmd, (unsigned long)blk_rq_pos(req),
318 blk_rq_cur_sectors(req), blk_rq_sectors(req),
319 req->buffer, rq_data_dir(req) ? "write" : "read");
319 320
320 blkdev_dequeue_request(req);
321 if (blkif_queue_request(req)) { 321 if (blkif_queue_request(req)) {
322 blk_requeue_request(rq, req); 322 blk_requeue_request(rq, req);
323wait: 323wait:
@@ -344,7 +344,7 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size)
344 queue_flag_set_unlocked(QUEUE_FLAG_VIRT, rq); 344 queue_flag_set_unlocked(QUEUE_FLAG_VIRT, rq);
345 345
346 /* Hard sector size and max sectors impersonate the equiv. hardware. */ 346 /* Hard sector size and max sectors impersonate the equiv. hardware. */
347 blk_queue_hardsect_size(rq, sector_size); 347 blk_queue_logical_block_size(rq, sector_size);
348 blk_queue_max_sectors(rq, 512); 348 blk_queue_max_sectors(rq, 512);
349 349
350 /* Each segment in a request is up to an aligned page in size. */ 350 /* Each segment in a request is up to an aligned page in size. */
@@ -551,7 +551,6 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
551 551
552 for (i = info->ring.rsp_cons; i != rp; i++) { 552 for (i = info->ring.rsp_cons; i != rp; i++) {
553 unsigned long id; 553 unsigned long id;
554 int ret;
555 554
556 bret = RING_GET_RESPONSE(&info->ring, i); 555 bret = RING_GET_RESPONSE(&info->ring, i);
557 id = bret->id; 556 id = bret->id;
@@ -578,8 +577,7 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
578 dev_dbg(&info->xbdev->dev, "Bad return from blkdev data " 577 dev_dbg(&info->xbdev->dev, "Bad return from blkdev data "
579 "request: %x\n", bret->status); 578 "request: %x\n", bret->status);
580 579
581 ret = __blk_end_request(req, error, blk_rq_bytes(req)); 580 __blk_end_request_all(req, error);
582 BUG_ON(ret);
583 break; 581 break;
584 default: 582 default:
585 BUG(); 583 BUG();
@@ -755,12 +753,12 @@ static int blkfront_probe(struct xenbus_device *dev,
755 753
756 /* Front end dir is a number, which is used as the id. */ 754 /* Front end dir is a number, which is used as the id. */
757 info->handle = simple_strtoul(strrchr(dev->nodename, '/')+1, NULL, 0); 755 info->handle = simple_strtoul(strrchr(dev->nodename, '/')+1, NULL, 0);
758 dev->dev.driver_data = info; 756 dev_set_drvdata(&dev->dev, info);
759 757
760 err = talk_to_backend(dev, info); 758 err = talk_to_backend(dev, info);
761 if (err) { 759 if (err) {
762 kfree(info); 760 kfree(info);
763 dev->dev.driver_data = NULL; 761 dev_set_drvdata(&dev->dev, NULL);
764 return err; 762 return err;
765 } 763 }
766 764
@@ -845,7 +843,7 @@ static int blkif_recover(struct blkfront_info *info)
845 */ 843 */
846static int blkfront_resume(struct xenbus_device *dev) 844static int blkfront_resume(struct xenbus_device *dev)
847{ 845{
848 struct blkfront_info *info = dev->dev.driver_data; 846 struct blkfront_info *info = dev_get_drvdata(&dev->dev);
849 int err; 847 int err;
850 848
851 dev_dbg(&dev->dev, "blkfront_resume: %s\n", dev->nodename); 849 dev_dbg(&dev->dev, "blkfront_resume: %s\n", dev->nodename);
@@ -924,7 +922,7 @@ static void blkfront_connect(struct blkfront_info *info)
924 */ 922 */
925static void blkfront_closing(struct xenbus_device *dev) 923static void blkfront_closing(struct xenbus_device *dev)
926{ 924{
927 struct blkfront_info *info = dev->dev.driver_data; 925 struct blkfront_info *info = dev_get_drvdata(&dev->dev);
928 unsigned long flags; 926 unsigned long flags;
929 927
930 dev_dbg(&dev->dev, "blkfront_closing: %s removed\n", dev->nodename); 928 dev_dbg(&dev->dev, "blkfront_closing: %s removed\n", dev->nodename);
@@ -959,7 +957,7 @@ static void blkfront_closing(struct xenbus_device *dev)
959static void backend_changed(struct xenbus_device *dev, 957static void backend_changed(struct xenbus_device *dev,
960 enum xenbus_state backend_state) 958 enum xenbus_state backend_state)
961{ 959{
962 struct blkfront_info *info = dev->dev.driver_data; 960 struct blkfront_info *info = dev_get_drvdata(&dev->dev);
963 struct block_device *bd; 961 struct block_device *bd;
964 962
965 dev_dbg(&dev->dev, "blkfront:backend_changed.\n"); 963 dev_dbg(&dev->dev, "blkfront:backend_changed.\n");
@@ -999,7 +997,7 @@ static void backend_changed(struct xenbus_device *dev,
999 997
1000static int blkfront_remove(struct xenbus_device *dev) 998static int blkfront_remove(struct xenbus_device *dev)
1001{ 999{
1002 struct blkfront_info *info = dev->dev.driver_data; 1000 struct blkfront_info *info = dev_get_drvdata(&dev->dev);
1003 1001
1004 dev_dbg(&dev->dev, "blkfront_remove: %s removed\n", dev->nodename); 1002 dev_dbg(&dev->dev, "blkfront_remove: %s removed\n", dev->nodename);
1005 1003
@@ -1012,7 +1010,7 @@ static int blkfront_remove(struct xenbus_device *dev)
1012 1010
1013static int blkfront_is_ready(struct xenbus_device *dev) 1011static int blkfront_is_ready(struct xenbus_device *dev)
1014{ 1012{
1015 struct blkfront_info *info = dev->dev.driver_data; 1013 struct blkfront_info *info = dev_get_drvdata(&dev->dev);
1016 1014
1017 return info->is_ready; 1015 return info->is_ready;
1018} 1016}
diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c
index 4aecf5dc6a93..f08491a3a813 100644
--- a/drivers/block/xsysace.c
+++ b/drivers/block/xsysace.c
@@ -463,10 +463,11 @@ struct request *ace_get_next_request(struct request_queue * q)
463{ 463{
464 struct request *req; 464 struct request *req;
465 465
466 while ((req = elv_next_request(q)) != NULL) { 466 while ((req = blk_peek_request(q)) != NULL) {
467 if (blk_fs_request(req)) 467 if (blk_fs_request(req))
468 break; 468 break;
469 end_request(req, 0); 469 blk_start_request(req);
470 __blk_end_request_all(req, -EIO);
470 } 471 }
471 return req; 472 return req;
472} 473}
@@ -492,9 +493,13 @@ static void ace_fsm_dostate(struct ace_device *ace)
492 set_capacity(ace->gd, 0); 493 set_capacity(ace->gd, 0);
493 dev_info(ace->dev, "No CF in slot\n"); 494 dev_info(ace->dev, "No CF in slot\n");
494 495
495 /* Drop all pending requests */ 496 /* Drop all in-flight and pending requests */
496 while ((req = elv_next_request(ace->queue)) != NULL) 497 if (ace->req) {
497 end_request(req, 0); 498 __blk_end_request_all(ace->req, -EIO);
499 ace->req = NULL;
500 }
501 while ((req = blk_fetch_request(ace->queue)) != NULL)
502 __blk_end_request_all(req, -EIO);
498 503
499 /* Drop back to IDLE state and notify waiters */ 504 /* Drop back to IDLE state and notify waiters */
500 ace->fsm_state = ACE_FSM_STATE_IDLE; 505 ace->fsm_state = ACE_FSM_STATE_IDLE;
@@ -642,19 +647,21 @@ static void ace_fsm_dostate(struct ace_device *ace)
642 ace->fsm_state = ACE_FSM_STATE_IDLE; 647 ace->fsm_state = ACE_FSM_STATE_IDLE;
643 break; 648 break;
644 } 649 }
650 blk_start_request(req);
645 651
646 /* Okay, it's a data request, set it up for transfer */ 652 /* Okay, it's a data request, set it up for transfer */
647 dev_dbg(ace->dev, 653 dev_dbg(ace->dev,
648 "request: sec=%llx hcnt=%lx, ccnt=%x, dir=%i\n", 654 "request: sec=%llx hcnt=%x, ccnt=%x, dir=%i\n",
649 (unsigned long long) req->sector, req->hard_nr_sectors, 655 (unsigned long long)blk_rq_pos(req),
650 req->current_nr_sectors, rq_data_dir(req)); 656 blk_rq_sectors(req), blk_rq_cur_sectors(req),
657 rq_data_dir(req));
651 658
652 ace->req = req; 659 ace->req = req;
653 ace->data_ptr = req->buffer; 660 ace->data_ptr = req->buffer;
654 ace->data_count = req->current_nr_sectors * ACE_BUF_PER_SECTOR; 661 ace->data_count = blk_rq_cur_sectors(req) * ACE_BUF_PER_SECTOR;
655 ace_out32(ace, ACE_MPULBA, req->sector & 0x0FFFFFFF); 662 ace_out32(ace, ACE_MPULBA, blk_rq_pos(req) & 0x0FFFFFFF);
656 663
657 count = req->hard_nr_sectors; 664 count = blk_rq_sectors(req);
658 if (rq_data_dir(req)) { 665 if (rq_data_dir(req)) {
659 /* Kick off write request */ 666 /* Kick off write request */
660 dev_dbg(ace->dev, "write data\n"); 667 dev_dbg(ace->dev, "write data\n");
@@ -688,7 +695,7 @@ static void ace_fsm_dostate(struct ace_device *ace)
688 dev_dbg(ace->dev, 695 dev_dbg(ace->dev,
689 "CFBSY set; t=%i iter=%i c=%i dc=%i irq=%i\n", 696 "CFBSY set; t=%i iter=%i c=%i dc=%i irq=%i\n",
690 ace->fsm_task, ace->fsm_iter_num, 697 ace->fsm_task, ace->fsm_iter_num,
691 ace->req->current_nr_sectors * 16, 698 blk_rq_cur_sectors(ace->req) * 16,
692 ace->data_count, ace->in_irq); 699 ace->data_count, ace->in_irq);
693 ace_fsm_yield(ace); /* need to poll CFBSY bit */ 700 ace_fsm_yield(ace); /* need to poll CFBSY bit */
694 break; 701 break;
@@ -697,7 +704,7 @@ static void ace_fsm_dostate(struct ace_device *ace)
697 dev_dbg(ace->dev, 704 dev_dbg(ace->dev,
698 "DATABUF not set; t=%i iter=%i c=%i dc=%i irq=%i\n", 705 "DATABUF not set; t=%i iter=%i c=%i dc=%i irq=%i\n",
699 ace->fsm_task, ace->fsm_iter_num, 706 ace->fsm_task, ace->fsm_iter_num,
700 ace->req->current_nr_sectors * 16, 707 blk_rq_cur_sectors(ace->req) * 16,
701 ace->data_count, ace->in_irq); 708 ace->data_count, ace->in_irq);
702 ace_fsm_yieldirq(ace); 709 ace_fsm_yieldirq(ace);
703 break; 710 break;
@@ -717,14 +724,13 @@ static void ace_fsm_dostate(struct ace_device *ace)
717 } 724 }
718 725
719 /* bio finished; is there another one? */ 726 /* bio finished; is there another one? */
720 if (__blk_end_request(ace->req, 0, 727 if (__blk_end_request_cur(ace->req, 0)) {
721 blk_rq_cur_bytes(ace->req))) { 728 /* dev_dbg(ace->dev, "next block; h=%u c=%u\n",
722 /* dev_dbg(ace->dev, "next block; h=%li c=%i\n", 729 * blk_rq_sectors(ace->req),
723 * ace->req->hard_nr_sectors, 730 * blk_rq_cur_sectors(ace->req));
724 * ace->req->current_nr_sectors);
725 */ 731 */
726 ace->data_ptr = ace->req->buffer; 732 ace->data_ptr = ace->req->buffer;
727 ace->data_count = ace->req->current_nr_sectors * 16; 733 ace->data_count = blk_rq_cur_sectors(ace->req) * 16;
728 ace_fsm_yieldirq(ace); 734 ace_fsm_yieldirq(ace);
729 break; 735 break;
730 } 736 }
@@ -978,7 +984,7 @@ static int __devinit ace_setup(struct ace_device *ace)
978 ace->queue = blk_init_queue(ace_request, &ace->lock); 984 ace->queue = blk_init_queue(ace_request, &ace->lock);
979 if (ace->queue == NULL) 985 if (ace->queue == NULL)
980 goto err_blk_initq; 986 goto err_blk_initq;
981 blk_queue_hardsect_size(ace->queue, 512); 987 blk_queue_logical_block_size(ace->queue, 512);
982 988
983 /* 989 /*
984 * Allocate and initialize GD structure 990 * Allocate and initialize GD structure
diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
index 80754cdd3119..4575171e5beb 100644
--- a/drivers/block/z2ram.c
+++ b/drivers/block/z2ram.c
@@ -70,15 +70,18 @@ static struct gendisk *z2ram_gendisk;
70static void do_z2_request(struct request_queue *q) 70static void do_z2_request(struct request_queue *q)
71{ 71{
72 struct request *req; 72 struct request *req;
73 while ((req = elv_next_request(q)) != NULL) { 73
74 unsigned long start = req->sector << 9; 74 req = blk_fetch_request(q);
75 unsigned long len = req->current_nr_sectors << 9; 75 while (req) {
76 unsigned long start = blk_rq_pos(req) << 9;
77 unsigned long len = blk_rq_cur_bytes(req);
78 int err = 0;
76 79
77 if (start + len > z2ram_size) { 80 if (start + len > z2ram_size) {
78 printk( KERN_ERR DEVICE_NAME ": bad access: block=%lu, count=%u\n", 81 printk( KERN_ERR DEVICE_NAME ": bad access: block=%lu, count=%u\n",
79 req->sector, req->current_nr_sectors); 82 blk_rq_pos(req), blk_rq_cur_sectors(req));
80 end_request(req, 0); 83 err = -EIO;
81 continue; 84 goto done;
82 } 85 }
83 while (len) { 86 while (len) {
84 unsigned long addr = start & Z2RAM_CHUNKMASK; 87 unsigned long addr = start & Z2RAM_CHUNKMASK;
@@ -93,7 +96,9 @@ static void do_z2_request(struct request_queue *q)
93 start += size; 96 start += size;
94 len -= size; 97 len -= size;
95 } 98 }
96 end_request(req, 1); 99 done:
100 if (!__blk_end_request_cur(req, err))
101 req = blk_fetch_request(q);
97 } 102 }
98} 103}
99 104