ide.h 46 KB

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