ide.h 44 KB

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