xref: /freebsd/sys/cam/ata/ata_all.h (revision 66e576525d35c68fcb86f142ebaa5a448555c0c7)
1 /*-
2  * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer,
10  *    without modification, immediately at the beginning of the file.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (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$
27  */
28 
29 #ifndef	CAM_ATA_ALL_H
30 #define CAM_ATA_ALL_H 1
31 
32 #include <sys/ata.h>
33 
34 struct ccb_ataio;
35 struct cam_periph;
36 union  ccb;
37 
38 struct 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 #define		CAM_ATAIO_DMA		0x10	/* DMA command */
45 
46 	u_int8_t	command;
47 	u_int8_t	features;
48 
49 	u_int8_t	lba_low;
50 	u_int8_t	lba_mid;
51 	u_int8_t	lba_high;
52 	u_int8_t	device;
53 
54 	u_int8_t	lba_low_exp;
55 	u_int8_t	lba_mid_exp;
56 	u_int8_t	lba_high_exp;
57 	u_int8_t	features_exp;
58 
59 	u_int8_t	sector_count;
60 	u_int8_t	sector_count_exp;
61 	u_int8_t	control;
62 };
63 
64 struct ata_res {
65 	u_int8_t	flags;		/* ATA command flags */
66 #define		CAM_ATAIO_48BIT		0x01	/* Command has 48-bit format */
67 
68 	u_int8_t	status;
69 	u_int8_t	error;
70 
71 	u_int8_t	lba_low;
72 	u_int8_t	lba_mid;
73 	u_int8_t	lba_high;
74 	u_int8_t	device;
75 
76 	u_int8_t	lba_low_exp;
77 	u_int8_t	lba_mid_exp;
78 	u_int8_t	lba_high_exp;
79 
80 	u_int8_t	sector_count;
81 	u_int8_t	sector_count_exp;
82 };
83 
84 int	ata_version(int ver);
85 
86 char *	ata_op_string(struct ata_cmd *cmd);
87 char *	ata_cmd_string(struct ata_cmd *cmd, char *cmd_string, size_t len);
88 char *	ata_res_string(struct ata_res *res, char *res_string, size_t len);
89 int	ata_command_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
90 int	ata_status_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
91 int	ata_res_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
92 
93 void	ata_print_ident(struct ata_params *ident_data);
94 
95 uint32_t	ata_logical_sector_size(struct ata_params *ident_data);
96 uint64_t	ata_physical_sector_size(struct ata_params *ident_data);
97 uint64_t	ata_logical_sector_offset(struct ata_params *ident_data);
98 
99 void	ata_28bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint8_t features,
100     uint32_t lba, uint8_t sector_count);
101 void	ata_48bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint16_t features,
102     uint64_t lba, uint16_t sector_count);
103 void	ata_ncq_cmd(struct ccb_ataio *ataio, uint8_t cmd,
104     uint64_t lba, uint16_t sector_count);
105 void	ata_reset_cmd(struct ccb_ataio *ataio);
106 void	ata_pm_read_cmd(struct ccb_ataio *ataio, int reg, int port);
107 void	ata_pm_write_cmd(struct ccb_ataio *ataio, int reg, int port, uint32_t val);
108 
109 void	ata_bswap(int8_t *buf, int len);
110 void	ata_btrim(int8_t *buf, int len);
111 void	ata_bpack(int8_t *src, int8_t *dst, int len);
112 
113 int	ata_max_pmode(struct ata_params *ap);
114 int	ata_max_wmode(struct ata_params *ap);
115 int	ata_max_umode(struct ata_params *ap);
116 int	ata_max_mode(struct ata_params *ap, int maxmode);
117 
118 char *	ata_mode2string(int mode);
119 int	ata_string2mode(char *str);
120 u_int	ata_mode2speed(int mode);
121 u_int	ata_revision2speed(int revision);
122 int	ata_speed2revision(u_int speed);
123 
124 int	ata_identify_match(caddr_t identbuffer, caddr_t table_entry);
125 int	ata_static_identify_match(caddr_t identbuffer, caddr_t table_entry);
126 
127 #endif
128