xref: /freebsd/sys/cam/ata/ata_all.h (revision 3631c638)
152c9ce25SScott Long /*-
252c9ce25SScott Long  * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
352c9ce25SScott Long  * All rights reserved.
452c9ce25SScott Long  *
552c9ce25SScott Long  * Redistribution and use in source and binary forms, with or without
652c9ce25SScott Long  * modification, are permitted provided that the following conditions
752c9ce25SScott Long  * are met:
852c9ce25SScott Long  * 1. Redistributions of source code must retain the above copyright
952c9ce25SScott Long  *    notice, this list of conditions and the following disclaimer,
1052c9ce25SScott Long  *    without modification, immediately at the beginning of the file.
1152c9ce25SScott Long  * 2. Redistributions in binary form must reproduce the above copyright
1252c9ce25SScott Long  *    notice, this list of conditions and the following disclaimer in the
1352c9ce25SScott Long  *    documentation and/or other materials provided with the distribution.
1452c9ce25SScott Long  *
1552c9ce25SScott Long  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1652c9ce25SScott Long  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1752c9ce25SScott Long  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1852c9ce25SScott Long  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1952c9ce25SScott Long  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2052c9ce25SScott Long  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2152c9ce25SScott Long  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2252c9ce25SScott Long  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2352c9ce25SScott Long  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2452c9ce25SScott Long  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2552c9ce25SScott Long  *
2652c9ce25SScott Long  * $FreeBSD$
2752c9ce25SScott Long  */
2852c9ce25SScott Long 
2952c9ce25SScott Long #ifndef	CAM_ATA_ALL_H
3052c9ce25SScott Long #define CAM_ATA_ALL_H 1
3152c9ce25SScott Long 
3252c9ce25SScott Long #include <sys/ata.h>
3352c9ce25SScott Long 
3452c9ce25SScott Long struct ccb_ataio;
3552c9ce25SScott Long struct cam_periph;
3652c9ce25SScott Long union  ccb;
3752c9ce25SScott Long 
383631c638SAlexander Motin #define	SID_AEN		0x04	/* Abuse inq_flags bit to track enabled AEN. */
39cf2b9a5fSAlexander Motin #define	SID_DMA		0x10	/* Abuse inq_flags bit to track enabled DMA. */
40cf2b9a5fSAlexander Motin 
4152c9ce25SScott Long struct ata_cmd {
4252c9ce25SScott Long 	u_int8_t	flags;		/* ATA command flags */
4352c9ce25SScott Long #define		CAM_ATAIO_48BIT		0x01	/* Command has 48-bit format */
4452c9ce25SScott Long #define		CAM_ATAIO_FPDMA		0x02	/* FPDMA command */
4552c9ce25SScott Long #define		CAM_ATAIO_CONTROL	0x04	/* Control, not a command */
4652c9ce25SScott Long #define		CAM_ATAIO_NEEDRESULT	0x08	/* Request requires result. */
47f3631e8dSAlexander Motin #define		CAM_ATAIO_DMA		0x10	/* DMA command */
4852c9ce25SScott Long 
4952c9ce25SScott Long 	u_int8_t	command;
5052c9ce25SScott Long 	u_int8_t	features;
5152c9ce25SScott Long 
5252c9ce25SScott Long 	u_int8_t	lba_low;
5352c9ce25SScott Long 	u_int8_t	lba_mid;
5452c9ce25SScott Long 	u_int8_t	lba_high;
5552c9ce25SScott Long 	u_int8_t	device;
5652c9ce25SScott Long 
5752c9ce25SScott Long 	u_int8_t	lba_low_exp;
5852c9ce25SScott Long 	u_int8_t	lba_mid_exp;
5952c9ce25SScott Long 	u_int8_t	lba_high_exp;
6052c9ce25SScott Long 	u_int8_t	features_exp;
6152c9ce25SScott Long 
6252c9ce25SScott Long 	u_int8_t	sector_count;
6352c9ce25SScott Long 	u_int8_t	sector_count_exp;
6452c9ce25SScott Long 	u_int8_t	control;
6552c9ce25SScott Long };
6652c9ce25SScott Long 
6752c9ce25SScott Long struct ata_res {
6852c9ce25SScott Long 	u_int8_t	flags;		/* ATA command flags */
6952c9ce25SScott Long #define		CAM_ATAIO_48BIT		0x01	/* Command has 48-bit format */
7052c9ce25SScott Long 
7152c9ce25SScott Long 	u_int8_t	status;
7252c9ce25SScott Long 	u_int8_t	error;
7352c9ce25SScott Long 
7452c9ce25SScott Long 	u_int8_t	lba_low;
7552c9ce25SScott Long 	u_int8_t	lba_mid;
7652c9ce25SScott Long 	u_int8_t	lba_high;
7752c9ce25SScott Long 	u_int8_t	device;
7852c9ce25SScott Long 
7952c9ce25SScott Long 	u_int8_t	lba_low_exp;
8052c9ce25SScott Long 	u_int8_t	lba_mid_exp;
8152c9ce25SScott Long 	u_int8_t	lba_high_exp;
8252c9ce25SScott Long 
8352c9ce25SScott Long 	u_int8_t	sector_count;
8452c9ce25SScott Long 	u_int8_t	sector_count_exp;
8552c9ce25SScott Long };
8652c9ce25SScott Long 
873089bb2eSAlexander Motin struct sep_identify_data {
883089bb2eSAlexander Motin 	uint8_t		length;		/* Enclosure descriptor length */
893089bb2eSAlexander Motin 	uint8_t		subenc_id;	/* Sub-enclosure identifier */
903089bb2eSAlexander Motin 	uint8_t		logical_id[8];	/* Enclosure logical identifier (WWN) */
913089bb2eSAlexander Motin 	uint8_t		vendor_id[8];	/* Vendor identification string */
923089bb2eSAlexander Motin 	uint8_t		product_id[16];	/* Product identification string */
933089bb2eSAlexander Motin 	uint8_t		product_rev[4];	/* Product revision string */
943089bb2eSAlexander Motin 	uint8_t		channel_id;	/* Channel identifier */
953089bb2eSAlexander Motin 	uint8_t		firmware_rev[4];/* Firmware revision */
963089bb2eSAlexander Motin 	uint8_t		interface_id[6];/* Interface spec ("S-E-S "/"SAF-TE")*/
973089bb2eSAlexander Motin 	uint8_t		interface_rev[4];/* Interface spec revision */
983089bb2eSAlexander Motin 	uint8_t		vend_spec[11];	/* Vendor specific information */
993089bb2eSAlexander Motin };
1003089bb2eSAlexander Motin 
10152c9ce25SScott Long int	ata_version(int ver);
1028691755dSAlexander Motin 
1038691755dSAlexander Motin char *	ata_op_string(struct ata_cmd *cmd);
1048691755dSAlexander Motin char *	ata_cmd_string(struct ata_cmd *cmd, char *cmd_string, size_t len);
1058691755dSAlexander Motin char *	ata_res_string(struct ata_res *res, char *res_string, size_t len);
1068691755dSAlexander Motin int	ata_command_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
1078691755dSAlexander Motin int	ata_status_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
1088691755dSAlexander Motin int	ata_res_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
1098691755dSAlexander Motin 
11052c9ce25SScott Long void	ata_print_ident(struct ata_params *ident_data);
11152c9ce25SScott Long 
112c1bd46c2SAlexander Motin uint32_t	ata_logical_sector_size(struct ata_params *ident_data);
113c1bd46c2SAlexander Motin uint64_t	ata_physical_sector_size(struct ata_params *ident_data);
114c1bd46c2SAlexander Motin uint64_t	ata_logical_sector_offset(struct ata_params *ident_data);
115c1bd46c2SAlexander Motin 
1167606b445SAlexander Motin void	ata_28bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint8_t features,
11752c9ce25SScott Long     uint32_t lba, uint8_t sector_count);
11852c9ce25SScott Long void	ata_48bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint16_t features,
11952c9ce25SScott Long     uint64_t lba, uint16_t sector_count);
12052c9ce25SScott Long void	ata_ncq_cmd(struct ccb_ataio *ataio, uint8_t cmd,
12152c9ce25SScott Long     uint64_t lba, uint16_t sector_count);
12252c9ce25SScott Long void	ata_reset_cmd(struct ccb_ataio *ataio);
12352c9ce25SScott Long void	ata_pm_read_cmd(struct ccb_ataio *ataio, int reg, int port);
1242a3510fdSAlexander Motin void	ata_pm_write_cmd(struct ccb_ataio *ataio, int reg, int port, uint32_t val);
12552c9ce25SScott Long 
12652c9ce25SScott Long void	ata_bswap(int8_t *buf, int len);
12752c9ce25SScott Long void	ata_btrim(int8_t *buf, int len);
12852c9ce25SScott Long void	ata_bpack(int8_t *src, int8_t *dst, int len);
12952c9ce25SScott Long 
13052c9ce25SScott Long int	ata_max_pmode(struct ata_params *ap);
13152c9ce25SScott Long int	ata_max_wmode(struct ata_params *ap);
13252c9ce25SScott Long int	ata_max_umode(struct ata_params *ap);
133c8039fc6SAlexander Motin int	ata_max_mode(struct ata_params *ap, int maxmode);
134c8039fc6SAlexander Motin 
135c8039fc6SAlexander Motin char *	ata_mode2string(int mode);
136b447e682SAlexander Motin int	ata_string2mode(char *str);
137c8039fc6SAlexander Motin u_int	ata_mode2speed(int mode);
138c8039fc6SAlexander Motin u_int	ata_revision2speed(int revision);
139c8039fc6SAlexander Motin int	ata_speed2revision(u_int speed);
14052c9ce25SScott Long 
14130a4094fSAlexander Motin int	ata_identify_match(caddr_t identbuffer, caddr_t table_entry);
14230a4094fSAlexander Motin int	ata_static_identify_match(caddr_t identbuffer, caddr_t table_entry);
14330a4094fSAlexander Motin 
1443089bb2eSAlexander Motin void	semb_print_ident(struct sep_identify_data *ident_data);
1453089bb2eSAlexander Motin 
1463089bb2eSAlexander Motin void semb_receive_diagnostic_results(struct ccb_ataio *ataio,
1473089bb2eSAlexander Motin 	u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*),
1483089bb2eSAlexander Motin 	uint8_t tag_action, int pcv, uint8_t page_code,
1493089bb2eSAlexander Motin 	uint8_t *data_ptr, uint16_t allocation_length, uint32_t timeout);
1503089bb2eSAlexander Motin 
1513089bb2eSAlexander Motin void semb_send_diagnostic(struct ccb_ataio *ataio,
1523089bb2eSAlexander Motin 	u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *),
1533089bb2eSAlexander Motin 	uint8_t tag_action, uint8_t *data_ptr, uint16_t param_list_length,
1543089bb2eSAlexander Motin 	uint32_t timeout);
1553089bb2eSAlexander Motin 
1563089bb2eSAlexander Motin void semb_read_buffer(struct ccb_ataio *ataio,
1573089bb2eSAlexander Motin 	u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb*),
1583089bb2eSAlexander Motin 	uint8_t tag_action, uint8_t page_code,
1593089bb2eSAlexander Motin 	uint8_t *data_ptr, uint16_t allocation_length, uint32_t timeout);
1603089bb2eSAlexander Motin 
1613089bb2eSAlexander Motin void semb_write_buffer(struct ccb_ataio *ataio,
1623089bb2eSAlexander Motin 	u_int32_t retries, void (*cbfcnp)(struct cam_periph *, union ccb *),
1633089bb2eSAlexander Motin 	uint8_t tag_action, uint8_t *data_ptr, uint16_t param_list_length,
1643089bb2eSAlexander Motin 	uint32_t timeout);
1653089bb2eSAlexander Motin 
16652c9ce25SScott Long #endif
167