ide.h 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515
  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/config.h>
  9. #include <linux/init.h>
  10. #include <linux/ioport.h>
  11. #include <linux/hdreg.h>
  12. #include <linux/hdsmart.h>
  13. #include <linux/blkdev.h>
  14. #include <linux/proc_fs.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/bitops.h>
  17. #include <linux/bio.h>
  18. #include <linux/device.h>
  19. #include <linux/pci.h>
  20. #include <asm/byteorder.h>
  21. #include <asm/system.h>
  22. #include <asm/io.h>
  23. #include <asm/semaphore.h>
  24. /*
  25. * This is the multiple IDE interface driver, as evolved from hd.c.
  26. * It supports up to four IDE interfaces, on one or more IRQs (usually 14 & 15).
  27. * There can be up to two drives per interface, as per the ATA-2 spec.
  28. *
  29. * Primary i/f: ide0: major=3; (hda) minor=0; (hdb) minor=64
  30. * Secondary i/f: ide1: major=22; (hdc or hd1a) minor=0; (hdd or hd1b) minor=64
  31. * Tertiary i/f: ide2: major=33; (hde) minor=0; (hdf) minor=64
  32. * Quaternary i/f: ide3: major=34; (hdg) minor=0; (hdh) minor=64
  33. */
  34. /******************************************************************************
  35. * IDE driver configuration options (play with these as desired):
  36. *
  37. * REALLY_SLOW_IO can be defined in ide.c and ide-cd.c, if necessary
  38. */
  39. #define INITIAL_MULT_COUNT 0 /* off=0; on=2,4,8,16,32, etc.. */
  40. #ifndef SUPPORT_SLOW_DATA_PORTS /* 1 to support slow data ports */
  41. #define SUPPORT_SLOW_DATA_PORTS 1 /* 0 to reduce kernel size */
  42. #endif
  43. #ifndef SUPPORT_VLB_SYNC /* 1 to support weird 32-bit chips */
  44. #define SUPPORT_VLB_SYNC 1 /* 0 to reduce kernel size */
  45. #endif
  46. #ifndef OK_TO_RESET_CONTROLLER /* 1 needed for good error recovery */
  47. #define OK_TO_RESET_CONTROLLER 1 /* 0 for use with AH2372A/B interface */
  48. #endif
  49. #ifndef DISABLE_IRQ_NOSYNC
  50. #define DISABLE_IRQ_NOSYNC 0
  51. #endif
  52. /*
  53. * Used to indicate "no IRQ", should be a value that cannot be an IRQ
  54. * number.
  55. */
  56. #define IDE_NO_IRQ (-1)
  57. /*
  58. * "No user-serviceable parts" beyond this point :)
  59. *****************************************************************************/
  60. typedef unsigned char byte; /* used everywhere */
  61. /*
  62. * Probably not wise to fiddle with these
  63. */
  64. #define ERROR_MAX 8 /* Max read/write errors per sector */
  65. #define ERROR_RESET 3 /* Reset controller every 4th retry */
  66. #define ERROR_RECAL 1 /* Recalibrate every 2nd retry */
  67. /*
  68. * Tune flags
  69. */
  70. #define IDE_TUNE_NOAUTO 2
  71. #define IDE_TUNE_AUTO 1
  72. #define IDE_TUNE_DEFAULT 0
  73. /*
  74. * state flags
  75. */
  76. #define DMA_PIO_RETRY 1 /* retrying in PIO */
  77. #define HWIF(drive) ((ide_hwif_t *)((drive)->hwif))
  78. #define HWGROUP(drive) ((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
  79. /*
  80. * Definitions for accessing IDE controller registers
  81. */
  82. #define IDE_NR_PORTS (10)
  83. #define IDE_DATA_OFFSET (0)
  84. #define IDE_ERROR_OFFSET (1)
  85. #define IDE_NSECTOR_OFFSET (2)
  86. #define IDE_SECTOR_OFFSET (3)
  87. #define IDE_LCYL_OFFSET (4)
  88. #define IDE_HCYL_OFFSET (5)
  89. #define IDE_SELECT_OFFSET (6)
  90. #define IDE_STATUS_OFFSET (7)
  91. #define IDE_CONTROL_OFFSET (8)
  92. #define IDE_IRQ_OFFSET (9)
  93. #define IDE_FEATURE_OFFSET IDE_ERROR_OFFSET
  94. #define IDE_COMMAND_OFFSET IDE_STATUS_OFFSET
  95. #define IDE_CONTROL_OFFSET_HOB (7)
  96. #define IDE_DATA_REG (HWIF(drive)->io_ports[IDE_DATA_OFFSET])
  97. #define IDE_ERROR_REG (HWIF(drive)->io_ports[IDE_ERROR_OFFSET])
  98. #define IDE_NSECTOR_REG (HWIF(drive)->io_ports[IDE_NSECTOR_OFFSET])
  99. #define IDE_SECTOR_REG (HWIF(drive)->io_ports[IDE_SECTOR_OFFSET])
  100. #define IDE_LCYL_REG (HWIF(drive)->io_ports[IDE_LCYL_OFFSET])
  101. #define IDE_HCYL_REG (HWIF(drive)->io_ports[IDE_HCYL_OFFSET])
  102. #define IDE_SELECT_REG (HWIF(drive)->io_ports[IDE_SELECT_OFFSET])
  103. #define IDE_STATUS_REG (HWIF(drive)->io_ports[IDE_STATUS_OFFSET])
  104. #define IDE_CONTROL_REG (HWIF(drive)->io_ports[IDE_CONTROL_OFFSET])
  105. #define IDE_IRQ_REG (HWIF(drive)->io_ports[IDE_IRQ_OFFSET])
  106. #define IDE_FEATURE_REG IDE_ERROR_REG
  107. #define IDE_COMMAND_REG IDE_STATUS_REG
  108. #define IDE_ALTSTATUS_REG IDE_CONTROL_REG
  109. #define IDE_IREASON_REG IDE_NSECTOR_REG
  110. #define IDE_BCOUNTL_REG IDE_LCYL_REG
  111. #define IDE_BCOUNTH_REG IDE_HCYL_REG
  112. #define OK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good))
  113. #define BAD_R_STAT (BUSY_STAT | ERR_STAT)
  114. #define BAD_W_STAT (BAD_R_STAT | WRERR_STAT)
  115. #define BAD_STAT (BAD_R_STAT | DRQ_STAT)
  116. #define DRIVE_READY (READY_STAT | SEEK_STAT)
  117. #define DATA_READY (DRQ_STAT)
  118. #define BAD_CRC (ABRT_ERR | ICRC_ERR)
  119. #define SATA_NR_PORTS (3) /* 16 possible ?? */
  120. #define SATA_STATUS_OFFSET (0)
  121. #define SATA_STATUS_REG (HWIF(drive)->sata_scr[SATA_STATUS_OFFSET])
  122. #define SATA_ERROR_OFFSET (1)
  123. #define SATA_ERROR_REG (HWIF(drive)->sata_scr[SATA_ERROR_OFFSET])
  124. #define SATA_CONTROL_OFFSET (2)
  125. #define SATA_CONTROL_REG (HWIF(drive)->sata_scr[SATA_CONTROL_OFFSET])
  126. #define SATA_MISC_OFFSET (0)
  127. #define SATA_MISC_REG (HWIF(drive)->sata_misc[SATA_MISC_OFFSET])
  128. #define SATA_PHY_OFFSET (1)
  129. #define SATA_PHY_REG (HWIF(drive)->sata_misc[SATA_PHY_OFFSET])
  130. #define SATA_IEN_OFFSET (2)
  131. #define SATA_IEN_REG (HWIF(drive)->sata_misc[SATA_IEN_OFFSET])
  132. /*
  133. * Our Physical Region Descriptor (PRD) table should be large enough
  134. * to handle the biggest I/O request we are likely to see. Since requests
  135. * can have no more than 256 sectors, and since the typical blocksize is
  136. * two or more sectors, we could get by with a limit of 128 entries here for
  137. * the usual worst case. Most requests seem to include some contiguous blocks,
  138. * further reducing the number of table entries required.
  139. *
  140. * The driver reverts to PIO mode for individual requests that exceed
  141. * this limit (possible with 512 byte blocksizes, eg. MSDOS f/s), so handling
  142. * 100% of all crazy scenarios here is not necessary.
  143. *
  144. * As it turns out though, we must allocate a full 4KB page for this,
  145. * so the two PRD tables (ide0 & ide1) will each get half of that,
  146. * allowing each to have about 256 entries (8 bytes each) from this.
  147. */
  148. #define PRD_BYTES 8
  149. #define PRD_ENTRIES 256
  150. /*
  151. * Some more useful definitions
  152. */
  153. #define PARTN_BITS 6 /* number of minor dev bits for partitions */
  154. #define MAX_DRIVES 2 /* per interface; 2 assumed by lots of code */
  155. #define SECTOR_SIZE 512
  156. #define SECTOR_WORDS (SECTOR_SIZE / 4) /* number of 32bit words per sector */
  157. #define IDE_LARGE_SEEK(b1,b2,t) (((b1) > (b2) + (t)) || ((b2) > (b1) + (t)))
  158. /*
  159. * Timeouts for various operations:
  160. */
  161. #define WAIT_DRQ (HZ/10) /* 100msec - spec allows up to 20ms */
  162. #define WAIT_READY (5*HZ) /* 5sec - some laptops are very slow */
  163. #define WAIT_PIDENTIFY (10*HZ) /* 10sec - should be less than 3ms (?), if all ATAPI CD is closed at boot */
  164. #define WAIT_WORSTCASE (30*HZ) /* 30sec - worst case when spinning up */
  165. #define WAIT_CMD (10*HZ) /* 10sec - maximum wait for an IRQ to happen */
  166. #define WAIT_MIN_SLEEP (2*HZ/100) /* 20msec - minimum sleep time */
  167. #define HOST(hwif,chipset) \
  168. { \
  169. return ((hwif)->chipset == chipset) ? 1 : 0; \
  170. }
  171. /*
  172. * Check for an interrupt and acknowledge the interrupt status
  173. */
  174. struct hwif_s;
  175. typedef int (ide_ack_intr_t)(struct hwif_s *);
  176. #ifndef NO_DMA
  177. #define NO_DMA 255
  178. #endif
  179. /*
  180. * hwif_chipset_t is used to keep track of the specific hardware
  181. * chipset used by each IDE interface, if known.
  182. */
  183. typedef enum { ide_unknown, ide_generic, ide_pci,
  184. ide_cmd640, ide_dtc2278, ide_ali14xx,
  185. ide_qd65xx, ide_umc8672, ide_ht6560b,
  186. ide_rz1000, ide_trm290,
  187. ide_cmd646, ide_cy82c693, ide_4drives,
  188. ide_pmac, ide_etrax100, ide_acorn,
  189. ide_au1xxx, ide_forced
  190. } hwif_chipset_t;
  191. /*
  192. * Structure to hold all information about the location of this port
  193. */
  194. typedef struct hw_regs_s {
  195. unsigned long io_ports[IDE_NR_PORTS]; /* task file registers */
  196. int irq; /* our irq number */
  197. int dma; /* our dma entry */
  198. ide_ack_intr_t *ack_intr; /* acknowledge interrupt */
  199. hwif_chipset_t chipset;
  200. struct device *dev;
  201. } hw_regs_t;
  202. /*
  203. * Register new hardware with ide
  204. */
  205. int ide_register_hw(hw_regs_t *hw, struct hwif_s **hwifp);
  206. int ide_register_hw_with_fixup(hw_regs_t *, struct hwif_s **, void (*)(struct hwif_s *));
  207. /*
  208. * Set up hw_regs_t structure before calling ide_register_hw (optional)
  209. */
  210. void ide_setup_ports( hw_regs_t *hw,
  211. unsigned long base,
  212. int *offsets,
  213. unsigned long ctrl,
  214. unsigned long intr,
  215. ide_ack_intr_t *ack_intr,
  216. #if 0
  217. ide_io_ops_t *iops,
  218. #endif
  219. int irq);
  220. static inline void ide_std_init_ports(hw_regs_t *hw,
  221. unsigned long io_addr,
  222. unsigned long ctl_addr)
  223. {
  224. unsigned int i;
  225. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
  226. hw->io_ports[i] = io_addr++;
  227. hw->io_ports[IDE_CONTROL_OFFSET] = ctl_addr;
  228. }
  229. #include <asm/ide.h>
  230. #ifndef MAX_HWIFS
  231. #define MAX_HWIFS CONFIG_IDE_MAX_HWIFS
  232. #endif
  233. /* needed on alpha, x86/x86_64, ia64, mips, ppc32 and sh */
  234. #ifndef IDE_ARCH_OBSOLETE_DEFAULTS
  235. # define ide_default_io_base(index) (0)
  236. # define ide_default_irq(base) (0)
  237. # define ide_init_default_irq(base) (0)
  238. #endif
  239. /*
  240. * ide_init_hwif_ports() is OBSOLETE and will be removed in 2.7 series.
  241. * New ports shouldn't define IDE_ARCH_OBSOLETE_INIT in <asm/ide.h>.
  242. */
  243. #ifdef IDE_ARCH_OBSOLETE_INIT
  244. static inline void ide_init_hwif_ports(hw_regs_t *hw,
  245. unsigned long io_addr,
  246. unsigned long ctl_addr,
  247. int *irq)
  248. {
  249. if (!ctl_addr)
  250. ide_std_init_ports(hw, io_addr, ide_default_io_ctl(io_addr));
  251. else
  252. ide_std_init_ports(hw, io_addr, ctl_addr);
  253. if (irq)
  254. *irq = 0;
  255. hw->io_ports[IDE_IRQ_OFFSET] = 0;
  256. #ifdef CONFIG_PPC32
  257. if (ppc_ide_md.ide_init_hwif)
  258. ppc_ide_md.ide_init_hwif(hw, io_addr, ctl_addr, irq);
  259. #endif
  260. }
  261. #else
  262. static inline void ide_init_hwif_ports(hw_regs_t *hw,
  263. unsigned long io_addr,
  264. unsigned long ctl_addr,
  265. int *irq)
  266. {
  267. if (io_addr || ctl_addr)
  268. printk(KERN_WARNING "%s: must not be called\n", __FUNCTION__);
  269. }
  270. #endif /* IDE_ARCH_OBSOLETE_INIT */
  271. /* Currently only m68k, apus and m8xx need it */
  272. #ifndef IDE_ARCH_ACK_INTR
  273. # define ide_ack_intr(hwif) (1)
  274. #endif
  275. /* Currently only Atari needs it */
  276. #ifndef IDE_ARCH_LOCK
  277. # define ide_release_lock() do {} while (0)
  278. # define ide_get_lock(hdlr, data) do {} while (0)
  279. #endif /* IDE_ARCH_LOCK */
  280. /*
  281. * Now for the data we need to maintain per-drive: ide_drive_t
  282. */
  283. #define ide_scsi 0x21
  284. #define ide_disk 0x20
  285. #define ide_optical 0x7
  286. #define ide_cdrom 0x5
  287. #define ide_tape 0x1
  288. #define ide_floppy 0x0
  289. /*
  290. * Special Driver Flags
  291. *
  292. * set_geometry : respecify drive geometry
  293. * recalibrate : seek to cyl 0
  294. * set_multmode : set multmode count
  295. * set_tune : tune interface for drive
  296. * serviced : service command
  297. * reserved : unused
  298. */
  299. typedef union {
  300. unsigned all : 8;
  301. struct {
  302. #if defined(__LITTLE_ENDIAN_BITFIELD)
  303. unsigned set_geometry : 1;
  304. unsigned recalibrate : 1;
  305. unsigned set_multmode : 1;
  306. unsigned set_tune : 1;
  307. unsigned serviced : 1;
  308. unsigned reserved : 3;
  309. #elif defined(__BIG_ENDIAN_BITFIELD)
  310. unsigned reserved : 3;
  311. unsigned serviced : 1;
  312. unsigned set_tune : 1;
  313. unsigned set_multmode : 1;
  314. unsigned recalibrate : 1;
  315. unsigned set_geometry : 1;
  316. #else
  317. #error "Please fix <asm/byteorder.h>"
  318. #endif
  319. } b;
  320. } special_t;
  321. /*
  322. * ATA DATA Register Special.
  323. * ATA NSECTOR Count Register().
  324. * ATAPI Byte Count Register.
  325. * Channel index ordering pairs.
  326. */
  327. typedef union {
  328. unsigned all :16;
  329. struct {
  330. #if defined(__LITTLE_ENDIAN_BITFIELD)
  331. unsigned low :8; /* LSB */
  332. unsigned high :8; /* MSB */
  333. #elif defined(__BIG_ENDIAN_BITFIELD)
  334. unsigned high :8; /* MSB */
  335. unsigned low :8; /* LSB */
  336. #else
  337. #error "Please fix <asm/byteorder.h>"
  338. #endif
  339. } b;
  340. } ata_nsector_t, ata_data_t, atapi_bcount_t, ata_index_t;
  341. /*
  342. * ATA-IDE Error Register
  343. *
  344. * mark : Bad address mark
  345. * tzero : Couldn't find track 0
  346. * abrt : Aborted Command
  347. * mcr : Media Change Request
  348. * id : ID field not found
  349. * mce : Media Change Event
  350. * ecc : Uncorrectable ECC error
  351. * bdd : dual meaing
  352. */
  353. typedef union {
  354. unsigned all :8;
  355. struct {
  356. #if defined(__LITTLE_ENDIAN_BITFIELD)
  357. unsigned mark :1;
  358. unsigned tzero :1;
  359. unsigned abrt :1;
  360. unsigned mcr :1;
  361. unsigned id :1;
  362. unsigned mce :1;
  363. unsigned ecc :1;
  364. unsigned bdd :1;
  365. #elif defined(__BIG_ENDIAN_BITFIELD)
  366. unsigned bdd :1;
  367. unsigned ecc :1;
  368. unsigned mce :1;
  369. unsigned id :1;
  370. unsigned mcr :1;
  371. unsigned abrt :1;
  372. unsigned tzero :1;
  373. unsigned mark :1;
  374. #else
  375. #error "Please fix <asm/byteorder.h>"
  376. #endif
  377. } b;
  378. } ata_error_t;
  379. /*
  380. * ATA-IDE Select Register, aka Device-Head
  381. *
  382. * head : always zeros here
  383. * unit : drive select number: 0/1
  384. * bit5 : always 1
  385. * lba : using LBA instead of CHS
  386. * bit7 : always 1
  387. */
  388. typedef union {
  389. unsigned all : 8;
  390. struct {
  391. #if defined(__LITTLE_ENDIAN_BITFIELD)
  392. unsigned head : 4;
  393. unsigned unit : 1;
  394. unsigned bit5 : 1;
  395. unsigned lba : 1;
  396. unsigned bit7 : 1;
  397. #elif defined(__BIG_ENDIAN_BITFIELD)
  398. unsigned bit7 : 1;
  399. unsigned lba : 1;
  400. unsigned bit5 : 1;
  401. unsigned unit : 1;
  402. unsigned head : 4;
  403. #else
  404. #error "Please fix <asm/byteorder.h>"
  405. #endif
  406. } b;
  407. } select_t, ata_select_t;
  408. /*
  409. * The ATA-IDE Status Register.
  410. * The ATAPI Status Register.
  411. *
  412. * check : Error occurred
  413. * idx : Index Error
  414. * corr : Correctable error occurred
  415. * drq : Data is request by the device
  416. * dsc : Disk Seek Complete : ata
  417. * : Media access command finished : atapi
  418. * df : Device Fault : ata
  419. * : Reserved : atapi
  420. * drdy : Ready, Command Mode Capable : ata
  421. * : Ignored for ATAPI commands : atapi
  422. * bsy : Disk is Busy
  423. * : The device has access to the command block
  424. */
  425. typedef union {
  426. unsigned all :8;
  427. struct {
  428. #if defined(__LITTLE_ENDIAN_BITFIELD)
  429. unsigned check :1;
  430. unsigned idx :1;
  431. unsigned corr :1;
  432. unsigned drq :1;
  433. unsigned dsc :1;
  434. unsigned df :1;
  435. unsigned drdy :1;
  436. unsigned bsy :1;
  437. #elif defined(__BIG_ENDIAN_BITFIELD)
  438. unsigned bsy :1;
  439. unsigned drdy :1;
  440. unsigned df :1;
  441. unsigned dsc :1;
  442. unsigned drq :1;
  443. unsigned corr :1;
  444. unsigned idx :1;
  445. unsigned check :1;
  446. #else
  447. #error "Please fix <asm/byteorder.h>"
  448. #endif
  449. } b;
  450. } ata_status_t, atapi_status_t;
  451. /*
  452. * ATA-IDE Control Register
  453. *
  454. * bit0 : Should be set to zero
  455. * nIEN : device INTRQ to host
  456. * SRST : host soft reset bit
  457. * bit3 : ATA-2 thingy, Should be set to 1
  458. * reserved456 : Reserved
  459. * HOB : 48-bit address ordering, High Ordered Bit
  460. */
  461. typedef union {
  462. unsigned all : 8;
  463. struct {
  464. #if defined(__LITTLE_ENDIAN_BITFIELD)
  465. unsigned bit0 : 1;
  466. unsigned nIEN : 1;
  467. unsigned SRST : 1;
  468. unsigned bit3 : 1;
  469. unsigned reserved456 : 3;
  470. unsigned HOB : 1;
  471. #elif defined(__BIG_ENDIAN_BITFIELD)
  472. unsigned HOB : 1;
  473. unsigned reserved456 : 3;
  474. unsigned bit3 : 1;
  475. unsigned SRST : 1;
  476. unsigned nIEN : 1;
  477. unsigned bit0 : 1;
  478. #else
  479. #error "Please fix <asm/byteorder.h>"
  480. #endif
  481. } b;
  482. } ata_control_t;
  483. /*
  484. * ATAPI Feature Register
  485. *
  486. * dma : Using DMA or PIO
  487. * reserved321 : Reserved
  488. * reserved654 : Reserved (Tag Type)
  489. * reserved7 : Reserved
  490. */
  491. typedef union {
  492. unsigned all :8;
  493. struct {
  494. #if defined(__LITTLE_ENDIAN_BITFIELD)
  495. unsigned dma :1;
  496. unsigned reserved321 :3;
  497. unsigned reserved654 :3;
  498. unsigned reserved7 :1;
  499. #elif defined(__BIG_ENDIAN_BITFIELD)
  500. unsigned reserved7 :1;
  501. unsigned reserved654 :3;
  502. unsigned reserved321 :3;
  503. unsigned dma :1;
  504. #else
  505. #error "Please fix <asm/byteorder.h>"
  506. #endif
  507. } b;
  508. } atapi_feature_t;
  509. /*
  510. * ATAPI Interrupt Reason Register.
  511. *
  512. * cod : Information transferred is command (1) or data (0)
  513. * io : The device requests us to read (1) or write (0)
  514. * reserved : Reserved
  515. */
  516. typedef union {
  517. unsigned all :8;
  518. struct {
  519. #if defined(__LITTLE_ENDIAN_BITFIELD)
  520. unsigned cod :1;
  521. unsigned io :1;
  522. unsigned reserved :6;
  523. #elif defined(__BIG_ENDIAN_BITFIELD)
  524. unsigned reserved :6;
  525. unsigned io :1;
  526. unsigned cod :1;
  527. #else
  528. #error "Please fix <asm/byteorder.h>"
  529. #endif
  530. } b;
  531. } atapi_ireason_t;
  532. /*
  533. * The ATAPI error register.
  534. *
  535. * ili : Illegal Length Indication
  536. * eom : End Of Media Detected
  537. * abrt : Aborted command - As defined by ATA
  538. * mcr : Media Change Requested - As defined by ATA
  539. * sense_key : Sense key of the last failed packet command
  540. */
  541. typedef union {
  542. unsigned all :8;
  543. struct {
  544. #if defined(__LITTLE_ENDIAN_BITFIELD)
  545. unsigned ili :1;
  546. unsigned eom :1;
  547. unsigned abrt :1;
  548. unsigned mcr :1;
  549. unsigned sense_key :4;
  550. #elif defined(__BIG_ENDIAN_BITFIELD)
  551. unsigned sense_key :4;
  552. unsigned mcr :1;
  553. unsigned abrt :1;
  554. unsigned eom :1;
  555. unsigned ili :1;
  556. #else
  557. #error "Please fix <asm/byteorder.h>"
  558. #endif
  559. } b;
  560. } atapi_error_t;
  561. /*
  562. * ATAPI floppy Drive Select Register
  563. *
  564. * sam_lun : Logical unit number
  565. * reserved3 : Reserved
  566. * drv : The responding drive will be drive 0 (0) or drive 1 (1)
  567. * one5 : Should be set to 1
  568. * reserved6 : Reserved
  569. * one7 : Should be set to 1
  570. */
  571. typedef union {
  572. unsigned all :8;
  573. struct {
  574. #if defined(__LITTLE_ENDIAN_BITFIELD)
  575. unsigned sam_lun :3;
  576. unsigned reserved3 :1;
  577. unsigned drv :1;
  578. unsigned one5 :1;
  579. unsigned reserved6 :1;
  580. unsigned one7 :1;
  581. #elif defined(__BIG_ENDIAN_BITFIELD)
  582. unsigned one7 :1;
  583. unsigned reserved6 :1;
  584. unsigned one5 :1;
  585. unsigned drv :1;
  586. unsigned reserved3 :1;
  587. unsigned sam_lun :3;
  588. #else
  589. #error "Please fix <asm/byteorder.h>"
  590. #endif
  591. } b;
  592. } atapi_select_t;
  593. /*
  594. * Status returned from various ide_ functions
  595. */
  596. typedef enum {
  597. ide_stopped, /* no drive operation was started */
  598. ide_started, /* a drive operation was started, handler was set */
  599. } ide_startstop_t;
  600. struct ide_driver_s;
  601. struct ide_settings_s;
  602. typedef struct ide_drive_s {
  603. char name[4]; /* drive name, such as "hda" */
  604. char driver_req[10]; /* requests specific driver */
  605. request_queue_t *queue; /* request queue */
  606. struct request *rq; /* current request */
  607. struct ide_drive_s *next; /* circular list of hwgroup drives */
  608. void *driver_data; /* extra driver data */
  609. struct hd_driveid *id; /* drive model identification info */
  610. struct proc_dir_entry *proc; /* /proc/ide/ directory entry */
  611. struct ide_settings_s *settings;/* /proc/ide/ drive settings */
  612. char devfs_name[64]; /* devfs crap */
  613. struct hwif_s *hwif; /* actually (ide_hwif_t *) */
  614. unsigned long sleep; /* sleep until this time */
  615. unsigned long service_start; /* time we started last request */
  616. unsigned long service_time; /* service time of last request */
  617. unsigned long timeout; /* max time to wait for irq */
  618. special_t special; /* special action flags */
  619. select_t select; /* basic drive/head select reg value */
  620. u8 keep_settings; /* restore settings after drive reset */
  621. u8 autodma; /* device can safely use dma on host */
  622. u8 using_dma; /* disk is using dma for read/write */
  623. u8 retry_pio; /* retrying dma capable host in pio */
  624. u8 state; /* retry state */
  625. u8 waiting_for_dma; /* dma currently in progress */
  626. u8 unmask; /* okay to unmask other irqs */
  627. u8 bswap; /* byte swap data */
  628. u8 dsc_overlap; /* DSC overlap */
  629. u8 nice1; /* give potential excess bandwidth */
  630. unsigned present : 1; /* drive is physically present */
  631. unsigned dead : 1; /* device ejected hint */
  632. unsigned id_read : 1; /* 1=id read from disk 0 = synthetic */
  633. unsigned noprobe : 1; /* from: hdx=noprobe */
  634. unsigned removable : 1; /* 1 if need to do check_media_change */
  635. unsigned attach : 1; /* needed for removable devices */
  636. unsigned is_flash : 1; /* 1 if probed as flash */
  637. unsigned forced_geom : 1; /* 1 if hdx=c,h,s was given at boot */
  638. unsigned no_unmask : 1; /* disallow setting unmask bit */
  639. unsigned no_io_32bit : 1; /* disallow enabling 32bit I/O */
  640. unsigned atapi_overlap : 1; /* ATAPI overlap (not supported) */
  641. unsigned nice0 : 1; /* give obvious excess bandwidth */
  642. unsigned nice2 : 1; /* give a share in our own bandwidth */
  643. unsigned doorlocking : 1; /* for removable only: door lock/unlock works */
  644. unsigned autotune : 2; /* 0=default, 1=autotune, 2=noautotune */
  645. unsigned remap_0_to_1 : 1; /* 0=noremap, 1=remap 0->1 (for EZDrive) */
  646. unsigned blocked : 1; /* 1=powermanagment told us not to do anything, so sleep nicely */
  647. unsigned vdma : 1; /* 1=doing PIO over DMA 0=doing normal DMA */
  648. unsigned addressing; /* : 3;
  649. * 0=28-bit
  650. * 1=48-bit
  651. * 2=48-bit doing 28-bit
  652. * 3=64-bit
  653. */
  654. unsigned scsi : 1; /* 0=default, 1=ide-scsi emulation */
  655. unsigned sleeping : 1; /* 1=sleeping & sleep field valid */
  656. unsigned post_reset : 1;
  657. u8 quirk_list; /* considered quirky, set for a specific host */
  658. u8 init_speed; /* transfer rate set at boot */
  659. u8 pio_speed; /* unused by core, used by some drivers for fallback from DMA */
  660. u8 current_speed; /* current transfer rate set */
  661. u8 dn; /* now wide spread use */
  662. u8 wcache; /* status of write cache */
  663. u8 acoustic; /* acoustic management */
  664. u8 media; /* disk, cdrom, tape, floppy, ... */
  665. u8 ctl; /* "normal" value for IDE_CONTROL_REG */
  666. u8 ready_stat; /* min status value for drive ready */
  667. u8 mult_count; /* current multiple sector setting */
  668. u8 mult_req; /* requested multiple sector setting */
  669. u8 tune_req; /* requested drive tuning setting */
  670. u8 io_32bit; /* 0=16-bit, 1=32-bit, 2/3=32bit+sync */
  671. u8 bad_wstat; /* used for ignoring WRERR_STAT */
  672. u8 nowerr; /* used for ignoring WRERR_STAT */
  673. u8 sect0; /* offset of first sector for DM6:DDO */
  674. u8 head; /* "real" number of heads */
  675. u8 sect; /* "real" sectors per track */
  676. u8 bios_head; /* BIOS/fdisk/LILO number of heads */
  677. u8 bios_sect; /* BIOS/fdisk/LILO sectors per track */
  678. unsigned int bios_cyl; /* BIOS/fdisk/LILO number of cyls */
  679. unsigned int cyl; /* "real" number of cyls */
  680. unsigned int drive_data; /* use by tuneproc/selectproc */
  681. unsigned int usage; /* current "open()" count for drive */
  682. unsigned int failures; /* current failure count */
  683. unsigned int max_failures; /* maximum allowed failure count */
  684. u64 capacity64; /* total number of sectors */
  685. int lun; /* logical unit */
  686. int crc_count; /* crc counter to reduce drive speed */
  687. struct list_head list;
  688. struct device gendev;
  689. struct semaphore gendev_rel_sem; /* to deal with device release() */
  690. } ide_drive_t;
  691. #define to_ide_device(dev)container_of(dev, ide_drive_t, gendev)
  692. #define IDE_CHIPSET_PCI_MASK \
  693. ((1<<ide_pci)|(1<<ide_cmd646)|(1<<ide_ali14xx))
  694. #define IDE_CHIPSET_IS_PCI(c) ((IDE_CHIPSET_PCI_MASK >> (c)) & 1)
  695. struct ide_pci_device_s;
  696. typedef struct hwif_s {
  697. struct hwif_s *next; /* for linked-list in ide_hwgroup_t */
  698. struct hwif_s *mate; /* other hwif from same PCI chip */
  699. struct hwgroup_s *hwgroup; /* actually (ide_hwgroup_t *) */
  700. struct proc_dir_entry *proc; /* /proc/ide/ directory entry */
  701. char name[6]; /* name of interface, eg. "ide0" */
  702. /* task file registers for pata and sata */
  703. unsigned long io_ports[IDE_NR_PORTS];
  704. unsigned long sata_scr[SATA_NR_PORTS];
  705. unsigned long sata_misc[SATA_NR_PORTS];
  706. hw_regs_t hw; /* Hardware info */
  707. ide_drive_t drives[MAX_DRIVES]; /* drive info */
  708. u8 major; /* our major number */
  709. u8 index; /* 0 for ide0; 1 for ide1; ... */
  710. u8 channel; /* for dual-port chips: 0=primary, 1=secondary */
  711. u8 straight8; /* Alan's straight 8 check */
  712. u8 bus_state; /* power state of the IDE bus */
  713. u8 atapi_dma; /* host supports atapi_dma */
  714. u8 ultra_mask;
  715. u8 mwdma_mask;
  716. u8 swdma_mask;
  717. hwif_chipset_t chipset; /* sub-module for tuning.. */
  718. struct pci_dev *pci_dev; /* for pci chipsets */
  719. struct ide_pci_device_s *cds; /* chipset device struct */
  720. void (*rw_disk)(ide_drive_t *, struct request *);
  721. #if 0
  722. ide_hwif_ops_t *hwifops;
  723. #else
  724. /* routine to tune PIO mode for drives */
  725. void (*tuneproc)(ide_drive_t *, u8);
  726. /* routine to retune DMA modes for drives */
  727. int (*speedproc)(ide_drive_t *, u8);
  728. /* tweaks hardware to select drive */
  729. void (*selectproc)(ide_drive_t *);
  730. /* chipset polling based on hba specifics */
  731. int (*reset_poll)(ide_drive_t *);
  732. /* chipset specific changes to default for device-hba resets */
  733. void (*pre_reset)(ide_drive_t *);
  734. /* routine to reset controller after a disk reset */
  735. void (*resetproc)(ide_drive_t *);
  736. /* special interrupt handling for shared pci interrupts */
  737. void (*intrproc)(ide_drive_t *);
  738. /* special host masking for drive selection */
  739. void (*maskproc)(ide_drive_t *, int);
  740. /* check host's drive quirk list */
  741. int (*quirkproc)(ide_drive_t *);
  742. /* driver soft-power interface */
  743. int (*busproc)(ide_drive_t *, int);
  744. // /* host rate limiter */
  745. // u8 (*ratemask)(ide_drive_t *);
  746. // /* device rate limiter */
  747. // u8 (*ratefilter)(ide_drive_t *, u8);
  748. #endif
  749. void (*ata_input_data)(ide_drive_t *, void *, u32);
  750. void (*ata_output_data)(ide_drive_t *, void *, u32);
  751. void (*atapi_input_bytes)(ide_drive_t *, void *, u32);
  752. void (*atapi_output_bytes)(ide_drive_t *, void *, u32);
  753. int (*dma_setup)(ide_drive_t *);
  754. void (*dma_exec_cmd)(ide_drive_t *, u8);
  755. void (*dma_start)(ide_drive_t *);
  756. int (*ide_dma_end)(ide_drive_t *drive);
  757. int (*ide_dma_check)(ide_drive_t *drive);
  758. int (*ide_dma_on)(ide_drive_t *drive);
  759. int (*ide_dma_off_quietly)(ide_drive_t *drive);
  760. int (*ide_dma_test_irq)(ide_drive_t *drive);
  761. int (*ide_dma_host_on)(ide_drive_t *drive);
  762. int (*ide_dma_host_off)(ide_drive_t *drive);
  763. int (*ide_dma_lostirq)(ide_drive_t *drive);
  764. int (*ide_dma_timeout)(ide_drive_t *drive);
  765. void (*OUTB)(u8 addr, unsigned long port);
  766. void (*OUTBSYNC)(ide_drive_t *drive, u8 addr, unsigned long port);
  767. void (*OUTW)(u16 addr, unsigned long port);
  768. void (*OUTL)(u32 addr, unsigned long port);
  769. void (*OUTSW)(unsigned long port, void *addr, u32 count);
  770. void (*OUTSL)(unsigned long port, void *addr, u32 count);
  771. u8 (*INB)(unsigned long port);
  772. u16 (*INW)(unsigned long port);
  773. u32 (*INL)(unsigned long port);
  774. void (*INSW)(unsigned long port, void *addr, u32 count);
  775. void (*INSL)(unsigned long port, void *addr, u32 count);
  776. /* dma physical region descriptor table (cpu view) */
  777. unsigned int *dmatable_cpu;
  778. /* dma physical region descriptor table (dma view) */
  779. dma_addr_t dmatable_dma;
  780. /* Scatter-gather list used to build the above */
  781. struct scatterlist *sg_table;
  782. int sg_max_nents; /* Maximum number of entries in it */
  783. int sg_nents; /* Current number of entries in it */
  784. int sg_dma_direction; /* dma transfer direction */
  785. /* data phase of the active command (currently only valid for PIO/DMA) */
  786. int data_phase;
  787. unsigned int nsect;
  788. unsigned int nleft;
  789. unsigned int cursg;
  790. unsigned int cursg_ofs;
  791. int mmio; /* hosts iomio (0) or custom (2) select */
  792. int rqsize; /* max sectors per request */
  793. int irq; /* our irq number */
  794. unsigned long dma_master; /* reference base addr dmabase */
  795. unsigned long dma_base; /* base addr for dma ports */
  796. unsigned long dma_command; /* dma command register */
  797. unsigned long dma_vendor1; /* dma vendor 1 register */
  798. unsigned long dma_status; /* dma status register */
  799. unsigned long dma_vendor3; /* dma vendor 3 register */
  800. unsigned long dma_prdtable; /* actual prd table address */
  801. unsigned long dma_base2; /* extended base addr for dma ports */
  802. unsigned dma_extra; /* extra addr for dma ports */
  803. unsigned long config_data; /* for use by chipset-specific code */
  804. unsigned long select_data; /* for use by chipset-specific code */
  805. unsigned noprobe : 1; /* don't probe for this interface */
  806. unsigned present : 1; /* this interface exists */
  807. unsigned hold : 1; /* this interface is always present */
  808. unsigned serialized : 1; /* serialized all channel operation */
  809. unsigned sharing_irq: 1; /* 1 = sharing irq with another hwif */
  810. unsigned reset : 1; /* reset after probe */
  811. unsigned autodma : 1; /* auto-attempt using DMA at boot */
  812. unsigned udma_four : 1; /* 1=ATA-66 capable, 0=default */
  813. unsigned no_lba48 : 1; /* 1 = cannot do LBA48 */
  814. unsigned no_lba48_dma : 1; /* 1 = cannot do LBA48 DMA */
  815. unsigned no_dsc : 1; /* 0 default, 1 dsc_overlap disabled */
  816. unsigned auto_poll : 1; /* supports nop auto-poll */
  817. unsigned sg_mapped : 1; /* sg_table and sg_nents are ready */
  818. struct device gendev;
  819. struct semaphore gendev_rel_sem; /* To deal with device release() */
  820. void *hwif_data; /* extra hwif data */
  821. unsigned dma;
  822. void (*led_act)(void *data, int rw);
  823. } ____cacheline_maxaligned_in_smp ide_hwif_t;
  824. /*
  825. * internal ide interrupt handler type
  826. */
  827. typedef ide_startstop_t (ide_pre_handler_t)(ide_drive_t *, struct request *);
  828. typedef ide_startstop_t (ide_handler_t)(ide_drive_t *);
  829. typedef int (ide_expiry_t)(ide_drive_t *);
  830. typedef struct hwgroup_s {
  831. /* irq handler, if active */
  832. ide_startstop_t (*handler)(ide_drive_t *);
  833. /* irq handler, suspended if active */
  834. ide_startstop_t (*handler_save)(ide_drive_t *);
  835. /* BOOL: protects all fields below */
  836. volatile int busy;
  837. /* BOOL: wake us up on timer expiry */
  838. unsigned int sleeping : 1;
  839. /* BOOL: polling active & poll_timeout field valid */
  840. unsigned int polling : 1;
  841. /* current drive */
  842. ide_drive_t *drive;
  843. /* ptr to current hwif in linked-list */
  844. ide_hwif_t *hwif;
  845. /* for pci chipsets */
  846. struct pci_dev *pci_dev;
  847. /* chipset device struct */
  848. struct ide_pci_device_s *cds;
  849. /* current request */
  850. struct request *rq;
  851. /* failsafe timer */
  852. struct timer_list timer;
  853. /* local copy of current write rq */
  854. struct request wrq;
  855. /* timeout value during long polls */
  856. unsigned long poll_timeout;
  857. /* queried upon timeouts */
  858. int (*expiry)(ide_drive_t *);
  859. /* ide_system_bus_speed */
  860. int pio_clock;
  861. unsigned char cmd_buf[4];
  862. } ide_hwgroup_t;
  863. /* structure attached to the request for IDE_TASK_CMDS */
  864. /*
  865. * configurable drive settings
  866. */
  867. #define TYPE_INT 0
  868. #define TYPE_INTA 1
  869. #define TYPE_BYTE 2
  870. #define TYPE_SHORT 3
  871. #define SETTING_READ (1 << 0)
  872. #define SETTING_WRITE (1 << 1)
  873. #define SETTING_RW (SETTING_READ | SETTING_WRITE)
  874. typedef int (ide_procset_t)(ide_drive_t *, int);
  875. typedef struct ide_settings_s {
  876. char *name;
  877. int rw;
  878. int read_ioctl;
  879. int write_ioctl;
  880. int data_type;
  881. int min;
  882. int max;
  883. int mul_factor;
  884. int div_factor;
  885. void *data;
  886. ide_procset_t *set;
  887. int auto_remove;
  888. struct ide_settings_s *next;
  889. } ide_settings_t;
  890. extern struct semaphore ide_setting_sem;
  891. extern int ide_add_setting(ide_drive_t *drive, const char *name, int rw, int read_ioctl, int write_ioctl, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set);
  892. extern ide_settings_t *ide_find_setting_by_name(ide_drive_t *drive, char *name);
  893. extern int ide_read_setting(ide_drive_t *t, ide_settings_t *setting);
  894. extern int ide_write_setting(ide_drive_t *drive, ide_settings_t *setting, int val);
  895. extern void ide_add_generic_settings(ide_drive_t *drive);
  896. /*
  897. * /proc/ide interface
  898. */
  899. typedef struct {
  900. const char *name;
  901. mode_t mode;
  902. read_proc_t *read_proc;
  903. write_proc_t *write_proc;
  904. } ide_proc_entry_t;
  905. #ifdef CONFIG_PROC_FS
  906. extern struct proc_dir_entry *proc_ide_root;
  907. extern void proc_ide_create(void);
  908. extern void proc_ide_destroy(void);
  909. extern void create_proc_ide_interfaces(void);
  910. void destroy_proc_ide_interface(ide_hwif_t *);
  911. extern void ide_add_proc_entries(struct proc_dir_entry *, ide_proc_entry_t *, void *);
  912. extern void ide_remove_proc_entries(struct proc_dir_entry *, ide_proc_entry_t *);
  913. read_proc_t proc_ide_read_capacity;
  914. read_proc_t proc_ide_read_geometry;
  915. #ifdef CONFIG_BLK_DEV_IDEPCI
  916. void ide_pci_create_host_proc(const char *, get_info_t *);
  917. #endif
  918. /*
  919. * Standard exit stuff:
  920. */
  921. #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) \
  922. { \
  923. len -= off; \
  924. if (len < count) { \
  925. *eof = 1; \
  926. if (len <= 0) \
  927. return 0; \
  928. } else \
  929. len = count; \
  930. *start = page + off; \
  931. return len; \
  932. }
  933. #else
  934. static inline void create_proc_ide_interfaces(void) { ; }
  935. static inline void destroy_proc_ide_interface(ide_hwif_t *hwif) { ; }
  936. #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) return 0;
  937. #endif
  938. /*
  939. * Power Management step value (rq->pm->pm_step).
  940. *
  941. * The step value starts at 0 (ide_pm_state_start_suspend) for a
  942. * suspend operation or 1000 (ide_pm_state_start_resume) for a
  943. * resume operation.
  944. *
  945. * For each step, the core calls the subdriver start_power_step() first.
  946. * This can return:
  947. * - ide_stopped : In this case, the core calls us back again unless
  948. * step have been set to ide_power_state_completed.
  949. * - ide_started : In this case, the channel is left busy until an
  950. * async event (interrupt) occurs.
  951. * Typically, start_power_step() will issue a taskfile request with
  952. * do_rw_taskfile().
  953. *
  954. * Upon reception of the interrupt, the core will call complete_power_step()
  955. * with the error code if any. This routine should update the step value
  956. * and return. It should not start a new request. The core will call
  957. * start_power_step for the new step value, unless step have been set to
  958. * ide_power_state_completed.
  959. *
  960. * Subdrivers are expected to define their own additional power
  961. * steps from 1..999 for suspend and from 1001..1999 for resume,
  962. * other values are reserved for future use.
  963. */
  964. enum {
  965. ide_pm_state_completed = -1,
  966. ide_pm_state_start_suspend = 0,
  967. ide_pm_state_start_resume = 1000,
  968. };
  969. /*
  970. * Subdrivers support.
  971. */
  972. typedef struct ide_driver_s {
  973. struct module *owner;
  974. const char *version;
  975. u8 media;
  976. unsigned supports_dsc_overlap : 1;
  977. ide_startstop_t (*do_request)(ide_drive_t *, struct request *, sector_t);
  978. int (*end_request)(ide_drive_t *, int, int);
  979. ide_startstop_t (*error)(ide_drive_t *, struct request *rq, u8, u8);
  980. ide_startstop_t (*abort)(ide_drive_t *, struct request *rq);
  981. int (*ioctl)(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
  982. ide_proc_entry_t *proc;
  983. void (*ata_prebuilder)(ide_drive_t *);
  984. void (*atapi_prebuilder)(ide_drive_t *);
  985. struct device_driver gen_driver;
  986. } ide_driver_t;
  987. int generic_ide_ioctl(ide_drive_t *, struct file *, struct block_device *, unsigned, unsigned long);
  988. /*
  989. * ide_hwifs[] is the master data structure used to keep track
  990. * of just about everything in ide.c. Whenever possible, routines
  991. * should be using pointers to a drive (ide_drive_t *) or
  992. * pointers to a hwif (ide_hwif_t *), rather than indexing this
  993. * structure directly (the allocation/layout may change!).
  994. *
  995. */
  996. #ifndef _IDE_C
  997. extern ide_hwif_t ide_hwifs[]; /* master data repository */
  998. #endif
  999. extern int noautodma;
  1000. extern int ide_end_request (ide_drive_t *drive, int uptodate, int nrsecs);
  1001. extern int __ide_end_request (ide_drive_t *drive, struct request *rq, int uptodate, int nrsecs);
  1002. /*
  1003. * This is used on exit from the driver to designate the next irq handler
  1004. * and also to start the safety timer.
  1005. */
  1006. extern void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry);
  1007. /*
  1008. * This is used on exit from the driver to designate the next irq handler
  1009. * and start the safety time safely and atomically from the IRQ handler
  1010. * with respect to the command issue (which it also does)
  1011. */
  1012. extern void ide_execute_command(ide_drive_t *, task_ioreg_t cmd, ide_handler_t *, unsigned int, ide_expiry_t *);
  1013. ide_startstop_t __ide_error(ide_drive_t *, struct request *, u8, u8);
  1014. /*
  1015. * ide_error() takes action based on the error returned by the controller.
  1016. * The caller should return immediately after invoking this.
  1017. *
  1018. * (drive, msg, status)
  1019. */
  1020. ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, byte stat);
  1021. ide_startstop_t __ide_abort(ide_drive_t *, struct request *);
  1022. /*
  1023. * Abort a running command on the controller triggering the abort
  1024. * from a host side, non error situation
  1025. * (drive, msg)
  1026. */
  1027. extern ide_startstop_t ide_abort(ide_drive_t *, const char *);
  1028. extern void ide_fix_driveid(struct hd_driveid *);
  1029. /*
  1030. * ide_fixstring() cleans up and (optionally) byte-swaps a text string,
  1031. * removing leading/trailing blanks and compressing internal blanks.
  1032. * It is primarily used to tidy up the model name/number fields as
  1033. * returned by the WIN_[P]IDENTIFY commands.
  1034. *
  1035. * (s, bytecount, byteswap)
  1036. */
  1037. extern void ide_fixstring(u8 *, const int, const int);
  1038. /*
  1039. * This routine busy-waits for the drive status to be not "busy".
  1040. * It then checks the status for all of the "good" bits and none
  1041. * of the "bad" bits, and if all is okay it returns 0. All other
  1042. * cases return 1 after doing "*startstop = ide_error()", and the
  1043. * caller should return the updated value of "startstop" in this case.
  1044. * "startstop" is unchanged when the function returns 0;
  1045. * (startstop, drive, good, bad, timeout)
  1046. */
  1047. extern int ide_wait_stat(ide_startstop_t *, ide_drive_t *, u8, u8, unsigned long);
  1048. /*
  1049. * Start a reset operation for an IDE interface.
  1050. * The caller should return immediately after invoking this.
  1051. */
  1052. extern ide_startstop_t ide_do_reset (ide_drive_t *);
  1053. /*
  1054. * This function is intended to be used prior to invoking ide_do_drive_cmd().
  1055. */
  1056. extern void ide_init_drive_cmd (struct request *rq);
  1057. /*
  1058. * this function returns error location sector offset in case of a write error
  1059. */
  1060. extern u64 ide_get_error_location(ide_drive_t *, char *);
  1061. /*
  1062. * "action" parameter type for ide_do_drive_cmd() below.
  1063. */
  1064. typedef enum {
  1065. ide_wait, /* insert rq at end of list, and wait for it */
  1066. ide_next, /* insert rq immediately after current request */
  1067. ide_preempt, /* insert rq in front of current request */
  1068. ide_head_wait, /* insert rq in front of current request and wait for it */
  1069. ide_end /* insert rq at end of list, but don't wait for it */
  1070. } ide_action_t;
  1071. /*
  1072. * This function issues a special IDE device request
  1073. * onto the request queue.
  1074. *
  1075. * If action is ide_wait, then the rq is queued at the end of the
  1076. * request queue, and the function sleeps until it has been processed.
  1077. * This is for use when invoked from an ioctl handler.
  1078. *
  1079. * If action is ide_preempt, then the rq is queued at the head of
  1080. * the request queue, displacing the currently-being-processed
  1081. * request and this function returns immediately without waiting
  1082. * for the new rq to be completed. This is VERY DANGEROUS, and is
  1083. * intended for careful use by the ATAPI tape/cdrom driver code.
  1084. *
  1085. * If action is ide_next, then the rq is queued immediately after
  1086. * the currently-being-processed-request (if any), and the function
  1087. * returns without waiting for the new rq to be completed. As above,
  1088. * This is VERY DANGEROUS, and is intended for careful use by the
  1089. * ATAPI tape/cdrom driver code.
  1090. *
  1091. * If action is ide_end, then the rq is queued at the end of the
  1092. * request queue, and the function returns immediately without waiting
  1093. * for the new rq to be completed. This is again intended for careful
  1094. * use by the ATAPI tape/cdrom driver code.
  1095. */
  1096. extern int ide_do_drive_cmd(ide_drive_t *, struct request *, ide_action_t);
  1097. /*
  1098. * Clean up after success/failure of an explicit drive cmd.
  1099. * stat/err are used only when (HWGROUP(drive)->rq->cmd == IDE_DRIVE_CMD).
  1100. * stat/err are used only when (HWGROUP(drive)->rq->cmd == IDE_DRIVE_TASK_MASK).
  1101. *
  1102. * (ide_drive_t *drive, u8 stat, u8 err)
  1103. */
  1104. extern void ide_end_drive_cmd(ide_drive_t *, u8, u8);
  1105. /*
  1106. * Issue ATA command and wait for completion.
  1107. * Use for implementing commands in kernel
  1108. *
  1109. * (ide_drive_t *drive, u8 cmd, u8 nsect, u8 feature, u8 sectors, u8 *buf)
  1110. */
  1111. extern int ide_wait_cmd(ide_drive_t *, u8, u8, u8, u8, u8 *);
  1112. typedef struct ide_task_s {
  1113. /*
  1114. * struct hd_drive_task_hdr tf;
  1115. * task_struct_t tf;
  1116. * struct hd_drive_hob_hdr hobf;
  1117. * hob_struct_t hobf;
  1118. */
  1119. task_ioreg_t tfRegister[8];
  1120. task_ioreg_t hobRegister[8];
  1121. ide_reg_valid_t tf_out_flags;
  1122. ide_reg_valid_t tf_in_flags;
  1123. int data_phase;
  1124. int command_type;
  1125. ide_pre_handler_t *prehandler;
  1126. ide_handler_t *handler;
  1127. struct request *rq; /* copy of request */
  1128. void *special; /* valid_t generally */
  1129. } ide_task_t;
  1130. extern u32 ide_read_24(ide_drive_t *);
  1131. extern void SELECT_DRIVE(ide_drive_t *);
  1132. extern void SELECT_INTERRUPT(ide_drive_t *);
  1133. extern void SELECT_MASK(ide_drive_t *, int);
  1134. extern void QUIRK_LIST(ide_drive_t *);
  1135. extern int drive_is_ready(ide_drive_t *);
  1136. extern int wait_for_ready(ide_drive_t *, int /* timeout */);
  1137. /*
  1138. * taskfile io for disks for now...and builds request from ide_ioctl
  1139. */
  1140. extern ide_startstop_t do_rw_taskfile(ide_drive_t *, ide_task_t *);
  1141. /*
  1142. * Special Flagged Register Validation Caller
  1143. */
  1144. extern ide_startstop_t flagged_taskfile(ide_drive_t *, ide_task_t *);
  1145. extern ide_startstop_t set_multmode_intr(ide_drive_t *);
  1146. extern ide_startstop_t set_geometry_intr(ide_drive_t *);
  1147. extern ide_startstop_t recal_intr(ide_drive_t *);
  1148. extern ide_startstop_t task_no_data_intr(ide_drive_t *);
  1149. extern ide_startstop_t task_in_intr(ide_drive_t *);
  1150. extern ide_startstop_t pre_task_out_intr(ide_drive_t *, struct request *);
  1151. extern int ide_raw_taskfile(ide_drive_t *, ide_task_t *, u8 *);
  1152. int ide_taskfile_ioctl(ide_drive_t *, unsigned int, unsigned long);
  1153. int ide_cmd_ioctl(ide_drive_t *, unsigned int, unsigned long);
  1154. int ide_task_ioctl(ide_drive_t *, unsigned int, unsigned long);
  1155. extern int system_bus_clock(void);
  1156. extern int ide_driveid_update(ide_drive_t *);
  1157. extern int ide_ata66_check(ide_drive_t *, ide_task_t *);
  1158. extern int ide_config_drive_speed(ide_drive_t *, u8);
  1159. extern u8 eighty_ninty_three (ide_drive_t *);
  1160. extern int set_transfer(ide_drive_t *, ide_task_t *);
  1161. extern int taskfile_lib_get_identify(ide_drive_t *drive, u8 *);
  1162. extern int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout);
  1163. /*
  1164. * ide_stall_queue() can be used by a drive to give excess bandwidth back
  1165. * to the hwgroup by sleeping for timeout jiffies.
  1166. */
  1167. extern void ide_stall_queue(ide_drive_t *drive, unsigned long timeout);
  1168. extern int ide_spin_wait_hwgroup(ide_drive_t *);
  1169. extern void ide_timer_expiry(unsigned long);
  1170. extern irqreturn_t ide_intr(int irq, void *dev_id, struct pt_regs *regs);
  1171. extern void do_ide_request(request_queue_t *);
  1172. extern void ide_init_subdrivers(void);
  1173. void ide_init_disk(struct gendisk *, ide_drive_t *);
  1174. extern int ideprobe_init(void);
  1175. extern void ide_scan_pcibus(int scan_direction) __init;
  1176. extern int ide_pci_register_driver(struct pci_driver *driver);
  1177. extern void ide_pci_unregister_driver(struct pci_driver *driver);
  1178. void ide_pci_setup_ports(struct pci_dev *, struct ide_pci_device_s *, int, ata_index_t *);
  1179. extern void ide_setup_pci_noise (struct pci_dev *dev, struct ide_pci_device_s *d);
  1180. extern void default_hwif_iops(ide_hwif_t *);
  1181. extern void default_hwif_mmiops(ide_hwif_t *);
  1182. extern void default_hwif_transport(ide_hwif_t *);
  1183. void ide_register_subdriver(ide_drive_t *, ide_driver_t *);
  1184. void ide_unregister_subdriver(ide_drive_t *, ide_driver_t *);
  1185. #define ON_BOARD 1
  1186. #define NEVER_BOARD 0
  1187. #ifdef CONFIG_BLK_DEV_OFFBOARD
  1188. # define OFF_BOARD ON_BOARD
  1189. #else /* CONFIG_BLK_DEV_OFFBOARD */
  1190. # define OFF_BOARD NEVER_BOARD
  1191. #endif /* CONFIG_BLK_DEV_OFFBOARD */
  1192. #define NODMA 0
  1193. #define NOAUTODMA 1
  1194. #define AUTODMA 2
  1195. typedef struct ide_pci_enablebit_s {
  1196. u8 reg; /* byte pci reg holding the enable-bit */
  1197. u8 mask; /* mask to isolate the enable-bit */
  1198. u8 val; /* value of masked reg when "enabled" */
  1199. } ide_pci_enablebit_t;
  1200. enum {
  1201. /* Uses ISA control ports not PCI ones. */
  1202. IDEPCI_FLAG_ISA_PORTS = (1 << 0),
  1203. IDEPCI_FLAG_FORCE_PDC = (1 << 1),
  1204. };
  1205. typedef struct ide_pci_device_s {
  1206. char *name;
  1207. int (*init_setup)(struct pci_dev *, struct ide_pci_device_s *);
  1208. void (*init_setup_dma)(struct pci_dev *, struct ide_pci_device_s *, ide_hwif_t *);
  1209. unsigned int (*init_chipset)(struct pci_dev *, const char *);
  1210. void (*init_iops)(ide_hwif_t *);
  1211. void (*init_hwif)(ide_hwif_t *);
  1212. void (*init_dma)(ide_hwif_t *, unsigned long);
  1213. void (*fixup)(ide_hwif_t *);
  1214. u8 channels;
  1215. u8 autodma;
  1216. ide_pci_enablebit_t enablebits[2];
  1217. u8 bootable;
  1218. unsigned int extra;
  1219. struct ide_pci_device_s *next;
  1220. u8 flags;
  1221. } ide_pci_device_t;
  1222. extern int ide_setup_pci_device(struct pci_dev *, ide_pci_device_t *);
  1223. extern int ide_setup_pci_devices(struct pci_dev *, struct pci_dev *, ide_pci_device_t *);
  1224. void ide_map_sg(ide_drive_t *, struct request *);
  1225. void ide_init_sg_cmd(ide_drive_t *, struct request *);
  1226. #define BAD_DMA_DRIVE 0
  1227. #define GOOD_DMA_DRIVE 1
  1228. #ifdef CONFIG_BLK_DEV_IDEDMA
  1229. int __ide_dma_bad_drive(ide_drive_t *);
  1230. int __ide_dma_good_drive(ide_drive_t *);
  1231. int ide_use_dma(ide_drive_t *);
  1232. int __ide_dma_off(ide_drive_t *);
  1233. void ide_dma_verbose(ide_drive_t *);
  1234. ide_startstop_t ide_dma_intr(ide_drive_t *);
  1235. #ifdef CONFIG_BLK_DEV_IDEDMA_PCI
  1236. extern int ide_build_sglist(ide_drive_t *, struct request *);
  1237. extern int ide_build_dmatable(ide_drive_t *, struct request *);
  1238. extern void ide_destroy_dmatable(ide_drive_t *);
  1239. extern int ide_release_dma(ide_hwif_t *);
  1240. extern void ide_setup_dma(ide_hwif_t *, unsigned long, unsigned int);
  1241. extern int __ide_dma_host_off(ide_drive_t *);
  1242. extern int __ide_dma_off_quietly(ide_drive_t *);
  1243. extern int __ide_dma_host_on(ide_drive_t *);
  1244. extern int __ide_dma_on(ide_drive_t *);
  1245. extern int __ide_dma_check(ide_drive_t *);
  1246. extern int ide_dma_setup(ide_drive_t *);
  1247. extern void ide_dma_start(ide_drive_t *);
  1248. extern int __ide_dma_end(ide_drive_t *);
  1249. extern int __ide_dma_lostirq(ide_drive_t *);
  1250. extern int __ide_dma_timeout(ide_drive_t *);
  1251. #endif /* CONFIG_BLK_DEV_IDEDMA_PCI */
  1252. #else
  1253. static inline int ide_use_dma(ide_drive_t *drive) { return 0; }
  1254. static inline int __ide_dma_off(ide_drive_t *drive) { return 0; }
  1255. static inline void ide_dma_verbose(ide_drive_t *drive) { ; }
  1256. #endif /* CONFIG_BLK_DEV_IDEDMA */
  1257. #ifndef CONFIG_BLK_DEV_IDEDMA_PCI
  1258. static inline void ide_release_dma(ide_hwif_t *drive) {;}
  1259. #endif
  1260. extern int ide_hwif_request_regions(ide_hwif_t *hwif);
  1261. extern void ide_hwif_release_regions(ide_hwif_t* hwif);
  1262. extern void ide_unregister (unsigned int index);
  1263. void ide_register_region(struct gendisk *);
  1264. void ide_unregister_region(struct gendisk *);
  1265. void ide_undecoded_slave(ide_hwif_t *);
  1266. int probe_hwif_init_with_fixup(ide_hwif_t *, void (*)(ide_hwif_t *));
  1267. extern int probe_hwif_init(ide_hwif_t *);
  1268. static inline void *ide_get_hwifdata (ide_hwif_t * hwif)
  1269. {
  1270. return hwif->hwif_data;
  1271. }
  1272. static inline void ide_set_hwifdata (ide_hwif_t * hwif, void *data)
  1273. {
  1274. hwif->hwif_data = data;
  1275. }
  1276. /* ide-lib.c */
  1277. extern u8 ide_dma_speed(ide_drive_t *drive, u8 mode);
  1278. extern u8 ide_rate_filter(u8 mode, u8 speed);
  1279. extern int ide_dma_enable(ide_drive_t *drive);
  1280. extern char *ide_xfer_verbose(u8 xfer_rate);
  1281. extern void ide_toggle_bounce(ide_drive_t *drive, int on);
  1282. extern int ide_set_xfer_rate(ide_drive_t *drive, u8 rate);
  1283. u8 ide_dump_status(ide_drive_t *, const char *, u8);
  1284. typedef struct ide_pio_timings_s {
  1285. int setup_time; /* Address setup (ns) minimum */
  1286. int active_time; /* Active pulse (ns) minimum */
  1287. int cycle_time; /* Cycle time (ns) minimum = (setup + active + recovery) */
  1288. } ide_pio_timings_t;
  1289. typedef struct ide_pio_data_s {
  1290. u8 pio_mode;
  1291. u8 use_iordy;
  1292. u8 overridden;
  1293. u8 blacklisted;
  1294. unsigned int cycle_time;
  1295. } ide_pio_data_t;
  1296. extern u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_pio_data_t *d);
  1297. extern const ide_pio_timings_t ide_pio_timings[6];
  1298. extern spinlock_t ide_lock;
  1299. extern struct semaphore ide_cfg_sem;
  1300. /*
  1301. * Structure locking:
  1302. *
  1303. * ide_cfg_sem and ide_lock together protect changes to
  1304. * ide_hwif_t->{next,hwgroup}
  1305. * ide_drive_t->next
  1306. *
  1307. * ide_hwgroup_t->busy: ide_lock
  1308. * ide_hwgroup_t->hwif: ide_lock
  1309. * ide_hwif_t->mate: constant, no locking
  1310. * ide_drive_t->hwif: constant, no locking
  1311. */
  1312. #define local_irq_set(flags) do { local_save_flags((flags)); local_irq_enable(); } while (0)
  1313. extern struct bus_type ide_bus_type;
  1314. /* check if CACHE FLUSH (EXT) command is supported (bits defined in ATA-6) */
  1315. #define ide_id_has_flush_cache(id) ((id)->cfs_enable_2 & 0x3000)
  1316. /* some Maxtor disks have bit 13 defined incorrectly so check bit 10 too */
  1317. #define ide_id_has_flush_cache_ext(id) \
  1318. (((id)->cfs_enable_2 & 0x2400) == 0x2400)
  1319. static inline int hwif_to_node(ide_hwif_t *hwif)
  1320. {
  1321. struct pci_dev *dev = hwif->pci_dev;
  1322. return dev ? pcibus_to_node(dev->bus) : -1;
  1323. }
  1324. #endif /* _IDE_H */