ide.h 45 KB

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