xref: /linux/drivers/scsi/smartpqi/smartpqi.h (revision 27655e9db47965f640b3ef5a6796587d58b523eb)
12cc37b15SDon Brace /* SPDX-License-Identifier: GPL-2.0 */
26c223761SKevin Barnett /*
3889653ecSKevin Barnett  *    driver for Microchip PQI-based storage controllers
4889653ecSKevin Barnett  *    Copyright (c) 2019-2021 Microchip Technology Inc. and its subsidiaries
52f4c4b92SDon Brace  *    Copyright (c) 2016-2018 Microsemi Corporation
66c223761SKevin Barnett  *    Copyright (c) 2016 PMC-Sierra, Inc.
76c223761SKevin Barnett  *
82f4c4b92SDon Brace  *    Questions/Comments/Bugfixes to storagedev@microchip.com
96c223761SKevin Barnett  *
106c223761SKevin Barnett  */
116c223761SKevin Barnett 
12ebaec8e3SCorentin Labbe #include <linux/io-64-nonatomic-lo-hi.h>
13ebaec8e3SCorentin Labbe 
146c223761SKevin Barnett #if !defined(_SMARTPQI_H)
156c223761SKevin Barnett #define _SMARTPQI_H
166c223761SKevin Barnett 
173d46a59aSDon Brace #include <scsi/scsi_host.h>
183d46a59aSDon Brace #include <linux/bsg-lib.h>
193d46a59aSDon Brace 
206c223761SKevin Barnett #pragma pack(1)
216c223761SKevin Barnett 
226c223761SKevin Barnett #define PQI_DEVICE_SIGNATURE	"PQI DREG"
236c223761SKevin Barnett 
246c223761SKevin Barnett /* This structure is defined by the PQI specification. */
256c223761SKevin Barnett struct pqi_device_registers {
266c223761SKevin Barnett 	__le64	signature;
276c223761SKevin Barnett 	u8	function_and_status_code;
286c223761SKevin Barnett 	u8	reserved[7];
296c223761SKevin Barnett 	u8	max_admin_iq_elements;
306c223761SKevin Barnett 	u8	max_admin_oq_elements;
316c223761SKevin Barnett 	u8	admin_iq_element_length;	/* in 16-byte units */
326c223761SKevin Barnett 	u8	admin_oq_element_length;	/* in 16-byte units */
336c223761SKevin Barnett 	__le16	max_reset_timeout;		/* in 100-millisecond units */
346c223761SKevin Barnett 	u8	reserved1[2];
356c223761SKevin Barnett 	__le32	legacy_intx_status;
366c223761SKevin Barnett 	__le32	legacy_intx_mask_set;
376c223761SKevin Barnett 	__le32	legacy_intx_mask_clear;
386c223761SKevin Barnett 	u8	reserved2[28];
396c223761SKevin Barnett 	__le32	device_status;
406c223761SKevin Barnett 	u8	reserved3[4];
416c223761SKevin Barnett 	__le64	admin_iq_pi_offset;
426c223761SKevin Barnett 	__le64	admin_oq_ci_offset;
436c223761SKevin Barnett 	__le64	admin_iq_element_array_addr;
446c223761SKevin Barnett 	__le64	admin_oq_element_array_addr;
456c223761SKevin Barnett 	__le64	admin_iq_ci_addr;
466c223761SKevin Barnett 	__le64	admin_oq_pi_addr;
476c223761SKevin Barnett 	u8	admin_iq_num_elements;
486c223761SKevin Barnett 	u8	admin_oq_num_elements;
496c223761SKevin Barnett 	__le16	admin_queue_int_msg_num;
506c223761SKevin Barnett 	u8	reserved4[4];
516c223761SKevin Barnett 	__le32	device_error;
526c223761SKevin Barnett 	u8	reserved5[4];
536c223761SKevin Barnett 	__le64	error_details;
546c223761SKevin Barnett 	__le32	device_reset;
556c223761SKevin Barnett 	__le32	power_action;
566c223761SKevin Barnett 	u8	reserved6[104];
576c223761SKevin Barnett };
586c223761SKevin Barnett 
596c223761SKevin Barnett /*
606c223761SKevin Barnett  * controller registers
616c223761SKevin Barnett  *
62889653ecSKevin Barnett  * These are defined by the Microchip implementation.
636c223761SKevin Barnett  *
646c223761SKevin Barnett  * Some registers (those named sis_*) are only used when in
656c223761SKevin Barnett  * legacy SIS mode before we transition the controller into
666c223761SKevin Barnett  * PQI mode.  There are a number of other SIS mode registers,
676c223761SKevin Barnett  * but we don't use them, so only the SIS registers that we
686c223761SKevin Barnett  * care about are defined here.  The offsets mentioned in the
696c223761SKevin Barnett  * comments are the offsets from the PCIe BAR 0.
706c223761SKevin Barnett  */
716c223761SKevin Barnett struct pqi_ctrl_registers {
726c223761SKevin Barnett 	u8	reserved[0x20];
736c223761SKevin Barnett 	__le32	sis_host_to_ctrl_doorbell;		/* 20h */
746c223761SKevin Barnett 	u8	reserved1[0x34 - (0x20 + sizeof(__le32))];
756c223761SKevin Barnett 	__le32	sis_interrupt_mask;			/* 34h */
766c223761SKevin Barnett 	u8	reserved2[0x9c - (0x34 + sizeof(__le32))];
776c223761SKevin Barnett 	__le32	sis_ctrl_to_host_doorbell;		/* 9Ch */
786c223761SKevin Barnett 	u8	reserved3[0xa0 - (0x9c + sizeof(__le32))];
796c223761SKevin Barnett 	__le32	sis_ctrl_to_host_doorbell_clear;	/* A0h */
80ff6abb73SKevin Barnett 	u8	reserved4[0xb0 - (0xa0 + sizeof(__le32))];
81ff6abb73SKevin Barnett 	__le32	sis_driver_scratch;			/* B0h */
822708a256SKevin Barnett 	__le32  sis_product_identifier;			/* B4h */
832708a256SKevin Barnett 	u8	reserved5[0xbc - (0xb4 + sizeof(__le32))];
846c223761SKevin Barnett 	__le32	sis_firmware_status;			/* BCh */
855d1f03e6SMurthy Bhat 	u8	reserved6[0xcc - (0xbc + sizeof(__le32))];
865d1f03e6SMurthy Bhat 	__le32	sis_ctrl_shutdown_reason_code;		/* CCh */
875d1f03e6SMurthy Bhat 	u8	reserved7[0x1000 - (0xcc + sizeof(__le32))];
886c223761SKevin Barnett 	__le32	sis_mailbox[8];				/* 1000h */
895d1f03e6SMurthy Bhat 	u8	reserved8[0x4000 - (0x1000 + (sizeof(__le32) * 8))];
906c223761SKevin Barnett 	/*
916c223761SKevin Barnett 	 * The PQI spec states that the PQI registers should be at
926c223761SKevin Barnett 	 * offset 0 from the PCIe BAR 0.  However, we can't map
936c223761SKevin Barnett 	 * them at offset 0 because that would break compatibility
946c223761SKevin Barnett 	 * with the SIS registers.  So we map them at offset 4000h.
956c223761SKevin Barnett 	 */
966c223761SKevin Barnett 	struct pqi_device_registers pqi_registers;	/* 4000h */
976c223761SKevin Barnett };
986c223761SKevin Barnett 
996c223761SKevin Barnett #define PQI_DEVICE_REGISTERS_OFFSET	0x4000
1006c223761SKevin Barnett 
1015d1f03e6SMurthy Bhat /* shutdown reasons for taking the controller offline */
1025d1f03e6SMurthy Bhat enum pqi_ctrl_shutdown_reason {
1035d1f03e6SMurthy Bhat 	PQI_IQ_NOT_DRAINED_TIMEOUT = 1,
1045d1f03e6SMurthy Bhat 	PQI_LUN_RESET_TIMEOUT = 2,
1055d1f03e6SMurthy Bhat 	PQI_IO_PENDING_POST_LUN_RESET_TIMEOUT = 3,
1065d1f03e6SMurthy Bhat 	PQI_NO_HEARTBEAT = 4,
1075d1f03e6SMurthy Bhat 	PQI_FIRMWARE_KERNEL_NOT_UP = 5,
1085d1f03e6SMurthy Bhat 	PQI_OFA_RESPONSE_TIMEOUT = 6,
1095d1f03e6SMurthy Bhat 	PQI_INVALID_REQ_ID = 7,
1105d1f03e6SMurthy Bhat 	PQI_UNMATCHED_REQ_ID = 8,
1115d1f03e6SMurthy Bhat 	PQI_IO_PI_OUT_OF_RANGE = 9,
1125d1f03e6SMurthy Bhat 	PQI_EVENT_PI_OUT_OF_RANGE = 10,
1135d1f03e6SMurthy Bhat 	PQI_UNEXPECTED_IU_TYPE = 11
1145d1f03e6SMurthy Bhat };
1155d1f03e6SMurthy Bhat 
1166c223761SKevin Barnett enum pqi_io_path {
1176c223761SKevin Barnett 	RAID_PATH = 0,
1186c223761SKevin Barnett 	AIO_PATH = 1
1196c223761SKevin Barnett };
1206c223761SKevin Barnett 
121061ef06aSKevin Barnett enum pqi_irq_mode {
122061ef06aSKevin Barnett 	IRQ_MODE_NONE,
123061ef06aSKevin Barnett 	IRQ_MODE_INTX,
124061ef06aSKevin Barnett 	IRQ_MODE_MSIX
125061ef06aSKevin Barnett };
126061ef06aSKevin Barnett 
1276c223761SKevin Barnett struct pqi_sg_descriptor {
1286c223761SKevin Barnett 	__le64	address;
1296c223761SKevin Barnett 	__le32	length;
1306c223761SKevin Barnett 	__le32	flags;
1316c223761SKevin Barnett };
1326c223761SKevin Barnett 
1336c223761SKevin Barnett /* manifest constants for the flags field of pqi_sg_descriptor */
1346c223761SKevin Barnett #define CISS_SG_LAST	0x40000000
1356c223761SKevin Barnett #define CISS_SG_CHAIN	0x80000000
1366c223761SKevin Barnett 
1376c223761SKevin Barnett struct pqi_iu_header {
1386c223761SKevin Barnett 	u8	iu_type;
1396c223761SKevin Barnett 	u8	reserved;
1406c223761SKevin Barnett 	__le16	iu_length;	/* in bytes - does not include the length */
1416c223761SKevin Barnett 				/* of this header */
1426c223761SKevin Barnett 	__le16	response_queue_id;	/* specifies the OQ where the */
1436c223761SKevin Barnett 					/* response IU is to be delivered */
144ae0c189dSKevin Barnett 	u16	driver_flags;	/* reserved for driver use */
1456c223761SKevin Barnett };
1466c223761SKevin Barnett 
147ae0c189dSKevin Barnett /* manifest constants for pqi_iu_header.driver_flags */
148ae0c189dSKevin Barnett #define PQI_DRIVER_NONBLOCKABLE_REQUEST		0x1
149ae0c189dSKevin Barnett 
1506c223761SKevin Barnett /*
1516c223761SKevin Barnett  * According to the PQI spec, the IU header is only the first 4 bytes of our
1526c223761SKevin Barnett  * pqi_iu_header structure.
1536c223761SKevin Barnett  */
1546c223761SKevin Barnett #define PQI_REQUEST_HEADER_LENGTH	4
1556c223761SKevin Barnett 
1566c223761SKevin Barnett struct pqi_general_admin_request {
1576c223761SKevin Barnett 	struct pqi_iu_header header;
1586c223761SKevin Barnett 	__le16	request_id;
1596c223761SKevin Barnett 	u8	function_code;
1606c223761SKevin Barnett 	union {
1616c223761SKevin Barnett 		struct {
1626c223761SKevin Barnett 			u8	reserved[33];
1636c223761SKevin Barnett 			__le32	buffer_length;
1646c223761SKevin Barnett 			struct pqi_sg_descriptor sg_descriptor;
1656c223761SKevin Barnett 		} report_device_capability;
1666c223761SKevin Barnett 
1676c223761SKevin Barnett 		struct {
1686c223761SKevin Barnett 			u8	reserved;
1696c223761SKevin Barnett 			__le16	queue_id;
1706c223761SKevin Barnett 			u8	reserved1[2];
1716c223761SKevin Barnett 			__le64	element_array_addr;
1726c223761SKevin Barnett 			__le64	ci_addr;
1736c223761SKevin Barnett 			__le16	num_elements;
1746c223761SKevin Barnett 			__le16	element_length;
1756c223761SKevin Barnett 			u8	queue_protocol;
1766c223761SKevin Barnett 			u8	reserved2[23];
1776c223761SKevin Barnett 			__le32	vendor_specific;
1786c223761SKevin Barnett 		} create_operational_iq;
1796c223761SKevin Barnett 
1806c223761SKevin Barnett 		struct {
1816c223761SKevin Barnett 			u8	reserved;
1826c223761SKevin Barnett 			__le16	queue_id;
1836c223761SKevin Barnett 			u8	reserved1[2];
1846c223761SKevin Barnett 			__le64	element_array_addr;
1856c223761SKevin Barnett 			__le64	pi_addr;
1866c223761SKevin Barnett 			__le16	num_elements;
1876c223761SKevin Barnett 			__le16	element_length;
1886c223761SKevin Barnett 			u8	queue_protocol;
1896c223761SKevin Barnett 			u8	reserved2[3];
1906c223761SKevin Barnett 			__le16	int_msg_num;
1916c223761SKevin Barnett 			__le16	coalescing_count;
1926c223761SKevin Barnett 			__le32	min_coalescing_time;
1936c223761SKevin Barnett 			__le32	max_coalescing_time;
1946c223761SKevin Barnett 			u8	reserved3[8];
1956c223761SKevin Barnett 			__le32	vendor_specific;
1966c223761SKevin Barnett 		} create_operational_oq;
1976c223761SKevin Barnett 
1986c223761SKevin Barnett 		struct {
1996c223761SKevin Barnett 			u8	reserved;
2006c223761SKevin Barnett 			__le16	queue_id;
2016c223761SKevin Barnett 			u8	reserved1[50];
2026c223761SKevin Barnett 		} delete_operational_queue;
2036c223761SKevin Barnett 
2046c223761SKevin Barnett 		struct {
2056c223761SKevin Barnett 			u8	reserved;
2066c223761SKevin Barnett 			__le16	queue_id;
2076c223761SKevin Barnett 			u8	reserved1[46];
2086c223761SKevin Barnett 			__le32	vendor_specific;
2096c223761SKevin Barnett 		} change_operational_iq_properties;
2106c223761SKevin Barnett 
2116c223761SKevin Barnett 	} data;
2126c223761SKevin Barnett };
2136c223761SKevin Barnett 
2146c223761SKevin Barnett struct pqi_general_admin_response {
2156c223761SKevin Barnett 	struct pqi_iu_header header;
2166c223761SKevin Barnett 	__le16	request_id;
2176c223761SKevin Barnett 	u8	function_code;
2186c223761SKevin Barnett 	u8	status;
2196c223761SKevin Barnett 	union {
2206c223761SKevin Barnett 		struct {
2216c223761SKevin Barnett 			u8	status_descriptor[4];
2226c223761SKevin Barnett 			__le64	iq_pi_offset;
2236c223761SKevin Barnett 			u8	reserved[40];
2246c223761SKevin Barnett 		} create_operational_iq;
2256c223761SKevin Barnett 
2266c223761SKevin Barnett 		struct {
2276c223761SKevin Barnett 			u8	status_descriptor[4];
2286c223761SKevin Barnett 			__le64	oq_ci_offset;
2296c223761SKevin Barnett 			u8	reserved[40];
2306c223761SKevin Barnett 		} create_operational_oq;
2316c223761SKevin Barnett 	} data;
2326c223761SKevin Barnett };
2336c223761SKevin Barnett 
2346c223761SKevin Barnett struct pqi_iu_layer_descriptor {
2356c223761SKevin Barnett 	u8	inbound_spanning_supported : 1;
2366c223761SKevin Barnett 	u8	reserved : 7;
2376c223761SKevin Barnett 	u8	reserved1[5];
2386c223761SKevin Barnett 	__le16	max_inbound_iu_length;
2396c223761SKevin Barnett 	u8	outbound_spanning_supported : 1;
2406c223761SKevin Barnett 	u8	reserved2 : 7;
2416c223761SKevin Barnett 	u8	reserved3[5];
2426c223761SKevin Barnett 	__le16	max_outbound_iu_length;
2436c223761SKevin Barnett };
2446c223761SKevin Barnett 
2456c223761SKevin Barnett struct pqi_device_capability {
2466c223761SKevin Barnett 	__le16	data_length;
2476c223761SKevin Barnett 	u8	reserved[6];
2486c223761SKevin Barnett 	u8	iq_arbitration_priority_support_bitmask;
2496c223761SKevin Barnett 	u8	maximum_aw_a;
2506c223761SKevin Barnett 	u8	maximum_aw_b;
2516c223761SKevin Barnett 	u8	maximum_aw_c;
2526c223761SKevin Barnett 	u8	max_arbitration_burst : 3;
2536c223761SKevin Barnett 	u8	reserved1 : 4;
2546c223761SKevin Barnett 	u8	iqa : 1;
2556c223761SKevin Barnett 	u8	reserved2[2];
2566c223761SKevin Barnett 	u8	iq_freeze : 1;
2576c223761SKevin Barnett 	u8	reserved3 : 7;
2586c223761SKevin Barnett 	__le16	max_inbound_queues;
2596c223761SKevin Barnett 	__le16	max_elements_per_iq;
2606c223761SKevin Barnett 	u8	reserved4[4];
2616c223761SKevin Barnett 	__le16	max_iq_element_length;
2626c223761SKevin Barnett 	__le16	min_iq_element_length;
2636c223761SKevin Barnett 	u8	reserved5[2];
2646c223761SKevin Barnett 	__le16	max_outbound_queues;
2656c223761SKevin Barnett 	__le16	max_elements_per_oq;
2666c223761SKevin Barnett 	__le16	intr_coalescing_time_granularity;
2676c223761SKevin Barnett 	__le16	max_oq_element_length;
2686c223761SKevin Barnett 	__le16	min_oq_element_length;
2696c223761SKevin Barnett 	u8	reserved6[24];
2706c223761SKevin Barnett 	struct pqi_iu_layer_descriptor iu_layer_descriptors[32];
2716c223761SKevin Barnett };
2726c223761SKevin Barnett 
2736c223761SKevin Barnett #define PQI_MAX_EMBEDDED_SG_DESCRIPTORS		4
2746702d2c4SDon Brace #define PQI_MAX_EMBEDDED_R56_SG_DESCRIPTORS	3
2756c223761SKevin Barnett 
2766c223761SKevin Barnett struct pqi_raid_path_request {
2776c223761SKevin Barnett 	struct pqi_iu_header header;
2786c223761SKevin Barnett 	__le16	request_id;
2796c223761SKevin Barnett 	__le16	nexus_id;
2806c223761SKevin Barnett 	__le32	buffer_length;
2816c223761SKevin Barnett 	u8	lun_number[8];
2826c223761SKevin Barnett 	__le16	protocol_specific;
2836c223761SKevin Barnett 	u8	data_direction : 2;
2846c223761SKevin Barnett 	u8	partial : 1;
2856c223761SKevin Barnett 	u8	reserved1 : 4;
2866c223761SKevin Barnett 	u8	fence : 1;
2876c223761SKevin Barnett 	__le16	error_index;
2886c223761SKevin Barnett 	u8	reserved2;
2896c223761SKevin Barnett 	u8	task_attribute : 3;
2906c223761SKevin Barnett 	u8	command_priority : 4;
2916c223761SKevin Barnett 	u8	reserved3 : 1;
2926c223761SKevin Barnett 	u8	reserved4 : 2;
2936c223761SKevin Barnett 	u8	additional_cdb_bytes_usage : 3;
2946c223761SKevin Barnett 	u8	reserved5 : 3;
29521432010Skoshyaji 	u8	cdb[16];
29621432010Skoshyaji 	u8	reserved6[12];
29721432010Skoshyaji 	__le32	timeout;
298583891c9SKevin Barnett 	struct pqi_sg_descriptor sg_descriptors[PQI_MAX_EMBEDDED_SG_DESCRIPTORS];
2996c223761SKevin Barnett };
3006c223761SKevin Barnett 
3016c223761SKevin Barnett struct pqi_aio_path_request {
3026c223761SKevin Barnett 	struct pqi_iu_header header;
3036c223761SKevin Barnett 	__le16	request_id;
3046c223761SKevin Barnett 	u8	reserved1[2];
3056c223761SKevin Barnett 	__le32	nexus_id;
3066c223761SKevin Barnett 	__le32	buffer_length;
3076c223761SKevin Barnett 	u8	data_direction : 2;
3086c223761SKevin Barnett 	u8	partial : 1;
3096c223761SKevin Barnett 	u8	memory_type : 1;
3106c223761SKevin Barnett 	u8	fence : 1;
3116c223761SKevin Barnett 	u8	encryption_enable : 1;
3126c223761SKevin Barnett 	u8	reserved2 : 2;
3136c223761SKevin Barnett 	u8	task_attribute : 3;
3146c223761SKevin Barnett 	u8	command_priority : 4;
3156c223761SKevin Barnett 	u8	reserved3 : 1;
3166c223761SKevin Barnett 	__le16	data_encryption_key_index;
3176c223761SKevin Barnett 	__le32	encrypt_tweak_lower;
3186c223761SKevin Barnett 	__le32	encrypt_tweak_upper;
3196c223761SKevin Barnett 	u8	cdb[16];
3206c223761SKevin Barnett 	__le16	error_index;
3216c223761SKevin Barnett 	u8	num_sg_descriptors;
3226c223761SKevin Barnett 	u8	cdb_length;
3236c223761SKevin Barnett 	u8	lun_number[8];
3246c223761SKevin Barnett 	u8	reserved4[4];
325583891c9SKevin Barnett 	struct pqi_sg_descriptor sg_descriptors[PQI_MAX_EMBEDDED_SG_DESCRIPTORS];
3266c223761SKevin Barnett };
3276c223761SKevin Barnett 
3287a012c23SDon Brace #define PQI_RAID1_NVME_XFER_LIMIT	(32 * 1024)	/* 32 KiB */
329583891c9SKevin Barnett 
3307a012c23SDon Brace struct pqi_aio_r1_path_request {
3317a012c23SDon Brace 	struct pqi_iu_header header;
3327a012c23SDon Brace 	__le16	request_id;
3337a012c23SDon Brace 	__le16	volume_id;	/* ID of the RAID volume */
3347a012c23SDon Brace 	__le32	it_nexus_1;	/* IT nexus of the 1st drive in the RAID volume */
3357a012c23SDon Brace 	__le32	it_nexus_2;	/* IT nexus of the 2nd drive in the RAID volume */
3367a012c23SDon Brace 	__le32	it_nexus_3;	/* IT nexus of the 3rd drive in the RAID volume */
3377a012c23SDon Brace 	__le32	data_length;	/* total bytes to read/write */
3387a012c23SDon Brace 	u8	data_direction : 2;
3397a012c23SDon Brace 	u8	partial : 1;
3407a012c23SDon Brace 	u8	memory_type : 1;
3417a012c23SDon Brace 	u8	fence : 1;
3427a012c23SDon Brace 	u8	encryption_enable : 1;
3437a012c23SDon Brace 	u8	reserved : 2;
3447a012c23SDon Brace 	u8	task_attribute : 3;
3457a012c23SDon Brace 	u8	command_priority : 4;
3467a012c23SDon Brace 	u8	reserved2 : 1;
3477a012c23SDon Brace 	__le16	data_encryption_key_index;
3487a012c23SDon Brace 	u8	cdb[16];
3497a012c23SDon Brace 	__le16	error_index;
3507a012c23SDon Brace 	u8	num_sg_descriptors;
3517a012c23SDon Brace 	u8	cdb_length;
3527a012c23SDon Brace 	u8	num_drives;	/* number of drives in the RAID volume (2 or 3) */
3537a012c23SDon Brace 	u8	reserved3[3];
3547a012c23SDon Brace 	__le32	encrypt_tweak_lower;
3557a012c23SDon Brace 	__le32	encrypt_tweak_upper;
3567a012c23SDon Brace 	struct pqi_sg_descriptor sg_descriptors[PQI_MAX_EMBEDDED_SG_DESCRIPTORS];
3577a012c23SDon Brace };
3587a012c23SDon Brace 
359f6cc2a77SKevin Barnett #define PQI_DEFAULT_MAX_WRITE_RAID_5_6			(8 * 1024U)
360f6cc2a77SKevin Barnett #define PQI_DEFAULT_MAX_TRANSFER_ENCRYPTED_SAS_SATA	(~0U)
361f6cc2a77SKevin Barnett #define PQI_DEFAULT_MAX_TRANSFER_ENCRYPTED_NVME		(32 * 1024U)
362f6cc2a77SKevin Barnett 
3636702d2c4SDon Brace struct pqi_aio_r56_path_request {
3646702d2c4SDon Brace 	struct pqi_iu_header header;
3656702d2c4SDon Brace 	__le16	request_id;
3666702d2c4SDon Brace 	__le16	volume_id;		/* ID of the RAID volume */
3676702d2c4SDon Brace 	__le32	data_it_nexus;		/* IT nexus for the data drive */
3686702d2c4SDon Brace 	__le32	p_parity_it_nexus;	/* IT nexus for the P parity drive */
3696702d2c4SDon Brace 	__le32	q_parity_it_nexus;	/* IT nexus for the Q parity drive */
3706702d2c4SDon Brace 	__le32	data_length;		/* total bytes to read/write */
3716702d2c4SDon Brace 	u8	data_direction : 2;
3726702d2c4SDon Brace 	u8	partial : 1;
3736702d2c4SDon Brace 	u8	mem_type : 1;		/* 0 = PCIe, 1 = DDR */
3746702d2c4SDon Brace 	u8	fence : 1;
3756702d2c4SDon Brace 	u8	encryption_enable : 1;
3766702d2c4SDon Brace 	u8	reserved : 2;
3776702d2c4SDon Brace 	u8	task_attribute : 3;
3786702d2c4SDon Brace 	u8	command_priority : 4;
3796702d2c4SDon Brace 	u8	reserved1 : 1;
3806702d2c4SDon Brace 	__le16	data_encryption_key_index;
3816702d2c4SDon Brace 	u8	cdb[16];
3826702d2c4SDon Brace 	__le16	error_index;
3836702d2c4SDon Brace 	u8	num_sg_descriptors;
3846702d2c4SDon Brace 	u8	cdb_length;
3856702d2c4SDon Brace 	u8	xor_multiplier;
3866702d2c4SDon Brace 	u8	reserved2[3];
3876702d2c4SDon Brace 	__le32	encrypt_tweak_lower;
3886702d2c4SDon Brace 	__le32	encrypt_tweak_upper;
3896702d2c4SDon Brace 	__le64	row;			/* row = logical LBA/blocks per row */
3906702d2c4SDon Brace 	u8	reserved3[8];
3916702d2c4SDon Brace 	struct pqi_sg_descriptor sg_descriptors[PQI_MAX_EMBEDDED_R56_SG_DESCRIPTORS];
3926702d2c4SDon Brace };
3936702d2c4SDon Brace 
3946c223761SKevin Barnett struct pqi_io_response {
3956c223761SKevin Barnett 	struct pqi_iu_header header;
3966c223761SKevin Barnett 	__le16	request_id;
3976c223761SKevin Barnett 	__le16	error_index;
3986c223761SKevin Barnett 	u8	reserved2[4];
3996c223761SKevin Barnett };
4006c223761SKevin Barnett 
4016c223761SKevin Barnett struct pqi_general_management_request {
4026c223761SKevin Barnett 	struct pqi_iu_header header;
4036c223761SKevin Barnett 	__le16	request_id;
4046c223761SKevin Barnett 	union {
4056c223761SKevin Barnett 		struct {
4066c223761SKevin Barnett 			u8	reserved[2];
4076c223761SKevin Barnett 			__le32	buffer_length;
4086c223761SKevin Barnett 			struct pqi_sg_descriptor sg_descriptors[3];
4096c223761SKevin Barnett 		} report_event_configuration;
4106c223761SKevin Barnett 
4116c223761SKevin Barnett 		struct {
4126c223761SKevin Barnett 			__le16	global_event_oq_id;
4136c223761SKevin Barnett 			__le32	buffer_length;
4146c223761SKevin Barnett 			struct pqi_sg_descriptor sg_descriptors[3];
4156c223761SKevin Barnett 		} set_event_configuration;
4166c223761SKevin Barnett 	} data;
4176c223761SKevin Barnett };
4186c223761SKevin Barnett 
4196c223761SKevin Barnett struct pqi_event_descriptor {
4206c223761SKevin Barnett 	u8	event_type;
4216c223761SKevin Barnett 	u8	reserved;
4226c223761SKevin Barnett 	__le16	oq_id;
4236c223761SKevin Barnett };
4246c223761SKevin Barnett 
4256c223761SKevin Barnett struct pqi_event_config {
4266c223761SKevin Barnett 	u8	reserved[2];
4276c223761SKevin Barnett 	u8	num_event_descriptors;
4286c223761SKevin Barnett 	u8	reserved1;
4295f492a7aSGustavo A. R. Silva 	struct pqi_event_descriptor descriptors[];
4306c223761SKevin Barnett };
4316c223761SKevin Barnett 
4326c223761SKevin Barnett #define PQI_MAX_EVENT_DESCRIPTORS	255
4336c223761SKevin Barnett 
4344fd22c13SMahesh Rajashekhara #define PQI_EVENT_OFA_MEMORY_ALLOCATION	0x0
4354fd22c13SMahesh Rajashekhara #define PQI_EVENT_OFA_QUIESCE		0x1
436583891c9SKevin Barnett #define PQI_EVENT_OFA_CANCELED		0x2
4374fd22c13SMahesh Rajashekhara 
4386c223761SKevin Barnett struct pqi_event_response {
4396c223761SKevin Barnett 	struct pqi_iu_header header;
4406c223761SKevin Barnett 	u8	event_type;
4416c223761SKevin Barnett 	u8	reserved2 : 7;
4429e68ccccSKevin Barnett 	u8	request_acknowledge : 1;
4436c223761SKevin Barnett 	__le16	event_id;
4446c223761SKevin Barnett 	__le32	additional_event_id;
4454fd22c13SMahesh Rajashekhara 	union {
4464fd22c13SMahesh Rajashekhara 		struct {
4474fd22c13SMahesh Rajashekhara 			__le32	bytes_requested;
4484fd22c13SMahesh Rajashekhara 			u8	reserved[12];
4494fd22c13SMahesh Rajashekhara 		} ofa_memory_allocation;
4504fd22c13SMahesh Rajashekhara 
4514fd22c13SMahesh Rajashekhara 		struct {
4524fd22c13SMahesh Rajashekhara 			__le16	reason;		/* reason for cancellation */
4534fd22c13SMahesh Rajashekhara 			u8	reserved[14];
4544fd22c13SMahesh Rajashekhara 		} ofa_cancelled;
4554fd22c13SMahesh Rajashekhara 	} data;
4566c223761SKevin Barnett };
4576c223761SKevin Barnett 
4586c223761SKevin Barnett struct pqi_event_acknowledge_request {
4596c223761SKevin Barnett 	struct pqi_iu_header header;
4606c223761SKevin Barnett 	u8	event_type;
4616c223761SKevin Barnett 	u8	reserved2;
4626c223761SKevin Barnett 	__le16	event_id;
4636c223761SKevin Barnett 	__le32	additional_event_id;
4646c223761SKevin Barnett };
4656c223761SKevin Barnett 
4666c223761SKevin Barnett struct pqi_task_management_request {
4676c223761SKevin Barnett 	struct pqi_iu_header header;
4686c223761SKevin Barnett 	__le16	request_id;
4696c223761SKevin Barnett 	__le16	nexus_id;
470c2922f17SMurthy Bhat 	u8	reserved[2];
471c2922f17SMurthy Bhat 	__le16  timeout;
4726c223761SKevin Barnett 	u8	lun_number[8];
4736c223761SKevin Barnett 	__le16	protocol_specific;
4746c223761SKevin Barnett 	__le16	outbound_queue_id_to_manage;
4756c223761SKevin Barnett 	__le16	request_id_to_manage;
4766c223761SKevin Barnett 	u8	task_management_function;
4776c223761SKevin Barnett 	u8	reserved2 : 7;
4786c223761SKevin Barnett 	u8	fence : 1;
4796c223761SKevin Barnett };
4806c223761SKevin Barnett 
4816c223761SKevin Barnett #define SOP_TASK_MANAGEMENT_LUN_RESET	0x8
4826c223761SKevin Barnett 
4836c223761SKevin Barnett struct pqi_task_management_response {
4846c223761SKevin Barnett 	struct pqi_iu_header header;
4856c223761SKevin Barnett 	__le16	request_id;
4866c223761SKevin Barnett 	__le16	nexus_id;
4876c223761SKevin Barnett 	u8	additional_response_info[3];
4886c223761SKevin Barnett 	u8	response_code;
4896c223761SKevin Barnett };
4906c223761SKevin Barnett 
491b212c251SKevin Barnett struct pqi_vendor_general_request {
492b212c251SKevin Barnett 	struct pqi_iu_header header;
493b212c251SKevin Barnett 	__le16	request_id;
494b212c251SKevin Barnett 	__le16	function_code;
495b212c251SKevin Barnett 	union {
496b212c251SKevin Barnett 		struct {
497b212c251SKevin Barnett 			__le16	first_section;
498b212c251SKevin Barnett 			__le16	last_section;
499b212c251SKevin Barnett 			u8	reserved[48];
500b212c251SKevin Barnett 		} config_table_update;
501b212c251SKevin Barnett 
502b212c251SKevin Barnett 		struct {
503b212c251SKevin Barnett 			__le64	buffer_address;
504b212c251SKevin Barnett 			__le32	buffer_length;
505b212c251SKevin Barnett 			u8	reserved[40];
506b212c251SKevin Barnett 		} ofa_memory_allocation;
507b212c251SKevin Barnett 	} data;
508b212c251SKevin Barnett };
509b212c251SKevin Barnett 
510b212c251SKevin Barnett struct pqi_vendor_general_response {
511b212c251SKevin Barnett 	struct pqi_iu_header header;
512b212c251SKevin Barnett 	__le16	request_id;
513b212c251SKevin Barnett 	__le16	function_code;
514b212c251SKevin Barnett 	__le16	status;
515b212c251SKevin Barnett 	u8	reserved[2];
516b212c251SKevin Barnett };
517b212c251SKevin Barnett 
518b212c251SKevin Barnett #define PQI_VENDOR_GENERAL_CONFIG_TABLE_UPDATE	0
5194fd22c13SMahesh Rajashekhara #define PQI_VENDOR_GENERAL_HOST_MEMORY_UPDATE	1
5204fd22c13SMahesh Rajashekhara 
5214fd22c13SMahesh Rajashekhara #define PQI_OFA_VERSION			1
5224fd22c13SMahesh Rajashekhara #define PQI_OFA_SIGNATURE		"OFA_QRM"
5234fd22c13SMahesh Rajashekhara #define PQI_OFA_MAX_SG_DESCRIPTORS	64
5244fd22c13SMahesh Rajashekhara 
5254fd22c13SMahesh Rajashekhara struct pqi_ofa_memory {
5264fd22c13SMahesh Rajashekhara 	__le64	signature;	/* "OFA_QRM" */
5274fd22c13SMahesh Rajashekhara 	__le16	version;	/* version of this struct (1 = 1st version) */
5284fd22c13SMahesh Rajashekhara 	u8	reserved[62];
5294fd22c13SMahesh Rajashekhara 	__le32	bytes_allocated;	/* total allocated memory in bytes */
5304fd22c13SMahesh Rajashekhara 	__le16	num_memory_descriptors;
5314fd22c13SMahesh Rajashekhara 	u8	reserved1[2];
5322790cd4dSKevin Barnett 	struct pqi_sg_descriptor sg_descriptor[PQI_OFA_MAX_SG_DESCRIPTORS];
5334fd22c13SMahesh Rajashekhara };
534b212c251SKevin Barnett 
5356c223761SKevin Barnett struct pqi_aio_error_info {
5366c223761SKevin Barnett 	u8	status;
5376c223761SKevin Barnett 	u8	service_response;
5386c223761SKevin Barnett 	u8	data_present;
5396c223761SKevin Barnett 	u8	reserved;
5406c223761SKevin Barnett 	__le32	residual_count;
5416c223761SKevin Barnett 	__le16	data_length;
5426c223761SKevin Barnett 	__le16	reserved1;
5436c223761SKevin Barnett 	u8	data[256];
5446c223761SKevin Barnett };
5456c223761SKevin Barnett 
5466c223761SKevin Barnett struct pqi_raid_error_info {
5476c223761SKevin Barnett 	u8	data_in_result;
5486c223761SKevin Barnett 	u8	data_out_result;
5496c223761SKevin Barnett 	u8	reserved[3];
5506c223761SKevin Barnett 	u8	status;
5516c223761SKevin Barnett 	__le16	status_qualifier;
5526c223761SKevin Barnett 	__le16	sense_data_length;
5536c223761SKevin Barnett 	__le16	response_data_length;
5546c223761SKevin Barnett 	__le32	data_in_transferred;
5556c223761SKevin Barnett 	__le32	data_out_transferred;
5566c223761SKevin Barnett 	u8	data[256];
5576c223761SKevin Barnett };
5586c223761SKevin Barnett 
5596c223761SKevin Barnett #define PQI_REQUEST_IU_TASK_MANAGEMENT			0x13
5606c223761SKevin Barnett #define PQI_REQUEST_IU_RAID_PATH_IO			0x14
5616c223761SKevin Barnett #define PQI_REQUEST_IU_AIO_PATH_IO			0x15
5626702d2c4SDon Brace #define PQI_REQUEST_IU_AIO_PATH_RAID5_IO		0x18
5636702d2c4SDon Brace #define PQI_REQUEST_IU_AIO_PATH_RAID6_IO		0x19
5647a012c23SDon Brace #define PQI_REQUEST_IU_AIO_PATH_RAID1_IO		0x1A
5656c223761SKevin Barnett #define PQI_REQUEST_IU_GENERAL_ADMIN			0x60
5666c223761SKevin Barnett #define PQI_REQUEST_IU_REPORT_VENDOR_EVENT_CONFIG	0x72
5676c223761SKevin Barnett #define PQI_REQUEST_IU_SET_VENDOR_EVENT_CONFIG		0x73
568b212c251SKevin Barnett #define PQI_REQUEST_IU_VENDOR_GENERAL			0x75
5696c223761SKevin Barnett #define PQI_REQUEST_IU_ACKNOWLEDGE_VENDOR_EVENT		0xf6
5706c223761SKevin Barnett 
5716c223761SKevin Barnett #define PQI_RESPONSE_IU_GENERAL_MANAGEMENT		0x81
5726c223761SKevin Barnett #define PQI_RESPONSE_IU_TASK_MANAGEMENT			0x93
5736c223761SKevin Barnett #define PQI_RESPONSE_IU_GENERAL_ADMIN			0xe0
5746c223761SKevin Barnett #define PQI_RESPONSE_IU_RAID_PATH_IO_SUCCESS		0xf0
5756c223761SKevin Barnett #define PQI_RESPONSE_IU_AIO_PATH_IO_SUCCESS		0xf1
5766c223761SKevin Barnett #define PQI_RESPONSE_IU_RAID_PATH_IO_ERROR		0xf2
5776c223761SKevin Barnett #define PQI_RESPONSE_IU_AIO_PATH_IO_ERROR		0xf3
5786c223761SKevin Barnett #define PQI_RESPONSE_IU_AIO_PATH_DISABLED		0xf4
5796c223761SKevin Barnett #define PQI_RESPONSE_IU_VENDOR_EVENT			0xf5
580b212c251SKevin Barnett #define PQI_RESPONSE_IU_VENDOR_GENERAL			0xf7
5816c223761SKevin Barnett 
5826c223761SKevin Barnett #define PQI_GENERAL_ADMIN_FUNCTION_REPORT_DEVICE_CAPABILITY	0x0
5836c223761SKevin Barnett #define PQI_GENERAL_ADMIN_FUNCTION_CREATE_IQ			0x10
5846c223761SKevin Barnett #define PQI_GENERAL_ADMIN_FUNCTION_CREATE_OQ			0x11
5856c223761SKevin Barnett #define PQI_GENERAL_ADMIN_FUNCTION_DELETE_IQ			0x12
5866c223761SKevin Barnett #define PQI_GENERAL_ADMIN_FUNCTION_DELETE_OQ			0x13
5876c223761SKevin Barnett #define PQI_GENERAL_ADMIN_FUNCTION_CHANGE_IQ_PROPERTY		0x14
5886c223761SKevin Barnett 
5896c223761SKevin Barnett #define PQI_GENERAL_ADMIN_STATUS_SUCCESS	0x0
5906c223761SKevin Barnett 
5916c223761SKevin Barnett #define PQI_IQ_PROPERTY_IS_AIO_QUEUE	0x1
5926c223761SKevin Barnett 
5936c223761SKevin Barnett #define PQI_GENERAL_ADMIN_IU_LENGTH		0x3c
5946c223761SKevin Barnett #define PQI_PROTOCOL_SOP			0x0
5956c223761SKevin Barnett 
5966c223761SKevin Barnett #define PQI_DATA_IN_OUT_GOOD					0x0
5976c223761SKevin Barnett #define PQI_DATA_IN_OUT_UNDERFLOW				0x1
5986c223761SKevin Barnett #define PQI_DATA_IN_OUT_BUFFER_ERROR				0x40
5996c223761SKevin Barnett #define PQI_DATA_IN_OUT_BUFFER_OVERFLOW				0x41
6006c223761SKevin Barnett #define PQI_DATA_IN_OUT_BUFFER_OVERFLOW_DESCRIPTOR_AREA		0x42
6016c223761SKevin Barnett #define PQI_DATA_IN_OUT_BUFFER_OVERFLOW_BRIDGE			0x43
6026c223761SKevin Barnett #define PQI_DATA_IN_OUT_PCIE_FABRIC_ERROR			0x60
6036c223761SKevin Barnett #define PQI_DATA_IN_OUT_PCIE_COMPLETION_TIMEOUT			0x61
6046c223761SKevin Barnett #define PQI_DATA_IN_OUT_PCIE_COMPLETER_ABORT_RECEIVED		0x62
6056c223761SKevin Barnett #define PQI_DATA_IN_OUT_PCIE_UNSUPPORTED_REQUEST_RECEIVED	0x63
6066c223761SKevin Barnett #define PQI_DATA_IN_OUT_PCIE_ECRC_CHECK_FAILED			0x64
6076c223761SKevin Barnett #define PQI_DATA_IN_OUT_PCIE_UNSUPPORTED_REQUEST		0x65
6086c223761SKevin Barnett #define PQI_DATA_IN_OUT_PCIE_ACS_VIOLATION			0x66
6096c223761SKevin Barnett #define PQI_DATA_IN_OUT_PCIE_TLP_PREFIX_BLOCKED			0x67
6106c223761SKevin Barnett #define PQI_DATA_IN_OUT_PCIE_POISONED_MEMORY_READ		0x6F
6116c223761SKevin Barnett #define PQI_DATA_IN_OUT_ERROR					0xf0
6126c223761SKevin Barnett #define PQI_DATA_IN_OUT_PROTOCOL_ERROR				0xf1
6136c223761SKevin Barnett #define PQI_DATA_IN_OUT_HARDWARE_ERROR				0xf2
6146c223761SKevin Barnett #define PQI_DATA_IN_OUT_UNSOLICITED_ABORT			0xf3
6156c223761SKevin Barnett #define PQI_DATA_IN_OUT_ABORTED					0xf4
6166c223761SKevin Barnett #define PQI_DATA_IN_OUT_TIMEOUT					0xf5
6176c223761SKevin Barnett 
6186c223761SKevin Barnett #define CISS_CMD_STATUS_SUCCESS			0x0
6196c223761SKevin Barnett #define CISS_CMD_STATUS_TARGET_STATUS		0x1
6206c223761SKevin Barnett #define CISS_CMD_STATUS_DATA_UNDERRUN		0x2
6216c223761SKevin Barnett #define CISS_CMD_STATUS_DATA_OVERRUN		0x3
6226c223761SKevin Barnett #define CISS_CMD_STATUS_INVALID			0x4
6236c223761SKevin Barnett #define CISS_CMD_STATUS_PROTOCOL_ERROR		0x5
6246c223761SKevin Barnett #define CISS_CMD_STATUS_HARDWARE_ERROR		0x6
6256c223761SKevin Barnett #define CISS_CMD_STATUS_CONNECTION_LOST		0x7
6266c223761SKevin Barnett #define CISS_CMD_STATUS_ABORTED			0x8
6276c223761SKevin Barnett #define CISS_CMD_STATUS_ABORT_FAILED		0x9
6286c223761SKevin Barnett #define CISS_CMD_STATUS_UNSOLICITED_ABORT	0xa
6296c223761SKevin Barnett #define CISS_CMD_STATUS_TIMEOUT			0xb
6306c223761SKevin Barnett #define CISS_CMD_STATUS_UNABORTABLE		0xc
6316c223761SKevin Barnett #define CISS_CMD_STATUS_TMF			0xd
6326c223761SKevin Barnett #define CISS_CMD_STATUS_AIO_DISABLED		0xe
6336c223761SKevin Barnett 
63426b390abSKevin Barnett #define PQI_CMD_STATUS_ABORTED	CISS_CMD_STATUS_ABORTED
63526b390abSKevin Barnett 
6366c223761SKevin Barnett #define PQI_NUM_EVENT_QUEUE_ELEMENTS	32
6376c223761SKevin Barnett #define PQI_EVENT_OQ_ELEMENT_LENGTH	sizeof(struct pqi_event_response)
6386c223761SKevin Barnett 
6396c223761SKevin Barnett #define PQI_EVENT_TYPE_HOTPLUG			0x1
6406c223761SKevin Barnett #define PQI_EVENT_TYPE_HARDWARE			0x2
6416c223761SKevin Barnett #define PQI_EVENT_TYPE_PHYSICAL_DEVICE		0x4
6426c223761SKevin Barnett #define PQI_EVENT_TYPE_LOGICAL_DEVICE		0x5
6434fd22c13SMahesh Rajashekhara #define PQI_EVENT_TYPE_OFA			0xfb
6446c223761SKevin Barnett #define PQI_EVENT_TYPE_AIO_STATE_CHANGE		0xfd
6456c223761SKevin Barnett #define PQI_EVENT_TYPE_AIO_CONFIG_CHANGE	0xfe
6466c223761SKevin Barnett 
6476c223761SKevin Barnett #pragma pack()
6486c223761SKevin Barnett 
6496c223761SKevin Barnett #define PQI_ERROR_BUFFER_ELEMENT_LENGTH		\
6506c223761SKevin Barnett 	sizeof(struct pqi_raid_error_info)
6516c223761SKevin Barnett 
6526c223761SKevin Barnett /* these values are based on our implementation */
6536c223761SKevin Barnett #define PQI_ADMIN_IQ_NUM_ELEMENTS		8
6546c223761SKevin Barnett #define PQI_ADMIN_OQ_NUM_ELEMENTS		20
6556c223761SKevin Barnett #define PQI_ADMIN_IQ_ELEMENT_LENGTH		64
6566c223761SKevin Barnett #define PQI_ADMIN_OQ_ELEMENT_LENGTH		64
6576c223761SKevin Barnett 
6586c223761SKevin Barnett #define PQI_OPERATIONAL_IQ_ELEMENT_LENGTH	128
6596c223761SKevin Barnett #define PQI_OPERATIONAL_OQ_ELEMENT_LENGTH	16
6606c223761SKevin Barnett 
6616c223761SKevin Barnett #define PQI_MIN_MSIX_VECTORS		1
6626c223761SKevin Barnett #define PQI_MAX_MSIX_VECTORS		64
6636c223761SKevin Barnett 
6646c223761SKevin Barnett /* these values are defined by the PQI spec */
6656c223761SKevin Barnett #define PQI_MAX_NUM_ELEMENTS_ADMIN_QUEUE	255
6666c223761SKevin Barnett #define PQI_MAX_NUM_ELEMENTS_OPERATIONAL_QUEUE	65535
6672708a256SKevin Barnett 
6686c223761SKevin Barnett #define PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT	64
6696c223761SKevin Barnett #define PQI_QUEUE_ELEMENT_LENGTH_ALIGNMENT	16
6706c223761SKevin Barnett #define PQI_ADMIN_INDEX_ALIGNMENT		64
6716c223761SKevin Barnett #define PQI_OPERATIONAL_INDEX_ALIGNMENT		4
6726c223761SKevin Barnett 
6736c223761SKevin Barnett #define PQI_MIN_OPERATIONAL_QUEUE_ID		1
6746c223761SKevin Barnett #define PQI_MAX_OPERATIONAL_QUEUE_ID		65535
6756c223761SKevin Barnett 
6766c223761SKevin Barnett #define PQI_AIO_SERV_RESPONSE_COMPLETE		0
6776c223761SKevin Barnett #define PQI_AIO_SERV_RESPONSE_FAILURE		1
6786c223761SKevin Barnett #define PQI_AIO_SERV_RESPONSE_TMF_COMPLETE	2
6796c223761SKevin Barnett #define PQI_AIO_SERV_RESPONSE_TMF_SUCCEEDED	3
6806c223761SKevin Barnett #define PQI_AIO_SERV_RESPONSE_TMF_REJECTED	4
6816c223761SKevin Barnett #define PQI_AIO_SERV_RESPONSE_TMF_INCORRECT_LUN	5
6826c223761SKevin Barnett 
6836c223761SKevin Barnett #define PQI_AIO_STATUS_IO_ERROR			0x1
6846c223761SKevin Barnett #define PQI_AIO_STATUS_IO_ABORTED		0x2
6856c223761SKevin Barnett #define PQI_AIO_STATUS_NO_PATH_TO_DEVICE	0x3
6866c223761SKevin Barnett #define PQI_AIO_STATUS_INVALID_DEVICE		0x4
6876c223761SKevin Barnett #define PQI_AIO_STATUS_AIO_PATH_DISABLED	0xe
6886c223761SKevin Barnett #define PQI_AIO_STATUS_UNDERRUN			0x51
6896c223761SKevin Barnett #define PQI_AIO_STATUS_OVERRUN			0x75
6906c223761SKevin Barnett 
6916c223761SKevin Barnett typedef u32 pqi_index_t;
6926c223761SKevin Barnett 
6936c223761SKevin Barnett /* SOP data direction flags */
6946c223761SKevin Barnett #define SOP_NO_DIRECTION_FLAG	0
6956c223761SKevin Barnett #define SOP_WRITE_FLAG		1	/* host writes data to Data-Out */
6966c223761SKevin Barnett 					/* buffer */
6976c223761SKevin Barnett #define SOP_READ_FLAG		2	/* host receives data from Data-In */
6986c223761SKevin Barnett 					/* buffer */
6996c223761SKevin Barnett #define SOP_BIDIRECTIONAL	3	/* data is transferred from the */
7006c223761SKevin Barnett 					/* Data-Out buffer and data is */
7016c223761SKevin Barnett 					/* transferred to the Data-In buffer */
7026c223761SKevin Barnett 
7036c223761SKevin Barnett #define SOP_TASK_ATTRIBUTE_SIMPLE		0
7046c223761SKevin Barnett #define SOP_TASK_ATTRIBUTE_HEAD_OF_QUEUE	1
7056c223761SKevin Barnett #define SOP_TASK_ATTRIBUTE_ORDERED		2
7066c223761SKevin Barnett #define SOP_TASK_ATTRIBUTE_ACA			4
7076c223761SKevin Barnett 
708b17f0486SKevin Barnett #define SOP_TMF_COMPLETE		0x0
7093406384bSMahesh Rajashekhara #define SOP_TMF_REJECTED		0x4
710b17f0486SKevin Barnett #define SOP_TMF_FUNCTION_SUCCEEDED	0x8
7116c223761SKevin Barnett 
7126c223761SKevin Barnett /* additional CDB bytes usage field codes */
7136c223761SKevin Barnett #define SOP_ADDITIONAL_CDB_BYTES_0	0	/* 16-byte CDB */
7146c223761SKevin Barnett #define SOP_ADDITIONAL_CDB_BYTES_4	1	/* 20-byte CDB */
7156c223761SKevin Barnett #define SOP_ADDITIONAL_CDB_BYTES_8	2	/* 24-byte CDB */
7166c223761SKevin Barnett #define SOP_ADDITIONAL_CDB_BYTES_12	3	/* 28-byte CDB */
7176c223761SKevin Barnett #define SOP_ADDITIONAL_CDB_BYTES_16	4	/* 32-byte CDB */
7186c223761SKevin Barnett 
7196c223761SKevin Barnett /*
7206c223761SKevin Barnett  * The purpose of this structure is to obtain proper alignment of objects in
7216c223761SKevin Barnett  * an admin queue pair.
7226c223761SKevin Barnett  */
7236c223761SKevin Barnett struct pqi_admin_queues_aligned {
7246c223761SKevin Barnett 	__aligned(PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT)
7256c223761SKevin Barnett 		u8	iq_element_array[PQI_ADMIN_IQ_ELEMENT_LENGTH]
7266c223761SKevin Barnett 					[PQI_ADMIN_IQ_NUM_ELEMENTS];
7276c223761SKevin Barnett 	__aligned(PQI_QUEUE_ELEMENT_ARRAY_ALIGNMENT)
7286c223761SKevin Barnett 		u8	oq_element_array[PQI_ADMIN_OQ_ELEMENT_LENGTH]
7296c223761SKevin Barnett 					[PQI_ADMIN_OQ_NUM_ELEMENTS];
7306c223761SKevin Barnett 	__aligned(PQI_ADMIN_INDEX_ALIGNMENT) pqi_index_t iq_ci;
7316c223761SKevin Barnett 	__aligned(PQI_ADMIN_INDEX_ALIGNMENT) pqi_index_t oq_pi;
7326c223761SKevin Barnett };
7336c223761SKevin Barnett 
7346c223761SKevin Barnett struct pqi_admin_queues {
7356c223761SKevin Barnett 	void		*iq_element_array;
7366c223761SKevin Barnett 	void		*oq_element_array;
737583891c9SKevin Barnett 	pqi_index_t __iomem *iq_ci;
738dac12fbcSKevin Barnett 	pqi_index_t __iomem *oq_pi;
7396c223761SKevin Barnett 	dma_addr_t	iq_element_array_bus_addr;
7406c223761SKevin Barnett 	dma_addr_t	oq_element_array_bus_addr;
7416c223761SKevin Barnett 	dma_addr_t	iq_ci_bus_addr;
7426c223761SKevin Barnett 	dma_addr_t	oq_pi_bus_addr;
7436c223761SKevin Barnett 	__le32 __iomem	*iq_pi;
7446c223761SKevin Barnett 	pqi_index_t	iq_pi_copy;
7456c223761SKevin Barnett 	__le32 __iomem	*oq_ci;
7466c223761SKevin Barnett 	pqi_index_t	oq_ci_copy;
7476c223761SKevin Barnett 	struct task_struct *task;
7486c223761SKevin Barnett 	u16		int_msg_num;
7496c223761SKevin Barnett };
7506c223761SKevin Barnett 
7516c223761SKevin Barnett struct pqi_queue_group {
7526c223761SKevin Barnett 	struct pqi_ctrl_info *ctrl_info;	/* backpointer */
7536c223761SKevin Barnett 	u16		iq_id[2];
7546c223761SKevin Barnett 	u16		oq_id;
7556c223761SKevin Barnett 	u16		int_msg_num;
7566c223761SKevin Barnett 	void		*iq_element_array[2];
7576c223761SKevin Barnett 	void		*oq_element_array;
7586c223761SKevin Barnett 	dma_addr_t	iq_element_array_bus_addr[2];
7596c223761SKevin Barnett 	dma_addr_t	oq_element_array_bus_addr;
7606c223761SKevin Barnett 	__le32 __iomem	*iq_pi[2];
7616c223761SKevin Barnett 	pqi_index_t	iq_pi_copy[2];
762dac12fbcSKevin Barnett 	pqi_index_t __iomem *iq_ci[2];
763dac12fbcSKevin Barnett 	pqi_index_t __iomem *oq_pi;
7646c223761SKevin Barnett 	dma_addr_t	iq_ci_bus_addr[2];
7656c223761SKevin Barnett 	dma_addr_t	oq_pi_bus_addr;
7666c223761SKevin Barnett 	__le32 __iomem	*oq_ci;
7676c223761SKevin Barnett 	pqi_index_t	oq_ci_copy;
7686c223761SKevin Barnett 	spinlock_t	submit_lock[2];	/* protect submission queue */
7696c223761SKevin Barnett 	struct list_head request_list[2];
7706c223761SKevin Barnett };
7716c223761SKevin Barnett 
7726c223761SKevin Barnett struct pqi_event_queue {
7736c223761SKevin Barnett 	u16		oq_id;
7746c223761SKevin Barnett 	u16		int_msg_num;
7756c223761SKevin Barnett 	void		*oq_element_array;
776dac12fbcSKevin Barnett 	pqi_index_t __iomem *oq_pi;
7776c223761SKevin Barnett 	dma_addr_t	oq_element_array_bus_addr;
7786c223761SKevin Barnett 	dma_addr_t	oq_pi_bus_addr;
7796c223761SKevin Barnett 	__le32 __iomem	*oq_ci;
7806c223761SKevin Barnett 	pqi_index_t	oq_ci_copy;
7816c223761SKevin Barnett };
7826c223761SKevin Barnett 
7836c223761SKevin Barnett #define PQI_DEFAULT_QUEUE_GROUP		0
7846c223761SKevin Barnett #define PQI_MAX_QUEUE_GROUPS		PQI_MAX_MSIX_VECTORS
7856c223761SKevin Barnett 
7866c223761SKevin Barnett struct pqi_encryption_info {
7876c223761SKevin Barnett 	u16	data_encryption_key_index;
7886c223761SKevin Barnett 	u32	encrypt_tweak_lower;
7896c223761SKevin Barnett 	u32	encrypt_tweak_upper;
7906c223761SKevin Barnett };
7916c223761SKevin Barnett 
79298f87667SKevin Barnett #pragma pack(1)
79398f87667SKevin Barnett 
79498f87667SKevin Barnett #define PQI_CONFIG_TABLE_SIGNATURE	"CFGTABLE"
79598f87667SKevin Barnett #define PQI_CONFIG_TABLE_MAX_LENGTH	((u16)~0)
79698f87667SKevin Barnett 
79798f87667SKevin Barnett /* configuration table section IDs */
798b212c251SKevin Barnett #define PQI_CONFIG_TABLE_ALL_SECTIONS			(-1)
79998f87667SKevin Barnett #define PQI_CONFIG_TABLE_SECTION_GENERAL_INFO		0
80098f87667SKevin Barnett #define PQI_CONFIG_TABLE_SECTION_FIRMWARE_FEATURES	1
80198f87667SKevin Barnett #define PQI_CONFIG_TABLE_SECTION_FIRMWARE_ERRATA	2
80298f87667SKevin Barnett #define PQI_CONFIG_TABLE_SECTION_DEBUG			3
80398f87667SKevin Barnett #define PQI_CONFIG_TABLE_SECTION_HEARTBEAT		4
8044fd22c13SMahesh Rajashekhara #define PQI_CONFIG_TABLE_SECTION_SOFT_RESET		5
80598f87667SKevin Barnett 
80698f87667SKevin Barnett struct pqi_config_table {
80798f87667SKevin Barnett 	u8	signature[8];		/* "CFGTABLE" */
80898f87667SKevin Barnett 	__le32	first_section_offset;	/* offset in bytes from the base */
80998f87667SKevin Barnett 					/* address of this table to the */
81098f87667SKevin Barnett 					/* first section */
81198f87667SKevin Barnett };
81298f87667SKevin Barnett 
81398f87667SKevin Barnett struct pqi_config_table_section_header {
81498f87667SKevin Barnett 	__le16	section_id;		/* as defined by the */
81598f87667SKevin Barnett 					/* PQI_CONFIG_TABLE_SECTION_* */
81698f87667SKevin Barnett 					/* manifest constants above */
81798f87667SKevin Barnett 	__le16	next_section_offset;	/* offset in bytes from base */
81898f87667SKevin Barnett 					/* address of the table of the */
81998f87667SKevin Barnett 					/* next section or 0 if last entry */
82098f87667SKevin Barnett };
82198f87667SKevin Barnett 
82298f87667SKevin Barnett struct pqi_config_table_general_info {
82398f87667SKevin Barnett 	struct pqi_config_table_section_header header;
82498f87667SKevin Barnett 	__le32	section_length;		/* size of this section in bytes */
82598f87667SKevin Barnett 					/* including the section header */
82698f87667SKevin Barnett 	__le32	max_outstanding_requests;	/* max. outstanding */
82798f87667SKevin Barnett 						/* commands supported by */
82898f87667SKevin Barnett 						/* the controller */
82998f87667SKevin Barnett 	__le32	max_sg_size;		/* max. transfer size of a single */
83098f87667SKevin Barnett 					/* command */
83198f87667SKevin Barnett 	__le32	max_sg_per_request;	/* max. number of scatter-gather */
83298f87667SKevin Barnett 					/* entries supported in a single */
83398f87667SKevin Barnett 					/* command */
83498f87667SKevin Barnett };
83598f87667SKevin Barnett 
836b212c251SKevin Barnett struct pqi_config_table_firmware_features {
837b212c251SKevin Barnett 	struct pqi_config_table_section_header header;
838b212c251SKevin Barnett 	__le16	num_elements;
839b212c251SKevin Barnett 	u8	features_supported[];
840b212c251SKevin Barnett /*	u8	features_requested_by_host[]; */
841b212c251SKevin Barnett /*	u8	features_enabled[]; */
842f6cc2a77SKevin Barnett /* The 2 fields below are only valid if the MAX_KNOWN_FEATURE bit is set. */
843f6cc2a77SKevin Barnett /*	__le16	firmware_max_known_feature; */
844f6cc2a77SKevin Barnett /*	__le16	host_max_known_feature; */
845b212c251SKevin Barnett };
846b212c251SKevin Barnett 
847b212c251SKevin Barnett #define PQI_FIRMWARE_FEATURE_OFA				0
848b212c251SKevin Barnett #define PQI_FIRMWARE_FEATURE_SMP				1
849f6cc2a77SKevin Barnett #define PQI_FIRMWARE_FEATURE_MAX_KNOWN_FEATURE			2
850f6cc2a77SKevin Barnett #define PQI_FIRMWARE_FEATURE_RAID_0_READ_BYPASS			3
851f6cc2a77SKevin Barnett #define PQI_FIRMWARE_FEATURE_RAID_1_READ_BYPASS			4
852f6cc2a77SKevin Barnett #define PQI_FIRMWARE_FEATURE_RAID_5_READ_BYPASS			5
853f6cc2a77SKevin Barnett #define PQI_FIRMWARE_FEATURE_RAID_6_READ_BYPASS			6
854f6cc2a77SKevin Barnett #define PQI_FIRMWARE_FEATURE_RAID_0_WRITE_BYPASS		7
855f6cc2a77SKevin Barnett #define PQI_FIRMWARE_FEATURE_RAID_1_WRITE_BYPASS		8
856f6cc2a77SKevin Barnett #define PQI_FIRMWARE_FEATURE_RAID_5_WRITE_BYPASS		9
857f6cc2a77SKevin Barnett #define PQI_FIRMWARE_FEATURE_RAID_6_WRITE_BYPASS		10
8584fd22c13SMahesh Rajashekhara #define PQI_FIRMWARE_FEATURE_SOFT_RESET_HANDSHAKE		11
859f6cc2a77SKevin Barnett #define PQI_FIRMWARE_FEATURE_UNIQUE_SATA_WWN			12
86021432010Skoshyaji #define PQI_FIRMWARE_FEATURE_RAID_IU_TIMEOUT			13
861c2922f17SMurthy Bhat #define PQI_FIRMWARE_FEATURE_TMF_IU_TIMEOUT			14
862f6cc2a77SKevin Barnett #define PQI_FIRMWARE_FEATURE_RAID_BYPASS_ON_ENCRYPTED_NVME	15
8637a84a821SKevin Barnett #define PQI_FIRMWARE_FEATURE_UNIQUE_WWID_IN_REPORT_PHYS_LUN	16
8645d1f03e6SMurthy Bhat #define PQI_FIRMWARE_FEATURE_FW_TRIAGE				17
86528ca6d87SMike McGowen #define PQI_FIRMWARE_FEATURE_RPL_EXTENDED_FORMAT_4_5		18
86628ca6d87SMike McGowen #define PQI_FIRMWARE_FEATURE_MAXIMUM				18
867b212c251SKevin Barnett 
86898f87667SKevin Barnett struct pqi_config_table_debug {
86998f87667SKevin Barnett 	struct pqi_config_table_section_header header;
87098f87667SKevin Barnett 	__le32	scratchpad;
87198f87667SKevin Barnett };
87298f87667SKevin Barnett 
87398f87667SKevin Barnett struct pqi_config_table_heartbeat {
87498f87667SKevin Barnett 	struct pqi_config_table_section_header header;
87598f87667SKevin Barnett 	__le32	heartbeat_counter;
87698f87667SKevin Barnett };
87798f87667SKevin Barnett 
8784fd22c13SMahesh Rajashekhara struct pqi_config_table_soft_reset {
8794fd22c13SMahesh Rajashekhara 	struct pqi_config_table_section_header header;
8804fd22c13SMahesh Rajashekhara 	u8 soft_reset_status;
8814fd22c13SMahesh Rajashekhara };
8824fd22c13SMahesh Rajashekhara 
8834fd22c13SMahesh Rajashekhara #define PQI_SOFT_RESET_INITIATE		0x1
8844fd22c13SMahesh Rajashekhara #define PQI_SOFT_RESET_ABORT		0x2
8854fd22c13SMahesh Rajashekhara 
8864fd22c13SMahesh Rajashekhara enum pqi_soft_reset_status {
8874fd22c13SMahesh Rajashekhara 	RESET_INITIATE_FIRMWARE,
8884fd22c13SMahesh Rajashekhara 	RESET_INITIATE_DRIVER,
8894fd22c13SMahesh Rajashekhara 	RESET_ABORT,
8904fd22c13SMahesh Rajashekhara 	RESET_NORESPONSE,
8914fd22c13SMahesh Rajashekhara 	RESET_TIMEDOUT
8924fd22c13SMahesh Rajashekhara };
8934fd22c13SMahesh Rajashekhara 
894336b6819SKevin Barnett union pqi_reset_register {
895336b6819SKevin Barnett 	struct {
896336b6819SKevin Barnett 		u32	reset_type : 3;
897336b6819SKevin Barnett 		u32	reserved : 2;
898336b6819SKevin Barnett 		u32	reset_action : 3;
899336b6819SKevin Barnett 		u32	hold_in_pd1 : 1;
900336b6819SKevin Barnett 		u32	reserved2 : 23;
901336b6819SKevin Barnett 	} bits;
902336b6819SKevin Barnett 	u32	all_bits;
903336b6819SKevin Barnett };
904336b6819SKevin Barnett 
905336b6819SKevin Barnett #define PQI_RESET_ACTION_RESET		0x1
906336b6819SKevin Barnett 
907336b6819SKevin Barnett #define PQI_RESET_TYPE_NO_RESET		0x0
908336b6819SKevin Barnett #define PQI_RESET_TYPE_SOFT_RESET	0x1
909336b6819SKevin Barnett #define PQI_RESET_TYPE_FIRM_RESET	0x2
910336b6819SKevin Barnett #define PQI_RESET_TYPE_HARD_RESET	0x3
911336b6819SKevin Barnett 
912336b6819SKevin Barnett #define PQI_RESET_ACTION_COMPLETED	0x2
913336b6819SKevin Barnett 
914336b6819SKevin Barnett #define PQI_RESET_POLL_INTERVAL_MSECS	100
915336b6819SKevin Barnett 
9166c223761SKevin Barnett #define PQI_MAX_OUTSTANDING_REQUESTS		((u32)~0)
917d727a776SKevin Barnett #define PQI_MAX_OUTSTANDING_REQUESTS_KDUMP	32
918eeee4107SYadan Fan #define PQI_MAX_TRANSFER_SIZE			(1024U * 1024U)
919d727a776SKevin Barnett #define PQI_MAX_TRANSFER_SIZE_KDUMP		(512 * 1024U)
9206c223761SKevin Barnett 
9216c223761SKevin Barnett #define RAID_MAP_MAX_ENTRIES		1024
9226c223761SKevin Barnett 
9236c223761SKevin Barnett #define PQI_PHYSICAL_DEVICE_BUS		0
9246c223761SKevin Barnett #define PQI_RAID_VOLUME_BUS		1
9256c223761SKevin Barnett #define PQI_HBA_BUS			2
926bd10cf0bSKevin Barnett #define PQI_EXTERNAL_RAID_VOLUME_BUS	3
927bd10cf0bSKevin Barnett #define PQI_MAX_BUS			PQI_EXTERNAL_RAID_VOLUME_BUS
928522bc026SDave Carroll #define PQI_VSEP_CISS_BTL		379
9296c223761SKevin Barnett 
9306c223761SKevin Barnett struct report_lun_header {
9316c223761SKevin Barnett 	__be32	list_length;
932694c5d5bSKevin Barnett 	u8	flags;
9336c223761SKevin Barnett 	u8	reserved[3];
9346c223761SKevin Barnett };
9356c223761SKevin Barnett 
936694c5d5bSKevin Barnett /* for flags field of struct report_lun_header */
937694c5d5bSKevin Barnett #define CISS_REPORT_LOG_FLAG_UNIQUE_LUN_ID	(1 << 0)
938694c5d5bSKevin Barnett #define CISS_REPORT_LOG_FLAG_QUEUE_DEPTH	(1 << 5)
939694c5d5bSKevin Barnett #define CISS_REPORT_LOG_FLAG_DRIVE_TYPE_MIX	(1 << 6)
940694c5d5bSKevin Barnett 
94128ca6d87SMike McGowen #define CISS_REPORT_PHYS_FLAG_EXTENDED_FORMAT_2		0x2
94228ca6d87SMike McGowen #define CISS_REPORT_PHYS_FLAG_EXTENDED_FORMAT_4		0x4
94328ca6d87SMike McGowen #define CISS_REPORT_PHYS_FLAG_EXTENDED_FORMAT_MASK	0xf
944694c5d5bSKevin Barnett 
94528ca6d87SMike McGowen struct report_log_lun {
9466c223761SKevin Barnett 	u8	lunid[8];
9476c223761SKevin Barnett 	u8	volume_id[16];
9486c223761SKevin Barnett };
9496c223761SKevin Barnett 
95028ca6d87SMike McGowen struct report_log_lun_list {
9516c223761SKevin Barnett 	struct report_lun_header header;
95228ca6d87SMike McGowen 	struct report_log_lun lun_entries[1];
9536c223761SKevin Barnett };
9546c223761SKevin Barnett 
95528ca6d87SMike McGowen struct report_phys_lun_8byte_wwid {
9566c223761SKevin Barnett 	u8	lunid[8];
9576c223761SKevin Barnett 	__be64	wwid;
9586c223761SKevin Barnett 	u8	device_type;
9596c223761SKevin Barnett 	u8	device_flags;
9606c223761SKevin Barnett 	u8	lun_count;	/* number of LUNs in a multi-LUN device */
9616c223761SKevin Barnett 	u8	redundant_paths;
9626c223761SKevin Barnett 	u32	aio_handle;
9636c223761SKevin Barnett };
9646c223761SKevin Barnett 
96528ca6d87SMike McGowen struct report_phys_lun_16byte_wwid {
96628ca6d87SMike McGowen 	u8	lunid[8];
96728ca6d87SMike McGowen 	u8	wwid[16];
96828ca6d87SMike McGowen 	u8	device_type;
96928ca6d87SMike McGowen 	u8	device_flags;
97028ca6d87SMike McGowen 	u8	lun_count;	/* number of LUNs in a multi-LUN device */
97128ca6d87SMike McGowen 	u8	redundant_paths;
97228ca6d87SMike McGowen 	u32	aio_handle;
97328ca6d87SMike McGowen };
97428ca6d87SMike McGowen 
9756c223761SKevin Barnett /* for device_flags field of struct report_phys_lun_extended_entry */
976694c5d5bSKevin Barnett #define CISS_REPORT_PHYS_DEV_FLAG_AIO_ENABLED	0x8
9776c223761SKevin Barnett 
97828ca6d87SMike McGowen struct report_phys_lun_8byte_wwid_list {
9796c223761SKevin Barnett 	struct report_lun_header header;
98028ca6d87SMike McGowen 	struct report_phys_lun_8byte_wwid lun_entries[1];
98128ca6d87SMike McGowen };
98228ca6d87SMike McGowen 
98328ca6d87SMike McGowen struct report_phys_lun_16byte_wwid_list {
98428ca6d87SMike McGowen 	struct report_lun_header header;
98528ca6d87SMike McGowen 	struct report_phys_lun_16byte_wwid lun_entries[1];
9866c223761SKevin Barnett };
9876c223761SKevin Barnett 
9886c223761SKevin Barnett struct raid_map_disk_data {
9896c223761SKevin Barnett 	u32	aio_handle;
9906c223761SKevin Barnett 	u8	xor_mult[2];
9916c223761SKevin Barnett 	u8	reserved[2];
9926c223761SKevin Barnett };
9936c223761SKevin Barnett 
994694c5d5bSKevin Barnett /* for flags field of RAID map */
9956c223761SKevin Barnett #define RAID_MAP_ENCRYPTION_ENABLED	0x1
9966c223761SKevin Barnett 
9976c223761SKevin Barnett struct raid_map {
9986c223761SKevin Barnett 	__le32	structure_size;		/* size of entire structure in bytes */
9996c223761SKevin Barnett 	__le32	volume_blk_size;	/* bytes / block in the volume */
10006c223761SKevin Barnett 	__le64	volume_blk_cnt;		/* logical blocks on the volume */
10016c223761SKevin Barnett 	u8	phys_blk_shift;		/* shift factor to convert between */
10026c223761SKevin Barnett 					/* units of logical blocks and */
10036c223761SKevin Barnett 					/* physical disk blocks */
10046c223761SKevin Barnett 	u8	parity_rotation_shift;	/* shift factor to convert between */
10056c223761SKevin Barnett 					/* units of logical stripes and */
10066c223761SKevin Barnett 					/* physical stripes */
10076c223761SKevin Barnett 	__le16	strip_size;		/* blocks used on each disk / stripe */
10086c223761SKevin Barnett 	__le64	disk_starting_blk;	/* first disk block used in volume */
10096c223761SKevin Barnett 	__le64	disk_blk_cnt;		/* disk blocks used by volume / disk */
10106c223761SKevin Barnett 	__le16	data_disks_per_row;	/* data disk entries / row in the map */
10116c223761SKevin Barnett 	__le16	metadata_disks_per_row;	/* mirror/parity disk entries / row */
10126c223761SKevin Barnett 					/* in the map */
10136c223761SKevin Barnett 	__le16	row_cnt;		/* rows in each layout map */
10146c223761SKevin Barnett 	__le16	layout_map_count;	/* layout maps (1 map per */
10156c223761SKevin Barnett 					/* mirror parity group) */
10166c223761SKevin Barnett 	__le16	flags;
10176c223761SKevin Barnett 	__le16	data_encryption_key_index;
10186c223761SKevin Barnett 	u8	reserved[16];
10196c223761SKevin Barnett 	struct raid_map_disk_data disk_data[RAID_MAP_MAX_ENTRIES];
10206c223761SKevin Barnett };
10216c223761SKevin Barnett 
10226c223761SKevin Barnett #pragma pack()
10236c223761SKevin Barnett 
1024281a817fSDon Brace struct pqi_scsi_dev_raid_map_data {
1025281a817fSDon Brace 	bool	is_write;
1026281a817fSDon Brace 	u8	raid_level;
1027281a817fSDon Brace 	u32	map_index;
1028281a817fSDon Brace 	u64	first_block;
1029281a817fSDon Brace 	u64	last_block;
1030281a817fSDon Brace 	u32	data_length;
1031281a817fSDon Brace 	u32	block_cnt;
1032281a817fSDon Brace 	u32	blocks_per_row;
1033281a817fSDon Brace 	u64	first_row;
1034281a817fSDon Brace 	u64	last_row;
1035281a817fSDon Brace 	u32	first_row_offset;
1036281a817fSDon Brace 	u32	last_row_offset;
1037281a817fSDon Brace 	u32	first_column;
1038281a817fSDon Brace 	u32	last_column;
1039281a817fSDon Brace 	u64	r5or6_first_row;
1040281a817fSDon Brace 	u64	r5or6_last_row;
1041281a817fSDon Brace 	u32	r5or6_first_row_offset;
1042281a817fSDon Brace 	u32	r5or6_last_row_offset;
1043281a817fSDon Brace 	u32	r5or6_first_column;
1044281a817fSDon Brace 	u32	r5or6_last_column;
1045281a817fSDon Brace 	u16	data_disks_per_row;
1046281a817fSDon Brace 	u32	total_disks_per_row;
1047281a817fSDon Brace 	u16	layout_map_count;
1048281a817fSDon Brace 	u32	stripesize;
1049281a817fSDon Brace 	u16	strip_size;
1050281a817fSDon Brace 	u32	first_group;
1051281a817fSDon Brace 	u32	last_group;
1052281a817fSDon Brace 	u32	map_row;
1053281a817fSDon Brace 	u32	aio_handle;
1054281a817fSDon Brace 	u64	disk_block;
1055281a817fSDon Brace 	u32	disk_block_cnt;
1056281a817fSDon Brace 	u8	cdb[16];
1057281a817fSDon Brace 	u8	cdb_length;
1058281a817fSDon Brace 
1059281a817fSDon Brace 	/* RAID 1 specific */
1060281a817fSDon Brace #define NUM_RAID1_MAP_ENTRIES	3
1061281a817fSDon Brace 	u32	num_it_nexus_entries;
1062281a817fSDon Brace 	u32	it_nexus[NUM_RAID1_MAP_ENTRIES];
1063281a817fSDon Brace 
1064583891c9SKevin Barnett 	/* RAID 5 / RAID 6 specific */
1065281a817fSDon Brace 	u32	p_parity_it_nexus;	/* aio_handle */
1066281a817fSDon Brace 	u32	q_parity_it_nexus;	/* aio_handle */
1067281a817fSDon Brace 	u8	xor_mult;
1068281a817fSDon Brace 	u64	row;
1069281a817fSDon Brace 	u64	stripe_lba;
1070281a817fSDon Brace 	u32	p_index;
1071281a817fSDon Brace 	u32	q_index;
1072281a817fSDon Brace };
1073281a817fSDon Brace 
10746c223761SKevin Barnett #define RAID_CTLR_LUNID		"\0\0\0\0\0\0\0\0"
10756c223761SKevin Barnett 
1076c7ffedb3SDon Brace #define NUM_STREAMS_PER_LUN	8
1077c7ffedb3SDon Brace 
1078c7ffedb3SDon Brace struct pqi_stream_data {
1079c7ffedb3SDon Brace 	u64	next_lba;
1080c7ffedb3SDon Brace 	u32	last_accessed;
1081c7ffedb3SDon Brace };
1082c7ffedb3SDon Brace 
10836c223761SKevin Barnett struct pqi_scsi_dev {
10846c223761SKevin Barnett 	int	devtype;		/* as reported by INQUIRY commmand */
10856c223761SKevin Barnett 	u8	device_type;		/* as reported by */
10866c223761SKevin Barnett 					/* BMIC_IDENTIFY_PHYSICAL_DEVICE */
10876c223761SKevin Barnett 					/* only valid for devtype = TYPE_DISK */
10886c223761SKevin Barnett 	int	bus;
10896c223761SKevin Barnett 	int	target;
10906c223761SKevin Barnett 	int	lun;
10916c223761SKevin Barnett 	u8	scsi3addr[8];
109228ca6d87SMike McGowen 	u8	wwid[16];
10936c223761SKevin Barnett 	u8	volume_id[16];
10946c223761SKevin Barnett 	u8	is_physical_device : 1;
1095bd10cf0bSKevin Barnett 	u8	is_external_raid_device : 1;
10963d46a59aSDon Brace 	u8	is_expander_smp_device : 1;
10976c223761SKevin Barnett 	u8	target_lun_valid : 1;
10986c223761SKevin Barnett 	u8	device_gone : 1;
10996c223761SKevin Barnett 	u8	new_device : 1;
11006c223761SKevin Barnett 	u8	keep_device : 1;
11016c223761SKevin Barnett 	u8	volume_offline : 1;
1102244ca45eSMahesh Rajashekhara 	u8	rescan : 1;
1103d4dc6aeaSKevin Barnett 	u8	ignore_device : 1;
1104376fb880SKevin Barnett 	bool	aio_enabled;		/* only valid for physical disks */
11051e46731eSMahesh Rajashekhara 	bool	in_remove;
11067561a7e4SKevin Barnett 	bool	device_offline;
11076c223761SKevin Barnett 	u8	vendor[8];		/* bytes 8-15 of inquiry data */
11086c223761SKevin Barnett 	u8	model[16];		/* bytes 16-31 of inquiry data */
11096c223761SKevin Barnett 	u64	sas_address;
11106c223761SKevin Barnett 	u8	raid_level;
11116c223761SKevin Barnett 	u16	queue_depth;		/* max. queue_depth for this device */
11126c223761SKevin Barnett 	u16	advertised_queue_depth;
11136c223761SKevin Barnett 	u32	aio_handle;
11146c223761SKevin Barnett 	u8	volume_status;
11156c223761SKevin Barnett 	u8	active_path_index;
11166c223761SKevin Barnett 	u8	path_map;
11176c223761SKevin Barnett 	u8	bay;
11182d2ad4bcSGilbert Wu 	u8	box_index;
11192d2ad4bcSGilbert Wu 	u8	phys_box_on_bus;
11202d2ad4bcSGilbert Wu 	u8	phy_connected_dev_type;
11216c223761SKevin Barnett 	u8	box[8];
11226c223761SKevin Barnett 	u16	phys_connector[8];
1123ec504b23SMurthy Bhat 	u8	phy_id;
11242a47834dSGilbert Wu 	u8	ncq_prio_enable;
11252a47834dSGilbert Wu 	u8	ncq_prio_support;
1126588a63feSKevin Barnett 	bool	raid_bypass_configured;	/* RAID bypass configured */
1127588a63feSKevin Barnett 	bool	raid_bypass_enabled;	/* RAID bypass enabled */
11287a012c23SDon Brace 	u32	next_bypass_group;
1129588a63feSKevin Barnett 	struct raid_map *raid_map;	/* RAID bypass map */
1130f6cc2a77SKevin Barnett 	u32	max_transfer_encrypted;
11316c223761SKevin Barnett 
11326c223761SKevin Barnett 	struct pqi_sas_port *sas_port;
11336c223761SKevin Barnett 	struct scsi_device *sdev;
11346c223761SKevin Barnett 
11356c223761SKevin Barnett 	struct list_head scsi_device_list_entry;
11366c223761SKevin Barnett 	struct list_head new_device_list_entry;
11376c223761SKevin Barnett 	struct list_head add_list_entry;
11386c223761SKevin Barnett 	struct list_head delete_list_entry;
11397561a7e4SKevin Barnett 
1140c7ffedb3SDon Brace 	struct pqi_stream_data stream_data[NUM_STREAMS_PER_LUN];
11417561a7e4SKevin Barnett 	atomic_t scsi_cmds_outstanding;
11428b664fefSKevin Barnett 	atomic_t raid_bypass_cnt;
11437a84a821SKevin Barnett 	u8	page_83_identifier[16];
11446c223761SKevin Barnett };
11456c223761SKevin Barnett 
11466c223761SKevin Barnett /* VPD inquiry pages */
11476c223761SKevin Barnett #define CISS_VPD_LV_DEVICE_GEOMETRY	0xc1	/* vendor-specific page */
1148588a63feSKevin Barnett #define CISS_VPD_LV_BYPASS_STATUS	0xc2	/* vendor-specific page */
11496c223761SKevin Barnett #define CISS_VPD_LV_STATUS		0xc3	/* vendor-specific page */
11506c223761SKevin Barnett 
11516c223761SKevin Barnett #define VPD_PAGE	(1 << 8)
11526c223761SKevin Barnett 
11536c223761SKevin Barnett #pragma pack(1)
11546c223761SKevin Barnett 
11556c223761SKevin Barnett /* structure for CISS_VPD_LV_STATUS */
11566c223761SKevin Barnett struct ciss_vpd_logical_volume_status {
11576c223761SKevin Barnett 	u8	peripheral_info;
11586c223761SKevin Barnett 	u8	page_code;
11596c223761SKevin Barnett 	u8	reserved;
11606c223761SKevin Barnett 	u8	page_length;
11616c223761SKevin Barnett 	u8	volume_status;
11626c223761SKevin Barnett 	u8	reserved2[3];
11636c223761SKevin Barnett 	__be32	flags;
11646c223761SKevin Barnett };
11656c223761SKevin Barnett 
11666c223761SKevin Barnett #pragma pack()
11676c223761SKevin Barnett 
11686c223761SKevin Barnett /* constants for volume_status field of ciss_vpd_logical_volume_status */
11696c223761SKevin Barnett #define CISS_LV_OK					0
11706c223761SKevin Barnett #define CISS_LV_FAILED					1
11716c223761SKevin Barnett #define CISS_LV_NOT_CONFIGURED				2
11726c223761SKevin Barnett #define CISS_LV_DEGRADED				3
11736c223761SKevin Barnett #define CISS_LV_READY_FOR_RECOVERY			4
11746c223761SKevin Barnett #define CISS_LV_UNDERGOING_RECOVERY			5
11756c223761SKevin Barnett #define CISS_LV_WRONG_PHYSICAL_DRIVE_REPLACED		6
11766c223761SKevin Barnett #define CISS_LV_PHYSICAL_DRIVE_CONNECTION_PROBLEM	7
11776c223761SKevin Barnett #define CISS_LV_HARDWARE_OVERHEATING			8
11786c223761SKevin Barnett #define CISS_LV_HARDWARE_HAS_OVERHEATED			9
11796c223761SKevin Barnett #define CISS_LV_UNDERGOING_EXPANSION			10
11806c223761SKevin Barnett #define CISS_LV_NOT_AVAILABLE				11
11816c223761SKevin Barnett #define CISS_LV_QUEUED_FOR_EXPANSION			12
11826c223761SKevin Barnett #define CISS_LV_DISABLED_SCSI_ID_CONFLICT		13
11836c223761SKevin Barnett #define CISS_LV_EJECTED					14
11846c223761SKevin Barnett #define CISS_LV_UNDERGOING_ERASE			15
11856c223761SKevin Barnett /* state 16 not used */
11866c223761SKevin Barnett #define CISS_LV_READY_FOR_PREDICTIVE_SPARE_REBUILD	17
11876c223761SKevin Barnett #define CISS_LV_UNDERGOING_RPI				18
11886c223761SKevin Barnett #define CISS_LV_PENDING_RPI				19
11896c223761SKevin Barnett #define CISS_LV_ENCRYPTED_NO_KEY			20
11906c223761SKevin Barnett /* state 21 not used */
11916c223761SKevin Barnett #define CISS_LV_UNDERGOING_ENCRYPTION			22
11926c223761SKevin Barnett #define CISS_LV_UNDERGOING_ENCRYPTION_REKEYING		23
11936c223761SKevin Barnett #define CISS_LV_ENCRYPTED_IN_NON_ENCRYPTED_CONTROLLER	24
11946c223761SKevin Barnett #define CISS_LV_PENDING_ENCRYPTION			25
11956c223761SKevin Barnett #define CISS_LV_PENDING_ENCRYPTION_REKEYING		26
11966c223761SKevin Barnett #define CISS_LV_NOT_SUPPORTED				27
11976c223761SKevin Barnett #define CISS_LV_STATUS_UNAVAILABLE			255
11986c223761SKevin Barnett 
11996c223761SKevin Barnett /* constants for flags field of ciss_vpd_logical_volume_status */
12006c223761SKevin Barnett #define CISS_LV_FLAGS_NO_HOST_IO	0x1	/* volume not available for */
12016c223761SKevin Barnett 						/* host I/O */
12026c223761SKevin Barnett 
12036c223761SKevin Barnett /* for SAS hosts and SAS expanders */
12046c223761SKevin Barnett struct pqi_sas_node {
12056c223761SKevin Barnett 	struct device *parent_dev;
12066c223761SKevin Barnett 	struct list_head port_list_head;
12076c223761SKevin Barnett };
12086c223761SKevin Barnett 
12096c223761SKevin Barnett struct pqi_sas_port {
12106c223761SKevin Barnett 	struct list_head port_list_entry;
12116c223761SKevin Barnett 	u64	sas_address;
12123d46a59aSDon Brace 	struct pqi_scsi_dev *device;
12136c223761SKevin Barnett 	struct sas_port *port;
12146c223761SKevin Barnett 	int	next_phy_index;
12156c223761SKevin Barnett 	struct list_head phy_list_head;
12166c223761SKevin Barnett 	struct pqi_sas_node *parent_node;
12176c223761SKevin Barnett 	struct sas_rphy *rphy;
12186c223761SKevin Barnett };
12196c223761SKevin Barnett 
12206c223761SKevin Barnett struct pqi_sas_phy {
12216c223761SKevin Barnett 	struct list_head phy_list_entry;
12226c223761SKevin Barnett 	struct sas_phy *phy;
12236c223761SKevin Barnett 	struct pqi_sas_port *parent_port;
12246c223761SKevin Barnett 	bool	added_to_port;
12256c223761SKevin Barnett };
12266c223761SKevin Barnett 
12276c223761SKevin Barnett struct pqi_io_request {
12286c223761SKevin Barnett 	atomic_t	refcount;
12296c223761SKevin Barnett 	u16		index;
12306c223761SKevin Barnett 	void (*io_complete_callback)(struct pqi_io_request *io_request,
12316c223761SKevin Barnett 		void *context);
12326c223761SKevin Barnett 	void		*context;
1233376fb880SKevin Barnett 	u8		raid_bypass : 1;
12346c223761SKevin Barnett 	int		status;
1235376fb880SKevin Barnett 	struct pqi_queue_group *queue_group;
12366c223761SKevin Barnett 	struct scsi_cmnd *scmd;
12376c223761SKevin Barnett 	void		*error_info;
12386c223761SKevin Barnett 	struct pqi_sg_descriptor *sg_chain_buffer;
12396c223761SKevin Barnett 	dma_addr_t	sg_chain_buffer_dma_handle;
12406c223761SKevin Barnett 	void		*iu;
12416c223761SKevin Barnett 	struct list_head request_list_entry;
12426c223761SKevin Barnett };
12436c223761SKevin Barnett 
12444fd22c13SMahesh Rajashekhara #define PQI_NUM_SUPPORTED_EVENTS	7
12456c223761SKevin Barnett 
12466c223761SKevin Barnett struct pqi_event {
12476c223761SKevin Barnett 	bool	pending;
12486c223761SKevin Barnett 	u8	event_type;
124906b41e0dSKevin Barnett 	u16	event_id;
125006b41e0dSKevin Barnett 	u32	additional_event_id;
12516c223761SKevin Barnett };
12526c223761SKevin Barnett 
12535e6429dfSKevin Barnett #define PQI_RESERVED_IO_SLOTS_LUN_RESET			1
12545e6429dfSKevin Barnett #define PQI_RESERVED_IO_SLOTS_EVENT_ACK			PQI_NUM_SUPPORTED_EVENTS
12555e6429dfSKevin Barnett #define PQI_RESERVED_IO_SLOTS_SYNCHRONOUS_REQUESTS	3
12565e6429dfSKevin Barnett #define PQI_RESERVED_IO_SLOTS				\
12575e6429dfSKevin Barnett 	(PQI_RESERVED_IO_SLOTS_LUN_RESET + PQI_RESERVED_IO_SLOTS_EVENT_ACK + \
12585e6429dfSKevin Barnett 	PQI_RESERVED_IO_SLOTS_SYNCHRONOUS_REQUESTS)
12595e6429dfSKevin Barnett 
12602708a256SKevin Barnett #define PQI_CTRL_PRODUCT_ID_GEN1	0
12612708a256SKevin Barnett #define PQI_CTRL_PRODUCT_ID_GEN2	7
12622708a256SKevin Barnett #define PQI_CTRL_PRODUCT_REVISION_A	0
12632708a256SKevin Barnett #define PQI_CTRL_PRODUCT_REVISION_B	1
12642708a256SKevin Barnett 
12656c223761SKevin Barnett struct pqi_ctrl_info {
12666c223761SKevin Barnett 	unsigned int	ctrl_id;
12676c223761SKevin Barnett 	struct pci_dev	*pci_dev;
1268598bef8dSKevin Barnett 	char		firmware_version[32];
12696d90615fSMurthy Bhat 	char		serial_number[17];
12706d90615fSMurthy Bhat 	char		model[17];
12716d90615fSMurthy Bhat 	char		vendor[9];
12722708a256SKevin Barnett 	u8		product_id;
12732708a256SKevin Barnett 	u8		product_revision;
12746c223761SKevin Barnett 	void __iomem	*iomem_base;
12756c223761SKevin Barnett 	struct pqi_ctrl_registers __iomem *registers;
12766c223761SKevin Barnett 	struct pqi_device_registers __iomem *pqi_registers;
12776c223761SKevin Barnett 	u32		max_sg_entries;
12786c223761SKevin Barnett 	u32		config_table_offset;
12796c223761SKevin Barnett 	u32		config_table_length;
12806c223761SKevin Barnett 	u16		max_inbound_queues;
12816c223761SKevin Barnett 	u16		max_elements_per_iq;
12826c223761SKevin Barnett 	u16		max_iq_element_length;
12836c223761SKevin Barnett 	u16		max_outbound_queues;
12846c223761SKevin Barnett 	u16		max_elements_per_oq;
12856c223761SKevin Barnett 	u16		max_oq_element_length;
12866c223761SKevin Barnett 	u32		max_transfer_size;
12876c223761SKevin Barnett 	u32		max_outstanding_requests;
12886c223761SKevin Barnett 	u32		max_io_slots;
12896c223761SKevin Barnett 	unsigned int	scsi_ml_can_queue;
12906c223761SKevin Barnett 	unsigned short	sg_tablesize;
12916c223761SKevin Barnett 	unsigned int	max_sectors;
12926c223761SKevin Barnett 	u32		error_buffer_length;
12936c223761SKevin Barnett 	void		*error_buffer;
12946c223761SKevin Barnett 	dma_addr_t	error_buffer_dma_handle;
12956c223761SKevin Barnett 	size_t		sg_chain_buffer_length;
12966c223761SKevin Barnett 	unsigned int	num_queue_groups;
1297061ef06aSKevin Barnett 	u16		max_hw_queue_index;
12986c223761SKevin Barnett 	u16		num_elements_per_iq;
12996c223761SKevin Barnett 	u16		num_elements_per_oq;
13006c223761SKevin Barnett 	u16		max_inbound_iu_length_per_firmware;
13016c223761SKevin Barnett 	u16		max_inbound_iu_length;
13026c223761SKevin Barnett 	unsigned int	max_sg_per_iu;
13036702d2c4SDon Brace 	unsigned int	max_sg_per_r56_iu;
13046c223761SKevin Barnett 	void		*admin_queue_memory_base;
13056c223761SKevin Barnett 	u32		admin_queue_memory_length;
13066c223761SKevin Barnett 	dma_addr_t	admin_queue_memory_base_dma_handle;
13076c223761SKevin Barnett 	void		*queue_memory_base;
13086c223761SKevin Barnett 	u32		queue_memory_length;
13096c223761SKevin Barnett 	dma_addr_t	queue_memory_base_dma_handle;
13106c223761SKevin Barnett 	struct pqi_admin_queues admin_queues;
13116c223761SKevin Barnett 	struct pqi_queue_group queue_groups[PQI_MAX_QUEUE_GROUPS];
13126c223761SKevin Barnett 	struct pqi_event_queue event_queue;
1313061ef06aSKevin Barnett 	enum pqi_irq_mode irq_mode;
13146c223761SKevin Barnett 	int		max_msix_vectors;
13156c223761SKevin Barnett 	int		num_msix_vectors_enabled;
13166c223761SKevin Barnett 	int		num_msix_vectors_initialized;
13176c223761SKevin Barnett 	int		event_irq;
13186c223761SKevin Barnett 	struct Scsi_Host *scsi_host;
13196c223761SKevin Barnett 
13206c223761SKevin Barnett 	struct mutex	scan_mutex;
13217561a7e4SKevin Barnett 	struct mutex	lun_reset_mutex;
13227561a7e4SKevin Barnett 	bool		controller_online;
13237561a7e4SKevin Barnett 	bool		block_requests;
13249fa82023SKevin Barnett 	bool		scan_blocked;
1325*27655e9dSMahesh Rajashekhara 	u8		logical_volume_rescan_needed : 1;
13266c223761SKevin Barnett 	u8		inbound_spanning_supported : 1;
13276c223761SKevin Barnett 	u8		outbound_spanning_supported : 1;
13286c223761SKevin Barnett 	u8		pqi_mode_enabled : 1;
1329336b6819SKevin Barnett 	u8		pqi_reset_quiesce_supported : 1;
13304fd22c13SMahesh Rajashekhara 	u8		soft_reset_handshake_supported : 1;
133121432010Skoshyaji 	u8		raid_iu_timeout_supported : 1;
1332c2922f17SMurthy Bhat 	u8		tmf_iu_timeout_supported : 1;
13337a84a821SKevin Barnett 	u8		unique_wwid_in_report_phys_lun_supported : 1;
13345d1f03e6SMurthy Bhat 	u8		firmware_triage_supported : 1;
133528ca6d87SMike McGowen 	u8		rpl_extended_format_4_5_supported : 1;
13367a012c23SDon Brace 	u8		enable_r1_writes : 1;
13376702d2c4SDon Brace 	u8		enable_r5_writes : 1;
13386702d2c4SDon Brace 	u8		enable_r6_writes : 1;
1339f6cc2a77SKevin Barnett 	u8		lv_drive_type_mix_valid : 1;
1340c7ffedb3SDon Brace 	u8		enable_stream_detection : 1;
1341f6cc2a77SKevin Barnett 
1342f6cc2a77SKevin Barnett 	u8		ciss_report_log_flags;
1343f6cc2a77SKevin Barnett 	u32		max_transfer_encrypted_sas_sata;
1344f6cc2a77SKevin Barnett 	u32		max_transfer_encrypted_nvme;
1345f6cc2a77SKevin Barnett 	u32		max_write_raid_5_6;
1346f6cc2a77SKevin Barnett 	u32		max_write_raid_1_10_2drive;
1347f6cc2a77SKevin Barnett 	u32		max_write_raid_1_10_3drive;
13486c223761SKevin Barnett 
13496c223761SKevin Barnett 	struct list_head scsi_device_list;
13506c223761SKevin Barnett 	spinlock_t	scsi_device_list_lock;
13516c223761SKevin Barnett 
13526c223761SKevin Barnett 	struct delayed_work rescan_work;
13536c223761SKevin Barnett 	struct delayed_work update_time_work;
13546c223761SKevin Barnett 
13556c223761SKevin Barnett 	struct pqi_sas_node *sas_host;
13566c223761SKevin Barnett 	u64		sas_address;
13576c223761SKevin Barnett 
13586c223761SKevin Barnett 	struct pqi_io_request *io_request_pool;
13596c223761SKevin Barnett 	u16		next_io_request_slot;
13606c223761SKevin Barnett 
13616a50d6adSKevin Barnett 	struct pqi_event events[PQI_NUM_SUPPORTED_EVENTS];
13626c223761SKevin Barnett 	struct work_struct event_work;
13636c223761SKevin Barnett 
13646c223761SKevin Barnett 	atomic_t	num_interrupts;
13656c223761SKevin Barnett 	int		previous_num_interrupts;
136698f87667SKevin Barnett 	u32		previous_heartbeat_count;
136798f87667SKevin Barnett 	__le32 __iomem	*heartbeat_counter;
13684fd22c13SMahesh Rajashekhara 	u8 __iomem	*soft_reset_status;
13696c223761SKevin Barnett 	struct timer_list heartbeat_timer;
13705f310425SKevin Barnett 	struct work_struct ctrl_offline_work;
13716c223761SKevin Barnett 
13726c223761SKevin Barnett 	struct semaphore sync_request_sem;
13737561a7e4SKevin Barnett 	atomic_t	num_busy_threads;
13747561a7e4SKevin Barnett 	atomic_t	num_blocked_threads;
13757561a7e4SKevin Barnett 	wait_queue_head_t block_requests_wait;
1376376fb880SKevin Barnett 
13772790cd4dSKevin Barnett 	struct mutex	ofa_mutex;
13784fd22c13SMahesh Rajashekhara 	struct pqi_ofa_memory *pqi_ofa_mem_virt_addr;
13794fd22c13SMahesh Rajashekhara 	dma_addr_t	pqi_ofa_mem_dma_handle;
13804fd22c13SMahesh Rajashekhara 	void		**pqi_ofa_chunk_virt_addr;
13812790cd4dSKevin Barnett 	struct work_struct ofa_memory_alloc_work;
13822790cd4dSKevin Barnett 	struct work_struct ofa_quiesce_work;
13832790cd4dSKevin Barnett 	u32		ofa_bytes_requested;
13842790cd4dSKevin Barnett 	u16		ofa_cancel_reason;
13856c223761SKevin Barnett };
13866c223761SKevin Barnett 
1387ff6abb73SKevin Barnett enum pqi_ctrl_mode {
1388162d7753SKevin Barnett 	SIS_MODE = 0,
1389ff6abb73SKevin Barnett 	PQI_MODE
1390ff6abb73SKevin Barnett };
1391ff6abb73SKevin Barnett 
13926c223761SKevin Barnett /*
13936c223761SKevin Barnett  * assume worst case: SATA queue depth of 31 minus 4 internal firmware commands
13946c223761SKevin Barnett  */
13956c223761SKevin Barnett #define PQI_PHYSICAL_DISK_DEFAULT_MAX_QUEUE_DEPTH	27
13966c223761SKevin Barnett 
13976c223761SKevin Barnett /* CISS commands */
13986c223761SKevin Barnett #define CISS_READ		0xc0
13996c223761SKevin Barnett #define CISS_REPORT_LOG		0xc2	/* Report Logical LUNs */
14006c223761SKevin Barnett #define CISS_REPORT_PHYS	0xc3	/* Report Physical LUNs */
14016c223761SKevin Barnett #define CISS_GET_RAID_MAP	0xc8
14026c223761SKevin Barnett 
14036c223761SKevin Barnett /* BMIC commands */
14046c223761SKevin Barnett #define BMIC_IDENTIFY_CONTROLLER		0x11
14056c223761SKevin Barnett #define BMIC_IDENTIFY_PHYSICAL_DEVICE		0x15
14066c223761SKevin Barnett #define BMIC_READ				0x26
14076c223761SKevin Barnett #define BMIC_WRITE				0x27
1408f6cc2a77SKevin Barnett #define BMIC_SENSE_FEATURE			0x61
14096c223761SKevin Barnett #define BMIC_SENSE_CONTROLLER_PARAMETERS	0x64
14106c223761SKevin Barnett #define BMIC_SENSE_SUBSYSTEM_INFORMATION	0x66
14113d46a59aSDon Brace #define BMIC_CSMI_PASSTHRU			0x68
14126c223761SKevin Barnett #define BMIC_WRITE_HOST_WELLNESS		0xa5
141358322fe0SKevin Barnett #define BMIC_FLUSH_CACHE			0xc2
1414171c2865SDave Carroll #define BMIC_SET_DIAG_OPTIONS			0xf4
1415171c2865SDave Carroll #define BMIC_SENSE_DIAG_OPTIONS			0xf5
14166c223761SKevin Barnett 
1417694c5d5bSKevin Barnett #define CSMI_CC_SAS_SMP_PASSTHRU		0x17
14183d46a59aSDon Brace 
141958322fe0SKevin Barnett #define SA_FLUSH_CACHE				0x1
14206c223761SKevin Barnett 
14216c223761SKevin Barnett #define MASKED_DEVICE(lunid)			((lunid)[3] & 0xc0)
1422bd10cf0bSKevin Barnett #define CISS_GET_LEVEL_2_BUS(lunid)		((lunid)[7] & 0x3f)
14236c223761SKevin Barnett #define CISS_GET_LEVEL_2_TARGET(lunid)		((lunid)[6])
14246c223761SKevin Barnett #define CISS_GET_DRIVE_NUMBER(lunid)		\
1425bd10cf0bSKevin Barnett 	(((CISS_GET_LEVEL_2_BUS((lunid)) - 1) << 8) + \
14266c223761SKevin Barnett 	CISS_GET_LEVEL_2_TARGET((lunid)))
14276c223761SKevin Barnett 
1428f6cc2a77SKevin Barnett #define LV_GET_DRIVE_TYPE_MIX(lunid)		((lunid)[6])
1429f6cc2a77SKevin Barnett 
1430f6cc2a77SKevin Barnett #define LV_DRIVE_TYPE_MIX_UNKNOWN		0
1431f6cc2a77SKevin Barnett #define LV_DRIVE_TYPE_MIX_NO_RESTRICTION	1
1432f6cc2a77SKevin Barnett #define LV_DRIVE_TYPE_MIX_SAS_HDD_ONLY		2
1433f6cc2a77SKevin Barnett #define LV_DRIVE_TYPE_MIX_SATA_HDD_ONLY		3
1434f6cc2a77SKevin Barnett #define LV_DRIVE_TYPE_MIX_SAS_OR_SATA_SSD_ONLY	4
1435f6cc2a77SKevin Barnett #define LV_DRIVE_TYPE_MIX_SAS_SSD_ONLY		5
1436f6cc2a77SKevin Barnett #define LV_DRIVE_TYPE_MIX_SATA_SSD_ONLY		6
1437f6cc2a77SKevin Barnett #define LV_DRIVE_TYPE_MIX_SAS_ONLY		7
1438f6cc2a77SKevin Barnett #define LV_DRIVE_TYPE_MIX_SATA_ONLY		8
1439f6cc2a77SKevin Barnett #define LV_DRIVE_TYPE_MIX_NVME_ONLY		9
1440f6cc2a77SKevin Barnett 
14416c223761SKevin Barnett #define NO_TIMEOUT		((unsigned long) -1)
14426c223761SKevin Barnett 
14436c223761SKevin Barnett #pragma pack(1)
14446c223761SKevin Barnett 
14456c223761SKevin Barnett struct bmic_identify_controller {
14466c223761SKevin Barnett 	u8	configured_logical_drive_count;
14476c223761SKevin Barnett 	__le32	configuration_signature;
1448598bef8dSKevin Barnett 	u8	firmware_version_short[4];
14496c223761SKevin Barnett 	u8	reserved[145];
14506c223761SKevin Barnett 	__le16	extended_logical_unit_count;
14516c223761SKevin Barnett 	u8	reserved1[34];
14526c223761SKevin Barnett 	__le16	firmware_build_number;
14536d90615fSMurthy Bhat 	u8	reserved2[8];
14546d90615fSMurthy Bhat 	u8	vendor_id[8];
14556d90615fSMurthy Bhat 	u8	product_id[16];
1456598bef8dSKevin Barnett 	u8	reserved3[62];
1457598bef8dSKevin Barnett 	__le32	extra_controller_flags;
1458598bef8dSKevin Barnett 	u8	reserved4[2];
14596c223761SKevin Barnett 	u8	controller_mode;
1460598bef8dSKevin Barnett 	u8	spare_part_number[32];
1461598bef8dSKevin Barnett 	u8	firmware_version_long[32];
14626d90615fSMurthy Bhat };
14636d90615fSMurthy Bhat 
1464598bef8dSKevin Barnett /* constants for extra_controller_flags field of bmic_identify_controller */
1465598bef8dSKevin Barnett #define BMIC_IDENTIFY_EXTRA_FLAGS_LONG_FW_VERSION_SUPPORTED	0x20000000
1466598bef8dSKevin Barnett 
14676d90615fSMurthy Bhat struct bmic_sense_subsystem_info {
14686d90615fSMurthy Bhat 	u8	reserved[44];
14696d90615fSMurthy Bhat 	u8	ctrl_serial_number[16];
14706c223761SKevin Barnett };
14716c223761SKevin Barnett 
1472694c5d5bSKevin Barnett /* constants for device_type field */
1473694c5d5bSKevin Barnett #define SA_DEVICE_TYPE_SATA		0x1
1474694c5d5bSKevin Barnett #define SA_DEVICE_TYPE_SAS		0x2
1475694c5d5bSKevin Barnett #define SA_DEVICE_TYPE_EXPANDER_SMP	0x5
1476ce143793SKevin Barnett #define SA_DEVICE_TYPE_SES		0x6
1477694c5d5bSKevin Barnett #define SA_DEVICE_TYPE_CONTROLLER	0x7
1478694c5d5bSKevin Barnett #define SA_DEVICE_TYPE_NVME		0x9
14793d46a59aSDon Brace 
14806c223761SKevin Barnett struct bmic_identify_physical_device {
14816c223761SKevin Barnett 	u8	scsi_bus;		/* SCSI Bus number on controller */
14826c223761SKevin Barnett 	u8	scsi_id;		/* SCSI ID on this bus */
14836c223761SKevin Barnett 	__le16	block_size;		/* sector size in bytes */
14846c223761SKevin Barnett 	__le32	total_blocks;		/* number for sectors on drive */
14856c223761SKevin Barnett 	__le32	reserved_blocks;	/* controller reserved (RIS) */
14866c223761SKevin Barnett 	u8	model[40];		/* Physical Drive Model */
14876c223761SKevin Barnett 	u8	serial_number[40];	/* Drive Serial Number */
14886c223761SKevin Barnett 	u8	firmware_revision[8];	/* drive firmware revision */
14896c223761SKevin Barnett 	u8	scsi_inquiry_bits;	/* inquiry byte 7 bits */
14906c223761SKevin Barnett 	u8	compaq_drive_stamp;	/* 0 means drive not stamped */
14916c223761SKevin Barnett 	u8	last_failure_reason;
14926c223761SKevin Barnett 	u8	flags;
14936c223761SKevin Barnett 	u8	more_flags;
14946c223761SKevin Barnett 	u8	scsi_lun;		/* SCSI LUN for phys drive */
14956c223761SKevin Barnett 	u8	yet_more_flags;
14966c223761SKevin Barnett 	u8	even_more_flags;
14976c223761SKevin Barnett 	__le32	spi_speed_rules;
14986c223761SKevin Barnett 	u8	phys_connector[2];	/* connector number on controller */
14996c223761SKevin Barnett 	u8	phys_box_on_bus;	/* phys enclosure this drive resides */
15006c223761SKevin Barnett 	u8	phys_bay_in_box;	/* phys drv bay this drive resides */
15016c223761SKevin Barnett 	__le32	rpm;			/* drive rotational speed in RPM */
15026c223761SKevin Barnett 	u8	device_type;		/* type of drive */
15036c223761SKevin Barnett 	u8	sata_version;		/* only valid when device_type = */
1504694c5d5bSKevin Barnett 					/* SA_DEVICE_TYPE_SATA */
15056c223761SKevin Barnett 	__le64	big_total_block_count;
15066c223761SKevin Barnett 	__le64	ris_starting_lba;
15076c223761SKevin Barnett 	__le32	ris_size;
15086c223761SKevin Barnett 	u8	wwid[20];
15096c223761SKevin Barnett 	u8	controller_phy_map[32];
15106c223761SKevin Barnett 	__le16	phy_count;
15116c223761SKevin Barnett 	u8	phy_connected_dev_type[256];
15126c223761SKevin Barnett 	u8	phy_to_drive_bay_num[256];
15136c223761SKevin Barnett 	__le16	phy_to_attached_dev_index[256];
15146c223761SKevin Barnett 	u8	box_index;
15156c223761SKevin Barnett 	u8	reserved;
15166c223761SKevin Barnett 	__le16	extra_physical_drive_flags;
15176c223761SKevin Barnett 	u8	negotiated_link_rate[256];
15186c223761SKevin Barnett 	u8	phy_to_phy_map[256];
15196c223761SKevin Barnett 	u8	redundant_path_present_map;
15206c223761SKevin Barnett 	u8	redundant_path_failure_map;
15216c223761SKevin Barnett 	u8	active_path_number;
15226c223761SKevin Barnett 	__le16	alternate_paths_phys_connector[8];
15236c223761SKevin Barnett 	u8	alternate_paths_phys_box_on_port[8];
15246c223761SKevin Barnett 	u8	multi_lun_device_lun_count;
15256c223761SKevin Barnett 	u8	minimum_good_fw_revision[8];
15266c223761SKevin Barnett 	u8	unique_inquiry_bytes[20];
15271be42f46SKevin Barnett 	u8	current_temperature_degrees;
15281be42f46SKevin Barnett 	u8	temperature_threshold_degrees;
15291be42f46SKevin Barnett 	u8	max_temperature_degrees;
15306c223761SKevin Barnett 	u8	logical_blocks_per_phys_block_exp;
15316c223761SKevin Barnett 	__le16	current_queue_depth_limit;
15326c223761SKevin Barnett 	u8	switch_name[10];
15336c223761SKevin Barnett 	__le16	switch_port;
15346c223761SKevin Barnett 	u8	alternate_paths_switch_name[40];
15356c223761SKevin Barnett 	u8	alternate_paths_switch_port[8];
15366c223761SKevin Barnett 	__le16	power_on_hours;
15376c223761SKevin Barnett 	__le16	percent_endurance_used;
15386c223761SKevin Barnett 	u8	drive_authentication;
15396c223761SKevin Barnett 	u8	smart_carrier_authentication;
15406c223761SKevin Barnett 	u8	smart_carrier_app_fw_version;
15416c223761SKevin Barnett 	u8	smart_carrier_bootloader_fw_version;
15421be42f46SKevin Barnett 	u8	sanitize_flags;
15431be42f46SKevin Barnett 	u8	encryption_key_flags;
15446c223761SKevin Barnett 	u8	encryption_key_name[64];
15456c223761SKevin Barnett 	__le32	misc_drive_flags;
15466c223761SKevin Barnett 	__le16	dek_index;
15471be42f46SKevin Barnett 	__le16	hba_drive_encryption_flags;
15481be42f46SKevin Barnett 	__le16	max_overwrite_time;
15491be42f46SKevin Barnett 	__le16	max_block_erase_time;
15501be42f46SKevin Barnett 	__le16	max_crypto_erase_time;
15511be42f46SKevin Barnett 	u8	connector_info[5];
15521be42f46SKevin Barnett 	u8	connector_name[8][8];
15531be42f46SKevin Barnett 	u8	page_83_identifier[16];
15541be42f46SKevin Barnett 	u8	maximum_link_rate[256];
15551be42f46SKevin Barnett 	u8	negotiated_physical_link_rate[256];
15561be42f46SKevin Barnett 	u8	box_connector_name[8];
15571be42f46SKevin Barnett 	u8	padding_to_multiple_of_512[9];
15586c223761SKevin Barnett };
15596c223761SKevin Barnett 
1560f6cc2a77SKevin Barnett #define BMIC_SENSE_FEATURE_IO_PAGE		0x8
1561f6cc2a77SKevin Barnett #define BMIC_SENSE_FEATURE_IO_PAGE_AIO_SUBPAGE	0x2
1562f6cc2a77SKevin Barnett 
1563f6cc2a77SKevin Barnett struct bmic_sense_feature_buffer_header {
1564f6cc2a77SKevin Barnett 	u8	page_code;
1565f6cc2a77SKevin Barnett 	u8	subpage_code;
1566f6cc2a77SKevin Barnett 	__le16	buffer_length;
1567f6cc2a77SKevin Barnett };
1568f6cc2a77SKevin Barnett 
1569f6cc2a77SKevin Barnett struct bmic_sense_feature_page_header {
1570f6cc2a77SKevin Barnett 	u8	page_code;
1571f6cc2a77SKevin Barnett 	u8	subpage_code;
1572f6cc2a77SKevin Barnett 	__le16	page_length;
1573f6cc2a77SKevin Barnett };
1574f6cc2a77SKevin Barnett 
1575f6cc2a77SKevin Barnett struct bmic_sense_feature_io_page_aio_subpage {
1576f6cc2a77SKevin Barnett 	struct bmic_sense_feature_page_header header;
1577f6cc2a77SKevin Barnett 	u8	firmware_read_support;
1578f6cc2a77SKevin Barnett 	u8	driver_read_support;
1579f6cc2a77SKevin Barnett 	u8	firmware_write_support;
1580f6cc2a77SKevin Barnett 	u8	driver_write_support;
1581f6cc2a77SKevin Barnett 	__le16	max_transfer_encrypted_sas_sata;
1582f6cc2a77SKevin Barnett 	__le16	max_transfer_encrypted_nvme;
1583f6cc2a77SKevin Barnett 	__le16	max_write_raid_5_6;
1584f6cc2a77SKevin Barnett 	__le16	max_write_raid_1_10_2drive;
1585f6cc2a77SKevin Barnett 	__le16	max_write_raid_1_10_3drive;
1586f6cc2a77SKevin Barnett };
1587f6cc2a77SKevin Barnett 
15883d46a59aSDon Brace struct bmic_smp_request {
15893d46a59aSDon Brace 	u8	frame_type;
15903d46a59aSDon Brace 	u8	function;
15913d46a59aSDon Brace 	u8	allocated_response_length;
15923d46a59aSDon Brace 	u8	request_length;
15933d46a59aSDon Brace 	u8	additional_request_bytes[1016];
15943d46a59aSDon Brace };
15953d46a59aSDon Brace 
15963d46a59aSDon Brace struct  bmic_smp_response {
15973d46a59aSDon Brace 	u8	frame_type;
15983d46a59aSDon Brace 	u8	function;
15993d46a59aSDon Brace 	u8	function_result;
16003d46a59aSDon Brace 	u8	response_length;
16013d46a59aSDon Brace 	u8	additional_response_bytes[1016];
16023d46a59aSDon Brace };
16033d46a59aSDon Brace 
16043d46a59aSDon Brace struct bmic_csmi_ioctl_header {
16053d46a59aSDon Brace 	__le32	header_length;
16063d46a59aSDon Brace 	u8	signature[8];
16073d46a59aSDon Brace 	__le32	timeout;
16083d46a59aSDon Brace 	__le32	control_code;
16093d46a59aSDon Brace 	__le32	return_code;
16103d46a59aSDon Brace 	__le32	length;
16113d46a59aSDon Brace };
16123d46a59aSDon Brace 
16133d46a59aSDon Brace struct bmic_csmi_smp_passthru {
16143d46a59aSDon Brace 	u8	phy_identifier;
16153d46a59aSDon Brace 	u8	port_identifier;
16163d46a59aSDon Brace 	u8	connection_rate;
16173d46a59aSDon Brace 	u8	reserved;
16183d46a59aSDon Brace 	__be64	destination_sas_address;
16193d46a59aSDon Brace 	__le32	request_length;
16203d46a59aSDon Brace 	struct bmic_smp_request request;
16213d46a59aSDon Brace 	u8	connection_status;
16223d46a59aSDon Brace 	u8	reserved1[3];
16233d46a59aSDon Brace 	__le32	response_length;
16243d46a59aSDon Brace 	struct bmic_smp_response response;
16253d46a59aSDon Brace };
16263d46a59aSDon Brace 
16273d46a59aSDon Brace struct bmic_csmi_smp_passthru_buffer {
16283d46a59aSDon Brace 	struct bmic_csmi_ioctl_header ioctl_header;
16293d46a59aSDon Brace 	struct bmic_csmi_smp_passthru parameters;
16303d46a59aSDon Brace };
16313d46a59aSDon Brace 
163258322fe0SKevin Barnett struct bmic_flush_cache {
163358322fe0SKevin Barnett 	u8	disable_flag;
163458322fe0SKevin Barnett 	u8	system_power_action;
163558322fe0SKevin Barnett 	u8	ndu_flush;
163658322fe0SKevin Barnett 	u8	shutdown_event;
163758322fe0SKevin Barnett 	u8	reserved[28];
163858322fe0SKevin Barnett };
163958322fe0SKevin Barnett 
164058322fe0SKevin Barnett /* for shutdown_event member of struct bmic_flush_cache */
164158322fe0SKevin Barnett enum bmic_flush_cache_shutdown_event {
164258322fe0SKevin Barnett 	NONE_CACHE_FLUSH_ONLY = 0,
164358322fe0SKevin Barnett 	SHUTDOWN = 1,
164458322fe0SKevin Barnett 	HIBERNATE = 2,
164558322fe0SKevin Barnett 	SUSPEND = 3,
164658322fe0SKevin Barnett 	RESTART = 4
164758322fe0SKevin Barnett };
164858322fe0SKevin Barnett 
1649171c2865SDave Carroll struct bmic_diag_options {
1650171c2865SDave Carroll 	__le32 options;
1651171c2865SDave Carroll };
1652171c2865SDave Carroll 
16536c223761SKevin Barnett #pragma pack()
16546c223761SKevin Barnett 
1655694c5d5bSKevin Barnett static inline struct pqi_ctrl_info *shost_to_hba(struct Scsi_Host *shost)
16563d46a59aSDon Brace {
1657694c5d5bSKevin Barnett 	void *hostdata = shost_priv(shost);
16583d46a59aSDon Brace 
1659694c5d5bSKevin Barnett 	return *((struct pqi_ctrl_info **)hostdata);
16600530736eSKevin Barnett }
16610530736eSKevin Barnett 
16623d46a59aSDon Brace void pqi_sas_smp_handler(struct bsg_job *job, struct Scsi_Host *shost,
16633d46a59aSDon Brace 	struct sas_rphy *rphy);
16643d46a59aSDon Brace 
16656c223761SKevin Barnett int pqi_add_sas_host(struct Scsi_Host *shost, struct pqi_ctrl_info *ctrl_info);
16666c223761SKevin Barnett void pqi_delete_sas_host(struct pqi_ctrl_info *ctrl_info);
16676c223761SKevin Barnett int pqi_add_sas_device(struct pqi_sas_node *pqi_sas_node,
16686c223761SKevin Barnett 	struct pqi_scsi_dev *device);
16696c223761SKevin Barnett void pqi_remove_sas_device(struct pqi_scsi_dev *device);
16706c223761SKevin Barnett struct pqi_scsi_dev *pqi_find_device_by_sas_rphy(
16716c223761SKevin Barnett 	struct pqi_ctrl_info *ctrl_info, struct sas_rphy *rphy);
16727561a7e4SKevin Barnett void pqi_prep_for_scsi_done(struct scsi_cmnd *scmd);
16733d46a59aSDon Brace int pqi_csmi_smp_passthru(struct pqi_ctrl_info *ctrl_info,
16743d46a59aSDon Brace 	struct bmic_csmi_smp_passthru_buffer *buffer, size_t buffer_length,
16753d46a59aSDon Brace 	struct pqi_raid_error_info *error_info);
16766c223761SKevin Barnett 
16776c223761SKevin Barnett extern struct sas_function_template pqi_sas_transport_functions;
16786c223761SKevin Barnett 
16796c223761SKevin Barnett #endif /* _SMARTPQI_H */
1680