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