162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Largely written by Julian Elischer (julian@tfs.com)
362306a36Sopenharmony_ci * for TRW Financial Systems.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * TRW Financial Systems, in accordance with their agreement with Carnegie
662306a36Sopenharmony_ci * Mellon University, makes this software available to CMU to distribute
762306a36Sopenharmony_ci * or use in any manner that they see fit as long as this message is kept with
862306a36Sopenharmony_ci * the software. For this reason TFS also grants any other persons or
962306a36Sopenharmony_ci * organisations permission to use or modify this software.
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci * TFS supplies this software to be publicly redistributed
1262306a36Sopenharmony_ci * on the understanding that TFS is not responsible for the correct
1362306a36Sopenharmony_ci * functioning of this software in any circumstances.
1462306a36Sopenharmony_ci *
1562306a36Sopenharmony_ci * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
1662306a36Sopenharmony_ci *
1762306a36Sopenharmony_ci * $FreeBSD: src/sys/cam/scsi/scsi_all.h,v 1.21 2002/10/08 17:12:44 ken Exp $
1862306a36Sopenharmony_ci *
1962306a36Sopenharmony_ci * Copyright (c) 2003 Adaptec Inc.
2062306a36Sopenharmony_ci * All rights reserved.
2162306a36Sopenharmony_ci *
2262306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
2362306a36Sopenharmony_ci * modification, are permitted provided that the following conditions
2462306a36Sopenharmony_ci * are met:
2562306a36Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
2662306a36Sopenharmony_ci *    notice, this list of conditions, and the following disclaimer,
2762306a36Sopenharmony_ci *    without modification.
2862306a36Sopenharmony_ci * 2. Redistributions in binary form must reproduce at minimum a disclaimer
2962306a36Sopenharmony_ci *    substantially similar to the "NO WARRANTY" disclaimer below
3062306a36Sopenharmony_ci *    ("Disclaimer") and any redistribution must be conditioned upon
3162306a36Sopenharmony_ci *    including a substantially similar Disclaimer requirement for further
3262306a36Sopenharmony_ci *    binary redistribution.
3362306a36Sopenharmony_ci * 3. Neither the names of the above-listed copyright holders nor the names
3462306a36Sopenharmony_ci *    of any contributors may be used to endorse or promote products derived
3562306a36Sopenharmony_ci *    from this software without specific prior written permission.
3662306a36Sopenharmony_ci *
3762306a36Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the
3862306a36Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free
3962306a36Sopenharmony_ci * Software Foundation.
4062306a36Sopenharmony_ci *
4162306a36Sopenharmony_ci * NO WARRANTY
4262306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4362306a36Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4462306a36Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
4562306a36Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4662306a36Sopenharmony_ci * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4762306a36Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4862306a36Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4962306a36Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
5062306a36Sopenharmony_ci * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
5162306a36Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
5262306a36Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGES.
5362306a36Sopenharmony_ci *
5462306a36Sopenharmony_ci * $Id$
5562306a36Sopenharmony_ci */
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci#ifndef	_AICLIB_H
5862306a36Sopenharmony_ci#define _AICLIB_H
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_cistruct scsi_sense
6162306a36Sopenharmony_ci{
6262306a36Sopenharmony_ci	uint8_t opcode;
6362306a36Sopenharmony_ci	uint8_t byte2;
6462306a36Sopenharmony_ci	uint8_t unused[2];
6562306a36Sopenharmony_ci	uint8_t length;
6662306a36Sopenharmony_ci	uint8_t control;
6762306a36Sopenharmony_ci};
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci#define		SCSI_REV_0		0
7062306a36Sopenharmony_ci#define		SCSI_REV_CCS		1
7162306a36Sopenharmony_ci#define		SCSI_REV_2		2
7262306a36Sopenharmony_ci#define		SCSI_REV_SPC		3
7362306a36Sopenharmony_ci#define		SCSI_REV_SPC2		4
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_cistruct scsi_sense_data
7662306a36Sopenharmony_ci{
7762306a36Sopenharmony_ci	uint8_t error_code;
7862306a36Sopenharmony_ci#define	SSD_ERRCODE			0x7F
7962306a36Sopenharmony_ci#define		SSD_CURRENT_ERROR	0x70
8062306a36Sopenharmony_ci#define		SSD_DEFERRED_ERROR	0x71
8162306a36Sopenharmony_ci#define	SSD_ERRCODE_VALID	0x80
8262306a36Sopenharmony_ci	uint8_t segment;
8362306a36Sopenharmony_ci	uint8_t flags;
8462306a36Sopenharmony_ci#define	SSD_KEY				0x0F
8562306a36Sopenharmony_ci#define		SSD_KEY_NO_SENSE	0x00
8662306a36Sopenharmony_ci#define		SSD_KEY_RECOVERED_ERROR	0x01
8762306a36Sopenharmony_ci#define		SSD_KEY_NOT_READY	0x02
8862306a36Sopenharmony_ci#define		SSD_KEY_MEDIUM_ERROR	0x03
8962306a36Sopenharmony_ci#define		SSD_KEY_HARDWARE_ERROR	0x04
9062306a36Sopenharmony_ci#define		SSD_KEY_ILLEGAL_REQUEST	0x05
9162306a36Sopenharmony_ci#define		SSD_KEY_UNIT_ATTENTION	0x06
9262306a36Sopenharmony_ci#define		SSD_KEY_DATA_PROTECT	0x07
9362306a36Sopenharmony_ci#define		SSD_KEY_BLANK_CHECK	0x08
9462306a36Sopenharmony_ci#define		SSD_KEY_Vendor_Specific	0x09
9562306a36Sopenharmony_ci#define		SSD_KEY_COPY_ABORTED	0x0a
9662306a36Sopenharmony_ci#define		SSD_KEY_ABORTED_COMMAND	0x0b
9762306a36Sopenharmony_ci#define		SSD_KEY_EQUAL		0x0c
9862306a36Sopenharmony_ci#define		SSD_KEY_VOLUME_OVERFLOW	0x0d
9962306a36Sopenharmony_ci#define		SSD_KEY_MISCOMPARE	0x0e
10062306a36Sopenharmony_ci#define		SSD_KEY_RESERVED	0x0f
10162306a36Sopenharmony_ci#define	SSD_ILI		0x20
10262306a36Sopenharmony_ci#define	SSD_EOM		0x40
10362306a36Sopenharmony_ci#define	SSD_FILEMARK	0x80
10462306a36Sopenharmony_ci	uint8_t info[4];
10562306a36Sopenharmony_ci	uint8_t extra_len;
10662306a36Sopenharmony_ci	uint8_t cmd_spec_info[4];
10762306a36Sopenharmony_ci	uint8_t add_sense_code;
10862306a36Sopenharmony_ci	uint8_t add_sense_code_qual;
10962306a36Sopenharmony_ci	uint8_t fru;
11062306a36Sopenharmony_ci	uint8_t sense_key_spec[3];
11162306a36Sopenharmony_ci#define	SSD_SCS_VALID		0x80
11262306a36Sopenharmony_ci#define SSD_FIELDPTR_CMD	0x40
11362306a36Sopenharmony_ci#define SSD_BITPTR_VALID	0x08
11462306a36Sopenharmony_ci#define SSD_BITPTR_VALUE	0x07
11562306a36Sopenharmony_ci#define SSD_MIN_SIZE 18
11662306a36Sopenharmony_ci	uint8_t extra_bytes[14];
11762306a36Sopenharmony_ci#define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
11862306a36Sopenharmony_ci};
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci/************************* Large Disk Handling ********************************/
12162306a36Sopenharmony_cistatic inline int
12262306a36Sopenharmony_ciaic_sector_div(sector_t capacity, int heads, int sectors)
12362306a36Sopenharmony_ci{
12462306a36Sopenharmony_ci	/* ugly, ugly sector_div calling convention.. */
12562306a36Sopenharmony_ci	sector_div(capacity, (heads * sectors));
12662306a36Sopenharmony_ci	return (int)capacity;
12762306a36Sopenharmony_ci}
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_cistatic inline uint32_t
13062306a36Sopenharmony_ciscsi_4btoul(uint8_t *bytes)
13162306a36Sopenharmony_ci{
13262306a36Sopenharmony_ci	uint32_t rv;
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci	rv = (bytes[0] << 24) |
13562306a36Sopenharmony_ci	     (bytes[1] << 16) |
13662306a36Sopenharmony_ci	     (bytes[2] << 8) |
13762306a36Sopenharmony_ci	     bytes[3];
13862306a36Sopenharmony_ci	return (rv);
13962306a36Sopenharmony_ci}
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci/* Macros for generating the elements of the PCI ID tables. */
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci#define GETID(v, s) (unsigned)(((v) >> (s)) & 0xFFFF ?: PCI_ANY_ID)
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci#define ID_C(x, c)						\
14662306a36Sopenharmony_ci{								\
14762306a36Sopenharmony_ci	GETID(x,32), GETID(x,48), GETID(x,0), GETID(x,16),	\
14862306a36Sopenharmony_ci	(c) << 8, 0xFFFF00, 0					\
14962306a36Sopenharmony_ci}
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci#define ID2C(x)                          \
15262306a36Sopenharmony_ci	ID_C(x, PCI_CLASS_STORAGE_SCSI), \
15362306a36Sopenharmony_ci	ID_C(x, PCI_CLASS_STORAGE_RAID)
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci#define IDIROC(x)  ((x) | ~ID_ALL_IROC_MASK)
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci/* Generate IDs for all 16 possibilites.
15862306a36Sopenharmony_ci * The argument has already masked out
15962306a36Sopenharmony_ci * the 4 least significant bits of the device id.
16062306a36Sopenharmony_ci * (e.g., mask: ID_9005_GENERIC_MASK).
16162306a36Sopenharmony_ci */
16262306a36Sopenharmony_ci#define ID16(x)                          \
16362306a36Sopenharmony_ci	ID(x),                           \
16462306a36Sopenharmony_ci	ID((x) | 0x0001000000000000ull), \
16562306a36Sopenharmony_ci	ID((x) | 0x0002000000000000ull), \
16662306a36Sopenharmony_ci	ID((x) | 0x0003000000000000ull), \
16762306a36Sopenharmony_ci	ID((x) | 0x0004000000000000ull), \
16862306a36Sopenharmony_ci	ID((x) | 0x0005000000000000ull), \
16962306a36Sopenharmony_ci	ID((x) | 0x0006000000000000ull), \
17062306a36Sopenharmony_ci	ID((x) | 0x0007000000000000ull), \
17162306a36Sopenharmony_ci	ID((x) | 0x0008000000000000ull), \
17262306a36Sopenharmony_ci	ID((x) | 0x0009000000000000ull), \
17362306a36Sopenharmony_ci	ID((x) | 0x000A000000000000ull), \
17462306a36Sopenharmony_ci	ID((x) | 0x000B000000000000ull), \
17562306a36Sopenharmony_ci	ID((x) | 0x000C000000000000ull), \
17662306a36Sopenharmony_ci	ID((x) | 0x000D000000000000ull), \
17762306a36Sopenharmony_ci	ID((x) | 0x000E000000000000ull), \
17862306a36Sopenharmony_ci	ID((x) | 0x000F000000000000ull)
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_ci#endif /*_AICLIB_H */
181