| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * linux/drivers/block/floppy.c |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 170 | 171 | #include <linux/kernel.h> |
|---|
| 171 | 172 | #include <linux/timer.h> |
|---|
| 172 | 173 | #include <linux/workqueue.h> |
|---|
| 173 | | -#define FDPATCHES |
|---|
| 174 | 174 | #include <linux/fdreg.h> |
|---|
| 175 | 175 | #include <linux/fd.h> |
|---|
| 176 | 176 | #include <linux/hdreg.h> |
|---|
| .. | .. |
|---|
| 252 | 252 | |
|---|
| 253 | 253 | static int irqdma_allocated; |
|---|
| 254 | 254 | |
|---|
| 255 | | -#include <linux/blkdev.h> |
|---|
| 255 | +#include <linux/blk-mq.h> |
|---|
| 256 | 256 | #include <linux/blkpg.h> |
|---|
| 257 | 257 | #include <linux/cdrom.h> /* for the compatibility eject ioctl */ |
|---|
| 258 | 258 | #include <linux/completion.h> |
|---|
| 259 | 259 | |
|---|
| 260 | +static LIST_HEAD(floppy_reqs); |
|---|
| 260 | 261 | static struct request *current_req; |
|---|
| 261 | | -static void do_fd_request(struct request_queue *q); |
|---|
| 262 | 262 | static int set_next_request(void); |
|---|
| 263 | 263 | |
|---|
| 264 | 264 | #ifndef fd_get_dma_residue |
|---|
| .. | .. |
|---|
| 305 | 305 | /* reverse mapping from unit and fdc to drive */ |
|---|
| 306 | 306 | #define REVDRIVE(fdc, unit) ((unit) + ((fdc) << 2)) |
|---|
| 307 | 307 | |
|---|
| 308 | | -#define DP (&drive_params[current_drive]) |
|---|
| 309 | | -#define DRS (&drive_state[current_drive]) |
|---|
| 310 | | -#define DRWE (&write_errors[current_drive]) |
|---|
| 311 | | -#define FDCS (&fdc_state[fdc]) |
|---|
| 312 | | - |
|---|
| 313 | | -#define UDP (&drive_params[drive]) |
|---|
| 314 | | -#define UDRS (&drive_state[drive]) |
|---|
| 315 | | -#define UDRWE (&write_errors[drive]) |
|---|
| 316 | | -#define UFDCS (&fdc_state[FDC(drive)]) |
|---|
| 317 | | - |
|---|
| 318 | 308 | #define PH_HEAD(floppy, head) (((((floppy)->stretch & 2) >> 1) ^ head) << 2) |
|---|
| 319 | 309 | #define STRETCH(floppy) ((floppy)->stretch & FD_STRETCH) |
|---|
| 320 | 310 | |
|---|
| 321 | | -/* read/write */ |
|---|
| 322 | | -#define COMMAND (raw_cmd->cmd[0]) |
|---|
| 323 | | -#define DR_SELECT (raw_cmd->cmd[1]) |
|---|
| 324 | | -#define TRACK (raw_cmd->cmd[2]) |
|---|
| 325 | | -#define HEAD (raw_cmd->cmd[3]) |
|---|
| 326 | | -#define SECTOR (raw_cmd->cmd[4]) |
|---|
| 327 | | -#define SIZECODE (raw_cmd->cmd[5]) |
|---|
| 328 | | -#define SECT_PER_TRACK (raw_cmd->cmd[6]) |
|---|
| 329 | | -#define GAP (raw_cmd->cmd[7]) |
|---|
| 330 | | -#define SIZECODE2 (raw_cmd->cmd[8]) |
|---|
| 311 | +/* read/write commands */ |
|---|
| 312 | +#define COMMAND 0 |
|---|
| 313 | +#define DR_SELECT 1 |
|---|
| 314 | +#define TRACK 2 |
|---|
| 315 | +#define HEAD 3 |
|---|
| 316 | +#define SECTOR 4 |
|---|
| 317 | +#define SIZECODE 5 |
|---|
| 318 | +#define SECT_PER_TRACK 6 |
|---|
| 319 | +#define GAP 7 |
|---|
| 320 | +#define SIZECODE2 8 |
|---|
| 331 | 321 | #define NR_RW 9 |
|---|
| 332 | 322 | |
|---|
| 333 | | -/* format */ |
|---|
| 334 | | -#define F_SIZECODE (raw_cmd->cmd[2]) |
|---|
| 335 | | -#define F_SECT_PER_TRACK (raw_cmd->cmd[3]) |
|---|
| 336 | | -#define F_GAP (raw_cmd->cmd[4]) |
|---|
| 337 | | -#define F_FILL (raw_cmd->cmd[5]) |
|---|
| 323 | +/* format commands */ |
|---|
| 324 | +#define F_SIZECODE 2 |
|---|
| 325 | +#define F_SECT_PER_TRACK 3 |
|---|
| 326 | +#define F_GAP 4 |
|---|
| 327 | +#define F_FILL 5 |
|---|
| 338 | 328 | #define NR_F 6 |
|---|
| 339 | 329 | |
|---|
| 340 | 330 | /* |
|---|
| .. | .. |
|---|
| 347 | 337 | /* |
|---|
| 348 | 338 | * globals used by 'result()' |
|---|
| 349 | 339 | */ |
|---|
| 350 | | -#define MAX_REPLIES 16 |
|---|
| 351 | | -static unsigned char reply_buffer[MAX_REPLIES]; |
|---|
| 340 | +static unsigned char reply_buffer[FD_RAW_REPLY_SIZE]; |
|---|
| 352 | 341 | static int inr; /* size of reply buffer, when called from interrupt */ |
|---|
| 353 | | -#define ST0 (reply_buffer[0]) |
|---|
| 354 | | -#define ST1 (reply_buffer[1]) |
|---|
| 355 | | -#define ST2 (reply_buffer[2]) |
|---|
| 356 | | -#define ST3 (reply_buffer[0]) /* result of GETSTATUS */ |
|---|
| 357 | | -#define R_TRACK (reply_buffer[3]) |
|---|
| 358 | | -#define R_HEAD (reply_buffer[4]) |
|---|
| 359 | | -#define R_SECTOR (reply_buffer[5]) |
|---|
| 360 | | -#define R_SIZECODE (reply_buffer[6]) |
|---|
| 342 | +#define ST0 0 |
|---|
| 343 | +#define ST1 1 |
|---|
| 344 | +#define ST2 2 |
|---|
| 345 | +#define ST3 0 /* result of GETSTATUS */ |
|---|
| 346 | +#define R_TRACK 3 |
|---|
| 347 | +#define R_HEAD 4 |
|---|
| 348 | +#define R_SECTOR 5 |
|---|
| 349 | +#define R_SIZECODE 6 |
|---|
| 361 | 350 | |
|---|
| 362 | 351 | #define SEL_DLY (2 * HZ / 100) |
|---|
| 363 | 352 | |
|---|
| .. | .. |
|---|
| 414 | 403 | static struct floppy_write_errors write_errors[N_DRIVE]; |
|---|
| 415 | 404 | static struct timer_list motor_off_timer[N_DRIVE]; |
|---|
| 416 | 405 | static struct gendisk *disks[N_DRIVE]; |
|---|
| 406 | +static struct blk_mq_tag_set tag_sets[N_DRIVE]; |
|---|
| 417 | 407 | static struct block_device *opened_bdev[N_DRIVE]; |
|---|
| 418 | 408 | static DEFINE_MUTEX(open_lock); |
|---|
| 419 | 409 | static struct floppy_raw_cmd *raw_cmd, default_raw_cmd; |
|---|
| 420 | | -static int fdc_queue; |
|---|
| 421 | 410 | |
|---|
| 422 | 411 | /* |
|---|
| 423 | 412 | * This struct defines the different floppy types. |
|---|
| .. | .. |
|---|
| 520 | 509 | static DECLARE_WAIT_QUEUE_HEAD(fdc_wait); |
|---|
| 521 | 510 | static DECLARE_WAIT_QUEUE_HEAD(command_done); |
|---|
| 522 | 511 | |
|---|
| 523 | | -/* Errors during formatting are counted here. */ |
|---|
| 524 | | -static int format_errors; |
|---|
| 512 | +/* errors encountered on the current (or last) request */ |
|---|
| 513 | +static int floppy_errors; |
|---|
| 525 | 514 | |
|---|
| 526 | 515 | /* Format request descriptor. */ |
|---|
| 527 | 516 | static struct format_descr format_req; |
|---|
| .. | .. |
|---|
| 541 | 530 | static char *floppy_track_buffer; |
|---|
| 542 | 531 | static int max_buffer_sectors; |
|---|
| 543 | 532 | |
|---|
| 544 | | -static int *errors; |
|---|
| 545 | 533 | typedef void (*done_f)(int); |
|---|
| 546 | 534 | static const struct cont_t { |
|---|
| 547 | 535 | void (*interrupt)(void); |
|---|
| .. | .. |
|---|
| 572 | 560 | * output_byte is automatically disabled when reset is set. |
|---|
| 573 | 561 | */ |
|---|
| 574 | 562 | static void reset_fdc(void); |
|---|
| 563 | +static int floppy_revalidate(struct gendisk *disk); |
|---|
| 575 | 564 | |
|---|
| 576 | 565 | /* |
|---|
| 577 | 566 | * These are global variables, as that's the easiest way to give |
|---|
| .. | .. |
|---|
| 592 | 581 | |
|---|
| 593 | 582 | /* fdc related variables, should end up in a struct */ |
|---|
| 594 | 583 | static struct floppy_fdc_state fdc_state[N_FDC]; |
|---|
| 595 | | -static int fdc; /* current fdc */ |
|---|
| 584 | +static int current_fdc; /* current fdc */ |
|---|
| 596 | 585 | |
|---|
| 597 | 586 | static struct workqueue_struct *floppy_wq; |
|---|
| 598 | 587 | |
|---|
| .. | .. |
|---|
| 603 | 592 | static unsigned char in_sector_offset; /* offset within physical sector, |
|---|
| 604 | 593 | * expressed in units of 512 bytes */ |
|---|
| 605 | 594 | |
|---|
| 595 | +static inline unsigned char fdc_inb(int fdc, int reg) |
|---|
| 596 | +{ |
|---|
| 597 | + return fd_inb(fdc_state[fdc].address, reg); |
|---|
| 598 | +} |
|---|
| 599 | + |
|---|
| 600 | +static inline void fdc_outb(unsigned char value, int fdc, int reg) |
|---|
| 601 | +{ |
|---|
| 602 | + fd_outb(value, fdc_state[fdc].address, reg); |
|---|
| 603 | +} |
|---|
| 604 | + |
|---|
| 606 | 605 | static inline bool drive_no_geom(int drive) |
|---|
| 607 | 606 | { |
|---|
| 608 | | - return !current_type[drive] && !ITYPE(UDRS->fd_device); |
|---|
| 607 | + return !current_type[drive] && !ITYPE(drive_state[drive].fd_device); |
|---|
| 609 | 608 | } |
|---|
| 610 | 609 | |
|---|
| 611 | 610 | #ifndef fd_eject |
|---|
| .. | .. |
|---|
| 629 | 628 | |
|---|
| 630 | 629 | static inline void debugt(const char *func, const char *msg) |
|---|
| 631 | 630 | { |
|---|
| 632 | | - if (DP->flags & DEBUGT) |
|---|
| 631 | + if (drive_params[current_drive].flags & DEBUGT) |
|---|
| 633 | 632 | pr_info("%s:%s dtime=%lu\n", func, msg, jiffies - debugtimer); |
|---|
| 634 | 633 | } |
|---|
| 635 | 634 | #else |
|---|
| .. | .. |
|---|
| 668 | 667 | |
|---|
| 669 | 668 | static int output_log_pos; |
|---|
| 670 | 669 | |
|---|
| 671 | | -#define current_reqD -1 |
|---|
| 672 | 670 | #define MAXTIMEOUT -2 |
|---|
| 673 | 671 | |
|---|
| 674 | 672 | static void __reschedule_timeout(int drive, const char *message) |
|---|
| 675 | 673 | { |
|---|
| 676 | 674 | unsigned long delay; |
|---|
| 677 | 675 | |
|---|
| 678 | | - if (drive == current_reqD) |
|---|
| 679 | | - drive = current_drive; |
|---|
| 680 | | - |
|---|
| 681 | 676 | if (drive < 0 || drive >= N_DRIVE) { |
|---|
| 682 | 677 | delay = 20UL * HZ; |
|---|
| 683 | 678 | drive = 0; |
|---|
| 684 | 679 | } else |
|---|
| 685 | | - delay = UDP->timeout; |
|---|
| 680 | + delay = drive_params[drive].timeout; |
|---|
| 686 | 681 | |
|---|
| 687 | 682 | mod_delayed_work(floppy_wq, &fd_timeout, delay); |
|---|
| 688 | | - if (UDP->flags & FD_DEBUG) |
|---|
| 683 | + if (drive_params[drive].flags & FD_DEBUG) |
|---|
| 689 | 684 | DPRINT("reschedule timeout %s\n", message); |
|---|
| 690 | 685 | timeout_message = message; |
|---|
| 691 | 686 | } |
|---|
| .. | .. |
|---|
| 739 | 734 | { |
|---|
| 740 | 735 | int fdc = FDC(drive); |
|---|
| 741 | 736 | |
|---|
| 742 | | - if (time_before(jiffies, UDRS->select_date + UDP->select_delay)) |
|---|
| 737 | + if (time_before(jiffies, drive_state[drive].select_date + drive_params[drive].select_delay)) |
|---|
| 743 | 738 | DPRINT("WARNING disk change called early\n"); |
|---|
| 744 | | - if (!(FDCS->dor & (0x10 << UNIT(drive))) || |
|---|
| 745 | | - (FDCS->dor & 3) != UNIT(drive) || fdc != FDC(drive)) { |
|---|
| 739 | + if (!(fdc_state[fdc].dor & (0x10 << UNIT(drive))) || |
|---|
| 740 | + (fdc_state[fdc].dor & 3) != UNIT(drive) || fdc != FDC(drive)) { |
|---|
| 746 | 741 | DPRINT("probing disk change on unselected drive\n"); |
|---|
| 747 | 742 | DPRINT("drive=%d fdc=%d dor=%x\n", drive, FDC(drive), |
|---|
| 748 | | - (unsigned int)FDCS->dor); |
|---|
| 743 | + (unsigned int)fdc_state[fdc].dor); |
|---|
| 749 | 744 | } |
|---|
| 750 | 745 | |
|---|
| 751 | | - debug_dcl(UDP->flags, |
|---|
| 746 | + debug_dcl(drive_params[drive].flags, |
|---|
| 752 | 747 | "checking disk change line for drive %d\n", drive); |
|---|
| 753 | | - debug_dcl(UDP->flags, "jiffies=%lu\n", jiffies); |
|---|
| 754 | | - debug_dcl(UDP->flags, "disk change line=%x\n", fd_inb(FD_DIR) & 0x80); |
|---|
| 755 | | - debug_dcl(UDP->flags, "flags=%lx\n", UDRS->flags); |
|---|
| 748 | + debug_dcl(drive_params[drive].flags, "jiffies=%lu\n", jiffies); |
|---|
| 749 | + debug_dcl(drive_params[drive].flags, "disk change line=%x\n", |
|---|
| 750 | + fdc_inb(fdc, FD_DIR) & 0x80); |
|---|
| 751 | + debug_dcl(drive_params[drive].flags, "flags=%lx\n", |
|---|
| 752 | + drive_state[drive].flags); |
|---|
| 756 | 753 | |
|---|
| 757 | | - if (UDP->flags & FD_BROKEN_DCL) |
|---|
| 758 | | - return test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); |
|---|
| 759 | | - if ((fd_inb(FD_DIR) ^ UDP->flags) & 0x80) { |
|---|
| 760 | | - set_bit(FD_VERIFY_BIT, &UDRS->flags); |
|---|
| 754 | + if (drive_params[drive].flags & FD_BROKEN_DCL) |
|---|
| 755 | + return test_bit(FD_DISK_CHANGED_BIT, |
|---|
| 756 | + &drive_state[drive].flags); |
|---|
| 757 | + if ((fdc_inb(fdc, FD_DIR) ^ drive_params[drive].flags) & 0x80) { |
|---|
| 758 | + set_bit(FD_VERIFY_BIT, &drive_state[drive].flags); |
|---|
| 761 | 759 | /* verify write protection */ |
|---|
| 762 | 760 | |
|---|
| 763 | | - if (UDRS->maxblock) /* mark it changed */ |
|---|
| 764 | | - set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); |
|---|
| 761 | + if (drive_state[drive].maxblock) /* mark it changed */ |
|---|
| 762 | + set_bit(FD_DISK_CHANGED_BIT, |
|---|
| 763 | + &drive_state[drive].flags); |
|---|
| 765 | 764 | |
|---|
| 766 | 765 | /* invalidate its geometry */ |
|---|
| 767 | | - if (UDRS->keep_data >= 0) { |
|---|
| 768 | | - if ((UDP->flags & FTD_MSG) && |
|---|
| 766 | + if (drive_state[drive].keep_data >= 0) { |
|---|
| 767 | + if ((drive_params[drive].flags & FTD_MSG) && |
|---|
| 769 | 768 | current_type[drive] != NULL) |
|---|
| 770 | 769 | DPRINT("Disk type is undefined after disk change\n"); |
|---|
| 771 | 770 | current_type[drive] = NULL; |
|---|
| .. | .. |
|---|
| 774 | 773 | |
|---|
| 775 | 774 | return 1; |
|---|
| 776 | 775 | } else { |
|---|
| 777 | | - UDRS->last_checked = jiffies; |
|---|
| 778 | | - clear_bit(FD_DISK_NEWCHANGE_BIT, &UDRS->flags); |
|---|
| 776 | + drive_state[drive].last_checked = jiffies; |
|---|
| 777 | + clear_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[drive].flags); |
|---|
| 779 | 778 | } |
|---|
| 780 | 779 | return 0; |
|---|
| 781 | 780 | } |
|---|
| .. | .. |
|---|
| 798 | 797 | unsigned char newdor; |
|---|
| 799 | 798 | unsigned char olddor; |
|---|
| 800 | 799 | |
|---|
| 801 | | - if (FDCS->address == -1) |
|---|
| 800 | + if (fdc_state[fdc].address == -1) |
|---|
| 802 | 801 | return -1; |
|---|
| 803 | 802 | |
|---|
| 804 | | - olddor = FDCS->dor; |
|---|
| 803 | + olddor = fdc_state[fdc].dor; |
|---|
| 805 | 804 | newdor = (olddor & mask) | data; |
|---|
| 806 | 805 | if (newdor != olddor) { |
|---|
| 807 | 806 | unit = olddor & 0x3; |
|---|
| 808 | 807 | if (is_selected(olddor, unit) && !is_selected(newdor, unit)) { |
|---|
| 809 | 808 | drive = REVDRIVE(fdc, unit); |
|---|
| 810 | | - debug_dcl(UDP->flags, |
|---|
| 809 | + debug_dcl(drive_params[drive].flags, |
|---|
| 811 | 810 | "calling disk change from set_dor\n"); |
|---|
| 812 | 811 | disk_change(drive); |
|---|
| 813 | 812 | } |
|---|
| 814 | | - FDCS->dor = newdor; |
|---|
| 815 | | - fd_outb(newdor, FD_DOR); |
|---|
| 813 | + fdc_state[fdc].dor = newdor; |
|---|
| 814 | + fdc_outb(newdor, fdc, FD_DOR); |
|---|
| 816 | 815 | |
|---|
| 817 | 816 | unit = newdor & 0x3; |
|---|
| 818 | 817 | if (!is_selected(olddor, unit) && is_selected(newdor, unit)) { |
|---|
| 819 | 818 | drive = REVDRIVE(fdc, unit); |
|---|
| 820 | | - UDRS->select_date = jiffies; |
|---|
| 819 | + drive_state[drive].select_date = jiffies; |
|---|
| 821 | 820 | } |
|---|
| 822 | 821 | } |
|---|
| 823 | 822 | return olddor; |
|---|
| 824 | 823 | } |
|---|
| 825 | 824 | |
|---|
| 826 | | -static void twaddle(void) |
|---|
| 825 | +static void twaddle(int fdc, int drive) |
|---|
| 827 | 826 | { |
|---|
| 828 | | - if (DP->select_delay) |
|---|
| 827 | + if (drive_params[drive].select_delay) |
|---|
| 829 | 828 | return; |
|---|
| 830 | | - fd_outb(FDCS->dor & ~(0x10 << UNIT(current_drive)), FD_DOR); |
|---|
| 831 | | - fd_outb(FDCS->dor, FD_DOR); |
|---|
| 832 | | - DRS->select_date = jiffies; |
|---|
| 829 | + fdc_outb(fdc_state[fdc].dor & ~(0x10 << UNIT(drive)), |
|---|
| 830 | + fdc, FD_DOR); |
|---|
| 831 | + fdc_outb(fdc_state[fdc].dor, fdc, FD_DOR); |
|---|
| 832 | + drive_state[drive].select_date = jiffies; |
|---|
| 833 | 833 | } |
|---|
| 834 | 834 | |
|---|
| 835 | 835 | /* |
|---|
| 836 | | - * Reset all driver information about the current fdc. |
|---|
| 836 | + * Reset all driver information about the specified fdc. |
|---|
| 837 | 837 | * This is needed after a reset, and after a raw command. |
|---|
| 838 | 838 | */ |
|---|
| 839 | | -static void reset_fdc_info(int mode) |
|---|
| 839 | +static void reset_fdc_info(int fdc, int mode) |
|---|
| 840 | 840 | { |
|---|
| 841 | 841 | int drive; |
|---|
| 842 | 842 | |
|---|
| 843 | | - FDCS->spec1 = FDCS->spec2 = -1; |
|---|
| 844 | | - FDCS->need_configure = 1; |
|---|
| 845 | | - FDCS->perp_mode = 1; |
|---|
| 846 | | - FDCS->rawcmd = 0; |
|---|
| 843 | + fdc_state[fdc].spec1 = fdc_state[fdc].spec2 = -1; |
|---|
| 844 | + fdc_state[fdc].need_configure = 1; |
|---|
| 845 | + fdc_state[fdc].perp_mode = 1; |
|---|
| 846 | + fdc_state[fdc].rawcmd = 0; |
|---|
| 847 | 847 | for (drive = 0; drive < N_DRIVE; drive++) |
|---|
| 848 | | - if (FDC(drive) == fdc && (mode || UDRS->track != NEED_1_RECAL)) |
|---|
| 849 | | - UDRS->track = NEED_2_RECAL; |
|---|
| 848 | + if (FDC(drive) == fdc && |
|---|
| 849 | + (mode || drive_state[drive].track != NEED_1_RECAL)) |
|---|
| 850 | + drive_state[drive].track = NEED_2_RECAL; |
|---|
| 850 | 851 | } |
|---|
| 851 | 852 | |
|---|
| 852 | | -/* selects the fdc and drive, and enables the fdc's input/dma. */ |
|---|
| 853 | +/* |
|---|
| 854 | + * selects the fdc and drive, and enables the fdc's input/dma. |
|---|
| 855 | + * Both current_drive and current_fdc are changed to match the new drive. |
|---|
| 856 | + */ |
|---|
| 853 | 857 | static void set_fdc(int drive) |
|---|
| 854 | 858 | { |
|---|
| 855 | | - unsigned int new_fdc = fdc; |
|---|
| 859 | + unsigned int fdc; |
|---|
| 856 | 860 | |
|---|
| 857 | | - if (drive >= 0 && drive < N_DRIVE) { |
|---|
| 858 | | - new_fdc = FDC(drive); |
|---|
| 859 | | - current_drive = drive; |
|---|
| 861 | + if (drive < 0 || drive >= N_DRIVE) { |
|---|
| 862 | + pr_info("bad drive value %d\n", drive); |
|---|
| 863 | + return; |
|---|
| 860 | 864 | } |
|---|
| 861 | | - if (new_fdc >= N_FDC) { |
|---|
| 865 | + |
|---|
| 866 | + fdc = FDC(drive); |
|---|
| 867 | + if (fdc >= N_FDC) { |
|---|
| 862 | 868 | pr_info("bad fdc value\n"); |
|---|
| 863 | 869 | return; |
|---|
| 864 | 870 | } |
|---|
| 865 | | - fdc = new_fdc; |
|---|
| 871 | + |
|---|
| 866 | 872 | set_dor(fdc, ~0, 8); |
|---|
| 867 | 873 | #if N_FDC > 1 |
|---|
| 868 | 874 | set_dor(1 - fdc, ~8, 0); |
|---|
| 869 | 875 | #endif |
|---|
| 870 | | - if (FDCS->rawcmd == 2) |
|---|
| 871 | | - reset_fdc_info(1); |
|---|
| 872 | | - if (fd_inb(FD_STATUS) != STATUS_READY) |
|---|
| 873 | | - FDCS->reset = 1; |
|---|
| 876 | + if (fdc_state[fdc].rawcmd == 2) |
|---|
| 877 | + reset_fdc_info(fdc, 1); |
|---|
| 878 | + if (fdc_inb(fdc, FD_STATUS) != STATUS_READY) |
|---|
| 879 | + fdc_state[fdc].reset = 1; |
|---|
| 880 | + |
|---|
| 881 | + current_drive = drive; |
|---|
| 882 | + current_fdc = fdc; |
|---|
| 874 | 883 | } |
|---|
| 875 | 884 | |
|---|
| 876 | | -/* locks the driver */ |
|---|
| 885 | +/* |
|---|
| 886 | + * locks the driver. |
|---|
| 887 | + * Both current_drive and current_fdc are changed to match the new drive. |
|---|
| 888 | + */ |
|---|
| 877 | 889 | static int lock_fdc(int drive) |
|---|
| 878 | 890 | { |
|---|
| 879 | 891 | if (WARN(atomic_read(&usage_count) == 0, |
|---|
| .. | .. |
|---|
| 923 | 935 | unsigned long volatile delta; |
|---|
| 924 | 936 | int fdc = FDC(drive); |
|---|
| 925 | 937 | |
|---|
| 926 | | - if (!(FDCS->dor & (0x10 << UNIT(drive)))) |
|---|
| 938 | + if (!(fdc_state[fdc].dor & (0x10 << UNIT(drive)))) |
|---|
| 927 | 939 | return; |
|---|
| 928 | 940 | |
|---|
| 929 | 941 | del_timer(motor_off_timer + drive); |
|---|
| 930 | 942 | |
|---|
| 931 | 943 | /* make spindle stop in a position which minimizes spinup time |
|---|
| 932 | 944 | * next time */ |
|---|
| 933 | | - if (UDP->rps) { |
|---|
| 934 | | - delta = jiffies - UDRS->first_read_date + HZ - |
|---|
| 935 | | - UDP->spindown_offset; |
|---|
| 936 | | - delta = ((delta * UDP->rps) % HZ) / UDP->rps; |
|---|
| 945 | + if (drive_params[drive].rps) { |
|---|
| 946 | + delta = jiffies - drive_state[drive].first_read_date + HZ - |
|---|
| 947 | + drive_params[drive].spindown_offset; |
|---|
| 948 | + delta = ((delta * drive_params[drive].rps) % HZ) / drive_params[drive].rps; |
|---|
| 937 | 949 | motor_off_timer[drive].expires = |
|---|
| 938 | | - jiffies + UDP->spindown - delta; |
|---|
| 950 | + jiffies + drive_params[drive].spindown - delta; |
|---|
| 939 | 951 | } |
|---|
| 940 | 952 | add_timer(motor_off_timer + drive); |
|---|
| 941 | 953 | } |
|---|
| .. | .. |
|---|
| 951 | 963 | int drive; |
|---|
| 952 | 964 | int saved_drive; |
|---|
| 953 | 965 | |
|---|
| 954 | | - if (DP->select_delay) |
|---|
| 966 | + if (drive_params[current_drive].select_delay) |
|---|
| 955 | 967 | return; |
|---|
| 956 | 968 | |
|---|
| 957 | 969 | saved_drive = current_drive; |
|---|
| 958 | 970 | for (i = 0; i < N_DRIVE; i++) { |
|---|
| 959 | 971 | drive = (saved_drive + i + 1) % N_DRIVE; |
|---|
| 960 | | - if (UDRS->fd_ref == 0 || UDP->select_delay != 0) |
|---|
| 972 | + if (drive_state[drive].fd_ref == 0 || drive_params[drive].select_delay != 0) |
|---|
| 961 | 973 | continue; /* skip closed drives */ |
|---|
| 962 | 974 | set_fdc(drive); |
|---|
| 963 | | - if (!(set_dor(fdc, ~3, UNIT(drive) | (0x10 << UNIT(drive))) & |
|---|
| 975 | + if (!(set_dor(current_fdc, ~3, UNIT(drive) | (0x10 << UNIT(drive))) & |
|---|
| 964 | 976 | (0x10 << UNIT(drive)))) |
|---|
| 965 | 977 | /* switch the motor off again, if it was off to |
|---|
| 966 | 978 | * begin with */ |
|---|
| 967 | | - set_dor(fdc, ~(0x10 << UNIT(drive)), 0); |
|---|
| 979 | + set_dor(current_fdc, ~(0x10 << UNIT(drive)), 0); |
|---|
| 968 | 980 | } |
|---|
| 969 | 981 | set_fdc(saved_drive); |
|---|
| 970 | 982 | } |
|---|
| .. | .. |
|---|
| 1010 | 1022 | * transfer */ |
|---|
| 1011 | 1023 | static void fd_watchdog(void) |
|---|
| 1012 | 1024 | { |
|---|
| 1013 | | - debug_dcl(DP->flags, "calling disk change from watchdog\n"); |
|---|
| 1025 | + debug_dcl(drive_params[current_drive].flags, |
|---|
| 1026 | + "calling disk change from watchdog\n"); |
|---|
| 1014 | 1027 | |
|---|
| 1015 | 1028 | if (disk_change(current_drive)) { |
|---|
| 1016 | 1029 | DPRINT("disk removed during i/o\n"); |
|---|
| .. | .. |
|---|
| 1034 | 1047 | static int fd_wait_for_completion(unsigned long expires, |
|---|
| 1035 | 1048 | void (*function)(void)) |
|---|
| 1036 | 1049 | { |
|---|
| 1037 | | - if (FDCS->reset) { |
|---|
| 1050 | + if (fdc_state[current_fdc].reset) { |
|---|
| 1038 | 1051 | reset_fdc(); /* do the reset during sleep to win time |
|---|
| 1039 | 1052 | * if we don't need to sleep, it's a good |
|---|
| 1040 | 1053 | * occasion anyways */ |
|---|
| .. | .. |
|---|
| 1055 | 1068 | unsigned long f; |
|---|
| 1056 | 1069 | |
|---|
| 1057 | 1070 | if (raw_cmd->length == 0) { |
|---|
| 1058 | | - int i; |
|---|
| 1059 | | - |
|---|
| 1060 | | - pr_info("zero dma transfer size:"); |
|---|
| 1061 | | - for (i = 0; i < raw_cmd->cmd_count; i++) |
|---|
| 1062 | | - pr_cont("%x,", raw_cmd->cmd[i]); |
|---|
| 1063 | | - pr_cont("\n"); |
|---|
| 1071 | + print_hex_dump(KERN_INFO, "zero dma transfer size: ", |
|---|
| 1072 | + DUMP_PREFIX_NONE, 16, 1, |
|---|
| 1073 | + raw_cmd->fullcmd, raw_cmd->cmd_count, false); |
|---|
| 1064 | 1074 | cont->done(0); |
|---|
| 1065 | | - FDCS->reset = 1; |
|---|
| 1075 | + fdc_state[current_fdc].reset = 1; |
|---|
| 1066 | 1076 | return; |
|---|
| 1067 | 1077 | } |
|---|
| 1068 | 1078 | if (((unsigned long)raw_cmd->kernel_data) % 512) { |
|---|
| 1069 | 1079 | pr_info("non aligned address: %p\n", raw_cmd->kernel_data); |
|---|
| 1070 | 1080 | cont->done(0); |
|---|
| 1071 | | - FDCS->reset = 1; |
|---|
| 1081 | + fdc_state[current_fdc].reset = 1; |
|---|
| 1072 | 1082 | return; |
|---|
| 1073 | 1083 | } |
|---|
| 1074 | 1084 | f = claim_dma_lock(); |
|---|
| .. | .. |
|---|
| 1076 | 1086 | #ifdef fd_dma_setup |
|---|
| 1077 | 1087 | if (fd_dma_setup(raw_cmd->kernel_data, raw_cmd->length, |
|---|
| 1078 | 1088 | (raw_cmd->flags & FD_RAW_READ) ? |
|---|
| 1079 | | - DMA_MODE_READ : DMA_MODE_WRITE, FDCS->address) < 0) { |
|---|
| 1089 | + DMA_MODE_READ : DMA_MODE_WRITE, |
|---|
| 1090 | + fdc_state[current_fdc].address) < 0) { |
|---|
| 1080 | 1091 | release_dma_lock(f); |
|---|
| 1081 | 1092 | cont->done(0); |
|---|
| 1082 | | - FDCS->reset = 1; |
|---|
| 1093 | + fdc_state[current_fdc].reset = 1; |
|---|
| 1083 | 1094 | return; |
|---|
| 1084 | 1095 | } |
|---|
| 1085 | 1096 | release_dma_lock(f); |
|---|
| .. | .. |
|---|
| 1090 | 1101 | DMA_MODE_READ : DMA_MODE_WRITE); |
|---|
| 1091 | 1102 | fd_set_dma_addr(raw_cmd->kernel_data); |
|---|
| 1092 | 1103 | fd_set_dma_count(raw_cmd->length); |
|---|
| 1093 | | - virtual_dma_port = FDCS->address; |
|---|
| 1104 | + virtual_dma_port = fdc_state[current_fdc].address; |
|---|
| 1094 | 1105 | fd_enable_dma(); |
|---|
| 1095 | 1106 | release_dma_lock(f); |
|---|
| 1096 | 1107 | #endif |
|---|
| 1097 | 1108 | } |
|---|
| 1098 | 1109 | |
|---|
| 1099 | | -static void show_floppy(void); |
|---|
| 1110 | +static void show_floppy(int fdc); |
|---|
| 1100 | 1111 | |
|---|
| 1101 | 1112 | /* waits until the fdc becomes ready */ |
|---|
| 1102 | | -static int wait_til_ready(void) |
|---|
| 1113 | +static int wait_til_ready(int fdc) |
|---|
| 1103 | 1114 | { |
|---|
| 1104 | 1115 | int status; |
|---|
| 1105 | 1116 | int counter; |
|---|
| 1106 | 1117 | |
|---|
| 1107 | | - if (FDCS->reset) |
|---|
| 1118 | + if (fdc_state[fdc].reset) |
|---|
| 1108 | 1119 | return -1; |
|---|
| 1109 | 1120 | for (counter = 0; counter < 10000; counter++) { |
|---|
| 1110 | | - status = fd_inb(FD_STATUS); |
|---|
| 1121 | + status = fdc_inb(fdc, FD_STATUS); |
|---|
| 1111 | 1122 | if (status & STATUS_READY) |
|---|
| 1112 | 1123 | return status; |
|---|
| 1113 | 1124 | } |
|---|
| 1114 | 1125 | if (initialized) { |
|---|
| 1115 | 1126 | DPRINT("Getstatus times out (%x) on fdc %d\n", status, fdc); |
|---|
| 1116 | | - show_floppy(); |
|---|
| 1127 | + show_floppy(fdc); |
|---|
| 1117 | 1128 | } |
|---|
| 1118 | | - FDCS->reset = 1; |
|---|
| 1129 | + fdc_state[fdc].reset = 1; |
|---|
| 1119 | 1130 | return -1; |
|---|
| 1120 | 1131 | } |
|---|
| 1121 | 1132 | |
|---|
| 1122 | 1133 | /* sends a command byte to the fdc */ |
|---|
| 1123 | | -static int output_byte(char byte) |
|---|
| 1134 | +static int output_byte(int fdc, char byte) |
|---|
| 1124 | 1135 | { |
|---|
| 1125 | | - int status = wait_til_ready(); |
|---|
| 1136 | + int status = wait_til_ready(fdc); |
|---|
| 1126 | 1137 | |
|---|
| 1127 | 1138 | if (status < 0) |
|---|
| 1128 | 1139 | return -1; |
|---|
| 1129 | 1140 | |
|---|
| 1130 | 1141 | if (is_ready_state(status)) { |
|---|
| 1131 | | - fd_outb(byte, FD_DATA); |
|---|
| 1142 | + fdc_outb(byte, fdc, FD_DATA); |
|---|
| 1132 | 1143 | output_log[output_log_pos].data = byte; |
|---|
| 1133 | 1144 | output_log[output_log_pos].status = status; |
|---|
| 1134 | 1145 | output_log[output_log_pos].jiffies = jiffies; |
|---|
| 1135 | 1146 | output_log_pos = (output_log_pos + 1) % OLOGSIZE; |
|---|
| 1136 | 1147 | return 0; |
|---|
| 1137 | 1148 | } |
|---|
| 1138 | | - FDCS->reset = 1; |
|---|
| 1149 | + fdc_state[fdc].reset = 1; |
|---|
| 1139 | 1150 | if (initialized) { |
|---|
| 1140 | 1151 | DPRINT("Unable to send byte %x to FDC. Fdc=%x Status=%x\n", |
|---|
| 1141 | 1152 | byte, fdc, status); |
|---|
| 1142 | | - show_floppy(); |
|---|
| 1153 | + show_floppy(fdc); |
|---|
| 1143 | 1154 | } |
|---|
| 1144 | 1155 | return -1; |
|---|
| 1145 | 1156 | } |
|---|
| 1146 | 1157 | |
|---|
| 1147 | 1158 | /* gets the response from the fdc */ |
|---|
| 1148 | | -static int result(void) |
|---|
| 1159 | +static int result(int fdc) |
|---|
| 1149 | 1160 | { |
|---|
| 1150 | 1161 | int i; |
|---|
| 1151 | 1162 | int status = 0; |
|---|
| 1152 | 1163 | |
|---|
| 1153 | | - for (i = 0; i < MAX_REPLIES; i++) { |
|---|
| 1154 | | - status = wait_til_ready(); |
|---|
| 1164 | + for (i = 0; i < FD_RAW_REPLY_SIZE; i++) { |
|---|
| 1165 | + status = wait_til_ready(fdc); |
|---|
| 1155 | 1166 | if (status < 0) |
|---|
| 1156 | 1167 | break; |
|---|
| 1157 | 1168 | status &= STATUS_DIR | STATUS_READY | STATUS_BUSY | STATUS_DMA; |
|---|
| .. | .. |
|---|
| 1161 | 1172 | return i; |
|---|
| 1162 | 1173 | } |
|---|
| 1163 | 1174 | if (status == (STATUS_DIR | STATUS_READY | STATUS_BUSY)) |
|---|
| 1164 | | - reply_buffer[i] = fd_inb(FD_DATA); |
|---|
| 1175 | + reply_buffer[i] = fdc_inb(fdc, FD_DATA); |
|---|
| 1165 | 1176 | else |
|---|
| 1166 | 1177 | break; |
|---|
| 1167 | 1178 | } |
|---|
| 1168 | 1179 | if (initialized) { |
|---|
| 1169 | 1180 | DPRINT("get result error. Fdc=%d Last status=%x Read bytes=%d\n", |
|---|
| 1170 | 1181 | fdc, status, i); |
|---|
| 1171 | | - show_floppy(); |
|---|
| 1182 | + show_floppy(fdc); |
|---|
| 1172 | 1183 | } |
|---|
| 1173 | | - FDCS->reset = 1; |
|---|
| 1184 | + fdc_state[fdc].reset = 1; |
|---|
| 1174 | 1185 | return -1; |
|---|
| 1175 | 1186 | } |
|---|
| 1176 | 1187 | |
|---|
| 1177 | 1188 | #define MORE_OUTPUT -2 |
|---|
| 1178 | 1189 | /* does the fdc need more output? */ |
|---|
| 1179 | | -static int need_more_output(void) |
|---|
| 1190 | +static int need_more_output(int fdc) |
|---|
| 1180 | 1191 | { |
|---|
| 1181 | | - int status = wait_til_ready(); |
|---|
| 1192 | + int status = wait_til_ready(fdc); |
|---|
| 1182 | 1193 | |
|---|
| 1183 | 1194 | if (status < 0) |
|---|
| 1184 | 1195 | return -1; |
|---|
| .. | .. |
|---|
| 1186 | 1197 | if (is_ready_state(status)) |
|---|
| 1187 | 1198 | return MORE_OUTPUT; |
|---|
| 1188 | 1199 | |
|---|
| 1189 | | - return result(); |
|---|
| 1200 | + return result(fdc); |
|---|
| 1190 | 1201 | } |
|---|
| 1191 | 1202 | |
|---|
| 1192 | 1203 | /* Set perpendicular mode as required, based on data rate, if supported. |
|---|
| 1193 | 1204 | * 82077 Now tested. 1Mbps data rate only possible with 82077-1. |
|---|
| 1194 | 1205 | */ |
|---|
| 1195 | | -static void perpendicular_mode(void) |
|---|
| 1206 | +static void perpendicular_mode(int fdc) |
|---|
| 1196 | 1207 | { |
|---|
| 1197 | 1208 | unsigned char perp_mode; |
|---|
| 1198 | 1209 | |
|---|
| .. | .. |
|---|
| 1207 | 1218 | default: |
|---|
| 1208 | 1219 | DPRINT("Invalid data rate for perpendicular mode!\n"); |
|---|
| 1209 | 1220 | cont->done(0); |
|---|
| 1210 | | - FDCS->reset = 1; |
|---|
| 1221 | + fdc_state[fdc].reset = 1; |
|---|
| 1211 | 1222 | /* |
|---|
| 1212 | 1223 | * convenient way to return to |
|---|
| 1213 | 1224 | * redo without too much hassle |
|---|
| .. | .. |
|---|
| 1218 | 1229 | } else |
|---|
| 1219 | 1230 | perp_mode = 0; |
|---|
| 1220 | 1231 | |
|---|
| 1221 | | - if (FDCS->perp_mode == perp_mode) |
|---|
| 1232 | + if (fdc_state[fdc].perp_mode == perp_mode) |
|---|
| 1222 | 1233 | return; |
|---|
| 1223 | | - if (FDCS->version >= FDC_82077_ORIG) { |
|---|
| 1224 | | - output_byte(FD_PERPENDICULAR); |
|---|
| 1225 | | - output_byte(perp_mode); |
|---|
| 1226 | | - FDCS->perp_mode = perp_mode; |
|---|
| 1234 | + if (fdc_state[fdc].version >= FDC_82077_ORIG) { |
|---|
| 1235 | + output_byte(fdc, FD_PERPENDICULAR); |
|---|
| 1236 | + output_byte(fdc, perp_mode); |
|---|
| 1237 | + fdc_state[fdc].perp_mode = perp_mode; |
|---|
| 1227 | 1238 | } else if (perp_mode) { |
|---|
| 1228 | 1239 | DPRINT("perpendicular mode not supported by this FDC.\n"); |
|---|
| 1229 | 1240 | } |
|---|
| .. | .. |
|---|
| 1232 | 1243 | static int fifo_depth = 0xa; |
|---|
| 1233 | 1244 | static int no_fifo; |
|---|
| 1234 | 1245 | |
|---|
| 1235 | | -static int fdc_configure(void) |
|---|
| 1246 | +static int fdc_configure(int fdc) |
|---|
| 1236 | 1247 | { |
|---|
| 1237 | 1248 | /* Turn on FIFO */ |
|---|
| 1238 | | - output_byte(FD_CONFIGURE); |
|---|
| 1239 | | - if (need_more_output() != MORE_OUTPUT) |
|---|
| 1249 | + output_byte(fdc, FD_CONFIGURE); |
|---|
| 1250 | + if (need_more_output(fdc) != MORE_OUTPUT) |
|---|
| 1240 | 1251 | return 0; |
|---|
| 1241 | | - output_byte(0); |
|---|
| 1242 | | - output_byte(0x10 | (no_fifo & 0x20) | (fifo_depth & 0xf)); |
|---|
| 1243 | | - output_byte(0); /* pre-compensation from track |
|---|
| 1244 | | - 0 upwards */ |
|---|
| 1252 | + output_byte(fdc, 0); |
|---|
| 1253 | + output_byte(fdc, 0x10 | (no_fifo & 0x20) | (fifo_depth & 0xf)); |
|---|
| 1254 | + output_byte(fdc, 0); /* pre-compensation from track 0 upwards */ |
|---|
| 1245 | 1255 | return 1; |
|---|
| 1246 | 1256 | } |
|---|
| 1247 | 1257 | |
|---|
| .. | .. |
|---|
| 1266 | 1276 | * |
|---|
| 1267 | 1277 | * These values are rounded up to the next highest available delay time. |
|---|
| 1268 | 1278 | */ |
|---|
| 1269 | | -static void fdc_specify(void) |
|---|
| 1279 | +static void fdc_specify(int fdc, int drive) |
|---|
| 1270 | 1280 | { |
|---|
| 1271 | 1281 | unsigned char spec1; |
|---|
| 1272 | 1282 | unsigned char spec2; |
|---|
| .. | .. |
|---|
| 1278 | 1288 | int hlt_max_code = 0x7f; |
|---|
| 1279 | 1289 | int hut_max_code = 0xf; |
|---|
| 1280 | 1290 | |
|---|
| 1281 | | - if (FDCS->need_configure && FDCS->version >= FDC_82072A) { |
|---|
| 1282 | | - fdc_configure(); |
|---|
| 1283 | | - FDCS->need_configure = 0; |
|---|
| 1291 | + if (fdc_state[fdc].need_configure && |
|---|
| 1292 | + fdc_state[fdc].version >= FDC_82072A) { |
|---|
| 1293 | + fdc_configure(fdc); |
|---|
| 1294 | + fdc_state[fdc].need_configure = 0; |
|---|
| 1284 | 1295 | } |
|---|
| 1285 | 1296 | |
|---|
| 1286 | 1297 | switch (raw_cmd->rate & 0x03) { |
|---|
| .. | .. |
|---|
| 1289 | 1300 | break; |
|---|
| 1290 | 1301 | case 1: |
|---|
| 1291 | 1302 | dtr = 300; |
|---|
| 1292 | | - if (FDCS->version >= FDC_82078) { |
|---|
| 1303 | + if (fdc_state[fdc].version >= FDC_82078) { |
|---|
| 1293 | 1304 | /* chose the default rate table, not the one |
|---|
| 1294 | 1305 | * where 1 = 2 Mbps */ |
|---|
| 1295 | | - output_byte(FD_DRIVESPEC); |
|---|
| 1296 | | - if (need_more_output() == MORE_OUTPUT) { |
|---|
| 1297 | | - output_byte(UNIT(current_drive)); |
|---|
| 1298 | | - output_byte(0xc0); |
|---|
| 1306 | + output_byte(fdc, FD_DRIVESPEC); |
|---|
| 1307 | + if (need_more_output(fdc) == MORE_OUTPUT) { |
|---|
| 1308 | + output_byte(fdc, UNIT(drive)); |
|---|
| 1309 | + output_byte(fdc, 0xc0); |
|---|
| 1299 | 1310 | } |
|---|
| 1300 | 1311 | } |
|---|
| 1301 | 1312 | break; |
|---|
| .. | .. |
|---|
| 1304 | 1315 | break; |
|---|
| 1305 | 1316 | } |
|---|
| 1306 | 1317 | |
|---|
| 1307 | | - if (FDCS->version >= FDC_82072) { |
|---|
| 1318 | + if (fdc_state[fdc].version >= FDC_82072) { |
|---|
| 1308 | 1319 | scale_dtr = dtr; |
|---|
| 1309 | 1320 | hlt_max_code = 0x00; /* 0==256msec*dtr0/dtr (not linear!) */ |
|---|
| 1310 | 1321 | hut_max_code = 0x0; /* 0==256msec*dtr0/dtr (not linear!) */ |
|---|
| 1311 | 1322 | } |
|---|
| 1312 | 1323 | |
|---|
| 1313 | 1324 | /* Convert step rate from microseconds to milliseconds and 4 bits */ |
|---|
| 1314 | | - srt = 16 - DIV_ROUND_UP(DP->srt * scale_dtr / 1000, NOMINAL_DTR); |
|---|
| 1325 | + srt = 16 - DIV_ROUND_UP(drive_params[drive].srt * scale_dtr / 1000, |
|---|
| 1326 | + NOMINAL_DTR); |
|---|
| 1315 | 1327 | if (slow_floppy) |
|---|
| 1316 | 1328 | srt = srt / 4; |
|---|
| 1317 | 1329 | |
|---|
| 1318 | 1330 | SUPBOUND(srt, 0xf); |
|---|
| 1319 | 1331 | INFBOUND(srt, 0); |
|---|
| 1320 | 1332 | |
|---|
| 1321 | | - hlt = DIV_ROUND_UP(DP->hlt * scale_dtr / 2, NOMINAL_DTR); |
|---|
| 1333 | + hlt = DIV_ROUND_UP(drive_params[drive].hlt * scale_dtr / 2, |
|---|
| 1334 | + NOMINAL_DTR); |
|---|
| 1322 | 1335 | if (hlt < 0x01) |
|---|
| 1323 | 1336 | hlt = 0x01; |
|---|
| 1324 | 1337 | else if (hlt > 0x7f) |
|---|
| 1325 | 1338 | hlt = hlt_max_code; |
|---|
| 1326 | 1339 | |
|---|
| 1327 | | - hut = DIV_ROUND_UP(DP->hut * scale_dtr / 16, NOMINAL_DTR); |
|---|
| 1340 | + hut = DIV_ROUND_UP(drive_params[drive].hut * scale_dtr / 16, |
|---|
| 1341 | + NOMINAL_DTR); |
|---|
| 1328 | 1342 | if (hut < 0x1) |
|---|
| 1329 | 1343 | hut = 0x1; |
|---|
| 1330 | 1344 | else if (hut > 0xf) |
|---|
| .. | .. |
|---|
| 1334 | 1348 | spec2 = (hlt << 1) | (use_virtual_dma & 1); |
|---|
| 1335 | 1349 | |
|---|
| 1336 | 1350 | /* If these parameters did not change, just return with success */ |
|---|
| 1337 | | - if (FDCS->spec1 != spec1 || FDCS->spec2 != spec2) { |
|---|
| 1351 | + if (fdc_state[fdc].spec1 != spec1 || |
|---|
| 1352 | + fdc_state[fdc].spec2 != spec2) { |
|---|
| 1338 | 1353 | /* Go ahead and set spec1 and spec2 */ |
|---|
| 1339 | | - output_byte(FD_SPECIFY); |
|---|
| 1340 | | - output_byte(FDCS->spec1 = spec1); |
|---|
| 1341 | | - output_byte(FDCS->spec2 = spec2); |
|---|
| 1354 | + output_byte(fdc, FD_SPECIFY); |
|---|
| 1355 | + output_byte(fdc, fdc_state[fdc].spec1 = spec1); |
|---|
| 1356 | + output_byte(fdc, fdc_state[fdc].spec2 = spec2); |
|---|
| 1342 | 1357 | } |
|---|
| 1343 | 1358 | } /* fdc_specify */ |
|---|
| 1344 | 1359 | |
|---|
| .. | .. |
|---|
| 1349 | 1364 | static int fdc_dtr(void) |
|---|
| 1350 | 1365 | { |
|---|
| 1351 | 1366 | /* If data rate not already set to desired value, set it. */ |
|---|
| 1352 | | - if ((raw_cmd->rate & 3) == FDCS->dtr) |
|---|
| 1367 | + if ((raw_cmd->rate & 3) == fdc_state[current_fdc].dtr) |
|---|
| 1353 | 1368 | return 0; |
|---|
| 1354 | 1369 | |
|---|
| 1355 | 1370 | /* Set dtr */ |
|---|
| 1356 | | - fd_outb(raw_cmd->rate & 3, FD_DCR); |
|---|
| 1371 | + fdc_outb(raw_cmd->rate & 3, current_fdc, FD_DCR); |
|---|
| 1357 | 1372 | |
|---|
| 1358 | 1373 | /* TODO: some FDC/drive combinations (C&T 82C711 with TEAC 1.2MB) |
|---|
| 1359 | 1374 | * need a stabilization period of several milliseconds to be |
|---|
| 1360 | 1375 | * enforced after data rate changes before R/W operations. |
|---|
| 1361 | 1376 | * Pause 5 msec to avoid trouble. (Needs to be 2 jiffies) |
|---|
| 1362 | 1377 | */ |
|---|
| 1363 | | - FDCS->dtr = raw_cmd->rate & 3; |
|---|
| 1378 | + fdc_state[current_fdc].dtr = raw_cmd->rate & 3; |
|---|
| 1364 | 1379 | return fd_wait_for_completion(jiffies + 2UL * HZ / 100, floppy_ready); |
|---|
| 1365 | 1380 | } /* fdc_dtr */ |
|---|
| 1366 | 1381 | |
|---|
| 1367 | 1382 | static void tell_sector(void) |
|---|
| 1368 | 1383 | { |
|---|
| 1369 | 1384 | pr_cont(": track %d, head %d, sector %d, size %d", |
|---|
| 1370 | | - R_TRACK, R_HEAD, R_SECTOR, R_SIZECODE); |
|---|
| 1385 | + reply_buffer[R_TRACK], reply_buffer[R_HEAD], |
|---|
| 1386 | + reply_buffer[R_SECTOR], |
|---|
| 1387 | + reply_buffer[R_SIZECODE]); |
|---|
| 1371 | 1388 | } /* tell_sector */ |
|---|
| 1372 | 1389 | |
|---|
| 1373 | 1390 | static void print_errors(void) |
|---|
| 1374 | 1391 | { |
|---|
| 1375 | 1392 | DPRINT(""); |
|---|
| 1376 | | - if (ST0 & ST0_ECE) { |
|---|
| 1393 | + if (reply_buffer[ST0] & ST0_ECE) { |
|---|
| 1377 | 1394 | pr_cont("Recalibrate failed!"); |
|---|
| 1378 | | - } else if (ST2 & ST2_CRC) { |
|---|
| 1395 | + } else if (reply_buffer[ST2] & ST2_CRC) { |
|---|
| 1379 | 1396 | pr_cont("data CRC error"); |
|---|
| 1380 | 1397 | tell_sector(); |
|---|
| 1381 | | - } else if (ST1 & ST1_CRC) { |
|---|
| 1398 | + } else if (reply_buffer[ST1] & ST1_CRC) { |
|---|
| 1382 | 1399 | pr_cont("CRC error"); |
|---|
| 1383 | 1400 | tell_sector(); |
|---|
| 1384 | | - } else if ((ST1 & (ST1_MAM | ST1_ND)) || |
|---|
| 1385 | | - (ST2 & ST2_MAM)) { |
|---|
| 1401 | + } else if ((reply_buffer[ST1] & (ST1_MAM | ST1_ND)) || |
|---|
| 1402 | + (reply_buffer[ST2] & ST2_MAM)) { |
|---|
| 1386 | 1403 | if (!probing) { |
|---|
| 1387 | 1404 | pr_cont("sector not found"); |
|---|
| 1388 | 1405 | tell_sector(); |
|---|
| 1389 | 1406 | } else |
|---|
| 1390 | 1407 | pr_cont("probe failed..."); |
|---|
| 1391 | | - } else if (ST2 & ST2_WC) { /* seek error */ |
|---|
| 1408 | + } else if (reply_buffer[ST2] & ST2_WC) { /* seek error */ |
|---|
| 1392 | 1409 | pr_cont("wrong cylinder"); |
|---|
| 1393 | | - } else if (ST2 & ST2_BC) { /* cylinder marked as bad */ |
|---|
| 1410 | + } else if (reply_buffer[ST2] & ST2_BC) { /* cylinder marked as bad */ |
|---|
| 1394 | 1411 | pr_cont("bad cylinder"); |
|---|
| 1395 | 1412 | } else { |
|---|
| 1396 | 1413 | pr_cont("unknown error. ST[0..2] are: 0x%x 0x%x 0x%x", |
|---|
| 1397 | | - ST0, ST1, ST2); |
|---|
| 1414 | + reply_buffer[ST0], reply_buffer[ST1], |
|---|
| 1415 | + reply_buffer[ST2]); |
|---|
| 1398 | 1416 | tell_sector(); |
|---|
| 1399 | 1417 | } |
|---|
| 1400 | 1418 | pr_cont("\n"); |
|---|
| .. | .. |
|---|
| 1413 | 1431 | |
|---|
| 1414 | 1432 | if (inr != 7) { |
|---|
| 1415 | 1433 | DPRINT("-- FDC reply error\n"); |
|---|
| 1416 | | - FDCS->reset = 1; |
|---|
| 1434 | + fdc_state[current_fdc].reset = 1; |
|---|
| 1417 | 1435 | return 1; |
|---|
| 1418 | 1436 | } |
|---|
| 1419 | 1437 | |
|---|
| 1420 | 1438 | /* check IC to find cause of interrupt */ |
|---|
| 1421 | | - switch (ST0 & ST0_INTR) { |
|---|
| 1439 | + switch (reply_buffer[ST0] & ST0_INTR) { |
|---|
| 1422 | 1440 | case 0x40: /* error occurred during command execution */ |
|---|
| 1423 | | - if (ST1 & ST1_EOC) |
|---|
| 1441 | + if (reply_buffer[ST1] & ST1_EOC) |
|---|
| 1424 | 1442 | return 0; /* occurs with pseudo-DMA */ |
|---|
| 1425 | 1443 | bad = 1; |
|---|
| 1426 | | - if (ST1 & ST1_WP) { |
|---|
| 1444 | + if (reply_buffer[ST1] & ST1_WP) { |
|---|
| 1427 | 1445 | DPRINT("Drive is write protected\n"); |
|---|
| 1428 | | - clear_bit(FD_DISK_WRITABLE_BIT, &DRS->flags); |
|---|
| 1446 | + clear_bit(FD_DISK_WRITABLE_BIT, |
|---|
| 1447 | + &drive_state[current_drive].flags); |
|---|
| 1429 | 1448 | cont->done(0); |
|---|
| 1430 | 1449 | bad = 2; |
|---|
| 1431 | | - } else if (ST1 & ST1_ND) { |
|---|
| 1432 | | - set_bit(FD_NEED_TWADDLE_BIT, &DRS->flags); |
|---|
| 1433 | | - } else if (ST1 & ST1_OR) { |
|---|
| 1434 | | - if (DP->flags & FTD_MSG) |
|---|
| 1450 | + } else if (reply_buffer[ST1] & ST1_ND) { |
|---|
| 1451 | + set_bit(FD_NEED_TWADDLE_BIT, |
|---|
| 1452 | + &drive_state[current_drive].flags); |
|---|
| 1453 | + } else if (reply_buffer[ST1] & ST1_OR) { |
|---|
| 1454 | + if (drive_params[current_drive].flags & FTD_MSG) |
|---|
| 1435 | 1455 | DPRINT("Over/Underrun - retrying\n"); |
|---|
| 1436 | 1456 | bad = 0; |
|---|
| 1437 | | - } else if (*errors >= DP->max_errors.reporting) { |
|---|
| 1457 | + } else if (floppy_errors >= drive_params[current_drive].max_errors.reporting) { |
|---|
| 1438 | 1458 | print_errors(); |
|---|
| 1439 | 1459 | } |
|---|
| 1440 | | - if (ST2 & ST2_WC || ST2 & ST2_BC) |
|---|
| 1460 | + if (reply_buffer[ST2] & ST2_WC || reply_buffer[ST2] & ST2_BC) |
|---|
| 1441 | 1461 | /* wrong cylinder => recal */ |
|---|
| 1442 | | - DRS->track = NEED_2_RECAL; |
|---|
| 1462 | + drive_state[current_drive].track = NEED_2_RECAL; |
|---|
| 1443 | 1463 | return bad; |
|---|
| 1444 | 1464 | case 0x80: /* invalid command given */ |
|---|
| 1445 | 1465 | DPRINT("Invalid FDC command given!\n"); |
|---|
| .. | .. |
|---|
| 1472 | 1492 | flags |= FD_RAW_INTR; |
|---|
| 1473 | 1493 | |
|---|
| 1474 | 1494 | if ((flags & FD_RAW_SPIN) && !(flags & FD_RAW_NO_MOTOR)) { |
|---|
| 1475 | | - ready_date = DRS->spinup_date + DP->spinup; |
|---|
| 1495 | + ready_date = drive_state[current_drive].spinup_date + drive_params[current_drive].spinup; |
|---|
| 1476 | 1496 | /* If spinup will take a long time, rerun scandrives |
|---|
| 1477 | 1497 | * again just before spinup completion. Beware that |
|---|
| 1478 | 1498 | * after scandrives, we must again wait for selection. |
|---|
| 1479 | 1499 | */ |
|---|
| 1480 | | - if (time_after(ready_date, jiffies + DP->select_delay)) { |
|---|
| 1481 | | - ready_date -= DP->select_delay; |
|---|
| 1500 | + if (time_after(ready_date, jiffies + drive_params[current_drive].select_delay)) { |
|---|
| 1501 | + ready_date -= drive_params[current_drive].select_delay; |
|---|
| 1482 | 1502 | function = floppy_start; |
|---|
| 1483 | 1503 | } else |
|---|
| 1484 | 1504 | function = setup_rw_floppy; |
|---|
| .. | .. |
|---|
| 1495 | 1515 | |
|---|
| 1496 | 1516 | r = 0; |
|---|
| 1497 | 1517 | for (i = 0; i < raw_cmd->cmd_count; i++) |
|---|
| 1498 | | - r |= output_byte(raw_cmd->cmd[i]); |
|---|
| 1518 | + r |= output_byte(current_fdc, raw_cmd->fullcmd[i]); |
|---|
| 1499 | 1519 | |
|---|
| 1500 | 1520 | debugt(__func__, "rw_command"); |
|---|
| 1501 | 1521 | |
|---|
| .. | .. |
|---|
| 1506 | 1526 | } |
|---|
| 1507 | 1527 | |
|---|
| 1508 | 1528 | if (!(flags & FD_RAW_INTR)) { |
|---|
| 1509 | | - inr = result(); |
|---|
| 1529 | + inr = result(current_fdc); |
|---|
| 1510 | 1530 | cont->interrupt(); |
|---|
| 1511 | 1531 | } else if (flags & FD_RAW_NEED_DISK) |
|---|
| 1512 | 1532 | fd_watchdog(); |
|---|
| .. | .. |
|---|
| 1521 | 1541 | static void seek_interrupt(void) |
|---|
| 1522 | 1542 | { |
|---|
| 1523 | 1543 | debugt(__func__, ""); |
|---|
| 1524 | | - if (inr != 2 || (ST0 & 0xF8) != 0x20) { |
|---|
| 1544 | + if (inr != 2 || (reply_buffer[ST0] & 0xF8) != 0x20) { |
|---|
| 1525 | 1545 | DPRINT("seek failed\n"); |
|---|
| 1526 | | - DRS->track = NEED_2_RECAL; |
|---|
| 1546 | + drive_state[current_drive].track = NEED_2_RECAL; |
|---|
| 1527 | 1547 | cont->error(); |
|---|
| 1528 | 1548 | cont->redo(); |
|---|
| 1529 | 1549 | return; |
|---|
| 1530 | 1550 | } |
|---|
| 1531 | | - if (DRS->track >= 0 && DRS->track != ST1 && !blind_seek) { |
|---|
| 1532 | | - debug_dcl(DP->flags, |
|---|
| 1551 | + if (drive_state[current_drive].track >= 0 && |
|---|
| 1552 | + drive_state[current_drive].track != reply_buffer[ST1] && |
|---|
| 1553 | + !blind_seek) { |
|---|
| 1554 | + debug_dcl(drive_params[current_drive].flags, |
|---|
| 1533 | 1555 | "clearing NEWCHANGE flag because of effective seek\n"); |
|---|
| 1534 | | - debug_dcl(DP->flags, "jiffies=%lu\n", jiffies); |
|---|
| 1535 | | - clear_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags); |
|---|
| 1556 | + debug_dcl(drive_params[current_drive].flags, "jiffies=%lu\n", |
|---|
| 1557 | + jiffies); |
|---|
| 1558 | + clear_bit(FD_DISK_NEWCHANGE_BIT, |
|---|
| 1559 | + &drive_state[current_drive].flags); |
|---|
| 1536 | 1560 | /* effective seek */ |
|---|
| 1537 | | - DRS->select_date = jiffies; |
|---|
| 1561 | + drive_state[current_drive].select_date = jiffies; |
|---|
| 1538 | 1562 | } |
|---|
| 1539 | | - DRS->track = ST1; |
|---|
| 1563 | + drive_state[current_drive].track = reply_buffer[ST1]; |
|---|
| 1540 | 1564 | floppy_ready(); |
|---|
| 1541 | 1565 | } |
|---|
| 1542 | 1566 | |
|---|
| 1543 | | -static void check_wp(void) |
|---|
| 1567 | +static void check_wp(int fdc, int drive) |
|---|
| 1544 | 1568 | { |
|---|
| 1545 | | - if (test_bit(FD_VERIFY_BIT, &DRS->flags)) { |
|---|
| 1569 | + if (test_bit(FD_VERIFY_BIT, &drive_state[drive].flags)) { |
|---|
| 1546 | 1570 | /* check write protection */ |
|---|
| 1547 | | - output_byte(FD_GETSTATUS); |
|---|
| 1548 | | - output_byte(UNIT(current_drive)); |
|---|
| 1549 | | - if (result() != 1) { |
|---|
| 1550 | | - FDCS->reset = 1; |
|---|
| 1571 | + output_byte(fdc, FD_GETSTATUS); |
|---|
| 1572 | + output_byte(fdc, UNIT(drive)); |
|---|
| 1573 | + if (result(fdc) != 1) { |
|---|
| 1574 | + fdc_state[fdc].reset = 1; |
|---|
| 1551 | 1575 | return; |
|---|
| 1552 | 1576 | } |
|---|
| 1553 | | - clear_bit(FD_VERIFY_BIT, &DRS->flags); |
|---|
| 1554 | | - clear_bit(FD_NEED_TWADDLE_BIT, &DRS->flags); |
|---|
| 1555 | | - debug_dcl(DP->flags, |
|---|
| 1577 | + clear_bit(FD_VERIFY_BIT, &drive_state[drive].flags); |
|---|
| 1578 | + clear_bit(FD_NEED_TWADDLE_BIT, |
|---|
| 1579 | + &drive_state[drive].flags); |
|---|
| 1580 | + debug_dcl(drive_params[drive].flags, |
|---|
| 1556 | 1581 | "checking whether disk is write protected\n"); |
|---|
| 1557 | | - debug_dcl(DP->flags, "wp=%x\n", ST3 & 0x40); |
|---|
| 1558 | | - if (!(ST3 & 0x40)) |
|---|
| 1559 | | - set_bit(FD_DISK_WRITABLE_BIT, &DRS->flags); |
|---|
| 1582 | + debug_dcl(drive_params[drive].flags, "wp=%x\n", |
|---|
| 1583 | + reply_buffer[ST3] & 0x40); |
|---|
| 1584 | + if (!(reply_buffer[ST3] & 0x40)) |
|---|
| 1585 | + set_bit(FD_DISK_WRITABLE_BIT, |
|---|
| 1586 | + &drive_state[drive].flags); |
|---|
| 1560 | 1587 | else |
|---|
| 1561 | | - clear_bit(FD_DISK_WRITABLE_BIT, &DRS->flags); |
|---|
| 1588 | + clear_bit(FD_DISK_WRITABLE_BIT, |
|---|
| 1589 | + &drive_state[drive].flags); |
|---|
| 1562 | 1590 | } |
|---|
| 1563 | 1591 | } |
|---|
| 1564 | 1592 | |
|---|
| .. | .. |
|---|
| 1568 | 1596 | |
|---|
| 1569 | 1597 | blind_seek = 0; |
|---|
| 1570 | 1598 | |
|---|
| 1571 | | - debug_dcl(DP->flags, "calling disk change from %s\n", __func__); |
|---|
| 1599 | + debug_dcl(drive_params[current_drive].flags, |
|---|
| 1600 | + "calling disk change from %s\n", __func__); |
|---|
| 1572 | 1601 | |
|---|
| 1573 | | - if (!test_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags) && |
|---|
| 1602 | + if (!test_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags) && |
|---|
| 1574 | 1603 | disk_change(current_drive) && (raw_cmd->flags & FD_RAW_NEED_DISK)) { |
|---|
| 1575 | 1604 | /* the media changed flag should be cleared after the seek. |
|---|
| 1576 | 1605 | * If it isn't, this means that there is really no disk in |
|---|
| 1577 | 1606 | * the drive. |
|---|
| 1578 | 1607 | */ |
|---|
| 1579 | | - set_bit(FD_DISK_CHANGED_BIT, &DRS->flags); |
|---|
| 1608 | + set_bit(FD_DISK_CHANGED_BIT, |
|---|
| 1609 | + &drive_state[current_drive].flags); |
|---|
| 1580 | 1610 | cont->done(0); |
|---|
| 1581 | 1611 | cont->redo(); |
|---|
| 1582 | 1612 | return; |
|---|
| 1583 | 1613 | } |
|---|
| 1584 | | - if (DRS->track <= NEED_1_RECAL) { |
|---|
| 1614 | + if (drive_state[current_drive].track <= NEED_1_RECAL) { |
|---|
| 1585 | 1615 | recalibrate_floppy(); |
|---|
| 1586 | 1616 | return; |
|---|
| 1587 | | - } else if (test_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags) && |
|---|
| 1617 | + } else if (test_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags) && |
|---|
| 1588 | 1618 | (raw_cmd->flags & FD_RAW_NEED_DISK) && |
|---|
| 1589 | | - (DRS->track <= NO_TRACK || DRS->track == raw_cmd->track)) { |
|---|
| 1619 | + (drive_state[current_drive].track <= NO_TRACK || drive_state[current_drive].track == raw_cmd->track)) { |
|---|
| 1590 | 1620 | /* we seek to clear the media-changed condition. Does anybody |
|---|
| 1591 | 1621 | * know a more elegant way, which works on all drives? */ |
|---|
| 1592 | 1622 | if (raw_cmd->track) |
|---|
| 1593 | 1623 | track = raw_cmd->track - 1; |
|---|
| 1594 | 1624 | else { |
|---|
| 1595 | | - if (DP->flags & FD_SILENT_DCL_CLEAR) { |
|---|
| 1596 | | - set_dor(fdc, ~(0x10 << UNIT(current_drive)), 0); |
|---|
| 1625 | + if (drive_params[current_drive].flags & FD_SILENT_DCL_CLEAR) { |
|---|
| 1626 | + set_dor(current_fdc, ~(0x10 << UNIT(current_drive)), 0); |
|---|
| 1597 | 1627 | blind_seek = 1; |
|---|
| 1598 | 1628 | raw_cmd->flags |= FD_RAW_NEED_SEEK; |
|---|
| 1599 | 1629 | } |
|---|
| 1600 | 1630 | track = 1; |
|---|
| 1601 | 1631 | } |
|---|
| 1602 | 1632 | } else { |
|---|
| 1603 | | - check_wp(); |
|---|
| 1604 | | - if (raw_cmd->track != DRS->track && |
|---|
| 1633 | + check_wp(current_fdc, current_drive); |
|---|
| 1634 | + if (raw_cmd->track != drive_state[current_drive].track && |
|---|
| 1605 | 1635 | (raw_cmd->flags & FD_RAW_NEED_SEEK)) |
|---|
| 1606 | 1636 | track = raw_cmd->track; |
|---|
| 1607 | 1637 | else { |
|---|
| .. | .. |
|---|
| 1611 | 1641 | } |
|---|
| 1612 | 1642 | |
|---|
| 1613 | 1643 | do_floppy = seek_interrupt; |
|---|
| 1614 | | - output_byte(FD_SEEK); |
|---|
| 1615 | | - output_byte(UNIT(current_drive)); |
|---|
| 1616 | | - if (output_byte(track) < 0) { |
|---|
| 1644 | + output_byte(current_fdc, FD_SEEK); |
|---|
| 1645 | + output_byte(current_fdc, UNIT(current_drive)); |
|---|
| 1646 | + if (output_byte(current_fdc, track) < 0) { |
|---|
| 1617 | 1647 | reset_fdc(); |
|---|
| 1618 | 1648 | return; |
|---|
| 1619 | 1649 | } |
|---|
| .. | .. |
|---|
| 1624 | 1654 | { |
|---|
| 1625 | 1655 | debugt(__func__, ""); |
|---|
| 1626 | 1656 | if (inr != 2) |
|---|
| 1627 | | - FDCS->reset = 1; |
|---|
| 1628 | | - else if (ST0 & ST0_ECE) { |
|---|
| 1629 | | - switch (DRS->track) { |
|---|
| 1657 | + fdc_state[current_fdc].reset = 1; |
|---|
| 1658 | + else if (reply_buffer[ST0] & ST0_ECE) { |
|---|
| 1659 | + switch (drive_state[current_drive].track) { |
|---|
| 1630 | 1660 | case NEED_1_RECAL: |
|---|
| 1631 | 1661 | debugt(__func__, "need 1 recal"); |
|---|
| 1632 | 1662 | /* after a second recalibrate, we still haven't |
|---|
| .. | .. |
|---|
| 1644 | 1674 | * not to move at recalibration is to |
|---|
| 1645 | 1675 | * be already at track 0.) Clear the |
|---|
| 1646 | 1676 | * new change flag */ |
|---|
| 1647 | | - debug_dcl(DP->flags, |
|---|
| 1677 | + debug_dcl(drive_params[current_drive].flags, |
|---|
| 1648 | 1678 | "clearing NEWCHANGE flag because of second recalibrate\n"); |
|---|
| 1649 | 1679 | |
|---|
| 1650 | | - clear_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags); |
|---|
| 1651 | | - DRS->select_date = jiffies; |
|---|
| 1652 | | - /* fall through */ |
|---|
| 1680 | + clear_bit(FD_DISK_NEWCHANGE_BIT, |
|---|
| 1681 | + &drive_state[current_drive].flags); |
|---|
| 1682 | + drive_state[current_drive].select_date = jiffies; |
|---|
| 1683 | + fallthrough; |
|---|
| 1653 | 1684 | default: |
|---|
| 1654 | 1685 | debugt(__func__, "default"); |
|---|
| 1655 | 1686 | /* Recalibrate moves the head by at |
|---|
| .. | .. |
|---|
| 1658 | 1689 | * track 0, this might mean that we |
|---|
| 1659 | 1690 | * started beyond track 80. Try |
|---|
| 1660 | 1691 | * again. */ |
|---|
| 1661 | | - DRS->track = NEED_1_RECAL; |
|---|
| 1692 | + drive_state[current_drive].track = NEED_1_RECAL; |
|---|
| 1662 | 1693 | break; |
|---|
| 1663 | 1694 | } |
|---|
| 1664 | 1695 | } else |
|---|
| 1665 | | - DRS->track = ST1; |
|---|
| 1696 | + drive_state[current_drive].track = reply_buffer[ST1]; |
|---|
| 1666 | 1697 | floppy_ready(); |
|---|
| 1667 | 1698 | } |
|---|
| 1668 | 1699 | |
|---|
| .. | .. |
|---|
| 1692 | 1723 | release_dma_lock(f); |
|---|
| 1693 | 1724 | |
|---|
| 1694 | 1725 | do_floppy = NULL; |
|---|
| 1695 | | - if (fdc >= N_FDC || FDCS->address == -1) { |
|---|
| 1726 | + if (current_fdc >= N_FDC || fdc_state[current_fdc].address == -1) { |
|---|
| 1696 | 1727 | /* we don't even know which FDC is the culprit */ |
|---|
| 1697 | 1728 | pr_info("DOR0=%x\n", fdc_state[0].dor); |
|---|
| 1698 | | - pr_info("floppy interrupt on bizarre fdc %d\n", fdc); |
|---|
| 1699 | | - pr_info("handler=%pf\n", handler); |
|---|
| 1729 | + pr_info("floppy interrupt on bizarre fdc %d\n", current_fdc); |
|---|
| 1730 | + pr_info("handler=%ps\n", handler); |
|---|
| 1700 | 1731 | is_alive(__func__, "bizarre fdc"); |
|---|
| 1701 | 1732 | return IRQ_NONE; |
|---|
| 1702 | 1733 | } |
|---|
| 1703 | 1734 | |
|---|
| 1704 | | - FDCS->reset = 0; |
|---|
| 1735 | + fdc_state[current_fdc].reset = 0; |
|---|
| 1705 | 1736 | /* We have to clear the reset flag here, because apparently on boxes |
|---|
| 1706 | 1737 | * with level triggered interrupts (PS/2, Sparc, ...), it is needed to |
|---|
| 1707 | | - * emit SENSEI's to clear the interrupt line. And FDCS->reset blocks the |
|---|
| 1708 | | - * emission of the SENSEI's. |
|---|
| 1738 | + * emit SENSEI's to clear the interrupt line. And fdc_state[fdc].reset |
|---|
| 1739 | + * blocks the emission of the SENSEI's. |
|---|
| 1709 | 1740 | * It is OK to emit floppy commands because we are in an interrupt |
|---|
| 1710 | 1741 | * handler here, and thus we have to fear no interference of other |
|---|
| 1711 | 1742 | * activity. |
|---|
| .. | .. |
|---|
| 1713 | 1744 | |
|---|
| 1714 | 1745 | do_print = !handler && print_unex && initialized; |
|---|
| 1715 | 1746 | |
|---|
| 1716 | | - inr = result(); |
|---|
| 1747 | + inr = result(current_fdc); |
|---|
| 1717 | 1748 | if (do_print) |
|---|
| 1718 | 1749 | print_result("unexpected interrupt", inr); |
|---|
| 1719 | 1750 | if (inr == 0) { |
|---|
| 1720 | 1751 | int max_sensei = 4; |
|---|
| 1721 | 1752 | do { |
|---|
| 1722 | | - output_byte(FD_SENSEI); |
|---|
| 1723 | | - inr = result(); |
|---|
| 1753 | + output_byte(current_fdc, FD_SENSEI); |
|---|
| 1754 | + inr = result(current_fdc); |
|---|
| 1724 | 1755 | if (do_print) |
|---|
| 1725 | 1756 | print_result("sensei", inr); |
|---|
| 1726 | 1757 | max_sensei--; |
|---|
| 1727 | | - } while ((ST0 & 0x83) != UNIT(current_drive) && |
|---|
| 1758 | + } while ((reply_buffer[ST0] & 0x83) != UNIT(current_drive) && |
|---|
| 1728 | 1759 | inr == 2 && max_sensei); |
|---|
| 1729 | 1760 | } |
|---|
| 1730 | 1761 | if (!handler) { |
|---|
| 1731 | | - FDCS->reset = 1; |
|---|
| 1762 | + fdc_state[current_fdc].reset = 1; |
|---|
| 1732 | 1763 | return IRQ_NONE; |
|---|
| 1733 | 1764 | } |
|---|
| 1734 | 1765 | schedule_bh(handler); |
|---|
| .. | .. |
|---|
| 1742 | 1773 | { |
|---|
| 1743 | 1774 | debugt(__func__, ""); |
|---|
| 1744 | 1775 | do_floppy = recal_interrupt; |
|---|
| 1745 | | - output_byte(FD_RECALIBRATE); |
|---|
| 1746 | | - if (output_byte(UNIT(current_drive)) < 0) |
|---|
| 1776 | + output_byte(current_fdc, FD_RECALIBRATE); |
|---|
| 1777 | + if (output_byte(current_fdc, UNIT(current_drive)) < 0) |
|---|
| 1747 | 1778 | reset_fdc(); |
|---|
| 1748 | 1779 | } |
|---|
| 1749 | 1780 | |
|---|
| .. | .. |
|---|
| 1753 | 1784 | static void reset_interrupt(void) |
|---|
| 1754 | 1785 | { |
|---|
| 1755 | 1786 | debugt(__func__, ""); |
|---|
| 1756 | | - result(); /* get the status ready for set_fdc */ |
|---|
| 1757 | | - if (FDCS->reset) { |
|---|
| 1758 | | - pr_info("reset set in interrupt, calling %pf\n", cont->error); |
|---|
| 1787 | + result(current_fdc); /* get the status ready for set_fdc */ |
|---|
| 1788 | + if (fdc_state[current_fdc].reset) { |
|---|
| 1789 | + pr_info("reset set in interrupt, calling %ps\n", cont->error); |
|---|
| 1759 | 1790 | cont->error(); /* a reset just after a reset. BAD! */ |
|---|
| 1760 | 1791 | } |
|---|
| 1761 | 1792 | cont->redo(); |
|---|
| .. | .. |
|---|
| 1763 | 1794 | |
|---|
| 1764 | 1795 | /* |
|---|
| 1765 | 1796 | * reset is done by pulling bit 2 of DOR low for a while (old FDCs), |
|---|
| 1766 | | - * or by setting the self clearing bit 7 of STATUS (newer FDCs) |
|---|
| 1797 | + * or by setting the self clearing bit 7 of STATUS (newer FDCs). |
|---|
| 1798 | + * This WILL trigger an interrupt, causing the handlers in the current |
|---|
| 1799 | + * cont's ->redo() to be called via reset_interrupt(). |
|---|
| 1767 | 1800 | */ |
|---|
| 1768 | 1801 | static void reset_fdc(void) |
|---|
| 1769 | 1802 | { |
|---|
| 1770 | 1803 | unsigned long flags; |
|---|
| 1771 | 1804 | |
|---|
| 1772 | 1805 | do_floppy = reset_interrupt; |
|---|
| 1773 | | - FDCS->reset = 0; |
|---|
| 1774 | | - reset_fdc_info(0); |
|---|
| 1806 | + fdc_state[current_fdc].reset = 0; |
|---|
| 1807 | + reset_fdc_info(current_fdc, 0); |
|---|
| 1775 | 1808 | |
|---|
| 1776 | 1809 | /* Pseudo-DMA may intercept 'reset finished' interrupt. */ |
|---|
| 1777 | 1810 | /* Irrelevant for systems with true DMA (i386). */ |
|---|
| .. | .. |
|---|
| 1780 | 1813 | fd_disable_dma(); |
|---|
| 1781 | 1814 | release_dma_lock(flags); |
|---|
| 1782 | 1815 | |
|---|
| 1783 | | - if (FDCS->version >= FDC_82072A) |
|---|
| 1784 | | - fd_outb(0x80 | (FDCS->dtr & 3), FD_STATUS); |
|---|
| 1816 | + if (fdc_state[current_fdc].version >= FDC_82072A) |
|---|
| 1817 | + fdc_outb(0x80 | (fdc_state[current_fdc].dtr & 3), |
|---|
| 1818 | + current_fdc, FD_STATUS); |
|---|
| 1785 | 1819 | else { |
|---|
| 1786 | | - fd_outb(FDCS->dor & ~0x04, FD_DOR); |
|---|
| 1820 | + fdc_outb(fdc_state[current_fdc].dor & ~0x04, current_fdc, FD_DOR); |
|---|
| 1787 | 1821 | udelay(FD_RESET_DELAY); |
|---|
| 1788 | | - fd_outb(FDCS->dor, FD_DOR); |
|---|
| 1822 | + fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR); |
|---|
| 1789 | 1823 | } |
|---|
| 1790 | 1824 | } |
|---|
| 1791 | 1825 | |
|---|
| 1792 | | -static void show_floppy(void) |
|---|
| 1826 | +static void show_floppy(int fdc) |
|---|
| 1793 | 1827 | { |
|---|
| 1794 | 1828 | int i; |
|---|
| 1795 | 1829 | |
|---|
| 1796 | 1830 | pr_info("\n"); |
|---|
| 1797 | 1831 | pr_info("floppy driver state\n"); |
|---|
| 1798 | 1832 | pr_info("-------------------\n"); |
|---|
| 1799 | | - pr_info("now=%lu last interrupt=%lu diff=%lu last called handler=%pf\n", |
|---|
| 1833 | + pr_info("now=%lu last interrupt=%lu diff=%lu last called handler=%ps\n", |
|---|
| 1800 | 1834 | jiffies, interruptjiffies, jiffies - interruptjiffies, |
|---|
| 1801 | 1835 | lasthandler); |
|---|
| 1802 | 1836 | |
|---|
| .. | .. |
|---|
| 1812 | 1846 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1, |
|---|
| 1813 | 1847 | reply_buffer, resultsize, true); |
|---|
| 1814 | 1848 | |
|---|
| 1815 | | - pr_info("status=%x\n", fd_inb(FD_STATUS)); |
|---|
| 1849 | + pr_info("status=%x\n", fdc_inb(fdc, FD_STATUS)); |
|---|
| 1816 | 1850 | pr_info("fdc_busy=%lu\n", fdc_busy); |
|---|
| 1817 | 1851 | if (do_floppy) |
|---|
| 1818 | | - pr_info("do_floppy=%pf\n", do_floppy); |
|---|
| 1852 | + pr_info("do_floppy=%ps\n", do_floppy); |
|---|
| 1819 | 1853 | if (work_pending(&floppy_work)) |
|---|
| 1820 | | - pr_info("floppy_work.func=%pf\n", floppy_work.func); |
|---|
| 1854 | + pr_info("floppy_work.func=%ps\n", floppy_work.func); |
|---|
| 1821 | 1855 | if (delayed_work_pending(&fd_timer)) |
|---|
| 1822 | 1856 | pr_info("delayed work.function=%p expires=%ld\n", |
|---|
| 1823 | 1857 | fd_timer.work.func, |
|---|
| .. | .. |
|---|
| 1838 | 1872 | unsigned long flags; |
|---|
| 1839 | 1873 | |
|---|
| 1840 | 1874 | if (initialized) |
|---|
| 1841 | | - show_floppy(); |
|---|
| 1875 | + show_floppy(current_fdc); |
|---|
| 1842 | 1876 | cancel_activity(); |
|---|
| 1843 | 1877 | |
|---|
| 1844 | 1878 | flags = claim_dma_lock(); |
|---|
| .. | .. |
|---|
| 1849 | 1883 | |
|---|
| 1850 | 1884 | if (initialized) |
|---|
| 1851 | 1885 | DPRINT("floppy timeout called\n"); |
|---|
| 1852 | | - FDCS->reset = 1; |
|---|
| 1886 | + fdc_state[current_fdc].reset = 1; |
|---|
| 1853 | 1887 | if (cont) { |
|---|
| 1854 | 1888 | cont->done(0); |
|---|
| 1855 | 1889 | cont->redo(); /* this will recall reset when needed */ |
|---|
| .. | .. |
|---|
| 1869 | 1903 | mask = 0xfc; |
|---|
| 1870 | 1904 | data = UNIT(current_drive); |
|---|
| 1871 | 1905 | if (!(raw_cmd->flags & FD_RAW_NO_MOTOR)) { |
|---|
| 1872 | | - if (!(FDCS->dor & (0x10 << UNIT(current_drive)))) { |
|---|
| 1906 | + if (!(fdc_state[current_fdc].dor & (0x10 << UNIT(current_drive)))) { |
|---|
| 1873 | 1907 | set_debugt(); |
|---|
| 1874 | 1908 | /* no read since this drive is running */ |
|---|
| 1875 | | - DRS->first_read_date = 0; |
|---|
| 1909 | + drive_state[current_drive].first_read_date = 0; |
|---|
| 1876 | 1910 | /* note motor start time if motor is not yet running */ |
|---|
| 1877 | | - DRS->spinup_date = jiffies; |
|---|
| 1911 | + drive_state[current_drive].spinup_date = jiffies; |
|---|
| 1878 | 1912 | data |= (0x10 << UNIT(current_drive)); |
|---|
| 1879 | 1913 | } |
|---|
| 1880 | | - } else if (FDCS->dor & (0x10 << UNIT(current_drive))) |
|---|
| 1914 | + } else if (fdc_state[current_fdc].dor & (0x10 << UNIT(current_drive))) |
|---|
| 1881 | 1915 | mask &= ~(0x10 << UNIT(current_drive)); |
|---|
| 1882 | 1916 | |
|---|
| 1883 | 1917 | /* starts motor and selects floppy */ |
|---|
| 1884 | 1918 | del_timer(motor_off_timer + current_drive); |
|---|
| 1885 | | - set_dor(fdc, mask, data); |
|---|
| 1919 | + set_dor(current_fdc, mask, data); |
|---|
| 1886 | 1920 | |
|---|
| 1887 | 1921 | /* wait_for_completion also schedules reset if needed. */ |
|---|
| 1888 | | - return fd_wait_for_completion(DRS->select_date + DP->select_delay, |
|---|
| 1922 | + return fd_wait_for_completion(drive_state[current_drive].select_date + drive_params[current_drive].select_delay, |
|---|
| 1889 | 1923 | function); |
|---|
| 1890 | 1924 | } |
|---|
| 1891 | 1925 | |
|---|
| 1892 | 1926 | static void floppy_ready(void) |
|---|
| 1893 | 1927 | { |
|---|
| 1894 | | - if (FDCS->reset) { |
|---|
| 1928 | + if (fdc_state[current_fdc].reset) { |
|---|
| 1895 | 1929 | reset_fdc(); |
|---|
| 1896 | 1930 | return; |
|---|
| 1897 | 1931 | } |
|---|
| .. | .. |
|---|
| 1900 | 1934 | if (fdc_dtr()) |
|---|
| 1901 | 1935 | return; |
|---|
| 1902 | 1936 | |
|---|
| 1903 | | - debug_dcl(DP->flags, "calling disk change from floppy_ready\n"); |
|---|
| 1937 | + debug_dcl(drive_params[current_drive].flags, |
|---|
| 1938 | + "calling disk change from floppy_ready\n"); |
|---|
| 1904 | 1939 | if (!(raw_cmd->flags & FD_RAW_NO_MOTOR) && |
|---|
| 1905 | | - disk_change(current_drive) && !DP->select_delay) |
|---|
| 1906 | | - twaddle(); /* this clears the dcl on certain |
|---|
| 1940 | + disk_change(current_drive) && !drive_params[current_drive].select_delay) |
|---|
| 1941 | + twaddle(current_fdc, current_drive); /* this clears the dcl on certain |
|---|
| 1907 | 1942 | * drive/controller combinations */ |
|---|
| 1908 | 1943 | |
|---|
| 1909 | 1944 | #ifdef fd_chose_dma_mode |
|---|
| .. | .. |
|---|
| 1915 | 1950 | #endif |
|---|
| 1916 | 1951 | |
|---|
| 1917 | 1952 | if (raw_cmd->flags & (FD_RAW_NEED_SEEK | FD_RAW_NEED_DISK)) { |
|---|
| 1918 | | - perpendicular_mode(); |
|---|
| 1919 | | - fdc_specify(); /* must be done here because of hut, hlt ... */ |
|---|
| 1953 | + perpendicular_mode(current_fdc); |
|---|
| 1954 | + fdc_specify(current_fdc, current_drive); /* must be done here because of hut, hlt ... */ |
|---|
| 1920 | 1955 | seek_floppy(); |
|---|
| 1921 | 1956 | } else { |
|---|
| 1922 | 1957 | if ((raw_cmd->flags & FD_RAW_READ) || |
|---|
| 1923 | 1958 | (raw_cmd->flags & FD_RAW_WRITE)) |
|---|
| 1924 | | - fdc_specify(); |
|---|
| 1959 | + fdc_specify(current_fdc, current_drive); |
|---|
| 1925 | 1960 | setup_rw_floppy(); |
|---|
| 1926 | 1961 | } |
|---|
| 1927 | 1962 | } |
|---|
| 1928 | 1963 | |
|---|
| 1929 | 1964 | static void floppy_start(void) |
|---|
| 1930 | 1965 | { |
|---|
| 1931 | | - reschedule_timeout(current_reqD, "floppy start"); |
|---|
| 1966 | + reschedule_timeout(current_drive, "floppy start"); |
|---|
| 1932 | 1967 | |
|---|
| 1933 | 1968 | scandrives(); |
|---|
| 1934 | | - debug_dcl(DP->flags, "setting NEWCHANGE in floppy_start\n"); |
|---|
| 1935 | | - set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags); |
|---|
| 1969 | + debug_dcl(drive_params[current_drive].flags, |
|---|
| 1970 | + "setting NEWCHANGE in floppy_start\n"); |
|---|
| 1971 | + set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags); |
|---|
| 1936 | 1972 | floppy_ready(); |
|---|
| 1937 | 1973 | } |
|---|
| 1938 | 1974 | |
|---|
| .. | .. |
|---|
| 1972 | 2008 | .done = (done_f)empty |
|---|
| 1973 | 2009 | }; |
|---|
| 1974 | 2010 | |
|---|
| 2011 | +/* schedules handler, waiting for completion. May be interrupted, will then |
|---|
| 2012 | + * return -EINTR, in which case the driver will automatically be unlocked. |
|---|
| 2013 | + */ |
|---|
| 1975 | 2014 | static int wait_til_done(void (*handler)(void), bool interruptible) |
|---|
| 1976 | 2015 | { |
|---|
| 1977 | 2016 | int ret; |
|---|
| .. | .. |
|---|
| 1990 | 2029 | return -EINTR; |
|---|
| 1991 | 2030 | } |
|---|
| 1992 | 2031 | |
|---|
| 1993 | | - if (FDCS->reset) |
|---|
| 2032 | + if (fdc_state[current_fdc].reset) |
|---|
| 1994 | 2033 | command_status = FD_COMMAND_ERROR; |
|---|
| 1995 | 2034 | if (command_status == FD_COMMAND_OKAY) |
|---|
| 1996 | 2035 | ret = 0; |
|---|
| .. | .. |
|---|
| 2027 | 2066 | * ========================== |
|---|
| 2028 | 2067 | */ |
|---|
| 2029 | 2068 | |
|---|
| 2030 | | -static int next_valid_format(void) |
|---|
| 2069 | +static int next_valid_format(int drive) |
|---|
| 2031 | 2070 | { |
|---|
| 2032 | 2071 | int probed_format; |
|---|
| 2033 | 2072 | |
|---|
| 2034 | | - probed_format = DRS->probed_format; |
|---|
| 2073 | + probed_format = drive_state[drive].probed_format; |
|---|
| 2035 | 2074 | while (1) { |
|---|
| 2036 | | - if (probed_format >= 8 || !DP->autodetect[probed_format]) { |
|---|
| 2037 | | - DRS->probed_format = 0; |
|---|
| 2075 | + if (probed_format >= FD_AUTODETECT_SIZE || |
|---|
| 2076 | + !drive_params[drive].autodetect[probed_format]) { |
|---|
| 2077 | + drive_state[drive].probed_format = 0; |
|---|
| 2038 | 2078 | return 1; |
|---|
| 2039 | 2079 | } |
|---|
| 2040 | | - if (floppy_type[DP->autodetect[probed_format]].sect) { |
|---|
| 2041 | | - DRS->probed_format = probed_format; |
|---|
| 2080 | + if (floppy_type[drive_params[drive].autodetect[probed_format]].sect) { |
|---|
| 2081 | + drive_state[drive].probed_format = probed_format; |
|---|
| 2042 | 2082 | return 0; |
|---|
| 2043 | 2083 | } |
|---|
| 2044 | 2084 | probed_format++; |
|---|
| .. | .. |
|---|
| 2050 | 2090 | int err_count; |
|---|
| 2051 | 2091 | |
|---|
| 2052 | 2092 | if (probing) { |
|---|
| 2053 | | - DRS->probed_format++; |
|---|
| 2054 | | - if (!next_valid_format()) |
|---|
| 2093 | + drive_state[current_drive].probed_format++; |
|---|
| 2094 | + if (!next_valid_format(current_drive)) |
|---|
| 2055 | 2095 | return; |
|---|
| 2056 | 2096 | } |
|---|
| 2057 | | - err_count = ++(*errors); |
|---|
| 2058 | | - INFBOUND(DRWE->badness, err_count); |
|---|
| 2059 | | - if (err_count > DP->max_errors.abort) |
|---|
| 2097 | + err_count = ++floppy_errors; |
|---|
| 2098 | + INFBOUND(write_errors[current_drive].badness, err_count); |
|---|
| 2099 | + if (err_count > drive_params[current_drive].max_errors.abort) |
|---|
| 2060 | 2100 | cont->done(0); |
|---|
| 2061 | | - if (err_count > DP->max_errors.reset) |
|---|
| 2062 | | - FDCS->reset = 1; |
|---|
| 2063 | | - else if (err_count > DP->max_errors.recal) |
|---|
| 2064 | | - DRS->track = NEED_2_RECAL; |
|---|
| 2101 | + if (err_count > drive_params[current_drive].max_errors.reset) |
|---|
| 2102 | + fdc_state[current_fdc].reset = 1; |
|---|
| 2103 | + else if (err_count > drive_params[current_drive].max_errors.recal) |
|---|
| 2104 | + drive_state[current_drive].track = NEED_2_RECAL; |
|---|
| 2065 | 2105 | } |
|---|
| 2066 | 2106 | |
|---|
| 2067 | 2107 | static void set_floppy(int drive) |
|---|
| 2068 | 2108 | { |
|---|
| 2069 | | - int type = ITYPE(UDRS->fd_device); |
|---|
| 2109 | + int type = ITYPE(drive_state[drive].fd_device); |
|---|
| 2070 | 2110 | |
|---|
| 2071 | 2111 | if (type) |
|---|
| 2072 | 2112 | _floppy = floppy_type + type; |
|---|
| .. | .. |
|---|
| 2112 | 2152 | FD_RAW_NEED_DISK | FD_RAW_NEED_SEEK); |
|---|
| 2113 | 2153 | raw_cmd->rate = _floppy->rate & 0x43; |
|---|
| 2114 | 2154 | raw_cmd->cmd_count = NR_F; |
|---|
| 2115 | | - COMMAND = FM_MODE(_floppy, FD_FORMAT); |
|---|
| 2116 | | - DR_SELECT = UNIT(current_drive) + PH_HEAD(_floppy, format_req.head); |
|---|
| 2117 | | - F_SIZECODE = FD_SIZECODE(_floppy); |
|---|
| 2118 | | - F_SECT_PER_TRACK = _floppy->sect << 2 >> F_SIZECODE; |
|---|
| 2119 | | - F_GAP = _floppy->fmt_gap; |
|---|
| 2120 | | - F_FILL = FD_FILL_BYTE; |
|---|
| 2155 | + raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_FORMAT); |
|---|
| 2156 | + raw_cmd->cmd[DR_SELECT] = UNIT(current_drive) + PH_HEAD(_floppy, format_req.head); |
|---|
| 2157 | + raw_cmd->cmd[F_SIZECODE] = FD_SIZECODE(_floppy); |
|---|
| 2158 | + raw_cmd->cmd[F_SECT_PER_TRACK] = _floppy->sect << 2 >> raw_cmd->cmd[F_SIZECODE]; |
|---|
| 2159 | + raw_cmd->cmd[F_GAP] = _floppy->fmt_gap; |
|---|
| 2160 | + raw_cmd->cmd[F_FILL] = FD_FILL_BYTE; |
|---|
| 2121 | 2161 | |
|---|
| 2122 | 2162 | raw_cmd->kernel_data = floppy_track_buffer; |
|---|
| 2123 | | - raw_cmd->length = 4 * F_SECT_PER_TRACK; |
|---|
| 2163 | + raw_cmd->length = 4 * raw_cmd->cmd[F_SECT_PER_TRACK]; |
|---|
| 2124 | 2164 | |
|---|
| 2125 | | - if (!F_SECT_PER_TRACK) |
|---|
| 2165 | + if (!raw_cmd->cmd[F_SECT_PER_TRACK]) |
|---|
| 2126 | 2166 | return; |
|---|
| 2127 | 2167 | |
|---|
| 2128 | 2168 | /* allow for about 30ms for data transport per track */ |
|---|
| 2129 | | - head_shift = (F_SECT_PER_TRACK + 5) / 6; |
|---|
| 2169 | + head_shift = (raw_cmd->cmd[F_SECT_PER_TRACK] + 5) / 6; |
|---|
| 2130 | 2170 | |
|---|
| 2131 | 2171 | /* a ``cylinder'' is two tracks plus a little stepping time */ |
|---|
| 2132 | 2172 | track_shift = 2 * head_shift + 3; |
|---|
| 2133 | 2173 | |
|---|
| 2134 | 2174 | /* position of logical sector 1 on this track */ |
|---|
| 2135 | 2175 | n = (track_shift * format_req.track + head_shift * format_req.head) |
|---|
| 2136 | | - % F_SECT_PER_TRACK; |
|---|
| 2176 | + % raw_cmd->cmd[F_SECT_PER_TRACK]; |
|---|
| 2137 | 2177 | |
|---|
| 2138 | 2178 | /* determine interleave */ |
|---|
| 2139 | 2179 | il = 1; |
|---|
| .. | .. |
|---|
| 2141 | 2181 | il++; |
|---|
| 2142 | 2182 | |
|---|
| 2143 | 2183 | /* initialize field */ |
|---|
| 2144 | | - for (count = 0; count < F_SECT_PER_TRACK; ++count) { |
|---|
| 2184 | + for (count = 0; count < raw_cmd->cmd[F_SECT_PER_TRACK]; ++count) { |
|---|
| 2145 | 2185 | here[count].track = format_req.track; |
|---|
| 2146 | 2186 | here[count].head = format_req.head; |
|---|
| 2147 | 2187 | here[count].sect = 0; |
|---|
| 2148 | | - here[count].size = F_SIZECODE; |
|---|
| 2188 | + here[count].size = raw_cmd->cmd[F_SIZECODE]; |
|---|
| 2149 | 2189 | } |
|---|
| 2150 | 2190 | /* place logical sectors */ |
|---|
| 2151 | | - for (count = 1; count <= F_SECT_PER_TRACK; ++count) { |
|---|
| 2191 | + for (count = 1; count <= raw_cmd->cmd[F_SECT_PER_TRACK]; ++count) { |
|---|
| 2152 | 2192 | here[n].sect = count; |
|---|
| 2153 | | - n = (n + il) % F_SECT_PER_TRACK; |
|---|
| 2193 | + n = (n + il) % raw_cmd->cmd[F_SECT_PER_TRACK]; |
|---|
| 2154 | 2194 | if (here[n].sect) { /* sector busy, find next free sector */ |
|---|
| 2155 | 2195 | ++n; |
|---|
| 2156 | | - if (n >= F_SECT_PER_TRACK) { |
|---|
| 2157 | | - n -= F_SECT_PER_TRACK; |
|---|
| 2196 | + if (n >= raw_cmd->cmd[F_SECT_PER_TRACK]) { |
|---|
| 2197 | + n -= raw_cmd->cmd[F_SECT_PER_TRACK]; |
|---|
| 2158 | 2198 | while (here[n].sect) |
|---|
| 2159 | 2199 | ++n; |
|---|
| 2160 | 2200 | } |
|---|
| 2161 | 2201 | } |
|---|
| 2162 | 2202 | } |
|---|
| 2163 | 2203 | if (_floppy->stretch & FD_SECTBASEMASK) { |
|---|
| 2164 | | - for (count = 0; count < F_SECT_PER_TRACK; count++) |
|---|
| 2204 | + for (count = 0; count < raw_cmd->cmd[F_SECT_PER_TRACK]; count++) |
|---|
| 2165 | 2205 | here[count].sect += FD_SECTBASE(_floppy) - 1; |
|---|
| 2166 | 2206 | } |
|---|
| 2167 | 2207 | } |
|---|
| .. | .. |
|---|
| 2190 | 2230 | |
|---|
| 2191 | 2231 | set_floppy(drive); |
|---|
| 2192 | 2232 | if (!_floppy || |
|---|
| 2193 | | - _floppy->track > DP->tracks || |
|---|
| 2233 | + _floppy->track > drive_params[current_drive].tracks || |
|---|
| 2194 | 2234 | tmp_format_req->track >= _floppy->track || |
|---|
| 2195 | 2235 | tmp_format_req->head >= _floppy->head || |
|---|
| 2196 | 2236 | (_floppy->sect << 2) % (1 << FD_SIZECODE(_floppy)) || |
|---|
| .. | .. |
|---|
| 2199 | 2239 | return -EINVAL; |
|---|
| 2200 | 2240 | } |
|---|
| 2201 | 2241 | format_req = *tmp_format_req; |
|---|
| 2202 | | - format_errors = 0; |
|---|
| 2203 | 2242 | cont = &format_cont; |
|---|
| 2204 | | - errors = &format_errors; |
|---|
| 2243 | + floppy_errors = 0; |
|---|
| 2205 | 2244 | ret = wait_til_done(redo_format, true); |
|---|
| 2206 | 2245 | if (ret == -EINTR) |
|---|
| 2207 | 2246 | return -EINTR; |
|---|
| .. | .. |
|---|
| 2222 | 2261 | /* current_count_sectors can be zero if transfer failed */ |
|---|
| 2223 | 2262 | if (error) |
|---|
| 2224 | 2263 | nr_sectors = blk_rq_cur_sectors(req); |
|---|
| 2225 | | - if (__blk_end_request(req, error, nr_sectors << 9)) |
|---|
| 2264 | + if (blk_update_request(req, error, nr_sectors << 9)) |
|---|
| 2226 | 2265 | return; |
|---|
| 2266 | + __blk_mq_end_request(req, error); |
|---|
| 2227 | 2267 | |
|---|
| 2228 | 2268 | /* We're done with the request */ |
|---|
| 2229 | 2269 | floppy_off(drive); |
|---|
| .. | .. |
|---|
| 2235 | 2275 | static void request_done(int uptodate) |
|---|
| 2236 | 2276 | { |
|---|
| 2237 | 2277 | struct request *req = current_req; |
|---|
| 2238 | | - struct request_queue *q; |
|---|
| 2239 | | - unsigned long flags; |
|---|
| 2240 | 2278 | int block; |
|---|
| 2241 | 2279 | char msg[sizeof("request done ") + sizeof(int) * 3]; |
|---|
| 2242 | 2280 | |
|---|
| .. | .. |
|---|
| 2249 | 2287 | return; |
|---|
| 2250 | 2288 | } |
|---|
| 2251 | 2289 | |
|---|
| 2252 | | - q = req->q; |
|---|
| 2253 | | - |
|---|
| 2254 | 2290 | if (uptodate) { |
|---|
| 2255 | 2291 | /* maintain values for invalidation on geometry |
|---|
| 2256 | 2292 | * change */ |
|---|
| 2257 | 2293 | block = current_count_sectors + blk_rq_pos(req); |
|---|
| 2258 | | - INFBOUND(DRS->maxblock, block); |
|---|
| 2294 | + INFBOUND(drive_state[current_drive].maxblock, block); |
|---|
| 2259 | 2295 | if (block > _floppy->sect) |
|---|
| 2260 | | - DRS->maxtrack = 1; |
|---|
| 2296 | + drive_state[current_drive].maxtrack = 1; |
|---|
| 2261 | 2297 | |
|---|
| 2262 | | - /* unlock chained buffers */ |
|---|
| 2263 | | - spin_lock_irqsave(q->queue_lock, flags); |
|---|
| 2264 | 2298 | floppy_end_request(req, 0); |
|---|
| 2265 | | - spin_unlock_irqrestore(q->queue_lock, flags); |
|---|
| 2266 | 2299 | } else { |
|---|
| 2267 | 2300 | if (rq_data_dir(req) == WRITE) { |
|---|
| 2268 | 2301 | /* record write error information */ |
|---|
| 2269 | | - DRWE->write_errors++; |
|---|
| 2270 | | - if (DRWE->write_errors == 1) { |
|---|
| 2271 | | - DRWE->first_error_sector = blk_rq_pos(req); |
|---|
| 2272 | | - DRWE->first_error_generation = DRS->generation; |
|---|
| 2302 | + write_errors[current_drive].write_errors++; |
|---|
| 2303 | + if (write_errors[current_drive].write_errors == 1) { |
|---|
| 2304 | + write_errors[current_drive].first_error_sector = blk_rq_pos(req); |
|---|
| 2305 | + write_errors[current_drive].first_error_generation = drive_state[current_drive].generation; |
|---|
| 2273 | 2306 | } |
|---|
| 2274 | | - DRWE->last_error_sector = blk_rq_pos(req); |
|---|
| 2275 | | - DRWE->last_error_generation = DRS->generation; |
|---|
| 2307 | + write_errors[current_drive].last_error_sector = blk_rq_pos(req); |
|---|
| 2308 | + write_errors[current_drive].last_error_generation = drive_state[current_drive].generation; |
|---|
| 2276 | 2309 | } |
|---|
| 2277 | | - spin_lock_irqsave(q->queue_lock, flags); |
|---|
| 2278 | 2310 | floppy_end_request(req, BLK_STS_IOERR); |
|---|
| 2279 | | - spin_unlock_irqrestore(q->queue_lock, flags); |
|---|
| 2280 | 2311 | } |
|---|
| 2281 | 2312 | } |
|---|
| 2282 | 2313 | |
|---|
| .. | .. |
|---|
| 2288 | 2319 | int heads; |
|---|
| 2289 | 2320 | int nr_sectors; |
|---|
| 2290 | 2321 | |
|---|
| 2291 | | - if (R_HEAD >= 2) { |
|---|
| 2322 | + if (reply_buffer[R_HEAD] >= 2) { |
|---|
| 2292 | 2323 | /* some Toshiba floppy controllers occasionnally seem to |
|---|
| 2293 | 2324 | * return bogus interrupts after read/write operations, which |
|---|
| 2294 | 2325 | * can be recognized by a bad head number (>= 2) */ |
|---|
| 2295 | 2326 | return; |
|---|
| 2296 | 2327 | } |
|---|
| 2297 | 2328 | |
|---|
| 2298 | | - if (!DRS->first_read_date) |
|---|
| 2299 | | - DRS->first_read_date = jiffies; |
|---|
| 2329 | + if (!drive_state[current_drive].first_read_date) |
|---|
| 2330 | + drive_state[current_drive].first_read_date = jiffies; |
|---|
| 2300 | 2331 | |
|---|
| 2301 | 2332 | nr_sectors = 0; |
|---|
| 2302 | | - ssize = DIV_ROUND_UP(1 << SIZECODE, 4); |
|---|
| 2333 | + ssize = DIV_ROUND_UP(1 << raw_cmd->cmd[SIZECODE], 4); |
|---|
| 2303 | 2334 | |
|---|
| 2304 | | - if (ST1 & ST1_EOC) |
|---|
| 2335 | + if (reply_buffer[ST1] & ST1_EOC) |
|---|
| 2305 | 2336 | eoc = 1; |
|---|
| 2306 | 2337 | else |
|---|
| 2307 | 2338 | eoc = 0; |
|---|
| 2308 | 2339 | |
|---|
| 2309 | | - if (COMMAND & 0x80) |
|---|
| 2340 | + if (raw_cmd->cmd[COMMAND] & 0x80) |
|---|
| 2310 | 2341 | heads = 2; |
|---|
| 2311 | 2342 | else |
|---|
| 2312 | 2343 | heads = 1; |
|---|
| 2313 | 2344 | |
|---|
| 2314 | | - nr_sectors = (((R_TRACK - TRACK) * heads + |
|---|
| 2315 | | - R_HEAD - HEAD) * SECT_PER_TRACK + |
|---|
| 2316 | | - R_SECTOR - SECTOR + eoc) << SIZECODE >> 2; |
|---|
| 2345 | + nr_sectors = (((reply_buffer[R_TRACK] - raw_cmd->cmd[TRACK]) * heads + |
|---|
| 2346 | + reply_buffer[R_HEAD] - raw_cmd->cmd[HEAD]) * raw_cmd->cmd[SECT_PER_TRACK] + |
|---|
| 2347 | + reply_buffer[R_SECTOR] - raw_cmd->cmd[SECTOR] + eoc) << raw_cmd->cmd[SIZECODE] >> 2; |
|---|
| 2317 | 2348 | |
|---|
| 2318 | 2349 | if (nr_sectors / ssize > |
|---|
| 2319 | 2350 | DIV_ROUND_UP(in_sector_offset + current_count_sectors, ssize)) { |
|---|
| 2320 | 2351 | DPRINT("long rw: %x instead of %lx\n", |
|---|
| 2321 | 2352 | nr_sectors, current_count_sectors); |
|---|
| 2322 | | - pr_info("rs=%d s=%d\n", R_SECTOR, SECTOR); |
|---|
| 2323 | | - pr_info("rh=%d h=%d\n", R_HEAD, HEAD); |
|---|
| 2324 | | - pr_info("rt=%d t=%d\n", R_TRACK, TRACK); |
|---|
| 2353 | + pr_info("rs=%d s=%d\n", reply_buffer[R_SECTOR], |
|---|
| 2354 | + raw_cmd->cmd[SECTOR]); |
|---|
| 2355 | + pr_info("rh=%d h=%d\n", reply_buffer[R_HEAD], |
|---|
| 2356 | + raw_cmd->cmd[HEAD]); |
|---|
| 2357 | + pr_info("rt=%d t=%d\n", reply_buffer[R_TRACK], |
|---|
| 2358 | + raw_cmd->cmd[TRACK]); |
|---|
| 2325 | 2359 | pr_info("heads=%d eoc=%d\n", heads, eoc); |
|---|
| 2326 | 2360 | pr_info("spt=%d st=%d ss=%d\n", |
|---|
| 2327 | | - SECT_PER_TRACK, fsector_t, ssize); |
|---|
| 2361 | + raw_cmd->cmd[SECT_PER_TRACK], fsector_t, ssize); |
|---|
| 2328 | 2362 | pr_info("in_sector_offset=%d\n", in_sector_offset); |
|---|
| 2329 | 2363 | } |
|---|
| 2330 | 2364 | |
|---|
| .. | .. |
|---|
| 2354 | 2388 | } |
|---|
| 2355 | 2389 | |
|---|
| 2356 | 2390 | if (probing) { |
|---|
| 2357 | | - if (DP->flags & FTD_MSG) |
|---|
| 2391 | + if (drive_params[current_drive].flags & FTD_MSG) |
|---|
| 2358 | 2392 | DPRINT("Auto-detected floppy type %s in fd%d\n", |
|---|
| 2359 | 2393 | _floppy->name, current_drive); |
|---|
| 2360 | 2394 | current_type[current_drive] = _floppy; |
|---|
| .. | .. |
|---|
| 2362 | 2396 | probing = 0; |
|---|
| 2363 | 2397 | } |
|---|
| 2364 | 2398 | |
|---|
| 2365 | | - if (CT(COMMAND) != FD_READ || |
|---|
| 2399 | + if (CT(raw_cmd->cmd[COMMAND]) != FD_READ || |
|---|
| 2366 | 2400 | raw_cmd->kernel_data == bio_data(current_req->bio)) { |
|---|
| 2367 | 2401 | /* transfer directly from buffer */ |
|---|
| 2368 | 2402 | cont->done(1); |
|---|
| 2369 | | - } else if (CT(COMMAND) == FD_READ) { |
|---|
| 2403 | + } else if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) { |
|---|
| 2370 | 2404 | buffer_track = raw_cmd->track; |
|---|
| 2371 | 2405 | buffer_drive = current_drive; |
|---|
| 2372 | 2406 | INFBOUND(buffer_max, nr_sectors + fsector_t); |
|---|
| .. | .. |
|---|
| 2425 | 2459 | min(max_sector, max_sector_2), |
|---|
| 2426 | 2460 | blk_rq_sectors(current_req)); |
|---|
| 2427 | 2461 | |
|---|
| 2428 | | - if (current_count_sectors <= 0 && CT(COMMAND) == FD_WRITE && |
|---|
| 2462 | + if (current_count_sectors <= 0 && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE && |
|---|
| 2429 | 2463 | buffer_max > fsector_t + blk_rq_sectors(current_req)) |
|---|
| 2430 | 2464 | current_count_sectors = min_t(int, buffer_max - fsector_t, |
|---|
| 2431 | 2465 | blk_rq_sectors(current_req)); |
|---|
| 2432 | 2466 | |
|---|
| 2433 | 2467 | remaining = current_count_sectors << 9; |
|---|
| 2434 | | - if (remaining > blk_rq_bytes(current_req) && CT(COMMAND) == FD_WRITE) { |
|---|
| 2468 | + if (remaining > blk_rq_bytes(current_req) && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) { |
|---|
| 2435 | 2469 | DPRINT("in copy buffer\n"); |
|---|
| 2436 | 2470 | pr_info("current_count_sectors=%ld\n", current_count_sectors); |
|---|
| 2437 | 2471 | pr_info("remaining=%d\n", remaining >> 9); |
|---|
| .. | .. |
|---|
| 2466 | 2500 | fsector_t, buffer_min); |
|---|
| 2467 | 2501 | pr_info("current_count_sectors=%ld\n", |
|---|
| 2468 | 2502 | current_count_sectors); |
|---|
| 2469 | | - if (CT(COMMAND) == FD_READ) |
|---|
| 2503 | + if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) |
|---|
| 2470 | 2504 | pr_info("read\n"); |
|---|
| 2471 | | - if (CT(COMMAND) == FD_WRITE) |
|---|
| 2505 | + if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) |
|---|
| 2472 | 2506 | pr_info("write\n"); |
|---|
| 2473 | 2507 | break; |
|---|
| 2474 | 2508 | } |
|---|
| 2475 | 2509 | if (((unsigned long)buffer) % 512) |
|---|
| 2476 | 2510 | DPRINT("%p buffer not aligned\n", buffer); |
|---|
| 2477 | 2511 | |
|---|
| 2478 | | - if (CT(COMMAND) == FD_READ) |
|---|
| 2512 | + if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) |
|---|
| 2479 | 2513 | memcpy(buffer, dma_buffer, size); |
|---|
| 2480 | 2514 | else |
|---|
| 2481 | 2515 | memcpy(dma_buffer, buffer, size); |
|---|
| .. | .. |
|---|
| 2493 | 2527 | /* work around a bug in pseudo DMA |
|---|
| 2494 | 2528 | * (on some FDCs) pseudo DMA does not stop when the CPU stops |
|---|
| 2495 | 2529 | * sending data. Hence we need a different way to signal the |
|---|
| 2496 | | - * transfer length: We use SECT_PER_TRACK. Unfortunately, this |
|---|
| 2530 | + * transfer length: We use raw_cmd->cmd[SECT_PER_TRACK]. Unfortunately, this |
|---|
| 2497 | 2531 | * does not work with MT, hence we can only transfer one head at |
|---|
| 2498 | 2532 | * a time |
|---|
| 2499 | 2533 | */ |
|---|
| .. | .. |
|---|
| 2502 | 2536 | int hard_sectors; |
|---|
| 2503 | 2537 | int end_sector; |
|---|
| 2504 | 2538 | |
|---|
| 2505 | | - if (CT(COMMAND) == FD_WRITE) { |
|---|
| 2506 | | - COMMAND &= ~0x80; /* switch off multiple track mode */ |
|---|
| 2539 | + if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) { |
|---|
| 2540 | + raw_cmd->cmd[COMMAND] &= ~0x80; /* switch off multiple track mode */ |
|---|
| 2507 | 2541 | |
|---|
| 2508 | | - hard_sectors = raw_cmd->length >> (7 + SIZECODE); |
|---|
| 2509 | | - end_sector = SECTOR + hard_sectors - 1; |
|---|
| 2510 | | - if (end_sector > SECT_PER_TRACK) { |
|---|
| 2542 | + hard_sectors = raw_cmd->length >> (7 + raw_cmd->cmd[SIZECODE]); |
|---|
| 2543 | + end_sector = raw_cmd->cmd[SECTOR] + hard_sectors - 1; |
|---|
| 2544 | + if (end_sector > raw_cmd->cmd[SECT_PER_TRACK]) { |
|---|
| 2511 | 2545 | pr_info("too many sectors %d > %d\n", |
|---|
| 2512 | | - end_sector, SECT_PER_TRACK); |
|---|
| 2546 | + end_sector, raw_cmd->cmd[SECT_PER_TRACK]); |
|---|
| 2513 | 2547 | return; |
|---|
| 2514 | 2548 | } |
|---|
| 2515 | | - SECT_PER_TRACK = end_sector; |
|---|
| 2516 | | - /* make sure SECT_PER_TRACK |
|---|
| 2549 | + raw_cmd->cmd[SECT_PER_TRACK] = end_sector; |
|---|
| 2550 | + /* make sure raw_cmd->cmd[SECT_PER_TRACK] |
|---|
| 2517 | 2551 | * points to end of transfer */ |
|---|
| 2518 | 2552 | } |
|---|
| 2519 | 2553 | } |
|---|
| .. | .. |
|---|
| 2546 | 2580 | raw_cmd->cmd_count = NR_RW; |
|---|
| 2547 | 2581 | if (rq_data_dir(current_req) == READ) { |
|---|
| 2548 | 2582 | raw_cmd->flags |= FD_RAW_READ; |
|---|
| 2549 | | - COMMAND = FM_MODE(_floppy, FD_READ); |
|---|
| 2583 | + raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_READ); |
|---|
| 2550 | 2584 | } else if (rq_data_dir(current_req) == WRITE) { |
|---|
| 2551 | 2585 | raw_cmd->flags |= FD_RAW_WRITE; |
|---|
| 2552 | | - COMMAND = FM_MODE(_floppy, FD_WRITE); |
|---|
| 2586 | + raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_WRITE); |
|---|
| 2553 | 2587 | } else { |
|---|
| 2554 | 2588 | DPRINT("%s: unknown command\n", __func__); |
|---|
| 2555 | 2589 | return 0; |
|---|
| .. | .. |
|---|
| 2557 | 2591 | |
|---|
| 2558 | 2592 | max_sector = _floppy->sect * _floppy->head; |
|---|
| 2559 | 2593 | |
|---|
| 2560 | | - TRACK = (int)blk_rq_pos(current_req) / max_sector; |
|---|
| 2594 | + raw_cmd->cmd[TRACK] = (int)blk_rq_pos(current_req) / max_sector; |
|---|
| 2561 | 2595 | fsector_t = (int)blk_rq_pos(current_req) % max_sector; |
|---|
| 2562 | | - if (_floppy->track && TRACK >= _floppy->track) { |
|---|
| 2596 | + if (_floppy->track && raw_cmd->cmd[TRACK] >= _floppy->track) { |
|---|
| 2563 | 2597 | if (blk_rq_cur_sectors(current_req) & 1) { |
|---|
| 2564 | 2598 | current_count_sectors = 1; |
|---|
| 2565 | 2599 | return 1; |
|---|
| 2566 | 2600 | } else |
|---|
| 2567 | 2601 | return 0; |
|---|
| 2568 | 2602 | } |
|---|
| 2569 | | - HEAD = fsector_t / _floppy->sect; |
|---|
| 2603 | + raw_cmd->cmd[HEAD] = fsector_t / _floppy->sect; |
|---|
| 2570 | 2604 | |
|---|
| 2571 | 2605 | if (((_floppy->stretch & (FD_SWAPSIDES | FD_SECTBASEMASK)) || |
|---|
| 2572 | | - test_bit(FD_NEED_TWADDLE_BIT, &DRS->flags)) && |
|---|
| 2606 | + test_bit(FD_NEED_TWADDLE_BIT, &drive_state[current_drive].flags)) && |
|---|
| 2573 | 2607 | fsector_t < _floppy->sect) |
|---|
| 2574 | 2608 | max_sector = _floppy->sect; |
|---|
| 2575 | 2609 | |
|---|
| 2576 | 2610 | /* 2M disks have phantom sectors on the first track */ |
|---|
| 2577 | | - if ((_floppy->rate & FD_2M) && (!TRACK) && (!HEAD)) { |
|---|
| 2611 | + if ((_floppy->rate & FD_2M) && (!raw_cmd->cmd[TRACK]) && (!raw_cmd->cmd[HEAD])) { |
|---|
| 2578 | 2612 | max_sector = 2 * _floppy->sect / 3; |
|---|
| 2579 | 2613 | if (fsector_t >= max_sector) { |
|---|
| 2580 | 2614 | current_count_sectors = |
|---|
| .. | .. |
|---|
| 2582 | 2616 | blk_rq_sectors(current_req)); |
|---|
| 2583 | 2617 | return 1; |
|---|
| 2584 | 2618 | } |
|---|
| 2585 | | - SIZECODE = 2; |
|---|
| 2619 | + raw_cmd->cmd[SIZECODE] = 2; |
|---|
| 2586 | 2620 | } else |
|---|
| 2587 | | - SIZECODE = FD_SIZECODE(_floppy); |
|---|
| 2621 | + raw_cmd->cmd[SIZECODE] = FD_SIZECODE(_floppy); |
|---|
| 2588 | 2622 | raw_cmd->rate = _floppy->rate & 0x43; |
|---|
| 2589 | | - if ((_floppy->rate & FD_2M) && (TRACK || HEAD) && raw_cmd->rate == 2) |
|---|
| 2623 | + if ((_floppy->rate & FD_2M) && |
|---|
| 2624 | + (raw_cmd->cmd[TRACK] || raw_cmd->cmd[HEAD]) && raw_cmd->rate == 2) |
|---|
| 2590 | 2625 | raw_cmd->rate = 1; |
|---|
| 2591 | 2626 | |
|---|
| 2592 | | - if (SIZECODE) |
|---|
| 2593 | | - SIZECODE2 = 0xff; |
|---|
| 2627 | + if (raw_cmd->cmd[SIZECODE]) |
|---|
| 2628 | + raw_cmd->cmd[SIZECODE2] = 0xff; |
|---|
| 2594 | 2629 | else |
|---|
| 2595 | | - SIZECODE2 = 0x80; |
|---|
| 2596 | | - raw_cmd->track = TRACK << STRETCH(_floppy); |
|---|
| 2597 | | - DR_SELECT = UNIT(current_drive) + PH_HEAD(_floppy, HEAD); |
|---|
| 2598 | | - GAP = _floppy->gap; |
|---|
| 2599 | | - ssize = DIV_ROUND_UP(1 << SIZECODE, 4); |
|---|
| 2600 | | - SECT_PER_TRACK = _floppy->sect << 2 >> SIZECODE; |
|---|
| 2601 | | - SECTOR = ((fsector_t % _floppy->sect) << 2 >> SIZECODE) + |
|---|
| 2630 | + raw_cmd->cmd[SIZECODE2] = 0x80; |
|---|
| 2631 | + raw_cmd->track = raw_cmd->cmd[TRACK] << STRETCH(_floppy); |
|---|
| 2632 | + raw_cmd->cmd[DR_SELECT] = UNIT(current_drive) + PH_HEAD(_floppy, raw_cmd->cmd[HEAD]); |
|---|
| 2633 | + raw_cmd->cmd[GAP] = _floppy->gap; |
|---|
| 2634 | + ssize = DIV_ROUND_UP(1 << raw_cmd->cmd[SIZECODE], 4); |
|---|
| 2635 | + raw_cmd->cmd[SECT_PER_TRACK] = _floppy->sect << 2 >> raw_cmd->cmd[SIZECODE]; |
|---|
| 2636 | + raw_cmd->cmd[SECTOR] = ((fsector_t % _floppy->sect) << 2 >> raw_cmd->cmd[SIZECODE]) + |
|---|
| 2602 | 2637 | FD_SECTBASE(_floppy); |
|---|
| 2603 | 2638 | |
|---|
| 2604 | 2639 | /* tracksize describes the size which can be filled up with sectors |
|---|
| .. | .. |
|---|
| 2606 | 2641 | */ |
|---|
| 2607 | 2642 | tracksize = _floppy->sect - _floppy->sect % ssize; |
|---|
| 2608 | 2643 | if (tracksize < _floppy->sect) { |
|---|
| 2609 | | - SECT_PER_TRACK++; |
|---|
| 2644 | + raw_cmd->cmd[SECT_PER_TRACK]++; |
|---|
| 2610 | 2645 | if (tracksize <= fsector_t % _floppy->sect) |
|---|
| 2611 | | - SECTOR--; |
|---|
| 2646 | + raw_cmd->cmd[SECTOR]--; |
|---|
| 2612 | 2647 | |
|---|
| 2613 | 2648 | /* if we are beyond tracksize, fill up using smaller sectors */ |
|---|
| 2614 | 2649 | while (tracksize <= fsector_t % _floppy->sect) { |
|---|
| 2615 | 2650 | while (tracksize + ssize > _floppy->sect) { |
|---|
| 2616 | | - SIZECODE--; |
|---|
| 2651 | + raw_cmd->cmd[SIZECODE]--; |
|---|
| 2617 | 2652 | ssize >>= 1; |
|---|
| 2618 | 2653 | } |
|---|
| 2619 | | - SECTOR++; |
|---|
| 2620 | | - SECT_PER_TRACK++; |
|---|
| 2654 | + raw_cmd->cmd[SECTOR]++; |
|---|
| 2655 | + raw_cmd->cmd[SECT_PER_TRACK]++; |
|---|
| 2621 | 2656 | tracksize += ssize; |
|---|
| 2622 | 2657 | } |
|---|
| 2623 | | - max_sector = HEAD * _floppy->sect + tracksize; |
|---|
| 2624 | | - } else if (!TRACK && !HEAD && !(_floppy->rate & FD_2M) && probing) { |
|---|
| 2658 | + max_sector = raw_cmd->cmd[HEAD] * _floppy->sect + tracksize; |
|---|
| 2659 | + } else if (!raw_cmd->cmd[TRACK] && !raw_cmd->cmd[HEAD] && !(_floppy->rate & FD_2M) && probing) { |
|---|
| 2625 | 2660 | max_sector = _floppy->sect; |
|---|
| 2626 | | - } else if (!HEAD && CT(COMMAND) == FD_WRITE) { |
|---|
| 2661 | + } else if (!raw_cmd->cmd[HEAD] && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) { |
|---|
| 2627 | 2662 | /* for virtual DMA bug workaround */ |
|---|
| 2628 | 2663 | max_sector = _floppy->sect; |
|---|
| 2629 | 2664 | } |
|---|
| .. | .. |
|---|
| 2635 | 2670 | (current_drive == buffer_drive) && |
|---|
| 2636 | 2671 | (fsector_t >= buffer_min) && (fsector_t < buffer_max)) { |
|---|
| 2637 | 2672 | /* data already in track buffer */ |
|---|
| 2638 | | - if (CT(COMMAND) == FD_READ) { |
|---|
| 2673 | + if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) { |
|---|
| 2639 | 2674 | copy_buffer(1, max_sector, buffer_max); |
|---|
| 2640 | 2675 | return 1; |
|---|
| 2641 | 2676 | } |
|---|
| 2642 | 2677 | } else if (in_sector_offset || blk_rq_sectors(current_req) < ssize) { |
|---|
| 2643 | | - if (CT(COMMAND) == FD_WRITE) { |
|---|
| 2678 | + if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) { |
|---|
| 2644 | 2679 | unsigned int sectors; |
|---|
| 2645 | 2680 | |
|---|
| 2646 | 2681 | sectors = fsector_t + blk_rq_sectors(current_req); |
|---|
| .. | .. |
|---|
| 2651 | 2686 | } |
|---|
| 2652 | 2687 | raw_cmd->flags &= ~FD_RAW_WRITE; |
|---|
| 2653 | 2688 | raw_cmd->flags |= FD_RAW_READ; |
|---|
| 2654 | | - COMMAND = FM_MODE(_floppy, FD_READ); |
|---|
| 2689 | + raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_READ); |
|---|
| 2655 | 2690 | } else if ((unsigned long)bio_data(current_req->bio) < MAX_DMA_ADDRESS) { |
|---|
| 2656 | 2691 | unsigned long dma_limit; |
|---|
| 2657 | 2692 | int direct, indirect; |
|---|
| .. | .. |
|---|
| 2684 | 2719 | */ |
|---|
| 2685 | 2720 | if (!direct || |
|---|
| 2686 | 2721 | (indirect * 2 > direct * 3 && |
|---|
| 2687 | | - *errors < DP->max_errors.read_track && |
|---|
| 2722 | + floppy_errors < drive_params[current_drive].max_errors.read_track && |
|---|
| 2688 | 2723 | ((!probing || |
|---|
| 2689 | | - (DP->read_track & (1 << DRS->probed_format)))))) { |
|---|
| 2724 | + (drive_params[current_drive].read_track & (1 << drive_state[current_drive].probed_format)))))) { |
|---|
| 2690 | 2725 | max_size = blk_rq_sectors(current_req); |
|---|
| 2691 | 2726 | } else { |
|---|
| 2692 | 2727 | raw_cmd->kernel_data = bio_data(current_req->bio); |
|---|
| .. | .. |
|---|
| 2702 | 2737 | } |
|---|
| 2703 | 2738 | } |
|---|
| 2704 | 2739 | |
|---|
| 2705 | | - if (CT(COMMAND) == FD_READ) |
|---|
| 2740 | + if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) |
|---|
| 2706 | 2741 | max_size = max_sector; /* unbounded */ |
|---|
| 2707 | 2742 | |
|---|
| 2708 | 2743 | /* claim buffer track if needed */ |
|---|
| .. | .. |
|---|
| 2710 | 2745 | buffer_drive != current_drive || /* bad drive */ |
|---|
| 2711 | 2746 | fsector_t > buffer_max || |
|---|
| 2712 | 2747 | fsector_t < buffer_min || |
|---|
| 2713 | | - ((CT(COMMAND) == FD_READ || |
|---|
| 2748 | + ((CT(raw_cmd->cmd[COMMAND]) == FD_READ || |
|---|
| 2714 | 2749 | (!in_sector_offset && blk_rq_sectors(current_req) >= ssize)) && |
|---|
| 2715 | 2750 | max_sector > 2 * max_buffer_sectors + buffer_min && |
|---|
| 2716 | 2751 | max_size + fsector_t > 2 * max_buffer_sectors + buffer_min)) { |
|---|
| .. | .. |
|---|
| 2722 | 2757 | raw_cmd->kernel_data = floppy_track_buffer + |
|---|
| 2723 | 2758 | ((aligned_sector_t - buffer_min) << 9); |
|---|
| 2724 | 2759 | |
|---|
| 2725 | | - if (CT(COMMAND) == FD_WRITE) { |
|---|
| 2760 | + if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) { |
|---|
| 2726 | 2761 | /* copy write buffer to track buffer. |
|---|
| 2727 | 2762 | * if we get here, we know that the write |
|---|
| 2728 | 2763 | * is either aligned or the data already in the buffer |
|---|
| .. | .. |
|---|
| 2744 | 2779 | raw_cmd->length <<= 9; |
|---|
| 2745 | 2780 | if ((raw_cmd->length < current_count_sectors << 9) || |
|---|
| 2746 | 2781 | (raw_cmd->kernel_data != bio_data(current_req->bio) && |
|---|
| 2747 | | - CT(COMMAND) == FD_WRITE && |
|---|
| 2782 | + CT(raw_cmd->cmd[COMMAND]) == FD_WRITE && |
|---|
| 2748 | 2783 | (aligned_sector_t + (raw_cmd->length >> 9) > buffer_max || |
|---|
| 2749 | 2784 | aligned_sector_t < buffer_min)) || |
|---|
| 2750 | | - raw_cmd->length % (128 << SIZECODE) || |
|---|
| 2785 | + raw_cmd->length % (128 << raw_cmd->cmd[SIZECODE]) || |
|---|
| 2751 | 2786 | raw_cmd->length <= 0 || current_count_sectors <= 0) { |
|---|
| 2752 | 2787 | DPRINT("fractionary current count b=%lx s=%lx\n", |
|---|
| 2753 | 2788 | raw_cmd->length, current_count_sectors); |
|---|
| .. | .. |
|---|
| 2758 | 2793 | current_count_sectors); |
|---|
| 2759 | 2794 | pr_info("st=%d ast=%d mse=%d msi=%d\n", |
|---|
| 2760 | 2795 | fsector_t, aligned_sector_t, max_sector, max_size); |
|---|
| 2761 | | - pr_info("ssize=%x SIZECODE=%d\n", ssize, SIZECODE); |
|---|
| 2796 | + pr_info("ssize=%x SIZECODE=%d\n", ssize, raw_cmd->cmd[SIZECODE]); |
|---|
| 2762 | 2797 | pr_info("command=%x SECTOR=%d HEAD=%d, TRACK=%d\n", |
|---|
| 2763 | | - COMMAND, SECTOR, HEAD, TRACK); |
|---|
| 2798 | + raw_cmd->cmd[COMMAND], raw_cmd->cmd[SECTOR], |
|---|
| 2799 | + raw_cmd->cmd[HEAD], raw_cmd->cmd[TRACK]); |
|---|
| 2764 | 2800 | pr_info("buffer drive=%d\n", buffer_drive); |
|---|
| 2765 | 2801 | pr_info("buffer track=%d\n", buffer_track); |
|---|
| 2766 | 2802 | pr_info("buffer_min=%d\n", buffer_min); |
|---|
| .. | .. |
|---|
| 2779 | 2815 | fsector_t, buffer_min, raw_cmd->length >> 9); |
|---|
| 2780 | 2816 | pr_info("current_count_sectors=%ld\n", |
|---|
| 2781 | 2817 | current_count_sectors); |
|---|
| 2782 | | - if (CT(COMMAND) == FD_READ) |
|---|
| 2818 | + if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) |
|---|
| 2783 | 2819 | pr_info("read\n"); |
|---|
| 2784 | | - if (CT(COMMAND) == FD_WRITE) |
|---|
| 2820 | + if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) |
|---|
| 2785 | 2821 | pr_info("write\n"); |
|---|
| 2786 | 2822 | return 0; |
|---|
| 2787 | 2823 | } |
|---|
| .. | .. |
|---|
| 2803 | 2839 | return 2; |
|---|
| 2804 | 2840 | } |
|---|
| 2805 | 2841 | |
|---|
| 2806 | | -/* |
|---|
| 2807 | | - * Round-robin between our available drives, doing one request from each |
|---|
| 2808 | | - */ |
|---|
| 2809 | 2842 | static int set_next_request(void) |
|---|
| 2810 | 2843 | { |
|---|
| 2811 | | - struct request_queue *q; |
|---|
| 2812 | | - int old_pos = fdc_queue; |
|---|
| 2813 | | - |
|---|
| 2814 | | - do { |
|---|
| 2815 | | - q = disks[fdc_queue]->queue; |
|---|
| 2816 | | - if (++fdc_queue == N_DRIVE) |
|---|
| 2817 | | - fdc_queue = 0; |
|---|
| 2818 | | - if (q) { |
|---|
| 2819 | | - current_req = blk_fetch_request(q); |
|---|
| 2820 | | - if (current_req) { |
|---|
| 2821 | | - current_req->error_count = 0; |
|---|
| 2822 | | - break; |
|---|
| 2823 | | - } |
|---|
| 2824 | | - } |
|---|
| 2825 | | - } while (fdc_queue != old_pos); |
|---|
| 2826 | | - |
|---|
| 2827 | | - return current_req != NULL; |
|---|
| 2844 | + current_req = list_first_entry_or_null(&floppy_reqs, struct request, |
|---|
| 2845 | + queuelist); |
|---|
| 2846 | + if (current_req) { |
|---|
| 2847 | + floppy_errors = 0; |
|---|
| 2848 | + list_del_init(¤t_req->queuelist); |
|---|
| 2849 | + return 1; |
|---|
| 2850 | + } |
|---|
| 2851 | + return 0; |
|---|
| 2828 | 2852 | } |
|---|
| 2829 | 2853 | |
|---|
| 2854 | +/* Starts or continues processing request. Will automatically unlock the |
|---|
| 2855 | + * driver at end of request. |
|---|
| 2856 | + */ |
|---|
| 2830 | 2857 | static void redo_fd_request(void) |
|---|
| 2831 | 2858 | { |
|---|
| 2832 | 2859 | int drive; |
|---|
| .. | .. |
|---|
| 2851 | 2878 | } |
|---|
| 2852 | 2879 | drive = (long)current_req->rq_disk->private_data; |
|---|
| 2853 | 2880 | set_fdc(drive); |
|---|
| 2854 | | - reschedule_timeout(current_reqD, "redo fd request"); |
|---|
| 2881 | + reschedule_timeout(current_drive, "redo fd request"); |
|---|
| 2855 | 2882 | |
|---|
| 2856 | 2883 | set_floppy(drive); |
|---|
| 2857 | 2884 | raw_cmd = &default_raw_cmd; |
|---|
| .. | .. |
|---|
| 2861 | 2888 | |
|---|
| 2862 | 2889 | disk_change(current_drive); |
|---|
| 2863 | 2890 | if (test_bit(current_drive, &fake_change) || |
|---|
| 2864 | | - test_bit(FD_DISK_CHANGED_BIT, &DRS->flags)) { |
|---|
| 2891 | + test_bit(FD_DISK_CHANGED_BIT, &drive_state[current_drive].flags)) { |
|---|
| 2865 | 2892 | DPRINT("disk absent or changed during operation\n"); |
|---|
| 2866 | 2893 | request_done(0); |
|---|
| 2867 | 2894 | goto do_request; |
|---|
| 2868 | 2895 | } |
|---|
| 2869 | 2896 | if (!_floppy) { /* Autodetection */ |
|---|
| 2870 | 2897 | if (!probing) { |
|---|
| 2871 | | - DRS->probed_format = 0; |
|---|
| 2872 | | - if (next_valid_format()) { |
|---|
| 2898 | + drive_state[current_drive].probed_format = 0; |
|---|
| 2899 | + if (next_valid_format(current_drive)) { |
|---|
| 2873 | 2900 | DPRINT("no autodetectable formats\n"); |
|---|
| 2874 | 2901 | _floppy = NULL; |
|---|
| 2875 | 2902 | request_done(0); |
|---|
| .. | .. |
|---|
| 2877 | 2904 | } |
|---|
| 2878 | 2905 | } |
|---|
| 2879 | 2906 | probing = 1; |
|---|
| 2880 | | - _floppy = floppy_type + DP->autodetect[DRS->probed_format]; |
|---|
| 2907 | + _floppy = floppy_type + drive_params[current_drive].autodetect[drive_state[current_drive].probed_format]; |
|---|
| 2881 | 2908 | } else |
|---|
| 2882 | 2909 | probing = 0; |
|---|
| 2883 | | - errors = &(current_req->error_count); |
|---|
| 2884 | 2910 | tmp = make_raw_rw_request(); |
|---|
| 2885 | 2911 | if (tmp < 2) { |
|---|
| 2886 | 2912 | request_done(tmp); |
|---|
| 2887 | 2913 | goto do_request; |
|---|
| 2888 | 2914 | } |
|---|
| 2889 | 2915 | |
|---|
| 2890 | | - if (test_bit(FD_NEED_TWADDLE_BIT, &DRS->flags)) |
|---|
| 2891 | | - twaddle(); |
|---|
| 2916 | + if (test_bit(FD_NEED_TWADDLE_BIT, &drive_state[current_drive].flags)) |
|---|
| 2917 | + twaddle(current_fdc, current_drive); |
|---|
| 2892 | 2918 | schedule_bh(floppy_start); |
|---|
| 2893 | 2919 | debugt(__func__, "queue fd request"); |
|---|
| 2894 | 2920 | return; |
|---|
| .. | .. |
|---|
| 2901 | 2927 | .done = request_done |
|---|
| 2902 | 2928 | }; |
|---|
| 2903 | 2929 | |
|---|
| 2930 | +/* schedule the request and automatically unlock the driver on completion */ |
|---|
| 2904 | 2931 | static void process_fd_request(void) |
|---|
| 2905 | 2932 | { |
|---|
| 2906 | 2933 | cont = &rw_cont; |
|---|
| 2907 | 2934 | schedule_bh(redo_fd_request); |
|---|
| 2908 | 2935 | } |
|---|
| 2909 | 2936 | |
|---|
| 2910 | | -static void do_fd_request(struct request_queue *q) |
|---|
| 2937 | +static blk_status_t floppy_queue_rq(struct blk_mq_hw_ctx *hctx, |
|---|
| 2938 | + const struct blk_mq_queue_data *bd) |
|---|
| 2911 | 2939 | { |
|---|
| 2940 | + blk_mq_start_request(bd->rq); |
|---|
| 2941 | + |
|---|
| 2912 | 2942 | if (WARN(max_buffer_sectors == 0, |
|---|
| 2913 | 2943 | "VFS: %s called on non-open device\n", __func__)) |
|---|
| 2914 | | - return; |
|---|
| 2944 | + return BLK_STS_IOERR; |
|---|
| 2915 | 2945 | |
|---|
| 2916 | 2946 | if (WARN(atomic_read(&usage_count) == 0, |
|---|
| 2917 | 2947 | "warning: usage count=0, current_req=%p sect=%ld flags=%llx\n", |
|---|
| 2918 | 2948 | current_req, (long)blk_rq_pos(current_req), |
|---|
| 2919 | 2949 | (unsigned long long) current_req->cmd_flags)) |
|---|
| 2920 | | - return; |
|---|
| 2950 | + return BLK_STS_IOERR; |
|---|
| 2921 | 2951 | |
|---|
| 2922 | 2952 | if (test_and_set_bit(0, &fdc_busy)) { |
|---|
| 2923 | 2953 | /* fdc busy, this new request will be treated when the |
|---|
| 2924 | 2954 | current one is done */ |
|---|
| 2925 | 2955 | is_alive(__func__, "old request running"); |
|---|
| 2926 | | - return; |
|---|
| 2956 | + return BLK_STS_RESOURCE; |
|---|
| 2927 | 2957 | } |
|---|
| 2958 | + |
|---|
| 2959 | + spin_lock_irq(&floppy_lock); |
|---|
| 2960 | + list_add_tail(&bd->rq->queuelist, &floppy_reqs); |
|---|
| 2961 | + spin_unlock_irq(&floppy_lock); |
|---|
| 2962 | + |
|---|
| 2928 | 2963 | command_status = FD_COMMAND_NONE; |
|---|
| 2929 | 2964 | __reschedule_timeout(MAXTIMEOUT, "fd_request"); |
|---|
| 2930 | 2965 | set_fdc(0); |
|---|
| 2931 | 2966 | process_fd_request(); |
|---|
| 2932 | 2967 | is_alive(__func__, ""); |
|---|
| 2968 | + return BLK_STS_OK; |
|---|
| 2933 | 2969 | } |
|---|
| 2934 | 2970 | |
|---|
| 2935 | 2971 | static const struct cont_t poll_cont = { |
|---|
| .. | .. |
|---|
| 2947 | 2983 | raw_cmd->track = 0; |
|---|
| 2948 | 2984 | raw_cmd->cmd_count = 0; |
|---|
| 2949 | 2985 | cont = &poll_cont; |
|---|
| 2950 | | - debug_dcl(DP->flags, "setting NEWCHANGE in poll_drive\n"); |
|---|
| 2951 | | - set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags); |
|---|
| 2986 | + debug_dcl(drive_params[current_drive].flags, |
|---|
| 2987 | + "setting NEWCHANGE in poll_drive\n"); |
|---|
| 2988 | + set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags); |
|---|
| 2952 | 2989 | |
|---|
| 2953 | 2990 | return wait_til_done(floppy_ready, interruptible); |
|---|
| 2954 | 2991 | } |
|---|
| .. | .. |
|---|
| 2970 | 3007 | .done = generic_done |
|---|
| 2971 | 3008 | }; |
|---|
| 2972 | 3009 | |
|---|
| 3010 | +/* |
|---|
| 3011 | + * Resets the FDC connected to drive <drive>. |
|---|
| 3012 | + * Both current_drive and current_fdc are changed to match the new drive. |
|---|
| 3013 | + */ |
|---|
| 2973 | 3014 | static int user_reset_fdc(int drive, int arg, bool interruptible) |
|---|
| 2974 | 3015 | { |
|---|
| 2975 | 3016 | int ret; |
|---|
| .. | .. |
|---|
| 2978 | 3019 | return -EINTR; |
|---|
| 2979 | 3020 | |
|---|
| 2980 | 3021 | if (arg == FD_RESET_ALWAYS) |
|---|
| 2981 | | - FDCS->reset = 1; |
|---|
| 2982 | | - if (FDCS->reset) { |
|---|
| 3022 | + fdc_state[current_fdc].reset = 1; |
|---|
| 3023 | + if (fdc_state[current_fdc].reset) { |
|---|
| 3024 | + /* note: reset_fdc will take care of unlocking the driver |
|---|
| 3025 | + * on completion. |
|---|
| 3026 | + */ |
|---|
| 2983 | 3027 | cont = &reset_cont; |
|---|
| 2984 | 3028 | ret = wait_til_done(reset_fdc, interruptible); |
|---|
| 2985 | 3029 | if (ret == -EINTR) |
|---|
| .. | .. |
|---|
| 3012 | 3056 | if (type) |
|---|
| 3013 | 3057 | floppy = floppy_type + type; |
|---|
| 3014 | 3058 | else { |
|---|
| 3015 | | - if (UDP->native_format) |
|---|
| 3016 | | - floppy = floppy_type + UDP->native_format; |
|---|
| 3059 | + if (drive_params[drive].native_format) |
|---|
| 3060 | + floppy = floppy_type + drive_params[drive].native_format; |
|---|
| 3017 | 3061 | else |
|---|
| 3018 | 3062 | return "(null)"; |
|---|
| 3019 | 3063 | } |
|---|
| .. | .. |
|---|
| 3022 | 3066 | else |
|---|
| 3023 | 3067 | return "(null)"; |
|---|
| 3024 | 3068 | } |
|---|
| 3069 | + |
|---|
| 3070 | +#ifdef CONFIG_BLK_DEV_FD_RAWCMD |
|---|
| 3025 | 3071 | |
|---|
| 3026 | 3072 | /* raw commands */ |
|---|
| 3027 | 3073 | static void raw_cmd_done(int flag) |
|---|
| .. | .. |
|---|
| 3033 | 3079 | raw_cmd->flags |= FD_RAW_HARDFAILURE; |
|---|
| 3034 | 3080 | } else { |
|---|
| 3035 | 3081 | raw_cmd->reply_count = inr; |
|---|
| 3036 | | - if (raw_cmd->reply_count > MAX_REPLIES) |
|---|
| 3082 | + if (raw_cmd->reply_count > FD_RAW_REPLY_SIZE) |
|---|
| 3037 | 3083 | raw_cmd->reply_count = 0; |
|---|
| 3038 | 3084 | for (i = 0; i < raw_cmd->reply_count; i++) |
|---|
| 3039 | 3085 | raw_cmd->reply[i] = reply_buffer[i]; |
|---|
| .. | .. |
|---|
| 3146 | 3192 | if (ret) |
|---|
| 3147 | 3193 | return -EFAULT; |
|---|
| 3148 | 3194 | param += sizeof(struct floppy_raw_cmd); |
|---|
| 3149 | | - if (ptr->cmd_count > 33) |
|---|
| 3150 | | - /* the command may now also take up the space |
|---|
| 3151 | | - * initially intended for the reply & the |
|---|
| 3152 | | - * reply count. Needed for long 82078 commands |
|---|
| 3153 | | - * such as RESTORE, which takes ... 17 command |
|---|
| 3154 | | - * bytes. Murphy's law #137: When you reserve |
|---|
| 3155 | | - * 16 bytes for a structure, you'll one day |
|---|
| 3156 | | - * discover that you really need 17... |
|---|
| 3157 | | - */ |
|---|
| 3195 | + if (ptr->cmd_count > FD_RAW_CMD_FULLSIZE) |
|---|
| 3158 | 3196 | return -EINVAL; |
|---|
| 3159 | 3197 | |
|---|
| 3160 | | - for (i = 0; i < 16; i++) |
|---|
| 3198 | + for (i = 0; i < FD_RAW_REPLY_SIZE; i++) |
|---|
| 3161 | 3199 | ptr->reply[i] = 0; |
|---|
| 3162 | 3200 | ptr->resultcode = 0; |
|---|
| 3163 | 3201 | |
|---|
| .. | .. |
|---|
| 3192 | 3230 | int ret2; |
|---|
| 3193 | 3231 | int ret; |
|---|
| 3194 | 3232 | |
|---|
| 3195 | | - if (FDCS->rawcmd <= 1) |
|---|
| 3196 | | - FDCS->rawcmd = 1; |
|---|
| 3233 | + if (fdc_state[current_fdc].rawcmd <= 1) |
|---|
| 3234 | + fdc_state[current_fdc].rawcmd = 1; |
|---|
| 3197 | 3235 | for (drive = 0; drive < N_DRIVE; drive++) { |
|---|
| 3198 | | - if (FDC(drive) != fdc) |
|---|
| 3236 | + if (FDC(drive) != current_fdc) |
|---|
| 3199 | 3237 | continue; |
|---|
| 3200 | 3238 | if (drive == current_drive) { |
|---|
| 3201 | | - if (UDRS->fd_ref > 1) { |
|---|
| 3202 | | - FDCS->rawcmd = 2; |
|---|
| 3239 | + if (drive_state[drive].fd_ref > 1) { |
|---|
| 3240 | + fdc_state[current_fdc].rawcmd = 2; |
|---|
| 3203 | 3241 | break; |
|---|
| 3204 | 3242 | } |
|---|
| 3205 | | - } else if (UDRS->fd_ref) { |
|---|
| 3206 | | - FDCS->rawcmd = 2; |
|---|
| 3243 | + } else if (drive_state[drive].fd_ref) { |
|---|
| 3244 | + fdc_state[current_fdc].rawcmd = 2; |
|---|
| 3207 | 3245 | break; |
|---|
| 3208 | 3246 | } |
|---|
| 3209 | 3247 | } |
|---|
| 3210 | 3248 | |
|---|
| 3211 | | - if (FDCS->reset) |
|---|
| 3249 | + if (fdc_state[current_fdc].reset) |
|---|
| 3212 | 3250 | return -EIO; |
|---|
| 3213 | 3251 | |
|---|
| 3214 | 3252 | ret = raw_cmd_copyin(cmd, param, &my_raw_cmd); |
|---|
| .. | .. |
|---|
| 3220 | 3258 | raw_cmd = my_raw_cmd; |
|---|
| 3221 | 3259 | cont = &raw_cmd_cont; |
|---|
| 3222 | 3260 | ret = wait_til_done(floppy_start, true); |
|---|
| 3223 | | - debug_dcl(DP->flags, "calling disk change from raw_cmd ioctl\n"); |
|---|
| 3261 | + debug_dcl(drive_params[current_drive].flags, |
|---|
| 3262 | + "calling disk change from raw_cmd ioctl\n"); |
|---|
| 3224 | 3263 | |
|---|
| 3225 | | - if (ret != -EINTR && FDCS->reset) |
|---|
| 3264 | + if (ret != -EINTR && fdc_state[current_fdc].reset) |
|---|
| 3226 | 3265 | ret = -EIO; |
|---|
| 3227 | 3266 | |
|---|
| 3228 | | - DRS->track = NO_TRACK; |
|---|
| 3267 | + drive_state[current_drive].track = NO_TRACK; |
|---|
| 3229 | 3268 | |
|---|
| 3230 | 3269 | ret2 = raw_cmd_copyout(cmd, param, my_raw_cmd); |
|---|
| 3231 | 3270 | if (!ret) |
|---|
| .. | .. |
|---|
| 3234 | 3273 | return ret; |
|---|
| 3235 | 3274 | } |
|---|
| 3236 | 3275 | |
|---|
| 3276 | +static int floppy_raw_cmd_ioctl(int type, int drive, int cmd, |
|---|
| 3277 | + void __user *param) |
|---|
| 3278 | +{ |
|---|
| 3279 | + int ret; |
|---|
| 3280 | + |
|---|
| 3281 | + pr_warn_once("Note: FDRAWCMD is deprecated and will be removed from the kernel in the near future.\n"); |
|---|
| 3282 | + |
|---|
| 3283 | + if (type) |
|---|
| 3284 | + return -EINVAL; |
|---|
| 3285 | + if (lock_fdc(drive)) |
|---|
| 3286 | + return -EINTR; |
|---|
| 3287 | + set_floppy(drive); |
|---|
| 3288 | + ret = raw_cmd_ioctl(cmd, param); |
|---|
| 3289 | + if (ret == -EINTR) |
|---|
| 3290 | + return -EINTR; |
|---|
| 3291 | + process_fd_request(); |
|---|
| 3292 | + return ret; |
|---|
| 3293 | +} |
|---|
| 3294 | + |
|---|
| 3295 | +#else /* CONFIG_BLK_DEV_FD_RAWCMD */ |
|---|
| 3296 | + |
|---|
| 3297 | +static int floppy_raw_cmd_ioctl(int type, int drive, int cmd, |
|---|
| 3298 | + void __user *param) |
|---|
| 3299 | +{ |
|---|
| 3300 | + return -EOPNOTSUPP; |
|---|
| 3301 | +} |
|---|
| 3302 | + |
|---|
| 3303 | +#endif |
|---|
| 3304 | + |
|---|
| 3237 | 3305 | static int invalidate_drive(struct block_device *bdev) |
|---|
| 3238 | 3306 | { |
|---|
| 3239 | 3307 | /* invalidate the buffer track to force a reread */ |
|---|
| 3240 | 3308 | set_bit((long)bdev->bd_disk->private_data, &fake_change); |
|---|
| 3241 | 3309 | process_fd_request(); |
|---|
| 3242 | | - check_disk_change(bdev); |
|---|
| 3310 | + if (bdev_check_media_change(bdev)) |
|---|
| 3311 | + floppy_revalidate(bdev->bd_disk); |
|---|
| 3243 | 3312 | return 0; |
|---|
| 3244 | 3313 | } |
|---|
| 3245 | 3314 | |
|---|
| .. | .. |
|---|
| 3253 | 3322 | (int)g->head <= 0 || |
|---|
| 3254 | 3323 | /* check for overflow in max_sector */ |
|---|
| 3255 | 3324 | (int)(g->sect * g->head) <= 0 || |
|---|
| 3256 | | - /* check for zero in F_SECT_PER_TRACK */ |
|---|
| 3325 | + /* check for zero in raw_cmd->cmd[F_SECT_PER_TRACK] */ |
|---|
| 3257 | 3326 | (unsigned char)((g->sect << 2) >> FD_SIZECODE(g)) == 0 || |
|---|
| 3258 | | - g->track <= 0 || g->track > UDP->tracks >> STRETCH(g) || |
|---|
| 3327 | + g->track <= 0 || g->track > drive_params[drive].tracks >> STRETCH(g) || |
|---|
| 3259 | 3328 | /* check if reserved bits are set */ |
|---|
| 3260 | 3329 | (g->stretch & ~(FD_STRETCH | FD_SWAPSIDES | FD_SECTBASEMASK)) != 0) |
|---|
| 3261 | 3330 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 3298 | 3367 | current_type[drive] = &user_params[drive]; |
|---|
| 3299 | 3368 | floppy_sizes[drive] = user_params[drive].size; |
|---|
| 3300 | 3369 | if (cmd == FDDEFPRM) |
|---|
| 3301 | | - DRS->keep_data = -1; |
|---|
| 3370 | + drive_state[current_drive].keep_data = -1; |
|---|
| 3302 | 3371 | else |
|---|
| 3303 | | - DRS->keep_data = 1; |
|---|
| 3372 | + drive_state[current_drive].keep_data = 1; |
|---|
| 3304 | 3373 | /* invalidation. Invalidate only when needed, i.e. |
|---|
| 3305 | 3374 | * when there are already sectors in the buffer cache |
|---|
| 3306 | 3375 | * whose number will change. This is useful, because |
|---|
| 3307 | 3376 | * mtools often changes the geometry of the disk after |
|---|
| 3308 | 3377 | * looking at the boot block */ |
|---|
| 3309 | | - if (DRS->maxblock > user_params[drive].sect || |
|---|
| 3310 | | - DRS->maxtrack || |
|---|
| 3378 | + if (drive_state[current_drive].maxblock > user_params[drive].sect || |
|---|
| 3379 | + drive_state[current_drive].maxtrack || |
|---|
| 3311 | 3380 | ((user_params[drive].sect ^ oldStretch) & |
|---|
| 3312 | 3381 | (FD_SWAPSIDES | FD_SECTBASEMASK))) |
|---|
| 3313 | 3382 | invalidate_drive(bdev); |
|---|
| .. | .. |
|---|
| 3398 | 3467 | return 0; |
|---|
| 3399 | 3468 | } |
|---|
| 3400 | 3469 | |
|---|
| 3401 | | -static bool valid_floppy_drive_params(const short autodetect[8], |
|---|
| 3470 | +static bool valid_floppy_drive_params(const short autodetect[FD_AUTODETECT_SIZE], |
|---|
| 3402 | 3471 | int native_format) |
|---|
| 3403 | 3472 | { |
|---|
| 3404 | 3473 | size_t floppy_type_size = ARRAY_SIZE(floppy_type); |
|---|
| 3405 | 3474 | size_t i = 0; |
|---|
| 3406 | 3475 | |
|---|
| 3407 | | - for (i = 0; i < 8; ++i) { |
|---|
| 3476 | + for (i = 0; i < FD_AUTODETECT_SIZE; ++i) { |
|---|
| 3408 | 3477 | if (autodetect[i] < 0 || |
|---|
| 3409 | 3478 | autodetect[i] >= floppy_type_size) |
|---|
| 3410 | 3479 | return false; |
|---|
| .. | .. |
|---|
| 3420 | 3489 | unsigned long param) |
|---|
| 3421 | 3490 | { |
|---|
| 3422 | 3491 | int drive = (long)bdev->bd_disk->private_data; |
|---|
| 3423 | | - int type = ITYPE(UDRS->fd_device); |
|---|
| 3424 | | - int i; |
|---|
| 3492 | + int type = ITYPE(drive_state[drive].fd_device); |
|---|
| 3425 | 3493 | int ret; |
|---|
| 3426 | 3494 | int size; |
|---|
| 3427 | 3495 | union inparam { |
|---|
| .. | .. |
|---|
| 3468 | 3536 | |
|---|
| 3469 | 3537 | switch (cmd) { |
|---|
| 3470 | 3538 | case FDEJECT: |
|---|
| 3471 | | - if (UDRS->fd_ref != 1) |
|---|
| 3539 | + if (drive_state[drive].fd_ref != 1) |
|---|
| 3472 | 3540 | /* somebody else has this drive open */ |
|---|
| 3473 | 3541 | return -EBUSY; |
|---|
| 3474 | 3542 | if (lock_fdc(drive)) |
|---|
| .. | .. |
|---|
| 3478 | 3546 | * non-Sparc architectures */ |
|---|
| 3479 | 3547 | ret = fd_eject(UNIT(drive)); |
|---|
| 3480 | 3548 | |
|---|
| 3481 | | - set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); |
|---|
| 3482 | | - set_bit(FD_VERIFY_BIT, &UDRS->flags); |
|---|
| 3549 | + set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags); |
|---|
| 3550 | + set_bit(FD_VERIFY_BIT, &drive_state[drive].flags); |
|---|
| 3483 | 3551 | process_fd_request(); |
|---|
| 3484 | 3552 | return ret; |
|---|
| 3485 | 3553 | case FDCLRPRM: |
|---|
| .. | .. |
|---|
| 3487 | 3555 | return -EINTR; |
|---|
| 3488 | 3556 | current_type[drive] = NULL; |
|---|
| 3489 | 3557 | floppy_sizes[drive] = MAX_DISK_SIZE << 1; |
|---|
| 3490 | | - UDRS->keep_data = 0; |
|---|
| 3558 | + drive_state[drive].keep_data = 0; |
|---|
| 3491 | 3559 | return invalidate_drive(bdev); |
|---|
| 3492 | 3560 | case FDSETPRM: |
|---|
| 3493 | 3561 | case FDDEFPRM: |
|---|
| .. | .. |
|---|
| 3502 | 3570 | outparam = &inparam.g; |
|---|
| 3503 | 3571 | break; |
|---|
| 3504 | 3572 | case FDMSGON: |
|---|
| 3505 | | - UDP->flags |= FTD_MSG; |
|---|
| 3573 | + drive_params[drive].flags |= FTD_MSG; |
|---|
| 3506 | 3574 | return 0; |
|---|
| 3507 | 3575 | case FDMSGOFF: |
|---|
| 3508 | | - UDP->flags &= ~FTD_MSG; |
|---|
| 3576 | + drive_params[drive].flags &= ~FTD_MSG; |
|---|
| 3509 | 3577 | return 0; |
|---|
| 3510 | 3578 | case FDFMTBEG: |
|---|
| 3511 | 3579 | if (lock_fdc(drive)) |
|---|
| 3512 | 3580 | return -EINTR; |
|---|
| 3513 | 3581 | if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR) |
|---|
| 3514 | 3582 | return -EINTR; |
|---|
| 3515 | | - ret = UDRS->flags; |
|---|
| 3583 | + ret = drive_state[drive].flags; |
|---|
| 3516 | 3584 | process_fd_request(); |
|---|
| 3517 | 3585 | if (ret & FD_VERIFY) |
|---|
| 3518 | 3586 | return -ENODEV; |
|---|
| .. | .. |
|---|
| 3520 | 3588 | return -EROFS; |
|---|
| 3521 | 3589 | return 0; |
|---|
| 3522 | 3590 | case FDFMTTRK: |
|---|
| 3523 | | - if (UDRS->fd_ref != 1) |
|---|
| 3591 | + if (drive_state[drive].fd_ref != 1) |
|---|
| 3524 | 3592 | return -EBUSY; |
|---|
| 3525 | 3593 | return do_format(drive, &inparam.f); |
|---|
| 3526 | 3594 | case FDFMTEND: |
|---|
| .. | .. |
|---|
| 3529 | 3597 | return -EINTR; |
|---|
| 3530 | 3598 | return invalidate_drive(bdev); |
|---|
| 3531 | 3599 | case FDSETEMSGTRESH: |
|---|
| 3532 | | - UDP->max_errors.reporting = (unsigned short)(param & 0x0f); |
|---|
| 3600 | + drive_params[drive].max_errors.reporting = (unsigned short)(param & 0x0f); |
|---|
| 3533 | 3601 | return 0; |
|---|
| 3534 | 3602 | case FDGETMAXERRS: |
|---|
| 3535 | | - outparam = &UDP->max_errors; |
|---|
| 3603 | + outparam = &drive_params[drive].max_errors; |
|---|
| 3536 | 3604 | break; |
|---|
| 3537 | 3605 | case FDSETMAXERRS: |
|---|
| 3538 | | - UDP->max_errors = inparam.max_errors; |
|---|
| 3606 | + drive_params[drive].max_errors = inparam.max_errors; |
|---|
| 3539 | 3607 | break; |
|---|
| 3540 | 3608 | case FDGETDRVTYP: |
|---|
| 3541 | 3609 | outparam = drive_name(type, drive); |
|---|
| .. | .. |
|---|
| 3545 | 3613 | if (!valid_floppy_drive_params(inparam.dp.autodetect, |
|---|
| 3546 | 3614 | inparam.dp.native_format)) |
|---|
| 3547 | 3615 | return -EINVAL; |
|---|
| 3548 | | - *UDP = inparam.dp; |
|---|
| 3616 | + drive_params[drive] = inparam.dp; |
|---|
| 3549 | 3617 | break; |
|---|
| 3550 | 3618 | case FDGETDRVPRM: |
|---|
| 3551 | | - outparam = UDP; |
|---|
| 3619 | + outparam = &drive_params[drive]; |
|---|
| 3552 | 3620 | break; |
|---|
| 3553 | 3621 | case FDPOLLDRVSTAT: |
|---|
| 3554 | 3622 | if (lock_fdc(drive)) |
|---|
| .. | .. |
|---|
| 3556 | 3624 | if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR) |
|---|
| 3557 | 3625 | return -EINTR; |
|---|
| 3558 | 3626 | process_fd_request(); |
|---|
| 3559 | | - /* fall through */ |
|---|
| 3627 | + fallthrough; |
|---|
| 3560 | 3628 | case FDGETDRVSTAT: |
|---|
| 3561 | | - outparam = UDRS; |
|---|
| 3629 | + outparam = &drive_state[drive]; |
|---|
| 3562 | 3630 | break; |
|---|
| 3563 | 3631 | case FDRESET: |
|---|
| 3564 | 3632 | return user_reset_fdc(drive, (int)param, true); |
|---|
| 3565 | 3633 | case FDGETFDCSTAT: |
|---|
| 3566 | | - outparam = UFDCS; |
|---|
| 3634 | + outparam = &fdc_state[FDC(drive)]; |
|---|
| 3567 | 3635 | break; |
|---|
| 3568 | 3636 | case FDWERRORCLR: |
|---|
| 3569 | | - memset(UDRWE, 0, sizeof(*UDRWE)); |
|---|
| 3637 | + memset(&write_errors[drive], 0, sizeof(write_errors[drive])); |
|---|
| 3570 | 3638 | return 0; |
|---|
| 3571 | 3639 | case FDWERRORGET: |
|---|
| 3572 | | - outparam = UDRWE; |
|---|
| 3640 | + outparam = &write_errors[drive]; |
|---|
| 3573 | 3641 | break; |
|---|
| 3574 | 3642 | case FDRAWCMD: |
|---|
| 3575 | | - if (type) |
|---|
| 3576 | | - return -EINVAL; |
|---|
| 3577 | | - if (lock_fdc(drive)) |
|---|
| 3578 | | - return -EINTR; |
|---|
| 3579 | | - set_floppy(drive); |
|---|
| 3580 | | - i = raw_cmd_ioctl(cmd, (void __user *)param); |
|---|
| 3581 | | - if (i == -EINTR) |
|---|
| 3582 | | - return -EINTR; |
|---|
| 3583 | | - process_fd_request(); |
|---|
| 3584 | | - return i; |
|---|
| 3643 | + return floppy_raw_cmd_ioctl(type, drive, cmd, (void __user *)param); |
|---|
| 3585 | 3644 | case FDTWADDLE: |
|---|
| 3586 | 3645 | if (lock_fdc(drive)) |
|---|
| 3587 | 3646 | return -EINTR; |
|---|
| 3588 | | - twaddle(); |
|---|
| 3647 | + twaddle(current_fdc, current_drive); |
|---|
| 3589 | 3648 | process_fd_request(); |
|---|
| 3590 | 3649 | return 0; |
|---|
| 3591 | 3650 | default: |
|---|
| .. | .. |
|---|
| 3629 | 3688 | struct floppy_max_errors max_errors; |
|---|
| 3630 | 3689 | char flags; |
|---|
| 3631 | 3690 | char read_track; |
|---|
| 3632 | | - short autodetect[8]; |
|---|
| 3691 | + short autodetect[FD_AUTODETECT_SIZE]; |
|---|
| 3633 | 3692 | compat_int_t checkfreq; |
|---|
| 3634 | 3693 | compat_int_t native_format; |
|---|
| 3635 | 3694 | }; |
|---|
| .. | .. |
|---|
| 3705 | 3764 | |
|---|
| 3706 | 3765 | mutex_lock(&floppy_mutex); |
|---|
| 3707 | 3766 | drive = (long)bdev->bd_disk->private_data; |
|---|
| 3708 | | - type = ITYPE(UDRS->fd_device); |
|---|
| 3767 | + type = ITYPE(drive_state[drive].fd_device); |
|---|
| 3709 | 3768 | err = set_geometry(cmd == FDSETPRM32 ? FDSETPRM : FDDEFPRM, |
|---|
| 3710 | 3769 | &v, drive, type, bdev); |
|---|
| 3711 | 3770 | mutex_unlock(&floppy_mutex); |
|---|
| .. | .. |
|---|
| 3721 | 3780 | |
|---|
| 3722 | 3781 | memset(&v, 0, sizeof(v)); |
|---|
| 3723 | 3782 | mutex_lock(&floppy_mutex); |
|---|
| 3724 | | - err = get_floppy_geometry(drive, ITYPE(UDRS->fd_device), &p); |
|---|
| 3783 | + err = get_floppy_geometry(drive, ITYPE(drive_state[drive].fd_device), |
|---|
| 3784 | + &p); |
|---|
| 3725 | 3785 | if (err) { |
|---|
| 3726 | 3786 | mutex_unlock(&floppy_mutex); |
|---|
| 3727 | 3787 | return err; |
|---|
| .. | .. |
|---|
| 3745 | 3805 | if (!valid_floppy_drive_params(v.autodetect, v.native_format)) |
|---|
| 3746 | 3806 | return -EINVAL; |
|---|
| 3747 | 3807 | mutex_lock(&floppy_mutex); |
|---|
| 3748 | | - UDP->cmos = v.cmos; |
|---|
| 3749 | | - UDP->max_dtr = v.max_dtr; |
|---|
| 3750 | | - UDP->hlt = v.hlt; |
|---|
| 3751 | | - UDP->hut = v.hut; |
|---|
| 3752 | | - UDP->srt = v.srt; |
|---|
| 3753 | | - UDP->spinup = v.spinup; |
|---|
| 3754 | | - UDP->spindown = v.spindown; |
|---|
| 3755 | | - UDP->spindown_offset = v.spindown_offset; |
|---|
| 3756 | | - UDP->select_delay = v.select_delay; |
|---|
| 3757 | | - UDP->rps = v.rps; |
|---|
| 3758 | | - UDP->tracks = v.tracks; |
|---|
| 3759 | | - UDP->timeout = v.timeout; |
|---|
| 3760 | | - UDP->interleave_sect = v.interleave_sect; |
|---|
| 3761 | | - UDP->max_errors = v.max_errors; |
|---|
| 3762 | | - UDP->flags = v.flags; |
|---|
| 3763 | | - UDP->read_track = v.read_track; |
|---|
| 3764 | | - memcpy(UDP->autodetect, v.autodetect, sizeof(v.autodetect)); |
|---|
| 3765 | | - UDP->checkfreq = v.checkfreq; |
|---|
| 3766 | | - UDP->native_format = v.native_format; |
|---|
| 3808 | + drive_params[drive].cmos = v.cmos; |
|---|
| 3809 | + drive_params[drive].max_dtr = v.max_dtr; |
|---|
| 3810 | + drive_params[drive].hlt = v.hlt; |
|---|
| 3811 | + drive_params[drive].hut = v.hut; |
|---|
| 3812 | + drive_params[drive].srt = v.srt; |
|---|
| 3813 | + drive_params[drive].spinup = v.spinup; |
|---|
| 3814 | + drive_params[drive].spindown = v.spindown; |
|---|
| 3815 | + drive_params[drive].spindown_offset = v.spindown_offset; |
|---|
| 3816 | + drive_params[drive].select_delay = v.select_delay; |
|---|
| 3817 | + drive_params[drive].rps = v.rps; |
|---|
| 3818 | + drive_params[drive].tracks = v.tracks; |
|---|
| 3819 | + drive_params[drive].timeout = v.timeout; |
|---|
| 3820 | + drive_params[drive].interleave_sect = v.interleave_sect; |
|---|
| 3821 | + drive_params[drive].max_errors = v.max_errors; |
|---|
| 3822 | + drive_params[drive].flags = v.flags; |
|---|
| 3823 | + drive_params[drive].read_track = v.read_track; |
|---|
| 3824 | + memcpy(drive_params[drive].autodetect, v.autodetect, |
|---|
| 3825 | + sizeof(v.autodetect)); |
|---|
| 3826 | + drive_params[drive].checkfreq = v.checkfreq; |
|---|
| 3827 | + drive_params[drive].native_format = v.native_format; |
|---|
| 3767 | 3828 | mutex_unlock(&floppy_mutex); |
|---|
| 3768 | 3829 | return 0; |
|---|
| 3769 | 3830 | } |
|---|
| .. | .. |
|---|
| 3775 | 3836 | |
|---|
| 3776 | 3837 | memset(&v, 0, sizeof(struct compat_floppy_drive_params)); |
|---|
| 3777 | 3838 | mutex_lock(&floppy_mutex); |
|---|
| 3778 | | - v.cmos = UDP->cmos; |
|---|
| 3779 | | - v.max_dtr = UDP->max_dtr; |
|---|
| 3780 | | - v.hlt = UDP->hlt; |
|---|
| 3781 | | - v.hut = UDP->hut; |
|---|
| 3782 | | - v.srt = UDP->srt; |
|---|
| 3783 | | - v.spinup = UDP->spinup; |
|---|
| 3784 | | - v.spindown = UDP->spindown; |
|---|
| 3785 | | - v.spindown_offset = UDP->spindown_offset; |
|---|
| 3786 | | - v.select_delay = UDP->select_delay; |
|---|
| 3787 | | - v.rps = UDP->rps; |
|---|
| 3788 | | - v.tracks = UDP->tracks; |
|---|
| 3789 | | - v.timeout = UDP->timeout; |
|---|
| 3790 | | - v.interleave_sect = UDP->interleave_sect; |
|---|
| 3791 | | - v.max_errors = UDP->max_errors; |
|---|
| 3792 | | - v.flags = UDP->flags; |
|---|
| 3793 | | - v.read_track = UDP->read_track; |
|---|
| 3794 | | - memcpy(v.autodetect, UDP->autodetect, sizeof(v.autodetect)); |
|---|
| 3795 | | - v.checkfreq = UDP->checkfreq; |
|---|
| 3796 | | - v.native_format = UDP->native_format; |
|---|
| 3839 | + v.cmos = drive_params[drive].cmos; |
|---|
| 3840 | + v.max_dtr = drive_params[drive].max_dtr; |
|---|
| 3841 | + v.hlt = drive_params[drive].hlt; |
|---|
| 3842 | + v.hut = drive_params[drive].hut; |
|---|
| 3843 | + v.srt = drive_params[drive].srt; |
|---|
| 3844 | + v.spinup = drive_params[drive].spinup; |
|---|
| 3845 | + v.spindown = drive_params[drive].spindown; |
|---|
| 3846 | + v.spindown_offset = drive_params[drive].spindown_offset; |
|---|
| 3847 | + v.select_delay = drive_params[drive].select_delay; |
|---|
| 3848 | + v.rps = drive_params[drive].rps; |
|---|
| 3849 | + v.tracks = drive_params[drive].tracks; |
|---|
| 3850 | + v.timeout = drive_params[drive].timeout; |
|---|
| 3851 | + v.interleave_sect = drive_params[drive].interleave_sect; |
|---|
| 3852 | + v.max_errors = drive_params[drive].max_errors; |
|---|
| 3853 | + v.flags = drive_params[drive].flags; |
|---|
| 3854 | + v.read_track = drive_params[drive].read_track; |
|---|
| 3855 | + memcpy(v.autodetect, drive_params[drive].autodetect, |
|---|
| 3856 | + sizeof(v.autodetect)); |
|---|
| 3857 | + v.checkfreq = drive_params[drive].checkfreq; |
|---|
| 3858 | + v.native_format = drive_params[drive].native_format; |
|---|
| 3797 | 3859 | mutex_unlock(&floppy_mutex); |
|---|
| 3798 | 3860 | |
|---|
| 3799 | 3861 | if (copy_to_user(arg, &v, sizeof(struct compat_floppy_drive_params))) |
|---|
| .. | .. |
|---|
| 3816 | 3878 | goto Eintr; |
|---|
| 3817 | 3879 | process_fd_request(); |
|---|
| 3818 | 3880 | } |
|---|
| 3819 | | - v.spinup_date = UDRS->spinup_date; |
|---|
| 3820 | | - v.select_date = UDRS->select_date; |
|---|
| 3821 | | - v.first_read_date = UDRS->first_read_date; |
|---|
| 3822 | | - v.probed_format = UDRS->probed_format; |
|---|
| 3823 | | - v.track = UDRS->track; |
|---|
| 3824 | | - v.maxblock = UDRS->maxblock; |
|---|
| 3825 | | - v.maxtrack = UDRS->maxtrack; |
|---|
| 3826 | | - v.generation = UDRS->generation; |
|---|
| 3827 | | - v.keep_data = UDRS->keep_data; |
|---|
| 3828 | | - v.fd_ref = UDRS->fd_ref; |
|---|
| 3829 | | - v.fd_device = UDRS->fd_device; |
|---|
| 3830 | | - v.last_checked = UDRS->last_checked; |
|---|
| 3831 | | - v.dmabuf = (uintptr_t)UDRS->dmabuf; |
|---|
| 3832 | | - v.bufblocks = UDRS->bufblocks; |
|---|
| 3881 | + v.spinup_date = drive_state[drive].spinup_date; |
|---|
| 3882 | + v.select_date = drive_state[drive].select_date; |
|---|
| 3883 | + v.first_read_date = drive_state[drive].first_read_date; |
|---|
| 3884 | + v.probed_format = drive_state[drive].probed_format; |
|---|
| 3885 | + v.track = drive_state[drive].track; |
|---|
| 3886 | + v.maxblock = drive_state[drive].maxblock; |
|---|
| 3887 | + v.maxtrack = drive_state[drive].maxtrack; |
|---|
| 3888 | + v.generation = drive_state[drive].generation; |
|---|
| 3889 | + v.keep_data = drive_state[drive].keep_data; |
|---|
| 3890 | + v.fd_ref = drive_state[drive].fd_ref; |
|---|
| 3891 | + v.fd_device = drive_state[drive].fd_device; |
|---|
| 3892 | + v.last_checked = drive_state[drive].last_checked; |
|---|
| 3893 | + v.dmabuf = (uintptr_t) drive_state[drive].dmabuf; |
|---|
| 3894 | + v.bufblocks = drive_state[drive].bufblocks; |
|---|
| 3833 | 3895 | mutex_unlock(&floppy_mutex); |
|---|
| 3834 | 3896 | |
|---|
| 3835 | 3897 | if (copy_to_user(arg, &v, sizeof(struct compat_floppy_drive_struct))) |
|---|
| .. | .. |
|---|
| 3847 | 3909 | struct floppy_fdc_state v; |
|---|
| 3848 | 3910 | |
|---|
| 3849 | 3911 | mutex_lock(&floppy_mutex); |
|---|
| 3850 | | - v = *UFDCS; |
|---|
| 3912 | + v = fdc_state[FDC(drive)]; |
|---|
| 3851 | 3913 | mutex_unlock(&floppy_mutex); |
|---|
| 3852 | 3914 | |
|---|
| 3853 | 3915 | memset(&v32, 0, sizeof(struct compat_floppy_fdc_state)); |
|---|
| .. | .. |
|---|
| 3877 | 3939 | |
|---|
| 3878 | 3940 | memset(&v32, 0, sizeof(struct compat_floppy_write_errors)); |
|---|
| 3879 | 3941 | mutex_lock(&floppy_mutex); |
|---|
| 3880 | | - v = *UDRWE; |
|---|
| 3942 | + v = write_errors[drive]; |
|---|
| 3881 | 3943 | mutex_unlock(&floppy_mutex); |
|---|
| 3882 | 3944 | v32.write_errors = v.write_errors; |
|---|
| 3883 | 3945 | v32.first_error_sector = v.first_error_sector; |
|---|
| .. | .. |
|---|
| 3895 | 3957 | { |
|---|
| 3896 | 3958 | int drive = (long)bdev->bd_disk->private_data; |
|---|
| 3897 | 3959 | switch (cmd) { |
|---|
| 3960 | + case CDROMEJECT: /* CD-ROM eject */ |
|---|
| 3961 | + case 0x6470: /* SunOS floppy eject */ |
|---|
| 3962 | + |
|---|
| 3898 | 3963 | case FDMSGON: |
|---|
| 3899 | 3964 | case FDMSGOFF: |
|---|
| 3900 | 3965 | case FDSETEMSGTRESH: |
|---|
| .. | .. |
|---|
| 3943 | 4008 | |
|---|
| 3944 | 4009 | /* read drive info out of physical CMOS */ |
|---|
| 3945 | 4010 | drive = 0; |
|---|
| 3946 | | - if (!UDP->cmos) |
|---|
| 3947 | | - UDP->cmos = FLOPPY0_TYPE; |
|---|
| 4011 | + if (!drive_params[drive].cmos) |
|---|
| 4012 | + drive_params[drive].cmos = FLOPPY0_TYPE; |
|---|
| 3948 | 4013 | drive = 1; |
|---|
| 3949 | | - if (!UDP->cmos && FLOPPY1_TYPE) |
|---|
| 3950 | | - UDP->cmos = FLOPPY1_TYPE; |
|---|
| 4014 | + if (!drive_params[drive].cmos) |
|---|
| 4015 | + drive_params[drive].cmos = FLOPPY1_TYPE; |
|---|
| 3951 | 4016 | |
|---|
| 3952 | 4017 | /* FIXME: additional physical CMOS drive detection should go here */ |
|---|
| 3953 | 4018 | |
|---|
| 3954 | 4019 | for (drive = 0; drive < N_DRIVE; drive++) { |
|---|
| 3955 | | - unsigned int type = UDP->cmos; |
|---|
| 4020 | + unsigned int type = drive_params[drive].cmos; |
|---|
| 3956 | 4021 | struct floppy_drive_params *params; |
|---|
| 3957 | 4022 | const char *name = NULL; |
|---|
| 3958 | 4023 | char temparea[32]; |
|---|
| .. | .. |
|---|
| 3982 | 4047 | |
|---|
| 3983 | 4048 | pr_cont("%s fd%d is %s", prepend, drive, name); |
|---|
| 3984 | 4049 | } |
|---|
| 3985 | | - *UDP = *params; |
|---|
| 4050 | + drive_params[drive] = *params; |
|---|
| 3986 | 4051 | } |
|---|
| 3987 | 4052 | |
|---|
| 3988 | 4053 | if (has_drive) |
|---|
| .. | .. |
|---|
| 3995 | 4060 | |
|---|
| 3996 | 4061 | mutex_lock(&floppy_mutex); |
|---|
| 3997 | 4062 | mutex_lock(&open_lock); |
|---|
| 3998 | | - if (!UDRS->fd_ref--) { |
|---|
| 4063 | + if (!drive_state[drive].fd_ref--) { |
|---|
| 3999 | 4064 | DPRINT("floppy_release with fd_ref == 0"); |
|---|
| 4000 | | - UDRS->fd_ref = 0; |
|---|
| 4065 | + drive_state[drive].fd_ref = 0; |
|---|
| 4001 | 4066 | } |
|---|
| 4002 | | - if (!UDRS->fd_ref) |
|---|
| 4067 | + if (!drive_state[drive].fd_ref) |
|---|
| 4003 | 4068 | opened_bdev[drive] = NULL; |
|---|
| 4004 | 4069 | mutex_unlock(&open_lock); |
|---|
| 4005 | 4070 | mutex_unlock(&floppy_mutex); |
|---|
| .. | .. |
|---|
| 4020 | 4085 | |
|---|
| 4021 | 4086 | mutex_lock(&floppy_mutex); |
|---|
| 4022 | 4087 | mutex_lock(&open_lock); |
|---|
| 4023 | | - old_dev = UDRS->fd_device; |
|---|
| 4088 | + old_dev = drive_state[drive].fd_device; |
|---|
| 4024 | 4089 | if (opened_bdev[drive] && opened_bdev[drive] != bdev) |
|---|
| 4025 | 4090 | goto out2; |
|---|
| 4026 | 4091 | |
|---|
| 4027 | | - if (!UDRS->fd_ref && (UDP->flags & FD_BROKEN_DCL)) { |
|---|
| 4028 | | - set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); |
|---|
| 4029 | | - set_bit(FD_VERIFY_BIT, &UDRS->flags); |
|---|
| 4092 | + if (!drive_state[drive].fd_ref && (drive_params[drive].flags & FD_BROKEN_DCL)) { |
|---|
| 4093 | + set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags); |
|---|
| 4094 | + set_bit(FD_VERIFY_BIT, &drive_state[drive].flags); |
|---|
| 4030 | 4095 | } |
|---|
| 4031 | 4096 | |
|---|
| 4032 | | - UDRS->fd_ref++; |
|---|
| 4097 | + drive_state[drive].fd_ref++; |
|---|
| 4033 | 4098 | |
|---|
| 4034 | 4099 | opened_bdev[drive] = bdev; |
|---|
| 4035 | 4100 | |
|---|
| .. | .. |
|---|
| 4038 | 4103 | if (!floppy_track_buffer) { |
|---|
| 4039 | 4104 | /* if opening an ED drive, reserve a big buffer, |
|---|
| 4040 | 4105 | * else reserve a small one */ |
|---|
| 4041 | | - if ((UDP->cmos == 6) || (UDP->cmos == 5)) |
|---|
| 4106 | + if ((drive_params[drive].cmos == 6) || (drive_params[drive].cmos == 5)) |
|---|
| 4042 | 4107 | try = 64; /* Only 48 actually useful */ |
|---|
| 4043 | 4108 | else |
|---|
| 4044 | 4109 | try = 32; /* Only 24 actually useful */ |
|---|
| .. | .. |
|---|
| 4066 | 4131 | } |
|---|
| 4067 | 4132 | |
|---|
| 4068 | 4133 | new_dev = MINOR(bdev->bd_dev); |
|---|
| 4069 | | - UDRS->fd_device = new_dev; |
|---|
| 4134 | + drive_state[drive].fd_device = new_dev; |
|---|
| 4070 | 4135 | set_capacity(disks[drive], floppy_sizes[new_dev]); |
|---|
| 4071 | 4136 | if (old_dev != -1 && old_dev != new_dev) { |
|---|
| 4072 | 4137 | if (buffer_drive == drive) |
|---|
| 4073 | 4138 | buffer_track = -1; |
|---|
| 4074 | 4139 | } |
|---|
| 4075 | 4140 | |
|---|
| 4076 | | - if (UFDCS->rawcmd == 1) |
|---|
| 4077 | | - UFDCS->rawcmd = 2; |
|---|
| 4141 | + if (fdc_state[FDC(drive)].rawcmd == 1) |
|---|
| 4142 | + fdc_state[FDC(drive)].rawcmd = 2; |
|---|
| 4078 | 4143 | |
|---|
| 4079 | 4144 | if (!(mode & FMODE_NDELAY)) { |
|---|
| 4080 | 4145 | if (mode & (FMODE_READ|FMODE_WRITE)) { |
|---|
| 4081 | | - UDRS->last_checked = 0; |
|---|
| 4082 | | - clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags); |
|---|
| 4083 | | - check_disk_change(bdev); |
|---|
| 4084 | | - if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags)) |
|---|
| 4146 | + drive_state[drive].last_checked = 0; |
|---|
| 4147 | + clear_bit(FD_OPEN_SHOULD_FAIL_BIT, |
|---|
| 4148 | + &drive_state[drive].flags); |
|---|
| 4149 | + if (bdev_check_media_change(bdev)) |
|---|
| 4150 | + floppy_revalidate(bdev->bd_disk); |
|---|
| 4151 | + if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags)) |
|---|
| 4085 | 4152 | goto out; |
|---|
| 4086 | | - if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags)) |
|---|
| 4153 | + if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags)) |
|---|
| 4087 | 4154 | goto out; |
|---|
| 4088 | 4155 | } |
|---|
| 4089 | 4156 | res = -EROFS; |
|---|
| 4090 | 4157 | if ((mode & FMODE_WRITE) && |
|---|
| 4091 | | - !test_bit(FD_DISK_WRITABLE_BIT, &UDRS->flags)) |
|---|
| 4158 | + !test_bit(FD_DISK_WRITABLE_BIT, &drive_state[drive].flags)) |
|---|
| 4092 | 4159 | goto out; |
|---|
| 4093 | 4160 | } |
|---|
| 4094 | 4161 | mutex_unlock(&open_lock); |
|---|
| 4095 | 4162 | mutex_unlock(&floppy_mutex); |
|---|
| 4096 | 4163 | return 0; |
|---|
| 4097 | 4164 | out: |
|---|
| 4098 | | - UDRS->fd_ref--; |
|---|
| 4165 | + drive_state[drive].fd_ref--; |
|---|
| 4099 | 4166 | |
|---|
| 4100 | | - if (!UDRS->fd_ref) |
|---|
| 4167 | + if (!drive_state[drive].fd_ref) |
|---|
| 4101 | 4168 | opened_bdev[drive] = NULL; |
|---|
| 4102 | 4169 | out2: |
|---|
| 4103 | 4170 | mutex_unlock(&open_lock); |
|---|
| .. | .. |
|---|
| 4113 | 4180 | { |
|---|
| 4114 | 4181 | int drive = (long)disk->private_data; |
|---|
| 4115 | 4182 | |
|---|
| 4116 | | - if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || |
|---|
| 4117 | | - test_bit(FD_VERIFY_BIT, &UDRS->flags)) |
|---|
| 4183 | + if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) || |
|---|
| 4184 | + test_bit(FD_VERIFY_BIT, &drive_state[drive].flags)) |
|---|
| 4118 | 4185 | return DISK_EVENT_MEDIA_CHANGE; |
|---|
| 4119 | 4186 | |
|---|
| 4120 | | - if (time_after(jiffies, UDRS->last_checked + UDP->checkfreq)) { |
|---|
| 4187 | + if (time_after(jiffies, drive_state[drive].last_checked + drive_params[drive].checkfreq)) { |
|---|
| 4121 | 4188 | if (lock_fdc(drive)) |
|---|
| 4122 | 4189 | return 0; |
|---|
| 4123 | 4190 | poll_drive(false, 0); |
|---|
| 4124 | 4191 | process_fd_request(); |
|---|
| 4125 | 4192 | } |
|---|
| 4126 | 4193 | |
|---|
| 4127 | | - if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || |
|---|
| 4128 | | - test_bit(FD_VERIFY_BIT, &UDRS->flags) || |
|---|
| 4194 | + if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) || |
|---|
| 4195 | + test_bit(FD_VERIFY_BIT, &drive_state[drive].flags) || |
|---|
| 4129 | 4196 | test_bit(drive, &fake_change) || |
|---|
| 4130 | 4197 | drive_no_geom(drive)) |
|---|
| 4131 | 4198 | return DISK_EVENT_MEDIA_CHANGE; |
|---|
| .. | .. |
|---|
| 4151 | 4218 | if (bio->bi_status) { |
|---|
| 4152 | 4219 | pr_info("floppy: error %d while reading block 0\n", |
|---|
| 4153 | 4220 | bio->bi_status); |
|---|
| 4154 | | - set_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags); |
|---|
| 4221 | + set_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags); |
|---|
| 4155 | 4222 | } |
|---|
| 4156 | 4223 | complete(&cbdata->complete); |
|---|
| 4157 | 4224 | } |
|---|
| .. | .. |
|---|
| 4162 | 4229 | struct bio_vec bio_vec; |
|---|
| 4163 | 4230 | struct page *page; |
|---|
| 4164 | 4231 | struct rb0_cbdata cbdata; |
|---|
| 4165 | | - size_t size; |
|---|
| 4166 | 4232 | |
|---|
| 4167 | 4233 | page = alloc_page(GFP_NOIO); |
|---|
| 4168 | 4234 | if (!page) { |
|---|
| .. | .. |
|---|
| 4170 | 4236 | return -ENOMEM; |
|---|
| 4171 | 4237 | } |
|---|
| 4172 | 4238 | |
|---|
| 4173 | | - size = bdev->bd_block_size; |
|---|
| 4174 | | - if (!size) |
|---|
| 4175 | | - size = 1024; |
|---|
| 4176 | | - |
|---|
| 4177 | 4239 | cbdata.drive = drive; |
|---|
| 4178 | 4240 | |
|---|
| 4179 | 4241 | bio_init(&bio, &bio_vec, 1); |
|---|
| 4180 | 4242 | bio_set_dev(&bio, bdev); |
|---|
| 4181 | | - bio_add_page(&bio, page, size, 0); |
|---|
| 4243 | + bio_add_page(&bio, page, block_size(bdev), 0); |
|---|
| 4182 | 4244 | |
|---|
| 4183 | 4245 | bio.bi_iter.bi_sector = 0; |
|---|
| 4184 | 4246 | bio.bi_flags |= (1 << BIO_QUIET); |
|---|
| .. | .. |
|---|
| 4208 | 4270 | int cf; |
|---|
| 4209 | 4271 | int res = 0; |
|---|
| 4210 | 4272 | |
|---|
| 4211 | | - if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || |
|---|
| 4212 | | - test_bit(FD_VERIFY_BIT, &UDRS->flags) || |
|---|
| 4273 | + if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) || |
|---|
| 4274 | + test_bit(FD_VERIFY_BIT, &drive_state[drive].flags) || |
|---|
| 4213 | 4275 | test_bit(drive, &fake_change) || |
|---|
| 4214 | 4276 | drive_no_geom(drive)) { |
|---|
| 4215 | 4277 | if (WARN(atomic_read(&usage_count) == 0, |
|---|
| .. | .. |
|---|
| 4219 | 4281 | res = lock_fdc(drive); |
|---|
| 4220 | 4282 | if (res) |
|---|
| 4221 | 4283 | return res; |
|---|
| 4222 | | - cf = (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || |
|---|
| 4223 | | - test_bit(FD_VERIFY_BIT, &UDRS->flags)); |
|---|
| 4284 | + cf = (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) || |
|---|
| 4285 | + test_bit(FD_VERIFY_BIT, &drive_state[drive].flags)); |
|---|
| 4224 | 4286 | if (!(cf || test_bit(drive, &fake_change) || drive_no_geom(drive))) { |
|---|
| 4225 | 4287 | process_fd_request(); /*already done by another thread */ |
|---|
| 4226 | 4288 | return 0; |
|---|
| 4227 | 4289 | } |
|---|
| 4228 | | - UDRS->maxblock = 0; |
|---|
| 4229 | | - UDRS->maxtrack = 0; |
|---|
| 4290 | + drive_state[drive].maxblock = 0; |
|---|
| 4291 | + drive_state[drive].maxtrack = 0; |
|---|
| 4230 | 4292 | if (buffer_drive == drive) |
|---|
| 4231 | 4293 | buffer_track = -1; |
|---|
| 4232 | 4294 | clear_bit(drive, &fake_change); |
|---|
| 4233 | | - clear_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); |
|---|
| 4295 | + clear_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags); |
|---|
| 4234 | 4296 | if (cf) |
|---|
| 4235 | | - UDRS->generation++; |
|---|
| 4297 | + drive_state[drive].generation++; |
|---|
| 4236 | 4298 | if (drive_no_geom(drive)) { |
|---|
| 4237 | 4299 | /* auto-sensing */ |
|---|
| 4238 | 4300 | res = __floppy_read_block_0(opened_bdev[drive], drive); |
|---|
| .. | .. |
|---|
| 4242 | 4304 | process_fd_request(); |
|---|
| 4243 | 4305 | } |
|---|
| 4244 | 4306 | } |
|---|
| 4245 | | - set_capacity(disk, floppy_sizes[UDRS->fd_device]); |
|---|
| 4307 | + set_capacity(disk, floppy_sizes[drive_state[drive].fd_device]); |
|---|
| 4246 | 4308 | return res; |
|---|
| 4247 | 4309 | } |
|---|
| 4248 | 4310 | |
|---|
| .. | .. |
|---|
| 4253 | 4315 | .ioctl = fd_ioctl, |
|---|
| 4254 | 4316 | .getgeo = fd_getgeo, |
|---|
| 4255 | 4317 | .check_events = floppy_check_events, |
|---|
| 4256 | | - .revalidate_disk = floppy_revalidate, |
|---|
| 4257 | 4318 | #ifdef CONFIG_COMPAT |
|---|
| 4258 | 4319 | .compat_ioctl = fd_compat_ioctl, |
|---|
| 4259 | 4320 | #endif |
|---|
| .. | .. |
|---|
| 4266 | 4327 | |
|---|
| 4267 | 4328 | /* Determine the floppy disk controller type */ |
|---|
| 4268 | 4329 | /* This routine was written by David C. Niemi */ |
|---|
| 4269 | | -static char __init get_fdc_version(void) |
|---|
| 4330 | +static char __init get_fdc_version(int fdc) |
|---|
| 4270 | 4331 | { |
|---|
| 4271 | 4332 | int r; |
|---|
| 4272 | 4333 | |
|---|
| 4273 | | - output_byte(FD_DUMPREGS); /* 82072 and better know DUMPREGS */ |
|---|
| 4274 | | - if (FDCS->reset) |
|---|
| 4334 | + output_byte(fdc, FD_DUMPREGS); /* 82072 and better know DUMPREGS */ |
|---|
| 4335 | + if (fdc_state[fdc].reset) |
|---|
| 4275 | 4336 | return FDC_NONE; |
|---|
| 4276 | | - r = result(); |
|---|
| 4337 | + r = result(fdc); |
|---|
| 4277 | 4338 | if (r <= 0x00) |
|---|
| 4278 | 4339 | return FDC_NONE; /* No FDC present ??? */ |
|---|
| 4279 | 4340 | if ((r == 1) && (reply_buffer[0] == 0x80)) { |
|---|
| .. | .. |
|---|
| 4286 | 4347 | return FDC_UNKNOWN; |
|---|
| 4287 | 4348 | } |
|---|
| 4288 | 4349 | |
|---|
| 4289 | | - if (!fdc_configure()) { |
|---|
| 4350 | + if (!fdc_configure(fdc)) { |
|---|
| 4290 | 4351 | pr_info("FDC %d is an 82072\n", fdc); |
|---|
| 4291 | 4352 | return FDC_82072; /* 82072 doesn't know CONFIGURE */ |
|---|
| 4292 | 4353 | } |
|---|
| 4293 | 4354 | |
|---|
| 4294 | | - output_byte(FD_PERPENDICULAR); |
|---|
| 4295 | | - if (need_more_output() == MORE_OUTPUT) { |
|---|
| 4296 | | - output_byte(0); |
|---|
| 4355 | + output_byte(fdc, FD_PERPENDICULAR); |
|---|
| 4356 | + if (need_more_output(fdc) == MORE_OUTPUT) { |
|---|
| 4357 | + output_byte(fdc, 0); |
|---|
| 4297 | 4358 | } else { |
|---|
| 4298 | 4359 | pr_info("FDC %d is an 82072A\n", fdc); |
|---|
| 4299 | 4360 | return FDC_82072A; /* 82072A as found on Sparcs. */ |
|---|
| 4300 | 4361 | } |
|---|
| 4301 | 4362 | |
|---|
| 4302 | | - output_byte(FD_UNLOCK); |
|---|
| 4303 | | - r = result(); |
|---|
| 4363 | + output_byte(fdc, FD_UNLOCK); |
|---|
| 4364 | + r = result(fdc); |
|---|
| 4304 | 4365 | if ((r == 1) && (reply_buffer[0] == 0x80)) { |
|---|
| 4305 | 4366 | pr_info("FDC %d is a pre-1991 82077\n", fdc); |
|---|
| 4306 | 4367 | return FDC_82077_ORIG; /* Pre-1991 82077, doesn't know |
|---|
| .. | .. |
|---|
| 4311 | 4372 | fdc, r); |
|---|
| 4312 | 4373 | return FDC_UNKNOWN; |
|---|
| 4313 | 4374 | } |
|---|
| 4314 | | - output_byte(FD_PARTID); |
|---|
| 4315 | | - r = result(); |
|---|
| 4375 | + output_byte(fdc, FD_PARTID); |
|---|
| 4376 | + r = result(fdc); |
|---|
| 4316 | 4377 | if (r != 1) { |
|---|
| 4317 | 4378 | pr_info("FDC %d init: PARTID: unexpected return of %d bytes.\n", |
|---|
| 4318 | 4379 | fdc, r); |
|---|
| .. | .. |
|---|
| 4394 | 4455 | if (current_drive >= 4 && !FDC2) |
|---|
| 4395 | 4456 | FDC2 = 0x370; |
|---|
| 4396 | 4457 | #endif |
|---|
| 4397 | | - DP->cmos = ints[2]; |
|---|
| 4458 | + drive_params[current_drive].cmos = ints[2]; |
|---|
| 4398 | 4459 | DPRINT("setting CMOS code to %d\n", ints[2]); |
|---|
| 4399 | 4460 | } |
|---|
| 4400 | 4461 | |
|---|
| .. | .. |
|---|
| 4470 | 4531 | pr_cont("\n"); |
|---|
| 4471 | 4532 | } else |
|---|
| 4472 | 4533 | DPRINT("botched floppy option\n"); |
|---|
| 4473 | | - DPRINT("Read Documentation/blockdev/floppy.txt\n"); |
|---|
| 4534 | + DPRINT("Read Documentation/admin-guide/blockdev/floppy.rst\n"); |
|---|
| 4474 | 4535 | return 0; |
|---|
| 4475 | 4536 | } |
|---|
| 4476 | 4537 | |
|---|
| .. | .. |
|---|
| 4483 | 4544 | int drive; |
|---|
| 4484 | 4545 | |
|---|
| 4485 | 4546 | drive = p->id; |
|---|
| 4486 | | - return sprintf(buf, "%X\n", UDP->cmos); |
|---|
| 4547 | + return sprintf(buf, "%X\n", drive_params[drive].cmos); |
|---|
| 4487 | 4548 | } |
|---|
| 4488 | 4549 | |
|---|
| 4489 | 4550 | static DEVICE_ATTR(cmos, 0444, floppy_cmos_show, NULL); |
|---|
| .. | .. |
|---|
| 4502 | 4563 | static int floppy_resume(struct device *dev) |
|---|
| 4503 | 4564 | { |
|---|
| 4504 | 4565 | int fdc; |
|---|
| 4566 | + int saved_drive; |
|---|
| 4505 | 4567 | |
|---|
| 4568 | + saved_drive = current_drive; |
|---|
| 4506 | 4569 | for (fdc = 0; fdc < N_FDC; fdc++) |
|---|
| 4507 | | - if (FDCS->address != -1) |
|---|
| 4508 | | - user_reset_fdc(-1, FD_RESET_ALWAYS, false); |
|---|
| 4509 | | - |
|---|
| 4570 | + if (fdc_state[fdc].address != -1) |
|---|
| 4571 | + user_reset_fdc(REVDRIVE(fdc, 0), FD_RESET_ALWAYS, false); |
|---|
| 4572 | + set_fdc(saved_drive); |
|---|
| 4510 | 4573 | return 0; |
|---|
| 4511 | 4574 | } |
|---|
| 4512 | 4575 | |
|---|
| .. | .. |
|---|
| 4520 | 4583 | .name = "floppy", |
|---|
| 4521 | 4584 | .pm = &floppy_pm_ops, |
|---|
| 4522 | 4585 | }, |
|---|
| 4586 | +}; |
|---|
| 4587 | + |
|---|
| 4588 | +static const struct blk_mq_ops floppy_mq_ops = { |
|---|
| 4589 | + .queue_rq = floppy_queue_rq, |
|---|
| 4523 | 4590 | }; |
|---|
| 4524 | 4591 | |
|---|
| 4525 | 4592 | static struct platform_device floppy_device[N_DRIVE]; |
|---|
| .. | .. |
|---|
| 4569 | 4636 | goto out_put_disk; |
|---|
| 4570 | 4637 | } |
|---|
| 4571 | 4638 | |
|---|
| 4572 | | - disks[drive]->queue = blk_init_queue(do_fd_request, &floppy_lock); |
|---|
| 4573 | | - if (!disks[drive]->queue) { |
|---|
| 4574 | | - err = -ENOMEM; |
|---|
| 4639 | + disks[drive]->queue = blk_mq_init_sq_queue(&tag_sets[drive], |
|---|
| 4640 | + &floppy_mq_ops, 2, |
|---|
| 4641 | + BLK_MQ_F_SHOULD_MERGE); |
|---|
| 4642 | + if (IS_ERR(disks[drive]->queue)) { |
|---|
| 4643 | + err = PTR_ERR(disks[drive]->queue); |
|---|
| 4644 | + disks[drive]->queue = NULL; |
|---|
| 4575 | 4645 | goto out_put_disk; |
|---|
| 4576 | 4646 | } |
|---|
| 4577 | 4647 | |
|---|
| .. | .. |
|---|
| 4580 | 4650 | disks[drive]->major = FLOPPY_MAJOR; |
|---|
| 4581 | 4651 | disks[drive]->first_minor = TOMINOR(drive); |
|---|
| 4582 | 4652 | disks[drive]->fops = &floppy_fops; |
|---|
| 4653 | + disks[drive]->events = DISK_EVENT_MEDIA_CHANGE; |
|---|
| 4583 | 4654 | sprintf(disks[drive]->disk_name, "fd%d", drive); |
|---|
| 4584 | 4655 | |
|---|
| 4585 | 4656 | timer_setup(&motor_off_timer[drive], motor_off_callback, 0); |
|---|
| .. | .. |
|---|
| 4606 | 4677 | config_types(); |
|---|
| 4607 | 4678 | |
|---|
| 4608 | 4679 | for (i = 0; i < N_FDC; i++) { |
|---|
| 4609 | | - fdc = i; |
|---|
| 4610 | | - memset(FDCS, 0, sizeof(*FDCS)); |
|---|
| 4611 | | - FDCS->dtr = -1; |
|---|
| 4612 | | - FDCS->dor = 0x4; |
|---|
| 4680 | + memset(&fdc_state[i], 0, sizeof(*fdc_state)); |
|---|
| 4681 | + fdc_state[i].dtr = -1; |
|---|
| 4682 | + fdc_state[i].dor = 0x4; |
|---|
| 4613 | 4683 | #if defined(__sparc__) || defined(__mc68000__) |
|---|
| 4614 | 4684 | /*sparcs/sun3x don't have a DOR reset which we can fall back on to */ |
|---|
| 4615 | 4685 | #ifdef __mc68000__ |
|---|
| 4616 | 4686 | if (MACH_IS_SUN3X) |
|---|
| 4617 | 4687 | #endif |
|---|
| 4618 | | - FDCS->version = FDC_82072A; |
|---|
| 4688 | + fdc_state[i].version = FDC_82072A; |
|---|
| 4619 | 4689 | #endif |
|---|
| 4620 | 4690 | } |
|---|
| 4621 | 4691 | |
|---|
| .. | .. |
|---|
| 4630 | 4700 | fdc_state[1].address = FDC2; |
|---|
| 4631 | 4701 | #endif |
|---|
| 4632 | 4702 | |
|---|
| 4633 | | - fdc = 0; /* reset fdc in case of unexpected interrupt */ |
|---|
| 4703 | + current_fdc = 0; /* reset fdc in case of unexpected interrupt */ |
|---|
| 4634 | 4704 | err = floppy_grab_irq_and_dma(); |
|---|
| 4635 | 4705 | if (err) { |
|---|
| 4636 | 4706 | cancel_delayed_work(&fd_timeout); |
|---|
| .. | .. |
|---|
| 4640 | 4710 | |
|---|
| 4641 | 4711 | /* initialise drive state */ |
|---|
| 4642 | 4712 | for (drive = 0; drive < N_DRIVE; drive++) { |
|---|
| 4643 | | - memset(UDRS, 0, sizeof(*UDRS)); |
|---|
| 4644 | | - memset(UDRWE, 0, sizeof(*UDRWE)); |
|---|
| 4645 | | - set_bit(FD_DISK_NEWCHANGE_BIT, &UDRS->flags); |
|---|
| 4646 | | - set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); |
|---|
| 4647 | | - set_bit(FD_VERIFY_BIT, &UDRS->flags); |
|---|
| 4648 | | - UDRS->fd_device = -1; |
|---|
| 4713 | + memset(&drive_state[drive], 0, sizeof(drive_state[drive])); |
|---|
| 4714 | + memset(&write_errors[drive], 0, sizeof(write_errors[drive])); |
|---|
| 4715 | + set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[drive].flags); |
|---|
| 4716 | + set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags); |
|---|
| 4717 | + set_bit(FD_VERIFY_BIT, &drive_state[drive].flags); |
|---|
| 4718 | + drive_state[drive].fd_device = -1; |
|---|
| 4649 | 4719 | floppy_track_buffer = NULL; |
|---|
| 4650 | 4720 | max_buffer_sectors = 0; |
|---|
| 4651 | 4721 | } |
|---|
| .. | .. |
|---|
| 4657 | 4727 | msleep(10); |
|---|
| 4658 | 4728 | |
|---|
| 4659 | 4729 | for (i = 0; i < N_FDC; i++) { |
|---|
| 4660 | | - fdc = i; |
|---|
| 4661 | | - FDCS->driver_version = FD_DRIVER_VERSION; |
|---|
| 4730 | + fdc_state[i].driver_version = FD_DRIVER_VERSION; |
|---|
| 4662 | 4731 | for (unit = 0; unit < 4; unit++) |
|---|
| 4663 | | - FDCS->track[unit] = 0; |
|---|
| 4664 | | - if (FDCS->address == -1) |
|---|
| 4732 | + fdc_state[i].track[unit] = 0; |
|---|
| 4733 | + if (fdc_state[i].address == -1) |
|---|
| 4665 | 4734 | continue; |
|---|
| 4666 | | - FDCS->rawcmd = 2; |
|---|
| 4667 | | - if (user_reset_fdc(-1, FD_RESET_ALWAYS, false)) { |
|---|
| 4735 | + fdc_state[i].rawcmd = 2; |
|---|
| 4736 | + if (user_reset_fdc(REVDRIVE(i, 0), FD_RESET_ALWAYS, false)) { |
|---|
| 4668 | 4737 | /* free ioports reserved by floppy_grab_irq_and_dma() */ |
|---|
| 4669 | | - floppy_release_regions(fdc); |
|---|
| 4670 | | - FDCS->address = -1; |
|---|
| 4671 | | - FDCS->version = FDC_NONE; |
|---|
| 4738 | + floppy_release_regions(i); |
|---|
| 4739 | + fdc_state[i].address = -1; |
|---|
| 4740 | + fdc_state[i].version = FDC_NONE; |
|---|
| 4672 | 4741 | continue; |
|---|
| 4673 | 4742 | } |
|---|
| 4674 | 4743 | /* Try to determine the floppy controller type */ |
|---|
| 4675 | | - FDCS->version = get_fdc_version(); |
|---|
| 4676 | | - if (FDCS->version == FDC_NONE) { |
|---|
| 4744 | + fdc_state[i].version = get_fdc_version(i); |
|---|
| 4745 | + if (fdc_state[i].version == FDC_NONE) { |
|---|
| 4677 | 4746 | /* free ioports reserved by floppy_grab_irq_and_dma() */ |
|---|
| 4678 | | - floppy_release_regions(fdc); |
|---|
| 4679 | | - FDCS->address = -1; |
|---|
| 4747 | + floppy_release_regions(i); |
|---|
| 4748 | + fdc_state[i].address = -1; |
|---|
| 4680 | 4749 | continue; |
|---|
| 4681 | 4750 | } |
|---|
| 4682 | | - if (can_use_virtual_dma == 2 && FDCS->version < FDC_82072A) |
|---|
| 4751 | + if (can_use_virtual_dma == 2 && |
|---|
| 4752 | + fdc_state[i].version < FDC_82072A) |
|---|
| 4683 | 4753 | can_use_virtual_dma = 0; |
|---|
| 4684 | 4754 | |
|---|
| 4685 | 4755 | have_no_fdc = 0; |
|---|
| .. | .. |
|---|
| 4687 | 4757 | * properly, so force a reset for the standard FDC clones, |
|---|
| 4688 | 4758 | * to avoid interrupt garbage. |
|---|
| 4689 | 4759 | */ |
|---|
| 4690 | | - user_reset_fdc(-1, FD_RESET_ALWAYS, false); |
|---|
| 4760 | + user_reset_fdc(REVDRIVE(i, 0), FD_RESET_ALWAYS, false); |
|---|
| 4691 | 4761 | } |
|---|
| 4692 | | - fdc = 0; |
|---|
| 4762 | + current_fdc = 0; |
|---|
| 4693 | 4763 | cancel_delayed_work(&fd_timeout); |
|---|
| 4694 | 4764 | current_drive = 0; |
|---|
| 4695 | 4765 | initialized = true; |
|---|
| .. | .. |
|---|
| 4715 | 4785 | /* to be cleaned up... */ |
|---|
| 4716 | 4786 | disks[drive]->private_data = (void *)(long)drive; |
|---|
| 4717 | 4787 | disks[drive]->flags |= GENHD_FL_REMOVABLE; |
|---|
| 4718 | | - device_add_disk(&floppy_device[drive].dev, disks[drive]); |
|---|
| 4788 | + device_add_disk(&floppy_device[drive].dev, disks[drive], NULL); |
|---|
| 4719 | 4789 | } |
|---|
| 4720 | 4790 | |
|---|
| 4721 | 4791 | return 0; |
|---|
| .. | .. |
|---|
| 4744 | 4814 | del_timer_sync(&motor_off_timer[drive]); |
|---|
| 4745 | 4815 | blk_cleanup_queue(disks[drive]->queue); |
|---|
| 4746 | 4816 | disks[drive]->queue = NULL; |
|---|
| 4817 | + blk_mq_free_tag_set(&tag_sets[drive]); |
|---|
| 4747 | 4818 | } |
|---|
| 4748 | 4819 | put_disk(disks[drive]); |
|---|
| 4749 | 4820 | } |
|---|
| .. | .. |
|---|
| 4784 | 4855 | { |
|---|
| 4785 | 4856 | while (p != io_regions) { |
|---|
| 4786 | 4857 | p--; |
|---|
| 4787 | | - release_region(FDCS->address + p->offset, p->size); |
|---|
| 4858 | + release_region(fdc_state[fdc].address + p->offset, p->size); |
|---|
| 4788 | 4859 | } |
|---|
| 4789 | 4860 | } |
|---|
| 4790 | 4861 | |
|---|
| .. | .. |
|---|
| 4795 | 4866 | const struct io_region *p; |
|---|
| 4796 | 4867 | |
|---|
| 4797 | 4868 | for (p = io_regions; p < ARRAY_END(io_regions); p++) { |
|---|
| 4798 | | - if (!request_region(FDCS->address + p->offset, |
|---|
| 4869 | + if (!request_region(fdc_state[fdc].address + p->offset, |
|---|
| 4799 | 4870 | p->size, "floppy")) { |
|---|
| 4800 | 4871 | DPRINT("Floppy io-port 0x%04lx in use\n", |
|---|
| 4801 | | - FDCS->address + p->offset); |
|---|
| 4872 | + fdc_state[fdc].address + p->offset); |
|---|
| 4802 | 4873 | floppy_release_allocated_regions(fdc, p); |
|---|
| 4803 | 4874 | return -EBUSY; |
|---|
| 4804 | 4875 | } |
|---|
| .. | .. |
|---|
| 4813 | 4884 | |
|---|
| 4814 | 4885 | static int floppy_grab_irq_and_dma(void) |
|---|
| 4815 | 4886 | { |
|---|
| 4887 | + int fdc; |
|---|
| 4888 | + |
|---|
| 4816 | 4889 | if (atomic_inc_return(&usage_count) > 1) |
|---|
| 4817 | 4890 | return 0; |
|---|
| 4818 | 4891 | |
|---|
| .. | .. |
|---|
| 4841 | 4914 | } |
|---|
| 4842 | 4915 | |
|---|
| 4843 | 4916 | for (fdc = 0; fdc < N_FDC; fdc++) { |
|---|
| 4844 | | - if (FDCS->address != -1) { |
|---|
| 4917 | + if (fdc_state[fdc].address != -1) { |
|---|
| 4845 | 4918 | if (floppy_request_regions(fdc)) |
|---|
| 4846 | 4919 | goto cleanup; |
|---|
| 4847 | 4920 | } |
|---|
| 4848 | 4921 | } |
|---|
| 4849 | 4922 | for (fdc = 0; fdc < N_FDC; fdc++) { |
|---|
| 4850 | | - if (FDCS->address != -1) { |
|---|
| 4851 | | - reset_fdc_info(1); |
|---|
| 4852 | | - fd_outb(FDCS->dor, FD_DOR); |
|---|
| 4923 | + if (fdc_state[fdc].address != -1) { |
|---|
| 4924 | + reset_fdc_info(fdc, 1); |
|---|
| 4925 | + fdc_outb(fdc_state[fdc].dor, fdc, FD_DOR); |
|---|
| 4853 | 4926 | } |
|---|
| 4854 | 4927 | } |
|---|
| 4855 | | - fdc = 0; |
|---|
| 4928 | + |
|---|
| 4856 | 4929 | set_dor(0, ~0, 8); /* avoid immediate interrupt */ |
|---|
| 4857 | 4930 | |
|---|
| 4858 | 4931 | for (fdc = 0; fdc < N_FDC; fdc++) |
|---|
| 4859 | | - if (FDCS->address != -1) |
|---|
| 4860 | | - fd_outb(FDCS->dor, FD_DOR); |
|---|
| 4932 | + if (fdc_state[fdc].address != -1) |
|---|
| 4933 | + fdc_outb(fdc_state[fdc].dor, fdc, FD_DOR); |
|---|
| 4861 | 4934 | /* |
|---|
| 4862 | 4935 | * The driver will try and free resources and relies on us |
|---|
| 4863 | 4936 | * to know if they were allocated or not. |
|---|
| 4864 | 4937 | */ |
|---|
| 4865 | | - fdc = 0; |
|---|
| 4938 | + current_fdc = 0; |
|---|
| 4866 | 4939 | irqdma_allocated = 1; |
|---|
| 4867 | 4940 | return 0; |
|---|
| 4868 | 4941 | cleanup: |
|---|
| .. | .. |
|---|
| 4870 | 4943 | fd_free_dma(); |
|---|
| 4871 | 4944 | while (--fdc >= 0) |
|---|
| 4872 | 4945 | floppy_release_regions(fdc); |
|---|
| 4946 | + current_fdc = 0; |
|---|
| 4873 | 4947 | atomic_dec(&usage_count); |
|---|
| 4874 | 4948 | return -1; |
|---|
| 4875 | 4949 | } |
|---|
| 4876 | 4950 | |
|---|
| 4877 | 4951 | static void floppy_release_irq_and_dma(void) |
|---|
| 4878 | 4952 | { |
|---|
| 4879 | | - int old_fdc; |
|---|
| 4953 | + int fdc; |
|---|
| 4880 | 4954 | #ifndef __sparc__ |
|---|
| 4881 | 4955 | int drive; |
|---|
| 4882 | 4956 | #endif |
|---|
| .. | .. |
|---|
| 4917 | 4991 | pr_info("auxiliary floppy timer still active\n"); |
|---|
| 4918 | 4992 | if (work_pending(&floppy_work)) |
|---|
| 4919 | 4993 | pr_info("work still pending\n"); |
|---|
| 4920 | | - old_fdc = fdc; |
|---|
| 4921 | 4994 | for (fdc = 0; fdc < N_FDC; fdc++) |
|---|
| 4922 | | - if (FDCS->address != -1) |
|---|
| 4995 | + if (fdc_state[fdc].address != -1) |
|---|
| 4923 | 4996 | floppy_release_regions(fdc); |
|---|
| 4924 | | - fdc = old_fdc; |
|---|
| 4925 | 4997 | } |
|---|
| 4926 | 4998 | |
|---|
| 4927 | 4999 | #ifdef MODULE |
|---|
| .. | .. |
|---|
| 4971 | 5043 | platform_device_unregister(&floppy_device[drive]); |
|---|
| 4972 | 5044 | } |
|---|
| 4973 | 5045 | blk_cleanup_queue(disks[drive]->queue); |
|---|
| 5046 | + blk_mq_free_tag_set(&tag_sets[drive]); |
|---|
| 4974 | 5047 | |
|---|
| 4975 | 5048 | /* |
|---|
| 4976 | 5049 | * These disks have not called add_disk(). Don't put down |
|---|