17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 58faf39b2Staylor * Common Development and Distribution License (the "License"). 68faf39b2Staylor * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 224c06356bSdh142964 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_SCSI_SCSI_PKT_H 277c478bd9Sstevel@tonic-gate #define _SYS_SCSI_SCSI_PKT_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/scsi/scsi_types.h> 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifdef __cplusplus 327c478bd9Sstevel@tonic-gate extern "C" { 337c478bd9Sstevel@tonic-gate #endif 347c478bd9Sstevel@tonic-gate 358faf39b2Staylor #ifdef _KERNEL 367c478bd9Sstevel@tonic-gate /* 377c478bd9Sstevel@tonic-gate * SCSI packet definition. 387c478bd9Sstevel@tonic-gate * 397c478bd9Sstevel@tonic-gate * This structure defines the packet which is allocated by a library 407c478bd9Sstevel@tonic-gate * function and handed to a target driver. The target driver fills 417c478bd9Sstevel@tonic-gate * in some information, and passes it to the library for transport 427c478bd9Sstevel@tonic-gate * to an addressed SCSI device. The host adapter found by 437c478bd9Sstevel@tonic-gate * the library fills in some other information as the command is 447c478bd9Sstevel@tonic-gate * processed. When the command completes (or can be taken no further) 457c478bd9Sstevel@tonic-gate * the function specified in the packet is called with a pointer to 467c478bd9Sstevel@tonic-gate * the packet as it argument. From fields within the packet, the target 477c478bd9Sstevel@tonic-gate * driver can determine the success or failure of the command. 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate struct scsi_pkt { 507c478bd9Sstevel@tonic-gate opaque_t pkt_ha_private; /* private data for host adapter */ 517c478bd9Sstevel@tonic-gate struct scsi_address pkt_address; /* destination packet is for */ 527c478bd9Sstevel@tonic-gate opaque_t pkt_private; /* private data for target driver */ 537c478bd9Sstevel@tonic-gate void (*pkt_comp)(struct scsi_pkt *); /* completion routine */ 547c478bd9Sstevel@tonic-gate uint_t pkt_flags; /* flags */ 557c478bd9Sstevel@tonic-gate int pkt_time; /* time allotted to complete command */ 567c478bd9Sstevel@tonic-gate uchar_t *pkt_scbp; /* pointer to status block */ 577c478bd9Sstevel@tonic-gate uchar_t *pkt_cdbp; /* pointer to command block */ 587c478bd9Sstevel@tonic-gate ssize_t pkt_resid; /* data bytes not transferred */ 597c478bd9Sstevel@tonic-gate uint_t pkt_state; /* state of command */ 607c478bd9Sstevel@tonic-gate uint_t pkt_statistics; /* statistics */ 617c478bd9Sstevel@tonic-gate uchar_t pkt_reason; /* reason completion called */ 62602ca9eaScth 63602ca9eaScth /* 64602ca9eaScth * The DDI does not allow a driver to allocate it's own scsi_pkt(9S), 65602ca9eaScth * a driver should not have *any* compiled in dependencies on 66602ca9eaScth * "sizeof (struct scsi_pkt)". If the driver has such dependencies, it 67602ca9eaScth * limits SCSA's ability to evolve. The proper way for an HBA to 68602ca9eaScth * allocate a scsi_pkt is via scsi_hba_pkt_alloc(9F), or the newer 69602ca9eaScth * tran_setup_pkt(9E) interfaces. Allocation rules have been in place 70602ca9eaScth * for many years, unfortunately a significant number of drivers 71602ca9eaScth * are still broken. 72602ca9eaScth * 73602ca9eaScth * NB: Until we can trust drivers to follow DDI scsi_pkt(9S) allocation 74602ca9eaScth * rules, access to all fields below require special consideration. 75602ca9eaScth * Access to these fields is limited to code paths that 'know' correct 76602ca9eaScth * scsi_pkt allocation interfaces must have been used. This means that 77602ca9eaScth * any target driver access to these fields is suspect, since a target 78602ca9eaScth * knows nothing about how an HBA drivers performs scsi_pkt allocation. 79602ca9eaScth * 80602ca9eaScth * NB: A private scsi_pkt_size() interface has been added to simplify 81602ca9eaScth * 'fixing' legacy HBA drivers. Use of scsi_pkt_size() is only 82602ca9eaScth * appropriate when the effort/cost of fixing a legacy driver to use 83602ca9eaScth * proper DDI scsi_pkt allocation interfaces is too great given the 84602ca9eaScth * remaining driver life. New HBA drivers should *not* use 85602ca9eaScth * scsi_pkt_size(). 86602ca9eaScth * 87602ca9eaScth * NB: While HBA drivers with violations are being fixed, in 88602ca9eaScth * rare cases access conditioned by scsi_pkt_allocated_correctly() is 89602ca9eaScth * permitted. 90602ca9eaScth */ 91602ca9eaScth /* HBA driver only, iff scsi_hba_pkt_alloc(9F)|tran_seup_pkt(9E) used */ 92602ca9eaScth uint_t pkt_cdblen; /* length of pkt_cdbp */ 93602ca9eaScth uint_t pkt_tgtlen; /* length of pkt_private */ 94602ca9eaScth uint_t pkt_scblen; /* lenght of pkt_scbp */ 95602ca9eaScth 96602ca9eaScth /* HBA driver only, iff tran_seup_pkt(9E) used */ 97602ca9eaScth ddi_dma_handle_t pkt_handle; /* private */ 98602ca9eaScth uint_t pkt_numcookies; /* number of DMA cookies */ 99602ca9eaScth off_t pkt_dma_offset; /* private */ 100602ca9eaScth size_t pkt_dma_len; /* private */ 101602ca9eaScth uint_t pkt_dma_flags; /* DMA flags */ 102602ca9eaScth ddi_dma_cookie_t *pkt_cookies; /* array of DMA cookies */ 103602ca9eaScth 104602ca9eaScth /* private: iff scsi_pkt_allocated_correctly() */ 105602ca9eaScth int pkt_path_instance; /* pHCI transport path */ 106602ca9eaScth 1074c06356bSdh142964 /* stage-temporary: iff scsi_pkt_allocated_correctly() */ 1084c06356bSdh142964 void *pkt_stmp; /* temporary for current pkt stage */ 1094c06356bSdh142964 110602ca9eaScth #ifdef SCSI_SIZE_CLEAN_VERIFY 111602ca9eaScth /* 112602ca9eaScth * Must be last: Building a driver with-and-without 113602ca9eaScth * -DSCSI_SIZE_CLEAN_VERIFY, and checking driver modules for 114602ca9eaScth * differences with a tools like 'wsdiff' allows a developer to verify 115602ca9eaScth * that their driver has no dependencies on scsi*(9S) size. 116602ca9eaScth */ 117602ca9eaScth int i_pkt_pad[8]; 118602ca9eaScth #endif /* SCSI_SIZE_CLEAN_VERIFY */ 1197c478bd9Sstevel@tonic-gate }; 1208faf39b2Staylor #endif /* _KERNEL */ 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate /* 1237c478bd9Sstevel@tonic-gate * Definitions for the pkt_flags field. 1247c478bd9Sstevel@tonic-gate */ 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate /* 1277c478bd9Sstevel@tonic-gate * Following defines are generic. 1287c478bd9Sstevel@tonic-gate */ 1297c478bd9Sstevel@tonic-gate #define FLAG_STAG 0x4000 /* Run command with Simple attribute */ 1307c478bd9Sstevel@tonic-gate #define FLAG_OTAG 0x2000 /* Run command with Ordered attribute */ 1317c478bd9Sstevel@tonic-gate #define FLAG_HTAG 0x1000 /* Run command with Head of Queue attribute */ 1327c478bd9Sstevel@tonic-gate #define FLAG_TAGMASK (FLAG_HTAG|FLAG_OTAG|FLAG_STAG) 1337c478bd9Sstevel@tonic-gate 1348faf39b2Staylor #define FLAG_ACA 0x0100 /* internal; do not use */ 1357c478bd9Sstevel@tonic-gate #define FLAG_HEAD 0x8000 /* This cmd should be put at the head */ 1367c478bd9Sstevel@tonic-gate /* of the HBA driver's queue */ 1377c478bd9Sstevel@tonic-gate #define FLAG_SENSING 0x0400 /* Running request sense for failed pkt */ 1387c478bd9Sstevel@tonic-gate #define FLAG_NOINTR 0x0001 /* Run command with no cmd completion */ 1397c478bd9Sstevel@tonic-gate /* callback; command has been completed */ 1407c478bd9Sstevel@tonic-gate /* upon return from scsi_transport(9F) */ 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate /* 1437c478bd9Sstevel@tonic-gate * Following defines are appropriate for SCSI parallel bus. 1447c478bd9Sstevel@tonic-gate */ 1457c478bd9Sstevel@tonic-gate #define FLAG_NODISCON 0x0002 /* Run command without disconnects */ 1467c478bd9Sstevel@tonic-gate #define FLAG_NOPARITY 0x0008 /* Run command without parity checking */ 1477c478bd9Sstevel@tonic-gate #define FLAG_RENEGOTIATE_WIDE_SYNC \ 1487c478bd9Sstevel@tonic-gate 0x1000000 /* Do wide and sync renegotiation before */ 1497c478bd9Sstevel@tonic-gate /* transporting this command to target */ 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate /* 1527c478bd9Sstevel@tonic-gate * Following defines are internal i.e. not part of DDI. 1537c478bd9Sstevel@tonic-gate */ 1547c478bd9Sstevel@tonic-gate #define FLAG_IMMEDIATE_CB \ 1557c478bd9Sstevel@tonic-gate 0x0800 /* Immediate callback on command */ 1567c478bd9Sstevel@tonic-gate /* completion, ie. do not defer */ 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate /* 1597c478bd9Sstevel@tonic-gate * Following defines are for USCSI options. 1607c478bd9Sstevel@tonic-gate */ 1617c478bd9Sstevel@tonic-gate #define FLAG_SILENT 0x00010000 1627c478bd9Sstevel@tonic-gate #define FLAG_DIAGNOSE 0x00020000 1637c478bd9Sstevel@tonic-gate #define FLAG_ISOLATE 0x00040000 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate /* 166af483cc8Sjianfei wang - Sun Microsystems - Beijing China * pkg_flag for TLR 167af483cc8Sjianfei wang - Sun Microsystems - Beijing China */ 168af483cc8Sjianfei wang - Sun Microsystems - Beijing China #define FLAG_TLR 0x00080000 169af483cc8Sjianfei wang - Sun Microsystems - Beijing China 170af483cc8Sjianfei wang - Sun Microsystems - Beijing China 171af483cc8Sjianfei wang - Sun Microsystems - Beijing China /* 1727c478bd9Sstevel@tonic-gate * Following define is for scsi_vhci. 1731cb30f30Sgap * NOQUEUE If pHCI cannot transport the command to the device, 1741cb30f30Sgap * do not queue the pkt in pHCI. Return immediately with 1751cb30f30Sgap * TRAN_BUSY. 1761cb30f30Sgap * PATH_INSTANCE Select specific path (pkt_path_instance). 1771cb30f30Sgap * We need both a pkt_path_instance field and flag bit so 1781cb30f30Sgap * that a retry after a path failure, which sets 1791cb30f30Sgap * pkt_path_instance to failed path, does not select the 1801cb30f30Sgap * failed path. 1817c478bd9Sstevel@tonic-gate */ 1827c478bd9Sstevel@tonic-gate #define FLAG_NOQUEUE 0x80000000 1831cb30f30Sgap #define FLAG_PKT_PATH_INSTANCE 0x40000000 /* Tell vhci the path to use */ 184*1cba8b6cSRandall Ralphs #define FLAG_PKT_COMP_CALLED 0x20000000 /* Set once pkt_comp called */ 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate /* 1877c478bd9Sstevel@tonic-gate * Definitions for the pkt_reason field. 1887c478bd9Sstevel@tonic-gate */ 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate /* 1917c478bd9Sstevel@tonic-gate * Following defines are generic. 1927c478bd9Sstevel@tonic-gate */ 1937c478bd9Sstevel@tonic-gate #define CMD_CMPLT 0 /* no transport errors- normal completion */ 1947c478bd9Sstevel@tonic-gate #define CMD_INCOMPLETE 1 /* transport stopped with not normal state */ 1957c478bd9Sstevel@tonic-gate #define CMD_DMA_DERR 2 /* dma direction error occurred */ 1967c478bd9Sstevel@tonic-gate #define CMD_TRAN_ERR 3 /* unspecified transport error */ 1977c478bd9Sstevel@tonic-gate #define CMD_RESET 4 /* Target completed hard reset sequence */ 1987c478bd9Sstevel@tonic-gate #define CMD_ABORTED 5 /* Command transport aborted on request */ 1997c478bd9Sstevel@tonic-gate #define CMD_TIMEOUT 6 /* Command timed out */ 2007c478bd9Sstevel@tonic-gate #define CMD_DATA_OVR 7 /* Data Overrun */ 2017c478bd9Sstevel@tonic-gate #define CMD_CMD_OVR 8 /* Command Overrun */ 2027c478bd9Sstevel@tonic-gate #define CMD_STS_OVR 9 /* Status Overrun */ 2031e32c0dcScth #define CMD_TERMINATED 22 /* Command transport terminated on request */ 204af483cc8Sjianfei wang - Sun Microsystems - Beijing China #define CMD_TLR_OFF 23 /* don't support TLR */ 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate /* 2077c478bd9Sstevel@tonic-gate * Following defines are appropriate for SCSI parallel bus. 2087c478bd9Sstevel@tonic-gate */ 2097c478bd9Sstevel@tonic-gate #define CMD_BADMSG 10 /* Message not Command Complete */ 2107c478bd9Sstevel@tonic-gate #define CMD_NOMSGOUT 11 /* Target refused to go to Message Out phase */ 2117c478bd9Sstevel@tonic-gate #define CMD_XID_FAIL 12 /* Extended Identify message rejected */ 2127c478bd9Sstevel@tonic-gate #define CMD_IDE_FAIL 13 /* Initiator Detected Error message rejected */ 2137c478bd9Sstevel@tonic-gate #define CMD_ABORT_FAIL 14 /* Abort message rejected */ 2147c478bd9Sstevel@tonic-gate #define CMD_REJECT_FAIL 15 /* Reject message rejected */ 2157c478bd9Sstevel@tonic-gate #define CMD_NOP_FAIL 16 /* No Operation message rejected */ 2167c478bd9Sstevel@tonic-gate #define CMD_PER_FAIL 17 /* Message Parity Error message rejected */ 2177c478bd9Sstevel@tonic-gate #define CMD_BDR_FAIL 18 /* Bus Device Reset message rejected */ 2187c478bd9Sstevel@tonic-gate #define CMD_ID_FAIL 19 /* Identify message rejected */ 2197c478bd9Sstevel@tonic-gate #define CMD_UNX_BUS_FREE 20 /* Unexpected Bus Free Phase occurred */ 2207c478bd9Sstevel@tonic-gate #define CMD_TAG_REJECT 21 /* Target rejected our tag message */ 2217c478bd9Sstevel@tonic-gate #define CMD_DEV_GONE 24 /* The device has been removed */ 2227c478bd9Sstevel@tonic-gate 2231e32c0dcScth /* Used by scsi_rname(9F) */ 2241e32c0dcScth #define CMD_REASON_ASCII { \ 2251e32c0dcScth "cmplt", "incomplete", "dma_derr", "tran_err", "reset", \ 2261e32c0dcScth "aborted", "timeout", "data_ovr", "cmd_ovr", "sts_ovr", \ 2271e32c0dcScth "badmsg", "nomsgout", "xid_fail", "ide_fail", "abort_fail", \ 2281e32c0dcScth "reject_fail", "nop_fail", "per_fail", "bdr_fail", "id_fail", \ 2291e32c0dcScth "unexpected_bus_free", "tag reject", "terminated", "", "gone", \ 2301e32c0dcScth NULL } 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate /* 2337c478bd9Sstevel@tonic-gate * Definitions for the pkt_state field 2347c478bd9Sstevel@tonic-gate */ 2357c478bd9Sstevel@tonic-gate #define STATE_GOT_BUS 0x01 /* Success in getting SCSI bus */ 2367c478bd9Sstevel@tonic-gate #define STATE_GOT_TARGET 0x02 /* Successfully connected with target */ 2377c478bd9Sstevel@tonic-gate #define STATE_SENT_CMD 0x04 /* Command successfully sent */ 2387c478bd9Sstevel@tonic-gate #define STATE_XFERRED_DATA 0x08 /* Data transfer took place */ 2397c478bd9Sstevel@tonic-gate #define STATE_GOT_STATUS 0x10 /* SCSI status received */ 2407c478bd9Sstevel@tonic-gate #define STATE_ARQ_DONE 0x20 /* auto rqsense took place */ 24130ab6db6Slh195018 #define STATE_XARQ_DONE 0X40 /* extra auto rqsense took place */ 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate /* 2447c478bd9Sstevel@tonic-gate * Definitions for the pkt_statistics field 2457c478bd9Sstevel@tonic-gate */ 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate /* 2487c478bd9Sstevel@tonic-gate * Following defines are generic. 2497c478bd9Sstevel@tonic-gate */ 2507c478bd9Sstevel@tonic-gate #define STAT_BUS_RESET 0x8 /* Reset operation on interconnect */ 2517c478bd9Sstevel@tonic-gate #define STAT_DEV_RESET 0x10 /* Target completed hard reset sequence */ 2527c478bd9Sstevel@tonic-gate #define STAT_ABORTED 0x20 /* Command was aborted */ 2537c478bd9Sstevel@tonic-gate #define STAT_TERMINATED 0x80 /* Command was terminated */ 2547c478bd9Sstevel@tonic-gate #define STAT_TIMEOUT 0x40 /* Command experienced a timeout */ 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate /* 2577c478bd9Sstevel@tonic-gate * Following defines are appropriate for SCSI parallel bus. 2587c478bd9Sstevel@tonic-gate */ 2597c478bd9Sstevel@tonic-gate #define STAT_DISCON 0x1 /* Command experienced a disconnect */ 2607c478bd9Sstevel@tonic-gate #define STAT_SYNC 0x2 /* Command did a synchronous data transfer */ 2617c478bd9Sstevel@tonic-gate #define STAT_PERR 0x4 /* Command experienced a SCSI parity error */ 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate /* 2647c478bd9Sstevel@tonic-gate * Definitions for what scsi_transport returns 2657c478bd9Sstevel@tonic-gate */ 2667c478bd9Sstevel@tonic-gate #define TRAN_ACCEPT 1 2677c478bd9Sstevel@tonic-gate #define TRAN_BUSY 0 2687c478bd9Sstevel@tonic-gate #define TRAN_BADPKT -1 2697c478bd9Sstevel@tonic-gate #define TRAN_FATAL_ERROR -2 /* HBA cannot accept any pkts */ 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate #ifdef _KERNEL 2727c478bd9Sstevel@tonic-gate /* 2737c478bd9Sstevel@tonic-gate * Kernel function declarations 2747c478bd9Sstevel@tonic-gate */ 2751e32c0dcScth int scsi_transport(struct scsi_pkt *pkt); 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate #define pkt_transport scsi_transport 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate #define SCSI_POLL_TIMEOUT 60 2807c478bd9Sstevel@tonic-gate 2817c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2847c478bd9Sstevel@tonic-gate } 2857c478bd9Sstevel@tonic-gate #endif 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate #endif /* _SYS_SCSI_SCSI_PKT_H */ 288