Skip to content

Commit 24630dc

Browse files
committed
ide: factor out device type classifying from do_identify()
Factor out device type classifying from do_identify() to ide_classify_ata_dev() and ide_classify_atapi_dev(). There should be no functional changes caused by this patch. Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
1 parent 96d4094 commit 24630dc

1 file changed

Lines changed: 81 additions & 73 deletions

File tree

‎drivers/ide/ide-probe.c‎

Lines changed: 81 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,82 @@ static void ide_disk_init_mult_count(ide_drive_t *drive)
101101
}
102102
}
103103

104+
static void ide_classify_ata_dev(ide_drive_t *drive)
105+
{
106+
u16 *id = drive->id;
107+
char *m = (char *)&id[ATA_ID_PROD];
108+
int is_cfa = ata_id_is_cfa(id);
109+
110+
/* CF devices are *not* removable in Linux definition of the term */
111+
if (is_cfa == 0 && (id[ATA_ID_CONFIG] & (1 << 7)))
112+
drive->dev_flags |= IDE_DFLAG_REMOVABLE;
113+
114+
drive->media = ide_disk;
115+
116+
if (!ata_id_has_unload(drive->id))
117+
drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
118+
119+
printk(KERN_INFO "%s: %s, %s DISK drive\n", drive->name, m,
120+
is_cfa ? "CFA" : "ATA");
121+
}
122+
123+
static void ide_classify_atapi_dev(ide_drive_t *drive)
124+
{
125+
u16 *id = drive->id;
126+
char *m = (char *)&id[ATA_ID_PROD];
127+
u8 type = (id[ATA_ID_CONFIG] >> 8) & 0x1f;
128+
129+
printk(KERN_INFO "%s: %s, ATAPI ", drive->name, m);
130+
switch (type) {
131+
case ide_floppy:
132+
if (!strstr(m, "CD-ROM")) {
133+
if (!strstr(m, "oppy") &&
134+
!strstr(m, "poyp") &&
135+
!strstr(m, "ZIP"))
136+
printk(KERN_CONT "cdrom or floppy?, assuming ");
137+
if (drive->media != ide_cdrom) {
138+
printk(KERN_CONT "FLOPPY");
139+
drive->dev_flags |= IDE_DFLAG_REMOVABLE;
140+
break;
141+
}
142+
}
143+
/* Early cdrom models used zero */
144+
type = ide_cdrom;
145+
case ide_cdrom:
146+
drive->dev_flags |= IDE_DFLAG_REMOVABLE;
147+
#ifdef CONFIG_PPC
148+
/* kludge for Apple PowerBook internal zip */
149+
if (!strstr(m, "CD-ROM") && strstr(m, "ZIP")) {
150+
printk(KERN_CONT "FLOPPY");
151+
type = ide_floppy;
152+
break;
153+
}
154+
#endif
155+
printk(KERN_CONT "CD/DVD-ROM");
156+
break;
157+
case ide_tape:
158+
printk(KERN_CONT "TAPE");
159+
break;
160+
case ide_optical:
161+
printk(KERN_CONT "OPTICAL");
162+
drive->dev_flags |= IDE_DFLAG_REMOVABLE;
163+
break;
164+
default:
165+
printk(KERN_CONT "UNKNOWN (type %d)", type);
166+
break;
167+
}
168+
169+
printk(KERN_CONT " drive\n");
170+
drive->media = type;
171+
/* an ATAPI device ignores DRDY */
172+
drive->ready_stat = 0;
173+
if (ata_id_cdb_intr(id))
174+
drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
175+
drive->dev_flags |= IDE_DFLAG_DOORLOCKING;
176+
/* we don't do head unloading on ATAPI devices */
177+
drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
178+
}
179+
104180
/**
105181
* do_identify - identify a drive
106182
* @drive: drive to identify
@@ -117,7 +193,7 @@ static void do_identify(ide_drive_t *drive, u8 cmd)
117193
u16 *id = drive->id;
118194
char *m = (char *)&id[ATA_ID_PROD];
119195
unsigned long flags;
120-
int bswap = 1, is_cfa;
196+
int bswap = 1;
121197

122198
/* local CPU only; some systems need this */
123199
local_irq_save(flags);
@@ -154,91 +230,23 @@ static void do_identify(ide_drive_t *drive, u8 cmd)
154230
if (strstr(m, "E X A B Y T E N E S T"))
155231
goto err_misc;
156232

157-
printk(KERN_INFO "%s: %s, ", drive->name, m);
158-
159233
drive->dev_flags |= IDE_DFLAG_PRESENT;
160234
drive->dev_flags &= ~IDE_DFLAG_DEAD;
161235

162236
/*
163237
* Check for an ATAPI device
164238
*/
165-
if (cmd == ATA_CMD_ID_ATAPI) {
166-
u8 type = (id[ATA_ID_CONFIG] >> 8) & 0x1f;
167-
168-
printk(KERN_CONT "ATAPI ");
169-
switch (type) {
170-
case ide_floppy:
171-
if (!strstr(m, "CD-ROM")) {
172-
if (!strstr(m, "oppy") &&
173-
!strstr(m, "poyp") &&
174-
!strstr(m, "ZIP"))
175-
printk(KERN_CONT "cdrom or floppy?, assuming ");
176-
if (drive->media != ide_cdrom) {
177-
printk(KERN_CONT "FLOPPY");
178-
drive->dev_flags |= IDE_DFLAG_REMOVABLE;
179-
break;
180-
}
181-
}
182-
/* Early cdrom models used zero */
183-
type = ide_cdrom;
184-
case ide_cdrom:
185-
drive->dev_flags |= IDE_DFLAG_REMOVABLE;
186-
#ifdef CONFIG_PPC
187-
/* kludge for Apple PowerBook internal zip */
188-
if (!strstr(m, "CD-ROM") && strstr(m, "ZIP")) {
189-
printk(KERN_CONT "FLOPPY");
190-
type = ide_floppy;
191-
break;
192-
}
193-
#endif
194-
printk(KERN_CONT "CD/DVD-ROM");
195-
break;
196-
case ide_tape:
197-
printk(KERN_CONT "TAPE");
198-
break;
199-
case ide_optical:
200-
printk(KERN_CONT "OPTICAL");
201-
drive->dev_flags |= IDE_DFLAG_REMOVABLE;
202-
break;
203-
default:
204-
printk(KERN_CONT "UNKNOWN (type %d)", type);
205-
break;
206-
}
207-
printk(KERN_CONT " drive\n");
208-
drive->media = type;
209-
/* an ATAPI device ignores DRDY */
210-
drive->ready_stat = 0;
211-
if (ata_id_cdb_intr(id))
212-
drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
213-
drive->dev_flags |= IDE_DFLAG_DOORLOCKING;
214-
/* we don't do head unloading on ATAPI devices */
215-
drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
216-
return;
217-
}
218-
239+
if (cmd == ATA_CMD_ID_ATAPI)
240+
ide_classify_atapi_dev(drive);
241+
else
219242
/*
220243
* Not an ATAPI device: looks like a "regular" hard disk
221244
*/
222-
223-
is_cfa = ata_id_is_cfa(id);
224-
225-
/* CF devices are *not* removable in Linux definition of the term */
226-
if (is_cfa == 0 && (id[ATA_ID_CONFIG] & (1 << 7)))
227-
drive->dev_flags |= IDE_DFLAG_REMOVABLE;
228-
229-
drive->media = ide_disk;
230-
231-
if (!ata_id_has_unload(drive->id))
232-
drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
233-
234-
printk(KERN_CONT "%s DISK drive\n", is_cfa ? "CFA" : "ATA");
235-
245+
ide_classify_ata_dev(drive);
236246
return;
237-
238247
err_misc:
239248
kfree(id);
240249
drive->dev_flags &= ~IDE_DFLAG_PRESENT;
241-
return;
242250
}
243251

244252
/**

0 commit comments

Comments
 (0)