* [PATCH 00/18] ide: add generic ATA/ATAPI disk driver
@ 2008-09-07 22:14 Bartlomiej Zolnierkiewicz
2008-09-07 22:14 ` [PATCH 01/18] ide-disk: fix IDE_DFLAG_LBA48 handling on resume Bartlomiej Zolnierkiewicz
` (18 more replies)
0 siblings, 19 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:14 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
[ Borislav, this is the 'futuristic' stuff that we were talking about. :) ]
Hi,
This patch series adds a generic ATA/ATAPI disk driver (ide-gd) replacing
ide-disk and ide-floppy drivers. It is achieved by moving the common code
to ide-gd.c, adding struct ide_disk_ops (which is used to abstract protocol
specific details) and updating ide-{disk,floppy}.c accordingly.
The main goal is to make the code more maintainable / easier to extend later.
As an immediate result we get driver specific debugging support for ATA disks
and ability for driver specific Power Management for ATAPI devices. Otherwise
it is really an initial merge (which means that in the future the code can be
further unified, struct ide_disk_ops can be made more fine-grained etc.).
patches:
#01-02 drive-by bugfixes
#03-04 small improvements (good on their own)
#05-12 small cleanups (good on their own)
#13-17 preparatory patches (just to make the review easier)
#18 the main patch
diffstat:
drivers/ide/Kconfig | 64 +--
drivers/ide/Makefile | 23 -
drivers/ide/ide-atapi.c | 2
drivers/ide/ide-cd.c | 22 -
drivers/ide/ide-cd_ioctl.c | 8
drivers/ide/ide-disk.c | 434 ++++------------------
drivers/ide/ide-disk.h | 35 -
drivers/ide/ide-disk_ioctl.c | 6
drivers/ide/ide-disk_proc.c | 2
drivers/ide/ide-floppy.c | 419 +++------------------
drivers/ide/ide-floppy.h | 79 +---
drivers/ide/ide-floppy_ioctl.c | 15
drivers/ide/ide-floppy_proc.c | 2
drivers/ide/ide-gd-floppy.c | 802 ++++++++++++++++++++---------------------
drivers/ide/ide-gd.c | 437 +++++++++++++++++++++-
drivers/ide/ide-gd.h | 44 ++
drivers/ide/ide-probe.c | 1
drivers/ide/ide-proc.c | 6
drivers/ide/ide-tape.c | 16
drivers/leds/Kconfig | 2
drivers/scsi/ide-scsi.c | 26 -
include/linux/ide.h | 34 +
22 files changed, 1209 insertions(+), 1270 deletions(-)
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 01/18] ide-disk: fix IDE_DFLAG_LBA48 handling on resume
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:14 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:14 ` [PATCH 02/18] ide-disk: lock media before checking for media change Bartlomiej Zolnierkiewicz
` (17 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:14 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
Some code in idedisk_setup() should be in idedisk_capacity() instead.
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/ide-disk.c | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
Index: b/drivers/ide/ide-disk.c
===================================================================
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -397,6 +397,26 @@ static void init_idedisk_capacity(ide_dr
if (ata_id_hpa_enabled(id))
idedisk_check_hpa(drive);
}
+
+ /* limit drive capacity to 137GB if LBA48 cannot be used */
+ if ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 &&
+ drive->capacity64 > 1ULL << 28) {
+ printk(KERN_WARNING "%s: cannot use LBA48 - full capacity "
+ "%llu sectors (%llu MB)\n",
+ drive->name, (unsigned long long)drive->capacity64,
+ sectors_to_MB(drive->capacity64));
+ drive->capacity64 = 1ULL << 28;
+ }
+
+ if ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) &&
+ (drive->dev_flags & IDE_DFLAG_LBA48)) {
+ if (drive->capacity64 > 1ULL << 28) {
+ printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode"
+ " will be used for accessing sectors "
+ "> %u\n", drive->name, 1 << 28);
+ } else
+ drive->dev_flags &= ~IDE_DFLAG_LBA48;
+ }
}
sector_t ide_disk_capacity(ide_drive_t *drive)
@@ -648,26 +668,6 @@ static void idedisk_setup(ide_drive_t *d
/* calculate drive capacity, and select LBA if possible */
init_idedisk_capacity(drive);
- /* limit drive capacity to 137GB if LBA48 cannot be used */
- if ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 &&
- drive->capacity64 > 1ULL << 28) {
- printk(KERN_WARNING "%s: cannot use LBA48 - full capacity "
- "%llu sectors (%llu MB)\n",
- drive->name, (unsigned long long)drive->capacity64,
- sectors_to_MB(drive->capacity64));
- drive->capacity64 = 1ULL << 28;
- }
-
- if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) &&
- (drive->dev_flags & IDE_DFLAG_LBA48)) {
- if (drive->capacity64 > 1ULL << 28) {
- printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode"
- " will be used for accessing sectors "
- "> %u\n", drive->name, 1 << 28);
- } else
- drive->dev_flags &= ~IDE_DFLAG_LBA48;
- }
-
/*
* if possible, give fdisk access to more of the drive,
* by correcting bios_cyls:
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 02/18] ide-disk: lock media before checking for media change
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
2008-09-07 22:14 ` [PATCH 01/18] ide-disk: fix IDE_DFLAG_LBA48 handling on resume Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:14 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:14 ` [PATCH 03/18] ide-floppy: use alloc_disk_node() Bartlomiej Zolnierkiewicz
` (16 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:14 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/ide-disk.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Index: b/drivers/ide/ide-disk.c
===================================================================
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -836,7 +836,6 @@ static int idedisk_open(struct inode *in
idkp->openers++;
if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
- check_disk_change(inode->i_bdev);
/*
* Ignore the return code from door_lock,
* since the open() has already succeeded,
@@ -845,6 +844,7 @@ static int idedisk_open(struct inode *in
if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) &&
idedisk_set_doorlock(drive, 1))
drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
+ check_disk_change(inode->i_bdev);
}
return 0;
}
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 03/18] ide-floppy: use alloc_disk_node()
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
2008-09-07 22:14 ` [PATCH 01/18] ide-disk: fix IDE_DFLAG_LBA48 handling on resume Bartlomiej Zolnierkiewicz
2008-09-07 22:14 ` [PATCH 02/18] ide-disk: lock media before checking for media change Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:14 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:14 ` [PATCH 04/18] ide-disk: use to_ide_drv() and ide_drv_g() Bartlomiej Zolnierkiewicz
` (15 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:14 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/ide-floppy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -788,7 +788,7 @@ static int ide_floppy_probe(ide_drive_t
goto failed;
}
- g = alloc_disk(1 << PARTN_BITS);
+ g = alloc_disk_node(1 << PARTN_BITS, hwif_to_node(drive->hwif));
if (!g)
goto out_free_floppy;
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 04/18] ide-disk: use to_ide_drv() and ide_drv_g()
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
` (2 preceding siblings ...)
2008-09-07 22:14 ` [PATCH 03/18] ide-floppy: use alloc_disk_node() Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:14 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:14 ` [PATCH 05/18] ide-disk: move IDE_DFLAG_DOORLOCKING flag handling to idedisk_set_doorlock() Bartlomiej Zolnierkiewicz
` (14 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:14 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
There should be no functional changes caused by this patch.
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/ide-disk.c | 14 ++++++--------
drivers/ide/ide-disk.h | 3 ---
drivers/ide/ide-disk_ioctl.c | 2 +-
3 files changed, 7 insertions(+), 12 deletions(-)
Index: b/drivers/ide/ide-disk.c
===================================================================
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -43,8 +43,6 @@
static DEFINE_MUTEX(idedisk_ref_mutex);
-#define to_ide_disk(obj) container_of(obj, struct ide_disk_obj, kref)
-
static void ide_disk_release(struct kref *);
static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
@@ -52,7 +50,7 @@ static struct ide_disk_obj *ide_disk_get
struct ide_disk_obj *idkp = NULL;
mutex_lock(&idedisk_ref_mutex);
- idkp = ide_disk_g(disk);
+ idkp = ide_drv_g(disk, ide_disk_obj);
if (idkp) {
if (ide_device_get(idkp->drive))
idkp = NULL;
@@ -740,7 +738,7 @@ static void ide_disk_remove(ide_drive_t
static void ide_disk_release(struct kref *kref)
{
- struct ide_disk_obj *idkp = to_ide_disk(kref);
+ struct ide_disk_obj *idkp = to_ide_drv(kref, ide_disk_obj);
ide_drive_t *drive = idkp->drive;
struct gendisk *g = idkp->disk;
@@ -852,7 +850,7 @@ static int idedisk_open(struct inode *in
static int idedisk_release(struct inode *inode, struct file *filp)
{
struct gendisk *disk = inode->i_bdev->bd_disk;
- struct ide_disk_obj *idkp = ide_disk_g(disk);
+ struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
ide_drive_t *drive = idkp->drive;
if (idkp->openers == 1)
@@ -873,7 +871,7 @@ static int idedisk_release(struct inode
static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
{
- struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
+ struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
ide_drive_t *drive = idkp->drive;
geo->heads = drive->bios_head;
@@ -884,7 +882,7 @@ static int idedisk_getgeo(struct block_d
static int idedisk_media_changed(struct gendisk *disk)
{
- struct ide_disk_obj *idkp = ide_disk_g(disk);
+ struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
ide_drive_t *drive = idkp->drive;
/* do not scan partitions twice if this is a removable device */
@@ -899,7 +897,7 @@ static int idedisk_media_changed(struct
static int idedisk_revalidate_disk(struct gendisk *disk)
{
- struct ide_disk_obj *idkp = ide_disk_g(disk);
+ struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
set_capacity(disk, ide_disk_capacity(idkp->drive));
return 0;
}
Index: b/drivers/ide/ide-disk.h
===================================================================
--- a/drivers/ide/ide-disk.h
+++ b/drivers/ide/ide-disk.h
@@ -9,9 +9,6 @@ struct ide_disk_obj {
unsigned int openers; /* protected by BKL for now */
};
-#define ide_disk_g(disk) \
- container_of((disk)->private_data, struct ide_disk_obj, driver)
-
/* ide-disk.c */
sector_t ide_disk_capacity(ide_drive_t *);
ide_decl_devset(address);
Index: b/drivers/ide/ide-disk_ioctl.c
===================================================================
--- a/drivers/ide/ide-disk_ioctl.c
+++ b/drivers/ide/ide-disk_ioctl.c
@@ -17,7 +17,7 @@ int ide_disk_ioctl(struct inode *inode,
unsigned int cmd, unsigned long arg)
{
struct block_device *bdev = inode->i_bdev;
- struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
+ struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
ide_drive_t *drive = idkp->drive;
int err;
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 05/18] ide-disk: move IDE_DFLAG_DOORLOCKING flag handling to idedisk_set_doorlock()
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
` (3 preceding siblings ...)
2008-09-07 22:14 ` [PATCH 04/18] ide-disk: use to_ide_drv() and ide_drv_g() Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:14 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:15 ` [PATCH 06/18] ide-{disk,floppy}: set IDE_DFLAG_ATTACH in *_setup() Bartlomiej Zolnierkiewicz
` (13 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:14 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
There should be no functional changes caused by this patch.
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/ide-disk.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
Index: b/drivers/ide/ide-disk.c
===================================================================
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -811,12 +811,21 @@ static ide_driver_t idedisk_driver = {
static int idedisk_set_doorlock(ide_drive_t *drive, int on)
{
ide_task_t task;
+ int ret;
+
+ if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0)
+ return 0;
memset(&task, 0, sizeof(task));
task.tf.command = on ? ATA_CMD_MEDIA_LOCK : ATA_CMD_MEDIA_UNLOCK;
task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
- return ide_no_data_taskfile(drive, &task);
+ ret = ide_no_data_taskfile(drive, &task);
+
+ if (ret)
+ drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
+
+ return ret;
}
static int idedisk_open(struct inode *inode, struct file *filp)
@@ -839,9 +848,7 @@ static int idedisk_open(struct inode *in
* since the open() has already succeeded,
* and the door_lock is irrelevant at this point.
*/
- if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) &&
- idedisk_set_doorlock(drive, 1))
- drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
+ idedisk_set_doorlock(drive, 1);
check_disk_change(inode->i_bdev);
}
return 0;
@@ -856,11 +863,8 @@ static int idedisk_release(struct inode
if (idkp->openers == 1)
ide_cacheflush_p(drive);
- if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
- if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) &&
- idedisk_set_doorlock(drive, 0))
- drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
- }
+ if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1)
+ idedisk_set_doorlock(drive, 0);
idkp->openers--;
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 06/18] ide-{disk,floppy}: set IDE_DFLAG_ATTACH in *_setup()
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
` (4 preceding siblings ...)
2008-09-07 22:14 ` [PATCH 05/18] ide-disk: move IDE_DFLAG_DOORLOCKING flag handling to idedisk_set_doorlock() Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:15 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:15 ` [PATCH 07/18] ide-floppy: drop 'floppy' argument from idefloppy_setup() Bartlomiej Zolnierkiewicz
` (12 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:15 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
There should be no functional changes caused by this patch.
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/ide-disk.c | 18 ++++++++++--------
drivers/ide/ide-floppy.c | 3 ++-
2 files changed, 12 insertions(+), 9 deletions(-)
Index: b/drivers/ide/ide-disk.c
===================================================================
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -710,6 +710,14 @@ static void idedisk_setup(ide_drive_t *d
drive->dev_flags |= IDE_DFLAG_WCACHE;
set_wcache(drive, 1);
+
+ if ((drive->dev_flags & IDE_DFLAG_LBA) == 0 &&
+ (drive->head == 0 || drive->head > 16)) {
+ printk(KERN_ERR "%s: invalid geometry: %d physical heads?\n",
+ drive->name, drive->head);
+ drive->dev_flags &= ~IDE_DFLAG_ATTACH;
+ } else
+ drive->dev_flags |= IDE_DFLAG_ATTACH;
}
static void ide_cacheflush_p(ide_drive_t *drive)
@@ -952,19 +960,13 @@ static int ide_disk_probe(ide_drive_t *d
drive->driver_data = idkp;
idedisk_setup(drive);
- if ((drive->dev_flags & IDE_DFLAG_LBA) == 0 &&
- (drive->head == 0 || drive->head > 16)) {
- printk(KERN_ERR "%s: INVALID GEOMETRY: %d PHYSICAL HEADS?\n",
- drive->name, drive->head);
- drive->dev_flags &= ~IDE_DFLAG_ATTACH;
- } else
- drive->dev_flags |= IDE_DFLAG_ATTACH;
+
+ set_capacity(g, ide_disk_capacity(drive));
g->minors = 1 << PARTN_BITS;
g->driverfs_dev = &drive->gendev;
if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
g->flags = GENHD_FL_REMOVABLE;
- set_capacity(g, ide_disk_capacity(drive));
g->fops = &idedisk_ops;
add_disk(g);
return 0;
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -598,6 +598,8 @@ static void idefloppy_setup(ide_drive_t
(void) ide_floppy_get_capacity(drive);
ide_proc_register_driver(drive, floppy->driver);
+
+ drive->dev_flags |= IDE_DFLAG_ATTACH;
}
static void ide_floppy_remove(ide_drive_t *drive)
@@ -807,7 +809,6 @@ static int ide_floppy_probe(ide_drive_t
drive->debug_mask = debug_mask;
idefloppy_setup(drive, floppy);
- drive->dev_flags |= IDE_DFLAG_ATTACH;
g->minors = 1 << PARTN_BITS;
g->driverfs_dev = &drive->gendev;
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 07/18] ide-floppy: drop 'floppy' argument from idefloppy_setup()
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
` (5 preceding siblings ...)
2008-09-07 22:15 ` [PATCH 06/18] ide-{disk,floppy}: set IDE_DFLAG_ATTACH in *_setup() Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:15 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:15 ` [PATCH 08/18] ide-floppy: use drive->capacity64 for caching current capacity Bartlomiej Zolnierkiewicz
` (11 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:15 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/ide-floppy.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -560,8 +560,9 @@ sector_t ide_floppy_capacity(ide_drive_t
return capacity;
}
-static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
+static void idefloppy_setup(ide_drive_t *drive)
{
+ struct ide_floppy_obj *floppy = drive->driver_data;
u16 *id = drive->id;
drive->pc_callback = ide_floppy_callback;
@@ -808,7 +809,7 @@ static int ide_floppy_probe(ide_drive_t
drive->debug_mask = debug_mask;
- idefloppy_setup(drive, floppy);
+ idefloppy_setup(drive);
g->minors = 1 << PARTN_BITS;
g->driverfs_dev = &drive->gendev;
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 08/18] ide-floppy: use drive->capacity64 for caching current capacity
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
` (6 preceding siblings ...)
2008-09-07 22:15 ` [PATCH 07/18] ide-floppy: drop 'floppy' argument from idefloppy_setup() Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:15 ` Bartlomiej Zolnierkiewicz
2008-09-10 11:20 ` Borislav Petkov
2008-09-07 22:15 ` [PATCH 09/18] ide: IDE_AFLAG_MEDIA_CHANGED -> IDE_DFLAG_MEDIA_CHANGED Bartlomiej Zolnierkiewicz
` (10 subsequent siblings)
18 siblings, 1 reply; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:15 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
* Use drive->capacity64 for caching current capacity.
* Switch ide_floppy_capacity() to use drive->capacity64.
* Call set_capacity() in idefloppy_open() and ide_floppy_probe()
instead of ide_floppy_get_capacity().
There should be no functional changes caused by this patch.
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/ide-floppy.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -445,7 +445,9 @@ static int ide_floppy_get_flexible_disk_
drive->name, lba_capacity, capacity);
floppy->blocks = floppy->block_size ?
capacity / floppy->block_size : 0;
+ drive->capacity64 = floppy->blocks * floppy->bs_factor;
}
+
return 0;
}
@@ -466,7 +468,7 @@ static int ide_floppy_get_capacity(ide_d
drive->bios_head = drive->bios_sect = 0;
floppy->blocks = 0;
floppy->bs_factor = 1;
- set_capacity(floppy->disk, 0);
+ drive->capacity64 = 0;
ide_floppy_create_read_capacity_cmd(&pc);
if (ide_queue_pc_tail(drive, disk, &pc)) {
@@ -523,6 +525,8 @@ static int ide_floppy_get_capacity(ide_d
"non 512 bytes block size not "
"fully supported\n",
drive->name);
+ drive->capacity64 =
+ floppy->blocks * floppy->bs_factor;
rc = 0;
}
break;
@@ -547,17 +551,12 @@ static int ide_floppy_get_capacity(ide_d
if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
(void) ide_floppy_get_flexible_disk_page(drive);
- set_capacity(disk, floppy->blocks * floppy->bs_factor);
-
return rc;
}
sector_t ide_floppy_capacity(ide_drive_t *drive)
{
- idefloppy_floppy_t *floppy = drive->driver_data;
- unsigned long capacity = floppy->blocks * floppy->bs_factor;
-
- return capacity;
+ return drive->capacity64;
}
static void idefloppy_setup(ide_drive_t *drive)
@@ -671,14 +670,16 @@ static int idefloppy_open(struct inode *
if (ide_do_test_unit_ready(drive, disk))
ide_do_start_stop(drive, disk, 1);
- if (ide_floppy_get_capacity(drive)
- && (filp->f_flags & O_NDELAY) == 0
+ ret = ide_floppy_get_capacity(drive);
+
+ set_capacity(disk, ide_floppy_capacity(drive));
+
+ if (ret && (filp->f_flags & O_NDELAY) == 0) {
/*
* Allow O_NDELAY to open a drive without a disk, or with an
* unreadable disk, so that we can get the format capacity
* of the drive or begin the format - Sam
*/
- ) {
ret = -EIO;
goto out_put_floppy;
}
@@ -811,6 +812,8 @@ static int ide_floppy_probe(ide_drive_t
idefloppy_setup(drive);
+ set_capacity(g, ide_floppy_capacity(drive));
+
g->minors = 1 << PARTN_BITS;
g->driverfs_dev = &drive->gendev;
if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 09/18] ide: IDE_AFLAG_MEDIA_CHANGED -> IDE_DFLAG_MEDIA_CHANGED
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
` (7 preceding siblings ...)
2008-09-07 22:15 ` [PATCH 08/18] ide-floppy: use drive->capacity64 for caching current capacity Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:15 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:15 ` [PATCH 10/18] ide: IDE_AFLAG_WP -> IDE_DFLAG_WP Bartlomiej Zolnierkiewicz
` (9 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:15 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
There should be no functional changes caused by this patch.
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/ide-cd.c | 6 +++---
drivers/ide/ide-cd_ioctl.c | 4 ++--
drivers/ide/ide-floppy.c | 6 +++---
include/linux/ide.h | 2 +-
4 files changed, 9 insertions(+), 9 deletions(-)
Index: b/drivers/ide/ide-cd.c
===================================================================
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -88,7 +88,7 @@ static void ide_cd_put(struct cdrom_info
/* Mark that we've seen a media change and invalidate our internal buffers. */
static void cdrom_saw_media_change(ide_drive_t *drive)
{
- drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED;
+ drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
drive->atapi_flags &= ~IDE_AFLAG_TOC_VALID;
}
@@ -1882,8 +1882,8 @@ static int ide_cdrom_setup(ide_drive_t *
if (!drive->queue->unplug_delay)
drive->queue->unplug_delay = 1;
- drive->atapi_flags = IDE_AFLAG_MEDIA_CHANGED | IDE_AFLAG_NO_EJECT |
- ide_cd_flags(id);
+ drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
+ drive->atapi_flags = IDE_AFLAG_NO_EJECT | ide_cd_flags(id);
if ((drive->atapi_flags & IDE_AFLAG_VERTOS_300_SSD) &&
fw_rev[4] == '1' && fw_rev[6] <= '2')
Index: b/drivers/ide/ide-cd_ioctl.c
===================================================================
--- a/drivers/ide/ide-cd_ioctl.c
+++ b/drivers/ide/ide-cd_ioctl.c
@@ -86,8 +86,8 @@ int ide_cdrom_check_media_change_real(st
if (slot_nr == CDSL_CURRENT) {
(void) cdrom_check_status(drive, NULL);
- retval = (drive->atapi_flags & IDE_AFLAG_MEDIA_CHANGED) ? 1 : 0;
- drive->atapi_flags &= ~IDE_AFLAG_MEDIA_CHANGED;
+ retval = (drive->dev_flags & IDE_DFLAG_MEDIA_CHANGED) ? 1 : 0;
+ drive->dev_flags &= ~IDE_DFLAG_MEDIA_CHANGED;
return retval;
} else {
return -EINVAL;
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -689,8 +689,8 @@ static int idefloppy_open(struct inode *
goto out_put_floppy;
}
- drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED;
ide_set_media_lock(drive, disk, 1);
+ drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
check_disk_change(inode->i_bdev);
} else if (drive->atapi_flags & IDE_AFLAG_FORMAT_IN_PROGRESS) {
ret = -EBUSY;
@@ -747,8 +747,8 @@ static int idefloppy_media_changed(struc
drive->dev_flags &= ~IDE_DFLAG_ATTACH;
return 0;
}
- ret = !!(drive->atapi_flags & IDE_AFLAG_MEDIA_CHANGED);
- drive->atapi_flags &= ~IDE_AFLAG_MEDIA_CHANGED;
+ ret = !!(drive->dev_flags & IDE_DFLAG_MEDIA_CHANGED);
+ drive->dev_flags &= ~IDE_DFLAG_MEDIA_CHANGED;
return ret;
}
Index: b/include/linux/ide.h
===================================================================
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -462,7 +462,6 @@ struct ide_acpi_hwif_link;
/* ATAPI device flags */
enum {
IDE_AFLAG_DRQ_INTERRUPT = (1 << 0),
- IDE_AFLAG_MEDIA_CHANGED = (1 << 1),
/* Drive cannot lock the door. */
IDE_AFLAG_NO_DOORLOCK = (1 << 2),
@@ -571,6 +570,7 @@ enum {
/* retrying in PIO */
IDE_DFLAG_DMA_PIO_RETRY = (1 << 25),
IDE_DFLAG_LBA = (1 << 26),
+ IDE_DFLAG_MEDIA_CHANGED = (1 << 27),
};
struct ide_drive_s {
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 10/18] ide: IDE_AFLAG_WP -> IDE_DFLAG_WP
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
` (8 preceding siblings ...)
2008-09-07 22:15 ` [PATCH 09/18] ide: IDE_AFLAG_MEDIA_CHANGED -> IDE_DFLAG_MEDIA_CHANGED Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:15 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:15 ` [PATCH 11/18] ide: IDE_AFLAG_FORMAT_IN_PROGRESS -> IDE_DFLAG_FORMAT_IN_PROGRESS Bartlomiej Zolnierkiewicz
` (8 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:15 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
There should be no functional changes caused by this patch.
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/ide-floppy.c | 8 ++++----
include/linux/ide.h | 4 ++--
2 files changed, 6 insertions(+), 6 deletions(-)
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -410,11 +410,11 @@ static int ide_floppy_get_flexible_disk_
}
if (pc.buf[3] & 0x80)
- drive->atapi_flags |= IDE_AFLAG_WP;
+ drive->dev_flags |= IDE_DFLAG_WP;
else
- drive->atapi_flags &= ~IDE_AFLAG_WP;
+ drive->dev_flags &= ~IDE_DFLAG_WP;
- set_disk_ro(disk, !!(drive->atapi_flags & IDE_AFLAG_WP));
+ set_disk_ro(disk, !!(drive->dev_flags & IDE_DFLAG_WP));
page = &pc.buf[8];
@@ -684,7 +684,7 @@ static int idefloppy_open(struct inode *
goto out_put_floppy;
}
- if ((drive->atapi_flags & IDE_AFLAG_WP) && (filp->f_mode & 2)) {
+ if ((drive->dev_flags & IDE_DFLAG_WP) && (filp->f_mode & 2)) {
ret = -EROFS;
goto out_put_floppy;
}
Index: b/include/linux/ide.h
===================================================================
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -501,8 +501,6 @@ enum {
IDE_AFLAG_CLIK_DRIVE = (1 << 19),
/* Requires BH algorithm for packets */
IDE_AFLAG_ZIP_DRIVE = (1 << 20),
- /* Write protect */
- IDE_AFLAG_WP = (1 << 21),
/* Supports format progress report */
IDE_AFLAG_SRFP = (1 << 22),
@@ -571,6 +569,8 @@ enum {
IDE_DFLAG_DMA_PIO_RETRY = (1 << 25),
IDE_DFLAG_LBA = (1 << 26),
IDE_DFLAG_MEDIA_CHANGED = (1 << 27),
+ /* write protect */
+ IDE_DFLAG_WP = (1 << 28),
};
struct ide_drive_s {
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 11/18] ide: IDE_AFLAG_FORMAT_IN_PROGRESS -> IDE_DFLAG_FORMAT_IN_PROGRESS
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
` (9 preceding siblings ...)
2008-09-07 22:15 ` [PATCH 10/18] ide: IDE_AFLAG_WP -> IDE_DFLAG_WP Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:15 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:15 ` [PATCH 12/18] ide: remove IDE_AFLAG_NO_DOORLOCKING Bartlomiej Zolnierkiewicz
` (7 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:15 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
There should be no functional changes caused by this patch.
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/ide-floppy.c | 6 +++---
drivers/ide/ide-floppy_ioctl.c | 6 +++---
include/linux/ide.h | 3 +--
3 files changed, 7 insertions(+), 8 deletions(-)
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -664,7 +664,7 @@ static int idefloppy_open(struct inode *
floppy->openers++;
if (floppy->openers == 1) {
- drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
+ drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
/* Just in case */
if (ide_do_test_unit_ready(drive, disk))
@@ -692,7 +692,7 @@ static int idefloppy_open(struct inode *
ide_set_media_lock(drive, disk, 1);
drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
check_disk_change(inode->i_bdev);
- } else if (drive->atapi_flags & IDE_AFLAG_FORMAT_IN_PROGRESS) {
+ } else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) {
ret = -EBUSY;
goto out_put_floppy;
}
@@ -714,7 +714,7 @@ static int idefloppy_release(struct inod
if (floppy->openers == 1) {
ide_set_media_lock(drive, disk, 0);
- drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
+ drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
}
floppy->openers--;
Index: b/drivers/ide/ide-floppy_ioctl.c
===================================================================
--- a/drivers/ide/ide-floppy_ioctl.c
+++ b/drivers/ide/ide-floppy_ioctl.c
@@ -138,11 +138,11 @@ static int ide_floppy_format_unit(ide_dr
if (floppy->openers > 1) {
/* Don't format if someone is using the disk */
- drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
+ drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
return -EBUSY;
}
- drive->atapi_flags |= IDE_AFLAG_FORMAT_IN_PROGRESS;
+ drive->dev_flags |= IDE_DFLAG_FORMAT_IN_PROGRESS;
/*
* Send ATAPI_FORMAT_UNIT to the drive.
@@ -174,7 +174,7 @@ static int ide_floppy_format_unit(ide_dr
out:
if (err)
- drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
+ drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
return err;
}
Index: b/include/linux/ide.h
===================================================================
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -495,8 +495,6 @@ enum {
IDE_AFLAG_LE_SPEED_FIELDS = (1 << 17),
/* ide-floppy */
- /* Format in progress */
- IDE_AFLAG_FORMAT_IN_PROGRESS = (1 << 18),
/* Avoid commands not supported in Clik drive */
IDE_AFLAG_CLIK_DRIVE = (1 << 19),
/* Requires BH algorithm for packets */
@@ -571,6 +569,7 @@ enum {
IDE_DFLAG_MEDIA_CHANGED = (1 << 27),
/* write protect */
IDE_DFLAG_WP = (1 << 28),
+ IDE_DFLAG_FORMAT_IN_PROGRESS = (1 << 29),
};
struct ide_drive_s {
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 12/18] ide: remove IDE_AFLAG_NO_DOORLOCKING
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
` (10 preceding siblings ...)
2008-09-07 22:15 ` [PATCH 11/18] ide: IDE_AFLAG_FORMAT_IN_PROGRESS -> IDE_DFLAG_FORMAT_IN_PROGRESS Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:15 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:15 ` [PATCH 13/18] ide-disk: factor out generic disk handling code to ide-gd.c Bartlomiej Zolnierkiewicz
` (6 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:15 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
Just use IDE_DFLAG_DOORLOCKING instead.
There should be no functional changes caused by this patch.
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/ide-atapi.c | 2 +-
drivers/ide/ide-cd.c | 2 +-
drivers/ide/ide-cd_ioctl.c | 4 ++--
drivers/ide/ide-floppy.c | 2 +-
drivers/ide/ide-probe.c | 1 +
drivers/ide/ide-tape.c | 2 +-
include/linux/ide.h | 2 --
7 files changed, 7 insertions(+), 8 deletions(-)
Index: b/drivers/ide/ide-atapi.c
===================================================================
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -191,7 +191,7 @@ int ide_set_media_lock(ide_drive_t *driv
{
struct ide_atapi_pc pc;
- if (drive->atapi_flags & IDE_AFLAG_NO_DOORLOCK)
+ if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0)
return 0;
ide_init_pc(&pc);
Index: b/drivers/ide/ide-cd.c
===================================================================
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -1635,7 +1635,7 @@ static int ide_cdrom_probe_capabilities(
return 0;
if ((buf[8 + 6] & 0x01) == 0)
- drive->atapi_flags |= IDE_AFLAG_NO_DOORLOCK;
+ drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
if (buf[8 + 6] & 0x08)
drive->atapi_flags &= ~IDE_AFLAG_NO_EJECT;
if (buf[8 + 3] & 0x01)
Index: b/drivers/ide/ide-cd_ioctl.c
===================================================================
--- a/drivers/ide/ide-cd_ioctl.c
+++ b/drivers/ide/ide-cd_ioctl.c
@@ -136,7 +136,7 @@ int ide_cd_lockdoor(ide_drive_t *drive,
sense = &my_sense;
/* If the drive cannot lock the door, just pretend. */
- if (drive->atapi_flags & IDE_AFLAG_NO_DOORLOCK) {
+ if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0) {
stat = 0;
} else {
unsigned char cmd[BLK_MAX_CDB];
@@ -157,7 +157,7 @@ int ide_cd_lockdoor(ide_drive_t *drive,
(sense->asc == 0x24 || sense->asc == 0x20)) {
printk(KERN_ERR "%s: door locking not supported\n",
drive->name);
- drive->atapi_flags |= IDE_AFLAG_NO_DOORLOCK;
+ drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
stat = 0;
}
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -592,7 +592,7 @@ static void idefloppy_setup(ide_drive_t
blk_queue_max_sectors(drive->queue, 64);
drive->atapi_flags |= IDE_AFLAG_CLIK_DRIVE;
/* IOMEGA Clik! drives do not support lock/unlock commands */
- drive->atapi_flags |= IDE_AFLAG_NO_DOORLOCK;
+ drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
}
(void) ide_floppy_get_capacity(drive);
Index: b/drivers/ide/ide-probe.c
===================================================================
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -208,6 +208,7 @@ static inline void do_identify (ide_driv
drive->ready_stat = 0;
if (ata_id_cdb_intr(id))
drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
+ drive->dev_flags |= IDE_DFLAG_DOORLOCKING;
return;
}
Index: b/drivers/ide/ide-tape.c
===================================================================
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -2107,7 +2107,7 @@ static void idetape_get_mode_sense_resul
/* device lacks locking support according to capabilities page */
if ((caps[6] & 1) == 0)
- drive->atapi_flags |= IDE_AFLAG_NO_DOORLOCK;
+ drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
if (caps[7] & 0x02)
tape->blk_size = 512;
Index: b/include/linux/ide.h
===================================================================
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -462,8 +462,6 @@ struct ide_acpi_hwif_link;
/* ATAPI device flags */
enum {
IDE_AFLAG_DRQ_INTERRUPT = (1 << 0),
- /* Drive cannot lock the door. */
- IDE_AFLAG_NO_DOORLOCK = (1 << 2),
/* ide-cd */
/* Drive cannot eject the disc. */
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 13/18] ide-disk: factor out generic disk handling code to ide-gd.c
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
` (11 preceding siblings ...)
2008-09-07 22:15 ` [PATCH 12/18] ide: remove IDE_AFLAG_NO_DOORLOCKING Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:15 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:16 ` [PATCH 14/18] ide-disk: use IDE_DFLAG_MEDIA_CHANGED Bartlomiej Zolnierkiewicz
` (5 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:15 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
While at it:
- IDEDISK_VERSION -> IDE_GD_VERSION
- ide_cacheflush_p() -> ide_disk_flush()
- init_idedisk_capacity() -> ide_disk_init_capacity()
- idedisk_set_doorlock() -> ide_disk_set_doorlock()
- idedisk_setup() -> ide_disk_setup()
- ide_disk_capacity() -> ide_gd_capacity()
- ide_disk_remove() -> ide_gd_remove()
- ide_disk_probe() -> ide_gd_probe()
- ide_disk_resume() -> ide_gd_resume()
- ide_device_shutdown() -> ide_gd_shutdown()
- idedisk_driver -> ide_gd_driver
- idedisk_open() -> ide_gd_open()
- idedisk_release() -> ide_gd_release()
- idedisk_getgeo() -> ide_gd_getgeo()
- idedisk_media_changed() -> ide_gd_media_changed()
- idedisk_revalidate_disk() -> ide_gd_revalidate_disk()
- idedisk_ops -> ide_gd_ops
- idedisk_init() -> ide_gd_init()
- idedisk_exit() -> ide_gd_exit()
There should be no functional changes caused by this patch.
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/Makefile | 2
drivers/ide/ide-disk.c | 299 +-------------------------------------------
drivers/ide/ide-disk.h | 8 +
drivers/ide/ide-disk_proc.c | 2
drivers/ide/ide-gd.c | 289 ++++++++++++++++++++++++++++++++++++++++++
5 files changed, 307 insertions(+), 293 deletions(-)
Index: b/drivers/ide/Makefile
===================================================================
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -37,7 +37,7 @@ obj-$(CONFIG_IDE_H8300) += h8300/
obj-$(CONFIG_IDE_GENERIC) += ide-generic.o
obj-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o
-ide-disk_mod-y += ide-disk.o ide-disk_ioctl.o
+ide-disk_mod-y += ide-gd.o ide-disk.o ide-disk_ioctl.o
ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o
ide-floppy_mod-y += ide-floppy.o ide-floppy_ioctl.o
Index: b/drivers/ide/ide-disk.c
===================================================================
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -14,9 +14,6 @@
* This is the IDE/ATA disk driver, as evolved from hd.c and ide.c.
*/
-#define IDEDISK_VERSION "1.18"
-
-#include <linux/module.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/kernel.h>
@@ -41,36 +38,6 @@
#include "ide-disk.h"
-static DEFINE_MUTEX(idedisk_ref_mutex);
-
-static void ide_disk_release(struct kref *);
-
-static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
-{
- struct ide_disk_obj *idkp = NULL;
-
- mutex_lock(&idedisk_ref_mutex);
- idkp = ide_drv_g(disk, ide_disk_obj);
- if (idkp) {
- if (ide_device_get(idkp->drive))
- idkp = NULL;
- else
- kref_get(&idkp->kref);
- }
- mutex_unlock(&idedisk_ref_mutex);
- return idkp;
-}
-
-static void ide_disk_put(struct ide_disk_obj *idkp)
-{
- ide_drive_t *drive = idkp->drive;
-
- mutex_lock(&idedisk_ref_mutex);
- kref_put(&idkp->kref, ide_disk_release);
- ide_device_put(drive);
- mutex_unlock(&idedisk_ref_mutex);
-}
-
static const u8 ide_rw_cmds[] = {
ATA_CMD_READ_MULTI,
ATA_CMD_WRITE_MULTI,
@@ -217,8 +184,8 @@ static ide_startstop_t __ide_do_rw_disk(
* 1073741822 == 549756 MB or 48bit addressing fake drive
*/
-static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
- sector_t block)
+ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
+ sector_t block)
{
ide_hwif_t *hwif = HWIF(drive);
@@ -366,7 +333,7 @@ static void idedisk_check_hpa(ide_drive_
}
}
-static void init_idedisk_capacity(ide_drive_t *drive)
+void ide_disk_init_capacity(ide_drive_t *drive)
{
u16 *id = drive->id;
int lba;
@@ -417,11 +384,6 @@ static void init_idedisk_capacity(ide_dr
}
}
-sector_t ide_disk_capacity(ide_drive_t *drive)
-{
- return drive->capacity64;
-}
-
static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
{
ide_drive_t *drive = q->queuedata;
@@ -520,7 +482,7 @@ static void update_ordered(ide_drive_t *
* time we have trimmed the drive capacity if LBA48 is
* not available so we don't need to recheck that.
*/
- capacity = ide_disk_capacity(drive);
+ capacity = ide_gd_capacity(drive);
barrier = ata_id_flush_enabled(id) &&
(drive->dev_flags & IDE_DFLAG_NOFLUSH) == 0 &&
((drive->dev_flags & IDE_DFLAG_LBA48) == 0 ||
@@ -628,7 +590,7 @@ ide_ext_devset_rw(wcache, wcache);
ide_ext_devset_rw_sync(nowerr, nowerr);
-static void idedisk_setup(ide_drive_t *drive)
+void ide_disk_setup(ide_drive_t *drive)
{
struct ide_disk_obj *idkp = drive->driver_data;
ide_hwif_t *hwif = drive->hwif;
@@ -664,13 +626,13 @@ static void idedisk_setup(ide_drive_t *d
drive->queue->max_sectors / 2);
/* calculate drive capacity, and select LBA if possible */
- init_idedisk_capacity(drive);
+ ide_disk_init_capacity(drive);
/*
* if possible, give fdisk access to more of the drive,
* by correcting bios_cyls:
*/
- capacity = ide_disk_capacity(drive);
+ capacity = ide_gd_capacity(drive);
if ((drive->dev_flags & IDE_DFLAG_FORCED_GEOM) == 0) {
if (ata_id_lba48_enabled(drive->id)) {
@@ -720,7 +682,7 @@ static void idedisk_setup(ide_drive_t *d
drive->dev_flags |= IDE_DFLAG_ATTACH;
}
-static void ide_cacheflush_p(ide_drive_t *drive)
+void ide_disk_flush(ide_drive_t *drive)
{
if (ata_id_flush_enabled(drive->id) == 0 ||
(drive->dev_flags & IDE_DFLAG_WCACHE) == 0)
@@ -730,93 +692,7 @@ static void ide_cacheflush_p(ide_drive_t
printk(KERN_INFO "%s: wcache flush failed!\n", drive->name);
}
-static void ide_disk_remove(ide_drive_t *drive)
-{
- struct ide_disk_obj *idkp = drive->driver_data;
- struct gendisk *g = idkp->disk;
-
- ide_proc_unregister_driver(drive, idkp->driver);
-
- del_gendisk(g);
-
- ide_cacheflush_p(drive);
-
- ide_disk_put(idkp);
-}
-
-static void ide_disk_release(struct kref *kref)
-{
- struct ide_disk_obj *idkp = to_ide_drv(kref, ide_disk_obj);
- ide_drive_t *drive = idkp->drive;
- struct gendisk *g = idkp->disk;
-
- drive->driver_data = NULL;
- g->private_data = NULL;
- put_disk(g);
- kfree(idkp);
-}
-
-static int ide_disk_probe(ide_drive_t *drive);
-
-/*
- * On HPA drives the capacity needs to be
- * reinitilized on resume otherwise the disk
- * can not be used and a hard reset is required
- */
-static void ide_disk_resume(ide_drive_t *drive)
-{
- if (ata_id_hpa_enabled(drive->id))
- init_idedisk_capacity(drive);
-}
-
-static void ide_device_shutdown(ide_drive_t *drive)
-{
-#ifdef CONFIG_ALPHA
- /* On Alpha, halt(8) doesn't actually turn the machine off,
- it puts you into the sort of firmware monitor. Typically,
- it's used to boot another kernel image, so it's not much
- different from reboot(8). Therefore, we don't need to
- spin down the disk in this case, especially since Alpha
- firmware doesn't handle disks in standby mode properly.
- On the other hand, it's reasonably safe to turn the power
- off when the shutdown process reaches the firmware prompt,
- as the firmware initialization takes rather long time -
- at least 10 seconds, which should be sufficient for
- the disk to expire its write cache. */
- if (system_state != SYSTEM_POWER_OFF) {
-#else
- if (system_state == SYSTEM_RESTART) {
-#endif
- ide_cacheflush_p(drive);
- return;
- }
-
- printk(KERN_INFO "Shutdown: %s\n", drive->name);
-
- drive->gendev.bus->suspend(&drive->gendev, PMSG_SUSPEND);
-}
-
-static ide_driver_t idedisk_driver = {
- .gen_driver = {
- .owner = THIS_MODULE,
- .name = "ide-disk",
- .bus = &ide_bus_type,
- },
- .probe = ide_disk_probe,
- .remove = ide_disk_remove,
- .resume = ide_disk_resume,
- .shutdown = ide_device_shutdown,
- .version = IDEDISK_VERSION,
- .do_request = ide_do_rw_disk,
- .end_request = ide_end_request,
- .error = __ide_error,
-#ifdef CONFIG_IDE_PROC_FS
- .proc = ide_disk_proc,
- .settings = ide_disk_settings,
-#endif
-};
-
-static int idedisk_set_doorlock(ide_drive_t *drive, int on)
+int ide_disk_set_doorlock(ide_drive_t *drive, int on)
{
ide_task_t task;
int ret;
@@ -835,160 +711,3 @@ static int idedisk_set_doorlock(ide_driv
return ret;
}
-
-static int idedisk_open(struct inode *inode, struct file *filp)
-{
- struct gendisk *disk = inode->i_bdev->bd_disk;
- struct ide_disk_obj *idkp;
- ide_drive_t *drive;
-
- idkp = ide_disk_get(disk);
- if (idkp == NULL)
- return -ENXIO;
-
- drive = idkp->drive;
-
- idkp->openers++;
-
- if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
- /*
- * Ignore the return code from door_lock,
- * since the open() has already succeeded,
- * and the door_lock is irrelevant at this point.
- */
- idedisk_set_doorlock(drive, 1);
- check_disk_change(inode->i_bdev);
- }
- return 0;
-}
-
-static int idedisk_release(struct inode *inode, struct file *filp)
-{
- struct gendisk *disk = inode->i_bdev->bd_disk;
- struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
- ide_drive_t *drive = idkp->drive;
-
- if (idkp->openers == 1)
- ide_cacheflush_p(drive);
-
- if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1)
- idedisk_set_doorlock(drive, 0);
-
- idkp->openers--;
-
- ide_disk_put(idkp);
-
- return 0;
-}
-
-static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
-{
- struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
- ide_drive_t *drive = idkp->drive;
-
- geo->heads = drive->bios_head;
- geo->sectors = drive->bios_sect;
- geo->cylinders = (u16)drive->bios_cyl; /* truncate */
- return 0;
-}
-
-static int idedisk_media_changed(struct gendisk *disk)
-{
- struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
- ide_drive_t *drive = idkp->drive;
-
- /* do not scan partitions twice if this is a removable device */
- if (drive->dev_flags & IDE_DFLAG_ATTACH) {
- drive->dev_flags &= ~IDE_DFLAG_ATTACH;
- return 0;
- }
-
- /* if removable, always assume it was changed */
- return !!(drive->dev_flags & IDE_DFLAG_REMOVABLE);
-}
-
-static int idedisk_revalidate_disk(struct gendisk *disk)
-{
- struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
- set_capacity(disk, ide_disk_capacity(idkp->drive));
- return 0;
-}
-
-static struct block_device_operations idedisk_ops = {
- .owner = THIS_MODULE,
- .open = idedisk_open,
- .release = idedisk_release,
- .ioctl = ide_disk_ioctl,
- .getgeo = idedisk_getgeo,
- .media_changed = idedisk_media_changed,
- .revalidate_disk = idedisk_revalidate_disk
-};
-
-MODULE_DESCRIPTION("ATA DISK Driver");
-
-static int ide_disk_probe(ide_drive_t *drive)
-{
- struct ide_disk_obj *idkp;
- struct gendisk *g;
-
- /* strstr("foo", "") is non-NULL */
- if (!strstr("ide-disk", drive->driver_req))
- goto failed;
-
- if (drive->media != ide_disk)
- goto failed;
-
- idkp = kzalloc(sizeof(*idkp), GFP_KERNEL);
- if (!idkp)
- goto failed;
-
- g = alloc_disk_node(1 << PARTN_BITS,
- hwif_to_node(drive->hwif));
- if (!g)
- goto out_free_idkp;
-
- ide_init_disk(g, drive);
-
- kref_init(&idkp->kref);
-
- idkp->drive = drive;
- idkp->driver = &idedisk_driver;
- idkp->disk = g;
-
- g->private_data = &idkp->driver;
-
- drive->driver_data = idkp;
-
- idedisk_setup(drive);
-
- set_capacity(g, ide_disk_capacity(drive));
-
- g->minors = 1 << PARTN_BITS;
- g->driverfs_dev = &drive->gendev;
- if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
- g->flags = GENHD_FL_REMOVABLE;
- g->fops = &idedisk_ops;
- add_disk(g);
- return 0;
-
-out_free_idkp:
- kfree(idkp);
-failed:
- return -ENODEV;
-}
-
-static void __exit idedisk_exit(void)
-{
- driver_unregister(&idedisk_driver.gen_driver);
-}
-
-static int __init idedisk_init(void)
-{
- return driver_register(&idedisk_driver.gen_driver);
-}
-
-MODULE_ALIAS("ide:*m-disk*");
-MODULE_ALIAS("ide-disk");
-module_init(idedisk_init);
-module_exit(idedisk_exit);
-MODULE_LICENSE("GPL");
Index: b/drivers/ide/ide-disk.h
===================================================================
--- a/drivers/ide/ide-disk.h
+++ b/drivers/ide/ide-disk.h
@@ -9,8 +9,14 @@ struct ide_disk_obj {
unsigned int openers; /* protected by BKL for now */
};
+sector_t ide_gd_capacity(ide_drive_t *);
+
/* ide-disk.c */
-sector_t ide_disk_capacity(ide_drive_t *);
+void ide_disk_init_capacity(ide_drive_t *);
+void ide_disk_setup(ide_drive_t *);
+void ide_disk_flush(ide_drive_t *);
+int ide_disk_set_doorlock(ide_drive_t *, int);
+ide_startstop_t ide_do_rw_disk(ide_drive_t *, struct request *, sector_t);
ide_decl_devset(address);
ide_decl_devset(multcount);
ide_decl_devset(nowerr);
Index: b/drivers/ide/ide-disk_proc.c
===================================================================
--- a/drivers/ide/ide-disk_proc.c
+++ b/drivers/ide/ide-disk_proc.c
@@ -56,7 +56,7 @@ static int proc_idedisk_read_capacity
ide_drive_t*drive = (ide_drive_t *)data;
int len;
- len = sprintf(page, "%llu\n", (long long)ide_disk_capacity(drive));
+ len = sprintf(page, "%llu\n", (long long)ide_gd_capacity(drive));
PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
}
Index: b/drivers/ide/ide-gd.c
===================================================================
--- /dev/null
+++ b/drivers/ide/ide-gd.c
@@ -0,0 +1,289 @@
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/string.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/genhd.h>
+#include <linux/mutex.h>
+#include <linux/ide.h>
+#include <linux/hdreg.h>
+
+#include "ide-disk.h"
+
+#define IDE_GD_VERSION "1.18"
+
+static DEFINE_MUTEX(ide_disk_ref_mutex);
+
+static void ide_disk_release(struct kref *);
+
+static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
+{
+ struct ide_disk_obj *idkp = NULL;
+
+ mutex_lock(&ide_disk_ref_mutex);
+ idkp = ide_drv_g(disk, ide_disk_obj);
+ if (idkp) {
+ if (ide_device_get(idkp->drive))
+ idkp = NULL;
+ else
+ kref_get(&idkp->kref);
+ }
+ mutex_unlock(&ide_disk_ref_mutex);
+ return idkp;
+}
+
+static void ide_disk_put(struct ide_disk_obj *idkp)
+{
+ ide_drive_t *drive = idkp->drive;
+
+ mutex_lock(&ide_disk_ref_mutex);
+ kref_put(&idkp->kref, ide_disk_release);
+ ide_device_put(drive);
+ mutex_unlock(&ide_disk_ref_mutex);
+}
+
+sector_t ide_gd_capacity(ide_drive_t *drive)
+{
+ return drive->capacity64;
+}
+
+static int ide_gd_probe(ide_drive_t *);
+
+static void ide_gd_remove(ide_drive_t *drive)
+{
+ struct ide_disk_obj *idkp = drive->driver_data;
+ struct gendisk *g = idkp->disk;
+
+ ide_proc_unregister_driver(drive, idkp->driver);
+
+ del_gendisk(g);
+
+ ide_disk_flush(drive);
+
+ ide_disk_put(idkp);
+}
+
+static void ide_disk_release(struct kref *kref)
+{
+ struct ide_disk_obj *idkp = to_ide_drv(kref, ide_disk_obj);
+ ide_drive_t *drive = idkp->drive;
+ struct gendisk *g = idkp->disk;
+
+ drive->driver_data = NULL;
+ g->private_data = NULL;
+ put_disk(g);
+ kfree(idkp);
+}
+
+/*
+ * On HPA drives the capacity needs to be
+ * reinitilized on resume otherwise the disk
+ * can not be used and a hard reset is required
+ */
+static void ide_gd_resume(ide_drive_t *drive)
+{
+ if (ata_id_hpa_enabled(drive->id))
+ ide_disk_init_capacity(drive);
+}
+
+static void ide_gd_shutdown(ide_drive_t *drive)
+{
+#ifdef CONFIG_ALPHA
+ /* On Alpha, halt(8) doesn't actually turn the machine off,
+ it puts you into the sort of firmware monitor. Typically,
+ it's used to boot another kernel image, so it's not much
+ different from reboot(8). Therefore, we don't need to
+ spin down the disk in this case, especially since Alpha
+ firmware doesn't handle disks in standby mode properly.
+ On the other hand, it's reasonably safe to turn the power
+ off when the shutdown process reaches the firmware prompt,
+ as the firmware initialization takes rather long time -
+ at least 10 seconds, which should be sufficient for
+ the disk to expire its write cache. */
+ if (system_state != SYSTEM_POWER_OFF) {
+#else
+ if (system_state == SYSTEM_RESTART) {
+#endif
+ ide_disk_flush(drive);
+ return;
+ }
+
+ printk(KERN_INFO "Shutdown: %s\n", drive->name);
+
+ drive->gendev.bus->suspend(&drive->gendev, PMSG_SUSPEND);
+}
+
+static ide_driver_t ide_gd_driver = {
+ .gen_driver = {
+ .owner = THIS_MODULE,
+ .name = "ide-disk",
+ .bus = &ide_bus_type,
+ },
+ .probe = ide_gd_probe,
+ .remove = ide_gd_remove,
+ .resume = ide_gd_resume,
+ .shutdown = ide_gd_shutdown,
+ .version = IDE_GD_VERSION,
+ .do_request = ide_do_rw_disk,
+ .end_request = ide_end_request,
+ .error = __ide_error,
+#ifdef CONFIG_IDE_PROC_FS
+ .proc = ide_disk_proc,
+ .settings = ide_disk_settings,
+#endif
+};
+
+static int ide_gd_open(struct inode *inode, struct file *filp)
+{
+ struct gendisk *disk = inode->i_bdev->bd_disk;
+ struct ide_disk_obj *idkp;
+ ide_drive_t *drive;
+
+ idkp = ide_disk_get(disk);
+ if (idkp == NULL)
+ return -ENXIO;
+
+ drive = idkp->drive;
+
+ idkp->openers++;
+
+ if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
+ /*
+ * Ignore the return code from door_lock,
+ * since the open() has already succeeded,
+ * and the door_lock is irrelevant at this point.
+ */
+ ide_disk_set_doorlock(drive, 1);
+ check_disk_change(inode->i_bdev);
+ }
+ return 0;
+}
+
+static int ide_gd_release(struct inode *inode, struct file *filp)
+{
+ struct gendisk *disk = inode->i_bdev->bd_disk;
+ struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
+ ide_drive_t *drive = idkp->drive;
+
+ if (idkp->openers == 1)
+ ide_disk_flush(drive);
+
+ if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1)
+ ide_disk_set_doorlock(drive, 0);
+
+ idkp->openers--;
+
+ ide_disk_put(idkp);
+
+ return 0;
+}
+
+static int ide_gd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+{
+ struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
+ ide_drive_t *drive = idkp->drive;
+
+ geo->heads = drive->bios_head;
+ geo->sectors = drive->bios_sect;
+ geo->cylinders = (u16)drive->bios_cyl; /* truncate */
+ return 0;
+}
+
+static int ide_gd_media_changed(struct gendisk *disk)
+{
+ struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
+ ide_drive_t *drive = idkp->drive;
+
+ /* do not scan partitions twice if this is a removable device */
+ if (drive->dev_flags & IDE_DFLAG_ATTACH) {
+ drive->dev_flags &= ~IDE_DFLAG_ATTACH;
+ return 0;
+ }
+
+ /* if removable, always assume it was changed */
+ return !!(drive->dev_flags & IDE_DFLAG_REMOVABLE);
+}
+
+static int ide_gd_revalidate_disk(struct gendisk *disk)
+{
+ struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
+ set_capacity(disk, ide_gd_capacity(idkp->drive));
+ return 0;
+}
+
+static struct block_device_operations ide_gd_ops = {
+ .owner = THIS_MODULE,
+ .open = ide_gd_open,
+ .release = ide_gd_release,
+ .ioctl = ide_disk_ioctl,
+ .getgeo = ide_gd_getgeo,
+ .media_changed = ide_gd_media_changed,
+ .revalidate_disk = ide_gd_revalidate_disk
+};
+
+static int ide_gd_probe(ide_drive_t *drive)
+{
+ struct ide_disk_obj *idkp;
+ struct gendisk *g;
+
+ /* strstr("foo", "") is non-NULL */
+ if (!strstr("ide-disk", drive->driver_req))
+ goto failed;
+
+ if (drive->media != ide_disk)
+ goto failed;
+
+ idkp = kzalloc(sizeof(*idkp), GFP_KERNEL);
+ if (!idkp)
+ goto failed;
+
+ g = alloc_disk_node(1 << PARTN_BITS, hwif_to_node(drive->hwif));
+ if (!g)
+ goto out_free_idkp;
+
+ ide_init_disk(g, drive);
+
+ kref_init(&idkp->kref);
+
+ idkp->drive = drive;
+ idkp->driver = &ide_gd_driver;
+ idkp->disk = g;
+
+ g->private_data = &idkp->driver;
+
+ drive->driver_data = idkp;
+
+ ide_disk_setup(drive);
+
+ set_capacity(g, ide_gd_capacity(drive));
+
+ g->minors = 1 << PARTN_BITS;
+ g->driverfs_dev = &drive->gendev;
+ if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
+ g->flags = GENHD_FL_REMOVABLE;
+ g->fops = &ide_gd_ops;
+ add_disk(g);
+ return 0;
+
+out_free_idkp:
+ kfree(idkp);
+failed:
+ return -ENODEV;
+}
+
+static int __init ide_gd_init(void)
+{
+ return driver_register(&ide_gd_driver.gen_driver);
+}
+
+static void __exit ide_gd_exit(void)
+{
+ driver_unregister(&ide_gd_driver.gen_driver);
+}
+
+MODULE_ALIAS("ide:*m-disk*");
+MODULE_ALIAS("ide-disk");
+module_init(ide_gd_init);
+module_exit(ide_gd_exit);
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("ATA DISK Driver");
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 14/18] ide-disk: use IDE_DFLAG_MEDIA_CHANGED
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
` (12 preceding siblings ...)
2008-09-07 22:15 ` [PATCH 13/18] ide-disk: factor out generic disk handling code to ide-gd.c Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:16 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:16 ` [PATCH 15/18] ide-floppy: factor out generic disk handling code to ide-gd-floppy.c Bartlomiej Zolnierkiewicz
` (4 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:16 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
Set IDE_DFLAG_MEDIA_CHANGED in ide_gd_open() to signalize
ide_gd_media_changed() that that media has changed (instead
of relying on IDE_DFLAG_REMOVABLE).
There should be no functional changes caused by this patch.
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/ide-gd.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
Index: b/drivers/ide/ide-gd.c
===================================================================
--- a/drivers/ide/ide-gd.c
+++ b/drivers/ide/ide-gd.c
@@ -154,6 +154,7 @@ static int ide_gd_open(struct inode *ino
* and the door_lock is irrelevant at this point.
*/
ide_disk_set_doorlock(drive, 1);
+ drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
check_disk_change(inode->i_bdev);
}
return 0;
@@ -193,6 +194,7 @@ static int ide_gd_media_changed(struct g
{
struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
ide_drive_t *drive = idkp->drive;
+ int ret;
/* do not scan partitions twice if this is a removable device */
if (drive->dev_flags & IDE_DFLAG_ATTACH) {
@@ -200,8 +202,10 @@ static int ide_gd_media_changed(struct g
return 0;
}
- /* if removable, always assume it was changed */
- return !!(drive->dev_flags & IDE_DFLAG_REMOVABLE);
+ ret = !!(drive->dev_flags & IDE_DFLAG_MEDIA_CHANGED);
+ drive->dev_flags &= ~IDE_DFLAG_MEDIA_CHANGED;
+
+ return ret;
}
static int ide_gd_revalidate_disk(struct gendisk *disk)
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 15/18] ide-floppy: factor out generic disk handling code to ide-gd-floppy.c
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
` (13 preceding siblings ...)
2008-09-07 22:16 ` [PATCH 14/18] ide-disk: use IDE_DFLAG_MEDIA_CHANGED Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:16 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:16 ` [PATCH 16/18] ide: prepare for merging ide-gd-floppy.c with ide-gd.c Bartlomiej Zolnierkiewicz
` (3 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:16 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
While at it:
- idefloppy_do_request() -> ide_floppy_do_request()
- idefloppy_end_request() -> ide_floppy_end_request()
- idefloppy_setup() -> ide_floppy_setup()
There should be no functional changes caused by this patch.
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/Makefile | 2
drivers/ide/ide-floppy.c | 319 +-------------------------------------------
drivers/ide/ide-floppy.h | 19 ++
drivers/ide/ide-gd-floppy.c | 298 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 327 insertions(+), 311 deletions(-)
Index: b/drivers/ide/Makefile
===================================================================
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -39,7 +39,7 @@ obj-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp
ide-disk_mod-y += ide-gd.o ide-disk.o ide-disk_ioctl.o
ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o
-ide-floppy_mod-y += ide-floppy.o ide-floppy_ioctl.o
+ide-floppy_mod-y += ide-gd-floppy.o ide-floppy.o ide-floppy_ioctl.o
ifeq ($(CONFIG_IDE_PROC_FS), y)
ide-disk_mod-y += ide-disk_proc.o
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -15,12 +15,6 @@
* Documentation/ide/ChangeLog.ide-floppy.1996-2002
*/
-#define DRV_NAME "ide-floppy"
-#define PFX DRV_NAME ": "
-
-#define IDEFLOPPY_VERSION "1.00"
-
-#include <linux/module.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/kernel.h>
@@ -49,19 +43,6 @@
#include "ide-floppy.h"
-/* module parameters */
-static unsigned long debug_mask;
-module_param(debug_mask, ulong, 0644);
-
-/* define to see debug info */
-#define IDEFLOPPY_DEBUG_LOG 0
-
-#if IDEFLOPPY_DEBUG_LOG
-#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, args)
-#else
-#define ide_debug_log(lvl, fmt, args...) do {} while (0)
-#endif
-
/*
* After each failed packet command we issue a request sense command and retry
* the packet command IDEFLOPPY_MAX_PC_RETRIES times.
@@ -83,41 +64,11 @@ module_param(debug_mask, ulong, 0644);
/* Error code returned in rq->errors to the higher part of the driver. */
#define IDEFLOPPY_ERROR_GENERAL 101
-static DEFINE_MUTEX(idefloppy_ref_mutex);
-
-static void idefloppy_cleanup_obj(struct kref *);
-
-static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
-{
- struct ide_floppy_obj *floppy = NULL;
-
- mutex_lock(&idefloppy_ref_mutex);
- floppy = ide_drv_g(disk, ide_floppy_obj);
- if (floppy) {
- if (ide_device_get(floppy->drive))
- floppy = NULL;
- else
- kref_get(&floppy->kref);
- }
- mutex_unlock(&idefloppy_ref_mutex);
- return floppy;
-}
-
-static void ide_floppy_put(struct ide_floppy_obj *floppy)
-{
- ide_drive_t *drive = floppy->drive;
-
- mutex_lock(&idefloppy_ref_mutex);
- kref_put(&floppy->kref, idefloppy_cleanup_obj);
- ide_device_put(drive);
- mutex_unlock(&idefloppy_ref_mutex);
-}
-
/*
* Used to finish servicing a request. For read/write requests, we will call
* ide_end_request to pass to the next buffer.
*/
-static int idefloppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
+int ide_floppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
{
idefloppy_floppy_t *floppy = drive->driver_data;
struct request *rq = HWGROUP(drive)->rq;
@@ -161,7 +112,7 @@ static void idefloppy_update_buffers(ide
struct bio *bio = rq->bio;
while ((bio = rq->bio) != NULL)
- idefloppy_end_request(drive, 1, 0);
+ ide_floppy_end_request(drive, 1, 0);
}
static void ide_floppy_callback(ide_drive_t *drive, int dsc)
@@ -200,7 +151,7 @@ static void ide_floppy_callback(ide_driv
"Aborting request!\n");
}
- idefloppy_end_request(drive, uptodate, 0);
+ ide_floppy_end_request(drive, uptodate, 0);
}
static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
@@ -329,8 +280,8 @@ static void idefloppy_blockpc_cmd(ideflo
pc->req_xfer = pc->buf_size = rq->data_len;
}
-static ide_startstop_t idefloppy_do_request(ide_drive_t *drive,
- struct request *rq, sector_t block_s)
+ide_startstop_t ide_floppy_do_request(ide_drive_t *drive, struct request *rq,
+ sector_t block_s)
{
idefloppy_floppy_t *floppy = drive->driver_data;
ide_hwif_t *hwif = drive->hwif;
@@ -353,7 +304,7 @@ static ide_startstop_t idefloppy_do_requ
else
printk(KERN_ERR PFX "%s: I/O error\n", drive->name);
- idefloppy_end_request(drive, 0, 0);
+ ide_floppy_end_request(drive, 0, 0);
return ide_stopped;
}
if (blk_fs_request(rq)) {
@@ -361,7 +312,7 @@ static ide_startstop_t idefloppy_do_requ
(rq->nr_sectors % floppy->bs_factor)) {
printk(KERN_ERR PFX "%s: unsupported r/w rq size\n",
drive->name);
- idefloppy_end_request(drive, 0, 0);
+ ide_floppy_end_request(drive, 0, 0);
return ide_stopped;
}
pc = &floppy->queued_pc;
@@ -373,7 +324,7 @@ static ide_startstop_t idefloppy_do_requ
idefloppy_blockpc_cmd(floppy, pc, rq);
} else {
blk_dump_rq_flags(rq, PFX "unsupported command in queue");
- idefloppy_end_request(drive, 0, 0);
+ ide_floppy_end_request(drive, 0, 0);
return ide_stopped;
}
@@ -455,7 +406,7 @@ static int ide_floppy_get_flexible_disk_
* Determine if a media is present in the floppy drive, and if so, its LBA
* capacity.
*/
-static int ide_floppy_get_capacity(ide_drive_t *drive)
+int ide_floppy_get_capacity(ide_drive_t *drive)
{
idefloppy_floppy_t *floppy = drive->driver_data;
struct gendisk *disk = floppy->disk;
@@ -554,12 +505,7 @@ static int ide_floppy_get_capacity(ide_d
return rc;
}
-sector_t ide_floppy_capacity(ide_drive_t *drive)
-{
- return drive->capacity64;
-}
-
-static void idefloppy_setup(ide_drive_t *drive)
+void ide_floppy_setup(ide_drive_t *drive)
{
struct ide_floppy_obj *floppy = drive->driver_data;
u16 *id = drive->id;
@@ -601,248 +547,3 @@ static void idefloppy_setup(ide_drive_t
drive->dev_flags |= IDE_DFLAG_ATTACH;
}
-
-static void ide_floppy_remove(ide_drive_t *drive)
-{
- idefloppy_floppy_t *floppy = drive->driver_data;
- struct gendisk *g = floppy->disk;
-
- ide_proc_unregister_driver(drive, floppy->driver);
-
- del_gendisk(g);
-
- ide_floppy_put(floppy);
-}
-
-static void idefloppy_cleanup_obj(struct kref *kref)
-{
- struct ide_floppy_obj *floppy = to_ide_drv(kref, ide_floppy_obj);
- ide_drive_t *drive = floppy->drive;
- struct gendisk *g = floppy->disk;
-
- drive->driver_data = NULL;
- g->private_data = NULL;
- put_disk(g);
- kfree(floppy);
-}
-
-static int ide_floppy_probe(ide_drive_t *);
-
-static ide_driver_t idefloppy_driver = {
- .gen_driver = {
- .owner = THIS_MODULE,
- .name = "ide-floppy",
- .bus = &ide_bus_type,
- },
- .probe = ide_floppy_probe,
- .remove = ide_floppy_remove,
- .version = IDEFLOPPY_VERSION,
- .do_request = idefloppy_do_request,
- .end_request = idefloppy_end_request,
- .error = __ide_error,
-#ifdef CONFIG_IDE_PROC_FS
- .proc = ide_floppy_proc,
- .settings = ide_floppy_settings,
-#endif
-};
-
-static int idefloppy_open(struct inode *inode, struct file *filp)
-{
- struct gendisk *disk = inode->i_bdev->bd_disk;
- struct ide_floppy_obj *floppy;
- ide_drive_t *drive;
- int ret = 0;
-
- floppy = ide_floppy_get(disk);
- if (!floppy)
- return -ENXIO;
-
- drive = floppy->drive;
-
- ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
-
- floppy->openers++;
-
- if (floppy->openers == 1) {
- drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
- /* Just in case */
-
- if (ide_do_test_unit_ready(drive, disk))
- ide_do_start_stop(drive, disk, 1);
-
- ret = ide_floppy_get_capacity(drive);
-
- set_capacity(disk, ide_floppy_capacity(drive));
-
- if (ret && (filp->f_flags & O_NDELAY) == 0) {
- /*
- * Allow O_NDELAY to open a drive without a disk, or with an
- * unreadable disk, so that we can get the format capacity
- * of the drive or begin the format - Sam
- */
- ret = -EIO;
- goto out_put_floppy;
- }
-
- if ((drive->dev_flags & IDE_DFLAG_WP) && (filp->f_mode & 2)) {
- ret = -EROFS;
- goto out_put_floppy;
- }
-
- ide_set_media_lock(drive, disk, 1);
- drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
- check_disk_change(inode->i_bdev);
- } else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) {
- ret = -EBUSY;
- goto out_put_floppy;
- }
- return 0;
-
-out_put_floppy:
- floppy->openers--;
- ide_floppy_put(floppy);
- return ret;
-}
-
-static int idefloppy_release(struct inode *inode, struct file *filp)
-{
- struct gendisk *disk = inode->i_bdev->bd_disk;
- struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
- ide_drive_t *drive = floppy->drive;
-
- ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
-
- if (floppy->openers == 1) {
- ide_set_media_lock(drive, disk, 0);
- drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
- }
-
- floppy->openers--;
-
- ide_floppy_put(floppy);
-
- return 0;
-}
-
-static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
-{
- struct ide_floppy_obj *floppy = ide_drv_g(bdev->bd_disk,
- ide_floppy_obj);
- ide_drive_t *drive = floppy->drive;
-
- geo->heads = drive->bios_head;
- geo->sectors = drive->bios_sect;
- geo->cylinders = (u16)drive->bios_cyl; /* truncate */
- return 0;
-}
-
-static int idefloppy_media_changed(struct gendisk *disk)
-{
- struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
- ide_drive_t *drive = floppy->drive;
- int ret;
-
- /* do not scan partitions twice if this is a removable device */
- if (drive->dev_flags & IDE_DFLAG_ATTACH) {
- drive->dev_flags &= ~IDE_DFLAG_ATTACH;
- return 0;
- }
- ret = !!(drive->dev_flags & IDE_DFLAG_MEDIA_CHANGED);
- drive->dev_flags &= ~IDE_DFLAG_MEDIA_CHANGED;
- return ret;
-}
-
-static int idefloppy_revalidate_disk(struct gendisk *disk)
-{
- struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
- set_capacity(disk, ide_floppy_capacity(floppy->drive));
- return 0;
-}
-
-static struct block_device_operations idefloppy_ops = {
- .owner = THIS_MODULE,
- .open = idefloppy_open,
- .release = idefloppy_release,
- .ioctl = ide_floppy_ioctl,
- .getgeo = idefloppy_getgeo,
- .media_changed = idefloppy_media_changed,
- .revalidate_disk = idefloppy_revalidate_disk
-};
-
-static int ide_floppy_probe(ide_drive_t *drive)
-{
- idefloppy_floppy_t *floppy;
- struct gendisk *g;
-
- if (!strstr("ide-floppy", drive->driver_req))
- goto failed;
-
- if (drive->media != ide_floppy)
- goto failed;
-
- if (!ide_check_atapi_device(drive, DRV_NAME)) {
- printk(KERN_ERR PFX "%s: not supported by this version of "
- DRV_NAME "\n", drive->name);
- goto failed;
- }
- floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL);
- if (!floppy) {
- printk(KERN_ERR PFX "%s: Can't allocate a floppy structure\n",
- drive->name);
- goto failed;
- }
-
- g = alloc_disk_node(1 << PARTN_BITS, hwif_to_node(drive->hwif));
- if (!g)
- goto out_free_floppy;
-
- ide_init_disk(g, drive);
-
- kref_init(&floppy->kref);
-
- floppy->drive = drive;
- floppy->driver = &idefloppy_driver;
- floppy->disk = g;
-
- g->private_data = &floppy->driver;
-
- drive->driver_data = floppy;
-
- drive->debug_mask = debug_mask;
-
- idefloppy_setup(drive);
-
- set_capacity(g, ide_floppy_capacity(drive));
-
- g->minors = 1 << PARTN_BITS;
- g->driverfs_dev = &drive->gendev;
- if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
- g->flags = GENHD_FL_REMOVABLE;
- g->fops = &idefloppy_ops;
- add_disk(g);
- return 0;
-
-out_free_floppy:
- kfree(floppy);
-failed:
- return -ENODEV;
-}
-
-static void __exit idefloppy_exit(void)
-{
- driver_unregister(&idefloppy_driver.gen_driver);
-}
-
-static int __init idefloppy_init(void)
-{
- printk(KERN_INFO DRV_NAME " driver " IDEFLOPPY_VERSION "\n");
- return driver_register(&idefloppy_driver.gen_driver);
-}
-
-MODULE_ALIAS("ide:*m-floppy*");
-MODULE_ALIAS("ide-floppy");
-module_init(idefloppy_init);
-module_exit(idefloppy_exit);
-MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
-
Index: b/drivers/ide/ide-floppy.h
===================================================================
--- a/drivers/ide/ide-floppy.h
+++ b/drivers/ide/ide-floppy.h
@@ -1,6 +1,18 @@
#ifndef __IDE_FLOPPY_H
#define __IDE_FLOPPY_H
+#define DRV_NAME "ide-floppy"
+#define PFX DRV_NAME ": "
+
+/* define to see debug info */
+#define IDEFLOPPY_DEBUG_LOG 0
+
+#if IDEFLOPPY_DEBUG_LOG
+#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, args)
+#else
+#define ide_debug_log(lvl, fmt, args...) do {} while (0)
+#endif
+
/*
* Most of our global data which we need to save even as we leave the driver
* due to an interrupt or a timer event is stored in a variable of type
@@ -45,10 +57,15 @@ typedef struct ide_floppy_obj {
#define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
#define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
+sector_t ide_floppy_capacity(ide_drive_t *);
+
/* ide-floppy.c */
void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *, u8);
void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *);
-sector_t ide_floppy_capacity(ide_drive_t *);
+int ide_floppy_get_capacity(ide_drive_t *);
+void ide_floppy_setup(ide_drive_t *);
+ide_startstop_t ide_floppy_do_request(ide_drive_t *, struct request *, sector_t);
+int ide_floppy_end_request(ide_drive_t *, int, int);
/* ide-floppy_ioctl.c */
int ide_floppy_ioctl(struct inode *, struct file *, unsigned, unsigned long);
Index: b/drivers/ide/ide-gd-floppy.c
===================================================================
--- /dev/null
+++ b/drivers/ide/ide-gd-floppy.c
@@ -0,0 +1,298 @@
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/string.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/genhd.h>
+#include <linux/mutex.h>
+#include <linux/ide.h>
+#include <linux/hdreg.h>
+
+#include "ide-floppy.h"
+
+#define IDEFLOPPY_VERSION "1.00"
+
+/* module parameters */
+static unsigned long debug_mask;
+module_param(debug_mask, ulong, 0644);
+
+static DEFINE_MUTEX(idefloppy_ref_mutex);
+
+static void idefloppy_cleanup_obj(struct kref *);
+
+static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
+{
+ struct ide_floppy_obj *floppy = NULL;
+
+ mutex_lock(&idefloppy_ref_mutex);
+ floppy = ide_drv_g(disk, ide_floppy_obj);
+ if (floppy) {
+ if (ide_device_get(floppy->drive))
+ floppy = NULL;
+ else
+ kref_get(&floppy->kref);
+ }
+ mutex_unlock(&idefloppy_ref_mutex);
+ return floppy;
+}
+
+static void ide_floppy_put(struct ide_floppy_obj *floppy)
+{
+ ide_drive_t *drive = floppy->drive;
+
+ mutex_lock(&idefloppy_ref_mutex);
+ kref_put(&floppy->kref, idefloppy_cleanup_obj);
+ ide_device_put(drive);
+ mutex_unlock(&idefloppy_ref_mutex);
+}
+
+sector_t ide_floppy_capacity(ide_drive_t *drive)
+{
+ return drive->capacity64;
+}
+
+static void ide_floppy_remove(ide_drive_t *drive)
+{
+ idefloppy_floppy_t *floppy = drive->driver_data;
+ struct gendisk *g = floppy->disk;
+
+ ide_proc_unregister_driver(drive, floppy->driver);
+
+ del_gendisk(g);
+
+ ide_floppy_put(floppy);
+}
+
+static void idefloppy_cleanup_obj(struct kref *kref)
+{
+ struct ide_floppy_obj *floppy = to_ide_drv(kref, ide_floppy_obj);
+ ide_drive_t *drive = floppy->drive;
+ struct gendisk *g = floppy->disk;
+
+ drive->driver_data = NULL;
+ g->private_data = NULL;
+ put_disk(g);
+ kfree(floppy);
+}
+
+static int ide_floppy_probe(ide_drive_t *);
+
+static ide_driver_t idefloppy_driver = {
+ .gen_driver = {
+ .owner = THIS_MODULE,
+ .name = "ide-floppy",
+ .bus = &ide_bus_type,
+ },
+ .probe = ide_floppy_probe,
+ .remove = ide_floppy_remove,
+ .version = IDEFLOPPY_VERSION,
+ .do_request = ide_floppy_do_request,
+ .end_request = ide_floppy_end_request,
+ .error = __ide_error,
+#ifdef CONFIG_IDE_PROC_FS
+ .proc = ide_floppy_proc,
+ .settings = ide_floppy_settings,
+#endif
+};
+
+static int idefloppy_open(struct inode *inode, struct file *filp)
+{
+ struct gendisk *disk = inode->i_bdev->bd_disk;
+ struct ide_floppy_obj *floppy;
+ ide_drive_t *drive;
+ int ret = 0;
+
+ floppy = ide_floppy_get(disk);
+ if (!floppy)
+ return -ENXIO;
+
+ drive = floppy->drive;
+
+ ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
+ floppy->openers++;
+
+ if (floppy->openers == 1) {
+ drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
+ /* Just in case */
+
+ if (ide_do_test_unit_ready(drive, disk))
+ ide_do_start_stop(drive, disk, 1);
+
+ ret = ide_floppy_get_capacity(drive);
+
+ set_capacity(disk, ide_floppy_capacity(drive));
+
+ if (ret && (filp->f_flags & O_NDELAY) == 0) {
+ /*
+ * Allow O_NDELAY to open a drive without a disk, or with an
+ * unreadable disk, so that we can get the format capacity
+ * of the drive or begin the format - Sam
+ */
+ ret = -EIO;
+ goto out_put_floppy;
+ }
+
+ if ((drive->dev_flags & IDE_DFLAG_WP) && (filp->f_mode & 2)) {
+ ret = -EROFS;
+ goto out_put_floppy;
+ }
+
+ ide_set_media_lock(drive, disk, 1);
+ drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
+ check_disk_change(inode->i_bdev);
+ } else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) {
+ ret = -EBUSY;
+ goto out_put_floppy;
+ }
+ return 0;
+
+out_put_floppy:
+ floppy->openers--;
+ ide_floppy_put(floppy);
+ return ret;
+}
+
+static int idefloppy_release(struct inode *inode, struct file *filp)
+{
+ struct gendisk *disk = inode->i_bdev->bd_disk;
+ struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
+ ide_drive_t *drive = floppy->drive;
+
+ ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
+ if (floppy->openers == 1) {
+ ide_set_media_lock(drive, disk, 0);
+ drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
+ }
+
+ floppy->openers--;
+
+ ide_floppy_put(floppy);
+
+ return 0;
+}
+
+static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+{
+ struct ide_floppy_obj *floppy = ide_drv_g(bdev->bd_disk,
+ ide_floppy_obj);
+ ide_drive_t *drive = floppy->drive;
+
+ geo->heads = drive->bios_head;
+ geo->sectors = drive->bios_sect;
+ geo->cylinders = (u16)drive->bios_cyl; /* truncate */
+ return 0;
+}
+
+static int idefloppy_media_changed(struct gendisk *disk)
+{
+ struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
+ ide_drive_t *drive = floppy->drive;
+ int ret;
+
+ /* do not scan partitions twice if this is a removable device */
+ if (drive->dev_flags & IDE_DFLAG_ATTACH) {
+ drive->dev_flags &= ~IDE_DFLAG_ATTACH;
+ return 0;
+ }
+
+ ret = !!(drive->dev_flags & IDE_DFLAG_MEDIA_CHANGED);
+ drive->dev_flags &= ~IDE_DFLAG_MEDIA_CHANGED;
+
+ return ret;
+}
+
+static int idefloppy_revalidate_disk(struct gendisk *disk)
+{
+ struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
+ set_capacity(disk, ide_floppy_capacity(floppy->drive));
+ return 0;
+}
+
+static struct block_device_operations idefloppy_ops = {
+ .owner = THIS_MODULE,
+ .open = idefloppy_open,
+ .release = idefloppy_release,
+ .ioctl = ide_floppy_ioctl,
+ .getgeo = idefloppy_getgeo,
+ .media_changed = idefloppy_media_changed,
+ .revalidate_disk = idefloppy_revalidate_disk
+};
+
+static int ide_floppy_probe(ide_drive_t *drive)
+{
+ idefloppy_floppy_t *floppy;
+ struct gendisk *g;
+
+ if (!strstr("ide-floppy", drive->driver_req))
+ goto failed;
+
+ if (drive->media != ide_floppy)
+ goto failed;
+
+ if (!ide_check_atapi_device(drive, DRV_NAME)) {
+ printk(KERN_ERR PFX "%s: not supported by this version of "
+ DRV_NAME "\n", drive->name);
+ goto failed;
+ }
+ floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL);
+ if (!floppy) {
+ printk(KERN_ERR PFX "%s: Can't allocate a floppy structure\n",
+ drive->name);
+ goto failed;
+ }
+
+ g = alloc_disk_node(1 << PARTN_BITS, hwif_to_node(drive->hwif));
+ if (!g)
+ goto out_free_floppy;
+
+ ide_init_disk(g, drive);
+
+ kref_init(&floppy->kref);
+
+ floppy->drive = drive;
+ floppy->driver = &idefloppy_driver;
+ floppy->disk = g;
+
+ g->private_data = &floppy->driver;
+
+ drive->driver_data = floppy;
+
+ drive->debug_mask = debug_mask;
+
+ ide_floppy_setup(drive);
+
+ set_capacity(g, ide_floppy_capacity(drive));
+
+ g->minors = 1 << PARTN_BITS;
+ g->driverfs_dev = &drive->gendev;
+ if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
+ g->flags = GENHD_FL_REMOVABLE;
+ g->fops = &idefloppy_ops;
+ add_disk(g);
+ return 0;
+
+out_free_floppy:
+ kfree(floppy);
+failed:
+ return -ENODEV;
+}
+
+static int __init idefloppy_init(void)
+{
+ printk(KERN_INFO DRV_NAME " driver " IDEFLOPPY_VERSION "\n");
+ return driver_register(&idefloppy_driver.gen_driver);
+}
+
+static void __exit idefloppy_exit(void)
+{
+ driver_unregister(&idefloppy_driver.gen_driver);
+}
+
+MODULE_ALIAS("ide:*m-floppy*");
+MODULE_ALIAS("ide-floppy");
+module_init(idefloppy_init);
+module_exit(idefloppy_exit);
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 16/18] ide: prepare for merging ide-gd-floppy.c with ide-gd.c
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
` (14 preceding siblings ...)
2008-09-07 22:16 ` [PATCH 15/18] ide-floppy: factor out generic disk handling code to ide-gd-floppy.c Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:16 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:16 ` [PATCH 17/18] ide: allow device drivers to specify per-device type /proc settings Bartlomiej Zolnierkiewicz
` (2 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:16 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
- idefloppy_ref_mutex -> ide_disk_ref_mutex
- idefloppy_cleanup_obj() -> ide_disk_release()
- ide_floppy_get() -> ide_disk_get()
- ide_floppy_put() -> ide_disk_put()
- ide_floppy_capacity() -> ide_gd_capacity()
- ide_floppy_remove() -> ide_gd_remove()
- ide_floppy_probe() -> ide_gd_probe()
- idefloppy_driver -> ide_gd_driver
- idefloppy_open() -> ide_gd_open()
- idefloppy_release() -> ide_gd_release()
- idefloppy_getgeo() -> ide_gd_getgeo()
- idefloppy_media_changed() -> ide_gd_media_changed()
- idefloppy_revalidate_disk() -> ide_gd_revalidate_disk()
- idefloppy_ops -> ide_gd_ops
- idefloppy_init() -> ide_gd_init()
- idefloppy_exit() -> ide_gd_exit()
- 'floppy' -> 'idkp' in ide_disk_*() and ide_gd_*()
- idefloppy_floppy_t -> struct ide_floppy_obj
There should be no functional changes caused by this patch.
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/ide-floppy.h | 2
drivers/ide/ide-floppy_proc.c | 2
drivers/ide/ide-gd-floppy.c | 179 ++++++++++++++++++++----------------------
3 files changed, 91 insertions(+), 92 deletions(-)
Index: b/drivers/ide/ide-floppy.h
===================================================================
--- a/drivers/ide/ide-floppy.h
+++ b/drivers/ide/ide-floppy.h
@@ -57,7 +57,7 @@ typedef struct ide_floppy_obj {
#define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
#define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
-sector_t ide_floppy_capacity(ide_drive_t *);
+sector_t ide_gd_capacity(ide_drive_t *);
/* ide-floppy.c */
void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *, u8);
Index: b/drivers/ide/ide-floppy_proc.c
===================================================================
--- a/drivers/ide/ide-floppy_proc.c
+++ b/drivers/ide/ide-floppy_proc.c
@@ -9,7 +9,7 @@ static int proc_idefloppy_read_capacity(
ide_drive_t*drive = (ide_drive_t *)data;
int len;
- len = sprintf(page, "%llu\n", (long long)ide_floppy_capacity(drive));
+ len = sprintf(page, "%llu\n", (long long)ide_gd_capacity(drive));
PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
}
Index: b/drivers/ide/ide-gd-floppy.c
===================================================================
--- a/drivers/ide/ide-gd-floppy.c
+++ b/drivers/ide/ide-gd-floppy.c
@@ -16,75 +16,75 @@
static unsigned long debug_mask;
module_param(debug_mask, ulong, 0644);
-static DEFINE_MUTEX(idefloppy_ref_mutex);
+static DEFINE_MUTEX(ide_disk_ref_mutex);
-static void idefloppy_cleanup_obj(struct kref *);
+static void ide_disk_release(struct kref *);
-static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
+static struct ide_floppy_obj *ide_disk_get(struct gendisk *disk)
{
- struct ide_floppy_obj *floppy = NULL;
+ struct ide_floppy_obj *idkp = NULL;
- mutex_lock(&idefloppy_ref_mutex);
- floppy = ide_drv_g(disk, ide_floppy_obj);
- if (floppy) {
- if (ide_device_get(floppy->drive))
- floppy = NULL;
+ mutex_lock(&ide_disk_ref_mutex);
+ idkp = ide_drv_g(disk, ide_floppy_obj);
+ if (idkp) {
+ if (ide_device_get(idkp->drive))
+ idkp = NULL;
else
- kref_get(&floppy->kref);
+ kref_get(&idkp->kref);
}
- mutex_unlock(&idefloppy_ref_mutex);
- return floppy;
+ mutex_unlock(&ide_disk_ref_mutex);
+ return idkp;
}
-static void ide_floppy_put(struct ide_floppy_obj *floppy)
+static void ide_disk_put(struct ide_floppy_obj *idkp)
{
- ide_drive_t *drive = floppy->drive;
+ ide_drive_t *drive = idkp->drive;
- mutex_lock(&idefloppy_ref_mutex);
- kref_put(&floppy->kref, idefloppy_cleanup_obj);
+ mutex_lock(&ide_disk_ref_mutex);
+ kref_put(&idkp->kref, ide_disk_release);
ide_device_put(drive);
- mutex_unlock(&idefloppy_ref_mutex);
+ mutex_unlock(&ide_disk_ref_mutex);
}
-sector_t ide_floppy_capacity(ide_drive_t *drive)
+sector_t ide_gd_capacity(ide_drive_t *drive)
{
return drive->capacity64;
}
-static void ide_floppy_remove(ide_drive_t *drive)
+static int ide_gd_probe(ide_drive_t *);
+
+static void ide_gd_remove(ide_drive_t *drive)
{
- idefloppy_floppy_t *floppy = drive->driver_data;
- struct gendisk *g = floppy->disk;
+ struct ide_floppy_obj *idkp = drive->driver_data;
+ struct gendisk *g = idkp->disk;
- ide_proc_unregister_driver(drive, floppy->driver);
+ ide_proc_unregister_driver(drive, idkp->driver);
del_gendisk(g);
- ide_floppy_put(floppy);
+ ide_disk_put(idkp);
}
-static void idefloppy_cleanup_obj(struct kref *kref)
+static void ide_disk_release(struct kref *kref)
{
- struct ide_floppy_obj *floppy = to_ide_drv(kref, ide_floppy_obj);
- ide_drive_t *drive = floppy->drive;
- struct gendisk *g = floppy->disk;
+ struct ide_floppy_obj *idkp = to_ide_drv(kref, ide_floppy_obj);
+ ide_drive_t *drive = idkp->drive;
+ struct gendisk *g = idkp->disk;
drive->driver_data = NULL;
g->private_data = NULL;
put_disk(g);
- kfree(floppy);
+ kfree(idkp);
}
-static int ide_floppy_probe(ide_drive_t *);
-
-static ide_driver_t idefloppy_driver = {
+static ide_driver_t ide_gd_driver = {
.gen_driver = {
.owner = THIS_MODULE,
.name = "ide-floppy",
.bus = &ide_bus_type,
},
- .probe = ide_floppy_probe,
- .remove = ide_floppy_remove,
+ .probe = ide_gd_probe,
+ .remove = ide_gd_remove,
.version = IDEFLOPPY_VERSION,
.do_request = ide_floppy_do_request,
.end_request = ide_floppy_end_request,
@@ -95,24 +95,24 @@ static ide_driver_t idefloppy_driver = {
#endif
};
-static int idefloppy_open(struct inode *inode, struct file *filp)
+static int ide_gd_open(struct inode *inode, struct file *filp)
{
struct gendisk *disk = inode->i_bdev->bd_disk;
- struct ide_floppy_obj *floppy;
+ struct ide_floppy_obj *idkp;
ide_drive_t *drive;
int ret = 0;
- floppy = ide_floppy_get(disk);
- if (!floppy)
+ idkp = ide_disk_get(disk);
+ if (idkp == NULL)
return -ENXIO;
- drive = floppy->drive;
+ drive = idkp->drive;
ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
- floppy->openers++;
+ idkp->openers++;
- if (floppy->openers == 1) {
+ if (idkp->openers == 1) {
drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
/* Just in case */
@@ -121,7 +121,7 @@ static int idefloppy_open(struct inode *
ret = ide_floppy_get_capacity(drive);
- set_capacity(disk, ide_floppy_capacity(drive));
+ set_capacity(disk, ide_gd_capacity(drive));
if (ret && (filp->f_flags & O_NDELAY) == 0) {
/*
@@ -130,12 +130,12 @@ static int idefloppy_open(struct inode *
* of the drive or begin the format - Sam
*/
ret = -EIO;
- goto out_put_floppy;
+ goto out_put_idkp;
}
if ((drive->dev_flags & IDE_DFLAG_WP) && (filp->f_mode & 2)) {
ret = -EROFS;
- goto out_put_floppy;
+ goto out_put_idkp;
}
ide_set_media_lock(drive, disk, 1);
@@ -143,41 +143,40 @@ static int idefloppy_open(struct inode *
check_disk_change(inode->i_bdev);
} else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) {
ret = -EBUSY;
- goto out_put_floppy;
+ goto out_put_idkp;
}
return 0;
-out_put_floppy:
- floppy->openers--;
- ide_floppy_put(floppy);
+out_put_idkp:
+ idkp->openers--;
+ ide_disk_put(idkp);
return ret;
}
-static int idefloppy_release(struct inode *inode, struct file *filp)
+static int ide_gd_release(struct inode *inode, struct file *filp)
{
struct gendisk *disk = inode->i_bdev->bd_disk;
- struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
- ide_drive_t *drive = floppy->drive;
+ struct ide_floppy_obj *idkp = ide_drv_g(disk, ide_floppy_obj);
+ ide_drive_t *drive = idkp->drive;
ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
- if (floppy->openers == 1) {
+ if (idkp->openers == 1) {
ide_set_media_lock(drive, disk, 0);
drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
}
- floppy->openers--;
+ idkp->openers--;
- ide_floppy_put(floppy);
+ ide_disk_put(idkp);
return 0;
}
-static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+static int ide_gd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
{
- struct ide_floppy_obj *floppy = ide_drv_g(bdev->bd_disk,
- ide_floppy_obj);
- ide_drive_t *drive = floppy->drive;
+ struct ide_floppy_obj *idkp = ide_drv_g(bdev->bd_disk, ide_floppy_obj);
+ ide_drive_t *drive = idkp->drive;
geo->heads = drive->bios_head;
geo->sectors = drive->bios_sect;
@@ -185,10 +184,10 @@ static int idefloppy_getgeo(struct block
return 0;
}
-static int idefloppy_media_changed(struct gendisk *disk)
+static int ide_gd_media_changed(struct gendisk *disk)
{
- struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
- ide_drive_t *drive = floppy->drive;
+ struct ide_floppy_obj *idkp = ide_drv_g(disk, ide_floppy_obj);
+ ide_drive_t *drive = idkp->drive;
int ret;
/* do not scan partitions twice if this is a removable device */
@@ -203,26 +202,26 @@ static int idefloppy_media_changed(struc
return ret;
}
-static int idefloppy_revalidate_disk(struct gendisk *disk)
+static int ide_gd_revalidate_disk(struct gendisk *disk)
{
- struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
- set_capacity(disk, ide_floppy_capacity(floppy->drive));
+ struct ide_floppy_obj *idkp = ide_drv_g(disk, ide_floppy_obj);
+ set_capacity(disk, ide_gd_capacity(idkp->drive));
return 0;
}
-static struct block_device_operations idefloppy_ops = {
+static struct block_device_operations ide_gd_ops = {
.owner = THIS_MODULE,
- .open = idefloppy_open,
- .release = idefloppy_release,
+ .open = ide_gd_open,
+ .release = ide_gd_release,
.ioctl = ide_floppy_ioctl,
- .getgeo = idefloppy_getgeo,
- .media_changed = idefloppy_media_changed,
- .revalidate_disk = idefloppy_revalidate_disk
+ .getgeo = ide_gd_getgeo,
+ .media_changed = ide_gd_media_changed,
+ .revalidate_disk = ide_gd_revalidate_disk
};
-static int ide_floppy_probe(ide_drive_t *drive)
+static int ide_gd_probe(ide_drive_t *drive)
{
- idefloppy_floppy_t *floppy;
+ struct ide_floppy_obj *idkp;
struct gendisk *g;
if (!strstr("ide-floppy", drive->driver_req))
@@ -236,8 +235,8 @@ static int ide_floppy_probe(ide_drive_t
DRV_NAME "\n", drive->name);
goto failed;
}
- floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL);
- if (!floppy) {
+ idkp = kzalloc(sizeof(*idkp), GFP_KERNEL);
+ if (!idkp) {
printk(KERN_ERR PFX "%s: Can't allocate a floppy structure\n",
drive->name);
goto failed;
@@ -245,54 +244,54 @@ static int ide_floppy_probe(ide_drive_t
g = alloc_disk_node(1 << PARTN_BITS, hwif_to_node(drive->hwif));
if (!g)
- goto out_free_floppy;
+ goto out_free_idkp;
ide_init_disk(g, drive);
- kref_init(&floppy->kref);
+ kref_init(&idkp->kref);
- floppy->drive = drive;
- floppy->driver = &idefloppy_driver;
- floppy->disk = g;
+ idkp->drive = drive;
+ idkp->driver = &ide_gd_driver;
+ idkp->disk = g;
- g->private_data = &floppy->driver;
+ g->private_data = &idkp->driver;
- drive->driver_data = floppy;
+ drive->driver_data = idkp;
drive->debug_mask = debug_mask;
ide_floppy_setup(drive);
- set_capacity(g, ide_floppy_capacity(drive));
+ set_capacity(g, ide_gd_capacity(drive));
g->minors = 1 << PARTN_BITS;
g->driverfs_dev = &drive->gendev;
if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
g->flags = GENHD_FL_REMOVABLE;
- g->fops = &idefloppy_ops;
+ g->fops = &ide_gd_ops;
add_disk(g);
return 0;
-out_free_floppy:
- kfree(floppy);
+out_free_idkp:
+ kfree(idkp);
failed:
return -ENODEV;
}
-static int __init idefloppy_init(void)
+static int __init ide_gd_init(void)
{
printk(KERN_INFO DRV_NAME " driver " IDEFLOPPY_VERSION "\n");
- return driver_register(&idefloppy_driver.gen_driver);
+ return driver_register(&ide_gd_driver.gen_driver);
}
-static void __exit idefloppy_exit(void)
+static void __exit ide_gd_exit(void)
{
- driver_unregister(&idefloppy_driver.gen_driver);
+ driver_unregister(&ide_gd_driver.gen_driver);
}
MODULE_ALIAS("ide:*m-floppy*");
MODULE_ALIAS("ide-floppy");
-module_init(idefloppy_init);
-module_exit(idefloppy_exit);
+module_init(ide_gd_init);
+module_exit(ide_gd_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 17/18] ide: allow device drivers to specify per-device type /proc settings
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
` (15 preceding siblings ...)
2008-09-07 22:16 ` [PATCH 16/18] ide: prepare for merging ide-gd-floppy.c with ide-gd.c Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:16 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:16 ` [PATCH 18/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
2008-09-10 11:20 ` [PATCH 00/18] " Borislav Petkov
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:16 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
Turn ide_driver_t's 'proc' field into ->proc_entries method
(and also 'settings' field into ->proc_devsets method). Then
update all device drivers accordingly.
There should be no functional changes caused by this patch.
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/ide-cd.c | 14 ++++++++++++--
drivers/ide/ide-gd-floppy.c | 16 ++++++++++++++--
drivers/ide/ide-gd.c | 16 ++++++++++++++--
drivers/ide/ide-proc.c | 6 +++---
drivers/ide/ide-tape.c | 14 ++++++++++++--
drivers/scsi/ide-scsi.c | 26 +++++++++++++++++---------
include/linux/ide.h | 4 ++--
7 files changed, 74 insertions(+), 22 deletions(-)
Index: b/drivers/ide/ide-cd.c
===================================================================
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -1904,6 +1904,16 @@ static const struct ide_proc_devset idec
IDE_PROC_DEVSET(dsc_overlap, 0, 1),
{ 0 },
};
+
+static ide_proc_entry_t *ide_cd_proc_entries(ide_drive_t *drive)
+{
+ return idecd_proc;
+}
+
+static const struct ide_proc_devset *ide_cd_proc_devsets(ide_drive_t *drive)
+{
+ return idecd_settings;
+}
#endif
static const struct cd_list_entry ide_cd_quirks_list[] = {
@@ -2064,8 +2074,8 @@ static ide_driver_t ide_cdrom_driver = {
.end_request = ide_end_request,
.error = __ide_error,
#ifdef CONFIG_IDE_PROC_FS
- .proc = idecd_proc,
- .settings = idecd_settings,
+ .proc_entries = ide_cd_proc_entries,
+ .proc_devsets = ide_cd_proc_devsets,
#endif
};
Index: b/drivers/ide/ide-gd-floppy.c
===================================================================
--- a/drivers/ide/ide-gd-floppy.c
+++ b/drivers/ide/ide-gd-floppy.c
@@ -77,6 +77,18 @@ static void ide_disk_release(struct kref
kfree(idkp);
}
+#ifdef CONFIG_IDE_PROC_FS
+static ide_proc_entry_t *ide_floppy_proc_entries(ide_drive_t *drive)
+{
+ return ide_floppy_proc;
+}
+
+static const struct ide_proc_devset *ide_floppy_proc_devsets(ide_drive_t *drive)
+{
+ return ide_floppy_settings;
+}
+#endif
+
static ide_driver_t ide_gd_driver = {
.gen_driver = {
.owner = THIS_MODULE,
@@ -90,8 +102,8 @@ static ide_driver_t ide_gd_driver = {
.end_request = ide_floppy_end_request,
.error = __ide_error,
#ifdef CONFIG_IDE_PROC_FS
- .proc = ide_floppy_proc,
- .settings = ide_floppy_settings,
+ .proc_entries = ide_floppy_proc_entries,
+ .proc_devsets = ide_floppy_proc_devsets,
#endif
};
Index: b/drivers/ide/ide-gd.c
===================================================================
--- a/drivers/ide/ide-gd.c
+++ b/drivers/ide/ide-gd.c
@@ -113,6 +113,18 @@ static void ide_gd_shutdown(ide_drive_t
drive->gendev.bus->suspend(&drive->gendev, PMSG_SUSPEND);
}
+#ifdef CONFIG_IDE_PROC_FS
+static ide_proc_entry_t *ide_disk_proc_entries(ide_drive_t *drive)
+{
+ return ide_disk_proc;
+}
+
+static const struct ide_proc_devset *ide_disk_proc_devsets(ide_drive_t *drive)
+{
+ return ide_disk_settings;
+}
+#endif
+
static ide_driver_t ide_gd_driver = {
.gen_driver = {
.owner = THIS_MODULE,
@@ -128,8 +140,8 @@ static ide_driver_t ide_gd_driver = {
.end_request = ide_end_request,
.error = __ide_error,
#ifdef CONFIG_IDE_PROC_FS
- .proc = ide_disk_proc,
- .settings = ide_disk_settings,
+ .proc_entries = ide_disk_proc_entries,
+ .proc_devsets = ide_disk_proc_devsets,
#endif
};
Index: b/drivers/ide/ide-proc.c
===================================================================
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -567,10 +567,10 @@ static void ide_remove_proc_entries(stru
void ide_proc_register_driver(ide_drive_t *drive, ide_driver_t *driver)
{
mutex_lock(&ide_setting_mtx);
- drive->settings = driver->settings;
+ drive->settings = driver->proc_devsets(drive);
mutex_unlock(&ide_setting_mtx);
- ide_add_proc_entries(drive->proc, driver->proc, drive);
+ ide_add_proc_entries(drive->proc, driver->proc_entries(drive), drive);
}
EXPORT_SYMBOL(ide_proc_register_driver);
@@ -591,7 +591,7 @@ void ide_proc_unregister_driver(ide_driv
{
unsigned long flags;
- ide_remove_proc_entries(drive->proc, driver->proc);
+ ide_remove_proc_entries(drive->proc, driver->proc_entries(drive));
mutex_lock(&ide_setting_mtx);
spin_lock_irqsave(&ide_lock, flags);
Index: b/drivers/ide/ide-tape.c
===================================================================
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -2297,6 +2297,16 @@ static ide_proc_entry_t idetape_proc[] =
{ "name", S_IFREG|S_IRUGO, proc_idetape_read_name, NULL },
{ NULL, 0, NULL, NULL }
};
+
+static ide_proc_entry_t *ide_tape_proc_entries(ide_drive_t *drive)
+{
+ return idetape_proc;
+}
+
+static const struct ide_proc_devset *ide_tape_proc_devsets(ide_drive_t *drive)
+{
+ return idetape_settings;
+}
#endif
static int ide_tape_probe(ide_drive_t *);
@@ -2314,8 +2324,8 @@ static ide_driver_t idetape_driver = {
.end_request = idetape_end_request,
.error = __ide_error,
#ifdef CONFIG_IDE_PROC_FS
- .proc = idetape_proc,
- .settings = idetape_settings,
+ .proc_entries = ide_tape_proc_entries,
+ .proc_devsets = ide_tape_proc_devsets,
#endif
};
Index: b/drivers/scsi/ide-scsi.c
===================================================================
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -343,6 +343,11 @@ static ide_startstop_t idescsi_do_reques
}
#ifdef CONFIG_IDE_PROC_FS
+static ide_proc_entry_t idescsi_proc[] = {
+ { "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL },
+ { NULL, 0, NULL, NULL }
+};
+
#define ide_scsi_devset_get(name, field) \
static int get_##name(ide_drive_t *drive) \
{ \
@@ -378,6 +383,16 @@ static const struct ide_proc_devset ides
IDE_PROC_DEVSET(transform, 0, 3),
{ 0 },
};
+
+static ide_proc_entry_t *ide_scsi_proc_entries(ide_drive_t *drive)
+{
+ return idescsi_proc;
+}
+
+static const struct ide_proc_devset *ide_scsi_proc_devsets(ide_drive_t *drive)
+{
+ return idescsi_settings;
+}
#endif
/*
@@ -419,13 +434,6 @@ static void ide_scsi_remove(ide_drive_t
static int ide_scsi_probe(ide_drive_t *);
-#ifdef CONFIG_IDE_PROC_FS
-static ide_proc_entry_t idescsi_proc[] = {
- { "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL },
- { NULL, 0, NULL, NULL }
-};
-#endif
-
static ide_driver_t idescsi_driver = {
.gen_driver = {
.owner = THIS_MODULE,
@@ -439,8 +447,8 @@ static ide_driver_t idescsi_driver = {
.end_request = idescsi_end_request,
.error = idescsi_atapi_error,
#ifdef CONFIG_IDE_PROC_FS
- .proc = idescsi_proc,
- .settings = idescsi_settings,
+ .proc_entries = ide_scsi_proc_entries,
+ .proc_devsets = ide_scsi_proc_devsets,
#endif
};
Index: b/include/linux/ide.h
===================================================================
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -1111,8 +1111,8 @@ struct ide_driver_s {
void (*resume)(ide_drive_t *);
void (*shutdown)(ide_drive_t *);
#ifdef CONFIG_IDE_PROC_FS
- ide_proc_entry_t *proc;
- const struct ide_proc_devset *settings;
+ ide_proc_entry_t * (*proc_entries)(ide_drive_t *);
+ const struct ide_proc_devset * (*proc_devsets)(ide_drive_t *);
#endif
};
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 18/18] ide: add generic ATA/ATAPI disk driver
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
` (16 preceding siblings ...)
2008-09-07 22:16 ` [PATCH 17/18] ide: allow device drivers to specify per-device type /proc settings Bartlomiej Zolnierkiewicz
@ 2008-09-07 22:16 ` Bartlomiej Zolnierkiewicz
2008-09-10 11:20 ` [PATCH 00/18] " Borislav Petkov
18 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-07 22:16 UTC (permalink / raw)
To: linux-ide; +Cc: Borislav Petkov, Bartlomiej Zolnierkiewicz, linux-kernel
* Add struct ide_disk_ops containing protocol specific methods.
* Add 'struct ide_disk_ops *' to ide_drive_t.
* Convert ide-{disk,floppy} drivers to use struct ide_disk_ops.
* Merge ide-{disk,floppy} drivers into generic ide-gd driver.
While at it:
- ide_disk_init_capacity() -> ide_disk_get_capacity()
Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/Kconfig | 64 +++-----
drivers/ide/Makefile | 19 +-
drivers/ide/ide-disk.c | 39 ++++-
drivers/ide/ide-disk.h | 24 +--
drivers/ide/ide-disk_ioctl.c | 4
drivers/ide/ide-floppy.c | 45 ++++-
drivers/ide/ide-floppy.h | 58 +------
drivers/ide/ide-floppy_ioctl.c | 9 -
drivers/ide/ide-gd-floppy.c | 309 -----------------------------------------
drivers/ide/ide-gd.c | 124 ++++++++++++++--
drivers/ide/ide-gd.h | 44 +++++
drivers/leds/Kconfig | 2
include/linux/ide.h | 19 ++
13 files changed, 305 insertions(+), 455 deletions(-)
Index: b/drivers/ide/Kconfig
===================================================================
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -84,21 +84,40 @@ config BLK_DEV_IDE_SATA
If unsure, say N.
-config BLK_DEV_IDEDISK
- tristate "Include IDE/ATA-2 DISK support"
- ---help---
- This will include enhanced support for MFM/RLL/IDE hard disks. If
- you have a MFM/RLL/IDE disk, and there is no special reason to use
- the old hard disk driver instead, say Y. If you have an SCSI-only
- system, you can say N here.
+config IDE_GD
+ tristate "generic ATA/ATAPI disk support"
+ default y
+ help
+ Support for ATA/ATAPI disks (including ATAPI floppy drives).
- To compile this driver as a module, choose M here: the
- module will be called ide-disk.
- Do not compile this driver as a module if your root file system
- (the one containing the directory /) is located on the IDE disk.
+ To compile this driver as a module, choose M here.
+ The module will be called ide-gd_mod.
If unsure, say Y.
+config IDE_GD_ATA
+ bool "ATA disk support"
+ depends on IDE_GD
+ default y
+ help
+ This will include support for ATA hard disks.
+
+ If unsure, say Y.
+
+config IDE_GD_ATAPI
+ bool "ATAPI floppy support"
+ depends on IDE_GD
+ select IDE_ATAPI
+ help
+ This will include support for ATAPI floppy drives
+ (i.e. Iomega ZIP or MKE LS-120).
+
+ For information about jumper settings and the question
+ of when a ZIP drive uses a partition table, see
+ <http://www.win.tue.nl/~aeb/linux/zip/zip-1.html>.
+
+ If unsure, say N.
+
config BLK_DEV_IDECS
tristate "PCMCIA IDE support"
depends on PCMCIA
@@ -163,29 +182,6 @@ config BLK_DEV_IDETAPE
To compile this driver as a module, choose M here: the
module will be called ide-tape.
-config BLK_DEV_IDEFLOPPY
- tristate "Include IDE/ATAPI FLOPPY support"
- select IDE_ATAPI
- ---help---
- If you have an IDE floppy drive which uses the ATAPI protocol,
- answer Y. ATAPI is a newer protocol used by IDE CD-ROM/tape/floppy
- drives, similar to the SCSI protocol.
-
- The LS-120 and the IDE/ATAPI Iomega ZIP drive are also supported by
- this driver. For information about jumper settings and the question
- of when a ZIP drive uses a partition table, see
- <http://www.win.tue.nl/~aeb/linux/zip/zip-1.html>.
- (ATAPI PD-CD/CDR drives are not supported by this driver; support
- for PD-CD/CDR drives is available if you answer Y to
- "SCSI emulation support", below).
-
- If you say Y here, the FLOPPY drive will be identified along with
- other IDE devices, as "hdb" or "hdc", or something similar (check
- the boot messages with dmesg).
-
- To compile this driver as a module, choose M here: the
- module will be called ide-floppy.
-
config BLK_DEV_IDESCSI
tristate "SCSI emulation support (DEPRECATED)"
depends on SCSI
Index: b/drivers/ide/Makefile
===================================================================
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -37,18 +37,25 @@ obj-$(CONFIG_IDE_H8300) += h8300/
obj-$(CONFIG_IDE_GENERIC) += ide-generic.o
obj-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o
-ide-disk_mod-y += ide-gd.o ide-disk.o ide-disk_ioctl.o
+ide-gd_mod-y += ide-gd.o
ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o
-ide-floppy_mod-y += ide-gd-floppy.o ide-floppy.o ide-floppy_ioctl.o
+ifeq ($(CONFIG_IDE_GD_ATA), y)
+ ide-gd_mod-y += ide-disk.o ide-disk_ioctl.o
ifeq ($(CONFIG_IDE_PROC_FS), y)
- ide-disk_mod-y += ide-disk_proc.o
- ide-floppy_mod-y += ide-floppy_proc.o
+ ide-gd_mod-y += ide-disk_proc.o
+endif
+endif
+
+ifeq ($(CONFIG_IDE_GD_ATAPI), y)
+ ide-gd_mod-y += ide-floppy.o ide-floppy_ioctl.o
+ifeq ($(CONFIG_IDE_PROC_FS), y)
+ ide-gd_mod-y += ide-floppy_proc.o
+endif
endif
-obj-$(CONFIG_BLK_DEV_IDEDISK) += ide-disk_mod.o
+obj-$(CONFIG_IDE_GD) += ide-gd_mod.o
obj-$(CONFIG_BLK_DEV_IDECD) += ide-cd_mod.o
-obj-$(CONFIG_BLK_DEV_IDEFLOPPY) += ide-floppy_mod.o
obj-$(CONFIG_BLK_DEV_IDETAPE) += ide-tape.o
ifeq ($(CONFIG_BLK_DEV_IDECS), y)
Index: b/drivers/ide/ide-disk.c
===================================================================
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -184,8 +184,8 @@ static ide_startstop_t __ide_do_rw_disk(
* 1073741822 == 549756 MB or 48bit addressing fake drive
*/
-ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
- sector_t block)
+static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
+ sector_t block)
{
ide_hwif_t *hwif = HWIF(drive);
@@ -333,7 +333,7 @@ static void idedisk_check_hpa(ide_drive_
}
}
-void ide_disk_init_capacity(ide_drive_t *drive)
+static int ide_disk_get_capacity(ide_drive_t *drive)
{
u16 *id = drive->id;
int lba;
@@ -382,6 +382,8 @@ void ide_disk_init_capacity(ide_drive_t
} else
drive->dev_flags &= ~IDE_DFLAG_LBA48;
}
+
+ return 0;
}
static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
@@ -590,7 +592,12 @@ ide_ext_devset_rw(wcache, wcache);
ide_ext_devset_rw_sync(nowerr, nowerr);
-void ide_disk_setup(ide_drive_t *drive)
+static int ide_disk_check(ide_drive_t *drive, const char *s)
+{
+ return 1;
+}
+
+static void ide_disk_setup(ide_drive_t *drive)
{
struct ide_disk_obj *idkp = drive->driver_data;
ide_hwif_t *hwif = drive->hwif;
@@ -626,7 +633,7 @@ void ide_disk_setup(ide_drive_t *drive)
drive->queue->max_sectors / 2);
/* calculate drive capacity, and select LBA if possible */
- ide_disk_init_capacity(drive);
+ ide_disk_get_capacity(drive);
/*
* if possible, give fdisk access to more of the drive,
@@ -682,7 +689,7 @@ void ide_disk_setup(ide_drive_t *drive)
drive->dev_flags |= IDE_DFLAG_ATTACH;
}
-void ide_disk_flush(ide_drive_t *drive)
+static void ide_disk_flush(ide_drive_t *drive)
{
if (ata_id_flush_enabled(drive->id) == 0 ||
(drive->dev_flags & IDE_DFLAG_WCACHE) == 0)
@@ -692,7 +699,13 @@ void ide_disk_flush(ide_drive_t *drive)
printk(KERN_INFO "%s: wcache flush failed!\n", drive->name);
}
-int ide_disk_set_doorlock(ide_drive_t *drive, int on)
+static int ide_disk_init_media(ide_drive_t *drive, struct gendisk *disk)
+{
+ return 0;
+}
+
+static int ide_disk_set_doorlock(ide_drive_t *drive, struct gendisk *disk,
+ int on)
{
ide_task_t task;
int ret;
@@ -711,3 +724,15 @@ int ide_disk_set_doorlock(ide_drive_t *d
return ret;
}
+
+const struct ide_disk_ops ide_ata_disk_ops = {
+ .check = ide_disk_check,
+ .get_capacity = ide_disk_get_capacity,
+ .setup = ide_disk_setup,
+ .flush = ide_disk_flush,
+ .init_media = ide_disk_init_media,
+ .set_doorlock = ide_disk_set_doorlock,
+ .do_request = ide_do_rw_disk,
+ .end_request = ide_end_request,
+ .ioctl = ide_disk_ioctl,
+};
Index: b/drivers/ide/ide-disk.h
===================================================================
--- a/drivers/ide/ide-disk.h
+++ b/drivers/ide/ide-disk.h
@@ -1,22 +1,11 @@
#ifndef __IDE_DISK_H
#define __IDE_DISK_H
-struct ide_disk_obj {
- ide_drive_t *drive;
- ide_driver_t *driver;
- struct gendisk *disk;
- struct kref kref;
- unsigned int openers; /* protected by BKL for now */
-};
-
-sector_t ide_gd_capacity(ide_drive_t *);
+#include "ide-gd.h"
+#ifdef CONFIG_IDE_GD_ATA
/* ide-disk.c */
-void ide_disk_init_capacity(ide_drive_t *);
-void ide_disk_setup(ide_drive_t *);
-void ide_disk_flush(ide_drive_t *);
-int ide_disk_set_doorlock(ide_drive_t *, int);
-ide_startstop_t ide_do_rw_disk(ide_drive_t *, struct request *, sector_t);
+extern const struct ide_disk_ops ide_ata_disk_ops;
ide_decl_devset(address);
ide_decl_devset(multcount);
ide_decl_devset(nowerr);
@@ -24,12 +13,17 @@ ide_decl_devset(wcache);
ide_decl_devset(acoustic);
/* ide-disk_ioctl.c */
-int ide_disk_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
+int ide_disk_ioctl(ide_drive_t *, struct inode *, struct file *, unsigned int,
+ unsigned long);
#ifdef CONFIG_IDE_PROC_FS
/* ide-disk_proc.c */
extern ide_proc_entry_t ide_disk_proc[];
extern const struct ide_proc_devset ide_disk_settings[];
#endif
+#else
+#define ide_disk_proc NULL
+#define ide_disk_settings NULL
+#endif
#endif /* __IDE_DISK_H */
Index: b/drivers/ide/ide-disk_ioctl.c
===================================================================
--- a/drivers/ide/ide-disk_ioctl.c
+++ b/drivers/ide/ide-disk_ioctl.c
@@ -13,12 +13,10 @@ static const struct ide_ioctl_devset ide
{ 0 }
};
-int ide_disk_ioctl(struct inode *inode, struct file *file,
+int ide_disk_ioctl(ide_drive_t *drive, struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
struct block_device *bdev = inode->i_bdev;
- struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
- ide_drive_t *drive = idkp->drive;
int err;
err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -68,7 +68,7 @@
* Used to finish servicing a request. For read/write requests, we will call
* ide_end_request to pass to the next buffer.
*/
-int ide_floppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
+static int ide_floppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
{
idefloppy_floppy_t *floppy = drive->driver_data;
struct request *rq = HWGROUP(drive)->rq;
@@ -280,13 +280,12 @@ static void idefloppy_blockpc_cmd(ideflo
pc->req_xfer = pc->buf_size = rq->data_len;
}
-ide_startstop_t ide_floppy_do_request(ide_drive_t *drive, struct request *rq,
- sector_t block_s)
+static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
+ struct request *rq, sector_t block)
{
idefloppy_floppy_t *floppy = drive->driver_data;
ide_hwif_t *hwif = drive->hwif;
struct ide_atapi_pc *pc;
- unsigned long block = (unsigned long)block_s;
ide_debug_log(IDE_DBG_FUNC, "%s: dev: %s, cmd: 0x%x, cmd_type: %x, "
"errors: %d\n",
@@ -316,7 +315,7 @@ ide_startstop_t ide_floppy_do_request(id
return ide_stopped;
}
pc = &floppy->queued_pc;
- idefloppy_create_rw_cmd(drive, pc, rq, block);
+ idefloppy_create_rw_cmd(drive, pc, rq, (unsigned long)block);
} else if (blk_special_request(rq)) {
pc = (struct ide_atapi_pc *) rq->buffer;
} else if (blk_pc_request(rq)) {
@@ -406,7 +405,7 @@ static int ide_floppy_get_flexible_disk_
* Determine if a media is present in the floppy drive, and if so, its LBA
* capacity.
*/
-int ide_floppy_get_capacity(ide_drive_t *drive)
+static int ide_floppy_get_capacity(ide_drive_t *drive)
{
idefloppy_floppy_t *floppy = drive->driver_data;
struct gendisk *disk = floppy->disk;
@@ -505,9 +504,9 @@ int ide_floppy_get_capacity(ide_drive_t
return rc;
}
-void ide_floppy_setup(ide_drive_t *drive)
+static void ide_floppy_setup(ide_drive_t *drive)
{
- struct ide_floppy_obj *floppy = drive->driver_data;
+ struct ide_disk_obj *floppy = drive->driver_data;
u16 *id = drive->id;
drive->pc_callback = ide_floppy_callback;
@@ -547,3 +546,33 @@ void ide_floppy_setup(ide_drive_t *drive
drive->dev_flags |= IDE_DFLAG_ATTACH;
}
+
+static void ide_floppy_flush(ide_drive_t *drive)
+{
+}
+
+static int ide_floppy_init_media(ide_drive_t *drive, struct gendisk *disk)
+{
+ int ret = 0;
+
+ if (ide_do_test_unit_ready(drive, disk))
+ ide_do_start_stop(drive, disk, 1);
+
+ ret = ide_floppy_get_capacity(drive);
+
+ set_capacity(disk, ide_gd_capacity(drive));
+
+ return ret;
+}
+
+const struct ide_disk_ops ide_atapi_disk_ops = {
+ .check = ide_check_atapi_device,
+ .get_capacity = ide_floppy_get_capacity,
+ .setup = ide_floppy_setup,
+ .flush = ide_floppy_flush,
+ .init_media = ide_floppy_init_media,
+ .set_doorlock = ide_set_media_lock,
+ .do_request = ide_floppy_do_request,
+ .end_request = ide_floppy_end_request,
+ .ioctl = ide_floppy_ioctl,
+};
Index: b/drivers/ide/ide-floppy.h
===================================================================
--- a/drivers/ide/ide-floppy.h
+++ b/drivers/ide/ide-floppy.h
@@ -1,48 +1,10 @@
#ifndef __IDE_FLOPPY_H
#define __IDE_FLOPPY_H
-#define DRV_NAME "ide-floppy"
-#define PFX DRV_NAME ": "
+#include "ide-gd.h"
-/* define to see debug info */
-#define IDEFLOPPY_DEBUG_LOG 0
-
-#if IDEFLOPPY_DEBUG_LOG
-#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, args)
-#else
-#define ide_debug_log(lvl, fmt, args...) do {} while (0)
-#endif
-
-/*
- * Most of our global data which we need to save even as we leave the driver
- * due to an interrupt or a timer event is stored in a variable of type
- * idefloppy_floppy_t, defined below.
- */
-typedef struct ide_floppy_obj {
- ide_drive_t *drive;
- ide_driver_t *driver;
- struct gendisk *disk;
- struct kref kref;
- unsigned int openers; /* protected by BKL for now */
-
- /* Last failed packet command */
- struct ide_atapi_pc *failed_pc;
- /* used for blk_{fs,pc}_request() requests */
- struct ide_atapi_pc queued_pc;
-
- /* Last error information */
- u8 sense_key, asc, ascq;
-
- int progress_indication;
-
- /* Device information */
- /* Current format */
- int blocks, block_size, bs_factor;
- /* Last format capacity descriptor */
- u8 cap_desc[8];
- /* Copy of the flexible disk page */
- u8 flexible_disk_page[32];
-} idefloppy_floppy_t;
+#ifdef CONFIG_IDE_GD_ATAPI
+typedef struct ide_disk_obj idefloppy_floppy_t;
/*
* Pages of the SELECT SENSE / MODE SENSE packet commands.
@@ -57,23 +19,23 @@ typedef struct ide_floppy_obj {
#define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
#define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
-sector_t ide_gd_capacity(ide_drive_t *);
-
/* ide-floppy.c */
+extern const struct ide_disk_ops ide_atapi_disk_ops;
void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *, u8);
void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *);
-int ide_floppy_get_capacity(ide_drive_t *);
-void ide_floppy_setup(ide_drive_t *);
-ide_startstop_t ide_floppy_do_request(ide_drive_t *, struct request *, sector_t);
-int ide_floppy_end_request(ide_drive_t *, int, int);
/* ide-floppy_ioctl.c */
-int ide_floppy_ioctl(struct inode *, struct file *, unsigned, unsigned long);
+int ide_floppy_ioctl(ide_drive_t *, struct inode *, struct file *, unsigned int,
+ unsigned long);
#ifdef CONFIG_IDE_PROC_FS
/* ide-floppy_proc.c */
extern ide_proc_entry_t ide_floppy_proc[];
extern const struct ide_proc_devset ide_floppy_settings[];
#endif
+#else
+#define ide_floppy_proc NULL
+#define ide_floppy_settings NULL
+#endif
#endif /*__IDE_FLOPPY_H */
Index: b/drivers/ide/ide-floppy_ioctl.c
===================================================================
--- a/drivers/ide/ide-floppy_ioctl.c
+++ b/drivers/ide/ide-floppy_ioctl.c
@@ -33,7 +33,7 @@
static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
{
- struct ide_floppy_obj *floppy = drive->driver_data;
+ struct ide_disk_obj *floppy = drive->driver_data;
struct ide_atapi_pc pc;
u8 header_len, desc_cnt;
int i, blocks, length, u_array_size, u_index;
@@ -260,13 +260,10 @@ static int ide_floppy_format_ioctl(ide_d
}
}
-int ide_floppy_ioctl(struct inode *inode, struct file *file,
- unsigned int cmd, unsigned long arg)
+int ide_floppy_ioctl(ide_drive_t *drive, struct inode *inode,
+ struct file *file, unsigned int cmd, unsigned long arg)
{
struct block_device *bdev = inode->i_bdev;
- struct ide_floppy_obj *floppy = ide_drv_g(bdev->bd_disk,
- ide_floppy_obj);
- ide_drive_t *drive = floppy->drive;
struct ide_atapi_pc pc;
void __user *argp = (void __user *)arg;
int err;
Index: b/drivers/ide/ide-gd-floppy.c
===================================================================
--- a/drivers/ide/ide-gd-floppy.c
+++ /dev/null
@@ -1,309 +0,0 @@
-#include <linux/module.h>
-#include <linux/types.h>
-#include <linux/string.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/genhd.h>
-#include <linux/mutex.h>
-#include <linux/ide.h>
-#include <linux/hdreg.h>
-
-#include "ide-floppy.h"
-
-#define IDEFLOPPY_VERSION "1.00"
-
-/* module parameters */
-static unsigned long debug_mask;
-module_param(debug_mask, ulong, 0644);
-
-static DEFINE_MUTEX(ide_disk_ref_mutex);
-
-static void ide_disk_release(struct kref *);
-
-static struct ide_floppy_obj *ide_disk_get(struct gendisk *disk)
-{
- struct ide_floppy_obj *idkp = NULL;
-
- mutex_lock(&ide_disk_ref_mutex);
- idkp = ide_drv_g(disk, ide_floppy_obj);
- if (idkp) {
- if (ide_device_get(idkp->drive))
- idkp = NULL;
- else
- kref_get(&idkp->kref);
- }
- mutex_unlock(&ide_disk_ref_mutex);
- return idkp;
-}
-
-static void ide_disk_put(struct ide_floppy_obj *idkp)
-{
- ide_drive_t *drive = idkp->drive;
-
- mutex_lock(&ide_disk_ref_mutex);
- kref_put(&idkp->kref, ide_disk_release);
- ide_device_put(drive);
- mutex_unlock(&ide_disk_ref_mutex);
-}
-
-sector_t ide_gd_capacity(ide_drive_t *drive)
-{
- return drive->capacity64;
-}
-
-static int ide_gd_probe(ide_drive_t *);
-
-static void ide_gd_remove(ide_drive_t *drive)
-{
- struct ide_floppy_obj *idkp = drive->driver_data;
- struct gendisk *g = idkp->disk;
-
- ide_proc_unregister_driver(drive, idkp->driver);
-
- del_gendisk(g);
-
- ide_disk_put(idkp);
-}
-
-static void ide_disk_release(struct kref *kref)
-{
- struct ide_floppy_obj *idkp = to_ide_drv(kref, ide_floppy_obj);
- ide_drive_t *drive = idkp->drive;
- struct gendisk *g = idkp->disk;
-
- drive->driver_data = NULL;
- g->private_data = NULL;
- put_disk(g);
- kfree(idkp);
-}
-
-#ifdef CONFIG_IDE_PROC_FS
-static ide_proc_entry_t *ide_floppy_proc_entries(ide_drive_t *drive)
-{
- return ide_floppy_proc;
-}
-
-static const struct ide_proc_devset *ide_floppy_proc_devsets(ide_drive_t *drive)
-{
- return ide_floppy_settings;
-}
-#endif
-
-static ide_driver_t ide_gd_driver = {
- .gen_driver = {
- .owner = THIS_MODULE,
- .name = "ide-floppy",
- .bus = &ide_bus_type,
- },
- .probe = ide_gd_probe,
- .remove = ide_gd_remove,
- .version = IDEFLOPPY_VERSION,
- .do_request = ide_floppy_do_request,
- .end_request = ide_floppy_end_request,
- .error = __ide_error,
-#ifdef CONFIG_IDE_PROC_FS
- .proc_entries = ide_floppy_proc_entries,
- .proc_devsets = ide_floppy_proc_devsets,
-#endif
-};
-
-static int ide_gd_open(struct inode *inode, struct file *filp)
-{
- struct gendisk *disk = inode->i_bdev->bd_disk;
- struct ide_floppy_obj *idkp;
- ide_drive_t *drive;
- int ret = 0;
-
- idkp = ide_disk_get(disk);
- if (idkp == NULL)
- return -ENXIO;
-
- drive = idkp->drive;
-
- ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
-
- idkp->openers++;
-
- if (idkp->openers == 1) {
- drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
- /* Just in case */
-
- if (ide_do_test_unit_ready(drive, disk))
- ide_do_start_stop(drive, disk, 1);
-
- ret = ide_floppy_get_capacity(drive);
-
- set_capacity(disk, ide_gd_capacity(drive));
-
- if (ret && (filp->f_flags & O_NDELAY) == 0) {
- /*
- * Allow O_NDELAY to open a drive without a disk, or with an
- * unreadable disk, so that we can get the format capacity
- * of the drive or begin the format - Sam
- */
- ret = -EIO;
- goto out_put_idkp;
- }
-
- if ((drive->dev_flags & IDE_DFLAG_WP) && (filp->f_mode & 2)) {
- ret = -EROFS;
- goto out_put_idkp;
- }
-
- ide_set_media_lock(drive, disk, 1);
- drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
- check_disk_change(inode->i_bdev);
- } else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) {
- ret = -EBUSY;
- goto out_put_idkp;
- }
- return 0;
-
-out_put_idkp:
- idkp->openers--;
- ide_disk_put(idkp);
- return ret;
-}
-
-static int ide_gd_release(struct inode *inode, struct file *filp)
-{
- struct gendisk *disk = inode->i_bdev->bd_disk;
- struct ide_floppy_obj *idkp = ide_drv_g(disk, ide_floppy_obj);
- ide_drive_t *drive = idkp->drive;
-
- ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
-
- if (idkp->openers == 1) {
- ide_set_media_lock(drive, disk, 0);
- drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
- }
-
- idkp->openers--;
-
- ide_disk_put(idkp);
-
- return 0;
-}
-
-static int ide_gd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
-{
- struct ide_floppy_obj *idkp = ide_drv_g(bdev->bd_disk, ide_floppy_obj);
- ide_drive_t *drive = idkp->drive;
-
- geo->heads = drive->bios_head;
- geo->sectors = drive->bios_sect;
- geo->cylinders = (u16)drive->bios_cyl; /* truncate */
- return 0;
-}
-
-static int ide_gd_media_changed(struct gendisk *disk)
-{
- struct ide_floppy_obj *idkp = ide_drv_g(disk, ide_floppy_obj);
- ide_drive_t *drive = idkp->drive;
- int ret;
-
- /* do not scan partitions twice if this is a removable device */
- if (drive->dev_flags & IDE_DFLAG_ATTACH) {
- drive->dev_flags &= ~IDE_DFLAG_ATTACH;
- return 0;
- }
-
- ret = !!(drive->dev_flags & IDE_DFLAG_MEDIA_CHANGED);
- drive->dev_flags &= ~IDE_DFLAG_MEDIA_CHANGED;
-
- return ret;
-}
-
-static int ide_gd_revalidate_disk(struct gendisk *disk)
-{
- struct ide_floppy_obj *idkp = ide_drv_g(disk, ide_floppy_obj);
- set_capacity(disk, ide_gd_capacity(idkp->drive));
- return 0;
-}
-
-static struct block_device_operations ide_gd_ops = {
- .owner = THIS_MODULE,
- .open = ide_gd_open,
- .release = ide_gd_release,
- .ioctl = ide_floppy_ioctl,
- .getgeo = ide_gd_getgeo,
- .media_changed = ide_gd_media_changed,
- .revalidate_disk = ide_gd_revalidate_disk
-};
-
-static int ide_gd_probe(ide_drive_t *drive)
-{
- struct ide_floppy_obj *idkp;
- struct gendisk *g;
-
- if (!strstr("ide-floppy", drive->driver_req))
- goto failed;
-
- if (drive->media != ide_floppy)
- goto failed;
-
- if (!ide_check_atapi_device(drive, DRV_NAME)) {
- printk(KERN_ERR PFX "%s: not supported by this version of "
- DRV_NAME "\n", drive->name);
- goto failed;
- }
- idkp = kzalloc(sizeof(*idkp), GFP_KERNEL);
- if (!idkp) {
- printk(KERN_ERR PFX "%s: Can't allocate a floppy structure\n",
- drive->name);
- goto failed;
- }
-
- g = alloc_disk_node(1 << PARTN_BITS, hwif_to_node(drive->hwif));
- if (!g)
- goto out_free_idkp;
-
- ide_init_disk(g, drive);
-
- kref_init(&idkp->kref);
-
- idkp->drive = drive;
- idkp->driver = &ide_gd_driver;
- idkp->disk = g;
-
- g->private_data = &idkp->driver;
-
- drive->driver_data = idkp;
-
- drive->debug_mask = debug_mask;
-
- ide_floppy_setup(drive);
-
- set_capacity(g, ide_gd_capacity(drive));
-
- g->minors = 1 << PARTN_BITS;
- g->driverfs_dev = &drive->gendev;
- if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
- g->flags = GENHD_FL_REMOVABLE;
- g->fops = &ide_gd_ops;
- add_disk(g);
- return 0;
-
-out_free_idkp:
- kfree(idkp);
-failed:
- return -ENODEV;
-}
-
-static int __init ide_gd_init(void)
-{
- printk(KERN_INFO DRV_NAME " driver " IDEFLOPPY_VERSION "\n");
- return driver_register(&ide_gd_driver.gen_driver);
-}
-
-static void __exit ide_gd_exit(void)
-{
- driver_unregister(&ide_gd_driver.gen_driver);
-}
-
-MODULE_ALIAS("ide:*m-floppy*");
-MODULE_ALIAS("ide-floppy");
-module_init(ide_gd_init);
-module_exit(ide_gd_exit);
-MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
Index: b/drivers/ide/ide-gd.c
===================================================================
--- a/drivers/ide/ide-gd.c
+++ b/drivers/ide/ide-gd.c
@@ -9,9 +9,14 @@
#include <linux/hdreg.h>
#include "ide-disk.h"
+#include "ide-floppy.h"
#define IDE_GD_VERSION "1.18"
+/* module parameters */
+static unsigned long debug_mask;
+module_param(debug_mask, ulong, 0644);
+
static DEFINE_MUTEX(ide_disk_ref_mutex);
static void ide_disk_release(struct kref *);
@@ -58,7 +63,7 @@ static void ide_gd_remove(ide_drive_t *d
del_gendisk(g);
- ide_disk_flush(drive);
+ drive->disk_ops->flush(drive);
ide_disk_put(idkp);
}
@@ -69,6 +74,7 @@ static void ide_disk_release(struct kref
ide_drive_t *drive = idkp->drive;
struct gendisk *g = idkp->disk;
+ drive->disk_ops = NULL;
drive->driver_data = NULL;
g->private_data = NULL;
put_disk(g);
@@ -83,7 +89,7 @@ static void ide_disk_release(struct kref
static void ide_gd_resume(ide_drive_t *drive)
{
if (ata_id_hpa_enabled(drive->id))
- ide_disk_init_capacity(drive);
+ (void)drive->disk_ops->get_capacity(drive);
}
static void ide_gd_shutdown(ide_drive_t *drive)
@@ -104,7 +110,7 @@ static void ide_gd_shutdown(ide_drive_t
#else
if (system_state == SYSTEM_RESTART) {
#endif
- ide_disk_flush(drive);
+ drive->disk_ops->flush(drive);
return;
}
@@ -116,19 +122,31 @@ static void ide_gd_shutdown(ide_drive_t
#ifdef CONFIG_IDE_PROC_FS
static ide_proc_entry_t *ide_disk_proc_entries(ide_drive_t *drive)
{
- return ide_disk_proc;
+ return (drive->media == ide_disk) ? ide_disk_proc : ide_floppy_proc;
}
static const struct ide_proc_devset *ide_disk_proc_devsets(ide_drive_t *drive)
{
- return ide_disk_settings;
+ return (drive->media == ide_disk) ? ide_disk_settings
+ : ide_floppy_settings;
}
#endif
+static ide_startstop_t ide_gd_do_request(ide_drive_t *drive,
+ struct request *rq, sector_t sector)
+{
+ return drive->disk_ops->do_request(drive, rq, sector);
+}
+
+static int ide_gd_end_request(ide_drive_t *drive, int uptodate, int nrsecs)
+{
+ return drive->disk_ops->end_request(drive, uptodate, nrsecs);
+}
+
static ide_driver_t ide_gd_driver = {
.gen_driver = {
.owner = THIS_MODULE,
- .name = "ide-disk",
+ .name = "ide-gd",
.bus = &ide_bus_type,
},
.probe = ide_gd_probe,
@@ -136,8 +154,8 @@ static ide_driver_t ide_gd_driver = {
.resume = ide_gd_resume,
.shutdown = ide_gd_shutdown,
.version = IDE_GD_VERSION,
- .do_request = ide_do_rw_disk,
- .end_request = ide_end_request,
+ .do_request = ide_gd_do_request,
+ .end_request = ide_gd_end_request,
.error = __ide_error,
#ifdef CONFIG_IDE_PROC_FS
.proc_entries = ide_disk_proc_entries,
@@ -150,6 +168,7 @@ static int ide_gd_open(struct inode *ino
struct gendisk *disk = inode->i_bdev->bd_disk;
struct ide_disk_obj *idkp;
ide_drive_t *drive;
+ int ret = 0;
idkp = ide_disk_get(disk);
if (idkp == NULL)
@@ -157,19 +176,49 @@ static int ide_gd_open(struct inode *ino
drive = idkp->drive;
+ ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
idkp->openers++;
if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
+ drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
+ /* Just in case */
+
+ ret = drive->disk_ops->init_media(drive, disk);
+
+ /*
+ * Allow O_NDELAY to open a drive without a disk, or with an
+ * unreadable disk, so that we can get the format capacity
+ * of the drive or begin the format - Sam
+ */
+ if (ret && (filp->f_flags & O_NDELAY) == 0) {
+ ret = -EIO;
+ goto out_put_idkp;
+ }
+
+ if ((drive->dev_flags & IDE_DFLAG_WP) && (filp->f_mode & 2)) {
+ ret = -EROFS;
+ goto out_put_idkp;
+ }
+
/*
* Ignore the return code from door_lock,
* since the open() has already succeeded,
* and the door_lock is irrelevant at this point.
*/
- ide_disk_set_doorlock(drive, 1);
+ drive->disk_ops->set_doorlock(drive, disk, 1);
drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
check_disk_change(inode->i_bdev);
+ } else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) {
+ ret = -EBUSY;
+ goto out_put_idkp;
}
return 0;
+
+out_put_idkp:
+ idkp->openers--;
+ ide_disk_put(idkp);
+ return ret;
}
static int ide_gd_release(struct inode *inode, struct file *filp)
@@ -178,11 +227,15 @@ static int ide_gd_release(struct inode *
struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
ide_drive_t *drive = idkp->drive;
+ ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
if (idkp->openers == 1)
- ide_disk_flush(drive);
+ drive->disk_ops->flush(drive);
- if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1)
- ide_disk_set_doorlock(drive, 0);
+ if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
+ drive->disk_ops->set_doorlock(drive, disk, 0);
+ drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
+ }
idkp->openers--;
@@ -227,11 +280,21 @@ static int ide_gd_revalidate_disk(struct
return 0;
}
+static int ide_gd_ioctl(struct inode *inode, struct file *file,
+ unsigned int cmd, unsigned long arg)
+{
+ struct block_device *bdev = inode->i_bdev;
+ struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
+ ide_drive_t *drive = idkp->drive;
+
+ return drive->disk_ops->ioctl(drive, inode, file, cmd, arg);
+}
+
static struct block_device_operations ide_gd_ops = {
.owner = THIS_MODULE,
.open = ide_gd_open,
.release = ide_gd_release,
- .ioctl = ide_disk_ioctl,
+ .ioctl = ide_gd_ioctl,
.getgeo = ide_gd_getgeo,
.media_changed = ide_gd_media_changed,
.revalidate_disk = ide_gd_revalidate_disk
@@ -239,19 +302,37 @@ static struct block_device_operations id
static int ide_gd_probe(ide_drive_t *drive)
{
+ const struct ide_disk_ops *disk_ops = NULL;
struct ide_disk_obj *idkp;
struct gendisk *g;
/* strstr("foo", "") is non-NULL */
- if (!strstr("ide-disk", drive->driver_req))
+ if (!strstr("ide-gd", drive->driver_req))
goto failed;
- if (drive->media != ide_disk)
+#ifdef CONFIG_IDE_GD_ATA
+ if (drive->media == ide_disk)
+ disk_ops = &ide_ata_disk_ops;
+#endif
+#ifdef CONFIG_IDE_GD_ATAPI
+ if (drive->media == ide_floppy)
+ disk_ops = &ide_atapi_disk_ops;
+#endif
+ if (disk_ops == NULL)
+ goto failed;
+
+ if (disk_ops->check(drive, DRV_NAME) == 0) {
+ printk(KERN_ERR PFX "%s: not supported by this driver\n",
+ drive->name);
goto failed;
+ }
idkp = kzalloc(sizeof(*idkp), GFP_KERNEL);
- if (!idkp)
+ if (!idkp) {
+ printk(KERN_ERR PFX "%s: can't allocate a disk structure\n",
+ drive->name);
goto failed;
+ }
g = alloc_disk_node(1 << PARTN_BITS, hwif_to_node(drive->hwif));
if (!g)
@@ -269,7 +350,11 @@ static int ide_gd_probe(ide_drive_t *dri
drive->driver_data = idkp;
- ide_disk_setup(drive);
+ drive->debug_mask = debug_mask;
+
+ drive->disk_ops = disk_ops;
+
+ disk_ops->setup(drive);
set_capacity(g, ide_gd_capacity(drive));
@@ -289,6 +374,7 @@ failed:
static int __init ide_gd_init(void)
{
+ printk(KERN_INFO DRV_NAME " driver " IDE_GD_VERSION "\n");
return driver_register(&ide_gd_driver.gen_driver);
}
@@ -299,7 +385,9 @@ static void __exit ide_gd_exit(void)
MODULE_ALIAS("ide:*m-disk*");
MODULE_ALIAS("ide-disk");
+MODULE_ALIAS("ide:*m-floppy*");
+MODULE_ALIAS("ide-floppy");
module_init(ide_gd_init);
module_exit(ide_gd_exit);
MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("ATA DISK Driver");
+MODULE_DESCRIPTION("generic ATA/ATAPI disk driver");
Index: b/drivers/ide/ide-gd.h
===================================================================
--- /dev/null
+++ b/drivers/ide/ide-gd.h
@@ -0,0 +1,44 @@
+#ifndef __IDE_GD_H
+#define __IDE_GD_H
+
+#define DRV_NAME "ide-gd"
+#define PFX DRV_NAME ": "
+
+/* define to see debug info */
+#define IDE_GD_DEBUG_LOG 0
+
+#if IDE_GD_DEBUG_LOG
+#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, args)
+#else
+#define ide_debug_log(lvl, fmt, args...) do {} while (0)
+#endif
+
+struct ide_disk_obj {
+ ide_drive_t *drive;
+ ide_driver_t *driver;
+ struct gendisk *disk;
+ struct kref kref;
+ unsigned int openers; /* protected by BKL for now */
+
+ /* Last failed packet command */
+ struct ide_atapi_pc *failed_pc;
+ /* used for blk_{fs,pc}_request() requests */
+ struct ide_atapi_pc queued_pc;
+
+ /* Last error information */
+ u8 sense_key, asc, ascq;
+
+ int progress_indication;
+
+ /* Device information */
+ /* Current format */
+ int blocks, block_size, bs_factor;
+ /* Last format capacity descriptor */
+ u8 cap_desc[8];
+ /* Copy of the flexible disk page */
+ u8 flexible_disk_page[32];
+};
+
+sector_t ide_gd_capacity(ide_drive_t *);
+
+#endif /* __IDE_GD_H */
Index: b/drivers/leds/Kconfig
===================================================================
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -185,7 +185,7 @@ config LEDS_TRIGGER_TIMER
config LEDS_TRIGGER_IDE_DISK
bool "LED IDE Disk Trigger"
- depends on LEDS_TRIGGERS && BLK_DEV_IDEDISK
+ depends on LEDS_TRIGGERS && IDE_GD_ATA
help
This allows LEDs to be controlled by IDE disk activity.
If unsure, say Y.
Index: b/include/linux/ide.h
===================================================================
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -459,6 +459,23 @@ struct ide_acpi_drive_link;
struct ide_acpi_hwif_link;
#endif
+struct ide_drive_s;
+
+struct ide_disk_ops {
+ int (*check)(struct ide_drive_s *, const char *);
+ int (*get_capacity)(struct ide_drive_s *);
+ void (*setup)(struct ide_drive_s *);
+ void (*flush)(struct ide_drive_s *);
+ int (*init_media)(struct ide_drive_s *, struct gendisk *);
+ int (*set_doorlock)(struct ide_drive_s *, struct gendisk *,
+ int);
+ ide_startstop_t (*do_request)(struct ide_drive_s *, struct request *,
+ sector_t);
+ int (*end_request)(struct ide_drive_s *, int, int);
+ int (*ioctl)(struct ide_drive_s *, struct inode *,
+ struct file *, unsigned int, unsigned long);
+};
+
/* ATAPI device flags */
enum {
IDE_AFLAG_DRQ_INTERRUPT = (1 << 0),
@@ -586,6 +603,8 @@ struct ide_drive_s {
#endif
struct hwif_s *hwif; /* actually (ide_hwif_t *) */
+ const struct ide_disk_ops *disk_ops;
+
unsigned long dev_flags;
unsigned long sleep; /* sleep until this time */
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 08/18] ide-floppy: use drive->capacity64 for caching current capacity
2008-09-07 22:15 ` [PATCH 08/18] ide-floppy: use drive->capacity64 for caching current capacity Bartlomiej Zolnierkiewicz
@ 2008-09-10 11:20 ` Borislav Petkov
2008-09-27 15:34 ` Bartlomiej Zolnierkiewicz
0 siblings, 1 reply; 22+ messages in thread
From: Borislav Petkov @ 2008-09-10 11:20 UTC (permalink / raw)
To: Bartlomiej Zolnierkiewicz; +Cc: linux-ide, linux-kernel
Hi,
On Mon, Sep 08, 2008 at 12:15:19AM +0200, Bartlomiej Zolnierkiewicz wrote:
> * Use drive->capacity64 for caching current capacity.
>
> * Switch ide_floppy_capacity() to use drive->capacity64.
>
> * Call set_capacity() in idefloppy_open() and ide_floppy_probe()
> instead of ide_floppy_get_capacity().
>
> There should be no functional changes caused by this patch.
>
> Cc: Borislav Petkov <petkovbb@gmail.com>
> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
> ---
> drivers/ide/ide-floppy.c | 23 +++++++++++++----------
> 1 file changed, 13 insertions(+), 10 deletions(-)
>
> Index: b/drivers/ide/ide-floppy.c
> ===================================================================
> --- a/drivers/ide/ide-floppy.c
> +++ b/drivers/ide/ide-floppy.c
> @@ -445,7 +445,9 @@ static int ide_floppy_get_flexible_disk_
> drive->name, lba_capacity, capacity);
> floppy->blocks = floppy->block_size ?
> capacity / floppy->block_size : 0;
> + drive->capacity64 = floppy->blocks * floppy->bs_factor;
why do we do the assignment only in the capacity < lba_capacity case?
drive->capacity64 is the total number of sectors, shouldn't we do
drive->capacity64 = floppy->blocks;
in the floppy->bs_factor == 1 case? Otherwise you have the case of calling
idefloppy_setup()
|-> ide_floppy_get_capacity()
|-> ide_floppy_get_flexible_disk_page()
and having drive->capacity64 == 0 in the (capacity >= lba_capacity) case which
assigns a capacity of 0 to disk->capacity in the set_capacity() call later ...
or am I missing something?
> }
> +
> return 0;
> }
>
> @@ -466,7 +468,7 @@ static int ide_floppy_get_capacity(ide_d
> drive->bios_head = drive->bios_sect = 0;
> floppy->blocks = 0;
> floppy->bs_factor = 1;
> - set_capacity(floppy->disk, 0);
> + drive->capacity64 = 0;
>
> ide_floppy_create_read_capacity_cmd(&pc);
> if (ide_queue_pc_tail(drive, disk, &pc)) {
> @@ -523,6 +525,8 @@ static int ide_floppy_get_capacity(ide_d
> "non 512 bytes block size not "
> "fully supported\n",
> drive->name);
> + drive->capacity64 =
> + floppy->blocks * floppy->bs_factor;
> rc = 0;
> }
> break;
> @@ -547,17 +551,12 @@ static int ide_floppy_get_capacity(ide_d
> if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
> (void) ide_floppy_get_flexible_disk_page(drive);
>
> - set_capacity(disk, floppy->blocks * floppy->bs_factor);
> -
> return rc;
> }
>
> sector_t ide_floppy_capacity(ide_drive_t *drive)
> {
> - idefloppy_floppy_t *floppy = drive->driver_data;
> - unsigned long capacity = floppy->blocks * floppy->bs_factor;
> -
> - return capacity;
> + return drive->capacity64;
you can simplify this one even further by killing ide_floppy_capacity() and
doing
set_capacity(disk, floppy->drive->capacity64);
in idefloppy_revalidate_disk().
> }
>
> static void idefloppy_setup(ide_drive_t *drive)
> @@ -671,14 +670,16 @@ static int idefloppy_open(struct inode *
> if (ide_do_test_unit_ready(drive, disk))
> ide_do_start_stop(drive, disk, 1);
>
> - if (ide_floppy_get_capacity(drive)
> - && (filp->f_flags & O_NDELAY) == 0
> + ret = ide_floppy_get_capacity(drive);
> +
> + set_capacity(disk, ide_floppy_capacity(drive));
ditto.
> +
> + if (ret && (filp->f_flags & O_NDELAY) == 0) {
> /*
> * Allow O_NDELAY to open a drive without a disk, or with an
> * unreadable disk, so that we can get the format capacity
> * of the drive or begin the format - Sam
> */
> - ) {
> ret = -EIO;
> goto out_put_floppy;
> }
> @@ -811,6 +812,8 @@ static int ide_floppy_probe(ide_drive_t
>
> idefloppy_setup(drive);
>
> + set_capacity(g, ide_floppy_capacity(drive));
ditto.
> +
> g->minors = 1 << PARTN_BITS;
> g->driverfs_dev = &drive->gendev;
> if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
--
Regards/Gruss,
Boris.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 00/18] ide: add generic ATA/ATAPI disk driver
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
` (17 preceding siblings ...)
2008-09-07 22:16 ` [PATCH 18/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
@ 2008-09-10 11:20 ` Borislav Petkov
18 siblings, 0 replies; 22+ messages in thread
From: Borislav Petkov @ 2008-09-10 11:20 UTC (permalink / raw)
To: Bartlomiej Zolnierkiewicz; +Cc: linux-ide, linux-kernel
On Mon, Sep 08, 2008 at 12:14:24AM +0200, Bartlomiej Zolnierkiewicz wrote:
>
> [ Borislav, this is the 'futuristic' stuff that we were talking about. :) ]
>
> Hi,
>
> This patch series adds a generic ATA/ATAPI disk driver (ide-gd) replacing
> ide-disk and ide-floppy drivers. It is achieved by moving the common code
> to ide-gd.c, adding struct ide_disk_ops (which is used to abstract protocol
> specific details) and updating ide-{disk,floppy}.c accordingly.
>
> The main goal is to make the code more maintainable / easier to extend later.
> As an immediate result we get driver specific debugging support for ATA disks
> and ability for driver specific Power Management for ATAPI devices. Otherwise
> it is really an initial merge (which means that in the future the code can be
> further unified, struct ide_disk_ops can be made more fine-grained etc.).
Looks cool, ACK with some comments/questions in separate mail. Will test on my
Iomega ZIP drive when I get back.
--
Regards/Gruss,
Boris.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 08/18] ide-floppy: use drive->capacity64 for caching current capacity
2008-09-10 11:20 ` Borislav Petkov
@ 2008-09-27 15:34 ` Bartlomiej Zolnierkiewicz
0 siblings, 0 replies; 22+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2008-09-27 15:34 UTC (permalink / raw)
To: petkovbb; +Cc: linux-ide, linux-kernel
Hi,
On Wednesday 10 September 2008, Borislav Petkov wrote:
> Hi,
>
> On Mon, Sep 08, 2008 at 12:15:19AM +0200, Bartlomiej Zolnierkiewicz wrote:
> > * Use drive->capacity64 for caching current capacity.
> >
> > * Switch ide_floppy_capacity() to use drive->capacity64.
> >
> > * Call set_capacity() in idefloppy_open() and ide_floppy_probe()
> > instead of ide_floppy_get_capacity().
> >
> > There should be no functional changes caused by this patch.
> >
> > Cc: Borislav Petkov <petkovbb@gmail.com>
> > Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
> > ---
> > drivers/ide/ide-floppy.c | 23 +++++++++++++----------
> > 1 file changed, 13 insertions(+), 10 deletions(-)
> >
> > Index: b/drivers/ide/ide-floppy.c
> > ===================================================================
> > --- a/drivers/ide/ide-floppy.c
> > +++ b/drivers/ide/ide-floppy.c
> > @@ -445,7 +445,9 @@ static int ide_floppy_get_flexible_disk_
> > drive->name, lba_capacity, capacity);
> > floppy->blocks = floppy->block_size ?
> > capacity / floppy->block_size : 0;
> > + drive->capacity64 = floppy->blocks * floppy->bs_factor;
>
> why do we do the assignment only in the capacity < lba_capacity case?
> drive->capacity64 is the total number of sectors, shouldn't we do
>
> drive->capacity64 = floppy->blocks;
>
> in the floppy->bs_factor == 1 case? Otherwise you have the case of calling
Probably we should...
> idefloppy_setup()
> |-> ide_floppy_get_capacity()
> |-> ide_floppy_get_flexible_disk_page()
>
> and having drive->capacity64 == 0 in the (capacity >= lba_capacity) case which
> assigns a capacity of 0 to disk->capacity in the set_capacity() call later ...
>
> or am I missing something?
...my patch just modified the code to also set ->capacity64 in places
which previously were modifying ->blocks and/or ->bs_factor (since
->capacity64 replaced open-coded ->blocks * ->bs_factor calculation),
so I think that the above problem is as an orthogonal issue and it
is the best to address it in separate pre- or post- patch (could you
please take care of it?).
[...]
> > @@ -547,17 +551,12 @@ static int ide_floppy_get_capacity(ide_d
> > if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
> > (void) ide_floppy_get_flexible_disk_page(drive);
> >
> > - set_capacity(disk, floppy->blocks * floppy->bs_factor);
> > -
> > return rc;
> > }
> >
> > sector_t ide_floppy_capacity(ide_drive_t *drive)
> > {
> > - idefloppy_floppy_t *floppy = drive->driver_data;
> > - unsigned long capacity = floppy->blocks * floppy->bs_factor;
> > -
> > - return capacity;
> > + return drive->capacity64;
>
> you can simplify this one even further by killing ide_floppy_capacity() and
> doing
>
> set_capacity(disk, floppy->drive->capacity64);
I did it ide_floppy_capacity()-way to match ide_disk_capacity()
and ease the merge (probably ide_gd_capacity() can be removed now).
Thanks,
Bart
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2008-09-27 17:28 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-07 22:14 [PATCH 00/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
2008-09-07 22:14 ` [PATCH 01/18] ide-disk: fix IDE_DFLAG_LBA48 handling on resume Bartlomiej Zolnierkiewicz
2008-09-07 22:14 ` [PATCH 02/18] ide-disk: lock media before checking for media change Bartlomiej Zolnierkiewicz
2008-09-07 22:14 ` [PATCH 03/18] ide-floppy: use alloc_disk_node() Bartlomiej Zolnierkiewicz
2008-09-07 22:14 ` [PATCH 04/18] ide-disk: use to_ide_drv() and ide_drv_g() Bartlomiej Zolnierkiewicz
2008-09-07 22:14 ` [PATCH 05/18] ide-disk: move IDE_DFLAG_DOORLOCKING flag handling to idedisk_set_doorlock() Bartlomiej Zolnierkiewicz
2008-09-07 22:15 ` [PATCH 06/18] ide-{disk,floppy}: set IDE_DFLAG_ATTACH in *_setup() Bartlomiej Zolnierkiewicz
2008-09-07 22:15 ` [PATCH 07/18] ide-floppy: drop 'floppy' argument from idefloppy_setup() Bartlomiej Zolnierkiewicz
2008-09-07 22:15 ` [PATCH 08/18] ide-floppy: use drive->capacity64 for caching current capacity Bartlomiej Zolnierkiewicz
2008-09-10 11:20 ` Borislav Petkov
2008-09-27 15:34 ` Bartlomiej Zolnierkiewicz
2008-09-07 22:15 ` [PATCH 09/18] ide: IDE_AFLAG_MEDIA_CHANGED -> IDE_DFLAG_MEDIA_CHANGED Bartlomiej Zolnierkiewicz
2008-09-07 22:15 ` [PATCH 10/18] ide: IDE_AFLAG_WP -> IDE_DFLAG_WP Bartlomiej Zolnierkiewicz
2008-09-07 22:15 ` [PATCH 11/18] ide: IDE_AFLAG_FORMAT_IN_PROGRESS -> IDE_DFLAG_FORMAT_IN_PROGRESS Bartlomiej Zolnierkiewicz
2008-09-07 22:15 ` [PATCH 12/18] ide: remove IDE_AFLAG_NO_DOORLOCKING Bartlomiej Zolnierkiewicz
2008-09-07 22:15 ` [PATCH 13/18] ide-disk: factor out generic disk handling code to ide-gd.c Bartlomiej Zolnierkiewicz
2008-09-07 22:16 ` [PATCH 14/18] ide-disk: use IDE_DFLAG_MEDIA_CHANGED Bartlomiej Zolnierkiewicz
2008-09-07 22:16 ` [PATCH 15/18] ide-floppy: factor out generic disk handling code to ide-gd-floppy.c Bartlomiej Zolnierkiewicz
2008-09-07 22:16 ` [PATCH 16/18] ide: prepare for merging ide-gd-floppy.c with ide-gd.c Bartlomiej Zolnierkiewicz
2008-09-07 22:16 ` [PATCH 17/18] ide: allow device drivers to specify per-device type /proc settings Bartlomiej Zolnierkiewicz
2008-09-07 22:16 ` [PATCH 18/18] ide: add generic ATA/ATAPI disk driver Bartlomiej Zolnierkiewicz
2008-09-10 11:20 ` [PATCH 00/18] " Borislav Petkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).