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