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