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

Merge tag 'for-5.7/drivers-2020-03-29' of git://git.kernel.dk/linux-block

Pull block driver updates from Jens Axboe:

- floppy driver cleanup series from Willy

- NVMe updates and fixes (Various)

- null_blk trace improvements (Chaitanya)

- bcache fixes (Coly)

- md fixes (via Song)

- loop block size change optimizations (Martijn)

- scnprintf() use (Takashi)

* tag 'for-5.7/drivers-2020-03-29' of git://git.kernel.dk/linux-block: (81 commits)
null_blk: add trace in null_blk_zoned.c
null_blk: add tracepoint helpers for zoned mode
block: add a zone condition debug helper
nvme: cleanup namespace identifier reporting in nvme_init_ns_head
nvme: rename __nvme_find_ns_head to nvme_find_ns_head
nvme: refactor nvme_identify_ns_descs error handling
nvme-tcp: Add warning on state change failure at nvme_tcp_setup_ctrl
nvme-rdma: Add warning on state change failure at nvme_rdma_setup_ctrl
nvme: Fix controller creation races with teardown flow
nvme: Make nvme_uninit_ctrl symmetric to nvme_init_ctrl
nvme: Fix ctrl use-after-free during sysfs deletion
nvme-pci: Re-order nvme_pci_free_ctrl
nvme: Remove unused return code from nvme_delete_ctrl_sync
nvme: Use nvme_state_terminal helper
nvme: release ida resources
nvme: Add compat_ioctl handler for NVME_IOCTL_SUBMIT_IO
nvmet-tcp: optimize tcp stack TX when data digest is used
nvme-fabrics: Use scnprintf() for avoiding potential buffer overflow
nvme-multipath: do not reset on unknown status
nvmet-rdma: allocate RW ctxs according to mdts
...

+1773 -975
+13 -75
arch/arm/include/asm/floppy.h
··· 8 8 */ 9 9 #ifndef __ASM_ARM_FLOPPY_H 10 10 #define __ASM_ARM_FLOPPY_H 11 - #if 0 12 - #include <mach/floppy.h> 13 - #endif 14 11 15 - #define fd_outb(val,port) \ 16 - do { \ 17 - if ((port) == (u32)FD_DOR) \ 18 - fd_setdor((val)); \ 19 - else \ 20 - outb((val),(port)); \ 12 + #define fd_outb(val,port) \ 13 + do { \ 14 + int new_val = (val); \ 15 + if (((port) & 7) == FD_DOR) { \ 16 + if (new_val & 0xf0) \ 17 + new_val = (new_val & 0x0c) | \ 18 + floppy_selects[new_val & 3]; \ 19 + else \ 20 + new_val &= 0x0c; \ 21 + } \ 22 + outb(new_val, (port)); \ 21 23 } while(0) 22 24 23 25 #define fd_inb(port) inb((port)) ··· 55 53 * to a non-zero track, and then restoring it to track 0. If an error occurs, 56 54 * then there is no floppy drive present. [to be put back in again] 57 55 */ 58 - static unsigned char floppy_selects[2][4] = 59 - { 60 - { 0x10, 0x21, 0x23, 0x33 }, 61 - { 0x10, 0x21, 0x23, 0x33 } 62 - }; 63 - 64 - #define fd_setdor(dor) \ 65 - do { \ 66 - int new_dor = (dor); \ 67 - if (new_dor & 0xf0) \ 68 - new_dor = (new_dor & 0x0c) | floppy_selects[fdc][new_dor & 3]; \ 69 - else \ 70 - new_dor &= 0x0c; \ 71 - outb(new_dor, FD_DOR); \ 72 - } while (0) 73 - 74 - /* 75 - * Someday, we'll automatically detect which drives are present... 76 - */ 77 - static inline void fd_scandrives (void) 78 - { 79 - #if 0 80 - int floppy, drive_count; 81 - 82 - fd_disable_irq(); 83 - raw_cmd = &default_raw_cmd; 84 - raw_cmd->flags = FD_RAW_SPIN | FD_RAW_NEED_SEEK; 85 - raw_cmd->track = 0; 86 - raw_cmd->rate = ?; 87 - drive_count = 0; 88 - for (floppy = 0; floppy < 4; floppy ++) { 89 - current_drive = drive_count; 90 - /* 91 - * Turn on floppy motor 92 - */ 93 - if (start_motor(redo_fd_request)) 94 - continue; 95 - /* 96 - * Set up FDC 97 - */ 98 - fdc_specify(); 99 - /* 100 - * Tell FDC to recalibrate 101 - */ 102 - output_byte(FD_RECALIBRATE); 103 - LAST_OUT(UNIT(floppy)); 104 - /* wait for command to complete */ 105 - if (!successful) { 106 - int i; 107 - for (i = drive_count; i < 3; i--) 108 - floppy_selects[fdc][i] = floppy_selects[fdc][i + 1]; 109 - floppy_selects[fdc][3] = 0; 110 - floppy -= 1; 111 - } else 112 - drive_count++; 113 - } 114 - #else 115 - floppy_selects[0][0] = 0x10; 116 - floppy_selects[0][1] = 0x21; 117 - floppy_selects[0][2] = 0x23; 118 - floppy_selects[0][3] = 0x33; 119 - #endif 120 - } 56 + static unsigned char floppy_selects[4] = { 0x10, 0x21, 0x23, 0x33 }; 121 57 122 58 #define FDC1 (0x3f0) 123 59 ··· 75 135 */ 76 136 static void driveswap(int *ints, int dummy, int dummy2) 77 137 { 78 - floppy_selects[0][0] ^= floppy_selects[0][1]; 79 - floppy_selects[0][1] ^= floppy_selects[0][0]; 80 - floppy_selects[0][0] ^= floppy_selects[0][1]; 138 + swap(floppy_selects[0], floppy_selects[1]); 81 139 } 82 140 83 141 #define EXTRA_FLOPPY_PARAMS ,{ "driveswap", &driveswap, NULL, 0, 0 }
+3
block/blk-settings.c
··· 628 628 printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n", 629 629 top, bottom); 630 630 } 631 + 632 + t->backing_dev_info->io_pages = 633 + t->limits.max_sectors >> (PAGE_SHIFT - 9); 631 634 } 632 635 EXPORT_SYMBOL(disk_stack_limits); 633 636
+32
block/blk-zoned.c
··· 20 20 21 21 #include "blk.h" 22 22 23 + #define ZONE_COND_NAME(name) [BLK_ZONE_COND_##name] = #name 24 + static const char *const zone_cond_name[] = { 25 + ZONE_COND_NAME(NOT_WP), 26 + ZONE_COND_NAME(EMPTY), 27 + ZONE_COND_NAME(IMP_OPEN), 28 + ZONE_COND_NAME(EXP_OPEN), 29 + ZONE_COND_NAME(CLOSED), 30 + ZONE_COND_NAME(READONLY), 31 + ZONE_COND_NAME(FULL), 32 + ZONE_COND_NAME(OFFLINE), 33 + }; 34 + #undef ZONE_COND_NAME 35 + 36 + /** 37 + * blk_zone_cond_str - Return string XXX in BLK_ZONE_COND_XXX. 38 + * @zone_cond: BLK_ZONE_COND_XXX. 39 + * 40 + * Description: Centralize block layer function to convert BLK_ZONE_COND_XXX 41 + * into string format. Useful in the debugging and tracing zone conditions. For 42 + * invalid BLK_ZONE_COND_XXX it returns string "UNKNOWN". 43 + */ 44 + const char *blk_zone_cond_str(enum blk_zone_cond zone_cond) 45 + { 46 + static const char *zone_cond_str = "UNKNOWN"; 47 + 48 + if (zone_cond < ARRAY_SIZE(zone_cond_name) && zone_cond_name[zone_cond]) 49 + zone_cond_str = zone_cond_name[zone_cond]; 50 + 51 + return zone_cond_str; 52 + } 53 + EXPORT_SYMBOL_GPL(blk_zone_cond_str); 54 + 23 55 static inline sector_t blk_zone_start(struct request_queue *q, 24 56 sector_t sector) 25 57 {
+6
drivers/block/Makefile
··· 6 6 # Rewritten to use lists instead of if-statements. 7 7 # 8 8 9 + # needed for trace events 10 + ccflags-y += -I$(src) 11 + 9 12 obj-$(CONFIG_MAC_FLOPPY) += swim3.o 10 13 obj-$(CONFIG_BLK_DEV_SWIM) += swim_mod.o 11 14 obj-$(CONFIG_BLK_DEV_FD) += floppy.o ··· 42 39 43 40 obj-$(CONFIG_BLK_DEV_NULL_BLK) += null_blk.o 44 41 null_blk-objs := null_blk_main.o 42 + ifeq ($(CONFIG_BLK_DEV_ZONED), y) 43 + null_blk-$(CONFIG_TRACING) += null_blk_trace.o 44 + endif 45 45 null_blk-$(CONFIG_BLK_DEV_ZONED) += null_blk_zoned.o 46 46 47 47 skd-y := skd_main.o
+2 -2
drivers/block/aoe/aoeblk.c
··· 87 87 if (*nd == NULL) 88 88 return snprintf(page, PAGE_SIZE, "none\n"); 89 89 for (p = page; nd < ne; nd++) 90 - p += snprintf(p, PAGE_SIZE - (p-page), "%s%s", 90 + p += scnprintf(p, PAGE_SIZE - (p-page), "%s%s", 91 91 p == page ? "" : ",", (*nd)->name); 92 - p += snprintf(p, PAGE_SIZE - (p-page), "\n"); 92 + p += scnprintf(p, PAGE_SIZE - (p-page), "\n"); 93 93 return p-page; 94 94 } 95 95 /* firmware version */
-11
drivers/block/drbd/drbd_main.c
··· 3413 3413 * the meta-data super block. This function sets MD_DIRTY, and starts a 3414 3414 * timer that ensures that within five seconds you have to call drbd_md_sync(). 3415 3415 */ 3416 - #ifdef DEBUG 3417 - void drbd_md_mark_dirty_(struct drbd_device *device, unsigned int line, const char *func) 3418 - { 3419 - if (!test_and_set_bit(MD_DIRTY, &device->flags)) { 3420 - mod_timer(&device->md_sync_timer, jiffies + HZ); 3421 - device->last_md_mark_dirty.line = line; 3422 - device->last_md_mark_dirty.func = func; 3423 - } 3424 - } 3425 - #else 3426 3416 void drbd_md_mark_dirty(struct drbd_device *device) 3427 3417 { 3428 3418 if (!test_and_set_bit(MD_DIRTY, &device->flags)) 3429 3419 mod_timer(&device->md_sync_timer, jiffies + 5*HZ); 3430 3420 } 3431 - #endif 3432 3421 3433 3422 void drbd_uuid_move_history(struct drbd_device *device) __must_hold(local) 3434 3423 {
+567 -524
drivers/block/floppy.c
··· 171 171 #include <linux/kernel.h> 172 172 #include <linux/timer.h> 173 173 #include <linux/workqueue.h> 174 - #define FDPATCHES 175 174 #include <linux/fdreg.h> 176 175 #include <linux/fd.h> 177 176 #include <linux/hdreg.h> ··· 305 306 /* reverse mapping from unit and fdc to drive */ 306 307 #define REVDRIVE(fdc, unit) ((unit) + ((fdc) << 2)) 307 308 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 309 #define PH_HEAD(floppy, head) (((((floppy)->stretch & 2) >> 1) ^ head) << 2) 319 310 #define STRETCH(floppy) ((floppy)->stretch & FD_STRETCH) 320 311 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]) 312 + /* read/write commands */ 313 + #define COMMAND 0 314 + #define DR_SELECT 1 315 + #define TRACK 2 316 + #define HEAD 3 317 + #define SECTOR 4 318 + #define SIZECODE 5 319 + #define SECT_PER_TRACK 6 320 + #define GAP 7 321 + #define SIZECODE2 8 331 322 #define NR_RW 9 332 323 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]) 324 + /* format commands */ 325 + #define F_SIZECODE 2 326 + #define F_SECT_PER_TRACK 3 327 + #define F_GAP 4 328 + #define F_FILL 5 338 329 #define NR_F 6 339 330 340 331 /* ··· 340 351 #define MAX_REPLIES 16 341 352 static unsigned char reply_buffer[MAX_REPLIES]; 342 353 static int inr; /* size of reply buffer, when called from interrupt */ 343 - #define ST0 (reply_buffer[0]) 344 - #define ST1 (reply_buffer[1]) 345 - #define ST2 (reply_buffer[2]) 346 - #define ST3 (reply_buffer[0]) /* result of GETSTATUS */ 347 - #define R_TRACK (reply_buffer[3]) 348 - #define R_HEAD (reply_buffer[4]) 349 - #define R_SECTOR (reply_buffer[5]) 350 - #define R_SIZECODE (reply_buffer[6]) 354 + #define ST0 0 355 + #define ST1 1 356 + #define ST2 2 357 + #define ST3 0 /* result of GETSTATUS */ 358 + #define R_TRACK 3 359 + #define R_HEAD 4 360 + #define R_SECTOR 5 361 + #define R_SIZECODE 6 351 362 352 363 #define SEL_DLY (2 * HZ / 100) 353 364 ··· 582 593 583 594 /* fdc related variables, should end up in a struct */ 584 595 static struct floppy_fdc_state fdc_state[N_FDC]; 585 - static int fdc; /* current fdc */ 596 + static int current_fdc; /* current fdc */ 586 597 587 598 static struct workqueue_struct *floppy_wq; 588 599 ··· 593 604 static unsigned char in_sector_offset; /* offset within physical sector, 594 605 * expressed in units of 512 bytes */ 595 606 607 + static inline unsigned char fdc_inb(int fdc, int reg) 608 + { 609 + return fd_inb(fdc_state[fdc].address + reg); 610 + } 611 + 612 + static inline void fdc_outb(unsigned char value, int fdc, int reg) 613 + { 614 + fd_outb(value, fdc_state[fdc].address + reg); 615 + } 616 + 596 617 static inline bool drive_no_geom(int drive) 597 618 { 598 - return !current_type[drive] && !ITYPE(UDRS->fd_device); 619 + return !current_type[drive] && !ITYPE(drive_state[drive].fd_device); 599 620 } 600 621 601 622 #ifndef fd_eject ··· 629 630 630 631 static inline void debugt(const char *func, const char *msg) 631 632 { 632 - if (DP->flags & DEBUGT) 633 + if (drive_params[current_drive].flags & DEBUGT) 633 634 pr_info("%s:%s dtime=%lu\n", func, msg, jiffies - debugtimer); 634 635 } 635 636 #else ··· 682 683 delay = 20UL * HZ; 683 684 drive = 0; 684 685 } else 685 - delay = UDP->timeout; 686 + delay = drive_params[drive].timeout; 686 687 687 688 mod_delayed_work(floppy_wq, &fd_timeout, delay); 688 - if (UDP->flags & FD_DEBUG) 689 + if (drive_params[drive].flags & FD_DEBUG) 689 690 DPRINT("reschedule timeout %s\n", message); 690 691 timeout_message = message; 691 692 } ··· 739 740 { 740 741 int fdc = FDC(drive); 741 742 742 - if (time_before(jiffies, UDRS->select_date + UDP->select_delay)) 743 + if (time_before(jiffies, drive_state[drive].select_date + drive_params[drive].select_delay)) 743 744 DPRINT("WARNING disk change called early\n"); 744 - if (!(FDCS->dor & (0x10 << UNIT(drive))) || 745 - (FDCS->dor & 3) != UNIT(drive) || fdc != FDC(drive)) { 745 + if (!(fdc_state[fdc].dor & (0x10 << UNIT(drive))) || 746 + (fdc_state[fdc].dor & 3) != UNIT(drive) || fdc != FDC(drive)) { 746 747 DPRINT("probing disk change on unselected drive\n"); 747 748 DPRINT("drive=%d fdc=%d dor=%x\n", drive, FDC(drive), 748 - (unsigned int)FDCS->dor); 749 + (unsigned int)fdc_state[fdc].dor); 749 750 } 750 751 751 - debug_dcl(UDP->flags, 752 + debug_dcl(drive_params[drive].flags, 752 753 "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); 754 + debug_dcl(drive_params[drive].flags, "jiffies=%lu\n", jiffies); 755 + debug_dcl(drive_params[drive].flags, "disk change line=%x\n", 756 + fdc_inb(fdc, FD_DIR) & 0x80); 757 + debug_dcl(drive_params[drive].flags, "flags=%lx\n", 758 + drive_state[drive].flags); 756 759 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); 760 + if (drive_params[drive].flags & FD_BROKEN_DCL) 761 + return test_bit(FD_DISK_CHANGED_BIT, 762 + &drive_state[drive].flags); 763 + if ((fdc_inb(fdc, FD_DIR) ^ drive_params[drive].flags) & 0x80) { 764 + set_bit(FD_VERIFY_BIT, &drive_state[drive].flags); 761 765 /* verify write protection */ 762 766 763 - if (UDRS->maxblock) /* mark it changed */ 764 - set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); 767 + if (drive_state[drive].maxblock) /* mark it changed */ 768 + set_bit(FD_DISK_CHANGED_BIT, 769 + &drive_state[drive].flags); 765 770 766 771 /* invalidate its geometry */ 767 - if (UDRS->keep_data >= 0) { 768 - if ((UDP->flags & FTD_MSG) && 772 + if (drive_state[drive].keep_data >= 0) { 773 + if ((drive_params[drive].flags & FTD_MSG) && 769 774 current_type[drive] != NULL) 770 775 DPRINT("Disk type is undefined after disk change\n"); 771 776 current_type[drive] = NULL; ··· 778 775 779 776 return 1; 780 777 } else { 781 - UDRS->last_checked = jiffies; 782 - clear_bit(FD_DISK_NEWCHANGE_BIT, &UDRS->flags); 778 + drive_state[drive].last_checked = jiffies; 779 + clear_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[drive].flags); 783 780 } 784 781 return 0; 785 782 } ··· 802 799 unsigned char newdor; 803 800 unsigned char olddor; 804 801 805 - if (FDCS->address == -1) 802 + if (fdc_state[fdc].address == -1) 806 803 return -1; 807 804 808 - olddor = FDCS->dor; 805 + olddor = fdc_state[fdc].dor; 809 806 newdor = (olddor & mask) | data; 810 807 if (newdor != olddor) { 811 808 unit = olddor & 0x3; 812 809 if (is_selected(olddor, unit) && !is_selected(newdor, unit)) { 813 810 drive = REVDRIVE(fdc, unit); 814 - debug_dcl(UDP->flags, 811 + debug_dcl(drive_params[drive].flags, 815 812 "calling disk change from set_dor\n"); 816 813 disk_change(drive); 817 814 } 818 - FDCS->dor = newdor; 819 - fd_outb(newdor, FD_DOR); 815 + fdc_state[fdc].dor = newdor; 816 + fdc_outb(newdor, fdc, FD_DOR); 820 817 821 818 unit = newdor & 0x3; 822 819 if (!is_selected(olddor, unit) && is_selected(newdor, unit)) { 823 820 drive = REVDRIVE(fdc, unit); 824 - UDRS->select_date = jiffies; 821 + drive_state[drive].select_date = jiffies; 825 822 } 826 823 } 827 824 return olddor; ··· 829 826 830 827 static void twaddle(void) 831 828 { 832 - if (DP->select_delay) 829 + if (drive_params[current_drive].select_delay) 833 830 return; 834 - fd_outb(FDCS->dor & ~(0x10 << UNIT(current_drive)), FD_DOR); 835 - fd_outb(FDCS->dor, FD_DOR); 836 - DRS->select_date = jiffies; 831 + fdc_outb(fdc_state[current_fdc].dor & ~(0x10 << UNIT(current_drive)), 832 + current_fdc, FD_DOR); 833 + fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR); 834 + drive_state[current_drive].select_date = jiffies; 837 835 } 838 836 839 837 /* ··· 845 841 { 846 842 int drive; 847 843 848 - FDCS->spec1 = FDCS->spec2 = -1; 849 - FDCS->need_configure = 1; 850 - FDCS->perp_mode = 1; 851 - FDCS->rawcmd = 0; 844 + fdc_state[current_fdc].spec1 = fdc_state[current_fdc].spec2 = -1; 845 + fdc_state[current_fdc].need_configure = 1; 846 + fdc_state[current_fdc].perp_mode = 1; 847 + fdc_state[current_fdc].rawcmd = 0; 852 848 for (drive = 0; drive < N_DRIVE; drive++) 853 - if (FDC(drive) == fdc && (mode || UDRS->track != NEED_1_RECAL)) 854 - UDRS->track = NEED_2_RECAL; 849 + if (FDC(drive) == current_fdc && 850 + (mode || drive_state[drive].track != NEED_1_RECAL)) 851 + drive_state[drive].track = NEED_2_RECAL; 855 852 } 856 853 857 854 /* selects the fdc and drive, and enables the fdc's input/dma. */ 858 855 static void set_fdc(int drive) 859 856 { 860 - unsigned int new_fdc = fdc; 857 + unsigned int new_fdc = current_fdc; 861 858 862 859 if (drive >= 0 && drive < N_DRIVE) { 863 860 new_fdc = FDC(drive); ··· 868 863 pr_info("bad fdc value\n"); 869 864 return; 870 865 } 871 - fdc = new_fdc; 872 - set_dor(fdc, ~0, 8); 866 + current_fdc = new_fdc; 867 + set_dor(current_fdc, ~0, 8); 873 868 #if N_FDC > 1 874 - set_dor(1 - fdc, ~8, 0); 869 + set_dor(1 - current_fdc, ~8, 0); 875 870 #endif 876 - if (FDCS->rawcmd == 2) 871 + if (fdc_state[current_fdc].rawcmd == 2) 877 872 reset_fdc_info(1); 878 - if (fd_inb(FD_STATUS) != STATUS_READY) 879 - FDCS->reset = 1; 873 + if (fdc_inb(current_fdc, FD_STATUS) != STATUS_READY) 874 + fdc_state[current_fdc].reset = 1; 880 875 } 881 876 882 877 /* locks the driver */ ··· 929 924 unsigned long volatile delta; 930 925 int fdc = FDC(drive); 931 926 932 - if (!(FDCS->dor & (0x10 << UNIT(drive)))) 927 + if (!(fdc_state[fdc].dor & (0x10 << UNIT(drive)))) 933 928 return; 934 929 935 930 del_timer(motor_off_timer + drive); 936 931 937 932 /* make spindle stop in a position which minimizes spinup time 938 933 * next time */ 939 - if (UDP->rps) { 940 - delta = jiffies - UDRS->first_read_date + HZ - 941 - UDP->spindown_offset; 942 - delta = ((delta * UDP->rps) % HZ) / UDP->rps; 934 + if (drive_params[drive].rps) { 935 + delta = jiffies - drive_state[drive].first_read_date + HZ - 936 + drive_params[drive].spindown_offset; 937 + delta = ((delta * drive_params[drive].rps) % HZ) / drive_params[drive].rps; 943 938 motor_off_timer[drive].expires = 944 - jiffies + UDP->spindown - delta; 939 + jiffies + drive_params[drive].spindown - delta; 945 940 } 946 941 add_timer(motor_off_timer + drive); 947 942 } ··· 957 952 int drive; 958 953 int saved_drive; 959 954 960 - if (DP->select_delay) 955 + if (drive_params[current_drive].select_delay) 961 956 return; 962 957 963 958 saved_drive = current_drive; 964 959 for (i = 0; i < N_DRIVE; i++) { 965 960 drive = (saved_drive + i + 1) % N_DRIVE; 966 - if (UDRS->fd_ref == 0 || UDP->select_delay != 0) 961 + if (drive_state[drive].fd_ref == 0 || drive_params[drive].select_delay != 0) 967 962 continue; /* skip closed drives */ 968 963 set_fdc(drive); 969 - if (!(set_dor(fdc, ~3, UNIT(drive) | (0x10 << UNIT(drive))) & 964 + if (!(set_dor(current_fdc, ~3, UNIT(drive) | (0x10 << UNIT(drive))) & 970 965 (0x10 << UNIT(drive)))) 971 966 /* switch the motor off again, if it was off to 972 967 * begin with */ 973 - set_dor(fdc, ~(0x10 << UNIT(drive)), 0); 968 + set_dor(current_fdc, ~(0x10 << UNIT(drive)), 0); 974 969 } 975 970 set_fdc(saved_drive); 976 971 } ··· 1016 1011 * transfer */ 1017 1012 static void fd_watchdog(void) 1018 1013 { 1019 - debug_dcl(DP->flags, "calling disk change from watchdog\n"); 1014 + debug_dcl(drive_params[current_drive].flags, 1015 + "calling disk change from watchdog\n"); 1020 1016 1021 1017 if (disk_change(current_drive)) { 1022 1018 DPRINT("disk removed during i/o\n"); ··· 1041 1035 static int fd_wait_for_completion(unsigned long expires, 1042 1036 void (*function)(void)) 1043 1037 { 1044 - if (FDCS->reset) { 1038 + if (fdc_state[current_fdc].reset) { 1045 1039 reset_fdc(); /* do the reset during sleep to win time 1046 1040 * if we don't need to sleep, it's a good 1047 1041 * occasion anyways */ ··· 1069 1063 pr_cont("%x,", raw_cmd->cmd[i]); 1070 1064 pr_cont("\n"); 1071 1065 cont->done(0); 1072 - FDCS->reset = 1; 1066 + fdc_state[current_fdc].reset = 1; 1073 1067 return; 1074 1068 } 1075 1069 if (((unsigned long)raw_cmd->kernel_data) % 512) { 1076 1070 pr_info("non aligned address: %p\n", raw_cmd->kernel_data); 1077 1071 cont->done(0); 1078 - FDCS->reset = 1; 1072 + fdc_state[current_fdc].reset = 1; 1079 1073 return; 1080 1074 } 1081 1075 f = claim_dma_lock(); ··· 1083 1077 #ifdef fd_dma_setup 1084 1078 if (fd_dma_setup(raw_cmd->kernel_data, raw_cmd->length, 1085 1079 (raw_cmd->flags & FD_RAW_READ) ? 1086 - DMA_MODE_READ : DMA_MODE_WRITE, FDCS->address) < 0) { 1080 + DMA_MODE_READ : DMA_MODE_WRITE, 1081 + fdc_state[current_fdc].address) < 0) { 1087 1082 release_dma_lock(f); 1088 1083 cont->done(0); 1089 - FDCS->reset = 1; 1084 + fdc_state[current_fdc].reset = 1; 1090 1085 return; 1091 1086 } 1092 1087 release_dma_lock(f); ··· 1098 1091 DMA_MODE_READ : DMA_MODE_WRITE); 1099 1092 fd_set_dma_addr(raw_cmd->kernel_data); 1100 1093 fd_set_dma_count(raw_cmd->length); 1101 - virtual_dma_port = FDCS->address; 1094 + virtual_dma_port = fdc_state[current_fdc].address; 1102 1095 fd_enable_dma(); 1103 1096 release_dma_lock(f); 1104 1097 #endif ··· 1112 1105 int status; 1113 1106 int counter; 1114 1107 1115 - if (FDCS->reset) 1108 + if (fdc_state[current_fdc].reset) 1116 1109 return -1; 1117 1110 for (counter = 0; counter < 10000; counter++) { 1118 - status = fd_inb(FD_STATUS); 1111 + status = fdc_inb(current_fdc, FD_STATUS); 1119 1112 if (status & STATUS_READY) 1120 1113 return status; 1121 1114 } 1122 1115 if (initialized) { 1123 - DPRINT("Getstatus times out (%x) on fdc %d\n", status, fdc); 1116 + DPRINT("Getstatus times out (%x) on fdc %d\n", status, current_fdc); 1124 1117 show_floppy(); 1125 1118 } 1126 - FDCS->reset = 1; 1119 + fdc_state[current_fdc].reset = 1; 1127 1120 return -1; 1128 1121 } 1129 1122 ··· 1136 1129 return -1; 1137 1130 1138 1131 if (is_ready_state(status)) { 1139 - fd_outb(byte, FD_DATA); 1132 + fdc_outb(byte, current_fdc, FD_DATA); 1140 1133 output_log[output_log_pos].data = byte; 1141 1134 output_log[output_log_pos].status = status; 1142 1135 output_log[output_log_pos].jiffies = jiffies; 1143 1136 output_log_pos = (output_log_pos + 1) % OLOGSIZE; 1144 1137 return 0; 1145 1138 } 1146 - FDCS->reset = 1; 1139 + fdc_state[current_fdc].reset = 1; 1147 1140 if (initialized) { 1148 1141 DPRINT("Unable to send byte %x to FDC. Fdc=%x Status=%x\n", 1149 - byte, fdc, status); 1142 + byte, current_fdc, status); 1150 1143 show_floppy(); 1151 1144 } 1152 1145 return -1; ··· 1169 1162 return i; 1170 1163 } 1171 1164 if (status == (STATUS_DIR | STATUS_READY | STATUS_BUSY)) 1172 - reply_buffer[i] = fd_inb(FD_DATA); 1165 + reply_buffer[i] = fdc_inb(current_fdc, FD_DATA); 1173 1166 else 1174 1167 break; 1175 1168 } 1176 1169 if (initialized) { 1177 1170 DPRINT("get result error. Fdc=%d Last status=%x Read bytes=%d\n", 1178 - fdc, status, i); 1171 + current_fdc, status, i); 1179 1172 show_floppy(); 1180 1173 } 1181 - FDCS->reset = 1; 1174 + fdc_state[current_fdc].reset = 1; 1182 1175 return -1; 1183 1176 } 1184 1177 ··· 1215 1208 default: 1216 1209 DPRINT("Invalid data rate for perpendicular mode!\n"); 1217 1210 cont->done(0); 1218 - FDCS->reset = 1; 1211 + fdc_state[current_fdc].reset = 1; 1219 1212 /* 1220 1213 * convenient way to return to 1221 1214 * redo without too much hassle ··· 1226 1219 } else 1227 1220 perp_mode = 0; 1228 1221 1229 - if (FDCS->perp_mode == perp_mode) 1222 + if (fdc_state[current_fdc].perp_mode == perp_mode) 1230 1223 return; 1231 - if (FDCS->version >= FDC_82077_ORIG) { 1224 + if (fdc_state[current_fdc].version >= FDC_82077_ORIG) { 1232 1225 output_byte(FD_PERPENDICULAR); 1233 1226 output_byte(perp_mode); 1234 - FDCS->perp_mode = perp_mode; 1227 + fdc_state[current_fdc].perp_mode = perp_mode; 1235 1228 } else if (perp_mode) { 1236 1229 DPRINT("perpendicular mode not supported by this FDC.\n"); 1237 1230 } ··· 1286 1279 int hlt_max_code = 0x7f; 1287 1280 int hut_max_code = 0xf; 1288 1281 1289 - if (FDCS->need_configure && FDCS->version >= FDC_82072A) { 1282 + if (fdc_state[current_fdc].need_configure && 1283 + fdc_state[current_fdc].version >= FDC_82072A) { 1290 1284 fdc_configure(); 1291 - FDCS->need_configure = 0; 1285 + fdc_state[current_fdc].need_configure = 0; 1292 1286 } 1293 1287 1294 1288 switch (raw_cmd->rate & 0x03) { ··· 1298 1290 break; 1299 1291 case 1: 1300 1292 dtr = 300; 1301 - if (FDCS->version >= FDC_82078) { 1293 + if (fdc_state[current_fdc].version >= FDC_82078) { 1302 1294 /* chose the default rate table, not the one 1303 1295 * where 1 = 2 Mbps */ 1304 1296 output_byte(FD_DRIVESPEC); ··· 1313 1305 break; 1314 1306 } 1315 1307 1316 - if (FDCS->version >= FDC_82072) { 1308 + if (fdc_state[current_fdc].version >= FDC_82072) { 1317 1309 scale_dtr = dtr; 1318 1310 hlt_max_code = 0x00; /* 0==256msec*dtr0/dtr (not linear!) */ 1319 1311 hut_max_code = 0x0; /* 0==256msec*dtr0/dtr (not linear!) */ 1320 1312 } 1321 1313 1322 1314 /* Convert step rate from microseconds to milliseconds and 4 bits */ 1323 - srt = 16 - DIV_ROUND_UP(DP->srt * scale_dtr / 1000, NOMINAL_DTR); 1315 + srt = 16 - DIV_ROUND_UP(drive_params[current_drive].srt * scale_dtr / 1000, 1316 + NOMINAL_DTR); 1324 1317 if (slow_floppy) 1325 1318 srt = srt / 4; 1326 1319 1327 1320 SUPBOUND(srt, 0xf); 1328 1321 INFBOUND(srt, 0); 1329 1322 1330 - hlt = DIV_ROUND_UP(DP->hlt * scale_dtr / 2, NOMINAL_DTR); 1323 + hlt = DIV_ROUND_UP(drive_params[current_drive].hlt * scale_dtr / 2, 1324 + NOMINAL_DTR); 1331 1325 if (hlt < 0x01) 1332 1326 hlt = 0x01; 1333 1327 else if (hlt > 0x7f) 1334 1328 hlt = hlt_max_code; 1335 1329 1336 - hut = DIV_ROUND_UP(DP->hut * scale_dtr / 16, NOMINAL_DTR); 1330 + hut = DIV_ROUND_UP(drive_params[current_drive].hut * scale_dtr / 16, 1331 + NOMINAL_DTR); 1337 1332 if (hut < 0x1) 1338 1333 hut = 0x1; 1339 1334 else if (hut > 0xf) ··· 1346 1335 spec2 = (hlt << 1) | (use_virtual_dma & 1); 1347 1336 1348 1337 /* If these parameters did not change, just return with success */ 1349 - if (FDCS->spec1 != spec1 || FDCS->spec2 != spec2) { 1338 + if (fdc_state[current_fdc].spec1 != spec1 || 1339 + fdc_state[current_fdc].spec2 != spec2) { 1350 1340 /* Go ahead and set spec1 and spec2 */ 1351 1341 output_byte(FD_SPECIFY); 1352 - output_byte(FDCS->spec1 = spec1); 1353 - output_byte(FDCS->spec2 = spec2); 1342 + output_byte(fdc_state[current_fdc].spec1 = spec1); 1343 + output_byte(fdc_state[current_fdc].spec2 = spec2); 1354 1344 } 1355 1345 } /* fdc_specify */ 1356 1346 ··· 1362 1350 static int fdc_dtr(void) 1363 1351 { 1364 1352 /* If data rate not already set to desired value, set it. */ 1365 - if ((raw_cmd->rate & 3) == FDCS->dtr) 1353 + if ((raw_cmd->rate & 3) == fdc_state[current_fdc].dtr) 1366 1354 return 0; 1367 1355 1368 1356 /* Set dtr */ 1369 - fd_outb(raw_cmd->rate & 3, FD_DCR); 1357 + fdc_outb(raw_cmd->rate & 3, current_fdc, FD_DCR); 1370 1358 1371 1359 /* TODO: some FDC/drive combinations (C&T 82C711 with TEAC 1.2MB) 1372 1360 * need a stabilization period of several milliseconds to be 1373 1361 * enforced after data rate changes before R/W operations. 1374 1362 * Pause 5 msec to avoid trouble. (Needs to be 2 jiffies) 1375 1363 */ 1376 - FDCS->dtr = raw_cmd->rate & 3; 1364 + fdc_state[current_fdc].dtr = raw_cmd->rate & 3; 1377 1365 return fd_wait_for_completion(jiffies + 2UL * HZ / 100, floppy_ready); 1378 1366 } /* fdc_dtr */ 1379 1367 1380 1368 static void tell_sector(void) 1381 1369 { 1382 1370 pr_cont(": track %d, head %d, sector %d, size %d", 1383 - R_TRACK, R_HEAD, R_SECTOR, R_SIZECODE); 1371 + reply_buffer[R_TRACK], reply_buffer[R_HEAD], 1372 + reply_buffer[R_SECTOR], 1373 + reply_buffer[R_SIZECODE]); 1384 1374 } /* tell_sector */ 1385 1375 1386 1376 static void print_errors(void) 1387 1377 { 1388 1378 DPRINT(""); 1389 - if (ST0 & ST0_ECE) { 1379 + if (reply_buffer[ST0] & ST0_ECE) { 1390 1380 pr_cont("Recalibrate failed!"); 1391 - } else if (ST2 & ST2_CRC) { 1381 + } else if (reply_buffer[ST2] & ST2_CRC) { 1392 1382 pr_cont("data CRC error"); 1393 1383 tell_sector(); 1394 - } else if (ST1 & ST1_CRC) { 1384 + } else if (reply_buffer[ST1] & ST1_CRC) { 1395 1385 pr_cont("CRC error"); 1396 1386 tell_sector(); 1397 - } else if ((ST1 & (ST1_MAM | ST1_ND)) || 1398 - (ST2 & ST2_MAM)) { 1387 + } else if ((reply_buffer[ST1] & (ST1_MAM | ST1_ND)) || 1388 + (reply_buffer[ST2] & ST2_MAM)) { 1399 1389 if (!probing) { 1400 1390 pr_cont("sector not found"); 1401 1391 tell_sector(); 1402 1392 } else 1403 1393 pr_cont("probe failed..."); 1404 - } else if (ST2 & ST2_WC) { /* seek error */ 1394 + } else if (reply_buffer[ST2] & ST2_WC) { /* seek error */ 1405 1395 pr_cont("wrong cylinder"); 1406 - } else if (ST2 & ST2_BC) { /* cylinder marked as bad */ 1396 + } else if (reply_buffer[ST2] & ST2_BC) { /* cylinder marked as bad */ 1407 1397 pr_cont("bad cylinder"); 1408 1398 } else { 1409 1399 pr_cont("unknown error. ST[0..2] are: 0x%x 0x%x 0x%x", 1410 - ST0, ST1, ST2); 1400 + reply_buffer[ST0], reply_buffer[ST1], 1401 + reply_buffer[ST2]); 1411 1402 tell_sector(); 1412 1403 } 1413 1404 pr_cont("\n"); ··· 1429 1414 1430 1415 if (inr != 7) { 1431 1416 DPRINT("-- FDC reply error\n"); 1432 - FDCS->reset = 1; 1417 + fdc_state[current_fdc].reset = 1; 1433 1418 return 1; 1434 1419 } 1435 1420 1436 1421 /* check IC to find cause of interrupt */ 1437 - switch (ST0 & ST0_INTR) { 1422 + switch (reply_buffer[ST0] & ST0_INTR) { 1438 1423 case 0x40: /* error occurred during command execution */ 1439 - if (ST1 & ST1_EOC) 1424 + if (reply_buffer[ST1] & ST1_EOC) 1440 1425 return 0; /* occurs with pseudo-DMA */ 1441 1426 bad = 1; 1442 - if (ST1 & ST1_WP) { 1427 + if (reply_buffer[ST1] & ST1_WP) { 1443 1428 DPRINT("Drive is write protected\n"); 1444 - clear_bit(FD_DISK_WRITABLE_BIT, &DRS->flags); 1429 + clear_bit(FD_DISK_WRITABLE_BIT, 1430 + &drive_state[current_drive].flags); 1445 1431 cont->done(0); 1446 1432 bad = 2; 1447 - } else if (ST1 & ST1_ND) { 1448 - set_bit(FD_NEED_TWADDLE_BIT, &DRS->flags); 1449 - } else if (ST1 & ST1_OR) { 1450 - if (DP->flags & FTD_MSG) 1433 + } else if (reply_buffer[ST1] & ST1_ND) { 1434 + set_bit(FD_NEED_TWADDLE_BIT, 1435 + &drive_state[current_drive].flags); 1436 + } else if (reply_buffer[ST1] & ST1_OR) { 1437 + if (drive_params[current_drive].flags & FTD_MSG) 1451 1438 DPRINT("Over/Underrun - retrying\n"); 1452 1439 bad = 0; 1453 - } else if (*errors >= DP->max_errors.reporting) { 1440 + } else if (*errors >= drive_params[current_drive].max_errors.reporting) { 1454 1441 print_errors(); 1455 1442 } 1456 - if (ST2 & ST2_WC || ST2 & ST2_BC) 1443 + if (reply_buffer[ST2] & ST2_WC || reply_buffer[ST2] & ST2_BC) 1457 1444 /* wrong cylinder => recal */ 1458 - DRS->track = NEED_2_RECAL; 1445 + drive_state[current_drive].track = NEED_2_RECAL; 1459 1446 return bad; 1460 1447 case 0x80: /* invalid command given */ 1461 1448 DPRINT("Invalid FDC command given!\n"); ··· 1490 1473 flags |= FD_RAW_INTR; 1491 1474 1492 1475 if ((flags & FD_RAW_SPIN) && !(flags & FD_RAW_NO_MOTOR)) { 1493 - ready_date = DRS->spinup_date + DP->spinup; 1476 + ready_date = drive_state[current_drive].spinup_date + drive_params[current_drive].spinup; 1494 1477 /* If spinup will take a long time, rerun scandrives 1495 1478 * again just before spinup completion. Beware that 1496 1479 * after scandrives, we must again wait for selection. 1497 1480 */ 1498 - if (time_after(ready_date, jiffies + DP->select_delay)) { 1499 - ready_date -= DP->select_delay; 1481 + if (time_after(ready_date, jiffies + drive_params[current_drive].select_delay)) { 1482 + ready_date -= drive_params[current_drive].select_delay; 1500 1483 function = floppy_start; 1501 1484 } else 1502 1485 function = setup_rw_floppy; ··· 1539 1522 static void seek_interrupt(void) 1540 1523 { 1541 1524 debugt(__func__, ""); 1542 - if (inr != 2 || (ST0 & 0xF8) != 0x20) { 1525 + if (inr != 2 || (reply_buffer[ST0] & 0xF8) != 0x20) { 1543 1526 DPRINT("seek failed\n"); 1544 - DRS->track = NEED_2_RECAL; 1527 + drive_state[current_drive].track = NEED_2_RECAL; 1545 1528 cont->error(); 1546 1529 cont->redo(); 1547 1530 return; 1548 1531 } 1549 - if (DRS->track >= 0 && DRS->track != ST1 && !blind_seek) { 1550 - debug_dcl(DP->flags, 1532 + if (drive_state[current_drive].track >= 0 && 1533 + drive_state[current_drive].track != reply_buffer[ST1] && 1534 + !blind_seek) { 1535 + debug_dcl(drive_params[current_drive].flags, 1551 1536 "clearing NEWCHANGE flag because of effective seek\n"); 1552 - debug_dcl(DP->flags, "jiffies=%lu\n", jiffies); 1553 - clear_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags); 1537 + debug_dcl(drive_params[current_drive].flags, "jiffies=%lu\n", 1538 + jiffies); 1539 + clear_bit(FD_DISK_NEWCHANGE_BIT, 1540 + &drive_state[current_drive].flags); 1554 1541 /* effective seek */ 1555 - DRS->select_date = jiffies; 1542 + drive_state[current_drive].select_date = jiffies; 1556 1543 } 1557 - DRS->track = ST1; 1544 + drive_state[current_drive].track = reply_buffer[ST1]; 1558 1545 floppy_ready(); 1559 1546 } 1560 1547 1561 1548 static void check_wp(void) 1562 1549 { 1563 - if (test_bit(FD_VERIFY_BIT, &DRS->flags)) { 1550 + if (test_bit(FD_VERIFY_BIT, &drive_state[current_drive].flags)) { 1564 1551 /* check write protection */ 1565 1552 output_byte(FD_GETSTATUS); 1566 1553 output_byte(UNIT(current_drive)); 1567 1554 if (result() != 1) { 1568 - FDCS->reset = 1; 1555 + fdc_state[current_fdc].reset = 1; 1569 1556 return; 1570 1557 } 1571 - clear_bit(FD_VERIFY_BIT, &DRS->flags); 1572 - clear_bit(FD_NEED_TWADDLE_BIT, &DRS->flags); 1573 - debug_dcl(DP->flags, 1558 + clear_bit(FD_VERIFY_BIT, &drive_state[current_drive].flags); 1559 + clear_bit(FD_NEED_TWADDLE_BIT, 1560 + &drive_state[current_drive].flags); 1561 + debug_dcl(drive_params[current_drive].flags, 1574 1562 "checking whether disk is write protected\n"); 1575 - debug_dcl(DP->flags, "wp=%x\n", ST3 & 0x40); 1576 - if (!(ST3 & 0x40)) 1577 - set_bit(FD_DISK_WRITABLE_BIT, &DRS->flags); 1563 + debug_dcl(drive_params[current_drive].flags, "wp=%x\n", 1564 + reply_buffer[ST3] & 0x40); 1565 + if (!(reply_buffer[ST3] & 0x40)) 1566 + set_bit(FD_DISK_WRITABLE_BIT, 1567 + &drive_state[current_drive].flags); 1578 1568 else 1579 - clear_bit(FD_DISK_WRITABLE_BIT, &DRS->flags); 1569 + clear_bit(FD_DISK_WRITABLE_BIT, 1570 + &drive_state[current_drive].flags); 1580 1571 } 1581 1572 } 1582 1573 ··· 1594 1569 1595 1570 blind_seek = 0; 1596 1571 1597 - debug_dcl(DP->flags, "calling disk change from %s\n", __func__); 1572 + debug_dcl(drive_params[current_drive].flags, 1573 + "calling disk change from %s\n", __func__); 1598 1574 1599 - if (!test_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags) && 1575 + if (!test_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags) && 1600 1576 disk_change(current_drive) && (raw_cmd->flags & FD_RAW_NEED_DISK)) { 1601 1577 /* the media changed flag should be cleared after the seek. 1602 1578 * If it isn't, this means that there is really no disk in 1603 1579 * the drive. 1604 1580 */ 1605 - set_bit(FD_DISK_CHANGED_BIT, &DRS->flags); 1581 + set_bit(FD_DISK_CHANGED_BIT, 1582 + &drive_state[current_drive].flags); 1606 1583 cont->done(0); 1607 1584 cont->redo(); 1608 1585 return; 1609 1586 } 1610 - if (DRS->track <= NEED_1_RECAL) { 1587 + if (drive_state[current_drive].track <= NEED_1_RECAL) { 1611 1588 recalibrate_floppy(); 1612 1589 return; 1613 - } else if (test_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags) && 1590 + } else if (test_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags) && 1614 1591 (raw_cmd->flags & FD_RAW_NEED_DISK) && 1615 - (DRS->track <= NO_TRACK || DRS->track == raw_cmd->track)) { 1592 + (drive_state[current_drive].track <= NO_TRACK || drive_state[current_drive].track == raw_cmd->track)) { 1616 1593 /* we seek to clear the media-changed condition. Does anybody 1617 1594 * know a more elegant way, which works on all drives? */ 1618 1595 if (raw_cmd->track) 1619 1596 track = raw_cmd->track - 1; 1620 1597 else { 1621 - if (DP->flags & FD_SILENT_DCL_CLEAR) { 1622 - set_dor(fdc, ~(0x10 << UNIT(current_drive)), 0); 1598 + if (drive_params[current_drive].flags & FD_SILENT_DCL_CLEAR) { 1599 + set_dor(current_fdc, ~(0x10 << UNIT(current_drive)), 0); 1623 1600 blind_seek = 1; 1624 1601 raw_cmd->flags |= FD_RAW_NEED_SEEK; 1625 1602 } ··· 1629 1602 } 1630 1603 } else { 1631 1604 check_wp(); 1632 - if (raw_cmd->track != DRS->track && 1605 + if (raw_cmd->track != drive_state[current_drive].track && 1633 1606 (raw_cmd->flags & FD_RAW_NEED_SEEK)) 1634 1607 track = raw_cmd->track; 1635 1608 else { ··· 1652 1625 { 1653 1626 debugt(__func__, ""); 1654 1627 if (inr != 2) 1655 - FDCS->reset = 1; 1656 - else if (ST0 & ST0_ECE) { 1657 - switch (DRS->track) { 1628 + fdc_state[current_fdc].reset = 1; 1629 + else if (reply_buffer[ST0] & ST0_ECE) { 1630 + switch (drive_state[current_drive].track) { 1658 1631 case NEED_1_RECAL: 1659 1632 debugt(__func__, "need 1 recal"); 1660 1633 /* after a second recalibrate, we still haven't ··· 1672 1645 * not to move at recalibration is to 1673 1646 * be already at track 0.) Clear the 1674 1647 * new change flag */ 1675 - debug_dcl(DP->flags, 1648 + debug_dcl(drive_params[current_drive].flags, 1676 1649 "clearing NEWCHANGE flag because of second recalibrate\n"); 1677 1650 1678 - clear_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags); 1679 - DRS->select_date = jiffies; 1651 + clear_bit(FD_DISK_NEWCHANGE_BIT, 1652 + &drive_state[current_drive].flags); 1653 + drive_state[current_drive].select_date = jiffies; 1680 1654 /* fall through */ 1681 1655 default: 1682 1656 debugt(__func__, "default"); ··· 1687 1659 * track 0, this might mean that we 1688 1660 * started beyond track 80. Try 1689 1661 * again. */ 1690 - DRS->track = NEED_1_RECAL; 1662 + drive_state[current_drive].track = NEED_1_RECAL; 1691 1663 break; 1692 1664 } 1693 1665 } else 1694 - DRS->track = ST1; 1666 + drive_state[current_drive].track = reply_buffer[ST1]; 1695 1667 floppy_ready(); 1696 1668 } 1697 1669 ··· 1721 1693 release_dma_lock(f); 1722 1694 1723 1695 do_floppy = NULL; 1724 - if (fdc >= N_FDC || FDCS->address == -1) { 1696 + if (current_fdc >= N_FDC || fdc_state[current_fdc].address == -1) { 1725 1697 /* we don't even know which FDC is the culprit */ 1726 1698 pr_info("DOR0=%x\n", fdc_state[0].dor); 1727 - pr_info("floppy interrupt on bizarre fdc %d\n", fdc); 1699 + pr_info("floppy interrupt on bizarre fdc %d\n", current_fdc); 1728 1700 pr_info("handler=%ps\n", handler); 1729 1701 is_alive(__func__, "bizarre fdc"); 1730 1702 return IRQ_NONE; 1731 1703 } 1732 1704 1733 - FDCS->reset = 0; 1705 + fdc_state[current_fdc].reset = 0; 1734 1706 /* We have to clear the reset flag here, because apparently on boxes 1735 1707 * with level triggered interrupts (PS/2, Sparc, ...), it is needed to 1736 - * emit SENSEI's to clear the interrupt line. And FDCS->reset blocks the 1737 - * emission of the SENSEI's. 1708 + * emit SENSEI's to clear the interrupt line. And fdc_state[fdc].reset 1709 + * blocks the emission of the SENSEI's. 1738 1710 * It is OK to emit floppy commands because we are in an interrupt 1739 1711 * handler here, and thus we have to fear no interference of other 1740 1712 * activity. ··· 1753 1725 if (do_print) 1754 1726 print_result("sensei", inr); 1755 1727 max_sensei--; 1756 - } while ((ST0 & 0x83) != UNIT(current_drive) && 1728 + } while ((reply_buffer[ST0] & 0x83) != UNIT(current_drive) && 1757 1729 inr == 2 && max_sensei); 1758 1730 } 1759 1731 if (!handler) { 1760 - FDCS->reset = 1; 1732 + fdc_state[current_fdc].reset = 1; 1761 1733 return IRQ_NONE; 1762 1734 } 1763 1735 schedule_bh(handler); ··· 1783 1755 { 1784 1756 debugt(__func__, ""); 1785 1757 result(); /* get the status ready for set_fdc */ 1786 - if (FDCS->reset) { 1758 + if (fdc_state[current_fdc].reset) { 1787 1759 pr_info("reset set in interrupt, calling %ps\n", cont->error); 1788 1760 cont->error(); /* a reset just after a reset. BAD! */ 1789 1761 } ··· 1799 1771 unsigned long flags; 1800 1772 1801 1773 do_floppy = reset_interrupt; 1802 - FDCS->reset = 0; 1774 + fdc_state[current_fdc].reset = 0; 1803 1775 reset_fdc_info(0); 1804 1776 1805 1777 /* Pseudo-DMA may intercept 'reset finished' interrupt. */ ··· 1809 1781 fd_disable_dma(); 1810 1782 release_dma_lock(flags); 1811 1783 1812 - if (FDCS->version >= FDC_82072A) 1813 - fd_outb(0x80 | (FDCS->dtr & 3), FD_STATUS); 1784 + if (fdc_state[current_fdc].version >= FDC_82072A) 1785 + fdc_outb(0x80 | (fdc_state[current_fdc].dtr & 3), 1786 + current_fdc, FD_STATUS); 1814 1787 else { 1815 - fd_outb(FDCS->dor & ~0x04, FD_DOR); 1788 + fdc_outb(fdc_state[current_fdc].dor & ~0x04, current_fdc, FD_DOR); 1816 1789 udelay(FD_RESET_DELAY); 1817 - fd_outb(FDCS->dor, FD_DOR); 1790 + fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR); 1818 1791 } 1819 1792 } 1820 1793 ··· 1842 1813 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1, 1843 1814 reply_buffer, resultsize, true); 1844 1815 1845 - pr_info("status=%x\n", fd_inb(FD_STATUS)); 1816 + pr_info("status=%x\n", fdc_inb(current_fdc, FD_STATUS)); 1846 1817 pr_info("fdc_busy=%lu\n", fdc_busy); 1847 1818 if (do_floppy) 1848 1819 pr_info("do_floppy=%ps\n", do_floppy); ··· 1879 1850 1880 1851 if (initialized) 1881 1852 DPRINT("floppy timeout called\n"); 1882 - FDCS->reset = 1; 1853 + fdc_state[current_fdc].reset = 1; 1883 1854 if (cont) { 1884 1855 cont->done(0); 1885 1856 cont->redo(); /* this will recall reset when needed */ ··· 1899 1870 mask = 0xfc; 1900 1871 data = UNIT(current_drive); 1901 1872 if (!(raw_cmd->flags & FD_RAW_NO_MOTOR)) { 1902 - if (!(FDCS->dor & (0x10 << UNIT(current_drive)))) { 1873 + if (!(fdc_state[current_fdc].dor & (0x10 << UNIT(current_drive)))) { 1903 1874 set_debugt(); 1904 1875 /* no read since this drive is running */ 1905 - DRS->first_read_date = 0; 1876 + drive_state[current_drive].first_read_date = 0; 1906 1877 /* note motor start time if motor is not yet running */ 1907 - DRS->spinup_date = jiffies; 1878 + drive_state[current_drive].spinup_date = jiffies; 1908 1879 data |= (0x10 << UNIT(current_drive)); 1909 1880 } 1910 - } else if (FDCS->dor & (0x10 << UNIT(current_drive))) 1881 + } else if (fdc_state[current_fdc].dor & (0x10 << UNIT(current_drive))) 1911 1882 mask &= ~(0x10 << UNIT(current_drive)); 1912 1883 1913 1884 /* starts motor and selects floppy */ 1914 1885 del_timer(motor_off_timer + current_drive); 1915 - set_dor(fdc, mask, data); 1886 + set_dor(current_fdc, mask, data); 1916 1887 1917 1888 /* wait_for_completion also schedules reset if needed. */ 1918 - return fd_wait_for_completion(DRS->select_date + DP->select_delay, 1889 + return fd_wait_for_completion(drive_state[current_drive].select_date + drive_params[current_drive].select_delay, 1919 1890 function); 1920 1891 } 1921 1892 1922 1893 static void floppy_ready(void) 1923 1894 { 1924 - if (FDCS->reset) { 1895 + if (fdc_state[current_fdc].reset) { 1925 1896 reset_fdc(); 1926 1897 return; 1927 1898 } ··· 1930 1901 if (fdc_dtr()) 1931 1902 return; 1932 1903 1933 - debug_dcl(DP->flags, "calling disk change from floppy_ready\n"); 1904 + debug_dcl(drive_params[current_drive].flags, 1905 + "calling disk change from floppy_ready\n"); 1934 1906 if (!(raw_cmd->flags & FD_RAW_NO_MOTOR) && 1935 - disk_change(current_drive) && !DP->select_delay) 1907 + disk_change(current_drive) && !drive_params[current_drive].select_delay) 1936 1908 twaddle(); /* this clears the dcl on certain 1937 1909 * drive/controller combinations */ 1938 1910 ··· 1962 1932 reschedule_timeout(current_reqD, "floppy start"); 1963 1933 1964 1934 scandrives(); 1965 - debug_dcl(DP->flags, "setting NEWCHANGE in floppy_start\n"); 1966 - set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags); 1935 + debug_dcl(drive_params[current_drive].flags, 1936 + "setting NEWCHANGE in floppy_start\n"); 1937 + set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags); 1967 1938 floppy_ready(); 1968 1939 } 1969 1940 ··· 2022 1991 return -EINTR; 2023 1992 } 2024 1993 2025 - if (FDCS->reset) 1994 + if (fdc_state[current_fdc].reset) 2026 1995 command_status = FD_COMMAND_ERROR; 2027 1996 if (command_status == FD_COMMAND_OKAY) 2028 1997 ret = 0; ··· 2063 2032 { 2064 2033 int probed_format; 2065 2034 2066 - probed_format = DRS->probed_format; 2035 + probed_format = drive_state[current_drive].probed_format; 2067 2036 while (1) { 2068 - if (probed_format >= 8 || !DP->autodetect[probed_format]) { 2069 - DRS->probed_format = 0; 2037 + if (probed_format >= 8 || !drive_params[current_drive].autodetect[probed_format]) { 2038 + drive_state[current_drive].probed_format = 0; 2070 2039 return 1; 2071 2040 } 2072 - if (floppy_type[DP->autodetect[probed_format]].sect) { 2073 - DRS->probed_format = probed_format; 2041 + if (floppy_type[drive_params[current_drive].autodetect[probed_format]].sect) { 2042 + drive_state[current_drive].probed_format = probed_format; 2074 2043 return 0; 2075 2044 } 2076 2045 probed_format++; ··· 2082 2051 int err_count; 2083 2052 2084 2053 if (probing) { 2085 - DRS->probed_format++; 2054 + drive_state[current_drive].probed_format++; 2086 2055 if (!next_valid_format()) 2087 2056 return; 2088 2057 } 2089 2058 err_count = ++(*errors); 2090 - INFBOUND(DRWE->badness, err_count); 2091 - if (err_count > DP->max_errors.abort) 2059 + INFBOUND(write_errors[current_drive].badness, err_count); 2060 + if (err_count > drive_params[current_drive].max_errors.abort) 2092 2061 cont->done(0); 2093 - if (err_count > DP->max_errors.reset) 2094 - FDCS->reset = 1; 2095 - else if (err_count > DP->max_errors.recal) 2096 - DRS->track = NEED_2_RECAL; 2062 + if (err_count > drive_params[current_drive].max_errors.reset) 2063 + fdc_state[current_fdc].reset = 1; 2064 + else if (err_count > drive_params[current_drive].max_errors.recal) 2065 + drive_state[current_drive].track = NEED_2_RECAL; 2097 2066 } 2098 2067 2099 2068 static void set_floppy(int drive) 2100 2069 { 2101 - int type = ITYPE(UDRS->fd_device); 2070 + int type = ITYPE(drive_state[drive].fd_device); 2102 2071 2103 2072 if (type) 2104 2073 _floppy = floppy_type + type; ··· 2144 2113 FD_RAW_NEED_DISK | FD_RAW_NEED_SEEK); 2145 2114 raw_cmd->rate = _floppy->rate & 0x43; 2146 2115 raw_cmd->cmd_count = NR_F; 2147 - COMMAND = FM_MODE(_floppy, FD_FORMAT); 2148 - DR_SELECT = UNIT(current_drive) + PH_HEAD(_floppy, format_req.head); 2149 - F_SIZECODE = FD_SIZECODE(_floppy); 2150 - F_SECT_PER_TRACK = _floppy->sect << 2 >> F_SIZECODE; 2151 - F_GAP = _floppy->fmt_gap; 2152 - F_FILL = FD_FILL_BYTE; 2116 + raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_FORMAT); 2117 + raw_cmd->cmd[DR_SELECT] = UNIT(current_drive) + PH_HEAD(_floppy, format_req.head); 2118 + raw_cmd->cmd[F_SIZECODE] = FD_SIZECODE(_floppy); 2119 + raw_cmd->cmd[F_SECT_PER_TRACK] = _floppy->sect << 2 >> raw_cmd->cmd[F_SIZECODE]; 2120 + raw_cmd->cmd[F_GAP] = _floppy->fmt_gap; 2121 + raw_cmd->cmd[F_FILL] = FD_FILL_BYTE; 2153 2122 2154 2123 raw_cmd->kernel_data = floppy_track_buffer; 2155 - raw_cmd->length = 4 * F_SECT_PER_TRACK; 2124 + raw_cmd->length = 4 * raw_cmd->cmd[F_SECT_PER_TRACK]; 2156 2125 2157 - if (!F_SECT_PER_TRACK) 2126 + if (!raw_cmd->cmd[F_SECT_PER_TRACK]) 2158 2127 return; 2159 2128 2160 2129 /* allow for about 30ms for data transport per track */ 2161 - head_shift = (F_SECT_PER_TRACK + 5) / 6; 2130 + head_shift = (raw_cmd->cmd[F_SECT_PER_TRACK] + 5) / 6; 2162 2131 2163 2132 /* a ``cylinder'' is two tracks plus a little stepping time */ 2164 2133 track_shift = 2 * head_shift + 3; 2165 2134 2166 2135 /* position of logical sector 1 on this track */ 2167 2136 n = (track_shift * format_req.track + head_shift * format_req.head) 2168 - % F_SECT_PER_TRACK; 2137 + % raw_cmd->cmd[F_SECT_PER_TRACK]; 2169 2138 2170 2139 /* determine interleave */ 2171 2140 il = 1; ··· 2173 2142 il++; 2174 2143 2175 2144 /* initialize field */ 2176 - for (count = 0; count < F_SECT_PER_TRACK; ++count) { 2145 + for (count = 0; count < raw_cmd->cmd[F_SECT_PER_TRACK]; ++count) { 2177 2146 here[count].track = format_req.track; 2178 2147 here[count].head = format_req.head; 2179 2148 here[count].sect = 0; 2180 - here[count].size = F_SIZECODE; 2149 + here[count].size = raw_cmd->cmd[F_SIZECODE]; 2181 2150 } 2182 2151 /* place logical sectors */ 2183 - for (count = 1; count <= F_SECT_PER_TRACK; ++count) { 2152 + for (count = 1; count <= raw_cmd->cmd[F_SECT_PER_TRACK]; ++count) { 2184 2153 here[n].sect = count; 2185 - n = (n + il) % F_SECT_PER_TRACK; 2154 + n = (n + il) % raw_cmd->cmd[F_SECT_PER_TRACK]; 2186 2155 if (here[n].sect) { /* sector busy, find next free sector */ 2187 2156 ++n; 2188 - if (n >= F_SECT_PER_TRACK) { 2189 - n -= F_SECT_PER_TRACK; 2157 + if (n >= raw_cmd->cmd[F_SECT_PER_TRACK]) { 2158 + n -= raw_cmd->cmd[F_SECT_PER_TRACK]; 2190 2159 while (here[n].sect) 2191 2160 ++n; 2192 2161 } 2193 2162 } 2194 2163 } 2195 2164 if (_floppy->stretch & FD_SECTBASEMASK) { 2196 - for (count = 0; count < F_SECT_PER_TRACK; count++) 2165 + for (count = 0; count < raw_cmd->cmd[F_SECT_PER_TRACK]; count++) 2197 2166 here[count].sect += FD_SECTBASE(_floppy) - 1; 2198 2167 } 2199 2168 } ··· 2222 2191 2223 2192 set_floppy(drive); 2224 2193 if (!_floppy || 2225 - _floppy->track > DP->tracks || 2194 + _floppy->track > drive_params[current_drive].tracks || 2226 2195 tmp_format_req->track >= _floppy->track || 2227 2196 tmp_format_req->head >= _floppy->head || 2228 2197 (_floppy->sect << 2) % (1 << FD_SIZECODE(_floppy)) || ··· 2284 2253 /* maintain values for invalidation on geometry 2285 2254 * change */ 2286 2255 block = current_count_sectors + blk_rq_pos(req); 2287 - INFBOUND(DRS->maxblock, block); 2256 + INFBOUND(drive_state[current_drive].maxblock, block); 2288 2257 if (block > _floppy->sect) 2289 - DRS->maxtrack = 1; 2258 + drive_state[current_drive].maxtrack = 1; 2290 2259 2291 2260 floppy_end_request(req, 0); 2292 2261 } else { 2293 2262 if (rq_data_dir(req) == WRITE) { 2294 2263 /* record write error information */ 2295 - DRWE->write_errors++; 2296 - if (DRWE->write_errors == 1) { 2297 - DRWE->first_error_sector = blk_rq_pos(req); 2298 - DRWE->first_error_generation = DRS->generation; 2264 + write_errors[current_drive].write_errors++; 2265 + if (write_errors[current_drive].write_errors == 1) { 2266 + write_errors[current_drive].first_error_sector = blk_rq_pos(req); 2267 + write_errors[current_drive].first_error_generation = drive_state[current_drive].generation; 2299 2268 } 2300 - DRWE->last_error_sector = blk_rq_pos(req); 2301 - DRWE->last_error_generation = DRS->generation; 2269 + write_errors[current_drive].last_error_sector = blk_rq_pos(req); 2270 + write_errors[current_drive].last_error_generation = drive_state[current_drive].generation; 2302 2271 } 2303 2272 floppy_end_request(req, BLK_STS_IOERR); 2304 2273 } ··· 2312 2281 int heads; 2313 2282 int nr_sectors; 2314 2283 2315 - if (R_HEAD >= 2) { 2284 + if (reply_buffer[R_HEAD] >= 2) { 2316 2285 /* some Toshiba floppy controllers occasionnally seem to 2317 2286 * return bogus interrupts after read/write operations, which 2318 2287 * can be recognized by a bad head number (>= 2) */ 2319 2288 return; 2320 2289 } 2321 2290 2322 - if (!DRS->first_read_date) 2323 - DRS->first_read_date = jiffies; 2291 + if (!drive_state[current_drive].first_read_date) 2292 + drive_state[current_drive].first_read_date = jiffies; 2324 2293 2325 2294 nr_sectors = 0; 2326 - ssize = DIV_ROUND_UP(1 << SIZECODE, 4); 2295 + ssize = DIV_ROUND_UP(1 << raw_cmd->cmd[SIZECODE], 4); 2327 2296 2328 - if (ST1 & ST1_EOC) 2297 + if (reply_buffer[ST1] & ST1_EOC) 2329 2298 eoc = 1; 2330 2299 else 2331 2300 eoc = 0; 2332 2301 2333 - if (COMMAND & 0x80) 2302 + if (raw_cmd->cmd[COMMAND] & 0x80) 2334 2303 heads = 2; 2335 2304 else 2336 2305 heads = 1; 2337 2306 2338 - nr_sectors = (((R_TRACK - TRACK) * heads + 2339 - R_HEAD - HEAD) * SECT_PER_TRACK + 2340 - R_SECTOR - SECTOR + eoc) << SIZECODE >> 2; 2307 + nr_sectors = (((reply_buffer[R_TRACK] - raw_cmd->cmd[TRACK]) * heads + 2308 + reply_buffer[R_HEAD] - raw_cmd->cmd[HEAD]) * raw_cmd->cmd[SECT_PER_TRACK] + 2309 + reply_buffer[R_SECTOR] - raw_cmd->cmd[SECTOR] + eoc) << raw_cmd->cmd[SIZECODE] >> 2; 2341 2310 2342 2311 if (nr_sectors / ssize > 2343 2312 DIV_ROUND_UP(in_sector_offset + current_count_sectors, ssize)) { 2344 2313 DPRINT("long rw: %x instead of %lx\n", 2345 2314 nr_sectors, current_count_sectors); 2346 - pr_info("rs=%d s=%d\n", R_SECTOR, SECTOR); 2347 - pr_info("rh=%d h=%d\n", R_HEAD, HEAD); 2348 - pr_info("rt=%d t=%d\n", R_TRACK, TRACK); 2315 + pr_info("rs=%d s=%d\n", reply_buffer[R_SECTOR], 2316 + raw_cmd->cmd[SECTOR]); 2317 + pr_info("rh=%d h=%d\n", reply_buffer[R_HEAD], 2318 + raw_cmd->cmd[HEAD]); 2319 + pr_info("rt=%d t=%d\n", reply_buffer[R_TRACK], 2320 + raw_cmd->cmd[TRACK]); 2349 2321 pr_info("heads=%d eoc=%d\n", heads, eoc); 2350 2322 pr_info("spt=%d st=%d ss=%d\n", 2351 - SECT_PER_TRACK, fsector_t, ssize); 2323 + raw_cmd->cmd[SECT_PER_TRACK], fsector_t, ssize); 2352 2324 pr_info("in_sector_offset=%d\n", in_sector_offset); 2353 2325 } 2354 2326 ··· 2381 2347 } 2382 2348 2383 2349 if (probing) { 2384 - if (DP->flags & FTD_MSG) 2350 + if (drive_params[current_drive].flags & FTD_MSG) 2385 2351 DPRINT("Auto-detected floppy type %s in fd%d\n", 2386 2352 _floppy->name, current_drive); 2387 2353 current_type[current_drive] = _floppy; ··· 2389 2355 probing = 0; 2390 2356 } 2391 2357 2392 - if (CT(COMMAND) != FD_READ || 2358 + if (CT(raw_cmd->cmd[COMMAND]) != FD_READ || 2393 2359 raw_cmd->kernel_data == bio_data(current_req->bio)) { 2394 2360 /* transfer directly from buffer */ 2395 2361 cont->done(1); 2396 - } else if (CT(COMMAND) == FD_READ) { 2362 + } else if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) { 2397 2363 buffer_track = raw_cmd->track; 2398 2364 buffer_drive = current_drive; 2399 2365 INFBOUND(buffer_max, nr_sectors + fsector_t); ··· 2452 2418 min(max_sector, max_sector_2), 2453 2419 blk_rq_sectors(current_req)); 2454 2420 2455 - if (current_count_sectors <= 0 && CT(COMMAND) == FD_WRITE && 2421 + if (current_count_sectors <= 0 && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE && 2456 2422 buffer_max > fsector_t + blk_rq_sectors(current_req)) 2457 2423 current_count_sectors = min_t(int, buffer_max - fsector_t, 2458 2424 blk_rq_sectors(current_req)); 2459 2425 2460 2426 remaining = current_count_sectors << 9; 2461 - if (remaining > blk_rq_bytes(current_req) && CT(COMMAND) == FD_WRITE) { 2427 + if (remaining > blk_rq_bytes(current_req) && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) { 2462 2428 DPRINT("in copy buffer\n"); 2463 2429 pr_info("current_count_sectors=%ld\n", current_count_sectors); 2464 2430 pr_info("remaining=%d\n", remaining >> 9); ··· 2493 2459 fsector_t, buffer_min); 2494 2460 pr_info("current_count_sectors=%ld\n", 2495 2461 current_count_sectors); 2496 - if (CT(COMMAND) == FD_READ) 2462 + if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) 2497 2463 pr_info("read\n"); 2498 - if (CT(COMMAND) == FD_WRITE) 2464 + if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) 2499 2465 pr_info("write\n"); 2500 2466 break; 2501 2467 } 2502 2468 if (((unsigned long)buffer) % 512) 2503 2469 DPRINT("%p buffer not aligned\n", buffer); 2504 2470 2505 - if (CT(COMMAND) == FD_READ) 2471 + if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) 2506 2472 memcpy(buffer, dma_buffer, size); 2507 2473 else 2508 2474 memcpy(dma_buffer, buffer, size); ··· 2520 2486 /* work around a bug in pseudo DMA 2521 2487 * (on some FDCs) pseudo DMA does not stop when the CPU stops 2522 2488 * sending data. Hence we need a different way to signal the 2523 - * transfer length: We use SECT_PER_TRACK. Unfortunately, this 2489 + * transfer length: We use raw_cmd->cmd[SECT_PER_TRACK]. Unfortunately, this 2524 2490 * does not work with MT, hence we can only transfer one head at 2525 2491 * a time 2526 2492 */ ··· 2529 2495 int hard_sectors; 2530 2496 int end_sector; 2531 2497 2532 - if (CT(COMMAND) == FD_WRITE) { 2533 - COMMAND &= ~0x80; /* switch off multiple track mode */ 2498 + if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) { 2499 + raw_cmd->cmd[COMMAND] &= ~0x80; /* switch off multiple track mode */ 2534 2500 2535 - hard_sectors = raw_cmd->length >> (7 + SIZECODE); 2536 - end_sector = SECTOR + hard_sectors - 1; 2537 - if (end_sector > SECT_PER_TRACK) { 2501 + hard_sectors = raw_cmd->length >> (7 + raw_cmd->cmd[SIZECODE]); 2502 + end_sector = raw_cmd->cmd[SECTOR] + hard_sectors - 1; 2503 + if (end_sector > raw_cmd->cmd[SECT_PER_TRACK]) { 2538 2504 pr_info("too many sectors %d > %d\n", 2539 - end_sector, SECT_PER_TRACK); 2505 + end_sector, raw_cmd->cmd[SECT_PER_TRACK]); 2540 2506 return; 2541 2507 } 2542 - SECT_PER_TRACK = end_sector; 2543 - /* make sure SECT_PER_TRACK 2508 + raw_cmd->cmd[SECT_PER_TRACK] = end_sector; 2509 + /* make sure raw_cmd->cmd[SECT_PER_TRACK] 2544 2510 * points to end of transfer */ 2545 2511 } 2546 2512 } ··· 2573 2539 raw_cmd->cmd_count = NR_RW; 2574 2540 if (rq_data_dir(current_req) == READ) { 2575 2541 raw_cmd->flags |= FD_RAW_READ; 2576 - COMMAND = FM_MODE(_floppy, FD_READ); 2542 + raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_READ); 2577 2543 } else if (rq_data_dir(current_req) == WRITE) { 2578 2544 raw_cmd->flags |= FD_RAW_WRITE; 2579 - COMMAND = FM_MODE(_floppy, FD_WRITE); 2545 + raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_WRITE); 2580 2546 } else { 2581 2547 DPRINT("%s: unknown command\n", __func__); 2582 2548 return 0; ··· 2584 2550 2585 2551 max_sector = _floppy->sect * _floppy->head; 2586 2552 2587 - TRACK = (int)blk_rq_pos(current_req) / max_sector; 2553 + raw_cmd->cmd[TRACK] = (int)blk_rq_pos(current_req) / max_sector; 2588 2554 fsector_t = (int)blk_rq_pos(current_req) % max_sector; 2589 - if (_floppy->track && TRACK >= _floppy->track) { 2555 + if (_floppy->track && raw_cmd->cmd[TRACK] >= _floppy->track) { 2590 2556 if (blk_rq_cur_sectors(current_req) & 1) { 2591 2557 current_count_sectors = 1; 2592 2558 return 1; 2593 2559 } else 2594 2560 return 0; 2595 2561 } 2596 - HEAD = fsector_t / _floppy->sect; 2562 + raw_cmd->cmd[HEAD] = fsector_t / _floppy->sect; 2597 2563 2598 2564 if (((_floppy->stretch & (FD_SWAPSIDES | FD_SECTBASEMASK)) || 2599 - test_bit(FD_NEED_TWADDLE_BIT, &DRS->flags)) && 2565 + test_bit(FD_NEED_TWADDLE_BIT, &drive_state[current_drive].flags)) && 2600 2566 fsector_t < _floppy->sect) 2601 2567 max_sector = _floppy->sect; 2602 2568 2603 2569 /* 2M disks have phantom sectors on the first track */ 2604 - if ((_floppy->rate & FD_2M) && (!TRACK) && (!HEAD)) { 2570 + if ((_floppy->rate & FD_2M) && (!raw_cmd->cmd[TRACK]) && (!raw_cmd->cmd[HEAD])) { 2605 2571 max_sector = 2 * _floppy->sect / 3; 2606 2572 if (fsector_t >= max_sector) { 2607 2573 current_count_sectors = ··· 2609 2575 blk_rq_sectors(current_req)); 2610 2576 return 1; 2611 2577 } 2612 - SIZECODE = 2; 2578 + raw_cmd->cmd[SIZECODE] = 2; 2613 2579 } else 2614 - SIZECODE = FD_SIZECODE(_floppy); 2580 + raw_cmd->cmd[SIZECODE] = FD_SIZECODE(_floppy); 2615 2581 raw_cmd->rate = _floppy->rate & 0x43; 2616 - if ((_floppy->rate & FD_2M) && (TRACK || HEAD) && raw_cmd->rate == 2) 2582 + if ((_floppy->rate & FD_2M) && 2583 + (raw_cmd->cmd[TRACK] || raw_cmd->cmd[HEAD]) && raw_cmd->rate == 2) 2617 2584 raw_cmd->rate = 1; 2618 2585 2619 - if (SIZECODE) 2620 - SIZECODE2 = 0xff; 2586 + if (raw_cmd->cmd[SIZECODE]) 2587 + raw_cmd->cmd[SIZECODE2] = 0xff; 2621 2588 else 2622 - SIZECODE2 = 0x80; 2623 - raw_cmd->track = TRACK << STRETCH(_floppy); 2624 - DR_SELECT = UNIT(current_drive) + PH_HEAD(_floppy, HEAD); 2625 - GAP = _floppy->gap; 2626 - ssize = DIV_ROUND_UP(1 << SIZECODE, 4); 2627 - SECT_PER_TRACK = _floppy->sect << 2 >> SIZECODE; 2628 - SECTOR = ((fsector_t % _floppy->sect) << 2 >> SIZECODE) + 2589 + raw_cmd->cmd[SIZECODE2] = 0x80; 2590 + raw_cmd->track = raw_cmd->cmd[TRACK] << STRETCH(_floppy); 2591 + raw_cmd->cmd[DR_SELECT] = UNIT(current_drive) + PH_HEAD(_floppy, raw_cmd->cmd[HEAD]); 2592 + raw_cmd->cmd[GAP] = _floppy->gap; 2593 + ssize = DIV_ROUND_UP(1 << raw_cmd->cmd[SIZECODE], 4); 2594 + raw_cmd->cmd[SECT_PER_TRACK] = _floppy->sect << 2 >> raw_cmd->cmd[SIZECODE]; 2595 + raw_cmd->cmd[SECTOR] = ((fsector_t % _floppy->sect) << 2 >> raw_cmd->cmd[SIZECODE]) + 2629 2596 FD_SECTBASE(_floppy); 2630 2597 2631 2598 /* tracksize describes the size which can be filled up with sectors ··· 2634 2599 */ 2635 2600 tracksize = _floppy->sect - _floppy->sect % ssize; 2636 2601 if (tracksize < _floppy->sect) { 2637 - SECT_PER_TRACK++; 2602 + raw_cmd->cmd[SECT_PER_TRACK]++; 2638 2603 if (tracksize <= fsector_t % _floppy->sect) 2639 - SECTOR--; 2604 + raw_cmd->cmd[SECTOR]--; 2640 2605 2641 2606 /* if we are beyond tracksize, fill up using smaller sectors */ 2642 2607 while (tracksize <= fsector_t % _floppy->sect) { 2643 2608 while (tracksize + ssize > _floppy->sect) { 2644 - SIZECODE--; 2609 + raw_cmd->cmd[SIZECODE]--; 2645 2610 ssize >>= 1; 2646 2611 } 2647 - SECTOR++; 2648 - SECT_PER_TRACK++; 2612 + raw_cmd->cmd[SECTOR]++; 2613 + raw_cmd->cmd[SECT_PER_TRACK]++; 2649 2614 tracksize += ssize; 2650 2615 } 2651 - max_sector = HEAD * _floppy->sect + tracksize; 2652 - } else if (!TRACK && !HEAD && !(_floppy->rate & FD_2M) && probing) { 2616 + max_sector = raw_cmd->cmd[HEAD] * _floppy->sect + tracksize; 2617 + } else if (!raw_cmd->cmd[TRACK] && !raw_cmd->cmd[HEAD] && !(_floppy->rate & FD_2M) && probing) { 2653 2618 max_sector = _floppy->sect; 2654 - } else if (!HEAD && CT(COMMAND) == FD_WRITE) { 2619 + } else if (!raw_cmd->cmd[HEAD] && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) { 2655 2620 /* for virtual DMA bug workaround */ 2656 2621 max_sector = _floppy->sect; 2657 2622 } ··· 2663 2628 (current_drive == buffer_drive) && 2664 2629 (fsector_t >= buffer_min) && (fsector_t < buffer_max)) { 2665 2630 /* data already in track buffer */ 2666 - if (CT(COMMAND) == FD_READ) { 2631 + if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) { 2667 2632 copy_buffer(1, max_sector, buffer_max); 2668 2633 return 1; 2669 2634 } 2670 2635 } else if (in_sector_offset || blk_rq_sectors(current_req) < ssize) { 2671 - if (CT(COMMAND) == FD_WRITE) { 2636 + if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) { 2672 2637 unsigned int sectors; 2673 2638 2674 2639 sectors = fsector_t + blk_rq_sectors(current_req); ··· 2679 2644 } 2680 2645 raw_cmd->flags &= ~FD_RAW_WRITE; 2681 2646 raw_cmd->flags |= FD_RAW_READ; 2682 - COMMAND = FM_MODE(_floppy, FD_READ); 2647 + raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_READ); 2683 2648 } else if ((unsigned long)bio_data(current_req->bio) < MAX_DMA_ADDRESS) { 2684 2649 unsigned long dma_limit; 2685 2650 int direct, indirect; ··· 2712 2677 */ 2713 2678 if (!direct || 2714 2679 (indirect * 2 > direct * 3 && 2715 - *errors < DP->max_errors.read_track && 2680 + *errors < drive_params[current_drive].max_errors.read_track && 2716 2681 ((!probing || 2717 - (DP->read_track & (1 << DRS->probed_format)))))) { 2682 + (drive_params[current_drive].read_track & (1 << drive_state[current_drive].probed_format)))))) { 2718 2683 max_size = blk_rq_sectors(current_req); 2719 2684 } else { 2720 2685 raw_cmd->kernel_data = bio_data(current_req->bio); ··· 2730 2695 } 2731 2696 } 2732 2697 2733 - if (CT(COMMAND) == FD_READ) 2698 + if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) 2734 2699 max_size = max_sector; /* unbounded */ 2735 2700 2736 2701 /* claim buffer track if needed */ ··· 2738 2703 buffer_drive != current_drive || /* bad drive */ 2739 2704 fsector_t > buffer_max || 2740 2705 fsector_t < buffer_min || 2741 - ((CT(COMMAND) == FD_READ || 2706 + ((CT(raw_cmd->cmd[COMMAND]) == FD_READ || 2742 2707 (!in_sector_offset && blk_rq_sectors(current_req) >= ssize)) && 2743 2708 max_sector > 2 * max_buffer_sectors + buffer_min && 2744 2709 max_size + fsector_t > 2 * max_buffer_sectors + buffer_min)) { ··· 2750 2715 raw_cmd->kernel_data = floppy_track_buffer + 2751 2716 ((aligned_sector_t - buffer_min) << 9); 2752 2717 2753 - if (CT(COMMAND) == FD_WRITE) { 2718 + if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) { 2754 2719 /* copy write buffer to track buffer. 2755 2720 * if we get here, we know that the write 2756 2721 * is either aligned or the data already in the buffer ··· 2772 2737 raw_cmd->length <<= 9; 2773 2738 if ((raw_cmd->length < current_count_sectors << 9) || 2774 2739 (raw_cmd->kernel_data != bio_data(current_req->bio) && 2775 - CT(COMMAND) == FD_WRITE && 2740 + CT(raw_cmd->cmd[COMMAND]) == FD_WRITE && 2776 2741 (aligned_sector_t + (raw_cmd->length >> 9) > buffer_max || 2777 2742 aligned_sector_t < buffer_min)) || 2778 - raw_cmd->length % (128 << SIZECODE) || 2743 + raw_cmd->length % (128 << raw_cmd->cmd[SIZECODE]) || 2779 2744 raw_cmd->length <= 0 || current_count_sectors <= 0) { 2780 2745 DPRINT("fractionary current count b=%lx s=%lx\n", 2781 2746 raw_cmd->length, current_count_sectors); ··· 2786 2751 current_count_sectors); 2787 2752 pr_info("st=%d ast=%d mse=%d msi=%d\n", 2788 2753 fsector_t, aligned_sector_t, max_sector, max_size); 2789 - pr_info("ssize=%x SIZECODE=%d\n", ssize, SIZECODE); 2754 + pr_info("ssize=%x SIZECODE=%d\n", ssize, raw_cmd->cmd[SIZECODE]); 2790 2755 pr_info("command=%x SECTOR=%d HEAD=%d, TRACK=%d\n", 2791 - COMMAND, SECTOR, HEAD, TRACK); 2756 + raw_cmd->cmd[COMMAND], raw_cmd->cmd[SECTOR], 2757 + raw_cmd->cmd[HEAD], raw_cmd->cmd[TRACK]); 2792 2758 pr_info("buffer drive=%d\n", buffer_drive); 2793 2759 pr_info("buffer track=%d\n", buffer_track); 2794 2760 pr_info("buffer_min=%d\n", buffer_min); ··· 2808 2772 fsector_t, buffer_min, raw_cmd->length >> 9); 2809 2773 pr_info("current_count_sectors=%ld\n", 2810 2774 current_count_sectors); 2811 - if (CT(COMMAND) == FD_READ) 2775 + if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) 2812 2776 pr_info("read\n"); 2813 - if (CT(COMMAND) == FD_WRITE) 2777 + if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) 2814 2778 pr_info("write\n"); 2815 2779 return 0; 2816 2780 } ··· 2877 2841 2878 2842 disk_change(current_drive); 2879 2843 if (test_bit(current_drive, &fake_change) || 2880 - test_bit(FD_DISK_CHANGED_BIT, &DRS->flags)) { 2844 + test_bit(FD_DISK_CHANGED_BIT, &drive_state[current_drive].flags)) { 2881 2845 DPRINT("disk absent or changed during operation\n"); 2882 2846 request_done(0); 2883 2847 goto do_request; 2884 2848 } 2885 2849 if (!_floppy) { /* Autodetection */ 2886 2850 if (!probing) { 2887 - DRS->probed_format = 0; 2851 + drive_state[current_drive].probed_format = 0; 2888 2852 if (next_valid_format()) { 2889 2853 DPRINT("no autodetectable formats\n"); 2890 2854 _floppy = NULL; ··· 2893 2857 } 2894 2858 } 2895 2859 probing = 1; 2896 - _floppy = floppy_type + DP->autodetect[DRS->probed_format]; 2860 + _floppy = floppy_type + drive_params[current_drive].autodetect[drive_state[current_drive].probed_format]; 2897 2861 } else 2898 2862 probing = 0; 2899 2863 errors = &(current_req->error_count); ··· 2903 2867 goto do_request; 2904 2868 } 2905 2869 2906 - if (test_bit(FD_NEED_TWADDLE_BIT, &DRS->flags)) 2870 + if (test_bit(FD_NEED_TWADDLE_BIT, &drive_state[current_drive].flags)) 2907 2871 twaddle(); 2908 2872 schedule_bh(floppy_start); 2909 2873 debugt(__func__, "queue fd request"); ··· 2972 2936 raw_cmd->track = 0; 2973 2937 raw_cmd->cmd_count = 0; 2974 2938 cont = &poll_cont; 2975 - debug_dcl(DP->flags, "setting NEWCHANGE in poll_drive\n"); 2976 - set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags); 2939 + debug_dcl(drive_params[current_drive].flags, 2940 + "setting NEWCHANGE in poll_drive\n"); 2941 + set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags); 2977 2942 2978 2943 return wait_til_done(floppy_ready, interruptible); 2979 2944 } ··· 3004 2967 return -EINTR; 3005 2968 3006 2969 if (arg == FD_RESET_ALWAYS) 3007 - FDCS->reset = 1; 3008 - if (FDCS->reset) { 2970 + fdc_state[current_fdc].reset = 1; 2971 + if (fdc_state[current_fdc].reset) { 3009 2972 cont = &reset_cont; 3010 2973 ret = wait_til_done(reset_fdc, interruptible); 3011 2974 if (ret == -EINTR) ··· 3038 3001 if (type) 3039 3002 floppy = floppy_type + type; 3040 3003 else { 3041 - if (UDP->native_format) 3042 - floppy = floppy_type + UDP->native_format; 3004 + if (drive_params[drive].native_format) 3005 + floppy = floppy_type + drive_params[drive].native_format; 3043 3006 else 3044 3007 return "(null)"; 3045 3008 } ··· 3216 3179 int ret2; 3217 3180 int ret; 3218 3181 3219 - if (FDCS->rawcmd <= 1) 3220 - FDCS->rawcmd = 1; 3182 + if (fdc_state[current_fdc].rawcmd <= 1) 3183 + fdc_state[current_fdc].rawcmd = 1; 3221 3184 for (drive = 0; drive < N_DRIVE; drive++) { 3222 - if (FDC(drive) != fdc) 3185 + if (FDC(drive) != current_fdc) 3223 3186 continue; 3224 3187 if (drive == current_drive) { 3225 - if (UDRS->fd_ref > 1) { 3226 - FDCS->rawcmd = 2; 3188 + if (drive_state[drive].fd_ref > 1) { 3189 + fdc_state[current_fdc].rawcmd = 2; 3227 3190 break; 3228 3191 } 3229 - } else if (UDRS->fd_ref) { 3230 - FDCS->rawcmd = 2; 3192 + } else if (drive_state[drive].fd_ref) { 3193 + fdc_state[current_fdc].rawcmd = 2; 3231 3194 break; 3232 3195 } 3233 3196 } 3234 3197 3235 - if (FDCS->reset) 3198 + if (fdc_state[current_fdc].reset) 3236 3199 return -EIO; 3237 3200 3238 3201 ret = raw_cmd_copyin(cmd, param, &my_raw_cmd); ··· 3244 3207 raw_cmd = my_raw_cmd; 3245 3208 cont = &raw_cmd_cont; 3246 3209 ret = wait_til_done(floppy_start, true); 3247 - debug_dcl(DP->flags, "calling disk change from raw_cmd ioctl\n"); 3210 + debug_dcl(drive_params[current_drive].flags, 3211 + "calling disk change from raw_cmd ioctl\n"); 3248 3212 3249 - if (ret != -EINTR && FDCS->reset) 3213 + if (ret != -EINTR && fdc_state[current_fdc].reset) 3250 3214 ret = -EIO; 3251 3215 3252 - DRS->track = NO_TRACK; 3216 + drive_state[current_drive].track = NO_TRACK; 3253 3217 3254 3218 ret2 = raw_cmd_copyout(cmd, param, my_raw_cmd); 3255 3219 if (!ret) ··· 3278 3240 (int)g->head <= 0 || 3279 3241 /* check for overflow in max_sector */ 3280 3242 (int)(g->sect * g->head) <= 0 || 3281 - /* check for zero in F_SECT_PER_TRACK */ 3243 + /* check for zero in raw_cmd->cmd[F_SECT_PER_TRACK] */ 3282 3244 (unsigned char)((g->sect << 2) >> FD_SIZECODE(g)) == 0 || 3283 - g->track <= 0 || g->track > UDP->tracks >> STRETCH(g) || 3245 + g->track <= 0 || g->track > drive_params[drive].tracks >> STRETCH(g) || 3284 3246 /* check if reserved bits are set */ 3285 3247 (g->stretch & ~(FD_STRETCH | FD_SWAPSIDES | FD_SECTBASEMASK)) != 0) 3286 3248 return -EINVAL; ··· 3323 3285 current_type[drive] = &user_params[drive]; 3324 3286 floppy_sizes[drive] = user_params[drive].size; 3325 3287 if (cmd == FDDEFPRM) 3326 - DRS->keep_data = -1; 3288 + drive_state[current_drive].keep_data = -1; 3327 3289 else 3328 - DRS->keep_data = 1; 3290 + drive_state[current_drive].keep_data = 1; 3329 3291 /* invalidation. Invalidate only when needed, i.e. 3330 3292 * when there are already sectors in the buffer cache 3331 3293 * whose number will change. This is useful, because 3332 3294 * mtools often changes the geometry of the disk after 3333 3295 * looking at the boot block */ 3334 - if (DRS->maxblock > user_params[drive].sect || 3335 - DRS->maxtrack || 3296 + if (drive_state[current_drive].maxblock > user_params[drive].sect || 3297 + drive_state[current_drive].maxtrack || 3336 3298 ((user_params[drive].sect ^ oldStretch) & 3337 3299 (FD_SWAPSIDES | FD_SECTBASEMASK))) 3338 3300 invalidate_drive(bdev); ··· 3445 3407 unsigned long param) 3446 3408 { 3447 3409 int drive = (long)bdev->bd_disk->private_data; 3448 - int type = ITYPE(UDRS->fd_device); 3410 + int type = ITYPE(drive_state[drive].fd_device); 3449 3411 int i; 3450 3412 int ret; 3451 3413 int size; ··· 3493 3455 3494 3456 switch (cmd) { 3495 3457 case FDEJECT: 3496 - if (UDRS->fd_ref != 1) 3458 + if (drive_state[drive].fd_ref != 1) 3497 3459 /* somebody else has this drive open */ 3498 3460 return -EBUSY; 3499 3461 if (lock_fdc(drive)) ··· 3503 3465 * non-Sparc architectures */ 3504 3466 ret = fd_eject(UNIT(drive)); 3505 3467 3506 - set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); 3507 - set_bit(FD_VERIFY_BIT, &UDRS->flags); 3468 + set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags); 3469 + set_bit(FD_VERIFY_BIT, &drive_state[drive].flags); 3508 3470 process_fd_request(); 3509 3471 return ret; 3510 3472 case FDCLRPRM: ··· 3512 3474 return -EINTR; 3513 3475 current_type[drive] = NULL; 3514 3476 floppy_sizes[drive] = MAX_DISK_SIZE << 1; 3515 - UDRS->keep_data = 0; 3477 + drive_state[drive].keep_data = 0; 3516 3478 return invalidate_drive(bdev); 3517 3479 case FDSETPRM: 3518 3480 case FDDEFPRM: ··· 3527 3489 outparam = &inparam.g; 3528 3490 break; 3529 3491 case FDMSGON: 3530 - UDP->flags |= FTD_MSG; 3492 + drive_params[drive].flags |= FTD_MSG; 3531 3493 return 0; 3532 3494 case FDMSGOFF: 3533 - UDP->flags &= ~FTD_MSG; 3495 + drive_params[drive].flags &= ~FTD_MSG; 3534 3496 return 0; 3535 3497 case FDFMTBEG: 3536 3498 if (lock_fdc(drive)) 3537 3499 return -EINTR; 3538 3500 if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR) 3539 3501 return -EINTR; 3540 - ret = UDRS->flags; 3502 + ret = drive_state[drive].flags; 3541 3503 process_fd_request(); 3542 3504 if (ret & FD_VERIFY) 3543 3505 return -ENODEV; ··· 3545 3507 return -EROFS; 3546 3508 return 0; 3547 3509 case FDFMTTRK: 3548 - if (UDRS->fd_ref != 1) 3510 + if (drive_state[drive].fd_ref != 1) 3549 3511 return -EBUSY; 3550 3512 return do_format(drive, &inparam.f); 3551 3513 case FDFMTEND: ··· 3554 3516 return -EINTR; 3555 3517 return invalidate_drive(bdev); 3556 3518 case FDSETEMSGTRESH: 3557 - UDP->max_errors.reporting = (unsigned short)(param & 0x0f); 3519 + drive_params[drive].max_errors.reporting = (unsigned short)(param & 0x0f); 3558 3520 return 0; 3559 3521 case FDGETMAXERRS: 3560 - outparam = &UDP->max_errors; 3522 + outparam = &drive_params[drive].max_errors; 3561 3523 break; 3562 3524 case FDSETMAXERRS: 3563 - UDP->max_errors = inparam.max_errors; 3525 + drive_params[drive].max_errors = inparam.max_errors; 3564 3526 break; 3565 3527 case FDGETDRVTYP: 3566 3528 outparam = drive_name(type, drive); ··· 3570 3532 if (!valid_floppy_drive_params(inparam.dp.autodetect, 3571 3533 inparam.dp.native_format)) 3572 3534 return -EINVAL; 3573 - *UDP = inparam.dp; 3535 + drive_params[drive] = inparam.dp; 3574 3536 break; 3575 3537 case FDGETDRVPRM: 3576 - outparam = UDP; 3538 + outparam = &drive_params[drive]; 3577 3539 break; 3578 3540 case FDPOLLDRVSTAT: 3579 3541 if (lock_fdc(drive)) ··· 3583 3545 process_fd_request(); 3584 3546 /* fall through */ 3585 3547 case FDGETDRVSTAT: 3586 - outparam = UDRS; 3548 + outparam = &drive_state[drive]; 3587 3549 break; 3588 3550 case FDRESET: 3589 3551 return user_reset_fdc(drive, (int)param, true); 3590 3552 case FDGETFDCSTAT: 3591 - outparam = UFDCS; 3553 + outparam = &fdc_state[FDC(drive)]; 3592 3554 break; 3593 3555 case FDWERRORCLR: 3594 - memset(UDRWE, 0, sizeof(*UDRWE)); 3556 + memset(&write_errors[drive], 0, sizeof(write_errors[drive])); 3595 3557 return 0; 3596 3558 case FDWERRORGET: 3597 - outparam = UDRWE; 3559 + outparam = &write_errors[drive]; 3598 3560 break; 3599 3561 case FDRAWCMD: 3600 3562 if (type) ··· 3730 3692 3731 3693 mutex_lock(&floppy_mutex); 3732 3694 drive = (long)bdev->bd_disk->private_data; 3733 - type = ITYPE(UDRS->fd_device); 3695 + type = ITYPE(drive_state[drive].fd_device); 3734 3696 err = set_geometry(cmd == FDSETPRM32 ? FDSETPRM : FDDEFPRM, 3735 3697 &v, drive, type, bdev); 3736 3698 mutex_unlock(&floppy_mutex); ··· 3746 3708 3747 3709 memset(&v, 0, sizeof(v)); 3748 3710 mutex_lock(&floppy_mutex); 3749 - err = get_floppy_geometry(drive, ITYPE(UDRS->fd_device), &p); 3711 + err = get_floppy_geometry(drive, ITYPE(drive_state[drive].fd_device), 3712 + &p); 3750 3713 if (err) { 3751 3714 mutex_unlock(&floppy_mutex); 3752 3715 return err; ··· 3771 3732 if (!valid_floppy_drive_params(v.autodetect, v.native_format)) 3772 3733 return -EINVAL; 3773 3734 mutex_lock(&floppy_mutex); 3774 - UDP->cmos = v.cmos; 3775 - UDP->max_dtr = v.max_dtr; 3776 - UDP->hlt = v.hlt; 3777 - UDP->hut = v.hut; 3778 - UDP->srt = v.srt; 3779 - UDP->spinup = v.spinup; 3780 - UDP->spindown = v.spindown; 3781 - UDP->spindown_offset = v.spindown_offset; 3782 - UDP->select_delay = v.select_delay; 3783 - UDP->rps = v.rps; 3784 - UDP->tracks = v.tracks; 3785 - UDP->timeout = v.timeout; 3786 - UDP->interleave_sect = v.interleave_sect; 3787 - UDP->max_errors = v.max_errors; 3788 - UDP->flags = v.flags; 3789 - UDP->read_track = v.read_track; 3790 - memcpy(UDP->autodetect, v.autodetect, sizeof(v.autodetect)); 3791 - UDP->checkfreq = v.checkfreq; 3792 - UDP->native_format = v.native_format; 3735 + drive_params[drive].cmos = v.cmos; 3736 + drive_params[drive].max_dtr = v.max_dtr; 3737 + drive_params[drive].hlt = v.hlt; 3738 + drive_params[drive].hut = v.hut; 3739 + drive_params[drive].srt = v.srt; 3740 + drive_params[drive].spinup = v.spinup; 3741 + drive_params[drive].spindown = v.spindown; 3742 + drive_params[drive].spindown_offset = v.spindown_offset; 3743 + drive_params[drive].select_delay = v.select_delay; 3744 + drive_params[drive].rps = v.rps; 3745 + drive_params[drive].tracks = v.tracks; 3746 + drive_params[drive].timeout = v.timeout; 3747 + drive_params[drive].interleave_sect = v.interleave_sect; 3748 + drive_params[drive].max_errors = v.max_errors; 3749 + drive_params[drive].flags = v.flags; 3750 + drive_params[drive].read_track = v.read_track; 3751 + memcpy(drive_params[drive].autodetect, v.autodetect, 3752 + sizeof(v.autodetect)); 3753 + drive_params[drive].checkfreq = v.checkfreq; 3754 + drive_params[drive].native_format = v.native_format; 3793 3755 mutex_unlock(&floppy_mutex); 3794 3756 return 0; 3795 3757 } ··· 3802 3762 3803 3763 memset(&v, 0, sizeof(struct compat_floppy_drive_params)); 3804 3764 mutex_lock(&floppy_mutex); 3805 - v.cmos = UDP->cmos; 3806 - v.max_dtr = UDP->max_dtr; 3807 - v.hlt = UDP->hlt; 3808 - v.hut = UDP->hut; 3809 - v.srt = UDP->srt; 3810 - v.spinup = UDP->spinup; 3811 - v.spindown = UDP->spindown; 3812 - v.spindown_offset = UDP->spindown_offset; 3813 - v.select_delay = UDP->select_delay; 3814 - v.rps = UDP->rps; 3815 - v.tracks = UDP->tracks; 3816 - v.timeout = UDP->timeout; 3817 - v.interleave_sect = UDP->interleave_sect; 3818 - v.max_errors = UDP->max_errors; 3819 - v.flags = UDP->flags; 3820 - v.read_track = UDP->read_track; 3821 - memcpy(v.autodetect, UDP->autodetect, sizeof(v.autodetect)); 3822 - v.checkfreq = UDP->checkfreq; 3823 - v.native_format = UDP->native_format; 3765 + v.cmos = drive_params[drive].cmos; 3766 + v.max_dtr = drive_params[drive].max_dtr; 3767 + v.hlt = drive_params[drive].hlt; 3768 + v.hut = drive_params[drive].hut; 3769 + v.srt = drive_params[drive].srt; 3770 + v.spinup = drive_params[drive].spinup; 3771 + v.spindown = drive_params[drive].spindown; 3772 + v.spindown_offset = drive_params[drive].spindown_offset; 3773 + v.select_delay = drive_params[drive].select_delay; 3774 + v.rps = drive_params[drive].rps; 3775 + v.tracks = drive_params[drive].tracks; 3776 + v.timeout = drive_params[drive].timeout; 3777 + v.interleave_sect = drive_params[drive].interleave_sect; 3778 + v.max_errors = drive_params[drive].max_errors; 3779 + v.flags = drive_params[drive].flags; 3780 + v.read_track = drive_params[drive].read_track; 3781 + memcpy(v.autodetect, drive_params[drive].autodetect, 3782 + sizeof(v.autodetect)); 3783 + v.checkfreq = drive_params[drive].checkfreq; 3784 + v.native_format = drive_params[drive].native_format; 3824 3785 mutex_unlock(&floppy_mutex); 3825 3786 3826 3787 if (copy_to_user(arg, &v, sizeof(struct compat_floppy_drive_params))) ··· 3844 3803 goto Eintr; 3845 3804 process_fd_request(); 3846 3805 } 3847 - v.spinup_date = UDRS->spinup_date; 3848 - v.select_date = UDRS->select_date; 3849 - v.first_read_date = UDRS->first_read_date; 3850 - v.probed_format = UDRS->probed_format; 3851 - v.track = UDRS->track; 3852 - v.maxblock = UDRS->maxblock; 3853 - v.maxtrack = UDRS->maxtrack; 3854 - v.generation = UDRS->generation; 3855 - v.keep_data = UDRS->keep_data; 3856 - v.fd_ref = UDRS->fd_ref; 3857 - v.fd_device = UDRS->fd_device; 3858 - v.last_checked = UDRS->last_checked; 3859 - v.dmabuf = (uintptr_t)UDRS->dmabuf; 3860 - v.bufblocks = UDRS->bufblocks; 3806 + v.spinup_date = drive_state[drive].spinup_date; 3807 + v.select_date = drive_state[drive].select_date; 3808 + v.first_read_date = drive_state[drive].first_read_date; 3809 + v.probed_format = drive_state[drive].probed_format; 3810 + v.track = drive_state[drive].track; 3811 + v.maxblock = drive_state[drive].maxblock; 3812 + v.maxtrack = drive_state[drive].maxtrack; 3813 + v.generation = drive_state[drive].generation; 3814 + v.keep_data = drive_state[drive].keep_data; 3815 + v.fd_ref = drive_state[drive].fd_ref; 3816 + v.fd_device = drive_state[drive].fd_device; 3817 + v.last_checked = drive_state[drive].last_checked; 3818 + v.dmabuf = (uintptr_t) drive_state[drive].dmabuf; 3819 + v.bufblocks = drive_state[drive].bufblocks; 3861 3820 mutex_unlock(&floppy_mutex); 3862 3821 3863 3822 if (copy_to_user(arg, &v, sizeof(struct compat_floppy_drive_struct))) ··· 3875 3834 struct floppy_fdc_state v; 3876 3835 3877 3836 mutex_lock(&floppy_mutex); 3878 - v = *UFDCS; 3837 + v = fdc_state[FDC(drive)]; 3879 3838 mutex_unlock(&floppy_mutex); 3880 3839 3881 3840 memset(&v32, 0, sizeof(struct compat_floppy_fdc_state)); ··· 3905 3864 3906 3865 memset(&v32, 0, sizeof(struct compat_floppy_write_errors)); 3907 3866 mutex_lock(&floppy_mutex); 3908 - v = *UDRWE; 3867 + v = write_errors[drive]; 3909 3868 mutex_unlock(&floppy_mutex); 3910 3869 v32.write_errors = v.write_errors; 3911 3870 v32.first_error_sector = v.first_error_sector; ··· 3974 3933 3975 3934 /* read drive info out of physical CMOS */ 3976 3935 drive = 0; 3977 - if (!UDP->cmos) 3978 - UDP->cmos = FLOPPY0_TYPE; 3936 + if (!drive_params[drive].cmos) 3937 + drive_params[drive].cmos = FLOPPY0_TYPE; 3979 3938 drive = 1; 3980 - if (!UDP->cmos) 3981 - UDP->cmos = FLOPPY1_TYPE; 3939 + if (!drive_params[drive].cmos) 3940 + drive_params[drive].cmos = FLOPPY1_TYPE; 3982 3941 3983 3942 /* FIXME: additional physical CMOS drive detection should go here */ 3984 3943 3985 3944 for (drive = 0; drive < N_DRIVE; drive++) { 3986 - unsigned int type = UDP->cmos; 3945 + unsigned int type = drive_params[drive].cmos; 3987 3946 struct floppy_drive_params *params; 3988 3947 const char *name = NULL; 3989 3948 char temparea[32]; ··· 4013 3972 4014 3973 pr_cont("%s fd%d is %s", prepend, drive, name); 4015 3974 } 4016 - *UDP = *params; 3975 + drive_params[drive] = *params; 4017 3976 } 4018 3977 4019 3978 if (has_drive) ··· 4026 3985 4027 3986 mutex_lock(&floppy_mutex); 4028 3987 mutex_lock(&open_lock); 4029 - if (!UDRS->fd_ref--) { 3988 + if (!drive_state[drive].fd_ref--) { 4030 3989 DPRINT("floppy_release with fd_ref == 0"); 4031 - UDRS->fd_ref = 0; 3990 + drive_state[drive].fd_ref = 0; 4032 3991 } 4033 - if (!UDRS->fd_ref) 3992 + if (!drive_state[drive].fd_ref) 4034 3993 opened_bdev[drive] = NULL; 4035 3994 mutex_unlock(&open_lock); 4036 3995 mutex_unlock(&floppy_mutex); ··· 4051 4010 4052 4011 mutex_lock(&floppy_mutex); 4053 4012 mutex_lock(&open_lock); 4054 - old_dev = UDRS->fd_device; 4013 + old_dev = drive_state[drive].fd_device; 4055 4014 if (opened_bdev[drive] && opened_bdev[drive] != bdev) 4056 4015 goto out2; 4057 4016 4058 - if (!UDRS->fd_ref && (UDP->flags & FD_BROKEN_DCL)) { 4059 - set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); 4060 - set_bit(FD_VERIFY_BIT, &UDRS->flags); 4017 + if (!drive_state[drive].fd_ref && (drive_params[drive].flags & FD_BROKEN_DCL)) { 4018 + set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags); 4019 + set_bit(FD_VERIFY_BIT, &drive_state[drive].flags); 4061 4020 } 4062 4021 4063 - UDRS->fd_ref++; 4022 + drive_state[drive].fd_ref++; 4064 4023 4065 4024 opened_bdev[drive] = bdev; 4066 4025 ··· 4069 4028 if (!floppy_track_buffer) { 4070 4029 /* if opening an ED drive, reserve a big buffer, 4071 4030 * else reserve a small one */ 4072 - if ((UDP->cmos == 6) || (UDP->cmos == 5)) 4031 + if ((drive_params[drive].cmos == 6) || (drive_params[drive].cmos == 5)) 4073 4032 try = 64; /* Only 48 actually useful */ 4074 4033 else 4075 4034 try = 32; /* Only 24 actually useful */ ··· 4097 4056 } 4098 4057 4099 4058 new_dev = MINOR(bdev->bd_dev); 4100 - UDRS->fd_device = new_dev; 4059 + drive_state[drive].fd_device = new_dev; 4101 4060 set_capacity(disks[drive], floppy_sizes[new_dev]); 4102 4061 if (old_dev != -1 && old_dev != new_dev) { 4103 4062 if (buffer_drive == drive) 4104 4063 buffer_track = -1; 4105 4064 } 4106 4065 4107 - if (UFDCS->rawcmd == 1) 4108 - UFDCS->rawcmd = 2; 4066 + if (fdc_state[FDC(drive)].rawcmd == 1) 4067 + fdc_state[FDC(drive)].rawcmd = 2; 4109 4068 4110 4069 if (!(mode & FMODE_NDELAY)) { 4111 4070 if (mode & (FMODE_READ|FMODE_WRITE)) { 4112 - UDRS->last_checked = 0; 4113 - clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags); 4071 + drive_state[drive].last_checked = 0; 4072 + clear_bit(FD_OPEN_SHOULD_FAIL_BIT, 4073 + &drive_state[drive].flags); 4114 4074 check_disk_change(bdev); 4115 - if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags)) 4075 + if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags)) 4116 4076 goto out; 4117 - if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags)) 4077 + if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags)) 4118 4078 goto out; 4119 4079 } 4120 4080 res = -EROFS; 4121 4081 if ((mode & FMODE_WRITE) && 4122 - !test_bit(FD_DISK_WRITABLE_BIT, &UDRS->flags)) 4082 + !test_bit(FD_DISK_WRITABLE_BIT, &drive_state[drive].flags)) 4123 4083 goto out; 4124 4084 } 4125 4085 mutex_unlock(&open_lock); 4126 4086 mutex_unlock(&floppy_mutex); 4127 4087 return 0; 4128 4088 out: 4129 - UDRS->fd_ref--; 4089 + drive_state[drive].fd_ref--; 4130 4090 4131 - if (!UDRS->fd_ref) 4091 + if (!drive_state[drive].fd_ref) 4132 4092 opened_bdev[drive] = NULL; 4133 4093 out2: 4134 4094 mutex_unlock(&open_lock); ··· 4145 4103 { 4146 4104 int drive = (long)disk->private_data; 4147 4105 4148 - if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || 4149 - test_bit(FD_VERIFY_BIT, &UDRS->flags)) 4106 + if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) || 4107 + test_bit(FD_VERIFY_BIT, &drive_state[drive].flags)) 4150 4108 return DISK_EVENT_MEDIA_CHANGE; 4151 4109 4152 - if (time_after(jiffies, UDRS->last_checked + UDP->checkfreq)) { 4110 + if (time_after(jiffies, drive_state[drive].last_checked + drive_params[drive].checkfreq)) { 4153 4111 if (lock_fdc(drive)) 4154 4112 return 0; 4155 4113 poll_drive(false, 0); 4156 4114 process_fd_request(); 4157 4115 } 4158 4116 4159 - if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || 4160 - test_bit(FD_VERIFY_BIT, &UDRS->flags) || 4117 + if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) || 4118 + test_bit(FD_VERIFY_BIT, &drive_state[drive].flags) || 4161 4119 test_bit(drive, &fake_change) || 4162 4120 drive_no_geom(drive)) 4163 4121 return DISK_EVENT_MEDIA_CHANGE; ··· 4183 4141 if (bio->bi_status) { 4184 4142 pr_info("floppy: error %d while reading block 0\n", 4185 4143 bio->bi_status); 4186 - set_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags); 4144 + set_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags); 4187 4145 } 4188 4146 complete(&cbdata->complete); 4189 4147 } ··· 4240 4198 int cf; 4241 4199 int res = 0; 4242 4200 4243 - if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || 4244 - test_bit(FD_VERIFY_BIT, &UDRS->flags) || 4201 + if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) || 4202 + test_bit(FD_VERIFY_BIT, &drive_state[drive].flags) || 4245 4203 test_bit(drive, &fake_change) || 4246 4204 drive_no_geom(drive)) { 4247 4205 if (WARN(atomic_read(&usage_count) == 0, ··· 4251 4209 res = lock_fdc(drive); 4252 4210 if (res) 4253 4211 return res; 4254 - cf = (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || 4255 - test_bit(FD_VERIFY_BIT, &UDRS->flags)); 4212 + cf = (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) || 4213 + test_bit(FD_VERIFY_BIT, &drive_state[drive].flags)); 4256 4214 if (!(cf || test_bit(drive, &fake_change) || drive_no_geom(drive))) { 4257 4215 process_fd_request(); /*already done by another thread */ 4258 4216 return 0; 4259 4217 } 4260 - UDRS->maxblock = 0; 4261 - UDRS->maxtrack = 0; 4218 + drive_state[drive].maxblock = 0; 4219 + drive_state[drive].maxtrack = 0; 4262 4220 if (buffer_drive == drive) 4263 4221 buffer_track = -1; 4264 4222 clear_bit(drive, &fake_change); 4265 - clear_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); 4223 + clear_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags); 4266 4224 if (cf) 4267 - UDRS->generation++; 4225 + drive_state[drive].generation++; 4268 4226 if (drive_no_geom(drive)) { 4269 4227 /* auto-sensing */ 4270 4228 res = __floppy_read_block_0(opened_bdev[drive], drive); ··· 4274 4232 process_fd_request(); 4275 4233 } 4276 4234 } 4277 - set_capacity(disk, floppy_sizes[UDRS->fd_device]); 4235 + set_capacity(disk, floppy_sizes[drive_state[drive].fd_device]); 4278 4236 return res; 4279 4237 } 4280 4238 ··· 4303 4261 int r; 4304 4262 4305 4263 output_byte(FD_DUMPREGS); /* 82072 and better know DUMPREGS */ 4306 - if (FDCS->reset) 4264 + if (fdc_state[current_fdc].reset) 4307 4265 return FDC_NONE; 4308 4266 r = result(); 4309 4267 if (r <= 0x00) 4310 4268 return FDC_NONE; /* No FDC present ??? */ 4311 4269 if ((r == 1) && (reply_buffer[0] == 0x80)) { 4312 - pr_info("FDC %d is an 8272A\n", fdc); 4270 + pr_info("FDC %d is an 8272A\n", current_fdc); 4313 4271 return FDC_8272A; /* 8272a/765 don't know DUMPREGS */ 4314 4272 } 4315 4273 if (r != 10) { 4316 4274 pr_info("FDC %d init: DUMPREGS: unexpected return of %d bytes.\n", 4317 - fdc, r); 4275 + current_fdc, r); 4318 4276 return FDC_UNKNOWN; 4319 4277 } 4320 4278 4321 4279 if (!fdc_configure()) { 4322 - pr_info("FDC %d is an 82072\n", fdc); 4280 + pr_info("FDC %d is an 82072\n", current_fdc); 4323 4281 return FDC_82072; /* 82072 doesn't know CONFIGURE */ 4324 4282 } 4325 4283 ··· 4327 4285 if (need_more_output() == MORE_OUTPUT) { 4328 4286 output_byte(0); 4329 4287 } else { 4330 - pr_info("FDC %d is an 82072A\n", fdc); 4288 + pr_info("FDC %d is an 82072A\n", current_fdc); 4331 4289 return FDC_82072A; /* 82072A as found on Sparcs. */ 4332 4290 } 4333 4291 4334 4292 output_byte(FD_UNLOCK); 4335 4293 r = result(); 4336 4294 if ((r == 1) && (reply_buffer[0] == 0x80)) { 4337 - pr_info("FDC %d is a pre-1991 82077\n", fdc); 4295 + pr_info("FDC %d is a pre-1991 82077\n", current_fdc); 4338 4296 return FDC_82077_ORIG; /* Pre-1991 82077, doesn't know 4339 4297 * LOCK/UNLOCK */ 4340 4298 } 4341 4299 if ((r != 1) || (reply_buffer[0] != 0x00)) { 4342 4300 pr_info("FDC %d init: UNLOCK: unexpected return of %d bytes.\n", 4343 - fdc, r); 4301 + current_fdc, r); 4344 4302 return FDC_UNKNOWN; 4345 4303 } 4346 4304 output_byte(FD_PARTID); 4347 4305 r = result(); 4348 4306 if (r != 1) { 4349 4307 pr_info("FDC %d init: PARTID: unexpected return of %d bytes.\n", 4350 - fdc, r); 4308 + current_fdc, r); 4351 4309 return FDC_UNKNOWN; 4352 4310 } 4353 4311 if (reply_buffer[0] == 0x80) { 4354 - pr_info("FDC %d is a post-1991 82077\n", fdc); 4312 + pr_info("FDC %d is a post-1991 82077\n", current_fdc); 4355 4313 return FDC_82077; /* Revised 82077AA passes all the tests */ 4356 4314 } 4357 4315 switch (reply_buffer[0] >> 5) { 4358 4316 case 0x0: 4359 4317 /* Either a 82078-1 or a 82078SL running at 5Volt */ 4360 - pr_info("FDC %d is an 82078.\n", fdc); 4318 + pr_info("FDC %d is an 82078.\n", current_fdc); 4361 4319 return FDC_82078; 4362 4320 case 0x1: 4363 - pr_info("FDC %d is a 44pin 82078\n", fdc); 4321 + pr_info("FDC %d is a 44pin 82078\n", current_fdc); 4364 4322 return FDC_82078; 4365 4323 case 0x2: 4366 - pr_info("FDC %d is a S82078B\n", fdc); 4324 + pr_info("FDC %d is a S82078B\n", current_fdc); 4367 4325 return FDC_S82078B; 4368 4326 case 0x3: 4369 - pr_info("FDC %d is a National Semiconductor PC87306\n", fdc); 4327 + pr_info("FDC %d is a National Semiconductor PC87306\n", current_fdc); 4370 4328 return FDC_87306; 4371 4329 default: 4372 4330 pr_info("FDC %d init: 82078 variant with unknown PARTID=%d.\n", 4373 - fdc, reply_buffer[0] >> 5); 4331 + current_fdc, reply_buffer[0] >> 5); 4374 4332 return FDC_82078_UNKN; 4375 4333 } 4376 4334 } /* get_fdc_version */ ··· 4426 4384 if (current_drive >= 4 && !FDC2) 4427 4385 FDC2 = 0x370; 4428 4386 #endif 4429 - DP->cmos = ints[2]; 4387 + drive_params[current_drive].cmos = ints[2]; 4430 4388 DPRINT("setting CMOS code to %d\n", ints[2]); 4431 4389 } 4432 4390 ··· 4515 4473 int drive; 4516 4474 4517 4475 drive = p->id; 4518 - return sprintf(buf, "%X\n", UDP->cmos); 4476 + return sprintf(buf, "%X\n", drive_params[drive].cmos); 4519 4477 } 4520 4478 4521 4479 static DEVICE_ATTR(cmos, 0444, floppy_cmos_show, NULL); ··· 4536 4494 int fdc; 4537 4495 4538 4496 for (fdc = 0; fdc < N_FDC; fdc++) 4539 - if (FDCS->address != -1) 4497 + if (fdc_state[fdc].address != -1) 4540 4498 user_reset_fdc(-1, FD_RESET_ALWAYS, false); 4541 4499 4542 4500 return 0; ··· 4646 4604 config_types(); 4647 4605 4648 4606 for (i = 0; i < N_FDC; i++) { 4649 - fdc = i; 4650 - memset(FDCS, 0, sizeof(*FDCS)); 4651 - FDCS->dtr = -1; 4652 - FDCS->dor = 0x4; 4607 + current_fdc = i; 4608 + memset(&fdc_state[current_fdc], 0, sizeof(*fdc_state)); 4609 + fdc_state[current_fdc].dtr = -1; 4610 + fdc_state[current_fdc].dor = 0x4; 4653 4611 #if defined(__sparc__) || defined(__mc68000__) 4654 4612 /*sparcs/sun3x don't have a DOR reset which we can fall back on to */ 4655 4613 #ifdef __mc68000__ 4656 4614 if (MACH_IS_SUN3X) 4657 4615 #endif 4658 - FDCS->version = FDC_82072A; 4616 + fdc_state[current_fdc].version = FDC_82072A; 4659 4617 #endif 4660 4618 } 4661 4619 ··· 4670 4628 fdc_state[1].address = FDC2; 4671 4629 #endif 4672 4630 4673 - fdc = 0; /* reset fdc in case of unexpected interrupt */ 4631 + current_fdc = 0; /* reset fdc in case of unexpected interrupt */ 4674 4632 err = floppy_grab_irq_and_dma(); 4675 4633 if (err) { 4676 4634 cancel_delayed_work(&fd_timeout); ··· 4680 4638 4681 4639 /* initialise drive state */ 4682 4640 for (drive = 0; drive < N_DRIVE; drive++) { 4683 - memset(UDRS, 0, sizeof(*UDRS)); 4684 - memset(UDRWE, 0, sizeof(*UDRWE)); 4685 - set_bit(FD_DISK_NEWCHANGE_BIT, &UDRS->flags); 4686 - set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); 4687 - set_bit(FD_VERIFY_BIT, &UDRS->flags); 4688 - UDRS->fd_device = -1; 4641 + memset(&drive_state[drive], 0, sizeof(drive_state[drive])); 4642 + memset(&write_errors[drive], 0, sizeof(write_errors[drive])); 4643 + set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[drive].flags); 4644 + set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags); 4645 + set_bit(FD_VERIFY_BIT, &drive_state[drive].flags); 4646 + drive_state[drive].fd_device = -1; 4689 4647 floppy_track_buffer = NULL; 4690 4648 max_buffer_sectors = 0; 4691 4649 } ··· 4697 4655 msleep(10); 4698 4656 4699 4657 for (i = 0; i < N_FDC; i++) { 4700 - fdc = i; 4701 - FDCS->driver_version = FD_DRIVER_VERSION; 4658 + current_fdc = i; 4659 + fdc_state[current_fdc].driver_version = FD_DRIVER_VERSION; 4702 4660 for (unit = 0; unit < 4; unit++) 4703 - FDCS->track[unit] = 0; 4704 - if (FDCS->address == -1) 4661 + fdc_state[current_fdc].track[unit] = 0; 4662 + if (fdc_state[current_fdc].address == -1) 4705 4663 continue; 4706 - FDCS->rawcmd = 2; 4664 + fdc_state[current_fdc].rawcmd = 2; 4707 4665 if (user_reset_fdc(-1, FD_RESET_ALWAYS, false)) { 4708 4666 /* free ioports reserved by floppy_grab_irq_and_dma() */ 4709 - floppy_release_regions(fdc); 4710 - FDCS->address = -1; 4711 - FDCS->version = FDC_NONE; 4667 + floppy_release_regions(current_fdc); 4668 + fdc_state[current_fdc].address = -1; 4669 + fdc_state[current_fdc].version = FDC_NONE; 4712 4670 continue; 4713 4671 } 4714 4672 /* Try to determine the floppy controller type */ 4715 - FDCS->version = get_fdc_version(); 4716 - if (FDCS->version == FDC_NONE) { 4673 + fdc_state[current_fdc].version = get_fdc_version(); 4674 + if (fdc_state[current_fdc].version == FDC_NONE) { 4717 4675 /* free ioports reserved by floppy_grab_irq_and_dma() */ 4718 - floppy_release_regions(fdc); 4719 - FDCS->address = -1; 4676 + floppy_release_regions(current_fdc); 4677 + fdc_state[current_fdc].address = -1; 4720 4678 continue; 4721 4679 } 4722 - if (can_use_virtual_dma == 2 && FDCS->version < FDC_82072A) 4680 + if (can_use_virtual_dma == 2 && 4681 + fdc_state[current_fdc].version < FDC_82072A) 4723 4682 can_use_virtual_dma = 0; 4724 4683 4725 4684 have_no_fdc = 0; ··· 4730 4687 */ 4731 4688 user_reset_fdc(-1, FD_RESET_ALWAYS, false); 4732 4689 } 4733 - fdc = 0; 4690 + current_fdc = 0; 4734 4691 cancel_delayed_work(&fd_timeout); 4735 4692 current_drive = 0; 4736 4693 initialized = true; ··· 4826 4783 { 4827 4784 while (p != io_regions) { 4828 4785 p--; 4829 - release_region(FDCS->address + p->offset, p->size); 4786 + release_region(fdc_state[fdc].address + p->offset, p->size); 4830 4787 } 4831 4788 } 4832 4789 ··· 4837 4794 const struct io_region *p; 4838 4795 4839 4796 for (p = io_regions; p < ARRAY_END(io_regions); p++) { 4840 - if (!request_region(FDCS->address + p->offset, 4797 + if (!request_region(fdc_state[fdc].address + p->offset, 4841 4798 p->size, "floppy")) { 4842 4799 DPRINT("Floppy io-port 0x%04lx in use\n", 4843 - FDCS->address + p->offset); 4800 + fdc_state[fdc].address + p->offset); 4844 4801 floppy_release_allocated_regions(fdc, p); 4845 4802 return -EBUSY; 4846 4803 } ··· 4882 4839 } 4883 4840 } 4884 4841 4885 - for (fdc = 0; fdc < N_FDC; fdc++) { 4886 - if (FDCS->address != -1) { 4887 - if (floppy_request_regions(fdc)) 4842 + for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) { 4843 + if (fdc_state[current_fdc].address != -1) { 4844 + if (floppy_request_regions(current_fdc)) 4888 4845 goto cleanup; 4889 4846 } 4890 4847 } 4891 - for (fdc = 0; fdc < N_FDC; fdc++) { 4892 - if (FDCS->address != -1) { 4848 + for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) { 4849 + if (fdc_state[current_fdc].address != -1) { 4893 4850 reset_fdc_info(1); 4894 - fd_outb(FDCS->dor, FD_DOR); 4851 + fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR); 4895 4852 } 4896 4853 } 4897 - fdc = 0; 4854 + current_fdc = 0; 4898 4855 set_dor(0, ~0, 8); /* avoid immediate interrupt */ 4899 4856 4900 - for (fdc = 0; fdc < N_FDC; fdc++) 4901 - if (FDCS->address != -1) 4902 - fd_outb(FDCS->dor, FD_DOR); 4857 + for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) 4858 + if (fdc_state[current_fdc].address != -1) 4859 + fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR); 4903 4860 /* 4904 4861 * The driver will try and free resources and relies on us 4905 4862 * to know if they were allocated or not. 4906 4863 */ 4907 - fdc = 0; 4864 + current_fdc = 0; 4908 4865 irqdma_allocated = 1; 4909 4866 return 0; 4910 4867 cleanup: 4911 4868 fd_free_irq(); 4912 4869 fd_free_dma(); 4913 - while (--fdc >= 0) 4914 - floppy_release_regions(fdc); 4870 + while (--current_fdc >= 0) 4871 + floppy_release_regions(current_fdc); 4915 4872 atomic_dec(&usage_count); 4916 4873 return -1; 4917 4874 } ··· 4959 4916 pr_info("auxiliary floppy timer still active\n"); 4960 4917 if (work_pending(&floppy_work)) 4961 4918 pr_info("work still pending\n"); 4962 - old_fdc = fdc; 4963 - for (fdc = 0; fdc < N_FDC; fdc++) 4964 - if (FDCS->address != -1) 4965 - floppy_release_regions(fdc); 4966 - fdc = old_fdc; 4919 + old_fdc = current_fdc; 4920 + for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) 4921 + if (fdc_state[current_fdc].address != -1) 4922 + floppy_release_regions(current_fdc); 4923 + current_fdc = old_fdc; 4967 4924 } 4968 4925 4969 4926 #ifdef MODULE
+10 -8
drivers/block/loop.c
··· 214 214 * LO_FLAGS_READ_ONLY, both are set from kernel, and losetup 215 215 * will get updated by ioctl(LOOP_GET_STATUS) 216 216 */ 217 - blk_mq_freeze_queue(lo->lo_queue); 217 + if (lo->lo_state == Lo_bound) 218 + blk_mq_freeze_queue(lo->lo_queue); 218 219 lo->use_dio = use_dio; 219 220 if (use_dio) { 220 221 blk_queue_flag_clear(QUEUE_FLAG_NOMERGES, lo->lo_queue); ··· 224 223 blk_queue_flag_set(QUEUE_FLAG_NOMERGES, lo->lo_queue); 225 224 lo->lo_flags &= ~LO_FLAGS_DIRECT_IO; 226 225 } 227 - blk_mq_unfreeze_queue(lo->lo_queue); 226 + if (lo->lo_state == Lo_bound) 227 + blk_mq_unfreeze_queue(lo->lo_queue); 228 228 } 229 229 230 230 static int ··· 1541 1539 if (arg < 512 || arg > PAGE_SIZE || !is_power_of_2(arg)) 1542 1540 return -EINVAL; 1543 1541 1544 - if (lo->lo_queue->limits.logical_block_size != arg) { 1545 - sync_blockdev(lo->lo_device); 1546 - kill_bdev(lo->lo_device); 1547 - } 1542 + if (lo->lo_queue->limits.logical_block_size == arg) 1543 + return 0; 1544 + 1545 + sync_blockdev(lo->lo_device); 1546 + kill_bdev(lo->lo_device); 1548 1547 1549 1548 blk_mq_freeze_queue(lo->lo_queue); 1550 1549 1551 1550 /* kill_bdev should have truncated all the pages */ 1552 - if (lo->lo_queue->limits.logical_block_size != arg && 1553 - lo->lo_device->bd_inode->i_mapping->nrpages) { 1551 + if (lo->lo_device->bd_inode->i_mapping->nrpages) { 1554 1552 err = -EAGAIN; 1555 1553 pr_warn("%s: loop%d (%s) has still dirty pages (nrpages=%lu)\n", 1556 1554 __func__, lo->lo_number, lo->lo_file_name,
+19 -8
drivers/block/nbd.c
··· 395 395 } 396 396 config = nbd->config; 397 397 398 - if (config->num_connections > 1) { 398 + if (config->num_connections > 1 || 399 + (config->num_connections == 1 && nbd->tag_set.timeout)) { 399 400 dev_err_ratelimited(nbd_to_dev(nbd), 400 401 "Connection timed out, retrying (%d/%d alive)\n", 401 402 atomic_read(&config->live_connections), 402 403 config->num_connections); 403 404 /* 404 405 * Hooray we have more connections, requeue this IO, the submit 405 - * path will put it on a real connection. 406 + * path will put it on a real connection. Or if only one 407 + * connection is configured, the submit path will wait util 408 + * a new connection is reconfigured or util dead timeout. 406 409 */ 407 - if (config->socks && config->num_connections > 1) { 410 + if (config->socks) { 408 411 if (cmd->index < config->num_connections) { 409 412 struct nbd_sock *nsock = 410 413 config->socks[cmd->index]; ··· 434 431 * Userspace sets timeout=0 to disable socket disconnection, 435 432 * so just warn and reset the timer. 436 433 */ 434 + struct nbd_sock *nsock = config->socks[cmd->index]; 437 435 cmd->retries++; 438 436 dev_info(nbd_to_dev(nbd), "Possible stuck request %p: control (%s@%llu,%uB). Runtime %u seconds\n", 439 437 req, nbdcmd_to_ascii(req_to_nbd_cmd_type(req)), 440 438 (unsigned long long)blk_rq_pos(req) << 9, 441 439 blk_rq_bytes(req), (req->timeout / HZ) * cmd->retries); 442 440 441 + mutex_lock(&nsock->tx_lock); 442 + if (cmd->cookie != nsock->cookie) { 443 + nbd_requeue_cmd(cmd); 444 + mutex_unlock(&nsock->tx_lock); 445 + mutex_unlock(&cmd->lock); 446 + nbd_config_put(nbd); 447 + return BLK_EH_DONE; 448 + } 449 + mutex_unlock(&nsock->tx_lock); 443 450 mutex_unlock(&cmd->lock); 444 451 nbd_config_put(nbd); 445 452 return BLK_EH_RESET_TIMER; ··· 754 741 dev_err(disk_to_dev(nbd->disk), "Receive data failed (result %d)\n", 755 742 result); 756 743 /* 757 - * If we've disconnected or we only have 1 758 - * connection then we need to make sure we 744 + * If we've disconnected, we need to make sure we 759 745 * complete this request, otherwise error out 760 746 * and let the timeout stuff handle resubmitting 761 747 * this request onto another connection. 762 748 */ 763 - if (nbd_disconnected(config) || 764 - config->num_connections <= 1) { 749 + if (nbd_disconnected(config)) { 765 750 cmd->status = BLK_STS_IOERR; 766 751 goto out; 767 752 } ··· 836 825 837 826 if (config->num_connections <= 1) { 838 827 dev_err_ratelimited(disk_to_dev(nbd->disk), 839 - "Attempted send on invalid socket\n"); 828 + "Dead connection, failed to find a fallback\n"); 840 829 return new_index; 841 830 } 842 831
+9
drivers/block/null_blk_main.c
··· 97 97 MODULE_PARM_DESC(home_node, "Home node for the device"); 98 98 99 99 #ifdef CONFIG_BLK_DEV_NULL_BLK_FAULT_INJECTION 100 + /* 101 + * For more details about fault injection, please refer to 102 + * Documentation/fault-injection/fault-injection.rst. 103 + */ 100 104 static char g_timeout_str[80]; 101 105 module_param_string(timeout, g_timeout_str, sizeof(g_timeout_str), 0444); 106 + MODULE_PARM_DESC(timeout, "Fault injection. timeout=<interval>,<probability>,<space>,<times>"); 102 107 103 108 static char g_requeue_str[80]; 104 109 module_param_string(requeue, g_requeue_str, sizeof(g_requeue_str), 0444); 110 + MODULE_PARM_DESC(requeue, "Fault injection. requeue=<interval>,<probability>,<space>,<times>"); 105 111 106 112 static char g_init_hctx_str[80]; 107 113 module_param_string(init_hctx, g_init_hctx_str, sizeof(g_init_hctx_str), 0444); 114 + MODULE_PARM_DESC(init_hctx, "Fault injection to fail hctx init. init_hctx=<interval>,<probability>,<space>,<times>"); 108 115 #endif 109 116 110 117 static int g_queue_mode = NULL_Q_MQ; ··· 622 615 if (tag != -1U) { 623 616 cmd = &nq->cmds[tag]; 624 617 cmd->tag = tag; 618 + cmd->error = BLK_STS_OK; 625 619 cmd->nq = nq; 626 620 if (nq->dev->irqmode == NULL_IRQ_TIMER) { 627 621 hrtimer_init(&cmd->timer, CLOCK_MONOTONIC, ··· 1403 1395 cmd->timer.function = null_cmd_timer_expired; 1404 1396 } 1405 1397 cmd->rq = bd->rq; 1398 + cmd->error = BLK_STS_OK; 1406 1399 cmd->nq = nq; 1407 1400 1408 1401 blk_mq_start_request(bd->rq);
+21
drivers/block/null_blk_trace.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * null_blk trace related helpers. 4 + * 5 + * Copyright (C) 2020 Western Digital Corporation or its affiliates. 6 + */ 7 + #include "null_blk_trace.h" 8 + 9 + /* 10 + * Helper to use for all null_blk traces to extract disk name. 11 + */ 12 + const char *nullb_trace_disk_name(struct trace_seq *p, char *name) 13 + { 14 + const char *ret = trace_seq_buffer_ptr(p); 15 + 16 + if (name && *name) 17 + trace_seq_printf(p, "disk=%s, ", name); 18 + trace_seq_putc(p, 0); 19 + 20 + return ret; 21 + }
+79
drivers/block/null_blk_trace.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * null_blk device driver tracepoints. 4 + * 5 + * Copyright (C) 2020 Western Digital Corporation or its affiliates. 6 + */ 7 + 8 + #undef TRACE_SYSTEM 9 + #define TRACE_SYSTEM nullb 10 + 11 + #if !defined(_TRACE_NULLB_H) || defined(TRACE_HEADER_MULTI_READ) 12 + #define _TRACE_NULLB_H 13 + 14 + #include <linux/tracepoint.h> 15 + #include <linux/trace_seq.h> 16 + 17 + #include "null_blk.h" 18 + 19 + const char *nullb_trace_disk_name(struct trace_seq *p, char *name); 20 + 21 + #define __print_disk_name(name) nullb_trace_disk_name(p, name) 22 + 23 + #ifndef TRACE_HEADER_MULTI_READ 24 + static inline void __assign_disk_name(char *name, struct gendisk *disk) 25 + { 26 + if (disk) 27 + memcpy(name, disk->disk_name, DISK_NAME_LEN); 28 + else 29 + memset(name, 0, DISK_NAME_LEN); 30 + } 31 + #endif 32 + 33 + TRACE_EVENT(nullb_zone_op, 34 + TP_PROTO(struct nullb_cmd *cmd, unsigned int zone_no, 35 + unsigned int zone_cond), 36 + TP_ARGS(cmd, zone_no, zone_cond), 37 + TP_STRUCT__entry( 38 + __array(char, disk, DISK_NAME_LEN) 39 + __field(enum req_opf, op) 40 + __field(unsigned int, zone_no) 41 + __field(unsigned int, zone_cond) 42 + ), 43 + TP_fast_assign( 44 + __entry->op = req_op(cmd->rq); 45 + __entry->zone_no = zone_no; 46 + __entry->zone_cond = zone_cond; 47 + __assign_disk_name(__entry->disk, cmd->rq->rq_disk); 48 + ), 49 + TP_printk("%s req=%-15s zone_no=%u zone_cond=%-10s", 50 + __print_disk_name(__entry->disk), 51 + blk_op_str(__entry->op), 52 + __entry->zone_no, 53 + blk_zone_cond_str(__entry->zone_cond)) 54 + ); 55 + 56 + TRACE_EVENT(nullb_report_zones, 57 + TP_PROTO(struct nullb *nullb, unsigned int nr_zones), 58 + TP_ARGS(nullb, nr_zones), 59 + TP_STRUCT__entry( 60 + __array(char, disk, DISK_NAME_LEN) 61 + __field(unsigned int, nr_zones) 62 + ), 63 + TP_fast_assign( 64 + __entry->nr_zones = nr_zones; 65 + __assign_disk_name(__entry->disk, nullb->disk); 66 + ), 67 + TP_printk("%s nr_zones=%u", 68 + __print_disk_name(__entry->disk), __entry->nr_zones) 69 + ); 70 + 71 + #endif /* _TRACE_NULLB_H */ 72 + 73 + #undef TRACE_INCLUDE_PATH 74 + #define TRACE_INCLUDE_PATH . 75 + #undef TRACE_INCLUDE_FILE 76 + #define TRACE_INCLUDE_FILE null_blk_trace 77 + 78 + /* This part must be outside protection */ 79 + #include <trace/define_trace.h>
+11 -1
drivers/block/null_blk_zoned.c
··· 2 2 #include <linux/vmalloc.h> 3 3 #include "null_blk.h" 4 4 5 + #define CREATE_TRACE_POINTS 6 + #include "null_blk_trace.h" 7 + 5 8 /* zone_size in MBs to sectors. */ 6 9 #define ZONE_SIZE_SHIFT 11 7 10 ··· 83 80 return 0; 84 81 85 82 nr_zones = min(nr_zones, dev->nr_zones - first_zone); 83 + trace_nullb_report_zones(nullb, nr_zones); 84 + 86 85 for (i = 0; i < nr_zones; i++) { 87 86 /* 88 87 * Stacked DM target drivers will remap the zone information by ··· 153 148 /* Invalid zone condition */ 154 149 return BLK_STS_IOERR; 155 150 } 151 + 152 + trace_nullb_zone_op(cmd, zno, zone->cond); 156 153 return BLK_STS_OK; 157 154 } 158 155 ··· 162 155 sector_t sector) 163 156 { 164 157 struct nullb_device *dev = cmd->nq->dev; 165 - struct blk_zone *zone = &dev->zones[null_zone_no(dev, sector)]; 158 + unsigned int zone_no = null_zone_no(dev, sector); 159 + struct blk_zone *zone = &dev->zones[zone_no]; 166 160 size_t i; 167 161 168 162 switch (op) { ··· 211 203 default: 212 204 return BLK_STS_NOTSUPP; 213 205 } 206 + 207 + trace_nullb_zone_op(cmd, zone_no, zone->cond); 214 208 return BLK_STS_OK; 215 209 } 216 210
+1 -1
drivers/block/rsxx/dma.c
··· 80 80 struct dma_tracker_list { 81 81 spinlock_t lock; 82 82 int head; 83 - struct dma_tracker list[0]; 83 + struct dma_tracker list[]; 84 84 }; 85 85 86 86
+21 -21
drivers/lightnvm/pblk-sysfs.c
··· 37 37 active = 0; 38 38 up(&rlun->wr_sem); 39 39 } 40 - sz += snprintf(page + sz, PAGE_SIZE - sz, 40 + sz += scnprintf(page + sz, PAGE_SIZE - sz, 41 41 "pblk: pos:%d, ch:%d, lun:%d - %d\n", 42 42 i, 43 43 rlun->bppa.a.ch, ··· 120 120 struct nvm_addrf_12 *ppaf = (struct nvm_addrf_12 *)&pblk->addrf; 121 121 struct nvm_addrf_12 *gppaf = (struct nvm_addrf_12 *)&geo->addrf; 122 122 123 - sz = snprintf(page, PAGE_SIZE, 123 + sz = scnprintf(page, PAGE_SIZE, 124 124 "g:(b:%d)blk:%d/%d,pg:%d/%d,lun:%d/%d,ch:%d/%d,pl:%d/%d,sec:%d/%d\n", 125 125 pblk->addrf_len, 126 126 ppaf->blk_offset, ppaf->blk_len, ··· 130 130 ppaf->pln_offset, ppaf->pln_len, 131 131 ppaf->sec_offset, ppaf->sec_len); 132 132 133 - sz += snprintf(page + sz, PAGE_SIZE - sz, 133 + sz += scnprintf(page + sz, PAGE_SIZE - sz, 134 134 "d:blk:%d/%d,pg:%d/%d,lun:%d/%d,ch:%d/%d,pl:%d/%d,sec:%d/%d\n", 135 135 gppaf->blk_offset, gppaf->blk_len, 136 136 gppaf->pg_offset, gppaf->pg_len, ··· 142 142 struct nvm_addrf *ppaf = &pblk->addrf; 143 143 struct nvm_addrf *gppaf = &geo->addrf; 144 144 145 - sz = snprintf(page, PAGE_SIZE, 145 + sz = scnprintf(page, PAGE_SIZE, 146 146 "pblk:(s:%d)ch:%d/%d,lun:%d/%d,chk:%d/%d/sec:%d/%d\n", 147 147 pblk->addrf_len, 148 148 ppaf->ch_offset, ppaf->ch_len, ··· 150 150 ppaf->chk_offset, ppaf->chk_len, 151 151 ppaf->sec_offset, ppaf->sec_len); 152 152 153 - sz += snprintf(page + sz, PAGE_SIZE - sz, 153 + sz += scnprintf(page + sz, PAGE_SIZE - sz, 154 154 "device:ch:%d/%d,lun:%d/%d,chk:%d/%d,sec:%d/%d\n", 155 155 gppaf->ch_offset, gppaf->ch_len, 156 156 gppaf->lun_offset, gppaf->lun_len, ··· 278 278 pblk_err(pblk, "corrupted free line list:%d/%d\n", 279 279 nr_free_lines, free_line_cnt); 280 280 281 - sz = snprintf(page, PAGE_SIZE - sz, 281 + sz = scnprintf(page, PAGE_SIZE - sz, 282 282 "line: nluns:%d, nblks:%d, nsecs:%d\n", 283 283 geo->all_luns, lm->blk_per_line, lm->sec_per_line); 284 284 285 - sz += snprintf(page + sz, PAGE_SIZE - sz, 285 + sz += scnprintf(page + sz, PAGE_SIZE - sz, 286 286 "lines:d:%d,l:%d-f:%d,m:%d/%d,c:%d,b:%d,co:%d(d:%d,l:%d)t:%d\n", 287 287 cur_data, cur_log, 288 288 nr_free_lines, ··· 292 292 d_line_cnt, l_line_cnt, 293 293 l_mg->nr_lines); 294 294 295 - sz += snprintf(page + sz, PAGE_SIZE - sz, 295 + sz += scnprintf(page + sz, PAGE_SIZE - sz, 296 296 "GC: full:%d, high:%d, mid:%d, low:%d, empty:%d, werr: %d, queue:%d\n", 297 297 gc_full, gc_high, gc_mid, gc_low, gc_empty, gc_werr, 298 298 atomic_read(&pblk->gc.read_inflight_gc)); 299 299 300 - sz += snprintf(page + sz, PAGE_SIZE - sz, 300 + sz += scnprintf(page + sz, PAGE_SIZE - sz, 301 301 "data (%d) cur:%d, left:%d, vsc:%d, s:%d, map:%d/%d (%d)\n", 302 302 cur_data, cur_sec, msecs, vsc, sec_in_line, 303 303 map_weight, lm->sec_per_line, ··· 313 313 struct pblk_line_meta *lm = &pblk->lm; 314 314 ssize_t sz = 0; 315 315 316 - sz = snprintf(page, PAGE_SIZE - sz, 316 + sz = scnprintf(page, PAGE_SIZE - sz, 317 317 "smeta - len:%d, secs:%d\n", 318 318 lm->smeta_len, lm->smeta_sec); 319 - sz += snprintf(page + sz, PAGE_SIZE - sz, 319 + sz += scnprintf(page + sz, PAGE_SIZE - sz, 320 320 "emeta - len:%d, sec:%d, bb_start:%d\n", 321 321 lm->emeta_len[0], lm->emeta_sec[0], 322 322 lm->emeta_bb); 323 - sz += snprintf(page + sz, PAGE_SIZE - sz, 323 + sz += scnprintf(page + sz, PAGE_SIZE - sz, 324 324 "bitmap lengths: sec:%d, blk:%d, lun:%d\n", 325 325 lm->sec_bitmap_len, 326 326 lm->blk_bitmap_len, 327 327 lm->lun_bitmap_len); 328 - sz += snprintf(page + sz, PAGE_SIZE - sz, 328 + sz += scnprintf(page + sz, PAGE_SIZE - sz, 329 329 "blk_line:%d, sec_line:%d, sec_blk:%d\n", 330 330 lm->blk_per_line, 331 331 lm->sec_per_line, ··· 344 344 { 345 345 int sz; 346 346 347 - sz = snprintf(page, PAGE_SIZE, 347 + sz = scnprintf(page, PAGE_SIZE, 348 348 "user:%lld gc:%lld pad:%lld WA:", 349 349 user, gc, pad); 350 350 351 351 if (!user) { 352 - sz += snprintf(page + sz, PAGE_SIZE - sz, "NaN\n"); 352 + sz += scnprintf(page + sz, PAGE_SIZE - sz, "NaN\n"); 353 353 } else { 354 354 u64 wa_int; 355 355 u32 wa_frac; ··· 358 358 wa_int = div64_u64(wa_int, user); 359 359 wa_int = div_u64_rem(wa_int, 100000, &wa_frac); 360 360 361 - sz += snprintf(page + sz, PAGE_SIZE - sz, "%llu.%05u\n", 361 + sz += scnprintf(page + sz, PAGE_SIZE - sz, "%llu.%05u\n", 362 362 wa_int, wa_frac); 363 363 } 364 364 ··· 401 401 total = atomic64_read(&pblk->nr_flush) - pblk->nr_flush_rst; 402 402 if (!total) { 403 403 for (i = 0; i < (buckets + 1); i++) 404 - sz += snprintf(page + sz, PAGE_SIZE - sz, 404 + sz += scnprintf(page + sz, PAGE_SIZE - sz, 405 405 "%d:0 ", i); 406 - sz += snprintf(page + sz, PAGE_SIZE - sz, "\n"); 406 + sz += scnprintf(page + sz, PAGE_SIZE - sz, "\n"); 407 407 408 408 return sz; 409 409 } ··· 411 411 for (i = 0; i < buckets; i++) 412 412 total_buckets += atomic64_read(&pblk->pad_dist[i]); 413 413 414 - sz += snprintf(page + sz, PAGE_SIZE - sz, "0:%lld%% ", 414 + sz += scnprintf(page + sz, PAGE_SIZE - sz, "0:%lld%% ", 415 415 bucket_percentage(total - total_buckets, total)); 416 416 417 417 for (i = 0; i < buckets; i++) { ··· 419 419 420 420 p = bucket_percentage(atomic64_read(&pblk->pad_dist[i]), 421 421 total); 422 - sz += snprintf(page + sz, PAGE_SIZE - sz, "%d:%lld%% ", 422 + sz += scnprintf(page + sz, PAGE_SIZE - sz, "%d:%lld%% ", 423 423 i + 1, p); 424 424 } 425 - sz += snprintf(page + sz, PAGE_SIZE - sz, "\n"); 425 + sz += scnprintf(page + sz, PAGE_SIZE - sz, "\n"); 426 426 427 427 return sz; 428 428 }
+174 -68
drivers/md/bcache/btree.c
··· 101 101 102 102 #define insert_lock(s, b) ((b)->level <= (s)->lock) 103 103 104 - /* 105 - * These macros are for recursing down the btree - they handle the details of 106 - * locking and looking up nodes in the cache for you. They're best treated as 107 - * mere syntax when reading code that uses them. 108 - * 109 - * op->lock determines whether we take a read or a write lock at a given depth. 110 - * If you've got a read lock and find that you need a write lock (i.e. you're 111 - * going to have to split), set op->lock and return -EINTR; btree_root() will 112 - * call you again and you'll have the correct lock. 113 - */ 114 - 115 - /** 116 - * btree - recurse down the btree on a specified key 117 - * @fn: function to call, which will be passed the child node 118 - * @key: key to recurse on 119 - * @b: parent btree node 120 - * @op: pointer to struct btree_op 121 - */ 122 - #define btree(fn, key, b, op, ...) \ 123 - ({ \ 124 - int _r, l = (b)->level - 1; \ 125 - bool _w = l <= (op)->lock; \ 126 - struct btree *_child = bch_btree_node_get((b)->c, op, key, l, \ 127 - _w, b); \ 128 - if (!IS_ERR(_child)) { \ 129 - _r = bch_btree_ ## fn(_child, op, ##__VA_ARGS__); \ 130 - rw_unlock(_w, _child); \ 131 - } else \ 132 - _r = PTR_ERR(_child); \ 133 - _r; \ 134 - }) 135 - 136 - /** 137 - * btree_root - call a function on the root of the btree 138 - * @fn: function to call, which will be passed the child node 139 - * @c: cache set 140 - * @op: pointer to struct btree_op 141 - */ 142 - #define btree_root(fn, c, op, ...) \ 143 - ({ \ 144 - int _r = -EINTR; \ 145 - do { \ 146 - struct btree *_b = (c)->root; \ 147 - bool _w = insert_lock(op, _b); \ 148 - rw_lock(_w, _b, _b->level); \ 149 - if (_b == (c)->root && \ 150 - _w == insert_lock(op, _b)) { \ 151 - _r = bch_btree_ ## fn(_b, op, ##__VA_ARGS__); \ 152 - } \ 153 - rw_unlock(_w, _b); \ 154 - bch_cannibalize_unlock(c); \ 155 - if (_r == -EINTR) \ 156 - schedule(); \ 157 - } while (_r == -EINTR); \ 158 - \ 159 - finish_wait(&(c)->btree_cache_wait, &(op)->wait); \ 160 - _r; \ 161 - }) 162 104 163 105 static inline struct bset *write_block(struct btree *b) 164 106 { ··· 1790 1848 1791 1849 /* if CACHE_SET_IO_DISABLE set, gc thread should stop too */ 1792 1850 do { 1793 - ret = btree_root(gc_root, c, &op, &writes, &stats); 1851 + ret = bcache_btree_root(gc_root, c, &op, &writes, &stats); 1794 1852 closure_sync(&writes); 1795 1853 cond_resched(); 1796 1854 ··· 1888 1946 } 1889 1947 1890 1948 if (p) 1891 - ret = btree(check_recurse, p, b, op); 1949 + ret = bcache_btree(check_recurse, p, b, op); 1892 1950 1893 1951 p = k; 1894 1952 } while (p && !ret); ··· 1897 1955 return ret; 1898 1956 } 1899 1957 1958 + 1959 + static int bch_btree_check_thread(void *arg) 1960 + { 1961 + int ret; 1962 + struct btree_check_info *info = arg; 1963 + struct btree_check_state *check_state = info->state; 1964 + struct cache_set *c = check_state->c; 1965 + struct btree_iter iter; 1966 + struct bkey *k, *p; 1967 + int cur_idx, prev_idx, skip_nr; 1968 + int i, n; 1969 + 1970 + k = p = NULL; 1971 + i = n = 0; 1972 + cur_idx = prev_idx = 0; 1973 + ret = 0; 1974 + 1975 + /* root node keys are checked before thread created */ 1976 + bch_btree_iter_init(&c->root->keys, &iter, NULL); 1977 + k = bch_btree_iter_next_filter(&iter, &c->root->keys, bch_ptr_bad); 1978 + BUG_ON(!k); 1979 + 1980 + p = k; 1981 + while (k) { 1982 + /* 1983 + * Fetch a root node key index, skip the keys which 1984 + * should be fetched by other threads, then check the 1985 + * sub-tree indexed by the fetched key. 1986 + */ 1987 + spin_lock(&check_state->idx_lock); 1988 + cur_idx = check_state->key_idx; 1989 + check_state->key_idx++; 1990 + spin_unlock(&check_state->idx_lock); 1991 + 1992 + skip_nr = cur_idx - prev_idx; 1993 + 1994 + while (skip_nr) { 1995 + k = bch_btree_iter_next_filter(&iter, 1996 + &c->root->keys, 1997 + bch_ptr_bad); 1998 + if (k) 1999 + p = k; 2000 + else { 2001 + /* 2002 + * No more keys to check in root node, 2003 + * current checking threads are enough, 2004 + * stop creating more. 2005 + */ 2006 + atomic_set(&check_state->enough, 1); 2007 + /* Update check_state->enough earlier */ 2008 + smp_mb__after_atomic(); 2009 + goto out; 2010 + } 2011 + skip_nr--; 2012 + cond_resched(); 2013 + } 2014 + 2015 + if (p) { 2016 + struct btree_op op; 2017 + 2018 + btree_node_prefetch(c->root, p); 2019 + c->gc_stats.nodes++; 2020 + bch_btree_op_init(&op, 0); 2021 + ret = bcache_btree(check_recurse, p, c->root, &op); 2022 + if (ret) 2023 + goto out; 2024 + } 2025 + p = NULL; 2026 + prev_idx = cur_idx; 2027 + cond_resched(); 2028 + } 2029 + 2030 + out: 2031 + info->result = ret; 2032 + /* update check_state->started among all CPUs */ 2033 + smp_mb__before_atomic(); 2034 + if (atomic_dec_and_test(&check_state->started)) 2035 + wake_up(&check_state->wait); 2036 + 2037 + return ret; 2038 + } 2039 + 2040 + 2041 + 2042 + static int bch_btree_chkthread_nr(void) 2043 + { 2044 + int n = num_online_cpus()/2; 2045 + 2046 + if (n == 0) 2047 + n = 1; 2048 + else if (n > BCH_BTR_CHKTHREAD_MAX) 2049 + n = BCH_BTR_CHKTHREAD_MAX; 2050 + 2051 + return n; 2052 + } 2053 + 1900 2054 int bch_btree_check(struct cache_set *c) 1901 2055 { 1902 - struct btree_op op; 2056 + int ret = 0; 2057 + int i; 2058 + struct bkey *k = NULL; 2059 + struct btree_iter iter; 2060 + struct btree_check_state *check_state; 2061 + char name[32]; 1903 2062 1904 - bch_btree_op_init(&op, SHRT_MAX); 2063 + /* check and mark root node keys */ 2064 + for_each_key_filter(&c->root->keys, k, &iter, bch_ptr_invalid) 2065 + bch_initial_mark_key(c, c->root->level, k); 1905 2066 1906 - return btree_root(check_recurse, c, &op); 2067 + bch_initial_mark_key(c, c->root->level + 1, &c->root->key); 2068 + 2069 + if (c->root->level == 0) 2070 + return 0; 2071 + 2072 + check_state = kzalloc(sizeof(struct btree_check_state), GFP_KERNEL); 2073 + if (!check_state) 2074 + return -ENOMEM; 2075 + 2076 + check_state->c = c; 2077 + check_state->total_threads = bch_btree_chkthread_nr(); 2078 + check_state->key_idx = 0; 2079 + spin_lock_init(&check_state->idx_lock); 2080 + atomic_set(&check_state->started, 0); 2081 + atomic_set(&check_state->enough, 0); 2082 + init_waitqueue_head(&check_state->wait); 2083 + 2084 + /* 2085 + * Run multiple threads to check btree nodes in parallel, 2086 + * if check_state->enough is non-zero, it means current 2087 + * running check threads are enough, unncessary to create 2088 + * more. 2089 + */ 2090 + for (i = 0; i < check_state->total_threads; i++) { 2091 + /* fetch latest check_state->enough earlier */ 2092 + smp_mb__before_atomic(); 2093 + if (atomic_read(&check_state->enough)) 2094 + break; 2095 + 2096 + check_state->infos[i].result = 0; 2097 + check_state->infos[i].state = check_state; 2098 + snprintf(name, sizeof(name), "bch_btrchk[%u]", i); 2099 + atomic_inc(&check_state->started); 2100 + 2101 + check_state->infos[i].thread = 2102 + kthread_run(bch_btree_check_thread, 2103 + &check_state->infos[i], 2104 + name); 2105 + if (IS_ERR(check_state->infos[i].thread)) { 2106 + pr_err("fails to run thread bch_btrchk[%d]", i); 2107 + for (--i; i >= 0; i--) 2108 + kthread_stop(check_state->infos[i].thread); 2109 + ret = -ENOMEM; 2110 + goto out; 2111 + } 2112 + } 2113 + 2114 + wait_event_interruptible(check_state->wait, 2115 + atomic_read(&check_state->started) == 0 || 2116 + test_bit(CACHE_SET_IO_DISABLE, &c->flags)); 2117 + 2118 + for (i = 0; i < check_state->total_threads; i++) { 2119 + if (check_state->infos[i].result) { 2120 + ret = check_state->infos[i].result; 2121 + goto out; 2122 + } 2123 + } 2124 + 2125 + out: 2126 + kfree(check_state); 2127 + return ret; 1907 2128 } 1908 2129 1909 2130 void bch_initial_gc_finish(struct cache_set *c) ··· 2506 2401 2507 2402 while ((k = bch_btree_iter_next_filter(&iter, &b->keys, 2508 2403 bch_ptr_bad))) { 2509 - ret = btree(map_nodes_recurse, k, b, 2404 + ret = bcache_btree(map_nodes_recurse, k, b, 2510 2405 op, from, fn, flags); 2511 2406 from = NULL; 2512 2407 ··· 2524 2419 int __bch_btree_map_nodes(struct btree_op *op, struct cache_set *c, 2525 2420 struct bkey *from, btree_map_nodes_fn *fn, int flags) 2526 2421 { 2527 - return btree_root(map_nodes_recurse, c, op, from, fn, flags); 2422 + return bcache_btree_root(map_nodes_recurse, c, op, from, fn, flags); 2528 2423 } 2529 2424 2530 - static int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op, 2425 + int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op, 2531 2426 struct bkey *from, btree_map_keys_fn *fn, 2532 2427 int flags) 2533 2428 { ··· 2540 2435 while ((k = bch_btree_iter_next_filter(&iter, &b->keys, bch_ptr_bad))) { 2541 2436 ret = !b->level 2542 2437 ? fn(op, b, k) 2543 - : btree(map_keys_recurse, k, b, op, from, fn, flags); 2438 + : bcache_btree(map_keys_recurse, k, 2439 + b, op, from, fn, flags); 2544 2440 from = NULL; 2545 2441 2546 2442 if (ret != MAP_CONTINUE) ··· 2558 2452 int bch_btree_map_keys(struct btree_op *op, struct cache_set *c, 2559 2453 struct bkey *from, btree_map_keys_fn *fn, int flags) 2560 2454 { 2561 - return btree_root(map_keys_recurse, c, op, from, fn, flags); 2455 + return bcache_btree_root(map_keys_recurse, c, op, from, fn, flags); 2562 2456 } 2563 2457 2564 2458 /* Keybuf code */
+84
drivers/md/bcache/btree.h
··· 145 145 struct bio *bio; 146 146 }; 147 147 148 + 149 + 150 + 148 151 #define BTREE_FLAG(flag) \ 149 152 static inline bool btree_node_ ## flag(struct btree *b) \ 150 153 { return test_bit(BTREE_NODE_ ## flag, &b->flags); } \ ··· 219 216 unsigned int insert_collision:1; 220 217 }; 221 218 219 + struct btree_check_state; 220 + struct btree_check_info { 221 + struct btree_check_state *state; 222 + struct task_struct *thread; 223 + int result; 224 + }; 225 + 226 + #define BCH_BTR_CHKTHREAD_MAX 64 227 + struct btree_check_state { 228 + struct cache_set *c; 229 + int total_threads; 230 + int key_idx; 231 + spinlock_t idx_lock; 232 + atomic_t started; 233 + atomic_t enough; 234 + wait_queue_head_t wait; 235 + struct btree_check_info infos[BCH_BTR_CHKTHREAD_MAX]; 236 + }; 237 + 222 238 static inline void bch_btree_op_init(struct btree_op *op, int write_lock_level) 223 239 { 224 240 memset(op, 0, sizeof(struct btree_op)); ··· 306 284 wake_up_gc(c); 307 285 } 308 286 287 + /* 288 + * These macros are for recursing down the btree - they handle the details of 289 + * locking and looking up nodes in the cache for you. They're best treated as 290 + * mere syntax when reading code that uses them. 291 + * 292 + * op->lock determines whether we take a read or a write lock at a given depth. 293 + * If you've got a read lock and find that you need a write lock (i.e. you're 294 + * going to have to split), set op->lock and return -EINTR; btree_root() will 295 + * call you again and you'll have the correct lock. 296 + */ 297 + 298 + /** 299 + * btree - recurse down the btree on a specified key 300 + * @fn: function to call, which will be passed the child node 301 + * @key: key to recurse on 302 + * @b: parent btree node 303 + * @op: pointer to struct btree_op 304 + */ 305 + #define bcache_btree(fn, key, b, op, ...) \ 306 + ({ \ 307 + int _r, l = (b)->level - 1; \ 308 + bool _w = l <= (op)->lock; \ 309 + struct btree *_child = bch_btree_node_get((b)->c, op, key, l, \ 310 + _w, b); \ 311 + if (!IS_ERR(_child)) { \ 312 + _r = bch_btree_ ## fn(_child, op, ##__VA_ARGS__); \ 313 + rw_unlock(_w, _child); \ 314 + } else \ 315 + _r = PTR_ERR(_child); \ 316 + _r; \ 317 + }) 318 + 319 + /** 320 + * btree_root - call a function on the root of the btree 321 + * @fn: function to call, which will be passed the child node 322 + * @c: cache set 323 + * @op: pointer to struct btree_op 324 + */ 325 + #define bcache_btree_root(fn, c, op, ...) \ 326 + ({ \ 327 + int _r = -EINTR; \ 328 + do { \ 329 + struct btree *_b = (c)->root; \ 330 + bool _w = insert_lock(op, _b); \ 331 + rw_lock(_w, _b, _b->level); \ 332 + if (_b == (c)->root && \ 333 + _w == insert_lock(op, _b)) { \ 334 + _r = bch_btree_ ## fn(_b, op, ##__VA_ARGS__); \ 335 + } \ 336 + rw_unlock(_w, _b); \ 337 + bch_cannibalize_unlock(c); \ 338 + if (_r == -EINTR) \ 339 + schedule(); \ 340 + } while (_r == -EINTR); \ 341 + \ 342 + finish_wait(&(c)->btree_cache_wait, &(op)->wait); \ 343 + _r; \ 344 + }) 345 + 309 346 #define MAP_DONE 0 310 347 #define MAP_CONTINUE 1 311 348 ··· 395 314 struct bkey *k); 396 315 int bch_btree_map_keys(struct btree_op *op, struct cache_set *c, 397 316 struct bkey *from, btree_map_keys_fn *fn, int flags); 317 + int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op, 318 + struct bkey *from, btree_map_keys_fn *fn, 319 + int flags); 398 320 399 321 typedef bool (keybuf_pred_fn)(struct keybuf *buf, struct bkey *k); 400 322
+1 -1
drivers/md/bcache/sysfs.c
··· 154 154 size_t i; 155 155 156 156 for (i = 0; list[i]; i++) 157 - out += snprintf(out, buf + size - out, 157 + out += scnprintf(out, buf + size - out, 158 158 i == selected ? "[%s] " : "%s ", list[i]); 159 159 160 160 out[-1] = '\n';
+158 -6
drivers/md/bcache/writeback.c
··· 183 183 */ 184 184 set_bit(BCACHE_DEV_RATE_DW_RUNNING, &dc->disk.flags); 185 185 /* paired with where BCACHE_DEV_RATE_DW_RUNNING is tested */ 186 - smp_mb(); 186 + smp_mb__after_atomic(); 187 187 188 188 /* 189 189 * CACHE_SET_IO_DISABLE might be set via sysfs interface, ··· 193 193 test_bit(CACHE_SET_IO_DISABLE, &c->flags)) { 194 194 clear_bit(BCACHE_DEV_RATE_DW_RUNNING, &dc->disk.flags); 195 195 /* paired with where BCACHE_DEV_RATE_DW_RUNNING is tested */ 196 - smp_mb(); 196 + smp_mb__after_atomic(); 197 197 return; 198 198 } 199 199 ··· 229 229 */ 230 230 clear_bit(BCACHE_DEV_RATE_DW_RUNNING, &dc->disk.flags); 231 231 /* paired with where BCACHE_DEV_RATE_DW_RUNNING is tested */ 232 - smp_mb(); 232 + smp_mb__after_atomic(); 233 233 } 234 234 235 235 static unsigned int writeback_delay(struct cached_dev *dc, ··· 785 785 return MAP_CONTINUE; 786 786 } 787 787 788 - void bch_sectors_dirty_init(struct bcache_device *d) 788 + static int bch_root_node_dirty_init(struct cache_set *c, 789 + struct bcache_device *d, 790 + struct bkey *k) 789 791 { 790 792 struct sectors_dirty_init op; 791 793 int ret; ··· 798 796 op.start = KEY(op.inode, 0, 0); 799 797 800 798 do { 801 - ret = bch_btree_map_keys(&op.op, d->c, &op.start, 802 - sectors_dirty_init_fn, 0); 799 + ret = bcache_btree(map_keys_recurse, 800 + k, 801 + c->root, 802 + &op.op, 803 + &op.start, 804 + sectors_dirty_init_fn, 805 + 0); 803 806 if (ret == -EAGAIN) 804 807 schedule_timeout_interruptible( 805 808 msecs_to_jiffies(INIT_KEYS_SLEEP_MS)); ··· 813 806 break; 814 807 } 815 808 } while (ret == -EAGAIN); 809 + 810 + return ret; 811 + } 812 + 813 + static int bch_dirty_init_thread(void *arg) 814 + { 815 + struct dirty_init_thrd_info *info = arg; 816 + struct bch_dirty_init_state *state = info->state; 817 + struct cache_set *c = state->c; 818 + struct btree_iter iter; 819 + struct bkey *k, *p; 820 + int cur_idx, prev_idx, skip_nr; 821 + int i; 822 + 823 + k = p = NULL; 824 + i = 0; 825 + cur_idx = prev_idx = 0; 826 + 827 + bch_btree_iter_init(&c->root->keys, &iter, NULL); 828 + k = bch_btree_iter_next_filter(&iter, &c->root->keys, bch_ptr_bad); 829 + BUG_ON(!k); 830 + 831 + p = k; 832 + 833 + while (k) { 834 + spin_lock(&state->idx_lock); 835 + cur_idx = state->key_idx; 836 + state->key_idx++; 837 + spin_unlock(&state->idx_lock); 838 + 839 + skip_nr = cur_idx - prev_idx; 840 + 841 + while (skip_nr) { 842 + k = bch_btree_iter_next_filter(&iter, 843 + &c->root->keys, 844 + bch_ptr_bad); 845 + if (k) 846 + p = k; 847 + else { 848 + atomic_set(&state->enough, 1); 849 + /* Update state->enough earlier */ 850 + smp_mb__after_atomic(); 851 + goto out; 852 + } 853 + skip_nr--; 854 + cond_resched(); 855 + } 856 + 857 + if (p) { 858 + if (bch_root_node_dirty_init(c, state->d, p) < 0) 859 + goto out; 860 + } 861 + 862 + p = NULL; 863 + prev_idx = cur_idx; 864 + cond_resched(); 865 + } 866 + 867 + out: 868 + /* In order to wake up state->wait in time */ 869 + smp_mb__before_atomic(); 870 + if (atomic_dec_and_test(&state->started)) 871 + wake_up(&state->wait); 872 + 873 + return 0; 874 + } 875 + 876 + static int bch_btre_dirty_init_thread_nr(void) 877 + { 878 + int n = num_online_cpus()/2; 879 + 880 + if (n == 0) 881 + n = 1; 882 + else if (n > BCH_DIRTY_INIT_THRD_MAX) 883 + n = BCH_DIRTY_INIT_THRD_MAX; 884 + 885 + return n; 886 + } 887 + 888 + void bch_sectors_dirty_init(struct bcache_device *d) 889 + { 890 + int i; 891 + struct bkey *k = NULL; 892 + struct btree_iter iter; 893 + struct sectors_dirty_init op; 894 + struct cache_set *c = d->c; 895 + struct bch_dirty_init_state *state; 896 + char name[32]; 897 + 898 + /* Just count root keys if no leaf node */ 899 + if (c->root->level == 0) { 900 + bch_btree_op_init(&op.op, -1); 901 + op.inode = d->id; 902 + op.count = 0; 903 + op.start = KEY(op.inode, 0, 0); 904 + 905 + for_each_key_filter(&c->root->keys, 906 + k, &iter, bch_ptr_invalid) 907 + sectors_dirty_init_fn(&op.op, c->root, k); 908 + return; 909 + } 910 + 911 + state = kzalloc(sizeof(struct bch_dirty_init_state), GFP_KERNEL); 912 + if (!state) { 913 + pr_warn("sectors dirty init failed: cannot allocate memory"); 914 + return; 915 + } 916 + 917 + state->c = c; 918 + state->d = d; 919 + state->total_threads = bch_btre_dirty_init_thread_nr(); 920 + state->key_idx = 0; 921 + spin_lock_init(&state->idx_lock); 922 + atomic_set(&state->started, 0); 923 + atomic_set(&state->enough, 0); 924 + init_waitqueue_head(&state->wait); 925 + 926 + for (i = 0; i < state->total_threads; i++) { 927 + /* Fetch latest state->enough earlier */ 928 + smp_mb__before_atomic(); 929 + if (atomic_read(&state->enough)) 930 + break; 931 + 932 + state->infos[i].state = state; 933 + atomic_inc(&state->started); 934 + snprintf(name, sizeof(name), "bch_dirty_init[%d]", i); 935 + 936 + state->infos[i].thread = 937 + kthread_run(bch_dirty_init_thread, 938 + &state->infos[i], 939 + name); 940 + if (IS_ERR(state->infos[i].thread)) { 941 + pr_err("fails to run thread bch_dirty_init[%d]", i); 942 + for (--i; i >= 0; i--) 943 + kthread_stop(state->infos[i].thread); 944 + goto out; 945 + } 946 + } 947 + 948 + wait_event_interruptible(state->wait, 949 + atomic_read(&state->started) == 0 || 950 + test_bit(CACHE_SET_IO_DISABLE, &c->flags)); 951 + 952 + out: 953 + kfree(state); 816 954 } 817 955 818 956 void bch_cached_dev_writeback_init(struct cached_dev *dc)
+19
drivers/md/bcache/writeback.h
··· 16 16 17 17 #define BCH_AUTO_GC_DIRTY_THRESHOLD 50 18 18 19 + #define BCH_DIRTY_INIT_THRD_MAX 64 19 20 /* 20 21 * 14 (16384ths) is chosen here as something that each backing device 21 22 * should be a reasonable fraction of the share, and not to blow up 22 23 * until individual backing devices are a petabyte. 23 24 */ 24 25 #define WRITEBACK_SHARE_SHIFT 14 26 + 27 + struct bch_dirty_init_state; 28 + struct dirty_init_thrd_info { 29 + struct bch_dirty_init_state *state; 30 + struct task_struct *thread; 31 + }; 32 + 33 + struct bch_dirty_init_state { 34 + struct cache_set *c; 35 + struct bcache_device *d; 36 + int total_threads; 37 + int key_idx; 38 + spinlock_t idx_lock; 39 + atomic_t started; 40 + atomic_t enough; 41 + wait_queue_head_t wait; 42 + struct dirty_init_thrd_info infos[BCH_DIRTY_INIT_THRD_MAX]; 43 + }; 25 44 26 45 static inline uint64_t bcache_dev_sectors_dirty(struct bcache_device *d) 27 46 {
+1 -1
drivers/md/md.c
··· 6185 6185 static void mddev_detach(struct mddev *mddev) 6186 6186 { 6187 6187 md_bitmap_wait_behind_writes(mddev); 6188 - if (mddev->pers && mddev->pers->quiesce) { 6188 + if (mddev->pers && mddev->pers->quiesce && !mddev->suspended) { 6189 6189 mddev->pers->quiesce(mddev, 1); 6190 6190 mddev->pers->quiesce(mddev, 0); 6191 6191 }
-2
drivers/nvme/host/Kconfig
··· 32 32 a hardware monitoring device will be created for each NVMe drive 33 33 in the system. 34 34 35 - If unsure, say N. 36 - 37 35 config NVME_FABRICS 38 36 tristate 39 37
+156 -99
drivers/nvme/host/core.c
··· 171 171 nvme_remove_namespaces(ctrl); 172 172 ctrl->ops->delete_ctrl(ctrl); 173 173 nvme_uninit_ctrl(ctrl); 174 - nvme_put_ctrl(ctrl); 175 174 } 176 175 177 176 static void nvme_delete_ctrl_work(struct work_struct *work) ··· 191 192 } 192 193 EXPORT_SYMBOL_GPL(nvme_delete_ctrl); 193 194 194 - static int nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl) 195 + static void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl) 195 196 { 196 - int ret = 0; 197 - 198 197 /* 199 198 * Keep a reference until nvme_do_delete_ctrl() complete, 200 199 * since ->delete_ctrl can free the controller. 201 200 */ 202 201 nvme_get_ctrl(ctrl); 203 - if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING)) 204 - ret = -EBUSY; 205 - if (!ret) 202 + if (nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING)) 206 203 nvme_do_delete_ctrl(ctrl); 207 204 nvme_put_ctrl(ctrl); 208 - return ret; 209 205 } 210 206 211 207 static inline bool nvme_ns_has_pi(struct nvme_ns *ns) ··· 285 291 nvme_req(req)->ctrl->comp_seen = true; 286 292 287 293 if (unlikely(status != BLK_STS_OK && nvme_req_needs_retry(req))) { 288 - if ((req->cmd_flags & REQ_NVME_MPATH) && 289 - blk_path_error(status)) { 290 - nvme_failover_req(req); 294 + if ((req->cmd_flags & REQ_NVME_MPATH) && nvme_failover_req(req)) 291 295 return; 292 - } 293 296 294 297 if (!blk_queue_dying(req->q)) { 295 298 nvme_retry_req(req); ··· 1046 1055 return error; 1047 1056 } 1048 1057 1058 + static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids, 1059 + struct nvme_ns_id_desc *cur) 1060 + { 1061 + const char *warn_str = "ctrl returned bogus length:"; 1062 + void *data = cur; 1063 + 1064 + switch (cur->nidt) { 1065 + case NVME_NIDT_EUI64: 1066 + if (cur->nidl != NVME_NIDT_EUI64_LEN) { 1067 + dev_warn(ctrl->device, "%s %d for NVME_NIDT_EUI64\n", 1068 + warn_str, cur->nidl); 1069 + return -1; 1070 + } 1071 + memcpy(ids->eui64, data + sizeof(*cur), NVME_NIDT_EUI64_LEN); 1072 + return NVME_NIDT_EUI64_LEN; 1073 + case NVME_NIDT_NGUID: 1074 + if (cur->nidl != NVME_NIDT_NGUID_LEN) { 1075 + dev_warn(ctrl->device, "%s %d for NVME_NIDT_NGUID\n", 1076 + warn_str, cur->nidl); 1077 + return -1; 1078 + } 1079 + memcpy(ids->nguid, data + sizeof(*cur), NVME_NIDT_NGUID_LEN); 1080 + return NVME_NIDT_NGUID_LEN; 1081 + case NVME_NIDT_UUID: 1082 + if (cur->nidl != NVME_NIDT_UUID_LEN) { 1083 + dev_warn(ctrl->device, "%s %d for NVME_NIDT_UUID\n", 1084 + warn_str, cur->nidl); 1085 + return -1; 1086 + } 1087 + uuid_copy(&ids->uuid, data + sizeof(*cur)); 1088 + return NVME_NIDT_UUID_LEN; 1089 + default: 1090 + /* Skip unknown types */ 1091 + return cur->nidl; 1092 + } 1093 + } 1094 + 1049 1095 static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid, 1050 1096 struct nvme_ns_ids *ids) 1051 1097 { ··· 1102 1074 1103 1075 status = nvme_submit_sync_cmd(ctrl->admin_q, &c, data, 1104 1076 NVME_IDENTIFY_DATA_SIZE); 1105 - if (status) 1077 + if (status) { 1078 + dev_warn(ctrl->device, 1079 + "Identify Descriptors failed (%d)\n", status); 1080 + /* 1081 + * Don't treat an error as fatal, as we potentially already 1082 + * have a NGUID or EUI-64. 1083 + */ 1084 + if (status > 0) 1085 + status = 0; 1106 1086 goto free_data; 1087 + } 1107 1088 1108 1089 for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) { 1109 1090 struct nvme_ns_id_desc *cur = data + pos; ··· 1120 1083 if (cur->nidl == 0) 1121 1084 break; 1122 1085 1123 - switch (cur->nidt) { 1124 - case NVME_NIDT_EUI64: 1125 - if (cur->nidl != NVME_NIDT_EUI64_LEN) { 1126 - dev_warn(ctrl->device, 1127 - "ctrl returned bogus length: %d for NVME_NIDT_EUI64\n", 1128 - cur->nidl); 1129 - goto free_data; 1130 - } 1131 - len = NVME_NIDT_EUI64_LEN; 1132 - memcpy(ids->eui64, data + pos + sizeof(*cur), len); 1133 - break; 1134 - case NVME_NIDT_NGUID: 1135 - if (cur->nidl != NVME_NIDT_NGUID_LEN) { 1136 - dev_warn(ctrl->device, 1137 - "ctrl returned bogus length: %d for NVME_NIDT_NGUID\n", 1138 - cur->nidl); 1139 - goto free_data; 1140 - } 1141 - len = NVME_NIDT_NGUID_LEN; 1142 - memcpy(ids->nguid, data + pos + sizeof(*cur), len); 1143 - break; 1144 - case NVME_NIDT_UUID: 1145 - if (cur->nidl != NVME_NIDT_UUID_LEN) { 1146 - dev_warn(ctrl->device, 1147 - "ctrl returned bogus length: %d for NVME_NIDT_UUID\n", 1148 - cur->nidl); 1149 - goto free_data; 1150 - } 1151 - len = NVME_NIDT_UUID_LEN; 1152 - uuid_copy(&ids->uuid, data + pos + sizeof(*cur)); 1153 - break; 1154 - default: 1155 - /* Skip unknown types */ 1156 - len = cur->nidl; 1157 - break; 1158 - } 1086 + len = nvme_process_ns_desc(ctrl, ids, cur); 1087 + if (len < 0) 1088 + goto free_data; 1159 1089 1160 1090 len += sizeof(*cur); 1161 1091 } ··· 1588 1584 return ret; 1589 1585 } 1590 1586 1587 + #ifdef CONFIG_COMPAT 1588 + struct nvme_user_io32 { 1589 + __u8 opcode; 1590 + __u8 flags; 1591 + __u16 control; 1592 + __u16 nblocks; 1593 + __u16 rsvd; 1594 + __u64 metadata; 1595 + __u64 addr; 1596 + __u64 slba; 1597 + __u32 dsmgmt; 1598 + __u32 reftag; 1599 + __u16 apptag; 1600 + __u16 appmask; 1601 + } __attribute__((__packed__)); 1602 + 1603 + #define NVME_IOCTL_SUBMIT_IO32 _IOW('N', 0x42, struct nvme_user_io32) 1604 + 1605 + static int nvme_compat_ioctl(struct block_device *bdev, fmode_t mode, 1606 + unsigned int cmd, unsigned long arg) 1607 + { 1608 + /* 1609 + * Corresponds to the difference of NVME_IOCTL_SUBMIT_IO 1610 + * between 32 bit programs and 64 bit kernel. 1611 + * The cause is that the results of sizeof(struct nvme_user_io), 1612 + * which is used to define NVME_IOCTL_SUBMIT_IO, 1613 + * are not same between 32 bit compiler and 64 bit compiler. 1614 + * NVME_IOCTL_SUBMIT_IO32 is for 64 bit kernel handling 1615 + * NVME_IOCTL_SUBMIT_IO issued from 32 bit programs. 1616 + * Other IOCTL numbers are same between 32 bit and 64 bit. 1617 + * So there is nothing to do regarding to other IOCTL numbers. 1618 + */ 1619 + if (cmd == NVME_IOCTL_SUBMIT_IO32) 1620 + return nvme_ioctl(bdev, mode, NVME_IOCTL_SUBMIT_IO, arg); 1621 + 1622 + return nvme_ioctl(bdev, mode, cmd, arg); 1623 + } 1624 + #else 1625 + #define nvme_compat_ioctl NULL 1626 + #endif /* CONFIG_COMPAT */ 1627 + 1591 1628 static int nvme_open(struct block_device *bdev, fmode_t mode) 1592 1629 { 1593 1630 struct nvme_ns *ns = bdev->bd_disk->private_data; ··· 1766 1721 static int nvme_report_ns_ids(struct nvme_ctrl *ctrl, unsigned int nsid, 1767 1722 struct nvme_id_ns *id, struct nvme_ns_ids *ids) 1768 1723 { 1769 - int ret = 0; 1770 - 1771 1724 memset(ids, 0, sizeof(*ids)); 1772 1725 1773 1726 if (ctrl->vs >= NVME_VS(1, 1, 0)) 1774 1727 memcpy(ids->eui64, id->eui64, sizeof(id->eui64)); 1775 1728 if (ctrl->vs >= NVME_VS(1, 2, 0)) 1776 1729 memcpy(ids->nguid, id->nguid, sizeof(id->nguid)); 1777 - if (ctrl->vs >= NVME_VS(1, 3, 0)) { 1778 - /* Don't treat error as fatal we potentially 1779 - * already have a NGUID or EUI-64 1780 - */ 1781 - ret = nvme_identify_ns_descs(ctrl, nsid, ids); 1782 - if (ret) 1783 - dev_warn(ctrl->device, 1784 - "Identify Descriptors failed (%d)\n", ret); 1785 - if (ret > 0) 1786 - ret = 0; 1787 - } 1788 - return ret; 1730 + if (ctrl->vs >= NVME_VS(1, 3, 0)) 1731 + return nvme_identify_ns_descs(ctrl, nsid, ids); 1732 + return 0; 1789 1733 } 1790 1734 1791 1735 static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids) ··· 2061 2027 static const struct block_device_operations nvme_fops = { 2062 2028 .owner = THIS_MODULE, 2063 2029 .ioctl = nvme_ioctl, 2064 - .compat_ioctl = nvme_ioctl, 2030 + .compat_ioctl = nvme_compat_ioctl, 2065 2031 .open = nvme_open, 2066 2032 .release = nvme_release, 2067 2033 .getgeo = nvme_getgeo, ··· 2089 2055 .open = nvme_ns_head_open, 2090 2056 .release = nvme_ns_head_release, 2091 2057 .ioctl = nvme_ioctl, 2092 - .compat_ioctl = nvme_ioctl, 2058 + .compat_ioctl = nvme_compat_ioctl, 2093 2059 .getgeo = nvme_getgeo, 2094 2060 .pr_ops = &nvme_pr_ops, 2095 2061 }; ··· 2108 2074 if ((csts & NVME_CSTS_RDY) == bit) 2109 2075 break; 2110 2076 2111 - msleep(100); 2077 + usleep_range(1000, 2000); 2112 2078 if (fatal_signal_pending(current)) 2113 2079 return -EINTR; 2114 2080 if (time_after(jiffies, timeout)) { 2115 2081 dev_err(ctrl->device, 2116 - "Device not ready; aborting %s\n", enabled ? 2117 - "initialisation" : "reset"); 2082 + "Device not ready; aborting %s, CSTS=0x%x\n", 2083 + enabled ? "initialisation" : "reset", csts); 2118 2084 return -ENODEV; 2119 2085 } 2120 2086 } ··· 2625 2591 lockdep_assert_held(&nvme_subsystems_lock); 2626 2592 2627 2593 list_for_each_entry(tmp, &subsys->ctrls, subsys_entry) { 2628 - if (tmp->state == NVME_CTRL_DELETING || 2629 - tmp->state == NVME_CTRL_DEAD) 2594 + if (nvme_state_terminal(tmp)) 2630 2595 continue; 2631 2596 2632 2597 if (tmp->cntlid == ctrl->cntlid) { ··· 3226 3193 { 3227 3194 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3228 3195 3196 + /* Can't delete non-created controllers */ 3197 + if (!ctrl->created) 3198 + return -EBUSY; 3199 + 3229 3200 if (device_remove_file_self(dev, attr)) 3230 3201 nvme_delete_ctrl_sync(ctrl); 3231 3202 return count; ··· 3279 3242 } 3280 3243 static DEVICE_ATTR(subsysnqn, S_IRUGO, nvme_sysfs_show_subsysnqn, NULL); 3281 3244 3245 + static ssize_t nvme_sysfs_show_hostnqn(struct device *dev, 3246 + struct device_attribute *attr, 3247 + char *buf) 3248 + { 3249 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3250 + 3251 + return snprintf(buf, PAGE_SIZE, "%s\n", ctrl->opts->host->nqn); 3252 + } 3253 + static DEVICE_ATTR(hostnqn, S_IRUGO, nvme_sysfs_show_hostnqn, NULL); 3254 + 3255 + static ssize_t nvme_sysfs_show_hostid(struct device *dev, 3256 + struct device_attribute *attr, 3257 + char *buf) 3258 + { 3259 + struct nvme_ctrl *ctrl = dev_get_drvdata(dev); 3260 + 3261 + return snprintf(buf, PAGE_SIZE, "%pU\n", &ctrl->opts->host->id); 3262 + } 3263 + static DEVICE_ATTR(hostid, S_IRUGO, nvme_sysfs_show_hostid, NULL); 3264 + 3282 3265 static ssize_t nvme_sysfs_show_address(struct device *dev, 3283 3266 struct device_attribute *attr, 3284 3267 char *buf) ··· 3324 3267 &dev_attr_numa_node.attr, 3325 3268 &dev_attr_queue_count.attr, 3326 3269 &dev_attr_sqsize.attr, 3270 + &dev_attr_hostnqn.attr, 3271 + &dev_attr_hostid.attr, 3327 3272 NULL 3328 3273 }; 3329 3274 ··· 3338 3279 if (a == &dev_attr_delete_controller.attr && !ctrl->ops->delete_ctrl) 3339 3280 return 0; 3340 3281 if (a == &dev_attr_address.attr && !ctrl->ops->get_address) 3282 + return 0; 3283 + if (a == &dev_attr_hostnqn.attr && !ctrl->opts) 3284 + return 0; 3285 + if (a == &dev_attr_hostid.attr && !ctrl->opts) 3341 3286 return 0; 3342 3287 3343 3288 return a->mode; ··· 3357 3294 NULL, 3358 3295 }; 3359 3296 3360 - static struct nvme_ns_head *__nvme_find_ns_head(struct nvme_subsystem *subsys, 3297 + static struct nvme_ns_head *nvme_find_ns_head(struct nvme_subsystem *subsys, 3361 3298 unsigned nsid) 3362 3299 { 3363 3300 struct nvme_ns_head *h; ··· 3390 3327 } 3391 3328 3392 3329 static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl, 3393 - unsigned nsid, struct nvme_id_ns *id) 3330 + unsigned nsid, struct nvme_id_ns *id, 3331 + struct nvme_ns_ids *ids) 3394 3332 { 3395 3333 struct nvme_ns_head *head; 3396 3334 size_t size = sizeof(*head); ··· 3414 3350 goto out_ida_remove; 3415 3351 head->subsys = ctrl->subsys; 3416 3352 head->ns_id = nsid; 3353 + head->ids = *ids; 3417 3354 kref_init(&head->ref); 3418 - 3419 - ret = nvme_report_ns_ids(ctrl, nsid, id, &head->ids); 3420 - if (ret) 3421 - goto out_cleanup_srcu; 3422 3355 3423 3356 ret = __nvme_check_ids(ctrl->subsys, head); 3424 3357 if (ret) { ··· 3451 3390 struct nvme_ctrl *ctrl = ns->ctrl; 3452 3391 bool is_shared = id->nmic & (1 << 0); 3453 3392 struct nvme_ns_head *head = NULL; 3393 + struct nvme_ns_ids ids; 3454 3394 int ret = 0; 3395 + 3396 + ret = nvme_report_ns_ids(ctrl, nsid, id, &ids); 3397 + if (ret) 3398 + goto out; 3455 3399 3456 3400 mutex_lock(&ctrl->subsys->lock); 3457 3401 if (is_shared) 3458 - head = __nvme_find_ns_head(ctrl->subsys, nsid); 3402 + head = nvme_find_ns_head(ctrl->subsys, nsid); 3459 3403 if (!head) { 3460 - head = nvme_alloc_ns_head(ctrl, nsid, id); 3404 + head = nvme_alloc_ns_head(ctrl, nsid, id, &ids); 3461 3405 if (IS_ERR(head)) { 3462 3406 ret = PTR_ERR(head); 3463 3407 goto out_unlock; 3464 3408 } 3465 3409 } else { 3466 - struct nvme_ns_ids ids; 3467 - 3468 - ret = nvme_report_ns_ids(ctrl, nsid, id, &ids); 3469 - if (ret) 3470 - goto out_unlock; 3471 - 3472 3410 if (!nvme_ns_ids_equal(&head->ids, &ids)) { 3473 3411 dev_err(ctrl->device, 3474 3412 "IDs don't match for shared namespace %d\n", ··· 3482 3422 3483 3423 out_unlock: 3484 3424 mutex_unlock(&ctrl->subsys->lock); 3425 + out: 3485 3426 if (ret > 0) 3486 3427 ret = blk_status_to_errno(nvme_error_status(ret)); 3487 3428 return ret; ··· 3541 3480 return 0; 3542 3481 } 3543 3482 3544 - static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) 3483 + static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) 3545 3484 { 3546 3485 struct nvme_ns *ns; 3547 3486 struct gendisk *disk; ··· 3551 3490 3552 3491 ns = kzalloc_node(sizeof(*ns), GFP_KERNEL, node); 3553 3492 if (!ns) 3554 - return -ENOMEM; 3493 + return; 3555 3494 3556 3495 ns->queue = blk_mq_init_queue(ctrl->tagset); 3557 - if (IS_ERR(ns->queue)) { 3558 - ret = PTR_ERR(ns->queue); 3496 + if (IS_ERR(ns->queue)) 3559 3497 goto out_free_ns; 3560 - } 3561 3498 3562 3499 if (ctrl->opts && ctrl->opts->data_digest) 3563 3500 ns->queue->backing_dev_info->capabilities ··· 3578 3519 if (ret) 3579 3520 goto out_free_queue; 3580 3521 3581 - if (id->ncap == 0) { 3582 - ret = -EINVAL; 3522 + if (id->ncap == 0) /* no namespace (legacy quirk) */ 3583 3523 goto out_free_id; 3584 - } 3585 3524 3586 3525 ret = nvme_init_ns_head(ns, nsid, id); 3587 3526 if (ret) ··· 3588 3531 nvme_set_disk_name(disk_name, ns, ctrl, &flags); 3589 3532 3590 3533 disk = alloc_disk_node(0, node); 3591 - if (!disk) { 3592 - ret = -ENOMEM; 3534 + if (!disk) 3593 3535 goto out_unlink_ns; 3594 - } 3595 3536 3596 3537 disk->fops = &nvme_fops; 3597 3538 disk->private_data = ns; ··· 3620 3565 nvme_fault_inject_init(&ns->fault_inject, ns->disk->disk_name); 3621 3566 kfree(id); 3622 3567 3623 - return 0; 3568 + return; 3624 3569 out_put_disk: 3625 3570 put_disk(ns->disk); 3626 3571 out_unlink_ns: ··· 3634 3579 blk_cleanup_queue(ns->queue); 3635 3580 out_free_ns: 3636 3581 kfree(ns); 3637 - if (ret > 0) 3638 - ret = blk_status_to_errno(nvme_error_status(ret)); 3639 - return ret; 3640 3582 } 3641 3583 3642 3584 static void nvme_ns_remove(struct nvme_ns *ns) ··· 4039 3987 nvme_queue_scan(ctrl); 4040 3988 nvme_start_queues(ctrl); 4041 3989 } 3990 + ctrl->created = true; 4042 3991 } 4043 3992 EXPORT_SYMBOL_GPL(nvme_start_ctrl); 4044 3993 ··· 4048 3995 nvme_fault_inject_fini(&ctrl->fault_inject); 4049 3996 dev_pm_qos_hide_latency_tolerance(ctrl->device); 4050 3997 cdev_device_del(&ctrl->cdev, ctrl->device); 3998 + nvme_put_ctrl(ctrl); 4051 3999 } 4052 4000 EXPORT_SYMBOL_GPL(nvme_uninit_ctrl); 4053 4001 ··· 4131 4077 if (ret) 4132 4078 goto out_release_instance; 4133 4079 4080 + nvme_get_ctrl(ctrl); 4134 4081 cdev_init(&ctrl->cdev, &nvme_dev_fops); 4135 4082 ctrl->cdev.owner = ops->module; 4136 4083 ret = cdev_device_add(&ctrl->cdev, ctrl->device); ··· 4150 4095 4151 4096 return 0; 4152 4097 out_free_name: 4098 + nvme_put_ctrl(ctrl); 4153 4099 kfree_const(ctrl->device->kobj.name); 4154 4100 out_release_instance: 4155 4101 ida_simple_remove(&nvme_instance_ida, ctrl->instance); ··· 4355 4299 destroy_workqueue(nvme_delete_wq); 4356 4300 destroy_workqueue(nvme_reset_wq); 4357 4301 destroy_workqueue(nvme_wq); 4302 + ida_destroy(&nvme_instance_ida); 4358 4303 } 4359 4304 4360 4305 MODULE_LICENSE("GPL");
+4 -4
drivers/nvme/host/fabrics.c
··· 105 105 int len = 0; 106 106 107 107 if (ctrl->opts->mask & NVMF_OPT_TRADDR) 108 - len += snprintf(buf, size, "traddr=%s", ctrl->opts->traddr); 108 + len += scnprintf(buf, size, "traddr=%s", ctrl->opts->traddr); 109 109 if (ctrl->opts->mask & NVMF_OPT_TRSVCID) 110 - len += snprintf(buf + len, size - len, "%strsvcid=%s", 110 + len += scnprintf(buf + len, size - len, "%strsvcid=%s", 111 111 (len) ? "," : "", ctrl->opts->trsvcid); 112 112 if (ctrl->opts->mask & NVMF_OPT_HOST_TRADDR) 113 - len += snprintf(buf + len, size - len, "%shost_traddr=%s", 113 + len += scnprintf(buf + len, size - len, "%shost_traddr=%s", 114 114 (len) ? "," : "", ctrl->opts->host_traddr); 115 - len += snprintf(buf + len, size - len, "\n"); 115 + len += scnprintf(buf + len, size - len, "\n"); 116 116 117 117 return len; 118 118 }
-3
drivers/nvme/host/fc.c
··· 3181 3181 goto fail_ctrl; 3182 3182 } 3183 3183 3184 - nvme_get_ctrl(&ctrl->ctrl); 3185 - 3186 3184 if (!queue_delayed_work(nvme_wq, &ctrl->connect_work, 0)) { 3187 - nvme_put_ctrl(&ctrl->ctrl); 3188 3185 dev_err(ctrl->ctrl.device, 3189 3186 "NVME-FC{%d}: failed to schedule initial connect\n", 3190 3187 ctrl->cnum);
+9 -12
drivers/nvme/host/multipath.c
··· 64 64 } 65 65 } 66 66 67 - void nvme_failover_req(struct request *req) 67 + bool nvme_failover_req(struct request *req) 68 68 { 69 69 struct nvme_ns *ns = req->q->queuedata; 70 70 u16 status = nvme_req(req)->status; 71 71 unsigned long flags; 72 - 73 - spin_lock_irqsave(&ns->head->requeue_lock, flags); 74 - blk_steal_bios(&ns->head->requeue_list, req); 75 - spin_unlock_irqrestore(&ns->head->requeue_lock, flags); 76 - blk_mq_end_request(req, 0); 77 72 78 73 switch (status & 0x7ff) { 79 74 case NVME_SC_ANA_TRANSITION: ··· 98 103 nvme_mpath_clear_current_path(ns); 99 104 break; 100 105 default: 101 - /* 102 - * Reset the controller for any non-ANA error as we don't know 103 - * what caused the error. 104 - */ 105 - nvme_reset_ctrl(ns->ctrl); 106 - break; 106 + /* This was a non-ANA error so follow the normal error path. */ 107 + return false; 107 108 } 108 109 110 + spin_lock_irqsave(&ns->head->requeue_lock, flags); 111 + blk_steal_bios(&ns->head->requeue_list, req); 112 + spin_unlock_irqrestore(&ns->head->requeue_lock, flags); 113 + blk_mq_end_request(req, 0); 114 + 109 115 kblockd_schedule_work(&ns->head->requeue_work); 116 + return true; 110 117 } 111 118 112 119 void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl)
+4 -2
drivers/nvme/host/nvme.h
··· 259 259 struct nvme_command ka_cmd; 260 260 struct work_struct fw_act_work; 261 261 unsigned long events; 262 + bool created; 262 263 263 264 #ifdef CONFIG_NVME_MULTIPATH 264 265 /* asymmetric namespace access: */ ··· 551 550 void nvme_mpath_start_freeze(struct nvme_subsystem *subsys); 552 551 void nvme_set_disk_name(char *disk_name, struct nvme_ns *ns, 553 552 struct nvme_ctrl *ctrl, int *flags); 554 - void nvme_failover_req(struct request *req); 553 + bool nvme_failover_req(struct request *req); 555 554 void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl); 556 555 int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl,struct nvme_ns_head *head); 557 556 void nvme_mpath_add_disk(struct nvme_ns *ns, struct nvme_id_ns *id); ··· 600 599 sprintf(disk_name, "nvme%dn%d", ctrl->instance, ns->head->instance); 601 600 } 602 601 603 - static inline void nvme_failover_req(struct request *req) 602 + static inline bool nvme_failover_req(struct request *req) 604 603 { 604 + return false; 605 605 } 606 606 static inline void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl) 607 607 {
+28 -63
drivers/nvme/host/pci.c
··· 971 971 nvme_end_request(req, cqe->status, cqe->result); 972 972 } 973 973 974 - static void nvme_complete_cqes(struct nvme_queue *nvmeq, u16 start, u16 end) 975 - { 976 - while (start != end) { 977 - nvme_handle_cqe(nvmeq, start); 978 - if (++start == nvmeq->q_depth) 979 - start = 0; 980 - } 981 - } 982 - 983 974 static inline void nvme_update_cq_head(struct nvme_queue *nvmeq) 984 975 { 985 - if (nvmeq->cq_head == nvmeq->q_depth - 1) { 976 + if (++nvmeq->cq_head == nvmeq->q_depth) { 986 977 nvmeq->cq_head = 0; 987 - nvmeq->cq_phase = !nvmeq->cq_phase; 988 - } else { 989 - nvmeq->cq_head++; 978 + nvmeq->cq_phase ^= 1; 990 979 } 991 980 } 992 981 993 - static inline int nvme_process_cq(struct nvme_queue *nvmeq, u16 *start, 994 - u16 *end, unsigned int tag) 982 + static inline int nvme_process_cq(struct nvme_queue *nvmeq) 995 983 { 996 984 int found = 0; 997 985 998 - *start = nvmeq->cq_head; 999 986 while (nvme_cqe_pending(nvmeq)) { 1000 - if (tag == -1U || nvmeq->cqes[nvmeq->cq_head].command_id == tag) 1001 - found++; 987 + found++; 988 + nvme_handle_cqe(nvmeq, nvmeq->cq_head); 1002 989 nvme_update_cq_head(nvmeq); 1003 990 } 1004 - *end = nvmeq->cq_head; 1005 991 1006 - if (*start != *end) 992 + if (found) 1007 993 nvme_ring_cq_doorbell(nvmeq); 1008 994 return found; 1009 995 } ··· 998 1012 { 999 1013 struct nvme_queue *nvmeq = data; 1000 1014 irqreturn_t ret = IRQ_NONE; 1001 - u16 start, end; 1002 1015 1003 1016 /* 1004 1017 * The rmb/wmb pair ensures we see all updates from a previous run of 1005 1018 * the irq handler, even if that was on another CPU. 1006 1019 */ 1007 1020 rmb(); 1008 - nvme_process_cq(nvmeq, &start, &end, -1); 1021 + if (nvme_process_cq(nvmeq)) 1022 + ret = IRQ_HANDLED; 1009 1023 wmb(); 1010 - 1011 - if (start != end) { 1012 - nvme_complete_cqes(nvmeq, start, end); 1013 - return IRQ_HANDLED; 1014 - } 1015 1024 1016 1025 return ret; 1017 1026 } ··· 1020 1039 } 1021 1040 1022 1041 /* 1023 - * Poll for completions any queue, including those not dedicated to polling. 1042 + * Poll for completions for any interrupt driven queue 1024 1043 * Can be called from any context. 1025 1044 */ 1026 - static int nvme_poll_irqdisable(struct nvme_queue *nvmeq, unsigned int tag) 1045 + static void nvme_poll_irqdisable(struct nvme_queue *nvmeq) 1027 1046 { 1028 1047 struct pci_dev *pdev = to_pci_dev(nvmeq->dev->dev); 1029 - u16 start, end; 1030 - int found; 1031 1048 1032 - /* 1033 - * For a poll queue we need to protect against the polling thread 1034 - * using the CQ lock. For normal interrupt driven threads we have 1035 - * to disable the interrupt to avoid racing with it. 1036 - */ 1037 - if (test_bit(NVMEQ_POLLED, &nvmeq->flags)) { 1038 - spin_lock(&nvmeq->cq_poll_lock); 1039 - found = nvme_process_cq(nvmeq, &start, &end, tag); 1040 - spin_unlock(&nvmeq->cq_poll_lock); 1041 - } else { 1042 - disable_irq(pci_irq_vector(pdev, nvmeq->cq_vector)); 1043 - found = nvme_process_cq(nvmeq, &start, &end, tag); 1044 - enable_irq(pci_irq_vector(pdev, nvmeq->cq_vector)); 1045 - } 1049 + WARN_ON_ONCE(test_bit(NVMEQ_POLLED, &nvmeq->flags)); 1046 1050 1047 - nvme_complete_cqes(nvmeq, start, end); 1048 - return found; 1051 + disable_irq(pci_irq_vector(pdev, nvmeq->cq_vector)); 1052 + nvme_process_cq(nvmeq); 1053 + enable_irq(pci_irq_vector(pdev, nvmeq->cq_vector)); 1049 1054 } 1050 1055 1051 1056 static int nvme_poll(struct blk_mq_hw_ctx *hctx) 1052 1057 { 1053 1058 struct nvme_queue *nvmeq = hctx->driver_data; 1054 - u16 start, end; 1055 1059 bool found; 1056 1060 1057 1061 if (!nvme_cqe_pending(nvmeq)) 1058 1062 return 0; 1059 1063 1060 1064 spin_lock(&nvmeq->cq_poll_lock); 1061 - found = nvme_process_cq(nvmeq, &start, &end, -1); 1062 - nvme_complete_cqes(nvmeq, start, end); 1065 + found = nvme_process_cq(nvmeq); 1063 1066 spin_unlock(&nvmeq->cq_poll_lock); 1064 1067 1065 1068 return found; ··· 1220 1255 /* 1221 1256 * Did we miss an interrupt? 1222 1257 */ 1223 - if (nvme_poll_irqdisable(nvmeq, req->tag)) { 1258 + if (test_bit(NVMEQ_POLLED, &nvmeq->flags)) 1259 + nvme_poll(req->mq_hctx); 1260 + else 1261 + nvme_poll_irqdisable(nvmeq); 1262 + 1263 + if (blk_mq_request_completed(req)) { 1224 1264 dev_warn(dev->ctrl.device, 1225 1265 "I/O %d QID %d timeout, completion polled\n", 1226 1266 req->tag, nvmeq->qid); ··· 1368 1398 else 1369 1399 nvme_disable_ctrl(&dev->ctrl); 1370 1400 1371 - nvme_poll_irqdisable(nvmeq, -1); 1401 + nvme_poll_irqdisable(nvmeq); 1372 1402 } 1373 1403 1374 1404 /* ··· 1379 1409 */ 1380 1410 static void nvme_reap_pending_cqes(struct nvme_dev *dev) 1381 1411 { 1382 - u16 start, end; 1383 1412 int i; 1384 1413 1385 - for (i = dev->ctrl.queue_count - 1; i > 0; i--) { 1386 - nvme_process_cq(&dev->queues[i], &start, &end, -1); 1387 - nvme_complete_cqes(&dev->queues[i], start, end); 1388 - } 1414 + for (i = dev->ctrl.queue_count - 1; i > 0; i--) 1415 + nvme_process_cq(&dev->queues[i]); 1389 1416 } 1390 1417 1391 1418 static int nvme_cmb_qdepth(struct nvme_dev *dev, int nr_io_queues, ··· 2470 2503 struct nvme_dev *dev = to_nvme_dev(ctrl); 2471 2504 2472 2505 nvme_dbbuf_dma_free(dev); 2473 - put_device(dev->dev); 2474 2506 nvme_free_tagset(dev); 2475 2507 if (dev->ctrl.admin_q) 2476 2508 blk_put_queue(dev->ctrl.admin_q); 2477 - kfree(dev->queues); 2478 2509 free_opal_dev(dev->ctrl.opal_dev); 2479 2510 mempool_destroy(dev->iod_mempool); 2511 + put_device(dev->dev); 2512 + kfree(dev->queues); 2480 2513 kfree(dev); 2481 2514 } 2482 2515 ··· 2656 2689 { 2657 2690 struct pci_dev *pdev = to_pci_dev(to_nvme_dev(ctrl)->dev); 2658 2691 2659 - return snprintf(buf, size, "%s", dev_name(&pdev->dev)); 2692 + return snprintf(buf, size, "%s\n", dev_name(&pdev->dev)); 2660 2693 } 2661 2694 2662 2695 static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = { ··· 2802 2835 dev_info(dev->ctrl.device, "pci function %s\n", dev_name(&pdev->dev)); 2803 2836 2804 2837 nvme_reset_ctrl(&dev->ctrl); 2805 - nvme_get_ctrl(&dev->ctrl); 2806 2838 async_schedule(nvme_async_probe, dev); 2807 2839 2808 2840 return 0; ··· 2873 2907 nvme_free_host_mem(dev); 2874 2908 nvme_dev_remove_admin(dev); 2875 2909 nvme_free_queues(dev, 0); 2876 - nvme_uninit_ctrl(&dev->ctrl); 2877 2910 nvme_release_prp_pools(dev); 2878 2911 nvme_dev_unmap(dev); 2879 - nvme_put_ctrl(&dev->ctrl); 2912 + nvme_uninit_ctrl(&dev->ctrl); 2880 2913 } 2881 2914 2882 2915 #ifdef CONFIG_PM_SLEEP
+6 -3
drivers/nvme/host/rdma.c
··· 1024 1024 1025 1025 changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE); 1026 1026 if (!changed) { 1027 - /* state change failure is ok if we're in DELETING state */ 1027 + /* 1028 + * state change failure is ok if we're in DELETING state, 1029 + * unless we're during creation of a new controller to 1030 + * avoid races with teardown flow. 1031 + */ 1028 1032 WARN_ON_ONCE(ctrl->ctrl.state != NVME_CTRL_DELETING); 1033 + WARN_ON_ONCE(new); 1029 1034 ret = -EINVAL; 1030 1035 goto destroy_io; 1031 1036 } ··· 2049 2044 2050 2045 dev_info(ctrl->ctrl.device, "new ctrl: NQN \"%s\", addr %pISpcs\n", 2051 2046 ctrl->ctrl.opts->subsysnqn, &ctrl->addr); 2052 - 2053 - nvme_get_ctrl(&ctrl->ctrl); 2054 2047 2055 2048 mutex_lock(&nvme_rdma_ctrl_mutex); 2056 2049 list_add_tail(&ctrl->list, &nvme_rdma_ctrl_list);
+96 -24
drivers/nvme/host/tcp.c
··· 20 20 21 21 struct nvme_tcp_queue; 22 22 23 + /* Define the socket priority to use for connections were it is desirable 24 + * that the NIC consider performing optimized packet processing or filtering. 25 + * A non-zero value being sufficient to indicate general consideration of any 26 + * possible optimization. Making it a module param allows for alternative 27 + * values that may be unique for some NIC implementations. 28 + */ 29 + static int so_priority; 30 + module_param(so_priority, int, 0644); 31 + MODULE_PARM_DESC(so_priority, "nvme tcp socket optimize priority"); 32 + 23 33 enum nvme_tcp_send_state { 24 34 NVME_TCP_SEND_CMD_PDU = 0, 25 35 NVME_TCP_SEND_H2C_PDU, ··· 1027 1017 if (req->state == NVME_TCP_SEND_DDGST) 1028 1018 ret = nvme_tcp_try_send_ddgst(req); 1029 1019 done: 1030 - if (ret == -EAGAIN) 1020 + if (ret == -EAGAIN) { 1031 1021 ret = 0; 1022 + } else if (ret < 0) { 1023 + dev_err(queue->ctrl->ctrl.device, 1024 + "failed to send request %d\n", ret); 1025 + if (ret != -EPIPE && ret != -ECONNRESET) 1026 + nvme_tcp_fail_request(queue->request); 1027 + nvme_tcp_done_send_req(queue); 1028 + } 1032 1029 return ret; 1033 1030 } 1034 1031 ··· 1066 1049 int result; 1067 1050 1068 1051 result = nvme_tcp_try_send(queue); 1069 - if (result > 0) { 1052 + if (result > 0) 1070 1053 pending = true; 1071 - } else if (unlikely(result < 0)) { 1072 - dev_err(queue->ctrl->ctrl.device, 1073 - "failed to send request %d\n", result); 1074 - 1075 - /* 1076 - * Fail the request unless peer closed the connection, 1077 - * in which case error recovery flow will complete all. 1078 - */ 1079 - if ((result != -EPIPE) && (result != -ECONNRESET)) 1080 - nvme_tcp_fail_request(queue->request); 1081 - nvme_tcp_done_send_req(queue); 1082 - return; 1083 - } 1054 + else if (unlikely(result < 0)) 1055 + break; 1084 1056 1085 1057 result = nvme_tcp_try_recv(queue); 1086 1058 if (result > 0) 1087 1059 pending = true; 1060 + else if (unlikely(result < 0)) 1061 + break; 1088 1062 1089 1063 if (!pending) 1090 1064 return; ··· 1256 1248 return ret; 1257 1249 } 1258 1250 1251 + static bool nvme_tcp_admin_queue(struct nvme_tcp_queue *queue) 1252 + { 1253 + return nvme_tcp_queue_id(queue) == 0; 1254 + } 1255 + 1256 + static bool nvme_tcp_default_queue(struct nvme_tcp_queue *queue) 1257 + { 1258 + struct nvme_tcp_ctrl *ctrl = queue->ctrl; 1259 + int qid = nvme_tcp_queue_id(queue); 1260 + 1261 + return !nvme_tcp_admin_queue(queue) && 1262 + qid < 1 + ctrl->io_queues[HCTX_TYPE_DEFAULT]; 1263 + } 1264 + 1265 + static bool nvme_tcp_read_queue(struct nvme_tcp_queue *queue) 1266 + { 1267 + struct nvme_tcp_ctrl *ctrl = queue->ctrl; 1268 + int qid = nvme_tcp_queue_id(queue); 1269 + 1270 + return !nvme_tcp_admin_queue(queue) && 1271 + !nvme_tcp_default_queue(queue) && 1272 + qid < 1 + ctrl->io_queues[HCTX_TYPE_DEFAULT] + 1273 + ctrl->io_queues[HCTX_TYPE_READ]; 1274 + } 1275 + 1276 + static bool nvme_tcp_poll_queue(struct nvme_tcp_queue *queue) 1277 + { 1278 + struct nvme_tcp_ctrl *ctrl = queue->ctrl; 1279 + int qid = nvme_tcp_queue_id(queue); 1280 + 1281 + return !nvme_tcp_admin_queue(queue) && 1282 + !nvme_tcp_default_queue(queue) && 1283 + !nvme_tcp_read_queue(queue) && 1284 + qid < 1 + ctrl->io_queues[HCTX_TYPE_DEFAULT] + 1285 + ctrl->io_queues[HCTX_TYPE_READ] + 1286 + ctrl->io_queues[HCTX_TYPE_POLL]; 1287 + } 1288 + 1289 + static void nvme_tcp_set_queue_io_cpu(struct nvme_tcp_queue *queue) 1290 + { 1291 + struct nvme_tcp_ctrl *ctrl = queue->ctrl; 1292 + int qid = nvme_tcp_queue_id(queue); 1293 + int n = 0; 1294 + 1295 + if (nvme_tcp_default_queue(queue)) 1296 + n = qid - 1; 1297 + else if (nvme_tcp_read_queue(queue)) 1298 + n = qid - ctrl->io_queues[HCTX_TYPE_DEFAULT] - 1; 1299 + else if (nvme_tcp_poll_queue(queue)) 1300 + n = qid - ctrl->io_queues[HCTX_TYPE_DEFAULT] - 1301 + ctrl->io_queues[HCTX_TYPE_READ] - 1; 1302 + queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false); 1303 + } 1304 + 1259 1305 static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, 1260 1306 int qid, size_t queue_size) 1261 1307 { 1262 1308 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); 1263 1309 struct nvme_tcp_queue *queue = &ctrl->queues[qid]; 1264 1310 struct linger sol = { .l_onoff = 1, .l_linger = 0 }; 1265 - int ret, opt, rcv_pdu_size, n; 1311 + int ret, opt, rcv_pdu_size; 1266 1312 1267 1313 queue->ctrl = ctrl; 1268 1314 INIT_LIST_HEAD(&queue->send_list); ··· 1371 1309 goto err_sock; 1372 1310 } 1373 1311 1312 + if (so_priority > 0) { 1313 + ret = kernel_setsockopt(queue->sock, SOL_SOCKET, SO_PRIORITY, 1314 + (char *)&so_priority, sizeof(so_priority)); 1315 + if (ret) { 1316 + dev_err(ctrl->ctrl.device, 1317 + "failed to set SO_PRIORITY sock opt, ret %d\n", 1318 + ret); 1319 + goto err_sock; 1320 + } 1321 + } 1322 + 1374 1323 /* Set socket type of service */ 1375 1324 if (nctrl->opts->tos >= 0) { 1376 1325 opt = nctrl->opts->tos; ··· 1395 1322 } 1396 1323 1397 1324 queue->sock->sk->sk_allocation = GFP_ATOMIC; 1398 - if (!qid) 1399 - n = 0; 1400 - else 1401 - n = (qid - 1) % num_online_cpus(); 1402 - queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false); 1325 + nvme_tcp_set_queue_io_cpu(queue); 1403 1326 queue->request = NULL; 1404 1327 queue->data_remaining = 0; 1405 1328 queue->ddgst_remaining = 0; ··· 1930 1861 } 1931 1862 1932 1863 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_LIVE)) { 1933 - /* state change failure is ok if we're in DELETING state */ 1864 + /* 1865 + * state change failure is ok if we're in DELETING state, 1866 + * unless we're during creation of a new controller to 1867 + * avoid races with teardown flow. 1868 + */ 1934 1869 WARN_ON_ONCE(ctrl->state != NVME_CTRL_DELETING); 1870 + WARN_ON_ONCE(new); 1935 1871 ret = -EINVAL; 1936 1872 goto destroy_io; 1937 1873 } ··· 2432 2358 2433 2359 dev_info(ctrl->ctrl.device, "new ctrl: NQN \"%s\", addr %pISp\n", 2434 2360 ctrl->ctrl.opts->subsysnqn, &ctrl->addr); 2435 - 2436 - nvme_get_ctrl(&ctrl->ctrl); 2437 2361 2438 2362 mutex_lock(&nvme_tcp_ctrl_mutex); 2439 2363 list_add_tail(&ctrl->list, &nvme_tcp_ctrl_list);
+30 -4
drivers/nvme/target/admin-cmd.c
··· 323 323 nvmet_req_complete(req, NVME_SC_INVALID_FIELD | NVME_SC_DNR); 324 324 } 325 325 326 + static void nvmet_id_set_model_number(struct nvme_id_ctrl *id, 327 + struct nvmet_subsys *subsys) 328 + { 329 + const char *model = NVMET_DEFAULT_CTRL_MODEL; 330 + struct nvmet_subsys_model *subsys_model; 331 + 332 + rcu_read_lock(); 333 + subsys_model = rcu_dereference(subsys->model); 334 + if (subsys_model) 335 + model = subsys_model->number; 336 + memcpy_and_pad(id->mn, sizeof(id->mn), model, strlen(model), ' '); 337 + rcu_read_unlock(); 338 + } 339 + 326 340 static void nvmet_execute_identify_ctrl(struct nvmet_req *req) 327 341 { 328 342 struct nvmet_ctrl *ctrl = req->sq->ctrl; 329 343 struct nvme_id_ctrl *id; 330 344 u16 status = 0; 331 - const char model[] = "Linux"; 332 345 333 346 id = kzalloc(sizeof(*id), GFP_KERNEL); 334 347 if (!id) { ··· 356 343 memset(id->sn, ' ', sizeof(id->sn)); 357 344 bin2hex(id->sn, &ctrl->subsys->serial, 358 345 min(sizeof(ctrl->subsys->serial), sizeof(id->sn) / 2)); 359 - memcpy_and_pad(id->mn, sizeof(id->mn), model, sizeof(model) - 1, ' '); 346 + nvmet_id_set_model_number(id, ctrl->subsys); 360 347 memcpy_and_pad(id->fr, sizeof(id->fr), 361 348 UTS_RELEASE, strlen(UTS_RELEASE), ' '); 362 349 ··· 370 357 /* we support multiple ports, multiples hosts and ANA: */ 371 358 id->cmic = (1 << 0) | (1 << 1) | (1 << 3); 372 359 373 - /* no limit on data transfer sizes for now */ 374 - id->mdts = 0; 360 + /* Limit MDTS according to transport capability */ 361 + if (ctrl->ops->get_mdts) 362 + id->mdts = ctrl->ops->get_mdts(ctrl); 363 + else 364 + id->mdts = 0; 365 + 375 366 id->cntlid = cpu_to_le16(ctrl->cntlid); 376 367 id->ver = cpu_to_le32(ctrl->subsys->ver); 377 368 ··· 738 721 { 739 722 struct nvmet_subsys *subsys = req->sq->ctrl->subsys; 740 723 u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10); 724 + u32 cdw11 = le32_to_cpu(req->cmd->common.cdw11); 741 725 u16 status = 0; 726 + u16 nsqr; 727 + u16 ncqr; 742 728 743 729 if (!nvmet_check_data_len(req, 0)) 744 730 return; 745 731 746 732 switch (cdw10 & 0xff) { 747 733 case NVME_FEAT_NUM_QUEUES: 734 + ncqr = (cdw11 >> 16) & 0xffff; 735 + nsqr = cdw11 & 0xffff; 736 + if (ncqr == 0xffff || nsqr == 0xffff) { 737 + status = NVME_SC_INVALID_FIELD | NVME_SC_DNR; 738 + break; 739 + } 748 740 nvmet_set_result(req, 749 741 (subsys->max_qid - 1) | ((subsys->max_qid - 1) << 16)); 750 742 break;
+137 -9
drivers/nvme/target/configfs.c
··· 395 395 struct nvmet_subsys *subsys = ns->subsys; 396 396 int ret = 0; 397 397 398 - 399 398 mutex_lock(&subsys->lock); 400 399 if (ns->enabled) { 401 400 ret = -EBUSY; 402 401 goto out_unlock; 403 402 } 404 - 405 403 406 404 if (uuid_parse(page, &ns->uuid)) 407 405 ret = -EINVAL; ··· 813 815 (int)NVME_MAJOR(subsys->ver), 814 816 (int)NVME_MINOR(subsys->ver), 815 817 (int)NVME_TERTIARY(subsys->ver)); 816 - else 817 - return snprintf(page, PAGE_SIZE, "%d.%d\n", 818 - (int)NVME_MAJOR(subsys->ver), 819 - (int)NVME_MINOR(subsys->ver)); 818 + 819 + return snprintf(page, PAGE_SIZE, "%d.%d\n", 820 + (int)NVME_MAJOR(subsys->ver), 821 + (int)NVME_MINOR(subsys->ver)); 820 822 } 821 823 822 824 static ssize_t nvmet_subsys_attr_version_store(struct config_item *item, ··· 825 827 struct nvmet_subsys *subsys = to_subsys(item); 826 828 int major, minor, tertiary = 0; 827 829 int ret; 828 - 829 830 830 831 ret = sscanf(page, "%d.%d.%d\n", &major, &minor, &tertiary); 831 832 if (ret != 2 && ret != 3) ··· 849 852 static ssize_t nvmet_subsys_attr_serial_store(struct config_item *item, 850 853 const char *page, size_t count) 851 854 { 852 - struct nvmet_subsys *subsys = to_subsys(item); 855 + u64 serial; 856 + 857 + if (sscanf(page, "%llx\n", &serial) != 1) 858 + return -EINVAL; 853 859 854 860 down_write(&nvmet_config_sem); 855 - sscanf(page, "%llx\n", &subsys->serial); 861 + to_subsys(item)->serial = serial; 856 862 up_write(&nvmet_config_sem); 857 863 858 864 return count; 859 865 } 860 866 CONFIGFS_ATTR(nvmet_subsys_, attr_serial); 861 867 868 + static ssize_t nvmet_subsys_attr_cntlid_min_show(struct config_item *item, 869 + char *page) 870 + { 871 + return snprintf(page, PAGE_SIZE, "%u\n", to_subsys(item)->cntlid_min); 872 + } 873 + 874 + static ssize_t nvmet_subsys_attr_cntlid_min_store(struct config_item *item, 875 + const char *page, size_t cnt) 876 + { 877 + u16 cntlid_min; 878 + 879 + if (sscanf(page, "%hu\n", &cntlid_min) != 1) 880 + return -EINVAL; 881 + 882 + if (cntlid_min == 0) 883 + return -EINVAL; 884 + 885 + down_write(&nvmet_config_sem); 886 + if (cntlid_min >= to_subsys(item)->cntlid_max) 887 + goto out_unlock; 888 + to_subsys(item)->cntlid_min = cntlid_min; 889 + up_write(&nvmet_config_sem); 890 + return cnt; 891 + 892 + out_unlock: 893 + up_write(&nvmet_config_sem); 894 + return -EINVAL; 895 + } 896 + CONFIGFS_ATTR(nvmet_subsys_, attr_cntlid_min); 897 + 898 + static ssize_t nvmet_subsys_attr_cntlid_max_show(struct config_item *item, 899 + char *page) 900 + { 901 + return snprintf(page, PAGE_SIZE, "%u\n", to_subsys(item)->cntlid_max); 902 + } 903 + 904 + static ssize_t nvmet_subsys_attr_cntlid_max_store(struct config_item *item, 905 + const char *page, size_t cnt) 906 + { 907 + u16 cntlid_max; 908 + 909 + if (sscanf(page, "%hu\n", &cntlid_max) != 1) 910 + return -EINVAL; 911 + 912 + if (cntlid_max == 0) 913 + return -EINVAL; 914 + 915 + down_write(&nvmet_config_sem); 916 + if (cntlid_max <= to_subsys(item)->cntlid_min) 917 + goto out_unlock; 918 + to_subsys(item)->cntlid_max = cntlid_max; 919 + up_write(&nvmet_config_sem); 920 + return cnt; 921 + 922 + out_unlock: 923 + up_write(&nvmet_config_sem); 924 + return -EINVAL; 925 + } 926 + CONFIGFS_ATTR(nvmet_subsys_, attr_cntlid_max); 927 + 928 + static ssize_t nvmet_subsys_attr_model_show(struct config_item *item, 929 + char *page) 930 + { 931 + struct nvmet_subsys *subsys = to_subsys(item); 932 + struct nvmet_subsys_model *subsys_model; 933 + char *model = NVMET_DEFAULT_CTRL_MODEL; 934 + int ret; 935 + 936 + rcu_read_lock(); 937 + subsys_model = rcu_dereference(subsys->model); 938 + if (subsys_model) 939 + model = subsys_model->number; 940 + ret = snprintf(page, PAGE_SIZE, "%s\n", model); 941 + rcu_read_unlock(); 942 + 943 + return ret; 944 + } 945 + 946 + /* See Section 1.5 of NVMe 1.4 */ 947 + static bool nvmet_is_ascii(const char c) 948 + { 949 + return c >= 0x20 && c <= 0x7e; 950 + } 951 + 952 + static ssize_t nvmet_subsys_attr_model_store(struct config_item *item, 953 + const char *page, size_t count) 954 + { 955 + struct nvmet_subsys *subsys = to_subsys(item); 956 + struct nvmet_subsys_model *new_model; 957 + char *new_model_number; 958 + int pos = 0, len; 959 + 960 + len = strcspn(page, "\n"); 961 + if (!len) 962 + return -EINVAL; 963 + 964 + for (pos = 0; pos < len; pos++) { 965 + if (!nvmet_is_ascii(page[pos])) 966 + return -EINVAL; 967 + } 968 + 969 + new_model_number = kstrndup(page, len, GFP_KERNEL); 970 + if (!new_model_number) 971 + return -ENOMEM; 972 + 973 + new_model = kzalloc(sizeof(*new_model) + len + 1, GFP_KERNEL); 974 + if (!new_model) { 975 + kfree(new_model_number); 976 + return -ENOMEM; 977 + } 978 + memcpy(new_model->number, new_model_number, len); 979 + 980 + down_write(&nvmet_config_sem); 981 + mutex_lock(&subsys->lock); 982 + new_model = rcu_replace_pointer(subsys->model, new_model, 983 + mutex_is_locked(&subsys->lock)); 984 + mutex_unlock(&subsys->lock); 985 + up_write(&nvmet_config_sem); 986 + 987 + kfree_rcu(new_model, rcuhead); 988 + 989 + return count; 990 + } 991 + CONFIGFS_ATTR(nvmet_subsys_, attr_model); 992 + 862 993 static struct configfs_attribute *nvmet_subsys_attrs[] = { 863 994 &nvmet_subsys_attr_attr_allow_any_host, 864 995 &nvmet_subsys_attr_attr_version, 865 996 &nvmet_subsys_attr_attr_serial, 997 + &nvmet_subsys_attr_attr_cntlid_min, 998 + &nvmet_subsys_attr_attr_cntlid_max, 999 + &nvmet_subsys_attr_attr_model, 866 1000 NULL, 867 1001 }; 868 1002
+7 -2
drivers/nvme/target/core.c
··· 1289 1289 if (!ctrl->sqs) 1290 1290 goto out_free_cqs; 1291 1291 1292 + if (subsys->cntlid_min > subsys->cntlid_max) 1293 + goto out_free_cqs; 1294 + 1292 1295 ret = ida_simple_get(&cntlid_ida, 1293 - NVME_CNTLID_MIN, NVME_CNTLID_MAX, 1296 + subsys->cntlid_min, subsys->cntlid_max, 1294 1297 GFP_KERNEL); 1295 1298 if (ret < 0) { 1296 1299 status = NVME_SC_CONNECT_CTRL_BUSY | NVME_SC_DNR; ··· 1441 1438 kfree(subsys); 1442 1439 return ERR_PTR(-ENOMEM); 1443 1440 } 1444 - 1441 + subsys->cntlid_min = NVME_CNTLID_MIN; 1442 + subsys->cntlid_max = NVME_CNTLID_MAX; 1445 1443 kref_init(&subsys->ref); 1446 1444 1447 1445 mutex_init(&subsys->lock); ··· 1461 1457 WARN_ON_ONCE(!list_empty(&subsys->namespaces)); 1462 1458 1463 1459 kfree(subsys->subsysnqn); 1460 + kfree_rcu(subsys->model, rcuhead); 1464 1461 kfree(subsys); 1465 1462 } 1466 1463
-3
drivers/nvme/target/loop.c
··· 485 485 out_disable: 486 486 dev_warn(ctrl->ctrl.device, "Removing after reset failure\n"); 487 487 nvme_uninit_ctrl(&ctrl->ctrl); 488 - nvme_put_ctrl(&ctrl->ctrl); 489 488 } 490 489 491 490 static const struct nvme_ctrl_ops nvme_loop_ctrl_ops = { ··· 616 617 617 618 dev_info(ctrl->ctrl.device, 618 619 "new ctrl: \"%s\"\n", ctrl->ctrl.opts->subsysnqn); 619 - 620 - nvme_get_ctrl(&ctrl->ctrl); 621 620 622 621 changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE); 623 622 WARN_ON_ONCE(!changed);
+11
drivers/nvme/target/nvmet.h
··· 23 23 #define NVMET_ASYNC_EVENTS 4 24 24 #define NVMET_ERROR_LOG_SLOTS 128 25 25 #define NVMET_NO_ERROR_LOC ((u16)-1) 26 + #define NVMET_DEFAULT_CTRL_MODEL "Linux" 26 27 27 28 /* 28 29 * Supported optional AENs: ··· 203 202 struct nvme_error_slot slots[NVMET_ERROR_LOG_SLOTS]; 204 203 }; 205 204 205 + struct nvmet_subsys_model { 206 + struct rcu_head rcuhead; 207 + char number[]; 208 + }; 209 + 206 210 struct nvmet_subsys { 207 211 enum nvme_subsys_type type; 208 212 ··· 217 211 struct list_head namespaces; 218 212 unsigned int nr_namespaces; 219 213 unsigned int max_nsid; 214 + u16 cntlid_min; 215 + u16 cntlid_max; 220 216 221 217 struct list_head ctrls; 222 218 ··· 235 227 236 228 struct config_group namespaces_group; 237 229 struct config_group allowed_hosts_group; 230 + 231 + struct nvmet_subsys_model __rcu *model; 238 232 }; 239 233 240 234 static inline struct nvmet_subsys *to_subsys(struct config_item *item) ··· 289 279 struct nvmet_port *port, char *traddr); 290 280 u16 (*install_queue)(struct nvmet_sq *nvme_sq); 291 281 void (*discovery_chg)(struct nvmet_port *port); 282 + u8 (*get_mdts)(const struct nvmet_ctrl *ctrl); 292 283 }; 293 284 294 285 #define NVMET_MAX_INLINE_BIOVEC 8
+13 -2
drivers/nvme/target/rdma.c
··· 31 31 #define NVMET_RDMA_MAX_INLINE_SGE 4 32 32 #define NVMET_RDMA_MAX_INLINE_DATA_SIZE max_t(int, SZ_16K, PAGE_SIZE) 33 33 34 + /* Assume mpsmin == device_page_size == 4KB */ 35 + #define NVMET_RDMA_MAX_MDTS 8 36 + 34 37 struct nvmet_rdma_cmd { 35 38 struct ib_sge sge[NVMET_RDMA_MAX_INLINE_SGE + 1]; 36 39 struct ib_cqe cqe; ··· 978 975 { 979 976 struct ib_qp_init_attr qp_attr; 980 977 struct nvmet_rdma_device *ndev = queue->dev; 981 - int comp_vector, nr_cqe, ret, i; 978 + int comp_vector, nr_cqe, ret, i, factor; 982 979 983 980 /* 984 981 * Spread the io queues across completion vectors, ··· 1011 1008 qp_attr.qp_type = IB_QPT_RC; 1012 1009 /* +1 for drain */ 1013 1010 qp_attr.cap.max_send_wr = queue->send_queue_size + 1; 1014 - qp_attr.cap.max_rdma_ctxs = queue->send_queue_size; 1011 + factor = rdma_rw_mr_factor(ndev->device, queue->cm_id->port_num, 1012 + 1 << NVMET_RDMA_MAX_MDTS); 1013 + qp_attr.cap.max_rdma_ctxs = queue->send_queue_size * factor; 1015 1014 qp_attr.cap.max_send_sge = max(ndev->device->attrs.max_sge_rd, 1016 1015 ndev->device->attrs.max_send_sge); 1017 1016 ··· 1607 1602 } 1608 1603 } 1609 1604 1605 + static u8 nvmet_rdma_get_mdts(const struct nvmet_ctrl *ctrl) 1606 + { 1607 + return NVMET_RDMA_MAX_MDTS; 1608 + } 1609 + 1610 1610 static const struct nvmet_fabrics_ops nvmet_rdma_ops = { 1611 1611 .owner = THIS_MODULE, 1612 1612 .type = NVMF_TRTYPE_RDMA, ··· 1622 1612 .queue_response = nvmet_rdma_queue_response, 1623 1613 .delete_ctrl = nvmet_rdma_delete_ctrl, 1624 1614 .disc_traddr = nvmet_rdma_disc_port_addr, 1615 + .get_mdts = nvmet_rdma_get_mdts, 1625 1616 }; 1626 1617 1627 1618 static void nvmet_rdma_remove_one(struct ib_device *ib_device, void *client_data)
+32 -3
drivers/nvme/target/tcp.c
··· 19 19 20 20 #define NVMET_TCP_DEF_INLINE_DATA_SIZE (4 * PAGE_SIZE) 21 21 22 + /* Define the socket priority to use for connections were it is desirable 23 + * that the NIC consider performing optimized packet processing or filtering. 24 + * A non-zero value being sufficient to indicate general consideration of any 25 + * possible optimization. Making it a module param allows for alternative 26 + * values that may be unique for some NIC implementations. 27 + */ 28 + static int so_priority; 29 + module_param(so_priority, int, 0644); 30 + MODULE_PARM_DESC(so_priority, "nvmet tcp socket optimize priority"); 31 + 22 32 #define NVMET_TCP_RECV_BUDGET 8 23 33 #define NVMET_TCP_SEND_BUDGET 8 24 34 #define NVMET_TCP_IO_WORK_BUDGET 64 ··· 632 622 return 1; 633 623 } 634 624 635 - static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd) 625 + static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) 636 626 { 637 627 struct nvmet_tcp_queue *queue = cmd->queue; 638 628 struct msghdr msg = { .msg_flags = MSG_DONTWAIT }; ··· 641 631 .iov_len = NVME_TCP_DIGEST_LENGTH - cmd->offset 642 632 }; 643 633 int ret; 634 + 635 + if (!last_in_batch && cmd->queue->send_list_len) 636 + msg.msg_flags |= MSG_MORE; 644 637 645 638 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len); 646 639 if (unlikely(ret <= 0)) ··· 685 672 } 686 673 687 674 if (cmd->state == NVMET_TCP_SEND_DDGST) { 688 - ret = nvmet_try_send_ddgst(cmd); 675 + ret = nvmet_try_send_ddgst(cmd, last_in_batch); 689 676 if (ret <= 0) 690 677 goto done_send; 691 678 } ··· 807 794 icresp->hdr.pdo = 0; 808 795 icresp->hdr.plen = cpu_to_le32(icresp->hdr.hlen); 809 796 icresp->pfv = cpu_to_le16(NVME_TCP_PFV_1_0); 810 - icresp->maxdata = cpu_to_le32(0xffff); /* FIXME: support r2t */ 797 + icresp->maxdata = cpu_to_le32(0x400000); /* 16M arbitrary limit */ 811 798 icresp->cpda = 0; 812 799 if (queue->hdr_digest) 813 800 icresp->digest |= NVME_TCP_HDR_DIGEST_ENABLE; ··· 1452 1439 if (ret) 1453 1440 return ret; 1454 1441 1442 + if (so_priority > 0) { 1443 + ret = kernel_setsockopt(sock, SOL_SOCKET, SO_PRIORITY, 1444 + (char *)&so_priority, sizeof(so_priority)); 1445 + if (ret) 1446 + return ret; 1447 + } 1448 + 1455 1449 /* Set socket type of service */ 1456 1450 if (inet->rcv_tos > 0) { 1457 1451 int tos = inet->rcv_tos; ··· 1646 1626 if (ret) { 1647 1627 pr_err("failed to set SO_REUSEADDR sock opt %d\n", ret); 1648 1628 goto err_sock; 1629 + } 1630 + 1631 + if (so_priority > 0) { 1632 + ret = kernel_setsockopt(port->sock, SOL_SOCKET, SO_PRIORITY, 1633 + (char *)&so_priority, sizeof(so_priority)); 1634 + if (ret) { 1635 + pr_err("failed to set SO_PRIORITY sock opt %d\n", ret); 1636 + goto err_sock; 1637 + } 1649 1638 } 1650 1639 1651 1640 ret = kernel_bind(port->sock, (struct sockaddr *)&port->addr,
+4
include/linux/blkdev.h
··· 952 952 } 953 953 954 954 #ifdef CONFIG_BLK_DEV_ZONED 955 + 956 + /* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */ 957 + const char *blk_zone_cond_str(enum blk_zone_cond zone_cond); 958 + 955 959 static inline unsigned int blk_rq_zone_no(struct request *rq) 956 960 { 957 961 return blk_queue_zone_no(rq->q, blk_rq_pos(rq));
+5 -13
include/uapi/linux/fdreg.h
··· 7 7 * Handbook", Sanches and Canton. 8 8 */ 9 9 10 - #ifdef FDPATCHES 11 - #define FD_IOPORT fdc_state[fdc].address 12 - #else 13 - /* It would be a lot saner just to force fdc_state[fdc].address to always 14 - be set ! FIXME */ 15 - #define FD_IOPORT 0x3f0 16 - #endif 17 - 18 10 /* Fd controller regs. S&C, about page 340 */ 19 - #define FD_STATUS (4 + FD_IOPORT ) 20 - #define FD_DATA (5 + FD_IOPORT ) 11 + #define FD_STATUS 4 12 + #define FD_DATA 5 21 13 22 14 /* Digital Output Register */ 23 - #define FD_DOR (2 + FD_IOPORT ) 15 + #define FD_DOR 2 24 16 25 17 /* Digital Input Register (read) */ 26 - #define FD_DIR (7 + FD_IOPORT ) 18 + #define FD_DIR 7 27 19 28 20 /* Diskette Control Register (write)*/ 29 - #define FD_DCR (7 + FD_IOPORT ) 21 + #define FD_DCR 7 30 22 31 23 /* Bits of main status register */ 32 24 #define STATUS_BUSYMASK 0x0F /* drive busy mask */