2019-05-19 12:08:20 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* drivers/block/ataflop.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993 Greg Harp
|
|
|
|
* Atari Support by Bjoern Brauel, Roman Hodek
|
|
|
|
*
|
|
|
|
* Big cleanup Sep 11..14 1994 Roman Hodek:
|
|
|
|
* - Driver now works interrupt driven
|
|
|
|
* - Support for two drives; should work, but I cannot test that :-(
|
|
|
|
* - Reading is done in whole tracks and buffered to speed up things
|
|
|
|
* - Disk change detection and drive deselecting after motor-off
|
|
|
|
* similar to TOS
|
|
|
|
* - Autodetection of disk format (DD/HD); untested yet, because I
|
|
|
|
* don't have an HD drive :-(
|
|
|
|
*
|
|
|
|
* Fixes Nov 13 1994 Martin Schaller:
|
|
|
|
* - Autodetection works now
|
|
|
|
* - Support for 5 1/4'' disks
|
|
|
|
* - Removed drive type (unknown on atari)
|
|
|
|
* - Do seeks with 8 Mhz
|
|
|
|
*
|
|
|
|
* Changes by Andreas Schwab:
|
|
|
|
* - After errors in multiple read mode try again reading single sectors
|
|
|
|
* (Feb 1995):
|
|
|
|
* - Clean up error handling
|
|
|
|
* - Set blk_size for proper size checking
|
|
|
|
* - Initialize track register when testing presence of floppy
|
|
|
|
* - Implement some ioctl's
|
|
|
|
*
|
|
|
|
* Changes by Torsten Lang:
|
|
|
|
* - When probing the floppies we should add the FDCCMDADD_H flag since
|
|
|
|
* the FDC will otherwise wait forever when no disk is inserted...
|
|
|
|
*
|
|
|
|
* ++ Freddi Aschwanden (fa) 20.9.95 fixes for medusa:
|
|
|
|
* - MFPDELAY() after each FDC access -> atari
|
|
|
|
* - more/other disk formats
|
|
|
|
* - DMA to the block buffer directly if we have a 32bit DMA
|
|
|
|
* - for medusa, the step rate is always 3ms
|
|
|
|
* - on medusa, use only cache_push()
|
|
|
|
* Roman:
|
|
|
|
* - Make disk format numbering independent from minors
|
|
|
|
* - Let user set max. supported drive type (speeds up format
|
|
|
|
* detection, saves buffer space)
|
|
|
|
*
|
|
|
|
* Roman 10/15/95:
|
|
|
|
* - implement some more ioctls
|
|
|
|
* - disk formatting
|
|
|
|
*
|
|
|
|
* Andreas 95/12/12:
|
|
|
|
* - increase gap size at start of track for HD/ED disks
|
|
|
|
*
|
|
|
|
* Michael (MSch) 11/07/96:
|
|
|
|
* - implemented FDSETPRM and FDDEFPRM ioctl
|
|
|
|
*
|
|
|
|
* Andreas (97/03/19):
|
|
|
|
* - implemented missing BLK* ioctls
|
|
|
|
*
|
|
|
|
* Things left to do:
|
|
|
|
* - Formatting
|
|
|
|
* - Maybe a better strategy for disk change detection (does anyone
|
|
|
|
* know one?)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
#include <linux/fd.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/init.h>
|
2018-10-15 15:18:24 +00:00
|
|
|
#include <linux/blk-mq.h>
|
2021-09-20 12:33:25 +00:00
|
|
|
#include <linux/major.h>
|
2010-06-02 12:28:52 +00:00
|
|
|
#include <linux/mutex.h>
|
2014-02-26 11:01:41 +00:00
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/wait.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include <asm/atariints.h>
|
|
|
|
#include <asm/atari_stdma.h>
|
|
|
|
#include <asm/atari_stram.h>
|
|
|
|
|
|
|
|
#define FD_MAX_UNITS 2
|
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
2010-06-02 12:28:52 +00:00
|
|
|
static DEFINE_MUTEX(ataflop_mutex);
|
2009-05-08 02:54:03 +00:00
|
|
|
static struct request *fd_request;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-10-11 19:20:48 +00:00
|
|
|
/*
|
|
|
|
* WD1772 stuff
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* register codes */
|
|
|
|
|
|
|
|
#define FDCSELREG_STP (0x80) /* command/status register */
|
|
|
|
#define FDCSELREG_TRA (0x82) /* track register */
|
|
|
|
#define FDCSELREG_SEC (0x84) /* sector register */
|
|
|
|
#define FDCSELREG_DTA (0x86) /* data register */
|
|
|
|
|
|
|
|
/* register names for FDC_READ/WRITE macros */
|
|
|
|
|
|
|
|
#define FDCREG_CMD 0
|
|
|
|
#define FDCREG_STATUS 0
|
|
|
|
#define FDCREG_TRACK 2
|
|
|
|
#define FDCREG_SECTOR 4
|
|
|
|
#define FDCREG_DATA 6
|
|
|
|
|
|
|
|
/* command opcodes */
|
|
|
|
|
|
|
|
#define FDCCMD_RESTORE (0x00) /* - */
|
|
|
|
#define FDCCMD_SEEK (0x10) /* | */
|
|
|
|
#define FDCCMD_STEP (0x20) /* | TYP 1 Commands */
|
|
|
|
#define FDCCMD_STIN (0x40) /* | */
|
|
|
|
#define FDCCMD_STOT (0x60) /* - */
|
|
|
|
#define FDCCMD_RDSEC (0x80) /* - TYP 2 Commands */
|
|
|
|
#define FDCCMD_WRSEC (0xa0) /* - " */
|
|
|
|
#define FDCCMD_RDADR (0xc0) /* - */
|
|
|
|
#define FDCCMD_RDTRA (0xe0) /* | TYP 3 Commands */
|
|
|
|
#define FDCCMD_WRTRA (0xf0) /* - */
|
|
|
|
#define FDCCMD_FORCI (0xd0) /* - TYP 4 Command */
|
|
|
|
|
|
|
|
/* command modifier bits */
|
|
|
|
|
|
|
|
#define FDCCMDADD_SR6 (0x00) /* step rate settings */
|
|
|
|
#define FDCCMDADD_SR12 (0x01)
|
|
|
|
#define FDCCMDADD_SR2 (0x02)
|
|
|
|
#define FDCCMDADD_SR3 (0x03)
|
|
|
|
#define FDCCMDADD_V (0x04) /* verify */
|
|
|
|
#define FDCCMDADD_H (0x08) /* wait for spin-up */
|
|
|
|
#define FDCCMDADD_U (0x10) /* update track register */
|
|
|
|
#define FDCCMDADD_M (0x10) /* multiple sector access */
|
|
|
|
#define FDCCMDADD_E (0x04) /* head settling flag */
|
|
|
|
#define FDCCMDADD_P (0x02) /* precompensation off */
|
|
|
|
#define FDCCMDADD_A0 (0x01) /* DAM flag */
|
|
|
|
|
|
|
|
/* status register bits */
|
|
|
|
|
|
|
|
#define FDCSTAT_MOTORON (0x80) /* motor on */
|
|
|
|
#define FDCSTAT_WPROT (0x40) /* write protected (FDCCMD_WR*) */
|
|
|
|
#define FDCSTAT_SPINUP (0x20) /* motor speed stable (Type I) */
|
|
|
|
#define FDCSTAT_DELDAM (0x20) /* sector has deleted DAM (Type II+III) */
|
|
|
|
#define FDCSTAT_RECNF (0x10) /* record not found */
|
|
|
|
#define FDCSTAT_CRC (0x08) /* CRC error */
|
|
|
|
#define FDCSTAT_TR00 (0x04) /* Track 00 flag (Type I) */
|
|
|
|
#define FDCSTAT_LOST (0x04) /* Lost Data (Type II+III) */
|
|
|
|
#define FDCSTAT_IDX (0x02) /* Index status (Type I) */
|
|
|
|
#define FDCSTAT_DRQ (0x02) /* DRQ status (Type II+III) */
|
|
|
|
#define FDCSTAT_BUSY (0x01) /* FDC is busy */
|
|
|
|
|
|
|
|
|
|
|
|
/* PSG Port A Bit Nr 0 .. Side Sel .. 0 -> Side 1 1 -> Side 2 */
|
|
|
|
#define DSKSIDE (0x01)
|
|
|
|
|
|
|
|
#define DSKDRVNONE (0x06)
|
|
|
|
#define DSKDRV0 (0x02)
|
|
|
|
#define DSKDRV1 (0x04)
|
|
|
|
|
|
|
|
/* step rates */
|
|
|
|
#define FDCSTEP_6 0x00
|
|
|
|
#define FDCSTEP_12 0x01
|
|
|
|
#define FDCSTEP_2 0x02
|
|
|
|
#define FDCSTEP_3 0x03
|
|
|
|
|
|
|
|
struct atari_format_descr {
|
|
|
|
int track; /* to be formatted */
|
|
|
|
int head; /* "" "" */
|
|
|
|
int sect_offset; /* offset of first sector */
|
|
|
|
};
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Disk types: DD, HD, ED */
|
|
|
|
static struct atari_disk_type {
|
|
|
|
const char *name;
|
|
|
|
unsigned spt; /* sectors per track */
|
|
|
|
unsigned blocks; /* total number of blocks */
|
|
|
|
unsigned fdc_speed; /* fdc_speed setting */
|
|
|
|
unsigned stretch; /* track doubling ? */
|
2008-02-06 09:38:09 +00:00
|
|
|
} atari_disk_type[] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
{ "d360", 9, 720, 0, 0}, /* 0: 360kB diskette */
|
|
|
|
{ "D360", 9, 720, 0, 1}, /* 1: 360kb in 720k or 1.2MB drive */
|
|
|
|
{ "D720", 9,1440, 0, 0}, /* 2: 720kb in 720k or 1.2MB drive */
|
|
|
|
{ "D820", 10,1640, 0, 0}, /* 3: DD disk with 82 tracks/10 sectors */
|
|
|
|
/* formats above are probed for type DD */
|
|
|
|
#define MAX_TYPE_DD 3
|
|
|
|
{ "h1200",15,2400, 3, 0}, /* 4: 1.2MB diskette */
|
|
|
|
{ "H1440",18,2880, 3, 0}, /* 5: 1.4 MB diskette (HD) */
|
|
|
|
{ "H1640",20,3280, 3, 0}, /* 6: 1.64MB diskette (fat HD) 82 tr 20 sec */
|
|
|
|
/* formats above are probed for types DD and HD */
|
|
|
|
#define MAX_TYPE_HD 6
|
|
|
|
{ "E2880",36,5760, 3, 0}, /* 7: 2.8 MB diskette (ED) */
|
|
|
|
{ "E3280",40,6560, 3, 0}, /* 8: 3.2 MB diskette (fat ED) 82 tr 40 sec */
|
|
|
|
/* formats above are probed for types DD, HD and ED */
|
|
|
|
#define MAX_TYPE_ED 8
|
|
|
|
/* types below are never autoprobed */
|
|
|
|
{ "H1680",21,3360, 3, 0}, /* 9: 1.68MB diskette (fat HD) 80 tr 21 sec */
|
|
|
|
{ "h410",10,820, 0, 1}, /* 10: 410k diskette 41 tr 10 sec, stretch */
|
|
|
|
{ "h1476",18,2952, 3, 0}, /* 11: 1.48MB diskette 82 tr 18 sec */
|
|
|
|
{ "H1722",21,3444, 3, 0}, /* 12: 1.72MB diskette 82 tr 21 sec */
|
|
|
|
{ "h420",10,840, 0, 1}, /* 13: 420k diskette 42 tr 10 sec, stretch */
|
|
|
|
{ "H830",10,1660, 0, 0}, /* 14: 820k diskette 83 tr 10 sec */
|
|
|
|
{ "h1494",18,2952, 3, 0}, /* 15: 1.49MB diskette 83 tr 18 sec */
|
|
|
|
{ "H1743",21,3486, 3, 0}, /* 16: 1.74MB diskette 83 tr 21 sec */
|
|
|
|
{ "h880",11,1760, 0, 0}, /* 17: 880k diskette 80 tr 11 sec */
|
|
|
|
{ "D1040",13,2080, 0, 0}, /* 18: 1.04MB diskette 80 tr 13 sec */
|
|
|
|
{ "D1120",14,2240, 0, 0}, /* 19: 1.12MB diskette 80 tr 14 sec */
|
|
|
|
{ "h1600",20,3200, 3, 0}, /* 20: 1.60MB diskette 80 tr 20 sec */
|
|
|
|
{ "H1760",22,3520, 3, 0}, /* 21: 1.76MB diskette 80 tr 22 sec */
|
|
|
|
{ "H1920",24,3840, 3, 0}, /* 22: 1.92MB diskette 80 tr 24 sec */
|
|
|
|
{ "E3200",40,6400, 3, 0}, /* 23: 3.2MB diskette 80 tr 40 sec */
|
|
|
|
{ "E3520",44,7040, 3, 0}, /* 24: 3.52MB diskette 80 tr 44 sec */
|
|
|
|
{ "E3840",48,7680, 3, 0}, /* 25: 3.84MB diskette 80 tr 48 sec */
|
|
|
|
{ "H1840",23,3680, 3, 0}, /* 26: 1.84MB diskette 80 tr 23 sec */
|
|
|
|
{ "D800",10,1600, 0, 0}, /* 27: 800k diskette 80 tr 10 sec */
|
|
|
|
};
|
|
|
|
|
|
|
|
static int StartDiskType[] = {
|
|
|
|
MAX_TYPE_DD,
|
|
|
|
MAX_TYPE_HD,
|
|
|
|
MAX_TYPE_ED
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TYPE_DD 0
|
|
|
|
#define TYPE_HD 1
|
|
|
|
#define TYPE_ED 2
|
|
|
|
|
|
|
|
static int DriveType = TYPE_HD;
|
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(ataflop_lock);
|
|
|
|
|
|
|
|
/* Array for translating minors into disk formats */
|
|
|
|
static struct {
|
|
|
|
int index;
|
|
|
|
unsigned drive_types;
|
|
|
|
} minor2disktype[] = {
|
|
|
|
{ 0, TYPE_DD }, /* 1: d360 */
|
|
|
|
{ 4, TYPE_HD }, /* 2: h1200 */
|
|
|
|
{ 1, TYPE_DD }, /* 3: D360 */
|
|
|
|
{ 2, TYPE_DD }, /* 4: D720 */
|
|
|
|
{ 1, TYPE_DD }, /* 5: h360 = D360 */
|
|
|
|
{ 2, TYPE_DD }, /* 6: h720 = D720 */
|
|
|
|
{ 5, TYPE_HD }, /* 7: H1440 */
|
|
|
|
{ 7, TYPE_ED }, /* 8: E2880 */
|
|
|
|
/* some PC formats :-) */
|
|
|
|
{ 8, TYPE_ED }, /* 9: E3280 <- was "CompaQ" == E2880 for PC */
|
|
|
|
{ 5, TYPE_HD }, /* 10: h1440 = H1440 */
|
|
|
|
{ 9, TYPE_HD }, /* 11: H1680 */
|
|
|
|
{ 10, TYPE_DD }, /* 12: h410 */
|
|
|
|
{ 3, TYPE_DD }, /* 13: H820 <- == D820, 82x10 */
|
|
|
|
{ 11, TYPE_HD }, /* 14: h1476 */
|
|
|
|
{ 12, TYPE_HD }, /* 15: H1722 */
|
|
|
|
{ 13, TYPE_DD }, /* 16: h420 */
|
|
|
|
{ 14, TYPE_DD }, /* 17: H830 */
|
|
|
|
{ 15, TYPE_HD }, /* 18: h1494 */
|
|
|
|
{ 16, TYPE_HD }, /* 19: H1743 */
|
|
|
|
{ 17, TYPE_DD }, /* 20: h880 */
|
|
|
|
{ 18, TYPE_DD }, /* 21: D1040 */
|
|
|
|
{ 19, TYPE_DD }, /* 22: D1120 */
|
|
|
|
{ 20, TYPE_HD }, /* 23: h1600 */
|
|
|
|
{ 21, TYPE_HD }, /* 24: H1760 */
|
|
|
|
{ 22, TYPE_HD }, /* 25: H1920 */
|
|
|
|
{ 23, TYPE_ED }, /* 26: E3200 */
|
|
|
|
{ 24, TYPE_ED }, /* 27: E3520 */
|
|
|
|
{ 25, TYPE_ED }, /* 28: E3840 */
|
|
|
|
{ 26, TYPE_HD }, /* 29: H1840 */
|
|
|
|
{ 27, TYPE_DD }, /* 30: D800 */
|
|
|
|
{ 6, TYPE_HD }, /* 31: H1640 <- was H1600 == h1600 for PC */
|
|
|
|
};
|
|
|
|
|
2006-01-08 09:05:11 +00:00
|
|
|
#define NUM_DISK_MINORS ARRAY_SIZE(minor2disktype)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Maximum disk size (in kilobytes). This default is used whenever the
|
|
|
|
* current disk size is unknown.
|
|
|
|
*/
|
|
|
|
#define MAX_DISK_SIZE 3280
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MSch: User-provided type information. 'drive' points to
|
|
|
|
* the respective entry of this array. Set by FDSETPRM ioctls.
|
|
|
|
*/
|
|
|
|
static struct atari_disk_type user_params[FD_MAX_UNITS];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* User-provided permanent type information. 'drive' points to
|
|
|
|
* the respective entry of this array. Set by FDDEFPRM ioctls,
|
|
|
|
* restored upon disk change by floppy_revalidate() if valid (as seen by
|
|
|
|
* default_params[].blocks > 0 - a bit in unit[].flags might be used for this?)
|
|
|
|
*/
|
|
|
|
static struct atari_disk_type default_params[FD_MAX_UNITS];
|
|
|
|
|
|
|
|
/* current info on each unit */
|
|
|
|
static struct atari_floppy_struct {
|
|
|
|
int connected; /* !=0 : drive is connected */
|
|
|
|
int autoprobe; /* !=0 : do autoprobe */
|
|
|
|
|
|
|
|
struct atari_disk_type *disktype; /* current type of disk */
|
|
|
|
|
|
|
|
int track; /* current head position or -1 if
|
|
|
|
unknown */
|
|
|
|
unsigned int steprate; /* steprate setting */
|
|
|
|
unsigned int wpstat; /* current state of WP signal (for
|
|
|
|
disk change detection) */
|
|
|
|
int flags; /* flags */
|
2020-10-29 14:58:38 +00:00
|
|
|
struct gendisk *disk[NUM_DISK_MINORS];
|
2021-09-27 22:03:00 +00:00
|
|
|
bool registered[NUM_DISK_MINORS];
|
2005-04-16 22:20:36 +00:00
|
|
|
int ref;
|
|
|
|
int type;
|
2018-10-15 15:18:24 +00:00
|
|
|
struct blk_mq_tag_set tag_set;
|
2022-05-08 09:37:08 +00:00
|
|
|
int error_count;
|
2005-04-16 22:20:36 +00:00
|
|
|
} unit[FD_MAX_UNITS];
|
|
|
|
|
|
|
|
#define UD unit[drive]
|
|
|
|
#define UDT unit[drive].disktype
|
|
|
|
#define SUD unit[SelectedDrive]
|
|
|
|
#define SUDT unit[SelectedDrive].disktype
|
|
|
|
|
|
|
|
|
|
|
|
#define FDC_READ(reg) ({ \
|
|
|
|
/* unsigned long __flags; */ \
|
|
|
|
unsigned short __val; \
|
|
|
|
/* local_irq_save(__flags); */ \
|
|
|
|
dma_wd.dma_mode_status = 0x80 | (reg); \
|
|
|
|
udelay(25); \
|
|
|
|
__val = dma_wd.fdc_acces_seccount; \
|
|
|
|
MFPDELAY(); \
|
|
|
|
/* local_irq_restore(__flags); */ \
|
|
|
|
__val & 0xff; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define FDC_WRITE(reg,val) \
|
|
|
|
do { \
|
|
|
|
/* unsigned long __flags; */ \
|
|
|
|
/* local_irq_save(__flags); */ \
|
|
|
|
dma_wd.dma_mode_status = 0x80 | (reg); \
|
|
|
|
udelay(25); \
|
|
|
|
dma_wd.fdc_acces_seccount = (val); \
|
|
|
|
MFPDELAY(); \
|
|
|
|
/* local_irq_restore(__flags); */ \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
|
|
/* Buffering variables:
|
|
|
|
* First, there is a DMA buffer in ST-RAM that is used for floppy DMA
|
|
|
|
* operations. Second, a track buffer is used to cache a whole track
|
|
|
|
* of the disk to save read operations. These are two separate buffers
|
|
|
|
* because that allows write operations without clearing the track buffer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int MaxSectors[] = {
|
|
|
|
11, 22, 44
|
|
|
|
};
|
|
|
|
static int BufferSize[] = {
|
|
|
|
15*512, 30*512, 60*512
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BUFFER_SIZE (BufferSize[DriveType])
|
|
|
|
|
|
|
|
unsigned char *DMABuffer; /* buffer for writes */
|
|
|
|
static unsigned long PhysDMABuffer; /* physical address */
|
|
|
|
|
|
|
|
static int UseTrackbuffer = -1; /* Do track buffering? */
|
2006-03-25 11:07:05 +00:00
|
|
|
module_param(UseTrackbuffer, int, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
unsigned char *TrackBuffer; /* buffer for reads */
|
|
|
|
static unsigned long PhysTrackBuffer; /* physical address */
|
|
|
|
static int BufferDrive, BufferSide, BufferTrack;
|
|
|
|
static int read_track; /* non-zero if we are reading whole tracks */
|
|
|
|
|
|
|
|
#define SECTOR_BUFFER(sec) (TrackBuffer + ((sec)-1)*512)
|
|
|
|
#define IS_BUFFERED(drive,side,track) \
|
|
|
|
(BufferDrive == (drive) && BufferSide == (side) && BufferTrack == (track))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These are global variables, as that's the easiest way to give
|
|
|
|
* information to interrupts. They are the data used for the current
|
|
|
|
* request.
|
|
|
|
*/
|
|
|
|
static int SelectedDrive = 0;
|
|
|
|
static int ReqCmd, ReqBlock;
|
|
|
|
static int ReqSide, ReqTrack, ReqSector, ReqCnt;
|
|
|
|
static int HeadSettleFlag = 0;
|
|
|
|
static unsigned char *ReqData, *ReqBuffer;
|
|
|
|
static int MotorOn = 0, MotorOffTrys;
|
|
|
|
static int IsFormatting = 0, FormatError;
|
|
|
|
|
|
|
|
static int UserSteprate[FD_MAX_UNITS] = { -1, -1 };
|
2006-03-25 11:07:05 +00:00
|
|
|
module_param_array(UserSteprate, int, NULL, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-02-26 11:01:41 +00:00
|
|
|
static DECLARE_COMPLETION(format_wait);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static unsigned long changed_floppies = 0xff, fake_change = 0;
|
|
|
|
#define CHECK_CHANGE_DELAY HZ/2
|
|
|
|
|
|
|
|
#define FD_MOTOR_OFF_DELAY (3*HZ)
|
|
|
|
#define FD_MOTOR_OFF_MAXTRY (10*20)
|
|
|
|
|
|
|
|
#define FLOPPY_TIMEOUT (6*HZ)
|
|
|
|
#define RECALIBRATE_ERRORS 4 /* After this many errors the drive
|
|
|
|
* will be recalibrated. */
|
|
|
|
#define MAX_ERRORS 8 /* After this many errors the driver
|
|
|
|
* will give up. */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The driver is trying to determine the correct media format
|
|
|
|
* while Probing is set. fd_rwsec_done() clears it after a
|
|
|
|
* successful access.
|
|
|
|
*/
|
|
|
|
static int Probing = 0;
|
|
|
|
|
|
|
|
/* This flag is set when a dummy seek is necessary to make the WP
|
|
|
|
* status bit accessible.
|
|
|
|
*/
|
|
|
|
static int NeedSeek = 0;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define DPRINT(a) printk a
|
|
|
|
#else
|
|
|
|
#define DPRINT(a)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/***************************** Prototypes *****************************/
|
|
|
|
|
|
|
|
static void fd_select_side( int side );
|
|
|
|
static void fd_select_drive( int drive );
|
|
|
|
static void fd_deselect( void );
|
2017-08-28 18:28:21 +00:00
|
|
|
static void fd_motor_off_timer(struct timer_list *unused);
|
|
|
|
static void check_change(struct timer_list *unused);
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static irqreturn_t floppy_irq (int irq, void *dummy);
|
2005-04-16 22:20:36 +00:00
|
|
|
static void fd_error( void );
|
|
|
|
static int do_format(int drive, int type, struct atari_format_descr *desc);
|
|
|
|
static void do_fd_action( int drive );
|
|
|
|
static void fd_calibrate( void );
|
|
|
|
static void fd_calibrate_done( int status );
|
|
|
|
static void fd_seek( void );
|
|
|
|
static void fd_seek_done( int status );
|
|
|
|
static void fd_rwsec( void );
|
2017-08-28 18:28:21 +00:00
|
|
|
static void fd_readtrack_check(struct timer_list *unused);
|
2005-04-16 22:20:36 +00:00
|
|
|
static void fd_rwsec_done( int status );
|
|
|
|
static void fd_rwsec_done1(int status);
|
|
|
|
static void fd_writetrack( void );
|
|
|
|
static void fd_writetrack_done( int status );
|
2017-08-28 18:28:21 +00:00
|
|
|
static void fd_times_out(struct timer_list *unused);
|
2005-04-16 22:20:36 +00:00
|
|
|
static void finish_fdc( void );
|
|
|
|
static void finish_fdc_done( int dummy );
|
|
|
|
static void setup_req_params( int drive );
|
2023-06-08 11:02:55 +00:00
|
|
|
static int fd_locked_ioctl(struct block_device *bdev, blk_mode_t mode,
|
|
|
|
unsigned int cmd, unsigned long param);
|
2005-04-16 22:20:36 +00:00
|
|
|
static void fd_probe( int drive );
|
|
|
|
static int fd_test_drive_present( int drive );
|
|
|
|
static void config_types( void );
|
2023-06-08 11:02:55 +00:00
|
|
|
static int floppy_open(struct gendisk *disk, blk_mode_t mode);
|
2023-06-08 11:02:37 +00:00
|
|
|
static void floppy_release(struct gendisk *disk);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/************************* End of Prototypes **************************/
|
|
|
|
|
2017-10-04 23:27:04 +00:00
|
|
|
static DEFINE_TIMER(motor_off_timer, fd_motor_off_timer);
|
|
|
|
static DEFINE_TIMER(readtrack_timer, fd_readtrack_check);
|
|
|
|
static DEFINE_TIMER(timeout_timer, fd_times_out);
|
|
|
|
static DEFINE_TIMER(fd_timer, check_change);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-06-03 07:38:04 +00:00
|
|
|
static void fd_end_request_cur(blk_status_t err)
|
2009-05-08 02:54:03 +00:00
|
|
|
{
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
DPRINT(("fd_end_request_cur(), bytes %d of %d\n",
|
|
|
|
blk_rq_cur_bytes(fd_request),
|
|
|
|
blk_rq_bytes(fd_request)));
|
|
|
|
|
2018-10-15 15:18:24 +00:00
|
|
|
if (!blk_update_request(fd_request, err,
|
|
|
|
blk_rq_cur_bytes(fd_request))) {
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
DPRINT(("calling __blk_mq_end_request()\n"));
|
2018-10-15 15:18:24 +00:00
|
|
|
__blk_mq_end_request(fd_request, err);
|
2009-05-08 02:54:03 +00:00
|
|
|
fd_request = NULL;
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
} else {
|
|
|
|
/* requeue rest of request */
|
|
|
|
DPRINT(("calling blk_mq_requeue_request()\n"));
|
|
|
|
blk_mq_requeue_request(fd_request, true);
|
|
|
|
fd_request = NULL;
|
2018-10-15 15:18:24 +00:00
|
|
|
}
|
2009-05-08 02:54:03 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static inline void start_motor_off_timer(void)
|
|
|
|
{
|
|
|
|
mod_timer(&motor_off_timer, jiffies + FD_MOTOR_OFF_DELAY);
|
|
|
|
MotorOffTrys = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void start_check_change_timer( void )
|
|
|
|
{
|
|
|
|
mod_timer(&fd_timer, jiffies + CHECK_CHANGE_DELAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void start_timeout(void)
|
|
|
|
{
|
|
|
|
mod_timer(&timeout_timer, jiffies + FLOPPY_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void stop_timeout(void)
|
|
|
|
{
|
|
|
|
del_timer(&timeout_timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Select the side to use. */
|
|
|
|
|
|
|
|
static void fd_select_side( int side )
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/* protect against various other ints mucking around with the PSG */
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
sound_ym.rd_data_reg_sel = 14; /* Select PSG Port A */
|
|
|
|
sound_ym.wd_data = (side == 0) ? sound_ym.rd_data_reg_sel | 0x01 :
|
|
|
|
sound_ym.rd_data_reg_sel & 0xfe;
|
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Select a drive, update the FDC's track register and set the correct
|
|
|
|
* clock speed for this disk's type.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void fd_select_drive( int drive )
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned char tmp;
|
|
|
|
|
|
|
|
if (drive == SelectedDrive)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* protect against various other ints mucking around with the PSG */
|
|
|
|
local_irq_save(flags);
|
|
|
|
sound_ym.rd_data_reg_sel = 14; /* Select PSG Port A */
|
|
|
|
tmp = sound_ym.rd_data_reg_sel;
|
|
|
|
sound_ym.wd_data = (tmp | DSKDRVNONE) & ~(drive == 0 ? DSKDRV0 : DSKDRV1);
|
|
|
|
atari_dont_touch_floppy_select = 1;
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
/* restore track register to saved value */
|
|
|
|
FDC_WRITE( FDCREG_TRACK, UD.track );
|
|
|
|
udelay(25);
|
|
|
|
|
|
|
|
/* select 8/16 MHz */
|
|
|
|
if (UDT)
|
|
|
|
if (ATARIHW_PRESENT(FDCSPEED))
|
|
|
|
dma_wd.fdc_speed = UDT->fdc_speed;
|
|
|
|
|
|
|
|
SelectedDrive = drive;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Deselect both drives. */
|
|
|
|
|
|
|
|
static void fd_deselect( void )
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/* protect against various other ints mucking around with the PSG */
|
|
|
|
local_irq_save(flags);
|
|
|
|
atari_dont_touch_floppy_select = 0;
|
|
|
|
sound_ym.rd_data_reg_sel=14; /* Select PSG Port A */
|
|
|
|
sound_ym.wd_data = (sound_ym.rd_data_reg_sel |
|
|
|
|
(MACH_IS_FALCON ? 3 : 7)); /* no drives selected */
|
|
|
|
/* On Falcon, the drive B select line is used on the printer port, so
|
|
|
|
* leave it alone... */
|
|
|
|
SelectedDrive = -1;
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This timer function deselects the drives when the FDC switched the
|
|
|
|
* motor off. The deselection cannot happen earlier because the FDC
|
|
|
|
* counts the index signals, which arrive only if one drive is selected.
|
|
|
|
*/
|
|
|
|
|
2017-08-28 18:28:21 +00:00
|
|
|
static void fd_motor_off_timer(struct timer_list *unused)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned char status;
|
|
|
|
|
|
|
|
if (SelectedDrive < 0)
|
|
|
|
/* no drive selected, needn't deselect anyone */
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (stdma_islocked())
|
|
|
|
goto retry;
|
|
|
|
|
|
|
|
status = FDC_READ( FDCREG_STATUS );
|
|
|
|
|
|
|
|
if (!(status & 0x80)) {
|
|
|
|
/* motor already turned off by FDC -> deselect drives */
|
|
|
|
MotorOn = 0;
|
|
|
|
fd_deselect();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* not yet off, try again */
|
|
|
|
|
|
|
|
retry:
|
|
|
|
/* Test again later; if tested too often, it seems there is no disk
|
|
|
|
* in the drive and the FDC will leave the motor on forever (or,
|
|
|
|
* at least until a disk is inserted). So we'll test only twice
|
|
|
|
* per second from then on...
|
|
|
|
*/
|
|
|
|
mod_timer(&motor_off_timer,
|
|
|
|
jiffies + (MotorOffTrys++ < FD_MOTOR_OFF_MAXTRY ? HZ/20 : HZ/2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This function is repeatedly called to detect disk changes (as good
|
|
|
|
* as possible) and keep track of the current state of the write protection.
|
|
|
|
*/
|
|
|
|
|
2017-08-28 18:28:21 +00:00
|
|
|
static void check_change(struct timer_list *unused)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
static int drive = 0;
|
|
|
|
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned char old_porta;
|
|
|
|
int stat;
|
|
|
|
|
|
|
|
if (++drive > 1 || !UD.connected)
|
|
|
|
drive = 0;
|
|
|
|
|
|
|
|
/* protect against various other ints mucking around with the PSG */
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
if (!stdma_islocked()) {
|
|
|
|
sound_ym.rd_data_reg_sel = 14;
|
|
|
|
old_porta = sound_ym.rd_data_reg_sel;
|
|
|
|
sound_ym.wd_data = (old_porta | DSKDRVNONE) &
|
|
|
|
~(drive == 0 ? DSKDRV0 : DSKDRV1);
|
|
|
|
stat = !!(FDC_READ( FDCREG_STATUS ) & FDCSTAT_WPROT);
|
|
|
|
sound_ym.wd_data = old_porta;
|
|
|
|
|
|
|
|
if (stat != UD.wpstat) {
|
|
|
|
DPRINT(( "wpstat[%d] = %d\n", drive, stat ));
|
|
|
|
UD.wpstat = stat;
|
|
|
|
set_bit (drive, &changed_floppies);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
start_check_change_timer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Handling of the Head Settling Flag: This flag should be set after each
|
|
|
|
* seek operation, because we don't use seeks with verify.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline void set_head_settle_flag(void)
|
|
|
|
{
|
|
|
|
HeadSettleFlag = FDCCMDADD_E;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int get_head_settle_flag(void)
|
|
|
|
{
|
|
|
|
int tmp = HeadSettleFlag;
|
|
|
|
HeadSettleFlag = 0;
|
|
|
|
return( tmp );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void copy_buffer(void *from, void *to)
|
|
|
|
{
|
|
|
|
ulong *p1 = (ulong *)from, *p2 = (ulong *)to;
|
|
|
|
int cnt;
|
|
|
|
|
|
|
|
for (cnt = 512/4; cnt; cnt--)
|
|
|
|
*p2++ = *p1++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* General Interrupt Handling */
|
|
|
|
|
|
|
|
static void (*FloppyIRQHandler)( int status ) = NULL;
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static irqreturn_t floppy_irq (int irq, void *dummy)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned char status;
|
|
|
|
void (*handler)( int );
|
|
|
|
|
|
|
|
handler = xchg(&FloppyIRQHandler, NULL);
|
|
|
|
|
|
|
|
if (handler) {
|
|
|
|
nop();
|
|
|
|
status = FDC_READ( FDCREG_STATUS );
|
|
|
|
DPRINT(("FDC irq, status = %02x handler = %08lx\n",status,(unsigned long)handler));
|
|
|
|
handler( status );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DPRINT(("FDC irq, no handler\n"));
|
|
|
|
}
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Error handling: If some error happened, retry some times, then
|
|
|
|
* recalibrate, then try again, and fail after MAX_ERRORS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void fd_error( void )
|
|
|
|
{
|
|
|
|
if (IsFormatting) {
|
|
|
|
IsFormatting = 0;
|
|
|
|
FormatError = 1;
|
2014-02-26 11:01:41 +00:00
|
|
|
complete(&format_wait);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-08 02:54:03 +00:00
|
|
|
if (!fd_request)
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
|
2022-05-08 09:37:08 +00:00
|
|
|
unit[SelectedDrive].error_count++;
|
|
|
|
if (unit[SelectedDrive].error_count >= MAX_ERRORS) {
|
2005-04-16 22:20:36 +00:00
|
|
|
printk(KERN_ERR "fd%d: too many errors.\n", SelectedDrive );
|
2017-06-03 07:38:04 +00:00
|
|
|
fd_end_request_cur(BLK_STS_IOERR);
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
finish_fdc();
|
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2022-05-08 09:37:08 +00:00
|
|
|
else if (unit[SelectedDrive].error_count == RECALIBRATE_ERRORS) {
|
2005-04-16 22:20:36 +00:00
|
|
|
printk(KERN_WARNING "fd%d: recalibrating\n", SelectedDrive );
|
|
|
|
if (SelectedDrive != -1)
|
|
|
|
SUD.track = -1;
|
|
|
|
}
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
/* need to re-run request to recalibrate */
|
|
|
|
atari_disable_irq( IRQ_MFP_FDC );
|
|
|
|
|
|
|
|
setup_req_params( SelectedDrive );
|
|
|
|
do_fd_action( SelectedDrive );
|
|
|
|
|
|
|
|
atari_enable_irq( IRQ_MFP_FDC );
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define SET_IRQ_HANDLER(proc) do { FloppyIRQHandler = (proc); } while(0)
|
|
|
|
|
|
|
|
|
|
|
|
/* ---------- Formatting ---------- */
|
|
|
|
|
|
|
|
#define FILL(n,val) \
|
|
|
|
do { \
|
|
|
|
memset( p, val, n ); \
|
|
|
|
p += n; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
static int do_format(int drive, int type, struct atari_format_descr *desc)
|
|
|
|
{
|
2020-10-29 14:58:38 +00:00
|
|
|
struct request_queue *q;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned char *p;
|
|
|
|
int sect, nsect;
|
|
|
|
unsigned long flags;
|
2018-10-15 15:18:24 +00:00
|
|
|
int ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-04-21 10:18:35 +00:00
|
|
|
if (type) {
|
2020-10-29 14:58:38 +00:00
|
|
|
type--;
|
2021-04-21 10:18:35 +00:00
|
|
|
if (type >= NUM_DISK_MINORS ||
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
minor2disktype[type].drive_types > DriveType) {
|
|
|
|
finish_fdc();
|
2021-04-21 10:18:35 +00:00
|
|
|
return -EINVAL;
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
}
|
2021-04-21 10:18:35 +00:00
|
|
|
}
|
2020-10-29 14:58:38 +00:00
|
|
|
|
|
|
|
q = unit[drive].disk[type]->queue;
|
2018-10-15 15:18:24 +00:00
|
|
|
blk_mq_freeze_queue(q);
|
|
|
|
blk_mq_quiesce_queue(q);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
stdma_lock(floppy_irq, NULL);
|
|
|
|
atari_turnon_irq( IRQ_MFP_FDC ); /* should be already, just to be sure */
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
if (type) {
|
|
|
|
type = minor2disktype[type].index;
|
2008-02-06 09:38:09 +00:00
|
|
|
UDT = &atari_disk_type[type];
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!UDT || desc->track >= UDT->blocks/UDT->spt/2 || desc->head >= 2) {
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
finish_fdc();
|
2018-10-15 15:18:24 +00:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsect = UDT->spt;
|
|
|
|
p = TrackBuffer;
|
|
|
|
/* The track buffer is used for the raw track data, so its
|
|
|
|
contents become invalid! */
|
|
|
|
BufferDrive = -1;
|
|
|
|
/* stop deselect timer */
|
|
|
|
del_timer( &motor_off_timer );
|
|
|
|
|
|
|
|
FILL( 60 * (nsect / 9), 0x4e );
|
|
|
|
for( sect = 0; sect < nsect; ++sect ) {
|
|
|
|
FILL( 12, 0 );
|
|
|
|
FILL( 3, 0xf5 );
|
|
|
|
*p++ = 0xfe;
|
|
|
|
*p++ = desc->track;
|
|
|
|
*p++ = desc->head;
|
|
|
|
*p++ = (nsect + sect - desc->sect_offset) % nsect + 1;
|
|
|
|
*p++ = 2;
|
|
|
|
*p++ = 0xf7;
|
|
|
|
FILL( 22, 0x4e );
|
|
|
|
FILL( 12, 0 );
|
|
|
|
FILL( 3, 0xf5 );
|
|
|
|
*p++ = 0xfb;
|
|
|
|
FILL( 512, 0xe5 );
|
|
|
|
*p++ = 0xf7;
|
|
|
|
FILL( 40, 0x4e );
|
|
|
|
}
|
|
|
|
FILL( TrackBuffer+BUFFER_SIZE-p, 0x4e );
|
|
|
|
|
|
|
|
IsFormatting = 1;
|
|
|
|
FormatError = 0;
|
|
|
|
ReqTrack = desc->track;
|
|
|
|
ReqSide = desc->head;
|
|
|
|
do_fd_action( drive );
|
|
|
|
|
2014-02-26 11:01:41 +00:00
|
|
|
wait_for_completion(&format_wait);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
finish_fdc();
|
2018-10-15 15:18:24 +00:00
|
|
|
ret = FormatError ? -EIO : 0;
|
|
|
|
out:
|
|
|
|
blk_mq_unquiesce_queue(q);
|
|
|
|
blk_mq_unfreeze_queue(q);
|
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* do_fd_action() is the general procedure for a fd request: All
|
|
|
|
* required parameter settings (drive select, side select, track
|
|
|
|
* position) are checked and set if needed. For each of these
|
|
|
|
* parameters and the actual reading or writing exist two functions:
|
|
|
|
* one that starts the setting (or skips it if possible) and one
|
|
|
|
* callback for the "done" interrupt. Each done func calls the next
|
|
|
|
* set function to propagate the request down to fd_rwsec_done().
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void do_fd_action( int drive )
|
|
|
|
{
|
|
|
|
DPRINT(("do_fd_action\n"));
|
|
|
|
|
|
|
|
if (UseTrackbuffer && !IsFormatting) {
|
|
|
|
repeat:
|
|
|
|
if (IS_BUFFERED( drive, ReqSide, ReqTrack )) {
|
|
|
|
if (ReqCmd == READ) {
|
|
|
|
copy_buffer( SECTOR_BUFFER(ReqSector), ReqData );
|
2009-05-08 02:54:03 +00:00
|
|
|
if (++ReqCnt < blk_rq_cur_sectors(fd_request)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/* read next sector */
|
|
|
|
setup_req_params( drive );
|
|
|
|
goto repeat;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* all sectors finished */
|
2017-06-03 07:38:04 +00:00
|
|
|
fd_end_request_cur(BLK_STS_OK);
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
finish_fdc();
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* cmd == WRITE, pay attention to track buffer
|
|
|
|
* consistency! */
|
|
|
|
copy_buffer( ReqData, SECTOR_BUFFER(ReqSector) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SelectedDrive != drive)
|
|
|
|
fd_select_drive( drive );
|
|
|
|
|
|
|
|
if (UD.track == -1)
|
|
|
|
fd_calibrate();
|
|
|
|
else if (UD.track != ReqTrack << UDT->stretch)
|
|
|
|
fd_seek();
|
|
|
|
else if (IsFormatting)
|
|
|
|
fd_writetrack();
|
|
|
|
else
|
|
|
|
fd_rwsec();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Seek to track 0 if the current track is unknown */
|
|
|
|
|
|
|
|
static void fd_calibrate( void )
|
|
|
|
{
|
|
|
|
if (SUD.track >= 0) {
|
|
|
|
fd_calibrate_done( 0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ATARIHW_PRESENT(FDCSPEED))
|
2019-11-28 03:09:32 +00:00
|
|
|
dma_wd.fdc_speed = 0; /* always seek with 8 Mhz */
|
2005-04-16 22:20:36 +00:00
|
|
|
DPRINT(("fd_calibrate\n"));
|
|
|
|
SET_IRQ_HANDLER( fd_calibrate_done );
|
|
|
|
/* we can't verify, since the speed may be incorrect */
|
|
|
|
FDC_WRITE( FDCREG_CMD, FDCCMD_RESTORE | SUD.steprate );
|
|
|
|
|
|
|
|
NeedSeek = 1;
|
|
|
|
MotorOn = 1;
|
|
|
|
start_timeout();
|
|
|
|
/* wait for IRQ */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void fd_calibrate_done( int status )
|
|
|
|
{
|
|
|
|
DPRINT(("fd_calibrate_done()\n"));
|
|
|
|
stop_timeout();
|
|
|
|
|
|
|
|
/* set the correct speed now */
|
|
|
|
if (ATARIHW_PRESENT(FDCSPEED))
|
|
|
|
dma_wd.fdc_speed = SUDT->fdc_speed;
|
|
|
|
if (status & FDCSTAT_RECNF) {
|
|
|
|
printk(KERN_ERR "fd%d: restore failed\n", SelectedDrive );
|
|
|
|
fd_error();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SUD.track = 0;
|
|
|
|
fd_seek();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Seek the drive to the requested track. The drive must have been
|
|
|
|
* calibrated at some point before this.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void fd_seek( void )
|
|
|
|
{
|
|
|
|
if (SUD.track == ReqTrack << SUDT->stretch) {
|
|
|
|
fd_seek_done( 0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ATARIHW_PRESENT(FDCSPEED)) {
|
|
|
|
dma_wd.fdc_speed = 0; /* always seek witch 8 Mhz */
|
|
|
|
MFPDELAY();
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT(("fd_seek() to track %d\n",ReqTrack));
|
|
|
|
FDC_WRITE( FDCREG_DATA, ReqTrack << SUDT->stretch);
|
|
|
|
udelay(25);
|
|
|
|
SET_IRQ_HANDLER( fd_seek_done );
|
|
|
|
FDC_WRITE( FDCREG_CMD, FDCCMD_SEEK | SUD.steprate );
|
|
|
|
|
|
|
|
MotorOn = 1;
|
|
|
|
set_head_settle_flag();
|
|
|
|
start_timeout();
|
|
|
|
/* wait for IRQ */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void fd_seek_done( int status )
|
|
|
|
{
|
|
|
|
DPRINT(("fd_seek_done()\n"));
|
|
|
|
stop_timeout();
|
|
|
|
|
|
|
|
/* set the correct speed */
|
|
|
|
if (ATARIHW_PRESENT(FDCSPEED))
|
|
|
|
dma_wd.fdc_speed = SUDT->fdc_speed;
|
|
|
|
if (status & FDCSTAT_RECNF) {
|
|
|
|
printk(KERN_ERR "fd%d: seek error (to track %d)\n",
|
|
|
|
SelectedDrive, ReqTrack );
|
|
|
|
/* we don't know exactly which track we are on now! */
|
|
|
|
SUD.track = -1;
|
|
|
|
fd_error();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SUD.track = ReqTrack << SUDT->stretch;
|
|
|
|
NeedSeek = 0;
|
|
|
|
if (IsFormatting)
|
|
|
|
fd_writetrack();
|
|
|
|
else
|
|
|
|
fd_rwsec();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This does the actual reading/writing after positioning the head
|
|
|
|
* over the correct track.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int MultReadInProgress = 0;
|
|
|
|
|
|
|
|
|
|
|
|
static void fd_rwsec( void )
|
|
|
|
{
|
|
|
|
unsigned long paddr, flags;
|
|
|
|
unsigned int rwflag, old_motoron;
|
|
|
|
unsigned int track;
|
|
|
|
|
|
|
|
DPRINT(("fd_rwsec(), Sec=%d, Access=%c\n",ReqSector, ReqCmd == WRITE ? 'w' : 'r' ));
|
|
|
|
if (ReqCmd == WRITE) {
|
|
|
|
if (ATARIHW_PRESENT(EXTD_DMA)) {
|
|
|
|
paddr = virt_to_phys(ReqData);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
copy_buffer( ReqData, DMABuffer );
|
|
|
|
paddr = PhysDMABuffer;
|
|
|
|
}
|
|
|
|
dma_cache_maintenance( paddr, 512, 1 );
|
|
|
|
rwflag = 0x100;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (read_track)
|
|
|
|
paddr = PhysTrackBuffer;
|
|
|
|
else
|
|
|
|
paddr = ATARIHW_PRESENT(EXTD_DMA) ?
|
|
|
|
virt_to_phys(ReqData) : PhysDMABuffer;
|
|
|
|
rwflag = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd_select_side( ReqSide );
|
|
|
|
|
|
|
|
/* Start sector of this operation */
|
|
|
|
FDC_WRITE( FDCREG_SECTOR, read_track ? 1 : ReqSector );
|
|
|
|
MFPDELAY();
|
|
|
|
/* Cheat for track if stretch != 0 */
|
|
|
|
if (SUDT->stretch) {
|
|
|
|
track = FDC_READ( FDCREG_TRACK);
|
|
|
|
MFPDELAY();
|
|
|
|
FDC_WRITE( FDCREG_TRACK, track >> SUDT->stretch);
|
|
|
|
}
|
|
|
|
udelay(25);
|
|
|
|
|
|
|
|
/* Setup DMA */
|
|
|
|
local_irq_save(flags);
|
|
|
|
dma_wd.dma_lo = (unsigned char)paddr;
|
|
|
|
MFPDELAY();
|
|
|
|
paddr >>= 8;
|
|
|
|
dma_wd.dma_md = (unsigned char)paddr;
|
|
|
|
MFPDELAY();
|
|
|
|
paddr >>= 8;
|
|
|
|
if (ATARIHW_PRESENT(EXTD_DMA))
|
|
|
|
st_dma_ext_dmahi = (unsigned short)paddr;
|
|
|
|
else
|
|
|
|
dma_wd.dma_hi = (unsigned char)paddr;
|
|
|
|
MFPDELAY();
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
/* Clear FIFO and switch DMA to correct mode */
|
|
|
|
dma_wd.dma_mode_status = 0x90 | rwflag;
|
|
|
|
MFPDELAY();
|
|
|
|
dma_wd.dma_mode_status = 0x90 | (rwflag ^ 0x100);
|
|
|
|
MFPDELAY();
|
|
|
|
dma_wd.dma_mode_status = 0x90 | rwflag;
|
|
|
|
MFPDELAY();
|
|
|
|
|
|
|
|
/* How many sectors for DMA */
|
|
|
|
dma_wd.fdc_acces_seccount = read_track ? SUDT->spt : 1;
|
|
|
|
|
|
|
|
udelay(25);
|
|
|
|
|
|
|
|
/* Start operation */
|
|
|
|
dma_wd.dma_mode_status = FDCSELREG_STP | rwflag;
|
|
|
|
udelay(25);
|
|
|
|
SET_IRQ_HANDLER( fd_rwsec_done );
|
|
|
|
dma_wd.fdc_acces_seccount =
|
|
|
|
(get_head_settle_flag() |
|
|
|
|
(rwflag ? FDCCMD_WRSEC : (FDCCMD_RDSEC | (read_track ? FDCCMDADD_M : 0))));
|
|
|
|
|
|
|
|
old_motoron = MotorOn;
|
|
|
|
MotorOn = 1;
|
|
|
|
NeedSeek = 1;
|
|
|
|
/* wait for interrupt */
|
|
|
|
|
|
|
|
if (read_track) {
|
|
|
|
/* If reading a whole track, wait about one disk rotation and
|
|
|
|
* then check if all sectors are read. The FDC will even
|
|
|
|
* search for the first non-existent sector and need 1 sec to
|
|
|
|
* recognise that it isn't present :-(
|
|
|
|
*/
|
|
|
|
MultReadInProgress = 1;
|
|
|
|
mod_timer(&readtrack_timer,
|
|
|
|
/* 1 rot. + 5 rot.s if motor was off */
|
|
|
|
jiffies + HZ/5 + (old_motoron ? 0 : HZ));
|
|
|
|
}
|
|
|
|
start_timeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-28 18:28:21 +00:00
|
|
|
static void fd_readtrack_check(struct timer_list *unused)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long flags, addr, addr2;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
if (!MultReadInProgress) {
|
|
|
|
/* This prevents a race condition that could arise if the
|
|
|
|
* interrupt is triggered while the calling of this timer
|
|
|
|
* callback function takes place. The IRQ function then has
|
|
|
|
* already cleared 'MultReadInProgress' when flow of control
|
|
|
|
* gets here.
|
|
|
|
*/
|
|
|
|
local_irq_restore(flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the current DMA address */
|
|
|
|
/* ++ f.a. read twice to avoid being fooled by switcher */
|
|
|
|
addr = 0;
|
|
|
|
do {
|
|
|
|
addr2 = addr;
|
|
|
|
addr = dma_wd.dma_lo & 0xff;
|
|
|
|
MFPDELAY();
|
|
|
|
addr |= (dma_wd.dma_md & 0xff) << 8;
|
|
|
|
MFPDELAY();
|
|
|
|
if (ATARIHW_PRESENT( EXTD_DMA ))
|
|
|
|
addr |= (st_dma_ext_dmahi & 0xffff) << 16;
|
|
|
|
else
|
|
|
|
addr |= (dma_wd.dma_hi & 0xff) << 16;
|
|
|
|
MFPDELAY();
|
|
|
|
} while(addr != addr2);
|
|
|
|
|
|
|
|
if (addr >= PhysTrackBuffer + SUDT->spt*512) {
|
|
|
|
/* already read enough data, force an FDC interrupt to stop
|
|
|
|
* the read operation
|
|
|
|
*/
|
|
|
|
SET_IRQ_HANDLER( NULL );
|
|
|
|
MultReadInProgress = 0;
|
|
|
|
local_irq_restore(flags);
|
|
|
|
DPRINT(("fd_readtrack_check(): done\n"));
|
|
|
|
FDC_WRITE( FDCREG_CMD, FDCCMD_FORCI );
|
|
|
|
udelay(25);
|
|
|
|
|
|
|
|
/* No error until now -- the FDC would have interrupted
|
|
|
|
* otherwise!
|
|
|
|
*/
|
|
|
|
fd_rwsec_done1(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* not yet finished, wait another tenth rotation */
|
|
|
|
local_irq_restore(flags);
|
|
|
|
DPRINT(("fd_readtrack_check(): not yet finished\n"));
|
|
|
|
mod_timer(&readtrack_timer, jiffies + HZ/5/10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void fd_rwsec_done( int status )
|
|
|
|
{
|
|
|
|
DPRINT(("fd_rwsec_done()\n"));
|
|
|
|
|
|
|
|
if (read_track) {
|
|
|
|
del_timer(&readtrack_timer);
|
|
|
|
if (!MultReadInProgress)
|
|
|
|
return;
|
|
|
|
MultReadInProgress = 0;
|
|
|
|
}
|
|
|
|
fd_rwsec_done1(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fd_rwsec_done1(int status)
|
|
|
|
{
|
|
|
|
unsigned int track;
|
|
|
|
|
|
|
|
stop_timeout();
|
|
|
|
|
|
|
|
/* Correct the track if stretch != 0 */
|
|
|
|
if (SUDT->stretch) {
|
|
|
|
track = FDC_READ( FDCREG_TRACK);
|
|
|
|
MFPDELAY();
|
|
|
|
FDC_WRITE( FDCREG_TRACK, track << SUDT->stretch);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!UseTrackbuffer) {
|
|
|
|
dma_wd.dma_mode_status = 0x90;
|
|
|
|
MFPDELAY();
|
|
|
|
if (!(dma_wd.dma_mode_status & 0x01)) {
|
|
|
|
printk(KERN_ERR "fd%d: DMA error\n", SelectedDrive );
|
|
|
|
goto err_end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MFPDELAY();
|
|
|
|
|
|
|
|
if (ReqCmd == WRITE && (status & FDCSTAT_WPROT)) {
|
|
|
|
printk(KERN_NOTICE "fd%d: is write protected\n", SelectedDrive );
|
|
|
|
goto err_end;
|
|
|
|
}
|
|
|
|
if ((status & FDCSTAT_RECNF) &&
|
|
|
|
/* RECNF is no error after a multiple read when the FDC
|
|
|
|
searched for a non-existent sector! */
|
|
|
|
!(read_track && FDC_READ(FDCREG_SECTOR) > SUDT->spt)) {
|
|
|
|
if (Probing) {
|
2008-02-06 09:38:09 +00:00
|
|
|
if (SUDT > atari_disk_type) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (SUDT[-1].blocks > ReqBlock) {
|
|
|
|
/* try another disk type */
|
|
|
|
SUDT--;
|
2020-10-29 14:58:38 +00:00
|
|
|
set_capacity(unit[SelectedDrive].disk[0],
|
2005-04-16 22:20:36 +00:00
|
|
|
SUDT->blocks);
|
|
|
|
} else
|
|
|
|
Probing = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (SUD.flags & FTD_MSG)
|
|
|
|
printk(KERN_INFO "fd%d: Auto-detected floppy type %s\n",
|
|
|
|
SelectedDrive, SUDT->name );
|
|
|
|
Probing=0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* record not found, but not probing. Maybe stretch wrong ? Restart probing */
|
|
|
|
if (SUD.autoprobe) {
|
2008-02-06 09:38:09 +00:00
|
|
|
SUDT = atari_disk_type + StartDiskType[DriveType];
|
2020-10-29 14:58:38 +00:00
|
|
|
set_capacity(unit[SelectedDrive].disk[0],
|
2005-04-16 22:20:36 +00:00
|
|
|
SUDT->blocks);
|
|
|
|
Probing = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Probing) {
|
|
|
|
if (ATARIHW_PRESENT(FDCSPEED)) {
|
|
|
|
dma_wd.fdc_speed = SUDT->fdc_speed;
|
|
|
|
MFPDELAY();
|
|
|
|
}
|
|
|
|
setup_req_params( SelectedDrive );
|
|
|
|
BufferDrive = -1;
|
|
|
|
do_fd_action( SelectedDrive );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printk(KERN_ERR "fd%d: sector %d not found (side %d, track %d)\n",
|
|
|
|
SelectedDrive, FDC_READ (FDCREG_SECTOR), ReqSide, ReqTrack );
|
|
|
|
goto err_end;
|
|
|
|
}
|
|
|
|
if (status & FDCSTAT_CRC) {
|
|
|
|
printk(KERN_ERR "fd%d: CRC error (side %d, track %d, sector %d)\n",
|
|
|
|
SelectedDrive, ReqSide, ReqTrack, FDC_READ (FDCREG_SECTOR) );
|
|
|
|
goto err_end;
|
|
|
|
}
|
|
|
|
if (status & FDCSTAT_LOST) {
|
|
|
|
printk(KERN_ERR "fd%d: lost data (side %d, track %d, sector %d)\n",
|
|
|
|
SelectedDrive, ReqSide, ReqTrack, FDC_READ (FDCREG_SECTOR) );
|
|
|
|
goto err_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
Probing = 0;
|
|
|
|
|
|
|
|
if (ReqCmd == READ) {
|
|
|
|
if (!read_track) {
|
|
|
|
void *addr;
|
|
|
|
addr = ATARIHW_PRESENT( EXTD_DMA ) ? ReqData : DMABuffer;
|
|
|
|
dma_cache_maintenance( virt_to_phys(addr), 512, 0 );
|
|
|
|
if (!ATARIHW_PRESENT( EXTD_DMA ))
|
|
|
|
copy_buffer (addr, ReqData);
|
|
|
|
} else {
|
|
|
|
dma_cache_maintenance( PhysTrackBuffer, MaxSectors[DriveType] * 512, 0 );
|
|
|
|
BufferDrive = SelectedDrive;
|
|
|
|
BufferSide = ReqSide;
|
|
|
|
BufferTrack = ReqTrack;
|
|
|
|
copy_buffer (SECTOR_BUFFER (ReqSector), ReqData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-08 02:54:03 +00:00
|
|
|
if (++ReqCnt < blk_rq_cur_sectors(fd_request)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/* read next sector */
|
|
|
|
setup_req_params( SelectedDrive );
|
|
|
|
do_fd_action( SelectedDrive );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* all sectors finished */
|
2017-06-03 07:38:04 +00:00
|
|
|
fd_end_request_cur(BLK_STS_OK);
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
finish_fdc();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
err_end:
|
|
|
|
BufferDrive = -1;
|
|
|
|
fd_error();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void fd_writetrack( void )
|
|
|
|
{
|
|
|
|
unsigned long paddr, flags;
|
|
|
|
unsigned int track;
|
|
|
|
|
|
|
|
DPRINT(("fd_writetrack() Tr=%d Si=%d\n", ReqTrack, ReqSide ));
|
|
|
|
|
|
|
|
paddr = PhysTrackBuffer;
|
|
|
|
dma_cache_maintenance( paddr, BUFFER_SIZE, 1 );
|
|
|
|
|
|
|
|
fd_select_side( ReqSide );
|
|
|
|
|
|
|
|
/* Cheat for track if stretch != 0 */
|
|
|
|
if (SUDT->stretch) {
|
|
|
|
track = FDC_READ( FDCREG_TRACK);
|
|
|
|
MFPDELAY();
|
|
|
|
FDC_WRITE(FDCREG_TRACK,track >> SUDT->stretch);
|
|
|
|
}
|
|
|
|
udelay(40);
|
|
|
|
|
|
|
|
/* Setup DMA */
|
|
|
|
local_irq_save(flags);
|
|
|
|
dma_wd.dma_lo = (unsigned char)paddr;
|
|
|
|
MFPDELAY();
|
|
|
|
paddr >>= 8;
|
|
|
|
dma_wd.dma_md = (unsigned char)paddr;
|
|
|
|
MFPDELAY();
|
|
|
|
paddr >>= 8;
|
|
|
|
if (ATARIHW_PRESENT( EXTD_DMA ))
|
|
|
|
st_dma_ext_dmahi = (unsigned short)paddr;
|
|
|
|
else
|
|
|
|
dma_wd.dma_hi = (unsigned char)paddr;
|
|
|
|
MFPDELAY();
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
/* Clear FIFO and switch DMA to correct mode */
|
|
|
|
dma_wd.dma_mode_status = 0x190;
|
|
|
|
MFPDELAY();
|
|
|
|
dma_wd.dma_mode_status = 0x90;
|
|
|
|
MFPDELAY();
|
|
|
|
dma_wd.dma_mode_status = 0x190;
|
|
|
|
MFPDELAY();
|
|
|
|
|
|
|
|
/* How many sectors for DMA */
|
|
|
|
dma_wd.fdc_acces_seccount = BUFFER_SIZE/512;
|
|
|
|
udelay(40);
|
|
|
|
|
|
|
|
/* Start operation */
|
|
|
|
dma_wd.dma_mode_status = FDCSELREG_STP | 0x100;
|
|
|
|
udelay(40);
|
|
|
|
SET_IRQ_HANDLER( fd_writetrack_done );
|
|
|
|
dma_wd.fdc_acces_seccount = FDCCMD_WRTRA | get_head_settle_flag();
|
|
|
|
|
|
|
|
MotorOn = 1;
|
|
|
|
start_timeout();
|
|
|
|
/* wait for interrupt */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void fd_writetrack_done( int status )
|
|
|
|
{
|
|
|
|
DPRINT(("fd_writetrack_done()\n"));
|
|
|
|
|
|
|
|
stop_timeout();
|
|
|
|
|
|
|
|
if (status & FDCSTAT_WPROT) {
|
|
|
|
printk(KERN_NOTICE "fd%d: is write protected\n", SelectedDrive );
|
|
|
|
goto err_end;
|
|
|
|
}
|
|
|
|
if (status & FDCSTAT_LOST) {
|
|
|
|
printk(KERN_ERR "fd%d: lost data (side %d, track %d)\n",
|
|
|
|
SelectedDrive, ReqSide, ReqTrack );
|
|
|
|
goto err_end;
|
|
|
|
}
|
|
|
|
|
2014-02-26 11:01:41 +00:00
|
|
|
complete(&format_wait);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
err_end:
|
|
|
|
fd_error();
|
|
|
|
}
|
|
|
|
|
2017-08-28 18:28:21 +00:00
|
|
|
static void fd_times_out(struct timer_list *unused)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
atari_disable_irq( IRQ_MFP_FDC );
|
|
|
|
if (!FloppyIRQHandler) goto end; /* int occurred after timer was fired, but
|
|
|
|
* before we came here... */
|
|
|
|
|
|
|
|
SET_IRQ_HANDLER( NULL );
|
|
|
|
/* If the timeout occurred while the readtrack_check timer was
|
|
|
|
* active, we need to cancel it, else bad things will happen */
|
|
|
|
if (UseTrackbuffer)
|
|
|
|
del_timer( &readtrack_timer );
|
|
|
|
FDC_WRITE( FDCREG_CMD, FDCCMD_FORCI );
|
|
|
|
udelay( 25 );
|
|
|
|
|
|
|
|
printk(KERN_ERR "floppy timeout\n" );
|
|
|
|
fd_error();
|
|
|
|
end:
|
|
|
|
atari_enable_irq( IRQ_MFP_FDC );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* The (noop) seek operation here is needed to make the WP bit in the
|
|
|
|
* FDC status register accessible for check_change. If the last disk
|
|
|
|
* operation would have been a RDSEC, this bit would always read as 0
|
|
|
|
* no matter what :-( To save time, the seek goes to the track we're
|
|
|
|
* already on.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void finish_fdc( void )
|
|
|
|
{
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
if (!NeedSeek || !stdma_is_locked_by(floppy_irq)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
finish_fdc_done( 0 );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DPRINT(("finish_fdc: dummy seek started\n"));
|
|
|
|
FDC_WRITE (FDCREG_DATA, SUD.track);
|
|
|
|
SET_IRQ_HANDLER( finish_fdc_done );
|
|
|
|
FDC_WRITE (FDCREG_CMD, FDCCMD_SEEK);
|
|
|
|
MotorOn = 1;
|
|
|
|
start_timeout();
|
|
|
|
/* we must wait for the IRQ here, because the ST-DMA
|
|
|
|
is released immediately afterwards and the interrupt
|
|
|
|
may be delivered to the wrong driver. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void finish_fdc_done( int dummy )
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
DPRINT(("finish_fdc_done entered\n"));
|
|
|
|
stop_timeout();
|
|
|
|
NeedSeek = 0;
|
|
|
|
|
|
|
|
if (timer_pending(&fd_timer) && time_before(fd_timer.expires, jiffies + 5))
|
|
|
|
/* If the check for a disk change is done too early after this
|
|
|
|
* last seek command, the WP bit still reads wrong :-((
|
|
|
|
*/
|
|
|
|
mod_timer(&fd_timer, jiffies + 5);
|
|
|
|
else
|
|
|
|
start_check_change_timer();
|
|
|
|
start_motor_off_timer();
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
if (stdma_is_locked_by(floppy_irq))
|
|
|
|
stdma_release();
|
2005-04-16 22:20:36 +00:00
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
DPRINT(("finish_fdc() finished\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The detection of disk changes is a dark chapter in Atari history :-(
|
|
|
|
* Because the "Drive ready" signal isn't present in the Atari
|
|
|
|
* hardware, one has to rely on the "Write Protect". This works fine,
|
|
|
|
* as long as no write protected disks are used. TOS solves this
|
|
|
|
* problem by introducing tri-state logic ("maybe changed") and
|
|
|
|
* looking at the serial number in block 0. This isn't possible for
|
|
|
|
* Linux, since the floppy driver can't make assumptions about the
|
|
|
|
* filesystem used on the disk and thus the contents of block 0. I've
|
|
|
|
* chosen the method to always say "The disk was changed" if it is
|
|
|
|
* unsure whether it was. This implies that every open or mount
|
|
|
|
* invalidates the disk buffers if you work with write protected
|
|
|
|
* disks. But at least this is better than working with incorrect data
|
|
|
|
* due to unrecognised disk changes.
|
|
|
|
*/
|
|
|
|
|
2011-03-09 18:54:27 +00:00
|
|
|
static unsigned int floppy_check_events(struct gendisk *disk,
|
|
|
|
unsigned int clearing)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct atari_floppy_struct *p = disk->private_data;
|
|
|
|
unsigned int drive = p - unit;
|
|
|
|
if (test_bit (drive, &fake_change)) {
|
|
|
|
/* simulated change (e.g. after formatting) */
|
2011-03-09 18:54:27 +00:00
|
|
|
return DISK_EVENT_MEDIA_CHANGE;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
if (test_bit (drive, &changed_floppies)) {
|
|
|
|
/* surely changed (the WP signal changed at least once) */
|
2011-03-09 18:54:27 +00:00
|
|
|
return DISK_EVENT_MEDIA_CHANGE;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
if (UD.wpstat) {
|
|
|
|
/* WP is on -> could be changed: to be sure, buffers should be
|
|
|
|
* invalidated...
|
|
|
|
*/
|
2011-03-09 18:54:27 +00:00
|
|
|
return DISK_EVENT_MEDIA_CHANGE;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int floppy_revalidate(struct gendisk *disk)
|
|
|
|
{
|
|
|
|
struct atari_floppy_struct *p = disk->private_data;
|
|
|
|
unsigned int drive = p - unit;
|
|
|
|
|
|
|
|
if (test_bit(drive, &changed_floppies) ||
|
2021-10-29 09:50:29 +00:00
|
|
|
test_bit(drive, &fake_change) || !p->disktype) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (UD.flags & FTD_MSG)
|
|
|
|
printk(KERN_ERR "floppy: clear format %p!\n", UDT);
|
|
|
|
BufferDrive = -1;
|
|
|
|
clear_bit(drive, &fake_change);
|
|
|
|
clear_bit(drive, &changed_floppies);
|
|
|
|
/* MSch: clearing geometry makes sense only for autoprobe
|
|
|
|
formats, for 'permanent user-defined' parameter:
|
|
|
|
restore default_params[] here if flagged valid! */
|
|
|
|
if (default_params[drive].blocks == 0)
|
2006-01-12 09:06:29 +00:00
|
|
|
UDT = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
|
|
|
UDT = &default_params[drive];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This sets up the global variables describing the current request. */
|
|
|
|
|
|
|
|
static void setup_req_params( int drive )
|
|
|
|
{
|
|
|
|
int block = ReqBlock + ReqCnt;
|
|
|
|
|
|
|
|
ReqTrack = block / UDT->spt;
|
|
|
|
ReqSector = block - ReqTrack * UDT->spt + 1;
|
|
|
|
ReqSide = ReqTrack & 1;
|
|
|
|
ReqTrack >>= 1;
|
|
|
|
ReqData = ReqBuffer + 512 * ReqCnt;
|
|
|
|
|
|
|
|
if (UseTrackbuffer)
|
2022-05-08 09:37:08 +00:00
|
|
|
read_track = (ReqCmd == READ && unit[drive].error_count == 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
|
|
|
read_track = 0;
|
|
|
|
|
|
|
|
DPRINT(("Request params: Si=%d Tr=%d Se=%d Data=%08lx\n",ReqSide,
|
|
|
|
ReqTrack, ReqSector, (unsigned long)ReqData ));
|
|
|
|
}
|
|
|
|
|
2018-10-15 15:18:24 +00:00
|
|
|
static blk_status_t ataflop_queue_rq(struct blk_mq_hw_ctx *hctx,
|
|
|
|
const struct blk_mq_queue_data *bd)
|
2010-09-24 18:35:45 +00:00
|
|
|
{
|
2021-11-26 12:18:00 +00:00
|
|
|
struct atari_floppy_struct *floppy = bd->rq->q->disk->private_data;
|
2018-10-15 15:18:24 +00:00
|
|
|
int drive = floppy - unit;
|
|
|
|
int type = floppy->type;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
DPRINT(("Queue request: drive %d type %d sectors %d of %d last %d\n",
|
|
|
|
drive, type, blk_rq_cur_sectors(bd->rq),
|
|
|
|
blk_rq_sectors(bd->rq), bd->last));
|
block: ataflop: fix breakage introduced at blk-mq refactoring
Refactoring of the Atari floppy driver when converting to blk-mq
has broken the state machine in not-so-subtle ways:
finish_fdc() must be called when operations on the floppy device
have completed. This is crucial in order to relase the ST-DMA
lock, which protects against concurrent access to the ST-DMA
controller by other drivers (some DMA related, most just related
to device register access - broken beyond compare, I know).
When rewriting the driver's old do_request() function, the fact
that finish_fdc() was called only when all queued requests had
completed appears to have been overlooked. Instead, the new
request function calls finish_fdc() immediately after the last
request has been queued. finish_fdc() executes a dummy seek after
most requests, and this overwrites the state machine's interrupt
hander that was set up to wait for completion of the read/write
request just prior. To make matters worse, finish_fdc() is called
before device interrupts are re-enabled, making certain that the
read/write interupt is missed.
Shifting the finish_fdc() call into the read/write request
completion handler ensures the driver waits for the request to
actually complete. With a queue depth of 2, we won't see long
request sequences, so calling finish_fdc() unconditionally just
adds a little overhead for the dummy seeks, and keeps the code
simple.
While we're at it, kill ataflop_commit_rqs() which does nothing
but run finish_fdc() unconditionally, again likely wiping out an
in-flight request.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95 ("ataflop: convert to blk-mq")
CC: linux-block@vger.kernel.org
CC: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Link: https://lore.kernel.org/r/20211019061321.26425-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-19 06:13:21 +00:00
|
|
|
|
2018-10-15 15:18:24 +00:00
|
|
|
spin_lock_irq(&ataflop_lock);
|
|
|
|
if (fd_request) {
|
|
|
|
spin_unlock_irq(&ataflop_lock);
|
|
|
|
return BLK_STS_DEV_RESOURCE;
|
|
|
|
}
|
|
|
|
if (!stdma_try_lock(floppy_irq, NULL)) {
|
|
|
|
spin_unlock_irq(&ataflop_lock);
|
|
|
|
return BLK_STS_RESOURCE;
|
|
|
|
}
|
|
|
|
fd_request = bd->rq;
|
2022-05-08 09:37:08 +00:00
|
|
|
unit[drive].error_count = 0;
|
2018-10-15 15:18:24 +00:00
|
|
|
blk_mq_start_request(fd_request);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-10-15 15:18:24 +00:00
|
|
|
atari_disable_irq( IRQ_MFP_FDC );
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
IsFormatting = 0;
|
|
|
|
|
|
|
|
if (!UD.connected) {
|
|
|
|
/* drive not connected */
|
|
|
|
printk(KERN_ERR "Unknown Device: fd%d\n", drive );
|
2017-06-03 07:38:04 +00:00
|
|
|
fd_end_request_cur(BLK_STS_IOERR);
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
stdma_release();
|
2018-10-15 15:18:24 +00:00
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (type == 0) {
|
|
|
|
if (!UDT) {
|
|
|
|
Probing = 1;
|
2008-02-06 09:38:09 +00:00
|
|
|
UDT = atari_disk_type + StartDiskType[DriveType];
|
2021-11-26 12:18:00 +00:00
|
|
|
set_capacity(bd->rq->q->disk, UDT->blocks);
|
2005-04-16 22:20:36 +00:00
|
|
|
UD.autoprobe = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* user supplied disk type */
|
|
|
|
if (--type >= NUM_DISK_MINORS) {
|
|
|
|
printk(KERN_WARNING "fd%d: invalid disk format", drive );
|
2017-06-03 07:38:04 +00:00
|
|
|
fd_end_request_cur(BLK_STS_IOERR);
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
stdma_release();
|
2018-10-15 15:18:24 +00:00
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
if (minor2disktype[type].drive_types > DriveType) {
|
|
|
|
printk(KERN_WARNING "fd%d: unsupported disk format", drive );
|
2017-06-03 07:38:04 +00:00
|
|
|
fd_end_request_cur(BLK_STS_IOERR);
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
stdma_release();
|
2018-10-15 15:18:24 +00:00
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
type = minor2disktype[type].index;
|
2008-02-06 09:38:09 +00:00
|
|
|
UDT = &atari_disk_type[type];
|
2021-11-26 12:18:00 +00:00
|
|
|
set_capacity(bd->rq->q->disk, UDT->blocks);
|
2005-04-16 22:20:36 +00:00
|
|
|
UD.autoprobe = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* stop deselect timer */
|
|
|
|
del_timer( &motor_off_timer );
|
|
|
|
|
|
|
|
ReqCnt = 0;
|
2009-05-08 02:54:03 +00:00
|
|
|
ReqCmd = rq_data_dir(fd_request);
|
|
|
|
ReqBlock = blk_rq_pos(fd_request);
|
2014-04-10 15:46:28 +00:00
|
|
|
ReqBuffer = bio_data(fd_request->bio);
|
2005-04-16 22:20:36 +00:00
|
|
|
setup_req_params( drive );
|
|
|
|
do_fd_action( drive );
|
|
|
|
|
|
|
|
atari_enable_irq( IRQ_MFP_FDC );
|
2018-10-15 15:18:24 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
spin_unlock_irq(&ataflop_lock);
|
|
|
|
return BLK_STS_OK;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 11:02:55 +00:00
|
|
|
static int fd_locked_ioctl(struct block_device *bdev, blk_mode_t mode,
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned int cmd, unsigned long param)
|
|
|
|
{
|
2008-03-02 14:23:54 +00:00
|
|
|
struct gendisk *disk = bdev->bd_disk;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct atari_floppy_struct *floppy = disk->private_data;
|
|
|
|
int drive = floppy - unit;
|
|
|
|
int type = floppy->type;
|
|
|
|
struct atari_format_descr fmt_desc;
|
|
|
|
struct atari_disk_type *dtp;
|
|
|
|
struct floppy_struct getprm;
|
|
|
|
int settype;
|
|
|
|
struct floppy_struct setprm;
|
2006-01-12 09:06:29 +00:00
|
|
|
void __user *argp = (void __user *)param;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case FDGETPRM:
|
|
|
|
if (type) {
|
|
|
|
if (--type >= NUM_DISK_MINORS)
|
|
|
|
return -ENODEV;
|
|
|
|
if (minor2disktype[type].drive_types > DriveType)
|
|
|
|
return -ENODEV;
|
|
|
|
type = minor2disktype[type].index;
|
2008-02-06 09:38:09 +00:00
|
|
|
dtp = &atari_disk_type[type];
|
2005-04-16 22:20:36 +00:00
|
|
|
if (UD.flags & FTD_MSG)
|
|
|
|
printk (KERN_ERR "floppy%d: found dtp %p name %s!\n",
|
|
|
|
drive, dtp, dtp->name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!UDT)
|
|
|
|
return -ENXIO;
|
|
|
|
else
|
|
|
|
dtp = UDT;
|
|
|
|
}
|
|
|
|
memset((void *)&getprm, 0, sizeof(getprm));
|
|
|
|
getprm.size = dtp->blocks;
|
|
|
|
getprm.sect = dtp->spt;
|
|
|
|
getprm.head = 2;
|
|
|
|
getprm.track = dtp->blocks/dtp->spt/2;
|
|
|
|
getprm.stretch = dtp->stretch;
|
2006-01-12 09:06:29 +00:00
|
|
|
if (copy_to_user(argp, &getprm, sizeof(getprm)))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
switch (cmd) {
|
|
|
|
case FDSETPRM:
|
|
|
|
case FDDEFPRM:
|
|
|
|
/*
|
|
|
|
* MSch 7/96: simple 'set geometry' case: just set the
|
|
|
|
* 'default' device params (minor == 0).
|
|
|
|
* Currently, the drive geometry is cleared after each
|
|
|
|
* disk change and subsequent revalidate()! simple
|
|
|
|
* implementation of FDDEFPRM: save geometry from a
|
|
|
|
* FDDEFPRM call and restore it in floppy_revalidate() !
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* get the parameters from user space */
|
|
|
|
if (floppy->ref != 1 && floppy->ref != -1)
|
|
|
|
return -EBUSY;
|
2006-01-12 09:06:29 +00:00
|
|
|
if (copy_from_user(&setprm, argp, sizeof(setprm)))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EFAULT;
|
|
|
|
/*
|
|
|
|
* first of all: check for floppy change and revalidate,
|
|
|
|
* or the next access will revalidate - and clear UDT :-(
|
|
|
|
*/
|
|
|
|
|
2011-03-09 18:54:27 +00:00
|
|
|
if (floppy_check_events(disk, 0))
|
2005-04-16 22:20:36 +00:00
|
|
|
floppy_revalidate(disk);
|
|
|
|
|
|
|
|
if (UD.flags & FTD_MSG)
|
|
|
|
printk (KERN_INFO "floppy%d: setting size %d spt %d str %d!\n",
|
|
|
|
drive, setprm.size, setprm.sect, setprm.stretch);
|
|
|
|
|
|
|
|
/* what if type > 0 here? Overwrite specified entry ? */
|
|
|
|
if (type) {
|
|
|
|
/* refuse to re-set a predefined type for now */
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
finish_fdc();
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* type == 0: first look for a matching entry in the type list,
|
|
|
|
* and set the UD.disktype field to use the perdefined entry.
|
|
|
|
* TODO: add user-defined format to head of autoprobe list ?
|
|
|
|
* Useful to include the user-type for future autodetection!
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (settype = 0; settype < NUM_DISK_MINORS; settype++) {
|
|
|
|
int setidx = 0;
|
|
|
|
if (minor2disktype[settype].drive_types > DriveType) {
|
|
|
|
/* skip this one, invalid for drive ... */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
setidx = minor2disktype[settype].index;
|
2008-02-06 09:38:09 +00:00
|
|
|
dtp = &atari_disk_type[setidx];
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* found matching entry ?? */
|
|
|
|
if ( dtp->blocks == setprm.size
|
|
|
|
&& dtp->spt == setprm.sect
|
|
|
|
&& dtp->stretch == setprm.stretch ) {
|
|
|
|
if (UD.flags & FTD_MSG)
|
|
|
|
printk (KERN_INFO "floppy%d: setting %s %p!\n",
|
|
|
|
drive, dtp->name, dtp);
|
|
|
|
UDT = dtp;
|
2020-10-29 14:58:38 +00:00
|
|
|
set_capacity(disk, UDT->blocks);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (cmd == FDDEFPRM) {
|
|
|
|
/* save settings as permanent default type */
|
|
|
|
default_params[drive].name = dtp->name;
|
|
|
|
default_params[drive].spt = dtp->spt;
|
|
|
|
default_params[drive].blocks = dtp->blocks;
|
|
|
|
default_params[drive].fdc_speed = dtp->fdc_speed;
|
|
|
|
default_params[drive].stretch = dtp->stretch;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no matching disk type found above - setting user_params */
|
|
|
|
|
|
|
|
if (cmd == FDDEFPRM) {
|
|
|
|
/* set permanent type */
|
|
|
|
dtp = &default_params[drive];
|
|
|
|
} else
|
|
|
|
/* set user type (reset by disk change!) */
|
|
|
|
dtp = &user_params[drive];
|
|
|
|
|
|
|
|
dtp->name = "user format";
|
|
|
|
dtp->blocks = setprm.size;
|
|
|
|
dtp->spt = setprm.sect;
|
|
|
|
if (setprm.sect > 14)
|
|
|
|
dtp->fdc_speed = 3;
|
|
|
|
else
|
|
|
|
dtp->fdc_speed = 0;
|
|
|
|
dtp->stretch = setprm.stretch;
|
|
|
|
|
|
|
|
if (UD.flags & FTD_MSG)
|
|
|
|
printk (KERN_INFO "floppy%d: blk %d spt %d str %d!\n",
|
|
|
|
drive, dtp->blocks, dtp->spt, dtp->stretch);
|
|
|
|
|
|
|
|
/* sanity check */
|
2009-07-13 20:43:41 +00:00
|
|
|
if (setprm.track != dtp->blocks/dtp->spt/2 ||
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
setprm.head != 2) {
|
|
|
|
finish_fdc();
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
block: ataflop: more blk-mq refactoring fixes
As it turns out, my earlier patch in commit 86d46fdaa12a (block:
ataflop: fix breakage introduced at blk-mq refactoring) was
incomplete. This patch fixes any remaining issues found during
more testing and code review.
Requests exceeding 4 k are handled in 4k segments but
__blk_mq_end_request() is never called on these (still
sectors outstanding on the request). With redo_fd_request()
removed, there is no provision to kick off processing of the
next segment, causing requests exceeding 4k to hang. (By
setting /sys/block/fd0/queue/max_sectors_k <= 4 as workaround,
this behaviour can be avoided).
Instead of reintroducing redo_fd_request(), requeue the remainder
of the request by calling blk_mq_requeue_request() on incomplete
requests (i.e. when blk_update_request() still returns true), and
rely on the block layer to queue the residual as new request.
Both error handling and formatting needs to release the
ST-DMA lock, so call finish_fdc() on these (this was previously
handled by redo_fd_request()). finish_fdc() may be called
legitimately without the ST-DMA lock held - make sure we only
release the lock if we actually held it. In a similar way,
early exit due to errors in ataflop_queue_rq() must release
the lock.
After minor errors, fd_error sets up to recalibrate the drive
but never re-runs the current operation (another task handled by
redo_fd_request() before). Call do_fd_action() to get the next
steps (seek, retry read/write) underway.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Fixes: 6ec3938cff95f (ataflop: convert to blk-mq)
CC: linux-block@vger.kernel.org
Link: https://lore.kernel.org/r/20211024002013.9332-1-schmitzmic@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-24 00:20:13 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
UDT = dtp;
|
2020-10-29 14:58:38 +00:00
|
|
|
set_capacity(disk, UDT->blocks);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
case FDMSGON:
|
|
|
|
UD.flags |= FTD_MSG;
|
|
|
|
return 0;
|
|
|
|
case FDMSGOFF:
|
|
|
|
UD.flags &= ~FTD_MSG;
|
|
|
|
return 0;
|
|
|
|
case FDSETEMSGTRESH:
|
|
|
|
return -EINVAL;
|
|
|
|
case FDFMTBEG:
|
|
|
|
return 0;
|
|
|
|
case FDFMTTRK:
|
|
|
|
if (floppy->ref != 1 && floppy->ref != -1)
|
|
|
|
return -EBUSY;
|
2006-01-12 09:06:29 +00:00
|
|
|
if (copy_from_user(&fmt_desc, argp, sizeof(fmt_desc)))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EFAULT;
|
|
|
|
return do_format(drive, type, &fmt_desc);
|
|
|
|
case FDCLRPRM:
|
|
|
|
UDT = NULL;
|
|
|
|
/* MSch: invalidate default_params */
|
|
|
|
default_params[drive].blocks = 0;
|
2020-10-29 14:58:38 +00:00
|
|
|
set_capacity(disk, MAX_DISK_SIZE * 2);
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough;
|
2005-04-16 22:20:36 +00:00
|
|
|
case FDFMTEND:
|
|
|
|
case FDFLUSH:
|
|
|
|
/* invalidate the buffer track to force a reread */
|
|
|
|
BufferDrive = -1;
|
|
|
|
set_bit(drive, &fake_change);
|
2023-10-17 18:48:21 +00:00
|
|
|
if (disk_check_media_change(disk)) {
|
|
|
|
bdev_mark_dead(disk->part0, true);
|
2023-06-08 11:02:35 +00:00
|
|
|
floppy_revalidate(disk);
|
2023-10-17 18:48:21 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-08 11:02:55 +00:00
|
|
|
static int fd_ioctl(struct block_device *bdev, blk_mode_t mode,
|
2010-07-08 08:18:46 +00:00
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_lock(&ataflop_mutex);
|
2010-07-08 08:18:46 +00:00
|
|
|
ret = fd_locked_ioctl(bdev, mode, cmd, arg);
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_unlock(&ataflop_mutex);
|
2010-07-08 08:18:46 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Initialize the 'unit' variable for drive 'drive' */
|
|
|
|
|
|
|
|
static void __init fd_probe( int drive )
|
|
|
|
{
|
|
|
|
UD.connected = 0;
|
|
|
|
UDT = NULL;
|
|
|
|
|
|
|
|
if (!fd_test_drive_present( drive ))
|
|
|
|
return;
|
|
|
|
|
|
|
|
UD.connected = 1;
|
|
|
|
UD.track = 0;
|
|
|
|
switch( UserSteprate[drive] ) {
|
|
|
|
case 2:
|
|
|
|
UD.steprate = FDCSTEP_2;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
UD.steprate = FDCSTEP_3;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
UD.steprate = FDCSTEP_6;
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
UD.steprate = FDCSTEP_12;
|
|
|
|
break;
|
|
|
|
default: /* should be -1 for "not set by user" */
|
|
|
|
if (ATARIHW_PRESENT( FDCSPEED ) || MACH_IS_MEDUSA)
|
|
|
|
UD.steprate = FDCSTEP_3;
|
|
|
|
else
|
|
|
|
UD.steprate = FDCSTEP_6;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
MotorOn = 1; /* from probe restore operation! */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This function tests the physical presence of a floppy drive (not
|
|
|
|
* whether a disk is inserted). This is done by issuing a restore
|
|
|
|
* command, waiting max. 2 seconds (that should be enough to move the
|
|
|
|
* head across the whole disk) and looking at the state of the "TR00"
|
|
|
|
* signal. This should now be raised if there is a drive connected
|
|
|
|
* (and there is no hardware failure :-) Otherwise, the drive is
|
|
|
|
* declared absent.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int __init fd_test_drive_present( int drive )
|
|
|
|
{
|
|
|
|
unsigned long timeout;
|
|
|
|
unsigned char status;
|
|
|
|
int ok;
|
|
|
|
|
|
|
|
if (drive >= (MACH_IS_FALCON ? 1 : 2)) return( 0 );
|
|
|
|
fd_select_drive( drive );
|
|
|
|
|
|
|
|
/* disable interrupt temporarily */
|
|
|
|
atari_turnoff_irq( IRQ_MFP_FDC );
|
|
|
|
FDC_WRITE (FDCREG_TRACK, 0xff00);
|
|
|
|
FDC_WRITE( FDCREG_CMD, FDCCMD_RESTORE | FDCCMDADD_H | FDCSTEP_6 );
|
|
|
|
|
|
|
|
timeout = jiffies + 2*HZ+HZ/2;
|
|
|
|
while (time_before(jiffies, timeout))
|
2009-02-22 08:38:47 +00:00
|
|
|
if (!(st_mfp.par_dt_reg & 0x20))
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
status = FDC_READ( FDCREG_STATUS );
|
|
|
|
ok = (status & FDCSTAT_TR00) != 0;
|
|
|
|
|
|
|
|
/* force interrupt to abort restore operation (FDC would try
|
|
|
|
* about 50 seconds!) */
|
|
|
|
FDC_WRITE( FDCREG_CMD, FDCCMD_FORCI );
|
|
|
|
udelay(500);
|
|
|
|
status = FDC_READ( FDCREG_STATUS );
|
|
|
|
udelay(20);
|
|
|
|
|
|
|
|
if (ok) {
|
|
|
|
/* dummy seek command to make WP bit accessible */
|
|
|
|
FDC_WRITE( FDCREG_DATA, 0 );
|
|
|
|
FDC_WRITE( FDCREG_CMD, FDCCMD_SEEK );
|
2009-02-22 08:38:47 +00:00
|
|
|
while( st_mfp.par_dt_reg & 0x20 )
|
2005-04-16 22:20:36 +00:00
|
|
|
;
|
|
|
|
status = FDC_READ( FDCREG_STATUS );
|
|
|
|
}
|
|
|
|
|
|
|
|
atari_turnon_irq( IRQ_MFP_FDC );
|
|
|
|
return( ok );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Look how many and which kind of drives are connected. If there are
|
|
|
|
* floppies, additionally start the disk-change and motor-off timers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void __init config_types( void )
|
|
|
|
{
|
|
|
|
int drive, cnt = 0;
|
|
|
|
|
|
|
|
/* for probing drives, set the FDC speed to 8 MHz */
|
|
|
|
if (ATARIHW_PRESENT(FDCSPEED))
|
|
|
|
dma_wd.fdc_speed = 0;
|
|
|
|
|
|
|
|
printk(KERN_INFO "Probing floppy drive(s):\n");
|
|
|
|
for( drive = 0; drive < FD_MAX_UNITS; drive++ ) {
|
|
|
|
fd_probe( drive );
|
|
|
|
if (UD.connected) {
|
|
|
|
printk(KERN_INFO "fd%d\n", drive);
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FDC_READ( FDCREG_STATUS ) & FDCSTAT_BUSY) {
|
|
|
|
/* If FDC is still busy from probing, give it another FORCI
|
|
|
|
* command to abort the operation. If this isn't done, the FDC
|
|
|
|
* will interrupt later and its IRQ line stays low, because
|
|
|
|
* the status register isn't read. And this will block any
|
|
|
|
* interrupts on this IRQ line :-(
|
|
|
|
*/
|
|
|
|
FDC_WRITE( FDCREG_CMD, FDCCMD_FORCI );
|
|
|
|
udelay(500);
|
|
|
|
FDC_READ( FDCREG_STATUS );
|
|
|
|
udelay(20);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt > 0) {
|
|
|
|
start_motor_off_timer();
|
|
|
|
if (cnt == 1) fd_select_drive( 0 );
|
|
|
|
start_check_change_timer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* floppy_open check for aliasing (/dev/fd0 can be the same as
|
|
|
|
* /dev/PS0 etc), and disallows simultaneous access to the same
|
|
|
|
* drive with different device numbers.
|
|
|
|
*/
|
|
|
|
|
2023-06-08 11:02:55 +00:00
|
|
|
static int floppy_open(struct gendisk *disk, blk_mode_t mode)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2023-06-08 11:02:36 +00:00
|
|
|
struct atari_floppy_struct *p = disk->private_data;
|
|
|
|
int type = disk->first_minor >> 2;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
DPRINT(("fd_open: type=%d\n",type));
|
|
|
|
if (p->ref && p->type != type)
|
|
|
|
return -EBUSY;
|
|
|
|
|
2023-06-08 11:02:55 +00:00
|
|
|
if (p->ref == -1 || (p->ref && mode & BLK_OPEN_EXCL))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EBUSY;
|
2023-06-08 11:02:55 +00:00
|
|
|
if (mode & BLK_OPEN_EXCL)
|
2005-04-16 22:20:36 +00:00
|
|
|
p->ref = -1;
|
|
|
|
else
|
|
|
|
p->ref++;
|
|
|
|
|
|
|
|
p->type = type;
|
|
|
|
|
2023-06-08 11:02:55 +00:00
|
|
|
if (mode & BLK_OPEN_NDELAY)
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
|
2023-06-08 11:02:55 +00:00
|
|
|
if (mode & (BLK_OPEN_READ | BLK_OPEN_WRITE)) {
|
2023-06-08 11:02:36 +00:00
|
|
|
if (disk_check_media_change(disk))
|
|
|
|
floppy_revalidate(disk);
|
2023-06-08 11:02:55 +00:00
|
|
|
if (mode & BLK_OPEN_WRITE) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (p->wpstat) {
|
|
|
|
if (p->ref < 0)
|
|
|
|
p->ref = 0;
|
|
|
|
else
|
|
|
|
p->ref--;
|
|
|
|
return -EROFS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-06-08 11:02:55 +00:00
|
|
|
static int floppy_unlocked_open(struct gendisk *disk, blk_mode_t mode)
|
2010-08-07 16:25:34 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_lock(&ataflop_mutex);
|
2023-06-08 11:02:36 +00:00
|
|
|
ret = floppy_open(disk, mode);
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_unlock(&ataflop_mutex);
|
2010-08-07 16:25:34 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2023-06-08 11:02:37 +00:00
|
|
|
static void floppy_release(struct gendisk *disk)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-03-02 14:23:54 +00:00
|
|
|
struct atari_floppy_struct *p = disk->private_data;
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_lock(&ataflop_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (p->ref < 0)
|
|
|
|
p->ref = 0;
|
|
|
|
else if (!p->ref--) {
|
|
|
|
printk(KERN_ERR "floppy_release with fd_ref == 0");
|
|
|
|
p->ref = 0;
|
|
|
|
}
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_unlock(&ataflop_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2009-09-22 00:01:13 +00:00
|
|
|
static const struct block_device_operations floppy_fops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.owner = THIS_MODULE,
|
2010-08-07 16:25:34 +00:00
|
|
|
.open = floppy_unlocked_open,
|
2008-03-02 14:23:54 +00:00
|
|
|
.release = floppy_release,
|
2010-07-08 08:18:46 +00:00
|
|
|
.ioctl = fd_ioctl,
|
2011-03-09 18:54:27 +00:00
|
|
|
.check_events = floppy_check_events,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2018-10-15 15:18:24 +00:00
|
|
|
static const struct blk_mq_ops ataflop_mq_ops = {
|
|
|
|
.queue_rq = ataflop_queue_rq,
|
|
|
|
};
|
|
|
|
|
2020-10-29 14:58:38 +00:00
|
|
|
static int ataflop_alloc_disk(unsigned int drive, unsigned int type)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2020-10-29 14:58:38 +00:00
|
|
|
struct gendisk *disk;
|
|
|
|
|
2024-02-13 07:34:20 +00:00
|
|
|
disk = blk_mq_alloc_disk(&unit[drive].tag_set, NULL, NULL);
|
2021-06-02 06:53:44 +00:00
|
|
|
if (IS_ERR(disk))
|
|
|
|
return PTR_ERR(disk);
|
2020-10-29 14:58:38 +00:00
|
|
|
|
|
|
|
disk->major = FLOPPY_MAJOR;
|
|
|
|
disk->first_minor = drive + (type << 2);
|
2021-06-02 06:53:44 +00:00
|
|
|
disk->minors = 1;
|
2020-10-29 14:58:38 +00:00
|
|
|
sprintf(disk->disk_name, "fd%d", drive);
|
|
|
|
disk->fops = &floppy_fops;
|
2021-11-22 13:06:22 +00:00
|
|
|
disk->flags |= GENHD_FL_NO_PART;
|
2020-10-29 14:58:38 +00:00
|
|
|
disk->events = DISK_EVENT_MEDIA_CHANGE;
|
|
|
|
disk->private_data = &unit[drive];
|
|
|
|
set_capacity(disk, MAX_DISK_SIZE * 2);
|
|
|
|
|
|
|
|
unit[drive].disk[type] = disk;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ataflop_probe(dev_t dev)
|
|
|
|
{
|
|
|
|
int drive = MINOR(dev) & 3;
|
|
|
|
int type = MINOR(dev) >> 2;
|
|
|
|
|
2021-04-21 10:19:45 +00:00
|
|
|
if (type)
|
|
|
|
type--;
|
|
|
|
|
|
|
|
if (drive >= FD_MAX_UNITS || type >= NUM_DISK_MINORS)
|
2020-10-29 14:58:38 +00:00
|
|
|
return;
|
2021-11-03 23:04:35 +00:00
|
|
|
if (unit[drive].disk[type])
|
2021-11-06 18:55:49 +00:00
|
|
|
return;
|
2021-11-03 23:04:35 +00:00
|
|
|
if (ataflop_alloc_disk(drive, type))
|
|
|
|
return;
|
|
|
|
if (add_disk(unit[drive].disk[type]))
|
|
|
|
goto cleanup_disk;
|
|
|
|
unit[drive].registered[type] = true;
|
|
|
|
return;
|
|
|
|
|
|
|
|
cleanup_disk:
|
2022-06-19 06:05:52 +00:00
|
|
|
put_disk(unit[drive].disk[type]);
|
2021-11-03 23:04:35 +00:00
|
|
|
unit[drive].disk[type] = NULL;
|
2021-11-03 23:04:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void atari_floppy_cleanup(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
for (i = 0; i < FD_MAX_UNITS; i++) {
|
|
|
|
for (type = 0; type < NUM_DISK_MINORS; type++) {
|
|
|
|
if (!unit[i].disk[type])
|
|
|
|
continue;
|
|
|
|
del_gendisk(unit[i].disk[type]);
|
|
|
|
put_disk(unit[i].disk[type]);
|
|
|
|
}
|
|
|
|
blk_mq_free_tag_set(&unit[i].tag_set);
|
|
|
|
}
|
|
|
|
|
|
|
|
del_timer_sync(&fd_timer);
|
|
|
|
atari_stram_free(DMABuffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2021-09-27 22:03:01 +00:00
|
|
|
static void atari_cleanup_floppy_disk(struct atari_floppy_struct *fs)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
|
|
|
|
for (type = 0; type < NUM_DISK_MINORS; type++) {
|
|
|
|
if (!fs->disk[type])
|
|
|
|
continue;
|
|
|
|
if (fs->registered[type])
|
|
|
|
del_gendisk(fs->disk[type]);
|
2022-06-19 06:05:52 +00:00
|
|
|
put_disk(fs->disk[type]);
|
2021-09-27 22:03:01 +00:00
|
|
|
}
|
|
|
|
blk_mq_free_tag_set(&fs->tag_set);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static int __init atari_floppy_init (void)
|
|
|
|
{
|
|
|
|
int i;
|
2018-10-15 15:18:24 +00:00
|
|
|
int ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (!MACH_IS_ATARI)
|
|
|
|
/* Amiga, Mac, ... don't have Atari-compatible floppy :-) */
|
2008-07-17 19:16:10 +00:00
|
|
|
return -ENODEV;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
for (i = 0; i < FD_MAX_UNITS; i++) {
|
2020-10-29 14:58:38 +00:00
|
|
|
memset(&unit[i].tag_set, 0, sizeof(unit[i].tag_set));
|
|
|
|
unit[i].tag_set.ops = &ataflop_mq_ops;
|
|
|
|
unit[i].tag_set.nr_hw_queues = 1;
|
|
|
|
unit[i].tag_set.nr_maps = 1;
|
|
|
|
unit[i].tag_set.queue_depth = 2;
|
|
|
|
unit[i].tag_set.numa_node = NUMA_NO_NODE;
|
|
|
|
unit[i].tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
|
|
|
|
ret = blk_mq_alloc_tag_set(&unit[i].tag_set);
|
|
|
|
if (ret)
|
2018-10-15 15:18:24 +00:00
|
|
|
goto err;
|
2018-10-11 19:20:49 +00:00
|
|
|
|
2020-10-29 14:58:38 +00:00
|
|
|
ret = ataflop_alloc_disk(i, 0);
|
|
|
|
if (ret) {
|
|
|
|
blk_mq_free_tag_set(&unit[i].tag_set);
|
2018-10-15 15:18:24 +00:00
|
|
|
goto err;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (UseTrackbuffer < 0)
|
|
|
|
/* not set by user -> use default: for now, we turn
|
|
|
|
track buffering off for all Medusas, though it
|
|
|
|
could be used with ones that have a counter
|
|
|
|
card. But the test is too hard :-( */
|
|
|
|
UseTrackbuffer = !MACH_IS_MEDUSA;
|
|
|
|
|
|
|
|
/* initialize variables */
|
|
|
|
SelectedDrive = -1;
|
|
|
|
BufferDrive = -1;
|
|
|
|
|
|
|
|
DMABuffer = atari_stram_alloc(BUFFER_SIZE+512, "ataflop");
|
|
|
|
if (!DMABuffer) {
|
|
|
|
printk(KERN_ERR "atari_floppy_init: cannot get dma buffer\n");
|
2018-10-15 15:18:24 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
TrackBuffer = DMABuffer + 512;
|
2014-03-31 08:06:07 +00:00
|
|
|
PhysDMABuffer = atari_stram_to_phys(DMABuffer);
|
2005-04-16 22:20:36 +00:00
|
|
|
PhysTrackBuffer = virt_to_phys(TrackBuffer);
|
|
|
|
BufferDrive = BufferSide = BufferTrack = -1;
|
|
|
|
|
|
|
|
for (i = 0; i < FD_MAX_UNITS; i++) {
|
|
|
|
unit[i].track = -1;
|
|
|
|
unit[i].flags = 0;
|
2021-09-27 22:03:02 +00:00
|
|
|
ret = add_disk(unit[i].disk[0]);
|
|
|
|
if (ret)
|
|
|
|
goto err_out_dma;
|
2021-09-27 22:03:00 +00:00
|
|
|
unit[i].registered[0] = true;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printk(KERN_INFO "Atari floppy driver: max. %cD, %strack buffering\n",
|
|
|
|
DriveType == 0 ? 'D' : DriveType == 1 ? 'H' : 'E',
|
|
|
|
UseTrackbuffer ? "" : "no ");
|
|
|
|
config_types();
|
|
|
|
|
2021-11-03 23:04:33 +00:00
|
|
|
ret = __register_blkdev(FLOPPY_MAJOR, "fd", ataflop_probe);
|
|
|
|
if (ret) {
|
|
|
|
printk(KERN_ERR "atari_floppy_init: cannot register block device\n");
|
|
|
|
atari_floppy_cleanup();
|
|
|
|
}
|
|
|
|
return ret;
|
2018-10-15 15:18:24 +00:00
|
|
|
|
2021-09-27 22:03:02 +00:00
|
|
|
err_out_dma:
|
|
|
|
atari_stram_free(DMABuffer);
|
2018-10-15 15:18:24 +00:00
|
|
|
err:
|
2021-09-27 22:03:01 +00:00
|
|
|
while (--i >= 0)
|
|
|
|
atari_cleanup_floppy_disk(&unit[i]);
|
2010-09-24 18:35:45 +00:00
|
|
|
|
2018-10-15 15:18:24 +00:00
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 09:06:36 +00:00
|
|
|
#ifndef MODULE
|
|
|
|
static int __init atari_floppy_setup(char *str)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-01-12 09:06:36 +00:00
|
|
|
int ints[3 + FD_MAX_UNITS];
|
2005-04-16 22:20:36 +00:00
|
|
|
int i;
|
2006-01-12 09:06:36 +00:00
|
|
|
|
|
|
|
if (!MACH_IS_ATARI)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
str = get_options(str, 3 + FD_MAX_UNITS, ints);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (ints[0] < 1) {
|
|
|
|
printk(KERN_ERR "ataflop_setup: no arguments!\n" );
|
2006-01-12 09:06:36 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
else if (ints[0] > 2+FD_MAX_UNITS) {
|
|
|
|
printk(KERN_ERR "ataflop_setup: too many arguments\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ints[1] < 0 || ints[1] > 2)
|
|
|
|
printk(KERN_ERR "ataflop_setup: bad drive type\n" );
|
|
|
|
else
|
|
|
|
DriveType = ints[1];
|
|
|
|
|
|
|
|
if (ints[0] >= 2)
|
|
|
|
UseTrackbuffer = (ints[2] > 0);
|
|
|
|
|
|
|
|
for( i = 3; i <= ints[0] && i-3 < FD_MAX_UNITS; ++i ) {
|
|
|
|
if (ints[i] != 2 && ints[i] != 3 && ints[i] != 6 && ints[i] != 12)
|
|
|
|
printk(KERN_ERR "ataflop_setup: bad steprate\n" );
|
|
|
|
else
|
|
|
|
UserSteprate[i-3] = ints[i];
|
|
|
|
}
|
2006-01-12 09:06:36 +00:00
|
|
|
return 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 09:06:36 +00:00
|
|
|
__setup("floppy=", atari_floppy_setup);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void __exit atari_floppy_exit(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unregister_blkdev(FLOPPY_MAJOR, "fd");
|
2021-11-03 23:04:33 +00:00
|
|
|
atari_floppy_cleanup();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(atari_floppy_init)
|
|
|
|
module_exit(atari_floppy_exit)
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|