GNU Linux-libre 4.9.294-gnu1
[releases.git] / include / linux / ide.h
1 #ifndef _IDE_H
2 #define _IDE_H
3 /*
4  *  linux/include/linux/ide.h
5  *
6  *  Copyright (C) 1994-2002  Linus Torvalds & authors
7  */
8
9 #include <linux/init.h>
10 #include <linux/ioport.h>
11 #include <linux/ata.h>
12 #include <linux/blkdev.h>
13 #include <linux/proc_fs.h>
14 #include <linux/interrupt.h>
15 #include <linux/bitops.h>
16 #include <linux/bio.h>
17 #include <linux/pci.h>
18 #include <linux/completion.h>
19 #include <linux/pm.h>
20 #include <linux/mutex.h>
21 /* for request_sense */
22 #include <linux/cdrom.h>
23 #include <asm/byteorder.h>
24 #include <asm/io.h>
25
26 #if defined(CONFIG_CRIS) || defined(CONFIG_FRV) || defined(CONFIG_MN10300)
27 # define SUPPORT_VLB_SYNC 0
28 #else
29 # define SUPPORT_VLB_SYNC 1
30 #endif
31
32 /*
33  * Probably not wise to fiddle with these
34  */
35 #define IDE_DEFAULT_MAX_FAILURES        1
36 #define ERROR_MAX       8       /* Max read/write errors per sector */
37 #define ERROR_RESET     3       /* Reset controller every 4th retry */
38 #define ERROR_RECAL     1       /* Recalibrate every 2nd retry */
39
40 struct device;
41
42 /* IDE-specific values for req->cmd_type */
43 enum ata_cmd_type_bits {
44         REQ_TYPE_ATA_TASKFILE = REQ_TYPE_DRV_PRIV + 1,
45         REQ_TYPE_ATA_PC,
46         REQ_TYPE_ATA_SENSE,     /* sense request */
47         REQ_TYPE_ATA_PM_SUSPEND,/* suspend request */
48         REQ_TYPE_ATA_PM_RESUME, /* resume request */
49 };
50
51 #define ata_pm_request(rq)      \
52         ((rq)->cmd_type == REQ_TYPE_ATA_PM_SUSPEND || \
53          (rq)->cmd_type == REQ_TYPE_ATA_PM_RESUME)
54
55 /* Error codes returned in rq->errors to the higher part of the driver. */
56 enum {
57         IDE_DRV_ERROR_GENERAL   = 101,
58         IDE_DRV_ERROR_FILEMARK  = 102,
59         IDE_DRV_ERROR_EOD       = 103,
60 };
61
62 /*
63  * Definitions for accessing IDE controller registers
64  */
65 #define IDE_NR_PORTS            (10)
66
67 struct ide_io_ports {
68         unsigned long   data_addr;
69
70         union {
71                 unsigned long error_addr;       /*   read:  error */
72                 unsigned long feature_addr;     /*  write: feature */
73         };
74
75         unsigned long   nsect_addr;
76         unsigned long   lbal_addr;
77         unsigned long   lbam_addr;
78         unsigned long   lbah_addr;
79
80         unsigned long   device_addr;
81
82         union {
83                 unsigned long status_addr;      /*  read: status  */
84                 unsigned long command_addr;     /* write: command */
85         };
86
87         unsigned long   ctl_addr;
88
89         unsigned long   irq_addr;
90 };
91
92 #define OK_STAT(stat,good,bad)  (((stat)&((good)|(bad)))==(good))
93
94 #define BAD_R_STAT      (ATA_BUSY | ATA_ERR)
95 #define BAD_W_STAT      (BAD_R_STAT | ATA_DF)
96 #define BAD_STAT        (BAD_R_STAT | ATA_DRQ)
97 #define DRIVE_READY     (ATA_DRDY | ATA_DSC)
98
99 #define BAD_CRC         (ATA_ABORTED | ATA_ICRC)
100
101 #define SATA_NR_PORTS           (3)     /* 16 possible ?? */
102
103 #define SATA_STATUS_OFFSET      (0)
104 #define SATA_ERROR_OFFSET       (1)
105 #define SATA_CONTROL_OFFSET     (2)
106
107 /*
108  * Our Physical Region Descriptor (PRD) table should be large enough
109  * to handle the biggest I/O request we are likely to see.  Since requests
110  * can have no more than 256 sectors, and since the typical blocksize is
111  * two or more sectors, we could get by with a limit of 128 entries here for
112  * the usual worst case.  Most requests seem to include some contiguous blocks,
113  * further reducing the number of table entries required.
114  *
115  * The driver reverts to PIO mode for individual requests that exceed
116  * this limit (possible with 512 byte blocksizes, eg. MSDOS f/s), so handling
117  * 100% of all crazy scenarios here is not necessary.
118  *
119  * As it turns out though, we must allocate a full 4KB page for this,
120  * so the two PRD tables (ide0 & ide1) will each get half of that,
121  * allowing each to have about 256 entries (8 bytes each) from this.
122  */
123 #define PRD_BYTES       8
124 #define PRD_ENTRIES     256
125
126 /*
127  * Some more useful definitions
128  */
129 #define PARTN_BITS      6       /* number of minor dev bits for partitions */
130 #define MAX_DRIVES      2       /* per interface; 2 assumed by lots of code */
131
132 /*
133  * Timeouts for various operations:
134  */
135 enum {
136         /* spec allows up to 20ms, but CF cards and SSD drives need more */
137         WAIT_DRQ        = 1 * HZ,       /* 1s */
138         /* some laptops are very slow */
139         WAIT_READY      = 5 * HZ,       /* 5s */
140         /* should be less than 3ms (?), if all ATAPI CD is closed at boot */
141         WAIT_PIDENTIFY  = 10 * HZ,      /* 10s */
142         /* worst case when spinning up */
143         WAIT_WORSTCASE  = 30 * HZ,      /* 30s */
144         /* maximum wait for an IRQ to happen */
145         WAIT_CMD        = 10 * HZ,      /* 10s */
146         /* Some drives require a longer IRQ timeout. */
147         WAIT_FLOPPY_CMD = 50 * HZ,      /* 50s */
148         /*
149          * Some drives (for example, Seagate STT3401A Travan) require a very
150          * long timeout, because they don't return an interrupt or clear their
151          * BSY bit until after the command completes (even retension commands).
152          */
153         WAIT_TAPE_CMD   = 900 * HZ,     /* 900s */
154         /* minimum sleep time */
155         WAIT_MIN_SLEEP  = HZ / 50,      /* 20ms */
156 };
157
158 /*
159  * Op codes for special requests to be handled by ide_special_rq().
160  * Values should be in the range of 0x20 to 0x3f.
161  */
162 #define REQ_DRIVE_RESET         0x20
163 #define REQ_DEVSET_EXEC         0x21
164 #define REQ_PARK_HEADS          0x22
165 #define REQ_UNPARK_HEADS        0x23
166
167 /*
168  * hwif_chipset_t is used to keep track of the specific hardware
169  * chipset used by each IDE interface, if known.
170  */
171 enum {          ide_unknown,    ide_generic,    ide_pci,
172                 ide_cmd640,     ide_dtc2278,    ide_ali14xx,
173                 ide_qd65xx,     ide_umc8672,    ide_ht6560b,
174                 ide_4drives,    ide_pmac,       ide_acorn,
175                 ide_au1xxx,     ide_palm3710
176 };
177
178 typedef u8 hwif_chipset_t;
179
180 /*
181  * Structure to hold all information about the location of this port
182  */
183 struct ide_hw {
184         union {
185                 struct ide_io_ports     io_ports;
186                 unsigned long           io_ports_array[IDE_NR_PORTS];
187         };
188
189         int             irq;                    /* our irq number */
190         struct device   *dev, *parent;
191         unsigned long   config;
192 };
193
194 static inline void ide_std_init_ports(struct ide_hw *hw,
195                                       unsigned long io_addr,
196                                       unsigned long ctl_addr)
197 {
198         unsigned int i;
199
200         for (i = 0; i <= 7; i++)
201                 hw->io_ports_array[i] = io_addr++;
202
203         hw->io_ports.ctl_addr = ctl_addr;
204 }
205
206 #define MAX_HWIFS       10
207
208 /*
209  * Now for the data we need to maintain per-drive:  ide_drive_t
210  */
211
212 #define ide_scsi        0x21
213 #define ide_disk        0x20
214 #define ide_optical     0x7
215 #define ide_cdrom       0x5
216 #define ide_tape        0x1
217 #define ide_floppy      0x0
218
219 /*
220  * Special Driver Flags
221  */
222 enum {
223         IDE_SFLAG_SET_GEOMETRY          = (1 << 0),
224         IDE_SFLAG_RECALIBRATE           = (1 << 1),
225         IDE_SFLAG_SET_MULTMODE          = (1 << 2),
226 };
227
228 /*
229  * Status returned from various ide_ functions
230  */
231 typedef enum {
232         ide_stopped,    /* no drive operation was started */
233         ide_started,    /* a drive operation was started, handler was set */
234 } ide_startstop_t;
235
236 enum {
237         IDE_VALID_ERROR                 = (1 << 1),
238         IDE_VALID_FEATURE               = IDE_VALID_ERROR,
239         IDE_VALID_NSECT                 = (1 << 2),
240         IDE_VALID_LBAL                  = (1 << 3),
241         IDE_VALID_LBAM                  = (1 << 4),
242         IDE_VALID_LBAH                  = (1 << 5),
243         IDE_VALID_DEVICE                = (1 << 6),
244         IDE_VALID_LBA                   = IDE_VALID_LBAL |
245                                           IDE_VALID_LBAM |
246                                           IDE_VALID_LBAH,
247         IDE_VALID_OUT_TF                = IDE_VALID_FEATURE |
248                                           IDE_VALID_NSECT |
249                                           IDE_VALID_LBA,
250         IDE_VALID_IN_TF                 = IDE_VALID_NSECT |
251                                           IDE_VALID_LBA,
252         IDE_VALID_OUT_HOB               = IDE_VALID_OUT_TF,
253         IDE_VALID_IN_HOB                = IDE_VALID_ERROR |
254                                           IDE_VALID_NSECT |
255                                           IDE_VALID_LBA,
256 };
257
258 enum {
259         IDE_TFLAG_LBA48                 = (1 << 0),
260         IDE_TFLAG_WRITE                 = (1 << 1),
261         IDE_TFLAG_CUSTOM_HANDLER        = (1 << 2),
262         IDE_TFLAG_DMA_PIO_FALLBACK      = (1 << 3),
263         /* force 16-bit I/O operations */
264         IDE_TFLAG_IO_16BIT              = (1 << 4),
265         /* struct ide_cmd was allocated using kmalloc() */
266         IDE_TFLAG_DYN                   = (1 << 5),
267         IDE_TFLAG_FS                    = (1 << 6),
268         IDE_TFLAG_MULTI_PIO             = (1 << 7),
269         IDE_TFLAG_SET_XFER              = (1 << 8),
270 };
271
272 enum {
273         IDE_FTFLAG_FLAGGED              = (1 << 0),
274         IDE_FTFLAG_SET_IN_FLAGS         = (1 << 1),
275         IDE_FTFLAG_OUT_DATA             = (1 << 2),
276         IDE_FTFLAG_IN_DATA              = (1 << 3),
277 };
278
279 struct ide_taskfile {
280         u8      data;           /* 0: data byte (for TASKFILE ioctl) */
281         union {                 /* 1: */
282                 u8 error;       /*  read: error */
283                 u8 feature;     /* write: feature */
284         };
285         u8      nsect;          /* 2: number of sectors */
286         u8      lbal;           /* 3: LBA low */
287         u8      lbam;           /* 4: LBA mid */
288         u8      lbah;           /* 5: LBA high */
289         u8      device;         /* 6: device select */
290         union {                 /* 7: */
291                 u8 status;      /*  read: status */
292                 u8 command;     /* write: command */
293         };
294 };
295
296 struct ide_cmd {
297         struct ide_taskfile     tf;
298         struct ide_taskfile     hob;
299         struct {
300                 struct {
301                         u8              tf;
302                         u8              hob;
303                 } out, in;
304         } valid;
305
306         u16                     tf_flags;
307         u8                      ftf_flags;      /* for TASKFILE ioctl */
308         int                     protocol;
309
310         int                     sg_nents;         /* number of sg entries */
311         int                     orig_sg_nents;
312         int                     sg_dma_direction; /* DMA transfer direction */
313
314         unsigned int            nbytes;
315         unsigned int            nleft;
316         unsigned int            last_xfer_len;
317
318         struct scatterlist      *cursg;
319         unsigned int            cursg_ofs;
320
321         struct request          *rq;            /* copy of request */
322 };
323
324 /* ATAPI packet command flags */
325 enum {
326         /* set when an error is considered normal - no retry (ide-tape) */
327         PC_FLAG_ABORT                   = (1 << 0),
328         PC_FLAG_SUPPRESS_ERROR          = (1 << 1),
329         PC_FLAG_WAIT_FOR_DSC            = (1 << 2),
330         PC_FLAG_DMA_OK                  = (1 << 3),
331         PC_FLAG_DMA_IN_PROGRESS         = (1 << 4),
332         PC_FLAG_DMA_ERROR               = (1 << 5),
333         PC_FLAG_WRITING                 = (1 << 6),
334 };
335
336 #define ATAPI_WAIT_PC           (60 * HZ)
337
338 struct ide_atapi_pc {
339         /* actual packet bytes */
340         u8 c[12];
341         /* incremented on each retry */
342         int retries;
343         int error;
344
345         /* bytes to transfer */
346         int req_xfer;
347
348         /* the corresponding request */
349         struct request *rq;
350
351         unsigned long flags;
352
353         /*
354          * those are more or less driver-specific and some of them are subject
355          * to change/removal later.
356          */
357         unsigned long timeout;
358 };
359
360 struct ide_devset;
361 struct ide_driver;
362
363 #ifdef CONFIG_BLK_DEV_IDEACPI
364 struct ide_acpi_drive_link;
365 struct ide_acpi_hwif_link;
366 #endif
367
368 struct ide_drive_s;
369
370 struct ide_disk_ops {
371         int             (*check)(struct ide_drive_s *, const char *);
372         int             (*get_capacity)(struct ide_drive_s *);
373         void            (*unlock_native_capacity)(struct ide_drive_s *);
374         void            (*setup)(struct ide_drive_s *);
375         void            (*flush)(struct ide_drive_s *);
376         int             (*init_media)(struct ide_drive_s *, struct gendisk *);
377         int             (*set_doorlock)(struct ide_drive_s *, struct gendisk *,
378                                         int);
379         ide_startstop_t (*do_request)(struct ide_drive_s *, struct request *,
380                                       sector_t);
381         int             (*ioctl)(struct ide_drive_s *, struct block_device *,
382                                  fmode_t, unsigned int, unsigned long);
383 };
384
385 /* ATAPI device flags */
386 enum {
387         IDE_AFLAG_DRQ_INTERRUPT         = (1 << 0),
388
389         /* ide-cd */
390         /* Drive cannot eject the disc. */
391         IDE_AFLAG_NO_EJECT              = (1 << 1),
392         /* Drive is a pre ATAPI 1.2 drive. */
393         IDE_AFLAG_PRE_ATAPI12           = (1 << 2),
394         /* TOC addresses are in BCD. */
395         IDE_AFLAG_TOCADDR_AS_BCD        = (1 << 3),
396         /* TOC track numbers are in BCD. */
397         IDE_AFLAG_TOCTRACKS_AS_BCD      = (1 << 4),
398         /* Saved TOC information is current. */
399         IDE_AFLAG_TOC_VALID             = (1 << 6),
400         /* We think that the drive door is locked. */
401         IDE_AFLAG_DOOR_LOCKED           = (1 << 7),
402         /* SET_CD_SPEED command is unsupported. */
403         IDE_AFLAG_NO_SPEED_SELECT       = (1 << 8),
404         IDE_AFLAG_VERTOS_300_SSD        = (1 << 9),
405         IDE_AFLAG_VERTOS_600_ESD        = (1 << 10),
406         IDE_AFLAG_SANYO_3CD             = (1 << 11),
407         IDE_AFLAG_FULL_CAPS_PAGE        = (1 << 12),
408         IDE_AFLAG_PLAY_AUDIO_OK         = (1 << 13),
409         IDE_AFLAG_LE_SPEED_FIELDS       = (1 << 14),
410
411         /* ide-floppy */
412         /* Avoid commands not supported in Clik drive */
413         IDE_AFLAG_CLIK_DRIVE            = (1 << 15),
414         /* Requires BH algorithm for packets */
415         IDE_AFLAG_ZIP_DRIVE             = (1 << 16),
416         /* Supports format progress report */
417         IDE_AFLAG_SRFP                  = (1 << 17),
418
419         /* ide-tape */
420         IDE_AFLAG_IGNORE_DSC            = (1 << 18),
421         /* 0 When the tape position is unknown */
422         IDE_AFLAG_ADDRESS_VALID         = (1 << 19),
423         /* Device already opened */
424         IDE_AFLAG_BUSY                  = (1 << 20),
425         /* Attempt to auto-detect the current user block size */
426         IDE_AFLAG_DETECT_BS             = (1 << 21),
427         /* Currently on a filemark */
428         IDE_AFLAG_FILEMARK              = (1 << 22),
429         /* 0 = no tape is loaded, so we don't rewind after ejecting */
430         IDE_AFLAG_MEDIUM_PRESENT        = (1 << 23),
431
432         IDE_AFLAG_NO_AUTOCLOSE          = (1 << 24),
433 };
434
435 /* device flags */
436 enum {
437         /* restore settings after device reset */
438         IDE_DFLAG_KEEP_SETTINGS         = (1 << 0),
439         /* device is using DMA for read/write */
440         IDE_DFLAG_USING_DMA             = (1 << 1),
441         /* okay to unmask other IRQs */
442         IDE_DFLAG_UNMASK                = (1 << 2),
443         /* don't attempt flushes */
444         IDE_DFLAG_NOFLUSH               = (1 << 3),
445         /* DSC overlap */
446         IDE_DFLAG_DSC_OVERLAP           = (1 << 4),
447         /* give potential excess bandwidth */
448         IDE_DFLAG_NICE1                 = (1 << 5),
449         /* device is physically present */
450         IDE_DFLAG_PRESENT               = (1 << 6),
451         /* disable Host Protected Area */
452         IDE_DFLAG_NOHPA                 = (1 << 7),
453         /* id read from device (synthetic if not set) */
454         IDE_DFLAG_ID_READ               = (1 << 8),
455         IDE_DFLAG_NOPROBE               = (1 << 9),
456         /* need to do check_media_change() */
457         IDE_DFLAG_REMOVABLE             = (1 << 10),
458         /* needed for removable devices */
459         IDE_DFLAG_ATTACH                = (1 << 11),
460         IDE_DFLAG_FORCED_GEOM           = (1 << 12),
461         /* disallow setting unmask bit */
462         IDE_DFLAG_NO_UNMASK             = (1 << 13),
463         /* disallow enabling 32-bit I/O */
464         IDE_DFLAG_NO_IO_32BIT           = (1 << 14),
465         /* for removable only: door lock/unlock works */
466         IDE_DFLAG_DOORLOCKING           = (1 << 15),
467         /* disallow DMA */
468         IDE_DFLAG_NODMA                 = (1 << 16),
469         /* powermanagement told us not to do anything, so sleep nicely */
470         IDE_DFLAG_BLOCKED               = (1 << 17),
471         /* sleeping & sleep field valid */
472         IDE_DFLAG_SLEEPING              = (1 << 18),
473         IDE_DFLAG_POST_RESET            = (1 << 19),
474         IDE_DFLAG_UDMA33_WARNED         = (1 << 20),
475         IDE_DFLAG_LBA48                 = (1 << 21),
476         /* status of write cache */
477         IDE_DFLAG_WCACHE                = (1 << 22),
478         /* used for ignoring ATA_DF */
479         IDE_DFLAG_NOWERR                = (1 << 23),
480         /* retrying in PIO */
481         IDE_DFLAG_DMA_PIO_RETRY         = (1 << 24),
482         IDE_DFLAG_LBA                   = (1 << 25),
483         /* don't unload heads */
484         IDE_DFLAG_NO_UNLOAD             = (1 << 26),
485         /* heads unloaded, please don't reset port */
486         IDE_DFLAG_PARKED                = (1 << 27),
487         IDE_DFLAG_MEDIA_CHANGED         = (1 << 28),
488         /* write protect */
489         IDE_DFLAG_WP                    = (1 << 29),
490         IDE_DFLAG_FORMAT_IN_PROGRESS    = (1 << 30),
491         IDE_DFLAG_NIEN_QUIRK            = (1 << 31),
492 };
493
494 struct ide_drive_s {
495         char            name[4];        /* drive name, such as "hda" */
496         char            driver_req[10]; /* requests specific driver */
497
498         struct request_queue    *queue; /* request queue */
499
500         struct request          *rq;    /* current request */
501         void            *driver_data;   /* extra driver data */
502         u16                     *id;    /* identification info */
503 #ifdef CONFIG_IDE_PROC_FS
504         struct proc_dir_entry *proc;    /* /proc/ide/ directory entry */
505         const struct ide_proc_devset *settings; /* /proc/ide/ drive settings */
506 #endif
507         struct hwif_s           *hwif;  /* actually (ide_hwif_t *) */
508
509         const struct ide_disk_ops *disk_ops;
510
511         unsigned long dev_flags;
512
513         unsigned long sleep;            /* sleep until this time */
514         unsigned long timeout;          /* max time to wait for irq */
515
516         u8      special_flags;          /* special action flags */
517
518         u8      select;                 /* basic drive/head select reg value */
519         u8      retry_pio;              /* retrying dma capable host in pio */
520         u8      waiting_for_dma;        /* dma currently in progress */
521         u8      dma;                    /* atapi dma flag */
522
523         u8      init_speed;     /* transfer rate set at boot */
524         u8      current_speed;  /* current transfer rate set */
525         u8      desired_speed;  /* desired transfer rate set */
526         u8      pio_mode;       /* for ->set_pio_mode _only_ */
527         u8      dma_mode;       /* for ->set_dma_mode _only_ */
528         u8      dn;             /* now wide spread use */
529         u8      acoustic;       /* acoustic management */
530         u8      media;          /* disk, cdrom, tape, floppy, ... */
531         u8      ready_stat;     /* min status value for drive ready */
532         u8      mult_count;     /* current multiple sector setting */
533         u8      mult_req;       /* requested multiple sector setting */
534         u8      io_32bit;       /* 0=16-bit, 1=32-bit, 2/3=32bit+sync */
535         u8      bad_wstat;      /* used for ignoring ATA_DF */
536         u8      head;           /* "real" number of heads */
537         u8      sect;           /* "real" sectors per track */
538         u8      bios_head;      /* BIOS/fdisk/LILO number of heads */
539         u8      bios_sect;      /* BIOS/fdisk/LILO sectors per track */
540
541         /* delay this long before sending packet command */
542         u8 pc_delay;
543
544         unsigned int    bios_cyl;       /* BIOS/fdisk/LILO number of cyls */
545         unsigned int    cyl;            /* "real" number of cyls */
546         void            *drive_data;    /* used by set_pio_mode/dev_select() */
547         unsigned int    failures;       /* current failure count */
548         unsigned int    max_failures;   /* maximum allowed failure count */
549         u64             probed_capacity;/* initial/native media capacity */
550         u64             capacity64;     /* total number of sectors */
551
552         int             lun;            /* logical unit */
553         int             crc_count;      /* crc counter to reduce drive speed */
554
555         unsigned long   debug_mask;     /* debugging levels switch */
556
557 #ifdef CONFIG_BLK_DEV_IDEACPI
558         struct ide_acpi_drive_link *acpidata;
559 #endif
560         struct list_head list;
561         struct device   gendev;
562         struct completion gendev_rel_comp;      /* to deal with device release() */
563
564         /* current packet command */
565         struct ide_atapi_pc *pc;
566
567         /* last failed packet command */
568         struct ide_atapi_pc *failed_pc;
569
570         /* callback for packet commands */
571         int  (*pc_callback)(struct ide_drive_s *, int);
572
573         ide_startstop_t (*irq_handler)(struct ide_drive_s *);
574
575         unsigned long atapi_flags;
576
577         struct ide_atapi_pc request_sense_pc;
578
579         /* current sense rq and buffer */
580         bool sense_rq_armed;
581         struct request sense_rq;
582         struct request_sense sense_data;
583 };
584
585 typedef struct ide_drive_s ide_drive_t;
586
587 #define to_ide_device(dev)              container_of(dev, ide_drive_t, gendev)
588
589 #define to_ide_drv(obj, cont_type)      \
590         container_of(obj, struct cont_type, dev)
591
592 #define ide_drv_g(disk, cont_type)      \
593         container_of((disk)->private_data, struct cont_type, driver)
594
595 struct ide_port_info;
596
597 struct ide_tp_ops {
598         void    (*exec_command)(struct hwif_s *, u8);
599         u8      (*read_status)(struct hwif_s *);
600         u8      (*read_altstatus)(struct hwif_s *);
601         void    (*write_devctl)(struct hwif_s *, u8);
602
603         void    (*dev_select)(ide_drive_t *);
604         void    (*tf_load)(ide_drive_t *, struct ide_taskfile *, u8);
605         void    (*tf_read)(ide_drive_t *, struct ide_taskfile *, u8);
606
607         void    (*input_data)(ide_drive_t *, struct ide_cmd *,
608                               void *, unsigned int);
609         void    (*output_data)(ide_drive_t *, struct ide_cmd *,
610                                void *, unsigned int);
611 };
612
613 extern const struct ide_tp_ops default_tp_ops;
614
615 /**
616  * struct ide_port_ops - IDE port operations
617  *
618  * @init_dev:           host specific initialization of a device
619  * @set_pio_mode:       routine to program host for PIO mode
620  * @set_dma_mode:       routine to program host for DMA mode
621  * @reset_poll:         chipset polling based on hba specifics
622  * @pre_reset:          chipset specific changes to default for device-hba resets
623  * @resetproc:          routine to reset controller after a disk reset
624  * @maskproc:           special host masking for drive selection
625  * @quirkproc:          check host's drive quirk list
626  * @clear_irq:          clear IRQ
627  *
628  * @mdma_filter:        filter MDMA modes
629  * @udma_filter:        filter UDMA modes
630  *
631  * @cable_detect:       detect cable type
632  */
633 struct ide_port_ops {
634         void    (*init_dev)(ide_drive_t *);
635         void    (*set_pio_mode)(struct hwif_s *, ide_drive_t *);
636         void    (*set_dma_mode)(struct hwif_s *, ide_drive_t *);
637         int     (*reset_poll)(ide_drive_t *);
638         void    (*pre_reset)(ide_drive_t *);
639         void    (*resetproc)(ide_drive_t *);
640         void    (*maskproc)(ide_drive_t *, int);
641         void    (*quirkproc)(ide_drive_t *);
642         void    (*clear_irq)(ide_drive_t *);
643         int     (*test_irq)(struct hwif_s *);
644
645         u8      (*mdma_filter)(ide_drive_t *);
646         u8      (*udma_filter)(ide_drive_t *);
647
648         u8      (*cable_detect)(struct hwif_s *);
649 };
650
651 struct ide_dma_ops {
652         void    (*dma_host_set)(struct ide_drive_s *, int);
653         int     (*dma_setup)(struct ide_drive_s *, struct ide_cmd *);
654         void    (*dma_start)(struct ide_drive_s *);
655         int     (*dma_end)(struct ide_drive_s *);
656         int     (*dma_test_irq)(struct ide_drive_s *);
657         void    (*dma_lost_irq)(struct ide_drive_s *);
658         /* below ones are optional */
659         int     (*dma_check)(struct ide_drive_s *, struct ide_cmd *);
660         int     (*dma_timer_expiry)(struct ide_drive_s *);
661         void    (*dma_clear)(struct ide_drive_s *);
662         /*
663          * The following method is optional and only required to be
664          * implemented for the SFF-8038i compatible controllers.
665          */
666         u8      (*dma_sff_read_status)(struct hwif_s *);
667 };
668
669 enum {
670         IDE_PFLAG_PROBING               = (1 << 0),
671 };
672
673 struct ide_host;
674
675 typedef struct hwif_s {
676         struct hwif_s *mate;            /* other hwif from same PCI chip */
677         struct proc_dir_entry *proc;    /* /proc/ide/ directory entry */
678
679         struct ide_host *host;
680
681         char name[6];                   /* name of interface, eg. "ide0" */
682
683         struct ide_io_ports     io_ports;
684
685         unsigned long   sata_scr[SATA_NR_PORTS];
686
687         ide_drive_t     *devices[MAX_DRIVES + 1];
688
689         unsigned long   port_flags;
690
691         u8 major;       /* our major number */
692         u8 index;       /* 0 for ide0; 1 for ide1; ... */
693         u8 channel;     /* for dual-port chips: 0=primary, 1=secondary */
694
695         u32 host_flags;
696
697         u8 pio_mask;
698
699         u8 ultra_mask;
700         u8 mwdma_mask;
701         u8 swdma_mask;
702
703         u8 cbl;         /* cable type */
704
705         hwif_chipset_t chipset; /* sub-module for tuning.. */
706
707         struct device *dev;
708
709         void (*rw_disk)(ide_drive_t *, struct request *);
710
711         const struct ide_tp_ops         *tp_ops;
712         const struct ide_port_ops       *port_ops;
713         const struct ide_dma_ops        *dma_ops;
714
715         /* dma physical region descriptor table (cpu view) */
716         unsigned int    *dmatable_cpu;
717         /* dma physical region descriptor table (dma view) */
718         dma_addr_t      dmatable_dma;
719
720         /* maximum number of PRD table entries */
721         int prd_max_nents;
722         /* PRD entry size in bytes */
723         int prd_ent_size;
724
725         /* Scatter-gather list used to build the above */
726         struct scatterlist *sg_table;
727         int sg_max_nents;               /* Maximum number of entries in it */
728
729         struct ide_cmd cmd;             /* current command */
730
731         int             rqsize;         /* max sectors per request */
732         int             irq;            /* our irq number */
733
734         unsigned long   dma_base;       /* base addr for dma ports */
735
736         unsigned long   config_data;    /* for use by chipset-specific code */
737         unsigned long   select_data;    /* for use by chipset-specific code */
738
739         unsigned long   extra_base;     /* extra addr for dma ports */
740         unsigned        extra_ports;    /* number of extra dma ports */
741
742         unsigned        present    : 1; /* this interface exists */
743         unsigned        busy       : 1; /* serializes devices on a port */
744
745         struct device           gendev;
746         struct device           *portdev;
747
748         struct completion gendev_rel_comp; /* To deal with device release() */
749
750         void            *hwif_data;     /* extra hwif data */
751
752 #ifdef CONFIG_BLK_DEV_IDEACPI
753         struct ide_acpi_hwif_link *acpidata;
754 #endif
755
756         /* IRQ handler, if active */
757         ide_startstop_t (*handler)(ide_drive_t *);
758
759         /* BOOL: polling active & poll_timeout field valid */
760         unsigned int polling : 1;
761
762         /* current drive */
763         ide_drive_t *cur_dev;
764
765         /* current request */
766         struct request *rq;
767
768         /* failsafe timer */
769         struct timer_list timer;
770         /* timeout value during long polls */
771         unsigned long poll_timeout;
772         /* queried upon timeouts */
773         int (*expiry)(ide_drive_t *);
774
775         int req_gen;
776         int req_gen_timer;
777
778         spinlock_t lock;
779 } ____cacheline_internodealigned_in_smp ide_hwif_t;
780
781 #define MAX_HOST_PORTS 4
782
783 struct ide_host {
784         ide_hwif_t      *ports[MAX_HOST_PORTS + 1];
785         unsigned int    n_ports;
786         struct device   *dev[2];
787
788         int             (*init_chipset)(struct pci_dev *);
789
790         void            (*get_lock)(irq_handler_t, void *);
791         void            (*release_lock)(void);
792
793         irq_handler_t   irq_handler;
794
795         unsigned long   host_flags;
796
797         int             irq_flags;
798
799         void            *host_priv;
800         ide_hwif_t      *cur_port;      /* for hosts requiring serialization */
801
802         /* used for hosts requiring serialization */
803         volatile unsigned long  host_busy;
804 };
805
806 #define IDE_HOST_BUSY 0
807
808 /*
809  *  internal ide interrupt handler type
810  */
811 typedef ide_startstop_t (ide_handler_t)(ide_drive_t *);
812 typedef int (ide_expiry_t)(ide_drive_t *);
813
814 /* used by ide-cd, ide-floppy, etc. */
815 typedef void (xfer_func_t)(ide_drive_t *, struct ide_cmd *, void *, unsigned);
816
817 extern struct mutex ide_setting_mtx;
818
819 /*
820  * configurable drive settings
821  */
822
823 #define DS_SYNC (1 << 0)
824
825 struct ide_devset {
826         int             (*get)(ide_drive_t *);
827         int             (*set)(ide_drive_t *, int);
828         unsigned int    flags;
829 };
830
831 #define __DEVSET(_flags, _get, _set) { \
832         .flags  = _flags, \
833         .get    = _get, \
834         .set    = _set, \
835 }
836
837 #define ide_devset_get(name, field) \
838 static int get_##name(ide_drive_t *drive) \
839 { \
840         return drive->field; \
841 }
842
843 #define ide_devset_set(name, field) \
844 static int set_##name(ide_drive_t *drive, int arg) \
845 { \
846         drive->field = arg; \
847         return 0; \
848 }
849
850 #define ide_devset_get_flag(name, flag) \
851 static int get_##name(ide_drive_t *drive) \
852 { \
853         return !!(drive->dev_flags & flag); \
854 }
855
856 #define ide_devset_set_flag(name, flag) \
857 static int set_##name(ide_drive_t *drive, int arg) \
858 { \
859         if (arg) \
860                 drive->dev_flags |= flag; \
861         else \
862                 drive->dev_flags &= ~flag; \
863         return 0; \
864 }
865
866 #define __IDE_DEVSET(_name, _flags, _get, _set) \
867 const struct ide_devset ide_devset_##_name = \
868         __DEVSET(_flags, _get, _set)
869
870 #define IDE_DEVSET(_name, _flags, _get, _set) \
871 static __IDE_DEVSET(_name, _flags, _get, _set)
872
873 #define ide_devset_rw(_name, _func) \
874 IDE_DEVSET(_name, 0, get_##_func, set_##_func)
875
876 #define ide_devset_w(_name, _func) \
877 IDE_DEVSET(_name, 0, NULL, set_##_func)
878
879 #define ide_ext_devset_rw(_name, _func) \
880 __IDE_DEVSET(_name, 0, get_##_func, set_##_func)
881
882 #define ide_ext_devset_rw_sync(_name, _func) \
883 __IDE_DEVSET(_name, DS_SYNC, get_##_func, set_##_func)
884
885 #define ide_decl_devset(_name) \
886 extern const struct ide_devset ide_devset_##_name
887
888 ide_decl_devset(io_32bit);
889 ide_decl_devset(keepsettings);
890 ide_decl_devset(pio_mode);
891 ide_decl_devset(unmaskirq);
892 ide_decl_devset(using_dma);
893
894 #ifdef CONFIG_IDE_PROC_FS
895 /*
896  * /proc/ide interface
897  */
898
899 #define ide_devset_rw_field(_name, _field) \
900 ide_devset_get(_name, _field); \
901 ide_devset_set(_name, _field); \
902 IDE_DEVSET(_name, DS_SYNC, get_##_name, set_##_name)
903
904 #define ide_devset_rw_flag(_name, _field) \
905 ide_devset_get_flag(_name, _field); \
906 ide_devset_set_flag(_name, _field); \
907 IDE_DEVSET(_name, DS_SYNC, get_##_name, set_##_name)
908
909 struct ide_proc_devset {
910         const char              *name;
911         const struct ide_devset *setting;
912         int                     min, max;
913         int                     (*mulf)(ide_drive_t *);
914         int                     (*divf)(ide_drive_t *);
915 };
916
917 #define __IDE_PROC_DEVSET(_name, _min, _max, _mulf, _divf) { \
918         .name = __stringify(_name), \
919         .setting = &ide_devset_##_name, \
920         .min = _min, \
921         .max = _max, \
922         .mulf = _mulf, \
923         .divf = _divf, \
924 }
925
926 #define IDE_PROC_DEVSET(_name, _min, _max) \
927 __IDE_PROC_DEVSET(_name, _min, _max, NULL, NULL)
928
929 typedef struct {
930         const char      *name;
931         umode_t         mode;
932         const struct file_operations *proc_fops;
933 } ide_proc_entry_t;
934
935 void proc_ide_create(void);
936 void proc_ide_destroy(void);
937 void ide_proc_register_port(ide_hwif_t *);
938 void ide_proc_port_register_devices(ide_hwif_t *);
939 void ide_proc_unregister_device(ide_drive_t *);
940 void ide_proc_unregister_port(ide_hwif_t *);
941 void ide_proc_register_driver(ide_drive_t *, struct ide_driver *);
942 void ide_proc_unregister_driver(ide_drive_t *, struct ide_driver *);
943
944 extern const struct file_operations ide_capacity_proc_fops;
945 extern const struct file_operations ide_geometry_proc_fops;
946 #else
947 static inline void proc_ide_create(void) { ; }
948 static inline void proc_ide_destroy(void) { ; }
949 static inline void ide_proc_register_port(ide_hwif_t *hwif) { ; }
950 static inline void ide_proc_port_register_devices(ide_hwif_t *hwif) { ; }
951 static inline void ide_proc_unregister_device(ide_drive_t *drive) { ; }
952 static inline void ide_proc_unregister_port(ide_hwif_t *hwif) { ; }
953 static inline void ide_proc_register_driver(ide_drive_t *drive,
954                                             struct ide_driver *driver) { ; }
955 static inline void ide_proc_unregister_driver(ide_drive_t *drive,
956                                               struct ide_driver *driver) { ; }
957 #endif
958
959 enum {
960         /* enter/exit functions */
961         IDE_DBG_FUNC =                  (1 << 0),
962         /* sense key/asc handling */
963         IDE_DBG_SENSE =                 (1 << 1),
964         /* packet commands handling */
965         IDE_DBG_PC =                    (1 << 2),
966         /* request handling */
967         IDE_DBG_RQ =                    (1 << 3),
968         /* driver probing/setup */
969         IDE_DBG_PROBE =                 (1 << 4),
970 };
971
972 /* DRV_NAME has to be defined in the driver before using the macro below */
973 #define __ide_debug_log(lvl, fmt, args...)                              \
974 {                                                                       \
975         if (unlikely(drive->debug_mask & lvl))                          \
976                 printk(KERN_INFO DRV_NAME ": %s: " fmt "\n",            \
977                                           __func__, ## args);           \
978 }
979
980 /*
981  * Power Management state machine (rq->pm->pm_step).
982  *
983  * For each step, the core calls ide_start_power_step() first.
984  * This can return:
985  *      - ide_stopped : In this case, the core calls us back again unless
986  *                      step have been set to ide_power_state_completed.
987  *      - ide_started : In this case, the channel is left busy until an
988  *                      async event (interrupt) occurs.
989  * Typically, ide_start_power_step() will issue a taskfile request with
990  * do_rw_taskfile().
991  *
992  * Upon reception of the interrupt, the core will call ide_complete_power_step()
993  * with the error code if any. This routine should update the step value
994  * and return. It should not start a new request. The core will call
995  * ide_start_power_step() for the new step value, unless step have been
996  * set to IDE_PM_COMPLETED.
997  */
998 enum {
999         IDE_PM_START_SUSPEND,
1000         IDE_PM_FLUSH_CACHE      = IDE_PM_START_SUSPEND,
1001         IDE_PM_STANDBY,
1002
1003         IDE_PM_START_RESUME,
1004         IDE_PM_RESTORE_PIO      = IDE_PM_START_RESUME,
1005         IDE_PM_IDLE,
1006         IDE_PM_RESTORE_DMA,
1007
1008         IDE_PM_COMPLETED,
1009 };
1010
1011 int generic_ide_suspend(struct device *, pm_message_t);
1012 int generic_ide_resume(struct device *);
1013
1014 void ide_complete_power_step(ide_drive_t *, struct request *);
1015 ide_startstop_t ide_start_power_step(ide_drive_t *, struct request *);
1016 void ide_complete_pm_rq(ide_drive_t *, struct request *);
1017 void ide_check_pm_state(ide_drive_t *, struct request *);
1018
1019 /*
1020  * Subdrivers support.
1021  *
1022  * The gendriver.owner field should be set to the module owner of this driver.
1023  * The gendriver.name field should be set to the name of this driver
1024  */
1025 struct ide_driver {
1026         const char                      *version;
1027         ide_startstop_t (*do_request)(ide_drive_t *, struct request *, sector_t);
1028         struct device_driver    gen_driver;
1029         int             (*probe)(ide_drive_t *);
1030         void            (*remove)(ide_drive_t *);
1031         void            (*resume)(ide_drive_t *);
1032         void            (*shutdown)(ide_drive_t *);
1033 #ifdef CONFIG_IDE_PROC_FS
1034         ide_proc_entry_t *              (*proc_entries)(ide_drive_t *);
1035         const struct ide_proc_devset *  (*proc_devsets)(ide_drive_t *);
1036 #endif
1037 };
1038
1039 #define to_ide_driver(drv) container_of(drv, struct ide_driver, gen_driver)
1040
1041 int ide_device_get(ide_drive_t *);
1042 void ide_device_put(ide_drive_t *);
1043
1044 struct ide_ioctl_devset {
1045         unsigned int    get_ioctl;
1046         unsigned int    set_ioctl;
1047         const struct ide_devset *setting;
1048 };
1049
1050 int ide_setting_ioctl(ide_drive_t *, struct block_device *, unsigned int,
1051                       unsigned long, const struct ide_ioctl_devset *);
1052
1053 int generic_ide_ioctl(ide_drive_t *, struct block_device *, unsigned, unsigned long);
1054
1055 extern int ide_vlb_clk;
1056 extern int ide_pci_clk;
1057
1058 int ide_end_rq(ide_drive_t *, struct request *, int, unsigned int);
1059 void ide_kill_rq(ide_drive_t *, struct request *);
1060
1061 void __ide_set_handler(ide_drive_t *, ide_handler_t *, unsigned int);
1062 void ide_set_handler(ide_drive_t *, ide_handler_t *, unsigned int);
1063
1064 void ide_execute_command(ide_drive_t *, struct ide_cmd *, ide_handler_t *,
1065                          unsigned int);
1066
1067 void ide_pad_transfer(ide_drive_t *, int, int);
1068
1069 ide_startstop_t ide_error(ide_drive_t *, const char *, u8);
1070
1071 void ide_fix_driveid(u16 *);
1072
1073 extern void ide_fixstring(u8 *, const int, const int);
1074
1075 int ide_busy_sleep(ide_drive_t *, unsigned long, int);
1076
1077 int __ide_wait_stat(ide_drive_t *, u8, u8, unsigned long, u8 *);
1078 int ide_wait_stat(ide_startstop_t *, ide_drive_t *, u8, u8, unsigned long);
1079
1080 ide_startstop_t ide_do_park_unpark(ide_drive_t *, struct request *);
1081 ide_startstop_t ide_do_devset(ide_drive_t *, struct request *);
1082
1083 extern ide_startstop_t ide_do_reset (ide_drive_t *);
1084
1085 extern int ide_devset_execute(ide_drive_t *drive,
1086                               const struct ide_devset *setting, int arg);
1087
1088 void ide_complete_cmd(ide_drive_t *, struct ide_cmd *, u8, u8);
1089 int ide_complete_rq(ide_drive_t *, int, unsigned int);
1090
1091 void ide_tf_readback(ide_drive_t *drive, struct ide_cmd *cmd);
1092 void ide_tf_dump(const char *, struct ide_cmd *);
1093
1094 void ide_exec_command(ide_hwif_t *, u8);
1095 u8 ide_read_status(ide_hwif_t *);
1096 u8 ide_read_altstatus(ide_hwif_t *);
1097 void ide_write_devctl(ide_hwif_t *, u8);
1098
1099 void ide_dev_select(ide_drive_t *);
1100 void ide_tf_load(ide_drive_t *, struct ide_taskfile *, u8);
1101 void ide_tf_read(ide_drive_t *, struct ide_taskfile *, u8);
1102
1103 void ide_input_data(ide_drive_t *, struct ide_cmd *, void *, unsigned int);
1104 void ide_output_data(ide_drive_t *, struct ide_cmd *, void *, unsigned int);
1105
1106 void SELECT_MASK(ide_drive_t *, int);
1107
1108 u8 ide_read_error(ide_drive_t *);
1109 void ide_read_bcount_and_ireason(ide_drive_t *, u16 *, u8 *);
1110
1111 int ide_check_ireason(ide_drive_t *, struct request *, int, int, int);
1112
1113 int ide_check_atapi_device(ide_drive_t *, const char *);
1114
1115 void ide_init_pc(struct ide_atapi_pc *);
1116
1117 /* Disk head parking */
1118 extern wait_queue_head_t ide_park_wq;
1119 ssize_t ide_park_show(struct device *dev, struct device_attribute *attr,
1120                       char *buf);
1121 ssize_t ide_park_store(struct device *dev, struct device_attribute *attr,
1122                        const char *buf, size_t len);
1123
1124 /*
1125  * Special requests for ide-tape block device strategy routine.
1126  *
1127  * In order to service a character device command, we add special requests to
1128  * the tail of our block device request queue and wait for their completion.
1129  */
1130 enum {
1131         REQ_IDETAPE_PC1         = (1 << 0), /* packet command (first stage) */
1132         REQ_IDETAPE_PC2         = (1 << 1), /* packet command (second stage) */
1133         REQ_IDETAPE_READ        = (1 << 2),
1134         REQ_IDETAPE_WRITE       = (1 << 3),
1135 };
1136
1137 int ide_queue_pc_tail(ide_drive_t *, struct gendisk *, struct ide_atapi_pc *,
1138                       void *, unsigned int);
1139
1140 int ide_do_test_unit_ready(ide_drive_t *, struct gendisk *);
1141 int ide_do_start_stop(ide_drive_t *, struct gendisk *, int);
1142 int ide_set_media_lock(ide_drive_t *, struct gendisk *, int);
1143 void ide_create_request_sense_cmd(ide_drive_t *, struct ide_atapi_pc *);
1144 void ide_retry_pc(ide_drive_t *drive);
1145
1146 void ide_prep_sense(ide_drive_t *drive, struct request *rq);
1147 int ide_queue_sense_rq(ide_drive_t *drive, void *special);
1148
1149 int ide_cd_expiry(ide_drive_t *);
1150
1151 int ide_cd_get_xferlen(struct request *);
1152
1153 ide_startstop_t ide_issue_pc(ide_drive_t *, struct ide_cmd *);
1154
1155 ide_startstop_t do_rw_taskfile(ide_drive_t *, struct ide_cmd *);
1156
1157 void ide_pio_bytes(ide_drive_t *, struct ide_cmd *, unsigned int, unsigned int);
1158
1159 void ide_finish_cmd(ide_drive_t *, struct ide_cmd *, u8);
1160
1161 int ide_raw_taskfile(ide_drive_t *, struct ide_cmd *, u8 *, u16);
1162 int ide_no_data_taskfile(ide_drive_t *, struct ide_cmd *);
1163
1164 int ide_taskfile_ioctl(ide_drive_t *, unsigned long);
1165
1166 int ide_dev_read_id(ide_drive_t *, u8, u16 *, int);
1167
1168 extern int ide_driveid_update(ide_drive_t *);
1169 extern int ide_config_drive_speed(ide_drive_t *, u8);
1170 extern u8 eighty_ninty_three (ide_drive_t *);
1171 extern int taskfile_lib_get_identify(ide_drive_t *drive, u8 *);
1172
1173 extern int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout);
1174
1175 extern void ide_stall_queue(ide_drive_t *drive, unsigned long timeout);
1176
1177 extern void ide_timer_expiry(unsigned long);
1178 extern irqreturn_t ide_intr(int irq, void *dev_id);
1179 extern void do_ide_request(struct request_queue *);
1180 extern void ide_requeue_and_plug(ide_drive_t *drive, struct request *rq);
1181
1182 void ide_init_disk(struct gendisk *, ide_drive_t *);
1183
1184 #ifdef CONFIG_IDEPCI_PCIBUS_ORDER
1185 extern int __ide_pci_register_driver(struct pci_driver *driver, struct module *owner, const char *mod_name);
1186 #define ide_pci_register_driver(d) __ide_pci_register_driver(d, THIS_MODULE, KBUILD_MODNAME)
1187 #else
1188 #define ide_pci_register_driver(d) pci_register_driver(d)
1189 #endif
1190
1191 static inline int ide_pci_is_in_compatibility_mode(struct pci_dev *dev)
1192 {
1193         if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && (dev->class & 5) != 5)
1194                 return 1;
1195         return 0;
1196 }
1197
1198 void ide_pci_setup_ports(struct pci_dev *, const struct ide_port_info *,
1199                          struct ide_hw *, struct ide_hw **);
1200 void ide_setup_pci_noise(struct pci_dev *, const struct ide_port_info *);
1201
1202 #ifdef CONFIG_BLK_DEV_IDEDMA_PCI
1203 int ide_pci_set_master(struct pci_dev *, const char *);
1204 unsigned long ide_pci_dma_base(ide_hwif_t *, const struct ide_port_info *);
1205 int ide_pci_check_simplex(ide_hwif_t *, const struct ide_port_info *);
1206 int ide_hwif_setup_dma(ide_hwif_t *, const struct ide_port_info *);
1207 #else
1208 static inline int ide_hwif_setup_dma(ide_hwif_t *hwif,
1209                                      const struct ide_port_info *d)
1210 {
1211         return -EINVAL;
1212 }
1213 #endif
1214
1215 struct ide_pci_enablebit {
1216         u8      reg;    /* byte pci reg holding the enable-bit */
1217         u8      mask;   /* mask to isolate the enable-bit */
1218         u8      val;    /* value of masked reg when "enabled" */
1219 };
1220
1221 enum {
1222         /* Uses ISA control ports not PCI ones. */
1223         IDE_HFLAG_ISA_PORTS             = (1 << 0),
1224         /* single port device */
1225         IDE_HFLAG_SINGLE                = (1 << 1),
1226         /* don't use legacy PIO blacklist */
1227         IDE_HFLAG_PIO_NO_BLACKLIST      = (1 << 2),
1228         /* set for the second port of QD65xx */
1229         IDE_HFLAG_QD_2ND_PORT           = (1 << 3),
1230         /* use PIO8/9 for prefetch off/on */
1231         IDE_HFLAG_ABUSE_PREFETCH        = (1 << 4),
1232         /* use PIO6/7 for fast-devsel off/on */
1233         IDE_HFLAG_ABUSE_FAST_DEVSEL     = (1 << 5),
1234         /* use 100-102 and 200-202 PIO values to set DMA modes */
1235         IDE_HFLAG_ABUSE_DMA_MODES       = (1 << 6),
1236         /*
1237          * keep DMA setting when programming PIO mode, may be used only
1238          * for hosts which have separate PIO and DMA timings (ie. PMAC)
1239          */
1240         IDE_HFLAG_SET_PIO_MODE_KEEP_DMA = (1 << 7),
1241         /* program host for the transfer mode after programming device */
1242         IDE_HFLAG_POST_SET_MODE         = (1 << 8),
1243         /* don't program host/device for the transfer mode ("smart" hosts) */
1244         IDE_HFLAG_NO_SET_MODE           = (1 << 9),
1245         /* trust BIOS for programming chipset/device for DMA */
1246         IDE_HFLAG_TRUST_BIOS_FOR_DMA    = (1 << 10),
1247         /* host is CS5510/CS5520 */
1248         IDE_HFLAG_CS5520                = (1 << 11),
1249         /* ATAPI DMA is unsupported */
1250         IDE_HFLAG_NO_ATAPI_DMA          = (1 << 12),
1251         /* set if host is a "non-bootable" controller */
1252         IDE_HFLAG_NON_BOOTABLE          = (1 << 13),
1253         /* host doesn't support DMA */
1254         IDE_HFLAG_NO_DMA                = (1 << 14),
1255         /* check if host is PCI IDE device before allowing DMA */
1256         IDE_HFLAG_NO_AUTODMA            = (1 << 15),
1257         /* host uses MMIO */
1258         IDE_HFLAG_MMIO                  = (1 << 16),
1259         /* no LBA48 */
1260         IDE_HFLAG_NO_LBA48              = (1 << 17),
1261         /* no LBA48 DMA */
1262         IDE_HFLAG_NO_LBA48_DMA          = (1 << 18),
1263         /* data FIFO is cleared by an error */
1264         IDE_HFLAG_ERROR_STOPS_FIFO      = (1 << 19),
1265         /* serialize ports */
1266         IDE_HFLAG_SERIALIZE             = (1 << 20),
1267         /* host is DTC2278 */
1268         IDE_HFLAG_DTC2278               = (1 << 21),
1269         /* 4 devices on a single set of I/O ports */
1270         IDE_HFLAG_4DRIVES               = (1 << 22),
1271         /* host is TRM290 */
1272         IDE_HFLAG_TRM290                = (1 << 23),
1273         /* use 32-bit I/O ops */
1274         IDE_HFLAG_IO_32BIT              = (1 << 24),
1275         /* unmask IRQs */
1276         IDE_HFLAG_UNMASK_IRQS           = (1 << 25),
1277         IDE_HFLAG_BROKEN_ALTSTATUS      = (1 << 26),
1278         /* serialize ports if DMA is possible (for sl82c105) */
1279         IDE_HFLAG_SERIALIZE_DMA         = (1 << 27),
1280         /* force host out of "simplex" mode */
1281         IDE_HFLAG_CLEAR_SIMPLEX         = (1 << 28),
1282         /* DSC overlap is unsupported */
1283         IDE_HFLAG_NO_DSC                = (1 << 29),
1284         /* never use 32-bit I/O ops */
1285         IDE_HFLAG_NO_IO_32BIT           = (1 << 30),
1286         /* never unmask IRQs */
1287         IDE_HFLAG_NO_UNMASK_IRQS        = (1 << 31),
1288 };
1289
1290 #ifdef CONFIG_BLK_DEV_OFFBOARD
1291 # define IDE_HFLAG_OFF_BOARD    0
1292 #else
1293 # define IDE_HFLAG_OFF_BOARD    IDE_HFLAG_NON_BOOTABLE
1294 #endif
1295
1296 struct ide_port_info {
1297         char                    *name;
1298
1299         int                     (*init_chipset)(struct pci_dev *);
1300
1301         void                    (*get_lock)(irq_handler_t, void *);
1302         void                    (*release_lock)(void);
1303
1304         void                    (*init_iops)(ide_hwif_t *);
1305         void                    (*init_hwif)(ide_hwif_t *);
1306         int                     (*init_dma)(ide_hwif_t *,
1307                                             const struct ide_port_info *);
1308
1309         const struct ide_tp_ops         *tp_ops;
1310         const struct ide_port_ops       *port_ops;
1311         const struct ide_dma_ops        *dma_ops;
1312
1313         struct ide_pci_enablebit        enablebits[2];
1314
1315         hwif_chipset_t          chipset;
1316
1317         u16                     max_sectors;    /* if < than the default one */
1318
1319         u32                     host_flags;
1320
1321         int                     irq_flags;
1322
1323         u8                      pio_mask;
1324         u8                      swdma_mask;
1325         u8                      mwdma_mask;
1326         u8                      udma_mask;
1327 };
1328
1329 /*
1330  * State information carried for REQ_TYPE_ATA_PM_SUSPEND and REQ_TYPE_ATA_PM_RESUME
1331  * requests.
1332  */
1333 struct ide_pm_state {
1334         /* PM state machine step value, currently driver specific */
1335         int     pm_step;
1336         /* requested PM state value (S1, S2, S3, S4, ...) */
1337         u32     pm_state;
1338         void*   data;           /* for driver use */
1339 };
1340
1341
1342 int ide_pci_init_one(struct pci_dev *, const struct ide_port_info *, void *);
1343 int ide_pci_init_two(struct pci_dev *, struct pci_dev *,
1344                      const struct ide_port_info *, void *);
1345 void ide_pci_remove(struct pci_dev *);
1346
1347 #ifdef CONFIG_PM
1348 int ide_pci_suspend(struct pci_dev *, pm_message_t);
1349 int ide_pci_resume(struct pci_dev *);
1350 #else
1351 #define ide_pci_suspend NULL
1352 #define ide_pci_resume NULL
1353 #endif
1354
1355 void ide_map_sg(ide_drive_t *, struct ide_cmd *);
1356 void ide_init_sg_cmd(struct ide_cmd *, unsigned int);
1357
1358 #define BAD_DMA_DRIVE           0
1359 #define GOOD_DMA_DRIVE          1
1360
1361 struct drive_list_entry {
1362         const char *id_model;
1363         const char *id_firmware;
1364 };
1365
1366 int ide_in_drive_list(u16 *, const struct drive_list_entry *);
1367
1368 #ifdef CONFIG_BLK_DEV_IDEDMA
1369 int ide_dma_good_drive(ide_drive_t *);
1370 int __ide_dma_bad_drive(ide_drive_t *);
1371
1372 u8 ide_find_dma_mode(ide_drive_t *, u8);
1373
1374 static inline u8 ide_max_dma_mode(ide_drive_t *drive)
1375 {
1376         return ide_find_dma_mode(drive, XFER_UDMA_6);
1377 }
1378
1379 void ide_dma_off_quietly(ide_drive_t *);
1380 void ide_dma_off(ide_drive_t *);
1381 void ide_dma_on(ide_drive_t *);
1382 int ide_set_dma(ide_drive_t *);
1383 void ide_check_dma_crc(ide_drive_t *);
1384 ide_startstop_t ide_dma_intr(ide_drive_t *);
1385
1386 int ide_allocate_dma_engine(ide_hwif_t *);
1387 void ide_release_dma_engine(ide_hwif_t *);
1388
1389 int ide_dma_prepare(ide_drive_t *, struct ide_cmd *);
1390 void ide_dma_unmap_sg(ide_drive_t *, struct ide_cmd *);
1391
1392 #ifdef CONFIG_BLK_DEV_IDEDMA_SFF
1393 int config_drive_for_dma(ide_drive_t *);
1394 int ide_build_dmatable(ide_drive_t *, struct ide_cmd *);
1395 void ide_dma_host_set(ide_drive_t *, int);
1396 int ide_dma_setup(ide_drive_t *, struct ide_cmd *);
1397 extern void ide_dma_start(ide_drive_t *);
1398 int ide_dma_end(ide_drive_t *);
1399 int ide_dma_test_irq(ide_drive_t *);
1400 int ide_dma_sff_timer_expiry(ide_drive_t *);
1401 u8 ide_dma_sff_read_status(ide_hwif_t *);
1402 extern const struct ide_dma_ops sff_dma_ops;
1403 #else
1404 static inline int config_drive_for_dma(ide_drive_t *drive) { return 0; }
1405 #endif /* CONFIG_BLK_DEV_IDEDMA_SFF */
1406
1407 void ide_dma_lost_irq(ide_drive_t *);
1408 ide_startstop_t ide_dma_timeout_retry(ide_drive_t *, int);
1409
1410 #else
1411 static inline u8 ide_find_dma_mode(ide_drive_t *drive, u8 speed) { return 0; }
1412 static inline u8 ide_max_dma_mode(ide_drive_t *drive) { return 0; }
1413 static inline void ide_dma_off_quietly(ide_drive_t *drive) { ; }
1414 static inline void ide_dma_off(ide_drive_t *drive) { ; }
1415 static inline void ide_dma_on(ide_drive_t *drive) { ; }
1416 static inline void ide_dma_verbose(ide_drive_t *drive) { ; }
1417 static inline int ide_set_dma(ide_drive_t *drive) { return 1; }
1418 static inline void ide_check_dma_crc(ide_drive_t *drive) { ; }
1419 static inline ide_startstop_t ide_dma_intr(ide_drive_t *drive) { return ide_stopped; }
1420 static inline ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error) { return ide_stopped; }
1421 static inline void ide_release_dma_engine(ide_hwif_t *hwif) { ; }
1422 static inline int ide_dma_prepare(ide_drive_t *drive,
1423                                   struct ide_cmd *cmd) { return 1; }
1424 static inline void ide_dma_unmap_sg(ide_drive_t *drive,
1425                                     struct ide_cmd *cmd) { ; }
1426 #endif /* CONFIG_BLK_DEV_IDEDMA */
1427
1428 #ifdef CONFIG_BLK_DEV_IDEACPI
1429 int ide_acpi_init(void);
1430 bool ide_port_acpi(ide_hwif_t *hwif);
1431 extern int ide_acpi_exec_tfs(ide_drive_t *drive);
1432 extern void ide_acpi_get_timing(ide_hwif_t *hwif);
1433 extern void ide_acpi_push_timing(ide_hwif_t *hwif);
1434 void ide_acpi_init_port(ide_hwif_t *);
1435 void ide_acpi_port_init_devices(ide_hwif_t *);
1436 extern void ide_acpi_set_state(ide_hwif_t *hwif, int on);
1437 #else
1438 static inline int ide_acpi_init(void) { return 0; }
1439 static inline bool ide_port_acpi(ide_hwif_t *hwif) { return 0; }
1440 static inline int ide_acpi_exec_tfs(ide_drive_t *drive) { return 0; }
1441 static inline void ide_acpi_get_timing(ide_hwif_t *hwif) { ; }
1442 static inline void ide_acpi_push_timing(ide_hwif_t *hwif) { ; }
1443 static inline void ide_acpi_init_port(ide_hwif_t *hwif) { ; }
1444 static inline void ide_acpi_port_init_devices(ide_hwif_t *hwif) { ; }
1445 static inline void ide_acpi_set_state(ide_hwif_t *hwif, int on) {}
1446 #endif
1447
1448 void ide_register_region(struct gendisk *);
1449 void ide_unregister_region(struct gendisk *);
1450
1451 void ide_check_nien_quirk_list(ide_drive_t *);
1452 void ide_undecoded_slave(ide_drive_t *);
1453
1454 void ide_port_apply_params(ide_hwif_t *);
1455 int ide_sysfs_register_port(ide_hwif_t *);
1456
1457 struct ide_host *ide_host_alloc(const struct ide_port_info *, struct ide_hw **,
1458                                 unsigned int);
1459 void ide_host_free(struct ide_host *);
1460 int ide_host_register(struct ide_host *, const struct ide_port_info *,
1461                       struct ide_hw **);
1462 int ide_host_add(const struct ide_port_info *, struct ide_hw **, unsigned int,
1463                  struct ide_host **);
1464 void ide_host_remove(struct ide_host *);
1465 int ide_legacy_device_add(const struct ide_port_info *, unsigned long);
1466 void ide_port_unregister_devices(ide_hwif_t *);
1467 void ide_port_scan(ide_hwif_t *);
1468
1469 static inline void *ide_get_hwifdata (ide_hwif_t * hwif)
1470 {
1471         return hwif->hwif_data;
1472 }
1473
1474 static inline void ide_set_hwifdata (ide_hwif_t * hwif, void *data)
1475 {
1476         hwif->hwif_data = data;
1477 }
1478
1479 extern void ide_toggle_bounce(ide_drive_t *drive, int on);
1480
1481 u64 ide_get_lba_addr(struct ide_cmd *, int);
1482 u8 ide_dump_status(ide_drive_t *, const char *, u8);
1483
1484 struct ide_timing {
1485         u8  mode;
1486         u8  setup;      /* t1 */
1487         u16 act8b;      /* t2 for 8-bit io */
1488         u16 rec8b;      /* t2i for 8-bit io */
1489         u16 cyc8b;      /* t0 for 8-bit io */
1490         u16 active;     /* t2 or tD */
1491         u16 recover;    /* t2i or tK */
1492         u16 cycle;      /* t0 */
1493         u16 udma;       /* t2CYCTYP/2 */
1494 };
1495
1496 enum {
1497         IDE_TIMING_SETUP        = (1 << 0),
1498         IDE_TIMING_ACT8B        = (1 << 1),
1499         IDE_TIMING_REC8B        = (1 << 2),
1500         IDE_TIMING_CYC8B        = (1 << 3),
1501         IDE_TIMING_8BIT         = IDE_TIMING_ACT8B | IDE_TIMING_REC8B |
1502                                   IDE_TIMING_CYC8B,
1503         IDE_TIMING_ACTIVE       = (1 << 4),
1504         IDE_TIMING_RECOVER      = (1 << 5),
1505         IDE_TIMING_CYCLE        = (1 << 6),
1506         IDE_TIMING_UDMA         = (1 << 7),
1507         IDE_TIMING_ALL          = IDE_TIMING_SETUP | IDE_TIMING_8BIT |
1508                                   IDE_TIMING_ACTIVE | IDE_TIMING_RECOVER |
1509                                   IDE_TIMING_CYCLE | IDE_TIMING_UDMA,
1510 };
1511
1512 struct ide_timing *ide_timing_find_mode(u8);
1513 u16 ide_pio_cycle_time(ide_drive_t *, u8);
1514 void ide_timing_merge(struct ide_timing *, struct ide_timing *,
1515                       struct ide_timing *, unsigned int);
1516 int ide_timing_compute(ide_drive_t *, u8, struct ide_timing *, int, int);
1517
1518 #ifdef CONFIG_IDE_XFER_MODE
1519 int ide_scan_pio_blacklist(char *);
1520 const char *ide_xfer_verbose(u8);
1521 int ide_pio_need_iordy(ide_drive_t *, const u8);
1522 int ide_set_pio_mode(ide_drive_t *, u8);
1523 int ide_set_dma_mode(ide_drive_t *, u8);
1524 void ide_set_pio(ide_drive_t *, u8);
1525 int ide_set_xfer_rate(ide_drive_t *, u8);
1526 #else
1527 static inline void ide_set_pio(ide_drive_t *drive, u8 pio) { ; }
1528 static inline int ide_set_xfer_rate(ide_drive_t *drive, u8 rate) { return -1; }
1529 #endif
1530
1531 static inline void ide_set_max_pio(ide_drive_t *drive)
1532 {
1533         ide_set_pio(drive, 255);
1534 }
1535
1536 char *ide_media_string(ide_drive_t *);
1537
1538 extern const struct attribute_group *ide_dev_groups[];
1539 extern struct bus_type ide_bus_type;
1540 extern struct class *ide_port_class;
1541
1542 static inline void ide_dump_identify(u8 *id)
1543 {
1544         print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 2, id, 512, 0);
1545 }
1546
1547 static inline int hwif_to_node(ide_hwif_t *hwif)
1548 {
1549         return hwif->dev ? dev_to_node(hwif->dev) : -1;
1550 }
1551
1552 static inline ide_drive_t *ide_get_pair_dev(ide_drive_t *drive)
1553 {
1554         ide_drive_t *peer = drive->hwif->devices[(drive->dn ^ 1) & 1];
1555
1556         return (peer->dev_flags & IDE_DFLAG_PRESENT) ? peer : NULL;
1557 }
1558
1559 static inline void *ide_get_drivedata(ide_drive_t *drive)
1560 {
1561         return drive->drive_data;
1562 }
1563
1564 static inline void ide_set_drivedata(ide_drive_t *drive, void *data)
1565 {
1566         drive->drive_data = data;
1567 }
1568
1569 #define ide_port_for_each_dev(i, dev, port) \
1570         for ((i) = 0; ((dev) = (port)->devices[i]) || (i) < MAX_DRIVES; (i)++)
1571
1572 #define ide_port_for_each_present_dev(i, dev, port) \
1573         for ((i) = 0; ((dev) = (port)->devices[i]) || (i) < MAX_DRIVES; (i)++) \
1574                 if ((dev)->dev_flags & IDE_DFLAG_PRESENT)
1575
1576 #define ide_host_for_each_port(i, port, host) \
1577         for ((i) = 0; ((port) = (host)->ports[i]) || (i) < MAX_HOST_PORTS; (i)++)
1578
1579
1580 #endif /* _IDE_H */