xref: /freebsd/sys/cam/ata/ata_all.h (revision f3631e8d)
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 
3852c9ce25SScott Long struct ata_cmd {
3952c9ce25SScott Long 	u_int8_t	flags;		/* ATA command flags */
4052c9ce25SScott Long #define		CAM_ATAIO_48BIT		0x01	/* Command has 48-bit format */
4152c9ce25SScott Long #define		CAM_ATAIO_FPDMA		0x02	/* FPDMA command */
4252c9ce25SScott Long #define		CAM_ATAIO_CONTROL	0x04	/* Control, not a command */
4352c9ce25SScott Long #define		CAM_ATAIO_NEEDRESULT	0x08	/* Request requires result. */
44f3631e8dSAlexander Motin #define		CAM_ATAIO_DMA		0x10	/* DMA command */
4552c9ce25SScott Long 
4652c9ce25SScott Long 	u_int8_t	command;
4752c9ce25SScott Long 	u_int8_t	features;
4852c9ce25SScott Long 
4952c9ce25SScott Long 	u_int8_t	lba_low;
5052c9ce25SScott Long 	u_int8_t	lba_mid;
5152c9ce25SScott Long 	u_int8_t	lba_high;
5252c9ce25SScott Long 	u_int8_t	device;
5352c9ce25SScott Long 
5452c9ce25SScott Long 	u_int8_t	lba_low_exp;
5552c9ce25SScott Long 	u_int8_t	lba_mid_exp;
5652c9ce25SScott Long 	u_int8_t	lba_high_exp;
5752c9ce25SScott Long 	u_int8_t	features_exp;
5852c9ce25SScott Long 
5952c9ce25SScott Long 	u_int8_t	sector_count;
6052c9ce25SScott Long 	u_int8_t	sector_count_exp;
6152c9ce25SScott Long 	u_int8_t	control;
6252c9ce25SScott Long };
6352c9ce25SScott Long 
6452c9ce25SScott Long struct ata_res {
6552c9ce25SScott Long 	u_int8_t	flags;		/* ATA command flags */
6652c9ce25SScott Long #define		CAM_ATAIO_48BIT		0x01	/* Command has 48-bit format */
6752c9ce25SScott Long 
6852c9ce25SScott Long 	u_int8_t	status;
6952c9ce25SScott Long 	u_int8_t	error;
7052c9ce25SScott Long 
7152c9ce25SScott Long 	u_int8_t	lba_low;
7252c9ce25SScott Long 	u_int8_t	lba_mid;
7352c9ce25SScott Long 	u_int8_t	lba_high;
7452c9ce25SScott Long 	u_int8_t	device;
7552c9ce25SScott Long 
7652c9ce25SScott Long 	u_int8_t	lba_low_exp;
7752c9ce25SScott Long 	u_int8_t	lba_mid_exp;
7852c9ce25SScott Long 	u_int8_t	lba_high_exp;
7952c9ce25SScott Long 
8052c9ce25SScott Long 	u_int8_t	sector_count;
8152c9ce25SScott Long 	u_int8_t	sector_count_exp;
8252c9ce25SScott Long };
8352c9ce25SScott Long 
8452c9ce25SScott Long int	ata_version(int ver);
858691755dSAlexander Motin 
868691755dSAlexander Motin char *	ata_op_string(struct ata_cmd *cmd);
878691755dSAlexander Motin char *	ata_cmd_string(struct ata_cmd *cmd, char *cmd_string, size_t len);
888691755dSAlexander Motin char *	ata_res_string(struct ata_res *res, char *res_string, size_t len);
898691755dSAlexander Motin int	ata_command_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
908691755dSAlexander Motin int	ata_status_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
918691755dSAlexander Motin int	ata_res_sbuf(struct ccb_ataio *ataio, struct sbuf *sb);
928691755dSAlexander Motin 
9352c9ce25SScott Long void	ata_print_ident(struct ata_params *ident_data);
9452c9ce25SScott Long 
95c1bd46c2SAlexander Motin uint32_t	ata_logical_sector_size(struct ata_params *ident_data);
96c1bd46c2SAlexander Motin uint64_t	ata_physical_sector_size(struct ata_params *ident_data);
97c1bd46c2SAlexander Motin uint64_t	ata_logical_sector_offset(struct ata_params *ident_data);
98c1bd46c2SAlexander Motin 
997606b445SAlexander Motin void	ata_28bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint8_t features,
10052c9ce25SScott Long     uint32_t lba, uint8_t sector_count);
10152c9ce25SScott Long void	ata_48bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint16_t features,
10252c9ce25SScott Long     uint64_t lba, uint16_t sector_count);
10352c9ce25SScott Long void	ata_ncq_cmd(struct ccb_ataio *ataio, uint8_t cmd,
10452c9ce25SScott Long     uint64_t lba, uint16_t sector_count);
10552c9ce25SScott Long void	ata_reset_cmd(struct ccb_ataio *ataio);
10652c9ce25SScott Long void	ata_pm_read_cmd(struct ccb_ataio *ataio, int reg, int port);
1072a3510fdSAlexander Motin void	ata_pm_write_cmd(struct ccb_ataio *ataio, int reg, int port, uint32_t val);
10852c9ce25SScott Long 
10952c9ce25SScott Long void	ata_bswap(int8_t *buf, int len);
11052c9ce25SScott Long void	ata_btrim(int8_t *buf, int len);
11152c9ce25SScott Long void	ata_bpack(int8_t *src, int8_t *dst, int len);
11252c9ce25SScott Long 
11352c9ce25SScott Long int	ata_max_pmode(struct ata_params *ap);
11452c9ce25SScott Long int	ata_max_wmode(struct ata_params *ap);
11552c9ce25SScott Long int	ata_max_umode(struct ata_params *ap);
116c8039fc6SAlexander Motin int	ata_max_mode(struct ata_params *ap, int maxmode);
117c8039fc6SAlexander Motin 
118c8039fc6SAlexander Motin char *	ata_mode2string(int mode);
119b447e682SAlexander Motin int	ata_string2mode(char *str);
120c8039fc6SAlexander Motin u_int	ata_mode2speed(int mode);
121c8039fc6SAlexander Motin u_int	ata_revision2speed(int revision);
122c8039fc6SAlexander Motin int	ata_speed2revision(u_int speed);
12352c9ce25SScott Long 
12430a4094fSAlexander Motin int	ata_identify_match(caddr_t identbuffer, caddr_t table_entry);
12530a4094fSAlexander Motin int	ata_static_identify_match(caddr_t identbuffer, caddr_t table_entry);
12630a4094fSAlexander Motin 
12752c9ce25SScott Long #endif
128