History

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 ...

Linus Torvalds committed 6 years ago

Commit 15926142 parents 10f36b1 766c32939 files · +1774 −976Browse files

Unified · Split

39 files
  1. arch/arm/include/asm/floppy.h +13 −75
  2. block/blk-settings.c +3 −0
  3. block/blk-zoned.c +32 −0
  4. drivers/block/Makefile +6 −0
  5. drivers/block/aoe/aoeblk.c +2 −2
  6. drivers/block/drbd/drbd_main.c +0 −11
  7. drivers/block/floppy.c +568 −525
  8. drivers/block/loop.c +10 −8
  9. drivers/block/nbd.c +19 −8
  10. drivers/block/null_blk_main.c +9 −0
  11. drivers/block/null_blk_trace.c +21 −0
  12. drivers/block/null_blk_trace.h +79 −0
  13. drivers/block/null_blk_zoned.c +11 −1
  14. drivers/block/rsxx/dma.c +1 −1
  15. drivers/lightnvm/pblk-sysfs.c +21 −21
  16. drivers/md/bcache/btree.c +174 −68
  17. drivers/md/bcache/btree.h +84 −0
  18. drivers/md/bcache/sysfs.c +1 −1
  19. drivers/md/bcache/writeback.c +158 −6
  20. drivers/md/bcache/writeback.h +19 −0
  21. drivers/md/md.c +1 −1
  22. drivers/nvme/host/Kconfig +0 −2
  23. drivers/nvme/host/core.c +156 −99
  24. drivers/nvme/host/fabrics.c +4 −4
  25. drivers/nvme/host/fc.c +0 −3
  26. drivers/nvme/host/multipath.c +9 −12
  27. drivers/nvme/host/nvme.h +4 −2
  28. drivers/nvme/host/pci.c +28 −63
  29. drivers/nvme/host/rdma.c +6 −3
  30. drivers/nvme/host/tcp.c +96 −24
  31. drivers/nvme/target/admin-cmd.c +30 −4
  32. drivers/nvme/target/configfs.c +137 −9
  33. drivers/nvme/target/core.c +7 −2
  34. drivers/nvme/target/loop.c +0 −3
  35. drivers/nvme/target/nvmet.h +11 −0
  36. drivers/nvme/target/rdma.c +13 −2
  37. drivers/nvme/target/tcp.c +32 −3
  38. include/linux/blkdev.h +4 −0
  39. include/uapi/linux/fdreg.h +5 −13
arch/arm/include/asm/floppy.h+13−75
@@ -8,16 +8,18 @@ · 7 unmodified lines
88 */
99 #ifndef __ASM_ARM_FLOPPY_H
1010 #define __ASM_ARM_FLOPPY_H
11−#if 0
12−#include <mach/floppy.h>
13−#endif
1411
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)); \
2123 } while(0)
2224
2325 #define fd_inb(port) inb((port))
@@ -53,69 +55,7 @@ static inline int fd_dma_setup(void *data, unsigned int length, · 29 unmodified lines
5355 * to a non-zero track, and then restoring it to track 0. If an error occurs,
5456 * then there is no floppy drive present. [to be put back in again]
5557 */
56−static unsigned char floppy_selects[2][4] =
57−{
58− { 0x10, 0x21, 0x23, 0x33 },
59− { 0x10, 0x21, 0x23, 0x33 }
60−};
61−
62−#define fd_setdor(dor) \
63−do { \
64− int new_dor = (dor); \
65− if (new_dor & 0xf0) \
66− new_dor = (new_dor & 0x0c) | floppy_selects[fdc][new_dor & 3]; \
67− else \
68− new_dor &= 0x0c; \
69− outb(new_dor, FD_DOR); \
70−} while (0)
71−
72−/*
73− * Someday, we'll automatically detect which drives are present...
74− */
75−static inline void fd_scandrives (void)
76−{
77−#if 0
78− int floppy, drive_count;
79−
80− fd_disable_irq();
81− raw_cmd = &default_raw_cmd;
82− raw_cmd->flags = FD_RAW_SPIN | FD_RAW_NEED_SEEK;
83− raw_cmd->track = 0;
84− raw_cmd->rate = ?;
85− drive_count = 0;
86− for (floppy = 0; floppy < 4; floppy ++) {
87− current_drive = drive_count;
88− /*
89− * Turn on floppy motor
90− */
91− if (start_motor(redo_fd_request))
92− continue;
93− /*
94− * Set up FDC
95− */
96− fdc_specify();
97− /*
98− * Tell FDC to recalibrate
99− */
100− output_byte(FD_RECALIBRATE);
101− LAST_OUT(UNIT(floppy));
102− /* wait for command to complete */
103− if (!successful) {
104− int i;
105− for (i = drive_count; i < 3; i--)
106− floppy_selects[fdc][i] = floppy_selects[fdc][i + 1];
107− floppy_selects[fdc][3] = 0;
108− floppy -= 1;
109− } else
110− drive_count++;
111− }
112−#else
113− floppy_selects[0][0] = 0x10;
114− floppy_selects[0][1] = 0x21;
115− floppy_selects[0][2] = 0x23;
116− floppy_selects[0][3] = 0x33;
117−#endif
118−}
58+static unsigned char floppy_selects[4] = { 0x10, 0x21, 0x23, 0x33 };
11959
12060 #define FDC1 (0x3f0)
12161
@@ -135,9 +75,7 @@ static inline void fd_scandrives (void) · 13 unmodified lines
13575 */
13676 static void driveswap(int *ints, int dummy, int dummy2)
13777 {
138− floppy_selects[0][0] ^= floppy_selects[0][1];
139− floppy_selects[0][1] ^= floppy_selects[0][0];
140− floppy_selects[0][0] ^= floppy_selects[0][1];
78+ swap(floppy_selects[0], floppy_selects[1]);
14179 }
14280
14381 #define EXTRA_FLOPPY_PARAMS ,{ "driveswap", &driveswap, NULL, 0, 0 }
block/blk-settings.c+3−0
@@ -628,6 +628,9 @@ void disk_stack_limits(struct gendisk *disk, struct block_device *bdev, · 627 unmodified lines
628628 printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n",
629629 top, bottom);
630630 }
631+
632+ t->backing_dev_info->io_pages =
633+ t->limits.max_sectors >> (PAGE_SHIFT - 9);
631634 }
632635 EXPORT_SYMBOL(disk_stack_limits);
633636
block/blk-zoned.c+32−0
@@ -20,6 +20,38 @@ · 19 unmodified lines
2020
2121 #include "blk.h"
2222
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+
2355 static inline sector_t blk_zone_start(struct request_queue *q,
2456 sector_t sector)
2557 {
drivers/block/Makefile+6−0
@@ -6,6 +6,9 @@ · 5 unmodified lines
66 # Rewritten to use lists instead of if-statements.
77 #
88
9+# needed for trace events
10+ccflags-y += -I$(src)
11+
912 obj-$(CONFIG_MAC_FLOPPY) += swim3.o
1013 obj-$(CONFIG_BLK_DEV_SWIM) += swim_mod.o
1114 obj-$(CONFIG_BLK_DEV_FD) += floppy.o
@@ -39,6 +42,9 @@ obj-$(CONFIG_ZRAM) += zram/ · 27 unmodified lines
3942
4043 obj-$(CONFIG_BLK_DEV_NULL_BLK) += null_blk.o
4144 null_blk-objs := null_blk_main.o
45+ifeq ($(CONFIG_BLK_DEV_ZONED), y)
46+null_blk-$(CONFIG_TRACING) += null_blk_trace.o
47+endif
4248 null_blk-$(CONFIG_BLK_DEV_ZONED) += null_blk_zoned.o
4349
4450 skd-y := skd_main.o
drivers/block/aoe/aoeblk.c+2−2
@@ -87,9 +87,9 @@ static ssize_t aoedisk_show_netif(struct device *dev, · 86 unmodified lines
8787 if (*nd == NULL)
8888 return snprintf(page, PAGE_SIZE, "none\n");
8989 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",
9191 p == page ? "" : ",", (*nd)->name);
92− p += snprintf(p, PAGE_SIZE - (p-page), "\n");
92+ p += scnprintf(p, PAGE_SIZE - (p-page), "\n");
9393 return p-page;
9494 }
9595 /* firmware version */
drivers/block/drbd/drbd_main.c+0−11
@@ -3413,22 +3413,11 @@ int drbd_md_read(struct drbd_device *device, struct drbd_backing_dev *bdev) · 3412 unmodified lines
34133413 * the meta-data super block. This function sets MD_DIRTY, and starts a
34143414 * timer that ensures that within five seconds you have to call drbd_md_sync().
34153415 */
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
34263416 void drbd_md_mark_dirty(struct drbd_device *device)
34273417 {
34283418 if (!test_and_set_bit(MD_DIRTY, &device->flags))
34293419 mod_timer(&device->md_sync_timer, jiffies + 5*HZ);
34303420 }
3431−#endif
34323421
34333422 void drbd_uuid_move_history(struct drbd_device *device) __must_hold(local)
34343423 {
drivers/block/floppy.c+568−525
@@ -171,7 +171,6 @@ static int print_unex = 1; · 170 unmodified lines
171171 #include <linux/kernel.h>
172172 #include <linux/timer.h>
173173 #include <linux/workqueue.h>
174−#define FDPATCHES
175174 #include <linux/fdreg.h>
176175 #include <linux/fd.h>
177176 #include <linux/hdreg.h>
@@ -306,36 +305,26 @@ static bool initialized; · 128 unmodified lines
306305 /* reverse mapping from unit and fdc to drive */
307306 #define REVDRIVE(fdc, unit) ((unit) + ((fdc) << 2))
308307
309−#define DP (&drive_params[current_drive])
310−#define DRS (&drive_state[current_drive])
311−#define DRWE (&write_errors[current_drive])
312−#define FDCS (&fdc_state[fdc])
313−
314−#define UDP (&drive_params[drive])
315−#define UDRS (&drive_state[drive])
316−#define UDRWE (&write_errors[drive])
317−#define UFDCS (&fdc_state[FDC(drive)])
318−
319308 #define PH_HEAD(floppy, head) (((((floppy)->stretch & 2) >> 1) ^ head) << 2)
320309 #define STRETCH(floppy) ((floppy)->stretch & FD_STRETCH)
321310
322−/* read/write */
323−#define COMMAND (raw_cmd->cmd[0])
324−#define DR_SELECT (raw_cmd->cmd[1])
325−#define TRACK (raw_cmd->cmd[2])
326−#define HEAD (raw_cmd->cmd[3])
327−#define SECTOR (raw_cmd->cmd[4])
328−#define SIZECODE (raw_cmd->cmd[5])
329−#define SECT_PER_TRACK (raw_cmd->cmd[6])
330−#define GAP (raw_cmd->cmd[7])
331−#define SIZECODE2 (raw_cmd->cmd[8])
311+/* read/write commands */
312+#define COMMAND 0
313+#define DR_SELECT 1
314+#define TRACK 2
315+#define HEAD 3
316+#define SECTOR 4
317+#define SIZECODE 5
318+#define SECT_PER_TRACK 6
319+#define GAP 7
320+#define SIZECODE2 8
332321 #define NR_RW 9
333322
334−/* format */
335−#define F_SIZECODE (raw_cmd->cmd[2])
336−#define F_SECT_PER_TRACK (raw_cmd->cmd[3])
337−#define F_GAP (raw_cmd->cmd[4])
338−#define F_FILL (raw_cmd->cmd[5])
323+/* format commands */
324+#define F_SIZECODE 2
325+#define F_SECT_PER_TRACK 3
326+#define F_GAP 4
327+#define F_FILL 5
339328 #define NR_F 6
340329
341330 /*
@@ -351,14 +340,14 @@ static bool initialized; · 9 unmodified lines
351340 #define MAX_REPLIES 16
352341 static unsigned char reply_buffer[MAX_REPLIES];
353342 static int inr; /* size of reply buffer, when called from interrupt */
354−#define ST0 (reply_buffer[0])
355−#define ST1 (reply_buffer[1])
356−#define ST2 (reply_buffer[2])
357−#define ST3 (reply_buffer[0]) /* result of GETSTATUS */
358−#define R_TRACK (reply_buffer[3])
359−#define R_HEAD (reply_buffer[4])
360−#define R_SECTOR (reply_buffer[5])
361−#define R_SIZECODE (reply_buffer[6])
343+#define ST0 0
344+#define ST1 1
345+#define ST2 2
346+#define ST3 0 /* result of GETSTATUS */
347+#define R_TRACK 3
348+#define R_HEAD 4
349+#define R_SECTOR 5
350+#define R_SIZECODE 6
362351
363352 #define SEL_DLY (2 * HZ / 100)
364353
@@ -593,7 +582,7 @@ static int buffer_max = -1; · 228 unmodified lines
593582
594583 /* fdc related variables, should end up in a struct */
595584 static struct floppy_fdc_state fdc_state[N_FDC];
596−static int fdc; /* current fdc */
585+static int current_fdc; /* current fdc */
597586
598587 static struct workqueue_struct *floppy_wq;
599588
@@ -604,9 +593,19 @@ static unsigned char fsector_t; /* sector in track */ · 4 unmodified lines
604593 static unsigned char in_sector_offset; /* offset within physical sector,
605594 * expressed in units of 512 bytes */
606595
596+static inline unsigned char fdc_inb(int fdc, int reg)
597+{
598+ return fd_inb(fdc_state[fdc].address + reg);
599+}
600+
601+static inline void fdc_outb(unsigned char value, int fdc, int reg)
602+{
603+ fd_outb(value, fdc_state[fdc].address + reg);
604+}
605+
607606 static inline bool drive_no_geom(int drive)
608607 {
609− return !current_type[drive] && !ITYPE(UDRS->fd_device);
608+ return !current_type[drive] && !ITYPE(drive_state[drive].fd_device);
610609 }
611610
612611 #ifndef fd_eject
@@ -630,7 +629,7 @@ static inline void set_debugt(void) · 17 unmodified lines
630629
631630 static inline void debugt(const char *func, const char *msg)
632631 {
633− if (DP->flags & DEBUGT)
632+ if (drive_params[current_drive].flags & DEBUGT)
634633 pr_info("%s:%s dtime=%lu\n", func, msg, jiffies - debugtimer);
635634 }
636635 #else
@@ -683,10 +682,10 @@ static void __reschedule_timeout(int drive, const char *message) · 46 unmodified lines
683682 delay = 20UL * HZ;
684683 drive = 0;
685684 } else
686− delay = UDP->timeout;
685+ delay = drive_params[drive].timeout;
687686
688687 mod_delayed_work(floppy_wq, &fd_timeout, delay);
689− if (UDP->flags & FD_DEBUG)
688+ if (drive_params[drive].flags & FD_DEBUG)
690689 DPRINT("reschedule timeout %s\n", message);
691690 timeout_message = message;
692691 }
@@ -740,33 +739,37 @@ static int disk_change(int drive) · 47 unmodified lines
740739 {
741740 int fdc = FDC(drive);
742741
743− if (time_before(jiffies, UDRS->select_date + UDP->select_delay))
742+ if (time_before(jiffies, drive_state[drive].select_date + drive_params[drive].select_delay))
744743 DPRINT("WARNING disk change called early\n");
745− if (!(FDCS->dor & (0x10 << UNIT(drive))) ||
746− (FDCS->dor & 3) != UNIT(drive) || fdc != FDC(drive)) {
744+ if (!(fdc_state[fdc].dor & (0x10 << UNIT(drive))) ||
745+ (fdc_state[fdc].dor & 3) != UNIT(drive) || fdc != FDC(drive)) {
747746 DPRINT("probing disk change on unselected drive\n");
748747 DPRINT("drive=%d fdc=%d dor=%x\n", drive, FDC(drive),
749− (unsigned int)FDCS->dor);
748+ (unsigned int)fdc_state[fdc].dor);
750749 }
751750
752− debug_dcl(UDP->flags,
751+ debug_dcl(drive_params[drive].flags,
753752 "checking disk change line for drive %d\n", drive);
754− debug_dcl(UDP->flags, "jiffies=%lu\n", jiffies);
755− debug_dcl(UDP->flags, "disk change line=%x\n", fd_inb(FD_DIR) & 0x80);
756− debug_dcl(UDP->flags, "flags=%lx\n", UDRS->flags);
757−
758− if (UDP->flags & FD_BROKEN_DCL)
759− return test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
760− if ((fd_inb(FD_DIR) ^ UDP->flags) & 0x80) {
761− set_bit(FD_VERIFY_BIT, &UDRS->flags);
753+ debug_dcl(drive_params[drive].flags, "jiffies=%lu\n", jiffies);
754+ debug_dcl(drive_params[drive].flags, "disk change line=%x\n",
755+ fdc_inb(fdc, FD_DIR) & 0x80);
756+ debug_dcl(drive_params[drive].flags, "flags=%lx\n",
757+ drive_state[drive].flags);
758+
759+ if (drive_params[drive].flags & FD_BROKEN_DCL)
760+ return test_bit(FD_DISK_CHANGED_BIT,
761+ &drive_state[drive].flags);
762+ if ((fdc_inb(fdc, FD_DIR) ^ drive_params[drive].flags) & 0x80) {
763+ set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
762764 /* verify write protection */
763765
764− if (UDRS->maxblock) /* mark it changed */
765− set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
766+ if (drive_state[drive].maxblock) /* mark it changed */
767+ set_bit(FD_DISK_CHANGED_BIT,
768+ &drive_state[drive].flags);
766769
767770 /* invalidate its geometry */
768− if (UDRS->keep_data >= 0) {
769− if ((UDP->flags & FTD_MSG) &&
771+ if (drive_state[drive].keep_data >= 0) {
772+ if ((drive_params[drive].flags & FTD_MSG) &&
770773 current_type[drive] != NULL)
771774 DPRINT("Disk type is undefined after disk change\n");
772775 current_type[drive] = NULL;
@@ -775,8 +778,8 @@ static int disk_change(int drive) · 2 unmodified lines
775778
776779 return 1;
777780 } else {
778− UDRS->last_checked = jiffies;
779− clear_bit(FD_DISK_NEWCHANGE_BIT, &UDRS->flags);
781+ drive_state[drive].last_checked = jiffies;
782+ clear_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[drive].flags);
780783 }
781784 return 0;
782785 }
@@ -799,26 +802,26 @@ static int set_dor(int fdc, char mask, char data) · 16 unmodified lines
799802 unsigned char newdor;
800803 unsigned char olddor;
801804
802− if (FDCS->address == -1)
805+ if (fdc_state[fdc].address == -1)
803806 return -1;
804807
805− olddor = FDCS->dor;
808+ olddor = fdc_state[fdc].dor;
806809 newdor = (olddor & mask) | data;
807810 if (newdor != olddor) {
808811 unit = olddor & 0x3;
809812 if (is_selected(olddor, unit) && !is_selected(newdor, unit)) {
810813 drive = REVDRIVE(fdc, unit);
811− debug_dcl(UDP->flags,
814+ debug_dcl(drive_params[drive].flags,
812815 "calling disk change from set_dor\n");
813816 disk_change(drive);
814817 }
815− FDCS->dor = newdor;
816− fd_outb(newdor, FD_DOR);
818+ fdc_state[fdc].dor = newdor;
819+ fdc_outb(newdor, fdc, FD_DOR);
817820
818821 unit = newdor & 0x3;
819822 if (!is_selected(olddor, unit) && is_selected(newdor, unit)) {
820823 drive = REVDRIVE(fdc, unit);
821− UDRS->select_date = jiffies;
824+ drive_state[drive].select_date = jiffies;
822825 }
823826 }
824827 return olddor;
@@ -826,11 +829,12 @@ static int set_dor(int fdc, char mask, char data) · 1 unmodified line
826829
827830 static void twaddle(void)
828831 {
829− if (DP->select_delay)
832+ if (drive_params[current_drive].select_delay)
830833 return;
831− fd_outb(FDCS->dor & ~(0x10 << UNIT(current_drive)), FD_DOR);
832− fd_outb(FDCS->dor, FD_DOR);
833− DRS->select_date = jiffies;
834+ fdc_outb(fdc_state[current_fdc].dor & ~(0x10 << UNIT(current_drive)),
835+ current_fdc, FD_DOR);
836+ fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR);
837+ drive_state[current_drive].select_date = jiffies;
834838 }
835839
836840 /*
@@ -841,19 +845,20 @@ static void reset_fdc_info(int mode) · 4 unmodified lines
841845 {
842846 int drive;
843847
844− FDCS->spec1 = FDCS->spec2 = -1;
845− FDCS->need_configure = 1;
846− FDCS->perp_mode = 1;
847− FDCS->rawcmd = 0;
848+ fdc_state[current_fdc].spec1 = fdc_state[current_fdc].spec2 = -1;
849+ fdc_state[current_fdc].need_configure = 1;
850+ fdc_state[current_fdc].perp_mode = 1;
851+ fdc_state[current_fdc].rawcmd = 0;
848852 for (drive = 0; drive < N_DRIVE; drive++)
849− if (FDC(drive) == fdc && (mode || UDRS->track != NEED_1_RECAL))
850− UDRS->track = NEED_2_RECAL;
853+ if (FDC(drive) == current_fdc &&
854+ (mode || drive_state[drive].track != NEED_1_RECAL))
855+ drive_state[drive].track = NEED_2_RECAL;
851856 }
852857
853858 /* selects the fdc and drive, and enables the fdc's input/dma. */
854859 static void set_fdc(int drive)
855860 {
856− unsigned int new_fdc = fdc;
861+ unsigned int new_fdc = current_fdc;
857862
858863 if (drive >= 0 && drive < N_DRIVE) {
859864 new_fdc = FDC(drive);
@@ -863,15 +868,15 @@ static void set_fdc(int drive) · 3 unmodified lines
863868 pr_info("bad fdc value\n");
864869 return;
865870 }
866− fdc = new_fdc;
867− set_dor(fdc, ~0, 8);
871+ current_fdc = new_fdc;
872+ set_dor(current_fdc, ~0, 8);
868873 #if N_FDC > 1
869− set_dor(1 - fdc, ~8, 0);
874+ set_dor(1 - current_fdc, ~8, 0);
870875 #endif
871− if (FDCS->rawcmd == 2)
876+ if (fdc_state[current_fdc].rawcmd == 2)
872877 reset_fdc_info(1);
873− if (fd_inb(FD_STATUS) != STATUS_READY)
874− FDCS->reset = 1;
878+ if (fdc_inb(current_fdc, FD_STATUS) != STATUS_READY)
879+ fdc_state[current_fdc].reset = 1;
875880 }
876881
877882 /* locks the driver */
@@ -924,19 +929,19 @@ static void floppy_off(unsigned int drive) · 46 unmodified lines
924929 unsigned long volatile delta;
925930 int fdc = FDC(drive);
926931
927− if (!(FDCS->dor & (0x10 << UNIT(drive))))
932+ if (!(fdc_state[fdc].dor & (0x10 << UNIT(drive))))
928933 return;
929934
930935 del_timer(motor_off_timer + drive);
931936
932937 /* make spindle stop in a position which minimizes spinup time
933938 * next time */
934− if (UDP->rps) {
935− delta = jiffies - UDRS->first_read_date + HZ -
936− UDP->spindown_offset;
937− delta = ((delta * UDP->rps) % HZ) / UDP->rps;
939+ if (drive_params[drive].rps) {
940+ delta = jiffies - drive_state[drive].first_read_date + HZ -
941+ drive_params[drive].spindown_offset;
942+ delta = ((delta * drive_params[drive].rps) % HZ) / drive_params[drive].rps;
938943 motor_off_timer[drive].expires =
939− jiffies + UDP->spindown - delta;
944+ jiffies + drive_params[drive].spindown - delta;
940945 }
941946 add_timer(motor_off_timer + drive);
942947 }
@@ -952,20 +957,20 @@ static void scandrives(void) · 9 unmodified lines
952957 int drive;
953958 int saved_drive;
954959
955− if (DP->select_delay)
960+ if (drive_params[current_drive].select_delay)
956961 return;
957962
958963 saved_drive = current_drive;
959964 for (i = 0; i < N_DRIVE; i++) {
960965 drive = (saved_drive + i + 1) % N_DRIVE;
961− if (UDRS->fd_ref == 0 || UDP->select_delay != 0)
966+ if (drive_state[drive].fd_ref == 0 || drive_params[drive].select_delay != 0)
962967 continue; /* skip closed drives */
963968 set_fdc(drive);
964− if (!(set_dor(fdc, ~3, UNIT(drive) | (0x10 << UNIT(drive))) &
969+ if (!(set_dor(current_fdc, ~3, UNIT(drive) | (0x10 << UNIT(drive))) &
965970 (0x10 << UNIT(drive))))
966971 /* switch the motor off again, if it was off to
967972 * begin with */
968− set_dor(fdc, ~(0x10 << UNIT(drive)), 0);
973+ set_dor(current_fdc, ~(0x10 << UNIT(drive)), 0);
969974 }
970975 set_fdc(saved_drive);
971976 }
@@ -1011,7 +1016,8 @@ static void cancel_activity(void) · 39 unmodified lines
10111016 * transfer */
10121017 static void fd_watchdog(void)
10131018 {
1014− debug_dcl(DP->flags, "calling disk change from watchdog\n");
1019+ debug_dcl(drive_params[current_drive].flags,
1020+ "calling disk change from watchdog\n");
10151021
10161022 if (disk_change(current_drive)) {
10171023 DPRINT("disk removed during i/o\n");
@@ -1035,7 +1041,7 @@ static void main_command_interrupt(void) · 17 unmodified lines
10351041 static int fd_wait_for_completion(unsigned long expires,
10361042 void (*function)(void))
10371043 {
1038− if (FDCS->reset) {
1044+ if (fdc_state[current_fdc].reset) {
10391045 reset_fdc(); /* do the reset during sleep to win time
10401046 * if we don't need to sleep, it's a good
10411047 * occasion anyways */
@@ -1063,13 +1069,13 @@ static void setup_DMA(void) · 21 unmodified lines
10631069 pr_cont("%x,", raw_cmd->cmd[i]);
10641070 pr_cont("\n");
10651071 cont->done(0);
1066− FDCS->reset = 1;
1072+ fdc_state[current_fdc].reset = 1;
10671073 return;
10681074 }
10691075 if (((unsigned long)raw_cmd->kernel_data) % 512) {
10701076 pr_info("non aligned address: %p\n", raw_cmd->kernel_data);
10711077 cont->done(0);
1072− FDCS->reset = 1;
1078+ fdc_state[current_fdc].reset = 1;
10731079 return;
10741080 }
10751081 f = claim_dma_lock();
@@ -1077,10 +1083,11 @@ static void setup_DMA(void) · 1 unmodified line
10771083 #ifdef fd_dma_setup
10781084 if (fd_dma_setup(raw_cmd->kernel_data, raw_cmd->length,
10791085 (raw_cmd->flags & FD_RAW_READ) ?
1080− DMA_MODE_READ : DMA_MODE_WRITE, FDCS->address) < 0) {
1086+ DMA_MODE_READ : DMA_MODE_WRITE,
1087+ fdc_state[current_fdc].address) < 0) {
10811088 release_dma_lock(f);
10821089 cont->done(0);
1083− FDCS->reset = 1;
1090+ fdc_state[current_fdc].reset = 1;
10841091 return;
10851092 }
10861093 release_dma_lock(f);
@@ -1091,7 +1098,7 @@ static void setup_DMA(void) · 4 unmodified lines
10911098 DMA_MODE_READ : DMA_MODE_WRITE);
10921099 fd_set_dma_addr(raw_cmd->kernel_data);
10931100 fd_set_dma_count(raw_cmd->length);
1094− virtual_dma_port = FDCS->address;
1101+ virtual_dma_port = fdc_state[current_fdc].address;
10951102 fd_enable_dma();
10961103 release_dma_lock(f);
10971104 #endif
@@ -1105,18 +1112,18 @@ static int wait_til_ready(void) · 7 unmodified lines
11051112 int status;
11061113 int counter;
11071114
1108− if (FDCS->reset)
1115+ if (fdc_state[current_fdc].reset)
11091116 return -1;
11101117 for (counter = 0; counter < 10000; counter++) {
1111− status = fd_inb(FD_STATUS);
1118+ status = fdc_inb(current_fdc, FD_STATUS);
11121119 if (status & STATUS_READY)
11131120 return status;
11141121 }
11151122 if (initialized) {
1116− DPRINT("Getstatus times out (%x) on fdc %d\n", status, fdc);
1123+ DPRINT("Getstatus times out (%x) on fdc %d\n", status, current_fdc);
11171124 show_floppy();
11181125 }
1119− FDCS->reset = 1;
1126+ fdc_state[current_fdc].reset = 1;
11201127 return -1;
11211128 }
11221129
@@ -1129,17 +1136,17 @@ static int output_byte(char byte) · 6 unmodified lines
11291136 return -1;
11301137
11311138 if (is_ready_state(status)) {
1132− fd_outb(byte, FD_DATA);
1139+ fdc_outb(byte, current_fdc, FD_DATA);
11331140 output_log[output_log_pos].data = byte;
11341141 output_log[output_log_pos].status = status;
11351142 output_log[output_log_pos].jiffies = jiffies;
11361143 output_log_pos = (output_log_pos + 1) % OLOGSIZE;
11371144 return 0;
11381145 }
1139− FDCS->reset = 1;
1146+ fdc_state[current_fdc].reset = 1;
11401147 if (initialized) {
11411148 DPRINT("Unable to send byte %x to FDC. Fdc=%x Status=%x\n",
1142− byte, fdc, status);
1149+ byte, current_fdc, status);
11431150 show_floppy();
11441151 }
11451152 return -1;
@@ -1162,16 +1169,16 @@ static int result(void) · 16 unmodified lines
11621169 return i;
11631170 }
11641171 if (status == (STATUS_DIR | STATUS_READY | STATUS_BUSY))
1165− reply_buffer[i] = fd_inb(FD_DATA);
1172+ reply_buffer[i] = fdc_inb(current_fdc, FD_DATA);
11661173 else
11671174 break;
11681175 }
11691176 if (initialized) {
11701177 DPRINT("get result error. Fdc=%d Last status=%x Read bytes=%d\n",
1171− fdc, status, i);
1178+ current_fdc, status, i);
11721179 show_floppy();
11731180 }
1174− FDCS->reset = 1;
1181+ fdc_state[current_fdc].reset = 1;
11751182 return -1;
11761183 }
11771184
@@ -1208,7 +1215,7 @@ static void perpendicular_mode(void) · 30 unmodified lines
12081215 default:
12091216 DPRINT("Invalid data rate for perpendicular mode!\n");
12101217 cont->done(0);
1211− FDCS->reset = 1;
1218+ fdc_state[current_fdc].reset = 1;
12121219 /*
12131220 * convenient way to return to
12141221 * redo without too much hassle
@@ -1219,12 +1226,12 @@ static void perpendicular_mode(void) · 4 unmodified lines
12191226 } else
12201227 perp_mode = 0;
12211228
1222− if (FDCS->perp_mode == perp_mode)
1229+ if (fdc_state[current_fdc].perp_mode == perp_mode)
12231230 return;
1224− if (FDCS->version >= FDC_82077_ORIG) {
1231+ if (fdc_state[current_fdc].version >= FDC_82077_ORIG) {
12251232 output_byte(FD_PERPENDICULAR);
12261233 output_byte(perp_mode);
1227− FDCS->perp_mode = perp_mode;
1234+ fdc_state[current_fdc].perp_mode = perp_mode;
12281235 } else if (perp_mode) {
12291236 DPRINT("perpendicular mode not supported by this FDC.\n");
12301237 }
@@ -1279,9 +1286,10 @@ static void fdc_specify(void) · 48 unmodified lines
12791286 int hlt_max_code = 0x7f;
12801287 int hut_max_code = 0xf;
12811288
1282− if (FDCS->need_configure && FDCS->version >= FDC_82072A) {
1289+ if (fdc_state[current_fdc].need_configure &&
1290+ fdc_state[current_fdc].version >= FDC_82072A) {
12831291 fdc_configure();
1284− FDCS->need_configure = 0;
1292+ fdc_state[current_fdc].need_configure = 0;
12851293 }
12861294
12871295 switch (raw_cmd->rate & 0x03) {
@@ -1290,7 +1298,7 @@ static void fdc_specify(void) · 2 unmodified lines
12901298 break;
12911299 case 1:
12921300 dtr = 300;
1293− if (FDCS->version >= FDC_82078) {
1301+ if (fdc_state[current_fdc].version >= FDC_82078) {
12941302 /* chose the default rate table, not the one
12951303 * where 1 = 2 Mbps */
12961304 output_byte(FD_DRIVESPEC);
@@ -1305,27 +1313,30 @@ static void fdc_specify(void) · 8 unmodified lines
13051313 break;
13061314 }
13071315
1308− if (FDCS->version >= FDC_82072) {
1316+ if (fdc_state[current_fdc].version >= FDC_82072) {
13091317 scale_dtr = dtr;
13101318 hlt_max_code = 0x00; /* 0==256msec*dtr0/dtr (not linear!) */
13111319 hut_max_code = 0x0; /* 0==256msec*dtr0/dtr (not linear!) */
13121320 }
13131321
13141322 /* Convert step rate from microseconds to milliseconds and 4 bits */
1315− srt = 16 - DIV_ROUND_UP(DP->srt * scale_dtr / 1000, NOMINAL_DTR);
1323+ srt = 16 - DIV_ROUND_UP(drive_params[current_drive].srt * scale_dtr / 1000,
1324+ NOMINAL_DTR);
13161325 if (slow_floppy)
13171326 srt = srt / 4;
13181327
13191328 SUPBOUND(srt, 0xf);
13201329 INFBOUND(srt, 0);
13211330
1322− hlt = DIV_ROUND_UP(DP->hlt * scale_dtr / 2, NOMINAL_DTR);
1331+ hlt = DIV_ROUND_UP(drive_params[current_drive].hlt * scale_dtr / 2,
1332+ NOMINAL_DTR);
13231333 if (hlt < 0x01)
13241334 hlt = 0x01;
13251335 else if (hlt > 0x7f)
13261336 hlt = hlt_max_code;
13271337
1328− hut = DIV_ROUND_UP(DP->hut * scale_dtr / 16, NOMINAL_DTR);
1338+ hut = DIV_ROUND_UP(drive_params[current_drive].hut * scale_dtr / 16,
1339+ NOMINAL_DTR);
13291340 if (hut < 0x1)
13301341 hut = 0x1;
13311342 else if (hut > 0xf)
@@ -1335,11 +1346,12 @@ static void fdc_specify(void) · 3 unmodified lines
13351346 spec2 = (hlt << 1) | (use_virtual_dma & 1);
13361347
13371348 /* If these parameters did not change, just return with success */
1338− if (FDCS->spec1 != spec1 || FDCS->spec2 != spec2) {
1349+ if (fdc_state[current_fdc].spec1 != spec1 ||
1350+ fdc_state[current_fdc].spec2 != spec2) {
13391351 /* Go ahead and set spec1 and spec2 */
13401352 output_byte(FD_SPECIFY);
1341− output_byte(FDCS->spec1 = spec1);
1342− output_byte(FDCS->spec2 = spec2);
1353+ output_byte(fdc_state[current_fdc].spec1 = spec1);
1354+ output_byte(fdc_state[current_fdc].spec2 = spec2);
13431355 }
13441356 } /* fdc_specify */
13451357
@@ -1350,52 +1362,55 @@ static void fdc_specify(void) · 4 unmodified lines
13501362 static int fdc_dtr(void)
13511363 {
13521364 /* If data rate not already set to desired value, set it. */
1353− if ((raw_cmd->rate & 3) == FDCS->dtr)
1365+ if ((raw_cmd->rate & 3) == fdc_state[current_fdc].dtr)
13541366 return 0;
13551367
13561368 /* Set dtr */
1357− fd_outb(raw_cmd->rate & 3, FD_DCR);
1369+ fdc_outb(raw_cmd->rate & 3, current_fdc, FD_DCR);
13581370
13591371 /* TODO: some FDC/drive combinations (C&T 82C711 with TEAC 1.2MB)
13601372 * need a stabilization period of several milliseconds to be
13611373 * enforced after data rate changes before R/W operations.
13621374 * Pause 5 msec to avoid trouble. (Needs to be 2 jiffies)
13631375 */
1364− FDCS->dtr = raw_cmd->rate & 3;
1376+ fdc_state[current_fdc].dtr = raw_cmd->rate & 3;
13651377 return fd_wait_for_completion(jiffies + 2UL * HZ / 100, floppy_ready);
13661378 } /* fdc_dtr */
13671379
13681380 static void tell_sector(void)
13691381 {
13701382 pr_cont(": track %d, head %d, sector %d, size %d",
1371− R_TRACK, R_HEAD, R_SECTOR, R_SIZECODE);
1383+ reply_buffer[R_TRACK], reply_buffer[R_HEAD],
1384+ reply_buffer[R_SECTOR],
1385+ reply_buffer[R_SIZECODE]);
13721386 } /* tell_sector */
13731387
13741388 static void print_errors(void)
13751389 {
13761390 DPRINT("");
1377− if (ST0 & ST0_ECE) {
1391+ if (reply_buffer[ST0] & ST0_ECE) {
13781392 pr_cont("Recalibrate failed!");
1379− } else if (ST2 & ST2_CRC) {
1393+ } else if (reply_buffer[ST2] & ST2_CRC) {
13801394 pr_cont("data CRC error");
13811395 tell_sector();
1382− } else if (ST1 & ST1_CRC) {
1396+ } else if (reply_buffer[ST1] & ST1_CRC) {
13831397 pr_cont("CRC error");
13841398 tell_sector();
1385− } else if ((ST1 & (ST1_MAM | ST1_ND)) ||
1386− (ST2 & ST2_MAM)) {
1399+ } else if ((reply_buffer[ST1] & (ST1_MAM | ST1_ND)) ||
1400+ (reply_buffer[ST2] & ST2_MAM)) {
13871401 if (!probing) {
13881402 pr_cont("sector not found");
13891403 tell_sector();
13901404 } else
13911405 pr_cont("probe failed...");
1392− } else if (ST2 & ST2_WC) { /* seek error */
1406+ } else if (reply_buffer[ST2] & ST2_WC) { /* seek error */
13931407 pr_cont("wrong cylinder");
1394− } else if (ST2 & ST2_BC) { /* cylinder marked as bad */
1408+ } else if (reply_buffer[ST2] & ST2_BC) { /* cylinder marked as bad */
13951409 pr_cont("bad cylinder");
13961410 } else {
13971411 pr_cont("unknown error. ST[0..2] are: 0x%x 0x%x 0x%x",
1398− ST0, ST1, ST2);
1412+ reply_buffer[ST0], reply_buffer[ST1],
1413+ reply_buffer[ST2]);
13991414 tell_sector();
14001415 }
14011416 pr_cont("\n");
@@ -1414,33 +1429,35 @@ static int interpret_errors(void) · 12 unmodified lines
14141429
14151430 if (inr != 7) {
14161431 DPRINT("-- FDC reply error\n");
1417− FDCS->reset = 1;
1432+ fdc_state[current_fdc].reset = 1;
14181433 return 1;
14191434 }
14201435
14211436 /* check IC to find cause of interrupt */
1422− switch (ST0 & ST0_INTR) {
1437+ switch (reply_buffer[ST0] & ST0_INTR) {
14231438 case 0x40: /* error occurred during command execution */
1424− if (ST1 & ST1_EOC)
1439+ if (reply_buffer[ST1] & ST1_EOC)
14251440 return 0; /* occurs with pseudo-DMA */
14261441 bad = 1;
1427− if (ST1 & ST1_WP) {
1442+ if (reply_buffer[ST1] & ST1_WP) {
14281443 DPRINT("Drive is write protected\n");
1429− clear_bit(FD_DISK_WRITABLE_BIT, &DRS->flags);
1444+ clear_bit(FD_DISK_WRITABLE_BIT,
1445+ &drive_state[current_drive].flags);
14301446 cont->done(0);
14311447 bad = 2;
1432− } else if (ST1 & ST1_ND) {
1433− set_bit(FD_NEED_TWADDLE_BIT, &DRS->flags);
1434− } else if (ST1 & ST1_OR) {
1435− if (DP->flags & FTD_MSG)
1448+ } else if (reply_buffer[ST1] & ST1_ND) {
1449+ set_bit(FD_NEED_TWADDLE_BIT,
1450+ &drive_state[current_drive].flags);
1451+ } else if (reply_buffer[ST1] & ST1_OR) {
1452+ if (drive_params[current_drive].flags & FTD_MSG)
14361453 DPRINT("Over/Underrun - retrying\n");
14371454 bad = 0;
1438− } else if (*errors >= DP->max_errors.reporting) {
1455+ } else if (*errors >= drive_params[current_drive].max_errors.reporting) {
14391456 print_errors();
14401457 }
1441− if (ST2 & ST2_WC || ST2 & ST2_BC)
1458+ if (reply_buffer[ST2] & ST2_WC || reply_buffer[ST2] & ST2_BC)
14421459 /* wrong cylinder => recal */
1443− DRS->track = NEED_2_RECAL;
1460+ drive_state[current_drive].track = NEED_2_RECAL;
14441461 return bad;
14451462 case 0x80: /* invalid command given */
14461463 DPRINT("Invalid FDC command given!\n");
@@ -1473,13 +1490,13 @@ static void setup_rw_floppy(void) · 26 unmodified lines
14731490 flags |= FD_RAW_INTR;
14741491
14751492 if ((flags & FD_RAW_SPIN) && !(flags & FD_RAW_NO_MOTOR)) {
1476− ready_date = DRS->spinup_date + DP->spinup;
1493+ ready_date = drive_state[current_drive].spinup_date + drive_params[current_drive].spinup;
14771494 /* If spinup will take a long time, rerun scandrives
14781495 * again just before spinup completion. Beware that
14791496 * after scandrives, we must again wait for selection.
14801497 */
1481− if (time_after(ready_date, jiffies + DP->select_delay)) {
1482− ready_date -= DP->select_delay;
1498+ if (time_after(ready_date, jiffies + drive_params[current_drive].select_delay)) {
1499+ ready_date -= drive_params[current_drive].select_delay;
14831500 function = floppy_start;
14841501 } else
14851502 function = setup_rw_floppy;
@@ -1522,44 +1539,52 @@ static int blind_seek; · 36 unmodified lines
15221539 static void seek_interrupt(void)
15231540 {
15241541 debugt(__func__, "");
1525− if (inr != 2 || (ST0 & 0xF8) != 0x20) {
1542+ if (inr != 2 || (reply_buffer[ST0] & 0xF8) != 0x20) {
15261543 DPRINT("seek failed\n");
1527− DRS->track = NEED_2_RECAL;
1544+ drive_state[current_drive].track = NEED_2_RECAL;
15281545 cont->error();
15291546 cont->redo();
15301547 return;
15311548 }
1532− if (DRS->track >= 0 && DRS->track != ST1 && !blind_seek) {
1533− debug_dcl(DP->flags,
1549+ if (drive_state[current_drive].track >= 0 &&
1550+ drive_state[current_drive].track != reply_buffer[ST1] &&
1551+ !blind_seek) {
1552+ debug_dcl(drive_params[current_drive].flags,
15341553 "clearing NEWCHANGE flag because of effective seek\n");
1535− debug_dcl(DP->flags, "jiffies=%lu\n", jiffies);
1536− clear_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
1554+ debug_dcl(drive_params[current_drive].flags, "jiffies=%lu\n",
1555+ jiffies);
1556+ clear_bit(FD_DISK_NEWCHANGE_BIT,
1557+ &drive_state[current_drive].flags);
15371558 /* effective seek */
1538− DRS->select_date = jiffies;
1559+ drive_state[current_drive].select_date = jiffies;
15391560 }
1540− DRS->track = ST1;
1561+ drive_state[current_drive].track = reply_buffer[ST1];
15411562 floppy_ready();
15421563 }
15431564
15441565 static void check_wp(void)
15451566 {
1546− if (test_bit(FD_VERIFY_BIT, &DRS->flags)) {
1567+ if (test_bit(FD_VERIFY_BIT, &drive_state[current_drive].flags)) {
15471568 /* check write protection */
15481569 output_byte(FD_GETSTATUS);
15491570 output_byte(UNIT(current_drive));
15501571 if (result() != 1) {
1551− FDCS->reset = 1;
1572+ fdc_state[current_fdc].reset = 1;
15521573 return;
15531574 }
1554− clear_bit(FD_VERIFY_BIT, &DRS->flags);
1555− clear_bit(FD_NEED_TWADDLE_BIT, &DRS->flags);
1556− debug_dcl(DP->flags,
1575+ clear_bit(FD_VERIFY_BIT, &drive_state[current_drive].flags);
1576+ clear_bit(FD_NEED_TWADDLE_BIT,
1577+ &drive_state[current_drive].flags);
1578+ debug_dcl(drive_params[current_drive].flags,
15571579 "checking whether disk is write protected\n");
1558− debug_dcl(DP->flags, "wp=%x\n", ST3 & 0x40);
1559− if (!(ST3 & 0x40))
1560− set_bit(FD_DISK_WRITABLE_BIT, &DRS->flags);
1580+ debug_dcl(drive_params[current_drive].flags, "wp=%x\n",
1581+ reply_buffer[ST3] & 0x40);
1582+ if (!(reply_buffer[ST3] & 0x40))
1583+ set_bit(FD_DISK_WRITABLE_BIT,
1584+ &drive_state[current_drive].flags);
15611585 else
1562− clear_bit(FD_DISK_WRITABLE_BIT, &DRS->flags);
1586+ clear_bit(FD_DISK_WRITABLE_BIT,
1587+ &drive_state[current_drive].flags);
15631588 }
15641589 }
15651590
@@ -1569,32 +1594,34 @@ static void seek_floppy(void) · 3 unmodified lines
15691594
15701595 blind_seek = 0;
15711596
1572− debug_dcl(DP->flags, "calling disk change from %s\n", __func__);
1597+ debug_dcl(drive_params[current_drive].flags,
1598+ "calling disk change from %s\n", __func__);
15731599
1574− if (!test_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags) &&
1600+ if (!test_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags) &&
15751601 disk_change(current_drive) && (raw_cmd->flags & FD_RAW_NEED_DISK)) {
15761602 /* the media changed flag should be cleared after the seek.
15771603 * If it isn't, this means that there is really no disk in
15781604 * the drive.
15791605 */
1580− set_bit(FD_DISK_CHANGED_BIT, &DRS->flags);
1606+ set_bit(FD_DISK_CHANGED_BIT,
1607+ &drive_state[current_drive].flags);
15811608 cont->done(0);
15821609 cont->redo();
15831610 return;
15841611 }
1585− if (DRS->track <= NEED_1_RECAL) {
1612+ if (drive_state[current_drive].track <= NEED_1_RECAL) {
15861613 recalibrate_floppy();
15871614 return;
1588− } else if (test_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags) &&
1615+ } else if (test_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags) &&
15891616 (raw_cmd->flags & FD_RAW_NEED_DISK) &&
1590− (DRS->track <= NO_TRACK || DRS->track == raw_cmd->track)) {
1617+ (drive_state[current_drive].track <= NO_TRACK || drive_state[current_drive].track == raw_cmd->track)) {
15911618 /* we seek to clear the media-changed condition. Does anybody
15921619 * know a more elegant way, which works on all drives? */
15931620 if (raw_cmd->track)
15941621 track = raw_cmd->track - 1;
15951622 else {
1596− if (DP->flags & FD_SILENT_DCL_CLEAR) {
1597− set_dor(fdc, ~(0x10 << UNIT(current_drive)), 0);
1623+ if (drive_params[current_drive].flags & FD_SILENT_DCL_CLEAR) {
1624+ set_dor(current_fdc, ~(0x10 << UNIT(current_drive)), 0);
15981625 blind_seek = 1;
15991626 raw_cmd->flags |= FD_RAW_NEED_SEEK;
16001627 }
@@ -1602,7 +1629,7 @@ static void seek_floppy(void) · 1 unmodified line
16021629 }
16031630 } else {
16041631 check_wp();
1605− if (raw_cmd->track != DRS->track &&
1632+ if (raw_cmd->track != drive_state[current_drive].track &&
16061633 (raw_cmd->flags & FD_RAW_NEED_SEEK))
16071634 track = raw_cmd->track;
16081635 else {
@@ -1625,9 +1652,9 @@ static void recal_interrupt(void) · 16 unmodified lines
16251652 {
16261653 debugt(__func__, "");
16271654 if (inr != 2)
1628− FDCS->reset = 1;
1629− else if (ST0 & ST0_ECE) {
1630− switch (DRS->track) {
1655+ fdc_state[current_fdc].reset = 1;
1656+ else if (reply_buffer[ST0] & ST0_ECE) {
1657+ switch (drive_state[current_drive].track) {
16311658 case NEED_1_RECAL:
16321659 debugt(__func__, "need 1 recal");
16331660 /* after a second recalibrate, we still haven't
@@ -1645,11 +1672,12 @@ static void recal_interrupt(void) · 11 unmodified lines
16451672 * not to move at recalibration is to
16461673 * be already at track 0.) Clear the
16471674 * new change flag */
1648− debug_dcl(DP->flags,
1675+ debug_dcl(drive_params[current_drive].flags,
16491676 "clearing NEWCHANGE flag because of second recalibrate\n");
16501677
1651− clear_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
1652− DRS->select_date = jiffies;
1678+ clear_bit(FD_DISK_NEWCHANGE_BIT,
1679+ &drive_state[current_drive].flags);
1680+ drive_state[current_drive].select_date = jiffies;
16531681 /* fall through */
16541682 default:
16551683 debugt(__func__, "default");
@@ -1659,11 +1687,11 @@ static void recal_interrupt(void) · 3 unmodified lines
16591687 * track 0, this might mean that we
16601688 * started beyond track 80. Try
16611689 * again. */
1662− DRS->track = NEED_1_RECAL;
1690+ drive_state[current_drive].track = NEED_1_RECAL;
16631691 break;
16641692 }
16651693 } else
1666− DRS->track = ST1;
1694+ drive_state[current_drive].track = reply_buffer[ST1];
16671695 floppy_ready();
16681696 }
16691697
@@ -1693,20 +1721,20 @@ irqreturn_t floppy_interrupt(int irq, void *dev_id) · 23 unmodified lines
16931721 release_dma_lock(f);
16941722
16951723 do_floppy = NULL;
1696− if (fdc >= N_FDC || FDCS->address == -1) {
1724+ if (current_fdc >= N_FDC || fdc_state[current_fdc].address == -1) {
16971725 /* we don't even know which FDC is the culprit */
16981726 pr_info("DOR0=%x\n", fdc_state[0].dor);
1699− pr_info("floppy interrupt on bizarre fdc %d\n", fdc);
1727+ pr_info("floppy interrupt on bizarre fdc %d\n", current_fdc);
17001728 pr_info("handler=%ps\n", handler);
17011729 is_alive(__func__, "bizarre fdc");
17021730 return IRQ_NONE;
17031731 }
17041732
1705− FDCS->reset = 0;
1733+ fdc_state[current_fdc].reset = 0;
17061734 /* We have to clear the reset flag here, because apparently on boxes
17071735 * with level triggered interrupts (PS/2, Sparc, ...), it is needed to
1708− * emit SENSEI's to clear the interrupt line. And FDCS->reset blocks the
1709− * emission of the SENSEI's.
1736+ * emit SENSEI's to clear the interrupt line. And fdc_state[fdc].reset
1737+ * blocks the emission of the SENSEI's.
17101738 * It is OK to emit floppy commands because we are in an interrupt
17111739 * handler here, and thus we have to fear no interference of other
17121740 * activity.
@@ -1725,11 +1753,11 @@ irqreturn_t floppy_interrupt(int irq, void *dev_id) · 12 unmodified lines
17251753 if (do_print)
17261754 print_result("sensei", inr);
17271755 max_sensei--;
1728− } while ((ST0 & 0x83) != UNIT(current_drive) &&
1756+ } while ((reply_buffer[ST0] & 0x83) != UNIT(current_drive) &&
17291757 inr == 2 && max_sensei);
17301758 }
17311759 if (!handler) {
1732− FDCS->reset = 1;
1760+ fdc_state[current_fdc].reset = 1;
17331761 return IRQ_NONE;
17341762 }
17351763 schedule_bh(handler);
@@ -1755,7 +1783,7 @@ static void reset_interrupt(void) · 19 unmodified lines
17551783 {
17561784 debugt(__func__, "");
17571785 result(); /* get the status ready for set_fdc */
1758− if (FDCS->reset) {
1786+ if (fdc_state[current_fdc].reset) {
17591787 pr_info("reset set in interrupt, calling %ps\n", cont->error);
17601788 cont->error(); /* a reset just after a reset. BAD! */
17611789 }
@@ -1771,7 +1799,7 @@ static void reset_fdc(void) · 9 unmodified lines
17711799 unsigned long flags;
17721800
17731801 do_floppy = reset_interrupt;
1774− FDCS->reset = 0;
1802+ fdc_state[current_fdc].reset = 0;
17751803 reset_fdc_info(0);
17761804
17771805 /* Pseudo-DMA may intercept 'reset finished' interrupt. */
@@ -1781,12 +1809,13 @@ static void reset_fdc(void) · 3 unmodified lines
17811809 fd_disable_dma();
17821810 release_dma_lock(flags);
17831811
1784− if (FDCS->version >= FDC_82072A)
1785− fd_outb(0x80 | (FDCS->dtr & 3), FD_STATUS);
1812+ if (fdc_state[current_fdc].version >= FDC_82072A)
1813+ fdc_outb(0x80 | (fdc_state[current_fdc].dtr & 3),
1814+ current_fdc, FD_STATUS);
17861815 else {
1787− fd_outb(FDCS->dor & ~0x04, FD_DOR);
1816+ fdc_outb(fdc_state[current_fdc].dor & ~0x04, current_fdc, FD_DOR);
17881817 udelay(FD_RESET_DELAY);
1789− fd_outb(FDCS->dor, FD_DOR);
1818+ fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR);
17901819 }
17911820 }
17921821
@@ -1813,7 +1842,7 @@ static void show_floppy(void) · 20 unmodified lines
18131842 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1,
18141843 reply_buffer, resultsize, true);
18151844
1816− pr_info("status=%x\n", fd_inb(FD_STATUS));
1845+ pr_info("status=%x\n", fdc_inb(current_fdc, FD_STATUS));
18171846 pr_info("fdc_busy=%lu\n", fdc_busy);
18181847 if (do_floppy)
18191848 pr_info("do_floppy=%ps\n", do_floppy);
@@ -1850,7 +1879,7 @@ static void floppy_shutdown(struct work_struct *arg) · 30 unmodified lines
18501879
18511880 if (initialized)
18521881 DPRINT("floppy timeout called\n");
1853− FDCS->reset = 1;
1882+ fdc_state[current_fdc].reset = 1;
18541883 if (cont) {
18551884 cont->done(0);
18561885 cont->redo(); /* this will recall reset when needed */
@@ -1870,29 +1899,29 @@ static int start_motor(void (*function)(void)) · 13 unmodified lines
18701899 mask = 0xfc;
18711900 data = UNIT(current_drive);
18721901 if (!(raw_cmd->flags & FD_RAW_NO_MOTOR)) {
1873− if (!(FDCS->dor & (0x10 << UNIT(current_drive)))) {
1902+ if (!(fdc_state[current_fdc].dor & (0x10 << UNIT(current_drive)))) {
18741903 set_debugt();
18751904 /* no read since this drive is running */
1876− DRS->first_read_date = 0;
1905+ drive_state[current_drive].first_read_date = 0;
18771906 /* note motor start time if motor is not yet running */
1878− DRS->spinup_date = jiffies;
1907+ drive_state[current_drive].spinup_date = jiffies;
18791908 data |= (0x10 << UNIT(current_drive));
18801909 }
1881− } else if (FDCS->dor & (0x10 << UNIT(current_drive)))
1910+ } else if (fdc_state[current_fdc].dor & (0x10 << UNIT(current_drive)))
18821911 mask &= ~(0x10 << UNIT(current_drive));
18831912
18841913 /* starts motor and selects floppy */
18851914 del_timer(motor_off_timer + current_drive);
1886− set_dor(fdc, mask, data);
1915+ set_dor(current_fdc, mask, data);
18871916
18881917 /* wait_for_completion also schedules reset if needed. */
1889− return fd_wait_for_completion(DRS->select_date + DP->select_delay,
1918+ return fd_wait_for_completion(drive_state[current_drive].select_date + drive_params[current_drive].select_delay,
18901919 function);
18911920 }
18921921
18931922 static void floppy_ready(void)
18941923 {
1895− if (FDCS->reset) {
1924+ if (fdc_state[current_fdc].reset) {
18961925 reset_fdc();
18971926 return;
18981927 }
@@ -1901,9 +1930,10 @@ static void floppy_ready(void) · 2 unmodified lines
19011930 if (fdc_dtr())
19021931 return;
19031932
1904− debug_dcl(DP->flags, "calling disk change from floppy_ready\n");
1933+ debug_dcl(drive_params[current_drive].flags,
1934+ "calling disk change from floppy_ready\n");
19051935 if (!(raw_cmd->flags & FD_RAW_NO_MOTOR) &&
1906− disk_change(current_drive) && !DP->select_delay)
1936+ disk_change(current_drive) && !drive_params[current_drive].select_delay)
19071937 twaddle(); /* this clears the dcl on certain
19081938 * drive/controller combinations */
19091939
@@ -1932,8 +1962,9 @@ static void floppy_start(void) · 22 unmodified lines
19321962 reschedule_timeout(current_reqD, "floppy start");
19331963
19341964 scandrives();
1935− debug_dcl(DP->flags, "setting NEWCHANGE in floppy_start\n");
1936− set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
1965+ debug_dcl(drive_params[current_drive].flags,
1966+ "setting NEWCHANGE in floppy_start\n");
1967+ set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags);
19371968 floppy_ready();
19381969 }
19391970
@@ -1991,7 +2022,7 @@ static int wait_til_done(void (*handler)(void), bool interruptible) · 51 unmodified lines
19912022 return -EINTR;
19922023 }
19932024
1994− if (FDCS->reset)
2025+ if (fdc_state[current_fdc].reset)
19952026 command_status = FD_COMMAND_ERROR;
19962027 if (command_status == FD_COMMAND_OKAY)
19972028 ret = 0;
@@ -2032,14 +2063,14 @@ static int next_valid_format(void) · 34 unmodified lines
20322063 {
20332064 int probed_format;
20342065
2035− probed_format = DRS->probed_format;
2066+ probed_format = drive_state[current_drive].probed_format;
20362067 while (1) {
2037− if (probed_format >= 8 || !DP->autodetect[probed_format]) {
2038− DRS->probed_format = 0;
2068+ if (probed_format >= 8 || !drive_params[current_drive].autodetect[probed_format]) {
2069+ drive_state[current_drive].probed_format = 0;
20392070 return 1;
20402071 }
2041− if (floppy_type[DP->autodetect[probed_format]].sect) {
2042− DRS->probed_format = probed_format;
2072+ if (floppy_type[drive_params[current_drive].autodetect[probed_format]].sect) {
2073+ drive_state[current_drive].probed_format = probed_format;
20432074 return 0;
20442075 }
20452076 probed_format++;
@@ -2051,23 +2082,23 @@ static void bad_flp_intr(void) · 5 unmodified lines
20512082 int err_count;
20522083
20532084 if (probing) {
2054− DRS->probed_format++;
2085+ drive_state[current_drive].probed_format++;
20552086 if (!next_valid_format())
20562087 return;
20572088 }
20582089 err_count = ++(*errors);
2059− INFBOUND(DRWE->badness, err_count);
2060− if (err_count > DP->max_errors.abort)
2090+ INFBOUND(write_errors[current_drive].badness, err_count);
2091+ if (err_count > drive_params[current_drive].max_errors.abort)
20612092 cont->done(0);
2062− if (err_count > DP->max_errors.reset)
2063− FDCS->reset = 1;
2064− else if (err_count > DP->max_errors.recal)
2065− DRS->track = NEED_2_RECAL;
2093+ if (err_count > drive_params[current_drive].max_errors.reset)
2094+ fdc_state[current_fdc].reset = 1;
2095+ else if (err_count > drive_params[current_drive].max_errors.recal)
2096+ drive_state[current_drive].track = NEED_2_RECAL;
20662097 }
20672098
20682099 static void set_floppy(int drive)
20692100 {
2070− int type = ITYPE(UDRS->fd_device);
2101+ int type = ITYPE(drive_state[drive].fd_device);
20712102
20722103 if (type)
20732104 _floppy = floppy_type + type;
@@ -2113,28 +2144,28 @@ static void setup_format_params(int track) · 39 unmodified lines
21132144 FD_RAW_NEED_DISK | FD_RAW_NEED_SEEK);
21142145 raw_cmd->rate = _floppy->rate & 0x43;
21152146 raw_cmd->cmd_count = NR_F;
2116− COMMAND = FM_MODE(_floppy, FD_FORMAT);
2117− DR_SELECT = UNIT(current_drive) + PH_HEAD(_floppy, format_req.head);
2118− F_SIZECODE = FD_SIZECODE(_floppy);
2119− F_SECT_PER_TRACK = _floppy->sect << 2 >> F_SIZECODE;
2120− F_GAP = _floppy->fmt_gap;
2121− F_FILL = FD_FILL_BYTE;
2147+ raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_FORMAT);
2148+ raw_cmd->cmd[DR_SELECT] = UNIT(current_drive) + PH_HEAD(_floppy, format_req.head);
2149+ raw_cmd->cmd[F_SIZECODE] = FD_SIZECODE(_floppy);
2150+ raw_cmd->cmd[F_SECT_PER_TRACK] = _floppy->sect << 2 >> raw_cmd->cmd[F_SIZECODE];
2151+ raw_cmd->cmd[F_GAP] = _floppy->fmt_gap;
2152+ raw_cmd->cmd[F_FILL] = FD_FILL_BYTE;
21222153
21232154 raw_cmd->kernel_data = floppy_track_buffer;
2124− raw_cmd->length = 4 * F_SECT_PER_TRACK;
2155+ raw_cmd->length = 4 * raw_cmd->cmd[F_SECT_PER_TRACK];
21252156
2126− if (!F_SECT_PER_TRACK)
2157+ if (!raw_cmd->cmd[F_SECT_PER_TRACK])
21272158 return;
21282159
21292160 /* allow for about 30ms for data transport per track */
2130− head_shift = (F_SECT_PER_TRACK + 5) / 6;
2161+ head_shift = (raw_cmd->cmd[F_SECT_PER_TRACK] + 5) / 6;
21312162
21322163 /* a ``cylinder'' is two tracks plus a little stepping time */
21332164 track_shift = 2 * head_shift + 3;
21342165
21352166 /* position of logical sector 1 on this track */
21362167 n = (track_shift * format_req.track + head_shift * format_req.head)
2137− % F_SECT_PER_TRACK;
2168+ % raw_cmd->cmd[F_SECT_PER_TRACK];
21382169
21392170 /* determine interleave */
21402171 il = 1;
@@ -2142,27 +2173,27 @@ static void setup_format_params(int track) · 1 unmodified line
21422173 il++;
21432174
21442175 /* initialize field */
2145− for (count = 0; count < F_SECT_PER_TRACK; ++count) {
2176+ for (count = 0; count < raw_cmd->cmd[F_SECT_PER_TRACK]; ++count) {
21462177 here[count].track = format_req.track;
21472178 here[count].head = format_req.head;
21482179 here[count].sect = 0;
2149− here[count].size = F_SIZECODE;
2180+ here[count].size = raw_cmd->cmd[F_SIZECODE];
21502181 }
21512182 /* place logical sectors */
2152− for (count = 1; count <= F_SECT_PER_TRACK; ++count) {
2183+ for (count = 1; count <= raw_cmd->cmd[F_SECT_PER_TRACK]; ++count) {
21532184 here[n].sect = count;
2154− n = (n + il) % F_SECT_PER_TRACK;
2185+ n = (n + il) % raw_cmd->cmd[F_SECT_PER_TRACK];
21552186 if (here[n].sect) { /* sector busy, find next free sector */
21562187 ++n;
2157− if (n >= F_SECT_PER_TRACK) {
2158− n -= F_SECT_PER_TRACK;
2188+ if (n >= raw_cmd->cmd[F_SECT_PER_TRACK]) {
2189+ n -= raw_cmd->cmd[F_SECT_PER_TRACK];
21592190 while (here[n].sect)
21602191 ++n;
21612192 }
21622193 }
21632194 }
21642195 if (_floppy->stretch & FD_SECTBASEMASK) {
2165− for (count = 0; count < F_SECT_PER_TRACK; count++)
2196+ for (count = 0; count < raw_cmd->cmd[F_SECT_PER_TRACK]; count++)
21662197 here[count].sect += FD_SECTBASE(_floppy) - 1;
21672198 }
21682199 }
@@ -2191,7 +2222,7 @@ static int do_format(int drive, struct format_descr *tmp_format_req) · 22 unmodified lines
21912222
21922223 set_floppy(drive);
21932224 if (!_floppy ||
2194− _floppy->track > DP->tracks ||
2225+ _floppy->track > drive_params[current_drive].tracks ||
21952226 tmp_format_req->track >= _floppy->track ||
21962227 tmp_format_req->head >= _floppy->head ||
21972228 (_floppy->sect << 2) % (1 << FD_SIZECODE(_floppy)) ||
@@ -2253,21 +2284,21 @@ static void request_done(int uptodate) · 55 unmodified lines
22532284 /* maintain values for invalidation on geometry
22542285 * change */
22552286 block = current_count_sectors + blk_rq_pos(req);
2256− INFBOUND(DRS->maxblock, block);
2287+ INFBOUND(drive_state[current_drive].maxblock, block);
22572288 if (block > _floppy->sect)
2258− DRS->maxtrack = 1;
2289+ drive_state[current_drive].maxtrack = 1;
22592290
22602291 floppy_end_request(req, 0);
22612292 } else {
22622293 if (rq_data_dir(req) == WRITE) {
22632294 /* record write error information */
2264− DRWE->write_errors++;
2265− if (DRWE->write_errors == 1) {
2266− DRWE->first_error_sector = blk_rq_pos(req);
2267− DRWE->first_error_generation = DRS->generation;
2295+ write_errors[current_drive].write_errors++;
2296+ if (write_errors[current_drive].write_errors == 1) {
2297+ write_errors[current_drive].first_error_sector = blk_rq_pos(req);
2298+ write_errors[current_drive].first_error_generation = drive_state[current_drive].generation;
22682299 }
2269− DRWE->last_error_sector = blk_rq_pos(req);
2270− DRWE->last_error_generation = DRS->generation;
2300+ write_errors[current_drive].last_error_sector = blk_rq_pos(req);
2301+ write_errors[current_drive].last_error_generation = drive_state[current_drive].generation;
22712302 }
22722303 floppy_end_request(req, BLK_STS_IOERR);
22732304 }
@@ -2281,43 +2312,46 @@ static void rw_interrupt(void) · 7 unmodified lines
22812312 int heads;
22822313 int nr_sectors;
22832314
2284− if (R_HEAD >= 2) {
2315+ if (reply_buffer[R_HEAD] >= 2) {
22852316 /* some Toshiba floppy controllers occasionnally seem to
22862317 * return bogus interrupts after read/write operations, which
22872318 * can be recognized by a bad head number (>= 2) */
22882319 return;
22892320 }
22902321
2291− if (!DRS->first_read_date)
2292− DRS->first_read_date = jiffies;
2322+ if (!drive_state[current_drive].first_read_date)
2323+ drive_state[current_drive].first_read_date = jiffies;
22932324
22942325 nr_sectors = 0;
2295− ssize = DIV_ROUND_UP(1 << SIZECODE, 4);
2326+ ssize = DIV_ROUND_UP(1 << raw_cmd->cmd[SIZECODE], 4);
22962327
2297− if (ST1 & ST1_EOC)
2328+ if (reply_buffer[ST1] & ST1_EOC)
22982329 eoc = 1;
22992330 else
23002331 eoc = 0;
23012332
2302− if (COMMAND & 0x80)
2333+ if (raw_cmd->cmd[COMMAND] & 0x80)
23032334 heads = 2;
23042335 else
23052336 heads = 1;
23062337
2307− nr_sectors = (((R_TRACK - TRACK) * heads +
2308− R_HEAD - HEAD) * SECT_PER_TRACK +
2309− R_SECTOR - SECTOR + eoc) << SIZECODE >> 2;
2338+ nr_sectors = (((reply_buffer[R_TRACK] - raw_cmd->cmd[TRACK]) * heads +
2339+ reply_buffer[R_HEAD] - raw_cmd->cmd[HEAD]) * raw_cmd->cmd[SECT_PER_TRACK] +
2340+ reply_buffer[R_SECTOR] - raw_cmd->cmd[SECTOR] + eoc) << raw_cmd->cmd[SIZECODE] >> 2;
23102341
23112342 if (nr_sectors / ssize >
23122343 DIV_ROUND_UP(in_sector_offset + current_count_sectors, ssize)) {
23132344 DPRINT("long rw: %x instead of %lx\n",
23142345 nr_sectors, current_count_sectors);
2315− pr_info("rs=%d s=%d\n", R_SECTOR, SECTOR);
2316− pr_info("rh=%d h=%d\n", R_HEAD, HEAD);
2317− pr_info("rt=%d t=%d\n", R_TRACK, TRACK);
2346+ pr_info("rs=%d s=%d\n", reply_buffer[R_SECTOR],
2347+ raw_cmd->cmd[SECTOR]);
2348+ pr_info("rh=%d h=%d\n", reply_buffer[R_HEAD],
2349+ raw_cmd->cmd[HEAD]);
2350+ pr_info("rt=%d t=%d\n", reply_buffer[R_TRACK],
2351+ raw_cmd->cmd[TRACK]);
23182352 pr_info("heads=%d eoc=%d\n", heads, eoc);
23192353 pr_info("spt=%d st=%d ss=%d\n",
2320− SECT_PER_TRACK, fsector_t, ssize);
2354+ raw_cmd->cmd[SECT_PER_TRACK], fsector_t, ssize);
23212355 pr_info("in_sector_offset=%d\n", in_sector_offset);
23222356 }
23232357
@@ -2347,7 +2381,7 @@ static void rw_interrupt(void) · 23 unmodified lines
23472381 }
23482382
23492383 if (probing) {
2350− if (DP->flags & FTD_MSG)
2384+ if (drive_params[current_drive].flags & FTD_MSG)
23512385 DPRINT("Auto-detected floppy type %s in fd%d\n",
23522386 _floppy->name, current_drive);
23532387 current_type[current_drive] = _floppy;
@@ -2355,11 +2389,11 @@ static void rw_interrupt(void) · 1 unmodified line
23552389 probing = 0;
23562390 }
23572391
2358− if (CT(COMMAND) != FD_READ ||
2392+ if (CT(raw_cmd->cmd[COMMAND]) != FD_READ ||
23592393 raw_cmd->kernel_data == bio_data(current_req->bio)) {
23602394 /* transfer directly from buffer */
23612395 cont->done(1);
2362− } else if (CT(COMMAND) == FD_READ) {
2396+ } else if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) {
23632397 buffer_track = raw_cmd->track;
23642398 buffer_drive = current_drive;
23652399 INFBOUND(buffer_max, nr_sectors + fsector_t);
@@ -2418,13 +2452,13 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2) · 52 unmodified lines
24182452 min(max_sector, max_sector_2),
24192453 blk_rq_sectors(current_req));
24202454
2421− if (current_count_sectors <= 0 && CT(COMMAND) == FD_WRITE &&
2455+ if (current_count_sectors <= 0 && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE &&
24222456 buffer_max > fsector_t + blk_rq_sectors(current_req))
24232457 current_count_sectors = min_t(int, buffer_max - fsector_t,
24242458 blk_rq_sectors(current_req));
24252459
24262460 remaining = current_count_sectors << 9;
2427− if (remaining > blk_rq_bytes(current_req) && CT(COMMAND) == FD_WRITE) {
2461+ if (remaining > blk_rq_bytes(current_req) && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
24282462 DPRINT("in copy buffer\n");
24292463 pr_info("current_count_sectors=%ld\n", current_count_sectors);
24302464 pr_info("remaining=%d\n", remaining >> 9);
@@ -2459,16 +2493,16 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2) · 28 unmodified lines
24592493 fsector_t, buffer_min);
24602494 pr_info("current_count_sectors=%ld\n",
24612495 current_count_sectors);
2462− if (CT(COMMAND) == FD_READ)
2496+ if (CT(raw_cmd->cmd[COMMAND]) == FD_READ)
24632497 pr_info("read\n");
2464− if (CT(COMMAND) == FD_WRITE)
2498+ if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE)
24652499 pr_info("write\n");
24662500 break;
24672501 }
24682502 if (((unsigned long)buffer) % 512)
24692503 DPRINT("%p buffer not aligned\n", buffer);
24702504
2471− if (CT(COMMAND) == FD_READ)
2505+ if (CT(raw_cmd->cmd[COMMAND]) == FD_READ)
24722506 memcpy(buffer, dma_buffer, size);
24732507 else
24742508 memcpy(dma_buffer, buffer, size);
@@ -2486,7 +2520,7 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2) · 11 unmodified lines
24862520 /* work around a bug in pseudo DMA
24872521 * (on some FDCs) pseudo DMA does not stop when the CPU stops
24882522 * sending data. Hence we need a different way to signal the
2489− * transfer length: We use SECT_PER_TRACK. Unfortunately, this
2523+ * transfer length: We use raw_cmd->cmd[SECT_PER_TRACK]. Unfortunately, this
24902524 * does not work with MT, hence we can only transfer one head at
24912525 * a time
24922526 */
@@ -2495,18 +2529,18 @@ static void virtualdmabug_workaround(void) · 2 unmodified lines
24952529 int hard_sectors;
24962530 int end_sector;
24972531
2498− if (CT(COMMAND) == FD_WRITE) {
2499− COMMAND &= ~0x80; /* switch off multiple track mode */
2532+ if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
2533+ raw_cmd->cmd[COMMAND] &= ~0x80; /* switch off multiple track mode */
25002534
2501− hard_sectors = raw_cmd->length >> (7 + SIZECODE);
2502− end_sector = SECTOR + hard_sectors - 1;
2503− if (end_sector > SECT_PER_TRACK) {
2535+ hard_sectors = raw_cmd->length >> (7 + raw_cmd->cmd[SIZECODE]);
2536+ end_sector = raw_cmd->cmd[SECTOR] + hard_sectors - 1;
2537+ if (end_sector > raw_cmd->cmd[SECT_PER_TRACK]) {
25042538 pr_info("too many sectors %d > %d\n",
2505− end_sector, SECT_PER_TRACK);
2539+ end_sector, raw_cmd->cmd[SECT_PER_TRACK]);
25062540 return;
25072541 }
2508− SECT_PER_TRACK = end_sector;
2509− /* make sure SECT_PER_TRACK
2542+ raw_cmd->cmd[SECT_PER_TRACK] = end_sector;
2543+ /* make sure raw_cmd->cmd[SECT_PER_TRACK]
25102544 * points to end of transfer */
25112545 }
25122546 }
@@ -2539,10 +2573,10 @@ static int make_raw_rw_request(void) · 26 unmodified lines
25392573 raw_cmd->cmd_count = NR_RW;
25402574 if (rq_data_dir(current_req) == READ) {
25412575 raw_cmd->flags |= FD_RAW_READ;
2542− COMMAND = FM_MODE(_floppy, FD_READ);
2576+ raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_READ);
25432577 } else if (rq_data_dir(current_req) == WRITE) {
25442578 raw_cmd->flags |= FD_RAW_WRITE;
2545− COMMAND = FM_MODE(_floppy, FD_WRITE);
2579+ raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_WRITE);
25462580 } else {
25472581 DPRINT("%s: unknown command\n", __func__);
25482582 return 0;
@@ -2550,24 +2584,24 @@ static int make_raw_rw_request(void) · 1 unmodified line
25502584
25512585 max_sector = _floppy->sect * _floppy->head;
25522586
2553− TRACK = (int)blk_rq_pos(current_req) / max_sector;
2587+ raw_cmd->cmd[TRACK] = (int)blk_rq_pos(current_req) / max_sector;
25542588 fsector_t = (int)blk_rq_pos(current_req) % max_sector;
2555− if (_floppy->track && TRACK >= _floppy->track) {
2589+ if (_floppy->track && raw_cmd->cmd[TRACK] >= _floppy->track) {
25562590 if (blk_rq_cur_sectors(current_req) & 1) {
25572591 current_count_sectors = 1;
25582592 return 1;
25592593 } else
25602594 return 0;
25612595 }
2562− HEAD = fsector_t / _floppy->sect;
2596+ raw_cmd->cmd[HEAD] = fsector_t / _floppy->sect;
25632597
25642598 if (((_floppy->stretch & (FD_SWAPSIDES | FD_SECTBASEMASK)) ||
2565− test_bit(FD_NEED_TWADDLE_BIT, &DRS->flags)) &&
2599+ test_bit(FD_NEED_TWADDLE_BIT, &drive_state[current_drive].flags)) &&
25662600 fsector_t < _floppy->sect)
25672601 max_sector = _floppy->sect;
25682602
25692603 /* 2M disks have phantom sectors on the first track */
2570− if ((_floppy->rate & FD_2M) && (!TRACK) && (!HEAD)) {
2604+ if ((_floppy->rate & FD_2M) && (!raw_cmd->cmd[TRACK]) && (!raw_cmd->cmd[HEAD])) {
25712605 max_sector = 2 * _floppy->sect / 3;
25722606 if (fsector_t >= max_sector) {
25732607 current_count_sectors =
@@ -2575,23 +2609,24 @@ static int make_raw_rw_request(void) · 1 unmodified line
25752609 blk_rq_sectors(current_req));
25762610 return 1;
25772611 }
2578− SIZECODE = 2;
2612+ raw_cmd->cmd[SIZECODE] = 2;
25792613 } else
2580− SIZECODE = FD_SIZECODE(_floppy);
2614+ raw_cmd->cmd[SIZECODE] = FD_SIZECODE(_floppy);
25812615 raw_cmd->rate = _floppy->rate & 0x43;
2582− if ((_floppy->rate & FD_2M) && (TRACK || HEAD) && raw_cmd->rate == 2)
2616+ if ((_floppy->rate & FD_2M) &&
2617+ (raw_cmd->cmd[TRACK] || raw_cmd->cmd[HEAD]) && raw_cmd->rate == 2)
25832618 raw_cmd->rate = 1;
25842619
2585− if (SIZECODE)
2586− SIZECODE2 = 0xff;
2620+ if (raw_cmd->cmd[SIZECODE])
2621+ raw_cmd->cmd[SIZECODE2] = 0xff;
25872622 else
2588− SIZECODE2 = 0x80;
2589− raw_cmd->track = TRACK << STRETCH(_floppy);
2590− DR_SELECT = UNIT(current_drive) + PH_HEAD(_floppy, HEAD);
2591− GAP = _floppy->gap;
2592− ssize = DIV_ROUND_UP(1 << SIZECODE, 4);
2593− SECT_PER_TRACK = _floppy->sect << 2 >> SIZECODE;
2594− SECTOR = ((fsector_t % _floppy->sect) << 2 >> SIZECODE) +
2623+ raw_cmd->cmd[SIZECODE2] = 0x80;
2624+ raw_cmd->track = raw_cmd->cmd[TRACK] << STRETCH(_floppy);
2625+ raw_cmd->cmd[DR_SELECT] = UNIT(current_drive) + PH_HEAD(_floppy, raw_cmd->cmd[HEAD]);
2626+ raw_cmd->cmd[GAP] = _floppy->gap;
2627+ ssize = DIV_ROUND_UP(1 << raw_cmd->cmd[SIZECODE], 4);
2628+ raw_cmd->cmd[SECT_PER_TRACK] = _floppy->sect << 2 >> raw_cmd->cmd[SIZECODE];
2629+ raw_cmd->cmd[SECTOR] = ((fsector_t % _floppy->sect) << 2 >> raw_cmd->cmd[SIZECODE]) +
25952630 FD_SECTBASE(_floppy);
25962631
25972632 /* tracksize describes the size which can be filled up with sectors
@@ -2599,24 +2634,24 @@ static int make_raw_rw_request(void) · 1 unmodified line
25992634 */
26002635 tracksize = _floppy->sect - _floppy->sect % ssize;
26012636 if (tracksize < _floppy->sect) {
2602− SECT_PER_TRACK++;
2637+ raw_cmd->cmd[SECT_PER_TRACK]++;
26032638 if (tracksize <= fsector_t % _floppy->sect)
2604− SECTOR--;
2639+ raw_cmd->cmd[SECTOR]--;
26052640
26062641 /* if we are beyond tracksize, fill up using smaller sectors */
26072642 while (tracksize <= fsector_t % _floppy->sect) {
26082643 while (tracksize + ssize > _floppy->sect) {
2609− SIZECODE--;
2644+ raw_cmd->cmd[SIZECODE]--;
26102645 ssize >>= 1;
26112646 }
2612− SECTOR++;
2613− SECT_PER_TRACK++;
2647+ raw_cmd->cmd[SECTOR]++;
2648+ raw_cmd->cmd[SECT_PER_TRACK]++;
26142649 tracksize += ssize;
26152650 }
2616− max_sector = HEAD * _floppy->sect + tracksize;
2617− } else if (!TRACK && !HEAD && !(_floppy->rate & FD_2M) && probing) {
2651+ max_sector = raw_cmd->cmd[HEAD] * _floppy->sect + tracksize;
2652+ } else if (!raw_cmd->cmd[TRACK] && !raw_cmd->cmd[HEAD] && !(_floppy->rate & FD_2M) && probing) {
26182653 max_sector = _floppy->sect;
2619− } else if (!HEAD && CT(COMMAND) == FD_WRITE) {
2654+ } else if (!raw_cmd->cmd[HEAD] && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
26202655 /* for virtual DMA bug workaround */
26212656 max_sector = _floppy->sect;
26222657 }
@@ -2628,12 +2663,12 @@ static int make_raw_rw_request(void) · 5 unmodified lines
26282663 (current_drive == buffer_drive) &&
26292664 (fsector_t >= buffer_min) && (fsector_t < buffer_max)) {
26302665 /* data already in track buffer */
2631− if (CT(COMMAND) == FD_READ) {
2666+ if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) {
26322667 copy_buffer(1, max_sector, buffer_max);
26332668 return 1;
26342669 }
26352670 } else if (in_sector_offset || blk_rq_sectors(current_req) < ssize) {
2636− if (CT(COMMAND) == FD_WRITE) {
2671+ if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
26372672 unsigned int sectors;
26382673
26392674 sectors = fsector_t + blk_rq_sectors(current_req);
@@ -2644,7 +2679,7 @@ static int make_raw_rw_request(void) · 4 unmodified lines
26442679 }
26452680 raw_cmd->flags &= ~FD_RAW_WRITE;
26462681 raw_cmd->flags |= FD_RAW_READ;
2647− COMMAND = FM_MODE(_floppy, FD_READ);
2682+ raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_READ);
26482683 } else if ((unsigned long)bio_data(current_req->bio) < MAX_DMA_ADDRESS) {
26492684 unsigned long dma_limit;
26502685 int direct, indirect;
@@ -2677,9 +2712,9 @@ static int make_raw_rw_request(void) · 26 unmodified lines
26772712 */
26782713 if (!direct ||
26792714 (indirect * 2 > direct * 3 &&
2680− *errors < DP->max_errors.read_track &&
2715+ *errors < drive_params[current_drive].max_errors.read_track &&
26812716 ((!probing ||
2682− (DP->read_track & (1 << DRS->probed_format)))))) {
2717+ (drive_params[current_drive].read_track & (1 << drive_state[current_drive].probed_format)))))) {
26832718 max_size = blk_rq_sectors(current_req);
26842719 } else {
26852720 raw_cmd->kernel_data = bio_data(current_req->bio);
@@ -2695,7 +2730,7 @@ static int make_raw_rw_request(void) · 9 unmodified lines
26952730 }
26962731 }
26972732
2698− if (CT(COMMAND) == FD_READ)
2733+ if (CT(raw_cmd->cmd[COMMAND]) == FD_READ)
26992734 max_size = max_sector; /* unbounded */
27002735
27012736 /* claim buffer track if needed */
@@ -2703,7 +2738,7 @@ static int make_raw_rw_request(void) · 1 unmodified line
27032738 buffer_drive != current_drive || /* bad drive */
27042739 fsector_t > buffer_max ||
27052740 fsector_t < buffer_min ||
2706− ((CT(COMMAND) == FD_READ ||
2741+ ((CT(raw_cmd->cmd[COMMAND]) == FD_READ ||
27072742 (!in_sector_offset && blk_rq_sectors(current_req) >= ssize)) &&
27082743 max_sector > 2 * max_buffer_sectors + buffer_min &&
27092744 max_size + fsector_t > 2 * max_buffer_sectors + buffer_min)) {
@@ -2715,7 +2750,7 @@ static int make_raw_rw_request(void) · 5 unmodified lines
27152750 raw_cmd->kernel_data = floppy_track_buffer +
27162751 ((aligned_sector_t - buffer_min) << 9);
27172752
2718− if (CT(COMMAND) == FD_WRITE) {
2753+ if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
27192754 /* copy write buffer to track buffer.
27202755 * if we get here, we know that the write
27212756 * is either aligned or the data already in the buffer
@@ -2737,10 +2772,10 @@ static int make_raw_rw_request(void) · 15 unmodified lines
27372772 raw_cmd->length <<= 9;
27382773 if ((raw_cmd->length < current_count_sectors << 9) ||
27392774 (raw_cmd->kernel_data != bio_data(current_req->bio) &&
2740− CT(COMMAND) == FD_WRITE &&
2775+ CT(raw_cmd->cmd[COMMAND]) == FD_WRITE &&
27412776 (aligned_sector_t + (raw_cmd->length >> 9) > buffer_max ||
27422777 aligned_sector_t < buffer_min)) ||
2743− raw_cmd->length % (128 << SIZECODE) ||
2778+ raw_cmd->length % (128 << raw_cmd->cmd[SIZECODE]) ||
27442779 raw_cmd->length <= 0 || current_count_sectors <= 0) {
27452780 DPRINT("fractionary current count b=%lx s=%lx\n",
27462781 raw_cmd->length, current_count_sectors);
@@ -2751,9 +2786,10 @@ static int make_raw_rw_request(void) · 4 unmodified lines
27512786 current_count_sectors);
27522787 pr_info("st=%d ast=%d mse=%d msi=%d\n",
27532788 fsector_t, aligned_sector_t, max_sector, max_size);
2754− pr_info("ssize=%x SIZECODE=%d\n", ssize, SIZECODE);
2789+ pr_info("ssize=%x SIZECODE=%d\n", ssize, raw_cmd->cmd[SIZECODE]);
27552790 pr_info("command=%x SECTOR=%d HEAD=%d, TRACK=%d\n",
2756− COMMAND, SECTOR, HEAD, TRACK);
2791+ raw_cmd->cmd[COMMAND], raw_cmd->cmd[SECTOR],
2792+ raw_cmd->cmd[HEAD], raw_cmd->cmd[TRACK]);
27572793 pr_info("buffer drive=%d\n", buffer_drive);
27582794 pr_info("buffer track=%d\n", buffer_track);
27592795 pr_info("buffer_min=%d\n", buffer_min);
@@ -2772,9 +2808,9 @@ static int make_raw_rw_request(void) · 12 unmodified lines
27722808 fsector_t, buffer_min, raw_cmd->length >> 9);
27732809 pr_info("current_count_sectors=%ld\n",
27742810 current_count_sectors);
2775− if (CT(COMMAND) == FD_READ)
2811+ if (CT(raw_cmd->cmd[COMMAND]) == FD_READ)
27762812 pr_info("read\n");
2777− if (CT(COMMAND) == FD_WRITE)
2813+ if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE)
27782814 pr_info("write\n");
27792815 return 0;
27802816 }
@@ -2841,14 +2877,14 @@ do_request: · 60 unmodified lines
28412877
28422878 disk_change(current_drive);
28432879 if (test_bit(current_drive, &fake_change) ||
2844− test_bit(FD_DISK_CHANGED_BIT, &DRS->flags)) {
2880+ test_bit(FD_DISK_CHANGED_BIT, &drive_state[current_drive].flags)) {
28452881 DPRINT("disk absent or changed during operation\n");
28462882 request_done(0);
28472883 goto do_request;
28482884 }
28492885 if (!_floppy) { /* Autodetection */
28502886 if (!probing) {
2851− DRS->probed_format = 0;
2887+ drive_state[current_drive].probed_format = 0;
28522888 if (next_valid_format()) {
28532889 DPRINT("no autodetectable formats\n");
28542890 _floppy = NULL;
@@ -2857,7 +2893,7 @@ do_request: · 2 unmodified lines
28572893 }
28582894 }
28592895 probing = 1;
2860− _floppy = floppy_type + DP->autodetect[DRS->probed_format];
2896+ _floppy = floppy_type + drive_params[current_drive].autodetect[drive_state[current_drive].probed_format];
28612897 } else
28622898 probing = 0;
28632899 errors = &(current_req->error_count);
@@ -2867,7 +2903,7 @@ do_request: · 3 unmodified lines
28672903 goto do_request;
28682904 }
28692905
2870− if (test_bit(FD_NEED_TWADDLE_BIT, &DRS->flags))
2906+ if (test_bit(FD_NEED_TWADDLE_BIT, &drive_state[current_drive].flags))
28712907 twaddle();
28722908 schedule_bh(floppy_start);
28732909 debugt(__func__, "queue fd request");
@@ -2936,8 +2972,9 @@ static int poll_drive(bool interruptible, int flag) · 62 unmodified lines
29362972 raw_cmd->track = 0;
29372973 raw_cmd->cmd_count = 0;
29382974 cont = &poll_cont;
2939− debug_dcl(DP->flags, "setting NEWCHANGE in poll_drive\n");
2940− set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
2975+ debug_dcl(drive_params[current_drive].flags,
2976+ "setting NEWCHANGE in poll_drive\n");
2977+ set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags);
29412978
29422979 return wait_til_done(floppy_ready, interruptible);
29432980 }
@@ -2967,8 +3004,8 @@ static int user_reset_fdc(int drive, int arg, bool interruptible) · 23 unmodified lines
29673004 return -EINTR;
29683005
29693006 if (arg == FD_RESET_ALWAYS)
2970− FDCS->reset = 1;
2971− if (FDCS->reset) {
3007+ fdc_state[current_fdc].reset = 1;
3008+ if (fdc_state[current_fdc].reset) {
29723009 cont = &reset_cont;
29733010 ret = wait_til_done(reset_fdc, interruptible);
29743011 if (ret == -EINTR)
@@ -3001,8 +3038,8 @@ static const char *drive_name(int type, int drive) · 26 unmodified lines
30013038 if (type)
30023039 floppy = floppy_type + type;
30033040 else {
3004− if (UDP->native_format)
3005− floppy = floppy_type + UDP->native_format;
3041+ if (drive_params[drive].native_format)
3042+ floppy = floppy_type + drive_params[drive].native_format;
30063043 else
30073044 return "(null)";
30083045 }
@@ -3179,23 +3216,23 @@ static int raw_cmd_ioctl(int cmd, void __user *param) · 170 unmodified lines
31793216 int ret2;
31803217 int ret;
31813218
3182− if (FDCS->rawcmd <= 1)
3183− FDCS->rawcmd = 1;
3219+ if (fdc_state[current_fdc].rawcmd <= 1)
3220+ fdc_state[current_fdc].rawcmd = 1;
31843221 for (drive = 0; drive < N_DRIVE; drive++) {
3185− if (FDC(drive) != fdc)
3222+ if (FDC(drive) != current_fdc)
31863223 continue;
31873224 if (drive == current_drive) {
3188− if (UDRS->fd_ref > 1) {
3189− FDCS->rawcmd = 2;
3225+ if (drive_state[drive].fd_ref > 1) {
3226+ fdc_state[current_fdc].rawcmd = 2;
31903227 break;
31913228 }
3192− } else if (UDRS->fd_ref) {
3193− FDCS->rawcmd = 2;
3229+ } else if (drive_state[drive].fd_ref) {
3230+ fdc_state[current_fdc].rawcmd = 2;
31943231 break;
31953232 }
31963233 }
31973234
3198− if (FDCS->reset)
3235+ if (fdc_state[current_fdc].reset)
31993236 return -EIO;
32003237
32013238 ret = raw_cmd_copyin(cmd, param, &my_raw_cmd);
@@ -3207,12 +3244,13 @@ static int raw_cmd_ioctl(int cmd, void __user *param) · 5 unmodified lines
32073244 raw_cmd = my_raw_cmd;
32083245 cont = &raw_cmd_cont;
32093246 ret = wait_til_done(floppy_start, true);
3210− debug_dcl(DP->flags, "calling disk change from raw_cmd ioctl\n");
3247+ debug_dcl(drive_params[current_drive].flags,
3248+ "calling disk change from raw_cmd ioctl\n");
32113249
3212− if (ret != -EINTR && FDCS->reset)
3250+ if (ret != -EINTR && fdc_state[current_fdc].reset)
32133251 ret = -EIO;
32143252
3215− DRS->track = NO_TRACK;
3253+ drive_state[current_drive].track = NO_TRACK;
32163254
32173255 ret2 = raw_cmd_copyout(cmd, param, my_raw_cmd);
32183256 if (!ret)
@@ -3240,9 +3278,9 @@ static int set_geometry(unsigned int cmd, struct floppy_struct *g, · 21 unmodified lines
32403278 (int)g->head <= 0 ||
32413279 /* check for overflow in max_sector */
32423280 (int)(g->sect * g->head) <= 0 ||
3243− /* check for zero in F_SECT_PER_TRACK */
3281+ /* check for zero in raw_cmd->cmd[F_SECT_PER_TRACK] */
32443282 (unsigned char)((g->sect << 2) >> FD_SIZECODE(g)) == 0 ||
3245− g->track <= 0 || g->track > UDP->tracks >> STRETCH(g) ||
3283+ g->track <= 0 || g->track > drive_params[drive].tracks >> STRETCH(g) ||
32463284 /* check if reserved bits are set */
32473285 (g->stretch & ~(FD_STRETCH | FD_SWAPSIDES | FD_SECTBASEMASK)) != 0)
32483286 return -EINVAL;
@@ -3285,16 +3323,16 @@ static int set_geometry(unsigned int cmd, struct floppy_struct *g, · 36 unmodified lines
32853323 current_type[drive] = &user_params[drive];
32863324 floppy_sizes[drive] = user_params[drive].size;
32873325 if (cmd == FDDEFPRM)
3288− DRS->keep_data = -1;
3326+ drive_state[current_drive].keep_data = -1;
32893327 else
3290− DRS->keep_data = 1;
3328+ drive_state[current_drive].keep_data = 1;
32913329 /* invalidation. Invalidate only when needed, i.e.
32923330 * when there are already sectors in the buffer cache
32933331 * whose number will change. This is useful, because
32943332 * mtools often changes the geometry of the disk after
32953333 * looking at the boot block */
3296− if (DRS->maxblock > user_params[drive].sect ||
3297− DRS->maxtrack ||
3334+ if (drive_state[current_drive].maxblock > user_params[drive].sect ||
3335+ drive_state[current_drive].maxtrack ||
32983336 ((user_params[drive].sect ^ oldStretch) &
32993337 (FD_SWAPSIDES | FD_SECTBASEMASK)))
33003338 invalidate_drive(bdev);
@@ -3407,7 +3445,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int · 106 unmodified lines
34073445 unsigned long param)
34083446 {
34093447 int drive = (long)bdev->bd_disk->private_data;
3410− int type = ITYPE(UDRS->fd_device);
3448+ int type = ITYPE(drive_state[drive].fd_device);
34113449 int i;
34123450 int ret;
34133451 int size;
@@ -3455,7 +3493,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int · 41 unmodified lines
34553493
34563494 switch (cmd) {
34573495 case FDEJECT:
3458− if (UDRS->fd_ref != 1)
3496+ if (drive_state[drive].fd_ref != 1)
34593497 /* somebody else has this drive open */
34603498 return -EBUSY;
34613499 if (lock_fdc(drive))
@@ -3465,8 +3503,8 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int · 3 unmodified lines
34653503 * non-Sparc architectures */
34663504 ret = fd_eject(UNIT(drive));
34673505
3468− set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
3469− set_bit(FD_VERIFY_BIT, &UDRS->flags);
3506+ set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
3507+ set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
34703508 process_fd_request();
34713509 return ret;
34723510 case FDCLRPRM:
@@ -3474,7 +3512,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int · 1 unmodified line
34743512 return -EINTR;
34753513 current_type[drive] = NULL;
34763514 floppy_sizes[drive] = MAX_DISK_SIZE << 1;
3477− UDRS->keep_data = 0;
3515+ drive_state[drive].keep_data = 0;
34783516 return invalidate_drive(bdev);
34793517 case FDSETPRM:
34803518 case FDDEFPRM:
@@ -3489,17 +3527,17 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int · 8 unmodified lines
34893527 outparam = &inparam.g;
34903528 break;
34913529 case FDMSGON:
3492− UDP->flags |= FTD_MSG;
3530+ drive_params[drive].flags |= FTD_MSG;
34933531 return 0;
34943532 case FDMSGOFF:
3495− UDP->flags &= ~FTD_MSG;
3533+ drive_params[drive].flags &= ~FTD_MSG;
34963534 return 0;
34973535 case FDFMTBEG:
34983536 if (lock_fdc(drive))
34993537 return -EINTR;
35003538 if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
35013539 return -EINTR;
3502− ret = UDRS->flags;
3540+ ret = drive_state[drive].flags;
35033541 process_fd_request();
35043542 if (ret & FD_VERIFY)
35053543 return -ENODEV;
@@ -3507,7 +3545,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int · 1 unmodified line
35073545 return -EROFS;
35083546 return 0;
35093547 case FDFMTTRK:
3510− if (UDRS->fd_ref != 1)
3548+ if (drive_state[drive].fd_ref != 1)
35113549 return -EBUSY;
35123550 return do_format(drive, &inparam.f);
35133551 case FDFMTEND:
@@ -3516,13 +3554,13 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int · 2 unmodified lines
35163554 return -EINTR;
35173555 return invalidate_drive(bdev);
35183556 case FDSETEMSGTRESH:
3519− UDP->max_errors.reporting = (unsigned short)(param & 0x0f);
3557+ drive_params[drive].max_errors.reporting = (unsigned short)(param & 0x0f);
35203558 return 0;
35213559 case FDGETMAXERRS:
3522− outparam = &UDP->max_errors;
3560+ outparam = &drive_params[drive].max_errors;
35233561 break;
35243562 case FDSETMAXERRS:
3525− UDP->max_errors = inparam.max_errors;
3563+ drive_params[drive].max_errors = inparam.max_errors;
35263564 break;
35273565 case FDGETDRVTYP:
35283566 outparam = drive_name(type, drive);
@@ -3532,10 +3570,10 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int · 3 unmodified lines
35323570 if (!valid_floppy_drive_params(inparam.dp.autodetect,
35333571 inparam.dp.native_format))
35343572 return -EINVAL;
3535− *UDP = inparam.dp;
3573+ drive_params[drive] = inparam.dp;
35363574 break;
35373575 case FDGETDRVPRM:
3538− outparam = UDP;
3576+ outparam = &drive_params[drive];
35393577 break;
35403578 case FDPOLLDRVSTAT:
35413579 if (lock_fdc(drive))
@@ -3545,18 +3583,18 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int · 3 unmodified lines
35453583 process_fd_request();
35463584 /* fall through */
35473585 case FDGETDRVSTAT:
3548− outparam = UDRS;
3586+ outparam = &drive_state[drive];
35493587 break;
35503588 case FDRESET:
35513589 return user_reset_fdc(drive, (int)param, true);
35523590 case FDGETFDCSTAT:
3553− outparam = UFDCS;
3591+ outparam = &fdc_state[FDC(drive)];
35543592 break;
35553593 case FDWERRORCLR:
3556− memset(UDRWE, 0, sizeof(*UDRWE));
3594+ memset(&write_errors[drive], 0, sizeof(write_errors[drive]));
35573595 return 0;
35583596 case FDWERRORGET:
3559− outparam = UDRWE;
3597+ outparam = &write_errors[drive];
35603598 break;
35613599 case FDRAWCMD:
35623600 if (type)
@@ -3692,7 +3730,7 @@ static int compat_set_geometry(struct block_device *bdev, fmode_t mode, unsigned · 129 unmodified lines
36923730
36933731 mutex_lock(&floppy_mutex);
36943732 drive = (long)bdev->bd_disk->private_data;
3695− type = ITYPE(UDRS->fd_device);
3733+ type = ITYPE(drive_state[drive].fd_device);
36963734 err = set_geometry(cmd == FDSETPRM32 ? FDSETPRM : FDDEFPRM,
36973735 &v, drive, type, bdev);
36983736 mutex_unlock(&floppy_mutex);
@@ -3708,7 +3746,8 @@ static int compat_get_prm(int drive, · 9 unmodified lines
37083746
37093747 memset(&v, 0, sizeof(v));
37103748 mutex_lock(&floppy_mutex);
3711− err = get_floppy_geometry(drive, ITYPE(UDRS->fd_device), &p);
3749+ err = get_floppy_geometry(drive, ITYPE(drive_state[drive].fd_device),
3750+ &p);
37123751 if (err) {
37133752 mutex_unlock(&floppy_mutex);
37143753 return err;
@@ -3732,25 +3771,26 @@ static int compat_setdrvprm(int drive, · 17 unmodified lines
37323771 if (!valid_floppy_drive_params(v.autodetect, v.native_format))
37333772 return -EINVAL;
37343773 mutex_lock(&floppy_mutex);
3735− UDP->cmos = v.cmos;
3736− UDP->max_dtr = v.max_dtr;
3737− UDP->hlt = v.hlt;
3738− UDP->hut = v.hut;
3739− UDP->srt = v.srt;
3740− UDP->spinup = v.spinup;
3741− UDP->spindown = v.spindown;
3742− UDP->spindown_offset = v.spindown_offset;
3743− UDP->select_delay = v.select_delay;
3744− UDP->rps = v.rps;
3745− UDP->tracks = v.tracks;
3746− UDP->timeout = v.timeout;
3747− UDP->interleave_sect = v.interleave_sect;
3748− UDP->max_errors = v.max_errors;
3749− UDP->flags = v.flags;
3750− UDP->read_track = v.read_track;
3751− memcpy(UDP->autodetect, v.autodetect, sizeof(v.autodetect));
3752− UDP->checkfreq = v.checkfreq;
3753− UDP->native_format = v.native_format;
3774+ drive_params[drive].cmos = v.cmos;
3775+ drive_params[drive].max_dtr = v.max_dtr;
3776+ drive_params[drive].hlt = v.hlt;
3777+ drive_params[drive].hut = v.hut;
3778+ drive_params[drive].srt = v.srt;
3779+ drive_params[drive].spinup = v.spinup;
3780+ drive_params[drive].spindown = v.spindown;
3781+ drive_params[drive].spindown_offset = v.spindown_offset;
3782+ drive_params[drive].select_delay = v.select_delay;
3783+ drive_params[drive].rps = v.rps;
3784+ drive_params[drive].tracks = v.tracks;
3785+ drive_params[drive].timeout = v.timeout;
3786+ drive_params[drive].interleave_sect = v.interleave_sect;
3787+ drive_params[drive].max_errors = v.max_errors;
3788+ drive_params[drive].flags = v.flags;
3789+ drive_params[drive].read_track = v.read_track;
3790+ memcpy(drive_params[drive].autodetect, v.autodetect,
3791+ sizeof(v.autodetect));
3792+ drive_params[drive].checkfreq = v.checkfreq;
3793+ drive_params[drive].native_format = v.native_format;
37543794 mutex_unlock(&floppy_mutex);
37553795 return 0;
37563796 }
@@ -3762,25 +3802,26 @@ static int compat_getdrvprm(int drive, · 5 unmodified lines
37623802
37633803 memset(&v, 0, sizeof(struct compat_floppy_drive_params));
37643804 mutex_lock(&floppy_mutex);
3765− v.cmos = UDP->cmos;
3766− v.max_dtr = UDP->max_dtr;
3767− v.hlt = UDP->hlt;
3768− v.hut = UDP->hut;
3769− v.srt = UDP->srt;
3770− v.spinup = UDP->spinup;
3771− v.spindown = UDP->spindown;
3772− v.spindown_offset = UDP->spindown_offset;
3773− v.select_delay = UDP->select_delay;
3774− v.rps = UDP->rps;
3775− v.tracks = UDP->tracks;
3776− v.timeout = UDP->timeout;
3777− v.interleave_sect = UDP->interleave_sect;
3778− v.max_errors = UDP->max_errors;
3779− v.flags = UDP->flags;
3780− v.read_track = UDP->read_track;
3781− memcpy(v.autodetect, UDP->autodetect, sizeof(v.autodetect));
3782− v.checkfreq = UDP->checkfreq;
3783− v.native_format = UDP->native_format;
3805+ v.cmos = drive_params[drive].cmos;
3806+ v.max_dtr = drive_params[drive].max_dtr;
3807+ v.hlt = drive_params[drive].hlt;
3808+ v.hut = drive_params[drive].hut;
3809+ v.srt = drive_params[drive].srt;
3810+ v.spinup = drive_params[drive].spinup;
3811+ v.spindown = drive_params[drive].spindown;
3812+ v.spindown_offset = drive_params[drive].spindown_offset;
3813+ v.select_delay = drive_params[drive].select_delay;
3814+ v.rps = drive_params[drive].rps;
3815+ v.tracks = drive_params[drive].tracks;
3816+ v.timeout = drive_params[drive].timeout;
3817+ v.interleave_sect = drive_params[drive].interleave_sect;
3818+ v.max_errors = drive_params[drive].max_errors;
3819+ v.flags = drive_params[drive].flags;
3820+ v.read_track = drive_params[drive].read_track;
3821+ memcpy(v.autodetect, drive_params[drive].autodetect,
3822+ sizeof(v.autodetect));
3823+ v.checkfreq = drive_params[drive].checkfreq;
3824+ v.native_format = drive_params[drive].native_format;
37843825 mutex_unlock(&floppy_mutex);
37853826
37863827 if (copy_to_user(arg, &v, sizeof(struct compat_floppy_drive_params)))
@@ -3803,20 +3844,20 @@ static int compat_getdrvstat(int drive, bool poll, · 16 unmodified lines
38033844 goto Eintr;
38043845 process_fd_request();
38053846 }
3806− v.spinup_date = UDRS->spinup_date;
3807− v.select_date = UDRS->select_date;
3808− v.first_read_date = UDRS->first_read_date;
3809− v.probed_format = UDRS->probed_format;
3810− v.track = UDRS->track;
3811− v.maxblock = UDRS->maxblock;
3812− v.maxtrack = UDRS->maxtrack;
3813− v.generation = UDRS->generation;
3814− v.keep_data = UDRS->keep_data;
3815− v.fd_ref = UDRS->fd_ref;
3816− v.fd_device = UDRS->fd_device;
3817− v.last_checked = UDRS->last_checked;
3818− v.dmabuf = (uintptr_t)UDRS->dmabuf;
3819− v.bufblocks = UDRS->bufblocks;
3847+ v.spinup_date = drive_state[drive].spinup_date;
3848+ v.select_date = drive_state[drive].select_date;
3849+ v.first_read_date = drive_state[drive].first_read_date;
3850+ v.probed_format = drive_state[drive].probed_format;
3851+ v.track = drive_state[drive].track;
3852+ v.maxblock = drive_state[drive].maxblock;
3853+ v.maxtrack = drive_state[drive].maxtrack;
3854+ v.generation = drive_state[drive].generation;
3855+ v.keep_data = drive_state[drive].keep_data;
3856+ v.fd_ref = drive_state[drive].fd_ref;
3857+ v.fd_device = drive_state[drive].fd_device;
3858+ v.last_checked = drive_state[drive].last_checked;
3859+ v.dmabuf = (uintptr_t) drive_state[drive].dmabuf;
3860+ v.bufblocks = drive_state[drive].bufblocks;
38203861 mutex_unlock(&floppy_mutex);
38213862
38223863 if (copy_to_user(arg, &v, sizeof(struct compat_floppy_drive_struct)))
@@ -3834,7 +3875,7 @@ static int compat_getfdcstat(int drive, · 11 unmodified lines
38343875 struct floppy_fdc_state v;
38353876
38363877 mutex_lock(&floppy_mutex);
3837− v = *UFDCS;
3878+ v = fdc_state[FDC(drive)];
38383879 mutex_unlock(&floppy_mutex);
38393880
38403881 memset(&v32, 0, sizeof(struct compat_floppy_fdc_state));
@@ -3864,7 +3905,7 @@ static int compat_werrorget(int drive, · 23 unmodified lines
38643905
38653906 memset(&v32, 0, sizeof(struct compat_floppy_write_errors));
38663907 mutex_lock(&floppy_mutex);
3867− v = *UDRWE;
3908+ v = write_errors[drive];
38683909 mutex_unlock(&floppy_mutex);
38693910 v32.write_errors = v.write_errors;
38703911 v32.first_error_sector = v.first_error_sector;
@@ -3933,16 +3974,16 @@ static void __init config_types(void) · 62 unmodified lines
39333974
39343975 /* read drive info out of physical CMOS */
39353976 drive = 0;
3936− if (!UDP->cmos)
3937− UDP->cmos = FLOPPY0_TYPE;
3977+ if (!drive_params[drive].cmos)
3978+ drive_params[drive].cmos = FLOPPY0_TYPE;
39383979 drive = 1;
3939− if (!UDP->cmos)
3940− UDP->cmos = FLOPPY1_TYPE;
3980+ if (!drive_params[drive].cmos)
3981+ drive_params[drive].cmos = FLOPPY1_TYPE;
39413982
39423983 /* FIXME: additional physical CMOS drive detection should go here */
39433984
39443985 for (drive = 0; drive < N_DRIVE; drive++) {
3945− unsigned int type = UDP->cmos;
3986+ unsigned int type = drive_params[drive].cmos;
39463987 struct floppy_drive_params *params;
39473988 const char *name = NULL;
39483989 char temparea[32];
@@ -3972,7 +4013,7 @@ static void __init config_types(void) · 23 unmodified lines
39724013
39734014 pr_cont("%s fd%d is %s", prepend, drive, name);
39744015 }
3975− *UDP = *params;
4016+ drive_params[drive] = *params;
39764017 }
39774018
39784019 if (has_drive)
@@ -3985,11 +4026,11 @@ static void floppy_release(struct gendisk *disk, fmode_t mode) · 6 unmodified lines
39854026
39864027 mutex_lock(&floppy_mutex);
39874028 mutex_lock(&open_lock);
3988− if (!UDRS->fd_ref--) {
4029+ if (!drive_state[drive].fd_ref--) {
39894030 DPRINT("floppy_release with fd_ref == 0");
3990− UDRS->fd_ref = 0;
4031+ drive_state[drive].fd_ref = 0;
39914032 }
3992− if (!UDRS->fd_ref)
4033+ if (!drive_state[drive].fd_ref)
39934034 opened_bdev[drive] = NULL;
39944035 mutex_unlock(&open_lock);
39954036 mutex_unlock(&floppy_mutex);
@@ -4010,16 +4051,16 @@ static int floppy_open(struct block_device *bdev, fmode_t mode) · 14 unmodified lines
40104051
40114052 mutex_lock(&floppy_mutex);
40124053 mutex_lock(&open_lock);
4013− old_dev = UDRS->fd_device;
4054+ old_dev = drive_state[drive].fd_device;
40144055 if (opened_bdev[drive] && opened_bdev[drive] != bdev)
40154056 goto out2;
40164057
4017− if (!UDRS->fd_ref && (UDP->flags & FD_BROKEN_DCL)) {
4018− set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
4019− set_bit(FD_VERIFY_BIT, &UDRS->flags);
4058+ if (!drive_state[drive].fd_ref && (drive_params[drive].flags & FD_BROKEN_DCL)) {
4059+ set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
4060+ set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
40204061 }
40214062
4022− UDRS->fd_ref++;
4063+ drive_state[drive].fd_ref++;
40234064
40244065 opened_bdev[drive] = bdev;
40254066
@@ -4028,7 +4069,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode) · 2 unmodified lines
40284069 if (!floppy_track_buffer) {
40294070 /* if opening an ED drive, reserve a big buffer,
40304071 * else reserve a small one */
4031− if ((UDP->cmos == 6) || (UDP->cmos == 5))
4072+ if ((drive_params[drive].cmos == 6) || (drive_params[drive].cmos == 5))
40324073 try = 64; /* Only 48 actually useful */
40334074 else
40344075 try = 32; /* Only 24 actually useful */
@@ -4056,38 +4097,39 @@ static int floppy_open(struct block_device *bdev, fmode_t mode) · 21 unmodified lines
40564097 }
40574098
40584099 new_dev = MINOR(bdev->bd_dev);
4059− UDRS->fd_device = new_dev;
4100+ drive_state[drive].fd_device = new_dev;
40604101 set_capacity(disks[drive], floppy_sizes[new_dev]);
40614102 if (old_dev != -1 && old_dev != new_dev) {
40624103 if (buffer_drive == drive)
40634104 buffer_track = -1;
40644105 }
40654106
4066− if (UFDCS->rawcmd == 1)
4067− UFDCS->rawcmd = 2;
4107+ if (fdc_state[FDC(drive)].rawcmd == 1)
4108+ fdc_state[FDC(drive)].rawcmd = 2;
40684109
40694110 if (!(mode & FMODE_NDELAY)) {
40704111 if (mode & (FMODE_READ|FMODE_WRITE)) {
4071− UDRS->last_checked = 0;
4072− clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags);
4112+ drive_state[drive].last_checked = 0;
4113+ clear_bit(FD_OPEN_SHOULD_FAIL_BIT,
4114+ &drive_state[drive].flags);
40734115 check_disk_change(bdev);
4074− if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags))
4116+ if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags))
40754117 goto out;
4076− if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags))
4118+ if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags))
40774119 goto out;
40784120 }
40794121 res = -EROFS;
40804122 if ((mode & FMODE_WRITE) &&
4081− !test_bit(FD_DISK_WRITABLE_BIT, &UDRS->flags))
4123+ !test_bit(FD_DISK_WRITABLE_BIT, &drive_state[drive].flags))
40824124 goto out;
40834125 }
40844126 mutex_unlock(&open_lock);
40854127 mutex_unlock(&floppy_mutex);
40864128 return 0;
40874129 out:
4088− UDRS->fd_ref--;
4130+ drive_state[drive].fd_ref--;
40894131
4090− if (!UDRS->fd_ref)
4132+ if (!drive_state[drive].fd_ref)
40914133 opened_bdev[drive] = NULL;
40924134 out2:
40934135 mutex_unlock(&open_lock);
@@ -4103,19 +4145,19 @@ static unsigned int floppy_check_events(struct gendisk *disk, · 9 unmodified lines
41034145 {
41044146 int drive = (long)disk->private_data;
41054147
4106− if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
4107− test_bit(FD_VERIFY_BIT, &UDRS->flags))
4148+ if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
4149+ test_bit(FD_VERIFY_BIT, &drive_state[drive].flags))
41084150 return DISK_EVENT_MEDIA_CHANGE;
41094151
4110− if (time_after(jiffies, UDRS->last_checked + UDP->checkfreq)) {
4152+ if (time_after(jiffies, drive_state[drive].last_checked + drive_params[drive].checkfreq)) {
41114153 if (lock_fdc(drive))
41124154 return 0;
41134155 poll_drive(false, 0);
41144156 process_fd_request();
41154157 }
41164158
4117− if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
4118− test_bit(FD_VERIFY_BIT, &UDRS->flags) ||
4159+ if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
4160+ test_bit(FD_VERIFY_BIT, &drive_state[drive].flags) ||
41194161 test_bit(drive, &fake_change) ||
41204162 drive_no_geom(drive))
41214163 return DISK_EVENT_MEDIA_CHANGE;
@@ -4141,7 +4183,7 @@ static void floppy_rb0_cb(struct bio *bio) · 19 unmodified lines
41414183 if (bio->bi_status) {
41424184 pr_info("floppy: error %d while reading block 0\n",
41434185 bio->bi_status);
4144− set_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags);
4186+ set_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags);
41454187 }
41464188 complete(&cbdata->complete);
41474189 }
@@ -4198,8 +4240,8 @@ static int floppy_revalidate(struct gendisk *disk) · 50 unmodified lines
41984240 int cf;
41994241 int res = 0;
42004242
4201− if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
4202− test_bit(FD_VERIFY_BIT, &UDRS->flags) ||
4243+ if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
4244+ test_bit(FD_VERIFY_BIT, &drive_state[drive].flags) ||
42034245 test_bit(drive, &fake_change) ||
42044246 drive_no_geom(drive)) {
42054247 if (WARN(atomic_read(&usage_count) == 0,
@@ -4209,20 +4251,20 @@ static int floppy_revalidate(struct gendisk *disk) · 3 unmodified lines
42094251 res = lock_fdc(drive);
42104252 if (res)
42114253 return res;
4212− cf = (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
4213− test_bit(FD_VERIFY_BIT, &UDRS->flags));
4254+ cf = (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
4255+ test_bit(FD_VERIFY_BIT, &drive_state[drive].flags));
42144256 if (!(cf || test_bit(drive, &fake_change) || drive_no_geom(drive))) {
42154257 process_fd_request(); /*already done by another thread */
42164258 return 0;
42174259 }
4218− UDRS->maxblock = 0;
4219− UDRS->maxtrack = 0;
4260+ drive_state[drive].maxblock = 0;
4261+ drive_state[drive].maxtrack = 0;
42204262 if (buffer_drive == drive)
42214263 buffer_track = -1;
42224264 clear_bit(drive, &fake_change);
4223− clear_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
4265+ clear_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
42244266 if (cf)
4225− UDRS->generation++;
4267+ drive_state[drive].generation++;
42264268 if (drive_no_geom(drive)) {
42274269 /* auto-sensing */
42284270 res = __floppy_read_block_0(opened_bdev[drive], drive);
@@ -4232,7 +4274,7 @@ static int floppy_revalidate(struct gendisk *disk) · 3 unmodified lines
42324274 process_fd_request();
42334275 }
42344276 }
4235− set_capacity(disk, floppy_sizes[UDRS->fd_device]);
4277+ set_capacity(disk, floppy_sizes[drive_state[drive].fd_device]);
42364278 return res;
42374279 }
42384280
@@ -4261,23 +4303,23 @@ static char __init get_fdc_version(void) · 22 unmodified lines
42614303 int r;
42624304
42634305 output_byte(FD_DUMPREGS); /* 82072 and better know DUMPREGS */
4264− if (FDCS->reset)
4306+ if (fdc_state[current_fdc].reset)
42654307 return FDC_NONE;
42664308 r = result();
42674309 if (r <= 0x00)
42684310 return FDC_NONE; /* No FDC present ??? */
42694311 if ((r == 1) && (reply_buffer[0] == 0x80)) {
4270− pr_info("FDC %d is an 8272A\n", fdc);
4312+ pr_info("FDC %d is an 8272A\n", current_fdc);
42714313 return FDC_8272A; /* 8272a/765 don't know DUMPREGS */
42724314 }
42734315 if (r != 10) {
42744316 pr_info("FDC %d init: DUMPREGS: unexpected return of %d bytes.\n",
4275− fdc, r);
4317+ current_fdc, r);
42764318 return FDC_UNKNOWN;
42774319 }
42784320
42794321 if (!fdc_configure()) {
4280− pr_info("FDC %d is an 82072\n", fdc);
4322+ pr_info("FDC %d is an 82072\n", current_fdc);
42814323 return FDC_82072; /* 82072 doesn't know CONFIGURE */
42824324 }
42834325
@@ -4285,50 +4327,50 @@ static char __init get_fdc_version(void) · 1 unmodified line
42854327 if (need_more_output() == MORE_OUTPUT) {
42864328 output_byte(0);
42874329 } else {
4288− pr_info("FDC %d is an 82072A\n", fdc);
4330+ pr_info("FDC %d is an 82072A\n", current_fdc);
42894331 return FDC_82072A; /* 82072A as found on Sparcs. */
42904332 }
42914333
42924334 output_byte(FD_UNLOCK);
42934335 r = result();
42944336 if ((r == 1) && (reply_buffer[0] == 0x80)) {
4295− pr_info("FDC %d is a pre-1991 82077\n", fdc);
4337+ pr_info("FDC %d is a pre-1991 82077\n", current_fdc);
42964338 return FDC_82077_ORIG; /* Pre-1991 82077, doesn't know
42974339 * LOCK/UNLOCK */
42984340 }
42994341 if ((r != 1) || (reply_buffer[0] != 0x00)) {
43004342 pr_info("FDC %d init: UNLOCK: unexpected return of %d bytes.\n",
4301− fdc, r);
4343+ current_fdc, r);
43024344 return FDC_UNKNOWN;
43034345 }
43044346 output_byte(FD_PARTID);
43054347 r = result();
43064348 if (r != 1) {
43074349 pr_info("FDC %d init: PARTID: unexpected return of %d bytes.\n",
4308− fdc, r);
4350+ current_fdc, r);
43094351 return FDC_UNKNOWN;
43104352 }
43114353 if (reply_buffer[0] == 0x80) {
4312− pr_info("FDC %d is a post-1991 82077\n", fdc);
4354+ pr_info("FDC %d is a post-1991 82077\n", current_fdc);
43134355 return FDC_82077; /* Revised 82077AA passes all the tests */
43144356 }
43154357 switch (reply_buffer[0] >> 5) {
43164358 case 0x0:
43174359 /* Either a 82078-1 or a 82078SL running at 5Volt */
4318− pr_info("FDC %d is an 82078.\n", fdc);
4360+ pr_info("FDC %d is an 82078.\n", current_fdc);
43194361 return FDC_82078;
43204362 case 0x1:
4321− pr_info("FDC %d is a 44pin 82078\n", fdc);
4363+ pr_info("FDC %d is a 44pin 82078\n", current_fdc);
43224364 return FDC_82078;
43234365 case 0x2:
4324− pr_info("FDC %d is a S82078B\n", fdc);
4366+ pr_info("FDC %d is a S82078B\n", current_fdc);
43254367 return FDC_S82078B;
43264368 case 0x3:
4327− pr_info("FDC %d is a National Semiconductor PC87306\n", fdc);
4369+ pr_info("FDC %d is a National Semiconductor PC87306\n", current_fdc);
43284370 return FDC_87306;
43294371 default:
43304372 pr_info("FDC %d init: 82078 variant with unknown PARTID=%d.\n",
4331− fdc, reply_buffer[0] >> 5);
4373+ current_fdc, reply_buffer[0] >> 5);
43324374 return FDC_82078_UNKN;
43334375 }
43344376 } /* get_fdc_version */
@@ -4384,7 +4426,7 @@ static void __init set_cmos(int *ints, int dummy, int dummy2) · 49 unmodified lines
43844426 if (current_drive >= 4 && !FDC2)
43854427 FDC2 = 0x370;
43864428 #endif
4387− DP->cmos = ints[2];
4429+ drive_params[current_drive].cmos = ints[2];
43884430 DPRINT("setting CMOS code to %d\n", ints[2]);
43894431 }
43904432
@@ -4473,7 +4515,7 @@ static ssize_t floppy_cmos_show(struct device *dev, · 82 unmodified lines
44734515 int drive;
44744516
44754517 drive = p->id;
4476− return sprintf(buf, "%X\n", UDP->cmos);
4518+ return sprintf(buf, "%X\n", drive_params[drive].cmos);
44774519 }
44784520
44794521 static DEVICE_ATTR(cmos, 0444, floppy_cmos_show, NULL);
@@ -4494,7 +4536,7 @@ static int floppy_resume(struct device *dev) · 14 unmodified lines
44944536 int fdc;
44954537
44964538 for (fdc = 0; fdc < N_FDC; fdc++)
4497− if (FDCS->address != -1)
4539+ if (fdc_state[fdc].address != -1)
44984540 user_reset_fdc(-1, FD_RESET_ALWAYS, false);
44994541
45004542 return 0;
@@ -4604,16 +4646,16 @@ static int __init do_floppy_init(void) · 103 unmodified lines
46044646 config_types();
46054647
46064648 for (i = 0; i < N_FDC; i++) {
4607− fdc = i;
4608− memset(FDCS, 0, sizeof(*FDCS));
4609− FDCS->dtr = -1;
4610− FDCS->dor = 0x4;
4649+ current_fdc = i;
4650+ memset(&fdc_state[current_fdc], 0, sizeof(*fdc_state));
4651+ fdc_state[current_fdc].dtr = -1;
4652+ fdc_state[current_fdc].dor = 0x4;
46114653 #if defined(__sparc__) || defined(__mc68000__)
46124654 /*sparcs/sun3x don't have a DOR reset which we can fall back on to */
46134655 #ifdef __mc68000__
46144656 if (MACH_IS_SUN3X)
46154657 #endif
4616− FDCS->version = FDC_82072A;
4658+ fdc_state[current_fdc].version = FDC_82072A;
46174659 #endif
46184660 }
46194661
@@ -4628,7 +4670,7 @@ static int __init do_floppy_init(void) · 8 unmodified lines
46284670 fdc_state[1].address = FDC2;
46294671 #endif
46304672
4631− fdc = 0; /* reset fdc in case of unexpected interrupt */
4673+ current_fdc = 0; /* reset fdc in case of unexpected interrupt */
46324674 err = floppy_grab_irq_and_dma();
46334675 if (err) {
46344676 cancel_delayed_work(&fd_timeout);
@@ -4638,12 +4680,12 @@ static int __init do_floppy_init(void) · 3 unmodified lines
46384680
46394681 /* initialise drive state */
46404682 for (drive = 0; drive < N_DRIVE; drive++) {
4641− memset(UDRS, 0, sizeof(*UDRS));
4642− memset(UDRWE, 0, sizeof(*UDRWE));
4643− set_bit(FD_DISK_NEWCHANGE_BIT, &UDRS->flags);
4644− set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
4645− set_bit(FD_VERIFY_BIT, &UDRS->flags);
4646− UDRS->fd_device = -1;
4683+ memset(&drive_state[drive], 0, sizeof(drive_state[drive]));
4684+ memset(&write_errors[drive], 0, sizeof(write_errors[drive]));
4685+ set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[drive].flags);
4686+ set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
4687+ set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
4688+ drive_state[drive].fd_device = -1;
46474689 floppy_track_buffer = NULL;
46484690 max_buffer_sectors = 0;
46494691 }
@@ -4655,29 +4697,30 @@ static int __init do_floppy_init(void) · 5 unmodified lines
46554697 msleep(10);
46564698
46574699 for (i = 0; i < N_FDC; i++) {
4658− fdc = i;
4659− FDCS->driver_version = FD_DRIVER_VERSION;
4700+ current_fdc = i;
4701+ fdc_state[current_fdc].driver_version = FD_DRIVER_VERSION;
46604702 for (unit = 0; unit < 4; unit++)
4661− FDCS->track[unit] = 0;
4662− if (FDCS->address == -1)
4703+ fdc_state[current_fdc].track[unit] = 0;
4704+ if (fdc_state[current_fdc].address == -1)
46634705 continue;
4664− FDCS->rawcmd = 2;
4706+ fdc_state[current_fdc].rawcmd = 2;
46654707 if (user_reset_fdc(-1, FD_RESET_ALWAYS, false)) {
46664708 /* free ioports reserved by floppy_grab_irq_and_dma() */
4667− floppy_release_regions(fdc);
4668− FDCS->address = -1;
4669− FDCS->version = FDC_NONE;
4709+ floppy_release_regions(current_fdc);
4710+ fdc_state[current_fdc].address = -1;
4711+ fdc_state[current_fdc].version = FDC_NONE;
46704712 continue;
46714713 }
46724714 /* Try to determine the floppy controller type */
4673− FDCS->version = get_fdc_version();
4674− if (FDCS->version == FDC_NONE) {
4715+ fdc_state[current_fdc].version = get_fdc_version();
4716+ if (fdc_state[current_fdc].version == FDC_NONE) {
46754717 /* free ioports reserved by floppy_grab_irq_and_dma() */
4676− floppy_release_regions(fdc);
4677− FDCS->address = -1;
4718+ floppy_release_regions(current_fdc);
4719+ fdc_state[current_fdc].address = -1;
46784720 continue;
46794721 }
4680− if (can_use_virtual_dma == 2 && FDCS->version < FDC_82072A)
4722+ if (can_use_virtual_dma == 2 &&
4723+ fdc_state[current_fdc].version < FDC_82072A)
46814724 can_use_virtual_dma = 0;
46824725
46834726 have_no_fdc = 0;
@@ -4687,7 +4730,7 @@ static int __init do_floppy_init(void) · 3 unmodified lines
46874730 */
46884731 user_reset_fdc(-1, FD_RESET_ALWAYS, false);
46894732 }
4690− fdc = 0;
4733+ current_fdc = 0;
46914734 cancel_delayed_work(&fd_timeout);
46924735 current_drive = 0;
46934736 initialized = true;
@@ -4783,7 +4826,7 @@ static void floppy_release_allocated_regions(int fdc, const struct io_region *p) · 89 unmodified lines
47834826 {
47844827 while (p != io_regions) {
47854828 p--;
4786− release_region(FDCS->address + p->offset, p->size);
4829+ release_region(fdc_state[fdc].address + p->offset, p->size);
47874830 }
47884831 }
47894832
@@ -4794,10 +4837,10 @@ static int floppy_request_regions(int fdc) · 4 unmodified lines
47944837 const struct io_region *p;
47954838
47964839 for (p = io_regions; p < ARRAY_END(io_regions); p++) {
4797− if (!request_region(FDCS->address + p->offset,
4840+ if (!request_region(fdc_state[fdc].address + p->offset,
47984841 p->size, "floppy")) {
47994842 DPRINT("Floppy io-port 0x%04lx in use\n",
4800− FDCS->address + p->offset);
4843+ fdc_state[fdc].address + p->offset);
48014844 floppy_release_allocated_regions(fdc, p);
48024845 return -EBUSY;
48034846 }
@@ -4839,36 +4882,36 @@ static int floppy_grab_irq_and_dma(void) · 35 unmodified lines
48394882 }
48404883 }
48414884
4842− for (fdc = 0; fdc < N_FDC; fdc++) {
4843− if (FDCS->address != -1) {
4844− if (floppy_request_regions(fdc))
4885+ for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) {
4886+ if (fdc_state[current_fdc].address != -1) {
4887+ if (floppy_request_regions(current_fdc))
48454888 goto cleanup;
48464889 }
48474890 }
4848− for (fdc = 0; fdc < N_FDC; fdc++) {
4849− if (FDCS->address != -1) {
4891+ for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) {
4892+ if (fdc_state[current_fdc].address != -1) {
48504893 reset_fdc_info(1);
4851− fd_outb(FDCS->dor, FD_DOR);
4894+ fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR);
48524895 }
48534896 }
4854− fdc = 0;
4897+ current_fdc = 0;
48554898 set_dor(0, ~0, 8); /* avoid immediate interrupt */
48564899
4857− for (fdc = 0; fdc < N_FDC; fdc++)
4858− if (FDCS->address != -1)
4859− fd_outb(FDCS->dor, FD_DOR);
4900+ for (current_fdc = 0; current_fdc < N_FDC; current_fdc++)
4901+ if (fdc_state[current_fdc].address != -1)
4902+ fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR);
48604903 /*
48614904 * The driver will try and free resources and relies on us
48624905 * to know if they were allocated or not.
48634906 */
4864− fdc = 0;
4907+ current_fdc = 0;
48654908 irqdma_allocated = 1;
48664909 return 0;
48674910 cleanup:
48684911 fd_free_irq();
48694912 fd_free_dma();
4870− while (--fdc >= 0)
4871− floppy_release_regions(fdc);
4913+ while (--current_fdc >= 0)
4914+ floppy_release_regions(current_fdc);
48724915 atomic_dec(&usage_count);
48734916 return -1;
48744917 }
@@ -4916,11 +4959,11 @@ static void floppy_release_irq_and_dma(void) · 41 unmodified lines
49164959 pr_info("auxiliary floppy timer still active\n");
49174960 if (work_pending(&floppy_work))
49184961 pr_info("work still pending\n");
4919− old_fdc = fdc;
4920− for (fdc = 0; fdc < N_FDC; fdc++)
4921− if (FDCS->address != -1)
4922− floppy_release_regions(fdc);
4923− fdc = old_fdc;
4962+ old_fdc = current_fdc;
4963+ for (current_fdc = 0; current_fdc < N_FDC; current_fdc++)
4964+ if (fdc_state[current_fdc].address != -1)
4965+ floppy_release_regions(current_fdc);
4966+ current_fdc = old_fdc;
49244967 }
49254968
49264969 #ifdef MODULE
drivers/block/loop.c+10−8
@@ -214,7 +214,8 @@ static void __loop_update_dio(struct loop_device *lo, bool dio) · 213 unmodified lines
214214 * LO_FLAGS_READ_ONLY, both are set from kernel, and losetup
215215 * will get updated by ioctl(LOOP_GET_STATUS)
216216 */
217− blk_mq_freeze_queue(lo->lo_queue);
217+ if (lo->lo_state == Lo_bound)
218+ blk_mq_freeze_queue(lo->lo_queue);
218219 lo->use_dio = use_dio;
219220 if (use_dio) {
220221 blk_queue_flag_clear(QUEUE_FLAG_NOMERGES, lo->lo_queue);
@@ -223,7 +224,8 @@ static void __loop_update_dio(struct loop_device *lo, bool dio) · 2 unmodified lines
223224 blk_queue_flag_set(QUEUE_FLAG_NOMERGES, lo->lo_queue);
224225 lo->lo_flags &= ~LO_FLAGS_DIRECT_IO;
225226 }
226− blk_mq_unfreeze_queue(lo->lo_queue);
227+ if (lo->lo_state == Lo_bound)
228+ blk_mq_unfreeze_queue(lo->lo_queue);
227229 }
228230
229231 static int
@@ -1539,16 +1541,16 @@ static int loop_set_block_size(struct loop_device *lo, unsigned long arg) · 1309 unmodified lines
15391541 if (arg < 512 || arg > PAGE_SIZE || !is_power_of_2(arg))
15401542 return -EINVAL;
15411543
1542− if (lo->lo_queue->limits.logical_block_size != arg) {
1543− sync_blockdev(lo->lo_device);
1544− kill_bdev(lo->lo_device);
1545− }
1544+ if (lo->lo_queue->limits.logical_block_size == arg)
1545+ return 0;
1546+
1547+ sync_blockdev(lo->lo_device);
1548+ kill_bdev(lo->lo_device);
15461549
15471550 blk_mq_freeze_queue(lo->lo_queue);
15481551
15491552 /* kill_bdev should have truncated all the pages */
1550− if (lo->lo_queue->limits.logical_block_size != arg &&
1551− lo->lo_device->bd_inode->i_mapping->nrpages) {
1553+ if (lo->lo_device->bd_inode->i_mapping->nrpages) {
15521554 err = -EAGAIN;
15531555 pr_warn("%s: loop%d (%s) has still dirty pages (nrpages=%lu)\n",
15541556 __func__, lo->lo_number, lo->lo_file_name,
drivers/block/nbd.c+19−8
@@ -395,16 +395,19 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req, · 394 unmodified lines
395395 }
396396 config = nbd->config;
397397
398− if (config->num_connections > 1) {
398+ if (config->num_connections > 1 ||
399+ (config->num_connections == 1 && nbd->tag_set.timeout)) {
399400 dev_err_ratelimited(nbd_to_dev(nbd),
400401 "Connection timed out, retrying (%d/%d alive)\n",
401402 atomic_read(&config->live_connections),
402403 config->num_connections);
403404 /*
404405 * 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.
406409 */
407− if (config->socks && config->num_connections > 1) {
410+ if (config->socks) {
408411 if (cmd->index < config->num_connections) {
409412 struct nbd_sock *nsock =
410413 config->socks[cmd->index];
@@ -431,12 +434,22 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req, · 20 unmodified lines
431434 * Userspace sets timeout=0 to disable socket disconnection,
432435 * so just warn and reset the timer.
433436 */
437+ struct nbd_sock *nsock = config->socks[cmd->index];
434438 cmd->retries++;
435439 dev_info(nbd_to_dev(nbd), "Possible stuck request %p: control (%s@%llu,%uB). Runtime %u seconds\n",
436440 req, nbdcmd_to_ascii(req_to_nbd_cmd_type(req)),
437441 (unsigned long long)blk_rq_pos(req) << 9,
438442 blk_rq_bytes(req), (req->timeout / HZ) * cmd->retries);
439443
444+ mutex_lock(&nsock->tx_lock);
445+ if (cmd->cookie != nsock->cookie) {
446+ nbd_requeue_cmd(cmd);
447+ mutex_unlock(&nsock->tx_lock);
448+ mutex_unlock(&cmd->lock);
449+ nbd_config_put(nbd);
450+ return BLK_EH_DONE;
451+ }
452+ mutex_unlock(&nsock->tx_lock);
440453 mutex_unlock(&cmd->lock);
441454 nbd_config_put(nbd);
442455 return BLK_EH_RESET_TIMER;
@@ -741,14 +754,12 @@ static struct nbd_cmd *nbd_read_stat(struct nbd_device *nbd, int index) · 298 unmodified lines
741754 dev_err(disk_to_dev(nbd->disk), "Receive data failed (result %d)\n",
742755 result);
743756 /*
744− * If we've disconnected or we only have 1
745− * connection then we need to make sure we
757+ * If we've disconnected, we need to make sure we
746758 * complete this request, otherwise error out
747759 * and let the timeout stuff handle resubmitting
748760 * this request onto another connection.
749761 */
750− if (nbd_disconnected(config) ||
751− config->num_connections <= 1) {
762+ if (nbd_disconnected(config)) {
752763 cmd->status = BLK_STS_IOERR;
753764 goto out;
754765 }
@@ -825,7 +836,7 @@ static int find_fallback(struct nbd_device *nbd, int index) · 70 unmodified lines
825836
826837 if (config->num_connections <= 1) {
827838 dev_err_ratelimited(disk_to_dev(nbd->disk),
828− "Attempted send on invalid socket\n");
839+ "Dead connection, failed to find a fallback\n");
829840 return new_index;
830841 }
831842
drivers/block/null_blk_main.c+9−0
@@ -97,14 +97,21 @@ module_param_named(home_node, g_home_node, int, 0444); · 96 unmodified lines
9797 MODULE_PARM_DESC(home_node, "Home node for the device");
9898
9999 #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+ */
100104 static char g_timeout_str[80];
101105 module_param_string(timeout, g_timeout_str, sizeof(g_timeout_str), 0444);
106+MODULE_PARM_DESC(timeout, "Fault injection. timeout=<interval>,<probability>,<space>,<times>");
102107
103108 static char g_requeue_str[80];
104109 module_param_string(requeue, g_requeue_str, sizeof(g_requeue_str), 0444);
110+MODULE_PARM_DESC(requeue, "Fault injection. requeue=<interval>,<probability>,<space>,<times>");
105111
106112 static char g_init_hctx_str[80];
107113 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>");
108115 #endif
109116
110117 static int g_queue_mode = NULL_Q_MQ;
@@ -615,6 +622,7 @@ static struct nullb_cmd *__alloc_cmd(struct nullb_queue *nq) · 504 unmodified lines
615622 if (tag != -1U) {
616623 cmd = &nq->cmds[tag];
617624 cmd->tag = tag;
625+ cmd->error = BLK_STS_OK;
618626 cmd->nq = nq;
619627 if (nq->dev->irqmode == NULL_IRQ_TIMER) {
620628 hrtimer_init(&cmd->timer, CLOCK_MONOTONIC,
@@ -1395,6 +1403,7 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx, · 774 unmodified lines
13951403 cmd->timer.function = null_cmd_timer_expired;
13961404 }
13971405 cmd->rq = bd->rq;
1406+ cmd->error = BLK_STS_OK;
13981407 cmd->nq = nq;
13991408
14001409 blk_mq_start_request(bd->rq);
drivers/block/null_blk_trace.c+21−0
@@ -0,0 +1,21 @@
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+}
drivers/block/null_blk_trace.h+79−0
@@ -0,0 +1,79 @@
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>
drivers/block/null_blk_zoned.c+11−1
@@ -2,6 +2,9 @@ · 1 unmodified line
22 #include <linux/vmalloc.h>
33 #include "null_blk.h"
44
5+#define CREATE_TRACE_POINTS
6+#include "null_blk_trace.h"
7+
58 /* zone_size in MBs to sectors. */
69 #define ZONE_SIZE_SHIFT 11
710
@@ -80,6 +83,8 @@ int null_report_zones(struct gendisk *disk, sector_t sector, · 72 unmodified lines
8083 return 0;
8184
8285 nr_zones = min(nr_zones, dev->nr_zones - first_zone);
86+ trace_nullb_report_zones(nullb, nr_zones);
87+
8388 for (i = 0; i < nr_zones; i++) {
8489 /*
8590 * Stacked DM target drivers will remap the zone information by
@@ -148,6 +153,8 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector, · 62 unmodified lines
148153 /* Invalid zone condition */
149154 return BLK_STS_IOERR;
150155 }
156+
157+ trace_nullb_zone_op(cmd, zno, zone->cond);
151158 return BLK_STS_OK;
152159 }
153160
@@ -155,7 +162,8 @@ static blk_status_t null_zone_mgmt(struct nullb_cmd *cmd, enum req_opf op, · 1 unmodified line
155162 sector_t sector)
156163 {
157164 struct nullb_device *dev = cmd->nq->dev;
158− struct blk_zone *zone = &dev->zones[null_zone_no(dev, sector)];
165+ unsigned int zone_no = null_zone_no(dev, sector);
166+ struct blk_zone *zone = &dev->zones[zone_no];
159167 size_t i;
160168
161169 switch (op) {
@@ -203,6 +211,8 @@ static blk_status_t null_zone_mgmt(struct nullb_cmd *cmd, enum req_opf op, · 41 unmodified lines
203211 default:
204212 return BLK_STS_NOTSUPP;
205213 }
214+
215+ trace_nullb_zone_op(cmd, zone_no, zone->cond);
206216 return BLK_STS_OK;
207217 }
208218
drivers/block/rsxx/dma.c+1−1
@@ -80,7 +80,7 @@ struct dma_tracker { · 79 unmodified lines
8080 struct dma_tracker_list {
8181 spinlock_t lock;
8282 int head;
83− struct dma_tracker list[0];
83+ struct dma_tracker list[];
8484 };
8585
8686
drivers/lightnvm/pblk-sysfs.c+21−21
@@ -37,7 +37,7 @@ static ssize_t pblk_sysfs_luns_show(struct pblk *pblk, char *page) · 36 unmodified lines
3737 active = 0;
3838 up(&rlun->wr_sem);
3939 }
40− sz += snprintf(page + sz, PAGE_SIZE - sz,
40+ sz += scnprintf(page + sz, PAGE_SIZE - sz,
4141 "pblk: pos:%d, ch:%d, lun:%d - %d\n",
4242 i,
4343 rlun->bppa.a.ch,
@@ -120,7 +120,7 @@ static ssize_t pblk_sysfs_ppaf(struct pblk *pblk, char *page) · 76 unmodified lines
120120 struct nvm_addrf_12 *ppaf = (struct nvm_addrf_12 *)&pblk->addrf;
121121 struct nvm_addrf_12 *gppaf = (struct nvm_addrf_12 *)&geo->addrf;
122122
123− sz = snprintf(page, PAGE_SIZE,
123+ sz = scnprintf(page, PAGE_SIZE,
124124 "g:(b:%d)blk:%d/%d,pg:%d/%d,lun:%d/%d,ch:%d/%d,pl:%d/%d,sec:%d/%d\n",
125125 pblk->addrf_len,
126126 ppaf->blk_offset, ppaf->blk_len,
@@ -130,7 +130,7 @@ static ssize_t pblk_sysfs_ppaf(struct pblk *pblk, char *page) · 3 unmodified lines
130130 ppaf->pln_offset, ppaf->pln_len,
131131 ppaf->sec_offset, ppaf->sec_len);
132132
133− sz += snprintf(page + sz, PAGE_SIZE - sz,
133+ sz += scnprintf(page + sz, PAGE_SIZE - sz,
134134 "d:blk:%d/%d,pg:%d/%d,lun:%d/%d,ch:%d/%d,pl:%d/%d,sec:%d/%d\n",
135135 gppaf->blk_offset, gppaf->blk_len,
136136 gppaf->pg_offset, gppaf->pg_len,
@@ -142,7 +142,7 @@ static ssize_t pblk_sysfs_ppaf(struct pblk *pblk, char *page) · 5 unmodified lines
142142 struct nvm_addrf *ppaf = &pblk->addrf;
143143 struct nvm_addrf *gppaf = &geo->addrf;
144144
145− sz = snprintf(page, PAGE_SIZE,
145+ sz = scnprintf(page, PAGE_SIZE,
146146 "pblk:(s:%d)ch:%d/%d,lun:%d/%d,chk:%d/%d/sec:%d/%d\n",
147147 pblk->addrf_len,
148148 ppaf->ch_offset, ppaf->ch_len,
@@ -150,7 +150,7 @@ static ssize_t pblk_sysfs_ppaf(struct pblk *pblk, char *page) · 1 unmodified line
150150 ppaf->chk_offset, ppaf->chk_len,
151151 ppaf->sec_offset, ppaf->sec_len);
152152
153− sz += snprintf(page + sz, PAGE_SIZE - sz,
153+ sz += scnprintf(page + sz, PAGE_SIZE - sz,
154154 "device:ch:%d/%d,lun:%d/%d,chk:%d/%d,sec:%d/%d\n",
155155 gppaf->ch_offset, gppaf->ch_len,
156156 gppaf->lun_offset, gppaf->lun_len,
@@ -278,11 +278,11 @@ static ssize_t pblk_sysfs_lines(struct pblk *pblk, char *page) · 121 unmodified lines
278278 pblk_err(pblk, "corrupted free line list:%d/%d\n",
279279 nr_free_lines, free_line_cnt);
280280
281− sz = snprintf(page, PAGE_SIZE - sz,
281+ sz = scnprintf(page, PAGE_SIZE - sz,
282282 "line: nluns:%d, nblks:%d, nsecs:%d\n",
283283 geo->all_luns, lm->blk_per_line, lm->sec_per_line);
284284
285− sz += snprintf(page + sz, PAGE_SIZE - sz,
285+ sz += scnprintf(page + sz, PAGE_SIZE - sz,
286286 "lines:d:%d,l:%d-f:%d,m:%d/%d,c:%d,b:%d,co:%d(d:%d,l:%d)t:%d\n",
287287 cur_data, cur_log,
288288 nr_free_lines,
@@ -292,12 +292,12 @@ static ssize_t pblk_sysfs_lines(struct pblk *pblk, char *page) · 3 unmodified lines
292292 d_line_cnt, l_line_cnt,
293293 l_mg->nr_lines);
294294
295− sz += snprintf(page + sz, PAGE_SIZE - sz,
295+ sz += scnprintf(page + sz, PAGE_SIZE - sz,
296296 "GC: full:%d, high:%d, mid:%d, low:%d, empty:%d, werr: %d, queue:%d\n",
297297 gc_full, gc_high, gc_mid, gc_low, gc_empty, gc_werr,
298298 atomic_read(&pblk->gc.read_inflight_gc));
299299
300− sz += snprintf(page + sz, PAGE_SIZE - sz,
300+ sz += scnprintf(page + sz, PAGE_SIZE - sz,
301301 "data (%d) cur:%d, left:%d, vsc:%d, s:%d, map:%d/%d (%d)\n",
302302 cur_data, cur_sec, msecs, vsc, sec_in_line,
303303 map_weight, lm->sec_per_line,
@@ -313,19 +313,19 @@ static ssize_t pblk_sysfs_lines_info(struct pblk *pblk, char *page) · 9 unmodified lines
313313 struct pblk_line_meta *lm = &pblk->lm;
314314 ssize_t sz = 0;
315315
316− sz = snprintf(page, PAGE_SIZE - sz,
316+ sz = scnprintf(page, PAGE_SIZE - sz,
317317 "smeta - len:%d, secs:%d\n",
318318 lm->smeta_len, lm->smeta_sec);
319− sz += snprintf(page + sz, PAGE_SIZE - sz,
319+ sz += scnprintf(page + sz, PAGE_SIZE - sz,
320320 "emeta - len:%d, sec:%d, bb_start:%d\n",
321321 lm->emeta_len[0], lm->emeta_sec[0],
322322 lm->emeta_bb);
323− sz += snprintf(page + sz, PAGE_SIZE - sz,
323+ sz += scnprintf(page + sz, PAGE_SIZE - sz,
324324 "bitmap lengths: sec:%d, blk:%d, lun:%d\n",
325325 lm->sec_bitmap_len,
326326 lm->blk_bitmap_len,
327327 lm->lun_bitmap_len);
328− sz += snprintf(page + sz, PAGE_SIZE - sz,
328+ sz += scnprintf(page + sz, PAGE_SIZE - sz,
329329 "blk_line:%d, sec_line:%d, sec_blk:%d\n",
330330 lm->blk_per_line,
331331 lm->sec_per_line,
@@ -344,12 +344,12 @@ static ssize_t pblk_get_write_amp(u64 user, u64 gc, u64 pad, · 12 unmodified lines
344344 {
345345 int sz;
346346
347− sz = snprintf(page, PAGE_SIZE,
347+ sz = scnprintf(page, PAGE_SIZE,
348348 "user:%lld gc:%lld pad:%lld WA:",
349349 user, gc, pad);
350350
351351 if (!user) {
352− sz += snprintf(page + sz, PAGE_SIZE - sz, "NaN\n");
352+ sz += scnprintf(page + sz, PAGE_SIZE - sz, "NaN\n");
353353 } else {
354354 u64 wa_int;
355355 u32 wa_frac;
@@ -358,7 +358,7 @@ static ssize_t pblk_get_write_amp(u64 user, u64 gc, u64 pad, · 2 unmodified lines
358358 wa_int = div64_u64(wa_int, user);
359359 wa_int = div_u64_rem(wa_int, 100000, &wa_frac);
360360
361− sz += snprintf(page + sz, PAGE_SIZE - sz, "%llu.%05u\n",
361+ sz += scnprintf(page + sz, PAGE_SIZE - sz, "%llu.%05u\n",
362362 wa_int, wa_frac);
363363 }
364364
@@ -401,9 +401,9 @@ static ssize_t pblk_sysfs_get_padding_dist(struct pblk *pblk, char *page) · 36 unmodified lines
401401 total = atomic64_read(&pblk->nr_flush) - pblk->nr_flush_rst;
402402 if (!total) {
403403 for (i = 0; i < (buckets + 1); i++)
404− sz += snprintf(page + sz, PAGE_SIZE - sz,
404+ sz += scnprintf(page + sz, PAGE_SIZE - sz,
405405 "%d:0 ", i);
406− sz += snprintf(page + sz, PAGE_SIZE - sz, "\n");
406+ sz += scnprintf(page + sz, PAGE_SIZE - sz, "\n");
407407
408408 return sz;
409409 }
@@ -411,7 +411,7 @@ static ssize_t pblk_sysfs_get_padding_dist(struct pblk *pblk, char *page) · 1 unmodified line
411411 for (i = 0; i < buckets; i++)
412412 total_buckets += atomic64_read(&pblk->pad_dist[i]);
413413
414− sz += snprintf(page + sz, PAGE_SIZE - sz, "0:%lld%% ",
414+ sz += scnprintf(page + sz, PAGE_SIZE - sz, "0:%lld%% ",
415415 bucket_percentage(total - total_buckets, total));
416416
417417 for (i = 0; i < buckets; i++) {
@@ -419,10 +419,10 @@ static ssize_t pblk_sysfs_get_padding_dist(struct pblk *pblk, char *page) · 1 unmodified line
419419
420420 p = bucket_percentage(atomic64_read(&pblk->pad_dist[i]),
421421 total);
422− sz += snprintf(page + sz, PAGE_SIZE - sz, "%d:%lld%% ",
422+ sz += scnprintf(page + sz, PAGE_SIZE - sz, "%d:%lld%% ",
423423 i + 1, p);
424424 }
425− sz += snprintf(page + sz, PAGE_SIZE - sz, "\n");
425+ sz += scnprintf(page + sz, PAGE_SIZE - sz, "\n");
426426
427427 return sz;
428428 }
drivers/md/bcache/btree.c+174−68
@@ -101,64 +101,6 @@ · 100 unmodified lines
101101
102102 #define insert_lock(s, b) ((b)->level <= (s)->lock)
103103
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−})
162104
163105 static inline struct bset *write_block(struct btree *b)
164106 {
@@ -1848,7 +1790,7 @@ static void bch_btree_gc(struct cache_set *c) · 1683 unmodified lines
18481790
18491791 /* if CACHE_SET_IO_DISABLE set, gc thread should stop too */
18501792 do {
1851− ret = btree_root(gc_root, c, &op, &writes, &stats);
1793+ ret = bcache_btree_root(gc_root, c, &op, &writes, &stats);
18521794 closure_sync(&writes);
18531795 cond_resched();
18541796
@@ -1946,7 +1888,7 @@ static int bch_btree_check_recurse(struct btree *b, struct btree_op *op) · 91 unmodified lines
19461888 }
19471889
19481890 if (p)
1949− ret = btree(check_recurse, p, b, op);
1891+ ret = bcache_btree(check_recurse, p, b, op);
19501892
19511893 p = k;
19521894 } while (p && !ret);
@@ -1955,13 +1897,176 @@ static int bch_btree_check_recurse(struct btree *b, struct btree_op *op) · 2 unmodified lines
19551897 return ret;
19561898 }
19571899
1900+
1901+static int bch_btree_check_thread(void *arg)
1902+{
1903+ int ret;
1904+ struct btree_check_info *info = arg;
1905+ struct btree_check_state *check_state = info->state;
1906+ struct cache_set *c = check_state->c;
1907+ struct btree_iter iter;
1908+ struct bkey *k, *p;
1909+ int cur_idx, prev_idx, skip_nr;
1910+ int i, n;
1911+
1912+ k = p = NULL;
1913+ i = n = 0;
1914+ cur_idx = prev_idx = 0;
1915+ ret = 0;
1916+
1917+ /* root node keys are checked before thread created */
1918+ bch_btree_iter_init(&c->root->keys, &iter, NULL);
1919+ k = bch_btree_iter_next_filter(&iter, &c->root->keys, bch_ptr_bad);
1920+ BUG_ON(!k);
1921+
1922+ p = k;
1923+ while (k) {
1924+ /*
1925+ * Fetch a root node key index, skip the keys which
1926+ * should be fetched by other threads, then check the
1927+ * sub-tree indexed by the fetched key.
1928+ */
1929+ spin_lock(&check_state->idx_lock);
1930+ cur_idx = check_state->key_idx;
1931+ check_state->key_idx++;
1932+ spin_unlock(&check_state->idx_lock);
1933+
1934+ skip_nr = cur_idx - prev_idx;
1935+
1936+ while (skip_nr) {
1937+ k = bch_btree_iter_next_filter(&iter,
1938+ &c->root->keys,
1939+ bch_ptr_bad);
1940+ if (k)
1941+ p = k;
1942+ else {
1943+ /*
1944+ * No more keys to check in root node,
1945+ * current checking threads are enough,
1946+ * stop creating more.
1947+ */
1948+ atomic_set(&check_state->enough, 1);
1949+ /* Update check_state->enough earlier */
1950+ smp_mb__after_atomic();
1951+ goto out;
1952+ }
1953+ skip_nr--;
1954+ cond_resched();
1955+ }
1956+
1957+ if (p) {
1958+ struct btree_op op;
1959+
1960+ btree_node_prefetch(c->root, p);
1961+ c->gc_stats.nodes++;
1962+ bch_btree_op_init(&op, 0);
1963+ ret = bcache_btree(check_recurse, p, c->root, &op);
1964+ if (ret)
1965+ goto out;
1966+ }
1967+ p = NULL;
1968+ prev_idx = cur_idx;
1969+ cond_resched();
1970+ }
1971+
1972+out:
1973+ info->result = ret;
1974+ /* update check_state->started among all CPUs */
1975+ smp_mb__before_atomic();
1976+ if (atomic_dec_and_test(&check_state->started))
1977+ wake_up(&check_state->wait);
1978+
1979+ return ret;
1980+}
1981+
1982+
1983+
1984+static int bch_btree_chkthread_nr(void)
1985+{
1986+ int n = num_online_cpus()/2;
1987+
1988+ if (n == 0)
1989+ n = 1;
1990+ else if (n > BCH_BTR_CHKTHREAD_MAX)
1991+ n = BCH_BTR_CHKTHREAD_MAX;
1992+
1993+ return n;
1994+}
1995+
19581996 int bch_btree_check(struct cache_set *c)
19591997 {
1960− struct btree_op op;
1998+ int ret = 0;
1999+ int i;
2000+ struct bkey *k = NULL;
2001+ struct btree_iter iter;
2002+ struct btree_check_state *check_state;
2003+ char name[32];
19612004
1962− bch_btree_op_init(&op, SHRT_MAX);
2005+ /* check and mark root node keys */
2006+ for_each_key_filter(&c->root->keys, k, &iter, bch_ptr_invalid)
2007+ bch_initial_mark_key(c, c->root->level, k);
2008+
2009+ bch_initial_mark_key(c, c->root->level + 1, &c->root->key);
2010+
2011+ if (c->root->level == 0)
2012+ return 0;
2013+
2014+ check_state = kzalloc(sizeof(struct btree_check_state), GFP_KERNEL);
2015+ if (!check_state)
2016+ return -ENOMEM;
19632017
1964− return btree_root(check_recurse, c, &op);
2018+ check_state->c = c;
2019+ check_state->total_threads = bch_btree_chkthread_nr();
2020+ check_state->key_idx = 0;
2021+ spin_lock_init(&check_state->idx_lock);
2022+ atomic_set(&check_state->started, 0);
2023+ atomic_set(&check_state->enough, 0);
2024+ init_waitqueue_head(&check_state->wait);
2025+
2026+ /*
2027+ * Run multiple threads to check btree nodes in parallel,
2028+ * if check_state->enough is non-zero, it means current
2029+ * running check threads are enough, unncessary to create
2030+ * more.
2031+ */
2032+ for (i = 0; i < check_state->total_threads; i++) {
2033+ /* fetch latest check_state->enough earlier */
2034+ smp_mb__before_atomic();
2035+ if (atomic_read(&check_state->enough))
2036+ break;
2037+
2038+ check_state->infos[i].result = 0;
2039+ check_state->infos[i].state = check_state;
2040+ snprintf(name, sizeof(name), "bch_btrchk[%u]", i);
2041+ atomic_inc(&check_state->started);
2042+
2043+ check_state->infos[i].thread =
2044+ kthread_run(bch_btree_check_thread,
2045+ &check_state->infos[i],
2046+ name);
2047+ if (IS_ERR(check_state->infos[i].thread)) {
2048+ pr_err("fails to run thread bch_btrchk[%d]", i);
2049+ for (--i; i >= 0; i--)
2050+ kthread_stop(check_state->infos[i].thread);
2051+ ret = -ENOMEM;
2052+ goto out;
2053+ }
2054+ }
2055+
2056+ wait_event_interruptible(check_state->wait,
2057+ atomic_read(&check_state->started) == 0 ||
2058+ test_bit(CACHE_SET_IO_DISABLE, &c->flags));
2059+
2060+ for (i = 0; i < check_state->total_threads; i++) {
2061+ if (check_state->infos[i].result) {
2062+ ret = check_state->infos[i].result;
2063+ goto out;
2064+ }
2065+ }
2066+
2067+out:
2068+ kfree(check_state);
2069+ return ret;
19652070 }
19662071
19672072 void bch_initial_gc_finish(struct cache_set *c)
@@ -2401,7 +2506,7 @@ static int bch_btree_map_nodes_recurse(struct btree *b, struct btree_op *op, · 433 unmodified lines
24012506
24022507 while ((k = bch_btree_iter_next_filter(&iter, &b->keys,
24032508 bch_ptr_bad))) {
2404− ret = btree(map_nodes_recurse, k, b,
2509+ ret = bcache_btree(map_nodes_recurse, k, b,
24052510 op, from, fn, flags);
24062511 from = NULL;
24072512
@@ -2419,10 +2524,10 @@ static int bch_btree_map_nodes_recurse(struct btree *b, struct btree_op *op, · 11 unmodified lines
24192524 int __bch_btree_map_nodes(struct btree_op *op, struct cache_set *c,
24202525 struct bkey *from, btree_map_nodes_fn *fn, int flags)
24212526 {
2422− return btree_root(map_nodes_recurse, c, op, from, fn, flags);
2527+ return bcache_btree_root(map_nodes_recurse, c, op, from, fn, flags);
24232528 }
24242529
2425−static int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op,
2530+int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op,
24262531 struct bkey *from, btree_map_keys_fn *fn,
24272532 int flags)
24282533 {
@@ -2435,7 +2540,8 @@ static int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op, · 6 unmodified lines
24352540 while ((k = bch_btree_iter_next_filter(&iter, &b->keys, bch_ptr_bad))) {
24362541 ret = !b->level
24372542 ? fn(op, b, k)
2438− : btree(map_keys_recurse, k, b, op, from, fn, flags);
2543+ : bcache_btree(map_keys_recurse, k,
2544+ b, op, from, fn, flags);
24392545 from = NULL;
24402546
24412547 if (ret != MAP_CONTINUE)
@@ -2452,7 +2558,7 @@ static int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op, · 10 unmodified lines
24522558 int bch_btree_map_keys(struct btree_op *op, struct cache_set *c,
24532559 struct bkey *from, btree_map_keys_fn *fn, int flags)
24542560 {
2455− return btree_root(map_keys_recurse, c, op, from, fn, flags);
2561+ return bcache_btree_root(map_keys_recurse, c, op, from, fn, flags);
24562562 }
24572563
24582564 /* Keybuf code */
drivers/md/bcache/btree.h+84−0
@@ -145,6 +145,9 @@ struct btree { · 144 unmodified lines
145145 struct bio *bio;
146146 };
147147
148+
149+
150+
148151 #define BTREE_FLAG(flag) \
149152 static inline bool btree_node_ ## flag(struct btree *b) \
150153 { return test_bit(BTREE_NODE_ ## flag, &b->flags); } \
@@ -216,6 +219,25 @@ struct btree_op { · 65 unmodified lines
216219 unsigned int insert_collision:1;
217220 };
218221
222+struct btree_check_state;
223+struct btree_check_info {
224+ struct btree_check_state *state;
225+ struct task_struct *thread;
226+ int result;
227+};
228+
229+#define BCH_BTR_CHKTHREAD_MAX 64
230+struct btree_check_state {
231+ struct cache_set *c;
232+ int total_threads;
233+ int key_idx;
234+ spinlock_t idx_lock;
235+ atomic_t started;
236+ atomic_t enough;
237+ wait_queue_head_t wait;
238+ struct btree_check_info infos[BCH_BTR_CHKTHREAD_MAX];
239+};
240+
219241 static inline void bch_btree_op_init(struct btree_op *op, int write_lock_level)
220242 {
221243 memset(op, 0, sizeof(struct btree_op));
@@ -284,6 +306,65 @@ static inline void force_wake_up_gc(struct cache_set *c) · 62 unmodified lines
284306 wake_up_gc(c);
285307 }
286308
309+/*
310+ * These macros are for recursing down the btree - they handle the details of
311+ * locking and looking up nodes in the cache for you. They're best treated as
312+ * mere syntax when reading code that uses them.
313+ *
314+ * op->lock determines whether we take a read or a write lock at a given depth.
315+ * If you've got a read lock and find that you need a write lock (i.e. you're
316+ * going to have to split), set op->lock and return -EINTR; btree_root() will
317+ * call you again and you'll have the correct lock.
318+ */
319+
320+/**
321+ * btree - recurse down the btree on a specified key
322+ * @fn: function to call, which will be passed the child node
323+ * @key: key to recurse on
324+ * @b: parent btree node
325+ * @op: pointer to struct btree_op
326+ */
327+#define bcache_btree(fn, key, b, op, ...) \
328+({ \
329+ int _r, l = (b)->level - 1; \
330+ bool _w = l <= (op)->lock; \
331+ struct btree *_child = bch_btree_node_get((b)->c, op, key, l, \
332+ _w, b); \
333+ if (!IS_ERR(_child)) { \
334+ _r = bch_btree_ ## fn(_child, op, ##__VA_ARGS__); \
335+ rw_unlock(_w, _child); \
336+ } else \
337+ _r = PTR_ERR(_child); \
338+ _r; \
339+})
340+
341+/**
342+ * btree_root - call a function on the root of the btree
343+ * @fn: function to call, which will be passed the child node
344+ * @c: cache set
345+ * @op: pointer to struct btree_op
346+ */
347+#define bcache_btree_root(fn, c, op, ...) \
348+({ \
349+ int _r = -EINTR; \
350+ do { \
351+ struct btree *_b = (c)->root; \
352+ bool _w = insert_lock(op, _b); \
353+ rw_lock(_w, _b, _b->level); \
354+ if (_b == (c)->root && \
355+ _w == insert_lock(op, _b)) { \
356+ _r = bch_btree_ ## fn(_b, op, ##__VA_ARGS__); \
357+ } \
358+ rw_unlock(_w, _b); \
359+ bch_cannibalize_unlock(c); \
360+ if (_r == -EINTR) \
361+ schedule(); \
362+ } while (_r == -EINTR); \
363+ \
364+ finish_wait(&(c)->btree_cache_wait, &(op)->wait); \
365+ _r; \
366+})
367+
287368 #define MAP_DONE 0
288369 #define MAP_CONTINUE 1
289370
@@ -314,6 +395,9 @@ typedef int (btree_map_keys_fn)(struct btree_op *op, struct btree *b, · 24 unmodified lines
314395 struct bkey *k);
315396 int bch_btree_map_keys(struct btree_op *op, struct cache_set *c,
316397 struct bkey *from, btree_map_keys_fn *fn, int flags);
398+int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op,
399+ struct bkey *from, btree_map_keys_fn *fn,
400+ int flags);
317401
318402 typedef bool (keybuf_pred_fn)(struct keybuf *buf, struct bkey *k);
319403
drivers/md/bcache/sysfs.c+1−1
@@ -154,7 +154,7 @@ static ssize_t bch_snprint_string_list(char *buf, · 153 unmodified lines
154154 size_t i;
155155
156156 for (i = 0; list[i]; i++)
157− out += snprintf(out, buf + size - out,
157+ out += scnprintf(out, buf + size - out,
158158 i == selected ? "[%s] " : "%s ", list[i]);
159159
160160 out[-1] = '\n';
drivers/md/bcache/writeback.c+158−6
@@ -183,7 +183,7 @@ static void update_writeback_rate(struct work_struct *work) · 182 unmodified lines
183183 */
184184 set_bit(BCACHE_DEV_RATE_DW_RUNNING, &dc->disk.flags);
185185 /* paired with where BCACHE_DEV_RATE_DW_RUNNING is tested */
186− smp_mb();
186+ smp_mb__after_atomic();
187187
188188 /*
189189 * CACHE_SET_IO_DISABLE might be set via sysfs interface,
@@ -193,7 +193,7 @@ static void update_writeback_rate(struct work_struct *work) · 3 unmodified lines
193193 test_bit(CACHE_SET_IO_DISABLE, &c->flags)) {
194194 clear_bit(BCACHE_DEV_RATE_DW_RUNNING, &dc->disk.flags);
195195 /* paired with where BCACHE_DEV_RATE_DW_RUNNING is tested */
196− smp_mb();
196+ smp_mb__after_atomic();
197197 return;
198198 }
199199
@@ -229,7 +229,7 @@ static void update_writeback_rate(struct work_struct *work) · 29 unmodified lines
229229 */
230230 clear_bit(BCACHE_DEV_RATE_DW_RUNNING, &dc->disk.flags);
231231 /* paired with where BCACHE_DEV_RATE_DW_RUNNING is tested */
232− smp_mb();
232+ smp_mb__after_atomic();
233233 }
234234
235235 static unsigned int writeback_delay(struct cached_dev *dc,
@@ -785,7 +785,9 @@ static int sectors_dirty_init_fn(struct btree_op *_op, struct btree *b, · 549 unmodified lines
785785 return MAP_CONTINUE;
786786 }
787787
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)
789791 {
790792 struct sectors_dirty_init op;
791793 int ret;
@@ -796,8 +798,13 @@ void bch_sectors_dirty_init(struct bcache_device *d) · 4 unmodified lines
796798 op.start = KEY(op.inode, 0, 0);
797799
798800 do {
799− ret = bch_btree_map_keys(&op.op, d->c, &op.start,
800− sectors_dirty_init_fn, 0);
801+ ret = bcache_btree(map_keys_recurse,
802+ k,
803+ c->root,
804+ &op.op,
805+ &op.start,
806+ sectors_dirty_init_fn,
807+ 0);
801808 if (ret == -EAGAIN)
802809 schedule_timeout_interruptible(
803810 msecs_to_jiffies(INIT_KEYS_SLEEP_MS));
@@ -806,6 +813,151 @@ void bch_sectors_dirty_init(struct bcache_device *d) · 2 unmodified lines
806813 break;
807814 }
808815 } while (ret == -EAGAIN);
816+
817+ return ret;
818+}
819+
820+static int bch_dirty_init_thread(void *arg)
821+{
822+ struct dirty_init_thrd_info *info = arg;
823+ struct bch_dirty_init_state *state = info->state;
824+ struct cache_set *c = state->c;
825+ struct btree_iter iter;
826+ struct bkey *k, *p;
827+ int cur_idx, prev_idx, skip_nr;
828+ int i;
829+
830+ k = p = NULL;
831+ i = 0;
832+ cur_idx = prev_idx = 0;
833+
834+ bch_btree_iter_init(&c->root->keys, &iter, NULL);
835+ k = bch_btree_iter_next_filter(&iter, &c->root->keys, bch_ptr_bad);
836+ BUG_ON(!k);
837+
838+ p = k;
839+
840+ while (k) {
841+ spin_lock(&state->idx_lock);
842+ cur_idx = state->key_idx;
843+ state->key_idx++;
844+ spin_unlock(&state->idx_lock);
845+
846+ skip_nr = cur_idx - prev_idx;
847+
848+ while (skip_nr) {
849+ k = bch_btree_iter_next_filter(&iter,
850+ &c->root->keys,
851+ bch_ptr_bad);
852+ if (k)
853+ p = k;
854+ else {
855+ atomic_set(&state->enough, 1);
856+ /* Update state->enough earlier */
857+ smp_mb__after_atomic();
858+ goto out;
859+ }
860+ skip_nr--;
861+ cond_resched();
862+ }
863+
864+ if (p) {
865+ if (bch_root_node_dirty_init(c, state->d, p) < 0)
866+ goto out;
867+ }
868+
869+ p = NULL;
870+ prev_idx = cur_idx;
871+ cond_resched();
872+ }
873+
874+out:
875+ /* In order to wake up state->wait in time */
876+ smp_mb__before_atomic();
877+ if (atomic_dec_and_test(&state->started))
878+ wake_up(&state->wait);
879+
880+ return 0;
881+}
882+
883+static int bch_btre_dirty_init_thread_nr(void)
884+{
885+ int n = num_online_cpus()/2;
886+
887+ if (n == 0)
888+ n = 1;
889+ else if (n > BCH_DIRTY_INIT_THRD_MAX)
890+ n = BCH_DIRTY_INIT_THRD_MAX;
891+
892+ return n;
893+}
894+
895+void bch_sectors_dirty_init(struct bcache_device *d)
896+{
897+ int i;
898+ struct bkey *k = NULL;
899+ struct btree_iter iter;
900+ struct sectors_dirty_init op;
901+ struct cache_set *c = d->c;
902+ struct bch_dirty_init_state *state;
903+ char name[32];
904+
905+ /* Just count root keys if no leaf node */
906+ if (c->root->level == 0) {
907+ bch_btree_op_init(&op.op, -1);
908+ op.inode = d->id;
909+ op.count = 0;
910+ op.start = KEY(op.inode, 0, 0);
911+
912+ for_each_key_filter(&c->root->keys,
913+ k, &iter, bch_ptr_invalid)
914+ sectors_dirty_init_fn(&op.op, c->root, k);
915+ return;
916+ }
917+
918+ state = kzalloc(sizeof(struct bch_dirty_init_state), GFP_KERNEL);
919+ if (!state) {
920+ pr_warn("sectors dirty init failed: cannot allocate memory");
921+ return;
922+ }
923+
924+ state->c = c;
925+ state->d = d;
926+ state->total_threads = bch_btre_dirty_init_thread_nr();
927+ state->key_idx = 0;
928+ spin_lock_init(&state->idx_lock);
929+ atomic_set(&state->started, 0);
930+ atomic_set(&state->enough, 0);
931+ init_waitqueue_head(&state->wait);
932+
933+ for (i = 0; i < state->total_threads; i++) {
934+ /* Fetch latest state->enough earlier */
935+ smp_mb__before_atomic();
936+ if (atomic_read(&state->enough))
937+ break;
938+
939+ state->infos[i].state = state;
940+ atomic_inc(&state->started);
941+ snprintf(name, sizeof(name), "bch_dirty_init[%d]", i);
942+
943+ state->infos[i].thread =
944+ kthread_run(bch_dirty_init_thread,
945+ &state->infos[i],
946+ name);
947+ if (IS_ERR(state->infos[i].thread)) {
948+ pr_err("fails to run thread bch_dirty_init[%d]", i);
949+ for (--i; i >= 0; i--)
950+ kthread_stop(state->infos[i].thread);
951+ goto out;
952+ }
953+ }
954+
955+ wait_event_interruptible(state->wait,
956+ atomic_read(&state->started) == 0 ||
957+ test_bit(CACHE_SET_IO_DISABLE, &c->flags));
958+
959+out:
960+ kfree(state);
809961 }
810962
811963 void bch_cached_dev_writeback_init(struct cached_dev *dc)
drivers/md/bcache/writeback.h+19−0
@@ -16,6 +16,7 @@ · 15 unmodified lines
1616
1717 #define BCH_AUTO_GC_DIRTY_THRESHOLD 50
1818
19+#define BCH_DIRTY_INIT_THRD_MAX 64
1920 /*
2021 * 14 (16384ths) is chosen here as something that each backing device
2122 * should be a reasonable fraction of the share, and not to blow up
@@ -23,6 +24,24 @@ · 1 unmodified line
2324 */
2425 #define WRITEBACK_SHARE_SHIFT 14
2526
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+};
44+
2645 static inline uint64_t bcache_dev_sectors_dirty(struct bcache_device *d)
2746 {
2847 uint64_t i, ret = 0;
drivers/md/md.c+1−1
@@ -6185,7 +6185,7 @@ EXPORT_SYMBOL_GPL(md_stop_writes); · 6184 unmodified lines
61856185 static void mddev_detach(struct mddev *mddev)
61866186 {
61876187 md_bitmap_wait_behind_writes(mddev);
6188− if (mddev->pers && mddev->pers->quiesce) {
6188+ if (mddev->pers && mddev->pers->quiesce && !mddev->suspended) {
61896189 mddev->pers->quiesce(mddev, 1);
61906190 mddev->pers->quiesce(mddev, 0);
61916191 }
drivers/nvme/host/Kconfig+0−2
@@ -32,8 +32,6 @@ config NVME_HWMON · 31 unmodified lines
3232 a hardware monitoring device will be created for each NVMe drive
3333 in the system.
3434
35− If unsure, say N.
36−
3735 config NVME_FABRICS
3836 tristate
3937
drivers/nvme/host/core.c+156−99
@@ -171,7 +171,6 @@ static void nvme_do_delete_ctrl(struct nvme_ctrl *ctrl) · 170 unmodified lines
171171 nvme_remove_namespaces(ctrl);
172172 ctrl->ops->delete_ctrl(ctrl);
173173 nvme_uninit_ctrl(ctrl);
174− nvme_put_ctrl(ctrl);
175174 }
176175
177176 static void nvme_delete_ctrl_work(struct work_struct *work)
@@ -192,21 +191,16 @@ int nvme_delete_ctrl(struct nvme_ctrl *ctrl) · 14 unmodified lines
192191 }
193192 EXPORT_SYMBOL_GPL(nvme_delete_ctrl);
194193
195−static int nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl)
194+static void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl)
196195 {
197− int ret = 0;
198−
199196 /*
200197 * Keep a reference until nvme_do_delete_ctrl() complete,
201198 * since ->delete_ctrl can free the controller.
202199 */
203200 nvme_get_ctrl(ctrl);
204− if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING))
205− ret = -EBUSY;
206− if (!ret)
201+ if (nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING))
207202 nvme_do_delete_ctrl(ctrl);
208203 nvme_put_ctrl(ctrl);
209− return ret;
210204 }
211205
212206 static inline bool nvme_ns_has_pi(struct nvme_ns *ns)
@@ -291,11 +285,8 @@ void nvme_complete_rq(struct request *req) · 78 unmodified lines
291285 nvme_req(req)->ctrl->comp_seen = true;
292286
293287 if (unlikely(status != BLK_STS_OK && nvme_req_needs_retry(req))) {
294− if ((req->cmd_flags & REQ_NVME_MPATH) &&
295− blk_path_error(status)) {
296− nvme_failover_req(req);
288+ if ((req->cmd_flags & REQ_NVME_MPATH) && nvme_failover_req(req))
297289 return;
298− }
299290
300291 if (!blk_queue_dying(req->q)) {
301292 nvme_retry_req(req);
@@ -1055,6 +1046,43 @@ static int nvme_identify_ctrl(struct nvme_ctrl *dev, struct nvme_id_ctrl **id) · 753 unmodified lines
10551046 return error;
10561047 }
10571048
1049+static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids,
1050+ struct nvme_ns_id_desc *cur)
1051+{
1052+ const char *warn_str = "ctrl returned bogus length:";
1053+ void *data = cur;
1054+
1055+ switch (cur->nidt) {
1056+ case NVME_NIDT_EUI64:
1057+ if (cur->nidl != NVME_NIDT_EUI64_LEN) {
1058+ dev_warn(ctrl->device, "%s %d for NVME_NIDT_EUI64\n",
1059+ warn_str, cur->nidl);
1060+ return -1;
1061+ }
1062+ memcpy(ids->eui64, data + sizeof(*cur), NVME_NIDT_EUI64_LEN);
1063+ return NVME_NIDT_EUI64_LEN;
1064+ case NVME_NIDT_NGUID:
1065+ if (cur->nidl != NVME_NIDT_NGUID_LEN) {
1066+ dev_warn(ctrl->device, "%s %d for NVME_NIDT_NGUID\n",
1067+ warn_str, cur->nidl);
1068+ return -1;
1069+ }
1070+ memcpy(ids->nguid, data + sizeof(*cur), NVME_NIDT_NGUID_LEN);
1071+ return NVME_NIDT_NGUID_LEN;
1072+ case NVME_NIDT_UUID:
1073+ if (cur->nidl != NVME_NIDT_UUID_LEN) {
1074+ dev_warn(ctrl->device, "%s %d for NVME_NIDT_UUID\n",
1075+ warn_str, cur->nidl);
1076+ return -1;
1077+ }
1078+ uuid_copy(&ids->uuid, data + sizeof(*cur));
1079+ return NVME_NIDT_UUID_LEN;
1080+ default:
1081+ /* Skip unknown types */
1082+ return cur->nidl;
1083+ }
1084+}
1085+
10581086 static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid,
10591087 struct nvme_ns_ids *ids)
10601088 {
@@ -1074,8 +1102,17 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid, · 13 unmodified lines
10741102
10751103 status = nvme_submit_sync_cmd(ctrl->admin_q, &c, data,
10761104 NVME_IDENTIFY_DATA_SIZE);
1077− if (status)
1105+ if (status) {
1106+ dev_warn(ctrl->device,
1107+ "Identify Descriptors failed (%d)\n", status);
1108+ /*
1109+ * Don't treat an error as fatal, as we potentially already
1110+ * have a NGUID or EUI-64.
1111+ */
1112+ if (status > 0)
1113+ status = 0;
10781114 goto free_data;
1115+ }
10791116
10801117 for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
10811118 struct nvme_ns_id_desc *cur = data + pos;
@@ -1083,42 +1120,9 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid, · 1 unmodified line
10831120 if (cur->nidl == 0)
10841121 break;
10851122
1086− switch (cur->nidt) {
1087− case NVME_NIDT_EUI64:
1088− if (cur->nidl != NVME_NIDT_EUI64_LEN) {
1089− dev_warn(ctrl->device,
1090− "ctrl returned bogus length: %d for NVME_NIDT_EUI64\n",
1091− cur->nidl);
1092− goto free_data;
1093− }
1094− len = NVME_NIDT_EUI64_LEN;
1095− memcpy(ids->eui64, data + pos + sizeof(*cur), len);
1096− break;
1097− case NVME_NIDT_NGUID:
1098− if (cur->nidl != NVME_NIDT_NGUID_LEN) {
1099− dev_warn(ctrl->device,
1100− "ctrl returned bogus length: %d for NVME_NIDT_NGUID\n",
1101− cur->nidl);
1102− goto free_data;
1103− }
1104− len = NVME_NIDT_NGUID_LEN;
1105− memcpy(ids->nguid, data + pos + sizeof(*cur), len);
1106− break;
1107− case NVME_NIDT_UUID:
1108− if (cur->nidl != NVME_NIDT_UUID_LEN) {
1109− dev_warn(ctrl->device,
1110− "ctrl returned bogus length: %d for NVME_NIDT_UUID\n",
1111− cur->nidl);
1112− goto free_data;
1113− }
1114− len = NVME_NIDT_UUID_LEN;
1115− uuid_copy(&ids->uuid, data + pos + sizeof(*cur));
1116− break;
1117− default:
1118− /* Skip unknown types */
1119− len = cur->nidl;
1120− break;
1121− }
1123+ len = nvme_process_ns_desc(ctrl, ids, cur);
1124+ if (len < 0)
1125+ goto free_data;
11221126
11231127 len += sizeof(*cur);
11241128 }
@@ -1584,6 +1588,47 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode, · 459 unmodified lines
15841588 return ret;
15851589 }
15861590
1591+#ifdef CONFIG_COMPAT
1592+struct nvme_user_io32 {
1593+ __u8 opcode;
1594+ __u8 flags;
1595+ __u16 control;
1596+ __u16 nblocks;
1597+ __u16 rsvd;
1598+ __u64 metadata;
1599+ __u64 addr;
1600+ __u64 slba;
1601+ __u32 dsmgmt;
1602+ __u32 reftag;
1603+ __u16 apptag;
1604+ __u16 appmask;
1605+} __attribute__((__packed__));
1606+
1607+#define NVME_IOCTL_SUBMIT_IO32 _IOW('N', 0x42, struct nvme_user_io32)
1608+
1609+static int nvme_compat_ioctl(struct block_device *bdev, fmode_t mode,
1610+ unsigned int cmd, unsigned long arg)
1611+{
1612+ /*
1613+ * Corresponds to the difference of NVME_IOCTL_SUBMIT_IO
1614+ * between 32 bit programs and 64 bit kernel.
1615+ * The cause is that the results of sizeof(struct nvme_user_io),
1616+ * which is used to define NVME_IOCTL_SUBMIT_IO,
1617+ * are not same between 32 bit compiler and 64 bit compiler.
1618+ * NVME_IOCTL_SUBMIT_IO32 is for 64 bit kernel handling
1619+ * NVME_IOCTL_SUBMIT_IO issued from 32 bit programs.
1620+ * Other IOCTL numbers are same between 32 bit and 64 bit.
1621+ * So there is nothing to do regarding to other IOCTL numbers.
1622+ */
1623+ if (cmd == NVME_IOCTL_SUBMIT_IO32)
1624+ return nvme_ioctl(bdev, mode, NVME_IOCTL_SUBMIT_IO, arg);
1625+
1626+ return nvme_ioctl(bdev, mode, cmd, arg);
1627+}
1628+#else
1629+#define nvme_compat_ioctl NULL
1630+#endif /* CONFIG_COMPAT */
1631+
15871632 static int nvme_open(struct block_device *bdev, fmode_t mode)
15881633 {
15891634 struct nvme_ns *ns = bdev->bd_disk->private_data;
@@ -1721,26 +1766,15 @@ static void nvme_config_write_zeroes(struct gendisk *disk, struct nvme_ns *ns) · 131 unmodified lines
17211766 static int nvme_report_ns_ids(struct nvme_ctrl *ctrl, unsigned int nsid,
17221767 struct nvme_id_ns *id, struct nvme_ns_ids *ids)
17231768 {
1724− int ret = 0;
1725−
17261769 memset(ids, 0, sizeof(*ids));
17271770
17281771 if (ctrl->vs >= NVME_VS(1, 1, 0))
17291772 memcpy(ids->eui64, id->eui64, sizeof(id->eui64));
17301773 if (ctrl->vs >= NVME_VS(1, 2, 0))
17311774 memcpy(ids->nguid, id->nguid, sizeof(id->nguid));
1732− if (ctrl->vs >= NVME_VS(1, 3, 0)) {
1733− /* Don't treat error as fatal we potentially
1734− * already have a NGUID or EUI-64
1735− */
1736− ret = nvme_identify_ns_descs(ctrl, nsid, ids);
1737− if (ret)
1738− dev_warn(ctrl->device,
1739− "Identify Descriptors failed (%d)\n", ret);
1740− if (ret > 0)
1741− ret = 0;
1742− }
1743− return ret;
1775+ if (ctrl->vs >= NVME_VS(1, 3, 0))
1776+ return nvme_identify_ns_descs(ctrl, nsid, ids);
1777+ return 0;
17441778 }
17451779
17461780 static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids)
@@ -2027,7 +2061,7 @@ EXPORT_SYMBOL_GPL(nvme_sec_submit); · 280 unmodified lines
20272061 static const struct block_device_operations nvme_fops = {
20282062 .owner = THIS_MODULE,
20292063 .ioctl = nvme_ioctl,
2030− .compat_ioctl = nvme_ioctl,
2064+ .compat_ioctl = nvme_compat_ioctl,
20312065 .open = nvme_open,
20322066 .release = nvme_release,
20332067 .getgeo = nvme_getgeo,
@@ -2055,7 +2089,7 @@ const struct block_device_operations nvme_ns_head_ops = { · 21 unmodified lines
20552089 .open = nvme_ns_head_open,
20562090 .release = nvme_ns_head_release,
20572091 .ioctl = nvme_ioctl,
2058− .compat_ioctl = nvme_ioctl,
2092+ .compat_ioctl = nvme_compat_ioctl,
20592093 .getgeo = nvme_getgeo,
20602094 .pr_ops = &nvme_pr_ops,
20612095 };
@@ -2074,13 +2108,13 @@ static int nvme_wait_ready(struct nvme_ctrl *ctrl, u64 cap, bool enabled) · 12 unmodified lines
20742108 if ((csts & NVME_CSTS_RDY) == bit)
20752109 break;
20762110
2077− msleep(100);
2111+ usleep_range(1000, 2000);
20782112 if (fatal_signal_pending(current))
20792113 return -EINTR;
20802114 if (time_after(jiffies, timeout)) {
20812115 dev_err(ctrl->device,
2082− "Device not ready; aborting %s\n", enabled ?
2083− "initialisation" : "reset");
2116+ "Device not ready; aborting %s, CSTS=0x%x\n",
2117+ enabled ? "initialisation" : "reset", csts);
20842118 return -ENODEV;
20852119 }
20862120 }
@@ -2591,8 +2625,7 @@ static bool nvme_validate_cntlid(struct nvme_subsystem *subsys, · 504 unmodified lines
25912625 lockdep_assert_held(&nvme_subsystems_lock);
25922626
25932627 list_for_each_entry(tmp, &subsys->ctrls, subsys_entry) {
2594− if (tmp->state == NVME_CTRL_DELETING ||
2595− tmp->state == NVME_CTRL_DEAD)
2628+ if (nvme_state_terminal(tmp))
25962629 continue;
25972630
25982631 if (tmp->cntlid == ctrl->cntlid) {
@@ -3193,6 +3226,10 @@ static ssize_t nvme_sysfs_delete(struct device *dev, · 594 unmodified lines
31933226 {
31943227 struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
31953228
3229+ /* Can't delete non-created controllers */
3230+ if (!ctrl->created)
3231+ return -EBUSY;
3232+
31963233 if (device_remove_file_self(dev, attr))
31973234 nvme_delete_ctrl_sync(ctrl);
31983235 return count;
@@ -3242,6 +3279,26 @@ static ssize_t nvme_sysfs_show_subsysnqn(struct device *dev, · 43 unmodified lines
32423279 }
32433280 static DEVICE_ATTR(subsysnqn, S_IRUGO, nvme_sysfs_show_subsysnqn, NULL);
32443281
3282+static ssize_t nvme_sysfs_show_hostnqn(struct device *dev,
3283+ struct device_attribute *attr,
3284+ char *buf)
3285+{
3286+ struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
3287+
3288+ return snprintf(buf, PAGE_SIZE, "%s\n", ctrl->opts->host->nqn);
3289+}
3290+static DEVICE_ATTR(hostnqn, S_IRUGO, nvme_sysfs_show_hostnqn, NULL);
3291+
3292+static ssize_t nvme_sysfs_show_hostid(struct device *dev,
3293+ struct device_attribute *attr,
3294+ char *buf)
3295+{
3296+ struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
3297+
3298+ return snprintf(buf, PAGE_SIZE, "%pU\n", &ctrl->opts->host->id);
3299+}
3300+static DEVICE_ATTR(hostid, S_IRUGO, nvme_sysfs_show_hostid, NULL);
3301+
32453302 static ssize_t nvme_sysfs_show_address(struct device *dev,
32463303 struct device_attribute *attr,
32473304 char *buf)
@@ -3267,6 +3324,8 @@ static struct attribute *nvme_dev_attrs[] = { · 19 unmodified lines
32673324 &dev_attr_numa_node.attr,
32683325 &dev_attr_queue_count.attr,
32693326 &dev_attr_sqsize.attr,
3327+ &dev_attr_hostnqn.attr,
3328+ &dev_attr_hostid.attr,
32703329 NULL
32713330 };
32723331
@@ -3280,6 +3339,10 @@ static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj, · 7 unmodified lines
32803339 return 0;
32813340 if (a == &dev_attr_address.attr && !ctrl->ops->get_address)
32823341 return 0;
3342+ if (a == &dev_attr_hostnqn.attr && !ctrl->opts)
3343+ return 0;
3344+ if (a == &dev_attr_hostid.attr && !ctrl->opts)
3345+ return 0;
32833346
32843347 return a->mode;
32853348 }
@@ -3294,7 +3357,7 @@ static const struct attribute_group *nvme_dev_attr_groups[] = { · 8 unmodified lines
32943357 NULL,
32953358 };
32963359
3297−static struct nvme_ns_head *__nvme_find_ns_head(struct nvme_subsystem *subsys,
3360+static struct nvme_ns_head *nvme_find_ns_head(struct nvme_subsystem *subsys,
32983361 unsigned nsid)
32993362 {
33003363 struct nvme_ns_head *h;
@@ -3327,7 +3390,8 @@ static int __nvme_check_ids(struct nvme_subsystem *subsys, · 26 unmodified lines
33273390 }
33283391
33293392 static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl,
3330− unsigned nsid, struct nvme_id_ns *id)
3393+ unsigned nsid, struct nvme_id_ns *id,
3394+ struct nvme_ns_ids *ids)
33313395 {
33323396 struct nvme_ns_head *head;
33333397 size_t size = sizeof(*head);
@@ -3350,12 +3414,9 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl, · 16 unmodified lines
33503414 goto out_ida_remove;
33513415 head->subsys = ctrl->subsys;
33523416 head->ns_id = nsid;
3417+ head->ids = *ids;
33533418 kref_init(&head->ref);
33543419
3355− ret = nvme_report_ns_ids(ctrl, nsid, id, &head->ids);
3356− if (ret)
3357− goto out_cleanup_srcu;
3358−
33593420 ret = __nvme_check_ids(ctrl->subsys, head);
33603421 if (ret) {
33613422 dev_err(ctrl->device,
@@ -3390,24 +3451,23 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid, · 28 unmodified lines
33903451 struct nvme_ctrl *ctrl = ns->ctrl;
33913452 bool is_shared = id->nmic & (1 << 0);
33923453 struct nvme_ns_head *head = NULL;
3454+ struct nvme_ns_ids ids;
33933455 int ret = 0;
33943456
3457+ ret = nvme_report_ns_ids(ctrl, nsid, id, &ids);
3458+ if (ret)
3459+ goto out;
3460+
33953461 mutex_lock(&ctrl->subsys->lock);
33963462 if (is_shared)
3397− head = __nvme_find_ns_head(ctrl->subsys, nsid);
3463+ head = nvme_find_ns_head(ctrl->subsys, nsid);
33983464 if (!head) {
3399− head = nvme_alloc_ns_head(ctrl, nsid, id);
3465+ head = nvme_alloc_ns_head(ctrl, nsid, id, &ids);
34003466 if (IS_ERR(head)) {
34013467 ret = PTR_ERR(head);
34023468 goto out_unlock;
34033469 }
34043470 } else {
3405− struct nvme_ns_ids ids;
3406−
3407− ret = nvme_report_ns_ids(ctrl, nsid, id, &ids);
3408− if (ret)
3409− goto out_unlock;
3410−
34113471 if (!nvme_ns_ids_equal(&head->ids, &ids)) {
34123472 dev_err(ctrl->device,
34133473 "IDs don't match for shared namespace %d\n",
@@ -3422,6 +3482,7 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid, · 8 unmodified lines
34223482
34233483 out_unlock:
34243484 mutex_unlock(&ctrl->subsys->lock);
3485+out:
34253486 if (ret > 0)
34263487 ret = blk_status_to_errno(nvme_error_status(ret));
34273488 return ret;
@@ -3480,7 +3541,7 @@ static int nvme_setup_streams_ns(struct nvme_ctrl *ctrl, struct nvme_ns *ns) · 52 unmodified lines
34803541 return 0;
34813542 }
34823543
3483−static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
3544+static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
34843545 {
34853546 struct nvme_ns *ns;
34863547 struct gendisk *disk;
@@ -3490,13 +3551,11 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) · 3 unmodified lines
34903551
34913552 ns = kzalloc_node(sizeof(*ns), GFP_KERNEL, node);
34923553 if (!ns)
3493− return -ENOMEM;
3554+ return;
34943555
34953556 ns->queue = blk_mq_init_queue(ctrl->tagset);
3496− if (IS_ERR(ns->queue)) {
3497− ret = PTR_ERR(ns->queue);
3557+ if (IS_ERR(ns->queue))
34983558 goto out_free_ns;
3499− }
35003559
35013560 if (ctrl->opts && ctrl->opts->data_digest)
35023561 ns->queue->backing_dev_info->capabilities
@@ -3519,10 +3578,8 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) · 16 unmodified lines
35193578 if (ret)
35203579 goto out_free_queue;
35213580
3522− if (id->ncap == 0) {
3523− ret = -EINVAL;
3581+ if (id->ncap == 0) /* no namespace (legacy quirk) */
35243582 goto out_free_id;
3525− }
35263583
35273584 ret = nvme_init_ns_head(ns, nsid, id);
35283585 if (ret)
@@ -3531,10 +3588,8 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) · 2 unmodified lines
35313588 nvme_set_disk_name(disk_name, ns, ctrl, &flags);
35323589
35333590 disk = alloc_disk_node(0, node);
3534− if (!disk) {
3535− ret = -ENOMEM;
3591+ if (!disk)
35363592 goto out_unlink_ns;
3537− }
35383593
35393594 disk->fops = &nvme_fops;
35403595 disk->private_data = ns;
@@ -3565,7 +3620,7 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) · 24 unmodified lines
35653620 nvme_fault_inject_init(&ns->fault_inject, ns->disk->disk_name);
35663621 kfree(id);
35673622
3568− return 0;
3623+ return;
35693624 out_put_disk:
35703625 put_disk(ns->disk);
35713626 out_unlink_ns:
@@ -3579,9 +3634,6 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) · 7 unmodified lines
35793634 blk_cleanup_queue(ns->queue);
35803635 out_free_ns:
35813636 kfree(ns);
3582− if (ret > 0)
3583− ret = blk_status_to_errno(nvme_error_status(ret));
3584− return ret;
35853637 }
35863638
35873639 static void nvme_ns_remove(struct nvme_ns *ns)
@@ -3987,6 +4039,7 @@ void nvme_start_ctrl(struct nvme_ctrl *ctrl) · 399 unmodified lines
39874039 nvme_queue_scan(ctrl);
39884040 nvme_start_queues(ctrl);
39894041 }
4042+ ctrl->created = true;
39904043 }
39914044 EXPORT_SYMBOL_GPL(nvme_start_ctrl);
39924045
@@ -3995,6 +4048,7 @@ void nvme_uninit_ctrl(struct nvme_ctrl *ctrl) · 2 unmodified lines
39954048 nvme_fault_inject_fini(&ctrl->fault_inject);
39964049 dev_pm_qos_hide_latency_tolerance(ctrl->device);
39974050 cdev_device_del(&ctrl->cdev, ctrl->device);
4051+ nvme_put_ctrl(ctrl);
39984052 }
39994053 EXPORT_SYMBOL_GPL(nvme_uninit_ctrl);
40004054
@@ -4077,6 +4131,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, · 76 unmodified lines
40774131 if (ret)
40784132 goto out_release_instance;
40794133
4134+ nvme_get_ctrl(ctrl);
40804135 cdev_init(&ctrl->cdev, &nvme_dev_fops);
40814136 ctrl->cdev.owner = ops->module;
40824137 ret = cdev_device_add(&ctrl->cdev, ctrl->device);
@@ -4095,6 +4150,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, · 12 unmodified lines
40954150
40964151 return 0;
40974152 out_free_name:
4153+ nvme_put_ctrl(ctrl);
40984154 kfree_const(ctrl->device->kobj.name);
40994155 out_release_instance:
41004156 ida_simple_remove(&nvme_instance_ida, ctrl->instance);
@@ -4299,6 +4355,7 @@ static void __exit nvme_core_exit(void) · 198 unmodified lines
42994355 destroy_workqueue(nvme_delete_wq);
43004356 destroy_workqueue(nvme_reset_wq);
43014357 destroy_workqueue(nvme_wq);
4358+ ida_destroy(&nvme_instance_ida);
43024359 }
43034360
43044361 MODULE_LICENSE("GPL");
drivers/nvme/host/fabrics.c+4−4
@@ -105,14 +105,14 @@ int nvmf_get_address(struct nvme_ctrl *ctrl, char *buf, int size) · 104 unmodified lines
105105 int len = 0;
106106
107107 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);
109109 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",
111111 (len) ? "," : "", ctrl->opts->trsvcid);
112112 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",
114114 (len) ? "," : "", ctrl->opts->host_traddr);
115− len += snprintf(buf + len, size - len, "\n");
115+ len += scnprintf(buf + len, size - len, "\n");
116116
117117 return len;
118118 }
drivers/nvme/host/fc.c+0−3
@@ -3181,10 +3181,7 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts, · 3180 unmodified lines
31813181 goto fail_ctrl;
31823182 }
31833183
3184− nvme_get_ctrl(&ctrl->ctrl);
3185−
31863184 if (!queue_delayed_work(nvme_wq, &ctrl->connect_work, 0)) {
3187− nvme_put_ctrl(&ctrl->ctrl);
31883185 dev_err(ctrl->ctrl.device,
31893186 "NVME-FC{%d}: failed to schedule initial connect\n",
31903187 ctrl->cnum);
drivers/nvme/host/multipath.c+9−12
@@ -64,17 +64,12 @@ void nvme_set_disk_name(char *disk_name, struct nvme_ns *ns, · 63 unmodified lines
6464 }
6565 }
6666
67−void nvme_failover_req(struct request *req)
67+bool nvme_failover_req(struct request *req)
6868 {
6969 struct nvme_ns *ns = req->q->queuedata;
7070 u16 status = nvme_req(req)->status;
7171 unsigned long flags;
7272
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−
7873 switch (status & 0x7ff) {
7974 case NVME_SC_ANA_TRANSITION:
8075 case NVME_SC_ANA_INACCESSIBLE:
@@ -103,15 +98,17 @@ void nvme_failover_req(struct request *req) · 22 unmodified lines
10398 nvme_mpath_clear_current_path(ns);
10499 break;
105100 default:
106− /*
107− * Reset the controller for any non-ANA error as we don't know
108− * what caused the error.
109− */
110− nvme_reset_ctrl(ns->ctrl);
111− break;
101+ /* This was a non-ANA error so follow the normal error path. */
102+ return false;
112103 }
113104
105+ spin_lock_irqsave(&ns->head->requeue_lock, flags);
106+ blk_steal_bios(&ns->head->requeue_list, req);
107+ spin_unlock_irqrestore(&ns->head->requeue_lock, flags);
108+ blk_mq_end_request(req, 0);
109+
114110 kblockd_schedule_work(&ns->head->requeue_work);
111+ return true;
115112 }
116113
117114 void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl)
drivers/nvme/host/nvme.h+4−2
@@ -259,6 +259,7 @@ struct nvme_ctrl { · 258 unmodified lines
259259 struct nvme_command ka_cmd;
260260 struct work_struct fw_act_work;
261261 unsigned long events;
262+ bool created;
262263
263264 #ifdef CONFIG_NVME_MULTIPATH
264265 /* asymmetric namespace access: */
@@ -550,7 +551,7 @@ void nvme_mpath_wait_freeze(struct nvme_subsystem *subsys); · 285 unmodified lines
550551 void nvme_mpath_start_freeze(struct nvme_subsystem *subsys);
551552 void nvme_set_disk_name(char *disk_name, struct nvme_ns *ns,
552553 struct nvme_ctrl *ctrl, int *flags);
553−void nvme_failover_req(struct request *req);
554+bool nvme_failover_req(struct request *req);
554555 void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl);
555556 int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl,struct nvme_ns_head *head);
556557 void nvme_mpath_add_disk(struct nvme_ns *ns, struct nvme_id_ns *id);
@@ -599,8 +600,9 @@ static inline void nvme_set_disk_name(char *disk_name, struct nvme_ns *ns, · 42 unmodified lines
599600 sprintf(disk_name, "nvme%dn%d", ctrl->instance, ns->head->instance);
600601 }
601602
602−static inline void nvme_failover_req(struct request *req)
603+static inline bool nvme_failover_req(struct request *req)
603604 {
605+ return false;
604606 }
605607 static inline void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl)
606608 {
drivers/nvme/host/pci.c+28−63
@@ -971,39 +971,25 @@ static inline void nvme_handle_cqe(struct nvme_queue *nvmeq, u16 idx) · 970 unmodified lines
971971 nvme_end_request(req, cqe->status, cqe->result);
972972 }
973973
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−
983974 static inline void nvme_update_cq_head(struct nvme_queue *nvmeq)
984975 {
985− if (nvmeq->cq_head == nvmeq->q_depth - 1) {
976+ if (++nvmeq->cq_head == nvmeq->q_depth) {
986977 nvmeq->cq_head = 0;
987− nvmeq->cq_phase = !nvmeq->cq_phase;
988− } else {
989− nvmeq->cq_head++;
978+ nvmeq->cq_phase ^= 1;
990979 }
991980 }
992981
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)
995983 {
996984 int found = 0;
997985
998− *start = nvmeq->cq_head;
999986 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);
1002989 nvme_update_cq_head(nvmeq);
1003990 }
1004− *end = nvmeq->cq_head;
1005991
1006− if (*start != *end)
992+ if (found)
1007993 nvme_ring_cq_doorbell(nvmeq);
1008994 return found;
1009995 }
@@ -1012,21 +998,16 @@ static irqreturn_t nvme_irq(int irq, void *data) · 2 unmodified lines
1012998 {
1013999 struct nvme_queue *nvmeq = data;
10141000 irqreturn_t ret = IRQ_NONE;
1015− u16 start, end;
10161001
10171002 /*
10181003 * The rmb/wmb pair ensures we see all updates from a previous run of
10191004 * the irq handler, even if that was on another CPU.
10201005 */
10211006 rmb();
1022− nvme_process_cq(nvmeq, &start, &end, -1);
1007+ if (nvme_process_cq(nvmeq))
1008+ ret = IRQ_HANDLED;
10231009 wmb();
10241010
1025− if (start != end) {
1026− nvme_complete_cqes(nvmeq, start, end);
1027− return IRQ_HANDLED;
1028− }
1029−
10301011 return ret;
10311012 }
10321013
@@ -1039,46 +1020,30 @@ static irqreturn_t nvme_irq_check(int irq, void *data) · 6 unmodified lines
10391020 }
10401021
10411022 /*
1042− * Poll for completions any queue, including those not dedicated to polling.
1023+ * Poll for completions for any interrupt driven queue
10431024 * Can be called from any context.
10441025 */
1045−static int nvme_poll_irqdisable(struct nvme_queue *nvmeq, unsigned int tag)
1026+static void nvme_poll_irqdisable(struct nvme_queue *nvmeq)
10461027 {
10471028 struct pci_dev *pdev = to_pci_dev(nvmeq->dev->dev);
1048− u16 start, end;
1049− int found;
10501029
1051− /*
1052− * For a poll queue we need to protect against the polling thread
1053− * using the CQ lock. For normal interrupt driven threads we have
1054− * to disable the interrupt to avoid racing with it.
1055− */
1056− if (test_bit(NVMEQ_POLLED, &nvmeq->flags)) {
1057− spin_lock(&nvmeq->cq_poll_lock);
1058− found = nvme_process_cq(nvmeq, &start, &end, tag);
1059− spin_unlock(&nvmeq->cq_poll_lock);
1060− } else {
1061− disable_irq(pci_irq_vector(pdev, nvmeq->cq_vector));
1062− found = nvme_process_cq(nvmeq, &start, &end, tag);
1063− enable_irq(pci_irq_vector(pdev, nvmeq->cq_vector));
1064− }
1030+ WARN_ON_ONCE(test_bit(NVMEQ_POLLED, &nvmeq->flags));
10651031
1066− nvme_complete_cqes(nvmeq, start, end);
1067− return found;
1032+ disable_irq(pci_irq_vector(pdev, nvmeq->cq_vector));
1033+ nvme_process_cq(nvmeq);
1034+ enable_irq(pci_irq_vector(pdev, nvmeq->cq_vector));
10681035 }
10691036
10701037 static int nvme_poll(struct blk_mq_hw_ctx *hctx)
10711038 {
10721039 struct nvme_queue *nvmeq = hctx->driver_data;
1073− u16 start, end;
10741040 bool found;
10751041
10761042 if (!nvme_cqe_pending(nvmeq))
10771043 return 0;
10781044
10791045 spin_lock(&nvmeq->cq_poll_lock);
1080− found = nvme_process_cq(nvmeq, &start, &end, -1);
1081− nvme_complete_cqes(nvmeq, start, end);
1046+ found = nvme_process_cq(nvmeq);
10821047 spin_unlock(&nvmeq->cq_poll_lock);
10831048
10841049 return found;
@@ -1255,7 +1220,12 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved) · 170 unmodified lines
12551220 /*
12561221 * Did we miss an interrupt?
12571222 */
1258− if (nvme_poll_irqdisable(nvmeq, req->tag)) {
1223+ if (test_bit(NVMEQ_POLLED, &nvmeq->flags))
1224+ nvme_poll(req->mq_hctx);
1225+ else
1226+ nvme_poll_irqdisable(nvmeq);
1227+
1228+ if (blk_mq_request_completed(req)) {
12591229 dev_warn(dev->ctrl.device,
12601230 "I/O %d QID %d timeout, completion polled\n",
12611231 req->tag, nvmeq->qid);
@@ -1398,7 +1368,7 @@ static void nvme_disable_admin_queue(struct nvme_dev *dev, bool shutdown) · 136 unmodified lines
13981368 else
13991369 nvme_disable_ctrl(&dev->ctrl);
14001370
1401− nvme_poll_irqdisable(nvmeq, -1);
1371+ nvme_poll_irqdisable(nvmeq);
14021372 }
14031373
14041374 /*
@@ -1409,13 +1379,10 @@ static void nvme_disable_admin_queue(struct nvme_dev *dev, bool shutdown) · 4 unmodified lines
14091379 */
14101380 static void nvme_reap_pending_cqes(struct nvme_dev *dev)
14111381 {
1412− u16 start, end;
14131382 int i;
14141383
1415− for (i = dev->ctrl.queue_count - 1; i > 0; i--) {
1416− nvme_process_cq(&dev->queues[i], &start, &end, -1);
1417− nvme_complete_cqes(&dev->queues[i], start, end);
1418− }
1384+ for (i = dev->ctrl.queue_count - 1; i > 0; i--)
1385+ nvme_process_cq(&dev->queues[i]);
14191386 }
14201387
14211388 static int nvme_cmb_qdepth(struct nvme_dev *dev, int nr_io_queues,
@@ -2503,13 +2470,13 @@ static void nvme_pci_free_ctrl(struct nvme_ctrl *ctrl) · 1081 unmodified lines
25032470 struct nvme_dev *dev = to_nvme_dev(ctrl);
25042471
25052472 nvme_dbbuf_dma_free(dev);
2506− put_device(dev->dev);
25072473 nvme_free_tagset(dev);
25082474 if (dev->ctrl.admin_q)
25092475 blk_put_queue(dev->ctrl.admin_q);
2510− kfree(dev->queues);
25112476 free_opal_dev(dev->ctrl.opal_dev);
25122477 mempool_destroy(dev->iod_mempool);
2478+ put_device(dev->dev);
2479+ kfree(dev->queues);
25132480 kfree(dev);
25142481 }
25152482
@@ -2689,7 +2656,7 @@ static int nvme_pci_get_address(struct nvme_ctrl *ctrl, char *buf, int size) · 173 unmodified lines
26892656 {
26902657 struct pci_dev *pdev = to_pci_dev(to_nvme_dev(ctrl)->dev);
26912658
2692− return snprintf(buf, size, "%s", dev_name(&pdev->dev));
2659+ return snprintf(buf, size, "%s\n", dev_name(&pdev->dev));
26932660 }
26942661
26952662 static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = {
@@ -2835,7 +2802,6 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id) · 139 unmodified lines
28352802 dev_info(dev->ctrl.device, "pci function %s\n", dev_name(&pdev->dev));
28362803
28372804 nvme_reset_ctrl(&dev->ctrl);
2838− nvme_get_ctrl(&dev->ctrl);
28392805 async_schedule(nvme_async_probe, dev);
28402806
28412807 return 0;
@@ -2907,10 +2873,9 @@ static void nvme_remove(struct pci_dev *pdev) · 65 unmodified lines
29072873 nvme_free_host_mem(dev);
29082874 nvme_dev_remove_admin(dev);
29092875 nvme_free_queues(dev, 0);
2910− nvme_uninit_ctrl(&dev->ctrl);
29112876 nvme_release_prp_pools(dev);
29122877 nvme_dev_unmap(dev);
2913− nvme_put_ctrl(&dev->ctrl);
2878+ nvme_uninit_ctrl(&dev->ctrl);
29142879 }
29152880
29162881 #ifdef CONFIG_PM_SLEEP
drivers/nvme/host/rdma.c+6−3
@@ -1024,8 +1024,13 @@ static int nvme_rdma_setup_ctrl(struct nvme_rdma_ctrl *ctrl, bool new) · 1023 unmodified lines
10241024
10251025 changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE);
10261026 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+ */
10281032 WARN_ON_ONCE(ctrl->ctrl.state != NVME_CTRL_DELETING);
1033+ WARN_ON_ONCE(new);
10291034 ret = -EINVAL;
10301035 goto destroy_io;
10311036 }
@@ -2045,8 +2050,6 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev, · 1013 unmodified lines
20452050 dev_info(ctrl->ctrl.device, "new ctrl: NQN \"%s\", addr %pISpcs\n",
20462051 ctrl->ctrl.opts->subsysnqn, &ctrl->addr);
20472052
2048− nvme_get_ctrl(&ctrl->ctrl);
2049−
20502053 mutex_lock(&nvme_rdma_ctrl_mutex);
20512054 list_add_tail(&ctrl->list, &nvme_rdma_ctrl_list);
20522055 mutex_unlock(&nvme_rdma_ctrl_mutex);
drivers/nvme/host/tcp.c+96−24
@@ -20,6 +20,16 @@ · 19 unmodified lines
2020
2121 struct nvme_tcp_queue;
2222
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+
2333 enum nvme_tcp_send_state {
2434 NVME_TCP_SEND_CMD_PDU = 0,
2535 NVME_TCP_SEND_H2C_PDU,
@@ -1017,8 +1027,15 @@ static int nvme_tcp_try_send(struct nvme_tcp_queue *queue) · 991 unmodified lines
10171027 if (req->state == NVME_TCP_SEND_DDGST)
10181028 ret = nvme_tcp_try_send_ddgst(req);
10191029 done:
1020− if (ret == -EAGAIN)
1030+ if (ret == -EAGAIN) {
10211031 ret = 0;
1032+ } else if (ret < 0) {
1033+ dev_err(queue->ctrl->ctrl.device,
1034+ "failed to send request %d\n", ret);
1035+ if (ret != -EPIPE && ret != -ECONNRESET)
1036+ nvme_tcp_fail_request(queue->request);
1037+ nvme_tcp_done_send_req(queue);
1038+ }
10221039 return ret;
10231040 }
10241041
@@ -1049,25 +1066,16 @@ static void nvme_tcp_io_work(struct work_struct *w) · 24 unmodified lines
10491066 int result;
10501067
10511068 result = nvme_tcp_try_send(queue);
1052− if (result > 0) {
1069+ if (result > 0)
10531070 pending = true;
1054− } else if (unlikely(result < 0)) {
1055− dev_err(queue->ctrl->ctrl.device,
1056− "failed to send request %d\n", result);
1057−
1058− /*
1059− * Fail the request unless peer closed the connection,
1060− * in which case error recovery flow will complete all.
1061− */
1062− if ((result != -EPIPE) && (result != -ECONNRESET))
1063− nvme_tcp_fail_request(queue->request);
1064− nvme_tcp_done_send_req(queue);
1065− return;
1066− }
1071+ else if (unlikely(result < 0))
1072+ break;
10671073
10681074 result = nvme_tcp_try_recv(queue);
10691075 if (result > 0)
10701076 pending = true;
1077+ else if (unlikely(result < 0))
1078+ break;
10711079
10721080 if (!pending)
10731081 return;
@@ -1248,13 +1256,67 @@ free_icreq: · 174 unmodified lines
12481256 return ret;
12491257 }
12501258
1259+static bool nvme_tcp_admin_queue(struct nvme_tcp_queue *queue)
1260+{
1261+ return nvme_tcp_queue_id(queue) == 0;
1262+}
1263+
1264+static bool nvme_tcp_default_queue(struct nvme_tcp_queue *queue)
1265+{
1266+ struct nvme_tcp_ctrl *ctrl = queue->ctrl;
1267+ int qid = nvme_tcp_queue_id(queue);
1268+
1269+ return !nvme_tcp_admin_queue(queue) &&
1270+ qid < 1 + ctrl->io_queues[HCTX_TYPE_DEFAULT];
1271+}
1272+
1273+static bool nvme_tcp_read_queue(struct nvme_tcp_queue *queue)
1274+{
1275+ struct nvme_tcp_ctrl *ctrl = queue->ctrl;
1276+ int qid = nvme_tcp_queue_id(queue);
1277+
1278+ return !nvme_tcp_admin_queue(queue) &&
1279+ !nvme_tcp_default_queue(queue) &&
1280+ qid < 1 + ctrl->io_queues[HCTX_TYPE_DEFAULT] +
1281+ ctrl->io_queues[HCTX_TYPE_READ];
1282+}
1283+
1284+static bool nvme_tcp_poll_queue(struct nvme_tcp_queue *queue)
1285+{
1286+ struct nvme_tcp_ctrl *ctrl = queue->ctrl;
1287+ int qid = nvme_tcp_queue_id(queue);
1288+
1289+ return !nvme_tcp_admin_queue(queue) &&
1290+ !nvme_tcp_default_queue(queue) &&
1291+ !nvme_tcp_read_queue(queue) &&
1292+ qid < 1 + ctrl->io_queues[HCTX_TYPE_DEFAULT] +
1293+ ctrl->io_queues[HCTX_TYPE_READ] +
1294+ ctrl->io_queues[HCTX_TYPE_POLL];
1295+}
1296+
1297+static void nvme_tcp_set_queue_io_cpu(struct nvme_tcp_queue *queue)
1298+{
1299+ struct nvme_tcp_ctrl *ctrl = queue->ctrl;
1300+ int qid = nvme_tcp_queue_id(queue);
1301+ int n = 0;
1302+
1303+ if (nvme_tcp_default_queue(queue))
1304+ n = qid - 1;
1305+ else if (nvme_tcp_read_queue(queue))
1306+ n = qid - ctrl->io_queues[HCTX_TYPE_DEFAULT] - 1;
1307+ else if (nvme_tcp_poll_queue(queue))
1308+ n = qid - ctrl->io_queues[HCTX_TYPE_DEFAULT] -
1309+ ctrl->io_queues[HCTX_TYPE_READ] - 1;
1310+ queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false);
1311+}
1312+
12511313 static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
12521314 int qid, size_t queue_size)
12531315 {
12541316 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl);
12551317 struct nvme_tcp_queue *queue = &ctrl->queues[qid];
12561318 struct linger sol = { .l_onoff = 1, .l_linger = 0 };
1257− int ret, opt, rcv_pdu_size, n;
1319+ int ret, opt, rcv_pdu_size;
12581320
12591321 queue->ctrl = ctrl;
12601322 INIT_LIST_HEAD(&queue->send_list);
@@ -1309,6 +1371,17 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, · 48 unmodified lines
13091371 goto err_sock;
13101372 }
13111373
1374+ if (so_priority > 0) {
1375+ ret = kernel_setsockopt(queue->sock, SOL_SOCKET, SO_PRIORITY,
1376+ (char *)&so_priority, sizeof(so_priority));
1377+ if (ret) {
1378+ dev_err(ctrl->ctrl.device,
1379+ "failed to set SO_PRIORITY sock opt, ret %d\n",
1380+ ret);
1381+ goto err_sock;
1382+ }
1383+ }
1384+
13121385 /* Set socket type of service */
13131386 if (nctrl->opts->tos >= 0) {
13141387 opt = nctrl->opts->tos;
@@ -1322,11 +1395,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, · 7 unmodified lines
13221395 }
13231396
13241397 queue->sock->sk->sk_allocation = GFP_ATOMIC;
1325− if (!qid)
1326− n = 0;
1327− else
1328− n = (qid - 1) % num_online_cpus();
1329− queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false);
1398+ nvme_tcp_set_queue_io_cpu(queue);
13301399 queue->request = NULL;
13311400 queue->data_remaining = 0;
13321401 queue->ddgst_remaining = 0;
@@ -1861,8 +1930,13 @@ static int nvme_tcp_setup_ctrl(struct nvme_ctrl *ctrl, bool new) · 528 unmodified lines
18611930 }
18621931
18631932 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_LIVE)) {
1864− /* state change failure is ok if we're in DELETING state */
1933+ /*
1934+ * state change failure is ok if we're in DELETING state,
1935+ * unless we're during creation of a new controller to
1936+ * avoid races with teardown flow.
1937+ */
18651938 WARN_ON_ONCE(ctrl->state != NVME_CTRL_DELETING);
1939+ WARN_ON_ONCE(new);
18661940 ret = -EINVAL;
18671941 goto destroy_io;
18681942 }
@@ -2359,8 +2433,6 @@ static struct nvme_ctrl *nvme_tcp_create_ctrl(struct device *dev, · 490 unmodified lines
23592433 dev_info(ctrl->ctrl.device, "new ctrl: NQN \"%s\", addr %pISp\n",
23602434 ctrl->ctrl.opts->subsysnqn, &ctrl->addr);
23612435
2362− nvme_get_ctrl(&ctrl->ctrl);
2363−
23642436 mutex_lock(&nvme_tcp_ctrl_mutex);
23652437 list_add_tail(&ctrl->list, &nvme_tcp_ctrl_list);
23662438 mutex_unlock(&nvme_tcp_ctrl_mutex);
drivers/nvme/target/admin-cmd.c+30−4
@@ -323,12 +323,25 @@ static void nvmet_execute_get_log_page(struct nvmet_req *req) · 322 unmodified lines
323323 nvmet_req_complete(req, NVME_SC_INVALID_FIELD | NVME_SC_DNR);
324324 }
325325
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+
326340 static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
327341 {
328342 struct nvmet_ctrl *ctrl = req->sq->ctrl;
329343 struct nvme_id_ctrl *id;
330344 u16 status = 0;
331− const char model[] = "Linux";
332345
333346 id = kzalloc(sizeof(*id), GFP_KERNEL);
334347 if (!id) {
@@ -343,7 +356,7 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req) · 8 unmodified lines
343356 memset(id->sn, ' ', sizeof(id->sn));
344357 bin2hex(id->sn, &ctrl->subsys->serial,
345358 min(sizeof(ctrl->subsys->serial), sizeof(id->sn) / 2));
346− memcpy_and_pad(id->mn, sizeof(id->mn), model, sizeof(model) - 1, ' ');
359+ nvmet_id_set_model_number(id, ctrl->subsys);
347360 memcpy_and_pad(id->fr, sizeof(id->fr),
348361 UTS_RELEASE, strlen(UTS_RELEASE), ' ');
349362
@@ -357,8 +370,12 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req) · 7 unmodified lines
357370 /* we support multiple ports, multiples hosts and ANA: */
358371 id->cmic = (1 << 0) | (1 << 1) | (1 << 3);
359372
360− /* no limit on data transfer sizes for now */
361− id->mdts = 0;
373+ /* Limit MDTS according to transport capability */
374+ if (ctrl->ops->get_mdts)
375+ id->mdts = ctrl->ops->get_mdts(ctrl);
376+ else
377+ id->mdts = 0;
378+
362379 id->cntlid = cpu_to_le16(ctrl->cntlid);
363380 id->ver = cpu_to_le32(ctrl->subsys->ver);
364381
@@ -721,13 +738,22 @@ static void nvmet_execute_set_features(struct nvmet_req *req) · 356 unmodified lines
721738 {
722739 struct nvmet_subsys *subsys = req->sq->ctrl->subsys;
723740 u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10);
741+ u32 cdw11 = le32_to_cpu(req->cmd->common.cdw11);
724742 u16 status = 0;
743+ u16 nsqr;
744+ u16 ncqr;
725745
726746 if (!nvmet_check_data_len(req, 0))
727747 return;
728748
729749 switch (cdw10 & 0xff) {
730750 case NVME_FEAT_NUM_QUEUES:
751+ ncqr = (cdw11 >> 16) & 0xffff;
752+ nsqr = cdw11 & 0xffff;
753+ if (ncqr == 0xffff || nsqr == 0xffff) {
754+ status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
755+ break;
756+ }
731757 nvmet_set_result(req,
732758 (subsys->max_qid - 1) | ((subsys->max_qid - 1) << 16));
733759 break;
drivers/nvme/target/configfs.c+137−9
@@ -395,14 +395,12 @@ static ssize_t nvmet_ns_device_uuid_store(struct config_item *item, · 394 unmodified lines
395395 struct nvmet_subsys *subsys = ns->subsys;
396396 int ret = 0;
397397
398−
399398 mutex_lock(&subsys->lock);
400399 if (ns->enabled) {
401400 ret = -EBUSY;
402401 goto out_unlock;
403402 }
404403
405−
406404 if (uuid_parse(page, &ns->uuid))
407405 ret = -EINVAL;
408406
@@ -815,10 +813,10 @@ static ssize_t nvmet_subsys_attr_version_show(struct config_item *item, · 406 unmodified lines
815813 (int)NVME_MAJOR(subsys->ver),
816814 (int)NVME_MINOR(subsys->ver),
817815 (int)NVME_TERTIARY(subsys->ver));
818− else
819− return snprintf(page, PAGE_SIZE, "%d.%d\n",
820− (int)NVME_MAJOR(subsys->ver),
821− (int)NVME_MINOR(subsys->ver));
816+
817+ return snprintf(page, PAGE_SIZE, "%d.%d\n",
818+ (int)NVME_MAJOR(subsys->ver),
819+ (int)NVME_MINOR(subsys->ver));
822820 }
823821
824822 static ssize_t nvmet_subsys_attr_version_store(struct config_item *item,
@@ -828,7 +826,6 @@ static ssize_t nvmet_subsys_attr_version_store(struct config_item *item, · 3 unmodified lines
828826 int major, minor, tertiary = 0;
829827 int ret;
830828
831−
832829 ret = sscanf(page, "%d.%d.%d\n", &major, &minor, &tertiary);
833830 if (ret != 2 && ret != 3)
834831 return -EINVAL;
@@ -852,20 +849,151 @@ static ssize_t nvmet_subsys_attr_serial_show(struct config_item *item, · 17 unmodified lines
852849 static ssize_t nvmet_subsys_attr_serial_store(struct config_item *item,
853850 const char *page, size_t count)
854851 {
855− struct nvmet_subsys *subsys = to_subsys(item);
852+ u64 serial;
853+
854+ if (sscanf(page, "%llx\n", &serial) != 1)
855+ return -EINVAL;
856856
857857 down_write(&nvmet_config_sem);
858− sscanf(page, "%llx\n", &subsys->serial);
858+ to_subsys(item)->serial = serial;
859859 up_write(&nvmet_config_sem);
860860
861861 return count;
862862 }
863863 CONFIGFS_ATTR(nvmet_subsys_, attr_serial);
864864
865+static ssize_t nvmet_subsys_attr_cntlid_min_show(struct config_item *item,
866+ char *page)
867+{
868+ return snprintf(page, PAGE_SIZE, "%u\n", to_subsys(item)->cntlid_min);
869+}
870+
871+static ssize_t nvmet_subsys_attr_cntlid_min_store(struct config_item *item,
872+ const char *page, size_t cnt)
873+{
874+ u16 cntlid_min;
875+
876+ if (sscanf(page, "%hu\n", &cntlid_min) != 1)
877+ return -EINVAL;
878+
879+ if (cntlid_min == 0)
880+ return -EINVAL;
881+
882+ down_write(&nvmet_config_sem);
883+ if (cntlid_min >= to_subsys(item)->cntlid_max)
884+ goto out_unlock;
885+ to_subsys(item)->cntlid_min = cntlid_min;
886+ up_write(&nvmet_config_sem);
887+ return cnt;
888+
889+out_unlock:
890+ up_write(&nvmet_config_sem);
891+ return -EINVAL;
892+}
893+CONFIGFS_ATTR(nvmet_subsys_, attr_cntlid_min);
894+
895+static ssize_t nvmet_subsys_attr_cntlid_max_show(struct config_item *item,
896+ char *page)
897+{
898+ return snprintf(page, PAGE_SIZE, "%u\n", to_subsys(item)->cntlid_max);
899+}
900+
901+static ssize_t nvmet_subsys_attr_cntlid_max_store(struct config_item *item,
902+ const char *page, size_t cnt)
903+{
904+ u16 cntlid_max;
905+
906+ if (sscanf(page, "%hu\n", &cntlid_max) != 1)
907+ return -EINVAL;
908+
909+ if (cntlid_max == 0)
910+ return -EINVAL;
911+
912+ down_write(&nvmet_config_sem);
913+ if (cntlid_max <= to_subsys(item)->cntlid_min)
914+ goto out_unlock;
915+ to_subsys(item)->cntlid_max = cntlid_max;
916+ up_write(&nvmet_config_sem);
917+ return cnt;
918+
919+out_unlock:
920+ up_write(&nvmet_config_sem);
921+ return -EINVAL;
922+}
923+CONFIGFS_ATTR(nvmet_subsys_, attr_cntlid_max);
924+
925+static ssize_t nvmet_subsys_attr_model_show(struct config_item *item,
926+ char *page)
927+{
928+ struct nvmet_subsys *subsys = to_subsys(item);
929+ struct nvmet_subsys_model *subsys_model;
930+ char *model = NVMET_DEFAULT_CTRL_MODEL;
931+ int ret;
932+
933+ rcu_read_lock();
934+ subsys_model = rcu_dereference(subsys->model);
935+ if (subsys_model)
936+ model = subsys_model->number;
937+ ret = snprintf(page, PAGE_SIZE, "%s\n", model);
938+ rcu_read_unlock();
939+
940+ return ret;
941+}
942+
943+/* See Section 1.5 of NVMe 1.4 */
944+static bool nvmet_is_ascii(const char c)
945+{
946+ return c >= 0x20 && c <= 0x7e;
947+}
948+
949+static ssize_t nvmet_subsys_attr_model_store(struct config_item *item,
950+ const char *page, size_t count)
951+{
952+ struct nvmet_subsys *subsys = to_subsys(item);
953+ struct nvmet_subsys_model *new_model;
954+ char *new_model_number;
955+ int pos = 0, len;
956+
957+ len = strcspn(page, "\n");
958+ if (!len)
959+ return -EINVAL;
960+
961+ for (pos = 0; pos < len; pos++) {
962+ if (!nvmet_is_ascii(page[pos]))
963+ return -EINVAL;
964+ }
965+
966+ new_model_number = kstrndup(page, len, GFP_KERNEL);
967+ if (!new_model_number)
968+ return -ENOMEM;
969+
970+ new_model = kzalloc(sizeof(*new_model) + len + 1, GFP_KERNEL);
971+ if (!new_model) {
972+ kfree(new_model_number);
973+ return -ENOMEM;
974+ }
975+ memcpy(new_model->number, new_model_number, len);
976+
977+ down_write(&nvmet_config_sem);
978+ mutex_lock(&subsys->lock);
979+ new_model = rcu_replace_pointer(subsys->model, new_model,
980+ mutex_is_locked(&subsys->lock));
981+ mutex_unlock(&subsys->lock);
982+ up_write(&nvmet_config_sem);
983+
984+ kfree_rcu(new_model, rcuhead);
985+
986+ return count;
987+}
988+CONFIGFS_ATTR(nvmet_subsys_, attr_model);
989+
865990 static struct configfs_attribute *nvmet_subsys_attrs[] = {
866991 &nvmet_subsys_attr_attr_allow_any_host,
867992 &nvmet_subsys_attr_attr_version,
868993 &nvmet_subsys_attr_attr_serial,
994+ &nvmet_subsys_attr_attr_cntlid_min,
995+ &nvmet_subsys_attr_attr_cntlid_max,
996+ &nvmet_subsys_attr_attr_model,
869997 NULL,
870998 };
871999
drivers/nvme/target/core.c+7−2
@@ -1289,8 +1289,11 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn, · 1288 unmodified lines
12891289 if (!ctrl->sqs)
12901290 goto out_free_cqs;
12911291
1292+ if (subsys->cntlid_min > subsys->cntlid_max)
1293+ goto out_free_cqs;
1294+
12921295 ret = ida_simple_get(&cntlid_ida,
1293− NVME_CNTLID_MIN, NVME_CNTLID_MAX,
1296+ subsys->cntlid_min, subsys->cntlid_max,
12941297 GFP_KERNEL);
12951298 if (ret < 0) {
12961299 status = NVME_SC_CONNECT_CTRL_BUSY | NVME_SC_DNR;
@@ -1438,7 +1441,8 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn, · 141 unmodified lines
14381441 kfree(subsys);
14391442 return ERR_PTR(-ENOMEM);
14401443 }
1441−
1444+ subsys->cntlid_min = NVME_CNTLID_MIN;
1445+ subsys->cntlid_max = NVME_CNTLID_MAX;
14421446 kref_init(&subsys->ref);
14431447
14441448 mutex_init(&subsys->lock);
@@ -1457,6 +1461,7 @@ static void nvmet_subsys_free(struct kref *ref) · 12 unmodified lines
14571461 WARN_ON_ONCE(!list_empty(&subsys->namespaces));
14581462
14591463 kfree(subsys->subsysnqn);
1464+ kfree_rcu(subsys->model, rcuhead);
14601465 kfree(subsys);
14611466 }
14621467
drivers/nvme/target/loop.c+0−3
@@ -485,7 +485,6 @@ out_destroy_admin: · 484 unmodified lines
485485 out_disable:
486486 dev_warn(ctrl->ctrl.device, "Removing after reset failure\n");
487487 nvme_uninit_ctrl(&ctrl->ctrl);
488− nvme_put_ctrl(&ctrl->ctrl);
489488 }
490489
491490 static const struct nvme_ctrl_ops nvme_loop_ctrl_ops = {
@@ -618,8 +617,6 @@ static struct nvme_ctrl *nvme_loop_create_ctrl(struct device *dev, · 126 unmodified lines
618617 dev_info(ctrl->ctrl.device,
619618 "new ctrl: \"%s\"\n", ctrl->ctrl.opts->subsysnqn);
620619
621− nvme_get_ctrl(&ctrl->ctrl);
622−
623620 changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE);
624621 WARN_ON_ONCE(!changed);
625622
drivers/nvme/target/nvmet.h+11−0
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323 #define NVMET_ASYNC_EVENTS 4
2424 #define NVMET_ERROR_LOG_SLOTS 128
2525 #define NVMET_NO_ERROR_LOC ((u16)-1)
26+#define NVMET_DEFAULT_CTRL_MODEL "Linux"
2627
2728 /*
2829 * Supported optional AENs:
@@ -202,6 +203,11 @@ struct nvmet_ctrl { · 173 unmodified lines
202203 struct nvme_error_slot slots[NVMET_ERROR_LOG_SLOTS];
203204 };
204205
206+struct nvmet_subsys_model {
207+ struct rcu_head rcuhead;
208+ char number[];
209+};
210+
205211 struct nvmet_subsys {
206212 enum nvme_subsys_type type;
207213
@@ -211,6 +217,8 @@ struct nvmet_subsys { · 3 unmodified lines
211217 struct list_head namespaces;
212218 unsigned int nr_namespaces;
213219 unsigned int max_nsid;
220+ u16 cntlid_min;
221+ u16 cntlid_max;
214222
215223 struct list_head ctrls;
216224
@@ -227,6 +235,8 @@ struct nvmet_subsys { · 10 unmodified lines
227235
228236 struct config_group namespaces_group;
229237 struct config_group allowed_hosts_group;
238+
239+ struct nvmet_subsys_model __rcu *model;
230240 };
231241
232242 static inline struct nvmet_subsys *to_subsys(struct config_item *item)
@@ -279,6 +289,7 @@ struct nvmet_fabrics_ops { · 46 unmodified lines
279289 struct nvmet_port *port, char *traddr);
280290 u16 (*install_queue)(struct nvmet_sq *nvme_sq);
281291 void (*discovery_chg)(struct nvmet_port *port);
292+ u8 (*get_mdts)(const struct nvmet_ctrl *ctrl);
282293 };
283294
284295 #define NVMET_MAX_INLINE_BIOVEC 8
drivers/nvme/target/rdma.c+13−2
@@ -31,6 +31,9 @@ · 30 unmodified lines
3131 #define NVMET_RDMA_MAX_INLINE_SGE 4
3232 #define NVMET_RDMA_MAX_INLINE_DATA_SIZE max_t(int, SZ_16K, PAGE_SIZE)
3333
34+/* Assume mpsmin == device_page_size == 4KB */
35+#define NVMET_RDMA_MAX_MDTS 8
36+
3437 struct nvmet_rdma_cmd {
3538 struct ib_sge sge[NVMET_RDMA_MAX_INLINE_SGE + 1];
3639 struct ib_cqe cqe;
@@ -975,7 +978,7 @@ static int nvmet_rdma_create_queue_ib(struct nvmet_rdma_queue *queue) · 938 unmodified lines
975978 {
976979 struct ib_qp_init_attr qp_attr;
977980 struct nvmet_rdma_device *ndev = queue->dev;
978− int comp_vector, nr_cqe, ret, i;
981+ int comp_vector, nr_cqe, ret, i, factor;
979982
980983 /*
981984 * Spread the io queues across completion vectors,
@@ -1008,7 +1011,9 @@ static int nvmet_rdma_create_queue_ib(struct nvmet_rdma_queue *queue) · 26 unmodified lines
10081011 qp_attr.qp_type = IB_QPT_RC;
10091012 /* +1 for drain */
10101013 qp_attr.cap.max_send_wr = queue->send_queue_size + 1;
1011− qp_attr.cap.max_rdma_ctxs = queue->send_queue_size;
1014+ factor = rdma_rw_mr_factor(ndev->device, queue->cm_id->port_num,
1015+ 1 << NVMET_RDMA_MAX_MDTS);
1016+ qp_attr.cap.max_rdma_ctxs = queue->send_queue_size * factor;
10121017 qp_attr.cap.max_send_sge = max(ndev->device->attrs.max_sge_rd,
10131018 ndev->device->attrs.max_send_sge);
10141019
@@ -1602,6 +1607,11 @@ static void nvmet_rdma_disc_port_addr(struct nvmet_req *req, · 587 unmodified lines
16021607 }
16031608 }
16041609
1610+static u8 nvmet_rdma_get_mdts(const struct nvmet_ctrl *ctrl)
1611+{
1612+ return NVMET_RDMA_MAX_MDTS;
1613+}
1614+
16051615 static const struct nvmet_fabrics_ops nvmet_rdma_ops = {
16061616 .owner = THIS_MODULE,
16071617 .type = NVMF_TRTYPE_RDMA,
@@ -1612,6 +1622,7 @@ static const struct nvmet_fabrics_ops nvmet_rdma_ops = { · 4 unmodified lines
16121622 .queue_response = nvmet_rdma_queue_response,
16131623 .delete_ctrl = nvmet_rdma_delete_ctrl,
16141624 .disc_traddr = nvmet_rdma_disc_port_addr,
1625+ .get_mdts = nvmet_rdma_get_mdts,
16151626 };
16161627
16171628 static void nvmet_rdma_remove_one(struct ib_device *ib_device, void *client_data)
drivers/nvme/target/tcp.c+32−3
@@ -19,6 +19,16 @@ · 18 unmodified lines
1919
2020 #define NVMET_TCP_DEF_INLINE_DATA_SIZE (4 * PAGE_SIZE)
2121
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+
2232 #define NVMET_TCP_RECV_BUDGET 8
2333 #define NVMET_TCP_SEND_BUDGET 8
2434 #define NVMET_TCP_IO_WORK_BUDGET 64
@@ -622,7 +632,7 @@ static int nvmet_try_send_r2t(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · 597 unmodified lines
622632 return 1;
623633 }
624634
625−static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd)
635+static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)
626636 {
627637 struct nvmet_tcp_queue *queue = cmd->queue;
628638 struct msghdr msg = { .msg_flags = MSG_DONTWAIT };
@@ -632,6 +642,9 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd) · 3 unmodified lines
632642 };
633643 int ret;
634644
645+ if (!last_in_batch && cmd->queue->send_list_len)
646+ msg.msg_flags |= MSG_MORE;
647+
635648 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len);
636649 if (unlikely(ret <= 0))
637650 return ret;
@@ -672,7 +685,7 @@ static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue, · 34 unmodified lines
672685 }
673686
674687 if (cmd->state == NVMET_TCP_SEND_DDGST) {
675− ret = nvmet_try_send_ddgst(cmd);
688+ ret = nvmet_try_send_ddgst(cmd, last_in_batch);
676689 if (ret <= 0)
677690 goto done_send;
678691 }
@@ -794,7 +807,7 @@ static int nvmet_tcp_handle_icreq(struct nvmet_tcp_queue *queue) · 115 unmodified lines
794807 icresp->hdr.pdo = 0;
795808 icresp->hdr.plen = cpu_to_le32(icresp->hdr.hlen);
796809 icresp->pfv = cpu_to_le16(NVME_TCP_PFV_1_0);
797− icresp->maxdata = cpu_to_le32(0xffff); /* FIXME: support r2t */
810+ icresp->maxdata = cpu_to_le32(0x400000); /* 16M arbitrary limit */
798811 icresp->cpda = 0;
799812 if (queue->hdr_digest)
800813 icresp->digest |= NVME_TCP_HDR_DIGEST_ENABLE;
@@ -1439,6 +1452,13 @@ static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue) · 638 unmodified lines
14391452 if (ret)
14401453 return ret;
14411454
1455+ if (so_priority > 0) {
1456+ ret = kernel_setsockopt(sock, SOL_SOCKET, SO_PRIORITY,
1457+ (char *)&so_priority, sizeof(so_priority));
1458+ if (ret)
1459+ return ret;
1460+ }
1461+
14421462 /* Set socket type of service */
14431463 if (inet->rcv_tos > 0) {
14441464 int tos = inet->rcv_tos;
@@ -1628,6 +1648,15 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport) · 183 unmodified lines
16281648 goto err_sock;
16291649 }
16301650
1651+ if (so_priority > 0) {
1652+ ret = kernel_setsockopt(port->sock, SOL_SOCKET, SO_PRIORITY,
1653+ (char *)&so_priority, sizeof(so_priority));
1654+ if (ret) {
1655+ pr_err("failed to set SO_PRIORITY sock opt %d\n", ret);
1656+ goto err_sock;
1657+ }
1658+ }
1659+
16311660 ret = kernel_bind(port->sock, (struct sockaddr *)&port->addr,
16321661 sizeof(port->addr));
16331662 if (ret) {
include/linux/blkdev.h+4−0
@@ -952,6 +952,10 @@ static inline unsigned int blk_rq_stats_sectors(const struct request *rq) · 951 unmodified lines
952952 }
953953
954954 #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+
955959 static inline unsigned int blk_rq_zone_no(struct request *rq)
956960 {
957961 return blk_queue_zone_no(rq->q, blk_rq_pos(rq));
include/uapi/linux/fdreg.h+5−13
@@ -7,26 +7,18 @@ · 6 unmodified lines
77 * Handbook", Sanches and Canton.
88 */
99
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−
1810 /* 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
2113
2214 /* Digital Output Register */
23−#define FD_DOR (2 + FD_IOPORT )
15+#define FD_DOR 2
2416
2517 /* Digital Input Register (read) */
26−#define FD_DIR (7 + FD_IOPORT )
18+#define FD_DIR 7
2719
2820 /* Diskette Control Register (write)*/
29−#define FD_DCR (7 + FD_IOPORT )
21+#define FD_DCR 7
3022
3123 /* Bits of main status register */
3224 #define STATUS_BUSYMASK 0x0F /* drive busy mask */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t