1 /* 2 * linux/drivers/block/ide.h 3 * 4 * Copyright (C) 1994, 1995 Linus Torvalds & authors 5 */ 6
7 /* 8 * This is the multiple IDE interface driver, as evolved from hd.c. 9 * It supports up to four IDE interfaces, on one or more IRQs (usually 14 & 15). 10 * There can be up to two drives per interface, as per the ATA-2 spec. 11 * 12 * Primary i/f: ide0: major=3; (hda) minor=0; (hdb) minor=64 13 * Secondary i/f: ide1: major=22; (hdc or hd1a) minor=0; (hdd or hd1b) minor=64 14 * Tertiary i/f: ide2: major=33; (hde) minor=0; (hdf) minor=64 15 * Quaternary i/f: ide3: major=34; (hdg) minor=0; (hdh) minor=64 16 */ 17
18 /****************************************************************************** 19 * IDE driver configuration options (play with these as desired): 20 */ 21 #undefREALLY_SLOW_IO/* most systems can safely undef this */ 22 #include <asm/io.h>
23
24 #defineREALLY_FAST_IO/* define if ide ports are perfect */ 25 #defineINITIAL_MULT_COUNT 0 /* off=0; on=2,4,8,16,32, etc.. */ 26
27 #ifndefDISK_RECOVERY_TIME/* off=0; on=access_delay_time */ 28 #defineDISK_RECOVERY_TIME 0 /* for hardware that needs it */ 29 #endif 30 #ifndefOK_TO_RESET_CONTROLLER/* 1 needed for good error recovery */ 31 #defineOK_TO_RESET_CONTROLLER 1 /* 0 for use with AH2372A/B interface */ 32 #endif 33 #ifndefSUPPORT_DTC2278/* 1 to support DTC2278 chipset */ 34 #defineSUPPORT_DTC2278 1 /* 0 to reduce kernel size */ 35 #endif 36 #ifndefFANCY_STATUS_DUMPS/* 1 for human-readable drive errors */ 37 #defineFANCY_STATUS_DUMPS 1 /* 0 to reduce kernel size */ 38 #endif 39
40 /* 41 * IDE_DRIVE_CMD is used to implement many features of the hdparm utility 42 */ 43 #defineIDE_DRIVE_CMD 99 /* (magic) undef to reduce kernel size*/ 44
45 /* 46 * "No user-serviceable parts" beyond this point :) 47 *****************************************************************************/ 48
49 typedefunsignedcharbyte; /* used everywhere */ 50
51 /* 52 * Probably not wise to fiddle with these 53 */ 54 #defineERROR_MAX 8 /* Max read/write errors per sector */ 55 #defineERROR_RESET 3 /* Reset controller every 4th retry */ 56 #defineERROR_RECAL 1 /* Recalibrate every 2nd retry */ 57
58 /* 59 * Ensure that various configuration flags have compatible settings 60 */ 61 #ifdefREALLY_SLOW_IO 62 #undefREALLY_FAST_IO 63 #endif 64
65 /* 66 * Definitions for accessing IDE controller registers 67 */ 68
69 #defineHWIF(drive) ((ide_hwif_t *)drive->hwif)
70 #defineHWGROUP(drive) ((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
71
72 #defineIDE_DATA_REG (HWIF(drive)->io_base)
73 #defineIDE_ERROR_REG (HWIF(drive)->io_base+1)
74 #defineIDE_NSECTOR_REG (HWIF(drive)->io_base+2)
75 #defineIDE_SECTOR_REG (HWIF(drive)->io_base+3)
76 #defineIDE_LCYL_REG (HWIF(drive)->io_base+4)
77 #defineIDE_HCYL_REG (HWIF(drive)->io_base+5)
78 #defineIDE_SELECT_REG (HWIF(drive)->io_base+6)
79 #defineIDE_STATUS_REG (HWIF(drive)->io_base+7)
80 #defineIDE_CONTROL_REG (HWIF(drive)->ctl_port)
81 #defineIDE_FEATURE_REGIDE_ERROR_REG 82 #defineIDE_COMMAND_REGIDE_STATUS_REG 83 #defineIDE_ALTSTATUS_REGIDE_CONTROL_REG 84
85 #ifdefREALLY_FAST_IO 86 #defineOUT_BYTE(b,p) outb((b),p)
87 #defineIN_BYTE(p) (byte)inb(p)
88 #else 89 #defineOUT_BYTE(b,p) outb_p((b),p)
90 #defineIN_BYTE(p) (byte)inb_p(p)
91 #endif/* REALLY_FAST_IO */ 92
93 #defineGET_ERR() IN_BYTE(IDE_ERROR_REG)
94 #defineGET_STAT() IN_BYTE(IDE_STATUS_REG)
95 #defineOK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good))
96 #defineBAD_R_STAT (BUSY_STAT | ERR_STAT)
97 #defineBAD_W_STAT (BAD_R_STAT | WRERR_STAT)
98 #defineBAD_STAT (BAD_R_STAT | DRQ_STAT)
99 #defineDRIVE_READY (READY_STAT | SEEK_STAT)
100 #defineDATA_READY (DRIVE_READY | DRQ_STAT)
101
102 /* 103 * Some more useful definitions 104 */ 105 #defineIDE_MAJOR_NAME "ide" /* the same for all i/f; see also genhd.c */ 106 #define MAJOR_NAME IDE_MAJOR_NAME 107 #definePARTN_BITS 6 /* number of minor dev bits for partitions */ 108 #definePARTN_MASK ((1<<PARTN_BITS)-1) /* a useful bit mask */ 109 #defineMAX_DRIVES 2 /* per interface; 2 assumed by lots of code */ 110 #defineMAX_HWIFS 4 /* an arbitrary, but realistic limit */ 111 #defineSECTOR_WORDS (512 / 4) /* number of 32bit words per sector */ 112
113 /* 114 * Timeouts for various operations: 115 */ 116 #defineWAIT_DRQ (5*HZ/100) /* 50msec - spec allows up to 20ms */ 117 #defineWAIT_READY (3*HZ/100) /* 30msec - should be instantaneous */ 118 #defineWAIT_PIDENTIFY (1*HZ) /* 1sec - should be less than 3ms (?) */ 119 #defineWAIT_WORSTCASE (30*HZ) /* 30sec - worst case when spinning up */ 120 #defineWAIT_CMD (10*HZ) /* 10sec - maximum wait for an IRQ to happen */ 121
122 #ifdefCONFIG_BLK_DEV_IDECD 123
124 structpacket_command{ 125 char *buffer;
126 intbuflen;
127 intstat;
128 unsignedcharc[12];
129 };
130
131
132 structatapi_request_sense{ 133 unsignedcharerror_code : 7;
134 unsignedcharvalid : 1;
135 bytereserved1;
136 unsignedcharsense_key : 4;
137 unsignedcharreserved2 : 1;
138 unsignedchar ili : 1;
139 unsignedcharreserved3 : 2;
140 byteinfo[4];
141 bytesense_len;
142 byte command_info[4];
143 byteasc;
144 byteascq;
145 byte fru;
146 byte sense_key_specific[3];
147 };
148
149 /* Space to hold the disk TOC. */ 150
151 #defineMAX_TRACKS 99
152 structatapi_toc_header{ 153 unsignedshorttoc_length;
154 bytefirst_track;
155 bytelast_track;
156 };
157
158 structatapi_toc_entry{ 159 bytereserved1;
160 unsignedcontrol : 4;
161 unsignedadr : 4;
162 bytetrack;
163 bytereserved2;
164 unsignedlba;
165 };
166
167 structatapi_toc{ 168 structatapi_toc_headerhdr;
169 structatapi_toc_entryent[MAX_TRACKS+1]; /* One extra for the leadout. */ 170 };
171
172 /* Extra per-device info for cdrom drives. */ 173 structcdrom_info{ 174
175 /* Buffer for table of contents. NULL if we haven't allocated 176 a TOC buffer for this device yet. */ 177
178 structatapi_toc *toc;
179
180 /* Sector buffer. If a read request wants only the first part of a cdrom 181 block, we cache the rest of the block here, in the expectation that that 182 data is going to be wanted soon. SECTOR_BUFFERED is the number of the 183 first buffered sector, and NSECTORS_BUFFERED is the number of sectors 184 in the buffer. Before the buffer is allocated, we should have 185 SECTOR_BUFFER == NULL and NSECTORS_BUFFERED == 0. */ 186
187 unsignedlongsector_buffered;
188 unsignedlongnsectors_buffered;
189 char *sector_buffer;
190
191 /* The result of the last successful request sense command 192 on this device. */ 193 structatapi_request_sensesense_data;
194 };
195
196 #endif/* CONFIG_BLK_DEV_IDECD */ 197
198 /* 199 * Now for the data we need to maintain per-drive: ide_drive_t 200 */ 201 typedefenum{disk, cdrom}media_t;
202
203 typedefunion{ 204 unsignedall : 8; /* all of the bits together */ 205 struct{ 206 unsignedset_geometry : 1; /* respecify drive geometry */ 207 unsignedrecalibrate : 1; /* seek to cyl 0 */ 208 unsignedset_multmode : 1; /* set multmode count */ 209 unsignedreserved : 5; /* unused */ 210 }b;
211 }special_t;
212
213 typedefunion{ 214 unsignedall : 8; /* all of the bits together */ 215 struct{ 216 unsignedhead : 4; /* always zeros here */ 217 unsignedunit : 1; /* drive select number, 0 or 1 */ 218 unsigned bit5 : 1; /* always 1 */ 219 unsignedlba : 1; /* using LBA instead of CHS */ 220 unsigned bit7 : 1; /* always 1 */ 221 }b;
222 }select_t;
223
224 typedefstruct ide_drive_s { 225 special_tspecial; /* special action flags */ 226 unsignedpresent : 1; /* drive is physically present */ 227 unsignednoprobe : 1; /* from: hdx=noprobe */ 228 unsignedkeep_settings : 1; /* restore settings after drive reset */ 229 unsignedbusy : 1; /* currently doing revalidate_disk() */ 230 unsignedvlb_32bit : 1; /* use 32bit in/out for data */ 231 unsignedvlb_sync : 1; /* needed for some 32bit chip sets */ 232 unsignedremoveable : 1; /* 1 if need to do check_media_change */ 233 unsigned dma_capable : 1; /* for Intel Triton chipset, others.. */ 234 select_tselect; /* basic drive/head select reg value */ 235 byteunmask; /* flag: okay to unmask other irqs */ 236 void *hwif; /* actually (ide_hwif_t *) */ 237 bytectl; /* "normal" value for IDE_CONTROL_REG */ 238 byteready_stat; /* min status value for drive ready */ 239 bytewpcom; /* ignored by all IDE drives */ 240 media_tmedia; /* disk, cdrom, tape */ 241 bytemult_count; /* current multiple sector setting */ 242 bytemult_req; /* requested multiple sector setting */ 243 bytechipset; /* interface chipset access method */ 244 bytebad_wstat; /* used for ignoring WRERR_STAT */ 245 bytesect0; /* offset of first sector for DM6:DDO */ 246 byteusage; /* current "open()" count for drive */ 247 bytehead; /* "real" number of heads */ 248 bytesect; /* "real" sectors per track */ 249 bytebios_head; /* BIOS/fdisk/LILO number of heads */ 250 bytebios_sect; /* BIOS/fdisk/LILO sectors per track */ 251 unsignedshortbios_cyl; /* BIOS/fdisk/LILO number of cyls */ 252 unsignedshortcyl; /* "real" number of cyls */ 253 structwait_queue *wqueue; /* used to wait for drive in open() */ 254 structhd_driveid *id; /* drive model identification info */ 255 structhd_struct *part; /* drive partition table */ 256 charname[4]; /* drive name, such as "hda" */ 257 #ifdefCONFIG_BLK_DEV_IDECD 258 structcdrom_infocdrom_info; /* from ide-cd.c */ 259 #endif/* CONFIG_BLK_DEV_IDECD */ 260 }ide_drive_t;
261
262 typedefstructhwif_s{ 263 structhwif_s *next; /* for linked-list in ide_hwgroup_t */ 264 void *hwgroup; /* actually (ide_hwgroup_t *) */ 265 unsignedshortio_base; /* base io port addr */ 266 unsignedshortctl_port; /* usually io_base+0x206 */ 267 ide_drive_tdrives[MAX_DRIVES]; /* drive info */ 268 structgendisk *gd; /* gendisk structure */ 269 byteirq; /* our irq number */ 270 bytemajor; /* our major number */ 271 byte drivecount; /* how many drives attached */ 272 charname[5]; /* name of interface, eg. "ide0" */ 273 unsignednoprobe : 1; /* don't probe for this interface */ 274 unsignedpresent : 1; /* this interface exists */ 275 unsignedlongreset_timeout; /* timeout value during ide resets */ 276 #if (DISK_RECOVERY_TIME > 0)
277 unsignedlong last_timer; /* time when previous rq was done */ 278 #endif 279 #ifdefCONFIG_BLK_DEV_IDECD 280 structrequestrequest_sense_request; /* from ide-cd.c */ 281 structpacket_commandrequest_sense_pc; /* from ide-cd.c */ 282 #endif/* CONFIG_BLK_DEV_IDECD */ 283 }ide_hwif_t;
284
285 /* 286 * our internal interrupt handler type 287 */ 288 typedefvoid (ide_handler_t)(ide_drive_t *);
289
290 typedefstruct hwgroup_s { 291 ide_handler_t *handler;/* irq handler, if active */ 292 ide_drive_t *drive; /* current drive */ 293 ide_hwif_t *hwif; /* ptr to current hwif in linked-list */ 294 structrequest *rq; /* current request */ 295 structtimer_listtimer; /* failsafe timer */ 296 structrequestwrq; /* local copy of current write rq */ 297 }ide_hwgroup_t;
298
299 /* 300 * One final include file, which references some of the data/defns from above 301 */ 302 #defineIDE_DRIVER/* "parameter" for blk.h */ 303 #include "blk.h"
304
305 #if (DISK_RECOVERY_TIME > 0)
306 voidide_set_recovery_timer (ide_hwif_t *);
307 #defineSET_RECOVERY_TIMER(drive) ide_set_recovery_timer (drive)
308 #else 309 #defineSET_RECOVERY_TIMER(drive)
310 #endif 311
312 /* 313 * The main (re-)entry point for handling a new request is IDE_DO_REQUEST. 314 * Note that IDE_DO_REQUEST should *only* ever be invoked from an interrupt 315 * handler. All others, such as a timer expiry handler, should call 316 * do_hwgroup_request() instead (currently local to ide.c). 317 */ 318 voidide_do_request (ide_hwgroup_t *);
319 #defineIDE_DO_REQUEST{SET_RECOVERY_TIMER(HWIF(drive)); ide_do_request(HWGROUP(drive)); } 320
321
322 /* 323 * This is used for (nearly) all data transfers from the IDE interface 324 */ 325 voidide_input_data (ide_drive_t *drive, void *buffer, unsignedintwcount);
326
327 /* 328 * This is used for (nearly) all data transfers to the IDE interface 329 */ 330 voidide_output_data (ide_drive_t *drive, void *buffer, unsignedintwcount);
331
332 /* 333 * This is used on exit from the driver, to designate the next irq handler 334 * and also to start the safety timer. 335 */ 336 voidide_set_handler (ide_drive_t *drive, ide_handler_t *handler);
337
338 /* 339 * Error reporting, in human readable form (luxurious, but a memory hog). 340 */ 341 byteide_dump_status (ide_drive_t *drive, constchar *msg, bytestat);
342
343 /* 344 * ide_error() takes action based on the error returned by the controller. 345 * 346 * Returns 1 if an ide reset operation has been initiated, in which case 347 * the caller MUST simply return from the driver (through however many levels). 348 * Returns 0 otherwise. 349 */ 350 intide_error (ide_drive_t *drive, constchar *msg, bytestat);
351
352 /* 353 * This routine busy-waits for the drive status to be not "busy". 354 * It then checks the status for all of the "good" bits and none 355 * of the "bad" bits, and if all is okay it returns 0. All other 356 * cases return 1 after invoking ide_error() 357 * 358 */ 359 intide_wait_stat (ide_drive_t *drive, bytegood, bytebad, unsignedlongtimeout);
360
361 /* 362 * This is called from genhd.c to correct DiskManager/EZ-Drive geometries 363 */ 364 intide_xlate_1024(dev_t, int, constchar *);
365
366 #ifdefCONFIG_BLK_DEV_IDECD 367 /* 368 * These are routines in ide-cd.c invoked from ide.c 369 */ 370 voidide_do_rw_cdrom (ide_drive_t *, unsignedlong);
371 intide_cdrom_ioctl (ide_drive_t *, structinode *, structfile *, unsignedint, unsignedlong);
372 intide_cdrom_check_media_change (ide_drive_t *);
373 intide_cdrom_open (structinode *, structfile *, ide_drive_t *);
374 voidide_cdrom_release (structinode *, structfile *, ide_drive_t *);
375 voidide_cdrom_setup (ide_drive_t *);
376 #endif/* CONFIG_BLK_DEV_IDECD */