Skip to content

Commit 48fb268

Browse files
committed
ide: remove drive->driveid
* Factor out HDIO_[OBSOLETE,GET]_IDENTITY ioctls handling to ide_get_identity_ioctl(). * Use temporary buffer in ide_get_identity_ioctl() instead of accessing drive->id directly. * Add ide_id_to_hd_driveid() inline to convert raw id into struct hd_driveid format (needed on big-endian). * Use ide_id_to_hd_driveid() in ide_get_identity_ioctl(), cleanup ide_fix_driveid() and switch ide to use use raw id. * Remove no longer needed drive->driveid. This leaves us with 3 users of struct hd_driveid in tree: - arch/um/drivers/ubd_kern.c - drivers/block/xsysace.c - drivers/usb/storage/isd200.c While at it: * Use ata_id_u{32,64}() and ata_id_has_{dma,lba,iordy}() macros. There should be no functional changes caused by this patch. Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
1 parent 4dde449 commit 48fb268

13 files changed

Lines changed: 90 additions & 69 deletions

File tree

‎drivers/ide/ide-disk.c‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,14 @@ static void ide_disk_put(struct ide_disk_obj *idkp)
101101
*/
102102
static int lba_capacity_is_ok(u16 *id)
103103
{
104-
struct hd_driveid *driveid = (struct hd_driveid *)id;
105104
unsigned long lba_sects, chs_sects, head, tail;
106105

107106
/* No non-LBA info .. so valid! */
108107
if (id[ATA_ID_CYLS] == 0)
109108
return 1;
110109

110+
lba_sects = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
111+
111112
/*
112113
* The ATA spec tells large drives to return
113114
* C/H/S = 16383/16/63 independent of their size.
@@ -118,10 +119,9 @@ static int lba_capacity_is_ok(u16 *id)
118119
(id[ATA_ID_CYLS] == 4092 && id[ATA_ID_CUR_CYLS] == 16383)) &&
119120
id[ATA_ID_SECTORS] == 63 &&
120121
(id[ATA_ID_HEADS] == 15 || id[ATA_ID_HEADS] == 16) &&
121-
(driveid->lba_capacity >= 16383 * 63 * id[ATA_ID_HEADS]))
122+
(lba_sects >= 16383 * 63 * id[ATA_ID_HEADS]))
122123
return 1;
123124

124-
lba_sects = driveid->lba_capacity;
125125
chs_sects = id[ATA_ID_CYLS] * id[ATA_ID_HEADS] * id[ATA_ID_SECTORS];
126126

127127
/* perform a rough sanity check on lba_sects: within 10% is OK */
@@ -133,7 +133,7 @@ static int lba_capacity_is_ok(u16 *id)
133133
tail = (lba_sects & 0xffff);
134134
lba_sects = (head | (tail << 16));
135135
if ((lba_sects - chs_sects) < chs_sects/10) {
136-
driveid->lba_capacity = lba_sects;
136+
*(__le32 *)&id[ATA_ID_LBA_CAPACITY] = __cpu_to_le32(lba_sects);
137137
return 1; /* lba_capacity is (now) good */
138138
}
139139

@@ -403,7 +403,7 @@ static inline int idedisk_supports_lba48(const u16 *id)
403403
{
404404
return (id[ATA_ID_COMMAND_SET_2] & 0x0400) &&
405405
(id[ATA_ID_CFS_ENABLE_2] & 0x0400) &&
406-
((struct hd_driveid *)id)->lba_capacity_2;
406+
ata_id_u64(id, ATA_ID_LBA_CAPACITY_2);
407407
}
408408

409409
/*
@@ -456,7 +456,6 @@ static void idedisk_check_hpa(ide_drive_t *drive)
456456

457457
static void init_idedisk_capacity(ide_drive_t *drive)
458458
{
459-
struct hd_driveid *driveid = drive->driveid;
460459
u16 *id = drive->id;
461460
/*
462461
* If this drive supports the Host Protected Area feature set,
@@ -467,13 +466,13 @@ static void init_idedisk_capacity(ide_drive_t *drive)
467466
if (idedisk_supports_lba48(id)) {
468467
/* drive speaks 48-bit LBA */
469468
drive->select.b.lba = 1;
470-
drive->capacity64 = driveid->lba_capacity_2;
469+
drive->capacity64 = ata_id_u64(id, ATA_ID_LBA_CAPACITY_2);
471470
if (hpa)
472471
idedisk_check_hpa(drive);
473-
} else if ((driveid->capability & 2) && lba_capacity_is_ok(id)) {
472+
} else if (ata_id_has_lba(id) && lba_capacity_is_ok(id)) {
474473
/* drive speaks 28-bit LBA */
475474
drive->select.b.lba = 1;
476-
drive->capacity64 = driveid->lba_capacity;
475+
drive->capacity64 = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
477476
if (hpa)
478477
idedisk_check_hpa(drive);
479478
} else {
@@ -622,7 +621,7 @@ static int set_multcount(ide_drive_t *drive, int arg)
622621
struct request *rq;
623622
int error;
624623

625-
if (arg < 0 || arg > drive->driveid->max_multsect)
624+
if (arg < 0 || arg > (drive->id[ATA_ID_MAX_MULTSECT] & 0xff))
626625
return -EINVAL;
627626

628627
if (drive->special.b.set_multmode)
@@ -775,8 +774,8 @@ static void idedisk_add_settings(ide_drive_t *drive)
775774
ide_add_setting(drive, "address", SETTING_RW, TYPE_BYTE, 0, 2, 1, 1,
776775
&drive->addressing, set_lba_addressing);
777776
ide_add_setting(drive, "multcount", SETTING_RW, TYPE_BYTE, 0,
778-
drive->driveid->max_multsect, 1, 1, &drive->mult_count,
779-
set_multcount);
777+
drive->id[ATA_ID_MAX_MULTSECT] & 0xff, 1, 1,
778+
&drive->mult_count, set_multcount);
780779
ide_add_setting(drive, "nowerr", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1,
781780
&drive->nowerr, set_nowerr);
782781
ide_add_setting(drive, "lun", SETTING_RW, TYPE_INT, 0, 7, 1, 1,

‎drivers/ide/ide-dma.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,8 @@ static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base, u8 req_mode)
649649
case XFER_SW_DMA_0:
650650
if (id[ATA_ID_FIELD_VALID] & 2) {
651651
mask = id[ATA_ID_SWDMA_MODES] & hwif->swdma_mask;
652-
} else if (drive->driveid->tDMA) {
653-
u8 mode = drive->driveid->tDMA;
652+
} else if (id[ATA_ID_OLD_DMA_MODES] >> 8) {
653+
u8 mode = id[ATA_ID_OLD_DMA_MODES] >> 8;
654654

655655
/*
656656
* if the mode is valid convert it to the mask
@@ -727,7 +727,7 @@ static int ide_tune_dma(ide_drive_t *drive)
727727
ide_hwif_t *hwif = drive->hwif;
728728
u8 speed;
729729

730-
if (drive->nodma || (drive->driveid->capability & 1) == 0)
730+
if (drive->nodma || ata_id_has_dma(drive->id) == 0)
731731
return 0;
732732

733733
/* consult the list of known "bad" drives */

‎drivers/ide/ide-iops.c‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -404,26 +404,10 @@ void ide_fix_driveid(u16 *id)
404404
{
405405
#ifndef __LITTLE_ENDIAN
406406
# ifdef __BIG_ENDIAN
407-
struct hd_driveid *driveid = (struct hd_driveid *)id;
408407
int i;
409408

410-
for (i = 0; i < 256; i++) {
411-
/* these words are accessed as two 8-bit values */
412-
if (i == 47 || i == 49 || i == 51 || i == 52 || i == 59)
413-
continue;
414-
if (i == 60 || i == 61) /* ->lba_capacity is 32-bit */
415-
continue;
416-
if (i == 98 || i == 99) /* ->spg is 32-bit */
417-
continue;
418-
if (i > 99 && i < 104) /* ->lba_capacity_2 is 64-bit */
419-
continue;
420-
409+
for (i = 0; i < 256; i++)
421410
id[i] = __le16_to_cpu(id[i]);
422-
}
423-
424-
driveid->lba_capacity = __le32_to_cpu(driveid->lba_capacity);
425-
driveid->spg = __le32_to_cpu(driveid->spg);
426-
driveid->lba_capacity_2 = __le64_to_cpu(driveid->lba_capacity_2);
427411
# else
428412
# error "Please fix <asm/byteorder.h>"
429413
# endif
@@ -752,7 +736,7 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
752736
#endif
753737

754738
/* Skip setting PIO flow-control modes on pre-EIDE drives */
755-
if ((speed & 0xf8) == XFER_PIO_0 && !(drive->driveid->capability & 8))
739+
if ((speed & 0xf8) == XFER_PIO_0 && ata_id_has_iordy(drive->id) == 0)
756740
goto skip;
757741

758742
/*

‎drivers/ide/ide-lib.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode)
102102
if (pio_mode != -1) {
103103
printk(KERN_INFO "%s: is on PIO blacklist\n", drive->name);
104104
} else {
105-
pio_mode = drive->driveid->tPIO;
105+
pio_mode = id[ATA_ID_OLD_PIO_MODES] >> 8;
106106
if (pio_mode > 2) { /* 2 is maximum allowed tPIO value */
107107
pio_mode = 2;
108108
overridden = 1;
109109
}
110110

111111
if (id[ATA_ID_FIELD_VALID] & 2) { /* ATA2? */
112-
if (drive->driveid->capability & 8) { /* IORDY sup? */
112+
if (ata_id_has_iordy(id)) {
113113
if (id[ATA_ID_PIO_MODES] & 7) {
114114
overridden = 0;
115115
if (id[ATA_ID_PIO_MODES] & 4)

‎drivers/ide/ide-probe.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,20 @@ static void ide_disk_init_chs(ide_drive_t *drive)
8787

8888
static void ide_disk_init_mult_count(ide_drive_t *drive)
8989
{
90-
struct hd_driveid *id = drive->driveid;
90+
u16 *id = drive->id;
91+
u8 max_multsect = id[ATA_ID_MAX_MULTSECT] & 0xff;
9192

92-
if (id->max_multsect) {
93+
if (max_multsect) {
9394
#ifdef CONFIG_IDEDISK_MULTI_MODE
94-
if ((id->max_multsect / 2) > 1) {
95-
id->multsect = id->max_multsect;
96-
id->multsect_valid = 1;
97-
} else {
98-
id->multsect = 0;
99-
id->multsect_valid = 0;
100-
}
101-
drive->mult_req = id->multsect;
95+
if ((max_multsect / 2) > 1)
96+
id[ATA_ID_MULTSECT] = max_multsect | 0x100;
97+
else
98+
id[ATA_ID_MULTSECT] &= ~0x1ff;
99+
100+
drive->mult_req = id[ATA_ID_MULTSECT] & 0xff;
102101
#endif
103-
if ((id->multsect_valid & 1) && id->multsect)
102+
if ((id[ATA_ID_MULTSECT] & 0x100) &&
103+
(id[ATA_ID_MULTSECT] & 0xff))
104104
drive->special.b.set_multmode = 1;
105105
}
106106
}

‎drivers/ide/ide-timings.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ u16 ide_pio_cycle_time(ide_drive_t *drive, u8 pio)
8383
u16 cycle = 0;
8484

8585
if (id[ATA_ID_FIELD_VALID] & 2) {
86-
if (drive->driveid->capability & 8)
86+
if (ata_id_has_iordy(drive->id))
8787
cycle = id[ATA_ID_EIDE_PIO_IORDY];
8888
else
8989
cycle = id[ATA_ID_EIDE_PIO];

‎drivers/ide/ide.c‎

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ int set_using_dma(ide_drive_t *drive, int arg)
328328
if (arg < 0 || arg > 1)
329329
return -EINVAL;
330330

331-
if ((drive->driveid->capability & 1) == 0)
331+
if (ata_id_has_dma(drive->id) == 0)
332332
goto out;
333333

334334
if (hwif->dma_ops == NULL)
@@ -502,12 +502,60 @@ static int generic_drive_reset(ide_drive_t *drive)
502502
return ret;
503503
}
504504

505+
static inline void ide_id_to_hd_driveid(u16 *id)
506+
{
507+
#ifdef __BIG_ENDIAN
508+
/* accessed in struct hd_driveid as 8-bit values */
509+
id[ATA_ID_MAX_MULTSECT] = __cpu_to_le16(id[ATA_ID_MAX_MULTSECT]);
510+
id[ATA_ID_CAPABILITY] = __cpu_to_le16(id[ATA_ID_CAPABILITY]);
511+
id[ATA_ID_OLD_PIO_MODES] = __cpu_to_le16(id[ATA_ID_OLD_PIO_MODES]);
512+
id[ATA_ID_OLD_DMA_MODES] = __cpu_to_le16(id[ATA_ID_OLD_DMA_MODES]);
513+
id[ATA_ID_MULTSECT] = __cpu_to_le16(id[ATA_ID_MULTSECT]);
514+
515+
/* as 32-bit values */
516+
*(u32 *)&id[ATA_ID_LBA_CAPACITY] = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
517+
*(u32 *)&id[ATA_ID_SPG] = ata_id_u32(id, ATA_ID_SPG);
518+
519+
/* as 64-bit value */
520+
*(u64 *)&id[ATA_ID_LBA_CAPACITY_2] =
521+
ata_id_u64(id, ATA_ID_LBA_CAPACITY_2);
522+
#endif
523+
}
524+
525+
static int ide_get_identity_ioctl(ide_drive_t *drive, unsigned int cmd,
526+
unsigned long arg)
527+
{
528+
u16 *id = NULL;
529+
int size = (cmd == HDIO_GET_IDENTITY) ? (ATA_ID_WORDS * 2) : 142;
530+
int rc = 0;
531+
532+
if (drive->id_read == 0) {
533+
rc = -ENOMSG;
534+
goto out;
535+
}
536+
537+
id = kmalloc(size, GFP_KERNEL);
538+
if (id == NULL) {
539+
rc = -ENOMEM;
540+
goto out;
541+
}
542+
543+
memcpy(id, drive->id, size);
544+
ide_id_to_hd_driveid(id);
545+
546+
if (copy_to_user((void __user *)arg, id, size))
547+
rc = -EFAULT;
548+
549+
kfree(id);
550+
out:
551+
return rc;
552+
}
553+
505554
int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
506555
unsigned int cmd, unsigned long arg)
507556
{
508557
unsigned long flags;
509558
ide_driver_t *drv;
510-
void __user *p = (void __user *)arg;
511559
int err = 0, (*setfunc)(ide_drive_t *, int);
512560
u8 *val;
513561

@@ -528,12 +576,7 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device
528576
case HDIO_GET_IDENTITY:
529577
if (bdev != bdev->bd_contains)
530578
return -EINVAL;
531-
if (drive->id_read == 0)
532-
return -ENOMSG;
533-
if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
534-
return -EFAULT;
535-
return 0;
536-
579+
return ide_get_identity_ioctl(drive, cmd, arg);
537580
case HDIO_GET_NICE:
538581
return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
539582
drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |

‎drivers/ide/legacy/qd65xx.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ static void qd6500_set_pio_mode(ide_drive_t *drive, const u8 pio)
195195
* FIXME: use "pio" value
196196
*/
197197
if (!qd_find_disk_type(drive, &active_time, &recovery_time) &&
198-
drive->driveid->tPIO && (id[ATA_ID_FIELD_VALID] & 2) &&
198+
(id[ATA_ID_OLD_PIO_MODES] & 0xff) && (id[ATA_ID_FIELD_VALID] & 2) &&
199199
id[ATA_ID_EIDE_PIO] >= 240) {
200200
printk(KERN_INFO "%s: PIO mode%d\n", drive->name,
201-
drive->driveid->tPIO);
201+
id[ATA_ID_OLD_PIO_MODES] & 0xff);
202202
active_time = 110;
203203
recovery_time = drive->id[ATA_ID_EIDE_PIO] - 120;
204204
}

‎drivers/ide/pci/cs5530.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static u8 cs5530_udma_filter(ide_drive_t *drive)
8888
if (mate->present == 0)
8989
goto out;
9090

91-
if ((mate->driveid->capability & 1) && __ide_dma_bad_drive(mate) == 0) {
91+
if (ata_id_has_dma(mateid) && __ide_dma_bad_drive(mate) == 0) {
9292
if ((mateid[ATA_ID_FIELD_VALID] & 4) &&
9393
(mateid[ATA_ID_UDMA_MODES] & 7))
9494
goto out;

‎drivers/ide/pci/it821x.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ static void it821x_quirkproc(ide_drive_t *drive)
470470
/* In raid mode the ident block is slightly buggy
471471
We need to set the bits so that the IDE layer knows
472472
LBA28. LBA48 and DMA ar valid */
473-
drive->driveid->capability |= 3; /* LBA28, DMA */
473+
id[ATA_ID_CAPABILITY] |= (3 << 8); /* LBA28, DMA */
474474
id[ATA_ID_COMMAND_SET_2] |= 0x0400; /* LBA48 valid */
475475
id[ATA_ID_CFS_ENABLE_2] |= 0x0400; /* LBA48 on */
476476
/* Reporting logic */
@@ -504,7 +504,7 @@ static void it821x_quirkproc(ide_drive_t *drive)
504504
* IDE core that DMA is supported (it821x hardware
505505
* takes care of DMA mode programming).
506506
*/
507-
if (drive->driveid->capability & 1) {
507+
if (ata_id_has_dma(id)) {
508508
id[ATA_ID_MWDMA_MODES] |= 0x0101;
509509
drive->current_speed = XFER_MW_DMA_0;
510510
}

0 commit comments

Comments
 (0)