master
  1/*-
  2 * SPDX-License-Identifier: BSD-2-Clause
  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
 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
 38#define	SID_DMA48	0x01 /* Abuse inq_flags bit to track enabled DMA48. */
 39#define	SID_AEN		0x04 /* Abuse inq_flags bit to track enabled AEN. */
 40#define	SID_DMA		0x10 /* Abuse inq_flags bit to track enabled DMA. */
 41
 42struct ata_cmd {
 43	uint8_t	flags;		/* ATA command flags */
 44#define		CAM_ATAIO_48BIT		0x01	/* Command has 48-bit format */
 45#define		CAM_ATAIO_FPDMA		0x02	/* FPDMA command */
 46#define		CAM_ATAIO_CONTROL	0x04	/* Control, not a command */
 47#define		CAM_ATAIO_NEEDRESULT	0x08	/* Request requires result. */
 48#define		CAM_ATAIO_DMA		0x10	/* DMA command */
 49
 50	uint8_t	command;
 51	uint8_t	features;
 52
 53	uint8_t	lba_low;
 54	uint8_t	lba_mid;
 55	uint8_t	lba_high;
 56	uint8_t	device;
 57
 58	uint8_t	lba_low_exp;
 59	uint8_t	lba_mid_exp;
 60	uint8_t	lba_high_exp;
 61	uint8_t	features_exp;
 62
 63	uint8_t	sector_count;
 64	uint8_t	sector_count_exp;
 65	uint8_t	control;
 66};
 67
 68struct ata_res {
 69	uint8_t	flags;		/* ATA command flags */
 70#define		CAM_ATAIO_48BIT		0x01	/* Command has 48-bit format */
 71
 72	uint8_t	status;
 73	uint8_t	error;
 74
 75	uint8_t	lba_low;
 76	uint8_t	lba_mid;
 77	uint8_t	lba_high;
 78	uint8_t	device;
 79
 80	uint8_t	lba_low_exp;
 81	uint8_t	lba_mid_exp;
 82	uint8_t	lba_high_exp;
 83
 84	uint8_t	sector_count;
 85	uint8_t	sector_count_exp;
 86};
 87
 88struct sep_identify_data {
 89	uint8_t		length;		/* Enclosure descriptor length */
 90	uint8_t		subenc_id;	/* Sub-enclosure identifier */
 91	uint8_t		logical_id[8];	/* Enclosure logical identifier (WWN) */
 92	uint8_t		vendor_id[8];	/* Vendor identification string */
 93	uint8_t		product_id[16];	/* Product identification string */
 94	uint8_t		product_rev[4];	/* Product revision string */
 95	uint8_t		channel_id;	/* Channel identifier */
 96	uint8_t		firmware_rev[4];/* Firmware revision */
 97	uint8_t		interface_id[6];/* Interface spec ("S-E-S "/"SAF-TE")*/
 98	uint8_t		interface_rev[4];/* Interface spec revision */
 99	uint8_t		vend_spec[11];	/* Vendor specific information */
100};
101
102int	ata_version(int ver);
103
104char *	ata_op_string(struct ata_cmd *cmd);
105char *	ata_cmd_string(struct ata_cmd *cmd, char *cmd_string, size_t len);
106void	ata_cmd_sbuf(struct ata_cmd *cmd, struct sbuf *sb);
107char *	ata_res_string(struct ata_res *res, char *res_string, size_t len);
108int	ata_command_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
109int	ata_status_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
110int	ata_res_sbuf(struct ata_res *res, struct sbuf *sb);
111
112void	ata_print_ident(struct ata_params *ident_data);
113void	ata_print_ident_sbuf(struct ata_params *ident_data, struct sbuf *sb);
114void	ata_print_ident_short(struct ata_params *ident_data);
115void	ata_print_ident_short_sbuf(struct ata_params *ident_data, struct sbuf *sb);
116
117uint32_t	ata_logical_sector_size(struct ata_params *ident_data);
118uint64_t	ata_physical_sector_size(struct ata_params *ident_data);
119uint64_t	ata_logical_sector_offset(struct ata_params *ident_data);
120
121void	ata_28bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint8_t features,
122    uint32_t lba, uint8_t sector_count);
123void	ata_48bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint16_t features,
124    uint64_t lba, uint16_t sector_count);
125void	ata_ncq_cmd(struct ccb_ataio *ataio, uint8_t cmd,
126    uint64_t lba, uint16_t sector_count);
127void	ata_reset_cmd(struct ccb_ataio *ataio);
128void	ata_pm_read_cmd(struct ccb_ataio *ataio, int reg, int port);
129void	ata_pm_write_cmd(struct ccb_ataio *ataio, int reg, int port, uint32_t val);
130void	ata_read_log(struct ccb_ataio *ataio, uint32_t retries,
131		     void (*cbfcnp)(struct cam_periph *, union ccb *),
132		     uint32_t log_address, uint32_t page_number,
133		     uint16_t block_count, uint32_t protocol,
134		     uint8_t *data_ptr, uint32_t dxfer_len, uint32_t timeout);
135
136void	ata_param_fixup(struct ata_params *ident_buf);
137void	ata_bswap(int8_t *buf, int len);
138void	ata_btrim(int8_t *buf, int len);
139void	ata_bpack(int8_t *src, int8_t *dst, int len);
140
141int	ata_max_pmode(struct ata_params *ap);
142int	ata_max_wmode(struct ata_params *ap);
143int	ata_max_umode(struct ata_params *ap);
144int	ata_max_mode(struct ata_params *ap, int maxmode);
145
146char *	ata_mode2string(int mode);
147int	ata_string2mode(char *str);
148u_int	ata_mode2speed(int mode);
149u_int	ata_revision2speed(int revision);
150int	ata_speed2revision(u_int speed);
151
152int	ata_identify_match(caddr_t identbuffer, caddr_t table_entry);
153int	ata_static_identify_match(caddr_t identbuffer, caddr_t table_entry);
154
155void	semb_print_ident(struct sep_identify_data *ident_data);
156void	semb_print_ident_sbuf(struct sep_identify_data *ident_data, struct sbuf *sb);
157void	semb_print_ident_short(struct sep_identify_data *ident_data);
158void	semb_print_ident_short_sbuf(struct sep_identify_data *ident_data, struct sbuf *sb);
159
160void semb_receive_diagnostic_results(struct ccb_ataio *ataio,
161	uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*),
162	uint8_t tag_action, int pcv, uint8_t page_code,
163	uint8_t *data_ptr, uint16_t allocation_length, uint32_t timeout);
164
165void semb_send_diagnostic(struct ccb_ataio *ataio,
166	uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *),
167	uint8_t tag_action, uint8_t *data_ptr, uint16_t param_list_length,
168	uint32_t timeout);
169
170void semb_read_buffer(struct ccb_ataio *ataio,
171	uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*),
172	uint8_t tag_action, uint8_t page_code,
173	uint8_t *data_ptr, uint16_t allocation_length, uint32_t timeout);
174
175void semb_write_buffer(struct ccb_ataio *ataio,
176	uint32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *),
177	uint8_t tag_action, uint8_t *data_ptr, uint16_t param_list_length,
178	uint32_t timeout);
179
180void ata_zac_mgmt_out(struct ccb_ataio *ataio, uint32_t retries, 
181	void (*cbfcnp)(struct cam_periph *, union ccb *),
182	int use_ncq __unused, uint8_t zm_action, uint64_t zone_id,
183	uint8_t zone_flags, uint16_t sector_count, uint8_t *data_ptr,
184	uint32_t dxfer_len, uint32_t timeout);
185
186void ata_zac_mgmt_in(struct ccb_ataio *ataio, uint32_t retries, 
187	void (*cbfcnp)(struct cam_periph *, union ccb *),
188	int use_ncq __unused, uint8_t zm_action, uint64_t zone_id,
189	uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
190	uint32_t timeout);
191
192#endif