1 |
1626 |
jcastillo |
/*
|
2 |
|
|
* linux/drivers/block/ide.h
|
3 |
|
|
*
|
4 |
|
|
* Copyright (C) 1994, 1995 Linus Torvalds & authors
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
|
|
#include <linux/config.h>
|
8 |
|
|
|
9 |
|
|
/*
|
10 |
|
|
* This is the multiple IDE interface driver, as evolved from hd.c.
|
11 |
|
|
* It supports up to four IDE interfaces, on one or more IRQs (usually 14 & 15).
|
12 |
|
|
* There can be up to two drives per interface, as per the ATA-2 spec.
|
13 |
|
|
*
|
14 |
|
|
* Primary i/f: ide0: major=3; (hda) minor=0; (hdb) minor=64
|
15 |
|
|
* Secondary i/f: ide1: major=22; (hdc or hd1a) minor=0; (hdd or hd1b) minor=64
|
16 |
|
|
* Tertiary i/f: ide2: major=33; (hde) minor=0; (hdf) minor=64
|
17 |
|
|
* Quaternary i/f: ide3: major=34; (hdg) minor=0; (hdh) minor=64
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
|
|
/******************************************************************************
|
21 |
|
|
* IDE driver configuration options (play with these as desired):
|
22 |
|
|
*
|
23 |
|
|
* REALLY_SLOW_IO can be defined in ide.c and ide-cd.c, if necessary
|
24 |
|
|
*/
|
25 |
|
|
#undef REALLY_FAST_IO /* define if ide ports are perfect */
|
26 |
|
|
#define INITIAL_MULT_COUNT 0 /* off=0; on=2,4,8,16,32, etc.. */
|
27 |
|
|
|
28 |
|
|
#ifdef CONFIG_COLDFIRE
|
29 |
|
|
/*
|
30 |
|
|
* ColdFire board specifics...
|
31 |
|
|
*/
|
32 |
|
|
#define SUPPORT_VLB_SYNC 0 /* No VLB on ColdFires */
|
33 |
|
|
#define MAX_HWIFS 1 /* Only 1 interface */
|
34 |
|
|
#endif
|
35 |
|
|
|
36 |
|
|
#ifndef SUPPORT_SLOW_DATA_PORTS /* 1 to support slow data ports */
|
37 |
|
|
#define SUPPORT_SLOW_DATA_PORTS 1 /* 0 to reduce kernel size */
|
38 |
|
|
#endif
|
39 |
|
|
#ifndef SUPPORT_VLB_SYNC /* 1 to support weird 32-bit chips */
|
40 |
|
|
#define SUPPORT_VLB_SYNC 1 /* 0 to reduce kernel size */
|
41 |
|
|
#endif
|
42 |
|
|
#ifndef DISK_RECOVERY_TIME /* off=0; on=access_delay_time */
|
43 |
|
|
#define DISK_RECOVERY_TIME 0 /* for hardware that needs it */
|
44 |
|
|
#endif
|
45 |
|
|
#ifndef OK_TO_RESET_CONTROLLER /* 1 needed for good error recovery */
|
46 |
|
|
#define OK_TO_RESET_CONTROLLER 1 /* 0 for use with AH2372A/B interface */
|
47 |
|
|
#endif
|
48 |
|
|
#ifndef FAKE_FDISK_FOR_EZDRIVE /* 1 to help linux fdisk with EZDRIVE */
|
49 |
|
|
#define FAKE_FDISK_FOR_EZDRIVE 1 /* 0 to reduce kernel size */
|
50 |
|
|
#endif
|
51 |
|
|
#ifndef FANCY_STATUS_DUMPS /* 1 for human-readable drive errors */
|
52 |
|
|
#define FANCY_STATUS_DUMPS 1 /* 0 to reduce kernel size */
|
53 |
|
|
#endif
|
54 |
|
|
|
55 |
|
|
#ifdef CONFIG_BLK_DEV_CMD640
|
56 |
|
|
#if 0 /* change to 1 when debugging cmd640 problems */
|
57 |
|
|
void cmd640_dump_regs (void);
|
58 |
|
|
#define CMD640_DUMP_REGS cmd640_dump_regs() /* for debugging cmd640 chipset */
|
59 |
|
|
#endif
|
60 |
|
|
#endif /* CONFIG_BLK_DEV_CMD640 */
|
61 |
|
|
|
62 |
|
|
#if defined(CONFIG_BLK_DEV_IDECD) || defined(CONFIG_BLK_DEV_IDETAPE) || \
|
63 |
|
|
defined(CONFIG_BLK_DEV_IDEFLOPPY) || defined(CONFIG_BLK_DEV_IDESCSI)
|
64 |
|
|
#define CONFIG_BLK_DEV_IDEATAPI 1
|
65 |
|
|
#endif
|
66 |
|
|
|
67 |
|
|
/*
|
68 |
|
|
* IDE_DRIVE_CMD is used to implement many features of the hdparm utility
|
69 |
|
|
*/
|
70 |
|
|
#define IDE_DRIVE_CMD 99 /* (magic) undef to reduce kernel size*/
|
71 |
|
|
|
72 |
|
|
/*
|
73 |
|
|
* "No user-serviceable parts" beyond this point :)
|
74 |
|
|
*****************************************************************************/
|
75 |
|
|
|
76 |
|
|
#if defined(CONFIG_BLK_DEV_IDESCSI) && !defined(CONFIG_SCSI)
|
77 |
|
|
#error "SCSI must also be selected"
|
78 |
|
|
#endif
|
79 |
|
|
|
80 |
|
|
typedef unsigned char byte; /* used everywhere */
|
81 |
|
|
|
82 |
|
|
/*
|
83 |
|
|
* Probably not wise to fiddle with these
|
84 |
|
|
*/
|
85 |
|
|
#define ERROR_MAX 8 /* Max read/write errors per sector */
|
86 |
|
|
#define ERROR_RESET 3 /* Reset controller every 4th retry */
|
87 |
|
|
#define ERROR_RECAL 1 /* Recalibrate every 2nd retry */
|
88 |
|
|
|
89 |
|
|
/*
|
90 |
|
|
* Ensure that various configuration flags have compatible settings
|
91 |
|
|
*/
|
92 |
|
|
#ifdef REALLY_SLOW_IO
|
93 |
|
|
#undef REALLY_FAST_IO
|
94 |
|
|
#endif
|
95 |
|
|
|
96 |
|
|
/*
|
97 |
|
|
* Definitions for accessing IDE controller registers
|
98 |
|
|
*/
|
99 |
|
|
|
100 |
|
|
#define HWIF(drive) ((ide_hwif_t *)((drive)->hwif))
|
101 |
|
|
#define HWGROUP(drive) ((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
|
102 |
|
|
|
103 |
|
|
#define IDE_DATA_OFFSET (0)
|
104 |
|
|
#define IDE_ERROR_OFFSET (1)
|
105 |
|
|
#define IDE_NSECTOR_OFFSET (2)
|
106 |
|
|
#define IDE_SECTOR_OFFSET (3)
|
107 |
|
|
#define IDE_LCYL_OFFSET (4)
|
108 |
|
|
#define IDE_HCYL_OFFSET (5)
|
109 |
|
|
#define IDE_SELECT_OFFSET (6)
|
110 |
|
|
#define IDE_STATUS_OFFSET (7)
|
111 |
|
|
#define IDE_FEATURE_OFFSET IDE_ERROR_OFFSET
|
112 |
|
|
#define IDE_COMMAND_OFFSET IDE_STATUS_OFFSET
|
113 |
|
|
|
114 |
|
|
#define IDE_DATA_REG (HWIF(drive)->io_base+IDE_DATA_OFFSET)
|
115 |
|
|
#define IDE_ERROR_REG (HWIF(drive)->io_base+IDE_ERROR_OFFSET)
|
116 |
|
|
#define IDE_NSECTOR_REG (HWIF(drive)->io_base+IDE_NSECTOR_OFFSET)
|
117 |
|
|
#define IDE_SECTOR_REG (HWIF(drive)->io_base+IDE_SECTOR_OFFSET)
|
118 |
|
|
#define IDE_LCYL_REG (HWIF(drive)->io_base+IDE_LCYL_OFFSET)
|
119 |
|
|
#define IDE_HCYL_REG (HWIF(drive)->io_base+IDE_HCYL_OFFSET)
|
120 |
|
|
#define IDE_SELECT_REG (HWIF(drive)->io_base+IDE_SELECT_OFFSET)
|
121 |
|
|
#define IDE_STATUS_REG (HWIF(drive)->io_base+IDE_STATUS_OFFSET)
|
122 |
|
|
#define IDE_CONTROL_REG (HWIF(drive)->ctl_port)
|
123 |
|
|
#define IDE_FEATURE_REG IDE_ERROR_REG
|
124 |
|
|
#define IDE_COMMAND_REG IDE_STATUS_REG
|
125 |
|
|
#define IDE_ALTSTATUS_REG IDE_CONTROL_REG
|
126 |
|
|
#define IDE_IREASON_REG IDE_NSECTOR_REG
|
127 |
|
|
#define IDE_BCOUNTL_REG IDE_LCYL_REG
|
128 |
|
|
#define IDE_BCOUNTH_REG IDE_HCYL_REG
|
129 |
|
|
|
130 |
|
|
#ifdef REALLY_FAST_IO
|
131 |
|
|
#define OUT_BYTE(b,p) outb((b),(p))
|
132 |
|
|
#define IN_BYTE(p) (byte)inb(p)
|
133 |
|
|
#else
|
134 |
|
|
#define OUT_BYTE(b,p) outb_p((b),(p))
|
135 |
|
|
#define IN_BYTE(p) (byte)inb_p(p)
|
136 |
|
|
#endif /* REALLY_FAST_IO */
|
137 |
|
|
|
138 |
|
|
#define GET_ERR() IN_BYTE(IDE_ERROR_REG)
|
139 |
|
|
#define GET_STAT() IN_BYTE(IDE_STATUS_REG)
|
140 |
|
|
#define OK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good))
|
141 |
|
|
#define BAD_R_STAT (BUSY_STAT | ERR_STAT)
|
142 |
|
|
#define BAD_W_STAT (BAD_R_STAT | WRERR_STAT)
|
143 |
|
|
#define BAD_STAT (BAD_R_STAT | DRQ_STAT)
|
144 |
|
|
#define DRIVE_READY (READY_STAT | SEEK_STAT)
|
145 |
|
|
#define DATA_READY (DRQ_STAT)
|
146 |
|
|
|
147 |
|
|
/*
|
148 |
|
|
* Some more useful definitions
|
149 |
|
|
*/
|
150 |
|
|
#define IDE_MAJOR_NAME "ide" /* the same for all i/f; see also genhd.c */
|
151 |
|
|
#define MAJOR_NAME IDE_MAJOR_NAME
|
152 |
|
|
#define PARTN_BITS 6 /* number of minor dev bits for partitions */
|
153 |
|
|
#define PARTN_MASK ((1<<PARTN_BITS)-1) /* a useful bit mask */
|
154 |
|
|
#define MAX_DRIVES 2 /* per interface; 2 assumed by lots of code */
|
155 |
|
|
#ifndef MAX_HWIFS
|
156 |
|
|
#define MAX_HWIFS 4 /* an arbitrary, but realistic limit */
|
157 |
|
|
#endif
|
158 |
|
|
#define SECTOR_WORDS (512 / 4) /* number of 32bit words per sector */
|
159 |
|
|
|
160 |
|
|
/*
|
161 |
|
|
* Timeouts for various operations:
|
162 |
|
|
*/
|
163 |
|
|
#define WAIT_DRQ (5*HZ/100) /* 50msec - spec allows up to 20ms */
|
164 |
|
|
#ifdef CONFIG_APM
|
165 |
|
|
#define WAIT_READY (5*HZ) /* 5sec - some laptops are very slow */
|
166 |
|
|
#else
|
167 |
|
|
#define WAIT_READY (3*HZ/100) /* 30msec - should be instantaneous */
|
168 |
|
|
#endif /* CONFIG_APM */
|
169 |
|
|
#define WAIT_PIDENTIFY (1*HZ) /* 1sec - should be less than 3ms (?) */
|
170 |
|
|
#define WAIT_WORSTCASE (30*HZ) /* 30sec - worst case when spinning up */
|
171 |
|
|
#define WAIT_CMD (10*HZ) /* 10sec - maximum wait for an IRQ to happen */
|
172 |
|
|
|
173 |
|
|
#if defined(CONFIG_BLK_DEV_HT6560B) || defined(CONFIG_BLK_DEV_PROMISE)
|
174 |
|
|
#define SELECT_DRIVE(hwif,drive) \
|
175 |
|
|
{ \
|
176 |
|
|
if (hwif->selectproc) \
|
177 |
|
|
hwif->selectproc(drive); \
|
178 |
|
|
else \
|
179 |
|
|
OUT_BYTE((drive)->select.all, hwif->io_base+IDE_SELECT_OFFSET); \
|
180 |
|
|
}
|
181 |
|
|
#else
|
182 |
|
|
#define SELECT_DRIVE(hwif,drive) OUT_BYTE((drive)->select.all, hwif->io_base+IDE_SELECT_OFFSET);
|
183 |
|
|
#endif /* CONFIG_BLK_DEV_HT6560B || CONFIG_BLK_DEV_PROMISE */
|
184 |
|
|
|
185 |
|
|
#ifdef CONFIG_BLK_DEV_IDETAPE
|
186 |
|
|
#include "ide-tape.h"
|
187 |
|
|
#endif /* CONFIG_BLK_DEV_IDETAPE */
|
188 |
|
|
|
189 |
|
|
#ifdef CONFIG_BLK_DEV_IDECD
|
190 |
|
|
|
191 |
|
|
struct atapi_request_sense {
|
192 |
|
|
unsigned char error_code : 7;
|
193 |
|
|
unsigned char valid : 1;
|
194 |
|
|
byte reserved1;
|
195 |
|
|
unsigned char sense_key : 4;
|
196 |
|
|
unsigned char reserved2 : 1;
|
197 |
|
|
unsigned char ili : 1;
|
198 |
|
|
unsigned char reserved3 : 2;
|
199 |
|
|
byte info[4];
|
200 |
|
|
byte sense_len;
|
201 |
|
|
byte command_info[4];
|
202 |
|
|
byte asc;
|
203 |
|
|
byte ascq;
|
204 |
|
|
byte fru;
|
205 |
|
|
byte sense_key_specific[3];
|
206 |
|
|
};
|
207 |
|
|
|
208 |
|
|
struct packet_command {
|
209 |
|
|
char *buffer;
|
210 |
|
|
int buflen;
|
211 |
|
|
int stat;
|
212 |
|
|
struct atapi_request_sense *sense_data;
|
213 |
|
|
unsigned char c[12];
|
214 |
|
|
};
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
/* Structure of a MSF cdrom address. */
|
218 |
|
|
struct atapi_msf {
|
219 |
|
|
byte reserved;
|
220 |
|
|
byte minute;
|
221 |
|
|
byte second;
|
222 |
|
|
byte frame;
|
223 |
|
|
};
|
224 |
|
|
|
225 |
|
|
|
226 |
|
|
/* Space to hold the disk TOC. */
|
227 |
|
|
|
228 |
|
|
#define MAX_TRACKS 99
|
229 |
|
|
struct atapi_toc_header {
|
230 |
|
|
unsigned short toc_length;
|
231 |
|
|
byte first_track;
|
232 |
|
|
byte last_track;
|
233 |
|
|
};
|
234 |
|
|
|
235 |
|
|
struct atapi_toc_entry {
|
236 |
|
|
byte reserved1;
|
237 |
|
|
unsigned control : 4;
|
238 |
|
|
unsigned adr : 4;
|
239 |
|
|
byte track;
|
240 |
|
|
byte reserved2;
|
241 |
|
|
union {
|
242 |
|
|
unsigned lba;
|
243 |
|
|
struct atapi_msf msf;
|
244 |
|
|
} addr;
|
245 |
|
|
};
|
246 |
|
|
|
247 |
|
|
struct atapi_toc {
|
248 |
|
|
int last_session_lba;
|
249 |
|
|
int xa_flag;
|
250 |
|
|
unsigned capacity;
|
251 |
|
|
struct atapi_toc_header hdr;
|
252 |
|
|
struct atapi_toc_entry ent[MAX_TRACKS+1];
|
253 |
|
|
/* One extra for the leadout. */
|
254 |
|
|
};
|
255 |
|
|
|
256 |
|
|
|
257 |
|
|
/* This structure is annoyingly close to, but not identical with,
|
258 |
|
|
the cdrom_subchnl structure from cdrom.h. */
|
259 |
|
|
struct atapi_cdrom_subchnl
|
260 |
|
|
{
|
261 |
|
|
u_char acdsc_reserved;
|
262 |
|
|
u_char acdsc_audiostatus;
|
263 |
|
|
u_short acdsc_length;
|
264 |
|
|
u_char acdsc_format;
|
265 |
|
|
|
266 |
|
|
u_char acdsc_adr: 4;
|
267 |
|
|
u_char acdsc_ctrl: 4;
|
268 |
|
|
u_char acdsc_trk;
|
269 |
|
|
u_char acdsc_ind;
|
270 |
|
|
union {
|
271 |
|
|
struct atapi_msf msf;
|
272 |
|
|
int lba;
|
273 |
|
|
} acdsc_absaddr;
|
274 |
|
|
union {
|
275 |
|
|
struct atapi_msf msf;
|
276 |
|
|
int lba;
|
277 |
|
|
} acdsc_reladdr;
|
278 |
|
|
};
|
279 |
|
|
|
280 |
|
|
|
281 |
|
|
/* Extra per-device info for cdrom drives. */
|
282 |
|
|
struct cdrom_info {
|
283 |
|
|
|
284 |
|
|
/* Buffer for table of contents. NULL if we haven't allocated
|
285 |
|
|
a TOC buffer for this device yet. */
|
286 |
|
|
|
287 |
|
|
struct atapi_toc *toc;
|
288 |
|
|
|
289 |
|
|
/* Sector buffer. If a read request wants only the first part
|
290 |
|
|
of a cdrom block, we cache the rest of the block here,
|
291 |
|
|
in the expectation that that data is going to be wanted soon.
|
292 |
|
|
SECTOR_BUFFERED is the number of the first buffered sector,
|
293 |
|
|
and NSECTORS_BUFFERED is the number of sectors in the buffer.
|
294 |
|
|
Before the buffer is allocated, we should have
|
295 |
|
|
SECTOR_BUFFER == NULL and NSECTORS_BUFFERED == 0. */
|
296 |
|
|
|
297 |
|
|
unsigned long sector_buffered;
|
298 |
|
|
unsigned long nsectors_buffered;
|
299 |
|
|
char *sector_buffer;
|
300 |
|
|
|
301 |
|
|
/* The result of the last successful request sense command
|
302 |
|
|
on this device. */
|
303 |
|
|
struct atapi_request_sense sense_data;
|
304 |
|
|
|
305 |
|
|
int max_sectors;
|
306 |
|
|
};
|
307 |
|
|
|
308 |
|
|
#endif /* CONFIG_BLK_DEV_IDECD */
|
309 |
|
|
|
310 |
|
|
/*
|
311 |
|
|
* Now for the data we need to maintain per-drive: ide_drive_t
|
312 |
|
|
*/
|
313 |
|
|
|
314 |
|
|
typedef enum {ide_disk, ide_cdrom, ide_tape, ide_floppy, ide_scsi} ide_media_t;
|
315 |
|
|
|
316 |
|
|
typedef union {
|
317 |
|
|
unsigned all : 8; /* all of the bits together */
|
318 |
|
|
struct {
|
319 |
|
|
unsigned set_geometry : 1; /* respecify drive geometry */
|
320 |
|
|
unsigned recalibrate : 1; /* seek to cyl 0 */
|
321 |
|
|
unsigned set_multmode : 1; /* set multmode count */
|
322 |
|
|
unsigned set_tune : 1; /* tune interface for drive */
|
323 |
|
|
unsigned mc : 1; /* acknowledge media change */
|
324 |
|
|
unsigned reserved : 3; /* unused */
|
325 |
|
|
} b;
|
326 |
|
|
} special_t;
|
327 |
|
|
|
328 |
|
|
typedef union {
|
329 |
|
|
unsigned all : 8; /* all of the bits together */
|
330 |
|
|
struct {
|
331 |
|
|
unsigned head : 4; /* always zeros here */
|
332 |
|
|
unsigned unit : 1; /* drive select number, 0 or 1 */
|
333 |
|
|
unsigned bit5 : 1; /* always 1 */
|
334 |
|
|
unsigned lba : 1; /* using LBA instead of CHS */
|
335 |
|
|
unsigned bit7 : 1; /* always 1 */
|
336 |
|
|
} b;
|
337 |
|
|
} select_t;
|
338 |
|
|
|
339 |
|
|
typedef struct ide_drive_s {
|
340 |
|
|
special_t special; /* special action flags */
|
341 |
|
|
unsigned present : 1; /* drive is physically present */
|
342 |
|
|
unsigned noprobe : 1; /* from: hdx=noprobe */
|
343 |
|
|
unsigned keep_settings : 1; /* restore settings after drive reset */
|
344 |
|
|
unsigned busy : 1; /* currently doing revalidate_disk() */
|
345 |
|
|
unsigned removable : 1; /* 1 if need to do check_media_change */
|
346 |
|
|
unsigned using_dma : 1; /* disk is using dma for read/write */
|
347 |
|
|
unsigned forced_geom : 1; /* 1 if hdx=c,h,s was given at boot */
|
348 |
|
|
unsigned unmask : 1; /* flag: okay to unmask other irqs */
|
349 |
|
|
unsigned no_unmask : 1; /* disallow setting unmask bit */
|
350 |
|
|
unsigned no_io_32bit : 1; /* disallow enabling 32bit I/O */
|
351 |
|
|
unsigned nobios : 1; /* flag: do not probe bios for drive */
|
352 |
|
|
unsigned slow : 1; /* flag: slow data port */
|
353 |
|
|
unsigned autotune : 2; /* 1=autotune, 2=noautotune, 0=default */
|
354 |
|
|
#if FAKE_FDISK_FOR_EZDRIVE
|
355 |
|
|
unsigned remap_0_to_1 : 1; /* flag: partitioned with ezdrive */
|
356 |
|
|
#endif /* FAKE_FDISK_FOR_EZDRIVE */
|
357 |
|
|
unsigned no_geom : 1; /* flag: do not set geometry */
|
358 |
|
|
ide_media_t media; /* disk, cdrom, tape, floppy */
|
359 |
|
|
select_t select; /* basic drive/head select reg value */
|
360 |
|
|
byte ctl; /* "normal" value for IDE_CONTROL_REG */
|
361 |
|
|
byte ready_stat; /* min status value for drive ready */
|
362 |
|
|
byte mult_count; /* current multiple sector setting */
|
363 |
|
|
byte mult_req; /* requested multiple sector setting */
|
364 |
|
|
byte tune_req; /* requested drive tuning setting */
|
365 |
|
|
byte io_32bit; /* 0=16-bit, 1=32-bit, 2/3=32bit+sync */
|
366 |
|
|
byte bad_wstat; /* used for ignoring WRERR_STAT */
|
367 |
|
|
byte sect0; /* offset of first sector for DM6:DDO */
|
368 |
|
|
byte usage; /* current "open()" count for drive */
|
369 |
|
|
byte head; /* "real" number of heads */
|
370 |
|
|
byte sect; /* "real" sectors per track */
|
371 |
|
|
byte bios_head; /* BIOS/fdisk/LILO number of heads */
|
372 |
|
|
byte bios_sect; /* BIOS/fdisk/LILO sectors per track */
|
373 |
|
|
unsigned short bios_cyl; /* BIOS/fdisk/LILO number of cyls */
|
374 |
|
|
unsigned short cyl; /* "real" number of cyls */
|
375 |
|
|
void *hwif; /* actually (ide_hwif_t *) */
|
376 |
|
|
struct wait_queue *wqueue; /* used to wait for drive in open() */
|
377 |
|
|
struct hd_driveid *id; /* drive model identification info */
|
378 |
|
|
struct hd_struct *part; /* drive partition table */
|
379 |
|
|
char name[4]; /* drive name, such as "hda" */
|
380 |
|
|
#ifdef CONFIG_BLK_DEV_IDECD
|
381 |
|
|
struct cdrom_info cdrom_info; /* for ide-cd.c */
|
382 |
|
|
#endif /* CONFIG_BLK_DEV_IDECD */
|
383 |
|
|
#ifdef CONFIG_BLK_DEV_IDETAPE
|
384 |
|
|
idetape_tape_t tape; /* for ide-tape.c */
|
385 |
|
|
#endif /* CONFIG_BLK_DEV_IDETAPE */
|
386 |
|
|
#ifdef CONFIG_BLK_DEV_IDEFLOPPY
|
387 |
|
|
void *floppy; /* for ide-floppy.c */
|
388 |
|
|
#endif /* CONFIG_BLK_DEV_IDEFLOPPY */
|
389 |
|
|
#ifdef CONFIG_BLK_DEV_IDESCSI
|
390 |
|
|
void *scsi; /* for ide-scsi.c */
|
391 |
|
|
#endif /* CONFIG_BLK_DEV_IDESCSI */
|
392 |
|
|
byte ide_scsi; /* use ide-scsi driver */
|
393 |
|
|
} ide_drive_t;
|
394 |
|
|
|
395 |
|
|
/*
|
396 |
|
|
* An ide_dmaproc_t() initiates/aborts DMA read/write operations on a drive.
|
397 |
|
|
*
|
398 |
|
|
* The caller is assumed to have selected the drive and programmed the drive's
|
399 |
|
|
* sector address using CHS or LBA. All that remains is to prepare for DMA
|
400 |
|
|
* and then issue the actual read/write DMA/PIO command to the drive.
|
401 |
|
|
*
|
402 |
|
|
* Returns 0 if all went well.
|
403 |
|
|
* Returns 1 if DMA read/write could not be started, in which case the caller
|
404 |
|
|
* should either try again later, or revert to PIO for the current request.
|
405 |
|
|
*/
|
406 |
|
|
typedef enum { ide_dma_read = 0, ide_dma_write = 1,
|
407 |
|
|
ide_dma_abort = 2, ide_dma_check = 3,
|
408 |
|
|
ide_dma_status_bad = 4, ide_dma_transferred = 5,
|
409 |
|
|
ide_dma_begin = 6 }
|
410 |
|
|
ide_dma_action_t;
|
411 |
|
|
|
412 |
|
|
typedef int (ide_dmaproc_t)(ide_dma_action_t, ide_drive_t *);
|
413 |
|
|
|
414 |
|
|
|
415 |
|
|
/*
|
416 |
|
|
* An ide_tuneproc_t() is used to set the speed of an IDE interface
|
417 |
|
|
* to a particular PIO mode. The "byte" parameter is used
|
418 |
|
|
* to select the PIO mode by number (0,1,2,3,4,5), and a value of 255
|
419 |
|
|
* indicates that the interface driver should "auto-tune" the PIO mode
|
420 |
|
|
* according to the drive capabilities in drive->id;
|
421 |
|
|
*
|
422 |
|
|
* Not all interface types support tuning, and not all of those
|
423 |
|
|
* support all possible PIO settings. They may silently ignore
|
424 |
|
|
* or round values as they see fit.
|
425 |
|
|
*/
|
426 |
|
|
typedef void (ide_tuneproc_t)(ide_drive_t *, byte);
|
427 |
|
|
|
428 |
|
|
/*
|
429 |
|
|
* This is used to provide HT6560B & PROMISE interface support.
|
430 |
|
|
*/
|
431 |
|
|
typedef void (ide_selectproc_t) (ide_drive_t *);
|
432 |
|
|
|
433 |
|
|
/*
|
434 |
|
|
* hwif_chipset_t is used to keep track of the specific hardware
|
435 |
|
|
* chipset used by each IDE interface, if known.
|
436 |
|
|
*/
|
437 |
|
|
typedef enum { ide_unknown, ide_generic, ide_triton,
|
438 |
|
|
ide_cmd640, ide_dtc2278, ide_ali14xx,
|
439 |
|
|
ide_qd6580, ide_umc8672, ide_ht6560b,
|
440 |
|
|
ide_promise, ide_udma }
|
441 |
|
|
hwif_chipset_t;
|
442 |
|
|
|
443 |
|
|
typedef struct hwif_s {
|
444 |
|
|
struct hwif_s *next; /* for linked-list in ide_hwgroup_t */
|
445 |
|
|
void *hwgroup; /* actually (ide_hwgroup_t *) */
|
446 |
|
|
#ifdef CONFIG_COLDFIRE
|
447 |
|
|
unsigned int io_base; /* base io port addr */
|
448 |
|
|
unsigned int ctl_port; /* usually io_base+0x206 */
|
449 |
|
|
#else
|
450 |
|
|
unsigned short io_base; /* base io port addr */
|
451 |
|
|
unsigned short ctl_port; /* usually io_base+0x206 */
|
452 |
|
|
#endif
|
453 |
|
|
ide_drive_t drives[MAX_DRIVES]; /* drive info */
|
454 |
|
|
struct gendisk *gd; /* gendisk structure */
|
455 |
|
|
ide_tuneproc_t *tuneproc; /* routine to tune PIO mode for drives */
|
456 |
|
|
#if defined(CONFIG_BLK_DEV_HT6560B) || defined(CONFIG_BLK_DEV_PROMISE)
|
457 |
|
|
ide_selectproc_t *selectproc; /* tweaks hardware to select drive */
|
458 |
|
|
#endif
|
459 |
|
|
ide_dmaproc_t *dmaproc; /* dma read/write/abort routine */
|
460 |
|
|
unsigned long *dmatable; /* dma physical region descriptor table */
|
461 |
|
|
unsigned short dma_base; /* base addr for dma ports (triton) */
|
462 |
|
|
byte irq; /* our irq number */
|
463 |
|
|
byte major; /* our major number */
|
464 |
|
|
char name[5]; /* name of interface, eg. "ide0" */
|
465 |
|
|
byte index; /* 0 for ide0; 1 for ide1; ... */
|
466 |
|
|
hwif_chipset_t chipset; /* sub-module for tuning.. */
|
467 |
|
|
unsigned noprobe : 1; /* don't probe for this interface */
|
468 |
|
|
unsigned present : 1; /* this interface exists */
|
469 |
|
|
unsigned serialized : 1; /* serialized operation with mate hwif */
|
470 |
|
|
unsigned sharing_irq: 1; /* 1 = sharing irq with another hwif */
|
471 |
|
|
#ifdef CONFIG_BLK_DEV_PROMISE
|
472 |
|
|
unsigned is_promise2: 1; /* 2nd i/f on promise DC4030 */
|
473 |
|
|
#endif /* CONFIG_BLK_DEV_PROMISE */
|
474 |
|
|
#if (DISK_RECOVERY_TIME > 0)
|
475 |
|
|
unsigned long last_time; /* time when previous rq was done */
|
476 |
|
|
#endif
|
477 |
|
|
#ifdef CONFIG_BLK_DEV_IDECD
|
478 |
|
|
struct request request_sense_request; /* from ide-cd.c */
|
479 |
|
|
struct packet_command request_sense_pc; /* from ide-cd.c */
|
480 |
|
|
#endif /* CONFIG_BLK_DEV_IDECD */
|
481 |
|
|
#ifdef CONFIG_BLK_DEV_IDETAPE
|
482 |
|
|
ide_drive_t *tape_drive; /* Pointer to the tape on this interface */
|
483 |
|
|
#endif /* CONFIG_BLK_DEV_IDETAPE */
|
484 |
|
|
} ide_hwif_t;
|
485 |
|
|
|
486 |
|
|
/*
|
487 |
|
|
* internal ide interrupt handler type
|
488 |
|
|
*/
|
489 |
|
|
typedef void (ide_handler_t)(ide_drive_t *);
|
490 |
|
|
|
491 |
|
|
typedef struct hwgroup_s {
|
492 |
|
|
ide_handler_t *handler;/* irq handler, if active */
|
493 |
|
|
ide_drive_t *drive; /* current drive */
|
494 |
|
|
ide_hwif_t *hwif; /* ptr to current hwif in linked-list */
|
495 |
|
|
ide_hwif_t *next_hwif; /* next selected hwif (for tape) */
|
496 |
|
|
struct request *rq; /* current request */
|
497 |
|
|
struct timer_list timer; /* failsafe timer */
|
498 |
|
|
struct request wrq; /* local copy of current write rq */
|
499 |
|
|
unsigned long poll_timeout; /* timeout value during long polls */
|
500 |
|
|
int active; /* set when servicing requests */
|
501 |
|
|
} ide_hwgroup_t;
|
502 |
|
|
|
503 |
|
|
/*
|
504 |
|
|
* ide_hwifs[] is the master data structure used to keep track
|
505 |
|
|
* of just about everything in ide.c. Whenever possible, routines
|
506 |
|
|
* should be using pointers to a drive (ide_drive_t *) or
|
507 |
|
|
* pointers to a hwif (ide_hwif_t *), rather than indexing this
|
508 |
|
|
* structure directly (the allocation/layout may change!).
|
509 |
|
|
*
|
510 |
|
|
*/
|
511 |
|
|
#ifndef _IDE_C
|
512 |
|
|
extern ide_hwif_t ide_hwifs[]; /* master data repository */
|
513 |
|
|
#endif
|
514 |
|
|
|
515 |
|
|
/*
|
516 |
|
|
* One final include file, which references some of the data/defns from above
|
517 |
|
|
*/
|
518 |
|
|
#define IDE_DRIVER /* "parameter" for blk.h */
|
519 |
|
|
#include <linux/blk.h>
|
520 |
|
|
|
521 |
|
|
#if (DISK_RECOVERY_TIME > 0)
|
522 |
|
|
void ide_set_recovery_timer (ide_hwif_t *);
|
523 |
|
|
#define SET_RECOVERY_TIMER(drive) ide_set_recovery_timer (drive)
|
524 |
|
|
#else
|
525 |
|
|
#define SET_RECOVERY_TIMER(drive)
|
526 |
|
|
#endif
|
527 |
|
|
|
528 |
|
|
/*
|
529 |
|
|
* This is used for (nearly) all data transfers from the IDE interface
|
530 |
|
|
*/
|
531 |
|
|
void ide_input_data (ide_drive_t *drive, void *buffer, unsigned int wcount);
|
532 |
|
|
|
533 |
|
|
/*
|
534 |
|
|
* This is used for (nearly) all data transfers to the IDE interface
|
535 |
|
|
*/
|
536 |
|
|
void ide_output_data (ide_drive_t *drive, void *buffer, unsigned int wcount);
|
537 |
|
|
|
538 |
|
|
/*
|
539 |
|
|
* This is used for (nearly) all ATAPI data transfers from/to the IDE interface
|
540 |
|
|
*/
|
541 |
|
|
void atapi_input_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount);
|
542 |
|
|
void atapi_output_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount);
|
543 |
|
|
|
544 |
|
|
/*
|
545 |
|
|
* This is used on exit from the driver, to designate the next irq handler
|
546 |
|
|
* and also to start the safety timer.
|
547 |
|
|
*/
|
548 |
|
|
void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, unsigned int timeout);
|
549 |
|
|
|
550 |
|
|
/*
|
551 |
|
|
* Error reporting, in human readable form (luxurious, but a memory hog).
|
552 |
|
|
*/
|
553 |
|
|
byte ide_dump_status (ide_drive_t *drive, const char *msg, byte stat);
|
554 |
|
|
|
555 |
|
|
/*
|
556 |
|
|
* ide_error() takes action based on the error returned by the controller.
|
557 |
|
|
* The calling function must return afterwards, to restart the request.
|
558 |
|
|
*/
|
559 |
|
|
void ide_error (ide_drive_t *drive, const char *msg, byte stat);
|
560 |
|
|
|
561 |
|
|
/*
|
562 |
|
|
* ide_fixstring() cleans up and (optionally) byte-swaps a text string,
|
563 |
|
|
* removing leading/trailing blanks and compressing internal blanks.
|
564 |
|
|
* It is primarily used to tidy up the model name/number fields as
|
565 |
|
|
* returned by the WIN_[P]IDENTIFY commands.
|
566 |
|
|
*/
|
567 |
|
|
void ide_fixstring (byte *s, const int bytecount, const int byteswap);
|
568 |
|
|
|
569 |
|
|
/*
|
570 |
|
|
* This routine busy-waits for the drive status to be not "busy".
|
571 |
|
|
* It then checks the status for all of the "good" bits and none
|
572 |
|
|
* of the "bad" bits, and if all is okay it returns 0. All other
|
573 |
|
|
* cases return 1 after invoking ide_error() -- caller should return.
|
574 |
|
|
*
|
575 |
|
|
*/
|
576 |
|
|
int ide_wait_stat (ide_drive_t *drive, byte good, byte bad, unsigned long timeout);
|
577 |
|
|
|
578 |
|
|
/*
|
579 |
|
|
* This routine is called from the partition-table code in genhd.c
|
580 |
|
|
* to "convert" a drive to a logical geometry with fewer than 1024 cyls.
|
581 |
|
|
*
|
582 |
|
|
* The second parameter, "xparm", determines exactly how the translation
|
583 |
|
|
* will be handled:
|
584 |
|
|
* 0 = convert to CHS with fewer than 1024 cyls
|
585 |
|
|
* using the same method as Ontrack DiskManager.
|
586 |
|
|
* 1 = same as "0", plus offset everything by 63 sectors.
|
587 |
|
|
* -1 = similar to "0", plus redirect sector 0 to sector 1.
|
588 |
|
|
* >1 = convert to a CHS geometry with "xparm" heads.
|
589 |
|
|
*
|
590 |
|
|
* Returns 0 if the translation was not possible, if the device was not
|
591 |
|
|
* an IDE disk drive, or if a geometry was "forced" on the commandline.
|
592 |
|
|
* Returns 1 if the geometry translation was successful.
|
593 |
|
|
*/
|
594 |
|
|
int ide_xlate_1024 (kdev_t, int, const char *);
|
595 |
|
|
|
596 |
|
|
/*
|
597 |
|
|
* Start a reset operation for an IDE interface.
|
598 |
|
|
* The caller should return immediately after invoking this.
|
599 |
|
|
*/
|
600 |
|
|
void ide_do_reset (ide_drive_t *);
|
601 |
|
|
|
602 |
|
|
/*
|
603 |
|
|
* This function is intended to be used prior to invoking ide_do_drive_cmd().
|
604 |
|
|
*/
|
605 |
|
|
void ide_init_drive_cmd (struct request *rq);
|
606 |
|
|
|
607 |
|
|
/*
|
608 |
|
|
* "action" parameter type for ide_do_drive_cmd() below.
|
609 |
|
|
*/
|
610 |
|
|
typedef enum
|
611 |
|
|
{ide_wait, /* insert rq at end of list, and wait for it */
|
612 |
|
|
ide_next, /* insert rq immediately after current request */
|
613 |
|
|
ide_preempt, /* insert rq in front of current request */
|
614 |
|
|
ide_end} /* insert rq at end of list, but don't wait for it */
|
615 |
|
|
ide_action_t;
|
616 |
|
|
|
617 |
|
|
/*
|
618 |
|
|
* This function issues a special IDE device request
|
619 |
|
|
* onto the request queue.
|
620 |
|
|
*
|
621 |
|
|
* If action is ide_wait, then the rq is queued at the end of the
|
622 |
|
|
* request queue, and the function sleeps until it has been processed.
|
623 |
|
|
* This is for use when invoked from an ioctl handler.
|
624 |
|
|
*
|
625 |
|
|
* If action is ide_preempt, then the rq is queued at the head of
|
626 |
|
|
* the request queue, displacing the currently-being-processed
|
627 |
|
|
* request and this function returns immediately without waiting
|
628 |
|
|
* for the new rq to be completed. This is VERY DANGEROUS, and is
|
629 |
|
|
* intended for careful use by the ATAPI tape/cdrom driver code.
|
630 |
|
|
*
|
631 |
|
|
* If action is ide_next, then the rq is queued immediately after
|
632 |
|
|
* the currently-being-processed-request (if any), and the function
|
633 |
|
|
* returns without waiting for the new rq to be completed. As above,
|
634 |
|
|
* This is VERY DANGEROUS, and is intended for careful use by the
|
635 |
|
|
* ATAPI tape/cdrom driver code.
|
636 |
|
|
*
|
637 |
|
|
* If action is ide_end, then the rq is queued at the end of the
|
638 |
|
|
* request queue, and the function returns immediately without waiting
|
639 |
|
|
* for the new rq to be completed. This is again intended for careful
|
640 |
|
|
* use by the ATAPI tape/cdrom driver code. (Currently used by ide-tape.c,
|
641 |
|
|
* when operating in the pipelined operation mode).
|
642 |
|
|
*/
|
643 |
|
|
int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t action);
|
644 |
|
|
|
645 |
|
|
/*
|
646 |
|
|
* Clean up after success/failure of an explicit drive cmd.
|
647 |
|
|
* stat/err are used only when (HWGROUP(drive)->rq->cmd == IDE_DRIVE_CMD).
|
648 |
|
|
*/
|
649 |
|
|
void ide_end_drive_cmd (ide_drive_t *drive, byte stat, byte err);
|
650 |
|
|
|
651 |
|
|
/*
|
652 |
|
|
* ide_system_bus_speed() returns what we think is the system VESA/PCI
|
653 |
|
|
* bus speed (in Mhz). This is used for calculating interface PIO timings.
|
654 |
|
|
* The default is 40 for known PCI systems, 50 otherwise.
|
655 |
|
|
* The "idebus=xx" parameter can be used to override this value.
|
656 |
|
|
*/
|
657 |
|
|
int ide_system_bus_speed (void);
|
658 |
|
|
|
659 |
|
|
/*
|
660 |
|
|
* ide_multwrite() transfers a block of up to mcount sectors of data
|
661 |
|
|
* to a drive as part of a disk multwrite operation.
|
662 |
|
|
*/
|
663 |
|
|
void ide_multwrite (ide_drive_t *drive, unsigned int mcount);
|
664 |
|
|
|
665 |
|
|
#ifdef CONFIG_BLK_DEV_IDECD
|
666 |
|
|
/*
|
667 |
|
|
* These are routines in ide-cd.c invoked from ide.c
|
668 |
|
|
*/
|
669 |
|
|
void ide_do_rw_cdrom (ide_drive_t *, unsigned long);
|
670 |
|
|
int ide_cdrom_ioctl (ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
|
671 |
|
|
int ide_cdrom_check_media_change (ide_drive_t *);
|
672 |
|
|
int ide_cdrom_open (struct inode *, struct file *, ide_drive_t *);
|
673 |
|
|
void ide_cdrom_release (struct inode *, struct file *, ide_drive_t *);
|
674 |
|
|
void ide_cdrom_setup (ide_drive_t *);
|
675 |
|
|
#endif /* CONFIG_BLK_DEV_IDECD */
|
676 |
|
|
|
677 |
|
|
#ifdef CONFIG_BLK_DEV_IDETAPE
|
678 |
|
|
|
679 |
|
|
/*
|
680 |
|
|
* Functions in ide-tape.c which are invoked from ide.c:
|
681 |
|
|
*/
|
682 |
|
|
|
683 |
|
|
/*
|
684 |
|
|
* idetape_identify_device is called during device probing stage to
|
685 |
|
|
* probe for an ide atapi tape drive and to initialize global variables
|
686 |
|
|
* in ide-tape.c which provide the link between the character device
|
687 |
|
|
* and the corresponding block device.
|
688 |
|
|
*
|
689 |
|
|
* Returns 1 if an ide tape was detected and is supported.
|
690 |
|
|
* Returns 0 otherwise.
|
691 |
|
|
*/
|
692 |
|
|
|
693 |
|
|
int idetape_identify_device (ide_drive_t *drive,struct hd_driveid *id);
|
694 |
|
|
|
695 |
|
|
/*
|
696 |
|
|
* idetape_setup is called a bit later than idetape_identify_device,
|
697 |
|
|
* during the search for disk partitions, to initialize various tape
|
698 |
|
|
* state variables in ide_drive_t *drive.
|
699 |
|
|
*/
|
700 |
|
|
|
701 |
|
|
void idetape_setup (ide_drive_t *drive);
|
702 |
|
|
|
703 |
|
|
/*
|
704 |
|
|
* idetape_do_request is our request function. It is called by ide.c
|
705 |
|
|
* to process a new request.
|
706 |
|
|
*/
|
707 |
|
|
|
708 |
|
|
void idetape_do_request (ide_drive_t *drive, struct request *rq, unsigned long block);
|
709 |
|
|
|
710 |
|
|
/*
|
711 |
|
|
* idetape_end_request is used to finish servicing a request, and to
|
712 |
|
|
* insert a pending pipeline request into the main device queue.
|
713 |
|
|
*/
|
714 |
|
|
|
715 |
|
|
void idetape_end_request (byte uptodate, ide_hwgroup_t *hwgroup);
|
716 |
|
|
|
717 |
|
|
/*
|
718 |
|
|
* Block device interface functions.
|
719 |
|
|
*/
|
720 |
|
|
|
721 |
|
|
int idetape_blkdev_ioctl (ide_drive_t *drive, struct inode *inode, struct file *file,
|
722 |
|
|
unsigned int cmd, unsigned long arg);
|
723 |
|
|
int idetape_blkdev_open (struct inode *inode, struct file *filp, ide_drive_t *drive);
|
724 |
|
|
void idetape_blkdev_release (struct inode *inode, struct file *filp, ide_drive_t *drive);
|
725 |
|
|
|
726 |
|
|
/*
|
727 |
|
|
* idetape_register_chrdev initializes the character device interface to
|
728 |
|
|
* the ide tape drive.
|
729 |
|
|
*/
|
730 |
|
|
|
731 |
|
|
void idetape_register_chrdev (void);
|
732 |
|
|
|
733 |
|
|
#endif /* CONFIG_BLK_DEV_IDETAPE */
|
734 |
|
|
|
735 |
|
|
#ifdef CONFIG_BLK_DEV_IDEFLOPPY
|
736 |
|
|
int idefloppy_identify_device (ide_drive_t *drive,struct hd_driveid *id);
|
737 |
|
|
void idefloppy_setup (ide_drive_t *drive);
|
738 |
|
|
void idefloppy_do_request (ide_drive_t *drive, struct request *rq, unsigned long block);
|
739 |
|
|
void idefloppy_end_request (byte uptodate, ide_hwgroup_t *hwgroup);
|
740 |
|
|
int idefloppy_ioctl (ide_drive_t *drive, struct inode *inode, struct file *file,
|
741 |
|
|
unsigned int cmd, unsigned long arg);
|
742 |
|
|
int idefloppy_open (struct inode *inode, struct file *filp, ide_drive_t *drive);
|
743 |
|
|
void idefloppy_release (struct inode *inode, struct file *filp, ide_drive_t *drive);
|
744 |
|
|
int idefloppy_media_change (ide_drive_t *drive);
|
745 |
|
|
unsigned long idefloppy_capacity (ide_drive_t *drive);
|
746 |
|
|
#endif /* CONFIG_BLK_DEV_IDEFLOPPY */
|
747 |
|
|
|
748 |
|
|
#ifdef CONFIG_BLK_DEV_IDESCSI
|
749 |
|
|
void idescsi_setup (ide_drive_t *drive);
|
750 |
|
|
void idescsi_do_request (ide_drive_t *drive, struct request *rq, unsigned long block);
|
751 |
|
|
void idescsi_end_request (byte uptodate, ide_hwgroup_t *hwgroup);
|
752 |
|
|
int idescsi_ioctl (ide_drive_t *drive, struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
|
753 |
|
|
int idescsi_open (struct inode *inode, struct file *filp, ide_drive_t *drive);
|
754 |
|
|
void idescsi_ide_release (struct inode *inode, struct file *filp, ide_drive_t *drive);
|
755 |
|
|
#endif /* CONFIG_BLK_DEV_IDESCSI */
|
756 |
|
|
|
757 |
|
|
#ifdef CONFIG_BLK_DEV_TRITON
|
758 |
|
|
void ide_init_triton (byte, byte);
|
759 |
|
|
#endif /* CONFIG_BLK_DEV_TRITON */
|