aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/linux/ata.h41
-rw-r--r--include/linux/libata.h113
2 files changed, 113 insertions, 41 deletions
diff --git a/include/linux/ata.h b/include/linux/ata.h
index a5b74efab067..d2873b732bb1 100644
--- a/include/linux/ata.h
+++ b/include/linux/ata.h
@@ -42,13 +42,18 @@ enum {
42 ATA_SECT_SIZE = 512, 42 ATA_SECT_SIZE = 512,
43 43
44 ATA_ID_WORDS = 256, 44 ATA_ID_WORDS = 256,
45 ATA_ID_PROD_OFS = 27,
46 ATA_ID_FW_REV_OFS = 23,
47 ATA_ID_SERNO_OFS = 10, 45 ATA_ID_SERNO_OFS = 10,
48 ATA_ID_MAJOR_VER = 80, 46 ATA_ID_FW_REV_OFS = 23,
49 ATA_ID_PIO_MODES = 64, 47 ATA_ID_PROD_OFS = 27,
48 ATA_ID_OLD_PIO_MODES = 51,
49 ATA_ID_FIELD_VALID = 53,
50 ATA_ID_MWDMA_MODES = 63, 50 ATA_ID_MWDMA_MODES = 63,
51 ATA_ID_PIO_MODES = 64,
52 ATA_ID_EIDE_DMA_MIN = 65,
53 ATA_ID_EIDE_PIO = 67,
54 ATA_ID_EIDE_PIO_IORDY = 68,
51 ATA_ID_UDMA_MODES = 88, 55 ATA_ID_UDMA_MODES = 88,
56 ATA_ID_MAJOR_VER = 80,
52 ATA_ID_PIO4 = (1 << 1), 57 ATA_ID_PIO4 = (1 << 1),
53 58
54 ATA_PCI_CTL_OFS = 2, 59 ATA_PCI_CTL_OFS = 2,
@@ -128,10 +133,15 @@ enum {
128 ATA_CMD_PIO_READ_EXT = 0x24, 133 ATA_CMD_PIO_READ_EXT = 0x24,
129 ATA_CMD_PIO_WRITE = 0x30, 134 ATA_CMD_PIO_WRITE = 0x30,
130 ATA_CMD_PIO_WRITE_EXT = 0x34, 135 ATA_CMD_PIO_WRITE_EXT = 0x34,
136 ATA_CMD_READ_MULTI = 0xC4,
137 ATA_CMD_READ_MULTI_EXT = 0x29,
138 ATA_CMD_WRITE_MULTI = 0xC5,
139 ATA_CMD_WRITE_MULTI_EXT = 0x39,
131 ATA_CMD_SET_FEATURES = 0xEF, 140 ATA_CMD_SET_FEATURES = 0xEF,
132 ATA_CMD_PACKET = 0xA0, 141 ATA_CMD_PACKET = 0xA0,
133 ATA_CMD_VERIFY = 0x40, 142 ATA_CMD_VERIFY = 0x40,
134 ATA_CMD_VERIFY_EXT = 0x42, 143 ATA_CMD_VERIFY_EXT = 0x42,
144 ATA_CMD_INIT_DEV_PARAMS = 0x91,
135 145
136 /* SETFEATURES stuff */ 146 /* SETFEATURES stuff */
137 SETFEATURES_XFER = 0x03, 147 SETFEATURES_XFER = 0x03,
@@ -146,14 +156,14 @@ enum {
146 XFER_MW_DMA_2 = 0x22, 156 XFER_MW_DMA_2 = 0x22,
147 XFER_MW_DMA_1 = 0x21, 157 XFER_MW_DMA_1 = 0x21,
148 XFER_MW_DMA_0 = 0x20, 158 XFER_MW_DMA_0 = 0x20,
159 XFER_SW_DMA_2 = 0x12,
160 XFER_SW_DMA_1 = 0x11,
161 XFER_SW_DMA_0 = 0x10,
149 XFER_PIO_4 = 0x0C, 162 XFER_PIO_4 = 0x0C,
150 XFER_PIO_3 = 0x0B, 163 XFER_PIO_3 = 0x0B,
151 XFER_PIO_2 = 0x0A, 164 XFER_PIO_2 = 0x0A,
152 XFER_PIO_1 = 0x09, 165 XFER_PIO_1 = 0x09,
153 XFER_PIO_0 = 0x08, 166 XFER_PIO_0 = 0x08,
154 XFER_SW_DMA_2 = 0x12,
155 XFER_SW_DMA_1 = 0x11,
156 XFER_SW_DMA_0 = 0x10,
157 XFER_PIO_SLOW = 0x00, 167 XFER_PIO_SLOW = 0x00,
158 168
159 /* ATAPI stuff */ 169 /* ATAPI stuff */
@@ -181,6 +191,7 @@ enum {
181 ATA_TFLAG_ISADDR = (1 << 1), /* enable r/w to nsect/lba regs */ 191 ATA_TFLAG_ISADDR = (1 << 1), /* enable r/w to nsect/lba regs */
182 ATA_TFLAG_DEVICE = (1 << 2), /* enable r/w to device reg */ 192 ATA_TFLAG_DEVICE = (1 << 2), /* enable r/w to device reg */
183 ATA_TFLAG_WRITE = (1 << 3), /* data dir: host->dev==1 (write) */ 193 ATA_TFLAG_WRITE = (1 << 3), /* data dir: host->dev==1 (write) */
194 ATA_TFLAG_LBA = (1 << 4), /* enable LBA */
184}; 195};
185 196
186enum ata_tf_protocols { 197enum ata_tf_protocols {
@@ -250,7 +261,19 @@ struct ata_taskfile {
250 ((u64) (id)[(n) + 1] << 16) | \ 261 ((u64) (id)[(n) + 1] << 16) | \
251 ((u64) (id)[(n) + 0]) ) 262 ((u64) (id)[(n) + 0]) )
252 263
253static inline int atapi_cdb_len(u16 *dev_id) 264static inline int ata_id_current_chs_valid(const u16 *id)
265{
266 /* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command
267 has not been issued to the device then the values of
268 id[54] to id[56] are vendor specific. */
269 return (id[53] & 0x01) && /* Current translation valid */
270 id[54] && /* cylinders in current translation */
271 id[55] && /* heads in current translation */
272 id[55] <= 16 &&
273 id[56]; /* sectors in current translation */
274}
275
276static inline int atapi_cdb_len(const u16 *dev_id)
254{ 277{
255 u16 tmp = dev_id[0] & 0x3; 278 u16 tmp = dev_id[0] & 0x3;
256 switch (tmp) { 279 switch (tmp) {
@@ -260,7 +283,7 @@ static inline int atapi_cdb_len(u16 *dev_id)
260 } 283 }
261} 284}
262 285
263static inline int is_atapi_taskfile(struct ata_taskfile *tf) 286static inline int is_atapi_taskfile(const struct ata_taskfile *tf)
264{ 287{
265 return (tf->protocol == ATA_PROT_ATAPI) || 288 return (tf->protocol == ATA_PROT_ATAPI) ||
266 (tf->protocol == ATA_PROT_ATAPI_NODATA) || 289 (tf->protocol == ATA_PROT_ATAPI_NODATA) ||
diff --git a/include/linux/libata.h b/include/linux/libata.h
index ceee1fc42c60..00a8a5738858 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -91,12 +91,13 @@ enum {
91 ATA_SHT_EMULATED = 1, 91 ATA_SHT_EMULATED = 1,
92 ATA_SHT_CMD_PER_LUN = 1, 92 ATA_SHT_CMD_PER_LUN = 1,
93 ATA_SHT_THIS_ID = -1, 93 ATA_SHT_THIS_ID = -1,
94 ATA_SHT_USE_CLUSTERING = 0, 94 ATA_SHT_USE_CLUSTERING = 1,
95 95
96 /* struct ata_device stuff */ 96 /* struct ata_device stuff */
97 ATA_DFLAG_LBA48 = (1 << 0), /* device supports LBA48 */ 97 ATA_DFLAG_LBA48 = (1 << 0), /* device supports LBA48 */
98 ATA_DFLAG_PIO = (1 << 1), /* device currently in PIO mode */ 98 ATA_DFLAG_PIO = (1 << 1), /* device currently in PIO mode */
99 ATA_DFLAG_LOCK_SECTORS = (1 << 2), /* don't adjust max_sectors */ 99 ATA_DFLAG_LOCK_SECTORS = (1 << 2), /* don't adjust max_sectors */
100 ATA_DFLAG_LBA = (1 << 3), /* device supports LBA */
100 101
101 ATA_DEV_UNKNOWN = 0, /* unknown device */ 102 ATA_DEV_UNKNOWN = 0, /* unknown device */
102 ATA_DEV_ATA = 1, /* ATA device */ 103 ATA_DEV_ATA = 1, /* ATA device */
@@ -154,17 +155,21 @@ enum {
154 ATA_SHIFT_UDMA = 0, 155 ATA_SHIFT_UDMA = 0,
155 ATA_SHIFT_MWDMA = 8, 156 ATA_SHIFT_MWDMA = 8,
156 ATA_SHIFT_PIO = 11, 157 ATA_SHIFT_PIO = 11,
158
159 /* Masks for port functions */
160 ATA_PORT_PRIMARY = (1 << 0),
161 ATA_PORT_SECONDARY = (1 << 1),
157}; 162};
158 163
159enum pio_task_states { 164enum hsm_task_states {
160 PIO_ST_UNKNOWN, 165 HSM_ST_UNKNOWN,
161 PIO_ST_IDLE, 166 HSM_ST_IDLE,
162 PIO_ST_POLL, 167 HSM_ST_POLL,
163 PIO_ST_TMOUT, 168 HSM_ST_TMOUT,
164 PIO_ST, 169 HSM_ST,
165 PIO_ST_LAST, 170 HSM_ST_LAST,
166 PIO_ST_LAST_POLL, 171 HSM_ST_LAST_POLL,
167 PIO_ST_ERR, 172 HSM_ST_ERR,
168}; 173};
169 174
170/* forward declarations */ 175/* forward declarations */
@@ -197,7 +202,7 @@ struct ata_ioports {
197struct ata_probe_ent { 202struct ata_probe_ent {
198 struct list_head node; 203 struct list_head node;
199 struct device *dev; 204 struct device *dev;
200 struct ata_port_operations *port_ops; 205 const struct ata_port_operations *port_ops;
201 Scsi_Host_Template *sht; 206 Scsi_Host_Template *sht;
202 struct ata_ioports port[ATA_MAX_PORTS]; 207 struct ata_ioports port[ATA_MAX_PORTS];
203 unsigned int n_ports; 208 unsigned int n_ports;
@@ -220,7 +225,7 @@ struct ata_host_set {
220 void __iomem *mmio_base; 225 void __iomem *mmio_base;
221 unsigned int n_ports; 226 unsigned int n_ports;
222 void *private_data; 227 void *private_data;
223 struct ata_port_operations *ops; 228 const struct ata_port_operations *ops;
224 struct ata_port * ports[0]; 229 struct ata_port * ports[0];
225}; 230};
226 231
@@ -278,15 +283,18 @@ struct ata_device {
278 u8 xfer_mode; 283 u8 xfer_mode;
279 unsigned int xfer_shift; /* ATA_SHIFT_xxx */ 284 unsigned int xfer_shift; /* ATA_SHIFT_xxx */
280 285
281 /* cache info about current transfer mode */ 286 unsigned int multi_count; /* sectors count for
282 u8 xfer_protocol; /* taskfile xfer protocol */ 287 READ/WRITE MULTIPLE */
283 u8 read_cmd; /* opcode to use on read */ 288
284 u8 write_cmd; /* opcode to use on write */ 289 /* for CHS addressing */
290 u16 cylinders; /* Number of cylinders */
291 u16 heads; /* Number of heads */
292 u16 sectors; /* Number of sectors per track */
285}; 293};
286 294
287struct ata_port { 295struct ata_port {
288 struct Scsi_Host *host; /* our co-allocated scsi host */ 296 struct Scsi_Host *host; /* our co-allocated scsi host */
289 struct ata_port_operations *ops; 297 const struct ata_port_operations *ops;
290 unsigned long flags; /* ATA_FLAG_xxx */ 298 unsigned long flags; /* ATA_FLAG_xxx */
291 unsigned int id; /* unique id req'd by scsi midlyr */ 299 unsigned int id; /* unique id req'd by scsi midlyr */
292 unsigned int port_no; /* unique port #; from zero */ 300 unsigned int port_no; /* unique port #; from zero */
@@ -319,7 +327,7 @@ struct ata_port {
319 struct work_struct packet_task; 327 struct work_struct packet_task;
320 328
321 struct work_struct pio_task; 329 struct work_struct pio_task;
322 unsigned int pio_task_state; 330 unsigned int hsm_task_state;
323 unsigned long pio_task_timeout; 331 unsigned long pio_task_timeout;
324 332
325 void *private_data; 333 void *private_data;
@@ -333,10 +341,10 @@ struct ata_port_operations {
333 void (*set_piomode) (struct ata_port *, struct ata_device *); 341 void (*set_piomode) (struct ata_port *, struct ata_device *);
334 void (*set_dmamode) (struct ata_port *, struct ata_device *); 342 void (*set_dmamode) (struct ata_port *, struct ata_device *);
335 343
336 void (*tf_load) (struct ata_port *ap, struct ata_taskfile *tf); 344 void (*tf_load) (struct ata_port *ap, const struct ata_taskfile *tf);
337 void (*tf_read) (struct ata_port *ap, struct ata_taskfile *tf); 345 void (*tf_read) (struct ata_port *ap, struct ata_taskfile *tf);
338 346
339 void (*exec_command)(struct ata_port *ap, struct ata_taskfile *tf); 347 void (*exec_command)(struct ata_port *ap, const struct ata_taskfile *tf);
340 u8 (*check_status)(struct ata_port *ap); 348 u8 (*check_status)(struct ata_port *ap);
341 u8 (*check_altstatus)(struct ata_port *ap); 349 u8 (*check_altstatus)(struct ata_port *ap);
342 u8 (*check_err)(struct ata_port *ap); 350 u8 (*check_err)(struct ata_port *ap);
@@ -377,9 +385,22 @@ struct ata_port_info {
377 unsigned long pio_mask; 385 unsigned long pio_mask;
378 unsigned long mwdma_mask; 386 unsigned long mwdma_mask;
379 unsigned long udma_mask; 387 unsigned long udma_mask;
380 struct ata_port_operations *port_ops; 388 const struct ata_port_operations *port_ops;
389};
390
391struct ata_timing {
392 unsigned short mode; /* ATA mode */
393 unsigned short setup; /* t1 */
394 unsigned short act8b; /* t2 for 8-bit I/O */
395 unsigned short rec8b; /* t2i for 8-bit I/O */
396 unsigned short cyc8b; /* t0 for 8-bit I/O */
397 unsigned short active; /* t2 or tD */
398 unsigned short recover; /* t2i or tK */
399 unsigned short cycle; /* t0 */
400 unsigned short udma; /* t2CYCTYP/2 */
381}; 401};
382 402
403#define FIT(v,vmin,vmax) max_t(short,min_t(short,v,vmax),vmin)
383 404
384extern void ata_port_probe(struct ata_port *); 405extern void ata_port_probe(struct ata_port *);
385extern void __sata_phy_reset(struct ata_port *ap); 406extern void __sata_phy_reset(struct ata_port *ap);
@@ -392,7 +413,7 @@ extern int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_i
392 unsigned int n_ports); 413 unsigned int n_ports);
393extern void ata_pci_remove_one (struct pci_dev *pdev); 414extern void ata_pci_remove_one (struct pci_dev *pdev);
394#endif /* CONFIG_PCI */ 415#endif /* CONFIG_PCI */
395extern int ata_device_add(struct ata_probe_ent *ent); 416extern int ata_device_add(const struct ata_probe_ent *ent);
396extern void ata_host_set_remove(struct ata_host_set *host_set); 417extern void ata_host_set_remove(struct ata_host_set *host_set);
397extern int ata_scsi_detect(Scsi_Host_Template *sht); 418extern int ata_scsi_detect(Scsi_Host_Template *sht);
398extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg); 419extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
@@ -400,19 +421,21 @@ extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmn
400extern int ata_scsi_error(struct Scsi_Host *host); 421extern int ata_scsi_error(struct Scsi_Host *host);
401extern int ata_scsi_release(struct Scsi_Host *host); 422extern int ata_scsi_release(struct Scsi_Host *host);
402extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc); 423extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc);
424extern int ata_ratelimit(void);
425
403/* 426/*
404 * Default driver ops implementations 427 * Default driver ops implementations
405 */ 428 */
406extern void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf); 429extern void ata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf);
407extern void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf); 430extern void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
408extern void ata_tf_to_fis(struct ata_taskfile *tf, u8 *fis, u8 pmp); 431extern void ata_tf_to_fis(const struct ata_taskfile *tf, u8 *fis, u8 pmp);
409extern void ata_tf_from_fis(u8 *fis, struct ata_taskfile *tf); 432extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf);
410extern void ata_noop_dev_select (struct ata_port *ap, unsigned int device); 433extern void ata_noop_dev_select (struct ata_port *ap, unsigned int device);
411extern void ata_std_dev_select (struct ata_port *ap, unsigned int device); 434extern void ata_std_dev_select (struct ata_port *ap, unsigned int device);
412extern u8 ata_check_status(struct ata_port *ap); 435extern u8 ata_check_status(struct ata_port *ap);
413extern u8 ata_altstatus(struct ata_port *ap); 436extern u8 ata_altstatus(struct ata_port *ap);
414extern u8 ata_chk_err(struct ata_port *ap); 437extern u8 ata_chk_err(struct ata_port *ap);
415extern void ata_exec_command(struct ata_port *ap, struct ata_taskfile *tf); 438extern void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf);
416extern int ata_port_start (struct ata_port *ap); 439extern int ata_port_start (struct ata_port *ap);
417extern void ata_port_stop (struct ata_port *ap); 440extern void ata_port_stop (struct ata_port *ap);
418extern void ata_host_stop (struct ata_host_set *host_set); 441extern void ata_host_stop (struct ata_host_set *host_set);
@@ -423,8 +446,8 @@ extern void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf,
423 unsigned int buflen); 446 unsigned int buflen);
424extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, 447extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
425 unsigned int n_elem); 448 unsigned int n_elem);
426extern unsigned int ata_dev_classify(struct ata_taskfile *tf); 449extern unsigned int ata_dev_classify(const struct ata_taskfile *tf);
427extern void ata_dev_id_string(u16 *id, unsigned char *s, 450extern void ata_dev_id_string(const u16 *id, unsigned char *s,
428 unsigned int ofs, unsigned int len); 451 unsigned int ofs, unsigned int len);
429extern void ata_dev_config(struct ata_port *ap, unsigned int i); 452extern void ata_dev_config(struct ata_port *ap, unsigned int i);
430extern void ata_bmdma_setup (struct ata_queued_cmd *qc); 453extern void ata_bmdma_setup (struct ata_queued_cmd *qc);
@@ -441,6 +464,32 @@ extern int ata_std_bios_param(struct scsi_device *sdev,
441 sector_t capacity, int geom[]); 464 sector_t capacity, int geom[]);
442extern int ata_scsi_slave_config(struct scsi_device *sdev); 465extern int ata_scsi_slave_config(struct scsi_device *sdev);
443 466
467/*
468 * Timing helpers
469 */
470extern int ata_timing_compute(struct ata_device *, unsigned short,
471 struct ata_timing *, int, int);
472extern void ata_timing_merge(const struct ata_timing *,
473 const struct ata_timing *, struct ata_timing *,
474 unsigned int);
475
476enum {
477 ATA_TIMING_SETUP = (1 << 0),
478 ATA_TIMING_ACT8B = (1 << 1),
479 ATA_TIMING_REC8B = (1 << 2),
480 ATA_TIMING_CYC8B = (1 << 3),
481 ATA_TIMING_8BIT = ATA_TIMING_ACT8B | ATA_TIMING_REC8B |
482 ATA_TIMING_CYC8B,
483 ATA_TIMING_ACTIVE = (1 << 4),
484 ATA_TIMING_RECOVER = (1 << 5),
485 ATA_TIMING_CYCLE = (1 << 6),
486 ATA_TIMING_UDMA = (1 << 7),
487 ATA_TIMING_ALL = ATA_TIMING_SETUP | ATA_TIMING_ACT8B |
488 ATA_TIMING_REC8B | ATA_TIMING_CYC8B |
489 ATA_TIMING_ACTIVE | ATA_TIMING_RECOVER |
490 ATA_TIMING_CYCLE | ATA_TIMING_UDMA,
491};
492
444 493
445#ifdef CONFIG_PCI 494#ifdef CONFIG_PCI
446struct pci_bits { 495struct pci_bits {
@@ -452,8 +501,8 @@ struct pci_bits {
452 501
453extern void ata_pci_host_stop (struct ata_host_set *host_set); 502extern void ata_pci_host_stop (struct ata_host_set *host_set);
454extern struct ata_probe_ent * 503extern struct ata_probe_ent *
455ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port); 504ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int portmask);
456extern int pci_test_config_bits(struct pci_dev *pdev, struct pci_bits *bits); 505extern int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits);
457 506
458#endif /* CONFIG_PCI */ 507#endif /* CONFIG_PCI */
459 508
@@ -463,7 +512,7 @@ static inline unsigned int ata_tag_valid(unsigned int tag)
463 return (tag < ATA_MAX_QUEUE) ? 1 : 0; 512 return (tag < ATA_MAX_QUEUE) ? 1 : 0;
464} 513}
465 514
466static inline unsigned int ata_dev_present(struct ata_device *dev) 515static inline unsigned int ata_dev_present(const struct ata_device *dev)
467{ 516{
468 return ((dev->class == ATA_DEV_ATA) || 517 return ((dev->class == ATA_DEV_ATA) ||
469 (dev->class == ATA_DEV_ATAPI)); 518 (dev->class == ATA_DEV_ATAPI));
@@ -662,7 +711,7 @@ static inline unsigned int sata_dev_present(struct ata_port *ap)
662 return ((scr_read(ap, SCR_STATUS) & 0xf) == 0x3) ? 1 : 0; 711 return ((scr_read(ap, SCR_STATUS) & 0xf) == 0x3) ? 1 : 0;
663} 712}
664 713
665static inline int ata_try_flush_cache(struct ata_device *dev) 714static inline int ata_try_flush_cache(const struct ata_device *dev)
666{ 715{
667 return ata_id_wcache_enabled(dev->id) || 716 return ata_id_wcache_enabled(dev->id) ||
668 ata_id_has_flush(dev->id) || 717 ata_id_has_flush(dev->id) ||