1195534Sscottl/*-
2195534Sscottl * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
3195534Sscottl * All rights reserved.
4195534Sscottl *
5195534Sscottl * Redistribution and use in source and binary forms, with or without
6195534Sscottl * modification, are permitted provided that the following conditions
7195534Sscottl * are met:
8195534Sscottl * 1. Redistributions of source code must retain the above copyright
9195534Sscottl *    notice, this list of conditions and the following disclaimer,
10195534Sscottl *    without modification, immediately at the beginning of the file.
11195534Sscottl * 2. Redistributions in binary form must reproduce the above copyright
12195534Sscottl *    notice, this list of conditions and the following disclaimer in the
13195534Sscottl *    documentation and/or other materials provided with the distribution.
14195534Sscottl *
15195534Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16195534Sscottl * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17195534Sscottl * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18195534Sscottl * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19195534Sscottl * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20195534Sscottl * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21195534Sscottl * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22195534Sscottl * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23195534Sscottl * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24195534Sscottl * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25195534Sscottl *
26195534Sscottl * $FreeBSD$
27195534Sscottl */
28195534Sscottl
29195534Sscottl#ifndef	CAM_ATA_ALL_H
30195534Sscottl#define CAM_ATA_ALL_H 1
31195534Sscottl
32195534Sscottl#include <sys/ata.h>
33195534Sscottl
34195534Sscottlstruct ccb_ataio;
35195534Sscottlstruct cam_periph;
36195534Sscottlunion  ccb;
37195534Sscottl
38249199Smarius#define	SID_DMA48	0x01 /* Abuse inq_flags bit to track enabled DMA48. */
39249199Smarius#define	SID_AEN		0x04 /* Abuse inq_flags bit to track enabled AEN. */
40249199Smarius#define	SID_DMA		0x10 /* Abuse inq_flags bit to track enabled DMA. */
41220886Smav
42195534Sscottlstruct ata_cmd {
43195534Sscottl	u_int8_t	flags;		/* ATA command flags */
44195534Sscottl#define		CAM_ATAIO_48BIT		0x01	/* Command has 48-bit format */
45195534Sscottl#define		CAM_ATAIO_FPDMA		0x02	/* FPDMA command */
46195534Sscottl#define		CAM_ATAIO_CONTROL	0x04	/* Control, not a command */
47195534Sscottl#define		CAM_ATAIO_NEEDRESULT	0x08	/* Request requires result. */
48200008Smav#define		CAM_ATAIO_DMA		0x10	/* DMA command */
49195534Sscottl
50195534Sscottl	u_int8_t	command;
51195534Sscottl	u_int8_t	features;
52195534Sscottl
53195534Sscottl	u_int8_t	lba_low;
54195534Sscottl	u_int8_t	lba_mid;
55195534Sscottl	u_int8_t	lba_high;
56195534Sscottl	u_int8_t	device;
57195534Sscottl
58195534Sscottl	u_int8_t	lba_low_exp;
59195534Sscottl	u_int8_t	lba_mid_exp;
60195534Sscottl	u_int8_t	lba_high_exp;
61195534Sscottl	u_int8_t	features_exp;
62195534Sscottl
63195534Sscottl	u_int8_t	sector_count;
64195534Sscottl	u_int8_t	sector_count_exp;
65195534Sscottl	u_int8_t	control;
66195534Sscottl};
67195534Sscottl
68195534Sscottlstruct ata_res {
69195534Sscottl	u_int8_t	flags;		/* ATA command flags */
70195534Sscottl#define		CAM_ATAIO_48BIT		0x01	/* Command has 48-bit format */
71195534Sscottl
72195534Sscottl	u_int8_t	status;
73195534Sscottl	u_int8_t	error;
74195534Sscottl
75195534Sscottl	u_int8_t	lba_low;
76195534Sscottl	u_int8_t	lba_mid;
77195534Sscottl	u_int8_t	lba_high;
78195534Sscottl	u_int8_t	device;
79195534Sscottl
80195534Sscottl	u_int8_t	lba_low_exp;
81195534Sscottl	u_int8_t	lba_mid_exp;
82195534Sscottl	u_int8_t	lba_high_exp;
83195534Sscottl
84195534Sscottl	u_int8_t	sector_count;
85195534Sscottl	u_int8_t	sector_count_exp;
86195534Sscottl};
87195534Sscottl
88235897Smavstruct sep_identify_data {
89235897Smav	uint8_t		length;		/* Enclosure descriptor length */
90235897Smav	uint8_t		subenc_id;	/* Sub-enclosure identifier */
91235897Smav	uint8_t		logical_id[8];	/* Enclosure logical identifier (WWN) */
92235897Smav	uint8_t		vendor_id[8];	/* Vendor identification string */
93235897Smav	uint8_t		product_id[16];	/* Product identification string */
94235897Smav	uint8_t		product_rev[4];	/* Product revision string */
95235897Smav	uint8_t		channel_id;	/* Channel identifier */
96235897Smav	uint8_t		firmware_rev[4];/* Firmware revision */
97235897Smav	uint8_t		interface_id[6];/* Interface spec ("S-E-S "/"SAF-TE")*/
98235897Smav	uint8_t		interface_rev[4];/* Interface spec revision */
99235897Smav	uint8_t		vend_spec[11];	/* Vendor specific information */
100235897Smav};
101235897Smav
102195534Sscottlint	ata_version(int ver);
103198849Smav
104198849Smavchar *	ata_op_string(struct ata_cmd *cmd);
105198849Smavchar *	ata_cmd_string(struct ata_cmd *cmd, char *cmd_string, size_t len);
106198849Smavchar *	ata_res_string(struct ata_res *res, char *res_string, size_t len);
107198849Smavint	ata_command_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
108198849Smavint	ata_status_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
109198849Smavint	ata_res_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
110198849Smav
111195534Sscottlvoid	ata_print_ident(struct ata_params *ident_data);
112257049Smavvoid	ata_print_ident_short(struct ata_params *ident_data);
113195534Sscottl
114198897Smavuint32_t	ata_logical_sector_size(struct ata_params *ident_data);
115198897Smavuint64_t	ata_physical_sector_size(struct ata_params *ident_data);
116198897Smavuint64_t	ata_logical_sector_offset(struct ata_params *ident_data);
117198897Smav
118196659Smavvoid	ata_28bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint8_t features,
119195534Sscottl    uint32_t lba, uint8_t sector_count);
120195534Sscottlvoid	ata_48bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint16_t features,
121195534Sscottl    uint64_t lba, uint16_t sector_count);
122195534Sscottlvoid	ata_ncq_cmd(struct ccb_ataio *ataio, uint8_t cmd,
123195534Sscottl    uint64_t lba, uint16_t sector_count);
124195534Sscottlvoid	ata_reset_cmd(struct ccb_ataio *ataio);
125195534Sscottlvoid	ata_pm_read_cmd(struct ccb_ataio *ataio, int reg, int port);
126198905Smavvoid	ata_pm_write_cmd(struct ccb_ataio *ataio, int reg, int port, uint32_t val);
127195534Sscottl
128195534Sscottlvoid	ata_bswap(int8_t *buf, int len);
129195534Sscottlvoid	ata_btrim(int8_t *buf, int len);
130195534Sscottlvoid	ata_bpack(int8_t *src, int8_t *dst, int len);
131195534Sscottl
132195534Sscottlint	ata_max_pmode(struct ata_params *ap);
133195534Sscottlint	ata_max_wmode(struct ata_params *ap);
134195534Sscottlint	ata_max_umode(struct ata_params *ap);
135199747Smavint	ata_max_mode(struct ata_params *ap, int maxmode);
136195534Sscottl
137199747Smavchar *	ata_mode2string(int mode);
138199821Smavint	ata_string2mode(char *str);
139199747Smavu_int	ata_mode2speed(int mode);
140199747Smavu_int	ata_revision2speed(int revision);
141199747Smavint	ata_speed2revision(u_int speed);
142199747Smav
143199178Smavint	ata_identify_match(caddr_t identbuffer, caddr_t table_entry);
144199178Smavint	ata_static_identify_match(caddr_t identbuffer, caddr_t table_entry);
145199178Smav
146235897Smavvoid	semb_print_ident(struct sep_identify_data *ident_data);
147257049Smavvoid	semb_print_ident_short(struct sep_identify_data *ident_data);
148235897Smav
149235897Smavvoid semb_receive_diagnostic_results(struct ccb_ataio *ataio,
150235897Smav	u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*),
151235897Smav	uint8_t tag_action, int pcv, uint8_t page_code,
152235897Smav	uint8_t *data_ptr, uint16_t allocation_length, uint32_t timeout);
153235897Smav
154235897Smavvoid semb_send_diagnostic(struct ccb_ataio *ataio,
155235897Smav	u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *),
156235897Smav	uint8_t tag_action, uint8_t *data_ptr, uint16_t param_list_length,
157235897Smav	uint32_t timeout);
158235897Smav
159235897Smavvoid semb_read_buffer(struct ccb_ataio *ataio,
160235897Smav	u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*),
161235897Smav	uint8_t tag_action, uint8_t page_code,
162235897Smav	uint8_t *data_ptr, uint16_t allocation_length, uint32_t timeout);
163235897Smav
164235897Smavvoid semb_write_buffer(struct ccb_ataio *ataio,
165235897Smav	u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *),
166235897Smav	uint8_t tag_action, uint8_t *data_ptr, uint16_t param_list_length,
167235897Smav	uint32_t timeout);
168235897Smav
169195534Sscottl#endif
170