ide.h 46 KB

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