Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'for-linus' of git://git.kernel.dk/linux-block

* 'for-linus' of git://git.kernel.dk/linux-block:
block: don't kick empty queue in blk_drain_queue()
block/swim3: Locking fixes
loop: Fix discard_alignment default setting
cfq-iosched: fix cfq_cic_link() race confition
cfq-iosched: free cic_index if blkio_alloc_blkg_stats fails
cciss: fix flush cache transfer length
cciss: Add IRQF_SHARED back in for the non-MSI(X) interrupt handler
loop: fix loop block driver discard and encryption comment
block: initialize request_queue's numa node during

+246 -168
+11 -12
block/blk-core.c
··· 366 366 if (drain_all) 367 367 blk_throtl_drain(q); 368 368 369 - __blk_run_queue(q); 369 + /* 370 + * This function might be called on a queue which failed 371 + * driver init after queue creation. Some drivers 372 + * (e.g. fd) get unhappy in such cases. Kick queue iff 373 + * dispatch queue has something on it. 374 + */ 375 + if (!list_empty(&q->queue_head)) 376 + __blk_run_queue(q); 370 377 371 378 if (drain_all) 372 379 nr_rqs = q->rq.count[0] + q->rq.count[1]; ··· 474 467 q->backing_dev_info.state = 0; 475 468 q->backing_dev_info.capabilities = BDI_CAP_MAP_COPY; 476 469 q->backing_dev_info.name = "block"; 470 + q->node = node_id; 477 471 478 472 err = bdi_init(&q->backing_dev_info); 479 473 if (err) { ··· 559 551 if (!uninit_q) 560 552 return NULL; 561 553 562 - q = blk_init_allocated_queue_node(uninit_q, rfn, lock, node_id); 554 + q = blk_init_allocated_queue(uninit_q, rfn, lock); 563 555 if (!q) 564 556 blk_cleanup_queue(uninit_q); 565 557 ··· 571 563 blk_init_allocated_queue(struct request_queue *q, request_fn_proc *rfn, 572 564 spinlock_t *lock) 573 565 { 574 - return blk_init_allocated_queue_node(q, rfn, lock, -1); 575 - } 576 - EXPORT_SYMBOL(blk_init_allocated_queue); 577 - 578 - struct request_queue * 579 - blk_init_allocated_queue_node(struct request_queue *q, request_fn_proc *rfn, 580 - spinlock_t *lock, int node_id) 581 - { 582 566 if (!q) 583 567 return NULL; 584 568 585 - q->node = node_id; 586 569 if (blk_init_free_list(q)) 587 570 return NULL; 588 571 ··· 603 604 604 605 return NULL; 605 606 } 606 - EXPORT_SYMBOL(blk_init_allocated_queue_node); 607 + EXPORT_SYMBOL(blk_init_allocated_queue); 607 608 608 609 int blk_get_queue(struct request_queue *q) 609 610 {
+14 -2
block/cfq-iosched.c
··· 3184 3184 } 3185 3185 } 3186 3186 3187 - if (ret) 3187 + if (ret && ret != -EEXIST) 3188 3188 printk(KERN_ERR "cfq: cic link failed!\n"); 3189 3189 3190 3190 return ret; ··· 3200 3200 { 3201 3201 struct io_context *ioc = NULL; 3202 3202 struct cfq_io_context *cic; 3203 + int ret; 3203 3204 3204 3205 might_sleep_if(gfp_mask & __GFP_WAIT); 3205 3206 ··· 3208 3207 if (!ioc) 3209 3208 return NULL; 3210 3209 3210 + retry: 3211 3211 cic = cfq_cic_lookup(cfqd, ioc); 3212 3212 if (cic) 3213 3213 goto out; ··· 3217 3215 if (cic == NULL) 3218 3216 goto err; 3219 3217 3220 - if (cfq_cic_link(cfqd, ioc, cic, gfp_mask)) 3218 + ret = cfq_cic_link(cfqd, ioc, cic, gfp_mask); 3219 + if (ret == -EEXIST) { 3220 + /* someone has linked cic to ioc already */ 3221 + cfq_cic_free(cic); 3222 + goto retry; 3223 + } else if (ret) 3221 3224 goto err_free; 3222 3225 3223 3226 out: ··· 4043 4036 4044 4037 if (blkio_alloc_blkg_stats(&cfqg->blkg)) { 4045 4038 kfree(cfqg); 4039 + 4040 + spin_lock(&cic_index_lock); 4041 + ida_remove(&cic_index_ida, cfqd->cic_index); 4042 + spin_unlock(&cic_index_lock); 4043 + 4046 4044 kfree(cfqd); 4047 4045 return NULL; 4048 4046 }
+4 -2
drivers/block/cciss.c
··· 2601 2601 c->Request.Timeout = 0; 2602 2602 c->Request.CDB[0] = BMIC_WRITE; 2603 2603 c->Request.CDB[6] = BMIC_CACHE_FLUSH; 2604 + c->Request.CDB[7] = (size >> 8) & 0xFF; 2605 + c->Request.CDB[8] = size & 0xFF; 2604 2606 break; 2605 2607 case TEST_UNIT_READY: 2606 2608 c->Request.CDBLen = 6; ··· 4882 4880 { 4883 4881 if (h->msix_vector || h->msi_vector) { 4884 4882 if (!request_irq(h->intr[h->intr_mode], msixhandler, 4885 - IRQF_DISABLED, h->devname, h)) 4883 + 0, h->devname, h)) 4886 4884 return 0; 4887 4885 dev_err(&h->pdev->dev, "Unable to get msi irq %d" 4888 4886 " for %s\n", h->intr[h->intr_mode], ··· 4891 4889 } 4892 4890 4893 4891 if (!request_irq(h->intr[h->intr_mode], intxhandler, 4894 - IRQF_DISABLED, h->devname, h)) 4892 + IRQF_SHARED, h->devname, h)) 4895 4893 return 0; 4896 4894 dev_err(&h->pdev->dev, "Unable to get irq %d for %s\n", 4897 4895 h->intr[h->intr_mode], h->devname);
+2 -2
drivers/block/loop.c
··· 422 422 423 423 /* 424 424 * We use punch hole to reclaim the free space used by the 425 - * image a.k.a. discard. However we do support discard if 425 + * image a.k.a. discard. However we do not support discard if 426 426 * encryption is enabled, because it may give an attacker 427 427 * useful information. 428 428 */ ··· 797 797 } 798 798 799 799 q->limits.discard_granularity = inode->i_sb->s_blocksize; 800 - q->limits.discard_alignment = inode->i_sb->s_blocksize; 800 + q->limits.discard_alignment = 0; 801 801 q->limits.max_discard_sectors = UINT_MAX >> 9; 802 802 q->limits.discard_zeroes_data = 1; 803 803 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
+215 -147
drivers/block/swim3.c
··· 16 16 * handle GCR disks 17 17 */ 18 18 19 + #undef DEBUG 20 + 19 21 #include <linux/stddef.h> 20 22 #include <linux/kernel.h> 21 23 #include <linux/sched.h> ··· 38 36 #include <asm/machdep.h> 39 37 #include <asm/pmac_feature.h> 40 38 41 - static DEFINE_MUTEX(swim3_mutex); 42 - static struct request_queue *swim3_queue; 43 - static struct gendisk *disks[2]; 44 - static struct request *fd_req; 45 - 46 39 #define MAX_FLOPPIES 2 40 + 41 + static DEFINE_MUTEX(swim3_mutex); 42 + static struct gendisk *disks[MAX_FLOPPIES]; 47 43 48 44 enum swim_state { 49 45 idle, ··· 177 177 178 178 struct floppy_state { 179 179 enum swim_state state; 180 - spinlock_t lock; 181 180 struct swim3 __iomem *swim3; /* hardware registers */ 182 181 struct dbdma_regs __iomem *dma; /* DMA controller registers */ 183 182 int swim3_intr; /* interrupt number for SWIM3 */ ··· 203 204 int wanted; 204 205 struct macio_dev *mdev; 205 206 char dbdma_cmd_space[5 * sizeof(struct dbdma_cmd)]; 207 + int index; 208 + struct request *cur_req; 206 209 }; 210 + 211 + #define swim3_err(fmt, arg...) dev_err(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg) 212 + #define swim3_warn(fmt, arg...) dev_warn(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg) 213 + #define swim3_info(fmt, arg...) dev_info(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg) 214 + 215 + #ifdef DEBUG 216 + #define swim3_dbg(fmt, arg...) dev_dbg(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg) 217 + #else 218 + #define swim3_dbg(fmt, arg...) do { } while(0) 219 + #endif 207 220 208 221 static struct floppy_state floppy_states[MAX_FLOPPIES]; 209 222 static int floppy_count = 0; ··· 235 224 0, 0, 0, 0, 0, 0 236 225 }; 237 226 238 - static void swim3_select(struct floppy_state *fs, int sel); 239 - static void swim3_action(struct floppy_state *fs, int action); 240 - static int swim3_readbit(struct floppy_state *fs, int bit); 241 - static void do_fd_request(struct request_queue * q); 242 - static void start_request(struct floppy_state *fs); 243 - static void set_timeout(struct floppy_state *fs, int nticks, 244 - void (*proc)(unsigned long)); 245 - static void scan_track(struct floppy_state *fs); 246 227 static void seek_track(struct floppy_state *fs, int n); 247 228 static void init_dma(struct dbdma_cmd *cp, int cmd, void *buf, int count); 248 - static void setup_transfer(struct floppy_state *fs); 249 229 static void act(struct floppy_state *fs); 250 230 static void scan_timeout(unsigned long data); 251 231 static void seek_timeout(unsigned long data); ··· 256 254 unsigned int clearing); 257 255 static int floppy_revalidate(struct gendisk *disk); 258 256 259 - static bool swim3_end_request(int err, unsigned int nr_bytes) 257 + static bool swim3_end_request(struct floppy_state *fs, int err, unsigned int nr_bytes) 260 258 { 261 - if (__blk_end_request(fd_req, err, nr_bytes)) 259 + struct request *req = fs->cur_req; 260 + int rc; 261 + 262 + swim3_dbg(" end request, err=%d nr_bytes=%d, cur_req=%p\n", 263 + err, nr_bytes, req); 264 + 265 + if (err) 266 + nr_bytes = blk_rq_cur_bytes(req); 267 + rc = __blk_end_request(req, err, nr_bytes); 268 + if (rc) 262 269 return true; 263 - 264 - fd_req = NULL; 270 + fs->cur_req = NULL; 265 271 return false; 266 - } 267 - 268 - static bool swim3_end_request_cur(int err) 269 - { 270 - return swim3_end_request(err, blk_rq_cur_bytes(fd_req)); 271 272 } 272 273 273 274 static void swim3_select(struct floppy_state *fs, int sel) ··· 308 303 return (stat & DATA) == 0; 309 304 } 310 305 311 - static void do_fd_request(struct request_queue * q) 312 - { 313 - int i; 314 - 315 - for(i=0; i<floppy_count; i++) { 316 - struct floppy_state *fs = &floppy_states[i]; 317 - if (fs->mdev->media_bay && 318 - check_media_bay(fs->mdev->media_bay) != MB_FD) 319 - continue; 320 - start_request(fs); 321 - } 322 - } 323 - 324 306 static void start_request(struct floppy_state *fs) 325 307 { 326 308 struct request *req; 327 309 unsigned long x; 310 + 311 + swim3_dbg("start request, initial state=%d\n", fs->state); 328 312 329 313 if (fs->state == idle && fs->wanted) { 330 314 fs->state = available; ··· 321 327 return; 322 328 } 323 329 while (fs->state == idle) { 324 - if (!fd_req) { 325 - fd_req = blk_fetch_request(swim3_queue); 326 - if (!fd_req) 330 + swim3_dbg("start request, idle loop, cur_req=%p\n", fs->cur_req); 331 + if (!fs->cur_req) { 332 + fs->cur_req = blk_fetch_request(disks[fs->index]->queue); 333 + swim3_dbg(" fetched request %p\n", fs->cur_req); 334 + if (!fs->cur_req) 327 335 break; 328 336 } 329 - req = fd_req; 330 - #if 0 331 - printk("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%u buf=%p\n", 332 - req->rq_disk->disk_name, req->cmd, 333 - (long)blk_rq_pos(req), blk_rq_sectors(req), req->buffer); 334 - printk(" errors=%d current_nr_sectors=%u\n", 335 - req->errors, blk_rq_cur_sectors(req)); 337 + req = fs->cur_req; 338 + 339 + if (fs->mdev->media_bay && 340 + check_media_bay(fs->mdev->media_bay) != MB_FD) { 341 + swim3_dbg("%s", " media bay absent, dropping req\n"); 342 + swim3_end_request(fs, -ENODEV, 0); 343 + continue; 344 + } 345 + 346 + #if 0 /* This is really too verbose */ 347 + swim3_dbg("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%u buf=%p\n", 348 + req->rq_disk->disk_name, req->cmd, 349 + (long)blk_rq_pos(req), blk_rq_sectors(req), 350 + req->buffer); 351 + swim3_dbg(" errors=%d current_nr_sectors=%u\n", 352 + req->errors, blk_rq_cur_sectors(req)); 336 353 #endif 337 354 338 355 if (blk_rq_pos(req) >= fs->total_secs) { 339 - swim3_end_request_cur(-EIO); 356 + swim3_dbg(" pos out of bounds (%ld, max is %ld)\n", 357 + (long)blk_rq_pos(req), (long)fs->total_secs); 358 + swim3_end_request(fs, -EIO, 0); 340 359 continue; 341 360 } 342 361 if (fs->ejected) { 343 - swim3_end_request_cur(-EIO); 362 + swim3_dbg("%s", " disk ejected\n"); 363 + swim3_end_request(fs, -EIO, 0); 344 364 continue; 345 365 } 346 366 ··· 362 354 if (fs->write_prot < 0) 363 355 fs->write_prot = swim3_readbit(fs, WRITE_PROT); 364 356 if (fs->write_prot) { 365 - swim3_end_request_cur(-EIO); 357 + swim3_dbg("%s", " try to write, disk write protected\n"); 358 + swim3_end_request(fs, -EIO, 0); 366 359 continue; 367 360 } 368 361 } ··· 378 369 x = ((long)blk_rq_pos(req)) % fs->secpercyl; 379 370 fs->head = x / fs->secpertrack; 380 371 fs->req_sector = x % fs->secpertrack + 1; 381 - fd_req = req; 382 372 fs->state = do_transfer; 383 373 fs->retries = 0; 384 374 ··· 385 377 } 386 378 } 387 379 380 + static void do_fd_request(struct request_queue * q) 381 + { 382 + start_request(q->queuedata); 383 + } 384 + 388 385 static void set_timeout(struct floppy_state *fs, int nticks, 389 386 void (*proc)(unsigned long)) 390 387 { 391 - unsigned long flags; 392 - 393 - spin_lock_irqsave(&fs->lock, flags); 394 388 if (fs->timeout_pending) 395 389 del_timer(&fs->timeout); 396 390 fs->timeout.expires = jiffies + nticks; ··· 400 390 fs->timeout.data = (unsigned long) fs; 401 391 add_timer(&fs->timeout); 402 392 fs->timeout_pending = 1; 403 - spin_unlock_irqrestore(&fs->lock, flags); 404 393 } 405 394 406 395 static inline void scan_track(struct floppy_state *fs) ··· 451 442 struct swim3 __iomem *sw = fs->swim3; 452 443 struct dbdma_cmd *cp = fs->dma_cmd; 453 444 struct dbdma_regs __iomem *dr = fs->dma; 445 + struct request *req = fs->cur_req; 454 446 455 - if (blk_rq_cur_sectors(fd_req) <= 0) { 456 - printk(KERN_ERR "swim3: transfer 0 sectors?\n"); 447 + if (blk_rq_cur_sectors(req) <= 0) { 448 + swim3_warn("%s", "Transfer 0 sectors ?\n"); 457 449 return; 458 450 } 459 - if (rq_data_dir(fd_req) == WRITE) 451 + if (rq_data_dir(req) == WRITE) 460 452 n = 1; 461 453 else { 462 454 n = fs->secpertrack - fs->req_sector + 1; 463 - if (n > blk_rq_cur_sectors(fd_req)) 464 - n = blk_rq_cur_sectors(fd_req); 455 + if (n > blk_rq_cur_sectors(req)) 456 + n = blk_rq_cur_sectors(req); 465 457 } 458 + 459 + swim3_dbg(" setup xfer at sect %d (of %d) head %d for %d\n", 460 + fs->req_sector, fs->secpertrack, fs->head, n); 461 + 466 462 fs->scount = n; 467 463 swim3_select(fs, fs->head? READ_DATA_1: READ_DATA_0); 468 464 out_8(&sw->sector, fs->req_sector); 469 465 out_8(&sw->nsect, n); 470 466 out_8(&sw->gap3, 0); 471 467 out_le32(&dr->cmdptr, virt_to_bus(cp)); 472 - if (rq_data_dir(fd_req) == WRITE) { 468 + if (rq_data_dir(req) == WRITE) { 473 469 /* Set up 3 dma commands: write preamble, data, postamble */ 474 470 init_dma(cp, OUTPUT_MORE, write_preamble, sizeof(write_preamble)); 475 471 ++cp; 476 - init_dma(cp, OUTPUT_MORE, fd_req->buffer, 512); 472 + init_dma(cp, OUTPUT_MORE, req->buffer, 512); 477 473 ++cp; 478 474 init_dma(cp, OUTPUT_LAST, write_postamble, sizeof(write_postamble)); 479 475 } else { 480 - init_dma(cp, INPUT_LAST, fd_req->buffer, n * 512); 476 + init_dma(cp, INPUT_LAST, req->buffer, n * 512); 481 477 } 482 478 ++cp; 483 479 out_le16(&cp->command, DBDMA_STOP); 484 480 out_8(&sw->control_bic, DO_ACTION | WRITE_SECTORS); 485 481 in_8(&sw->error); 486 482 out_8(&sw->control_bic, DO_ACTION | WRITE_SECTORS); 487 - if (rq_data_dir(fd_req) == WRITE) 483 + if (rq_data_dir(req) == WRITE) 488 484 out_8(&sw->control_bis, WRITE_SECTORS); 489 485 in_8(&sw->intr); 490 486 out_le32(&dr->control, (RUN << 16) | RUN); ··· 502 488 static void act(struct floppy_state *fs) 503 489 { 504 490 for (;;) { 491 + swim3_dbg(" act loop, state=%d, req_cyl=%d, cur_cyl=%d\n", 492 + fs->state, fs->req_cyl, fs->cur_cyl); 493 + 505 494 switch (fs->state) { 506 495 case idle: 507 496 return; /* XXX shouldn't get here */ 508 497 509 498 case locating: 510 499 if (swim3_readbit(fs, TRACK_ZERO)) { 500 + swim3_dbg("%s", " locate track 0\n"); 511 501 fs->cur_cyl = 0; 512 502 if (fs->req_cyl == 0) 513 503 fs->state = do_transfer; ··· 529 511 break; 530 512 } 531 513 if (fs->req_cyl == fs->cur_cyl) { 532 - printk("whoops, seeking 0\n"); 514 + swim3_warn("%s", "Whoops, seeking 0\n"); 533 515 fs->state = do_transfer; 534 516 break; 535 517 } ··· 545 527 case do_transfer: 546 528 if (fs->cur_cyl != fs->req_cyl) { 547 529 if (fs->retries > 5) { 548 - swim3_end_request_cur(-EIO); 530 + swim3_err("Wrong cylinder in transfer, want: %d got %d\n", 531 + fs->req_cyl, fs->cur_cyl); 532 + swim3_end_request(fs, -EIO, 0); 549 533 fs->state = idle; 550 534 return; 551 535 } ··· 562 542 return; 563 543 564 544 default: 565 - printk(KERN_ERR"swim3: unknown state %d\n", fs->state); 545 + swim3_err("Unknown state %d\n", fs->state); 566 546 return; 567 547 } 568 548 } ··· 572 552 { 573 553 struct floppy_state *fs = (struct floppy_state *) data; 574 554 struct swim3 __iomem *sw = fs->swim3; 555 + unsigned long flags; 575 556 557 + swim3_dbg("* scan timeout, state=%d\n", fs->state); 558 + 559 + spin_lock_irqsave(&swim3_lock, flags); 576 560 fs->timeout_pending = 0; 577 561 out_8(&sw->control_bic, DO_ACTION | WRITE_SECTORS); 578 562 out_8(&sw->select, RELAX); 579 563 out_8(&sw->intr_enable, 0); 580 564 fs->cur_cyl = -1; 581 565 if (fs->retries > 5) { 582 - swim3_end_request_cur(-EIO); 566 + swim3_end_request(fs, -EIO, 0); 583 567 fs->state = idle; 584 568 start_request(fs); 585 569 } else { 586 570 fs->state = jogging; 587 571 act(fs); 588 572 } 573 + spin_unlock_irqrestore(&swim3_lock, flags); 589 574 } 590 575 591 576 static void seek_timeout(unsigned long data) 592 577 { 593 578 struct floppy_state *fs = (struct floppy_state *) data; 594 579 struct swim3 __iomem *sw = fs->swim3; 580 + unsigned long flags; 595 581 582 + swim3_dbg("* seek timeout, state=%d\n", fs->state); 583 + 584 + spin_lock_irqsave(&swim3_lock, flags); 596 585 fs->timeout_pending = 0; 597 586 out_8(&sw->control_bic, DO_SEEK); 598 587 out_8(&sw->select, RELAX); 599 588 out_8(&sw->intr_enable, 0); 600 - printk(KERN_ERR "swim3: seek timeout\n"); 601 - swim3_end_request_cur(-EIO); 589 + swim3_err("%s", "Seek timeout\n"); 590 + swim3_end_request(fs, -EIO, 0); 602 591 fs->state = idle; 603 592 start_request(fs); 593 + spin_unlock_irqrestore(&swim3_lock, flags); 604 594 } 605 595 606 596 static void settle_timeout(unsigned long data) 607 597 { 608 598 struct floppy_state *fs = (struct floppy_state *) data; 609 599 struct swim3 __iomem *sw = fs->swim3; 600 + unsigned long flags; 610 601 602 + swim3_dbg("* settle timeout, state=%d\n", fs->state); 603 + 604 + spin_lock_irqsave(&swim3_lock, flags); 611 605 fs->timeout_pending = 0; 612 606 if (swim3_readbit(fs, SEEK_COMPLETE)) { 613 607 out_8(&sw->select, RELAX); 614 608 fs->state = locating; 615 609 act(fs); 616 - return; 610 + goto unlock; 617 611 } 618 612 out_8(&sw->select, RELAX); 619 613 if (fs->settle_time < 2*HZ) { 620 614 ++fs->settle_time; 621 615 set_timeout(fs, 1, settle_timeout); 622 - return; 616 + goto unlock; 623 617 } 624 - printk(KERN_ERR "swim3: seek settle timeout\n"); 625 - swim3_end_request_cur(-EIO); 618 + swim3_err("%s", "Seek settle timeout\n"); 619 + swim3_end_request(fs, -EIO, 0); 626 620 fs->state = idle; 627 621 start_request(fs); 622 + unlock: 623 + spin_unlock_irqrestore(&swim3_lock, flags); 628 624 } 629 625 630 626 static void xfer_timeout(unsigned long data) ··· 648 612 struct floppy_state *fs = (struct floppy_state *) data; 649 613 struct swim3 __iomem *sw = fs->swim3; 650 614 struct dbdma_regs __iomem *dr = fs->dma; 615 + unsigned long flags; 651 616 int n; 652 617 618 + swim3_dbg("* xfer timeout, state=%d\n", fs->state); 619 + 620 + spin_lock_irqsave(&swim3_lock, flags); 653 621 fs->timeout_pending = 0; 654 622 out_le32(&dr->control, RUN << 16); 655 623 /* We must wait a bit for dbdma to stop */ ··· 662 622 out_8(&sw->intr_enable, 0); 663 623 out_8(&sw->control_bic, WRITE_SECTORS | DO_ACTION); 664 624 out_8(&sw->select, RELAX); 665 - printk(KERN_ERR "swim3: timeout %sing sector %ld\n", 666 - (rq_data_dir(fd_req)==WRITE? "writ": "read"), 667 - (long)blk_rq_pos(fd_req)); 668 - swim3_end_request_cur(-EIO); 625 + swim3_err("Timeout %sing sector %ld\n", 626 + (rq_data_dir(fs->cur_req)==WRITE? "writ": "read"), 627 + (long)blk_rq_pos(fs->cur_req)); 628 + swim3_end_request(fs, -EIO, 0); 669 629 fs->state = idle; 670 630 start_request(fs); 631 + spin_unlock_irqrestore(&swim3_lock, flags); 671 632 } 672 633 673 634 static irqreturn_t swim3_interrupt(int irq, void *dev_id) ··· 679 638 int stat, resid; 680 639 struct dbdma_regs __iomem *dr; 681 640 struct dbdma_cmd *cp; 641 + unsigned long flags; 642 + struct request *req = fs->cur_req; 682 643 644 + swim3_dbg("* interrupt, state=%d\n", fs->state); 645 + 646 + spin_lock_irqsave(&swim3_lock, flags); 683 647 intr = in_8(&sw->intr); 684 648 err = (intr & ERROR_INTR)? in_8(&sw->error): 0; 685 649 if ((intr & ERROR_INTR) && fs->state != do_transfer) 686 - printk(KERN_ERR "swim3_interrupt, state=%d, dir=%x, intr=%x, err=%x\n", 687 - fs->state, rq_data_dir(fd_req), intr, err); 650 + swim3_err("Non-transfer error interrupt: state=%d, dir=%x, intr=%x, err=%x\n", 651 + fs->state, rq_data_dir(req), intr, err); 688 652 switch (fs->state) { 689 653 case locating: 690 654 if (intr & SEEN_SECTOR) { ··· 699 653 del_timer(&fs->timeout); 700 654 fs->timeout_pending = 0; 701 655 if (sw->ctrack == 0xff) { 702 - printk(KERN_ERR "swim3: seen sector but cyl=ff?\n"); 656 + swim3_err("%s", "Seen sector but cyl=ff?\n"); 703 657 fs->cur_cyl = -1; 704 658 if (fs->retries > 5) { 705 - swim3_end_request_cur(-EIO); 659 + swim3_end_request(fs, -EIO, 0); 706 660 fs->state = idle; 707 661 start_request(fs); 708 662 } else { ··· 714 668 fs->cur_cyl = sw->ctrack; 715 669 fs->cur_sector = sw->csect; 716 670 if (fs->expect_cyl != -1 && fs->expect_cyl != fs->cur_cyl) 717 - printk(KERN_ERR "swim3: expected cyl %d, got %d\n", 718 - fs->expect_cyl, fs->cur_cyl); 671 + swim3_err("Expected cyl %d, got %d\n", 672 + fs->expect_cyl, fs->cur_cyl); 719 673 fs->state = do_transfer; 720 674 act(fs); 721 675 } ··· 750 704 fs->timeout_pending = 0; 751 705 dr = fs->dma; 752 706 cp = fs->dma_cmd; 753 - if (rq_data_dir(fd_req) == WRITE) 707 + if (rq_data_dir(req) == WRITE) 754 708 ++cp; 755 709 /* 756 710 * Check that the main data transfer has finished. ··· 775 729 if (intr & ERROR_INTR) { 776 730 n = fs->scount - 1 - resid / 512; 777 731 if (n > 0) { 778 - blk_update_request(fd_req, 0, n << 9); 732 + blk_update_request(req, 0, n << 9); 779 733 fs->req_sector += n; 780 734 } 781 735 if (fs->retries < 5) { 782 736 ++fs->retries; 783 737 act(fs); 784 738 } else { 785 - printk("swim3: error %sing block %ld (err=%x)\n", 786 - rq_data_dir(fd_req) == WRITE? "writ": "read", 787 - (long)blk_rq_pos(fd_req), err); 788 - swim3_end_request_cur(-EIO); 739 + swim3_err("Error %sing block %ld (err=%x)\n", 740 + rq_data_dir(req) == WRITE? "writ": "read", 741 + (long)blk_rq_pos(req), err); 742 + swim3_end_request(fs, -EIO, 0); 789 743 fs->state = idle; 790 744 } 791 745 } else { 792 746 if ((stat & ACTIVE) == 0 || resid != 0) { 793 747 /* musta been an error */ 794 - printk(KERN_ERR "swim3: fd dma: stat=%x resid=%d\n", stat, resid); 795 - printk(KERN_ERR " state=%d, dir=%x, intr=%x, err=%x\n", 796 - fs->state, rq_data_dir(fd_req), intr, err); 797 - swim3_end_request_cur(-EIO); 748 + swim3_err("fd dma error: stat=%x resid=%d\n", stat, resid); 749 + swim3_err(" state=%d, dir=%x, intr=%x, err=%x\n", 750 + fs->state, rq_data_dir(req), intr, err); 751 + swim3_end_request(fs, -EIO, 0); 798 752 fs->state = idle; 799 753 start_request(fs); 800 754 break; 801 755 } 802 - if (swim3_end_request(0, fs->scount << 9)) { 756 + fs->retries = 0; 757 + if (swim3_end_request(fs, 0, fs->scount << 9)) { 803 758 fs->req_sector += fs->scount; 804 759 if (fs->req_sector > fs->secpertrack) { 805 760 fs->req_sector -= fs->secpertrack; ··· 817 770 start_request(fs); 818 771 break; 819 772 default: 820 - printk(KERN_ERR "swim3: don't know what to do in state %d\n", fs->state); 773 + swim3_err("Don't know what to do in state %d\n", fs->state); 821 774 } 775 + spin_unlock_irqrestore(&swim3_lock, flags); 822 776 return IRQ_HANDLED; 823 777 } 824 778 ··· 829 781 } 830 782 */ 831 783 784 + /* Called under the mutex to grab exclusive access to a drive */ 832 785 static int grab_drive(struct floppy_state *fs, enum swim_state state, 833 786 int interruptible) 834 787 { 835 788 unsigned long flags; 836 789 837 - spin_lock_irqsave(&fs->lock, flags); 838 - if (fs->state != idle) { 790 + swim3_dbg("%s", "-> grab drive\n"); 791 + 792 + spin_lock_irqsave(&swim3_lock, flags); 793 + if (fs->state != idle && fs->state != available) { 839 794 ++fs->wanted; 840 795 while (fs->state != available) { 796 + spin_unlock_irqrestore(&swim3_lock, flags); 841 797 if (interruptible && signal_pending(current)) { 842 798 --fs->wanted; 843 - spin_unlock_irqrestore(&fs->lock, flags); 844 799 return -EINTR; 845 800 } 846 801 interruptible_sleep_on(&fs->wait); 802 + spin_lock_irqsave(&swim3_lock, flags); 847 803 } 848 804 --fs->wanted; 849 805 } 850 806 fs->state = state; 851 - spin_unlock_irqrestore(&fs->lock, flags); 807 + spin_unlock_irqrestore(&swim3_lock, flags); 808 + 852 809 return 0; 853 810 } 854 811 ··· 861 808 { 862 809 unsigned long flags; 863 810 864 - spin_lock_irqsave(&fs->lock, flags); 811 + swim3_dbg("%s", "-> release drive\n"); 812 + 813 + spin_lock_irqsave(&swim3_lock, flags); 865 814 fs->state = idle; 866 815 start_request(fs); 867 - spin_unlock_irqrestore(&fs->lock, flags); 816 + spin_unlock_irqrestore(&swim3_lock, flags); 868 817 } 869 818 870 819 static int fd_eject(struct floppy_state *fs) ··· 1021 966 { 1022 967 struct floppy_state *fs = disk->private_data; 1023 968 struct swim3 __iomem *sw = fs->swim3; 969 + 1024 970 mutex_lock(&swim3_mutex); 1025 971 if (fs->ref_count > 0 && --fs->ref_count == 0) { 1026 972 swim3_action(fs, MOTOR_OFF); ··· 1087 1031 .revalidate_disk= floppy_revalidate, 1088 1032 }; 1089 1033 1034 + static void swim3_mb_event(struct macio_dev* mdev, int mb_state) 1035 + { 1036 + struct floppy_state *fs = macio_get_drvdata(mdev); 1037 + struct swim3 __iomem *sw = fs->swim3; 1038 + 1039 + if (!fs) 1040 + return; 1041 + if (mb_state != MB_FD) 1042 + return; 1043 + 1044 + /* Clear state */ 1045 + out_8(&sw->intr_enable, 0); 1046 + in_8(&sw->intr); 1047 + in_8(&sw->error); 1048 + } 1049 + 1090 1050 static int swim3_add_device(struct macio_dev *mdev, int index) 1091 1051 { 1092 1052 struct device_node *swim = mdev->ofdev.dev.of_node; 1093 1053 struct floppy_state *fs = &floppy_states[index]; 1094 1054 int rc = -EBUSY; 1095 1055 1056 + /* Do this first for message macros */ 1057 + memset(fs, 0, sizeof(*fs)); 1058 + fs->mdev = mdev; 1059 + fs->index = index; 1060 + 1096 1061 /* Check & Request resources */ 1097 1062 if (macio_resource_count(mdev) < 2) { 1098 - printk(KERN_WARNING "ifd%d: no address for %s\n", 1099 - index, swim->full_name); 1063 + swim3_err("%s", "No address in device-tree\n"); 1100 1064 return -ENXIO; 1101 1065 } 1102 - if (macio_irq_count(mdev) < 2) { 1103 - printk(KERN_WARNING "fd%d: no intrs for device %s\n", 1104 - index, swim->full_name); 1066 + if (macio_irq_count(mdev) < 1) { 1067 + swim3_err("%s", "No interrupt in device-tree\n"); 1068 + return -ENXIO; 1105 1069 } 1106 1070 if (macio_request_resource(mdev, 0, "swim3 (mmio)")) { 1107 - printk(KERN_ERR "fd%d: can't request mmio resource for %s\n", 1108 - index, swim->full_name); 1071 + swim3_err("%s", "Can't request mmio resource\n"); 1109 1072 return -EBUSY; 1110 1073 } 1111 1074 if (macio_request_resource(mdev, 1, "swim3 (dma)")) { 1112 - printk(KERN_ERR "fd%d: can't request dma resource for %s\n", 1113 - index, swim->full_name); 1075 + swim3_err("%s", "Can't request dma resource\n"); 1114 1076 macio_release_resource(mdev, 0); 1115 1077 return -EBUSY; 1116 1078 } ··· 1137 1063 if (mdev->media_bay == NULL) 1138 1064 pmac_call_feature(PMAC_FTR_SWIM3_ENABLE, swim, 0, 1); 1139 1065 1140 - memset(fs, 0, sizeof(*fs)); 1141 - spin_lock_init(&fs->lock); 1142 1066 fs->state = idle; 1143 1067 fs->swim3 = (struct swim3 __iomem *) 1144 1068 ioremap(macio_resource_start(mdev, 0), 0x200); 1145 1069 if (fs->swim3 == NULL) { 1146 - printk("fd%d: couldn't map registers for %s\n", 1147 - index, swim->full_name); 1070 + swim3_err("%s", "Couldn't map mmio registers\n"); 1148 1071 rc = -ENOMEM; 1149 1072 goto out_release; 1150 1073 } 1151 1074 fs->dma = (struct dbdma_regs __iomem *) 1152 1075 ioremap(macio_resource_start(mdev, 1), 0x200); 1153 1076 if (fs->dma == NULL) { 1154 - printk("fd%d: couldn't map DMA for %s\n", 1155 - index, swim->full_name); 1077 + swim3_err("%s", "Couldn't map dma registers\n"); 1156 1078 iounmap(fs->swim3); 1157 1079 rc = -ENOMEM; 1158 1080 goto out_release; ··· 1160 1090 fs->secpercyl = 36; 1161 1091 fs->secpertrack = 18; 1162 1092 fs->total_secs = 2880; 1163 - fs->mdev = mdev; 1164 1093 init_waitqueue_head(&fs->wait); 1165 1094 1166 1095 fs->dma_cmd = (struct dbdma_cmd *) DBDMA_ALIGN(fs->dbdma_cmd_space); 1167 1096 memset(fs->dma_cmd, 0, 2 * sizeof(struct dbdma_cmd)); 1168 1097 st_le16(&fs->dma_cmd[1].command, DBDMA_STOP); 1169 1098 1099 + if (mdev->media_bay == NULL || check_media_bay(mdev->media_bay) == MB_FD) 1100 + swim3_mb_event(mdev, MB_FD); 1101 + 1170 1102 if (request_irq(fs->swim3_intr, swim3_interrupt, 0, "SWIM3", fs)) { 1171 - printk(KERN_ERR "fd%d: couldn't request irq %d for %s\n", 1172 - index, fs->swim3_intr, swim->full_name); 1103 + swim3_err("%s", "Couldn't request interrupt\n"); 1173 1104 pmac_call_feature(PMAC_FTR_SWIM3_ENABLE, swim, 0, 0); 1174 1105 goto out_unmap; 1175 1106 return -EBUSY; 1176 1107 } 1177 - /* 1178 - if (request_irq(fs->dma_intr, fd_dma_interrupt, 0, "SWIM3-dma", fs)) { 1179 - printk(KERN_ERR "Couldn't get irq %d for SWIM3 DMA", 1180 - fs->dma_intr); 1181 - return -EBUSY; 1182 - } 1183 - */ 1184 1108 1185 1109 init_timer(&fs->timeout); 1186 1110 1187 - printk(KERN_INFO "fd%d: SWIM3 floppy controller %s\n", floppy_count, 1111 + swim3_info("SWIM3 floppy controller %s\n", 1188 1112 mdev->media_bay ? "in media bay" : ""); 1189 1113 1190 1114 return 0; ··· 1196 1132 1197 1133 static int __devinit swim3_attach(struct macio_dev *mdev, const struct of_device_id *match) 1198 1134 { 1199 - int i, rc; 1200 1135 struct gendisk *disk; 1136 + int index, rc; 1137 + 1138 + index = floppy_count++; 1139 + if (index >= MAX_FLOPPIES) 1140 + return -ENXIO; 1201 1141 1202 1142 /* Add the drive */ 1203 - rc = swim3_add_device(mdev, floppy_count); 1143 + rc = swim3_add_device(mdev, index); 1204 1144 if (rc) 1205 1145 return rc; 1146 + /* Now register that disk. Same comment about failure handling */ 1147 + disk = disks[index] = alloc_disk(1); 1148 + if (disk == NULL) 1149 + return -ENOMEM; 1150 + disk->queue = blk_init_queue(do_fd_request, &swim3_lock); 1151 + if (disk->queue == NULL) { 1152 + put_disk(disk); 1153 + return -ENOMEM; 1154 + } 1155 + disk->queue->queuedata = &floppy_states[index]; 1206 1156 1207 - /* Now create the queue if not there yet */ 1208 - if (swim3_queue == NULL) { 1157 + if (index == 0) { 1209 1158 /* If we failed, there isn't much we can do as the driver is still 1210 1159 * too dumb to remove the device, just bail out 1211 1160 */ 1212 1161 if (register_blkdev(FLOPPY_MAJOR, "fd")) 1213 1162 return 0; 1214 - swim3_queue = blk_init_queue(do_fd_request, &swim3_lock); 1215 - if (swim3_queue == NULL) { 1216 - unregister_blkdev(FLOPPY_MAJOR, "fd"); 1217 - return 0; 1218 - } 1219 1163 } 1220 1164 1221 - /* Now register that disk. Same comment about failure handling */ 1222 - i = floppy_count++; 1223 - disk = disks[i] = alloc_disk(1); 1224 - if (disk == NULL) 1225 - return 0; 1226 - 1227 1165 disk->major = FLOPPY_MAJOR; 1228 - disk->first_minor = i; 1166 + disk->first_minor = index; 1229 1167 disk->fops = &floppy_fops; 1230 - disk->private_data = &floppy_states[i]; 1231 - disk->queue = swim3_queue; 1168 + disk->private_data = &floppy_states[index]; 1232 1169 disk->flags |= GENHD_FL_REMOVABLE; 1233 - sprintf(disk->disk_name, "fd%d", i); 1170 + sprintf(disk->disk_name, "fd%d", index); 1234 1171 set_capacity(disk, 2880); 1235 1172 add_disk(disk); 1236 1173 ··· 1259 1194 .of_match_table = swim3_match, 1260 1195 }, 1261 1196 .probe = swim3_attach, 1197 + #ifdef CONFIG_PMAC_MEDIABAY 1198 + .mediabay_event = swim3_mb_event, 1199 + #endif 1262 1200 #if 0 1263 1201 .suspend = swim3_suspend, 1264 1202 .resume = swim3_resume,
-3
include/linux/blkdev.h
··· 805 805 */ 806 806 extern struct request_queue *blk_init_queue_node(request_fn_proc *rfn, 807 807 spinlock_t *lock, int node_id); 808 - extern struct request_queue *blk_init_allocated_queue_node(struct request_queue *, 809 - request_fn_proc *, 810 - spinlock_t *, int node_id); 811 808 extern struct request_queue *blk_init_queue(request_fn_proc *, spinlock_t *); 812 809 extern struct request_queue *blk_init_allocated_queue(struct request_queue *, 813 810 request_fn_proc *, spinlock_t *);