ata_all.h revision 199178
1292740Snp/*-
2292740Snp * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
3319182Sngie * All rights reserved.
4292740Snp *
5292740Snp * Redistribution and use in source and binary forms, with or without
6292740Snp * modification, are permitted provided that the following conditions
7292740Snp * are met:
8292740Snp * 1. Redistributions of source code must retain the above copyright
9292740Snp *    notice, this list of conditions and the following disclaimer,
10292740Snp *    without modification, immediately at the beginning of the file.
11292740Snp * 2. Redistributions in binary form must reproduce the above copyright
12292740Snp *    notice, this list of conditions and the following disclaimer in the
13292740Snp *    documentation and/or other materials provided with the distribution.
14292740Snp *
15292740Snp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16292740Snp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17292740Snp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18292740Snp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19292740Snp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20292740Snp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21292740Snp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22292740Snp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23292740Snp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/cam/ata/ata_all.h 199178 2009-11-11 11:10:36Z mav $
27 */
28
29#ifndef	CAM_ATA_ALL_H
30#define CAM_ATA_ALL_H 1
31
32#include <sys/ata.h>
33
34struct ccb_ataio;
35struct cam_periph;
36union  ccb;
37
38struct ata_cmd {
39	u_int8_t	flags;		/* ATA command flags */
40#define		CAM_ATAIO_48BIT		0x01	/* Command has 48-bit format */
41#define		CAM_ATAIO_FPDMA		0x02	/* FPDMA command */
42#define		CAM_ATAIO_CONTROL	0x04	/* Control, not a command */
43#define		CAM_ATAIO_NEEDRESULT	0x08	/* Request requires result. */
44
45	u_int8_t	command;
46	u_int8_t	features;
47
48	u_int8_t	lba_low;
49	u_int8_t	lba_mid;
50	u_int8_t	lba_high;
51	u_int8_t	device;
52
53	u_int8_t	lba_low_exp;
54	u_int8_t	lba_mid_exp;
55	u_int8_t	lba_high_exp;
56	u_int8_t	features_exp;
57
58	u_int8_t	sector_count;
59	u_int8_t	sector_count_exp;
60	u_int8_t	control;
61};
62
63struct ata_res {
64	u_int8_t	flags;		/* ATA command flags */
65#define		CAM_ATAIO_48BIT		0x01	/* Command has 48-bit format */
66
67	u_int8_t	status;
68	u_int8_t	error;
69
70	u_int8_t	lba_low;
71	u_int8_t	lba_mid;
72	u_int8_t	lba_high;
73	u_int8_t	device;
74
75	u_int8_t	lba_low_exp;
76	u_int8_t	lba_mid_exp;
77	u_int8_t	lba_high_exp;
78
79	u_int8_t	sector_count;
80	u_int8_t	sector_count_exp;
81};
82
83int	ata_version(int ver);
84
85char *	ata_op_string(struct ata_cmd *cmd);
86char *	ata_cmd_string(struct ata_cmd *cmd, char *cmd_string, size_t len);
87char *	ata_res_string(struct ata_res *res, char *res_string, size_t len);
88int	ata_command_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
89int	ata_status_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
90int	ata_res_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
91
92void	ata_print_ident(struct ata_params *ident_data);
93
94uint32_t	ata_logical_sector_size(struct ata_params *ident_data);
95uint64_t	ata_physical_sector_size(struct ata_params *ident_data);
96uint64_t	ata_logical_sector_offset(struct ata_params *ident_data);
97
98void	ata_28bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint8_t features,
99    uint32_t lba, uint8_t sector_count);
100void	ata_48bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint16_t features,
101    uint64_t lba, uint16_t sector_count);
102void	ata_ncq_cmd(struct ccb_ataio *ataio, uint8_t cmd,
103    uint64_t lba, uint16_t sector_count);
104void	ata_reset_cmd(struct ccb_ataio *ataio);
105void	ata_pm_read_cmd(struct ccb_ataio *ataio, int reg, int port);
106void	ata_pm_write_cmd(struct ccb_ataio *ataio, int reg, int port, uint32_t val);
107
108void	ata_bswap(int8_t *buf, int len);
109void	ata_btrim(int8_t *buf, int len);
110void	ata_bpack(int8_t *src, int8_t *dst, int len);
111
112int	ata_max_pmode(struct ata_params *ap);
113int	ata_max_wmode(struct ata_params *ap);
114int	ata_max_umode(struct ata_params *ap);
115int	ata_max_mode(struct ata_params *ap, int mode, int maxmode);
116
117int	ata_identify_match(caddr_t identbuffer, caddr_t table_entry);
118int	ata_static_identify_match(caddr_t identbuffer, caddr_t table_entry);
119
120#endif
121