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 * REALLY_SLOW_IO can be defined in ide.c and ide-cd.c, if necessary 22 */ 23 #undefREALLY_FAST_IO/* define if ide ports are perfect */ 24 #defineINITIAL_MULT_COUNT 0 /* off=0; on=2,4,8,16,32, etc.. */ 25
26 #ifndefDISK_RECOVERY_TIME/* off=0; on=access_delay_time */ 27 #defineDISK_RECOVERY_TIME 0 /* for hardware that needs it */ 28 #endif 29 #ifndefOK_TO_RESET_CONTROLLER/* 1 needed for good error recovery */ 30 #defineOK_TO_RESET_CONTROLLER 1 /* 0 for use with AH2372A/B interface */ 31 #endif 32 #ifndefFAKE_FDISK_FOR_EZDRIVE/* 1 to help linux fdisk with EZDRIVE */ 33 #defineFAKE_FDISK_FOR_EZDRIVE 1 /* 0 to reduce kernel size */ 34 #endif 35 #ifndefSUPPORT_RZ1000/* 1 to support RZ1000 chipset */ 36 #defineSUPPORT_RZ1000 1 /* 0 to reduce kernel size */ 37 #endif 38 #ifndefSUPPORT_CMD640/* 1 to support CMD640 chipset */ 39 #defineSUPPORT_CMD640 1 /* 0 to reduce kernel size */ 40 #endif 41 #ifndefSUPPORT_HT6560B/* 1 to support HT6560B chipset */ 42 #defineSUPPORT_HT6560B 1 /* 0 to reduce kernel size */ 43 #endif 44 #ifndefSUPPORT_DTC2278/* 1 to support DTC2278 chipset */ 45 #defineSUPPORT_DTC2278 1 /* 0 to reduce kernel size */ 46 #ifndefSET_DTC2278_MODE4 47 #defineSET_DTC2278_MODE4 0 /* 1 to init primary i/f for PIO mode4 */ 48 #endif 49 #endif 50 #ifndefFANCY_STATUS_DUMPS/* 1 for human-readable drive errors */ 51 #defineFANCY_STATUS_DUMPS 1 /* 0 to reduce kernel size */ 52 #endif 53
54 /* 55 * IDE_DRIVE_CMD is used to implement many features of the hdparm utility 56 */ 57 #defineIDE_DRIVE_CMD 99 /* (magic) undef to reduce kernel size*/ 58
59 /* 60 * "No user-serviceable parts" beyond this point :) 61 *****************************************************************************/ 62
63 typedefunsignedcharbyte; /* used everywhere */ 64
65 /* 66 * Probably not wise to fiddle with these 67 */ 68 #defineERROR_MAX 8 /* Max read/write errors per sector */ 69 #defineERROR_RESET 3 /* Reset controller every 4th retry */ 70 #defineERROR_RECAL 1 /* Recalibrate every 2nd retry */ 71
72 /* 73 * Ensure that various configuration flags have compatible settings 74 */ 75 #ifdefREALLY_SLOW_IO 76 #undefREALLY_FAST_IO 77 #endif 78
79 /* 80 * Definitions for accessing IDE controller registers 81 */ 82
83 #defineHWIF(drive) ((ide_hwif_t *)drive->hwif)
84 #defineHWGROUP(drive) ((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
85
86 #defineIDE_DATA_OFFSET (0)
87 #defineIDE_ERROR_OFFSET (1)
88 #defineIDE_NSECTOR_OFFSET (2)
89 #defineIDE_SECTOR_OFFSET (3)
90 #defineIDE_LCYL_OFFSET (4)
91 #defineIDE_HCYL_OFFSET (5)
92 #defineIDE_SELECT_OFFSET (6)
93 #defineIDE_STATUS_OFFSET (7)
94 #defineIDE_FEATURE_OFFSETIDE_ERROR_OFFSET 95 #defineIDE_COMMAND_OFFSETIDE_STATUS_OFFSET 96
97 #defineIDE_DATA_REG (HWIF(drive)->io_base+IDE_DATA_OFFSET)
98 #defineIDE_ERROR_REG (HWIF(drive)->io_base+IDE_ERROR_OFFSET)
99 #defineIDE_NSECTOR_REG (HWIF(drive)->io_base+IDE_NSECTOR_OFFSET)
100 #defineIDE_SECTOR_REG (HWIF(drive)->io_base+IDE_SECTOR_OFFSET)
101 #defineIDE_LCYL_REG (HWIF(drive)->io_base+IDE_LCYL_OFFSET)
102 #defineIDE_HCYL_REG (HWIF(drive)->io_base+IDE_HCYL_OFFSET)
103 #defineIDE_SELECT_REG (HWIF(drive)->io_base+IDE_SELECT_OFFSET)
104 #defineIDE_STATUS_REG (HWIF(drive)->io_base+IDE_STATUS_OFFSET)
105 #defineIDE_CONTROL_REG (HWIF(drive)->ctl_port)
106 #defineIDE_FEATURE_REGIDE_ERROR_REG 107 #defineIDE_COMMAND_REGIDE_STATUS_REG 108 #defineIDE_ALTSTATUS_REGIDE_CONTROL_REG 109
110 #ifdefREALLY_FAST_IO 111 #defineOUT_BYTE(b,p) outb((b),p)
112 #defineIN_BYTE(p) (byte)inb(p)
113 #else 114 #defineOUT_BYTE(b,p) outb_p((b),p)
115 #defineIN_BYTE(p) (byte)inb_p(p)
116 #endif/* REALLY_FAST_IO */ 117
118 #defineGET_ERR() IN_BYTE(IDE_ERROR_REG)
119 #defineGET_STAT() IN_BYTE(IDE_STATUS_REG)
120 #defineOK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good))
121 #defineBAD_R_STAT (BUSY_STAT | ERR_STAT)
122 #defineBAD_W_STAT (BAD_R_STAT | WRERR_STAT)
123 #defineBAD_STAT (BAD_R_STAT | DRQ_STAT)
124 #defineDRIVE_READY (READY_STAT | SEEK_STAT)
125 #defineDATA_READY (DRIVE_READY | DRQ_STAT)
126
127 /* 128 * Some more useful definitions 129 */ 130 #defineIDE_MAJOR_NAME "ide" /* the same for all i/f; see also genhd.c */ 131 #define MAJOR_NAME IDE_MAJOR_NAME 132 #definePARTN_BITS 6 /* number of minor dev bits for partitions */ 133 #definePARTN_MASK ((1<<PARTN_BITS)-1) /* a useful bit mask */ 134 #defineMAX_DRIVES 2 /* per interface; 2 assumed by lots of code */ 135 #defineMAX_HWIFS 4 /* an arbitrary, but realistic limit */ 136 #defineSECTOR_WORDS (512 / 4) /* number of 32bit words per sector */ 137
138 /* 139 * Timeouts for various operations: 140 */ 141 #defineWAIT_DRQ (5*HZ/100) /* 50msec - spec allows up to 20ms */ 142 #defineWAIT_READY (3*HZ/100) /* 30msec - should be instantaneous */ 143 #defineWAIT_PIDENTIFY (1*HZ) /* 1sec - should be less than 3ms (?) */ 144 #defineWAIT_WORSTCASE (30*HZ) /* 30sec - worst case when spinning up */ 145 #defineWAIT_CMD (10*HZ) /* 10sec - maximum wait for an IRQ to happen */ 146
147 #ifdefCONFIG_BLK_DEV_IDECD 148
149 structatapi_request_sense{ 150 unsignedcharerror_code : 7;
151 unsignedcharvalid : 1;
152 bytereserved1;
153 unsignedcharsense_key : 4;
154 unsignedcharreserved2 : 1;
155 unsignedchar ili : 1;
156 unsignedcharreserved3 : 2;
157 byteinfo[4];
158 bytesense_len;
159 byte command_info[4];
160 byteasc;
161 byteascq;
162 byte fru;
163 bytesense_key_specific[3];
164 };
165
166 structpacket_command{ 167 char *buffer;
168 intbuflen;
169 intstat;
170 structatapi_request_sense *sense_data;
171 unsignedcharc[12];
172 };
173
174 /* Space to hold the disk TOC. */ 175
176 #defineMAX_TRACKS 99
177 structatapi_toc_header{ 178 unsignedshorttoc_length;
179 bytefirst_track;
180 bytelast_track;
181 };
182
183 structatapi_toc_entry{ 184 bytereserved1;
185 unsignedcontrol : 4;
186 unsignedadr : 4;
187 bytetrack;
188 bytereserved2;
189 unsignedlba;
190 };
191
192 structatapi_toc{ 193 intlast_session_lba;
194 intxa_flag;
195 unsignedcapacity;
196 structatapi_toc_headerhdr;
197 structatapi_toc_entryent[MAX_TRACKS+1]; /* One extra for the leadout. */ 198 };
199
200 /* Extra per-device info for cdrom drives. */ 201 structcdrom_info{ 202
203 /* Buffer for table of contents. NULL if we haven't allocated 204 a TOC buffer for this device yet. */ 205
206 structatapi_toc *toc;
207
208 /* Sector buffer. If a read request wants only the first part of a cdrom 209 block, we cache the rest of the block here, in the expectation that that 210 data is going to be wanted soon. SECTOR_BUFFERED is the number of the 211 first buffered sector, and NSECTORS_BUFFERED is the number of sectors 212 in the buffer. Before the buffer is allocated, we should have 213 SECTOR_BUFFER == NULL and NSECTORS_BUFFERED == 0. */ 214
215 unsignedlongsector_buffered;
216 unsignedlongnsectors_buffered;
217 char *sector_buffer;
218
219 /* The result of the last successful request sense command 220 on this device. */ 221 structatapi_request_sensesense_data;
222 };
223
224 #endif/* CONFIG_BLK_DEV_IDECD */ 225
226 /* 227 * Now for the data we need to maintain per-drive: ide_drive_t 228 */ 229 typedefenum{disk, cdrom}media_t;
230
231 typedefunion{ 232 unsignedall : 8; /* all of the bits together */ 233 struct{ 234 unsignedset_geometry : 1; /* respecify drive geometry */ 235 unsignedrecalibrate : 1; /* seek to cyl 0 */ 236 unsignedset_multmode : 1; /* set multmode count */ 237 unsignedreserved : 5; /* unused */ 238 }b;
239 }special_t;
240
241 typedefunion{ 242 unsignedall : 8; /* all of the bits together */ 243 struct{ 244 unsignedhead : 4; /* always zeros here */ 245 unsignedunit : 1; /* drive select number, 0 or 1 */ 246 unsigned bit5 : 1; /* always 1 */ 247 unsignedlba : 1; /* using LBA instead of CHS */ 248 unsigned bit7 : 1; /* always 1 */ 249 }b;
250 }select_t;
251
252 typedefstruct ide_drive_s { 253 special_tspecial; /* special action flags */ 254 #ifFAKE_FDISK_FOR_EZDRIVE 255 unsignedezdrive : 1; /* flag: partitioned with ezdrive */ 256 #endif/* FAKE_FDISK_FOR_EZDRIVE */ 257 unsignedpresent : 1; /* drive is physically present */ 258 unsignednoprobe : 1; /* from: hdx=noprobe */ 259 unsignedkeep_settings : 1; /* restore settings after drive reset */ 260 unsignedbusy : 1; /* currently doing revalidate_disk() */ 261 unsignedvlb_32bit : 1; /* use 32bit in/out for data */ 262 unsignedvlb_sync : 1; /* needed for some 32bit chip sets */ 263 unsignedremoveable : 1; /* 1 if need to do check_media_change */ 264 unsignedusing_dma : 1; /* disk is using dma for read/write */ 265 unsignedunmask : 1; /* flag: okay to unmask other irqs */ 266 media_tmedia; /* disk, cdrom, tape */ 267 select_tselect; /* basic drive/head select reg value */ 268 void *hwif; /* actually (ide_hwif_t *) */ 269 bytectl; /* "normal" value for IDE_CONTROL_REG */ 270 byteready_stat; /* min status value for drive ready */ 271 bytemult_count; /* current multiple sector setting */ 272 bytemult_req; /* requested multiple sector setting */ 273 bytechipset; /* interface chipset access method */ 274 bytebad_wstat; /* used for ignoring WRERR_STAT */ 275 bytesect0; /* offset of first sector for DM6:DDO */ 276 byteusage; /* current "open()" count for drive */ 277 bytehead; /* "real" number of heads */ 278 bytesect; /* "real" sectors per track */ 279 bytebios_head; /* BIOS/fdisk/LILO number of heads */ 280 bytebios_sect; /* BIOS/fdisk/LILO sectors per track */ 281 unsignedshortbios_cyl; /* BIOS/fdisk/LILO number of cyls */ 282 unsignedshortcyl; /* "real" number of cyls */ 283 structwait_queue *wqueue; /* used to wait for drive in open() */ 284 structhd_driveid *id; /* drive model identification info */ 285 structhd_struct *part; /* drive partition table */ 286 charname[4]; /* drive name, such as "hda" */ 287 #ifdefCONFIG_BLK_DEV_IDECD 288 structcdrom_infocdrom_info; /* from ide-cd.c */ 289 #endif/* CONFIG_BLK_DEV_IDECD */ 290 }ide_drive_t;
291
292 /* 293 * An ide_dmaproc_t() initiates/aborts DMA read/write operations on a drive. 294 * 295 * The caller is assumed to have selected the drive and programmed the drive's 296 * sector address using CHS or LBA. All that remains is to prepare for DMA 297 * and then issue the actual read/write DMA/PIO command to the drive. 298 * 299 * Returns 0 if all went well. 300 * Returns 1 if DMA read/write could not be started, in which case the caller 301 * should either try again later, or revert to PIO for the current request. 302 */ 303 typedefenum{ide_dma_read = 0, ide_dma_write = 1, ide_dma_abort = 2, ide_dma_check = 3}ide_dma_action_t;
304 typedefint (ide_dmaproc_t)(ide_dma_action_t, ide_drive_t *);
305
306 typedefstructhwif_s{ 307 structhwif_s *next; /* for linked-list in ide_hwgroup_t */ 308 void *hwgroup; /* actually (ide_hwgroup_t *) */ 309 unsignedshortio_base; /* base io port addr */ 310 unsignedshortctl_port; /* usually io_base+0x206 */ 311 ide_drive_tdrives[MAX_DRIVES]; /* drive info */ 312 structgendisk *gd; /* gendisk structure */ 313 ide_dmaproc_t *dmaproc; /* dma read/write/abort routine */ 314 unsignedlong *dmatable; /* dma physical region descriptor table */ 315 unsignedshortdma_base; /* base addr for dma ports (triton) */ 316 byteirq; /* our irq number */ 317 bytemajor; /* our major number */ 318 byteselect; /* pri/sec hwif select for ht6560b */ 319 charname[5]; /* name of interface, eg. "ide0" */ 320 unsignednoprobe : 1; /* don't probe for this interface */ 321 unsignedpresent : 1; /* this interface exists */ 322 #if (DISK_RECOVERY_TIME > 0)
323 unsignedlonglast_time; /* time when previous rq was done */ 324 #endif 325 #ifdefCONFIG_BLK_DEV_IDECD 326 structrequestrequest_sense_request; /* from ide-cd.c */ 327 structpacket_commandrequest_sense_pc; /* from ide-cd.c */ 328 #endif/* CONFIG_BLK_DEV_IDECD */ 329 }ide_hwif_t;
330
331 /* 332 * internal ide interrupt handler type 333 */ 334 typedefvoid (ide_handler_t)(ide_drive_t *);
335
336 typedefstruct hwgroup_s { 337 ide_handler_t *handler;/* irq handler, if active */ 338 ide_drive_t *drive; /* current drive */ 339 ide_hwif_t *hwif; /* ptr to current hwif in linked-list */ 340 structrequest *rq; /* current request */ 341 structtimer_listtimer; /* failsafe timer */ 342 structrequestwrq; /* local copy of current write rq */ 343 unsignedlongreset_timeout; /* timeout value during ide resets */ 344 #ifdefCONFIG_BLK_DEV_IDECD 345 intdoing_atapi_reset;
346 #endif/* CONFIG_BLK_DEV_IDECD */ 347 }ide_hwgroup_t;
348
349 /* 350 * One final include file, which references some of the data/defns from above 351 */ 352 #defineIDE_DRIVER/* "parameter" for blk.h */ 353 #include "blk.h"
354
355 #if (DISK_RECOVERY_TIME > 0)
356 voidide_set_recovery_timer (ide_hwif_t *);
357 #defineSET_RECOVERY_TIMER(drive) ide_set_recovery_timer (drive)
358 #else 359 #defineSET_RECOVERY_TIMER(drive)
360 #endif 361
362 /* 363 * The main (re-)entry point for handling a new request is IDE_DO_REQUEST. 364 * Note that IDE_DO_REQUEST should *only* ever be invoked from an interrupt 365 * handler. All others, such as a timer expiry handler, should call 366 * do_hwgroup_request() instead (currently local to ide.c). 367 */ 368 voidide_do_request (ide_hwgroup_t *);
369 #defineIDE_DO_REQUEST{SET_RECOVERY_TIMER(HWIF(drive)); ide_do_request(HWGROUP(drive)); } 370
371
372 /* 373 * This is used for (nearly) all data transfers from the IDE interface 374 */ 375 voidide_input_data (ide_drive_t *drive, void *buffer, unsignedintwcount);
376
377 /* 378 * This is used for (nearly) all data transfers to the IDE interface 379 */ 380 voidide_output_data (ide_drive_t *drive, void *buffer, unsignedintwcount);
381
382 /* 383 * This is used on exit from the driver, to designate the next irq handler 384 * and also to start the safety timer. 385 */ 386 voidide_set_handler (ide_drive_t *drive, ide_handler_t *handler);
387
388 /* 389 * Error reporting, in human readable form (luxurious, but a memory hog). 390 */ 391 byteide_dump_status (ide_drive_t *drive, constchar *msg, bytestat);
392
393 /* 394 * ide_error() takes action based on the error returned by the controller. 395 * 396 * Returns 1 if an ide reset operation has been initiated, in which case 397 * the caller MUST simply return from the driver (through however many levels). 398 * Returns 0 otherwise. 399 */ 400 intide_error (ide_drive_t *drive, constchar *msg, bytestat);
401
402 /* 403 * This routine busy-waits for the drive status to be not "busy". 404 * It then checks the status for all of the "good" bits and none 405 * of the "bad" bits, and if all is okay it returns 0. All other 406 * cases return 1 after invoking ide_error() 407 * 408 */ 409 intide_wait_stat (ide_drive_t *drive, bytegood, bytebad, unsignedlongtimeout);
410
411 /* 412 * This is called from genhd.c to correct DiskManager/EZ-Drive geometries 413 */ 414 intide_xlate_1024(kdev_t, int, constchar *);
415
416 /* 417 * Start a reset operation for an IDE interface. 418 * Returns 0 if the reset operation is still in progress, 419 * in which case the drive MUST return, to await completion. 420 * Returns 1 if the reset is complete (success or failure). 421 */ 422 intide_do_reset (ide_drive_t *);
423
424 /* 425 * ide_alloc(): memory allocation for use *only* during driver initialization. 426 * If "within_area" is non-zero, the memory will be allocated such that 427 * it lies entirely within a "within_area" sized area (eg. 4096). This is 428 * needed for DMA stuff. "within_area" must be a power of two (not validated). 429 * All allocations are longword aligned. 430 */ 431 void *ide_alloc (unsignedlongbytecount, unsignedlongwithin_area);
432
433 /* 434 * This function issues a specific IDE drive command onto the 435 * tail of the request queue, and waits for it to be completed. 436 * If arg is NULL, it goes through all the motions, 437 * but without actually sending a command to the drive. 438 * 439 * The value of arg is passed to the internal handler as rq->buffer. 440 */ 441 intide_do_drive_cmd(kdev_trdev, char *args);
442
443
444 #ifdefCONFIG_BLK_DEV_IDECD 445 /* 446 * These are routines in ide-cd.c invoked from ide.c 447 */ 448 voidide_do_rw_cdrom (ide_drive_t *, unsignedlong);
449 intide_cdrom_ioctl (ide_drive_t *, structinode *, structfile *, unsignedint, unsignedlong);
450 intide_cdrom_check_media_change (ide_drive_t *);
451 intide_cdrom_open (structinode *, structfile *, ide_drive_t *);
452 voidide_cdrom_release (structinode *, structfile *, ide_drive_t *);
453 voidide_cdrom_setup (ide_drive_t *);
454 #endif/* CONFIG_BLK_DEV_IDECD */ 455
456 #ifdefCONFIG_BLK_DEV_TRITON 457 voidide_init_triton (byte, byte);
458 #endif/* CONFIG_BLK_DEV_TRITON */ 459