ide.h 45 KB

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