1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SYS_SCSI_SCSI_PKT_H 28 #define _SYS_SCSI_SCSI_PKT_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #include <sys/scsi/scsi_types.h> 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 /* 39 * SCSI packet definition. 40 * 41 * This structure defines the packet which is allocated by a library 42 * function and handed to a target driver. The target driver fills 43 * in some information, and passes it to the library for transport 44 * to an addressed SCSI device. The host adapter found by 45 * the library fills in some other information as the command is 46 * processed. When the command completes (or can be taken no further) 47 * the function specified in the packet is called with a pointer to 48 * the packet as it argument. From fields within the packet, the target 49 * driver can determine the success or failure of the command. 50 */ 51 52 struct scsi_pkt { 53 opaque_t pkt_ha_private; /* private data for host adapter */ 54 struct scsi_address pkt_address; /* destination packet is for */ 55 opaque_t pkt_private; /* private data for target driver */ 56 void (*pkt_comp)(struct scsi_pkt *); /* completion routine */ 57 uint_t pkt_flags; /* flags */ 58 int pkt_time; /* time allotted to complete command */ 59 uchar_t *pkt_scbp; /* pointer to status block */ 60 uchar_t *pkt_cdbp; /* pointer to command block */ 61 ssize_t pkt_resid; /* data bytes not transferred */ 62 uint_t pkt_state; /* state of command */ 63 uint_t pkt_statistics; /* statistics */ 64 uchar_t pkt_reason; /* reason completion called */ 65 }; 66 67 /* 68 * Definitions for the pkt_flags field. 69 */ 70 71 /* 72 * Following defines are generic. 73 */ 74 #define FLAG_STAG 0x4000 /* Run command with Simple attribute */ 75 #define FLAG_OTAG 0x2000 /* Run command with Ordered attribute */ 76 #define FLAG_HTAG 0x1000 /* Run command with Head of Queue attribute */ 77 #define FLAG_TAGMASK (FLAG_HTAG|FLAG_OTAG|FLAG_STAG) 78 79 #define FLAG_ACA 0x0100 /* Run command with ACA attribute */ 80 #define FLAG_HEAD 0x8000 /* This cmd should be put at the head */ 81 /* of the HBA driver's queue */ 82 #define FLAG_SENSING 0x0400 /* Running request sense for failed pkt */ 83 #define FLAG_NOINTR 0x0001 /* Run command with no cmd completion */ 84 /* callback; command has been completed */ 85 /* upon return from scsi_transport(9F) */ 86 87 /* 88 * Following defines are appropriate for SCSI parallel bus. 89 */ 90 #define FLAG_NODISCON 0x0002 /* Run command without disconnects */ 91 #define FLAG_NOPARITY 0x0008 /* Run command without parity checking */ 92 #define FLAG_RENEGOTIATE_WIDE_SYNC \ 93 0x1000000 /* Do wide and sync renegotiation before */ 94 /* transporting this command to target */ 95 96 /* 97 * Following defines are internal i.e. not part of DDI. 98 */ 99 #define FLAG_SUBLUN 0x0004 /* Use the sublun field in pkt_address */ 100 #define FLAG_QUEHOLD 0x0200 /* Don't advance HA que until cmd completes */ 101 #define FLAG_IMMEDIATE_CB \ 102 0x0800 /* Immediate callback on command */ 103 /* completion, ie. do not defer */ 104 105 106 107 /* 108 * Following defines are for USCSI options. 109 */ 110 #define FLAG_SILENT 0x00010000 111 #define FLAG_DIAGNOSE 0x00020000 112 #define FLAG_ISOLATE 0x00040000 113 114 /* 115 * Following define is for scsi_vhci. 116 * If pHCI cannot transport the command to the device, do not queue the pkt 117 * in pHCI. Return immediately with TRAN_BUSY. 118 */ 119 #define FLAG_NOQUEUE 0x80000000 120 121 122 /* 123 * Definitions for the pkt_reason field. 124 */ 125 126 /* 127 * Following defines are generic. 128 */ 129 #define CMD_CMPLT 0 /* no transport errors- normal completion */ 130 #define CMD_INCOMPLETE 1 /* transport stopped with not normal state */ 131 #define CMD_DMA_DERR 2 /* dma direction error occurred */ 132 #define CMD_TRAN_ERR 3 /* unspecified transport error */ 133 #define CMD_RESET 4 /* Target completed hard reset sequence */ 134 #define CMD_ABORTED 5 /* Command transport aborted on request */ 135 #define CMD_TERMINATED 22 /* Command transport terminated on request */ 136 #define CMD_TIMEOUT 6 /* Command timed out */ 137 #define CMD_DATA_OVR 7 /* Data Overrun */ 138 #define CMD_CMD_OVR 8 /* Command Overrun */ 139 #define CMD_STS_OVR 9 /* Status Overrun */ 140 141 /* 142 * Following defines are appropriate for SCSI parallel bus. 143 */ 144 #define CMD_BADMSG 10 /* Message not Command Complete */ 145 #define CMD_NOMSGOUT 11 /* Target refused to go to Message Out phase */ 146 #define CMD_XID_FAIL 12 /* Extended Identify message rejected */ 147 #define CMD_IDE_FAIL 13 /* Initiator Detected Error message rejected */ 148 #define CMD_ABORT_FAIL 14 /* Abort message rejected */ 149 #define CMD_REJECT_FAIL 15 /* Reject message rejected */ 150 #define CMD_NOP_FAIL 16 /* No Operation message rejected */ 151 #define CMD_PER_FAIL 17 /* Message Parity Error message rejected */ 152 #define CMD_BDR_FAIL 18 /* Bus Device Reset message rejected */ 153 #define CMD_ID_FAIL 19 /* Identify message rejected */ 154 #define CMD_UNX_BUS_FREE 20 /* Unexpected Bus Free Phase occurred */ 155 #define CMD_TAG_REJECT 21 /* Target rejected our tag message */ 156 #define CMD_DEV_GONE 24 /* The device has been removed */ 157 158 159 /* 160 * Definitions for the pkt_state field 161 */ 162 163 #define STATE_GOT_BUS 0x01 /* Success in getting SCSI bus */ 164 #define STATE_GOT_TARGET 0x02 /* Successfully connected with target */ 165 #define STATE_SENT_CMD 0x04 /* Command successfully sent */ 166 #define STATE_XFERRED_DATA 0x08 /* Data transfer took place */ 167 #define STATE_GOT_STATUS 0x10 /* SCSI status received */ 168 #define STATE_ARQ_DONE 0x20 /* auto rqsense took place */ 169 170 171 /* 172 * Definitions for the pkt_statistics field 173 */ 174 175 /* 176 * Following defines are generic. 177 */ 178 #define STAT_BUS_RESET 0x8 /* Reset operation on interconnect */ 179 #define STAT_DEV_RESET 0x10 /* Target completed hard reset sequence */ 180 #define STAT_ABORTED 0x20 /* Command was aborted */ 181 #define STAT_TERMINATED 0x80 /* Command was terminated */ 182 #define STAT_TIMEOUT 0x40 /* Command experienced a timeout */ 183 184 /* 185 * Following defines are appropriate for SCSI parallel bus. 186 */ 187 #define STAT_DISCON 0x1 /* Command experienced a disconnect */ 188 #define STAT_SYNC 0x2 /* Command did a synchronous data transfer */ 189 #define STAT_PERR 0x4 /* Command experienced a SCSI parity error */ 190 191 192 /* 193 * Definitions for what scsi_transport returns 194 */ 195 196 #define TRAN_ACCEPT 1 197 #define TRAN_BUSY 0 198 #define TRAN_BADPKT -1 199 #define TRAN_FATAL_ERROR -2 /* HBA cannot accept any pkts */ 200 201 #ifdef _KERNEL 202 /* 203 * Kernel function declarations 204 */ 205 206 #define pkt_transport scsi_transport 207 208 #ifdef __STDC__ 209 extern int scsi_transport(struct scsi_pkt *pkt); 210 #else /* __STDC__ */ 211 extern int scsi_transport(); 212 #endif /* __STDC__ */ 213 214 #define SCSI_POLL_TIMEOUT 60 215 216 #endif /* _KERNEL */ 217 218 #ifdef __cplusplus 219 } 220 #endif 221 222 #endif /* _SYS_SCSI_SCSI_PKT_H */ 223