162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * pmcraid.h -- PMC Sierra MaxRAID controller driver header file
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Written By: Anil Ravindranath<anil_ravindranath@pmc-sierra.com>
662306a36Sopenharmony_ci *             PMC-Sierra Inc
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * Copyright (C) 2008, 2009 PMC Sierra Inc.
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#ifndef _PMCRAID_H
1262306a36Sopenharmony_ci#define _PMCRAID_H
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#include <linux/types.h>
1562306a36Sopenharmony_ci#include <linux/completion.h>
1662306a36Sopenharmony_ci#include <linux/list.h>
1762306a36Sopenharmony_ci#include <scsi/scsi.h>
1862306a36Sopenharmony_ci#include <scsi/scsi_cmnd.h>
1962306a36Sopenharmony_ci#include <linux/cdev.h>
2062306a36Sopenharmony_ci#include <net/netlink.h>
2162306a36Sopenharmony_ci#include <net/genetlink.h>
2262306a36Sopenharmony_ci#include <linux/connector.h>
2362306a36Sopenharmony_ci/*
2462306a36Sopenharmony_ci * Driver name   : string representing the driver name
2562306a36Sopenharmony_ci * Device file   : /dev file to be used for management interfaces
2662306a36Sopenharmony_ci * Driver version: version string in major_version.minor_version.patch format
2762306a36Sopenharmony_ci * Driver date   : date information in "Mon dd yyyy" format
2862306a36Sopenharmony_ci */
2962306a36Sopenharmony_ci#define PMCRAID_DRIVER_NAME		"PMC MaxRAID"
3062306a36Sopenharmony_ci#define PMCRAID_DEVFILE			"pmcsas"
3162306a36Sopenharmony_ci#define PMCRAID_DRIVER_VERSION		"1.0.3"
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#define PMCRAID_FW_VERSION_1		0x002
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci/* Maximum number of adapters supported by current version of the driver */
3662306a36Sopenharmony_ci#define PMCRAID_MAX_ADAPTERS		1024
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci/* Bit definitions as per firmware, bit position [0][1][2].....[31] */
3962306a36Sopenharmony_ci#define PMC_BIT8(n)          (1 << (7-n))
4062306a36Sopenharmony_ci#define PMC_BIT16(n)         (1 << (15-n))
4162306a36Sopenharmony_ci#define PMC_BIT32(n)         (1 << (31-n))
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci/* PMC PCI vendor ID and device ID values */
4462306a36Sopenharmony_ci#define PCI_VENDOR_ID_PMC			0x11F8
4562306a36Sopenharmony_ci#define PCI_DEVICE_ID_PMC_MAXRAID		0x5220
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci/*
4862306a36Sopenharmony_ci * MAX_CMD          : maximum commands that can be outstanding with IOA
4962306a36Sopenharmony_ci * MAX_IO_CMD       : command blocks available for IO commands
5062306a36Sopenharmony_ci * MAX_HCAM_CMD     : command blocks available for HCAMS
5162306a36Sopenharmony_ci * MAX_INTERNAL_CMD : command blocks available for internal commands like reset
5262306a36Sopenharmony_ci */
5362306a36Sopenharmony_ci#define PMCRAID_MAX_CMD				1024
5462306a36Sopenharmony_ci#define PMCRAID_MAX_IO_CMD			1020
5562306a36Sopenharmony_ci#define PMCRAID_MAX_HCAM_CMD			2
5662306a36Sopenharmony_ci#define PMCRAID_MAX_INTERNAL_CMD		2
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci/* MAX_IOADLS       : max number of scatter-gather lists supported by IOA
5962306a36Sopenharmony_ci * IOADLS_INTERNAL  : number of ioadls included as part of IOARCB.
6062306a36Sopenharmony_ci * IOADLS_EXTERNAL  : number of ioadls allocated external to IOARCB
6162306a36Sopenharmony_ci */
6262306a36Sopenharmony_ci#define PMCRAID_IOADLS_INTERNAL			 27
6362306a36Sopenharmony_ci#define PMCRAID_IOADLS_EXTERNAL			 37
6462306a36Sopenharmony_ci#define PMCRAID_MAX_IOADLS			 PMCRAID_IOADLS_INTERNAL
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci/* HRRQ_ENTRY_SIZE  : size of hrrq buffer
6762306a36Sopenharmony_ci * IOARCB_ALIGNMENT : alignment required for IOARCB
6862306a36Sopenharmony_ci * IOADL_ALIGNMENT  : alignment requirement for IOADLs
6962306a36Sopenharmony_ci * MSIX_VECTORS     : number of MSIX vectors supported
7062306a36Sopenharmony_ci */
7162306a36Sopenharmony_ci#define HRRQ_ENTRY_SIZE                          sizeof(__le32)
7262306a36Sopenharmony_ci#define PMCRAID_IOARCB_ALIGNMENT                 32
7362306a36Sopenharmony_ci#define PMCRAID_IOADL_ALIGNMENT                  16
7462306a36Sopenharmony_ci#define PMCRAID_IOASA_ALIGNMENT                  4
7562306a36Sopenharmony_ci#define PMCRAID_NUM_MSIX_VECTORS                 16
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci/* various other limits */
7862306a36Sopenharmony_ci#define PMCRAID_VENDOR_ID_LEN			8
7962306a36Sopenharmony_ci#define PMCRAID_PRODUCT_ID_LEN			16
8062306a36Sopenharmony_ci#define PMCRAID_SERIAL_NUM_LEN			8
8162306a36Sopenharmony_ci#define PMCRAID_LUN_LEN				8
8262306a36Sopenharmony_ci#define PMCRAID_MAX_CDB_LEN			16
8362306a36Sopenharmony_ci#define PMCRAID_DEVICE_ID_LEN			8
8462306a36Sopenharmony_ci#define PMCRAID_SENSE_DATA_LEN			256
8562306a36Sopenharmony_ci#define PMCRAID_ADD_CMD_PARAM_LEN		48
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci#define PMCRAID_MAX_BUS_TO_SCAN                  1
8862306a36Sopenharmony_ci#define PMCRAID_MAX_NUM_TARGETS_PER_BUS          256
8962306a36Sopenharmony_ci#define PMCRAID_MAX_NUM_LUNS_PER_TARGET          8
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci/* IOA bus/target/lun number of IOA resources */
9262306a36Sopenharmony_ci#define PMCRAID_IOA_BUS_ID                       0xfe
9362306a36Sopenharmony_ci#define PMCRAID_IOA_TARGET_ID                    0xff
9462306a36Sopenharmony_ci#define PMCRAID_IOA_LUN_ID                       0xff
9562306a36Sopenharmony_ci#define PMCRAID_VSET_BUS_ID                      0x1
9662306a36Sopenharmony_ci#define PMCRAID_VSET_LUN_ID                      0x0
9762306a36Sopenharmony_ci#define PMCRAID_PHYS_BUS_ID                      0x0
9862306a36Sopenharmony_ci#define PMCRAID_VIRTUAL_ENCL_BUS_ID              0x8
9962306a36Sopenharmony_ci#define PMCRAID_MAX_VSET_TARGETS                 0x7F
10062306a36Sopenharmony_ci#define PMCRAID_MAX_VSET_LUNS_PER_TARGET         8
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci#define PMCRAID_IOA_MAX_SECTORS                  32767
10362306a36Sopenharmony_ci#define PMCRAID_VSET_MAX_SECTORS                 512
10462306a36Sopenharmony_ci#define PMCRAID_MAX_CMD_PER_LUN                  254
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci/* Number of configuration table entries (resources), includes 1 FP,
10762306a36Sopenharmony_ci * 1 Enclosure device
10862306a36Sopenharmony_ci */
10962306a36Sopenharmony_ci#define PMCRAID_MAX_RESOURCES                    256
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci/* Adapter Commands used by driver */
11262306a36Sopenharmony_ci#define PMCRAID_QUERY_RESOURCE_STATE             0xC2
11362306a36Sopenharmony_ci#define PMCRAID_RESET_DEVICE                     0xC3
11462306a36Sopenharmony_ci/* options to select reset target */
11562306a36Sopenharmony_ci#define ENABLE_RESET_MODIFIER                    0x80
11662306a36Sopenharmony_ci#define RESET_DEVICE_LUN                         0x40
11762306a36Sopenharmony_ci#define RESET_DEVICE_TARGET                      0x20
11862306a36Sopenharmony_ci#define RESET_DEVICE_BUS                         0x10
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci#define PMCRAID_IDENTIFY_HRRQ                    0xC4
12162306a36Sopenharmony_ci#define PMCRAID_QUERY_IOA_CONFIG                 0xC5
12262306a36Sopenharmony_ci#define PMCRAID_QUERY_CMD_STATUS		 0xCB
12362306a36Sopenharmony_ci#define PMCRAID_ABORT_CMD                        0xC7
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci/* CANCEL ALL command, provides option for setting SYNC_COMPLETE
12662306a36Sopenharmony_ci * on the target resources for which commands got cancelled
12762306a36Sopenharmony_ci */
12862306a36Sopenharmony_ci#define PMCRAID_CANCEL_ALL_REQUESTS		 0xCE
12962306a36Sopenharmony_ci#define PMCRAID_SYNC_COMPLETE_AFTER_CANCEL       PMC_BIT8(0)
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci/* HCAM command and types of HCAM supported by IOA */
13262306a36Sopenharmony_ci#define PMCRAID_HOST_CONTROLLED_ASYNC            0xCF
13362306a36Sopenharmony_ci#define PMCRAID_HCAM_CODE_CONFIG_CHANGE          0x01
13462306a36Sopenharmony_ci#define PMCRAID_HCAM_CODE_LOG_DATA               0x02
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci/* IOA shutdown command and various shutdown types */
13762306a36Sopenharmony_ci#define PMCRAID_IOA_SHUTDOWN                     0xF7
13862306a36Sopenharmony_ci#define PMCRAID_SHUTDOWN_NORMAL                  0x00
13962306a36Sopenharmony_ci#define PMCRAID_SHUTDOWN_PREPARE_FOR_NORMAL      0x40
14062306a36Sopenharmony_ci#define PMCRAID_SHUTDOWN_NONE                    0x100
14162306a36Sopenharmony_ci#define PMCRAID_SHUTDOWN_ABBREV                  0x80
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci/* SET SUPPORTED DEVICES command and the option to select all the
14462306a36Sopenharmony_ci * devices to be supported
14562306a36Sopenharmony_ci */
14662306a36Sopenharmony_ci#define PMCRAID_SET_SUPPORTED_DEVICES            0xFB
14762306a36Sopenharmony_ci#define ALL_DEVICES_SUPPORTED                    PMC_BIT8(0)
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci/* This option is used with SCSI WRITE_BUFFER command */
15062306a36Sopenharmony_ci#define PMCRAID_WR_BUF_DOWNLOAD_AND_SAVE         0x05
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci/* IOASC Codes used by driver */
15362306a36Sopenharmony_ci#define PMCRAID_IOASC_SENSE_MASK                 0xFFFFFF00
15462306a36Sopenharmony_ci#define PMCRAID_IOASC_SENSE_KEY(ioasc)           ((ioasc) >> 24)
15562306a36Sopenharmony_ci#define PMCRAID_IOASC_SENSE_CODE(ioasc)          (((ioasc) & 0x00ff0000) >> 16)
15662306a36Sopenharmony_ci#define PMCRAID_IOASC_SENSE_QUAL(ioasc)          (((ioasc) & 0x0000ff00) >> 8)
15762306a36Sopenharmony_ci#define PMCRAID_IOASC_SENSE_STATUS(ioasc)        ((ioasc) & 0x000000ff)
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci#define PMCRAID_IOASC_GOOD_COMPLETION			0x00000000
16062306a36Sopenharmony_ci#define PMCRAID_IOASC_GC_IOARCB_NOTFOUND		0x005A0000
16162306a36Sopenharmony_ci#define PMCRAID_IOASC_NR_INIT_CMD_REQUIRED		0x02040200
16262306a36Sopenharmony_ci#define PMCRAID_IOASC_NR_IOA_RESET_REQUIRED		0x02048000
16362306a36Sopenharmony_ci#define PMCRAID_IOASC_NR_SYNC_REQUIRED			0x023F0000
16462306a36Sopenharmony_ci#define PMCRAID_IOASC_ME_READ_ERROR_NO_REALLOC		0x03110C00
16562306a36Sopenharmony_ci#define PMCRAID_IOASC_HW_CANNOT_COMMUNICATE		0x04050000
16662306a36Sopenharmony_ci#define PMCRAID_IOASC_HW_DEVICE_TIMEOUT			0x04080100
16762306a36Sopenharmony_ci#define PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR	0x04448500
16862306a36Sopenharmony_ci#define PMCRAID_IOASC_HW_IOA_RESET_REQUIRED		0x04448600
16962306a36Sopenharmony_ci#define PMCRAID_IOASC_IR_INVALID_RESOURCE_HANDLE        0x05250000
17062306a36Sopenharmony_ci#define PMCRAID_IOASC_AC_TERMINATED_BY_HOST		0x0B5A0000
17162306a36Sopenharmony_ci#define PMCRAID_IOASC_UA_BUS_WAS_RESET			0x06290000
17262306a36Sopenharmony_ci#define PMCRAID_IOASC_TIME_STAMP_OUT_OF_SYNC		0x06908B00
17362306a36Sopenharmony_ci#define PMCRAID_IOASC_UA_BUS_WAS_RESET_BY_OTHER		0x06298000
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci/* Driver defined IOASCs */
17662306a36Sopenharmony_ci#define PMCRAID_IOASC_IOA_WAS_RESET			0x10000001
17762306a36Sopenharmony_ci#define PMCRAID_IOASC_PCI_ACCESS_ERROR			0x10000002
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci/* Various timeout values (in milliseconds) used. If any of these are chip
18062306a36Sopenharmony_ci * specific, move them to pmcraid_chip_details structure.
18162306a36Sopenharmony_ci */
18262306a36Sopenharmony_ci#define PMCRAID_PCI_DEASSERT_TIMEOUT		2000
18362306a36Sopenharmony_ci#define PMCRAID_BIST_TIMEOUT			2000
18462306a36Sopenharmony_ci#define PMCRAID_AENWAIT_TIMEOUT			5000
18562306a36Sopenharmony_ci#define PMCRAID_TRANSOP_TIMEOUT			60000
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_ci#define PMCRAID_RESET_TIMEOUT			(2 * HZ)
18862306a36Sopenharmony_ci#define PMCRAID_CHECK_FOR_RESET_TIMEOUT		((HZ / 10))
18962306a36Sopenharmony_ci#define PMCRAID_VSET_IO_TIMEOUT			(60 * HZ)
19062306a36Sopenharmony_ci#define PMCRAID_INTERNAL_TIMEOUT		(60 * HZ)
19162306a36Sopenharmony_ci#define PMCRAID_SHUTDOWN_TIMEOUT		(150 * HZ)
19262306a36Sopenharmony_ci#define PMCRAID_RESET_BUS_TIMEOUT		(60 * HZ)
19362306a36Sopenharmony_ci#define PMCRAID_RESET_HOST_TIMEOUT		(150 * HZ)
19462306a36Sopenharmony_ci#define PMCRAID_REQUEST_SENSE_TIMEOUT		(30 * HZ)
19562306a36Sopenharmony_ci#define PMCRAID_SET_SUP_DEV_TIMEOUT		(2 * 60 * HZ)
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_ci/* structure to represent a scatter-gather element (IOADL descriptor) */
19862306a36Sopenharmony_cistruct pmcraid_ioadl_desc {
19962306a36Sopenharmony_ci	__le64 address;
20062306a36Sopenharmony_ci	__le32 data_len;
20162306a36Sopenharmony_ci	__u8  reserved[3];
20262306a36Sopenharmony_ci	__u8  flags;
20362306a36Sopenharmony_ci} __attribute__((packed, aligned(PMCRAID_IOADL_ALIGNMENT)));
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci/* pmcraid_ioadl_desc.flags values */
20662306a36Sopenharmony_ci#define IOADL_FLAGS_CHAINED      PMC_BIT8(0)
20762306a36Sopenharmony_ci#define IOADL_FLAGS_LAST_DESC    PMC_BIT8(1)
20862306a36Sopenharmony_ci#define IOADL_FLAGS_READ_LAST    PMC_BIT8(1)
20962306a36Sopenharmony_ci#define IOADL_FLAGS_WRITE_LAST   PMC_BIT8(1)
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_ci/* additional IOARCB data which can be CDB or additional request parameters
21362306a36Sopenharmony_ci * or list of IOADLs. Firmware supports max of 512 bytes for IOARCB, hence then
21462306a36Sopenharmony_ci * number of IOADLs are limted to 27. In case they are more than 27, they will
21562306a36Sopenharmony_ci * be used in chained form
21662306a36Sopenharmony_ci */
21762306a36Sopenharmony_cistruct pmcraid_ioarcb_add_data {
21862306a36Sopenharmony_ci	union {
21962306a36Sopenharmony_ci		struct pmcraid_ioadl_desc ioadl[PMCRAID_IOADLS_INTERNAL];
22062306a36Sopenharmony_ci		__u8 add_cmd_params[PMCRAID_ADD_CMD_PARAM_LEN];
22162306a36Sopenharmony_ci	} u;
22262306a36Sopenharmony_ci};
22362306a36Sopenharmony_ci
22462306a36Sopenharmony_ci/*
22562306a36Sopenharmony_ci * IOA Request Control Block
22662306a36Sopenharmony_ci */
22762306a36Sopenharmony_cistruct pmcraid_ioarcb {
22862306a36Sopenharmony_ci	__le64 ioarcb_bus_addr;
22962306a36Sopenharmony_ci	__le32 resource_handle;
23062306a36Sopenharmony_ci	__le32 response_handle;
23162306a36Sopenharmony_ci	__le64 ioadl_bus_addr;
23262306a36Sopenharmony_ci	__le32 ioadl_length;
23362306a36Sopenharmony_ci	__le32 data_transfer_length;
23462306a36Sopenharmony_ci	__le64 ioasa_bus_addr;
23562306a36Sopenharmony_ci	__le16 ioasa_len;
23662306a36Sopenharmony_ci	__le16 cmd_timeout;
23762306a36Sopenharmony_ci	__le16 add_cmd_param_offset;
23862306a36Sopenharmony_ci	__le16 add_cmd_param_length;
23962306a36Sopenharmony_ci	__le32 reserved1[2];
24062306a36Sopenharmony_ci	__le32 reserved2;
24162306a36Sopenharmony_ci	__u8  request_type;
24262306a36Sopenharmony_ci	__u8  request_flags0;
24362306a36Sopenharmony_ci	__u8  request_flags1;
24462306a36Sopenharmony_ci	__u8  hrrq_id;
24562306a36Sopenharmony_ci	__u8  cdb[PMCRAID_MAX_CDB_LEN];
24662306a36Sopenharmony_ci	struct pmcraid_ioarcb_add_data add_data;
24762306a36Sopenharmony_ci};
24862306a36Sopenharmony_ci
24962306a36Sopenharmony_ci/* well known resource handle values */
25062306a36Sopenharmony_ci#define PMCRAID_IOA_RES_HANDLE        0xffffffff
25162306a36Sopenharmony_ci#define PMCRAID_INVALID_RES_HANDLE    0
25262306a36Sopenharmony_ci
25362306a36Sopenharmony_ci/* pmcraid_ioarcb.request_type values */
25462306a36Sopenharmony_ci#define REQ_TYPE_SCSI                 0x00
25562306a36Sopenharmony_ci#define REQ_TYPE_IOACMD               0x01
25662306a36Sopenharmony_ci#define REQ_TYPE_HCAM                 0x02
25762306a36Sopenharmony_ci
25862306a36Sopenharmony_ci/* pmcraid_ioarcb.flags0 values */
25962306a36Sopenharmony_ci#define TRANSFER_DIR_WRITE            PMC_BIT8(0)
26062306a36Sopenharmony_ci#define INHIBIT_UL_CHECK              PMC_BIT8(2)
26162306a36Sopenharmony_ci#define SYNC_OVERRIDE                 PMC_BIT8(3)
26262306a36Sopenharmony_ci#define SYNC_COMPLETE                 PMC_BIT8(4)
26362306a36Sopenharmony_ci#define NO_LINK_DESCS                 PMC_BIT8(5)
26462306a36Sopenharmony_ci
26562306a36Sopenharmony_ci/* pmcraid_ioarcb.flags1 values */
26662306a36Sopenharmony_ci#define DELAY_AFTER_RESET             PMC_BIT8(0)
26762306a36Sopenharmony_ci#define TASK_TAG_SIMPLE               0x10
26862306a36Sopenharmony_ci#define TASK_TAG_ORDERED              0x20
26962306a36Sopenharmony_ci#define TASK_TAG_QUEUE_HEAD           0x30
27062306a36Sopenharmony_ci
27162306a36Sopenharmony_ci/* toggle bit offset in response handle */
27262306a36Sopenharmony_ci#define HRRQ_TOGGLE_BIT               0x01
27362306a36Sopenharmony_ci#define HRRQ_RESPONSE_BIT             0x02
27462306a36Sopenharmony_ci
27562306a36Sopenharmony_ci/* IOA Status Area */
27662306a36Sopenharmony_cistruct pmcraid_ioasa_vset {
27762306a36Sopenharmony_ci	__le32 failing_lba_hi;
27862306a36Sopenharmony_ci	__le32 failing_lba_lo;
27962306a36Sopenharmony_ci	__le32 reserved;
28062306a36Sopenharmony_ci} __attribute__((packed, aligned(4)));
28162306a36Sopenharmony_ci
28262306a36Sopenharmony_cistruct pmcraid_ioasa {
28362306a36Sopenharmony_ci	__le32 ioasc;
28462306a36Sopenharmony_ci	__le16 returned_status_length;
28562306a36Sopenharmony_ci	__le16 available_status_length;
28662306a36Sopenharmony_ci	__le32 residual_data_length;
28762306a36Sopenharmony_ci	__le32 ilid;
28862306a36Sopenharmony_ci	__le32 fd_ioasc;
28962306a36Sopenharmony_ci	__le32 fd_res_address;
29062306a36Sopenharmony_ci	__le32 fd_res_handle;
29162306a36Sopenharmony_ci	__le32 reserved;
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ci	/* resource specific sense information */
29462306a36Sopenharmony_ci	union {
29562306a36Sopenharmony_ci		struct pmcraid_ioasa_vset vset;
29662306a36Sopenharmony_ci	} u;
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ci	/* IOA autosense data */
29962306a36Sopenharmony_ci	__le16 auto_sense_length;
30062306a36Sopenharmony_ci	__le16 error_data_length;
30162306a36Sopenharmony_ci	__u8  sense_data[PMCRAID_SENSE_DATA_LEN];
30262306a36Sopenharmony_ci} __attribute__((packed, aligned(4)));
30362306a36Sopenharmony_ci
30462306a36Sopenharmony_ci#define PMCRAID_DRIVER_ILID           0xffffffff
30562306a36Sopenharmony_ci
30662306a36Sopenharmony_ci/* Config Table Entry per Resource */
30762306a36Sopenharmony_cistruct pmcraid_config_table_entry {
30862306a36Sopenharmony_ci	__u8  resource_type;
30962306a36Sopenharmony_ci	__u8  bus_protocol;
31062306a36Sopenharmony_ci	__le16 array_id;
31162306a36Sopenharmony_ci	__u8  common_flags0;
31262306a36Sopenharmony_ci	__u8  common_flags1;
31362306a36Sopenharmony_ci	__u8  unique_flags0;
31462306a36Sopenharmony_ci	__u8  unique_flags1;	/*also used as vset target_id */
31562306a36Sopenharmony_ci	__le32 resource_handle;
31662306a36Sopenharmony_ci	__le32 resource_address;
31762306a36Sopenharmony_ci	__u8  device_id[PMCRAID_DEVICE_ID_LEN];
31862306a36Sopenharmony_ci	__u8  lun[PMCRAID_LUN_LEN];
31962306a36Sopenharmony_ci} __attribute__((packed, aligned(4)));
32062306a36Sopenharmony_ci
32162306a36Sopenharmony_ci/* extended configuration table sizes are also of 32 bytes in size */
32262306a36Sopenharmony_cistruct pmcraid_config_table_entry_ext {
32362306a36Sopenharmony_ci	struct pmcraid_config_table_entry cfgte;
32462306a36Sopenharmony_ci};
32562306a36Sopenharmony_ci
32662306a36Sopenharmony_ci/* resource types (config_table_entry.resource_type values) */
32762306a36Sopenharmony_ci#define RES_TYPE_AF_DASD     0x00
32862306a36Sopenharmony_ci#define RES_TYPE_GSCSI       0x01
32962306a36Sopenharmony_ci#define RES_TYPE_VSET        0x02
33062306a36Sopenharmony_ci#define RES_TYPE_IOA_FP      0xFF
33162306a36Sopenharmony_ci
33262306a36Sopenharmony_ci#define RES_IS_IOA(res)      ((res).resource_type == RES_TYPE_IOA_FP)
33362306a36Sopenharmony_ci#define RES_IS_GSCSI(res)    ((res).resource_type == RES_TYPE_GSCSI)
33462306a36Sopenharmony_ci#define RES_IS_VSET(res)     ((res).resource_type == RES_TYPE_VSET)
33562306a36Sopenharmony_ci#define RES_IS_AFDASD(res)   ((res).resource_type == RES_TYPE_AF_DASD)
33662306a36Sopenharmony_ci
33762306a36Sopenharmony_ci/* bus_protocol values used by driver */
33862306a36Sopenharmony_ci#define RES_TYPE_VENCLOSURE  0x8
33962306a36Sopenharmony_ci
34062306a36Sopenharmony_ci/* config_table_entry.common_flags0 */
34162306a36Sopenharmony_ci#define MULTIPATH_RESOURCE   PMC_BIT32(0)
34262306a36Sopenharmony_ci
34362306a36Sopenharmony_ci/* unique_flags1 */
34462306a36Sopenharmony_ci#define IMPORT_MODE_MANUAL   PMC_BIT8(0)
34562306a36Sopenharmony_ci
34662306a36Sopenharmony_ci/* well known resource handle values */
34762306a36Sopenharmony_ci#define RES_HANDLE_IOA       0xFFFFFFFF
34862306a36Sopenharmony_ci#define RES_HANDLE_NONE      0x00000000
34962306a36Sopenharmony_ci
35062306a36Sopenharmony_ci/* well known resource address values */
35162306a36Sopenharmony_ci#define RES_ADDRESS_IOAFP    0xFEFFFFFF
35262306a36Sopenharmony_ci#define RES_ADDRESS_INVALID  0xFFFFFFFF
35362306a36Sopenharmony_ci
35462306a36Sopenharmony_ci/* BUS/TARGET/LUN values from resource_addrr */
35562306a36Sopenharmony_ci#define RES_BUS(res_addr)    (le32_to_cpu(res_addr) & 0xFF)
35662306a36Sopenharmony_ci#define RES_TARGET(res_addr) ((le32_to_cpu(res_addr) >> 16) & 0xFF)
35762306a36Sopenharmony_ci#define RES_LUN(res_addr)    0x0
35862306a36Sopenharmony_ci
35962306a36Sopenharmony_ci/* configuration table structure */
36062306a36Sopenharmony_cistruct pmcraid_config_table {
36162306a36Sopenharmony_ci	__le16 num_entries;
36262306a36Sopenharmony_ci	__u8  table_format;
36362306a36Sopenharmony_ci	__u8  reserved1;
36462306a36Sopenharmony_ci	__u8  flags;
36562306a36Sopenharmony_ci	__u8  reserved2[11];
36662306a36Sopenharmony_ci	union {
36762306a36Sopenharmony_ci		struct pmcraid_config_table_entry
36862306a36Sopenharmony_ci				entries[PMCRAID_MAX_RESOURCES];
36962306a36Sopenharmony_ci		struct pmcraid_config_table_entry_ext
37062306a36Sopenharmony_ci				entries_ext[PMCRAID_MAX_RESOURCES];
37162306a36Sopenharmony_ci	};
37262306a36Sopenharmony_ci} __attribute__((packed, aligned(4)));
37362306a36Sopenharmony_ci
37462306a36Sopenharmony_ci/* config_table.flags value */
37562306a36Sopenharmony_ci#define MICROCODE_UPDATE_REQUIRED		PMC_BIT32(0)
37662306a36Sopenharmony_ci
37762306a36Sopenharmony_ci/*
37862306a36Sopenharmony_ci * HCAM format
37962306a36Sopenharmony_ci */
38062306a36Sopenharmony_ci#define PMCRAID_HOSTRCB_LDNSIZE			4056
38162306a36Sopenharmony_ci
38262306a36Sopenharmony_ci/* Error log notification format */
38362306a36Sopenharmony_cistruct pmcraid_hostrcb_error {
38462306a36Sopenharmony_ci	__le32 fd_ioasc;
38562306a36Sopenharmony_ci	__le32 fd_ra;
38662306a36Sopenharmony_ci	__le32 fd_rh;
38762306a36Sopenharmony_ci	__le32 prc;
38862306a36Sopenharmony_ci	union {
38962306a36Sopenharmony_ci		__u8 data[PMCRAID_HOSTRCB_LDNSIZE];
39062306a36Sopenharmony_ci	} u;
39162306a36Sopenharmony_ci} __attribute__ ((packed, aligned(4)));
39262306a36Sopenharmony_ci
39362306a36Sopenharmony_cistruct pmcraid_hcam_hdr {
39462306a36Sopenharmony_ci	__u8  op_code;
39562306a36Sopenharmony_ci	__u8  notification_type;
39662306a36Sopenharmony_ci	__u8  notification_lost;
39762306a36Sopenharmony_ci	__u8  flags;
39862306a36Sopenharmony_ci	__u8  overlay_id;
39962306a36Sopenharmony_ci	__u8  reserved1[3];
40062306a36Sopenharmony_ci	__le32 ilid;
40162306a36Sopenharmony_ci	__le32 timestamp1;
40262306a36Sopenharmony_ci	__le32 timestamp2;
40362306a36Sopenharmony_ci	__le32 data_len;
40462306a36Sopenharmony_ci} __attribute__((packed, aligned(4)));
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_ci#define PMCRAID_AEN_GROUP	0x3
40762306a36Sopenharmony_ci
40862306a36Sopenharmony_cistruct pmcraid_hcam_ccn {
40962306a36Sopenharmony_ci	struct pmcraid_hcam_hdr header;
41062306a36Sopenharmony_ci	struct pmcraid_config_table_entry cfg_entry;
41162306a36Sopenharmony_ci	struct pmcraid_config_table_entry cfg_entry_old;
41262306a36Sopenharmony_ci} __attribute__((packed, aligned(4)));
41362306a36Sopenharmony_ci
41462306a36Sopenharmony_ci#define PMCRAID_CCN_EXT_SIZE	3944
41562306a36Sopenharmony_cistruct pmcraid_hcam_ccn_ext {
41662306a36Sopenharmony_ci	struct pmcraid_hcam_hdr header;
41762306a36Sopenharmony_ci	struct pmcraid_config_table_entry_ext cfg_entry;
41862306a36Sopenharmony_ci	struct pmcraid_config_table_entry_ext cfg_entry_old;
41962306a36Sopenharmony_ci	__u8   reserved[PMCRAID_CCN_EXT_SIZE];
42062306a36Sopenharmony_ci} __attribute__((packed, aligned(4)));
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_cistruct pmcraid_hcam_ldn {
42362306a36Sopenharmony_ci	struct pmcraid_hcam_hdr header;
42462306a36Sopenharmony_ci	struct pmcraid_hostrcb_error error_log;
42562306a36Sopenharmony_ci} __attribute__((packed, aligned(4)));
42662306a36Sopenharmony_ci
42762306a36Sopenharmony_ci/* pmcraid_hcam.op_code values */
42862306a36Sopenharmony_ci#define HOSTRCB_TYPE_CCN			0xE1
42962306a36Sopenharmony_ci#define HOSTRCB_TYPE_LDN			0xE2
43062306a36Sopenharmony_ci
43162306a36Sopenharmony_ci/* pmcraid_hcam.notification_type values */
43262306a36Sopenharmony_ci#define NOTIFICATION_TYPE_ENTRY_CHANGED		0x0
43362306a36Sopenharmony_ci#define NOTIFICATION_TYPE_ENTRY_NEW		0x1
43462306a36Sopenharmony_ci#define NOTIFICATION_TYPE_ENTRY_DELETED		0x2
43562306a36Sopenharmony_ci#define NOTIFICATION_TYPE_STATE_CHANGE		0x3
43662306a36Sopenharmony_ci#define NOTIFICATION_TYPE_ENTRY_STATECHANGED	0x4
43762306a36Sopenharmony_ci#define NOTIFICATION_TYPE_ERROR_LOG		0x10
43862306a36Sopenharmony_ci#define NOTIFICATION_TYPE_INFORMATION_LOG	0x11
43962306a36Sopenharmony_ci
44062306a36Sopenharmony_ci#define HOSTRCB_NOTIFICATIONS_LOST		PMC_BIT8(0)
44162306a36Sopenharmony_ci
44262306a36Sopenharmony_ci/* pmcraid_hcam.flags values */
44362306a36Sopenharmony_ci#define HOSTRCB_INTERNAL_OP_ERROR		PMC_BIT8(0)
44462306a36Sopenharmony_ci#define HOSTRCB_ERROR_RESPONSE_SENT		PMC_BIT8(1)
44562306a36Sopenharmony_ci
44662306a36Sopenharmony_ci/* pmcraid_hcam.overlay_id values */
44762306a36Sopenharmony_ci#define HOSTRCB_OVERLAY_ID_08			0x08
44862306a36Sopenharmony_ci#define HOSTRCB_OVERLAY_ID_09			0x09
44962306a36Sopenharmony_ci#define HOSTRCB_OVERLAY_ID_11			0x11
45062306a36Sopenharmony_ci#define HOSTRCB_OVERLAY_ID_12			0x12
45162306a36Sopenharmony_ci#define HOSTRCB_OVERLAY_ID_13			0x13
45262306a36Sopenharmony_ci#define HOSTRCB_OVERLAY_ID_14			0x14
45362306a36Sopenharmony_ci#define HOSTRCB_OVERLAY_ID_16			0x16
45462306a36Sopenharmony_ci#define HOSTRCB_OVERLAY_ID_17			0x17
45562306a36Sopenharmony_ci#define HOSTRCB_OVERLAY_ID_20			0x20
45662306a36Sopenharmony_ci#define HOSTRCB_OVERLAY_ID_FF			0xFF
45762306a36Sopenharmony_ci
45862306a36Sopenharmony_ci/* Implementation specific card details */
45962306a36Sopenharmony_cistruct pmcraid_chip_details {
46062306a36Sopenharmony_ci	/* hardware register offsets */
46162306a36Sopenharmony_ci	unsigned long  ioastatus;
46262306a36Sopenharmony_ci	unsigned long  ioarrin;
46362306a36Sopenharmony_ci	unsigned long  mailbox;
46462306a36Sopenharmony_ci	unsigned long  global_intr_mask;
46562306a36Sopenharmony_ci	unsigned long  ioa_host_intr;
46662306a36Sopenharmony_ci	unsigned long  ioa_host_msix_intr;
46762306a36Sopenharmony_ci	unsigned long  ioa_host_intr_clr;
46862306a36Sopenharmony_ci	unsigned long  ioa_host_mask;
46962306a36Sopenharmony_ci	unsigned long  ioa_host_mask_clr;
47062306a36Sopenharmony_ci	unsigned long  host_ioa_intr;
47162306a36Sopenharmony_ci	unsigned long  host_ioa_intr_clr;
47262306a36Sopenharmony_ci
47362306a36Sopenharmony_ci	/* timeout used during transitional to operational state */
47462306a36Sopenharmony_ci	unsigned long transop_timeout;
47562306a36Sopenharmony_ci};
47662306a36Sopenharmony_ci
47762306a36Sopenharmony_ci/* IOA to HOST doorbells (interrupts) */
47862306a36Sopenharmony_ci#define INTRS_TRANSITION_TO_OPERATIONAL		PMC_BIT32(0)
47962306a36Sopenharmony_ci#define INTRS_IOARCB_TRANSFER_FAILED		PMC_BIT32(3)
48062306a36Sopenharmony_ci#define INTRS_IOA_UNIT_CHECK			PMC_BIT32(4)
48162306a36Sopenharmony_ci#define INTRS_NO_HRRQ_FOR_CMD_RESPONSE		PMC_BIT32(5)
48262306a36Sopenharmony_ci#define INTRS_CRITICAL_OP_IN_PROGRESS		PMC_BIT32(6)
48362306a36Sopenharmony_ci#define INTRS_IO_DEBUG_ACK			PMC_BIT32(7)
48462306a36Sopenharmony_ci#define INTRS_IOARRIN_LOST			PMC_BIT32(27)
48562306a36Sopenharmony_ci#define INTRS_SYSTEM_BUS_MMIO_ERROR		PMC_BIT32(28)
48662306a36Sopenharmony_ci#define INTRS_IOA_PROCESSOR_ERROR		PMC_BIT32(29)
48762306a36Sopenharmony_ci#define INTRS_HRRQ_VALID			PMC_BIT32(30)
48862306a36Sopenharmony_ci#define INTRS_OPERATIONAL_STATUS		PMC_BIT32(0)
48962306a36Sopenharmony_ci#define INTRS_ALLOW_MSIX_VECTOR0		PMC_BIT32(31)
49062306a36Sopenharmony_ci
49162306a36Sopenharmony_ci/* Host to IOA Doorbells */
49262306a36Sopenharmony_ci#define DOORBELL_RUNTIME_RESET			PMC_BIT32(1)
49362306a36Sopenharmony_ci#define DOORBELL_IOA_RESET_ALERT		PMC_BIT32(7)
49462306a36Sopenharmony_ci#define DOORBELL_IOA_DEBUG_ALERT		PMC_BIT32(9)
49562306a36Sopenharmony_ci#define DOORBELL_ENABLE_DESTRUCTIVE_DIAGS	PMC_BIT32(8)
49662306a36Sopenharmony_ci#define DOORBELL_IOA_START_BIST			PMC_BIT32(23)
49762306a36Sopenharmony_ci#define DOORBELL_INTR_MODE_MSIX			PMC_BIT32(25)
49862306a36Sopenharmony_ci#define DOORBELL_INTR_MSIX_CLR			PMC_BIT32(26)
49962306a36Sopenharmony_ci#define DOORBELL_RESET_IOA			PMC_BIT32(31)
50062306a36Sopenharmony_ci
50162306a36Sopenharmony_ci/* Global interrupt mask register value */
50262306a36Sopenharmony_ci#define GLOBAL_INTERRUPT_MASK			0x5ULL
50362306a36Sopenharmony_ci
50462306a36Sopenharmony_ci#define PMCRAID_ERROR_INTERRUPTS	(INTRS_IOARCB_TRANSFER_FAILED | \
50562306a36Sopenharmony_ci					 INTRS_IOA_UNIT_CHECK | \
50662306a36Sopenharmony_ci					 INTRS_NO_HRRQ_FOR_CMD_RESPONSE | \
50762306a36Sopenharmony_ci					 INTRS_IOARRIN_LOST | \
50862306a36Sopenharmony_ci					 INTRS_SYSTEM_BUS_MMIO_ERROR | \
50962306a36Sopenharmony_ci					 INTRS_IOA_PROCESSOR_ERROR)
51062306a36Sopenharmony_ci
51162306a36Sopenharmony_ci#define PMCRAID_PCI_INTERRUPTS		(PMCRAID_ERROR_INTERRUPTS | \
51262306a36Sopenharmony_ci					 INTRS_HRRQ_VALID | \
51362306a36Sopenharmony_ci					 INTRS_TRANSITION_TO_OPERATIONAL |\
51462306a36Sopenharmony_ci					 INTRS_ALLOW_MSIX_VECTOR0)
51562306a36Sopenharmony_ci
51662306a36Sopenharmony_ci/* control_block, associated with each of the commands contains IOARCB, IOADLs
51762306a36Sopenharmony_ci * memory for IOASA. Additional 3 * 16 bytes are allocated in order to support
51862306a36Sopenharmony_ci * additional request parameters (of max size 48) any command.
51962306a36Sopenharmony_ci */
52062306a36Sopenharmony_cistruct pmcraid_control_block {
52162306a36Sopenharmony_ci	struct pmcraid_ioarcb ioarcb;
52262306a36Sopenharmony_ci	struct pmcraid_ioadl_desc ioadl[PMCRAID_IOADLS_EXTERNAL + 3];
52362306a36Sopenharmony_ci	struct pmcraid_ioasa ioasa;
52462306a36Sopenharmony_ci} __attribute__ ((packed, aligned(PMCRAID_IOARCB_ALIGNMENT)));
52562306a36Sopenharmony_ci
52662306a36Sopenharmony_ci/* pmcraid_sglist - Scatter-gather list allocated for passthrough ioctls
52762306a36Sopenharmony_ci */
52862306a36Sopenharmony_cistruct pmcraid_sglist {
52962306a36Sopenharmony_ci	u32 order;
53062306a36Sopenharmony_ci	u32 num_sg;
53162306a36Sopenharmony_ci	u32 num_dma_sg;
53262306a36Sopenharmony_ci	struct scatterlist *scatterlist;
53362306a36Sopenharmony_ci};
53462306a36Sopenharmony_ci
53562306a36Sopenharmony_ci/* page D0 inquiry data of focal point resource */
53662306a36Sopenharmony_cistruct pmcraid_inquiry_data {
53762306a36Sopenharmony_ci	__u8	ph_dev_type;
53862306a36Sopenharmony_ci	__u8	page_code;
53962306a36Sopenharmony_ci	__u8	reserved1;
54062306a36Sopenharmony_ci	__u8	add_page_len;
54162306a36Sopenharmony_ci	__u8	length;
54262306a36Sopenharmony_ci	__u8	reserved2;
54362306a36Sopenharmony_ci	__be16	fw_version;
54462306a36Sopenharmony_ci	__u8	reserved3[16];
54562306a36Sopenharmony_ci};
54662306a36Sopenharmony_ci
54762306a36Sopenharmony_ci#define PMCRAID_TIMESTAMP_LEN		12
54862306a36Sopenharmony_ci#define PMCRAID_REQ_TM_STR_LEN		6
54962306a36Sopenharmony_ci#define PMCRAID_SCSI_SET_TIMESTAMP	0xA4
55062306a36Sopenharmony_ci#define PMCRAID_SCSI_SERVICE_ACTION	0x0F
55162306a36Sopenharmony_ci
55262306a36Sopenharmony_cistruct pmcraid_timestamp_data {
55362306a36Sopenharmony_ci	__u8 reserved1[4];
55462306a36Sopenharmony_ci	__u8 timestamp[PMCRAID_REQ_TM_STR_LEN];		/* current time value */
55562306a36Sopenharmony_ci	__u8 reserved2[2];
55662306a36Sopenharmony_ci};
55762306a36Sopenharmony_ci
55862306a36Sopenharmony_ci/* pmcraid_cmd - LLD representation of SCSI command */
55962306a36Sopenharmony_cistruct pmcraid_cmd {
56062306a36Sopenharmony_ci
56162306a36Sopenharmony_ci	/* Ptr and bus address of DMA.able control block for this command */
56262306a36Sopenharmony_ci	struct pmcraid_control_block *ioa_cb;
56362306a36Sopenharmony_ci	dma_addr_t ioa_cb_bus_addr;
56462306a36Sopenharmony_ci	dma_addr_t dma_handle;
56562306a36Sopenharmony_ci
56662306a36Sopenharmony_ci	/* pointer to mid layer structure of SCSI commands */
56762306a36Sopenharmony_ci	struct scsi_cmnd *scsi_cmd;
56862306a36Sopenharmony_ci
56962306a36Sopenharmony_ci	struct list_head free_list;
57062306a36Sopenharmony_ci	struct completion wait_for_completion;
57162306a36Sopenharmony_ci	struct timer_list timer;	/* needed for internal commands */
57262306a36Sopenharmony_ci	u32 timeout;			/* current timeout value */
57362306a36Sopenharmony_ci	u32 index;			/* index into the command list */
57462306a36Sopenharmony_ci	u8 completion_req;		/* for handling internal commands */
57562306a36Sopenharmony_ci	u8 release;			/* for handling completions */
57662306a36Sopenharmony_ci
57762306a36Sopenharmony_ci	void (*cmd_done) (struct pmcraid_cmd *);
57862306a36Sopenharmony_ci	struct pmcraid_instance *drv_inst;
57962306a36Sopenharmony_ci
58062306a36Sopenharmony_ci	struct pmcraid_sglist *sglist; /* used for passthrough IOCTLs */
58162306a36Sopenharmony_ci
58262306a36Sopenharmony_ci	/* scratch used */
58362306a36Sopenharmony_ci	union {
58462306a36Sopenharmony_ci		/* during reset sequence */
58562306a36Sopenharmony_ci		unsigned long time_left;
58662306a36Sopenharmony_ci		struct pmcraid_resource_entry *res;
58762306a36Sopenharmony_ci		int hrrq_index;
58862306a36Sopenharmony_ci
58962306a36Sopenharmony_ci		/* used during IO command error handling. Sense buffer
59062306a36Sopenharmony_ci		 * for REQUEST SENSE command if firmware is not sending
59162306a36Sopenharmony_ci		 * auto sense data
59262306a36Sopenharmony_ci		 */
59362306a36Sopenharmony_ci		struct  {
59462306a36Sopenharmony_ci			u8 *sense_buffer;
59562306a36Sopenharmony_ci			dma_addr_t sense_buffer_dma;
59662306a36Sopenharmony_ci		};
59762306a36Sopenharmony_ci	};
59862306a36Sopenharmony_ci};
59962306a36Sopenharmony_ci
60062306a36Sopenharmony_ci/*
60162306a36Sopenharmony_ci * Interrupt registers of IOA
60262306a36Sopenharmony_ci */
60362306a36Sopenharmony_cistruct pmcraid_interrupts {
60462306a36Sopenharmony_ci	void __iomem *ioa_host_interrupt_reg;
60562306a36Sopenharmony_ci	void __iomem *ioa_host_msix_interrupt_reg;
60662306a36Sopenharmony_ci	void __iomem *ioa_host_interrupt_clr_reg;
60762306a36Sopenharmony_ci	void __iomem *ioa_host_interrupt_mask_reg;
60862306a36Sopenharmony_ci	void __iomem *ioa_host_interrupt_mask_clr_reg;
60962306a36Sopenharmony_ci	void __iomem *global_interrupt_mask_reg;
61062306a36Sopenharmony_ci	void __iomem *host_ioa_interrupt_reg;
61162306a36Sopenharmony_ci	void __iomem *host_ioa_interrupt_clr_reg;
61262306a36Sopenharmony_ci};
61362306a36Sopenharmony_ci
61462306a36Sopenharmony_ci/* ISR parameters LLD allocates (one for each MSI-X if enabled) vectors */
61562306a36Sopenharmony_cistruct pmcraid_isr_param {
61662306a36Sopenharmony_ci	struct pmcraid_instance *drv_inst;
61762306a36Sopenharmony_ci	u8 hrrq_id;			/* hrrq entry index */
61862306a36Sopenharmony_ci};
61962306a36Sopenharmony_ci
62062306a36Sopenharmony_ci
62162306a36Sopenharmony_ci/* AEN message header sent as part of event data to applications */
62262306a36Sopenharmony_cistruct pmcraid_aen_msg {
62362306a36Sopenharmony_ci	u32 hostno;
62462306a36Sopenharmony_ci	u32 length;
62562306a36Sopenharmony_ci	u8  reserved[8];
62662306a36Sopenharmony_ci	u8  data[];
62762306a36Sopenharmony_ci};
62862306a36Sopenharmony_ci
62962306a36Sopenharmony_ci/* Controller state event message type */
63062306a36Sopenharmony_cistruct pmcraid_state_msg {
63162306a36Sopenharmony_ci	struct pmcraid_aen_msg msg;
63262306a36Sopenharmony_ci	u32 ioa_state;
63362306a36Sopenharmony_ci};
63462306a36Sopenharmony_ci
63562306a36Sopenharmony_ci#define PMC_DEVICE_EVENT_RESET_START		0x11000000
63662306a36Sopenharmony_ci#define PMC_DEVICE_EVENT_RESET_SUCCESS		0x11000001
63762306a36Sopenharmony_ci#define PMC_DEVICE_EVENT_RESET_FAILED		0x11000002
63862306a36Sopenharmony_ci#define PMC_DEVICE_EVENT_SHUTDOWN_START		0x11000003
63962306a36Sopenharmony_ci#define PMC_DEVICE_EVENT_SHUTDOWN_SUCCESS	0x11000004
64062306a36Sopenharmony_ci#define PMC_DEVICE_EVENT_SHUTDOWN_FAILED	0x11000005
64162306a36Sopenharmony_ci
64262306a36Sopenharmony_cistruct pmcraid_hostrcb {
64362306a36Sopenharmony_ci	struct pmcraid_instance *drv_inst;
64462306a36Sopenharmony_ci	struct pmcraid_aen_msg *msg;
64562306a36Sopenharmony_ci	struct pmcraid_hcam_hdr *hcam;	/* pointer to hcam buffer */
64662306a36Sopenharmony_ci	struct pmcraid_cmd  *cmd;       /* pointer to command block used */
64762306a36Sopenharmony_ci	dma_addr_t baddr;		/* system address of hcam buffer */
64862306a36Sopenharmony_ci	atomic_t ignore;		/* process HCAM response ? */
64962306a36Sopenharmony_ci};
65062306a36Sopenharmony_ci
65162306a36Sopenharmony_ci#define PMCRAID_AEN_HDR_SIZE	sizeof(struct pmcraid_aen_msg)
65262306a36Sopenharmony_ci
65362306a36Sopenharmony_ci
65462306a36Sopenharmony_ci
65562306a36Sopenharmony_ci/*
65662306a36Sopenharmony_ci * Per adapter structure maintained by LLD
65762306a36Sopenharmony_ci */
65862306a36Sopenharmony_cistruct pmcraid_instance {
65962306a36Sopenharmony_ci	/* Array of allowed-to-be-exposed resources, initialized from
66062306a36Sopenharmony_ci	 * Configutation Table, later updated with CCNs
66162306a36Sopenharmony_ci	 */
66262306a36Sopenharmony_ci	struct pmcraid_resource_entry *res_entries;
66362306a36Sopenharmony_ci
66462306a36Sopenharmony_ci	struct list_head free_res_q;	/* res_entries lists for easy lookup */
66562306a36Sopenharmony_ci	struct list_head used_res_q;	/* List of to be exposed resources */
66662306a36Sopenharmony_ci	spinlock_t resource_lock;	/* spinlock to protect resource list */
66762306a36Sopenharmony_ci
66862306a36Sopenharmony_ci	void __iomem *mapped_dma_addr;
66962306a36Sopenharmony_ci	void __iomem *ioa_status;	/* Iomapped IOA status register */
67062306a36Sopenharmony_ci	void __iomem *mailbox;		/* Iomapped mailbox register */
67162306a36Sopenharmony_ci	void __iomem *ioarrin;		/* IOmapped IOARR IN register */
67262306a36Sopenharmony_ci
67362306a36Sopenharmony_ci	struct pmcraid_interrupts int_regs;
67462306a36Sopenharmony_ci	struct pmcraid_chip_details *chip_cfg;
67562306a36Sopenharmony_ci
67662306a36Sopenharmony_ci	/* HostRCBs needed for HCAM */
67762306a36Sopenharmony_ci	struct pmcraid_hostrcb ldn;
67862306a36Sopenharmony_ci	struct pmcraid_hostrcb ccn;
67962306a36Sopenharmony_ci	struct pmcraid_state_msg scn;	/* controller state change msg */
68062306a36Sopenharmony_ci
68162306a36Sopenharmony_ci
68262306a36Sopenharmony_ci	/* Bus address of start of HRRQ */
68362306a36Sopenharmony_ci	dma_addr_t hrrq_start_bus_addr[PMCRAID_NUM_MSIX_VECTORS];
68462306a36Sopenharmony_ci
68562306a36Sopenharmony_ci	/* Pointer to 1st entry of HRRQ */
68662306a36Sopenharmony_ci	__le32 *hrrq_start[PMCRAID_NUM_MSIX_VECTORS];
68762306a36Sopenharmony_ci
68862306a36Sopenharmony_ci	/* Pointer to last entry of HRRQ */
68962306a36Sopenharmony_ci	__le32 *hrrq_end[PMCRAID_NUM_MSIX_VECTORS];
69062306a36Sopenharmony_ci
69162306a36Sopenharmony_ci	/* Pointer to current pointer of hrrq */
69262306a36Sopenharmony_ci	__le32 *hrrq_curr[PMCRAID_NUM_MSIX_VECTORS];
69362306a36Sopenharmony_ci
69462306a36Sopenharmony_ci	/* Lock for HRRQ access */
69562306a36Sopenharmony_ci	spinlock_t hrrq_lock[PMCRAID_NUM_MSIX_VECTORS];
69662306a36Sopenharmony_ci
69762306a36Sopenharmony_ci	struct pmcraid_inquiry_data *inq_data;
69862306a36Sopenharmony_ci	dma_addr_t  inq_data_baddr;
69962306a36Sopenharmony_ci
70062306a36Sopenharmony_ci	struct pmcraid_timestamp_data *timestamp_data;
70162306a36Sopenharmony_ci	dma_addr_t  timestamp_data_baddr;
70262306a36Sopenharmony_ci
70362306a36Sopenharmony_ci	/* size of configuration table entry, varies based on the firmware */
70462306a36Sopenharmony_ci	u32	config_table_entry_size;
70562306a36Sopenharmony_ci
70662306a36Sopenharmony_ci	/* Expected toggle bit at host */
70762306a36Sopenharmony_ci	u8 host_toggle_bit[PMCRAID_NUM_MSIX_VECTORS];
70862306a36Sopenharmony_ci
70962306a36Sopenharmony_ci
71062306a36Sopenharmony_ci	/* Wait Q for  threads to wait for Reset IOA completion */
71162306a36Sopenharmony_ci	wait_queue_head_t reset_wait_q;
71262306a36Sopenharmony_ci	struct pmcraid_cmd *reset_cmd;
71362306a36Sopenharmony_ci
71462306a36Sopenharmony_ci	/* structures for supporting SIGIO based AEN. */
71562306a36Sopenharmony_ci	struct fasync_struct *aen_queue;
71662306a36Sopenharmony_ci	struct mutex aen_queue_lock;	/* lock for aen subscribers list */
71762306a36Sopenharmony_ci	struct cdev cdev;
71862306a36Sopenharmony_ci
71962306a36Sopenharmony_ci	struct Scsi_Host *host;	/* mid layer interface structure handle */
72062306a36Sopenharmony_ci	struct pci_dev *pdev;	/* PCI device structure handle */
72162306a36Sopenharmony_ci
72262306a36Sopenharmony_ci	/* No of Reset IOA retries . IOA marked dead if threshold exceeds */
72362306a36Sopenharmony_ci	u8 ioa_reset_attempts;
72462306a36Sopenharmony_ci#define PMCRAID_RESET_ATTEMPTS 3
72562306a36Sopenharmony_ci
72662306a36Sopenharmony_ci	u8  current_log_level;	/* default level for logging IOASC errors */
72762306a36Sopenharmony_ci
72862306a36Sopenharmony_ci	u8  num_hrrq;		/* Number of interrupt vectors allocated */
72962306a36Sopenharmony_ci	u8  interrupt_mode;	/* current interrupt mode legacy or msix */
73062306a36Sopenharmony_ci	dev_t dev;		/* Major-Minor numbers for Char device */
73162306a36Sopenharmony_ci
73262306a36Sopenharmony_ci	/* Used as ISR handler argument */
73362306a36Sopenharmony_ci	struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
73462306a36Sopenharmony_ci
73562306a36Sopenharmony_ci	/* Message id as filled in last fired IOARCB, used to identify HRRQ */
73662306a36Sopenharmony_ci	atomic_t last_message_id;
73762306a36Sopenharmony_ci
73862306a36Sopenharmony_ci	/* configuration table */
73962306a36Sopenharmony_ci	struct pmcraid_config_table *cfg_table;
74062306a36Sopenharmony_ci	dma_addr_t cfg_table_bus_addr;
74162306a36Sopenharmony_ci
74262306a36Sopenharmony_ci	/* structures related to command blocks */
74362306a36Sopenharmony_ci	struct kmem_cache *cmd_cachep;		/* cache for cmd blocks */
74462306a36Sopenharmony_ci	struct dma_pool *control_pool;		/* pool for control blocks */
74562306a36Sopenharmony_ci	char   cmd_pool_name[64];		/* name of cmd cache */
74662306a36Sopenharmony_ci	char   ctl_pool_name[64];		/* name of control cache */
74762306a36Sopenharmony_ci
74862306a36Sopenharmony_ci	struct pmcraid_cmd *cmd_list[PMCRAID_MAX_CMD];
74962306a36Sopenharmony_ci
75062306a36Sopenharmony_ci	struct list_head free_cmd_pool;
75162306a36Sopenharmony_ci	struct list_head pending_cmd_pool;
75262306a36Sopenharmony_ci	spinlock_t free_pool_lock;		/* free pool lock */
75362306a36Sopenharmony_ci	spinlock_t pending_pool_lock;		/* pending pool lock */
75462306a36Sopenharmony_ci
75562306a36Sopenharmony_ci	/* Tasklet to handle deferred processing */
75662306a36Sopenharmony_ci	struct tasklet_struct isr_tasklet[PMCRAID_NUM_MSIX_VECTORS];
75762306a36Sopenharmony_ci
75862306a36Sopenharmony_ci	/* Work-queue (Shared) for deferred reset processing */
75962306a36Sopenharmony_ci	struct work_struct worker_q;
76062306a36Sopenharmony_ci
76162306a36Sopenharmony_ci	/* No of IO commands pending with FW */
76262306a36Sopenharmony_ci	atomic_t outstanding_cmds;
76362306a36Sopenharmony_ci
76462306a36Sopenharmony_ci	/* should add/delete resources to mid-layer now ?*/
76562306a36Sopenharmony_ci	atomic_t expose_resources;
76662306a36Sopenharmony_ci
76762306a36Sopenharmony_ci
76862306a36Sopenharmony_ci
76962306a36Sopenharmony_ci	u32 ioa_state:4;	/* For IOA Reset sequence FSM */
77062306a36Sopenharmony_ci#define IOA_STATE_OPERATIONAL       0x0
77162306a36Sopenharmony_ci#define IOA_STATE_UNKNOWN           0x1
77262306a36Sopenharmony_ci#define IOA_STATE_DEAD              0x2
77362306a36Sopenharmony_ci#define IOA_STATE_IN_SOFT_RESET     0x3
77462306a36Sopenharmony_ci#define IOA_STATE_IN_HARD_RESET     0x4
77562306a36Sopenharmony_ci#define IOA_STATE_IN_RESET_ALERT    0x5
77662306a36Sopenharmony_ci#define IOA_STATE_IN_BRINGDOWN      0x6
77762306a36Sopenharmony_ci#define IOA_STATE_IN_BRINGUP        0x7
77862306a36Sopenharmony_ci
77962306a36Sopenharmony_ci	u32 ioa_reset_in_progress:1; /* true if IOA reset is in progress */
78062306a36Sopenharmony_ci	u32 ioa_hard_reset:1;	/* TRUE if Hard Reset is needed */
78162306a36Sopenharmony_ci	u32 ioa_unit_check:1;	/* Indicates Unit Check condition */
78262306a36Sopenharmony_ci	u32 ioa_bringdown:1;	/* whether IOA needs to be brought down */
78362306a36Sopenharmony_ci	u32 force_ioa_reset:1;  /* force adapter reset ? */
78462306a36Sopenharmony_ci	u32 reinit_cfg_table:1; /* reinit config table due to lost CCN */
78562306a36Sopenharmony_ci	u32 ioa_shutdown_type:2;/* shutdown type used during reset */
78662306a36Sopenharmony_ci#define SHUTDOWN_NONE               0x0
78762306a36Sopenharmony_ci#define SHUTDOWN_NORMAL             0x1
78862306a36Sopenharmony_ci#define SHUTDOWN_ABBREV             0x2
78962306a36Sopenharmony_ci	u32 timestamp_error:1; /* indicate set timestamp for out of sync */
79062306a36Sopenharmony_ci
79162306a36Sopenharmony_ci};
79262306a36Sopenharmony_ci
79362306a36Sopenharmony_ci/* LLD maintained resource entry structure */
79462306a36Sopenharmony_cistruct pmcraid_resource_entry {
79562306a36Sopenharmony_ci	struct list_head queue;	/* link to "to be exposed" resources */
79662306a36Sopenharmony_ci	union {
79762306a36Sopenharmony_ci		struct pmcraid_config_table_entry cfg_entry;
79862306a36Sopenharmony_ci		struct pmcraid_config_table_entry_ext cfg_entry_ext;
79962306a36Sopenharmony_ci	};
80062306a36Sopenharmony_ci	struct scsi_device *scsi_dev;	/* Link scsi_device structure */
80162306a36Sopenharmony_ci	atomic_t read_failures;		/* count of failed READ commands */
80262306a36Sopenharmony_ci	atomic_t write_failures;	/* count of failed WRITE commands */
80362306a36Sopenharmony_ci
80462306a36Sopenharmony_ci	/* To indicate add/delete/modify during CCN */
80562306a36Sopenharmony_ci	u8 change_detected;
80662306a36Sopenharmony_ci#define RES_CHANGE_ADD          0x1	/* add this to mid-layer */
80762306a36Sopenharmony_ci#define RES_CHANGE_DEL          0x2	/* remove this from mid-layer */
80862306a36Sopenharmony_ci
80962306a36Sopenharmony_ci	u8 reset_progress;      /* Device is resetting */
81062306a36Sopenharmony_ci
81162306a36Sopenharmony_ci	/*
81262306a36Sopenharmony_ci	 * When IOA asks for sync (i.e. IOASC = Not Ready, Sync Required), this
81362306a36Sopenharmony_ci	 * flag will be set, mid layer will be asked to retry. In the next
81462306a36Sopenharmony_ci	 * attempt, this flag will be checked in queuecommand() to set
81562306a36Sopenharmony_ci	 * SYNC_COMPLETE flag in IOARCB (flag_0).
81662306a36Sopenharmony_ci	 */
81762306a36Sopenharmony_ci	u8 sync_reqd;
81862306a36Sopenharmony_ci
81962306a36Sopenharmony_ci	/* target indicates the mapped target_id assigned to this resource if
82062306a36Sopenharmony_ci	 * this is VSET resource. For non-VSET resources this will be un-used
82162306a36Sopenharmony_ci	 * or zero
82262306a36Sopenharmony_ci	 */
82362306a36Sopenharmony_ci	u8 target;
82462306a36Sopenharmony_ci};
82562306a36Sopenharmony_ci
82662306a36Sopenharmony_ci/* Data structures used in IOASC error code logging */
82762306a36Sopenharmony_cistruct pmcraid_ioasc_error {
82862306a36Sopenharmony_ci	u32 ioasc_code;		/* IOASC code */
82962306a36Sopenharmony_ci	u8 log_level;		/* default log level assignment. */
83062306a36Sopenharmony_ci	char *error_string;
83162306a36Sopenharmony_ci};
83262306a36Sopenharmony_ci
83362306a36Sopenharmony_ci/* Initial log_level assignments for various IOASCs */
83462306a36Sopenharmony_ci#define IOASC_LOG_LEVEL_NONE	    0x0 /* no logging */
83562306a36Sopenharmony_ci#define IOASC_LOG_LEVEL_MUST        0x1	/* must log: all high-severity errors */
83662306a36Sopenharmony_ci#define IOASC_LOG_LEVEL_HARD        0x2	/* optional – low severity errors */
83762306a36Sopenharmony_ci
83862306a36Sopenharmony_ci/* Error information maintained by LLD. LLD initializes the pmcraid_error_table
83962306a36Sopenharmony_ci * statically.
84062306a36Sopenharmony_ci */
84162306a36Sopenharmony_cistatic struct pmcraid_ioasc_error pmcraid_ioasc_error_table[] = {
84262306a36Sopenharmony_ci	{0x01180600, IOASC_LOG_LEVEL_HARD,
84362306a36Sopenharmony_ci	 "Recovered Error, soft media error, sector reassignment suggested"},
84462306a36Sopenharmony_ci	{0x015D0000, IOASC_LOG_LEVEL_HARD,
84562306a36Sopenharmony_ci	 "Recovered Error, failure prediction threshold exceeded"},
84662306a36Sopenharmony_ci	{0x015D9200, IOASC_LOG_LEVEL_HARD,
84762306a36Sopenharmony_ci	 "Recovered Error, soft Cache Card Battery error threshold"},
84862306a36Sopenharmony_ci	{0x015D9200, IOASC_LOG_LEVEL_HARD,
84962306a36Sopenharmony_ci	 "Recovered Error, soft Cache Card Battery error threshold"},
85062306a36Sopenharmony_ci	{0x02048000, IOASC_LOG_LEVEL_HARD,
85162306a36Sopenharmony_ci	 "Not Ready, IOA Reset Required"},
85262306a36Sopenharmony_ci	{0x02408500, IOASC_LOG_LEVEL_HARD,
85362306a36Sopenharmony_ci	 "Not Ready, IOA microcode download required"},
85462306a36Sopenharmony_ci	{0x03110B00, IOASC_LOG_LEVEL_HARD,
85562306a36Sopenharmony_ci	 "Medium Error, data unreadable, reassignment suggested"},
85662306a36Sopenharmony_ci	{0x03110C00, IOASC_LOG_LEVEL_MUST,
85762306a36Sopenharmony_ci	 "Medium Error, data unreadable do not reassign"},
85862306a36Sopenharmony_ci	{0x03310000, IOASC_LOG_LEVEL_HARD,
85962306a36Sopenharmony_ci	 "Medium Error, media corrupted"},
86062306a36Sopenharmony_ci	{0x04050000, IOASC_LOG_LEVEL_HARD,
86162306a36Sopenharmony_ci	 "Hardware Error, IOA can't communicate with device"},
86262306a36Sopenharmony_ci	{0x04080000, IOASC_LOG_LEVEL_MUST,
86362306a36Sopenharmony_ci	 "Hardware Error, device bus error"},
86462306a36Sopenharmony_ci	{0x04088000, IOASC_LOG_LEVEL_MUST,
86562306a36Sopenharmony_ci	 "Hardware Error, device bus is not functioning"},
86662306a36Sopenharmony_ci	{0x04118000, IOASC_LOG_LEVEL_HARD,
86762306a36Sopenharmony_ci	 "Hardware Error, IOA reserved area data check"},
86862306a36Sopenharmony_ci	{0x04118100, IOASC_LOG_LEVEL_HARD,
86962306a36Sopenharmony_ci	 "Hardware Error, IOA reserved area invalid data pattern"},
87062306a36Sopenharmony_ci	{0x04118200, IOASC_LOG_LEVEL_HARD,
87162306a36Sopenharmony_ci	 "Hardware Error, IOA reserved area LRC error"},
87262306a36Sopenharmony_ci	{0x04320000, IOASC_LOG_LEVEL_HARD,
87362306a36Sopenharmony_ci	 "Hardware Error, reassignment space exhausted"},
87462306a36Sopenharmony_ci	{0x04330000, IOASC_LOG_LEVEL_HARD,
87562306a36Sopenharmony_ci	 "Hardware Error, data transfer underlength error"},
87662306a36Sopenharmony_ci	{0x04330000, IOASC_LOG_LEVEL_HARD,
87762306a36Sopenharmony_ci	 "Hardware Error, data transfer overlength error"},
87862306a36Sopenharmony_ci	{0x04418000, IOASC_LOG_LEVEL_MUST,
87962306a36Sopenharmony_ci	 "Hardware Error, PCI bus error"},
88062306a36Sopenharmony_ci	{0x04440000, IOASC_LOG_LEVEL_HARD,
88162306a36Sopenharmony_ci	 "Hardware Error, device error"},
88262306a36Sopenharmony_ci	{0x04448200, IOASC_LOG_LEVEL_MUST,
88362306a36Sopenharmony_ci	 "Hardware Error, IOA error"},
88462306a36Sopenharmony_ci	{0x04448300, IOASC_LOG_LEVEL_HARD,
88562306a36Sopenharmony_ci	 "Hardware Error, undefined device response"},
88662306a36Sopenharmony_ci	{0x04448400, IOASC_LOG_LEVEL_HARD,
88762306a36Sopenharmony_ci	 "Hardware Error, IOA microcode error"},
88862306a36Sopenharmony_ci	{0x04448600, IOASC_LOG_LEVEL_HARD,
88962306a36Sopenharmony_ci	 "Hardware Error, IOA reset required"},
89062306a36Sopenharmony_ci	{0x04449200, IOASC_LOG_LEVEL_HARD,
89162306a36Sopenharmony_ci	 "Hardware Error, hard Cache Fearuee Card Battery error"},
89262306a36Sopenharmony_ci	{0x0444A000, IOASC_LOG_LEVEL_HARD,
89362306a36Sopenharmony_ci	 "Hardware Error, failed device altered"},
89462306a36Sopenharmony_ci	{0x0444A200, IOASC_LOG_LEVEL_HARD,
89562306a36Sopenharmony_ci	 "Hardware Error, data check after reassignment"},
89662306a36Sopenharmony_ci	{0x0444A300, IOASC_LOG_LEVEL_HARD,
89762306a36Sopenharmony_ci	 "Hardware Error, LRC error after reassignment"},
89862306a36Sopenharmony_ci	{0x044A0000, IOASC_LOG_LEVEL_HARD,
89962306a36Sopenharmony_ci	 "Hardware Error, device bus error (msg/cmd phase)"},
90062306a36Sopenharmony_ci	{0x04670400, IOASC_LOG_LEVEL_HARD,
90162306a36Sopenharmony_ci	 "Hardware Error, new device can't be used"},
90262306a36Sopenharmony_ci	{0x04678000, IOASC_LOG_LEVEL_HARD,
90362306a36Sopenharmony_ci	 "Hardware Error, invalid multiadapter configuration"},
90462306a36Sopenharmony_ci	{0x04678100, IOASC_LOG_LEVEL_HARD,
90562306a36Sopenharmony_ci	 "Hardware Error, incorrect connection between enclosures"},
90662306a36Sopenharmony_ci	{0x04678200, IOASC_LOG_LEVEL_HARD,
90762306a36Sopenharmony_ci	 "Hardware Error, connections exceed IOA design limits"},
90862306a36Sopenharmony_ci	{0x04678300, IOASC_LOG_LEVEL_HARD,
90962306a36Sopenharmony_ci	 "Hardware Error, incorrect multipath connection"},
91062306a36Sopenharmony_ci	{0x04679000, IOASC_LOG_LEVEL_HARD,
91162306a36Sopenharmony_ci	 "Hardware Error, command to LUN failed"},
91262306a36Sopenharmony_ci	{0x064C8000, IOASC_LOG_LEVEL_HARD,
91362306a36Sopenharmony_ci	 "Unit Attention, cache exists for missing/failed device"},
91462306a36Sopenharmony_ci	{0x06670100, IOASC_LOG_LEVEL_HARD,
91562306a36Sopenharmony_ci	 "Unit Attention, incompatible exposed mode device"},
91662306a36Sopenharmony_ci	{0x06670600, IOASC_LOG_LEVEL_HARD,
91762306a36Sopenharmony_ci	 "Unit Attention, attachment of logical unit failed"},
91862306a36Sopenharmony_ci	{0x06678000, IOASC_LOG_LEVEL_HARD,
91962306a36Sopenharmony_ci	 "Unit Attention, cables exceed connective design limit"},
92062306a36Sopenharmony_ci	{0x06678300, IOASC_LOG_LEVEL_HARD,
92162306a36Sopenharmony_ci	 "Unit Attention, incomplete multipath connection between" \
92262306a36Sopenharmony_ci	 "IOA and enclosure"},
92362306a36Sopenharmony_ci	{0x06678400, IOASC_LOG_LEVEL_HARD,
92462306a36Sopenharmony_ci	 "Unit Attention, incomplete multipath connection between" \
92562306a36Sopenharmony_ci	 "device and enclosure"},
92662306a36Sopenharmony_ci	{0x06678500, IOASC_LOG_LEVEL_HARD,
92762306a36Sopenharmony_ci	 "Unit Attention, incomplete multipath connection between" \
92862306a36Sopenharmony_ci	 "IOA and remote IOA"},
92962306a36Sopenharmony_ci	{0x06678600, IOASC_LOG_LEVEL_HARD,
93062306a36Sopenharmony_ci	 "Unit Attention, missing remote IOA"},
93162306a36Sopenharmony_ci	{0x06679100, IOASC_LOG_LEVEL_HARD,
93262306a36Sopenharmony_ci	 "Unit Attention, enclosure doesn't support required multipath" \
93362306a36Sopenharmony_ci	 "function"},
93462306a36Sopenharmony_ci	{0x06698200, IOASC_LOG_LEVEL_HARD,
93562306a36Sopenharmony_ci	 "Unit Attention, corrupt array parity detected on device"},
93662306a36Sopenharmony_ci	{0x066B0200, IOASC_LOG_LEVEL_HARD,
93762306a36Sopenharmony_ci	 "Unit Attention, array exposed"},
93862306a36Sopenharmony_ci	{0x066B8200, IOASC_LOG_LEVEL_HARD,
93962306a36Sopenharmony_ci	 "Unit Attention, exposed array is still protected"},
94062306a36Sopenharmony_ci	{0x066B9200, IOASC_LOG_LEVEL_HARD,
94162306a36Sopenharmony_ci	 "Unit Attention, Multipath redundancy level got worse"},
94262306a36Sopenharmony_ci	{0x07270000, IOASC_LOG_LEVEL_HARD,
94362306a36Sopenharmony_ci	 "Data Protect, device is read/write protected by IOA"},
94462306a36Sopenharmony_ci	{0x07278000, IOASC_LOG_LEVEL_HARD,
94562306a36Sopenharmony_ci	 "Data Protect, IOA doesn't support device attribute"},
94662306a36Sopenharmony_ci	{0x07278100, IOASC_LOG_LEVEL_HARD,
94762306a36Sopenharmony_ci	 "Data Protect, NVRAM mirroring prohibited"},
94862306a36Sopenharmony_ci	{0x07278400, IOASC_LOG_LEVEL_HARD,
94962306a36Sopenharmony_ci	 "Data Protect, array is short 2 or more devices"},
95062306a36Sopenharmony_ci	{0x07278600, IOASC_LOG_LEVEL_HARD,
95162306a36Sopenharmony_ci	 "Data Protect, exposed array is short a required device"},
95262306a36Sopenharmony_ci	{0x07278700, IOASC_LOG_LEVEL_HARD,
95362306a36Sopenharmony_ci	 "Data Protect, array members not at required addresses"},
95462306a36Sopenharmony_ci	{0x07278800, IOASC_LOG_LEVEL_HARD,
95562306a36Sopenharmony_ci	 "Data Protect, exposed mode device resource address conflict"},
95662306a36Sopenharmony_ci	{0x07278900, IOASC_LOG_LEVEL_HARD,
95762306a36Sopenharmony_ci	 "Data Protect, incorrect resource address of exposed mode device"},
95862306a36Sopenharmony_ci	{0x07278A00, IOASC_LOG_LEVEL_HARD,
95962306a36Sopenharmony_ci	 "Data Protect, Array is missing a device and parity is out of sync"},
96062306a36Sopenharmony_ci	{0x07278B00, IOASC_LOG_LEVEL_HARD,
96162306a36Sopenharmony_ci	 "Data Protect, maximum number of arrays already exist"},
96262306a36Sopenharmony_ci	{0x07278C00, IOASC_LOG_LEVEL_HARD,
96362306a36Sopenharmony_ci	 "Data Protect, cannot locate cache data for device"},
96462306a36Sopenharmony_ci	{0x07278D00, IOASC_LOG_LEVEL_HARD,
96562306a36Sopenharmony_ci	 "Data Protect, cache data exits for a changed device"},
96662306a36Sopenharmony_ci	{0x07279100, IOASC_LOG_LEVEL_HARD,
96762306a36Sopenharmony_ci	 "Data Protect, detection of a device requiring format"},
96862306a36Sopenharmony_ci	{0x07279200, IOASC_LOG_LEVEL_HARD,
96962306a36Sopenharmony_ci	 "Data Protect, IOA exceeds maximum number of devices"},
97062306a36Sopenharmony_ci	{0x07279600, IOASC_LOG_LEVEL_HARD,
97162306a36Sopenharmony_ci	 "Data Protect, missing array, volume set is not functional"},
97262306a36Sopenharmony_ci	{0x07279700, IOASC_LOG_LEVEL_HARD,
97362306a36Sopenharmony_ci	 "Data Protect, single device for a volume set"},
97462306a36Sopenharmony_ci	{0x07279800, IOASC_LOG_LEVEL_HARD,
97562306a36Sopenharmony_ci	 "Data Protect, missing multiple devices for a volume set"},
97662306a36Sopenharmony_ci	{0x07279900, IOASC_LOG_LEVEL_HARD,
97762306a36Sopenharmony_ci	 "Data Protect, maximum number of volument sets already exists"},
97862306a36Sopenharmony_ci	{0x07279A00, IOASC_LOG_LEVEL_HARD,
97962306a36Sopenharmony_ci	 "Data Protect, other volume set problem"},
98062306a36Sopenharmony_ci};
98162306a36Sopenharmony_ci
98262306a36Sopenharmony_ci/* macros to help in debugging */
98362306a36Sopenharmony_ci#define pmcraid_err(...)  \
98462306a36Sopenharmony_ci	printk(KERN_ERR "MaxRAID: "__VA_ARGS__)
98562306a36Sopenharmony_ci
98662306a36Sopenharmony_ci#define pmcraid_info(...) \
98762306a36Sopenharmony_ci	if (pmcraid_debug_log) \
98862306a36Sopenharmony_ci		printk(KERN_INFO "MaxRAID: "__VA_ARGS__)
98962306a36Sopenharmony_ci
99062306a36Sopenharmony_ci/* check if given command is a SCSI READ or SCSI WRITE command */
99162306a36Sopenharmony_ci#define SCSI_READ_CMD           0x1	/* any of SCSI READ commands */
99262306a36Sopenharmony_ci#define SCSI_WRITE_CMD          0x2	/* any of SCSI WRITE commands */
99362306a36Sopenharmony_ci#define SCSI_CMD_TYPE(opcode) \
99462306a36Sopenharmony_ci({  u8 op = opcode; u8 __type = 0;\
99562306a36Sopenharmony_ci	if (op == READ_6 || op == READ_10 || op == READ_12 || op == READ_16)\
99662306a36Sopenharmony_ci		__type = SCSI_READ_CMD;\
99762306a36Sopenharmony_ci	else if (op == WRITE_6 || op == WRITE_10 || op == WRITE_12 || \
99862306a36Sopenharmony_ci		 op == WRITE_16)\
99962306a36Sopenharmony_ci		__type = SCSI_WRITE_CMD;\
100062306a36Sopenharmony_ci	__type;\
100162306a36Sopenharmony_ci})
100262306a36Sopenharmony_ci
100362306a36Sopenharmony_ci#define IS_SCSI_READ_WRITE(opcode) \
100462306a36Sopenharmony_ci({	u8 __type = SCSI_CMD_TYPE(opcode); \
100562306a36Sopenharmony_ci	(__type == SCSI_READ_CMD || __type == SCSI_WRITE_CMD) ? 1 : 0;\
100662306a36Sopenharmony_ci})
100762306a36Sopenharmony_ci
100862306a36Sopenharmony_ci
100962306a36Sopenharmony_ci/*
101062306a36Sopenharmony_ci * pmcraid_ioctl_header - definition of header structure that precedes all the
101162306a36Sopenharmony_ci * buffers given as ioctl arguments.
101262306a36Sopenharmony_ci *
101362306a36Sopenharmony_ci * .signature           : always ASCII string, "PMCRAID"
101462306a36Sopenharmony_ci * .reserved            : not used
101562306a36Sopenharmony_ci * .buffer_length       : length of the buffer following the header
101662306a36Sopenharmony_ci */
101762306a36Sopenharmony_cistruct pmcraid_ioctl_header {
101862306a36Sopenharmony_ci	u8  signature[8];
101962306a36Sopenharmony_ci	u32 reserved;
102062306a36Sopenharmony_ci	u32 buffer_length;
102162306a36Sopenharmony_ci};
102262306a36Sopenharmony_ci
102362306a36Sopenharmony_ci#define PMCRAID_IOCTL_SIGNATURE      "PMCRAID"
102462306a36Sopenharmony_ci
102562306a36Sopenharmony_ci/*
102662306a36Sopenharmony_ci * keys to differentiate between driver handled IOCTLs and passthrough
102762306a36Sopenharmony_ci * IOCTLs passed to IOA. driver determines the ioctl type using macro
102862306a36Sopenharmony_ci * _IOC_TYPE
102962306a36Sopenharmony_ci */
103062306a36Sopenharmony_ci#define PMCRAID_DRIVER_IOCTL         'D'
103162306a36Sopenharmony_ci
103262306a36Sopenharmony_ci#define DRV_IOCTL(n, size) \
103362306a36Sopenharmony_ci	_IOC(_IOC_READ|_IOC_WRITE, PMCRAID_DRIVER_IOCTL, (n), (size))
103462306a36Sopenharmony_ci
103562306a36Sopenharmony_ci/*
103662306a36Sopenharmony_ci * _ARGSIZE: macro that gives size of the argument type passed to an IOCTL cmd.
103762306a36Sopenharmony_ci * This is to facilitate applications avoiding un-necessary memory allocations.
103862306a36Sopenharmony_ci * For example, most of driver handled ioctls do not require ioarcb, ioasa.
103962306a36Sopenharmony_ci */
104062306a36Sopenharmony_ci#define _ARGSIZE(arg) (sizeof(struct pmcraid_ioctl_header) + sizeof(arg))
104162306a36Sopenharmony_ci
104262306a36Sopenharmony_ci/* Driver handled IOCTL command definitions */
104362306a36Sopenharmony_ci
104462306a36Sopenharmony_ci#define PMCRAID_IOCTL_RESET_ADAPTER          \
104562306a36Sopenharmony_ci	DRV_IOCTL(5, sizeof(struct pmcraid_ioctl_header))
104662306a36Sopenharmony_ci
104762306a36Sopenharmony_ci#endif /* _PMCRAID_H */
1048