]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/cam/ata/ata_all.h
OpenZFS: MFV 2.0-rc3-gfc5966
[FreeBSD/FreeBSD.git] / sys / cam / ata / ata_all.h
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer,
12  *    without modification, immediately at the beginning of the file.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30
31 #ifndef CAM_ATA_ALL_H
32 #define CAM_ATA_ALL_H 1
33
34 #include <sys/ata.h>
35
36 struct ccb_ataio;
37 struct cam_periph;
38 union  ccb;
39
40 #define SID_DMA48       0x01 /* Abuse inq_flags bit to track enabled DMA48. */
41 #define SID_AEN         0x04 /* Abuse inq_flags bit to track enabled AEN. */
42 #define SID_DMA         0x10 /* Abuse inq_flags bit to track enabled DMA. */
43
44 struct ata_cmd {
45         u_int8_t        flags;          /* ATA command flags */
46 #define         CAM_ATAIO_48BIT         0x01    /* Command has 48-bit format */
47 #define         CAM_ATAIO_FPDMA         0x02    /* FPDMA command */
48 #define         CAM_ATAIO_CONTROL       0x04    /* Control, not a command */
49 #define         CAM_ATAIO_NEEDRESULT    0x08    /* Request requires result. */
50 #define         CAM_ATAIO_DMA           0x10    /* DMA command */
51
52         u_int8_t        command;
53         u_int8_t        features;
54
55         u_int8_t        lba_low;
56         u_int8_t        lba_mid;
57         u_int8_t        lba_high;
58         u_int8_t        device;
59
60         u_int8_t        lba_low_exp;
61         u_int8_t        lba_mid_exp;
62         u_int8_t        lba_high_exp;
63         u_int8_t        features_exp;
64
65         u_int8_t        sector_count;
66         u_int8_t        sector_count_exp;
67         u_int8_t        control;
68 };
69
70 struct ata_res {
71         u_int8_t        flags;          /* ATA command flags */
72 #define         CAM_ATAIO_48BIT         0x01    /* Command has 48-bit format */
73
74         u_int8_t        status;
75         u_int8_t        error;
76
77         u_int8_t        lba_low;
78         u_int8_t        lba_mid;
79         u_int8_t        lba_high;
80         u_int8_t        device;
81
82         u_int8_t        lba_low_exp;
83         u_int8_t        lba_mid_exp;
84         u_int8_t        lba_high_exp;
85
86         u_int8_t        sector_count;
87         u_int8_t        sector_count_exp;
88 };
89
90 struct sep_identify_data {
91         uint8_t         length;         /* Enclosure descriptor length */
92         uint8_t         subenc_id;      /* Sub-enclosure identifier */
93         uint8_t         logical_id[8];  /* Enclosure logical identifier (WWN) */
94         uint8_t         vendor_id[8];   /* Vendor identification string */
95         uint8_t         product_id[16]; /* Product identification string */
96         uint8_t         product_rev[4]; /* Product revision string */
97         uint8_t         channel_id;     /* Channel identifier */
98         uint8_t         firmware_rev[4];/* Firmware revision */
99         uint8_t         interface_id[6];/* Interface spec ("S-E-S "/"SAF-TE")*/
100         uint8_t         interface_rev[4];/* Interface spec revision */
101         uint8_t         vend_spec[11];  /* Vendor specific information */
102 };
103
104 int     ata_version(int ver);
105
106 char *  ata_op_string(struct ata_cmd *cmd);
107 char *  ata_cmd_string(struct ata_cmd *cmd, char *cmd_string, size_t len);
108 void    ata_cmd_sbuf(struct ata_cmd *cmd, struct sbuf *sb);
109 char *  ata_res_string(struct ata_res *res, char *res_string, size_t len);
110 int     ata_command_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
111 int     ata_status_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
112 int     ata_res_sbuf(struct ata_res *res, struct sbuf *sb);
113
114 void    ata_print_ident(struct ata_params *ident_data);
115 void    ata_print_ident_sbuf(struct ata_params *ident_data, struct sbuf *sb);
116 void    ata_print_ident_short(struct ata_params *ident_data);
117 void    ata_print_ident_short_sbuf(struct ata_params *ident_data, struct sbuf *sb);
118
119 uint32_t        ata_logical_sector_size(struct ata_params *ident_data);
120 uint64_t        ata_physical_sector_size(struct ata_params *ident_data);
121 uint64_t        ata_logical_sector_offset(struct ata_params *ident_data);
122
123 void    ata_28bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint8_t features,
124     uint32_t lba, uint8_t sector_count);
125 void    ata_48bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint16_t features,
126     uint64_t lba, uint16_t sector_count);
127 void    ata_ncq_cmd(struct ccb_ataio *ataio, uint8_t cmd,
128     uint64_t lba, uint16_t sector_count);
129 void    ata_reset_cmd(struct ccb_ataio *ataio);
130 void    ata_pm_read_cmd(struct ccb_ataio *ataio, int reg, int port);
131 void    ata_pm_write_cmd(struct ccb_ataio *ataio, int reg, int port, uint32_t val);
132 void    ata_read_log(struct ccb_ataio *ataio, uint32_t retries,
133                      void (*cbfcnp)(struct cam_periph *, union ccb *),
134                      uint32_t log_address, uint32_t page_number,
135                      uint16_t block_count, uint32_t protocol,
136                      uint8_t *data_ptr, uint32_t dxfer_len, uint32_t timeout);
137
138 void    ata_param_fixup(struct ata_params *ident_buf);
139 void    ata_bswap(int8_t *buf, int len);
140 void    ata_btrim(int8_t *buf, int len);
141 void    ata_bpack(int8_t *src, int8_t *dst, int len);
142
143 int     ata_max_pmode(struct ata_params *ap);
144 int     ata_max_wmode(struct ata_params *ap);
145 int     ata_max_umode(struct ata_params *ap);
146 int     ata_max_mode(struct ata_params *ap, int maxmode);
147
148 char *  ata_mode2string(int mode);
149 int     ata_string2mode(char *str);
150 u_int   ata_mode2speed(int mode);
151 u_int   ata_revision2speed(int revision);
152 int     ata_speed2revision(u_int speed);
153
154 int     ata_identify_match(caddr_t identbuffer, caddr_t table_entry);
155 int     ata_static_identify_match(caddr_t identbuffer, caddr_t table_entry);
156
157 void    semb_print_ident(struct sep_identify_data *ident_data);
158 void    semb_print_ident_sbuf(struct sep_identify_data *ident_data, struct sbuf *sb);
159 void    semb_print_ident_short(struct sep_identify_data *ident_data);
160 void    semb_print_ident_short_sbuf(struct sep_identify_data *ident_data, struct sbuf *sb);
161
162 void semb_receive_diagnostic_results(struct ccb_ataio *ataio,
163         u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*),
164         uint8_t tag_action, int pcv, uint8_t page_code,
165         uint8_t *data_ptr, uint16_t allocation_length, uint32_t timeout);
166
167 void semb_send_diagnostic(struct ccb_ataio *ataio,
168         u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *),
169         uint8_t tag_action, uint8_t *data_ptr, uint16_t param_list_length,
170         uint32_t timeout);
171
172 void semb_read_buffer(struct ccb_ataio *ataio,
173         u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*),
174         uint8_t tag_action, uint8_t page_code,
175         uint8_t *data_ptr, uint16_t allocation_length, uint32_t timeout);
176
177 void semb_write_buffer(struct ccb_ataio *ataio,
178         u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *),
179         uint8_t tag_action, uint8_t *data_ptr, uint16_t param_list_length,
180         uint32_t timeout);
181
182 void ata_zac_mgmt_out(struct ccb_ataio *ataio, uint32_t retries, 
183         void (*cbfcnp)(struct cam_periph *, union ccb *),
184         int use_ncq __unused, uint8_t zm_action, uint64_t zone_id,
185         uint8_t zone_flags, uint16_t sector_count, uint8_t *data_ptr,
186         uint32_t dxfer_len, uint32_t timeout);
187
188 void ata_zac_mgmt_in(struct ccb_ataio *ataio, uint32_t retries, 
189         void (*cbfcnp)(struct cam_periph *, union ccb *),
190         int use_ncq __unused, uint8_t zm_action, uint64_t zone_id,
191         uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
192         uint32_t timeout);
193
194 #endif